@powerhousedao/switchboard 6.2.3-dev.9 → 6.2.3-dev.91
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/.tsbuild/test/ai-gateway.test.d.ts +2 -0
- package/.tsbuild/test/ai-gateway.test.d.ts.map +1 -0
- package/.tsbuild/test/attachments/byte-grants.test.d.ts +2 -0
- package/.tsbuild/test/attachments/byte-grants.test.d.ts.map +1 -0
- package/.tsbuild/test/attachments/byte-routes-read-gate.integration.test.d.ts +2 -0
- package/.tsbuild/test/attachments/byte-routes-read-gate.integration.test.d.ts.map +1 -0
- package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts +2 -0
- package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts.map +1 -0
- package/.tsbuild/test/attachments/url-signer.test.d.ts +2 -0
- package/.tsbuild/test/attachments/url-signer.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-auth-config.test.d.ts +2 -0
- package/.tsbuild/test/boot-auth-config.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-create-signature-policy.test.d.ts +2 -0
- package/.tsbuild/test/boot-create-signature-policy.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-desktop-auth.test.d.ts +2 -0
- package/.tsbuild/test/boot-desktop-auth.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-env-isolation.test.d.ts +2 -0
- package/.tsbuild/test/boot-env-isolation.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-helpers.d.ts +5 -0
- package/.tsbuild/test/boot-helpers.d.ts.map +1 -0
- package/.tsbuild/test/boot-inspection-enabled.test.d.ts +2 -0
- package/.tsbuild/test/boot-inspection-enabled.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-mcp-auth.test.d.ts +2 -0
- package/.tsbuild/test/boot-mcp-auth.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-mcp-enabled.test.d.ts +2 -0
- package/.tsbuild/test/boot-mcp-enabled.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-port-zero.test.d.ts +2 -0
- package/.tsbuild/test/boot-port-zero.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-preconditions.test.d.ts +2 -0
- package/.tsbuild/test/boot-preconditions.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-privacy.test.d.ts +2 -0
- package/.tsbuild/test/boot-privacy.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-ready-drives.test.d.ts +2 -0
- package/.tsbuild/test/boot-ready-drives.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-undo-v3-flag.test.d.ts +2 -0
- package/.tsbuild/test/boot-undo-v3-flag.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-unsupported-stored-documents.test.d.ts +2 -0
- package/.tsbuild/test/boot-unsupported-stored-documents.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-without-renown.test.d.ts +2 -0
- package/.tsbuild/test/boot-without-renown.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-without-require-signatures.test.d.ts +2 -0
- package/.tsbuild/test/boot-without-require-signatures.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-worker-trust-policy.test.d.ts +2 -0
- package/.tsbuild/test/boot-worker-trust-policy.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts +2 -0
- package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts +2 -0
- package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts.map +1 -0
- package/.tsbuild/test/builder-defaults.test.d.ts +2 -0
- package/.tsbuild/test/builder-defaults.test.d.ts.map +1 -0
- package/.tsbuild/test/config-from-env.test.d.ts +2 -0
- package/.tsbuild/test/config-from-env.test.d.ts.map +1 -0
- package/.tsbuild/test/config-merge.test.d.ts +2 -0
- package/.tsbuild/test/config-merge.test.d.ts.map +1 -0
- package/.tsbuild/test/config-schema.test.d.ts +2 -0
- package/.tsbuild/test/config-schema.test.d.ts.map +1 -0
- package/.tsbuild/test/create-signature-policy.test.d.ts +2 -0
- package/.tsbuild/test/create-signature-policy.test.d.ts.map +1 -0
- package/.tsbuild/test/default-drive-protocol-versions.test.d.ts +2 -0
- package/.tsbuild/test/default-drive-protocol-versions.test.d.ts.map +1 -0
- package/.tsbuild/test/default-drive-slug.test.d.ts +2 -0
- package/.tsbuild/test/default-drive-slug.test.d.ts.map +1 -0
- package/.tsbuild/test/delegated-publish.test.d.ts +2 -0
- package/.tsbuild/test/delegated-publish.test.d.ts.map +1 -0
- package/.tsbuild/test/durable-node-fs-pg16.test.d.ts +2 -0
- package/.tsbuild/test/durable-node-fs-pg16.test.d.ts.map +1 -0
- package/.tsbuild/test/fatal-shutdown.test.d.ts +2 -0
- package/.tsbuild/test/fatal-shutdown.test.d.ts.map +1 -0
- package/.tsbuild/test/inspection-throttle.test.d.ts +2 -0
- package/.tsbuild/test/inspection-throttle.test.d.ts.map +1 -0
- package/.tsbuild/test/keyframe-reclaim-store.test.d.ts +2 -0
- package/.tsbuild/test/keyframe-reclaim-store.test.d.ts.map +1 -0
- package/.tsbuild/test/observability-signals.test.d.ts +2 -0
- package/.tsbuild/test/observability-signals.test.d.ts.map +1 -0
- package/.tsbuild/test/permissions-backfill.test.d.ts +2 -0
- package/.tsbuild/test/permissions-backfill.test.d.ts.map +1 -0
- package/.tsbuild/test/pglite-preflight.test.d.ts +2 -0
- package/.tsbuild/test/pglite-preflight.test.d.ts.map +1 -0
- package/.tsbuild/test/pglite-storage-dirs.test.d.ts +2 -0
- package/.tsbuild/test/pglite-storage-dirs.test.d.ts.map +1 -0
- package/.tsbuild/test/pglite-store.test.d.ts +2 -0
- package/.tsbuild/test/pglite-store.test.d.ts.map +1 -0
- package/.tsbuild/test/plugin-config-schemas.test.d.ts +2 -0
- package/.tsbuild/test/plugin-config-schemas.test.d.ts.map +1 -0
- package/.tsbuild/test/plugin-presence.test.d.ts +2 -0
- package/.tsbuild/test/plugin-presence.test.d.ts.map +1 -0
- package/.tsbuild/test/port-probe.test.d.ts +2 -0
- package/.tsbuild/test/port-probe.test.d.ts.map +1 -0
- package/.tsbuild/test/processor-timing-log.test.d.ts +2 -0
- package/.tsbuild/test/processor-timing-log.test.d.ts.map +1 -0
- package/.tsbuild/test/renown-storage-path.test.d.ts +2 -0
- package/.tsbuild/test/renown-storage-path.test.d.ts.map +1 -0
- package/.tsbuild/test/renown-trust-policy.test.d.ts +2 -0
- package/.tsbuild/test/renown-trust-policy.test.d.ts.map +1 -0
- package/.tsbuild/test/served-schemas.test.d.ts +2 -0
- package/.tsbuild/test/served-schemas.test.d.ts.map +1 -0
- package/.tsbuild/test/shutdown.test.d.ts +2 -0
- package/.tsbuild/test/shutdown.test.d.ts.map +1 -0
- package/.tsbuild/test/snapshot-writer.d.ts +18 -0
- package/.tsbuild/test/snapshot-writer.d.ts.map +1 -0
- package/.tsbuild/test/store-lock.test.d.ts +2 -0
- package/.tsbuild/test/store-lock.test.d.ts.map +1 -0
- package/.tsbuild/test/two-switchboards.test.d.ts +2 -0
- package/.tsbuild/test/two-switchboards.test.d.ts.map +1 -0
- package/.tsbuild/test/unsupported-stored-documents.test.d.ts +2 -0
- package/.tsbuild/test/unsupported-stored-documents.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/harness.d.ts +56 -0
- package/.tsbuild/test/workflow/harness.d.ts.map +1 -0
- package/.tsbuild/test/workflow/oauth-apps-config.test.d.ts +2 -0
- package/.tsbuild/test/workflow/oauth-apps-config.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/oauth.test.d.ts +2 -0
- package/.tsbuild/test/workflow/oauth.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/resolvers.test.d.ts +2 -0
- package/.tsbuild/test/workflow/resolvers.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/runtime-host.test.d.ts +2 -0
- package/.tsbuild/test/workflow/runtime-host.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/waitpoint-routes.test.d.ts +2 -0
- package/.tsbuild/test/workflow/waitpoint-routes.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/waitpoint-runtime.test.d.ts +2 -0
- package/.tsbuild/test/workflow/waitpoint-runtime.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/webhook-dedupe.test.d.ts +2 -0
- package/.tsbuild/test/workflow/webhook-dedupe.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/webhook-signed.test.d.ts +2 -0
- package/.tsbuild/test/workflow/webhook-signed.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/webhook-trigger-test.test.d.ts +2 -0
- package/.tsbuild/test/workflow/webhook-trigger-test.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/webhook-unsigned.test.d.ts +2 -0
- package/.tsbuild/test/workflow/webhook-unsigned.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow-reactor-access.test.d.ts +2 -0
- package/.tsbuild/test/workflow-reactor-access.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts +2 -0
- package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow-read-gate.test.d.ts +2 -0
- package/.tsbuild/test/workflow-read-gate.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow-runtime.test.d.ts +2 -0
- package/.tsbuild/test/workflow-runtime.test.d.ts.map +1 -0
- package/.tsbuild/test/workflows-plugin-config.test.d.ts +2 -0
- package/.tsbuild/test/workflows-plugin-config.test.d.ts.map +1 -0
- package/.tsbuild/tsconfig.tsbuildinfo +1 -1
- package/.tsbuild/tsdown.config.d.ts.map +1 -1
- package/.tsbuild/vitest.config.d.ts.map +1 -1
- package/Auth.md +144 -2
- package/CHANGELOG.md +1226 -0
- package/README.md +101 -22
- package/dist/boot.d.mts +46 -0
- package/dist/boot.d.mts.map +1 -0
- package/dist/boot.mjs +67 -0
- package/dist/boot.mjs.map +1 -0
- package/dist/config/from-env.d.mts +15 -0
- package/dist/config/from-env.d.mts.map +1 -0
- package/dist/config/from-env.mjs +4 -0
- package/dist/config/schema.d.mts +3 -0
- package/dist/config/schema.mjs +4 -0
- package/dist/from-env-C6dHDvAu.mjs +474 -0
- package/dist/from-env-C6dHDvAu.mjs.map +1 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +84 -84
- package/dist/index.mjs.map +1 -1
- package/dist/install-packages.d.mts +2 -1
- package/dist/install-packages.mjs +2 -2
- package/dist/install-packages.mjs.map +1 -1
- package/dist/mcp-SsBK14Jm.mjs +32 -0
- package/dist/mcp-SsBK14Jm.mjs.map +1 -0
- package/dist/migrate.d.mts +2 -1
- package/dist/migrate.mjs +7 -5
- package/dist/migrate.mjs.map +1 -1
- package/dist/plugin-host-H2uebOKI.d.mts +46 -0
- package/dist/plugin-host-H2uebOKI.d.mts.map +1 -0
- package/dist/plugins/ai.d.mts +37 -0
- package/dist/plugins/ai.d.mts.map +1 -0
- package/dist/plugins/ai.mjs +400 -0
- package/dist/plugins/ai.mjs.map +1 -0
- package/dist/plugins/attachments.d.mts +33 -0
- package/dist/plugins/attachments.d.mts.map +1 -0
- package/dist/plugins/attachments.mjs +4 -0
- package/dist/plugins/mcp.d.mts +31 -0
- package/dist/plugins/mcp.d.mts.map +1 -0
- package/dist/plugins/mcp.mjs +4 -0
- package/dist/plugins/privacy.d.mts +22 -0
- package/dist/plugins/privacy.d.mts.map +1 -0
- package/dist/plugins/privacy.mjs +4 -0
- package/dist/plugins/workflows.d.mts +79 -0
- package/dist/plugins/workflows.d.mts.map +1 -0
- package/dist/plugins/workflows.mjs +4 -0
- package/dist/postgres-url-DTDhBjXX.mjs +11 -0
- package/dist/postgres-url-DTDhBjXX.mjs.map +1 -0
- package/dist/privacy-BO8Q25xI.mjs +44 -0
- package/dist/privacy-BO8Q25xI.mjs.map +1 -0
- package/dist/privacy-DxIJGH4P.mjs +91 -0
- package/dist/privacy-DxIJGH4P.mjs.map +1 -0
- package/dist/renown-layers-DmbWLt46.mjs +42 -0
- package/dist/renown-layers-DmbWLt46.mjs.map +1 -0
- package/dist/schema-B11_2pKM.mjs +328 -0
- package/dist/schema-B11_2pKM.mjs.map +1 -0
- package/dist/schema-BRNH0PaA.d.mts +247 -0
- package/dist/schema-BRNH0PaA.d.mts.map +1 -0
- package/dist/server-DyLVCH38.mjs +2730 -0
- package/dist/server-DyLVCH38.mjs.map +1 -0
- package/dist/server.d.mts +129 -189
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +5 -5
- package/dist/types-DzO3_320.d.mts +308 -0
- package/dist/types-DzO3_320.d.mts.map +1 -0
- package/dist/utils-Cm0TE6dP.mjs +148 -0
- package/dist/utils-Cm0TE6dP.mjs.map +1 -0
- package/dist/utils.d.mts +30 -5
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +5 -4
- package/dist/worker-pool-gyxJnCxA.mjs +304 -0
- package/dist/worker-pool-gyxJnCxA.mjs.map +1 -0
- package/dist/workflow-runtime-CF5pc8mt.d.mts +33 -0
- package/dist/workflow-runtime-CF5pc8mt.d.mts.map +1 -0
- package/dist/workflows-C9BQlyT0.mjs +1943 -0
- package/dist/workflows-C9BQlyT0.mjs.map +1 -0
- package/package.json +85 -24
- package/scripts/install-packages.sh +0 -0
- package/test/ai-gateway.test.ts +612 -0
- package/test/attachment-reference-read-model.test.ts +28 -20
- package/test/attachments/auth.test.ts +85 -0
- package/test/attachments/byte-grants.test.ts +290 -0
- package/test/attachments/byte-routes-read-gate.integration.test.ts +314 -0
- package/test/attachments/download-target.test.ts +211 -32
- package/test/attachments/index.test.ts +47 -4
- package/test/attachments/reserve-metadata-parity.test.ts +96 -0
- package/test/attachments/routes-integration.test.ts +60 -4
- package/test/attachments/routes.test.ts +297 -35
- package/test/attachments/service-config.test.ts +41 -19
- package/test/attachments/url-signer.test.ts +105 -0
- package/test/boot-auth-config.test.ts +109 -0
- package/test/boot-create-signature-policy.test.ts +110 -0
- package/test/boot-desktop-auth.test.ts +278 -0
- package/test/boot-env-isolation.test.ts +26 -0
- package/test/boot-helpers.ts +19 -0
- package/test/boot-inspection-enabled.test.ts +140 -0
- package/test/boot-mcp-auth.test.ts +449 -0
- package/test/boot-mcp-enabled.test.ts +119 -0
- package/test/boot-port-zero.test.ts +101 -0
- package/test/boot-preconditions.test.ts +213 -0
- package/test/boot-privacy.test.ts +232 -0
- package/test/boot-ready-drives.test.ts +141 -0
- package/test/boot-undo-v3-flag.test.ts +120 -0
- package/test/boot-unsupported-stored-documents.test.ts +214 -0
- package/test/boot-without-renown.test.ts +83 -0
- package/test/boot-without-require-signatures.test.ts +76 -0
- package/test/boot-worker-trust-policy.test.ts +91 -0
- package/test/boot-workflow-singleton-conflict.test.ts +109 -0
- package/test/boot-workflow-singleton-retry.test.ts +122 -0
- package/test/builder-defaults.test.ts +80 -0
- package/test/config-from-env.test.ts +963 -0
- package/test/config-merge.test.ts +226 -0
- package/test/config-schema.test.ts +167 -0
- package/test/create-signature-policy.test.ts +69 -0
- package/test/default-drive-protocol-versions.test.ts +79 -0
- package/test/default-drive-slug.test.ts +265 -0
- package/test/delegated-publish.test.ts +435 -0
- package/test/durable-node-fs-pg16.test.ts +80 -0
- package/test/fatal-shutdown.test.ts +205 -0
- package/test/goldens/packages.graphql +797 -0
- package/test/goldens/privacy.graphql +853 -0
- package/test/goldens/reactor-drive-nodes.graphql +827 -0
- package/test/goldens/resolvers.json +327 -0
- package/test/goldens/supergraph.graphql +5918 -0
- package/test/goldens/workflow-runtime.graphql +1548 -0
- package/test/inspection-throttle.test.ts +23 -0
- package/test/keyframe-reclaim-store.test.ts +156 -0
- package/test/observability-signals.test.ts +131 -0
- package/test/permissions-backfill.test.ts +486 -0
- package/test/pglite-dialect.test.ts +237 -2
- package/test/pglite-preflight.test.ts +313 -0
- package/test/pglite-storage-dirs.test.ts +113 -0
- package/test/pglite-store.test.ts +441 -0
- package/test/pglite-version.test.ts +9 -1
- package/test/plugin-config-schemas.test.ts +83 -0
- package/test/plugin-presence.test.ts +262 -0
- package/test/port-probe.test.ts +45 -0
- package/test/processor-timing-log.test.ts +109 -0
- package/test/reactor-feature-flags.test.ts +20 -0
- package/test/redact-webhook-path.test.ts +9 -0
- package/test/renown-storage-path.test.ts +40 -0
- package/test/renown-trust-policy.test.ts +313 -0
- package/test/served-schemas.test.ts +134 -0
- package/test/shutdown.test.ts +278 -0
- package/test/snapshot-writer.ts +94 -0
- package/test/store-lock.test.ts +65 -0
- package/test/two-switchboards.test.ts +146 -0
- package/test/unsupported-stored-documents.test.ts +72 -0
- package/test/worker-pool.test.ts +27 -1
- package/test/workflow/harness.ts +289 -0
- package/test/workflow/oauth-apps-config.test.ts +66 -0
- package/test/workflow/oauth.test.ts +286 -0
- package/test/workflow/resolvers.test.ts +488 -0
- package/test/workflow/runtime-host.test.ts +19 -0
- package/test/workflow/waitpoint-routes.test.ts +306 -0
- package/test/workflow/waitpoint-runtime.test.ts +204 -0
- package/test/workflow/webhook-dedupe.test.ts +295 -0
- package/test/workflow/webhook-signed.test.ts +509 -0
- package/test/workflow/webhook-trigger-test.test.ts +82 -0
- package/test/workflow/webhook-unsigned.test.ts +345 -0
- package/test/workflow-reactor-access.test.ts +384 -0
- package/test/workflow-reactor-enforcement.test.ts +808 -0
- package/test/workflow-read-gate.test.ts +213 -0
- package/test/workflow-runtime.test.ts +1254 -0
- package/test/workflows-plugin-config.test.ts +77 -0
- package/tsconfig.json +11 -2
- package/tsdown.config.ts +13 -1
- package/vitest.config.ts +65 -0
- package/dist/server-CiKkVE6g.mjs +0 -1555
- package/dist/server-CiKkVE6g.mjs.map +0 -1
- package/dist/utils-Baw7rThP.mjs +0 -80
- package/dist/utils-Baw7rThP.mjs.map +0 -1
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
// A switchboard shaped like the desktop host's: sign-in enforced, the first
|
|
2
|
+
// person the owner, bound to loopback, and working with Renown unreachable once
|
|
3
|
+
// that person has signed in (ADR 0008 §11).
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
6
|
+
import { createServer, type Server } from "node:http";
|
|
7
|
+
import { createRequire } from "node:module";
|
|
8
|
+
import { networkInterfaces, tmpdir } from "node:os";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import type { GraphQLManager } from "@powerhousedao/reactor-api";
|
|
11
|
+
import {
|
|
12
|
+
buildAndSignCredential,
|
|
13
|
+
MemoryKeyStorage,
|
|
14
|
+
RenownCryptoBuilder,
|
|
15
|
+
type IRenownCrypto,
|
|
16
|
+
type PowerhouseVerifiableCredential,
|
|
17
|
+
type SignCredentialTypedData,
|
|
18
|
+
} from "@renown/sdk/node";
|
|
19
|
+
import type { ILogger } from "document-model";
|
|
20
|
+
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
|
21
|
+
import type { SwitchboardConfigInput } from "../src/config/schema.js";
|
|
22
|
+
import type { startSwitchboard } from "../src/server.mjs";
|
|
23
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
24
|
+
|
|
25
|
+
// viem is the SDK's own dependency; the switchboard does not declare it.
|
|
26
|
+
type Account = {
|
|
27
|
+
address: `0x${string}`;
|
|
28
|
+
signTypedData(args: unknown): Promise<`0x${string}`>;
|
|
29
|
+
};
|
|
30
|
+
const { privateKeyToAccount } = createRequire(
|
|
31
|
+
import.meta.resolve("@renown/sdk/node"),
|
|
32
|
+
)("viem/accounts") as {
|
|
33
|
+
privateKeyToAccount: (key: `0x${string}`) => Account;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// Well-known Anvil dev keys; never used for anything real.
|
|
37
|
+
const PERSON = privateKeyToAccount(
|
|
38
|
+
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
|
|
39
|
+
);
|
|
40
|
+
const VISITOR = privateKeyToAccount(
|
|
41
|
+
"0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d",
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const ENV_KEYS = [
|
|
45
|
+
"PH_REACTOR_DATABASE_URL",
|
|
46
|
+
"AUTH_ENABLED",
|
|
47
|
+
"ADMINS",
|
|
48
|
+
"RESOLVE_CALLER_IDENTITY",
|
|
49
|
+
"REQUIRE_AUTHENTICATED_CALLER",
|
|
50
|
+
"RENOWN_URL",
|
|
51
|
+
"SWITCHBOARD_URL",
|
|
52
|
+
] as const;
|
|
53
|
+
|
|
54
|
+
const logger = {
|
|
55
|
+
verbose: vi.fn(),
|
|
56
|
+
debug: vi.fn(),
|
|
57
|
+
info: vi.fn(),
|
|
58
|
+
warn: vi.fn(),
|
|
59
|
+
error: vi.fn(),
|
|
60
|
+
child: () => logger,
|
|
61
|
+
} as unknown as ILogger;
|
|
62
|
+
|
|
63
|
+
type Switchboard = Awaited<ReturnType<typeof startSwitchboard>>;
|
|
64
|
+
|
|
65
|
+
const newKey = (): Promise<IRenownCrypto> =>
|
|
66
|
+
new RenownCryptoBuilder().withKeyPairStorage(new MemoryKeyStorage()).build();
|
|
67
|
+
|
|
68
|
+
const credentialFor = (
|
|
69
|
+
account: Account,
|
|
70
|
+
key: string,
|
|
71
|
+
expiresInDays = 7,
|
|
72
|
+
): Promise<PowerhouseVerifiableCredential> =>
|
|
73
|
+
buildAndSignCredential({
|
|
74
|
+
signTypedData: ((args) =>
|
|
75
|
+
account.signTypedData(args)) as SignCredentialTypedData,
|
|
76
|
+
address: account.address,
|
|
77
|
+
chainId: 1,
|
|
78
|
+
app: "connect",
|
|
79
|
+
appId: key,
|
|
80
|
+
expiresInDays,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
/** Renown's REST lookup and nothing else. */
|
|
84
|
+
function fakeRenown(
|
|
85
|
+
credentials: Map<string, PowerhouseVerifiableCredential>,
|
|
86
|
+
): Promise<{ server: Server; url: string }> {
|
|
87
|
+
const server = createServer((request, response) => {
|
|
88
|
+
const url = new URL(request.url ?? "/", "http://renown.test");
|
|
89
|
+
const credential =
|
|
90
|
+
url.pathname === "/api/auth/credential"
|
|
91
|
+
? credentials.get(url.searchParams.get("appId") ?? "")
|
|
92
|
+
: undefined;
|
|
93
|
+
response.writeHead(credential ? 200 : 404, {
|
|
94
|
+
"content-type": "application/json",
|
|
95
|
+
});
|
|
96
|
+
response.end(JSON.stringify(credential ? { credential } : {}));
|
|
97
|
+
});
|
|
98
|
+
return new Promise((resolve) => {
|
|
99
|
+
server.listen(0, "127.0.0.1", () => {
|
|
100
|
+
const address = server.address();
|
|
101
|
+
const port = typeof address === "object" ? address?.port : undefined;
|
|
102
|
+
resolve({ server, url: `http://127.0.0.1:${String(port)}` });
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const stopped = (server: Server) =>
|
|
108
|
+
new Promise<void>((resolve) => {
|
|
109
|
+
server.close(() => resolve());
|
|
110
|
+
server.closeAllConnections();
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// A booted server under a full suite's load: the default 5s is for a unit test.
|
|
114
|
+
describe(
|
|
115
|
+
"a switchboard on a person's own computer",
|
|
116
|
+
{ timeout: 60_000 },
|
|
117
|
+
() => {
|
|
118
|
+
let root = "";
|
|
119
|
+
let previous: [string, string | undefined][] = [];
|
|
120
|
+
let switchboard: Switchboard | undefined;
|
|
121
|
+
let person: IRenownCrypto;
|
|
122
|
+
let visitor: IRenownCrypto;
|
|
123
|
+
let renown: { server: Server; url: string };
|
|
124
|
+
|
|
125
|
+
const config = (renownUrl: string): SwitchboardConfigInput => ({
|
|
126
|
+
server: { port: 0, host: "127.0.0.1" },
|
|
127
|
+
storage: {
|
|
128
|
+
userDataDir: root,
|
|
129
|
+
readModel: { url: join(root, "read-model") },
|
|
130
|
+
},
|
|
131
|
+
features: { workflows: false, mcp: false },
|
|
132
|
+
packages: { disableLocal: true },
|
|
133
|
+
auth: {
|
|
134
|
+
enabled: true,
|
|
135
|
+
requireAuthenticatedCaller: true,
|
|
136
|
+
resolveIdentity: true,
|
|
137
|
+
ownerClaim: true,
|
|
138
|
+
offlineCredentials: true,
|
|
139
|
+
renown: { source: "remote", url: renownUrl },
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const boot = async (renownUrl: string) => {
|
|
144
|
+
switchboard = await bootSwitchboard(config(renownUrl), { logger });
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const stop = async () => {
|
|
148
|
+
await switchboard?.shutdown();
|
|
149
|
+
switchboard = undefined;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const ask = async (
|
|
153
|
+
key?: IRenownCrypto,
|
|
154
|
+
address?: string,
|
|
155
|
+
): Promise<number> => {
|
|
156
|
+
const bearer = key ? await key.getBearerToken(address) : undefined;
|
|
157
|
+
const response = await fetch(
|
|
158
|
+
`http://127.0.0.1:${String(switchboard!.port)}/graphql`,
|
|
159
|
+
{
|
|
160
|
+
method: "POST",
|
|
161
|
+
headers: {
|
|
162
|
+
"content-type": "application/json",
|
|
163
|
+
...(bearer ? { authorization: `Bearer ${bearer}` } : {}),
|
|
164
|
+
},
|
|
165
|
+
body: JSON.stringify({ query: "{ __typename }" }),
|
|
166
|
+
},
|
|
167
|
+
);
|
|
168
|
+
return response.status;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const isAdmin = (address: string): boolean =>
|
|
172
|
+
(
|
|
173
|
+
switchboard as unknown as { api: { graphqlManager: GraphQLManager } }
|
|
174
|
+
).api.graphqlManager
|
|
175
|
+
.getAuthorizationService()
|
|
176
|
+
.isSupremeAdmin(address);
|
|
177
|
+
|
|
178
|
+
beforeAll(async () => {
|
|
179
|
+
root = await mkdtemp(join(tmpdir(), "switchboard-desktop-auth-"));
|
|
180
|
+
previous = ENV_KEYS.map((key) => [key, process.env[key]]);
|
|
181
|
+
for (const key of ENV_KEYS) delete process.env[key];
|
|
182
|
+
process.env.PH_REACTOR_DATABASE_URL = join(root, "reactor-storage");
|
|
183
|
+
|
|
184
|
+
person = await newKey();
|
|
185
|
+
visitor = await newKey();
|
|
186
|
+
renown = await fakeRenown(
|
|
187
|
+
new Map([
|
|
188
|
+
// Past its date: it is the proof that counts while Renown is away.
|
|
189
|
+
[person.did, await credentialFor(PERSON, person.did, -1)],
|
|
190
|
+
[visitor.did, await credentialFor(VISITOR, visitor.did)],
|
|
191
|
+
]),
|
|
192
|
+
);
|
|
193
|
+
await boot(renown.url);
|
|
194
|
+
}, 120_000);
|
|
195
|
+
|
|
196
|
+
afterAll(async () => {
|
|
197
|
+
await stop();
|
|
198
|
+
await stopped(renown.server);
|
|
199
|
+
for (const [key, value] of previous) {
|
|
200
|
+
if (value === undefined) delete process.env[key];
|
|
201
|
+
else process.env[key] = value;
|
|
202
|
+
}
|
|
203
|
+
await rm(root, { recursive: true, force: true });
|
|
204
|
+
}, 60_000);
|
|
205
|
+
|
|
206
|
+
it("has its own key on first run, apart from the person's", () => {
|
|
207
|
+
expect(existsSync(join(root, ".ph", ".keypair.json"))).toBe(true);
|
|
208
|
+
const hostKey = switchboard!.renown?.did;
|
|
209
|
+
expect(hostKey).toMatch(/^did:key:/);
|
|
210
|
+
expect(hostKey).not.toBe(person.did);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("refuses anyone not signed in", async () => {
|
|
214
|
+
expect(await ask()).toBe(401);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it("makes the first person to sign in its owner, with no env file", async () => {
|
|
218
|
+
expect(isAdmin(PERSON.address)).toBe(false);
|
|
219
|
+
expect(await ask(person, PERSON.address)).toBe(200);
|
|
220
|
+
expect(isAdmin(PERSON.address)).toBe(true);
|
|
221
|
+
const owner = JSON.parse(
|
|
222
|
+
await readFile(join(root, ".ph", ".owner.json"), "utf8"),
|
|
223
|
+
) as { owner: string };
|
|
224
|
+
expect(owner.owner).toBe(PERSON.address.toLowerCase());
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it("gives a second person no ownership", async () => {
|
|
228
|
+
expect(await ask(visitor, VISITOR.address)).toBe(200);
|
|
229
|
+
expect(isAdmin(VISITOR.address)).toBe(false);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("answers on loopback only", async () => {
|
|
233
|
+
const lan = Object.values(networkInterfaces())
|
|
234
|
+
.flat()
|
|
235
|
+
.find((entry) => entry?.family === "IPv4" && !entry.internal);
|
|
236
|
+
if (!lan) return;
|
|
237
|
+
await expect(
|
|
238
|
+
fetch(`http://${lan.address}:${String(switchboard!.port)}/graphql`, {
|
|
239
|
+
signal: AbortSignal.timeout(3_000),
|
|
240
|
+
}),
|
|
241
|
+
).rejects.toThrow();
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it("refuses an owner claim on an address others can reach", async () => {
|
|
245
|
+
const exposed = config(renown.url);
|
|
246
|
+
await expect(
|
|
247
|
+
bootSwitchboard(
|
|
248
|
+
{
|
|
249
|
+
...exposed,
|
|
250
|
+
server: { port: 0, host: "0.0.0.0" },
|
|
251
|
+
storage: {
|
|
252
|
+
userDataDir: join(root, "exposed"),
|
|
253
|
+
readModel: { url: join(root, "exposed", "read-model") },
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
{ logger },
|
|
257
|
+
),
|
|
258
|
+
).rejects.toThrow(/loopback/);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("boots and verifies its owner with Renown unreachable", async () => {
|
|
262
|
+
expect(existsSync(join(root, ".ph", ".credentials.json"))).toBe(true);
|
|
263
|
+
await stop();
|
|
264
|
+
await stopped(renown.server);
|
|
265
|
+
|
|
266
|
+
await boot(renown.url);
|
|
267
|
+
|
|
268
|
+
expect(await ask(person, PERSON.address)).toBe(200);
|
|
269
|
+
expect(isAdmin(PERSON.address)).toBe(true);
|
|
270
|
+
}, 120_000);
|
|
271
|
+
|
|
272
|
+
it("verifies nobody it has not seen while Renown is unreachable", async () => {
|
|
273
|
+
const stranger = await newKey();
|
|
274
|
+
expect(await ask(stranger, VISITOR.address)).toBe(401);
|
|
275
|
+
expect(await ask()).toBe(401);
|
|
276
|
+
});
|
|
277
|
+
},
|
|
278
|
+
);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
5
|
+
import { switchboardBootFactsFromEnv } from "../src/boot.mjs";
|
|
6
|
+
|
|
7
|
+
// Its own file: a .env loaded by an earlier import in this worker would mask a leak.
|
|
8
|
+
describe("switchboardBootFactsFromEnv", () => {
|
|
9
|
+
const cwd = process.cwd();
|
|
10
|
+
let dir: string | undefined;
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
process.chdir(cwd);
|
|
13
|
+
if (dir) rmSync(dir, { recursive: true, force: true });
|
|
14
|
+
delete process.env.PH_BOOT_ENV_SENTINEL;
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("leaves process.env as it found it, with a .env in the cwd", async () => {
|
|
18
|
+
dir = mkdtempSync(path.join(tmpdir(), "sb-boot-env-"));
|
|
19
|
+
writeFileSync(path.join(dir, ".env"), "PH_BOOT_ENV_SENTINEL=leaked\n");
|
|
20
|
+
process.chdir(dir);
|
|
21
|
+
const before = { ...process.env };
|
|
22
|
+
await switchboardBootFactsFromEnv({}, { dev: false });
|
|
23
|
+
expect(process.env.PH_BOOT_ENV_SENTINEL).toBeUndefined();
|
|
24
|
+
expect({ ...process.env }).toEqual(before);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { switchboardConfigFromEnv } from "../src/config/from-env.js";
|
|
2
|
+
import { callerOverEnv } from "../src/config/merge.js";
|
|
3
|
+
import type { SwitchboardConfigInput } from "../src/config/schema.js";
|
|
4
|
+
import { startSwitchboard, type SwitchboardDeps } from "../src/server.mjs";
|
|
5
|
+
|
|
6
|
+
/** Boots the way an edge does: the caller's layer over `env`'s. */
|
|
7
|
+
export function bootSwitchboard(
|
|
8
|
+
config: SwitchboardConfigInput,
|
|
9
|
+
deps: SwitchboardDeps = {},
|
|
10
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
11
|
+
): ReturnType<typeof startSwitchboard> {
|
|
12
|
+
return startSwitchboard(
|
|
13
|
+
callerOverEnv(
|
|
14
|
+
switchboardConfigFromEnv(env, { logger: deps.logger }),
|
|
15
|
+
config,
|
|
16
|
+
),
|
|
17
|
+
deps,
|
|
18
|
+
);
|
|
19
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import type { ILogger } from "document-model";
|
|
5
|
+
import { describe, expect, it, vi } from "vitest";
|
|
6
|
+
import type { startSwitchboard } from "../src/server.mjs";
|
|
7
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
8
|
+
|
|
9
|
+
function stubLogger(): ILogger {
|
|
10
|
+
const logger = {
|
|
11
|
+
verbose: vi.fn(),
|
|
12
|
+
debug: vi.fn(),
|
|
13
|
+
info: vi.fn(),
|
|
14
|
+
warn: vi.fn(),
|
|
15
|
+
error: vi.fn(),
|
|
16
|
+
child: vi.fn(),
|
|
17
|
+
};
|
|
18
|
+
logger.child.mockReturnValue(logger);
|
|
19
|
+
return logger as unknown as ILogger;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function withSwitchboard(
|
|
23
|
+
env: Record<string, string>,
|
|
24
|
+
inspection: boolean | undefined,
|
|
25
|
+
run: (
|
|
26
|
+
switchboard: Awaited<ReturnType<typeof startSwitchboard>>,
|
|
27
|
+
) => Promise<void>,
|
|
28
|
+
): Promise<void> {
|
|
29
|
+
const tempRoot = await mkdtemp(
|
|
30
|
+
join(tmpdir(), "switchboard-inspection-enabled-"),
|
|
31
|
+
);
|
|
32
|
+
const names = [
|
|
33
|
+
"PH_REACTOR_DATABASE_URL",
|
|
34
|
+
"INSPECTION_ENABLED",
|
|
35
|
+
...Object.keys(env),
|
|
36
|
+
];
|
|
37
|
+
const previous = names.map((name) => [name, process.env[name]] as const);
|
|
38
|
+
process.env.PH_REACTOR_DATABASE_URL = join(tempRoot, "reactor-storage");
|
|
39
|
+
delete process.env.INSPECTION_ENABLED;
|
|
40
|
+
Object.assign(process.env, env);
|
|
41
|
+
let switchboard: Awaited<ReturnType<typeof startSwitchboard>> | undefined;
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
switchboard = await bootSwitchboard(
|
|
45
|
+
{
|
|
46
|
+
server: { port: 0 },
|
|
47
|
+
storage: { readModel: { url: join(tempRoot, "read-model") } },
|
|
48
|
+
features: { workflows: false },
|
|
49
|
+
inspection: { enabled: inspection },
|
|
50
|
+
packages: { disableLocal: true },
|
|
51
|
+
identity: { keypairPath: join(tempRoot, "identity.json") },
|
|
52
|
+
drive: {
|
|
53
|
+
slug: "default-drive",
|
|
54
|
+
global: { name: "Default Drive" },
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
{ logger: stubLogger() },
|
|
58
|
+
);
|
|
59
|
+
await run(switchboard);
|
|
60
|
+
await switchboard.shutdown();
|
|
61
|
+
switchboard = undefined;
|
|
62
|
+
} finally {
|
|
63
|
+
await switchboard?.shutdown();
|
|
64
|
+
for (const [name, value] of previous) {
|
|
65
|
+
if (value === undefined) {
|
|
66
|
+
delete process.env[name];
|
|
67
|
+
} else {
|
|
68
|
+
process.env[name] = value;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
await rm(tempRoot, { recursive: true, force: true });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const query = `{ inspection { info { workflows } } }`;
|
|
76
|
+
|
|
77
|
+
async function postQuery(
|
|
78
|
+
port: number,
|
|
79
|
+
path: string,
|
|
80
|
+
): Promise<{ status: number; body: unknown }> {
|
|
81
|
+
const response = await fetch(`http://127.0.0.1:${port}${path}`, {
|
|
82
|
+
method: "POST",
|
|
83
|
+
headers: { "content-type": "application/json" },
|
|
84
|
+
body: JSON.stringify({ query }),
|
|
85
|
+
});
|
|
86
|
+
const text = await response.text();
|
|
87
|
+
let body: unknown = text;
|
|
88
|
+
try {
|
|
89
|
+
body = JSON.parse(text);
|
|
90
|
+
} catch {
|
|
91
|
+
// Not JSON; keep the raw text.
|
|
92
|
+
}
|
|
93
|
+
return { status: response.status, body };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
describe("booting Switchboard", () => {
|
|
97
|
+
it("mounts /graphql/inspection by default", async () => {
|
|
98
|
+
await withSwitchboard(
|
|
99
|
+
{},
|
|
100
|
+
undefined,
|
|
101
|
+
async ({ inspectionEnabled, port }) => {
|
|
102
|
+
expect(inspectionEnabled).toBe(true);
|
|
103
|
+
const { status, body } = await postQuery(port, "/graphql/inspection");
|
|
104
|
+
expect(status).toBe(200);
|
|
105
|
+
expect(body).toMatchObject({
|
|
106
|
+
data: { inspection: { info: { workflows: false } } },
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
);
|
|
110
|
+
}, 60_000);
|
|
111
|
+
|
|
112
|
+
it('leaves /graphql/inspection unmounted under INSPECTION_ENABLED="false"', async () => {
|
|
113
|
+
await withSwitchboard(
|
|
114
|
+
{ INSPECTION_ENABLED: "false" },
|
|
115
|
+
undefined,
|
|
116
|
+
async ({ inspectionEnabled, port }) => {
|
|
117
|
+
expect(inspectionEnabled).toBe(false);
|
|
118
|
+
expect((await postQuery(port, "/graphql/inspection")).status).toBe(404);
|
|
119
|
+
const supergraph = await postQuery(port, "/graphql");
|
|
120
|
+
const { errors } = supergraph.body as {
|
|
121
|
+
errors?: { message: string }[];
|
|
122
|
+
};
|
|
123
|
+
expect(errors?.[0]?.message).toContain(
|
|
124
|
+
'Cannot query field "inspection"',
|
|
125
|
+
);
|
|
126
|
+
},
|
|
127
|
+
);
|
|
128
|
+
}, 60_000);
|
|
129
|
+
|
|
130
|
+
it("keeps a host's inspection: false over INSPECTION_ENABLED=true", async () => {
|
|
131
|
+
await withSwitchboard(
|
|
132
|
+
{ INSPECTION_ENABLED: "true" },
|
|
133
|
+
false,
|
|
134
|
+
async ({ inspectionEnabled, port }) => {
|
|
135
|
+
expect(inspectionEnabled).toBe(false);
|
|
136
|
+
expect((await postQuery(port, "/graphql/inspection")).status).toBe(404);
|
|
137
|
+
},
|
|
138
|
+
);
|
|
139
|
+
}, 60_000);
|
|
140
|
+
});
|