@sasjs/adapter 3.9.0 → 3.9.3

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/package.json CHANGED
@@ -72,12 +72,12 @@
72
72
  },
73
73
  "main": "index.js",
74
74
  "dependencies": {
75
- "@sasjs/utils": "2.42.0",
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.9.0"
82
+ "version": "3.9.3"
83
83
  }
package/src/SASjs.ts CHANGED
@@ -916,8 +916,8 @@ export default class SASjs {
916
916
  return await this.sasJSApiClient?.deploy(dataJson, appLoc, authConfig)
917
917
  }
918
918
 
919
- public async executeJobSASjs(query: ExecutionQuery) {
920
- return await this.sasJSApiClient?.executeJob(query)
919
+ public async executeJobSASjs(query: ExecutionQuery, authConfig?: AuthConfig) {
920
+ return await this.sasJSApiClient?.executeJob(query, authConfig)
921
921
  }
922
922
 
923
923
  /**
@@ -43,7 +43,9 @@ export class SASjsApiClient {
43
43
  return Promise.resolve(result)
44
44
  }
45
45
 
46
- public async executeJob(query: ExecutionQuery) {
46
+ public async executeJob(query: ExecutionQuery, authConfig?: AuthConfig) {
47
+ const access_token = authConfig ? authConfig.access_token : undefined
48
+
47
49
  const { result } = await this.requestClient.post<{
48
50
  status: string
49
51
  message: string
@@ -51,7 +53,7 @@ export class SASjsApiClient {
51
53
  logPath?: string
52
54
  error?: {}
53
55
  _webout?: string
54
- }>('SASjsApi/stp/execute', query, undefined)
56
+ }>('SASjsApi/stp/execute', query, access_token)
55
57
 
56
58
  if (Object.keys(result).includes('_webout')) {
57
59
  result._webout = parseWeboutResponse(result._webout!)
@@ -62,8 +64,8 @@ export class SASjsApiClient {
62
64
 
63
65
  /**
64
66
  * Executes code on a SASJS server.
65
- * @param serverUrl - a server url to execute code.
66
67
  * @param code - a string of code to execute.
68
+ * @param authConfig - an object for authentication.
67
69
  */
68
70
  public async executeScript(code: string, authConfig?: AuthConfig) {
69
71
  let access_token = (authConfig || {}).access_token
@@ -74,12 +76,23 @@ export class SASjsApiClient {
74
76
  ServerType.Sasjs
75
77
  ))
76
78
  }
77
- const response = await this.requestClient.post(
78
- 'SASjsApi/code/execute',
79
- { code },
80
- access_token
81
- )
82
- return response.result as string
79
+
80
+ let parsedSasjsServerLog = ''
81
+
82
+ await this.requestClient
83
+ .post('SASjsApi/code/execute', { code }, access_token)
84
+ .then((res: any) => {
85
+ if (res.result?.log) {
86
+ parsedSasjsServerLog = res.result.log
87
+ .map((logLine: any) => logLine.line)
88
+ .join('\n')
89
+ }
90
+ })
91
+ .catch((err) => {
92
+ parsedSasjsServerLog = err
93
+ })
94
+
95
+ return parsedSasjsServerLog
83
96
  }
84
97
 
85
98
  /**
@@ -21,6 +21,7 @@ import {
21
21
  } from '../utils'
22
22
  import { BaseJobExecutor } from './JobExecutor'
23
23
  import { parseWeboutResponse } from '../utils/parseWeboutResponse'
24
+ import { Server } from 'https'
24
25
 
25
26
  export interface WaitingRequstPromise {
26
27
  promise: Promise<any> | null
@@ -46,7 +47,7 @@ export class WebJobExecutor extends BaseJobExecutor {
46
47
  authConfig?: AuthConfig,
47
48
  extraResponseAttributes: ExtraResponseAttributes[] = []
48
49
  ) {
49
- const loginCallback = loginRequiredCallback || (() => Promise.resolve())
50
+ const loginCallback = loginRequiredCallback
50
51
  const program = isRelativePath(sasJob)
51
52
  ? config.appLoc
52
53
  ? config.appLoc.replace(/\/?$/, '/') + sasJob.replace(/^\//, '')
@@ -79,7 +80,7 @@ export class WebJobExecutor extends BaseJobExecutor {
79
80
  )
80
81
  })
81
82
 
82
- await loginCallback()
83
+ if (loginCallback) await loginCallback()
83
84
  } else {
84
85
  reject(new ErrorResponse(e?.message, e))
85
86
  }
@@ -220,6 +221,15 @@ export class WebJobExecutor extends BaseJobExecutor {
220
221
  }
221
222
 
222
223
  if (e instanceof LoginRequiredError) {
224
+ if (!loginRequiredCallback) {
225
+ reject(
226
+ new ErrorResponse(
227
+ 'Request is not authenticated. Make sure .env file exists with valid credentials.',
228
+ e
229
+ )
230
+ )
231
+ }
232
+
223
233
  this.appendWaitingRequest(() => {
224
234
  return this.execute(
225
235
  sasJob,
@@ -238,7 +248,7 @@ export class WebJobExecutor extends BaseJobExecutor {
238
248
  )
239
249
  })
240
250
 
241
- await loginCallback()
251
+ if (loginCallback) await loginCallback()
242
252
  } else {
243
253
  reject(new ErrorResponse(e?.message, e))
244
254
  }
@@ -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
- specialMissingValueRegExp.test(row[field])
40
+ isSpecialMissing(row[field])
40
41
  ) {
41
42
  hasSpecialMissingString = true
42
43
  }
@@ -130,10 +131,9 @@ export const convertToCSV = (
130
131
  value = currentCell === null ? '' : currentCell
131
132
 
132
133
  if (formats && formats[fieldName] === 'best.') {
133
- if (value && !specialMissingValueRegExp.test(value)) {
134
- console.log(`🤖[value]🤖`, value)
134
+ if (value && !isSpecialMissing(value)) {
135
135
  throw new Error(
136
- 'Special missing value can only be a single character from A to Z or _'
136
+ `A Special missing value can only be a single character from 'A' to 'Z', '_', '.[a-z]', '._'`
137
137
  )
138
138
  }
139
139