@sasjs/adapter 4.17.2 → 4.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SASViyaApiClient.d.ts +6 -7
- package/SASjs.d.ts +4 -1
- package/api/viya/executeOnComputeApi.d.ts +3 -1
- package/api/viya/pollJobState.d.ts +3 -2
- package/auth/getTokens.d.ts +13 -1
- package/index-dev.js +9162 -3935
- package/index.d.ts +1 -0
- package/index.js +7291 -2064
- package/minified_sas9.js +400 -366
- package/node/SASViyaApiClient.d.ts +6 -7
- package/node/SASjs.d.ts +4 -1
- package/node/api/viya/executeOnComputeApi.d.ts +3 -1
- package/node/api/viya/pollJobState.d.ts +3 -2
- package/node/auth/getTokens.d.ts +13 -1
- package/node/index.d.ts +1 -0
- package/node/index.js +142 -36
- package/package.json +2 -2
- package/src/SASViyaApiClient.ts +44 -16
- package/src/SASjs.ts +12 -2
- package/src/api/viya/executeOnComputeApi.ts +19 -6
- package/src/api/viya/pollJobState.ts +21 -9
- package/src/auth/getTokens.ts +82 -9
- package/src/index.ts +1 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Job, Session, Context, ContextAllAttributes, Folder, File, EditContextInput, PollOptions } from './types';
|
|
3
3
|
import { SasAuthResponse, MacroVar, AuthConfig } from '@sasjs/utils/types';
|
|
4
4
|
import { RequestClient } from './request/RequestClient';
|
|
5
|
+
import { OnTokensRefreshed } from './auth/getTokens';
|
|
5
6
|
import { FileResource } from './types/FileResource';
|
|
6
7
|
interface JobExecutionResult {
|
|
7
8
|
result?: {
|
|
@@ -74,10 +75,6 @@ export declare class SASViyaApiClient {
|
|
|
74
75
|
getLauncherContexts(accessToken?: string): Promise<{
|
|
75
76
|
createdBy: any;
|
|
76
77
|
id: any;
|
|
77
|
-
/**
|
|
78
|
-
* A client for interfacing with the SAS Viya REST API.
|
|
79
|
-
*
|
|
80
|
-
*/
|
|
81
78
|
name: any;
|
|
82
79
|
version: any;
|
|
83
80
|
attributes: {};
|
|
@@ -143,8 +140,9 @@ export declare class SASViyaApiClient {
|
|
|
143
140
|
* @param pollOptions - an object that represents poll interval(milliseconds) and maximum amount of attempts. Object example: { maxPollCount: 24 * 60 * 60, pollInterval: 1000 }. More information available at src/api/viya/pollJobState.ts.
|
|
144
141
|
* @param printPid - a boolean that indicates whether the function should print (PID) of the started job.
|
|
145
142
|
* @param variables - an object that represents macro variables.
|
|
143
|
+
* @param onTokensRefreshed - optional callback invoked with the rotated token pair after a successful internal refresh, so consumers that persist tokens can store the new pair.
|
|
146
144
|
*/
|
|
147
|
-
executeScript(jobPath: string, linesOfCode: string[], contextName: string, authConfig?: AuthConfig, data?: null, debug?: boolean, expectWebout?: boolean, waitForResult?: boolean, pollOptions?: PollOptions, printPid?: boolean, variables?: MacroVar): Promise<any>;
|
|
145
|
+
executeScript(jobPath: string, linesOfCode: string[], contextName: string, authConfig?: AuthConfig, data?: null, debug?: boolean, expectWebout?: boolean, waitForResult?: boolean, pollOptions?: PollOptions, printPid?: boolean, variables?: MacroVar, onTokensRefreshed?: OnTokensRefreshed): Promise<any>;
|
|
148
146
|
/**
|
|
149
147
|
* Fetches the file content for a file in the specified folder.
|
|
150
148
|
*
|
|
@@ -241,7 +239,7 @@ export declare class SASViyaApiClient {
|
|
|
241
239
|
* @param printPid - a boolean that indicates whether the function should print (PID) of the started job.
|
|
242
240
|
* @param variables - an object that represents macro variables.
|
|
243
241
|
*/
|
|
244
|
-
executeComputeJob(sasJob: string, contextName: string, debug?: boolean, data?: any, authConfig?: AuthConfig, waitForResult?: boolean, expectWebout?: boolean, pollOptions?: PollOptions, printPid?: boolean, variables?: MacroVar): Promise<any>;
|
|
242
|
+
executeComputeJob(sasJob: string, contextName: string, debug?: boolean, data?: any, authConfig?: AuthConfig, waitForResult?: boolean, expectWebout?: boolean, pollOptions?: PollOptions, printPid?: boolean, variables?: MacroVar, onTokensRefreshed?: OnTokensRefreshed): Promise<any>;
|
|
245
243
|
/**
|
|
246
244
|
* Executes a job via the SAS Viya Job Execution API
|
|
247
245
|
* @param sasJob - the relative or absolute path to the job.
|
|
@@ -249,8 +247,9 @@ export declare class SASViyaApiClient {
|
|
|
249
247
|
* @param debug - sets the _debug flag in the job arguments.
|
|
250
248
|
* @param data - any data to be passed in as input to the job.
|
|
251
249
|
* @param accessToken - an optional access token for an authorized user.
|
|
250
|
+
* @param onTokensRefreshed - optional callback invoked with the rotated token pair after a successful internal refresh, so consumers that persist tokens can store the new pair.
|
|
252
251
|
*/
|
|
253
|
-
executeJob(sasJob: string, contextName: string, debug: boolean, data?: any, authConfig?: AuthConfig): Promise<JobExecutionResult>;
|
|
252
|
+
executeJob(sasJob: string, contextName: string, debug: boolean, data?: any, authConfig?: AuthConfig, onTokensRefreshed?: OnTokensRefreshed): Promise<JobExecutionResult>;
|
|
254
253
|
private populateFolderMap;
|
|
255
254
|
private pollJobState;
|
|
256
255
|
private uploadTables;
|
package/node/SASjs.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { SASjsConfig, UploadFile, EditContextInput, PollOptions, VerboseMode, LoginOptions, LoginResult, ExecutionQuery, Tables } from './types';
|
|
3
3
|
import { SASViyaApiClient } from './SASViyaApiClient';
|
|
4
4
|
import { SASjsAuthResponse } from './SASjsApiClient';
|
|
5
|
+
import { OnTokensRefreshed } from './auth/getTokens';
|
|
5
6
|
import { MacroVar, AuthConfig, ExtraResponseAttributes, SasAuthResponse, AuthConfigSas9 } from '@sasjs/utils/types';
|
|
6
7
|
import { AxiosResponse, AxiosError } from 'axios';
|
|
7
8
|
interface ExecuteScriptParams {
|
|
@@ -12,6 +13,7 @@ interface ExecuteScriptParams {
|
|
|
12
13
|
authConfig?: AuthConfig;
|
|
13
14
|
authConfigSas9?: AuthConfigSas9;
|
|
14
15
|
debug?: boolean;
|
|
16
|
+
onTokensRefreshed?: OnTokensRefreshed;
|
|
15
17
|
}
|
|
16
18
|
/**
|
|
17
19
|
* SASjs is a JavaScript adapter for SAS.
|
|
@@ -42,8 +44,9 @@ export default class SASjs {
|
|
|
42
44
|
* @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute scripts.
|
|
43
45
|
* @param authConfigSas9 - (required for server type sas9) a valid username and password that are authorised to execute scripts.
|
|
44
46
|
* @param debug - (optional) if true, global debug config will be overriden
|
|
47
|
+
* @param onTokensRefreshed - (optional, SAS Viya only) callback invoked with the rotated token pair after a successful internal refresh, so consumers that persist tokens can store the new pair.
|
|
45
48
|
*/
|
|
46
|
-
executeScript({ linesOfCode, fileName, contextName, runTime, authConfig, authConfigSas9, debug }: ExecuteScriptParams): Promise<any>;
|
|
49
|
+
executeScript({ linesOfCode, fileName, contextName, runTime, authConfig, authConfigSas9, debug, onTokensRefreshed }: ExecuteScriptParams): Promise<any>;
|
|
47
50
|
/**
|
|
48
51
|
* Executes job on SASJS server.
|
|
49
52
|
* @param query - an object containing job path and debug level.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AuthConfig, MacroVar } from '@sasjs/utils/types';
|
|
2
2
|
import { PollOptions } from '../..';
|
|
3
|
+
import { OnTokensRefreshed } from '../../auth/getTokens';
|
|
3
4
|
import { RequestClient } from '../../request/RequestClient';
|
|
4
5
|
import { SessionManager } from '../../SessionManager';
|
|
5
6
|
/**
|
|
@@ -15,5 +16,6 @@ import { SessionManager } from '../../SessionManager';
|
|
|
15
16
|
* @param pollOptions - an object that represents poll interval(milliseconds) and maximum amount of attempts. Object example: { maxPollCount: 24 * 60 * 60, pollInterval: 1000 }. More information available at src/api/viya/pollJobState.ts.
|
|
16
17
|
* @param printPid - a boolean that indicates whether the function should print (PID) of the started job.
|
|
17
18
|
* @param variables - an object that represents macro variables.
|
|
19
|
+
* @param onTokensRefreshed - optional callback invoked with the rotated token pair after a successful internal refresh, so consumers that persist tokens can store the new pair.
|
|
18
20
|
*/
|
|
19
|
-
export declare function executeOnComputeApi(requestClient: RequestClient, sessionManager: SessionManager, rootFolderName: string, jobPath: string, linesOfCode: string[], contextName: string, authConfig?: AuthConfig, data?: any, debug?: boolean, expectWebout?: boolean, waitForResult?: boolean, pollOptions?: PollOptions, printPid?: boolean, variables?: MacroVar): Promise<any>;
|
|
21
|
+
export declare function executeOnComputeApi(requestClient: RequestClient, sessionManager: SessionManager, rootFolderName: string, jobPath: string, linesOfCode: string[], contextName: string, authConfig?: AuthConfig, data?: any, debug?: boolean, expectWebout?: boolean, waitForResult?: boolean, pollOptions?: PollOptions, printPid?: boolean, variables?: MacroVar, onTokensRefreshed?: OnTokensRefreshed): Promise<any>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AuthConfig } from '@sasjs/utils/types';
|
|
2
2
|
import { Job, PollOptions } from '../..';
|
|
3
|
+
import { OnTokensRefreshed } from '../../auth/getTokens';
|
|
3
4
|
import { RequestClient } from '../../request/RequestClient';
|
|
4
5
|
import { WriteStream, JobSessionManager } from '../../types';
|
|
5
6
|
export declare enum JobState {
|
|
@@ -35,7 +36,7 @@ export declare enum JobState {
|
|
|
35
36
|
* @param jobSessionManager - job session object containing session object and an instance of Session Manager. Job session object is used to periodically (every 10th job state poll) check parent session state.
|
|
36
37
|
* @returns - a promise which resolves with a job state
|
|
37
38
|
*/
|
|
38
|
-
export declare function pollJobState(requestClient: RequestClient, postedJob: Job, debug: boolean, authConfig?: AuthConfig, pollOptions?: PollOptions, jobSessionManager?: JobSessionManager): Promise<JobState>;
|
|
39
|
+
export declare function pollJobState(requestClient: RequestClient, postedJob: Job, debug: boolean, authConfig?: AuthConfig, pollOptions?: PollOptions, jobSessionManager?: JobSessionManager, onTokensRefreshed?: OnTokensRefreshed): Promise<JobState>;
|
|
39
40
|
/**
|
|
40
41
|
* Polls job state.
|
|
41
42
|
* @param requestClient - the pre-configured HTTP request client.
|
|
@@ -50,7 +51,7 @@ export declare function pollJobState(requestClient: RequestClient, postedJob: Jo
|
|
|
50
51
|
* @param jobSessionManager - job session object containing session object and an instance of Session Manager. Job session object is used to periodically (every 10th job state poll) check parent session state. Session state is considered healthy if it is equal to 'running' or 'idle'.
|
|
51
52
|
* @returns - a promise which resolves with a job state
|
|
52
53
|
*/
|
|
53
|
-
export declare const doPoll: (requestClient: RequestClient, postedJob: Job, currentState: JobState, debug: boolean, pollCount: number, pollOptions: PollOptions, authConfig?: AuthConfig, streamLog?: boolean, logStream?: WriteStream, jobSessionManager?: JobSessionManager) => Promise<{
|
|
54
|
+
export declare const doPoll: (requestClient: RequestClient, postedJob: Job, currentState: JobState, debug: boolean, pollCount: number, pollOptions: PollOptions, authConfig?: AuthConfig, streamLog?: boolean, logStream?: WriteStream, jobSessionManager?: JobSessionManager, onTokensRefreshed?: OnTokensRefreshed) => Promise<{
|
|
54
55
|
state: JobState;
|
|
55
56
|
pollCount: number;
|
|
56
57
|
}>;
|
package/node/auth/getTokens.d.ts
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import { AuthConfig, ServerType } from '@sasjs/utils/types';
|
|
2
2
|
import { RequestClient } from '../request/RequestClient';
|
|
3
|
+
/**
|
|
4
|
+
* Callback invoked with the rotated token pair after a successful internal
|
|
5
|
+
* refresh. Viya refresh tokens are single-use/rotating, so consumers that
|
|
6
|
+
* persist tokens (e.g. the CLI writing `.env.{target}`) should pass a handler
|
|
7
|
+
* wherever this is accepted to avoid the persisted pair going stale.
|
|
8
|
+
*/
|
|
9
|
+
export type OnTokensRefreshed = (tokens: {
|
|
10
|
+
access_token: string;
|
|
11
|
+
refresh_token: string;
|
|
12
|
+
}) => void | Promise<void>;
|
|
3
13
|
/**
|
|
4
14
|
* Returns the auth configuration, refreshing the tokens if necessary.
|
|
5
15
|
* This function can only be used by Node, if a server type is SASVIYA.
|
|
6
16
|
* @param requestClient - the pre-configured HTTP request client
|
|
7
17
|
* @param authConfig - an object containing a client ID, secret, access token and refresh token
|
|
8
18
|
* @param serverType - server type for which refreshing the tokens, defaults to SASVIYA
|
|
19
|
+
* @param onTokensRefreshed - optional callback invoked with the rotated token
|
|
20
|
+
* pair after a successful internal refresh.
|
|
9
21
|
*/
|
|
10
|
-
export declare function getTokens(requestClient: RequestClient, authConfig: AuthConfig, serverType?: ServerType): Promise<AuthConfig>;
|
|
22
|
+
export declare function getTokens(requestClient: RequestClient, authConfig: AuthConfig, serverType?: ServerType, onTokensRefreshed?: OnTokensRefreshed): Promise<AuthConfig>;
|