@secondlayer/shared 7.11.1 → 8.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 (50) hide show
  1. package/dist/src/archive/range-digest.d.ts +0 -169
  2. package/dist/src/archive/semantic-digest-builder.d.ts +0 -169
  3. package/dist/src/coverage/index.d.ts +0 -169
  4. package/dist/src/crypto/secrets.js +22 -3
  5. package/dist/src/crypto/secrets.js.map +3 -3
  6. package/dist/src/db/index.d.ts +1 -211
  7. package/dist/src/db/index.js +22 -16
  8. package/dist/src/db/index.js.map +4 -4
  9. package/dist/src/db/queries/chain-reorgs.d.ts +0 -169
  10. package/dist/src/db/queries/chain-reorgs.js +22 -16
  11. package/dist/src/db/queries/chain-reorgs.js.map +4 -4
  12. package/dist/src/db/queries/contracts.d.ts +0 -169
  13. package/dist/src/db/queries/instance.d.ts +0 -169
  14. package/dist/src/db/queries/integrity.d.ts +0 -169
  15. package/dist/src/db/queries/subgraph-gaps.d.ts +0 -169
  16. package/dist/src/db/queries/subgraph-operations.d.ts +1 -170
  17. package/dist/src/db/queries/subgraph-operations.js +1 -15
  18. package/dist/src/db/queries/subgraph-operations.js.map +3 -3
  19. package/dist/src/db/queries/subgraphs.d.ts +1 -191
  20. package/dist/src/db/queries/subgraphs.js +30 -1068
  21. package/dist/src/db/queries/subgraphs.js.map +5 -12
  22. package/dist/src/db/queries/subscriptions.d.ts +0 -169
  23. package/dist/src/db/queries/subscriptions.js +22 -3
  24. package/dist/src/db/queries/subscriptions.js.map +3 -3
  25. package/dist/src/db/schema.d.ts +1 -198
  26. package/dist/src/errors.d.ts +1 -22
  27. package/dist/src/errors.js +2 -4
  28. package/dist/src/errors.js.map +3 -3
  29. package/dist/src/index.d.ts +5 -256
  30. package/dist/src/index.js +23 -20
  31. package/dist/src/index.js.map +6 -6
  32. package/dist/src/mode.d.ts +16 -2
  33. package/dist/src/mode.js +25 -4
  34. package/dist/src/mode.js.map +3 -3
  35. package/dist/src/node/local-client.d.ts +0 -169
  36. package/dist/src/runtime/index.js +26 -3
  37. package/dist/src/runtime/index.js.map +3 -3
  38. package/dist/src/schemas/index.d.ts +5 -25
  39. package/dist/src/schemas/index.js +1 -2
  40. package/dist/src/schemas/index.js.map +3 -3
  41. package/dist/src/schemas/subgraphs.d.ts +5 -25
  42. package/dist/src/schemas/subgraphs.js +1 -2
  43. package/dist/src/schemas/subgraphs.js.map +3 -3
  44. package/dist/src/streams-rows/index.d.ts +399 -0
  45. package/dist/src/streams-rows/index.js +336 -0
  46. package/dist/src/streams-rows/index.js.map +17 -0
  47. package/dist/src/subgraphs/spec.d.ts +0 -9
  48. package/migrations/0118_drop_retired_control_tables.ts +53 -0
  49. package/migrations/0119_drop_accounts_plan.ts +29 -0
  50. package/package.json +5 -1
@@ -15,14 +15,33 @@ var __export = (target, all) => {
15
15
  };
16
16
 
17
17
  // src/mode.ts
