mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-08 13:00:05 +00:00
chore: merge master into issue-532
This commit is contained in:
1
package-lock.json
generated
1
package-lock.json
generated
@@ -6351,6 +6351,7 @@
|
|||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"semver": "^7.3.5",
|
"semver": "^7.3.5",
|
||||||
"ssri": "^8.0.1",
|
"ssri": "^8.0.1",
|
||||||
|
"tar": "^6.1.0",
|
||||||
"treeverse": "^1.0.4",
|
"treeverse": "^1.0.4",
|
||||||
"walk-up-path": "^1.0.0"
|
"walk-up-path": "^1.0.0"
|
||||||
}
|
}
|
||||||
|
|||||||
22129
sasjs-tests/package-lock.json
generated
22129
sasjs-tests/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -41,6 +41,19 @@ export const basicTests = (
|
|||||||
assertion: (response: any) =>
|
assertion: (response: any) =>
|
||||||
response && response.isLoggedIn && response.userName === userName
|
response && response.isLoggedIn && response.userName === userName
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: 'Fetch username for already logged in user',
|
||||||
|
description: 'Should log the user in',
|
||||||
|
test: async () => {
|
||||||
|
await adapter.logIn(userName, password)
|
||||||
|
|
||||||
|
const newAdapterIns = new SASjs(adapter.getSasjsConfig())
|
||||||
|
|
||||||
|
return await newAdapterIns.checkSession()
|
||||||
|
},
|
||||||
|
assertion: (response: any) =>
|
||||||
|
response?.isLoggedIn && response?.userName === userName
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: 'Multiple Log in attempts',
|
title: 'Multiple Log in attempts',
|
||||||
description:
|
description:
|
||||||
@@ -48,7 +61,7 @@ export const basicTests = (
|
|||||||
test: async () => {
|
test: async () => {
|
||||||
await adapter.logOut()
|
await adapter.logOut()
|
||||||
await adapter.logIn('invalid', 'invalid')
|
await adapter.logIn('invalid', 'invalid')
|
||||||
return adapter.logIn(userName, password)
|
return await adapter.logIn(userName, password)
|
||||||
},
|
},
|
||||||
assertion: (response: any) =>
|
assertion: (response: any) =>
|
||||||
response && response.isLoggedIn && response.userName === userName
|
response && response.isLoggedIn && response.userName === userName
|
||||||
@@ -151,7 +164,7 @@ export const basicTests = (
|
|||||||
description:
|
description:
|
||||||
'Should complete successful request with extra attributes present in response',
|
'Should complete successful request with extra attributes present in response',
|
||||||
test: async () => {
|
test: async () => {
|
||||||
const config = {
|
const config: Partial<SASjsConfig> = {
|
||||||
useComputeApi: false
|
useComputeApi: false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,43 +23,61 @@ export class AuthManager {
|
|||||||
* Logs into the SAS server with the supplied credentials.
|
* Logs into the SAS server with the supplied credentials.
|
||||||
* @param username - a string representing the username.
|
* @param username - a string representing the username.
|
||||||
* @param password - a string representing the password.
|
* @param password - a string representing the password.
|
||||||
|
* @returns - a boolean `isLoggedin` and a string `username`
|
||||||
*/
|
*/
|
||||||
public async logIn(username: string, password: string) {
|
public async logIn(
|
||||||
const loginParams: any = {
|
username: string,
|
||||||
|
password: string
|
||||||
|
): Promise<{
|
||||||
|
isLoggedIn: boolean
|
||||||
|
userName: string
|
||||||
|
}> {
|
||||||
|
const loginParams = {
|
||||||
_service: 'default',
|
_service: 'default',
|
||||||
username,
|
username,
|
||||||
password
|
password
|
||||||
}
|
}
|
||||||
|
|
||||||
this.userName = loginParams.username
|
let {
|
||||||
|
isLoggedIn: isLoggedInAlready,
|
||||||
|
loginForm,
|
||||||
|
userName: currentSessionUsername
|
||||||
|
} = await this.checkSession()
|
||||||
|
|
||||||
const { isLoggedIn, loginForm } = await this.checkSession()
|
if (isLoggedInAlready) {
|
||||||
|
if (currentSessionUsername === loginParams.username) {
|
||||||
|
await this.loginCallback()
|
||||||
|
|
||||||
if (isLoggedIn) {
|
this.userName = currentSessionUsername!
|
||||||
await this.loginCallback()
|
return {
|
||||||
|
isLoggedIn: true,
|
||||||
return {
|
userName: this.userName
|
||||||
isLoggedIn,
|
}
|
||||||
userName: this.userName
|
} else {
|
||||||
|
this.logOut()
|
||||||
}
|
}
|
||||||
}
|
} else this.userName = ''
|
||||||
|
|
||||||
let loginResponse = await this.sendLoginRequest(loginForm, loginParams)
|
let loginResponse = await this.sendLoginRequest(loginForm, loginParams)
|
||||||
|
|
||||||
let loggedIn = isLogInSuccess(loginResponse)
|
let isLoggedIn = isLogInSuccess(loginResponse)
|
||||||
|
|
||||||
if (!loggedIn) {
|
if (!isLoggedIn) {
|
||||||
if (isCredentialsVerifyError(loginResponse)) {
|
if (isCredentialsVerifyError(loginResponse)) {
|
||||||
const newLoginForm = await this.getLoginForm(loginResponse)
|
const newLoginForm = await this.getLoginForm(loginResponse)
|
||||||
|
|
||||||
loginResponse = await this.sendLoginRequest(newLoginForm, loginParams)
|
loginResponse = await this.sendLoginRequest(newLoginForm, loginParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentSession = await this.checkSession()
|
const res = await this.checkSession()
|
||||||
loggedIn = currentSession.isLoggedIn
|
isLoggedIn = res.isLoggedIn
|
||||||
|
|
||||||
|
if (isLoggedIn) this.userName = res.userName!
|
||||||
|
} else {
|
||||||
|
this.userName = loginParams.username
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loggedIn) {
|
if (isLoggedIn) {
|
||||||
if (this.serverType === ServerType.Sas9) {
|
if (this.serverType === ServerType.Sas9) {
|
||||||
const casAuthenticationUrl = `${this.serverUrl}/SASStoredProcess/j_spring_cas_security_check`
|
const casAuthenticationUrl = `${this.serverUrl}/SASStoredProcess/j_spring_cas_security_check`
|
||||||
|
|
||||||
@@ -70,10 +88,10 @@ export class AuthManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.loginCallback()
|
this.loginCallback()
|
||||||
}
|
} else this.userName = ''
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isLoggedIn: !!loggedIn,
|
isLoggedIn,
|
||||||
userName: this.userName
|
userName: this.userName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,14 +121,21 @@ export class AuthManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether a session is active, or login is required.
|
* Checks whether a session is active, or login is required.
|
||||||
* @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 three values
|
||||||
|
* - a boolean `isLoggedIn`
|
||||||
|
* - a string `userName` and
|
||||||
|
* - a form `loginForm` if not loggedin.
|
||||||
*/
|
*/
|
||||||
public async checkSession() {
|
public async checkSession(): Promise<{
|
||||||
|
isLoggedIn: boolean
|
||||||
|
userName?: string
|
||||||
|
loginForm?: any
|
||||||
|
}> {
|
||||||
//For VIYA we will send request on API endpoint. Which is faster then pinging SASJobExecution.
|
//For VIYA we will send request on API endpoint. Which is faster then pinging SASJobExecution.
|
||||||
//For SAS9 we will send request on SASStoredProcess
|
//For SAS9 we will send request on SASStoredProcess
|
||||||
const url =
|
const url =
|
||||||
this.serverType === 'SASVIYA'
|
this.serverType === 'SASVIYA'
|
||||||
? `${this.serverUrl}/identities`
|
? `${this.serverUrl}/identities/users/@currentUser`
|
||||||
: `${this.serverUrl}/SASStoredProcess`
|
: `${this.serverUrl}/SASStoredProcess`
|
||||||
|
|
||||||
const { result: loginResponse } = await this.requestClient
|
const { result: loginResponse } = await this.requestClient
|
||||||
@@ -120,6 +145,10 @@ export class AuthManager {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const isLoggedIn = loginResponse !== 'authErr'
|
const isLoggedIn = loginResponse !== 'authErr'
|
||||||
|
const userName = isLoggedIn
|
||||||
|
? this.extractUserName(loginResponse)
|
||||||
|
: undefined
|
||||||
|
|
||||||
let loginForm = null
|
let loginForm = null
|
||||||
|
|
||||||
if (!isLoggedIn) {
|
if (!isLoggedIn) {
|
||||||
@@ -138,11 +167,29 @@ export class AuthManager {
|
|||||||
|
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
isLoggedIn,
|
isLoggedIn,
|
||||||
userName: this.userName,
|
userName: userName?.toLowerCase(),
|
||||||
loginForm
|
loginForm
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private extractUserName = (response: any): string => {
|
||||||
|
switch (this.serverType) {
|
||||||
|
case ServerType.SasViya:
|
||||||
|
return response?.id
|
||||||
|
|
||||||
|
case ServerType.Sas9:
|
||||||
|
const matched = response?.match(/"title":"Log Off [0-1a-zA-Z ]*"/)
|
||||||
|
const username = matched?.[0].slice(17, -1)
|
||||||
|
|
||||||
|
if (!username.includes(' ')) return username
|
||||||
|
|
||||||
|
return username
|
||||||
|
.split(' ')
|
||||||
|
.map((name: string) => name.slice(0, 3).toLowerCase())
|
||||||
|
.join('')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private getLoginForm(response: any) {
|
private getLoginForm(response: any) {
|
||||||
const pattern: RegExp = /<form.+action="(.*Logon[^"]*).*>/
|
const pattern: RegExp = /<form.+action="(.*Logon[^"]*).*>/
|
||||||
const matches = pattern.exec(response)
|
const matches = pattern.exec(response)
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ describe('AuthManager', () => {
|
|||||||
jest.spyOn(authManager, 'checkSession').mockImplementation(() =>
|
jest.spyOn(authManager, 'checkSession').mockImplementation(() =>
|
||||||
Promise.resolve({
|
Promise.resolve({
|
||||||
isLoggedIn: true,
|
isLoggedIn: true,
|
||||||
userName: 'test',
|
userName,
|
||||||
loginForm: 'test'
|
loginForm: 'test'
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -89,7 +89,6 @@ describe('AuthManager', () => {
|
|||||||
jest.spyOn(authManager, 'checkSession').mockImplementation(() =>
|
jest.spyOn(authManager, 'checkSession').mockImplementation(() =>
|
||||||
Promise.resolve({
|
Promise.resolve({
|
||||||
isLoggedIn: false,
|
isLoggedIn: false,
|
||||||
userName: 'test',
|
|
||||||
loginForm: { name: 'test' }
|
loginForm: { name: 'test' }
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -175,7 +174,7 @@ describe('AuthManager', () => {
|
|||||||
expect(response.isLoggedIn).toBeTruthy()
|
expect(response.isLoggedIn).toBeTruthy()
|
||||||
expect(mockedAxios.get).toHaveBeenNthCalledWith(
|
expect(mockedAxios.get).toHaveBeenNthCalledWith(
|
||||||
1,
|
1,
|
||||||
`http://test-server.com/identities`,
|
`http://test-server.com/identities/users/@currentUser`,
|
||||||
{
|
{
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
responseType: 'text',
|
responseType: 'text',
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
} from '../types/errors'
|
} from '../types/errors'
|
||||||
import { ExtraResponseAttributes } from '@sasjs/utils/types'
|
import { ExtraResponseAttributes } from '@sasjs/utils/types'
|
||||||
import { BaseJobExecutor } from './JobExecutor'
|
import { BaseJobExecutor } from './JobExecutor'
|
||||||
|
import { appendExtraResponseAttributes } from '../utils'
|
||||||
|
|
||||||
export class JesJobExecutor extends BaseJobExecutor {
|
export class JesJobExecutor extends BaseJobExecutor {
|
||||||
constructor(serverUrl: string, private sasViyaApiClient: SASViyaApiClient) {
|
constructor(serverUrl: string, private sasViyaApiClient: SASViyaApiClient) {
|
||||||
@@ -29,21 +30,10 @@ export class JesJobExecutor extends BaseJobExecutor {
|
|||||||
.then((response: any) => {
|
.then((response: any) => {
|
||||||
this.sasViyaApiClient.appendRequest(response, sasJob, config.debug)
|
this.sasViyaApiClient.appendRequest(response, sasJob, config.debug)
|
||||||
|
|
||||||
let responseObject = {}
|
const responseObject = appendExtraResponseAttributes(
|
||||||
|
response,
|
||||||
if (extraResponseAttributes && extraResponseAttributes.length > 0) {
|
extraResponseAttributes
|
||||||
const extraAttributes = extraResponseAttributes.reduce(
|
)
|
||||||
(map: any, obj: any) => ((map[obj] = response[obj]), map),
|
|
||||||
{}
|
|
||||||
)
|
|
||||||
|
|
||||||
responseObject = {
|
|
||||||
result: response.result,
|
|
||||||
...extraAttributes
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
responseObject = response.result
|
|
||||||
}
|
|
||||||
|
|
||||||
resolve(responseObject)
|
resolve(responseObject)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
import { ServerType } from '@sasjs/utils/types'
|
import {
|
||||||
|
AuthConfig,
|
||||||
|
ExtraResponseAttributes,
|
||||||
|
ServerType
|
||||||
|
} from '@sasjs/utils/types'
|
||||||
import {
|
import {
|
||||||
ErrorResponse,
|
ErrorResponse,
|
||||||
JobExecutionError,
|
JobExecutionError,
|
||||||
@@ -12,7 +16,8 @@ import { SASViyaApiClient } from '../SASViyaApiClient'
|
|||||||
import {
|
import {
|
||||||
isRelativePath,
|
isRelativePath,
|
||||||
getValidJson,
|
getValidJson,
|
||||||
parseSasViyaDebugResponse
|
parseSasViyaDebugResponse,
|
||||||
|
appendExtraResponseAttributes
|
||||||
} from '../utils'
|
} from '../utils'
|
||||||
import { BaseJobExecutor } from './JobExecutor'
|
import { BaseJobExecutor } from './JobExecutor'
|
||||||
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
|
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
|
||||||
@@ -37,7 +42,9 @@ export class WebJobExecutor extends BaseJobExecutor {
|
|||||||
sasJob: string,
|
sasJob: string,
|
||||||
data: any,
|
data: any,
|
||||||
config: any,
|
config: any,
|
||||||
loginRequiredCallback?: any
|
loginRequiredCallback?: any,
|
||||||
|
authConfig?: AuthConfig,
|
||||||
|
extraResponseAttributes: ExtraResponseAttributes[] = []
|
||||||
) {
|
) {
|
||||||
const loginCallback = loginRequiredCallback || (() => Promise.resolve())
|
const loginCallback = loginRequiredCallback || (() => Promise.resolve())
|
||||||
const program = isRelativePath(sasJob)
|
const program = isRelativePath(sasJob)
|
||||||
@@ -114,24 +121,32 @@ export class WebJobExecutor extends BaseJobExecutor {
|
|||||||
this.requestClient!.post(apiUrl, formData, undefined)
|
this.requestClient!.post(apiUrl, formData, undefined)
|
||||||
.then(async (res: any) => {
|
.then(async (res: any) => {
|
||||||
this.requestClient!.appendRequest(res, sasJob, config.debug)
|
this.requestClient!.appendRequest(res, sasJob, config.debug)
|
||||||
if (this.serverType === ServerType.SasViya && config.debug) {
|
|
||||||
const jsonResponse = await parseSasViyaDebugResponse(
|
|
||||||
res.result,
|
|
||||||
this.requestClient,
|
|
||||||
this.serverUrl
|
|
||||||
)
|
|
||||||
resolve(jsonResponse)
|
|
||||||
}
|
|
||||||
if (this.serverType === ServerType.Sas9 && config.debug) {
|
|
||||||
let jsonResponse = res.result
|
|
||||||
if (typeof res.result === 'string')
|
|
||||||
jsonResponse = parseWeboutResponse(res.result, apiUrl)
|
|
||||||
|
|
||||||
getValidJson(jsonResponse)
|
let jsonResponse = res.result
|
||||||
resolve(res.result)
|
|
||||||
|
if (config.debug) {
|
||||||
|
switch (this.serverType) {
|
||||||
|
case ServerType.SasViya:
|
||||||
|
jsonResponse = await parseSasViyaDebugResponse(
|
||||||
|
res.result,
|
||||||
|
this.requestClient,
|
||||||
|
this.serverUrl
|
||||||
|
)
|
||||||
|
break
|
||||||
|
case ServerType.Sas9:
|
||||||
|
jsonResponse =
|
||||||
|
typeof res.result === 'string'
|
||||||
|
? parseWeboutResponse(res.result, apiUrl)
|
||||||
|
: res.result
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
getValidJson(res.result as string)
|
|
||||||
resolve(res.result)
|
const responseObject = appendExtraResponseAttributes(
|
||||||
|
{ result: jsonResponse },
|
||||||
|
extraResponseAttributes
|
||||||
|
)
|
||||||
|
resolve(responseObject)
|
||||||
})
|
})
|
||||||
.catch(async (e: Error) => {
|
.catch(async (e: Error) => {
|
||||||
if (e instanceof JobExecutionError) {
|
if (e instanceof JobExecutionError) {
|
||||||
@@ -147,7 +162,9 @@ export class WebJobExecutor extends BaseJobExecutor {
|
|||||||
sasJob,
|
sasJob,
|
||||||
data,
|
data,
|
||||||
config,
|
config,
|
||||||
loginRequiredCallback
|
loginRequiredCallback,
|
||||||
|
authConfig,
|
||||||
|
extraResponseAttributes
|
||||||
).then(
|
).then(
|
||||||
(res: any) => {
|
(res: any) => {
|
||||||
resolve(res)
|
resolve(res)
|
||||||
|
|||||||
@@ -562,46 +562,60 @@ export const throwIfError = (response: AxiosResponse) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const parseError = (data: string) => {
|
const parseError = (data: string) => {
|
||||||
|
if (!data) return null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const responseJson = JSON.parse(data?.replace(/[\n\r]/g, ' '))
|
const responseJson = JSON.parse(data?.replace(/[\n\r]/g, ' '))
|
||||||
return responseJson.errorCode && responseJson.message
|
if (responseJson.errorCode && responseJson.message) {
|
||||||
? new JobExecutionError(
|
return new JobExecutionError(
|
||||||
responseJson.errorCode,
|
responseJson.errorCode,
|
||||||
responseJson.message,
|
responseJson.message,
|
||||||
data?.replace(/[\n\r]/g, ' ')
|
data?.replace(/[\n\r]/g, ' ')
|
||||||
)
|
)
|
||||||
: null
|
|
||||||
} catch (_) {
|
|
||||||
try {
|
|
||||||
const hasError = data?.includes('{"errorCode')
|
|
||||||
if (hasError) {
|
|
||||||
const parts = data.split('{"errorCode')
|
|
||||||
if (parts.length > 1) {
|
|
||||||
const error = '{"errorCode' + parts[1].split('"}')[0] + '"}'
|
|
||||||
const errorJson = JSON.parse(error.replace(/[\n\r]/g, ' '))
|
|
||||||
return new JobExecutionError(
|
|
||||||
errorJson.errorCode,
|
|
||||||
errorJson.message,
|
|
||||||
data?.replace(/[\n\r]/g, '\n')
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const hasError = !!data?.match(/stored process not found: /i)
|
|
||||||
if (hasError) {
|
|
||||||
const parts = data.split(/stored process not found: /i)
|
|
||||||
if (parts.length > 1) {
|
|
||||||
const storedProcessPath = parts[1].split('<i>')[1].split('</i>')[0]
|
|
||||||
const message = `Stored process not found: ${storedProcessPath}`
|
|
||||||
return new JobExecutionError(404, message, '')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (_) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
} catch (_) {
|
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
}
|
} catch (_) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const hasError = data?.includes('{"errorCode')
|
||||||
|
if (hasError) {
|
||||||
|
const parts = data.split('{"errorCode')
|
||||||
|
if (parts.length > 1) {
|
||||||
|
const error = '{"errorCode' + parts[1].split('"}')[0] + '"}'
|
||||||
|
const errorJson = JSON.parse(error.replace(/[\n\r]/g, ' '))
|
||||||
|
return new JobExecutionError(
|
||||||
|
errorJson.errorCode,
|
||||||
|
errorJson.message,
|
||||||
|
data?.replace(/[\n\r]/g, '\n')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const hasError = !!data?.match(/stored process not found: /i)
|
||||||
|
if (hasError) {
|
||||||
|
const parts = data.split(/stored process not found: /i)
|
||||||
|
if (parts.length > 1) {
|
||||||
|
const storedProcessPath = parts[1].split('<i>')[1].split('</i>')[0]
|
||||||
|
const message = `Stored process not found: ${storedProcessPath}`
|
||||||
|
return new JobExecutionError(404, message, '')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const hasError =
|
||||||
|
!!data?.match(/Stored Process Error/i) &&
|
||||||
|
!!data?.match(/This request completed with errors./i)
|
||||||
|
if (hasError) {
|
||||||
|
const parts = data.split('<h2>SAS Log</h2>')
|
||||||
|
if (parts.length > 1) {
|
||||||
|
const log = parts[1].split('<pre>')[1].split('</pre>')[0]
|
||||||
|
const message = `This request completed with errors.`
|
||||||
|
return new JobExecutionError(404, message, log)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
22
src/utils/appendExtraResponseAttributes.ts
Normal file
22
src/utils/appendExtraResponseAttributes.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { ExtraResponseAttributes } from '@sasjs/utils/types'
|
||||||
|
|
||||||
|
export async function appendExtraResponseAttributes(
|
||||||
|
response: any,
|
||||||
|
extraResponseAttributes: ExtraResponseAttributes[]
|
||||||
|
) {
|
||||||
|
let responseObject = {}
|
||||||
|
|
||||||
|
if (extraResponseAttributes?.length) {
|
||||||
|
const extraAttributes = extraResponseAttributes.reduce(
|
||||||
|
(map: any, obj: any) => ((map[obj] = response[obj]), map),
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
|
||||||
|
responseObject = {
|
||||||
|
result: response.result,
|
||||||
|
...extraAttributes
|
||||||
|
}
|
||||||
|
} else responseObject = response.result
|
||||||
|
|
||||||
|
return responseObject
|
||||||
|
}
|
||||||
@@ -15,3 +15,4 @@ export * from './parseWeboutResponse'
|
|||||||
export * from './fetchLogByChunks'
|
export * from './fetchLogByChunks'
|
||||||
export * from './getValidJson'
|
export * from './getValidJson'
|
||||||
export * from './parseViyaDebugResponse'
|
export * from './parseViyaDebugResponse'
|
||||||
|
export * from './appendExtraResponseAttributes'
|
||||||
|
|||||||
Reference in New Issue
Block a user