@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.
Files changed (312) hide show
  1. package/.tsbuild/test/ai-gateway.test.d.ts +2 -0
  2. package/.tsbuild/test/ai-gateway.test.d.ts.map +1 -0
  3. package/.tsbuild/test/attachments/byte-grants.test.d.ts +2 -0
  4. package/.tsbuild/test/attachments/byte-grants.test.d.ts.map +1 -0
  5. package/.tsbuild/test/attachments/byte-routes-read-gate.integration.test.d.ts +2 -0
  6. package/.tsbuild/test/attachments/byte-routes-read-gate.integration.test.d.ts.map +1 -0
  7. package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts +2 -0
  8. package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts.map +1 -0
  9. package/.tsbuild/test/attachments/url-signer.test.d.ts +2 -0
  10. package/.tsbuild/test/attachments/url-signer.test.d.ts.map +1 -0
  11. package/.tsbuild/test/boot-auth-config.test.d.ts +2 -0
  12. package/.tsbuild/test/boot-auth-config.test.d.ts.map +1 -0
  13. package/.tsbuild/test/boot-create-signature-policy.test.d.ts +2 -0
  14. package/.tsbuild/test/boot-create-signature-policy.test.d.ts.map +1 -0
  15. package/.tsbuild/test/boot-desktop-auth.test.d.ts +2 -0
  16. package/.tsbuild/test/boot-desktop-auth.test.d.ts.map +1 -0
  17. package/.tsbuild/test/boot-env-isolation.test.d.ts +2 -0
  18. package/.tsbuild/test/boot-env-isolation.test.d.ts.map +1 -0
  19. package/.tsbuild/test/boot-helpers.d.ts +5 -0
  20. package/.tsbuild/test/boot-helpers.d.ts.map +1 -0
  21. package/.tsbuild/test/boot-inspection-enabled.test.d.ts +2 -0
  22. package/.tsbuild/test/boot-inspection-enabled.test.d.ts.map +1 -0
  23. package/.tsbuild/test/boot-mcp-auth.test.d.ts +2 -0
  24. package/.tsbuild/test/boot-mcp-auth.test.d.ts.map +1 -0
  25. package/.tsbuild/test/boot-mcp-enabled.test.d.ts +2 -0
  26. package/.tsbuild/test/boot-mcp-enabled.test.d.ts.map +1 -0
  27. package/.tsbuild/test/boot-port-zero.test.d.ts +2 -0
  28. package/.tsbuild/test/boot-port-zero.test.d.ts.map +1 -0
  29. package/.tsbuild/test/boot-preconditions.test.d.ts +2 -0
  30. package/.tsbuild/test/boot-preconditions.test.d.ts.map +1 -0
  31. package/.tsbuild/test/boot-privacy.test.d.ts +2 -0
  32. package/.tsbuild/test/boot-privacy.test.d.ts.map +1 -0
  33. package/.tsbuild/test/boot-ready-drives.test.d.ts +2 -0
  34. package/.tsbuild/test/boot-ready-drives.test.d.ts.map +1 -0
  35. package/.tsbuild/test/boot-undo-v3-flag.test.d.ts +2 -0
  36. package/.tsbuild/test/boot-undo-v3-flag.test.d.ts.map +1 -0
  37. package/.tsbuild/test/boot-unsupported-stored-documents.test.d.ts +2 -0
  38. package/.tsbuild/test/boot-unsupported-stored-documents.test.d.ts.map +1 -0
  39. package/.tsbuild/test/boot-without-renown.test.d.ts +2 -0
  40. package/.tsbuild/test/boot-without-renown.test.d.ts.map +1 -0
  41. package/.tsbuild/test/boot-without-require-signatures.test.d.ts +2 -0
  42. package/.tsbuild/test/boot-without-require-signatures.test.d.ts.map +1 -0
  43. package/.tsbuild/test/boot-worker-trust-policy.test.d.ts +2 -0
  44. package/.tsbuild/test/boot-worker-trust-policy.test.d.ts.map +1 -0
  45. package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts +2 -0
  46. package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts.map +1 -0
  47. package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts +2 -0
  48. package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts.map +1 -0
  49. package/.tsbuild/test/builder-defaults.test.d.ts +2 -0
  50. package/.tsbuild/test/builder-defaults.test.d.ts.map +1 -0
  51. package/.tsbuild/test/config-from-env.test.d.ts +2 -0
  52. package/.tsbuild/test/config-from-env.test.d.ts.map +1 -0
  53. package/.tsbuild/test/config-merge.test.d.ts +2 -0
  54. package/.tsbuild/test/config-merge.test.d.ts.map +1 -0
  55. package/.tsbuild/test/config-schema.test.d.ts +2 -0
  56. package/.tsbuild/test/config-schema.test.d.ts.map +1 -0
  57. package/.tsbuild/test/create-signature-policy.test.d.ts +2 -0
  58. package/.tsbuild/test/create-signature-policy.test.d.ts.map +1 -0
  59. package/.tsbuild/test/default-drive-protocol-versions.test.d.ts +2 -0
  60. package/.tsbuild/test/default-drive-protocol-versions.test.d.ts.map +1 -0
  61. package/.tsbuild/test/default-drive-slug.test.d.ts +2 -0
  62. package/.tsbuild/test/default-drive-slug.test.d.ts.map +1 -0
  63. package/.tsbuild/test/delegated-publish.test.d.ts +2 -0
  64. package/.tsbuild/test/delegated-publish.test.d.ts.map +1 -0
  65. package/.tsbuild/test/durable-node-fs-pg16.test.d.ts +2 -0
  66. package/.tsbuild/test/durable-node-fs-pg16.test.d.ts.map +1 -0
  67. package/.tsbuild/test/fatal-shutdown.test.d.ts +2 -0
  68. package/.tsbuild/test/fatal-shutdown.test.d.ts.map +1 -0
  69. package/.tsbuild/test/inspection-throttle.test.d.ts +2 -0
  70. package/.tsbuild/test/inspection-throttle.test.d.ts.map +1 -0
  71. package/.tsbuild/test/keyframe-reclaim-store.test.d.ts +2 -0
  72. package/.tsbuild/test/keyframe-reclaim-store.test.d.ts.map +1 -0
  73. package/.tsbuild/test/observability-signals.test.d.ts +2 -0
  74. package/.tsbuild/test/observability-signals.test.d.ts.map +1 -0
  75. package/.tsbuild/test/permissions-backfill.test.d.ts +2 -0
  76. package/.tsbuild/test/permissions-backfill.test.d.ts.map +1 -0
  77. package/.tsbuild/test/pglite-preflight.test.d.ts +2 -0
  78. package/.tsbuild/test/pglite-preflight.test.d.ts.map +1 -0
  79. package/.tsbuild/test/pglite-storage-dirs.test.d.ts +2 -0
  80. package/.tsbuild/test/pglite-storage-dirs.test.d.ts.map +1 -0
  81. package/.tsbuild/test/pglite-store.test.d.ts +2 -0
  82. package/.tsbuild/test/pglite-store.test.d.ts.map +1 -0
  83. package/.tsbuild/test/plugin-config-schemas.test.d.ts +2 -0
  84. package/.tsbuild/test/plugin-config-schemas.test.d.ts.map +1 -0
  85. package/.tsbuild/test/plugin-presence.test.d.ts +2 -0
  86. package/.tsbuild/test/plugin-presence.test.d.ts.map +1 -0
  87. package/.tsbuild/test/port-probe.test.d.ts +2 -0
  88. package/.tsbuild/test/port-probe.test.d.ts.map +1 -0
  89. package/.tsbuild/test/processor-timing-log.test.d.ts +2 -0
  90. package/.tsbuild/test/processor-timing-log.test.d.ts.map +1 -0
  91. package/.tsbuild/test/redact-webhook-path.test.d.ts +2 -0
  92. package/.tsbuild/test/redact-webhook-path.test.d.ts.map +1 -0
  93. package/.tsbuild/test/renown-storage-path.test.d.ts +2 -0
  94. package/.tsbuild/test/renown-storage-path.test.d.ts.map +1 -0
  95. package/.tsbuild/test/renown-trust-policy.test.d.ts +2 -0
  96. package/.tsbuild/test/renown-trust-policy.test.d.ts.map +1 -0
  97. package/.tsbuild/test/served-schemas.test.d.ts +2 -0
  98. package/.tsbuild/test/served-schemas.test.d.ts.map +1 -0
  99. package/.tsbuild/test/shutdown.test.d.ts +2 -0
  100. package/.tsbuild/test/shutdown.test.d.ts.map +1 -0
  101. package/.tsbuild/test/snapshot-writer.d.ts +18 -0
  102. package/.tsbuild/test/snapshot-writer.d.ts.map +1 -0
  103. package/.tsbuild/test/store-lock.test.d.ts +2 -0
  104. package/.tsbuild/test/store-lock.test.d.ts.map +1 -0
  105. package/.tsbuild/test/two-switchboards.test.d.ts +2 -0
  106. package/.tsbuild/test/two-switchboards.test.d.ts.map +1 -0
  107. package/.tsbuild/test/unsupported-stored-documents.test.d.ts +2 -0
  108. package/.tsbuild/test/unsupported-stored-documents.test.d.ts.map +1 -0
  109. package/.tsbuild/test/workflow/harness.d.ts +56 -0
  110. package/.tsbuild/test/workflow/harness.d.ts.map +1 -0
  111. package/.tsbuild/test/workflow/oauth-apps-config.test.d.ts +2 -0
  112. package/.tsbuild/test/workflow/oauth-apps-config.test.d.ts.map +1 -0
  113. package/.tsbuild/test/workflow/oauth.test.d.ts +2 -0
  114. package/.tsbuild/test/workflow/oauth.test.d.ts.map +1 -0
  115. package/.tsbuild/test/workflow/resolvers.test.d.ts +2 -0
  116. package/.tsbuild/test/workflow/resolvers.test.d.ts.map +1 -0
  117. package/.tsbuild/test/workflow/runtime-host.test.d.ts +2 -0
  118. package/.tsbuild/test/workflow/runtime-host.test.d.ts.map +1 -0
  119. package/.tsbuild/test/workflow/waitpoint-routes.test.d.ts +2 -0
  120. package/.tsbuild/test/workflow/waitpoint-routes.test.d.ts.map +1 -0
  121. package/.tsbuild/test/workflow/waitpoint-runtime.test.d.ts +2 -0
  122. package/.tsbuild/test/workflow/waitpoint-runtime.test.d.ts.map +1 -0
  123. package/.tsbuild/test/workflow/webhook-dedupe.test.d.ts +2 -0
  124. package/.tsbuild/test/workflow/webhook-dedupe.test.d.ts.map +1 -0
  125. package/.tsbuild/test/workflow/webhook-signed.test.d.ts +2 -0
  126. package/.tsbuild/test/workflow/webhook-signed.test.d.ts.map +1 -0
  127. package/.tsbuild/test/workflow/webhook-trigger-test.test.d.ts +2 -0
  128. package/.tsbuild/test/workflow/webhook-trigger-test.test.d.ts.map +1 -0
  129. package/.tsbuild/test/workflow/webhook-unsigned.test.d.ts +2 -0
  130. package/.tsbuild/test/workflow/webhook-unsigned.test.d.ts.map +1 -0
  131. package/.tsbuild/test/workflow-reactor-access.test.d.ts +2 -0
  132. package/.tsbuild/test/workflow-reactor-access.test.d.ts.map +1 -0
  133. package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts +2 -0
  134. package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts.map +1 -0
  135. package/.tsbuild/test/workflow-read-gate.test.d.ts +2 -0
  136. package/.tsbuild/test/workflow-read-gate.test.d.ts.map +1 -0
  137. package/.tsbuild/test/workflow-runtime.test.d.ts +2 -0
  138. package/.tsbuild/test/workflow-runtime.test.d.ts.map +1 -0
  139. package/.tsbuild/test/workflows-plugin-config.test.d.ts +2 -0
  140. package/.tsbuild/test/workflows-plugin-config.test.d.ts.map +1 -0
  141. package/.tsbuild/tsconfig.tsbuildinfo +1 -1
  142. package/.tsbuild/tsdown.config.d.ts.map +1 -1
  143. package/.tsbuild/vitest.config.d.ts.map +1 -1
  144. package/Auth.md +144 -2
  145. package/CHANGELOG.md +1356 -0
  146. package/README.md +102 -22
  147. package/dist/boot.d.mts +46 -0
  148. package/dist/boot.d.mts.map +1 -0
  149. package/dist/boot.mjs +67 -0
  150. package/dist/boot.mjs.map +1 -0
  151. package/dist/config/from-env.d.mts +15 -0
  152. package/dist/config/from-env.d.mts.map +1 -0
  153. package/dist/config/from-env.mjs +4 -0
  154. package/dist/config/schema.d.mts +3 -0
  155. package/dist/config/schema.mjs +4 -0
  156. package/dist/from-env-FH4fPeIE.mjs +481 -0
  157. package/dist/from-env-FH4fPeIE.mjs.map +1 -0
  158. package/dist/index.d.mts +2 -1
  159. package/dist/index.mjs +98 -80
  160. package/dist/index.mjs.map +1 -1
  161. package/dist/install-packages.d.mts +2 -1
  162. package/dist/install-packages.mjs +2 -2
  163. package/dist/install-packages.mjs.map +1 -1
  164. package/dist/mcp-SsBK14Jm.mjs +32 -0
  165. package/dist/mcp-SsBK14Jm.mjs.map +1 -0
  166. package/dist/migrate.d.mts +2 -1
  167. package/dist/migrate.mjs +7 -5
  168. package/dist/migrate.mjs.map +1 -1
  169. package/dist/plugin-host-CK9_tVak.d.mts +46 -0
  170. package/dist/plugin-host-CK9_tVak.d.mts.map +1 -0
  171. package/dist/plugins/ai.d.mts +37 -0
  172. package/dist/plugins/ai.d.mts.map +1 -0
  173. package/dist/plugins/ai.mjs +400 -0
  174. package/dist/plugins/ai.mjs.map +1 -0
  175. package/dist/plugins/attachments.d.mts +33 -0
  176. package/dist/plugins/attachments.d.mts.map +1 -0
  177. package/dist/plugins/attachments.mjs +4 -0
  178. package/dist/plugins/mcp.d.mts +31 -0
  179. package/dist/plugins/mcp.d.mts.map +1 -0
  180. package/dist/plugins/mcp.mjs +4 -0
  181. package/dist/plugins/privacy.d.mts +22 -0
  182. package/dist/plugins/privacy.d.mts.map +1 -0
  183. package/dist/plugins/privacy.mjs +4 -0
  184. package/dist/plugins/workflows.d.mts +79 -0
  185. package/dist/plugins/workflows.d.mts.map +1 -0
  186. package/dist/plugins/workflows.mjs +4 -0
  187. package/dist/postgres-url-DTDhBjXX.mjs +11 -0
  188. package/dist/postgres-url-DTDhBjXX.mjs.map +1 -0
  189. package/dist/privacy-BO8Q25xI.mjs +44 -0
  190. package/dist/privacy-BO8Q25xI.mjs.map +1 -0
  191. package/dist/privacy-DxIJGH4P.mjs +91 -0
  192. package/dist/privacy-DxIJGH4P.mjs.map +1 -0
  193. package/dist/renown-layers-DmbWLt46.mjs +42 -0
  194. package/dist/renown-layers-DmbWLt46.mjs.map +1 -0
  195. package/dist/schema-CsY8bjsu.mjs +329 -0
  196. package/dist/schema-CsY8bjsu.mjs.map +1 -0
  197. package/dist/schema-MAUTnmj1.d.mts +251 -0
  198. package/dist/schema-MAUTnmj1.d.mts.map +1 -0
  199. package/dist/server-CirQ9hyu.mjs +2732 -0
  200. package/dist/server-CirQ9hyu.mjs.map +1 -0
  201. package/dist/server.d.mts +129 -189
  202. package/dist/server.d.mts.map +1 -1
  203. package/dist/server.mjs +5 -5
  204. package/dist/types-CidZdkhU.d.mts +314 -0
  205. package/dist/types-CidZdkhU.d.mts.map +1 -0
  206. package/dist/utils-Cm0TE6dP.mjs +148 -0
  207. package/dist/utils-Cm0TE6dP.mjs.map +1 -0
  208. package/dist/utils.d.mts +30 -5
  209. package/dist/utils.d.mts.map +1 -1
  210. package/dist/utils.mjs +5 -4
  211. package/dist/worker-pool-gyxJnCxA.mjs +304 -0
  212. package/dist/worker-pool-gyxJnCxA.mjs.map +1 -0
  213. package/dist/workflow-runtime-CF5pc8mt.d.mts +33 -0
  214. package/dist/workflow-runtime-CF5pc8mt.d.mts.map +1 -0
  215. package/dist/workflows-C9BQlyT0.mjs +1943 -0
  216. package/dist/workflows-C9BQlyT0.mjs.map +1 -0
  217. package/package.json +85 -24
  218. package/scripts/install-packages.sh +0 -0
  219. package/test/ai-gateway.test.ts +612 -0
  220. package/test/attachment-reference-read-model.test.ts +28 -20
  221. package/test/attachments/auth.test.ts +85 -0
  222. package/test/attachments/byte-grants.test.ts +290 -0
  223. package/test/attachments/byte-routes-read-gate.integration.test.ts +314 -0
  224. package/test/attachments/download-target.test.ts +211 -32
  225. package/test/attachments/index.test.ts +47 -4
  226. package/test/attachments/reserve-metadata-parity.test.ts +96 -0
  227. package/test/attachments/routes-integration.test.ts +60 -4
  228. package/test/attachments/routes.test.ts +297 -35
  229. package/test/attachments/service-config.test.ts +41 -19
  230. package/test/attachments/url-signer.test.ts +105 -0
  231. package/test/boot-auth-config.test.ts +109 -0
  232. package/test/boot-create-signature-policy.test.ts +110 -0
  233. package/test/boot-desktop-auth.test.ts +278 -0
  234. package/test/boot-env-isolation.test.ts +26 -0
  235. package/test/boot-helpers.ts +19 -0
  236. package/test/boot-inspection-enabled.test.ts +140 -0
  237. package/test/boot-mcp-auth.test.ts +449 -0
  238. package/test/boot-mcp-enabled.test.ts +119 -0
  239. package/test/boot-port-zero.test.ts +101 -0
  240. package/test/boot-preconditions.test.ts +213 -0
  241. package/test/boot-privacy.test.ts +232 -0
  242. package/test/boot-ready-drives.test.ts +141 -0
  243. package/test/boot-undo-v3-flag.test.ts +120 -0
  244. package/test/boot-unsupported-stored-documents.test.ts +214 -0
  245. package/test/boot-without-renown.test.ts +83 -0
  246. package/test/boot-without-require-signatures.test.ts +76 -0
  247. package/test/boot-worker-trust-policy.test.ts +91 -0
  248. package/test/boot-workflow-singleton-conflict.test.ts +109 -0
  249. package/test/boot-workflow-singleton-retry.test.ts +122 -0
  250. package/test/builder-defaults.test.ts +80 -0
  251. package/test/config-from-env.test.ts +963 -0
  252. package/test/config-merge.test.ts +248 -0
  253. package/test/config-schema.test.ts +167 -0
  254. package/test/create-signature-policy.test.ts +69 -0
  255. package/test/default-drive-protocol-versions.test.ts +79 -0
  256. package/test/default-drive-slug.test.ts +265 -0
  257. package/test/delegated-publish.test.ts +435 -0
  258. package/test/durable-node-fs-pg16.test.ts +80 -0
  259. package/test/fatal-shutdown.test.ts +205 -0
  260. package/test/goldens/packages.graphql +797 -0
  261. package/test/goldens/privacy.graphql +853 -0
  262. package/test/goldens/reactor-drive-nodes.graphql +827 -0
  263. package/test/goldens/resolvers.json +327 -0
  264. package/test/goldens/supergraph.graphql +5918 -0
  265. package/test/goldens/workflow-runtime.graphql +1548 -0
  266. package/test/inspection-throttle.test.ts +23 -0
  267. package/test/keyframe-reclaim-store.test.ts +156 -0
  268. package/test/observability-signals.test.ts +131 -0
  269. package/test/permissions-backfill.test.ts +486 -0
  270. package/test/pglite-dialect.test.ts +237 -2
  271. package/test/pglite-preflight.test.ts +313 -0
  272. package/test/pglite-storage-dirs.test.ts +113 -0
  273. package/test/pglite-store.test.ts +441 -0
  274. package/test/pglite-version.test.ts +9 -1
  275. package/test/plugin-config-schemas.test.ts +83 -0
  276. package/test/plugin-presence.test.ts +262 -0
  277. package/test/port-probe.test.ts +45 -0
  278. package/test/processor-timing-log.test.ts +109 -0
  279. package/test/reactor-feature-flags.test.ts +20 -0
  280. package/test/redact-webhook-path.test.ts +62 -0
  281. package/test/renown-storage-path.test.ts +40 -0
  282. package/test/renown-trust-policy.test.ts +313 -0
  283. package/test/served-schemas.test.ts +134 -0
  284. package/test/shutdown.test.ts +278 -0
  285. package/test/snapshot-writer.ts +94 -0
  286. package/test/store-lock.test.ts +65 -0
  287. package/test/two-switchboards.test.ts +146 -0
  288. package/test/unsupported-stored-documents.test.ts +72 -0
  289. package/test/worker-pool.test.ts +27 -1
  290. package/test/workflow/harness.ts +289 -0
  291. package/test/workflow/oauth-apps-config.test.ts +66 -0
  292. package/test/workflow/oauth.test.ts +286 -0
  293. package/test/workflow/resolvers.test.ts +488 -0
  294. package/test/workflow/runtime-host.test.ts +19 -0
  295. package/test/workflow/waitpoint-routes.test.ts +306 -0
  296. package/test/workflow/waitpoint-runtime.test.ts +204 -0
  297. package/test/workflow/webhook-dedupe.test.ts +295 -0
  298. package/test/workflow/webhook-signed.test.ts +509 -0
  299. package/test/workflow/webhook-trigger-test.test.ts +82 -0
  300. package/test/workflow/webhook-unsigned.test.ts +345 -0
  301. package/test/workflow-reactor-access.test.ts +384 -0
  302. package/test/workflow-reactor-enforcement.test.ts +808 -0
  303. package/test/workflow-read-gate.test.ts +213 -0
  304. package/test/workflow-runtime.test.ts +1254 -0
  305. package/test/workflows-plugin-config.test.ts +77 -0
  306. package/tsconfig.json +11 -2
  307. package/tsdown.config.ts +13 -1
  308. package/vitest.config.ts +65 -0
  309. package/dist/server-B2r6AQ4Q.mjs +0 -1553
  310. package/dist/server-B2r6AQ4Q.mjs.map +0 -1
  311. package/dist/utils-Baw7rThP.mjs +0 -80
  312. package/dist/utils-Baw7rThP.mjs.map +0 -1
