@capybara-hq/kernel 0.1.0-rc.146 → 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 (168) 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 +2 -0
  34. package/dist/catalog/provenance.js +5 -1
  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/net.d.ts +5 -1
  45. package/dist/ctx/net.js +62 -12
  46. package/dist/db/kernel-schema.d.ts +31 -0
  47. package/dist/db/migrator.js +0 -36
  48. package/dist/dial-in/routes.js +1 -1
  49. package/dist/erasure/org-batches.js +1 -6
  50. package/dist/erasure/org-catalog.js +6 -2
  51. package/dist/erasure/org-rules.js +1 -0
  52. package/dist/erasure/org-worker.js +0 -13
  53. package/dist/errors.d.ts +6 -0
  54. package/dist/errors.js +6 -0
  55. package/dist/extensions/admin-ops.d.ts +14 -1
  56. package/dist/extensions/admin-ops.js +30 -3
  57. package/dist/extensions/admin-view.d.ts +21 -1
  58. package/dist/extensions/admin-view.js +43 -0
  59. package/dist/extensions/bootstrap-packages.d.ts +5 -0
  60. package/dist/extensions/bootstrap-packages.js +1 -1
  61. package/dist/extensions/bootstrap-review.d.ts +251 -0
  62. package/dist/extensions/bootstrap-review.js +676 -0
  63. package/dist/extensions/bootstrap.d.ts +21 -1
  64. package/dist/extensions/bootstrap.js +72 -2
  65. package/dist/extensions/cli.d.ts +6 -0
  66. package/dist/extensions/cli.js +4 -0
  67. package/dist/extensions/enabled.d.ts +3 -0
  68. package/dist/extensions/extensions.module.js +9 -0
  69. package/dist/extensions/full-access-disclosure.d.ts +15 -0
  70. package/dist/extensions/full-access-disclosure.js +57 -0
  71. package/dist/extensions/grant-epoch.d.ts +5 -0
  72. package/dist/extensions/grant-epoch.js +9 -0
  73. package/dist/extensions/host.d.ts +71 -2
  74. package/dist/extensions/host.js +293 -27
  75. package/dist/extensions/installs.d.ts +18 -0
  76. package/dist/extensions/installs.js +28 -0
  77. package/dist/extensions/isolated/admission.d.ts +17 -2
  78. package/dist/extensions/isolated/admission.js +15 -7
  79. package/dist/extensions/isolated/authorization.d.ts +8 -2
  80. package/dist/extensions/isolated/authorization.js +11 -3
  81. package/dist/extensions/isolated/broker.d.ts +3 -0
  82. package/dist/extensions/isolated/broker.js +50 -14
  83. package/dist/extensions/isolated/configured-package.d.ts +5 -0
  84. package/dist/extensions/isolated/configured-package.js +2 -0
  85. package/dist/extensions/isolated/lanes.d.ts +44 -3
  86. package/dist/extensions/isolated/lanes.js +263 -80
  87. package/dist/extensions/isolated/metrics.d.ts +146 -0
  88. package/dist/extensions/isolated/metrics.js +304 -0
  89. package/dist/extensions/isolated/revision.d.ts +7 -1
  90. package/dist/extensions/isolated/revision.js +26 -5
  91. package/dist/extensions/isolated/rpc.d.ts +5 -0
  92. package/dist/extensions/isolated/rpc.js +7 -2
  93. package/dist/extensions/isolated/sandbox.d.ts +23 -0
  94. package/dist/extensions/isolated/sandbox.js +50 -0
  95. package/dist/extensions/isolated/status.d.ts +79 -0
  96. package/dist/extensions/isolated/status.js +216 -0
  97. package/dist/extensions/isolated/tier.d.ts +127 -2
  98. package/dist/extensions/isolated/tier.js +266 -7
  99. package/dist/extensions/isolated/usage.d.ts +134 -0
  100. package/dist/extensions/isolated/usage.js +322 -0
  101. package/dist/extensions/lifecycle.d.ts +42 -2
  102. package/dist/extensions/lifecycle.js +100 -4
  103. package/dist/extensions/org-config.js +11 -0
  104. package/dist/extensions/package.d.ts +14 -0
  105. package/dist/extensions/package.js +23 -0
  106. package/dist/extensions/permissions.controller.d.ts +35 -0
  107. package/dist/extensions/permissions.controller.js +98 -0
  108. package/dist/extensions/permissions.schemas.d.ts +288 -0
  109. package/dist/extensions/permissions.schemas.js +96 -0
  110. package/dist/extensions/permissions.service.d.ts +116 -0
  111. package/dist/extensions/permissions.service.js +428 -0
  112. package/dist/extensions/realm-retirement.d.ts +65 -0
  113. package/dist/extensions/realm-retirement.js +150 -0
  114. package/dist/extensions/revision-approvals.d.ts +58 -3
  115. package/dist/extensions/revision-approvals.js +135 -14
  116. package/dist/extensions/revision-review.d.ts +144 -0
  117. package/dist/extensions/revision-review.js +297 -0
  118. package/dist/extensions/revocation.js +3 -0
  119. package/dist/extensions/state.module.js +12 -0
  120. package/dist/git/run-end.d.ts +35 -7
  121. package/dist/git/run-end.js +87 -38
  122. package/dist/http/api.module.js +2 -0
  123. package/dist/identity/audit.d.ts +2 -1
  124. package/dist/identity/audit.js +4 -17
  125. package/dist/index.d.ts +4 -0
  126. package/dist/index.js +4 -0
  127. package/dist/infra/config/kernel-config.service.d.ts +6 -0
  128. package/dist/infra/config/kernel-config.service.js +21 -0
  129. package/dist/infra/outbox/registry.d.ts +13 -0
  130. package/dist/infra/outbox/registry.js +8 -0
  131. package/dist/lifecycle/kernel-lifecycle.d.ts +25 -1
  132. package/dist/lifecycle/kernel-lifecycle.js +73 -18
  133. package/dist/net/private-endpoint-preflight.d.ts +159 -0
  134. package/dist/net/private-endpoint-preflight.js +417 -0
  135. package/dist/net/private-endpoints.d.ts +68 -0
  136. package/dist/net/private-endpoints.js +164 -0
  137. package/dist/net/public-address.d.ts +14 -0
  138. package/dist/net/public-address.js +15 -1
  139. package/dist/net/safe-fetch.d.ts +2 -1
  140. package/dist/net/safe-fetch.js +10 -3
  141. package/dist/overrides.d.ts +4 -0
  142. package/dist/overrides.js +2 -0
  143. package/dist/packages/official-publisher.d.ts +26 -1
  144. package/dist/packages/official-publisher.js +48 -1
  145. package/dist/packages/provenance.d.ts +11 -0
  146. package/dist/packages/provenance.js +24 -0
  147. package/dist/platform/exclusions.js +4 -4
  148. package/dist/platform/ops/automations.ops.js +1 -1
  149. package/dist/platform/ops/catalog-admin.ops.js +25 -4
  150. package/dist/platform/ops/extension-permissions.ops.d.ts +11 -0
  151. package/dist/platform/ops/extension-permissions.ops.js +159 -0
  152. package/dist/platform/platform-ops.module.d.ts +2 -1
  153. package/dist/platform/platform-ops.module.js +2 -0
  154. package/dist/platform/route-schemas.js +2 -0
  155. package/dist/retention/purge-batch.js +10 -14
  156. package/dist/runtime/maintenance.d.ts +4 -2
  157. package/dist/runtime/maintenance.js +16 -3
  158. package/dist/runtime/run-finish.d.ts +3 -3
  159. package/dist/runtime/run-finish.js +7 -3
  160. package/dist/sandbox/permission-availability.d.ts +17 -2
  161. package/dist/sandbox/permission-availability.js +22 -1
  162. package/dist/sandbox/permission-facts.js +7 -1
  163. package/dist/tools/builtins/sandbox/common.js +2 -0
  164. package/dist/tools/pipeline.d.ts +2 -1
  165. package/dist/tools/pipeline.js +7 -2
  166. package/package.json +4 -3
  167. package/src/migrations/0238_extension_usage.sql +40 -0
  168. package/src/migrations/0239_extension_replica_isolation.sql +28 -0
