@misterhomer1992/miit-bot-payment 1.0.0 → 1.0.2

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.
Files changed (82) hide show
  1. package/README.md +262 -146
  2. package/dist/index.d.ts +2 -7
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +2 -18
  5. package/dist/index.js.map +1 -1
  6. package/dist/modules/app/types.d.ts +2 -0
  7. package/dist/modules/app/types.d.ts.map +1 -0
  8. package/dist/modules/app/types.js +3 -0
  9. package/dist/modules/app/types.js.map +1 -0
  10. package/dist/modules/cancellableAPI/utils.d.ts +17 -0
  11. package/dist/modules/cancellableAPI/utils.d.ts.map +1 -0
  12. package/dist/modules/cancellableAPI/utils.js +43 -0
  13. package/dist/modules/cancellableAPI/utils.js.map +1 -0
  14. package/dist/modules/invoice/const.d.ts +4 -0
  15. package/dist/modules/invoice/const.d.ts.map +1 -0
  16. package/dist/modules/invoice/const.js +8 -0
  17. package/dist/modules/invoice/const.js.map +1 -0
  18. package/dist/modules/invoice/index.d.ts +5 -0
  19. package/dist/modules/invoice/index.d.ts.map +1 -0
  20. package/dist/modules/invoice/index.js +21 -0
  21. package/dist/modules/invoice/index.js.map +1 -0
  22. package/dist/modules/invoice/repository.d.ts +34 -0
  23. package/dist/modules/invoice/repository.d.ts.map +1 -0
  24. package/dist/modules/invoice/repository.js +68 -0
  25. package/dist/modules/invoice/repository.js.map +1 -0
  26. package/dist/modules/invoice/service.d.ts +29 -0
  27. package/dist/modules/invoice/service.d.ts.map +1 -0
  28. package/dist/modules/invoice/service.js +61 -0
  29. package/dist/modules/invoice/service.js.map +1 -0
  30. package/dist/modules/invoice/types.d.ts +14 -0
  31. package/dist/modules/invoice/types.d.ts.map +1 -0
  32. package/dist/modules/invoice/types.js +3 -0
  33. package/dist/modules/invoice/types.js.map +1 -0
  34. package/dist/modules/logger/types.d.ts +8 -0
  35. package/dist/modules/logger/types.d.ts.map +1 -0
  36. package/dist/modules/logger/types.js +3 -0
  37. package/dist/modules/logger/types.js.map +1 -0
  38. package/dist/modules/network/utils.d.ts +9 -0
  39. package/dist/modules/network/utils.d.ts.map +1 -0
  40. package/dist/modules/network/utils.js +20 -0
  41. package/dist/modules/network/utils.js.map +1 -0
  42. package/dist/modules/payments/const.d.ts +4 -0
  43. package/dist/modules/payments/const.d.ts.map +1 -0
  44. package/dist/modules/payments/const.js +11 -0
  45. package/dist/modules/payments/const.js.map +1 -0
  46. package/dist/modules/payments/index.d.ts +5 -0
  47. package/dist/modules/payments/index.d.ts.map +1 -0
  48. package/dist/modules/payments/index.js +21 -0
  49. package/dist/modules/payments/index.js.map +1 -0
  50. package/dist/modules/payments/repository.d.ts +82 -0
  51. package/dist/modules/payments/repository.d.ts.map +1 -0
  52. package/dist/modules/payments/repository.js +153 -0
  53. package/dist/modules/payments/repository.js.map +1 -0
  54. package/dist/modules/payments/service.d.ts +65 -0
  55. package/dist/modules/payments/service.d.ts.map +1 -0
  56. package/dist/modules/payments/service.js +132 -0
  57. package/dist/modules/payments/service.js.map +1 -0
  58. package/dist/modules/payments/types.d.ts +31 -0
  59. package/dist/modules/payments/types.d.ts.map +1 -0
  60. package/dist/modules/payments/types.js +3 -0
  61. package/dist/modules/payments/types.js.map +1 -0
  62. package/dist/modules/user/userModel.d.ts +78 -0
  63. package/dist/modules/user/userModel.d.ts.map +1 -0
  64. package/dist/modules/user/userModel.js +3 -0
  65. package/dist/modules/user/userModel.js.map +1 -0
  66. package/dist/modules/user/userRepository.d.ts +22 -0
  67. package/dist/modules/user/userRepository.d.ts.map +1 -0
  68. package/dist/modules/user/userRepository.js +47 -0
  69. package/dist/modules/user/userRepository.js.map +1 -0
  70. package/dist/types/function.d.ts +3 -0
  71. package/dist/types/function.d.ts.map +1 -0
  72. package/dist/types/function.js +3 -0
  73. package/dist/types/function.js.map +1 -0
  74. package/dist/types/utilities.d.ts +10 -0
  75. package/dist/types/utilities.d.ts.map +1 -0
  76. package/dist/types/utilities.js +3 -0
  77. package/dist/types/utilities.js.map +1 -0
  78. package/dist/utils.d.ts +10 -0
  79. package/dist/utils.d.ts.map +1 -0
  80. package/dist/utils.js +45 -0
  81. package/dist/utils.js.map +1 -0
  82. package/package.json +55 -45
