@substrat-run/kernel 0.141.0 → 0.142.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 (66) hide show
  1. package/dist/async-invocation-log.d.ts +1 -1
  2. package/dist/async-invocation-log.d.ts.map +1 -1
  3. package/dist/async-invocation-log.js +1 -1
  4. package/dist/async-invocation-log.js.map +1 -1
  5. package/dist/capability.d.ts +123 -3
  6. package/dist/capability.d.ts.map +1 -1
  7. package/dist/capability.js +263 -13
  8. package/dist/capability.js.map +1 -1
  9. package/dist/connector-calls.d.ts +3 -72
  10. package/dist/connector-calls.d.ts.map +1 -1
  11. package/dist/connector-calls.js +3 -62
  12. package/dist/connector-calls.js.map +1 -1
  13. package/dist/index.d.ts +11 -91
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +7 -59
  16. package/dist/index.js.map +1 -1
  17. package/dist/invocation-line.d.ts +211 -0
  18. package/dist/invocation-line.d.ts.map +1 -0
  19. package/dist/invocation-line.js +33 -0
  20. package/dist/invocation-line.js.map +1 -0
  21. package/dist/meters.d.ts +21 -1
  22. package/dist/meters.d.ts.map +1 -1
  23. package/dist/meters.js +0 -0
  24. package/dist/meters.js.map +1 -1
  25. package/dist/module-log.d.ts +5 -4
  26. package/dist/module-log.d.ts.map +1 -1
  27. package/dist/module-log.js +5 -4
  28. package/dist/module-log.js.map +1 -1
  29. package/dist/permission-checker.d.ts +23 -0
  30. package/dist/permission-checker.d.ts.map +1 -1
  31. package/dist/permission-checker.js.map +1 -1
  32. package/dist/permission-eval.d.ts.map +1 -1
  33. package/dist/permission-eval.js +77 -21
  34. package/dist/permission-eval.js.map +1 -1
  35. package/dist/platform-sweep.d.ts +81 -1
  36. package/dist/platform-sweep.d.ts.map +1 -1
  37. package/dist/platform-sweep.js +125 -0
  38. package/dist/platform-sweep.js.map +1 -1
  39. package/dist/scope-copy-ledger.d.ts +49 -0
  40. package/dist/scope-copy-ledger.d.ts.map +1 -1
  41. package/dist/scope-copy-ledger.js +43 -0
  42. package/dist/scope-copy-ledger.js.map +1 -1
  43. package/dist/scope-host.d.ts +56 -10
  44. package/dist/scope-host.d.ts.map +1 -1
  45. package/dist/scope-host.js.map +1 -1
  46. package/dist/storage-gauge.d.ts +125 -0
  47. package/dist/storage-gauge.d.ts.map +1 -0
  48. package/dist/storage-gauge.js +234 -0
  49. package/dist/storage-gauge.js.map +1 -0
  50. package/package.json +10 -2
  51. package/dist/invocation-log.d.ts +0 -447
  52. package/dist/invocation-log.d.ts.map +0 -1
  53. package/dist/invocation-log.js +0 -410
  54. package/dist/invocation-log.js.map +0 -1
  55. package/dist/platform-call.d.ts +0 -45
  56. package/dist/platform-call.d.ts.map +0 -1
  57. package/dist/platform-call.js +0 -63
  58. package/dist/platform-call.js.map +0 -1
  59. package/dist/provider-error.d.ts +0 -38
  60. package/dist/provider-error.d.ts.map +0 -1
  61. package/dist/provider-error.js +0 -65
  62. package/dist/provider-error.js.map +0 -1
  63. package/dist/routed-node.d.ts +0 -87
  64. package/dist/routed-node.d.ts.map +0 -1
  65. package/dist/routed-node.js +0 -67
  66. package/dist/routed-node.js.map +0 -1
