UNPKG

33.8 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 postAuthorizations
557 * @description
558 * Executes a `POST /authorizations` request for the specified `authorizations request`
559 * @param {Object} authorizationRequest The authorization request
560 * @param {string} destFspId The id of the destination participant
561 * @returns {Promise<object>} JSON response body if one was received
562 */
563 postAuthorizations (
564 authorizationRequest: PostAuthorizationsRequest,
565 destFspId: string
566 ): Promise<GenericRequestResponse | MojaloopRequestResponse>;
567
568 /**
569 * @function putAuthorizations
570 * @description
571 * Executes a 'PUT /authorizations' request
572 * @param {string} transactionRequestId
573 * @param {object} authorizationResponse
574 * @param {string} destFspId
575 */
576 putAuthorizations(
577 transactionRequestId: string,
578 authorizationResponse: PutAuthorizationRequest,
579 destFspId: string
580 ): Promise<GenericRequestResponse | MojaloopRequestResponse>
581
582 /**
583 * @function putAuthorizationsError
584 * @description
585 * Executes a `PUT /authorizations/{ID}/error
586 * @param {string} transactionRequestId
587 * @param {object} error
588 * @param {string} destFspId
589 */
590 putAuthorizationsError(
591 transactionRequestId: string,
592 error: TErrorInformationObject,
593 destFspId: string
594 ): Promise<GenericRequestResponse | MojaloopRequestResponse>
595
596 }
597
598 interface WSO2AuthConfig {
599 logger: Logger.Logger,
600 tlsCreds?: {
601 ca: string
602 cert: string
603 key: string
604 },
605 clientKey?: string
606 clientSecret?: string
607 tokenEndpoint?: string
608 refreshSeconds?: number
609 refreshRetrySeconds?: number
610 staticToken?: string
611 }
612 /**
613 * @class WSO2Auth
614 * @description Obtain WSO2 bearer token and periodically refresh it
615 */
616 class WSO2Auth {
617 constructor(config: WSO2AuthConfig)
618
619 /**
620 * @function getToken
621 * @description returns the latest retrieved token
622 * @returns {string} the latest token
623 */
624 getToken(): string
625
626 /**
627 * @function start
628 * @description starts the retrieve fresh token periodic task
629 * @returns {Promise<void>}
630 */
631 start(): void
632
633 /**
634 * @function stop
635 * @description stops the retrieve fresh token periodic task
636 * @returns {void}
637 */
638 stop(): void
639 }
640 namespace Logger {
641 type Level = 'verbose' | 'debug' | 'warn' | 'error' | 'trace' | 'info' | 'fatal'
642 type TimestampFormatter = (ts: Date) => string;
643 type Stringify = (toBeStringified: unknown) => string;
644 interface LoggerStringifyParams {
645 ctx: unknown
646 msg: unknown
647 level: Level
648 }
649
650 type LoggerStringify = (params: LoggerStringifyParams) => string
651
652
653 interface BuildStringifyParams {
654 space?: number
655 printTimestamp?: boolean
656 timestampFmt?: TimestampFormatter
657 stringify?: Stringify
658 }
659 type BuildStringify = (params: BuildStringifyParams) => LoggerStringify;
660
661 function buildStringify(params: BuildStringifyParams): LoggerStringify
662
663 interface LoggerOptions {
664 allowContextOverwrite: boolean
665 copy: (arg0: unknown) => unknown
666 levels: Level[]
667 }
668
669 interface LoggerConstructorParams {
670 ctx?: unknown
671 stringify?: BuildStringify
672 opts?: LoggerOptions
673 }
674
675 interface LoggerConfigureParams {
676 stringify?: BuildStringify
677 opts?: LoggerOptions
678 }
679
680 /**
681 * @class Logger
682 * @description fast and lightweight logger which do pretty dumping of anything into the log in a pretty way
683 */
684 class Logger {
685 protected stringify: BuildStringify
686 protected opts: LoggerOptions
687
688 constructor(params?: LoggerConstructorParams)
689
690 configure(params?: LoggerConfigureParams): void
691
692 push(arg: unknown): Logger
693 log(...args: unknown[]): void
694
695 // default set of logging methods taken from default levels
696 // if you want to use different log levels
697 // this part of code will not work for you
698 verbose(arg: unknown): void
699 debug(arg: unknown): void
700 warn(arg: unknown): void
701 error(arg: unknown): void
702 trace(arg: unknown): void
703 info(arg: unknown): void
704 fatal(arg: unknown): void
705 }
706 }
707
708 enum RequestResponseType { ArrayBuffer, JSON, Text, Stream }
709 type RequestMethod = 'GET' | 'PATCH' | 'POST' | 'PUT'
710 export type RequestBody = string | Buffer | Uint8Array
711 interface RequestOptions {
712 method: RequestMethod
713 uri: string
714 agent: http.Agent
715 qs?: string
716 headers?: Record<string, string>
717 // body is passed to http.ClientRequest.write
718 // https://nodejs.org/api/http.html#http_class_http_clientrequest
719 // https://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback
720 body? : RequestBody
721 responseType?: RequestResponseType
722 }
723 interface RequestResponse<Data = string | Buffer | Record<string, unknown>>{
724 statusCode: number
725 headers?: Record<string, string>
726 data: Data
727 }
728
729 function request<Data>(opts: RequestOptions): Promise<RequestResponse<Data>>
730
731 namespace request {
732 let ResponseType: RequestResponseType
733 }
734
735 namespace requests {
736 namespace common {
737 function bodyStringifier(arg0: unknown): string | Buffer
738 }
739 }
740
741 namespace Errors {
742 interface MojaloopApiErrorCode {
743 code: string
744 message: string
745 httpStatusCode?: number
746 }
747
748 interface MojaloopApiErrorObject {
749 errorInformation: {
750 errorCode: string
751 errorDescription: string
752 extensionList: unknown[]
753 }
754 }
755 interface MojaloopApiErrorCodesEnum {
756 //Generic communication errors
757 COMMUNICATION_ERROR: MojaloopApiErrorCode
758 DESTINATION_COMMUNICATION_ERROR: MojaloopApiErrorCode
759
760 //Generic server errors
761 SERVER_ERROR: MojaloopApiErrorCode
762 INTERNAL_SERVER_ERROR: MojaloopApiErrorCode
763 NOT_IMPLEMENTED: MojaloopApiErrorCode
764 SERVICE_CURRENTLY_UNAVAILABLE: MojaloopApiErrorCode
765 SERVER_TIMED_OUT: MojaloopApiErrorCode
766 SERVER_BUSY: MojaloopApiErrorCode
767
768 //Generic client errors
769 METHOD_NOT_ALLOWED: MojaloopApiErrorCode
770 CLIENT_ERROR: MojaloopApiErrorCode
771 UNACCEPTABLE_VERSION: MojaloopApiErrorCode
772 UNKNOWN_URI: MojaloopApiErrorCode
773 ADD_PARTY_INFO_ERROR: MojaloopApiErrorCode
774 DELETE_PARTY_INFO_ERROR: MojaloopApiErrorCode, // Error code thrown in ALS when deleting participant info fails
775
776 //Client validation errors
777 VALIDATION_ERROR: MojaloopApiErrorCode
778 MALFORMED_SYNTAX: MojaloopApiErrorCode
779 MISSING_ELEMENT: MojaloopApiErrorCode
780 TOO_MANY_ELEMENTS: MojaloopApiErrorCode
781 TOO_LARGE_PAYLOAD: MojaloopApiErrorCode
782 INVALID_SIGNATURE: MojaloopApiErrorCode
783 MODIFIED_REQUEST: MojaloopApiErrorCode
784 MISSING_MANDATORY_EXTENSION: MojaloopApiErrorCode
785
786 //identifier errors
787 ID_NOT_FOUND: MojaloopApiErrorCode
788 DESTINATION_FSP_ERROR: MojaloopApiErrorCode
789 PAYER_FSP_ID_NOT_FOUND: MojaloopApiErrorCode
790 PAYEE_FSP_ID_NOT_FOUND: MojaloopApiErrorCode
791 PARTY_NOT_FOUND: MojaloopApiErrorCode
792 QUOTE_ID_NOT_FOUND: MojaloopApiErrorCode
793 TXN_REQUEST_ID_NOT_FOUND: MojaloopApiErrorCode
794 TXN_ID_NOT_FOUND: MojaloopApiErrorCode
795 TRANSFER_ID_NOT_FOUND: MojaloopApiErrorCode
796 BULK_QUOTE_ID_NOT_FOUND: MojaloopApiErrorCode
797 BULK_TRANSFER_ID_NOT_FOUND: MojaloopApiErrorCode
798
799 //expired errors
800 EXPIRED_ERROR: MojaloopApiErrorCode
801 TXN_REQUEST_EXPIRED: MojaloopApiErrorCode
802 QUOTE_EXPIRED: MojaloopApiErrorCode
803 TRANSFER_EXPIRED: MojaloopApiErrorCode
804
805 //payer errors
806 PAYER_ERROR: MojaloopApiErrorCode
807 PAYER_FSP_INSUFFICIENT_LIQUIDITY: MojaloopApiErrorCode
808 PAYER_REJECTION: MojaloopApiErrorCode
809 PAYER_REJECTED_TXN_REQUEST: MojaloopApiErrorCode
810 PAYER_FSP_UNSUPPORTED_TXN_TYPE: MojaloopApiErrorCode
811 PAYER_UNSUPPORTED_CURRENCY: MojaloopApiErrorCode
812 PAYER_LIMIT_ERROR: MojaloopApiErrorCode
813 PAYER_PERMISSION_ERROR: MojaloopApiErrorCode
814 PAYER_BLOCKED_ERROR: MojaloopApiErrorCode
815
816 //payee errors
817 PAYEE_ERROR: MojaloopApiErrorCode
818 PAYEE_FSP_INSUFFICIENT_LIQUIDITY: MojaloopApiErrorCode
819 PAYEE_REJECTION: MojaloopApiErrorCode
820 PAYEE_REJECTED_QUOTE: MojaloopApiErrorCode
821 PAYEE_FSP_UNSUPPORTED_TXN_TYPE: MojaloopApiErrorCode
822 PAYEE_FSP_REJECTED_QUOTE: MojaloopApiErrorCode
823 PAYEE_REJECTED_TXN: MojaloopApiErrorCode
824 PAYEE_FSP_REJECTED_TXN: MojaloopApiErrorCode
825 PAYEE_UNSUPPORTED_CURRENCY: MojaloopApiErrorCode
826 PAYEE_LIMIT_ERROR: MojaloopApiErrorCode
827 PAYEE_PERMISSION_ERROR: MojaloopApiErrorCode
828 GENERIC_PAYEE_BLOCKED_ERROR: MojaloopApiErrorCode
829 }
830
831 const MojaloopApiErrorCodes: MojaloopApiErrorCodesEnum
832
833 function MojaloopApiErrorCodeFromCode(code: string): MojaloopApiErrorCode
834
835 function MojaloopApiErrorObjectFromCode(code: MojaloopApiErrorCode): MojaloopApiErrorObject
836
837 interface FullErrorObject {
838 message: string
839 replyTo: string
840 apiErrorCode: MojaloopApiErrorCode
841 extensions?: unknown
842 cause?: string
843 }
844 class MojaloopFSPIOPError extends Error {
845 public cause: Error | unknown
846 public message: string
847 public replyTo: string
848 public apiErrorCode: MojaloopApiErrorCode
849 public extensions: unknown
850
851 constructor(
852 cause: Error | unknown,
853 message: string,
854 replyTo: string,
855 apiErrorCode: MojaloopApiErrorCode,
856 extensions?: unknown
857 )
858
859 toApiErrorObject(): MojaloopApiErrorObject
860 toFullErrorObject(): FullErrorObject
861 toString(): string
862 }
863 }
864}
865
866export = SDKStandardComponents