actions/register_ws_endpoint.ts

Composed WebSocket endpoint registration — the primitive create_app_server mounts each ws_endpoints entry with. An app assembled by create_app_server declares its endpoints there rather than calling this, and gets the shared action rate limiters, the origin default, the surface entry, and the audit guard with them.

Wraps the standard upgrade stack:

  1. verify_request_source(allowed_origins) — reject disallowed origins before the upgrade handshake runs.
  2. require_auth — reject unauthenticated upgrades.
  3. require_token_scope('surface:ws_upgrade') — rule 3: a narrowed token cannot hold a socket. Mounted here, ahead of the role guard, so a narrowed token is told about its scope rather than about a role it also lacks. register_action_ws repeats the check on its own route chain, which is what covers consumers mounting it directly; the earlier answer wins when both are wired.
  4. Authorization phase — resolve the acting actor against the authenticated account plus an optional ?acting=<uuid> query string, and build the RequestContext that per-message dispatch reads. Multi-actor accounts must supply ?acting to pick a persona; single-actor accounts work without it.
  5. Optional require_role(required_roles) — for endpoints gated to a non-empty any-of set of roles.

Then delegates to register_action_ws for per-message JSON-RPC dispatch.

view source

Declarations
#

2 declarations

register_ws_endpoint
#

actions/register_ws_endpoint.ts view source

(options: RegisterWsEndpointOptions): RegisterActionWsResult import {register_ws_endpoint} from '@fuzdev/fuz_app/actions/register_ws_endpoint.js';

Mount a WebSocket endpoint with the standard upgrade stack (origin check + auth + token scope + actor resolution + optional role) and JSON-RPC dispatch.

Returns the BackendWebsocketTransport (supplied or freshly created), same as register_action_ws — retain it to wire create_ws_auth_guard on on_audit_event or to broadcast.

options

returns

RegisterActionWsResult

mutates

  • options.app — applies origin/auth/scope/authorization/role middleware via `app.use`, then registers the `GET path` route via the inner `register_action_ws`
  • options.connection_closer — adds the endpoint's transport, once the mount has succeeded, for good — pass `null` and add it yourself to hold the remover

RegisterWsEndpointOptions
#

actions/register_ws_endpoint.ts view source

RegisterWsEndpointOptions import type {RegisterWsEndpointOptions} from '@fuzdev/fuz_app/actions/register_ws_endpoint.js';

inheritance

allowed_origins

Origin allowlist regexes — typically parsed from the FUZ_ALLOWED_ORIGINS env var via parse_allowed_origins. Passed straight to verify_request_source.

type readonly RegExp[]

required_roles?

Roles permitted to upgrade — any-of disjunction (matches the underlying require_role semantics). Omit (or pass []) for any authenticated account (require_auth + actor resolution alone); set to e.g. [ROLE_ADMIN] to gate the endpoint behind a single role or [ROLE_ADMIN, ROLE_KEEPER] to permit either. The per-action auth in each spec still applies at dispatch time — this is a coarse upgrade-time gate.

type readonly string[]

Depends on
#

Imported by
#