@sasjs/adapter 3.10.18 → 4.0.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/SASjs.d.ts +19 -39
- package/SASjsApiClient.d.ts +7 -0
- package/index.d.ts +2 -0
- package/index.js +2 -2
- package/node/SASjs.d.ts +19 -39
- package/node/SASjsApiClient.d.ts +7 -0
- package/node/index.d.ts +2 -0
- package/node/index.js +2 -2
- package/package.json +1 -1
- package/src/SASjs.ts +70 -87
- package/src/SASjsApiClient.ts +7 -0
- package/src/index.ts +2 -0
package/package.json
CHANGED
package/src/SASjs.ts
CHANGED
|
@@ -17,7 +17,8 @@ import {
|
|
|
17
17
|
AuthConfig,
|
|
18
18
|
ExtraResponseAttributes,
|
|
19
19
|
SasAuthResponse,
|
|
20
|
-
ServicePackSASjs
|
|
20
|
+
ServicePackSASjs,
|
|
21
|
+
AuthConfigSas9
|
|
21
22
|
} from '@sasjs/utils/types'
|
|
22
23
|
import { RequestClient } from './request/RequestClient'
|
|
23
24
|
import { SasjsRequestClient } from './request/SasjsRequestClient'
|
|
@@ -33,6 +34,16 @@ import {
|
|
|
33
34
|
import { ErrorResponse } from './types/errors'
|
|
34
35
|
import { LoginOptions, LoginResult } from './types/Login'
|
|
35
36
|
|
|
37
|
+
interface ExecuteScriptParams {
|
|
38
|
+
linesOfCode: string[]
|
|
39
|
+
fileName?: string
|
|
40
|
+
contextName?: string
|
|
41
|
+
runTime?: string
|
|
42
|
+
authConfig?: AuthConfig
|
|
43
|
+
authConfigSas9?: AuthConfigSas9
|
|
44
|
+
debug?: boolean
|
|
45
|
+
}
|
|
46
|
+
|
|
36
47
|
const defaultConfig: SASjsConfig = {
|
|
37
48
|
serverUrl: '',
|
|
38
49
|
pathSASJS: '/SASjsApi/stp/execute',
|
|
@@ -79,74 +90,73 @@ export default class SASjs {
|
|
|
79
90
|
}
|
|
80
91
|
|
|
81
92
|
/**
|
|
82
|
-
* Executes
|
|
83
|
-
*
|
|
84
|
-
* @param
|
|
85
|
-
* @param
|
|
86
|
-
* @param
|
|
93
|
+
* Executes code on a SAS server.
|
|
94
|
+
* @param linesOfCode - lines of code to run.
|
|
95
|
+
* @param fileName - (required for server type sas viya) name of the file to run. It will be converted to path to the file being submitted for execution.
|
|
96
|
+
* @param contextName - (required for server type sas viya) context name on which code will be run on the server.
|
|
97
|
+
* @param runTime - (required for server type sasjs) a string to represent runTime for code execution.
|
|
98
|
+
* @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute scripts.
|
|
99
|
+
* @param authConfigSas9 - (required for server type sas9) a valid username and password that are authorised to execute scripts.
|
|
100
|
+
* @param debug - (optional) if true, global debug config will be overriden
|
|
87
101
|
*/
|
|
88
|
-
public async
|
|
89
|
-
linesOfCode
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
102
|
+
public async executeScript({
|
|
103
|
+
linesOfCode,
|
|
104
|
+
fileName,
|
|
105
|
+
contextName,
|
|
106
|
+
runTime,
|
|
107
|
+
authConfig,
|
|
108
|
+
authConfigSas9,
|
|
109
|
+
debug
|
|
110
|
+
}: ExecuteScriptParams) {
|
|
111
|
+
this.isMethodSupported('executeScript', [
|
|
112
|
+
ServerType.Sas9,
|
|
113
|
+
ServerType.Sasjs,
|
|
114
|
+
ServerType.SasViya
|
|
115
|
+
])
|
|
94
116
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
password
|
|
99
|
-
)
|
|
100
|
-
}
|
|
117
|
+
if (this.sasjsConfig.serverType === ServerType.Sas9) {
|
|
118
|
+
if (!authConfigSas9)
|
|
119
|
+
throw new Error('Auth config for sas9 is not provided')
|
|
101
120
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
code: string,
|
|
109
|
-
runTime?: string,
|
|
110
|
-
authConfig?: AuthConfig
|
|
111
|
-
) {
|
|
112
|
-
this.isMethodSupported('executeScriptSASJS', [ServerType.Sasjs])
|
|
121
|
+
return await this.sas9ApiClient?.executeScript(
|
|
122
|
+
linesOfCode,
|
|
123
|
+
authConfigSas9.userName,
|
|
124
|
+
authConfigSas9.password
|
|
125
|
+
)
|
|
126
|
+
}
|
|
113
127
|
|
|
114
|
-
|
|
115
|
-
|
|
128
|
+
if (this.sasjsConfig.serverType === ServerType.Sasjs) {
|
|
129
|
+
return await this.sasJSApiClient?.executeScript(
|
|
130
|
+
linesOfCode.join('\n'),
|
|
131
|
+
runTime,
|
|
132
|
+
authConfig
|
|
133
|
+
)
|
|
134
|
+
}
|
|
116
135
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
* @param fileName - name of the file to run. It will be converted to path to the file being submitted for execution.
|
|
120
|
-
* @param linesOfCode - lines of sas code from the file to run.
|
|
121
|
-
* @param contextName - context name on which code will be run on the server.
|
|
122
|
-
* @param authConfig - (optional) the access token, refresh token, client and secret for authorizing the request.
|
|
123
|
-
* @param debug - (optional) if true, global debug config will be overriden
|
|
124
|
-
*/
|
|
125
|
-
public async executeScriptSASViya(
|
|
126
|
-
fileName: string,
|
|
127
|
-
linesOfCode: string[],
|
|
128
|
-
contextName: string,
|
|
129
|
-
authConfig?: AuthConfig,
|
|
130
|
-
debug?: boolean
|
|
131
|
-
) {
|
|
132
|
-
this.isMethodSupported('executeScriptSASViya', [ServerType.SasViya])
|
|
136
|
+
if (this.sasjsConfig.serverType === ServerType.SasViya) {
|
|
137
|
+
contextName = contextName || this.sasjsConfig.contextName
|
|
133
138
|
|
|
134
|
-
|
|
139
|
+
if (!contextName) {
|
|
140
|
+
throw new Error(
|
|
141
|
+
'Context name is undefined. Please set a `contextName` in your SASjs or override config.'
|
|
142
|
+
)
|
|
143
|
+
}
|
|
135
144
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
145
|
+
if (!fileName) {
|
|
146
|
+
throw new Error(
|
|
147
|
+
'File name is required in case of SAS VIYA. Please provide a `fileName`.'
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return await this.sasViyaApiClient!.executeScript(
|
|
152
|
+
fileName,
|
|
153
|
+
linesOfCode,
|
|
154
|
+
contextName,
|
|
155
|
+
authConfig,
|
|
156
|
+
null,
|
|
157
|
+
debug ? debug : this.sasjsConfig.debug
|
|
139
158
|
)
|
|
140
159
|
}
|
|
141
|
-
|
|
142
|
-
return await this.sasViyaApiClient!.executeScript(
|
|
143
|
-
fileName,
|
|
144
|
-
linesOfCode,
|
|
145
|
-
contextName,
|
|
146
|
-
authConfig,
|
|
147
|
-
null,
|
|
148
|
-
debug ? debug : this.sasjsConfig.debug
|
|
149
|
-
)
|
|
150
160
|
}
|
|
151
161
|
|
|
152
162
|
/**
|
|
@@ -826,33 +836,6 @@ export default class SASjs {
|
|
|
826
836
|
)
|
|
827
837
|
}
|
|
828
838
|
|
|
829
|
-
/**
|
|
830
|
-
* Creates the folders and services at the given location `appLoc` on the given server `serverUrl`.
|
|
831
|
-
* @param dataJson - the JSON specifying the folders and files to be created, can also includes
|
|
832
|
-
* appLoc, streamServiceName, streamWebFolder, streamLogo
|
|
833
|
-
* @param appLoc - (optional) the base folder in which to create the new folders and
|
|
834
|
-
* services. If not provided, is taken from SASjsConfig. Precedence will be of appLoc present in dataJson.
|
|
835
|
-
* @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute compute jobs.
|
|
836
|
-
*/
|
|
837
|
-
public async deployToSASjs(
|
|
838
|
-
dataJson: ServicePackSASjs,
|
|
839
|
-
appLoc?: string,
|
|
840
|
-
authConfig?: AuthConfig
|
|
841
|
-
) {
|
|
842
|
-
if (!appLoc) {
|
|
843
|
-
appLoc = this.sasjsConfig.appLoc
|
|
844
|
-
}
|
|
845
|
-
return await this.sasJSApiClient?.deploy(dataJson, appLoc, authConfig)
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
public async executeJobSASjs(query: ExecutionQuery, authConfig?: AuthConfig) {
|
|
849
|
-
return await this.sasJSApiClient?.executeJob(
|
|
850
|
-
query,
|
|
851
|
-
this.sasjsConfig.appLoc,
|
|
852
|
-
authConfig
|
|
853
|
-
)
|
|
854
|
-
}
|
|
855
|
-
|
|
856
839
|
/**
|
|
857
840
|
* Kicks off execution of the given job via the compute API.
|
|
858
841
|
* @returns an object representing the compute session created for the given job.
|
package/src/SASjsApiClient.ts
CHANGED
|
@@ -8,6 +8,13 @@ import { getTokens } from './auth/getTokens'
|
|
|
8
8
|
export class SASjsApiClient {
|
|
9
9
|
constructor(private requestClient: RequestClient) {}
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Creates the folders and services at the given location `appLoc` on the given server `serverUrl`.
|
|
13
|
+
* @param dataJson - the JSON specifying the folders and files to be created, can also includes
|
|
14
|
+
* appLoc, streamServiceName, streamWebFolder, streamLogo
|
|
15
|
+
* @param appLoc - the base folder in which to create the new folders and services.
|
|
16
|
+
* @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute compute jobs.
|
|
17
|
+
*/
|
|
11
18
|
public async deploy(
|
|
12
19
|
dataJson: ServicePackSASjs,
|
|
13
20
|
appLoc: string,
|