@dgac/nmb2b-client
Version:
EUROCONTROL Network Manager B2B SOAP client
1,381 lines (1,328 loc) • 40.5 kB
JavaScript
// src/security.ts
import invariant from "invariant";
// src/utils/debug.ts
import d from "debug";
var PREFIX = "@dgac/nmb2b-client";
var debug = d(PREFIX);
function log(ns) {
if (!ns) {
return debug;
}
return debug.extend(ns);
}
var debug_default = log;
// src/security.ts
import {
ClientSSLSecurity,
ClientSSLSecurityPFX,
BasicAuthSecurity
} from "soap";
import fs from "fs";
var debug2 = debug_default("security");
function isValidSecurity(obj) {
invariant(!!obj && typeof obj === "object", "Must be an object");
if ("apiKeyId" in obj) {
invariant(
!!obj.apiKeyId && typeof obj.apiKeyId === "string" && obj.apiKeyId.length > 0,
"security.apiKeyId must be a string with a length > 0"
);
invariant(
"apiSecretKey" in obj && typeof obj.apiSecretKey === "string" && obj.apiSecretKey.length > 0,
"security.apiSecretKey must be defined when using security.apiKeyId"
);
return true;
}
invariant(
"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) {
invariant(
"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 BasicAuthSecurity(apiKeyId, apiSecretKey);
} else if ("pfx" in security) {
const { pfx, passphrase } = security;
debug2("Using PFX certificates");
return new ClientSSLSecurityPFX(pfx, passphrase);
} else if ("cert" in security) {
debug2("Using PEM certificates");
const { key, cert, passphrase } = security;
return new ClientSSLSecurity(
key,
cert,
void 0,
passphrase ? { passphrase } : null
);
}
throw new Error("Invalid security object");
}
// src/constants.ts
import path from "path";
var B2B_VERSION = "27.0.0";
var B2BFlavours = ["OPS", "PREOPS"];
var getWSDLPath = ({
service,
flavour,
XSD_PATH
}) => path.join(
XSD_PATH,
`${B2B_VERSION}/${service}_${flavour}_${B2B_VERSION}.wsdl`
);
// src/config.ts
import invariant2 from "invariant";
import { URL } from "url";
function isConfigValid(args) {
invariant2(!!args && typeof args === "object", "Invalid config");
invariant2(
"security" in args && isValidSecurity(args.security),
"Please provide a valid security option"
);
invariant2(
"flavour" in args && typeof args.flavour === "string",
`Invalid config.flavour. Supported flavours: ${B2BFlavours.join(", ")}`
);
invariant2(
B2BFlavours.includes(args.flavour),
`Invalid config.flavour. Supported flavours: ${B2BFlavours.join(", ")}`
);
if ("apiKeyId" in args.security) {
invariant2(
"endpoint" in args && !!args.endpoint,
`When using an config.security.apiKeyId, config.endpoint must be defined`
);
invariant2(
"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 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
import fs3 from "fs";
import path2 from "path";
import lockfile from "proper-lockfile";
import { promisify } from "util";
// src/utils/fs.ts
import * as fs2 from "fs/promises";
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
import axios from "axios";
import { extract } from "tar";
// src/utils/xsd/createAxiosConfig.ts
import https from "https";
function createAxiosConfig({ security }) {
if (!!security && "apiKeyId" in security) {
return {
auth: {
username: security.apiKeyId,
password: security.apiSecretKey
}
};
}
const httpsAgent = new https.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 axios.get(url, {
timeout: 15 * 1e3,
responseType: "stream",
...options
});
return new Promise((resolve, reject) => {
res.data.pipe(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
import { UTCDateMini } from "@date-fns/utc";
import axios2 from "axios";
import { format } from "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>${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 axios2({
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 = promisify(fs3.readdir);
var getWSDLPath2 = ({ XSD_PATH }) => path2.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 lockfile.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
import { createClient } from "soap";
// src/utils/transformers/types.ts
import { UTCDate } from "@date-fns/utc";
import { format as format2 } from "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) => format2(new UTCDate(d2), timeFormat),
output: outputBase.date
},
DateYearMonthDay: {
input: (d2) => format2(new UTCDate(d2), dateFormat),
output: outputBase.date
},
DateTimeSecond: {
input: (d2) => format2(new 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
import { piped, identity, evolve, map } from "remeda";
function prepareSerializer(schema) {
const transformer = prepareTransformer(schema);
return piped(
reorderKeys(schema),
transformer ? evolve(transformer) : 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 ? map(transformer) : transformer };
}
} else if (typeof schema[curr] === "object") {
const subItem = prepareTransformer(schema[curr]);
if (subItem) {
return {
...prev,
[key]: isArray ? map(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
import { pipe } from "remeda";
function instrument({
service,
query
}) {
return (fn) => 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) => {
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
import { createClient as createClient2 } from "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 {
createClient2(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
import { createClient as createClient3 } from "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 {
createClient3(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
import { createClient as createClient4 } from "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 {
createClient4(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;
});
}
export {
NMB2BError,
makeAirspaceClient,
makeB2BClient,
makeFlightClient,
makeFlowClient,
makeGeneralInformationClient
};
//# sourceMappingURL=index.js.map