UNPKG

33.2 kBTypeScriptView Raw
1import http from 'http'
2import { KeyObject } from 'tls'
3declare namespace SDKStandardComponents {
4 /* Base Mojaloop Types */
5
6 // Ref: https://github.com/mojaloop/api-snippets/blob/master/v1.0/openapi3/schemas/Currency.yaml
7 type TCurrency = 'AED' | 'AFN' | 'ALL' | 'AMD' | 'ANG' | 'AOA' | 'ARS' | 'AUD' | 'AWG' | 'AZN' |
8 'BAM' | 'BBD' | 'BDT' | 'BGN' | 'BHD' | 'BIF' | 'BMD' | 'BND' | 'BOB' | 'BRL' | 'BSD' | 'BTN' | 'BWP' | 'BYN' | 'BZD' |
9 'CAD' | 'CDF' | 'CHF' | 'CLP' | 'CNY' | 'COP' | 'CRC' | 'CUC' | 'CUP' | 'CVE' | 'CZK' |
10 'DJF' | 'DKK' | 'DOP' | 'DZD' |
11 'EGP' | 'ERN' | 'ETB' | 'EUR' |
12 'FJD' | 'FKP' |
13 'GBP' | 'GEL' | 'GGP' | 'GHS' | 'GIP' | 'GMD' | 'GNF' | 'GTQ' | 'GYD' |
14 'HKD' | 'HNL' | 'HRK' | 'HTG' | 'HUF' |
15 'IDR' | 'ILS' | 'IMP' | 'INR' | 'IQD' | 'IRR' | 'ISK' |
16 'JEP' | 'JMD' | 'JOD' | 'JPY' |
17 'KES' | 'KGS' | 'KHR' | 'KMF' | 'KPW' | 'KRW' | 'KWD' | 'KYD' | 'KZT' |
18 'LAK' | 'LBP' | 'LKR' | 'LRD' | 'LSL' | 'LYD' |
19 'MAD' | 'MDL' | 'MGA' | 'MKD' | 'MMK' | 'MNT' | 'MOP' | 'MRO' | 'MUR' | 'MVR' | 'MWK' | 'MXN' | 'MYR' | 'MZN' |
20 'NAD' | 'NGN' | 'NIO' | 'NOK' | 'NPR' | 'NZD' |
21 'OMR' |
22 'PAB' | 'PEN' | 'PGK' | 'PHP' | 'PKR' | 'PLN' | 'PYG' |
23 'QAR' |
24 'RON' | 'RSD' | 'RUB' | 'RWF' |
25 'SAR' | 'SBD' | 'SCR' | 'SDG' | 'SEK' | 'SGD' | 'SHP' | 'SLL' | 'SOS' | 'SPL' | 'SRD' | 'STD' | 'SVC' | 'SYP' | 'SZL' |
26 'THB' | 'TJS' | 'TMT' | 'TND' | 'TOP' | 'TRY' | 'TTD' | 'TVD' | 'TWD' | 'TZS' |
27 'UAH' | 'UGX' | 'USD' | 'UYU' | 'UZS' |
28 'VEF' | 'VND' | 'VUV' |
29 'WST' |
30 'XAF' | 'XCD' | 'XDR' | 'XOF' | 'XPF' |
31 'YER' |
32 'ZAR' | 'ZMW' | 'ZWD';
33
34 type TAuthChannel = 'WEB' | 'OTP';
35
36 // Ref: https://github.com/mojaloop/api-snippets/blob/master/v1.0/openapi3/schemas/Party.yaml
37 type TParty = {
38 partyIdInfo: {
39 fspId: string;
40 partyIdType: string;
41 partyIdentifier: string;
42 partySubIdentifier?: string;
43 }
44 merchantClassificationCode?: string;
45 name?: string;
46 personalInfo?: {
47 complexName?: {
48 firstName?: string;
49 middleName?: string;
50 lastName?: string;
51 }
52 dateOfBirth?: string
53 };
54 };
55
56 // Ref: https://github.com/mojaloop/api-snippets/blob/master/v1.0/openapi3/schemas/Money.yaml
57 type TMoney = {
58 amount: string;
59 currency: TCurrency;
60 };
61
62 // Ref: https://github.com/mojaloop/api-snippets/blob/master/v1.0/openapi3/schemas/GeoCode.yaml
63 type TGeoCode = {
64 latitude: string;
65 longitude: string;
66 }
67
68 // Ref: https://github.com/mojaloop/api-snippets/blob/master/v1.0/openapi3/schemas/ExtensionList.yaml
69 type TExtensionList = {
70 extension: Array<{
71 key: string;
72 value: string;
73 }>
74 }
75
76 // Ref: https://github.com/mojaloop/api-snippets/blob/master/v1.0/openapi3/schemas/QuotesIDPutResponse.yaml
77 type TQuotesIDPutResponse = {
78 transferAmount: TMoney;
79 expiration: Date;
80 ilpPacket: string;
81 condition: string;
82 payeeReceiveAmount?: TMoney;
83 payeeFspFee?: TMoney;
84 payeeFspCommission?: TMoney;
85 geoCode?: TGeoCode;
86 extensionList?: TExtensionList
87 }
88
89 // Ref: https://github.com/mojaloop/api-snippets/blob/master/v1.0/openapi3/schemas/ErrorInformationObject.yaml
90 type TErrorInformationObject = {
91 errorInformation: TErrorInformation;
92 }
93
94 // Ref: https://github.com/mojaloop/api-snippets/blob/master/v1.0/openapi3/schemas/ErrorInformation.yaml
95 type TErrorInformation = {
96 errorCode: string;
97 errorDescription: string;
98 extensionList?: TExtensionList;
99 }
100
101 type TCredential = {
102 id: string | null;
103 credentialType: 'FIDO';
104 status: 'PENDING' | 'VERIFIED';
105 challenge: {
106 payload: string;
107 signature: string | null;
108 },
109 payload: string | null;
110 }
111
112 type TCredentialScope = {
113 actions: string[];
114 accountId: string;
115 }
116
117 // Ref: https://github.com/mojaloop/api-snippets/blob/master/v1.0/openapi3/schemas/AmountType.yaml
118 enum TAmountType {
119 SEND = 'SEND',
120 RECEIVE = 'RECEIVE',
121 }
122
123 /* hashmap of versions of various resources */
124 type TResourceVersions = {
125 [resource: string]: {
126 contentVersion: string,
127 acceptVersion: string
128 }
129 }
130
131 /* Base Request Types */
132 type GenericRequestResponse = {
133 statusCode: number;
134 headers: any;
135 data: Buffer;
136 };
137
138 type MojaloopRequestResponse = undefined;
139 interface BaseRequestTLSConfig {
140 mutualTLS: {
141 enabled: boolean;
142 };
143 creds: {
144 ca: string | Buffer | Array<string | Buffer>;
145 cert: string | Buffer | Array<string | Buffer>;
146 key?: string | Buffer | Array<Buffer | KeyObject>;
147 }
148 }
149
150 type BaseRequestConfigType = {
151 logger: Logger.Logger;
152 tls: BaseRequestTLSConfig;
153 dfspId: string;
154 jwsSign: boolean;
155 jwsSignPutParties?: boolean;
156 jwsSigningKey?: Buffer;
157 wso2Auth?: object;
158 alsEndpoint?: string;
159 peerEndpoint?: string;
160 quotesEndpoint?: string;
161 bulkQuotesEndpoint?: string;
162 transfersEndpoint?: string;
163 bulkTransfersEndpoint?: string;
164 transactionRequestsEndpoint?: string;
165 thirdpartyRequestsEndpoint?: string;
166 resourceVersions?: TResourceVersions;
167 }
168
169 /* Individual Request Types */
170 type PutConsentsRequest = {
171 requestId: string;
172 initiatorId: string;
173 participantId: string;
174 scopes: Array<{
175 accountId: string;
176 actions: Array<string>;
177 }>;
178 credential: TCredential;
179 }
180
181 type PostConsentsRequest = {
182 id: string;
183 requestId: string;
184 initiatorId: string;
185 participantId: string;
186 scopes: TCredentialScope[];
187 credential?: TCredential;
188 }
189
190 type PutConsentRequestsRequest = {
191 initiatorId: string;
192 authChannels: TAuthChannel[];
193 scopes: TCredentialScope[];
194 callbackUri: string;
195 authUri: string | null;
196 authToken: string;
197 }
198
199 type PostConsentRequestsRequest = {
200 id: string;
201 initiatorId: string;
202 authChannels: TAuthChannel[];
203 scopes: TCredentialScope[];
204 callbackUri: string;
205 }
206
207 type PostAuthorizationsRequest = {
208 transactionRequestId: string;
209 authenticationType: 'U2F';
210 retriesLeft: string;
211 amount: TMoney;
212 transactionId: string;
213 quote: TQuotesIDPutResponse;
214 }
215
216 type AuthenticationType = 'OTP' | 'QRCODE' | 'U2F'
217
218 type AuthenticationValue = {
219 pinValue: string;
220 counter: string;
221 }
222
223 type AuthenticationInfo = {
224 authentication: AuthenticationType;
225 authenticationValue: AuthenticationValue | string;
226 }
227
228 type AuthorizationResponse = 'ENTERED' | 'REJECTED' | 'RESEND';
229
230 type PutAuthorizationRequest = {
231 authenticationInfo: AuthenticationInfo;
232 responseType: AuthorizationResponse;
233 }
234
235 type TransactionType = {
236 scenario: string;
237 initiator: string;
238 initiatorType: string;
239 }
240 type PostThirdPartyRequestTransactionsRequest = {
241 transactionRequestId: string;
242 sourceAccountId: string;
243 consentId: string;
244 payee: TParty;
245 payer: TParty;
246 amountType: TAmountType;
247 amount: TMoney;
248 transactionType: TransactionType;
249 expiration: string;
250 }
251
252 type PutThirdpartyRequestsTransactionsAuthorizationsRequest = {
253 challenge: string;
254 consentId: string;
255 sourceAccountId: string;
256 status: 'PENDING' | 'VERIFIED';
257 value: string;
258 }
259
260 type PatchConsentsRequest = {
261 status: 'REVOKED';
262 revokedAt: string;
263 }
264
265 class BaseRequests {
266 constructor(config: BaseRequestConfigType)
267 }
268
269 type PutThirdpartyRequestsTransactionsRequest = {
270 transactionRequestId: string;
271 transactionRequestState: 'RECEIVED' | 'PENDING' | 'ACCEPTED' | 'REJECTED';
272 }
273
274 type PostThirdpartyRequestsTransactionsAuthorizationsRequest = {
275 challenge: string;
276 consentId: string;
277 sourceAccountId: string;
278 status: 'PENDING' | 'VERIFIED';
279 value: string;
280 }
281
282 type PostQuoteRequest = {
283 quoteId: string;
284 transactionId: string;
285 transactionRequestId: string;
286 payee: TParty;
287 payer: TParty;
288 amountType: TAmountType;
289 amount: TMoney;
290 transactionType: TransactionType;
291 note: string;
292 }
293
294 /**
295 * @class ThirdpartyRequests
296 * @description Client library for making outbound Mojaloop requests
297 * for 3rd party functions (e.g. PISP use cases)
298 */
299 class ThirdpartyRequests extends BaseRequests {
300 /**
301 * @function patchConsents
302 * @description Executes a `PATCH /consents/{id}` request.
303 * @param {string} consentId The `id` of the consent object to be updated
304 * @param {PatchConsentsRequest} consentBody The body of the consent object
305 * @param {string} destParticipantId The id of the destination participant
306 */
307 patchConsents(
308 consentId: string,
309 consentBody: PatchConsentsRequest,
310 destParticipantId: string
311 ): Promise<GenericRequestResponse | MojaloopRequestResponse>;
312
313 /**
314 * @function putConsents
315 * @description Executes a `PUT /consents/{id}` request.
316 * @param {string} consentId The `id` of the consent object to be updated
317 * @param {PutConsentsRequest} consentBody The body of the consent object
318 * @param {string} destParticipantId The id of the destination participant
319 */
320 putConsents(
321 consentId: string,
322 consentBody: PutConsentsRequest,
323 destParticipantId: string
324 ): Promise<GenericRequestResponse | MojaloopRequestResponse>;
325
326 /**
327 * @function putConsents
328 * @description Executes a `PUT /consents/{id}/error` request.
329 * @param {string} consentId The `id` of the consent object to be updated
330 * @param {PutConsentsRequest} consentBody The body of the consent object
331 * @param {string} destParticipantId The id of the destination participant
332 */
333 putConsentsError(
334 consentId: string,
335 consentBody: TErrorInformationObject,
336 destParticipantId: string
337 ): Promise<GenericRequestResponse | MojaloopRequestResponse>;
338
339 /**
340 * @function postConsents
341 * @description Executes a `POST /consents` request.
342 * @param {PostConsentsRequest} consentBody The body of the consent object
343 * @param {string} destParticipantId The id of the destination participant
344 */
345 postConsents(
346 consentBody: PostConsentsRequest,
347 destParticipantId: string
348 ): Promise<GenericRequestResponse | MojaloopRequestResponse>;
349
350 /**
351 * @function putConsentRequests
352 * @description Executes a `PUT /consentRequests/{id}` request.
353 * @param {string} consentRequestId The `id` of the consent requests object to be updated
354 * @param {PutConsentRequestsRequest} consentRequestBody The body of the consent requests object
355 * @param {string} destParticipantId The id of the destination participant
356 */
357 putConsentRequests(
358 consentRequestId: string,
359 consentRequestBody: PutConsentRequestsRequest,
360 destParticipantId: string
361 ): Promise<GenericRequestResponse | MojaloopRequestResponse>;
362
363 /**
364 * @function postConsentRequests
365 * @description Executes a `POST /consentRequests` request.
366 * @param {PostConsentRequestsRequest} consentRequestBody The body of the consent requests object
367 * @param {string} destParticipantId The id of the destination participant
368 */
369 postConsentRequests(
370 consentRequestBody: PostConsentRequestsRequest,
371 destParticipantId: string
372 ): Promise<GenericRequestResponse | MojaloopRequestResponse>;
373
374
375 /**
376 * @function postAuthorizations
377 * @description
378 * Executes a `POST /authorizations` request for the specified `transactionRequestId`
379 * @param {Object} authorizationBody The authorizationBody
380 * @param {string} destParticipantId The id of the destination participant, in this case, a PISP
381 * @returns {Promise<object>} JSON response body if one was received
382 */
383 postAuthorizations(
384 authorizationBody: PostAuthorizationsRequest,
385 destParticipantId: string
386 ): Promise<GenericRequestResponse | MojaloopRequestResponse>;
387
388 /**
389 * @function getThirdpartyRequestsTransactions
390 * @description
391 * Executes a `GET /thirdpartyRequests/transactions/{transactionRequestId}` request for the specified `transactionRequestId`
392 * @param {string} transactionRequestId The `id` of the transactionRequest/thirdpartyRequest
393 * @param {string} destParticipantId The `id` of the destination participant, in this case, a DFSP
394 * @returns {Promise<object>} JSON response body if one was received
395 */
396 getThirdpartyRequestsTransactions(
397 transactionRequestId: string,
398 destParticipantId: string
399 ): Promise<GenericRequestResponse | MojaloopRequestResponse>;
400
401 /**
402 * @function postThirdpartyRequestsTransactions
403 * @description
404 * Executes a `POST /thirdpartyRequests/transactions` request
405 * @param {Object} thirdpartyRequestsTransactionsBody The thirdpartyRequestsTransactionsBody
406 * @param {string} destParticipantId The id of the destination participant, in this case, a DFSP
407 * @returns {Promise<object>} JSON response body if one was received
408 */
409 postThirdpartyRequestsTransactions(
410 thirdpartyRequestsTransactionsBody: PostThirdPartyRequestTransactionsRequest,
411 destParticipantId: string
412 ): Promise<GenericRequestResponse | MojaloopRequestResponse>;
413
414 /**
415 * @function putThirdpartyRequestsTransactions
416 * @description
417 * Executes a `PUT /thirdpartyRequests/transactions/${transactionRequestId}` request
418 * @param {Object} thirdpartyRequestsTransactionsBody The thirdpartyRequestsTransactionsBody
419 * @param {string} transactionRequestId The `id` of the transactionRequest/thirdpartyRequest
420 * @param {string} destParticipantId The id of the destination participant, in this case, a DFSP
421 * @returns {Promise<object>} JSON response body if one was received
422 */
423 putThirdpartyRequestsTransactions(
424 thirdpartyRequestsTransactionsBody: PutThirdpartyRequestsTransactionsRequest,
425 transactionRequestId: string,
426 destParticipantId: string
427 ): Promise<GenericRequestResponse | MojaloopRequestResponse>;
428
429 /**
430 * @function putThirdpartyRequestsTransactionsError
431 * @description
432 * Executes a `PUT thirdpartyRequests/transactions/${transactionRequestId}/error` request
433 * @param {Object} thirdpartyRequestsTransactionsBody The thirdpartyRequestsTransactionsBody
434 * @param {string} transactionRequestId The `id` of the transactionRequest/thirdpartyRequest
435 * @param {string} destParticipantId The id of the destination participant, in this case, a DFSP
436 * @returns {Promise<object>} JSON response body if one was received
437 */
438 putThirdpartyRequestsTransactionsError(
439 thirdpartyRequestsTransactionsBody: TErrorInformationObject,
440 transactionRequestId: string,
441 destParticipantId: string
442 ): Promise<GenericRequestResponse | MojaloopRequestResponse>;
443
444 /**
445 * @function postThirdpartyRequestsTransactionsAuthorizations
446 * @description
447 * Executes a `POST /thirdpartyRequests/transactions/${transactionRequestId}/authorizations` request
448 * @param {Object} thirdpartyRequestsTransactionsBody The thirdpartyRequestsTransactionsBody
449 * @param {string} transactionRequestId The `id` of the transactionRequest/thirdpartyRequest
450 * @param {string} destParticipantId The id of the destination participant, in this case, a DFSP
451 * @returns {Promise<object>} JSON response body if one was received
452 */
453 postThirdpartyRequestsTransactionsAuthorizations(
454 thirdpartyRequestsTransactionsBody: PostThirdpartyRequestsTransactionsAuthorizationsRequest,
455 transactionRequestId: string,
456 destParticipantId: string
457 ): Promise<GenericRequestResponse | MojaloopRequestResponse>;
458
459 /**
460 * @function putThirdpartyRequestsTransactionsAuthorizations
461 * @description
462 * Executes a `PUT /thirdpartyRequests/transactions/${transactionRequestId}/authorizations` request
463 * @param {putThirdpartyRequestsTransactionsAuthorizationsRequest} thirdpartyRequestsTransactionsBody The thirdpartyRequestsTransactionsBody
464 * @param {string} transactionRequestId The `id` of the transactionRequest/thirdpartyRequest
465 * @param {string} destParticipantId The id of the destination participant, in this case, a DFSP
466 * @returns {Promise<object>} JSON response body if one was received
467 */
468 putThirdpartyRequestsTransactionsAuthorizations(
469 thirdpartyRequestsTransactionsBody: PutThirdpartyRequestsTransactionsAuthorizationsRequest,
470 transactionRequestId: string,
471 destParticipantId: string
472 ): Promise<GenericRequestResponse | MojaloopRequestResponse>;
473
474 /**
475 * @function putThirdpartyRequestsTransactionsAuthorizationsError
476 * @description
477 * Executes a `PUT thirdpartyRequests/transactions/${transactionRequestId}/authorizations/error` request
478 * @param {putThirdpartyRequestsTransactionsAuthorizationsRequest} thirdpartyRequestsTransactionsBody The thirdpartyRequestsTransactionsBody
479 * @param {string} transactionRequestId The `id` of the transactionRequest/thirdpartyRequest
480 * @param {string} destParticipantId The id of the destination participant, in this case, a DFSP
481 * @returns {Promise<object>} JSON response body if one was received
482 */
483 putThirdpartyRequestsTransactionsAuthorizationsError(
484 thirdpartyRequestsTransactionsBody: TErrorInformationObject,
485 transactionRequestId: string,
486 destParticipantId: string
487 ): Promise<GenericRequestResponse | MojaloopRequestResponse>;
488 }
489
490 class MojaloopRequests extends BaseRequests {
491 /**
492 * @function getParties
493 * @description
494 * Executes a GET /parties request for the specified identifier type and identifier
495 * @param {string} idType The party id type
496 * @param {string} id The party id
497 * @param {string} [idSubValue] The optional party id sub value
498 * @returns Promise<{object}> - JSON response body if one was received
499 */
500 getParties(
501 idType: string,
502 idValue: string,
503 idSubValue?: string
504 ): Promise<GenericRequestResponse | MojaloopRequestResponse>;
505
506 /**
507 * @function putParties
508 * @description
509 * Executes a PUT /parties request for the specified identifier type and identifier
510 * @param {string} idType The party id type
511 * @param {string} id The party id
512 * @param {string} [idSubValue] The party id sub value - pass `undefined` if not specified
513 * @param {object} body The party's properties
514 * @param {string} destFspId The id of the destination participant, in this case, a DFSP
515 */
516 putParties(
517 idType: string,
518 idValue: string,
519 idSubValue: string | undefined,
520 body: TParty,
521 destFspId: string
522 ): Promise<GenericRequestResponse | MojaloopRequestResponse>;
523
524 /**
525 * @function putPartiesError
526 * @description
527 * Executes a PUT /parties/{IdType}/{IdValue}/error request for the specified identifier type and identifier
528 * @param {string} idType The party id type
529 * @param {string} id The party id
530 * @param {string} [idSubValue] The party id sub value - pass `undefined` if not specified
531 * @param {Error} [error] The error specification
532 * @param {string} destFspId The id of the destination participant, in this case, a DFSP
533 */
534 putPartiesError(
535 idType: string,
536 idValue: string,
537 idSubValue: string | undefined,
538 error: TErrorInformationObject,
539 destFspId: string
540 ): Promise<GenericRequestResponse | MojaloopRequestResponse>;
541
542 /**
543 * @function postQuotes
544 * @description
545 * Executes a `POST /postQuotes` request
546 * @param {Object} postQuoteRequest The postQuoteRequest
547 * @param {string} destParticipantId The id of the destination participant, in this case, a DFSP
548 * @returns {Promise<object>} JSON response body if one was received
549 */
550 postQuotes(
551 quoteRequest: PostQuoteRequest,
552 destParticipantId: string
553 ): Promise<GenericRequestResponse | MojaloopRequestResponse>;
554
555 /**
556 * @function putAuthorizations
557 * @description
558 * Executes a 'PUT /authorizations' request
559 * @param {string} transactionRequestId
560 * @param {object} authorizationResponse
561 * @param {string} destFspId
562 */
563 putAuthorizations(
564 transactionRequestId: string,
565 authorizationResponse: PutAuthorizationRequest,
566 destFspId: string
567 ): Promise<GenericRequestResponse | MojaloopRequestResponse>
568
569 /**
570 * @function putAuthorizationsError
571 * @description
572 * Executes a `PUT /authorizations/{ID}/error
573 * @param {string} transactionRequestId
574 * @param {object} error
575 * @param {string} destFspId
576 */
577 putAuthorizationsError(
578 transactionRequestId: string,
579 error: TErrorInformationObject,
580 destFspId: string
581 ): Promise<GenericRequestResponse | MojaloopRequestResponse>
582
583 }
584
585 interface WSO2AuthConfig {
586 logger: Logger.Logger,
587 tlsCreds?: {
588 ca: string
589 cert: string
590 key: string
591 },
592 clientKey?: string
593 clientSecret?: string
594 tokenEndpoint?: string
595 refreshSeconds?: number
596 refreshRetrySeconds?: number
597 staticToken?: string
598 }
599 /**
600 * @class WSO2Auth
601 * @description Obtain WSO2 bearer token and periodically refresh it
602 */
603 class WSO2Auth {
604 constructor(config: WSO2AuthConfig)
605
606 /**
607 * @function getToken
608 * @description returns the latest retrieved token
609 * @returns {string} the latest token
610 */
611 getToken(): string
612
613 /**
614 * @function start
615 * @description starts the retrieve fresh token periodic task
616 * @returns {Promise<void>}
617 */
618 start(): void
619
620 /**
621 * @function stop
622 * @description stops the retrieve fresh token periodic task
623 * @returns {void}
624 */
625 stop(): void
626 }
627 namespace Logger {
628 type Level = 'verbose' | 'debug' | 'warn' | 'error' | 'trace' | 'info' | 'fatal'
629 type TimestampFormatter = (ts: Date) => string;
630 type Stringify = (toBeStringified: unknown) => string;
631 interface LoggerStringifyParams {
632 ctx: unknown
633 msg: unknown
634 level: Level
635 }
636
637 type LoggerStringify = (params: LoggerStringifyParams) => string
638
639
640 interface BuildStringifyParams {
641 space?: number
642 printTimestamp?: boolean
643 timestampFmt?: TimestampFormatter
644 stringify?: Stringify
645 }
646 type BuildStringify = (params: BuildStringifyParams) => LoggerStringify;
647
648 function buildStringify(params: BuildStringifyParams): LoggerStringify
649
650 interface LoggerOptions {
651 allowContextOverwrite: boolean
652 copy: (arg0: unknown) => unknown
653 levels: Level[]
654 }
655
656 interface LoggerConstructorParams {
657 ctx?: unknown
658 stringify?: BuildStringify
659 opts?: LoggerOptions
660 }
661
662 interface LoggerConfigureParams {
663 stringify?: BuildStringify
664 opts?: LoggerOptions
665 }
666
667 /**
668 * @class Logger
669 * @description fast and lightweight logger which do pretty dumping of anything into the log in a pretty way
670 */
671 class Logger {
672 protected stringify: BuildStringify
673 protected opts: LoggerOptions
674
675 constructor(params?: LoggerConstructorParams)
676
677 configure(params?: LoggerConfigureParams): void
678
679 push(arg: unknown): Logger
680 log(...args: unknown[]): void
681
682 // default set of logging methods taken from default levels
683 // if you want to use different log levels
684 // this part of code will not work for you
685 verbose(arg: unknown): void
686 debug(arg: unknown): void
687 warn(arg: unknown): void
688 error(arg: unknown): void
689 trace(arg: unknown): void
690 info(arg: unknown): void
691 fatal(arg: unknown): void
692 }
693 }
694
695 enum RequestResponseType { ArrayBuffer, JSON, Text, Stream }
696 type RequestMethod = 'GET' | 'PATCH' | 'POST' | 'PUT'
697 export type RequestBody = string | Buffer | Uint8Array
698 interface RequestOptions {
699 method: RequestMethod
700 uri: string
701 agent: http.Agent
702 qs?: string
703 headers?: Record<string, string>
704 // body is passed to http.ClientRequest.write
705 // https://nodejs.org/api/http.html#http_class_http_clientrequest
706 // https://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback
707 body? : RequestBody
708 responseType?: RequestResponseType
709 }
710 interface RequestResponse<Data = string | Buffer | Record<string, unknown>>{
711 statusCode: number
712 headers?: Record<string, string>
713 data: Data
714 }
715
716 function request<Data>(opts: RequestOptions): Promise<RequestResponse<Data>>
717
718 namespace request {
719 let ResponseType: RequestResponseType
720 }
721
722 namespace requests {
723 namespace common {
724 function bodyStringifier(arg0: unknown): string | Buffer
725 }
726 }
727
728 namespace Errors {
729 interface MojaloopApiErrorCode {
730 code: string
731 message: string
732 httpStatusCode?: number
733 }
734
735 interface MojaloopApiErrorObject {
736 errorInformation: {
737 errorCode: string
738 errorDescription: string
739 extensionList: unknown[]
740 }
741 }
742 interface MojaloopApiErrorCodesEnum {
743 //Generic communication errors
744 COMMUNICATION_ERROR: MojaloopApiErrorCode
745 DESTINATION_COMMUNICATION_ERROR: MojaloopApiErrorCode
746
747 //Generic server errors
748 SERVER_ERROR: MojaloopApiErrorCode
749 INTERNAL_SERVER_ERROR: MojaloopApiErrorCode
750 NOT_IMPLEMENTED: MojaloopApiErrorCode
751 SERVICE_CURRENTLY_UNAVAILABLE: MojaloopApiErrorCode
752 SERVER_TIMED_OUT: MojaloopApiErrorCode
753 SERVER_BUSY: MojaloopApiErrorCode
754
755 //Generic client errors
756 METHOD_NOT_ALLOWED: MojaloopApiErrorCode
757 CLIENT_ERROR: MojaloopApiErrorCode
758 UNACCEPTABLE_VERSION: MojaloopApiErrorCode
759 UNKNOWN_URI: MojaloopApiErrorCode
760 ADD_PARTY_INFO_ERROR: MojaloopApiErrorCode
761 DELETE_PARTY_INFO_ERROR: MojaloopApiErrorCode, // Error code thrown in ALS when deleting participant info fails
762
763 //Client validation errors
764 VALIDATION_ERROR: MojaloopApiErrorCode
765 MALFORMED_SYNTAX: MojaloopApiErrorCode
766 MISSING_ELEMENT: MojaloopApiErrorCode
767 TOO_MANY_ELEMENTS: MojaloopApiErrorCode
768 TOO_LARGE_PAYLOAD: MojaloopApiErrorCode
769 INVALID_SIGNATURE: MojaloopApiErrorCode
770 MODIFIED_REQUEST: MojaloopApiErrorCode
771 MISSING_MANDATORY_EXTENSION: MojaloopApiErrorCode
772
773 //identifier errors
774 ID_NOT_FOUND: MojaloopApiErrorCode
775 DESTINATION_FSP_ERROR: MojaloopApiErrorCode
776 PAYER_FSP_ID_NOT_FOUND: MojaloopApiErrorCode
777 PAYEE_FSP_ID_NOT_FOUND: MojaloopApiErrorCode
778 PARTY_NOT_FOUND: MojaloopApiErrorCode
779 QUOTE_ID_NOT_FOUND: MojaloopApiErrorCode
780 TXN_REQUEST_ID_NOT_FOUND: MojaloopApiErrorCode
781 TXN_ID_NOT_FOUND: MojaloopApiErrorCode
782 TRANSFER_ID_NOT_FOUND: MojaloopApiErrorCode
783 BULK_QUOTE_ID_NOT_FOUND: MojaloopApiErrorCode
784 BULK_TRANSFER_ID_NOT_FOUND: MojaloopApiErrorCode
785
786 //expired errors
787 EXPIRED_ERROR: MojaloopApiErrorCode
788 TXN_REQUEST_EXPIRED: MojaloopApiErrorCode
789 QUOTE_EXPIRED: MojaloopApiErrorCode
790 TRANSFER_EXPIRED: MojaloopApiErrorCode
791
792 //payer errors
793 PAYER_ERROR: MojaloopApiErrorCode
794 PAYER_FSP_INSUFFICIENT_LIQUIDITY: MojaloopApiErrorCode
795 PAYER_REJECTION: MojaloopApiErrorCode
796 PAYER_REJECTED_TXN_REQUEST: MojaloopApiErrorCode
797 PAYER_FSP_UNSUPPORTED_TXN_TYPE: MojaloopApiErrorCode
798 PAYER_UNSUPPORTED_CURRENCY: MojaloopApiErrorCode
799 PAYER_LIMIT_ERROR: MojaloopApiErrorCode
800 PAYER_PERMISSION_ERROR: MojaloopApiErrorCode
801 PAYER_BLOCKED_ERROR: MojaloopApiErrorCode
802
803 //payee errors
804 PAYEE_ERROR: MojaloopApiErrorCode
805 PAYEE_FSP_INSUFFICIENT_LIQUIDITY: MojaloopApiErrorCode
806 PAYEE_REJECTION: MojaloopApiErrorCode
807 PAYEE_REJECTED_QUOTE: MojaloopApiErrorCode
808 PAYEE_FSP_UNSUPPORTED_TXN_TYPE: MojaloopApiErrorCode
809 PAYEE_FSP_REJECTED_QUOTE: MojaloopApiErrorCode
810 PAYEE_REJECTED_TXN: MojaloopApiErrorCode
811 PAYEE_FSP_REJECTED_TXN: MojaloopApiErrorCode
812 PAYEE_UNSUPPORTED_CURRENCY: MojaloopApiErrorCode
813 PAYEE_LIMIT_ERROR: MojaloopApiErrorCode
814 PAYEE_PERMISSION_ERROR: MojaloopApiErrorCode
815 GENERIC_PAYEE_BLOCKED_ERROR: MojaloopApiErrorCode
816 }
817
818 const MojaloopApiErrorCodes: MojaloopApiErrorCodesEnum
819
820 function MojaloopApiErrorCodeFromCode(code: string): MojaloopApiErrorCode
821
822 function MojaloopApiErrorObjectFromCode(code: MojaloopApiErrorCode): MojaloopApiErrorObject
823
824 interface FullErrorObject {
825 message: string
826 replyTo: string
827 apiErrorCode: MojaloopApiErrorCode
828 extensions?: unknown
829 cause?: string
830 }
831 class MojaloopFSPIOPError extends Error {
832 public cause: Error | unknown
833 public message: string
834 public replyTo: string
835 public apiErrorCode: MojaloopApiErrorCode
836 public extensions: unknown
837
838 constructor(
839 cause: Error | unknown,
840 message: string,
841 replyTo: string,
842 apiErrorCode: MojaloopApiErrorCode,
843 extensions?: unknown
844 )
845
846 toApiErrorObject(): MojaloopApiErrorObject
847 toFullErrorObject(): FullErrorObject
848 toString(): string
849 }
850 }
851}
852
853export = SDKStandardComponents