@powerhousedao/switchboard 6.2.3-dev.7 → 6.2.3-dev.70
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/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-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-inspection-enabled.test.d.ts +2 -0
- package/.tsbuild/test/boot-inspection-enabled.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-privacy.test.d.ts +2 -0
- package/.tsbuild/test/boot-privacy.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/create-signature-policy.test.d.ts +2 -0
- package/.tsbuild/test/create-signature-policy.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-flag.test.d.ts +2 -0
- package/.tsbuild/test/inspection-flag.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/mcp-flag.test.d.ts +2 -0
- package/.tsbuild/test/mcp-flag.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/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/plugin-presence.test.d.ts +2 -0
- package/.tsbuild/test/plugin-presence.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/snapshot-writer.d.ts +18 -0
- package/.tsbuild/test/snapshot-writer.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.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/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/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 +842 -0
- package/README.md +47 -10
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +50 -50
- 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-cNWW82NH.mjs +27 -0
- package/dist/mcp-cNWW82NH.mjs.map +1 -0
- package/dist/migrate.d.mts +2 -1
- package/dist/migrate.mjs +4 -3
- package/dist/migrate.mjs.map +1 -1
- package/dist/plugin-host-CGO4XZzK.d.mts +38 -0
- package/dist/plugin-host-CGO4XZzK.d.mts.map +1 -0
- package/dist/plugins/attachments.d.mts +23 -0
- package/dist/plugins/attachments.d.mts.map +1 -0
- package/dist/plugins/attachments.mjs +4 -0
- package/dist/plugins/mcp.d.mts +21 -0
- package/dist/plugins/mcp.d.mts.map +1 -0
- package/dist/plugins/mcp.mjs +4 -0
- package/dist/plugins/privacy.d.mts +12 -0
- package/dist/plugins/privacy.d.mts.map +1 -0
- package/dist/plugins/privacy.mjs +4 -0
- package/dist/plugins/workflows.d.mts +36 -0
- package/dist/plugins/workflows.d.mts.map +1 -0
- package/dist/plugins/workflows.mjs +4 -0
- package/dist/privacy-C8KVimKF.mjs +113 -0
- package/dist/privacy-C8KVimKF.mjs.map +1 -0
- package/dist/{server-CiKkVE6g.mjs → server-CF_mjyJi.mjs} +1170 -228
- package/dist/server-CF_mjyJi.mjs.map +1 -0
- package/dist/server.d.mts +190 -30
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +4 -5
- package/dist/{utils-Baw7rThP.mjs → utils-uaBlzyjS.mjs} +15 -9
- package/dist/utils-uaBlzyjS.mjs.map +1 -0
- package/dist/utils.d.mts +4 -5
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +3 -3
- package/dist/workflow-runtime-7GaJ13c9.d.mts +30 -0
- package/dist/workflow-runtime-7GaJ13c9.d.mts.map +1 -0
- package/dist/workflows-qKtqZhn3.mjs +1338 -0
- package/dist/workflows-qKtqZhn3.mjs.map +1 -0
- package/package.json +49 -20
- package/scripts/install-packages.sh +0 -0
- package/test/attachment-reference-read-model.test.ts +6 -1
- 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 +201 -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 +271 -24
- package/test/attachments/service-config.test.ts +13 -3
- package/test/attachments/url-signer.test.ts +105 -0
- package/test/boot-create-signature-policy.test.ts +108 -0
- package/test/boot-inspection-enabled.test.ts +150 -0
- package/test/boot-mcp-enabled.test.ts +130 -0
- package/test/boot-privacy.test.ts +243 -0
- package/test/boot-unsupported-stored-documents.test.ts +213 -0
- package/test/boot-without-renown.test.ts +81 -0
- package/test/boot-without-require-signatures.test.ts +74 -0
- package/test/boot-worker-trust-policy.test.ts +90 -0
- package/test/boot-workflow-singleton-conflict.test.ts +107 -0
- package/test/boot-workflow-singleton-retry.test.ts +133 -0
- package/test/builder-defaults.test.ts +80 -0
- package/test/create-signature-policy.test.ts +69 -0
- package/test/durable-node-fs-pg16.test.ts +80 -0
- package/test/fatal-shutdown.test.ts +165 -0
- package/test/inspection-flag.test.ts +62 -0
- package/test/inspection-throttle.test.ts +23 -0
- package/test/mcp-flag.test.ts +56 -0
- package/test/observability-signals.test.ts +131 -0
- package/test/pglite-dialect.test.ts +217 -2
- package/test/pglite-preflight.test.ts +313 -0
- package/test/pglite-storage-dirs.test.ts +103 -0
- package/test/pglite-version.test.ts +9 -1
- package/test/plugin-presence.test.ts +269 -0
- package/test/renown-trust-policy.test.ts +315 -0
- package/test/snapshot-writer.ts +94 -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.test.ts +214 -0
- package/test/workflow/resolvers.test.ts +357 -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 +1122 -0
- package/tsconfig.json +11 -2
- package/tsdown.config.ts +9 -1
- package/dist/server-CiKkVE6g.mjs.map +0 -1
- package/dist/utils-Baw7rThP.mjs.map +0 -1
|
@@ -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":"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","debug_id":"ff8496aa-7c16-5960-8a4d-9f5b6fd3e74d"}
|