UNPKG

cargowise-eadapter

Version:
30 lines (29 loc) 1.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setupSoap = void 0; const node_fetch_1 = require("node-fetch"); const soap = require("soap"); const urllib = require("url"); /** * Setup a soap client that is compatible with CW1 eAdapter service. * * @param config eAdapter config * @returns soap client and WSDL object */ async function setupSoap(config) { const url = new urllib.URL(config.wsdlUrl); if (typeof config.wsdlXml !== "string") { const res = await node_fetch_1.default(config.wsdlUrl); config.wsdlXml = await res.text(); } const wsdlXml = config.wsdlXml.replace(/Server:SOAPWebServicePort/gi, url.hostname); const wsdl = new soap.WSDL(wsdlXml, config.wsdlUrl, {}); await new Promise((resolve, reject) => wsdl.onReady((err) => (err ? reject(err) : resolve(undefined)))); const client = new soap.Client(wsdl); client.setSecurity(new soap.WSSecurity(config.username, config.password)); return { wsdl, client, }; } exports.setupSoap = setupSoap;