@sasjs/adapter 3.7.13 → 3.8.1

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.
@@ -14,6 +14,6 @@ export declare class Sas9JobExecutor extends BaseJobExecutor {
14
14
  private requestClient;
15
15
  private sas9RequestClient;
16
16
  constructor(serverUrl: string, serverType: ServerType, jobsPath: string, requestClient: RequestClient, httpsAgentOptions?: https.AgentOptions);
17
- execute(sasJob: string, data: any, config: any): Promise<any>;
17
+ execute(sasJob: string, data: any, config: any): Promise<unknown>;
18
18
  private getRequestParams;
19
19
  }
package/package.json CHANGED
@@ -72,12 +72,12 @@
72
72
  },
73
73
  "main": "index.js",
74
74
  "dependencies": {
75
- "@sasjs/utils": "2.36.1",
75
+ "@sasjs/utils": "2.40.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.7.13"
82
+ "version": "3.8.1"
83
83
  }
package/src/SASjs.ts CHANGED
@@ -17,7 +17,8 @@ import {
17
17
  MacroVar,
18
18
  AuthConfig,
19
19
  ExtraResponseAttributes,
20
- SasAuthResponse
20
+ SasAuthResponse,
21
+ StreamConfig
21
22
  } from '@sasjs/utils/types'
22
23
  import { RequestClient } from './request/RequestClient'
23
24
  import { SasjsRequestClient } from './request/SasjsRequestClient'
