UNPKG

@dgac/nmb2b-client

Version:

EUROCONTROL Network Manager B2B SOAP client

109 lines (107 loc) 3.69 kB
import { createDebugLogger } from "./utils/debug.mjs"; import { assertValidConfig, obfuscate } from "./config.mjs"; import { getAirspaceClient } from "./Airspace/index.mjs"; import { getFlightClient } from "./Flight/index.mjs"; import { getFlowClient } from "./Flow/index.mjs"; import { getGeneralInformationClient } from "./GeneralInformation/index.mjs"; import { download } from "./utils/xsd/index.mjs"; //#region src/createB2BClient.ts const debug = createDebugLogger(); const CONFIG_DEFAULTS = { flavour: "OPS", XSD_PATH: "/tmp/b2b-xsd", hooks: [] }; /** * Main factory to create a fully initialized B2B client. * Handles WSDL downloading (if needed) and initializes all sub-services. * * @param options - Configuration options for the client. See {@link CreateB2BClientOptions}. * @returns The initialized {@link B2BClient} instance. */ async function createB2BClient(options) { debug("Creating B2B Client ..."); const config = prepareConfig(options); await download(config); const [Airspace, Flight, Flow, GeneralInformation] = await Promise.all([ getAirspaceClient(config), getFlightClient(config), getFlowClient(config), getGeneralInformationClient(config) ]); debug("Successfully created B2B Client"); return { Airspace, Flight, Flow, GeneralInformation }; } /** * Factory to create a standalone client for the Airspace domain. * * @param options - Configuration options for the client. See {@link CreateB2BClientOptions}. * @returns The initialized {@link AirspaceService} instance. */ async function createAirspaceClient(options) { debug("Creating B2B Airspace client ..."); const config = prepareConfig(options); await download(config); const client = await getAirspaceClient(config); debug("Successfully created B2B Airspace client"); return client; } /** * Factory to create a standalone client for the Flight domain. * * @param options - Configuration options for the client. See {@link CreateB2BClientOptions}. * @returns The initialized {@link FlightService} instance. */ async function createFlightClient(options) { debug("Creating B2B Flight client ..."); const config = prepareConfig(options); await download(config); const client = await getFlightClient(config); debug("Successfully created B2B Flight client"); return client; } /** * Factory to create a standalone client for the Flow domain. * * @param options - Configuration options for the client. See {@link CreateB2BClientOptions}. * @returns The initialized {@link FlowService} instance. */ async function createFlowClient(options) { debug("Creating B2B Flow client ..."); const config = prepareConfig(options); await download(config); const client = await getFlowClient(config); debug("Successfully created B2B Flow client"); return client; } /** * Factory to create a standalone client for the GeneralInformation domain. * * @param options - Configuration options for the client. See {@link CreateB2BClientOptions}. * @returns The initialized {@link GeneralInformationService} instance. */ async function createGeneralInformationClient(options) { debug("Creating B2B GeneralInformation client ..."); const config = prepareConfig(options); await download(config); const client = await getGeneralInformationClient(config); debug("Successfully created B2B GeneralInformation client"); return client; } function prepareConfig(options) { const config = { ...CONFIG_DEFAULTS, ...options }; assertValidConfig(config); debug("Config is %o", obfuscate(config)); return config; } //#endregion export { createAirspaceClient, createB2BClient, createFlightClient, createFlowClient, createGeneralInformationClient }; //# sourceMappingURL=createB2BClient.mjs.map