package/README.md CHANGED
@@ -1,18 +1,18 @@
1
1
  # @miit-bot/payment-utils
2
2
 
3
- A TypeScript utility library for payment validation and formatting. This library provides robust validation for credit card numbers, payment amounts, CVV codes, and formatting utilities for displaying payment information.
3
+ Personal TypeScript library for managing payments and invoices in my bot applications. Built specifically for Wayforpay integration with Firebase/Firestore backend.
4
4
 
5
- ## Features
5
+ ## Purpose
6
6
 
7
- - 💳 Credit card validation with Luhn algorithm
8
- - 🏦 Automatic card type detection (Visa, Mastercard, Amex, Discover)
9
- - 💰 Payment amount validation with customizable limits
10
- - 🔒 CVV/CVC validation
11
- - 🎨 Card number formatting and masking
12
- - 🌍 Currency formatting with internationalization support
13
- - 📅 Expiry date formatting
14
- - 🔧 Written in TypeScript with full type definitions
15
- - Zero dependencies (dev dependencies only)
7
+ This is a private utility library I use across my bot projects to handle:
8
+
9
+ - Payment processing with Wayforpay
10
+ - Invoice management and webhook handling
11
+ - Payment lifecycle tracking (pending completed/failed/expired)
12
+ - Multi-platform support (Telegram, web, etc.)
13
+ - Expired payment cleanup
14
+
15
+ Also includes some legacy payment validation and formatting utilities.
16
16
 
17
17
  ## Installation
18
18
 
@@ -20,226 +20,342 @@ A TypeScript utility library for payment validation and formatting. This library
20
20
  npm install @miit-bot/payment-utils
21
21
  ```
22
22
 
23
- or
23
+ ## Setup
24
24
 
25
- ```bash
26
- yarn add @miit-bot/payment-utils
25
+ ### Firebase Initialization
26
+
27
+ Initialize Firebase Admin SDK before using payment/invoice services:
28
+
29
+ ```typescript
30
+ import * as admin from 'firebase-admin';
31
+
32
+ admin.initializeApp({
33
+ credential: admin.credential.cert({
34
+ projectId: 'your-project-id',
35
+ clientEmail: 'your-client-email',
36
+ privateKey: 'your-private-key',
37
+ }),
38
+ });
27
39
  ```
28
40
 
41
+ ### Required Firestore Collections
42
+
43
+ - `payments` - Payment records
44
+ - `invoices` - Invoice records from Wayforpay webhooks
45
+
29
46
  ## Usage
30
47
 
31
- ### Card Validation
48
+ ### PaymentService
49
+
50
+ Manages payment lifecycle from creation to completion.
32
51
 