18
- var VALID_MODES = ["oss", "platform"];
19
- function getInstanceMode() {
18
+ var VALID_MODES = [
19
+ "oss",
20
+ "platform",
21
+ "archive"
22
+ ];
23
+ function declaredMode() {
20
24
  const raw = process.env.INSTANCE_MODE?.trim().toLowerCase();
21
25
  if (raw && VALID_MODES.includes(raw)) {
22
26
  return raw;
23
27
  }
24
28
  return "oss";
25
29
  }
30
+ function getInstanceMode() {
31
+ const declared = declaredMode();
32
+ return declared === "archive" ? "platform" : declared;
33
+ }
34
+ function getDeclaredInstanceMode() {
35
+ return declaredMode();
36
+ }
37
+ function isMeteredReads() {
38
+ const override = process.env.METERED_READS?.trim().toLowerCase();
39
+ if (override === "true")
40
+ return true;
41
+ if (override === "false")
42
+ return false;
43
+ return getInstanceMode() === "platform";
44
+ }
26
45
  function isPlatformMode() {
27
46
  return getInstanceMode() === "platform";
28
47
  }
@@ -160,5 +179,5 @@ export {
160
179
  decryptSecret
161
180
  };
162
181
 
163
- //# debugId=D05BC92983E1614B64756E2164756E21
182
+ //# debugId=8E49B42A8C43DF1864756E2164756E21
164
183
  //# sourceMappingURL=secrets.js.map
@@ -2,10 +2,10 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/mode.ts", "../src/crypto/secrets.ts"],
4
4
  "sourcesContent": [
5
- "/**\n * Instance modes for the Secondlayer platform.\n *\n * - `oss`: self-hosted, single-tenant. No auth middleware, no platform routes\n * (projects, admin). Everything runs against a single `DATABASE_URL`.\n * Intended for `docker compose up`.\n *\n * - `platform`: control-plane mode. Magic-link auth, API keys, projects,\n * admin. Serves the dashboard + CLI against a single shared DB. Post\n * 2026-05-14 shared-rip this also serves subgraphs + subscriptions.\n */\n\nexport type InstanceMode = \"oss\" | \"platform\";\n\nconst VALID_MODES: readonly InstanceMode[] = [\"oss\", \"platform\"];\n\n/**\n * Resolve the active instance mode from `process.env.INSTANCE_MODE`.\n * Defaults to `\"oss\"` — the safest default for self-hosters who deploy\n * without setting the variable.\n */\nexport function getInstanceMode(): InstanceMode {\n\tconst raw = process.env.INSTANCE_MODE?.trim().toLowerCase();\n\tif (raw && (VALID_MODES as readonly string[]).includes(raw)) {\n\t\treturn raw as InstanceMode;\n\t}\n\treturn \"oss\";\n}\n\n/** True when the active mode is `\"platform\"` (shared multi-tenant). */\nexport function isPlatformMode(): boolean {\n\treturn getInstanceMode() === \"platform\";\n}\n\n/** True when the active mode is `\"oss\"` (self-hosted). */\nexport function isOssMode(): boolean {\n\treturn getInstanceMode() === \"oss\";\n}\n",
5
+ "/**\n * Instance modes for the Secondlayer platform.\n *\n * - `oss`: self-hosted, single-tenant. No auth middleware, no platform routes\n * (projects, admin). Everything runs against a single `DATABASE_URL`.\n * Intended for `docker compose up`.\n *\n * - `platform`: control-plane mode. Magic-link auth, API keys, projects,\n * admin. Serves the dashboard + CLI against a single shared DB. Post\n * 2026-05-14 shared-rip this also serves subgraphs + subscriptions.\n */\n\nexport type InstanceMode = \"oss\" | \"platform\";\n\n/** What the operator wrote in the env — `archive` is the honest name for the\n * metered public-archive deployment and aliases `platform` behaviorally. */\nexport type DeclaredInstanceMode = InstanceMode | \"archive\";\n\nconst VALID_MODES: readonly DeclaredInstanceMode[] = [\n\t\"oss\",\n\t\"platform\",\n\t\"archive\",\n];\n\nfunction declaredMode(): DeclaredInstanceMode {\n\tconst raw = process.env.INSTANCE_MODE?.trim().toLowerCase();\n\tif (raw && (VALID_MODES as readonly string[]).includes(raw)) {\n\t\treturn raw as DeclaredInstanceMode;\n\t}\n\treturn \"oss\";\n}\n\n/**\n * Resolve the active instance mode from `process.env.INSTANCE_MODE`.\n * Defaults to `\"oss\"` — the safest default for self-hosters who deploy\n * without setting the variable. `archive` normalizes to `platform` here so\n * every behavioral branch stays a two-way choice; use\n * `getDeclaredInstanceMode()` for display surfaces.\n */\nexport function getInstanceMode(): InstanceMode {\n\tconst declared = declaredMode();\n\treturn declared === \"archive\" ? \"platform\" : declared;\n}\n\n/** The mode as declared in the env, for status/identity surfaces. */\nexport function getDeclaredInstanceMode(): DeclaredInstanceMode {\n\treturn declaredMode();\n}\n\n/**\n * True when public reads are credit-metered (the free window, retention, and\n * credits gates arm). Platform/archive deployments meter by default;\n * self-host never does unless the operator explicitly sets\n * `METERED_READS=true`. `METERED_READS=false` disarms a metered deployment.\n */\nexport function isMeteredReads(): boolean {\n\tconst override = process.env.METERED_READS?.trim().toLowerCase();\n\tif (override === \"true\") return true;\n\tif (override === \"false\") return false;\n\treturn getInstanceMode() === \"platform\";\n}\n\n/** True when the active mode is `\"platform\"` (shared multi-tenant). */\nexport function isPlatformMode(): boolean {\n\treturn getInstanceMode() === \"platform\";\n}\n\n/** True when the active mode is `\"oss\"` (self-hosted). */\nexport function isOssMode(): boolean {\n\treturn getInstanceMode() === \"oss\";\n}\n",
6
6
  "import { createCipheriv, createDecipheriv, randomBytes } from \"node:crypto\";\nimport {\n\tappendFileSync,\n\tcloseSync,\n\texistsSync,\n\topenSync,\n\treadFileSync,\n\tunlinkSync,\n} from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { getInstanceMode } from \"../mode.ts\";\n\n/**\n * AES-256-GCM symmetric envelope for encrypted secrets at rest (tenant keys,\n * subscription signing secrets, etc.).\n *\n * Ciphertext layout: `iv (12 bytes) || authTag (16 bytes) || ciphertext`\n *\n * The key comes from `SECONDLAYER_SECRETS_KEY` — 32 bytes hex. In OSS mode,\n * if the env var is unset on first use we autogenerate a key and persist it\n * to `.env.local` in the current working directory so subsequent restarts\n * pick it up without user intervention. Dedicated/platform modes throw —\n * those runtimes must provision the key explicitly.\n *\n * Rotation strategy: re-encrypt all rows with the new key and swap the env\n * var. Not zero-downtime, but acceptable at v2 scale. For real KMS (AWS\n * KMS, Vault, GCP KMS), wrap the same byte layout behind an\n * `EncryptSecret`/`DecryptSecret` interface and swap at startup.\n */\n\nconst KEY_ENV = \"SECONDLAYER_SECRETS_KEY\";\nconst IV_LEN = 12;\nconst TAG_LEN = 16;\n\nfunction readExistingKey(envPath: string): string | null {\n\tif (!existsSync(envPath)) return null;\n\tconst contents = readFileSync(envPath, \"utf8\");\n\tconst match = contents.match(/^SECONDLAYER_SECRETS_KEY=([a-fA-F0-9]{64})/m);\n\t// biome-ignore lint/style/noNonNullAssertion: value is non-null after preceding check or by construction; TS narrowing limitation\n\treturn match ? match[1]! : null;\n}\n\n/**\n * Atomic file lock via `openSync(..., \"wx\")` — O_CREAT | O_EXCL. If two\n * processes race on cold-compose start, exactly one creates the lock\n * file; the loser polls until the winner finishes writing `.env.local`,\n * then reads the winner's key. Stale locks (process crashed mid-write)\n * are cleaned after `STALE_LOCK_MS`.\n */\nconst STALE_LOCK_MS = 10_000;\nconst POLL_MS = 25;\n\nfunction bootstrapOssKey(): string {\n\tconst envPath = resolve(process.cwd(), \".env.local\");\n\n\t// Fast path — key already on disk from a prior run.\n\tconst existing = readExistingKey(envPath);\n\tif (existing) {\n\t\tprocess.env[KEY_ENV] = existing;\n\t\treturn existing;\n\t}\n\n\tconst lockPath = `${envPath}.secret-bootstrap.lock`;\n\tlet lockFd: number | null = null;\n\ttry {\n\t\tlockFd = openSync(lockPath, \"wx\", 0o600);\n\t} catch (err) {\n\t\tconst e = err as NodeJS.ErrnoException;\n\t\tif (e.code !== \"EEXIST\") throw err;\n\t}\n\n\tif (lockFd === null) {\n\t\t// Another process is bootstrapping. Poll for its result.\n\t\tconst deadline = Date.now() + STALE_LOCK_MS;\n\t\twhile (Date.now() < deadline) {\n\t\t\tconst key = readExistingKey(envPath);\n\t\t\tif (key) {\n\t\t\t\tprocess.env[KEY_ENV] = key;\n\t\t\t\treturn key;\n\t\t\t}\n\t\t\tBun.sleepSync(POLL_MS);\n\t\t}\n\t\t// Lock holder died mid-write — force-clean and retry once.\n\t\ttry {\n\t\t\tunlinkSync(lockPath);\n\t\t} catch {}\n\t\treturn bootstrapOssKey();\n\t}\n\n\ttry {\n\t\tconst hex = randomBytes(32).toString(\"hex\");\n\t\tconst line = `${existsSync(envPath) ? \"\\n\" : \"\"}${KEY_ENV}=${hex}\\n`;\n\t\tappendFileSync(envPath, line, { mode: 0o600 });\n\t\tprocess.env[KEY_ENV] = hex;\n\t\tconsole.log(\n\t\t\t`[secondlayer] generated ${KEY_ENV}; saved to ${envPath} (mode 0600)`,\n\t\t);\n\t\treturn hex;\n\t} finally {\n\t\tcloseSync(lockFd);\n\t\ttry {\n\t\t\tunlinkSync(lockPath);\n\t\t} catch {}\n\t}\n}\n\nfunction loadKey(): Buffer {\n\tlet hex = process.env[KEY_ENV];\n\tif (!hex) {\n\t\tif (getInstanceMode() === \"oss\") {\n\t\t\thex = bootstrapOssKey();\n\t\t} else {\n\t\t\tthrow new Error(\n\t\t\t\t`${KEY_ENV} not set. Generate one with: openssl rand -hex 32`,\n\t\t\t);\n\t\t}\n\t}\n\tconst key = Buffer.from(hex, \"hex\");\n\tif (key.length !== 32) {\n\t\tthrow new Error(`${KEY_ENV} must be 32 bytes hex (got ${key.length})`);\n\t}\n\treturn key;\n}\n\nlet _cachedKey: Buffer | null = null;\nfunction getKey(): Buffer {\n\tif (!_cachedKey) _cachedKey = loadKey();\n\treturn _cachedKey;\n}\n\n/**\n * Non-throwing check for whether a secrets key is currently resolvable —\n * same resolution order as {@link loadKey} (env var, then the OSS\n * `.env.local` fallback), but never bootstraps a new key (that would\n * generate+persist a key as a side effect of a mere existence check), never\n * throws, and never returns or logs the key itself. Used by callers that\n * need to fail loud on a missing key BEFORE attempting a decrypt (f072).\n */\nexport function secretsKeyAvailable(): boolean {\n\tif (process.env[KEY_ENV]) return true;\n\tif (getInstanceMode() === \"oss\") {\n\t\tconst envPath = resolve(process.cwd(), \".env.local\");\n\t\treturn readExistingKey(envPath) !== null;\n\t}\n\treturn false;\n}\n\nexport function encryptSecret(plaintext: string): Buffer {\n\tconst key = getKey();\n\tconst iv = randomBytes(IV_LEN);\n\tconst cipher = createCipheriv(\"aes-256-gcm\", key, iv);\n\tconst ciphertext = Buffer.concat([\n\t\tcipher.update(plaintext, \"utf8\"),\n\t\tcipher.final(),\n\t]);\n\tconst tag = cipher.getAuthTag();\n\treturn Buffer.concat([iv, tag, ciphertext]);\n}\n\nexport function decryptSecret(envelope: Buffer): string {\n\tconst key = getKey();\n\tconst iv = envelope.subarray(0, IV_LEN);\n\tconst tag = envelope.subarray(IV_LEN, IV_LEN + TAG_LEN);\n\tconst ciphertext = envelope.subarray(IV_LEN + TAG_LEN);\n\tconst decipher = createDecipheriv(\"aes-256-gcm\", key, iv);\n\tdecipher.setAuthTag(tag);\n\treturn decipher.update(ciphertext).toString(\"utf8\") + decipher.final(\"utf8\");\n}\n\n/** Generate a fresh 32-byte hex key suitable for `SECONDLAYER_SECRETS_KEY`. */\nexport function generateSecretsKey(): string {\n\treturn randomBytes(32).toString(\"hex\");\n}\n"
7
7
  ],
8
- "mappings": ";;;;;;;;;;;;;;;;;AAcA,IAAM,cAAuC,CAAC,OAAO,UAAU;AAOxD,SAAS,eAAe,GAAiB;AAAA,EAC/C,MAAM,MAAM,QAAQ,IAAI,eAAe,KAAK,EAAE,YAAY;AAAA,EAC1D,IAAI,OAAQ,YAAkC,SAAS,GAAG,GAAG;AAAA,IA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
10
  "names": []
11
11
  }