@@ -0,0 +1,35 @@
1
+ import type { z } from "zod";
2
+ import { type Principal } from "../identity/principal.js";
3
+ import { type IsolationStatus, PermissionApproveBody, type PermissionApproveResult, type PermissionInventory, type PermissionReviewView, PermissionRevokeBody, type PermissionRevokeResult } from "./permissions.schemas.js";
4
+ import { ExtensionPermissions } from "./permissions.service.js";
5
+ /**
6
+ * The extension permission routes (plan task 1.4a; `permissions.schemas.ts` has the contract)
7
+ * and the isolation status (1.4j). Super admins only.
8
+ */
9
+ export declare class ExtensionPermissionsController {
10
+ private readonly permissions;
11
+ constructor(permissions: ExtensionPermissions);
12
+ /** Every install record with its shadow decision, grants and shadow placements. */
13
+ inventory(): Promise<PermissionInventory>;
14
+ /**
15
+ * The permission review of the install's current revision. Not installed -> 404
16
+ * `extension.not_found`; digest not recorded yet or package unreadable -> 409
17
+ * `extension.permission_review_unavailable`.
18
+ */
19
+ review(name: string): Promise<PermissionReviewView>;
20
+ /**
21
+ * A person approves that review (a human security consent: no Platform operation): the revision
22
+ * grant and the legacy approval in one transaction. Another revision or review -> 409
23
+ * `extension.permission_review_stale`; a wrong full-access acknowledgement -> 409
24
+ * `plugin.full_access_ack_invalid`; a missing one -> 200 with the grant skipped (until 1.5a).
25
+ */
26
+ approve(principal: Principal, name: string, body: z.infer<typeof PermissionApproveBody>): Promise<PermissionApproveResult>;
27
+ /**
28
+ * Revokes keys of a revision's live grant, or the whole grant. Unknown or unrevocable keys -> 409
29
+ * `extension.permission_keys_unknown`; no live grant -> 404
30
+ * `extension.permission_grant_not_found`.
31
+ */
32
+ revoke(principal: Principal, name: string, body: z.infer<typeof PermissionRevokeBody>): Promise<PermissionRevokeResult>;
33
+ /** The isolation status: `not_configured`, or each live replica's supervisor checks. */
34
+ isolation(): Promise<IsolationStatus>;
35
+ }
@@ -0,0 +1,98 @@
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 { Controller, Get, HttpCode, Inject, Param, Post } from "@nestjs/common";
11
+ import { CurrentPrincipal, patTokenId, requireUser, SuperAdmin, } from "../identity/principal.js";
12
+ import { createZodDto } from "../infra/validation/create-zod-dto.js";
13
+ import { ZBody } from "../infra/validation/zod-params.js";
14
+ import { PermissionApproveBody, PermissionRevokeBody, } from "./permissions.schemas.js";
15
+ import { ExtensionPermissions } from "./permissions.service.js";
16
+ class PermissionApproveBodyDto extends createZodDto(PermissionApproveBody, "ExtensionPermissionApproveBody") {
17
+ }
18
+ class PermissionRevokeBodyDto extends createZodDto(PermissionRevokeBody, "ExtensionPermissionRevokeBody") {
19
+ }
20
+ const actorOpts = (actor) => {
21
+ const tokenId = patTokenId(actor);
22
+ return tokenId !== undefined ? { actorTokenId: tokenId } : {};
23
+ };
24
+ /**
25
+ * The extension permission routes (plan task 1.4a; `permissions.schemas.ts` has the contract)
26
+ * and the isolation status (1.4j). Super admins only.
27
+ */
28
+ let ExtensionPermissionsController = class ExtensionPermissionsController {
29
+ permissions;
30
+ constructor(permissions) {
31
+ this.permissions = permissions;
32
+ }
33
+ /** Every install record with its shadow decision, grants and shadow placements. */
34
+ inventory() {
35
+ return this.permissions.inventory();
36
+ }
37
+ /**
38
+ * The permission review of the install's current revision. Not installed -> 404
39
+ * `extension.not_found`; digest not recorded yet or package unreadable -> 409
40
+ * `extension.permission_review_unavailable`.
41
+ */
42
+ review(name) {
43
+ return this.permissions.review(name);
44
+ }
45
+ /**
46
+ * A person approves that review (a human security consent: no Platform operation): the revision
47
+ * grant and the legacy approval in one transaction. Another revision or review -> 409
48
+ * `extension.permission_review_stale`; a wrong full-access acknowledgement -> 409
49
+ * `plugin.full_access_ack_invalid`; a missing one -> 200 with the grant skipped (until 1.5a).
50
+ */
51
+ approve(principal, name, body) {
52
+ const actor = requireUser(principal);
53
+ return this.permissions.approve(actor.account.id, name, body, actorOpts(actor));
54
+ }
55
+ /**
56
+ * Revokes keys of a revision's live grant, or the whole grant. Unknown or unrevocable keys -> 409
57
+ * `extension.permission_keys_unknown`; no live grant -> 404
58
+ * `extension.permission_grant_not_found`.
59
+ */
60
+ revoke(principal, name, body) {
61
+ const actor = requireUser(principal);
62
+ return this.permissions.revoke(actor.account.id, name, body, actorOpts(actor));
63
+ }
64
+ /** The isolation status: `not_configured`, or each live replica's supervisor checks. */
65
+ isolation() {
66
+ return this.permissions.isolationStatus();
67
+ }
68
+ };
69
+ __decorate([
70
+ Get("extension-permissions")
71
+ ], ExtensionPermissionsController.prototype, "inventory", null);
72
+ __decorate([
73
+ Get("extension-permissions/:name/review"),
74
+ __param(0, Param("name"))
75
+ ], ExtensionPermissionsController.prototype, "review", null);
76
+ __decorate([
77
+ Post("extension-permissions/:name/approve"),
78
+ HttpCode(200),
79
+ __param(0, CurrentPrincipal()),
80
+ __param(1, Param("name")),
81
+ __param(2, ZBody(PermissionApproveBodyDto))
82
+ ], ExtensionPermissionsController.prototype, "approve", null);
83
+ __decorate([
84
+ Post("extension-permissions/:name/revoke"),
85
+ HttpCode(200),
86
+ __param(0, CurrentPrincipal()),
87
+ __param(1, Param("name")),
88
+ __param(2, ZBody(PermissionRevokeBodyDto))
89
+ ], ExtensionPermissionsController.prototype, "revoke", null);
90
+ __decorate([
91
+ Get("extension-isolation")
92
+ ], ExtensionPermissionsController.prototype, "isolation", null);
93
+ ExtensionPermissionsController = __decorate([
94
+ Controller("api/v1/admin"),
95
+ SuperAdmin(),
96
+ __param(0, Inject(ExtensionPermissions))
97
+ ], ExtensionPermissionsController);
98
+ export { ExtensionPermissionsController };
@@ -0,0 +1,288 @@
1
+ import { z } from "zod";
2
+ import type { PrivateEndpointGap } from "../net/private-endpoint-preflight.js";
3
+ import type { RouteSchemas } from "../platform/route-schemas.js";
4
+ import type { ExecutionDecision } from "./execution-realm.js";
5
+ import type { ShadowPlacement } from "./isolated/tier.js";
6
+ import type { ReviewDisplay } from "./review-hash.js";
7
+ import type { ShadowGrantStatus, ShadowRevisionDecision } from "./revision-approvals.js";
8
+ import type { ApprovalScope, ExecutionRealm, GrantAuthority, GrantSource, PublisherEvidence, RevisionGrantState } from "./revision-grants.js";
9
+ import type { RevisionReview } from "./revision-review.js";
10
+ /**
11
+ * The shared schemas of the extension permission routes (extension permission model spec,
12
+ * "Review, updates and provenance", "Revocation, audit and people"; plan tasks 1.4a and 1.4j).
13
+ * Requests are zod schemas, used by the controller and by the Platform operations (the parity
14
+ * test compares them); responses are the exported view types. The web (1.4d / 1.4e / 1.4k) and
15
+ * the CLI (1.4f) build against both.
16
+ *
17
+ * Routes (all super admin):
18
+ * - `GET /api/v1/admin/extension-permissions`: the inventory, one {@link PermissionInventoryEntry}
19
+ * per install record ({@link PermissionInventory}).
20
+ * - `GET /api/v1/admin/extension-permissions/:name/review`: the permission review of the
21
+ * install's current revision ({@link PermissionReviewView}). Its Platform operation returns a
22
+ * handoff link card to the web confirm page.
23
+ * - `POST /api/v1/admin/extension-permissions/:name/approve`: a person confirms that review
24
+ * ({@link PermissionApproveBody}), full access included with one acknowledgement per realm. It
25
+ * is a `human security consent` exclusion of the Platform tool and is refused unattended. Returns
26
+ * {@link PermissionApproveResult}.
27
+ * - `POST /api/v1/admin/extension-permissions/:name/revoke`: revokes keys of a revision's grant,
28
+ * or the whole grant ({@link PermissionRevokeBody}); revocation only narrows, so the Platform
29
+ * tool may do it. Returns {@link PermissionRevokeResult}.
30
+ * - `GET /api/v1/admin/extension-isolation`: the isolation status ({@link IsolationStatus}).
31
+ *
32
+ * The catalog import and import-and-update confirms take the same
33
+ * {@link FullAccessAcknowledgementBody} (`catalog/admin-catalog.schemas.ts`).
34
+ */
35
+ /** An extension name as the routes take it (`@Param`). */
36
+ export declare const PermissionNamePathParams: z.ZodObject<{
37
+ name: z.ZodString;
38
+ }, z.core.$strip>;
39
+ /** One exact revision of the named extension: its version and the archive's lowercase sha512. */
40
+ export declare const PermissionRevisionBody: z.ZodObject<{
41
+ version: z.ZodString;
42
+ sha512: z.ZodString;
43
+ }, z.core.$strict>;
44
+ /**
45
+ * One explicit acknowledgement per realm whose full access a permission review confers, bound to
46
+ * that review's hash (plan task 1.3d): `reviewHash` is the review's `hash`, `realms` exactly its
47
+ * `acknowledge`. A wrong one is refused (409 `plugin.full_access_ack_invalid`).
48
+ */
49
+ export declare const FullAccessAcknowledgementBody: z.ZodObject<{
50
+ reviewHash: z.ZodString;
51
+ realms: z.ZodArray<z.ZodEnum<{
52
+ browser: "browser";
53
+ device: "device";
54
+ server: "server";
55
+ }>>;
56
+ }, z.core.$strict>;
57
+ /**
58
+ * `POST …/:name/approve`: confirms the review `GET …/:name/review` returned for `revision`. The
59
+ * install must still run that revision and the review must still hash to `reviewHash` (else 409
60
+ * `extension.permission_review_stale`). A review that confers full access records its revision
61
+ * grant only with `fullAccessAcknowledgement` naming exactly its realms: a wrong one is refused
62
+ * (409 `plugin.full_access_ack_invalid`), a missing one returns 200 with the grant `skipped`
63
+ * (shadow mode; refused from plan task 1.5a). The legacy approval is written either way until 1.5a.
64
+ */
65
+ export declare const PermissionApproveBody: z.ZodObject<{
66
+ revision: z.ZodObject<{
67
+ version: z.ZodString;
68
+ sha512: z.ZodString;
69
+ }, z.core.$strict>;
70
+ reviewHash: z.ZodString;
71
+ fullAccessAcknowledgement: z.ZodOptional<z.ZodObject<{
72
+ reviewHash: z.ZodString;
73
+ realms: z.ZodArray<z.ZodEnum<{
74
+ browser: "browser";
75
+ device: "device";
76
+ server: "server";
77
+ }>>;
78
+ }, z.core.$strict>>;
79
+ }, z.core.$strict>;
80
+ /**
81
+ * `POST …/:name/revoke`: revokes `keys` of the revision's live grant (a realm's full access is its
82
+ * `execution.full-access:<realm>` key), or the whole grant without `keys`. Unknown or unrevocable
83
+ * keys -> 409 `extension.permission_keys_unknown`; no live grant -> 404
84
+ * `extension.permission_grant_not_found`.
85
+ */
86
+ export declare const PermissionRevokeBody: z.ZodObject<{
87
+ revision: z.ZodObject<{
88
+ version: z.ZodString;
89
+ sha512: z.ZodString;
90
+ }, z.core.$strict>;
91
+ keys: z.ZodOptional<z.ZodArray<z.ZodString>>;
92
+ reason: z.ZodOptional<z.ZodString>;
93
+ }, z.core.$strict>;
94
+ export declare const PERMISSION_ROUTES: readonly RouteSchemas[];
95
+ /** One exact revision. */
96
+ export interface PermissionRevision {
97
+ version: string;
98
+ /** Lowercase hex sha512 of the archive; null while the package backfill has not recorded it. */
99
+ sha512: string | null;
100
+ }
101
+ /** A revision grant as the inventory shows it (no purposes: the review shows those). */
102
+ export interface PermissionGrantSummary {
103
+ generation: number;
104
+ state: RevisionGrantState;
105
+ source: GrantSource;
106
+ authority: GrantAuthority;
107
+ publisherEvidence: PublisherEvidence;
108
+ approvalScope: {
109
+ mode: ApprovalScope["mode"];
110
+ orgs: string[];
111
+ };
112
+ /** Full-access realms and their forcing keys, net of revocation and retirement. */
113
+ realms: Partial<Record<ExecutionRealm, string[]>>;
114
+ /** Keys still serving. */
115
+ serving: string[];
116
+ /** Keys revoked or retired (every key once the grant is revoked): the Partially revoked rows. */
117
+ withdrawn: string[];
118
+ reviewHash: string;
119
+ approvedBy: string | null;
120
+ approvedAt: string;
121
+ }
122
+ /** Where one replica would place the revision on its last convergence (1.3b, shadow). */
123
+ export interface PermissionShadowExecution {
124
+ replicaId: string;
125
+ /** The revision that replica placed (it may still be converging to the installed one). */
126
+ version: string;
127
+ host: "available" | "not_configured" | "failing";
128
+ decision: Pick<ExecutionDecision, "kind" | "fullAccess" | "unknownKeys" | "confirmable">;
129
+ uncovered: Partial<Record<ExecutionRealm, string[]>>;
130
+ would: ShadowPlacement;
131
+ diverges: boolean;
132
+ hostReasonRetired: boolean;
133
+ }
134
+ /** One install record in the inventory. */
135
+ export interface PermissionInventoryEntry {
136
+ plugin: string;
137
+ /** The installed revision. */
138
+ revision: PermissionRevision;
139
+ /**
140
+ * `catalog`, `npm`, `file` or `bootstrap` (install records only: a config-declared extension's
141
+ * revision is reviewed by the bootstrap review, plan task 1.3c).
142
+ */
143
+ source: string;
144
+ catalogItemId: string | null;
145
+ required: boolean;
146
+ /** The shadow decision of the installed revision (status, keys, would serve). */
147
+ status: ShadowGrantStatus;
148
+ decision: ShadowRevisionDecision;
149
+ /** The installed revision's own grant (any state), if it ever had one. */
150
+ grant: PermissionGrantSummary | null;
151
+ /** The install's approved revision when it is another one (an upgrade waiting for review). */
152
+ approved: (PermissionRevision & {
153
+ generation: number;
154
+ }) | null;
155
+ /** The install's candidate revision, waiting for review. */
156
+ candidate: PermissionRevision | null;
157
+ /** Per live replica, the shadow placement of its last convergence (empty until it ran). */
158
+ executions: PermissionShadowExecution[];
159
+ }
160
+ export interface PermissionInventory {
161
+ entries: PermissionInventoryEntry[];
162
+ /** Required installs the enforcing start gate (1.5a) would refuse. */
163
+ missingRequired: string[];
164
+ }
165
+ /** `GET …/:name/review`. */
166
+ export interface PermissionReviewView {
167
+ plugin: string;
168
+ revision: {
169
+ version: string;
170
+ sha512: string;
171
+ };
172
+ /** The review of that revision: display, hash, consent, realms to acknowledge, block. */
173
+ review: Pick<RevisionReview, "hash" | "consent" | "acknowledge" | "blocked"> & {
174
+ display: ReviewDisplay;
175
+ };
176
+ /** The web confirm page for this review (what the Platform operation's handoff opens). */
177
+ confirmUrl: string;
178
+ /** Manifest paths and sizes of the client files in the exact revision being reviewed. */
179
+ clientFiles?: {
180
+ path: string;
181
+ size: number;
182
+ }[];
183
+ /**
184
+ * The deployment's isolation state now (`GET /api/v1/admin/extension-isolation`'s `state`): the
185
+ * review binds only whether the supervisor is configured, so show this beside it (a revision
186
+ * that runs isolated is unavailable while the supervisor fails).
187
+ */
188
+ isolation: "not_configured" | "available" | "failing" | "unknown";
189
+ }
190
+ /** `POST …/:name/approve`. */
191
+ export interface PermissionApproveResult {
192
+ plugin: string;
193
+ revision: {
194
+ version: string;
195
+ sha512: string;
196
+ };
197
+ /** What happened to the revision grant (the legacy approval is written either way until 1.5a). */
198
+ grant: {
199
+ status: "granted" | "kept";
200
+ generation: number;
201
+ } | {
202
+ status: "continued";
203
+ generation: number;
204
+ fullAccess: ExecutionRealm[];
205
+ } | {
206
+ status: "skipped";
207
+ reason: string;
208
+ };
209
+ }
210
+ /** `POST …/:name/revoke`. */
211
+ export interface PermissionRevokeResult {
212
+ plugin: string;
213
+ revision: {
214
+ version: string;
215
+ sha512: string;
216
+ };
217
+ grant: PermissionGrantSummary;
218
+ /** Keys this revocation withdrew. */
219
+ withdrawn: string[];
220
+ /** Per full-access realm revoked, where the revision goes next once revocation is enforced. */
221
+ fullAccess: {
222
+ realm: ExecutionRealm;
223
+ next: "isolated" | "pending_approval";
224
+ }[];
225
+ /**
226
+ * Whether revocation already changes what runs: false in shadow mode until the enforcing
227
+ * cutover (plan task 1.5a), when the legacy approval still governs admission and the extension
228
+ * keeps running as before; disable it to stop it now.
229
+ */
230
+ enforced: boolean;
231
+ }
232
+ /** A supervisor check that can fail, in the order the kernel runs them. */
233
+ export type IsolationCheck = "guard_reachability" | "engine_runtime" | "image" | "postgres_socket";
234
+ /** One live replica's supervisor readiness, as its last probe saw it. */
235
+ export interface ReplicaIsolation {
236
+ replicaId: string;
237
+ /** `not_configured`: this replica runs without the supervisor (a mixed configuration). */
238
+ state: "available" | "failing" | "not_configured";
239
+ /** The first check that failed (`failing` only); `message` is the kernel's English text. */
240
+ failedCheck: IsolationCheck | null;
241
+ message: string | null;
242
+ /** When its last probe ran; null when not configured. */
243
+ probedAt: string | null;
244
+ }
245
+ /** A plugin a failing supervisor keeps from running (it would run isolated). */
246
+ export interface IsolationPausedPlugin {
247
+ plugin: string;
248
+ version: string;
249
+ /** The replicas where it is paused. */
250
+ replicas: string[];
251
+ }
252
+ /**
253
+ * `GET /api/v1/admin/extension-isolation`. Not configured: only the state, the kernel probes
254
+ * nothing. Configured: `available` when every live replica's supervisor passed its checks,
255
+ * `failing` when any did not (`replicas` says which check), `unknown` before any replica probed.
256
+ */
257
+ export type IsolationStatus = {
258
+ state: "not_configured";
259
+ } | {
260
+ state: "available" | "failing" | "unknown";
261
+ replicas: ReplicaIsolation[];
262
+ paused: IsolationPausedPlugin[];
263
+ /** Platform endpoints `ctx.net` would not admit for isolated plugins (#1459). */
264
+ privateEndpointGaps: PrivateEndpointGap[];
265
+ };
266
+ /**
267
+ * The org-facing disclosure of an optional full-access plugin (spec "Review, updates and
268
+ * provenance" step 3; the 1.4f org page), on the org catalog item read: shown to the org's admins
269
+ * when the plugin's approved revision runs with full access, null otherwise (and always null for
270
+ * other members). No secrets, no other org's data, no deployment internals beyond the realms and
271
+ * why they need full access.
272
+ */
273
+ export interface FullAccessDisclosure {
274
+ approvedRevision: {
275
+ version: string;
276
+ };
277
+ realms: ExecutionRealm[];
278
+ /**
279
+ * Why full access is needed, by class: `host_no_isolation` (the deployment runs without the
280
+ * isolation supervisor), `provider_contract` (an extension point without an isolated form yet),
281
+ * `client_code` (code in the app page), `device_host` (a service outside the device sandbox),
282
+ * `declared` (a declared capability that only runs with the kernel's privileges).
283
+ */
284
+ reasons: FullAccessReason[];
285
+ approverAuthority: GrantAuthority;
286
+ approvedAt: string;
287
+ }
288
+ export type FullAccessReason = "host_no_isolation" | "provider_contract" | "client_code" | "device_host" | "declared";
@@ -0,0 +1,96 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * The shared schemas of the extension permission routes (extension permission model spec,
4
+ * "Review, updates and provenance", "Revocation, audit and people"; plan tasks 1.4a and 1.4j).
5
+ * Requests are zod schemas, used by the controller and by the Platform operations (the parity
6
+ * test compares them); responses are the exported view types. The web (1.4d / 1.4e / 1.4k) and
7
+ * the CLI (1.4f) build against both.
8
+ *
9
+ * Routes (all super admin):
10
+ * - `GET /api/v1/admin/extension-permissions`: the inventory, one {@link PermissionInventoryEntry}
11
+ * per install record ({@link PermissionInventory}).
12
+ * - `GET /api/v1/admin/extension-permissions/:name/review`: the permission review of the
13
+ * install's current revision ({@link PermissionReviewView}). Its Platform operation returns a
14
+ * handoff link card to the web confirm page.
15
+ * - `POST /api/v1/admin/extension-permissions/:name/approve`: a person confirms that review
16
+ * ({@link PermissionApproveBody}), full access included with one acknowledgement per realm. It
17
+ * is a `human security consent` exclusion of the Platform tool and is refused unattended. Returns
18
+ * {@link PermissionApproveResult}.
19
+ * - `POST /api/v1/admin/extension-permissions/:name/revoke`: revokes keys of a revision's grant,
20
+ * or the whole grant ({@link PermissionRevokeBody}); revocation only narrows, so the Platform
21
+ * tool may do it. Returns {@link PermissionRevokeResult}.
22
+ * - `GET /api/v1/admin/extension-isolation`: the isolation status ({@link IsolationStatus}).
23
+ *
24
+ * The catalog import and import-and-update confirms take the same
25
+ * {@link FullAccessAcknowledgementBody} (`catalog/admin-catalog.schemas.ts`).
26
+ */
27
+ /** An extension name as the routes take it (`@Param`). */
28
+ export const PermissionNamePathParams = z.object({ name: z.string().min(1).max(64) });
29
+ const Realm = z.enum(["server", "browser", "device"]);
30
+ /** `review:v1:<sha256 hex>`, the hash of a revision's permission review (1.2e). */
31
+ const ReviewHash = z.string().regex(/^review:v1:[0-9a-f]{64}$/);
32
+ /** One exact revision of the named extension: its version and the archive's lowercase sha512. */
33
+ export const PermissionRevisionBody = z
34
+ .object({
35
+ version: z.string().min(1).max(256),
36
+ sha512: z.string().regex(/^[0-9a-f]{128}$/),
37
+ })
38
+ .strict();
39
+ /**
40
+ * One explicit acknowledgement per realm whose full access a permission review confers, bound to
41
+ * that review's hash (plan task 1.3d): `reviewHash` is the review's `hash`, `realms` exactly its
42
+ * `acknowledge`. A wrong one is refused (409 `plugin.full_access_ack_invalid`).
43
+ */
44
+ export const FullAccessAcknowledgementBody = z
45
+ .object({
46
+ reviewHash: z.string().min(1).max(128),
47
+ realms: z.array(Realm).max(3),
48
+ })
49
+ .strict();
50
+ /**
51
+ * `POST …/:name/approve`: confirms the review `GET …/:name/review` returned for `revision`. The
52
+ * install must still run that revision and the review must still hash to `reviewHash` (else 409
53
+ * `extension.permission_review_stale`). A review that confers full access records its revision
54
+ * grant only with `fullAccessAcknowledgement` naming exactly its realms: a wrong one is refused
55
+ * (409 `plugin.full_access_ack_invalid`), a missing one returns 200 with the grant `skipped`
56
+ * (shadow mode; refused from plan task 1.5a). The legacy approval is written either way until 1.5a.
57
+ */
58
+ export const PermissionApproveBody = z
59
+ .object({
60
+ revision: PermissionRevisionBody,
61
+ reviewHash: ReviewHash,
62
+ fullAccessAcknowledgement: FullAccessAcknowledgementBody.optional(),
63
+ })
64
+ .strict();
65
+ /**
66
+ * `POST …/:name/revoke`: revokes `keys` of the revision's live grant (a realm's full access is its
67
+ * `execution.full-access:<realm>` key), or the whole grant without `keys`. Unknown or unrevocable
68
+ * keys -> 409 `extension.permission_keys_unknown`; no live grant -> 404
69
+ * `extension.permission_grant_not_found`.
70
+ */
71
+ export const PermissionRevokeBody = z
72
+ .object({
73
+ revision: PermissionRevisionBody,
74
+ keys: z.array(z.string().min(1).max(512)).min(1).max(200).optional(),
75
+ /** Shown in the audit. */
76
+ reason: z.string().min(1).max(500).optional(),
77
+ })
78
+ .strict();
79
+ export const PERMISSION_ROUTES = [
80
+ { route: "GET /api/v1/admin/extension-permissions" },
81
+ {
82
+ route: "GET /api/v1/admin/extension-permissions/:name/review",
83
+ params: PermissionNamePathParams,
84
+ },
85
+ {
86
+ route: "POST /api/v1/admin/extension-permissions/:name/approve",
87
+ params: PermissionNamePathParams,
88
+ body: PermissionApproveBody,
89
+ },
90
+ {
91
+ route: "POST /api/v1/admin/extension-permissions/:name/revoke",
92
+ params: PermissionNamePathParams,
93
+ body: PermissionRevokeBody,
94
+ },
95
+ { route: "GET /api/v1/admin/extension-isolation" },
96
+ ];
@@ -0,0 +1,116 @@
1
+ import { SuperAdminLock } from "../identity/super-admin.js";
2
+ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
3
+ import { KernelDb } from "../infra/database/kernel-db.js";
4
+ import { TransactionHost } from "../infra/database/transaction-host.js";
5
+ import { ExtensionAdmin } from "./admin-view.js";
6
+ import { ExtensionBlobs } from "./blobs.js";
7
+ import { ExtensionInstalls } from "./installs.js";
8
+ import { IsolationStatusReader } from "./isolated/status.js";
9
+ import { PluginInstallLock } from "./locks.js";
10
+ import type { IsolationStatus, PermissionApproveResult, PermissionGrantSummary, PermissionInventory, PermissionReviewView, PermissionRevokeResult } from "./permissions.schemas.js";
11
+ import { ExtensionRevisionApprovals } from "./revision-approvals.js";
12
+ import { ExtensionRevisionGrants, type RevisionGrant } from "./revision-grants.js";
13
+ import { type FullAccessAcknowledgement, RevisionReviews } from "./revision-review.js";
14
+ import { ExtensionRevocations } from "./revocation.js";
15
+ /**
16
+ * The extension permission routes (extension permission model plan task 1.4a; spec "Review,
17
+ * updates and provenance", "Revocation, audit and people") and the isolation status (1.4j): the
18
+ * inventory of every install record, the review of an install's current revision, a person's
19
+ * approval of it (a revision grant, full access with one acknowledgement per realm), revocation
20
+ * of keys or a whole grant, and the deployment-wide isolation status.
21
+ *
22
+ * Shadow mode until plan task 1.5a: an approval records the revision grant and also writes the
23
+ * legacy snapshot, which keeps governing admission; a revocation changes the grant (its leases
24
+ * enforce from 1.5a, 1.3e).
25
+ */
26
+ /** The web page where a person confirms the installed revision's permission review. */
27
+ export declare const permissionConfirmUrl: (name: string) => string;
28
+ export declare function grantSummary(grant: RevisionGrant): PermissionGrantSummary;
29
+ export declare class ExtensionPermissions {
30
+ private readonly kdb;
31
+ readonly txHost: TransactionHost;
32
+ private readonly config;
33
+ private readonly installs;
34
+ private readonly blobs;
35
+ private readonly grants;
36
+ private readonly approvals;
37
+ private readonly reviews;
38
+ private readonly revocations;
39
+ private readonly isolation;
40
+ private readonly installLock;
41
+ /** The legacy snapshot an approval still writes until 1.5a. */
42
+ private readonly admin;
43
+ /** Approve and revoke re-check the super admin under the role lock. */
44
+ private readonly adminLock;
45
+ constructor(kdb: KernelDb, txHost: TransactionHost, config: KernelConfigService, installs: ExtensionInstalls, blobs: Pick<ExtensionBlobs, "get">, grants: ExtensionRevisionGrants, approvals: Pick<ExtensionRevisionApprovals, "decisions">, reviews: RevisionReviews, revocations: ExtensionRevocations, isolation: IsolationStatusReader, installLock: PluginInstallLock,
46
+ /** The legacy snapshot an approval still writes until 1.5a. */
47
+ admin: Pick<ExtensionAdmin, "legacySubject" | "writeLegacyApproval" | "notifyApproved">,
48
+ /** Approve and revoke re-check the super admin under the role lock. */
49
+ adminLock: SuperAdminLock);
50
+ /** Every install record with its shadow decision, grants and shadow placements. */
51
+ inventory(): Promise<PermissionInventory>;
52
+ /**
53
+ * The permission review of the install's current revision; `operator`: as the operator approves
54
+ * it from the CLI (`capybara extensions approve`, authority `operator`).
55
+ */
56
+ review(name: string, opts?: {
57
+ operator?: boolean;
58
+ }): Promise<PermissionReviewView>;
59
+ /**
60
+ * A person approves the review of the install's current revision: the revision grant (full
61
+ * access needs `ack`), then the legacy snapshot until 1.5a. The revision must still be the one
62
+ * reviewed and the review must still hash the same, else 409 `extension.permission_review_stale`.
63
+ */
64
+ approve(actor: string, name: string, body: {
65
+ revision: {
66
+ version: string;
67
+ sha512: string;
68
+ };
69
+ reviewHash: string;
70
+ fullAccessAcknowledgement?: FullAccessAcknowledgement | undefined;
71
+ }, opts?: {
72
+ actorTokenId?: string;
73
+ }): Promise<PermissionApproveResult>;
74
+ /**
75
+ * The operator approves the review `review(name, { operator: true })` printed, from the CLI: an
76
+ * `operator_cli` revision grant under the same checks (the revision, the review hash, one
77
+ * acknowledgement per full-access realm). The CLI writes the legacy snapshot itself.
78
+ */
79
+ approveAsOperator(name: string, body: {
80
+ revision: {
81
+ version: string;
82
+ sha512: string;
83
+ };
84
+ reviewHash: string;
85
+ fullAccessAcknowledgement?: FullAccessAcknowledgement | undefined;
86
+ },
87
+ /** The CLI's legacy snapshot write, run in the grant's transaction (it joins it). */
88
+ legacy?: () => Promise<unknown>): Promise<PermissionApproveResult["grant"]>;
89
+ private approveIn;
90
+ /** Revokes keys of a revision's live grant, or the whole grant. */
91
+ revoke(actor: string, name: string, body: {
92
+ revision: {
93
+ version: string;
94
+ sha512: string;
95
+ };
96
+ keys?: string[] | undefined;
97
+ reason?: string | undefined;
98
+ }, opts?: {
99
+ actorTokenId?: string;
100
+ }): Promise<PermissionRevokeResult>;
101
+ /** The revocation under the super admin re-check, in one transaction. */
102
+ private revokeIn;
103
+ /** The deployment-wide isolation status. Not configured: only that, nothing probed or read. */
104
+ isolationStatus(): Promise<IsolationStatus>;
105
+ private prepare;
106
+ /** The install's current revision, read for a review (outside any transaction). */
107
+ private installed;
108
+ /** The catalog item's scope; an install outside the catalog is deployment-wide (`all`). */
109
+ private itemScope;
110
+ /**
111
+ * The installed revision's publisher evidence as the catalog recorded it: the official proof
112
+ * (the official identity), an official revision under the pin-only policy (`pin_only`, #1368),
113
+ * else `none` (the review shows it; continuity needs a verified publisher).
114
+ */
115
+ private publisherOf;
116
+ }