UNPKG

@mojaloop/ml-schema-transformer-lib

Version:
373 lines (356 loc) 12.5 kB
import { ContextLogger } from '@mojaloop/central-services-logger/src/contextLogger'; import { TransformDefinition, Options, State, Transformer, AsyncTransformer } from './map-transform.mjs'; /***** License -------------- Copyright © 2020-2025 Mojaloop Foundation The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Contributors -------------- This is the official list of the Mojaloop project contributors for this file. Names of the original copyright holders (individuals or organizations) should be listed with a '*' in the first column. People who have contributed from an organization can be listed under the organization that actually holds the copyright for their contributions (see the Mojaloop Foundation for an example). Those individuals should have their names indented and be marked with a '-'. Email address can be added optionally within square brackets <email>. * Mojaloop Foundation - Name Surname <name.surname@mojaloop.io> * Steven Oderayi <steven.oderayi@infitx.com> -------------- ******/ declare const isContextLogger: (logger: ContextLogger) => logger is ContextLogger; declare const TypeGuards: { FSPIOP: { parties: { put: { isSource: (source: FspiopPutPartiesSource) => source is FspiopPutPartiesSource; }; putError: { isSource: (source: FspiopPutPartiesErrorSource) => source is FspiopPutPartiesErrorSource; }; }; quotes: { post: { isSource: (source: FspiopSource) => source is FspiopSource; }; put: { isSource: (source: FspiopPutQuotesSource) => source is FspiopPutQuotesSource; }; putError: { isSource: (source: FspiopSource) => source is FspiopSource; }; }; transfers: { post: { isSource: (source: FspiopSource) => source is FspiopSource; }; patch: { isSource: (source: FspiopSource) => source is FspiopSource; }; put: { isSource: (source: FspiopSource) => source is FspiopSource; }; putError: { isSource: (source: FspiopSource) => source is FspiopSource; }; }; fxQuotes: { post: { isSource: (source: FspiopSource) => source is FspiopSource; }; put: { isSource: (source: FspiopSource) => source is FspiopSource; }; putError: { isSource: (source: FspiopSource) => source is FspiopSource; }; }; fxTransfers: { post: { isSource: (source: FspiopSource) => source is FspiopSource; }; patch: { isSource: (source: FspiopSource) => source is FspiopSource; }; put: { isSource: (source: FspiopSource) => source is FspiopSource; }; putError: { isSource: (source: FspiopSource) => source is FspiopSource; }; }; }; FSPIOPISO20022: { parties: { put: { isSource: (source: IsoSource) => source is IsoSource; }; putError: { isSource: (source: IsoSource) => source is IsoSource; }; }; quotes: { post: { isSource: (source: IsoSource) => source is IsoSource; }; put: { isSource: (source: IsoSource) => source is IsoSource; }; putError: { isSource: (source: IsoSource) => source is IsoSource; }; }; transfers: { post: { isSource: (source: IsoSource) => source is IsoSource; }; patch: { isSource: (source: IsoSource) => source is IsoSource; }; put: { isSource: (source: IsoSource) => source is IsoSource; }; putError: { isSource: (source: IsoSource) => source is IsoSource; }; }; fxQuotes: { post: { isSource: (source: IsoSource) => source is IsoSource; }; put: { isSource: (source: IsoSource) => source is IsoSource; }; putError: { isSource: (source: IsoSource) => source is IsoSource; }; }; fxTransfers: { post: { isSource: (source: IsoSource) => source is IsoSource; }; patch: { isSource: (source: IsoSource) => source is IsoSource; }; put: { isSource: (source: IsoSource) => source is IsoSource; }; putError: { isSource: (source: IsoSource) => source is IsoSource; }; }; }; }; /***** License -------------- Copyright © 2020-2025 Mojaloop Foundation The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Contributors -------------- This is the official list of the Mojaloop project contributors for this file. Names of the original copyright holders (individuals or organizations) should be listed with a '*' in the first column. People who have contributed from an organization can be listed under the organization that actually holds the copyright for their contributions (see the Mojaloop Foundation for an example). Those individuals should have their names indented and be marked with a '-'. Email address can be added optionally within square brackets <email>. * Mojaloop Foundation - Name Surname <name.surname@mojaloop.io> * Steven Oderayi <steven.oderayi@infitx.com> -------------- ******/ declare enum HTTP_METHOD { GET = "GET", PUT = "PUT", POST = "POST", DELETE = "DELETE", PATCH = "PATCH" } declare enum API_NAME { FSPIOP = "fspiop", ISO20022 = "iso" } interface ITransformer { transform(source: Partial<Source>, { mapperOptions }: { mapperOptions?: State; }): Promise<Partial<Target>>; } type FacadeOptions = { overrideMapping?: TransformDefinition; mapTransformOptions?: Options; mapperOptions?: State; validateTarget?: boolean; }; type FspiopFacadeOptions = FacadeOptions & { unrollExtensions?: boolean; }; type FspiopFacadeFunction = (source: Source, options: FacadeOptions) => Promise<IsoTarget>; type IsoFacadeOptions = FacadeOptions & { rollUpUnmappedAsExtensions?: boolean; }; type IsoFacadeFunction = (source: IsoSource, options: FacadeOptions) => Promise<Partial<Target>>; type TransformFunctionOptions = { mapping: TransformDefinition; mapperOptions?: State; mapTransformOptions?: Options; logger: ContextLogger; }; type CreateTransformerOptions = { mapTransformOptions?: Options; }; declare enum ID_GENERATOR_TYPE { ulid = "ulid", uuid = "uuid" } interface ICustomTransforms { [key: string | symbol]: Transformer | AsyncTransformer; } type ConfigOptions = { logger?: ContextLogger; isTestingMode?: boolean; unrollExtensions?: boolean; rollUpUnmappedAsExtensions?: boolean; validateTarget?: boolean; }; type Headers = { 'fspiop-source': string; 'fspiop-destination': string; }; type Params = { Type?: string; ID?: string; SubId?: string; }; type PartyIdParamsSource = { Type: string; ID: string; SubId?: string; IdPath?: string; } | { Type?: string; ID?: string; SubId?: string; IdPath: string; }; type PartyIdParamsTarget = { Type: string; ID: string; SubId?: string; }; type Source = { body: GenericObject; headers?: Headers; params?: Partial<Params>; }; type Target = { body: GenericObject; headers: Headers; params: Params; }; type FspiopSource = Pick<Source, 'body'>; type FspiopTarget = Pick<Target, 'body'>; type FspiopPutQuotesSource = { body: GenericObject; params: Pick<Params, 'ID'>; $context?: { isoPostQuote: GenericObject; }; headers?: Headers; } | { body: GenericObject; params: Pick<Params, 'ID'>; headers: Headers; $context?: { isoPostQuote: GenericObject; }; }; type FspiopPutQuotesTarget = { body: GenericObject; headers: Headers; params: Pick<Params, 'ID'>; }; type FspiopPutPartiesSource = { body: GenericObject; headers: Headers; params: PartyIdParamsSource; }; type FspiopPutPartiesTarget = { body: GenericObject; headers: Headers; params: PartyIdParamsTarget; }; type FspiopPutPartiesErrorSource = { body: GenericObject; headers: Headers; params: PartyIdParamsSource; }; type FspiopPutPartiesErrorTarget = { body: GenericObject; headers: Headers; params: PartyIdParamsTarget; }; type FspiopPostTransfersSource = { body: GenericObject; $context?: { isoPostQuoteResponse: GenericObject; }; headers?: Headers; } | { body: GenericObject; params: Pick<Params, 'ID'>; headers: Headers; $context?: { isoPostQuoteResponse: GenericObject; }; }; type IsoSource = Pick<Source, 'body'>; type IsoTarget = Pick<Target, 'body'>; type GenericObject = Record<string, any>; type Primitive = string | number | boolean; type PipelineStep = ({ source, target, options, logger }: { source: GenericObject; target: GenericObject; options: GenericObject; logger: ContextLogger; }) => GenericObject; type PipelineStepsConfig = { [key: string]: GenericObject; }; type PipelineOptions = { pipelineSteps: PipelineStep[]; logger: ContextLogger; [key: string]: any; }; type Json = string | number | boolean | Json[] | { [key: string]: Json; }; type LogContext = Json | string | null; declare const logLevelsMap: { readonly error: "error"; readonly warn: "warn"; readonly info: "info"; readonly verbose: "verbose"; readonly debug: "debug"; readonly silly: "silly"; readonly audit: "audit"; readonly trace: "trace"; readonly perf: "perf"; }; declare const logLevelValues: ("info" | "error" | "warn" | "verbose" | "debug" | "silly" | "audit" | "trace" | "perf")[]; type LogLevel = (typeof logLevelValues)[number]; type Request = { path: string; method: HTTP_METHOD; headers: GenericObject; body: GenericObject; query: GenericObject; }; export { API_NAME, type ConfigOptions, type CreateTransformerOptions, type FacadeOptions, type FspiopFacadeFunction, type FspiopFacadeOptions, type FspiopPostTransfersSource, type FspiopPutPartiesErrorSource, type FspiopPutPartiesErrorTarget, type FspiopPutPartiesSource, type FspiopPutPartiesTarget, type FspiopPutQuotesSource, type FspiopPutQuotesTarget, type FspiopSource, type FspiopTarget, type GenericObject, HTTP_METHOD, type Headers, type ICustomTransforms, ID_GENERATOR_TYPE, type ITransformer, type IsoFacadeFunction, type IsoFacadeOptions, type IsoSource, type IsoTarget, type Json, type LogContext, type LogLevel, type Params, type PartyIdParamsSource, type PartyIdParamsTarget, type PipelineOptions, type PipelineStep, type PipelineStepsConfig, type Primitive, type Request, type Source, type Target, type TransformFunctionOptions, TypeGuards, isContextLogger, logLevelValues, logLevelsMap };