33
52
  ```typescript
34
- import { validateCardNumber, CardType } from '@miit-bot/payment-utils';
53
+ import { PaymentService } from '@miit-bot/payment-utils';
54
+
55
+ const logger = {
56
+ error: (params) => console.error(params),
57
+ info: (params) => console.info(params),
58
+ warn: (params) => console.warn(params),
59
+ debug: (params) => console.debug(params),
60
+ };
61
+
62
+ const paymentService = new PaymentService(logger);
63
+
64
+ // Create payment when user initiates purchase
65
+ const payment = await paymentService.create({
66
+ orderReference: 'ORDER_123456',
67
+ userId: 'user_abc',
68
+ status: 'pending',
69
+ paymentLink: 'https://wayforpay.com/pay/...',
70
+ planId: 'premium_monthly',
71
+ amount: 99.99,
72
+ currency: 'USD',
73
+ createdAt: new Date().toISOString(),
74
+ platform: 'telegram',
75
+ provider: 'wayforpay',
76
+ });
35
77
 
36
- // Validate a credit card number
37
- const result = validateCardNumber('4532015112830366');
38
- console.log(result);
39
- // {
40
- // isValid: true,
41
- // cardType: 'VISA',
42
- // message: 'Valid card number'
43
- // }
44
- ```
78
+ // Retrieve by order reference
79
+ const payment = await paymentService.getByOrderReference('ORDER_123456');
45
80
 
46
- ### Amount Validation
81
+ // Get user's payment history
82
+ const userPayments = await paymentService.getByUserId({
83
+ userId: 'user_abc',
84
+ appNamespace: 'telegram',
85
+ status: 'completed', // optional filter
86
+ });
47
87
 
48
- ```typescript
49
- import { validateAmount } from '@miit-bot/payment-utils';
88
+ // Update payment status (e.g., after webhook)
89
+ await paymentService.updateFields({
90
+ orderReference: 'ORDER_123456',
91
+ fields: [
92
+ ['status', 'completed'],
93
+ ['invoiceId', 'invoice_xyz'],
94
+ ],
95
+ });
50
96
 
51
- // Validate payment amount
52
- const result = validateAmount(99.99);
53
- console.log(result);
54
- // {
55
- // isValid: true,
56
- // amount: 99.99,
57
- // message: 'Valid amount'
58
- // }
59
-
60
- // With custom limits
61
- const customResult = validateAmount(150.0, 10, 100);
62
- console.log(customResult);
63
- // {
64
- // isValid: false,
65
- // amount: 150,
66
- // message: 'Amount must not exceed 100'
67
- // }
97
+ // Find expired pending payments for cleanup
98
+ const expiredPayments = await paymentService.getExpiredPendingPayments({
99
+ hoursOld: 24, // default: 24
100
+ });
68
101
  ```
69
102
 
70
- ### CVV Validation
103
+ ### InvoiceService
71
104
 
72
- ```typescript
73
- import { validateCVV, CardType } from '@miit-bot/payment-utils';
105
+ Stores invoice data from Wayforpay webhooks.
74
106
 
75
- // Validate CVV
76
- const isValid = validateCVV('123'); // true
107
+ ```typescript
108
+ import { InvoiceService } from '@miit-bot/payment-utils';
109
+
110
+ const invoiceService = new InvoiceService(logger);
111
+
112
+ // Create invoice from webhook data
113
+ const invoice = await invoiceService.create({
114
+ merchantAccount: 'merchant_123',
115
+ orderReference: 'ORDER_123456',
116
+ merchantSignature: 'signature_hash',
117
+ reasonCode: 1100,
118
+ reason: 'Payment successful',
119
+ createdDate: Date.now(),
120
+ processingDate: Date.now(),
121
+ currency: 'USD',
122
+ amount: 99.99,
123
+ });
77
124
 
78
- // Validate Amex CVV (4 digits)
79
- const isValidAmex = validateCVV('1234', CardType.AMEX); // true
125
+ // Retrieve invoice
126
+ const invoice = await invoiceService.getByOrderReference('ORDER_123456');
80
127
  ```
81
128
 
82
- ### Card Formatting
83
-
84
- ```typescript
85
- import { formatCardNumber, maskCardNumber } from '@miit-bot/payment-utils';
129
+ ## Typical Workflow
86
130
 
87
- // Format card number with spaces
88
- const formatted = formatCardNumber('4532015112830366');
89
- console.log(formatted); // '4532 0151 1283 0366'
131
+ ### 1. User Initiates Payment
90
132
 
