From 73ee214b61b9870cd79af6b62230df94e23d63b6 Mon Sep 17 00:00:00 2001 From: Sabir Hassan Date: Wed, 13 Apr 2022 18:22:26 +0500 Subject: [PATCH 1/2] feat: add method for executing scripts on sasjs server --- src/SASjs.ts | 11 +++++++++++ src/SASjsApiClient.ts | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/SASjs.ts b/src/SASjs.ts index 2b2fb6d..94e7f11 100644 --- a/src/SASjs.ts +++ b/src/SASjs.ts @@ -97,6 +97,17 @@ export default class SASjs { ) } + /** + * Executes code against a SAS JS server + * @param code - a string of code from the file to run. + * @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute scripts. + */ + public async executeScriptSASjs(code: string, authConfig?: AuthConfig) { + this.isMethodSupported('executeScriptSASJS', [ServerType.Sasjs]) + + return await this.sasJSApiClient?.executeScript(code, authConfig) + } + /** * Executes sas code in a SAS Viya compute session. * @param fileName - name of the file to run. It will be converted to path to the file being submitted for execution. diff --git a/src/SASjsApiClient.ts b/src/SASjsApiClient.ts index c0a4268..a3600f7 100644 --- a/src/SASjsApiClient.ts +++ b/src/SASjsApiClient.ts @@ -60,6 +60,28 @@ export class SASjsApiClient { return Promise.resolve(result) } + /** + * Executes code on a SASJS server. + * @param serverUrl - a server url to execute code. + * @param code - a string of code to execute. + */ + public async executeScript(code: string, authConfig?: AuthConfig) { + let access_token = (authConfig || {}).access_token + if (authConfig) { + ;({ access_token } = await getTokens( + this.requestClient, + authConfig, + ServerType.Sasjs + )) + } + const response = await this.requestClient.post( + 'SASjsApi/code/execute', + { code }, + access_token + ) + return response.result as string + } + /** * Exchanges the auth code for an access token for the given client. * @param clientId - the client ID to authenticate with. From 6c02ee4cd6e80bd26b3d6b6931c2d13aa60d8d8b Mon Sep 17 00:00:00 2001 From: Allan Bowe <4420615+allanbowe@users.noreply.github.com> Date: Wed, 13 Apr 2022 19:49:16 +0100 Subject: [PATCH 2/2] Update SASjs.ts --- src/SASjs.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SASjs.ts b/src/SASjs.ts index 94e7f11..ac83240 100644 --- a/src/SASjs.ts +++ b/src/SASjs.ts @@ -77,7 +77,7 @@ export default class SASjs { } /** - * Executes code against a SAS 9 server. Requires a runner to be present in + * Executes SAS code on a SAS 9 server. Requires a runner to be present in * the users home directory in metadata. * @param linesOfCode - lines of sas code from the file to run. * @param username - a string representing the username. @@ -98,7 +98,7 @@ export default class SASjs { } /** - * Executes code against a SAS JS server + * Executes SAS code on a SASJS server * @param code - a string of code from the file to run. * @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute scripts. */