mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-04 03:00:05 +00:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ed64e5a2c | ||
|
|
0479a5d651 | ||
|
|
005f10bb47 | ||
|
|
8192f69f67 | ||
|
|
a409d8cdb6 | ||
|
|
618a20eaba | ||
|
|
c9b1273c31 | ||
|
|
59674744be | ||
|
|
870cc0055b | ||
|
|
0ffa62fab4 | ||
|
|
b4c7868fb6 | ||
|
|
2266578013 | ||
|
|
f2ebe1a5b0 | ||
|
|
6a52bbe560 | ||
|
|
a5c725e677 | ||
|
|
f5e1907e28 |
@@ -70,6 +70,14 @@ parmcards4;
|
|||||||
%webout(CLOSE)
|
%webout(CLOSE)
|
||||||
;;;;
|
;;;;
|
||||||
%mp_createwebservice(path=/Public/app/common,name=sendArr)
|
%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`.
|
The above services will return anything you send. To run the tests simply launch `npm run cypress`.
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ export class FileUploader {
|
|||||||
private appLoc: string,
|
private appLoc: string,
|
||||||
private serverUrl: string,
|
private serverUrl: string,
|
||||||
private jobsPath: string,
|
private jobsPath: string,
|
||||||
private csrfToken: CsrfToken | null = null
|
private setCsrfTokenWeb: any,
|
||||||
|
private csrfToken: CsrfToken | null = null,
|
||||||
) {}
|
) {}
|
||||||
private retryCount = 0;
|
private retryCount = 0;
|
||||||
|
|
||||||
@@ -61,6 +62,8 @@ export class FileUploader {
|
|||||||
headerName: tokenHeader,
|
headerName: tokenHeader,
|
||||||
value: token || "",
|
value: token || "",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.setCsrfTokenWeb(this.csrfToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -208,12 +208,15 @@ export class SASViyaApiClient {
|
|||||||
debug = false
|
debug = false
|
||||||
) {
|
) {
|
||||||
silent = !debug;
|
silent = !debug;
|
||||||
|
|
||||||
const headers: any = {
|
const headers: any = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
};
|
};
|
||||||
|
|
||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
headers.Authorization = `Bearer ${accessToken}`;
|
headers.Authorization = `Bearer ${accessToken}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
let executionSessionId: string;
|
let executionSessionId: string;
|
||||||
const session = await this.sessionManager.getSession(accessToken);
|
const session = await this.sessionManager.getSession(accessToken);
|
||||||
executionSessionId = session!.id;
|
executionSessionId = session!.id;
|
||||||
@@ -241,7 +244,9 @@ export class SASViyaApiClient {
|
|||||||
SYS_JES_JOB_URI: "",
|
SYS_JES_JOB_URI: "",
|
||||||
_program: this.rootFolderName + "/" + jobName,
|
_program: this.rootFolderName + "/" + jobName,
|
||||||
};
|
};
|
||||||
|
|
||||||
let files: any[] = [];
|
let files: any[] = [];
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
if (JSON.stringify(data).includes(";")) {
|
if (JSON.stringify(data).includes(";")) {
|
||||||
files = await this.uploadTables(data, accessToken);
|
files = await this.uploadTables(data, accessToken);
|
||||||
@@ -269,10 +274,12 @@ export class SASViyaApiClient {
|
|||||||
arguments: jobArguments,
|
arguments: jobArguments,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
const { result: postedJob, etag } = await this.request<Job>(
|
const { result: postedJob, etag } = await this.request<Job>(
|
||||||
`${this.serverUrl}/compute/sessions/${executionSessionId}/jobs`,
|
`${this.serverUrl}/compute/sessions/${executionSessionId}/jobs`,
|
||||||
postJobRequest
|
postJobRequest
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!silent) {
|
if (!silent) {
|
||||||
console.log(`Job has been submitted for ${fileName}`);
|
console.log(`Job has been submitted for ${fileName}`);
|
||||||
console.log(
|
console.log(
|
||||||
@@ -288,17 +295,20 @@ export class SASViyaApiClient {
|
|||||||
accessToken,
|
accessToken,
|
||||||
silent
|
silent
|
||||||
);
|
);
|
||||||
|
|
||||||
const { result: currentJob } = await this.request<Job>(
|
const { result: currentJob } = await this.request<Job>(
|
||||||
`${this.serverUrl}/compute/sessions/${executionSessionId}/jobs/${postedJob.id}`,
|
`${this.serverUrl}/compute/sessions/${executionSessionId}/jobs/${postedJob.id}`,
|
||||||
{ headers }
|
{ headers }
|
||||||
);
|
);
|
||||||
|
|
||||||
let jobResult, log;
|
let jobResult, log;
|
||||||
|
|
||||||
if (jobStatus === "failed" || jobStatus === "error") {
|
if (jobStatus === "failed" || jobStatus === "error") {
|
||||||
return Promise.reject(currentJob.error);
|
return Promise.reject(currentJob.error);
|
||||||
}
|
}
|
||||||
const resultLink = `/compute/sessions/${executionSessionId}/filerefs/_webout/content`;
|
const resultLink = `/compute/sessions/${executionSessionId}/filerefs/_webout/content`;
|
||||||
const logLink = currentJob.links.find((l) => l.rel === "log");
|
const logLink = currentJob.links.find((l) => l.rel === "log");
|
||||||
|
|
||||||
if (resultLink) {
|
if (resultLink) {
|
||||||
jobResult = await this.request<any>(
|
jobResult = await this.request<any>(
|
||||||
`${this.serverUrl}${resultLink}`,
|
`${this.serverUrl}${resultLink}`,
|
||||||
@@ -708,11 +718,12 @@ export class SASViyaApiClient {
|
|||||||
`The job ${sasJob} was not found in ${this.rootFolderName}`
|
`The job ${sasJob} was not found in ${this.rootFolderName}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let files: any[] = [];
|
let files: any[] = [];
|
||||||
if (data && Object.keys(data).length) {
|
if (data && Object.keys(data).length) {
|
||||||
files = await this.uploadTables(data, accessToken);
|
files = await this.uploadTables(data, accessToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
const jobName = path.basename(sasJob);
|
const jobName = path.basename(sasJob);
|
||||||
const jobFolder = sasJob.replace(`/${jobName}`, "");
|
const jobFolder = sasJob.replace(`/${jobName}`, "");
|
||||||
const allJobsInFolder = this.rootFolderMap.get(jobFolder.replace("/", ""));
|
const allJobsInFolder = this.rootFolderMap.get(jobFolder.replace("/", ""));
|
||||||
@@ -1007,12 +1018,12 @@ export class SASViyaApiClient {
|
|||||||
headers,
|
headers,
|
||||||
};
|
};
|
||||||
|
|
||||||
const { result: file } = await this.request<any>(
|
const uploadResponse = await this.request<any>(
|
||||||
`${this.serverUrl}/files/files#rawUpload`,
|
`${this.serverUrl}/files/files#rawUpload`,
|
||||||
createFileRequest
|
createFileRequest
|
||||||
);
|
);
|
||||||
|
|
||||||
uploadedFiles.push({ tableName, file });
|
uploadedFiles.push({ tableName, file: uploadResponse.result });
|
||||||
}
|
}
|
||||||
return uploadedFiles;
|
return uploadedFiles;
|
||||||
}
|
}
|
||||||
|
|||||||
74
src/SASjs.ts
74
src/SASjs.ts
@@ -1,6 +1,13 @@
|
|||||||
import "isomorphic-fetch";
|
import { isIEorEdgeOrOldFirefox } from "./utils/isIeOrEdge";
|
||||||
import * as e6p from "es6-promise";
|
import * as e6p from "es6-promise";
|
||||||
(e6p as any).polyfill();
|
(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 {
|
import {
|
||||||
convertToCSV,
|
convertToCSV,
|
||||||
compareTimestamps,
|
compareTimestamps,
|
||||||
@@ -12,6 +19,7 @@ import {
|
|||||||
isLogInSuccess,
|
isLogInSuccess,
|
||||||
parseSourceCode,
|
parseSourceCode,
|
||||||
parseGeneratedCode,
|
parseGeneratedCode,
|
||||||
|
parseWeboutResponse,
|
||||||
needsRetry,
|
needsRetry,
|
||||||
asyncForEach,
|
asyncForEach,
|
||||||
} from "./utils";
|
} from "./utils";
|
||||||
@@ -391,8 +399,10 @@ export default class SASjs {
|
|||||||
this.sasjsConfig.appLoc,
|
this.sasjsConfig.appLoc,
|
||||||
this.sasjsConfig.serverUrl,
|
this.sasjsConfig.serverUrl,
|
||||||
this.jobsPath,
|
this.jobsPath,
|
||||||
|
this.setCsrfTokenWeb,
|
||||||
this.csrfTokenWeb
|
this.csrfTokenWeb
|
||||||
);
|
);
|
||||||
|
|
||||||
return fileUploader.uploadFile(sasJob, files, params);
|
return fileUploader.uploadFile(sasJob, files, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -559,7 +569,15 @@ export default class SASjs {
|
|||||||
this.appendSasjsRequest(response, sasJob, null);
|
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) => {
|
.catch(async (e) => {
|
||||||
if (needsRetry(JSON.stringify(e))) {
|
if (needsRetry(JSON.stringify(e))) {
|
||||||
@@ -639,7 +657,18 @@ export default class SASjs {
|
|||||||
} else {
|
} else {
|
||||||
this.appendSasjsRequest(response, sasJob, null);
|
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) => {
|
.catch(async (e) => {
|
||||||
if (needsRetry(JSON.stringify(e))) {
|
if (needsRetry(JSON.stringify(e))) {
|
||||||
@@ -834,7 +863,7 @@ export default class SASjs {
|
|||||||
} else {
|
} else {
|
||||||
if (config.serverType === ServerType.SAS9 && config.debug) {
|
if (config.serverType === ServerType.SAS9 && config.debug) {
|
||||||
this.updateUsername(responseText);
|
this.updateUsername(responseText);
|
||||||
const jsonResponseText = this.parseSAS9Response(responseText);
|
const jsonResponseText = parseWeboutResponse(responseText);
|
||||||
|
|
||||||
if (jsonResponseText !== "") {
|
if (jsonResponseText !== "") {
|
||||||
resolve(JSON.parse(jsonResponseText));
|
resolve(JSON.parse(jsonResponseText));
|
||||||
@@ -884,6 +913,10 @@ export default class SASjs {
|
|||||||
|
|
||||||
return sasjsWaitingRequest.requestPromise.promise;
|
return sasjsWaitingRequest.requestPromise.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private setCsrfTokenWeb = (csrfToken: CsrfToken) => {
|
||||||
|
this.csrfTokenWeb = csrfToken;
|
||||||
|
};
|
||||||
|
|
||||||
private setCsrfTokenApi = (csrfToken: CsrfToken) => {
|
private setCsrfTokenApi = (csrfToken: CsrfToken) => {
|
||||||
this.csrfTokenApi = csrfToken;
|
this.csrfTokenApi = csrfToken;
|
||||||
@@ -975,23 +1008,6 @@ export default class SASjs {
|
|||||||
return uri;
|
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) {
|
private parseSAS9ErrorResponse(response: string) {
|
||||||
const logLines = response.split("\n");
|
const logLines = response.split("\n");
|
||||||
const parsedLines: string[] = [];
|
const parsedLines: string[] = [];
|
||||||
@@ -1049,7 +1065,12 @@ export default class SASjs {
|
|||||||
if (response && response.result && response.log) {
|
if (response && response.result && response.log) {
|
||||||
sourceCode = parseSourceCode(response.log);
|
sourceCode = parseSourceCode(response.log);
|
||||||
generatedCode = parseGeneratedCode(response.log);
|
generatedCode = parseGeneratedCode(response.log);
|
||||||
sasWork = JSON.parse(response.result).WORK;
|
|
||||||
|
if (this.sasjsConfig.debug) {
|
||||||
|
sasWork = JSON.parse(parseWeboutResponse(response.result)).WORK;
|
||||||
|
} else {
|
||||||
|
sasWork = JSON.parse(response.result).WORK;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (response) {
|
if (response) {
|
||||||
sourceCode = parseSourceCode(response);
|
sourceCode = parseSourceCode(response);
|
||||||
@@ -1078,7 +1099,7 @@ export default class SASjs {
|
|||||||
|
|
||||||
if (this.sasjsConfig.serverType === ServerType.SAS9) {
|
if (this.sasjsConfig.serverType === ServerType.SAS9) {
|
||||||
try {
|
try {
|
||||||
jsonResponse = JSON.parse(this.parseSAS9Response(response));
|
jsonResponse = JSON.parse(parseWeboutResponse(response));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
@@ -1109,6 +1130,10 @@ export default class SASjs {
|
|||||||
return sortedRequests;
|
return sortedRequests;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public clearSasRequests() {
|
||||||
|
this.sasjsRequests = [];
|
||||||
|
}
|
||||||
|
|
||||||
private setupConfiguration() {
|
private setupConfiguration() {
|
||||||
if (
|
if (
|
||||||
this.sasjsConfig.serverUrl === undefined ||
|
this.sasjsConfig.serverUrl === undefined ||
|
||||||
@@ -1158,7 +1183,8 @@ export default class SASjs {
|
|||||||
this.fileUploader = new FileUploader(
|
this.fileUploader = new FileUploader(
|
||||||
this.sasjsConfig.appLoc,
|
this.sasjsConfig.appLoc,
|
||||||
this.sasjsConfig.serverUrl,
|
this.sasjsConfig.serverUrl,
|
||||||
this.jobsPath
|
this.jobsPath,
|
||||||
|
this.setCsrfTokenWeb
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,3 +12,4 @@ export * from "./parseSourceCode";
|
|||||||
export * from "./parseSasViyaLog";
|
export * from "./parseSasViyaLog";
|
||||||
export * from "./serialize";
|
export * from "./serialize";
|
||||||
export * from "./splitChunks";
|
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;
|
retryCount = 0;
|
||||||
|
|
||||||
return retryResponse;
|
etag = retryResponse.etag;
|
||||||
|
return retryResponse.result;
|
||||||
} else {
|
} else {
|
||||||
retryCount = 0;
|
retryCount = 0;
|
||||||
|
|
||||||
@@ -89,7 +90,8 @@ export async function makeRequest<T>(
|
|||||||
);
|
);
|
||||||
retryCount = 0;
|
retryCount = 0;
|
||||||
|
|
||||||
return retryResponse;
|
etag = retryResponse.etag;
|
||||||
|
return retryResponse.result;
|
||||||
} else {
|
} else {
|
||||||
retryCount = 0;
|
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