Skip to content

Commit

Permalink
feat: update to wsdl-next 1.0.7, add requestAgent for scale request p…
Browse files Browse the repository at this point in the history
…erformance
  • Loading branch information
pont1s committed Apr 30, 2022
1 parent 7b37f99 commit 3b4b6dd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "soap-next",
"version": "1.1.1",
"version": "1.1.2",
"description": "Simple soap client",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -34,7 +34,7 @@
},
"dependencies": {
"axios": "^0.27.2",
"wsdl-next": "^1.0.5"
"wsdl-next": "^1.0.7"
},
"keywords": [
"SOAP",
Expand Down
30 changes: 22 additions & 8 deletions src/SoapRequest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import axios, { AxiosRequestHeaders } from 'axios';
import axios, { AxiosRequestHeaders, AxiosRequestConfig } from 'axios';
import { WsdlNext } from 'wsdl-next';
import { Agent } from 'http';
import { Agent as AgentHttps } from 'https';
import {
SoapBodyAttributes, SoapBodyParams, SoapParams,
} from './SoapTypes';
Expand All @@ -11,6 +13,8 @@ export default class SoapRequest {

private wsdl: WsdlNext;

private readonly requestAgent: Agent | AgentHttps;

constructor(url: string, params: SoapParams, wsdl: WsdlNext) {
this.url = url;
this.clientParams = params;
Expand All @@ -22,6 +26,7 @@ export default class SoapRequest {
};
}
this.wsdl = wsdl;
this.requestAgent = wsdl.requestAgent;
}

async getRequestHeadParams() {
Expand Down Expand Up @@ -164,21 +169,30 @@ export default class SoapRequest {
}

async request(body: string) {
const url = this.url.split('?')[0];
const result = await axios({
url,
const urlWithoutParams = this.url.split('?')[0];

const axiosConfig: AxiosRequestConfig = {
url: urlWithoutParams,
method: 'POST',
headers: this.clientParams.httpHeaders as AxiosRequestHeaders,
responseType: 'text',
data: body,
});
};

return result;
if (this.requestAgent instanceof Agent) {
axiosConfig.httpAgent = this.requestAgent;
} else {
axiosConfig.httpsAgent = this.requestAgent;
}

const result = await axios(axiosConfig);

return result.data as string;
}

async call(method: string, bodyParams: SoapBodyParams, attributes: SoapBodyAttributes) {
const requestXml = await this.getRequestXml(method, bodyParams, attributes);
const result = await this.request(requestXml);

return result.data;
return result;
}
}

0 comments on commit 3b4b6dd

Please sign in to comment.