@@ -0,0 +1,314 @@
1
+ import { n as WorkflowTriggersCapability } from "./workflow-runtime-CF5pc8mt.mjs";
2
+ import { ILogger } from "document-model";
3
+ import { IInspector, IReactorClient, InProcessReactorClientModule, ModelManifestEntry, UnsupportedStoredDocuments } from "@powerhousedao/reactor";
4
+ import { AttachmentReferenceProjectionCapability, HostValidationMode } from "@powerhousedao/reactor-api";
5
+ import { ISigner } from "@powerhousedao/shared/document-model";
6
+ import { IErasureService } from "@powerhousedao/reactor-privacy";
7
+ import { IAttachmentService } from "@powerhousedao/reactor-attachments";
8
+ import { ResolvedPlugin } from "@powerhousedao/host-core";
9
+ import { DriveInput } from "@powerhousedao/shared/document-drive";
10
+ import { IRenown } from "@renown/sdk";
11
+ //#region src/privacy.d.mts
12
+ type PrivacyOptions = {
13
+ /** Wins over PH_PRIVACY_ENABLED. */
14
+ enabled?: boolean;
15
+ /** Wins over PH_PRIVACY_DEPLOYMENT_SECRET. */
16
+ deploymentSecret?: string;
17
+ /** The reactor's signer, for a caller-provided reactor. */
18
+ signer?: ISigner;
19
+ /** Each wins over its PH_PRIVACY_* env var. */
20
+ intervalMs?: number;
21
+ deadlineMs?: number;
22
+ markerGraceMs?: number;
23
+ purgeTimeoutMs?: number;
24
+ };
25
+ //#endregion
26
+ //#region src/types.d.ts
27
+ /**
28
+ * Drive container document type chosen for the boot-time default drive. The
29
+ * legacy `powerhouse/document-drive` keeps the existing behavior; the newer
30
+ * `powerhouse/reactor-drive` is wired through `ensureDrive` and
31
+ * uses the relationship-based child graph.
32
+ */
33
+ type SwitchboardDriveDocumentType = "powerhouse/document-drive" | "powerhouse/reactor-drive";
34
+ /** A {@link DriveInput} extended with the optional drive-container type. */
35
+ type SwitchboardDriveInput = DriveInput & {
36
+ documentType?: SwitchboardDriveDocumentType;
37
+ };
38
+ type StorageOptions = {
39
+ type: "filesystem" | "memory" | "postgres" | "browser";
40
+ filesystemPath?: string;
41
+ postgresUrl?: string;
42
+ };
43
+ type IdentityOptions = {
44
+ /** Path to the keypair file. Defaults to ~/.ph/keypair.json */
45
+ keypairPath?: string;
46
+ /**
47
+ * If true, won't start without an existing keypair.
48
+ * Use this to ensure the switchboard only runs with an authenticated identity.
49
+ */
50
+ requireExisting?: boolean;
51
+ /** Base url of the Renown instance to use */
52
+ baseUrl?: string;
53
+ };
54
+ /**
55
+ * The options view of a switchboard's config and deps: what plugins'
56
+ * `transformServerOptions` hook receives. `startSwitchboard` takes the
57
+ * config (`@powerhousedao/switchboard/config`) and {@link SwitchboardDeps}.
58
+ */
59
+ type StartServerOptions = {
60
+ /**
61
+ * Pre-built ReactorClientModule (typically from
62
+ * `@powerhousedao/reactor#ReactorClientBuilder.buildModule`). When set, the
63
+ * switchboard reuses the caller's reactor instead of building its own,
64
+ * and the caller owns the reactor's lifecycle. The API, GraphQL manager,
65
+ * MCP, attachments, package management subgraph, and registry HTTP loader
66
+ * are still configured around it.
67
+ *
68
+ * Lifecycle contract: switchboard does NOT wire itself into the caller's
69
+ * reactor shutdown. Callers must invoke `shutdown()` on the returned
70
+ * `SwitchboardReactor` from their own teardown (and SIGINT handlers) to
71
+ * drain `/graphql`, MCP, attachments, etc. Killing the caller's reactor
72
+ * alone will not release these resources.
73
+ *
74
+ * Setup contract: the reactor must have switchboard's expected wiring
75
+ * already applied — channel scheme, document models, signal handlers,
76
+ * etc. Use `applySwitchboardReactorDefaults` from this module to apply
77
+ * the same defaults switchboard uses internally; opt out of individual
78
+ * pieces as needed.
79
+ */
80
+ reactor?: InProcessReactorClientModule;
81
+ /**
82
+ * Route uncaught exceptions, and unhandled rejections nothing else listens
83
+ * for, through the reactor's SIGTERM shutdown, so PGlite stores are flushed
84
+ * before the process exits with code 1. Installed once the switchboard's own reactor is built;
85
+ * ignored when `reactor` is passed. For process entry points only, since
86
+ * it adds process-wide listeners.
87
+ */
88
+ fatalErrorShutdown?: boolean;
89
+ /**
90
+ * Install the owned reactor's SIGINT/SIGTERM handlers (default true).
91
+ * False when a supervisor owns the process exit (a `ph run` compound
92
+ * member): the reactor then stops only through `shutdown()`. Ignored with
93
+ * a caller-provided `reactor`.
94
+ */
95
+ signalHandlers?: boolean;
96
+ /**
97
+ * `/ready` waits for this too: drives the caller seeds after the server
98
+ * starts. A rejection leaves the server not ready.
99
+ */
100
+ readyAfter?: Promise<unknown>;
101
+ /**
102
+ * Registry URL for the HttpPackageLoader. Enables `PackagesSubgraph`
103
+ * (install/uninstall mutations) plus dynamic package resolution.
104
+ * Falls back to PH_REGISTRY_URL env, then `packageRegistryUrl` in the
105
+ * powerhouse config file.
106
+ */
107
+ registryUrl?: string;
108
+ configFile?: string;
109
+ /**
110
+ * 0 binds a port the OS picks, reported on the result's `port`: the only
111
+ * race-free choice when several instances start at once. A taken non-zero
112
+ * port falls back to the next free one, which another process can still
113
+ * claim between the probe and the bind.
114
+ */
115
+ port?: number;
116
+ /**
117
+ * If true, fail immediately when the requested port is in use instead of
118
+ * falling back to the next free port. Matches the semantics of Vite's
119
+ * `--strictPort` flag that flows through the `ph vetra` command.
120
+ */
121
+ strictPort?: boolean;
122
+ dev?: boolean;
123
+ dbPath?: string;
124
+ drive?: SwitchboardDriveInput;
125
+ packages?: string[];
126
+ remoteDrives?: string[];
127
+ https?: {
128
+ keyPath: string;
129
+ certPath: string;
130
+ } | boolean | undefined;
131
+ /**
132
+ * Identity options for Renown.
133
+ * When configured, the switchboard will load the keypair from `ph login`
134
+ * and can authenticate with remote services on behalf of the user.
135
+ */
136
+ identity?: IdentityOptions;
137
+ /** Base URL for the attachment service; defaults to `PH_SWITCHBOARD_PUBLIC_URL` then `http(s)://localhost:${port}`. */
138
+ attachmentServiceUrl?: string;
139
+ /** Mount the MCP server at `/mcp`. On by default; `false` wins over
140
+ * MCP_ENABLED, which can turn it off but never on. */
141
+ mcp?: boolean;
142
+ /** The plugin composition to boot with (FEATURE_PLUGIN_HOST_ENABLED): the
143
+ * resolved host.js runner.plugins entries, supplied by the uniform-runners
144
+ * switchboard runner (R2 step 2) or a test. Omitted = the built-in default
145
+ * composition. Resolved plugins, not specifiers — resolution happens at the
146
+ * runner against the PROJECT dependency tree. */
147
+ pluginComposition?: ResolvedPlugin[];
148
+ /** Mount the read-only inspection subgraph at `/graphql/inspection`. On by
149
+ * default; `false` wins over INSPECTION_ENABLED, which can turn it off. */
150
+ inspection?: boolean;
151
+ /** Open each PGlite store (reactor-storage, read-storage) in its own worker
152
+ * thread. Wins either way over PH_PGLITE_WORKERS; unset, the env var
153
+ * decides, then PGLITE_WORKERS_DEFAULT. */
154
+ pgliteWorkers?: boolean;
155
+ /** Powerhouse workflows: the runtime, its subgraph, its webhooks and its
156
+ * document models. Wins over PH_WORKFLOWS_ENABLED and the config file. */
157
+ workflows?: {
158
+ enabled?: boolean;
159
+ /** OAuth2 apps the publisher owns (`oauth_app` on a connection): per app,
160
+ * the provider's client files by kind. Wins over the config file's
161
+ * `workflows.oauthApps`; relative paths there are from the config file.
162
+ * `relay` is a token broker for the app's web client, used for a web
163
+ * sign-in when this host has no web client file: the provider needs only
164
+ * the broker's one redirect URI, and the secret stays with the broker. */
165
+ oauthApps?: {
166
+ id: string;
167
+ clients: {
168
+ desktop?: string;
169
+ web?: string;
170
+ };
171
+ relay?: {
172
+ clientId: string;
173
+ redirectUri: string;
174
+ tokenUrl: string;
175
+ };
176
+ }[];
177
+ };
178
+ /** The GDPR add-on; off unless this or PH_PRIVACY_ENABLED turns it on. */
179
+ privacy?: PrivacyOptions;
180
+ processorConfig?: Map<string, unknown>;
181
+ disableLocalPackages?: boolean;
182
+ enableDocumentModelSubgraphs?: boolean;
183
+ /**
184
+ * When true, enables dynamic loading of document models from the registry
185
+ * when an unknown document type is encountered during sync.
186
+ * Disabled by default — enable with DYNAMIC_MODEL_LOADING=true env var.
187
+ */
188
+ dynamicModelLoading?: boolean;
189
+ /**
190
+ * @experimental What the API does with a package model host validation
191
+ * reports a finding for: `log` (the default) serves it, `refuse` leaves it
192
+ * out of the served schema. Env: PH_HOST_VALIDATION.
193
+ */
194
+ hostValidation?: HostValidationMode;
195
+ logger?: ILogger;
196
+ /**
197
+ * When true, on startup any local PGLite data dirs whose `PG_VERSION` is
198
+ * older than the bundled PGLite are migrated to the current version
199
+ * (backup → dump → restore) before the server boots. When false, the
200
+ * server logs a warning and runs against the legacy data using the
201
+ * matching legacy PGLite module.
202
+ *
203
+ * Triggered by the `--migrate-pglite` CLI flag or `PH_MIGRATE_PGLITE=true`.
204
+ */
205
+ migratePglite?: boolean;
206
+ /**
207
+ * Force a specific PGLite-embedded PG major (16 or 17) on startup.
208
+ *
209
+ * **Destructive**: any existing local PGLite data dirs are wiped before
210
+ * the chosen PGLite re-`initdb`'s them at the requested version. Postgres
211
+ * URLs are unaffected. Takes precedence over `migratePglite`.
212
+ *
213
+ * Triggered by `PH_FORCE_PG_VERSION=16|17`.
214
+ */
215
+ forcePgVersion?: 16 | 17;
216
+ /**
217
+ * Executor worker pool: `numWorkers > 0` runs jobs in N worker threads;
218
+ * `"auto"` sizes the pool from the machine's available cores; 0 or unset
219
+ * keeps the in-process executor (the default). Unset fields fall back to
220
+ * the REACTOR_WORKERS / REACTOR_DB_* env vars. Requires a Postgres reactor
221
+ * database; incompatible with `dev` mode (Vite-loaded models cannot cross
222
+ * a thread boundary).
223
+ */
224
+ workerPool?: {
225
+ numWorkers?: number | "auto";
226
+ dbPoolSizePerWorker?: number;
227
+ acquireTimeoutMs?: number;
228
+ };
229
+ /**
230
+ * Projection worker: `enabled` runs the built-in document-view /
231
+ * document-indexer read models in one worker thread, off the host event
232
+ * loop; unset keeps them in-process (the default). Unset fields fall back
233
+ * to the REACTOR_PROJECTION_WORKER / REACTOR_DB_POOL_SIZE_PROJECTION env
234
+ * vars. Requires a Postgres reactor database and worker-importable
235
+ * document-model sources (switchboard resolves them itself); incompatible
236
+ * with `dev` mode (Vite-loaded models cannot cross a thread boundary).
237
+ */
238
+ projectionWorker?: {
239
+ enabled?: boolean;
240
+ dbPoolSize?: number;
241
+ };
242
+ /**
243
+ * Stored documents at protocol versions this build does not run: "refuse"
244
+ * (the default) fails the boot with a StoredDocumentsRefusedError;
245
+ * "read-only" starts with a warning and keeps those documents read-only.
246
+ * Unset falls back to the REACTOR_UNSUPPORTED_STORED_DOCUMENTS env var.
247
+ * Ignored when `reactor` is passed.
248
+ */
249
+ unsupportedStoredDocuments?: UnsupportedStoredDocuments;
250
+ };
251
+ /** What a switchboard is started with that is not a setting. */
252
+ type SwitchboardDeps = {
253
+ logger?: ILogger;
254
+ /** See {@link StartServerOptions.reactor}. */
255
+ reactor?: InProcessReactorClientModule;
256
+ /** See {@link StartServerOptions.pluginComposition}. */
257
+ pluginComposition?: ResolvedPlugin[];
258
+ /** Receives failures in background work; Sentry by default. */
259
+ reportError?: (error: unknown) => void;
260
+ /** See {@link StartServerOptions.fatalErrorShutdown}. */
261
+ fatalErrorShutdown?: boolean;
262
+ /** See {@link StartServerOptions.signalHandlers}. */
263
+ signalHandlers?: boolean;
264
+ /** See {@link StartServerOptions.readyAfter}. */
265
+ readyAfter?: Promise<unknown>;
266
+ /** The privacy add-on's signer, for a caller-provided reactor. */
267
+ privacySigner?: ISigner;
268
+ };
269
+ type SwitchboardReactor = {
270
+ defaultDriveUrl: string | undefined;
271
+ reactor: IReactorClient;
272
+ /** Switchboard-backed remote attachment service over its own `/attachments/*` API, for downstream consumers.
273
+ * Undefined when the attachments plugin is absent from the composition
274
+ * (FEATURE_PLUGIN_HOST_ENABLED — presence is activation, rewire R2.3). */
275
+ attachmentService: IAttachmentService | undefined;
276
+ /** Whether the authoritative attachment-reference projection is active. */
277
+ attachmentReferenceProjection: AttachmentReferenceProjectionCapability;
278
+ /** Whether the workflow runtime's operation intake is indexing. Undefined
279
+ * when workflows are off; unavailable means no document trigger fires. */
280
+ workflowTriggers?: WorkflowTriggersCapability;
281
+ /** Whether workflows are on, after the option, PH_WORKFLOWS_ENABLED and the config file. */
282
+ workflowsEnabled: boolean;
283
+ /** The boot list of importable models workers and workflow pieces load; empty when none are resolved. */
284
+ modelManifest(): ModelManifestEntry[];
285
+ /** Present when the privacy add-on runs: its erasure service. */
286
+ privacy?: {
287
+ erasure: IErasureService;
288
+ };
289
+ /** Whether `/mcp` is mounted, after the option and MCP_ENABLED. */
290
+ mcpEnabled: boolean;
291
+ /** Whether `/graphql/inspection` is mounted, after the option and INSPECTION_ENABLED. */
292
+ inspectionEnabled: boolean;
293
+ /** The reactor's inspector, as the host reads it (processors, catch-up); undefined without inspection. */
294
+ inspector: IInspector | undefined;
295
+ /** The Renown instance if identity was initialized */
296
+ renown: IRenown | null;
297
+ /**
298
+ * Port the HTTP server actually bound to: the OS-picked one when 0 was
299
+ * requested, the next free one when the requested port was in use.
300
+ */
301
+ port: number;
302
+ /**
303
+ * Idempotent. Owned reactor: runs the reactor module's memoized
304
+ * `shutdown()` (kill, shutdown hooks incl. the api drain, database).
305
+ * Caller-provided reactor: drains the api only (HTTP server, GraphQL
306
+ * manager, attachments, MCP, read-model DB); the caller owns the reactor
307
+ * and must call this from its own teardown.
308
+ */
309
+ shutdown: () => Promise<void>;
310
+ };
311
+ //#endregion
312
+ export { SwitchboardDriveDocumentType as a, SwitchboardDeps as i, StartServerOptions as n, SwitchboardDriveInput as o, StorageOptions as r, SwitchboardReactor as s, IdentityOptions as t };
313
+ export {};
314
+ //# sourceMappingURL=types-CidZdkhU.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-CidZdkhU.d.mts","names":[],"sources":["../src/privacy.mts","../src/types.ts"],"mappings":";;;;;;;;;;;KAyBY;;EAEV;;EAEA;;EAEA,SAAS;;EAET;EACA;EACA;EACA;;;;;;;;;;KCRU;;KAKA,wBAAwB;EAClC,eAAe;;KAGL;EACV;EACA;EACA;;KAGU;;EAEV;;;;;EAKA;;EAGA;;;;;;;KAQU;;;;;;;;;;;;;;;;;;;;;EAqBV,UAAU;;;;;;;;EAQV;;;;;;;EAOA;;;;;EAKA,aAAa;;;;;;;EAOb;EACA;;;;;;;EAOA;;;;;;EAMA;EACA;EACA;EACA,QAAQ;EACR;EACA;EACA;IAEM;IACA;;;;;;;EASN,WAAW;;EAEX;;;EAGA;;;;;;EAMA,oBAAoB;;;EAGpB;;;;EAIA;;;EAGA;IACE;;;;;;;IAOA;MACE;MACA;QAAW;QAAkB;;MAC7B;QAAU;QAAkB;QAAqB;;;;;EAIrD,UAAU;EACV,kBAAkB;EAClB;EACA;;;;;;EAMA;;;;;;EAMA,iBAAiB;EACjB,SAAS;;;;;;;;;;EAUT;;;;;;;;;;EAUA;;;;;;;;;EASA;IACE;IACA;IACA;;;;;;;;;;;EAWF;IACE;IACA;;;;;;;;;EASF,6BAA6B;;;KAInB;EACV,SAAS;;EAET,UAAU;;EAEV,oBAAoB;;EAEpB,eAAe;;EAEf;;EAEA;;EAEA,aAAa;;EAEb,gBAAgB;;KAGN;EACV;EACA,SAAS;;;;EAIT,mBAAmB;;EAEnB,+BAA+B;;;EAG/B,mBAAmB;;EAEnB;;EAEA,iBAAiB;;EAEjB;IAAY,SAAS;;;EAErB;;EAEA;;EAEA,WAAW;;EAEX,QAAQ;;;;;EAKR;;;;;;;;EAQA,gBAAgB"}
@@ -0,0 +1,148 @@
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]="aa01e979-2da2-5a91-8bd6-514c16afd3b2")}catch(e){}}();
3
+ import { REACTOR_DRIVE_DOCUMENT_TYPE, reactorDriveCreateState } from "@powerhousedao/reactor-drive";
4
+ import { driveCreateState, driveDocumentType } from "@powerhousedao/shared/document-drive";
5
+ //#region src/utils.mts
6
+ const isDriveDocumentType = (documentType) => documentType === driveDocumentType || documentType === REACTOR_DRIVE_DOCUMENT_TYPE;
7
+ /**
8
+ * Only a legacy drive can take a chosen id; without one the client's creation
9
+ * default applies.
10
+ */
11
+ function newDrive(client, documentType, initialState, id) {
12
+ return client.newDocument(documentType, {
13
+ initialState,
14
+ ...id ? {
15
+ signaturePolicy: "legacy",
16
+ id
17
+ } : {}
18
+ });
19
+ }
20
+ /** The document a slug names, unless someone deleted it and kept the slug. */
21
+ async function liveHolder(client, id) {
22
+ let document;
23
+ try {
24
+ document = await client.get(id);
25
+ } catch (error) {
26
+ if (error instanceof Error && (error.name === "DocumentDeletedError" || error.name === "DocumentNotFoundError")) return "deleted";
27
+ throw error;
28
+ }
29
+ return document.state.document?.isDeleted ? "deleted" : document;
30
+ }
31
+ /** The document that already holds `slug`; null when two do (an id and a slug). */
32
+ async function slugHolder(client, slug) {
33
+ let id;
34
+ try {
35
+ id = await client.resolveIdOrSlug(slug);
36
+ } catch (error) {
37
+ return error instanceof Error && error.name === "DocumentNotFoundError" ? void 0 : null;
38
+ }
39
+ const holder = await liveHolder(client, id);
40
+ return holder === "deleted" && id === slug ? void 0 : holder;
41
+ }
42
+ async function existingDrive(client, id) {
43
+ try {
44
+ const document = await client.get(id);
45
+ return document.state.document?.isDeleted ? void 0 : document;
46
+ } catch {
47
+ return;
48
+ }
49
+ }
50
+ const driveState = (drive, documentType) => {
51
+ if (documentType === REACTOR_DRIVE_DOCUMENT_TYPE) {
52
+ const { global, local } = reactorDriveCreateState();
53
+ return {
54
+ global: {
55
+ ...global,
56
+ name: drive.global.name,
57
+ icon: drive.global.icon ?? global.icon
58
+ },
59
+ local: {
60
+ ...local,
61
+ availableOffline: drive.local?.availableOffline ?? local.availableOffline,
62
+ sharingType: drive.local?.sharingType ?? local.sharingType
63
+ }
64
+ };
65
+ }
66
+ const { global } = driveCreateState();
67
+ return {
68
+ global: {
69
+ ...global,
70
+ name: drive.global.name,
71
+ icon: drive.global.icon ?? global.icon
72
+ },
73
+ local: {
74
+ availableOffline: drive.local?.availableOffline ?? false,
75
+ sharingType: drive.local?.sharingType ?? "public",
76
+ listeners: drive.local?.listeners ?? [],
77
+ triggers: drive.local?.triggers ?? []
78
+ }
79
+ };
80
+ };
81
+ /**
82
+ * Makes sure the drive `drive.slug` names exists, and returns the URL it is
83
+ * served at, or undefined when it could not be made (logged, so the server
84
+ * still starts).
85
+ *
86
+ * The slug is the drive's name, and the only thing an existing drive is found
87
+ * by: everything else is what a missing drive is created with, so a drive of
88
+ * another type or id under that slug is left as it is. `drive.id` is found too,
89
+ * for a drive declared by an id it already has. Without one the reactor
90
+ * generates the id, so nothing here may rely on it equalling the slug.
91
+ *
92
+ * A deleted drive frees its slug, so the next call makes a new empty drive and
93
+ * the slug names that one from then on. Its id stays taken, so a declared id
94
+ * that a deleted drive holds gives way to a generated one. A delete with
95
+ * `keepSlug` is someone deciding the drive is gone: the slug stays on it and
96
+ * nothing is created.
97
+ */
98
+ async function ensureDrive(client, drive, serverPort, logger = console) {
99
+ if (!drive.slug && !drive.id) throw new Error("A drive needs a slug");
100
+ const documentType = drive.documentType ?? driveDocumentType;
101
+ if (drive.slug) {
102
+ const holder = await slugHolder(client, drive.slug);
103
+ if (holder === "deleted") {
104
+ logger.error(`The default drive "${drive.slug}" was not created: it was deleted, and its slug kept.`);
105
+ return;
106
+ }
107
+ if (holder?.header && isDriveDocumentType(holder.header.documentType)) return `http://localhost:${serverPort}/d/${holder.header.id}`;
108
+ if (holder !== void 0) {
109
+ const owner = holder ? `${holder.header.documentType} document ${holder.header.id}` : "two documents";
110
+ logger.error(`The default drive "${drive.slug}" was not created: the slug belongs to ${owner}.`);
111
+ return;
112
+ }
113
+ }
114
+ if (drive.id && await existingDrive(client, drive.id)) return `http://localhost:${serverPort}/d/${drive.id}`;
115
+ const document = await newDrive(client, documentType, driveState(drive, documentType), drive.id);
116
+ if (drive.slug) document.header.slug = drive.slug;
117
+ if (drive.global.name) document.header.name = drive.global.name;
118
+ if (drive.preferredEditor) document.header.meta = { preferredEditor: drive.preferredEditor };
119
+ try {
120
+ await (await client.write.create(document)).readable;
121
+ } catch (e) {
122
+ if (!(e instanceof Error ? e.message : String(e)).includes("already exists")) throw e;
123
+ if (drive.slug && drive.id && !await existingDrive(client, drive.id)) return ensureDrive(client, {
124
+ ...drive,
125
+ id: void 0
126
+ }, serverPort, logger);
127
+ }
128
+ return `http://localhost:${serverPort}/d/${drive.id || drive.slug}`;
129
+ }
130
+ /** @deprecated Use {@link ensureDrive}. */
131
+ function addDefaultDrive(client, drive, serverPort, logger = console) {
132
+ return ensureDrive(client, {
133
+ ...drive,
134
+ documentType: driveDocumentType
135
+ }, serverPort, logger);
136
+ }
137
+ /** @deprecated Use {@link ensureDrive} with `documentType`. */
138
+ function addDefaultReactorDrive(client, drive, serverPort, logger = console) {
139
+ return ensureDrive(client, {
140
+ ...drive,
141
+ documentType: REACTOR_DRIVE_DOCUMENT_TYPE
142
+ }, serverPort, logger);
143
+ }
144
+ //#endregion
145
+ export { addDefaultReactorDrive as n, ensureDrive as r, addDefaultDrive as t };
146
+
147
+ //# sourceMappingURL=utils-Cm0TE6dP.mjs.map
148
+ //# debugId=aa01e979-2da2-5a91-8bd6-514c16afd3b2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils-Cm0TE6dP.mjs","sources":["../src/utils.mts"],"sourcesContent":["import type { IReactorClient } from \"@powerhousedao/reactor\";\nimport {\n REACTOR_DRIVE_DOCUMENT_TYPE,\n reactorDriveCreateState,\n} from \"@powerhousedao/reactor-drive\";\nimport {\n driveCreateState,\n driveDocumentType,\n} from \"@powerhousedao/shared/document-drive\";\nimport type { DriveInput } from \"@powerhousedao/shared/document-drive\";\nimport type {\n PHBaseState,\n PHDocument,\n} from \"@powerhousedao/shared/document-model\";\nimport type {\n SwitchboardDriveDocumentType,\n SwitchboardDriveInput,\n} from \"./types.js\";\n\nconst isDriveDocumentType = (documentType: string): boolean =>\n documentType === driveDocumentType ||\n documentType === REACTOR_DRIVE_DOCUMENT_TYPE;\n\n/**\n * Only a legacy drive can take a chosen id; without one the client's creation\n * default applies.\n */\nfunction newDrive<TDocument extends PHDocument>(\n client: IReactorClient,\n documentType: string,\n initialState: Partial<PHBaseState>,\n id: string | undefined,\n): Promise<TDocument> {\n return client.newDocument<TDocument>(documentType, {\n initialState,\n ...(id ? { signaturePolicy: \"legacy\" as const, id } : {}),\n });\n}\n\ntype DefaultDriveLogger = { error: (message: string) => void };\n\n/** The document a slug names, unless someone deleted it and kept the slug. */\nasync function liveHolder(\n client: IReactorClient,\n id: string,\n): Promise<PHDocument | \"deleted\"> {\n let document: PHDocument;\n try {\n document = await client.get(id);\n } catch (error) {\n // A slug resolved to it, so it exists: which error depends on the host.\n const gone =\n error instanceof Error &&\n (error.name === \"DocumentDeletedError\" ||\n error.name === \"DocumentNotFoundError\");\n if (gone) return \"deleted\";\n throw error;\n }\n return document.state.document?.isDeleted ? \"deleted\" : document;\n}\n\n/** The document that already holds `slug`; null when two do (an id and a slug). */\nasync function slugHolder(\n client: IReactorClient,\n slug: string,\n): Promise<PHDocument | \"deleted\" | null | undefined> {\n let id: string;\n try {\n id = await client.resolveIdOrSlug(slug);\n } catch (error) {\n const notFound =\n error instanceof Error && error.name === \"DocumentNotFoundError\";\n return notFound ? undefined : null;\n }\n const holder = await liveHolder(client, id);\n // The slug matched a deleted document's id, which leaves the slug free.\n return holder === \"deleted\" && id === slug ? undefined : holder;\n}\n\nasync function existingDrive(\n client: IReactorClient,\n id: string,\n): Promise<PHDocument | undefined> {\n try {\n const document = await client.get(id);\n return document.state.document?.isDeleted ? undefined : document;\n } catch {\n return undefined;\n }\n}\n\nconst driveState = (\n drive: SwitchboardDriveInput,\n documentType: SwitchboardDriveDocumentType,\n): Partial<PHBaseState> => {\n if (documentType === REACTOR_DRIVE_DOCUMENT_TYPE) {\n const { global, local } = reactorDriveCreateState();\n return {\n global: {\n ...global,\n name: drive.global.name,\n icon: drive.global.icon ?? global.icon,\n },\n local: {\n ...local,\n availableOffline:\n drive.local?.availableOffline ?? local.availableOffline,\n sharingType: drive.local?.sharingType ?? local.sharingType,\n },\n } as Partial<PHBaseState>;\n }\n const { global } = driveCreateState();\n return {\n global: {\n ...global,\n name: drive.global.name,\n icon: drive.global.icon ?? global.icon,\n },\n local: {\n availableOffline: drive.local?.availableOffline ?? false,\n sharingType: drive.local?.sharingType ?? \"public\",\n listeners: drive.local?.listeners ?? [],\n triggers: drive.local?.triggers ?? [],\n },\n } as Partial<PHBaseState>;\n};\n\n/**\n * Makes sure the drive `drive.slug` names exists, and returns the URL it is\n * served at, or undefined when it could not be made (logged, so the server\n * still starts).\n *\n * The slug is the drive's name, and the only thing an existing drive is found\n * by: everything else is what a missing drive is created with, so a drive of\n * another type or id under that slug is left as it is. `drive.id` is found too,\n * for a drive declared by an id it already has. Without one the reactor\n * generates the id, so nothing here may rely on it equalling the slug.\n *\n * A deleted drive frees its slug, so the next call makes a new empty drive and\n * the slug names that one from then on. Its id stays taken, so a declared id\n * that a deleted drive holds gives way to a generated one. A delete with\n * `keepSlug` is someone deciding the drive is gone: the slug stays on it and\n * nothing is created.\n */\nexport async function ensureDrive(\n client: IReactorClient,\n drive: SwitchboardDriveInput,\n serverPort: number,\n logger: DefaultDriveLogger = console,\n): Promise<string | undefined> {\n if (!drive.slug && !drive.id) {\n throw new Error(\"A drive needs a slug\");\n }\n const documentType = drive.documentType ?? driveDocumentType;\n\n if (drive.slug) {\n const holder = await slugHolder(client, drive.slug);\n if (holder === \"deleted\") {\n logger.error(\n `The default drive \"${drive.slug}\" was not created: it was deleted, and its slug kept.`,\n );\n return undefined;\n }\n if (holder?.header && isDriveDocumentType(holder.header.documentType)) {\n return `http://localhost:${serverPort}/d/${holder.header.id}`;\n }\n if (holder !== undefined) {\n const owner = holder\n ? `${holder.header.documentType} document ${holder.header.id}`\n : \"two documents\";\n logger.error(\n `The default drive \"${drive.slug}\" was not created: the slug belongs to ${owner}.`,\n );\n return undefined;\n }\n }\n if (drive.id && (await existingDrive(client, drive.id))) {\n return `http://localhost:${serverPort}/d/${drive.id}`;\n }\n\n const document = await newDrive(\n client,\n documentType,\n driveState(drive, documentType),\n drive.id,\n );\n if (drive.slug) {\n document.header.slug = drive.slug;\n }\n if (drive.global.name) {\n document.header.name = drive.global.name;\n }\n if (drive.preferredEditor) {\n document.header.meta = { preferredEditor: drive.preferredEditor };\n }\n\n try {\n await (\n await client.write.create(document)\n ).readable;\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : String(e);\n if (!errorMessage.includes(\"already exists\")) {\n throw e;\n }\n if (drive.slug && drive.id && !(await existingDrive(client, drive.id))) {\n return ensureDrive(\n client,\n { ...drive, id: undefined },\n serverPort,\n logger,\n );\n }\n }\n\n return `http://localhost:${serverPort}/d/${drive.id || drive.slug}`;\n}\n\n/** @deprecated Use {@link ensureDrive}. */\nexport function addDefaultDrive(\n client: IReactorClient,\n drive: DriveInput,\n serverPort: number,\n logger: DefaultDriveLogger = console,\n): Promise<string | undefined> {\n return ensureDrive(\n client,\n { ...drive, documentType: driveDocumentType },\n serverPort,\n logger,\n );\n}\n\n/** @deprecated Use {@link ensureDrive} with `documentType`. */\nexport function addDefaultReactorDrive(\n client: IReactorClient,\n drive: DriveInput,\n serverPort: number,\n logger: DefaultDriveLogger = console,\n): Promise<string | undefined> {\n return ensureDrive(\n client,\n { ...drive, documentType: REACTOR_DRIVE_DOCUMENT_TYPE },\n serverPort,\n logger,\n );\n}\n\nexport { isPostgresUrl } from \"./postgres-url.mjs\";\n"],"names":[],"mappings":"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","debug_id":"aa01e979-2da2-5a91-8bd6-514c16afd3b2"}
package/dist/utils.d.mts CHANGED
@@ -1,10 +1,35 @@
1
+ import { o as SwitchboardDriveInput } from "./types-CidZdkhU.mjs";
1
2
  import { IReactorClient } from "@powerhousedao/reactor";
