@agentbadge/database 0.6.13 → 0.6.15
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/repositories/commerce-repository.d.ts +9 -0
- package/dist/repositories/commerce-repository.js +24 -0
- package/dist/repositories/commerce-store.d.ts +18 -0
- package/dist/repositories/commerce-store.js +19 -0
- package/dist/repositories/payment-repository.d.ts +25 -0
- package/dist/repositories/payment-repository.js +56 -0
- package/dist/repositories/payment-store.d.ts +50 -0
- package/dist/repositories/payment-store.js +42 -0
- package/package.json +1 -1
|
@@ -73,5 +73,14 @@ export declare class CommercePaymentRepository implements CommercePaymentStore {
|
|
|
73
73
|
getById(id: string): Promise<CommercePaymentRow | null>;
|
|
74
74
|
getByAgreement(agreementId: string): Promise<CommercePaymentRow | null>;
|
|
75
75
|
applyStatus(id: string, expectedFrom: string, to: string, patch?: PaymentStatusPatch): Promise<CommercePaymentRow | null>;
|
|
76
|
+
list(opts?: {
|
|
77
|
+
mode?: string;
|
|
78
|
+
status?: string;
|
|
79
|
+
statuses?: readonly string[];
|
|
80
|
+
recordedSinceMs?: number;
|
|
81
|
+
recordedUntilMs?: number;
|
|
82
|
+
limit?: number;
|
|
83
|
+
offset?: number;
|
|
84
|
+
}): Promise<CommercePaymentRow[]>;
|
|
76
85
|
}
|
|
77
86
|
export declare function createPrismaCommerceStores(db: PrismaDb): CommerceStores;
|
|
@@ -500,6 +500,30 @@ export class CommercePaymentRepository {
|
|
|
500
500
|
});
|
|
501
501
|
return row ? toPaymentRow(row) : null;
|
|
502
502
|
}
|
|
503
|
+
async list(opts = {}) {
|
|
504
|
+
const statusSet = opts.statuses !== undefined
|
|
505
|
+
? new Set(opts.statuses)
|
|
506
|
+
: opts.status !== undefined
|
|
507
|
+
? new Set([opts.status])
|
|
508
|
+
: undefined;
|
|
509
|
+
const eq = {};
|
|
510
|
+
if (opts.mode !== undefined)
|
|
511
|
+
eq["mode"] = opts.mode;
|
|
512
|
+
const candidates = await this.orm.where(eq).all();
|
|
513
|
+
const stamp = (r) => r.recordedAtMs ?? Date.parse(r.createdAt);
|
|
514
|
+
const out = candidates
|
|
515
|
+
.map(toPaymentRow)
|
|
516
|
+
.filter((r) => (statusSet === undefined || statusSet.has(r.status)) &&
|
|
517
|
+
(opts.recordedSinceMs === undefined ||
|
|
518
|
+
(r.recordedAtMs != null &&
|
|
519
|
+
r.recordedAtMs >= opts.recordedSinceMs)) &&
|
|
520
|
+
(opts.recordedUntilMs === undefined ||
|
|
521
|
+
(r.recordedAtMs != null &&
|
|
522
|
+
r.recordedAtMs <= opts.recordedUntilMs)));
|
|
523
|
+
out.sort((a, b) => stamp(b) - stamp(a));
|
|
524
|
+
const offset = opts.offset ?? 0;
|
|
525
|
+
return out.slice(offset, opts.limit === undefined ? undefined : offset + opts.limit);
|
|
526
|
+
}
|
|
503
527
|
}
|
|
504
528
|
export function createPrismaCommerceStores(db) {
|
|
505
529
|
const bundle = (client) => ({
|
|
@@ -179,6 +179,15 @@ export interface CommercePaymentStore {
|
|
|
179
179
|
getById(id: string): Promise<CommercePaymentRow | null>;
|
|
180
180
|
getByAgreement(agreementId: string): Promise<CommercePaymentRow | null>;
|
|
181
181
|
applyStatus(id: string, expectedFrom: string, to: string, patch?: PaymentStatusPatch): Promise<CommercePaymentRow | null>;
|
|
182
|
+
list(opts?: {
|
|
183
|
+
mode?: string;
|
|
184
|
+
status?: string;
|
|
185
|
+
statuses?: readonly string[];
|
|
186
|
+
recordedSinceMs?: number;
|
|
187
|
+
recordedUntilMs?: number;
|
|
188
|
+
limit?: number;
|
|
189
|
+
offset?: number;
|
|
190
|
+
}): Promise<CommercePaymentRow[]>;
|
|
182
191
|
}
|
|
183
192
|
export interface CommerceStores {
|
|
184
193
|
tasks: CommerceTaskStore;
|
|
@@ -249,5 +258,14 @@ export declare class InMemoryCommercePaymentStore implements CommercePaymentStor
|
|
|
249
258
|
getById(id: string): Promise<CommercePaymentRow | null>;
|
|
250
259
|
getByAgreement(agreementId: string): Promise<CommercePaymentRow | null>;
|
|
251
260
|
applyStatus(id: string, expectedFrom: string, to: string, patch?: PaymentStatusPatch): Promise<CommercePaymentRow | null>;
|
|
261
|
+
list(opts?: {
|
|
262
|
+
mode?: string;
|
|
263
|
+
status?: string;
|
|
264
|
+
statuses?: readonly string[];
|
|
265
|
+
recordedSinceMs?: number;
|
|
266
|
+
recordedUntilMs?: number;
|
|
267
|
+
limit?: number;
|
|
268
|
+
offset?: number;
|
|
269
|
+
}): Promise<CommercePaymentRow[]>;
|
|
252
270
|
}
|
|
253
271
|
export declare function createInMemoryCommerceStores(): CommerceStores;
|
|
@@ -301,6 +301,25 @@ export class InMemoryCommercePaymentStore {
|
|
|
301
301
|
this.rows.set(id, next);
|
|
302
302
|
return next;
|
|
303
303
|
}
|
|
304
|
+
async list(opts = {}) {
|
|
305
|
+
const statusSet = opts.statuses !== undefined
|
|
306
|
+
? new Set(opts.statuses)
|
|
307
|
+
: opts.status !== undefined
|
|
308
|
+
? new Set([opts.status])
|
|
309
|
+
: undefined;
|
|
310
|
+
const stamp = (r) => r.recordedAtMs ?? Date.parse(r.createdAt);
|
|
311
|
+
const out = [...this.rows.values()].filter((r) => (opts.mode === undefined || r.mode === opts.mode) &&
|
|
312
|
+
(statusSet === undefined || statusSet.has(r.status)) &&
|
|
313
|
+
(opts.recordedSinceMs === undefined ||
|
|
314
|
+
(r.recordedAtMs != null &&
|
|
315
|
+
r.recordedAtMs >= opts.recordedSinceMs)) &&
|
|
316
|
+
(opts.recordedUntilMs === undefined ||
|
|
317
|
+
(r.recordedAtMs != null &&
|
|
318
|
+
r.recordedAtMs <= opts.recordedUntilMs)));
|
|
319
|
+
out.sort((a, b) => stamp(b) - stamp(a));
|
|
320
|
+
const offset = opts.offset ?? 0;
|
|
321
|
+
return out.slice(offset, opts.limit === undefined ? undefined : offset + opts.limit);
|
|
322
|
+
}
|
|
304
323
|
}
|
|
305
324
|
function cloneRows(value) {
|
|
306
325
|
if (value === null || typeof value !== "object")
|
|
@@ -11,6 +11,20 @@ export declare class PaymentRepository implements PaymentStore {
|
|
|
11
11
|
listByCustomer(customerId: string): Promise<PaymentRow[]>;
|
|
12
12
|
applyStatus(id: string, expectedFrom: string, to: string, updatedAtMs: number): Promise<PaymentRow | null>;
|
|
13
13
|
listExpired(nowMs: number): Promise<PaymentRow[]>;
|
|
14
|
+
list(opts?: {
|
|
15
|
+
status?: string;
|
|
16
|
+
statuses?: readonly string[];
|
|
17
|
+
purpose?: string;
|
|
18
|
+
productId?: string;
|
|
19
|
+
customerId?: string;
|
|
20
|
+
agentId?: string;
|
|
21
|
+
sinceMs?: number;
|
|
22
|
+
untilMs?: number;
|
|
23
|
+
updatedSinceMs?: number;
|
|
24
|
+
updatedUntilMs?: number;
|
|
25
|
+
limit?: number;
|
|
26
|
+
offset?: number;
|
|
27
|
+
}): Promise<PaymentRow[]>;
|
|
14
28
|
}
|
|
15
29
|
export declare class PaymentAttemptRepository implements PaymentAttemptStore {
|
|
16
30
|
private readonly db;
|
|
@@ -26,6 +40,17 @@ export declare class PaymentAttemptRepository implements PaymentAttemptStore {
|
|
|
26
40
|
listExpired(nowMs: number): Promise<PaymentAttemptRow[]>;
|
|
27
41
|
listPayable(nowMs: number): Promise<PaymentAttemptRow[]>;
|
|
28
42
|
listRecentTerminal(sinceMs: number): Promise<PaymentAttemptRow[]>;
|
|
43
|
+
list(opts?: {
|
|
44
|
+
paymentId?: string;
|
|
45
|
+
provider?: string;
|
|
46
|
+
network?: string;
|
|
47
|
+
status?: string;
|
|
48
|
+
statuses?: readonly string[];
|
|
49
|
+
confirmedSinceMs?: number;
|
|
50
|
+
confirmedUntilMs?: number;
|
|
51
|
+
limit?: number;
|
|
52
|
+
offset?: number;
|
|
53
|
+
}): Promise<PaymentAttemptRow[]>;
|
|
29
54
|
}
|
|
30
55
|
export declare class PaymentReceiptRepository implements PaymentReceiptStore {
|
|
31
56
|
private readonly db;
|
|
@@ -199,6 +199,35 @@ export class PaymentRepository {
|
|
|
199
199
|
}
|
|
200
200
|
return out;
|
|
201
201
|
}
|
|
202
|
+
async list(opts = {}) {
|
|
203
|
+
const statusSet = opts.statuses !== undefined
|
|
204
|
+
? new Set(opts.statuses)
|
|
205
|
+
: opts.status !== undefined
|
|
206
|
+
? new Set([opts.status])
|
|
207
|
+
: undefined;
|
|
208
|
+
const eq = {};
|
|
209
|
+
if (opts.purpose !== undefined)
|
|
210
|
+
eq["purpose"] = opts.purpose;
|
|
211
|
+
if (opts.productId !== undefined)
|
|
212
|
+
eq["productId"] = opts.productId;
|
|
213
|
+
if (opts.customerId !== undefined)
|
|
214
|
+
eq["customerId"] = opts.customerId;
|
|
215
|
+
if (opts.agentId !== undefined)
|
|
216
|
+
eq["agentId"] = opts.agentId;
|
|
217
|
+
const candidates = await this.orm.where(eq).all();
|
|
218
|
+
const out = candidates
|
|
219
|
+
.map(toPaymentRow)
|
|
220
|
+
.filter((r) => (statusSet === undefined || statusSet.has(r.status)) &&
|
|
221
|
+
(opts.sinceMs === undefined || r.createdAtMs >= opts.sinceMs) &&
|
|
222
|
+
(opts.untilMs === undefined || r.createdAtMs <= opts.untilMs) &&
|
|
223
|
+
(opts.updatedSinceMs === undefined ||
|
|
224
|
+
r.updatedAtMs >= opts.updatedSinceMs) &&
|
|
225
|
+
(opts.updatedUntilMs === undefined ||
|
|
226
|
+
r.updatedAtMs <= opts.updatedUntilMs));
|
|
227
|
+
out.sort((a, b) => b.createdAtMs - a.createdAtMs);
|
|
228
|
+
const offset = opts.offset ?? 0;
|
|
229
|
+
return out.slice(offset, opts.limit === undefined ? undefined : offset + opts.limit);
|
|
230
|
+
}
|
|
202
231
|
}
|
|
203
232
|
export class PaymentAttemptRepository {
|
|
204
233
|
db;
|
|
@@ -323,6 +352,33 @@ export class PaymentAttemptRepository {
|
|
|
323
352
|
}
|
|
324
353
|
return out;
|
|
325
354
|
}
|
|
355
|
+
async list(opts = {}) {
|
|
356
|
+
const statusSet = opts.statuses !== undefined
|
|
357
|
+
? new Set(opts.statuses)
|
|
358
|
+
: opts.status !== undefined
|
|
359
|
+
? new Set([opts.status])
|
|
360
|
+
: undefined;
|
|
361
|
+
const eq = {};
|
|
362
|
+
if (opts.paymentId !== undefined)
|
|
363
|
+
eq["paymentId"] = opts.paymentId;
|
|
364
|
+
if (opts.provider !== undefined)
|
|
365
|
+
eq["provider"] = opts.provider;
|
|
366
|
+
if (opts.network !== undefined)
|
|
367
|
+
eq["network"] = opts.network;
|
|
368
|
+
const candidates = await this.orm.where(eq).all();
|
|
369
|
+
const out = candidates
|
|
370
|
+
.map(toAttemptRow)
|
|
371
|
+
.filter((r) => (statusSet === undefined || statusSet.has(r.status)) &&
|
|
372
|
+
(opts.confirmedSinceMs === undefined ||
|
|
373
|
+
(r.confirmedAtMs != null &&
|
|
374
|
+
r.confirmedAtMs >= opts.confirmedSinceMs)) &&
|
|
375
|
+
(opts.confirmedUntilMs === undefined ||
|
|
376
|
+
(r.confirmedAtMs != null &&
|
|
377
|
+
r.confirmedAtMs <= opts.confirmedUntilMs)));
|
|
378
|
+
out.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
|
|
379
|
+
const offset = opts.offset ?? 0;
|
|
380
|
+
return out.slice(offset, opts.limit === undefined ? undefined : offset + opts.limit);
|
|
381
|
+
}
|
|
326
382
|
}
|
|
327
383
|
export class PaymentReceiptRepository {
|
|
328
384
|
db;
|
|
@@ -28,6 +28,20 @@ export interface PaymentStore {
|
|
|
28
28
|
listByCustomer(customerId: string): Promise<PaymentRow[]>;
|
|
29
29
|
applyStatus(id: string, expectedFrom: string, to: string, updatedAtMs: number): Promise<PaymentRow | null>;
|
|
30
30
|
listExpired(nowMs: number): Promise<PaymentRow[]>;
|
|
31
|
+
list(opts?: {
|
|
32
|
+
status?: string;
|
|
33
|
+
statuses?: readonly string[];
|
|
34
|
+
purpose?: string;
|
|
35
|
+
productId?: string;
|
|
36
|
+
customerId?: string;
|
|
37
|
+
agentId?: string;
|
|
38
|
+
sinceMs?: number;
|
|
39
|
+
untilMs?: number;
|
|
40
|
+
updatedSinceMs?: number;
|
|
41
|
+
updatedUntilMs?: number;
|
|
42
|
+
limit?: number;
|
|
43
|
+
offset?: number;
|
|
44
|
+
}): Promise<PaymentRow[]>;
|
|
31
45
|
}
|
|
32
46
|
export interface PaymentAttemptInsert {
|
|
33
47
|
id: string;
|
|
@@ -64,6 +78,17 @@ export interface PaymentAttemptStore {
|
|
|
64
78
|
listExpired(nowMs: number): Promise<PaymentAttemptRow[]>;
|
|
65
79
|
listPayable(nowMs: number): Promise<PaymentAttemptRow[]>;
|
|
66
80
|
listRecentTerminal(sinceMs: number): Promise<PaymentAttemptRow[]>;
|
|
81
|
+
list(opts?: {
|
|
82
|
+
paymentId?: string;
|
|
83
|
+
provider?: string;
|
|
84
|
+
network?: string;
|
|
85
|
+
status?: string;
|
|
86
|
+
statuses?: readonly string[];
|
|
87
|
+
confirmedSinceMs?: number;
|
|
88
|
+
confirmedUntilMs?: number;
|
|
89
|
+
limit?: number;
|
|
90
|
+
offset?: number;
|
|
91
|
+
}): Promise<PaymentAttemptRow[]>;
|
|
67
92
|
}
|
|
68
93
|
export interface PaymentReceiptInsert {
|
|
69
94
|
id: string;
|
|
@@ -222,6 +247,20 @@ export declare class InMemoryPaymentStore implements PaymentStore {
|
|
|
222
247
|
listByCustomer(customerId: string): Promise<PaymentRow[]>;
|
|
223
248
|
applyStatus(id: string, expectedFrom: string, to: string, updatedAtMs: number): Promise<PaymentRow | null>;
|
|
224
249
|
listExpired(nowMs: number): Promise<PaymentRow[]>;
|
|
250
|
+
list(opts?: {
|
|
251
|
+
status?: string;
|
|
252
|
+
statuses?: readonly string[];
|
|
253
|
+
purpose?: string;
|
|
254
|
+
productId?: string;
|
|
255
|
+
customerId?: string;
|
|
256
|
+
agentId?: string;
|
|
257
|
+
sinceMs?: number;
|
|
258
|
+
untilMs?: number;
|
|
259
|
+
updatedSinceMs?: number;
|
|
260
|
+
updatedUntilMs?: number;
|
|
261
|
+
limit?: number;
|
|
262
|
+
offset?: number;
|
|
263
|
+
}): Promise<PaymentRow[]>;
|
|
225
264
|
}
|
|
226
265
|
export declare class InMemoryPaymentAttemptStore implements PaymentAttemptStore {
|
|
227
266
|
private readonly rows;
|
|
@@ -234,6 +273,17 @@ export declare class InMemoryPaymentAttemptStore implements PaymentAttemptStore
|
|
|
234
273
|
listExpired(nowMs: number): Promise<PaymentAttemptRow[]>;
|
|
235
274
|
listPayable(nowMs: number): Promise<PaymentAttemptRow[]>;
|
|
236
275
|
listRecentTerminal(sinceMs: number): Promise<PaymentAttemptRow[]>;
|
|
276
|
+
list(opts?: {
|
|
277
|
+
paymentId?: string;
|
|
278
|
+
provider?: string;
|
|
279
|
+
network?: string;
|
|
280
|
+
status?: string;
|
|
281
|
+
statuses?: readonly string[];
|
|
282
|
+
confirmedSinceMs?: number;
|
|
283
|
+
confirmedUntilMs?: number;
|
|
284
|
+
limit?: number;
|
|
285
|
+
offset?: number;
|
|
286
|
+
}): Promise<PaymentAttemptRow[]>;
|
|
237
287
|
private readonly terminalStampMs;
|
|
238
288
|
}
|
|
239
289
|
export declare class InMemoryPaymentReceiptStore implements PaymentReceiptStore {
|
|
@@ -63,6 +63,28 @@ export class InMemoryPaymentStore {
|
|
|
63
63
|
r.expiresAtMs < nowMs &&
|
|
64
64
|
(r.status === "PENDING" || r.status === "PROCESSING"));
|
|
65
65
|
}
|
|
66
|
+
async list(opts = {}) {
|
|
67
|
+
const statusSet = opts.statuses !== undefined
|
|
68
|
+
? new Set(opts.statuses)
|
|
69
|
+
: opts.status !== undefined
|
|
70
|
+
? new Set([opts.status])
|
|
71
|
+
: undefined;
|
|
72
|
+
const out = [...this.rows.values()].filter((r) => (statusSet === undefined || statusSet.has(r.status)) &&
|
|
73
|
+
(opts.purpose === undefined || r.purpose === opts.purpose) &&
|
|
74
|
+
(opts.productId === undefined || r.productId === opts.productId) &&
|
|
75
|
+
(opts.customerId === undefined ||
|
|
76
|
+
r.customerId === opts.customerId) &&
|
|
77
|
+
(opts.agentId === undefined || r.agentId === opts.agentId) &&
|
|
78
|
+
(opts.sinceMs === undefined || r.createdAtMs >= opts.sinceMs) &&
|
|
79
|
+
(opts.untilMs === undefined || r.createdAtMs <= opts.untilMs) &&
|
|
80
|
+
(opts.updatedSinceMs === undefined ||
|
|
81
|
+
r.updatedAtMs >= opts.updatedSinceMs) &&
|
|
82
|
+
(opts.updatedUntilMs === undefined ||
|
|
83
|
+
r.updatedAtMs <= opts.updatedUntilMs));
|
|
84
|
+
out.sort((a, b) => b.createdAtMs - a.createdAtMs);
|
|
85
|
+
const offset = opts.offset ?? 0;
|
|
86
|
+
return out.slice(offset, opts.limit === undefined ? undefined : offset + opts.limit);
|
|
87
|
+
}
|
|
66
88
|
}
|
|
67
89
|
export class InMemoryPaymentAttemptStore {
|
|
68
90
|
rows = new Map();
|
|
@@ -148,6 +170,26 @@ export class InMemoryPaymentAttemptStore {
|
|
|
148
170
|
return stamp == null || stamp >= sinceMs;
|
|
149
171
|
});
|
|
150
172
|
}
|
|
173
|
+
async list(opts = {}) {
|
|
174
|
+
const statusSet = opts.statuses !== undefined
|
|
175
|
+
? new Set(opts.statuses)
|
|
176
|
+
: opts.status !== undefined
|
|
177
|
+
? new Set([opts.status])
|
|
178
|
+
: undefined;
|
|
179
|
+
const out = [...this.rows.values()].filter((r) => (opts.paymentId === undefined || r.paymentId === opts.paymentId) &&
|
|
180
|
+
(opts.provider === undefined || r.provider === opts.provider) &&
|
|
181
|
+
(opts.network === undefined || r.network === opts.network) &&
|
|
182
|
+
(statusSet === undefined || statusSet.has(r.status)) &&
|
|
183
|
+
(opts.confirmedSinceMs === undefined ||
|
|
184
|
+
(r.confirmedAtMs != null &&
|
|
185
|
+
r.confirmedAtMs >= opts.confirmedSinceMs)) &&
|
|
186
|
+
(opts.confirmedUntilMs === undefined ||
|
|
187
|
+
(r.confirmedAtMs != null &&
|
|
188
|
+
r.confirmedAtMs <= opts.confirmedUntilMs)));
|
|
189
|
+
out.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
|
|
190
|
+
const offset = opts.offset ?? 0;
|
|
191
|
+
return out.slice(offset, opts.limit === undefined ? undefined : offset + opts.limit);
|
|
192
|
+
}
|
|
151
193
|
terminalStampMs = new Map();
|
|
152
194
|
}
|
|
153
195
|
export class InMemoryPaymentReceiptStore {
|
package/package.json
CHANGED