diff --git a/README.md b/README.md index 9d267fd..522c5fa 100644 --- a/README.md +++ b/README.md @@ -172,8 +172,8 @@ Configuration on the client side involves passing an object on startup, which ca * `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. * `debug` - if `true` then SAS Logs and extra debug information is returned. -* `useComputeApi` - if `true` and the serverType is `SASVIYA` then the REST APIs will be called directly (rather than using the JES web service). -* `contextName` - if missing or blank, and `useComputeApi` is `true` and `serverType` is `SASVIYA` then the JES API will be used. +* `useComputeApi` - Only relevant when the serverType is `SASVIYA`. If `true` the [Compute API](https://github.com/sasjs/adapter#using-the-compute-api) is used. If `false` the [JES API](https://github.com/sasjs/adapter#using-the-jes-api) is used. If `null` or `undefined` the [Web](https://github.com/sasjs/adapter#using-jes-web-app) approach is used. +* `contextName` - Context on which the reqeusts will be called. The adapter supports a number of approaches for interfacing with Viya (`serverType` is `SASVIYA`). For maximum performance, be sure to [configure your compute context](https://sasjs.io/guide-viya/#shared-account-and-server-re-use) with `reuseServerProcesses` as `true` and a system account in `runServerAs`. This functionality is available since Viya 3.5. This configuration is supported when [creating contexts using the CLI](https://sasjs.io/sasjs-cli-context/#sasjs-context-create). @@ -184,7 +184,8 @@ In this setup, all requests are routed through the JES web app, at `YOURSERVER/S ``` { appLoc:"/Your/Path", - serverType:"SASVIYA" + serverType:"SASVIYA", + contextName: 'yourComputeContext' } ``` @@ -195,7 +196,8 @@ Here we are running Jobs using the Job Execution Service except this time we are { appLoc:"/Your/Path", serverType:"SASVIYA", - useComputeApi: true + useComputeApi: false, + contextName: 'yourComputeContext' } ``` diff --git a/src/FileUploader.ts b/src/FileUploader.ts index c9cecc6..74b70b1 100644 --- a/src/FileUploader.ts +++ b/src/FileUploader.ts @@ -2,15 +2,19 @@ import { isUrl } 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 appLoc: string, - serverUrl: string, + private sasjsConfig: SASjsConfig, private jobsPath: string, private requestClient: RequestClient ) { - if (serverUrl) isUrl(serverUrl) + if (this.sasjsConfig.serverUrl) isUrl(this.sasjsConfig.serverUrl) } public uploadFile(sasJob: string, files: UploadFile[], params: any) { @@ -29,12 +33,17 @@ export class FileUploader { } } - const program = this.appLoc - ? this.appLoc.replace(/\/?$/, '/') + sasJob.replace(/^\//, '') + const program = this.sasjsConfig.appLoc + ? this.sasjsConfig.appLoc.replace(/\/?$/, '/') + sasJob.replace(/^\//, '') : sasJob const uploadUrl = `${this.jobsPath}/?${ '_program=' + program - }${paramsString}` + }${paramsString}${ + this.sasjsConfig.serverType === ServerType.SasViya && + this.sasjsConfig.contextName + ? '&_contextname=' + this.sasjsConfig.contextName + : '' + }` const formData = new FormData() @@ -44,6 +53,7 @@ export class FileUploader { const csrfToken = this.requestClient.getCsrfToken('file') if (csrfToken) formData.append('_csrf', csrfToken.value) + if (this.sasjsConfig.debug) formData.append('_debug', '131') const headers = { 'cache-control': 'no-cache', diff --git a/src/SASjs.ts b/src/SASjs.ts index 9304a51..151d033 100644 --- a/src/SASjs.ts +++ b/src/SASjs.ts @@ -544,12 +544,7 @@ export default class SASjs { public uploadFile(sasJob: string, files: UploadFile[], params: any) { const fileUploader = this.fileUploader || - new FileUploader( - this.sasjsConfig.appLoc, - this.sasjsConfig.serverUrl, - this.jobsPath, - this.requestClient! - ) + new FileUploader(this.sasjsConfig, this.jobsPath, this.requestClient!) return fileUploader.uploadFile(sasJob, files, params) } @@ -595,7 +590,11 @@ export default class SASjs { const validationResult = this.validateInput(data) if (validationResult.status) { - if (config.serverType === ServerType.SasViya && config.contextName) { + if ( + config.serverType !== ServerType.Sas9 && + config.useComputeApi !== undefined && + config.useComputeApi !== null + ) { if (config.useComputeApi) { return await this.computeJobExecutor!.execute( sasJob, diff --git a/src/job-execution/WebJobExecutor.ts b/src/job-execution/WebJobExecutor.ts index 61f215c..76f0aad 100644 --- a/src/job-execution/WebJobExecutor.ts +++ b/src/job-execution/WebJobExecutor.ts @@ -39,15 +39,18 @@ export class WebJobExecutor extends BaseJobExecutor { ? config.appLoc.replace(/\/?$/, '/') + sasJob.replace(/^\//, '') : sasJob : sasJob - const jobUri = - config.serverType === ServerType.SasViya - ? await this.getJobUri(sasJob) - : '' - const apiUrl = `${config.serverUrl}${this.jobsPath}/?${ - jobUri.length > 0 - ? '__program=' + program + '&_job=' + jobUri - : '_program=' + program - }` + let apiUrl = `${config.serverUrl}${this.jobsPath}/?${'_program=' + program}` + + if (config.serverType === ServerType.SasViya) { + const jobUri = + config.serverType === ServerType.SasViya + ? await this.getJobUri(sasJob) + : '' + + apiUrl += jobUri.length > 0 ? '&_job=' + jobUri : '' + + apiUrl += config.contextName ? `&_contextname=${config.contextName}` : '' + } let requestParams = { ...this.getRequestParams(config)