pecunia-core 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,566 @@
1
+ //#region src/types/errors/index.ts
2
+ let ErrorType = /* @__PURE__ */ function(ErrorType$1) {
3
+ ErrorType$1["INVALID_REQUEST"] = "INVALID_REQUEST_ERROR";
4
+ ErrorType$1["PAYMENT"] = "PAYMENT_ERROR";
5
+ ErrorType$1["AUTHENTICATION"] = "AUTHENTICATION_ERROR";
6
+ ErrorType$1["RATE_LIMIT"] = "RATE_LIMIT_ERROR";
7
+ ErrorType$1["PROVIDER"] = "PROVIDER_ERROR";
8
+ ErrorType$1["API"] = "API_ERROR";
9
+ return ErrorType$1;
10
+ }({});
11
+
12
+ //#endregion
13
+ //#region src/errors/shared/index.ts
14
+ const SHARED_ERROR_REGISTRY = {
15
+ duplicate_transaction: {
16
+ code: "duplicate_transaction",
17
+ type: ErrorType.PAYMENT,
18
+ statusCode: 409,
19
+ message: "Transaction already exists."
20
+ },
21
+ invalid_phone_number: {
22
+ code: "invalid_phone_number",
23
+ type: ErrorType.INVALID_REQUEST,
24
+ statusCode: 400,
25
+ message: "The phone number provided is invalid."
26
+ },
27
+ invalid_request_payload: {
28
+ code: "invalid_request_payload",
29
+ type: ErrorType.INVALID_REQUEST,
30
+ statusCode: 400,
31
+ message: "The request payload is invalid."
32
+ },
33
+ resource_not_found: {
34
+ code: "resource_not_found",
35
+ type: ErrorType.INVALID_REQUEST,
36
+ statusCode: 404,
37
+ message: "Requested resource not found."
38
+ }
39
+ };
40
+
41
+ //#endregion
42
+ //#region src/errors/providers/mpesa/registry.ts
43
+ const MPESA_ERROR_REGISTRY = {
44
+ ...SHARED_ERROR_REGISTRY,
45
+ insufficient_funds: {
46
+ code: "insufficient_funds",
47
+ type: ErrorType.PAYMENT,
48
+ statusCode: 402,
49
+ message: "Insufficient funds."
50
+ },
51
+ transaction_cancelled: {
52
+ code: "transaction_cancelled",
53
+ type: ErrorType.PAYMENT,
54
+ statusCode: 402,
55
+ message: "Customer cancelled the transaction."
56
+ },
57
+ transaction_timeout: {
58
+ code: "transaction_timeout",
59
+ type: ErrorType.PAYMENT,
60
+ statusCode: 408,
61
+ message: "Customer did not enter their PIN in time."
62
+ },
63
+ transaction_in_progress: {
64
+ code: "transaction_in_progress",
65
+ type: ErrorType.PAYMENT,
66
+ statusCode: 409,
67
+ message: "Transaction in progress."
68
+ },
69
+ transaction_expired: {
70
+ code: "transaction_expired",
71
+ type: ErrorType.PAYMENT,
72
+ statusCode: 408,
73
+ message: "Transaction has expired."
74
+ },
75
+ daily_limit_exceeded: {
76
+ code: "daily_limit_exceeded",
77
+ type: ErrorType.PAYMENT,
78
+ statusCode: 402,
79
+ message: "Daily transaction limit exceeded."
80
+ },
81
+ invalid_amount: {
82
+ code: "invalid_amount",
83
+ type: ErrorType.INVALID_REQUEST,
84
+ statusCode: 400,
85
+ message: "The amount is below the minimum or above the maximum allowed."
86
+ },
87
+ missing_parameter: {
88
+ code: "missing_parameter",
89
+ type: ErrorType.INVALID_REQUEST,
90
+ statusCode: 400,
91
+ message: "Required parameter is missing."
92
+ },
93
+ invalid_access_token: {
94
+ code: "invalid_access_token",
95
+ type: ErrorType.AUTHENTICATION,
96
+ statusCode: 401,
97
+ message: "Invalid access token."
98
+ },
99
+ invalid_credentials: {
100
+ code: "invalid_credentials",
101
+ type: ErrorType.AUTHENTICATION,
102
+ statusCode: 401,
103
+ message: "Invalid credentials."
104
+ },
105
+ rate_limit_exceeded: {
106
+ code: "rate_limit_exceeded",
107
+ type: ErrorType.RATE_LIMIT,
108
+ statusCode: 429,
109
+ message: "Rate limit exceeded."
110
+ },
111
+ provider_unavailable: {
112
+ code: "provider_unavailable",
113
+ type: ErrorType.PROVIDER,
114
+ statusCode: 503,
115
+ message: "Provider currently unavailable."
116
+ },
117
+ provider_timeout: {
118
+ code: "provider_timeout",
119
+ type: ErrorType.PROVIDER,
120
+ statusCode: 504,
121
+ message: "Provider took too long to respond."
122
+ },
123
+ internal_server_error: {
124
+ code: "internal_server_error",
125
+ type: ErrorType.API,
126
+ statusCode: 500,
127
+ message: "Unexpected error occurred."
128
+ },
129
+ urls_already_registered: {
130
+ code: "urls_already_registered",
131
+ type: ErrorType.INVALID_REQUEST,
132
+ statusCode: 409,
133
+ message: "Callback URLs already registered"
134
+ },
135
+ unknown_error: {
136
+ code: "unknown_error",
137
+ type: ErrorType.API,
138
+ statusCode: 500,
139
+ message: "Unknown error occurred."
140
+ }
141
+ };
142
+
143
+ //#endregion
144
+ //#region src/errors/providers/airtel/registry.ts
145
+ const AIRTEL_ERROR_REGISTRY = {
146
+ ...SHARED_ERROR_REGISTRY,
147
+ transaction_ambiguous: {
148
+ code: "transaction_ambiguous",
149
+ type: ErrorType.PAYMENT,
150
+ statusCode: 202,
151
+ message: "Payment status is unknown at the moment. Please perform a transaction enquiry."
152
+ },
153
+ invalid_currency: {
154
+ code: "invalid_currency",
155
+ type: ErrorType.INVALID_REQUEST,
156
+ statusCode: 400,
157
+ message: "Unsupported currency."
158
+ },
159
+ provider_unavailable: {
160
+ code: "provider_unavailable",
161
+ type: ErrorType.PROVIDER,
162
+ statusCode: 503,
163
+ message: "Airtel provider is unavailable or not configured to process this request."
164
+ },
165
+ missing_parameter: {
166
+ code: "missing_parameter",
167
+ type: ErrorType.INVALID_REQUEST,
168
+ statusCode: 400,
169
+ message: "Required parameter is missing."
170
+ },
171
+ invalid_request_payload: {
172
+ code: "invalid_request_payload",
173
+ type: ErrorType.INVALID_REQUEST,
174
+ statusCode: 400,
175
+ message: "The request payload is invalid."
176
+ },
177
+ unauthorized: {
178
+ code: "unauthorized",
179
+ type: ErrorType.AUTHENTICATION,
180
+ statusCode: 401,
181
+ message: "You are not authorized to perform this operation."
182
+ },
183
+ provider_timeout: {
184
+ code: "provider_timeout",
185
+ type: ErrorType.PROVIDER,
186
+ statusCode: 504,
187
+ message: "Provider took too long to respond. Please retry or perform a transaction enquiry."
188
+ },
189
+ unknown_error: {
190
+ code: "unknown_error",
191
+ type: ErrorType.API,
192
+ statusCode: 500,
193
+ message: "Unknown Airtel error occurred."
194
+ }
195
+ };
196
+
197
+ //#endregion
198
+ //#region src/constants/index.ts
199
+ const statusCodes = {
200
+ OK: 200,
201
+ CREATED: 201,
202
+ ACCEPTED: 202,
203
+ NO_CONTENT: 204,
204
+ MULTIPLE_CHOICES: 300,
205
+ MOVED_PERMANENTLY: 301,
206
+ FOUND: 302,
207
+ SEE_OTHER: 303,
208
+ NOT_MODIFIED: 304,
209
+ TEMPORARY_REDIRECT: 307,
210
+ BAD_REQUEST: 400,
211
+ UNAUTHORIZED: 401,
212
+ PAYMENT_REQUIRED: 402,
213
+ FORBIDDEN: 403,
214
+ NOT_FOUND: 404,
215
+ METHOD_NOT_ALLOWED: 405,
216
+ NOT_ACCEPTABLE: 406,
217
+ PROXY_AUTHENTICATION_REQUIRED: 407,
218
+ REQUEST_TIMEOUT: 408,
219
+ CONFLICT: 409,
220
+ GONE: 410,
221
+ LENGTH_REQUIRED: 411,
222
+ PRECONDITION_FAILED: 412,
223
+ PAYLOAD_TOO_LARGE: 413,
224
+ URI_TOO_LONG: 414,
225
+ UNSUPPORTED_MEDIA_TYPE: 415,
226
+ RANGE_NOT_SATISFIABLE: 416,
227
+ EXPECTATION_FAILED: 417,
228
+ "I'M_A_TEAPOT": 418,
229
+ MISDIRECTED_REQUEST: 421,
230
+ UNPROCESSABLE_ENTITY: 422,
231
+ LOCKED: 423,
232
+ FAILED_DEPENDENCY: 424,
233
+ TOO_EARLY: 425,
234
+ UPGRADE_REQUIRED: 426,
235
+ PRECONDITION_REQUIRED: 428,
236
+ TOO_MANY_REQUESTS: 429,
237
+ REQUEST_HEADER_FIELDS_TOO_LARGE: 431,
238
+ UNAVAILABLE_FOR_LEGAL_REASONS: 451,
239
+ INTERNAL_SERVER_ERROR: 500,
240
+ NOT_IMPLEMENTED: 501,
241
+ BAD_GATEWAY: 502,
242
+ SERVICE_UNAVAILABLE: 503,
243
+ GATEWAY_TIMEOUT: 504,
244
+ HTTP_VERSION_NOT_SUPPORTED: 505,
245
+ VARIANT_ALSO_NEGOTIATES: 506,
246
+ INSUFFICIENT_STORAGE: 507,
247
+ LOOP_DETECTED: 508,
248
+ NOT_EXTENDED: 510,
249
+ NETWORK_AUTHENTICATION_REQUIRED: 511
250
+ };
251
+ let PaymentProviders = /* @__PURE__ */ function(PaymentProviders$1) {
252
+ PaymentProviders$1["MPESA"] = "MPESA";
253
+ PaymentProviders$1["AIRTEL"] = "AIRTEL";
254
+ return PaymentProviders$1;
255
+ }({});
256
+ let Currency = /* @__PURE__ */ function(Currency$1) {
257
+ Currency$1["KES"] = "KES";
258
+ return Currency$1;
259
+ }({});
260
+ let PriceType = /* @__PURE__ */ function(PriceType$1) {
261
+ PriceType$1["ONE_TIME"] = "ONE_TIME";
262
+ PriceType$1["RECURRING"] = "RECURRING";
263
+ PriceType$1["METERED"] = "METERED";
264
+ return PriceType$1;
265
+ }({});
266
+ let PricingModel = /* @__PURE__ */ function(PricingModel$1) {
267
+ PricingModel$1["FLAT"] = "FLAT";
268
+ return PricingModel$1;
269
+ }({});
270
+ let BillingInterval = /* @__PURE__ */ function(BillingInterval$1) {
271
+ BillingInterval$1["DAY"] = "DAY";
272
+ BillingInterval$1["WEEK"] = "WEEK";
273
+ BillingInterval$1["MONTH"] = "MONTH";
274
+ BillingInterval$1["YEAR"] = "YEAR";
275
+ return BillingInterval$1;
276
+ }({});
277
+ let UsageAggregation = /* @__PURE__ */ function(UsageAggregation$1) {
278
+ UsageAggregation$1["SUM"] = "SUM";
279
+ UsageAggregation$1["MAX"] = "MAX";
280
+ UsageAggregation$1["LAST_DURING_PERIOD"] = "LAST_DURING_PERIOD";
281
+ UsageAggregation$1["LAST_EVER"] = "LAST_EVER";
282
+ return UsageAggregation$1;
283
+ }({});
284
+ let UsageAction = /* @__PURE__ */ function(UsageAction$1) {
285
+ UsageAction$1["INCREMENT"] = "INCREMENT";
286
+ UsageAction$1["SUM"] = "SUM";
287
+ return UsageAction$1;
288
+ }({});
289
+ let ProrationBehavior = /* @__PURE__ */ function(ProrationBehavior$1) {
290
+ ProrationBehavior$1["CREATE_PRORATIONS"] = "CREATE_PRORATIONS";
291
+ ProrationBehavior$1["NONE"] = "NONE";
292
+ ProrationBehavior$1["ALWAYS_INVOICE"] = "ALWAYS_INVOICE";
293
+ return ProrationBehavior$1;
294
+ }({});
295
+ let CollectionMethod = /* @__PURE__ */ function(CollectionMethod$1) {
296
+ CollectionMethod$1["CHARGE_AUTOMATICALLY"] = "CHARGE_AUTOMATICALLY";
297
+ CollectionMethod$1["SEND_INVOICE"] = "SEND_INVOICE";
298
+ return CollectionMethod$1;
299
+ }({});
300
+ let SubscriptionStatus = /* @__PURE__ */ function(SubscriptionStatus$1) {
301
+ SubscriptionStatus$1["INCOMPLETE"] = "INCOMPLETE";
302
+ SubscriptionStatus$1["INCOMPLETE_EXPIRED"] = "INCOMPLETE_EXPIRED";
303
+ SubscriptionStatus$1["TRIALING"] = "TRIALING";
304
+ SubscriptionStatus$1["ACTIVE"] = "ACTIVE";
305
+ SubscriptionStatus$1["UNPAID"] = "UNPAID";
306
+ SubscriptionStatus$1["CANCELED"] = "CANCELED";
307
+ SubscriptionStatus$1["PAUSED"] = "PAUSED";
308
+ return SubscriptionStatus$1;
309
+ }({});
310
+ let ScheduleStatus = /* @__PURE__ */ function(ScheduleStatus$1) {
311
+ ScheduleStatus$1["ACTIVE"] = "ACTIVE";
312
+ ScheduleStatus$1["COMPLETED"] = "COMPLETED";
313
+ ScheduleStatus$1["CANCELED"] = "CANCELED";
314
+ ScheduleStatus$1["RELEASED"] = "RELEASED";
315
+ return ScheduleStatus$1;
316
+ }({});
317
+ let InvoiceStatus = /* @__PURE__ */ function(InvoiceStatus$1) {
318
+ InvoiceStatus$1["DRAFT"] = "DRAFT";
319
+ InvoiceStatus$1["OPEN"] = "OPEN";
320
+ InvoiceStatus$1["PAID"] = "PAID";
321
+ InvoiceStatus$1["VOID"] = "VOID";
322
+ InvoiceStatus$1["UNCOLLECTIBLE"] = "UNCOLLECTIBLE";
323
+ return InvoiceStatus$1;
324
+ }({});
325
+ let WebHookEventStatus = /* @__PURE__ */ function(WebHookEventStatus$1) {
326
+ WebHookEventStatus$1["PENDING"] = "PENDING";
327
+ WebHookEventStatus$1["PROCESSING"] = "PROCESSING";
328
+ WebHookEventStatus$1["SUCCEEDED"] = "SUCCEEDED";
329
+ WebHookEventStatus$1["FAILED"] = "FAILED";
330
+ WebHookEventStatus$1["RETRYING"] = "RETRYING";
331
+ return WebHookEventStatus$1;
332
+ }({});
333
+ let CheckoutSessionMode = /* @__PURE__ */ function(CheckoutSessionMode$1) {
334
+ CheckoutSessionMode$1["PAYMENT"] = "PAYMENT";
335
+ CheckoutSessionMode$1["SUBSCRIPTION"] = "SUBSCRIPTION";
336
+ return CheckoutSessionMode$1;
337
+ }({});
338
+ let WebHookDeliveryTrigger = /* @__PURE__ */ function(WebHookDeliveryTrigger$1) {
339
+ WebHookDeliveryTrigger$1["SYSTEM"] = "SYSTEM";
340
+ WebHookDeliveryTrigger$1["MANUAL"] = "MANUAL";
341
+ WebHookDeliveryTrigger$1["RETRY"] = "RETRY";
342
+ return WebHookDeliveryTrigger$1;
343
+ }({});
344
+ let CheckoutSessionStatus = /* @__PURE__ */ function(CheckoutSessionStatus$1) {
345
+ CheckoutSessionStatus$1["OPEN"] = "OPEN";
346
+ CheckoutSessionStatus$1["COMPLETE"] = "COMPLETE";
347
+ CheckoutSessionStatus$1["EXPIRED"] = "EXPIRED";
348
+ return CheckoutSessionStatus$1;
349
+ }({});
350
+ let PaymentIntentStatus = /* @__PURE__ */ function(PaymentIntentStatus$1) {
351
+ PaymentIntentStatus$1["REQUIRES_CONFIRMATION"] = "REQUIRES_CONFIRMATION";
352
+ PaymentIntentStatus$1["PROCESSING"] = "PROCESSING";
353
+ PaymentIntentStatus$1["REQUIRES_ACTION"] = "REQUIRES_ACTION";
354
+ PaymentIntentStatus$1["SUCCEEDED"] = "SUCCEEDED";
355
+ PaymentIntentStatus$1["FAILED"] = "FAILED";
356
+ PaymentIntentStatus$1["CANCELED"] = "CANCELED";
357
+ return PaymentIntentStatus$1;
358
+ }({});
359
+ let TransactionType = /* @__PURE__ */ function(TransactionType$1) {
360
+ TransactionType$1["PAYMENT"] = "PAYMENT";
361
+ TransactionType$1["REFUND"] = "REFUND";
362
+ return TransactionType$1;
363
+ }({});
364
+ let TransactionStatus = /* @__PURE__ */ function(TransactionStatus$1) {
365
+ TransactionStatus$1["PENDING"] = "PENDING";
366
+ TransactionStatus$1["SUCCEEDED"] = "SUCCEEDED";
367
+ TransactionStatus$1["FAILED"] = "FAILED";
368
+ TransactionStatus$1["REVERSED"] = "REVERSED";
369
+ return TransactionStatus$1;
370
+ }({});
371
+ let ScheduledTaskType = /* @__PURE__ */ function(ScheduledTaskType$1) {
372
+ ScheduledTaskType$1["INVOICE_GENERATION"] = "INVOICE_GENERATION";
373
+ ScheduledTaskType$1["SUBSCRIPTION_RENEWAL"] = "SUBSCRIPTION_RENEWAL";
374
+ ScheduledTaskType$1["DUNNING"] = "DUNNING";
375
+ ScheduledTaskType$1["WEBHOOK_RETRY"] = "WEBHOOK_RETRY";
376
+ ScheduledTaskType$1["CLEANUP"] = "CLEANUP";
377
+ ScheduledTaskType$1["TRIAL_ENDING_NOTIFICATION"] = "TRIAL_ENDING_NOTIFICATION";
378
+ return ScheduledTaskType$1;
379
+ }({});
380
+ let ScheduledTaskStatus = /* @__PURE__ */ function(ScheduledTaskStatus$1) {
381
+ ScheduledTaskStatus$1["PENDING"] = "PENDING";
382
+ ScheduledTaskStatus$1["PROCESSING"] = "PROCESSING";
383
+ ScheduledTaskStatus$1["COMPLETED"] = "COMPLETED";
384
+ ScheduledTaskStatus$1["FAILED"] = "FAILED";
385
+ ScheduledTaskStatus$1["CANCELED"] = "CANCELED";
386
+ return ScheduledTaskStatus$1;
387
+ }({});
388
+ let AuditAction = /* @__PURE__ */ function(AuditAction$1) {
389
+ AuditAction$1["CREATED"] = "CREATED";
390
+ AuditAction$1["UPDATED"] = "UPDATED";
391
+ AuditAction$1["DELETED"] = "DELETED";
392
+ AuditAction$1["PAYMENT_SUCCEEDED"] = "PAYMENT_SUCCEEDED";
393
+ AuditAction$1["PAYMENT_FAILED"] = "PAYMENT_FAILED";
394
+ AuditAction$1["REFUND_ISSUED"] = "REFUND_ISSUED";
395
+ AuditAction$1["SUBSCRIPTION_CANCELED"] = "SUBSCRIPTION_CANCELED";
396
+ AuditAction$1["INVOICE_FINALIZED"] = "INVOICE_FINALIZED";
397
+ return AuditAction$1;
398
+ }({});
399
+ let Actor = /* @__PURE__ */ function(Actor$1) {
400
+ Actor$1["USER_ID"] = "USER_ID";
401
+ Actor$1["CRON"] = "CRON";
402
+ Actor$1["SYSTEM"] = "SYSTEM";
403
+ Actor$1["API_KEY_ID"] = "API_KEY_ID";
404
+ return Actor$1;
405
+ }({});
406
+ let ProductType = /* @__PURE__ */ function(ProductType$1) {
407
+ ProductType$1["GOOD"] = "good";
408
+ ProductType$1["SERVICE"] = "service";
409
+ return ProductType$1;
410
+ }({});
411
+ let DiscountType = /* @__PURE__ */ function(DiscountType$1) {
412
+ DiscountType$1["PERCENTAGE"] = "PERCENTAGE";
413
+ DiscountType$1["FIXED_AMOUNT"] = "FIXED_AMOUNT";
414
+ return DiscountType$1;
415
+ }({});
416
+ let LedgerEntryType = /* @__PURE__ */ function(LedgerEntryType$1) {
417
+ LedgerEntryType$1["DEBIT"] = "DEBIT";
418
+ LedgerEntryType$1["CREDIT"] = "CREDIT";
419
+ return LedgerEntryType$1;
420
+ }({});
421
+ let AccountType = /* @__PURE__ */ function(AccountType$1) {
422
+ AccountType$1["ACCOUNTS_RECEIVABLE"] = "ACCOUNTS_RECEIVABLE";
423
+ AccountType$1["CUSTOMER_CREDIT"] = "CUSTOMER_CREDIT";
424
+ AccountType$1["SYSTEM_ADJUSTMENT"] = "SYSTEM_ADJUSTMENT";
425
+ return AccountType$1;
426
+ }({});
427
+ const ERROR_REGISTRY = {
428
+ MPESA: MPESA_ERROR_REGISTRY,
429
+ AIRTEL: AIRTEL_ERROR_REGISTRY
430
+ };
431
+
432
+ //#endregion
433
+ //#region src/errors/providers/mpesa/error-codes.ts
434
+ const errorCodes$1 = new Map([
435
+ ["400.003.01", "invalid_access_token"],
436
+ ["400.008.01", "invalid_credentials"],
437
+ ["400.008.02", "invalid_credentials"],
438
+ ["404.001.04", "invalid_credentials"],
439
+ ["18", "invalid_credentials"],
440
+ ["20", "invalid_credentials"],
441
+ ["400.003.02", "missing_parameter"],
442
+ ["400.002.05", "invalid_request_payload"],
443
+ ["24", "missing_parameter"],
444
+ ["25", "invalid_request_payload"],
445
+ ["2001", "invalid_phone_number"],
446
+ ["500.003.03", "rate_limit_exceeded"],
447
+ ["100000011", "rate_limit_exceeded"],
448
+ ["100000002", "rate_limit_exceeded"],
449
+ ["1", "insufficient_funds"],
450
+ ["1032", "transaction_cancelled"],
451
+ ["1037", "transaction_timeout"],
452
+ ["1001", "transaction_in_progress"],
453
+ ["1019", "transaction_expired"],
454
+ ["500.003.1001", "internal_server_error"],
455
+ ["500.003.02", "provider_unavailable"],
456
+ ["17", "internal_server_error"],
457
+ ["1055", "provider_timeout"],
458
+ ["9999", "provider_unavailable"],
459
+ ["100000004", "internal_server_error"],
460
+ ["00.002.1001", "provider_unavailable"],
461
+ ["15", "duplicate_transaction"],
462
+ ["404.003.01", "resource_not_found"]
463
+ ]);
464
+ const toKey$1 = (code) => String(code).trim();
465
+ const MPESA_ADAPTER = {
466
+ id: "MPESA",
467
+ mapErrorCode: (code) => errorCodes$1.get(toKey$1(code)) ?? "unknown_error"
468
+ };
469
+
470
+ //#endregion
471
+ //#region src/errors/providers/airtel/error-codes.ts
472
+ const errorCodes = new Map([
473
+ ["0000900", "transaction_ambiguous"],
474
+ ["ESB000001", "transaction_ambiguous"],
475
+ ["ESB000004", "transaction_ambiguous"],
476
+ ["ESB000014", "transaction_ambiguous"],
477
+ ["ESB000008", "invalid_request_payload"],
478
+ ["ESB000033", "invalid_phone_number"],
479
+ ["ESB000036", "invalid_phone_number"],
480
+ ["ESB000035", "invalid_currency"],
481
+ ["ESB000034", "invalid_request_payload"],
482
+ ["ESB000039", "invalid_request_payload"],
483
+ ["ESB000041", "duplicate_transaction"],
484
+ ["ESB000045", "resource_not_found"],
485
+ ["ESB000011", "unknown_error"],
486
+ ["ROUTER001", "provider_unavailable"],
487
+ ["ROUTER003", "missing_parameter"],
488
+ ["ROUTER005", "provider_unavailable"],
489
+ ["ROUTER006", "invalid_request_payload"],
490
+ ["ROUTER007", "unauthorized"],
491
+ ["ROUTER112", "invalid_currency"],
492
+ ["ROUTER114", "invalid_request_payload"],
493
+ ["ROUTER115", "invalid_request_payload"],
494
+ ["ROUTER116", "invalid_request_payload"],
495
+ ["ROUTER117", "provider_timeout"],
496
+ ["ROUTER119", "invalid_currency"]
497
+ ]);
498
+ const toKey = (code) => String(code).trim();
499
+ const AIRTEL_ADAPTER = {
500
+ id: "AIRTEL",
501
+ mapErrorCode: (code) => errorCodes.get(toKey(code)) ?? "unknown_error"
502
+ };
503
+
504
+ //#endregion
505
+ //#region src/db/utils/get-provider-adapter.ts
506
+ const PROVIDERS = {
507
+ MPESA: MPESA_ADAPTER,
508
+ AIRTEL: AIRTEL_ADAPTER
509
+ };
510
+ const getProviderAdapter = (id) => PROVIDERS[id];
511
+
512
+ //#endregion
513
+ //#region src/errors/index.ts
514
+ const createProviderError = (provider, providerResultCode) => {
515
+ const adapter = getProviderAdapter(provider);
516
+ const registry = ERROR_REGISTRY[provider];
517
+ const errorDefinition = registry[adapter.mapErrorCode(providerResultCode)] ?? registry.unknown_error;
518
+ return { error: {
519
+ provider,
520
+ statusCode: errorDefinition.statusCode,
521
+ code: errorDefinition.code,
522
+ type: errorDefinition.type,
523
+ message: errorDefinition.message
524
+ } };
525
+ };
526
+ var ApiError = class ApiError extends Error {
527
+ errorCode;
528
+ statusCode;
529
+ context;
530
+ requestId;
531
+ timestamp;
532
+ constructor(message, errorCode, statusCode, context, requestId, timestamp) {
533
+ super(message);
534
+ this.name = "API_ERROR";
535
+ this.errorCode = errorCode;
536
+ this.statusCode = statusCode;
537
+ this.requestId = requestId;
538
+ this.timestamp = timestamp;
539
+ this.context = context;
540
+ Object.setPrototypeOf(this, ApiError.prototype);
541
+ if (Error.captureStackTrace) Error.captureStackTrace(this, ApiError);
542
+ }
543
+ };
544
+ var ValidationError = class ValidationError extends Error {
545
+ field;
546
+ value;
547
+ constructor(message, field, value) {
548
+ super(message);
549
+ this.field = field;
550
+ this.value = value;
551
+ Object.setPrototypeOf(this, ValidationError.prototype);
552
+ if (Error.captureStackTrace) Error.captureStackTrace(this, ValidationError);
553
+ }
554
+ };
555
+ var PecuniaError = class extends Error {
556
+ constructor(message, cause) {
557
+ super(message);
558
+ this.name = "PecuniaError";
559
+ this.message = message;
560
+ this.cause = cause;
561
+ this.stack = "";
562
+ }
563
+ };
564
+
565
+ //#endregion
566
+ export { UsageAggregation as A, ScheduleStatus as C, TransactionStatus as D, SubscriptionStatus as E, WebHookEventStatus as M, statusCodes as N, TransactionType as O, ErrorType as P, ProrationBehavior as S, ScheduledTaskType as T, PaymentIntentStatus as _, AccountType as a, PricingModel as b, BillingInterval as c, CollectionMethod as d, Currency as f, LedgerEntryType as g, InvoiceStatus as h, createProviderError as i, WebHookDeliveryTrigger as j, UsageAction as k, CheckoutSessionMode as l, ERROR_REGISTRY as m, PecuniaError as n, Actor as o, DiscountType as p, ValidationError as r, AuditAction as s, ApiError as t, CheckoutSessionStatus as u, PaymentProviders as v, ScheduledTaskStatus as w, ProductType as x, PriceType as y };
@@ -0,0 +1,9 @@
1
+ import { uuidv7 } from "uuidv7";
2
+
3
+ //#region src/utils/generate-id.ts
4
+ const generateId = () => {
5
+ return uuidv7();
6
+ };
7
+
8
+ //#endregion
9
+ export { generateId as t };