UNPKG

@dgac/nmb2b-client

Version:

EUROCONTROL Network Manager B2B SOAP client

1,419 lines (1,364 loc) 43.3 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { NMB2BError: () => NMB2BError, makeAirspaceClient: () => makeAirspaceClient, makeB2BClient: () => makeB2BClient, makeFlightClient: () => makeFlightClient, makeFlowClient: () => makeFlowClient, makeGeneralInformationClient: () => makeGeneralInformationClient }); module.exports = __toCommonJS(src_exports); // src/security.ts var import_invariant = __toESM(require("invariant"), 1); // src/utils/debug.ts var import_debug = __toESM(require("debug"), 1); var PREFIX = "@dgac/nmb2b-client"; var debug = (0, import_debug.default)(PREFIX); function log(ns) { if (!ns) { return debug; } return debug.extend(ns); } var debug_default = log; // src/security.ts var import_soap = require("soap"); var import_fs = __toESM(require("fs"), 1); var debug2 = debug_default("security"); function isValidSecurity(obj) { (0, import_invariant.default)(!!obj && typeof obj === "object", "Must be an object"); if ("apiKeyId" in obj) { (0, import_invariant.default)( !!obj.apiKeyId && typeof obj.apiKeyId === "string" && obj.apiKeyId.length > 0, "security.apiKeyId must be a string with a length > 0" ); (0, import_invariant.default)( "apiSecretKey" in obj && typeof obj.apiSecretKey === "string" && obj.apiSecretKey.length > 0, "security.apiSecretKey must be defined when using security.apiKeyId" ); return true; } (0, import_invariant.default)( "pfx" in obj && Buffer.isBuffer(obj.pfx) || "cert" in obj && Buffer.isBuffer(obj.cert), "security.pfx or security.cert must be buffers" ); if ("cert" in obj && obj.cert) { (0, import_invariant.default)( "key" in obj && obj.key && Buffer.isBuffer(obj.key), "security.key must be a buffer if security.pem is defined" ); } return true; } function prepareSecurity(config) { const { security } = config; if ("apiKeyId" in security) { const { apiKeyId, apiSecretKey } = security; debug2("Using ApiGateway security"); return new import_soap.BasicAuthSecurity(apiKeyId, apiSecretKey); } else if ("pfx" in security) { const { pfx, passphrase } = security; debug2("Using PFX certificates"); return new import_soap.ClientSSLSecurityPFX(pfx, passphrase); } else if ("cert" in security) { debug2("Using PEM certificates"); const { key, cert, passphrase } = security; return new import_soap.ClientSSLSecurity( key, cert, void 0, passphrase ? { passphrase } : null ); } throw new Error("Invalid security object"); } // src/constants.ts var import_path = __toESM(require("path"), 1); var B2B_VERSION = "27.0.0"; var B2BFlavours = ["OPS", "PREOPS"]; var getWSDLPath = ({ service, flavour, XSD_PATH }) => import_path.default.join( XSD_PATH, `${B2B_VERSION}/${service}_${flavour}_${B2B_VERSION}.wsdl` ); // src/config.ts var import_invariant2 = __toESM(require("invariant"), 1); var import_url = require("url"); function isConfigValid(args) { (0, import_invariant2.default)(!!args && typeof args === "object", "Invalid config"); (0, import_invariant2.default)( "security" in args && isValidSecurity(args.security), "Please provide a valid security option" ); (0, import_invariant2.default)( "flavour" in args && typeof args.flavour === "string", `Invalid config.flavour. Supported flavours: ${B2BFlavours.join(", ")}` ); (0, import_invariant2.default)( B2BFlavours.includes(args.flavour), `Invalid config.flavour. Supported flavours: ${B2BFlavours.join(", ")}` ); if ("apiKeyId" in args.security) { (0, import_invariant2.default)( "endpoint" in args && !!args.endpoint, `When using an config.security.apiKeyId, config.endpoint must be defined` ); (0, import_invariant2.default)( "xsdEndpoint" in args && !!args.xsdEndpoint, `When using an config.security.apiKeyId, config.xsdEndpoint must be defined` ); } return true; } var B2B_ROOTS = { OPS: "https://www.b2b.nm.eurocontrol.int", PREOPS: "https://www.b2b.preops.nm.eurocontrol.int" }; function getEndpoint(config = {}) { const { endpoint, flavour } = config; if (flavour && flavour === "PREOPS") { return `${endpoint ?? B2B_ROOTS.PREOPS}/B2B_PREOPS/gateway/spec/${B2B_VERSION}`; } return `${endpoint ?? B2B_ROOTS.OPS}/B2B_OPS/gateway/spec/${B2B_VERSION}`; } function getFileEndpoint(config = {}) { const { endpoint, flavour } = config; if (flavour && flavour === "PREOPS") { return `${endpoint ?? B2B_ROOTS.PREOPS}/FILE_PREOPS/gateway/spec`; } return `${endpoint ?? B2B_ROOTS.OPS}/FILE_OPS/gateway/spec`; } function getFileUrl(path3, config = {}) { if (config.endpoint) { return new import_url.URL( (path3[0] && path3.startsWith("/") ? "" : "/") + path3, config.endpoint ).toString(); } return getFileEndpoint(config) + (path3[0] && path3.startsWith("/") ? "" : "/") + path3; } function obfuscate(config) { return { ...config, security: Object.keys(config.security).reduce((prev, curr) => { return { ...prev, [curr]: "xxxxxxxxxxxxxxxx" }; }, {}) }; } // src/utils/xsd/index.ts var import_fs2 = __toESM(require("fs"), 1); var import_path2 = __toESM(require("path"), 1); var import_proper_lockfile = __toESM(require("proper-lockfile"), 1); var import_util = require("util"); // src/utils/fs.ts var fs2 = __toESM(require("fs/promises"), 1); var debug3 = debug_default("dir-exists"); async function dirExists(path3, { readable, writable } = { readable: true, writable: false }) { debug3( `Testing if directory ${path3} is readable ${writable ? "and writable " : ""}...` ); try { const stats = await fs2.stat(path3); if (!stats.isDirectory()) { return false; } await fs2.access( path3, (writable ? fs2.constants.W_OK : 0) | (readable ? fs2.constants.R_OK : 0) ); debug3(`Directory ${path3} is accessible`); return true; } catch { return false; } } async function createDir(path3) { debug3("Creating directory %s ...", path3); await fs2.mkdir(path3, { recursive: true }); } // src/utils/xsd/downloadFile.ts var import_axios = __toESM(require("axios"), 1); var import_tar = require("tar"); // src/utils/xsd/createAxiosConfig.ts var import_https = __toESM(require("https"), 1); function createAxiosConfig({ security }) { if (!!security && "apiKeyId" in security) { return { auth: { username: security.apiKeyId, password: security.apiSecretKey } }; } const httpsAgent = new import_https.default.Agent(security); return { httpsAgent }; } // src/utils/xsd/downloadFile.ts var debug4 = debug_default("wsdl-downloader"); async function downloadFile(filePath, { flavour, security, XSD_PATH: outputDir, xsdEndpoint }) { const options = createAxiosConfig({ security }); const url = xsdEndpoint || getFileUrl(filePath, { flavour }); debug4(`Downloading ${url}`); try { const res = await import_axios.default.get(url, { timeout: 15 * 1e3, responseType: "stream", ...options }); return new Promise((resolve, reject) => { res.data.pipe((0, import_tar.extract)({ cwd: outputDir })).on("error", reject).on("close", () => { debug4("Downloaded and extracted WSDL files"); resolve(); }); }); } catch (err) { const message = err instanceof Error ? err.message : "Unknown error"; throw new Error(`Unable to download WSDL: ${message}`, { cause: err }); } } // src/utils/xsd/filePath.ts var import_utc = require("@date-fns/utc"); var import_axios2 = __toESM(require("axios"), 1); var import_date_fns = require("date-fns"); // src/utils/timeFormats.ts var timeFormat = "yyyy-MM-dd HH:mm"; var dateFormat = "yyyy-MM-dd"; var timeFormatWithSeconds = timeFormat + ":ss"; // src/utils/xsd/filePath.ts var 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>${(0, import_date_fns.format)(new import_utc.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 (0, import_axios2.default)({ 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]; } // src/utils/xsd/index.ts var debug5 = debug_default("wsdl"); var readdir = (0, import_util.promisify)(import_fs2.default.readdir); var getWSDLPath2 = ({ XSD_PATH }) => import_path2.default.join(XSD_PATH, B2B_VERSION); async function WSDLExists(config) { const directory = getWSDLPath2(config); debug5(`Checking if directory ${directory} exists`); if (!await dirExists(directory)) { return false; } const files = await readdir(directory); return files.length > 0; } async function download(config) { const outputDir = getWSDLPath2(config); if (!await dirExists(outputDir)) { debug5(`Creating directory ${outputDir}`); await createDir(outputDir); } debug5(`Acquiring lock for folder ${outputDir}`); const release = await import_proper_lockfile.default.lock(outputDir, { retries: 5 }); debug5(`Lock acquired. Testing WSDL existence ...`); const hasWSDL = await WSDLExists(config); if (!config.ignoreWSDLCache && hasWSDL) { debug5("WSDL found"); await release(); return; } const fileName = await requestFilename(config); debug5(`Downloading ${fileName}`); await downloadFile(fileName, config); await release(); } // src/Airspace/index.ts var import_soap2 = require("soap"); // src/utils/transformers/types.ts var import_utc2 = require("@date-fns/utc"); var import_date_fns2 = require("date-fns"); var outputBase = { integer: (text) => { return parseInt(text, 10); }, /** * * Parse a NMB2B date/datetime. * * All datetimes are assumed to be UTC. * * Per NM B2B documentation, we only need to support these formats: * - DateTimeMinute: YYYY-MM-DD hh:mm * - DateTimeSecond: YYYY-MM-DD hh:mm:ss * - DateYearMonthDay: YYYY-MM-DD * * All dates are * @param text NM B2B Date string * @returns Parsed Date instance */ date: (text) => { let [date, time] = text.split(" "); if (!time) { return new Date(text); } if (time.length === 5) { time += ":00"; } return /* @__PURE__ */ new Date(`${date}T${time}Z`); } }; var types = { FlightLevel_DataType: { input: null, output: outputBase.integer }, DurationHourMinute: { input: (d2) => { const totalMinutes = Math.floor(d2 / 60); const hours = Math.floor(totalMinutes / 60); const minutes = totalMinutes % 60; return `${hours}`.padStart(2, "0") + `${minutes}`.padStart(2, "0"); }, output: (s) => { const hours = parseInt(s.slice(0, 2), 10); const minutes = parseInt(s.slice(2), 10); return 60 * (60 * hours + minutes); } }, DurationHourMinuteSecond: { input: (d2) => { const totalMinutes = Math.floor(d2 / 60); const hours = Math.floor(totalMinutes / 60); const minutes = totalMinutes % 60; return `${hours}`.padStart(2, "0") + `${minutes}`.padStart(2, "0") + `${d2 % 60}`.padStart(2, "0"); }, output: (s) => { const hours = parseInt(s.slice(0, 2), 10); const minutes = parseInt(s.slice(2, 4), 10); const seconds = parseInt(s.slice(4), 10); return 3600 * hours + 60 * minutes + seconds; } }, DurationMinute: { input: (d2) => Math.floor(d2 / 60), output: (d2) => 60 * d2 }, CountsValue: { input: null, output: outputBase.integer }, DateTimeMinute: { input: (d2) => (0, import_date_fns2.format)(new import_utc2.UTCDate(d2), timeFormat), output: outputBase.date }, DateYearMonthDay: { input: (d2) => (0, import_date_fns2.format)(new import_utc2.UTCDate(d2), dateFormat), output: outputBase.date }, DateTimeSecond: { input: (d2) => (0, import_date_fns2.format)(new import_utc2.UTCDate(d2), timeFormatWithSeconds), output: outputBase.date }, DistanceNM: { input: null, output: outputBase.integer }, DistanceM: { input: null, output: outputBase.integer }, Bearing: { input: null, output: outputBase.integer }, OTMVThreshold: { input: null, output: outputBase.integer } }; // src/utils/transformers/serializer.ts var import_remeda = require("remeda"); function prepareSerializer(schema) { const transformer = prepareTransformer(schema); return (0, import_remeda.piped)( reorderKeys(schema), transformer ? (0, import_remeda.evolve)(transformer) : import_remeda.identity // (obj) => { // console.log(JSON.stringify(obj, null, 2)); // return obj; // }, ); } function reduceXSDType(str) { return str.split("|")[0]; } function prepareTransformer(schema) { return Object.keys(schema).reduce((prev, curr) => { let key = curr; let isArray = false; if (curr.endsWith("[]")) { key = curr.slice(0, -2); isArray = true; } if (typeof schema[curr] === "string") { const type = reduceXSDType(schema[curr]); if (types[type]?.input) { const transformer = types[type].input; return { ...prev, [key]: isArray ? (0, import_remeda.map)(transformer) : transformer }; } } else if (typeof schema[curr] === "object") { const subItem = prepareTransformer(schema[curr]); if (subItem) { return { ...prev, [key]: isArray ? (0, import_remeda.map)((0, import_remeda.evolve)(subItem)) : subItem }; } } return prev; }, null); } function reorderKeys(schema) { return (obj) => { return Object.keys(schema).reduce((prev, curr) => { const lookupKey = curr.replace(/\[\]$/, ""); const isArrayExpected = curr.endsWith("[]"); if (!(lookupKey in obj)) { return prev; } const currSchema = schema[curr]; if (typeof currSchema === "string") { prev[lookupKey] = obj[lookupKey]; return prev; } if (typeof currSchema === "object") { if (Object.keys(currSchema).filter( (k) => k !== "targetNSAlias" && k !== "targetNamespace" ).length) { prev[lookupKey] = isArrayExpected && obj[lookupKey] && Array.isArray(obj[lookupKey]) ? obj[lookupKey].map(reorderKeys(currSchema)) : reorderKeys(currSchema)(obj[lookupKey]); return prev; } prev[lookupKey] = obj[lookupKey]; return prev; } return prev; }, {}); }; } // src/utils/transformers/index.ts var deserializer = Object.entries(types).reduce((prev, [key, { output }]) => { if (output) { prev[key] = output; } return prev; }, {}); // src/utils/instrumentation/withLog.ts function withLog(namespace) { const debug7 = debug_default(namespace); return (fn) => (values, options) => { if (values) { debug7("Called with input %o", values); } else { debug7("Called"); } return fn(values, options).then( (res) => { debug7("Succeded"); return res; }, (err) => { debug7("Failed"); return Promise.reject( err instanceof Error ? err : new Error("Unknown error", { cause: err }) ); } ); }; } // src/utils/instrumentation/index.ts var import_remeda2 = require("remeda"); function instrument({ service, query }) { return (fn) => (0, import_remeda2.pipe)(fn, withLog(`${service}:${query}`)); } // src/utils/NMB2BError.ts var NMB2BError = class extends Error { constructor({ reply }) { super(); if (reply.requestId) { this.requestId = reply.requestId; } if (reply.requestReceptionTime) { this.requestReceptionTime = reply.requestReceptionTime; } if (reply.sendTime) { this.sendTime = reply.sendTime; } if (reply.inputValidationErrors) { this.inputValidationErrors = reply.inputValidationErrors; } if (reply.warnings) { this.warnings = reply.warnings; } if (reply.slaError) { this.slaError = reply.slaError; } if (reply.reason) { this.reason = reply.reason; } this.status = reply.status; this.message = this.status; if (this.reason) { this.message = `${this.message}: ${this.reason}`; } } }; // src/utils/internals.ts function injectSendTime(values) { const sendTime = /* @__PURE__ */ new Date(); if (!values || typeof values !== "object") { return { sendTime }; } return { sendTime, ...values }; } function responseStatusHandler(resolve, reject) { return (err, reply) => { if (err) { reject(err); return; } if (reply.status === "OK") { resolve(reply); return; } else { const err2 = new NMB2BError({ reply }); reject(err2); return; } }; } // src/Airspace/queryCompleteAIXMDatasets.ts function prepareQueryCompleteAIXMDatasets(client) { const schema = ( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access client.describe().AirspaceStructureService.AirspaceStructurePort.queryCompleteAIXMDatasets.input ); const serializer = prepareSerializer(schema); return instrument({ service: "Airspace", query: "queryCompleteAIXMDatasets" })( (values, options) => new Promise((resolve, reject) => { client.queryCompleteAIXMDatasets( serializer(injectSendTime(values)), options, responseStatusHandler(resolve, reject) ); }) ); } // src/Airspace/retrieveAUP.ts function prepareRetrieveAUP(client) { const schema = ( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access client.describe().AirspaceAvailabilityService.AirspaceAvailabilityPort.retrieveAUP.input ); const serializer = prepareSerializer(schema); return instrument({ service: "Airspace", query: "retrieveAUP" })( (values, options) => new Promise((resolve, reject) => { client.retrieveAUP( serializer(injectSendTime(values)), options, responseStatusHandler(resolve, reject) ); }) ); } // src/Airspace/retrieveAUPChain.ts function prepareRetrieveAUPChain(client) { const schema = ( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access client.describe().AirspaceAvailabilityService.AirspaceAvailabilityPort.retrieveAUPChain.input ); const serializer = prepareSerializer(schema); return instrument({ service: "Airspace", query: "retrieveAUPChain" })( (values, options) => new Promise((resolve, reject) => { client.retrieveAUPChain( serializer(injectSendTime(values)), options, responseStatusHandler(resolve, reject) ); }) ); } // src/Airspace/retrieveEAUPChain.ts function prepareRetrieveEAUPChain(client) { const schema = ( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access client.describe().AirspaceAvailabilityService.AirspaceAvailabilityPort.retrieveEAUPChain.input ); const serializer = prepareSerializer(schema); return instrument({ service: "Airspace", query: "retrieveEAUPChain" })( (values, options) => new Promise((resolve, reject) => { client.retrieveEAUPChain( serializer(injectSendTime(values)), options, responseStatusHandler(resolve, reject) ); }) ); } // src/Airspace/index.ts var getWSDL = ({ XSD_PATH, flavour }) => getWSDLPath({ service: "AirspaceServices", flavour, XSD_PATH }); function createAirspaceServices(config) { const WSDL = getWSDL(config); const security = prepareSecurity(config); return new Promise((resolve, reject) => { (0, import_soap2.createClient)(WSDL, { customDeserializer: deserializer }, (err, client) => { try { if (err) { reject( err instanceof Error ? err : new Error("Unknown error", { cause: err }) ); return; } client.setSecurity(security); resolve(client); } catch (err2) { console.log(err2); reject( err2 instanceof Error ? err2 : new Error("Unknown error", { cause: err2 }) ); return; } }); }); } function getAirspaceClient(config) { return createAirspaceServices(config).then((client) => ({ __soapClient: client, config, queryCompleteAIXMDatasets: prepareQueryCompleteAIXMDatasets(client), retrieveAUPChain: prepareRetrieveAUPChain(client), retrieveEAUPChain: prepareRetrieveEAUPChain(client), retrieveAUP: prepareRetrieveAUP(client) })); } // src/Flight/index.ts var import_soap3 = require("soap"); // src/Flight/retrieveFlight.ts function prepareRetrieveFlight(client) { const schema = ( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access client.describe().FlightManagementService.FlightManagementPort.retrieveFlight.input ); const serializer = prepareSerializer(schema); return instrument({ service: "Flight", query: "retrieveFlight" })( (values, options) => new Promise((resolve, reject) => { client.retrieveFlight( serializer(injectSendTime(values)), options, responseStatusHandler(resolve, reject) ); }) ); } // src/Flight/queryFlightsByAirspace.ts function prepareQueryFlightsByAirspace(client) { const schema = ( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access client.describe().FlightManagementService.FlightManagementPort.queryFlightsByAirspace.input ); const serializer = prepareSerializer(schema); return instrument({ service: "Flight", query: "queryFlightsByAirspace" })( (values, options) => new Promise((resolve, reject) => { client.queryFlightsByAirspace( serializer(injectSendTime(values)), options, responseStatusHandler(resolve, reject) ); }) ); } // src/Flight/queryFlightPlans.ts function prepareQueryFlightPlans(client) { const schema = ( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access client.describe().FlightManagementService.FlightManagementPort.queryFlightPlans.input ); const serializer = prepareSerializer(schema); return instrument({ service: "Flight", query: "queryFlightPlans" })( (values, options) => new Promise((resolve, reject) => { client.queryFlightPlans( serializer(injectSendTime(values)), options, responseStatusHandler(resolve, reject) ); }) ); } // src/Flight/queryFlightsByTrafficVolume.ts function prepareQueryFlightsByTrafficVolume(client) { const schema = ( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access client.describe().FlightManagementService.FlightManagementPort.queryFlightsByTrafficVolume.input ); const serializer = prepareSerializer(schema); return instrument({ service: "Flight", query: "queryFlightsByTrafficVolume" })( (values, options) => new Promise((resolve, reject) => { client.queryFlightsByTrafficVolume( serializer(injectSendTime(values)), options, responseStatusHandler(resolve, reject) ); }) ); } // src/Flight/queryFlightsByMeasure.ts function prepareQueryFlightsByMeasure(client) { const schema = ( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access client.describe().FlightManagementService.FlightManagementPort.queryFlightsByMeasure.input ); const serializer = prepareSerializer(schema); return instrument({ service: "Flight", query: "queryFlightsByMeasure" })( (values, options) => new Promise((resolve, reject) => { client.queryFlightsByMeasure( serializer(injectSendTime(values)), options, responseStatusHandler(resolve, reject) ); }) ); } // src/Flight/queryFlightsByAerodrome.ts function prepareQueryFlightsByAerodrome(client) { const schema = ( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access client.describe().FlightManagementService.FlightManagementPort.queryFlightsByAerodrome.input ); const serializer = prepareSerializer(schema); return instrument({ service: "Flight", query: "queryFlightsByAerodrome" })( (values, options) => new Promise((resolve, reject) => { client.queryFlightsByAerodrome( serializer(injectSendTime(values)), options, responseStatusHandler(resolve, reject) ); }) ); } // src/Flight/queryFlightsByAerodromeSet.ts function prepareQueryFlightsByAerodromeSet(client) { const schema = ( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access client.describe().FlightManagementService.FlightManagementPort.queryFlightsByAerodromeSet.input ); const serializer = prepareSerializer(schema); return instrument({ service: "Flight", query: "queryFlightsByAerodromeSet" })( (values, options) => new Promise((resolve, reject) => { client.queryFlightsByAerodromeSet( serializer(injectSendTime(values)), options, responseStatusHandler(resolve, reject) ); }) ); } // src/Flight/queryFlightsByAircraftOperator.ts function prepareQueryFlightsByAircraftOperator(client) { const schema = ( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access client.describe().FlightManagementService.FlightManagementPort.queryFlightsByAircraftOperator.input ); const serializer = prepareSerializer(schema); return instrument({ service: "Flight", query: "queryFlightsByAircraftOperator" })( (values, options) => new Promise((resolve, reject) => { client.queryFlightsByAircraftOperator( serializer(injectSendTime(values)), options, responseStatusHandler(resolve, reject) ); }) ); } // src/Flight/index.ts var getWSDL2 = ({ flavour, XSD_PATH }) => getWSDLPath({ service: "FlightServices", flavour, XSD_PATH }); function createFlightServices(config) { const WSDL = getWSDL2(config); const security = prepareSecurity(config); return new Promise((resolve, reject) => { try { (0, import_soap3.createClient)(WSDL, { customDeserializer: deserializer }, (err, client) => { if (err) { reject( err instanceof Error ? err : new Error("Unknown error", { cause: err }) ); return; } client.setSecurity(security); resolve(client); }); } catch (err) { console.log(err); reject( err instanceof Error ? err : new Error("Unknown error", { cause: err }) ); return; } }); } function getFlightClient(config) { return createFlightServices(config).then((client) => ({ __soapClient: client, config, retrieveFlight: prepareRetrieveFlight(client), queryFlightsByAirspace: prepareQueryFlightsByAirspace(client), queryFlightPlans: prepareQueryFlightPlans(client), queryFlightsByTrafficVolume: prepareQueryFlightsByTrafficVolume(client), queryFlightsByMeasure: prepareQueryFlightsByMeasure(client), queryFlightsByAerodrome: prepareQueryFlightsByAerodrome(client), queryFlightsByAerodromeSet: prepareQueryFlightsByAerodromeSet(client), queryFlightsByAircraftOperator: prepareQueryFlightsByAircraftOperator(client) })); } // src/Flow/index.ts var import_soap4 = require("soap"); // src/Flow/queryHotspots.ts function prepareQueryHotspots(client) { const schema = ( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access client.describe().TacticalUpdatesService.TacticalUpdatesPort.queryHotspots.input ); const serializer = prepareSerializer(schema); return instrument({ service: "Flow", query: "queryHotspots" })( (values, options) => new Promise((resolve, reject) => { client.queryHotspots( serializer(injectSendTime(values)), options, responseStatusHandler(resolve, reject) ); }) ); } // src/Flow/queryRegulations.ts function prepareQueryRegulations(client) { const schema = ( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access client.describe().MeasuresService.MeasuresPort.queryRegulations.input ); const serializer = prepareSerializer(schema); return instrument({ service: "Flow", query: "queryRegulations" })( (values, options) => new Promise((resolve, reject) => { client.queryRegulations( serializer(injectSendTime(values)), options, responseStatusHandler(resolve, reject) ); }) ); } // src/Flow/queryTrafficCountsByAirspace.ts function prepareQueryTrafficCountsByAirspace(client) { const schema = ( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access client.describe().TrafficCountsService.TrafficCountsPort.queryTrafficCountsByAirspace.input ); const serializer = prepareSerializer(schema); return instrument({ service: "Flow", query: "queryTrafficCountsByAirspace" })( (values, options) => new Promise((resolve, reject) => { client.queryTrafficCountsByAirspace( serializer(injectSendTime(values)), options, responseStatusHandler(resolve, reject) ); }) ); } // src/Flow/queryTrafficCountsByTrafficVolume.ts function prepareQueryTrafficCountsByTrafficVolume(client) { const schema = ( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access client.describe().TrafficCountsService.TrafficCountsPort.queryTrafficCountsByTrafficVolume.input ); const serializer = prepareSerializer(schema); return instrument({ service: "Flow", query: "queryTrafficCountsByTrafficVolume" })( (values, options) => new Promise((resolve, reject) => { client.queryTrafficCountsByTrafficVolume( serializer(injectSendTime(values)), options, responseStatusHandler(resolve, reject) ); }) ); } // src/Flow/retrieveCapacityPlan.ts function prepareRetrieveCapacityPlan(client) { const schema = ( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access client.describe().TacticalUpdatesService.TacticalUpdatesPort.retrieveCapacityPlan.input ); const serializer = prepareSerializer(schema); return instrument({ service: "Flow", query: "retrieveCapacityPlan" })( (values, options) => new Promise((resolve, reject) => { client.retrieveCapacityPlan( serializer(injectSendTime(values)), options, responseStatusHandler(resolve, reject) ); }) ); } // src/Flow/retrieveOTMVPlan.ts function prepareRetrieveOTMVPlan(client) { const schema = ( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access client.describe().TacticalUpdatesService.TacticalUpdatesPort.retrieveOTMVPlan.input ); const serializer = prepareSerializer(schema); return instrument({ service: "Flow", query: "retrieveOTMVPlan" })( (values, options) => new Promise((resolve, reject) => { client.retrieveOTMVPlan( serializer(injectSendTime(values)), options, responseStatusHandler(resolve, reject) ); }) ); } // src/Flow/retrieveRunwayConfigurationPlan.ts function prepareRetrieveRunwayConfigurationPlan(client) { const schema = ( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access client.describe().TacticalUpdatesService.TacticalUpdatesPort.retrieveRunwayConfigurationPlan.input ); const serializer = prepareSerializer(schema); return instrument({ service: "Flow", query: "retrieveRunwayConfigurationPlan" })( (values, options) => new Promise((resolve, reject) => { client.retrieveRunwayConfigurationPlan( serializer(injectSendTime(values)), options, responseStatusHandler(resolve, reject) ); }) ); } // src/Flow/retrieveSectorConfigurationPlan.ts function prepareRetrieveSectorConfigurationPlan(client) { const schema = ( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access client.describe().TacticalUpdatesService.TacticalUpdatesPort.retrieveSectorConfigurationPlan.input ); const serializer = prepareSerializer(schema); return instrument({ service: "Flow", query: "retrieveSectorConfigurationPlan" })( (values, options) => new Promise((resolve, reject) => { client.retrieveSectorConfigurationPlan( serializer(injectSendTime(values)), options, responseStatusHandler(resolve, reject) ); }) ); } // src/Flow/updateCapacityPlan.ts function prepareUpdateCapacityPlan(client) { const schema = ( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access client.describe().TacticalUpdatesService.TacticalUpdatesPort.updateCapacityPlan.input ); const serializer = prepareSerializer(schema); return instrument({ service: "Flow", query: "updateCapacityPlan" })( (values, options) => new Promise((resolve, reject) => { client.updateCapacityPlan( serializer(injectSendTime(values)), options, responseStatusHandler(resolve, reject) ); }) ); } // src/Flow/updateOTMVPlan.ts function prepareUpdateOTMVPlan(client) { const schema = ( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access client.describe().TacticalUpdatesService.TacticalUpdatesPort.updateOTMVPlan.input ); const serializer = prepareSerializer(schema); return instrument({ service: "Flow", query: "updateOTMVPlan" })( (values, options) => new Promise((resolve, reject) => { console.log( JSON.stringify(serializer(injectSendTime(values)), null, 2) ); client.updateOTMVPlan( serializer(injectSendTime(values)), options, responseStatusHandler(resolve, reject) ); }) ); } // src/Flow/index.ts var getWSDL3 = ({ flavour, XSD_PATH }) => getWSDLPath({ service: "FlowServices", flavour, XSD_PATH }); function createFlowServices(config) { const WSDL = getWSDL3(config); const security = prepareSecurity(config); return new Promise((resolve, reject) => { try { (0, import_soap4.createClient)(WSDL, { customDeserializer: deserializer }, (err, client) => { if (err) { reject( err instanceof Error ? err : new Error("Unknown error", { cause: err }) ); return; } client.setSecurity(security); resolve(client); }); } catch (err) { console.log(err); reject( err instanceof Error ? err : new Error("Unknown error", { cause: err }) ); return; } }); } function getFlowClient(config) { return createFlowServices(config).then((client) => ({ __soapClient: client, config, retrieveSectorConfigurationPlan: prepareRetrieveSectorConfigurationPlan(client), queryTrafficCountsByAirspace: prepareQueryTrafficCountsByAirspace(client), queryRegulations: prepareQueryRegulations(client), queryHotspots: prepareQueryHotspots(client), queryTrafficCountsByTrafficVolume: prepareQueryTrafficCountsByTrafficVolume(client), retrieveOTMVPlan: prepareRetrieveOTMVPlan(client), updateOTMVPlan: prepareUpdateOTMVPlan(client), retrieveCapacityPlan: prepareRetrieveCapacityPlan(client), updateCapacityPlan: prepareUpdateCapacityPlan(client), retrieveRunwayConfigurationPlan: prepareRetrieveRunwayConfigurationPlan(client) })); } // src/GeneralInformation/index.ts var import_soap5 = require("soap"); // src/GeneralInformation/queryNMB2BWSDLs.ts function prepareQueryNMB2BWSDLs(client) { const schema = ( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access client.describe().NMB2BInfoService.NMB2BInfoPort.queryNMB2BWSDLs.input ); const serializer = prepareSerializer(schema); return instrument({ service: "GeneralInformation", query: "queryNMB2BWSDLs" })( (values, options) => new Promise((resolve, reject) => { client.queryNMB2BWSDLs( serializer(injectSendTime(values)), options, responseStatusHandler(resolve, reject) ); }) ); } // src/GeneralInformation/retrieveUserinformation.ts function prepareRetrieveUserInformation(client) { const schema = ( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access client.describe().NMB2BInfoService.NMB2BInfoPort.retrieveUserInformation.input ); const serializer = prepareSerializer(schema); return instrument({ service: "GeneralInformation", query: "retrieveUserInformation" })( (values, options) => new Promise((resolve, reject) => { client.retrieveUserInformation( serializer(injectSendTime(values)), options, responseStatusHandler(resolve, reject) ); }) ); } // src/GeneralInformation/index.ts var getWSDL4 = ({ flavour, XSD_PATH }) => getWSDLPath({ service: "GeneralinformationServices", flavour, XSD_PATH }); function createGeneralInformationServices(config) { const WSDL = getWSDL4(config); const security = prepareSecurity(config); return new Promise((resolve, reject) => { try { (0, import_soap5.createClient)(WSDL, { customDeserializer: deserializer }, (err, client) => { if (err) { reject( err instanceof Error ? err : new Error("Unknown error", { cause: err }) ); return; } client.setSecurity(security); resolve(client); }); } catch (err) { reject( err instanceof Error ? err : new Error("Unknown error", { cause: err }) ); return; } }); } function getGeneralInformationClient(config) { return createGeneralInformationServices(config).then( (client) => ({ __soapClient: client, config, queryNMB2BWSDLs: prepareQueryNMB2BWSDLs(client), retrieveUserInformation: prepareRetrieveUserInformation(client) }), (err) => { console.error(err); return Promise.reject( err instanceof Error ? err : new Error("Unknown error", { cause: err }) ); } ); } // src/index.ts var debug6 = debug_default(); var defaults = { flavour: "OPS", XSD_PATH: "/tmp/b2b-xsd" }; async function makeB2BClient(args) { const options = { ...defaults, ...args }; debug6("Instantiating B2B Client ..."); if (!isConfigValid(options)) { debug6("Invalid options provided"); throw new Error("Invalid options provided"); } debug6("Config is %o", obfuscate(options)); await download(options); return Promise.all([ getAirspaceClient(options), getFlightClient(options), getFlowClient(options), getGeneralInformationClient(options) ]).then((res) => { debug6("Successfully created B2B Client"); return res; }).then(([Airspace, Flight, Flow, GeneralInformation]) => ({ Airspace, Flight, Flow, GeneralInformation })); } async function makeAirspaceClient(args) { const options = { ...defaults, ...args }; debug6("Instantiating B2B Airspace client ..."); if (!isConfigValid(options)) { debug6("Invalid options provided"); throw new Error("Invalid options provided"); } debug6("Config is %o", obfuscate(options)); await download(options); return getAirspaceClient(options).then((res) => { debug6("Successfully created B2B Airspace client"); return res; }); } async function makeFlightClient(args) { const options = { ...defaults, ...args }; debug6("Instantiating B2B Flight client ..."); if (!isConfigValid(options)) { debug6("Invalid options provided"); throw new Error("Invalid options provided"); } debug6("Config is %o", obfuscate(options)); await download(options); return getFlightClient(options).then((res) => { debug6("Successfully created B2B Flight client"); return res; }); } async function makeFlowClient(args) { const options = { ...defaults, ...args }; debug6("Instantiating B2B Flow client ..."); if (!isConfigValid(options)) { debug6("Invalid options provided"); throw new Error("Invalid options provided"); } debug6("Config is %o", obfuscate(options)); await download(options); return getFlowClient(options).then((res) => { debug6("Successfully created B2B Flow client"); return res; }); } async function makeGeneralInformationClient(args) { const options = { ...defaults, ...args }; debug6("Instantiating B2B GeneralInformation client ..."); if (!isConfigValid(options)) { debug6("Invalid options provided"); throw new Error("Invalid options provided"); } debug6("Config is %o", obfuscate(options)); await download(options); return getGeneralInformationClient(options).then((res) => { debug6("Successfully created B2B GeneralInformation client"); return res; }); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { NMB2BError, makeAirspaceClient, makeB2BClient, makeFlightClient, makeFlowClient, makeGeneralInformationClient }); //# sourceMappingURL=index.cjs.map