@nehorai/payments-drizzle 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/index.cjs +1310 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +47 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +1289 -0
- package/dist/index.js.map +1 -0
- package/dist/provider-health.drizzle-repository-DfRo4qJ8.d.cts +185 -0
- package/dist/provider-health.drizzle-repository-DfRo4qJ8.d.ts +185 -0
- package/dist/repositories/index.cjs +1190 -0
- package/dist/repositories/index.cjs.map +1 -0
- package/dist/repositories/index.d.cts +16 -0
- package/dist/repositories/index.d.ts +16 -0
- package/dist/repositories/index.js +1177 -0
- package/dist/repositories/index.js.map +1 -0
- package/dist/schema/index.cjs +276 -0
- package/dist/schema/index.cjs.map +1 -0
- package/dist/schema/index.d.cts +1729 -0
- package/dist/schema/index.d.ts +1729 -0
- package/dist/schema/index.js +269 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/storage/index.cjs +124 -0
- package/dist/storage/index.cjs.map +1 -0
- package/dist/storage/index.d.cts +52 -0
- package/dist/storage/index.d.ts +52 -0
- package/dist/storage/index.js +96 -0
- package/dist/storage/index.js.map +1 -0
- package/package.json +53 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { ITransactionRepository, Transaction, CreateTransactionInput, UpdateTransactionInput, ProviderName, TransactionFilter, PaginationParams, PaginatedResult, TransactionStatus, IPaymentMethodRepository, PaymentMethod, CreatePaymentMethodInput, UpdatePaymentMethodInput, PaymentMethodFilter, IWebhookEventRepository, WebhookEvent, CreateWebhookEventInput, UpdateWebhookEventInput, WebhookEventFilter, WebhookEventStatus, IAuditLogRepository, AuditLogEntry, CreateAuditLogInput, AuditLogFilter, AuditLogAction, IProviderHealthRepository, ProviderHealth, UpdateProviderHealthInput, HealthCheckResult } from '@nehorai/payments/repository';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @nehorai/payments-drizzle - Base Drizzle Repository
|
|
5
|
+
*
|
|
6
|
+
* Common utilities and types for Drizzle repository implementations.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Drizzle database instance type
|
|
10
|
+
* Uses a minimal interface to support any Drizzle database instance.
|
|
11
|
+
* Generic enough to work with any Drizzle PostgreSQL database.
|
|
12
|
+
*/
|
|
13
|
+
type DrizzleDB = {
|
|
14
|
+
select: (...args: any[]) => any;
|
|
15
|
+
insert: (table: any) => any;
|
|
16
|
+
update: (table: any) => any;
|
|
17
|
+
delete: (table: any) => any;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Convert database row to camelCase entity
|
|
21
|
+
*/
|
|
22
|
+
declare function toCamelCase<T extends Record<string, unknown>>(row: Record<string, unknown>): T;
|
|
23
|
+
/**
|
|
24
|
+
* Convert camelCase entity to snake_case for database
|
|
25
|
+
*/
|
|
26
|
+
declare function toSnakeCase<T extends Record<string, unknown>>(obj: Record<string, unknown>): T;
|
|
27
|
+
/**
|
|
28
|
+
* Apply pagination to query results
|
|
29
|
+
*/
|
|
30
|
+
declare function applyPagination<T>(items: T[], total: number, limit: number, offset: number): {
|
|
31
|
+
data: T[];
|
|
32
|
+
total: number;
|
|
33
|
+
limit: number;
|
|
34
|
+
offset: number;
|
|
35
|
+
hasMore: boolean;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Parse numeric string to number (Drizzle returns numeric as string)
|
|
39
|
+
*/
|
|
40
|
+
declare function parseNumeric(value: string | number | null | undefined): number;
|
|
41
|
+
/**
|
|
42
|
+
* Convert array filter to SQL-friendly format
|
|
43
|
+
*/
|
|
44
|
+
declare function normalizeArrayFilter<T>(value: T | T[] | undefined): T[] | undefined;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @nehorai/payments-drizzle - Drizzle Transaction Repository
|
|
48
|
+
*
|
|
49
|
+
* Implements ITransactionRepository using Drizzle ORM.
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Drizzle implementation of ITransactionRepository
|
|
54
|
+
*/
|
|
55
|
+
declare class DrizzleTransactionRepository implements ITransactionRepository {
|
|
56
|
+
private db;
|
|
57
|
+
constructor(db: DrizzleDB);
|
|
58
|
+
findById(id: string): Promise<Transaction | null>;
|
|
59
|
+
create(data: CreateTransactionInput): Promise<Transaction>;
|
|
60
|
+
update(id: string, data: UpdateTransactionInput): Promise<Transaction | null>;
|
|
61
|
+
delete(id: string): Promise<boolean>;
|
|
62
|
+
findByInternalPaymentId(internalPaymentId: string): Promise<Transaction | null>;
|
|
63
|
+
findByIdempotencyKey(idempotencyKey: string): Promise<Transaction | null>;
|
|
64
|
+
findByProviderTransactionId(provider: ProviderName, providerTransactionId: string): Promise<Transaction | null>;
|
|
65
|
+
findMany(filter: TransactionFilter, pagination?: PaginationParams): Promise<PaginatedResult<Transaction>>;
|
|
66
|
+
findByUserId(userId: string, pagination?: PaginationParams): Promise<PaginatedResult<Transaction>>;
|
|
67
|
+
updateStatus(id: string, status: TransactionStatus, additionalData?: Partial<UpdateTransactionInput>): Promise<Transaction | null>;
|
|
68
|
+
incrementRefundedAmount(id: string, amountMinor: number): Promise<Transaction | null>;
|
|
69
|
+
findExpiredAuthorizations(beforeDate: Date): Promise<Transaction[]>;
|
|
70
|
+
countByStatus(filter?: TransactionFilter): Promise<Record<TransactionStatus, number>>;
|
|
71
|
+
private buildFilterConditions;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @nehorai/payments-drizzle - Drizzle Payment Method Repository
|
|
76
|
+
*
|
|
77
|
+
* Implements IPaymentMethodRepository using Drizzle ORM.
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Drizzle implementation of IPaymentMethodRepository
|
|
82
|
+
*/
|
|
83
|
+
declare class DrizzlePaymentMethodRepository implements IPaymentMethodRepository {
|
|
84
|
+
private db;
|
|
85
|
+
constructor(db: DrizzleDB);
|
|
86
|
+
findById(id: string): Promise<PaymentMethod | null>;
|
|
87
|
+
create(data: CreatePaymentMethodInput): Promise<PaymentMethod>;
|
|
88
|
+
update(id: string, data: UpdatePaymentMethodInput): Promise<PaymentMethod | null>;
|
|
89
|
+
delete(id: string): Promise<boolean>;
|
|
90
|
+
findByProviderPaymentMethodId(provider: ProviderName, providerPaymentMethodId: string): Promise<PaymentMethod | null>;
|
|
91
|
+
findByUserId(userId: string, filter?: Partial<PaymentMethodFilter>): Promise<PaymentMethod[]>;
|
|
92
|
+
findDefaultForUser(userId: string): Promise<PaymentMethod | null>;
|
|
93
|
+
findMany(filter: PaymentMethodFilter, pagination?: PaginationParams): Promise<PaginatedResult<PaymentMethod>>;
|
|
94
|
+
setAsDefault(id: string, userId: string): Promise<PaymentMethod | null>;
|
|
95
|
+
deactivate(id: string): Promise<boolean>;
|
|
96
|
+
markAsUsed(id: string): Promise<PaymentMethod | null>;
|
|
97
|
+
findByCardBin(userId: string, cardBin: string): Promise<PaymentMethod[]>;
|
|
98
|
+
countActiveForUser(userId: string): Promise<number>;
|
|
99
|
+
private buildFilterConditions;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @nehorai/payments-drizzle - Drizzle Webhook Event Repository
|
|
104
|
+
*
|
|
105
|
+
* Implements IWebhookEventRepository using Drizzle ORM.
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Drizzle implementation of IWebhookEventRepository
|
|
110
|
+
*/
|
|
111
|
+
declare class DrizzleWebhookEventRepository implements IWebhookEventRepository {
|
|
112
|
+
private db;
|
|
113
|
+
constructor(db: DrizzleDB);
|
|
114
|
+
findById(id: string): Promise<WebhookEvent | null>;
|
|
115
|
+
create(data: CreateWebhookEventInput): Promise<WebhookEvent>;
|
|
116
|
+
update(id: string, data: UpdateWebhookEventInput): Promise<WebhookEvent | null>;
|
|
117
|
+
delete(id: string): Promise<boolean>;
|
|
118
|
+
findByProviderEventId(provider: ProviderName, providerEventId: string): Promise<WebhookEvent | null>;
|
|
119
|
+
findByTransactionId(transactionId: string): Promise<WebhookEvent[]>;
|
|
120
|
+
findMany(filter: WebhookEventFilter, pagination?: PaginationParams): Promise<PaginatedResult<WebhookEvent>>;
|
|
121
|
+
findFailedForRetry(maxAttempts: number, olderThan?: Date): Promise<WebhookEvent[]>;
|
|
122
|
+
findPending(limit?: number): Promise<WebhookEvent[]>;
|
|
123
|
+
markAsProcessing(id: string): Promise<boolean>;
|
|
124
|
+
markAsProcessed(id: string, transactionId?: string): Promise<WebhookEvent | null>;
|
|
125
|
+
markAsFailed(id: string, errorMessage: string, errorDetails?: Record<string, unknown>): Promise<WebhookEvent | null>;
|
|
126
|
+
incrementAttempts(id: string): Promise<WebhookEvent | null>;
|
|
127
|
+
isAlreadyProcessed(provider: ProviderName, providerEventId: string): Promise<boolean>;
|
|
128
|
+
countByStatus(filter?: WebhookEventFilter): Promise<Record<WebhookEventStatus, number>>;
|
|
129
|
+
private buildFilterConditions;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @nehorai/payments-drizzle - Drizzle Audit Log Repository
|
|
134
|
+
*
|
|
135
|
+
* Implements IAuditLogRepository using Drizzle ORM.
|
|
136
|
+
* Audit logs are immutable - only create and read operations.
|
|
137
|
+
*/
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Drizzle implementation of IAuditLogRepository
|
|
141
|
+
*/
|
|
142
|
+
declare class DrizzleAuditLogRepository implements IAuditLogRepository {
|
|
143
|
+
private db;
|
|
144
|
+
constructor(db: DrizzleDB);
|
|
145
|
+
findById(id: string): Promise<AuditLogEntry | null>;
|
|
146
|
+
create(data: CreateAuditLogInput): Promise<AuditLogEntry>;
|
|
147
|
+
createMany(entries: CreateAuditLogInput[]): Promise<AuditLogEntry[]>;
|
|
148
|
+
findByTransactionId(transactionId: string, pagination?: PaginationParams): Promise<PaginatedResult<AuditLogEntry>>;
|
|
149
|
+
findMany(filter: AuditLogFilter, pagination?: PaginationParams): Promise<PaginatedResult<AuditLogEntry>>;
|
|
150
|
+
findByCorrelationId(correlationId: string): Promise<AuditLogEntry[]>;
|
|
151
|
+
getTransactionHistory(transactionId: string): Promise<AuditLogEntry[]>;
|
|
152
|
+
countByAction(filter?: AuditLogFilter): Promise<Record<AuditLogAction, number>>;
|
|
153
|
+
private buildFilterConditions;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @nehorai/payments-drizzle - Drizzle Provider Health Repository
|
|
158
|
+
*
|
|
159
|
+
* Implements IProviderHealthRepository using Drizzle ORM.
|
|
160
|
+
* Manages circuit breaker state and provider metrics.
|
|
161
|
+
*/
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Drizzle implementation of IProviderHealthRepository
|
|
165
|
+
*/
|
|
166
|
+
declare class DrizzleProviderHealthRepository implements IProviderHealthRepository {
|
|
167
|
+
private db;
|
|
168
|
+
constructor(db: DrizzleDB);
|
|
169
|
+
findByProvider(provider: ProviderName): Promise<ProviderHealth | null>;
|
|
170
|
+
getOrCreate(provider: ProviderName): Promise<ProviderHealth>;
|
|
171
|
+
update(provider: ProviderName, data: UpdateProviderHealthInput): Promise<ProviderHealth | null>;
|
|
172
|
+
findAll(): Promise<ProviderHealth[]>;
|
|
173
|
+
recordSuccess(provider: ProviderName, latencyMs: number): Promise<void>;
|
|
174
|
+
recordFailure(provider: ProviderName, error?: string): Promise<void>;
|
|
175
|
+
openCircuit(provider: ProviderName, retryAfterMs: number): Promise<void>;
|
|
176
|
+
closeCircuit(provider: ProviderName): Promise<void>;
|
|
177
|
+
halfOpenCircuit(provider: ProviderName): Promise<void>;
|
|
178
|
+
updateHealthCheck(provider: ProviderName, result: HealthCheckResult): Promise<void>;
|
|
179
|
+
findOpenCircuits(): Promise<ProviderHealth[]>;
|
|
180
|
+
findReadyForRetry(): Promise<ProviderHealth[]>;
|
|
181
|
+
resetStats(provider: ProviderName): Promise<void>;
|
|
182
|
+
updateErrorRate(provider: ProviderName): Promise<number>;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export { type DrizzleDB as D, DrizzleAuditLogRepository as a, DrizzlePaymentMethodRepository as b, DrizzleProviderHealthRepository as c, DrizzleTransactionRepository as d, DrizzleWebhookEventRepository as e, applyPagination as f, toSnakeCase as g, normalizeArrayFilter as n, parseNumeric as p, toCamelCase as t };
|