@powerhousedao/switchboard 6.2.3-dev.58 → 6.2.3-dev.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/.tsbuild/test/plugin-presence.test.d.ts +2 -0
  2. package/.tsbuild/test/plugin-presence.test.d.ts.map +1 -0
  3. package/.tsbuild/tsconfig.tsbuildinfo +1 -1
  4. package/CHANGELOG.md +22 -0
  5. package/dist/index.mjs +1 -1
  6. package/dist/mcp-cNWW82NH.mjs +27 -0
  7. package/dist/mcp-cNWW82NH.mjs.map +1 -0
  8. package/dist/plugin-host-CGO4XZzK.d.mts +38 -0
  9. package/dist/plugin-host-CGO4XZzK.d.mts.map +1 -0
  10. package/dist/plugins/attachments.d.mts +23 -0
  11. package/dist/plugins/attachments.d.mts.map +1 -0
  12. package/dist/plugins/attachments.mjs +4 -0
  13. package/dist/plugins/mcp.d.mts +21 -0
  14. package/dist/plugins/mcp.d.mts.map +1 -0
  15. package/dist/plugins/mcp.mjs +4 -0
  16. package/dist/plugins/privacy.d.mts +12 -0
  17. package/dist/plugins/privacy.d.mts.map +1 -0
  18. package/dist/plugins/privacy.mjs +4 -0
  19. package/dist/plugins/workflows.d.mts +36 -0
  20. package/dist/plugins/workflows.d.mts.map +1 -0
  21. package/dist/plugins/workflows.mjs +4 -0
  22. package/dist/privacy-C8KVimKF.mjs +113 -0
  23. package/dist/privacy-C8KVimKF.mjs.map +1 -0
  24. package/dist/{server-Cw2WnaCA.mjs → server-Ncv91CrC.mjs} +187 -1359
  25. package/dist/server-Ncv91CrC.mjs.map +1 -0
  26. package/dist/server.d.mts +12 -14
  27. package/dist/server.d.mts.map +1 -1
  28. package/dist/server.mjs +3 -3
  29. package/dist/workflow-runtime-7GaJ13c9.d.mts +30 -0
  30. package/dist/workflow-runtime-7GaJ13c9.d.mts.map +1 -0
  31. package/dist/workflows-qKtqZhn3.mjs +1338 -0
  32. package/dist/workflows-qKtqZhn3.mjs.map +1 -0
  33. package/package.json +42 -17
  34. package/test/boot-mcp-enabled.test.ts +10 -1
  35. package/test/plugin-presence.test.ts +269 -0
  36. package/tsconfig.json +3 -0
  37. package/tsdown.config.ts +6 -0
  38. package/dist/server-Cw2WnaCA.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ ## 6.2.3-dev.59 (2026-10-15)
