mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-08 04:50:06 +00:00
Compare commits
8 Commits
session-ma
...
v1.18.4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f0590e0fe | ||
|
|
5efb294ff2 | ||
|
|
011e2d83dc | ||
|
|
e36b511530 | ||
|
|
b6a2a85d1d | ||
|
|
f1cceeb5e6 | ||
|
|
6fee2548fd | ||
|
|
91005066cf |
6
sasjs-tests/package-lock.json
generated
6
sasjs-tests/package-lock.json
generated
@@ -1357,9 +1357,9 @@
|
|||||||
"integrity": "sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw=="
|
"integrity": "sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw=="
|
||||||
},
|
},
|
||||||
"@sasjs/adapter": {
|
"@sasjs/adapter": {
|
||||||
"version": "1.12.0",
|
"version": "1.18.3",
|
||||||
"resolved": "https://registry.npmjs.org/@sasjs/adapter/-/adapter-1.12.0.tgz",
|
"resolved": "https://registry.npmjs.org/@sasjs/adapter/-/adapter-1.18.3.tgz",
|
||||||
"integrity": "sha512-0uGQH9ynomWzdBaEujEtcR38q6V7LCgG0mrb1Wellv6cC/IHD3j6WfeZZAgtiMPeOSJjbCDBOlVnzC2TlBqJFw==",
|
"integrity": "sha512-wzDFJRyt2dXFeQP+JzqRGunYUbujrAbU/Jc4IWg5URsCkGAzwsNl/4G0xJVbqOTy1MvoZ431rfCnvhkUlg7D3Q==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"es6-promise": "^4.2.8",
|
"es6-promise": "^4.2.8",
|
||||||
"form-data": "^3.0.0",
|
"form-data": "^3.0.0",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"homepage": ".",
|
"homepage": ".",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sasjs/adapter": "^1.12.0",
|
"@sasjs/adapter": "^1.18.2",
|
||||||
"@sasjs/test-framework": "^1.4.0",
|
"@sasjs/test-framework": "^1.4.0",
|
||||||
"@testing-library/jest-dom": "^4.2.4",
|
"@testing-library/jest-dom": "^4.2.4",
|
||||||
"@testing-library/react": "^9.5.0",
|
"@testing-library/react": "^9.5.0",
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
import React from "react";
|
|
||||||
import { render } from "@testing-library/react";
|
|
||||||
import App from "./App";
|
|
||||||
|
|
||||||
test("renders learn react link", () => {
|
|
||||||
const { getByText } = render(<App />);
|
|
||||||
const linkElement = getByText(/learn react/i);
|
|
||||||
expect(linkElement).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
@@ -3,12 +3,12 @@ import { TestSuite } from "@sasjs/test-framework";
|
|||||||
|
|
||||||
const defaultConfig: SASjsConfig = {
|
const defaultConfig: SASjsConfig = {
|
||||||
serverUrl: window.location.origin,
|
serverUrl: window.location.origin,
|
||||||
pathSAS9: "/SASStoredProcess/do",
|
pathSAS9: '/SASStoredProcess/do',
|
||||||
pathSASViya: "/SASJobExecution",
|
pathSASViya: '/SASJobExecution',
|
||||||
appLoc: "/Public/seedapp",
|
appLoc: '/Public/seedapp',
|
||||||
serverType: ServerType.SASViya,
|
serverType: ServerType.SASViya,
|
||||||
debug: true,
|
debug: false,
|
||||||
contextName: "SAS Job Execution compute context",
|
contextName: 'SAS Job Execution compute context',
|
||||||
useComputeApi: false
|
useComputeApi: false
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -57,6 +57,7 @@ export const basicTests = (
|
|||||||
},
|
},
|
||||||
assertion: (sasjsInstance: SASjs) => {
|
assertion: (sasjsInstance: SASjs) => {
|
||||||
const sasjsConfig = sasjsInstance.getSasjsConfig();
|
const sasjsConfig = sasjsInstance.getSasjsConfig();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
sasjsConfig.serverUrl === defaultConfig.serverUrl &&
|
sasjsConfig.serverUrl === defaultConfig.serverUrl &&
|
||||||
sasjsConfig.pathSAS9 === defaultConfig.pathSAS9 &&
|
sasjsConfig.pathSAS9 === defaultConfig.pathSAS9 &&
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ export const sendArrTests = (adapter: SASjs): TestSuite => ({
|
|||||||
return adapter.request("common/sendArr", data).catch((e) => e);
|
return adapter.request("common/sendArr", data).catch((e) => e);
|
||||||
},
|
},
|
||||||
assertion: (error: any) => {
|
assertion: (error: any) => {
|
||||||
return !!error && !!error.body && !!error.body.message;
|
return !!error && !!error.error && !!error.error.message;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -185,7 +185,7 @@ export const sendObjTests = (adapter: SASjs): TestSuite => ({
|
|||||||
};
|
};
|
||||||
return adapter.request("common/sendObj", invalidData).catch((e) => e);
|
return adapter.request("common/sendObj", invalidData).catch((e) => e);
|
||||||
},
|
},
|
||||||
assertion: (error: any) => !!error && !!error.body && !!error.body.message
|
assertion: (error: any) => !!error && !!error.error && !!error.error.message
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Single string value",
|
title: "Single string value",
|
||||||
@@ -219,7 +219,7 @@ export const sendObjTests = (adapter: SASjs): TestSuite => ({
|
|||||||
.catch((e) => e);
|
.catch((e) => e);
|
||||||
},
|
},
|
||||||
assertion: (error: any) => {
|
assertion: (error: any) => {
|
||||||
return !!error && !!error.body && !!error.body.message;
|
return !!error && !!error.error && !!error.error.message;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,22 +23,24 @@ export const sasjsRequestTests = (adapter: SASjs): TestSuite => ({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Make error and capture log",
|
title: "Make error and capture log",
|
||||||
description: "Should make an error and capture log",
|
description: "Should make an error and capture log, in the same time it is testing if debug override is working",
|
||||||
test: async () => {
|
test: async () => {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
adapter
|
adapter
|
||||||
.request("common/makeErr", data)
|
.request("common/makeErr", data, {debug: true})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
//no action here, this request must throw error
|
//no action here, this request must throw error
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
let sasRequests = adapter.getSasRequests();
|
let sasRequests = adapter.getSasRequests();
|
||||||
let makeErrRequest =
|
let makeErrRequest: any =
|
||||||
sasRequests.find((req) =>
|
sasRequests.find((req) =>
|
||||||
req.serviceLink.includes("makeErr")
|
req.serviceLink.includes("makeErr")
|
||||||
) || null;
|
) || null;
|
||||||
|
|
||||||
resolve(!!makeErrRequest);
|
if (!makeErrRequest) resolve(false)
|
||||||
|
|
||||||
|
resolve(!!(makeErrRequest.logFile && makeErrRequest.logFile.length > 0));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -426,10 +426,10 @@ export class SASViyaApiClient {
|
|||||||
* @param linesOfCode - an array of code lines to execute.
|
* @param linesOfCode - an array of code lines to execute.
|
||||||
* @param contextName - the context to execute the code in.
|
* @param contextName - the context to execute the code in.
|
||||||
* @param accessToken - an access token for an authorized user.
|
* @param accessToken - an access token for an authorized user.
|
||||||
* @param sessionId - optional session ID to reuse.
|
|
||||||
* @param data - execution data.
|
* @param data - execution data.
|
||||||
* @param debug - when set to true, the log will be returned.
|
* @param debug - when set to true, the log will be returned.
|
||||||
* @param expectWebout - when set to true, the automatic _webout fileref will be checked for content, and that content returned. This fileref is used when the Job contains a SASjs web request (as opposed to executing arbitrary SAS code).
|
* @param expectWebout - when set to true, the automatic _webout fileref will be checked for content, and that content returned. This fileref is used when the Job contains a SASjs web request (as opposed to executing arbitrary SAS code).
|
||||||
|
* @param waitForResult - when set to true, function will return the session
|
||||||
*/
|
*/
|
||||||
public async executeScript(
|
public async executeScript(
|
||||||
jobPath: string,
|
jobPath: string,
|
||||||
@@ -437,6 +437,7 @@ export class SASViyaApiClient {
|
|||||||
contextName: string,
|
contextName: string,
|
||||||
accessToken?: string,
|
accessToken?: string,
|
||||||
data = null,
|
data = null,
|
||||||
|
debug: boolean = false,
|
||||||
expectWebout = false,
|
expectWebout = false,
|
||||||
waitForResult = true
|
waitForResult = true
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
@@ -467,7 +468,7 @@ export class SASViyaApiClient {
|
|||||||
_OMITTEXTLOG: true
|
_OMITTEXTLOG: true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.debug) {
|
if (debug) {
|
||||||
jobArguments['_OMITTEXTLOG'] = false
|
jobArguments['_OMITTEXTLOG'] = false
|
||||||
jobArguments['_OMITSESSIONRESULTS'] = false
|
jobArguments['_OMITSESSIONRESULTS'] = false
|
||||||
jobArguments['_DEBUG'] = 131
|
jobArguments['_DEBUG'] = 131
|
||||||
@@ -535,7 +536,7 @@ export class SASViyaApiClient {
|
|||||||
return session
|
return session
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.debug) {
|
if (debug) {
|
||||||
console.log(`Job has been submitted for '${fileName}'.`)
|
console.log(`Job has been submitted for '${fileName}'.`)
|
||||||
console.log(
|
console.log(
|
||||||
`You can monitor the job progress at '${this.serverUrl}${
|
`You can monitor the job progress at '${this.serverUrl}${
|
||||||
@@ -558,7 +559,7 @@ export class SASViyaApiClient {
|
|||||||
|
|
||||||
const logLink = currentJob.links.find((l) => l.rel === 'log')
|
const logLink = currentJob.links.find((l) => l.rel === 'log')
|
||||||
|
|
||||||
if (this.debug && logLink) {
|
if (debug && logLink) {
|
||||||
log = await this.request<any>(
|
log = await this.request<any>(
|
||||||
`${this.serverUrl}${logLink.href}/content?limit=10000`,
|
`${this.serverUrl}${logLink.href}/content?limit=10000`,
|
||||||
{
|
{
|
||||||
@@ -574,7 +575,7 @@ export class SASViyaApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (jobStatus === 'failed' || jobStatus === 'error') {
|
if (jobStatus === 'failed' || jobStatus === 'error') {
|
||||||
return Promise.reject({ error: currentJob.error, log })
|
return Promise.reject({ job: currentJob, log })
|
||||||
}
|
}
|
||||||
|
|
||||||
let resultLink
|
let resultLink
|
||||||
@@ -606,12 +607,10 @@ export class SASViyaApiClient {
|
|||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
|
|
||||||
return Promise.reject(
|
return Promise.reject({
|
||||||
new ErrorResponse('Job execution failed.', {
|
status: 500,
|
||||||
status: 500,
|
log: log
|
||||||
body: log
|
})
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
@@ -635,6 +634,7 @@ export class SASViyaApiClient {
|
|||||||
contextName,
|
contextName,
|
||||||
accessToken,
|
accessToken,
|
||||||
data,
|
data,
|
||||||
|
debug,
|
||||||
false,
|
false,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
@@ -955,6 +955,7 @@ export class SASViyaApiClient {
|
|||||||
public async executeComputeJob(
|
public async executeComputeJob(
|
||||||
sasJob: string,
|
sasJob: string,
|
||||||
contextName: string,
|
contextName: string,
|
||||||
|
debug?: boolean,
|
||||||
data?: any,
|
data?: any,
|
||||||
accessToken?: string,
|
accessToken?: string,
|
||||||
waitForResult = true,
|
waitForResult = true,
|
||||||
@@ -1041,6 +1042,7 @@ export class SASViyaApiClient {
|
|||||||
contextName,
|
contextName,
|
||||||
accessToken,
|
accessToken,
|
||||||
data,
|
data,
|
||||||
|
debug,
|
||||||
expectWebout,
|
expectWebout,
|
||||||
waitForResult
|
waitForResult
|
||||||
)
|
)
|
||||||
|
|||||||
14
src/SASjs.ts
14
src/SASjs.ts
@@ -734,6 +734,7 @@ export default class SASjs {
|
|||||||
return this.sasViyaApiClient?.executeComputeJob(
|
return this.sasViyaApiClient?.executeComputeJob(
|
||||||
sasJob,
|
sasJob,
|
||||||
config.contextName,
|
config.contextName,
|
||||||
|
config.debug,
|
||||||
data,
|
data,
|
||||||
accessToken,
|
accessToken,
|
||||||
!!waitForResult,
|
!!waitForResult,
|
||||||
@@ -766,6 +767,7 @@ export default class SASjs {
|
|||||||
?.executeComputeJob(
|
?.executeComputeJob(
|
||||||
sasJob,
|
sasJob,
|
||||||
config.contextName,
|
config.contextName,
|
||||||
|
config.debug,
|
||||||
data,
|
data,
|
||||||
accessToken,
|
accessToken,
|
||||||
waitForResult,
|
waitForResult,
|
||||||
@@ -895,8 +897,8 @@ export default class SASjs {
|
|||||||
|
|
||||||
return responseJson
|
return responseJson
|
||||||
})
|
})
|
||||||
.catch(async (e) => {
|
.catch(async (response) => {
|
||||||
if (needsRetry(JSON.stringify(e))) {
|
if (needsRetry(JSON.stringify(response))) {
|
||||||
if (this.retryCountJeseApi < requestRetryLimit) {
|
if (this.retryCountJeseApi < requestRetryLimit) {
|
||||||
let retryResponse = await this.executeJobViaJesApi(
|
let retryResponse = await this.executeJobViaJesApi(
|
||||||
sasJob,
|
sasJob,
|
||||||
@@ -917,11 +919,11 @@ export default class SASjs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e?.log) {
|
if (response?.log) {
|
||||||
this.appendSasjsRequest(e.log, sasJob, null)
|
this.appendSasjsRequest(response.log, sasJob, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.toString().includes('Job was not found')) {
|
if (response.toString().includes('Job was not found')) {
|
||||||
reject(
|
reject(
|
||||||
new ErrorResponse('Service not found on the server.', {
|
new ErrorResponse('Service not found on the server.', {
|
||||||
sasJob: sasJob
|
sasJob: sasJob
|
||||||
@@ -929,7 +931,7 @@ export default class SASjs {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
reject(new ErrorResponse('Job execution failed.', e))
|
reject(new ErrorResponse('Job execution failed.', response))
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user