@sasjs/adapter 4.3.8 → 4.5.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 +11 -6
- package/SASjs.d.ts +1 -1
- package/api/viya/executeScript.d.ts +1 -1
- package/api/viya/pollJobState.d.ts +33 -1
- package/auth/getAccessTokenForViya.d.ts +2 -2
- package/auth/getTokenRequestErrorPrefix.d.ts +44 -0
- package/auth/spec/getTokenRequestErrorPrefix.spec.d.ts +1 -0
- package/index-dev.js +2 -2
- package/index.js +1 -1
- package/minified_sas9.js +1 -1
- package/node/SASViyaApiClient.d.ts +11 -6
- package/node/SASjs.d.ts +1 -1
- package/node/api/viya/executeScript.d.ts +1 -1
- package/node/api/viya/pollJobState.d.ts +33 -1
- package/node/auth/getAccessTokenForViya.d.ts +2 -2
- package/node/auth/getTokenRequestErrorPrefix.d.ts +44 -0
- package/node/index.js +1 -1
- package/node/types/PollOptions.d.ts +3 -1
- package/package.json +1 -1
- package/src/SASViyaApiClient.ts +30 -7
- package/src/SASjs.ts +1 -1
- package/src/api/viya/executeScript.ts +3 -3
- package/src/api/viya/pollJobState.ts +160 -81
- package/src/auth/getAccessTokenForSasjs.ts +13 -1
- package/src/auth/getAccessTokenForViya.ts +22 -6
- package/src/auth/getTokenRequestErrorPrefix.ts +88 -0
- package/src/auth/getTokens.ts +3 -0
- package/src/auth/refreshTokensForSasjs.ts +11 -1
- package/src/auth/refreshTokensForViya.ts +15 -2
- package/src/job-execution/FileUploader.ts +9 -0
- package/src/types/PollOptions.ts +5 -2
- package/types/PollOptions.d.ts +3 -1
package/SASViyaApiClient.d.ts
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
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
|
+
interface JobExecutionResult {
|
|
6
|
+
result?: {
|
|
7
|
+
result: object;
|
|
8
|
+
};
|
|
9
|
+
log?: string;
|
|
10
|
+
error?: object;
|
|
11
|
+
}
|
|
5
12
|
/**
|
|
6
13
|
* A client for interfacing with the SAS Viya REST API.
|
|
7
14
|
*
|
|
@@ -126,7 +133,7 @@ export declare class SASViyaApiClient {
|
|
|
126
133
|
* @param debug - when set to true, the log will be returned.
|
|
127
134
|
* @param expectWebout - when set to true, the automatic _webout fileref will be checked for content, and that content returned. This fileref is used when the Job contains a SASjs web request (as opposed to executing arbitrary SAS code).
|
|
128
135
|
* @param waitForResult - when set to true, function will return the session
|
|
129
|
-
* @param pollOptions - an object that represents poll interval(milliseconds) and maximum amount of attempts. Object example: {
|
|
136
|
+
* @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.
|
|
130
137
|
* @param printPid - a boolean that indicates whether the function should print (PID) of the started job.
|
|
131
138
|
* @param variables - an object that represents macro variables.
|
|
132
139
|
*/
|
|
@@ -206,7 +213,7 @@ export declare class SASViyaApiClient {
|
|
|
206
213
|
* @param accessToken - an optional access token for an authorized user.
|
|
207
214
|
* @param waitForResult - a boolean indicating if the function should wait for a result.
|
|
208
215
|
* @param expectWebout - a boolean indicating whether to expect a _webout response.
|
|
209
|
-
* @param pollOptions - an object that represents poll interval(milliseconds) and maximum amount of attempts. Object example: {
|
|
216
|
+
* @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.
|
|
210
217
|
* @param printPid - a boolean that indicates whether the function should print (PID) of the started job.
|
|
211
218
|
* @param variables - an object that represents macro variables.
|
|
212
219
|
*/
|
|
@@ -219,10 +226,7 @@ export declare class SASViyaApiClient {
|
|
|
219
226
|
* @param data - any data to be passed in as input to the job.
|
|
220
227
|
* @param accessToken - an optional access token for an authorized user.
|
|
221
228
|
*/
|
|
222
|
-
executeJob(sasJob: string, contextName: string, debug: boolean, data?: any, authConfig?: AuthConfig): Promise<
|
|
223
|
-
result: any;
|
|
224
|
-
log: any;
|
|
225
|
-
}>;
|
|
229
|
+
executeJob(sasJob: string, contextName: string, debug: boolean, data?: any, authConfig?: AuthConfig): Promise<JobExecutionResult>;
|
|
226
230
|
private populateFolderMap;
|
|
227
231
|
private pollJobState;
|
|
228
232
|
private uploadTables;
|
|
@@ -263,3 +267,4 @@ export declare class SASViyaApiClient {
|
|
|
263
267
|
*/
|
|
264
268
|
deleteFolder(folderPath: string, accessToken?: string): Promise<Folder | undefined>;
|
|
265
269
|
}
|
|
270
|
+
export {};
|
package/SASjs.d.ts
CHANGED
|
@@ -305,7 +305,7 @@ export default class SASjs {
|
|
|
305
305
|
* @param authConfig - a valid client, secret, refresh and access tokens that are authorised to execute compute jobs.
|
|
306
306
|
* The access token is not required when the user is authenticated via the browser.
|
|
307
307
|
* @param waitForResult - a boolean that indicates whether the function needs to wait for execution to complete.
|
|
308
|
-
* @param pollOptions - an object that represents poll interval(milliseconds) and maximum amount of attempts. Object example: {
|
|
308
|
+
* @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.
|
|
309
309
|
* @param printPid - a boolean that indicates whether the function should print (PID) of the started job.
|
|
310
310
|
* @param variables - an object that represents macro variables.
|
|
311
311
|
*/
|
|
@@ -12,7 +12,7 @@ import { SessionManager } from '../../SessionManager';
|
|
|
12
12
|
* @param debug - when set to true, the log will be returned.
|
|
13
13
|
* @param expectWebout - when set to true, the automatic _webout fileref will be checked for content, and that content returned. This fileref is used when the Job contains a SASjs web request (as opposed to executing arbitrary SAS code).
|
|
14
14
|
* @param waitForResult - when set to true, function will return the session
|
|
15
|
-
* @param pollOptions - an object that represents poll interval(milliseconds) and maximum amount of attempts. Object example: {
|
|
15
|
+
* @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
16
|
* @param printPid - a boolean that indicates whether the function should print (PID) of the started job.
|
|
17
17
|
* @param variables - an object that represents macro variables.
|
|
18
18
|
*/
|
|
@@ -1,4 +1,36 @@
|
|
|
1
1
|
import { AuthConfig } from '@sasjs/utils/types';
|
|
2
2
|
import { Job, PollOptions } from '../..';
|
|
3
3
|
import { RequestClient } from '../../request/RequestClient';
|
|
4
|
-
export declare
|
|
4
|
+
export declare enum JobState {
|
|
5
|
+
Completed = "completed",
|
|
6
|
+
Running = "running",
|
|
7
|
+
Pending = "pending",
|
|
8
|
+
Unavailable = "unavailable",
|
|
9
|
+
NoState = "",
|
|
10
|
+
Failed = "failed",
|
|
11
|
+
Error = "error"
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Polls job status using default or provided poll options.
|
|
15
|
+
* @param requestClient - the pre-configured HTTP request client.
|
|
16
|
+
* @param postedJob - the relative or absolute path to the job.
|
|
17
|
+
* @param debug - sets the _debug flag in the job arguments.
|
|
18
|
+
* @param authConfig - an access token, refresh token, client and secret for an authorized user.
|
|
19
|
+
* @param pollOptions - an object containing maxPollCount, pollInterval, streamLog and logFolderPath. It will override the first default poll options in poll strategy if provided.
|
|
20
|
+
* Example pollOptions:
|
|
21
|
+
* {
|
|
22
|
+
* maxPollCount: 200,
|
|
23
|
+
* pollInterval: 300,
|
|
24
|
+
* streamLog: true, // optional, equals to false by default.
|
|
25
|
+
* pollStrategy?: // optional array of poll options that should be applied after 'maxPollCount' of the provided poll options is reached. If not provided the default (see example below) poll strategy will be used.
|
|
26
|
+
* }
|
|
27
|
+
* Example pollStrategy (values used from default poll strategy):
|
|
28
|
+
* [
|
|
29
|
+
* { maxPollCount: 200, pollInterval: 300 }, // approximately ~2 mins (including time to get response (~300ms))
|
|
30
|
+
* { maxPollCount: 300, pollInterval: 3000 }, // approximately ~5.5 mins (including time to get response (~300ms))
|
|
31
|
+
* { maxPollCount: 500, pollInterval: 30000 }, // approximately ~50.5 mins (including time to get response (~300ms))
|
|
32
|
+
* { maxPollCount: 3400, pollInterval: 60000 } // approximately ~3015 mins (~125 hours) (including time to get response (~300ms))
|
|
33
|
+
* ]
|
|
34
|
+
* @returns - a promise which resolves with a job state
|
|
35
|
+
*/
|
|
36
|
+
export declare function pollJobState(requestClient: RequestClient, postedJob: Job, debug: boolean, authConfig?: AuthConfig, pollOptions?: PollOptions): Promise<JobState>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { SasAuthResponse } from '@sasjs/utils/types';
|
|
2
2
|
import { RequestClient } from '../request/RequestClient';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* @param requestClient - the pre-configured HTTP request client
|
|
4
|
+
* Exchange the auth code for access / refresh tokens for the given client / secret pair.
|
|
5
|
+
* @param requestClient - the pre-configured HTTP request client.
|
|
6
6
|
* @param clientId - the client ID to authenticate with.
|
|
7
7
|
* @param clientSecret - the client secret to authenticate with.
|
|
8
8
|
* @param authCode - the auth code received from the server.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ServerType } from '@sasjs/utils/types';
|
|
2
|
+
declare type Server = ServerType.SasViya | ServerType.Sasjs;
|
|
3
|
+
declare type Operation = 'fetching access token' | 'refreshing tokens';
|
|
4
|
+
/**
|
|
5
|
+
* Forms error prefix for requests related to token operations.
|
|
6
|
+
* @param operation - string describing operation ('fetching access token' or 'refreshing tokens').
|
|
7
|
+
* @param funcName - name of the function sent the request.
|
|
8
|
+
* @param server - server type (SASVIYA or SASJS).
|
|
9
|
+
* @param url - endpoint used to send the request.
|
|
10
|
+
* @param data - request payload.
|
|
11
|
+
* @param headers - request headers.
|
|
12
|
+
* @param clientId - client ID to authenticate with.
|
|
13
|
+
* @param clientSecret - client secret to authenticate with.
|
|
14
|
+
* @returns - string containing request information. Example:
|
|
15
|
+
* Error while fetching access token from /SASLogon/oauth/token
|
|
16
|
+
* Thrown by the @sasjs/adapter getAccessTokenForViya function.
|
|
17
|
+
* Payload:
|
|
18
|
+
* {
|
|
19
|
+
* "grant_type": "authorization_code",
|
|
20
|
+
* "code": "example_code"
|
|
21
|
+
* }
|
|
22
|
+
* Headers:
|
|
23
|
+
* {
|
|
24
|
+
* "Authorization": "Basic NEdMQXBwOjRHTEFwcDE=",
|
|
25
|
+
* "Accept": "application/json"
|
|
26
|
+
* }
|
|
27
|
+
* ClientId: exampleClientId
|
|
28
|
+
* ClientSecret: exampleClientSecret
|
|
29
|
+
*
|
|
30
|
+
* Response from Viya is below.
|
|
31
|
+
* Auth error: {
|
|
32
|
+
* "error": "invalid_token",
|
|
33
|
+
* "error_description": "No scopes were granted"
|
|
34
|
+
* }
|
|
35
|
+
*/
|
|
36
|
+
export declare const getTokenRequestErrorPrefix: (operation: Operation, funcName: string, server: Server, url: string, data?: {}, headers?: {}, clientId?: string, clientSecret?: string) => string;
|
|
37
|
+
/**
|
|
38
|
+
* Parse error prefix to get response payload.
|
|
39
|
+
* @param prefix - error prefix generated by getTokenRequestErrorPrefix function.
|
|
40
|
+
* @param server - server type (SASVIYA or SASJS).
|
|
41
|
+
* @returns - response payload.
|
|
42
|
+
*/
|
|
43
|
+
export declare const getTokenRequestErrorPrefixResponse: (prefix: string, server: ServerType.SasViya | ServerType.Sasjs) => string;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|