@secondlayer/shared 7.11.2 → 9.0.0

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.
Files changed (60) hide show
  1. package/dist/src/archive/range-digest.d.ts +16 -169
  2. package/dist/src/archive/semantic-digest-builder.d.ts +16 -169
  3. package/dist/src/archive/status.js +11 -3
  4. package/dist/src/archive/status.js.map +3 -3
  5. package/dist/src/coverage/index.d.ts +15 -169
  6. package/dist/src/crypto/secrets.js +22 -3
  7. package/dist/src/crypto/secrets.js.map +3 -3
  8. package/dist/src/db/index.d.ts +18 -211
  9. package/dist/src/db/index.js +23 -16
  10. package/dist/src/db/index.js.map +4 -4
  11. package/dist/src/db/queries/chain-reorgs.d.ts +16 -169
  12. package/dist/src/db/queries/chain-reorgs.js +23 -16
  13. package/dist/src/db/queries/chain-reorgs.js.map +4 -4
  14. package/dist/src/db/queries/contracts.d.ts +16 -169
  15. package/dist/src/db/queries/instance.d.ts +16 -169
  16. package/dist/src/db/queries/integrity.d.ts +16 -169
  17. package/dist/src/db/queries/subgraph-gaps.d.ts +16 -169
  18. package/dist/src/db/queries/subgraph-operations.d.ts +17 -170
  19. package/dist/src/db/queries/subgraph-operations.js +1 -15
  20. package/dist/src/db/queries/subgraph-operations.js.map +3 -3
  21. package/dist/src/db/queries/subgraphs.d.ts +17 -191
  22. package/dist/src/db/queries/subgraphs.js +30 -1068
  23. package/dist/src/db/queries/subgraphs.js.map +5 -12
  24. package/dist/src/db/queries/subscriptions.d.ts +16 -169
  25. package/dist/src/db/queries/subscriptions.js +22 -3
  26. package/dist/src/db/queries/subscriptions.js.map +3 -3
  27. package/dist/src/db/queries/sync-scope.d.ts +1006 -0
  28. package/dist/src/db/queries/sync-scope.js +116 -0
  29. package/dist/src/db/queries/sync-scope.js.map +10 -0
  30. package/dist/src/db/schema.d.ts +17 -198
  31. package/dist/src/errors.d.ts +1 -22
  32. package/dist/src/errors.js +2 -4
  33. package/dist/src/errors.js.map +3 -3
  34. package/dist/src/index.d.ts +22 -256
  35. package/dist/src/index.js +24 -20
  36. package/dist/src/index.js.map +6 -6
  37. package/dist/src/mode.d.ts +16 -2
  38. package/dist/src/mode.js +25 -4
  39. package/dist/src/mode.js.map +3 -3
  40. package/dist/src/node/local-client.d.ts +16 -169
  41. package/dist/src/runtime/index.d.ts +137 -18
  42. package/dist/src/runtime/index.js +261 -41
  43. package/dist/src/runtime/index.js.map +9 -7
  44. package/dist/src/schemas/index.d.ts +5 -25
  45. package/dist/src/schemas/index.js +1 -2
  46. package/dist/src/schemas/index.js.map +3 -3
  47. package/dist/src/schemas/subgraphs.d.ts +5 -25
  48. package/dist/src/schemas/subgraphs.js +1 -2
  49. package/dist/src/schemas/subgraphs.js.map +3 -3
  50. package/dist/src/streams-rows/index.d.ts +399 -0
  51. package/dist/src/streams-rows/index.js +336 -0
  52. package/dist/src/streams-rows/index.js.map +17 -0
  53. package/dist/src/subgraphs/spec.d.ts +0 -9
  54. package/migrations/0118_drop_retired_control_tables.ts +53 -0
  55. package/migrations/0119_drop_accounts_plan.ts +29 -0
  56. package/migrations/0120_sync_scopes.ts +42 -0
  57. package/package.json +10 -6
  58. package/dist/src/x402.d.ts +0 -47
  59. package/dist/src/x402.js +0 -79
  60. package/dist/src/x402.js.map +0 -10
