UNPKG

@dgac/nmb2b-client

Version:

EUROCONTROL Network Manager B2B SOAP client

50 lines (48 loc) 2.18 kB
import { assert } from "./utils/assert.js"; import { isValidSecurity } from "./security.js"; import { B2BFlavours, B2B_VERSION } from "./constants.js"; import { URL } from "url"; //#region src/config.ts function isConfigValid(args) { assert(!!args && typeof args === "object", "Invalid config"); assert("security" in args && isValidSecurity(args.security), "Please provide a valid security option"); assert("flavour" in args && typeof args.flavour === "string", `Invalid config.flavour. Supported flavours: ${B2BFlavours.join(", ")}`); assert(B2BFlavours.includes(args.flavour), `Invalid config.flavour. Supported flavours: ${B2BFlavours.join(", ")}`); if ("apiKeyId" in args.security) { assert("endpoint" in args && !!args.endpoint, `When using an config.security.apiKeyId, config.endpoint must be defined`); assert("xsdEndpoint" in args && !!args.xsdEndpoint, `When using an config.security.apiKeyId, config.xsdEndpoint must be defined`); } return true; } const 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(path, config = {}) { if (config.endpoint) return new URL((path[0] && path.startsWith("/") ? "" : "/") + path, config.endpoint).toString(); return getFileEndpoint(config) + (path[0] && path.startsWith("/") ? "" : "/") + path; } function obfuscate(config) { return { ...config, security: Object.keys(config.security).reduce((prev, curr) => { return { ...prev, [curr]: "xxxxxxxxxxxxxxxx" }; }, {}) }; } //#endregion export { getEndpoint, getFileEndpoint, getFileUrl, isConfigValid, obfuscate }; //# sourceMappingURL=config.js.map