1
0
mirror of https://github.com/sasjs/adapter.git synced 2025-12-11 09:24:35 +00:00

Compare commits

..

16 Commits

Author SHA1 Message Date
Muhammad Saad
6bfd7024ce Merge pull request #705 from sasjs/issue-703
sasjs server type - request and job execution auth fix
2022-04-27 19:18:44 -07:00
fdc3e1cce8 style: lint 2022-04-26 17:41:35 +02:00
fc47222830 fix: web request method - login callback handling 2022-04-26 17:37:13 +02:00
Yury Shkoda
0a5de21386 Merge pull request #704 from sasjs/chore
chore: removed console.log
2022-04-26 17:34:58 +03:00
Yury Shkoda
1cbe57d512 chore: removed console.log 2022-04-26 17:25:21 +03:00
936e4f8c0a fix: sasjs server type - request and job execution auth fix 2022-04-26 16:18:36 +02:00
Allan Bowe
4ebf949912 Merge pull request #699 from sasjs/special-missing
Special missing function from @sasjs/utils
2022-04-26 13:54:11 +03:00
c00c8007e5 chore: utils update 2022-04-26 12:27:55 +02:00
54516665bf chore: string escaping 2022-04-22 11:54:59 +02:00
ecec2e77c0 chore: error improved 2022-04-21 15:45:59 +02:00
Allan Bowe
102898ac33 Merge pull request #700 from sasjs/parse-log-in-executeScript
fix: parse log in executeScript method on sasjs server
2022-04-18 21:31:31 +03:00
7370a2be4c fix: can not read property map of undefined 2022-04-18 23:28:12 +05:00
135d019026 chore: update tsdoc for executeScript method 2022-04-18 22:56:51 +05:00
e2651344d7 fix: parse log in executeScript method on sasjs server 2022-04-18 22:50:27 +05:00
9bf3885868 chore: test fix 2022-04-18 14:54:50 +02:00
caa5aa47dc fix: isSpecialMissing from utils 2022-04-18 14:49:57 +02:00
7 changed files with 51 additions and 28 deletions

14
package-lock.json generated
View File

