@agentbadge/database 0.6.2 → 0.6.3
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 +4 -0
- package/dist/database.js +6 -0
- package/dist/index.d.ts +7 -3
- package/dist/index.js +4 -2
- package/dist/prisma/contract.json +1841 -393
- package/dist/repositories/agent-request-repository.d.ts +56 -0
- package/dist/repositories/agent-request-repository.js +145 -0
- package/dist/repositories/agent-survey-repository.d.ts +37 -0
- package/dist/repositories/agent-survey-repository.js +82 -0
- package/dist/repositories/payment-repository.d.ts +29 -1
- package/dist/repositories/payment-repository.js +179 -0
- package/dist/repositories/payment-store.d.ts +81 -0
- package/dist/repositories/payment-store.js +105 -0
- package/package.json +1 -1
|
@@ -126,6 +126,9 @@ export class InMemoryPaymentAttemptStore {
|
|
|
126
126
|
updatedAt: nowIso(),
|
|
127
127
|
};
|
|
128
128
|
this.rows.set(id, updated);
|
|
129
|
+
if (TERMINAL_ATTEMPT_STATUSES.includes(to)) {
|
|
130
|
+
this.terminalStampMs.set(id, updatedAtMs);
|
|
131
|
+
}
|
|
129
132
|
return updated;
|
|
130
133
|
}
|
|
131
134
|
async listExpired(nowMs) {
|
|
@@ -133,6 +136,19 @@ export class InMemoryPaymentAttemptStore {
|
|
|
133
136
|
r.expiresAtMs < nowMs &&
|
|
134
137
|
!TERMINAL_ATTEMPT_STATUSES.includes(r.status));
|
|
135
138
|
}
|
|
139
|
+
async listPayable(nowMs) {
|
|
140
|
+
return [...this.rows.values()].filter((r) => !TERMINAL_ATTEMPT_STATUSES.includes(r.status) &&
|
|
141
|
+
(r.expiresAtMs == null || r.expiresAtMs > nowMs));
|
|
142
|
+
}
|
|
143
|
+
async listRecentTerminal(sinceMs) {
|
|
144
|
+
return [...this.rows.values()].filter((r) => {
|
|
145
|
+
if (!TERMINAL_ATTEMPT_STATUSES.includes(r.status))
|
|
146
|
+
return false;
|
|
147
|
+
const stamp = this.terminalStampMs.get(r.id) ?? r.confirmedAtMs;
|
|
148
|
+
return stamp == null || stamp >= sinceMs;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
terminalStampMs = new Map();
|
|
136
152
|
}
|
|
137
153
|
export class InMemoryPaymentReceiptStore {
|
|
138
154
|
rows = new Map();
|
|
@@ -257,13 +273,102 @@ export class InMemoryPaymentPriceStore {
|
|
|
257
273
|
return all;
|
|
258
274
|
}
|
|
259
275
|
}
|
|
276
|
+
export class InMemoryPaymentExceptionStore {
|
|
277
|
+
rows = new Map();
|
|
278
|
+
async append(e) {
|
|
279
|
+
if (this.rows.has(e.id))
|
|
280
|
+
return null;
|
|
281
|
+
const row = {
|
|
282
|
+
...e,
|
|
283
|
+
resolvedAtMs: null,
|
|
284
|
+
resolutionNote: null,
|
|
285
|
+
createdAt: nowIso(),
|
|
286
|
+
};
|
|
287
|
+
this.rows.set(row.id, row);
|
|
288
|
+
return row;
|
|
289
|
+
}
|
|
290
|
+
async getById(id) {
|
|
291
|
+
return this.rows.get(id) ?? null;
|
|
292
|
+
}
|
|
293
|
+
async listByPayment(paymentId) {
|
|
294
|
+
return [...this.rows.values()].filter((r) => r.paymentId === paymentId);
|
|
295
|
+
}
|
|
296
|
+
async list(opts = {}) {
|
|
297
|
+
let out = [...this.rows.values()].filter((r) => (opts.status === undefined || r.status === opts.status) &&
|
|
298
|
+
(opts.kind === undefined || r.kind === opts.kind) &&
|
|
299
|
+
(opts.sinceMs === undefined || r.createdAtMs >= opts.sinceMs));
|
|
300
|
+
out.sort((a, b) => b.createdAtMs - a.createdAtMs);
|
|
301
|
+
if (opts.limit !== undefined)
|
|
302
|
+
out = out.slice(0, opts.limit);
|
|
303
|
+
return out;
|
|
304
|
+
}
|
|
305
|
+
async resolve(id, status, note) {
|
|
306
|
+
const row = this.rows.get(id);
|
|
307
|
+
if (!row || row.status !== "OPEN")
|
|
308
|
+
return null;
|
|
309
|
+
const next = {
|
|
310
|
+
...row,
|
|
311
|
+
status,
|
|
312
|
+
resolvedAtMs: Date.now(),
|
|
313
|
+
resolutionNote: note ?? null,
|
|
314
|
+
};
|
|
315
|
+
this.rows.set(id, next);
|
|
316
|
+
return next;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
export class InMemoryUsageRecordStore {
|
|
320
|
+
rows = new Map();
|
|
321
|
+
async append(r) {
|
|
322
|
+
if (this.rows.has(r.id))
|
|
323
|
+
return null;
|
|
324
|
+
for (const x of this.rows.values()) {
|
|
325
|
+
if (x.requestId === r.requestId)
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
const row = {
|
|
329
|
+
...r,
|
|
330
|
+
agentId: r.agentId ?? null,
|
|
331
|
+
currency: r.currency ?? "USDC",
|
|
332
|
+
txHash: r.txHash ?? null,
|
|
333
|
+
createdAt: nowIso(),
|
|
334
|
+
};
|
|
335
|
+
this.rows.set(row.id, row);
|
|
336
|
+
return row;
|
|
337
|
+
}
|
|
338
|
+
async getById(id) {
|
|
339
|
+
return this.rows.get(id) ?? null;
|
|
340
|
+
}
|
|
341
|
+
async getByRequestId(requestId) {
|
|
342
|
+
return ([...this.rows.values()].find((r) => r.requestId === requestId) ??
|
|
343
|
+
null);
|
|
344
|
+
}
|
|
345
|
+
async listByPayment(paymentId) {
|
|
346
|
+
return [...this.rows.values()]
|
|
347
|
+
.filter((r) => r.paymentId === paymentId)
|
|
348
|
+
.sort((a, b) => b.createdAtMs - a.createdAtMs);
|
|
349
|
+
}
|
|
350
|
+
async listByAgent(agentId, limit) {
|
|
351
|
+
const out = [...this.rows.values()]
|
|
352
|
+
.filter((r) => r.agentId === agentId)
|
|
353
|
+
.sort((a, b) => b.createdAtMs - a.createdAtMs);
|
|
354
|
+
return limit === undefined ? out : out.slice(0, limit);
|
|
355
|
+
}
|
|
356
|
+
async listByResource(resource, limit) {
|
|
357
|
+
const out = [...this.rows.values()]
|
|
358
|
+
.filter((r) => r.resource === resource)
|
|
359
|
+
.sort((a, b) => b.createdAtMs - a.createdAtMs);
|
|
360
|
+
return limit === undefined ? out : out.slice(0, limit);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
260
363
|
export function createInMemoryPaymentStores() {
|
|
261
364
|
return {
|
|
262
365
|
payments: new InMemoryPaymentStore(),
|
|
263
366
|
attempts: new InMemoryPaymentAttemptStore(),
|
|
264
367
|
receipts: new InMemoryPaymentReceiptStore(),
|
|
265
368
|
events: new InMemoryPaymentEventStore(),
|
|
369
|
+
exceptions: new InMemoryPaymentExceptionStore(),
|
|
266
370
|
products: new InMemoryPaymentProductStore(),
|
|
267
371
|
prices: new InMemoryPaymentPriceStore(),
|
|
372
|
+
usageRecords: new InMemoryUsageRecordStore(),
|
|
268
373
|
};
|
|
269
374
|
}
|