@@ -134,7 +135,7 @@ export default class SASjs {
134
135
 
135
136
  /**
136
137
  * Gets compute contexts.
137
- * @param accessToken - an access token for an authorized user.
138
+ * @param accessToken - an access token for an authorised user.
138
139
  */
139
140
  public async getComputeContexts(accessToken: string) {
140
141
  this.isMethodSupported('getComputeContexts', [ServerType.SasViya])
@@ -144,7 +145,7 @@ export default class SASjs {
144
145
 
145
146
  /**
146
147
  * Gets launcher contexts.
147
- * @param accessToken - an access token for an authorized user.
148
+ * @param accessToken - an access token for an authorised user.
148
149
  */
149
150
  public async getLauncherContexts(accessToken: string) {
150
151
  this.isMethodSupported('getLauncherContexts', [ServerType.SasViya])
@@ -163,7 +164,7 @@ export default class SASjs {
163
164
 
164
165
  /**
165
166
  * Gets executable compute contexts.
166
- * @param authConfig - an access token, refresh token, client and secret for an authorized user.
167
+ * @param authConfig - an access token, refresh token, client and secret for an authorised user.
167
168
  */
168
169
  public async getExecutableContexts(authConfig: AuthConfig) {
169
170
  this.isMethodSupported('getExecutableContexts', [ServerType.SasViya])
@@ -177,8 +178,8 @@ export default class SASjs {
177
178
  * @param launchContextName - the name of the launcher context used by the compute service.
178
179
  * @param sharedAccountId - the ID of the account to run the servers for this context as.
179
180
  * @param autoExecLines - the lines of code to execute during session initialization.
180
- * @param accessToken - an access token for an authorized user.
181
- * @param authorizedUsers - an optional list of authorized user IDs.
181
+ * @param accessToken - an access token for an authorised user.
182
+ * @param authorisedUsers - an optional list of authorised user IDs.
182
183
  */
183
184
  public async createComputeContext(
184
185
  contextName: string,
@@ -186,7 +187,7 @@ export default class SASjs {
186
187
  sharedAccountId: string,
187
188
  autoExecLines: string[],
188
189
  accessToken: string,
189
- authorizedUsers?: string[]
190
+ authorisedUsers?: string[]
190
191
  ) {
191
192
  this.isMethodSupported('createComputeContext', [ServerType.SasViya])
192
193
 
@@ -196,7 +197,7 @@ export default class SASjs {
196
197
  sharedAccountId,
197
198
  autoExecLines,
198
199
  accessToken,
199
- authorizedUsers
200
+ authorisedUsers
200
201
  )
201
202
  }
202
203
 
@@ -205,7 +206,7 @@ export default class SASjs {
205
206
  * @param contextName - the name of the context to be created.
206
207
  * @param description - the description of the context to be created.
207
208
  * @param launchType - launch type of the context to be created.
208
- * @param accessToken - an access token for an authorized user.
209
+ * @param accessToken - an access token for an authorised user.
209
210
  */
210
211
  public async createLauncherContext(
211
212
  contextName: string,
@@ -227,7 +228,7 @@ export default class SASjs {
227
228
  * Updates a compute context on the given server.
228
229
  * @param contextName - the original name of the context to be deleted.
229
230
  * @param editedContext - an object with the properties to be updated.
230
- * @param accessToken - an access token for an authorized user.
231
+ * @param accessToken - an access token for an authorised user.
231
232
  */
232
233
  public async editComputeContext(
233
234
  contextName: string,
@@ -246,7 +247,7 @@ export default class SASjs {
246
247
  /**
247
248
  * Deletes a compute context on the given server.
248
249
  * @param contextName - the name of the context to be deleted.
249
- * @param accessToken - an access token for an authorized user.
250
+ * @param accessToken - an access token for an authorised user.
250
251
  */
251
252
  public async deleteComputeContext(contextName: string, accessToken?: string) {
252
253
  this.isMethodSupported('deleteComputeContext', [ServerType.SasViya])
@@ -261,7 +262,7 @@ export default class SASjs {
261
262
  * Returns a JSON representation of a compute context.
262
263
  * @example: { "createdBy": "admin", "links": [...], "id": "ID", "version": 2, "name": "context1" }
263
264
  * @param contextName - the name of the context to return.
264
- * @param accessToken - an access token for an authorized user.
265
+ * @param accessToken - an access token for an authorised user.
265
266
  */
266
267
  public async getComputeContextByName(
267
268
  contextName: string,
@@ -278,7 +279,7 @@ export default class SASjs {
278
279
  /**
279
280
  * Returns a JSON representation of a compute context.
280
281
  * @param contextId - an id of the context to return.
281
- * @param accessToken - an access token for an authorized user.
282
+ * @param accessToken - an access token for an authorised user.
282
283
  */
283
284
  public async getComputeContextById(contextId: string, accessToken?: string) {
284
285
  this.isMethodSupported('getComputeContextById', [ServerType.SasViya])
@@ -891,17 +892,24 @@ export default class SASjs {
891
892
  * @param members - the JSON specifying the folders and services to be created.
892
893
  * @param appLoc - the base folder in which to create the new folders and
893
894
  * services. If not provided, is taken from SASjsConfig.
895
+ * @param streamConfig - optional configuration object of StreamConfig for deploying streaming app.
894
896
  * @param authConfig - a valid client, secret, refresh and access tokens that are authorised to execute compute jobs.
895
897
  */
896
898
  public async deployToSASjs(
897
899
  members: FileTree,
898
900
  appLoc?: string,
901
+ streamConfig?: StreamConfig,
899
902
  authConfig?: AuthConfig
900
903
  ) {
901
904
  if (!appLoc) {
902
905
  appLoc = this.sasjsConfig.appLoc
903
906
  }
904
- return await this.sasJSApiClient?.deploy(members, appLoc, authConfig)
907
+ return await this.sasJSApiClient?.deploy(
908
+ members,
909
+ appLoc,
910
+ streamConfig,
911
+ authConfig
912
+ )
905
913
  }
906
914
 
907
915
  public async executeJobSASjs(query: ExecutionQuery) {
@@ -972,7 +980,7 @@ export default class SASjs {
972
980
  /**
973
981
  * Fetches content of the log file
974
982
  * @param logUrl - url of the log file.
975
- * @param accessToken - an access token for an authorized user.
983
+ * @param accessToken - an access token for an authorised user.
976
984
  */
977
985
  public async fetchLogFileContent(logUrl: string, accessToken?: string) {
978
986
  return await this.requestClient!.get(logUrl, accessToken).then((res) => {
@@ -1,4 +1,4 @@
1
- import { AuthConfig, ServerType } from '@sasjs/utils/types'
1
+ import { AuthConfig, ServerType, StreamConfig } from '@sasjs/utils/types'
2
2
  import { FileTree, ExecutionQuery } from './types'
3
3
  import { RequestClient } from './request/RequestClient'
4
4
  import { getAccessTokenForSasjs } from './auth/getAccessTokenForSasjs'
@@ -20,6 +20,7 @@ export class SASjsApiClient {
20
20
  public async deploy(
21
21
  members: FileTree,
22
22
  appLoc: string,
23
+ streamConfig?: StreamConfig,
23
24
  authConfig?: AuthConfig
24
25
  ) {
25
26
  let access_token = (authConfig || {}).access_token
@@ -33,10 +34,17 @@ export class SASjsApiClient {
33
34
  const { result } = await this.requestClient.post<{
34
35
  status: string
35
36
  message: string
37
+ streamServiceName?: string
36
38
  example?: {}
37
39
  }>(
38
40
  'SASjsApi/drive/deploy',
39
- { fileTree: members, appLoc: appLoc },
41
+ {
42
+ fileTree: members,
43
+ appLoc: appLoc,
44
+ streamServiceName: streamConfig?.streamServiceName,
45
+ streamWebFolder: streamConfig?.streamWebFolder,
46
+ streamLogo: streamConfig?.streamLogo
47
+ },
40
48
  access_token,
41
49
  undefined,
42
50
  {},
@@ -26,11 +26,18 @@ export const generateFileUploadForm = (
26
26
  )
27
27
  }
28
28
 
29
- const file = new Blob([csv], {
30
- type: 'application/csv'
31
- })
29
+ if (typeof FormData === 'undefined' && formData instanceof NodeFormData) {
30
+ formData.append(name, csv, {
31
+ filename: `${name}.csv`,
32
+ contentType: 'application/csv'
33
+ })
34
+ } else {
35
+ const file = new Blob([csv], {
36
+ type: 'application/csv'
37
+ })
32
38
 
33
- formData.append(name, file, `${name}.csv`)
39
+ formData.append(name, file, `${name}.csv`)
40
+ }
34
41
  }
35
42
 
36
43
  return formData
@@ -74,26 +74,32 @@ export class Sas9JobExecutor extends BaseJobExecutor {
74
74
  ? 'multipart/form-data; boundary=' + (formData as any)._boundary
75
75
  : 'text/plain'
76
76
 
77
- return await this.sas9RequestClient!.post(
78
- apiUrl,
79
- formData,
80
- undefined,
81
- contentType,
82
- {
77
+ const requestPromise = new Promise((resolve, reject) =>
78
+ this.sas9RequestClient!.post(apiUrl, formData, undefined, contentType, {
83
79
  Accept: '*/*',
84
80
  Connection: 'Keep-Alive'
85
- }
86
- )
87
- .then((res: any) => {
88
- //appending response to requests array that will be used for requests history reference
89
- this.requestClient!.appendRequest(res, sasJob, config.debug)
90
- return res
91
- })
92
- .catch((err: any) => {
93
- //appending error to requests array that will be used for requests history reference
94
- this.requestClient!.appendRequest(err, sasJob, config.debug)
95
- return err
96
81
  })
82
+ .then((res: any) => {
83
+ // appending response to requests array that will be used for requests history reference
84
+ this.requestClient!.appendRequest(res, sasJob, config.debug)
85
+ resolve(res)
86
+ })
87
+ .catch((err: any) => {
88
+ // by default error string is equal to actual error object
89
+ let errString = err
90
+
91
+ // if error object contains non empty result attribute, set result to errString
92
+ if (err.result && err.result !== '') errString = err.result
93
+ // if there's no result but error message, set error message to errString
94
+ else if (err.message) errString = err.message
95
+
96
+ // appending error to requests array that will be used for requests history reference
97
+ this.requestClient!.appendRequest(errString, sasJob, config.debug)
98
+ reject(new ErrorResponse(err?.message, err))
99
+ })
100
+ )
101
+
102
+ return requestPromise
97
103
  }
98
104
 
99
105
  private getRequestParams(config: any): any {