mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-07 12:30:06 +00:00
Merge branch 'master' into service-pack-with-file-resource
This commit is contained in:
8
package-lock.json
generated
8
package-lock.json
generated
@@ -1005,11 +1005,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@sasjs/utils": {
|
"@sasjs/utils": {
|
||||||
"version": "2.18.0",
|
"version": "2.20.1",
|
||||||
"resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.18.0.tgz",
|
"resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.20.1.tgz",
|
||||||
"integrity": "sha512-6VTbRP1KU0gGi1mSIHl+XyL9Vqk8rBW7a7VQOF6vzD+AVgfgYd0t76djAUCcA7Dos8NJXAoDUuah+iNvXJY+cw==",
|
"integrity": "sha512-Wer6RrGPowBgvgJ2Hdk2nrdA9mIsG4AKI50s/cEWKfzMnQRQVrCNmVUyZlM5I8/pZRzsMzwq7PLaxjAADYUCuQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@types/prompts": "^2.0.11",
|
"@types/prompts": "^2.0.13",
|
||||||
"chalk": "^4.1.1",
|
"chalk": "^4.1.1",
|
||||||
"cli-table": "^0.3.6",
|
"cli-table": "^0.3.6",
|
||||||
"consola": "^2.15.0",
|
"consola": "^2.15.0",
|
||||||
|
|||||||
@@ -64,7 +64,7 @@
|
|||||||
},
|
},
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sasjs/utils": "^2.18.0",
|
"@sasjs/utils": "^2.20.1",
|
||||||
"axios": "^0.21.1",
|
"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",
|
||||||
|
|||||||
@@ -145,6 +145,33 @@ export const basicTests = (
|
|||||||
sasjsConfig.debug === false
|
sasjsConfig.debug === false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Request with extra attributes on JES approach',
|
||||||
|
description:
|
||||||
|
'Should complete successful request with extra attributes present in response',
|
||||||
|
test: async () => {
|
||||||
|
const config = {
|
||||||
|
useComputeApi: false
|
||||||
|
}
|
||||||
|
|
||||||
|
return await adapter.request(
|
||||||
|
'common/sendArr',
|
||||||
|
stringData,
|
||||||
|
config,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
['output', 'file', 'data']
|
||||||
|
)
|
||||||
|
},
|
||||||
|
assertion: (response: any) => {
|
||||||
|
const responseKeys: any = Object.keys(response)
|
||||||
|
return (
|
||||||
|
responseKeys.includes('file') &&
|
||||||
|
responseKeys.includes('output') &&
|
||||||
|
responseKeys.includes('data')
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|||||||
10
src/SASjs.ts
10
src/SASjs.ts
@@ -14,6 +14,7 @@ import {
|
|||||||
Sas9JobExecutor
|
Sas9JobExecutor
|
||||||
} from './job-execution'
|
} from './job-execution'
|
||||||
import { ErrorResponse } from './types/errors'
|
import { ErrorResponse } from './types/errors'
|
||||||
|
import { ExtraResponseAttributes } from '@sasjs/utils/types'
|
||||||
|
|
||||||
const defaultConfig: SASjsConfig = {
|
const defaultConfig: SASjsConfig = {
|
||||||
serverUrl: '',
|
serverUrl: '',
|
||||||
@@ -575,13 +576,17 @@ export default class SASjs {
|
|||||||
* `await request(sasJobPath, data, config, () => setIsLoggedIn(false))`
|
* `await request(sasJobPath, data, config, () => setIsLoggedIn(false))`
|
||||||
* If you are not passing in any data and configuration, it will look like so:
|
* If you are not passing in any data and configuration, it will look like so:
|
||||||
* `await request(sasJobPath, {}, {}, () => setIsLoggedIn(false))`
|
* `await request(sasJobPath, {}, {}, () => setIsLoggedIn(false))`
|
||||||
|
* @param extraResponseAttributes - a array of predefined values that are used
|
||||||
|
* to provide extra attributes (same names as those values) to be added in response
|
||||||
|
* Supported values are declared in ExtraResponseAttributes type.
|
||||||
*/
|
*/
|
||||||
public async request(
|
public async request(
|
||||||
sasJob: string,
|
sasJob: string,
|
||||||
data: { [key: string]: any },
|
data: { [key: string]: any },
|
||||||
config: { [key: string]: any } = {},
|
config: { [key: string]: any } = {},
|
||||||
loginRequiredCallback?: () => any,
|
loginRequiredCallback?: () => any,
|
||||||
accessToken?: string
|
accessToken?: string,
|
||||||
|
extraResponseAttributes: ExtraResponseAttributes[] = []
|
||||||
) {
|
) {
|
||||||
config = {
|
config = {
|
||||||
...this.sasjsConfig,
|
...this.sasjsConfig,
|
||||||
@@ -603,7 +608,8 @@ export default class SASjs {
|
|||||||
data,
|
data,
|
||||||
config,
|
config,
|
||||||
loginRequiredCallback,
|
loginRequiredCallback,
|
||||||
accessToken
|
accessToken,
|
||||||
|
extraResponseAttributes
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else if (
|
} else if (
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
JobExecutionError,
|
JobExecutionError,
|
||||||
LoginRequiredError
|
LoginRequiredError
|
||||||
} from '../types/errors'
|
} from '../types/errors'
|
||||||
|
import { ExtraResponseAttributes } from '@sasjs/utils/types'
|
||||||
import { BaseJobExecutor } from './JobExecutor'
|
import { BaseJobExecutor } from './JobExecutor'
|
||||||
|
|
||||||
export class JesJobExecutor extends BaseJobExecutor {
|
export class JesJobExecutor extends BaseJobExecutor {
|
||||||
@@ -17,7 +18,8 @@ export class JesJobExecutor extends BaseJobExecutor {
|
|||||||
data: any,
|
data: any,
|
||||||
config: any,
|
config: any,
|
||||||
loginRequiredCallback?: any,
|
loginRequiredCallback?: any,
|
||||||
accessToken?: string
|
accessToken?: string,
|
||||||
|
extraResponseAttributes: ExtraResponseAttributes[] = []
|
||||||
) {
|
) {
|
||||||
const loginCallback = loginRequiredCallback || (() => Promise.resolve())
|
const loginCallback = loginRequiredCallback || (() => Promise.resolve())
|
||||||
|
|
||||||
@@ -30,10 +32,26 @@ export class JesJobExecutor extends BaseJobExecutor {
|
|||||||
data,
|
data,
|
||||||
accessToken
|
accessToken
|
||||||
)
|
)
|
||||||
.then((response) => {
|
.then((response: any) => {
|
||||||
this.appendRequest(response, sasJob, config.debug)
|
this.appendRequest(response, sasJob, config.debug)
|
||||||
|
|
||||||
resolve(response)
|
let responseObject = {}
|
||||||
|
|
||||||
|
if (extraResponseAttributes && extraResponseAttributes.length > 0) {
|
||||||
|
const extraAttributes = extraResponseAttributes.reduce(
|
||||||
|
(map: any, obj: any) => ((map[obj] = response[obj]), map),
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
|
||||||
|
responseObject = {
|
||||||
|
result: response.result,
|
||||||
|
...extraAttributes
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
responseObject = response.result
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(responseObject)
|
||||||
})
|
})
|
||||||
.catch(async (e: Error) => {
|
.catch(async (e: Error) => {
|
||||||
if (e instanceof JobExecutionError) {
|
if (e instanceof JobExecutionError) {
|
||||||
@@ -50,7 +68,9 @@ export class JesJobExecutor extends BaseJobExecutor {
|
|||||||
sasJob,
|
sasJob,
|
||||||
data,
|
data,
|
||||||
config,
|
config,
|
||||||
loginRequiredCallback
|
loginRequiredCallback,
|
||||||
|
accessToken,
|
||||||
|
extraResponseAttributes
|
||||||
).then(
|
).then(
|
||||||
(res: any) => {
|
(res: any) => {
|
||||||
resolve(res)
|
resolve(res)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { ServerType } from '@sasjs/utils/types'
|
import { ServerType } from '@sasjs/utils/types'
|
||||||
import { SASjsRequest } from '../types'
|
import { SASjsRequest } from '../types'
|
||||||
|
import { ExtraResponseAttributes } from '@sasjs/utils/types'
|
||||||
import { asyncForEach, parseGeneratedCode, parseSourceCode } from '../utils'
|
import { asyncForEach, parseGeneratedCode, parseSourceCode } from '../utils'
|
||||||
|
|
||||||
export type ExecuteFunction = () => Promise<any>
|
export type ExecuteFunction = () => Promise<any>
|
||||||
@@ -10,7 +11,8 @@ export interface JobExecutor {
|
|||||||
data: any,
|
data: any,
|
||||||
config: any,
|
config: any,
|
||||||
loginRequiredCallback?: any,
|
loginRequiredCallback?: any,
|
||||||
accessToken?: string
|
accessToken?: string,
|
||||||
|
extraResponseAttributes?: ExtraResponseAttributes[]
|
||||||
) => Promise<any>
|
) => Promise<any>
|
||||||
resendWaitingRequests: () => Promise<void>
|
resendWaitingRequests: () => Promise<void>
|
||||||
getRequests: () => SASjsRequest[]
|
getRequests: () => SASjsRequest[]
|
||||||
@@ -28,7 +30,8 @@ export abstract class BaseJobExecutor implements JobExecutor {
|
|||||||
data: any,
|
data: any,
|
||||||
config: any,
|
config: any,
|
||||||
loginRequiredCallback?: any,
|
loginRequiredCallback?: any,
|
||||||
accessToken?: string | undefined
|
accessToken?: string | undefined,
|
||||||
|
extraResponseAttributes?: ExtraResponseAttributes[]
|
||||||
): Promise<any>
|
): Promise<any>
|
||||||
|
|
||||||
resendWaitingRequests = async () => {
|
resendWaitingRequests = async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user