mirror of
https://github.com/sasjs/adapter.git
synced 2025-12-11 09:24:35 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf35e52962 | ||
|
|
eb83101dbf | ||
|
|
56d84e1940 | ||
|
|
283800dfa6 | ||
|
|
c073d72dd4 | ||
|
|
f5d40eaaf7 | ||
|
|
8e9cf98985 | ||
|
|
79ba044dea | ||
|
|
9329dc848a | ||
|
|
98c492e85e | ||
| d1fcc2ca0a | |||
|
|
f602d5baf0 | ||
|
|
4744dbf196 |
20
README.md
20
README.md
@@ -94,10 +94,10 @@ const sasJs = new SASjs({your config})
|
||||
More on the config later.
|
||||
|
||||
### SAS Logon
|
||||
All authentication from the adapter is done against SASLogon. There are two approaches that can be taken, which are configured using the `LoginMechanism` attribute of the sasJs config object (above):
|
||||
All authentication from the adapter is done against SASLogon. There are two approaches that can be taken, which are configured using the `loginMechanism` attribute of the sasJs config object (above):
|
||||
|
||||
* `LoginMechanism:'Redirected'` - this approach enables authentication through a SASLogon window, supporting complex authentication flows (such as 2FA) and avoids the need to handle passwords in the application itself. The styling of the window can be modified using CSS.
|
||||
* `LoginMechanism:'Default'` - this approach requires that the username and password are captured, and used within the `.login()` method. This can be helpful for development, or automated testing.
|
||||
* `loginMechanism:'Redirected'` - this approach enables authentication through a SASLogon window, supporting complex authentication flows (such as 2FA) and avoids the need to handle passwords in the application itself. The styling of the window can be modified using CSS.
|
||||
* `loginMechanism:'Default'` - this approach requires that the username and password are captured, and used within the `.login()` method. This can be helpful for development, or automated testing.
|
||||
|
||||
Sample code for logging in with the `Default` approach:
|
||||
|
||||
@@ -125,7 +125,11 @@ sasJs.request("/path/to/my/service", dataObject)
|
||||
})
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
If the path starts with a `/` then it should be a full path to the service. If there is no leading `/` then it is relative to the `appLoc`.
|
||||
|
||||
The data object can be null (for services with no input), or can contain one or more "tables" in the following format:
|
||||
|
||||
```javascript
|
||||
let dataObject={
|
||||
@@ -141,7 +145,9 @@ let dataObject={
|
||||
};
|
||||
```
|
||||
|
||||
There are optional parameters such as a config object and a callback login function.
|
||||
These tables (`tablewith2cols1row` and `tablewith1col2rows`) will be created in SAS WORK after running `%webout(FETCH)` in your SAS service.
|
||||
|
||||
The `request()` method also has optional parameters such as a config object and a callback login function.
|
||||
|
||||
The response object will contain returned tables and columns. Table names are always lowercase, and column names uppercase.
|
||||
|
||||
@@ -248,6 +254,8 @@ Where an entire column is made up of special missing numerics, there would be no
|
||||
%webout(OBJ,a,missing=STRING,showmeta=YES)
|
||||
```
|
||||
|
||||
The `%webout()` macro itself is just a wrapper for the [mp_jsonout](https://core.sasjs.io/mp__jsonout_8sas.html) macro.
|
||||
|
||||
## Configuration
|
||||
|
||||
Configuration on the client side involves passing an object on startup, which can also be passed with each request. Technical documentation on the SASjsConfig class is available [here](https://adapter.sasjs.io/classes/types.sasjsconfig.html). The main config items are:
|
||||
@@ -256,7 +264,7 @@ Configuration on the client side involves passing an object on startup, which ca
|
||||
* `serverType` - either `SAS9`, `SASVIYA` or `SASJS`. The `SASJS` server type is for use with [sasjs/server](https://github.com/sasjs/server).
|
||||
* `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.
|
||||
* `LoginMechanism` - either `Default` or `Redirected`. See [SAS Logon](#sas-logon) section.
|
||||
* `loginMechanism` - either `Default` or `Redirected`. See [SAS Logon](#sas-logon) section.
|
||||
* `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`.
|
||||
* `requestHistoryLimit` - Request history limit. Increasing this limit may affect browser performance, especially with debug (logs) enabled. Default is 10.
|
||||
|
||||
4113
package-lock.json
generated
4113
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -64,7 +64,7 @@
|
||||
"prettier": "2.7.1",
|
||||
"process": "0.11.10",
|
||||
"rimraf": "3.0.2",
|
||||
"semantic-release": "18.0.0",
|
||||
"semantic-release": "19.0.3",
|
||||
"terser-webpack-plugin": "5.3.1",
|
||||
"ts-jest": "27.1.3",
|
||||
"ts-loader": "9.2.6",
|
||||
|
||||
30895
sasjs-tests/package-lock.json
generated
30895
sasjs-tests/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,7 @@
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@sasjs/adapter": "file:../build/sasjs-adapter-5.0.0.tgz",
|
||||
"@sasjs/test-framework": "^1.4.3",
|
||||
"@sasjs/test-framework": "^1.5.6",
|
||||
"@types/jest": "^26.0.20",
|
||||
"@types/node": "^14.14.41",
|
||||
"@types/react": "^17.0.1",
|
||||
@@ -14,7 +14,7 @@
|
||||
"react": "^17.0.1",
|
||||
"react-dom": "^17.0.1",
|
||||
"react-router-dom": "^5.2.0",
|
||||
"react-scripts": "^4.0.2",
|
||||
"react-scripts": "^5.0.1",
|
||||
"typescript": "^4.1.3"
|
||||
},
|
||||
"scripts": {
|
||||
@@ -43,6 +43,6 @@
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"node-sass": "^6.0.1"
|
||||
"node-sass": "^7.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,12 +11,13 @@ import { fileUploadTests } from './testSuites/FileUpload'
|
||||
const App = (): ReactElement<{}> => {
|
||||
const { adapter, config } = useContext(AppContext)
|
||||
const [testSuites, setTestSuites] = useState<TestSuite[]>([])
|
||||
const appLoc = config.sasJsConfig.appLoc
|
||||
|
||||
useEffect(() => {
|
||||
if (adapter) {
|
||||
const testSuites = [
|
||||
basicTests(adapter, config.userName, config.password),
|
||||
sendArrTests(adapter),
|
||||
sendArrTests(adapter, appLoc),
|
||||
sendObjTests(adapter),
|
||||
specialCaseTests(adapter),
|
||||
sasjsRequestTests(adapter),
|
||||
@@ -24,12 +25,12 @@ const App = (): ReactElement<{}> => {
|
||||
]
|
||||
|
||||
if (adapter.getSasjsConfig().serverType === 'SASVIYA') {
|
||||
testSuites.push(computeTests(adapter))
|
||||
testSuites.push(computeTests(adapter, appLoc))
|
||||
}
|
||||
|
||||
setTestSuites(testSuites)
|
||||
}
|
||||
}, [adapter, config])
|
||||
}, [adapter, config, appLoc])
|
||||
|
||||
return (
|
||||
<div className="app">
|
||||
|
||||
@@ -3,7 +3,7 @@ import { TestSuite } from '@sasjs/test-framework'
|
||||
|
||||
const stringData: any = { table1: [{ col1: 'first col value' }] }
|
||||
|
||||
export const computeTests = (adapter: SASjs): TestSuite => ({
|
||||
export const computeTests = (adapter: SASjs, appLoc: string): TestSuite => ({
|
||||
name: 'Compute',
|
||||
tests: [
|
||||
{
|
||||
@@ -35,7 +35,7 @@ export const computeTests = (adapter: SASjs): TestSuite => ({
|
||||
description: 'Should start a compute job and return the session',
|
||||
test: () => {
|
||||
const data: any = { table1: [{ col1: 'first col value' }] }
|
||||
return adapter.startComputeJob('/Public/app/common/sendArr', data)
|
||||
return adapter.startComputeJob(`${appLoc}/common/sendArr`, data)
|
||||
},
|
||||
assertion: (res: any) => {
|
||||
const expectedProperties = ['id', 'applicationName', 'attributes']
|
||||
|
||||
@@ -45,14 +45,14 @@ const getLargeObjectData = () => {
|
||||
return data
|
||||
}
|
||||
|
||||
export const sendArrTests = (adapter: SASjs): TestSuite => ({
|
||||
export const sendArrTests = (adapter: SASjs, appLoc: string): TestSuite => ({
|
||||
name: 'sendArr',
|
||||
tests: [
|
||||
{
|
||||
title: 'Absolute paths',
|
||||
description: 'Should work with absolute paths to SAS jobs',
|
||||
test: () => {
|
||||
return adapter.request('/Public/app/common/sendArr', stringData)
|
||||
return adapter.request(`${appLoc}/common/sendArr`, stringData)
|
||||
},
|
||||
assertion: (res: any) => {
|
||||
return res.table1[0][0] === stringData.table1[0].col1
|
||||
|
||||
@@ -23,7 +23,7 @@ export class AuthManager {
|
||||
? '/SASLogon/logout?'
|
||||
: this.serverType === ServerType.SasViya
|
||||
? '/SASLogon/logout.do?'
|
||||
: '/SASjsApi/auth/logout'
|
||||
: '/SASLogon/logout'
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -334,19 +334,9 @@ export class AuthManager {
|
||||
|
||||
/**
|
||||
* Logs out of the configured SAS server.
|
||||
* @param accessToken - an optional access token is required for SASjs server type.
|
||||
*
|
||||
*/
|
||||
public async logOut() {
|
||||
if (this.serverType === ServerType.Sasjs) {
|
||||
return this.requestClient
|
||||
.delete(this.logoutUrl)
|
||||
.catch(() => true)
|
||||
.finally(() => {
|
||||
this.requestClient.clearLocalStorageTokens()
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
this.requestClient.clearCsrfTokens()
|
||||
|
||||
return this.requestClient.get(this.logoutUrl, undefined).then(() => true)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as NodeFormData from 'form-data'
|
||||
import { convertToCSV } from '../utils/convertToCsv'
|
||||
import { convertToCSV, isFormatsTable } from '../utils/convertToCsv'
|
||||
import { splitChunks } from '../utils/splitChunks'
|
||||
|
||||
export const generateTableUploadForm = (
|
||||
@@ -13,7 +13,8 @@ export const generateTableUploadForm = (
|
||||
for (const tableName in data) {
|
||||
tableCounter++
|
||||
|
||||
sasjsTables.push(tableName)
|
||||
// Formats table should not be sent as part of 'sasjs_tables'
|
||||
if (!isFormatsTable(tableName)) sasjsTables.push(tableName)
|
||||
|
||||
const csv = convertToCSV(data, tableName)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { convertToCSV } from './convertToCsv'
|
||||
import { convertToCSV, isFormatsTable } from './convertToCsv'
|
||||
|
||||
describe('convertToCsv', () => {
|
||||
const tableName = 'testTable'
|
||||
@@ -216,7 +216,9 @@ describe('convertToCsv', () => {
|
||||
const data = { [tableName]: [{ var1: 'string' }] }
|
||||
|
||||
expect(() => convertToCSV(data, 'wrongTableName')).toThrow(
|
||||
new Error('No table provided to be converted to CSV')
|
||||
new Error(
|
||||
'Error while converting to CSV. No table provided to be converted to CSV.'
|
||||
)
|
||||
)
|
||||
})
|
||||
|
||||
@@ -226,3 +228,15 @@ describe('convertToCsv', () => {
|
||||
expect(convertToCSV(data, tableName)).toEqual('')
|
||||
})
|
||||
})
|
||||
|
||||
describe('isFormatsTable', () => {
|
||||
const tableName = 'sometable'
|
||||
|
||||
it('should return true if table name match pattern of formats table', () => {
|
||||
expect(isFormatsTable(`$${tableName}`)).toEqual(true)
|
||||
})
|
||||
|
||||
it('should return false if table name does not match pattern of formats table', () => {
|
||||
expect(isFormatsTable(tableName)).toEqual(false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { isSpecialMissing } from '@sasjs/utils/input/validators'
|
||||
import { prefixMessage } from '@sasjs/utils/error'
|
||||
|
||||
/**
|
||||
* Converts the given JSON object array to a CSV string.
|
||||
@@ -9,7 +10,10 @@ export const convertToCSV = (
|
||||
tableName: string
|
||||
) => {
|
||||
if (!data[tableName]) {
|
||||
throw new Error('No table provided to be converted to CSV')
|
||||
throw prefixMessage(
|
||||
'No table provided to be converted to CSV.',
|
||||
'Error while converting to CSV. '
|
||||
)
|
||||
}
|
||||
|
||||
const table = data[tableName]
|
||||
@@ -170,6 +174,12 @@ export const convertToCSV = (
|
||||
return finalCSV
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if table is table of formats (table name should start from '$' character).
|
||||
* @param tableName - table name.
|
||||
*/
|
||||
export const isFormatsTable = (tableName: string) => /^\$.*/.test(tableName)
|
||||
|
||||
const getByteSize = (str: string) => {
|
||||
let byteSize = str.length
|
||||
for (let i = str.length - 1; i >= 0; i--) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { convertToCSV } from './convertToCsv'
|
||||
import { convertToCSV, isFormatsTable } from './convertToCsv'
|
||||
import { splitChunks } from './splitChunks'
|
||||
|
||||
export const formatDataForRequest = (data: any) => {
|
||||
@@ -8,7 +8,7 @@ export const formatDataForRequest = (data: any) => {
|
||||
|
||||
for (const tableName in data) {
|
||||
if (
|
||||
tableName.match(/^\$.*/) &&
|
||||
isFormatsTable(tableName) &&
|
||||
Object.keys(data).includes(tableName.replace(/^\$/, ''))
|
||||
) {
|
||||
continue
|
||||
@@ -16,7 +16,8 @@ export const formatDataForRequest = (data: any) => {
|
||||
|
||||
tableCounter++
|
||||
|
||||
sasjsTables.push(tableName)
|
||||
// Formats table should not be sent as part of 'sasjs_tables'
|
||||
if (!isFormatsTable(tableName)) sasjsTables.push(tableName)
|
||||
|
||||
const csv = convertToCSV(data, tableName)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user