@powerhousedao/switchboard 6.2.3-dev.1 → 6.2.3-dev.100
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/redact-webhook-path.test.d.ts +2 -0
- package/.tsbuild/test/redact-webhook-path.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 +1356 -0
- package/README.md +102 -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-FH4fPeIE.mjs +481 -0
- package/dist/from-env-FH4fPeIE.mjs.map +1 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +98 -80
- 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-CK9_tVak.d.mts +46 -0
- package/dist/plugin-host-CK9_tVak.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-CsY8bjsu.mjs +329 -0
- package/dist/schema-CsY8bjsu.mjs.map +1 -0
- package/dist/schema-MAUTnmj1.d.mts +251 -0
- package/dist/schema-MAUTnmj1.d.mts.map +1 -0
- package/dist/server-CirQ9hyu.mjs +2732 -0
- package/dist/server-CirQ9hyu.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-CidZdkhU.d.mts +314 -0
- package/dist/types-CidZdkhU.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 +248 -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 +62 -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-B2r6AQ4Q.mjs +0 -1553
- package/dist/server-B2r6AQ4Q.mjs.map +0 -1
- package/dist/utils-Baw7rThP.mjs +0 -80
- package/dist/utils-Baw7rThP.mjs.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PGlite } from "@electric-sql/pglite";
|
|
2
|
-
import type { API } from "@powerhousedao/reactor-api";
|
|
2
|
+
import type { API, IAttachmentAccessService } from "@powerhousedao/reactor-api";
|
|
3
3
|
import { createHttpAdapter } from "@powerhousedao/reactor-api";
|
|
4
4
|
import {
|
|
5
5
|
AttachmentBuilder,
|
|
@@ -13,44 +13,56 @@ import { mkdtemp, rm } from "node:fs/promises";
|
|
|
13
13
|
import type { Server } from "node:http";
|
|
14
14
|
import { tmpdir } from "node:os";
|
|
15
15
|
import { join } from "node:path";
|
|
16
|
-
import { afterAll,
|
|
16
|
+
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
17
17
|
import { registerAttachmentRoutes } from "../../src/attachments/index.js";
|
|
18
|
+
import { switchboardConfigFromEnv } from "../../src/config/from-env.js";
|
|
19
|
+
import {
|
|
20
|
+
callerOverEnv,
|
|
21
|
+
switchboardConfigSchema,
|
|
22
|
+
} from "../../src/config/schema.js";
|
|
18
23
|
import { deriveAttachmentServiceConfig } from "../../src/server.mjs";
|
|
19
24
|
|
|
20
25
|
describe("deriveAttachmentServiceConfig", () => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
});
|
|
26
|
+
// An edge's config, as the server derives the options view from it.
|
|
27
|
+
const serviceUrlOf = (env: Record<string, string>, caller?: string) =>
|
|
28
|
+
switchboardConfigSchema.parse(
|
|
29
|
+
callerOverEnv(switchboardConfigFromEnv(env), {
|
|
30
|
+
attachments: { serviceUrl: caller },
|
|
31
|
+
}),
|
|
32
|
+
).attachments.serviceUrl;
|
|
30
33
|
|
|
31
34
|
it("defaults to http://localhost:${port} with no auth when renown is null", () => {
|
|
32
|
-
delete process.env.PH_SWITCHBOARD_PUBLIC_URL;
|
|
33
35
|
const config = deriveAttachmentServiceConfig({}, 4001, null);
|
|
34
36
|
expect(config.remoteUrl).toBe("http://localhost:4001");
|
|
35
37
|
expect(config.jwtHandler).toBeUndefined();
|
|
36
38
|
});
|
|
37
39
|
|
|
38
40
|
it("uses https when options.https is set", () => {
|
|
39
|
-
delete process.env.PH_SWITCHBOARD_PUBLIC_URL;
|
|
40
41
|
const config = deriveAttachmentServiceConfig({ https: true }, 4443, null);
|
|
41
42
|
expect(config.remoteUrl).toBe("https://localhost:4443");
|
|
42
43
|
});
|
|
43
44
|
|
|
44
45
|
it("prefers PH_SWITCHBOARD_PUBLIC_URL over the localhost default", () => {
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
const config = deriveAttachmentServiceConfig(
|
|
47
|
+
{
|
|
48
|
+
attachmentServiceUrl: serviceUrlOf({
|
|
49
|
+
PH_SWITCHBOARD_PUBLIC_URL: "https://sb.example.com",
|
|
50
|
+
}),
|
|
51
|
+
},
|
|
52
|
+
4001,
|
|
53
|
+
null,
|
|
54
|
+
);
|
|
47
55
|
expect(config.remoteUrl).toBe("https://sb.example.com");
|
|
48
56
|
});
|
|
49
57
|
|
|
50
58
|
it("prefers the explicit attachmentServiceUrl option above all else", () => {
|
|
51
|
-
process.env.PH_SWITCHBOARD_PUBLIC_URL = "https://sb.example.com";
|
|
52
59
|
const config = deriveAttachmentServiceConfig(
|
|
53
|
-
{
|
|
60
|
+
{
|
|
61
|
+
attachmentServiceUrl: serviceUrlOf(
|
|
62
|
+
{ PH_SWITCHBOARD_PUBLIC_URL: "https://sb.example.com" },
|
|
63
|
+
"https://override.example.com",
|
|
64
|
+
),
|
|
65
|
+
},
|
|
54
66
|
4001,
|
|
55
67
|
null,
|
|
56
68
|
);
|
|
@@ -109,10 +121,20 @@ describe("attachment service built from deriveAttachmentServiceConfig round-trip
|
|
|
109
121
|
registerAttachmentRoutes({
|
|
110
122
|
httpAdapter: adapter,
|
|
111
123
|
attachments,
|
|
124
|
+
attachmentAccess: {
|
|
125
|
+
canReadAttachment: (
|
|
126
|
+
request: Parameters<IAttachmentAccessService["canReadAttachment"]>[0],
|
|
127
|
+
) =>
|
|
128
|
+
Promise.resolve({
|
|
129
|
+
kind: "allowed",
|
|
130
|
+
documentId: request.documentId as never,
|
|
131
|
+
ref: request.attachmentRef as never,
|
|
132
|
+
}),
|
|
133
|
+
},
|
|
112
134
|
authService: undefined,
|
|
113
135
|
} as unknown as API);
|
|
114
136
|
|
|
115
|
-
server = await adapter.listen(0);
|
|
137
|
+
server = await adapter.listen(0, undefined, "127.0.0.1");
|
|
116
138
|
const addr = server.address();
|
|
117
139
|
if (!addr || typeof addr === "string") throw new Error("no addr");
|
|
118
140
|
port = addr.port;
|
|
@@ -149,7 +171,7 @@ describe("attachment service built from deriveAttachmentServiceConfig round-trip
|
|
|
149
171
|
const result = await upload.send(stream);
|
|
150
172
|
expect(result.header.sizeBytes).toBe(bytes.byteLength);
|
|
151
173
|
|
|
152
|
-
const got = await service.get(result.ref);
|
|
174
|
+
const got = await service.get(result.ref, { documentId: "doc-1" });
|
|
153
175
|
expect(got.header.mimeType).toBe("text/plain");
|
|
154
176
|
const reader = got.body.getReader();
|
|
155
177
|
const chunks: Uint8Array[] = [];
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { AttachmentHash } from "@powerhousedao/reactor";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
ATTACHMENT_URL_SIGNING_SECRET_ENV,
|
|
5
|
+
AttachmentUrlSigner,
|
|
6
|
+
resolveAttachmentUrlSigning,
|
|
7
|
+
} from "../../src/attachments/url-signer.js";
|
|
8
|
+
|
|
9
|
+
const HASH = "a".repeat(64) as AttachmentHash;
|
|
10
|
+
const OTHER_HASH = "b".repeat(64) as AttachmentHash;
|
|
11
|
+
const SECRET = "k".repeat(32);
|
|
12
|
+
|
|
13
|
+
function signed(now: number, ttl = 300) {
|
|
14
|
+
const signer = new AttachmentUrlSigner(SECRET, () => now);
|
|
15
|
+
const { query, expiresAtUtc } = signer.sign(HASH, "doc-1", ttl);
|
|
16
|
+
const params = new URLSearchParams(query);
|
|
17
|
+
return {
|
|
18
|
+
signer,
|
|
19
|
+
expiresAtUtc,
|
|
20
|
+
documentId: params.get("documentId")!,
|
|
21
|
+
expires: params.get("expires")!,
|
|
22
|
+
signature: params.get("signature")!,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe("AttachmentUrlSigner", () => {
|
|
27
|
+
const NOW = Date.parse("2026-09-24T00:00:00.000Z");
|
|
28
|
+
|
|
29
|
+
it("verifies what it signed until the expiry", () => {
|
|
30
|
+
const { signer, expiresAtUtc, documentId, expires, signature } =
|
|
31
|
+
signed(NOW);
|
|
32
|
+
|
|
33
|
+
expect(documentId).toBe("doc-1");
|
|
34
|
+
expect(expiresAtUtc).toBe(new Date(NOW + 300_000).toISOString());
|
|
35
|
+
expect(signer.verify(HASH, documentId, expires, signature)).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("refuses at and after the expiry", () => {
|
|
39
|
+
const { expires, signature } = signed(NOW);
|
|
40
|
+
const at = new AttachmentUrlSigner(SECRET, () => NOW + 300_000);
|
|
41
|
+
|
|
42
|
+
expect(at.verify(HASH, "doc-1", expires, signature)).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("refuses a different hash, document, expiry or secret", () => {
|
|
46
|
+
const { signer, expires, signature } = signed(NOW);
|
|
47
|
+
|
|
48
|
+
expect(signer.verify(OTHER_HASH, "doc-1", expires, signature)).toBe(false);
|
|
49
|
+
expect(signer.verify(HASH, "doc-2", expires, signature)).toBe(false);
|
|
50
|
+
expect(
|
|
51
|
+
signer.verify(HASH, "doc-1", String(Number(expires) + 1), signature),
|
|
52
|
+
).toBe(false);
|
|
53
|
+
expect(
|
|
54
|
+
new AttachmentUrlSigner("x".repeat(32), () => NOW).verify(
|
|
55
|
+
HASH,
|
|
56
|
+
"doc-1",
|
|
57
|
+
expires,
|
|
58
|
+
signature,
|
|
59
|
+
),
|
|
60
|
+
).toBe(false);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("refuses malformed expiry and signature values", () => {
|
|
64
|
+
const { signer, expires, signature } = signed(NOW);
|
|
65
|
+
|
|
66
|
+
expect(signer.verify(HASH, "doc-1", `${expires}.0`, signature)).toBe(false);
|
|
67
|
+
expect(signer.verify(HASH, "doc-1", expires, `${signature}=`)).toBe(false);
|
|
68
|
+
expect(signer.verify(HASH, "doc-1", expires, "")).toBe(false);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe("resolveAttachmentUrlSigning", () => {
|
|
73
|
+
it("uses a configured secret", () => {
|
|
74
|
+
const signing = resolveAttachmentUrlSigning({
|
|
75
|
+
[ATTACHMENT_URL_SIGNING_SECRET_ENV]: SECRET,
|
|
76
|
+
NODE_ENV: "production",
|
|
77
|
+
});
|
|
78
|
+
expect(signing.status).toBe("configured");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("fails closed in production when unset", () => {
|
|
82
|
+
expect(resolveAttachmentUrlSigning({ NODE_ENV: "production" })).toEqual({
|
|
83
|
+
status: "unconfigured",
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it.each([undefined, "development", "test"])(
|
|
88
|
+
"uses a per-process secret when unset and NODE_ENV is %s",
|
|
89
|
+
(nodeEnv) => {
|
|
90
|
+
const signing = resolveAttachmentUrlSigning({ NODE_ENV: nodeEnv });
|
|
91
|
+
expect(signing.status).toBe("ephemeral");
|
|
92
|
+
},
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
it.each(["short", ` ${"k".repeat(32)}`, ""])(
|
|
96
|
+
"refuses to boot on an unusable secret %j",
|
|
97
|
+
(secret) => {
|
|
98
|
+
expect(() =>
|
|
99
|
+
resolveAttachmentUrlSigning({
|
|
100
|
+
[ATTACHMENT_URL_SIGNING_SECRET_ENV]: secret,
|
|
101
|
+
}),
|
|
102
|
+
).toThrow(ATTACHMENT_URL_SIGNING_SECRET_ENV);
|
|
103
|
+
},
|
|
104
|
+
);
|
|
105
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { mkdtemp, rm, writeFile } 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 { SwitchboardConfigInput } from "../src/config/schema.js";
|
|
7
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
8
|
+
|
|
9
|
+
type Info = ReturnType<typeof vi.fn>;
|
|
10
|
+
|
|
11
|
+
function stubLogger(): ILogger & { info: Info } {
|
|
12
|
+
const logger = {
|
|
13
|
+
verbose: vi.fn(),
|
|
14
|
+
debug: vi.fn(),
|
|
15
|
+
info: vi.fn(),
|
|
16
|
+
warn: vi.fn(),
|
|
17
|
+
error: vi.fn(),
|
|
18
|
+
child: vi.fn(),
|
|
19
|
+
};
|
|
20
|
+
logger.child.mockReturnValue(logger);
|
|
21
|
+
return logger as unknown as ILogger & { info: Info };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const AUTH_VARS = ["AUTH_ENABLED", "ADMINS", "RESOLVE_CALLER_IDENTITY"];
|
|
25
|
+
|
|
26
|
+
/** Whether the switchboard enforces auth, from reactor-api's setup log. */
|
|
27
|
+
async function bootsWithAuth(options: {
|
|
28
|
+
file: Record<string, unknown>;
|
|
29
|
+
config?: SwitchboardConfigInput["auth"];
|
|
30
|
+
env?: Record<string, string>;
|
|
31
|
+
}): Promise<boolean> {
|
|
32
|
+
const tempRoot = await mkdtemp(join(tmpdir(), "switchboard-auth-config-"));
|
|
33
|
+
const names = ["PH_REACTOR_DATABASE_URL", ...AUTH_VARS];
|
|
34
|
+
const previous = names.map((name) => [name, process.env[name]] as const);
|
|
35
|
+
for (const name of AUTH_VARS) delete process.env[name];
|
|
36
|
+
process.env.PH_REACTOR_DATABASE_URL = join(tempRoot, "reactor-storage");
|
|
37
|
+
Object.assign(process.env, options.env);
|
|
38
|
+
const configFile = join(tempRoot, "powerhouse.config.json");
|
|
39
|
+
await writeFile(configFile, JSON.stringify(options.file));
|
|
40
|
+
const logger = stubLogger();
|
|
41
|
+
const switchboard = await bootSwitchboard(
|
|
42
|
+
{
|
|
43
|
+
configFile,
|
|
44
|
+
auth: options.config,
|
|
45
|
+
server: { port: 0 },
|
|
46
|
+
storage: { readModel: { url: join(tempRoot, "read-model") } },
|
|
47
|
+
features: { workflows: false, mcp: false },
|
|
48
|
+
packages: { disableLocal: true },
|
|
49
|
+
identity: { keypairPath: join(tempRoot, "identity.json") },
|
|
50
|
+
},
|
|
51
|
+
{ logger },
|
|
52
|
+
).finally(() => {
|
|
53
|
+
for (const [name, value] of previous) {
|
|
54
|
+
if (value === undefined) delete process.env[name];
|
|
55
|
+
else process.env[name] = value;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
try {
|
|
59
|
+
const setup = logger.info.mock.calls.find(
|
|
60
|
+
([message]) =>
|
|
61
|
+
typeof message === "string" &&
|
|
62
|
+
message.startsWith("Setting up Auth middleware"),
|
|
63
|
+
);
|
|
64
|
+
return setup?.[1] === true;
|
|
65
|
+
} finally {
|
|
66
|
+
await switchboard.shutdown();
|
|
67
|
+
await rm(tempRoot, { recursive: true, force: true });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const ADMIN = "0x1111111111111111111111111111111111111111";
|
|
72
|
+
|
|
73
|
+
describe("booting Switchboard with auth", () => {
|
|
74
|
+
it("enforces auth the config turns on", async () => {
|
|
75
|
+
expect(
|
|
76
|
+
await bootsWithAuth({
|
|
77
|
+
file: {},
|
|
78
|
+
config: { enabled: true, admins: [ADMIN] },
|
|
79
|
+
}),
|
|
80
|
+
).toBe(true);
|
|
81
|
+
}, 60_000);
|
|
82
|
+
|
|
83
|
+
it("still takes auth from the config file when the config leaves it unset", async () => {
|
|
84
|
+
expect(
|
|
85
|
+
await bootsWithAuth({
|
|
86
|
+
file: { auth: { enabled: true, admins: [ADMIN] } },
|
|
87
|
+
}),
|
|
88
|
+
).toBe(true);
|
|
89
|
+
}, 60_000);
|
|
90
|
+
|
|
91
|
+
it("lets AUTH_ENABLED override the config file, as before", async () => {
|
|
92
|
+
expect(
|
|
93
|
+
await bootsWithAuth({
|
|
94
|
+
file: { auth: { enabled: true, admins: [ADMIN] } },
|
|
95
|
+
env: { AUTH_ENABLED: "false" },
|
|
96
|
+
}),
|
|
97
|
+
).toBe(false);
|
|
98
|
+
}, 60_000);
|
|
99
|
+
|
|
100
|
+
it("lets AUTH_ENABLED override the caller's config, as it overrode options", async () => {
|
|
101
|
+
expect(
|
|
102
|
+
await bootsWithAuth({
|
|
103
|
+
file: {},
|
|
104
|
+
config: { enabled: false },
|
|
105
|
+
env: { AUTH_ENABLED: "true", ADMINS: ADMIN },
|
|
106
|
+
}),
|
|
107
|
+
).toBe(true);
|
|
108
|
+
}, 60_000);
|
|
109
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {
|
|
2
|
+
hasDerivedDocumentId,
|
|
3
|
+
isDerivedDocumentId,
|
|
4
|
+
signaturePolicyOf,
|
|
5
|
+
} from "@powerhousedao/shared/document-model";
|
|
6
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
7
|
+
import { tmpdir } from "node:os";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import type { ILogger } from "document-model";
|
|
10
|
+
import { describe, expect, it, vi } from "vitest";
|
|
11
|
+
import type { startSwitchboard } from "../src/server.mjs";
|
|
12
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
13
|
+
|
|
14
|
+
function stubLogger(): ILogger {
|
|
15
|
+
const logger = {
|
|
16
|
+
verbose: vi.fn(),
|
|
17
|
+
debug: vi.fn(),
|
|
18
|
+
info: vi.fn(),
|
|
19
|
+
warn: vi.fn(),
|
|
20
|
+
error: vi.fn(),
|
|
21
|
+
child: vi.fn(),
|
|
22
|
+
};
|
|
23
|
+
logger.child.mockReturnValue(logger);
|
|
24
|
+
return logger as unknown as ILogger;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function withSwitchboard(
|
|
28
|
+
env: Record<string, string>,
|
|
29
|
+
run: (
|
|
30
|
+
switchboard: Awaited<ReturnType<typeof startSwitchboard>>,
|
|
31
|
+
) => Promise<void>,
|
|
32
|
+
): Promise<void> {
|
|
33
|
+
const tempRoot = await mkdtemp(join(tmpdir(), "switchboard-create-policy-"));
|
|
34
|
+
const names = ["PH_REACTOR_DATABASE_URL", ...Object.keys(env)];
|
|
35
|
+
const previous = names.map((name) => [name, process.env[name]] as const);
|
|
36
|
+
process.env.PH_REACTOR_DATABASE_URL = join(tempRoot, "reactor-storage");
|
|
37
|
+
Object.assign(process.env, env);
|
|
38
|
+
let switchboard: Awaited<ReturnType<typeof startSwitchboard>> | undefined;
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
switchboard = await bootSwitchboard(
|
|
42
|
+
{
|
|
43
|
+
server: { port: 0 },
|
|
44
|
+
storage: { readModel: { url: join(tempRoot, "read-model") } },
|
|
45
|
+
features: { workflows: false, mcp: false },
|
|
46
|
+
packages: { disableLocal: true },
|
|
47
|
+
identity: { keypairPath: join(tempRoot, "identity.json") },
|
|
48
|
+
drive: {
|
|
49
|
+
slug: "default-drive",
|
|
50
|
+
global: { name: "Default Drive" },
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
{ logger: stubLogger() },
|
|
54
|
+
);
|
|
55
|
+
await run(switchboard);
|
|
56
|
+
await switchboard.shutdown();
|
|
57
|
+
switchboard = undefined;
|
|
58
|
+
} finally {
|
|
59
|
+
await switchboard?.shutdown();
|
|
60
|
+
for (const [name, value] of previous) {
|
|
61
|
+
if (value === undefined) {
|
|
62
|
+
delete process.env[name];
|
|
63
|
+
} else {
|
|
64
|
+
process.env[name] = value;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
await rm(tempRoot, { recursive: true, force: true });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
describe("booting Switchboard", () => {
|
|
72
|
+
it("creates v2-required documents and drives by default", async () => {
|
|
73
|
+
await withSwitchboard({}, async ({ reactor }) => {
|
|
74
|
+
const document = await reactor.createEmpty("powerhouse/document-model");
|
|
75
|
+
expect(signaturePolicyOf(document.header)).toBe("v2-required");
|
|
76
|
+
expect(hasDerivedDocumentId(document.header)).toBe(true);
|
|
77
|
+
|
|
78
|
+
const drive = await reactor.drives.create({ global: { name: "Drive" } });
|
|
79
|
+
expect(signaturePolicyOf(drive.header)).toBe("v2-required");
|
|
80
|
+
|
|
81
|
+
const defaultDrive = await reactor.get("default-drive");
|
|
82
|
+
expect(signaturePolicyOf(defaultDrive.header)).toBe("v2-required");
|
|
83
|
+
});
|
|
84
|
+
}, 60_000);
|
|
85
|
+
|
|
86
|
+
it("creates legacy documents and drives under CREATE_SIGNATURE_POLICY=legacy", async () => {
|
|
87
|
+
await withSwitchboard(
|
|
88
|
+
{ CREATE_SIGNATURE_POLICY: "legacy" },
|
|
89
|
+
async ({ reactor }) => {
|
|
90
|
+
const document = await reactor.createEmpty("powerhouse/document-model");
|
|
91
|
+
expect(signaturePolicyOf(document.header)).toBe("legacy");
|
|
92
|
+
expect(isDerivedDocumentId(document.header.id)).toBe(false);
|
|
93
|
+
|
|
94
|
+
const drive = await reactor.drives.create({
|
|
95
|
+
global: { name: "Drive" },
|
|
96
|
+
});
|
|
97
|
+
expect(signaturePolicyOf(drive.header)).toBe("legacy");
|
|
98
|
+
expect(isDerivedDocumentId(drive.header.id)).toBe(false);
|
|
99
|
+
|
|
100
|
+
const defaultDrive = await reactor.get("default-drive");
|
|
101
|
+
expect(signaturePolicyOf(defaultDrive.header)).toBe("legacy");
|
|
102
|
+
|
|
103
|
+
const asked = await reactor.createEmpty("powerhouse/document-model", {
|
|
104
|
+
signaturePolicy: "v2-required",
|
|
105
|
+
});
|
|
106
|
+
expect(hasDerivedDocumentId(asked.header)).toBe(true);
|
|
107
|
+
},
|
|
108
|
+
);
|
|
109
|
+
}, 60_000);
|
|
110
|
+
});
|