@capybara-hq/kernel 0.1.0-rc.132 → 0.1.0-rc.134
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.
- package/bootstrap.json +5 -5
- package/dist/admin/admin.module.js +3 -0
- package/dist/admin/admin.schemas.d.ts +4 -0
- package/dist/admin/health.service.d.ts +2 -2
- package/dist/admin/health.service.js +6 -2
- package/dist/admin/setup.service.js +6 -1
- package/dist/agents/agents.controller.js +3 -2
- package/dist/agents/agents.service.d.ts +2 -0
- package/dist/agents/agents.service.js +7 -0
- package/dist/automations/events/trigger-events.service.d.ts +13 -1
- package/dist/automations/events/trigger-events.service.js +27 -14
- package/dist/catalog/catalog.service.d.ts +2 -0
- package/dist/catalog/catalog.service.js +28 -5
- package/dist/catalog/marketplace-fetch.d.ts +2 -0
- package/dist/catalog/marketplace-fetch.js +15 -0
- package/dist/catalog/marketplaces.service.d.ts +4 -4
- package/dist/catalog/marketplaces.service.js +3 -2
- package/dist/catalog/owned-items.d.ts +2 -0
- package/dist/catalog/owned-items.js +30 -31
- package/dist/catalog/ownership.js +40 -38
- package/dist/catalog/plugin-import.d.ts +3 -4
- package/dist/catalog/plugin-import.js +50 -1
- package/dist/catalog/plugin-upgrade.d.ts +8 -0
- package/dist/catalog/plugin-upgrade.js +95 -7
- package/dist/catalog/publisher-policy.d.ts +9 -0
- package/dist/catalog/publisher-policy.js +12 -0
- package/dist/catalog/unshare.js +66 -58
- package/dist/client/client-access.service.js +5 -3
- package/dist/config/schema.d.ts +1 -0
- package/dist/config/schema.js +8 -1
- package/dist/conversations/conversations.controller.js +4 -14
- package/dist/conversations/conversations.service.d.ts +14 -0
- package/dist/conversations/conversations.service.js +20 -2
- package/dist/ctx/create-ctx.d.ts +15 -2
- package/dist/ctx/create-ctx.js +195 -79
- package/dist/ctx/durable-cancellation.d.ts +3 -0
- package/dist/ctx/durable-cancellation.js +8 -0
- package/dist/ctx/durable-effects.service.d.ts +81 -0
- package/dist/ctx/durable-effects.service.js +316 -0
- package/dist/ctx/durable-envelope.d.ts +24 -0
- package/dist/ctx/durable-envelope.js +80 -0
- package/dist/ctx/durable-failure.d.ts +7 -0
- package/dist/ctx/durable-failure.js +32 -0
- package/dist/ctx/durable-job.d.ts +9 -0
- package/dist/ctx/durable-job.js +2 -0
- package/dist/ctx/durable-keys.d.ts +27 -0
- package/dist/ctx/durable-keys.js +138 -0
- package/dist/ctx/durable-relay.d.ts +29 -0
- package/dist/ctx/durable-relay.js +250 -0
- package/dist/ctx/queue.d.ts +2 -0
- package/dist/ctx/queue.js +25 -15
- package/dist/db/extension-db.js +2 -0
- package/dist/db/extension-handoff-schema.d.ts +6 -0
- package/dist/db/extension-handoff-schema.js +72 -0
- package/dist/db/extension-rls-predicate.d.ts +1 -0
- package/dist/db/extension-rls-predicate.js +8 -0
- package/dist/db/extension-schema-transfer.d.ts +1 -1
- package/dist/db/extension-schema-transfer.js +18 -6
- package/dist/db/kernel-schema.d.ts +64 -0
- package/dist/db/migrator.js +6 -13
- package/dist/db/pool.d.ts +2 -2
- package/dist/db/pool.js +2 -2
- package/dist/db/sql-statements.d.ts +3 -0
- package/dist/db/sql-statements.js +15 -5
- package/dist/device-access/device-access.module.js +12 -2
- package/dist/device-access/device-access.service.d.ts +30 -2
- package/dist/device-access/device-access.service.js +38 -4
- package/dist/device-access/host-gate.d.ts +45 -0
- package/dist/device-access/host-gate.js +92 -0
- package/dist/device-access/host-service-stop-sweep.d.ts +33 -0
- package/dist/device-access/host-service-stop-sweep.js +112 -0
- package/dist/device-access/host-service-stop.d.ts +78 -0
- package/dist/device-access/host-service-stop.js +144 -0
- package/dist/device-access/host-services.d.ts +211 -0
- package/dist/device-access/host-services.js +803 -0
- package/dist/device-access/person-handles.d.ts +10 -0
- package/dist/device-access/person-handles.js +25 -0
- package/dist/device-access/service-events.d.ts +199 -0
- package/dist/device-access/service-events.js +704 -0
- package/dist/device-access/token.d.ts +5 -0
- package/dist/device-access/token.js +5 -0
- package/dist/devices/devices.service.js +3 -0
- package/dist/dial-in/access.d.ts +5 -5
- package/dist/dial-in/access.js +19 -12
- package/dist/dial-in/gateway.js +6 -2
- package/dist/dial-in/machines.d.ts +9 -2
- package/dist/dial-in/machines.js +27 -4
- package/dist/erasure/device-cleanup.js +12 -0
- package/dist/erasure/org-catalog.js +2 -2
- package/dist/erasure/org-rules.js +10 -0
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +2 -0
- package/dist/extensions/admin-ops.js +8 -2
- package/dist/extensions/deployed-snapshots.d.ts +4 -1
- package/dist/extensions/deployed-snapshots.js +7 -2
- package/dist/extensions/extensions.module.js +10 -0
- package/dist/extensions/host.d.ts +12 -2
- package/dist/extensions/host.js +44 -22
- package/dist/extensions/instance.d.ts +5 -0
- package/dist/extensions/instance.js +10 -0
- package/dist/extensions/ledger.d.ts +1 -1
- package/dist/extensions/lifecycle-hooks.js +3 -3
- package/dist/extensions/org-config.js +6 -1
- package/dist/extensions/permission-set.d.ts +7 -0
- package/dist/extensions/permission-set.js +10 -0
- package/dist/extensions/permission-view.d.ts +1 -1
- package/dist/extensions/permission-view.js +10 -1
- package/dist/extensions/sources.d.ts +1 -0
- package/dist/extensions/sources.js +9 -0
- package/dist/git/tickets.js +32 -27
- package/dist/http/app.js +5 -3
- package/dist/identity/accounts.d.ts +6 -1
- package/dist/identity/accounts.js +11 -2
- package/dist/identity/api-tokens.js +7 -6
- package/dist/identity/settings.d.ts +9 -1
- package/dist/identity/settings.js +16 -1
- package/dist/inbox/inbox-items.service.d.ts +5 -0
- package/dist/inbox/inbox-items.service.js +57 -33
- package/dist/inbox/org-notices.js +3 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/infra/database/extension-effect-key-lock.d.ts +10 -0
- package/dist/infra/database/extension-effect-key-lock.js +69 -0
- package/dist/infra/database/extension-handoff.d.ts +27 -0
- package/dist/infra/database/extension-handoff.js +113 -0
- package/dist/infra/database/scoped-dialect.d.ts +3 -2
- package/dist/infra/database/scoped-dialect.js +260 -72
- package/dist/infra/database/startup-activation-transaction.d.ts +2 -0
- package/dist/infra/database/startup-activation-transaction.js +3 -2
- package/dist/infra/outbox/outbox.dispatcher.d.ts +6 -1
- package/dist/infra/outbox/outbox.dispatcher.js +64 -4
- package/dist/infra/outbox/outbox.module.js +2 -0
- package/dist/infra/outbox/registry.d.ts +40 -0
- package/dist/infra/outbox/registry.js +42 -0
- package/dist/infra/queue/queue-names.d.ts +1 -1
- package/dist/infra/queue/queue-names.js +1 -0
- package/dist/infra/queue/run-job.d.ts +4 -1
- package/dist/infra/queue/run-job.js +10 -2
- package/dist/kernel.js +1 -0
- package/dist/kernel.module.js +3 -0
- package/dist/orgs/offboarding.js +18 -9
- package/dist/orgs/orgs.service.js +16 -0
- package/dist/orgs/settings.service.js +3 -0
- package/dist/packages/npm-publish-keys.json +27 -0
- package/dist/packages/official-publisher.d.ts +19 -0
- package/dist/packages/official-publisher.js +152 -0
- package/dist/packages/provenance.d.ts +7 -0
- package/dist/packages/provenance.js +22 -19
- package/dist/packages/sigstore-trusted-root.json +126 -0
- package/dist/platform/ops/admin.ops.js +2 -1
- package/dist/platform/ops/orgs.ops.js +1 -0
- package/dist/roles/worker-role.d.ts +6 -3
- package/dist/roles/worker-role.js +12 -4
- package/dist/roles/worker.module.js +9 -0
- package/dist/runtime/maintenance.d.ts +5 -2
- package/dist/runtime/maintenance.js +18 -4
- package/dist/sandbox/device-reports.d.ts +4 -4
- package/dist/sandbox/device-reports.js +40 -30
- package/dist/sandbox/device-services.d.ts +2 -1
- package/dist/sandbox/device-services.js +5 -1
- package/dist/sandbox/permission-ceiling-writes.d.ts +8 -0
- package/dist/sandbox/permission-ceiling-writes.js +21 -0
- package/dist/sandbox/permission-config-publication.js +5 -1
- package/dist/themes/theme-state.js +24 -13
- package/dist/tools/call-scope.d.ts +6 -0
- package/dist/tools/call-scope.js +22 -0
- package/dist/tools/registry.js +20 -2
- package/dist/ui/views.js +36 -8
- package/package.json +9 -4
- package/src/migrations/0222_device_host_services.sql +27 -0
- package/src/migrations/0223_device_service_events.sql +54 -0
- package/src/migrations/0224_cache_conversation_rls_settings.sql +33 -0
- package/src/migrations/0225_extension_effect_receipts.sql +25 -0
|
@@ -19,6 +19,18 @@ export interface OutboxJobSpec {
|
|
|
19
19
|
* name without one does not type-check as an `OutboxJobName` (`add` does not check it at runtime).
|
|
20
20
|
*/
|
|
21
21
|
export declare const OUTBOX_JOBS: {
|
|
22
|
+
readonly "extension-queue-effect": {
|
|
23
|
+
readonly queue: "cap-kernel-maintenance";
|
|
24
|
+
readonly processedIn: "packages/kernel/src/infra/outbox/outbox.dispatcher.ts";
|
|
25
|
+
readonly idempotent: "Adds a plugin queue job with a deterministic destination ID. Plugin job handlers are idempotent.";
|
|
26
|
+
readonly opts: {};
|
|
27
|
+
};
|
|
28
|
+
readonly "extension-effect-redrive": {
|
|
29
|
+
readonly queue: "cap-kernel-maintenance";
|
|
30
|
+
readonly processedIn: "packages/kernel/src/ctx/durable-relay.ts";
|
|
31
|
+
readonly idempotent: "Verifies the original signed effect and checks its durable receipt before applying it.";
|
|
32
|
+
readonly opts: {};
|
|
33
|
+
};
|
|
22
34
|
readonly "data-erasure": {
|
|
23
35
|
readonly queue: "cap-kernel-maintenance";
|
|
24
36
|
readonly idempotent: "Each generation claims the durable request under a row lock. Stale and completed deliveries do nothing.";
|
|
@@ -570,6 +582,34 @@ export declare const OUTBOX_JOBS: {
|
|
|
570
582
|
readonly removeOnFail: true;
|
|
571
583
|
};
|
|
572
584
|
};
|
|
585
|
+
readonly "device-host-services-stop": {
|
|
586
|
+
readonly queue: "cap-kernel-maintenance";
|
|
587
|
+
readonly idempotent: "Stops the extension's host services on the devices that started one; stopping a service that is not running is a no-op";
|
|
588
|
+
readonly processedIn: "packages/kernel/src/runtime/maintenance.ts";
|
|
589
|
+
readonly opts: {
|
|
590
|
+
readonly attempts: 10;
|
|
591
|
+
readonly backoff: {
|
|
592
|
+
readonly type: "exponential";
|
|
593
|
+
readonly delay: 5000;
|
|
594
|
+
};
|
|
595
|
+
readonly removeOnComplete: true;
|
|
596
|
+
readonly removeOnFail: true;
|
|
597
|
+
};
|
|
598
|
+
};
|
|
599
|
+
readonly "device-service-events": {
|
|
600
|
+
readonly queue: "cap-device-service-events";
|
|
601
|
+
readonly idempotent: "the delivery takes the service's lock and hands on only rows not yet marked delivered, in seq order, marking each once its handler resolved; a repeat finds them delivered (handlers get each event at least once)";
|
|
602
|
+
readonly processedIn: "packages/kernel/src/device-access/service-events.ts";
|
|
603
|
+
readonly opts: {
|
|
604
|
+
readonly attempts: 10;
|
|
605
|
+
readonly backoff: {
|
|
606
|
+
readonly type: "exponential";
|
|
607
|
+
readonly delay: 2000;
|
|
608
|
+
};
|
|
609
|
+
readonly removeOnComplete: true;
|
|
610
|
+
readonly removeOnFail: true;
|
|
611
|
+
};
|
|
612
|
+
};
|
|
573
613
|
readonly "hook-run-lifecycle": {
|
|
574
614
|
readonly queue: "cap-kernel-lifecycle";
|
|
575
615
|
readonly idempotent: "the `run.lifecycle` handler sets a display state keyed by the run and phase (the SDK contract: handlers are idempotent); the job id is deterministic per run, phase and wait";
|
|
@@ -21,6 +21,18 @@ const SCOPE_JOB_OPTS = {
|
|
|
21
21
|
* name without one does not type-check as an `OutboxJobName` (`add` does not check it at runtime).
|
|
22
22
|
*/
|
|
23
23
|
export const OUTBOX_JOBS = {
|
|
24
|
+
"extension-queue-effect": {
|
|
25
|
+
queue: "cap-kernel-maintenance",
|
|
26
|
+
processedIn: "packages/kernel/src/infra/outbox/outbox.dispatcher.ts",
|
|
27
|
+
idempotent: "Adds a plugin queue job with a deterministic destination ID. Plugin job handlers are idempotent.",
|
|
28
|
+
opts: {},
|
|
29
|
+
},
|
|
30
|
+
"extension-effect-redrive": {
|
|
31
|
+
queue: "cap-kernel-maintenance",
|
|
32
|
+
processedIn: "packages/kernel/src/ctx/durable-relay.ts",
|
|
33
|
+
idempotent: "Verifies the original signed effect and checks its durable receipt before applying it.",
|
|
34
|
+
opts: {},
|
|
35
|
+
},
|
|
24
36
|
"data-erasure": {
|
|
25
37
|
queue: "cap-kernel-maintenance",
|
|
26
38
|
idempotent: "Each generation claims the durable request under a row lock. Stale and completed deliveries do nothing.",
|
|
@@ -512,6 +524,36 @@ export const OUTBOX_JOBS = {
|
|
|
512
524
|
removeOnFail: true,
|
|
513
525
|
},
|
|
514
526
|
},
|
|
527
|
+
// `device-access/host-service-stop.ts` HOST_SERVICES_STOP_JOB: owed by the transaction that
|
|
528
|
+
// switches an extension off in an org (`OrgExtensionConfigs`) or on the deployment
|
|
529
|
+
// (`ExtensionAdminOps`), under `hostServicesStopJobId` (local agents spec, call 5)
|
|
530
|
+
"device-host-services-stop": {
|
|
531
|
+
queue: "cap-kernel-maintenance",
|
|
532
|
+
idempotent: "Stops the extension's host services on the devices that started one; stopping a service that is not running is a no-op",
|
|
533
|
+
processedIn: "packages/kernel/src/runtime/maintenance.ts",
|
|
534
|
+
opts: {
|
|
535
|
+
attempts: 10,
|
|
536
|
+
backoff: { type: "exponential", delay: 5_000 },
|
|
537
|
+
removeOnComplete: true,
|
|
538
|
+
removeOnFail: true,
|
|
539
|
+
},
|
|
540
|
+
},
|
|
541
|
+
// `device-access/service-events.ts` SERVICE_EVENTS_JOB: owed by the transaction that stores a
|
|
542
|
+
// device service event (`ServiceEvents.record`, local agents spec Part 1), under
|
|
543
|
+
// `serviceEventsJobId` (one per event)
|
|
544
|
+
"device-service-events": {
|
|
545
|
+
queue: "cap-device-service-events",
|
|
546
|
+
idempotent: "the delivery takes the service's lock and hands on only rows not yet marked delivered, in seq order, marking each once its handler resolved; a repeat finds them delivered (handlers get each event at least once)",
|
|
547
|
+
processedIn: "packages/kernel/src/device-access/service-events.ts",
|
|
548
|
+
// 10 attempts from 2 s, doubling (about 17 min in all); removed once done, so the same event
|
|
549
|
+
// reported again owes a job that is not deduped away
|
|
550
|
+
opts: {
|
|
551
|
+
attempts: 10,
|
|
552
|
+
backoff: { type: "exponential", delay: 2_000 },
|
|
553
|
+
removeOnComplete: true,
|
|
554
|
+
removeOnFail: true,
|
|
555
|
+
},
|
|
556
|
+
},
|
|
515
557
|
// `extensions/run-lifecycle-owe.ts` RUN_LIFECYCLE_JOB: owed by the transaction that starts a
|
|
516
558
|
// run, suspends it on a person, resumes it, ends it (finished, failed, aborted) or declines,
|
|
517
559
|
// expires or gives up on directed work, once per phase of a run (and wait) and plugin
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* (admin/health.service.ts) lists the same names from the feature constants;
|
|
5
5
|
* test/infra/queue-names.test.ts keeps the two equal.
|
|
6
6
|
*/
|
|
7
|
-
export declare const KERNEL_QUEUES: readonly ["cap-kernel-runs", "cap-kernel-subagent-runs", "cap-kernel-channels", "cap-kernel-maintenance", "cap-kernel-tool-watch", "cap-kernel-plugin-scope", "cap-kernel-titles", "cap-kernel-suggestions", "cap-kernel-usage-report", "cap-kernel-evals", "cap-kernel-lifecycle", "cap-push-deliver", "cap-connector-tools", "cap-template-connectors"];
|
|
7
|
+
export declare const KERNEL_QUEUES: readonly ["cap-kernel-runs", "cap-kernel-subagent-runs", "cap-kernel-channels", "cap-kernel-maintenance", "cap-kernel-tool-watch", "cap-kernel-plugin-scope", "cap-kernel-titles", "cap-kernel-suggestions", "cap-kernel-usage-report", "cap-kernel-evals", "cap-kernel-lifecycle", "cap-push-deliver", "cap-connector-tools", "cap-template-connectors", "cap-device-service-events"];
|
|
8
8
|
export type KernelQueueName = (typeof KERNEL_QUEUES)[number];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ContextJob } from "../../log-context.js";
|
|
2
|
+
import { type OrgScope } from "../database/org-scope.js";
|
|
2
3
|
/**
|
|
3
4
|
* The wrapper every queue processor runs its job in: a fresh async context (no transaction of
|
|
4
5
|
* whoever enqueued the job or started the worker is visible), `queue` / `jobId` / `runId` in the
|
|
@@ -6,7 +7,8 @@ import { type ContextJob } from "../../log-context.js";
|
|
|
6
7
|
* §5.3, §10) is the job's org when its data carries a string `orgId`; else the platform scope when
|
|
7
8
|
* the queue's work is deployment-wide (`opts.platform`, the reason); else none, never inherited
|
|
8
9
|
* from whoever started the worker (a missing org fails closed once RLS is enforced, and the
|
|
9
|
-
* unscoped-query check reports it).
|
|
10
|
+
* unscoped-query check reports it). An explicit `opts.scope` overrides payload inference, with
|
|
11
|
+
* `null` selecting no scope.
|
|
10
12
|
*
|
|
11
13
|
* ```ts
|
|
12
14
|
* @Processor("cap-kernel-titles")
|
|
@@ -19,4 +21,5 @@ import { type ContextJob } from "../../log-context.js";
|
|
|
19
21
|
*/
|
|
20
22
|
export declare function runJob<T>(queue: string, job: ContextJob, fn: () => Promise<T>, opts?: {
|
|
21
23
|
platform?: string;
|
|
24
|
+
scope?: OrgScope | null;
|
|
22
25
|
}): Promise<T>;
|
|
@@ -8,7 +8,8 @@ import { runOutsideTransaction } from "../database/transaction-host.js";
|
|
|
8
8
|
* §5.3, §10) is the job's org when its data carries a string `orgId`; else the platform scope when
|
|
9
9
|
* the queue's work is deployment-wide (`opts.platform`, the reason); else none, never inherited
|
|
10
10
|
* from whoever started the worker (a missing org fails closed once RLS is enforced, and the
|
|
11
|
-
* unscoped-query check reports it).
|
|
11
|
+
* unscoped-query check reports it). An explicit `opts.scope` overrides payload inference, with
|
|
12
|
+
* `null` selecting no scope.
|
|
12
13
|
*
|
|
13
14
|
* ```ts
|
|
14
15
|
* @Processor("cap-kernel-titles")
|
|
@@ -20,9 +21,16 @@ import { runOutsideTransaction } from "../database/transaction-host.js";
|
|
|
20
21
|
* ```
|
|
21
22
|
*/
|
|
22
23
|
export function runJob(queue, job, fn, opts = {}) {
|
|
23
|
-
const orgId = job.data?.orgId;
|
|
24
24
|
const run = () => withJobContext(queue, job, fn);
|
|
25
25
|
return runOutsideTransaction(() => {
|
|
26
|
+
if (opts.scope !== undefined) {
|
|
27
|
+
if (opts.scope?.kind === "org")
|
|
28
|
+
return withOrgScope(opts.scope.orgId, run);
|
|
29
|
+
if (opts.scope?.kind === "platform")
|
|
30
|
+
return asPlatform(opts.scope.reason, run);
|
|
31
|
+
return withoutOrgScope(run);
|
|
32
|
+
}
|
|
33
|
+
const orgId = job.data?.orgId;
|
|
26
34
|
if (typeof orgId === "string" && orgId !== "")
|
|
27
35
|
return withOrgScope(orgId, run);
|
|
28
36
|
if (opts.platform !== undefined)
|
package/dist/kernel.js
CHANGED
|
@@ -52,6 +52,7 @@ export async function migrateAll(config, opts = {}) {
|
|
|
52
52
|
dbUrl: config.db.url,
|
|
53
53
|
...(config.db.extensionsUrl !== undefined && {
|
|
54
54
|
extensionIdentity: extensionDbIdentity(config.db),
|
|
55
|
+
handoffRuntimeLogin: config.db.extensionEffectRelayLogin ?? "capybara_runtime",
|
|
55
56
|
}),
|
|
56
57
|
connectTimeoutMs,
|
|
57
58
|
autoApprove: config.extensionPermissions.autoApprove,
|
package/dist/kernel.module.js
CHANGED
|
@@ -14,6 +14,7 @@ import { ClientModule } from "./client/client.module.js";
|
|
|
14
14
|
import { PromptSuggestionsModule } from "./conversations/prompt-suggestions.js";
|
|
15
15
|
import { TitlesModule } from "./conversations/titles.js";
|
|
16
16
|
import { ExtensionDeviceAccessModule } from "./device-access/device-access.module.js";
|
|
17
|
+
import { DeviceServiceEventsModule } from "./device-access/service-events.js";
|
|
17
18
|
import { BootstrapDefaultsService } from "./extensions/bootstrap-defaults.js";
|
|
18
19
|
import { ExtensionsModule } from "./extensions/extensions.module.js";
|
|
19
20
|
import { ApiModule } from "./http/api.module.js";
|
|
@@ -134,6 +135,8 @@ let KernelModule = KernelModule_1 = class KernelModule {
|
|
|
134
135
|
ClientModule,
|
|
135
136
|
// ctx.deviceAccess: extensions' device services (the host finds it at the time of use)
|
|
136
137
|
ExtensionDeviceAccessModule,
|
|
138
|
+
// ctx.devices.serviceEvent: host service events (the host finds it at the time of use)
|
|
139
|
+
DeviceServiceEventsModule,
|
|
137
140
|
// ctx.triggers: the events extensions emit (the host finds it at the time of use)
|
|
138
141
|
TriggerEventsModule,
|
|
139
142
|
// ctx.inbox: personal inbox items extensions post (the host finds it at the time of use)
|
package/dist/orgs/offboarding.js
CHANGED
|
@@ -13,6 +13,7 @@ import { sql } from "kysely";
|
|
|
13
13
|
import { retargetSetupRequests } from "../agents/pending-connector-requests.js";
|
|
14
14
|
import { EventLog } from "../conversations/event-log.js";
|
|
15
15
|
import { lockConversationTrees } from "../conversations/tree.js";
|
|
16
|
+
import { oweHostServicesStopOnDevices } from "../device-access/host-service-stop.js";
|
|
16
17
|
import { revokeSiteGrantsOfDevice } from "../device-access/site-grants.js";
|
|
17
18
|
import { ApiError } from "../errors.js";
|
|
18
19
|
import { enabledExtensionsQuery } from "../extensions/enabled.js";
|
|
@@ -21,6 +22,7 @@ import { ExtensionRegistry } from "../extensions/registry.js";
|
|
|
21
22
|
import { audit } from "../identity/audit.js";
|
|
22
23
|
import { SessionService } from "../identity/sessions.js";
|
|
23
24
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
25
|
+
import { asPlatform } from "../infra/database/org-scope.js";
|
|
24
26
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
25
27
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
26
28
|
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
@@ -199,16 +201,18 @@ let Offboarding = class Offboarding {
|
|
|
199
201
|
.returning("id")
|
|
200
202
|
.execute()
|
|
201
203
|
: [];
|
|
202
|
-
// org-filter: removal revokes the person's personal tokens account-wide on purpose (comment above)
|
|
203
204
|
const tokens = revoke
|
|
204
|
-
? await
|
|
205
|
-
.
|
|
206
|
-
.
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
205
|
+
? await asPlatform("Revoke account-wide personal tokens after member removal", () => {
|
|
206
|
+
// org-filter: personal tokens belong to the account and have a null org_id.
|
|
207
|
+
return this.db
|
|
208
|
+
.updateTable("api_tokens")
|
|
209
|
+
.set({ revoked_at: sql `now()` })
|
|
210
|
+
.where("kind", "=", "personal")
|
|
211
|
+
.where("account_id", "=", accountId)
|
|
212
|
+
.where("revoked_at", "is", null)
|
|
213
|
+
.returning("id")
|
|
214
|
+
.execute();
|
|
215
|
+
})
|
|
212
216
|
: [];
|
|
213
217
|
// a registration follows its session (push plan decision 3)
|
|
214
218
|
await deletePushRegistrationsForSessions(this.db.db, sessions.map((r) => r.id));
|
|
@@ -320,6 +324,11 @@ let Offboarding = class Offboarding {
|
|
|
320
324
|
await revokeLoopbackGrantsOfDevice(this.db.db, this.outbox, { orgId, deviceId: d.id });
|
|
321
325
|
await revokeSiteGrantsOfDevice(this.db.db, { orgId, deviceId: d.id });
|
|
322
326
|
}
|
|
327
|
+
// the person's host services in the org end with their devices (local agents spec, call 5)
|
|
328
|
+
await oweHostServicesStopOnDevices(this.db.db, this.outbox, {
|
|
329
|
+
orgId,
|
|
330
|
+
deviceIds: devices.map((d) => d.id),
|
|
331
|
+
});
|
|
323
332
|
await this.db
|
|
324
333
|
.deleteFrom("device_defaults")
|
|
325
334
|
.where("org_id", "=", orgId)
|
|
@@ -13,6 +13,7 @@ import { sql } from "kysely";
|
|
|
13
13
|
import { OwnedItems } from "../catalog/owned-items.js";
|
|
14
14
|
import { cancelPendingRequests } from "../catalog/request-rules.js";
|
|
15
15
|
import { PluginScopeSync } from "../catalog/scope-sync.js";
|
|
16
|
+
import { EXTENSION_QUEUE_EFFECT_JOB } from "../ctx/durable-job.js";
|
|
16
17
|
import { ErasureRequests } from "../erasure/requests.js";
|
|
17
18
|
import { ApiError } from "../errors.js";
|
|
18
19
|
import { EvalBudget } from "../evals/budget.js";
|
|
@@ -270,6 +271,21 @@ let OrgsService = class OrgsService {
|
|
|
270
271
|
.set({ deleted_at: sql `now()` })
|
|
271
272
|
.where("id", "=", orgId)
|
|
272
273
|
.execute();
|
|
274
|
+
await this.db
|
|
275
|
+
.insertInto("extension_effect_cancellations")
|
|
276
|
+
.columns(["id", "plugin", "reason"])
|
|
277
|
+
.expression((eb) => eb
|
|
278
|
+
.selectFrom("outbox")
|
|
279
|
+
.select([
|
|
280
|
+
"job_id as id",
|
|
281
|
+
sql `data->>'plugin'`.as("plugin"),
|
|
282
|
+
sql `'organization_deleted'`.as("reason"),
|
|
283
|
+
])
|
|
284
|
+
.where("org_id", "=", orgId)
|
|
285
|
+
.where("job_name", "=", EXTENSION_QUEUE_EFFECT_JOB)
|
|
286
|
+
.where("dead_at", "is", null))
|
|
287
|
+
.onConflict((conflict) => conflict.doNothing())
|
|
288
|
+
.execute();
|
|
273
289
|
// the org's owed jobs go with it; dead letters stay for the overview, and the deletion's own
|
|
274
290
|
// cleanup work carries no org_id (transactional outbox spec §9). Usage reports stay owed: the
|
|
275
291
|
// usage happened, and billing plugins are still told about a deleted org's usage
|
|
@@ -940,6 +940,9 @@ let OrgSettingsService = class OrgSettingsService {
|
|
|
940
940
|
return after.outsideSandbox === "off";
|
|
941
941
|
return hostsNarrowed(scope, row, orgHosts, (host) => hostGrantable(grantCeiling, host));
|
|
942
942
|
}, resetConsent);
|
|
943
|
+
// running outside the sandbox switched off closes the host gate on the org's devices
|
|
944
|
+
if (effOutside(before) === "allowed" && effOutside(reread) === "off")
|
|
945
|
+
await this.ceilings.oweHostServiceStopsLocked({ orgId }, "org");
|
|
943
946
|
}
|
|
944
947
|
return after;
|
|
945
948
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"keys": [
|
|
3
|
+
{
|
|
4
|
+
"keyId": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
|
|
5
|
+
"keyUsage": "npm:attestations",
|
|
6
|
+
"publicKey": {
|
|
7
|
+
"rawBytes": "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE1Olb3zMAFFxXKHiIkQO5cJ3Yhl5i6UPp+IhuteBJbuHcA5UogKo0EWtlWwW6KSaKoTNEYL7JlCQiVnkhBktUgg==",
|
|
8
|
+
"keyDetails": "PKIX_ECDSA_P256_SHA_256",
|
|
9
|
+
"validFor": {
|
|
10
|
+
"start": "2022-12-01T00:00:00.000Z",
|
|
11
|
+
"end": "2025-01-29T00:00:00.000Z"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"keyId": "SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U",
|
|
17
|
+
"keyUsage": "npm:attestations",
|
|
18
|
+
"publicKey": {
|
|
19
|
+
"rawBytes": "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEY6Ya7W++7aUPzvMTrezH6Ycx3c+HOKYCcNGybJZSCJq/fd7Qa8uuAKtdIkUQtQiEKERhAmE5lMMJhP8OkDOa2g==",
|
|
20
|
+
"keyDetails": "PKIX_ECDSA_P256_SHA_256",
|
|
21
|
+
"validFor": {
|
|
22
|
+
"start": "2025-01-13T00:00:00.000Z"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { NpmFetchConfig } from "./npm.js";
|
|
2
|
+
import { type Provenance } from "./provenance.js";
|
|
3
|
+
declare const POLICY_VERSION = 1;
|
|
4
|
+
export interface OfficialNpmRevision {
|
|
5
|
+
name: string;
|
|
6
|
+
version: string;
|
|
7
|
+
/** SHA-512 already checked against the fetched artifact bytes. */
|
|
8
|
+
integrity: string;
|
|
9
|
+
}
|
|
10
|
+
export interface OfficialPublisherProof extends Provenance {
|
|
11
|
+
revision: OfficialNpmRevision;
|
|
12
|
+
evidenceDigest: string;
|
|
13
|
+
policyVersion: typeof POLICY_VERSION;
|
|
14
|
+
}
|
|
15
|
+
/** Checks both signatures, transparency evidence and publisher identity with the bundled roots. */
|
|
16
|
+
export declare function verifyOfficialPublisher(body: unknown, revision: OfficialNpmRevision): OfficialPublisherProof;
|
|
17
|
+
/** Uses the same bounded registry client as the review's display-only provenance. */
|
|
18
|
+
export declare function fetchOfficialPublisher(cfg: NpmFetchConfig, revision: OfficialNpmRevision, signal?: AbortSignal): Promise<OfficialPublisherProof>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { bundleFromJSON } from "@sigstore/bundle";
|
|
3
|
+
import { PublicKey, TrustedRoot } from "@sigstore/protobuf-specs";
|
|
4
|
+
import { toSignedEntity, toTrustMaterial, Verifier } from "@sigstore/verify";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { canonicalJson } from "../tools/canonical-json.js";
|
|
7
|
+
import npmPublishKeys from "./npm-publish-keys.json" with { type: "json" };
|
|
8
|
+
import { fetchNpmAttestations, PROVENANCE_TIMEOUT_MS, SLSA_PROVENANCE_V1, sha512Hex, } from "./provenance.js";
|
|
9
|
+
import trustedRoot from "./sigstore-trusted-root.json" with { type: "json" };
|
|
10
|
+
const NPM_PUBLISH = "https://github.com/npm/attestation/tree/main/specs/publish/v0.1";
|
|
11
|
+
const REGISTRY = "https://registry.npmjs.org";
|
|
12
|
+
const REPOSITORY = "https://github.com/capybara-hq/plugins";
|
|
13
|
+
const REPOSITORY_ID = "1436732755";
|
|
14
|
+
const OWNER_ID = "343699164";
|
|
15
|
+
const WORKFLOW = ".github/workflows/release.yml";
|
|
16
|
+
const MAIN_REF = "refs/heads/main";
|
|
17
|
+
const WORKFLOW_IDENTITY = [REPOSITORY, "/", WORKFLOW, "@", MAIN_REF].join("");
|
|
18
|
+
const GITHUB_ISSUER = "https://token.actions.githubusercontent.com";
|
|
19
|
+
const BUILD_TYPE = "https://slsa-framework.github.io/github-actions-buildtypes/workflow/v1";
|
|
20
|
+
const POLICY_VERSION = 1;
|
|
21
|
+
// These two files are Sigstore production TUF targets: trusted_root.json and
|
|
22
|
+
// registry.npmjs.org/keys.json (publish keys only). Refresh them from the authenticated
|
|
23
|
+
// TUF repository during review. Verification receives no trust material from the registry.
|
|
24
|
+
const verifier = new Verifier(toTrustMaterial(TrustedRoot.fromJSON(trustedRoot), Object.fromEntries(npmPublishKeys.keys.map((key) => [key.keyId, PublicKey.fromJSON(key.publicKey)]))));
|
|
25
|
+
const attestationsSchema = z.object({
|
|
26
|
+
attestations: z.array(z.object({ predicateType: z.string(), bundle: z.unknown() })).max(16),
|
|
27
|
+
});
|
|
28
|
+
const statementSchema = z.object({
|
|
29
|
+
_type: z.enum(["https://in-toto.io/Statement/v1", "https://in-toto.io/Statement/v0.1"]),
|
|
30
|
+
predicateType: z.string(),
|
|
31
|
+
subject: z
|
|
32
|
+
.array(z.object({ name: z.string(), digest: z.object({ sha512: z.string() }) }))
|
|
33
|
+
.length(1),
|
|
34
|
+
predicate: z.unknown(),
|
|
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
|
+
const publishSchema = z.object({
|
|
58
|
+
name: z.string(),
|
|
59
|
+
version: z.string(),
|
|
60
|
+
registry: z.literal(REGISTRY),
|
|
61
|
+
});
|
|
62
|
+
function checkEnvelope(raw, type, revision) {
|
|
63
|
+
const bundle = bundleFromJSON(raw);
|
|
64
|
+
if (bundle.content.$case !== "dsseEnvelope" ||
|
|
65
|
+
bundle.content.dsseEnvelope.payloadType !== "application/vnd.in-toto+json") {
|
|
66
|
+
throw new Error("Expected an in-toto DSSE bundle");
|
|
67
|
+
}
|
|
68
|
+
const entity = toSignedEntity(bundle);
|
|
69
|
+
if (!entity.tlogEntries.some((entry) => entry.inclusionProof !== undefined)) {
|
|
70
|
+
throw new Error("The attestation has no transparency log inclusion proof");
|
|
71
|
+
}
|
|
72
|
+
const statement = statementSchema.parse(JSON.parse(bundle.content.dsseEnvelope.payload.toString("utf8")));
|
|
73
|
+
const [subject] = statement.subject;
|
|
74
|
+
const digest = sha512Hex(revision.integrity);
|
|
75
|
+
const packageUrl = ["pkg:npm/", revision.name.replace(/^@/, "%40"), "@", revision.version].join("");
|
|
76
|
+
if (!digest ||
|
|
77
|
+
statement.predicateType !== type ||
|
|
78
|
+
(type === SLSA_PROVENANCE_V1 && statement._type !== "https://in-toto.io/Statement/v1") ||
|
|
79
|
+
subject?.name !== packageUrl ||
|
|
80
|
+
subject.digest.sha512 !== digest) {
|
|
81
|
+
throw new Error("The attestation does not match this package, version and SHA-512");
|
|
82
|
+
}
|
|
83
|
+
return { entity, predicate: statement.predicate };
|
|
84
|
+
}
|
|
85
|
+
function verifyBuildSigner(entity) {
|
|
86
|
+
if (entity.key.$case !== "certificate") {
|
|
87
|
+
throw new Error("The build attestation has no signing certificate");
|
|
88
|
+
}
|
|
89
|
+
const cert = entity.key.certificate;
|
|
90
|
+
const signer = verifier.verify(entity, { extensions: { issuer: GITHUB_ISSUER } });
|
|
91
|
+
// Fulcio extensions sign these GitHub OIDC claims independently of the predicate.
|
|
92
|
+
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");
|
|
95
|
+
}
|
|
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");
|
|
102
|
+
}
|
|
103
|
+
const commit = claim(13);
|
|
104
|
+
if (!commit)
|
|
105
|
+
throw new Error("The signing certificate names no source commit");
|
|
106
|
+
return commit;
|
|
107
|
+
}
|
|
108
|
+
/** Checks both signatures, transparency evidence and publisher identity with the bundled roots. */
|
|
109
|
+
export function verifyOfficialPublisher(body, revision) {
|
|
110
|
+
const { attestations } = attestationsSchema.parse(body);
|
|
111
|
+
const [publish, ...duplicatePublish] = attestations.filter((a) => a.predicateType === NPM_PUBLISH);
|
|
112
|
+
const [build, ...duplicateBuild] = attestations.filter((a) => a.predicateType === SLSA_PROVENANCE_V1);
|
|
113
|
+
if (!publish || !build || duplicatePublish.length || duplicateBuild.length) {
|
|
114
|
+
throw new Error("Expected one registry publish attestation and one workflow attestation");
|
|
115
|
+
}
|
|
116
|
+
const published = checkEnvelope(publish.bundle, NPM_PUBLISH, revision);
|
|
117
|
+
if (published.entity.key.$case !== "public-key") {
|
|
118
|
+
throw new Error("The publish attestation must be signed by an npm registry key");
|
|
119
|
+
}
|
|
120
|
+
const info = publishSchema.parse(published.predicate);
|
|
121
|
+
if (info.name !== revision.name || info.version !== revision.version) {
|
|
122
|
+
throw new Error("The npm registry attested a different package revision");
|
|
123
|
+
}
|
|
124
|
+
verifier.verify(published.entity);
|
|
125
|
+
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) {
|
|
129
|
+
throw new Error("The signing certificate does not match the build's source commit");
|
|
130
|
+
}
|
|
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");
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
checked: true,
|
|
136
|
+
revision,
|
|
137
|
+
repository: REPOSITORY,
|
|
138
|
+
commit,
|
|
139
|
+
workflow: WORKFLOW,
|
|
140
|
+
buildType: BUILD_TYPE,
|
|
141
|
+
evidenceDigest: createHash("sha256")
|
|
142
|
+
.update(canonicalJson([publish.bundle, build.bundle]))
|
|
143
|
+
.digest("hex"),
|
|
144
|
+
policyVersion: POLICY_VERSION,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/** Uses the same bounded registry client as the review's display-only provenance. */
|
|
148
|
+
export async function fetchOfficialPublisher(cfg, revision, signal) {
|
|
149
|
+
const timeout = AbortSignal.timeout(PROVENANCE_TIMEOUT_MS);
|
|
150
|
+
const attestations = await fetchNpmAttestations(cfg, revision.name, revision.version, signal ? AbortSignal.any([signal, timeout]) : timeout);
|
|
151
|
+
return verifyOfficialPublisher(attestations, revision);
|
|
152
|
+
}
|
|
@@ -21,17 +21,22 @@ export interface Provenance {
|
|
|
21
21
|
workflow: string;
|
|
22
22
|
/** The SLSA build type (which CI system's build definition). */
|
|
23
23
|
buildType: string;
|
|
24
|
+
/** Present only when the official publisher attestations were verified. */
|
|
25
|
+
evidenceDigest?: string;
|
|
24
26
|
}
|
|
25
27
|
/** Provenance was not checked (no attestation, offline, or an answer that could not be read). */
|
|
26
28
|
export interface ProvenanceNotChecked {
|
|
27
29
|
checked: false;
|
|
28
30
|
reason: string;
|
|
31
|
+
reasonCode?: "official_pin_only";
|
|
29
32
|
}
|
|
30
33
|
export type ProvenanceResult = Provenance | ProvenanceNotChecked;
|
|
31
34
|
/** The predicate type of an SLSA v1 provenance statement. */
|
|
32
35
|
export declare const SLSA_PROVENANCE_V1 = "https://slsa.dev/provenance/v1";
|
|
33
36
|
/** Provenance must not hold up an import: a slow registry gives "not checked". */
|
|
34
37
|
export declare const PROVENANCE_TIMEOUT_MS = 15000;
|
|
38
|
+
/** The hex sha512 of a `sha512-<base64>` integrity (undefined for anything else). */
|
|
39
|
+
export declare function sha512Hex(integrity: string): string | undefined;
|
|
35
40
|
/**
|
|
36
41
|
* Reads the SLSA provenance of `name@version` from the configured registry. `integrity` (the
|
|
37
42
|
* tarball's `sha512-…`, when known) must be among the statement's subject digests, so a statement
|
|
@@ -40,6 +45,8 @@ export declare const PROVENANCE_TIMEOUT_MS = 15000;
|
|
|
40
45
|
export declare function fetchProvenance(cfg: NpmFetchConfig, name: string, version: string, signal: AbortSignal, opts?: {
|
|
41
46
|
integrity?: string;
|
|
42
47
|
}): Promise<ProvenanceResult>;
|
|
48
|
+
/** Fetches bounded attestation evidence without accepting it as publisher proof. */
|
|
49
|
+
export declare function fetchNpmAttestations(cfg: NpmFetchConfig, name: string, version: string, signal: AbortSignal): Promise<unknown>;
|
|
43
50
|
/**
|
|
44
51
|
* Parses an attestations answer (`{ attestations: [{ predicateType, bundle: { dsseEnvelope } }] }`).
|
|
45
52
|
* Exported for tests.
|
|
@@ -10,12 +10,14 @@ export const PROVENANCE_TIMEOUT_MS = 15_000;
|
|
|
10
10
|
const NPM_NAME_RE = /^(?:@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/;
|
|
11
11
|
const SEMVER_RE = /^[0-9A-Za-z.+-]{1,256}$/;
|
|
12
12
|
const COMMIT_RE = /^[0-9a-f]{40}(?:[0-9a-f]{24})?$/;
|
|
13
|
+
class NpmAttestationsError extends Error {
|
|
14
|
+
}
|
|
13
15
|
const notChecked = (reason) => ({ checked: false, reason });
|
|
14
16
|
const errMsg = (e) => (e instanceof Error ? e.message : String(e));
|
|
15
17
|
const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
16
18
|
const str = (v) => typeof v === "string" && v.length > 0 && v.length <= 2048 ? v : undefined;
|
|
17
19
|
/** The hex sha512 of a `sha512-<base64>` integrity (undefined for anything else). */
|
|
18
|
-
function sha512Hex(integrity) {
|
|
20
|
+
export function sha512Hex(integrity) {
|
|
19
21
|
for (const part of integrity.trim().split(/\s+/)) {
|
|
20
22
|
const m = /^sha512-([A-Za-z0-9+/]+={0,2})$/.exec(part);
|
|
21
23
|
if (m) {
|
|
@@ -32,13 +34,20 @@ function sha512Hex(integrity) {
|
|
|
32
34
|
* about another tarball is not shown. Never throws (an aborted `signal` included).
|
|
33
35
|
*/
|
|
34
36
|
export async function fetchProvenance(cfg, name, version, signal, opts = {}) {
|
|
37
|
+
try {
|
|
38
|
+
return parseAttestations(await fetchNpmAttestations(cfg, name, version, signal), opts.integrity);
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
return notChecked(e instanceof NpmAttestationsError ? e.message : `cannot read the attestations: ${errMsg(e)}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** Fetches bounded attestation evidence without accepting it as publisher proof. */
|
|
45
|
+
export async function fetchNpmAttestations(cfg, name, version, signal) {
|
|
35
46
|
if (!NPM_NAME_RE.test(name) || name.length > 214 || !SEMVER_RE.test(version)) {
|
|
36
|
-
|
|
47
|
+
throw new NpmAttestationsError("not a valid npm package name and version");
|
|
37
48
|
}
|
|
38
|
-
let body;
|
|
39
49
|
try {
|
|
40
50
|
const registry = new URL(cfg.registry.endsWith("/") ? cfg.registry : `${cfg.registry}/`);
|
|
41
|
-
// the npm client's escaping: a scoped name's `/` is %2f
|
|
42
51
|
const url = new URL(`-/npm/v1/attestations/${name.replace("/", "%2f")}@${encodeURIComponent(version)}`, registry);
|
|
43
52
|
const res = await safeFetch(url.toString(), {
|
|
44
53
|
headers: {
|
|
@@ -47,30 +56,24 @@ export async function fetchProvenance(cfg, name, version, signal, opts = {}) {
|
|
|
47
56
|
},
|
|
48
57
|
signal,
|
|
49
58
|
}, cfg.net, cfg.lookup !== undefined ? { lookup: cfg.lookup } : {});
|
|
50
|
-
if (res.status === 404) {
|
|
51
|
-
await res.body?.cancel().catch(() => { });
|
|
52
|
-
return notChecked("the registry has no provenance for this version");
|
|
53
|
-
}
|
|
54
59
|
if (!res.ok) {
|
|
55
60
|
await res.body?.cancel().catch(() => { });
|
|
56
|
-
|
|
61
|
+
throw new NpmAttestationsError(res.status === 404
|
|
62
|
+
? "the registry has no provenance for this version"
|
|
63
|
+
: `the registry answered HTTP ${res.status} for the attestations`);
|
|
57
64
|
}
|
|
58
65
|
const raw = await readCapped(res, MAX_ATTESTATION_BYTES, () => new Error("the attestations are too large"));
|
|
59
|
-
|
|
66
|
+
return JSON.parse(raw.toString("utf8"));
|
|
60
67
|
}
|
|
61
68
|
catch (e) {
|
|
62
69
|
if (signal.aborted)
|
|
63
|
-
|
|
70
|
+
throw new NpmAttestationsError("the registry did not answer in time", { cause: e });
|
|
64
71
|
if (e instanceof NetDeniedError) {
|
|
65
|
-
|
|
72
|
+
throw new NpmAttestationsError(`the network rules refused the attestations: ${e.message}`, {
|
|
73
|
+
cause: e,
|
|
74
|
+
});
|
|
66
75
|
}
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
try {
|
|
70
|
-
return parseAttestations(body, opts.integrity);
|
|
71
|
-
}
|
|
72
|
-
catch (e) {
|
|
73
|
-
return notChecked(`cannot read the attestations: ${errMsg(e)}`);
|
|
76
|
+
throw e;
|
|
74
77
|
}
|
|
75
78
|
}
|
|
76
79
|
/**
|