UNPKG

@dgac/nmb2b-client

Version:

EUROCONTROL Network Manager B2B SOAP client

42 lines (40 loc) 1.53 kB
import { B2B_VERSION } from "../../constants.js"; import { getEndpoint } from "../../config.js"; import { createAxiosConfig } from "./createAxiosConfig.js"; import { timeFormatWithSeconds } from "../timeFormats.js"; import axios from "axios"; import { UTCDateMini } from "@date-fns/utc"; import { format } from "date-fns"; //#region src/utils/xsd/filePath.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 requestFilename({ 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: getEndpoint({ 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 matches[1]; } //#endregion export { requestFilename }; //# sourceMappingURL=filePath.js.map