@substrat-run/kernel 0.219.0 → 0.221.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 (92) hide show
  1. package/dist/adopt-major.d.ts +150 -0
  2. package/dist/adopt-major.d.ts.map +1 -0
  3. package/dist/adopt-major.js +150 -0
  4. package/dist/adopt-major.js.map +1 -0
  5. package/dist/app-environments.d.ts +113 -0
  6. package/dist/app-environments.d.ts.map +1 -0
  7. package/dist/app-environments.js +239 -0
  8. package/dist/app-environments.js.map +1 -0
  9. package/dist/broker-relay-scope.d.ts +53 -0
  10. package/dist/broker-relay-scope.d.ts.map +1 -0
  11. package/dist/broker-relay-scope.js +77 -0
  12. package/dist/broker-relay-scope.js.map +1 -0
  13. package/dist/broker-relay.d.ts +5 -1
  14. package/dist/broker-relay.d.ts.map +1 -1
  15. package/dist/broker-relay.js.map +1 -1
  16. package/dist/broker-schema.d.ts.map +1 -1
  17. package/dist/broker-schema.js +12 -0
  18. package/dist/broker-schema.js.map +1 -1
  19. package/dist/carried-copy.d.ts.map +1 -1
  20. package/dist/carried-copy.js +3 -0
  21. package/dist/carried-copy.js.map +1 -1
  22. package/dist/connect-intent.d.ts +24 -0
  23. package/dist/connect-intent.d.ts.map +1 -0
  24. package/dist/connect-intent.js +25 -0
  25. package/dist/connect-intent.js.map +1 -0
  26. package/dist/connection-context.d.ts +30 -0
  27. package/dist/connection-context.d.ts.map +1 -1
  28. package/dist/connection-context.js.map +1 -1
  29. package/dist/delivery-broker.d.ts +77 -1
  30. package/dist/delivery-broker.d.ts.map +1 -1
  31. package/dist/delivery-broker.js +112 -8
  32. package/dist/delivery-broker.js.map +1 -1
  33. package/dist/delivery-contract.d.ts +36 -0
  34. package/dist/delivery-contract.d.ts.map +1 -0
  35. package/dist/delivery-contract.js +84 -0
  36. package/dist/delivery-contract.js.map +1 -0
  37. package/dist/directory-lake-keep.d.ts.map +1 -1
  38. package/dist/directory-lake-keep.js +5 -0
  39. package/dist/directory-lake-keep.js.map +1 -1
  40. package/dist/email-intent.d.ts +32 -0
  41. package/dist/email-intent.d.ts.map +1 -1
  42. package/dist/email-intent.js +66 -1
  43. package/dist/email-intent.js.map +1 -1
  44. package/dist/entity-trash.d.ts +45 -0
  45. package/dist/entity-trash.d.ts.map +1 -1
  46. package/dist/entity-trash.js +52 -0
  47. package/dist/entity-trash.js.map +1 -1
  48. package/dist/index.d.ts +19 -8
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +22 -4
  51. package/dist/index.js.map +1 -1
  52. package/dist/permission-checker.d.ts.map +1 -1
  53. package/dist/permission-checker.js +4 -2
  54. package/dist/permission-checker.js.map +1 -1
  55. package/dist/release-within-major.d.ts +173 -0
  56. package/dist/release-within-major.d.ts.map +1 -0
  57. package/dist/release-within-major.js +283 -0
  58. package/dist/release-within-major.js.map +1 -0
  59. package/dist/reserved-roles.d.ts +12 -1
  60. package/dist/reserved-roles.d.ts.map +1 -1
  61. package/dist/reserved-roles.js.map +1 -1
  62. package/dist/schedule-due.d.ts +88 -0
  63. package/dist/schedule-due.d.ts.map +1 -0
  64. package/dist/schedule-due.js +116 -0
  65. package/dist/schedule-due.js.map +1 -0
  66. package/dist/schedule-state.d.ts +1 -1
  67. package/dist/schedule-state.d.ts.map +1 -1
  68. package/dist/schedule-state.js +6 -0
  69. package/dist/schedule-state.js.map +1 -1
  70. package/dist/scope-copy.d.ts.map +1 -1
  71. package/dist/scope-copy.js +13 -1
  72. package/dist/scope-copy.js.map +1 -1
  73. package/dist/scope-host.d.ts +202 -2
  74. package/dist/scope-host.d.ts.map +1 -1
  75. package/dist/scope-host.js.map +1 -1
  76. package/dist/scope-identity.d.ts +10 -1
  77. package/dist/scope-identity.d.ts.map +1 -1
  78. package/dist/scope-identity.js +12 -3
  79. package/dist/scope-identity.js.map +1 -1
  80. package/dist/scope-store.d.ts +30 -6
  81. package/dist/scope-store.d.ts.map +1 -1
  82. package/dist/scope-store.js +30 -1
  83. package/dist/scope-store.js.map +1 -1
  84. package/dist/scope-types.d.ts +161 -0
  85. package/dist/scope-types.d.ts.map +1 -0
  86. package/dist/scope-types.js +227 -0
  87. package/dist/scope-types.js.map +1 -0
  88. package/dist/store-proof.d.ts +45 -0
  89. package/dist/store-proof.d.ts.map +1 -0
  90. package/dist/store-proof.js +97 -0
  91. package/dist/store-proof.js.map +1 -0
  92. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"scope-store.js","sourceRoot":"","sources":["../src/scope-store.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EACnB,yBAAyB,EACzB,wBAAwB,EACxB,UAAU,EACV,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,aAAa,GAYd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,oBAAoB,EAAsB,MAAM,sBAAsB,CAAC;AAEhF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAuCjC,MAAM,UAAU,mBAAmB,CACjC,OAA0C;IAE1C,MAAM,OAAO,GAAG,IAAI,GAAG,EAA4B,CAAC;IACpD,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,CAAC;QAC3C,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,wBAAwB,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;QAChF,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,OAAO,CA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types on a host (#2993, K-64): which modules a scope of each type runs, and the type a
3
+ * provision gives a scope. Both adapters read these, so a pure host and a Durable Object agree on
4
+ * what a scope of a type is.
5
+ *
6
+ * The declaration and its full rules are `@substrat-run/contracts` (`scopeTypeOffences`, which
7
+ * `definePermissions` applies at load). A host is handed the declared surface as its
8
+ * `permissions` and holds again only what it acts on: a `home` type, unique names, and modules the
9
+ * surface lists. A host given no `permissions`, or a surface declaring no types, has one `home`
10
+ * type running every registered module, as every host does today.
11
+ */
12
+ import { HOME_SCOPE_TYPE, type SubstratError } from '@substrat-run/contracts';
13
+ export { HOME_SCOPE_TYPE };
14
+ /** A scope type as a host reads it off its `permissions`: a name, the modules it runs and its roles. */
15
+ export interface HostScopeTypeDeclaration {
16
+ readonly name: string;
17
+ readonly modules: readonly string[];
18
+ /** The vertical's roles that exist on a scope of this type (#2993 part 3). Absent: none. */
19
+ readonly roles?: readonly string[];
20
+ /** The types a scope of this type may hold as children (#2995). Absent: none. */
21
+ readonly children?: readonly string[];
22
+ /**
23
+ * How a request may reach a scope of this type (#2995): `direct`, `parent` or both. Absent: the
24
+ * contract's default, `direct` for the home type and `parent` for any other.
25
+ */
26
+ readonly accepts?: readonly ('direct' | 'parent')[];
27
+ }
28
+ /**
29
+ * The `_substrat_meta` key a Durable Object records its scope's type under (#2993 part 3), as it
30
+ * records its tenant: written once at provision, read at wake. Absent is `home`, which every scope
31
+ * from before scope types is. It describes this store, never the data, so no dump carries it
32
+ * (`STORE_LOCAL_META_KEYS`): a copy's type is the one its own provision fixed.
33
+ */
34
+ export declare const SCOPE_TYPE_META_KEY = "scope_type";
35
+ /**
36
+ * The modules each type runs. `declared: false` is the one implicit `home` type, whose module set
37
+ * is every module registered (`null`), so nothing about such a host changes.
38
+ */
39
+ export type ScopeTypePlan = {
40
+ readonly declared: false;
41
+ } | {
42
+ readonly declared: true;
43
+ /** Each type's modules. */
44
+ readonly types: ReadonlyMap<string, ReadonlySet<string>>;
45
+ /** Each type's roles (#2993 part 3). */
46
+ readonly roles: ReadonlyMap<string, ReadonlySet<string>>;
47
+ /** Every role some type names: the roles a scope-role door judges by type. */
48
+ readonly typedRoles: ReadonlySet<string>;
49
+ /** Each type's child types (#2995). */
50
+ readonly children: ReadonlyMap<string, ReadonlySet<string>>;
51
+ /** How each type may be reached (#2995). */
52
+ readonly accepts: ReadonlyMap<string, ReadonlySet<ScopeAccess>>;
53
+ };
54
+ /** How a request reaches a scope (#2995): routed to it, or from its parent's host code through the door. */
55
+ export type ScopeAccess = 'direct' | 'parent';
56
+ /** What a host's `permissions` carries for this: its listed modules, and its types if declared. */
57
+ export interface ScopeTypeSource {
58
+ readonly modules: readonly {
59
+ manifest: {
60
+ id: string;
61
+ };
62
+ }[];
63
+ readonly scopeTypes?: readonly HostScopeTypeDeclaration[];
64
+ }
65
+ /** The host's plan from its `permissions`. Throws, at construction, on a declaration it cannot act on. */
66
+ export declare function scopeTypePlanOf(permissions: ScopeTypeSource | undefined): ScopeTypePlan;
67
+ /**
68
+ * #2993 part 4: the plan of a vertical as its STORED deploy manifest declares it, for a module-less
69
+ * coordinator, which registers none of the vertical's modules and so has no `permissions` of its
70
+ * own for it. The types name the modules they run, so those are the modules listed. A manifest that
71
+ * declares no types, or none this reads, is the one implicit `home` type: such a coordinator then
72
+ * refuses every other type, as it did before the manifest carried them.
73
+ */
74
+ export declare function scopeTypePlanOfManifest(manifestJson: string | null | undefined): ScopeTypePlan;
75
+ /** Whether a scope of `type` runs `moduleId`. On a host with no declared types, every module runs. */
76
+ export declare function scopeTypeRuns(plan: ScopeTypePlan, type: string, moduleId: string): boolean;
77
+ /**
78
+ * The type a provision gives a scope, and the rule that keeps it: the type is fixed when the scope
79
+ * is first provisioned (#2993). `recorded` is what the directory holds for an existing scope
80
+ * (`null` for a row from before types, which is `home`), or `undefined` for a new one.
81
+ *
82
+ * Refused: a type this host does not declare (`validation_failed`), and a re-provision naming a
83
+ * type other than the one recorded (`conflict`). A re-provision that names none keeps the record.
84
+ */
85
+ export declare function provisionedScopeType(plan: ScopeTypePlan, requested: string | undefined, recorded: string | null | undefined, scopeId: string): string;
86
+ /**
87
+ * The refusal for an operation a scope's type does not run. `not_found`, the code an unknown
88
+ * operation answers with, because on this scope it is one: the scope carries none of that
89
+ * module's tables.
90
+ */
91
+ export declare function operationNotInScopeType(operation: string, type: string): SubstratError;
92
+ /**
93
+ * Why `roleKey` may not be seated at a scope of `type` (#2993 part 3), or null. A role the vertical's
94
+ * types name exists only on the types that name it: seating a clinic's role on a record scope would
95
+ * grant keys of modules that scope does not run. Admitted: every role on a host with no declared
96
+ * types, and a role no type names (one the tenant defined for itself), which is left to the door's
97
+ * own rules, as a key a host knows nothing about is.
98
+ */
99
+ export declare function scopeTypeRoleRefusal(plan: ScopeTypePlan, type: string, roleKey: string): string | null;
100
+ /** What a host reads off its directory about the scope a child is to be provisioned under. */
101
+ export interface ParentScopeFacts {
102
+ readonly tenantId: string;
103
+ readonly status: string;
104
+ readonly vertical: string | null;
105
+ /** The parent's recorded type, `home` for a row from before types. */
106
+ readonly type: string;
107
+ /** The parent's own parent, `null` when it has none. */
108
+ readonly parentScopeId: string | null;
109
+ /** The scope it was copied from, `null` when it is no copy. */
110
+ readonly forkedFrom: string | null;
111
+ }
112
+ /**
113
+ * Why a scope of `childType` may not be provisioned as a child of `parent` (#2995), or null. Read
114
+ * before the provision writes anything, by both hosts.
115
+ *
116
+ * - An unknown parent, and a parent of another tenant, are both `not_found`: a tenant learns nothing
117
+ * about another's scopes from the refusal (K-3).
118
+ * - A child runs its parent's app (`validation_failed` otherwise).
119
+ * - The parent is `active` and no copy (`conflict`): a copy holds no children, so deleting one never
120
+ * has to find any, and nothing is provisioned under a scope on its way out.
121
+ * - One level (`validation_failed`): a parent that is itself a child holds none.
122
+ * - The child's type is one the parent's type declares as a child (`validation_failed`). On a host
123
+ * that declares no types there is only `home`, which holds none.
124
+ */
125
+ export declare function childScopeRefusal(plan: ScopeTypePlan, parentScopeId: string, parent: ParentScopeFacts | undefined, child: {
126
+ readonly tenantId: string;
127
+ readonly vertical: string | null;
128
+ readonly type: string;
129
+ }): SubstratError | null;
130
+ /**
131
+ * The parent a provision gives a scope, and the rule that keeps it (#2995): the link is written when
132
+ * the scope is first provisioned and never moves. `recorded` is the directory's value for an existing
133
+ * scope (`null`: no parent), or `undefined` for a new one. A re-provision restating the link, or
134
+ * naming none, keeps it; one naming another parent, or a parent for a scope that has none, is refused.
135
+ */
136
+ export declare function provisionedParent(requested: string | undefined, recorded: string | null | undefined, scopeId: string): string | null;
137
+ /** Whether a scope of `type` admits `access`. On a host with no declared types every scope is `home`, reached directly. */
138
+ export declare function scopeTypeAccepts(plan: ScopeTypePlan, type: string, access: ScopeAccess): boolean;
139
+ /**
140
+ * Why a direct request (the person's own door, routed to the scope) may not reach this scope, or
141
+ * null (#2995). Only a scope WITH a parent is judged: a child whose type accepts `parent` only is
142
+ * reached through its parent. A typed scope with no parent (provisioned by staff, or a copy, which
143
+ * carries no link) is left as #2993 left it.
144
+ */
145
+ export declare function directAccessRefusal(plan: ScopeTypePlan, type: string, parentScopeId: string | null, scopeId: string): SubstratError | null;
146
+ /**
147
+ * Why a call from `callerScopeId` through the child door may not reach `child`, or null (#2995).
148
+ * Reach follows the link: the calling scope is the child's own parent, in the same tenant. Any other
149
+ * scope, a sibling included, is answered `not_found`, as an unknown scope is. Then the child's type
150
+ * admits `parent` (`forbidden` otherwise), and the parent is `active` (`conflict`): host code of a
151
+ * suspended or archived parent calls nothing.
152
+ */
153
+ export declare function childDoorRefusal(plan: ScopeTypePlan, tenantId: string, callerScopeId: string, childScopeId: string, child: {
154
+ readonly tenantId: string;
155
+ readonly type: string;
156
+ readonly parentScopeId: string | null;
157
+ } | undefined, parent: {
158
+ readonly tenantId: string;
159
+ readonly status: string;
160
+ } | undefined): SubstratError | null;
161
+ //# sourceMappingURL=scope-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope-types.d.ts","sourceRoot":"","sources":["../src/scope-types.ts"],"names":[],"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EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,SAAS,EAC9G,MAAM,EAAE;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,GACzE,aAAa,GAAG,IAAI,CAWtB"}
@@ -0,0 +1,227 @@
1
+ /**
2
+ * Scope types on a host (#2993, K-64): which modules a scope of each type runs, and the type a
3
+ * provision gives a scope. Both adapters read these, so a pure host and a Durable Object agree on
4
+ * what a scope of a type is.
5
+ *
6
+ * The declaration and its full rules are `@substrat-run/contracts` (`scopeTypeOffences`, which
7
+ * `definePermissions` applies at load). A host is handed the declared surface as its
8
+ * `permissions` and holds again only what it acts on: a `home` type, unique names, and modules the
9
+ * surface lists. A host given no `permissions`, or a surface declaring no types, has one `home`
10
+ * type running every registered module, as every host does today.
11
+ */
12
+ import { HOME_SCOPE_TYPE, SCOPE_TYPE_NAME, scopeTypesOfManifestJson, substratError } from '@substrat-run/contracts';
13
+ export { HOME_SCOPE_TYPE };
14
+ /**
15
+ * The `_substrat_meta` key a Durable Object records its scope's type under (#2993 part 3), as it
16
+ * records its tenant: written once at provision, read at wake. Absent is `home`, which every scope
17
+ * from before scope types is. It describes this store, never the data, so no dump carries it
18
+ * (`STORE_LOCAL_META_KEYS`): a copy's type is the one its own provision fixed.
19
+ */
20
+ export const SCOPE_TYPE_META_KEY = 'scope_type';
21
+ /** The host's plan from its `permissions`. Throws, at construction, on a declaration it cannot act on. */
22
+ export function scopeTypePlanOf(permissions) {
23
+ const declared = permissions?.scopeTypes;
24
+ if (!declared)
25
+ return { declared: false };
26
+ const listed = new Set(permissions.modules.map((m) => m.manifest.id));
27
+ const types = new Map();
28
+ const roles = new Map();
29
+ const typedRoles = new Set();
30
+ const children = new Map();
31
+ const accepts = new Map();
32
+ for (const t of declared) {
33
+ if (!SCOPE_TYPE_NAME.test(t.name))
34
+ throw new Error(`scope type '${t.name}': a name is a lowercase slug (${SCOPE_TYPE_NAME.source})`);
35
+ if (types.has(t.name))
36
+ throw new Error(`scope type '${t.name}' is declared twice`);
37
+ const unlisted = t.modules.filter((id) => !listed.has(id));
38
+ if (unlisted.length) {
39
+ throw new Error(`scope type '${t.name}' runs ${unlisted.map((id) => `'${id}'`).join(', ')}, which this host's permissions do not list. ` +
40
+ 'A type names modules of the surface it is declared on');
41
+ }
42
+ types.set(t.name, new Set(t.modules));
43
+ roles.set(t.name, new Set(t.roles ?? []));
44
+ for (const r of t.roles ?? [])
45
+ typedRoles.add(r);
46
+ children.set(t.name, new Set(t.children ?? []));
47
+ accepts.set(t.name, new Set(t.accepts ?? (t.name === HOME_SCOPE_TYPE ? ['direct'] : ['parent'])));
48
+ }
49
+ if (!types.has(HOME_SCOPE_TYPE)) {
50
+ throw new Error(`no scope type is named '${HOME_SCOPE_TYPE}': it is the type an install provisions, and every vertical has one`);
51
+ }
52
+ // #2995: what a host acts on when it writes a parent link. Every child type is declared, none is
53
+ // the home type, and a child type holds no children of its own: one level.
54
+ for (const [name, kids] of children) {
55
+ for (const kid of kids) {
56
+ if (kid === HOME_SCOPE_TYPE)
57
+ throw new Error(`scope type '${name}' names '${HOME_SCOPE_TYPE}' as a child. The home type has no parent`);
58
+ if (!types.has(kid))
59
+ throw new Error(`scope type '${name}' names child type '${kid}', which is not declared`);
60
+ if ((children.get(kid)?.size ?? 0) > 0) {
61
+ throw new Error(`scope type '${kid}' is a child type and declares children of its own. Children are one level deep (#2995)`);
62
+ }
63
+ }
64
+ }
65
+ return { declared: true, types, roles, typedRoles, children, accepts };
66
+ }
67
+ /**
68
+ * #2993 part 4: the plan of a vertical as its STORED deploy manifest declares it, for a module-less
69
+ * coordinator, which registers none of the vertical's modules and so has no `permissions` of its
70
+ * own for it. The types name the modules they run, so those are the modules listed. A manifest that
71
+ * declares no types, or none this reads, is the one implicit `home` type: such a coordinator then
72
+ * refuses every other type, as it did before the manifest carried them.
73
+ */
74
+ export function scopeTypePlanOfManifest(manifestJson) {
75
+ const declared = scopeTypesOfManifestJson(manifestJson);
76
+ if (declared === undefined)
77
+ return { declared: false };
78
+ const modules = [...new Set(declared.flatMap((t) => t.modules))].map((id) => ({ manifest: { id } }));
79
+ try {
80
+ return scopeTypePlanOf({ modules, scopeTypes: declared });
81
+ }
82
+ catch {
83
+ // A push refuses such a declaration (`pushedScopeTypeProblems`); one stored anyway is read as none.
84
+ return { declared: false };
85
+ }
86
+ }
87
+ /** Whether a scope of `type` runs `moduleId`. On a host with no declared types, every module runs. */
88
+ export function scopeTypeRuns(plan, type, moduleId) {
89
+ if (!plan.declared)
90
+ return true;
91
+ return plan.types.get(type)?.has(moduleId) ?? false;
92
+ }
93
+ /**
94
+ * The type a provision gives a scope, and the rule that keeps it: the type is fixed when the scope
95
+ * is first provisioned (#2993). `recorded` is what the directory holds for an existing scope
96
+ * (`null` for a row from before types, which is `home`), or `undefined` for a new one.
97
+ *
98
+ * Refused: a type this host does not declare (`validation_failed`), and a re-provision naming a
99
+ * type other than the one recorded (`conflict`). A re-provision that names none keeps the record.
100
+ */
101
+ export function provisionedScopeType(plan, requested, recorded, scopeId) {
102
+ if (requested !== undefined) {
103
+ const known = plan.declared ? plan.types.has(requested) : requested === HOME_SCOPE_TYPE;
104
+ if (!known) {
105
+ const names = plan.declared ? [...plan.types.keys()].sort() : [HOME_SCOPE_TYPE];
106
+ throw substratError('validation_failed', `scope type '${requested}' is not declared here (declared: ${names.join(', ')})`);
107
+ }
108
+ }
109
+ if (recorded === undefined)
110
+ return requested ?? HOME_SCOPE_TYPE;
111
+ const current = recorded ?? HOME_SCOPE_TYPE;
112
+ if (requested !== undefined && requested !== current) {
113
+ throw substratError('conflict', `scope ${scopeId} is a '${current}' scope, and a scope's type is fixed when it is provisioned: it cannot become '${requested}'`);
114
+ }
115
+ return current;
116
+ }
117
+ /**
118
+ * The refusal for an operation a scope's type does not run. `not_found`, the code an unknown
119
+ * operation answers with, because on this scope it is one: the scope carries none of that
120
+ * module's tables.
121
+ */
122
+ export function operationNotInScopeType(operation, type) {
123
+ return substratError('not_found', `unknown operation: ${operation} (a '${type}' scope does not run the module that declares it)`);
124
+ }
125
+ /**
126
+ * Why `roleKey` may not be seated at a scope of `type` (#2993 part 3), or null. A role the vertical's
127
+ * types name exists only on the types that name it: seating a clinic's role on a record scope would
128
+ * grant keys of modules that scope does not run. Admitted: every role on a host with no declared
129
+ * types, and a role no type names (one the tenant defined for itself), which is left to the door's
130
+ * own rules, as a key a host knows nothing about is.
131
+ */
132
+ export function scopeTypeRoleRefusal(plan, type, roleKey) {
133
+ if (!plan.declared || !plan.typedRoles.has(roleKey))
134
+ return null;
135
+ if (plan.roles.get(type)?.has(roleKey))
136
+ return null;
137
+ return `role '${roleKey}' does not exist on a '${type}' scope: the vertical declares it on other scope types only`;
138
+ }
139
+ /**
140
+ * Why a scope of `childType` may not be provisioned as a child of `parent` (#2995), or null. Read
141
+ * before the provision writes anything, by both hosts.
142
+ *
143
+ * - An unknown parent, and a parent of another tenant, are both `not_found`: a tenant learns nothing
144
+ * about another's scopes from the refusal (K-3).
145
+ * - A child runs its parent's app (`validation_failed` otherwise).
146
+ * - The parent is `active` and no copy (`conflict`): a copy holds no children, so deleting one never
147
+ * has to find any, and nothing is provisioned under a scope on its way out.
148
+ * - One level (`validation_failed`): a parent that is itself a child holds none.
149
+ * - The child's type is one the parent's type declares as a child (`validation_failed`). On a host
150
+ * that declares no types there is only `home`, which holds none.
151
+ */
152
+ export function childScopeRefusal(plan, parentScopeId, parent, child) {
153
+ if (!parent || parent.tenantId !== child.tenantId) {
154
+ return substratError('not_found', `unknown parent scope for tenant: (${child.tenantId}, ${parentScopeId})`);
155
+ }
156
+ if (parent.vertical !== child.vertical) {
157
+ return substratError('validation_failed', `a child runs its parent's app: scope ${parentScopeId} runs '${parent.vertical ?? 'none'}', not '${child.vertical ?? 'none'}'`);
158
+ }
159
+ if (parent.status !== 'active') {
160
+ return substratError('conflict', `scope ${parentScopeId} is ${parent.status}: a child is provisioned under an active scope only`);
161
+ }
162
+ if (parent.forkedFrom !== null) {
163
+ return substratError('conflict', `scope ${parentScopeId} is a copy, and a copy holds no children`);
164
+ }
165
+ if (parent.parentScopeId !== null) {
166
+ return substratError('validation_failed', `scope ${parentScopeId} is a child itself, and children are one level deep`);
167
+ }
168
+ const allowed = plan.declared ? plan.children.get(parent.type) : undefined;
169
+ if (!allowed?.has(child.type)) {
170
+ const names = allowed && allowed.size ? [...allowed].sort().join(', ') : 'none';
171
+ return substratError('validation_failed', `a '${parent.type}' scope holds no '${child.type}' children (its type declares: ${names})`);
172
+ }
173
+ return null;
174
+ }
175
+ /**
176
+ * The parent a provision gives a scope, and the rule that keeps it (#2995): the link is written when
177
+ * the scope is first provisioned and never moves. `recorded` is the directory's value for an existing
178
+ * scope (`null`: no parent), or `undefined` for a new one. A re-provision restating the link, or
179
+ * naming none, keeps it; one naming another parent, or a parent for a scope that has none, is refused.
180
+ */
181
+ export function provisionedParent(requested, recorded, scopeId) {
182
+ if (recorded === undefined)
183
+ return requested ?? null;
184
+ if (requested !== undefined && requested !== recorded) {
185
+ throw substratError('conflict', recorded === null
186
+ ? `scope ${scopeId} has no parent, and a parent link is written only when a child is provisioned`
187
+ : `scope ${scopeId} is a child of ${recorded}, and a scope's parent is fixed when it is provisioned`);
188
+ }
189
+ return recorded;
190
+ }
191
+ /** Whether a scope of `type` admits `access`. On a host with no declared types every scope is `home`, reached directly. */
192
+ export function scopeTypeAccepts(plan, type, access) {
193
+ if (!plan.declared)
194
+ return access === 'direct';
195
+ return plan.accepts.get(type)?.has(access) ?? false;
196
+ }
197
+ /**
198
+ * Why a direct request (the person's own door, routed to the scope) may not reach this scope, or
199
+ * null (#2995). Only a scope WITH a parent is judged: a child whose type accepts `parent` only is
200
+ * reached through its parent. A typed scope with no parent (provisioned by staff, or a copy, which
201
+ * carries no link) is left as #2993 left it.
202
+ */
203
+ export function directAccessRefusal(plan, type, parentScopeId, scopeId) {
204
+ if (parentScopeId === null || scopeTypeAccepts(plan, type, 'direct'))
205
+ return null;
206
+ return substratError('forbidden', `scope ${scopeId} is a '${type}' scope, reached through its parent only`);
207
+ }
208
+ /**
209
+ * Why a call from `callerScopeId` through the child door may not reach `child`, or null (#2995).
210
+ * Reach follows the link: the calling scope is the child's own parent, in the same tenant. Any other
211
+ * scope, a sibling included, is answered `not_found`, as an unknown scope is. Then the child's type
212
+ * admits `parent` (`forbidden` otherwise), and the parent is `active` (`conflict`): host code of a
213
+ * suspended or archived parent calls nothing.
214
+ */
215
+ export function childDoorRefusal(plan, tenantId, callerScopeId, childScopeId, child, parent) {
216
+ if (!child || child.tenantId !== tenantId || child.parentScopeId !== callerScopeId || !parent || parent.tenantId !== tenantId) {
217
+ return substratError('not_found', `scope ${childScopeId} is no child of scope ${callerScopeId} in tenant ${tenantId}`);
218
+ }
219
+ if (!scopeTypeAccepts(plan, child.type, 'parent')) {
220
+ return substratError('forbidden', `scope ${childScopeId} is a '${child.type}' scope, which does not accept calls through its parent`);
221
+ }
222
+ if (parent.status !== 'active') {
223
+ return substratError('conflict', `scope ${callerScopeId} is ${parent.status}, so it calls none of its children`);
224
+ }
225
+ return null;
226
+ }
227
+ //# sourceMappingURL=scope-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope-types.js","sourceRoot":"","sources":["../src/scope-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,wBAAwB,EAAE,aAAa,EAAsB,MAAM,yBAAyB,CAAC;AAExI,OAAO,EAAE,eAAe,EAAE,CAAC;AAiB3B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,YAAY,CAAC;AA+BhD,0GAA0G;AAC1G,MAAM,UAAU,eAAe,CAAC,WAAwC;IACtE,MAAM,QAAQ,GAAG,WAAW,EAAE,UAAU,CA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reProof } from '@substrat-run/contracts';
2
+ import type { ScopedSql } from './scope-host.js';
3
+ export declare const STORE_PROOF_DDL = "\n CREATE TABLE IF NOT EXISTS _substrat_store_proofs (\n id TEXT PRIMARY KEY,\n -- SHA-256 hex of the secret. The secret itself is stored NOWHERE.\n token_hash TEXT NOT NULL UNIQUE,\n binding TEXT NOT NULL,\n operation TEXT NOT NULL,\n -- The principal whose operation checked the key, and the only one whose stub may redeem it.\n minted_by TEXT NOT NULL,\n minted_at TEXT NOT NULL,\n expires_at TEXT NOT NULL,\n -- Set by the one redemption. A spent proof is refused like an unknown one.\n redeemed_at TEXT\n );\n CREATE INDEX IF NOT EXISTS _substrat_store_proofs_expires\n ON _substrat_store_proofs (expires_at);\n";
4
+ /** The tables `STORE_PROOF_DDL` builds — what a copy of a scope leaves behind. */
5
+ export declare const STORE_PROOF_TABLE_NAMES: readonly ['_substrat_store_proofs'];
6
+ /** What the mint needs: the operation's own seams, and the vertical's declared store keys. */
7
+ export interface StoreProofVerbDeps {
8
+ /** RAW spine access inside the operation's own transaction. */
9
+ sql: ScopedSql;
10
+ subject: CheckSubject;
11
+ /** True when this context is a consumer's, whose checks allow unconditionally. */
12
+ consumer: boolean;
13
+ /**
14
+ * The clock read when the proof is minted, not the operation's stable instant: a proof's minute
15
+ * starts at its mint, so a handler that ran long before minting still hands out a whole one.
16
+ */
17
+ now: Instant;
18
+ /** The operation's OWN check, so the key's pass is one of its authorizations. */
19
+ check: (permission: PermissionKey, entity?: EntityRef) => Promise<Decision>;
20
+ assertWrites: (verb: string) => void;
21
+ /** This invocation's minted secrets — the tripwire on its writes reads them. */
22
+ minted: string[];
23
+ /** The key the vertical declared for a store operation, or `undefined`. */
24
+ keyOf: (binding: string, operation: string) => string | undefined;
25
+ /** How long a proof lives. {@link STORE_PROOF_TTL_SECONDS} unless a host is told otherwise. */
26
+ ttlSeconds?: number;
27
+ }
28
+ /** `ctx.storeProof`: check the store operation's key and record a proof of it. See the file header. */
29
+ export declare function mintStoreProof(deps: StoreProofVerbDeps, binding: unknown, operation: unknown): Promise<StoreProof>;
30
+ /** The secret a caller handed the stub: the proof `ctx.storeProof` returned, or its `proof` string. */
31
+ export declare function storeProofSecretOf(proof: unknown): string | undefined;
32
+ /**
33
+ * Spend a proof on one store call. Runs on the scope's own queue, outside any operation, so the read
34
+ * and the write below cannot interleave with another redemption. Refuses unless the proof names a row
35
+ * of this scope, for `binding`, `operation` and `principal`, unexpired and unspent.
36
+ */
37
+ export declare function redeemStoreProof(deps: {
38
+ sql: ScopedSql;
39
+ now: Instant;
40
+ }, secret: unknown, expect: {
41
+ binding: string;
42
+ operation: string;
43
+ principal: string;
44
+ }): Promise<void>;
45
+ //# sourceMappingURL=store-proof.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store-proof.d.ts","sourceRoot":"","sources":["../src/store-proof.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,KAAK,UAAU,EAChB,MAAM,yBAAyB,CAAC;AAIjC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAqCjD,eAAO,MAAM,eAAe,opBAgB3B,CAAC;AAEF,kFAAkF;AAClF,eAAO,MAAM,uBAAuB,YAAI,wBAAwB,CAAU,CAAC;AAE3E,8FAA8F;AAC9F,MAAM,WAAW,kBAAkB;IACjC,+DAA+D;IAC/D,GAAG,EAAE,SAAS,CAAC;IACf,OAAO,EAAE,YAAY,CAAC;IACtB,kFAAkF;IAClF,QAAQ,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,GAAG,EAAE,OAAO,CAAC;IACb,iFAAiF;IACjF,KAAK,EAAE,CAAC,UAAU,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,SAAS,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC5E,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,gFAAgF;IAChF,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,2EAA2E;IAC3E,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IAClE,+FAA+F;IAC/F,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAUD,uGAAuG;AACvG,wBAAsB,cAAc,CAAC,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAwCxH;AAQD,uGAAuG;AACvG,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAMrE;AAWD;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE;IAAE,GAAG,EAAE,SAAS,CAAC;IAAC,GAAG,EAAE,OAAO,CAAA;CAAE,EACtC,MAAM,EAAE,OAAO,EACf,MAAM,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAChE,OAAO,CAAC,IAAI,CAAC,CAuBf"}
@@ -0,0 +1,97 @@
1
+ import { STORE_PROOF_PREFIX, STORE_PROOF_REFUSED, STORE_PROOF_TTL_SECONDS, isStoreProofShape, storeCatalogOperation, substratError, } from '@substrat-run/contracts';
2
+ import { toBase64url } from './base64url.js';
3
+ import { capabilityTokenHash } from './capability.js';
4
+ import { assertAllowed } from './permission-checker.js';
5
+ import { ulid } from './ulid.js';
6
+ export const STORE_PROOF_DDL = `
7
+ CREATE TABLE IF NOT EXISTS _substrat_store_proofs (
8
+ id TEXT PRIMARY KEY,
9
+ -- SHA-256 hex of the secret. The secret itself is stored NOWHERE.
10
+ token_hash TEXT NOT NULL UNIQUE,
11
+ binding TEXT NOT NULL,
12
+ operation TEXT NOT NULL,
13
+ -- The principal whose operation checked the key, and the only one whose stub may redeem it.
14
+ minted_by TEXT NOT NULL,
15
+ minted_at TEXT NOT NULL,
16
+ expires_at TEXT NOT NULL,
17
+ -- Set by the one redemption. A spent proof is refused like an unknown one.
18
+ redeemed_at TEXT
19
+ );
20
+ CREATE INDEX IF NOT EXISTS _substrat_store_proofs_expires
21
+ ON _substrat_store_proofs (expires_at);
22
+ `;
23
+ /** The tables `STORE_PROOF_DDL` builds — what a copy of a scope leaves behind. */
24
+ export const STORE_PROOF_TABLE_NAMES = ['_substrat_store_proofs'];
25
+ const VERB = 'ctx.storeProof';
26
+ const BINDING = /^[A-Z][A-Z0-9_]*$/;
27
+ /** A fresh proof secret: 256 bits, base64url, prefixed. Only its hash is ever stored. */
28
+ function mintStoreProofSecret() {
29
+ return STORE_PROOF_PREFIX + toBase64url(crypto.getRandomValues(new Uint8Array(32)));
30
+ }
31
+ /** `ctx.storeProof`: check the store operation's key and record a proof of it. See the file header. */
32
+ export async function mintStoreProof(deps, binding, operation) {
33
+ deps.assertWrites(VERB);
34
+ if (deps.consumer || deps.subject.kind !== 'principal') {
35
+ throw substratError('forbidden', `${VERB}: only an operation a principal called may mint a store proof — a consumer's checks allow ` +
36
+ 'unconditionally, and a capability, a peer or a system actor has no host code to make the call', { reason: STORE_PROOF_REFUSED });
37
+ }
38
+ if (typeof binding !== 'string' || !BINDING.test(binding)) {
39
+ throw substratError('validation_failed', `${VERB}: '${String(binding)}' is not a store binding`);
40
+ }
41
+ if (!storeCatalogOperation.safeParse(operation).success) {
42
+ throw substratError('validation_failed', `${VERB}: '${String(operation)}' is not a store operation a vertical may call`);
43
+ }
44
+ const op = operation;
45
+ const key = deps.keyOf(binding, op);
46
+ if (key === undefined) {
47
+ throw substratError('forbidden', `${VERB}: store '${binding}' operation '${op}' has no permission key, so it cannot be called. ` +
48
+ 'Declare it on definePermissions `stores` (K-64).', { reason: STORE_PROOF_REFUSED });
49
+ }
50
+ assertAllowed(await deps.check(key));
51
+ const secret = mintStoreProofSecret();
52
+ const ttl = deps.ttlSeconds ?? STORE_PROOF_TTL_SECONDS;
53
+ const expiresAt = new Date(Date.parse(deps.now) + ttl * 1000).toISOString();
54
+ // A proof past its expiry redeems nothing, so its row is only weight: each mint clears them.
55
+ deps.sql.exec('DELETE FROM _substrat_store_proofs WHERE expires_at <= ?', [deps.now]);
56
+ deps.sql.exec(`INSERT INTO _substrat_store_proofs (id, token_hash, binding, operation, minted_by, minted_at, expires_at)
57
+ VALUES (?, ?, ?, ?, ?, ?, ?)`, [ulid(), await capabilityTokenHash(secret), binding, op, deps.subject.id, deps.now, expiresAt]);
58
+ deps.minted.push(secret);
59
+ return { proof: secret, binding, operation: op, expiresAt };
60
+ }
61
+ /** One answer for every refused redemption, so a wrong proof says nothing about which part was wrong. */
62
+ const refused = () => substratError('forbidden', 'store call refused: it carries no live proof an operation minted for this store operation', {
63
+ reason: STORE_PROOF_REFUSED,
64
+ });
65
+ /** The secret a caller handed the stub: the proof `ctx.storeProof` returned, or its `proof` string. */
66
+ export function storeProofSecretOf(proof) {
67
+ if (typeof proof === 'string')
68
+ return proof;
69
+ if (proof !== null && typeof proof === 'object' && typeof proof.proof === 'string') {
70
+ return proof.proof;
71
+ }
72
+ return undefined;
73
+ }
74
+ /**
75
+ * Spend a proof on one store call. Runs on the scope's own queue, outside any operation, so the read
76
+ * and the write below cannot interleave with another redemption. Refuses unless the proof names a row
77
+ * of this scope, for `binding`, `operation` and `principal`, unexpired and unspent.
78
+ */
79
+ export async function redeemStoreProof(deps, secret, expect) {
80
+ if (!isStoreProofShape(secret))
81
+ throw refused();
82
+ const row = deps.sql.query('SELECT id, binding, operation, minted_by, expires_at, redeemed_at FROM _substrat_store_proofs WHERE token_hash = ?', [await capabilityTokenHash(secret)])[0];
83
+ if (!row ||
84
+ row.binding !== expect.binding ||
85
+ row.operation !== expect.operation ||
86
+ row.minted_by !== expect.principal ||
87
+ row.redeemed_at !== null ||
88
+ row.expires_at <= deps.now) {
89
+ throw refused();
90
+ }
91
+ // The row the UPDATE returns, not `changes`: a Durable Object counts a trigger's writes in it too
92
+ // (a live capture's log), which would refuse a good proof after spending it.
93
+ const spent = deps.sql.query('UPDATE _substrat_store_proofs SET redeemed_at = ? WHERE id = ? AND redeemed_at IS NULL RETURNING id', [deps.now, row.id]);
94
+ if (spent.length !== 1)
95
+ throw refused();
96
+ }
97
+ //# sourceMappingURL=store-proof.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store-proof.js","sourceRoot":"","sources":["../src/store-proof.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,uBAAuB,EACvB,iBAAiB,EACjB,qBAAqB,EACrB,aAAa,GAOd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAoCjC,MAAM,CAAC,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;;CAgB9B,CAAC;AAEF,kFAAkF;AAClF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,wBAAwB,CAAU,CAAC;AAyB3E,MAAM,IAAI,GAAG,gBAAgB,CAAC;AAC9B,MAAM,OAAO,GAAG,mBAAmB,CAAC;AAEpC,yFAAyF;AACzF,SAAS,oBAAoB;IAC3B,OAAO,kBAAkB,GAAG,WAAW,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AACtF,CAAC;AAED,uGAAuG;AACvG,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAAwB,EAAE,OAAgB,EAAE,SAAkB;IACjG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IACxB,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAA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