91
- // Format and mask
92
- const masked = formatCardNumber('4532015112830366', true);
93
- console.log(masked); // '**** **** **** 0366'
133
+ ```typescript
134
+ const payment = await paymentService.create({
135
+ orderReference: generateOrderReference(),
136
+ userId: user.id,
137
+ status: 'pending',
138
+ paymentLink: wayforpayUrl,
139
+ planId: 'premium_monthly',
140
+ amount: 99.99,
141
+ currency: 'USD',
142
+ createdAt: new Date().toISOString(),
143
+ platform: 'telegram',
144
+ provider: 'wayforpay',
145
+ });
94
146
 
95
- // Custom masking
96
- const customMask = maskCardNumber('4532015112830366', 4, 'X');
97
- console.log(customMask); // 'XXXXXXXXXXXX0366'
147
+ // Send link to user
148
+ sendPaymentLink(payment.paymentLink);
98
149
  ```
99
150
 
100
- ### Currency Formatting
151
+ ### 2. Wayforpay Webhook Handler
101
152
 
102
153
  ```typescript
103
- import { formatCurrency } from '@miit-bot/payment-utils';
154
+ // Update payment status
155
+ await paymentService.updateFields({
156
+ orderReference: webhookData.orderReference,
157
+ fields: [['status', 'completed']],
158
+ });
104
159
 
105
- // Format as USD
106
- const usd = formatCurrency(1234.56);
107
- console.log(usd); // '$1,234.56'
160
+ // Save invoice
161
+ const invoice = await invoiceService.create({
162
+ merchantAccount: webhookData.merchantAccount,
163
+ orderReference: webhookData.orderReference,
164
+ merchantSignature: webhookData.merchantSignature,
165
+ reasonCode: webhookData.reasonCode,
166
+ reason: webhookData.reason,
167
+ createdDate: webhookData.createdDate,
168
+ processingDate: webhookData.processingDate,
169
+ currency: webhookData.currency,
170
+ amount: webhookData.amount,
171
+ });
108
172
 
109
- // Format with custom locale and currency
110
- const eur = formatCurrency(1234.56, {
111
- locale: 'de-DE',
112
- currency: 'EUR',
173
+ // Link invoice to payment
174
+ await paymentService.updateFields({
175
+ orderReference: webhookData.orderReference,
176
+ fields: [['invoiceId', invoice.id]],
113
177
  });
114
- console.log(eur); // '1.234,56 €'
115
178
  ```
116
179
 
117
- ### Expiry Date Formatting
180
+ ### 3. Cleanup Expired Payments (Cron Job)
118
181
 
119
182
  ```typescript
120
- import { formatExpiryDate } from '@miit-bot/payment-utils';
121
-
122
- // Format expiry date
123
- const expiry = formatExpiryDate(12, 2025);
124
- console.log(expiry); // '12/25'
183
+ async function cleanupExpiredPayments() {
184
+ const expired = await paymentService.getExpiredPendingPayments({ hoursOld: 24 });
185
+
186
+ for (const payment of expired) {
187
+ await paymentService.updateFields({
188
+ orderReference: payment.orderReference,
189
+ fields: [['status', 'expired']],
190
+ });
191
+ }
192
+ }
125
193
  ```
126
194
 
127
195
  ## API Reference
128
196
 
197
+ ### PaymentService
198
+
199
+ **Methods:**
200
+
201
+ - `getByOrderReference(orderReference: string): Promise<PaymentEntity | null>`
202
+ - `getByUserId(params: { userId: string; appNamespace: AppNamespace; status?: PaymentStatus }): Promise<PaymentEntity[]>`
203
+ - `create(paymentData: Omit<PaymentEntity, 'id'>): Promise<PaymentEntity>`
204
+ - `updateFields(params: { orderReference: string; fields: UpdateDBPaymentFields }): Promise<void>`
205
+ - `getExpiredPendingPayments(params?: { hoursOld?: number }): Promise<PaymentEntity[]>`
206
+
207
+ ### InvoiceService
208
+
209
+ **Methods:**
210
+
211
+ - `create(invoiceData: Omit<InvoiceEntity, 'id'>): Promise<InvoiceEntity>`
212
+ - `getByOrderReference(orderReference: string): Promise<InvoiceEntity | null>`
213
+
129
214
  ### Types
130
215
 
131
- #### CardType
216
+ #### PaymentEntity
132
217
 
