From 269514a44f7e2c880e792a6388a2c0f7fca6e7ee Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Wed, 10 Feb 2021 08:19:48 +0000 Subject: [PATCH] fix(*): expose CSRF token, add getFolder API --- src/SASViyaApiClient.ts | 11 +++++++++++ src/SASjs.ts | 14 ++++++++++++++ src/auth/AuthManager.ts | 8 +------- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/SASViyaApiClient.ts b/src/SASViyaApiClient.ts index 3d3d5ab..c5581cd 100644 --- a/src/SASViyaApiClient.ts +++ b/src/SASViyaApiClient.ts @@ -495,6 +495,17 @@ export class SASViyaApiClient { } } + /** + * Fetches a folder. Path to the folder is required. + * @param folderPath - the absolute path to the folder. + * @param accessToken - an access token for authorizing the request. + */ + public async getFolder(folderPath: string, accessToken?: string) { + return await this.requestClient + .get(`/folders/folders/@item?path=${folderPath}`, accessToken) + .then((res) => res.result) + } + /** * Creates a folder. Path to or URI of the parent folder is required. * @param folderName - the name of the new folder. diff --git a/src/SASjs.ts b/src/SASjs.ts index 06e158e..7883b78 100644 --- a/src/SASjs.ts +++ b/src/SASjs.ts @@ -50,6 +50,10 @@ export default class SASjs { this.setupConfiguration() } + public getCsrfToken(type: 'general' | 'file' = 'general') { + return this.requestClient?.getCsrfToken(type) + } + public async executeScriptSAS9( linesOfCode: string[], serverName: string, @@ -292,6 +296,16 @@ export default class SASjs { ) } + /** + * Fetches a folder from the SAS file system. + * @param folderPath - path of the folder to be fetched. + * @param accessToken - the access token to authorize the request. + */ + public async getFolder(folderPath: string, accessToken?: string) { + this.isMethodSupported('getFolder', ServerType.SasViya) + return await this.sasViyaApiClient!.getFolder(folderPath, accessToken) + } + /** * For performance (and in case of accidental error) the `deleteFolder` function does not actually delete the folder (and all its content and subfolder content). Instead the folder is simply moved to the recycle bin. Deletion time will be added to the folder name. * @param folderPath - the full path (eg `/Public/example/deleteThis`) of the folder to be deleted. diff --git a/src/auth/AuthManager.ts b/src/auth/AuthManager.ts index e40c7ed..8b79599 100644 --- a/src/auth/AuthManager.ts +++ b/src/auth/AuthManager.ts @@ -60,13 +60,7 @@ export class AuthManager { } ) - let loggedIn - - if (isAuthorizeFormRequired(loginResponse)) { - await this.requestClient.authorize(loginResponse) - } else { - loggedIn = isLogInSuccess(loginResponse) - } + let loggedIn = isLogInSuccess(loginResponse) if (!loggedIn) { const currentSession = await this.checkSession()