@@ -1,87 +0,0 @@
1
- import type { ScopeId, TenantId } from '@substrat-run/contracts';
2
- /**
3
- * A tenant or scope id: a ULID, exactly what `@substrat-run/contracts`' `tenantId` and
4
- * `scopeId` schemas accept (`z.string().regex(ULID).brand()`).
5
- *
6
- * Checked with the pattern itself rather than through those schemas since #1893, because
7
- * this file is bundled into the platform's entry in front of EVERY deployed vertical
8
- * (`withInvocationLog`), and a runtime import of the contracts package pulls all of it —
9
- * and zod — into that bundle: 750 KB added to every upload to run one regex. The brands
10
- * are types, so they still come from contracts; `routed-node.test.ts` holds this pattern to
11
- * those schemas so the two cannot drift.
12
- */
13
- export declare const ROUTED_ID: RegExp;
14
- /**
15
- * Reading the node the router asserted (K-26).
16
- *
17
- * The router resolves `hostname → (tenant, scope, surface)` and forwards over a
18
- * service binding with that resolution in headers. This is the vertical's side of
19
- * that contract, shared because every vertical needs it and none of them should be
20
- * re-deriving how to trust it. Moving from the kernel to `vertical-host` (#1978), which
21
- * already re-exports it.
22
- *
23
- * Web-standard only and structurally typed: the base tsconfig is `ES2023` with no
24
- * DOM lib, deliberately, so no package assumes a browser. Taking the one method we
25
- * need rather than the whole `Headers` type keeps that true and costs nothing — a
26
- * real `Headers` satisfies it, and so does a plain object in a test.
27
- */
28
- /** The one method this needs from a `Headers`. A real `Headers` satisfies it. */
29
- export interface HeaderReader {
30
- get(name: string): string | null;
31
- }
32
- export interface RoutedNode {
33
- tenantId: TenantId;
34
- scopeId: ScopeId;
35
- /** Which app answers: `app`, `storefront`, `back-office`, … Vertical vocabulary. */
36
- surface: string;
37
- verticalSlug: string | null;
38
- }
39
- /** Thrown when headers are present but not trustworthy. Never means "no router". */
40
- export declare class RouterAssertionError extends Error {
41
- }
42
- export interface ReadRoutedNodeOptions {
43
- /**
44
- * The router's shared secret, as this worker holds it (`ROUTER_SECRET`). When set,
45
- * an assertion is trusted only if `x-substrat-router` matches it — always, even
46
- * with `allowUnsigned`.
47
- */
48
- expectedSecret?: string;
49
- /**
50
- * Accept an assertion nobody signed, when no secret is configured (#966).
51
- *
52
- * Off by default, and that default is the boundary: a worker deployed without
53
- * its secret used to trust any `x-substrat-*` headers it was handed, which is a
54
- * forged tenant from anyone who could reach the script directly. Now it refuses
55
- * them — loudly, as a `RouterAssertionError` — until the secret is provisioned.
56
- *
57
- * The one legitimate exception is an un-routed local instance behind a dev
58
- * router that has no secret either, which is what `ALLOW_DEV_NODE` already
59
- * names; a host sets this from that flag and from nothing else.
60
- */
61
- allowUnsigned?: boolean;
62
- }
63
- /**
64
- * The `(tenant, scope)` this request is for, or `null` when no router fronted it.
65
- *
66
- * Three outcomes, kept distinct on purpose:
67
- *
68
- * - **null** — no assertion at all. The caller decides: a single-tenant standalone
69
- * deploy substitutes its own node, anything else refuses.
70
- * - **throws** — headers are present but wrong: a bad or missing secret, a secret
71
- * this worker cannot verify because it holds none, or ids that are not ULIDs.
72
- * Present-but-wrong is a misconfiguration or an attack, and collapsing it into
73
- * `null` would let either one fall through to whatever the caller does for
74
- * "unrouted".
75
- * - **a node** — trustworthy, and the tenant whose data this request may touch.
76
- *
77
- * `expectedSecret` is what makes the headers trustworthy in code. K-26's real
78
- * boundary is that vertical workers have no public route, so the router is the only
79
- * possible source — but that is a deployment fact, and `workers.dev` is on by
80
- * default. When the secret is configured, a request that did not come from the
81
- * router cannot assert a tenant no matter how the routes are configured. When it is
82
- * NOT configured the assertion fails closed (#966): an unsigned assertion is refused
83
- * unless the host opted in with `allowUnsigned`, so forgetting to provision the
84
- * secret is a visible outage rather than an open door.
85
- */
86
- export declare function readRoutedNode(headers: HeaderReader, options?: ReadRoutedNodeOptions): RoutedNode | null;
87
- //# sourceMappingURL=routed-node.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"routed-node.d.ts","sourceRoot":"","sources":["../src/routed-node.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAEjE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,QAA6B,CAAC;AAEpD;;;;;;;;;;;;;GAaG;AAEH,iFAAiF;AACjF,MAAM,WAAW,YAAY;IAC3B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,oFAAoF;IACpF,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,oFAAoF;AACpF,qBAAa,oBAAqB,SAAQ,KAAK;CAAG;AAElD,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;;;;;;OAWG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,YAAY,EACrB,OAAO,GAAE,qBAA0B,GAClC,UAAU,GAAG,IAAI,CA6BnB"}
@@ -1,67 +0,0 @@
1
- import { secretMatches } from './platform-call.js';
2
- /**
3
- * A tenant or scope id: a ULID, exactly what `@substrat-run/contracts`' `tenantId` and
4
- * `scopeId` schemas accept (`z.string().regex(ULID).brand()`).
5
- *
6
- * Checked with the pattern itself rather than through those schemas since #1893, because
7
- * this file is bundled into the platform's entry in front of EVERY deployed vertical
8
- * (`withInvocationLog`), and a runtime import of the contracts package pulls all of it —
9
- * and zod — into that bundle: 750 KB added to every upload to run one regex. The brands
10
- * are types, so they still come from contracts; `routed-node.test.ts` holds this pattern to
11
- * those schemas so the two cannot drift.
12
- */
13
- export const ROUTED_ID = /^[0-9A-HJKMNP-TV-Z]{26}$/;
14
- /** Thrown when headers are present but not trustworthy. Never means "no router". */
15
- export class RouterAssertionError extends Error {
16
- }
17
- /**
18
- * The `(tenant, scope)` this request is for, or `null` when no router fronted it.
19
- *
20
- * Three outcomes, kept distinct on purpose:
21
- *
22
- * - **null** — no assertion at all. The caller decides: a single-tenant standalone
23
- * deploy substitutes its own node, anything else refuses.
24
- * - **throws** — headers are present but wrong: a bad or missing secret, a secret
25
- * this worker cannot verify because it holds none, or ids that are not ULIDs.
26
- * Present-but-wrong is a misconfiguration or an attack, and collapsing it into
27
- * `null` would let either one fall through to whatever the caller does for
28
- * "unrouted".
29
- * - **a node** — trustworthy, and the tenant whose data this request may touch.
30
- *
31
- * `expectedSecret` is what makes the headers trustworthy in code. K-26's real
32
- * boundary is that vertical workers have no public route, so the router is the only
33
- * possible source — but that is a deployment fact, and `workers.dev` is on by
34
- * default. When the secret is configured, a request that did not come from the
35
- * router cannot assert a tenant no matter how the routes are configured. When it is
36
- * NOT configured the assertion fails closed (#966): an unsigned assertion is refused
37
- * unless the host opted in with `allowUnsigned`, so forgetting to provision the
38
- * secret is a visible outage rather than an open door.
39
- */
40
- export function readRoutedNode(headers, options = {}) {
41
- const rawTenant = headers.get('x-substrat-tenant');
42
- const rawScope = headers.get('x-substrat-scope');
43
- if (!rawTenant && !rawScope)
44
- return null;
45
- const { expectedSecret, allowUnsigned = false } = options;
46
- if (expectedSecret) {
47
- if (!secretMatches(headers.get('x-substrat-router'), expectedSecret)) {
48
- throw new RouterAssertionError('router assertion is not signed by a known router');
49
- }
50
- }
51
- else if (!allowUnsigned) {
52
- throw new RouterAssertionError('router assertion cannot be verified: this worker has no ROUTER_SECRET configured');
53
- }
54
- if (!rawTenant || !rawScope) {
55
- throw new RouterAssertionError('router assertion is incomplete');
56
- }
57
- if (!ROUTED_ID.test(rawTenant) || !ROUTED_ID.test(rawScope)) {
58
- throw new RouterAssertionError('router assertion carries a malformed id');
59
- }
60
- return {
61
- tenantId: rawTenant,
62
- scopeId: rawScope,
63
- surface: headers.get('x-substrat-surface') ?? 'app',
64
- verticalSlug: headers.get('x-substrat-vertical'),
65
- };
66
- }
67
- //# sourceMappingURL=routed-node.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"routed-node.js","sourceRoot":"","sources":["../src/routed-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,0BAA0B,CAAC;AA8BpD,oFAAoF;AACpF,MAAM,OAAO,oBAAqB,SAAQ,KAAK;CAAG;AAwBlD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,cAAc,CAC5B,OAAqB,EACrB,OAAO,GAA0B,EAAE;IAEnC,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACnD,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IACjD,IAAI,CAAC,SA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