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

fix: local config

This commit is contained in:
Mihajlo Medjedovic
2020-07-19 17:44:29 +02:00
parent c7d6c66093
commit 405a19f0cf

View File

@@ -42,7 +42,6 @@ const requestRetryLimit = 5;
* *
*/ */
export default class SASjs { export default class SASjs {
private globalSasjsConfig: SASjsConfig = new SASjsConfig();
private sasjsConfig: SASjsConfig = new SASjsConfig(); private sasjsConfig: SASjsConfig = new SASjsConfig();
private jobsPath: string = ""; private jobsPath: string = "";
private logoutUrl: string = ""; private logoutUrl: string = "";
@@ -63,7 +62,6 @@ export default class SASjs {
}; };
this.setupConfiguration(); this.setupConfiguration();
this.globalSasjsConfig = { ...this.sasjsConfig };
} }
public async executeScriptSAS9( public async executeScriptSAS9(
@@ -385,29 +383,28 @@ export default class SASjs {
public async request( public async request(
sasJob: string, sasJob: string,
data: any, data: any,
config?: SASjsConfig, config: any = {},
loginRequiredCallback?: any, loginRequiredCallback?: any,
accessToken?: string accessToken?: string
) { ) {
let requestResponse; let requestResponse;
if (config) { config = {
this.sasjsConfig = { ...this.sasjsConfig,
...this.globalSasjsConfig, ...config
...config
};
} }
sasJob = sasJob.startsWith("/") ? sasJob.replace("/", "") : sasJob; sasJob = sasJob.startsWith("/") ? sasJob.replace("/", "") : sasJob;
if ( if (
this.sasjsConfig.serverType === ServerType.SASViya && config.serverType === ServerType.SASViya &&
this.sasjsConfig.contextName config.contextName
) { ) {
if (this.sasjsConfig.useComputeApi) { if (config.useComputeApi) {
requestResponse = await this.executeJobViaComputeApi( requestResponse = await this.executeJobViaComputeApi(
sasJob, sasJob,
data, data,
config,
loginRequiredCallback, loginRequiredCallback,
accessToken accessToken
); );
@@ -415,6 +412,7 @@ export default class SASjs {
requestResponse = await this.executeJobViaJesApi( requestResponse = await this.executeJobViaJesApi(
sasJob, sasJob,
data, data,
config,
loginRequiredCallback, loginRequiredCallback,
accessToken accessToken
); );
@@ -423,12 +421,11 @@ export default class SASjs {
requestResponse = await this.executeJobViaWeb( requestResponse = await this.executeJobViaWeb(
sasJob, sasJob,
data, data,
config,
loginRequiredCallback loginRequiredCallback
); );
} }
this.sasjsConfig = this.globalSasjsConfig;
return requestResponse; return requestResponse;
} }
@@ -495,6 +492,7 @@ export default class SASjs {
private async executeJobViaComputeApi( private async executeJobViaComputeApi(
sasJob: string, sasJob: string,
data: any, data: any,
config: any,
loginRequiredCallback?: any, loginRequiredCallback?: any,
accessToken?: string accessToken?: string
) { ) {
@@ -514,13 +512,13 @@ export default class SASjs {
await this.sasViyaApiClient await this.sasViyaApiClient
?.executeComputeJob( ?.executeComputeJob(
sasJob, sasJob,
this.sasjsConfig.contextName, config.contextName,
this.sasjsConfig.debug, config.debug,
data, data,
accessToken accessToken
) )
.then((response) => { .then((response) => {
if (!this.sasjsConfig.debug) { if (!config.debug) {
this.appendSasjsRequest(null, sasJob, null); this.appendSasjsRequest(null, sasJob, null);
} else { } else {
this.appendSasjsRequest(response, sasJob, null); this.appendSasjsRequest(response, sasJob, null);
@@ -546,6 +544,7 @@ export default class SASjs {
private async executeJobViaJesApi( private async executeJobViaJesApi(
sasJob: string, sasJob: string,
data: any, data: any,
config: any,
loginRequiredCallback?: any, loginRequiredCallback?: any,
accessToken?: string accessToken?: string
) { ) {
@@ -573,13 +572,13 @@ export default class SASjs {
await this.sasViyaApiClient await this.sasViyaApiClient
?.executeJob( ?.executeJob(
sasJob, sasJob,
this.sasjsConfig.contextName, config.contextName,
this.sasjsConfig.debug, config.debug,
data, data,
accessToken accessToken
) )
.then((response) => { .then((response) => {
if (!this.sasjsConfig.debug) { if (!config.debug) {
this.appendSasjsRequest(null, sasJob, null); this.appendSasjsRequest(null, sasJob, null);
} else { } else {
this.appendSasjsRequest(response, sasJob, null); this.appendSasjsRequest(response, sasJob, null);
@@ -599,6 +598,7 @@ export default class SASjs {
private async executeJobViaWeb( private async executeJobViaWeb(
sasJob: string, sasJob: string,
data: any, data: any,
config: any,
loginRequiredCallback?: any loginRequiredCallback?: any
) { ) {
const sasjsWaitingRequest: SASjsWaitingRequest = { const sasjsWaitingRequest: SASjsWaitingRequest = {
@@ -610,14 +610,14 @@ export default class SASjs {
SASjob: sasJob, SASjob: sasJob,
data data
}; };
const program = this.sasjsConfig.appLoc const program = config.appLoc
? this.sasjsConfig.appLoc.replace(/\/?$/, "/") + sasJob.replace(/^\//, "") ? config.appLoc.replace(/\/?$/, "/") + sasJob.replace(/^\//, "")
: sasJob; : sasJob;
const jobUri = const jobUri =
this.sasjsConfig.serverType === "SASVIYA" config.serverType === "SASVIYA"
? await this.getJobUri(sasJob) ? await this.getJobUri(sasJob)
: ""; : "";
const apiUrl = `${this.sasjsConfig.serverUrl}${this.jobsPath}/?${ const apiUrl = `${config.serverUrl}${this.jobsPath}/?${
jobUri.length > 0 jobUri.length > 0
? "__program=" + program + "&_job=" + jobUri ? "__program=" + program + "&_job=" + jobUri
: "_program=" + program : "_program=" + program
@@ -635,7 +635,7 @@ export default class SASjs {
if (data) { if (data) {
const stringifiedData = JSON.stringify(data); const stringifiedData = JSON.stringify(data);
if ( if (
this.sasjsConfig.serverType === ServerType.SAS9 || config.serverType === ServerType.SAS9 ||
stringifiedData.length > 500000 || stringifiedData.length > 500000 ||
stringifiedData.includes(";") stringifiedData.includes(";")
) { ) {
@@ -727,7 +727,7 @@ export default class SASjs {
if ( if (
response.redirected && response.redirected &&
this.sasjsConfig.serverType === ServerType.SAS9 config.serverType === ServerType.SAS9
) { ) {
isRedirected = true; isRedirected = true;
} }
@@ -760,8 +760,8 @@ export default class SASjs {
this.sasjsWaitingRequests.push(sasjsWaitingRequest); this.sasjsWaitingRequests.push(sasjsWaitingRequest);
} else { } else {
if ( if (
this.sasjsConfig.serverType === ServerType.SAS9 && config.serverType === ServerType.SAS9 &&
this.sasjsConfig.debug config.debug
) { ) {
this.updateUsername(responseText); this.updateUsername(responseText);
const jsonResponseText = this.parseSAS9Response(responseText); const jsonResponseText = this.parseSAS9Response(responseText);
@@ -774,8 +774,8 @@ export default class SASjs {
}); });
} }
} else if ( } else if (
this.sasjsConfig.serverType === ServerType.SASViya && config.serverType === ServerType.SASViya &&
this.sasjsConfig.debug config.debug
) { ) {
try { try {
this.parseSASVIYADebugResponse(responseText).then( this.parseSASVIYADebugResponse(responseText).then(