mirror of
https://github.com/sasjs/adapter.git
synced 2025-12-12 09:44:36 +00:00
Compare commits
7 Commits
sasjs-test
...
fixing-sas
| Author | SHA1 | Date | |
|---|---|---|---|
| 0bd156141c | |||
| a615c5fdb6 | |||
| ca7ee83f7f | |||
| 97a530cc66 | |||
| 317c8c81a0 | |||
| c87776ca1b | |||
| 04032831c3 |
@@ -1,103 +1,24 @@
|
|||||||
{
|
{
|
||||||
"projectName": "adapter",
|
|
||||||
"projectOwner": "sasjs",
|
|
||||||
"repoType": "github",
|
|
||||||
"repoHost": "https://github.com",
|
|
||||||
"files": [
|
"files": [
|
||||||
"README.md"
|
"README.md"
|
||||||
],
|
],
|
||||||
"imageSize": 100,
|
"imageSize": 100,
|
||||||
"commit": false,
|
"commit": false,
|
||||||
"commitConvention": "angular",
|
|
||||||
"contributors": [
|
"contributors": [
|
||||||
{
|
|
||||||
"login": "krishna-acondy",
|
|
||||||
"name": "Krishna Acondy",
|
|
||||||
"avatar_url": "https://avatars.githubusercontent.com/u/2980428?v=4",
|
|
||||||
"profile": "https://krishna-acondy.io/",
|
|
||||||
"contributions": [
|
|
||||||
"code",
|
|
||||||
"infra",
|
|
||||||
"blog",
|
|
||||||
"content",
|
|
||||||
"ideas",
|
|
||||||
"video"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"login": "YuryShkoda",
|
|
||||||
"name": "Yury Shkoda",
|
|
||||||
"avatar_url": "https://avatars.githubusercontent.com/u/25773492?v=4",
|
|
||||||
"profile": "https://www.erudicat.com/",
|
|
||||||
"contributions": [
|
|
||||||
"code",
|
|
||||||
"infra",
|
|
||||||
"ideas",
|
|
||||||
"test",
|
|
||||||
"video"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"login": "medjedovicm",
|
"login": "medjedovicm",
|
||||||
"name": "Mihajlo Medjedovic",
|
"name": "Mihajlo Medjedovic",
|
||||||
"avatar_url": "https://avatars.githubusercontent.com/u/18329105?v=4",
|
"avatar_url": "https://avatars.githubusercontent.com/u/18329105?v=4",
|
||||||
"profile": "https://github.com/medjedovicm",
|
"profile": "https://github.com/medjedovicm",
|
||||||
"contributions": [
|
"contributions": [
|
||||||
"code",
|
"code"
|
||||||
"infra",
|
|
||||||
"test",
|
|
||||||
"review"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"login": "allanbowe",
|
|
||||||
"name": "Allan Bowe",
|
|
||||||
"avatar_url": "https://avatars.githubusercontent.com/u/4420615?v=4",
|
|
||||||
"profile": "https://github.com/allanbowe",
|
|
||||||
"contributions": [
|
|
||||||
"code",
|
|
||||||
"review",
|
|
||||||
"test",
|
|
||||||
"mentoring",
|
|
||||||
"maintenance"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"login": "saadjutt01",
|
|
||||||
"name": "Muhammad Saad ",
|
|
||||||
"avatar_url": "https://avatars.githubusercontent.com/u/8914650?v=4",
|
|
||||||
"profile": "https://github.com/saadjutt01",
|
|
||||||
"contributions": [
|
|
||||||
"code",
|
|
||||||
"review",
|
|
||||||
"test",
|
|
||||||
"mentoring",
|
|
||||||
"infra"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"login": "sabhas",
|
|
||||||
"name": "Sabir Hassan",
|
|
||||||
"avatar_url": "https://avatars.githubusercontent.com/u/82647447?v=4",
|
|
||||||
"profile": "https://github.com/sabhas",
|
|
||||||
"contributions": [
|
|
||||||
"code",
|
|
||||||
"review",
|
|
||||||
"test",
|
|
||||||
"ideas"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"login": "VladislavParhomchik",
|
|
||||||
"name": "VladislavParhomchik",
|
|
||||||
"avatar_url": "https://avatars.githubusercontent.com/u/83717836?v=4",
|
|
||||||
"profile": "https://github.com/VladislavParhomchik",
|
|
||||||
"contributions": [
|
|
||||||
"test",
|
|
||||||
"review"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"contributorsPerLine": 7,
|
"contributorsPerLine": 7,
|
||||||
|
"projectName": "adapter",
|
||||||
|
"projectOwner": "sasjs",
|
||||||
|
"repoType": "github",
|
||||||
|
"repoHost": "https://github.com",
|
||||||
"skipCi": true
|
"skipCi": true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ GREEN="\033[1;32m"
|
|||||||
# temporary file which holds the message).
|
# temporary file which holds the message).
|
||||||
commit_message=$(cat "$1")
|
commit_message=$(cat "$1")
|
||||||
|
|
||||||
if (echo "$commit_message" | grep -Eq "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([a-z0-9 -\*]+\))?!?: .+$") then
|
if (echo "$commit_message" | grep -Eq "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([a-z0-9 \-\*]+\))?!?: .+$") then
|
||||||
echo "${GREEN} ✔ Commit message meets Conventional Commit standards"
|
echo "${GREEN} ✔ Commit message meets Conventional Commit standards"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|||||||
10
.github/dependabot.yml
vendored
10
.github/dependabot.yml
vendored
@@ -1,7 +1,7 @@
|
|||||||
version: 2
|
version: 2
|
||||||
updates:
|
updates:
|
||||||
- package-ecosystem: npm
|
- package-ecosystem: npm
|
||||||
directory: '/'
|
directory: "/"
|
||||||
schedule:
|
schedule:
|
||||||
interval: monthly
|
interval: daily
|
||||||
open-pull-requests-limit: 10
|
open-pull-requests-limit: 10
|
||||||
|
|||||||
5
.github/workflows/build.yml
vendored
5
.github/workflows/build.yml
vendored
@@ -13,15 +13,14 @@ jobs:
|
|||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [lts/fermium]
|
node-version: [15.x]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
- name: Use Node.js ${{ matrix.node-version }}
|
||||||
uses: actions/setup-node@v2
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node-version }}
|
node-version: ${{ matrix.node-version }}
|
||||||
cache: npm
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
- name: Check code style
|
- name: Check code style
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
sasjs-tests/
|
sasjs-tests/
|
||||||
docs/
|
docs/
|
||||||
.github/
|
.github/
|
||||||
*.md
|
CONTRIBUTING.md
|
||||||
*.spec.ts
|
|
||||||
.all-contributorsrc
|
|
||||||
|
|||||||
27
README.md
27
README.md
@@ -36,7 +36,7 @@ Ok ok. Deploy this [example.html](https://raw.githubusercontent.com/sasjs/adapte
|
|||||||
|
|
||||||
The backend part can be deployed as follows:
|
The backend part can be deployed as follows:
|
||||||
|
|
||||||
```sas
|
```
|
||||||
%let appLoc=/Public/app/readme; /* Metadata or Viya Folder per SASjs config */
|
%let appLoc=/Public/app/readme; /* Metadata or Viya Folder per SASjs config */
|
||||||
filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
|
filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
|
||||||
%inc mc; /* compile macros (can also be downloaded & compiled seperately) */
|
%inc mc; /* compile macros (can also be downloaded & compiled seperately) */
|
||||||
@@ -85,11 +85,11 @@ let sasJs = new SASjs.default(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
If you've installed it via NPM, you can import it as a default import like so:
|
If you've installed it via NPM, you can import it as a default import like so:
|
||||||
```js
|
```
|
||||||
import SASjs from '@sasjs/adapter';
|
import SASjs from '@sasjs/adapter';
|
||||||
```
|
```
|
||||||
You can then instantiate it with:
|
You can then instantiate it with:
|
||||||
```js
|
```
|
||||||
const sasJs = new SASjs({your config})
|
const sasJs = new SASjs({your config})
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -119,7 +119,6 @@ sasJs.request("/path/to/my/service", dataObject)
|
|||||||
console.log(response.tablewith2cols1row[0].COL1.value)
|
console.log(response.tablewith2cols1row[0].COL1.value)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
We supply the path to the SAS service, and a data object. The data object can be null (for services with no input), or can contain one or more tables in the following format:
|
We supply the path to the SAS service, and a data object. The data object can be null (for services with no input), or can contain one or more tables in the following format:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
@@ -147,7 +146,6 @@ The adapter will also cache the logs (if debug enabled) and even the work tables
|
|||||||
The SAS side is handled by a number of macros in the [macro core](https://github.com/sasjs/core) library.
|
The SAS side is handled by a number of macros in the [macro core](https://github.com/sasjs/core) library.
|
||||||
|
|
||||||
The following snippet shows the process of SAS tables arriving / leaving:
|
The following snippet shows the process of SAS tables arriving / leaving:
|
||||||
|
|
||||||
```sas
|
```sas
|
||||||
/* fetch all input tables sent from frontend - they arrive as work tables */
|
/* fetch all input tables sent from frontend - they arrive as work tables */
|
||||||
%webout(FETCH)
|
%webout(FETCH)
|
||||||
@@ -163,6 +161,7 @@ run;
|
|||||||
%webout(OBJ,tables,fmt=N) /* unformatted (raw) data */
|
%webout(OBJ,tables,fmt=N) /* unformatted (raw) data */
|
||||||
%webout(OBJ,tables,label=newtable) /* rename tables on export */
|
%webout(OBJ,tables,label=newtable) /* rename tables on export */
|
||||||
%webout(CLOSE) /* close the JSON and send some extra useful variables too */
|
%webout(CLOSE) /* close the JSON and send some extra useful variables too */
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
@@ -173,7 +172,6 @@ Configuration on the client side involves passing an object on startup, which ca
|
|||||||
* `serverType` - either `SAS9` or `SASVIYA`.
|
* `serverType` - either `SAS9` or `SASVIYA`.
|
||||||
* `serverUrl` - the location (including http protocol and port) of the SAS Server. Can be omitted, eg if serving directly from the SAS Web Server, or in streaming mode.
|
* `serverUrl` - the location (including http protocol and port) of the SAS Server. Can be omitted, eg if serving directly from the SAS Web Server, or in streaming mode.
|
||||||
* `debug` - if `true` then SAS Logs and extra debug information is returned.
|
* `debug` - if `true` then SAS Logs and extra debug information is returned.
|
||||||
* `LoginMechanism` - either `Default` or `Redirected`. If `Redirected` then authentication occurs through the injection of an additional screen, which contains the SASLogon prompt. This allows for more complex authentication flows (such as 2FA) and avoids the need to handle passwords in the application itself. The styling of the redirect flow can also be modified. If left at "Default" then the developer must capture the username and password and use these with the `.login()` method.
|
|
||||||
* `useComputeApi` - Only relevant when the serverType is `SASVIYA`. If `true` the [Compute API](#using-the-compute-api) is used. If `false` the [JES API](#using-the-jes-api) is used. If `null` or `undefined` the [Web](#using-jes-web-app) approach is used.
|
* `useComputeApi` - Only relevant when the serverType is `SASVIYA`. If `true` the [Compute API](#using-the-compute-api) is used. If `false` the [JES API](#using-the-jes-api) is used. If `null` or `undefined` the [Web](#using-jes-web-app) approach is used.
|
||||||
* `contextName` - Compute context on which the requests will be called. If missing or not provided, defaults to `Job Execution Compute context`.
|
* `contextName` - Compute context on which the requests will be called. If missing or not provided, defaults to `Job Execution Compute context`.
|
||||||
|
|
||||||
@@ -198,7 +196,7 @@ Here we are running Jobs using the Job Execution Service except this time we are
|
|||||||
|
|
||||||
This approach (`useComputeApi: false`) also ensures that jobs are displayed in Environment Manager.
|
This approach (`useComputeApi: false`) also ensures that jobs are displayed in Environment Manager.
|
||||||
|
|
||||||
```json
|
```
|
||||||
{
|
{
|
||||||
appLoc:"/Your/Path",
|
appLoc:"/Your/Path",
|
||||||
serverType:"SASVIYA",
|
serverType:"SASVIYA",
|
||||||
@@ -212,12 +210,12 @@ This approach is by far the fastest, as a result of the optimisations we have bu
|
|||||||
|
|
||||||
With this approach (`useComputeApi: true`), the requests/logs will _not_ appear in the list in Environment manager.
|
With this approach (`useComputeApi: true`), the requests/logs will _not_ appear in the list in Environment manager.
|
||||||
|
|
||||||
```json
|
```
|
||||||
{
|
{
|
||||||
appLoc:"/Your/Path",
|
appLoc:"/Your/Path",
|
||||||
serverType:"SASVIYA",
|
serverType:"SASVIYA",
|
||||||
useComputeApi: true,
|
useComputeApi: true,
|
||||||
contextName: "yourComputeContext"
|
contextName: 'yourComputeContext'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -238,9 +236,6 @@ If you find this library useful, help us grow our star graph!
|
|||||||

|

|
||||||
|
|
||||||
## Contributors ✨
|
## Contributors ✨
|
||||||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
||||||
[](#contributors-)
|
|
||||||
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
||||||
|
|
||||||
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
||||||
|
|
||||||
@@ -249,13 +244,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|||||||
<!-- markdownlint-disable -->
|
<!-- markdownlint-disable -->
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td align="center"><a href="https://krishna-acondy.io/"><img src="https://avatars.githubusercontent.com/u/2980428?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Krishna Acondy</b></sub></a><br /><a href="https://github.com/sasjs/adapter/commits?author=krishna-acondy" title="Code">💻</a> <a href="#infra-krishna-acondy" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#blog-krishna-acondy" title="Blogposts">📝</a> <a href="#content-krishna-acondy" title="Content">🖋</a> <a href="#ideas-krishna-acondy" title="Ideas, Planning, & Feedback">🤔</a> <a href="#video-krishna-acondy" title="Videos">📹</a></td>
|
<td align="center"><a href="https://github.com/medjedovicm"><img src="https://avatars.githubusercontent.com/u/18329105?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Mihajlo Medjedovic</b></sub></a><br /><a href="https://github.com/sasjs/adapter/commits?author=medjedovicm" title="Code">💻</a></td>
|
||||||
<td align="center"><a href="https://www.erudicat.com/"><img src="https://avatars.githubusercontent.com/u/25773492?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Yury Shkoda</b></sub></a><br /><a href="https://github.com/sasjs/adapter/commits?author=YuryShkoda" title="Code">💻</a> <a href="#infra-YuryShkoda" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#ideas-YuryShkoda" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/sasjs/adapter/commits?author=YuryShkoda" title="Tests">⚠️</a> <a href="#video-YuryShkoda" title="Videos">📹</a></td>
|
|
||||||
<td align="center"><a href="https://github.com/medjedovicm"><img src="https://avatars.githubusercontent.com/u/18329105?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Mihajlo Medjedovic</b></sub></a><br /><a href="https://github.com/sasjs/adapter/commits?author=medjedovicm" title="Code">💻</a> <a href="#infra-medjedovicm" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/sasjs/adapter/commits?author=medjedovicm" title="Tests">⚠️</a> <a href="https://github.com/sasjs/adapter/pulls?q=is%3Apr+reviewed-by%3Amedjedovicm" title="Reviewed Pull Requests">👀</a></td>
|
|
||||||
<td align="center"><a href="https://github.com/allanbowe"><img src="https://avatars.githubusercontent.com/u/4420615?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Allan Bowe</b></sub></a><br /><a href="https://github.com/sasjs/adapter/commits?author=allanbowe" title="Code">💻</a> <a href="https://github.com/sasjs/adapter/pulls?q=is%3Apr+reviewed-by%3Aallanbowe" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/sasjs/adapter/commits?author=allanbowe" title="Tests">⚠️</a> <a href="#mentoring-allanbowe" title="Mentoring">🧑🏫</a> <a href="#maintenance-allanbowe" title="Maintenance">🚧</a></td>
|
|
||||||
<td align="center"><a href="https://github.com/saadjutt01"><img src="https://avatars.githubusercontent.com/u/8914650?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Muhammad Saad </b></sub></a><br /><a href="https://github.com/sasjs/adapter/commits?author=saadjutt01" title="Code">💻</a> <a href="https://github.com/sasjs/adapter/pulls?q=is%3Apr+reviewed-by%3Asaadjutt01" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/sasjs/adapter/commits?author=saadjutt01" title="Tests">⚠️</a> <a href="#mentoring-saadjutt01" title="Mentoring">🧑🏫</a> <a href="#infra-saadjutt01" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
|
|
||||||
<td align="center"><a href="https://github.com/sabhas"><img src="https://avatars.githubusercontent.com/u/82647447?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sabir Hassan</b></sub></a><br /><a href="https://github.com/sasjs/adapter/commits?author=sabhas" title="Code">💻</a> <a href="https://github.com/sasjs/adapter/pulls?q=is%3Apr+reviewed-by%3Asabhas" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/sasjs/adapter/commits?author=sabhas" title="Tests">⚠️</a> <a href="#ideas-sabhas" title="Ideas, Planning, & Feedback">🤔</a></td>
|
|
||||||
<td align="center"><a href="https://github.com/VladislavParhomchik"><img src="https://avatars.githubusercontent.com/u/83717836?v=4?s=100" width="100px;" alt=""/><br /><sub><b>VladislavParhomchik</b></sub></a><br /><a href="https://github.com/sasjs/adapter/commits?author=VladislavParhomchik" title="Tests">⚠️</a> <a href="https://github.com/sasjs/adapter/pulls?q=is%3Apr+reviewed-by%3AVladislavParhomchik" title="Reviewed Pull Requests">👀</a></td>
|
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
const result = process.versions
|
|
||||||
if (result && result.node) {
|
|
||||||
if (parseInt(result.node) < 14) {
|
|
||||||
console.log(
|
|
||||||
'\x1b[31m%s\x1b[0m',
|
|
||||||
`❌ Process failed due to Node Version,\nPlease install and use Node Version >= 14\nYour current Node Version is: ${result.node}`
|
|
||||||
)
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.log(
|
|
||||||
'\x1b[31m%s\x1b[0m',
|
|
||||||
'Something went wrong while checking Node version'
|
|
||||||
)
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
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
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
139
docs/index.html
139
docs/index.html
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
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
19515
package-lock.json
generated
19515
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
31
package.json
31
package.json
@@ -3,10 +3,8 @@
|
|||||||
"description": "JavaScript adapter for SAS",
|
"description": "JavaScript adapter for SAS",
|
||||||
"homepage": "https://adapter.sasjs.io",
|
"homepage": "https://adapter.sasjs.io",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"preinstall": "node checkNodeVersion",
|
|
||||||
"prebuild": "node checkNodeVersion",
|
|
||||||
"build": "rimraf build && rimraf node && mkdir node && copyfiles -u 1 \"./src/**/*\" ./node && webpack && rimraf build/src && rimraf node",
|
"build": "rimraf build && rimraf node && mkdir node && copyfiles -u 1 \"./src/**/*\" ./node && webpack && rimraf build/src && rimraf node",
|
||||||
"package:lib": "npm run build && copyfiles ./package.json ./checkNodeVersion.js build && cd build && npm version \"5.0.0\" && npm pack",
|
"package:lib": "npm run build && copyfiles ./package.json build && cd build && npm version \"5.0.0\" && npm pack",
|
||||||
"publish:lib": "npm run build && cd build && npm publish",
|
"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}\" && npx prettier --write \"sasjs-tests/src/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\"",
|
"lint:fix": "npx prettier --write \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\" && npx prettier --write \"sasjs-tests/src/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\"",
|
||||||
"lint": "npx prettier --check \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\" && npx prettier --check \"sasjs-tests/src/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\"",
|
"lint": "npx prettier --check \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\" && npx prettier --check \"sasjs-tests/src/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\"",
|
||||||
@@ -41,43 +39,42 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/axios": "^0.14.0",
|
"@types/axios": "^0.14.0",
|
||||||
"@types/express": "^4.17.13",
|
|
||||||
"@types/form-data": "^2.5.0",
|
"@types/form-data": "^2.5.0",
|
||||||
"@types/jest": "^27.0.2",
|
"@types/jest": "^26.0.24",
|
||||||
"@types/mime": "^2.0.3",
|
"@types/mime": "^2.0.3",
|
||||||
"@types/pem": "^1.9.6",
|
|
||||||
"@types/tough-cookie": "^4.0.1",
|
"@types/tough-cookie": "^4.0.1",
|
||||||
"copyfiles": "^2.4.1",
|
"copyfiles": "^2.4.1",
|
||||||
"cp": "^0.2.0",
|
"cp": "^0.2.0",
|
||||||
"dotenv": "^10.0.0",
|
"dotenv": "^10.0.0",
|
||||||
"express": "^4.17.1",
|
"jest": "^27.0.6",
|
||||||
"jest": "^27.2.0",
|
|
||||||
"jest-extended": "^0.11.5",
|
"jest-extended": "^0.11.5",
|
||||||
"node-polyfill-webpack-plugin": "^1.1.4",
|
"node-polyfill-webpack-plugin": "^1.1.4",
|
||||||
"path": "^0.12.7",
|
"path": "^0.12.7",
|
||||||
"pem": "^1.14.4",
|
|
||||||
"process": "^0.11.10",
|
"process": "^0.11.10",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"semantic-release": "^18.0.0",
|
"semantic-release": "^17.4.4",
|
||||||
"terser-webpack-plugin": "^5.2.4",
|
"terser-webpack-plugin": "^5.1.4",
|
||||||
"ts-jest": "^27.0.3",
|
"ts-jest": "^27.0.3",
|
||||||
"ts-loader": "^9.2.6",
|
"ts-loader": "^9.2.2",
|
||||||
"tslint": "^6.1.3",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.18.0",
|
"tslint-config-prettier": "^1.18.0",
|
||||||
"typedoc": "0.19.2",
|
"typedoc": "^0.21.4",
|
||||||
"typedoc-neo-theme": "^1.1.1",
|
"typedoc-neo-theme": "^1.1.1",
|
||||||
"typedoc-plugin-external-module-name": "^4.0.6",
|
"typedoc-plugin-external-module-name": "^4.0.6",
|
||||||
"typescript": "4.3.5",
|
"typescript": "^4.3.5",
|
||||||
"webpack": "^5.56.0",
|
"webpack": "^5.44.0",
|
||||||
"webpack-cli": "^4.7.2"
|
"webpack-cli": "^4.7.2"
|
||||||
},
|
},
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sasjs/utils": "^2.32.0",
|
"@sasjs/utils": "^2.27.1",
|
||||||
"axios": "^0.21.4",
|
"axios": "^0.21.1",
|
||||||
"axios-cookiejar-support": "^1.0.1",
|
"axios-cookiejar-support": "^1.0.1",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0",
|
||||||
"https": "^1.0.0",
|
"https": "^1.0.0",
|
||||||
"tough-cookie": "^4.0.0"
|
"tough-cookie": "^4.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=15"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
27327
sasjs-tests/package-lock.json
generated
27327
sasjs-tests/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,7 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sasjs/adapter": "file:../build/sasjs-adapter-5.0.0.tgz",
|
"@sasjs/adapter": "file:../build/sasjs-adapter-5.0.0.tgz",
|
||||||
"@sasjs/test-framework": "^1.4.2",
|
"@sasjs/test-framework": "^1.4.0",
|
||||||
"@types/jest": "^26.0.20",
|
"@types/jest": "^26.0.20",
|
||||||
"@types/node": "^14.14.41",
|
"@types/node": "^14.14.41",
|
||||||
"@types/react": "^17.0.1",
|
"@types/react": "^17.0.1",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import SASjs, { LoginMechanism, SASjsConfig } from '@sasjs/adapter'
|
import SASjs, { SASjsConfig } from '@sasjs/adapter'
|
||||||
import { TestSuite } from '@sasjs/test-framework'
|
import { TestSuite } from '@sasjs/test-framework'
|
||||||
import { ServerType } from '@sasjs/utils/types'
|
import { ServerType } from '@sasjs/utils/types'
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ const defaultConfig: SASjsConfig = {
|
|||||||
debug: false,
|
debug: false,
|
||||||
contextName: 'SAS Job Execution compute context',
|
contextName: 'SAS Job Execution compute context',
|
||||||
useComputeApi: false,
|
useComputeApi: false,
|
||||||
loginMechanism: LoginMechanism.Default
|
allowInsecureRequests: false
|
||||||
}
|
}
|
||||||
|
|
||||||
const customConfig = {
|
const customConfig = {
|
||||||
@@ -41,27 +41,16 @@ export const basicTests = (
|
|||||||
assertion: (response: any) =>
|
assertion: (response: any) =>
|
||||||
response && response.isLoggedIn && response.userName === userName
|
response && response.isLoggedIn && response.userName === userName
|
||||||
},
|
},
|
||||||
{
|
|
||||||
title: 'Fetch username for already logged in user',
|
|
||||||
description: 'Should log the user in',
|
|
||||||
test: async () => {
|
|
||||||
await adapter.logIn(userName, password)
|
|
||||||
|
|
||||||
const newAdapterIns = new SASjs(adapter.getSasjsConfig())
|
|
||||||
|
|
||||||
return await newAdapterIns.checkSession()
|
|
||||||
},
|
|
||||||
assertion: (response: any) =>
|
|
||||||
response?.isLoggedIn && response?.userName === userName
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
title: 'Multiple Log in attempts',
|
title: 'Multiple Log in attempts',
|
||||||
description:
|
description:
|
||||||
'Should fail on first attempt and should log the user in on second attempt',
|
'Should fail on first attempt and should log the user in on second attempt',
|
||||||
test: async () => {
|
test: async () => {
|
||||||
await adapter.logOut()
|
await adapter.logOut()
|
||||||
|
await sleep(1000)
|
||||||
await adapter.logIn('invalid', 'invalid')
|
await adapter.logIn('invalid', 'invalid')
|
||||||
return await adapter.logIn(userName, password)
|
await sleep(1000)
|
||||||
|
return adapter.logIn(userName, password)
|
||||||
},
|
},
|
||||||
assertion: (response: any) =>
|
assertion: (response: any) =>
|
||||||
response && response.isLoggedIn && response.userName === userName
|
response && response.isLoggedIn && response.userName === userName
|
||||||
@@ -77,8 +66,8 @@ export const basicTests = (
|
|||||||
'common/sendArr',
|
'common/sendArr',
|
||||||
stringData,
|
stringData,
|
||||||
undefined,
|
undefined,
|
||||||
async () => {
|
() => {
|
||||||
await adapter.logIn(userName, password)
|
adapter.logIn(userName, password)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -164,7 +153,10 @@ export const basicTests = (
|
|||||||
description:
|
description:
|
||||||
'Should complete successful request with extra attributes present in response',
|
'Should complete successful request with extra attributes present in response',
|
||||||
test: async () => {
|
test: async () => {
|
||||||
const config: Partial<SASjsConfig> = {
|
if (adapter.getSasjsConfig().serverType !== 'SASVIYA')
|
||||||
|
return Promise.resolve('skip')
|
||||||
|
|
||||||
|
const config = {
|
||||||
useComputeApi: false
|
useComputeApi: false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,9 +170,15 @@ export const basicTests = (
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
assertion: (response: any) => {
|
assertion: (response: any) => {
|
||||||
|
if (response === 'skip') return true
|
||||||
|
|
||||||
const responseKeys: any = Object.keys(response)
|
const responseKeys: any = Object.keys(response)
|
||||||
return responseKeys.includes('file') && responseKeys.includes('data')
|
return responseKeys.includes('file') && responseKeys.includes('data')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const sleep = (ms: number) => {
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, ms))
|
||||||
|
}
|
||||||
|
|||||||
101
src/FileUploader.ts
Normal file
101
src/FileUploader.ts
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
import { isUrl, getValidJson, parseSasViyaDebugResponse } from './utils'
|
||||||
|
import { UploadFile } from './types/UploadFile'
|
||||||
|
import { ErrorResponse, LoginRequiredError } from './types/errors'
|
||||||
|
import { RequestClient } from './request/RequestClient'
|
||||||
|
import { ServerType } from '@sasjs/utils/types'
|
||||||
|
import SASjs from './SASjs'
|
||||||
|
import { Server } from 'https'
|
||||||
|
import { SASjsConfig } from './types'
|
||||||
|
import { config } from 'process'
|
||||||
|
|
||||||
|
export class FileUploader {
|
||||||
|
constructor(
|
||||||
|
private sasjsConfig: SASjsConfig,
|
||||||
|
private jobsPath: string,
|
||||||
|
private requestClient: RequestClient
|
||||||
|
) {
|
||||||
|
if (this.sasjsConfig.serverUrl) isUrl(this.sasjsConfig.serverUrl)
|
||||||
|
}
|
||||||
|
|
||||||
|
public uploadFile(sasJob: string, files: UploadFile[], params: any) {
|
||||||
|
if (files?.length < 1)
|
||||||
|
return Promise.reject(
|
||||||
|
new ErrorResponse('At least one file must be provided.')
|
||||||
|
)
|
||||||
|
if (!sasJob || sasJob === '')
|
||||||
|
return Promise.reject(new ErrorResponse('sasJob must be provided.'))
|
||||||
|
|
||||||
|
let paramsString = ''
|
||||||
|
|
||||||
|
for (let param in params) {
|
||||||
|
if (params.hasOwnProperty(param)) {
|
||||||
|
paramsString += `&${param}=${params[param]}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const program = this.sasjsConfig.appLoc
|
||||||
|
? this.sasjsConfig.appLoc.replace(/\/?$/, '/') + sasJob.replace(/^\//, '')
|
||||||
|
: sasJob
|
||||||
|
const uploadUrl = `${this.jobsPath}/?${
|
||||||
|
'_program=' + program
|
||||||
|
}${paramsString}`
|
||||||
|
|
||||||
|
const formData = new FormData()
|
||||||
|
|
||||||
|
for (let file of files) {
|
||||||
|
formData.append('file', file.file, file.fileName)
|
||||||
|
}
|
||||||
|
|
||||||
|
const csrfToken = this.requestClient.getCsrfToken('file')
|
||||||
|
if (csrfToken) formData.append('_csrf', csrfToken.value)
|
||||||
|
if (this.sasjsConfig.debug) formData.append('_debug', '131')
|
||||||
|
if (
|
||||||
|
this.sasjsConfig.serverType === ServerType.SasViya &&
|
||||||
|
this.sasjsConfig.contextName
|
||||||
|
)
|
||||||
|
formData.append('_contextname', this.sasjsConfig.contextName)
|
||||||
|
|
||||||
|
const headers = {
|
||||||
|
'cache-control': 'no-cache',
|
||||||
|
Accept: '*/*',
|
||||||
|
'Content-Type': 'text/plain'
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.requestClient
|
||||||
|
.post(uploadUrl, formData, undefined, 'application/json', headers)
|
||||||
|
.then(async (res) => {
|
||||||
|
// for web approach on Viya
|
||||||
|
if (
|
||||||
|
this.sasjsConfig.debug &&
|
||||||
|
(this.sasjsConfig.useComputeApi === null ||
|
||||||
|
this.sasjsConfig.useComputeApi === undefined) &&
|
||||||
|
this.sasjsConfig.serverType === ServerType.SasViya
|
||||||
|
) {
|
||||||
|
const jsonResponse = await parseSasViyaDebugResponse(
|
||||||
|
res.result as string,
|
||||||
|
this.requestClient,
|
||||||
|
this.sasjsConfig.serverUrl
|
||||||
|
)
|
||||||
|
return typeof jsonResponse === 'string'
|
||||||
|
? getValidJson(jsonResponse)
|
||||||
|
: jsonResponse
|
||||||
|
}
|
||||||
|
|
||||||
|
return typeof res.result === 'string'
|
||||||
|
? getValidJson(res.result)
|
||||||
|
: res.result
|
||||||
|
|
||||||
|
//TODO: append to SASjs requests
|
||||||
|
})
|
||||||
|
.catch((err: Error) => {
|
||||||
|
if (err instanceof LoginRequiredError) {
|
||||||
|
return Promise.reject(
|
||||||
|
new ErrorResponse('You must be logged in to upload a file.', err)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return Promise.reject(
|
||||||
|
new ErrorResponse('File upload request failed.', err)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import * as https from 'https'
|
|
||||||
import { generateTimestamp } from '@sasjs/utils/time'
|
import { generateTimestamp } from '@sasjs/utils/time'
|
||||||
import * as NodeFormData from 'form-data'
|
import * as NodeFormData from 'form-data'
|
||||||
import { Sas9RequestClient } from './request/Sas9RequestClient'
|
import { Sas9RequestClient } from './request/Sas9RequestClient'
|
||||||
@@ -11,13 +10,9 @@ import { isUrl } from './utils'
|
|||||||
export class SAS9ApiClient {
|
export class SAS9ApiClient {
|
||||||
private requestClient: Sas9RequestClient
|
private requestClient: Sas9RequestClient
|
||||||
|
|
||||||
constructor(
|
constructor(private serverUrl: string, private jobsPath: string) {
|
||||||
private serverUrl: string,
|
|
||||||
private jobsPath: string,
|
|
||||||
httpsAgentOptions?: https.AgentOptions
|
|
||||||
) {
|
|
||||||
if (serverUrl) isUrl(serverUrl)
|
if (serverUrl) isUrl(serverUrl)
|
||||||
this.requestClient = new Sas9RequestClient(serverUrl, httpsAgentOptions)
|
this.requestClient = new Sas9RequestClient(serverUrl, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
import { Logger, LogLevel } from '@sasjs/utils/logger'
|
|
||||||
import { RequestClient } from './request/RequestClient'
|
|
||||||
import { SASViyaApiClient } from './SASViyaApiClient'
|
|
||||||
import { Folder } from './types'
|
|
||||||
import { RootFolderNotFoundError } from './types/errors'
|
|
||||||
|
|
||||||
const mockFolder: Folder = {
|
|
||||||
id: '1',
|
|
||||||
uri: '/folder',
|
|
||||||
links: [],
|
|
||||||
memberCount: 1
|
|
||||||
}
|
|
||||||
|
|
||||||
const requestClient = new (<jest.Mock<RequestClient>>RequestClient)()
|
|
||||||
const sasViyaApiClient = new SASViyaApiClient(
|
|
||||||
'https://test.com',
|
|
||||||
'/test',
|
|
||||||
'test context',
|
|
||||||
requestClient
|
|
||||||
)
|
|
||||||
|
|
||||||
describe('SASViyaApiClient', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
;(process as any).logger = new Logger(LogLevel.Off)
|
|
||||||
setupMocks()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should throw an error when the root folder is not found on the server', async () => {
|
|
||||||
jest
|
|
||||||
.spyOn(requestClient, 'get')
|
|
||||||
.mockImplementation(() => Promise.reject('Not Found'))
|
|
||||||
const error = await sasViyaApiClient
|
|
||||||
.createFolder('test', '/foo')
|
|
||||||
.catch((e) => e)
|
|
||||||
expect(error).toBeInstanceOf(RootFolderNotFoundError)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
const setupMocks = () => {
|
|
||||||
jest
|
|
||||||
.spyOn(requestClient, 'get')
|
|
||||||
.mockImplementation(() =>
|
|
||||||
Promise.resolve({ result: mockFolder, etag: '', status: 200 })
|
|
||||||
)
|
|
||||||
|
|
||||||
jest
|
|
||||||
.spyOn(requestClient, 'post')
|
|
||||||
.mockImplementation(() =>
|
|
||||||
Promise.resolve({ result: mockFolder, etag: '', status: 200 })
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
JobDefinition,
|
JobDefinition,
|
||||||
PollOptions
|
PollOptions
|
||||||
} from './types'
|
} from './types'
|
||||||
import { JobExecutionError, RootFolderNotFoundError } from './types/errors'
|
import { JobExecutionError } from './types/errors'
|
||||||
import { SessionManager } from './SessionManager'
|
import { SessionManager } from './SessionManager'
|
||||||
import { ContextManager } from './ContextManager'
|
import { ContextManager } from './ContextManager'
|
||||||
import { SasAuthResponse, MacroVar, AuthConfig } from '@sasjs/utils/types'
|
import { SasAuthResponse, MacroVar, AuthConfig } from '@sasjs/utils/types'
|
||||||
@@ -22,8 +22,8 @@ import { pollJobState } from './api/viya/pollJobState'
|
|||||||
import { getTokens } from './auth/getTokens'
|
import { getTokens } from './auth/getTokens'
|
||||||
import { uploadTables } from './api/viya/uploadTables'
|
import { uploadTables } from './api/viya/uploadTables'
|
||||||
import { executeScript } from './api/viya/executeScript'
|
import { executeScript } from './api/viya/executeScript'
|
||||||
import { getAccessTokenForViya } from './auth/getAccessTokenForViya'
|
import { getAccessToken } from './auth/getAccessToken'
|
||||||
import { refreshTokensForViya } from './auth/refreshTokensForViya'
|
import { refreshTokens } from './auth/refreshTokens'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A client for interfacing with the SAS Viya REST API.
|
* A client for interfacing with the SAS Viya REST API.
|
||||||
@@ -51,16 +51,6 @@ export class SASViyaApiClient {
|
|||||||
)
|
)
|
||||||
private folderMap = new Map<string, Job[]>()
|
private folderMap = new Map<string, Job[]>()
|
||||||
|
|
||||||
/**
|
|
||||||
* A helper method used to call appendRequest method of RequestClient
|
|
||||||
* @param response - response from sasjs request
|
|
||||||
* @param program - name of program
|
|
||||||
* @param debug - a boolean that indicates whether debug was enabled or not
|
|
||||||
*/
|
|
||||||
public appendRequest(response: any, program: string, debug: boolean) {
|
|
||||||
this.requestClient!.appendRequest(response, program, debug)
|
|
||||||
}
|
|
||||||
|
|
||||||
public get debug() {
|
public get debug() {
|
||||||
return this._debug
|
return this._debug
|
||||||
}
|
}
|
||||||
@@ -391,11 +381,7 @@ export class SASViyaApiClient {
|
|||||||
)
|
)
|
||||||
const newFolderName = `${parentFolderPath.split('/').pop()}`
|
const newFolderName = `${parentFolderPath.split('/').pop()}`
|
||||||
if (newParentFolderPath === '') {
|
if (newParentFolderPath === '') {
|
||||||
throw new RootFolderNotFoundError(
|
throw new Error('Root folder has to be present on the server.')
|
||||||
parentFolderPath,
|
|
||||||
this.serverUrl,
|
|
||||||
accessToken
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
logger.info(
|
logger.info(
|
||||||
`Creating parent folder:\n'${newFolderName}' in '${newParentFolderPath}'`
|
`Creating parent folder:\n'${newFolderName}' in '${newParentFolderPath}'`
|
||||||
@@ -534,26 +520,21 @@ export class SASViyaApiClient {
|
|||||||
clientSecret: string,
|
clientSecret: string,
|
||||||
authCode: string
|
authCode: string
|
||||||
): Promise<SasAuthResponse> {
|
): Promise<SasAuthResponse> {
|
||||||
return getAccessTokenForViya(
|
return getAccessToken(this.requestClient, clientId, clientSecret, authCode)
|
||||||
this.requestClient,
|
|
||||||
clientId,
|
|
||||||
clientSecret,
|
|
||||||
authCode
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exchanges the refresh token for an access token for the given client.
|
* Exchanges the refresh token for an access token for the given client.
|
||||||
* @param clientId - the client ID to authenticate with.
|
* @param clientId - the client ID to authenticate with.
|
||||||
* @param clientSecret - the client secret to authenticate with.
|
* @param clientSecret - the client secret to authenticate with.
|
||||||
* @param refreshToken - the refresh token received from the server.
|
* @param authCode - the refresh token received from the server.
|
||||||
*/
|
*/
|
||||||
public async refreshTokens(
|
public async refreshTokens(
|
||||||
clientId: string,
|
clientId: string,
|
||||||
clientSecret: string,
|
clientSecret: string,
|
||||||
refreshToken: string
|
refreshToken: string
|
||||||
) {
|
) {
|
||||||
return refreshTokensForViya(
|
return refreshTokens(
|
||||||
this.requestClient,
|
this.requestClient,
|
||||||
clientId,
|
clientId,
|
||||||
clientSecret,
|
clientSecret,
|
||||||
|
|||||||
269
src/SASjs.ts
269
src/SASjs.ts
@@ -1,41 +1,27 @@
|
|||||||
import { compareTimestamps, asyncForEach } from './utils'
|
import { compareTimestamps, asyncForEach } from './utils'
|
||||||
import {
|
import { SASjsConfig, UploadFile, EditContextInput, PollOptions } from './types'
|
||||||
SASjsConfig,
|
|
||||||
UploadFile,
|
|
||||||
EditContextInput,
|
|
||||||
PollOptions,
|
|
||||||
LoginMechanism,
|
|
||||||
FolderMember,
|
|
||||||
ServiceMember,
|
|
||||||
ExecutionQuery
|
|
||||||
} from './types'
|
|
||||||
import { SASViyaApiClient } from './SASViyaApiClient'
|
import { SASViyaApiClient } from './SASViyaApiClient'
|
||||||
import { SAS9ApiClient } from './SAS9ApiClient'
|
import { SAS9ApiClient } from './SAS9ApiClient'
|
||||||
import { SASjsApiClient, SASjsAuthResponse } from './SASjsApiClient'
|
import { FileUploader } from './FileUploader'
|
||||||
import { AuthManager } from './auth'
|
import { AuthManager } from './auth'
|
||||||
import {
|
import {
|
||||||
ServerType,
|
ServerType,
|
||||||
MacroVar,
|
MacroVar,
|
||||||
AuthConfig,
|
AuthConfig,
|
||||||
ExtraResponseAttributes,
|
ExtraResponseAttributes
|
||||||
SasAuthResponse
|
|
||||||
} from '@sasjs/utils/types'
|
} from '@sasjs/utils/types'
|
||||||
import { RequestClient } from './request/RequestClient'
|
import { RequestClient } from './request/RequestClient'
|
||||||
import { SasjsRequestClient } from './request/SasjsRequestClient'
|
|
||||||
import {
|
import {
|
||||||
JobExecutor,
|
JobExecutor,
|
||||||
WebJobExecutor,
|
WebJobExecutor,
|
||||||
ComputeJobExecutor,
|
ComputeJobExecutor,
|
||||||
JesJobExecutor,
|
JesJobExecutor,
|
||||||
Sas9JobExecutor,
|
Sas9JobExecutor
|
||||||
FileUploader
|
|
||||||
} from './job-execution'
|
} from './job-execution'
|
||||||
import { ErrorResponse } from './types/errors'
|
import { ErrorResponse } from './types/errors'
|
||||||
import { LoginOptions, LoginResult } from './types/Login'
|
|
||||||
|
|
||||||
const defaultConfig: SASjsConfig = {
|
const defaultConfig: SASjsConfig = {
|
||||||
serverUrl: '',
|
serverUrl: '',
|
||||||
pathSASJS: '/SASjsApi/stp/execute',
|
|
||||||
pathSAS9: '/SASStoredProcess/do',
|
pathSAS9: '/SASStoredProcess/do',
|
||||||
pathSASViya: '/SASJobExecution',
|
pathSASViya: '/SASJobExecution',
|
||||||
appLoc: '/Public/seedapp',
|
appLoc: '/Public/seedapp',
|
||||||
@@ -43,7 +29,7 @@ const defaultConfig: SASjsConfig = {
|
|||||||
debug: false,
|
debug: false,
|
||||||
contextName: 'SAS Job Execution compute context',
|
contextName: 'SAS Job Execution compute context',
|
||||||
useComputeApi: null,
|
useComputeApi: null,
|
||||||
loginMechanism: LoginMechanism.Default
|
allowInsecureRequests: false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,7 +41,6 @@ export default class SASjs {
|
|||||||
private jobsPath: string = ''
|
private jobsPath: string = ''
|
||||||
private sasViyaApiClient: SASViyaApiClient | null = null
|
private sasViyaApiClient: SASViyaApiClient | null = null
|
||||||
private sas9ApiClient: SAS9ApiClient | null = null
|
private sas9ApiClient: SAS9ApiClient | null = null
|
||||||
private sasJSApiClient: SASjsApiClient | null = null
|
|
||||||
private fileUploader: FileUploader | null = null
|
private fileUploader: FileUploader | null = null
|
||||||
private authManager: AuthManager | null = null
|
private authManager: AuthManager | null = null
|
||||||
private requestClient: RequestClient | null = null
|
private requestClient: RequestClient | null = null
|
||||||
@@ -64,7 +49,7 @@ export default class SASjs {
|
|||||||
private jesJobExecutor: JobExecutor | null = null
|
private jesJobExecutor: JobExecutor | null = null
|
||||||
private sas9JobExecutor: JobExecutor | null = null
|
private sas9JobExecutor: JobExecutor | null = null
|
||||||
|
|
||||||
constructor(config?: Partial<SASjsConfig>) {
|
constructor(config?: any) {
|
||||||
this.sasjsConfig = {
|
this.sasjsConfig = {
|
||||||
...defaultConfig,
|
...defaultConfig,
|
||||||
...config
|
...config
|
||||||
@@ -82,7 +67,7 @@ export default class SASjs {
|
|||||||
userName: string,
|
userName: string,
|
||||||
password: string
|
password: string
|
||||||
) {
|
) {
|
||||||
this.isMethodSupported('executeScriptSAS9', [ServerType.Sas9])
|
this.isMethodSupported('executeScriptSAS9', ServerType.Sas9)
|
||||||
|
|
||||||
return await this.sas9ApiClient?.executeScript(
|
return await this.sas9ApiClient?.executeScript(
|
||||||
linesOfCode,
|
linesOfCode,
|
||||||
@@ -96,7 +81,7 @@ export default class SASjs {
|
|||||||
* @param accessToken - an access token for an authorized user.
|
* @param accessToken - an access token for an authorized user.
|
||||||
*/
|
*/
|
||||||
public async getComputeContexts(accessToken: string) {
|
public async getComputeContexts(accessToken: string) {
|
||||||
this.isMethodSupported('getComputeContexts', [ServerType.SasViya])
|
this.isMethodSupported('getComputeContexts', ServerType.SasViya)
|
||||||
|
|
||||||
return await this.sasViyaApiClient!.getComputeContexts(accessToken)
|
return await this.sasViyaApiClient!.getComputeContexts(accessToken)
|
||||||
}
|
}
|
||||||
@@ -106,7 +91,7 @@ export default class SASjs {
|
|||||||
* @param accessToken - an access token for an authorized user.
|
* @param accessToken - an access token for an authorized user.
|
||||||
*/
|
*/
|
||||||
public async getLauncherContexts(accessToken: string) {
|
public async getLauncherContexts(accessToken: string) {
|
||||||
this.isMethodSupported('getLauncherContexts', [ServerType.SasViya])
|
this.isMethodSupported('getLauncherContexts', ServerType.SasViya)
|
||||||
|
|
||||||
return await this.sasViyaApiClient!.getLauncherContexts(accessToken)
|
return await this.sasViyaApiClient!.getLauncherContexts(accessToken)
|
||||||
}
|
}
|
||||||
@@ -115,7 +100,7 @@ export default class SASjs {
|
|||||||
* Gets default(system) launcher contexts.
|
* Gets default(system) launcher contexts.
|
||||||
*/
|
*/
|
||||||
public getDefaultComputeContexts() {
|
public getDefaultComputeContexts() {
|
||||||
this.isMethodSupported('getDefaultComputeContexts', [ServerType.SasViya])
|
this.isMethodSupported('getDefaultComputeContexts', ServerType.SasViya)
|
||||||
|
|
||||||
return this.sasViyaApiClient!.getDefaultComputeContexts()
|
return this.sasViyaApiClient!.getDefaultComputeContexts()
|
||||||
}
|
}
|
||||||
@@ -125,7 +110,7 @@ export default class SASjs {
|
|||||||
* @param authConfig - an access token, refresh token, client and secret for an authorized user.
|
* @param authConfig - an access token, refresh token, client and secret for an authorized user.
|
||||||
*/
|
*/
|
||||||
public async getExecutableContexts(authConfig: AuthConfig) {
|
public async getExecutableContexts(authConfig: AuthConfig) {
|
||||||
this.isMethodSupported('getExecutableContexts', [ServerType.SasViya])
|
this.isMethodSupported('getExecutableContexts', ServerType.SasViya)
|
||||||
|
|
||||||
return await this.sasViyaApiClient!.getExecutableContexts(authConfig)
|
return await this.sasViyaApiClient!.getExecutableContexts(authConfig)
|
||||||
}
|
}
|
||||||
@@ -147,7 +132,7 @@ export default class SASjs {
|
|||||||
accessToken: string,
|
accessToken: string,
|
||||||
authorizedUsers?: string[]
|
authorizedUsers?: string[]
|
||||||
) {
|
) {
|
||||||
this.isMethodSupported('createComputeContext', [ServerType.SasViya])
|
this.isMethodSupported('createComputeContext', ServerType.SasViya)
|
||||||
|
|
||||||
return await this.sasViyaApiClient!.createComputeContext(
|
return await this.sasViyaApiClient!.createComputeContext(
|
||||||
contextName,
|
contextName,
|
||||||
@@ -172,7 +157,7 @@ export default class SASjs {
|
|||||||
launchType: string,
|
launchType: string,
|
||||||
accessToken: string
|
accessToken: string
|
||||||
) {
|
) {
|
||||||
this.isMethodSupported('createLauncherContext', [ServerType.SasViya])
|
this.isMethodSupported('createLauncherContext', ServerType.SasViya)
|
||||||
|
|
||||||
return await this.sasViyaApiClient!.createLauncherContext(
|
return await this.sasViyaApiClient!.createLauncherContext(
|
||||||
contextName,
|
contextName,
|
||||||
@@ -193,7 +178,7 @@ export default class SASjs {
|
|||||||
editedContext: EditContextInput,
|
editedContext: EditContextInput,
|
||||||
accessToken?: string
|
accessToken?: string
|
||||||
) {
|
) {
|
||||||
this.isMethodSupported('editComputeContext', [ServerType.SasViya])
|
this.isMethodSupported('editComputeContext', ServerType.SasViya)
|
||||||
|
|
||||||
return await this.sasViyaApiClient!.editComputeContext(
|
return await this.sasViyaApiClient!.editComputeContext(
|
||||||
contextName,
|
contextName,
|
||||||
@@ -208,7 +193,7 @@ export default class SASjs {
|
|||||||
* @param accessToken - an access token for an authorized user.
|
* @param accessToken - an access token for an authorized user.
|
||||||
*/
|
*/
|
||||||
public async deleteComputeContext(contextName: string, accessToken?: string) {
|
public async deleteComputeContext(contextName: string, accessToken?: string) {
|
||||||
this.isMethodSupported('deleteComputeContext', [ServerType.SasViya])
|
this.isMethodSupported('deleteComputeContext', ServerType.SasViya)
|
||||||
|
|
||||||
return await this.sasViyaApiClient!.deleteComputeContext(
|
return await this.sasViyaApiClient!.deleteComputeContext(
|
||||||
contextName,
|
contextName,
|
||||||
@@ -226,7 +211,7 @@ export default class SASjs {
|
|||||||
contextName: string,
|
contextName: string,
|
||||||
accessToken?: string
|
accessToken?: string
|
||||||
) {
|
) {
|
||||||
this.isMethodSupported('getComputeContextByName', [ServerType.SasViya])
|
this.isMethodSupported('getComputeContextByName', ServerType.SasViya)
|
||||||
|
|
||||||
return await this.sasViyaApiClient!.getComputeContextByName(
|
return await this.sasViyaApiClient!.getComputeContextByName(
|
||||||
contextName,
|
contextName,
|
||||||
@@ -240,7 +225,7 @@ export default class SASjs {
|
|||||||
* @param accessToken - an access token for an authorized user.
|
* @param accessToken - an access token for an authorized user.
|
||||||
*/
|
*/
|
||||||
public async getComputeContextById(contextId: string, accessToken?: string) {
|
public async getComputeContextById(contextId: string, accessToken?: string) {
|
||||||
this.isMethodSupported('getComputeContextById', [ServerType.SasViya])
|
this.isMethodSupported('getComputeContextById', ServerType.SasViya)
|
||||||
|
|
||||||
return await this.sasViyaApiClient!.getComputeContextById(
|
return await this.sasViyaApiClient!.getComputeContextById(
|
||||||
contextId,
|
contextId,
|
||||||
@@ -249,7 +234,7 @@ export default class SASjs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async createSession(contextName: string, accessToken: string) {
|
public async createSession(contextName: string, accessToken: string) {
|
||||||
this.isMethodSupported('createSession', [ServerType.SasViya])
|
this.isMethodSupported('createSession', ServerType.SasViya)
|
||||||
|
|
||||||
return await this.sasViyaApiClient!.createSession(contextName, accessToken)
|
return await this.sasViyaApiClient!.createSession(contextName, accessToken)
|
||||||
}
|
}
|
||||||
@@ -269,7 +254,7 @@ export default class SASjs {
|
|||||||
authConfig?: AuthConfig,
|
authConfig?: AuthConfig,
|
||||||
debug?: boolean
|
debug?: boolean
|
||||||
) {
|
) {
|
||||||
this.isMethodSupported('executeScriptSASViya', [ServerType.SasViya])
|
this.isMethodSupported('executeScriptSASViya', ServerType.SasViya)
|
||||||
if (!contextName) {
|
if (!contextName) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Context name is undefined. Please set a `contextName` in your SASjs or override config.'
|
'Context name is undefined. Please set a `contextName` in your SASjs or override config.'
|
||||||
@@ -359,7 +344,7 @@ export default class SASjs {
|
|||||||
* @param accessToken - the access token to authorize the request.
|
* @param accessToken - the access token to authorize the request.
|
||||||
*/
|
*/
|
||||||
public async getFolder(folderPath: string, accessToken?: string) {
|
public async getFolder(folderPath: string, accessToken?: string) {
|
||||||
this.isMethodSupported('getFolder', [ServerType.SasViya])
|
this.isMethodSupported('getFolder', ServerType.SasViya)
|
||||||
return await this.sasViyaApiClient!.getFolder(folderPath, accessToken)
|
return await this.sasViyaApiClient!.getFolder(folderPath, accessToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,7 +354,7 @@ export default class SASjs {
|
|||||||
* @param accessToken - an access token for authorizing the request.
|
* @param accessToken - an access token for authorizing the request.
|
||||||
*/
|
*/
|
||||||
public async deleteFolder(folderPath: string, accessToken: string) {
|
public async deleteFolder(folderPath: string, accessToken: string) {
|
||||||
this.isMethodSupported('deleteFolder', [ServerType.SasViya])
|
this.isMethodSupported('deleteFolder', ServerType.SasViya)
|
||||||
|
|
||||||
return await this.sasViyaApiClient?.deleteFolder(folderPath, accessToken)
|
return await this.sasViyaApiClient?.deleteFolder(folderPath, accessToken)
|
||||||
}
|
}
|
||||||
@@ -384,7 +369,7 @@ export default class SASjs {
|
|||||||
accessToken?: string,
|
accessToken?: string,
|
||||||
limit?: number
|
limit?: number
|
||||||
) {
|
) {
|
||||||
this.isMethodSupported('listFolder', [ServerType.SasViya])
|
this.isMethodSupported('listFolder', ServerType.SasViya)
|
||||||
|
|
||||||
return await this.sasViyaApiClient?.listFolder(
|
return await this.sasViyaApiClient?.listFolder(
|
||||||
sourceFolder,
|
sourceFolder,
|
||||||
@@ -406,7 +391,7 @@ export default class SASjs {
|
|||||||
targetFolderName: string,
|
targetFolderName: string,
|
||||||
accessToken: string
|
accessToken: string
|
||||||
) {
|
) {
|
||||||
this.isMethodSupported('moveFolder', [ServerType.SasViya])
|
this.isMethodSupported('moveFolder', ServerType.SasViya)
|
||||||
|
|
||||||
return await this.sasViyaApiClient?.moveFolder(
|
return await this.sasViyaApiClient?.moveFolder(
|
||||||
sourceFolder,
|
sourceFolder,
|
||||||
@@ -424,7 +409,7 @@ export default class SASjs {
|
|||||||
accessToken?: string,
|
accessToken?: string,
|
||||||
sasApiClient?: SASViyaApiClient
|
sasApiClient?: SASViyaApiClient
|
||||||
) {
|
) {
|
||||||
this.isMethodSupported('createJobDefinition', [ServerType.SasViya])
|
this.isMethodSupported('createJobDefinition', ServerType.SasViya)
|
||||||
|
|
||||||
if (sasApiClient)
|
if (sasApiClient)
|
||||||
return await sasApiClient!.createJobDefinition(
|
return await sasApiClient!.createJobDefinition(
|
||||||
@@ -444,7 +429,7 @@ export default class SASjs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async getAuthCode(clientId: string) {
|
public async getAuthCode(clientId: string) {
|
||||||
this.isMethodSupported('getAuthCode', [ServerType.SasViya])
|
this.isMethodSupported('getAuthCode', ServerType.SasViya)
|
||||||
|
|
||||||
return await this.sasViyaApiClient!.getAuthCode(clientId)
|
return await this.sasViyaApiClient!.getAuthCode(clientId)
|
||||||
}
|
}
|
||||||
@@ -459,14 +444,8 @@ export default class SASjs {
|
|||||||
clientId: string,
|
clientId: string,
|
||||||
clientSecret: string,
|
clientSecret: string,
|
||||||
authCode: string
|
authCode: string
|
||||||
): Promise<SasAuthResponse | SASjsAuthResponse> {
|
) {
|
||||||
this.isMethodSupported('getAccessToken', [
|
this.isMethodSupported('getAccessToken', ServerType.SasViya)
|
||||||
ServerType.SasViya,
|
|
||||||
ServerType.Sasjs
|
|
||||||
])
|
|
||||||
|
|
||||||
if (this.sasjsConfig.serverType === ServerType.Sasjs)
|
|
||||||
return await this.sasJSApiClient!.getAccessToken(clientId, authCode)
|
|
||||||
|
|
||||||
return await this.sasViyaApiClient!.getAccessToken(
|
return await this.sasViyaApiClient!.getAccessToken(
|
||||||
clientId,
|
clientId,
|
||||||
@@ -475,24 +454,12 @@ export default class SASjs {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Exchanges the refresh token for an access token for the given client.
|
|
||||||
* @param clientId - the client ID to authenticate with.
|
|
||||||
* @param clientSecret - the client secret to authenticate with.
|
|
||||||
* @param refreshToken - the refresh token received from the server.
|
|
||||||
*/
|
|
||||||
public async refreshTokens(
|
public async refreshTokens(
|
||||||
clientId: string,
|
clientId: string,
|
||||||
clientSecret: string,
|
clientSecret: string,
|
||||||
refreshToken: string
|
refreshToken: string
|
||||||
): Promise<SasAuthResponse | SASjsAuthResponse> {
|
) {
|
||||||
this.isMethodSupported('refreshTokens', [
|
this.isMethodSupported('refreshTokens', ServerType.SasViya)
|
||||||
ServerType.SasViya,
|
|
||||||
ServerType.Sasjs
|
|
||||||
])
|
|
||||||
|
|
||||||
if (this.sasjsConfig.serverType === ServerType.Sasjs)
|
|
||||||
return await this.sasJSApiClient!.refreshTokens(refreshToken)
|
|
||||||
|
|
||||||
return await this.sasViyaApiClient!.refreshTokens(
|
return await this.sasViyaApiClient!.refreshTokens(
|
||||||
clientId,
|
clientId,
|
||||||
@@ -502,7 +469,7 @@ export default class SASjs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async deleteClient(clientId: string, accessToken: string) {
|
public async deleteClient(clientId: string, accessToken: string) {
|
||||||
this.isMethodSupported('deleteClient', [ServerType.SasViya])
|
this.isMethodSupported('deleteClient', ServerType.SasViya)
|
||||||
|
|
||||||
return await this.sasViyaApiClient!.deleteClient(clientId, accessToken)
|
return await this.sasViyaApiClient!.deleteClient(clientId, accessToken)
|
||||||
}
|
}
|
||||||
@@ -532,7 +499,7 @@ export default class SASjs {
|
|||||||
...this.sasjsConfig,
|
...this.sasjsConfig,
|
||||||
...config
|
...config
|
||||||
}
|
}
|
||||||
this.setupConfiguration()
|
await this.setupConfiguration()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -558,39 +525,9 @@ export default class SASjs {
|
|||||||
* Logs into the SAS server with the supplied credentials.
|
* Logs into the SAS server with the supplied credentials.
|
||||||
* @param username - a string representing the username.
|
* @param username - a string representing the username.
|
||||||
* @param password - a string representing the password.
|
* @param password - a string representing the password.
|
||||||
* @param clientId - a string representing the client ID.
|
|
||||||
*/
|
*/
|
||||||
public async logIn(
|
public async logIn(username: string, password: string) {
|
||||||
username?: string,
|
return this.authManager!.logIn(username, password)
|
||||||
password?: string,
|
|
||||||
clientId?: string,
|
|
||||||
options: LoginOptions = {}
|
|
||||||
): Promise<LoginResult> {
|
|
||||||
if (this.sasjsConfig.loginMechanism === LoginMechanism.Default) {
|
|
||||||
if (!username || !password)
|
|
||||||
throw new Error(
|
|
||||||
'A username and password are required when using the default login mechanism.'
|
|
||||||
)
|
|
||||||
|
|
||||||
if (this.sasjsConfig.serverType === ServerType.Sasjs) {
|
|
||||||
if (!clientId)
|
|
||||||
throw new Error(
|
|
||||||
'A username, password and clientId are required when using the default login mechanism with server type SASJS.'
|
|
||||||
)
|
|
||||||
|
|
||||||
return this.authManager!.logInSasjs(username, password, clientId)
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.authManager!.logIn(username, password)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof window === typeof undefined) {
|
|
||||||
throw new Error(
|
|
||||||
'The redirected login mechanism is only available for use in the browser.'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.authManager!.redirectedLogIn(options)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -607,32 +544,24 @@ export default class SASjs {
|
|||||||
* Process). Is prepended at runtime with the value of `appLoc`.
|
* Process). Is prepended at runtime with the value of `appLoc`.
|
||||||
* @param files - array of files to be uploaded, including File object and file name.
|
* @param files - array of files to be uploaded, including File object and file name.
|
||||||
* @param params - request URL parameters.
|
* @param params - request URL parameters.
|
||||||
* @param config - provide any changes to the config here, for instance to
|
* @param overrideSasjsConfig - object to override existing config (optional)
|
||||||
* enable/disable `debug`. Any change provided will override the global config,
|
|
||||||
* for that particular function call.
|
|
||||||
* @param loginRequiredCallback - a function that is called if the
|
|
||||||
* user is not logged in (eg to display a login form). The request will be
|
|
||||||
* resubmitted after successful login.
|
|
||||||
*/
|
*/
|
||||||
public async uploadFile(
|
public uploadFile(
|
||||||
sasJob: string,
|
sasJob: string,
|
||||||
files: UploadFile[],
|
files: UploadFile[],
|
||||||
params: { [key: string]: any } | null,
|
params: any,
|
||||||
config: { [key: string]: any } = {},
|
overrideSasjsConfig?: any
|
||||||
loginRequiredCallback?: () => any
|
|
||||||
) {
|
) {
|
||||||
config = {
|
const fileUploader = overrideSasjsConfig
|
||||||
...this.sasjsConfig,
|
? new FileUploader(
|
||||||
...config
|
{ ...this.sasjsConfig, ...overrideSasjsConfig },
|
||||||
}
|
this.jobsPath,
|
||||||
const data = { files, params }
|
this.requestClient!
|
||||||
|
)
|
||||||
|
: this.fileUploader ||
|
||||||
|
new FileUploader(this.sasjsConfig, this.jobsPath, this.requestClient!)
|
||||||
|
|
||||||
return await this.fileUploader!.execute(
|
return fileUploader.uploadFile(sasJob, files, params)
|
||||||
sasJob,
|
|
||||||
data,
|
|
||||||
config,
|
|
||||||
loginRequiredCallback
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -690,11 +619,6 @@ export default class SASjs {
|
|||||||
authConfig
|
authConfig
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
if (!config.contextName)
|
|
||||||
config = {
|
|
||||||
...config,
|
|
||||||
contextName: 'SAS Job Execution compute context'
|
|
||||||
}
|
|
||||||
return await this.jesJobExecutor!.execute(
|
return await this.jesJobExecutor!.execute(
|
||||||
sasJob,
|
sasJob,
|
||||||
data,
|
data,
|
||||||
@@ -806,7 +730,7 @@ export default class SASjs {
|
|||||||
accessToken?: string,
|
accessToken?: string,
|
||||||
isForced = false
|
isForced = false
|
||||||
) {
|
) {
|
||||||
this.isMethodSupported('deployServicePack', [ServerType.SasViya])
|
this.isMethodSupported('deployServicePack', ServerType.SasViya)
|
||||||
|
|
||||||
let sasApiClient: any = null
|
let sasApiClient: any = null
|
||||||
if (serverUrl || appLoc) {
|
if (serverUrl || appLoc) {
|
||||||
@@ -825,11 +749,7 @@ export default class SASjs {
|
|||||||
)
|
)
|
||||||
sasApiClient.debug = this.sasjsConfig.debug
|
sasApiClient.debug = this.sasjsConfig.debug
|
||||||
} else if (this.sasjsConfig.serverType === ServerType.Sas9) {
|
} else if (this.sasjsConfig.serverType === ServerType.Sas9) {
|
||||||
sasApiClient = new SAS9ApiClient(
|
sasApiClient = new SAS9ApiClient(serverUrl, this.jobsPath)
|
||||||
serverUrl,
|
|
||||||
this.jobsPath,
|
|
||||||
this.sasjsConfig.httpsAgentOptions
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let sasClientConfig: any = null
|
let sasClientConfig: any = null
|
||||||
@@ -860,14 +780,6 @@ export default class SASjs {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deployToSASjs(members: [FolderMember, ServiceMember]) {
|
|
||||||
return await this.sasJSApiClient?.deploy(members, this.sasjsConfig.appLoc)
|
|
||||||
}
|
|
||||||
|
|
||||||
public async executeJobSASjs(query: ExecutionQuery) {
|
|
||||||
return await this.sasJSApiClient?.executeJob(query)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kicks off execution of the given job via the compute API.
|
* Kicks off execution of the given job via the compute API.
|
||||||
* @returns an object representing the compute session created for the given job.
|
* @returns an object representing the compute session created for the given job.
|
||||||
@@ -901,7 +813,7 @@ export default class SASjs {
|
|||||||
...config
|
...config
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isMethodSupported('startComputeJob', [ServerType.SasViya])
|
this.isMethodSupported('startComputeJob', ServerType.SasViya)
|
||||||
if (!config.contextName) {
|
if (!config.contextName) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Context name is undefined. Please set a `contextName` in your SASjs or override config.'
|
'Context name is undefined. Please set a `contextName` in your SASjs or override config.'
|
||||||
@@ -926,7 +838,6 @@ export default class SASjs {
|
|||||||
await this.webJobExecutor?.resendWaitingRequests()
|
await this.webJobExecutor?.resendWaitingRequests()
|
||||||
await this.computeJobExecutor?.resendWaitingRequests()
|
await this.computeJobExecutor?.resendWaitingRequests()
|
||||||
await this.jesJobExecutor?.resendWaitingRequests()
|
await this.jesJobExecutor?.resendWaitingRequests()
|
||||||
await this.fileUploader?.resendWaitingRequests()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -958,18 +869,20 @@ export default class SASjs {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* this method returns an array of SASjsRequest
|
|
||||||
* @returns SASjsRequest[]
|
|
||||||
*/
|
|
||||||
public getSasRequests() {
|
public getSasRequests() {
|
||||||
const requests = [...this.requestClient!.getRequests()]
|
const requests = [
|
||||||
|
...this.webJobExecutor!.getRequests(),
|
||||||
|
...this.computeJobExecutor!.getRequests(),
|
||||||
|
...this.jesJobExecutor!.getRequests()
|
||||||
|
]
|
||||||
const sortedRequests = requests.sort(compareTimestamps)
|
const sortedRequests = requests.sort(compareTimestamps)
|
||||||
return sortedRequests
|
return sortedRequests
|
||||||
}
|
}
|
||||||
|
|
||||||
public clearSasRequests() {
|
public clearSasRequests() {
|
||||||
this.requestClient!.clearRequests()
|
this.webJobExecutor!.clearRequests()
|
||||||
|
this.computeJobExecutor!.clearRequests()
|
||||||
|
this.jesJobExecutor!.clearRequests()
|
||||||
}
|
}
|
||||||
|
|
||||||
private setupConfiguration() {
|
private setupConfiguration() {
|
||||||
@@ -992,28 +905,15 @@ export default class SASjs {
|
|||||||
this.sasjsConfig.serverUrl = this.sasjsConfig.serverUrl.slice(0, -1)
|
this.sasjsConfig.serverUrl = this.sasjsConfig.serverUrl.slice(0, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.requestClient) {
|
this.requestClient = new RequestClient(
|
||||||
const RequestClientClass =
|
this.sasjsConfig.serverUrl,
|
||||||
this.sasjsConfig.serverType === ServerType.Sasjs
|
this.sasjsConfig.allowInsecureRequests
|
||||||
? SasjsRequestClient
|
)
|
||||||
: RequestClient
|
|
||||||
this.requestClient = new RequestClientClass(
|
|
||||||
this.sasjsConfig.serverUrl,
|
|
||||||
this.sasjsConfig.httpsAgentOptions
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
this.requestClient.setConfig(
|
|
||||||
this.sasjsConfig.serverUrl,
|
|
||||||
this.sasjsConfig.httpsAgentOptions
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.jobsPath =
|
this.jobsPath =
|
||||||
this.sasjsConfig.serverType === ServerType.SasViya
|
this.sasjsConfig.serverType === ServerType.SasViya
|
||||||
? this.sasjsConfig.pathSASViya
|
? this.sasjsConfig.pathSASViya
|
||||||
: this.sasjsConfig.serverType === ServerType.Sas9
|
: this.sasjsConfig.pathSAS9
|
||||||
? this.sasjsConfig.pathSAS9
|
|
||||||
: this.sasjsConfig.pathSASJS || ''
|
|
||||||
|
|
||||||
this.authManager = new AuthManager(
|
this.authManager = new AuthManager(
|
||||||
this.sasjsConfig.serverUrl,
|
this.sasjsConfig.serverUrl,
|
||||||
@@ -1023,49 +923,33 @@ export default class SASjs {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (this.sasjsConfig.serverType === ServerType.SasViya) {
|
if (this.sasjsConfig.serverType === ServerType.SasViya) {
|
||||||
if (this.sasViyaApiClient) {
|
if (this.sasViyaApiClient)
|
||||||
this.sasViyaApiClient!.setConfig(
|
this.sasViyaApiClient!.setConfig(
|
||||||
this.sasjsConfig.serverUrl,
|
this.sasjsConfig.serverUrl,
|
||||||
this.sasjsConfig.appLoc
|
this.sasjsConfig.appLoc
|
||||||
)
|
)
|
||||||
} else {
|
else
|
||||||
this.sasViyaApiClient = new SASViyaApiClient(
|
this.sasViyaApiClient = new SASViyaApiClient(
|
||||||
this.sasjsConfig.serverUrl,
|
this.sasjsConfig.serverUrl,
|
||||||
this.sasjsConfig.appLoc,
|
this.sasjsConfig.appLoc,
|
||||||
this.sasjsConfig.contextName,
|
this.sasjsConfig.contextName,
|
||||||
this.requestClient
|
this.requestClient
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
this.sasViyaApiClient.debug = this.sasjsConfig.debug
|
this.sasViyaApiClient.debug = this.sasjsConfig.debug
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.sasjsConfig.serverType === ServerType.Sas9) {
|
if (this.sasjsConfig.serverType === ServerType.Sas9) {
|
||||||
if (this.sas9ApiClient) {
|
if (this.sas9ApiClient)
|
||||||
this.sas9ApiClient!.setConfig(this.sasjsConfig.serverUrl)
|
this.sas9ApiClient!.setConfig(this.sasjsConfig.serverUrl)
|
||||||
} else {
|
else
|
||||||
this.sas9ApiClient = new SAS9ApiClient(
|
this.sas9ApiClient = new SAS9ApiClient(
|
||||||
this.sasjsConfig.serverUrl,
|
this.sasjsConfig.serverUrl,
|
||||||
this.jobsPath,
|
this.jobsPath
|
||||||
this.sasjsConfig.httpsAgentOptions
|
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.sasjsConfig.serverType === ServerType.Sasjs) {
|
|
||||||
if (this.sasJSApiClient) {
|
|
||||||
this.sasJSApiClient.setConfig(this.sasjsConfig.serverUrl)
|
|
||||||
} else {
|
|
||||||
this.sasJSApiClient = new SASjsApiClient(
|
|
||||||
this.sasjsConfig.serverUrl,
|
|
||||||
this.requestClient
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.fileUploader = new FileUploader(
|
this.fileUploader = new FileUploader(
|
||||||
this.sasjsConfig.serverUrl,
|
this.sasjsConfig,
|
||||||
this.sasjsConfig.serverType!,
|
|
||||||
this.jobsPath,
|
this.jobsPath,
|
||||||
this.requestClient
|
this.requestClient
|
||||||
)
|
)
|
||||||
@@ -1081,9 +965,7 @@ export default class SASjs {
|
|||||||
this.sas9JobExecutor = new Sas9JobExecutor(
|
this.sas9JobExecutor = new Sas9JobExecutor(
|
||||||
this.sasjsConfig.serverUrl,
|
this.sasjsConfig.serverUrl,
|
||||||
this.sasjsConfig.serverType!,
|
this.sasjsConfig.serverType!,
|
||||||
this.jobsPath,
|
this.jobsPath
|
||||||
this.requestClient,
|
|
||||||
this.sasjsConfig.httpsAgentOptions
|
|
||||||
)
|
)
|
||||||
|
|
||||||
this.computeJobExecutor = new ComputeJobExecutor(
|
this.computeJobExecutor = new ComputeJobExecutor(
|
||||||
@@ -1150,15 +1032,12 @@ export default class SASjs {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private isMethodSupported(method: string, serverTypes: ServerType[]) {
|
private isMethodSupported(method: string, serverType: string) {
|
||||||
if (
|
if (this.sasjsConfig.serverType !== serverType) {
|
||||||
!this.sasjsConfig.serverType ||
|
|
||||||
!serverTypes.includes(this.sasjsConfig.serverType)
|
|
||||||
) {
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Method '${method}' is only supported on ${serverTypes.join(
|
`Method '${method}' is only supported on ${
|
||||||
', '
|
serverType === ServerType.Sas9 ? 'SAS9' : 'SAS Viya'
|
||||||
)} servers.`
|
} servers.`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
import { FolderMember, ServiceMember, ExecutionQuery } from './types'
|
|
||||||
import { RequestClient } from './request/RequestClient'
|
|
||||||
import { getAccessTokenForSasjs } from './auth/getAccessTokenForSasjs'
|
|
||||||
import { refreshTokensForSasjs } from './auth/refreshTokensForSasjs'
|
|
||||||
import { getAuthCodeForSasjs } from './auth/getAuthCodeForSasjs'
|
|
||||||
|
|
||||||
export class SASjsApiClient {
|
|
||||||
constructor(
|
|
||||||
private serverUrl: string,
|
|
||||||
private requestClient: RequestClient
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public setConfig(serverUrl: string) {
|
|
||||||
if (serverUrl) this.serverUrl = serverUrl
|
|
||||||
}
|
|
||||||
|
|
||||||
public async deploy(members: [FolderMember, ServiceMember], appLoc: string) {
|
|
||||||
const { result } = await this.requestClient.post<{
|
|
||||||
status: string
|
|
||||||
message: string
|
|
||||||
example?: {}
|
|
||||||
}>(
|
|
||||||
'SASjsApi/drive/deploy',
|
|
||||||
{ fileTree: members, appLoc: appLoc },
|
|
||||||
undefined
|
|
||||||
)
|
|
||||||
|
|
||||||
return Promise.resolve(result)
|
|
||||||
}
|
|
||||||
|
|
||||||
public async executeJob(query: ExecutionQuery) {
|
|
||||||
const { result } = await this.requestClient.post<{
|
|
||||||
status: string
|
|
||||||
message: string
|
|
||||||
log?: string
|
|
||||||
logPath?: string
|
|
||||||
error?: {}
|
|
||||||
}>('SASjsApi/stp/execute', query, undefined)
|
|
||||||
|
|
||||||
return Promise.resolve(result)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exchanges the auth code for an access token for the given client.
|
|
||||||
* @param clientId - the client ID to authenticate with.
|
|
||||||
* @param authCode - the auth code received from the server.
|
|
||||||
*/
|
|
||||||
public async getAccessToken(
|
|
||||||
clientId: string,
|
|
||||||
authCode: string
|
|
||||||
): Promise<SASjsAuthResponse> {
|
|
||||||
return getAccessTokenForSasjs(this.requestClient, clientId, authCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exchanges the refresh token for an access token.
|
|
||||||
* @param refreshToken - the refresh token received from the server.
|
|
||||||
*/
|
|
||||||
public async refreshTokens(refreshToken: string): Promise<SASjsAuthResponse> {
|
|
||||||
return refreshTokensForSasjs(this.requestClient, refreshToken)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs a login authenticate and returns an auth code for the given client.
|
|
||||||
* @param username - a string representing the username.
|
|
||||||
* @param password - a string representing the password.
|
|
||||||
* @param clientId - the client ID to authenticate with.
|
|
||||||
*/
|
|
||||||
public async getAuthCode(
|
|
||||||
username: string,
|
|
||||||
password: string,
|
|
||||||
clientId: string
|
|
||||||
) {
|
|
||||||
return getAuthCodeForSasjs(this.requestClient, username, password, clientId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo move to sasjs/utils
|
|
||||||
export interface SASjsAuthResponse {
|
|
||||||
access_token: string
|
|
||||||
refresh_token: string
|
|
||||||
}
|
|
||||||
@@ -5,10 +5,10 @@ import { prefixMessage } from '@sasjs/utils/error'
|
|||||||
import { RequestClient } from './request/RequestClient'
|
import { RequestClient } from './request/RequestClient'
|
||||||
|
|
||||||
const MAX_SESSION_COUNT = 1
|
const MAX_SESSION_COUNT = 1
|
||||||
|
const RETRY_LIMIT: number = 3
|
||||||
|
let RETRY_COUNT: number = 0
|
||||||
|
|
||||||
export class SessionManager {
|
export class SessionManager {
|
||||||
private loggedErrors: NoSessionStateError[] = []
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private serverUrl: string,
|
private serverUrl: string,
|
||||||
private contextName: string,
|
private contextName: string,
|
||||||
@@ -154,75 +154,69 @@ export class SessionManager {
|
|||||||
session: Session,
|
session: Session,
|
||||||
etag: string | null,
|
etag: string | null,
|
||||||
accessToken?: string
|
accessToken?: string
|
||||||
): Promise<string> {
|
) {
|
||||||
const logger = process.logger || console
|
const logger = process.logger || console
|
||||||
|
|
||||||
let sessionState = session.state
|
let sessionState = session.state
|
||||||
|
|
||||||
const stateLink = session.links.find((l: any) => l.rel === 'state')
|
const stateLink = session.links.find((l: any) => l.rel === 'state')
|
||||||
|
|
||||||
if (
|
return new Promise(async (resolve, reject) => {
|
||||||
sessionState === 'pending' ||
|
if (
|
||||||
sessionState === 'running' ||
|
sessionState === 'pending' ||
|
||||||
sessionState === ''
|
sessionState === 'running' ||
|
||||||
) {
|
sessionState === ''
|
||||||
if (stateLink) {
|
) {
|
||||||
if (this.debug && !this.printedSessionState.printed) {
|
if (stateLink) {
|
||||||
logger.info(`Polling: ${this.serverUrl + stateLink.href}`)
|
if (this.debug && !this.printedSessionState.printed) {
|
||||||
|
logger.info('Polling session status...')
|
||||||
|
|
||||||
this.printedSessionState.printed = true
|
this.printedSessionState.printed = true
|
||||||
}
|
|
||||||
|
|
||||||
const { result: state, responseStatus: responseStatus } =
|
|
||||||
await this.getSessionState(
|
|
||||||
`${this.serverUrl}${stateLink.href}?wait=30`,
|
|
||||||
etag!,
|
|
||||||
accessToken
|
|
||||||
).catch((err) => {
|
|
||||||
throw prefixMessage(err, 'Error while getting session state.')
|
|
||||||
})
|
|
||||||
|
|
||||||
sessionState = state.trim()
|
|
||||||
|
|
||||||
if (this.debug && this.printedSessionState.state !== sessionState) {
|
|
||||||
logger.info(`Current session state is '${sessionState}'`)
|
|
||||||
|
|
||||||
this.printedSessionState.state = sessionState
|
|
||||||
this.printedSessionState.printed = false
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sessionState) {
|
|
||||||
const stateError = new NoSessionStateError(
|
|
||||||
responseStatus,
|
|
||||||
this.serverUrl + stateLink.href,
|
|
||||||
session.links.find((l: any) => l.rel === 'log')?.href as string
|
|
||||||
)
|
|
||||||
|
|
||||||
if (
|
|
||||||
!this.loggedErrors.find(
|
|
||||||
(err: NoSessionStateError) =>
|
|
||||||
err.serverResponseStatus === stateError.serverResponseStatus
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
this.loggedErrors.push(stateError)
|
|
||||||
|
|
||||||
logger.info(stateError.message)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return await this.waitForSession(session, etag, accessToken)
|
const { result: state, responseStatus: responseStatus } =
|
||||||
|
await this.getSessionState(
|
||||||
|
`${this.serverUrl}${stateLink.href}?wait=30`,
|
||||||
|
etag!,
|
||||||
|
accessToken
|
||||||
|
).catch((err) => {
|
||||||
|
throw prefixMessage(err, 'Error while getting session state.')
|
||||||
|
})
|
||||||
|
|
||||||
|
sessionState = state.trim()
|
||||||
|
|
||||||
|
if (this.debug && this.printedSessionState.state !== sessionState) {
|
||||||
|
logger.info(`Current session state is '${sessionState}'`)
|
||||||
|
|
||||||
|
this.printedSessionState.state = sessionState
|
||||||
|
this.printedSessionState.printed = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// There is an internal error present in SAS Viya 3.5
|
||||||
|
// Retry to wait for a session status in such case of SAS internal error
|
||||||
|
if (!sessionState) {
|
||||||
|
if (RETRY_COUNT < RETRY_LIMIT) {
|
||||||
|
RETRY_COUNT++
|
||||||
|
|
||||||
|
resolve(this.waitForSession(session, etag, accessToken))
|
||||||
|
} else {
|
||||||
|
reject(
|
||||||
|
new NoSessionStateError(
|
||||||
|
responseStatus,
|
||||||
|
this.serverUrl + stateLink.href,
|
||||||
|
session.links.find((l: any) => l.rel === 'log')
|
||||||
|
?.href as string
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(sessionState)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loggedErrors = []
|
|
||||||
|
|
||||||
return sessionState
|
|
||||||
} else {
|
} else {
|
||||||
throw 'Error while getting session state link.'
|
resolve(sessionState)
|
||||||
}
|
}
|
||||||
} else {
|
})
|
||||||
this.loggedErrors = []
|
|
||||||
|
|
||||||
return sessionState
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getSessionState(
|
private async getSessionState(
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { getTokens } from '../../auth/getTokens'
|
|||||||
import { RequestClient } from '../../request/RequestClient'
|
import { RequestClient } from '../../request/RequestClient'
|
||||||
import { JobStatePollError } from '../../types/errors'
|
import { JobStatePollError } from '../../types/errors'
|
||||||
import { Link, WriteStream } from '../../types'
|
import { Link, WriteStream } from '../../types'
|
||||||
import { delay, isNode } from '../../utils'
|
import { isNode } from '../../utils'
|
||||||
|
|
||||||
export async function pollJobState(
|
export async function pollJobState(
|
||||||
requestClient: RequestClient,
|
requestClient: RequestClient,
|
||||||
@@ -206,11 +206,10 @@ const doPoll = async (
|
|||||||
|
|
||||||
pollCount++
|
pollCount++
|
||||||
|
|
||||||
const jobHref = postedJob.links.find((l: Link) => l.rel === 'self')!.href
|
|
||||||
|
|
||||||
if (pollOptions?.streamLog) {
|
if (pollOptions?.streamLog) {
|
||||||
|
const jobUrl = postedJob.links.find((l: Link) => l.rel === 'self')
|
||||||
const { result: job } = await requestClient.get<Job>(
|
const { result: job } = await requestClient.get<Job>(
|
||||||
jobHref,
|
jobUrl!.href,
|
||||||
authConfig?.access_token
|
authConfig?.access_token
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -232,7 +231,7 @@ const doPoll = async (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (debug && printedState !== state) {
|
if (debug && printedState !== state) {
|
||||||
logger.info(`Polling: ${requestClient.getBaseUrl() + jobHref}/state`)
|
logger.info('Polling job status...')
|
||||||
logger.info(`Current job state: ${state}`)
|
logger.info(`Current job state: ${state}`)
|
||||||
|
|
||||||
printedState = state
|
printedState = state
|
||||||
@@ -247,3 +246,5 @@ const doPoll = async (
|
|||||||
|
|
||||||
return { state, pollCount }
|
return { state, pollCount }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
|
||||||
|
|||||||
@@ -9,10 +9,7 @@ import * as isNodeModule from '../../../utils/isNode'
|
|||||||
import { PollOptions } from '../../../types'
|
import { PollOptions } from '../../../types'
|
||||||
import { WriteStream } from 'fs'
|
import { WriteStream } from 'fs'
|
||||||
|
|
||||||
const baseUrl = 'http://localhost'
|
|
||||||
const requestClient = new (<jest.Mock<RequestClient>>RequestClient)()
|
const requestClient = new (<jest.Mock<RequestClient>>RequestClient)()
|
||||||
requestClient['httpClient'].defaults.baseURL = baseUrl
|
|
||||||
|
|
||||||
const defaultPollOptions: PollOptions = {
|
const defaultPollOptions: PollOptions = {
|
||||||
maxPollCount: 100,
|
maxPollCount: 100,
|
||||||
pollInterval: 500,
|
pollInterval: 500,
|
||||||
@@ -198,7 +195,7 @@ describe('pollJobState', () => {
|
|||||||
expect((process as any).logger.info).toHaveBeenCalledTimes(4)
|
expect((process as any).logger.info).toHaveBeenCalledTimes(4)
|
||||||
expect((process as any).logger.info).toHaveBeenNthCalledWith(
|
expect((process as any).logger.info).toHaveBeenNthCalledWith(
|
||||||
1,
|
1,
|
||||||
`Polling: ${baseUrl}/job/state`
|
'Polling job status...'
|
||||||
)
|
)
|
||||||
expect((process as any).logger.info).toHaveBeenNthCalledWith(
|
expect((process as any).logger.info).toHaveBeenNthCalledWith(
|
||||||
2,
|
2,
|
||||||
@@ -206,7 +203,7 @@ describe('pollJobState', () => {
|
|||||||
)
|
)
|
||||||
expect((process as any).logger.info).toHaveBeenNthCalledWith(
|
expect((process as any).logger.info).toHaveBeenNthCalledWith(
|
||||||
3,
|
3,
|
||||||
`Polling: ${baseUrl}/job/state`
|
'Polling job status...'
|
||||||
)
|
)
|
||||||
expect((process as any).logger.info).toHaveBeenNthCalledWith(
|
expect((process as any).logger.info).toHaveBeenNthCalledWith(
|
||||||
4,
|
4,
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user