1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-08 13:00:05 +00:00

Compare commits

..

1 Commits

Author SHA1 Message Date
Saad Jutt
66061c6471 fix(loginPrompt): z-index added 2021-09-10 20:41:43 +05:00
117 changed files with 3587 additions and 30245 deletions

View File

@@ -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

View File

@@ -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

2
.gitignore vendored
View File

@@ -5,4 +5,4 @@ build
/coverage /coverage
.DS_Store .DS_Store

View File

@@ -3,4 +3,3 @@ docs/
.github/ .github/
*.md *.md
*.spec.ts *.spec.ts
.all-contributorsrc

View File

@@ -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'
} }
``` ```

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

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

20051
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -41,40 +41,36 @@
"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": "^27.0.1",
"@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.1.0",
"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.7",
"terser-webpack-plugin": "^5.2.4", "terser-webpack-plugin": "^5.2.0",
"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.9",
"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.30.0",
"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",

View File

@@ -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",

View File

@@ -13,6 +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,
allowInsecureRequests: false,
loginMechanism: LoginMechanism.Default loginMechanism: LoginMechanism.Default
} }
@@ -77,8 +78,8 @@ export const basicTests = (
'common/sendArr', 'common/sendArr',
stringData, stringData,
undefined, undefined,
async () => { () => {
await adapter.logIn(userName, password) adapter.logIn(userName, password)
} }
) )
}, },

98
src/FileUploader.ts Normal file
View File

@@ -0,0 +1,98 @@
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'
}
// currently only web approach is supported for file upload
// therefore log is part of response with debug enabled and must be parsed
return this.requestClient
.post(uploadUrl, formData, undefined, 'application/json', headers)
.then(async (res) => {
if (
this.sasjsConfig.serverType === ServerType.SasViya &&
this.sasjsConfig.debug
) {
const jsonResponse = await parseSasViyaDebugResponse(
res.result as string,
this.requestClient,
this.sasjsConfig.serverUrl
)
return 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)
)
})
}
}

View File