@@ -241,11 +241,9 @@ interface AccountsTable {
241
241
  ghost: Generated<boolean>;
242
242
  /** Stacks principal owning a wallet-ghost account (x402-paid deploys). */
243
243
  wallet_principal: string | null;
244
- plan: Generated<string>;
245
244
  display_name: string | null;
246
245
  bio: string | null;
247
246
  avatar_url: string | null;
248
- slug: string | null;
249
247
  stripe_customer_id: string | null;
250
248
  /** Opt-out toggle for the subgraph reindex-completion email. Defaults true. */
251
249
  notify_reindex_complete: Generated<boolean>;
@@ -262,19 +260,6 @@ interface SessionsTable {
262
260
  last_used_at: Date | null;
263
261
  created_at: Generated<Date>;
264
262
  }
265
- /**
266
- * One-time claim tokens for ghost accounts. The raw token only ever appears in
267
- * the claim URL returned at mint time; we store its sha256. A used token marks
268
- * the account as claimed (or merged into an existing account).
269
- */
270
- interface ClaimTokensTable {
271
- id: Generated<string>;
272
- account_id: string;
273
- token_hash: string;
274
- created_at: Generated<Date>;
275
- expires_at: Date;
276
- used_at: Date | null;
277
- }
278
263
  interface MagicLinksTable {
279
264
  id: Generated<string>;
280
265
  email: string;
@@ -285,47 +270,6 @@ interface MagicLinksTable {
285
270
  failed_attempts: Generated<number>;
286
271
  created_at: Generated<Date>;
287
272
  }
288
- interface UsageDailyTable {
289
- account_id: string;
290
- tenant_id: string | null;
291
- date: string;
292
- api_requests: Generated<number>;
293
- deliveries: Generated<number>;
294
- streams_events_returned: Generated<number>;
295
- index_decoded_events_returned: Generated<number>;
296
- }
297
- interface UsageSnapshotsTable {
298
- id: Generated<string>;
299
- account_id: string;
300
- measured_at: Generated<Date>;
301
- storage_bytes: Generated<number>;
302
- }
303
- interface AccountInsightsTable {
304
- id: Generated<string>;
305
- account_id: string;
306
- category: string;
307
- insight_type: string;
308
- resource_id: string | null;
309
- severity: string;
310
- title: string;
311
- body: string;
312
- data: unknown;
313
- dismissed_at: Date | null;
314
- expires_at: Date | null;
315
- created_at: Generated<Date>;
316
- }
317
- interface AccountAgentRunsTable {
318
- id: Generated<string>;
319
- account_id: string;
320
- started_at: Generated<Date>;
321
- completed_at: Date | null;
322
- status: Generated<string>;
323
- input_tokens: Generated<number>;
324
- output_tokens: Generated<number>;
325
- cost_usd: Generated<number>;
326
- insights_created: Generated<number>;
327
- error: string | null;
328
- }
329
273
  interface SubgraphProcessingStatsTable {
330
274
  id: Generated<string>;
331
275
  subgraph_name: string;
@@ -358,41 +302,6 @@ interface SubgraphHealthSnapshotsTable {
358
302
  last_processed_block: number | null;
359
303
  captured_at: Generated<Date>;
360
304
  }
361
- interface SubgraphUsageDailyTable {
362
- subgraph_id: string;
363
- date: string;
364
- query_count: Generated<number>;
365
- }
366
- interface ProjectsTable {
367
- id: Generated<string>;
368
- name: string;
369
- slug: string;
370
- account_id: string;
371
- settings: Generated<Record<string, unknown>>;
372
- network: Generated<string>;
373
- node_rpc: string | null;
374
- created_at: Generated<Date>;
375
- updated_at: Generated<Date>;
376
- }
377
- interface TeamMembersTable {
378
- id: Generated<string>;
379
- project_id: string;
380
- account_id: string;
381
- role: Generated<string>;
382
- invited_by: string | null;
383
- created_at: Generated<Date>;
384
- }
385
- interface TeamInvitationsTable {
386
- id: Generated<string>;
387
- project_id: string;
388
- email: string;
389
- role: Generated<string>;
390
- token: string;
391
- invited_by: string | null;
392
- expires_at: Date;
393
- accepted_at: Date | null;
394
- created_at: Generated<Date>;
395
- }
396
305
  interface ProcessedStripeEventsTable {
397
306
  event_id: string;
398
307
  event_type: string;
@@ -845,27 +754,14 @@ interface Database {
845
754
  accounts: AccountsTable;
846
755
  sessions: SessionsTable;
847
756
  magic_links: MagicLinksTable;
848
- claim_tokens: ClaimTokensTable;
849
- usage_daily: UsageDailyTable;
850
- usage_snapshots: UsageSnapshotsTable;
851
- account_insights: AccountInsightsTable;
852
- account_agent_runs: AccountAgentRunsTable;
853
757
  subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
854
758
  subgraph_processing_stats: SubgraphProcessingStatsTable;
855
759
  subgraph_table_snapshots: SubgraphTableSnapshotsTable;
856
760
  subgraph_gaps: SubgraphGapsTable;
857
761
  subgraph_operations: SubgraphOperationsTable;
858
- subgraph_usage_daily: SubgraphUsageDailyTable;
859
- projects: ProjectsTable;
860
- team_members: TeamMembersTable;
861
- team_invitations: TeamInvitationsTable;
862
762
  processed_stripe_events: ProcessedStripeEventsTable;
863
- tenants: TenantsTable;
864
- tenant_usage_monthly: TenantUsageMonthlyTable;
865
- tenant_compute_addons: TenantComputeAddonsTable;
866
763
  account_spend_caps: AccountSpendCapsTable;
867
764
  account_credits: AccountCreditsTable;
868
- provisioning_audit_log: ProvisioningAuditLogTable;
869
765
  subscriptions: SubscriptionsTable;
870
766
  subscription_outbox: SubscriptionOutboxTable;
871
767
  subscription_deliveries: SubscriptionDeliveriesTable;
@@ -940,66 +836,6 @@ interface X402PaymentsTable {
940
836
  * reconciler's heal path can never double-credit them. */
941
837
  credited_at: Generated<Date> | null;
942
838
  }
943
- type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
944
- interface TenantsTable {
945
- id: Generated<string>;
946
- account_id: string;
947
- slug: string;
948
- status: ColumnType<TenantStatus, TenantStatus | undefined, TenantStatus>;
949
- plan: string;
950
- cpus: ColumnType<number, number | string, number | string>;
951
- memory_mb: number;
952
- storage_limit_mb: number;
953
- storage_used_mb: number | null;
954
- pg_container_id: string | null;
955
- api_container_id: string | null;
956
- processor_container_id: string | null;
957
- target_database_url_enc: Buffer;
958
- tenant_jwt_secret_enc: Buffer;
959
- anon_key_enc: Buffer;
960
- service_key_enc: Buffer;
961
- api_url_internal: string;
962
- api_url_public: string;
963
- suspended_at: Date | null;
964
- last_health_check_at: Date | null;
965
- last_active_at: Generated<Date>;
966
- service_gen: Generated<number>;
967
- anon_gen: Generated<number>;
968
- project_id: string | null;
969
- created_at: Generated<Date>;
970
- updated_at: Generated<Date>;
971
- }
972
- type Tenant = Selectable<TenantsTable>;
973
- type InsertTenant = Insertable<TenantsTable>;
974
- type UpdateTenant = Updateable<TenantsTable>;
975
- interface TenantUsageMonthlyTable {
976
- id: Generated<string>;
977
- tenant_id: string;
978
- period_month: Date;
979
- storage_peak_mb: Generated<number>;
980
- storage_avg_mb: Generated<number>;
981
- storage_last_mb: Generated<number>;
982
- measurements: Generated<number>;
983
- first_at: Generated<Date>;
984
- last_at: Generated<Date>;
985
- }
986
- type TenantUsageMonthly = Selectable<TenantUsageMonthlyTable>;
987
- type InsertTenantUsageMonthly = Insertable<TenantUsageMonthlyTable>;
988
- type UpdateTenantUsageMonthly = Updateable<TenantUsageMonthlyTable>;
989
- interface TenantComputeAddonsTable {
990
- id: Generated<string>;
991
- tenant_id: string;
992
- memory_mb_delta: Generated<number>;
993
- cpu_delta: Generated<number | string>;
994
- storage_mb_delta: Generated<number>;
995
- effective_from: Generated<Date>;
996
- effective_until: Date | null;
997
- stripe_subscription_item_id: string | null;
998
- created_at: Generated<Date>;
999
- }
1000
- type TenantComputeAddon = Selectable<TenantComputeAddonsTable>;
1001
- type InsertTenantComputeAddon = Insertable<TenantComputeAddonsTable>;
1002
- type UpdateTenantComputeAddon = Updateable<TenantComputeAddonsTable>;
1003
839
  interface AccountSpendCapsTable {
1004
840
  account_id: string;
1005
841
  monthly_cap_cents: number | null;
@@ -1029,22 +865,6 @@ interface AccountCreditsTable {
1029
865
  type AccountCredits = Selectable<AccountCreditsTable>;
1030
866
  type InsertAccountCredits = Insertable<AccountCreditsTable>;
1031
867
  type UpdateAccountCredits = Updateable<AccountCreditsTable>;
1032
- type ProvisioningAuditEvent = "provision.start" | "provision.success" | "provision.failure" | "suspend" | "resume" | "resize" | "keys.rotate" | "bastion.key.upload" | "bastion.key.revoke" | "teardown";
1033
- type ProvisioningAuditStatus = "ok" | "error";
1034
- interface ProvisioningAuditLogTable {
1035
- id: Generated<string>;
1036
- tenant_id: string | null;
1037
- tenant_slug: string | null;
1038
- account_id: string | null;
1039
- actor: string;
1040
- event: ProvisioningAuditEvent;
1041
- status: ProvisioningAuditStatus;
1042
- detail: unknown | null;
1043
- error: string | null;
1044
- created_at: Generated<Date>;
1045
- }
1046
- type ProvisioningAuditLog = Selectable<ProvisioningAuditLogTable>;
1047
- type InsertProvisioningAuditLog = Insertable<ProvisioningAuditLogTable>;
1048
868
  type Block = Selectable<BlocksTable>;
1049
869
  type InsertBlock = Insertable<BlocksTable>;
1050
870
  type UpdateBlock = Updateable<BlocksTable>;
@@ -1075,29 +895,12 @@ type Account = Selectable<AccountsTable>;
1075
895
  type InsertAccount = Insertable<AccountsTable>;
1076
896
  type MagicLink = Selectable<MagicLinksTable>;
1077
897
  type InsertMagicLink = Insertable<MagicLinksTable>;
1078
- type ClaimToken = Selectable<ClaimTokensTable>;
1079
- type InsertClaimToken = Insertable<ClaimTokensTable>;
1080
898
  type Session = Selectable<SessionsTable>;
1081
899
  type InsertSession = Insertable<SessionsTable>;
1082
- type UsageDaily = Selectable<UsageDailyTable>;
1083
- type UsageSnapshot = Selectable<UsageSnapshotsTable>;
1084
- type AccountInsight = Selectable<AccountInsightsTable>;
1085
- type InsertAccountInsight = Insertable<AccountInsightsTable>;
1086
- type AccountAgentRun = Selectable<AccountAgentRunsTable>;
1087
- type InsertAccountAgentRun = Insertable<AccountAgentRunsTable>;
1088
900
  type SubgraphHealthSnapshot = Selectable<SubgraphHealthSnapshotsTable>;
1089
901
  type InsertSubgraphHealthSnapshot = Insertable<SubgraphHealthSnapshotsTable>;
1090
902
  type SubgraphGap = Selectable<SubgraphGapsTable>;
1091
903
  type InsertSubgraphGap = Insertable<SubgraphGapsTable>;
1092
- type SubgraphUsageDaily = Selectable<SubgraphUsageDailyTable>;
1093
- type InsertSubgraphUsageDaily = Insertable<SubgraphUsageDailyTable>;
1094
- type Project = Selectable<ProjectsTable>;
1095
- type InsertProject = Insertable<ProjectsTable>;
1096
- type UpdateProject = Updateable<ProjectsTable>;
1097
- type TeamMember = Selectable<TeamMembersTable>;
1098
- type InsertTeamMember = Insertable<TeamMembersTable>;
1099
- type TeamInvitation = Selectable<TeamInvitationsTable>;
1100
- type InsertTeamInvitation = Insertable<TeamInvitationsTable>;
1101
904
  type SubscriptionStatus = "active" | "paused" | "error";
1102
905
  /** Polymorphic subscription mode: `subgraph` reacts to processed table rows;
1103
906
  * `chain` reacts to raw chain events matched directly off the Index/Streams
@@ -2118,20 +1921,8 @@ declare const TABLE_TO_DB: {
2118
1921
  api_keys: string
2119
1922
  sessions: string
2120
1923
  magic_links: string
2121
- claim_tokens: string
2122
- usage_daily: string
2123
- usage_snapshots: string
2124
- account_insights: string
2125
- account_agent_runs: string
2126
1924
  account_spend_caps: string
2127
1925
  processed_stripe_events: string
2128
- tenants: string
2129
- tenant_usage_monthly: string
2130
- tenant_compute_addons: string
2131
- provisioning_audit_log: string
2132
- projects: string
2133
- team_members: string
2134
- team_invitations: string
2135
1926
  subscriptions: string
2136
1927
  subscription_outbox: string
2137
1928
  subscription_deliveries: string
@@ -2140,7 +1931,6 @@ declare const TABLE_TO_DB: {
2140
1931
  subgraph_operations: string
2141
1932
  subgraph_health_snapshots: string
2142
1933
  subgraph_gaps: string
2143
- subgraph_usage_daily: string
2144
1934
  subgraph_processing_stats: string
2145
1935
  subgraph_table_snapshots: string
2146
1936
  x402_payments: string
@@ -2217,4 +2007,4 @@ declare function getRawClient(role?: "source" | "target"): ReturnType<typeof pos
2217
2007
  declare function getRawClientFor(url: string): ReturnType<typeof postgres>;
2218
2008
  /** Close all DB connection pools. Call in CLI commands to allow process exit. */
2219
2009
  declare function closeDb(): Promise<void>;
2220
- export { sql, setMigrationRole, parseJsonb, onControlPlane, onChainPlane, jsonb, getTargetDb, getSourceDb, getRawClientFor, getRawClient, getMigrationRole, getDbSplitStatus, getDb, closeDb, assertDbSplit, applicationDatabaseUrl, 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, TABLE_TO_DB, 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, SOURCE_READ_TYPES, SOURCE_READ_PKS, SOURCE_READ_COLUMNS, RunStatus, RetryState, RepairMode, ProvisioningAuditStatus, ProvisioningAuditLogTable, ProvisioningAuditLog, ProvisioningAuditEvent, ProjectsTable, Project, ProcessedStripeEventsTable, Pox5EventsTable, Pox5EventTopic, Pox4SignersDailyTable, Pox4FunctionName, Pox4CyclesDailyTable, Pox4CallsTable, PendingForkBlocksTable, OutboxStatus, ObserverJournalTable, ObserverJournalStatus, NumericAsText, NativeClock, MigrationRole, 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, IndexPrimaryKey, IndexColumnType, IndexColumn, FailureUnit, FailureClass, EventsTable, EventsArchiveTable, Event, DecoderCheckpointsTable, DecodedEventsTable, DeadLetterEventsTable, DbSplitStatus, DbReadRow, DbPlane, 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 };
2010
+ export { sql, setMigrationRole, parseJsonb, onControlPlane, onChainPlane, jsonb, getTargetDb, getSourceDb, getRawClientFor, getRawClient, getMigrationRole, getDbSplitStatus, getDb, closeDb, assertDbSplit, applicationDatabaseUrl, X402PaymentsTable, X402BalancesTable, UpdateTransaction, UpdateSubscriptionOutbox, UpdateSubscription, UpdateSubgraphOperation, UpdateSubgraph, UpdateIndexProgress, UpdateEvent, UpdateContract, UpdateBlock, UpdateApiKey, UpdateAccountSpendCap, UpdateAccountCredits, TriggerEvaluatorStateTable, TriggerEvaluatorState, TransactionsTable, TransactionsArchiveTable, Transaction, TABLE_TO_DB, 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, SOURCE_READ_TYPES, SOURCE_READ_PKS, SOURCE_READ_COLUMNS, RunStatus, RetryState, RepairMode, ProcessedStripeEventsTable, Pox5EventsTable, Pox5EventTopic, Pox4SignersDailyTable, Pox4FunctionName, Pox4CyclesDailyTable, Pox4CallsTable, PendingForkBlocksTable, OutboxStatus, ObserverJournalTable, ObserverJournalStatus, NumericAsText, NativeClock, MigrationRole, 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, IndexPrimaryKey, IndexColumnType, IndexColumn, FailureUnit, FailureClass, EventsTable, EventsArchiveTable, Event, DecoderCheckpointsTable, DecodedEventsTable, DeadLetterEventsTable, DbSplitStatus, DbReadRow, DbPlane, 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 };
@@ -139,14 +139,33 @@ class Logger {
139
139
  var logger = new Logger;
140
140
 
141
141
  // src/mode.ts
142
- var VALID_MODES = ["oss", "platform"];
143
- function getInstanceMode() {
142
+ var VALID_MODES = [
143
+ "oss",
144
+ "platform",
145
+ "archive"
146
+ ];
147
+ function declaredMode() {
144
148
  const raw = process.env.INSTANCE_MODE?.trim().toLowerCase();
145
149
  if (raw && VALID_MODES.includes(raw)) {
146
150
  return raw;
147
151
  }
148
152
  return "oss";
149
153
  }
154
+ function getInstanceMode() {
155
+ const declared = declaredMode();
156
+ return declared === "archive" ? "platform" : declared;
157
+ }
158
+ function getDeclaredInstanceMode() {
159
+ return declaredMode();
160
+ }
161
+ function isMeteredReads() {
162
+ const override = process.env.METERED_READS?.trim().toLowerCase();
163
+ if (override === "true")
164
+ return true;
165
+ if (override === "false")
166
+ return false;
167
+ return getInstanceMode() === "platform";
168
+ }
150
169
  function isPlatformMode() {
151
170
  return getInstanceMode() === "platform";
152
171
  }
@@ -749,20 +768,8 @@ var TABLE_TO_DB = {
749
768
  api_keys: "target",
750
769
  sessions: "target",
751
770
  magic_links: "target",
752
- claim_tokens: "target",
753
- usage_daily: "target",
754
- usage_snapshots: "target",
755
- account_insights: "target",
756
- account_agent_runs: "target",
757
771
  account_spend_caps: "target",
758
772
  processed_stripe_events: "target",
759
- tenants: "target",
760
- tenant_usage_monthly: "target",
761
- tenant_compute_addons: "target",
762
- provisioning_audit_log: "target",
763
- projects: "target",
764
- team_members: "target",
765
- team_invitations: "target",
766
773
  subscriptions: "target",
767
774
  subscription_outbox: "target",
768
775
  subscription_deliveries: "target",
@@ -771,7 +778,6 @@ var TABLE_TO_DB = {
771
778
  subgraph_operations: "target",
772
779
  subgraph_health_snapshots: "target",
773
780
  subgraph_gaps: "target",
774
- subgraph_usage_daily: "target",
775
781
  subgraph_processing_stats: "target",
776
782
  subgraph_table_snapshots: "target",
777
783
  x402_payments: "target",
@@ -979,5 +985,5 @@ export {
979
985
  SOURCE_READ_COLUMNS
980
986
  };
981
987
 
982
- //# debugId=12924C1A09E0071964756E2164756E21
988
+ //# debugId=DD3D0E63F39C5F9D64756E2164756E21
983
989
  //# sourceMappingURL=index.js.map