UNPKG

@dgac/nmb2b-client

Version:

EUROCONTROL Network Manager B2B SOAP client

1 lines 6.39 kB
{"version":3,"file":"createB2BClient.mjs","names":["downloadWSDLIfNeeded"],"sources":["../src/createB2BClient.ts"],"sourcesContent":["import type { SetOptional } from 'type-fest';\nimport type { AirspaceService } from './Airspace/index.js';\nimport { getAirspaceClient } from './Airspace/index.js';\nimport { assertValidConfig, obfuscate, type Config } from './config.js';\nimport type { B2BFlavour } from './constants.js';\nimport type { FlightService } from './Flight/index.js';\nimport { getFlightClient } from './Flight/index.js';\nimport type { FlowService } from './Flow/index.js';\nimport { getFlowClient } from './Flow/index.js';\nimport type { GeneralInformationService } from './GeneralInformation/index.js';\nimport { getGeneralInformationClient } from './GeneralInformation/index.js';\nimport { createDebugLogger } from './utils/debug.js';\nimport { download as downloadWSDLIfNeeded } from './utils/xsd/index.js';\n\nconst debug = createDebugLogger();\n\n/**\n * Main client object grouping all available B2B domains (Airspace, Flight, Flow, GeneralInformation).\n */\nexport interface B2BClient {\n Airspace: AirspaceService;\n Flight: FlightService;\n Flow: FlowService;\n GeneralInformation: GeneralInformationService;\n}\n\nexport type {\n AirspaceService,\n FlightService,\n FlowService,\n GeneralInformationService,\n};\n\nconst CONFIG_DEFAULTS = {\n flavour: 'OPS' as B2BFlavour,\n XSD_PATH: '/tmp/b2b-xsd',\n hooks: [],\n} satisfies Partial<Config>;\n\n/**\n * Options for initializing the B2B client.\n */\nexport type CreateB2BClientOptions = SetOptional<\n Config,\n keyof typeof CONFIG_DEFAULTS\n>;\n\n/**\n * Main factory to create a fully initialized B2B client.\n * Handles WSDL downloading (if needed) and initializes all sub-services.\n *\n * @param options - Configuration options for the client. See {@link CreateB2BClientOptions}.\n * @returns The initialized {@link B2BClient} instance.\n */\nexport async function createB2BClient(\n options: CreateB2BClientOptions,\n): Promise<B2BClient> {\n debug('Creating B2B Client ...');\n\n const config = prepareConfig(options);\n\n await downloadWSDLIfNeeded(config);\n\n const [Airspace, Flight, Flow, GeneralInformation] = await Promise.all([\n getAirspaceClient(config),\n getFlightClient(config),\n getFlowClient(config),\n getGeneralInformationClient(config),\n ]);\n\n debug('Successfully created B2B Client');\n\n return {\n Airspace,\n Flight,\n Flow,\n GeneralInformation,\n };\n}\n\n/**\n * Factory to create a standalone client for the Airspace domain.\n *\n * @param options - Configuration options for the client. See {@link CreateB2BClientOptions}.\n * @returns The initialized {@link AirspaceService} instance.\n */\nexport async function createAirspaceClient(\n options: CreateB2BClientOptions,\n): Promise<AirspaceService> {\n debug('Creating B2B Airspace client ...');\n\n const config = prepareConfig(options);\n\n await downloadWSDLIfNeeded(config);\n\n const client = await getAirspaceClient(config);\n\n debug('Successfully created B2B Airspace client');\n\n return client;\n}\n\n/**\n * Factory to create a standalone client for the Flight domain.\n *\n * @param options - Configuration options for the client. See {@link CreateB2BClientOptions}.\n * @returns The initialized {@link FlightService} instance.\n */\nexport async function createFlightClient(\n options: CreateB2BClientOptions,\n): Promise<FlightService> {\n debug('Creating B2B Flight client ...');\n\n const config = prepareConfig(options);\n\n await downloadWSDLIfNeeded(config);\n\n const client = await getFlightClient(config);\n\n debug('Successfully created B2B Flight client');\n\n return client;\n}\n\n/**\n * Factory to create a standalone client for the Flow domain.\n *\n * @param options - Configuration options for the client. See {@link CreateB2BClientOptions}.\n * @returns The initialized {@link FlowService} instance.\n */\nexport async function createFlowClient(\n options: CreateB2BClientOptions,\n): Promise<FlowService> {\n debug('Creating B2B Flow client ...');\n\n const config = prepareConfig(options);\n\n await downloadWSDLIfNeeded(config);\n\n const client = await getFlowClient(config);\n\n debug('Successfully created B2B Flow client');\n\n return client;\n}\n\n/**\n * Factory to create a standalone client for the GeneralInformation domain.\n *\n * @param options - Configuration options for the client. See {@link CreateB2BClientOptions}.\n * @returns The initialized {@link GeneralInformationService} instance.\n */\nexport async function createGeneralInformationClient(\n options: CreateB2BClientOptions,\n): Promise<GeneralInformationService> {\n debug('Creating B2B GeneralInformation client ...');\n\n const config = prepareConfig(options);\n\n await downloadWSDLIfNeeded(config);\n\n const client = await getGeneralInformationClient(config);\n\n debug('Successfully created B2B GeneralInformation client');\n\n return client;\n}\n\nfunction prepareConfig(options: CreateB2BClientOptions): Config {\n const config = { ...CONFIG_DEFAULTS, ...options };\n\n assertValidConfig(config);\n\n debug('Config is %o', obfuscate(config));\n\n return config;\n}\n"],"mappings":";;;;;;;;;AAcA,MAAM,QAAQ,mBAAmB;AAmBjC,MAAM,kBAAkB;CACtB,SAAS;CACT,UAAU;CACV,OAAO,EAAE;CACV;;;;;;;;AAiBD,eAAsB,gBACpB,SACoB;AACpB,OAAM,0BAA0B;CAEhC,MAAM,SAAS,cAAc,QAAQ;AAErC,OAAMA,SAAqB,OAAO;CAElC,MAAM,CAAC,UAAU,QAAQ,MAAM,sBAAsB,MAAM,QAAQ,IAAI;EACrE,kBAAkB,OAAO;EACzB,gBAAgB,OAAO;EACvB,cAAc,OAAO;EACrB,4BAA4B,OAAO;EACpC,CAAC;AAEF,OAAM,kCAAkC;AAExC,QAAO;EACL;EACA;EACA;EACA;EACD;;;;;;;;AASH,eAAsB,qBACpB,SAC0B;AAC1B,OAAM,mCAAmC;CAEzC,MAAM,SAAS,cAAc,QAAQ;AAErC,OAAMA,SAAqB,OAAO;CAElC,MAAM,SAAS,MAAM,kBAAkB,OAAO;AAE9C,OAAM,2CAA2C;AAEjD,QAAO;;;;;;;;AAST,eAAsB,mBACpB,SACwB;AACxB,OAAM,iCAAiC;CAEvC,MAAM,SAAS,cAAc,QAAQ;AAErC,OAAMA,SAAqB,OAAO;CAElC,MAAM,SAAS,MAAM,gBAAgB,OAAO;AAE5C,OAAM,yCAAyC;AAE/C,QAAO;;;;;;;;AAST,eAAsB,iBACpB,SACsB;AACtB,OAAM,+BAA+B;CAErC,MAAM,SAAS,cAAc,QAAQ;AAErC,OAAMA,SAAqB,OAAO;CAElC,MAAM,SAAS,MAAM,cAAc,OAAO;AAE1C,OAAM,uCAAuC;AAE7C,QAAO;;;;;;;;AAST,eAAsB,+BACpB,SACoC;AACpC,OAAM,6CAA6C;CAEnD,MAAM,SAAS,cAAc,QAAQ;AAErC,OAAMA,SAAqB,OAAO;CAElC,MAAM,SAAS,MAAM,4BAA4B,OAAO;AAExD,OAAM,qDAAqD;AAE3D,QAAO;;AAGT,SAAS,cAAc,SAAyC;CAC9D,MAAM,SAAS;EAAE,GAAG;EAAiB,GAAG;EAAS;AAEjD,mBAAkB,OAAO;AAEzB,OAAM,gBAAgB,UAAU,OAAO,CAAC;AAExC,QAAO"}