UNPKG

@dgac/nmb2b-client

Version:

EUROCONTROL Network Manager B2B SOAP client

1 lines 2.57 kB
{"version":3,"file":"getWSDLDownloadURL.mjs","names":[],"sources":["../../../src/utils/xsd/getWSDLDownloadURL.ts"],"sourcesContent":["import { UTCDateMini } from '@date-fns/utc';\nimport axios from 'axios';\nimport { format } from 'date-fns';\nimport { getFileUrl, getSoapEndpoint } from '../../config.js';\nimport type { B2BFlavour } from '../../constants.js';\nimport { B2B_VERSION } from '../../constants.js';\nimport type { Security } from '../../security.js';\nimport { timeFormatWithSeconds } from '../timeFormats.js';\nimport { createAxiosConfig } from './createAxiosConfig.js';\n\nconst makeQuery = ({ version }: { version: string }) => `\n<soap:Envelope\n xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"\n xmlns:generalinformation=\"eurocontrol/cfmu/b2b/GeneralinformationServices\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n>\n <soap:Header />\n <soap:Body>\n <generalinformation:NMB2BWSDLsRequest>\n <sendTime>${format(new UTCDateMini(), timeFormatWithSeconds)}</sendTime>\n <version>${version}</version>\n </generalinformation:NMB2BWSDLsRequest>\n </soap:Body>\n</soap:Envelope>\n`;\n\nexport async function getWSDLDownloadURL({\n flavour,\n security,\n xsdEndpoint,\n}: {\n flavour: B2BFlavour;\n security: Security;\n xsdEndpoint?: string;\n}): Promise<string> {\n if (xsdEndpoint) {\n return xsdEndpoint;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!!security && 'apiKeyId' in security) {\n throw new Error(\n 'Should never happen, config.xsdEndpoint should be defined',\n );\n }\n\n const res = await axios<string>({\n url: getSoapEndpoint({ flavour }),\n method: 'POST',\n data: makeQuery({ version: B2B_VERSION }),\n responseType: 'text',\n ...createAxiosConfig({ security }),\n });\n\n const matches = /<id>(.+)<\\/id>/.exec(res.data);\n\n if (!matches?.[1]) {\n throw new Error(`Could not extract WSDL tarball file from B2B response`);\n }\n\n return getFileUrl(matches[1], { flavour });\n}\n"],"mappings":";;;;;;;;;AAUA,MAAM,aAAa,EAAE,cAAmC;;;;;;;;;kBAStC,OAAO,IAAI,aAAa,EAAE,sBAAsB,CAAC;iBAClD,QAAQ;;;;;AAMzB,eAAsB,mBAAmB,EACvC,SACA,UACA,eAKkB;AAClB,KAAI,YACF,QAAO;AAIT,KAAI,CAAC,CAAC,YAAY,cAAc,SAC9B,OAAM,IAAI,MACR,4DACD;CAGH,MAAM,MAAM,MAAM,MAAc;EAC9B,KAAK,gBAAgB,EAAE,SAAS,CAAC;EACjC,QAAQ;EACR,MAAM,UAAU,EAAE,SAAS,aAAa,CAAC;EACzC,cAAc;EACd,GAAG,kBAAkB,EAAE,UAAU,CAAC;EACnC,CAAC;CAEF,MAAM,UAAU,iBAAiB,KAAK,IAAI,KAAK;AAE/C,KAAI,CAAC,UAAU,GACb,OAAM,IAAI,MAAM,wDAAwD;AAG1E,QAAO,WAAW,QAAQ,IAAI,EAAE,SAAS,CAAC"}