133
218
  ```typescript
134
- enum CardType {
135
- VISA = 'VISA',
136
- MASTERCARD = 'MASTERCARD',
137
- AMEX = 'AMEX',
138
- DISCOVER = 'DISCOVER',
139
- UNKNOWN = 'UNKNOWN',
219
+ interface PaymentEntity {
220
+ id?: string;
221
+ orderReference: string;
222
+ userId: string;
223
+ status: 'pending' | 'completed' | 'failed' | 'expired';
224
+ paymentLink: string;
225
+ planId: string;
226
+ amount: number;
227
+ currency: 'UAH' | 'USD';
228
+ createdAt: string;
229
+ invoiceId?: string;
230
+ platform: AppNamespace;
231
+ provider: 'wayforpay';
140
232
  }
141
233
  ```
142
234
 
143
- #### CardValidationResult
235
+ #### InvoiceEntity
144
236
 
145
237
  ```typescript
146
- interface CardValidationResult {
147
- isValid: boolean;
148
- cardType: CardType;
149
- message?: string;
238
+ interface InvoiceEntity {
239
+ id: string;
240
+ merchantAccount: string;
241
+ orderReference: string;
242
+ merchantSignature: string;
243
+ reasonCode: number;
244
+ reason: string;
245
+ createdDate: number;
246
+ processingDate: number;
247
+ currency: string;
248
+ amount: number;
150
249
  }
151
250
  ```
152
251
 
153
- #### AmountValidationResult
252
+ #### Logger Interface
154
253
 
155
254
  ```typescript
156
- interface AmountValidationResult {
157
- isValid: boolean;
158
- amount?: number;
159
- message?: string;
255
+ interface Logger {
256
+ error(params: { message: string; payload?: any }): void;
257
+ info(params: { message: string; payload?: any }): void;
258
+ warn(params: { message: string; payload?: any }): void;
259
+ debug(params: { message: string; payload?: any }): void;
160
260
  }
161
261
  ```
162
262
 
163
- ### Validators
263
+ ## Legacy Validation & Formatting
164
264
 
165
- #### validateCardNumber(cardNumber: string): CardValidationResult
166
-
167
- Validates a credit card number using the Luhn algorithm and detects the card type.
265
+ ### Card Validation
168
266
 
169
- #### validateAmount(amount: string | number, minAmount?: number, maxAmount?: number): AmountValidationResult
267
+ ```typescript
268
+ import { validateCardNumber, CardType } from '@miit-bot/payment-utils';
170
269
 
171
- Validates a payment amount with optional min/max limits. Defaults: min=0.01, max=999999.99
270
+ const result = validateCardNumber('4532015112830366');
271
+ // { isValid: true, cardType: 'VISA', message: 'Valid card number' }
272
+ ```
172
273
 
173
- #### validateCVV(cvv: string, cardType?: CardType): boolean
274
+ ### Amount Validation
174
275
 
175
- Validates a CVV/CVC code. Returns true if valid (3 digits for most cards, 4 for Amex).
276
+ ```typescript
277
+ import { validateAmount } from '@miit-bot/payment-utils';
176
278
 
177
- ### Formatters
279
+ const result = validateAmount(99.99);
280
+ // { isValid: true, amount: 99.99, message: 'Valid amount' }
281
+ ```
178
282
 
179
- #### formatCardNumber(cardNumber: string, maskDigits?: boolean): string
283
+ ### CVV Validation
180
284
 
181
- Formats a card number with spaces. Optionally masks all but the last 4 digits.
285
+ ```typescript
286
+ import { validateCVV, CardType } from '@miit-bot/payment-utils';
182
287
 
183
- #### formatCurrency(amount: number, options?: CurrencyFormatOptions): string
288
+ const isValid = validateCVV('123'); // true
289
+ const isValidAmex = validateCVV('1234', CardType.AMEX); // true
290
+ ```
184
291
 
185
- Formats a number as currency with internationalization support.
292
+ ### Card Formatting
186
293
 
