@agentbadge/database 0.6.10 → 0.6.11

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.
@@ -188,7 +188,7 @@ export class EntitlementRepository {
188
188
  const cur = afterKey !== undefined ? parseReversalCursor(afterKey) : null;
189
189
  const plan = cur !== null
190
190
  ? this.db.raw
191
- .sql `SELECT "id","ownerId","productCode","sourcePaymentId","status","validFromMs","validUntilMs","idempotencyKey","activeSlot","payload","createdAt","updatedAt" FROM "entitlement" WHERE "status" = 'ACTIVE' AND "sourcePaymentId" IS NOT NULL AND ("createdAt" > ${param(cur.cAt, { codecId: "pg/timestamptz-string@1" })} OR ("createdAt" = ${param(cur.cAt, { codecId: "pg/timestamptz-string@1" })} AND "id" > ${param(cur.cId, { codecId: "pg/text@1" })})) ORDER BY "createdAt" ASC, "id" ASC LIMIT ${lim}`
191
+ .sql `SELECT "id","ownerId","productCode","sourcePaymentId","status","validFromMs","validUntilMs","idempotencyKey","activeSlot","payload","createdAt","updatedAt" FROM "entitlement" WHERE "status" = 'ACTIVE' AND "sourcePaymentId" IS NOT NULL AND ("createdAt","id") > (${param(cur.cAt, { codecId: "pg/timestamptz-string@1" })}, ${param(cur.cId, { codecId: "pg/text@1" })})) ORDER BY "createdAt" ASC, "id" ASC LIMIT ${lim}`
192
192
  .returnsRow(ENTITLEMENT_ROW_SPEC)
193
193
  .build()
194
194
  : this.db.raw
@@ -1,11 +1,15 @@
1
1
  const nowIso = () => new Date().toISOString();
2
+ const CURSOR_TS_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?(Z|[+-]\d{2}:\d{2})$/;
2
3
  export const parseReversalCursor = (afterKey) => {
3
4
  const sep = afterKey.indexOf("|");
4
5
  if (sep <= 0 || sep === afterKey.length - 1)
5
6
  return null;
6
7
  const cAt = afterKey.slice(0, sep);
7
8
  const cId = afterKey.slice(sep + 1);
8
- if (Number.isNaN(Date.parse(cAt)))
9
+ if (!CURSOR_TS_RE.test(cAt))
10
+ return null;
11
+ const parsed = Date.parse(cAt);
12
+ if (Number.isNaN(parsed))
9
13
  return null;
10
14
  return { cAt, cId };
11
15
  };
@@ -312,11 +312,10 @@ export class PaymentAttemptRepository {
312
312
  return out;
313
313
  }
314
314
  async listRecentTerminal(sinceMs) {
315
- const sinceParam = param(sinceMs, { codecId: "pg/int8@1" });
316
315
  const out = [];
317
316
  for (const status of TERMINAL_ATTEMPT_STATUSES) {
318
317
  const plan = this.db.raw
319
- .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 COALESCE(EXTRACT(EPOCH FROM "updatedAt") * 1000, "confirmedAtMs"::float8, 0) >= ${sinceParam}`
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`
320
319
  .returnsRow(ATTEMPT_ROW_SPEC)
321
320
  .build();
322
321
  const rows = await this.db.runtime().query(plan);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentbadge/database",
3
- "version": "0.6.10",
3
+ "version": "0.6.11",
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",