hono_context.ts

Hono context variable augmentation for fuz_app.

Cross-cutting shared vocabulary — defines the Hono ContextVariableMap variables used by auth, http, server, and testing modules.

Auto-loaded by server/app_server.ts (side-effect import) and transitively by auth middleware modules that import CREDENTIAL_TYPE_KEY. Consumers don't need a manual import unless bypassing the standard server assembly.

view source

Declarations
#

7 declarations

ACCOUNT_ID_KEY
#

hono_context.ts view source

"auth_account_id" import {ACCOUNT_ID_KEY} from '@fuzdev/fuz_app/hono_context.js';

Hono context variable name for the authenticated account id.

Set by the auth middleware (session, bearer, or daemon token) on a valid credential. null for unauthenticated requests. The route-spec wrapper / RPC dispatcher's authorization phase reads this when resolving the acting actor; account-grain auth guards (require_auth) and account-grain handlers read it directly.

AUTH_API_TOKEN_ID_KEY
#

hono_context.ts view source

"auth_api_token_id" import {AUTH_API_TOKEN_ID_KEY} from '@fuzdev/fuz_app/hono_context.js';

Hono context variable name for the authenticated API token id.

CREDENTIAL_TYPE_KEY
#

hono_context.ts view source

"credential_type" import {CREDENTIAL_TYPE_KEY} from '@fuzdev/fuz_app/hono_context.js';

Hono context variable name for the credential type.

CREDENTIAL_TYPES
#

hono_context.ts view source

readonly ["session", "api_token", "daemon_token"] import {CREDENTIAL_TYPES} from '@fuzdev/fuz_app/hono_context.js';

The credential types that can authenticate a request — the closed set of fuz_app builtins. The open registry on top (create_credential_type_schema(consumer_types)) is consulted at registry time by create_role_schema for RoleSpec.required_credential_types validation; the wire-validated CredentialType enum here stays narrow because middleware only ever sets one of the three builtins.

CredentialType
#

hono_context.ts view source

ZodEnum<{ session: "session"; api_token: "api_token"; daemon_token: "daemon_token"; }> import type {CredentialType} from '@fuzdev/fuz_app/hono_context.js';

Credential type — how a request was authenticated.

TEST_CONTEXT_PRESET_KEY
#

hono_context.ts view source

"test_context_preset" import {TEST_CONTEXT_PRESET_KEY} from '@fuzdev/fuz_app/hono_context.js';

Hono context variable name for the test-harness pre-baked context flag.

Test harnesses (create_test_app_from_specs, create_fake_hono_context, the WS round-trip connect() helper, plus per-test middleware that pre-populates REQUEST_CONTEXT_KEY) set this to true so apply_authorization_phase skips its DB-backed actor resolution and trusts the supplied RequestContext. Production middleware never sets this key — only test code does. The flag is the explicit escape hatch that replaced the implicit "is REQUEST_CONTEXT_KEY already set?" probe, so that future production code consulting REQUEST_CONTEXT_KEY cannot silently bypass the live build.

TOKEN_SCOPE_KEY
#

hono_context.ts view source

"token_scope" import {TOKEN_SCOPE_KEY} from '@fuzdev/fuz_app/hono_context.js';

Hono context variable name for the credential's TokenScope.

Set by every auth middleware that resolves a credential — bearer reads it from the token row; session and daemon-token set full, because a browser session *is* full account authority (narrowing it is what role grants are for) and the daemon token is singular, filesystem-proved, and keeper-bound.

Unset only for the anonymous caller, who holds no credential to narrow. Downstream must not read an unset value as permissive for an *authenticated* caller — that absent case is exactly the permissive default this design removes.

Depends on
#

Imported by
#