187
- #### maskCardNumber(cardNumber: string, visibleDigits?: number, maskChar?: string): string
294
+ ```typescript
295
+ import { formatCardNumber, maskCardNumber } from '@miit-bot/payment-utils';
188
296
 
189
- Masks a card number showing only the last N digits.
297
+ formatCardNumber('4532015112830366'); // '4532 0151 1283 0366'
298
+ formatCardNumber('4532015112830366', true); // '**** **** **** 0366'
299
+ maskCardNumber('4532015112830366', 4, 'X'); // 'XXXXXXXXXXXX0366'
300
+ ```
190
301
 
191
- #### formatExpiryDate(month: number, year: number): string
302
+ ### Currency Formatting
192
303
 
193
- Formats an expiry date to MM/YY format.
304
+ ```typescript
305
+ import { formatCurrency } from '@miit-bot/payment-utils';
194
306
 
195
- ## Development
307
+ formatCurrency(1234.56); // '$1,234.56'
308
+ formatCurrency(1234.56, { locale: 'de-DE', currency: 'EUR' }); // '1.234,56 €'
309
+ ```
196
310
 
197
- ### Setup
311
+ ### Expiry Date Formatting
198
312
 
199
- ```bash
200
- # Install dependencies
201
- npm install
313
+ ```typescript
314
+ import { formatExpiryDate } from '@miit-bot/payment-utils';
202
315
 
203
- # Build the library
204
- npm run build
316
+ formatExpiryDate(12, 2025); // '12/25'
317
+ ```
205
318
 
206
- # Run linter
207
- npm run lint
319
+ ## Architecture
208
320
 
209
- # Format code
210
- npm run format
321
+ **Service Layer** - Business logic and error handling
211
322
 
212
- # Watch mode for development
213
- npm run watch
214
- ```
323
+ - `PaymentService` - Payment operations
324
+ - `InvoiceService` - Invoice operations
215
325
 
216
- ### Building
326
+ **Repository Layer** - Database operations
217
327
 
218
- The library is built using TypeScript compiler. The build output is in the `dist` folder with:
328
+ - `PaymentRepository` - Firestore queries for payments
329
+ - `InvoiceRepository` - Firestore queries for invoices
219
330
 
220
- - Compiled JavaScript files
221
- - Type declaration files (.d.ts)
222
- - Source maps
331
+ Benefits: Clean separation, easy testing, type-safe.
223
332
 
224
- ### Publishing
333
+ ## Development
225
334
 
226
335
  ```bash
227
- # Build and publish to npm
228
- npm publish
229
- ```
336
+ # Install
337
+ npm install
230
338
 
231
- ## License
339
+ # Build
340
+ npm run build
232
341
 
233
- MIT
342
+ # Lint
343
+ npm run lint
234
344
 
235
- ## Contributing
345
+ # Format
346
+ npm run format
236
347
 