2
3
  import { DriveInput } from "@powerhousedao/shared/document-drive";
3
-
4
+ //#region src/postgres-url.d.mts
5
+ export declare function isPostgresUrl(url: string): boolean;
6
+ //#endregion
4
7
  //#region src/utils.d.mts
5
- declare function addDefaultDrive(client: IReactorClient, drive: DriveInput, serverPort: number): Promise<string>;
6
- declare function addDefaultReactorDrive(client: IReactorClient, drive: DriveInput, serverPort: number): Promise<string>;
7
- declare function isPostgresUrl(url: string): boolean;
8
+ type DefaultDriveLogger = {
9
+ error: (message: string) => void;
10
+ };
11
+ /**
12
+ * Makes sure the drive `drive.slug` names exists, and returns the URL it is
13
+ * served at, or undefined when it could not be made (logged, so the server
14
+ * still starts).
15
+ *
16
+ * The slug is the drive's name, and the only thing an existing drive is found
17
+ * by: everything else is what a missing drive is created with, so a drive of
18
+ * another type or id under that slug is left as it is. `drive.id` is found too,
19
+ * for a drive declared by an id it already has. Without one the reactor
20
+ * generates the id, so nothing here may rely on it equalling the slug.
21
+ *
22
+ * A deleted drive frees its slug, so the next call makes a new empty drive and
23
+ * the slug names that one from then on. Its id stays taken, so a declared id
24
+ * that a deleted drive holds gives way to a generated one. A delete with
25
+ * `keepSlug` is someone deciding the drive is gone: the slug stays on it and
26
+ * nothing is created.
27
+ */
28
+ export declare function ensureDrive(client: IReactorClient, drive: SwitchboardDriveInput, serverPort: number, logger?: DefaultDriveLogger): Promise<string | undefined>;
29
+ /** @deprecated Use {@link ensureDrive}. */
30
+ export declare function addDefaultDrive(client: IReactorClient, drive: DriveInput, serverPort: number, logger?: DefaultDriveLogger): Promise<string | undefined>;
31
+ /** @deprecated Use {@link ensureDrive} with `documentType`. */
32
+ export declare function addDefaultReactorDrive(client: IReactorClient, drive: DriveInput, serverPort: number, logger?: DefaultDriveLogger): Promise<string | undefined>;
8
33
  //#endregion
