@substrat-run/control-plane-api 0.146.0 → 0.148.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 (69) hide show
  1. package/dist/api.d.ts +69 -1
  2. package/dist/api.d.ts.map +1 -1
  3. package/dist/api.js +986 -383
  4. package/dist/api.js.map +1 -1
  5. package/dist/browser.d.ts +1 -1
  6. package/dist/browser.d.ts.map +1 -1
  7. package/dist/browser.js.map +1 -1
  8. package/dist/deploy.d.ts +46 -0
  9. package/dist/deploy.d.ts.map +1 -1
  10. package/dist/deploy.js +53 -1
  11. package/dist/deploy.js.map +1 -1
  12. package/dist/errors.d.ts +19 -1
  13. package/dist/errors.d.ts.map +1 -1
  14. package/dist/errors.js +18 -4
  15. package/dist/errors.js.map +1 -1
  16. package/dist/index.d.ts +10 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +6 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/lake-gateway.d.ts +54 -0
  21. package/dist/lake-gateway.d.ts.map +1 -0
  22. package/dist/lake-gateway.js +158 -0
  23. package/dist/lake-gateway.js.map +1 -0
  24. package/dist/platform-entry.d.ts +23 -1
  25. package/dist/platform-entry.d.ts.map +1 -1
  26. package/dist/platform-entry.generated.d.ts +9 -1
  27. package/dist/platform-entry.generated.d.ts.map +1 -1
  28. package/dist/platform-entry.generated.js +10 -2
  29. package/dist/platform-entry.generated.js.map +1 -1
  30. package/dist/platform-entry.js +31 -1
  31. package/dist/platform-entry.js.map +1 -1
  32. package/dist/platform-scope-stores.d.ts +151 -0
  33. package/dist/platform-scope-stores.d.ts.map +1 -0
  34. package/dist/platform-scope-stores.js +241 -0
  35. package/dist/platform-scope-stores.js.map +1 -0
  36. package/dist/r2-sql-engine.d.ts +50 -0
  37. package/dist/r2-sql-engine.d.ts.map +1 -0
  38. package/dist/r2-sql-engine.js +126 -0
  39. package/dist/r2-sql-engine.js.map +1 -0
  40. package/dist/scope-copy-cleanup.d.ts +12 -0
  41. package/dist/scope-copy-cleanup.d.ts.map +1 -1
  42. package/dist/scope-copy-cleanup.js +14 -3
  43. package/dist/scope-copy-cleanup.js.map +1 -1
  44. package/dist/staff-client.d.ts +9 -1
  45. package/dist/staff-client.d.ts.map +1 -1
  46. package/dist/staff-client.js.map +1 -1
  47. package/dist/store-entry.d.ts +90 -0
  48. package/dist/store-entry.d.ts.map +1 -0
  49. package/dist/store-entry.generated.d.ts +60 -0
  50. package/dist/store-entry.generated.d.ts.map +1 -0
  51. package/dist/store-entry.generated.js +62 -0
  52. package/dist/store-entry.generated.js.map +1 -0
  53. package/dist/store-entry.js +178 -0
  54. package/dist/store-entry.js.map +1 -0
  55. package/dist/store-releases.d.ts +147 -0
  56. package/dist/store-releases.d.ts.map +1 -0
  57. package/dist/store-releases.js +298 -0
  58. package/dist/store-releases.js.map +1 -0
  59. package/dist/store-script.d.ts +80 -0
  60. package/dist/store-script.d.ts.map +1 -0
  61. package/dist/store-script.js +173 -0
  62. package/dist/store-script.js.map +1 -0
  63. package/dist/vertical-client.d.ts +19 -2
  64. package/dist/vertical-client.d.ts.map +1 -1
  65. package/dist/vertical-client.js +10 -1
  66. package/dist/vertical-client.js.map +1 -1
  67. package/dist/wfp.js +1 -1
  68. package/dist/wfp.js.map +1 -1
  69. package/package.json +7 -6