2
+
3
+ ### 🚀 Features
4
+
5
+ - **connect,vetra-studio:** browser plugin pipeline over the served composition (R3.2) + the studio plugins (R4 start) ([8fb91868da](https://github.com/powerhouse-inc/powerhouse/commit/8fb91868da))
6
+ - **ph-cli,switchboard:** host.js compositions and core drives reach the switchboard runner (R2.6b) ([e74f6830fe](https://github.com/powerhouse-inc/powerhouse/commit/e74f6830fe))
7
+ - **switchboard:** plugin composition seam for host.js entries and tests (R2.6a) ([8e64a8e6ea](https://github.com/powerhouse-inc/powerhouse/commit/8e64a8e6ea))
8
+ - **switchboard:** workflows subsystem carved into the plugin composition (R2.5) ([e9467d9c38](https://github.com/powerhouse-inc/powerhouse/commit/e9467d9c38))
9
+ - **switchboard:** privacy subsystem carved into the plugin composition (R2.4) ([8bff8cbbff](https://github.com/powerhouse-inc/powerhouse/commit/8bff8cbbff))
10
+ - **switchboard:** attachments subsystem carved into the plugin composition (R2.3) ([d63108172e](https://github.com/powerhouse-inc/powerhouse/commit/d63108172e))
11
+ - **switchboard:** mcp subsystem as the first built-in plugin (R2.2) ([41aebd9a0d](https://github.com/powerhouse-inc/powerhouse/commit/41aebd9a0d))
12
+ - **switchboard:** plugin pipeline scaffold for the subsystem carve (R2.1) ([042cd5a93c](https://github.com/powerhouse-inc/powerhouse/commit/042cd5a93c))
13
+
14
+ ### 🩹 Fixes
15
+
16
+ - **switchboard:** absent plugins actually deactivate — presence suite (R2.6c) ([5c5380f872](https://github.com/powerhouse-inc/powerhouse/commit/5c5380f872))
17
+
18
+ ### ❤️ Thank You
19
+
20
+ - Claude Fable 5
21
+ - Wouter Kampmann
22
+
1
23
  ## 6.2.3-dev.58 (2026-10-14)
2
24
 
3
25
  ### 🩹 Fixes
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="c9eef974-47b1-5e45-aad6-5ebb1885b76a")}catch(e){}}();
4
- import { a as StoredDocumentsRefusedError, c as initProfilerFromEnv, i as startSwitchboard, l as parseForcePgVersion } from "./server-Cw2WnaCA.mjs";
4
+ import { a as StoredDocumentsRefusedError, i as startSwitchboard, l as initProfilerFromEnv, u as parseForcePgVersion } from "./server-Ncv91CrC.mjs";
5
5
  import { metrics } from "@opentelemetry/api";
6
6
  import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
7
7
  import { ExpressInstrumentation } from "@opentelemetry/instrumentation-express";
@@ -0,0 +1,27 @@
1
+ //#region src/plugins/mcp.mts
2
+ /**
3
+ * R2.2 — the MCP subsystem as a built-in plugin. Flag-on semantics: PRESENCE
4
+ * IS ACTIVATION — listed (built-in default) means the /mcp endpoint mounts;
5
+ * removed from the composition means it does not exist. The MCP_ENABLED env
6
+ * flag governs the classic/flag-off path only (resolveMcpEnabled, which
7
+ * still runs and whose result this transform overrides flag-on).
8
+ *
9
+ * The mount itself lives inside reactor-api's initializeAndStartAPI (carve
10
+ * map: reactor-api server.ts:1282-1294) and is driven by options.mcp — the
11
+ * plugin's whole job is owning that option.
12
+ */
13
+
14
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d0d8adf1-591a-51b6-9fdb-e71751e66fca")}catch(e){}}();
15
+ const mcpPlugin = {
16
+ name: "switchboard-mcp",
17
+ appliesTo: "switchboard",
18
+ hooks: { transformServerOptions: (options) => options.mcp === false ? options : {
19
+ ...options,
20
+ mcp: true
21
+ } }
22
+ };
23
+ //#endregion
24
+ export { mcpPlugin as t };
25
+
26
+ //# sourceMappingURL=mcp-cNWW82NH.mjs.map
27
+ //# debugId=d0d8adf1-591a-51b6-9fdb-e71751e66fca
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-cNWW82NH.mjs","sources":["../src/plugins/mcp.mts"],"sourcesContent":["import type { HostPlugin } from \"@powerhousedao/host-core\";\nimport type { SwitchboardHostContext } from \"../plugin-host.mjs\";\n\n/**\n * R2.2 — the MCP subsystem as a built-in plugin. Flag-on semantics: PRESENCE\n * IS ACTIVATION — listed (built-in default) means the /mcp endpoint mounts;\n * removed from the composition means it does not exist. The MCP_ENABLED env\n * flag governs the classic/flag-off path only (resolveMcpEnabled, which\n * still runs and whose result this transform overrides flag-on).\n *\n * The mount itself lives inside reactor-api's initializeAndStartAPI (carve\n * map: reactor-api server.ts:1282-1294) and is driven by options.mcp — the\n * plugin's whole job is owning that option.\n */\nexport const mcpPlugin: HostPlugin<{\n transformServerOptions: (\n options: Record<string, unknown>,\n ctx: SwitchboardHostContext,\n ) => Record<string, unknown>;\n}> = {\n name: \"switchboard-mcp\",\n appliesTo: \"switchboard\",\n hooks: {\n // An explicit caller/host `mcp: false` option keeps winning (the same\n // short-circuit resolveMcpEnabled has); only the ENV flag loses its\n // meaning flag-on — presence in the composition is the switch.\n transformServerOptions: (options) =>\n options.mcp === false ? options : { ...options, mcp: true },\n },\n};\n\n// resolveHostPlugins consumes the DEFAULT export (plugin object or factory).\nexport default mcpPlugin;\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAcA,MAAa,YAKR;CACH,MAAM;CACN,WAAW;CACX,OAAO,EAIL,yBAAyB,YACvB,QAAQ,QAAQ,QAAQ,UAAU;EAAE,GAAG;EAAS,KAAK;CAAK,EAC9D;AACF","debug_id":"d0d8adf1-591a-51b6-9fdb-e71751e66fca"}
@@ -0,0 +1,38 @@
1
+ import { HostPlugin, MergedContribution, ResolvedPlugin } from "@powerhousedao/host-core";
2
+ //#region src/plugin-host.d.mts
3
+ /**
4
+ * The context plugins receive. Fields are populated as the boot spine reaches
5
+ * them (api/client/graphqlManager are undefined before stage 17); concrete
6
+ * types stay in server.mts — subsystem carves tighten their own slices.
7
+ */
8
+ interface SwitchboardHostContext {
9
+ /** The switchboard's ILogger; typed loosely here to avoid pinning the
10
+ * logger package in the scaffold — subsystem carves use it as-is. */
11
+ logger: unknown;
12
+ options: Record<string, unknown>;
13
+ renown: unknown;
14
+ serverPort?: number;
15
+ /** Set by the attachments plugin at onHttpMounting; the boot reads it for
16
+ * the returned handle. */
17
+ attachmentService?: unknown;
18
+ /** Privacy plugin state: config resolved at transformServerOptions
19
+ * (fail-fast), the running subsystem set at onSubgraphsRegistering. */
20
+ privacyConfig?: unknown;
21
+ privacy?: unknown;
22
+ /** Workflows plugin: wiring closures handed in by server.mts, runtime +
23
+ * retry handles stored by the plugin. */
24
+ workflowsOrchestration?: unknown;
25
+ workflows?: unknown;
26
+ workflowsRetry?: unknown;
27
+ api?: unknown;
28
+ client?: unknown;
29
+ graphqlManager?: unknown;
30
+ reactorClientModule?: unknown;
31
+ /** Late subgraph registrations drain before the readiness router update. */
32
+ lateSubgraphs?: Promise<unknown>[];
33
+ contributions: Record<string, MergedContribution[]>;
34
+ }
35
+ //#endregion
36
+ export { SwitchboardHostContext as t };
37
+ export {};
38
+ //# sourceMappingURL=plugin-host-CGO4XZzK.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-host-CGO4XZzK.d.mts","names":[],"sources":["../src/plugin-host.mts"],"mappings":";;;;;;;UAgDiB;;;EAGf;EACA,SAAS;EACT;EACA;;;EAGA;;;EAGA;EACA;;;EAGA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA,gBAAgB;EAChB,eAAe,eAAe"}
@@ -0,0 +1,23 @@
1
+ import { t as SwitchboardHostContext } from "../plugin-host-CGO4XZzK.mjs";
2
+ import { HostPlugin } from "@powerhousedao/host-core";
3
+ //#region src/plugins/attachments.d.mts
4
+ /**
5
+ * R2.3 — the attachments subsystem as a built-in plugin: the six /attachments
6
+ * routes mount at onHttpMounting and the remote attachment service is created
7
+ * for the returned handle. Presence is activation — removed from the
8
+ * composition, the routes and service do not exist. NOT yet carved: the
9
+ * attachment-reference read model registered inside reactor construction
10
+ * (carve map: server.mts initializeClient) — it follows with the
11
+ * onReadModelsRegistering step in R2 step 2; until then it registers on both
12
+ * paths (a dormant read model when the plugin is absent, harmless).
13
+ *
14
+ * Inputs (carve map): api (routes), options.attachmentServiceUrl /
15
+ * PH_SWITCHBOARD_PUBLIC_URL / https + serverPort + renown (service config).
16
+ */
17
+ export declare const attachmentsPlugin: HostPlugin<{
18
+ onHttpMounting: (ctx: SwitchboardHostContext) => void;
19
+ }>;
20
+ //#endregion
21
+ export { attachmentsPlugin as default };
22
+ export {};
23
+ //# sourceMappingURL=attachments.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachments.d.mts","names":[],"sources":["../../src/plugins/attachments.mts"],"mappings":";;;;;;;;;;;;;;;;qBAoBa,mBAAmB;EAC9B,iBAAiB,KAAK"}
@@ -0,0 +1,4 @@
1
+ import { s as attachmentsPlugin } from "../server-Ncv91CrC.mjs";
2
+ export { attachmentsPlugin, attachmentsPlugin as default };
3
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d185ce4b-9915-5c8a-b597-065cc85a9750")}catch(e){}}();
4
+ //# debugId=d185ce4b-9915-5c8a-b597-065cc85a9750
@@ -0,0 +1,21 @@
1
+ import { t as SwitchboardHostContext } from "../plugin-host-CGO4XZzK.mjs";
2
+ import { HostPlugin } from "@powerhousedao/host-core";
3
+ //#region src/plugins/mcp.d.mts
4
+ /**
5
+ * R2.2 — the MCP subsystem as a built-in plugin. Flag-on semantics: PRESENCE
6
+ * IS ACTIVATION — listed (built-in default) means the /mcp endpoint mounts;
7
+ * removed from the composition means it does not exist. The MCP_ENABLED env
8
+ * flag governs the classic/flag-off path only (resolveMcpEnabled, which
9
+ * still runs and whose result this transform overrides flag-on).
10
+ *
11
+ * The mount itself lives inside reactor-api's initializeAndStartAPI (carve
12
+ * map: reactor-api server.ts:1282-1294) and is driven by options.mcp — the
13
+ * plugin's whole job is owning that option.
14
+ */
15
+ export declare const mcpPlugin: HostPlugin<{
16
+ transformServerOptions: (options: Record<string, unknown>, ctx: SwitchboardHostContext) => Record<string, unknown>;
17
+ }>;
18
+ //#endregion
19
+ export { mcpPlugin as default };
20
+ export {};
21
+ //# sourceMappingURL=mcp.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.d.mts","names":[],"sources":["../../src/plugins/mcp.mts"],"mappings":";;;;;;;;;;;;;;qBAca,WAAW;EACtB,yBACE,SAAS,yBACT,KAAK,2BACF"}
@@ -0,0 +1,4 @@
1
+ import { t as mcpPlugin } from "../mcp-cNWW82NH.mjs";
2
+ export { mcpPlugin as default, mcpPlugin };
3
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="eae60854-3cb6-5759-8567-94ac5a34d60a")}catch(e){}}();
4
+ //# debugId=eae60854-3cb6-5759-8567-94ac5a34d60a
@@ -0,0 +1,12 @@
1
+ import { t as SwitchboardHostContext } from "../plugin-host-CGO4XZzK.mjs";
2
+ import { HostPlugin } from "@powerhousedao/host-core";
3
+ //#region src/plugins/privacy.d.mts
4
+ export declare const privacyPlugin: HostPlugin<{
5
+ transformServerOptions: (options: Record<string, unknown>, ctx: SwitchboardHostContext) => Record<string, unknown>;
6
+ onSubgraphsRegistering: (ctx: SwitchboardHostContext) => Promise<void>;
7
+ onShutdown: (ctx: SwitchboardHostContext) => Promise<void>;
8
+ }>;
9
+ //#endregion
10
+ export { privacyPlugin as default };
11
+ export {};
12
+ //# sourceMappingURL=privacy.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"privacy.d.mts","names":[],"sources":["../../src/plugins/privacy.mts"],"mappings":";;;qBA+Ba,eAAe;EAC1B,yBACE,SAAS,yBACT,KAAK,2BACF;EACL,yBAAyB,KAAK,2BAA2B;EACzD,aAAa,KAAK,2BAA2B"}
@@ -0,0 +1,4 @@
1
+ import { t as privacyPlugin } from "../privacy-C8KVimKF.mjs";
2
+ export { privacyPlugin as default, privacyPlugin };
3
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="942527ef-2aa7-59d7-a6fa-6766c92fb0b1")}catch(e){}}();
4
+ //# debugId=942527ef-2aa7-59d7-a6fa-6766c92fb0b1
@@ -0,0 +1,36 @@
1
+ import { t as SwitchboardHostContext } from "../plugin-host-CGO4XZzK.mjs";
2
+ import { t as ComposedWorkflowRuntime } from "../workflow-runtime-7GaJ13c9.mjs";
3
+ import { HostPlugin } from "@powerhousedao/host-core";
4
+ //#region src/plugins/workflows.d.mts
5
+ /**
6
+ * R2.5 — the workflows subsystem as a built-in plugin. Presence is activation
7
+ * (an explicit options.workflows.enabled === false still wins, mirroring the
8
+ * mcp carve); the PH_WORKFLOWS_ENABLED env/config resolution governs the
9
+ * classic path only.
10
+ *
11
+ * The orchestration (compose, singleton-conflict retry, subgraph
12
+ * registration, start, inspection fact) moves here VERBATIM from the inline
13
+ * block; the dependency-heavy wiring closures (composeWorkflows,
14
+ * registerWorkflowSubgraph) stay in server.mts and travel via ctx — same
15
+ * realm, code moved not redesigned. Carve-map constraints preserved: the
16
+ * retry path's onComposed registers + updates the router ITSELF (it may fire
17
+ * after the readiness drain); teardown stops retry then runtime, and runs
18
+ * AFTER privacy's (sequential onShutdown, registration order).
19
+ */
20
+ export interface WorkflowsOrchestration {
21
+ enabled: boolean;
22
+ composeWorkflows: () => Promise<ComposedWorkflowRuntime>;
23
+ registerWorkflowSubgraph: (composed: ComposedWorkflowRuntime) => Promise<void>;
24
+ updateRouter: () => Promise<void>;
25
+ reportMountFailure: (error: unknown) => void;
26
+ setWorkflowsFact: () => void;
27
+ }
28
+ export declare const workflowsPlugin: HostPlugin<{
29
+ transformServerOptions: (options: Record<string, unknown>, ctx: SwitchboardHostContext) => Record<string, unknown>;
30
+ onSubgraphsRegistering: (ctx: SwitchboardHostContext) => Promise<void>;
31
+ onShutdown: (ctx: SwitchboardHostContext) => Promise<void>;
32
+ }>;
33
+ //#endregion
34
+ export { workflowsPlugin as default };
35
+ export {};
36
+ //# sourceMappingURL=workflows.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflows.d.mts","names":[],"sources":["../../src/plugins/workflows.mts"],"mappings":";;;;;;;;;;;;;;;;;;;iBA0BiB;EACf;EACA,wBAAwB,QAAQ;EAChC,2BACE,UAAU,4BACP;EACL,oBAAoB;EACpB,qBAAqB;EACrB;;qBAOW,iBAAiB;EAC5B,yBACE,SAAS,yBACT,KAAK,2BACF;EACL,yBAAyB,KAAK,2BAA2B;EACzD,aAAa,KAAK,2BAA2B"}
@@ -0,0 +1,4 @@
1
+ import { t as workflowsPlugin } from "../workflows-qKtqZhn3.mjs";
2
+ export { workflowsPlugin as default, workflowsPlugin };
3
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="ec591584-f4a2-5205-ae5e-deecdc2af277")}catch(e){}}();
4
+ //# debugId=ec591584-f4a2-5205-ae5e-deecdc2af277
@@ -0,0 +1,113 @@
1
+
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="ff8496aa-7c16-5960-8a4d-9f5b6fd3e74d")}catch(e){}}();
3
+ import { AuthorizationPolicy, PrivacyPermissionAdapter } from "@powerhousedao/reactor-api";
4
+ import { DisclosureService, MIN_DEPLOYMENT_SECRET_BYTES, createModuleErasure, createPrivacySubgraph, registerSubjectDocumentsReadModel } from "@powerhousedao/reactor-privacy";
5
+ //#region src/privacy.mts
6
+ const DAY_MS = 864e5;
7
+ /** Enabling privacy on a switchboard that cannot run it safely. */
8
+ var PrivacyBootError = class extends Error {
9
+ constructor(message) {
10
+ super(message);
11
+ this.name = "PrivacyBootError";
12
+ }
13
+ };
14
+ function positive(env, name, unitMs) {
15
+ const raw = env[name];
16
+ if (raw === void 0 || raw.trim() === "") return void 0;
17
+ const value = Number(raw);
18
+ if (!Number.isFinite(value) || value <= 0) throw new PrivacyBootError(`${name} must be a positive number, got "${raw}"`);
19
+ return value * unitMs;
20
+ }
21
+ function resolvePrivacy(options, env) {
22
+ if (!(options?.enabled ?? env.PH_PRIVACY_ENABLED === "true")) return { enabled: false };
23
+ const deploymentSecret = options?.deploymentSecret ?? env.PH_PRIVACY_DEPLOYMENT_SECRET;
24
+ if (!deploymentSecret || Buffer.byteLength(deploymentSecret, "utf8") < MIN_DEPLOYMENT_SECRET_BYTES) throw new PrivacyBootError(`PH_PRIVACY_ENABLED needs PH_PRIVACY_DEPLOYMENT_SECRET of at least ${MIN_DEPLOYMENT_SECRET_BYTES} bytes`);
25
+ return {
26
+ enabled: true,
27
+ deploymentSecret,
28
+ intervalMs: positive(env, "PH_PRIVACY_INTERVAL_MS", 1),
29
+ deadlineMs: positive(env, "PH_PRIVACY_DEADLINE_DAYS", DAY_MS),
30
+ markerGraceMs: positive(env, "PH_PRIVACY_MARKER_GRACE_DAYS", DAY_MS),
31
+ purgeTimeoutMs: positive(env, "PH_PRIVACY_PURGE_TIMEOUT_MINUTES", 6e4)
32
+ };
33
+ }
34
+ /** Subject index, erasure scheduler and admin subgraph on a built reactor. */
35
+ async function startPrivacy(deps) {
36
+ const { config, reactorModule, authorizationService } = deps;
37
+ if (authorizationService.config.policy === AuthorizationPolicy.OPEN) throw new PrivacyBootError("PH_PRIVACY_ENABLED is refused under the OPEN authorization policy: every caller, anonymous included, would administer erasure. Enable authentication (AUTH_ENABLED=true with ADMINS) first.");
38
+ if (!reactorModule) throw new PrivacyBootError("PH_PRIVACY_ENABLED needs an in-process reactor module");
39
+ if (!deps.signer?.app?.key) throw new PrivacyBootError("PH_PRIVACY_ENABLED needs a reactor signer (a Renown identity): every receiver refuses an unsigned purge marker");
40
+ const permissions = deps.documentPermissionService ? new PrivacyPermissionAdapter(deps.documentPermissionService) : void 0;
41
+ const { service, scheduler } = createModuleErasure(reactorModule, {
42
+ deploymentSecret: config.deploymentSecret,
43
+ signer: deps.signer,
44
+ permissions,
45
+ intervalMs: config.intervalMs,
46
+ deadlineMs: config.deadlineMs,
47
+ markerGraceMs: config.markerGraceMs,
48
+ purgeTimeoutMs: config.purgeTimeoutMs,
49
+ logger: deps.logger
50
+ });
51
+ const disclosure = new DisclosureService(reactorModule.database, config.deploymentSecret, permissions);
52
+ let subgraph;
53
+ try {
54
+ subgraph = createPrivacySubgraph({
55
+ authorizationService,
56
+ erasure: service,
57
+ disclosure
58
+ });
59
+ } catch (error) {
60
+ throw new PrivacyBootError(error instanceof Error ? error.message : String(error));
61
+ }
62
+ await registerSubjectDocumentsReadModel(reactorModule, { deploymentSecret: config.deploymentSecret });
63
+ await deps.graphqlManager.registerSubgraphInstance({
64
+ ...subgraph,
65
+ path: deps.graphqlManager.getBasePath(),
66
+ reactorClient: deps.reactorClient,
67
+ relationalDb: void 0
68
+ }, "graphql", false);
69
+ scheduler.start();
70
+ deps.logger.info("Privacy add-on started: subject index, erasure scheduler");
71
+ return {
72
+ erasure: service,
73
+ scheduler,
74
+ stop: () => scheduler.stop()
75
+ };
76
+ }
77
+ //#endregion
78
+ //#region src/plugins/privacy.mts
79
+ const privacyPlugin = {
80
+ name: "switchboard-privacy",
81
+ appliesTo: "switchboard",
82
+ hooks: {
83
+ transformServerOptions: (options, ctx) => {
84
+ ctx.privacyConfig = resolvePrivacy(options.privacy, process.env);
85
+ return options;
86
+ },
87
+ onSubgraphsRegistering: async (ctx) => {
88
+ const config = ctx.privacyConfig;
89
+ if (!config.enabled) return;
90
+ const options = ctx.options;
91
+ const signer = options.reactor ? options.privacy?.signer : options.privacy?.signer ?? ctx.renown?.signer;
92
+ const api = ctx.api;
93
+ ctx.privacy = await startPrivacy({
94
+ config,
95
+ reactorModule: ctx.reactorClientModule?.reactorModule,
96
+ signer,
97
+ authorizationService: api.authorizationService,
98
+ documentPermissionService: api.documentPermissionService,
99
+ graphqlManager: ctx.graphqlManager,
100
+ reactorClient: ctx.client,
101
+ logger: ctx.logger.child(["privacy"])
102
+ });
103
+ },
104
+ onShutdown: async (ctx) => {
105
+ await ctx.privacy?.stop();
106
+ }
107
+ }
108
+ };
109
+ //#endregion
110
+ export { resolvePrivacy as n, startPrivacy as r, privacyPlugin as t };
111
+
112
+ //# sourceMappingURL=privacy-C8KVimKF.mjs.map
113
+ //# debugId=ff8496aa-7c16-5960-8a4d-9f5b6fd3e74d
@@ -0,0 +1 @@
1
+ {"version":3,"file":"privacy-C8KVimKF.mjs","sources":["../src/privacy.mts","../src/plugins/privacy.mts"],"sourcesContent":["import type {\n InProcessReactorModule,\n IReactorClient,\n} from \"@powerhousedao/reactor\";\nimport {\n AuthorizationPolicy,\n PrivacyPermissionAdapter,\n type DocumentPermissionService,\n type GraphQLManager,\n type IAuthorizationService,\n} from \"@powerhousedao/reactor-api\";\nimport {\n createModuleErasure,\n createPrivacySubgraph,\n DisclosureService,\n MIN_DEPLOYMENT_SECRET_BYTES,\n registerSubjectDocumentsReadModel,\n type ErasureScheduler,\n type IErasureService,\n} from \"@powerhousedao/reactor-privacy\";\nimport type { ISigner } from \"@powerhousedao/shared/document-model\";\nimport type { ILogger } from \"document-model\";\n\nconst DAY_MS = 24 * 60 * 60 * 1000;\n\nexport type PrivacyOptions = {\n /** Wins over PH_PRIVACY_ENABLED. */\n enabled?: boolean;\n /** Wins over PH_PRIVACY_DEPLOYMENT_SECRET. */\n deploymentSecret?: string;\n /** The reactor's signer, for a caller-provided reactor. */\n signer?: ISigner;\n};\n\nexport type ResolvedPrivacy =\n | { enabled: false }\n | {\n enabled: true;\n deploymentSecret: string;\n intervalMs?: number;\n deadlineMs?: number;\n markerGraceMs?: number;\n purgeTimeoutMs?: number;\n };\n\n/** Enabling privacy on a switchboard that cannot run it safely. */\nexport class PrivacyBootError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"PrivacyBootError\";\n }\n}\n\nfunction positive(\n env: NodeJS.ProcessEnv,\n name: string,\n unitMs: number,\n): number | undefined {\n const raw = env[name];\n if (raw === undefined || raw.trim() === \"\") return undefined;\n const value = Number(raw);\n if (!Number.isFinite(value) || value <= 0) {\n throw new PrivacyBootError(\n `${name} must be a positive number, got \"${raw}\"`,\n );\n }\n return value * unitMs;\n}\n\nexport function resolvePrivacy(\n options: PrivacyOptions | undefined,\n env: NodeJS.ProcessEnv,\n): ResolvedPrivacy {\n const enabled = options?.enabled ?? env.PH_PRIVACY_ENABLED === \"true\";\n if (!enabled) return { enabled: false };\n const deploymentSecret =\n options?.deploymentSecret ?? env.PH_PRIVACY_DEPLOYMENT_SECRET;\n if (\n !deploymentSecret ||\n Buffer.byteLength(deploymentSecret, \"utf8\") < MIN_DEPLOYMENT_SECRET_BYTES\n ) {\n throw new PrivacyBootError(\n `PH_PRIVACY_ENABLED needs PH_PRIVACY_DEPLOYMENT_SECRET of at least ${MIN_DEPLOYMENT_SECRET_BYTES} bytes`,\n );\n }\n return {\n enabled: true,\n deploymentSecret,\n intervalMs: positive(env, \"PH_PRIVACY_INTERVAL_MS\", 1),\n deadlineMs: positive(env, \"PH_PRIVACY_DEADLINE_DAYS\", DAY_MS),\n markerGraceMs: positive(env, \"PH_PRIVACY_MARKER_GRACE_DAYS\", DAY_MS),\n purgeTimeoutMs: positive(env, \"PH_PRIVACY_PURGE_TIMEOUT_MINUTES\", 60_000),\n };\n}\n\nexport type RunningPrivacy = {\n erasure: IErasureService;\n scheduler: ErasureScheduler;\n stop(): Promise<void>;\n};\n\n/** Subject index, erasure scheduler and admin subgraph on a built reactor. */\nexport async function startPrivacy(deps: {\n config: Extract<ResolvedPrivacy, { enabled: true }>;\n reactorModule: InProcessReactorModule | undefined;\n signer: ISigner | undefined;\n authorizationService: IAuthorizationService;\n documentPermissionService: DocumentPermissionService | undefined;\n graphqlManager: GraphQLManager;\n reactorClient: IReactorClient;\n logger: ILogger;\n}): Promise<RunningPrivacy> {\n const { config, reactorModule, authorizationService } = deps;\n if (authorizationService.config.policy === AuthorizationPolicy.OPEN) {\n throw new PrivacyBootError(\n \"PH_PRIVACY_ENABLED is refused under the OPEN authorization policy: every caller, anonymous included, would administer erasure. Enable authentication (AUTH_ENABLED=true with ADMINS) first.\",\n );\n }\n if (!reactorModule) {\n throw new PrivacyBootError(\n \"PH_PRIVACY_ENABLED needs an in-process reactor module\",\n );\n }\n if (!deps.signer?.app?.key) {\n throw new PrivacyBootError(\n \"PH_PRIVACY_ENABLED needs a reactor signer (a Renown identity): every receiver refuses an unsigned purge marker\",\n );\n }\n\n const permissions = deps.documentPermissionService\n ? new PrivacyPermissionAdapter(deps.documentPermissionService)\n : undefined;\n const { service, scheduler } = createModuleErasure(reactorModule, {\n deploymentSecret: config.deploymentSecret,\n signer: deps.signer,\n permissions,\n intervalMs: config.intervalMs,\n deadlineMs: config.deadlineMs,\n markerGraceMs: config.markerGraceMs,\n purgeTimeoutMs: config.purgeTimeoutMs,\n logger: deps.logger,\n });\n\n const disclosure = new DisclosureService(\n reactorModule.database,\n config.deploymentSecret,\n permissions,\n );\n let subgraph;\n try {\n subgraph = createPrivacySubgraph({\n authorizationService,\n erasure: service,\n disclosure,\n });\n } catch (error) {\n throw new PrivacyBootError(\n error instanceof Error ? error.message : String(error),\n );\n }\n\n await registerSubjectDocumentsReadModel(reactorModule, {\n deploymentSecret: config.deploymentSecret,\n });\n await deps.graphqlManager.registerSubgraphInstance(\n {\n ...subgraph,\n path: deps.graphqlManager.getBasePath(),\n reactorClient: deps.reactorClient,\n relationalDb: undefined as never,\n },\n \"graphql\",\n false,\n );\n\n scheduler.start();\n deps.logger.info(\"Privacy add-on started: subject index, erasure scheduler\");\n return {\n erasure: service,\n scheduler,\n stop: () => scheduler.stop(),\n };\n}\n","import type { IRenown } from \"@renown/sdk\";\nimport type { HostPlugin } from \"@powerhousedao/host-core\";\nimport type { ILogger } from \"document-model\";\nimport {\n resolvePrivacy,\n startPrivacy,\n type PrivacyOptions,\n type ResolvedPrivacy,\n type RunningPrivacy,\n} from \"../privacy.mjs\";\nimport type { SwitchboardHostContext } from \"../plugin-host.mjs\";\n\n/**\n * R2.4 — the privacy subsystem as a built-in plugin. Presence is activation\n * of the SUBSYSTEM; whether privacy enforcement runs still requires its\n * config (enabled + deploymentSecret — A SECRET, env-only:\n * PH_PRIVACY_DEPLOYMENT_SECRET never enters host files).\n *\n * Timing preserved from the inline path (carve map): config resolves EARLY at\n * transformServerOptions (a bad secret fails the boot before any resource\n * opens — same fail-fast property as the inline line-571 resolve); the mount\n * runs at onSubgraphsRegistering, whose server-side call site carries the\n * inline failure semantics (stop workflows, abortBoot, rethrow); teardown is\n * first in shutdown via onShutdown.\n */\n\ntype PrivacyCapableOptions = Record<string, unknown> & {\n privacy?: PrivacyOptions & { signer?: unknown };\n reactor?: unknown;\n};\n\nexport const privacyPlugin: HostPlugin<{\n transformServerOptions: (\n options: Record<string, unknown>,\n ctx: SwitchboardHostContext,\n ) => Record<string, unknown>;\n onSubgraphsRegistering: (ctx: SwitchboardHostContext) => Promise<void>;\n onShutdown: (ctx: SwitchboardHostContext) => Promise<void>;\n}> = {\n name: \"switchboard-privacy\",\n appliesTo: \"switchboard\",\n hooks: {\n transformServerOptions: (options, ctx) => {\n // Fail-fast resolve, before the reactor is built.\n ctx.privacyConfig = resolvePrivacy(\n (options as PrivacyCapableOptions).privacy,\n process.env,\n );\n return options;\n },\n onSubgraphsRegistering: async (ctx) => {\n const config = ctx.privacyConfig as ResolvedPrivacy;\n if (!config.enabled) return;\n const options = ctx.options as PrivacyCapableOptions;\n // The caller's reactor signs with a signer only the caller knows.\n const signer = options.reactor\n ? options.privacy?.signer\n : (options.privacy?.signer ?? (ctx.renown as IRenown | null)?.signer);\n const api = ctx.api as {\n authorizationService: never;\n documentPermissionService: never;\n };\n ctx.privacy = await startPrivacy({\n config,\n reactorModule: (\n ctx.reactorClientModule as { reactorModule?: never } | undefined\n )?.reactorModule,\n signer: signer as never,\n authorizationService: api.authorizationService,\n documentPermissionService: api.documentPermissionService,\n graphqlManager: ctx.graphqlManager as never,\n reactorClient: ctx.client as never,\n logger: (ctx.logger as ILogger).child([\"privacy\"]),\n });\n },\n onShutdown: async (ctx) => {\n await (ctx.privacy as RunningPrivacy | undefined)?.stop();\n },\n },\n};\n\n// resolveHostPlugins consumes the DEFAULT export (plugin object or factory).\nexport default privacyPlugin;\n"],"names":[],"mappings":";;;;;AAuBA,MAAM,SAAS;;AAuBf,IAAa,mBAAb,cAAsC,MAAM;CAC1C,YAAY,SAAiB;EAC3B,MAAM,OAAO;EACb,KAAK,OAAO;CACd;AACF;AAEA,SAAS,SACP,KACA,MACA,QACoB;CACpB,MAAM,MAAM,IAAI;CAChB,IAAI,QAAQ,KAAA,KAAa,IAAI,KAAK,MAAM,IAAI,OAAO,KAAA;CACnD,MAAM,QAAQ,OAAO,GAAG;CACxB,IAAI,CAAC,OAAO,SAAS,KAAK,KAAK,SAAS,GACtC,MAAM,IAAI,iBACR,G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