auth/admin_actions.ts

Admin RPC action handlers — admin-only operations exposed on the JSON-RPC surface.

Four action categories:

  • Account management: admin_account_list, admin_session_list, admin_session_revoke_all, admin_token_revoke_all.
  • Audit log reads: audit_log_list, audit_log_role_grant_history.
  • Invite CRUD: invite_create, invite_list, invite_delete.
  • App settings: app_settings_get, app_settings_update. The update handler writes the app_settings row in the database; signup reads the open_signup toggle fresh from that row on every request, so no in-memory state is shared between this surface and signup.

The action specs themselves live in auth/admin_action_specs.ts. Mutations emit matching audit events via deps.audit.emit.

Authorization is declared at the spec level (auth: {role: 'admin'}) so the RPC dispatcher enforces it before the handler runs and the generated surface accurately reports the requirement. role_grant_revoke in auth/role_grant_offer_actions.ts uses the same spec-level pattern even though its sibling methods are authenticated-but-not-admin — the dispatcher checks auth per-spec, so mixed-auth endpoints compose cleanly. Handler-level gates are reserved for input-dependent elevation (e.g. role_grant_offer_list/_history elevate to admin only when the caller passes an account_id other than their own — an input-dependent check the spec can't express).

view source

Declarations
#

2 declarations

AdminActionOptions
#

auth/admin_actions.ts view source

AdminActionOptions import type {AdminActionOptions} from '@fuzdev/fuz_app/auth/admin_actions.js';

roles?

Role schema result from create_role_schema(). Defaults to builtin roles only. Used to derive grantable_roles (the subset whose RoleSpec.grant_paths includes 'admin') returned by admin_account_list.

type RoleSchemaResult

connection_closer?

Live-connection closer — when set, admin_session_revoke_all and admin_token_revoke_all handlers eagerly close affected WebSocket sockets for the target account BEFORE emitting the corresponding audit event. Mirrors the self-service surface (see AccountActionOptions.connection_closer). BackendWebsocketTransport satisfies this interface structurally. When absent, only the listener-based close (transports_ws_auth_guard) runs.

type ConnectionCloser | null

create_admin_actions
#

auth/admin_actions.ts view source

(deps: ActionFactoryDeps, options?: AdminActionOptions): RpcAction[] import {create_admin_actions} from '@fuzdev/fuz_app/auth/admin_actions.js';

Create the admin-only RPC actions.

deps

ActionFactoryDeps (log, audit). log drives RPC- internal error logging; audit.emit writes audit rows via the captured pool. The bound emitter encapsulates listener fan-out and the optional AuditLogConfig.

options

role schema for grantable_roles derivation

default {}

returns

RpcAction[]

the RpcAction array to spread into a create_rpc_endpoint call

Depends on
#

Imported by
#