@@ -84,6 +84,28 @@ declared: {
84
84
  * and a later upload never re-declares one that is already live.
85
85
  */
86
86
  export declare function deployedDoClasses(doClasses: readonly string[], supplySweeper: boolean | undefined): string[];
87
+ /** The flag that gives a script `node:async_hooks` and nothing else of node (#2245). */
88
+ export declare const ASYNC_LOCAL_STORAGE_FLAG = "nodejs_als";
89
+ /**
90
+ * The compatibility flags a wrapped script is uploaded with, and whether the platform entry
91
+ * may import `AsyncLocalStorage` (#2245, RFC §6: the request runs in one, so its store calls
92
+ * reach its line). The entry imports `node:async_hooks`, which workerd allows only under
93
+ * `nodejs_als` or `nodejs_compat`:
94
+ *
95
+ * - either flag already there: the flags go up exactly as declared;
96
+ * - neither: `nodejs_als` is appended, after the declared ones. It has no compatibility-date
97
+ * gate, and it adds `node:async_hooks` alone — no other node module, no globals;
98
+ * - the script opts out with `no_nodejs_als`: the flags go up as declared and the entry drops
99
+ * its import, so the upload never fails over it. With `nodejs_compat` beside the opt-out,
100
+ * vertical-host still reaches `AsyncLocalStorage` through `process.getBuiltinModule` and the
101
+ * line names the calls; with no `nodejs_compat` either, the line names no store calls.
102
+ *
103
+ * Existing flags are never removed or reordered.
104
+ */
105
+ export declare function platformEntryFlags(declared: readonly string[] | undefined): {
106
+ flags: string[];
107
+ asyncLocalStorage: boolean;
108
+ };
87
109
  /**
88
110
  * The bundle as uploaded: the platform's entry module added (or refreshed) and named as
89
111
  * the script's main module, importing the vertical's own entry — and, when the version's
@@ -94,5 +116,5 @@ export declare function deployedDoClasses(doClasses: readonly string[], supplySw
94
116
  * bundle the platform cannot or need not wrap comes back unchanged, apart from dropping stale
95
117
  * platform modules it can no longer reach.
96
118
  */
97
- export declare function withPlatformEntry<B extends Pick<VerticalBundle, 'entry' | 'modules'> & Partial<Pick<VerticalBundle, 'doClasses' | 'bindings' | 'supplySweeper'>>>(bundle: B): B;
119
+ export declare function withPlatformEntry<B extends Pick<VerticalBundle, 'entry' | 'modules'> & Partial<Pick<VerticalBundle, 'doClasses' | 'bindings' | 'supplySweeper' | 'compatibilityFlags'>>>(bundle: B): B;
98
120
  //# sourceMappingURL=platform-entry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"platform-entry.d.ts","sourceRoot":"","sources":["../src/platform-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,OAAO,EAML,KAAK,cAAc,EACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EACL,qBAAqB,EAGrB,uBAAuB,EAExB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,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C,CAkCd"}
@@ -7,8 +7,16 @@
7
7
  export declare const PLATFORM_ENTRY_MODULE = "substrat-platform-entry.js";
8
8
  /** The import specifier the uploader replaces with `./<the bundle's entry>`. */
9
9
  export declare const PLATFORM_ENTRY_PLACEHOLDER = "__SUBSTRAT_VERTICAL_ENTRY__";
10
- /** The entry itself — 10668 bytes of ESM. */
10
+ /** The entry itself — 12959 bytes of ESM. */
11
11
  export declare const PLATFORM_ENTRY_SOURCE: string;
12
+ /**
13
+ * #2245: the entry's `node:async_hooks` import, as it appears in `PLATFORM_ENTRY_SOURCE`, and
14
+ * the line the uploader puts in its place for a script that can have no `AsyncLocalStorage`
15
+ * (one that opts out with `no_nodejs_als`). With no `nodejs_compat` either, that script's line names
16
+ * no store calls; with it, vertical-host reaches the class through `process.getBuiltinModule`.
17
+ */
18
+ export declare const PLATFORM_ENTRY_ALS_IMPORT = "import { AsyncLocalStorage } from \"node:async_hooks\";";
19
+ export declare const PLATFORM_ENTRY_ALS_FALLBACK = "const AsyncLocalStorage = undefined;";
12
20
  /**
13
21
  * The scope sweeper the platform supplies (#1902) — uploaded beside the entry, which
14
22
  * re-exports its class, when a vertical declares schedules and brings no sweeper of its own.
@@ -1 +1 @@
1
- {"version":3,"file":"platform-entry.generated.d.ts","sourceRoot":"","sources":["../src/platform-entry.generated.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,+BAA+B,CAAC;AAElE,gFAAgF;AAChF,eAAO,MAAM,0BAA0B,gCAAgC,CAAC;AAExE,6CAA6C;AAC7C,eAAO,MAAM,qBAAqB,EAAE,MAA02V,CAAC;AAE/4V;;;GAGG;AACH,eAAO,MAAM,uBAAuB,iCAAiC,CAAC;AAEtE,8CAA8C;AAC9C,eAAO,MAAM,uBAAuB,EAAE,MAA60T,CAAC"}
1
+ {"version":3,"file":"platform-entry.generated.d.ts","sourceRoot":"","sources":["../src/platform-entry.generated.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,+BAA+B,CAAC;AAElE,gFAAgF;AAChF,eAAO,MAAM,0BAA0B,gCAAgC,CAAC;AAExE,6CAA6C;AAC7C,eAAO,MAAM,qBAAqB,EAAE,MAA0qa,CAAC;AAE/sa;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,4DAA4D,CAAC;AACnG,eAAO,MAAM,2BAA2B,yCAAyC,CAAC;AAElF;;;GAGG;AACH,eAAO,MAAM,uBAAuB,iCAAiC,CAAC;AAEtE,8CAA8C;AAC9C,eAAO,MAAM,uBAAuB,EAAE,MAA60T,CAAC"}
@@ -9,8 +9,16 @@
9
9
  export const PLATFORM_ENTRY_MODULE = 'substrat-platform-entry.js';
10
10
  /** The import specifier the uploader replaces with `./<the bundle's entry>`. */
11
11
  export const PLATFORM_ENTRY_PLACEHOLDER = '__SUBSTRAT_VERTICAL_ENTRY__';
12
- /** The entry itself — 10668 bytes of ESM. */
13
- export const PLATFORM_ENTRY_SOURCE = "// packages/contracts/dist/invocation-record.js\nvar INVOCATION_RECORD_HEADER = \"x-substrat-invocation-record\";\nvar REQUEST_ID_HEADER = \"x-substrat-request-id\";\nvar INVOCATION_RECORD_FIELD_MAX = 128;\nvar FIELDS = [\"operation\", \"problemCode\", \"principalKind\"];\nfunction encodeInvocationRecord(record) {\n const params = new URLSearchParams();\n for (const key of FIELDS) {\n const v = record[key];\n if (typeof v === \"string\" && v !== \"\")\n params.set(key, v.slice(0, INVOCATION_RECORD_FIELD_MAX));\n }\n const value = params.toString();\n return value === \"\" ? null : value;\n}\nvar FIELD_COVERAGE_HEADER = \"x-substrat-field-coverage\";\nfunction invocationLevelOf(status, threw, problemCode) {\n if (threw || status === null || status >= 500)\n return \"error\";\n if (status >= 400)\n return \"warn\";\n if (problemCode)\n return \"warn\";\n return \"info\";\n}\n\n// packages/kernel/dist/invocation-line.js\nfunction invocationLine(f) {\n const emitted = f.emitted;\n return {\n substrat: \"invocation\",\n ...f.kind ? { kind: f.kind } : {},\n tenantId: f.tenantId,\n scopeId: f.scopeId,\n vertical: f.vertical ?? null,\n surface: f.surface ?? null,\n method: f.method ?? null,\n path: f.path ?? null,\n status: f.status ?? null,\n threw: f.threw,\n durationMs: f.durationMs,\n invocationId: f.invocationId,\n level: f.level,\n operation: f.operation ?? null,\n problemCode: f.problemCode ?? null,\n principalKind: f.principalKind ?? null,\n eventCount: emitted ? emitted.total : null,\n eventTypes: emitted ? distinct(emitted.events.map((e) => e.type)) : [],\n entities: emitted && f.withEntities !== false ? distinct(emitted.events.map((e) => e.entity)) : [],\n versionId: f.versionId ?? null,\n ...f.outputFields ? { outputFields: f.outputFields, ...f.fieldCoverageId ? { fieldCoverageId: f.fieldCoverageId } : {} } : {},\n ...f.async ?? {}\n };\n}\nfunction distinct(values) {\n return [...new Set(values)];\n}\n\n// packages/kernel/dist/ulid.js\nvar B32 = \"0123456789ABCDEFGHJKMNPQRSTVWXYZ\";\nvar MAX_ULID_TIME = 2 ** 48 - 1;\nvar ULID_SHAPE = /^[0-9A-HJKMNP-TV-Z]{26}$/;\nvar unencodable = (t) => `not an encodable ULID instant: ${t} (want 0..${MAX_ULID_TIME})`;\nfunction encodeTime(time) {\n let ts = \"\";\n let t = time;\n for (let i = 0; i < 10; i++) {\n ts = B32[t % 32] + ts;\n t = Math.floor(t / 32);\n }\n return ts;\n}\nfunction createUlid() {\n let lastTime = -1;\n const lastRand = new Array(16).fill(0);\n function freshRandom() {\n const bytes = crypto.getRandomValues(new Uint8Array(16));\n for (let i = 0; i < 16; i++)\n lastRand[i] = bytes[i] % 32;\n }\n function incrementRandom() {\n for (let i = 15; i >= 0; i--) {\n if (lastRand[i] < 31) {\n lastRand[i]++;\n return true;\n }\n lastRand[i] = 0;\n }\n return false;\n }\n const mint = ((now = Date.now()) => {\n if (!Number.isSafeInteger(now))\n throw new RangeError(unencodable(now));\n let time = now;\n if (time <= lastTime) {\n time = lastTime;\n if (!incrementRandom()) {\n time = lastTime + 1;\n freshRandom();\n }\n } else {\n freshRandom();\n }\n if (time < 0 || time > MAX_ULID_TIME)\n throw new RangeError(unencodable(time));\n lastTime = time;\n let r = \"\";\n for (const d of lastRand)\n r += B32[d];\n return encodeTime(time) + r;\n });\n mint.seedFrom = (id) => {\n const time = ulidTime(id);\n if (time < lastTime)\n return;\n const rand = [];\n for (const ch of id.slice(10))\n rand.push(B32.indexOf(ch));\n if (time === lastTime) {\n let ahead = false;\n for (let i = 0; i < 16; i++) {\n if (rand[i] !== lastRand[i]) {\n ahead = rand[i] > lastRand[i];\n break;\n }\n }\n if (!ahead)\n return;\n }\n lastTime = time;\n for (let i = 0; i < 16; i++)\n lastRand[i] = rand[i];\n };\n return mint;\n}\nvar processUlid = createUlid();\nfunction ulid(now = Date.now()) {\n return processUlid(now);\n}\nfunction ulidTime(id) {\n if (!ULID_SHAPE.test(id))\n throw new Error(`not a ULID: ${id}`);\n let t = 0;\n for (const ch of id.slice(0, 10))\n t = t * 32 + B32.indexOf(ch);\n if (t > MAX_ULID_TIME)\n throw new Error(`not a ULID: ${id}`);\n return t;\n}\n\n// packages/contracts/dist/wire-auth.js\nfunction secretMatches(presented, expected) {\n const given = presented ?? \"\";\n let diff = given.length ^ expected.length | (given.length === 0 ? 1 : 0);\n for (let i = 0; i < expected.length; i++) {\n diff |= (i < given.length ? given.charCodeAt(i) : 0) ^ expected.charCodeAt(i);\n }\n return diff === 0;\n}\n\n// packages/vertical-host/src/routed-node.ts\nvar ROUTED_ID = /^[0-9A-HJKMNP-TV-Z]{26}$/;\nvar RouterAssertionError = class extends Error {\n};\nfunction readRoutedNode(headers, options = {}) {\n const rawTenant = headers.get(\"x-substrat-tenant\");\n const rawScope = headers.get(\"x-substrat-scope\");\n if (!rawTenant && !rawScope) return null;\n const { expectedSecret, allowUnsigned = false } = options;\n if (expectedSecret) {\n if (!secretMatches(headers.get(\"x-substrat-router\"), expectedSecret)) {\n throw new RouterAssertionError(\"router assertion is not signed by a known router\");\n }\n } else if (!allowUnsigned) {\n throw new RouterAssertionError(\n \"router assertion cannot be verified: this worker has no ROUTER_SECRET configured\"\n );\n }\n if (!rawTenant || !rawScope) {\n throw new RouterAssertionError(\"router assertion is incomplete\");\n }\n if (!ROUTED_ID.test(rawTenant) || !ROUTED_ID.test(rawScope)) {\n throw new RouterAssertionError(\"router assertion carries a malformed id\");\n }\n return {\n tenantId: rawTenant,\n scopeId: rawScope,\n surface: headers.get(\"x-substrat-surface\") ?? \"app\",\n verticalSlug: headers.get(\"x-substrat-vertical\")\n };\n}\n\n// packages/vertical-host/src/invocation-log.ts\nfunction versionIdOf(env) {\n const v = env?.SUBSTRAT_VERSION_ID;\n return typeof v === \"string\" && v.length > 0 ? v : null;\n}\nfunction pathOf(url) {\n try {\n return new URL(url).pathname;\n } catch {\n return \"/\";\n }\n}\nvar STAMPS = /* @__PURE__ */ Symbol.for(\"substrat.invocation-stamp\");\nfunction stamps() {\n const g = globalThis;\n return g[STAMPS] ??= /* @__PURE__ */ new WeakMap();\n}\nfunction invocationStampOf(request) {\n return stamps().get(request);\n}\nfunction withRequestId(response, id) {\n const headers = response?.headers;\n try {\n headers?.set?.(REQUEST_ID_HEADER, id);\n return response;\n } catch {\n }\n try {\n const r = response;\n if (r.status === 101) return response;\n const copy = new Response(r.body, r);\n copy.headers.set(REQUEST_ID_HEADER, id);\n return copy;\n } catch {\n return response;\n }\n}\nfunction beginStamp(request, env, options) {\n const stamp = { invocationId: ulid(), record: {} };\n const fieldCoverageId = armedFieldCoverageId(request.headers, env, options);\n if (fieldCoverageId) stamp.fieldCoverageId = fieldCoverageId;\n stamps().set(request, stamp);\n return stamp;\n}\nfunction armedFieldCoverageId(headers, env, options) {\n let id;\n try {\n id = headers.get(FIELD_COVERAGE_HEADER);\n } catch {\n return void 0;\n }\n if (id === null || !ROUTED_ID.test(id)) return void 0;\n return routedNodeOrNull(headers, env, options) !== null ? id : void 0;\n}\nfunction writeInvocationLine(stamp, done, options) {\n try {\n writeLineOrThrow(stamp, done, options);\n } catch (e) {\n try {\n console.log(JSON.stringify({ substrat: \"invocation-log-fault\", detail: String(e) }));\n } catch {\n }\n }\n}\nfunction writeLineOrThrow(stamp, done, options) {\n const node = routedNodeOrNull(done.request.headers, done.env, options);\n if (!node) return;\n const { record, invocationId } = stamp;\n const line = invocationLine({\n tenantId: node.tenantId,\n scopeId: node.scopeId,\n vertical: node.verticalSlug,\n surface: node.surface,\n method: done.request.method,\n path: pathOf(done.request.url),\n status: done.status,\n threw: done.threw,\n durationMs: Date.now() - done.started,\n invocationId,\n level: invocationLevelOf(done.status, done.threw, record.problemCode),\n operation: record.operation,\n problemCode: record.problemCode,\n principalKind: record.principalKind,\n ...record.emitted ? { emitted: record.emitted } : {},\n versionId: versionIdOf(done.env),\n ...record.outputFields ? { outputFields: record.outputFields } : {},\n ...stamp.fieldCoverageId ? { fieldCoverageId: stamp.fieldCoverageId } : {}\n });\n console.log(JSON.stringify(line));\n}\nvar OTHER_HANDLERS = [\"scheduled\", \"queue\", \"email\", \"tail\", \"trace\", \"alarm\", \"test\"];\nfunction withInvocationLog(worker, options = {}) {\n const inner = worker?.fetch;\n if (typeof inner !== \"function\") return worker;\n const wrapped = {\n async fetch(request, env, ctx) {\n if (invocationStampOf(request)) return inner.call(worker, request, env, ctx);\n const started = Date.now();\n const stamp = beginStamp(request, env, options);\n let status = null;\n let threw = false;\n try {\n const response = withRequestId(await inner.call(worker, request, env, ctx), stamp.invocationId);\n status = response.status;\n handRecordToRouter(response, stamp.record, request, env, options);\n return response;\n } catch (e) {\n threw = true;\n throw e;\n } finally {\n writeInvocationLine(stamp, { request, env, status, threw, started }, options);\n }\n }\n };\n for (const name of OTHER_HANDLERS) {\n const h = worker[name];\n if (typeof h === \"function\") wrapped[name] = h.bind(worker);\n }\n return wrapped;\n}\nfunction handRecordToRouter(response, record, request, env, options) {\n try {\n const value = encodeInvocationRecord(record);\n if (value === null || !routedNodeOrNull(request.headers, env, options)) return;\n response.headers?.set?.(\n INVOCATION_RECORD_HEADER,\n value\n );\n } catch {\n }\n}\nfunction routedNodeOrNull(headers, env, options) {\n try {\n return readRoutedNode(headers, {\n expectedSecret: options.routerSecret?.(env),\n allowUnsigned: options.allowUnsigned?.(env) ?? false\n });\n } catch (e) {\n if (!(e instanceof RouterAssertionError)) console.log(JSON.stringify({ substrat: \"invocation-log-fault\", detail: String(e) }));\n return null;\n }\n}\n\n// substrat-platform-entry.ts\nimport * as vertical from \"__SUBSTRAT_VERTICAL_ENTRY__\";\nexport * from \"__SUBSTRAT_VERTICAL_ENTRY__\";\nvar substrat_platform_entry_default = withInvocationLog(vertical.default, {\n routerSecret: (env) => env.ROUTER_SECRET,\n allowUnsigned: (env) => env.ALLOW_DEV_NODE === \"true\"\n});\nexport {\n substrat_platform_entry_default as default\n};\n";
12
+ /** The entry itself — 12959 bytes of ESM. */
13
+ export const PLATFORM_ENTRY_SOURCE = "// substrat-platform-entry.ts\nimport { AsyncLocalStorage } from \"node:async_hooks\";\n\n// packages/contracts/dist/invocation-record.js\nvar INVOCATION_RECORD_HEADER = \"x-substrat-invocation-record\";\nvar REQUEST_ID_HEADER = \"x-substrat-request-id\";\nvar INVOCATION_RECORD_FIELD_MAX = 128;\nvar FIELDS = [\"operation\", \"problemCode\", \"principalKind\"];\nfunction encodeInvocationRecord(record) {\n const params = new URLSearchParams();\n for (const key of FIELDS) {\n const v = record[key];\n if (typeof v === \"string\" && v !== \"\")\n params.set(key, v.slice(0, INVOCATION_RECORD_FIELD_MAX));\n }\n const value = params.toString();\n return value === \"\" ? null : value;\n}\nvar FIELD_COVERAGE_HEADER = \"x-substrat-field-coverage\";\nfunction invocationLevelOf(status, threw, problemCode) {\n if (threw || status === null || status >= 500)\n return \"error\";\n if (status >= 400)\n return \"warn\";\n if (problemCode)\n return \"warn\";\n return \"info\";\n}\n\n// packages/kernel/dist/invocation-line.js\nfunction invocationLine(f) {\n const emitted = f.emitted;\n return {\n substrat: \"invocation\",\n ...f.kind ? { kind: f.kind } : {},\n tenantId: f.tenantId,\n scopeId: f.scopeId,\n vertical: f.vertical ?? null,\n surface: f.surface ?? null,\n method: f.method ?? null,\n path: f.path ?? null,\n status: f.status ?? null,\n threw: f.threw,\n durationMs: f.durationMs,\n invocationId: f.invocationId,\n level: f.level,\n operation: f.operation ?? null,\n problemCode: f.problemCode ?? null,\n principalKind: f.principalKind ?? null,\n eventCount: emitted ? emitted.total : null,\n eventTypes: emitted ? distinct(emitted.events.map((e) => e.type)) : [],\n entities: emitted && f.withEntities !== false ? distinct(emitted.events.map((e) => e.entity)) : [],\n versionId: f.versionId ?? null,\n ...f.outputFields ? { outputFields: f.outputFields, ...f.fieldCoverageId ? { fieldCoverageId: f.fieldCoverageId } : {} } : {},\n ...f.storeCalls && f.storeCalls.length > 0 ? { storeCalls: f.storeCalls } : {},\n ...f.storeCallsDropped ? { storeCallsDropped: f.storeCallsDropped } : {},\n ...f.async ?? {}\n };\n}\nvar STORE_CALL_LOG_CAP = 16;\nfunction tallyStoreCall(tally, call) {\n const calls = tally.storeCalls ?? (tally.storeCalls = []);\n if (calls.length < STORE_CALL_LOG_CAP) {\n calls.push({ binding: call.binding, operation: call.operation, outcome: call.outcome, durationMs: call.durationMs });\n } else {\n tally.storeCallsDropped = (tally.storeCallsDropped ?? 0) + 1;\n }\n}\nvar STORE_CALL_SINK_KEY = \"substrat.store-call-sink\";\nfunction distinct(values) {\n return [...new Set(values)];\n}\n\n// packages/kernel/dist/ulid.js\nvar B32 = \"0123456789ABCDEFGHJKMNPQRSTVWXYZ\";\nvar MAX_ULID_TIME = 2 ** 48 - 1;\nvar ULID_SHAPE = /^[0-9A-HJKMNP-TV-Z]{26}$/;\nvar unencodable = (t) => `not an encodable ULID instant: ${t} (want 0..${MAX_ULID_TIME})`;\nfunction encodeTime(time) {\n let ts = \"\";\n let t = time;\n for (let i = 0; i < 10; i++) {\n ts = B32[t % 32] + ts;\n t = Math.floor(t / 32);\n }\n return ts;\n}\nfunction createUlid() {\n let lastTime = -1;\n const lastRand = new Array(16).fill(0);\n function freshRandom() {\n const bytes = crypto.getRandomValues(new Uint8Array(16));\n for (let i = 0; i < 16; i++)\n lastRand[i] = bytes[i] % 32;\n }\n function incrementRandom() {\n for (let i = 15; i >= 0; i--) {\n if (lastRand[i] < 31) {\n lastRand[i]++;\n return true;\n }\n lastRand[i] = 0;\n }\n return false;\n }\n const mint = ((now = Date.now()) => {\n if (!Number.isSafeInteger(now))\n throw new RangeError(unencodable(now));\n let time = now;\n if (time <= lastTime) {\n time = lastTime;\n if (!incrementRandom()) {\n time = lastTime + 1;\n freshRandom();\n }\n } else {\n freshRandom();\n }\n if (time < 0 || time > MAX_ULID_TIME)\n throw new RangeError(unencodable(time));\n lastTime = time;\n let r = \"\";\n for (const d of lastRand)\n r += B32[d];\n return encodeTime(time) + r;\n });\n mint.seedFrom = (id) => {\n const time = ulidTime(id);\n if (time < lastTime)\n return;\n const rand = [];\n for (const ch of id.slice(10))\n rand.push(B32.indexOf(ch));\n if (time === lastTime) {\n let ahead = false;\n for (let i = 0; i < 16; i++) {\n if (rand[i] !== lastRand[i]) {\n ahead = rand[i] > lastRand[i];\n break;\n }\n }\n if (!ahead)\n return;\n }\n lastTime = time;\n for (let i = 0; i < 16; i++)\n lastRand[i] = rand[i];\n };\n return mint;\n}\nvar processUlid = createUlid();\nfunction ulid(now = Date.now()) {\n return processUlid(now);\n}\nfunction ulidTime(id) {\n if (!ULID_SHAPE.test(id))\n throw new Error(`not a ULID: ${id}`);\n let t = 0;\n for (const ch of id.slice(0, 10))\n t = t * 32 + B32.indexOf(ch);\n if (t > MAX_ULID_TIME)\n throw new Error(`not a ULID: ${id}`);\n return t;\n}\n\n// packages/contracts/dist/wire-auth.js\nfunction secretMatches(presented, expected) {\n const given = presented ?? \"\";\n let diff = given.length ^ expected.length | (given.length === 0 ? 1 : 0);\n for (let i = 0; i < expected.length; i++) {\n diff |= (i < given.length ? given.charCodeAt(i) : 0) ^ expected.charCodeAt(i);\n }\n return diff === 0;\n}\n\n// packages/vertical-host/src/routed-node.ts\nvar ROUTED_ID = /^[0-9A-HJKMNP-TV-Z]{26}$/;\nvar RouterAssertionError = class extends Error {\n};\nfunction readRoutedNode(headers, options = {}) {\n const rawTenant = headers.get(\"x-substrat-tenant\");\n const rawScope = headers.get(\"x-substrat-scope\");\n if (!rawTenant && !rawScope) return null;\n const { expectedSecret, allowUnsigned = false } = options;\n if (expectedSecret) {\n if (!secretMatches(headers.get(\"x-substrat-router\"), expectedSecret)) {\n throw new RouterAssertionError(\"router assertion is not signed by a known router\");\n }\n } else if (!allowUnsigned) {\n throw new RouterAssertionError(\n \"router assertion cannot be verified: this worker has no ROUTER_SECRET configured\"\n );\n }\n if (!rawTenant || !rawScope) {\n throw new RouterAssertionError(\"router assertion is incomplete\");\n }\n if (!ROUTED_ID.test(rawTenant) || !ROUTED_ID.test(rawScope)) {\n throw new RouterAssertionError(\"router assertion carries a malformed id\");\n }\n return {\n tenantId: rawTenant,\n scopeId: rawScope,\n surface: headers.get(\"x-substrat-surface\") ?? \"app\",\n verticalSlug: headers.get(\"x-substrat-vertical\")\n };\n}\n\n// packages/vertical-host/src/invocation-log.ts\nfunction builtinAsyncLocalStorage() {\n try {\n const proc = globalThis.process;\n const mod = proc?.getBuiltinModule?.(\"node:async_hooks\");\n return typeof mod?.AsyncLocalStorage === \"function\" ? mod.AsyncLocalStorage : void 0;\n } catch {\n return void 0;\n }\n}\nfunction storeCallSlot(provided) {\n try {\n const g = globalThis;\n const key = Symbol.for(STORE_CALL_SINK_KEY);\n const existing = g[key];\n if (typeof existing?.run === \"function\" && typeof existing.current === \"function\") return existing;\n const Als = provided ?? builtinAsyncLocalStorage();\n if (!Als) return void 0;\n const storage = new Als();\n const slot = {\n current() {\n const tally = storage.getStore();\n return tally ? (call) => tallyStoreCall(tally, call) : void 0;\n },\n run: (tally, fn) => storage.run(tally, fn)\n };\n g[key] = slot;\n return slot;\n } catch {\n return void 0;\n }\n}\nfunction runRecordingStoreCalls(record, provided, fn) {\n const slot = storeCallSlot(provided);\n return slot ? slot.run(record, fn) : fn();\n}\nfunction versionIdOf(env) {\n const v = env?.SUBSTRAT_VERSION_ID;\n return typeof v === \"string\" && v.length > 0 ? v : null;\n}\nvar UPLOAD_LINK_SECRET_SEGMENT = /^(\\/api\\/attachment-uploads\\/[^/]+\\/[^/]+\\/)[^/]+/;\nvar redactUploadLinkSecret = (pathname) => pathname.replace(UPLOAD_LINK_SECRET_SEGMENT, \"$1[redacted]\");\nfunction pathOf(url) {\n try {\n return redactUploadLinkSecret(new URL(url).pathname);\n } catch {\n return \"/\";\n }\n}\nvar STAMPS = /* @__PURE__ */ Symbol.for(\"substrat.invocation-stamp\");\nfunction stamps() {\n const g = globalThis;\n return g[STAMPS] ??= /* @__PURE__ */ new WeakMap();\n}\nfunction invocationStampOf(request) {\n return stamps().get(request);\n}\nfunction withRequestId(response, id) {\n const headers = response?.headers;\n try {\n headers?.set?.(REQUEST_ID_HEADER, id);\n return response;\n } catch {\n }\n try {\n const r = response;\n if (r.status === 101) return response;\n const copy = new Response(r.body, r);\n copy.headers.set(REQUEST_ID_HEADER, id);\n return copy;\n } catch {\n return response;\n }\n}\nfunction beginStamp(request, env, options) {\n const stamp = { invocationId: ulid(), record: {} };\n const fieldCoverageId = armedFieldCoverageId(request.headers, env, options);\n if (fieldCoverageId) stamp.fieldCoverageId = fieldCoverageId;\n stamps().set(request, stamp);\n return stamp;\n}\nfunction armedFieldCoverageId(headers, env, options) {\n let id;\n try {\n id = headers.get(FIELD_COVERAGE_HEADER);\n } catch {\n return void 0;\n }\n if (id === null || !ROUTED_ID.test(id)) return void 0;\n return routedNodeOrNull(headers, env, options) !== null ? id : void 0;\n}\nfunction writeInvocationLine(stamp, done, options) {\n try {\n writeLineOrThrow(stamp, done, options);\n } catch (e) {\n try {\n console.log(JSON.stringify({ substrat: \"invocation-log-fault\", detail: String(e) }));\n } catch {\n }\n }\n}\nfunction writeLineOrThrow(stamp, done, options) {\n const node = routedNodeOrNull(done.request.headers, done.env, options);\n if (!node) return;\n const { record, invocationId } = stamp;\n const line = invocationLine({\n tenantId: node.tenantId,\n scopeId: node.scopeId,\n vertical: node.verticalSlug,\n surface: node.surface,\n method: done.request.method,\n path: pathOf(done.request.url),\n status: done.status,\n threw: done.threw,\n durationMs: Date.now() - done.started,\n invocationId,\n level: invocationLevelOf(done.status, done.threw, record.problemCode),\n operation: record.operation,\n problemCode: record.problemCode,\n principalKind: record.principalKind,\n ...record.emitted ? { emitted: record.emitted } : {},\n versionId: versionIdOf(done.env),\n ...record.outputFields ? { outputFields: record.outputFields } : {},\n ...stamp.fieldCoverageId ? { fieldCoverageId: stamp.fieldCoverageId } : {},\n ...record.storeCalls && record.storeCalls.length > 0 ? { storeCalls: record.storeCalls } : {},\n ...record.storeCallsDropped ? { storeCallsDropped: record.storeCallsDropped } : {}\n });\n console.log(JSON.stringify(line));\n}\nvar OTHER_HANDLERS = [\"scheduled\", \"queue\", \"email\", \"tail\", \"trace\", \"alarm\", \"test\"];\nfunction withInvocationLog(worker, options = {}) {\n const inner = worker?.fetch;\n if (typeof inner !== \"function\") return worker;\n const wrapped = {\n async fetch(request, env, ctx) {\n if (invocationStampOf(request)) return inner.call(worker, request, env, ctx);\n const started = Date.now();\n const stamp = beginStamp(request, env, options);\n let status = null;\n let threw = false;\n try {\n const response = withRequestId(\n await runRecordingStoreCalls(stamp.record, options.asyncLocalStorage, () => inner.call(worker, request, env, ctx)),\n stamp.invocationId\n );\n status = response.status;\n handRecordToRouter(response, stamp.record, request, env, options);\n return response;\n } catch (e) {\n threw = true;\n throw e;\n } finally {\n writeInvocationLine(stamp, { request, env, status, threw, started }, options);\n }\n }\n };\n for (const name of OTHER_HANDLERS) {\n const h = worker[name];\n if (typeof h === \"function\") wrapped[name] = h.bind(worker);\n }\n return wrapped;\n}\nfunction handRecordToRouter(response, record, request, env, options) {\n try {\n const value = encodeInvocationRecord(record);\n if (value === null || !routedNodeOrNull(request.headers, env, options)) return;\n response.headers?.set?.(\n INVOCATION_RECORD_HEADER,\n value\n );\n } catch {\n }\n}\nfunction routedNodeOrNull(headers, env, options) {\n try {\n return readRoutedNode(headers, {\n expectedSecret: options.routerSecret?.(env),\n allowUnsigned: options.allowUnsigned?.(env) ?? false\n });\n } catch (e) {\n if (!(e instanceof RouterAssertionError)) console.log(JSON.stringify({ substrat: \"invocation-log-fault\", detail: String(e) }));\n return null;\n }\n}\n\n// substrat-platform-entry.ts\nimport * as vertical from \"__SUBSTRAT_VERTICAL_ENTRY__\";\nexport * from \"__SUBSTRAT_VERTICAL_ENTRY__\";\nvar substrat_platform_entry_default = withInvocationLog(vertical.default, {\n routerSecret: (env) => env.ROUTER_SECRET,\n allowUnsigned: (env) => env.ALLOW_DEV_NODE === \"true\",\n asyncLocalStorage: AsyncLocalStorage\n});\nexport {\n substrat_platform_entry_default as default\n};\n";
14
+ /**
15
+ * #2245: the entry's `node:async_hooks` import, as it appears in `PLATFORM_ENTRY_SOURCE`, and
16
+ * the line the uploader puts in its place for a script that can have no `AsyncLocalStorage`
17
+ * (one that opts out with `no_nodejs_als`). With no `nodejs_compat` either, that script's line names
18
+ * no store calls; with it, vertical-host reaches the class through `process.getBuiltinModule`.
19
+ */
20
+ export const PLATFORM_ENTRY_ALS_IMPORT = "import { AsyncLocalStorage } from \"node:async_hooks\";";
21
+ export const PLATFORM_ENTRY_ALS_FALLBACK = "const AsyncLocalStorage = undefined;";
14
22
  /**
15
23
  * The scope sweeper the platform supplies (#1902) — uploaded beside the entry, which
16
24
  * re-exports its class, when a vertical declares schedules and brings no sweeper of its own.
@@ -1 +1 @@
1
- {"version":3,"file":"platform-entry.generated.js","sourceRoot":"","sources":["../src/platform-entry.generated.ts"],"names":[],"mappings":"AAAA,8KAA8K;AAC9K,sEAAsE;AAEtE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,4BAA4B,CAAC;AAElE,gFAAgF;AAChF,MAAM,CAAC,MAAM,0BAA0B,GAAG,6BAA6B,CAAC;AAExE,6CAA6C;AAC7C,MAAM,CAAC,MAAM,qBAAqB,GAAW,i2VAAi2V,CAAC;AAE/4V;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,8BAA8B,CAAC;AAEtE,8CAA8C;AAC9C,MAAM,CAAC,MAAM,uBAAuB,GAAW,o0TAAo0T,CAAC"}
1
+ {"version":3,"file":"platform-entry.generated.js","sourceRoot":"","sources":["../src/platform-entry.generated.ts"],"names":[],"mappings":"AAAA,8KAA8K;AAC9K,sEAAsE;AAEtE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,4BAA4B,CAAC;AAElE,gFAAgF;AAChF,MAAM,CAAC,MAAM,0BAA0B,GAAG,6BAA6B,CAAC;AAExE,6CAA6C;AAC7C,MAAM,CAAC,MAAM,qBAAqB,GAAW,iqaAAiqa,CAAC;AAE/sa;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,yDAAyD,CAAC;AACnG,MAAM,CAAC,MAAM,2BAA2B,GAAG,sCAAsC,CAAC;AAElF;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,8BAA8B,CAAC;AAEtE,8CAA8C;AAC9C,MAAM,CAAC,MAAM,uBAAuB,GAAW,o0TAAo0T,CAAC"}
@@ -30,7 +30,7 @@
30
30
  * keeps that answer for every later upload.
31
31
  */
32
32
  import { PLATFORM_SWEEPER_BINDING, PLATFORM_SWEEPER_CLASS, PLATFORM_SWEEPER_VAR, PLATFORM_SWEEP_HOST_KEY, sweeperConflict, } from '@substrat-run/contracts';
33
- import { PLATFORM_ENTRY_MODULE, PLATFORM_ENTRY_PLACEHOLDER, PLATFORM_ENTRY_SOURCE, PLATFORM_SWEEPER_MODULE, PLATFORM_SWEEPER_SOURCE, } from './platform-entry.generated.js';
33
+ import { PLATFORM_ENTRY_ALS_FALLBACK, PLATFORM_ENTRY_ALS_IMPORT, PLATFORM_ENTRY_MODULE, PLATFORM_ENTRY_PLACEHOLDER, PLATFORM_ENTRY_SOURCE, PLATFORM_SWEEPER_MODULE, PLATFORM_SWEEPER_SOURCE, } from './platform-entry.generated.js';
34
34
  export { PLATFORM_ENTRY_MODULE, PLATFORM_SWEEPER_MODULE };
35
35
  const PLATFORM_MODULES = new Set([PLATFORM_ENTRY_MODULE, PLATFORM_SWEEPER_MODULE]);
36
36
  /** The line `invocationLog` writes, as it appears in any build: `substrat:"invocation"`. */
@@ -182,6 +182,32 @@ declared, bundle) {
182
182
  export function deployedDoClasses(doClasses, supplySweeper) {
183
183
  return supplySweeper ? [...new Set([...doClasses, PLATFORM_SWEEPER_CLASS])] : [...doClasses];
184
184
  }
185
+ /** The flag that gives a script `node:async_hooks` and nothing else of node (#2245). */
186
+ export const ASYNC_LOCAL_STORAGE_FLAG = 'nodejs_als';
187
+ /**
188
+ * The compatibility flags a wrapped script is uploaded with, and whether the platform entry
189
+ * may import `AsyncLocalStorage` (#2245, RFC §6: the request runs in one, so its store calls
190
+ * reach its line). The entry imports `node:async_hooks`, which workerd allows only under
191
+ * `nodejs_als` or `nodejs_compat`:
192
+ *
193
+ * - either flag already there: the flags go up exactly as declared;
194
+ * - neither: `nodejs_als` is appended, after the declared ones. It has no compatibility-date
195
+ * gate, and it adds `node:async_hooks` alone — no other node module, no globals;
196
+ * - the script opts out with `no_nodejs_als`: the flags go up as declared and the entry drops
197
+ * its import, so the upload never fails over it. With `nodejs_compat` beside the opt-out,
198
+ * vertical-host still reaches `AsyncLocalStorage` through `process.getBuiltinModule` and the
199
+ * line names the calls; with no `nodejs_compat` either, the line names no store calls.
200
+ *
201
+ * Existing flags are never removed or reordered.
202
+ */
203
+ export function platformEntryFlags(declared) {
204
+ const flags = [...(declared ?? [])];
205
+ if (flags.includes(`no_${ASYNC_LOCAL_STORAGE_FLAG}`))
206
+ return { flags, asyncLocalStorage: false };
207
+ if (flags.includes(ASYNC_LOCAL_STORAGE_FLAG) || flags.includes('nodejs_compat'))
208
+ return { flags, asyncLocalStorage: true };
209
+ return { flags: [...flags, ASYNC_LOCAL_STORAGE_FLAG], asyncLocalStorage: true };
210
+ }
185
211
  /**
186
212
  * The bundle as uploaded: the platform's entry module added (or refreshed) and named as
187
213
  * the script's main module, importing the vertical's own entry — and, when the version's
@@ -198,14 +224,18 @@ export function withPlatformEntry(bundle) {
198
224
  return bundle;
199
225
  const own = bundle.modules.filter((m) => !PLATFORM_MODULES.has(m.name));
200
226
  const encode = (text) => new TextEncoder().encode(text);
227
+ const { flags, asyncLocalStorage } = platformEntryFlags(bundle.compatibilityFlags);
201
228
  // Module names are paths from the script root, where the platform entry sits too.
202
229
  let source = PLATFORM_ENTRY_SOURCE.split(PLATFORM_ENTRY_PLACEHOLDER).join(`./${bundle.entry}`);
230
+ if (!asyncLocalStorage)
231
+ source = source.split(PLATFORM_ENTRY_ALS_IMPORT).join(PLATFORM_ENTRY_ALS_FALLBACK);
203
232
  if (supply)
204
233
  source += `export { ${PLATFORM_SWEEPER_CLASS} } from "./${PLATFORM_SWEEPER_MODULE}";\n`;
205
234
  const kind = 'application/javascript+module';
206
235
  return {
207
236
  ...bundle,
208
237
  entry: PLATFORM_ENTRY_MODULE,
238
+ compatibilityFlags: flags,
209
239
  modules: [
210
240
  { name: PLATFORM_ENTRY_MODULE, content: encode(source), contentType: kind },
211
241
  ...(supply ? [{ name: PLATFORM_SWEEPER_MODULE, content: encode(PLATFORM_SWEEPER_SOURCE), contentType: kind }] : []),
@@ -1 +1 @@
1
- {"version":3,"file":"platform-entry.js","sourceRoot":"","sources":["../src/platform-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,oBAAoB,EACpB,uBAAuB,EACvB,eAAe,GAEhB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,qBAAqB,EACrB,0BAA0B,EAC1B,qBAAqB,EACrB,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,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AI,GAAG,+BAA+B,CAAC;IAC7C,OAAO;QACL,GAAG,MAAM;QACT,KAAK,EAAE,qBAAqB;QAC5B,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE;YACP,EAAE,IAAI,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE;YAC3E,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,uBAAuB,EAAE,OAAO,EAAE,MAAM,CAAC,uBAAuB,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACnH,GAAG,GAAG;SACP;QACD,GAAG,CAAC,MAAM;YACR,CAAC,CAAC;gBACE,mFAAmF;gBACnF,0DAA0D;gBAC1D,SAAS,EAAE,iBAAiB,CAAC,MAAM,CAAC,SAAS,IAAI,EAAE,EAAE,IAAI,CAAC;gBAC1D,QAAQ,EAAE;oBACR,GAAG,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC;oBAC1B,EAAE,IAAI,EAAE,0BAA0B,EAAE,IAAI,EAAE,wBAAwB,EAAE,UAAU,EAAE,sBAAsB,EAAE;oBACxG,+FAA+F;oBAC/F,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,oBAAoB,EAAE,IAAI,EAAE,wBAAwB,EAAwC;iBACzH;aACF;YACH,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC"}
@@ -0,0 +1,151 @@
1
+ import { type PlatformActorId, type ReservedStoreOperation, type Scope, type ScopeDumpTable, type StoreKindRegistration } from '@substrat-run/contracts';
2
+ import { type HostAdmin } from '@substrat-run/kernel';
3
+ /**
4
+ * A reserved scope-store call, made by the control plane straight at the store
5
+ * script (#2207). The vertical is not on this path: it holds neither the
6
+ * namespace nor the key. The key signs the envelope here, audience `platform`,
7
+ * which is the only audience a `substrat.*` operation accepts.
8
+ */
9
+ export interface PlatformScopeStoreDispatch {
10
+ /** PKCS8 Ed25519 private key, base64url. Signs audience `platform`. */
11
+ readonly platformKey: string;
12
+ fetch(scriptName: string, request: Request): Promise<Response>;
13
+ }
14
+ export interface PlatformScopeStoreTarget {
15
+ readonly vertical: string;
16
+ readonly kind: string;
17
+ readonly tenantId: string;
18
+ readonly scopeId: string;
19
+ readonly binding: string;
20
+ }
21
+ /** One declared binding, as a version manifest lists it. */
22
+ export interface DeclaredScopeStore {
23
+ readonly binding: string;
24
+ readonly kind: string;
25
+ }
26
+ export interface PlatformScopeStores {
27
+ exportStores(input: {
28
+ tenantId: string;
29
+ scopeId: string;
30
+ vertical: string;
31
+ stores: readonly DeclaredScopeStore[];
32
+ }): Promise<{
33
+ binding: string;
34
+ kind: string;
35
+ tables: ScopeDumpTable[];
36
+ }[]>;
37
+ importStores(input: {
38
+ tenantId: string;
39
+ scopeId: string;
40
+ vertical: string;
41
+ stores: readonly {
42
+ binding: string;
43
+ kind: string;
44
+ tables: ScopeDumpTable[];
45
+ }[];
46
+ }): Promise<void>;
47
+ eraseSubject(input: {
48
+ tenantId: string;
49
+ scopeId: string;
50
+ vertical: string;
51
+ subjectId: string;
52
+ stores: readonly DeclaredScopeStore[];
53
+ }): Promise<{
54
+ binding: string;
55
+ erased: number;
56
+ }[]>;
57
+ wipeStores(input: {
58
+ tenantId: string;
59
+ scopeId: string;
60
+ vertical: string;
61
+ stores: readonly DeclaredScopeStore[];
62
+ }): Promise<void>;
63
+ sizeStores(input: {
64
+ tenantId: string;
65
+ scopeId: string;
66
+ vertical: string;
67
+ stores: readonly DeclaredScopeStore[];
68
+ }): Promise<{
69
+ binding: string;
70
+ bytes: number;
71
+ }[]>;
72
+ }
73
+ /** Bindings a version manifest declares. Missing JSON is none. Unreadable JSON fails closed. */
74
+ export declare function declaredStoresOf(manifestJson: string | null): DeclaredScopeStore[];
75
+ /**
76
+ * The version a scope's deployment runs, read once (#2207, L14). A scope with a serving pin runs
77
+ * the serving pointer's version when the pointer's ref is its pin, and an unknown one otherwise;
78
+ * a scope with no pin runs its bound version. `servingPointer` is the pointer as read, for a scope
79
+ * with a pin: the pair a subject-erasure claim requires to still hold (#2285). A pointer that
80
+ * cannot be read refuses (503): neither the version nor the fence can be named.
81
+ */
82
+ export interface RunningVersion {
83
+ readonly versionId: string | null;
84
+ readonly servingPointer?: {
85
+ ref: string;
86
+ versionId: string;
87
+ } | null;
88
+ }
89
+ export declare function runningVersionOf(admin: Pick<HostAdmin, 'verticalServing'>, actor: PlatformActorId, scope: Pick<Scope, 'vertical' | 'verticalVersionId' | 'servingRef'>): Promise<RunningVersion>;
90
+ /**
91
+ * Stop the router serving a scope, before its stores are wiped (#2285, L6). The router admits a
92
+ * scope only while one of its hostnames is `active`, and it reads that row on every request, so
93
+ * unbinding is immediate. Unbind is idempotent: a retry after a failed wipe finds nothing left
94
+ * to remove. A hostname set merely non-active would not hold — the issuance reconcile heals a
95
+ * platform hostname back to `active`.
96
+ */
97
+ export declare function unrouteScope(admin: Pick<HostAdmin, 'listHostnames' | 'unbindHostname'>, actor: PlatformActorId, scope: Pick<Scope, 'tenantId' | 'id'>): Promise<void>;
98
+ /**
99
+ * The scope stores of the version a scope's deployment runs (#2207). A scope on its vertical's
100
+ * serving pin runs the serving pointer's version, and any other scope its bound version; this
101
+ * is the version the router reads a scope's stores from (`READ_ROUTE_SQL`), and the one a restore
102
+ * may import into (L8). The lifecycle reaches more: `scopeStoresOf`. Provisioning sets the
103
+ * serving pin and no bound version, so reading the bound version alone answers "no store" for an
104
+ * ordinary install whose store the router serves. A pin that names another script than the
105
+ * pointer's is unknown, as #2242's erasure gate has it.
106
+ *
107
+ * The gate is `mayHoldScopeStores`: with no kind registered nothing can hold a store, and the
108
+ * answer is none. Otherwise a version that cannot be named, a manifest that cannot be read, or one
109
+ * the gate says may hold a store without naming it refuses (503), rather than let a backup, a
110
+ * wipe, a replay or an erasure skip a store that may hold data.
111
+ *
112
+ * `running` is a resolution the caller already holds (`runningVersionOf`), so a caller that fences
113
+ * on the version reads it once and judges the stores against the same read.
114
+ */
115
+ export declare function runningVersionStoresOf(admin: Pick<HostAdmin, 'verticalServing' | 'versionManifest'>, actor: PlatformActorId, scope: Pick<Scope, 'id' | 'vertical' | 'verticalVersionId' | 'servingRef'>, kinds?: readonly StoreKindRegistration[], running?: RunningVersion): Promise<DeclaredScopeStore[]>;
116
+ /**
117
+ * What the lifecycle reaches for a scope (#2286, L17): the running version's stores
118
+ * (`runningVersionStoresOf`, which still fails closed first), and every binding any version of its
119
+ * vertical has declared (`HostAdmin.verticalScopeStores`, read by its keys). Export, wipe, erasure
120
+ * and the meter reach `all`, so an object under a binding a later version dropped is still
121
+ * reached. A restore imports only into `running` (L8).
122
+ *
123
+ * A binding keeps its kind for the life of the vertical, since publish refuses a re-kind; a
124
+ * running version whose kind disagrees with the record, or a record that cannot be read,
125
+ * refuses (503).
126
+ */
127
+ export declare function scopeStoreReachOf(admin: Pick<HostAdmin, 'verticalServing' | 'versionManifest' | 'verticalScopeStores'>, actor: PlatformActorId, scope: Pick<Scope, 'id' | 'vertical' | 'verticalVersionId' | 'servingRef'>, kinds?: readonly StoreKindRegistration[], running?: RunningVersion): Promise<{
128
+ running: DeclaredScopeStore[];
129
+ all: DeclaredScopeStore[];
130
+ }>;
131
+ /** `scopeStoreReachOf`'s `all`: every store the lifecycle reaches for a scope (#2286). */
132
+ export declare function scopeStoresOf(admin: Pick<HostAdmin, 'verticalServing' | 'versionManifest' | 'verticalScopeStores'>, actor: PlatformActorId, scope: Pick<Scope, 'id' | 'vertical' | 'verticalVersionId' | 'servingRef'>, kinds?: readonly StoreKindRegistration[], running?: RunningVersion): Promise<DeclaredScopeStore[]>;
133
+ /** Sign the envelope and POST the reserved operation at that kind's script. */
134
+ export declare function callPlatformScopeStore(dispatch: PlatformScopeStoreDispatch, target: PlatformScopeStoreTarget, operation: ReservedStoreOperation, input?: unknown): Promise<unknown>;
135
+ /**
136
+ * The same call at a named script and object: the platform's canary (#2300), which no
137
+ * (vertical, scope) names. Its answer is parsed as every reserved answer is.
138
+ */
139
+ export declare function callPlatformScopeStoreAt(dispatch: PlatformScopeStoreDispatch, target: {
140
+ readonly scriptName: string;
141
+ readonly objectName: string;
142
+ }, operation: ReservedStoreOperation, input?: unknown): Promise<unknown>;
143
+ /** The five reserved operations, one call per declared binding. */
144
+ export declare function platformScopeStoresFor(dispatch: PlatformScopeStoreDispatch): PlatformScopeStores;
145
+ /**
146
+ * The caller of a hosted control plane that has no route to the store scripts (#2207): every
147
+ * call is refused (503). A hosted control plane always passes a caller, this one included, so
148
+ * a missing route refuses the backup, wipe or erasure that needs a store instead of skipping it.
149
+ */
150
+ export declare function unreachablePlatformScopeStores(): PlatformScopeStores;
151
+ //# sourceMappingURL=platform-scope-stores.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform-scope-stores.d.ts","sourceRoot":"","sources":["../src/platform-scope-stores.ts"],"names":[],"mappings":"AAAA,OAAO,EAeL,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,KAAK,EACV,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC3B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAA8B,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAIlF;;;;;GAKG;AACH,MAAM,WAAW,0BAA0B;IACzC,uEAAuE;IACvE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CAChE;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1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