mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-07 20:40:05 +00:00
Compare commits
63 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa531b34fd | ||
|
|
354443c98b | ||
|
|
ee30ab195f | ||
|
|
02c1712d22 | ||
|
|
37def7a956 | ||
|
|
653e3d05e0 | ||
|
|
d8467c24b1 | ||
|
|
fc9056c1ac | ||
|
|
9b1d295b82 | ||
|
|
e2ea3f4ddc | ||
|
|
99d0b01a24 | ||
|
|
131c672020 | ||
|
|
338f2fb2dd | ||
|
|
4552a9a856 | ||
|
|
daeb753f9e | ||
|
|
f50a99d0b8 | ||
|
|
e6d0d3efd5 | ||
|
|
057460467c | ||
|
|
5aee9d955e | ||
|
|
7fb1da31e4 | ||
|
|
1aa92c0a69 | ||
|
|
4c097a69fd | ||
|
|
2634933e84 | ||
|
|
d60c0850c2 | ||
|
|
491bc3371c | ||
|
|
c1bab07b08 | ||
|
|
95f3ebd51d | ||
|
|
0e5b72b54f | ||
|
|
33ce592379 | ||
|
|
9f6591d7e3 | ||
|
|
5343ca00d8 | ||
|
|
f764f1f22f | ||
|
|
978af5037e | ||
|
|
39e88052c7 | ||
|
|
889351caf1 | ||
|
|
e6476dc230 | ||
|
|
e7de45c94f | ||
|
|
2f822aba71 | ||
|
|
ba687bf8e2 | ||
|
|
618cbe5a21 | ||
|
|
d723150b6d | ||
|
|
b1ad983ca5 | ||
|
|
4711d0510e | ||
|
|
93854c287f | ||
|
|
687a3047fd | ||
|
|
c067c6e74d | ||
|
|
04b44f40ba | ||
|
|
ce2126bd34 | ||
|
|
638efe8899 | ||
|
|
23353355e4 | ||
|
|
1be64798c5 | ||
|
|
a92a458cf1 | ||
|
|
703fdf9c02 | ||
|
|
bc239cf5d6 | ||
|
|
86780db478 | ||
|
|
5d5afa20c7 | ||
|
|
d662c1a981 | ||
|
|
f3abafd5ed | ||
|
|
5076ea696c | ||
|
|
3a60e6422c | ||
|
|
b90b5d5c03 | ||
|
|
d5a8140d4f | ||
|
|
5f5d84da87 |
17
PULL_REQUEST_TEMPLATE.md
Normal file
17
PULL_REQUEST_TEMPLATE.md
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
## Issue
|
||||||
|
|
||||||
|
Link any related issue(s) in this section.
|
||||||
|
|
||||||
|
## Intent
|
||||||
|
|
||||||
|
What this PR intends to achieve.
|
||||||
|
|
||||||
|
## Implementation
|
||||||
|
|
||||||
|
What code changes have been made to achieve the intent.
|
||||||
|
|
||||||
|
## Checks
|
||||||
|
|
||||||
|
- [ ] Code is formatted correctly (`npm run lint:fix`).
|
||||||
|
- [ ] All 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
231
docs/classes/reflection-725.reflection-191.fileuploader.html
Normal file
231
docs/classes/reflection-725.reflection-191.fileuploader.html
Normal file
File diff suppressed because one or more lines are too long
312
docs/classes/reflection-725.reflection-191.sas9apiclient.html
Normal file
312
docs/classes/reflection-725.reflection-191.sas9apiclient.html
Normal file
File diff suppressed because one or more lines are too long
1336
docs/classes/reflection-725.reflection-191.sasjs.html
Normal file
1336
docs/classes/reflection-725.reflection-191.sasjs.html
Normal file
File diff suppressed because one or more lines are too long
1267
docs/classes/reflection-725.reflection-191.sasviyaapiclient.html
Normal file
1267
docs/classes/reflection-725.reflection-191.sasviyaapiclient.html
Normal file
File diff suppressed because one or more lines are too long
271
docs/classes/reflection-725.reflection-191.sessionmanager.html
Normal file
271
docs/classes/reflection-725.reflection-191.sessionmanager.html
Normal file
File diff suppressed because one or more lines are too long
231
docs/classes/reflection-725.reflection-194.fileuploader.html
Normal file
231
docs/classes/reflection-725.reflection-194.fileuploader.html
Normal file
File diff suppressed because one or more lines are too long
312
docs/classes/reflection-725.reflection-194.sas9apiclient.html
Normal file
312
docs/classes/reflection-725.reflection-194.sas9apiclient.html
Normal file
File diff suppressed because one or more lines are too long
1336
docs/classes/reflection-725.reflection-194.sasjs.html
Normal file
1336
docs/classes/reflection-725.reflection-194.sasjs.html
Normal file
File diff suppressed because one or more lines are too long
1270
docs/classes/reflection-725.reflection-194.sasviyaapiclient.html
Normal file
1270
docs/classes/reflection-725.reflection-194.sasviyaapiclient.html
Normal file
File diff suppressed because one or more lines are too long
271
docs/classes/reflection-725.reflection-194.sessionmanager.html
Normal file
271
docs/classes/reflection-725.reflection-194.sessionmanager.html
Normal file
File diff suppressed because one or more lines are too long
231
docs/classes/reflection-734.reflection-194.fileuploader.html
Normal file
231
docs/classes/reflection-734.reflection-194.fileuploader.html
Normal file
File diff suppressed because one or more lines are too long
312
docs/classes/reflection-734.reflection-194.sas9apiclient.html
Normal file
312
docs/classes/reflection-734.reflection-194.sas9apiclient.html
Normal file
File diff suppressed because one or more lines are too long
1385
docs/classes/reflection-734.reflection-194.sasjs.html
Normal file
1385
docs/classes/reflection-734.reflection-194.sasjs.html
Normal file
File diff suppressed because one or more lines are too long
1350
docs/classes/reflection-734.reflection-194.sasviyaapiclient.html
Normal file
1350
docs/classes/reflection-734.reflection-194.sasviyaapiclient.html
Normal file
File diff suppressed because one or more lines are too long
271
docs/classes/reflection-734.reflection-194.sessionmanager.html
Normal file
271
docs/classes/reflection-734.reflection-194.sessionmanager.html
Normal file
File diff suppressed because one or more lines are too long
231
docs/classes/reflection-743.reflection-195.fileuploader.html
Normal file
231
docs/classes/reflection-743.reflection-195.fileuploader.html
Normal file
File diff suppressed because one or more lines are too long
312
docs/classes/reflection-743.reflection-195.sas9apiclient.html
Normal file
312
docs/classes/reflection-743.reflection-195.sas9apiclient.html
Normal file
File diff suppressed because one or more lines are too long
1419
docs/classes/reflection-743.reflection-195.sasjs.html
Normal file
1419
docs/classes/reflection-743.reflection-195.sasjs.html
Normal file
File diff suppressed because one or more lines are too long
1415
docs/classes/reflection-743.reflection-195.sasviyaapiclient.html
Normal file
1415
docs/classes/reflection-743.reflection-195.sasviyaapiclient.html
Normal file
File diff suppressed because one or more lines are too long
271
docs/classes/reflection-743.reflection-195.sessionmanager.html
Normal file
271
docs/classes/reflection-743.reflection-195.sessionmanager.html
Normal file
File diff suppressed because one or more lines are too long
231
docs/classes/reflection-759.reflection-211.fileuploader.html
Normal file
231
docs/classes/reflection-759.reflection-211.fileuploader.html
Normal file
File diff suppressed because one or more lines are too long
312
docs/classes/reflection-759.reflection-211.sas9apiclient.html
Normal file
312
docs/classes/reflection-759.reflection-211.sas9apiclient.html
Normal file
File diff suppressed because one or more lines are too long
1430
docs/classes/reflection-759.reflection-211.sasjs.html
Normal file
1430
docs/classes/reflection-759.reflection-211.sasjs.html
Normal file
File diff suppressed because one or more lines are too long
1395
docs/classes/reflection-759.reflection-211.sasviyaapiclient.html
Normal file
1395
docs/classes/reflection-759.reflection-211.sasviyaapiclient.html
Normal file
File diff suppressed because one or more lines are too long
271
docs/classes/reflection-759.reflection-211.sessionmanager.html
Normal file
271
docs/classes/reflection-759.reflection-211.sessionmanager.html
Normal file
File diff suppressed because one or more lines are too long
231
docs/classes/reflection-762.reflection-214.fileuploader.html
Normal file
231
docs/classes/reflection-762.reflection-214.fileuploader.html
Normal file
File diff suppressed because one or more lines are too long
312
docs/classes/reflection-762.reflection-214.sas9apiclient.html
Normal file
312
docs/classes/reflection-762.reflection-214.sas9apiclient.html
Normal file
File diff suppressed because one or more lines are too long
1430
docs/classes/reflection-762.reflection-214.sasjs.html
Normal file
1430
docs/classes/reflection-762.reflection-214.sasjs.html
Normal file
File diff suppressed because one or more lines are too long
1395
docs/classes/reflection-762.reflection-214.sasviyaapiclient.html
Normal file
1395
docs/classes/reflection-762.reflection-214.sasviyaapiclient.html
Normal file
File diff suppressed because one or more lines are too long
271
docs/classes/reflection-762.reflection-214.sessionmanager.html
Normal file
271
docs/classes/reflection-762.reflection-214.sessionmanager.html
Normal file
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
398
docs/interfaces/types.contextallattributes.html
Normal file
398
docs/interfaces/types.contextallattributes.html
Normal file
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
106
docs/modules/reflection-725.html
Normal file
106
docs/modules/reflection-725.html
Normal file
File diff suppressed because one or more lines are too long
128
docs/modules/reflection-725.reflection-191.html
Normal file
128
docs/modules/reflection-725.reflection-191.html
Normal file
File diff suppressed because one or more lines are too long
128
docs/modules/reflection-725.reflection-194.html
Normal file
128
docs/modules/reflection-725.reflection-194.html
Normal file
File diff suppressed because one or more lines are too long
106
docs/modules/reflection-734.html
Normal file
106
docs/modules/reflection-734.html
Normal file
File diff suppressed because one or more lines are too long
128
docs/modules/reflection-734.reflection-194.html
Normal file
128
docs/modules/reflection-734.reflection-194.html
Normal file
File diff suppressed because one or more lines are too long
106
docs/modules/reflection-743.html
Normal file
106
docs/modules/reflection-743.html
Normal file
File diff suppressed because one or more lines are too long
128
docs/modules/reflection-743.reflection-195.html
Normal file
128
docs/modules/reflection-743.reflection-195.html
Normal file
File diff suppressed because one or more lines are too long
106
docs/modules/reflection-759.html
Normal file
106
docs/modules/reflection-759.html
Normal file
File diff suppressed because one or more lines are too long
128
docs/modules/reflection-759.reflection-211.html
Normal file
128
docs/modules/reflection-759.reflection-211.html
Normal file
File diff suppressed because one or more lines are too long
106
docs/modules/reflection-762.html
Normal file
106
docs/modules/reflection-762.html
Normal file
File diff suppressed because one or more lines are too long
128
docs/modules/reflection-762.reflection-214.html
Normal file
128
docs/modules/reflection-762.reflection-214.html
Normal file
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
@@ -30,8 +30,8 @@
|
|||||||
$('#chart-container').append('<canvas id="myChart" style="display: none;"></canvas>')
|
$('#chart-container').append('<canvas id="myChart" style="display: none;"></canvas>')
|
||||||
// make a request to a SAS service
|
// make a request to a SAS service
|
||||||
var type = $("#cars")[0].options[$("#cars")[0].selectedIndex].value;
|
var type = $("#cars")[0].options[$("#cars")[0].selectedIndex].value;
|
||||||
// request data from an endpoint under your appLoc
|
// request data from an endpoint under your appLoc (missing opening slash implies relative path)
|
||||||
sasJs.request("/common/getdata", {
|
sasJs.request("common/getdata", {
|
||||||
// send data as an array of objects - each object is one row
|
// send data as an array of objects - each object is one row
|
||||||
fromjs: [{ type: type }]
|
fromjs: [{ type: type }]
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
|
|||||||
2264
package-lock.json
generated
2264
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
@@ -37,28 +37,28 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/isomorphic-fetch": "0.0.35",
|
"@types/isomorphic-fetch": "0.0.35",
|
||||||
"@types/jest": "^26.0.13",
|
"@types/jest": "^26.0.14",
|
||||||
"cp": "^0.2.0",
|
"cp": "^0.2.0",
|
||||||
"jest": "^25.5.4",
|
"jest": "^25.5.4",
|
||||||
"path": "^0.12.7",
|
"path": "^0.12.7",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"semantic-release": "^17.1.1",
|
"semantic-release": "^17.1.2",
|
||||||
|
"terser-webpack-plugin": "^4.2.2",
|
||||||
"ts-jest": "^25.5.1",
|
"ts-jest": "^25.5.1",
|
||||||
"ts-loader": "^8.0.3",
|
"ts-loader": "^8.0.4",
|
||||||
"tslint": "^6.1.3",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.18.0",
|
"tslint-config-prettier": "^1.18.0",
|
||||||
"typedoc": "^0.17.8",
|
"typedoc": "^0.17.8",
|
||||||
"typedoc-neo-theme": "^1.0.10",
|
"typedoc-neo-theme": "^1.0.10",
|
||||||
"typedoc-plugin-external-module-name": "^4.0.3",
|
"typedoc-plugin-external-module-name": "^4.0.3",
|
||||||
"typescript": "^3.9.7",
|
"typescript": "^3.9.7",
|
||||||
"uglifyjs-webpack-plugin": "^2.2.0",
|
"webpack": "^4.44.2",
|
||||||
"webpack": "^4.44.1",
|
|
||||||
"webpack-cli": "^3.3.12"
|
"webpack-cli": "^3.3.12"
|
||||||
},
|
},
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"es6-promise": "^4.2.8",
|
"es6-promise": "^4.2.8",
|
||||||
"form-data": "^3.0.0",
|
"form-data": "^3.0.0",
|
||||||
"isomorphic-fetch": "^2.2.1"
|
"isomorphic-fetch": "^3.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
6
sasjs-tests/package-lock.json
generated
6
sasjs-tests/package-lock.json
generated
@@ -1357,9 +1357,9 @@
|
|||||||
"integrity": "sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw=="
|
"integrity": "sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw=="
|
||||||
},
|
},
|
||||||
"@sasjs/adapter": {
|
"@sasjs/adapter": {
|
||||||
"version": "1.3.13",
|
"version": "1.12.0",
|
||||||
"resolved": "https://registry.npmjs.org/@sasjs/adapter/-/adapter-1.3.13.tgz",
|
"resolved": "https://registry.npmjs.org/@sasjs/adapter/-/adapter-1.12.0.tgz",
|
||||||
"integrity": "sha512-dWcDxgY3FB7Yx1I5dPpeQeyJDu4lezhIFrjn6lbdwRhV15aqOt4l9o9qZP+VbgOXqyi9gN0Y+p+vs2chBDFQqg==",
|
"integrity": "sha512-0uGQH9ynomWzdBaEujEtcR38q6V7LCgG0mrb1Wellv6cC/IHD3j6WfeZZAgtiMPeOSJjbCDBOlVnzC2TlBqJFw==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"es6-promise": "^4.2.8",
|
"es6-promise": "^4.2.8",
|
||||||
"form-data": "^3.0.0",
|
"form-data": "^3.0.0",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"homepage": ".",
|
"homepage": ".",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sasjs/adapter": "^1.3.13",
|
"@sasjs/adapter": "^1.12.0",
|
||||||
"@sasjs/test-framework": "^1.4.0",
|
"@sasjs/test-framework": "^1.4.0",
|
||||||
"@testing-library/jest-dom": "^4.2.4",
|
"@testing-library/jest-dom": "^4.2.4",
|
||||||
"@testing-library/react": "^9.5.0",
|
"@testing-library/react": "^9.5.0",
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ const defaultConfig: SASjsConfig = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const customConfig = {
|
const customConfig = {
|
||||||
serverUrl: "url",
|
serverUrl: "http://url.com",
|
||||||
pathSAS9: "sas9",
|
pathSAS9: "sas9",
|
||||||
pathSASViya: "viya",
|
pathSASViya: "viya",
|
||||||
appLoc: "/Public/seedapp",
|
appLoc: "/Public/seedapp",
|
||||||
|
|||||||
@@ -47,6 +47,16 @@ const getLargeObjectData = () => {
|
|||||||
export const sendArrTests = (adapter: SASjs): TestSuite => ({
|
export const sendArrTests = (adapter: SASjs): TestSuite => ({
|
||||||
name: "sendArr",
|
name: "sendArr",
|
||||||
tests: [
|
tests: [
|
||||||
|
{
|
||||||
|
title: "Absolute paths",
|
||||||
|
description: "Should work with absolute paths to SAS jobs",
|
||||||
|
test: () => {
|
||||||
|
return adapter.request("/Public/app/common/sendArr", stringData);
|
||||||
|
},
|
||||||
|
assertion: (res: any) => {
|
||||||
|
return res.table1[0][0] === stringData.table1[0].col1;
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: "Single string value",
|
title: "Single string value",
|
||||||
description: "Should send an array with a single string value",
|
description: "Should send an array with a single string value",
|
||||||
@@ -78,7 +88,7 @@ export const sendArrTests = (adapter: SASjs): TestSuite => ({
|
|||||||
return adapter.request("common/sendArr", data).catch((e) => e);
|
return adapter.request("common/sendArr", data).catch((e) => e);
|
||||||
},
|
},
|
||||||
assertion: (error: any) => {
|
assertion: (error: any) => {
|
||||||
return !!error && !!error.MESSAGE;
|
return !!error && !!error.body && !!error.body.message;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -175,7 +185,7 @@ export const sendObjTests = (adapter: SASjs): TestSuite => ({
|
|||||||
};
|
};
|
||||||
return adapter.request("common/sendObj", invalidData).catch((e) => e);
|
return adapter.request("common/sendObj", invalidData).catch((e) => e);
|
||||||
},
|
},
|
||||||
assertion: (error: any) => !!error && !!error.MESSAGE
|
assertion: (error: any) => !!error && !!error.body && !!error.body.message
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Single string value",
|
title: "Single string value",
|
||||||
@@ -209,7 +219,7 @@ export const sendObjTests = (adapter: SASjs): TestSuite => ({
|
|||||||
.catch((e) => e);
|
.catch((e) => e);
|
||||||
},
|
},
|
||||||
assertion: (error: any) => {
|
assertion: (error: any) => {
|
||||||
return !!error && !!error.MESSAGE;
|
return !!error && !!error.body && !!error.body.message;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,20 +3,22 @@ import {
|
|||||||
parseAndSubmitAuthorizeForm,
|
parseAndSubmitAuthorizeForm,
|
||||||
convertToCSV,
|
convertToCSV,
|
||||||
makeRequest,
|
makeRequest,
|
||||||
|
isRelativePath,
|
||||||
isUri,
|
isUri,
|
||||||
isUrl
|
isUrl
|
||||||
} from './utils'
|
} from './utils'
|
||||||
import * as NodeFormData from 'form-data'
|
import * as NodeFormData from 'form-data'
|
||||||
import * as path from 'path'
|
|
||||||
import {
|
import {
|
||||||
Job,
|
Job,
|
||||||
Session,
|
Session,
|
||||||
Context,
|
Context,
|
||||||
|
ContextAllAttributes,
|
||||||
Folder,
|
Folder,
|
||||||
CsrfToken,
|
CsrfToken,
|
||||||
EditContextInput
|
EditContextInput,
|
||||||
|
ErrorResponse,
|
||||||
|
JobDefinition
|
||||||
} from './types'
|
} from './types'
|
||||||
import { JobDefinition } from './types/JobDefinition'
|
|
||||||
import { formatDataForRequest } from './utils/formatDataForRequest'
|
import { formatDataForRequest } from './utils/formatDataForRequest'
|
||||||
import { SessionManager } from './SessionManager'
|
import { SessionManager } from './SessionManager'
|
||||||
|
|
||||||
@@ -29,35 +31,43 @@ export class SASViyaApiClient {
|
|||||||
private serverUrl: string,
|
private serverUrl: string,
|
||||||
private rootFolderName: string,
|
private rootFolderName: string,
|
||||||
private contextName: string,
|
private contextName: string,
|
||||||
private setCsrfToken: (csrfToken: CsrfToken) => void,
|
private setCsrfToken: (csrfToken: CsrfToken) => void
|
||||||
private rootFolderMap = new Map<string, Job[]>()
|
|
||||||
) {
|
) {
|
||||||
if (!rootFolderName) {
|
|
||||||
throw new Error('Root folder must be provided.')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (serverUrl) isUrl(serverUrl)
|
if (serverUrl) isUrl(serverUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
private csrfToken: CsrfToken | null = null
|
private csrfToken: CsrfToken | null = null
|
||||||
private rootFolder: Folder | null = null
|
private fileUploadCsrfToken: CsrfToken | null = null
|
||||||
|
private _debug = false
|
||||||
private sessionManager = new SessionManager(
|
private sessionManager = new SessionManager(
|
||||||
this.serverUrl,
|
this.serverUrl,
|
||||||
this.contextName,
|
this.contextName,
|
||||||
this.setCsrfToken
|
this.setCsrfToken
|
||||||
)
|
)
|
||||||
private isForceDeploy: boolean = false
|
private folderMap = new Map<string, Job[]>()
|
||||||
|
|
||||||
/**
|
public get debug() {
|
||||||
* Returns a map containing the directory structure in the currently set root folder.
|
return this._debug
|
||||||
*/
|
|
||||||
public async getAppLocMap() {
|
|
||||||
if (this.rootFolderMap.size) {
|
|
||||||
return this.rootFolderMap
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.populateRootFolderMap()
|
public set debug(value: boolean) {
|
||||||
return this.rootFolderMap
|
this._debug = value
|
||||||
|
this.sessionManager.debug = value
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of jobs in the currently set root folder.
|
||||||
|
*/
|
||||||
|
public async getJobsInFolder(folderPath: string) {
|
||||||
|
const path = isRelativePath(folderPath)
|
||||||
|
? `${this.rootFolderName}/${folderPath}`
|
||||||
|
: folderPath
|
||||||
|
if (this.folderMap.get(path)) {
|
||||||
|
return this.folderMap.get(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.populateFolderMap(path)
|
||||||
|
return this.folderMap.get(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -140,7 +150,6 @@ export class SASViyaApiClient {
|
|||||||
linesOfCode,
|
linesOfCode,
|
||||||
context.name,
|
context.name,
|
||||||
accessToken,
|
accessToken,
|
||||||
false,
|
|
||||||
null,
|
null,
|
||||||
true
|
true
|
||||||
).catch(() => null)
|
).catch(() => null)
|
||||||
@@ -192,7 +201,7 @@ export class SASViyaApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { result: contexts } = await this.request<{ items: Context[] }>(
|
const { result: contexts } = await this.request<{ items: Context[] }>(
|
||||||
`${this.serverUrl}/compute/contexts`,
|
`${this.serverUrl}/compute/contexts?limit=10000`,
|
||||||
{ headers }
|
{ headers }
|
||||||
)
|
)
|
||||||
const executionContext =
|
const executionContext =
|
||||||
@@ -224,16 +233,16 @@ export class SASViyaApiClient {
|
|||||||
* @param launchContextName - the name of the launcher context used by the compute service.
|
* @param launchContextName - the name of the launcher context used by the compute service.
|
||||||
* @param sharedAccountId - the ID of the account to run the servers for this context.
|
* @param sharedAccountId - the ID of the account to run the servers for this context.
|
||||||
* @param autoExecLines - the lines of code to execute during session initialization.
|
* @param autoExecLines - the lines of code to execute during session initialization.
|
||||||
* @param authorizedUsers - an optional list of authorized user IDs.
|
|
||||||
* @param accessToken - an access token for an authorized user.
|
* @param accessToken - an access token for an authorized user.
|
||||||
|
* @param authorizedUsers - an optional list of authorized user IDs.
|
||||||
*/
|
*/
|
||||||
public async createContext(
|
public async createContext(
|
||||||
contextName: string,
|
contextName: string,
|
||||||
launchContextName: string,
|
launchContextName: string,
|
||||||
sharedAccountId: string,
|
sharedAccountId: string,
|
||||||
autoExecLines: string[],
|
autoExecLines: string[],
|
||||||
authorizedUsers: string[],
|
accessToken?: string,
|
||||||
accessToken?: string
|
authorizedUsers?: string[]
|
||||||
) {
|
) {
|
||||||
if (!contextName) {
|
if (!contextName) {
|
||||||
throw new Error('Context name is required.')
|
throw new Error('Context name is required.')
|
||||||
@@ -313,10 +322,22 @@ export class SASViyaApiClient {
|
|||||||
headers.Authorization = `Bearer ${accessToken}`
|
headers.Authorization = `Bearer ${accessToken}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const originalContext = await this.getContextByName(
|
let originalContext
|
||||||
|
|
||||||
|
originalContext = await this.getComputeContextByName(
|
||||||
contextName,
|
contextName,
|
||||||
accessToken
|
accessToken
|
||||||
)
|
).catch((_) => {})
|
||||||
|
|
||||||
|
// Try to find context by id, when context name has been changed.
|
||||||
|
if (!originalContext) {
|
||||||
|
originalContext = await this.getComputeContextById(
|
||||||
|
editedContext.id!,
|
||||||
|
accessToken
|
||||||
|
).catch((err) => {
|
||||||
|
throw err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const { result: context, etag } = await this.request<Context>(
|
const { result: context, etag } = await this.request<Context>(
|
||||||
`${this.serverUrl}/compute/contexts/${originalContext.id}`,
|
`${this.serverUrl}/compute/contexts/${originalContext.id}`,
|
||||||
@@ -372,7 +393,7 @@ export class SASViyaApiClient {
|
|||||||
headers.Authorization = `Bearer ${accessToken}`
|
headers.Authorization = `Bearer ${accessToken}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const context = await this.getContextByName(contextName, accessToken)
|
const context = await this.getComputeContextByName(contextName, accessToken)
|
||||||
|
|
||||||
const deleteContextRequest: RequestInit = {
|
const deleteContextRequest: RequestInit = {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
@@ -387,27 +408,23 @@ export class SASViyaApiClient {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes code on the current SAS Viya server.
|
* Executes code on the current SAS Viya server.
|
||||||
* @param fileName - a name for the file being submitted for execution.
|
* @param jobPath - the path to the file being submitted for execution.
|
||||||
* @param linesOfCode - an array of code lines to execute.
|
* @param linesOfCode - an array of code lines to execute.
|
||||||
* @param contextName - the context to execute the code in.
|
* @param contextName - the context to execute the code in.
|
||||||
* @param accessToken - an access token for an authorized user.
|
* @param accessToken - an access token for an authorized user.
|
||||||
* @param sessionId - optional session ID to reuse.
|
* @param sessionId - optional session ID to reuse.
|
||||||
* @param silent - optional flag to disable logging.
|
|
||||||
* @param data - execution data.
|
* @param data - execution data.
|
||||||
* @param debug - when set to true, the log will be returned.
|
* @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 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).
|
||||||
*/
|
*/
|
||||||
public async executeScript(
|
public async executeScript(
|
||||||
jobName: string,
|
jobPath: string,
|
||||||
linesOfCode: string[],
|
linesOfCode: string[],
|
||||||
contextName: string,
|
contextName: string,
|
||||||
accessToken?: string,
|
accessToken?: string,
|
||||||
silent = false,
|
|
||||||
data = null,
|
data = null,
|
||||||
debug = false,
|
|
||||||
expectWebout = false
|
expectWebout = false
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
silent = !debug
|
|
||||||
try {
|
try {
|
||||||
const headers: any = {
|
const headers: any = {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
@@ -430,19 +447,27 @@ export class SASViyaApiClient {
|
|||||||
_OMITTEXTLOG: true
|
_OMITTEXTLOG: true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug) {
|
if (this.debug) {
|
||||||
jobArguments['_OMITTEXTLOG'] = false
|
jobArguments['_OMITTEXTLOG'] = false
|
||||||
jobArguments['_OMITSESSIONRESULTS'] = false
|
jobArguments['_OMITSESSIONRESULTS'] = false
|
||||||
jobArguments['_DEBUG'] = 131
|
jobArguments['_DEBUG'] = 131
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileName = `exec-${
|
let fileName
|
||||||
jobName.includes('/') ? jobName.split('/')[1] : jobName
|
if (isRelativePath(jobPath)) {
|
||||||
|
fileName = `exec-${
|
||||||
|
jobPath.includes('/') ? jobPath.split('/')[1] : jobPath
|
||||||
}`
|
}`
|
||||||
|
} else {
|
||||||
|
const jobPathParts = jobPath.split('/')
|
||||||
|
fileName = jobPathParts.pop()
|
||||||
|
}
|
||||||
|
|
||||||
let jobVariables: any = {
|
let jobVariables: any = {
|
||||||
SYS_JES_JOB_URI: '',
|
SYS_JES_JOB_URI: '',
|
||||||
_program: this.rootFolderName + '/' + jobName
|
_program: isRelativePath(jobPath)
|
||||||
|
? this.rootFolderName + '/' + jobPath
|
||||||
|
: jobPath
|
||||||
}
|
}
|
||||||
|
|
||||||
let files: any[] = []
|
let files: any[] = []
|
||||||
@@ -482,7 +507,7 @@ export class SASViyaApiClient {
|
|||||||
postJobRequest
|
postJobRequest
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!silent) {
|
if (this.debug) {
|
||||||
console.log(`Job has been submitted for '${fileName}'.`)
|
console.log(`Job has been submitted for '${fileName}'.`)
|
||||||
console.log(
|
console.log(
|
||||||
`You can monitor the job progress at '${this.serverUrl}${
|
`You can monitor the job progress at '${this.serverUrl}${
|
||||||
@@ -491,12 +516,7 @@ export class SASViyaApiClient {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const jobStatus = await this.pollJobState(
|
const jobStatus = await this.pollJobState(postedJob, etag, accessToken)
|
||||||
postedJob,
|
|
||||||
etag,
|
|
||||||
accessToken,
|
|
||||||
silent
|
|
||||||
)
|
|
||||||
|
|
||||||
const { result: currentJob } = await this.request<Job>(
|
const { result: currentJob } = await this.request<Job>(
|
||||||
`${this.serverUrl}/compute/sessions/${executionSessionId}/jobs/${postedJob.id}`,
|
`${this.serverUrl}/compute/sessions/${executionSessionId}/jobs/${postedJob.id}`,
|
||||||
@@ -508,7 +528,7 @@ export class SASViyaApiClient {
|
|||||||
|
|
||||||
const logLink = currentJob.links.find((l) => l.rel === 'log')
|
const logLink = currentJob.links.find((l) => l.rel === 'log')
|
||||||
|
|
||||||
if (debug && logLink) {
|
if (this.debug && logLink) {
|
||||||
log = await this.request<any>(
|
log = await this.request<any>(
|
||||||
`${this.serverUrl}${logLink.href}/content?limit=10000`,
|
`${this.serverUrl}${logLink.href}/content?limit=10000`,
|
||||||
{
|
{
|
||||||
@@ -534,9 +554,30 @@ export class SASViyaApiClient {
|
|||||||
`${this.serverUrl}${resultLink}`,
|
`${this.serverUrl}${resultLink}`,
|
||||||
{ headers },
|
{ headers },
|
||||||
'text'
|
'text'
|
||||||
).catch((e) => ({
|
).catch(async (e) => {
|
||||||
|
if (e && e.status === 404) {
|
||||||
|
if (logLink) {
|
||||||
|
log = await this.request<any>(
|
||||||
|
`${this.serverUrl}${logLink.href}/content?limit=10000`,
|
||||||
|
{
|
||||||
|
headers
|
||||||
|
}
|
||||||
|
).then((res: any) =>
|
||||||
|
res.result.items.map((i: any) => i.line).join('\n')
|
||||||
|
)
|
||||||
|
|
||||||
|
return Promise.reject(
|
||||||
|
new ErrorResponse('Job execution failed', {
|
||||||
|
status: 500,
|
||||||
|
body: log
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
result: JSON.stringify(e)
|
result: JSON.stringify(e)
|
||||||
}))
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.sessionManager.clearSession(executionSessionId, accessToken)
|
await this.sessionManager.clearSession(executionSessionId, accessToken)
|
||||||
@@ -545,13 +586,11 @@ export class SASViyaApiClient {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e && e.status === 404) {
|
if (e && e.status === 404) {
|
||||||
return this.executeScript(
|
return this.executeScript(
|
||||||
jobName,
|
jobPath,
|
||||||
linesOfCode,
|
linesOfCode,
|
||||||
contextName,
|
contextName,
|
||||||
accessToken,
|
accessToken,
|
||||||
silent,
|
data
|
||||||
data,
|
|
||||||
debug
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
throw e
|
throw e
|
||||||
@@ -583,8 +622,6 @@ export class SASViyaApiClient {
|
|||||||
if (!parentFolderUri && parentFolderPath) {
|
if (!parentFolderUri && parentFolderPath) {
|
||||||
parentFolderUri = await this.getFolderUri(parentFolderPath, accessToken)
|
parentFolderUri = await this.getFolderUri(parentFolderPath, accessToken)
|
||||||
if (!parentFolderUri) {
|
if (!parentFolderUri) {
|
||||||
if (isForced) this.isForceDeploy = true
|
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`Parent folder at path '${parentFolderPath}' is not present.`
|
`Parent folder at path '${parentFolderPath}' is not present.`
|
||||||
)
|
)
|
||||||
@@ -610,37 +647,16 @@ export class SASViyaApiClient {
|
|||||||
`Parent folder '${newFolderName}' has been successfully created.`
|
`Parent folder '${newFolderName}' has been successfully created.`
|
||||||
)
|
)
|
||||||
parentFolderUri = `/folders/folders/${parentFolder.id}`
|
parentFolderUri = `/folders/folders/${parentFolder.id}`
|
||||||
} else if (isForced && accessToken && !this.isForceDeploy) {
|
} else if (isForced && accessToken) {
|
||||||
this.isForceDeploy = true
|
const folderPath = parentFolderPath + '/' + folderName
|
||||||
|
const folderUri = await this.getFolderUri(folderPath, accessToken)
|
||||||
|
|
||||||
await this.deleteFolder(parentFolderPath, accessToken)
|
if (folderUri) {
|
||||||
|
await this.deleteFolder(
|
||||||
const newParentFolderPath = parentFolderPath.substring(
|
parentFolderPath + '/' + folderName,
|
||||||
0,
|
|
||||||
parentFolderPath.lastIndexOf('/')
|
|
||||||
)
|
|
||||||
const newFolderName = `${parentFolderPath.split('/').pop()}`
|
|
||||||
|
|
||||||
if (newParentFolderPath === '') {
|
|
||||||
throw new Error(`Root folder has to be present on the server.`)
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
`Creating parent folder:\n'${newFolderName}' in '${newParentFolderPath}'`
|
|
||||||
)
|
|
||||||
|
|
||||||
const parentFolder = await this.createFolder(
|
|
||||||
newFolderName,
|
|
||||||
newParentFolderPath,
|
|
||||||
undefined,
|
|
||||||
accessToken
|
accessToken
|
||||||
)
|
)
|
||||||
|
}
|
||||||
console.log(
|
|
||||||
`Parent folder '${newFolderName}' has been successfully created.`
|
|
||||||
)
|
|
||||||
|
|
||||||
parentFolderUri = `/folders/folders/${parentFolder.id}`
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -662,8 +678,11 @@ export class SASViyaApiClient {
|
|||||||
createFolderRequest
|
createFolderRequest
|
||||||
)
|
)
|
||||||
|
|
||||||
// updates rootFolderMap with newly created folder.
|
// update folder map with newly created folder.
|
||||||
await this.populateRootFolderMap(accessToken)
|
await this.populateFolderMap(
|
||||||
|
`${parentFolderPath}/${folderName}`,
|
||||||
|
accessToken
|
||||||
|
)
|
||||||
return createFolderResponse
|
return createFolderResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -892,30 +911,51 @@ export class SASViyaApiClient {
|
|||||||
data?: any,
|
data?: any,
|
||||||
accessToken?: string
|
accessToken?: string
|
||||||
) {
|
) {
|
||||||
if (!this.rootFolder) {
|
if (isRelativePath(sasJob) && !this.rootFolderName) {
|
||||||
await this.populateRootFolder(accessToken)
|
|
||||||
}
|
|
||||||
if (!this.rootFolder) {
|
|
||||||
throw new Error(`Root folder was not found.`)
|
|
||||||
}
|
|
||||||
if (!this.rootFolderMap.size) {
|
|
||||||
await this.populateRootFolderMap(accessToken)
|
|
||||||
}
|
|
||||||
if (!this.rootFolderMap.size) {
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`The job '${sasJob}' was not found in '${this.rootFolderName}'.`
|
'Relative paths cannot be used without specifying a root folder name'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isRelativePath(sasJob)) {
|
||||||
|
const folderName = sasJob.split('/')[0]
|
||||||
|
await this.populateFolderMap(
|
||||||
|
`${this.rootFolderName}/${folderName}`,
|
||||||
|
accessToken
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!this.folderMap.get(`${this.rootFolderName}/${folderName}`)) {
|
||||||
|
throw new Error(
|
||||||
|
`The folder '${folderName}' was not found at '${this.serverUrl}/${this.rootFolderName}'`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const folderPathParts = sasJob.split('/')
|
||||||
|
folderPathParts.pop()
|
||||||
|
const folderPath = folderPathParts.join('/')
|
||||||
|
await this.populateFolderMap(folderPath, accessToken)
|
||||||
|
}
|
||||||
|
|
||||||
const headers: any = { 'Content-Type': 'application/json' }
|
const headers: any = { 'Content-Type': 'application/json' }
|
||||||
if (!!accessToken) {
|
if (!!accessToken) {
|
||||||
headers.Authorization = `Bearer ${accessToken}`
|
headers.Authorization = `Bearer ${accessToken}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let jobToExecute
|
||||||
|
if (isRelativePath(sasJob)) {
|
||||||
const folderName = sasJob.split('/')[0]
|
const folderName = sasJob.split('/')[0]
|
||||||
const jobName = sasJob.split('/')[1]
|
const jobName = sasJob.split('/')[1]
|
||||||
const jobFolder = this.rootFolderMap.get(folderName)
|
const jobFolder = this.folderMap.get(
|
||||||
const jobToExecute = jobFolder?.find((item) => item.name === jobName)
|
`${this.rootFolderName}/${folderName}`
|
||||||
|
)
|
||||||
|
jobToExecute = jobFolder?.find((item) => item.name === jobName)
|
||||||
|
} else {
|
||||||
|
const folderPathParts = sasJob.split('/')
|
||||||
|
const jobName = folderPathParts.pop()
|
||||||
|
const folderPath = folderPathParts.join('/')
|
||||||
|
const jobFolder = this.folderMap.get(folderPath)
|
||||||
|
jobToExecute = jobFolder?.find((item) => item.name === jobName)
|
||||||
|
}
|
||||||
|
|
||||||
if (!jobToExecute) {
|
if (!jobToExecute) {
|
||||||
throw new Error(`Job was not found.`)
|
throw new Error(`Job was not found.`)
|
||||||
@@ -949,16 +989,14 @@ export class SASViyaApiClient {
|
|||||||
linesToExecute,
|
linesToExecute,
|
||||||
contextName,
|
contextName,
|
||||||
accessToken,
|
accessToken,
|
||||||
true,
|
|
||||||
data,
|
data,
|
||||||
debug,
|
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes a job via the SAS Viya Job Execution API.
|
* Executes a job via the SAS Viya Job Execution API
|
||||||
* @param sasJob - the relative path to the job.
|
* @param sasJob - the relative or absolute path to the job.
|
||||||
* @param contextName - the name of the context where the job is to be executed.
|
* @param contextName - the name of the context where the job is to be executed.
|
||||||
* @param debug - sets the _debug flag in the job arguments.
|
* @param debug - sets the _debug flag in the job arguments.
|
||||||
* @param data - any data to be passed in as input to the job.
|
* @param data - any data to be passed in as input to the job.
|
||||||
@@ -971,20 +1009,34 @@ export class SASViyaApiClient {
|
|||||||
data?: any,
|
data?: any,
|
||||||
accessToken?: string
|
accessToken?: string
|
||||||
) {
|
) {
|
||||||
if (!this.rootFolder) {
|
if (isRelativePath(sasJob) && !this.rootFolderName) {
|
||||||
await this.populateRootFolder(accessToken)
|
throw new Error(
|
||||||
|
'Relative paths cannot be used without specifying a root folder name.'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.rootFolder) {
|
if (isRelativePath(sasJob)) {
|
||||||
throw new Error(`Root folder was not found.`)
|
const folderName = sasJob.split('/')[0]
|
||||||
}
|
await this.populateFolderMap(
|
||||||
if (!this.rootFolderMap.size) {
|
`${this.rootFolderName}/${folderName}`,
|
||||||
await this.populateRootFolderMap(accessToken)
|
accessToken
|
||||||
}
|
|
||||||
if (!this.rootFolderMap.size) {
|
|
||||||
throw new Error(
|
|
||||||
`The job '${sasJob}' was not found in folder '${this.rootFolderName}'.`
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (!this.folderMap.get(`${this.rootFolderName}/${folderName}`)) {
|
||||||
|
throw new Error(
|
||||||
|
`The folder '${folderName}' was not found at '${this.serverUrl}/${this.rootFolderName}'.`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const folderPathParts = sasJob.split('/')
|
||||||
|
folderPathParts.pop()
|
||||||
|
const folderPath = folderPathParts.join('/')
|
||||||
|
await this.populateFolderMap(folderPath, accessToken)
|
||||||
|
if (!this.folderMap.get(folderPath)) {
|
||||||
|
throw new Error(
|
||||||
|
`The folder '${folderPath}' was not found at '${this.serverUrl}'.`
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let files: any[] = []
|
let files: any[] = []
|
||||||
@@ -992,25 +1044,29 @@ export class SASViyaApiClient {
|
|||||||
files = await this.uploadTables(data, accessToken)
|
files = await this.uploadTables(data, accessToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
const jobName = path.basename(sasJob)
|
let jobToExecute: Job | undefined
|
||||||
const jobFolder = sasJob.replace(`/${jobName}`, '')
|
let jobName: string | undefined
|
||||||
const allJobsInFolder = this.rootFolderMap.get(jobFolder.replace('/', ''))
|
let jobPath: string | undefined
|
||||||
|
if (isRelativePath(sasJob)) {
|
||||||
if (allJobsInFolder) {
|
const folderName = sasJob.split('/')[0]
|
||||||
const jobSpec = allJobsInFolder.find((j: Job) => j.name === jobName)
|
jobName = sasJob.split('/')[1]
|
||||||
|
jobPath = `${this.rootFolderName}/${folderName}`
|
||||||
if (!jobSpec) {
|
const jobFolder = this.folderMap.get(jobPath)
|
||||||
throw new Error('Job was not found.')
|
jobToExecute = jobFolder?.find((item) => item.name === jobName)
|
||||||
|
} else {
|
||||||
|
const folderPathParts = sasJob.split('/')
|
||||||
|
jobName = folderPathParts.pop()
|
||||||
|
jobPath = folderPathParts.join('/')
|
||||||
|
const jobFolder = this.folderMap.get(jobPath)
|
||||||
|
jobToExecute = jobFolder?.find((item) => item.name === jobName)
|
||||||
}
|
}
|
||||||
|
|
||||||
const jobDefinitionLink = jobSpec?.links.find(
|
if (!jobToExecute) {
|
||||||
|
throw new Error(`The job ${sasJob} was not found.`)
|
||||||
|
}
|
||||||
|
const jobDefinitionLink = jobToExecute?.links.find(
|
||||||
(l) => l.rel === 'getResource'
|
(l) => l.rel === 'getResource'
|
||||||
)?.href
|
)?.href
|
||||||
|
|
||||||
if (!jobDefinitionLink) {
|
|
||||||
throw new Error('Job definition URI was not found.')
|
|
||||||
}
|
|
||||||
|
|
||||||
const requestInfo: any = {
|
const requestInfo: any = {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
}
|
}
|
||||||
@@ -1029,7 +1085,7 @@ export class SASViyaApiClient {
|
|||||||
|
|
||||||
const jobArguments: { [key: string]: any } = {
|
const jobArguments: { [key: string]: any } = {
|
||||||
_contextName: contextName,
|
_contextName: contextName,
|
||||||
_program: `${this.rootFolderName}/${sasJob}`,
|
_program: `${jobPath}/${jobName}`,
|
||||||
_webin_file_count: files.length,
|
_webin_file_count: files.length,
|
||||||
_OMITJSONLISTING: true,
|
_OMITJSONLISTING: true,
|
||||||
_OMITJSONLOG: true,
|
_OMITJSONLOG: true,
|
||||||
@@ -1065,18 +1121,14 @@ export class SASViyaApiClient {
|
|||||||
`${this.serverUrl}/jobExecution/jobs?_action=wait`,
|
`${this.serverUrl}/jobExecution/jobs?_action=wait`,
|
||||||
postJobRequest
|
postJobRequest
|
||||||
)
|
)
|
||||||
const jobStatus = await this.pollJobState(
|
const jobStatus = await this.pollJobState(postedJob, etag, accessToken)
|
||||||
postedJob,
|
|
||||||
etag,
|
|
||||||
accessToken,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
const { result: currentJob } = await this.request<Job>(
|
const { result: currentJob } = await this.request<Job>(
|
||||||
`${this.serverUrl}/jobExecution/jobs/${postedJob.id}`,
|
`${this.serverUrl}/jobExecution/jobs/${postedJob.id}`,
|
||||||
{ headers }
|
{ headers }
|
||||||
)
|
)
|
||||||
|
|
||||||
let jobResult, log
|
let jobResult
|
||||||
|
let log
|
||||||
if (jobStatus === 'failed') {
|
if (jobStatus === 'failed') {
|
||||||
return Promise.reject(currentJob.error)
|
return Promise.reject(currentJob.error)
|
||||||
}
|
}
|
||||||
@@ -1095,21 +1147,20 @@ export class SASViyaApiClient {
|
|||||||
{
|
{
|
||||||
headers
|
headers
|
||||||
}
|
}
|
||||||
).then((res: any) =>
|
).then((res: any) => res.result.items.map((i: any) => i.line).join('\n'))
|
||||||
res.result.items.map((i: any) => i.line).join('\n')
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
return { result: jobResult?.result, log }
|
return { result: jobResult?.result, log }
|
||||||
} else {
|
|
||||||
throw new Error(
|
|
||||||
`The job '${sasJob}' was not found in folder '${this.rootFolderName}'.`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async populateRootFolderMap(accessToken?: string) {
|
private async populateFolderMap(folderPath: string, accessToken?: string) {
|
||||||
const allItems = new Map<string, Job[]>()
|
const path = isRelativePath(folderPath)
|
||||||
const url = '/folders/folders/@item?path=' + this.rootFolderName
|
? `${this.rootFolderName}/${folderPath}`
|
||||||
|
: folderPath
|
||||||
|
if (this.folderMap.get(path)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = '/folders/folders/@item?path=' + path
|
||||||
const requestInfo: any = {
|
const requestInfo: any = {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
}
|
}
|
||||||
@@ -1121,9 +1172,7 @@ export class SASViyaApiClient {
|
|||||||
requestInfo
|
requestInfo
|
||||||
)
|
)
|
||||||
if (!folder) {
|
if (!folder) {
|
||||||
throw new Error(
|
throw new Error(`The path ${path} does not exist on ${this.serverUrl}`)
|
||||||
`Not able to populate root folder map, because folder '${this.rootFolderName}' does not exist.`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
const { result: members } = await this.request<{ items: any[] }>(
|
const { result: members } = await this.request<{ items: any[] }>(
|
||||||
`${this.serverUrl}/folders/folders/${folder.id}/members`,
|
`${this.serverUrl}/folders/folders/${folder.id}/members`,
|
||||||
@@ -1131,62 +1180,13 @@ export class SASViyaApiClient {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const itemsAtRoot = members.items
|
const itemsAtRoot = members.items
|
||||||
allItems.set('', itemsAtRoot)
|
this.folderMap.set(path, itemsAtRoot)
|
||||||
const subfolderRequests = members.items
|
|
||||||
.filter((i: any) => i.contentType === 'folder')
|
|
||||||
.map(async (member: any) => {
|
|
||||||
const subFolderUrl =
|
|
||||||
'/folders/folders/@item?path=' +
|
|
||||||
this.rootFolderName +
|
|
||||||
'/' +
|
|
||||||
member.name
|
|
||||||
const { result: memberDetail } = await this.request<Folder>(
|
|
||||||
`${this.serverUrl}${subFolderUrl}`,
|
|
||||||
requestInfo
|
|
||||||
)
|
|
||||||
|
|
||||||
const membersLink = memberDetail.links.find(
|
|
||||||
(l: any) => l.rel === 'members'
|
|
||||||
)
|
|
||||||
|
|
||||||
const { result: memberContents } = await this.request<{ items: any[] }>(
|
|
||||||
`${this.serverUrl}${membersLink!.href}`,
|
|
||||||
requestInfo
|
|
||||||
)
|
|
||||||
const itemsInFolder = memberContents.items as any[]
|
|
||||||
allItems.set(member.name, itemsInFolder)
|
|
||||||
return itemsInFolder
|
|
||||||
})
|
|
||||||
await Promise.all(subfolderRequests)
|
|
||||||
|
|
||||||
this.rootFolderMap = allItems
|
|
||||||
}
|
|
||||||
|
|
||||||
private async populateRootFolder(accessToken?: string) {
|
|
||||||
const url = '/folders/folders/@item?path=' + this.rootFolderName
|
|
||||||
const requestInfo: RequestInit = {
|
|
||||||
method: 'GET'
|
|
||||||
}
|
|
||||||
if (accessToken) {
|
|
||||||
requestInfo.headers = { Authorization: `Bearer ${accessToken}` }
|
|
||||||
}
|
|
||||||
let error
|
|
||||||
const rootFolder = await this.request<Folder>(
|
|
||||||
`${this.serverUrl}${url}`,
|
|
||||||
requestInfo
|
|
||||||
)
|
|
||||||
|
|
||||||
this.rootFolder = rootFolder?.result || null
|
|
||||||
if (error) {
|
|
||||||
throw new Error(JSON.stringify(error))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async pollJobState(
|
private async pollJobState(
|
||||||
postedJob: any,
|
postedJob: any,
|
||||||
etag: string | null,
|
etag: string | null,
|
||||||
accessToken?: string,
|
accessToken?: string
|
||||||
silent = false
|
|
||||||
) {
|
) {
|
||||||
const MAX_POLL_COUNT = 1000
|
const MAX_POLL_COUNT = 1000
|
||||||
const POLL_INTERVAL = 100
|
const POLL_INTERVAL = 100
|
||||||
@@ -1225,7 +1225,7 @@ export class SASViyaApiClient {
|
|||||||
postedJobState === 'pending'
|
postedJobState === 'pending'
|
||||||
) {
|
) {
|
||||||
if (stateLink) {
|
if (stateLink) {
|
||||||
if (!silent) {
|
if (this.debug) {
|
||||||
console.log('Polling job status... \n')
|
console.log('Polling job status... \n')
|
||||||
}
|
}
|
||||||
const { result: jobState } = await this.request<string>(
|
const { result: jobState } = await this.request<string>(
|
||||||
@@ -1237,7 +1237,7 @@ export class SASViyaApiClient {
|
|||||||
)
|
)
|
||||||
|
|
||||||
postedJobState = jobState.trim()
|
postedJobState = jobState.trim()
|
||||||
if (!silent) {
|
if (this.debug) {
|
||||||
console.log(`Current state: ${postedJobState}\n`)
|
console.log(`Current state: ${postedJobState}\n`)
|
||||||
}
|
}
|
||||||
pollCount++
|
pollCount++
|
||||||
@@ -1253,49 +1253,6 @@ export class SASViyaApiClient {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private async waitForSession(
|
|
||||||
session: Session,
|
|
||||||
etag: string | null,
|
|
||||||
accessToken?: string,
|
|
||||||
silent = false
|
|
||||||
) {
|
|
||||||
let sessionState = session.state
|
|
||||||
let pollCount = 0
|
|
||||||
const headers: any = {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'If-None-Match': etag
|
|
||||||
}
|
|
||||||
if (accessToken) {
|
|
||||||
headers.Authorization = `Bearer ${accessToken}`
|
|
||||||
}
|
|
||||||
const stateLink = session.links.find((l: any) => l.rel === 'state')
|
|
||||||
return new Promise(async (resolve, _) => {
|
|
||||||
if (sessionState === 'pending') {
|
|
||||||
if (stateLink) {
|
|
||||||
if (!silent) {
|
|
||||||
console.log('Polling session status... \n')
|
|
||||||
}
|
|
||||||
const { result: state } = await this.request<string>(
|
|
||||||
`${this.serverUrl}${stateLink.href}?wait=30`,
|
|
||||||
{
|
|
||||||
headers
|
|
||||||
},
|
|
||||||
'text'
|
|
||||||
)
|
|
||||||
|
|
||||||
sessionState = state.trim()
|
|
||||||
if (!silent) {
|
|
||||||
console.log(`Current state: ${sessionState}\n`)
|
|
||||||
}
|
|
||||||
pollCount++
|
|
||||||
resolve(sessionState)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
resolve(sessionState)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private async uploadTables(data: any, accessToken?: string) {
|
private async uploadTables(data: any, accessToken?: string) {
|
||||||
const uploadedFiles = []
|
const uploadedFiles = []
|
||||||
const headers: any = {
|
const headers: any = {
|
||||||
@@ -1321,7 +1278,9 @@ export class SASViyaApiClient {
|
|||||||
|
|
||||||
const uploadResponse = await this.request<any>(
|
const uploadResponse = await this.request<any>(
|
||||||
`${this.serverUrl}/files/files#rawUpload`,
|
`${this.serverUrl}/files/files#rawUpload`,
|
||||||
createFileRequest
|
createFileRequest,
|
||||||
|
'json',
|
||||||
|
'fileUpload'
|
||||||
)
|
)
|
||||||
|
|
||||||
uploadedFiles.push({ tableName, file: uploadResponse.result })
|
uploadedFiles.push({ tableName, file: uploadResponse.result })
|
||||||
@@ -1370,7 +1329,13 @@ export class SASViyaApiClient {
|
|||||||
return `/folders/folders/${folder.id}`
|
return `/folders/folders/${folder.id}`
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getContextByName(
|
/**
|
||||||
|
* Returns a JSON representation of a compute context.
|
||||||
|
* @example: { "createdBy": "admin", "links": [...], "id": "ID", "version": 2, "name": "context1" }
|
||||||
|
* @param contextName - the name of the context to return.
|
||||||
|
* @param accessToken - an access token for an authorized user.
|
||||||
|
*/
|
||||||
|
public async getComputeContextByName(
|
||||||
contextName: string,
|
contextName: string,
|
||||||
accessToken?: string
|
accessToken?: string
|
||||||
): Promise<Context> {
|
): Promise<Context> {
|
||||||
@@ -1385,9 +1350,7 @@ export class SASViyaApiClient {
|
|||||||
const { result: contexts } = await this.request<{ items: Context[] }>(
|
const { result: contexts } = await this.request<{ items: Context[] }>(
|
||||||
`${this.serverUrl}/compute/contexts?filter=eq(name, "${contextName}")`,
|
`${this.serverUrl}/compute/contexts?filter=eq(name, "${contextName}")`,
|
||||||
{ headers }
|
{ headers }
|
||||||
).catch((err) => {
|
)
|
||||||
throw err
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!contexts || !(contexts.items && contexts.items.length)) {
|
if (!contexts || !(contexts.items && contexts.items.length)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -1398,6 +1361,33 @@ export class SASViyaApiClient {
|
|||||||
return contexts.items[0]
|
return contexts.items[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a JSON representation of a compute context.
|
||||||
|
* @param contextId - an id of the context to return.
|
||||||
|
* @param accessToken - an access token for an authorized user.
|
||||||
|
*/
|
||||||
|
public async getComputeContextById(
|
||||||
|
contextId: string,
|
||||||
|
accessToken?: string
|
||||||
|
): Promise<ContextAllAttributes> {
|
||||||
|
const headers: any = {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (accessToken) {
|
||||||
|
headers.Authorization = `Bearer ${accessToken}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const { result: context } = await this.request<ContextAllAttributes>(
|
||||||
|
`${this.serverUrl}/compute/contexts/${contextId}`,
|
||||||
|
{ headers }
|
||||||
|
).catch((err) => {
|
||||||
|
throw err
|
||||||
|
})
|
||||||
|
|
||||||
|
return context
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves a Viya folder to a new location. The folder may be renamed at the same time.
|
* Moves a Viya folder to a new location. The folder may be renamed at the same time.
|
||||||
* @param sourceFolder - the full path (eg `/Public/example/myFolder`) or URI of the source folder to be moved. Providing URI instead of path will save one extra request.
|
* @param sourceFolder - the full path (eg `/Public/example/myFolder`) or URI of the source folder to be moved. Providing URI instead of path will save one extra request.
|
||||||
@@ -1441,6 +1431,16 @@ export class SASViyaApiClient {
|
|||||||
`${this.serverUrl}${url}`,
|
`${this.serverUrl}${url}`,
|
||||||
requestInfo
|
requestInfo
|
||||||
).catch((err) => {
|
).catch((err) => {
|
||||||
|
if (err.code && err.code === 'ENOTFOUND') {
|
||||||
|
const notFoundError = {
|
||||||
|
body: JSON.stringify({
|
||||||
|
message: `Folder '${sourceFolder.split('/').pop()}' was not found.`
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
throw notFoundError
|
||||||
|
}
|
||||||
|
|
||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -1476,22 +1476,36 @@ export class SASViyaApiClient {
|
|||||||
this.setCsrfToken(csrfToken)
|
this.setCsrfToken(csrfToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setFileUploadCsrfToken = (csrfToken: CsrfToken) => {
|
||||||
|
this.fileUploadCsrfToken = csrfToken
|
||||||
|
}
|
||||||
|
|
||||||
private async request<T>(
|
private async request<T>(
|
||||||
url: string,
|
url: string,
|
||||||
options: RequestInit,
|
options: RequestInit,
|
||||||
contentType: 'text' | 'json' = 'json'
|
contentType: 'text' | 'json' = 'json',
|
||||||
|
type: 'fileUpload' | 'other' = 'other'
|
||||||
) {
|
) {
|
||||||
|
const callback =
|
||||||
|
type === 'fileUpload'
|
||||||
|
? this.setFileUploadCsrfToken
|
||||||
|
: this.setCsrfTokenLocal
|
||||||
|
|
||||||
|
if (type === 'other') {
|
||||||
if (this.csrfToken) {
|
if (this.csrfToken) {
|
||||||
options.headers = {
|
options.headers = {
|
||||||
...options.headers,
|
...options.headers,
|
||||||
[this.csrfToken.headerName]: this.csrfToken.value
|
[this.csrfToken.headerName]: this.csrfToken.value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return await makeRequest<T>(
|
} else {
|
||||||
url,
|
if (this.fileUploadCsrfToken) {
|
||||||
options,
|
options.headers = {
|
||||||
this.setCsrfTokenLocal,
|
...options.headers,
|
||||||
contentType
|
[this.fileUploadCsrfToken.headerName]: this.fileUploadCsrfToken.value
|
||||||
)
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return await makeRequest<T>(url, options, callback, contentType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
122
src/SASjs.ts
122
src/SASjs.ts
@@ -21,7 +21,8 @@ import {
|
|||||||
parseGeneratedCode,
|
parseGeneratedCode,
|
||||||
parseWeboutResponse,
|
parseWeboutResponse,
|
||||||
needsRetry,
|
needsRetry,
|
||||||
asyncForEach
|
asyncForEach,
|
||||||
|
isRelativePath
|
||||||
} from './utils'
|
} from './utils'
|
||||||
import {
|
import {
|
||||||
SASjsConfig,
|
SASjsConfig,
|
||||||
@@ -112,16 +113,16 @@ export default class SASjs {
|
|||||||
* @param launchContextName - the name of the launcher context used by the compute service.
|
* @param launchContextName - the name of the launcher context used by the compute service.
|
||||||
* @param sharedAccountId - the ID of the account to run the servers for this context as.
|
* @param sharedAccountId - the ID of the account to run the servers for this context as.
|
||||||
* @param autoExecLines - the lines of code to execute during session initialization.
|
* @param autoExecLines - the lines of code to execute during session initialization.
|
||||||
* @param authorizedUsers - an optional list of authorized user IDs.
|
|
||||||
* @param accessToken - an access token for an authorized user.
|
* @param accessToken - an access token for an authorized user.
|
||||||
|
* @param authorizedUsers - an optional list of authorized user IDs.
|
||||||
*/
|
*/
|
||||||
public async createContext(
|
public async createContext(
|
||||||
contextName: string,
|
contextName: string,
|
||||||
launchContextName: string,
|
launchContextName: string,
|
||||||
sharedAccountId: string,
|
sharedAccountId: string,
|
||||||
autoExecLines: string[],
|
autoExecLines: string[],
|
||||||
authorizedUsers: string[],
|
accessToken: string,
|
||||||
accessToken: string
|
authorizedUsers?: string[]
|
||||||
) {
|
) {
|
||||||
this.isMethodSupported('createContext', ServerType.SASViya)
|
this.isMethodSupported('createContext', ServerType.SASViya)
|
||||||
|
|
||||||
@@ -130,8 +131,8 @@ export default class SASjs {
|
|||||||
launchContextName,
|
launchContextName,
|
||||||
sharedAccountId,
|
sharedAccountId,
|
||||||
autoExecLines,
|
autoExecLines,
|
||||||
authorizedUsers,
|
accessToken,
|
||||||
accessToken
|
authorizedUsers
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,6 +167,38 @@ export default class SASjs {
|
|||||||
return await this.sasViyaApiClient!.deleteContext(contextName, accessToken)
|
return await this.sasViyaApiClient!.deleteContext(contextName, accessToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a JSON representation of a compute context.
|
||||||
|
* @example: { "createdBy": "admin", "links": [...], "id": "ID", "version": 2, "name": "context1" }
|
||||||
|
* @param contextName - the name of the context to return.
|
||||||
|
* @param accessToken - an access token for an authorized user.
|
||||||
|
*/
|
||||||
|
public async getComputeContextByName(
|
||||||
|
contextName: string,
|
||||||
|
accessToken?: string
|
||||||
|
) {
|
||||||
|
this.isMethodSupported('getComputeContextByName', ServerType.SASViya)
|
||||||
|
|
||||||
|
return await this.sasViyaApiClient!.getComputeContextByName(
|
||||||
|
contextName,
|
||||||
|
accessToken
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a JSON representation of a compute context.
|
||||||
|
* @param contextId - an id of the context to return.
|
||||||
|
* @param accessToken - an access token for an authorized user.
|
||||||
|
*/
|
||||||
|
public async getComputeContextById(contextId: string, accessToken?: string) {
|
||||||
|
this.isMethodSupported('getComputeContextById', ServerType.SASViya)
|
||||||
|
|
||||||
|
return await this.sasViyaApiClient!.getComputeContextById(
|
||||||
|
contextId,
|
||||||
|
accessToken
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
public async createSession(contextName: string, accessToken: string) {
|
public async createSession(contextName: string, accessToken: string) {
|
||||||
this.isMethodSupported('createSession', ServerType.SASViya)
|
this.isMethodSupported('createSession', ServerType.SASViya)
|
||||||
|
|
||||||
@@ -176,9 +209,7 @@ export default class SASjs {
|
|||||||
fileName: string,
|
fileName: string,
|
||||||
linesOfCode: string[],
|
linesOfCode: string[],
|
||||||
contextName: string,
|
contextName: string,
|
||||||
accessToken?: string,
|
accessToken?: string
|
||||||
sessionId = '',
|
|
||||||
silent = false
|
|
||||||
) {
|
) {
|
||||||
this.isMethodSupported('executeScriptSASViya', ServerType.SASViya)
|
this.isMethodSupported('executeScriptSASViya', ServerType.SASViya)
|
||||||
|
|
||||||
@@ -187,9 +218,7 @@ export default class SASjs {
|
|||||||
linesOfCode,
|
linesOfCode,
|
||||||
contextName,
|
contextName,
|
||||||
accessToken,
|
accessToken,
|
||||||
silent,
|
null
|
||||||
null,
|
|
||||||
this.sasjsConfig.debug
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,8 +239,6 @@ export default class SASjs {
|
|||||||
sasApiClient?: SASViyaApiClient,
|
sasApiClient?: SASViyaApiClient,
|
||||||
isForced?: boolean
|
isForced?: boolean
|
||||||
) {
|
) {
|
||||||
this.isMethodSupported('createFolder', ServerType.SASViya)
|
|
||||||
|
|
||||||
if (sasApiClient)
|
if (sasApiClient)
|
||||||
return await sasApiClient.createFolder(
|
return await sasApiClient.createFolder(
|
||||||
folderName,
|
folderName,
|
||||||
@@ -228,6 +255,40 @@ export default class SASjs {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For performance (and in case of accidental error) the `deleteFolder` function does not actually delete the folder (and all its content and subfolder content). Instead the folder is simply moved to the recycle bin. Deletion time will be added to the folder name.
|
||||||
|
* @param folderPath - the full path (eg `/Public/example/deleteThis`) of the folder to be deleted.
|
||||||
|
* @param accessToken - an access token for authorizing the request.
|
||||||
|
*/
|
||||||
|
public async deleteFolder(folderPath: string, accessToken: string) {
|
||||||
|
this.isMethodSupported('deleteFolder', ServerType.SASViya)
|
||||||
|
|
||||||
|
return await this.sasViyaApiClient?.deleteFolder(folderPath, accessToken)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves folder to a new location. The folder may be renamed at the same time.
|
||||||
|
* @param sourceFolder - the full path (eg `/Public/example/myFolder`) or URI of the source folder to be moved. Providing URI instead of path will save one extra request.
|
||||||
|
* @param targetParentFolder - the full path or URI of the _parent_ folder to which the `sourceFolder` will be moved (eg `/Public/newDestination`). To move a folder, a user has to have write permissions in targetParentFolder. Providing URI instead of path will save one extra request.
|
||||||
|
* @param targetFolderName - the name of the "moved" folder. If left blank, the original folder name will be used (eg `myFolder` in `/Public/newDestination/myFolder` for the example above). Optional field.
|
||||||
|
* @param accessToken - an access token for authorizing the request.
|
||||||
|
*/
|
||||||
|
public async moveFolder(
|
||||||
|
sourceFolder: string,
|
||||||
|
targetParentFolder: string,
|
||||||
|
targetFolderName: string,
|
||||||
|
accessToken: string
|
||||||
|
) {
|
||||||
|
this.isMethodSupported('moveFolder', ServerType.SASViya)
|
||||||
|
|
||||||
|
return await this.sasViyaApiClient?.moveFolder(
|
||||||
|
sourceFolder,
|
||||||
|
targetParentFolder,
|
||||||
|
targetFolderName,
|
||||||
|
accessToken
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
public async createJobDefinition(
|
public async createJobDefinition(
|
||||||
jobName: string,
|
jobName: string,
|
||||||
code: string,
|
code: string,
|
||||||
@@ -345,6 +406,9 @@ export default class SASjs {
|
|||||||
*/
|
*/
|
||||||
public setDebugState(value: boolean) {
|
public setDebugState(value: boolean) {
|
||||||
this.sasjsConfig.debug = value
|
this.sasjsConfig.debug = value
|
||||||
|
if (this.sasViyaApiClient) {
|
||||||
|
this.sasViyaApiClient.debug = value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -501,8 +565,6 @@ export default class SASjs {
|
|||||||
...config
|
...config
|
||||||
}
|
}
|
||||||
|
|
||||||
sasJob = sasJob.startsWith('/') ? sasJob.replace('/', '') : sasJob
|
|
||||||
|
|
||||||
if (config.serverType === ServerType.SASViya && config.contextName) {
|
if (config.serverType === ServerType.SASViya && config.contextName) {
|
||||||
if (config.useComputeApi) {
|
if (config.useComputeApi) {
|
||||||
requestResponse = await this.executeJobViaComputeApi(
|
requestResponse = await this.executeJobViaComputeApi(
|
||||||
@@ -572,6 +634,7 @@ export default class SASjs {
|
|||||||
this.sasjsConfig.contextName,
|
this.sasjsConfig.contextName,
|
||||||
this.setCsrfTokenApi
|
this.setCsrfTokenApi
|
||||||
)
|
)
|
||||||
|
sasApiClient.debug = this.sasjsConfig.debug
|
||||||
} else if (this.sasjsConfig.serverType === ServerType.SAS9) {
|
} else if (this.sasjsConfig.serverType === ServerType.SAS9) {
|
||||||
sasApiClient = new SAS9ApiClient(serverUrl)
|
sasApiClient = new SAS9ApiClient(serverUrl)
|
||||||
}
|
}
|
||||||
@@ -794,11 +857,15 @@ export default class SASjs {
|
|||||||
SASjob: sasJob,
|
SASjob: sasJob,
|
||||||
data
|
data
|
||||||
}
|
}
|
||||||
const program = config.appLoc
|
const program = isRelativePath(sasJob)
|
||||||
|
? config.appLoc
|
||||||
? config.appLoc.replace(/\/?$/, '/') + sasJob.replace(/^\//, '')
|
? config.appLoc.replace(/\/?$/, '/') + sasJob.replace(/^\//, '')
|
||||||
: sasJob
|
: sasJob
|
||||||
|
: sasJob
|
||||||
const jobUri =
|
const jobUri =
|
||||||
config.serverType === 'SASVIYA' ? await this.getJobUri(sasJob) : ''
|
config.serverType === ServerType.SASViya
|
||||||
|
? await this.getJobUri(sasJob)
|
||||||
|
: ''
|
||||||
const apiUrl = `${config.serverUrl}${this.jobsPath}/?${
|
const apiUrl = `${config.serverUrl}${this.jobsPath}/?${
|
||||||
jobUri.length > 0
|
jobUri.length > 0
|
||||||
? '__program=' + program + '&_job=' + jobUri
|
? '__program=' + program + '&_job=' + jobUri
|
||||||
@@ -1091,14 +1158,20 @@ export default class SASjs {
|
|||||||
|
|
||||||
private async getJobUri(sasJob: string) {
|
private async getJobUri(sasJob: string) {
|
||||||
if (!this.sasViyaApiClient) return ''
|
if (!this.sasViyaApiClient) return ''
|
||||||
const jobMap: any = await this.sasViyaApiClient.getAppLocMap()
|
|
||||||
let uri = ''
|
let uri = ''
|
||||||
|
|
||||||
if (jobMap.size) {
|
let folderPath
|
||||||
const jobKey = sasJob.split('/')[0]
|
let jobName: string
|
||||||
const jobName = sasJob.split('/')[1]
|
if (isRelativePath(sasJob)) {
|
||||||
|
folderPath = sasJob.split('/')[0]
|
||||||
|
jobName = sasJob.split('/')[1]
|
||||||
|
} else {
|
||||||
|
const folderPathParts = sasJob.split('/')
|
||||||
|
jobName = folderPathParts.pop() || ''
|
||||||
|
folderPath = folderPathParts.join('/')
|
||||||
|
}
|
||||||
|
|
||||||
const locJobs = jobMap.get(jobKey)
|
const locJobs = await this.sasViyaApiClient.getJobsInFolder(folderPath)
|
||||||
if (locJobs) {
|
if (locJobs) {
|
||||||
const job = locJobs.find(
|
const job = locJobs.find(
|
||||||
(el: any) => el.name === jobName && el.contentType === 'jobDefinition'
|
(el: any) => el.name === jobName && el.contentType === 'jobDefinition'
|
||||||
@@ -1107,7 +1180,6 @@ export default class SASjs {
|
|||||||
uri = job.uri
|
uri = job.uri
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return uri
|
return uri
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1280,6 +1352,8 @@ export default class SASjs {
|
|||||||
this.sasjsConfig.contextName,
|
this.sasjsConfig.contextName,
|
||||||
this.setCsrfTokenApi
|
this.setCsrfTokenApi
|
||||||
)
|
)
|
||||||
|
|
||||||
|
this.sasViyaApiClient.debug = this.sasjsConfig.debug
|
||||||
}
|
}
|
||||||
if (this.sasjsConfig.serverType === ServerType.SAS9) {
|
if (this.sasjsConfig.serverType === ServerType.SAS9) {
|
||||||
if (this.sas9ApiClient)
|
if (this.sas9ApiClient)
|
||||||
|
|||||||
@@ -15,6 +15,15 @@ export class SessionManager {
|
|||||||
private sessions: Session[] = []
|
private sessions: Session[] = []
|
||||||
private currentContext: Context | null = null
|
private currentContext: Context | null = null
|
||||||
private csrfToken: CsrfToken | null = null
|
private csrfToken: CsrfToken | null = null
|
||||||
|
private _debug: boolean = false
|
||||||
|
|
||||||
|
public get debug() {
|
||||||
|
return this._debug
|
||||||
|
}
|
||||||
|
|
||||||
|
public set debug(value: boolean) {
|
||||||
|
this._debug = value
|
||||||
|
}
|
||||||
|
|
||||||
async getSession(accessToken?: string) {
|
async getSession(accessToken?: string) {
|
||||||
await this.createSessions(accessToken)
|
await this.createSessions(accessToken)
|
||||||
@@ -78,7 +87,7 @@ export class SessionManager {
|
|||||||
if (!this.currentContext) {
|
if (!this.currentContext) {
|
||||||
const { result: contexts } = await this.request<{
|
const { result: contexts } = await this.request<{
|
||||||
items: Context[]
|
items: Context[]
|
||||||
}>(`${this.serverUrl}/compute/contexts`, {
|
}>(`${this.serverUrl}/compute/contexts?limit=10000`, {
|
||||||
headers: this.getHeaders(accessToken)
|
headers: this.getHeaders(accessToken)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -115,8 +124,7 @@ export class SessionManager {
|
|||||||
private async waitForSession(
|
private async waitForSession(
|
||||||
session: Session,
|
session: Session,
|
||||||
etag: string | null,
|
etag: string | null,
|
||||||
accessToken?: string,
|
accessToken?: string
|
||||||
silent = false
|
|
||||||
) {
|
) {
|
||||||
let sessionState = session.state
|
let sessionState = session.state
|
||||||
const headers: any = {
|
const headers: any = {
|
||||||
@@ -127,7 +135,7 @@ export class SessionManager {
|
|||||||
return new Promise(async (resolve, _) => {
|
return new Promise(async (resolve, _) => {
|
||||||
if (sessionState === 'pending') {
|
if (sessionState === 'pending') {
|
||||||
if (stateLink) {
|
if (stateLink) {
|
||||||
if (!silent) {
|
if (this.debug) {
|
||||||
console.log('Polling session status... \n') // ?
|
console.log('Polling session status... \n') // ?
|
||||||
}
|
}
|
||||||
const { result: state } = await this.request<string>(
|
const { result: state } = await this.request<string>(
|
||||||
@@ -139,7 +147,7 @@ export class SessionManager {
|
|||||||
)
|
)
|
||||||
|
|
||||||
sessionState = state.trim()
|
sessionState = state.trim()
|
||||||
if (!silent) {
|
if (this.debug) {
|
||||||
console.log(`Current state is '${sessionState}'\n`)
|
console.log(`Current state is '${sessionState}'\n`)
|
||||||
}
|
}
|
||||||
resolve(sessionState)
|
resolve(sessionState)
|
||||||
|
|||||||
@@ -14,4 +14,26 @@ export interface EditContextInput {
|
|||||||
attributes?: any
|
attributes?: any
|
||||||
authorizedUsers?: string[]
|
authorizedUsers?: string[]
|
||||||
authorizeAllAuthenticatedUsers?: boolean
|
authorizeAllAuthenticatedUsers?: boolean
|
||||||
|
id?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ContextAllAttributes {
|
||||||
|
attributes: {
|
||||||
|
reuseServerProcesses: boolean
|
||||||
|
runServerAs: string
|
||||||
|
}
|
||||||
|
modifiedTimeStamp: string
|
||||||
|
createdBy: string
|
||||||
|
creationTimeStamp: string
|
||||||
|
launchType: string
|
||||||
|
environment: {
|
||||||
|
autoExecLines: [string]
|
||||||
|
}
|
||||||
|
launchContext: {
|
||||||
|
contextName: string
|
||||||
|
}
|
||||||
|
modifiedBy: string
|
||||||
|
id: string
|
||||||
|
version: number
|
||||||
|
name: string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { ServerType } from './ServerType'
|
import { ServerType } from './ServerType'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the configuration for the SASjs instance.
|
* Specifies the configuration for the SASjs instance - eg where and how to
|
||||||
*
|
* connect to SAS.
|
||||||
*/
|
*/
|
||||||
export class SASjsConfig {
|
export class SASjsConfig {
|
||||||
/**
|
/**
|
||||||
@@ -11,11 +11,24 @@ export class SASjsConfig {
|
|||||||
* streamed.
|
* streamed.
|
||||||
*/
|
*/
|
||||||
serverUrl: string = ''
|
serverUrl: string = ''
|
||||||
|
/**
|
||||||
|
* The location of the Stored Process Web Application. By default the adapter
|
||||||
|
* will use '/SASStoredProcess/do' on SAS 9.
|
||||||
|
*/
|
||||||
pathSAS9: string = ''
|
pathSAS9: string = ''
|
||||||
|
/**
|
||||||
|
* The location of the Job Execution Web Application. By default the adapter
|
||||||
|
* will use '/SASJobExecution' on SAS Viya.
|
||||||
|
*/
|
||||||
pathSASViya: string = ''
|
pathSASViya: string = ''
|
||||||
/**
|
/**
|
||||||
* The appLoc is the parent folder under which the SAS services (STPs or Job
|
* The appLoc is the parent folder under which the SAS services (STPs or Job
|
||||||
* Execution Services) are stored.
|
* Execution Services) are stored. We recommend that each app is stored in
|
||||||
|
* a dedicated parent folder (the appLoc) and the services are grouped inside
|
||||||
|
* subfolders within the appLoc - allowing functionality to be restricted
|
||||||
|
* according to those groups at backend.
|
||||||
|
* When using appLoc, the paths provided in the `request` function should be
|
||||||
|
* _without_ a leading slash (/).
|
||||||
*/
|
*/
|
||||||
appLoc: string = ''
|
appLoc: string = ''
|
||||||
/**
|
/**
|
||||||
@@ -26,6 +39,22 @@ export class SASjsConfig {
|
|||||||
* Set to `true` to enable additional debugging.
|
* Set to `true` to enable additional debugging.
|
||||||
*/
|
*/
|
||||||
debug: boolean = true
|
debug: boolean = true
|
||||||
|
/**
|
||||||
|
* The name of the compute context to use when calling the Viya APIs directly.
|
||||||
|
* Example value: 'SAS Job Execution compute context'
|
||||||
|
* If set to missing or empty, and useComputeApi is true, the adapter will use
|
||||||
|
* the JES APIs. If provided, the Job Code will be executed in pooled
|
||||||
|
* compute sessions on this named context.
|
||||||
|
*/
|
||||||
contextName: string = ''
|
contextName: string = ''
|
||||||
|
/**
|
||||||
|
* Set to `false` to use the Job Execution Web Service. To enhance VIYA
|
||||||
|
* performance, set to `true` and provide a `contextName` on which to run
|
||||||
|
* the code. When running on a named context, the code executes under the
|
||||||
|
* user identity. When running as a Job Execution service, the code runs
|
||||||
|
* under the identity in the JES context. If no `contextName` is provided,
|
||||||
|
* and `useComputeApi` is `true`, then the service will run as a Job, except
|
||||||
|
* triggered using the APIs instead of the Job Execution Web Service broker.
|
||||||
|
*/
|
||||||
useComputeApi = false
|
useComputeApi = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
export * from './Context'
|
export * from './Context'
|
||||||
export * from './CsrfToken'
|
export * from './CsrfToken'
|
||||||
|
export * from './ErrorResponse'
|
||||||
export * from './Folder'
|
export * from './Folder'
|
||||||
export * from './Job'
|
export * from './Job'
|
||||||
|
export * from './JobDefinition'
|
||||||
|
export * from './JobResult'
|
||||||
export * from './Link'
|
export * from './Link'
|
||||||
export * from './SASjsConfig'
|
export * from './SASjsConfig'
|
||||||
export * from './SASjsRequest'
|
export * from './SASjsRequest'
|
||||||
@@ -9,4 +12,3 @@ export * from './SASjsWaitingRequest'
|
|||||||
export * from './ServerType'
|
export * from './ServerType'
|
||||||
export * from './Session'
|
export * from './Session'
|
||||||
export * from './UploadFile'
|
export * from './UploadFile'
|
||||||
export * from './ErrorResponse'
|
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ export * from './convertToCsv'
|
|||||||
export * from './isAuthorizeFormRequired'
|
export * from './isAuthorizeFormRequired'
|
||||||
export * from './isLoginRequired'
|
export * from './isLoginRequired'
|
||||||
export * from './isLoginSuccess'
|
export * from './isLoginSuccess'
|
||||||
|
export * from './isRelativePath'
|
||||||
|
export * from './isUri'
|
||||||
|
export * from './isUrl'
|
||||||
export * from './makeRequest'
|
export * from './makeRequest'
|
||||||
export * from './needsRetry'
|
export * from './needsRetry'
|
||||||
export * from './parseAndSubmitAuthorizeForm'
|
export * from './parseAndSubmitAuthorizeForm'
|
||||||
@@ -13,5 +16,3 @@ export * from './parseSasViyaLog'
|
|||||||
export * from './serialize'
|
export * from './serialize'
|
||||||
export * from './splitChunks'
|
export * from './splitChunks'
|
||||||
export * from './parseWeboutResponse'
|
export * from './parseWeboutResponse'
|
||||||
export * from './isUri'
|
|
||||||
export * from './isUrl'
|
|
||||||
|
|||||||
2
src/utils/isRelativePath.ts
Normal file
2
src/utils/isRelativePath.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
export const isRelativePath = (uri: string): boolean =>
|
||||||
|
!!uri && !uri.startsWith('/')
|
||||||
@@ -48,7 +48,7 @@ export async function makeRequest<T>(
|
|||||||
try {
|
try {
|
||||||
body = JSON.parse(body)
|
body = JSON.parse(body)
|
||||||
|
|
||||||
body.message = `Forbidden. Check your permissions and user groups. ${
|
body.message = `Forbidden. Check your permissions and user groups, and also the scopes granted when registering your CLIENT_ID. ${
|
||||||
body.message || ''
|
body.message || ''
|
||||||
}`
|
}`
|
||||||
|
|
||||||
|
|||||||
@@ -1,49 +1,56 @@
|
|||||||
const path = require("path");
|
const path = require('path')
|
||||||
const webpack = require("webpack");
|
const webpack = require('webpack')
|
||||||
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
|
const terserPlugin = require('terser-webpack-plugin')
|
||||||
|
|
||||||
const browserConfig = {
|
const browserConfig = {
|
||||||
entry: "./src/index.ts",
|
entry: './src/index.ts',
|
||||||
devtool: "inline-source-map",
|
devtool: 'inline-source-map',
|
||||||
mode: "development",
|
mode: 'production',
|
||||||
optimization: {
|
optimization: {
|
||||||
minimize: false,
|
minimizer: [
|
||||||
|
new terserPlugin({
|
||||||
|
cache: true,
|
||||||
|
parallel: true,
|
||||||
|
sourceMap: true,
|
||||||
|
terserOptions: {}
|
||||||
|
})
|
||||||
|
]
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
test: /\.ts?$/,
|
test: /\.ts?$/,
|
||||||
use: "ts-loader",
|
use: 'ts-loader',
|
||||||
exclude: /node_modules/,
|
exclude: /node_modules/
|
||||||
},
|
}
|
||||||
],
|
]
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: [".ts", ".js"],
|
extensions: ['.ts', '.js']
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
filename: "index.js",
|
filename: 'index.js',
|
||||||
path: path.resolve(__dirname, "build"),
|
path: path.resolve(__dirname, 'build'),
|
||||||
libraryTarget: "umd",
|
libraryTarget: 'umd',
|
||||||
library: "SASjs",
|
library: 'SASjs'
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en/),
|
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en/),
|
||||||
new webpack.SourceMapDevToolPlugin({
|
new webpack.SourceMapDevToolPlugin({
|
||||||
filename: null,
|
filename: null,
|
||||||
exclude: [/node_modules/],
|
exclude: [/node_modules/],
|
||||||
test: /\.ts($|\?)/i,
|
test: /\.ts($|\?)/i
|
||||||
}),
|
})
|
||||||
],
|
]
|
||||||
};
|
}
|
||||||
|
|
||||||
const nodeConfig = {
|
const nodeConfig = {
|
||||||
...browserConfig,
|
...browserConfig,
|
||||||
target: "node",
|
target: 'node',
|
||||||
output: {
|
output: {
|
||||||
...browserConfig.output,
|
...browserConfig.output,
|
||||||
path: path.resolve(__dirname, "build", "node"),
|
path: path.resolve(__dirname, 'build', 'node')
|
||||||
},
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports = [browserConfig, nodeConfig];
|
module.exports = [browserConfig, nodeConfig]
|
||||||
|
|||||||
Reference in New Issue
Block a user