@capybara-hq/kernel 0.1.0-rc.145 → 0.1.0-rc.147

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 (185) hide show
  1. package/dist/admin/extensions.controller.d.ts +0 -11
  2. package/dist/admin/extensions.controller.js +0 -28
  3. package/dist/admin/health.service.d.ts +25 -1
  4. package/dist/admin/health.service.js +50 -18
  5. package/dist/audit/full-access.d.ts +78 -0
  6. package/dist/audit/full-access.js +283 -0
  7. package/dist/automations/automations.service.d.ts +1 -0
  8. package/dist/automations/automations.service.js +3 -1
  9. package/dist/automations/calendar.js +3 -1
  10. package/dist/automations/grant-rules.d.ts +2 -1
  11. package/dist/automations/grant-rules.js +8 -1
  12. package/dist/automations/unattended.d.ts +13 -1
  13. package/dist/automations/unattended.js +13 -1
  14. package/dist/catalog/admin-catalog.controller.d.ts +8 -0
  15. package/dist/catalog/admin-catalog.controller.js +8 -2
  16. package/dist/catalog/admin-catalog.schemas.d.ts +10 -0
  17. package/dist/catalog/admin-catalog.schemas.js +8 -1
  18. package/dist/catalog/catalog-content.d.ts +6 -0
  19. package/dist/catalog/catalog-scope.service.d.ts +22 -2
  20. package/dist/catalog/catalog-scope.service.js +27 -3
  21. package/dist/catalog/catalog.service.js +19 -2
  22. package/dist/catalog/marketplaces.service.d.ts +1 -1
  23. package/dist/catalog/org-catalog.service.d.ts +8 -1
  24. package/dist/catalog/org-catalog.service.js +36 -3
  25. package/dist/catalog/platform-components.js +3 -2
  26. package/dist/catalog/platform-import-update.d.ts +2 -0
  27. package/dist/catalog/platform-import-update.js +8 -1
  28. package/dist/catalog/plugin-connectors.d.ts +11 -0
  29. package/dist/catalog/plugin-connectors.js +33 -0
  30. package/dist/catalog/plugin-import.d.ts +35 -15
  31. package/dist/catalog/plugin-import.js +110 -35
  32. package/dist/catalog/plugin-install.js +6 -0
  33. package/dist/catalog/provenance.d.ts +71 -0
  34. package/dist/catalog/provenance.js +112 -0
  35. package/dist/config/auto-approve.d.ts +16 -0
  36. package/dist/config/auto-approve.js +24 -0
  37. package/dist/config/capacity-presets.d.ts +243 -0
  38. package/dist/config/capacity-presets.js +195 -0
  39. package/dist/config/env.d.ts +2 -1
  40. package/dist/config/env.js +6 -1
  41. package/dist/config/load.js +15 -0
  42. package/dist/config/schema.d.ts +46 -9
  43. package/dist/config/schema.js +154 -30
  44. package/dist/ctx/create-ctx.d.ts +16 -0
  45. package/dist/ctx/create-ctx.js +269 -34
  46. package/dist/ctx/net.d.ts +5 -1
  47. package/dist/ctx/net.js +62 -12
  48. package/dist/db/kernel-schema.d.ts +31 -0
  49. package/dist/db/migrator.js +0 -36
  50. package/dist/dial-in/routes.js +1 -1
  51. package/dist/erasure/org-batches.js +1 -6
  52. package/dist/erasure/org-catalog.js +6 -2
  53. package/dist/erasure/org-rules.js +1 -0
  54. package/dist/erasure/org-worker.js +0 -13
  55. package/dist/errors.d.ts +6 -0
  56. package/dist/errors.js +6 -0
  57. package/dist/extensions/admin-ops.d.ts +14 -1
  58. package/dist/extensions/admin-ops.js +30 -3
  59. package/dist/extensions/admin-view.d.ts +21 -1
  60. package/dist/extensions/admin-view.js +43 -0
  61. package/dist/extensions/bootstrap-packages.d.ts +5 -0
  62. package/dist/extensions/bootstrap-packages.js +1 -1
  63. package/dist/extensions/bootstrap-review.d.ts +251 -0
  64. package/dist/extensions/bootstrap-review.js +676 -0
  65. package/dist/extensions/bootstrap.d.ts +21 -1
  66. package/dist/extensions/bootstrap.js +72 -2
  67. package/dist/extensions/cli.d.ts +6 -0
  68. package/dist/extensions/cli.js +4 -0
  69. package/dist/extensions/enabled.d.ts +3 -0
  70. package/dist/extensions/execution-realm.d.ts +96 -0
  71. package/dist/extensions/execution-realm.js +141 -0
  72. package/dist/extensions/extensions.module.js +12 -0
  73. package/dist/extensions/full-access-disclosure.d.ts +15 -0
  74. package/dist/extensions/full-access-disclosure.js +57 -0
  75. package/dist/extensions/grant-epoch.d.ts +9 -2
  76. package/dist/extensions/grant-epoch.js +13 -2
  77. package/dist/extensions/host.d.ts +96 -4
  78. package/dist/extensions/host.js +411 -33
  79. package/dist/extensions/installs.d.ts +18 -0
  80. package/dist/extensions/installs.js +28 -0
  81. package/dist/extensions/instance.d.ts +2 -0
  82. package/dist/extensions/instance.js +1 -0
  83. package/dist/extensions/isolated/admission.d.ts +23 -2
  84. package/dist/extensions/isolated/admission.js +32 -7
  85. package/dist/extensions/isolated/authorization.d.ts +8 -2
  86. package/dist/extensions/isolated/authorization.js +11 -3
  87. package/dist/extensions/isolated/broker.d.ts +3 -0
  88. package/dist/extensions/isolated/broker.js +50 -14
  89. package/dist/extensions/isolated/configured-package.d.ts +5 -0
  90. package/dist/extensions/isolated/configured-package.js +2 -0
  91. package/dist/extensions/isolated/lanes.d.ts +44 -3
  92. package/dist/extensions/isolated/lanes.js +263 -80
  93. package/dist/extensions/isolated/metrics.d.ts +146 -0
  94. package/dist/extensions/isolated/metrics.js +304 -0
  95. package/dist/extensions/isolated/revision.d.ts +7 -1
  96. package/dist/extensions/isolated/revision.js +26 -5
  97. package/dist/extensions/isolated/rpc.d.ts +5 -0
  98. package/dist/extensions/isolated/rpc.js +7 -2
  99. package/dist/extensions/isolated/sandbox.d.ts +23 -0
  100. package/dist/extensions/isolated/sandbox.js +50 -0
  101. package/dist/extensions/isolated/status.d.ts +79 -0
  102. package/dist/extensions/isolated/status.js +216 -0
  103. package/dist/extensions/isolated/tier.d.ts +127 -2
  104. package/dist/extensions/isolated/tier.js +266 -7
  105. package/dist/extensions/isolated/usage.d.ts +134 -0
  106. package/dist/extensions/isolated/usage.js +322 -0
  107. package/dist/extensions/ledger.d.ts +5 -0
  108. package/dist/extensions/ledger.js +16 -0
  109. package/dist/extensions/lifecycle.d.ts +42 -2
  110. package/dist/extensions/lifecycle.js +100 -4
  111. package/dist/extensions/org-config.js +11 -0
  112. package/dist/extensions/package.d.ts +14 -0
  113. package/dist/extensions/package.js +23 -0
  114. package/dist/extensions/permission-view.d.ts +2 -2
  115. package/dist/extensions/permissions.controller.d.ts +35 -0
  116. package/dist/extensions/permissions.controller.js +98 -0
  117. package/dist/extensions/permissions.schemas.d.ts +288 -0
  118. package/dist/extensions/permissions.schemas.js +96 -0
  119. package/dist/extensions/permissions.service.d.ts +116 -0
  120. package/dist/extensions/permissions.service.js +428 -0
  121. package/dist/extensions/realm-retirement.d.ts +65 -0
  122. package/dist/extensions/realm-retirement.js +150 -0
  123. package/dist/extensions/registry.d.ts +6 -0
  124. package/dist/extensions/registry.js +8 -0
  125. package/dist/extensions/review-hash.d.ts +114 -0
  126. package/dist/extensions/review-hash.js +145 -0
  127. package/dist/extensions/revision-approvals.d.ts +58 -3
  128. package/dist/extensions/revision-approvals.js +135 -14
  129. package/dist/extensions/revision-grants.d.ts +10 -0
  130. package/dist/extensions/revision-review.d.ts +144 -0
  131. package/dist/extensions/revision-review.js +297 -0
  132. package/dist/extensions/revocation-leases.d.ts +273 -0
  133. package/dist/extensions/revocation-leases.js +533 -0
  134. package/dist/extensions/revocation.d.ts +78 -0
  135. package/dist/extensions/revocation.js +205 -0
  136. package/dist/extensions/state.module.js +12 -0
  137. package/dist/git/run-end.d.ts +35 -7
  138. package/dist/git/run-end.js +87 -38
  139. package/dist/http/api.module.js +2 -0
  140. package/dist/identity/audit.d.ts +2 -1
  141. package/dist/identity/audit.js +4 -17
  142. package/dist/index.d.ts +10 -2
  143. package/dist/index.js +10 -2
  144. package/dist/infra/config/kernel-config.service.d.ts +6 -0
  145. package/dist/infra/config/kernel-config.service.js +21 -0
  146. package/dist/infra/outbox/registry.d.ts +13 -0
  147. package/dist/infra/outbox/registry.js +8 -0
  148. package/dist/lifecycle/kernel-lifecycle.d.ts +27 -1
  149. package/dist/lifecycle/kernel-lifecycle.js +83 -22
  150. package/dist/net/private-endpoint-preflight.d.ts +159 -0
  151. package/dist/net/private-endpoint-preflight.js +417 -0
  152. package/dist/net/private-endpoints.d.ts +68 -0
  153. package/dist/net/private-endpoints.js +164 -0
  154. package/dist/net/public-address.d.ts +14 -0
  155. package/dist/net/public-address.js +15 -1
  156. package/dist/net/safe-fetch.d.ts +2 -1
  157. package/dist/net/safe-fetch.js +10 -3
  158. package/dist/overrides.d.ts +9 -1
  159. package/dist/overrides.js +4 -0
  160. package/dist/packages/official-publisher.d.ts +65 -1
  161. package/dist/packages/official-publisher.js +171 -46
  162. package/dist/packages/provenance.d.ts +11 -0
  163. package/dist/packages/provenance.js +24 -0
  164. package/dist/platform/exclusions.js +4 -4
  165. package/dist/platform/ops/automations.ops.js +1 -1
  166. package/dist/platform/ops/catalog-admin.ops.js +25 -4
  167. package/dist/platform/ops/extension-permissions.ops.d.ts +11 -0
  168. package/dist/platform/ops/extension-permissions.ops.js +159 -0
  169. package/dist/platform/platform-ops.module.d.ts +2 -1
  170. package/dist/platform/platform-ops.module.js +2 -0
  171. package/dist/platform/route-schemas.js +2 -0
  172. package/dist/retention/purge-batch.js +10 -14
  173. package/dist/runtime/maintenance.d.ts +4 -2
  174. package/dist/runtime/maintenance.js +16 -3
  175. package/dist/runtime/run-finish.d.ts +3 -3
  176. package/dist/runtime/run-finish.js +7 -3
  177. package/dist/sandbox/permission-availability.d.ts +17 -2
  178. package/dist/sandbox/permission-availability.js +22 -1
  179. package/dist/sandbox/permission-facts.js +7 -1
  180. package/dist/tools/builtins/sandbox/common.js +2 -0
  181. package/dist/tools/pipeline.d.ts +2 -1
  182. package/dist/tools/pipeline.js +7 -2
  183. package/package.json +4 -3
  184. package/src/migrations/0238_extension_usage.sql +40 -0
  185. package/src/migrations/0239_extension_replica_isolation.sql +28 -0
