@dgac/nmb2b-client
Version:
EUROCONTROL Network Manager B2B SOAP client
42 lines (40 loc) • 1.61 kB
JavaScript
import { timeFormatWithSeconds } from "../timeFormats.mjs";
import { B2B_VERSION } from "../../constants.mjs";
import { getFileUrl, getSoapEndpoint } from "../../config.mjs";
import { createAxiosConfig } from "./createAxiosConfig.mjs";
import { UTCDateMini } from "@date-fns/utc";
import { format } from "date-fns";
import axios from "axios";
//#region src/utils/xsd/getWSDLDownloadURL.ts
const makeQuery = ({ version }) => `
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:generalinformation="eurocontrol/cfmu/b2b/GeneralinformationServices"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
<soap:Header />
<soap:Body>
<generalinformation:NMB2BWSDLsRequest>
<sendTime>${format(new UTCDateMini(), timeFormatWithSeconds)}</sendTime>
<version>${version}</version>
</generalinformation:NMB2BWSDLsRequest>
</soap:Body>
</soap:Envelope>
`;
async function getWSDLDownloadURL({ flavour, security, xsdEndpoint }) {
if (xsdEndpoint) return xsdEndpoint;
if (!!security && "apiKeyId" in security) throw new Error("Should never happen, config.xsdEndpoint should be defined");
const res = await axios({
url: getSoapEndpoint({ flavour }),
method: "POST",
data: makeQuery({ version: B2B_VERSION }),
responseType: "text",
...createAxiosConfig({ security })
});
const matches = /<id>(.+)<\/id>/.exec(res.data);
if (!matches?.[1]) throw new Error(`Could not extract WSDL tarball file from B2B response`);
return getFileUrl(matches[1], { flavour });
}
//#endregion
export { getWSDLDownloadURL };
//# sourceMappingURL=getWSDLDownloadURL.mjs.map