From f48089cb8c50dd5f262a3e8a5f020ff46d856a3d Mon Sep 17 00:00:00 2001 From: Saad Jutt Date: Fri, 11 Feb 2022 21:04:51 +0500 Subject: [PATCH 1/2] fix(SASJS): sasjs server deployment with auth + refresh token bug --- src/SASjs.ts | 11 +++++++++-- src/SASjsApiClient.ts | 18 ++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/SASjs.ts b/src/SASjs.ts index 2728f16..2610612 100644 --- a/src/SASjs.ts +++ b/src/SASjs.ts @@ -865,8 +865,15 @@ export default class SASjs { ) } - public async deployToSASjs(members: [FolderMember, ServiceMember]) { - return await this.sasJSApiClient?.deploy(members, this.sasjsConfig.appLoc) + public async deployToSASjs( + members: [FolderMember, ServiceMember], + authConfig?: AuthConfig + ) { + return await this.sasJSApiClient?.deploy( + members, + this.sasjsConfig.appLoc, + authConfig + ) } public async executeJobSASjs(query: ExecutionQuery) { diff --git a/src/SASjsApiClient.ts b/src/SASjsApiClient.ts index 73ed694..4b60e54 100644 --- a/src/SASjsApiClient.ts +++ b/src/SASjsApiClient.ts @@ -1,8 +1,10 @@ +import { AuthConfig, ServerType } from '@sasjs/utils/types' import { FolderMember, ServiceMember, ExecutionQuery } from './types' import { RequestClient } from './request/RequestClient' import { getAccessTokenForSasjs } from './auth/getAccessTokenForSasjs' import { refreshTokensForSasjs } from './auth/refreshTokensForSasjs' import { getAuthCodeForSasjs } from './auth/getAuthCodeForSasjs' +import { getTokens } from './auth/getTokens' export class SASjsApiClient { constructor( @@ -14,7 +16,19 @@ export class SASjsApiClient { if (serverUrl) this.serverUrl = serverUrl } - public async deploy(members: [FolderMember, ServiceMember], appLoc: string) { + public async deploy( + members: [FolderMember, ServiceMember], + appLoc: string, + authConfig?: AuthConfig + ) { + let access_token = (authConfig || {}).access_token + if (authConfig) { + ;({ access_token } = await getTokens( + this.requestClient, + authConfig, + ServerType.Sasjs + )) + } const { result } = await this.requestClient.post<{ status: string message: string @@ -22,7 +36,7 @@ export class SASjsApiClient { }>( 'SASjsApi/drive/deploy', { fileTree: members, appLoc: appLoc }, - undefined + access_token ) return Promise.resolve(result) From ebd55c5b02330106b0c6a3860d4c4228763e7420 Mon Sep 17 00:00:00 2001 From: Saad Jutt Date: Fri, 11 Feb 2022 21:18:18 +0500 Subject: [PATCH 2/2] chore: provided JSDoc for deployToSASjs --- src/SASjs.ts | 24 +++++++++++++++--------- src/SASjsApiClient.ts | 4 ++-- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/SASjs.ts b/src/SASjs.ts index 2610612..54f05b7 100644 --- a/src/SASjs.ts +++ b/src/SASjs.ts @@ -5,9 +5,8 @@ import { EditContextInput, PollOptions, LoginMechanism, - FolderMember, - ServiceMember, - ExecutionQuery + ExecutionQuery, + FileTree } from './types' import { SASViyaApiClient } from './SASViyaApiClient' import { SAS9ApiClient } from './SAS9ApiClient' @@ -865,15 +864,22 @@ export default class SASjs { ) } + /** + * Creates the folders and services at the given location `appLoc` on the given server `serverUrl`. + * @param members - the JSON specifying the folders and services to be created. + * @param appLoc - the base folder in which to create the new folders and + * services. If not provided, is taken from SASjsConfig. + * @param authConfig - a valid client, secret, refresh and access tokens that are authorised to execute compute jobs. + */ public async deployToSASjs( - members: [FolderMember, ServiceMember], + members: FileTree, + appLoc?: string, authConfig?: AuthConfig ) { - return await this.sasJSApiClient?.deploy( - members, - this.sasjsConfig.appLoc, - authConfig - ) + if (!appLoc) { + appLoc = this.sasjsConfig.appLoc + } + return await this.sasJSApiClient?.deploy(members, appLoc, authConfig) } public async executeJobSASjs(query: ExecutionQuery) { diff --git a/src/SASjsApiClient.ts b/src/SASjsApiClient.ts index 4b60e54..2706e94 100644 --- a/src/SASjsApiClient.ts +++ b/src/SASjsApiClient.ts @@ -1,5 +1,5 @@ import { AuthConfig, ServerType } from '@sasjs/utils/types' -import { FolderMember, ServiceMember, ExecutionQuery } from './types' +import { FileTree, ExecutionQuery } from './types' import { RequestClient } from './request/RequestClient' import { getAccessTokenForSasjs } from './auth/getAccessTokenForSasjs' import { refreshTokensForSasjs } from './auth/refreshTokensForSasjs' @@ -17,7 +17,7 @@ export class SASjsApiClient { } public async deploy( - members: [FolderMember, ServiceMember], + members: FileTree, appLoc: string, authConfig?: AuthConfig ) {