@nehorai/payments 0.1.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.
- package/LICENSE +21 -0
- package/dist/config/index.cjs +116 -0
- package/dist/config/index.cjs.map +1 -0
- package/dist/config/index.d.cts +125 -0
- package/dist/config/index.d.ts +125 -0
- package/dist/config/index.js +83 -0
- package/dist/config/index.js.map +1 -0
- package/dist/factory.cjs +807 -0
- package/dist/factory.cjs.map +1 -0
- package/dist/factory.d.cts +96 -0
- package/dist/factory.d.ts +96 -0
- package/dist/factory.js +777 -0
- package/dist/factory.js.map +1 -0
- package/dist/index.cjs +1341 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +40 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +1260 -0
- package/dist/index.js.map +1 -0
- package/dist/payment-orchestrator-CPaLmDM5.d.ts +404 -0
- package/dist/payment-orchestrator-Co_X6T_V.d.cts +404 -0
- package/dist/payment-types-68W-PlGg.d.cts +211 -0
- package/dist/payment-types-68W-PlGg.d.ts +211 -0
- package/dist/providers/interfaces/index.cjs +19 -0
- package/dist/providers/interfaces/index.cjs.map +1 -0
- package/dist/providers/interfaces/index.d.cts +80 -0
- package/dist/providers/interfaces/index.d.ts +80 -0
- package/dist/providers/interfaces/index.js +1 -0
- package/dist/providers/interfaces/index.js.map +1 -0
- package/dist/repository/interfaces/index.cjs +19 -0
- package/dist/repository/interfaces/index.cjs.map +1 -0
- package/dist/repository/interfaces/index.d.cts +556 -0
- package/dist/repository/interfaces/index.d.ts +556 -0
- package/dist/repository/interfaces/index.js +1 -0
- package/dist/repository/interfaces/index.js.map +1 -0
- package/dist/routing-engine.interface-DJzGXor9.d.cts +194 -0
- package/dist/routing-engine.interface-h9_GmQ4b.d.ts +194 -0
- package/dist/services/index.cjs +806 -0
- package/dist/services/index.cjs.map +1 -0
- package/dist/services/index.d.cts +75 -0
- package/dist/services/index.d.ts +75 -0
- package/dist/services/index.js +763 -0
- package/dist/services/index.js.map +1 -0
- package/dist/state-machine-Cu6_qKnv.d.cts +109 -0
- package/dist/state-machine-Cu6_qKnv.d.ts +109 -0
- package/dist/types/index.cjs +173 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +127 -0
- package/dist/types/index.d.ts +127 -0
- package/dist/types/index.js +130 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.cjs +167 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +102 -0
- package/dist/utils/index.d.ts +102 -0
- package/dist/utils/index.js +127 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,556 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nehorai/payments Repository - Base Interfaces
|
|
3
|
+
*
|
|
4
|
+
* Common types and base interface for all repositories.
|
|
5
|
+
* Framework-agnostic - works with any database adapter.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Pagination parameters
|
|
9
|
+
*/
|
|
10
|
+
interface PaginationParams {
|
|
11
|
+
limit?: number;
|
|
12
|
+
offset?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Paginated response wrapper
|
|
16
|
+
*/
|
|
17
|
+
interface PaginatedResult<T> {
|
|
18
|
+
data: T[];
|
|
19
|
+
total: number;
|
|
20
|
+
limit: number;
|
|
21
|
+
offset: number;
|
|
22
|
+
hasMore: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Date range filter
|
|
26
|
+
*/
|
|
27
|
+
interface DateRangeFilter {
|
|
28
|
+
from?: Date;
|
|
29
|
+
to?: Date;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Sort direction
|
|
33
|
+
*/
|
|
34
|
+
type SortDirection = 'asc' | 'desc';
|
|
35
|
+
/**
|
|
36
|
+
* Sort parameter
|
|
37
|
+
*/
|
|
38
|
+
interface SortParam<T extends string = string> {
|
|
39
|
+
field: T;
|
|
40
|
+
direction: SortDirection;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Base repository interface with common CRUD operations
|
|
44
|
+
*/
|
|
45
|
+
interface IBaseRepository<T, TCreate, TUpdate, TId = string> {
|
|
46
|
+
/**
|
|
47
|
+
* Find entity by ID
|
|
48
|
+
*/
|
|
49
|
+
findById(id: TId): Promise<T | null>;
|
|
50
|
+
/**
|
|
51
|
+
* Create new entity
|
|
52
|
+
*/
|
|
53
|
+
create(data: TCreate): Promise<T>;
|
|
54
|
+
/**
|
|
55
|
+
* Update existing entity
|
|
56
|
+
*/
|
|
57
|
+
update(id: TId, data: TUpdate): Promise<T | null>;
|
|
58
|
+
/**
|
|
59
|
+
* Delete entity by ID
|
|
60
|
+
*/
|
|
61
|
+
delete(id: TId): Promise<boolean>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @nehorai/payments Repository - Transaction Interface
|
|
66
|
+
*
|
|
67
|
+
* Defines operations for payment transaction persistence.
|
|
68
|
+
* Implement this interface to integrate with your database.
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Transaction status (maps to state machine)
|
|
73
|
+
*/
|
|
74
|
+
type TransactionStatus = 'created' | 'pending_authorization' | 'authorized' | 'capturing' | 'captured' | 'voided' | 'failed' | 'expired' | 'partially_refunded' | 'fully_refunded';
|
|
75
|
+
/**
|
|
76
|
+
* Transaction type
|
|
77
|
+
*/
|
|
78
|
+
type TransactionType = 'one_time_purchase' | 'subscription_initial' | 'subscription_renewal' | 'refund';
|
|
79
|
+
/**
|
|
80
|
+
* Tax invoice status
|
|
81
|
+
*/
|
|
82
|
+
type TaxInvoiceStatus = 'pending' | 'generated' | 'sent' | 'failed';
|
|
83
|
+
/**
|
|
84
|
+
* Provider name - generic string identifier
|
|
85
|
+
*/
|
|
86
|
+
type ProviderName = string;
|
|
87
|
+
/**
|
|
88
|
+
* Transaction entity
|
|
89
|
+
*/
|
|
90
|
+
interface Transaction {
|
|
91
|
+
id: string;
|
|
92
|
+
internalPaymentId: string;
|
|
93
|
+
idempotencyKey: string | null;
|
|
94
|
+
userId: string;
|
|
95
|
+
transactionType: TransactionType;
|
|
96
|
+
status: TransactionStatus;
|
|
97
|
+
amountMinor: number;
|
|
98
|
+
currency: string;
|
|
99
|
+
originalAmountMinor: number | null;
|
|
100
|
+
originalCurrency: string | null;
|
|
101
|
+
currencyConversionRate: number | null;
|
|
102
|
+
provider: ProviderName;
|
|
103
|
+
providerTransactionId: string | null;
|
|
104
|
+
providerAuthorizationCode: string | null;
|
|
105
|
+
providerMetadata: Record<string, unknown> | null;
|
|
106
|
+
authorizedAt: Date | null;
|
|
107
|
+
capturedAt: Date | null;
|
|
108
|
+
voidedAt: Date | null;
|
|
109
|
+
captureDeadline: Date | null;
|
|
110
|
+
refundedAmountMinor: number;
|
|
111
|
+
lastRefundAt: Date | null;
|
|
112
|
+
taxInvoiceStatus: TaxInvoiceStatus;
|
|
113
|
+
taxInvoiceNumber: string | null;
|
|
114
|
+
taxInvoiceUrl: string | null;
|
|
115
|
+
failureCode: string | null;
|
|
116
|
+
failureMessage: string | null;
|
|
117
|
+
failureDetails: Record<string, unknown> | null;
|
|
118
|
+
description: string | null;
|
|
119
|
+
metadata: Record<string, unknown> | null;
|
|
120
|
+
createdAt: Date;
|
|
121
|
+
updatedAt: Date;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Create transaction input
|
|
125
|
+
*/
|
|
126
|
+
interface CreateTransactionInput {
|
|
127
|
+
internalPaymentId: string;
|
|
128
|
+
idempotencyKey?: string;
|
|
129
|
+
userId: string;
|
|
130
|
+
transactionType: TransactionType;
|
|
131
|
+
status?: TransactionStatus;
|
|
132
|
+
amountMinor: number;
|
|
133
|
+
currency: string;
|
|
134
|
+
provider: ProviderName;
|
|
135
|
+
description?: string;
|
|
136
|
+
metadata?: Record<string, unknown>;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Update transaction input
|
|
140
|
+
*/
|
|
141
|
+
interface UpdateTransactionInput {
|
|
142
|
+
status?: TransactionStatus;
|
|
143
|
+
providerTransactionId?: string;
|
|
144
|
+
providerAuthorizationCode?: string;
|
|
145
|
+
providerMetadata?: Record<string, unknown>;
|
|
146
|
+
authorizedAt?: Date;
|
|
147
|
+
capturedAt?: Date;
|
|
148
|
+
voidedAt?: Date;
|
|
149
|
+
captureDeadline?: Date;
|
|
150
|
+
refundedAmountMinor?: number;
|
|
151
|
+
lastRefundAt?: Date;
|
|
152
|
+
taxInvoiceStatus?: TaxInvoiceStatus;
|
|
153
|
+
taxInvoiceNumber?: string;
|
|
154
|
+
taxInvoiceUrl?: string;
|
|
155
|
+
failureCode?: string;
|
|
156
|
+
failureMessage?: string;
|
|
157
|
+
failureDetails?: Record<string, unknown>;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Transaction filter options
|
|
161
|
+
*/
|
|
162
|
+
interface TransactionFilter {
|
|
163
|
+
userId?: string;
|
|
164
|
+
status?: TransactionStatus | TransactionStatus[];
|
|
165
|
+
provider?: ProviderName | ProviderName[];
|
|
166
|
+
transactionType?: TransactionType | TransactionType[];
|
|
167
|
+
dateRange?: DateRangeFilter;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Transaction repository interface
|
|
171
|
+
*/
|
|
172
|
+
interface ITransactionRepository extends IBaseRepository<Transaction, CreateTransactionInput, UpdateTransactionInput> {
|
|
173
|
+
/**
|
|
174
|
+
* Find transaction by internal payment ID
|
|
175
|
+
*/
|
|
176
|
+
findByInternalPaymentId(internalPaymentId: string): Promise<Transaction | null>;
|
|
177
|
+
/**
|
|
178
|
+
* Find transaction by idempotency key
|
|
179
|
+
*/
|
|
180
|
+
findByIdempotencyKey(idempotencyKey: string): Promise<Transaction | null>;
|
|
181
|
+
/**
|
|
182
|
+
* Find transaction by provider transaction ID
|
|
183
|
+
*/
|
|
184
|
+
findByProviderTransactionId(provider: ProviderName, providerTransactionId: string): Promise<Transaction | null>;
|
|
185
|
+
/**
|
|
186
|
+
* Find transactions with filters and pagination
|
|
187
|
+
*/
|
|
188
|
+
findMany(filter: TransactionFilter, pagination?: PaginationParams): Promise<PaginatedResult<Transaction>>;
|
|
189
|
+
/**
|
|
190
|
+
* Find transactions by user ID
|
|
191
|
+
*/
|
|
192
|
+
findByUserId(userId: string, pagination?: PaginationParams): Promise<PaginatedResult<Transaction>>;
|
|
193
|
+
/**
|
|
194
|
+
* Update transaction status (with validation)
|
|
195
|
+
*/
|
|
196
|
+
updateStatus(id: string, status: TransactionStatus, additionalData?: Partial<UpdateTransactionInput>): Promise<Transaction | null>;
|
|
197
|
+
/**
|
|
198
|
+
* Increment refunded amount
|
|
199
|
+
*/
|
|
200
|
+
incrementRefundedAmount(id: string, amountMinor: number): Promise<Transaction | null>;
|
|
201
|
+
/**
|
|
202
|
+
* Find expired authorizations (for cleanup)
|
|
203
|
+
*/
|
|
204
|
+
findExpiredAuthorizations(beforeDate: Date): Promise<Transaction[]>;
|
|
205
|
+
/**
|
|
206
|
+
* Count transactions by status
|
|
207
|
+
*/
|
|
208
|
+
countByStatus(filter?: TransactionFilter): Promise<Record<TransactionStatus, number>>;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* @nehorai/payments Repository - Payment Method Interface
|
|
213
|
+
*
|
|
214
|
+
* Defines operations for saved payment method persistence.
|
|
215
|
+
* Implement this interface to integrate with your database.
|
|
216
|
+
*/
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Payment method type
|
|
220
|
+
*/
|
|
221
|
+
type PaymentMethodType = 'card' | 'bank_account' | 'paypal';
|
|
222
|
+
/**
|
|
223
|
+
* Card brand
|
|
224
|
+
*/
|
|
225
|
+
type CardBrand = 'visa' | 'mastercard' | 'amex' | 'discover' | 'isracard' | 'diners' | 'unknown';
|
|
226
|
+
/**
|
|
227
|
+
* Payment method entity
|
|
228
|
+
*/
|
|
229
|
+
interface PaymentMethod {
|
|
230
|
+
id: string;
|
|
231
|
+
userId: string;
|
|
232
|
+
type: PaymentMethodType;
|
|
233
|
+
provider: ProviderName;
|
|
234
|
+
providerPaymentMethodId: string;
|
|
235
|
+
cardBrand: CardBrand | null;
|
|
236
|
+
cardLast4: string | null;
|
|
237
|
+
cardExpMonth: string | null;
|
|
238
|
+
cardExpYear: string | null;
|
|
239
|
+
cardBin: string | null;
|
|
240
|
+
isDefault: boolean;
|
|
241
|
+
isActive: boolean;
|
|
242
|
+
providerMetadata: Record<string, unknown> | null;
|
|
243
|
+
createdAt: Date;
|
|
244
|
+
updatedAt: Date;
|
|
245
|
+
lastUsedAt: Date | null;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Create payment method input
|
|
249
|
+
*/
|
|
250
|
+
interface CreatePaymentMethodInput {
|
|
251
|
+
userId: string;
|
|
252
|
+
type: PaymentMethodType;
|
|
253
|
+
provider: ProviderName;
|
|
254
|
+
providerPaymentMethodId: string;
|
|
255
|
+
cardBrand?: CardBrand;
|
|
256
|
+
cardLast4?: string;
|
|
257
|
+
cardExpMonth?: string;
|
|
258
|
+
cardExpYear?: string;
|
|
259
|
+
cardBin?: string;
|
|
260
|
+
isDefault?: boolean;
|
|
261
|
+
providerMetadata?: Record<string, unknown>;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Update payment method input
|
|
265
|
+
*/
|
|
266
|
+
interface UpdatePaymentMethodInput {
|
|
267
|
+
isDefault?: boolean;
|
|
268
|
+
isActive?: boolean;
|
|
269
|
+
cardExpMonth?: string;
|
|
270
|
+
cardExpYear?: string;
|
|
271
|
+
lastUsedAt?: Date;
|
|
272
|
+
providerMetadata?: Record<string, unknown>;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Payment method filter options
|
|
276
|
+
*/
|
|
277
|
+
interface PaymentMethodFilter {
|
|
278
|
+
userId?: string;
|
|
279
|
+
provider?: ProviderName | ProviderName[];
|
|
280
|
+
type?: PaymentMethodType | PaymentMethodType[];
|
|
281
|
+
isDefault?: boolean;
|
|
282
|
+
isActive?: boolean;
|
|
283
|
+
cardBin?: string;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Payment method repository interface
|
|
287
|
+
*/
|
|
288
|
+
interface IPaymentMethodRepository extends IBaseRepository<PaymentMethod, CreatePaymentMethodInput, UpdatePaymentMethodInput> {
|
|
289
|
+
findByProviderPaymentMethodId(provider: ProviderName, providerPaymentMethodId: string): Promise<PaymentMethod | null>;
|
|
290
|
+
findByUserId(userId: string, filter?: Partial<PaymentMethodFilter>): Promise<PaymentMethod[]>;
|
|
291
|
+
findDefaultForUser(userId: string): Promise<PaymentMethod | null>;
|
|
292
|
+
findMany(filter: PaymentMethodFilter, pagination?: PaginationParams): Promise<PaginatedResult<PaymentMethod>>;
|
|
293
|
+
setAsDefault(id: string, userId: string): Promise<PaymentMethod | null>;
|
|
294
|
+
deactivate(id: string): Promise<boolean>;
|
|
295
|
+
markAsUsed(id: string): Promise<PaymentMethod | null>;
|
|
296
|
+
findByCardBin(userId: string, cardBin: string): Promise<PaymentMethod[]>;
|
|
297
|
+
countActiveForUser(userId: string): Promise<number>;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* @nehorai/payments Repository - Webhook Event Interface
|
|
302
|
+
*
|
|
303
|
+
* Defines operations for webhook event persistence.
|
|
304
|
+
* Used for idempotent webhook processing.
|
|
305
|
+
*/
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Webhook event processing status
|
|
309
|
+
*/
|
|
310
|
+
type WebhookEventStatus = 'pending' | 'processing' | 'processed' | 'failed' | 'ignored';
|
|
311
|
+
/**
|
|
312
|
+
* Webhook event entity
|
|
313
|
+
*/
|
|
314
|
+
interface WebhookEvent {
|
|
315
|
+
id: string;
|
|
316
|
+
provider: ProviderName;
|
|
317
|
+
providerEventId: string;
|
|
318
|
+
eventType: string;
|
|
319
|
+
status: WebhookEventStatus;
|
|
320
|
+
attempts: number;
|
|
321
|
+
lastAttemptAt: Date | null;
|
|
322
|
+
transactionId: string | null;
|
|
323
|
+
payload: Record<string, unknown>;
|
|
324
|
+
signature: string | null;
|
|
325
|
+
errorMessage: string | null;
|
|
326
|
+
errorDetails: Record<string, unknown> | null;
|
|
327
|
+
receivedAt: Date;
|
|
328
|
+
processedAt: Date | null;
|
|
329
|
+
createdAt: Date;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Create webhook event input
|
|
333
|
+
*/
|
|
334
|
+
interface CreateWebhookEventInput {
|
|
335
|
+
provider: ProviderName;
|
|
336
|
+
providerEventId: string;
|
|
337
|
+
eventType: string;
|
|
338
|
+
payload: Record<string, unknown>;
|
|
339
|
+
signature?: string;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Update webhook event input
|
|
343
|
+
*/
|
|
344
|
+
interface UpdateWebhookEventInput {
|
|
345
|
+
status?: WebhookEventStatus;
|
|
346
|
+
attempts?: number;
|
|
347
|
+
lastAttemptAt?: Date;
|
|
348
|
+
transactionId?: string;
|
|
349
|
+
processedAt?: Date;
|
|
350
|
+
errorMessage?: string;
|
|
351
|
+
errorDetails?: Record<string, unknown>;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Webhook event filter options
|
|
355
|
+
*/
|
|
356
|
+
interface WebhookEventFilter {
|
|
357
|
+
provider?: ProviderName | ProviderName[];
|
|
358
|
+
eventType?: string | string[];
|
|
359
|
+
status?: WebhookEventStatus | WebhookEventStatus[];
|
|
360
|
+
transactionId?: string;
|
|
361
|
+
dateRange?: DateRangeFilter;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Webhook event repository interface
|
|
365
|
+
*/
|
|
366
|
+
interface IWebhookEventRepository extends IBaseRepository<WebhookEvent, CreateWebhookEventInput, UpdateWebhookEventInput> {
|
|
367
|
+
findByProviderEventId(provider: ProviderName, providerEventId: string): Promise<WebhookEvent | null>;
|
|
368
|
+
findByTransactionId(transactionId: string): Promise<WebhookEvent[]>;
|
|
369
|
+
findMany(filter: WebhookEventFilter, pagination?: PaginationParams): Promise<PaginatedResult<WebhookEvent>>;
|
|
370
|
+
findFailedForRetry(maxAttempts: number, olderThan?: Date): Promise<WebhookEvent[]>;
|
|
371
|
+
findPending(limit?: number): Promise<WebhookEvent[]>;
|
|
372
|
+
markAsProcessing(id: string): Promise<boolean>;
|
|
373
|
+
markAsProcessed(id: string, transactionId?: string): Promise<WebhookEvent | null>;
|
|
374
|
+
markAsFailed(id: string, errorMessage: string, errorDetails?: Record<string, unknown>): Promise<WebhookEvent | null>;
|
|
375
|
+
incrementAttempts(id: string): Promise<WebhookEvent | null>;
|
|
376
|
+
isAlreadyProcessed(provider: ProviderName, providerEventId: string): Promise<boolean>;
|
|
377
|
+
countByStatus(filter?: WebhookEventFilter): Promise<Record<WebhookEventStatus, number>>;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* @nehorai/payments Repository - Audit Log Interface
|
|
382
|
+
*
|
|
383
|
+
* Defines operations for payment audit log persistence.
|
|
384
|
+
* Audit logs are immutable - only create and read operations.
|
|
385
|
+
*/
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Audit log action types
|
|
389
|
+
*/
|
|
390
|
+
type AuditLogAction = 'created' | 'status_changed' | 'authorized' | 'captured' | 'voided' | 'refund_initiated' | 'refund_completed' | 'webhook_received' | 'webhook_processed' | 'error_occurred' | 'retry_attempted' | 'manual_intervention';
|
|
391
|
+
/**
|
|
392
|
+
* Who/what triggered the action
|
|
393
|
+
*/
|
|
394
|
+
type AuditLogTrigger = 'user' | 'webhook' | 'system' | 'admin' | 'cron' | 'api';
|
|
395
|
+
/**
|
|
396
|
+
* Audit log entity
|
|
397
|
+
*/
|
|
398
|
+
interface AuditLogEntry {
|
|
399
|
+
id: string;
|
|
400
|
+
transactionId: string;
|
|
401
|
+
action: AuditLogAction;
|
|
402
|
+
previousState: Record<string, unknown> | null;
|
|
403
|
+
newState: Record<string, unknown>;
|
|
404
|
+
triggeredBy: AuditLogTrigger;
|
|
405
|
+
triggeredById: string | null;
|
|
406
|
+
ipAddress: string | null;
|
|
407
|
+
userAgent: string | null;
|
|
408
|
+
correlationId: string | null;
|
|
409
|
+
metadata: Record<string, unknown> | null;
|
|
410
|
+
createdAt: Date;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Create audit log entry input
|
|
414
|
+
*/
|
|
415
|
+
interface CreateAuditLogInput {
|
|
416
|
+
transactionId: string;
|
|
417
|
+
action: AuditLogAction;
|
|
418
|
+
previousState?: Record<string, unknown>;
|
|
419
|
+
newState: Record<string, unknown>;
|
|
420
|
+
triggeredBy: AuditLogTrigger;
|
|
421
|
+
triggeredById?: string;
|
|
422
|
+
ipAddress?: string;
|
|
423
|
+
userAgent?: string;
|
|
424
|
+
correlationId?: string;
|
|
425
|
+
metadata?: Record<string, unknown>;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Audit log filter options
|
|
429
|
+
*/
|
|
430
|
+
interface AuditLogFilter {
|
|
431
|
+
transactionId?: string;
|
|
432
|
+
action?: AuditLogAction | AuditLogAction[];
|
|
433
|
+
triggeredBy?: AuditLogTrigger | AuditLogTrigger[];
|
|
434
|
+
triggeredById?: string;
|
|
435
|
+
correlationId?: string;
|
|
436
|
+
dateRange?: DateRangeFilter;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Audit log repository interface
|
|
440
|
+
* Note: Audit logs are immutable - no update or delete operations
|
|
441
|
+
*/
|
|
442
|
+
interface IAuditLogRepository {
|
|
443
|
+
findById(id: string): Promise<AuditLogEntry | null>;
|
|
444
|
+
create(data: CreateAuditLogInput): Promise<AuditLogEntry>;
|
|
445
|
+
createMany(entries: CreateAuditLogInput[]): Promise<AuditLogEntry[]>;
|
|
446
|
+
findByTransactionId(transactionId: string, pagination?: PaginationParams): Promise<PaginatedResult<AuditLogEntry>>;
|
|
447
|
+
findMany(filter: AuditLogFilter, pagination?: PaginationParams): Promise<PaginatedResult<AuditLogEntry>>;
|
|
448
|
+
findByCorrelationId(correlationId: string): Promise<AuditLogEntry[]>;
|
|
449
|
+
getTransactionHistory(transactionId: string): Promise<AuditLogEntry[]>;
|
|
450
|
+
countByAction(filter?: AuditLogFilter): Promise<Record<AuditLogAction, number>>;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* @nehorai/payments Repository - Provider Health Interface
|
|
455
|
+
*
|
|
456
|
+
* Defines operations for provider health/circuit breaker persistence.
|
|
457
|
+
* Used for tracking provider availability and performance.
|
|
458
|
+
*/
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Circuit breaker states
|
|
462
|
+
*/
|
|
463
|
+
type CircuitBreakerState = 'closed' | 'open' | 'half_open';
|
|
464
|
+
/**
|
|
465
|
+
* Health check result
|
|
466
|
+
*/
|
|
467
|
+
interface HealthCheckResult {
|
|
468
|
+
healthy: boolean;
|
|
469
|
+
latencyMs?: number;
|
|
470
|
+
error?: string;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Provider health entity
|
|
474
|
+
*/
|
|
475
|
+
interface ProviderHealth {
|
|
476
|
+
id: string;
|
|
477
|
+
provider: ProviderName;
|
|
478
|
+
circuitState: CircuitBreakerState;
|
|
479
|
+
failureCount: number;
|
|
480
|
+
successCount: number;
|
|
481
|
+
lastFailureAt: Date | null;
|
|
482
|
+
lastSuccessAt: Date | null;
|
|
483
|
+
circuitOpenedAt: Date | null;
|
|
484
|
+
nextRetryAt: Date | null;
|
|
485
|
+
avgLatencyMs: number | null;
|
|
486
|
+
errorRate: number | null;
|
|
487
|
+
requestCountWindow: number;
|
|
488
|
+
lastHealthCheckAt: Date | null;
|
|
489
|
+
healthCheckResult: HealthCheckResult | null;
|
|
490
|
+
createdAt: Date;
|
|
491
|
+
updatedAt: Date;
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Create provider health input
|
|
495
|
+
*/
|
|
496
|
+
interface CreateProviderHealthInput {
|
|
497
|
+
provider: ProviderName;
|
|
498
|
+
circuitState?: CircuitBreakerState;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Update provider health input
|
|
502
|
+
*/
|
|
503
|
+
interface UpdateProviderHealthInput {
|
|
504
|
+
circuitState?: CircuitBreakerState;
|
|
505
|
+
failureCount?: number;
|
|
506
|
+
successCount?: number;
|
|
507
|
+
lastFailureAt?: Date;
|
|
508
|
+
lastSuccessAt?: Date;
|
|
509
|
+
circuitOpenedAt?: Date;
|
|
510
|
+
nextRetryAt?: Date;
|
|
511
|
+
avgLatencyMs?: number;
|
|
512
|
+
errorRate?: number;
|
|
513
|
+
requestCountWindow?: number;
|
|
514
|
+
lastHealthCheckAt?: Date;
|
|
515
|
+
healthCheckResult?: HealthCheckResult;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Provider health repository interface
|
|
519
|
+
*/
|
|
520
|
+
interface IProviderHealthRepository {
|
|
521
|
+
findByProvider(provider: ProviderName): Promise<ProviderHealth | null>;
|
|
522
|
+
getOrCreate(provider: ProviderName): Promise<ProviderHealth>;
|
|
523
|
+
update(provider: ProviderName, data: UpdateProviderHealthInput): Promise<ProviderHealth | null>;
|
|
524
|
+
findAll(): Promise<ProviderHealth[]>;
|
|
525
|
+
recordSuccess(provider: ProviderName, latencyMs: number): Promise<void>;
|
|
526
|
+
recordFailure(provider: ProviderName, error?: string): Promise<void>;
|
|
527
|
+
openCircuit(provider: ProviderName, retryAfterMs: number): Promise<void>;
|
|
528
|
+
closeCircuit(provider: ProviderName): Promise<void>;
|
|
529
|
+
halfOpenCircuit(provider: ProviderName): Promise<void>;
|
|
530
|
+
updateHealthCheck(provider: ProviderName, result: HealthCheckResult): Promise<void>;
|
|
531
|
+
findOpenCircuits(): Promise<ProviderHealth[]>;
|
|
532
|
+
findReadyForRetry(): Promise<ProviderHealth[]>;
|
|
533
|
+
resetStats(provider: ProviderName): Promise<void>;
|
|
534
|
+
updateErrorRate(provider: ProviderName): Promise<number>;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* @nehorai/payments Repository - Interface Exports
|
|
539
|
+
*
|
|
540
|
+
* All repository interfaces for database-agnostic payment operations.
|
|
541
|
+
* Implement these interfaces to integrate with your database.
|
|
542
|
+
*/
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Combined repository interface for all payment operations.
|
|
546
|
+
* Implement this interface to provide a complete database adapter.
|
|
547
|
+
*/
|
|
548
|
+
interface IPaymentRepositories {
|
|
549
|
+
transactions: ITransactionRepository;
|
|
550
|
+
paymentMethods: IPaymentMethodRepository;
|
|
551
|
+
webhookEvents: IWebhookEventRepository;
|
|
552
|
+
auditLog: IAuditLogRepository;
|
|
553
|
+
providerHealth: IProviderHealthRepository;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
export type { AuditLogAction, AuditLogEntry, AuditLogFilter, AuditLogTrigger, CardBrand, CircuitBreakerState, CreateAuditLogInput, CreatePaymentMethodInput, CreateProviderHealthInput, CreateTransactionInput, CreateWebhookEventInput, DateRangeFilter, HealthCheckResult, IAuditLogRepository, IBaseRepository, IPaymentMethodRepository, IPaymentRepositories, IProviderHealthRepository, ITransactionRepository, IWebhookEventRepository, PaginatedResult, PaginationParams, PaymentMethod, PaymentMethodFilter, PaymentMethodType, ProviderHealth, ProviderName, SortDirection, SortParam, TaxInvoiceStatus, Transaction, TransactionFilter, TransactionStatus, TransactionType, UpdatePaymentMethodInput, UpdateProviderHealthInput, UpdateTransactionInput, UpdateWebhookEventInput, WebhookEvent, WebhookEventFilter, WebhookEventStatus };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|