@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
@@ -145,6 +145,13 @@ export function isLinkLocalAddress(ip) {
145
145
  export function isLoopbackOrUnspecifiedAddress(ip) {
146
146
  return inTable(ip, loopbackOrUnspecified);
147
147
  }
148
+ const loopbackOnly = new BlockList();
149
+ loopbackOnly.addSubnet("127.0.0.0", 8, "ipv4");
150
+ loopbackOnly.addAddress("::1", "ipv6");
151
+ /** Loopback only (`127.0.0.0/8`, `::1`, embedded forms included), never unspecified. */
152
+ export function isLoopbackAddress(ip) {
153
+ return inTable(ip, loopbackOnly);
154
+ }
148
155
  /** A hostname normalized for comparison: lower case, no IPv6 brackets, no trailing dots. */
149
156
  export function normalizeHost(host) {
150
157
  let h = host.trim().toLowerCase();
@@ -312,12 +319,19 @@ export async function resolvePublic(host, policy, lookup = defaultLookup, origin
312
319
  throw new NetDeniedError("net.dns_failed", h, `Cannot resolve ${h}.`);
313
320
  }
314
321
  const ex = exemptions(h, policy, origin);
322
+ // a private endpoint alias exempts exactly its origin (see NetPolicy.privateEndpoint)
323
+ const alias = policy.privateEndpoint !== undefined && origin === policy.privateEndpoint.origin
324
+ ? policy.privateEndpoint
325
+ : undefined;
315
326
  // extension requests never reach the kernel's own host, whatever the exemptions
316
327
  const ownHost = (a) => policy.extension !== undefined &&
317
328
  !policy.allowInsecureLoopback &&
329
+ !(alias?.allowLoopback === true && isLoopbackAddress(a)) &&
318
330
  isLoopbackOrUnspecifiedAddress(a);
319
331
  const refused = (a) => isForbiddenAddress(a) &&
320
- (isLinkLocalAddress(a) || ownHost(a) || (!ex.all && !allowedBy(ex.cidrs, a)));
332
+ (isLinkLocalAddress(a) ||
333
+ ownHost(a) ||
334
+ (alias === undefined && !ex.all && !allowedBy(ex.cidrs, a)));
321
335
  if (addrs.some(refused)) {
322
336
  const hint = policy.extension?.privateHint ??
323
337
  "add the hostname to net.allowPrivateHosts to allow an internal host";
@@ -11,7 +11,8 @@ import { type LookupFn, type NetPolicy } from "./public-address.js";
11
11
  * - with `policy.proxy` (`net.httpsProxy`), an https URL whose host is not loopback and not in
12
12
  * `noProxy` tunnels through the proxy (`proxy.ts`) instead: the host is not resolved locally
13
13
  * (the proxy resolves it and owns SSRF protection for the resolved address), but an IP-literal
14
- * host is still checked against the private ranges and `allowPrivateHosts`;
14
+ * host is still checked against the private ranges and `allowPrivateHosts`; an origin a
15
+ * `net.privateEndpoints` alias admitted (`policy.privateEndpoint`) never uses the proxy;
15
16
  * - redirects are never followed: a 3xx (other than 304) is {@link NetDeniedError} `net.redirect`,
16
17
  * or, with `redirects: "return"`, returned to the caller as is (its body unread);
17
18
  * - with `maxBytes`, a declared or streamed body over the limit is {@link NetBodyTooLargeError}.
@@ -13,7 +13,8 @@ import { hostEntryExempts, isLoopbackHost, NetDeniedError, normalizeHost, resolv
13
13
  * - with `policy.proxy` (`net.httpsProxy`), an https URL whose host is not loopback and not in
14
14
  * `noProxy` tunnels through the proxy (`proxy.ts`) instead: the host is not resolved locally
15
15
  * (the proxy resolves it and owns SSRF protection for the resolved address), but an IP-literal
16
- * host is still checked against the private ranges and `allowPrivateHosts`;
16
+ * host is still checked against the private ranges and `allowPrivateHosts`; an origin a
17
+ * `net.privateEndpoints` alias admitted (`policy.privateEndpoint`) never uses the proxy;
17
18
  * - redirects are never followed: a 3xx (other than 304) is {@link NetDeniedError} `net.redirect`,
18
19
  * or, with `redirects: "return"`, returned to the caller as is (its body unread);
19
20
  * - with `maxBytes`, a declared or streamed body over the limit is {@link NetBodyTooLargeError}.
@@ -154,8 +155,11 @@ async function safeFetchOnce(url, init, policy, opts) {
154
155
  throw new NetDeniedError("net.insecure_url", "", "The URL is not valid.");
155
156
  }
156
157
  const host = normalizeHost(target.hostname);
158
+ // a net.privateEndpoints alias admitted this exact origin (ctx.net): direct, http if configured
159
+ const aliased = policy.privateEndpoint?.origin === target.origin;
157
160
  const insecureOk = target.protocol === "http:" &&
158
- ((policy.allowInsecureLoopback && isLoopbackHost(host)) ||
161
+ (aliased ||
162
+ (policy.allowInsecureLoopback && isLoopbackHost(host)) ||
159
163
  policy.trustedOrigins.some((o) => originOf(o) === target.origin));
160
164
  if (target.protocol !== "https:" && !insecureOk) {
161
165
  // an extension request to a host the org allows only as a host entry (https only): name the
@@ -164,12 +168,15 @@ async function safeFetchOnce(url, init, policy, opts) {
164
168
  target.protocol === "http:" &&
165
169
  hostEntryExempts(host, policy)
166
170
  ? ` ${host} is allowed for the organization over https only; to allow plain http, ask a super admin to allow the origin ${target.origin}.`
167
- : "";
171
+ : policy.extension?.insecureHint !== undefined && target.protocol === "http:"
172
+ ? ` If it is an internal endpoint: ${policy.extension.insecureHint}.`
173
+ : "";
168
174
  throw new NetDeniedError("net.insecure_url", host, `The URL must use https (${host}).${hint}`);
169
175
  }
170
176
  const proxy = policy.proxy;
171
177
  const proxied = proxy !== undefined &&
172
178
  target.protocol === "https:" &&
179
+ !aliased &&
173
180
  !isLoopbackHost(host) &&
174
181
  !bypassesProxy(host, proxy.noProxy);
175
182
  // getaddrinfo cannot be cancelled: stop waiting for it when the caller gives up
@@ -8,6 +8,7 @@ import { EXTENSION_NET_SEAMS, type ExtensionNetSeams } from "./ctx/net.js";
8
8
  import type { EvalReplayHooks } from "./evals/run-replay.js";
9
9
  import { EVAL_REPLAY_HOOKS } from "./evals/worker.js";
10
10
  import { BOOTSTRAP_LOCK_TTL } from "./extensions/bootstrap.js";
11
+ import { REVOCATION_ENFORCEMENT } from "./extensions/revocation-leases.js";
11
12
  import { USAGE_SUBSCRIBERS_CLOCK } from "./extensions/usage-subscribers.js";
12
13
  import { FILE_PREVIEW_TIMEOUT } from "./files/previewers.js";
13
14
  import { GIT_UPSTREAM_ORIGIN, type GitUpstreamOrigin } from "./git/gateway.js";
@@ -18,6 +19,7 @@ import { OUTBOX_DISPATCH_FAILS } from "./infra/outbox/outbox.dispatcher.js";
18
19
  import { OUTBOX_FAST_PATH_SETTLED } from "./infra/outbox/outbox.module.js";
19
20
  import { PRESENCE_INTERVAL_MS } from "./infra/presence/replica-presence.js";
20
21
  import type { KernelQueueName } from "./infra/queue/queue-names.js";
22
+ import { BROKERED_ENDPOINT_PINS_SEAM, type BrokeredEndpointPin } from "./net/private-endpoint-preflight.js";
21
23
  import { PUSH_SEND_TIMEOUT_MS } from "./push/delivery.js";
22
24
  import { PROJECT_KNOWLEDGE_TIMEOUT, type ProjectKnowledgeTimeouts } from "./runtime/project/knowledge.service.js";
23
25
  import { LIST_MODELS_TIMEOUT } from "./runtime/providers.js";
@@ -68,10 +70,14 @@ import { EMBED_TOKEN_CLOCK } from "./ui/embed-token.js";
68
70
  * - `PLUGIN_PUBLIC_WRITE_LIMIT`: a lower limit for unsafe methods on `public` extension routes;
69
71
  * - `EXTENSION_NET_SEAMS`: `ctx.net`'s DNS and dispatcher (a hostname resolving to a private address
70
72
  * served by a loopback fake);
73
+ * - `BROKERED_ENDPOINT_PINS_SEAM`: the brokered pins the bootstrap's private endpoint preflight
74
+ * checks (a fixture plugin standing in for object-store-s3's ctx.net build);
71
75
  * - `APP_INTERCEPTOR`: one more global interceptor (a probe of the matched routes);
72
76
  * - `TOOL_WATCH_TIMINGS`: shorter watched-wait poll timings (interval, watcher timeout);
73
77
  * - `PERMISSION_AUTO_GRANT_HOOKS`: a barrier after a Full access auto-grant's precheck (two
74
- * replicas racing the same crossing).
78
+ * replicas racing the same crossing);
79
+ * - `REVOCATION_ENFORCEMENT`: enforce grant revocation before plan task 1.5a (the dual-replica tests
80
+ * of the enforcing branches; removed with the shadow switch by 1.5a).
75
81
  */
76
82
  interface KernelSeams {
77
83
  [AGENT_LOOP_FACTORY]: AgentLoopFactory;
@@ -102,9 +108,11 @@ interface KernelSeams {
102
108
  [BACKGROUND_STOP_ATTEMPT_MS]: () => number;
103
109
  [PLUGIN_PUBLIC_WRITE_LIMIT]: number;
104
110
  [EXTENSION_NET_SEAMS]: ExtensionNetSeams;
111
+ [BROKERED_ENDPOINT_PINS_SEAM]: readonly BrokeredEndpointPin[];
105
112
  [APP_INTERCEPTOR]: NestInterceptor;
106
113
  [PERMISSION_AUTO_GRANT_HOOKS]: PermissionAutoGrantHooks;
107
114
  [TOOL_WATCH_TIMINGS]: Partial<ToolWatchTimings>;
115
+ [REVOCATION_ENFORCEMENT]: boolean;
108
116
  }
109
117
  /**
110
118
  * A seam of the kernel's own tests (`KernelAppOptions.overrides`): a value for one of the named
package/dist/overrides.js CHANGED
@@ -6,6 +6,7 @@ import { PROMPT_SUGGESTION_TIMEOUT } from "./conversations/prompt-suggestions.js
6
6
  import { EXTENSION_NET_SEAMS } from "./ctx/net.js";
7
7
  import { EVAL_REPLAY_HOOKS } from "./evals/worker.js";
8
8
  import { BOOTSTRAP_LOCK_TTL } from "./extensions/bootstrap.js";
9
+ import { REVOCATION_ENFORCEMENT } from "./extensions/revocation-leases.js";
9
10
  import { USAGE_SUBSCRIBERS_CLOCK } from "./extensions/usage-subscribers.js";
10
11
  import { FILE_PREVIEW_TIMEOUT } from "./files/previewers.js";
11
12
  import { GIT_UPSTREAM_ORIGIN } from "./git/gateway.js";
@@ -15,6 +16,7 @@ import { PLUGIN_PUBLIC_WRITE_LIMIT } from "./http/plugin-route-access.js";
15
16
  import { OUTBOX_DISPATCH_FAILS } from "./infra/outbox/outbox.dispatcher.js";
16
17
  import { OUTBOX_FAST_PATH_SETTLED } from "./infra/outbox/outbox.module.js";
17
18
  import { PRESENCE_INTERVAL_MS } from "./infra/presence/replica-presence.js";
19
+ import { BROKERED_ENDPOINT_PINS_SEAM, } from "./net/private-endpoint-preflight.js";
18
20
  import { PUSH_SEND_TIMEOUT_MS } from "./push/delivery.js";
19
21
  import { PROJECT_KNOWLEDGE_TIMEOUT, } from "./runtime/project/knowledge.service.js";
20
22
  import { LIST_MODELS_TIMEOUT } from "./runtime/providers.js";
@@ -58,9 +60,11 @@ const SEAM_TOKENS = [
58
60
  BACKGROUND_STOP_ATTEMPT_MS,
59
61
  PLUGIN_PUBLIC_WRITE_LIMIT,
60
62
  EXTENSION_NET_SEAMS,
63
+ BROKERED_ENDPOINT_PINS_SEAM,
61
64
  APP_INTERCEPTOR,
62
65
  PERMISSION_AUTO_GRANT_HOOKS,
63
66
  TOOL_WATCH_TIMINGS,
67
+ REVOCATION_ENFORCEMENT,
64
68
  ];
65
69
  const allSeamsListed = true;
66
70
  void allSeamsListed;
@@ -1,5 +1,5 @@
1
1
  import type { NpmFetchConfig } from "./npm.js";
2
- import { type Provenance } from "./provenance.js";
2
+ import { type Provenance, type ProvenanceResult } from "./provenance.js";
3
3
  declare const POLICY_VERSION = 1;
4
4
  export interface OfficialNpmRevision {
5
5
  name: string;
@@ -12,8 +12,72 @@ export interface OfficialPublisherProof extends Provenance {
12
12
  evidenceDigest: string;
13
13
  policyVersion: typeof POLICY_VERSION;
14
14
  }
15
+ /** A build signer's GitHub Actions identity, read from the Fulcio certificate extensions. */
16
+ export interface PublisherCertificate {
17
+ /** The OIDC issuer the certificate was issued for. */
18
+ issuer: string;
19
+ /** The certificate's subject alternative name: `<repository>/<workflow>@<ref>`. */
20
+ identity: string;
21
+ /** The source repository URL. */
22
+ repository: string;
23
+ repositoryId: string;
24
+ ownerId: string;
25
+ /** The workflow file path within the repository. */
26
+ workflow: string;
27
+ /** The git ref the workflow ran on. */
28
+ ref: string;
29
+ /** The source commit. */
30
+ commit: string;
31
+ }
32
+ /** A package revision whose registry publish and build attestations both verified. */
33
+ export interface VerifiedPublisher {
34
+ revision: OfficialNpmRevision;
35
+ certificate: PublisherCertificate;
36
+ buildType: string;
37
+ evidenceDigest: string;
38
+ }
39
+ /**
40
+ * Any GitHub Actions publisher (publisher evidence for review and continuity, plan task 1.2e):
41
+ * both attestations verified, and the build predicate in agreement with the certificate. The
42
+ * identity is returned as signed; `catalog/provenance.ts` normalizes it.
43
+ */
44
+ export declare function verifyPublisher(body: unknown, revision: OfficialNpmRevision): VerifiedPublisher;
45
+ /**
46
+ * The one definition of official proof, shared by the official marketplace's admission
47
+ * ({@link verifyOfficialPublisher}) and publisher evidence (`classifyPublisherEvidence`): a revision
48
+ * whose attestations verified ({@link verifyPublisher}: the build predicate agrees with the
49
+ * certificate and its source commit) is official when the certificate is the official release
50
+ * workflow on the official repository's main ref, the build type is the GitHub Actions workflow
51
+ * build, and the package is in the Capybara plugin namespace. Returns why it is not, or undefined.
52
+ */
53
+ export declare function officialPublisherProblem(verified: VerifiedPublisher): string | undefined;
15
54
  /** Checks both signatures, transparency evidence and publisher identity with the bundled roots. */
16
55
  export declare function verifyOfficialPublisher(body: unknown, revision: OfficialNpmRevision): OfficialPublisherProof;
56
+ /**
57
+ * The official release workflow's certificate claims, without the per-build commit: what an
58
+ * official proof ({@link verifyOfficialPublisher}) established, for normalizing its publisher
59
+ * identity without the attestation bundle.
60
+ */
61
+ export declare const OFFICIAL_PUBLISHER_CERTIFICATE: Readonly<Omit<PublisherCertificate, "commit">>;
62
+ /** The result of {@link fetchPublisherAttestation}: verified, or why not. */
63
+ export type PublisherAttestation = {
64
+ ok: true;
65
+ verified: VerifiedPublisher;
66
+ } | {
67
+ ok: false;
68
+ reason: string;
69
+ transient: boolean;
70
+ };
71
+ /**
72
+ * One fetch of a revision's attestations for both its review: the display-only provenance and
73
+ * the publisher verified as any GitHub Actions publisher ({@link verifyPublisher}). Never throws:
74
+ * a missing, unreadable or unverifiable attestation is `ok: false` (transient for a network or
75
+ * registry hiccup). Integrity was checked by the caller.
76
+ */
77
+ export declare function fetchAttestationEvidence(cfg: NpmFetchConfig, revision: OfficialNpmRevision, signal?: AbortSignal): Promise<{
78
+ provenance: ProvenanceResult;
79
+ attestation: PublisherAttestation;
80
+ }>;
17
81
  /** Uses the same bounded registry client as the review's display-only provenance. */
18
82
  export declare function fetchOfficialPublisher(cfg: NpmFetchConfig, revision: OfficialNpmRevision, signal?: AbortSignal): Promise<OfficialPublisherProof>;
19
83
  /** A failed publisher check; `transient` failures (network, timeout, 5xx) may pass on a retry soon. */
@@ -5,7 +5,7 @@ import { toSignedEntity, toTrustMaterial, Verifier } from "@sigstore/verify";
5
5
  import { z } from "zod";
6
6
  import { canonicalJson } from "../tools/canonical-json.js";
7
7
  import npmPublishKeys from "./npm-publish-keys.json" with { type: "json" };
8
- import { fetchNpmAttestations, isTransientAttestationsFailure, PROVENANCE_TIMEOUT_MS, SLSA_PROVENANCE_V1, sha512Hex, } from "./provenance.js";
8
+ import { fetchNpmAttestations, fetchProvenanceWithBody, isTransientAttestationsFailure, PROVENANCE_TIMEOUT_MS, SLSA_PROVENANCE_V1, sha512Hex, } from "./provenance.js";
9
9
  import trustedRoot from "./sigstore-trusted-root.json" with { type: "json" };
10
10
  const NPM_PUBLISH = "https://github.com/npm/attestation/tree/main/specs/publish/v0.1";
11
11
  const REGISTRY = "https://registry.npmjs.org";
@@ -33,27 +33,6 @@ const statementSchema = z.object({
33
33
  .length(1),
34
34
  predicate: z.unknown(),
35
35
  });
36
- const buildSchema = z.object({
37
- buildDefinition: z.object({
38
- buildType: z.literal(BUILD_TYPE),
39
- externalParameters: z.object({
40
- workflow: z.object({
41
- repository: z.literal(REPOSITORY),
42
- path: z.literal(WORKFLOW),
43
- ref: z.literal(MAIN_REF),
44
- }),
45
- }),
46
- internalParameters: z.object({
47
- github: z.object({
48
- repository_id: z.literal(REPOSITORY_ID),
49
- repository_owner_id: z.literal(OWNER_ID),
50
- }),
51
- }),
52
- resolvedDependencies: z
53
- .array(z.object({ digest: z.object({ gitCommit: z.string().regex(/^[0-9a-f]{40}$/) }) }))
54
- .min(1),
55
- }),
56
- });
57
36
  const publishSchema = z.object({
58
37
  name: z.string(),
59
38
  version: z.string(),
@@ -82,7 +61,7 @@ function checkEnvelope(raw, type, revision) {
82
61
  }
83
62
  return { entity, predicate: statement.predicate };
84
63
  }
85
- function verifyBuildSigner(entity) {
64
+ function readBuildCertificate(entity) {
86
65
  if (entity.key.$case !== "certificate") {
87
66
  throw new Error("The build attestation has no signing certificate");
88
67
  }
@@ -90,23 +69,67 @@ function verifyBuildSigner(entity) {
90
69
  const signer = verifier.verify(entity, { extensions: { issuer: GITHUB_ISSUER } });
91
70
  // Fulcio extensions sign these GitHub OIDC claims independently of the predicate.
92
71
  const claim = (oid) => cert.extension(`1.3.6.1.4.1.57264.1.${oid}`)?.valueObj.subs[0]?.value.toString("utf8");
93
- if (claim(14) !== MAIN_REF || !claim(9)?.endsWith(`/${WORKFLOW}@${MAIN_REF}`)) {
94
- throw new Error("The signing certificate does not match the official release workflow or main ref");
72
+ const identity = signer.identity?.subjectAlternativeName;
73
+ const buildSigner = claim(9);
74
+ const repository = claim(12);
75
+ const ref = claim(14);
76
+ const repositoryId = claim(15);
77
+ const ownerId = claim(17);
78
+ const commit = claim(13);
79
+ if (!identity ||
80
+ !buildSigner ||
81
+ !repository ||
82
+ !ref ||
83
+ !repositoryId ||
84
+ !ownerId ||
85
+ !commit ||
86
+ identity !== buildSigner) {
87
+ throw new Error("The signing certificate does not carry a complete GitHub Actions identity");
95
88
  }
96
- if (signer.identity?.subjectAlternativeName !== WORKFLOW_IDENTITY ||
97
- claim(9) !== WORKFLOW_IDENTITY ||
98
- claim(12) !== REPOSITORY ||
99
- claim(15) !== REPOSITORY_ID ||
100
- claim(17) !== OWNER_ID) {
101
- throw new Error("The signing certificate does not match the official repository identity");
89
+ // A reusable workflow signs with its own file (the SAN and build signer name the called
90
+ // workflow, possibly in another repository at another ref), not the source repository's
91
+ // workflow. Such a signer is refused: the identity reviewers approve and continuity compares is
92
+ // `<repository>/<workflow>`, and a called workflow outside the repository would let whoever owns
93
+ // it publish under that repository's name, so the workflow must live in the source repository at
94
+ // the built ref.
95
+ const prefix = `${repository}/`;
96
+ const suffix = `@${ref}`;
97
+ if (!buildSigner.startsWith(prefix) || !buildSigner.endsWith(suffix)) {
98
+ throw new Error("The signing certificate's workflow is not in its source repository and ref");
102
99
  }
103
- const commit = claim(13);
104
- if (!commit)
105
- throw new Error("The signing certificate names no source commit");
106
- return commit;
100
+ const workflow = buildSigner.slice(prefix.length, buildSigner.length - suffix.length);
101
+ return {
102
+ issuer: GITHUB_ISSUER,
103
+ identity,
104
+ repository,
105
+ repositoryId,
106
+ ownerId,
107
+ workflow,
108
+ ref,
109
+ commit,
110
+ };
107
111
  }
108
- /** Checks both signatures, transparency evidence and publisher identity with the bundled roots. */
109
- export function verifyOfficialPublisher(body, revision) {
112
+ const genericBuildSchema = z.object({
113
+ buildDefinition: z.object({
114
+ buildType: z.string(),
115
+ externalParameters: z.object({
116
+ workflow: z.object({ repository: z.string(), path: z.string(), ref: z.string() }),
117
+ }),
118
+ internalParameters: z.object({
119
+ github: z.object({ repository_id: z.string(), repository_owner_id: z.string() }),
120
+ }),
121
+ resolvedDependencies: z
122
+ .array(z.object({ digest: z.object({ gitCommit: z.string().regex(/^[0-9a-f]{40}$/) }) }))
123
+ .min(1),
124
+ }),
125
+ });
126
+ /**
127
+ * Checks both signatures and the transparency evidence of an npm package revision built by GitHub
128
+ * Actions, with the bundled roots: the registry's publish attestation (an npm registry key) and the
129
+ * SLSA build attestation (a Fulcio certificate from the GitHub OIDC issuer). Returns the signing
130
+ * certificate's identity and the build predicate, still to be checked by the caller.
131
+ */
132
+ function attested(body, revision) {
110
133
  const { attestations } = attestationsSchema.parse(body);
111
134
  const [publish, ...duplicatePublish] = attestations.filter((a) => a.predicateType === NPM_PUBLISH);
112
135
  const [build, ...duplicateBuild] = attestations.filter((a) => a.predicateType === SLSA_PROVENANCE_V1);
@@ -123,27 +146,129 @@ export function verifyOfficialPublisher(body, revision) {
123
146
  }
124
147
  verifier.verify(published.entity);
125
148
  const built = checkEnvelope(build.bundle, SLSA_PROVENANCE_V1, revision);
126
- const commit = verifyBuildSigner(built.entity);
127
- const [source] = buildSchema.parse(built.predicate).buildDefinition.resolvedDependencies;
128
- if (source?.digest.gitCommit !== commit) {
149
+ return {
150
+ certificate: readBuildCertificate(built.entity),
151
+ predicate: built.predicate,
152
+ evidenceDigest: createHash("sha256")
153
+ .update(canonicalJson([publish.bundle, build.bundle]))
154
+ .digest("hex"),
155
+ };
156
+ }
157
+ /**
158
+ * Any GitHub Actions publisher (publisher evidence for review and continuity, plan task 1.2e):
159
+ * both attestations verified, and the build predicate in agreement with the certificate. The
160
+ * identity is returned as signed; `catalog/provenance.ts` normalizes it.
161
+ */
162
+ export function verifyPublisher(body, revision) {
163
+ const { certificate, predicate, evidenceDigest } = attested(body, revision);
164
+ const def = genericBuildSchema.parse(predicate).buildDefinition;
165
+ const workflow = def.externalParameters.workflow;
166
+ const [source] = def.resolvedDependencies;
167
+ if (workflow.repository !== certificate.repository ||
168
+ workflow.path !== certificate.workflow ||
169
+ workflow.ref !== certificate.ref ||
170
+ def.internalParameters.github.repository_id !== certificate.repositoryId ||
171
+ def.internalParameters.github.repository_owner_id !== certificate.ownerId) {
172
+ throw new Error("The build definition does not match the signing certificate");
173
+ }
174
+ if (source?.digest.gitCommit !== certificate.commit) {
129
175
  throw new Error("The signing certificate does not match the build's source commit");
130
176
  }
131
- if (!/^@capybara-hq\/plugin-[a-z0-9][a-z0-9-]*$/.test(revision.name)) {
132
- throw new Error("An official plugin must belong to the Capybara npm namespace");
177
+ return { revision, certificate, buildType: def.buildType, evidenceDigest };
178
+ }
179
+ const OFFICIAL_NAME = /^@capybara-hq\/plugin-[a-z0-9][a-z0-9-]*$/;
180
+ /**
181
+ * The one definition of official proof, shared by the official marketplace's admission
182
+ * ({@link verifyOfficialPublisher}) and publisher evidence (`classifyPublisherEvidence`): a revision
183
+ * whose attestations verified ({@link verifyPublisher}: the build predicate agrees with the
184
+ * certificate and its source commit) is official when the certificate is the official release
185
+ * workflow on the official repository's main ref, the build type is the GitHub Actions workflow
186
+ * build, and the package is in the Capybara plugin namespace. Returns why it is not, or undefined.
187
+ */
188
+ export function officialPublisherProblem(verified) {
189
+ const cert = verified.certificate;
190
+ if (cert.ref !== MAIN_REF || cert.workflow !== WORKFLOW) {
191
+ return "The signing certificate does not match the official release workflow or main ref";
192
+ }
193
+ if (cert.issuer !== GITHUB_ISSUER ||
194
+ cert.identity !== WORKFLOW_IDENTITY ||
195
+ cert.repository !== REPOSITORY ||
196
+ cert.repositoryId !== REPOSITORY_ID ||
197
+ cert.ownerId !== OWNER_ID) {
198
+ return "The signing certificate does not match the official repository identity";
199
+ }
200
+ if (verified.buildType !== BUILD_TYPE) {
201
+ return "The build attestation is not a GitHub Actions workflow build";
133
202
  }
203
+ if (!OFFICIAL_NAME.test(verified.revision.name)) {
204
+ return "An official plugin must belong to the Capybara npm namespace";
205
+ }
206
+ return undefined;
207
+ }
208
+ /** Checks both signatures, transparency evidence and publisher identity with the bundled roots. */
209
+ export function verifyOfficialPublisher(body, revision) {
210
+ const verified = verifyPublisher(body, revision);
211
+ const problem = officialPublisherProblem(verified);
212
+ if (problem)
213
+ throw new Error(problem);
134
214
  return {
135
215
  checked: true,
136
216
  revision,
137
217
  repository: REPOSITORY,
138
- commit,
218
+ commit: verified.certificate.commit,
139
219
  workflow: WORKFLOW,
140
220
  buildType: BUILD_TYPE,
141
- evidenceDigest: createHash("sha256")
142
- .update(canonicalJson([publish.bundle, build.bundle]))
143
- .digest("hex"),
221
+ evidenceDigest: verified.evidenceDigest,
144
222
  policyVersion: POLICY_VERSION,
145
223
  };
146
224
  }
225
+ /**
226
+ * The official release workflow's certificate claims, without the per-build commit: what an
227
+ * official proof ({@link verifyOfficialPublisher}) established, for normalizing its publisher
228
+ * identity without the attestation bundle.
229
+ */
230
+ export const OFFICIAL_PUBLISHER_CERTIFICATE = Object.freeze({
231
+ issuer: GITHUB_ISSUER,
232
+ identity: WORKFLOW_IDENTITY,
233
+ repository: REPOSITORY,
234
+ repositoryId: REPOSITORY_ID,
235
+ ownerId: OWNER_ID,
236
+ workflow: WORKFLOW,
237
+ ref: MAIN_REF,
238
+ });
239
+ /**
240
+ * One fetch of a revision's attestations for both its review: the display-only provenance and
241
+ * the publisher verified as any GitHub Actions publisher ({@link verifyPublisher}). Never throws:
242
+ * a missing, unreadable or unverifiable attestation is `ok: false` (transient for a network or
243
+ * registry hiccup). Integrity was checked by the caller.
244
+ */
245
+ export async function fetchAttestationEvidence(cfg, revision, signal) {
246
+ const timeout = AbortSignal.timeout(PROVENANCE_TIMEOUT_MS);
247
+ const got = await fetchProvenanceWithBody(cfg, revision.name, revision.version, signal ? AbortSignal.any([signal, timeout]) : timeout, { integrity: revision.integrity });
248
+ if (got.body === undefined) {
249
+ const reason = got.provenance.checked ? "no attestations" : got.provenance.reason;
250
+ return {
251
+ provenance: got.provenance,
252
+ attestation: { ok: false, reason, transient: got.transient === true },
253
+ };
254
+ }
255
+ try {
256
+ return {
257
+ provenance: got.provenance,
258
+ attestation: { ok: true, verified: verifyPublisher(got.body, revision) },
259
+ };
260
+ }
261
+ catch (e) {
262
+ return {
263
+ provenance: got.provenance,
264
+ attestation: {
265
+ ok: false,
266
+ reason: e instanceof Error ? e.message : String(e),
267
+ transient: false,
268
+ },
269
+ };
270
+ }
271
+ }
147
272
  /** Uses the same bounded registry client as the review's display-only provenance. */
148
273
  export async function fetchOfficialPublisher(cfg, revision, signal) {
149
274
  const timeout = AbortSignal.timeout(PROVENANCE_TIMEOUT_MS);
@@ -51,6 +51,17 @@ export declare function sha512Hex(integrity: string): string | undefined;
51
51
  export declare function fetchProvenance(cfg: NpmFetchConfig, name: string, version: string, signal: AbortSignal, opts?: {
52
52
  integrity?: string;
53
53
  }): Promise<ProvenanceResult>;
54
+ /**
55
+ * {@link fetchProvenance} that also returns the attestations answer it parsed, for the caller to
56
+ * verify the publisher from the same fetch. Never throws.
57
+ */
58
+ export declare function fetchProvenanceWithBody(cfg: NpmFetchConfig, name: string, version: string, signal: AbortSignal, opts?: {
59
+ integrity?: string;
60
+ }): Promise<{
61
+ provenance: ProvenanceResult;
62
+ body?: unknown;
63
+ transient?: boolean;
64
+ }>;
54
65
  /** Fetches bounded attestation evidence without accepting it as publisher proof. */
55
66
  export declare function fetchNpmAttestations(cfg: NpmFetchConfig, name: string, version: string, signal: AbortSignal): Promise<unknown>;
56
67
  /**
@@ -60,6 +60,30 @@ export async function fetchProvenance(cfg, name, version, signal, opts = {}) {
60
60
  return notChecked(e instanceof NpmAttestationsError ? e.message : `cannot read the attestations: ${errMsg(e)}`);
61
61
  }
62
62
  }
63
+ /**
64
+ * {@link fetchProvenance} that also returns the attestations answer it parsed, for the caller to
65
+ * verify the publisher from the same fetch. Never throws.
66
+ */
67
+ export async function fetchProvenanceWithBody(cfg, name, version, signal, opts = {}) {
68
+ let body;
69
+ try {
70
+ body = await fetchNpmAttestations(cfg, name, version, signal);
71
+ }
72
+ catch (e) {
73
+ return {
74
+ provenance: notChecked(e instanceof NpmAttestationsError
75
+ ? e.message
76
+ : `cannot read the attestations: ${errMsg(e)}`),
77
+ transient: isTransientAttestationsFailure(e),
78
+ };
79
+ }
80
+ try {
81
+ return { provenance: parseAttestations(body, opts.integrity), body };
82
+ }
83
+ catch (e) {
84
+ return { provenance: notChecked(`cannot read the attestations: ${errMsg(e)}`), body };
85
+ }
86
+ }
63
87
  /** Fetches bounded attestation evidence without accepting it as publisher proof. */
64
88
  export async function fetchNpmAttestations(cfg, name, version, signal) {
65
89
  if (!NPM_NAME_RE.test(name) || name.length > 214 || !SEMVER_RE.test(version)) {
@@ -61,9 +61,9 @@ export const PLATFORM_EXCLUSIONS = [
61
61
  reason: "Delivers other orgs' config copies of an extension (which differ, which secrets each holds) to the super admin's browser; an agent works in its own org",
62
62
  },
63
63
  {
64
- route: "POST /api/v1/admin/extensions/:name/approve",
64
+ route: "POST /api/v1/admin/extension-permissions/:name/approve",
65
65
  category: "human-only",
66
- reason: "Approves an extension's permission manifest, a trust decision",
66
+ reason: "Human security consent: a person approves an extension revision's permission review, full access included with one acknowledgement per realm; refused unattended",
67
67
  },
68
68
  {
69
69
  route: "POST /api/v1/admin/extensions/:name/install",
@@ -145,12 +145,12 @@ export const PLATFORM_EXCLUSIONS = [
145
145
  {
146
146
  route: "POST /api/v1/admin/catalog/imports/:stagingId/confirm",
147
147
  category: "human-only",
148
- reason: "Confirms an import review, an approval decision by the super admin",
148
+ reason: "Human security consent: confirms an import review and its revision's permissions, full access with one acknowledgement per realm",
149
149
  },
150
150
  {
151
151
  route: "POST /api/v1/admin/catalog/imports/:stagingId/update",
152
152
  category: "human-only",
153
- reason: "Confirms an import review together with the platform update it applies, an approval decision by the super admin",
153
+ reason: "Human security consent: confirms an import review and its revision's permissions together with the platform update it applies, full access with one acknowledgement per realm",
154
154
  },
155
155
  {
156
156
  route: "GET /api/v1/admin/catalog/items/:id/icon",
@@ -488,7 +488,7 @@ let AutomationsOperations = class AutomationsOperations {
488
488
  }),
489
489
  defineOperation({
490
490
  id: "automations.runs",
491
- description: "A task's run history, latest first (default 50, at most 200): each tick with its status, skip reason, error, conversation and the tools refused for lack of an approval. Takes the id from automations.list.",
491
+ description: "A task's run history, latest first (default 50, at most 200): each tick with its status, skip reason, error, conversation and the tools refused for lack of an approval (automations.grants-add can approve those). An entry `review:<command|write|read>` is a call the command review held: it always needs a person and is never grantable. Takes the id from automations.list.",
492
492
  input: RunsQuery.extend({ automationId: Id }).strict(),
493
493
  example: { automationId: EXAMPLE_ID },
494
494
  authz: { orgAction: "automations.use" },
@@ -469,7 +469,7 @@ let CatalogAdminOperations = class CatalogAdminOperations {
469
469
  }),
470
470
  defineOperation({
471
471
  id: "plugins.set-scope",
472
- description: "Change where a platform plugin is on (super admin), for every org at once: pass the scope (and orgs for named) and the scopeHash plugins.scope-preview returned for that same target. Orgs that lose it have it removed by the scope sync; a preview that is out of date is refused.",
472
+ description: "Change where a platform plugin is on (super admin), for every org at once: pass the scope (and orgs for named) and the scopeHash plugins.scope-preview returned for that same target. Orgs that lose it have it removed by the scope sync; a preview that is out of date is refused. This operation only narrows: a scope reaching orgs the current one does not is not applied (applied: false) and you widen it yourself in the admin console, where it opens.",
473
473
  input: z.object({ itemId: ItemId, ...CatalogScopeBody.shape }).strict(),
474
474
  example: {
475
475
  itemId: "3f1c2a9e-5b7d-4e21-9c0a-1d2e3f4a5b6c",
@@ -550,10 +550,31 @@ let CatalogAdminOperations = class CatalogAdminOperations {
550
550
  scope: input.scope,
551
551
  ...(input.orgs !== undefined && { orgs: input.orgs }),
552
552
  };
553
- return {
554
- item: await this.withoutPluginNames(input.itemId, target, () => this.scope.setScope(ctx.actorAccountId, input.itemId, { ...target, scopeHash: input.scopeHash }, { auditDetail: viaAgent("plugins.set-scope", ctx) })),
555
- };
553
+ try {
554
+ return {
555
+ applied: true,
556
+ item: await this.withoutPluginNames(input.itemId, target, () => this.scope.setScope(ctx.actorAccountId, input.itemId, { ...target, scopeHash: input.scopeHash },
557
+ // the Platform tool only narrows; widening is the person's, on the web
558
+ { auditDetail: viaAgent("plugins.set-scope", ctx), onlyNarrows: true })),
559
+ };
560
+ }
561
+ catch (e) {
562
+ if (e instanceof ApiError && e.code === "plugin.scope_widening_not_allowed") {
563
+ return { applied: false, code: e.code, message: e.message };
564
+ }
565
+ throw e;
566
+ }
556
567
  },
568
+ handoff: (input, result) => result?.applied === false
569
+ ? {
570
+ kind: "handoff",
571
+ title: {
572
+ zh: "在管理后台扩大插件范围",
573
+ en: "Widen the plugin's scope in the admin console",
574
+ },
575
+ target: { type: "link", url: `/admin/plugins/${encodeURIComponent(input.itemId)}` },
576
+ }
577
+ : null,
557
578
  }),
558
579
  defineOperation({
559
580
  id: "plugins.set-disabled",
@@ -0,0 +1,11 @@
1
+ import { type OnModuleInit } from "@nestjs/common";
2
+ import { ExtensionPermissions } from "../../extensions/permissions.service.js";
3
+ import { KernelDb } from "../../infra/database/kernel-db.js";
4
+ import { PlatformOperations } from "../registry.js";
5
+ export declare class ExtensionPermissionOperations implements OnModuleInit {
6
+ private readonly registry;
7
+ private readonly permissions;
8
+ private readonly kdb;
9
+ constructor(registry: PlatformOperations, permissions: ExtensionPermissions, kdb: KernelDb);
10
+ onModuleInit(): void;
11
+ }