@secondlayer/subgraphs 3.24.2 → 3.24.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.
@@ -366,6 +366,17 @@ type EventRecord = {
366
366
  };
367
367
  import { Database as Database2 } from "@secondlayer/shared/db";
368
368
  import { Kysely as Kysely2, Transaction } from "kysely";
369
+ /** f072: thrown by `resolveRoute` when a BYO subgraph needs its user-DB
370
+ * connection decrypted but this process holds no `SECONDLAYER_SECRETS_KEY`
371
+ * — the subgraph processor deliberately does not hold the master key (it
372
+ * runs untrusted handler code in-process, every block; see f049 site 3 /
373
+ * the sandbox spike doc's D3). Deny by default, fail loud: this must NEVER
374
+ * be caught and silently rerouted to the managed target DB, since that
375
+ * would write a tenant's rows into ours — far worse than halting the
376
+ * block. */
377
+ declare class ByoKeyUnavailableError extends Error {
378
+ constructor(subgraphName: string);
379
+ }
369
380
  /** Drop a subgraph's cached route — call on redeploy/delete (conn may
370
381
  * change). Also evicts any warm sandbox subprocess for this subgraph
371
382
  * (f071 Stage A `host.ts`) on the same edge: a redeploy can change
@@ -480,4 +491,4 @@ declare const BLOCK_RETRY_DELAYS_MS: number[];
480
491
  */
481
492
  declare function processBlockWithRetry(subgraph: SubgraphDefinition, subgraphName: string, blockHeight: number, opts?: ProcessBlockOptions, retryDelaysMs?: number[]): Promise<ProcessBlockResult>;
482
493
  declare function processBlock(subgraph: SubgraphDefinition, subgraphName: string, blockHeight: number, opts?: ProcessBlockOptions): Promise<ProcessBlockResult>;
483
- export { resolveFactoryContracts, processBlockWithRetry, processBlock, invalidateSubgraphRoute, ProcessBlockTiming, ProcessBlockResult, ProcessBlockOptions, PreloadedBlockData, BLOCK_RETRY_DELAYS_MS };
494
+ export { resolveFactoryContracts, processBlockWithRetry, processBlock, invalidateSubgraphRoute, ProcessBlockTiming, ProcessBlockResult, ProcessBlockOptions, PreloadedBlockData, ByoKeyUnavailableError, BLOCK_RETRY_DELAYS_MS };
@@ -1627,6 +1627,7 @@ function matchSources(sources, transactions, events, traitContracts = new Map, f
1627
1627
  }
1628
1628
 
1629
1629
  // src/runtime/block-processor.ts
1630
+ import { secretsKeyAvailable } from "@secondlayer/shared/crypto/secrets";
1630
1631
  import { getTargetDb } from "@secondlayer/shared/db";
1631
1632
  import { resolveTraitContractIds } from "@secondlayer/shared/db/queries/contracts";
1632
1633
  import { advanceOperationCursor } from "@secondlayer/shared/db/queries/subgraph-operations";
@@ -2564,12 +2565,22 @@ async function refreshMatcher(db) {
2564
2565
 
2565
2566
  // src/runtime/block-processor.ts
2566
2567
  var routeCache = new Map;
2568
+
2569
+ class ByoKeyUnavailableError extends Error {
2570
+ constructor(subgraphName) {
2571
+ super(`subgraph ${subgraphName} is BYO (database_url_enc set) but this process has no SECONDLAYER_SECRETS_KEY — the subgraph processor deliberately does not hold it (f072). Route BYO subgraphs to a process that does, or unset BYO.`);
2572
+ this.name = "ByoKeyUnavailableError";
2573
+ }
2574
+ }
2567
2575
  async function resolveRoute(subgraphName, targetDb) {
2568
2576
  const cached = routeCache.get(subgraphName);
2569
2577
  if (cached)
2570
2578
  return cached;
2571
2579
  const row = await targetDb.selectFrom("subgraphs").selectAll().where("name", "=", subgraphName).executeTakeFirst();
2572
2580
  const byo = row ? isByoSubgraph(row) : false;
2581
+ if (row && byo && !secretsKeyAvailable()) {
2582
+ throw new ByoKeyUnavailableError(subgraphName);
2583
+ }
2573
2584
  const route = {
2574
2585
  schemaName: row?.schema_name ?? pgSchemaName(subgraphName),
2575
2586
  dataDb: row && byo ? resolveSubgraphDb(row) : targetDb,
@@ -2942,8 +2953,9 @@ export {
2942
2953
  processBlockWithRetry,
2943
2954
  processBlock,
2944
2955
  invalidateSubgraphRoute,
2956
+ ByoKeyUnavailableError,
2945
2957
  BLOCK_RETRY_DELAYS_MS
2946
2958
  };
2947
2959
 
2948
- //# debugId=7DCA5B46BE5FE59C64756E2164756E21
2960
+ //# debugId=B97EC9302707D2CA64756E2164756E21
2949
2961
  //# sourceMappingURL=block-processor.js.map