1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-03 10:40:06 +00:00

Compare commits

..

1 Commits

Author SHA1 Message Date
Krishna Acondy
232f4ec3fb chore(*): add tests for SessionManager 2020-11-24 07:42:18 +00:00
48 changed files with 227 additions and 4767 deletions

View File

@@ -27,6 +27,16 @@ jobs:
run: npm run lint
- name: Run unit tests
run: npm test
env:
CI: true
CLIENT: ${{secrets.CLIENT}}
SECRET: ${{secrets.SECRET}}
SAS_USERNAME: ${{secrets.SAS_USERNAME}}
SAS_PASSWORD: ${{secrets.SAS_PASSWORD}}
SERVER_URL: ${{secrets.SERVER_URL}}
SERVER_TYPE: ${{secrets.SERVER_TYPE}}
ACCESS_TOKEN: ${{secrets.ACCESS_TOKEN}}
REFRESH_TOKEN: ${{secrets.REFRESH_TOKEN}}
- name: Build Package
run: npm run package:lib
env:

2
.gitignore vendored
View File

@@ -1,2 +1,2 @@
node_modules
build
build

View File

@@ -14,5 +14,5 @@ What code changes have been made to achieve the intent.
- [ ] Code is formatted correctly (`npm run lint:fix`).
- [ ] All unit tests are passing (`npm test`).
- [ ] All `sasjs-cli` unit tests are passing (`npm test`).
- [ ] All `sasjs-tests` unit tests are passing (`npm test`).
- [ ] All `sasjs-tests` are passing (instructions available [here](https://github.com/sasjs/adapter/blob/master/sasjs-tests/README.md)).

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

119
package-lock.json generated
View File

@@ -3688,6 +3688,12 @@
"is-obj": "^2.0.0"
}
},
"dotenv": {
"version": "8.2.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz",
"integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==",
"dev": true
},
"duplexer2": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/duplexer2/-/duplexer2-0.1.4.tgz",
@@ -4794,9 +4800,9 @@
}
},
"highlight.js": {
"version": "10.4.0",
"resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.4.0.tgz",
"integrity": "sha512-EfrUGcQ63oLJbj0J0RI9ebX6TAITbsDBLbsjr881L/X5fMO9+oadKzEF21C7R3ULKG6Gv3uoab2HiqVJa/4+oA==",
"version": "10.1.1",
"resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.1.1.tgz",
"integrity": "sha512-b4L09127uVa+9vkMgPpdUQP78ickGbHEQTWeBrQFTJZ4/n2aihWOGS0ZoUqAwjVmfjhq/C76HRzkqwZhK4sBbg==",
"dev": true
},
"hmac-drbg": {
@@ -4936,6 +4942,14 @@
"dev": true,
"requires": {
"resolve-from": "^5.0.0"
},
"dependencies": {
"resolve-from": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz",
"integrity": "sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==",
"dev": true
}
}
},
"import-local": {
@@ -8563,9 +8577,9 @@
"dev": true
},
"npm": {
"version": "6.14.9",
"resolved": "https://registry.npmjs.org/npm/-/npm-6.14.9.tgz",
"integrity": "sha512-yHi1+i9LyAZF1gAmgyYtVk+HdABlLy94PMIDoK1TRKWvmFQAt5z3bodqVwKvzY0s6dLqQPVsRLiwhJfNtiHeCg==",
"version": "6.14.8",
"resolved": "https://registry.npmjs.org/npm/-/npm-6.14.8.tgz",
"integrity": "sha512-HBZVBMYs5blsj94GTeQZel7s9odVuuSUHy1+AlZh7rPVux1os2ashvEGLy/STNK7vUjbrCg5Kq9/GXisJgdf6A==",
"dev": true,
"requires": {
"JSONStream": "^1.3.5",
@@ -8648,7 +8662,7 @@
"npm-pick-manifest": "^3.0.2",
"npm-profile": "^4.0.4",
"npm-registry-fetch": "^4.0.7",
"npm-user-validate": "^1.0.1",
"npm-user-validate": "~1.0.0",
"npmlog": "~4.1.2",
"once": "~1.4.0",
"opener": "^1.5.1",
@@ -8723,6 +8737,17 @@
"humanize-ms": "^1.2.1"
}
},
"ajv": {
"version": "5.5.2",
"bundled": true,
"dev": true,
"requires": {
"co": "^4.6.0",
"fast-deep-equal": "^1.0.0",
"fast-json-stable-stringify": "^2.0.0",
"json-schema-traverse": "^0.3.0"
}
},
"ansi-align": {
"version": "2.0.0",
"bundled": true,
@@ -9053,6 +9078,11 @@
"mkdirp": "~0.5.0"
}
},
"co": {
"version": "4.6.0",
"bundled": true,
"dev": true
},
"code-point-at": {
"version": "1.1.0",
"bundled": true,
@@ -9501,6 +9531,11 @@
"bundled": true,
"dev": true
},
"fast-deep-equal": {
"version": "1.1.0",
"bundled": true,
"dev": true
},
"fast-json-stable-stringify": {
"version": "2.0.0",
"bundled": true,
@@ -9821,35 +9856,12 @@
"dev": true
},
"har-validator": {
"version": "5.1.5",
"version": "5.1.0",
"bundled": true,
"dev": true,
"requires": {
"ajv": "^6.12.3",
"ajv": "^5.3.0",
"har-schema": "^2.0.0"
},
"dependencies": {
"ajv": {
"version": "6.12.6",
"bundled": true,
"dev": true,
"requires": {
"fast-deep-equal": "^3.1.1",
"fast-json-stable-stringify": "^2.0.0",
"json-schema-traverse": "^0.4.1",
"uri-js": "^4.2.2"
}
},
"fast-deep-equal": {
"version": "3.1.3",
"bundled": true,
"dev": true
},
"json-schema-traverse": {
"version": "0.4.1",
"bundled": true,
"dev": true
}
}
},
"has": {
@@ -10136,6 +10148,11 @@
"bundled": true,
"dev": true
},
"json-schema-traverse": {
"version": "0.3.1",
"bundled": true,
"dev": true
},
"json-stringify-safe": {
"version": "5.0.1",
"bundled": true,
@@ -10777,11 +10794,6 @@
"path-key": "^2.0.0"
}
},
"npm-user-validate": {
"version": "1.0.1",
"bundled": true,
"dev": true
},
"npmlog": {
"version": "4.1.2",
"bundled": true,
@@ -11782,21 +11794,6 @@
"xdg-basedir": "^3.0.0"
}
},
"uri-js": {
"version": "4.4.0",
"bundled": true,
"dev": true,
"requires": {
"punycode": "^2.1.0"
},
"dependencies": {
"punycode": {
"version": "2.1.1",
"bundled": true,
"dev": true
}
}
},
"url-parse-lax": {
"version": "1.0.0",
"bundled": true,
@@ -12100,6 +12097,12 @@
"path-key": "^2.0.0"
}
},
"npm-user-validate": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/npm-user-validate/-/npm-user-validate-1.0.1.tgz",
"integrity": "sha512-uQwcd/tY+h1jnEaze6cdX/LrhWhoBxfSknxentoqmIuStxUExxjWd3ULMLFPiFUrZKbOVMowH6Jq2FRWfmhcEw==",
"dev": true
},
"nwsapi": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.0.tgz",
@@ -13247,9 +13250,9 @@
}
},
"semantic-release": {
"version": "17.3.0",
"resolved": "https://registry.npmjs.org/semantic-release/-/semantic-release-17.3.0.tgz",
"integrity": "sha512-enhDayMZRP4nWcWAMBFHHB7THRaIcRdUAZv3lxd65pXs2ttzay7IeCvRRrGayRWExtnY0ulwRz5Ycp88Dv/UeQ==",
"version": "17.2.3",
"resolved": "https://registry.npmjs.org/semantic-release/-/semantic-release-17.2.3.tgz",
"integrity": "sha512-MY1MlowGQrkOR7+leOD8ICkVOC6i1szbwDODdbJ0UdshtMx8Ms0bhpRQmEEliqYKEb5PLv/dqs6zKKuHT7UxTg==",
"dev": true,
"requires": {
"@semantic-release/commit-analyzer": "^8.0.0",
@@ -13340,6 +13343,12 @@
"integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==",
"dev": true
},
"resolve-from": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz",
"integrity": "sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==",
"dev": true
},
"semver": {
"version": "7.3.2",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz",

View File

@@ -2,7 +2,7 @@
"name": "@sasjs/adapter",
"description": "JavaScript adapter for SAS",
"scripts": {
"build": "rimraf build && rimraf node && mkdir node && cp -r src/* node && webpack && rimraf build/src && rimraf node",
"build": "rimraf build && webpack",
"package:lib": "npm run build && cp ./package.json build && cd build && npm version \"5.0.0\" && npm pack",
"publish:lib": "npm run build && cd build && npm publish",
"lint:fix": "npx prettier --write 'src/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}'",
@@ -39,10 +39,11 @@
"@types/isomorphic-fetch": "0.0.35",
"@types/jest": "^26.0.15",
"cp": "^0.2.0",
"dotenv": "^8.2.0",
"jest": "^25.5.4",
"path": "^0.12.7",
"rimraf": "^3.0.2",
"semantic-release": "^17.3.0",
"semantic-release": "^17.2.3",
"terser-webpack-plugin": "^4.2.3",
"ts-jest": "^25.5.1",
"ts-loader": "^8.0.11",

View File

@@ -1357,9 +1357,9 @@
"integrity": "sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw=="
},
"@sasjs/adapter": {
"version": "1.18.3",
"resolved": "https://registry.npmjs.org/@sasjs/adapter/-/adapter-1.18.3.tgz",
"integrity": "sha512-wzDFJRyt2dXFeQP+JzqRGunYUbujrAbU/Jc4IWg5URsCkGAzwsNl/4G0xJVbqOTy1MvoZ431rfCnvhkUlg7D3Q==",
"version": "1.12.0",
"resolved": "https://registry.npmjs.org/@sasjs/adapter/-/adapter-1.12.0.tgz",
"integrity": "sha512-0uGQH9ynomWzdBaEujEtcR38q6V7LCgG0mrb1Wellv6cC/IHD3j6WfeZZAgtiMPeOSJjbCDBOlVnzC2TlBqJFw==",
"requires": {
"es6-promise": "^4.2.8",
"form-data": "^3.0.0",

View File

@@ -4,7 +4,7 @@
"homepage": ".",
"private": true,
"dependencies": {
"@sasjs/adapter": "^1.18.2",
"@sasjs/adapter": "^1.12.0",
"@sasjs/test-framework": "^1.4.0",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",

View File

@@ -0,0 +1,9 @@
import React from "react";
import { render } from "@testing-library/react";
import App from "./App";
test("renders learn react link", () => {
const { getByText } = render(<App />);
const linkElement = getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});

View File

@@ -3,12 +3,12 @@ import { TestSuite } from "@sasjs/test-framework";
const defaultConfig: SASjsConfig = {
serverUrl: window.location.origin,
pathSAS9: '/SASStoredProcess/do',
pathSASViya: '/SASJobExecution',
appLoc: '/Public/seedapp',
pathSAS9: "/SASStoredProcess/do",
pathSASViya: "/SASJobExecution",
appLoc: "/Public/seedapp",
serverType: ServerType.SASViya,
debug: false,
contextName: 'SAS Job Execution compute context',
debug: true,
contextName: "SAS Job Execution compute context",
useComputeApi: false
};
@@ -57,7 +57,6 @@ export const basicTests = (
},
assertion: (sasjsInstance: SASjs) => {
const sasjsConfig = sasjsInstance.getSasjsConfig();
return (
sasjsConfig.serverUrl === defaultConfig.serverUrl &&
sasjsConfig.pathSAS9 === defaultConfig.pathSAS9 &&

View File

@@ -25,71 +25,17 @@ export const computeTests = (adapter: SASjs): TestSuite => ({
},
assertion: (res: any) => {
const expectedProperties = ["id", "state", "creationTimeStamp", "jobConditionCode"]
return validate(expectedProperties, res.result);
}
},
{
title: "Execute Script Viya - complete job",
description: "Should execute sas file and return log",
test: () => {
const fileLines = [
`data;`,
`do x=1 to 100;`,
`output;`,
`end;`,
`run;`
]
return adapter.executeScriptSASViya(
'sasCode.sas',
fileLines,
'SAS Studio compute context',
undefined,
true
)
},
assertion: (res: any) => {
const expectedLogContent = `1 data;\\n2 do x=1 to 100;\\n3 output;\\n4 end;\\n5 run;\\n\\n`
return validateLog(expectedLogContent, res.log);
}
},
{
title: "Execute Script Viya - failed job",
description: "Should execute sas file and return log",
test: () => {
const fileLines = [
`%abort;`
]
return adapter.executeScriptSASViya(
'sasCode.sas',
fileLines,
'SAS Studio compute context',
undefined,
true
).catch((err: any) => err )
},
assertion: (res: any) => {
const expectedLogContent = `1 %abort;\\nERROR: The %ABORT statement is not valid in open code.\\n`
return validateLog(expectedLogContent, res.log);
return validate(expectedProperties, res);
}
}
]
});
const validateLog = (text: string, log: string): boolean => {
const isValid = JSON.stringify(log).includes(text)
return isValid
}
const validate = (expectedProperties: string[], data: any): boolean => {
const actualProperties = Object.keys(data);
const isValid = expectedProperties.every(
(property) => actualProperties.includes(property)
);
return isValid
const isValid = expectedProperties.every(
(property) => actualProperties.includes(property)
);
return isValid
}

View File

@@ -88,7 +88,7 @@ export const sendArrTests = (adapter: SASjs): TestSuite => ({
return adapter.request("common/sendArr", data).catch((e) => e);
},
assertion: (error: any) => {
return !!error && !!error.error && !!error.error.message;
return !!error && !!error.body && !!error.body.message;
}
},
{
@@ -185,7 +185,7 @@ export const sendObjTests = (adapter: SASjs): TestSuite => ({
};
return adapter.request("common/sendObj", invalidData).catch((e) => e);
},
assertion: (error: any) => !!error && !!error.error && !!error.error.message
assertion: (error: any) => !!error && !!error.body && !!error.body.message
},
{
title: "Single string value",
@@ -219,7 +219,7 @@ export const sendObjTests = (adapter: SASjs): TestSuite => ({
.catch((e) => e);
},
assertion: (error: any) => {
return !!error && !!error.error && !!error.error.message;
return !!error && !!error.body && !!error.body.message;
}
},
{

View File

@@ -23,24 +23,22 @@ export const sasjsRequestTests = (adapter: SASjs): TestSuite => ({
},
{
title: "Make error and capture log",
description: "Should make an error and capture log, in the same time it is testing if debug override is working",
description: "Should make an error and capture log",
test: async () => {
return new Promise(async (resolve, reject) => {
adapter
.request("common/makeErr", data, {debug: true})
.request("common/makeErr", data)
.then((res) => {
//no action here, this request must throw error
})
.catch((err) => {
let sasRequests = adapter.getSasRequests();
let makeErrRequest: any =
let makeErrRequest =
sasRequests.find((req) =>
req.serviceLink.includes("makeErr")
) || null;
if (!makeErrRequest) resolve(false)
resolve(!!(makeErrRequest.logFile && makeErrRequest.logFile.length > 0));
resolve(!!makeErrRequest);
});
});
},

View File

@@ -17,8 +17,7 @@ import {
CsrfToken,
EditContextInput,
ErrorResponse,
JobDefinition,
PollOptions
JobDefinition
} from './types'
import { formatDataForRequest } from './utils/formatDataForRequest'
import { SessionManager } from './SessionManager'
@@ -155,7 +154,6 @@ export class SASViyaApiClient {
context.name,
accessToken,
null,
false,
true,
true
).catch((err) => err)
@@ -166,27 +164,30 @@ export class SASViyaApiClient {
for (const promise of promises) results.push(await promise())
results.forEach((result: any, index: number) => {
if (result && result.log) {
if (result && result.error && result.error.details) {
try {
const resultParsed = result.log
let sysUserId = ''
const resultParsed = result.error.details
const sysUserIdLog = resultParsed
.split('\n')
.find((line: string) => line.startsWith('SYSUSERID='))
if (resultParsed && resultParsed.body) {
let sysUserId = ''
if (sysUserIdLog) {
sysUserId = sysUserIdLog.replace('SYSUSERID=', '')
const sysUserIdLog = resultParsed.body
.split('\n')
.find((line: string) => line.startsWith('SYSUSERID='))
executableContexts.push({
createdBy: contextsList[index].createdBy,
id: contextsList[index].id,
name: contextsList[index].name,
version: contextsList[index].version,
attributes: {
sysUserId
}
})
if (sysUserIdLog) {
sysUserId = sysUserIdLog.replace('SYSUSERID=', '')
executableContexts.push({
createdBy: contextsList[index].createdBy,
id: contextsList[index].id,
name: contextsList[index].name,
version: contextsList[index].version,
attributes: {
sysUserId
}
})
}
}
} catch (error) {
throw error
@@ -425,11 +426,10 @@ export class SASViyaApiClient {
* @param linesOfCode - an array of code lines to execute.
* @param contextName - the context to execute the code in.
* @param accessToken - an access token for an authorized user.
* @param sessionId - optional session ID to reuse.
* @param data - execution data.
* @param debug - when set to true, the log will be returned.
* @param expectWebout - when set to true, the automatic _webout fileref will be checked for content, and that content returned. This fileref is used when the Job contains a SASjs web request (as opposed to executing arbitrary SAS code).
* @param waitForResult - when set to true, function will return the session
* @param pollOptions - an object that represents poll interval(milliseconds) and maximum amount of attempts. Object example: { MAX_POLL_COUNT: 24 * 60 * 60, POLL_INTERVAL: 1000 }.
*/
public async executeScript(
jobPath: string,
@@ -437,10 +437,8 @@ export class SASViyaApiClient {
contextName: string,
accessToken?: string,
data = null,
debug: boolean = false,
expectWebout = false,
waitForResult = true,
pollOptions?: PollOptions
waitForResult = true
): Promise<any> {
try {
const headers: any = {
@@ -469,7 +467,7 @@ export class SASViyaApiClient {
_OMITTEXTLOG: true
}
if (debug) {
if (this.debug) {
jobArguments['_OMITTEXTLOG'] = false
jobArguments['_OMITSESSIONRESULTS'] = false
jobArguments['_DEBUG'] = 131
@@ -537,7 +535,7 @@ export class SASViyaApiClient {
return session
}
if (debug) {
if (this.debug) {
console.log(`Job has been submitted for '${fileName}'.`)
console.log(
`You can monitor the job progress at '${this.serverUrl}${
@@ -546,12 +544,7 @@ export class SASViyaApiClient {
)
}
const jobStatus = await this.pollJobState(
postedJob,
etag,
accessToken,
pollOptions
)
const jobStatus = await this.pollJobState(postedJob, etag, accessToken)
const { result: currentJob } = await this.request<Job>(
`${this.serverUrl}/compute/sessions/${executionSessionId}/jobs/${postedJob.id}`,
@@ -565,7 +558,7 @@ export class SASViyaApiClient {
const logLink = currentJob.links.find((l) => l.rel === 'log')
if (debug && logLink) {
if (this.debug && logLink) {
log = await this.request<any>(
`${this.serverUrl}${logLink.href}/content?limit=10000`,
{
@@ -581,7 +574,7 @@ export class SASViyaApiClient {
}
if (jobStatus === 'failed' || jobStatus === 'error') {
return Promise.reject({ job: currentJob, log })
return Promise.reject({ error: currentJob.error, log })
}
let resultLink
@@ -589,7 +582,7 @@ export class SASViyaApiClient {
if (expectWebout) {
resultLink = `/compute/sessions/${executionSessionId}/filerefs/_webout/content`
} else {
return { job: currentJob, log }
return currentJob
}
if (resultLink) {
@@ -613,10 +606,12 @@ export class SASViyaApiClient {
throw err
})
return Promise.reject({
status: 500,
log: log
})
return Promise.reject(
new ErrorResponse('Job execution failed.', {
status: 500,
body: log
})
)
}
}
return {
@@ -640,7 +635,6 @@ export class SASViyaApiClient {
contextName,
accessToken,
data,
debug,
false,
true
)
@@ -957,17 +951,14 @@ export class SASViyaApiClient {
* @param accessToken - an optional access token for an authorized user.
* @param waitForResult - a boolean indicating if the function should wait for a result.
* @param expectWebout - a boolean indicating whether to expect a _webout response.
* @param pollOptions - an object that represents poll interval(milliseconds) and maximum amount of attempts. Object example: { MAX_POLL_COUNT: 24 * 60 * 60, POLL_INTERVAL: 1000 }.
*/
public async executeComputeJob(
sasJob: string,
contextName: string,
debug?: boolean,
data?: any,
accessToken?: string,
waitForResult = true,
expectWebout = false,
pollOptions?: PollOptions
expectWebout = false
) {
if (isRelativePath(sasJob) && !this.rootFolderName) {
throw new Error(
@@ -1050,10 +1041,8 @@ export class SASViyaApiClient {
contextName,
accessToken,
data,
debug,
expectWebout,
waitForResult,
pollOptions
waitForResult
)
}
@@ -1238,7 +1227,7 @@ export class SASViyaApiClient {
throw new Error(`The path ${path} does not exist on ${this.serverUrl}`)
}
const { result: members } = await this.request<{ items: any[] }>(
`${this.serverUrl}/folders/folders/${folder.id}/members?limit=${folder.memberCount}`,
`${this.serverUrl}/folders/folders/${folder.id}/members`,
requestInfo
)
@@ -1246,21 +1235,13 @@ export class SASViyaApiClient {
this.folderMap.set(path, itemsAtRoot)
}
// REFACTOR: set default value for 'pollOptions' attribute
private async pollJobState(
postedJob: any,
etag: string | null,
accessToken?: string,
pollOptions?: PollOptions
accessToken?: string
) {
let POLL_INTERVAL = 100
let MAX_POLL_COUNT = 1000
if (pollOptions) {
POLL_INTERVAL = pollOptions.POLL_INTERVAL || POLL_INTERVAL
MAX_POLL_COUNT = pollOptions.MAX_POLL_COUNT || MAX_POLL_COUNT
}
const MAX_POLL_COUNT = 1000
const POLL_INTERVAL = 100
let postedJobState = ''
let pollCount = 0
const headers: any = {

View File

@@ -32,8 +32,7 @@ import {
CsrfToken,
UploadFile,
EditContextInput,
ErrorResponse,
PollOptions
ErrorResponse
} from './types'
import { SASViyaApiClient } from './SASViyaApiClient'
import { SAS9ApiClient } from './SAS9ApiClient'
@@ -206,20 +205,11 @@ export default class SASjs {
return await this.sasViyaApiClient!.createSession(contextName, accessToken)
}
/**
* Executes the sas code against given sas server
* @param fileName - name of the file to run. It will be converted to path to the file being submitted for execution.
* @param linesOfCode - lines of sas code from the file to run.
* @param contextName - context name on which code will be run on the server.
* @param accessToken - (optional) the access token for authorizing the request.
* @param debug - (optional) if true, global debug config will be overriden
*/
public async executeScriptSASViya(
fileName: string,
linesOfCode: string[],
contextName: string,
accessToken?: string,
debug?: boolean
accessToken?: string
) {
this.isMethodSupported('executeScriptSASViya', ServerType.SASViya)
@@ -228,8 +218,7 @@ export default class SASjs {
linesOfCode,
contextName,
accessToken,
null,
debug ? debug : this.sasjsConfig.debug
null
)
}
@@ -722,15 +711,13 @@ export default class SASjs {
* @param accessToken - a valid access token that is authorised to execute compute jobs.
* The access token is not required when the user is authenticated via the browser.
* @param waitForResult - a boolean that indicates whether the function needs to wait for execution to complete.
* @param pollOptions - an object that represents poll interval(milliseconds) and maximum amount of attempts. Object example: { MAX_POLL_COUNT: 24 * 60 * 60, POLL_INTERVAL: 1000 }.
*/
public async startComputeJob(
sasJob: string,
data: any,
config: any = {},
accessToken?: string,
waitForResult?: boolean,
pollOptions?: PollOptions
waitForResult?: boolean
) {
config = {
...this.sasjsConfig,
@@ -747,12 +734,10 @@ export default class SASjs {
return this.sasViyaApiClient?.executeComputeJob(
sasJob,
config.contextName,
config.debug,
data,
accessToken,
!!waitForResult,
false,
pollOptions
false
)
}
@@ -781,7 +766,6 @@ export default class SASjs {
?.executeComputeJob(
sasJob,
config.contextName,
config.debug,
data,
accessToken,
waitForResult,
@@ -911,8 +895,8 @@ export default class SASjs {
return responseJson
})
.catch(async (response) => {
if (needsRetry(JSON.stringify(response))) {
.catch(async (e) => {
if (needsRetry(JSON.stringify(e))) {
if (this.retryCountJeseApi < requestRetryLimit) {
let retryResponse = await this.executeJobViaJesApi(
sasJob,
@@ -933,11 +917,11 @@ export default class SASjs {
}
}
if (response?.log) {
this.appendSasjsRequest(response.log, sasJob, null)
if (e?.log) {
this.appendSasjsRequest(e.log, sasJob, null)
}
if (response.toString().includes('Job was not found')) {
if (e.toString().includes('Job was not found')) {
reject(
new ErrorResponse('Service not found on the server.', {
sasJob: sasJob
@@ -945,7 +929,7 @@ export default class SASjs {
)
}
reject(new ErrorResponse('Job execution failed.', response))
reject(new ErrorResponse('Job execution failed.', e))
})
)
}

View File

@@ -0,0 +1,38 @@
import dotenv from 'dotenv'
import { SessionManager } from '../SessionManager'
import { CsrfToken } from '../types'
describe('SessionManager', () => {
const setCsrfToken = jest
.fn()
.mockImplementation((csrfToken: CsrfToken) => console.log(csrfToken))
beforeAll(() => {
dotenv.config()
})
it('should instantiate', () => {
const sessionManager = new SessionManager(
'http://test-server.com',
'test context',
setCsrfToken
)
expect(sessionManager).toBeInstanceOf(SessionManager)
expect(sessionManager.debug).toBeFalsy()
expect((sessionManager as any).serverUrl).toEqual('http://test-server.com')
expect((sessionManager as any).contextName).toEqual('test context')
})
it('should set the debug flag', () => {
const sessionManager = new SessionManager(
'http://test-server.com',
'test context',
setCsrfToken
)
sessionManager.debug = true
expect(sessionManager.debug).toBeTruthy()
})
})

View File

@@ -4,5 +4,4 @@ export interface Folder {
id: string
uri: string
links: Link[]
memberCount: number
}

View File

@@ -1,4 +0,0 @@
export interface PollOptions {
MAX_POLL_COUNT?: number
POLL_INTERVAL?: number
}

View File

@@ -12,4 +12,3 @@ export * from './SASjsWaitingRequest'
export * from './ServerType'
export * from './Session'
export * from './UploadFile'
export * from './PollOptions'

View File

@@ -47,7 +47,6 @@ const browserConfig = {
const nodeConfig = {
...browserConfig,
target: 'node',
entry: './node/index.ts',
output: {
...browserConfig.output,
path: path.resolve(__dirname, 'build', 'node')