@sasjs/adapter 3.8.5 → 3.9.2
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/SASjs.d.ts +7 -1
- package/SASjsApiClient.d.ts +6 -0
- package/index.js +2 -2
- package/node/SASjs.d.ts +7 -1
- package/node/SASjsApiClient.d.ts +6 -0
- package/node/index.js +2 -2
- package/package.json +2 -2
- package/src/SASjs.ts +12 -1
- package/src/SASjsApiClient.ts +33 -0
- package/src/utils/convertToCsv.ts +5 -4
package/package.json
CHANGED
|
@@ -72,12 +72,12 @@
|
|
|
72
72
|
},
|
|
73
73
|
"main": "index.js",
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@sasjs/utils": "2.
|
|
75
|
+
"@sasjs/utils": "2.44.0",
|
|
76
76
|
"axios": "0.26.0",
|
|
77
77
|
"axios-cookiejar-support": "1.0.1",
|
|
78
78
|
"form-data": "4.0.0",
|
|
79
79
|
"https": "1.0.0",
|
|
80
80
|
"tough-cookie": "4.0.0"
|
|
81
81
|
},
|
|
82
|
-
"version": "3.
|
|
82
|
+
"version": "3.9.2"
|
|
83
83
|
}
|
package/src/SASjs.ts
CHANGED
|
@@ -77,7 +77,7 @@ export default class SASjs {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
|
-
* Executes code
|
|
80
|
+
* Executes SAS code on a SAS 9 server. Requires a runner to be present in
|
|
81
81
|
* the users home directory in metadata.
|
|
82
82
|
* @param linesOfCode - lines of sas code from the file to run.
|
|
83
83
|
* @param username - a string representing the username.
|
|
@@ -97,6 +97,17 @@ export default class SASjs {
|
|
|
97
97
|
)
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Executes SAS code on a SASJS server
|
|
102
|
+
* @param code - a string of code from the file to run.
|
|
103
|
+
* @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute scripts.
|
|
104
|
+
*/
|
|
105
|
+
public async executeScriptSASjs(code: string, authConfig?: AuthConfig) {
|
|
106
|
+
this.isMethodSupported('executeScriptSASJS', [ServerType.Sasjs])
|
|
107
|
+
|
|
108
|
+
return await this.sasJSApiClient?.executeScript(code, authConfig)
|
|
109
|
+
}
|
|
110
|
+
|
|
100
111
|
/**
|
|
101
112
|
* Executes sas code in a SAS Viya compute session.
|
|
102
113
|
* @param fileName - name of the file to run. It will be converted to path to the file being submitted for execution.
|
package/src/SASjsApiClient.ts
CHANGED
|
@@ -60,6 +60,39 @@ export class SASjsApiClient {
|
|
|
60
60
|
return Promise.resolve(result)
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Executes code on a SASJS server.
|
|
65
|
+
* @param code - a string of code to execute.
|
|
66
|
+
* @param authConfig - an object for authentication.
|
|
67
|
+
*/
|
|
68
|
+
public async executeScript(code: string, authConfig?: AuthConfig) {
|
|
69
|
+
let access_token = (authConfig || {}).access_token
|
|
70
|
+
if (authConfig) {
|
|
71
|
+
;({ access_token } = await getTokens(
|
|
72
|
+
this.requestClient,
|
|
73
|
+
authConfig,
|
|
74
|
+
ServerType.Sasjs
|
|
75
|
+
))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
let parsedSasjsServerLog = ''
|
|
79
|
+
|
|
80
|
+
await this.requestClient
|
|
81
|
+
.post('SASjsApi/code/execute', { code }, access_token)
|
|
82
|
+
.then((res: any) => {
|
|
83
|
+
if (res.result?.log) {
|
|
84
|
+
parsedSasjsServerLog = res.result.log
|
|
85
|
+
.map((logLine: any) => logLine.line)
|
|
86
|
+
.join('\n')
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
.catch((err) => {
|
|
90
|
+
parsedSasjsServerLog = err
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
return parsedSasjsServerLog
|
|
94
|
+
}
|
|
95
|
+
|
|
63
96
|
/**
|
|
64
97
|
* Exchanges the auth code for an access token for the given client.
|
|
65
98
|
* @param clientId - the client ID to authenticate with.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isSpecialMissing } from '@sasjs/utils'
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Converts the given JSON object array to a CSV string.
|
|
3
5
|
* @param data - the array of JSON objects to convert.
|
|
@@ -18,7 +20,6 @@ export const convertToCSV = (
|
|
|
18
20
|
let headers: string[] = []
|
|
19
21
|
let csvTest
|
|
20
22
|
let invalidString = false
|
|
21
|
-
const specialMissingValueRegExp = /^[a-z_]{1}$/i
|
|
22
23
|
|
|
23
24
|
if (formats) {
|
|
24
25
|
headers = Object.keys(formats).map((key) => `${key}:${formats![key]}`)
|
|
@@ -36,7 +37,7 @@ export const convertToCSV = (
|
|
|
36
37
|
hasNullOrNumber = true
|
|
37
38
|
} else if (
|
|
38
39
|
typeof row[field] === 'string' &&
|
|
39
|
-
|
|
40
|
+
isSpecialMissing(row[field])
|
|
40
41
|
) {
|
|
41
42
|
hasSpecialMissingString = true
|
|
42
43
|
}
|
|
@@ -130,10 +131,10 @@ export const convertToCSV = (
|
|
|
130
131
|
value = currentCell === null ? '' : currentCell
|
|
131
132
|
|
|
132
133
|
if (formats && formats[fieldName] === 'best.') {
|
|
133
|
-
if (value && !
|
|
134
|
+
if (value && !isSpecialMissing(value)) {
|
|
134
135
|
console.log(`🤖[value]🤖`, value)
|
|
135
136
|
throw new Error(
|
|
136
|
-
|
|
137
|
+
`A Special missing value can only be a single character from 'A' to 'Z', '_', '.[a-z]', '._'`
|
|
137
138
|
)
|
|
138
139
|
}
|
|
139
140
|
|