@dgac/nmb2b-client
Version:
EUROCONTROL Network Manager B2B SOAP client
1 lines • 6.1 kB
Source Map (JSON)
{"version":3,"sources":["../../src/utils/index.ts","../../src/utils/NMB2BError.ts","../../src/utils/extractReferenceLocation.ts"],"sourcesContent":["export { NMB2BError } from './NMB2BError';\nexport { extractReferenceLocation } from './extractReferenceLocation';\n","import type { B2B_Error, Reply, ReplyStatus } from '../Common/types';\n\n/**\n * Represents an error response received from NM B2B\n */\nexport class NMB2BError extends Error {\n /**\n * UTC time at which the request was received at NM.\n *\n * Always set when an XML reply is returned, regardless of the possible exceptions that occurred within the request processing.\n */\n declare requestReceptionTime?: Date;\n\n /**\n * Identification of the request. This id is not unique across time: the request is uniquely identified via two attributes: `requestReceptionTime` and `requestId`.\n *\n * Always set when an XML reply is returned, regardless of the possible exceptions that occurred within the request processing.\n */\n declare requestId?: string;\n\n /**\n * UTC time at which NM has sent the reply.\n *\n * Always set when an XML reply is returned, regardless of the possible exceptions that occurred within the request processing.\n */\n declare sendTime?: Date;\n\n /**\n * Status code explaining the error.\n */\n declare status: Exclude<ReplyStatus, 'OK'>;\n\n /**\n * Contains the input validation errors, if any.\n * Set to null if the request successfully passed input validations (i.e. status is not set to `INVALID_INPUT`).\n */\n declare inputValidationErrors?: Array<B2B_Error>;\n\n /**\n * Contains the output validation errors, if any.\n * Set to null if the request successfully passed output validations (i.e. status is not set to `INVALID_OUTPUT`).\n */\n declare outputValidationErrors?: Array<B2B_Error>;\n\n /**\n * Warnings, if any\n */\n declare warnings?: Array<B2B_Error>;\n\n /**\n * Describes an error caused by a SLA violation.\n *\n */\n declare slaError?: B2B_Error;\n\n declare reason?: string;\n\n constructor({\n reply,\n }: {\n reply: Reply & { status: Exclude<ReplyStatus, 'OK'> };\n }) {\n super();\n\n if (reply.requestId) {\n this.requestId = reply.requestId;\n }\n\n if (reply.requestReceptionTime) {\n this.requestReceptionTime = reply.requestReceptionTime;\n }\n\n if (reply.sendTime) {\n this.sendTime = reply.sendTime;\n }\n\n if (reply.inputValidationErrors) {\n this.inputValidationErrors = reply.inputValidationErrors;\n }\n\n if (reply.warnings) {\n this.warnings = reply.warnings;\n }\n\n if (reply.slaError) {\n this.slaError = reply.slaError;\n }\n\n if (reply.reason) {\n this.reason = reply.reason;\n }\n this.status = reply.status;\n this.message = this.status;\n\n if (this.reason) {\n this.message = `${this.message}: ${this.reason}`;\n }\n }\n}\n","import type {\n ReferenceLocation,\n WithReferenceLocationOnPrefixOptional,\n WithReferenceLocationOnPrefix,\n} from '../Airspace/types';\n\nconst keys = [\n 'ReferenceLocationAirspace',\n 'ReferenceLocationAerodrome',\n 'ReferenceLocationAerodromeSet',\n 'ReferenceLocationDbePoint',\n 'ReferenceLocationPublishedPoint',\n] as const;\n\n/**\n * Extract a reference location with a given key-prefix from a reply object.\n * @param prefix Prefix of the keys of the reference location\n * @param input NMB2B object\n *\n *\n * @example\n * ```typescript\n * const input = {\n * 'protectedLocation-ReferenceLocationAirspace': { type: 'AIRSPACE', id: 'LFEEKR' },\n * regulationId: 'FOOBAR',\n * };\n *\n * const location = extractReferenceLocation('protectedLocation', input);\n * // { type: 'AIRSPACE', id: 'LFEEKR' }\n * ```\n */\nexport function extractReferenceLocation<\n const TPrefix extends string,\n TInput extends WithReferenceLocationOnPrefix<TPrefix>,\n>(prefix: TPrefix, input: TInput): ReferenceLocation;\n\n/**\n * Extract a reference location with a given key-prefix from a reply object.\n * @param prefix Prefix of the keys of the reference location\n * @param input NMB2B object\n *\n *\n * @example\n * ```typescript\n * const input = {\n * 'protectedLocation-ReferenceLocationAirspace': { type: 'AIRSPACE', id: 'LFEEKR' },\n * regulationId: 'FOOBAR',\n * };\n *\n * const location = extractReferenceLocation('protectedLocation', input);\n * // { type: 'AIRSPACE', id: 'LFEEKR' }\n * ```\n */\nexport function extractReferenceLocation<\n const TPrefix extends string,\n TInput extends undefined | WithReferenceLocationOnPrefixOptional<TPrefix>,\n>(prefix: TPrefix, input: TInput): undefined | ReferenceLocation;\n\nexport function extractReferenceLocation<\n const TPrefix extends string,\n TInput extends\n | undefined\n | WithReferenceLocationOnPrefixOptional<TPrefix>\n | WithReferenceLocationOnPrefix<TPrefix>,\n>(prefix: TPrefix, input: TInput): ReferenceLocation | undefined {\n if (!input) {\n return;\n }\n\n for (const k of keys) {\n const key = `${prefix}-${k}` as const;\n\n if (key in input) {\n return input[key as keyof TInput];\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKO,IAAM,aAAN,cAAyB,MAAM;AAAA,EAoDpC,YAAY;AAAA,IACV;AAAA,EACF,GAEG;AACD,UAAM;AAEN,QAAI,MAAM,WAAW;AACnB,WAAK,YAAY,MAAM;AAAA,IACzB;AAEA,QAAI,MAAM,sBAAsB;AAC9B,WAAK,uBAAuB,MAAM;AAAA,IACpC;AAEA,QAAI,MAAM,UAAU;AAClB,WAAK,WAAW,MAAM;AAAA,IACxB;AAEA,QAAI,MAAM,uBAAuB;AAC/B,WAAK,wBAAwB,MAAM;AAAA,IACrC;AAEA,QAAI,MAAM,UAAU;AAClB,WAAK,WAAW,MAAM;AAAA,IACxB;AAEA,QAAI,MAAM,UAAU;AAClB,WAAK,WAAW,MAAM;AAAA,IACxB;AAEA,QAAI,MAAM,QAAQ;AAChB,WAAK,SAAS,MAAM;AAAA,IACtB;AACA,SAAK,SAAS,MAAM;AACpB,SAAK,UAAU,KAAK;AAEpB,QAAI,KAAK,QAAQ;AACf,WAAK,UAAU,GAAG,KAAK,OAAO,KAAK,KAAK,MAAM;AAAA,IAChD;AAAA,EACF;AACF;;;AC5FA,IAAM,OAAO;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AA8CO,SAAS,yBAMd,QAAiB,OAA8C;AAC/D,MAAI,CAAC,OAAO;AACV;AAAA,EACF;AAEA,aAAW,KAAK,MAAM;AACpB,UAAM,MAAM,GAAG,MAAM,IAAI,CAAC;AAE1B,QAAI,OAAO,OAAO;AAChB,aAAO,MAAM,GAAmB;AAAA,IAClC;AAAA,EACF;AACF;","names":[]}