@@ -0,0 +1,297 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { Inject, Injectable } from "@nestjs/common";
11
+ import semver from "semver";
12
+ import { ApiError } from "../errors.js";
13
+ import { audit } from "../identity/audit.js";
14
+ import { KernelDb } from "../infra/database/kernel-db.js";
15
+ import { TransactionHost } from "../infra/database/transaction-host.js";
16
+ import { Transactional } from "../infra/database/transactional.decorator.js";
17
+ import { executionDecision } from "./execution-realm.js";
18
+ import { deploymentConfigIsolatable } from "./isolated/admission.js";
19
+ import { IsolationStatusReader } from "./isolated/status.js";
20
+ import { permissionKeys } from "./permission-set.js";
21
+ import { grantPurposeRows, reviewDisplay, revisionReviewHash, } from "./review-hash.js";
22
+ import { scopeWider } from "./revision-approvals.js";
23
+ import { continuityProblem, ExtensionRevisionGrants, isLive, RevisionGrantError, } from "./revision-grants.js";
24
+ const sortedScope = (scope) => scope.mode === "named" ? { mode: "named", orgs: [...new Set(scope.orgs)].sort() } : scope;
25
+ /** The review of one revision. Pure. */
26
+ export function buildRevisionReview(input) {
27
+ const approvalScope = sortedScope(input.approvalScope);
28
+ const server = true;
29
+ const client = input.pkg.section.client !== undefined ? {} : undefined;
30
+ const configSchemaIsolatable = deploymentConfigIsolatable(input.pkg.section);
31
+ const decision = executionDecision({
32
+ keys: permissionKeys(input.set),
33
+ server,
34
+ client,
35
+ host: input.host,
36
+ configSchemaIsolatable,
37
+ });
38
+ const { rows } = grantPurposeRows(input.set, decision);
39
+ const { own, previous } = input;
40
+ const ownLive = own !== undefined && isLive(own.state);
41
+ const lower = previous !== undefined &&
42
+ semver.valid(input.revision.version) !== null &&
43
+ semver.valid(previous.revision.version) !== null &&
44
+ semver.lt(input.revision.version, previous.revision.version);
45
+ const problem =
46
+ // A revoked or retired revision comes back only through a fresh human review, never continuity
47
+ own !== undefined && !ownLive
48
+ ? `its grant is ${own.state}; only a new review restores it`
49
+ : ownLive && scopeWider(approvalScope, own.approvalScope)
50
+ ? `the live grant of this revision covers the ${own.approvalScope.mode} scope only; revoke it to review the ${approvalScope.mode} scope`
51
+ : // a rollback is served only under the selected revision's own grant, never continuity
52
+ lower
53
+ ? "a version below the approved one is a rollback: it needs its own grant"
54
+ : previous
55
+ ? continuityProblem(previous, {
56
+ purposes: rows,
57
+ realms: decision.fullAccess,
58
+ approvalScope,
59
+ publisher: input.publisher,
60
+ })
61
+ : "there is no approved revision to continue";
62
+ const consent = ownLive && !scopeWider(approvalScope, own.approvalScope)
63
+ ? { kind: "granted", generation: own.generation }
64
+ : problem === undefined
65
+ ? { kind: "continuity" }
66
+ : { kind: "review", reason: problem };
67
+ // The display shows the authority the confirm exercises: a continuation carries its source's
68
+ const authority = consent.kind === "continuity" && previous
69
+ ? previous.authority
70
+ : consent.kind === "granted" && own
71
+ ? own.authority
72
+ : (input.authority ?? "super_admin");
73
+ const display = reviewDisplay({
74
+ revision: input.revision,
75
+ set: input.set,
76
+ host: input.host,
77
+ server,
78
+ client,
79
+ configSchemaIsolatable,
80
+ approvalScope,
81
+ authority,
82
+ publisher: input.publisher,
83
+ evidenceDigest: input.evidenceDigest,
84
+ previous,
85
+ });
86
+ const blocked = display.missingPurposes.length > 0
87
+ ? `missing purposes: ${display.missingPurposes.join(", ")}; republish with purposes`
88
+ : !display.execution.confirmable
89
+ ? `unknown permission keys: ${display.unknownKeys.join(", ")}`
90
+ : undefined;
91
+ return {
92
+ revision: { ...input.revision },
93
+ publisher: input.publisher,
94
+ evidenceDigest: input.evidenceDigest ?? null,
95
+ preparedScope: approvalScope,
96
+ display,
97
+ hash: revisionReviewHash(display),
98
+ consent,
99
+ acknowledge: consent.kind === "review"
100
+ ? Object.keys(decision.fullAccess).sort()
101
+ : [],
102
+ ...(blocked !== undefined && { blocked }),
103
+ };
104
+ }
105
+ /**
106
+ * Checks a full-access acknowledgement sent with a confirm against the prepared review (1.3d).
107
+ * Absent is allowed until plan task 1.5a (the grant is skipped); present, it must name the
108
+ * review's hash and exactly the realms the review needs acknowledged, else 409
109
+ * `plugin.full_access_ack_invalid`.
110
+ */
111
+ export function checkAcknowledgement(review, ack) {
112
+ if (ack === undefined)
113
+ return;
114
+ const invalid = (why) => new ApiError("plugin.full_access_ack_invalid", `The full-access acknowledgement does not match this review: ${why}; review it again and acknowledge each realm`, [{ reason: why }]);
115
+ if (ack.reviewHash !== review.hash)
116
+ throw invalid("it was given for another review");
117
+ const given = [...new Set(ack.realms)].sort();
118
+ const needed = review.acknowledge;
119
+ const missing = needed.filter((realm) => !given.includes(realm));
120
+ const extra = given.filter((realm) => !needed.includes(realm));
121
+ if (missing.length > 0)
122
+ throw invalid(`full access for ${missing.join(", ")} is not acknowledged`);
123
+ if (extra.length > 0)
124
+ throw invalid(`${extra.join(", ")} needs no full-access acknowledgement`);
125
+ }
126
+ /** Prepare and confirm of revision reviews, and the grant a confirmation records. */
127
+ let RevisionReviews = class RevisionReviews {
128
+ kdb;
129
+ txHost;
130
+ grants;
131
+ isolation;
132
+ constructor(kdb, txHost, grants,
133
+ /** The host profile a review binds (plan task 1.4j): configured or not. */
134
+ isolation) {
135
+ this.kdb = kdb;
136
+ this.txHost = txHost;
137
+ this.grants = grants;
138
+ this.isolation = isolation;
139
+ }
140
+ /** The live grant of the install's approved revision, if any. */
141
+ async previousGrant(plugin) {
142
+ let approved;
143
+ try {
144
+ ({ approved } = await this.grants.installRevisions(plugin));
145
+ }
146
+ catch (err) {
147
+ // not installed yet: nothing to continue
148
+ if (err instanceof RevisionGrantError && err.code === "not_found")
149
+ return undefined;
150
+ throw err;
151
+ }
152
+ return approved ? this.grants.live(approved) : undefined;
153
+ }
154
+ /** The review of a revision as prepare shows it. */
155
+ async prepare(input) {
156
+ return buildRevisionReview({
157
+ ...input,
158
+ host: await this.isolation.reviewProfile(),
159
+ previous: await this.previousGrant(input.revision.plugin),
160
+ own: await this.grants.get(input.revision),
161
+ });
162
+ }
163
+ /**
164
+ * At confirm, in the confirm's transaction (under the extension's install lock): rechecks the
165
+ * prepared review against the current previous grant and host, then records the grant for the
166
+ * chosen scope. Returns `stale` when the review no longer holds; never throws for a grant that
167
+ * cannot be recorded in shadow mode (the outcome says why).
168
+ */
169
+ async confirm(input) {
170
+ const { prepared } = input;
171
+ const host = await this.isolation.reviewProfile();
172
+ const previous = await this.previousGrant(prepared.revision.plugin);
173
+ const own = await this.grants.get(prepared.revision);
174
+ const base = {
175
+ revision: prepared.revision,
176
+ pkg: input.pkg,
177
+ set: input.set,
178
+ host,
179
+ publisher: prepared.publisher,
180
+ evidenceDigest: prepared.evidenceDigest ?? undefined,
181
+ previous,
182
+ own,
183
+ authority: input.operator ? "operator" : "super_admin",
184
+ };
185
+ const again = buildRevisionReview({ ...base, approvalScope: prepared.preparedScope });
186
+ if (again.hash !== prepared.hash)
187
+ return "stale";
188
+ const chosen = buildRevisionReview({ ...base, approvalScope: input.approvalScope });
189
+ // A kept grant the person saw must still be there: revoked since prepare, the review is stale
190
+ // (checked at the prepared scope: a scope widened at confirm is a review its acknowledgement
191
+ // does not cover, skipped below, not a stale review)
192
+ if (prepared.consent.kind === "granted" && again.consent.kind !== "granted")
193
+ return "stale";
194
+ if (chosen.consent.kind === "granted") {
195
+ return { status: "kept", generation: chosen.consent.generation };
196
+ }
197
+ if (input.actor === null) {
198
+ if (!input.operator) {
199
+ return { status: "skipped", reason: "only a person's review records a grant" };
200
+ }
201
+ }
202
+ if (chosen.blocked !== undefined)
203
+ return { status: "skipped", reason: chosen.blocked };
204
+ const decision = executionDecision({
205
+ keys: permissionKeys(input.set),
206
+ server: true,
207
+ client: input.pkg.section.client !== undefined ? {} : undefined,
208
+ host,
209
+ configSchemaIsolatable: deploymentConfigIsolatable(input.pkg.section),
210
+ });
211
+ const { rows } = grantPurposeRows(input.set, decision);
212
+ const continuing = chosen.consent.kind === "continuity" && previous !== undefined;
213
+ // The acknowledgement binds the prepared hash; the scope chosen after it does not widen what
214
+ // full access reaches (org scope cannot confine it)
215
+ // A review grant needs every realm it confers acknowledged. The acknowledgement was checked
216
+ // against the prepared review; the scope chosen at confirm can still turn a continuation into
217
+ // a review (a wider scope), whose realms it then does not cover: no grant until 1.5a
218
+ if (!continuing) {
219
+ const acknowledged = new Set(input.ack?.realms ?? []);
220
+ const missing = chosen.acknowledge.filter((realm) => !acknowledged.has(realm));
221
+ if (missing.length > 0) {
222
+ return {
223
+ status: "skipped",
224
+ reason: `waits for an acknowledged review: full access for ${missing.join(", ")}`,
225
+ };
226
+ }
227
+ }
228
+ let grant;
229
+ try {
230
+ grant = await this.grants.record({
231
+ revision: prepared.revision,
232
+ purposes: rows,
233
+ realms: decision.fullAccess,
234
+ reviewHash: chosen.hash,
235
+ approvalScope: input.approvalScope,
236
+ source: continuing ? "continuity" : input.operator ? "operator_cli" : "review",
237
+ publisher: prepared.publisher,
238
+ ...(continuing && { continuedFrom: previous.revision }),
239
+ approvedBy: input.actor,
240
+ });
241
+ }
242
+ catch (err) {
243
+ if (err instanceof RevisionGrantError)
244
+ return { status: "skipped", reason: err.message };
245
+ throw err;
246
+ }
247
+ const fullAccess = Object.keys(grant.realms);
248
+ const detail = {
249
+ plugin: grant.revision.plugin,
250
+ version: grant.revision.version,
251
+ sha512: grant.revision.sha512,
252
+ generation: grant.generation,
253
+ reviewHash: grant.reviewHash,
254
+ realms: grant.realms,
255
+ authority: grant.authority,
256
+ publisherEvidence: grant.publisherEvidence,
257
+ };
258
+ if (continuing) {
259
+ if (fullAccess.length > 0) {
260
+ await audit(this.kdb.db, {
261
+ actorAccountId: input.actor,
262
+ ...(input.actorTokenId !== undefined && { actorTokenId: input.actorTokenId }),
263
+ action: "extension.full_access_continued",
264
+ target: grant.revision.plugin,
265
+ detail: { ...detail, continuedFrom: grant.continuedFrom },
266
+ });
267
+ }
268
+ return { status: "continued", generation: grant.generation, fullAccess };
269
+ }
270
+ await audit(this.kdb.db, {
271
+ actorAccountId: input.actor,
272
+ ...(input.actorTokenId !== undefined && { actorTokenId: input.actorTokenId }),
273
+ action: "extension.revision_granted",
274
+ target: grant.revision.plugin,
275
+ // the acknowledgement binds the prepared display; the grant binds the display with the scope
276
+ // chosen at confirm (org scope cannot confine full access), and the audit links the two
277
+ detail: {
278
+ ...detail,
279
+ acknowledged: input.ack?.realms ?? [],
280
+ acknowledgedReviewHash: input.ack?.reviewHash ?? null,
281
+ preparedReviewHash: prepared.hash,
282
+ },
283
+ });
284
+ return { status: "granted", generation: grant.generation };
285
+ }
286
+ };
287
+ __decorate([
288
+ Transactional({ propagation: "mandatory" })
289
+ ], RevisionReviews.prototype, "confirm", null);
290
+ RevisionReviews = __decorate([
291
+ Injectable(),
292
+ __param(0, Inject(KernelDb)),
293
+ __param(1, Inject(TransactionHost)),
294
+ __param(2, Inject(ExtensionRevisionGrants)),
295
+ __param(3, Inject(IsolationStatusReader))
296
+ ], RevisionReviews);
297
+ export { RevisionReviews };
@@ -0,0 +1,273 @@
1
+ import type { KernelSchemaDb } from "../db/kernel-schema.js";
2
+ import { type GrantEpochView } from "./isolated/authorization.js";
3
+ import { type ExecutionRealm, type RevisionGrant, type RevisionGrantState } from "./revision-grants.js";
4
+ /**
5
+ * Revocation on a serving replica (extension permission model spec 2026-12-04, "Revocation, audit
6
+ * and people"; plan task 1.3e). The write side is {@link ExtensionRevocations} in `revocation.ts`;
7
+ * this file holds what the host and `ctx` need without depending on the Nest service: the key
8
+ * classes, the serving surface of a grant, and the replica-local permission leases.
9
+ *
10
+ * A lease belongs to one extension instance (one loaded generation of one package revision). It
11
+ * caches the revision's grant state, valid only at the grant epoch it was confirmed at and while
12
+ * that epoch is fresh: every committed grant change advances the epoch (the grant tables' triggers
13
+ * of migration 0235, on the 0234 epoch),
14
+ * so a replica that missed the fan-out hint still revalidates within the 5 s bound. Revalidations
15
+ * are coalesced, and a read started before a change can only confirm the epoch it started at.
16
+ *
17
+ * Shadow mode until plan task 1.5a (the plan's rollout fence): the revocation is written, audited and
18
+ * advances the epoch, and every lease computes its decision within the bound and reports it (logs,
19
+ * {@link RevisionLeases.statesOf}, the Partially revoked view), but nothing is refused, aborted,
20
+ * withdrawn or unloaded on account of it, and no call waits on a lease read: the legacy approval
21
+ * path keeps governing. Task 1.5a sets {@link REVOCATION_ENFORCED} and removes the shadow branch.
22
+ * When enforcing, a revision with no grant never refuses, and one with a grant fails closed while
23
+ * its state cannot be confirmed.
24
+ */
25
+ /** The rollout fence: false until plan task 1.5a turns enforcement on and deletes this switch. */
26
+ export declare const REVOCATION_ENFORCED: boolean;
27
+ /**
28
+ * The kernel test seam that enforces revocation before task 1.5a (a kernel test's
29
+ * `KernelAppOptions.overrides`, value `true`), so the dual-replica tests exercise the enforcing
30
+ * branches. Task 1.5a removes it with {@link REVOCATION_ENFORCED}.
31
+ */
32
+ export declare const REVOCATION_ENFORCEMENT: unique symbol;
33
+ /**
34
+ * A revision whose grant no longer lets it run where it would (whole grant revoked, or server full
35
+ * access revoked while the remaining grant still needs it, or no isolated form): it waits for a new
36
+ * review instead of failing (enforcing only).
37
+ */
38
+ export declare class RevocationPendingError extends Error {
39
+ constructor(message: string);
40
+ }
41
+ /** What revoking one key does (the spec's revocation table). */
42
+ export type KeyClass =
43
+ /** A registration (route, tool, provider, hook, view, setup check): withdrawn. */
44
+ {
45
+ kind: "registration";
46
+ }
47
+ /** A `ctx` resource or operation: refused with `ExtensionPermissionError`, handles closed. */
48
+ | {
49
+ kind: "capability";
50
+ }
51
+ /** `execution.full-access:<realm>`: the privileged generation is unloaded. */
52
+ | {
53
+ kind: "full_access";
54
+ realm: ExecutionRealm;
55
+ }
56
+ /**
57
+ * A key no running surface can withdraw on its own (network, config, tables, embeds,
58
+ * dependencies, client code, raw egress, migration warnings): only a whole-grant revocation,
59
+ * which unloads the revision, takes it away, so {@link revocableKeys} refuses it alone.
60
+ */
61
+ | {
62
+ kind: "unenforced";
63
+ };
64
+ export declare function classifyKey(key: string): KeyClass;
65
+ /** The keys a partial revocation cannot honour on its own (revoke the whole grant instead). */
66
+ export declare function unrevocableKeys(keys: readonly string[]): string[];
67
+ /** The grant fields revocation reads. */
68
+ export type GrantSurface = Pick<RevisionGrant, "keys" | "disabledKeys" | "retiredKeys" | "realms" | "retiredForcing" | "state" | "generation">;
69
+ /**
70
+ * What a full-access realm whose key no longer serves becomes: `isolated` when the remaining grant
71
+ * fits the sandbox, otherwise `pending_approval`. The remaining grant fits when none of the realm's
72
+ * forcing keys still applies: each was retired, or is a permission key that no longer serves (a
73
+ * host reason such as `host.no-isolation` is never a grant key, so it keeps the realm pending).
74
+ */
75
+ export declare function realmAfterRevocation(grant: GrantSurface, realm: ExecutionRealm): "isolated" | "pending_approval";
76
+ /**
77
+ * A revision grant as the inventory shows it: the withdrawn keys by class and the remaining
78
+ * serving surface (**Partially revoked** when some, not all, keys are withdrawn).
79
+ */
80
+ export interface RevocationView {
81
+ state: RevisionGrantState;
82
+ generation: number;
83
+ /** Keys revoked or retired (every key once the grant is revoked). */
84
+ withdrawn: string[];
85
+ /** Keys still serving. */
86
+ serving: string[];
87
+ registrations: string[];
88
+ capabilities: string[];
89
+ fullAccess: {
90
+ realm: ExecutionRealm;
91
+ next: "isolated" | "pending_approval";
92
+ }[];
93
+ }
94
+ export declare function revocationView(grant: GrantSurface): RevocationView;
95
+ /** A revision's grant state as one lease caches it. */
96
+ export interface LeaseState {
97
+ status: "no_grant" | RevisionGrantState;
98
+ generation?: number;
99
+ /** Grant keys that no longer serve: revoked or retired, every key once the grant is revoked. */
100
+ refused: ReadonlySet<string>;
101
+ /** Realms the grant reviewed whose full access no longer serves. */
102
+ realmsRevoked: readonly ExecutionRealm[];
103
+ }
104
+ export declare const NO_GRANT: LeaseState;
105
+ /**
106
+ * The lease state of a revision's newest grant generation. A retired grant is not a revocation
107
+ * (its revision was superseded; admission of a superseded revision belongs to the enforcing
108
+ * cutover), so it refuses nothing here.
109
+ */
110
+ export declare function leaseStateOf(grant: GrantSurface | undefined): LeaseState;
111
+ /**
112
+ * The newest grant generation of each revision stored under the given package sha256s (the
113
+ * package's sha512 names the revision): one query for all of them. A package without a recorded
114
+ * digest or a review has no entry. Grants and packages are deployment rows (no org_id), read
115
+ * outside any org scope.
116
+ */
117
+ export declare function readGrantSurfacesBySha256(db: KernelSchemaDb, sha256s: readonly string[]): Promise<Map<string, GrantSurface>>;
118
+ /** The newest grant generation of the revision stored under one package sha256, or undefined. */
119
+ export declare function readGrantSurfaceBySha256(db: KernelSchemaDb, sha256: string): Promise<GrantSurface | undefined>;
120
+ /** Newly refused keys of a lease, after a revalidation that saw them (enforcing only). */
121
+ export type LeaseRefusalListener = (keys: string[], state: LeaseState) => void;
122
+ export interface LeaseOptions {
123
+ plugin: string;
124
+ /** The package of the instance; null (a config-declared extension): no lease. */
125
+ sha256: string | null;
126
+ /** The instance runs in the kernel process (full access for the server realm, today's trusted tier). */
127
+ inProcess: boolean;
128
+ }
129
+ /**
130
+ * The enforcing decision for one key under a confirmed lease state: refused when the grant no
131
+ * longer serves it, when the whole grant is revoked, or when an in-process generation lost its
132
+ * server full access. Keys the grant never reviewed are not revocation's to refuse.
133
+ */
134
+ export declare function leaseAllows(state: LeaseState, key: string, inProcess: boolean): boolean;
135
+ /** One revalidation's read: the epoch captured before it, and the state (undefined: it failed). */
136
+ interface LeaseRead {
137
+ epoch: string | undefined;
138
+ checkedAt: number;
139
+ state: (sha256: string) => LeaseState | undefined;
140
+ }
141
+ /**
142
+ * The revision authority of one extension instance. {@link check} answers synchronously while the
143
+ * state is confirmed at the fresh epoch, and otherwise after one coalesced revalidation.
144
+ */
145
+ export declare class PermissionLease {
146
+ private readonly owner;
147
+ readonly plugin: string;
148
+ readonly sha256: string;
149
+ readonly inProcess: boolean;
150
+ private state;
151
+ /** The epoch the state was confirmed at; undefined while unconfirmed. */
152
+ private epoch;
153
+ private checkedAt;
154
+ /** The last revalidation failed (no epoch or no grant read): what is known is not confirmed. */
155
+ private readFailed;
156
+ private pending;
157
+ private readonly controllers;
158
+ /** Aborted when the whole lease is fenced: closes every handle that relied on it. */
159
+ private fenced;
160
+ private readonly listeners;
161
+ /** Keys whose computed refusal was already reported in shadow mode. */
162
+ private readonly reported;
163
+ closed: boolean;
164
+ constructor(owner: RevisionLeases, plugin: string, sha256: string, inProcess: boolean);
165
+ /** Whether this replica enforces revocation (false until plan task 1.5a). */
166
+ get enforced(): boolean;
167
+ /**
168
+ * Whether `key` may be used now. In shadow mode always true and never waiting: a stale lease
169
+ * refreshes in the background, and a computed refusal is reported once per key. When enforcing:
170
+ * {@link wouldAllow} after one coalesced revalidation when the state is not confirmed.
171
+ */
172
+ check(key: string): boolean | Promise<boolean>;
173
+ /**
174
+ * The computed decision from what is known: {@link leaseAllows} under the last state, and a
175
+ * refusal when the last read failed and the revision has a grant or was never confirmed (fail
176
+ * closed; a revision confirmed without a grant has nothing to revoke).
177
+ */
178
+ wouldAllow(key: string): boolean;
179
+ /** The keys refused by the last confirmed state. */
180
+ refusedKeys(): string[];
181
+ /** The last confirmed state, if any. */
182
+ current(): LeaseState | undefined;
183
+ /**
184
+ * Aborted when `key` is refused or the lease is fenced (enforcing only): the handles that relied
185
+ * on it close. A key restored by a new grant gets a fresh signal.
186
+ */
187
+ signal(key: string): AbortSignal;
188
+ onRefused(listener: LeaseRefusalListener): () => void;
189
+ close(): void;
190
+ /** Drops the confirmation (a hint or a fence): the next check reads the grant again. */
191
+ invalidate(): void;
192
+ /**
193
+ * The settle deadline or an epoch outage: a lease with a grant that is not confirmed at the
194
+ * current epoch is unconfirmed; when enforcing it also closes its handles, and the next check
195
+ * revalidates (failing closed if it cannot).
196
+ */
197
+ fenceIfStale(epoch: string | undefined): void;
198
+ /** Revalidates alone, or with a read shared by every lease of a fence or epoch change. */
199
+ revalidate(shared?: Promise<LeaseRead>): Promise<LeaseState | undefined>;
200
+ private valid;
201
+ private apply;
202
+ }
203
+ export interface RevisionLeasesOptions {
204
+ epochs: GrantEpochView;
205
+ /** The lease states of the revisions stored under package sha256s (one query for all). */
206
+ read: (sha256s: readonly string[]) => Promise<Map<string, LeaseState>>;
207
+ /**
208
+ * An in-process generation lost its server full access, or the whole grant was revoked
209
+ * (enforcing only): converge, so the generation is unloaded (and restarted isolated when the
210
+ * remaining grant fits).
211
+ */
212
+ onUnload: (plugin: string) => void;
213
+ /**
214
+ * A new grant serves withdrawn keys again (enforcing only): reload the instance, since withdrawn
215
+ * registrations come back only with a new setup.
216
+ */
217
+ onRestored: (plugin: string) => void;
218
+ onFault?: (plugin: string, err: unknown) => void;
219
+ /** A decision computed but not enforced (shadow mode): what enforcement would do. */
220
+ onShadow?: (plugin: string, decision: ShadowRevocation) => void;
221
+ /**
222
+ * Enforce the decisions; defaults to {@link REVOCATION_ENFORCED}. Only the tests of the
223
+ * enforcing branch pass true; task 1.5a removes this option with the shadow branch.
224
+ */
225
+ enforce?: boolean;
226
+ now?: () => number;
227
+ }
228
+ /** What a lease would enforce, reported while revocation is computed only. */
229
+ export type ShadowRevocation = {
230
+ refusedCall: string;
231
+ } | {
232
+ refused: string[];
233
+ lostServerFullAccess: boolean;
234
+ revoked: boolean;
235
+ state: LeaseState;
236
+ };
237
+ /** The leases of every instance on this replica (one per instance with a package). */
238
+ export declare class RevisionLeases {
239
+ private readonly options;
240
+ private readonly leases;
241
+ readonly epochs: GrantEpochView;
242
+ readonly now: () => number;
243
+ readonly enforced: boolean;
244
+ /** Callbacks run in the context the leases were built in, never a caller's org scope. */
245
+ private readonly inOwnContext;
246
+ constructor(options: RevisionLeasesOptions);
247
+ /** Opens the lease of an instance and starts confirming it; undefined without a package. */
248
+ open({ plugin, sha256, inProcess }: LeaseOptions): PermissionLease | undefined;
249
+ /** The confirmed states of a plugin's leases on this replica (the computed decisions). */
250
+ statesOf(plugin: string): LeaseState[];
251
+ /** The local fence after a commit, or a fan-out hint: revalidate the plugin's leases now. */
252
+ fence(plugin?: string): Promise<void>;
253
+ /** The grant epoch advanced: every lease may be stale; revalidate them all with one read. */
254
+ epochChanged(): Promise<void>;
255
+ /** The settle deadline after an epoch change: close what was not confirmed at the new epoch. */
256
+ fenceStale(): void;
257
+ /** No epoch read succeeded for the whole bound: close every lease that has a grant. */
258
+ fenceAll(): void;
259
+ /** One lease's read (its first confirmation, or a check that found it stale). */
260
+ readOne(sha256: string): Promise<LeaseRead>;
261
+ forget(lease: PermissionLease): void;
262
+ mustUnload(lease: PermissionLease): void;
263
+ restored(lease: PermissionLease): void;
264
+ shadow(lease: PermissionLease, decision: ShadowRevocation): void;
265
+ fault(lease: PermissionLease, err: unknown): void;
266
+ private revalidateAll;
267
+ /**
268
+ * The epoch is captured before the grants are read: a revocation committed after the read's
269
+ * snapshot advances the epoch past this value, so the result never outlives it.
270
+ */
271
+ private readStates;
272
+ }
273
+ export {};