@agentbadge/database 0.6.0 → 0.6.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.
- package/dist/database.d.ts +8 -0
- package/dist/database.js +18 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +8 -0
- package/dist/prisma/contract.json +3797 -1213
- package/dist/repositories/archive-cursor-repository.d.ts +8 -0
- package/dist/repositories/archive-cursor-repository.js +38 -0
- package/dist/repositories/archive-cursor-store.d.ts +21 -0
- package/dist/repositories/archive-cursor-store.js +16 -0
- package/dist/repositories/econ-ledger-repository.d.ts +22 -0
- package/dist/repositories/econ-ledger-repository.js +138 -0
- package/dist/repositories/econ-ledger-store.d.ts +53 -0
- package/dist/repositories/econ-ledger-store.js +130 -0
- package/dist/repositories/forensics-edge-repository.d.ts +4 -0
- package/dist/repositories/forensics-edge-repository.js +8 -0
- package/dist/repositories/forensics-store.d.ts +8 -0
- package/dist/repositories/forensics-store.js +7 -0
- package/dist/repositories/payment-repository.d.ts +66 -0
- package/dist/repositories/payment-repository.js +445 -0
- package/dist/repositories/payment-store.d.ts +210 -0
- package/dist/repositories/payment-store.js +269 -0
- package/dist/repositories/trust-edge-repository.d.ts +16 -0
- package/dist/repositories/trust-edge-repository.js +93 -0
- package/dist/repositories/trust-edge-store.d.ts +70 -0
- package/dist/repositories/trust-edge-store.js +183 -0
- package/package.json +2 -1
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import { TERMINAL_ATTEMPT_STATUSES } from "./payment-store.js";
|
|
2
|
+
const num = (v) => Number(v);
|
|
3
|
+
const numOrNull = (v) => v === null || v === undefined ? null : Number(v);
|
|
4
|
+
const dec = (v) => String(v);
|
|
5
|
+
const toPaymentRow = (r) => ({
|
|
6
|
+
id: r.id,
|
|
7
|
+
reference: r.reference,
|
|
8
|
+
idempotencyKey: r.idempotencyKey,
|
|
9
|
+
customerId: r.customerId,
|
|
10
|
+
agentId: r.agentId,
|
|
11
|
+
productId: r.productId,
|
|
12
|
+
orderId: r.orderId,
|
|
13
|
+
amount: dec(r.amount),
|
|
14
|
+
currency: r.currency,
|
|
15
|
+
status: r.status,
|
|
16
|
+
purpose: r.purpose,
|
|
17
|
+
expiresAtMs: numOrNull(r.expiresAtMs),
|
|
18
|
+
createdAtMs: num(r.createdAtMs),
|
|
19
|
+
updatedAtMs: num(r.updatedAtMs),
|
|
20
|
+
payload: r.payload,
|
|
21
|
+
createdAt: r.createdAt,
|
|
22
|
+
updatedAt: r.updatedAt,
|
|
23
|
+
});
|
|
24
|
+
const toAttemptRow = (r) => ({
|
|
25
|
+
id: r.id,
|
|
26
|
+
paymentId: r.paymentId,
|
|
27
|
+
provider: r.provider,
|
|
28
|
+
network: r.network,
|
|
29
|
+
token: r.token,
|
|
30
|
+
amount: dec(r.amount),
|
|
31
|
+
currency: r.currency,
|
|
32
|
+
status: r.status,
|
|
33
|
+
providerReference: r.providerReference,
|
|
34
|
+
transactionHash: r.transactionHash,
|
|
35
|
+
expiresAtMs: numOrNull(r.expiresAtMs),
|
|
36
|
+
confirmedAtMs: numOrNull(r.confirmedAtMs),
|
|
37
|
+
payload: r.payload,
|
|
38
|
+
createdAt: r.createdAt,
|
|
39
|
+
updatedAt: r.updatedAt,
|
|
40
|
+
});
|
|
41
|
+
const toReceiptRow = (r) => ({
|
|
42
|
+
id: r.id,
|
|
43
|
+
paymentId: r.paymentId,
|
|
44
|
+
attemptId: r.attemptId,
|
|
45
|
+
provider: r.provider,
|
|
46
|
+
externalReference: r.externalReference,
|
|
47
|
+
network: r.network,
|
|
48
|
+
transactionHash: r.transactionHash,
|
|
49
|
+
payer: r.payer,
|
|
50
|
+
recipient: r.recipient,
|
|
51
|
+
amount: dec(r.amount),
|
|
52
|
+
asset: r.asset,
|
|
53
|
+
verifiedAtMs: num(r.verifiedAtMs),
|
|
54
|
+
payload: r.payload,
|
|
55
|
+
createdAt: r.createdAt,
|
|
56
|
+
});
|
|
57
|
+
const toEventRow = (r) => ({
|
|
58
|
+
id: r.id,
|
|
59
|
+
entity: r.entity,
|
|
60
|
+
paymentId: r.paymentId,
|
|
61
|
+
attemptId: r.attemptId,
|
|
62
|
+
from: r.from,
|
|
63
|
+
to: r.to,
|
|
64
|
+
actor: r.actor,
|
|
65
|
+
reason: r.reason,
|
|
66
|
+
atMs: num(r.atMs),
|
|
67
|
+
payload: r.payload,
|
|
68
|
+
createdAt: r.createdAt,
|
|
69
|
+
});
|
|
70
|
+
const toProductRow = (r) => ({
|
|
71
|
+
id: r.id,
|
|
72
|
+
code: r.code,
|
|
73
|
+
name: r.name,
|
|
74
|
+
description: r.description,
|
|
75
|
+
category: r.category,
|
|
76
|
+
active: r.active,
|
|
77
|
+
payload: r.payload,
|
|
78
|
+
createdAt: r.createdAt,
|
|
79
|
+
updatedAt: r.updatedAt,
|
|
80
|
+
});
|
|
81
|
+
const toPriceRow = (r) => ({
|
|
82
|
+
id: r.id,
|
|
83
|
+
productId: r.productId,
|
|
84
|
+
amount: dec(r.amount),
|
|
85
|
+
currency: r.currency,
|
|
86
|
+
billingType: r.billingType,
|
|
87
|
+
interval: r.interval,
|
|
88
|
+
active: r.active,
|
|
89
|
+
payload: r.payload,
|
|
90
|
+
createdAt: r.createdAt,
|
|
91
|
+
updatedAt: r.updatedAt,
|
|
92
|
+
});
|
|
93
|
+
export class PaymentRepository {
|
|
94
|
+
db;
|
|
95
|
+
constructor(db) {
|
|
96
|
+
this.db = db;
|
|
97
|
+
}
|
|
98
|
+
get orm() {
|
|
99
|
+
return this.db.orm.public.Payment;
|
|
100
|
+
}
|
|
101
|
+
async create(p) {
|
|
102
|
+
if (await this.getById(p.id))
|
|
103
|
+
return null;
|
|
104
|
+
if (await this.getByReference(p.reference))
|
|
105
|
+
return null;
|
|
106
|
+
if (p.idempotencyKey != null &&
|
|
107
|
+
(await this.getByIdempotencyKey(p.idempotencyKey))) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
const row = await this.orm.create({
|
|
111
|
+
id: p.id,
|
|
112
|
+
reference: p.reference,
|
|
113
|
+
idempotencyKey: p.idempotencyKey ?? null,
|
|
114
|
+
customerId: p.customerId ?? null,
|
|
115
|
+
agentId: p.agentId ?? null,
|
|
116
|
+
productId: p.productId ?? null,
|
|
117
|
+
orderId: p.orderId ?? null,
|
|
118
|
+
amount: p.amount,
|
|
119
|
+
currency: p.currency ?? "USD",
|
|
120
|
+
status: p.status,
|
|
121
|
+
purpose: p.purpose,
|
|
122
|
+
expiresAtMs: p.expiresAtMs != null
|
|
123
|
+
? BigInt(p.expiresAtMs)
|
|
124
|
+
: null,
|
|
125
|
+
createdAtMs: BigInt(p.createdAtMs),
|
|
126
|
+
updatedAtMs: BigInt(p.updatedAtMs),
|
|
127
|
+
payload: p.payload,
|
|
128
|
+
});
|
|
129
|
+
return toPaymentRow(row);
|
|
130
|
+
}
|
|
131
|
+
async getById(id) {
|
|
132
|
+
const r = await this.orm.where({ id }).first();
|
|
133
|
+
return r ? toPaymentRow(r) : null;
|
|
134
|
+
}
|
|
135
|
+
async getByReference(reference) {
|
|
136
|
+
const r = await this.orm.where({ reference }).first();
|
|
137
|
+
return r ? toPaymentRow(r) : null;
|
|
138
|
+
}
|
|
139
|
+
async getByIdempotencyKey(key) {
|
|
140
|
+
const r = await this.orm.where({ idempotencyKey: key }).first();
|
|
141
|
+
return r ? toPaymentRow(r) : null;
|
|
142
|
+
}
|
|
143
|
+
async listByCustomer(customerId) {
|
|
144
|
+
const rows = await this.orm
|
|
145
|
+
.orderBy((e) => e.createdAtMs.desc())
|
|
146
|
+
.where({ customerId })
|
|
147
|
+
.all();
|
|
148
|
+
return rows.map(toPaymentRow);
|
|
149
|
+
}
|
|
150
|
+
async applyStatus(id, expectedFrom, to, updatedAtMs) {
|
|
151
|
+
const row = await this.orm.where({ id, status: expectedFrom }).update({
|
|
152
|
+
status: to,
|
|
153
|
+
updatedAtMs: BigInt(updatedAtMs),
|
|
154
|
+
});
|
|
155
|
+
return row ? toPaymentRow(row) : null;
|
|
156
|
+
}
|
|
157
|
+
async listExpired(nowMs) {
|
|
158
|
+
const out = [];
|
|
159
|
+
for (const status of ["PENDING", "PROCESSING"]) {
|
|
160
|
+
const rows = await this.orm.where({ status }).all();
|
|
161
|
+
for (const r of rows) {
|
|
162
|
+
const exp = numOrNull(r.expiresAtMs);
|
|
163
|
+
if (exp !== null && exp < nowMs)
|
|
164
|
+
out.push(toPaymentRow(r));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return out;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
export class PaymentAttemptRepository {
|
|
171
|
+
db;
|
|
172
|
+
constructor(db) {
|
|
173
|
+
this.db = db;
|
|
174
|
+
}
|
|
175
|
+
get orm() {
|
|
176
|
+
return this.db.orm.public.PaymentAttempt;
|
|
177
|
+
}
|
|
178
|
+
async create(a) {
|
|
179
|
+
if (await this.getById(a.id))
|
|
180
|
+
return null;
|
|
181
|
+
if (a.providerReference != null &&
|
|
182
|
+
(await this.getByProviderRef(a.provider, a.providerReference))) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
if (a.transactionHash != null &&
|
|
186
|
+
(await this.getByProviderTx(a.provider, a.transactionHash))) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
const row = await this.orm.create({
|
|
190
|
+
id: a.id,
|
|
191
|
+
paymentId: a.paymentId,
|
|
192
|
+
provider: a.provider,
|
|
193
|
+
network: a.network ?? null,
|
|
194
|
+
token: a.token ?? null,
|
|
195
|
+
amount: a.amount,
|
|
196
|
+
currency: a.currency,
|
|
197
|
+
status: a.status,
|
|
198
|
+
providerReference: a.providerReference ?? null,
|
|
199
|
+
transactionHash: a.transactionHash ?? null,
|
|
200
|
+
expiresAtMs: a.expiresAtMs != null
|
|
201
|
+
? BigInt(a.expiresAtMs)
|
|
202
|
+
: null,
|
|
203
|
+
confirmedAtMs: a.confirmedAtMs != null
|
|
204
|
+
? BigInt(a.confirmedAtMs)
|
|
205
|
+
: null,
|
|
206
|
+
payload: a.payload,
|
|
207
|
+
});
|
|
208
|
+
return toAttemptRow(row);
|
|
209
|
+
}
|
|
210
|
+
async getById(id) {
|
|
211
|
+
const r = await this.orm.where({ id }).first();
|
|
212
|
+
return r ? toAttemptRow(r) : null;
|
|
213
|
+
}
|
|
214
|
+
async listByPayment(paymentId) {
|
|
215
|
+
const rows = await this.orm.where({ paymentId }).all();
|
|
216
|
+
return rows.map(toAttemptRow);
|
|
217
|
+
}
|
|
218
|
+
async getByProviderRef(provider, providerReference) {
|
|
219
|
+
const r = await this.orm
|
|
220
|
+
.where({ provider, providerReference })
|
|
221
|
+
.first();
|
|
222
|
+
return r ? toAttemptRow(r) : null;
|
|
223
|
+
}
|
|
224
|
+
async getByProviderTx(provider, transactionHash) {
|
|
225
|
+
const r = await this.orm
|
|
226
|
+
.where({ provider, transactionHash })
|
|
227
|
+
.first();
|
|
228
|
+
return r ? toAttemptRow(r) : null;
|
|
229
|
+
}
|
|
230
|
+
async getByTxHash(transactionHash) {
|
|
231
|
+
const r = await this.orm.where({ transactionHash }).first();
|
|
232
|
+
return r ? toAttemptRow(r) : null;
|
|
233
|
+
}
|
|
234
|
+
async applyStatus(id, expectedFrom, to, _updatedAtMs, patch) {
|
|
235
|
+
const row = await this.orm.where({ id, status: expectedFrom }).update({
|
|
236
|
+
status: to,
|
|
237
|
+
...(patch?.confirmedAtMs !== undefined
|
|
238
|
+
? {
|
|
239
|
+
confirmedAtMs: BigInt(patch.confirmedAtMs),
|
|
240
|
+
}
|
|
241
|
+
: {}),
|
|
242
|
+
...(patch?.transactionHash !== undefined
|
|
243
|
+
? { transactionHash: patch.transactionHash }
|
|
244
|
+
: {}),
|
|
245
|
+
...(patch?.providerReference !== undefined
|
|
246
|
+
? { providerReference: patch.providerReference }
|
|
247
|
+
: {}),
|
|
248
|
+
});
|
|
249
|
+
return row ? toAttemptRow(row) : null;
|
|
250
|
+
}
|
|
251
|
+
async listExpired(nowMs) {
|
|
252
|
+
const out = [];
|
|
253
|
+
const openStatuses = [
|
|
254
|
+
"CREATED",
|
|
255
|
+
"PENDING",
|
|
256
|
+
"PROCESSING",
|
|
257
|
+
].filter((s) => !TERMINAL_ATTEMPT_STATUSES.includes(s));
|
|
258
|
+
for (const status of openStatuses) {
|
|
259
|
+
const rows = await this.orm.where({ status }).all();
|
|
260
|
+
for (const r of rows) {
|
|
261
|
+
const exp = numOrNull(r.expiresAtMs);
|
|
262
|
+
if (exp !== null && exp < nowMs)
|
|
263
|
+
out.push(toAttemptRow(r));
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return out;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
export class PaymentReceiptRepository {
|
|
270
|
+
db;
|
|
271
|
+
constructor(db) {
|
|
272
|
+
this.db = db;
|
|
273
|
+
}
|
|
274
|
+
get orm() {
|
|
275
|
+
return this.db.orm.public.PaymentReceipt;
|
|
276
|
+
}
|
|
277
|
+
async append(r) {
|
|
278
|
+
if (await this.getById(r.id))
|
|
279
|
+
return null;
|
|
280
|
+
if (await this.getByExternalRef(r.provider, r.externalReference)) {
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
const row = await this.orm.create({
|
|
284
|
+
id: r.id,
|
|
285
|
+
paymentId: r.paymentId,
|
|
286
|
+
attemptId: r.attemptId,
|
|
287
|
+
provider: r.provider,
|
|
288
|
+
externalReference: r.externalReference,
|
|
289
|
+
network: r.network ?? null,
|
|
290
|
+
transactionHash: r.transactionHash ?? null,
|
|
291
|
+
payer: r.payer ?? null,
|
|
292
|
+
recipient: r.recipient ?? null,
|
|
293
|
+
amount: r.amount,
|
|
294
|
+
asset: r.asset,
|
|
295
|
+
verifiedAtMs: BigInt(r.verifiedAtMs),
|
|
296
|
+
payload: r.payload,
|
|
297
|
+
});
|
|
298
|
+
return toReceiptRow(row);
|
|
299
|
+
}
|
|
300
|
+
async getById(id) {
|
|
301
|
+
const r = await this.orm.where({ id }).first();
|
|
302
|
+
return r ? toReceiptRow(r) : null;
|
|
303
|
+
}
|
|
304
|
+
async listByPayment(paymentId) {
|
|
305
|
+
const rows = await this.orm.where({ paymentId }).all();
|
|
306
|
+
return rows.map(toReceiptRow);
|
|
307
|
+
}
|
|
308
|
+
async getByExternalRef(provider, externalReference) {
|
|
309
|
+
const r = await this.orm
|
|
310
|
+
.where({ provider, externalReference })
|
|
311
|
+
.first();
|
|
312
|
+
return r ? toReceiptRow(r) : null;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
export class PaymentEventRepository {
|
|
316
|
+
db;
|
|
317
|
+
constructor(db) {
|
|
318
|
+
this.db = db;
|
|
319
|
+
}
|
|
320
|
+
get orm() {
|
|
321
|
+
return this.db.orm.public.PaymentEvent;
|
|
322
|
+
}
|
|
323
|
+
async append(e) {
|
|
324
|
+
const existing = await this.orm.where({ id: e.id }).first();
|
|
325
|
+
if (existing)
|
|
326
|
+
return null;
|
|
327
|
+
const row = await this.orm.create({
|
|
328
|
+
id: e.id,
|
|
329
|
+
entity: e.entity,
|
|
330
|
+
paymentId: e.paymentId,
|
|
331
|
+
attemptId: e.attemptId ?? null,
|
|
332
|
+
from: e.from,
|
|
333
|
+
to: e.to,
|
|
334
|
+
actor: e.actor,
|
|
335
|
+
reason: e.reason ?? null,
|
|
336
|
+
atMs: BigInt(e.atMs),
|
|
337
|
+
payload: e.payload,
|
|
338
|
+
});
|
|
339
|
+
return toEventRow(row);
|
|
340
|
+
}
|
|
341
|
+
async listByPayment(paymentId) {
|
|
342
|
+
const rows = await this.orm
|
|
343
|
+
.orderBy((e) => e.atMs.asc())
|
|
344
|
+
.where({ paymentId })
|
|
345
|
+
.all();
|
|
346
|
+
return rows.map(toEventRow);
|
|
347
|
+
}
|
|
348
|
+
async listByAttempt(attemptId) {
|
|
349
|
+
const rows = await this.orm
|
|
350
|
+
.orderBy((e) => e.atMs.asc())
|
|
351
|
+
.where({ attemptId })
|
|
352
|
+
.all();
|
|
353
|
+
return rows.map(toEventRow);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
export class PaymentProductRepository {
|
|
357
|
+
db;
|
|
358
|
+
constructor(db) {
|
|
359
|
+
this.db = db;
|
|
360
|
+
}
|
|
361
|
+
get orm() {
|
|
362
|
+
return this.db.orm.public.PaymentProduct;
|
|
363
|
+
}
|
|
364
|
+
async upsert(p) {
|
|
365
|
+
const existing = await this.orm.where({ code: p.code }).first();
|
|
366
|
+
if (existing) {
|
|
367
|
+
const updated = await this.orm.where({ id: existing.id }).update({
|
|
368
|
+
name: p.name,
|
|
369
|
+
description: p.description ?? null,
|
|
370
|
+
category: p.category,
|
|
371
|
+
active: p.active ?? true,
|
|
372
|
+
payload: p.payload,
|
|
373
|
+
});
|
|
374
|
+
return toProductRow(updated);
|
|
375
|
+
}
|
|
376
|
+
const row = await this.orm.create({
|
|
377
|
+
id: p.id,
|
|
378
|
+
code: p.code,
|
|
379
|
+
name: p.name,
|
|
380
|
+
description: p.description ?? null,
|
|
381
|
+
category: p.category,
|
|
382
|
+
active: p.active ?? true,
|
|
383
|
+
payload: p.payload,
|
|
384
|
+
});
|
|
385
|
+
return toProductRow(row);
|
|
386
|
+
}
|
|
387
|
+
async getById(id) {
|
|
388
|
+
const r = await this.orm.where({ id }).first();
|
|
389
|
+
return r ? toProductRow(r) : null;
|
|
390
|
+
}
|
|
391
|
+
async getByCode(code) {
|
|
392
|
+
const r = await this.orm.where({ code }).first();
|
|
393
|
+
return r ? toProductRow(r) : null;
|
|
394
|
+
}
|
|
395
|
+
async list(opts) {
|
|
396
|
+
const rows = opts?.activeOnly
|
|
397
|
+
? await this.orm.where({ active: true }).all()
|
|
398
|
+
: await this.orm.all();
|
|
399
|
+
return rows.map(toProductRow);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
export class PaymentPriceRepository {
|
|
403
|
+
db;
|
|
404
|
+
constructor(db) {
|
|
405
|
+
this.db = db;
|
|
406
|
+
}
|
|
407
|
+
get orm() {
|
|
408
|
+
return this.db.orm.public.PaymentPrice;
|
|
409
|
+
}
|
|
410
|
+
async create(p) {
|
|
411
|
+
if (await this.getById(p.id))
|
|
412
|
+
return null;
|
|
413
|
+
const row = await this.orm.create({
|
|
414
|
+
id: p.id,
|
|
415
|
+
productId: p.productId,
|
|
416
|
+
amount: p.amount,
|
|
417
|
+
currency: p.currency ?? "USD",
|
|
418
|
+
billingType: p.billingType,
|
|
419
|
+
interval: p.interval ?? null,
|
|
420
|
+
active: p.active ?? true,
|
|
421
|
+
payload: p.payload,
|
|
422
|
+
});
|
|
423
|
+
return toPriceRow(row);
|
|
424
|
+
}
|
|
425
|
+
async getById(id) {
|
|
426
|
+
const r = await this.orm.where({ id }).first();
|
|
427
|
+
return r ? toPriceRow(r) : null;
|
|
428
|
+
}
|
|
429
|
+
async listByProduct(productId, opts) {
|
|
430
|
+
const rows = opts?.activeOnly
|
|
431
|
+
? await this.orm.where({ productId, active: true }).all()
|
|
432
|
+
: await this.orm.where({ productId }).all();
|
|
433
|
+
return rows.map(toPriceRow);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
export function createPrismaPaymentStores(db) {
|
|
437
|
+
return {
|
|
438
|
+
payments: new PaymentRepository(db),
|
|
439
|
+
attempts: new PaymentAttemptRepository(db),
|
|
440
|
+
receipts: new PaymentReceiptRepository(db),
|
|
441
|
+
events: new PaymentEventRepository(db),
|
|
442
|
+
products: new PaymentProductRepository(db),
|
|
443
|
+
prices: new PaymentPriceRepository(db),
|
|
444
|
+
};
|
|
445
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import type { JsonValue } from "@prisma/orm-postgres/target/codec-types";
|
|
2
|
+
export interface PaymentInsert {
|
|
3
|
+
id: string;
|
|
4
|
+
reference: string;
|
|
5
|
+
idempotencyKey?: string | null;
|
|
6
|
+
customerId?: string | null;
|
|
7
|
+
agentId?: string | null;
|
|
8
|
+
productId?: string | null;
|
|
9
|
+
orderId?: string | null;
|
|
10
|
+
amount: string;
|
|
11
|
+
currency?: string;
|
|
12
|
+
status: string;
|
|
13
|
+
purpose: string;
|
|
14
|
+
expiresAtMs?: number | null;
|
|
15
|
+
createdAtMs: number;
|
|
16
|
+
updatedAtMs: number;
|
|
17
|
+
payload: JsonValue;
|
|
18
|
+
}
|
|
19
|
+
export interface PaymentRow extends PaymentInsert {
|
|
20
|
+
createdAt: string;
|
|
21
|
+
updatedAt: string;
|
|
22
|
+
}
|
|
23
|
+
export interface PaymentStore {
|
|
24
|
+
create(p: PaymentInsert): Promise<PaymentRow | null>;
|
|
25
|
+
getById(id: string): Promise<PaymentRow | null>;
|
|
26
|
+
getByReference(reference: string): Promise<PaymentRow | null>;
|
|
27
|
+
getByIdempotencyKey(key: string): Promise<PaymentRow | null>;
|
|
28
|
+
listByCustomer(customerId: string): Promise<PaymentRow[]>;
|
|
29
|
+
applyStatus(id: string, expectedFrom: string, to: string, updatedAtMs: number): Promise<PaymentRow | null>;
|
|
30
|
+
listExpired(nowMs: number): Promise<PaymentRow[]>;
|
|
31
|
+
}
|
|
32
|
+
export interface PaymentAttemptInsert {
|
|
33
|
+
id: string;
|
|
34
|
+
paymentId: string;
|
|
35
|
+
provider: string;
|
|
36
|
+
network?: string | null;
|
|
37
|
+
token?: string | null;
|
|
38
|
+
amount: string;
|
|
39
|
+
currency: string;
|
|
40
|
+
status: string;
|
|
41
|
+
providerReference?: string | null;
|
|
42
|
+
transactionHash?: string | null;
|
|
43
|
+
expiresAtMs?: number | null;
|
|
44
|
+
confirmedAtMs?: number | null;
|
|
45
|
+
payload: JsonValue;
|
|
46
|
+
}
|
|
47
|
+
export interface PaymentAttemptRow extends PaymentAttemptInsert {
|
|
48
|
+
createdAt: string;
|
|
49
|
+
updatedAt: string;
|
|
50
|
+
}
|
|
51
|
+
export declare const TERMINAL_ATTEMPT_STATUSES: readonly string[];
|
|
52
|
+
export interface AttemptStatusPatch {
|
|
53
|
+
confirmedAtMs?: number;
|
|
54
|
+
transactionHash?: string | null;
|
|
55
|
+
providerReference?: string | null;
|
|
56
|
+
}
|
|
57
|
+
export interface PaymentAttemptStore {
|
|
58
|
+
create(a: PaymentAttemptInsert): Promise<PaymentAttemptRow | null>;
|
|
59
|
+
getById(id: string): Promise<PaymentAttemptRow | null>;
|
|
60
|
+
listByPayment(paymentId: string): Promise<PaymentAttemptRow[]>;
|
|
61
|
+
getByProviderRef(provider: string, providerReference: string): Promise<PaymentAttemptRow | null>;
|
|
62
|
+
getByTxHash(transactionHash: string): Promise<PaymentAttemptRow | null>;
|
|
63
|
+
applyStatus(id: string, expectedFrom: string, to: string, updatedAtMs: number, patch?: AttemptStatusPatch): Promise<PaymentAttemptRow | null>;
|
|
64
|
+
listExpired(nowMs: number): Promise<PaymentAttemptRow[]>;
|
|
65
|
+
}
|
|
66
|
+
export interface PaymentReceiptInsert {
|
|
67
|
+
id: string;
|
|
68
|
+
paymentId: string;
|
|
69
|
+
attemptId: string;
|
|
70
|
+
provider: string;
|
|
71
|
+
externalReference: string;
|
|
72
|
+
network?: string | null;
|
|
73
|
+
transactionHash?: string | null;
|
|
74
|
+
payer?: string | null;
|
|
75
|
+
recipient?: string | null;
|
|
76
|
+
amount: string;
|
|
77
|
+
asset: string;
|
|
78
|
+
verifiedAtMs: number;
|
|
79
|
+
payload: JsonValue;
|
|
80
|
+
}
|
|
81
|
+
export interface PaymentReceiptRow extends PaymentReceiptInsert {
|
|
82
|
+
createdAt: string;
|
|
83
|
+
}
|
|
84
|
+
export interface PaymentReceiptStore {
|
|
85
|
+
append(r: PaymentReceiptInsert): Promise<PaymentReceiptRow | null>;
|
|
86
|
+
getById(id: string): Promise<PaymentReceiptRow | null>;
|
|
87
|
+
listByPayment(paymentId: string): Promise<PaymentReceiptRow[]>;
|
|
88
|
+
getByExternalRef(provider: string, externalReference: string): Promise<PaymentReceiptRow | null>;
|
|
89
|
+
}
|
|
90
|
+
export interface PaymentEventInsert {
|
|
91
|
+
id: string;
|
|
92
|
+
entity: string;
|
|
93
|
+
paymentId: string;
|
|
94
|
+
attemptId?: string | null;
|
|
95
|
+
from: string;
|
|
96
|
+
to: string;
|
|
97
|
+
actor: string;
|
|
98
|
+
reason?: string | null;
|
|
99
|
+
atMs: number;
|
|
100
|
+
payload: JsonValue;
|
|
101
|
+
}
|
|
102
|
+
export interface PaymentEventRow extends PaymentEventInsert {
|
|
103
|
+
createdAt: string;
|
|
104
|
+
}
|
|
105
|
+
export interface PaymentEventStore {
|
|
106
|
+
append(e: PaymentEventInsert): Promise<PaymentEventRow | null>;
|
|
107
|
+
listByPayment(paymentId: string): Promise<PaymentEventRow[]>;
|
|
108
|
+
listByAttempt(attemptId: string): Promise<PaymentEventRow[]>;
|
|
109
|
+
}
|
|
110
|
+
export interface PaymentProductInsert {
|
|
111
|
+
id: string;
|
|
112
|
+
code: string;
|
|
113
|
+
name: string;
|
|
114
|
+
description?: string | null;
|
|
115
|
+
category: string;
|
|
116
|
+
active?: boolean;
|
|
117
|
+
payload: JsonValue;
|
|
118
|
+
}
|
|
119
|
+
export interface PaymentProductRow extends PaymentProductInsert {
|
|
120
|
+
createdAt: string;
|
|
121
|
+
updatedAt: string;
|
|
122
|
+
}
|
|
123
|
+
export interface PaymentProductStore {
|
|
124
|
+
upsert(p: PaymentProductInsert): Promise<PaymentProductRow>;
|
|
125
|
+
getById(id: string): Promise<PaymentProductRow | null>;
|
|
126
|
+
getByCode(code: string): Promise<PaymentProductRow | null>;
|
|
127
|
+
list(opts?: {
|
|
128
|
+
activeOnly?: boolean;
|
|
129
|
+
}): Promise<PaymentProductRow[]>;
|
|
130
|
+
}
|
|
131
|
+
export interface PaymentPriceInsert {
|
|
132
|
+
id: string;
|
|
133
|
+
productId: string;
|
|
134
|
+
amount: string;
|
|
135
|
+
currency?: string;
|
|
136
|
+
billingType: string;
|
|
137
|
+
interval?: string | null;
|
|
138
|
+
active?: boolean;
|
|
139
|
+
payload: JsonValue;
|
|
140
|
+
}
|
|
141
|
+
export interface PaymentPriceRow extends PaymentPriceInsert {
|
|
142
|
+
createdAt: string;
|
|
143
|
+
updatedAt: string;
|
|
144
|
+
}
|
|
145
|
+
export interface PaymentPriceStore {
|
|
146
|
+
create(p: PaymentPriceInsert): Promise<PaymentPriceRow | null>;
|
|
147
|
+
getById(id: string): Promise<PaymentPriceRow | null>;
|
|
148
|
+
listByProduct(productId: string, opts?: {
|
|
149
|
+
activeOnly?: boolean;
|
|
150
|
+
}): Promise<PaymentPriceRow[]>;
|
|
151
|
+
}
|
|
152
|
+
export interface PaymentStores {
|
|
153
|
+
payments: PaymentStore;
|
|
154
|
+
attempts: PaymentAttemptStore;
|
|
155
|
+
receipts: PaymentReceiptStore;
|
|
156
|
+
events: PaymentEventStore;
|
|
157
|
+
products: PaymentProductStore;
|
|
158
|
+
prices: PaymentPriceStore;
|
|
159
|
+
}
|
|
160
|
+
export declare class InMemoryPaymentStore implements PaymentStore {
|
|
161
|
+
private readonly rows;
|
|
162
|
+
create(p: PaymentInsert): Promise<PaymentRow | null>;
|
|
163
|
+
getById(id: string): Promise<PaymentRow | null>;
|
|
164
|
+
getByReference(reference: string): Promise<PaymentRow | null>;
|
|
165
|
+
getByIdempotencyKey(key: string): Promise<PaymentRow | null>;
|
|
166
|
+
listByCustomer(customerId: string): Promise<PaymentRow[]>;
|
|
167
|
+
applyStatus(id: string, expectedFrom: string, to: string, updatedAtMs: number): Promise<PaymentRow | null>;
|
|
168
|
+
listExpired(nowMs: number): Promise<PaymentRow[]>;
|
|
169
|
+
}
|
|
170
|
+
export declare class InMemoryPaymentAttemptStore implements PaymentAttemptStore {
|
|
171
|
+
private readonly rows;
|
|
172
|
+
create(a: PaymentAttemptInsert): Promise<PaymentAttemptRow | null>;
|
|
173
|
+
getById(id: string): Promise<PaymentAttemptRow | null>;
|
|
174
|
+
listByPayment(paymentId: string): Promise<PaymentAttemptRow[]>;
|
|
175
|
+
getByProviderRef(provider: string, providerReference: string): Promise<PaymentAttemptRow | null>;
|
|
176
|
+
getByTxHash(transactionHash: string): Promise<PaymentAttemptRow | null>;
|
|
177
|
+
applyStatus(id: string, expectedFrom: string, to: string, updatedAtMs: number, patch?: AttemptStatusPatch): Promise<PaymentAttemptRow | null>;
|
|
178
|
+
listExpired(nowMs: number): Promise<PaymentAttemptRow[]>;
|
|
179
|
+
}
|
|
180
|
+
export declare class InMemoryPaymentReceiptStore implements PaymentReceiptStore {
|
|
181
|
+
private readonly rows;
|
|
182
|
+
append(r: PaymentReceiptInsert): Promise<PaymentReceiptRow | null>;
|
|
183
|
+
getById(id: string): Promise<PaymentReceiptRow | null>;
|
|
184
|
+
listByPayment(paymentId: string): Promise<PaymentReceiptRow[]>;
|
|
185
|
+
getByExternalRef(provider: string, externalReference: string): Promise<PaymentReceiptRow | null>;
|
|
186
|
+
}
|
|
187
|
+
export declare class InMemoryPaymentEventStore implements PaymentEventStore {
|
|
188
|
+
private readonly rows;
|
|
189
|
+
append(e: PaymentEventInsert): Promise<PaymentEventRow | null>;
|
|
190
|
+
listByPayment(paymentId: string): Promise<PaymentEventRow[]>;
|
|
191
|
+
listByAttempt(attemptId: string): Promise<PaymentEventRow[]>;
|
|
192
|
+
}
|
|
193
|
+
export declare class InMemoryPaymentProductStore implements PaymentProductStore {
|
|
194
|
+
private readonly rows;
|
|
195
|
+
upsert(p: PaymentProductInsert): Promise<PaymentProductRow>;
|
|
196
|
+
getById(id: string): Promise<PaymentProductRow | null>;
|
|
197
|
+
getByCode(code: string): Promise<PaymentProductRow | null>;
|
|
198
|
+
list(opts?: {
|
|
199
|
+
activeOnly?: boolean;
|
|
200
|
+
}): Promise<PaymentProductRow[]>;
|
|
201
|
+
}
|
|
202
|
+
export declare class InMemoryPaymentPriceStore implements PaymentPriceStore {
|
|
203
|
+
private readonly rows;
|
|
204
|
+
create(p: PaymentPriceInsert): Promise<PaymentPriceRow | null>;
|
|
205
|
+
getById(id: string): Promise<PaymentPriceRow | null>;
|
|
206
|
+
listByProduct(productId: string, opts?: {
|
|
207
|
+
activeOnly?: boolean;
|
|
208
|
+
}): Promise<PaymentPriceRow[]>;
|
|
209
|
+
}
|
|
210
|
+
export declare function createInMemoryPaymentStores(): PaymentStores;
|