@sasjs/adapter 3.10.2 → 3.10.5
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 +18 -12
- package/SASjs.d.ts +1 -4
- package/auth/AuthManager.d.ts +2 -5
- package/index.js +2 -2
- package/node/SASjs.d.ts +1 -4
- package/node/auth/AuthManager.d.ts +2 -5
- package/node/index.js +2 -2
- package/node/utils/convertToCsv.d.ts +5 -0
- package/package.json +7 -6
- package/src/api/viya/executeScript.ts +2 -2
- package/src/api/viya/writeStream.ts +1 -1
- package/src/auth/AuthManager.ts +2 -12
- package/src/file/generateTableUploadForm.ts +3 -2
- package/src/job-execution/WebJobExecutor.ts +17 -9
- package/src/request/RequestClient.ts +5 -5
- package/src/request/Sas9RequestClient.ts +2 -2
- package/src/utils/convertToCsv.ts +11 -1
- package/src/utils/formatDataForRequest.ts +4 -3
- package/src/utils/getValidJson.ts +1 -1
- package/src/utils/parseSasViyaLog.ts +1 -1
- package/src/utils/parseWeboutResponse.ts +1 -1
- package/utils/convertToCsv.d.ts +5 -0
|
@@ -5,3 +5,8 @@
|
|
|
5
5
|
export declare const convertToCSV: (data: {
|
|
6
6
|
[key: string]: any;
|
|
7
7
|
}, tableName: string) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Checks if table is table of formats (table name should start from '$' character).
|
|
10
|
+
* @param tableName - table name.
|
|
11
|
+
*/
|
|
12
|
+
export declare const isFormatsTable: (tableName: string) => boolean;
|
package/package.json
CHANGED
|
@@ -44,18 +44,16 @@
|
|
|
44
44
|
"license": "ISC",
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@cypress/webpack-preprocessor": "5.9.1",
|
|
47
|
-
"@types/form-data": "2.5.0",
|
|
48
|
-
"cypress": "7.7.0",
|
|
49
|
-
"typedoc-neo-theme": "1.1.1",
|
|
50
|
-
"typedoc-plugin-external-module-name": "4.0.6",
|
|
51
47
|
"@types/axios": "0.14.0",
|
|
52
48
|
"@types/express": "4.17.13",
|
|
49
|
+
"@types/form-data": "2.5.0",
|
|
53
50
|
"@types/jest": "27.4.0",
|
|
54
51
|
"@types/mime": "2.0.3",
|
|
55
52
|
"@types/pem": "1.9.6",
|
|
56
53
|
"@types/tough-cookie": "4.0.1",
|
|
57
54
|
"copyfiles": "2.4.1",
|
|
58
55
|
"cp": "0.2.0",
|
|
56
|
+
"cypress": "7.7.0",
|
|
59
57
|
"dotenv": "16.0.0",
|
|
60
58
|
"express": "4.17.3",
|
|
61
59
|
"jest": "27.4.7",
|
|
@@ -63,15 +61,18 @@
|
|
|
63
61
|
"node-polyfill-webpack-plugin": "1.1.4",
|
|
64
62
|
"path": "0.12.7",
|
|
65
63
|
"pem": "1.14.6",
|
|
64
|
+
"prettier": "2.7.1",
|
|
66
65
|
"process": "0.11.10",
|
|
67
66
|
"rimraf": "3.0.2",
|
|
68
|
-
"semantic-release": "
|
|
67
|
+
"semantic-release": "19.0.3",
|
|
69
68
|
"terser-webpack-plugin": "5.3.1",
|
|
70
69
|
"ts-jest": "27.1.3",
|
|
71
70
|
"ts-loader": "9.2.6",
|
|
72
71
|
"tslint": "6.1.3",
|
|
73
72
|
"tslint-config-prettier": "1.18.0",
|
|
74
73
|
"typedoc": "0.22.11",
|
|
74
|
+
"typedoc-neo-theme": "1.1.1",
|
|
75
|
+
"typedoc-plugin-external-module-name": "4.0.6",
|
|
75
76
|
"typedoc-plugin-rename-defaults": "0.4.0",
|
|
76
77
|
"typescript": "4.5.5",
|
|
77
78
|
"webpack": "5.69.0",
|
|
@@ -86,5 +87,5 @@
|
|
|
86
87
|
"https": "1.0.0",
|
|
87
88
|
"tough-cookie": "4.0.0"
|
|
88
89
|
},
|
|
89
|
-
"version": "3.10.
|
|
90
|
+
"version": "3.10.5"
|
|
90
91
|
}
|
|
@@ -240,7 +240,7 @@ export async function executeScript(
|
|
|
240
240
|
|
|
241
241
|
jobResult = await requestClient
|
|
242
242
|
.get<any>(resultLink, access_token, 'text/plain')
|
|
243
|
-
.catch(async (e) => {
|
|
243
|
+
.catch(async (e: any) => {
|
|
244
244
|
if (e instanceof NotFoundError) {
|
|
245
245
|
if (logLink) {
|
|
246
246
|
const logUrl = `${logLink.href}/content`
|
|
@@ -271,7 +271,7 @@ export async function executeScript(
|
|
|
271
271
|
})
|
|
272
272
|
|
|
273
273
|
return { result: jobResult?.result, log }
|
|
274
|
-
} catch (e) {
|
|
274
|
+
} catch (e: any) {
|
|
275
275
|
interface HttpError {
|
|
276
276
|
status: number
|
|
277
277
|
}
|
package/src/auth/AuthManager.ts
CHANGED
|
@@ -23,7 +23,7 @@ export class AuthManager {
|
|
|
23
23
|
? '/SASLogon/logout?'
|
|
24
24
|
: this.serverType === ServerType.SasViya
|
|
25
25
|
? '/SASLogon/logout.do?'
|
|
26
|
-
: '/
|
|
26
|
+
: '/SASLogon/logout'
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/**
|
|
@@ -334,19 +334,9 @@ export class AuthManager {
|
|
|
334
334
|
|
|
335
335
|
/**
|
|
336
336
|
* Logs out of the configured SAS server.
|
|
337
|
-
*
|
|
337
|
+
*
|
|
338
338
|
*/
|
|
339
339
|
public async logOut() {
|
|
340
|
-
if (this.serverType === ServerType.Sasjs) {
|
|
341
|
-
return this.requestClient
|
|
342
|
-
.delete(this.logoutUrl)
|
|
343
|
-
.catch(() => true)
|
|
344
|
-
.finally(() => {
|
|
345
|
-
this.requestClient.clearLocalStorageTokens()
|
|
346
|
-
return true
|
|
347
|
-
})
|
|
348
|
-
}
|
|
349
|
-
|
|
350
340
|
this.requestClient.clearCsrfTokens()
|
|
351
341
|
|
|
352
342
|
return this.requestClient.get(this.logoutUrl, undefined).then(() => true)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as NodeFormData from 'form-data'
|
|
2
|
-
import { convertToCSV } from '../utils/convertToCsv'
|
|
2
|
+
import { convertToCSV, isFormatsTable } from '../utils/convertToCsv'
|
|
3
3
|
import { splitChunks } from '../utils/splitChunks'
|
|
4
4
|
|
|
5
5
|
export const generateTableUploadForm = (
|
|
@@ -13,7 +13,8 @@ export const generateTableUploadForm = (
|
|
|
13
13
|
for (const tableName in data) {
|
|
14
14
|
tableCounter++
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
// Formats table should not be sent as part of 'sasjs_tables'
|
|
17
|
+
if (!isFormatsTable(tableName)) sasjsTables.push(tableName)
|
|
17
18
|
|
|
18
19
|
const csv = convertToCSV(data, tableName)
|
|
19
20
|
|
|
@@ -169,15 +169,23 @@ export class WebJobExecutor extends BaseJobExecutor {
|
|
|
169
169
|
? res.result.log.map((logLine: any) => logLine.line).join('\n')
|
|
170
170
|
: res.result.log
|
|
171
171
|
|
|
172
|
-
const resObj =
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
172
|
+
const resObj =
|
|
173
|
+
this.serverType === ServerType.Sasjs
|
|
174
|
+
? {
|
|
175
|
+
result: res.result._webout,
|
|
176
|
+
log: parsedSasjsServerLog
|
|
177
|
+
}
|
|
178
|
+
: res
|
|
179
|
+
|
|
180
|
+
if (
|
|
181
|
+
this.serverType === ServerType.Sasjs &&
|
|
182
|
+
res.result._webout.length < 1
|
|
183
|
+
) {
|
|
184
|
+
throw new JobExecutionError(
|
|
185
|
+
0,
|
|
186
|
+
`No webout was returned by job ${program}. Server type is SASJS and the calling function is WebJobExecutor. Please check the SAS log for more info.`,
|
|
187
|
+
parsedSasjsServerLog
|
|
188
|
+
)
|
|
181
189
|
}
|
|
182
190
|
|
|
183
191
|
this.requestClient!.appendRequest(resObj, sasJob, config.debug)
|
|
@@ -207,7 +207,7 @@ export class RequestClient implements HttpClient {
|
|
|
207
207
|
|
|
208
208
|
return this.parseResponse<T>(response)
|
|
209
209
|
})
|
|
210
|
-
.catch(async (e) => {
|
|
210
|
+
.catch(async (e: any) => {
|
|
211
211
|
return await this.handleError(
|
|
212
212
|
e,
|
|
213
213
|
() =>
|
|
@@ -248,7 +248,7 @@ export class RequestClient implements HttpClient {
|
|
|
248
248
|
|
|
249
249
|
return this.parseResponse<T>(response)
|
|
250
250
|
})
|
|
251
|
-
.catch(async (e) => {
|
|
251
|
+
.catch(async (e: any) => {
|
|
252
252
|
return await this.handleError(e, () =>
|
|
253
253
|
this.post<T>(url, data, accessToken, contentType, overrideHeaders)
|
|
254
254
|
)
|
|
@@ -272,7 +272,7 @@ export class RequestClient implements HttpClient {
|
|
|
272
272
|
throwIfError(response)
|
|
273
273
|
return this.parseResponse<T>(response)
|
|
274
274
|
})
|
|
275
|
-
.catch(async (e) => {
|
|
275
|
+
.catch(async (e: any) => {
|
|
276
276
|
return await this.handleError(e, () =>
|
|
277
277
|
this.put<T>(url, data, accessToken, overrideHeaders)
|
|
278
278
|
)
|
|
@@ -291,7 +291,7 @@ export class RequestClient implements HttpClient {
|
|
|
291
291
|
throwIfError(response)
|
|
292
292
|
return this.parseResponse<T>(response)
|
|
293
293
|
})
|
|
294
|
-
.catch(async (e) => {
|
|
294
|
+
.catch(async (e: any) => {
|
|
295
295
|
return await this.handleError(e, () => this.delete<T>(url, accessToken))
|
|
296
296
|
})
|
|
297
297
|
}
|
|
@@ -309,7 +309,7 @@ export class RequestClient implements HttpClient {
|
|
|
309
309
|
throwIfError(response)
|
|
310
310
|
return this.parseResponse<T>(response)
|
|
311
311
|
})
|
|
312
|
-
.catch(async (e) => {
|
|
312
|
+
.catch(async (e: any) => {
|
|
313
313
|
return await this.handleError(e, () =>
|
|
314
314
|
this.patch<T>(url, data, accessToken)
|
|
315
315
|
)
|
|
@@ -68,7 +68,7 @@ export class Sas9RequestClient extends RequestClient {
|
|
|
68
68
|
throwIfError(response)
|
|
69
69
|
return this.parseResponse<T>(response)
|
|
70
70
|
})
|
|
71
|
-
.catch(async (e) => {
|
|
71
|
+
.catch(async (e: any) => {
|
|
72
72
|
return await this.handleError(
|
|
73
73
|
e,
|
|
74
74
|
() =>
|
|
@@ -113,7 +113,7 @@ export class Sas9RequestClient extends RequestClient {
|
|
|
113
113
|
throwIfError(response)
|
|
114
114
|
return this.parseResponse<T>(response)
|
|
115
115
|
})
|
|
116
|
-
.catch(async (e) => {
|
|
116
|
+
.catch(async (e: any) => {
|
|
117
117
|
return await this.handleError(e, () =>
|
|
118
118
|
this.post<T>(url, data, accessToken, contentType, overrideHeaders)
|
|
119
119
|
)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isSpecialMissing } from '@sasjs/utils/input/validators'
|
|
2
|
+
import { prefixMessage } from '@sasjs/utils/error'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Converts the given JSON object array to a CSV string.
|
|
@@ -9,7 +10,10 @@ export const convertToCSV = (
|
|
|
9
10
|
tableName: string
|
|
10
11
|
) => {
|
|
11
12
|
if (!data[tableName]) {
|
|
12
|
-
throw
|
|
13
|
+
throw prefixMessage(
|
|
14
|
+
'No table provided to be converted to CSV.',
|
|
15
|
+
'Error while converting to CSV. '
|
|
16
|
+
)
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
const table = data[tableName]
|
|
@@ -170,6 +174,12 @@ export const convertToCSV = (
|
|
|
170
174
|
return finalCSV
|
|
171
175
|
}
|
|
172
176
|
|
|
177
|
+
/**
|
|
178
|
+
* Checks if table is table of formats (table name should start from '$' character).
|
|
179
|
+
* @param tableName - table name.
|
|
180
|
+
*/
|
|
181
|
+
export const isFormatsTable = (tableName: string) => /^\$.*/.test(tableName)
|
|
182
|
+
|
|
173
183
|
const getByteSize = (str: string) => {
|
|
174
184
|
let byteSize = str.length
|
|
175
185
|
for (let i = str.length - 1; i >= 0; i--) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { convertToCSV } from './convertToCsv'
|
|
1
|
+
import { convertToCSV, isFormatsTable } from './convertToCsv'
|
|
2
2
|
import { splitChunks } from './splitChunks'
|
|
3
3
|
|
|
4
4
|
export const formatDataForRequest = (data: any) => {
|
|
@@ -8,7 +8,7 @@ export const formatDataForRequest = (data: any) => {
|
|
|
8
8
|
|
|
9
9
|
for (const tableName in data) {
|
|
10
10
|
if (
|
|
11
|
-
tableName
|
|
11
|
+
isFormatsTable(tableName) &&
|
|
12
12
|
Object.keys(data).includes(tableName.replace(/^\$/, ''))
|
|
13
13
|
) {
|
|
14
14
|
continue
|
|
@@ -16,7 +16,8 @@ export const formatDataForRequest = (data: any) => {
|
|
|
16
16
|
|
|
17
17
|
tableCounter++
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
// Formats table should not be sent as part of 'sasjs_tables'
|
|
20
|
+
if (!isFormatsTable(tableName)) sasjsTables.push(tableName)
|
|
20
21
|
|
|
21
22
|
const csv = convertToCSV(data, tableName)
|
|
22
23
|
|
|
@@ -4,7 +4,7 @@ export const parseSasViyaLog = (logResponse: { items: any[] }) => {
|
|
|
4
4
|
log = logResponse.items
|
|
5
5
|
? logResponse.items.map((i) => i.line).join('\n')
|
|
6
6
|
: JSON.stringify(logResponse)
|
|
7
|
-
} catch (e) {
|
|
7
|
+
} catch (e: any) {
|
|
8
8
|
console.error('An error has occurred while parsing the log response', e)
|
|
9
9
|
log = logResponse
|
|
10
10
|
}
|
|
@@ -8,7 +8,7 @@ export const parseWeboutResponse = (response: string, url?: string): string => {
|
|
|
8
8
|
sasResponse = response
|
|
9
9
|
.split('>>weboutBEGIN<<')[1]
|
|
10
10
|
.split('>>weboutEND<<')[0]
|
|
11
|
-
} catch (e) {
|
|
11
|
+
} catch (e: any) {
|
|
12
12
|
if (url) throw new WeboutResponseError(url)
|
|
13
13
|
|
|
14
14
|
sasResponse = ''
|
package/utils/convertToCsv.d.ts
CHANGED
|
@@ -5,3 +5,8 @@
|
|
|
5
5
|
export declare const convertToCSV: (data: {
|
|
6
6
|
[key: string]: any;
|
|
7
7
|
}, tableName: string) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Checks if table is table of formats (table name should start from '$' character).
|
|
10
|
+
* @param tableName - table name.
|
|
11
|
+
*/
|
|
12
|
+
export declare const isFormatsTable: (tableName: string) => boolean;
|