mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-03 18:50:05 +00:00
Compare commits
17 Commits
v3.7.11
...
snyk-upgra
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28e0e3a147 | ||
|
|
ee97e8211e | ||
| d0eb1a7bfb | |||
|
|
256e4ef314 | ||
|
|
6a6dfc5e9d | ||
|
|
5140848039 | ||
|
|
31baf01d3e | ||
|
|
804e78cf0c | ||
| f6a621fe46 | |||
| c47d0c9789 | |||
|
|
1ddc71b017 | ||
|
|
3e507885ab | ||
| e92d0d73b5 | |||
| 00a99e752c | |||
|
|
b13f3d2fcb | ||
|
|
495e4b9069 | ||
|
|
2e843e3f36 |
1
docs/CNAME
Normal file
1
docs/CNAME
Normal file
@@ -0,0 +1 @@
|
|||||||
|
adapter.sasjs.io
|
||||||
28
package-lock.json
generated
28
package-lock.json
generated
@@ -8,8 +8,8 @@
|
|||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sasjs/utils": "2.36.1",
|
"@sasjs/utils": "2.40.0",
|
||||||
"axios": "0.26.0",
|
"axios": "^0.26.1",
|
||||||
"axios-cookiejar-support": "1.0.1",
|
"axios-cookiejar-support": "1.0.1",
|
||||||
"form-data": "4.0.0",
|
"form-data": "4.0.0",
|
||||||
"https": "1.0.0",
|
"https": "1.0.0",
|
||||||
@@ -1142,9 +1142,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@sasjs/utils": {
|
"node_modules/@sasjs/utils": {
|
||||||
"version": "2.36.1",
|
"version": "2.40.0",
|
||||||
"resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.36.1.tgz",
|
"resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.40.0.tgz",
|
||||||
"integrity": "sha512-JkGUpLOODsvkeU+S25jb9k2WnvzyD2w6cEk7YyQ/byuqKL8xawH91PPWegrVcJlDY8WmqKE4CPcA3d1mM3B3LA==",
|
"integrity": "sha512-U0y/eqRlvfkMHmKDlr1xmeN+Rask7TnJPuRpOz71P8QpGYTw1M9AyZvzRSk503p4KCJb8ysdcqXyGVLfhuoM+A==",
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/fs-extra": "9.0.13",
|
"@types/fs-extra": "9.0.13",
|
||||||
@@ -2189,9 +2189,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/axios": {
|
"node_modules/axios": {
|
||||||
"version": "0.26.0",
|
"version": "0.26.1",
|
||||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.26.0.tgz",
|
"resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz",
|
||||||
"integrity": "sha512-lKoGLMYtHvFrPVt3r+RBMp9nh34N0M8zEfCWqdWZx6phynIEhQqAdydpyBAAG211zlhX9Rgu08cOamy6XjE5Og==",
|
"integrity": "sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"follow-redirects": "^1.14.8"
|
"follow-redirects": "^1.14.8"
|
||||||
}
|
}
|
||||||
@@ -13870,9 +13870,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@sasjs/utils": {
|
"@sasjs/utils": {
|
||||||
"version": "2.36.1",
|
"version": "2.40.0",
|
||||||
"resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.36.1.tgz",
|
"resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.40.0.tgz",
|
||||||
"integrity": "sha512-JkGUpLOODsvkeU+S25jb9k2WnvzyD2w6cEk7YyQ/byuqKL8xawH91PPWegrVcJlDY8WmqKE4CPcA3d1mM3B3LA==",
|
"integrity": "sha512-U0y/eqRlvfkMHmKDlr1xmeN+Rask7TnJPuRpOz71P8QpGYTw1M9AyZvzRSk503p4KCJb8ysdcqXyGVLfhuoM+A==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@types/fs-extra": "9.0.13",
|
"@types/fs-extra": "9.0.13",
|
||||||
"@types/prompts": "2.0.13",
|
"@types/prompts": "2.0.13",
|
||||||
@@ -14787,9 +14787,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"axios": {
|
"axios": {
|
||||||
"version": "0.26.0",
|
"version": "0.26.1",
|
||||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.26.0.tgz",
|
"resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz",
|
||||||
"integrity": "sha512-lKoGLMYtHvFrPVt3r+RBMp9nh34N0M8zEfCWqdWZx6phynIEhQqAdydpyBAAG211zlhX9Rgu08cOamy6XjE5Og==",
|
"integrity": "sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"follow-redirects": "^1.14.8"
|
"follow-redirects": "^1.14.8"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,8 +72,8 @@
|
|||||||
},
|
},
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sasjs/utils": "2.36.1",
|
"@sasjs/utils": "2.40.0",
|
||||||
"axios": "0.26.0",
|
"axios": "0.26.1",
|
||||||
"axios-cookiejar-support": "1.0.1",
|
"axios-cookiejar-support": "1.0.1",
|
||||||
"form-data": "4.0.0",
|
"form-data": "4.0.0",
|
||||||
"https": "1.0.0",
|
"https": "1.0.0",
|
||||||
|
|||||||
38
src/SASjs.ts
38
src/SASjs.ts
@@ -17,7 +17,8 @@ import {
|
|||||||
MacroVar,
|
MacroVar,
|
||||||
AuthConfig,
|
AuthConfig,
|
||||||
ExtraResponseAttributes,
|
ExtraResponseAttributes,
|
||||||
SasAuthResponse
|
SasAuthResponse,
|
||||||
|
StreamConfig
|
||||||
} from '@sasjs/utils/types'
|
} from '@sasjs/utils/types'
|
||||||
import { RequestClient } from './request/RequestClient'
|
import { RequestClient } from './request/RequestClient'
|
||||||
import { SasjsRequestClient } from './request/SasjsRequestClient'
|
import { SasjsRequestClient } from './request/SasjsRequestClient'
|
||||||
@@ -134,7 +135,7 @@ export default class SASjs {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets compute contexts.
|
* Gets compute contexts.
|
||||||
* @param accessToken - an access token for an authorized user.
|
* @param accessToken - an access token for an authorised user.
|
||||||
*/
|
*/
|
||||||
public async getComputeContexts(accessToken: string) {
|
public async getComputeContexts(accessToken: string) {
|
||||||
this.isMethodSupported('getComputeContexts', [ServerType.SasViya])
|
this.isMethodSupported('getComputeContexts', [ServerType.SasViya])
|
||||||
@@ -144,7 +145,7 @@ export default class SASjs {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets launcher contexts.
|
* Gets launcher contexts.
|
||||||
* @param accessToken - an access token for an authorized user.
|
* @param accessToken - an access token for an authorised user.
|
||||||
*/
|
*/
|
||||||
public async getLauncherContexts(accessToken: string) {
|
public async getLauncherContexts(accessToken: string) {
|
||||||
this.isMethodSupported('getLauncherContexts', [ServerType.SasViya])
|
this.isMethodSupported('getLauncherContexts', [ServerType.SasViya])
|
||||||
@@ -163,7 +164,7 @@ export default class SASjs {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets executable compute contexts.
|
* Gets executable compute contexts.
|
||||||
* @param authConfig - an access token, refresh token, client and secret for an authorized user.
|
* @param authConfig - an access token, refresh token, client and secret for an authorised user.
|
||||||
*/
|
*/
|
||||||
public async getExecutableContexts(authConfig: AuthConfig) {
|
public async getExecutableContexts(authConfig: AuthConfig) {
|
||||||
this.isMethodSupported('getExecutableContexts', [ServerType.SasViya])
|
this.isMethodSupported('getExecutableContexts', [ServerType.SasViya])
|
||||||
@@ -177,8 +178,8 @@ export default class SASjs {
|
|||||||
* @param launchContextName - the name of the launcher context used by the compute service.
|
* @param launchContextName - the name of the launcher context used by the compute service.
|
||||||
* @param sharedAccountId - the ID of the account to run the servers for this context as.
|
* @param sharedAccountId - the ID of the account to run the servers for this context as.
|
||||||
* @param autoExecLines - the lines of code to execute during session initialization.
|
* @param autoExecLines - the lines of code to execute during session initialization.
|
||||||
* @param accessToken - an access token for an authorized user.
|
* @param accessToken - an access token for an authorised user.
|
||||||
* @param authorizedUsers - an optional list of authorized user IDs.
|
* @param authorisedUsers - an optional list of authorised user IDs.
|
||||||
*/
|
*/
|
||||||
public async createComputeContext(
|
public async createComputeContext(
|
||||||
contextName: string,
|
contextName: string,
|
||||||
@@ -186,7 +187,7 @@ export default class SASjs {
|
|||||||
sharedAccountId: string,
|
sharedAccountId: string,
|
||||||
autoExecLines: string[],
|
autoExecLines: string[],
|
||||||
accessToken: string,
|
accessToken: string,
|
||||||
authorizedUsers?: string[]
|
authorisedUsers?: string[]
|
||||||
) {
|
) {
|
||||||
this.isMethodSupported('createComputeContext', [ServerType.SasViya])
|
this.isMethodSupported('createComputeContext', [ServerType.SasViya])
|
||||||
|
|
||||||
@@ -196,7 +197,7 @@ export default class SASjs {
|
|||||||
sharedAccountId,
|
sharedAccountId,
|
||||||
autoExecLines,
|
autoExecLines,
|
||||||
accessToken,
|
accessToken,
|
||||||
authorizedUsers
|
authorisedUsers
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,7 +206,7 @@ export default class SASjs {
|
|||||||
* @param contextName - the name of the context to be created.
|
* @param contextName - the name of the context to be created.
|
||||||
* @param description - the description of the context to be created.
|
* @param description - the description of the context to be created.
|
||||||
* @param launchType - launch type of the context to be created.
|
* @param launchType - launch type of the context to be created.
|
||||||
* @param accessToken - an access token for an authorized user.
|
* @param accessToken - an access token for an authorised user.
|
||||||
*/
|
*/
|
||||||
public async createLauncherContext(
|
public async createLauncherContext(
|
||||||
contextName: string,
|
contextName: string,
|
||||||
@@ -227,7 +228,7 @@ export default class SASjs {
|
|||||||
* Updates a compute context on the given server.
|
* Updates a compute context on the given server.
|
||||||
* @param contextName - the original name of the context to be deleted.
|
* @param contextName - the original name of the context to be deleted.
|
||||||
* @param editedContext - an object with the properties to be updated.
|
* @param editedContext - an object with the properties to be updated.
|
||||||
* @param accessToken - an access token for an authorized user.
|
* @param accessToken - an access token for an authorised user.
|
||||||
*/
|
*/
|
||||||
public async editComputeContext(
|
public async editComputeContext(
|
||||||
contextName: string,
|
contextName: string,
|
||||||
@@ -246,7 +247,7 @@ export default class SASjs {
|
|||||||
/**
|
/**
|
||||||
* Deletes a compute context on the given server.
|
* Deletes a compute context on the given server.
|
||||||
* @param contextName - the name of the context to be deleted.
|
* @param contextName - the name of the context to be deleted.
|
||||||
* @param accessToken - an access token for an authorized user.
|
* @param accessToken - an access token for an authorised user.
|
||||||
*/
|
*/
|
||||||
public async deleteComputeContext(contextName: string, accessToken?: string) {
|
public async deleteComputeContext(contextName: string, accessToken?: string) {
|
||||||
this.isMethodSupported('deleteComputeContext', [ServerType.SasViya])
|
this.isMethodSupported('deleteComputeContext', [ServerType.SasViya])
|
||||||
@@ -261,7 +262,7 @@ export default class SASjs {
|
|||||||
* Returns a JSON representation of a compute context.
|
* Returns a JSON representation of a compute context.
|
||||||
* @example: { "createdBy": "admin", "links": [...], "id": "ID", "version": 2, "name": "context1" }
|
* @example: { "createdBy": "admin", "links": [...], "id": "ID", "version": 2, "name": "context1" }
|
||||||
* @param contextName - the name of the context to return.
|
* @param contextName - the name of the context to return.
|
||||||
* @param accessToken - an access token for an authorized user.
|
* @param accessToken - an access token for an authorised user.
|
||||||
*/
|
*/
|
||||||
public async getComputeContextByName(
|
public async getComputeContextByName(
|
||||||
contextName: string,
|
contextName: string,
|
||||||
@@ -278,7 +279,7 @@ export default class SASjs {
|
|||||||
/**
|
/**
|
||||||
* Returns a JSON representation of a compute context.
|
* Returns a JSON representation of a compute context.
|
||||||
* @param contextId - an id of the context to return.
|
* @param contextId - an id of the context to return.
|
||||||
* @param accessToken - an access token for an authorized user.
|
* @param accessToken - an access token for an authorised user.
|
||||||
*/
|
*/
|
||||||
public async getComputeContextById(contextId: string, accessToken?: string) {
|
public async getComputeContextById(contextId: string, accessToken?: string) {
|
||||||
this.isMethodSupported('getComputeContextById', [ServerType.SasViya])
|
this.isMethodSupported('getComputeContextById', [ServerType.SasViya])
|
||||||
@@ -891,17 +892,24 @@ export default class SASjs {
|
|||||||
* @param members - the JSON specifying the folders and services to be created.
|
* @param members - the JSON specifying the folders and services to be created.
|
||||||
* @param appLoc - the base folder in which to create the new folders and
|
* @param appLoc - the base folder in which to create the new folders and
|
||||||
* services. If not provided, is taken from SASjsConfig.
|
* services. If not provided, is taken from SASjsConfig.
|
||||||
|
* @param streamConfig - optional configuration object of StreamConfig for deploying streaming app.
|
||||||
* @param authConfig - a valid client, secret, refresh and access tokens that are authorised to execute compute jobs.
|
* @param authConfig - a valid client, secret, refresh and access tokens that are authorised to execute compute jobs.
|
||||||
*/
|
*/
|
||||||
public async deployToSASjs(
|
public async deployToSASjs(
|
||||||
members: FileTree,
|
members: FileTree,
|
||||||
appLoc?: string,
|
appLoc?: string,
|
||||||
|
streamConfig?: StreamConfig,
|
||||||
authConfig?: AuthConfig
|
authConfig?: AuthConfig
|
||||||
) {
|
) {
|
||||||
if (!appLoc) {
|
if (!appLoc) {
|
||||||
appLoc = this.sasjsConfig.appLoc
|
appLoc = this.sasjsConfig.appLoc
|
||||||
}
|
}
|
||||||
return await this.sasJSApiClient?.deploy(members, appLoc, authConfig)
|
return await this.sasJSApiClient?.deploy(
|
||||||
|
members,
|
||||||
|
appLoc,
|
||||||
|
streamConfig,
|
||||||
|
authConfig
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async executeJobSASjs(query: ExecutionQuery) {
|
public async executeJobSASjs(query: ExecutionQuery) {
|
||||||
@@ -972,7 +980,7 @@ export default class SASjs {
|
|||||||
/**
|
/**
|
||||||
* Fetches content of the log file
|
* Fetches content of the log file
|
||||||
* @param logUrl - url of the log file.
|
* @param logUrl - url of the log file.
|
||||||
* @param accessToken - an access token for an authorized user.
|
* @param accessToken - an access token for an authorised user.
|
||||||
*/
|
*/
|
||||||
public async fetchLogFileContent(logUrl: string, accessToken?: string) {
|
public async fetchLogFileContent(logUrl: string, accessToken?: string) {
|
||||||
return await this.requestClient!.get(logUrl, accessToken).then((res) => {
|
return await this.requestClient!.get(logUrl, accessToken).then((res) => {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { AuthConfig, ServerType } from '@sasjs/utils/types'
|
import { AuthConfig, ServerType, StreamConfig } from '@sasjs/utils/types'
|
||||||
import { FileTree, ExecutionQuery } from './types'
|
import { FileTree, ExecutionQuery } from './types'
|
||||||
import { RequestClient } from './request/RequestClient'
|
import { RequestClient } from './request/RequestClient'
|
||||||
import { getAccessTokenForSasjs } from './auth/getAccessTokenForSasjs'
|
import { getAccessTokenForSasjs } from './auth/getAccessTokenForSasjs'
|
||||||
@@ -20,6 +20,7 @@ export class SASjsApiClient {
|
|||||||
public async deploy(
|
public async deploy(
|
||||||
members: FileTree,
|
members: FileTree,
|
||||||
appLoc: string,
|
appLoc: string,
|
||||||
|
streamConfig?: StreamConfig,
|
||||||
authConfig?: AuthConfig
|
authConfig?: AuthConfig
|
||||||
) {
|
) {
|
||||||
let access_token = (authConfig || {}).access_token
|
let access_token = (authConfig || {}).access_token
|
||||||
@@ -33,10 +34,17 @@ export class SASjsApiClient {
|
|||||||
const { result } = await this.requestClient.post<{
|
const { result } = await this.requestClient.post<{
|
||||||
status: string
|
status: string
|
||||||
message: string
|
message: string
|
||||||
|
streamServiceName?: string
|
||||||
example?: {}
|
example?: {}
|
||||||
}>(
|
}>(
|
||||||
'SASjsApi/drive/deploy',
|
'SASjsApi/drive/deploy',
|
||||||
{ fileTree: members, appLoc: appLoc },
|
{
|
||||||
|
fileTree: members,
|
||||||
|
appLoc: appLoc,
|
||||||
|
streamServiceName: streamConfig?.streamServiceName,
|
||||||
|
streamWebFolder: streamConfig?.streamWebFolder,
|
||||||
|
streamLogo: streamConfig?.streamLogo
|
||||||
|
},
|
||||||
access_token,
|
access_token,
|
||||||
undefined,
|
undefined,
|
||||||
{},
|
{},
|
||||||
|
|||||||
@@ -26,11 +26,18 @@ export const generateFileUploadForm = (
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const file = new Blob([csv], {
|
if (typeof FormData === 'undefined' && formData instanceof NodeFormData) {
|
||||||
type: 'application/csv'
|
formData.append(name, csv, {
|
||||||
})
|
filename: `${name}.csv`,
|
||||||
|
contentType: 'application/csv'
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
const file = new Blob([csv], {
|
||||||
|
type: 'application/csv'
|
||||||
|
})
|
||||||
|
|
||||||
formData.append(name, file, `${name}.csv`)
|
formData.append(name, file, `${name}.csv`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return formData
|
return formData
|
||||||
|
|||||||
@@ -74,38 +74,32 @@ export class Sas9JobExecutor extends BaseJobExecutor {
|
|||||||
? 'multipart/form-data; boundary=' + (formData as any)._boundary
|
? 'multipart/form-data; boundary=' + (formData as any)._boundary
|
||||||
: 'text/plain'
|
: 'text/plain'
|
||||||
|
|
||||||
return await this.sas9RequestClient!.post(
|
const requestPromise = new Promise((resolve, reject) =>
|
||||||
apiUrl,
|
this.sas9RequestClient!.post(apiUrl, formData, undefined, contentType, {
|
||||||
formData,
|
|
||||||
undefined,
|
|
||||||
contentType,
|
|
||||||
{
|
|
||||||
Accept: '*/*',
|
Accept: '*/*',
|
||||||
Connection: 'Keep-Alive'
|
Connection: 'Keep-Alive'
|
||||||
}
|
})
|
||||||
|
.then((res: any) => {
|
||||||
|
// appending response to requests array that will be used for requests history reference
|
||||||
|
this.requestClient!.appendRequest(res, sasJob, config.debug)
|
||||||
|
resolve(res)
|
||||||
|
})
|
||||||
|
.catch((err: any) => {
|
||||||
|
// by default error string is equal to actual error object
|
||||||
|
let errString = err
|
||||||
|
|
||||||
|
// if error object contains non empty result attribute, set result to errString
|
||||||
|
if (err.result && err.result !== '') errString = err.result
|
||||||
|
// if there's no result but error message, set error message to errString
|
||||||
|
else if (err.message) errString = err.message
|
||||||
|
|
||||||
|
// appending error to requests array that will be used for requests history reference
|
||||||
|
this.requestClient!.appendRequest(errString, sasJob, config.debug)
|
||||||
|
reject(new ErrorResponse(err?.message, err))
|
||||||
|
})
|
||||||
)
|
)
|
||||||
.then((res: any) => {
|
|
||||||
let resString = res
|
|
||||||
|
|
||||||
if (typeof res === 'object') {
|
return requestPromise
|
||||||
resString = JSON.stringify(res)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.requestClient!.appendRequest(resString, sasJob, config.debug)
|
|
||||||
|
|
||||||
return res
|
|
||||||
})
|
|
||||||
.catch((err: any) => {
|
|
||||||
let errString = err
|
|
||||||
|
|
||||||
if (typeof err === 'object') {
|
|
||||||
errString = JSON.stringify(errString)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.requestClient!.appendRequest(errString, sasJob, config.debug)
|
|
||||||
|
|
||||||
return err
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private getRequestParams(config: any): any {
|
private getRequestParams(config: any): any {
|
||||||
|
|||||||
@@ -557,8 +557,18 @@ export class RequestClient implements HttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const throwIfError = (response: AxiosResponse) => {
|
export const throwIfError = (response: AxiosResponse) => {
|
||||||
if (response.status === 401) {
|
switch (response.status) {
|
||||||
throw new LoginRequiredError()
|
case 400:
|
||||||
|
if (typeof response.data === 'object') {
|
||||||
|
throw new LoginRequiredError(response.data)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 401:
|
||||||
|
if (typeof response.data === 'object') {
|
||||||
|
throw new LoginRequiredError(response.data)
|
||||||
|
} else {
|
||||||
|
throw new LoginRequiredError()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.data?.entityID?.includes('login')) {
|
if (response.data?.entityID?.includes('login')) {
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ const ERROR_MESSAGES = {
|
|||||||
CCA: 'unable to verify the first certificate'
|
CCA: 'unable to verify the first certificate'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const incorrectAuthCodeErr = {
|
||||||
|
error: 'unauthorized',
|
||||||
|
error_description: 'Bad credentials'
|
||||||
|
}
|
||||||
|
|
||||||
describe('RequestClient', () => {
|
describe('RequestClient', () => {
|
||||||
let server: http.Server
|
let server: http.Server
|
||||||
|
|
||||||
@@ -65,7 +70,7 @@ describe('RequestClient', () => {
|
|||||||
adapter.getAccessToken('clientId', 'clientSecret', 'incorrect')
|
adapter.getAccessToken('clientId', 'clientSecret', 'incorrect')
|
||||||
).rejects.toEqual(
|
).rejects.toEqual(
|
||||||
prefixMessage(
|
prefixMessage(
|
||||||
new LoginRequiredError(),
|
new LoginRequiredError(incorrectAuthCodeErr),
|
||||||
'Error while getting access token. '
|
'Error while getting access token. '
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -246,7 +251,7 @@ describe('RequestClient - Self Signed Server', () => {
|
|||||||
adapter.getAccessToken('clientId', 'clientSecret', 'incorrect')
|
adapter.getAccessToken('clientId', 'clientSecret', 'incorrect')
|
||||||
).rejects.toEqual(
|
).rejects.toEqual(
|
||||||
prefixMessage(
|
prefixMessage(
|
||||||
new LoginRequiredError(),
|
new LoginRequiredError(incorrectAuthCodeErr),
|
||||||
'Error while getting access token. '
|
'Error while getting access token. '
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
export class LoginRequiredError extends Error {
|
export class LoginRequiredError extends Error {
|
||||||
constructor() {
|
constructor(details?: any) {
|
||||||
super('Auth error: You must be logged in to access this resource')
|
const message = details
|
||||||
|
? JSON.stringify(details, null, 2)
|
||||||
|
: 'You must be logged in to access this resource'
|
||||||
|
|
||||||
|
super(`Auth error: ${message}`)
|
||||||
this.name = 'LoginRequiredError'
|
this.name = 'LoginRequiredError'
|
||||||
Object.setPrototypeOf(this, LoginRequiredError.prototype)
|
Object.setPrototypeOf(this, LoginRequiredError.prototype)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user