mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-05 03:30:05 +00:00
Compare commits
53 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e4f23334d3 | ||
|
|
5593963b89 | ||
|
|
83fa82108b | ||
|
|
4018cf95ba | ||
|
|
173b6e3e8d | ||
|
|
0ed5447aff | ||
|
|
6344a906d8 | ||
|
|
2032aacba3 | ||
|
|
fadccfc94c | ||
|
|
551e4e43c1 | ||
| 3fff4f9c4d | |||
|
|
3f119432db | ||
|
|
2147c59314 | ||
|
|
b247da249a | ||
|
|
e79089b880 | ||
|
|
fe907e1c43 | ||
|
|
e95e894365 | ||
|
|
82414d8b8b | ||
|
|
456fa68f0f | ||
|
|
076adc1f6a | ||
|
|
9676488ff2 | ||
|
|
e9affb862d | ||
|
|
e04371510e | ||
|
|
19657a1c12 | ||
|
|
6424c82ac9 | ||
|
|
fcab18191f | ||
|
|
f157612a0e | ||
|
|
b8cb7d52e7 | ||
|
|
d8d1968162 | ||
|
|
0e1d1f1d99 | ||
|
|
0b055dd05f | ||
|
|
ba91c29ba8 | ||
|
|
bd19457c2a | ||
|
|
b0570e1cd9 | ||
|
|
a5f1b59f7b | ||
|
|
01ca29fc01 | ||
|
|
ed9648fdf9 | ||
|
|
7e17aa6eb3 | ||
|
|
9caee9941a | ||
|
|
e309e7a4f4 | ||
|
|
c47441d6d4 | ||
|
|
1844bc48ac | ||
|
|
7a5adebdb5 | ||
|
|
b39f0c577b | ||
|
|
15f4065cd8 | ||
|
|
4c67665b4d | ||
|
|
76d0b82b4c | ||
|
|
95d65d270d | ||
|
|
4e5c9c1ccd | ||
|
|
3267af0724 | ||
|
|
75120424d0 | ||
|
|
f8c6318a88 | ||
|
|
dc98ce3b0b |
18
.git-hooks/commit-msg
Executable file
18
.git-hooks/commit-msg
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
RED="\033[1;31m"
|
||||||
|
GREEN="\033[1;32m"
|
||||||
|
|
||||||
|
# Get the commit message (the parameter we're given is just the path to the
|
||||||
|
# temporary file which holds the message).
|
||||||
|
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
|
||||||
|
echo "${GREEN} ✔ Commit message meets Conventional Commit standards"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "${RED}❌ Commit message does not meet the Conventional Commit standard!"
|
||||||
|
echo "An example of a valid message is:"
|
||||||
|
echo " feat(login): add the 'remember me' button"
|
||||||
|
echo "ℹ More details at: https://www.conventionalcommits.org/en/v1.0.0/#summary"
|
||||||
|
exit 1
|
||||||
4
.npmignore
Normal file
4
.npmignore
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
sasjs-tests/
|
||||||
|
docs/
|
||||||
|
.github/
|
||||||
|
CONTRIBUTING.md
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
# Change Log
|
# Change Log
|
||||||
|
|
||||||
|
Since March 2020 the changelog is managed by github releases - see [https://github.com/sasjs/adapter/releases](https://github.com/sasjs/adapter/releases).
|
||||||
|
|
||||||
|
## Changes up to 5th March 2020
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||||
|
|
||||||
<a name="1.9.0"></a>
|
<a name="1.9.0"></a>
|
||||||
|
|||||||
@@ -2,75 +2,127 @@
|
|||||||
|
|
||||||
## Our Pledge
|
## Our Pledge
|
||||||
|
|
||||||
In the interest of fostering an open and welcoming environment, we as
|
We as members, contributors, and leaders pledge to make participation in our
|
||||||
contributors and maintainers pledge to making participation in our project and
|
community a harassment-free experience for everyone, regardless of age, body
|
||||||
our community a harassment-free experience for everyone, regardless of age, body
|
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||||
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
identity and expression, level of experience, education, socio-economic status,
|
||||||
level of experience, education, socio-economic status, nationality, personal
|
nationality, personal appearance, race, religion, or sexual identity
|
||||||
appearance, race, religion, or sexual identity and orientation.
|
and orientation.
|
||||||
|
|
||||||
|
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||||
|
diverse, inclusive, and healthy community.
|
||||||
|
|
||||||
## Our Standards
|
## Our Standards
|
||||||
|
|
||||||
Examples of behavior that contributes to creating a positive environment
|
Examples of behavior that contributes to a positive environment for our
|
||||||
include:
|
community include:
|
||||||
|
|
||||||
* Using welcoming and inclusive language
|
* Demonstrating empathy and kindness toward other people
|
||||||
* Being respectful of differing viewpoints and experiences
|
* Being respectful of differing opinions, viewpoints, and experiences
|
||||||
* Gracefully accepting constructive criticism
|
* Giving and gracefully accepting constructive feedback
|
||||||
* Focusing on what is best for the community
|
* Accepting responsibility and apologizing to those affected by our mistakes,
|
||||||
* Showing empathy towards other community members
|
and learning from the experience
|
||||||
|
* Focusing on what is best not just for us as individuals, but for the
|
||||||
|
overall community
|
||||||
|
|
||||||
Examples of unacceptable behavior by participants include:
|
Examples of unacceptable behavior include:
|
||||||
|
|
||||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
* The use of sexualized language or imagery, and sexual attention or
|
||||||
advances
|
advances of any kind
|
||||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||||
* Public or private harassment
|
* Public or private harassment
|
||||||
* Publishing others' private information, such as a physical or electronic
|
* Publishing others' private information, such as a physical or email
|
||||||
address, without explicit permission
|
address, without their explicit permission
|
||||||
* Other conduct which could reasonably be considered inappropriate in a
|
* Other conduct which could reasonably be considered inappropriate in a
|
||||||
professional setting
|
professional setting
|
||||||
|
|
||||||
## Our Responsibilities
|
## Enforcement Responsibilities
|
||||||
|
|
||||||
Project maintainers are responsible for clarifying the standards of acceptable
|
Community leaders are responsible for clarifying and enforcing our standards of
|
||||||
behavior and are expected to take appropriate and fair corrective action in
|
acceptable behavior and will take appropriate and fair corrective action in
|
||||||
response to any instances of unacceptable behavior.
|
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||||
|
or harmful.
|
||||||
|
|
||||||
Project maintainers have the right and responsibility to remove, edit, or
|
Community leaders have the right and responsibility to remove, edit, or reject
|
||||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||||
permanently any contributor for other behaviors that they deem inappropriate,
|
decisions when appropriate.
|
||||||
threatening, offensive, or harmful.
|
|
||||||
|
|
||||||
## Scope
|
## Scope
|
||||||
|
|
||||||
This Code of Conduct applies both within project spaces and in public spaces
|
This Code of Conduct applies within all community spaces, and also applies when
|
||||||
when an individual is representing the project or its community. Examples of
|
an individual is officially representing the community in public spaces.
|
||||||
representing a project or community include using an official project e-mail
|
Examples of representing our community include using an official e-mail address,
|
||||||
address, posting via an official social media account, or acting as an appointed
|
posting via an official social media account, or acting as an appointed
|
||||||
representative at an online or offline event. Representation of a project may be
|
representative at an online or offline event.
|
||||||
further defined and clarified by project maintainers.
|
|
||||||
|
|
||||||
## Enforcement
|
## Enforcement
|
||||||
|
|
||||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||||
reported by contacting the project team at support@macropeople.com. All
|
reported to the community leaders responsible for enforcement at
|
||||||
complaints will be reviewed and investigated and will result in a response that
|
https://sasapps.io/contact-us.
|
||||||
is deemed necessary and appropriate to the circumstances. The project team is
|
All complaints will be reviewed and investigated promptly and fairly.
|
||||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
||||||
Further details of specific enforcement policies may be posted separately.
|
|
||||||
|
|
||||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
All community leaders are obligated to respect the privacy and security of the
|
||||||
faith may face temporary or permanent repercussions as determined by other
|
reporter of any incident.
|
||||||
members of the project's leadership.
|
|
||||||
|
## Enforcement Guidelines
|
||||||
|
|
||||||
|
Community leaders will follow these Community Impact Guidelines in determining
|
||||||
|
the consequences for any action they deem in violation of this Code of Conduct:
|
||||||
|
|
||||||
|
### 1. Correction
|
||||||
|
|
||||||
|
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||||
|
unprofessional or unwelcome in the community.
|
||||||
|
|
||||||
|
**Consequence**: A private, written warning from community leaders, providing
|
||||||
|
clarity around the nature of the violation and an explanation of why the
|
||||||
|
behavior was inappropriate. A public apology may be requested.
|
||||||
|
|
||||||
|
### 2. Warning
|
||||||
|
|
||||||
|
**Community Impact**: A violation through a single incident or series
|
||||||
|
of actions.
|
||||||
|
|
||||||
|
**Consequence**: A warning with consequences for continued behavior. No
|
||||||
|
interaction with the people involved, including unsolicited interaction with
|
||||||
|
those enforcing the Code of Conduct, for a specified period of time. This
|
||||||
|
includes avoiding interactions in community spaces as well as external channels
|
||||||
|
like social media. Violating these terms may lead to a temporary or
|
||||||
|
permanent ban.
|
||||||
|
|
||||||
|
### 3. Temporary Ban
|
||||||
|
|
||||||
|
**Community Impact**: A serious violation of community standards, including
|
||||||
|
sustained inappropriate behavior.
|
||||||
|
|
||||||
|
**Consequence**: A temporary ban from any sort of interaction or public
|
||||||
|
communication with the community for a specified period of time. No public or
|
||||||
|
private interaction with the people involved, including unsolicited interaction
|
||||||
|
with those enforcing the Code of Conduct, is allowed during this period.
|
||||||
|
Violating these terms may lead to a permanent ban.
|
||||||
|
|
||||||
|
### 4. Permanent Ban
|
||||||
|
|
||||||
|
**Community Impact**: Demonstrating a pattern of violation of community
|
||||||
|
standards, including sustained inappropriate behavior, harassment of an
|
||||||
|
individual, or aggression toward or disparagement of classes of individuals.
|
||||||
|
|
||||||
|
**Consequence**: A permanent ban from any sort of public interaction within
|
||||||
|
the community.
|
||||||
|
|
||||||
## Attribution
|
## Attribution
|
||||||
|
|
||||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||||
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
version 2.0, available at
|
||||||
|
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
||||||
|
|
||||||
|
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
||||||
|
enforcement ladder](https://github.com/mozilla/diversity).
|
||||||
|
|
||||||
[homepage]: https://www.contributor-covenant.org
|
[homepage]: https://www.contributor-covenant.org
|
||||||
|
|
||||||
For answers to common questions about this code of conduct, see
|
For answers to common questions about this code of conduct, see the FAQ at
|
||||||
https://www.contributor-covenant.org/faq
|
https://www.contributor-covenant.org/faq. Translations are available at
|
||||||
|
https://www.contributor-covenant.org/translations.
|
||||||
|
|||||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Macro People
|
Copyright (c) 2021 Macro People
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
29
README.md
29
README.md
@@ -1,7 +1,23 @@
|
|||||||
[](https://www.jsdelivr.com/package/npm/@sasjs/adapter)
|
|
||||||
|
|
||||||
# @sasjs/adapter
|
# @sasjs/adapter
|
||||||
|
|
||||||
|
[![npm package][npm-image]][npm-url]
|
||||||
|
[![Github Workflow][githubworkflow-image]][githubworkflow-url]
|
||||||
|
[![Dependency Status][dependency-image]][dependency-url]
|
||||||
|
[]()
|
||||||
|

|
||||||
|
[](/LICENSE)
|
||||||
|

|
||||||
|

|
||||||
|
[](https://gitpod.io/#https://github.com/sasjs/adapter)
|
||||||
|
|
||||||
|
|
||||||
|
[npm-image]:https://img.shields.io/npm/v/@sasjs/adapter.svg
|
||||||
|
[npm-url]:http://npmjs.org/package/@sasjs/adapter
|
||||||
|
[githubworkflow-image]:https://github.com/sasjs/adapter/actions/workflows/build.yml/badge.svg
|
||||||
|
[githubworkflow-url]:https://github.com/sasjs/adapter/blob/main/.github/workflows/build.yml
|
||||||
|
[dependency-image]:https://david-dm.org/sasjs/adapter.svg
|
||||||
|
[dependency-url]:https://github.com/sasjs/adapter/blob/main/package.json
|
||||||
|
|
||||||
SASjs is a open-source framework for building Web Apps on SAS® platforms. You can use as much or as little of it as you like. This repository contains the JS adapter, the part that handles the to/from SAS communication on the client side. There are 3 ways to install it:
|
SASjs is a open-source framework for building Web Apps on SAS® platforms. You can use as much or as little of it as you like. This repository contains the JS adapter, the part that handles the to/from SAS communication on the client side. There are 3 ways to install it:
|
||||||
|
|
||||||
1 - `npm install @sasjs/adapter` - for use in a node project
|
1 - `npm install @sasjs/adapter` - for use in a node project
|
||||||
@@ -198,8 +214,15 @@ This approach is by far the fastest, as a result of the optimisations we have bu
|
|||||||
|
|
||||||
# More resources
|
# More resources
|
||||||
|
|
||||||
For more information and examples specific to this adapter you can check out the [user guide](https://sasjs.io/sasjs-adapter/) or the [technical](http://adapter.sasjs.io/) documentation.
|
For more information and examples specific to this adapter you can check out the [user guide](https://sasjs.io/sasjs-adapter/) or the [technical](http://adapter.sasjs.io/) documentation.
|
||||||
|
|
||||||
For more information on building web apps in general, check out these [resources](https://sasjs.io/training/resources/) or contact the [author](https://www.linkedin.com/in/allanbowe/) directly.
|
For more information on building web apps in general, check out these [resources](https://sasjs.io/training/resources/) or contact the [author](https://www.linkedin.com/in/allanbowe/) directly.
|
||||||
|
|
||||||
If you are a SAS 9 or SAS Viya customer you can also request a copy of [Data Controller](https://datacontroller.io) - free for up to 5 users, this tool makes use of all parts of the SASjs framework.
|
If you are a SAS 9 or SAS Viya customer you can also request a copy of [Data Controller](https://datacontroller.io) - free for up to 5 users, this tool makes use of all parts of the SASjs framework.
|
||||||
|
|
||||||
|
|
||||||
|
## Star Gazing
|
||||||
|
|
||||||
|
If you find this library useful, help us grow our star graph!
|
||||||
|
|
||||||
|

|
||||||
3914
package-lock.json
generated
3914
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
35
package.json
35
package.json
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@sasjs/adapter",
|
"name": "@sasjs/adapter",
|
||||||
"description": "JavaScript adapter for SAS",
|
"description": "JavaScript adapter for SAS",
|
||||||
|
"homepage": "https://adapter.sasjs.io",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "rimraf build && rimraf node && mkdir node && cp -r src/* node && webpack && rimraf build/src && rimraf node",
|
"build": "rimraf build && rimraf node && mkdir node && cp -r src/* node && webpack && rimraf build/src && rimraf node",
|
||||||
"package:lib": "npm run build && cp ./package.json build && cd build && npm version \"5.0.0\" && npm pack",
|
"package:lib": "npm run build && cp ./package.json build && cd build && npm version \"5.0.0\" && npm pack",
|
||||||
@@ -11,7 +12,8 @@
|
|||||||
"prepublishOnly": "cp -r ./build/* . && rm -rf ./build",
|
"prepublishOnly": "cp -r ./build/* . && rm -rf ./build",
|
||||||
"postpublish": "git clean -fd",
|
"postpublish": "git clean -fd",
|
||||||
"semantic-release": "semantic-release",
|
"semantic-release": "semantic-release",
|
||||||
"typedoc": "typedoc"
|
"typedoc": "typedoc",
|
||||||
|
"postinstall": "[ -d .git ] && git config core.hooksPath ./.git-hooks || true"
|
||||||
},
|
},
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
@@ -36,31 +38,36 @@
|
|||||||
},
|
},
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^26.0.22",
|
"@types/jest": "^26.0.23",
|
||||||
|
"@types/tough-cookie": "^4.0.0",
|
||||||
"cp": "^0.2.0",
|
"cp": "^0.2.0",
|
||||||
"dotenv": "^8.2.0",
|
"dotenv": "^10.0.0",
|
||||||
"jest": "^26.6.3",
|
"jest": "^27.0.4",
|
||||||
"jest-extended": "^0.11.5",
|
"jest-extended": "^0.11.5",
|
||||||
"path": "^0.12.7",
|
"path": "^0.12.7",
|
||||||
|
"process": "^0.11.10",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"semantic-release": "^17.4.2",
|
"semantic-release": "^17.4.3",
|
||||||
"terser-webpack-plugin": "^4.2.3",
|
"terser-webpack-plugin": "^5.1.3",
|
||||||
"ts-jest": "^25.5.1",
|
"ts-jest": "^27.0.2",
|
||||||
"ts-loader": "^9.1.2",
|
"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.20.35",
|
"typedoc": "^0.20.36",
|
||||||
"typedoc-neo-theme": "^1.1.0",
|
"typedoc-neo-theme": "^1.1.1",
|
||||||
"typedoc-plugin-external-module-name": "^4.0.6",
|
"typedoc-plugin-external-module-name": "^4.0.6",
|
||||||
"typescript": "^3.9.9",
|
"typescript": "^4.3.2",
|
||||||
"webpack": "^5.33.2",
|
"webpack": "^5.38.1",
|
||||||
"webpack-cli": "^4.7.0"
|
"webpack-cli": "^4.7.0"
|
||||||
},
|
},
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sasjs/utils": "^2.10.2",
|
"@sasjs/utils": "^2.17.1",
|
||||||
"axios": "^0.21.1",
|
"axios": "^0.21.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",
|
||||||
|
"url": "^0.11.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
|
|||||||
%inc mc;
|
%inc mc;
|
||||||
filename ft15f001 temp;
|
filename ft15f001 temp;
|
||||||
parmcards4;
|
parmcards4;
|
||||||
|
%webout(FETCH)
|
||||||
%webout(OPEN)
|
%webout(OPEN)
|
||||||
%macro x();
|
%macro x();
|
||||||
%do i=1 %to &_webin_file_count; %webout(OBJ,&&_webin_name&i) %end;
|
%do i=1 %to &_webin_file_count; %webout(OBJ,&&_webin_name&i) %end;
|
||||||
@@ -63,6 +64,7 @@ parmcards4;
|
|||||||
;;;;
|
;;;;
|
||||||
%mm_createwebservice(path=/Public/app/common,name=sendObj)
|
%mm_createwebservice(path=/Public/app/common,name=sendObj)
|
||||||
parmcards4;
|
parmcards4;
|
||||||
|
%webout(FETCH)
|
||||||
%webout(OPEN)
|
%webout(OPEN)
|
||||||
%macro x();
|
%macro x();
|
||||||
%do i=1 %to &_webin_file_count; %webout(ARR,&&_webin_name&i) %end;
|
%do i=1 %to &_webin_file_count; %webout(ARR,&&_webin_name&i) %end;
|
||||||
@@ -70,6 +72,10 @@ parmcards4;
|
|||||||
%webout(CLOSE)
|
%webout(CLOSE)
|
||||||
;;;;
|
;;;;
|
||||||
%mm_createwebservice(path=/Public/app/common,name=sendArr)
|
%mm_createwebservice(path=/Public/app/common,name=sendArr)
|
||||||
|
parmcards4;
|
||||||
|
let he who hath understanding, reckon the number of the beast
|
||||||
|
;;;;
|
||||||
|
%mm_createwebservice(path=/Public/app/common,name=makeErr)
|
||||||
```
|
```
|
||||||
|
|
||||||
### SAS Viya
|
### SAS Viya
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import axios, { AxiosInstance } from 'axios'
|
import { generateTimestamp } from '@sasjs/utils/time'
|
||||||
|
import * as NodeFormData from 'form-data'
|
||||||
|
import { Sas9RequestClient } from './request/Sas9RequestClient'
|
||||||
import { isUrl } from './utils'
|
import { isUrl } from './utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -6,11 +8,11 @@ import { isUrl } from './utils'
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export class SAS9ApiClient {
|
export class SAS9ApiClient {
|
||||||
private httpClient: AxiosInstance
|
private requestClient: Sas9RequestClient
|
||||||
|
|
||||||
constructor(private serverUrl: string) {
|
constructor(private serverUrl: string, private jobsPath: string) {
|
||||||
if (serverUrl) isUrl(serverUrl)
|
if (serverUrl) isUrl(serverUrl)
|
||||||
this.httpClient = axios.create({ baseURL: this.serverUrl })
|
this.requestClient = new Sas9RequestClient(serverUrl, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,27 +35,52 @@ export class SAS9ApiClient {
|
|||||||
/**
|
/**
|
||||||
* Executes code on a SAS9 server.
|
* Executes code on a SAS9 server.
|
||||||
* @param linesOfCode - an array of code lines to execute.
|
* @param linesOfCode - an array of code lines to execute.
|
||||||
* @param serverName - the server to execute the code on.
|
* @param userName - the user name to log into the current SAS server.
|
||||||
* @param repositoryName - the repository to execute the code in.
|
* @param password - the password to log into the current SAS server.
|
||||||
*/
|
*/
|
||||||
public async executeScript(
|
public async executeScript(
|
||||||
linesOfCode: string[],
|
linesOfCode: string[],
|
||||||
serverName: string,
|
userName: string,
|
||||||
repositoryName: string
|
password: string
|
||||||
) {
|
) {
|
||||||
const requestPayload = linesOfCode.join('\n')
|
await this.requestClient.login(userName, password, this.jobsPath)
|
||||||
|
|
||||||
const executeScriptResponse = await this.httpClient.put(
|
const formData = generateFileUploadForm(linesOfCode.join('\n'))
|
||||||
`/sas/servers/${serverName}/cmd?repositoryName=${repositoryName}`,
|
|
||||||
`command=${requestPayload}`,
|
const codeInjectorPath = `/User Folders/${userName}/My Folder/sasjs/runner`
|
||||||
{
|
const contentType =
|
||||||
headers: {
|
'multipart/form-data; boundary=' + formData.getBoundary()
|
||||||
Accept: 'application/json'
|
const contentLength = formData.getLengthSync()
|
||||||
},
|
|
||||||
responseType: 'text'
|
const headers = {
|
||||||
}
|
'cache-control': 'no-cache',
|
||||||
|
Accept: '*/*',
|
||||||
|
'Content-Type': contentType,
|
||||||
|
'Content-Length': contentLength,
|
||||||
|
Connection: 'keep-alive'
|
||||||
|
}
|
||||||
|
const storedProcessUrl = `${this.jobsPath}/?${
|
||||||
|
'_program=' + codeInjectorPath + '&_debug=log'
|
||||||
|
}`
|
||||||
|
const response = await this.requestClient.post(
|
||||||
|
storedProcessUrl,
|
||||||
|
formData,
|
||||||
|
undefined,
|
||||||
|
contentType,
|
||||||
|
headers
|
||||||
)
|
)
|
||||||
|
|
||||||
return executeScriptResponse.data
|
return response.result as string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const generateFileUploadForm = (data: any): NodeFormData => {
|
||||||
|
const formData = new NodeFormData()
|
||||||
|
const filename = `sasjs-execute-sas9-${generateTimestamp('')}.sas`
|
||||||
|
formData.append(filename, data, {
|
||||||
|
filename,
|
||||||
|
contentType: 'text/plain'
|
||||||
|
})
|
||||||
|
|
||||||
|
return formData
|
||||||
|
}
|
||||||
|
|||||||
@@ -719,13 +719,11 @@ export class SASViyaApiClient {
|
|||||||
let formData
|
let formData
|
||||||
if (typeof FormData === 'undefined') {
|
if (typeof FormData === 'undefined') {
|
||||||
formData = new NodeFormData()
|
formData = new NodeFormData()
|
||||||
formData.append('grant_type', 'authorization_code')
|
|
||||||
formData.append('code', authCode)
|
|
||||||
} else {
|
} else {
|
||||||
formData = new FormData()
|
formData = new FormData()
|
||||||
formData.append('grant_type', 'authorization_code')
|
|
||||||
formData.append('code', authCode)
|
|
||||||
}
|
}
|
||||||
|
formData.append('grant_type', 'authorization_code')
|
||||||
|
formData.append('code', authCode)
|
||||||
|
|
||||||
const authResponse = await this.requestClient
|
const authResponse = await this.requestClient
|
||||||
.post(
|
.post(
|
||||||
|
|||||||
32
src/SASjs.ts
32
src/SASjs.ts
@@ -10,7 +10,8 @@ import {
|
|||||||
JobExecutor,
|
JobExecutor,
|
||||||
WebJobExecutor,
|
WebJobExecutor,
|
||||||
ComputeJobExecutor,
|
ComputeJobExecutor,
|
||||||
JesJobExecutor
|
JesJobExecutor,
|
||||||
|
Sas9JobExecutor
|
||||||
} from './job-execution'
|
} from './job-execution'
|
||||||
import { ErrorResponse } from './types/errors'
|
import { ErrorResponse } from './types/errors'
|
||||||
|
|
||||||
@@ -41,6 +42,7 @@ export default class SASjs {
|
|||||||
private webJobExecutor: JobExecutor | null = null
|
private webJobExecutor: JobExecutor | null = null
|
||||||
private computeJobExecutor: JobExecutor | null = null
|
private computeJobExecutor: JobExecutor | null = null
|
||||||
private jesJobExecutor: JobExecutor | null = null
|
private jesJobExecutor: JobExecutor | null = null
|
||||||
|
private sas9JobExecutor: JobExecutor | null = null
|
||||||
|
|
||||||
constructor(config?: any) {
|
constructor(config?: any) {
|
||||||
this.sasjsConfig = {
|
this.sasjsConfig = {
|
||||||
@@ -57,15 +59,15 @@ export default class SASjs {
|
|||||||
|
|
||||||
public async executeScriptSAS9(
|
public async executeScriptSAS9(
|
||||||
linesOfCode: string[],
|
linesOfCode: string[],
|
||||||
serverName: string,
|
userName: string,
|
||||||
repositoryName: 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,
|
||||||
serverName,
|
userName,
|
||||||
repositoryName
|
password
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -569,6 +571,12 @@ export default class SASjs {
|
|||||||
accessToken
|
accessToken
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
} else if (
|
||||||
|
config.serverType === ServerType.Sas9 &&
|
||||||
|
config.username &&
|
||||||
|
config.password
|
||||||
|
) {
|
||||||
|
return await this.sas9JobExecutor!.execute(sasJob, data, config)
|
||||||
} else {
|
} else {
|
||||||
return await this.webJobExecutor!.execute(
|
return await this.webJobExecutor!.execute(
|
||||||
sasJob,
|
sasJob,
|
||||||
@@ -616,7 +624,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(serverUrl)
|
sasApiClient = new SAS9ApiClient(serverUrl, this.jobsPath)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let sasClientConfig: any = null
|
let sasClientConfig: any = null
|
||||||
@@ -805,7 +813,11 @@ export default class SASjs {
|
|||||||
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 this.sas9ApiClient = new SAS9ApiClient(this.sasjsConfig.serverUrl)
|
else
|
||||||
|
this.sas9ApiClient = new SAS9ApiClient(
|
||||||
|
this.sasjsConfig.serverUrl,
|
||||||
|
this.jobsPath
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.fileUploader = new FileUploader(
|
this.fileUploader = new FileUploader(
|
||||||
@@ -823,6 +835,12 @@ export default class SASjs {
|
|||||||
this.sasViyaApiClient!
|
this.sasViyaApiClient!
|
||||||
)
|
)
|
||||||
|
|
||||||
|
this.sas9JobExecutor = new Sas9JobExecutor(
|
||||||
|
this.sasjsConfig.serverUrl,
|
||||||
|
this.sasjsConfig.serverType!,
|
||||||
|
this.jobsPath
|
||||||
|
)
|
||||||
|
|
||||||
this.computeJobExecutor = new ComputeJobExecutor(
|
this.computeJobExecutor = new ComputeJobExecutor(
|
||||||
this.sasjsConfig.serverUrl,
|
this.sasjsConfig.serverUrl,
|
||||||
this.sasViyaApiClient!
|
this.sasViyaApiClient!
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ describe('AuthManager', () => {
|
|||||||
expect((authManager as any).logoutUrl).toEqual('/SASLogon/logout?')
|
expect((authManager as any).logoutUrl).toEqual('/SASLogon/logout?')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should call the auth callback and return when already logged in', async (done) => {
|
it('should call the auth callback and return when already logged in', async () => {
|
||||||
const authManager = new AuthManager(
|
const authManager = new AuthManager(
|
||||||
serverUrl,
|
serverUrl,
|
||||||
serverType,
|
serverType,
|
||||||
@@ -77,10 +77,9 @@ describe('AuthManager', () => {
|
|||||||
expect(loginResponse.isLoggedIn).toBeTruthy()
|
expect(loginResponse.isLoggedIn).toBeTruthy()
|
||||||
expect(loginResponse.userName).toEqual(userName)
|
expect(loginResponse.userName).toEqual(userName)
|
||||||
expect(authCallback).toHaveBeenCalledTimes(1)
|
expect(authCallback).toHaveBeenCalledTimes(1)
|
||||||
done()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should post a login request to the server if not logged in', async (done) => {
|
it('should post a login request to the server if not logged in', async () => {
|
||||||
const authManager = new AuthManager(
|
const authManager = new AuthManager(
|
||||||
serverUrl,
|
serverUrl,
|
||||||
serverType,
|
serverType,
|
||||||
@@ -121,10 +120,9 @@ describe('AuthManager', () => {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
expect(authCallback).toHaveBeenCalledTimes(1)
|
expect(authCallback).toHaveBeenCalledTimes(1)
|
||||||
done()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should parse and submit the authorisation form when necessary', async (done) => {
|
it('should parse and submit the authorisation form when necessary', async () => {
|
||||||
const authManager = new AuthManager(
|
const authManager = new AuthManager(
|
||||||
serverUrl,
|
serverUrl,
|
||||||
serverType,
|
serverType,
|
||||||
@@ -160,10 +158,9 @@ describe('AuthManager', () => {
|
|||||||
expect(requestClient.authorize).toHaveBeenCalledWith(
|
expect(requestClient.authorize).toHaveBeenCalledWith(
|
||||||
mockLoginAuthoriseRequiredResponse
|
mockLoginAuthoriseRequiredResponse
|
||||||
)
|
)
|
||||||
done()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should check and return session information if logged in', async (done) => {
|
it('should check and return session information if logged in', async () => {
|
||||||
const authManager = new AuthManager(
|
const authManager = new AuthManager(
|
||||||
serverUrl,
|
serverUrl,
|
||||||
serverType,
|
serverType,
|
||||||
@@ -189,7 +186,5 @@ describe('AuthManager', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
done()
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
110
src/job-execution/Sas9JobExecutor.ts
Normal file
110
src/job-execution/Sas9JobExecutor.ts
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
import { ServerType } from '@sasjs/utils/types'
|
||||||
|
import * as NodeFormData from 'form-data'
|
||||||
|
import { ErrorResponse } from '../types/errors'
|
||||||
|
import { convertToCSV, isRelativePath } from '../utils'
|
||||||
|
import { BaseJobExecutor } from './JobExecutor'
|
||||||
|
import { Sas9RequestClient } from '../request/Sas9RequestClient'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Job executor for SAS9 servers for use in Node.js environments.
|
||||||
|
* Initiates login with the provided username and password from the config
|
||||||
|
* The cookies are stored in the request client and used in subsequent
|
||||||
|
* job execution requests.
|
||||||
|
*/
|
||||||
|
export class Sas9JobExecutor extends BaseJobExecutor {
|
||||||
|
private requestClient: Sas9RequestClient
|
||||||
|
constructor(
|
||||||
|
serverUrl: string,
|
||||||
|
serverType: ServerType,
|
||||||
|
private jobsPath: string
|
||||||
|
) {
|
||||||
|
super(serverUrl, serverType)
|
||||||
|
this.requestClient = new Sas9RequestClient(serverUrl, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
async execute(sasJob: string, data: any, config: any) {
|
||||||
|
const program = isRelativePath(sasJob)
|
||||||
|
? config.appLoc
|
||||||
|
? config.appLoc.replace(/\/?$/, '/') + sasJob.replace(/^\//, '')
|
||||||
|
: sasJob
|
||||||
|
: sasJob
|
||||||
|
let apiUrl = `${config.serverUrl}${this.jobsPath}?${'_program=' + program}`
|
||||||
|
apiUrl = `${apiUrl}${
|
||||||
|
config.username && config.password
|
||||||
|
? '&_username=' + config.username + '&_password=' + config.password
|
||||||
|
: ''
|
||||||
|
}`
|
||||||
|
|
||||||
|
let requestParams = {
|
||||||
|
...this.getRequestParams(config)
|
||||||
|
}
|
||||||
|
|
||||||
|
let formData = new NodeFormData()
|
||||||
|
|
||||||
|
if (data) {
|
||||||
|
try {
|
||||||
|
formData = generateFileUploadForm(formData, data)
|
||||||
|
} catch (e) {
|
||||||
|
return Promise.reject(new ErrorResponse(e?.message, e))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const key in requestParams) {
|
||||||
|
if (requestParams.hasOwnProperty(key)) {
|
||||||
|
formData.append(key, requestParams[key])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.requestClient.login(
|
||||||
|
config.username,
|
||||||
|
config.password,
|
||||||
|
this.jobsPath
|
||||||
|
)
|
||||||
|
const contentType =
|
||||||
|
data && Object.keys(data).length
|
||||||
|
? 'multipart/form-data; boundary=' + (formData as any)._boundary
|
||||||
|
: 'text/plain'
|
||||||
|
return await this.requestClient!.post(
|
||||||
|
apiUrl,
|
||||||
|
formData,
|
||||||
|
undefined,
|
||||||
|
contentType,
|
||||||
|
{
|
||||||
|
Accept: '*/*',
|
||||||
|
Connection: 'Keep-Alive'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private getRequestParams(config: any): any {
|
||||||
|
const requestParams: any = {}
|
||||||
|
|
||||||
|
if (config.debug) {
|
||||||
|
requestParams['_debug'] = 131
|
||||||
|
}
|
||||||
|
|
||||||
|
return requestParams
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const generateFileUploadForm = (
|
||||||
|
formData: NodeFormData,
|
||||||
|
data: any
|
||||||
|
): NodeFormData => {
|
||||||
|
for (const tableName in data) {
|
||||||
|
const name = tableName
|
||||||
|
const csv = convertToCSV(data[tableName])
|
||||||
|
if (csv === 'ERROR: LARGE STRING LENGTH') {
|
||||||
|
throw new Error(
|
||||||
|
'The max length of a string value in SASjs is 32765 characters.'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
formData.append(name, csv, {
|
||||||
|
filename: `${name}.csv`,
|
||||||
|
contentType: 'application/csv'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return formData
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
export * from './ComputeJobExecutor'
|
export * from './ComputeJobExecutor'
|
||||||
export * from './JesJobExecutor'
|
export * from './JesJobExecutor'
|
||||||
export * from './JobExecutor'
|
export * from './JobExecutor'
|
||||||
|
export * from './Sas9JobExecutor'
|
||||||
export * from './WebJobExecutor'
|
export * from './WebJobExecutor'
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
} from '../types/errors'
|
} from '../types/errors'
|
||||||
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
|
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
|
||||||
import { prefixMessage } from '@sasjs/utils/error'
|
import { prefixMessage } from '@sasjs/utils/error'
|
||||||
|
import { SAS9AuthError } from '../types/errors/SAS9AuthError'
|
||||||
|
|
||||||
export interface HttpClient {
|
export interface HttpClient {
|
||||||
get<T>(
|
get<T>(
|
||||||
@@ -44,11 +45,11 @@ export interface HttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class RequestClient implements HttpClient {
|
export class RequestClient implements HttpClient {
|
||||||
private csrfToken: CsrfToken = { headerName: '', value: '' }
|
protected csrfToken: CsrfToken = { headerName: '', value: '' }
|
||||||
private fileUploadCsrfToken: CsrfToken | undefined
|
protected fileUploadCsrfToken: CsrfToken | undefined
|
||||||
private httpClient: AxiosInstance
|
protected httpClient: AxiosInstance
|
||||||
|
|
||||||
constructor(private baseUrl: string, allowInsecure = false) {
|
constructor(protected baseUrl: string, allowInsecure = false) {
|
||||||
const https = require('https')
|
const https = require('https')
|
||||||
if (allowInsecure && https.Agent) {
|
if (allowInsecure && https.Agent) {
|
||||||
this.httpClient = axios.create({
|
this.httpClient = axios.create({
|
||||||
@@ -290,7 +291,7 @@ export class RequestClient implements HttpClient {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private getHeaders = (
|
protected getHeaders = (
|
||||||
accessToken: string | undefined,
|
accessToken: string | undefined,
|
||||||
contentType: string
|
contentType: string
|
||||||
) => {
|
) => {
|
||||||
@@ -315,7 +316,7 @@ export class RequestClient implements HttpClient {
|
|||||||
return headers
|
return headers
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseAndSetFileUploadCsrfToken = (response: AxiosResponse) => {
|
protected parseAndSetFileUploadCsrfToken = (response: AxiosResponse) => {
|
||||||
const token = this.parseCsrfToken(response)
|
const token = this.parseCsrfToken(response)
|
||||||
|
|
||||||
if (token) {
|
if (token) {
|
||||||
@@ -323,7 +324,7 @@ export class RequestClient implements HttpClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseAndSetCsrfToken = (response: AxiosResponse) => {
|
protected parseAndSetCsrfToken = (response: AxiosResponse) => {
|
||||||
const token = this.parseCsrfToken(response)
|
const token = this.parseCsrfToken(response)
|
||||||
|
|
||||||
if (token) {
|
if (token) {
|
||||||
@@ -347,7 +348,7 @@ export class RequestClient implements HttpClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleError = async (
|
protected handleError = async (
|
||||||
e: any,
|
e: any,
|
||||||
callback: any,
|
callback: any,
|
||||||
debug: boolean = false
|
debug: boolean = false
|
||||||
@@ -405,7 +406,7 @@ export class RequestClient implements HttpClient {
|
|||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseResponse<T>(response: AxiosResponse<any>) {
|
protected parseResponse<T>(response: AxiosResponse<any>) {
|
||||||
const etag = response?.headers ? response.headers['etag'] : ''
|
const etag = response?.headers ? response.headers['etag'] : ''
|
||||||
let parsedResponse
|
let parsedResponse
|
||||||
let includeSAS9Log: boolean = false
|
let includeSAS9Log: boolean = false
|
||||||
@@ -439,7 +440,7 @@ export class RequestClient implements HttpClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const throwIfError = (response: AxiosResponse) => {
|
export const throwIfError = (response: AxiosResponse) => {
|
||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
throw new LoginRequiredError()
|
throw new LoginRequiredError()
|
||||||
}
|
}
|
||||||
@@ -470,6 +471,10 @@ const throwIfError = (response: AxiosResponse) => {
|
|||||||
throw new AuthorizeError(response.data.message, authorizeRequestUrl)
|
throw new AuthorizeError(response.data.message, authorizeRequestUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (response.config?.url?.includes('sasAuthError')) {
|
||||||
|
throw new SAS9AuthError()
|
||||||
|
}
|
||||||
|
|
||||||
const error = parseError(response.data as string)
|
const error = parseError(response.data as string)
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|||||||
121
src/request/Sas9RequestClient.ts
Normal file
121
src/request/Sas9RequestClient.ts
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
import { AxiosRequestConfig } from 'axios'
|
||||||
|
import axiosCookieJarSupport from 'axios-cookiejar-support'
|
||||||
|
import * as tough from 'tough-cookie'
|
||||||
|
import { prefixMessage } from '@sasjs/utils/error'
|
||||||
|
import { RequestClient, throwIfError } from './RequestClient'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specific request client for SAS9 in Node.js environments.
|
||||||
|
* Handles redirects and cookie management.
|
||||||
|
*/
|
||||||
|
export class Sas9RequestClient extends RequestClient {
|
||||||
|
constructor(baseUrl: string, allowInsecure = false) {
|
||||||
|
super(baseUrl, allowInsecure)
|
||||||
|
this.httpClient.defaults.maxRedirects = 0
|
||||||
|
this.httpClient.defaults.validateStatus = (status) =>
|
||||||
|
status >= 200 && status < 303
|
||||||
|
|
||||||
|
if (axiosCookieJarSupport) {
|
||||||
|
axiosCookieJarSupport(this.httpClient)
|
||||||
|
this.httpClient.defaults.jar = new tough.CookieJar()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async login(username: string, password: string, jobsPath: string) {
|
||||||
|
const codeInjectorPath = `/User Folders/${username}/My Folder/sasjs/runner`
|
||||||
|
if (this.httpClient.defaults.jar) {
|
||||||
|
;(this.httpClient.defaults.jar as tough.CookieJar).removeAllCookies()
|
||||||
|
await this.get(
|
||||||
|
`${jobsPath}?_program=${codeInjectorPath}&_username=${username}&_password=${password}`,
|
||||||
|
undefined,
|
||||||
|
'text/plain'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async get<T>(
|
||||||
|
url: string,
|
||||||
|
accessToken: string | undefined,
|
||||||
|
contentType: string = 'application/json',
|
||||||
|
overrideHeaders: { [key: string]: string | number } = {},
|
||||||
|
debug: boolean = false
|
||||||
|
): Promise<{ result: T; etag: string }> {
|
||||||
|
const headers = {
|
||||||
|
...this.getHeaders(accessToken, contentType),
|
||||||
|
...overrideHeaders
|
||||||
|
}
|
||||||
|
|
||||||
|
const requestConfig: AxiosRequestConfig = {
|
||||||
|
headers,
|
||||||
|
responseType: contentType === 'text/plain' ? 'text' : 'json',
|
||||||
|
withCredentials: true
|
||||||
|
}
|
||||||
|
if (contentType === 'text/plain') {
|
||||||
|
requestConfig.transformResponse = undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.httpClient
|
||||||
|
.get<T>(url, requestConfig)
|
||||||
|
.then((response) => {
|
||||||
|
if (response.status === 302) {
|
||||||
|
return this.get(
|
||||||
|
response.headers['location'],
|
||||||
|
accessToken,
|
||||||
|
contentType
|
||||||
|
)
|
||||||
|
}
|
||||||
|
throwIfError(response)
|
||||||
|
return this.parseResponse<T>(response)
|
||||||
|
})
|
||||||
|
.catch(async (e) => {
|
||||||
|
return await this.handleError(
|
||||||
|
e,
|
||||||
|
() =>
|
||||||
|
this.get<T>(url, accessToken, contentType, overrideHeaders).catch(
|
||||||
|
(err) => {
|
||||||
|
throw prefixMessage(
|
||||||
|
err,
|
||||||
|
'Error while executing handle error callback. '
|
||||||
|
)
|
||||||
|
}
|
||||||
|
),
|
||||||
|
debug
|
||||||
|
).catch((err) => {
|
||||||
|
throw prefixMessage(err, 'Error while handling error. ')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public post<T>(
|
||||||
|
url: string,
|
||||||
|
data: any,
|
||||||
|
accessToken: string | undefined,
|
||||||
|
contentType = 'application/json',
|
||||||
|
overrideHeaders: { [key: string]: string | number } = {}
|
||||||
|
): Promise<{ result: T; etag: string }> {
|
||||||
|
const headers = {
|
||||||
|
...this.getHeaders(accessToken, contentType),
|
||||||
|
...overrideHeaders
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.httpClient
|
||||||
|
.post<T>(url, data, { headers, withCredentials: true })
|
||||||
|
.then(async (response) => {
|
||||||
|
if (response.status === 302) {
|
||||||
|
return await this.get(
|
||||||
|
response.headers['location'],
|
||||||
|
undefined,
|
||||||
|
contentType,
|
||||||
|
overrideHeaders
|
||||||
|
)
|
||||||
|
}
|
||||||
|
throwIfError(response)
|
||||||
|
return this.parseResponse<T>(response)
|
||||||
|
})
|
||||||
|
.catch(async (e) => {
|
||||||
|
return await this.handleError(e, () =>
|
||||||
|
this.post<T>(url, data, accessToken, contentType, overrideHeaders)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
|
/**
|
||||||
|
* @jest-environment jsdom
|
||||||
|
*/
|
||||||
|
|
||||||
import { FileUploader } from '../FileUploader'
|
import { FileUploader } from '../FileUploader'
|
||||||
import { UploadFile } from '../types'
|
import { UploadFile } from '../types'
|
||||||
import { RequestClient } from '../request/RequestClient'
|
import { RequestClient } from '../request/RequestClient'
|
||||||
@@ -35,41 +39,40 @@ describe('FileUploader', () => {
|
|||||||
new RequestClient('https://sample.server.com')
|
new RequestClient('https://sample.server.com')
|
||||||
)
|
)
|
||||||
|
|
||||||
it('should upload successfully', async (done) => {
|
it('should upload successfully', async () => {
|
||||||
const sasJob = 'test/upload'
|
const sasJob = 'test/upload'
|
||||||
const { files, params } = prepareFilesAndParams()
|
const { files, params } = prepareFilesAndParams()
|
||||||
mockedAxios.post.mockImplementation(() =>
|
mockedAxios.post.mockImplementation(() =>
|
||||||
Promise.resolve({ data: sampleResponse })
|
Promise.resolve({ data: sampleResponse })
|
||||||
)
|
)
|
||||||
|
|
||||||
fileUploader.uploadFile(sasJob, files, params).then((res: any) => {
|
const res = await fileUploader.uploadFile(sasJob, files, params)
|
||||||
expect(res).toEqual(JSON.parse(sampleResponse))
|
|
||||||
done()
|
expect(res).toEqual(JSON.parse(sampleResponse))
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should an error when no files are provided', async (done) => {
|
it('should an error when no files are provided', async () => {
|
||||||
const sasJob = 'test/upload'
|
const sasJob = 'test/upload'
|
||||||
const files: UploadFile[] = []
|
const files: UploadFile[] = []
|
||||||
const params = { table: 'libtable' }
|
const params = { table: 'libtable' }
|
||||||
|
|
||||||
fileUploader.uploadFile(sasJob, files, params).catch((err: any) => {
|
const err = await fileUploader
|
||||||
expect(err.error.message).toEqual('At least one file must be provided.')
|
.uploadFile(sasJob, files, params)
|
||||||
done()
|
.catch((err: any) => err)
|
||||||
})
|
expect(err.error.message).toEqual('At least one file must be provided.')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should throw an error when no sasJob is provided', async (done) => {
|
it('should throw an error when no sasJob is provided', async () => {
|
||||||
const sasJob = ''
|
const sasJob = ''
|
||||||
const { files, params } = prepareFilesAndParams()
|
const { files, params } = prepareFilesAndParams()
|
||||||
|
|
||||||
fileUploader.uploadFile(sasJob, files, params).catch((err: any) => {
|
const err = await fileUploader
|
||||||
expect(err.error.message).toEqual('sasJob must be provided.')
|
.uploadFile(sasJob, files, params)
|
||||||
done()
|
.catch((err: any) => err)
|
||||||
})
|
expect(err.error.message).toEqual('sasJob must be provided.')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should throw an error when login is required', async (done) => {
|
it('should throw an error when login is required', async () => {
|
||||||
mockedAxios.post.mockImplementation(() =>
|
mockedAxios.post.mockImplementation(() =>
|
||||||
Promise.resolve({ data: '<form action="Logon">' })
|
Promise.resolve({ data: '<form action="Logon">' })
|
||||||
)
|
)
|
||||||
@@ -77,15 +80,13 @@ describe('FileUploader', () => {
|
|||||||
const sasJob = 'test'
|
const sasJob = 'test'
|
||||||
const { files, params } = prepareFilesAndParams()
|
const { files, params } = prepareFilesAndParams()
|
||||||
|
|
||||||
fileUploader.uploadFile(sasJob, files, params).catch((err: any) => {
|
const err = await fileUploader
|
||||||
expect(err.error.message).toEqual(
|
.uploadFile(sasJob, files, params)
|
||||||
'You must be logged in to upload a file.'
|
.catch((err: any) => err)
|
||||||
)
|
expect(err.error.message).toEqual('You must be logged in to upload a file.')
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should throw an error when invalid JSON is returned by the server', async (done) => {
|
it('should throw an error when invalid JSON is returned by the server', async () => {
|
||||||
mockedAxios.post.mockImplementation(() =>
|
mockedAxios.post.mockImplementation(() =>
|
||||||
Promise.resolve({ data: '{invalid: "json"' })
|
Promise.resolve({ data: '{invalid: "json"' })
|
||||||
)
|
)
|
||||||
@@ -93,13 +94,13 @@ describe('FileUploader', () => {
|
|||||||
const sasJob = 'test'
|
const sasJob = 'test'
|
||||||
const { files, params } = prepareFilesAndParams()
|
const { files, params } = prepareFilesAndParams()
|
||||||
|
|
||||||
fileUploader.uploadFile(sasJob, files, params).catch((err: any) => {
|
const err = await fileUploader
|
||||||
expect(err.error.message).toEqual('File upload request failed.')
|
.uploadFile(sasJob, files, params)
|
||||||
done()
|
.catch((err: any) => err)
|
||||||
})
|
expect(err.error.message).toEqual('File upload request failed.')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should throw an error when the server request fails', async (done) => {
|
it('should throw an error when the server request fails', async () => {
|
||||||
mockedAxios.post.mockImplementation(() =>
|
mockedAxios.post.mockImplementation(() =>
|
||||||
Promise.reject({ data: '{message: "Server error"}' })
|
Promise.reject({ data: '{message: "Server error"}' })
|
||||||
)
|
)
|
||||||
@@ -107,10 +108,9 @@ describe('FileUploader', () => {
|
|||||||
const sasJob = 'test'
|
const sasJob = 'test'
|
||||||
const { files, params } = prepareFilesAndParams()
|
const { files, params } = prepareFilesAndParams()
|
||||||
|
|
||||||
fileUploader.uploadFile(sasJob, files, params).catch((err: any) => {
|
const err = await fileUploader
|
||||||
expect(err.error.message).toEqual('File upload request failed.')
|
.uploadFile(sasJob, files, params)
|
||||||
|
.catch((err: any) => err)
|
||||||
done()
|
expect(err.error.message).toEqual('File upload request failed.')
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ describe('FolderOperations', () => {
|
|||||||
|
|
||||||
beforeEach(() => {})
|
beforeEach(() => {})
|
||||||
|
|
||||||
it('should move and rename folder', async (done) => {
|
it('should move and rename folder', async () => {
|
||||||
mockFetchResponse(false)
|
mockFetchResponse(false)
|
||||||
|
|
||||||
let res: any = await sasViyaApiClient.moveFolder(
|
let res: any = await sasViyaApiClient.moveFolder(
|
||||||
@@ -26,11 +26,9 @@ describe('FolderOperations', () => {
|
|||||||
|
|
||||||
expect(res.folder.name).toEqual('newName')
|
expect(res.folder.name).toEqual('newName')
|
||||||
expect(res.folder.parentFolderUri.split('=')[1]).toEqual('/Test/toFolder')
|
expect(res.folder.parentFolderUri.split('=')[1]).toEqual('/Test/toFolder')
|
||||||
|
|
||||||
done()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should move and keep the name of folder', async (done) => {
|
it('should move and keep the name of folder', async () => {
|
||||||
mockFetchResponse(true)
|
mockFetchResponse(true)
|
||||||
|
|
||||||
let res: any = await sasViyaApiClient.moveFolder(
|
let res: any = await sasViyaApiClient.moveFolder(
|
||||||
@@ -42,11 +40,9 @@ describe('FolderOperations', () => {
|
|||||||
|
|
||||||
expect(res.folder.name).toEqual('oldName')
|
expect(res.folder.name).toEqual('oldName')
|
||||||
expect(res.folder.parentFolderUri.split('=')[1]).toEqual('/Test/toFolder')
|
expect(res.folder.parentFolderUri.split('=')[1]).toEqual('/Test/toFolder')
|
||||||
|
|
||||||
done()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should only rename folder', async (done) => {
|
it('should only rename folder', async () => {
|
||||||
mockFetchResponse(false)
|
mockFetchResponse(false)
|
||||||
|
|
||||||
let res: any = await sasViyaApiClient.moveFolder(
|
let res: any = await sasViyaApiClient.moveFolder(
|
||||||
@@ -58,8 +54,6 @@ describe('FolderOperations', () => {
|
|||||||
|
|
||||||
expect(res.folder.name).toEqual('newName')
|
expect(res.folder.name).toEqual('newName')
|
||||||
expect(res.folder.parentFolderUri.split('=')[1]).toEqual('/Test/toFolder')
|
expect(res.folder.parentFolderUri.split('=')[1]).toEqual('/Test/toFolder')
|
||||||
|
|
||||||
done()
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { parseGeneratedCode } from '../../utils/index'
|
import { parseGeneratedCode } from '../../utils/index'
|
||||||
|
|
||||||
it('should parse generated code', async (done) => {
|
it('should parse generated code', () => {
|
||||||
expect(sampleResponse).toBeTruthy()
|
expect(sampleResponse).toBeTruthy()
|
||||||
|
|
||||||
const parsedGeneratedCode = parseGeneratedCode(sampleResponse)
|
const parsedGeneratedCode = parseGeneratedCode(sampleResponse)
|
||||||
@@ -15,8 +15,6 @@ it('should parse generated code', async (done) => {
|
|||||||
expect(generatedCodeLines[2].startsWith('MPRINT(MM_WEBOUT)')).toBeTruthy()
|
expect(generatedCodeLines[2].startsWith('MPRINT(MM_WEBOUT)')).toBeTruthy()
|
||||||
expect(generatedCodeLines[3].startsWith('MPRINT(MM_WEBRIGHT)')).toBeTruthy()
|
expect(generatedCodeLines[3].startsWith('MPRINT(MM_WEBRIGHT)')).toBeTruthy()
|
||||||
expect(generatedCodeLines[4].startsWith('MPRINT(MM_WEBOUT)')).toBeTruthy()
|
expect(generatedCodeLines[4].startsWith('MPRINT(MM_WEBOUT)')).toBeTruthy()
|
||||||
|
|
||||||
done()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
/* tslint:disable */
|
/* tslint:disable */
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { parseSourceCode } from '../../utils/index'
|
import { parseSourceCode } from '../../utils/index'
|
||||||
|
|
||||||
it('should parse SAS9 source code', async (done) => {
|
it('should parse SAS9 source code', async () => {
|
||||||
expect(sampleResponse).toBeTruthy()
|
expect(sampleResponse).toBeTruthy()
|
||||||
|
|
||||||
const parsedSourceCode = parseSourceCode(sampleResponse)
|
const parsedSourceCode = parseSourceCode(sampleResponse)
|
||||||
@@ -15,8 +15,6 @@ it('should parse SAS9 source code', async (done) => {
|
|||||||
expect(sourceCodeLines[2].startsWith('8')).toBeTruthy()
|
expect(sourceCodeLines[2].startsWith('8')).toBeTruthy()
|
||||||
expect(sourceCodeLines[3].startsWith('9')).toBeTruthy()
|
expect(sourceCodeLines[3].startsWith('9')).toBeTruthy()
|
||||||
expect(sourceCodeLines[4].startsWith('10')).toBeTruthy()
|
expect(sourceCodeLines[4].startsWith('10')).toBeTruthy()
|
||||||
|
|
||||||
done()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
/* tslint:disable */
|
/* tslint:disable */
|
||||||
|
|||||||
9
src/types/errors/SAS9AuthError.ts
Normal file
9
src/types/errors/SAS9AuthError.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
export class SAS9AuthError extends Error {
|
||||||
|
constructor() {
|
||||||
|
super(
|
||||||
|
'The credentials you provided cannot be authenticated. Please provide a valid set of credentials.'
|
||||||
|
)
|
||||||
|
this.name = 'AuthorizeError'
|
||||||
|
Object.setPrototypeOf(this, SAS9AuthError.prototype)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,11 +7,10 @@ const browserConfig = {
|
|||||||
devtool: 'inline-source-map',
|
devtool: 'inline-source-map',
|
||||||
mode: 'production',
|
mode: 'production',
|
||||||
optimization: {
|
optimization: {
|
||||||
|
minimize: true,
|
||||||
minimizer: [
|
minimizer: [
|
||||||
new terserPlugin({
|
new terserPlugin({
|
||||||
cache: true,
|
|
||||||
parallel: true,
|
parallel: true,
|
||||||
sourceMap: true,
|
|
||||||
terserOptions: {}
|
terserOptions: {}
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
@@ -41,6 +40,9 @@ const browserConfig = {
|
|||||||
filename: null,
|
filename: null,
|
||||||
exclude: [/node_modules/],
|
exclude: [/node_modules/],
|
||||||
test: /\.ts($|\?)/i
|
test: /\.ts($|\?)/i
|
||||||
|
}),
|
||||||
|
new webpack.ProvidePlugin({
|
||||||
|
process: 'process/browser'
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user