mirror of
https://github.com/sasjs/adapter.git
synced 2025-12-11 09:24:35 +00:00
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0c6409e402 | ||
|
|
68b864cf75 | ||
|
|
75a11cdff4 | ||
|
|
4e2b6d32cc | ||
|
|
cd9757b383 | ||
|
|
fb727788d0 | ||
|
|
35eb6c4935 | ||
|
|
ea0f338b90 | ||
|
|
b6a17b39b9 | ||
|
|
9ed64e5a2c | ||
|
|
0479a5d651 | ||
|
|
005f10bb47 | ||
|
|
98c9cb78ff | ||
|
|
8192f69f67 | ||
|
|
c28a8ebf15 | ||
|
|
a409d8cdb6 | ||
|
|
618a20eaba | ||
|
|
c9b1273c31 | ||
|
|
59674744be | ||
|
|
870cc0055b | ||
|
|
0ffa62fab4 | ||
|
|
b4c7868fb6 | ||
|
|
2266578013 | ||
|
|
f2ebe1a5b0 | ||
|
|
6a52bbe560 | ||
|
|
a5c725e677 |
@@ -70,6 +70,14 @@ parmcards4;
|
||||
%webout(CLOSE)
|
||||
;;;;
|
||||
%mp_createwebservice(path=/Public/app/common,name=sendArr)
|
||||
filename ft15f001 temp;
|
||||
parmcards4;
|
||||
If you can keep your head when all about you
|
||||
Are losing theirs and blaming it on you,
|
||||
If you can trust yourself when all men doubt you,
|
||||
But make allowance for their doubting too;
|
||||
;;;;
|
||||
%mp_createwebservice(path=/Public/app/common,name=makeErr)
|
||||
```
|
||||
|
||||
The above services will return anything you send. To run the tests simply launch `npm run cypress`.
|
||||
|
||||
6
package-lock.json
generated
6
package-lock.json
generated
@@ -1648,9 +1648,9 @@
|
||||
}
|
||||
},
|
||||
"@types/jest": {
|
||||
"version": "26.0.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.9.tgz",
|
||||
"integrity": "sha512-k4qFfJ5AUKrWok5KYXp2EPm89b0P/KZpl7Vg4XuOTVVQEhLDBDBU3iBFrjjdgd8fLw96aAtmnwhXHl63bWeBQQ==",
|
||||
"version": "26.0.10",
|
||||
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.10.tgz",
|
||||
"integrity": "sha512-i2m0oyh8w/Lum7wWK/YOZJakYF8Mx08UaKA1CtbmFeDquVhAEdA7znacsVSf2hJ1OQ/OfVMGN90pw/AtzF8s/Q==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"jest-diff": "^25.2.1",
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@types/isomorphic-fetch": "0.0.35",
|
||||
"@types/jest": "^26.0.9",
|
||||
"@types/jest": "^26.0.10",
|
||||
"cp": "^0.2.0",
|
||||
"jest": "^25.5.4",
|
||||
"path": "^0.12.7",
|
||||
|
||||
24
sasjs-tests/package-lock.json
generated
24
sasjs-tests/package-lock.json
generated
@@ -1357,9 +1357,9 @@
|
||||
"integrity": "sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw=="
|
||||
},
|
||||
"@sasjs/adapter": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@sasjs/adapter/-/adapter-1.2.0.tgz",
|
||||
"integrity": "sha512-PcQcmb7TsfPJ94tzFnvycm+tMYD3wKx2a6niwHfsV9+g6XHtmwReVV3EPZZ5XB4s565vU6Qc+ZnFbMIAeik8QA==",
|
||||
"version": "1.3.6",
|
||||
"resolved": "https://registry.npmjs.org/@sasjs/adapter/-/adapter-1.3.6.tgz",
|
||||
"integrity": "sha512-d2B+cTII+vabKCU8mJy90mEz3tCWw2pEp4qIBGsDamJiTS0Rx69dgXGHuRUm8KtjLDHHrzwXATsqviU3dnU0QQ==",
|
||||
"requires": {
|
||||
"es6-promise": "^4.2.8",
|
||||
"form-data": "^3.0.0",
|
||||
@@ -1379,9 +1379,9 @@
|
||||
}
|
||||
},
|
||||
"@sasjs/test-framework": {
|
||||
"version": "1.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@sasjs/test-framework/-/test-framework-1.3.3.tgz",
|
||||
"integrity": "sha512-Ou4UXlxBAVR8jv7boVvJ/eKLHRTQvDi9LouPAasLCO2EC4AD0wX1hLMwVhmydCvsdgVEeXs6InvX3ROHiKSADg==",
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@sasjs/test-framework/-/test-framework-1.4.0.tgz",
|
||||
"integrity": "sha512-Pd8PUH5B5RO6q4w3OQXX7aWicvA/CJMXA/FCf2xp332ZTKBb/5uV+HphAOFKpCh58y+ykYYVSV0ZaDO/4t1h3A==",
|
||||
"requires": {
|
||||
"@types/react-highlight.js": "^1.0.0",
|
||||
"immer": "^7.0.7",
|
||||
@@ -12234,9 +12234,9 @@
|
||||
}
|
||||
},
|
||||
"semantic-ui-react": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/semantic-ui-react/-/semantic-ui-react-1.1.1.tgz",
|
||||
"integrity": "sha512-QtzLNkK4MUe1HQo4S7/tIkSp4NFtxSGDzTMKxmvztMJ6jt+nKGmMyjpyxJsrm3ohU8Z3sTyBUyiBsDYW4jNtjw==",
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/semantic-ui-react/-/semantic-ui-react-1.2.0.tgz",
|
||||
"integrity": "sha512-9tNL94nEy16RdupTQNiURyemWUIxtTpQgFimCbOOHRBOe1ApsFz3FWFsrGjv9zFtE7dQMslLYov9BQOelTCVwA==",
|
||||
"requires": {
|
||||
"@babel/runtime": "^7.10.5",
|
||||
"@semantic-ui-react/event-stack": "^3.1.0",
|
||||
@@ -12260,9 +12260,9 @@
|
||||
}
|
||||
},
|
||||
"lodash": {
|
||||
"version": "4.17.19",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz",
|
||||
"integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ=="
|
||||
"version": "4.17.20",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz",
|
||||
"integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA=="
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
"homepage": ".",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@sasjs/adapter": "^1.2.0",
|
||||
"@sasjs/test-framework": "^1.3.3",
|
||||
"@sasjs/adapter": "^1.3.6",
|
||||
"@sasjs/test-framework": "^1.4.0",
|
||||
"@testing-library/jest-dom": "^4.2.4",
|
||||
"@testing-library/react": "^9.5.0",
|
||||
"@testing-library/user-event": "^7.2.1",
|
||||
|
||||
@@ -21,5 +21,26 @@ export const sasjsRequestTests = (adapter: SASjs): TestSuite => ({
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Make error and capture log",
|
||||
description: "Should make an error and capture log",
|
||||
test: async () => {
|
||||
return new Promise( async (resolve, reject) => {
|
||||
adapter.request("common/makeErr", data)
|
||||
.then((res) => {
|
||||
//no action here, this request must throw error
|
||||
})
|
||||
.catch((err) => {
|
||||
let sasRequests = adapter.getSasRequests();
|
||||
let makeErrRequest = sasRequests.find(req => req.serviceLink.includes('makeErr')) || null;
|
||||
|
||||
resolve(!!makeErrRequest);
|
||||
})
|
||||
})
|
||||
},
|
||||
assertion: (response) => {
|
||||
return response;
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
@@ -9,7 +9,8 @@ export class FileUploader {
|
||||
private appLoc: string,
|
||||
private serverUrl: string,
|
||||
private jobsPath: string,
|
||||
private csrfToken: CsrfToken | null = null
|
||||
private setCsrfTokenWeb: any,
|
||||
private csrfToken: CsrfToken | null = null,
|
||||
) {}
|
||||
private retryCount = 0;
|
||||
|
||||
@@ -61,6 +62,8 @@ export class FileUploader {
|
||||
headerName: tokenHeader,
|
||||
value: token || "",
|
||||
};
|
||||
|
||||
this.setCsrfTokenWeb(this.csrfToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,127 +206,149 @@ export class SASViyaApiClient {
|
||||
silent = false,
|
||||
data = null,
|
||||
debug = false
|
||||
) {
|
||||
): Promise<any> {
|
||||
silent = !debug;
|
||||
const headers: any = {
|
||||
"Content-Type": "application/json",
|
||||
};
|
||||
if (accessToken) {
|
||||
headers.Authorization = `Bearer ${accessToken}`;
|
||||
}
|
||||
let executionSessionId: string;
|
||||
const session = await this.sessionManager.getSession(accessToken);
|
||||
executionSessionId = session!.id;
|
||||
try {
|
||||
const headers: any = {
|
||||
"Content-Type": "application/json",
|
||||
};
|
||||
|
||||
const jobArguments: { [key: string]: any } = {
|
||||
_contextName: contextName,
|
||||
_OMITJSONLISTING: true,
|
||||
_OMITJSONLOG: true,
|
||||
_OMITSESSIONRESULTS: true,
|
||||
_OMITTEXTLISTING: true,
|
||||
_OMITTEXTLOG: true,
|
||||
};
|
||||
if (accessToken) {
|
||||
headers.Authorization = `Bearer ${accessToken}`;
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
jobArguments["_OMITTEXTLOG"] = false;
|
||||
jobArguments["_OMITSESSIONRESULTS"] = false;
|
||||
jobArguments["_DEBUG"] = 131;
|
||||
}
|
||||
let executionSessionId: string;
|
||||
const session = await this.sessionManager.getSession(accessToken);
|
||||
executionSessionId = session!.id;
|
||||
|
||||
const fileName = `exec-${
|
||||
jobName.includes("/") ? jobName.split("/")[1] : jobName
|
||||
}`;
|
||||
const jobArguments: { [key: string]: any } = {
|
||||
_contextName: contextName,
|
||||
_OMITJSONLISTING: true,
|
||||
_OMITJSONLOG: true,
|
||||
_OMITSESSIONRESULTS: true,
|
||||
_OMITTEXTLISTING: true,
|
||||
_OMITTEXTLOG: true,
|
||||
};
|
||||
|
||||
let jobVariables: any = {
|
||||
SYS_JES_JOB_URI: "",
|
||||
_program: this.rootFolderName + "/" + jobName,
|
||||
};
|
||||
let files: any[] = [];
|
||||
if (data) {
|
||||
if (JSON.stringify(data).includes(";")) {
|
||||
files = await this.uploadTables(data, accessToken);
|
||||
jobVariables["_webin_file_count"] = files.length;
|
||||
files.forEach((fileInfo, index) => {
|
||||
jobVariables[
|
||||
`_webin_fileuri${index + 1}`
|
||||
] = `/files/files/${fileInfo.file.id}`;
|
||||
jobVariables[`_webin_name${index + 1}`] = fileInfo.tableName;
|
||||
});
|
||||
if (debug) {
|
||||
jobArguments["_OMITTEXTLOG"] = false;
|
||||
jobArguments["_OMITSESSIONRESULTS"] = false;
|
||||
jobArguments["_DEBUG"] = 131;
|
||||
}
|
||||
|
||||
const fileName = `exec-${
|
||||
jobName.includes("/") ? jobName.split("/")[1] : jobName
|
||||
}`;
|
||||
|
||||
let jobVariables: any = {
|
||||
SYS_JES_JOB_URI: "",
|
||||
_program: this.rootFolderName + "/" + jobName,
|
||||
};
|
||||
|
||||
let files: any[] = [];
|
||||
|
||||
if (data) {
|
||||
if (JSON.stringify(data).includes(";")) {
|
||||
files = await this.uploadTables(data, accessToken);
|
||||
jobVariables["_webin_file_count"] = files.length;
|
||||
files.forEach((fileInfo, index) => {
|
||||
jobVariables[
|
||||
`_webin_fileuri${index + 1}`
|
||||
] = `/files/files/${fileInfo.file.id}`;
|
||||
jobVariables[`_webin_name${index + 1}`] = fileInfo.tableName;
|
||||
});
|
||||
} else {
|
||||
jobVariables = { ...jobVariables, ...formatDataForRequest(data) };
|
||||
}
|
||||
}
|
||||
|
||||
// Execute job in session
|
||||
const postJobRequest = {
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify({
|
||||
name: fileName,
|
||||
description: "Powered by SASjs",
|
||||
code: linesOfCode,
|
||||
variables: jobVariables,
|
||||
arguments: jobArguments,
|
||||
}),
|
||||
};
|
||||
|
||||
const { result: postedJob, etag } = await this.request<Job>(
|
||||
`${this.serverUrl}/compute/sessions/${executionSessionId}/jobs`,
|
||||
postJobRequest
|
||||
);
|
||||
|
||||
if (!silent) {
|
||||
console.log(`Job has been submitted for ${fileName}`);
|
||||
console.log(
|
||||
`You can monitor the job progress at ${this.serverUrl}${
|
||||
postedJob.links.find((l: any) => l.rel === "state")!.href
|
||||
}`
|
||||
);
|
||||
}
|
||||
|
||||
const jobStatus = await this.pollJobState(
|
||||
postedJob,
|
||||
etag,
|
||||
accessToken,
|
||||
silent
|
||||
);
|
||||
|
||||
const { result: currentJob } = await this.request<Job>(
|
||||
`${this.serverUrl}/compute/sessions/${executionSessionId}/jobs/${postedJob.id}`,
|
||||
{ headers }
|
||||
);
|
||||
|
||||
let jobResult, log;
|
||||
|
||||
const logLink = currentJob.links.find((l) => l.rel === "log");
|
||||
|
||||
if (true && logLink) {
|
||||
log = await this.request<any>(
|
||||
`${this.serverUrl}${logLink.href}/content?limit=10000`,
|
||||
{
|
||||
headers,
|
||||
}
|
||||
).then((res: any) =>
|
||||
res.result.items.map((i: any) => i.line).join("\n")
|
||||
);
|
||||
}
|
||||
|
||||
if (jobStatus === "failed" || jobStatus === "error") {
|
||||
return Promise.reject({ error: currentJob.error, log: log });
|
||||
}
|
||||
const resultLink = `/compute/sessions/${executionSessionId}/filerefs/_webout/content`;
|
||||
|
||||
if (resultLink) {
|
||||
jobResult = await this.request<any>(
|
||||
`${this.serverUrl}${resultLink}`,
|
||||
{ headers },
|
||||
"text"
|
||||
).catch((e) => ({
|
||||
result: JSON.stringify(e),
|
||||
}));
|
||||
}
|
||||
|
||||
await this.sessionManager.clearSession(executionSessionId, accessToken);
|
||||
|
||||
return { result: jobResult?.result, log };
|
||||
} catch (e) {
|
||||
if (e && e.status === 404) {
|
||||
return this.executeScript(
|
||||
jobName,
|
||||
linesOfCode,
|
||||
contextName,
|
||||
accessToken,
|
||||
silent,
|
||||
data,
|
||||
debug
|
||||
);
|
||||
} else {
|
||||
jobVariables = { ...jobVariables, ...formatDataForRequest(data) };
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// Execute job in session
|
||||
const postJobRequest = {
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify({
|
||||
name: fileName,
|
||||
description: "Powered by SASjs",
|
||||
code: linesOfCode,
|
||||
variables: jobVariables,
|
||||
arguments: jobArguments,
|
||||
}),
|
||||
};
|
||||
const { result: postedJob, etag } = await this.request<Job>(
|
||||
`${this.serverUrl}/compute/sessions/${executionSessionId}/jobs`,
|
||||
postJobRequest
|
||||
);
|
||||
if (!silent) {
|
||||
console.log(`Job has been submitted for ${fileName}`);
|
||||
console.log(
|
||||
`You can monitor the job progress at ${this.serverUrl}${
|
||||
postedJob.links.find((l: any) => l.rel === "state")!.href
|
||||
}`
|
||||
);
|
||||
}
|
||||
|
||||
const jobStatus = await this.pollJobState(
|
||||
postedJob,
|
||||
etag,
|
||||
accessToken,
|
||||
silent
|
||||
);
|
||||
const { result: currentJob } = await this.request<Job>(
|
||||
`${this.serverUrl}/compute/sessions/${executionSessionId}/jobs/${postedJob.id}`,
|
||||
{ headers }
|
||||
);
|
||||
|
||||
let jobResult, log;
|
||||
if (jobStatus === "failed" || jobStatus === "error") {
|
||||
return Promise.reject(currentJob.error);
|
||||
}
|
||||
const resultLink = `/compute/sessions/${executionSessionId}/filerefs/_webout/content`;
|
||||
const logLink = currentJob.links.find((l) => l.rel === "log");
|
||||
if (resultLink) {
|
||||
jobResult = await this.request<any>(
|
||||
`${this.serverUrl}${resultLink}`,
|
||||
{ headers },
|
||||
"text"
|
||||
).catch((e) => ({
|
||||
result: JSON.stringify(e),
|
||||
}));
|
||||
}
|
||||
|
||||
if (true && logLink) {
|
||||
log = await this.request<any>(
|
||||
`${this.serverUrl}${logLink.href}/content?limit=10000`,
|
||||
{
|
||||
headers,
|
||||
}
|
||||
).then((res: any) => res.result.items.map((i: any) => i.line).join("\n"));
|
||||
}
|
||||
|
||||
await this.sessionManager.clearSession(executionSessionId, accessToken);
|
||||
|
||||
return { result: jobResult?.result, log };
|
||||
// } else {
|
||||
// console.error(
|
||||
// `Unable to find execution context ${contextName}.\nPlease check the contextName in the tgtDeployVars and try again.`
|
||||
// );
|
||||
// console.error("Response from server: ", JSON.stringify(this.contexts));
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -713,6 +735,7 @@ export class SASViyaApiClient {
|
||||
if (data && Object.keys(data).length) {
|
||||
files = await this.uploadTables(data, accessToken);
|
||||
}
|
||||
|
||||
const jobName = path.basename(sasJob);
|
||||
const jobFolder = sasJob.replace(`/${jobName}`, "");
|
||||
const allJobsInFolder = this.rootFolderMap.get(jobFolder.replace("/", ""));
|
||||
@@ -1007,12 +1030,12 @@ export class SASViyaApiClient {
|
||||
headers,
|
||||
};
|
||||
|
||||
const { result: file } = await this.request<any>(
|
||||
const uploadResponse = await this.request<any>(
|
||||
`${this.serverUrl}/files/files#rawUpload`,
|
||||
createFileRequest
|
||||
);
|
||||
|
||||
uploadedFiles.push({ tableName, file });
|
||||
uploadedFiles.push({ tableName, file: uploadResponse.result });
|
||||
}
|
||||
return uploadedFiles;
|
||||
}
|
||||
|
||||
86
src/SASjs.ts
86
src/SASjs.ts
@@ -1,6 +1,13 @@
|
||||
import "isomorphic-fetch";
|
||||
import { isIEorEdgeOrOldFirefox } from "./utils/isIeOrEdge";
|
||||
import * as e6p from "es6-promise";
|
||||
(e6p as any).polyfill();
|
||||
if (isIEorEdgeOrOldFirefox()) {
|
||||
if (window) {
|
||||
window.fetch = undefined as any; // ensure the polyfill runs
|
||||
}
|
||||
}
|
||||
// tslint:disable-next-line
|
||||
require("isomorphic-fetch");
|
||||
import {
|
||||
convertToCSV,
|
||||
compareTimestamps,
|
||||
@@ -12,6 +19,7 @@ import {
|
||||
isLogInSuccess,
|
||||
parseSourceCode,
|
||||
parseGeneratedCode,
|
||||
parseWeboutResponse,
|
||||
needsRetry,
|
||||
asyncForEach,
|
||||
} from "./utils";
|
||||
@@ -391,8 +399,10 @@ export default class SASjs {
|
||||
this.sasjsConfig.appLoc,
|
||||
this.sasjsConfig.serverUrl,
|
||||
this.jobsPath,
|
||||
this.setCsrfTokenWeb,
|
||||
this.csrfTokenWeb
|
||||
);
|
||||
|
||||
return fileUploader.uploadFile(sasJob, files, params);
|
||||
}
|
||||
|
||||
@@ -559,10 +569,20 @@ export default class SASjs {
|
||||
this.appendSasjsRequest(response, sasJob, null);
|
||||
}
|
||||
|
||||
resolve(JSON.parse(response!.result));
|
||||
let responseJson;
|
||||
|
||||
try {
|
||||
responseJson = JSON.parse(response!.result);
|
||||
} catch {
|
||||
responseJson = JSON.parse(parseWeboutResponse(response!.result));
|
||||
}
|
||||
|
||||
resolve(responseJson);
|
||||
})
|
||||
.catch(async (e) => {
|
||||
if (needsRetry(JSON.stringify(e))) {
|
||||
.catch(async (response) => {
|
||||
let error = response.error || response;
|
||||
|
||||
if (needsRetry(JSON.stringify(error))) {
|
||||
if (this.retryCountComputeApi < requestRetryLimit) {
|
||||
let retryResponse = await this.executeJobViaComputeApi(
|
||||
sasJob,
|
||||
@@ -581,15 +601,17 @@ export default class SASjs {
|
||||
}
|
||||
}
|
||||
|
||||
if (e && e.status === 401) {
|
||||
if (error && error.status === 401) {
|
||||
if (loginRequiredCallback) loginRequiredCallback(true);
|
||||
sasjsWaitingRequest.requestPromise.resolve = resolve;
|
||||
sasjsWaitingRequest.requestPromise.reject = reject;
|
||||
sasjsWaitingRequest.config = config;
|
||||
this.sasjsWaitingRequests.push(sasjsWaitingRequest);
|
||||
} else {
|
||||
reject({ MESSAGE: e || "Job execution failed" });
|
||||
reject({ MESSAGE: error || "Job execution failed" });
|
||||
}
|
||||
|
||||
this.appendSasjsRequest(response.log, sasJob, null);
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -639,7 +661,18 @@ export default class SASjs {
|
||||
} else {
|
||||
this.appendSasjsRequest(response, sasJob, null);
|
||||
}
|
||||
return JSON.parse(response!.result);
|
||||
|
||||
let responseJson;
|
||||
|
||||
try {
|
||||
responseJson = JSON.parse(response!.result);
|
||||
} catch {
|
||||
responseJson = JSON.parse(
|
||||
parseWeboutResponse(response!.result)
|
||||
);
|
||||
}
|
||||
|
||||
return responseJson;
|
||||
})
|
||||
.catch(async (e) => {
|
||||
if (needsRetry(JSON.stringify(e))) {
|
||||
@@ -834,7 +867,7 @@ export default class SASjs {
|
||||
} else {
|
||||
if (config.serverType === ServerType.SAS9 && config.debug) {
|
||||
this.updateUsername(responseText);
|
||||
const jsonResponseText = this.parseSAS9Response(responseText);
|
||||
const jsonResponseText = parseWeboutResponse(responseText);
|
||||
|
||||
if (jsonResponseText !== "") {
|
||||
resolve(JSON.parse(jsonResponseText));
|
||||
@@ -884,6 +917,10 @@ export default class SASjs {
|
||||
|
||||
return sasjsWaitingRequest.requestPromise.promise;
|
||||
}
|
||||
|
||||
private setCsrfTokenWeb = (csrfToken: CsrfToken) => {
|
||||
this.csrfTokenWeb = csrfToken;
|
||||
};
|
||||
|
||||
private setCsrfTokenApi = (csrfToken: CsrfToken) => {
|
||||
this.csrfTokenApi = csrfToken;
|
||||
@@ -975,23 +1012,6 @@ export default class SASjs {
|
||||
return uri;
|
||||
}
|
||||
|
||||
private parseSAS9Response(response: string) {
|
||||
let sas9Response = "";
|
||||
|
||||
if (response.includes(">>weboutBEGIN<<")) {
|
||||
try {
|
||||
sas9Response = response
|
||||
.split(">>weboutBEGIN<<")[1]
|
||||
.split(">>weboutEND<<")[0];
|
||||
} catch (e) {
|
||||
sas9Response = "";
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
return sas9Response;
|
||||
}
|
||||
|
||||
private parseSAS9ErrorResponse(response: string) {
|
||||
const logLines = response.split("\n");
|
||||
const parsedLines: string[] = [];
|
||||
@@ -1049,7 +1069,16 @@ export default class SASjs {
|
||||
if (response && response.result && response.log) {
|
||||
sourceCode = parseSourceCode(response.log);
|
||||
generatedCode = parseGeneratedCode(response.log);
|
||||
sasWork = JSON.parse(response.result).WORK;
|
||||
|
||||
if (this.sasjsConfig.debug) {
|
||||
if (response.log) {
|
||||
sasWork = response.log;
|
||||
} else {
|
||||
sasWork = JSON.parse(parseWeboutResponse(response.result)).WORK;
|
||||
}
|
||||
} else {
|
||||
sasWork = JSON.parse(response.result).WORK;
|
||||
}
|
||||
} else {
|
||||
if (response) {
|
||||
sourceCode = parseSourceCode(response);
|
||||
@@ -1078,7 +1107,7 @@ export default class SASjs {
|
||||
|
||||
if (this.sasjsConfig.serverType === ServerType.SAS9) {
|
||||
try {
|
||||
jsonResponse = JSON.parse(this.parseSAS9Response(response));
|
||||
jsonResponse = JSON.parse(parseWeboutResponse(response));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
@@ -1162,7 +1191,8 @@ export default class SASjs {
|
||||
this.fileUploader = new FileUploader(
|
||||
this.sasjsConfig.appLoc,
|
||||
this.sasjsConfig.serverUrl,
|
||||
this.jobsPath
|
||||
this.jobsPath,
|
||||
this.setCsrfTokenWeb
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,16 @@ export class SessionManager {
|
||||
await this.createSessions(accessToken);
|
||||
this.createAndWaitForSession(accessToken);
|
||||
const session = this.sessions.pop();
|
||||
const secondsSinceSessionCreation =
|
||||
(new Date().getTime() - new Date(session!.creationTimeStamp).getTime()) /
|
||||
1000;
|
||||
if (
|
||||
secondsSinceSessionCreation >= session!.attributes.sessionInactiveTimeout
|
||||
) {
|
||||
await this.createSessions(accessToken);
|
||||
const freshSession = this.sessions.pop();
|
||||
return freshSession;
|
||||
}
|
||||
return session;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,4 +4,8 @@ export interface Session {
|
||||
id: string;
|
||||
state: string;
|
||||
links: Link[];
|
||||
attributes: {
|
||||
sessionInactiveTimeout: number;
|
||||
};
|
||||
creationTimeStamp: string;
|
||||
}
|
||||
|
||||
@@ -12,3 +12,4 @@ export * from "./parseSourceCode";
|
||||
export * from "./parseSasViyaLog";
|
||||
export * from "./serialize";
|
||||
export * from "./splitChunks";
|
||||
export * from "./parseWeboutResponse";
|
||||
|
||||
34
src/utils/isIeOrEdge.ts
Normal file
34
src/utils/isIeOrEdge.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
export function isIEorEdgeOrOldFirefox() {
|
||||
if (typeof window === "undefined") {
|
||||
return false;
|
||||
}
|
||||
const ua = window.navigator.userAgent;
|
||||
|
||||
if (ua.indexOf("Firefox") > 0) {
|
||||
const version = parseInt(
|
||||
ua.substring(ua.lastIndexOf("Firefox/") + 8, ua.length),
|
||||
10
|
||||
);
|
||||
return version <= 60;
|
||||
}
|
||||
|
||||
const msie = ua.indexOf("MSIE ");
|
||||
if (msie > 0) {
|
||||
// IE 10 or older => return version number
|
||||
return true;
|
||||
}
|
||||
|
||||
const trident = ua.indexOf("Trident/");
|
||||
if (trident > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const edge = ua.indexOf("Edge/");
|
||||
if (edge > 0) {
|
||||
// Edge (IE 12+) => return version number
|
||||
return true;
|
||||
}
|
||||
|
||||
// other browser
|
||||
return false;
|
||||
}
|
||||
@@ -55,7 +55,8 @@ export async function makeRequest<T>(
|
||||
);
|
||||
retryCount = 0;
|
||||
|
||||
return retryResponse;
|
||||
etag = retryResponse.etag;
|
||||
return retryResponse.result;
|
||||
} else {
|
||||
retryCount = 0;
|
||||
|
||||
@@ -89,7 +90,8 @@ export async function makeRequest<T>(
|
||||
);
|
||||
retryCount = 0;
|
||||
|
||||
return retryResponse;
|
||||
etag = retryResponse.etag;
|
||||
return retryResponse.result;
|
||||
} else {
|
||||
retryCount = 0;
|
||||
|
||||
|
||||
16
src/utils/parseWeboutResponse.ts
Normal file
16
src/utils/parseWeboutResponse.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export const parseWeboutResponse = (response: string) => {
|
||||
let sasResponse = "";
|
||||
|
||||
if (response.includes(">>weboutBEGIN<<")) {
|
||||
try {
|
||||
sasResponse = response
|
||||
.split(">>weboutBEGIN<<")[1]
|
||||
.split(">>weboutEND<<")[0];
|
||||
} catch (e) {
|
||||
sasResponse = "";
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
return sasResponse;
|
||||
}
|
||||
Reference in New Issue
Block a user