1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-14 23:50:06 +00:00

Compare commits

...

7 Commits

Author SHA1 Message Date
Allan Bowe
f27444bc52 Merge pull request #48 from sasjs/issue47
fix: login not working on non english browsers
2020-08-23 18:24:36 +02:00
Mihajlo Medjedovic
de426c9a92 fix: login not working on non english browsers 2020-08-23 18:17:35 +02:00
Allan Bowe
a006ead205 Merge pull request #46 from sasjs/issue45
fix: jobViaWeb config override
2020-08-23 17:07:47 +02:00
Mihajlo Medjedovic
422c2a1fd5 fix: jobViaWeb config override 2020-08-23 17:04:39 +02:00
Krishna Acondy
0c6409e402 Merge pull request #44 from sasjs/session-expiry-retry
fix(session-expiry-retry): retry job with new session on expiry
2020-08-18 21:45:47 +01:00
Krishna Acondy
68b864cf75 fix(session-expiry): discard and create new session if expired 2020-08-18 21:35:02 +01:00
Krishna Acondy
75a11cdff4 fix(session-expiry-retry): retry job with new session when current session has expired 2020-08-18 20:23:59 +01:00
4 changed files with 151 additions and 126 deletions

View File

@@ -206,9 +206,9 @@ export class SASViyaApiClient {
silent = false, silent = false,
data = null, data = null,
debug = false debug = false
) { ): Promise<any> {
silent = !debug; silent = !debug;
try {
const headers: any = { const headers: any = {
"Content-Type": "application/json", "Content-Type": "application/json",
}; };
@@ -311,7 +311,9 @@ export class SASViyaApiClient {
{ {
headers, headers,
} }
).then((res: any) => res.result.items.map((i: any) => i.line).join("\n")); ).then((res: any) =>
res.result.items.map((i: any) => i.line).join("\n")
);
} }
if (jobStatus === "failed" || jobStatus === "error") { if (jobStatus === "failed" || jobStatus === "error") {
@@ -332,12 +334,21 @@ export class SASViyaApiClient {
await this.sessionManager.clearSession(executionSessionId, accessToken); await this.sessionManager.clearSession(executionSessionId, accessToken);
return { result: jobResult?.result, log }; return { result: jobResult?.result, log };
// } else { } catch (e) {
// console.error( if (e && e.status === 404) {
// `Unable to find execution context ${contextName}.\nPlease check the contextName in the tgtDeployVars and try again.` return this.executeScript(
// ); jobName,
// console.error("Response from server: ", JSON.stringify(this.contexts)); linesOfCode,
// } contextName,
accessToken,
silent,
data,
debug
);
} else {
throw e;
}
}
} }
/** /**

View File

@@ -291,7 +291,7 @@ export default class SASjs {
public async checkSession() { public async checkSession() {
const loginResponse = await fetch(this.loginUrl.replace(".do", "")); const loginResponse = await fetch(this.loginUrl.replace(".do", ""));
const responseText = await loginResponse.text(); const responseText = await loginResponse.text();
const isLoggedIn = /You have signed in./gm.test(responseText); const isLoggedIn = /<button.+onClick.+logout/gm.test(responseText);
return Promise.resolve({ return Promise.resolve({
isLoggedIn, isLoggedIn,
@@ -730,7 +730,7 @@ export default class SASjs {
}`; }`;
const requestParams = { const requestParams = {
...this.getRequestParamsWeb(), ...this.getRequestParamsWeb(config),
}; };
const formData = new FormData(); const formData = new FormData();
@@ -941,14 +941,14 @@ export default class SASjs {
this.sasjsWaitingRequests = []; this.sasjsWaitingRequests = [];
} }
private getRequestParamsWeb(): any { private getRequestParamsWeb(config: any): any {
const requestParams: any = {}; const requestParams: any = {};
if (this.csrfTokenWeb) { if (this.csrfTokenWeb) {
requestParams["_csrf"] = this.csrfTokenWeb.value; requestParams["_csrf"] = this.csrfTokenWeb.value;
} }
if (this.sasjsConfig.debug) { if (config.debug) {
requestParams["_omittextlog"] = "false"; requestParams["_omittextlog"] = "false";
requestParams["_omitsessionresults"] = "false"; requestParams["_omitsessionresults"] = "false";

View File

@@ -17,6 +17,16 @@ export class SessionManager {
await this.createSessions(accessToken); await this.createSessions(accessToken);
this.createAndWaitForSession(accessToken); this.createAndWaitForSession(accessToken);
const session = this.sessions.pop(); 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; return session;
} }

View File

@@ -4,4 +4,8 @@ export interface Session {
id: string; id: string;
state: string; state: string;
links: Link[]; links: Link[];
attributes: {
sessionInactiveTimeout: number;
};
creationTimeStamp: string;
} }