n8n-nodes-soaprequest
Version:
n8n node for soap requests
91 lines • 3.74 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SoapRequest = void 0;
const Soap_operations_1 = require("./Soap.operations");
const Authentication_utils_1 = require("./Authentication.utils");
const SoapMessage_1 = require("./SoapMessage");
const xpath_1 = __importDefault(require("xpath"));
const xml2js_1 = require("xml2js");
const xmldom_1 = require("@xmldom/xmldom");
const Authentication_operations_1 = require("./Authentication.operations");
class SoapRequest {
constructor() {
this.description = {
credentials: [
{
name: 'soapApi',
required: false,
displayName: 'SOAP API',
displayOptions: {
show: {
authentication: [Authentication_operations_1.SOAP_API_CREDENTIALS_TYPE],
},
},
},
],
description: 'SOAP Request',
displayName: 'SOAP Request',
defaults: {
name: 'SOAP Request',
},
group: ['transform'],
inputs: ['main'],
name: 'soapRequest',
icon: 'file:soaprequest.svg',
outputs: ['main'],
properties: [
...Authentication_operations_1.authenticationOperations,
...Soap_operations_1.soapOperations,
],
version: 1,
};
}
async execute() {
const method = this.getNodeParameter(Soap_operations_1.METHOD, 0, '');
const url = this.getNodeParameter(Soap_operations_1.URL, 0, '');
const sendHeaders = this.getNodeParameter(Soap_operations_1.SEND_HEADERS, 0, false);
const soapBody = await (0, Authentication_utils_1.interpolateSOAPBodyCredentials)(this, 0);
const soapHeader = sendHeaders ? await (0, Authentication_utils_1.interpolateSOAPHeaderCredentials)(this, 0) : undefined;
const soapMessage = new SoapMessage_1.SOAPMessageBuilder()
.addHeader(soapHeader)
.setBody(soapBody)
.build()
.toString();
const convertToJson = this.getNodeParameter(Soap_operations_1.CONVERT_TO_JSON, 0, false);
const options = {
headers: {
'Content-Type': 'application/soap+xml',
'Accept': 'application/soap+xml',
},
method: method,
uri: url,
body: soapMessage,
json: false,
resolveWithFullResponse: true,
};
const response = await this.helpers.request.call(this, options);
const doc = new xmldom_1.DOMParser().parseFromString(response['body'], 'text/xml');
const select = xpath_1.default.useNamespaces({ "soap": "http://www.w3.org/2003/05/soap-envelope" });
const responseBody = select("//soap:Body/*", doc).toString();
let resultData = responseBody;
if (convertToJson) {
(0, xml2js_1.parseString)(responseBody, {
explicitArray: false,
ignoreAttrs: true,
}, (error, result) => {
resultData = result;
});
}
return [this.helpers.returnJsonArray([{
data: resultData,
headers: response.headers,
statusCode: response.statusCode,
statusMessage: response.statusMessage
}])];
}
}
exports.SoapRequest = SoapRequest;
//# sourceMappingURL=SoapRequest.node.js.map