@sasjs/adapter 3.0.1 → 3.2.1
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 +2 -8
- package/SASjs.d.ts +17 -6
- package/SASjsApiClient.d.ts +22 -0
- package/auth/AuthManager.d.ts +14 -1
- package/auth/getAccessTokenForSasjs.d.ts +11 -0
- package/{node/auth/getAccessToken.d.ts → auth/getAccessTokenForViya.d.ts} +1 -1
- package/auth/getAuthCodeForSasjs.d.ts +9 -0
- package/auth/getTokens.d.ts +3 -2
- package/auth/refreshTokensForSasjs.d.ts +10 -0
- package/auth/{refreshTokens.d.ts → refreshTokensForViya.d.ts} +2 -2
- package/auth/spec/{getAccessToken.spec.d.ts → getAccessTokenForSasjs.spec.d.ts} +0 -0
- package/auth/spec/{refreshTokens.spec.d.ts → getAccessTokenForViya.spec.d.ts} +0 -0
- package/auth/spec/mockResponses.d.ts +4 -0
- package/auth/spec/refreshTokensForSasjs.spec.d.ts +1 -0
- package/auth/spec/refreshTokensForViya.spec.d.ts +1 -0
- package/index.js +2 -2
- package/job-execution/Sas9JobExecutor.d.ts +4 -5
- package/node/SASViyaApiClient.d.ts +2 -8
- package/node/SASjs.d.ts +17 -6
- package/node/SASjsApiClient.d.ts +22 -0
- package/node/auth/AuthManager.d.ts +14 -1
- package/node/auth/getAccessTokenForSasjs.d.ts +11 -0
- package/{auth/getAccessToken.d.ts → node/auth/getAccessTokenForViya.d.ts} +1 -1
- package/node/auth/getAuthCodeForSasjs.d.ts +9 -0
- package/node/auth/getTokens.d.ts +3 -2
- package/node/auth/refreshTokensForSasjs.d.ts +10 -0
- package/node/auth/{refreshTokens.d.ts → refreshTokensForViya.d.ts} +2 -2
- package/node/index.js +2 -2
- package/node/job-execution/Sas9JobExecutor.d.ts +4 -5
- package/node/request/RequestClient.d.ts +4 -0
- package/node/request/SasjsRequestClient.d.ts +8 -0
- package/node/types/SASjsConfig.d.ts +5 -0
- package/node/utils/getValidJson.d.ts +1 -1
- package/node/utils/parseViyaDebugResponse.d.ts +1 -1
- package/package.json +2 -2
- package/request/RequestClient.d.ts +4 -0
- package/request/SasjsRequestClient.d.ts +8 -0
- package/src/SASViyaApiClient.ts +10 -5
- package/src/SASjs.ts +84 -42
- package/src/SASjsApiClient.ts +43 -0
- package/src/auth/AuthManager.ts +72 -6
- package/src/auth/getAccessTokenForSasjs.ts +36 -0
- package/src/auth/{getAccessToken.ts → getAccessTokenForViya.ts} +1 -1
- package/src/auth/getAuthCodeForSasjs.ts +31 -0
- package/src/auth/getTokens.ts +16 -9
- package/src/auth/refreshTokensForSasjs.ts +35 -0
- package/src/auth/{refreshTokens.ts → refreshTokensForViya.ts} +2 -2
- package/src/auth/spec/mockResponses.ts +5 -0
- package/src/job-execution/Sas9JobExecutor.ts +34 -4
- package/src/job-execution/WebJobExecutor.ts +18 -3
- package/src/request/RequestClient.ts +11 -0
- package/src/request/Sas9RequestClient.ts +1 -1
- package/src/request/SasjsRequestClient.ts +23 -0
- package/src/types/SASjsConfig.ts +5 -0
- package/src/utils/getValidJson.ts +1 -1
- package/src/utils/parseWeboutResponse.ts +1 -1
- package/types/SASjsConfig.d.ts +5 -0
- package/utils/getValidJson.d.ts +1 -1
- package/utils/parseViyaDebugResponse.d.ts +1 -1
- package/CHANGELOG.md +0 -213
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import * as https from 'https';
|
|
3
3
|
import { ServerType } from '@sasjs/utils/types';
|
|
4
4
|
import { BaseJobExecutor } from './JobExecutor';
|
|
5
|
+
import { RequestClient } from '../request/RequestClient';
|
|
5
6
|
/**
|
|
6
7
|
* Job executor for SAS9 servers for use in Node.js environments.
|
|
7
8
|
* Initiates login with the provided username and password from the config
|
|
@@ -11,10 +12,8 @@ import { BaseJobExecutor } from './JobExecutor';
|
|
|
11
12
|
export declare class Sas9JobExecutor extends BaseJobExecutor {
|
|
12
13
|
private jobsPath;
|
|
13
14
|
private requestClient;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
etag: string;
|
|
18
|
-
}>;
|
|
15
|
+
private sas9RequestClient;
|
|
16
|
+
constructor(serverUrl: string, serverType: ServerType, jobsPath: string, requestClient: RequestClient, httpsAgentOptions?: https.AgentOptions);
|
|
17
|
+
execute(sasJob: string, data: any, config: any): Promise<any>;
|
|
19
18
|
private getRequestParams;
|
|
20
19
|
}
|
|
@@ -27,7 +27,9 @@ export interface HttpClient {
|
|
|
27
27
|
etag: string;
|
|
28
28
|
}>;
|
|
29
29
|
getCsrfToken(type: 'general' | 'file'): CsrfToken | undefined;
|
|
30
|
+
saveLocalStorageToken(accessToken: string, refreshToken: string): void;
|
|
30
31
|
clearCsrfTokens(): void;
|
|
32
|
+
clearLocalStorageTokens(): void;
|
|
31
33
|
getBaseUrl(): string;
|
|
32
34
|
}
|
|
33
35
|
export declare class RequestClient implements HttpClient {
|
|
@@ -38,8 +40,10 @@ export declare class RequestClient implements HttpClient {
|
|
|
38
40
|
protected httpClient: AxiosInstance;
|
|
39
41
|
constructor(baseUrl: string, httpsAgentOptions?: https.AgentOptions);
|
|
40
42
|
setConfig(baseUrl: string, httpsAgentOptions?: https.AgentOptions): void;
|
|
43
|
+
saveLocalStorageToken(accessToken: string, refreshToken: string): void;
|
|
41
44
|
getCsrfToken(type?: 'general' | 'file'): CsrfToken | undefined;
|
|
42
45
|
clearCsrfTokens(): void;
|
|
46
|
+
clearLocalStorageTokens(): void;
|
|
43
47
|
getBaseUrl(): string;
|
|
44
48
|
/**
|
|
45
49
|
* this method returns all requests, an array of SASjsRequest type
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RequestClient } from './RequestClient';
|
|
2
|
+
/**
|
|
3
|
+
* Specific request client for SASJS.
|
|
4
|
+
* Append tokens in headers.
|
|
5
|
+
*/
|
|
6
|
+
export declare class SasjsRequestClient extends RequestClient {
|
|
7
|
+
getHeaders: (accessToken: string | undefined, contentType: string) => any;
|
|
8
|
+
}
|
|
@@ -12,6 +12,11 @@ export declare class SASjsConfig {
|
|
|
12
12
|
* streamed.
|
|
13
13
|
*/
|
|
14
14
|
serverUrl: string;
|
|
15
|
+
/**
|
|
16
|
+
* The location of the STP Process Web Application. By default the adapter
|
|
17
|
+
* will use '/SASjsApi/stp/execute' on SAS JS.
|
|
18
|
+
*/
|
|
19
|
+
pathSASJS?: string;
|
|
15
20
|
/**
|
|
16
21
|
* The location of the Stored Process Web Application. By default the adapter
|
|
17
22
|
* will use '/SASStoredProcess/do' on SAS 9.
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* if string passed then parse the string to json else if throw error for all other types unless it is not a valid json object.
|
|
3
3
|
* @param str - string to check.
|
|
4
4
|
*/
|
|
5
|
-
export declare const getValidJson: (str: string | object) =>
|
|
5
|
+
export declare const getValidJson: (str: string | object) => object;
|
|
@@ -9,4 +9,4 @@ import { RequestClient } from '../request/RequestClient';
|
|
|
9
9
|
* @param serverUrl
|
|
10
10
|
* @returns
|
|
11
11
|
*/
|
|
12
|
-
export declare const parseSasViyaDebugResponse: (response: string, requestClient: RequestClient, serverUrl: string) => Promise<
|
|
12
|
+
export declare const parseSasViyaDebugResponse: (response: string, requestClient: RequestClient, serverUrl: string) => Promise<object>;
|
package/package.json
CHANGED
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"ts-loader": "^9.2.6",
|
|
65
65
|
"tslint": "^6.1.3",
|
|
66
66
|
"tslint-config-prettier": "^1.18.0",
|
|
67
|
-
"typedoc": "
|
|
67
|
+
"typedoc": "0.19.2",
|
|
68
68
|
"typedoc-neo-theme": "^1.1.1",
|
|
69
69
|
"typedoc-plugin-external-module-name": "^4.0.6",
|
|
70
70
|
"typescript": "4.3.5",
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"https": "^1.0.0",
|
|
81
81
|
"tough-cookie": "^4.0.0"
|
|
82
82
|
},
|
|
83
|
-
"version": "3.
|
|
83
|
+
"version": "3.2.1"
|
|
84
84
|
}
|
|
@@ -27,7 +27,9 @@ export interface HttpClient {
|
|
|
27
27
|
etag: string;
|
|
28
28
|
}>;
|
|
29
29
|
getCsrfToken(type: 'general' | 'file'): CsrfToken | undefined;
|
|
30
|
+
saveLocalStorageToken(accessToken: string, refreshToken: string): void;
|
|
30
31
|
clearCsrfTokens(): void;
|
|
32
|
+
clearLocalStorageTokens(): void;
|
|
31
33
|
getBaseUrl(): string;
|
|
32
34
|
}
|
|
33
35
|
export declare class RequestClient implements HttpClient {
|
|
@@ -38,8 +40,10 @@ export declare class RequestClient implements HttpClient {
|
|
|
38
40
|
protected httpClient: AxiosInstance;
|
|
39
41
|
constructor(baseUrl: string, httpsAgentOptions?: https.AgentOptions);
|
|
40
42
|
setConfig(baseUrl: string, httpsAgentOptions?: https.AgentOptions): void;
|
|
43
|
+
saveLocalStorageToken(accessToken: string, refreshToken: string): void;
|
|
41
44
|
getCsrfToken(type?: 'general' | 'file'): CsrfToken | undefined;
|
|
42
45
|
clearCsrfTokens(): void;
|
|
46
|
+
clearLocalStorageTokens(): void;
|
|
43
47
|
getBaseUrl(): string;
|
|
44
48
|
/**
|
|
45
49
|
* this method returns all requests, an array of SASjsRequest type
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RequestClient } from './RequestClient';
|
|
2
|
+
/**
|
|
3
|
+
* Specific request client for SASJS.
|
|
4
|
+
* Append tokens in headers.
|
|
5
|
+
*/
|
|
6
|
+
export declare class SasjsRequestClient extends RequestClient {
|
|
7
|
+
getHeaders: (accessToken: string | undefined, contentType: string) => any;
|
|
8
|
+
}
|
package/src/SASViyaApiClient.ts
CHANGED
|
@@ -22,8 +22,8 @@ import { pollJobState } from './api/viya/pollJobState'
|
|
|
22
22
|
import { getTokens } from './auth/getTokens'
|
|
23
23
|
import { uploadTables } from './api/viya/uploadTables'
|
|
24
24
|
import { executeScript } from './api/viya/executeScript'
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
25
|
+
import { getAccessTokenForViya } from './auth/getAccessTokenForViya'
|
|
26
|
+
import { refreshTokensForViya } from './auth/refreshTokensForViya'
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* A client for interfacing with the SAS Viya REST API.
|
|
@@ -534,21 +534,26 @@ export class SASViyaApiClient {
|
|
|
534
534
|
clientSecret: string,
|
|
535
535
|
authCode: string
|
|
536
536
|
): Promise<SasAuthResponse> {
|
|
537
|
-
return
|
|
537
|
+
return getAccessTokenForViya(
|
|
538
|
+
this.requestClient,
|
|
539
|
+
clientId,
|
|
540
|
+
clientSecret,
|
|
541
|
+
authCode
|
|
542
|
+
)
|
|
538
543
|
}
|
|
539
544
|
|
|
540
545
|
/**
|
|
541
546
|
* Exchanges the refresh token for an access token for the given client.
|
|
542
547
|
* @param clientId - the client ID to authenticate with.
|
|
543
548
|
* @param clientSecret - the client secret to authenticate with.
|
|
544
|
-
* @param
|
|
549
|
+
* @param refreshToken - the refresh token received from the server.
|
|
545
550
|
*/
|
|
546
551
|
public async refreshTokens(
|
|
547
552
|
clientId: string,
|
|
548
553
|
clientSecret: string,
|
|
549
554
|
refreshToken: string
|
|
550
555
|
) {
|
|
551
|
-
return
|
|
556
|
+
return refreshTokensForViya(
|
|
552
557
|
this.requestClient,
|
|
553
558
|
clientId,
|
|
554
559
|
clientSecret,
|
package/src/SASjs.ts
CHANGED
|
@@ -11,15 +11,17 @@ import {
|
|
|
11
11
|
} from './types'
|
|
12
12
|
import { SASViyaApiClient } from './SASViyaApiClient'
|
|
13
13
|
import { SAS9ApiClient } from './SAS9ApiClient'
|
|
14
|
-
import { SASjsApiClient } from './SASjsApiClient'
|
|
14
|
+
import { SASjsApiClient, SASjsAuthResponse } from './SASjsApiClient'
|
|
15
15
|
import { AuthManager } from './auth'
|
|
16
16
|
import {
|
|
17
17
|
ServerType,
|
|
18
18
|
MacroVar,
|
|
19
19
|
AuthConfig,
|
|
20
|
-
ExtraResponseAttributes
|
|
20
|
+
ExtraResponseAttributes,
|
|
21
|
+
SasAuthResponse
|
|
21
22
|
} from '@sasjs/utils/types'
|
|
22
23
|
import { RequestClient } from './request/RequestClient'
|
|
24
|
+
import { SasjsRequestClient } from './request/SasjsRequestClient'
|
|
23
25
|
import {
|
|
24
26
|
JobExecutor,
|
|
25
27
|
WebJobExecutor,
|
|
@@ -33,6 +35,7 @@ import { LoginOptions, LoginResult } from './types/Login'
|
|
|
33
35
|
|
|
34
36
|
const defaultConfig: SASjsConfig = {
|
|
35
37
|
serverUrl: '',
|
|
38
|
+
pathSASJS: '/SASjsApi/stp/execute',
|
|
36
39
|
pathSAS9: '/SASStoredProcess/do',
|
|
37
40
|
pathSASViya: '/SASJobExecution',
|
|
38
41
|
appLoc: '/Public/seedapp',
|
|
@@ -52,7 +55,7 @@ export default class SASjs {
|
|
|
52
55
|
private jobsPath: string = ''
|
|
53
56
|
private sasViyaApiClient: SASViyaApiClient | null = null
|
|
54
57
|
private sas9ApiClient: SAS9ApiClient | null = null
|
|
55
|
-
private
|
|
58
|
+
private sasJSApiClient: SASjsApiClient | null = null
|
|
56
59
|
private fileUploader: FileUploader | null = null
|
|
57
60
|
private authManager: AuthManager | null = null
|
|
58
61
|
private requestClient: RequestClient | null = null
|
|
@@ -79,7 +82,7 @@ export default class SASjs {
|
|
|
79
82
|
userName: string,
|
|
80
83
|
password: string
|
|
81
84
|
) {
|
|
82
|
-
this.isMethodSupported('executeScriptSAS9', ServerType.Sas9)
|
|
85
|
+
this.isMethodSupported('executeScriptSAS9', [ServerType.Sas9])
|
|
83
86
|
|
|
84
87
|
return await this.sas9ApiClient?.executeScript(
|
|
85
88
|
linesOfCode,
|
|
@@ -93,7 +96,7 @@ export default class SASjs {
|
|
|
93
96
|
* @param accessToken - an access token for an authorized user.
|
|
94
97
|
*/
|
|
95
98
|
public async getComputeContexts(accessToken: string) {
|
|
96
|
-
this.isMethodSupported('getComputeContexts', ServerType.SasViya)
|
|
99
|
+
this.isMethodSupported('getComputeContexts', [ServerType.SasViya])
|
|
97
100
|
|
|
98
101
|
return await this.sasViyaApiClient!.getComputeContexts(accessToken)
|
|
99
102
|
}
|
|
@@ -103,7 +106,7 @@ export default class SASjs {
|
|
|
103
106
|
* @param accessToken - an access token for an authorized user.
|
|
104
107
|
*/
|
|
105
108
|
public async getLauncherContexts(accessToken: string) {
|
|
106
|
-
this.isMethodSupported('getLauncherContexts', ServerType.SasViya)
|
|
109
|
+
this.isMethodSupported('getLauncherContexts', [ServerType.SasViya])
|
|
107
110
|
|
|
108
111
|
return await this.sasViyaApiClient!.getLauncherContexts(accessToken)
|
|
109
112
|
}
|
|
@@ -112,7 +115,7 @@ export default class SASjs {
|
|
|
112
115
|
* Gets default(system) launcher contexts.
|
|
113
116
|
*/
|
|
114
117
|
public getDefaultComputeContexts() {
|
|
115
|
-
this.isMethodSupported('getDefaultComputeContexts', ServerType.SasViya)
|
|
118
|
+
this.isMethodSupported('getDefaultComputeContexts', [ServerType.SasViya])
|
|
116
119
|
|
|
117
120
|
return this.sasViyaApiClient!.getDefaultComputeContexts()
|
|
118
121
|
}
|
|
@@ -122,7 +125,7 @@ export default class SASjs {
|
|
|
122
125
|
* @param authConfig - an access token, refresh token, client and secret for an authorized user.
|
|
123
126
|
*/
|
|
124
127
|
public async getExecutableContexts(authConfig: AuthConfig) {
|
|
125
|
-
this.isMethodSupported('getExecutableContexts', ServerType.SasViya)
|
|
128
|
+
this.isMethodSupported('getExecutableContexts', [ServerType.SasViya])
|
|
126
129
|
|
|
127
130
|
return await this.sasViyaApiClient!.getExecutableContexts(authConfig)
|
|
128
131
|
}
|
|
@@ -144,7 +147,7 @@ export default class SASjs {
|
|
|
144
147
|
accessToken: string,
|
|
145
148
|
authorizedUsers?: string[]
|
|
146
149
|
) {
|
|
147
|
-
this.isMethodSupported('createComputeContext', ServerType.SasViya)
|
|
150
|
+
this.isMethodSupported('createComputeContext', [ServerType.SasViya])
|
|
148
151
|
|
|
149
152
|
return await this.sasViyaApiClient!.createComputeContext(
|
|
150
153
|
contextName,
|
|
@@ -169,7 +172,7 @@ export default class SASjs {
|
|
|
169
172
|
launchType: string,
|
|
170
173
|
accessToken: string
|
|
171
174
|
) {
|
|
172
|
-
this.isMethodSupported('createLauncherContext', ServerType.SasViya)
|
|
175
|
+
this.isMethodSupported('createLauncherContext', [ServerType.SasViya])
|
|
173
176
|
|
|
174
177
|
return await this.sasViyaApiClient!.createLauncherContext(
|
|
175
178
|
contextName,
|
|
@@ -190,7 +193,7 @@ export default class SASjs {
|
|
|
190
193
|
editedContext: EditContextInput,
|
|
191
194
|
accessToken?: string
|
|
192
195
|
) {
|
|
193
|
-
this.isMethodSupported('editComputeContext', ServerType.SasViya)
|
|
196
|
+
this.isMethodSupported('editComputeContext', [ServerType.SasViya])
|
|
194
197
|
|
|
195
198
|
return await this.sasViyaApiClient!.editComputeContext(
|
|
196
199
|
contextName,
|
|
@@ -205,7 +208,7 @@ export default class SASjs {
|
|
|
205
208
|
* @param accessToken - an access token for an authorized user.
|
|
206
209
|
*/
|
|
207
210
|
public async deleteComputeContext(contextName: string, accessToken?: string) {
|
|
208
|
-
this.isMethodSupported('deleteComputeContext', ServerType.SasViya)
|
|
211
|
+
this.isMethodSupported('deleteComputeContext', [ServerType.SasViya])
|
|
209
212
|
|
|
210
213
|
return await this.sasViyaApiClient!.deleteComputeContext(
|
|
211
214
|
contextName,
|
|
@@ -223,7 +226,7 @@ export default class SASjs {
|
|
|
223
226
|
contextName: string,
|
|
224
227
|
accessToken?: string
|
|
225
228
|
) {
|
|
226
|
-
this.isMethodSupported('getComputeContextByName', ServerType.SasViya)
|
|
229
|
+
this.isMethodSupported('getComputeContextByName', [ServerType.SasViya])
|
|
227
230
|
|
|
228
231
|
return await this.sasViyaApiClient!.getComputeContextByName(
|
|
229
232
|
contextName,
|
|
@@ -237,7 +240,7 @@ export default class SASjs {
|
|
|
237
240
|
* @param accessToken - an access token for an authorized user.
|
|
238
241
|
*/
|
|
239
242
|
public async getComputeContextById(contextId: string, accessToken?: string) {
|
|
240
|
-
this.isMethodSupported('getComputeContextById', ServerType.SasViya)
|
|
243
|
+
this.isMethodSupported('getComputeContextById', [ServerType.SasViya])
|
|
241
244
|
|
|
242
245
|
return await this.sasViyaApiClient!.getComputeContextById(
|
|
243
246
|
contextId,
|
|
@@ -246,7 +249,7 @@ export default class SASjs {
|
|
|
246
249
|
}
|
|
247
250
|
|
|
248
251
|
public async createSession(contextName: string, accessToken: string) {
|
|
249
|
-
this.isMethodSupported('createSession', ServerType.SasViya)
|
|
252
|
+
this.isMethodSupported('createSession', [ServerType.SasViya])
|
|
250
253
|
|
|
251
254
|
return await this.sasViyaApiClient!.createSession(contextName, accessToken)
|
|
252
255
|
}
|
|
@@ -266,7 +269,7 @@ export default class SASjs {
|
|
|
266
269
|
authConfig?: AuthConfig,
|
|
267
270
|
debug?: boolean
|
|
268
271
|
) {
|
|
269
|
-
this.isMethodSupported('executeScriptSASViya', ServerType.SasViya)
|
|
272
|
+
this.isMethodSupported('executeScriptSASViya', [ServerType.SasViya])
|
|
270
273
|
if (!contextName) {
|
|
271
274
|
throw new Error(
|
|
272
275
|
'Context name is undefined. Please set a `contextName` in your SASjs or override config.'
|
|
@@ -356,7 +359,7 @@ export default class SASjs {
|
|
|
356
359
|
* @param accessToken - the access token to authorize the request.
|
|
357
360
|
*/
|
|
358
361
|
public async getFolder(folderPath: string, accessToken?: string) {
|
|
359
|
-
this.isMethodSupported('getFolder', ServerType.SasViya)
|
|
362
|
+
this.isMethodSupported('getFolder', [ServerType.SasViya])
|
|
360
363
|
return await this.sasViyaApiClient!.getFolder(folderPath, accessToken)
|
|
361
364
|
}
|
|
362
365
|
|
|
@@ -366,7 +369,7 @@ export default class SASjs {
|
|
|
366
369
|
* @param accessToken - an access token for authorizing the request.
|
|
367
370
|
*/
|
|
368
371
|
public async deleteFolder(folderPath: string, accessToken: string) {
|
|
369
|
-
this.isMethodSupported('deleteFolder', ServerType.SasViya)
|
|
372
|
+
this.isMethodSupported('deleteFolder', [ServerType.SasViya])
|
|
370
373
|
|
|
371
374
|
return await this.sasViyaApiClient?.deleteFolder(folderPath, accessToken)
|
|
372
375
|
}
|
|
@@ -381,7 +384,7 @@ export default class SASjs {
|
|
|
381
384
|
accessToken?: string,
|
|
382
385
|
limit?: number
|
|
383
386
|
) {
|
|
384
|
-
this.isMethodSupported('listFolder', ServerType.SasViya)
|
|
387
|
+
this.isMethodSupported('listFolder', [ServerType.SasViya])
|
|
385
388
|
|
|
386
389
|
return await this.sasViyaApiClient?.listFolder(
|
|
387
390
|
sourceFolder,
|
|
@@ -403,7 +406,7 @@ export default class SASjs {
|
|
|
403
406
|
targetFolderName: string,
|
|
404
407
|
accessToken: string
|
|
405
408
|
) {
|
|
406
|
-
this.isMethodSupported('moveFolder', ServerType.SasViya)
|
|
409
|
+
this.isMethodSupported('moveFolder', [ServerType.SasViya])
|
|
407
410
|
|
|
408
411
|
return await this.sasViyaApiClient?.moveFolder(
|
|
409
412
|
sourceFolder,
|
|
@@ -421,7 +424,7 @@ export default class SASjs {
|
|
|
421
424
|
accessToken?: string,
|
|
422
425
|
sasApiClient?: SASViyaApiClient
|
|
423
426
|
) {
|
|
424
|
-
this.isMethodSupported('createJobDefinition', ServerType.SasViya)
|
|
427
|
+
this.isMethodSupported('createJobDefinition', [ServerType.SasViya])
|
|
425
428
|
|
|
426
429
|
if (sasApiClient)
|
|
427
430
|
return await sasApiClient!.createJobDefinition(
|
|
@@ -441,7 +444,7 @@ export default class SASjs {
|
|
|
441
444
|
}
|
|
442
445
|
|
|
443
446
|
public async getAuthCode(clientId: string) {
|
|
444
|
-
this.isMethodSupported('getAuthCode', ServerType.SasViya)
|
|
447
|
+
this.isMethodSupported('getAuthCode', [ServerType.SasViya])
|
|
445
448
|
|
|
446
449
|
return await this.sasViyaApiClient!.getAuthCode(clientId)
|
|
447
450
|
}
|
|
@@ -456,8 +459,14 @@ export default class SASjs {
|
|
|
456
459
|
clientId: string,
|
|
457
460
|
clientSecret: string,
|
|
458
461
|
authCode: string
|
|
459
|
-
) {
|
|
460
|
-
this.isMethodSupported('getAccessToken',
|
|
462
|
+
): Promise<SasAuthResponse | SASjsAuthResponse> {
|
|
463
|
+
this.isMethodSupported('getAccessToken', [
|
|
464
|
+
ServerType.SasViya,
|
|
465
|
+
ServerType.Sasjs
|
|
466
|
+
])
|
|
467
|
+
|
|
468
|
+
if (this.sasjsConfig.serverType === ServerType.Sasjs)
|
|
469
|
+
return await this.sasJSApiClient!.getAccessToken(clientId, authCode)
|
|
461
470
|
|
|
462
471
|
return await this.sasViyaApiClient!.getAccessToken(
|
|
463
472
|
clientId,
|
|
@@ -466,12 +475,24 @@ export default class SASjs {
|
|
|
466
475
|
)
|
|
467
476
|
}
|
|
468
477
|
|
|
478
|
+
/**
|
|
479
|
+
* Exchanges the refresh token for an access token for the given client.
|
|
480
|
+
* @param clientId - the client ID to authenticate with.
|
|
481
|
+
* @param clientSecret - the client secret to authenticate with.
|
|
482
|
+
* @param refreshToken - the refresh token received from the server.
|
|
483
|
+
*/
|
|
469
484
|
public async refreshTokens(
|
|
470
485
|
clientId: string,
|
|
471
486
|
clientSecret: string,
|
|
472
487
|
refreshToken: string
|
|
473
|
-
) {
|
|
474
|
-
this.isMethodSupported('refreshTokens',
|
|
488
|
+
): Promise<SasAuthResponse | SASjsAuthResponse> {
|
|
489
|
+
this.isMethodSupported('refreshTokens', [
|
|
490
|
+
ServerType.SasViya,
|
|
491
|
+
ServerType.Sasjs
|
|
492
|
+
])
|
|
493
|
+
|
|
494
|
+
if (this.sasjsConfig.serverType === ServerType.Sasjs)
|
|
495
|
+
return await this.sasJSApiClient!.refreshTokens(refreshToken)
|
|
475
496
|
|
|
476
497
|
return await this.sasViyaApiClient!.refreshTokens(
|
|
477
498
|
clientId,
|
|
@@ -481,7 +502,7 @@ export default class SASjs {
|
|
|
481
502
|
}
|
|
482
503
|
|
|
483
504
|
public async deleteClient(clientId: string, accessToken: string) {
|
|
484
|
-
this.isMethodSupported('deleteClient', ServerType.SasViya)
|
|
505
|
+
this.isMethodSupported('deleteClient', [ServerType.SasViya])
|
|
485
506
|
|
|
486
507
|
return await this.sasViyaApiClient!.deleteClient(clientId, accessToken)
|
|
487
508
|
}
|
|
@@ -537,18 +558,29 @@ export default class SASjs {
|
|
|
537
558
|
* Logs into the SAS server with the supplied credentials.
|
|
538
559
|
* @param username - a string representing the username.
|
|
539
560
|
* @param password - a string representing the password.
|
|
561
|
+
* @param clientId - a string representing the client ID.
|
|
540
562
|
*/
|
|
541
563
|
public async logIn(
|
|
542
564
|
username?: string,
|
|
543
565
|
password?: string,
|
|
566
|
+
clientId?: string,
|
|
544
567
|
options: LoginOptions = {}
|
|
545
568
|
): Promise<LoginResult> {
|
|
546
569
|
if (this.sasjsConfig.loginMechanism === LoginMechanism.Default) {
|
|
547
|
-
if (!username || !password)
|
|
570
|
+
if (!username || !password)
|
|
548
571
|
throw new Error(
|
|
549
572
|
'A username and password are required when using the default login mechanism.'
|
|
550
573
|
)
|
|
574
|
+
|
|
575
|
+
if (this.sasjsConfig.serverType === ServerType.Sasjs) {
|
|
576
|
+
if (!clientId)
|
|
577
|
+
throw new Error(
|
|
578
|
+
'A username, password and clientId are required when using the default login mechanism with server type SASJS.'
|
|
579
|
+
)
|
|
580
|
+
|
|
581
|
+
return this.authManager!.logInSasjs(username, password, clientId)
|
|
551
582
|
}
|
|
583
|
+
|
|
552
584
|
return this.authManager!.logIn(username, password)
|
|
553
585
|
}
|
|
554
586
|
|
|
@@ -774,7 +806,7 @@ export default class SASjs {
|
|
|
774
806
|
accessToken?: string,
|
|
775
807
|
isForced = false
|
|
776
808
|
) {
|
|
777
|
-
this.isMethodSupported('deployServicePack', ServerType.SasViya)
|
|
809
|
+
this.isMethodSupported('deployServicePack', [ServerType.SasViya])
|
|
778
810
|
|
|
779
811
|
let sasApiClient: any = null
|
|
780
812
|
if (serverUrl || appLoc) {
|
|
@@ -829,11 +861,11 @@ export default class SASjs {
|
|
|
829
861
|
}
|
|
830
862
|
|
|
831
863
|
public async deployToSASjs(members: [FolderMember, ServiceMember]) {
|
|
832
|
-
return await this.
|
|
864
|
+
return await this.sasJSApiClient?.deploy(members, this.sasjsConfig.appLoc)
|
|
833
865
|
}
|
|
834
866
|
|
|
835
867
|
public async executeJobSASjs(query: ExecutionQuery) {
|
|
836
|
-
return await this.
|
|
868
|
+
return await this.sasJSApiClient?.executeJob(query)
|
|
837
869
|
}
|
|
838
870
|
|
|
839
871
|
/**
|
|
@@ -869,7 +901,7 @@ export default class SASjs {
|
|
|
869
901
|
...config
|
|
870
902
|
}
|
|
871
903
|
|
|
872
|
-
this.isMethodSupported('startComputeJob', ServerType.SasViya)
|
|
904
|
+
this.isMethodSupported('startComputeJob', [ServerType.SasViya])
|
|
873
905
|
if (!config.contextName) {
|
|
874
906
|
throw new Error(
|
|
875
907
|
'Context name is undefined. Please set a `contextName` in your SASjs or override config.'
|
|
@@ -961,7 +993,11 @@ export default class SASjs {
|
|
|
961
993
|
}
|
|
962
994
|
|
|
963
995
|
if (!this.requestClient) {
|
|
964
|
-
|
|
996
|
+
const RequestClientClass =
|
|
997
|
+
this.sasjsConfig.serverType === ServerType.Sasjs
|
|
998
|
+
? SasjsRequestClient
|
|
999
|
+
: RequestClient
|
|
1000
|
+
this.requestClient = new RequestClientClass(
|
|
965
1001
|
this.sasjsConfig.serverUrl,
|
|
966
1002
|
this.sasjsConfig.httpsAgentOptions
|
|
967
1003
|
)
|
|
@@ -975,7 +1011,9 @@ export default class SASjs {
|
|
|
975
1011
|
this.jobsPath =
|
|
976
1012
|
this.sasjsConfig.serverType === ServerType.SasViya
|
|
977
1013
|
? this.sasjsConfig.pathSASViya
|
|
978
|
-
: this.sasjsConfig.
|
|
1014
|
+
: this.sasjsConfig.serverType === ServerType.Sas9
|
|
1015
|
+
? this.sasjsConfig.pathSAS9
|
|
1016
|
+
: this.sasjsConfig.pathSASJS || ''
|
|
979
1017
|
|
|
980
1018
|
this.authManager = new AuthManager(
|
|
981
1019
|
this.sasjsConfig.serverUrl,
|
|
@@ -1015,10 +1053,10 @@ export default class SASjs {
|
|
|
1015
1053
|
}
|
|
1016
1054
|
|
|
1017
1055
|
if (this.sasjsConfig.serverType === ServerType.Sasjs) {
|
|
1018
|
-
if (this.
|
|
1019
|
-
this.
|
|
1056
|
+
if (this.sasJSApiClient) {
|
|
1057
|
+
this.sasJSApiClient.setConfig(this.sasjsConfig.serverUrl)
|
|
1020
1058
|
} else {
|
|
1021
|
-
this.
|
|
1059
|
+
this.sasJSApiClient = new SASjsApiClient(
|
|
1022
1060
|
this.sasjsConfig.serverUrl,
|
|
1023
1061
|
this.requestClient
|
|
1024
1062
|
)
|
|
@@ -1044,6 +1082,7 @@ export default class SASjs {
|
|
|
1044
1082
|
this.sasjsConfig.serverUrl,
|
|
1045
1083
|
this.sasjsConfig.serverType!,
|
|
1046
1084
|
this.jobsPath,
|
|
1085
|
+
this.requestClient,
|
|
1047
1086
|
this.sasjsConfig.httpsAgentOptions
|
|
1048
1087
|
)
|
|
1049
1088
|
|
|
@@ -1111,12 +1150,15 @@ export default class SASjs {
|
|
|
1111
1150
|
})
|
|
1112
1151
|
}
|
|
1113
1152
|
|
|
1114
|
-
private isMethodSupported(method: string,
|
|
1115
|
-
if (
|
|
1153
|
+
private isMethodSupported(method: string, serverTypes: ServerType[]) {
|
|
1154
|
+
if (
|
|
1155
|
+
!this.sasjsConfig.serverType ||
|
|
1156
|
+
!serverTypes.includes(this.sasjsConfig.serverType)
|
|
1157
|
+
) {
|
|
1116
1158
|
throw new Error(
|
|
1117
|
-
`Method '${method}' is only supported on ${
|
|
1118
|
-
|
|
1119
|
-
} servers.`
|
|
1159
|
+
`Method '${method}' is only supported on ${serverTypes.join(
|
|
1160
|
+
', '
|
|
1161
|
+
)} servers.`
|
|
1120
1162
|
)
|
|
1121
1163
|
}
|
|
1122
1164
|
}
|
package/src/SASjsApiClient.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { FolderMember, ServiceMember, ExecutionQuery } from './types'
|
|
2
2
|
import { RequestClient } from './request/RequestClient'
|
|
3
|
+
import { getAccessTokenForSasjs } from './auth/getAccessTokenForSasjs'
|
|
4
|
+
import { refreshTokensForSasjs } from './auth/refreshTokensForSasjs'
|
|
5
|
+
import { getAuthCodeForSasjs } from './auth/getAuthCodeForSasjs'
|
|
3
6
|
|
|
4
7
|
export class SASjsApiClient {
|
|
5
8
|
constructor(
|
|
@@ -36,4 +39,44 @@ export class SASjsApiClient {
|
|
|
36
39
|
|
|
37
40
|
return Promise.resolve(result)
|
|
38
41
|
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Exchanges the auth code for an access token for the given client.
|
|
45
|
+
* @param clientId - the client ID to authenticate with.
|
|
46
|
+
* @param authCode - the auth code received from the server.
|
|
47
|
+
*/
|
|
48
|
+
public async getAccessToken(
|
|
49
|
+
clientId: string,
|
|
50
|
+
authCode: string
|
|
51
|
+
): Promise<SASjsAuthResponse> {
|
|
52
|
+
return getAccessTokenForSasjs(this.requestClient, clientId, authCode)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Exchanges the refresh token for an access token.
|
|
57
|
+
* @param refreshToken - the refresh token received from the server.
|
|
58
|
+
*/
|
|
59
|
+
public async refreshTokens(refreshToken: string): Promise<SASjsAuthResponse> {
|
|
60
|
+
return refreshTokensForSasjs(this.requestClient, refreshToken)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Performs a login authenticate and returns an auth code for the given client.
|
|
65
|
+
* @param username - a string representing the username.
|
|
66
|
+
* @param password - a string representing the password.
|
|
67
|
+
* @param clientId - the client ID to authenticate with.
|
|
68
|
+
*/
|
|
69
|
+
public async getAuthCode(
|
|
70
|
+
username: string,
|
|
71
|
+
password: string,
|
|
72
|
+
clientId: string
|
|
73
|
+
) {
|
|
74
|
+
return getAuthCodeForSasjs(this.requestClient, username, password, clientId)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// todo move to sasjs/utils
|
|
79
|
+
export interface SASjsAuthResponse {
|
|
80
|
+
access_token: string
|
|
81
|
+
refresh_token: string
|
|
39
82
|
}
|