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

Compare commits

..

22 Commits

Author SHA1 Message Date
Yury Shkoda
59195e6379 Merge branch 'master' into snyk-upgrade-f3e7f573ad5222a75980dcffc4381458 2022-05-10 12:27:32 +03:00
Allan Bowe
72ed5e3fab chore: update test suite README with lrecl option 2022-04-28 11:11:46 +01:00
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
snyk-bot
3a820c56a9 fix: upgrade @sasjs/utils from 2.42.0 to 2.42.1
Snyk has created this PR to upgrade @sasjs/utils from 2.42.0 to 2.42.1.

See this package in npm:
https://www.npmjs.com/package/@sasjs/utils

See this project in Snyk:
https://app.snyk.io/org/allanbowe/project/2cf085e5-c256-4a84-bf6a-227076754853?utm_source=github&utm_medium=referral&page=upgrade-pr
2022-04-23 23:21:18 +00: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
Allan Bowe
7a42bc1b88 Merge pull request #698 from sasjs/executeScriptSASjs
feat: add method for executing scripts on sasjs server
2022-04-13 21:49:46 +03:00
Allan Bowe
6c02ee4cd6 Update SASjs.ts 2022-04-13 19:49:16 +01:00
73ee214b61 feat: add method for executing scripts on sasjs server 2022-04-13 18:22:26 +05:00
8 changed files with 80 additions and 24 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

@@ -65,7 +65,7 @@ The below services need to be created on your SAS server, at the location specif
```sas
filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
%inc mc;
filename ft15f001 temp;
filename ft15f001 temp lrecl=1000;
parmcards4;
%webout(FETCH)
%webout(OPEN)
@@ -113,7 +113,7 @@ data _null_;
```sas
filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
%inc mc;
filename ft15f001 temp;
filename ft15f001 temp lrecl=1000;
parmcards4;
%webout(FETCH)
%webout(OPEN)

View File

@@ -77,7 +77,7 @@ export default class SASjs {
}
/**
* Executes code against a SAS 9 server. Requires a runner to be present in
* Executes SAS code on a SAS 9 server. Requires a runner to be present in
* the users home directory in metadata.
* @param linesOfCode - lines of sas code from the file to run.
* @param username - a string representing the username.
@@ -97,6 +97,17 @@ export default class SASjs {
)
}
/**
* Executes SAS code on a SASJS server
* @param code - a string of code from the file to run.
* @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute scripts.
*/
public async executeScriptSASjs(code: string, authConfig?: AuthConfig) {
this.isMethodSupported('executeScriptSASJS', [ServerType.Sasjs])
return await this.sasJSApiClient?.executeScript(code, authConfig)
}
/**
* Executes sas code in a SAS Viya compute session.
* @param fileName - name of the file to run. It will be converted to path to the file being submitted for execution.
@@ -905,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!)
@@ -60,6 +62,39 @@ export class SASjsApiClient {
return Promise.resolve(result)
}
/**
* Executes code on a SASJS server.
* @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
if (authConfig) {
;({ access_token } = await getTokens(
this.requestClient,
authConfig,
ServerType.Sasjs
))
}
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
}
/**
* Exchanges the auth code for an access token for the given client.
* @param clientId - the client ID to authenticate with.

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]', '._'`
)
}