@@ -0,0 +1,116 @@
1
+ import { createRequire } from "node:module";
2
+ var __defProp = Object.defineProperty;
3
+ var __returnValue = (v) => v;
4
+ function __exportSetter(name, newValue) {
5
+ this[name] = __returnValue.bind(null, newValue);
6
+ }
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, {
10
+ get: all[name],
11
+ enumerable: true,
12
+ configurable: true,
13
+ set: __exportSetter.bind(all, name)
14
+ });
15
+ };
16
+
17
+ // src/db/queries/sync-scope.ts
18
+ var SYNC_START_HEIGHT_ENV = "SECONDLAYER_SYNC_START_HEIGHT";
19
+
20
+ class InvalidSyncStartHeightError extends Error {
21
+ value;
22
+ name = "InvalidSyncStartHeightError";
23
+ constructor(value) {
24
+ super(`${SYNC_START_HEIGHT_ENV} must be a non-negative integer (got ${value})`);
25
+ this.value = value;
26
+ }
27
+ }
28
+ function syncStartHeightFromEnv(env = process.env) {
29
+ const raw = env[SYNC_START_HEIGHT_ENV];
30
+ if (raw === undefined || raw.trim() === "")
31
+ return null;
32
+ const height = Number(raw.trim());
33
+ if (!Number.isInteger(height) || height < 0) {
34
+ throw new InvalidSyncStartHeightError(raw);
35
+ }
36
+ return height;
37
+ }
38
+ function toScope(row) {
39
+ return {
40
+ network: row.network,
41
+ start_height: Number(row.start_height),
42
+ target_height: row.target_height === null ? null : Number(row.target_height),
43
+ bootstrap: {
44
+ source: row.bootstrap_source,
45
+ manifest_digest: row.bootstrap_manifest_digest,
46
+ genesis_hash: row.genesis_hash
47
+ }
48
+ };
49
+ }
50
+ async function getSyncScope(db, network) {
51
+ const row = await db.selectFrom("sync_scopes").select([
52
+ "network",
53
+ "start_height",
54
+ "target_height",
55
+ "bootstrap_source",
56
+ "bootstrap_manifest_digest",
57
+ "genesis_hash"
58
+ ]).where("network", "=", network).executeTakeFirst();
59
+ return row ? toScope(row) : null;
60
+ }
61
+ async function upsertSyncScope(db, scope) {
62
+ const row = await db.insertInto("sync_scopes").values({
63
+ network: scope.network,
64
+ start_height: scope.start_height,
65
+ target_height: scope.target_height,
66
+ bootstrap_source: scope.bootstrap.source,
67
+ bootstrap_manifest_digest: scope.bootstrap.manifest_digest,
68
+ genesis_hash: scope.bootstrap.genesis_hash
69
+ }).onConflict((oc) => oc.column("network").doUpdateSet({
70
+ start_height: scope.start_height,
71
+ target_height: scope.target_height,
72
+ bootstrap_source: scope.bootstrap.source,
73
+ bootstrap_manifest_digest: scope.bootstrap.manifest_digest,
74
+ genesis_hash: scope.bootstrap.genesis_hash,
75
+ updated_at: new Date
76
+ })).returning([
77
+ "network",
78
+ "start_height",
79
+ "target_height",
80
+ "bootstrap_source",
81
+ "bootstrap_manifest_digest",
82
+ "genesis_hash"
83
+ ]).executeTakeFirstOrThrow();
84
+ return toScope(row);
85
+ }
86
+ async function resolveSyncScope(db, network) {
87
+ const persisted = await getSyncScope(db, network);
88
+ if (persisted)
89
+ return persisted;
90
+ const declaredStart = syncStartHeightFromEnv();
91
+ const lowest = await db.selectFrom("blocks").select(({ fn }) => fn.min("height").as("min")).where("canonical", "=", true).executeTakeFirst();
92
+ const lowestStored = lowest?.min === null || lowest?.min === undefined ? null : Number(lowest.min);
93
+ const startHeight = declaredStart ?? lowestStored ?? 0;
94
+ const genesis = startHeight === 0 ? await db.selectFrom("blocks").select("hash").where("canonical", "=", true).where("height", "=", 0).executeTakeFirst() : undefined;
95
+ return {
96
+ network,
97
+ start_height: startHeight,
98
+ target_height: null,
99
+ bootstrap: {
100
+ source: startHeight === 0 ? "genesis" : "import",
101
+ manifest_digest: null,
102
+ genesis_hash: genesis?.hash ?? null
103
+ }
104
+ };
105
+ }
106
+ export {
107
+ upsertSyncScope,
108
+ syncStartHeightFromEnv,
109
+ resolveSyncScope,
110
+ getSyncScope,
111
+ SYNC_START_HEIGHT_ENV,
112
+ InvalidSyncStartHeightError
113
+ };
114
+
115
+ //# debugId=A8458ACA2A49456264756E2164756E21
116
+ //# sourceMappingURL=sync-scope.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/db/queries/sync-scope.ts"],
4
+ "sourcesContent": [
5
+ "import type { Kysely } from \"kysely\";\nimport type { BootstrapSource, SyncScope } from \"../../coverage/evaluate.ts\";\nimport type { Database } from \"../types.ts\";\n\n/**\n * The instance's declared sync scope.\n *\n * An instance that starts at height N is not an instance missing the first N\n * blocks — but nothing in the schema said so, so every consumer had to guess\n * from `MIN(height)`. `sync_scopes` records the declaration; this module is the\n * only place that reads it, and it always answers in the `SyncScope` shape the\n * coverage evaluator consumes.\n *\n * `resolveSyncScope` never fails on an instance that predates the table: with\n * no row it derives a scope from what the database already shows, so an\n * existing install keeps working without a backfill dance.\n */\n\n/**\n * Declares a forward-only instance: history below this height is deliberately\n * absent, not lost. Read only when no `sync_scopes` row exists — a recorded\n * scope always wins, because it is the one an operator committed to.\n */\nexport const SYNC_START_HEIGHT_ENV = \"SECONDLAYER_SYNC_START_HEIGHT\";\n\nexport class InvalidSyncStartHeightError extends Error {\n\treadonly name = \"InvalidSyncStartHeightError\";\n\tconstructor(readonly value: string) {\n\t\tsuper(\n\t\t\t`${SYNC_START_HEIGHT_ENV} must be a non-negative integer (got ${value})`,\n\t\t);\n\t}\n}\n\n/**\n * Throws rather than ignoring a malformed value: a typo'd start height that\n * silently falls back to genesis would report a real forward-only instance as\n * an 8M-block gap, which is the exact confusion this table exists to end.\n */\nexport function syncStartHeightFromEnv(\n\tenv: NodeJS.ProcessEnv = process.env,\n): number | null {\n\tconst raw = env[SYNC_START_HEIGHT_ENV];\n\tif (raw === undefined || raw.trim() === \"\") return null;\n\tconst height = Number(raw.trim());\n\tif (!Number.isInteger(height) || height < 0) {\n\t\tthrow new InvalidSyncStartHeightError(raw);\n\t}\n\treturn height;\n}\n\nfunction toScope(row: {\n\tnetwork: string;\n\tstart_height: number | string;\n\ttarget_height: number | string | null;\n\tbootstrap_source: BootstrapSource;\n\tbootstrap_manifest_digest: string | null;\n\tgenesis_hash: string | null;\n}): SyncScope {\n\treturn {\n\t\tnetwork: row.network,\n\t\tstart_height: Number(row.start_height),\n\t\ttarget_height:\n\t\t\trow.target_height === null ? null : Number(row.target_height),\n\t\tbootstrap: {\n\t\t\tsource: row.bootstrap_source,\n\t\t\tmanifest_digest: row.bootstrap_manifest_digest,\n\t\t\tgenesis_hash: row.genesis_hash,\n\t\t},\n\t};\n}\n\nexport async function getSyncScope(\n\tdb: Kysely<Database>,\n\tnetwork: string,\n): Promise<SyncScope | null> {\n\tconst row = await db\n\t\t.selectFrom(\"sync_scopes\")\n\t\t.select([\n\t\t\t\"network\",\n\t\t\t\"start_height\",\n\t\t\t\"target_height\",\n\t\t\t\"bootstrap_source\",\n\t\t\t\"bootstrap_manifest_digest\",\n\t\t\t\"genesis_hash\",\n\t\t])\n\t\t.where(\"network\", \"=\", network)\n\t\t.executeTakeFirst();\n\treturn row ? toScope(row) : null;\n}\n\n/**\n * Record (or restate) the scope for a network. Bootstrap and re-bootstrap are\n * the writers; the upsert is idempotent so re-running a restore over the same\n * archive does not fork the declaration.\n */\nexport async function upsertSyncScope(\n\tdb: Kysely<Database>,\n\tscope: SyncScope,\n): Promise<SyncScope> {\n\tconst row = await db\n\t\t.insertInto(\"sync_scopes\")\n\t\t.values({\n\t\t\tnetwork: scope.network,\n\t\t\tstart_height: scope.start_height,\n\t\t\ttarget_height: scope.target_height,\n\t\t\tbootstrap_source: scope.bootstrap.source,\n\t\t\tbootstrap_manifest_digest: scope.bootstrap.manifest_digest,\n\t\t\tgenesis_hash: scope.bootstrap.genesis_hash,\n\t\t})\n\t\t.onConflict((oc) =>\n\t\t\toc.column(\"network\").doUpdateSet({\n\t\t\t\tstart_height: scope.start_height,\n\t\t\t\ttarget_height: scope.target_height,\n\t\t\t\tbootstrap_source: scope.bootstrap.source,\n\t\t\t\tbootstrap_manifest_digest: scope.bootstrap.manifest_digest,\n\t\t\t\tgenesis_hash: scope.bootstrap.genesis_hash,\n\t\t\t\tupdated_at: new Date(),\n\t\t\t}),\n\t\t)\n\t\t.returning([\n\t\t\t\"network\",\n\t\t\t\"start_height\",\n\t\t\t\"target_height\",\n\t\t\t\"bootstrap_source\",\n\t\t\t\"bootstrap_manifest_digest\",\n\t\t\t\"genesis_hash\",\n\t\t])\n\t\t.executeTakeFirstOrThrow();\n\treturn toScope(row);\n}\n\n/**\n * The persisted scope, or one derived from the database when none was ever\n * recorded.\n *\n * The derivation is deliberately conservative: it claims only what the data\n * already shows (the lowest canonical block, the genesis hash if genesis is\n * present) and never invents provenance — an instance whose history starts\n * above genesis with no recorded bootstrap is an `import`, not an archive\n * restore we can vouch for.\n */\nexport async function resolveSyncScope(\n\tdb: Kysely<Database>,\n\tnetwork: string,\n): Promise<SyncScope> {\n\tconst persisted = await getSyncScope(db, network);\n\tif (persisted) return persisted;\n\n\tconst declaredStart = syncStartHeightFromEnv();\n\tconst lowest = await db\n\t\t.selectFrom(\"blocks\")\n\t\t.select(({ fn }) => fn.min(\"height\").as(\"min\"))\n\t\t.where(\"canonical\", \"=\", true)\n\t\t.executeTakeFirst();\n\tconst lowestStored =\n\t\tlowest?.min === null || lowest?.min === undefined\n\t\t\t? null\n\t\t\t: Number(lowest.min);\n\tconst startHeight = declaredStart ?? lowestStored ?? 0;\n\n\tconst genesis =\n\t\tstartHeight === 0\n\t\t\t? await db\n\t\t\t\t\t.selectFrom(\"blocks\")\n\t\t\t\t\t.select(\"hash\")\n\t\t\t\t\t.where(\"canonical\", \"=\", true)\n\t\t\t\t\t.where(\"height\", \"=\", 0)\n\t\t\t\t\t.executeTakeFirst()\n\t\t\t: undefined;\n\n\treturn {\n\t\tnetwork,\n\t\tstart_height: startHeight,\n\t\ttarget_height: null,\n\t\tbootstrap: {\n\t\t\tsource: startHeight === 0 ? \"genesis\" : \"import\",\n\t\t\tmanifest_digest: null,\n\t\t\tgenesis_hash: genesis?.hash ?? null,\n\t\t},\n\t};\n}\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;;;;;;AAuBO,IAAM,wBAAwB;AAAA;AAE9B,MAAM,oCAAoC,MAAM;AAAA,EAEjC;AAAA,EADZ,OAAO;AAAA,EAChB,WAAW,CAAU,OAAe;AAAA,IACnC,MACC,GAAG,6DAA6D,QACjE;AAAA,IAHoB;AAAA;AAKtB;AAOO,SAAS,sBAAsB,CACrC,MAAyB,QAAQ,KACjB;AAAA,EAChB,MAAM,MAAM,IAAI;AAAA,EAChB,IAAI,QAAQ,aAAa,IAAI,KAAK,MAAM;AAAA,IAAI,OAAO;AAAA,EACnD,MAAM,SAAS,OAAO,IAAI,KAAK,CAAC;AAAA,EAChC,IAAI,CAAC,OAAO,UAAU,MAAM,KAAK,SAAS,GAAG;AAAA,IAC5C,MAAM,IAAI,4BAA4B,GAAG;AAA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AAA,EAC1B,OAAO,QAAQ,GAAG;AAAA;AAanB,eAAsB,gBAAgB,CACrC,IACA,SACqB;AAAA,EACrB,MAAM,YAAY,MAAM,aAAa,IAAI,OAAO;AAAA,EAChD,IAAI;AAAA,IAAW,OAAO;AAAA,EAEtB,MAAM,gBAAgB,uBAAuB;AAAA,EAC7C,MAAM,SAAS,MAAM,GACnB,WAAW,QAAQ,EACnB,OAAO,GAAG,SAAS,GAAG,IAAI,QAAQ,EAAE,GAAG,KAAK,CAAC,EAC7C,MAAM,aAAa,KAAK,IAAI,EAC5B,iBAAiB;AAAA,EACnB,MAAM,eACL,QAAQ,QAAQ,QAAQ,QAAQ,QAAQ,YACrC,OACA,OAAO,OAAO,GAAG;AAAA,EACrB,MAAM,cAAc,iBAAiB,gBAAgB;AAAA,EAErD,MAAM,UACL,gBAAgB,IACb,MAAM,GACL,WAAW,QAAQ,EACnB,OAAO,MAAM,EACb,MAAM,aAAa,KAAK,IAAI,EAC5B,MAAM,UAAU,KAAK,CAAC,EACtB,iBAAiB,IAClB;AAAA,EAEJ,OAAO;AAAA,IACN;AAAA,IACA,cAAc;AAAA,IACd,eAAe;AAAA,IACf,WAAW;AAAA,MACV,QAAQ,gBAAgB,IAAI,YAAY;AAAA,MACxC,iBAAiB;AAAA,MACjB,cAAc,SAAS,QAAQ;AAAA,IAChC;AAAA,EACD;AAAA;",
8
+ "debugId": "A8458ACA2A49456264756E2164756E21",
9
+ "names": []
10
+ }
@@ -17,6 +17,7 @@ declare const FAILURE_CLASSES: readonly ["omission", "version", "digest_mismatch
17
17
  type FailureClass = (typeof FAILURE_CLASSES)[number];
18
18
  declare const RETRY_STATES: readonly ["open", "retrying", "halted", "resolved"];
19
19
  type RetryState = (typeof RETRY_STATES)[number];
20
+ type BootstrapSource = "archive" | "genesis" | "import";
20
21
  interface BlocksTable {
21
22
  height: number;
22
23
  hash: string;
@@ -222,11 +223,9 @@ interface AccountsTable {
222
223
  ghost: Generated<boolean>;
223
224
  /** Stacks principal owning a wallet-ghost account (x402-paid deploys). */
224
225
  wallet_principal: string | null;
225
- plan: Generated<string>;
226
226
  display_name: string | null;
227
227
  bio: string | null;
228
228
  avatar_url: string | null;
229
- slug: string | null;
230
229
  stripe_customer_id: string | null;
231
230
  /** Opt-out toggle for the subgraph reindex-completion email. Defaults true. */
232
231
  notify_reindex_complete: Generated<boolean>;
@@ -243,19 +242,6 @@ interface SessionsTable {
243
242
  last_used_at: Date | null;
244
243
  created_at: Generated<Date>;
245
244
  }
246
- /**
247
- * One-time claim tokens for ghost accounts. The raw token only ever appears in
248
- * the claim URL returned at mint time; we store its sha256. A used token marks
249
- * the account as claimed (or merged into an existing account).
250
- */
251
- interface ClaimTokensTable {
252
- id: Generated<string>;
253
- account_id: string;
254
- token_hash: string;
255
- created_at: Generated<Date>;
256
- expires_at: Date;
257
- used_at: Date | null;
258
- }
259
245
  interface MagicLinksTable {
260
246
  id: Generated<string>;
261
247
  email: string;
@@ -266,47 +252,6 @@ interface MagicLinksTable {
266
252
  failed_attempts: Generated<number>;
267
253
  created_at: Generated<Date>;
268
254
  }
269
- interface UsageDailyTable {
270
- account_id: string;
271
- tenant_id: string | null;
272
- date: string;
273
- api_requests: Generated<number>;
274
- deliveries: Generated<number>;
275
- streams_events_returned: Generated<number>;
276
- index_decoded_events_returned: Generated<number>;
277
- }
278
- interface UsageSnapshotsTable {
279
- id: Generated<string>;
280
- account_id: string;
281
- measured_at: Generated<Date>;
282
- storage_bytes: Generated<number>;
283
- }
284
- interface AccountInsightsTable {
285
- id: Generated<string>;
286
- account_id: string;
287
- category: string;
288
- insight_type: string;
289
- resource_id: string | null;
290
- severity: string;
291
- title: string;
292
- body: string;
293
- data: unknown;
294
- dismissed_at: Date | null;
295
- expires_at: Date | null;
296
- created_at: Generated<Date>;
297
- }
298
- interface AccountAgentRunsTable {
299
- id: Generated<string>;
300
- account_id: string;
301
- started_at: Generated<Date>;
302
- completed_at: Date | null;
303
- status: Generated<string>;
304
- input_tokens: Generated<number>;
305
- output_tokens: Generated<number>;
306
- cost_usd: Generated<number>;
307
- insights_created: Generated<number>;
308
- error: string | null;
309
- }
310
255
  interface SubgraphProcessingStatsTable {
311
256
  id: Generated<string>;
312
257
  subgraph_name: string;
@@ -339,41 +284,6 @@ interface SubgraphHealthSnapshotsTable {
339
284
  last_processed_block: number | null;
340
285
  captured_at: Generated<Date>;
341
286
  }
342
- interface SubgraphUsageDailyTable {
343
- subgraph_id: string;
344
- date: string;
345
- query_count: Generated<number>;
346
- }
347
- interface ProjectsTable {
348
- id: Generated<string>;
349
- name: string;
350
- slug: string;
351
- account_id: string;
352
- settings: Generated<Record<string, unknown>>;
353
- network: Generated<string>;
354
- node_rpc: string | null;
355
- created_at: Generated<Date>;
356
- updated_at: Generated<Date>;
357
- }
358
- interface TeamMembersTable {
359
- id: Generated<string>;
360
- project_id: string;
361
- account_id: string;
362
- role: Generated<string>;
363
- invited_by: string | null;
364
- created_at: Generated<Date>;
365
- }
366
- interface TeamInvitationsTable {
367
- id: Generated<string>;
368
- project_id: string;
369
- email: string;
370
- role: Generated<string>;
371
- token: string;
372
- invited_by: string | null;
373
- expires_at: Date;
374
- accepted_at: Date | null;
375
- created_at: Generated<Date>;
376
- }
377
287
  interface ProcessedStripeEventsTable {
378
288
  event_id: string;
379
289
  event_type: string;
@@ -810,6 +720,20 @@ interface StageFailuresTable {
810
720
  resolved_at: Date | null;
811
721
  retain_until: Generated<Date>;
812
722
  }
723
+ /**
724
+ * The instance's declared scope — one row per network. `start_height` is what
725
+ * makes missing history below it deliberate rather than a gap.
726
+ */
727
+ interface SyncScopesTable {
728
+ network: string;
729
+ start_height: number;
730
+ target_height: number | null;
731
+ bootstrap_source: BootstrapSource;
732
+ bootstrap_manifest_digest: string | null;
733
+ genesis_hash: string | null;
734
+ created_at: Generated<Date>;
735
+ updated_at: Generated<Date>;
736
+ }
813
737
  interface Database {
814
738
  blocks: BlocksTable;
815
739
  transactions: TransactionsTable;
@@ -826,27 +750,14 @@ interface Database {
826
750
  accounts: AccountsTable;
827
751
  sessions: SessionsTable;
828
752
  magic_links: MagicLinksTable;
829
- claim_tokens: ClaimTokensTable;
830
- usage_daily: UsageDailyTable;
831
- usage_snapshots: UsageSnapshotsTable;
832
- account_insights: AccountInsightsTable;
833
- account_agent_runs: AccountAgentRunsTable;
834
753
  subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
835
754
  subgraph_processing_stats: SubgraphProcessingStatsTable;
836
755
  subgraph_table_snapshots: SubgraphTableSnapshotsTable;
837
756
  subgraph_gaps: SubgraphGapsTable;
838
757
  subgraph_operations: SubgraphOperationsTable;
839
- subgraph_usage_daily: SubgraphUsageDailyTable;
840
- projects: ProjectsTable;
841
- team_members: TeamMembersTable;
842
- team_invitations: TeamInvitationsTable;
843
758
  processed_stripe_events: ProcessedStripeEventsTable;
844
- tenants: TenantsTable;
845
- tenant_usage_monthly: TenantUsageMonthlyTable;
846
- tenant_compute_addons: TenantComputeAddonsTable;
847
759
  account_spend_caps: AccountSpendCapsTable;
848
760
  account_credits: AccountCreditsTable;
849
- provisioning_audit_log: ProvisioningAuditLogTable;
850
761
  subscriptions: SubscriptionsTable;
851
762
  subscription_outbox: SubscriptionOutboxTable;
852
763
  subscription_deliveries: SubscriptionDeliveriesTable;
@@ -875,6 +786,7 @@ interface Database {
875
786
  chain_read_cache: ChainReadCacheTable;
876
787
  pending_fork_blocks: PendingForkBlocksTable;
877
788
  observer_journal: ObserverJournalTable;
789
+ sync_scopes: SyncScopesTable;
878
790
  stage_registry: StageRegistryTable;
879
791
  stage_runs: StageRunsTable;
880
792
  stage_block_receipts: StageBlockReceiptsTable;
@@ -921,66 +833,6 @@ interface X402PaymentsTable {
921
833
  * reconciler's heal path can never double-credit them. */
922
834
  credited_at: Generated<Date> | null;
923
835
  }
924
- type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
925
- interface TenantsTable {
926
- id: Generated<string>;
927
- account_id: string;
928
- slug: string;
929
- status: ColumnType<TenantStatus, TenantStatus | undefined, TenantStatus>;
930
- plan: string;
931
- cpus: ColumnType<number, number | string, number | string>;
932
- memory_mb: number;
933
- storage_limit_mb: number;
934
- storage_used_mb: number | null;
935
- pg_container_id: string | null;
936
- api_container_id: string | null;
937
- processor_container_id: string | null;
938
- target_database_url_enc: Buffer;
939
- tenant_jwt_secret_enc: Buffer;
940
- anon_key_enc: Buffer;
941
- service_key_enc: Buffer;
942
- api_url_internal: string;
943
- api_url_public: string;
944
- suspended_at: Date | null;
945
- last_health_check_at: Date | null;
946
- last_active_at: Generated<Date>;
947
- service_gen: Generated<number>;
948
- anon_gen: Generated<number>;
949
- project_id: string | null;
950
- created_at: Generated<Date>;
951
- updated_at: Generated<Date>;
952
- }
953
- type Tenant = Selectable<TenantsTable>;
954
- type InsertTenant = Insertable<TenantsTable>;
955
- type UpdateTenant = Updateable<TenantsTable>;
956
- interface TenantUsageMonthlyTable {
957
- id: Generated<string>;
958
- tenant_id: string;
959
- period_month: Date;
960
- storage_peak_mb: Generated<number>;
961
- storage_avg_mb: Generated<number>;
962
- storage_last_mb: Generated<number>;
963
- measurements: Generated<number>;
964
- first_at: Generated<Date>;
965
- last_at: Generated<Date>;
966
- }
967
- type TenantUsageMonthly = Selectable<TenantUsageMonthlyTable>;
968
- type InsertTenantUsageMonthly = Insertable<TenantUsageMonthlyTable>;
969
- type UpdateTenantUsageMonthly = Updateable<TenantUsageMonthlyTable>;
970
- interface TenantComputeAddonsTable {
971
- id: Generated<string>;
972
- tenant_id: string;
973
- memory_mb_delta: Generated<number>;
974
- cpu_delta: Generated<number | string>;
975
- storage_mb_delta: Generated<number>;
976
- effective_from: Generated<Date>;
977
- effective_until: Date | null;
978
- stripe_subscription_item_id: string | null;
979
- created_at: Generated<Date>;
980
- }
981
- type TenantComputeAddon = Selectable<TenantComputeAddonsTable>;
982
- type InsertTenantComputeAddon = Insertable<TenantComputeAddonsTable>;
983
- type UpdateTenantComputeAddon = Updateable<TenantComputeAddonsTable>;
984
836
  interface AccountSpendCapsTable {
985
837
  account_id: string;
986
838
  monthly_cap_cents: number | null;
@@ -1010,22 +862,6 @@ interface AccountCreditsTable {
1010
862
  type AccountCredits = Selectable<AccountCreditsTable>;
1011
863
  type InsertAccountCredits = Insertable<AccountCreditsTable>;
1012
864
  type UpdateAccountCredits = Updateable<AccountCreditsTable>;
1013
- type ProvisioningAuditEvent = "provision.start" | "provision.success" | "provision.failure" | "suspend" | "resume" | "resize" | "keys.rotate" | "bastion.key.upload" | "bastion.key.revoke" | "teardown";
1014
- type ProvisioningAuditStatus = "ok" | "error";
1015
- interface ProvisioningAuditLogTable {
1016
- id: Generated<string>;
1017
- tenant_id: string | null;
1018
- tenant_slug: string | null;
1019
- account_id: string | null;
1020
- actor: string;
1021
- event: ProvisioningAuditEvent;
1022
- status: ProvisioningAuditStatus;
1023
- detail: unknown | null;
1024
- error: string | null;
1025
- created_at: Generated<Date>;
1026
- }
1027
- type ProvisioningAuditLog = Selectable<ProvisioningAuditLogTable>;
1028
- type InsertProvisioningAuditLog = Insertable<ProvisioningAuditLogTable>;
1029
865
  type Block = Selectable<BlocksTable>;
1030
866
  type InsertBlock = Insertable<BlocksTable>;
1031
867
  type UpdateBlock = Updateable<BlocksTable>;
@@ -1056,29 +892,12 @@ type Account = Selectable<AccountsTable>;
1056
892
  type InsertAccount = Insertable<AccountsTable>;
1057
893
  type MagicLink = Selectable<MagicLinksTable>;
1058
894
  type InsertMagicLink = Insertable<MagicLinksTable>;
1059
- type ClaimToken = Selectable<ClaimTokensTable>;
1060
- type InsertClaimToken = Insertable<ClaimTokensTable>;
1061
895
  type Session = Selectable<SessionsTable>;
1062
896
  type InsertSession = Insertable<SessionsTable>;
1063
- type UsageDaily = Selectable<UsageDailyTable>;
1064
- type UsageSnapshot = Selectable<UsageSnapshotsTable>;
1065
- type AccountInsight = Selectable<AccountInsightsTable>;
1066
- type InsertAccountInsight = Insertable<AccountInsightsTable>;
1067
- type AccountAgentRun = Selectable<AccountAgentRunsTable>;
1068
- type InsertAccountAgentRun = Insertable<AccountAgentRunsTable>;
1069
897
  type SubgraphHealthSnapshot = Selectable<SubgraphHealthSnapshotsTable>;
1070
898
  type InsertSubgraphHealthSnapshot = Insertable<SubgraphHealthSnapshotsTable>;
1071
899
  type SubgraphGap = Selectable<SubgraphGapsTable>;
1072
900
  type InsertSubgraphGap = Insertable<SubgraphGapsTable>;
1073
- type SubgraphUsageDaily = Selectable<SubgraphUsageDailyTable>;
1074
- type InsertSubgraphUsageDaily = Insertable<SubgraphUsageDailyTable>;
1075
- type Project = Selectable<ProjectsTable>;
1076
- type InsertProject = Insertable<ProjectsTable>;
1077
- type UpdateProject = Updateable<ProjectsTable>;
1078
- type TeamMember = Selectable<TeamMembersTable>;
1079
- type InsertTeamMember = Insertable<TeamMembersTable>;
1080
- type TeamInvitation = Selectable<TeamInvitationsTable>;
1081
- type InsertTeamInvitation = Insertable<TeamInvitationsTable>;
1082
901
  type SubscriptionStatus = "active" | "paused" | "error";
1083
902
  /** Polymorphic subscription mode: `subgraph` reacts to processed table rows;
1084
903
  * `chain` reacts to raw chain events matched directly off the Index/Streams
@@ -1176,4 +995,4 @@ interface TriggerEvaluatorStateTable {
1176
995
  updated_at: Generated<Date>;
1177
996
  }
1178
997
  type TriggerEvaluatorState = Selectable<TriggerEvaluatorStateTable>;
1179
- export { X402PaymentsTable, X402BalancesTable, UsageSnapshotsTable, UsageSnapshot, UsageDailyTable, UsageDaily, UpdateTransaction, UpdateTenantUsageMonthly, UpdateTenantComputeAddon, UpdateTenant, UpdateSubscriptionOutbox, UpdateSubscription, UpdateSubgraphOperation, UpdateSubgraph, UpdateProject, UpdateIndexProgress, UpdateEvent, UpdateContract, UpdateBlock, UpdateApiKey, UpdateAccountSpendCap, UpdateAccountCredits, TriggerEvaluatorStateTable, TriggerEvaluatorState, TransactionsTable, TransactionsArchiveTable, Transaction, TenantsTable, TenantUsageMonthlyTable, TenantUsageMonthly, TenantStatus, TenantComputeAddonsTable, TenantComputeAddon, Tenant, TeamMembersTable, TeamMember, TeamInvitationsTable, TeamInvitation, SubscriptionsTable, SubscriptionStatus, SubscriptionRuntime, SubscriptionOutboxTable, SubscriptionOutbox, SubscriptionKind, SubscriptionFormat, SubscriptionDelivery, SubscriptionDeliveriesTable, Subscription, SubgraphsTable, SubgraphUsageDailyTable, SubgraphUsageDaily, SubgraphTableSnapshotsTable, SubgraphProcessingStatsTable, SubgraphOperationsTable, SubgraphOperationStatus, SubgraphOperationKind, SubgraphOperation, SubgraphHealthSnapshotsTable, SubgraphHealthSnapshot, SubgraphGapsTable, SubgraphGap, Subgraph, StageRunsTable, StageRegistryTable, StageKind, StageFailuresTable, StageBlockReceiptsTable, SessionsTable, Session, ServiceHeartbeatsTable, SbtcTokenEventsTable, SbtcTokenEventType, SbtcSupplySnapshotsTable, SbtcSettlementsTable, SbtcEventsTable, SbtcEventTopic, RunStatus, RetryState, RepairMode, ProvisioningAuditStatus, ProvisioningAuditLogTable, ProvisioningAuditLog, ProvisioningAuditEvent, ProjectsTable, Project, ProcessedStripeEventsTable, Pox5EventsTable, Pox5EventTopic, Pox4SignersDailyTable, Pox4FunctionName, Pox4CyclesDailyTable, Pox4CallsTable, PendingForkBlocksTable, OutboxStatus, ObserverJournalTable, ObserverJournalStatus, NativeClock, MempoolTransactionsTable, MempoolTransaction, MagicLinksTable, MagicLink, InstancesTable, InsertTransaction, InsertTenantUsageMonthly, InsertTenantComputeAddon, InsertTenant, InsertTeamMember, InsertTeamInvitation, InsertSubscriptionOutbox, InsertSubscriptionDelivery, InsertSubscription, InsertSubgraphUsageDaily, InsertSubgraphOperation, InsertSubgraphHealthSnapshot, InsertSubgraphGap, InsertSubgraph, InsertSession, InsertProvisioningAuditLog, InsertProject, InsertMempoolTransaction, InsertMagicLink, InsertIndexProgress, InsertEvent, InsertContract, InsertClaimToken, InsertBlock, InsertApiKey, InsertAccountSpendCap, InsertAccountInsight, InsertAccountCredits, InsertAccountAgentRun, InsertAccount, IndexProgressTable, IndexProgress, FailureUnit, FailureClass, EventsTable, EventsArchiveTable, Event, DecoderCheckpointsTable, DecodedEventsTable, DeadLetterEventsTable, Database, CoverageSegmentsTable, ContractsTable, Contract, ClaimTokensTable, ClaimToken, ChainReorgsTable, ChainReadCacheTable, BurnBlockRewardsTable, BurnBlockRewardSlotsTable, BnsNamespacesTable, BnsNamespaceEventsTable, BnsNamespaceEventStatus, BnsNamesTable, BnsNameEventsTable, BnsNameEventTopic, BnsMarketplaceEventsTable, BnsMarketplaceAction, BlocksTable, Block, ApiKeysTable, ApiKey, AccountsTable, AccountSpendCapsTable, AccountSpendCap, AccountInsightsTable, AccountInsight, AccountCreditsTable, AccountCredits, AccountAgentRunsTable, AccountAgentRun, Account };
998
+ export { X402PaymentsTable, X402BalancesTable, UpdateTransaction, UpdateSubscriptionOutbox, UpdateSubscription, UpdateSubgraphOperation, UpdateSubgraph, UpdateIndexProgress, UpdateEvent, UpdateContract, UpdateBlock, UpdateApiKey, UpdateAccountSpendCap, UpdateAccountCredits, TriggerEvaluatorStateTable, TriggerEvaluatorState, TransactionsTable, TransactionsArchiveTable, Transaction, SyncScopesTable, SubscriptionsTable, SubscriptionStatus, SubscriptionRuntime, SubscriptionOutboxTable, SubscriptionOutbox, SubscriptionKind, SubscriptionFormat, SubscriptionDelivery, SubscriptionDeliveriesTable, Subscription, SubgraphsTable, SubgraphTableSnapshotsTable, SubgraphProcessingStatsTable, SubgraphOperationsTable, SubgraphOperationStatus, SubgraphOperationKind, SubgraphOperation, SubgraphHealthSnapshotsTable, SubgraphHealthSnapshot, SubgraphGapsTable, SubgraphGap, Subgraph, StageRunsTable, StageRegistryTable, StageKind, StageFailuresTable, StageBlockReceiptsTable, SessionsTable, Session, ServiceHeartbeatsTable, SbtcTokenEventsTable, SbtcTokenEventType, SbtcSupplySnapshotsTable, SbtcSettlementsTable, SbtcEventsTable, SbtcEventTopic, RunStatus, RetryState, RepairMode, ProcessedStripeEventsTable, Pox5EventsTable, Pox5EventTopic, Pox4SignersDailyTable, Pox4FunctionName, Pox4CyclesDailyTable, Pox4CallsTable, PendingForkBlocksTable, OutboxStatus, ObserverJournalTable, ObserverJournalStatus, NativeClock, MempoolTransactionsTable, MempoolTransaction, MagicLinksTable, MagicLink, InstancesTable, InsertTransaction, InsertSubscriptionOutbox, InsertSubscriptionDelivery, InsertSubscription, InsertSubgraphOperation, InsertSubgraphHealthSnapshot, InsertSubgraphGap, InsertSubgraph, InsertSession, InsertMempoolTransaction, InsertMagicLink, InsertIndexProgress, InsertEvent, InsertContract, InsertBlock, InsertApiKey, InsertAccountSpendCap, InsertAccountCredits, InsertAccount, IndexProgressTable, IndexProgress, FailureUnit, FailureClass, EventsTable, EventsArchiveTable, Event, DecoderCheckpointsTable, DecodedEventsTable, DeadLetterEventsTable, Database, CoverageSegmentsTable, ContractsTable, Contract, ChainReorgsTable, ChainReadCacheTable, BurnBlockRewardsTable, BurnBlockRewardSlotsTable, BnsNamespacesTable, BnsNamespaceEventsTable, BnsNamespaceEventStatus, BnsNamesTable, BnsNameEventsTable, BnsNameEventTopic, BnsMarketplaceEventsTable, BnsMarketplaceAction, BlocksTable, Block, ApiKeysTable, ApiKey, AccountsTable, AccountSpendCapsTable, AccountSpendCap, AccountCreditsTable, AccountCredits, Account };
@@ -14,27 +14,6 @@ declare const ErrorCodes: {
14
14
  readonly INSTANCE_EXISTS: "INSTANCE_EXISTS"
15
15
  };
16
16
  type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
17
- /**
18
- * Structured payload carried on a refused BYO breaking-change deploy. Single-sourced
19
- * here so subgraphs (thrower), api (body), sdk (typed error), and cli (renderer) all
20
- * agree on shape. The deploy is still refused — this only describes the manual
21
- * DROP + rebuild the user must run themselves.
22
- */
23
- interface ByoBreakingChangeDetails {
24
- reasons: string[];
25
- diff: {
26
- addedTables: string[]
27
- removedTables: string[]
28
- addedColumns: Record<string, string[]>
29
- breakingChanges: string[]
30
- };
31
- plan: {
32
- schemaName: string
33
- dropStatement: string
34
- statements: string[]
35
- grantScript: string
36
- };
37
- }
38
17
  /** Base error class for all Secondlayer errors. */
39
18
  declare class SecondLayerError extends Error {
40
19
  code: ErrorCode;
@@ -95,4 +74,4 @@ declare class TenantSuspendedError extends SecondLayerError {
95
74
  * (avoids cross-bundle instanceof failures from bunup class duplication). */
96
75
  declare const CODE_TO_STATUS: Record<string, 400 | 401 | 402 | 403 | 404 | 409 | 422 | 423 | 429 | 503>;
97
76
  declare function getErrorMessage(err: unknown): string;
98
- export { getErrorMessage, VersionConflictError, ValidationError, TenantSuspendedError, SecondLayerError, RateLimitError, PaymentRequiredError, NotFoundError, KeyRotatedError, ForbiddenError, ErrorCodes, ErrorCode, DatabaseError, CODE_TO_STATUS, ByoBreakingChangeDetails, AuthorizationError, AuthenticationError };
77
+ export { getErrorMessage, VersionConflictError, ValidationError, TenantSuspendedError, SecondLayerError, RateLimitError, PaymentRequiredError, NotFoundError, KeyRotatedError, ForbiddenError, ErrorCodes, ErrorCode, DatabaseError, CODE_TO_STATUS, AuthorizationError, AuthenticationError };
@@ -138,10 +138,8 @@ var CODE_TO_STATUS = {
138
138
  NO_TENANT_FOR_PROJECT: 404,
139
139
  INSTANCE_EXISTS: 409,
140
140
  SUBGRAPH_NOT_FOUND: 404,
141
- BYO_BREAKING_CHANGE: 422,
142
141
  PUBLIC_NAME_TAKEN: 409,
143
- GHOST_KEY_READ_ONLY: 403,
144
- GENESIS_BACKFILL_REQUIRES_PLAN: 403
142
+ GHOST_KEY_READ_ONLY: 403
145
143
  };
146
144
  function getErrorMessage(err) {
147
145
  return err instanceof Error ? err.message : String(err);
@@ -164,5 +162,5 @@ export {
164
162
  AuthenticationError
165
163
  };
166
164
 
167
- //# debugId=7FB861FAC1CC3EBE64756E2164756E21
165
+ //# debugId=5807B9DB95B688C664756E2164756E21
168
166
  //# sourceMappingURL=errors.js.map
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/errors.ts"],
4
4
  "sourcesContent": [
5
- "export const ErrorCodes = {\n\tVALIDATION_ERROR: \"VALIDATION_ERROR\",\n\tDATABASE_ERROR: \"DATABASE_ERROR\",\n\tAUTHENTICATION_ERROR: \"AUTHENTICATION_ERROR\",\n\tAUTHORIZATION_ERROR: \"AUTHORIZATION_ERROR\",\n\tRATE_LIMIT_ERROR: \"RATE_LIMIT_ERROR\",\n\tPAYMENT_REQUIRED: \"PAYMENT_REQUIRED\",\n\tFORBIDDEN: \"FORBIDDEN\",\n\tVERSION_CONFLICT: \"VERSION_CONFLICT\",\n\tNOT_FOUND: \"NOT_FOUND\",\n\t// Tenant lifecycle (CLI surfaces these verbatim)\n\tKEY_ROTATED: \"KEY_ROTATED\",\n\tTENANT_SUSPENDED: \"TENANT_SUSPENDED\",\n\tNO_TENANT_FOR_PROJECT: \"NO_TENANT_FOR_PROJECT\",\n\tINSTANCE_EXISTS: \"INSTANCE_EXISTS\",\n} as const;\n\nexport type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];\n\n/**\n * Structured payload carried on a refused BYO breaking-change deploy. Single-sourced\n * here so subgraphs (thrower), api (body), sdk (typed error), and cli (renderer) all\n * agree on shape. The deploy is still refused — this only describes the manual\n * DROP + rebuild the user must run themselves.\n */\nexport interface ByoBreakingChangeDetails {\n\treasons: string[];\n\tdiff: {\n\t\taddedTables: string[];\n\t\tremovedTables: string[];\n\t\taddedColumns: Record<string, string[]>;\n\t\tbreakingChanges: string[];\n\t};\n\tplan: {\n\t\tschemaName: string;\n\t\tdropStatement: string;\n\t\tstatements: string[];\n\t\tgrantScript: string;\n\t};\n}\n\n/** Base error class for all Secondlayer errors. */\nexport class SecondLayerError extends Error {\n\tpublic code: ErrorCode;\n\tpublic override cause?: unknown;\n\t/** Optional structured payload merged into the HTTP error body (machine-readable hints). */\n\tpublic details?: Record<string, unknown>;\n\n\tconstructor(\n\t\tcode: ErrorCode,\n\t\tmessage: string,\n\t\tcause?: unknown,\n\t\tdetails?: Record<string, unknown>,\n\t) {\n\t\tsuper(message);\n\t\tthis.code = code;\n\t\tthis.cause = cause;\n\t\tthis.details = details;\n\t\tthis.name = this.constructor.name;\n\t\tError.captureStackTrace?.(this, this.constructor);\n\t}\n\n\ttoJSON(): {\n\t\tname: string;\n\t\tcode: string;\n\t\tmessage: string;\n\t\tstack: string | undefined;\n\t\tcause: unknown;\n\t\tdetails: Record<string, unknown> | undefined;\n\t} {\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tcode: this.code,\n\t\t\tmessage: this.message,\n\t\t\tstack: this.stack,\n\t\t\tcause: this.cause,\n\t\t\tdetails: this.details,\n\t\t};\n\t}\n}\n\nexport class NotFoundError extends SecondLayerError {\n\tconstructor(message: string) {\n\t\tsuper(\"NOT_FOUND\", message);\n\t}\n}\n\nexport class ValidationError extends SecondLayerError {\n\tconstructor(message: string, cause?: unknown) {\n\t\tsuper(\"VALIDATION_ERROR\", message, cause);\n\t}\n}\n\nexport class DatabaseError extends SecondLayerError {\n\tconstructor(message: string, cause?: unknown) {\n\t\tsuper(\"DATABASE_ERROR\", message, cause);\n\t}\n}\n\nexport class AuthenticationError extends SecondLayerError {\n\tconstructor(message: string) {\n\t\tsuper(\"AUTHENTICATION_ERROR\", message);\n\t}\n}\n\nexport class AuthorizationError extends SecondLayerError {\n\tconstructor(message: string, details?: Record<string, unknown>) {\n\t\tsuper(\"AUTHORIZATION_ERROR\", message, undefined, details);\n\t}\n}\n\nexport class RateLimitError extends SecondLayerError {\n\tconstructor(message: string) {\n\t\tsuper(\"RATE_LIMIT_ERROR\", message);\n\t}\n}\n\n/**\n * HTTP 402. Carries the x402 challenge (or a retry-later reason) in `details` so\n * the global error handler emits it in the body. The wire `PAYMENT-REQUIRED`\n * header is set separately by the x402 middleware on the challenge path.\n */\nexport class PaymentRequiredError extends SecondLayerError {\n\tconstructor(message: string, details?: Record<string, unknown>) {\n\t\tsuper(\"PAYMENT_REQUIRED\", message, undefined, details);\n\t}\n}\n\nexport class ForbiddenError extends SecondLayerError {\n\tconstructor(message = \"Forbidden\") {\n\t\tsuper(\"FORBIDDEN\", message);\n\t}\n}\n\nexport class VersionConflictError extends SecondLayerError {\n\tpublic currentVersion: string;\n\tpublic expectedVersion: string;\n\n\tconstructor(currentVersion: string, expectedVersion: string) {\n\t\tsuper(\n\t\t\t\"VERSION_CONFLICT\",\n\t\t\t`Version conflict: expected ${expectedVersion}, current ${currentVersion}`,\n\t\t);\n\t\tthis.currentVersion = currentVersion;\n\t\tthis.expectedVersion = expectedVersion;\n\t}\n}\n\nexport class KeyRotatedError extends SecondLayerError {\n\tconstructor(message = \"Token has been rotated\") {\n\t\tsuper(\"KEY_ROTATED\", message);\n\t}\n}\n\nexport class TenantSuspendedError extends SecondLayerError {\n\tconstructor(message = \"Instance is suspended\") {\n\t\tsuper(\"TENANT_SUSPENDED\", message);\n\t}\n}\n\n/** Error code → HTTP status. Used by API middleware for code-based matching\n * (avoids cross-bundle instanceof failures from bunup class duplication). */\n// String literal map — codes don't have to be in the central ErrorCode\n// enum (route-local error classes can supply any code; we just map the\n// HTTP status here). This keeps cross-bundle instanceof failures out of\n// the equation.\nexport const CODE_TO_STATUS: Record<\n\tstring,\n\t400 | 401 | 402 | 403 | 404 | 409 | 422 | 423 | 429 | 503\n> = {\n\t// The chain plane has no data yet — a fresh self-host install before the\n\t// first block lands. Retryable, and not the operator's mistake, so it is a\n\t// 503 with a name rather than an opaque 500.\n\tCHAIN_DATA_UNAVAILABLE: 503,\n\tAUTHENTICATION_ERROR: 401,\n\tAUTHORIZATION_ERROR: 403,\n\tPAYMENT_REQUIRED: 402,\n\tRATE_LIMIT_ERROR: 429,\n\tFORBIDDEN: 403,\n\tNOT_FOUND: 404,\n\tVALIDATION_ERROR: 400,\n\tKEY_ROTATED: 401,\n\tTENANT_SUSPENDED: 423,\n\tNO_TENANT_FOR_PROJECT: 404,\n\tINSTANCE_EXISTS: 409,\n\tSUBGRAPH_NOT_FOUND: 404,\n\tBYO_BREAKING_CHANGE: 422,\n\tPUBLIC_NAME_TAKEN: 409,\n\tGHOST_KEY_READ_ONLY: 403,\n\tGENESIS_BACKFILL_REQUIRES_PLAN: 403,\n} as const;\n\nexport function getErrorMessage(err: unknown): string {\n\treturn err instanceof Error ? err.message : String(err);\n}\n"
5
+ "export const ErrorCodes = {\n\tVALIDATION_ERROR: \"VALIDATION_ERROR\",\n\tDATABASE_ERROR: \"DATABASE_ERROR\",\n\tAUTHENTICATION_ERROR: \"AUTHENTICATION_ERROR\",\n\tAUTHORIZATION_ERROR: \"AUTHORIZATION_ERROR\",\n\tRATE_LIMIT_ERROR: \"RATE_LIMIT_ERROR\",\n\tPAYMENT_REQUIRED: \"PAYMENT_REQUIRED\",\n\tFORBIDDEN: \"FORBIDDEN\",\n\tVERSION_CONFLICT: \"VERSION_CONFLICT\",\n\tNOT_FOUND: \"NOT_FOUND\",\n\t// Tenant lifecycle (CLI surfaces these verbatim)\n\tKEY_ROTATED: \"KEY_ROTATED\",\n\tTENANT_SUSPENDED: \"TENANT_SUSPENDED\",\n\tNO_TENANT_FOR_PROJECT: \"NO_TENANT_FOR_PROJECT\",\n\tINSTANCE_EXISTS: \"INSTANCE_EXISTS\",\n} as const;\n\nexport type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];\n\n/** Base error class for all Secondlayer errors. */\nexport class SecondLayerError extends Error {\n\tpublic code: ErrorCode;\n\tpublic override cause?: unknown;\n\t/** Optional structured payload merged into the HTTP error body (machine-readable hints). */\n\tpublic details?: Record<string, unknown>;\n\n\tconstructor(\n\t\tcode: ErrorCode,\n\t\tmessage: string,\n\t\tcause?: unknown,\n\t\tdetails?: Record<string, unknown>,\n\t) {\n\t\tsuper(message);\n\t\tthis.code = code;\n\t\tthis.cause = cause;\n\t\tthis.details = details;\n\t\tthis.name = this.constructor.name;\n\t\tError.captureStackTrace?.(this, this.constructor);\n\t}\n\n\ttoJSON(): {\n\t\tname: string;\n\t\tcode: string;\n\t\tmessage: string;\n\t\tstack: string | undefined;\n\t\tcause: unknown;\n\t\tdetails: Record<string, unknown> | undefined;\n\t} {\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tcode: this.code,\n\t\t\tmessage: this.message,\n\t\t\tstack: this.stack,\n\t\t\tcause: this.cause,\n\t\t\tdetails: this.details,\n\t\t};\n\t}\n}\n\nexport class NotFoundError extends SecondLayerError {\n\tconstructor(message: string) {\n\t\tsuper(\"NOT_FOUND\", message);\n\t}\n}\n\nexport class ValidationError extends SecondLayerError {\n\tconstructor(message: string, cause?: unknown) {\n\t\tsuper(\"VALIDATION_ERROR\", message, cause);\n\t}\n}\n\nexport class DatabaseError extends SecondLayerError {\n\tconstructor(message: string, cause?: unknown) {\n\t\tsuper(\"DATABASE_ERROR\", message, cause);\n\t}\n}\n\nexport class AuthenticationError extends SecondLayerError {\n\tconstructor(message: string) {\n\t\tsuper(\"AUTHENTICATION_ERROR\", message);\n\t}\n}\n\nexport class AuthorizationError extends SecondLayerError {\n\tconstructor(message: string, details?: Record<string, unknown>) {\n\t\tsuper(\"AUTHORIZATION_ERROR\", message, undefined, details);\n\t}\n}\n\nexport class RateLimitError extends SecondLayerError {\n\tconstructor(message: string) {\n\t\tsuper(\"RATE_LIMIT_ERROR\", message);\n\t}\n}\n\n/**\n * HTTP 402. Carries the x402 challenge (or a retry-later reason) in `details` so\n * the global error handler emits it in the body. The wire `PAYMENT-REQUIRED`\n * header is set separately by the x402 middleware on the challenge path.\n */\nexport class PaymentRequiredError extends SecondLayerError {\n\tconstructor(message: string, details?: Record<string, unknown>) {\n\t\tsuper(\"PAYMENT_REQUIRED\", message, undefined, details);\n\t}\n}\n\nexport class ForbiddenError extends SecondLayerError {\n\tconstructor(message = \"Forbidden\") {\n\t\tsuper(\"FORBIDDEN\", message);\n\t}\n}\n\nexport class VersionConflictError extends SecondLayerError {\n\tpublic currentVersion: string;\n\tpublic expectedVersion: string;\n\n\tconstructor(currentVersion: string, expectedVersion: string) {\n\t\tsuper(\n\t\t\t\"VERSION_CONFLICT\",\n\t\t\t`Version conflict: expected ${expectedVersion}, current ${currentVersion}`,\n\t\t);\n\t\tthis.currentVersion = currentVersion;\n\t\tthis.expectedVersion = expectedVersion;\n\t}\n}\n\nexport class KeyRotatedError extends SecondLayerError {\n\tconstructor(message = \"Token has been rotated\") {\n\t\tsuper(\"KEY_ROTATED\", message);\n\t}\n}\n\nexport class TenantSuspendedError extends SecondLayerError {\n\tconstructor(message = \"Instance is suspended\") {\n\t\tsuper(\"TENANT_SUSPENDED\", message);\n\t}\n}\n\n/** Error code → HTTP status. Used by API middleware for code-based matching\n * (avoids cross-bundle instanceof failures from bunup class duplication). */\n// String literal map — codes don't have to be in the central ErrorCode\n// enum (route-local error classes can supply any code; we just map the\n// HTTP status here). This keeps cross-bundle instanceof failures out of\n// the equation.\nexport const CODE_TO_STATUS: Record<\n\tstring,\n\t400 | 401 | 402 | 403 | 404 | 409 | 422 | 423 | 429 | 503\n> = {\n\t// The chain plane has no data yet — a fresh self-host install before the\n\t// first block lands. Retryable, and not the operator's mistake, so it is a\n\t// 503 with a name rather than an opaque 500.\n\tCHAIN_DATA_UNAVAILABLE: 503,\n\tAUTHENTICATION_ERROR: 401,\n\tAUTHORIZATION_ERROR: 403,\n\tPAYMENT_REQUIRED: 402,\n\tRATE_LIMIT_ERROR: 429,\n\tFORBIDDEN: 403,\n\tNOT_FOUND: 404,\n\tVALIDATION_ERROR: 400,\n\tKEY_ROTATED: 401,\n\tTENANT_SUSPENDED: 423,\n\tNO_TENANT_FOR_PROJECT: 404,\n\tINSTANCE_EXISTS: 409,\n\tSUBGRAPH_NOT_FOUND: 404,\n\tPUBLIC_NAME_TAKEN: 409,\n\tGHOST_KEY_READ_ONLY: 403,\n} as const;\n\nexport function getErrorMessage(err: unknown): string {\n\treturn err instanceof Error ? err.message : String(err);\n}\n"
6
6
  ],
7
- "mappings": ";;;;;;;;;;;;;;;;;AAAO,IAAM,aAAa;AAAA,EACzB,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,sBAAsB;AAAA,EACtB,qBAA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