237
- Contributions are welcome! Please feel free to submit a Pull Request.
348
+ # Watch
349
+ npm run watch
350
+ ```
238
351
 
239
- ## Author
352
+ ### Dependencies
240
353
 
241
- Your Name
354
+ - **firebase-admin** - Peer dependency for Firestore
355
+ - **TypeScript** - Dev dependency
356
+ - **ESLint** - Dev dependency
357
+ - **Prettier** - Dev dependency
242
358
 
243
- ## Repository
359
+ ## License
244
360
 
245
- https://github.com/yourusername/miit-bot-payment
361
+ MIT
package/dist/index.d.ts CHANGED
@@ -1,8 +1,3 @@
1
- /**
2
- * @miit-bot/payment-utils
3
- * A TypeScript utility library for payment validation and formatting
4
- */
5
- export * from './types';
6
- export { validateCardNumber, validateAmount, validateCVV } from './validators';
7
- export { formatCardNumber, formatCurrency, maskCardNumber, formatExpiryDate } from './formatters';
1
+ export * from './modules/payments';
2
+ export * from './modules/invoice';
8
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAG/E,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -1,8 +1,4 @@
1
1
  "use strict";
2
- /**
3
- * @miit-bot/payment-utils
4
- * A TypeScript utility library for payment validation and formatting
5
- */
6
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
3
  if (k2 === undefined) k2 = k;
8
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -18,18 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
19
15
  };
20
16
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.formatExpiryDate = exports.maskCardNumber = exports.formatCurrency = exports.formatCardNumber = exports.validateCVV = exports.validateAmount = exports.validateCardNumber = void 0;
22
- // Export types
23
- __exportStar(require("./types"), exports);
24
- // Export validators
25
- var validators_1 = require("./validators");
26
- Object.defineProperty(exports, "validateCardNumber", { enumerable: true, get: function () { return validators_1.validateCardNumber; } });
27
- Object.defineProperty(exports, "validateAmount", { enumerable: true, get: function () { return validators_1.validateAmount; } });
28
- Object.defineProperty(exports, "validateCVV", { enumerable: true, get: function () { return validators_1.validateCVV; } });
29
- // Export formatters
30
- var formatters_1 = require("./formatters");
31
- Object.defineProperty(exports, "formatCardNumber", { enumerable: true, get: function () { return formatters_1.formatCardNumber; } });
32
- Object.defineProperty(exports, "formatCurrency", { enumerable: true, get: function () { return formatters_1.formatCurrency; } });
33
- Object.defineProperty(exports, "maskCardNumber", { enumerable: true, get: function () { return formatters_1.maskCardNumber; } });
34
- Object.defineProperty(exports, "formatExpiryDate", { enumerable: true, get: function () { return formatters_1.formatExpiryDate; } });
17
+ __exportStar(require("./modules/payments"), exports);
18
+ __exportStar(require("./modules/invoice"), exports);
35
19
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;AAEH,eAAe;AACf,0CAAwB;AAExB,oBAAoB;AACpB,2CAA+E;AAAtE,gHAAA,kBAAkB,OAAA;AAAE,4GAAA,cAAc,OAAA;AAAE,yGAAA,WAAW,OAAA;AAExD,oBAAoB;AACpB,2CAAkG;AAAzF,8GAAA,gBAAgB,OAAA;AAAE,4GAAA,cAAc,OAAA;AAAE,4GAAA,cAAc,OAAA;AAAE,8GAAA,gBAAgB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,oDAAkC"}
@@ -0,0 +1,2 @@
1
+ export type AppNamespace = 'app' | 'telegram';
2
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/modules/app/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,UAAU,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/modules/app/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,17 @@
1
+ import { SimpleFn } from '../../types/function';
2
+ import { AppNamespace } from '../app/types';
3
+ type DefaultParams = Record<string, unknown> & {
4
+ userId: string;
5
+ appNamespace: AppNamespace;
6
+ };
7
+ declare function wrapCancellableAPI<T extends SimpleFn, TParams extends any[] = Parameters<T> extends never[] ? [DefaultParams] : Parameters<T> & [DefaultParams]>(api: T, props?: {
8
+ timeout?: number;
9
+ }): (...args: TParams) => Promise<Awaited<ReturnType<T>> | never>;
10
+ declare function wrapTimeoutAPI<T extends SimpleFn, TParams extends any[] = Parameters<T> extends never[] ? [DefaultParams] : Parameters<T> & [DefaultParams]>(api: T, props?: {
11
+ timeout?: number;
12
+ }): (...args: TParams) => Promise<Awaited<ReturnType<T>> | never>;
13
+ declare function wrapRawTimeoutAPI<T extends SimpleFn, TParams extends any[] = Parameters<T>>(api: T, props?: {
14
+ timeout?: number;
15
+ }): (...args: TParams) => Promise<Awaited<ReturnType<T>> | never>;
16
+ export { wrapCancellableAPI, wrapTimeoutAPI, wrapRawTimeoutAPI };
17
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/modules/cancellableAPI/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,KAAK,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,YAAY,CAAC;CAC9B,CAAC;AAEF,iBAAS,kBAAkB,CACvB,CAAC,SAAS,QAAQ,EAClB,OAAO,SAAS,GAAG,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,SAAS,KAAK,EAAE,GAAG,CAAC,aAAa,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,EAC3G,GAAG,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,IACjB,GAAG,MAAM,OAAO,KAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAW9E;AAED,iBAAS,cAAc,CACnB,CAAC,SAAS,QAAQ,EAClB,OAAO,SAAS,GAAG,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,SAAS,KAAK,EAAE,GAAG,CAAC,aAAa,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,EAC3G,GAAG,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,IACjB,GAAG,MAAM,OAAO,KAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAW9E;AAED,iBAAS,iBAAiB,CAAC,CAAC,SAAS,QAAQ,EAAE,OAAO,SAAS,GAAG,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,EAChF,GAAG,EAAE,CAAC,EACN,KAAK,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,IAEX,GAAG,MAAM,OAAO,KAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAW9E;AAED,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,iBAAiB,EAAE,CAAC"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.wrapCancellableAPI = wrapCancellableAPI;
4
+ exports.wrapTimeoutAPI = wrapTimeoutAPI;
5
+ exports.wrapRawTimeoutAPI = wrapRawTimeoutAPI;
6
+ const utils_1 = require("../network/utils");
7
+ function wrapCancellableAPI(api, props) {
8
+ return function (...args) {
9
+ const { promise: timeoutPromise, cleanUp } = (0, utils_1.mockTimeoutResponse)({
10
+ timeout: props?.timeout,
11
+ });
12
+ return Promise.race([api(...args), timeoutPromise])
13
+ .catch((e) => {
14
+ throw e;
15
+ })
16
+ .finally(cleanUp);
17
+ };
18
+ }
19
+ function wrapTimeoutAPI(api, props) {
20
+ return function (...args) {
21
+ const { promise: timeoutPromise, cleanUp } = (0, utils_1.mockTimeoutResponse)({
22
+ timeout: props?.timeout,
23
+ });
24
+ return Promise.race([api(...args), timeoutPromise])
25
+ .catch((e) => {
26
+ throw e;
27
+ })
28
+ .finally(cleanUp);
29
+ };
30
+ }
31
+ function wrapRawTimeoutAPI(api, props) {
32
+ return function (...args) {
33
+ const { promise: timeoutPromise, cleanUp } = (0, utils_1.mockTimeoutResponse)({
34
+ timeout: props?.timeout,
35
+ });
36
+ return Promise.race([api(...args), timeoutPromise])
37
+ .catch((e) => {
38
+ throw e;
39
+ })
40
+ .finally(cleanUp);
41
+ };
42
+ }
43
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/modules/cancellableAPI/utils.ts"],"names":[],"mappings":";;AA4DS,gDAAkB;AAAE,wCAAc;AAAE,8CAAiB;AA1D9D,4CAAuD;AAOvD,SAAS,kBAAkB,CAGzB,GAAM,EAAE,KAA4B;IAClC,OAAO,UAAU,GAAG,IAAa;QAC7B,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,IAAA,2BAAmB,EAAC;YAC7D,OAAO,EAAE,KAAK,EAAE,OAAO;SAC1B,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,EAAE,cAAc,CAAC,CAAC;aAC9C,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;YACT,MAAM,CAAC,CAAC;QACZ,CAAC,CAAC;aACD,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC,CAAC;AACN,CAAC;AAED,SAAS,cAAc,CAGrB,GAAM,EAAE,KAA4B;IAClC,OAAO,UAAU,GAAG,IAAa;QAC7B,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,IAAA,2BAAmB,EAAC;YAC7D,OAAO,EAAE,KAAK,EAAE,OAAO;SAC1B,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,EAAE,cAAc,CAAC,CAAC;aAC9C,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;YACT,MAAM,CAAC,CAAC;QACZ,CAAC,CAAC;aACD,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC,CAAC;AACN,CAAC;AAED,SAAS,iBAAiB,CACtB,GAAM,EACN,KAA4B;IAE5B,OAAO,UAAU,GAAG,IAAa;QAC7B,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,IAAA,2BAAmB,EAAC;YAC7D,OAAO,EAAE,KAAK,EAAE,OAAO;SAC1B,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,EAAE,cAAc,CAAC,CAAC;aAC9C,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;YACT,MAAM,CAAC,CAAC;QACZ,CAAC,CAAC;aACD,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC,CAAC;AACN,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { InvoiceEntity } from './types';
2
+ declare const DEFAULT_INVOICE_ENTITY: Partial<InvoiceEntity>;
3
+ export { DEFAULT_INVOICE_ENTITY };
4
+ //# sourceMappingURL=const.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../../src/modules/invoice/const.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,QAAA,MAAM,sBAAsB,EAAE,OAAO,CAAC,aAAa,CAElD,CAAC;AAEF,OAAO,EAAE,sBAAsB,EAAE,CAAC"}