@sasjs/adapter 3.7.6 → 3.7.9
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 +12 -5
- package/index.js +2 -2
- package/node/index.js +2 -2
- package/node/utils/convertToCsv.d.ts +3 -5
- package/package.json +10 -10
- package/src/api/viya/uploadTables.ts +1 -1
- package/src/auth/getAccessTokenForViya.ts +7 -17
- package/src/file/generateFileUploadForm.ts +1 -1
- package/src/file/generateTableUploadForm.ts +8 -1
- package/src/job-execution/Sas9JobExecutor.ts +2 -1
- package/src/job-execution/WebJobExecutor.ts +1 -1
- package/src/utils/convertToCsv.ts +16 -8
- package/src/utils/formatDataForRequest.ts +6 -1
- package/utils/convertToCsv.d.ts +3 -5
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
* Converts the given JSON object array to a CSV string.
|
|
3
3
|
* @param data - the array of JSON objects to convert.
|
|
4
4
|
*/
|
|
5
|
-
export declare const convertToCSV: (data:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
} | undefined) => string;
|
|
5
|
+
export declare const convertToCSV: (data: {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}, tableName: string) => string;
|
package/package.json
CHANGED
|
@@ -43,23 +43,23 @@
|
|
|
43
43
|
"@types/axios": "0.14.0",
|
|
44
44
|
"@types/express": "4.17.13",
|
|
45
45
|
"@types/form-data": "2.5.0",
|
|
46
|
-
"@types/jest": "27.0
|
|
46
|
+
"@types/jest": "27.4.0",
|
|
47
47
|
"@types/mime": "2.0.3",
|
|
48
48
|
"@types/pem": "1.9.6",
|
|
49
49
|
"@types/tough-cookie": "4.0.1",
|
|
50
50
|
"copyfiles": "2.4.1",
|
|
51
51
|
"cp": "0.2.0",
|
|
52
|
-
"dotenv": "
|
|
53
|
-
"express": "4.17.
|
|
52
|
+
"dotenv": "16.0.0",
|
|
53
|
+
"express": "4.17.3",
|
|
54
54
|
"jest": "27.4.7",
|
|
55
55
|
"jest-extended": "2.0.0",
|
|
56
56
|
"node-polyfill-webpack-plugin": "1.1.4",
|
|
57
57
|
"path": "0.12.7",
|
|
58
|
-
"pem": "1.14.
|
|
58
|
+
"pem": "1.14.6",
|
|
59
59
|
"process": "0.11.10",
|
|
60
60
|
"rimraf": "3.0.2",
|
|
61
61
|
"semantic-release": "18.0.0",
|
|
62
|
-
"terser-webpack-plugin": "5.3.
|
|
62
|
+
"terser-webpack-plugin": "5.3.1",
|
|
63
63
|
"ts-jest": "27.1.3",
|
|
64
64
|
"ts-loader": "9.2.6",
|
|
65
65
|
"tslint": "6.1.3",
|
|
@@ -67,18 +67,18 @@
|
|
|
67
67
|
"typedoc": "0.22.11",
|
|
68
68
|
"typedoc-neo-theme": "1.1.1",
|
|
69
69
|
"typedoc-plugin-external-module-name": "4.0.6",
|
|
70
|
-
"typescript": "4.5.
|
|
71
|
-
"webpack": "5.
|
|
72
|
-
"webpack-cli": "4.
|
|
70
|
+
"typescript": "4.5.5",
|
|
71
|
+
"webpack": "5.69.0",
|
|
72
|
+
"webpack-cli": "4.9.2"
|
|
73
73
|
},
|
|
74
74
|
"main": "index.js",
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@sasjs/utils": "2.
|
|
76
|
+
"@sasjs/utils": "2.36.1",
|
|
77
77
|
"axios": "0.26.0",
|
|
78
78
|
"axios-cookiejar-support": "1.0.1",
|
|
79
79
|
"form-data": "4.0.0",
|
|
80
80
|
"https": "1.0.0",
|
|
81
81
|
"tough-cookie": "4.0.0"
|
|
82
82
|
},
|
|
83
|
-
"version": "3.7.
|
|
83
|
+
"version": "3.7.9"
|
|
84
84
|
}
|
|
@@ -18,7 +18,7 @@ export async function uploadTables(
|
|
|
18
18
|
const uploadedFiles = []
|
|
19
19
|
|
|
20
20
|
for (const tableName in data) {
|
|
21
|
-
const csv = convertToCSV(data
|
|
21
|
+
const csv = convertToCSV(data, tableName)
|
|
22
22
|
if (csv === 'ERROR: LARGE STRING LENGTH') {
|
|
23
23
|
throw new Error(
|
|
24
24
|
'The max length of a string value in SASjs is 32765 characters.'
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { SasAuthResponse } from '@sasjs/utils/types'
|
|
2
2
|
import { prefixMessage } from '@sasjs/utils/error'
|
|
3
|
-
import * as NodeFormData from 'form-data'
|
|
4
3
|
import { RequestClient } from '../request/RequestClient'
|
|
5
4
|
|
|
6
5
|
/**
|
|
@@ -24,26 +23,17 @@ export async function getAccessTokenForViya(
|
|
|
24
23
|
token = Buffer.from(clientId + ':' + clientSecret).toString('base64')
|
|
25
24
|
}
|
|
26
25
|
const headers = {
|
|
27
|
-
Authorization: 'Basic ' + token
|
|
26
|
+
Authorization: 'Basic ' + token,
|
|
27
|
+
Accept: 'application/json'
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
formData = new FormData()
|
|
35
|
-
}
|
|
36
|
-
formData.append('grant_type', 'authorization_code')
|
|
37
|
-
formData.append('code', authCode)
|
|
30
|
+
const data = new URLSearchParams({
|
|
31
|
+
grant_type: 'authorization_code',
|
|
32
|
+
code: authCode
|
|
33
|
+
})
|
|
38
34
|
|
|
39
35
|
const authResponse = await requestClient
|
|
40
|
-
.post(
|
|
41
|
-
url,
|
|
42
|
-
formData,
|
|
43
|
-
undefined,
|
|
44
|
-
'multipart/form-data; boundary=' + (formData as any)._boundary,
|
|
45
|
-
headers
|
|
46
|
-
)
|
|
36
|
+
.post(url, data, undefined, 'application/x-www-form-urlencoded', headers)
|
|
47
37
|
.then((res) => res.result as SasAuthResponse)
|
|
48
38
|
.catch((err) => {
|
|
49
39
|
throw prefixMessage(err, 'Error while getting access token. ')
|
|
@@ -18,7 +18,7 @@ export const generateFileUploadForm = (
|
|
|
18
18
|
if (!Array.isArray(data[tableName])) continue
|
|
19
19
|
|
|
20
20
|
const name = tableName
|
|
21
|
-
const csv = convertToCSV(data
|
|
21
|
+
const csv = convertToCSV(data, tableName)
|
|
22
22
|
|
|
23
23
|
if (csv === 'ERROR: LARGE STRING LENGTH') {
|
|
24
24
|
throw new Error(
|
|
@@ -9,18 +9,24 @@ export const generateTableUploadForm = (
|
|
|
9
9
|
const sasjsTables = []
|
|
10
10
|
const requestParams: any = {}
|
|
11
11
|
let tableCounter = 0
|
|
12
|
+
|
|
12
13
|
for (const tableName in data) {
|
|
13
14
|
tableCounter++
|
|
15
|
+
|
|
14
16
|
sasjsTables.push(tableName)
|
|
15
|
-
|
|
17
|
+
|
|
18
|
+
const csv = convertToCSV(data, tableName)
|
|
19
|
+
|
|
16
20
|
if (csv === 'ERROR: LARGE STRING LENGTH') {
|
|
17
21
|
throw new Error(
|
|
18
22
|
'The max length of a string value in SASjs is 32765 characters.'
|
|
19
23
|
)
|
|
20
24
|
}
|
|
25
|
+
|
|
21
26
|
// if csv has length more then 16k, send in chunks
|
|
22
27
|
if (csv.length > 16000) {
|
|
23
28
|
const csvChunks = splitChunks(csv)
|
|
29
|
+
|
|
24
30
|
// append chunks to form data with same key
|
|
25
31
|
csvChunks.map((chunk) => {
|
|
26
32
|
formData.append(`sasjs${tableCounter}data`, chunk)
|
|
@@ -29,6 +35,7 @@ export const generateTableUploadForm = (
|
|
|
29
35
|
requestParams[`sasjs${tableCounter}data`] = csv
|
|
30
36
|
}
|
|
31
37
|
}
|
|
38
|
+
|
|
32
39
|
requestParams['sasjs_tables'] = sasjsTables.join(' ')
|
|
33
40
|
|
|
34
41
|
return { formData, requestParams }
|
|
@@ -125,7 +125,8 @@ const generateFileUploadForm = (
|
|
|
125
125
|
): NodeFormData => {
|
|
126
126
|
for (const tableName in data) {
|
|
127
127
|
const name = tableName
|
|
128
|
-
const csv = convertToCSV(data
|
|
128
|
+
const csv = convertToCSV(data, tableName)
|
|
129
|
+
|
|
129
130
|
if (csv === 'ERROR: LARGE STRING LENGTH') {
|
|
130
131
|
throw new Error(
|
|
131
132
|
'The max length of a string value in SASjs is 32765 characters.'
|
|
@@ -208,7 +208,7 @@ export class WebJobExecutor extends BaseJobExecutor {
|
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
const responseObject = appendExtraResponseAttributes(
|
|
211
|
-
{ result: jsonResponse },
|
|
211
|
+
{ result: jsonResponse, log: parsedSasjsServerLog },
|
|
212
212
|
extraResponseAttributes
|
|
213
213
|
)
|
|
214
214
|
resolve(responseObject)
|
|
@@ -3,10 +3,18 @@
|
|
|
3
3
|
* @param data - the array of JSON objects to convert.
|
|
4
4
|
*/
|
|
5
5
|
export const convertToCSV = (
|
|
6
|
-
data:
|
|
7
|
-
|
|
6
|
+
data: { [key: string]: any },
|
|
7
|
+
tableName: string
|
|
8
8
|
) => {
|
|
9
|
-
|
|
9
|
+
if (!data[tableName]) {
|
|
10
|
+
throw new Error('No table provided to be converted to CSV')
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const table = data[tableName]
|
|
14
|
+
|
|
15
|
+
if (!Array.isArray(table)) return ''
|
|
16
|
+
|
|
17
|
+
let formats = data[`$${tableName}`]?.formats
|
|
10
18
|
let headers: string[] = []
|
|
11
19
|
let csvTest
|
|
12
20
|
let invalidString = false
|
|
@@ -16,14 +24,14 @@ export const convertToCSV = (
|
|
|
16
24
|
headers = Object.keys(formats).map((key) => `${key}:${formats![key]}`)
|
|
17
25
|
}
|
|
18
26
|
|
|
19
|
-
const headerFields = Object.keys(
|
|
27
|
+
const headerFields = Object.keys(table[0])
|
|
20
28
|
|
|
21
29
|
headerFields.forEach((field) => {
|
|
22
30
|
if (!formats || !Object.keys(formats).includes(field)) {
|
|
23
31
|
let hasNullOrNumber = false
|
|
24
32
|
let hasSpecialMissingString = false
|
|
25
33
|
|
|
26
|
-
|
|
34
|
+
table.forEach((row: { [key: string]: any }) => {
|
|
27
35
|
if (row[field] === null || typeof row[field] === 'number') {
|
|
28
36
|
hasNullOrNumber = true
|
|
29
37
|
} else if (
|
|
@@ -45,7 +53,7 @@ export const convertToCSV = (
|
|
|
45
53
|
let hasMixedTypes: boolean = false
|
|
46
54
|
let rowNumError: number = -1
|
|
47
55
|
|
|
48
|
-
const longestValueForField =
|
|
56
|
+
const longestValueForField = table
|
|
49
57
|
.map((row: any, index: number) => {
|
|
50
58
|
if (row[field] || row[field] === '') {
|
|
51
59
|
if (firstFoundType) {
|
|
@@ -101,7 +109,7 @@ export const convertToCSV = (
|
|
|
101
109
|
}
|
|
102
110
|
})
|
|
103
111
|
|
|
104
|
-
if (
|
|
112
|
+
if (formats) {
|
|
105
113
|
headers = headers.sort(
|
|
106
114
|
(a, b) =>
|
|
107
115
|
headerFields.indexOf(a.replace(/:.*/, '')) -
|
|
@@ -111,7 +119,7 @@ export const convertToCSV = (
|
|
|
111
119
|
|
|
112
120
|
if (invalidString) return 'ERROR: LARGE STRING LENGTH'
|
|
113
121
|
|
|
114
|
-
csvTest =
|
|
122
|
+
csvTest = table.map((row: any) => {
|
|
115
123
|
const fields = Object.keys(row).map((fieldName, index) => {
|
|
116
124
|
let value
|
|
117
125
|
const currentCell = row[fieldName]
|
|
@@ -15,19 +15,24 @@ export const formatDataForRequest = (data: any) => {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
tableCounter++
|
|
18
|
+
|
|
18
19
|
sasjsTables.push(tableName)
|
|
19
|
-
|
|
20
|
+
|
|
21
|
+
const csv = convertToCSV(data, tableName)
|
|
20
22
|
|
|
21
23
|
if (csv === 'ERROR: LARGE STRING LENGTH') {
|
|
22
24
|
throw new Error(
|
|
23
25
|
'The max length of a string value in SASjs is 32765 characters.'
|
|
24
26
|
)
|
|
25
27
|
}
|
|
28
|
+
|
|
26
29
|
// if csv has length more then 16k, send in chunks
|
|
27
30
|
if (csv.length > 16000) {
|
|
28
31
|
const csvChunks = splitChunks(csv)
|
|
32
|
+
|
|
29
33
|
// append chunks to form data with same key
|
|
30
34
|
result[`sasjs${tableCounter}data0`] = csvChunks.length
|
|
35
|
+
|
|
31
36
|
csvChunks.forEach((chunk, index) => {
|
|
32
37
|
result[`sasjs${tableCounter}data${index + 1}`] = chunk
|
|
33
38
|
})
|
package/utils/convertToCsv.d.ts
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
* Converts the given JSON object array to a CSV string.
|
|
3
3
|
* @param data - the array of JSON objects to convert.
|
|
4
4
|
*/
|
|
5
|
-
export declare const convertToCSV: (data:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
} | undefined) => string;
|
|
5
|
+
export declare const convertToCSV: (data: {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}, tableName: string) => string;
|