@sasjs/adapter 4.3.1 → 4.3.3
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/SASjsApiClient.d.ts +10 -5
- package/index-dev.js +2 -2
- package/index.js +1 -1
- package/node/SASjsApiClient.d.ts +10 -5
- package/node/index.js +2 -0
- package/node/request/SasjsRequestClient.d.ts +9 -6
- package/package.json +1 -1
- package/request/SasjsRequestClient.d.ts +9 -6
- package/src/SASjsApiClient.ts +28 -11
- package/src/job-execution/SasjsJobExecutor.ts +9 -1
- package/src/request/SasjsRequestClient.ts +23 -6
- package/src/utils/getValidJson.ts +1 -0
- package/node/main.js +0 -2
- /package/node/{main.js.LICENSE.txt → index.js.LICENSE.txt} +0 -0
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { RequestClient } from './RequestClient';
|
|
2
2
|
import { AxiosResponse } from 'axios';
|
|
3
|
+
interface SasjsParsedResponse<T> {
|
|
4
|
+
result: T;
|
|
5
|
+
log: string;
|
|
6
|
+
etag: string;
|
|
7
|
+
status: number;
|
|
8
|
+
printOutput?: string;
|
|
9
|
+
}
|
|
3
10
|
/**
|
|
4
11
|
* Specific request client for SASJS.
|
|
5
12
|
* Append tokens in headers.
|
|
6
13
|
*/
|
|
7
14
|
export declare class SasjsRequestClient extends RequestClient {
|
|
8
15
|
getHeaders: (accessToken: string | undefined, contentType: string) => any;
|
|
9
|
-
protected parseResponse<T>(response: AxiosResponse<any>):
|
|
10
|
-
result: T;
|
|
11
|
-
log: any;
|
|
12
|
-
etag: string;
|
|
13
|
-
status: number;
|
|
14
|
-
};
|
|
16
|
+
protected parseResponse<T>(response: AxiosResponse<any>): SasjsParsedResponse<T>;
|
|
15
17
|
}
|
|
18
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { RequestClient } from './RequestClient';
|
|
2
2
|
import { AxiosResponse } from 'axios';
|
|
3
|
+
interface SasjsParsedResponse<T> {
|
|
4
|
+
result: T;
|
|
5
|
+
log: string;
|
|
6
|
+
etag: string;
|
|
7
|
+
status: number;
|
|
8
|
+
printOutput?: string;
|
|
9
|
+
}
|
|
3
10
|
/**
|
|
4
11
|
* Specific request client for SASJS.
|
|
5
12
|
* Append tokens in headers.
|
|
6
13
|
*/
|
|
7
14
|
export declare class SasjsRequestClient extends RequestClient {
|
|
8
15
|
getHeaders: (accessToken: string | undefined, contentType: string) => any;
|
|
9
|
-
protected parseResponse<T>(response: AxiosResponse<any>):
|
|
10
|
-
result: T;
|
|
11
|
-
log: any;
|
|
12
|
-
etag: string;
|
|
13
|
-
status: number;
|
|
14
|
-
};
|
|
16
|
+
protected parseResponse<T>(response: AxiosResponse<any>): SasjsParsedResponse<T>;
|
|
15
17
|
}
|
|
18
|
+
export {};
|
package/src/SASjsApiClient.ts
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
import * as NodeFormData from 'form-data'
|
|
2
2
|
import { AuthConfig, ServerType, ServicePackSASjs } from '@sasjs/utils/types'
|
|
3
|
+
import { prefixMessage } from '@sasjs/utils/error'
|
|
3
4
|
import { ExecutionQuery } from './types'
|
|
4
5
|
import { RequestClient } from './request/RequestClient'
|
|
5
6
|
import { getAccessTokenForSasjs } from './auth/getAccessTokenForSasjs'
|
|
6
7
|
import { refreshTokensForSasjs } from './auth/refreshTokensForSasjs'
|
|
7
8
|
import { getTokens } from './auth/getTokens'
|
|
8
9
|
|
|
10
|
+
// TODO: move to sasjs/utils
|
|
11
|
+
export interface SASjsAuthResponse {
|
|
12
|
+
access_token: string
|
|
13
|
+
refresh_token: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ScriptExecutionResult {
|
|
17
|
+
log: string
|
|
18
|
+
webout?: string
|
|
19
|
+
printOutput?: string
|
|
20
|
+
}
|
|
21
|
+
|
|
9
22
|
export class SASjsApiClient {
|
|
10
23
|
constructor(private requestClient: RequestClient) {}
|
|
11
24
|
|
|
@@ -118,18 +131,28 @@ export class SASjsApiClient {
|
|
|
118
131
|
code: string,
|
|
119
132
|
runTime: string = 'sas',
|
|
120
133
|
authConfig?: AuthConfig
|
|
121
|
-
) {
|
|
134
|
+
): Promise<ScriptExecutionResult> {
|
|
122
135
|
const access_token = await this.getAccessTokenForRequest(authConfig)
|
|
123
|
-
|
|
124
|
-
let parsedSasjsServerLog = ''
|
|
136
|
+
const executionResult: ScriptExecutionResult = { log: '' }
|
|
125
137
|
|
|
126
138
|
await this.requestClient
|
|
127
139
|
.post('SASjsApi/code/execute', { code, runTime }, access_token)
|
|
128
140
|
.then((res: any) => {
|
|
129
|
-
|
|
141
|
+
const { log, printOutput, result: webout } = res
|
|
142
|
+
|
|
143
|
+
executionResult.log = log
|
|
144
|
+
|
|
145
|
+
if (printOutput) executionResult.printOutput = printOutput
|
|
146
|
+
if (webout) executionResult.webout = webout
|
|
147
|
+
})
|
|
148
|
+
.catch((err) => {
|
|
149
|
+
throw prefixMessage(
|
|
150
|
+
err,
|
|
151
|
+
'Error while sending POST request to execute code. '
|
|
152
|
+
)
|
|
130
153
|
})
|
|
131
154
|
|
|
132
|
-
return
|
|
155
|
+
return executionResult
|
|
133
156
|
}
|
|
134
157
|
|
|
135
158
|
/**
|
|
@@ -152,9 +175,3 @@ export class SASjsApiClient {
|
|
|
152
175
|
return refreshTokensForSasjs(this.requestClient, refreshToken)
|
|
153
176
|
}
|
|
154
177
|
}
|
|
155
|
-
|
|
156
|
-
// todo move to sasjs/utils
|
|
157
|
-
export interface SASjsAuthResponse {
|
|
158
|
-
access_token: string
|
|
159
|
-
refresh_token: string
|
|
160
|
-
}
|
|
@@ -13,7 +13,11 @@ import { generateFileUploadForm } from '../file/generateFileUploadForm'
|
|
|
13
13
|
|
|
14
14
|
import { RequestClient } from '../request/RequestClient'
|
|
15
15
|
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
isRelativePath,
|
|
18
|
+
appendExtraResponseAttributes,
|
|
19
|
+
getValidJson
|
|
20
|
+
} from '../utils'
|
|
17
21
|
import { BaseJobExecutor } from './JobExecutor'
|
|
18
22
|
|
|
19
23
|
export class SasjsJobExecutor extends BaseJobExecutor {
|
|
@@ -89,12 +93,16 @@ export class SasjsJobExecutor extends BaseJobExecutor {
|
|
|
89
93
|
)
|
|
90
94
|
}
|
|
91
95
|
|
|
96
|
+
const { result } = res.result
|
|
97
|
+
if (result && result.trim()) res.result = getValidJson(result)
|
|
98
|
+
|
|
92
99
|
this.requestClient!.appendRequest(res, sasJob, config.debug)
|
|
93
100
|
|
|
94
101
|
const responseObject = appendExtraResponseAttributes(
|
|
95
102
|
res,
|
|
96
103
|
extraResponseAttributes
|
|
97
104
|
)
|
|
105
|
+
|
|
98
106
|
resolve(responseObject)
|
|
99
107
|
})
|
|
100
108
|
.catch(async (e: Error) => {
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { RequestClient } from './RequestClient'
|
|
2
2
|
import { AxiosResponse } from 'axios'
|
|
3
|
-
import { SASJS_LOGS_SEPARATOR
|
|
3
|
+
import { SASJS_LOGS_SEPARATOR } from '../utils'
|
|
4
|
+
|
|
5
|
+
interface SasjsParsedResponse<T> {
|
|
6
|
+
result: T
|
|
7
|
+
log: string
|
|
8
|
+
etag: string
|
|
9
|
+
status: number
|
|
10
|
+
printOutput?: string
|
|
11
|
+
}
|
|
4
12
|
|
|
5
13
|
/**
|
|
6
14
|
* Specific request client for SASJS.
|
|
@@ -27,7 +35,7 @@ export class SasjsRequestClient extends RequestClient {
|
|
|
27
35
|
protected parseResponse<T>(response: AxiosResponse<any>) {
|
|
28
36
|
const etag = response?.headers ? response.headers['etag'] : ''
|
|
29
37
|
let parsedResponse = {}
|
|
30
|
-
let log
|
|
38
|
+
let webout, log, printOutput
|
|
31
39
|
|
|
32
40
|
try {
|
|
33
41
|
if (typeof response.data === 'string') {
|
|
@@ -38,17 +46,26 @@ export class SasjsRequestClient extends RequestClient {
|
|
|
38
46
|
} catch {
|
|
39
47
|
if (response.data.includes(SASJS_LOGS_SEPARATOR)) {
|
|
40
48
|
const splittedResponse = response.data.split(SASJS_LOGS_SEPARATOR)
|
|
49
|
+
|
|
50
|
+
webout = splittedResponse[0]
|
|
51
|
+
if (webout) parsedResponse = webout
|
|
52
|
+
|
|
41
53
|
log = splittedResponse[1]
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
54
|
+
printOutput = splittedResponse[2]
|
|
55
|
+
} else {
|
|
56
|
+
parsedResponse = response.data
|
|
57
|
+
}
|
|
45
58
|
}
|
|
46
59
|
|
|
47
|
-
|
|
60
|
+
const returnResult: SasjsParsedResponse<T> = {
|
|
48
61
|
result: parsedResponse as T,
|
|
49
62
|
log,
|
|
50
63
|
etag,
|
|
51
64
|
status: response.status
|
|
52
65
|
}
|
|
66
|
+
|
|
67
|
+
if (printOutput) returnResult.printOutput = printOutput
|
|
68
|
+
|
|
69
|
+
return returnResult
|
|
53
70
|
}
|
|
54
71
|
}
|