@agentbadge/database 0.6.11 → 0.6.14

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.
@@ -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;
@@ -315,7 +344,7 @@ export class PaymentAttemptRepository {
315
344
  const out = [];
316
345
  for (const status of TERMINAL_ATTEMPT_STATUSES) {
317
346
  const plan = this.db.raw
318
- .sql `SELECT "id","paymentId","provider","network","token","amount","currency","status","providerReference","transactionHash","expiresAtMs","confirmedAtMs","payload","createdAt","updatedAt" FROM "paymentAttempt" WHERE "status" = ${param(status, { codecId: "pg/text@1" })} AND "updatedAt" >= to_timestamp(${param(sinceMs, { codecId: "pg/int8@1" })} / 1000.0) ORDER BY "updatedAt" ASC, "id" ASC`
347
+ .sql `SELECT "id","paymentId","provider","network","token","amount","currency","status","providerReference","transactionHash","expiresAtMs","confirmedAtMs","payload","createdAt","updatedAt" FROM "paymentAttempt" WHERE "status" = ${param(status, { codecId: "pg/text@1" })} AND "updatedAt" >= to_timestamp(${param(BigInt(sinceMs), { codecId: "pg/int8@1" })} / 1000.0) ORDER BY "updatedAt" ASC, "id" ASC`
319
348
  .returnsRow(ATTEMPT_ROW_SPEC)
320
349
  .build();
321
350
  const rows = await this.db.runtime().query(plan);
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentbadge/database",
3
- "version": "0.6.11",
3
+ "version": "0.6.14",
4
4
  "description": "Shared database layer for AgentBadge — Prisma ORM 8 client, repositories, store abstraction",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",