UNPKG

@dgac/nmb2b-client

Version:

EUROCONTROL Network Manager B2B SOAP client

166 lines (160 loc) 5.76 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/config.ts var config_exports = {}; __export(config_exports, { getEndpoint: () => getEndpoint, getFileEndpoint: () => getFileEndpoint, getFileUrl: () => getFileUrl, isConfigValid: () => isConfigValid, obfuscate: () => obfuscate }); module.exports = __toCommonJS(config_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; } // src/constants.ts var import_path = __toESM(require("path"), 1); var B2B_VERSION = "27.0.0"; var B2BFlavours = ["OPS", "PREOPS"]; // 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(path2, config = {}) { if (config.endpoint) { return new import_url.URL( (path2[0] && path2.startsWith("/") ? "" : "/") + path2, config.endpoint ).toString(); } return getFileEndpoint(config) + (path2[0] && path2.startsWith("/") ? "" : "/") + path2; } function obfuscate(config) { return { ...config, security: Object.keys(config.security).reduce((prev, curr) => { return { ...prev, [curr]: "xxxxxxxxxxxxxxxx" }; }, {}) }; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { getEndpoint, getFileEndpoint, getFileUrl, isConfigValid, obfuscate }); //# sourceMappingURL=config.cjs.map