9
- export { addDefaultDrive, addDefaultReactorDrive, isPostgresUrl };
34
+ export {};
10
35
  //# sourceMappingURL=utils.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.mts","names":[],"sources":["../src/utils.mts"],"mappings":";;;;iBAWsB,eAAA,CACpB,MAAA,EAAQ,cAAA,EACR,KAAA,EAAO,UAAA,EACP,UAAA,WAAkB,OAAA;AAAA,iBAgEE,sBAAA,CACpB,MAAA,EAAQ,cAAA,EACR,KAAA,EAAO,UAAA,EACP,UAAA,WAAkB,OAAA;AAAA,iBA6DJ,aAAA,CAAc,GAAA"}
1
+ {"version":3,"file":"utils.d.mts","names":[],"sources":["../src/postgres-url.mts","../src/utils.mts"],"mappings":";;;;wBAAgB,cAAc;;;KCuCzB;EAAuB,QAAQ;;;;;;;;;;;;;;;;;;;wBAyGd,YACpB,QAAQ,gBACR,OAAO,uBACP,oBACA,SAAQ,qBACP;;wBAsEa,gBACd,QAAQ,gBACR,OAAO,YACP,oBACA,SAAQ,qBACP;;wBAUa,uBACd,QAAQ,gBACR,OAAO,YACP,oBACA,SAAQ,qBACP"}
package/dist/utils.mjs CHANGED
@@ -1,4 +1,5 @@
1
- import { n as addDefaultReactorDrive, r as isPostgresUrl, t as addDefaultDrive } from "./utils-Baw7rThP.mjs";
2
- export { addDefaultDrive, addDefaultReactorDrive, isPostgresUrl };
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]="8227e60f-e412-513a-b0cb-502740b7f818")}catch(e){}}();
4
- //# debugId=8227e60f-e412-513a-b0cb-502740b7f818
1
+ import { t as isPostgresUrl } from "./postgres-url-DTDhBjXX.mjs";
2
+ import { n as addDefaultReactorDrive, r as ensureDrive, t as addDefaultDrive } from "./utils-Cm0TE6dP.mjs";
3
+ export { addDefaultDrive, addDefaultReactorDrive, ensureDrive, isPostgresUrl };
4
+ !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]="88a1492b-20ef-5063-8ee1-40e31754cbd9")}catch(e){}}();
5
+ //# debugId=88a1492b-20ef-5063-8ee1-40e31754cbd9