@sasjs/adapter 4.7.0 → 4.9.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/README.md +6 -1
- package/SASjs.d.ts +31 -5
- package/index-dev.js +2 -2
- package/index.js +1 -1
- package/minified/sas9/SASjs.d.ts +1 -1
- package/minified_sas9.js +1 -1
- package/node/SASjs.d.ts +31 -5
- package/node/index.js +1 -1
- package/node/request/RequestClient.d.ts +9 -31
- package/node/request/SasjsRequestClient.d.ts +1 -7
- package/node/types/RequestClient.d.ts +46 -0
- package/node/types/SASjsConfig.d.ts +5 -0
- package/node/types/index.d.ts +3 -1
- package/node/utils/compareTimestamps.d.ts +1 -1
- package/package.json +1 -1
- package/request/RequestClient.d.ts +9 -31
- package/request/SasjsRequestClient.d.ts +1 -7
- package/src/SASjs.ts +59 -8
- package/src/minified/sas9/SASjs.ts +2 -1
- package/src/minified/sas9/WebJobExecutor.ts +0 -1
- package/src/request/RequestClient.ts +23 -38
- package/src/request/SasjsRequestClient.ts +1 -9
- package/src/types/RequestClient.ts +55 -0
- package/src/types/SASjsConfig.ts +5 -0
- package/src/types/index.ts +3 -1
- package/src/utils/compareTimestamps.ts +1 -1
- package/types/RequestClient.d.ts +46 -0
- package/types/SASjsConfig.d.ts +5 -0
- package/types/index.d.ts +3 -1
- package/utils/compareTimestamps.d.ts +1 -1
- package/node/types/SASjsRequest.d.ts +0 -12
- package/src/types/SASjsRequest.ts +0 -12
- package/types/SASjsRequest.d.ts +0 -12
|
@@ -2,45 +2,17 @@
|
|
|
2
2
|
import { AxiosInstance, AxiosResponse } from 'axios';
|
|
3
3
|
import * as https from 'https';
|
|
4
4
|
import { CsrfToken } from '..';
|
|
5
|
-
import { SASjsRequest } from '../types';
|
|
6
|
-
export interface HttpClient {
|
|
7
|
-
get<T>(url: string, accessToken: string | undefined, contentType: string, overrideHeaders: {
|
|
8
|
-
[key: string]: string | number;
|
|
9
|
-
}): Promise<{
|
|
10
|
-
result: T;
|
|
11
|
-
etag: string;
|
|
12
|
-
}>;
|
|
13
|
-
post<T>(url: string, data: any, accessToken: string | undefined, contentType: string, overrideHeaders: {
|
|
14
|
-
[key: string]: string | number;
|
|
15
|
-
}): Promise<{
|
|
16
|
-
result: T;
|
|
17
|
-
etag: string;
|
|
18
|
-
}>;
|
|
19
|
-
put<T>(url: string, data: any, accessToken: string | undefined, overrideHeaders: {
|
|
20
|
-
[key: string]: string | number;
|
|
21
|
-
}): Promise<{
|
|
22
|
-
result: T;
|
|
23
|
-
etag: string;
|
|
24
|
-
}>;
|
|
25
|
-
delete<T>(url: string, accessToken: string | undefined): Promise<{
|
|
26
|
-
result: T;
|
|
27
|
-
etag: string;
|
|
28
|
-
}>;
|
|
29
|
-
getCsrfToken(type: 'general' | 'file'): CsrfToken | undefined;
|
|
30
|
-
saveLocalStorageToken(accessToken: string, refreshToken: string): void;
|
|
31
|
-
clearCsrfTokens(): void;
|
|
32
|
-
clearLocalStorageTokens(): void;
|
|
33
|
-
getBaseUrl(): string;
|
|
34
|
-
}
|
|
5
|
+
import { SASjsRequest, HttpClient, VerboseMode } from '../types';
|
|
35
6
|
export declare class RequestClient implements HttpClient {
|
|
36
7
|
protected baseUrl: string;
|
|
37
8
|
private requests;
|
|
38
9
|
private requestsLimit;
|
|
39
10
|
private httpInterceptor?;
|
|
11
|
+
private verboseMode;
|
|
40
12
|
protected csrfToken: CsrfToken;
|
|
41
13
|
protected fileUploadCsrfToken: CsrfToken | undefined;
|
|
42
14
|
protected httpClient: AxiosInstance;
|
|
43
|
-
constructor(baseUrl: string, httpsAgentOptions?: https.AgentOptions, requestsLimit?: number);
|
|
15
|
+
constructor(baseUrl: string, httpsAgentOptions?: https.AgentOptions, requestsLimit?: number, verboseMode?: VerboseMode);
|
|
44
16
|
setConfig(baseUrl: string, httpsAgentOptions?: https.AgentOptions): void;
|
|
45
17
|
saveLocalStorageToken(accessToken: string, refreshToken: string): void;
|
|
46
18
|
getCsrfToken(type?: 'general' | 'file'): CsrfToken | undefined;
|
|
@@ -96,6 +68,7 @@ export declare class RequestClient implements HttpClient {
|
|
|
96
68
|
authorize: (response: string) => Promise<any>;
|
|
97
69
|
/**
|
|
98
70
|
* Adds colors to the string.
|
|
71
|
+
* If verboseMode is set to 'bleached', colors should be disabled
|
|
99
72
|
* @param str - string to be prettified.
|
|
100
73
|
* @returns - prettified string
|
|
101
74
|
*/
|
|
@@ -107,6 +80,11 @@ export declare class RequestClient implements HttpClient {
|
|
|
107
80
|
*/
|
|
108
81
|
private parseInterceptedBody;
|
|
109
82
|
private defaultInterceptionCallBack;
|
|
83
|
+
/**
|
|
84
|
+
* Sets verbose mode.
|
|
85
|
+
* @param verboseMode - value of the verbose mode, can be true, false or bleached(without extra colors).
|
|
86
|
+
*/
|
|
87
|
+
setVerboseMode: (verboseMode: VerboseMode) => void;
|
|
110
88
|
/**
|
|
111
89
|
* Turns on verbose mode to log every HTTP response.
|
|
112
90
|
* @param successCallBack - function that should be triggered on every HTTP response with the status 2**.
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { RequestClient } from './RequestClient';
|
|
2
2
|
import { AxiosResponse } from 'axios';
|
|
3
|
-
|
|
4
|
-
result: T;
|
|
5
|
-
log: string;
|
|
6
|
-
etag: string;
|
|
7
|
-
status: number;
|
|
8
|
-
printOutput?: string;
|
|
9
|
-
}
|
|
3
|
+
import { SasjsParsedResponse } from '../types';
|
|
10
4
|
/**
|
|
11
5
|
* Specific request client for SASJS.
|
|
12
6
|
* Append tokens in headers.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { CsrfToken } from '..';
|
|
2
|
+
export interface HttpClient {
|
|
3
|
+
get<T>(url: string, accessToken: string | undefined, contentType: string, overrideHeaders: {
|
|
4
|
+
[key: string]: string | number;
|
|
5
|
+
}): Promise<{
|
|
6
|
+
result: T;
|
|
7
|
+
etag: string;
|
|
8
|
+
}>;
|
|
9
|
+
post<T>(url: string, data: any, accessToken: string | undefined, contentType: string, overrideHeaders: {
|
|
10
|
+
[key: string]: string | number;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
result: T;
|
|
13
|
+
etag: string;
|
|
14
|
+
}>;
|
|
15
|
+
put<T>(url: string, data: any, accessToken: string | undefined, overrideHeaders: {
|
|
16
|
+
[key: string]: string | number;
|
|
17
|
+
}): Promise<{
|
|
18
|
+
result: T;
|
|
19
|
+
etag: string;
|
|
20
|
+
}>;
|
|
21
|
+
delete<T>(url: string, accessToken: string | undefined): Promise<{
|
|
22
|
+
result: T;
|
|
23
|
+
etag: string;
|
|
24
|
+
}>;
|
|
25
|
+
getCsrfToken(type: 'general' | 'file'): CsrfToken | undefined;
|
|
26
|
+
saveLocalStorageToken(accessToken: string, refreshToken: string): void;
|
|
27
|
+
clearCsrfTokens(): void;
|
|
28
|
+
clearLocalStorageTokens(): void;
|
|
29
|
+
getBaseUrl(): string;
|
|
30
|
+
}
|
|
31
|
+
export interface SASjsRequest {
|
|
32
|
+
serviceLink: string;
|
|
33
|
+
timestamp: Date;
|
|
34
|
+
sourceCode: string;
|
|
35
|
+
generatedCode: string;
|
|
36
|
+
logFile: string;
|
|
37
|
+
SASWORK: any;
|
|
38
|
+
}
|
|
39
|
+
export interface SasjsParsedResponse<T> {
|
|
40
|
+
result: T;
|
|
41
|
+
log: string;
|
|
42
|
+
etag: string;
|
|
43
|
+
status: number;
|
|
44
|
+
printOutput?: string;
|
|
45
|
+
}
|
|
46
|
+
export declare type VerboseMode = boolean | 'bleached';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import * as https from 'https';
|
|
3
3
|
import { ServerType } from '@sasjs/utils/types';
|
|
4
|
+
import { VerboseMode } from '../types';
|
|
4
5
|
/**
|
|
5
6
|
* Specifies the configuration for the SASjs instance - eg where and how to
|
|
6
7
|
* connect to SAS.
|
|
@@ -45,6 +46,10 @@ export declare class SASjsConfig {
|
|
|
45
46
|
* Set to `true` to enable additional debugging.
|
|
46
47
|
*/
|
|
47
48
|
debug: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Set to `true` to enable verbose mode that will log a summary of every HTTP response.
|
|
51
|
+
*/
|
|
52
|
+
verbose?: VerboseMode;
|
|
48
53
|
/**
|
|
49
54
|
* The name of the compute context to use when calling the Viya services directly.
|
|
50
55
|
* Example value: 'SAS Job Execution compute context'
|
package/node/types/index.d.ts
CHANGED
|
@@ -6,10 +6,12 @@ export * from './Job';
|
|
|
6
6
|
export * from './JobDefinition';
|
|
7
7
|
export * from './JobResult';
|
|
8
8
|
export * from './Link';
|
|
9
|
+
export * from './Login';
|
|
9
10
|
export * from './SASjsConfig';
|
|
10
|
-
export * from './
|
|
11
|
+
export * from './RequestClient';
|
|
11
12
|
export * from './Session';
|
|
12
13
|
export * from './UploadFile';
|
|
13
14
|
export * from './PollOptions';
|
|
14
15
|
export * from './WriteStream';
|
|
15
16
|
export * from './ExecuteScript';
|
|
17
|
+
export * from './errors';
|
package/package.json
CHANGED
|
@@ -2,45 +2,17 @@
|
|
|
2
2
|
import { AxiosInstance, AxiosResponse } from 'axios';
|
|
3
3
|
import * as https from 'https';
|
|
4
4
|
import { CsrfToken } from '..';
|
|
5
|
-
import { SASjsRequest } from '../types';
|
|
6
|
-
export interface HttpClient {
|
|
7
|
-
get<T>(url: string, accessToken: string | undefined, contentType: string, overrideHeaders: {
|
|
8
|
-
[key: string]: string | number;
|
|
9
|
-
}): Promise<{
|
|
10
|
-
result: T;
|
|
11
|
-
etag: string;
|
|
12
|
-
}>;
|
|
13
|
-
post<T>(url: string, data: any, accessToken: string | undefined, contentType: string, overrideHeaders: {
|
|
14
|
-
[key: string]: string | number;
|
|
15
|
-
}): Promise<{
|
|
16
|
-
result: T;
|
|
17
|
-
etag: string;
|
|
18
|
-
}>;
|
|
19
|
-
put<T>(url: string, data: any, accessToken: string | undefined, overrideHeaders: {
|
|
20
|
-
[key: string]: string | number;
|
|
21
|
-
}): Promise<{
|
|
22
|
-
result: T;
|
|
23
|
-
etag: string;
|
|
24
|
-
}>;
|
|
25
|
-
delete<T>(url: string, accessToken: string | undefined): Promise<{
|
|
26
|
-
result: T;
|
|
27
|
-
etag: string;
|
|
28
|
-
}>;
|
|
29
|
-
getCsrfToken(type: 'general' | 'file'): CsrfToken | undefined;
|
|
30
|
-
saveLocalStorageToken(accessToken: string, refreshToken: string): void;
|
|
31
|
-
clearCsrfTokens(): void;
|
|
32
|
-
clearLocalStorageTokens(): void;
|
|
33
|
-
getBaseUrl(): string;
|
|
34
|
-
}
|
|
5
|
+
import { SASjsRequest, HttpClient, VerboseMode } from '../types';
|
|
35
6
|
export declare class RequestClient implements HttpClient {
|
|
36
7
|
protected baseUrl: string;
|
|
37
8
|
private requests;
|
|
38
9
|
private requestsLimit;
|
|
39
10
|
private httpInterceptor?;
|
|
11
|
+
private verboseMode;
|
|
40
12
|
protected csrfToken: CsrfToken;
|
|
41
13
|
protected fileUploadCsrfToken: CsrfToken | undefined;
|
|
42
14
|
protected httpClient: AxiosInstance;
|
|
43
|
-
constructor(baseUrl: string, httpsAgentOptions?: https.AgentOptions, requestsLimit?: number);
|
|
15
|
+
constructor(baseUrl: string, httpsAgentOptions?: https.AgentOptions, requestsLimit?: number, verboseMode?: VerboseMode);
|
|
44
16
|
setConfig(baseUrl: string, httpsAgentOptions?: https.AgentOptions): void;
|
|
45
17
|
saveLocalStorageToken(accessToken: string, refreshToken: string): void;
|
|
46
18
|
getCsrfToken(type?: 'general' | 'file'): CsrfToken | undefined;
|
|
@@ -96,6 +68,7 @@ export declare class RequestClient implements HttpClient {
|
|
|
96
68
|
authorize: (response: string) => Promise<any>;
|
|
97
69
|
/**
|
|
98
70
|
* Adds colors to the string.
|
|
71
|
+
* If verboseMode is set to 'bleached', colors should be disabled
|
|
99
72
|
* @param str - string to be prettified.
|
|
100
73
|
* @returns - prettified string
|
|
101
74
|
*/
|
|
@@ -107,6 +80,11 @@ export declare class RequestClient implements HttpClient {
|
|
|
107
80
|
*/
|
|
108
81
|
private parseInterceptedBody;
|
|
109
82
|
private defaultInterceptionCallBack;
|
|
83
|
+
/**
|
|
84
|
+
* Sets verbose mode.
|
|
85
|
+
* @param verboseMode - value of the verbose mode, can be true, false or bleached(without extra colors).
|
|
86
|
+
*/
|
|
87
|
+
setVerboseMode: (verboseMode: VerboseMode) => void;
|
|
110
88
|
/**
|
|
111
89
|
* Turns on verbose mode to log every HTTP response.
|
|
112
90
|
* @param successCallBack - function that should be triggered on every HTTP response with the status 2**.
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { RequestClient } from './RequestClient';
|
|
2
2
|
import { AxiosResponse } from 'axios';
|
|
3
|
-
|
|
4
|
-
result: T;
|
|
5
|
-
log: string;
|
|
6
|
-
etag: string;
|
|
7
|
-
status: number;
|
|
8
|
-
printOutput?: string;
|
|
9
|
-
}
|
|
3
|
+
import { SasjsParsedResponse } from '../types';
|
|
10
4
|
/**
|
|
11
5
|
* Specific request client for SASJS.
|
|
12
6
|
* Append tokens in headers.
|
package/src/SASjs.ts
CHANGED
|
@@ -4,7 +4,12 @@ import {
|
|
|
4
4
|
UploadFile,
|
|
5
5
|
EditContextInput,
|
|
6
6
|
PollOptions,
|
|
7
|
-
LoginMechanism
|
|
7
|
+
LoginMechanism,
|
|
8
|
+
VerboseMode,
|
|
9
|
+
ErrorResponse,
|
|
10
|
+
LoginOptions,
|
|
11
|
+
LoginResult,
|
|
12
|
+
ExecutionQuery
|
|
8
13
|
} from './types'
|
|
9
14
|
import { SASViyaApiClient } from './SASViyaApiClient'
|
|
10
15
|
import { SAS9ApiClient } from './SAS9ApiClient'
|
|
@@ -29,8 +34,7 @@ import {
|
|
|
29
34
|
Sas9JobExecutor,
|
|
30
35
|
FileUploader
|
|
31
36
|
} from './job-execution'
|
|
32
|
-
import {
|
|
33
|
-
import { LoginOptions, LoginResult } from './types/Login'
|
|
37
|
+
import { AxiosResponse } from 'axios'
|
|
34
38
|
|
|
35
39
|
interface ExecuteScriptParams {
|
|
36
40
|
linesOfCode: string[]
|
|
@@ -157,6 +161,23 @@ export default class SASjs {
|
|
|
157
161
|
}
|
|
158
162
|
}
|
|
159
163
|
|
|
164
|
+
/**
|
|
165
|
+
* Executes job on SASJS server.
|
|
166
|
+
* @param query - an object containing job path and debug level.
|
|
167
|
+
* @param appLoc - an application path.
|
|
168
|
+
* @param authConfig - an object for authentication.
|
|
169
|
+
* @returns a promise that resolves into job execution result and log.
|
|
170
|
+
*/
|
|
171
|
+
public async executeJob(
|
|
172
|
+
query: ExecutionQuery,
|
|
173
|
+
appLoc: string,
|
|
174
|
+
authConfig?: AuthConfig
|
|
175
|
+
) {
|
|
176
|
+
this.isMethodSupported('executeScript', [ServerType.Sasjs])
|
|
177
|
+
|
|
178
|
+
return await this.sasJSApiClient?.executeJob(query, appLoc, authConfig)
|
|
179
|
+
}
|
|
180
|
+
|
|
160
181
|
/**
|
|
161
182
|
* Gets compute contexts.
|
|
162
183
|
* @param accessToken - an access token for an authorised user.
|
|
@@ -854,7 +875,7 @@ export default class SASjs {
|
|
|
854
875
|
* @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.
|
|
855
876
|
* @param printPid - a boolean that indicates whether the function should print (PID) of the started job.
|
|
856
877
|
* @param variables - an object that represents macro variables.
|
|
857
|
-
* @param verboseMode - boolean to enable verbose mode (log every HTTP response).
|
|
878
|
+
* @param verboseMode - boolean or a string equal to 'bleached' to enable verbose mode (log every HTTP response).
|
|
858
879
|
*/
|
|
859
880
|
public async startComputeJob(
|
|
860
881
|
sasJob: string,
|
|
@@ -865,7 +886,7 @@ export default class SASjs {
|
|
|
865
886
|
pollOptions?: PollOptions,
|
|
866
887
|
printPid = false,
|
|
867
888
|
variables?: MacroVar,
|
|
868
|
-
verboseMode?:
|
|
889
|
+
verboseMode?: VerboseMode
|
|
869
890
|
) {
|
|
870
891
|
config = {
|
|
871
892
|
...this.sasjsConfig,
|
|
@@ -879,8 +900,10 @@ export default class SASjs {
|
|
|
879
900
|
)
|
|
880
901
|
}
|
|
881
902
|
|
|
882
|
-
if (verboseMode)
|
|
883
|
-
|
|
903
|
+
if (verboseMode) {
|
|
904
|
+
this.requestClient?.setVerboseMode(verboseMode)
|
|
905
|
+
this.requestClient?.enableVerboseMode()
|
|
906
|
+
} else if (verboseMode === false) this.requestClient?.disableVerboseMode()
|
|
884
907
|
|
|
885
908
|
return this.sasViyaApiClient?.executeComputeJob(
|
|
886
909
|
sasJob,
|
|
@@ -975,7 +998,8 @@ export default class SASjs {
|
|
|
975
998
|
this.requestClient = new RequestClientClass(
|
|
976
999
|
this.sasjsConfig.serverUrl,
|
|
977
1000
|
this.sasjsConfig.httpsAgentOptions,
|
|
978
|
-
this.sasjsConfig.requestHistoryLimit
|
|
1001
|
+
this.sasjsConfig.requestHistoryLimit,
|
|
1002
|
+
this.sasjsConfig.verbose
|
|
979
1003
|
)
|
|
980
1004
|
} else {
|
|
981
1005
|
this.requestClient.setConfig(
|
|
@@ -1139,4 +1163,31 @@ export default class SASjs {
|
|
|
1139
1163
|
)
|
|
1140
1164
|
}
|
|
1141
1165
|
}
|
|
1166
|
+
|
|
1167
|
+
/**
|
|
1168
|
+
* Enables verbose mode that will log a summary of every HTTP response.
|
|
1169
|
+
* @param successCallBack - function that should be triggered on every HTTP response with the status 2**.
|
|
1170
|
+
* @param errorCallBack - function that should be triggered on every HTTP response with the status different from 2**.
|
|
1171
|
+
*/
|
|
1172
|
+
public enableVerboseMode(
|
|
1173
|
+
successCallBack?: (response: AxiosResponse) => AxiosResponse,
|
|
1174
|
+
errorCallBack?: (response: AxiosResponse) => AxiosResponse
|
|
1175
|
+
) {
|
|
1176
|
+
this.requestClient?.enableVerboseMode(successCallBack, errorCallBack)
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
/**
|
|
1180
|
+
* Turns off verbose mode to log every HTTP response.
|
|
1181
|
+
*/
|
|
1182
|
+
public disableVerboseMode() {
|
|
1183
|
+
this.requestClient?.disableVerboseMode()
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
/**
|
|
1187
|
+
* Sets verbose mode.
|
|
1188
|
+
* @param verboseMode - value of the verbose mode, can be true, false or bleached(without extra colors).
|
|
1189
|
+
*/
|
|
1190
|
+
public setVerboseMode = (verboseMode: VerboseMode) => {
|
|
1191
|
+
this.requestClient?.setVerboseMode(verboseMode)
|
|
1192
|
+
}
|
|
1142
1193
|
}
|
|
@@ -233,7 +233,8 @@ export default class SASjs {
|
|
|
233
233
|
this.requestClient = new RequestClient(
|
|
234
234
|
this.sasjsConfig.serverUrl,
|
|
235
235
|
this.sasjsConfig.httpsAgentOptions,
|
|
236
|
-
this.sasjsConfig.requestHistoryLimit
|
|
236
|
+
this.sasjsConfig.requestHistoryLimit,
|
|
237
|
+
this.sasjsConfig.verbose
|
|
237
238
|
)
|
|
238
239
|
} else {
|
|
239
240
|
this.requestClient.setConfig(
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
JobExecutionError,
|
|
11
11
|
CertificateError
|
|
12
12
|
} from '../types/errors'
|
|
13
|
-
import { SASjsRequest } from '../types'
|
|
13
|
+
import { SASjsRequest, HttpClient, VerboseMode } from '../types'
|
|
14
14
|
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
|
|
15
15
|
import { prefixMessage } from '@sasjs/utils/error'
|
|
16
16
|
import { SAS9AuthError } from '../types/errors/SAS9AuthError'
|
|
@@ -22,45 +22,11 @@ import {
|
|
|
22
22
|
import { InvalidSASjsCsrfError } from '../types/errors/InvalidSASjsCsrfError'
|
|
23
23
|
import { inspect } from 'util'
|
|
24
24
|
|
|
25
|
-
export interface HttpClient {
|
|
26
|
-
get<T>(
|
|
27
|
-
url: string,
|
|
28
|
-
accessToken: string | undefined,
|
|
29
|
-
contentType: string,
|
|
30
|
-
overrideHeaders: { [key: string]: string | number }
|
|
31
|
-
): Promise<{ result: T; etag: string }>
|
|
32
|
-
|
|
33
|
-
post<T>(
|
|
34
|
-
url: string,
|
|
35
|
-
data: any,
|
|
36
|
-
accessToken: string | undefined,
|
|
37
|
-
contentType: string,
|
|
38
|
-
overrideHeaders: { [key: string]: string | number }
|
|
39
|
-
): Promise<{ result: T; etag: string }>
|
|
40
|
-
|
|
41
|
-
put<T>(
|
|
42
|
-
url: string,
|
|
43
|
-
data: any,
|
|
44
|
-
accessToken: string | undefined,
|
|
45
|
-
overrideHeaders: { [key: string]: string | number }
|
|
46
|
-
): Promise<{ result: T; etag: string }>
|
|
47
|
-
|
|
48
|
-
delete<T>(
|
|
49
|
-
url: string,
|
|
50
|
-
accessToken: string | undefined
|
|
51
|
-
): Promise<{ result: T; etag: string }>
|
|
52
|
-
|
|
53
|
-
getCsrfToken(type: 'general' | 'file'): CsrfToken | undefined
|
|
54
|
-
saveLocalStorageToken(accessToken: string, refreshToken: string): void
|
|
55
|
-
clearCsrfTokens(): void
|
|
56
|
-
clearLocalStorageTokens(): void
|
|
57
|
-
getBaseUrl(): string
|
|
58
|
-
}
|
|
59
|
-
|
|
60
25
|
export class RequestClient implements HttpClient {
|
|
61
26
|
private requests: SASjsRequest[] = []
|
|
62
27
|
private requestsLimit: number = 10
|
|
63
28
|
private httpInterceptor?: number
|
|
29
|
+
private verboseMode: VerboseMode = false
|
|
64
30
|
|
|
65
31
|
protected csrfToken: CsrfToken = { headerName: '', value: '' }
|
|
66
32
|
protected fileUploadCsrfToken: CsrfToken | undefined
|
|
@@ -69,11 +35,17 @@ export class RequestClient implements HttpClient {
|
|
|
69
35
|
constructor(
|
|
70
36
|
protected baseUrl: string,
|
|
71
37
|
httpsAgentOptions?: https.AgentOptions,
|
|
72
|
-
requestsLimit?: number
|
|
38
|
+
requestsLimit?: number,
|
|
39
|
+
verboseMode?: VerboseMode
|
|
73
40
|
) {
|
|
74
41
|
this.createHttpClient(baseUrl, httpsAgentOptions)
|
|
75
42
|
|
|
76
43
|
if (requestsLimit) this.requestsLimit = requestsLimit
|
|
44
|
+
|
|
45
|
+
if (verboseMode) {
|
|
46
|
+
this.setVerboseMode(verboseMode)
|
|
47
|
+
this.enableVerboseMode()
|
|
48
|
+
}
|
|
77
49
|
}
|
|
78
50
|
|
|
79
51
|
public setConfig(baseUrl: string, httpsAgentOptions?: https.AgentOptions) {
|
|
@@ -395,10 +367,12 @@ export class RequestClient implements HttpClient {
|
|
|
395
367
|
|
|
396
368
|
/**
|
|
397
369
|
* Adds colors to the string.
|
|
370
|
+
* If verboseMode is set to 'bleached', colors should be disabled
|
|
398
371
|
* @param str - string to be prettified.
|
|
399
372
|
* @returns - prettified string
|
|
400
373
|
*/
|
|
401
|
-
private prettifyString = (str: any) =>
|
|
374
|
+
private prettifyString = (str: any) =>
|
|
375
|
+
inspect(str, { colors: this.verboseMode !== 'bleached' })
|
|
402
376
|
|
|
403
377
|
/**
|
|
404
378
|
* Formats HTTP request/response body.
|
|
@@ -468,6 +442,17 @@ ${resHeaders}${parsedResBody ? `\n\n${parsedResBody}` : ''}
|
|
|
468
442
|
return response
|
|
469
443
|
}
|
|
470
444
|
|
|
445
|
+
/**
|
|
446
|
+
* Sets verbose mode.
|
|
447
|
+
* @param verboseMode - value of the verbose mode, can be true, false or bleached(without extra colors).
|
|
448
|
+
*/
|
|
449
|
+
public setVerboseMode = (verboseMode: VerboseMode) => {
|
|
450
|
+
this.verboseMode = verboseMode
|
|
451
|
+
|
|
452
|
+
if (this.verboseMode) this.enableVerboseMode()
|
|
453
|
+
else this.disableVerboseMode()
|
|
454
|
+
}
|
|
455
|
+
|
|
471
456
|
/**
|
|
472
457
|
* Turns on verbose mode to log every HTTP response.
|
|
473
458
|
* @param successCallBack - function that should be triggered on every HTTP response with the status 2**.
|
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
import { RequestClient } from './RequestClient'
|
|
2
2
|
import { AxiosResponse } from 'axios'
|
|
3
|
-
|
|
4
|
-
export interface SasjsParsedResponse<T> {
|
|
5
|
-
result: T
|
|
6
|
-
log: string
|
|
7
|
-
etag: string
|
|
8
|
-
status: number
|
|
9
|
-
printOutput?: string
|
|
10
|
-
}
|
|
3
|
+
import { SasjsParsedResponse } from '../types'
|
|
11
4
|
|
|
12
5
|
/**
|
|
13
6
|
* Specific request client for SASJS.
|
|
14
7
|
* Append tokens in headers.
|
|
15
8
|
*/
|
|
16
|
-
|
|
17
9
|
export class SasjsRequestClient extends RequestClient {
|
|
18
10
|
getHeaders = (accessToken: string | undefined, contentType: string) => {
|
|
19
11
|
const headers: any = {}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { CsrfToken } from '..'
|
|
2
|
+
|
|
3
|
+
export interface HttpClient {
|
|
4
|
+
get<T>(
|
|
5
|
+
url: string,
|
|
6
|
+
accessToken: string | undefined,
|
|
7
|
+
contentType: string,
|
|
8
|
+
overrideHeaders: { [key: string]: string | number }
|
|
9
|
+
): Promise<{ result: T; etag: string }>
|
|
10
|
+
|
|
11
|
+
post<T>(
|
|
12
|
+
url: string,
|
|
13
|
+
data: any,
|
|
14
|
+
accessToken: string | undefined,
|
|
15
|
+
contentType: string,
|
|
16
|
+
overrideHeaders: { [key: string]: string | number }
|
|
17
|
+
): Promise<{ result: T; etag: string }>
|
|
18
|
+
|
|
19
|
+
put<T>(
|
|
20
|
+
url: string,
|
|
21
|
+
data: any,
|
|
22
|
+
accessToken: string | undefined,
|
|
23
|
+
overrideHeaders: { [key: string]: string | number }
|
|
24
|
+
): Promise<{ result: T; etag: string }>
|
|
25
|
+
|
|
26
|
+
delete<T>(
|
|
27
|
+
url: string,
|
|
28
|
+
accessToken: string | undefined
|
|
29
|
+
): Promise<{ result: T; etag: string }>
|
|
30
|
+
|
|
31
|
+
getCsrfToken(type: 'general' | 'file'): CsrfToken | undefined
|
|
32
|
+
saveLocalStorageToken(accessToken: string, refreshToken: string): void
|
|
33
|
+
clearCsrfTokens(): void
|
|
34
|
+
clearLocalStorageTokens(): void
|
|
35
|
+
getBaseUrl(): string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface SASjsRequest {
|
|
39
|
+
serviceLink: string
|
|
40
|
+
timestamp: Date
|
|
41
|
+
sourceCode: string
|
|
42
|
+
generatedCode: string
|
|
43
|
+
logFile: string
|
|
44
|
+
SASWORK: any
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface SasjsParsedResponse<T> {
|
|
48
|
+
result: T
|
|
49
|
+
log: string
|
|
50
|
+
etag: string
|
|
51
|
+
status: number
|
|
52
|
+
printOutput?: string
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type VerboseMode = boolean | 'bleached'
|
package/src/types/SASjsConfig.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as https from 'https'
|
|
2
2
|
import { ServerType } from '@sasjs/utils/types'
|
|
3
|
+
import { VerboseMode } from '../types'
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Specifies the configuration for the SASjs instance - eg where and how to
|
|
@@ -45,6 +46,10 @@ export class SASjsConfig {
|
|
|
45
46
|
* Set to `true` to enable additional debugging.
|
|
46
47
|
*/
|
|
47
48
|
debug: boolean = true
|
|
49
|
+
/**
|
|
50
|
+
* Set to `true` to enable verbose mode that will log a summary of every HTTP response.
|
|
51
|
+
*/
|
|
52
|
+
verbose?: VerboseMode = true
|
|
48
53
|
/**
|
|
49
54
|
* The name of the compute context to use when calling the Viya services directly.
|
|
50
55
|
* Example value: 'SAS Job Execution compute context'
|
package/src/types/index.ts
CHANGED
|
@@ -6,10 +6,12 @@ export * from './Job'
|
|
|
6
6
|
export * from './JobDefinition'
|
|
7
7
|
export * from './JobResult'
|
|
8
8
|
export * from './Link'
|
|
9
|
+
export * from './Login'
|
|
9
10
|
export * from './SASjsConfig'
|
|
10
|
-
export * from './
|
|
11
|
+
export * from './RequestClient'
|
|
11
12
|
export * from './Session'
|
|
12
13
|
export * from './UploadFile'
|
|
13
14
|
export * from './PollOptions'
|
|
14
15
|
export * from './WriteStream'
|
|
15
16
|
export * from './ExecuteScript'
|
|
17
|
+
export * from './errors'
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { CsrfToken } from '..';
|
|
2
|
+
export interface HttpClient {
|
|
3
|
+
get<T>(url: string, accessToken: string | undefined, contentType: string, overrideHeaders: {
|
|
4
|
+
[key: string]: string | number;
|
|
5
|
+
}): Promise<{
|
|
6
|
+
result: T;
|
|
7
|
+
etag: string;
|
|
8
|
+
}>;
|
|
9
|
+
post<T>(url: string, data: any, accessToken: string | undefined, contentType: string, overrideHeaders: {
|
|
10
|
+
[key: string]: string | number;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
result: T;
|
|
13
|
+
etag: string;
|
|
14
|
+
}>;
|
|
15
|
+
put<T>(url: string, data: any, accessToken: string | undefined, overrideHeaders: {
|
|
16
|
+
[key: string]: string | number;
|
|
17
|
+
}): Promise<{
|
|
18
|
+
result: T;
|
|
19
|
+
etag: string;
|
|
20
|
+
}>;
|
|
21
|
+
delete<T>(url: string, accessToken: string | undefined): Promise<{
|
|
22
|
+
result: T;
|
|
23
|
+
etag: string;
|
|
24
|
+
}>;
|
|
25
|
+
getCsrfToken(type: 'general' | 'file'): CsrfToken | undefined;
|
|
26
|
+
saveLocalStorageToken(accessToken: string, refreshToken: string): void;
|
|
27
|
+
clearCsrfTokens(): void;
|
|
28
|
+
clearLocalStorageTokens(): void;
|
|
29
|
+
getBaseUrl(): string;
|
|
30
|
+
}
|
|
31
|
+
export interface SASjsRequest {
|
|
32
|
+
serviceLink: string;
|
|
33
|
+
timestamp: Date;
|
|
34
|
+
sourceCode: string;
|
|
35
|
+
generatedCode: string;
|
|
36
|
+
logFile: string;
|
|
37
|
+
SASWORK: any;
|
|
38
|
+
}
|
|
39
|
+
export interface SasjsParsedResponse<T> {
|
|
40
|
+
result: T;
|
|
41
|
+
log: string;
|
|
42
|
+
etag: string;
|
|
43
|
+
status: number;
|
|
44
|
+
printOutput?: string;
|
|
45
|
+
}
|
|
46
|
+
export declare type VerboseMode = boolean | 'bleached';
|