@@ -8,7 +8,7 @@
"hasInstallScript": true,
"license": "ISC",
"dependencies": {
"@sasjs/utils": "2.42.0",
"@sasjs/utils": "2.44.0",
"axios": "0.26.0",
"axios-cookiejar-support": "1.0.1",
"form-data": "4.0.0",
@@ -1142,9 +1142,9 @@
}
},
"node_modules/@sasjs/utils": {
"version": "2.42.0",
"resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.42.0.tgz",
"integrity": "sha512-Y69l89PYNF/h9xvVH72om/39xA+cY80bhiVLzp/fJb3BlvzCf4RNswBBanUOv2I5JNa7gPpJuE7mEiXOlhD3eg==",
"version": "2.44.0",
"resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.44.0.tgz",
"integrity": "sha512-hpC4erHYA8Mcb38mzxFEP0cXehfa0iKeqSW2d9MmxZ9g2qpy0BU6xyZJohN9kOiafXo5H359ndNKsg4DOq5YgA==",
"hasInstallScript": true,
"dependencies": {
"@types/fs-extra": "9.0.13",
@@ -13870,9 +13870,9 @@
}
},
"@sasjs/utils": {
"version": "2.42.0",
"resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.42.0.tgz",
"integrity": "sha512-Y69l89PYNF/h9xvVH72om/39xA+cY80bhiVLzp/fJb3BlvzCf4RNswBBanUOv2I5JNa7gPpJuE7mEiXOlhD3eg==",
"version": "2.44.0",
"resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.44.0.tgz",
"integrity": "sha512-hpC4erHYA8Mcb38mzxFEP0cXehfa0iKeqSW2d9MmxZ9g2qpy0BU6xyZJohN9kOiafXo5H359ndNKsg4DOq5YgA==",
"requires": {
"@types/fs-extra": "9.0.13",
"@types/prompts": "2.0.13",

View File

@@ -72,7 +72,7 @@
},
"main": "index.js",
"dependencies": {
"@sasjs/utils": "2.42.0",
"@sasjs/utils": "2.44.0",
"axios": "0.26.0",
"axios-cookiejar-support": "1.0.1",
"form-data": "4.0.0",

View File

@@ -916,8 +916,8 @@ export default class SASjs {
return await this.sasJSApiClient?.deploy(dataJson, appLoc, authConfig)
}
public async executeJobSASjs(query: ExecutionQuery) {
return await this.sasJSApiClient?.executeJob(query)
public async executeJobSASjs(query: ExecutionQuery, authConfig?: AuthConfig) {
return await this.sasJSApiClient?.executeJob(query, authConfig)
}
/**

View File

@@ -43,7 +43,9 @@ export class SASjsApiClient {
return Promise.resolve(result)
}
public async executeJob(query: ExecutionQuery) {
public async executeJob(query: ExecutionQuery, authConfig?: AuthConfig) {
const access_token = authConfig ? authConfig.access_token : undefined
const { result } = await this.requestClient.post<{
status: string
message: string
@@ -51,7 +53,7 @@ export class SASjsApiClient {
logPath?: string
error?: {}
_webout?: string
}>('SASjsApi/stp/execute', query, undefined)
}>('SASjsApi/stp/execute', query, access_token)
if (Object.keys(result).includes('_webout')) {
result._webout = parseWeboutResponse(result._webout!)
@@ -62,8 +64,8 @@ export class SASjsApiClient {
/**
* Executes code on a SASJS server.
* @param serverUrl - a server url to execute code.
* @param code - a string of code to execute.
* @param authConfig - an object for authentication.
*/
public async executeScript(code: string, authConfig?: AuthConfig) {
let access_token = (authConfig || {}).access_token
@@ -74,12 +76,23 @@ export class SASjsApiClient {
ServerType.Sasjs
))
}
const response = await this.requestClient.post(
'SASjsApi/code/execute',
{ code },
access_token
)
return response.result as string
let parsedSasjsServerLog = ''
await this.requestClient
.post('SASjsApi/code/execute', { code }, access_token)
.then((res: any) => {
if (res.result?.log) {
parsedSasjsServerLog = res.result.log
.map((logLine: any) => logLine.line)
.join('\n')
}
})
.catch((err) => {
parsedSasjsServerLog = err
})
return parsedSasjsServerLog
}
/**

View File

@@ -21,6 +21,7 @@ import {
} from '../utils'
import { BaseJobExecutor } from './JobExecutor'
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
import { Server } from 'https'
export interface WaitingRequstPromise {
promise: Promise<any> | null
@@ -46,7 +47,7 @@ export class WebJobExecutor extends BaseJobExecutor {
authConfig?: AuthConfig,
extraResponseAttributes: ExtraResponseAttributes[] = []
) {
const loginCallback = loginRequiredCallback || (() => Promise.resolve())
const loginCallback = loginRequiredCallback
const program = isRelativePath(sasJob)
? config.appLoc
? config.appLoc.replace(/\/?$/, '/') + sasJob.replace(/^\//, '')
@@ -79,7 +80,7 @@ export class WebJobExecutor extends BaseJobExecutor {
)
})
await loginCallback()
if (loginCallback) await loginCallback()
} else {
reject(new ErrorResponse(e?.message, e))
}
@@ -220,6 +221,15 @@ export class WebJobExecutor extends BaseJobExecutor {
}
if (e instanceof LoginRequiredError) {
if (!loginRequiredCallback) {
reject(
new ErrorResponse(
'Request is not authenticated. Make sure .env file exists with valid credentials.',
e
)
)
}
this.appendWaitingRequest(() => {
return this.execute(
sasJob,
@@ -238,7 +248,7 @@ export class WebJobExecutor extends BaseJobExecutor {
)
})
await loginCallback()
if (loginCallback) await loginCallback()
} else {
reject(new ErrorResponse(e?.message, e))
}

View File

@@ -62,7 +62,7 @@ describe('formatDataForRequest', () => {
expect(() => formatDataForRequest(tableWithMissingValues)).toThrow(
new Error(
'Special missing value can only be a single character from A to Z or _'
`A Special missing value can only be a single character from 'A' to 'Z', '_', '.[a-z]', '._'`
)
)
})

View File

@@ -1,3 +1,5 @@
import { isSpecialMissing } from '@sasjs/utils'
/**
* Converts the given JSON object array to a CSV string.
* @param data - the array of JSON objects to convert.
@@ -18,7 +20,6 @@ export const convertToCSV = (
let headers: string[] = []
let csvTest
let invalidString = false
const specialMissingValueRegExp = /^[a-z_]{1}$/i
if (formats) {
headers = Object.keys(formats).map((key) => `${key}:${formats![key]}`)
@@ -36,7 +37,7 @@ export const convertToCSV = (
hasNullOrNumber = true
} else if (
typeof row[field] === 'string' &&
specialMissingValueRegExp.test(row[field])
isSpecialMissing(row[field])
) {
hasSpecialMissingString = true
}
@@ -130,10 +131,9 @@ export const convertToCSV = (
value = currentCell === null ? '' : currentCell
if (formats && formats[fieldName] === 'best.') {
if (value && !specialMissingValueRegExp.test(value)) {
console.log(`🤖[value]🤖`, value)
if (value && !isSpecialMissing(value)) {
throw new Error(
'Special missing value can only be a single character from A to Z or _'
`A Special missing value can only be a single character from 'A' to 'Z', '_', '.[a-z]', '._'`
)
}