@@ -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'
@@ -14,10 +13,10 @@ export class SAS9ApiClient {
constructor( constructor(
private serverUrl: string, private serverUrl: string,
private jobsPath: string, private jobsPath: string,
httpsAgentOptions?: https.AgentOptions allowInsecureRequests: boolean
) { ) {
if (serverUrl) isUrl(serverUrl) if (serverUrl) isUrl(serverUrl)
this.requestClient = new Sas9RequestClient(serverUrl, httpsAgentOptions) this.requestClient = new Sas9RequestClient(serverUrl, allowInsecureRequests)
} }
/** /**

View File

@@ -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
} }

View File

@@ -4,14 +4,11 @@ import {
UploadFile, UploadFile,
EditContextInput, EditContextInput,
PollOptions, PollOptions,
LoginMechanism, LoginMechanism
FolderMember,
ServiceMember,
ExecutionQuery
} from './types' } from './types'
import { SASViyaApiClient } from './SASViyaApiClient' import { SASViyaApiClient } from './SASViyaApiClient'
import { SAS9ApiClient } from './SAS9ApiClient' import { SAS9ApiClient } from './SAS9ApiClient'
import { SASjsApiClient } from './SASjsApiClient' import { FileUploader } from './FileUploader'
import { AuthManager } from './auth' import { AuthManager } from './auth'
import { import {
ServerType, ServerType,
@@ -25,15 +22,13 @@ import {
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' 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',
@@ -41,6 +36,7 @@ const defaultConfig: SASjsConfig = {
debug: false, debug: false,
contextName: 'SAS Job Execution compute context', contextName: 'SAS Job Execution compute context',
useComputeApi: null, useComputeApi: null,
allowInsecureRequests: false,
loginMechanism: LoginMechanism.Default loginMechanism: LoginMechanism.Default
} }
@@ -53,7 +49,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
@@ -62,7 +57,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
@@ -512,7 +507,7 @@ export default class SASjs {
...this.sasjsConfig, ...this.sasjsConfig,
...config ...config
} }
this.setupConfiguration() await this.setupConfiguration()
} }
/** /**
@@ -528,11 +523,10 @@ export default class SASjs {
/** /**
* Checks whether a session is active, or login is required. * Checks whether a session is active, or login is required.
* @param accessToken - an optional access token is required for SASjs server type.
* @returns - a promise which resolves with an object containing two values - a boolean `isLoggedIn`, and a string `userName`. * @returns - a promise which resolves with an object containing two values - a boolean `isLoggedIn`, and a string `userName`.
*/ */
public async checkSession(accessToken?: string) { public async checkSession() {
return this.authManager!.checkSession(accessToken) return this.authManager!.checkSession()
} }
/** /**
@@ -565,10 +559,9 @@ export default class SASjs {
/** /**
* Logs out of the configured SAS server. * Logs out of the configured SAS server.
* @param accessToken - an optional access token is required for SASjs server type.
*/ */
public logOut(accessToken?: string) { public logOut() {
return this.authManager!.logOut(accessToken) return this.authManager!.logOut()
} }
/** /**
@@ -578,32 +571,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
)
} }
/** /**
@@ -799,7 +784,7 @@ export default class SASjs {
sasApiClient = new SAS9ApiClient( sasApiClient = new SAS9ApiClient(
serverUrl, serverUrl,
this.jobsPath, this.jobsPath,
this.sasjsConfig.httpsAgentOptions this.sasjsConfig.allowInsecureRequests
) )
} }
} else { } else {
@@ -831,14 +816,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.
@@ -897,7 +874,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()
} }
/** /**
@@ -929,18 +905,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() {
@@ -963,24 +941,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(
this.requestClient = new RequestClient( this.sasjsConfig.serverUrl,
this.sasjsConfig.serverUrl, this.sasjsConfig.allowInsecureRequests
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,
@@ -990,49 +959,34 @@ 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 this.sasjsConfig.allowInsecureRequests
) )
}
}
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
) )
@@ -1049,8 +1003,7 @@ export default class SASjs {
this.sasjsConfig.serverUrl, this.sasjsConfig.serverUrl,
this.sasjsConfig.serverType!, this.sasjsConfig.serverType!,
this.jobsPath, this.jobsPath,
this.requestClient, this.sasjsConfig.allowInsecureRequests
this.sasjsConfig.httpsAgentOptions
) )
this.computeJobExecutor = new ComputeJobExecutor( this.computeJobExecutor = new ComputeJobExecutor(

View File

@@ -1,39 +0,0 @@
import { FolderMember, ServiceMember, ExecutionQuery } from './types'
import { RequestClient } from './request/RequestClient'
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)
}
}

View File

@@ -21,9 +21,7 @@ export class AuthManager {
this.logoutUrl = this.logoutUrl =
this.serverType === ServerType.Sas9 this.serverType === ServerType.Sas9
? '/SASLogon/logout?' ? '/SASLogon/logout?'
: this.serverType === ServerType.SasViya : '/SASLogon/logout.do?'
? '/SASLogon/logout.do?'
: '/SASjsApi/auth/logout'
} }
/** /**
@@ -182,21 +180,20 @@ export class AuthManager {
/** /**
* Checks whether a session is active, or login is required. * Checks whether a session is active, or login is required.
* @param accessToken - an optional access token is required for SASjs server type.
* @returns - a promise which resolves with an object containing three values * @returns - a promise which resolves with an object containing three values
* - a boolean `isLoggedIn` * - a boolean `isLoggedIn`
* - a string `userName` and * - a string `userName` and
* - a form `loginForm` if not loggedin. * - a form `loginForm` if not loggedin.
*/ */
public async checkSession(accessToken?: string): Promise<{ public async checkSession(): Promise<{
isLoggedIn: boolean isLoggedIn: boolean
userName: string userName: string
loginForm?: any loginForm?: any
}> { }> {
const { isLoggedIn, userName } = await this.fetchUserName(accessToken) const { isLoggedIn, userName } = await this.fetchUserName()
let loginForm = null let loginForm = null
if (!isLoggedIn && this.serverType !== ServerType.Sasjs) { if (!isLoggedIn) {
//We will logout to make sure cookies are removed and login form is presented //We will logout to make sure cookies are removed and login form is presented
//Residue can happen in case of session expiration //Residue can happen in case of session expiration
await this.logOut() await this.logOut()
@@ -221,20 +218,19 @@ export class AuthManager {
return await this.getLoginForm(formResponse) return await this.getLoginForm(formResponse)
} }
private async fetchUserName(accessToken?: string): Promise<{ private async fetchUserName(): Promise<{
isLoggedIn: boolean isLoggedIn: boolean
userName: string userName: string
}> { }> {
//For VIYA we will send request on API endpoint. Which is faster then pinging SASJobExecution.
//For SAS9 we will send request on SASStoredProcess
const url = const url =
this.serverType === ServerType.SasViya this.serverType === ServerType.SasViya
? `${this.serverUrl}/identities/users/@currentUser` ? `${this.serverUrl}/identities/users/@currentUser`
: this.serverType === ServerType.Sas9 : `${this.serverUrl}/SASStoredProcess`
? `${this.serverUrl}/SASStoredProcess`
: `${this.serverUrl}/SASjsApi/session`
// Access token is required for server type `SASjs`
const { result: loginResponse } = await this.requestClient const { result: loginResponse } = await this.requestClient
.get<string>(url, accessToken, 'text/plain') .get<string>(url, undefined, 'text/plain')
.catch((err: any) => { .catch((err: any) => {
return { result: 'authErr' } return { result: 'authErr' }
}) })
@@ -260,13 +256,6 @@ export class AuthManager {
.split(' ') .split(' ')
.map((name: string) => name.slice(0, 3).toLowerCase()) .map((name: string) => name.slice(0, 3).toLowerCase())
.join('') .join('')
case ServerType.Sasjs:
return response?.username
default:
console.error('Server Type not found in extractUserName function')
return ''
} }
} }
@@ -313,12 +302,8 @@ export class AuthManager {
/** /**
* Logs out of the configured SAS server. * Logs out of the configured SAS server.
* @param accessToken - an optional access token is required for SASjs server type.
*/ */
public logOut(accessToken?: string) { public logOut() {
if (this.serverType === ServerType.Sasjs) {
return this.requestClient.post(this.logoutUrl, undefined, accessToken)
}
this.requestClient.clearCsrfTokens() this.requestClient.clearCsrfTokens()
return this.requestClient.get(this.logoutUrl, undefined).then(() => true) return this.requestClient.get(this.logoutUrl, undefined).then(() => true)
} }

View File

@@ -46,7 +46,7 @@ export async function getAccessToken(
) )
.then((res) => res.result as SasAuthResponse) .then((res) => res.result as SasAuthResponse)
.catch((err) => { .catch((err) => {
throw prefixMessage(err, 'Error while getting access token. ') throw prefixMessage(err, 'Error while getting access token')
}) })
return authResponse return authResponse

View File

@@ -35,16 +35,19 @@ export class ComputeJobExecutor extends BaseJobExecutor {
expectWebout expectWebout
) )
.then((response) => { .then((response) => {
this.sasViyaApiClient.appendRequest(response, sasJob, config.debug) this.appendRequest(response, sasJob, config.debug)
resolve(response.result) resolve(response.result)
}) })
.catch(async (e: Error) => { .catch(async (e: Error) => {
if (e instanceof ComputeJobExecutionError) { if (e instanceof ComputeJobExecutionError) {
this.sasViyaApiClient.appendRequest(e, sasJob, config.debug) this.appendRequest(e, sasJob, config.debug)
reject(new ErrorResponse(e?.message, e)) reject(new ErrorResponse(e?.message, e))
} }
if (e instanceof LoginRequiredError) { if (e instanceof LoginRequiredError) {
await loginCallback()
this.appendWaitingRequest(() => { this.appendWaitingRequest(() => {
return this.execute( return this.execute(
sasJob, sasJob,
@@ -60,8 +63,6 @@ export class ComputeJobExecutor extends BaseJobExecutor {
} }
) )
}) })
await loginCallback()
} else { } else {
reject(new ErrorResponse(e?.message, e)) reject(new ErrorResponse(e?.message, e))
} }

View File

@@ -1,143 +0,0 @@
import {
getValidJson,
parseSasViyaDebugResponse,
parseWeboutResponse
} from '../utils'
import { UploadFile } from '../types/UploadFile'
import {
ErrorResponse,
JobExecutionError,
LoginRequiredError
} from '../types/errors'
import { RequestClient } from '../request/RequestClient'
import { ServerType } from '@sasjs/utils/types'
import { BaseJobExecutor } from './JobExecutor'
interface dataFileUpload {
files: UploadFile[]
params: { [key: string]: any } | null
}
export class FileUploader extends BaseJobExecutor {
constructor(
serverUrl: string,
serverType: ServerType,
private jobsPath: string,
private requestClient: RequestClient
) {
super(serverUrl, serverType)
}
public async execute(
sasJob: string,
data: any,
config: any,
loginRequiredCallback?: any
) {
const { files, params }: dataFileUpload = data
const loginCallback = loginRequiredCallback || (() => Promise.resolve())
if (!files?.length)
throw new ErrorResponse('At least one file must be provided.')
if (!sasJob || sasJob === '')
throw new ErrorResponse('sasJob must be provided.')
let paramsString = ''
for (let param in params)
if (params.hasOwnProperty(param))
paramsString += `&${param}=${params[param]}`
const program = config.appLoc
? config.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 (config.debug) formData.append('_debug', '131')
if (config.serverType === ServerType.SasViya && config.contextName)
formData.append('_contextname', config.contextName)
const headers = {
'cache-control': 'no-cache',
Accept: '*/*',
'Content-Type': 'text/plain'
}
// currently only web approach is supported for file upload
// therefore log is part of response with debug enabled and must be parsed
const requestPromise = new Promise((resolve, reject) => {
this.requestClient
.post(uploadUrl, formData, undefined, 'application/json', headers)
.then(async (res: any) => {
this.requestClient.appendRequest(res, sasJob, config.debug)
let jsonResponse = res.result
if (config.debug) {
switch (this.serverType) {
case ServerType.SasViya:
jsonResponse = await parseSasViyaDebugResponse(
res.result,
this.requestClient,
config.serverUrl
)
break
case ServerType.Sas9:
jsonResponse =
typeof res.result === 'string'
? parseWeboutResponse(res.result, uploadUrl)
: res.result
break
}
} else {
jsonResponse =
typeof res.result === 'string'
? getValidJson(res.result)
: res.result
}
resolve(jsonResponse)
})
.catch(async (e: Error) => {
if (e instanceof JobExecutionError) {
this.requestClient!.appendRequest(e, sasJob, config.debug)
reject(new ErrorResponse(e?.message, e))
}
if (e instanceof LoginRequiredError) {
this.appendWaitingRequest(() => {
return this.execute(
sasJob,
data,
config,
loginRequiredCallback
).then(
(res: any) => {
resolve(res)
},
(err: any) => {
reject(err)
}
)
})
await loginCallback()
} else {
reject(new ErrorResponse('File upload request failed.', e))
}
})
})
return requestPromise
}
}

View File

@@ -28,7 +28,7 @@ export class JesJobExecutor extends BaseJobExecutor {
this.sasViyaApiClient this.sasViyaApiClient
?.executeJob(sasJob, config.contextName, config.debug, data, authConfig) ?.executeJob(sasJob, config.contextName, config.debug, data, authConfig)
.then((response: any) => { .then((response: any) => {
this.sasViyaApiClient.appendRequest(response, sasJob, config.debug) this.appendRequest(response, sasJob, config.debug)
const responseObject = appendExtraResponseAttributes( const responseObject = appendExtraResponseAttributes(
response, response,
@@ -39,12 +39,14 @@ export class JesJobExecutor extends BaseJobExecutor {
}) })
.catch(async (e: Error) => { .catch(async (e: Error) => {
if (e instanceof JobExecutionError) { if (e instanceof JobExecutionError) {
this.sasViyaApiClient.appendRequest(e, sasJob, config.debug) this.appendRequest(e, sasJob, config.debug)
reject(new ErrorResponse(e?.message, e)) reject(new ErrorResponse(e?.message, e))
} }
if (e instanceof LoginRequiredError) { if (e instanceof LoginRequiredError) {
await loginCallback()
this.appendWaitingRequest(() => { this.appendWaitingRequest(() => {
return this.execute( return this.execute(
sasJob, sasJob,
@@ -62,8 +64,6 @@ export class JesJobExecutor extends BaseJobExecutor {
} }
) )
}) })
await loginCallback()
} else { } else {
reject(new ErrorResponse(e?.message, e)) reject(new ErrorResponse(e?.message, e))
} }

View File

@@ -1,6 +1,7 @@
import { AuthConfig, ServerType } from '@sasjs/utils/types' import { AuthConfig, ServerType } from '@sasjs/utils/types'
import { SASjsRequest } from '../types'
import { ExtraResponseAttributes } from '@sasjs/utils/types' import { ExtraResponseAttributes } from '@sasjs/utils/types'
import { asyncForEach } from '../utils' import { asyncForEach, parseGeneratedCode, parseSourceCode } from '../utils'
export type ExecuteFunction = () => Promise<any> export type ExecuteFunction = () => Promise<any>
@@ -14,12 +15,15 @@ export interface JobExecutor {
extraResponseAttributes?: ExtraResponseAttributes[] extraResponseAttributes?: ExtraResponseAttributes[]
) => Promise<any> ) => Promise<any>
resendWaitingRequests: () => Promise<void> resendWaitingRequests: () => Promise<void>
getRequests: () => SASjsRequest[]
clearRequests: () => void
} }
export abstract class BaseJobExecutor implements JobExecutor { export abstract class BaseJobExecutor implements JobExecutor {
constructor(protected serverUrl: string, protected serverType: ServerType) {} constructor(protected serverUrl: string, protected serverType: ServerType) {}
private waitingRequests: ExecuteFunction[] = [] private waitingRequests: ExecuteFunction[] = []
private requests: SASjsRequest[] = []
abstract execute( abstract execute(
sasJob: string, sasJob: string,
@@ -42,7 +46,54 @@ export abstract class BaseJobExecutor implements JobExecutor {
return return
} }
getRequests = () => this.requests
clearRequests = () => {
this.requests = []
}
protected appendWaitingRequest(request: ExecuteFunction) { protected appendWaitingRequest(request: ExecuteFunction) {
this.waitingRequests.push(request) this.waitingRequests.push(request)
} }
protected appendRequest(response: any, program: string, debug: boolean) {
let sourceCode = ''
let generatedCode = ''
let sasWork = null
if (debug) {
if (response?.log) {
sourceCode = parseSourceCode(response.log)
generatedCode = parseGeneratedCode(response.log)
if (response?.result) {
sasWork = response.result.WORK
} else {
sasWork = response.log
}
} else if (response?.result) {
sourceCode = parseSourceCode(response.result)
generatedCode = parseGeneratedCode(response.result)
sasWork = response.result.WORK
}
}
const stringifiedResult =
typeof response?.result === 'string'
? response?.result
: JSON.stringify(response?.result, null, 2)
this.requests.push({
logFile: response?.log || stringifiedResult || response,
serviceLink: program,
timestamp: new Date(),
sourceCode,
generatedCode,
SASWORK: sasWork
})
if (this.requests.length > 20) {
this.requests.splice(0, 1)
}
}
} }

View File

@@ -1,11 +1,9 @@
import * as https from 'https'
import { ServerType } from '@sasjs/utils/types' import { ServerType } from '@sasjs/utils/types'
import * as NodeFormData from 'form-data' import * as NodeFormData from 'form-data'
import { ErrorResponse } from '../types/errors' import { ErrorResponse } from '../types/errors'
import { convertToCSV, isRelativePath } from '../utils' import { convertToCSV, isRelativePath } from '../utils'
import { BaseJobExecutor } from './JobExecutor' import { BaseJobExecutor } from './JobExecutor'
import { Sas9RequestClient } from '../request/Sas9RequestClient' import { Sas9RequestClient } from '../request/Sas9RequestClient'
import { RequestClient } from '../request/RequestClient'
/** /**
* Job executor for SAS9 servers for use in Node.js environments. * Job executor for SAS9 servers for use in Node.js environments.
@@ -14,16 +12,15 @@ import { RequestClient } from '../request/RequestClient'
* job execution requests. * job execution requests.
*/ */
export class Sas9JobExecutor extends BaseJobExecutor { export class Sas9JobExecutor extends BaseJobExecutor {
private sas9RequestClient: Sas9RequestClient private requestClient: Sas9RequestClient
constructor( constructor(
serverUrl: string, serverUrl: string,
serverType: ServerType, serverType: ServerType,
private jobsPath: string, private jobsPath: string,
private requestClient: RequestClient, allowInsecureRequests: boolean
httpsAgentOptions?: https.AgentOptions
) { ) {
super(serverUrl, serverType) super(serverUrl, serverType)
this.sas9RequestClient = new Sas9RequestClient(serverUrl, httpsAgentOptions) this.requestClient = new Sas9RequestClient(serverUrl, allowInsecureRequests)
} }
async execute(sasJob: string, data: any, config: any) { async execute(sasJob: string, data: any, config: any) {
@@ -39,8 +36,6 @@ export class Sas9JobExecutor extends BaseJobExecutor {
: '' : ''
}` }`
apiUrl = `${apiUrl}${config.debug ? '&_debug=131' : ''}`
let requestParams = { let requestParams = {
...this.getRequestParams(config) ...this.getRequestParams(config)
} }
@@ -50,11 +45,9 @@ export class Sas9JobExecutor extends BaseJobExecutor {
if (data) { if (data) {
try { try {
formData = generateFileUploadForm(formData, data) formData = generateFileUploadForm(formData, data)
} catch (e: any) { } catch (e) {
return Promise.reject(new ErrorResponse(e?.message, e)) return Promise.reject(new ErrorResponse(e?.message, e))
} }
} else {
data = ''
} }
for (const key in requestParams) { for (const key in requestParams) {
@@ -63,18 +56,16 @@ export class Sas9JobExecutor extends BaseJobExecutor {
} }
} }
await this.sas9RequestClient.login( await this.requestClient.login(
config.username, config.username,
config.password, config.password,
this.jobsPath this.jobsPath
) )
const contentType = const contentType =
data && Object.keys(data).length data && Object.keys(data).length
? 'multipart/form-data; boundary=' + (formData as any)._boundary ? 'multipart/form-data; boundary=' + (formData as any)._boundary
: 'text/plain' : 'text/plain'
return await this.requestClient!.post(
return await this.sas9RequestClient!.post(
apiUrl, apiUrl,
formData, formData,
undefined, undefined,
@@ -84,28 +75,6 @@ export class Sas9JobExecutor extends BaseJobExecutor {
Connection: 'Keep-Alive' Connection: 'Keep-Alive'
} }
) )
.then((res: any) => {
let resString = res
if (typeof res === 'object') {
resString = JSON.stringify(res)
}
this.requestClient!.appendRequest(resString, sasJob, config.debug)
return res
})
.catch((err: any) => {
let errString = err
if (typeof err === 'object') {
errString = JSON.stringify(errString)
}
this.requestClient!.appendRequest(errString, sasJob, config.debug)
return err
})
} }
private getRequestParams(config: any): any { private getRequestParams(config: any): any {

View File

@@ -15,8 +15,7 @@ import { SASViyaApiClient } from '../SASViyaApiClient'
import { import {
isRelativePath, isRelativePath,
parseSasViyaDebugResponse, parseSasViyaDebugResponse,
appendExtraResponseAttributes, appendExtraResponseAttributes
getValidJson
} from '../utils' } from '../utils'
import { BaseJobExecutor } from './JobExecutor' import { BaseJobExecutor } from './JobExecutor'
import { parseWeboutResponse } from '../utils/parseWeboutResponse' import { parseWeboutResponse } from '../utils/parseWeboutResponse'
@@ -54,36 +53,7 @@ export class WebJobExecutor extends BaseJobExecutor {
let apiUrl = `${config.serverUrl}${this.jobsPath}/?${'_program=' + program}` let apiUrl = `${config.serverUrl}${this.jobsPath}/?${'_program=' + program}`
if (config.serverType === ServerType.SasViya) { if (config.serverType === ServerType.SasViya) {
let jobUri const jobUri = await this.getJobUri(sasJob)
try {
jobUri = await this.getJobUri(sasJob)
} catch (e: any) {
return new Promise(async (resolve, reject) => {
if (e instanceof LoginRequiredError) {
this.appendWaitingRequest(() => {
return this.execute(
sasJob,
data,
config,
loginRequiredCallback,
authConfig,
extraResponseAttributes
).then(
(res: any) => {
resolve(res)
},
(err: any) => {
reject(err)
}
)
})
await loginCallback()
} else {
reject(new ErrorResponse(e?.message, e))
}
})
}
apiUrl += jobUri.length > 0 ? '&_job=' + jobUri : '' apiUrl += jobUri.length > 0 ? '&_job=' + jobUri : ''
@@ -114,14 +84,13 @@ export class WebJobExecutor extends BaseJobExecutor {
const stringifiedData = JSON.stringify(data) const stringifiedData = JSON.stringify(data)
if ( if (
config.serverType === ServerType.Sas9 || config.serverType === ServerType.Sas9 ||
config.serverType === ServerType.Sasjs ||
stringifiedData.length > 500000 || stringifiedData.length > 500000 ||
stringifiedData.includes(';') stringifiedData.includes(';')
) { ) {
// file upload approach // file upload approach
try { try {
formData = generateFileUploadForm(formData, data) formData = generateFileUploadForm(formData, data)
} catch (e: any) { } catch (e) {
return Promise.reject(new ErrorResponse(e?.message, e)) return Promise.reject(new ErrorResponse(e?.message, e))
} }
} else { } else {
@@ -131,7 +100,7 @@ export class WebJobExecutor extends BaseJobExecutor {
generateTableUploadForm(formData, data) generateTableUploadForm(formData, data)
formData = newFormData formData = newFormData
requestParams = { ...requestParams, ...params } requestParams = { ...requestParams, ...params }
} catch (e: any) { } catch (e) {
return Promise.reject(new ErrorResponse(e?.message, e)) return Promise.reject(new ErrorResponse(e?.message, e))
} }
} }
@@ -144,25 +113,10 @@ export class WebJobExecutor extends BaseJobExecutor {
} }
const requestPromise = new Promise((resolve, reject) => { const requestPromise = new Promise((resolve, reject) => {
// Access token is required for server type `SASjs` this.requestClient!.post(apiUrl, formData, undefined)
this.requestClient!.post(apiUrl, formData, authConfig?.access_token)
.then(async (res: any) => { .then(async (res: any) => {
const resObj =
this.serverType === ServerType.Sasjs
? {
result: res.result._webout,
log: res.result.log
}
: res
this.requestClient!.appendRequest(resObj, sasJob, config.debug)
let jsonResponse = res.result let jsonResponse = res.result
if (this.serverType === ServerType.Sasjs) {
const webout = parseWeboutResponse(res.result._webout, apiUrl)
jsonResponse = getValidJson(webout)
}
if (config.debug) { if (config.debug) {
switch (this.serverType) { switch (this.serverType) {
case ServerType.SasViya: case ServerType.SasViya:
@@ -181,6 +135,8 @@ export class WebJobExecutor extends BaseJobExecutor {
} }
} }
this.appendRequest(res, sasJob, config.debug)
const responseObject = appendExtraResponseAttributes( const responseObject = appendExtraResponseAttributes(
{ result: jsonResponse }, { result: jsonResponse },
extraResponseAttributes extraResponseAttributes
@@ -189,7 +145,8 @@ export class WebJobExecutor extends BaseJobExecutor {
}) })
.catch(async (e: Error) => { .catch(async (e: Error) => {
if (e instanceof JobExecutionError) { if (e instanceof JobExecutionError) {
this.requestClient!.appendRequest(e, sasJob, config.debug) this.appendRequest(e, sasJob, config.debug)
reject(new ErrorResponse(e?.message, e)) reject(new ErrorResponse(e?.message, e))
} }

View File

@@ -3,4 +3,3 @@ export * from './JesJobExecutor'
export * from './JobExecutor' export * from './JobExecutor'
export * from './Sas9JobExecutor' export * from './Sas9JobExecutor'
export * from './WebJobExecutor' export * from './WebJobExecutor'
export * from './FileUploader'

Some files were not shown because too many files have changed in this diff Show More