@secondlayer/shared 6.41.1 → 6.41.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.
@@ -137,6 +137,7 @@ interface SubgraphsTable {
137
137
  /** (event type, contract) probe pairs persisted at deploy for weight classification. */
138
138
  sparse_probe_targets: unknown | null;
139
139
  database_url_enc: ColumnType<Buffer | null, Buffer | null | undefined, Buffer | null>;
140
+ sandbox_workers: Generated<boolean>;
140
141
  created_at: Generated<Date>;
141
142
  updated_at: Generated<Date>;
142
143
  }
@@ -752,6 +753,11 @@ interface X402PaymentsTable {
752
753
  /** USD-micros to credit on confirmation, for deposit rows the reconciler
753
754
  * settles asynchronously. NULL for per-call settles (credit nothing). */
754
755
  credit_usd_micros: string | null;
756
+ /** Idempotency key: stamped exactly once when this row's credit is applied.
757
+ * NULL means never credited (or not a credit-bearing row). Pre-migration
758
+ * non-pending deposit rows are backfilled to a non-null sentinel so the
759
+ * reconciler's heal path can never double-credit them. */
760
+ credited_at: Generated<Date> | null;
755
761
  }
756
762
  type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
757
763
  interface TenantsTable {
@@ -119,6 +119,7 @@ interface SubgraphsTable {
119
119
  /** (event type, contract) probe pairs persisted at deploy for weight classification. */
120
120
  sparse_probe_targets: unknown | null;
121
121
  database_url_enc: ColumnType<Buffer | null, Buffer | null | undefined, Buffer | null>;
122
+ sandbox_workers: Generated<boolean>;
122
123
  created_at: Generated<Date>;
123
124
  updated_at: Generated<Date>;
124
125
  }
@@ -734,6 +735,11 @@ interface X402PaymentsTable {
734
735
  /** USD-micros to credit on confirmation, for deposit rows the reconciler
735
736
  * settles asynchronously. NULL for per-call settles (credit nothing). */
736
737
  credit_usd_micros: string | null;
738
+ /** Idempotency key: stamped exactly once when this row's credit is applied.
739
+ * NULL means never credited (or not a credit-bearing row). Pre-migration
740
+ * non-pending deposit rows are backfilled to a non-null sentinel so the
741
+ * reconciler's heal path can never double-credit them. */
742
+ credited_at: Generated<Date> | null;
737
743
  }
738
744
  type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
739
745
  interface TenantsTable {
@@ -119,6 +119,7 @@ interface SubgraphsTable {
119
119
  /** (event type, contract) probe pairs persisted at deploy for weight classification. */
120
120
  sparse_probe_targets: unknown | null;
121
121
  database_url_enc: ColumnType<Buffer | null, Buffer | null | undefined, Buffer | null>;
122
+ sandbox_workers: Generated<boolean>;
122
123
  created_at: Generated<Date>;
123
124
  updated_at: Generated<Date>;
124
125
  }
@@ -734,6 +735,11 @@ interface X402PaymentsTable {
734
735
  /** USD-micros to credit on confirmation, for deposit rows the reconciler
735
736
  * settles asynchronously. NULL for per-call settles (credit nothing). */
736
737
  credit_usd_micros: string | null;
738
+ /** Idempotency key: stamped exactly once when this row's credit is applied.
739
+ * NULL means never credited (or not a credit-bearing row). Pre-migration
740
+ * non-pending deposit rows are backfilled to a non-null sentinel so the
741
+ * reconciler's heal path can never double-credit them. */
742
+ credited_at: Generated<Date> | null;
737
743
  }
738
744
  type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
739
745
  interface TenantsTable {
@@ -119,6 +119,7 @@ interface SubgraphsTable {
119
119
  /** (event type, contract) probe pairs persisted at deploy for weight classification. */
120
120
  sparse_probe_targets: unknown | null;
121
121
  database_url_enc: ColumnType<Buffer | null, Buffer | null | undefined, Buffer | null>;
122
+ sandbox_workers: Generated<boolean>;
122
123
  created_at: Generated<Date>;
123
124
  updated_at: Generated<Date>;
124
125
  }
@@ -734,6 +735,11 @@ interface X402PaymentsTable {
734
735
  /** USD-micros to credit on confirmation, for deposit rows the reconciler
735
736
  * settles asynchronously. NULL for per-call settles (credit nothing). */
736
737
  credit_usd_micros: string | null;
738
+ /** Idempotency key: stamped exactly once when this row's credit is applied.
739
+ * NULL means never credited (or not a credit-bearing row). Pre-migration
740
+ * non-pending deposit rows are backfilled to a non-null sentinel so the
741
+ * reconciler's heal path can never double-credit them. */
742
+ credited_at: Generated<Date> | null;
737
743
  }
738
744
  type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
739
745
  interface TenantsTable {
@@ -119,6 +119,7 @@ interface SubgraphsTable {
119
119
  /** (event type, contract) probe pairs persisted at deploy for weight classification. */
120
120
  sparse_probe_targets: unknown | null;
121
121
  database_url_enc: ColumnType<Buffer | null, Buffer | null | undefined, Buffer | null>;
122
+ sandbox_workers: Generated<boolean>;
122
123
  created_at: Generated<Date>;
123
124
  updated_at: Generated<Date>;
124
125
  }
@@ -734,6 +735,11 @@ interface X402PaymentsTable {
734
735
  /** USD-micros to credit on confirmation, for deposit rows the reconciler
735
736
  * settles asynchronously. NULL for per-call settles (credit nothing). */
736
737
  credit_usd_micros: string | null;
738
+ /** Idempotency key: stamped exactly once when this row's credit is applied.
739
+ * NULL means never credited (or not a credit-bearing row). Pre-migration
740
+ * non-pending deposit rows are backfilled to a non-null sentinel so the
741
+ * reconciler's heal path can never double-credit them. */
742
+ credited_at: Generated<Date> | null;
737
743
  }
738
744
  type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
739
745
  interface TenantsTable {
@@ -119,6 +119,7 @@ interface SubgraphsTable {
119
119
  /** (event type, contract) probe pairs persisted at deploy for weight classification. */
120
120
  sparse_probe_targets: unknown | null;
121
121
  database_url_enc: ColumnType<Buffer | null, Buffer | null | undefined, Buffer | null>;
122
+ sandbox_workers: Generated<boolean>;
122
123
  created_at: Generated<Date>;
123
124
  updated_at: Generated<Date>;
124
125
  }
@@ -734,6 +735,11 @@ interface X402PaymentsTable {
734
735
  /** USD-micros to credit on confirmation, for deposit rows the reconciler
735
736
  * settles asynchronously. NULL for per-call settles (credit nothing). */
736
737
  credit_usd_micros: string | null;
738
+ /** Idempotency key: stamped exactly once when this row's credit is applied.
739
+ * NULL means never credited (or not a credit-bearing row). Pre-migration
740
+ * non-pending deposit rows are backfilled to a non-null sentinel so the
741
+ * reconciler's heal path can never double-credit them. */
742
+ credited_at: Generated<Date> | null;
737
743
  }
738
744
  type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
739
745
  interface TenantsTable {
@@ -120,6 +120,7 @@ interface SubgraphsTable {
120
120
  /** (event type, contract) probe pairs persisted at deploy for weight classification. */
121
121
  sparse_probe_targets: unknown | null;
122
122
  database_url_enc: ColumnType<Buffer | null, Buffer | null | undefined, Buffer | null>;
123
+ sandbox_workers: Generated<boolean>;
123
124
  created_at: Generated<Date>;
124
125
  updated_at: Generated<Date>;
125
126
  }
@@ -735,6 +736,11 @@ interface X402PaymentsTable {
735
736
  /** USD-micros to credit on confirmation, for deposit rows the reconciler
736
737
  * settles asynchronously. NULL for per-call settles (credit nothing). */
737
738
  credit_usd_micros: string | null;
739
+ /** Idempotency key: stamped exactly once when this row's credit is applied.
740
+ * NULL means never credited (or not a credit-bearing row). Pre-migration
741
+ * non-pending deposit rows are backfilled to a non-null sentinel so the
742
+ * reconciler's heal path can never double-credit them. */
743
+ credited_at: Generated<Date> | null;
738
744
  }
739
745
  type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
740
746
  interface TenantsTable {
@@ -119,6 +119,7 @@ interface SubgraphsTable {
119
119
  /** (event type, contract) probe pairs persisted at deploy for weight classification. */
120
120
  sparse_probe_targets: unknown | null;
121
121
  database_url_enc: ColumnType<Buffer | null, Buffer | null | undefined, Buffer | null>;
122
+ sandbox_workers: Generated<boolean>;
122
123
  created_at: Generated<Date>;
123
124
  updated_at: Generated<Date>;
124
125
  }
@@ -734,6 +735,11 @@ interface X402PaymentsTable {
734
735
  /** USD-micros to credit on confirmation, for deposit rows the reconciler
735
736
  * settles asynchronously. NULL for per-call settles (credit nothing). */
736
737
  credit_usd_micros: string | null;
738
+ /** Idempotency key: stamped exactly once when this row's credit is applied.
739
+ * NULL means never credited (or not a credit-bearing row). Pre-migration
740
+ * non-pending deposit rows are backfilled to a non-null sentinel so the
741
+ * reconciler's heal path can never double-credit them. */
742
+ credited_at: Generated<Date> | null;
737
743
  }
738
744
  type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
739
745
  interface TenantsTable {
@@ -118,6 +118,7 @@ interface SubgraphsTable {
118
118
  /** (event type, contract) probe pairs persisted at deploy for weight classification. */
119
119
  sparse_probe_targets: unknown | null;
120
120
  database_url_enc: ColumnType<Buffer | null, Buffer | null | undefined, Buffer | null>;
121
+ sandbox_workers: Generated<boolean>;
121
122
  created_at: Generated<Date>;
122
123
  updated_at: Generated<Date>;
123
124
  }
@@ -733,6 +734,11 @@ interface X402PaymentsTable {
733
734
  /** USD-micros to credit on confirmation, for deposit rows the reconciler
734
735
  * settles asynchronously. NULL for per-call settles (credit nothing). */
735
736
  credit_usd_micros: string | null;
737
+ /** Idempotency key: stamped exactly once when this row's credit is applied.
738
+ * NULL means never credited (or not a credit-bearing row). Pre-migration
739
+ * non-pending deposit rows are backfilled to a non-null sentinel so the
740
+ * reconciler's heal path can never double-credit them. */
741
+ credited_at: Generated<Date> | null;
736
742
  }
737
743
  type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
738
744
  interface TenantsTable {
@@ -118,6 +118,7 @@ interface SubgraphsTable {
118
118
  /** (event type, contract) probe pairs persisted at deploy for weight classification. */
119
119
  sparse_probe_targets: unknown | null;
120
120
  database_url_enc: ColumnType<Buffer | null, Buffer | null | undefined, Buffer | null>;
121
+ sandbox_workers: Generated<boolean>;
121
122
  created_at: Generated<Date>;
122
123
  updated_at: Generated<Date>;
123
124
  }
@@ -733,6 +734,11 @@ interface X402PaymentsTable {
733
734
  /** USD-micros to credit on confirmation, for deposit rows the reconciler
734
735
  * settles asynchronously. NULL for per-call settles (credit nothing). */
735
736
  credit_usd_micros: string | null;
737
+ /** Idempotency key: stamped exactly once when this row's credit is applied.
738
+ * NULL means never credited (or not a credit-bearing row). Pre-migration
739
+ * non-pending deposit rows are backfilled to a non-null sentinel so the
740
+ * reconciler's heal path can never double-credit them. */
741
+ credited_at: Generated<Date> | null;
736
742
  }
737
743
  type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
738
744
  interface TenantsTable {
@@ -119,6 +119,7 @@ interface SubgraphsTable {
119
119
  /** (event type, contract) probe pairs persisted at deploy for weight classification. */
120
120
  sparse_probe_targets: unknown | null;
121
121
  database_url_enc: ColumnType<Buffer | null, Buffer | null | undefined, Buffer | null>;
122
+ sandbox_workers: Generated<boolean>;
122
123
  created_at: Generated<Date>;
123
124
  updated_at: Generated<Date>;
124
125
  }
@@ -734,6 +735,11 @@ interface X402PaymentsTable {
734
735
  /** USD-micros to credit on confirmation, for deposit rows the reconciler
735
736
  * settles asynchronously. NULL for per-call settles (credit nothing). */
736
737
  credit_usd_micros: string | null;
738
+ /** Idempotency key: stamped exactly once when this row's credit is applied.
739
+ * NULL means never credited (or not a credit-bearing row). Pre-migration
740
+ * non-pending deposit rows are backfilled to a non-null sentinel so the
741
+ * reconciler's heal path can never double-credit them. */
742
+ credited_at: Generated<Date> | null;
737
743
  }
738
744
  type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
739
745
  interface TenantsTable {
@@ -0,0 +1,41 @@
1
+ import { type Kysely, sql } from "kysely";
2
+ import { onControlPlane } from "../src/db/migration-role.ts";
3
+
4
+ // `credited_at` is the idempotency key for deposit crediting: stamped exactly
5
+ // once, whenever a deposit's balance credit is applied. Only a row where it's
6
+ // NULL is eligible for the reconciler's heal path (f069).
7
+ //
8
+ // THE TRAP: right after ADD COLUMN, every existing row (including historical
9
+ // `confirmed` deposits the old route-handler path already credited) has
10
+ // credited_at = NULL. If the reconciler treated NULL as "never credited" for
11
+ // those rows, it would DOUBLE-CREDIT every already-credited historical
12
+ // deposit. So we backfill all pre-existing non-pending deposit rows to a
13
+ // non-null sentinel (`updated_at`) — their true credit state is unknowable
14
+ // from ledger data alone, so healing must never touch them. `pending` rows
15
+ // stay NULL (not yet credited, still eligible once they confirm) and
16
+ // non-deposit rows stay NULL (they never carry a credit). Only rows created
17
+ // AFTER this migration are ever heal-eligible. Back-crediting truly-stranded
18
+ // historical rows is a separate founder payout decision, OUT OF SCOPE here.
19
+ export async function up(db: Kysely<unknown>): Promise<void> {
20
+ await sql`SET lock_timeout = '30s'`.execute(db);
21
+ await onControlPlane(async () => {
22
+ await sql`
23
+ ALTER TABLE x402_payments
24
+ ADD COLUMN IF NOT EXISTS credited_at TIMESTAMPTZ
25
+ `.execute(db);
26
+ await sql`
27
+ UPDATE x402_payments
28
+ SET credited_at = updated_at
29
+ WHERE kind = 'deposit' AND state <> 'pending' AND credited_at IS NULL
30
+ `.execute(db);
31
+ });
32
+ }
33
+
34
+ export async function down(db: Kysely<unknown>): Promise<void> {
35
+ await onControlPlane(async () => {
36
+ await sql`
37
+ ALTER TABLE x402_payments
38
+ DROP COLUMN IF EXISTS credited_at
39
+ `.execute(db);
40
+ });
41
+ }
@@ -0,0 +1,28 @@
1
+ import { type Kysely, sql } from "kysely";
2
+ import { onControlPlane } from "../src/db/migration-role.ts";
3
+
4
+ // f071 Stage 2a: per-subgraph opt-in for the sandboxed (Bun Worker) handler
5
+ // execution path. Default FALSE everywhere — the global env flag
6
+ // (SUBGRAPH_SANDBOX_WORKERS) is the capability switch, this column is the
7
+ // per-tenant rollout switch; both must be true for a subgraph to route
8
+ // through the worker path (see runtime/sandbox/flag.ts). No subgraph is
9
+ // opted in by this migration — that's a later, separate cutover decision
10
+ // (Stage 2c). Control-plane (TARGET) — the subgraphs control-plane table.
11
+ export async function up(db: Kysely<unknown>): Promise<void> {
12
+ await sql`SET lock_timeout = '30s'`.execute(db);
13
+ await onControlPlane(async () => {
14
+ await sql`
15
+ ALTER TABLE subgraphs
16
+ ADD COLUMN IF NOT EXISTS sandbox_workers BOOLEAN NOT NULL DEFAULT FALSE
17
+ `.execute(db);
18
+ });
19
+ }
20
+
21
+ export async function down(db: Kysely<unknown>): Promise<void> {
22
+ await onControlPlane(async () => {
23
+ await sql`
24
+ ALTER TABLE subgraphs
25
+ DROP COLUMN IF EXISTS sandbox_workers
26
+ `.execute(db);
27
+ });
28
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secondlayer/shared",
3
- "version": "6.41.1",
3
+ "version": "6.41.3",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -167,7 +167,7 @@
167
167
  "prepublishOnly": "bun run build"
168
168
  },
169
169
  "dependencies": {
170
- "@secondlayer/stacks": "^2.10.0",
170
+ "@secondlayer/stacks": "^2.11.0",
171
171
  "kysely": "0.28.15",
172
172
  "kysely-postgres-js": "3.0.0",
173
173
  "postgres": "^3.4.6",