@makaio/framework 1.0.0-dev-1781022866275 → 1.0.0-dev-1781023871421
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/dist/.makaio-build.json +5 -0
- package/dist/account-identity-DT5NOtFi.mjs +1 -0
- package/dist/adapter-C1eI-fGV.mjs +1 -0
- package/dist/adapters/acp-client/index.d.mts +6208 -0
- package/dist/adapters/acp-client/index.mjs +3 -0
- package/dist/adapters/config/index.d.mts +429 -0
- package/dist/adapters/config/index.mjs +1 -0
- package/dist/adapters/index.d.mts +4202 -0
- package/dist/adapters/index.mjs +18 -0
- package/dist/adapters/node.d.mts +263 -0
- package/dist/adapters/node.mjs +4 -0
- package/dist/adapters/stream-session/index.d.mts +1414 -0
- package/dist/adapters/stream-session/index.mjs +1 -0
- package/dist/adapters/stream-session/testing/index.d.mts +29 -0
- package/dist/adapters/stream-session/testing/index.mjs +1 -0
- package/dist/artifact-B3npq1cy.mjs +1 -0
- package/dist/base-orchestrator-wyumsn3b.d.mts +772 -0
- package/dist/bus/index.d.mts +3994 -0
- package/dist/bus/index.mjs +1 -0
- package/dist/bus-Caz3Jpbc.mjs +1 -0
- package/dist/bus-Hb-LGzgb.mjs +2 -0
- package/dist/capability-service-CJbmhfv9.mjs +1 -0
- package/dist/chunk-DTipWd-i.mjs +1 -0
- package/dist/chunk-cpUYaJdV.mjs +1 -0
- package/dist/cleanEnvForAdapter-KkYzQa1f.mjs +1 -0
- package/dist/client-bx74gm4R.mjs +1 -0
- package/dist/clients/index.d.mts +2639 -0
- package/dist/clients/index.mjs +2 -0
- package/dist/clients-namespace-GmSJpBUV.d.mts +332 -0
- package/dist/config-namespace-CPY9YsR8.d.mts +638 -0
- package/dist/config-namespace-ncYg2ct_.mjs +1 -0
- package/dist/contracts/adapter/index.d.mts +3 -0
- package/dist/contracts/adapter/index.mjs +1 -0
- package/dist/contracts/adapter/schemas/session-lineage.d.mts +2 -0
- package/dist/contracts/adapter/schemas/session-lineage.mjs +1 -0
- package/dist/contracts/artifact/index.d.mts +2 -0
- package/dist/contracts/artifact/index.mjs +1 -0
- package/dist/contracts/client/index.d.mts +3 -0
- package/dist/contracts/client/index.mjs +1 -0
- package/dist/contracts/common/index.d.mts +2 -0
- package/dist/contracts/common/index.mjs +1 -0
- package/dist/contracts/config/index.d.mts +455 -0
- package/dist/contracts/config/index.mjs +1 -0
- package/dist/contracts/extension/index.d.mts +4 -0
- package/dist/contracts/extension/index.mjs +1 -0
- package/dist/contracts/facet/index.d.mts +2 -0
- package/dist/contracts/facet/index.mjs +1 -0
- package/dist/contracts/harness/index.d.mts +2 -0
- package/dist/contracts/harness/index.mjs +1 -0
- package/dist/contracts/host/index.d.mts +2 -0
- package/dist/contracts/host/index.mjs +1 -0
- package/dist/contracts/index.d.mts +23046 -0
- package/dist/contracts/index.mjs +1 -0
- package/dist/contracts/materialization/index.d.mts +4 -0
- package/dist/contracts/materialization/index.mjs +1 -0
- package/dist/contracts/model-registry/index.d.mts +2 -0
- package/dist/contracts/model-registry/index.mjs +1 -0
- package/dist/contracts/native-session-supervisor/index.d.mts +2 -0
- package/dist/contracts/native-session-supervisor/index.mjs +1 -0
- package/dist/contracts/platform/index.d.mts +2 -0
- package/dist/contracts/platform/index.mjs +1 -0
- package/dist/contracts/provider/index.d.mts +3 -0
- package/dist/contracts/provider/index.mjs +1 -0
- package/dist/contracts/session/index.d.mts +3 -0
- package/dist/contracts/session/index.mjs +1 -0
- package/dist/contracts/shared/index.d.mts +2 -0
- package/dist/contracts/shared/index.mjs +1 -0
- package/dist/contracts/skill/index.d.mts +2 -0
- package/dist/contracts/skill/index.mjs +1 -0
- package/dist/contracts/telemetry/index.d.mts +2 -0
- package/dist/contracts/telemetry/index.mjs +1 -0
- package/dist/contracts/timeout/index.d.mts +2 -0
- package/dist/contracts/timeout/index.mjs +1 -0
- package/dist/contracts/toast/index.d.mts +198 -0
- package/dist/contracts/toast/index.mjs +1 -0
- package/dist/contracts/variant/index.d.mts +2 -0
- package/dist/contracts/variant/index.mjs +1 -0
- package/dist/core/index.d.mts +1263 -0
- package/dist/core/index.mjs +1 -0
- package/dist/credential-ref-YWQQENEo.mjs +1 -0
- package/dist/cursor-storage-CtVJ3JzB.mjs +1 -0
- package/dist/definition-BLCdXGzh.d.mts +383 -0
- package/dist/definition-CrgHIpTK.d.mts +60 -0
- package/dist/definition-DZMXOnjX.mjs +1 -0
- package/dist/definition-pkJ6szUl.d.mts +158 -0
- package/dist/drizzle-Eq8W1EbD.mjs +1 -0
- package/dist/event-Ca2yUf5i.mjs +1 -0
- package/dist/execution-target-CRPTfZlc.mjs +1 -0
- package/dist/extension-C-4BHMRI.mjs +1 -0
- package/dist/extension-CpIUgBKI.mjs +1 -0
- package/dist/extension-namespace-cMh_mMiL.mjs +1 -0
- package/dist/facet-BuwhrThl.mjs +1 -0
- package/dist/filesystem-service-B8rhBRgB.mjs +1 -0
- package/dist/filesystem-service-p_iJVHd4.d.mts +66 -0
- package/dist/git/index.d.mts +210 -0
- package/dist/git/index.mjs +18 -0
- package/dist/globby-rtWVaFHv.mjs +41 -0
- package/dist/handlers-CkTsQLra.mjs +41 -0
- package/dist/harness-BRCMcvQN.mjs +1 -0
- package/dist/hooks/index.d.mts +423 -0
- package/dist/hooks/index.mjs +1 -0
- package/dist/host-Br9VuOyr.mjs +1 -0
- package/dist/identity-Cz2IeEtm.mjs +1 -0
- package/dist/index-472sOmsW.d.mts +218 -0
- package/dist/index-8SZkg7s6.d.mts +353 -0
- package/dist/index-B3PK4FIn.d.mts +5116 -0
- package/dist/index-B80L4YqA.d.mts +180 -0
- package/dist/index-BFg9BUpx.d.mts +355 -0
- package/dist/index-BGfWS6GE.d.mts +483 -0
- package/dist/index-BVgfS-AJ.d.mts +109 -0
- package/dist/index-B_zQC98V.d.mts +995 -0
- package/dist/index-Bh_Ne7LF.d.mts +1008 -0
- package/dist/index-Bvb2mMH6.d.mts +1730 -0
- package/dist/index-CCGVh9BF2.d.mts +749 -0
- package/dist/index-CGmcS0Ma.d.mts +412 -0
- package/dist/index-CHQ1SqT0.d.mts +117 -0
- package/dist/index-CLpjm52M.d.mts +183 -0
- package/dist/index-Caig6TeF.d.mts +6746 -0
- package/dist/index-CelJCBjk.d.mts +2992 -0
- package/dist/index-ChunCFu4.d.mts +11 -0
- package/dist/index-Cm0dUkWL.d.mts +4651 -0
- package/dist/index-CokQYGVP.d.mts +184 -0
- package/dist/index-Cs0kZXIz2.d.mts +37 -0
- package/dist/index-D5d5HeWI2.d.mts +259 -0
- package/dist/index-D90OmGmV.d.mts +389 -0
- package/dist/index-D9MwJ2Q8.d.mts +67 -0
- package/dist/index-DANINzMu.d.mts +40 -0
- package/dist/index-DBw-89vC2.d.mts +3640 -0
- package/dist/index-DGBu6bHi2.d.mts +438 -0
- package/dist/index-DKC62dY5.d.mts +146 -0
- package/dist/index-DKia0MX1.d.mts +43 -0
- package/dist/index-DMKnON5s.d.mts +28 -0
- package/dist/index-DUaw0Dw8.d.mts +14747 -0
- package/dist/index-De3kPhlN.d.mts +72 -0
- package/dist/index-L4GjJDKb.d.mts +822 -0
- package/dist/index-U-A8eyGT.d.mts +1490 -0
- package/dist/index-eemAKwsB.d.mts +362 -0
- package/dist/index-mNec7V-9.d.mts +1075 -0
- package/dist/index-soFznFCy2.d.mts +89 -0
- package/dist/index-vtXJuwrz.d.mts +40 -0
- package/dist/index-x_lVDp_J.d.mts +134 -0
- package/dist/json-value-CmhSGMLv.mjs +1 -0
- package/dist/kernel/cli/index.d.mts +143 -0
- package/dist/kernel/cli/index.mjs +1 -0
- package/dist/kernel/cli/schemas.d.mts +64 -0
- package/dist/kernel/cli/schemas.mjs +1 -0
- package/dist/kernel/extension/index.d.mts +2 -0
- package/dist/kernel/extension/index.mjs +1 -0
- package/dist/kernel/index.d.mts +296 -0
- package/dist/kernel/index.mjs +1 -0
- package/dist/kernel/namespace/index.d.mts +2 -0
- package/dist/kernel/namespace/index.mjs +1 -0
- package/dist/kernel/observability/index.d.mts +2 -0
- package/dist/kernel/observability/index.mjs +1 -0
- package/dist/kernel/providers/index.d.mts +2 -0
- package/dist/kernel/providers/index.mjs +1 -0
- package/dist/kernel/window/index.d.mts +2 -0
- package/dist/kernel/window/index.mjs +1 -0
- package/dist/materialization-CuUBu4XI.mjs +1 -0
- package/dist/model-registry-CfXytvzx.mjs +1 -0
- package/dist/model-registry-Scn_MC2d.mjs +1 -0
- package/dist/namespace-5QQqbF-B.d.mts +3133 -0
- package/dist/namespace-BM7Djng9.d.mts +189 -0
- package/dist/namespace-BoD94mrN.mjs +1 -0
- package/dist/namespace-BwzZJqTV.mjs +1 -0
- package/dist/namespace-CFLAmQfh.mjs +1 -0
- package/dist/namespace-CTm3nEvh.d.mts +51 -0
- package/dist/namespace-CaaNnKcR.d.mts +921 -0
- package/dist/namespace-CaoZ3S78.d.mts +43 -0
- package/dist/namespace-CxhsoFUP.d.mts +607 -0
- package/dist/namespace-DD8Oiqo7.d.mts +580 -0
- package/dist/namespace-DLovh2Ws.d.mts +1313 -0
- package/dist/namespace-DgqkaOVu.d.mts +768 -0
- package/dist/namespace-DkRgbZYn.mjs +1 -0
- package/dist/namespace-Dr8K0MCp.d.mts +2047 -0
- package/dist/namespace-DuXK5AYN.mjs +1 -0
- package/dist/namespace-EQniz-Aw.d.mts +142 -0
- package/dist/namespace-IV1QK__V.d.mts +159 -0
- package/dist/namespace-LViZ-EQk.mjs +1 -0
- package/dist/namespace-TyiTsLFv.d.mts +3020 -0
- package/dist/namespace-Yna5-Pws.mjs +1 -0
- package/dist/namespace-xcmbQlxh.mjs +1 -0
- package/dist/native-session-supervisor-B1TnaPUF.mjs +1 -0
- package/dist/node/bus-server/index.d.mts +178 -0
- package/dist/node/bus-server/index.mjs +1 -0
- package/dist/node/bus-server/server-lifecycle.d.mts +2 -0
- package/dist/node/bus-server/server-lifecycle.mjs +1 -0
- package/dist/node/machine-identity/index.d.mts +85 -0
- package/dist/node/machine-identity/index.mjs +3 -0
- package/dist/node/transports/index.d.mts +1945 -0
- package/dist/node/transports/index.mjs +2 -0
- package/dist/orchestrator-shared-CIDiFJMD.mjs +1 -0
- package/dist/orchestrator-shared-Dfa7FMyw.d.mts +249 -0
- package/dist/package-DKVlsMP3.mjs +1 -0
- package/dist/platform-DZ7z-wXD.mjs +1 -0
- package/dist/profile-6ynCD5k3.mjs +1 -0
- package/dist/provider-context-CK6B4X_8.mjs +1 -0
- package/dist/providers/index.d.mts +135 -0
- package/dist/providers/index.mjs +1 -0
- package/dist/providers-namespace-DSEpli4A.d.mts +583 -0
- package/dist/providers-u8i15co9.mjs +1 -0
- package/dist/schema-CoyE6mPt.mjs +1 -0
- package/dist/schema-M5YTvSAG.d.mts +949 -0
- package/dist/schema-e0wU_lcV.mjs +1 -0
- package/dist/schema-introspection-Dn1jWQs1.mjs +1 -0
- package/dist/schemas-Bd0OjRQf.d.mts +46 -0
- package/dist/schemas-C46QfKzv.d.mts +459 -0
- package/dist/schemas-CDBSjg7o.d.mts +237 -0
- package/dist/schemas-CR1Rripy.mjs +1 -0
- package/dist/schemas-CVvwIfG4.mjs +1 -0
- package/dist/schemas-CaLhkkLn.mjs +1 -0
- package/dist/schemas-ClOOT1W6.d.mts +174 -0
- package/dist/schemas-DATniTHb.d.mts +182 -0
- package/dist/schemas-DE-GNmSD.mjs +1 -0
- package/dist/schemas-DVF1A4DF.d.mts +160 -0
- package/dist/schemas-DaRSfYLf.d.mts +73 -0
- package/dist/schemas-DiYVzG6e.d.mts +315 -0
- package/dist/schemas-hSrzflwZ.mjs +1 -0
- package/dist/schemas-j7ivZ2HI.d.mts +944 -0
- package/dist/schemas-jFe1AuI-.mjs +1 -0
- package/dist/schemas-wg_6PAdV.d.mts +153 -0
- package/dist/scoped-bus-04pwo1uM.mjs +1 -0
- package/dist/server-lifecycle-FXTPW39-.mjs +1 -0
- package/dist/server-lifecycle-YoSGFGnU.d.mts +160 -0
- package/dist/service-base/index.d.mts +98 -0
- package/dist/service-base/index.mjs +1 -0
- package/dist/services/adapter-runtime/index.d.mts +4 -0
- package/dist/services/adapter-runtime/index.mjs +1 -0
- package/dist/services/adapter-runtime/namespace.d.mts +2 -0
- package/dist/services/adapter-runtime/namespace.mjs +1 -0
- package/dist/services/adapter-runtime/schemas.d.mts +2 -0
- package/dist/services/adapter-runtime/schemas.mjs +1 -0
- package/dist/services/adapter-subsystem/index.d.mts +3 -0
- package/dist/services/adapter-subsystem/index.mjs +1 -0
- package/dist/services/adapter-subsystem/namespace.d.mts +2 -0
- package/dist/services/adapter-subsystem/namespace.mjs +1 -0
- package/dist/services/agent-runtime/index.d.mts +3 -0
- package/dist/services/agent-runtime/index.mjs +1 -0
- package/dist/services/agent-runtime/namespace.d.mts +2 -0
- package/dist/services/agent-runtime/namespace.mjs +1 -0
- package/dist/services/agent-runtime/schemas.d.mts +2 -0
- package/dist/services/agent-runtime/schemas.mjs +1 -0
- package/dist/services/capability/index.d.mts +2 -0
- package/dist/services/capability/index.mjs +1 -0
- package/dist/services/cli-detection/namespace.d.mts +56 -0
- package/dist/services/cli-detection/namespace.mjs +1 -0
- package/dist/services/codebase/index.d.mts +3 -0
- package/dist/services/codebase/index.mjs +1 -0
- package/dist/services/codebase/namespace.d.mts +2 -0
- package/dist/services/codebase/namespace.mjs +1 -0
- package/dist/services/codebase/schemas.d.mts +2 -0
- package/dist/services/codebase/schemas.mjs +1 -0
- package/dist/services/compression/index.d.mts +3 -0
- package/dist/services/compression/index.mjs +1 -0
- package/dist/services/compression/namespace.d.mts +2 -0
- package/dist/services/compression/namespace.mjs +1 -0
- package/dist/services/compression/schemas.d.mts +2 -0
- package/dist/services/compression/schemas.mjs +1 -0
- package/dist/services/context-rules/index.d.mts +412 -0
- package/dist/services/context-rules/index.mjs +1 -0
- package/dist/services/credential-change/index.d.mts +17 -0
- package/dist/services/credential-change/index.mjs +1 -0
- package/dist/services/definition/index.d.mts +2 -0
- package/dist/services/definition/index.mjs +1 -0
- package/dist/services/definition/namespace.d.mts +71 -0
- package/dist/services/definition/namespace.mjs +1 -0
- package/dist/services/definition/schemas.d.mts +38 -0
- package/dist/services/definition/schemas.mjs +1 -0
- package/dist/services/dialog/namespace.d.mts +105 -0
- package/dist/services/dialog/namespace.mjs +1 -0
- package/dist/services/dialog/schemas.d.mts +109 -0
- package/dist/services/dialog/schemas.mjs +1 -0
- package/dist/services/execution-target/index.d.mts +4 -0
- package/dist/services/execution-target/index.mjs +1 -0
- package/dist/services/execution-target/namespace.d.mts +2 -0
- package/dist/services/execution-target/namespace.mjs +1 -0
- package/dist/services/execution-target/schemas.d.mts +2 -0
- package/dist/services/execution-target/schemas.mjs +1 -0
- package/dist/services/filesystem/index.d.mts +3 -0
- package/dist/services/filesystem/index.mjs +1 -0
- package/dist/services/filesystem/namespace.d.mts +432 -0
- package/dist/services/filesystem/namespace.mjs +1 -0
- package/dist/services/filesystem/schemas.d.mts +240 -0
- package/dist/services/filesystem/schemas.mjs +1 -0
- package/dist/services/git/namespace.d.mts +1163 -0
- package/dist/services/git/namespace.mjs +1 -0
- package/dist/services/git/schemas.d.mts +932 -0
- package/dist/services/git/schemas.mjs +1 -0
- package/dist/services/harness/index.d.mts +861 -0
- package/dist/services/harness/index.mjs +1 -0
- package/dist/services/harness/storage/schema.d.mts +424 -0
- package/dist/services/harness/storage/schema.mjs +1 -0
- package/dist/services/index.d.mts +6185 -0
- package/dist/services/index.mjs +1 -0
- package/dist/services/local-notification/index.d.mts +25 -0
- package/dist/services/local-notification/index.mjs +1 -0
- package/dist/services/local-notification/namespace.d.mts +73 -0
- package/dist/services/local-notification/namespace.mjs +1 -0
- package/dist/services/local-notification/schemas.d.mts +88 -0
- package/dist/services/local-notification/schemas.mjs +1 -0
- package/dist/services/log-import/browser.d.mts +3 -0
- package/dist/services/log-import/browser.mjs +1 -0
- package/dist/services/log-import/index.d.mts +274 -0
- package/dist/services/log-import/index.mjs +2 -0
- package/dist/services/log-import/log-import.d.mts +3 -0
- package/dist/services/log-import/log-import.mjs +1 -0
- package/dist/services/log-import/namespace.d.mts +327 -0
- package/dist/services/log-import/namespace.mjs +1 -0
- package/dist/services/log-import/schemas.d.mts +217 -0
- package/dist/services/log-import/schemas.mjs +1 -0
- package/dist/services/model-registry/index.d.mts +2 -0
- package/dist/services/model-registry/index.mjs +1 -0
- package/dist/services/preferences/index.d.mts +3 -0
- package/dist/services/preferences/index.mjs +1 -0
- package/dist/services/preferences/schemas.d.mts +2 -0
- package/dist/services/preferences/schemas.mjs +1 -0
- package/dist/services/preferences/storage-namespace.d.mts +3 -0
- package/dist/services/preferences/storage-namespace.mjs +1 -0
- package/dist/services/provider-context/index.d.mts +2 -0
- package/dist/services/provider-context/index.mjs +1 -0
- package/dist/services/provider-runtime/index.d.mts +136 -0
- package/dist/services/provider-runtime/index.mjs +1 -0
- package/dist/services/session/handlers/index.d.mts +2 -0
- package/dist/services/session/handlers/index.mjs +1 -0
- package/dist/services/session/index.d.mts +10 -0
- package/dist/services/session/index.mjs +1 -0
- package/dist/services/session/messages/namespace.d.mts +2 -0
- package/dist/services/session/messages/namespace.mjs +1 -0
- package/dist/services/session/orchestrator-testing/index.d.mts +2 -0
- package/dist/services/session/orchestrator-testing/index.mjs +1 -0
- package/dist/services/session/session-events/namespace.d.mts +2 -0
- package/dist/services/session/session-events/namespace.mjs +1 -0
- package/dist/services/session/storage/namespace.d.mts +2 -0
- package/dist/services/session/storage/namespace.mjs +1 -0
- package/dist/services/session/storage/schema.d.mts +2 -0
- package/dist/services/session/storage/schema.mjs +1 -0
- package/dist/services/session/testing/index.d.mts +35 -0
- package/dist/services/session/testing/index.mjs +65 -0
- package/dist/services/session/testing/orchestrator-shared.d.mts +2 -0
- package/dist/services/session/testing/orchestrator-shared.mjs +1 -0
- package/dist/services/session/turns/namespace.d.mts +2 -0
- package/dist/services/session/turns/namespace.mjs +1 -0
- package/dist/services/session-editor/index.d.mts +119 -0
- package/dist/services/session-editor/index.mjs +1 -0
- package/dist/services/settings/index.d.mts +47 -0
- package/dist/services/settings/index.mjs +1 -0
- package/dist/services/settings/namespace.d.mts +663 -0
- package/dist/services/settings/namespace.mjs +1 -0
- package/dist/services/settings/storage/clients-namespace.d.mts +2 -0
- package/dist/services/settings/storage/clients-namespace.mjs +1 -0
- package/dist/services/settings/storage/extension-configs/namespace.d.mts +184 -0
- package/dist/services/settings/storage/extension-configs/namespace.mjs +1 -0
- package/dist/services/settings/storage/index.d.mts +4 -0
- package/dist/services/settings/storage/index.mjs +1 -0
- package/dist/services/settings/storage/providers-namespace.d.mts +2 -0
- package/dist/services/settings/storage/providers-namespace.mjs +1 -0
- package/dist/services/subagent/index.d.mts +2 -0
- package/dist/services/subagent/index.mjs +1 -0
- package/dist/services/subagent-template/index.d.mts +3 -0
- package/dist/services/subagent-template/index.mjs +1 -0
- package/dist/services/subagent-template/namespace.d.mts +2 -0
- package/dist/services/subagent-template/namespace.mjs +1 -0
- package/dist/services/subagent-template/schemas.d.mts +2 -0
- package/dist/services/subagent-template/schemas.mjs +1 -0
- package/dist/services/tool-approval/index.d.mts +2 -0
- package/dist/services/tool-approval/index.mjs +1 -0
- package/dist/services/tools/index.d.mts +2 -0
- package/dist/services/tools/index.mjs +1 -0
- package/dist/services/tray-menu/index.d.mts +4 -0
- package/dist/services/tray-menu/index.mjs +1 -0
- package/dist/services/tray-menu/namespace.d.mts +2 -0
- package/dist/services/tray-menu/namespace.mjs +1 -0
- package/dist/services/tray-menu/schemas.d.mts +2 -0
- package/dist/services/tray-menu/schemas.mjs +1 -0
- package/dist/services/turn/index.d.mts +2 -0
- package/dist/services/turn/index.mjs +1 -0
- package/dist/services/turn/namespace.d.mts +2 -0
- package/dist/services/turn/namespace.mjs +1 -0
- package/dist/services/turn/schemas.d.mts +335 -0
- package/dist/services/turn/schemas.mjs +1 -0
- package/dist/session-BoldSdNZ2.mjs +134 -0
- package/dist/session-DuVOYctZ.mjs +1 -0
- package/dist/session-lineage-CRsc9g1x.d.mts +65 -0
- package/dist/shared-DpOEfD8F.mjs +1 -0
- package/dist/shared-schemas-CPShiLNp.mjs +1 -0
- package/dist/skill-CQO4mDqK.mjs +1 -0
- package/dist/storage/drizzle/client.d.mts +78 -0
- package/dist/storage/drizzle/client.mjs +1 -0
- package/dist/storage/drizzle/index.d.mts +137 -0
- package/dist/storage/drizzle/index.mjs +1 -0
- package/dist/storage/handlers/drizzle/index.d.mts +2 -0
- package/dist/storage/handlers/drizzle/index.mjs +1 -0
- package/dist/storage/handlers/index.d.mts +33 -0
- package/dist/storage/handlers/index.mjs +1 -0
- package/dist/storage/index.d.mts +192 -0
- package/dist/storage/index.mjs +1 -0
- package/dist/storage-namespace-BXkoh5Sy.d.mts +221 -0
- package/dist/storage-namespace-DWsYLAXa.mjs +1 -0
- package/dist/storage-namespace-definition-Bkx5rSto.d.mts +17 -0
- package/dist/storage-namespace-definition-CqSdsuCC.mjs +1 -0
- package/dist/style.css +3782 -0
- package/dist/telemetry-CvdLBWuk.mjs +1 -0
- package/dist/testing/drizzle-harness.d.mts +130 -0
- package/dist/testing/drizzle-harness.mjs +1 -0
- package/dist/testing/index.d.mts +106 -0
- package/dist/testing/index.mjs +1 -0
- package/dist/timeout-XsYIOKrc.mjs +1 -0
- package/dist/tool-approval-service-BvZWhYZp.mjs +1 -0
- package/dist/tools/index.d.mts +835 -0
- package/dist/tools/index.mjs +1 -0
- package/dist/tools/testing/index.d.mts +53 -0
- package/dist/tools/testing/index.mjs +1 -0
- package/dist/tools-D-luYcDw.mjs +1431 -0
- package/dist/tray-menu-service-DuXq5k22.mjs +1 -0
- package/dist/types-BCMUtBj1.d.mts +1106 -0
- package/dist/types-C2Ob9zz_.d.mts +128 -0
- package/dist/types-CCdqjeuH.d.mts +262 -0
- package/dist/types-DZHvOc_Q.d.mts +305 -0
- package/dist/types-Dy3YTcTF.d.mts +6777 -0
- package/dist/types-MfJZ67e9.d.mts +315 -0
- package/dist/types-dyP-bXXE.d.mts +31 -0
- package/dist/ui-components/index.d.mts +2342 -0
- package/dist/ui-components/index.mjs +8 -0
- package/dist/ui-config-9bDRwFZr.mjs +1 -0
- package/dist/ui-hooks/index.d.mts +1915 -0
- package/dist/ui-hooks/index.mjs +1 -0
- package/dist/ui-kernel/index.d.mts +2793 -0
- package/dist/ui-kernel/index.mjs +1 -0
- package/dist/ui-kernel/pages/namespace.d.mts +88 -0
- package/dist/ui-kernel/pages/namespace.mjs +1 -0
- package/dist/ui-kernel/pages/schemas.d.mts +2 -0
- package/dist/ui-kernel/pages/schemas.mjs +1 -0
- package/dist/ui-views/index.d.mts +487 -0
- package/dist/ui-views/index.mjs +30 -0
- package/dist/utils/health-probe.d.mts +26 -0
- package/dist/utils/health-probe.mjs +1 -0
- package/dist/utils/index.d.mts +262 -0
- package/dist/utils/index.mjs +2 -0
- package/dist/utils/keychain.d.mts +31 -0
- package/dist/utils/keychain.mjs +1 -0
- package/dist/utils/project-manifest.d.mts +130 -0
- package/dist/utils/project-manifest.mjs +1 -0
- package/dist/utils/resolve-package-root.d.mts +12 -0
- package/dist/utils/resolve-package-root.mjs +1 -0
- package/dist/utils/scope-paths.d.mts +33 -0
- package/dist/utils/scope-paths.mjs +1 -0
- package/dist/utils/workspace-packages.d.mts +59 -0
- package/dist/utils/workspace-packages.mjs +1 -0
- package/dist/utils/workspace-root.d.mts +24 -0
- package/dist/utils/workspace-root.mjs +2 -0
- package/dist/variant-CT6XBP6T.mjs +1 -0
- package/dist/version-BeT3ASEe.mjs +1 -0
- package/dist/visibility-Cb62p9bv.mjs +1 -0
- package/dist/window-registry-CBcrGTv4.d.mts +130 -0
- package/dist/window-registry-DW-dKRjQ.mjs +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,1945 @@
|
|
|
1
|
+
import { PayloadFilter, TransportPeerContext, TransportReceiveContext } from "@makaio/framework/core";
|
|
2
|
+
import { BusBroadcastMessage, BusEventMessage, BusMessage, BusReceiveHandler, BusRequestMessage, BusTransport, BusTransportError } from "@makaio/framework/bus";
|
|
3
|
+
|
|
4
|
+
//#region transports/ws/src/auth/interface.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Transport authentication strategy.
|
|
7
|
+
*
|
|
8
|
+
* Implementations authenticate WebSocket connections and manage auth lifecycle.
|
|
9
|
+
* Auth messages are handled during a pre-connect phase before normal message flow begins.
|
|
10
|
+
*/
|
|
11
|
+
interface TransportAuth {
|
|
12
|
+
/**
|
|
13
|
+
* Authenticate a client connection.
|
|
14
|
+
*
|
|
15
|
+
* Called during the pre-connect phase after the WebSocket is open but before
|
|
16
|
+
* normal message handling begins. Auth messages flow through handleAuthMessage().
|
|
17
|
+
* @param send - Function to send auth messages to the server
|
|
18
|
+
* @throws Error if authentication fails
|
|
19
|
+
*/
|
|
20
|
+
authenticateClient(send: (message: unknown) => void): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Authenticate a server connection with a specific client socket.
|
|
23
|
+
*
|
|
24
|
+
* Called when a new client connects to the server, during the pre-connect phase.
|
|
25
|
+
* @param socket - The client WebSocket connection to authenticate
|
|
26
|
+
* @param send - Function to send auth messages to the client
|
|
27
|
+
* @throws Error if authentication fails
|
|
28
|
+
*/
|
|
29
|
+
authenticateServer(socket: WebSocketLike, send: (message: unknown) => void): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Handle incoming message during authentication phase.
|
|
32
|
+
*
|
|
33
|
+
* This is called by the transport's message handler to route auth messages
|
|
34
|
+
* to the auth implementation during the pre-connect phase.
|
|
35
|
+
* @param message - Parsed message object
|
|
36
|
+
* @param socket - Optional socket identifier for server-side multi-client scenarios
|
|
37
|
+
* @returns true if the message was an auth message and was handled, false otherwise
|
|
38
|
+
*/
|
|
39
|
+
handleAuthMessage(message: unknown, socket?: WebSocketLike): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Return trusted receive context for a socket after authentication.
|
|
42
|
+
*
|
|
43
|
+
* Server transports call this when routing inbound bus messages from the
|
|
44
|
+
* socket. Undefined means the auth strategy has no context to expose.
|
|
45
|
+
* @param socket - Optional socket for server-side multi-client transports
|
|
46
|
+
* @returns Trusted local receive context, or undefined
|
|
47
|
+
*/
|
|
48
|
+
getReceiveContext?(socket?: WebSocketLike): TransportReceiveContext | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Return whether a previously authenticated socket may still send bus frames.
|
|
51
|
+
*
|
|
52
|
+
* Auth strategies with expiring or revocable credentials should re-check the
|
|
53
|
+
* backing authorization state here because a successful WebSocket handshake
|
|
54
|
+
* can outlive the credential used for that handshake.
|
|
55
|
+
* @param socket - Server-side socket whose live authorization should be checked.
|
|
56
|
+
* @returns `true` when the socket remains authorized, `false` when it must be closed.
|
|
57
|
+
*/
|
|
58
|
+
isSocketAuthenticated?(socket: WebSocketLike): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Clean up authentication resources for a specific socket.
|
|
61
|
+
*
|
|
62
|
+
* Called when a socket disconnects to immediately release per-socket resources like:
|
|
63
|
+
* - Pending authentication state
|
|
64
|
+
* - Authentication timers for that socket
|
|
65
|
+
* - Socket-specific auth data
|
|
66
|
+
*
|
|
67
|
+
* This prevents memory leaks when sockets disconnect during authentication.
|
|
68
|
+
* @param socket - The socket to clean up auth resources for
|
|
69
|
+
*/
|
|
70
|
+
cleanupSocket(socket: WebSocketLike): void;
|
|
71
|
+
/**
|
|
72
|
+
* Clean up authentication resources.
|
|
73
|
+
*
|
|
74
|
+
* Called during disconnect() to release resources like:
|
|
75
|
+
* - Authentication timers
|
|
76
|
+
* - Token refresh intervals
|
|
77
|
+
* - Event listeners
|
|
78
|
+
* - Cached credentials
|
|
79
|
+
*/
|
|
80
|
+
cleanup(): void;
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region transports/ws/src/auth/hmac-auth.d.ts
|
|
84
|
+
/**
|
|
85
|
+
* HMAC authentication configuration.
|
|
86
|
+
*/
|
|
87
|
+
interface HmacAuthOptions {
|
|
88
|
+
/**
|
|
89
|
+
* Shared secret for HMAC computation.
|
|
90
|
+
*
|
|
91
|
+
* IMPORTANT: This should be a strong, randomly-generated secret.
|
|
92
|
+
* Both client and server must use the same secret.
|
|
93
|
+
*
|
|
94
|
+
* On the server side this field is used for global-secret clients. When
|
|
95
|
+
* `resolveSecret` is also provided, identity-bound clients use their
|
|
96
|
+
* resolved identity secret and clients without an `identityId` continue to
|
|
97
|
+
* use this global secret.
|
|
98
|
+
*/
|
|
99
|
+
secret: string;
|
|
100
|
+
/**
|
|
101
|
+
* HMAC algorithm to use.
|
|
102
|
+
* @defaultValue 'sha256'
|
|
103
|
+
*/
|
|
104
|
+
algorithm?: string;
|
|
105
|
+
/**
|
|
106
|
+
* Timeout for authentication challenge in milliseconds.
|
|
107
|
+
*
|
|
108
|
+
* If client doesn't respond within this time, authentication fails.
|
|
109
|
+
* @defaultValue 5000
|
|
110
|
+
*/
|
|
111
|
+
challengeTimeout?: number;
|
|
112
|
+
/**
|
|
113
|
+
* Client-side identity claim sent alongside the HMAC signature.
|
|
114
|
+
*
|
|
115
|
+
* When set the client includes this value as `identityId` in the
|
|
116
|
+
* `auth-response` frame. The server stores it in
|
|
117
|
+
* `serverAuthenticatedPeers` and exposes it via `getReceiveContext()`.
|
|
118
|
+
*
|
|
119
|
+
* Leave undefined for global-secret mode (backward-compatible default).
|
|
120
|
+
*/
|
|
121
|
+
identityId?: string;
|
|
122
|
+
/**
|
|
123
|
+
* Server-side per-identity secret resolver for identity-bound mode.
|
|
124
|
+
*
|
|
125
|
+
* When provided and the client supplies `identityId`, the server calls
|
|
126
|
+
* `resolveSecret(identityId)` and uses the returned secret to verify the
|
|
127
|
+
* HMAC signature. Clients that omit `identityId` continue to authenticate
|
|
128
|
+
* against the global `secret`.
|
|
129
|
+
*
|
|
130
|
+
* Return `null` to reject the connection (unknown identity).
|
|
131
|
+
* @param claimedId - The `identityId` value from the `auth-response` frame.
|
|
132
|
+
* @returns The HMAC secret for this identity, or `null` to reject.
|
|
133
|
+
*/
|
|
134
|
+
resolveSecret?: (claimedId: string) => string | null;
|
|
135
|
+
/**
|
|
136
|
+
* Server-side peer context resolver for identity-bound mode.
|
|
137
|
+
*
|
|
138
|
+
* When provided, the authenticated identity is exposed to bus handlers as
|
|
139
|
+
* this peer context instead of the backward-compatible `workflow-execution`
|
|
140
|
+
* default. Return `null` when no peer context should be exposed.
|
|
141
|
+
* @param claimedId - The authenticated `identityId`.
|
|
142
|
+
* @returns Trusted peer context for the authenticated identity, or `null`.
|
|
143
|
+
*/
|
|
144
|
+
resolvePeer?: (claimedId: string) => TransportPeerContext | null;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* HMAC challenge/response authentication implementation.
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* const auth = new HmacAuth({
|
|
151
|
+
* secret: process.env.WEBSOCKET_SECRET,
|
|
152
|
+
* algorithm: 'sha256',
|
|
153
|
+
* challengeTimeout: 5000,
|
|
154
|
+
* });
|
|
155
|
+
*
|
|
156
|
+
* const transport = createClientTransport({
|
|
157
|
+
* websocket: ws,
|
|
158
|
+
* auth,
|
|
159
|
+
* });
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
declare class HmacAuth implements TransportAuth {
|
|
163
|
+
private readonly secret;
|
|
164
|
+
private readonly algorithm;
|
|
165
|
+
private readonly challengeTimeout;
|
|
166
|
+
private readonly identityId;
|
|
167
|
+
private readonly resolveSecret;
|
|
168
|
+
private readonly resolvePeer;
|
|
169
|
+
private pendingChallenge?;
|
|
170
|
+
private pendingResult?;
|
|
171
|
+
private queuedChallengeNonce;
|
|
172
|
+
private queuedResult;
|
|
173
|
+
private clientAuthComplete;
|
|
174
|
+
private serverPendingResponses;
|
|
175
|
+
private serverAuthenticatedSockets;
|
|
176
|
+
/**
|
|
177
|
+
* Maps each successfully authenticated socket to the identity ID it claimed.
|
|
178
|
+
* Populated in identity-bound mode; empty in global-secret mode.
|
|
179
|
+
* Cleaned up in `cleanupSocket()` when the socket disconnects.
|
|
180
|
+
*/
|
|
181
|
+
private serverAuthenticatedPeers;
|
|
182
|
+
constructor(options: HmacAuthOptions);
|
|
183
|
+
/**
|
|
184
|
+
* Server-side authentication flow.
|
|
185
|
+
*
|
|
186
|
+
* Global-secret mode (default):
|
|
187
|
+
* 1. Generate random nonce
|
|
188
|
+
* 2. Send auth-challenge to client
|
|
189
|
+
* 3. Wait for auth-response with signature (via handleAuthMessage)
|
|
190
|
+
* 4. Verify signature matches HMAC(secret, nonce)
|
|
191
|
+
* 5. Send auth-result
|
|
192
|
+
*
|
|
193
|
+
* Identity-bound mode (`resolveSecret` provided):
|
|
194
|
+
* Same flow, but the `auth-response` also carries `identityId`. The server
|
|
195
|
+
* resolves the per-identity secret via `resolveSecret(identityId)` and
|
|
196
|
+
* verifies HMAC against that secret. On success the socket is registered in
|
|
197
|
+
* `serverAuthenticatedPeers` so `getReceiveContext()` can expose the peer.
|
|
198
|
+
* @param socket - The client WebSocket connection to authenticate
|
|
199
|
+
* @param send - Function to send auth messages to the client
|
|
200
|
+
* @throws Error if authentication fails
|
|
201
|
+
*/
|
|
202
|
+
authenticateServer(socket: WebSocketLike, send: (message: unknown) => void): Promise<void>;
|
|
203
|
+
/**
|
|
204
|
+
* Client-side authentication flow.
|
|
205
|
+
*
|
|
206
|
+
* 1. Wait for auth-challenge from server (via handleAuthMessage)
|
|
207
|
+
* 2. Compute signature = HMAC(secret, nonce)
|
|
208
|
+
* 3. Send auth-response with signature
|
|
209
|
+
* 4. Wait for auth-result (via handleAuthMessage)
|
|
210
|
+
* 5. Throw if authentication failed
|
|
211
|
+
* @param send - Function to send auth messages to the server
|
|
212
|
+
* @throws Error if authentication fails
|
|
213
|
+
*/
|
|
214
|
+
authenticateClient(send: (message: unknown) => void): Promise<void>;
|
|
215
|
+
/**
|
|
216
|
+
* Handle incoming message during authentication phase.
|
|
217
|
+
*
|
|
218
|
+
* Routes auth messages to the appropriate pending operation.
|
|
219
|
+
* ALWAYS consumes auth message types to prevent them from leaking to regular handlers.
|
|
220
|
+
* @param message - Parsed message object
|
|
221
|
+
* @param socket - Optional socket identifier for server-side multi-client scenarios
|
|
222
|
+
* @returns true if the message was an auth message (consumed regardless of pending state)
|
|
223
|
+
*/
|
|
224
|
+
handleAuthMessage(message: unknown, socket?: WebSocketLike): boolean;
|
|
225
|
+
/**
|
|
226
|
+
* Wait for auth-challenge message from server.
|
|
227
|
+
*
|
|
228
|
+
* Message will be delivered via handleAuthMessage().
|
|
229
|
+
* @returns The nonce from the challenge
|
|
230
|
+
* @throws Error if timeout
|
|
231
|
+
*/
|
|
232
|
+
private waitForAuthChallenge;
|
|
233
|
+
/**
|
|
234
|
+
* Wait for auth-response message from client.
|
|
235
|
+
*
|
|
236
|
+
* Message will be delivered via handleAuthMessage().
|
|
237
|
+
* @param socket - The client socket to track
|
|
238
|
+
* @returns The signature and optional identity ID from the response
|
|
239
|
+
* @throws Error if timeout
|
|
240
|
+
*/
|
|
241
|
+
private waitForAuthResponseWithIdentity;
|
|
242
|
+
/**
|
|
243
|
+
* Wait for auth-result message from server.
|
|
244
|
+
*
|
|
245
|
+
* Message will be delivered via handleAuthMessage().
|
|
246
|
+
* @returns The authentication result
|
|
247
|
+
* @throws Error if timeout
|
|
248
|
+
*/
|
|
249
|
+
private waitForAuthResult;
|
|
250
|
+
/**
|
|
251
|
+
* Compute HMAC signature for a nonce using the instance secret.
|
|
252
|
+
* @param nonce - The nonce to sign
|
|
253
|
+
* @returns Promise resolving to hex-encoded HMAC signature
|
|
254
|
+
*/
|
|
255
|
+
private computeHmac;
|
|
256
|
+
/**
|
|
257
|
+
* Compute HMAC signature for a nonce using an explicit secret.
|
|
258
|
+
* @param nonce - The nonce to sign
|
|
259
|
+
* @param secret - Secret to use for key derivation
|
|
260
|
+
* @returns Promise resolving to hex-encoded HMAC signature
|
|
261
|
+
*/
|
|
262
|
+
private computeHmacWithSecret;
|
|
263
|
+
/**
|
|
264
|
+
* Return trusted receive context for a socket that has authenticated
|
|
265
|
+
* in identity-bound mode.
|
|
266
|
+
*
|
|
267
|
+
* For global-secret clients this returns `undefined` — there is no
|
|
268
|
+
* per-identity peer to expose.
|
|
269
|
+
*
|
|
270
|
+
* The `transportName` is intentionally left as `''` here; the transport
|
|
271
|
+
* registry merges in the registered name when it synthesises the effective
|
|
272
|
+
* receive context (§1.3 of the bus-origin design).
|
|
273
|
+
* @param socket - The socket whose peer identity to retrieve.
|
|
274
|
+
* @returns Trusted receive context with peer identity, or `undefined`.
|
|
275
|
+
*/
|
|
276
|
+
getReceiveContext(socket?: WebSocketLike): TransportReceiveContext | undefined;
|
|
277
|
+
/**
|
|
278
|
+
* Check whether a server-side socket remains authorized for bus traffic.
|
|
279
|
+
*
|
|
280
|
+
* Identity-bound HMAC sockets are revalidated against `resolveSecret()` on
|
|
281
|
+
* every inbound frame so process-local registry revocation, such as dashboard
|
|
282
|
+
* session expiry, takes effect without waiting for the WebSocket to close.
|
|
283
|
+
* Global-secret sockets have no identity to revoke and remain authorized by
|
|
284
|
+
* their completed handshake.
|
|
285
|
+
* @param socket - The socket whose live authorization should be checked.
|
|
286
|
+
* @returns `true` when the socket is still authorized.
|
|
287
|
+
*/
|
|
288
|
+
isSocketAuthenticated(socket: WebSocketLike): boolean;
|
|
289
|
+
/**
|
|
290
|
+
* Compare two hex-encoded HMAC signatures in constant time.
|
|
291
|
+
*
|
|
292
|
+
* A variable-time `===` comparison leaks information about how many prefix
|
|
293
|
+
* characters match, enabling timing-based secret recovery. This method decodes
|
|
294
|
+
* both signatures to byte arrays and uses a constant-time XOR accumulator so
|
|
295
|
+
* every comparison takes the same wall-clock time regardless of the match point.
|
|
296
|
+
* @param a - First hex signature
|
|
297
|
+
* @param b - Second hex signature
|
|
298
|
+
* @returns True when both signatures are identical
|
|
299
|
+
*/
|
|
300
|
+
private constantTimeEqual;
|
|
301
|
+
/**
|
|
302
|
+
* Send auth result messages without masking the original auth error.
|
|
303
|
+
*
|
|
304
|
+
* Disconnect races can make `send` throw after auth already failed; callers
|
|
305
|
+
* should still observe the original failure reason.
|
|
306
|
+
* @param send - Transport send function
|
|
307
|
+
* @param message - Auth result message payload
|
|
308
|
+
*/
|
|
309
|
+
private sendAuthResultBestEffort;
|
|
310
|
+
/**
|
|
311
|
+
* Clean up authentication resources for a specific socket.
|
|
312
|
+
*
|
|
313
|
+
* Called when a socket disconnects to immediately release resources
|
|
314
|
+
* and prevent memory leaks during the authentication timeout window.
|
|
315
|
+
* @param socket - The socket to clean up
|
|
316
|
+
*/
|
|
317
|
+
cleanupSocket(socket: WebSocketLike): void;
|
|
318
|
+
/**
|
|
319
|
+
* Clean up authentication resources.
|
|
320
|
+
*
|
|
321
|
+
* Clears any pending authentication operations and their timeouts.
|
|
322
|
+
*/
|
|
323
|
+
cleanup(): void;
|
|
324
|
+
}
|
|
325
|
+
//#endregion
|
|
326
|
+
//#region transports/ws/src/auth/identity-secret-registry.d.ts
|
|
327
|
+
/** Options for registering an HMAC identity secret. */
|
|
328
|
+
interface HmacIdentitySecretRegistrationOptions {
|
|
329
|
+
/**
|
|
330
|
+
* Trusted peer kind exposed after this identity authenticates.
|
|
331
|
+
*
|
|
332
|
+
* Defaults to `workflow-execution` because the original identity-bound HMAC
|
|
333
|
+
* clients are workflow runners.
|
|
334
|
+
*/
|
|
335
|
+
readonly peerKind?: string;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Register an HMAC secret for a transport identity.
|
|
339
|
+
*
|
|
340
|
+
* The returned cleanup removes the entry only when it still points at the
|
|
341
|
+
* exact registration object, so replacing identity metadata cannot be
|
|
342
|
+
* accidentally undone by an older cleanup handle.
|
|
343
|
+
* @param identityId - Transport identity that may authenticate with the secret.
|
|
344
|
+
* @param secret - HMAC secret expected for the identity.
|
|
345
|
+
* @param options - Optional trusted peer metadata for this identity.
|
|
346
|
+
* @returns Cleanup function that unregisters this exact secret.
|
|
347
|
+
*/
|
|
348
|
+
declare function registerHmacIdentitySecret(identityId: string, secret: string, options?: HmacIdentitySecretRegistrationOptions): () => void;
|
|
349
|
+
/**
|
|
350
|
+
* Resolve an HMAC secret for an identity claim.
|
|
351
|
+
* @param identityId - Claimed transport identity.
|
|
352
|
+
* @returns Registered secret, or null when the identity is unknown.
|
|
353
|
+
*/
|
|
354
|
+
declare function resolveHmacIdentitySecret(identityId: string): string | null;
|
|
355
|
+
/**
|
|
356
|
+
* Resolve trusted peer context for an identity claim.
|
|
357
|
+
* @param identityId - Claimed transport identity.
|
|
358
|
+
* @returns Registered peer context, or null when the identity is unknown.
|
|
359
|
+
*/
|
|
360
|
+
declare function resolveHmacIdentityPeer(identityId: string): TransportPeerContext | null;
|
|
361
|
+
/**
|
|
362
|
+
* Clear all registered identity secrets.
|
|
363
|
+
*
|
|
364
|
+
* Intended for tests that exercise the process-global registry.
|
|
365
|
+
*/
|
|
366
|
+
declare function clearHmacIdentitySecretsForTesting(): void;
|
|
367
|
+
//#endregion
|
|
368
|
+
//#region transports/ws/src/auth/e2e-auth.d.ts
|
|
369
|
+
/**
|
|
370
|
+
* E2E authentication configuration.
|
|
371
|
+
*/
|
|
372
|
+
interface E2EAuthOptions {
|
|
373
|
+
/** Our static identity keypair for signing (ECDSA P-256) */
|
|
374
|
+
signingKeyPair: CryptoKeyPair;
|
|
375
|
+
/** Our identifier (deviceId for browser, machineId for server) */
|
|
376
|
+
identityId: string;
|
|
377
|
+
/** Expected peer identifier (required for browser connections; machineId from QR payload) */
|
|
378
|
+
peerId?: string;
|
|
379
|
+
/** Lookup peer's signing public key by their identity */
|
|
380
|
+
getPeerSigningKey: (peerId: string) => Promise<CryptoKey | null>;
|
|
381
|
+
/** Auth timeout in milliseconds. @defaultValue 10000 */
|
|
382
|
+
timeout?: number;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* E2E authenticated encryption implementation.
|
|
386
|
+
*/
|
|
387
|
+
declare class E2EAuth implements TransportAuth {
|
|
388
|
+
private readonly signingKeyPair;
|
|
389
|
+
private readonly identityId;
|
|
390
|
+
private readonly peerId?;
|
|
391
|
+
private readonly getPeerSigningKey;
|
|
392
|
+
private readonly timeout;
|
|
393
|
+
private pendingKeyExchange?;
|
|
394
|
+
private pendingResult?;
|
|
395
|
+
private clientSession?;
|
|
396
|
+
private clientEphemeralKeyPair?;
|
|
397
|
+
private serverPendingKeyExchange;
|
|
398
|
+
private serverSessions;
|
|
399
|
+
private serverEphemeralKeyPairs;
|
|
400
|
+
constructor(options: E2EAuthOptions);
|
|
401
|
+
/**
|
|
402
|
+
* Client-side authentication flow.
|
|
403
|
+
*
|
|
404
|
+
* If an error occurs after pending promises are created, they are cleaned up
|
|
405
|
+
* before rethrowing to prevent unhandled rejections from lingering timeouts.
|
|
406
|
+
* @param send - Function to send auth messages to the server
|
|
407
|
+
*/
|
|
408
|
+
authenticateClient(send: (message: unknown) => void): Promise<void>;
|
|
409
|
+
/**
|
|
410
|
+
* Server-side authentication flow.
|
|
411
|
+
* @param socket - The client WebSocket connection to authenticate
|
|
412
|
+
* @param send - Function to send auth messages to the client
|
|
413
|
+
*/
|
|
414
|
+
authenticateServer(socket: WebSocketLike, send: (message: unknown) => void): Promise<void>;
|
|
415
|
+
/**
|
|
416
|
+
* Handle incoming message during authentication phase.
|
|
417
|
+
* @param message - Parsed message object
|
|
418
|
+
* @param socket - Optional socket identifier for server-side
|
|
419
|
+
* @returns true if the message was an E2E auth message
|
|
420
|
+
*/
|
|
421
|
+
handleAuthMessage(message: unknown, socket?: WebSocketLike): boolean;
|
|
422
|
+
private waitForKeyExchangeResponse;
|
|
423
|
+
private waitForAuthResult;
|
|
424
|
+
private waitForClientKeyExchange;
|
|
425
|
+
/**
|
|
426
|
+
* Get the derived AES-256-GCM session key for encrypting/decrypting payloads.
|
|
427
|
+
* @param socket - Optional socket (server-side only)
|
|
428
|
+
* @returns Session key if authenticated, null otherwise
|
|
429
|
+
*/
|
|
430
|
+
getSessionKey(socket?: WebSocketLike): CryptoKey | null;
|
|
431
|
+
/**
|
|
432
|
+
* Get the peer's identity ID authenticated during handshake.
|
|
433
|
+
* @param socket - Optional socket (server-side only)
|
|
434
|
+
* @returns Peer ID if authenticated, null otherwise
|
|
435
|
+
*/
|
|
436
|
+
getPeerId(socket?: WebSocketLike): string | null;
|
|
437
|
+
/**
|
|
438
|
+
* Return trusted receive context for a socket that has completed E2E authentication.
|
|
439
|
+
*
|
|
440
|
+
* The `transportName` is intentionally left as `''` here; the transport
|
|
441
|
+
* registry merges in the registered name when it synthesises the effective
|
|
442
|
+
* receive context.
|
|
443
|
+
* @param socket - Optional socket (server-side only)
|
|
444
|
+
* @returns Trusted receive context with peer identity, or `undefined`.
|
|
445
|
+
*/
|
|
446
|
+
getReceiveContext(socket?: WebSocketLike): TransportReceiveContext | undefined;
|
|
447
|
+
/**
|
|
448
|
+
* Clean up authentication resources for a specific socket.
|
|
449
|
+
* @param socket - The socket to clean up
|
|
450
|
+
*/
|
|
451
|
+
cleanupSocket(socket: WebSocketLike): void;
|
|
452
|
+
/**
|
|
453
|
+
* Clean up authentication resources.
|
|
454
|
+
*/
|
|
455
|
+
cleanup(): void;
|
|
456
|
+
}
|
|
457
|
+
//#endregion
|
|
458
|
+
//#region transports/ws/src/auth/e2e-relay-auth.d.ts
|
|
459
|
+
type RelayAuthMode = 'initiator' | 'responder';
|
|
460
|
+
/**
|
|
461
|
+
* Configuration for relay-mode E2E authentication.
|
|
462
|
+
*/
|
|
463
|
+
interface E2ERelayAuthOptions {
|
|
464
|
+
/** Static ECDSA signing keypair */
|
|
465
|
+
signingKeyPair: CryptoKeyPair;
|
|
466
|
+
/** Local identity ID */
|
|
467
|
+
identityId: string;
|
|
468
|
+
/** Lookup peer signing key by identity */
|
|
469
|
+
getPeerSigningKey: (peerId: string) => Promise<CryptoKey | null>;
|
|
470
|
+
/** Auth timeout in milliseconds. @defaultValue 10000 */
|
|
471
|
+
timeout?: number;
|
|
472
|
+
/**
|
|
473
|
+
* Relay handshake mode.
|
|
474
|
+
* - initiator: sends exchange immediately (browser)
|
|
475
|
+
* - responder: waits for peer exchange before responding (machine)
|
|
476
|
+
* @defaultValue "initiator"
|
|
477
|
+
*/
|
|
478
|
+
mode?: RelayAuthMode;
|
|
479
|
+
/**
|
|
480
|
+
* Whether authenticateClient should block until handshake completes.
|
|
481
|
+
* Use false for machine-side relay connections to avoid startup stalls
|
|
482
|
+
* when no browser is connected.
|
|
483
|
+
* @defaultValue true
|
|
484
|
+
*/
|
|
485
|
+
blocking?: boolean;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Relay-mode E2E authentication implementation.
|
|
489
|
+
*/
|
|
490
|
+
declare class E2ERelayAuth implements TransportAuth {
|
|
491
|
+
private readonly signingKeyPair;
|
|
492
|
+
private readonly identityId;
|
|
493
|
+
private readonly getPeerSigningKey;
|
|
494
|
+
private readonly timeout;
|
|
495
|
+
private readonly mode;
|
|
496
|
+
private readonly blocking;
|
|
497
|
+
private pendingPeer?;
|
|
498
|
+
private sessionKey?;
|
|
499
|
+
private peerId?;
|
|
500
|
+
private localEphemeral?;
|
|
501
|
+
private localExchangeMessage?;
|
|
502
|
+
private sentLocalExchange;
|
|
503
|
+
private earlyPeer?;
|
|
504
|
+
private sendAuthMessage?;
|
|
505
|
+
/**
|
|
506
|
+
* Monotonically increasing counter to invalidate stale async
|
|
507
|
+
* `processPeerExchange` tasks from previous sessions.
|
|
508
|
+
*/
|
|
509
|
+
private authGeneration;
|
|
510
|
+
/**
|
|
511
|
+
* True while a non-blocking `processPeerExchange` is in flight.
|
|
512
|
+
* Prevents duplicate dispatches when the initiator sends its exchange
|
|
513
|
+
* twice (initial + confirmation after deriving its own key).
|
|
514
|
+
*/
|
|
515
|
+
private processingExchange;
|
|
516
|
+
constructor(options: E2ERelayAuthOptions);
|
|
517
|
+
/**
|
|
518
|
+
* Client-side authentication flow (relay mode).
|
|
519
|
+
*
|
|
520
|
+
* Resets all derived session state before starting a fresh handshake so that
|
|
521
|
+
* this instance can be reused across WebSocketClientTransport reconnections.
|
|
522
|
+
* Constructor-time config (`signingKeyPair`, `identityId`, `getPeerSigningKey`,
|
|
523
|
+
* `mode`, `blocking`) is intentionally preserved by `cleanup()`.
|
|
524
|
+
* @param send - Function to send auth messages to peer via relay
|
|
525
|
+
*/
|
|
526
|
+
authenticateClient(send: (message: unknown) => void): Promise<void>;
|
|
527
|
+
/**
|
|
528
|
+
* Server-side auth is not used in relay mode.
|
|
529
|
+
*
|
|
530
|
+
* No `cleanup()` call is needed here: this method throws unconditionally
|
|
531
|
+
* before setting any session state, so there is nothing to reset.
|
|
532
|
+
* @param _socket - WebSocket connection (unused)
|
|
533
|
+
* @param _send - Auth send function (unused)
|
|
534
|
+
*/
|
|
535
|
+
authenticateServer(_socket: WebSocketLike, _send: (message: unknown) => void): Promise<void>;
|
|
536
|
+
/**
|
|
537
|
+
* Handle incoming message during authentication phase.
|
|
538
|
+
* @param message - Parsed message
|
|
539
|
+
* @returns true if handled
|
|
540
|
+
*/
|
|
541
|
+
handleAuthMessage(message: unknown): boolean;
|
|
542
|
+
cleanupSocket(_socket: WebSocketLike): void;
|
|
543
|
+
cleanup(): void;
|
|
544
|
+
/**
|
|
545
|
+
* Fire-and-forget `processPeerExchange` with `processingExchange` tracking
|
|
546
|
+
* and generation-guarded cleanup.
|
|
547
|
+
* @param peer - Peer key-exchange message
|
|
548
|
+
* @param generation - Auth generation at dispatch time
|
|
549
|
+
*/
|
|
550
|
+
private dispatchPeerExchange;
|
|
551
|
+
/**
|
|
552
|
+
* Get derived session key after handshake.
|
|
553
|
+
* @returns Session key or null
|
|
554
|
+
*/
|
|
555
|
+
getSessionKey(): CryptoKey | null;
|
|
556
|
+
/**
|
|
557
|
+
* Get peer identity ID after handshake.
|
|
558
|
+
* @returns Peer identity ID or null
|
|
559
|
+
*/
|
|
560
|
+
getPeerId(): string | null;
|
|
561
|
+
/**
|
|
562
|
+
* Return trusted receive context after a successful relay handshake.
|
|
563
|
+
*
|
|
564
|
+
* Relay auth is always client-mode (no socket parameter). The `transportName`
|
|
565
|
+
* is intentionally left as `''`; the transport registry fills it in.
|
|
566
|
+
* @returns Trusted receive context with peer identity, or `undefined`.
|
|
567
|
+
*/
|
|
568
|
+
getReceiveContext(): TransportReceiveContext | undefined;
|
|
569
|
+
private waitForPeerExchange;
|
|
570
|
+
private ensureLocalExchangeMessage;
|
|
571
|
+
private sendLocalExchange;
|
|
572
|
+
/**
|
|
573
|
+
* Retry the latest queued peer exchange after an in-flight attempt settles.
|
|
574
|
+
*
|
|
575
|
+
* Non-blocking relay auth can receive a newer peer exchange while the current
|
|
576
|
+
* one is still deriving keys. WebSocketClientTransport reconnects are already
|
|
577
|
+
* generation-scoped; this helper only re-dispatches messages queued within the
|
|
578
|
+
* same live auth session so newer exchanges are not stranded behind a failure.
|
|
579
|
+
* @param generation - Auth generation that just finished processing
|
|
580
|
+
*/
|
|
581
|
+
private retryQueuedPeerExchange;
|
|
582
|
+
/**
|
|
583
|
+
* Verify the peer's exchange, derive the shared session key, and store it.
|
|
584
|
+
*
|
|
585
|
+
* The `generation` parameter prevents stale async tasks from a previous
|
|
586
|
+
* session from overwriting the current session's keys. Each call to
|
|
587
|
+
* `authenticateClient` increments `authGeneration`; if a task's generation
|
|
588
|
+
* no longer matches, it silently aborts before writing any state.
|
|
589
|
+
* @param peer - Peer key-exchange message
|
|
590
|
+
* @param generation - Auth generation at dispatch time
|
|
591
|
+
*/
|
|
592
|
+
private processPeerExchange;
|
|
593
|
+
}
|
|
594
|
+
//#endregion
|
|
595
|
+
//#region transports/ws/src/auth/dispatching-auth.d.ts
|
|
596
|
+
/**
|
|
597
|
+
* Options for creating a dispatching auth strategy.
|
|
598
|
+
*/
|
|
599
|
+
interface DispatchingAuthOptions {
|
|
600
|
+
/** Auth strategy for HMAC challenge/response clients. */
|
|
601
|
+
hmac?: TransportAuth;
|
|
602
|
+
/** Auth strategy for E2E key-exchange clients. */
|
|
603
|
+
e2e?: TransportAuth;
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Auth dispatcher that routes to the appropriate strategy based on the first
|
|
607
|
+
* auth message type received from the client.
|
|
608
|
+
*
|
|
609
|
+
* Enables a single bus server port to accept both HMAC-authenticated
|
|
610
|
+
* connections (e.g., Electron) and E2E-authenticated connections (e.g., mobile).
|
|
611
|
+
*
|
|
612
|
+
* ### How it works
|
|
613
|
+
*
|
|
614
|
+
* HMAC auth is server-initiated (the server sends a challenge before any client
|
|
615
|
+
* message arrives). E2E auth is client-initiated (the client sends `e2e-key-exchange`
|
|
616
|
+
* as its first message). This creates a dispatch ordering problem: the dispatcher
|
|
617
|
+
* cannot wait for the client's first message before deciding which strategy to use,
|
|
618
|
+
* because HMAC requires the server to act first.
|
|
619
|
+
*
|
|
620
|
+
* The solution:
|
|
621
|
+
*
|
|
622
|
+
* **Single strategy**: If only one strategy is configured, `authenticateServer`
|
|
623
|
+
* delegates immediately — no dispatch needed, no ordering constraint.
|
|
624
|
+
*
|
|
625
|
+
* **Both strategies**: `authenticateServer` calls `hmac.authenticateServer()`
|
|
626
|
+
* eagerly so HMAC can send its challenge right away. It then waits for the
|
|
627
|
+
* client's first message to determine the winner:
|
|
628
|
+
* - `auth-response` → HMAC is already running; forward and let it complete.
|
|
629
|
+
* - `e2e-key-exchange` → E2E wins; cancel HMAC (its pending promise is
|
|
630
|
+
* rejected via `cleanupSocket`), start `e2e.authenticateServer()`, and
|
|
631
|
+
* forward the message to E2E.
|
|
632
|
+
*
|
|
633
|
+
* A cancellation flag on the `send` wrapper given to HMAC prevents HMAC's
|
|
634
|
+
* error path from sending spurious `auth-result: false` to E2E clients.
|
|
635
|
+
* @example
|
|
636
|
+
* ```typescript
|
|
637
|
+
* const auth = new DispatchingAuth({
|
|
638
|
+
* hmac: new HmacAuth({ secret: process.env.BUS_SECRET! }),
|
|
639
|
+
* e2e: new E2EAuth({ ... }),
|
|
640
|
+
* });
|
|
641
|
+
*
|
|
642
|
+
* const server = createBusServer({ websocket: wss, auth });
|
|
643
|
+
* ```
|
|
644
|
+
*/
|
|
645
|
+
declare class DispatchingAuth implements TransportAuth {
|
|
646
|
+
private readonly hmac;
|
|
647
|
+
private e2e;
|
|
648
|
+
/** Maps each socket to its resolved auth strategy after the first message. */
|
|
649
|
+
private readonly socketStrategy;
|
|
650
|
+
/**
|
|
651
|
+
* Maps each socket to its pending server-auth state while we wait for the
|
|
652
|
+
* first client message to determine the appropriate strategy.
|
|
653
|
+
*/
|
|
654
|
+
private readonly pendingServerAuth;
|
|
655
|
+
/**
|
|
656
|
+
* Per-socket cancellation flags for eagerly-started HMAC auth.
|
|
657
|
+
*
|
|
658
|
+
* When E2E wins the dispatch race, the flag is set to `true` so the `send`
|
|
659
|
+
* wrapper passed to HMAC becomes a no-op, preventing spurious `auth-result`
|
|
660
|
+
* failure messages from reaching the E2E client.
|
|
661
|
+
*/
|
|
662
|
+
private readonly hmacCancelled;
|
|
663
|
+
/**
|
|
664
|
+
* @param options - Auth strategies to dispatch between
|
|
665
|
+
*/
|
|
666
|
+
constructor(options: DispatchingAuthOptions);
|
|
667
|
+
/**
|
|
668
|
+
* Set or replace the E2E authentication strategy after construction.
|
|
669
|
+
*
|
|
670
|
+
* Used in transport-first boot sequences where the bus server starts with
|
|
671
|
+
* HMAC-only auth and E2E auth is wired in later, once machine identity
|
|
672
|
+
* (e.g. LAN keypair) becomes available. Only affects new connection
|
|
673
|
+
* handshakes — in-flight authentications are unaffected.
|
|
674
|
+
* @param e2e - The E2E auth strategy to register
|
|
675
|
+
*/
|
|
676
|
+
setE2EAuth(e2e: TransportAuth): void;
|
|
677
|
+
/**
|
|
678
|
+
* Authenticate a client connection.
|
|
679
|
+
*
|
|
680
|
+
* The dispatcher is a server-side concern; clients always know which strategy
|
|
681
|
+
* they are using. This method delegates to the first configured strategy as a
|
|
682
|
+
* fallback, or throws if no strategy is configured.
|
|
683
|
+
* @param send - Function to send auth messages to the server
|
|
684
|
+
* @returns Promise that resolves when client authentication is complete
|
|
685
|
+
* @throws Error if no auth strategy is configured
|
|
686
|
+
*/
|
|
687
|
+
authenticateClient(send: (message: unknown) => void): Promise<void>;
|
|
688
|
+
/**
|
|
689
|
+
* Authenticate a server connection with a specific client socket.
|
|
690
|
+
*
|
|
691
|
+
* **Single strategy**: delegates immediately to the configured strategy.
|
|
692
|
+
*
|
|
693
|
+
* **Both strategies**: starts HMAC eagerly (so it can send its challenge),
|
|
694
|
+
* then parks a pending promise that resolves or rejects once
|
|
695
|
+
* `handleAuthMessage` receives the first client message and determines the
|
|
696
|
+
* winner. If E2E wins, HMAC is cancelled via `cleanupSocket`.
|
|
697
|
+
* @param socket - The client WebSocket connection to authenticate
|
|
698
|
+
* @param send - Function to send auth messages to the client
|
|
699
|
+
* @returns Promise that resolves when server authentication is complete
|
|
700
|
+
* @throws Error if no strategy matches the client's auth type, or if the
|
|
701
|
+
* delegated strategy rejects authentication
|
|
702
|
+
*/
|
|
703
|
+
authenticateServer(socket: WebSocketLike, send: (message: unknown) => void): Promise<void>;
|
|
704
|
+
/**
|
|
705
|
+
* Handle incoming message during authentication phase.
|
|
706
|
+
*
|
|
707
|
+
* On the first message for an unknown socket, peeks at `message.type` to
|
|
708
|
+
* select a strategy, then delegates `authenticateServer` and this message
|
|
709
|
+
* to the selected strategy. Subsequent messages for the same socket are
|
|
710
|
+
* forwarded directly.
|
|
711
|
+
* @param message - Parsed message object
|
|
712
|
+
* @param socket - Optional socket identifier for server-side multi-client scenarios
|
|
713
|
+
* @returns true if the message was handled as an auth message, false otherwise
|
|
714
|
+
*/
|
|
715
|
+
handleAuthMessage(message: unknown, socket?: WebSocketLike): boolean;
|
|
716
|
+
/**
|
|
717
|
+
* Clean up authentication resources for a specific socket.
|
|
718
|
+
*
|
|
719
|
+
* Delegates to the resolved strategy if one was selected, then removes
|
|
720
|
+
* all per-socket state held by the dispatcher itself.
|
|
721
|
+
* @param socket - The socket to clean up auth resources for
|
|
722
|
+
*/
|
|
723
|
+
cleanupSocket(socket: WebSocketLike): void;
|
|
724
|
+
/**
|
|
725
|
+
* Clean up all authentication resources.
|
|
726
|
+
*
|
|
727
|
+
* Calls `cleanup` on both configured strategies (if present) and clears
|
|
728
|
+
* all internal maps.
|
|
729
|
+
*/
|
|
730
|
+
cleanup(): void;
|
|
731
|
+
/**
|
|
732
|
+
* Peek at the `type` field of an unknown message without a full parse.
|
|
733
|
+
* @param message - Raw parsed message object
|
|
734
|
+
* @returns The string value of `message.type`, or `undefined`
|
|
735
|
+
*/
|
|
736
|
+
private peekType;
|
|
737
|
+
/**
|
|
738
|
+
* Returns the single configured strategy, or `undefined` if both or neither
|
|
739
|
+
* are configured.
|
|
740
|
+
*
|
|
741
|
+
* Used by `authenticateServer` to short-circuit dispatch when only one
|
|
742
|
+
* strategy is present.
|
|
743
|
+
* @returns The sole configured strategy, or `undefined`
|
|
744
|
+
*/
|
|
745
|
+
private resolveSingleStrategy;
|
|
746
|
+
/**
|
|
747
|
+
* Select the appropriate strategy based on the first auth message type.
|
|
748
|
+
*
|
|
749
|
+
* HMAC clients send `auth-response` as their first message (the server
|
|
750
|
+
* already sent `auth-challenge` eagerly). E2E clients send `e2e-key-exchange`.
|
|
751
|
+
* @param message - The first auth message received from the client
|
|
752
|
+
* @returns The matching strategy, or `undefined` if none matches
|
|
753
|
+
*/
|
|
754
|
+
private resolveStrategy;
|
|
755
|
+
/**
|
|
756
|
+
* Cancel the eagerly-started HMAC authentication for a socket.
|
|
757
|
+
*
|
|
758
|
+
* Sets the cancellation flag (preventing spurious `send` calls from HMAC's
|
|
759
|
+
* error path) and calls `hmac.cleanupSocket` to reject HMAC's pending
|
|
760
|
+
* response promise and release its resources.
|
|
761
|
+
* @param socket - The socket whose HMAC auth should be cancelled
|
|
762
|
+
*/
|
|
763
|
+
private cancelHmac;
|
|
764
|
+
}
|
|
765
|
+
//#endregion
|
|
766
|
+
//#region transports/ws/src/types.d.ts
|
|
767
|
+
/**
|
|
768
|
+
* Transport-level close event shape.
|
|
769
|
+
*
|
|
770
|
+
* Browser `CloseEvent` is not available in every runtime that implements this
|
|
771
|
+
* duck-typed WebSocket contract (for example Bun server handlers running under
|
|
772
|
+
* Node-based test runners), but transport consumers only rely on the close
|
|
773
|
+
* code and reason.
|
|
774
|
+
*/
|
|
775
|
+
interface WebSocketCloseEvent extends Event {
|
|
776
|
+
/**
|
|
777
|
+
* WebSocket close status code.
|
|
778
|
+
*/
|
|
779
|
+
readonly code: number;
|
|
780
|
+
/**
|
|
781
|
+
* Human-readable close reason.
|
|
782
|
+
*/
|
|
783
|
+
readonly reason: string;
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* Create a transport-level close event without depending on the browser-only
|
|
787
|
+
* `CloseEvent` global.
|
|
788
|
+
* @param code - WebSocket close code.
|
|
789
|
+
* @param reason - Human-readable close reason.
|
|
790
|
+
* @returns Portable close event for {@link WebSocketLike} listeners.
|
|
791
|
+
*/
|
|
792
|
+
declare function createWebSocketCloseEvent(code?: number, reason?: string): WebSocketCloseEvent;
|
|
793
|
+
/**
|
|
794
|
+
* Client-side WebSocket interface.
|
|
795
|
+
*
|
|
796
|
+
* Compatible with browser WebSocket API and ws.WebSocket.
|
|
797
|
+
*/
|
|
798
|
+
interface WebSocketLike {
|
|
799
|
+
/**
|
|
800
|
+
* Send data over the WebSocket connection.
|
|
801
|
+
* @param data - Data to send (string, binary buffer, or Blob)
|
|
802
|
+
*/
|
|
803
|
+
send(data: string | BufferSource | Blob): void;
|
|
804
|
+
/**
|
|
805
|
+
* Close the WebSocket connection.
|
|
806
|
+
* @param code - Close code (optional)
|
|
807
|
+
* @param reason - Close reason (optional)
|
|
808
|
+
*/
|
|
809
|
+
close(code?: number, reason?: string): void;
|
|
810
|
+
/**
|
|
811
|
+
* Add an event listener.
|
|
812
|
+
* @param event - Event type
|
|
813
|
+
* @param listener - Event listener function
|
|
814
|
+
*/
|
|
815
|
+
addEventListener(event: 'message', listener: (event: MessageEvent) => void): void;
|
|
816
|
+
addEventListener(event: 'error', listener: (event: Event) => void): void;
|
|
817
|
+
addEventListener(event: 'close', listener: (event: WebSocketCloseEvent) => void): void;
|
|
818
|
+
addEventListener(event: 'open', listener: (event: Event) => void): void;
|
|
819
|
+
/**
|
|
820
|
+
* Remove an event listener.
|
|
821
|
+
* @param event - Event type
|
|
822
|
+
* @param listener - Event listener function
|
|
823
|
+
*/
|
|
824
|
+
removeEventListener(event: 'message', listener: (event: MessageEvent) => void): void;
|
|
825
|
+
removeEventListener(event: 'error', listener: (event: Event) => void): void;
|
|
826
|
+
removeEventListener(event: 'close', listener: (event: WebSocketCloseEvent) => void): void;
|
|
827
|
+
removeEventListener(event: 'open', listener: (event: Event) => void): void;
|
|
828
|
+
/**
|
|
829
|
+
* Current connection state.
|
|
830
|
+
*/
|
|
831
|
+
readonly readyState: number;
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* Server-side WebSocketServer interface.
|
|
835
|
+
*
|
|
836
|
+
* Compatible with ws.WebSocketServer.
|
|
837
|
+
*/
|
|
838
|
+
interface WebSocketServerLike {
|
|
839
|
+
/**
|
|
840
|
+
* Register a connection handler.
|
|
841
|
+
* @param event - Event type
|
|
842
|
+
* @param listener - Event listener function
|
|
843
|
+
*/
|
|
844
|
+
on(event: 'connection', listener: (socket: WebSocketLike) => void): void;
|
|
845
|
+
on(event: 'error', listener: (error: Error) => void): void;
|
|
846
|
+
on(event: 'close', listener: () => void): void;
|
|
847
|
+
/**
|
|
848
|
+
* Remove an event listener.
|
|
849
|
+
* @param event - Event type
|
|
850
|
+
* @param listener - Event listener function
|
|
851
|
+
*/
|
|
852
|
+
off(event: 'connection', listener: (socket: WebSocketLike) => void): void;
|
|
853
|
+
off(event: 'error', listener: (error: Error) => void): void;
|
|
854
|
+
off(event: 'close', listener: () => void): void;
|
|
855
|
+
/**
|
|
856
|
+
* Close the WebSocket server.
|
|
857
|
+
* @param callback - Callback when server is closed
|
|
858
|
+
*/
|
|
859
|
+
close(callback?: (err?: Error) => void): void;
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* Shared WebSocket transport configuration.
|
|
863
|
+
*/
|
|
864
|
+
interface WebSocketTransportOptionsBase {
|
|
865
|
+
/**
|
|
866
|
+
* Optional authentication strategy.
|
|
867
|
+
*/
|
|
868
|
+
auth?: TransportAuth;
|
|
869
|
+
/**
|
|
870
|
+
* Enable debug logging.
|
|
871
|
+
*/
|
|
872
|
+
debug?: boolean;
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* Client-mode WebSocket transport configuration.
|
|
876
|
+
*/
|
|
877
|
+
interface WebSocketClientTransportOptions$1 extends WebSocketTransportOptionsBase {
|
|
878
|
+
/**
|
|
879
|
+
* Transport mode: client.
|
|
880
|
+
*/
|
|
881
|
+
mode: 'client';
|
|
882
|
+
/**
|
|
883
|
+
* WebSocket instance for client mode.
|
|
884
|
+
*/
|
|
885
|
+
websocket: WebSocketLike;
|
|
886
|
+
}
|
|
887
|
+
/**
|
|
888
|
+
* Server-mode WebSocket transport configuration.
|
|
889
|
+
*/
|
|
890
|
+
interface WebSocketServerTransportOptions extends WebSocketTransportOptionsBase {
|
|
891
|
+
/**
|
|
892
|
+
* Transport mode: server.
|
|
893
|
+
*/
|
|
894
|
+
mode: 'server';
|
|
895
|
+
/**
|
|
896
|
+
* WebSocketServer instance for server mode.
|
|
897
|
+
*/
|
|
898
|
+
websocket: WebSocketServerLike;
|
|
899
|
+
}
|
|
900
|
+
/**
|
|
901
|
+
* WebSocket transport configuration (discriminated union).
|
|
902
|
+
*/
|
|
903
|
+
type WebSocketTransportOptions = WebSocketClientTransportOptions$1 | WebSocketServerTransportOptions;
|
|
904
|
+
/**
|
|
905
|
+
* Codec for encoding and decoding bus messages on the wire.
|
|
906
|
+
*
|
|
907
|
+
* Implement this interface to add transport-level encryption, custom framing,
|
|
908
|
+
* or any other wire-format transformation. Both client transports
|
|
909
|
+
* (`createClientTransport` and `WebSocketClientTransport`) accept an optional
|
|
910
|
+
* codec and fall back to a plain JSON codec when none is provided.
|
|
911
|
+
*/
|
|
912
|
+
interface ClientTransportCodec {
|
|
913
|
+
/**
|
|
914
|
+
* Encode a bus message for transmission.
|
|
915
|
+
* @param message - Bus message to encode
|
|
916
|
+
* @returns Encoded payload to send over the socket
|
|
917
|
+
*/
|
|
918
|
+
encode(message: BusMessage): Promise<string | BufferSource>;
|
|
919
|
+
/**
|
|
920
|
+
* Decode a parsed wire message into a bus message.
|
|
921
|
+
* @param message - Parsed message object
|
|
922
|
+
* @returns Bus message
|
|
923
|
+
*/
|
|
924
|
+
decode(message: unknown): Promise<BusMessage>;
|
|
925
|
+
}
|
|
926
|
+
//#endregion
|
|
927
|
+
//#region transports/ws/src/ws-client-reconnect.d.ts
|
|
928
|
+
/**
|
|
929
|
+
* Reconnection utilities for `WebSocketClientTransport`.
|
|
930
|
+
*
|
|
931
|
+
* Pure helpers for exponential-backoff timing used by the reconnect loop
|
|
932
|
+
* inside `WebSocketClientTransport`. Kept separate so the main transport
|
|
933
|
+
* module stays focused on the `BusTransport` contract.
|
|
934
|
+
*/
|
|
935
|
+
/**
|
|
936
|
+
* Reconnection configuration for `WebSocketClientTransport`.
|
|
937
|
+
*
|
|
938
|
+
* Controls exponential-backoff timing. Pass `false` to the parent options to
|
|
939
|
+
* disable automatic reconnection entirely.
|
|
940
|
+
*/
|
|
941
|
+
interface WebSocketClientTransportReconnectOptions {
|
|
942
|
+
/**
|
|
943
|
+
* Base delay in milliseconds for the first reconnect attempt.
|
|
944
|
+
* The effective minimum is 100 ms regardless of the value specified.
|
|
945
|
+
* @defaultValue 1000
|
|
946
|
+
*/
|
|
947
|
+
baseMs?: number;
|
|
948
|
+
/**
|
|
949
|
+
* Maximum delay cap in milliseconds.
|
|
950
|
+
* @defaultValue 10000
|
|
951
|
+
*/
|
|
952
|
+
maxMs?: number;
|
|
953
|
+
}
|
|
954
|
+
//#endregion
|
|
955
|
+
//#region transports/ws/src/ws-client-options.d.ts
|
|
956
|
+
/**
|
|
957
|
+
* Configuration options for `WebSocketClientTransport`.
|
|
958
|
+
*/
|
|
959
|
+
interface WebSocketClientTransportOptions {
|
|
960
|
+
/**
|
|
961
|
+
* WebSocket server URL.
|
|
962
|
+
*
|
|
963
|
+
* The transport creates and recreates the WebSocket internally — callers
|
|
964
|
+
* never pass a `WebSocket` instance directly.
|
|
965
|
+
* @example 'ws://localhost:8080/bus'
|
|
966
|
+
*/
|
|
967
|
+
url: string;
|
|
968
|
+
/**
|
|
969
|
+
* Transport identity used for registration in the bus transport registry.
|
|
970
|
+
* @defaultValue 'ws-client'
|
|
971
|
+
*/
|
|
972
|
+
name?: string;
|
|
973
|
+
/**
|
|
974
|
+
* Authentication strategy for HMAC or E2E handshakes.
|
|
975
|
+
*/
|
|
976
|
+
auth?: TransportAuth;
|
|
977
|
+
/**
|
|
978
|
+
* Wire codec for encryption or custom framing.
|
|
979
|
+
*
|
|
980
|
+
* Defaults to a plain JSON codec with no transformation.
|
|
981
|
+
*/
|
|
982
|
+
codec?: ClientTransportCodec;
|
|
983
|
+
/**
|
|
984
|
+
* Optional async transform applied to every incoming message after codec
|
|
985
|
+
* decoding, before correlation tracking and handler dispatch.
|
|
986
|
+
*
|
|
987
|
+
* Use this to inject E2E decryption or message normalization.
|
|
988
|
+
* @param message - Decoded bus message from the wire
|
|
989
|
+
* @returns Transformed message (may be the same reference if unchanged)
|
|
990
|
+
*/
|
|
991
|
+
messageTransform?: (message: BusMessage) => Promise<BusMessage>;
|
|
992
|
+
/**
|
|
993
|
+
* Automatic reconnection configuration. Defaults to exponential backoff
|
|
994
|
+
* starting at 1 s and capped at 10 s. Pass `false` to disable automatic
|
|
995
|
+
* reconnection.
|
|
996
|
+
*
|
|
997
|
+
* Note: this configures the reconnection *policy* and is distinct from the
|
|
998
|
+
* imperative {@link WebSocketClientTransport.reconnect} method, which triggers
|
|
999
|
+
* an immediate reconnect attempt.
|
|
1000
|
+
* @defaultValue `{ baseMs: 1000, maxMs: 10000 }`
|
|
1001
|
+
*/
|
|
1002
|
+
autoReconnect?: WebSocketClientTransportReconnectOptions | false;
|
|
1003
|
+
/**
|
|
1004
|
+
* WebSocket constructor factory.
|
|
1005
|
+
*
|
|
1006
|
+
* Defaults to the `ws` package's `WebSocket` loaded via dynamic import.
|
|
1007
|
+
* Override this to provide a browser `WebSocket`, a mock for testing, or any
|
|
1008
|
+
* other `WebSocketLike` implementation. The factory may be async so that
|
|
1009
|
+
* callers can defer module loading until the first connection attempt.
|
|
1010
|
+
* @param url - WebSocket server URL
|
|
1011
|
+
* @returns A `WebSocketLike` instance (not yet opened), or a Promise thereof
|
|
1012
|
+
*/
|
|
1013
|
+
createWebSocket?: (url: string) => WebSocketLike | Promise<WebSocketLike>;
|
|
1014
|
+
/**
|
|
1015
|
+
* Called each time the transport establishes a connection (initial or reconnect).
|
|
1016
|
+
*
|
|
1017
|
+
* Fired after the socket is open, authentication is complete, and subscriptions
|
|
1018
|
+
* have been replayed. Use this to trigger application-level reconnect recovery.
|
|
1019
|
+
*/
|
|
1020
|
+
onConnected?: () => void;
|
|
1021
|
+
/**
|
|
1022
|
+
* Called each time the transport loses its connection.
|
|
1023
|
+
*
|
|
1024
|
+
* Fired when the socket closes unexpectedly (not on a clean `disconnect()` call).
|
|
1025
|
+
* Use this to activate application-level disconnect recovery logic.
|
|
1026
|
+
*/
|
|
1027
|
+
onDisconnected?: () => void;
|
|
1028
|
+
/**
|
|
1029
|
+
* Enable verbose debug logging to the console.
|
|
1030
|
+
* @defaultValue false
|
|
1031
|
+
*/
|
|
1032
|
+
debug?: boolean;
|
|
1033
|
+
}
|
|
1034
|
+
//#endregion
|
|
1035
|
+
//#region transports/ws/src/ws-client-transport.d.ts
|
|
1036
|
+
/**
|
|
1037
|
+
* URL-based WebSocket client transport with built-in reconnection.
|
|
1038
|
+
*
|
|
1039
|
+
* Takes a URL and owns the full connection lifecycle — socket creation,
|
|
1040
|
+
* authentication, subscription replay, and exponential-backoff reconnection.
|
|
1041
|
+
* Callers never create or pass a `WebSocket` directly.
|
|
1042
|
+
* @example
|
|
1043
|
+
* ```typescript
|
|
1044
|
+
* const transport = new WebSocketClientTransport({ url: 'ws://localhost:8080/bus' });
|
|
1045
|
+
* await transport.connect();
|
|
1046
|
+
* await transport.subscribe('adapter.*');
|
|
1047
|
+
* ```
|
|
1048
|
+
*/
|
|
1049
|
+
declare class WebSocketClientTransport implements BusTransport {
|
|
1050
|
+
/** Transport identity for the bus registry. */
|
|
1051
|
+
readonly name: string;
|
|
1052
|
+
private readonly url;
|
|
1053
|
+
private readonly auth;
|
|
1054
|
+
private readonly codec;
|
|
1055
|
+
private readonly messageTransform;
|
|
1056
|
+
private readonly autoReconnectConfig;
|
|
1057
|
+
private readonly wsFactory;
|
|
1058
|
+
private readonly debug;
|
|
1059
|
+
private readonly onConnectedCallback;
|
|
1060
|
+
private readonly onDisconnectedCallback;
|
|
1061
|
+
private socket;
|
|
1062
|
+
private authComplete;
|
|
1063
|
+
private readonly correlations;
|
|
1064
|
+
private readonly handlers;
|
|
1065
|
+
private readonly localSubscriptions;
|
|
1066
|
+
private readonly pendingSubscriptionAcks;
|
|
1067
|
+
private subscriptionAckSeq;
|
|
1068
|
+
private messageListener;
|
|
1069
|
+
private closeListener;
|
|
1070
|
+
/** AbortController for the active reconnect loop; `null` when not connected. */
|
|
1071
|
+
private reconnectAbort;
|
|
1072
|
+
/** AbortController for the current backoff sleep; aborting wakes the sleep early. */
|
|
1073
|
+
private backoffWakeAbort;
|
|
1074
|
+
/**
|
|
1075
|
+
* Whether `runReconnectLoop` is currently executing.
|
|
1076
|
+
* Used by `reconnect()` to distinguish mid-attempt (no-op) from loop-never-started (retry).
|
|
1077
|
+
*/
|
|
1078
|
+
private reconnectLoopRunning;
|
|
1079
|
+
/** Resolver for the current ready promise; `null` once resolved. */
|
|
1080
|
+
private readyResolve;
|
|
1081
|
+
/** Resolves when the subscribe-sync-complete handshake is received; reset on each reconnect. */
|
|
1082
|
+
ready: Promise<void>;
|
|
1083
|
+
/** Set by the transport registry to track each session's ready promise for dispatch gating. */
|
|
1084
|
+
onNewReadySession: ((promise: Promise<void>) => void) | undefined;
|
|
1085
|
+
/** Set by the transport registry; called after auth + subscription replay on each connect. */
|
|
1086
|
+
onConnected: (() => void) | undefined;
|
|
1087
|
+
/** Set by the transport registry; called when the connection drops unexpectedly. */
|
|
1088
|
+
onDisconnected: (() => void) | undefined;
|
|
1089
|
+
/**
|
|
1090
|
+
* Create a new `WebSocketClientTransport`.
|
|
1091
|
+
* @param options - Transport configuration
|
|
1092
|
+
*/
|
|
1093
|
+
constructor(options: WebSocketClientTransportOptions);
|
|
1094
|
+
/**
|
|
1095
|
+
* Connect to the bus server, authenticate, replay subscriptions, and start
|
|
1096
|
+
* the reconnect loop if enabled.
|
|
1097
|
+
* @returns Promise that resolves when the initial connection is established
|
|
1098
|
+
*/
|
|
1099
|
+
connect(): Promise<void>;
|
|
1100
|
+
/**
|
|
1101
|
+
* Disconnect and clean up: stops the reconnect loop, closes the socket,
|
|
1102
|
+
* and releases auth, correlation, and handler state.
|
|
1103
|
+
* @returns Promise that resolves when the transport is fully disconnected
|
|
1104
|
+
*/
|
|
1105
|
+
disconnect(): Promise<void>;
|
|
1106
|
+
/**
|
|
1107
|
+
* Send a message over the WebSocket connection.
|
|
1108
|
+
* @param message - Bus message to send
|
|
1109
|
+
* @param timeout - Correlation timeout in milliseconds; `0` means no automatic timeout
|
|
1110
|
+
* @returns Promise resolving to response (requests), results array (broadcasts), or boolean (events)
|
|
1111
|
+
*/
|
|
1112
|
+
send<TMessage extends BusMessage>(message: TMessage, timeout?: number): Promise<TMessage extends BusRequestMessage ? unknown : TMessage extends BusBroadcastMessage ? Array<{
|
|
1113
|
+
nodeId: string;
|
|
1114
|
+
payload: unknown;
|
|
1115
|
+
}> : boolean>;
|
|
1116
|
+
/**
|
|
1117
|
+
* Register a handler for all inbound messages.
|
|
1118
|
+
* @param handler - Invoked for each decoded inbound message with optional receive context
|
|
1119
|
+
* @returns Unsubscribe function
|
|
1120
|
+
*/
|
|
1121
|
+
onReceive(handler: BusReceiveHandler): () => void;
|
|
1122
|
+
/**
|
|
1123
|
+
* Subscribe to a subject on the server with an optional payload filter.
|
|
1124
|
+
*
|
|
1125
|
+
* Buffers the subscription for reconnect replay. Sends immediately when the
|
|
1126
|
+
* socket is open. See {@link addSubscription} for full semantics.
|
|
1127
|
+
* @param subject - Subject pattern (supports wildcards like `'adapter.*'`)
|
|
1128
|
+
* @param filter - Optional payload filter for server-side smart-routing
|
|
1129
|
+
* @param priorities - Handler priorities registered for this subject
|
|
1130
|
+
* @returns Promise that resolves when buffering (and optional send) is complete
|
|
1131
|
+
*/
|
|
1132
|
+
subscribe(subject: string, filter?: PayloadFilter, priorities?: number[]): Promise<void>;
|
|
1133
|
+
/**
|
|
1134
|
+
* Unsubscribe from a subject on the server.
|
|
1135
|
+
*
|
|
1136
|
+
* Removes the subject from the replay buffer. Sends immediately when the
|
|
1137
|
+
* socket is open. See {@link removeSubscription} for full semantics.
|
|
1138
|
+
* @param subject - Subject to unsubscribe from
|
|
1139
|
+
* @returns Promise that resolves when the removal (and optional send) is complete
|
|
1140
|
+
*/
|
|
1141
|
+
unsubscribe(subject: string): Promise<void>;
|
|
1142
|
+
/** @returns Set of subject patterns currently subscribed. */
|
|
1143
|
+
getSubscriptions(): Set<string>;
|
|
1144
|
+
/**
|
|
1145
|
+
* Cancel a pending correlated request.
|
|
1146
|
+
* @param correlationId - Correlation ID to cancel
|
|
1147
|
+
* @param error - Optional cancellation error
|
|
1148
|
+
*/
|
|
1149
|
+
cancelRequest(correlationId: string, error?: Error): void;
|
|
1150
|
+
/**
|
|
1151
|
+
* Returns `true` when the socket is open (`readyState === 1`) and auth has completed.
|
|
1152
|
+
* @returns `true` if the transport can send messages
|
|
1153
|
+
*/
|
|
1154
|
+
isReady(): boolean;
|
|
1155
|
+
/**
|
|
1156
|
+
* Trigger an immediate reconnection attempt.
|
|
1157
|
+
*
|
|
1158
|
+
* Cancels an active backoff wait, starts the reconnect loop if it stalled,
|
|
1159
|
+
* or performs a one-shot connect when auto-reconnect is disabled.
|
|
1160
|
+
* @returns Promise that resolves when the attempt is initiated (loop) or completes (one-shot)
|
|
1161
|
+
*/
|
|
1162
|
+
reconnect(): Promise<void>;
|
|
1163
|
+
/**
|
|
1164
|
+
* Start the background reconnect loop; thin wrapper around `runReconnectLoop`.
|
|
1165
|
+
* @param signal - AbortSignal that stops the loop (fires on `disconnect()`)
|
|
1166
|
+
* @returns Promise that resolves when the loop exits (signal aborted)
|
|
1167
|
+
*/
|
|
1168
|
+
private startReconnectLoop;
|
|
1169
|
+
/**
|
|
1170
|
+
* Build a `SubscriptionDeps` snapshot for the subscription helpers.
|
|
1171
|
+
* @returns Subscription dependency context bound to this transport instance
|
|
1172
|
+
*/
|
|
1173
|
+
private subscriptionDeps;
|
|
1174
|
+
/**
|
|
1175
|
+
* Track one dynamic subscription update until the remote peer acknowledges it.
|
|
1176
|
+
* @returns Ack identifier, pending promise, and cleanup reject callback.
|
|
1177
|
+
*/
|
|
1178
|
+
private beginSubscriptionAck;
|
|
1179
|
+
/**
|
|
1180
|
+
* Resolve a pending dynamic subscription acknowledgement.
|
|
1181
|
+
* @param ackId - Ack identifier received from the peer.
|
|
1182
|
+
*/
|
|
1183
|
+
private resolveSubscriptionAck;
|
|
1184
|
+
/**
|
|
1185
|
+
* Reject one pending dynamic subscription acknowledgement.
|
|
1186
|
+
* @param ackId - Ack identifier to reject.
|
|
1187
|
+
* @param error - Rejection reason.
|
|
1188
|
+
*/
|
|
1189
|
+
private rejectSubscriptionAck;
|
|
1190
|
+
/**
|
|
1191
|
+
* Reject all pending subscription acknowledgements for a closing socket session.
|
|
1192
|
+
* @param error - Rejection reason.
|
|
1193
|
+
*/
|
|
1194
|
+
private rejectPendingSubscriptionAcks;
|
|
1195
|
+
/**
|
|
1196
|
+
* Build the `ConnectionDeps` context for connection lifecycle helpers.
|
|
1197
|
+
* @returns Connection dependency context bound to this transport instance
|
|
1198
|
+
*/
|
|
1199
|
+
private connectionDeps;
|
|
1200
|
+
/**
|
|
1201
|
+
* Default `ws`-package WebSocket factory (dynamic import avoids bundling in browsers).
|
|
1202
|
+
* @param url - WebSocket server URL
|
|
1203
|
+
* @returns Promise resolving to a `WebSocketLike` instance
|
|
1204
|
+
*/
|
|
1205
|
+
private readonly defaultWsFactory;
|
|
1206
|
+
/**
|
|
1207
|
+
* Wire the no-reconnect close listener; resets `reconnectAbort` on close
|
|
1208
|
+
* so `connect()` can be called again.
|
|
1209
|
+
* @param ws - The connected socket to watch for closure
|
|
1210
|
+
*/
|
|
1211
|
+
private wireNoReconnectClose;
|
|
1212
|
+
}
|
|
1213
|
+
//#endregion
|
|
1214
|
+
//#region transports/ws/src/server-transport.d.ts
|
|
1215
|
+
interface ServerTransportOptions {
|
|
1216
|
+
websocket: WebSocketServerLike;
|
|
1217
|
+
/**
|
|
1218
|
+
* Transport identity used as the registry key when registered on a bus.
|
|
1219
|
+
* @defaultValue 'websocket'
|
|
1220
|
+
*/
|
|
1221
|
+
name?: string;
|
|
1222
|
+
auth?: TransportAuth;
|
|
1223
|
+
debug?: boolean;
|
|
1224
|
+
}
|
|
1225
|
+
/**
|
|
1226
|
+
* Server-mode WebSocket transport.
|
|
1227
|
+
*
|
|
1228
|
+
* Manages multiple client connections and broadcasts messages to all connected clients.
|
|
1229
|
+
* @example
|
|
1230
|
+
* ```typescript
|
|
1231
|
+
* import { WebSocketServer } from 'ws';
|
|
1232
|
+
*
|
|
1233
|
+
* const wss = new WebSocketServer({ port: 8080 });
|
|
1234
|
+
* const transport = new ServerTransport({
|
|
1235
|
+
* websocket: wss,
|
|
1236
|
+
* });
|
|
1237
|
+
*
|
|
1238
|
+
* await transport.connect();
|
|
1239
|
+
* ```
|
|
1240
|
+
*/
|
|
1241
|
+
declare class ServerTransport implements BusTransport {
|
|
1242
|
+
/** Transport identity used as the registry key when registered on a bus. */
|
|
1243
|
+
readonly name: string;
|
|
1244
|
+
private readonly wss;
|
|
1245
|
+
private readonly auth;
|
|
1246
|
+
private readonly debug;
|
|
1247
|
+
private readonly handlers;
|
|
1248
|
+
private readonly registry;
|
|
1249
|
+
/** Server-local handler subjects + priorities, advertised to connected clients. */
|
|
1250
|
+
private readonly serverSubscriptions;
|
|
1251
|
+
private readonly broadcastAggregator;
|
|
1252
|
+
private readonly correlations;
|
|
1253
|
+
private connectionListener;
|
|
1254
|
+
/**
|
|
1255
|
+
* @param options - Server transport configuration
|
|
1256
|
+
*/
|
|
1257
|
+
constructor(options: ServerTransportOptions);
|
|
1258
|
+
/**
|
|
1259
|
+
* Send serialized data to a client without letting one socket failure disrupt fan-out.
|
|
1260
|
+
* @param client - Target client socket
|
|
1261
|
+
* @param data - Serialized message payload
|
|
1262
|
+
*/
|
|
1263
|
+
private sendToClientSafely;
|
|
1264
|
+
/**
|
|
1265
|
+
* Start listening for client connections.
|
|
1266
|
+
* @throws Error when called while the transport is already connected
|
|
1267
|
+
*/
|
|
1268
|
+
connect(): Promise<void>;
|
|
1269
|
+
/**
|
|
1270
|
+
* Stop listening and disconnect all clients.
|
|
1271
|
+
*/
|
|
1272
|
+
disconnect(): Promise<void>;
|
|
1273
|
+
/**
|
|
1274
|
+
* Send a broadcast message to all interested clients and aggregate responses.
|
|
1275
|
+
* @param message - Broadcast message to fan out
|
|
1276
|
+
* @param timeout - Broadcast response aggregation timeout in milliseconds. Use `0` to disable automatic timeout and
|
|
1277
|
+
* finalization, which can leave the returned promise pending until every target client responds or disconnects
|
|
1278
|
+
* @returns Promise resolving to aggregated results from all responding handlers
|
|
1279
|
+
*/
|
|
1280
|
+
send(message: BusBroadcastMessage, timeout?: number): Promise<Array<{
|
|
1281
|
+
nodeId: string;
|
|
1282
|
+
payload: unknown;
|
|
1283
|
+
}>>;
|
|
1284
|
+
/**
|
|
1285
|
+
* Send a request to connected clients and return the first response.
|
|
1286
|
+
* @param message - Request message
|
|
1287
|
+
* @param timeout - Correlation timeout in milliseconds; `0` means no automatic timeout
|
|
1288
|
+
* @returns Promise resolving to the handler response payload
|
|
1289
|
+
*/
|
|
1290
|
+
send(message: BusRequestMessage, timeout?: number): Promise<unknown>;
|
|
1291
|
+
/**
|
|
1292
|
+
* Send an event or other message to all interested clients.
|
|
1293
|
+
* @param message - Bus message to deliver
|
|
1294
|
+
* @param timeout - Correlation timeout in milliseconds; `0` means no automatic timeout
|
|
1295
|
+
* @returns Promise resolving to `true` if delivered to at least one client, `false` otherwise
|
|
1296
|
+
*/
|
|
1297
|
+
send(message: BusMessage, timeout?: number): Promise<boolean>;
|
|
1298
|
+
/**
|
|
1299
|
+
* Register a handler for incoming messages from clients.
|
|
1300
|
+
* @param handler - Handler function for incoming messages
|
|
1301
|
+
* @returns Unsubscribe function
|
|
1302
|
+
*/
|
|
1303
|
+
onReceive(handler: BusReceiveHandler): () => void;
|
|
1304
|
+
/**
|
|
1305
|
+
* Cancel a pending correlated server-initiated request.
|
|
1306
|
+
* @param correlationId - Correlation ID to cancel
|
|
1307
|
+
* @param error - Optional cancellation error
|
|
1308
|
+
*/
|
|
1309
|
+
cancelRequest(correlationId: string, error?: Error): void;
|
|
1310
|
+
/**
|
|
1311
|
+
* Receive aggregated broadcast results from the transport registry.
|
|
1312
|
+
*
|
|
1313
|
+
* Called directly by the transport registry after executing local handlers
|
|
1314
|
+
* and relay transports for a client-initiated broadcast, replacing the
|
|
1315
|
+
* legacy send() side-channel.
|
|
1316
|
+
* @param correlationId - Correlation ID of the originating broadcast
|
|
1317
|
+
* @param results - Aggregated results from local handlers and relay transports
|
|
1318
|
+
* @param error - Optional structured error propagated to the originator
|
|
1319
|
+
*/
|
|
1320
|
+
onBroadcastResults(correlationId: string, results: ReadonlyArray<{
|
|
1321
|
+
nodeId: string;
|
|
1322
|
+
payload: unknown;
|
|
1323
|
+
}>, error?: BusTransportError): void;
|
|
1324
|
+
/**
|
|
1325
|
+
* Advertise a server-local handler to all connected WebSocket clients.
|
|
1326
|
+
*
|
|
1327
|
+
* Called by the transport registry when a handler registers on this bus via
|
|
1328
|
+
* `bus.on()`. The full accumulated priority set for the subject is received
|
|
1329
|
+
* (replace semantics, not incremental).
|
|
1330
|
+
* @param subject - Subject pattern
|
|
1331
|
+
* @param filter - Optional payload filter
|
|
1332
|
+
* @param priorities - Handler priorities for priority-based dispatch
|
|
1333
|
+
*/
|
|
1334
|
+
subscribe(subject: string, filter?: PayloadFilter, priorities?: number[]): Promise<void>;
|
|
1335
|
+
/**
|
|
1336
|
+
* Return the number of currently authenticated and connected clients.
|
|
1337
|
+
*
|
|
1338
|
+
* Clients that are still in the authentication phase are not counted.
|
|
1339
|
+
* @returns Number of fully connected clients
|
|
1340
|
+
*/
|
|
1341
|
+
getConnectionCount(): number;
|
|
1342
|
+
/**
|
|
1343
|
+
* Remove a server-local handler advertisement from all connected clients.
|
|
1344
|
+
* @param subject - Subject pattern to unsubscribe
|
|
1345
|
+
*/
|
|
1346
|
+
unsubscribe(subject: string): Promise<void>;
|
|
1347
|
+
}
|
|
1348
|
+
//#endregion
|
|
1349
|
+
//#region transports/ws/src/transport-helpers.d.ts
|
|
1350
|
+
/**
|
|
1351
|
+
* Extract an error message from a WebSocket error event.
|
|
1352
|
+
*
|
|
1353
|
+
* Node `ws` fires `ErrorEvent` (has `.message`), browsers fire a plain `Event`
|
|
1354
|
+
* without it. This helper normalises both shapes into a string.
|
|
1355
|
+
* @param event - The error event from a WebSocket `error` listener
|
|
1356
|
+
* @param fallback - Fallback message when no `.message` property exists
|
|
1357
|
+
* @returns Human-readable error message
|
|
1358
|
+
*/
|
|
1359
|
+
declare function extractSocketErrorMessage(event: Event, fallback?: string): string;
|
|
1360
|
+
//#endregion
|
|
1361
|
+
//#region transports/ws/src/create-e2e-transport.d.ts
|
|
1362
|
+
/**
|
|
1363
|
+
* E2E transport configuration.
|
|
1364
|
+
*
|
|
1365
|
+
* The `e2eAuth` instance serves as both the TransportAuth (for the handshake)
|
|
1366
|
+
* and the session key provider (for message encryption/decryption).
|
|
1367
|
+
*
|
|
1368
|
+
* Provide a pre-created `websocket` to wrap a caller-owned socket. All other
|
|
1369
|
+
* options are forwarded to `WebSocketClientTransport` (excluding `auth`,
|
|
1370
|
+
* `messageTransform`, `url`, `createWebSocket`, and `autoReconnect`, which
|
|
1371
|
+
* are managed internally by this factory).
|
|
1372
|
+
*/
|
|
1373
|
+
interface E2ETransportOptions extends Omit<WebSocketClientTransportOptions, 'auth' | 'messageTransform' | 'url' | 'createWebSocket' | 'autoReconnect'> {
|
|
1374
|
+
/**
|
|
1375
|
+
* Pre-created WebSocket instance to wrap.
|
|
1376
|
+
*
|
|
1377
|
+
* The factory treats this socket as caller-owned and disables
|
|
1378
|
+
* auto-reconnect. When reconnect is needed, the caller is responsible for
|
|
1379
|
+
* creating new sockets.
|
|
1380
|
+
*/
|
|
1381
|
+
websocket: WebSocketLike;
|
|
1382
|
+
/**
|
|
1383
|
+
* E2E auth instance used for both handshake and encryption.
|
|
1384
|
+
*/
|
|
1385
|
+
e2eAuth: E2EAuth;
|
|
1386
|
+
}
|
|
1387
|
+
//#endregion
|
|
1388
|
+
//#region transports/ws/src/e2e-client-transport.d.ts
|
|
1389
|
+
/**
|
|
1390
|
+
* E2E client transport configuration.
|
|
1391
|
+
*
|
|
1392
|
+
* The `e2eAuth` instance serves as both the TransportAuth (for the handshake)
|
|
1393
|
+
* and the session key provider (for message encryption/decryption).
|
|
1394
|
+
*/
|
|
1395
|
+
type E2EClientTransportOptions = E2ETransportOptions;
|
|
1396
|
+
/**
|
|
1397
|
+
* Create an E2E encrypted client transport.
|
|
1398
|
+
*
|
|
1399
|
+
* Wraps a `WebSocketClientTransport` to transparently encrypt/decrypt
|
|
1400
|
+
* application payload/result/error fields using the session key established
|
|
1401
|
+
* during E2E auth.
|
|
1402
|
+
*
|
|
1403
|
+
* Decryption runs in the `messageTransform` pipeline, so response
|
|
1404
|
+
* correlation sees decrypted results and errors.
|
|
1405
|
+
* @param options - E2E client transport configuration
|
|
1406
|
+
* @returns BusTransport with E2E encryption
|
|
1407
|
+
* @example
|
|
1408
|
+
* ```typescript
|
|
1409
|
+
* const e2eAuth = new E2EAuth({
|
|
1410
|
+
* signingKeyPair,
|
|
1411
|
+
* identityId: deviceId,
|
|
1412
|
+
* peerId: machineId,
|
|
1413
|
+
* getPeerSigningKey: async () => machinePublicKey,
|
|
1414
|
+
* });
|
|
1415
|
+
*
|
|
1416
|
+
* const transport = createE2EClientTransport({
|
|
1417
|
+
* websocket: ws,
|
|
1418
|
+
* e2eAuth,
|
|
1419
|
+
* });
|
|
1420
|
+
*
|
|
1421
|
+
* await transport.connect(); // Runs E2E handshake
|
|
1422
|
+
* // Subsequent application payload/result/error fields are encrypted automatically.
|
|
1423
|
+
* ```
|
|
1424
|
+
*/
|
|
1425
|
+
declare function createE2EClientTransport(options: E2EClientTransportOptions): BusTransport;
|
|
1426
|
+
//#endregion
|
|
1427
|
+
//#region transports/ws/src/relay-control-registry.d.ts
|
|
1428
|
+
/**
|
|
1429
|
+
* Registry for relay control subjects.
|
|
1430
|
+
*
|
|
1431
|
+
* Maps namespace/subject pairs to their plaintext (control-plane) classification.
|
|
1432
|
+
* Host code registers control subjects at boot time before freezing the
|
|
1433
|
+
* registry. Once frozen, no further registrations are allowed — this enforces
|
|
1434
|
+
* the security invariant that the plaintext subject set cannot change after the
|
|
1435
|
+
* transport handshake begins.
|
|
1436
|
+
*/
|
|
1437
|
+
/**
|
|
1438
|
+
* Mutable-then-frozen registry mapping relay control namespaces and subjects.
|
|
1439
|
+
*
|
|
1440
|
+
* Callers register event subjects and request namespaces before calling
|
|
1441
|
+
* {@link RelayControlRegistry.freeze}. After freezing, all `register*` methods
|
|
1442
|
+
* throw so the set cannot be widened post-handshake.
|
|
1443
|
+
*/
|
|
1444
|
+
interface RelayControlRegistry {
|
|
1445
|
+
/**
|
|
1446
|
+
* Register a set of plaintext event subjects for a namespace.
|
|
1447
|
+
*
|
|
1448
|
+
* May be called multiple times for the same namespace — subjects accumulate.
|
|
1449
|
+
* @param namespace - Bus namespace (e.g. `'relay'`)
|
|
1450
|
+
* @param subjects - Subject names to classify as control events
|
|
1451
|
+
* @throws When called after {@link freeze}
|
|
1452
|
+
*/
|
|
1453
|
+
registerEventSubjects(namespace: string, subjects: readonly string[]): void;
|
|
1454
|
+
/**
|
|
1455
|
+
* Register an explicit allowlist of plaintext request subjects for a namespace.
|
|
1456
|
+
*
|
|
1457
|
+
* Only the listed subjects will be classified as control-plane (plaintext)
|
|
1458
|
+
* traffic for the given namespace. An explicit allowlist is required — there
|
|
1459
|
+
* is no allow-all mode — to enforce least-privilege classification.
|
|
1460
|
+
* @param namespace - Bus namespace (e.g. `'tunnel'`)
|
|
1461
|
+
* @param subjects - Explicit subject allowlist; must be non-empty
|
|
1462
|
+
* @throws When called after {@link freeze}
|
|
1463
|
+
*/
|
|
1464
|
+
registerRequestNamespace(namespace: string, subjects: readonly string[]): void;
|
|
1465
|
+
/**
|
|
1466
|
+
* Freeze the registry.
|
|
1467
|
+
*
|
|
1468
|
+
* After freezing, `registerEventSubjects` and `registerRequestNamespace`
|
|
1469
|
+
* throw on any call. Must be called before passing the registry to the
|
|
1470
|
+
* transport so the security invariant (no post-handshake plaintext injection)
|
|
1471
|
+
* is enforced.
|
|
1472
|
+
*/
|
|
1473
|
+
freeze(): void;
|
|
1474
|
+
/**
|
|
1475
|
+
* Check whether the registry has been frozen.
|
|
1476
|
+
*
|
|
1477
|
+
* The transport asserts this is `true` inside `connect()` to guarantee
|
|
1478
|
+
* the plaintext subject set cannot be widened after the handshake begins.
|
|
1479
|
+
* @returns `true` after {@link freeze} has been called
|
|
1480
|
+
*/
|
|
1481
|
+
isFrozen(): boolean;
|
|
1482
|
+
/**
|
|
1483
|
+
* Check whether an event message on the given namespace/subject is a control event.
|
|
1484
|
+
* @param namespace - Bus namespace of the event
|
|
1485
|
+
* @param subject - Subject of the event
|
|
1486
|
+
* @returns `true` when this namespace/subject pair is registered as a control event
|
|
1487
|
+
*/
|
|
1488
|
+
isControlEvent(namespace: string, subject: string): boolean;
|
|
1489
|
+
/**
|
|
1490
|
+
* Check whether a request on the given namespace/subject is a control request.
|
|
1491
|
+
* @param namespace - Bus namespace of the request
|
|
1492
|
+
* @param subject - Subject of the request
|
|
1493
|
+
* @returns `true` when this namespace/subject pair is registered as a control request
|
|
1494
|
+
*/
|
|
1495
|
+
isControlRequest(namespace: string, subject: string): boolean;
|
|
1496
|
+
}
|
|
1497
|
+
/**
|
|
1498
|
+
* Create a new mutable relay control registry.
|
|
1499
|
+
*
|
|
1500
|
+
* The registry starts unfrozen. Call `registerEventSubjects` and
|
|
1501
|
+
* `registerRequestNamespace` to populate it, then call `freeze()` before
|
|
1502
|
+
* passing it to the transport.
|
|
1503
|
+
* @returns A fresh, unfrozen {@link RelayControlRegistry}
|
|
1504
|
+
*/
|
|
1505
|
+
declare function createRelayControlRegistry(): RelayControlRegistry;
|
|
1506
|
+
//#endregion
|
|
1507
|
+
//#region transports/ws/src/e2e-relay-client-transport.d.ts
|
|
1508
|
+
/**
|
|
1509
|
+
* E2E relay client transport configuration.
|
|
1510
|
+
*
|
|
1511
|
+
* Provide a pre-created `websocket` to wrap a caller-owned socket. All other
|
|
1512
|
+
* options are forwarded to `WebSocketClientTransport` (excluding `auth`,
|
|
1513
|
+
* `messageTransform`, `url`, `codec`, `createWebSocket`, and `autoReconnect`,
|
|
1514
|
+
* which are managed internally by this factory).
|
|
1515
|
+
*/
|
|
1516
|
+
interface E2ERelayClientTransportOptions extends Omit<WebSocketClientTransportOptions, 'auth' | 'messageTransform' | 'url' | 'createWebSocket' | 'codec' | 'autoReconnect'> {
|
|
1517
|
+
/**
|
|
1518
|
+
* Pre-created WebSocket instance to wrap.
|
|
1519
|
+
*
|
|
1520
|
+
* The factory treats this socket as caller-owned and disables
|
|
1521
|
+
* auto-reconnect. When reconnect is needed, the caller is responsible for
|
|
1522
|
+
* creating new sockets.
|
|
1523
|
+
*/
|
|
1524
|
+
websocket: WebSocketLike;
|
|
1525
|
+
/**
|
|
1526
|
+
* Relay-mode E2E auth instance.
|
|
1527
|
+
*/
|
|
1528
|
+
e2eAuth: E2ERelayAuth;
|
|
1529
|
+
/**
|
|
1530
|
+
* Frozen relay control registry that classifies plaintext control subjects.
|
|
1531
|
+
*
|
|
1532
|
+
* Must be frozen before the transport begins connecting. Determines which
|
|
1533
|
+
* namespace/subject pairs are routed as relay-control envelopes rather than
|
|
1534
|
+
* E2E encrypted messages.
|
|
1535
|
+
*/
|
|
1536
|
+
registry: RelayControlRegistry;
|
|
1537
|
+
}
|
|
1538
|
+
/**
|
|
1539
|
+
* Return value of {@link createE2ERelayCodec}.
|
|
1540
|
+
*
|
|
1541
|
+
* The `reset` method clears all tracked relay-control correlation IDs so that
|
|
1542
|
+
* stale IDs from a previous WebSocket session do not bleed into the next E2E
|
|
1543
|
+
* session when the codec is reused across reconnections.
|
|
1544
|
+
*/
|
|
1545
|
+
interface E2ERelayCodecHandle {
|
|
1546
|
+
/** Wire codec for E2E relay encryption. */
|
|
1547
|
+
codec: ClientTransportCodec;
|
|
1548
|
+
/**
|
|
1549
|
+
* Clear all relay-control correlation IDs.
|
|
1550
|
+
*
|
|
1551
|
+
* Must be called at the start of each new connection attempt when the same
|
|
1552
|
+
* codec instance is reused across {@link WebSocketClientTransport}
|
|
1553
|
+
* reconnections (e.g. inside `authenticateClient`).
|
|
1554
|
+
*/
|
|
1555
|
+
reset: () => void;
|
|
1556
|
+
}
|
|
1557
|
+
/**
|
|
1558
|
+
* Create the wire codec for an E2E encrypted relay transport.
|
|
1559
|
+
*
|
|
1560
|
+
* The codec handles message encryption/decryption and relay-control envelope
|
|
1561
|
+
* routing. Use this when constructing a `WebSocketClientTransport` with E2E
|
|
1562
|
+
* relay encryption instead of the lower-level `createE2ERelayClientTransport`.
|
|
1563
|
+
*
|
|
1564
|
+
* The returned `reset()` method **must** be called at the start of each new
|
|
1565
|
+
* connection attempt when the codec is reused across reconnections. Failing to
|
|
1566
|
+
* reset allows relay-control correlation IDs from a previous session to
|
|
1567
|
+
* influence routing decisions in the new E2E session.
|
|
1568
|
+
* @param e2eAuth - Relay-mode E2E auth instance
|
|
1569
|
+
* @param registry - Frozen relay control registry for subject classification
|
|
1570
|
+
* @param debug - Enable diagnostic logging
|
|
1571
|
+
* @returns Codec handle containing the wire codec and a session-reset function
|
|
1572
|
+
*/
|
|
1573
|
+
declare function createE2ERelayCodec(e2eAuth: E2ERelayAuth, registry: RelayControlRegistry, debug?: boolean): E2ERelayCodecHandle;
|
|
1574
|
+
/**
|
|
1575
|
+
* Create an E2E encrypted relay client transport.
|
|
1576
|
+
* @param options - Transport configuration
|
|
1577
|
+
* @returns BusTransport with relay-mode E2E encryption
|
|
1578
|
+
*/
|
|
1579
|
+
declare function createE2ERelayClientTransport(options: E2ERelayClientTransportOptions): BusTransport;
|
|
1580
|
+
//#endregion
|
|
1581
|
+
//#region transports/ws/src/relay-control-envelope.d.ts
|
|
1582
|
+
/**
|
|
1583
|
+
* Relay control envelope message shape used on the wire.
|
|
1584
|
+
*/
|
|
1585
|
+
interface RelayControlEnvelopeMessage {
|
|
1586
|
+
type: 'relay-control';
|
|
1587
|
+
payload: RelayControlBusMessage;
|
|
1588
|
+
v: 1;
|
|
1589
|
+
}
|
|
1590
|
+
/** Bus message type that may be wrapped in a relay control envelope. */
|
|
1591
|
+
type RelayControlBusMessage = BusEventMessage | BusRequestMessage;
|
|
1592
|
+
/**
|
|
1593
|
+
* Return value of {@link createRelayControlHelpers}.
|
|
1594
|
+
*
|
|
1595
|
+
* All three helpers share the same {@link RelayControlRegistry} captured in
|
|
1596
|
+
* their common closure.
|
|
1597
|
+
*/
|
|
1598
|
+
interface RelayControlHelpers {
|
|
1599
|
+
/**
|
|
1600
|
+
* Create a relay control envelope for a relay-owned bus message.
|
|
1601
|
+
*
|
|
1602
|
+
* Throws when the message is not classified as a control message by the
|
|
1603
|
+
* registry (i.e. would not pass {@link isRelayControlBusMessage}).
|
|
1604
|
+
* @param message - Relay bus message to wrap
|
|
1605
|
+
* @returns Relay control envelope message
|
|
1606
|
+
*/
|
|
1607
|
+
createRelayControlEnvelope(message: RelayControlBusMessage): RelayControlEnvelopeMessage;
|
|
1608
|
+
/**
|
|
1609
|
+
* Check whether a parsed wire value is a relay control envelope.
|
|
1610
|
+
* @param message - Parsed message candidate
|
|
1611
|
+
* @returns `true` if the value is a relay control envelope
|
|
1612
|
+
*/
|
|
1613
|
+
isRelayControlEnvelopeMessage(message: unknown): message is RelayControlEnvelopeMessage;
|
|
1614
|
+
/**
|
|
1615
|
+
* Check whether a bus message is a relay control event or request.
|
|
1616
|
+
* @param message - Bus message candidate
|
|
1617
|
+
* @returns `true` when the message is classified as a relay control message
|
|
1618
|
+
*/
|
|
1619
|
+
isRelayControlBusMessage(message: unknown): message is RelayControlBusMessage;
|
|
1620
|
+
}
|
|
1621
|
+
/**
|
|
1622
|
+
* Create relay control envelope helpers bound to a specific registry.
|
|
1623
|
+
*
|
|
1624
|
+
* The registry must be {@link RelayControlRegistry.freeze | frozen} before
|
|
1625
|
+
* calling this function — or at minimum before the transport begins
|
|
1626
|
+
* processing messages — so the security invariant (no post-handshake
|
|
1627
|
+
* plaintext injection) is upheld.
|
|
1628
|
+
* @param registry - Frozen relay control registry
|
|
1629
|
+
* @returns Helper functions with the registry captured in their closure
|
|
1630
|
+
*/
|
|
1631
|
+
declare function createRelayControlHelpers(registry: RelayControlRegistry): RelayControlHelpers;
|
|
1632
|
+
//#endregion
|
|
1633
|
+
//#region transports/ws/src/crypto/ecdh.d.ts
|
|
1634
|
+
/**
|
|
1635
|
+
* ECDH (Elliptic Curve Diffie-Hellman) key management using Web Crypto API.
|
|
1636
|
+
*
|
|
1637
|
+
* Implements ECDH P-256 for secure key exchange in E2E encryption.
|
|
1638
|
+
* Uses Web Crypto API for browser and Node.js compatibility.
|
|
1639
|
+
*/
|
|
1640
|
+
/**
|
|
1641
|
+
* Generate an ECDH P-256 keypair.
|
|
1642
|
+
*
|
|
1643
|
+
* Creates a new elliptic curve keypair for ECDH key exchange.
|
|
1644
|
+
* The P-256 curve is universally supported by Web Crypto API.
|
|
1645
|
+
* @param extractable - Whether the private key can be exported. Set to false for browser device keys (security), true for Node.js server keys (persistence).
|
|
1646
|
+
* @returns Promise resolving to CryptoKeyPair
|
|
1647
|
+
*/
|
|
1648
|
+
declare function generateECDHKeyPair(extractable?: boolean): Promise<CryptoKeyPair>;
|
|
1649
|
+
/**
|
|
1650
|
+
* Export public key to base64url (SPKI format).
|
|
1651
|
+
* @param key - Public CryptoKey to export
|
|
1652
|
+
* @returns Promise resolving to base64url-encoded public key
|
|
1653
|
+
*/
|
|
1654
|
+
declare function exportPublicKey(key: CryptoKey): Promise<string>;
|
|
1655
|
+
/**
|
|
1656
|
+
* Export ECDH public key to base64url (raw format).
|
|
1657
|
+
* @param key - Public CryptoKey to export
|
|
1658
|
+
* @returns Base64url-encoded raw public key
|
|
1659
|
+
*/
|
|
1660
|
+
declare function exportPublicKeyRaw(key: CryptoKey): Promise<string>;
|
|
1661
|
+
/**
|
|
1662
|
+
* Import ECDH public key from base64url raw format.
|
|
1663
|
+
* @param base64url - Base64url-encoded raw public key
|
|
1664
|
+
* @returns Imported CryptoKey for ECDH operations
|
|
1665
|
+
*/
|
|
1666
|
+
declare function importPublicKeyRaw(base64url: string): Promise<CryptoKey>;
|
|
1667
|
+
/**
|
|
1668
|
+
* Import public key from base64url (SPKI format).
|
|
1669
|
+
* @param base64url - Base64url-encoded public key (SPKI format)
|
|
1670
|
+
* @param usages - Key usages (default: empty for public keys used only in deriveBits)
|
|
1671
|
+
* @returns Promise resolving to imported CryptoKey
|
|
1672
|
+
*/
|
|
1673
|
+
declare function importPublicKey(base64url: string, usages?: KeyUsage[]): Promise<CryptoKey>;
|
|
1674
|
+
/**
|
|
1675
|
+
* Export private key to PKCS8 PEM format (for Node.js file storage).
|
|
1676
|
+
* @param key - Private CryptoKey to export
|
|
1677
|
+
* @returns Promise resolving to PEM string
|
|
1678
|
+
* @throws Error if key is non-extractable
|
|
1679
|
+
*/
|
|
1680
|
+
declare function exportPrivateKeyPEM(key: CryptoKey): Promise<string>;
|
|
1681
|
+
/**
|
|
1682
|
+
* Import private key from PKCS8 PEM format.
|
|
1683
|
+
* @param pem - PEM-encoded private key string
|
|
1684
|
+
* @returns Promise resolving to imported CryptoKey
|
|
1685
|
+
*/
|
|
1686
|
+
declare function importPrivateKeyPEM(pem: string): Promise<CryptoKey>;
|
|
1687
|
+
/**
|
|
1688
|
+
* Derive shared secret via ECDH.
|
|
1689
|
+
*
|
|
1690
|
+
* Performs ECDH key agreement: combines own private key with peer's public key
|
|
1691
|
+
* to derive a shared secret. Both parties derive the same secret.
|
|
1692
|
+
* @param privateKey - Own private key
|
|
1693
|
+
* @param publicKey - Peer's public key
|
|
1694
|
+
* @returns Promise resolving to raw shared secret as ArrayBuffer
|
|
1695
|
+
*/
|
|
1696
|
+
declare function deriveSharedSecret(privateKey: CryptoKey, publicKey: CryptoKey): Promise<ArrayBuffer>;
|
|
1697
|
+
//#endregion
|
|
1698
|
+
//#region transports/ws/src/crypto/aes-gcm.d.ts
|
|
1699
|
+
/**
|
|
1700
|
+
* AES-256-GCM encryption and decryption using Web Crypto API.
|
|
1701
|
+
*
|
|
1702
|
+
* AES-GCM provides authenticated encryption: both confidentiality
|
|
1703
|
+
* and integrity protection in a single operation.
|
|
1704
|
+
*/
|
|
1705
|
+
/**
|
|
1706
|
+
* Encrypt plaintext with AES-256-GCM.
|
|
1707
|
+
*
|
|
1708
|
+
* Generates a random 12-byte nonce and encrypts data.
|
|
1709
|
+
* The nonce must be transmitted alongside the ciphertext for decryption.
|
|
1710
|
+
* @param key - AES-256 CryptoKey
|
|
1711
|
+
* @param plaintext - Data to encrypt (Uint8Array)
|
|
1712
|
+
* @returns Promise resolving to object with ciphertext and nonce
|
|
1713
|
+
* @example
|
|
1714
|
+
* ```typescript
|
|
1715
|
+
* const sessionKey = await deriveSessionKey(...);
|
|
1716
|
+
* const plaintext = encodeText(JSON.stringify(payload));
|
|
1717
|
+
* const { ciphertext, nonce } = await encrypt(sessionKey, plaintext);
|
|
1718
|
+
* // Send both ciphertext and nonce to peer
|
|
1719
|
+
* ```
|
|
1720
|
+
*/
|
|
1721
|
+
declare function encrypt(key: CryptoKey, plaintext: Uint8Array): Promise<{
|
|
1722
|
+
ciphertext: Uint8Array;
|
|
1723
|
+
nonce: Uint8Array;
|
|
1724
|
+
}>;
|
|
1725
|
+
/**
|
|
1726
|
+
* Decrypt ciphertext with AES-256-GCM.
|
|
1727
|
+
*
|
|
1728
|
+
* Decrypts data using the same nonce that was used for encryption.
|
|
1729
|
+
* Automatically verifies the authentication tag - throws if data was tampered with.
|
|
1730
|
+
* @param key - AES-256 CryptoKey
|
|
1731
|
+
* @param ciphertext - Encrypted data
|
|
1732
|
+
* @param nonce - 12-byte nonce used during encryption
|
|
1733
|
+
* @returns Promise resolving to decrypted Uint8Array
|
|
1734
|
+
* @throws Error if authentication fails (data tampered with)
|
|
1735
|
+
* @example
|
|
1736
|
+
* ```typescript
|
|
1737
|
+
* const plaintext = await decrypt(sessionKey, ciphertext, nonce);
|
|
1738
|
+
* const payload = JSON.parse(decodeText(plaintext));
|
|
1739
|
+
* ```
|
|
1740
|
+
*/
|
|
1741
|
+
declare function decrypt(key: CryptoKey, ciphertext: Uint8Array, nonce: Uint8Array): Promise<Uint8Array>;
|
|
1742
|
+
/**
|
|
1743
|
+
* Import raw AES-256-GCM key.
|
|
1744
|
+
*
|
|
1745
|
+
* Converts raw key material (from HKDF) into a CryptoKey for encryption/decryption.
|
|
1746
|
+
* @param rawKey - 32-byte raw key material (256 bits)
|
|
1747
|
+
* @returns Promise resolving to AES-256 CryptoKey
|
|
1748
|
+
* @example
|
|
1749
|
+
* ```typescript
|
|
1750
|
+
* const rawSessionKey = await deriveSessionKeyRaw(...);
|
|
1751
|
+
* const sessionKey = await importAESKey(rawSessionKey);
|
|
1752
|
+
* ```
|
|
1753
|
+
*/
|
|
1754
|
+
declare function importAESKey(rawKey: ArrayBuffer): Promise<CryptoKey>;
|
|
1755
|
+
//#endregion
|
|
1756
|
+
//#region transports/ws/src/crypto/hkdf.d.ts
|
|
1757
|
+
/**
|
|
1758
|
+
* HKDF (HMAC-based Key Derivation Function) using Web Crypto API.
|
|
1759
|
+
*
|
|
1760
|
+
* Derives a session encryption key from ECDH shared secret.
|
|
1761
|
+
* HKDF provides key stretching and domain separation.
|
|
1762
|
+
*/
|
|
1763
|
+
/**
|
|
1764
|
+
* Derive AES-256 key from shared secret using HKDF-SHA256.
|
|
1765
|
+
*
|
|
1766
|
+
* Performs HKDF key derivation to convert raw ECDH shared secret
|
|
1767
|
+
* into a proper AES-256 session key. Uses salt for randomness
|
|
1768
|
+
* and info for domain separation.
|
|
1769
|
+
* @param sharedSecret - Raw shared secret from ECDH (ArrayBuffer)
|
|
1770
|
+
* @param salt - Salt bytes (can be random or fixed context). Recommended: 16+ bytes of randomness.
|
|
1771
|
+
* @param info - Context string for domain separation (e.g., "makaio-e2e-session-v1")
|
|
1772
|
+
* @returns Promise resolving to AES-256 CryptoKey
|
|
1773
|
+
* @example
|
|
1774
|
+
* ```typescript
|
|
1775
|
+
* const sharedSecret = await deriveSharedSecret(myPrivateKey, peerPublicKey);
|
|
1776
|
+
* const salt = crypto.getRandomValues(new Uint8Array(16));
|
|
1777
|
+
* const sessionKey = await deriveSessionKey(sharedSecret, salt, "makaio-e2e-session-v1");
|
|
1778
|
+
* ```
|
|
1779
|
+
*/
|
|
1780
|
+
declare function deriveSessionKey(sharedSecret: ArrayBuffer, salt: Uint8Array, info: string): Promise<CryptoKey>;
|
|
1781
|
+
//#endregion
|
|
1782
|
+
//#region transports/ws/src/crypto/ecdsa.d.ts
|
|
1783
|
+
/**
|
|
1784
|
+
* ECDSA (Elliptic Curve Digital Signature Algorithm) using Web Crypto API.
|
|
1785
|
+
*
|
|
1786
|
+
* Implements ECDSA P-256 SHA-256 for signing ephemeral public keys
|
|
1787
|
+
* during E2E authentication handshake.
|
|
1788
|
+
*/
|
|
1789
|
+
/**
|
|
1790
|
+
* Generate an ECDSA P-256 signing keypair.
|
|
1791
|
+
*
|
|
1792
|
+
* Creates a new elliptic curve keypair for digital signatures.
|
|
1793
|
+
* The P-256 curve with SHA-256 is universally supported by Web Crypto API.
|
|
1794
|
+
* @param extractable - Whether the private key can be exported. Set to false for browser device keys (security), true for Node.js server keys (persistence).
|
|
1795
|
+
* @returns Promise resolving to CryptoKeyPair
|
|
1796
|
+
*/
|
|
1797
|
+
declare function generateSigningKeyPair(extractable?: boolean): Promise<CryptoKeyPair>;
|
|
1798
|
+
/**
|
|
1799
|
+
* Sign data with ECDSA P-256 SHA-256.
|
|
1800
|
+
*
|
|
1801
|
+
* Creates a digital signature over the data using the private key.
|
|
1802
|
+
* @param privateKey - Signing private key
|
|
1803
|
+
* @param data - Data to sign (Uint8Array)
|
|
1804
|
+
* @returns Promise resolving to signature as Uint8Array
|
|
1805
|
+
*/
|
|
1806
|
+
declare function sign(privateKey: CryptoKey, data: Uint8Array): Promise<Uint8Array>;
|
|
1807
|
+
/**
|
|
1808
|
+
* Verify ECDSA P-256 SHA-256 signature.
|
|
1809
|
+
*
|
|
1810
|
+
* Verifies that the signature was created by the holder of the private key
|
|
1811
|
+
* corresponding to the public key.
|
|
1812
|
+
* @param publicKey - Verification public key
|
|
1813
|
+
* @param signature - Signature to verify
|
|
1814
|
+
* @param data - Original data that was signed
|
|
1815
|
+
* @returns Promise resolving to true if signature is valid, false otherwise
|
|
1816
|
+
*/
|
|
1817
|
+
declare function verify(publicKey: CryptoKey, signature: Uint8Array, data: Uint8Array): Promise<boolean>;
|
|
1818
|
+
/**
|
|
1819
|
+
* Export signing public key to base64url (SPKI format).
|
|
1820
|
+
* @param key - Public CryptoKey to export
|
|
1821
|
+
* @returns Promise resolving to base64url-encoded public key
|
|
1822
|
+
*/
|
|
1823
|
+
declare function exportSigningPublicKey(key: CryptoKey): Promise<string>;
|
|
1824
|
+
/**
|
|
1825
|
+
* Import signing public key from base64url for verification.
|
|
1826
|
+
* @param base64url - Base64url-encoded public key (SPKI format)
|
|
1827
|
+
* @returns Promise resolving to imported CryptoKey for verification
|
|
1828
|
+
*/
|
|
1829
|
+
declare function importSigningPublicKey(base64url: string): Promise<CryptoKey>;
|
|
1830
|
+
/**
|
|
1831
|
+
* Export signing public key to base64url (raw format).
|
|
1832
|
+
* @param key - Public CryptoKey to export
|
|
1833
|
+
* @returns Base64url-encoded raw public key
|
|
1834
|
+
*/
|
|
1835
|
+
declare function exportSigningPublicKeyRaw(key: CryptoKey): Promise<string>;
|
|
1836
|
+
/**
|
|
1837
|
+
* Import signing public key from base64url raw format.
|
|
1838
|
+
* @param base64url - Base64url-encoded raw public key
|
|
1839
|
+
* @returns Imported CryptoKey for verification
|
|
1840
|
+
*/
|
|
1841
|
+
declare function importSigningPublicKeyRaw(base64url: string): Promise<CryptoKey>;
|
|
1842
|
+
/**
|
|
1843
|
+
* Export signing private key to PKCS8 PEM format (for Node.js file storage).
|
|
1844
|
+
* @param key - Private CryptoKey to export
|
|
1845
|
+
* @returns Promise resolving to PEM string
|
|
1846
|
+
* @throws Error if key is non-extractable
|
|
1847
|
+
*/
|
|
1848
|
+
declare function exportSigningPrivateKeyPEM(key: CryptoKey): Promise<string>;
|
|
1849
|
+
/**
|
|
1850
|
+
* Import signing private key from PKCS8 PEM format.
|
|
1851
|
+
* @param pem - PEM-encoded private key string
|
|
1852
|
+
* @returns Promise resolving to imported CryptoKey
|
|
1853
|
+
*/
|
|
1854
|
+
declare function importSigningPrivateKeyPEM(pem: string): Promise<CryptoKey>;
|
|
1855
|
+
//#endregion
|
|
1856
|
+
//#region transports/ws/src/crypto/encoding.d.ts
|
|
1857
|
+
/**
|
|
1858
|
+
* Base64url encoding utilities for cryptographic data.
|
|
1859
|
+
*
|
|
1860
|
+
* Uses URL-safe base64 encoding (RFC 4648) without padding.
|
|
1861
|
+
* Standard for encoding binary crypto material in JSON/URLs.
|
|
1862
|
+
*/
|
|
1863
|
+
/**
|
|
1864
|
+
* Encode Uint8Array to base64url string.
|
|
1865
|
+
*
|
|
1866
|
+
* Converts binary data to URL-safe base64 string without padding.
|
|
1867
|
+
* Uses chunked approach to avoid call stack overflow on large payloads.
|
|
1868
|
+
* @param data - Binary data to encode
|
|
1869
|
+
* @returns Base64url-encoded string
|
|
1870
|
+
* @example
|
|
1871
|
+
* ```typescript
|
|
1872
|
+
* const nonce = crypto.getRandomValues(new Uint8Array(12));
|
|
1873
|
+
* const encoded = toBase64Url(nonce); // "Zj4Qr..." (no padding)
|
|
1874
|
+
* ```
|
|
1875
|
+
*/
|
|
1876
|
+
declare function toBase64Url(data: Uint8Array): string;
|
|
1877
|
+
/**
|
|
1878
|
+
* Decode base64url string to Uint8Array.
|
|
1879
|
+
*
|
|
1880
|
+
* Converts URL-safe base64 string back to binary data.
|
|
1881
|
+
* @param base64url - Base64url-encoded string
|
|
1882
|
+
* @returns Binary data as Uint8Array
|
|
1883
|
+
* @throws Error if input is not valid base64url
|
|
1884
|
+
* @example
|
|
1885
|
+
* ```typescript
|
|
1886
|
+
* const data = fromBase64Url("Zj4Qr...");
|
|
1887
|
+
* ```
|
|
1888
|
+
*/
|
|
1889
|
+
declare function fromBase64Url(base64url: string): Uint8Array;
|
|
1890
|
+
/**
|
|
1891
|
+
* Encode string to Uint8Array (UTF-8).
|
|
1892
|
+
*
|
|
1893
|
+
* Converts text to binary using UTF-8 encoding.
|
|
1894
|
+
* @param text - String to encode
|
|
1895
|
+
* @returns UTF-8 encoded bytes
|
|
1896
|
+
* @example
|
|
1897
|
+
* ```typescript
|
|
1898
|
+
* const data = encodeText("Hello, world!");
|
|
1899
|
+
* ```
|
|
1900
|
+
*/
|
|
1901
|
+
declare function encodeText(text: string): Uint8Array;
|
|
1902
|
+
/**
|
|
1903
|
+
* Decode Uint8Array to string (UTF-8).
|
|
1904
|
+
*
|
|
1905
|
+
* Converts binary data to text using UTF-8 decoding.
|
|
1906
|
+
* @param data - Binary data to decode
|
|
1907
|
+
* @returns Decoded string
|
|
1908
|
+
* @example
|
|
1909
|
+
* ```typescript
|
|
1910
|
+
* const text = decodeText(data);
|
|
1911
|
+
* ```
|
|
1912
|
+
*/
|
|
1913
|
+
declare function decodeText(data: Uint8Array): string;
|
|
1914
|
+
declare namespace index_d_exports {
|
|
1915
|
+
export { decodeText, decrypt, deriveSessionKey, deriveSharedSecret, encodeText, encrypt, exportPrivateKeyPEM, exportPublicKey, exportPublicKeyRaw, exportSigningPrivateKeyPEM, exportSigningPublicKey, exportSigningPublicKeyRaw, fromBase64Url, generateECDHKeyPair, generateSigningKeyPair, importAESKey, importPrivateKeyPEM, importPublicKey, importPublicKeyRaw, importSigningPrivateKeyPEM, importSigningPublicKey, importSigningPublicKeyRaw, sign, toBase64Url, verify };
|
|
1916
|
+
}
|
|
1917
|
+
//#endregion
|
|
1918
|
+
//#region transports/ws/src/index.d.ts
|
|
1919
|
+
/**
|
|
1920
|
+
* Create a WebSocket transport for the specified mode.
|
|
1921
|
+
*
|
|
1922
|
+
* For client mode the transport wraps a pre-created `WebSocket` via
|
|
1923
|
+
* `WebSocketClientTransport`. Because this factory accepts an already-created
|
|
1924
|
+
* socket, caller-supplied dial-time `connectionOptions` cannot be honored here;
|
|
1925
|
+
* use `WebSocketClientTransport` directly when you need reconnect or socket
|
|
1926
|
+
* creation options.
|
|
1927
|
+
* @param options - Transport configuration
|
|
1928
|
+
* @returns BusTransport instance
|
|
1929
|
+
*/
|
|
1930
|
+
declare function createWebSocketTransport(options: WebSocketTransportOptions): BusTransport;
|
|
1931
|
+
/**
|
|
1932
|
+
* Module augmentation for BusTransportRegistry.
|
|
1933
|
+
*
|
|
1934
|
+
* This enables type-safe access to the WebSocket transport:
|
|
1935
|
+
* ```typescript
|
|
1936
|
+
* const transport = getTransport('websocket'); // Type: BusTransport
|
|
1937
|
+
* ```
|
|
1938
|
+
*/
|
|
1939
|
+
declare module '@makaio/framework/bus' {
|
|
1940
|
+
interface BusTransportRegistry {
|
|
1941
|
+
websocket: BusTransport;
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
//#endregion
|
|
1945
|
+
export { type ClientTransportCodec, DispatchingAuth, E2EAuth, E2ERelayAuth, type E2ERelayAuthOptions, HmacAuth, type HmacIdentitySecretRegistrationOptions, type RelayControlBusMessage, type RelayControlEnvelopeMessage, type RelayControlHelpers, type RelayControlRegistry, ServerTransport, type TransportAuth, WebSocketClientTransport, type WebSocketClientTransportOptions, type WebSocketClientTransportReconnectOptions, type WebSocketCloseEvent, type WebSocketLike, type WebSocketServerLike, clearHmacIdentitySecretsForTesting, createE2EClientTransport, createE2ERelayClientTransport, createE2ERelayCodec, createRelayControlHelpers, createRelayControlRegistry, createWebSocketCloseEvent, createWebSocketTransport, index_d_exports as crypto, extractSocketErrorMessage, registerHmacIdentitySecret, resolveHmacIdentityPeer, resolveHmacIdentitySecret };
|