mirror of
https://github.com/sasjs/adapter.git
synced 2025-12-25 15:01:20 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ea3925977 | ||
| 489df78391 | |||
|
|
842c7f9b23 | ||
| fe3f6d6287 | |||
|
|
9728ebd98d | ||
|
|
8e116d81d7 | ||
|
|
fbca91144d | ||
|
|
9b239abda0 | ||
|
|
d3dff44918 |
2
.github/dependabot.yml
vendored
2
.github/dependabot.yml
vendored
@@ -4,4 +4,4 @@ updates:
|
||||
directory: '/'
|
||||
schedule:
|
||||
interval: monthly
|
||||
open-pull-requests-limit: 10
|
||||
open-pull-requests-limit: 2
|
||||
|
||||
@@ -254,6 +254,7 @@ Configuration on the client side involves passing an object on startup, which ca
|
||||
* `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.
|
||||
* `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.
|
||||
|
||||
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).
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ const errorAndCsrfData: any = {
|
||||
}
|
||||
|
||||
const testTable = 'sometable'
|
||||
const testTableWithNullVars: { [key: string]: any } = {
|
||||
export const testTableWithNullVars: { [key: string]: any } = {
|
||||
[testTable]: [
|
||||
{ var1: 'string', var2: 232, nullvar: 'A' },
|
||||
{ var1: 'string', var2: 232, nullvar: 'B' },
|
||||
|
||||
@@ -1034,7 +1034,8 @@ export default class SASjs {
|
||||
: RequestClient
|
||||
this.requestClient = new RequestClientClass(
|
||||
this.sasjsConfig.serverUrl,
|
||||
this.sasjsConfig.httpsAgentOptions
|
||||
this.sasjsConfig.httpsAgentOptions,
|
||||
this.sasjsConfig.requestHistoryLimit
|
||||
)
|
||||
} else {
|
||||
this.requestClient.setConfig(
|
||||
|
||||
@@ -5,8 +5,11 @@ export const generateFileUploadForm = (
|
||||
data: any
|
||||
): FormData => {
|
||||
for (const tableName in data) {
|
||||
if (!Array.isArray(data[tableName])) continue
|
||||
|
||||
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.'
|
||||
|
||||
55
src/file/spec/generateFileUploadForm.spec.ts
Normal file
55
src/file/spec/generateFileUploadForm.spec.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { generateFileUploadForm } from '../generateFileUploadForm'
|
||||
|
||||
describe('generateFileUploadForm', () => {
|
||||
beforeAll(() => {
|
||||
function FormDataMock(this: any) {
|
||||
this.append = () => {}
|
||||
}
|
||||
|
||||
const BlobMock = jest.fn()
|
||||
|
||||
;(global as any).FormData = FormDataMock
|
||||
;(global as any).Blob = BlobMock
|
||||
})
|
||||
|
||||
it('should generate file upload form from data', () => {
|
||||
const formData = new FormData()
|
||||
const testTable = 'sometable'
|
||||
const testTableWithNullVars: { [key: string]: any } = {
|
||||
[testTable]: [
|
||||
{ var1: 'string', var2: 232, nullvar: 'A' },
|
||||
{ var1: 'string', var2: 232, nullvar: 'B' },
|
||||
{ var1: 'string', var2: 232, nullvar: '_' },
|
||||
{ var1: 'string', var2: 232, nullvar: 0 },
|
||||
{ var1: 'string', var2: 232, nullvar: 'z' },
|
||||
{ var1: 'string', var2: 232, nullvar: null }
|
||||
],
|
||||
[`$${testTable}`]: { formats: { var1: '$char12.', nullvar: 'best.' } }
|
||||
}
|
||||
const tableName = Object.keys(testTableWithNullVars).filter((key: string) =>
|
||||
Array.isArray(testTableWithNullVars[key])
|
||||
)[0]
|
||||
|
||||
jest.spyOn(formData, 'append').mockImplementation(() => {})
|
||||
|
||||
generateFileUploadForm(formData, testTableWithNullVars)
|
||||
|
||||
expect(formData.append).toHaveBeenCalledOnce()
|
||||
expect(formData.append).toHaveBeenCalledWith(
|
||||
tableName,
|
||||
{},
|
||||
`${tableName}.csv`
|
||||
)
|
||||
})
|
||||
|
||||
it('should throw an error if too large string was provided', () => {
|
||||
const formData = new FormData()
|
||||
const data = { testTable: [{ var1: 'z'.repeat(32765 + 1) }] }
|
||||
|
||||
expect(() => generateFileUploadForm(formData, data)).toThrow(
|
||||
new Error(
|
||||
'The max length of a string value in SASjs is 32765 characters.'
|
||||
)
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -56,6 +56,7 @@ export interface HttpClient {
|
||||
|
||||
export class RequestClient implements HttpClient {
|
||||
private requests: SASjsRequest[] = []
|
||||
private requestsLimit: number = 10
|
||||
|
||||
protected csrfToken: CsrfToken = { headerName: '', value: '' }
|
||||
protected fileUploadCsrfToken: CsrfToken | undefined
|
||||
@@ -63,9 +64,11 @@ export class RequestClient implements HttpClient {
|
||||
|
||||
constructor(
|
||||
protected baseUrl: string,
|
||||
httpsAgentOptions?: https.AgentOptions
|
||||
httpsAgentOptions?: https.AgentOptions,
|
||||
requestsLimit?: number
|
||||
) {
|
||||
this.createHttpClient(baseUrl, httpsAgentOptions)
|
||||
if (requestsLimit) this.requestsLimit = requestsLimit
|
||||
}
|
||||
|
||||
public setConfig(baseUrl: string, httpsAgentOptions?: https.AgentOptions) {
|
||||
@@ -149,7 +152,7 @@ export class RequestClient implements HttpClient {
|
||||
SASWORK: sasWork
|
||||
})
|
||||
|
||||
if (this.requests.length > 20) {
|
||||
if (this.requests.length > this.requestsLimit) {
|
||||
this.requests.splice(0, 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ export class SASjsConfig {
|
||||
*/
|
||||
useComputeApi: boolean | null = null
|
||||
/**
|
||||
* Optional settings to configure HTTPS Agent.
|
||||
* Optional setting to configure HTTPS Agent.
|
||||
* By providing `key`, `cert`, `ca` to connect with server
|
||||
* Other options can be set `rejectUnauthorized` and `requestCert`
|
||||
*/
|
||||
@@ -69,6 +69,11 @@ export class SASjsConfig {
|
||||
* Supported login mechanisms are - Redirected and Default
|
||||
*/
|
||||
loginMechanism: LoginMechanism = LoginMechanism.Default
|
||||
/**
|
||||
* Optional setting to configure request history limit. Increasing this limit
|
||||
* may affect browser performance, especially with debug (logs) enabled.
|
||||
*/
|
||||
requestHistoryLimit?: number = 10
|
||||
}
|
||||
|
||||
export enum LoginMechanism {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* @param data - the array of JSON objects to convert.
|
||||
*/
|
||||
export const convertToCSV = (
|
||||
data: any,
|
||||
data: any[],
|
||||
sasFormats?: { formats: { [key: string]: string } }
|
||||
) => {
|
||||
let formats = sasFormats?.formats
|
||||
@@ -76,7 +76,7 @@ export const convertToCSV = (
|
||||
return byteSize
|
||||
}
|
||||
})
|
||||
.sort((a: number, b: number) => b - a)[0]
|
||||
.sort((a: any, b: any) => b - a)[0]
|
||||
|
||||
if (longestValueForField && longestValueForField > 32765) {
|
||||
invalidString = true
|
||||
|
||||
Reference in New Issue
Block a user