@fuzdev/fuz_app 0.54.0 → 0.56.0
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/actions/CLAUDE.md +214 -103
- package/dist/actions/action_bridge.d.ts +8 -5
- package/dist/actions/action_bridge.d.ts.map +1 -1
- package/dist/actions/action_bridge.js +1 -11
- package/dist/actions/action_codegen.d.ts +32 -0
- package/dist/actions/action_codegen.d.ts.map +1 -1
- package/dist/actions/action_codegen.js +35 -15
- package/dist/actions/action_registry.d.ts.map +1 -1
- package/dist/actions/action_registry.js +5 -2
- package/dist/actions/action_rpc.d.ts +141 -22
- package/dist/actions/action_rpc.d.ts.map +1 -1
- package/dist/actions/action_rpc.js +106 -187
- package/dist/actions/action_spec.d.ts +55 -16
- package/dist/actions/action_spec.d.ts.map +1 -1
- package/dist/actions/action_spec.js +16 -11
- package/dist/actions/action_types.d.ts +28 -60
- package/dist/actions/action_types.d.ts.map +1 -1
- package/dist/actions/action_types.js +13 -5
- package/dist/actions/broadcast_api.d.ts +2 -2
- package/dist/actions/broadcast_api.js +2 -2
- package/dist/actions/compile_action_registry.d.ts +50 -0
- package/dist/actions/compile_action_registry.d.ts.map +1 -0
- package/dist/actions/compile_action_registry.js +69 -0
- package/dist/actions/heartbeat.d.ts +8 -4
- package/dist/actions/heartbeat.d.ts.map +1 -1
- package/dist/actions/heartbeat.js +5 -4
- package/dist/actions/perform_action.d.ts +145 -0
- package/dist/actions/perform_action.d.ts.map +1 -0
- package/dist/actions/perform_action.js +258 -0
- package/dist/actions/register_action_ws.d.ts +46 -40
- package/dist/actions/register_action_ws.d.ts.map +1 -1
- package/dist/actions/register_action_ws.js +101 -159
- package/dist/actions/register_ws_endpoint.d.ts +15 -10
- package/dist/actions/register_ws_endpoint.d.ts.map +1 -1
- package/dist/actions/register_ws_endpoint.js +54 -7
- package/dist/actions/transports.d.ts.map +1 -1
- package/dist/actions/transports.js +0 -4
- package/dist/actions/transports_ws_auth_guard.d.ts +1 -1
- package/dist/actions/transports_ws_auth_guard.js +1 -1
- package/dist/actions/transports_ws_backend.d.ts +1 -1
- package/dist/actions/transports_ws_backend.js +1 -1
- package/dist/auth/CLAUDE.md +794 -410
- package/dist/auth/account_action_specs.d.ts +28 -7
- package/dist/auth/account_action_specs.d.ts.map +1 -1
- package/dist/auth/account_action_specs.js +7 -7
- package/dist/auth/account_actions.d.ts +7 -13
- package/dist/auth/account_actions.d.ts.map +1 -1
- package/dist/auth/account_actions.js +26 -35
- package/dist/auth/account_queries.d.ts +52 -16
- package/dist/auth/account_queries.d.ts.map +1 -1
- package/dist/auth/account_queries.js +87 -38
- package/dist/auth/account_routes.d.ts +9 -11
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +118 -46
- package/dist/auth/account_schema.d.ts +46 -35
- package/dist/auth/account_schema.d.ts.map +1 -1
- package/dist/auth/account_schema.js +21 -28
- package/dist/auth/admin_action_specs.d.ts +100 -32
- package/dist/auth/admin_action_specs.d.ts.map +1 -1
- package/dist/auth/admin_action_specs.js +64 -33
- package/dist/auth/admin_actions.d.ts +13 -19
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +37 -41
- package/dist/auth/audit_emitter.d.ts +160 -0
- package/dist/auth/audit_emitter.d.ts.map +1 -0
- package/dist/auth/audit_emitter.js +83 -0
- package/dist/auth/audit_log_queries.d.ts +17 -48
- package/dist/auth/audit_log_queries.d.ts.map +1 -1
- package/dist/auth/audit_log_queries.js +20 -56
- package/dist/auth/audit_log_routes.d.ts +1 -1
- package/dist/auth/audit_log_routes.d.ts.map +1 -1
- package/dist/auth/audit_log_routes.js +7 -3
- package/dist/auth/audit_log_schema.d.ts +92 -32
- package/dist/auth/audit_log_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_schema.js +75 -46
- package/dist/auth/auth_guard_resolver.d.ts +44 -0
- package/dist/auth/auth_guard_resolver.d.ts.map +1 -0
- package/dist/auth/auth_guard_resolver.js +56 -0
- package/dist/auth/bearer_auth.d.ts +9 -7
- package/dist/auth/bearer_auth.d.ts.map +1 -1
- package/dist/auth/bearer_auth.js +13 -21
- package/dist/auth/bootstrap_account.d.ts +7 -7
- package/dist/auth/bootstrap_account.d.ts.map +1 -1
- package/dist/auth/bootstrap_account.js +7 -7
- package/dist/auth/bootstrap_routes.d.ts.map +1 -1
- package/dist/auth/bootstrap_routes.js +11 -10
- package/dist/auth/cleanup.d.ts +20 -26
- package/dist/auth/cleanup.d.ts.map +1 -1
- package/dist/auth/cleanup.js +33 -42
- package/dist/auth/credential_type_schema.d.ts +115 -0
- package/dist/auth/credential_type_schema.d.ts.map +1 -0
- package/dist/auth/credential_type_schema.js +127 -0
- package/dist/auth/daemon_token_middleware.d.ts +23 -11
- package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.js +28 -22
- package/dist/auth/ddl.d.ts +2 -2
- package/dist/auth/ddl.d.ts.map +1 -1
- package/dist/auth/ddl.js +6 -6
- package/dist/auth/deps.d.ts +7 -18
- package/dist/auth/deps.d.ts.map +1 -1
- package/dist/auth/grant_path_schema.d.ts +117 -0
- package/dist/auth/grant_path_schema.d.ts.map +1 -0
- package/dist/auth/grant_path_schema.js +137 -0
- package/dist/auth/invite_queries.d.ts +12 -1
- package/dist/auth/invite_queries.d.ts.map +1 -1
- package/dist/auth/invite_queries.js +12 -1
- package/dist/auth/invite_schema.d.ts +1 -1
- package/dist/auth/invite_schema.d.ts.map +1 -1
- package/dist/auth/invite_schema.js +1 -1
- package/dist/auth/middleware.d.ts.map +1 -1
- package/dist/auth/middleware.js +9 -4
- package/dist/auth/migrations.d.ts +37 -14
- package/dist/auth/migrations.d.ts.map +1 -1
- package/dist/auth/migrations.js +79 -32
- package/dist/auth/request_context.d.ts +331 -61
- package/dist/auth/request_context.d.ts.map +1 -1
- package/dist/auth/request_context.js +378 -95
- package/dist/auth/{permit_offer_action_specs.d.ts → role_grant_offer_action_specs.d.ts} +163 -94
- package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -0
- package/dist/auth/role_grant_offer_action_specs.js +262 -0
- package/dist/auth/role_grant_offer_actions.d.ts +104 -0
- package/dist/auth/role_grant_offer_actions.d.ts.map +1 -0
- package/dist/auth/role_grant_offer_actions.js +473 -0
- package/dist/auth/{permit_offer_notifications.d.ts → role_grant_offer_notifications.d.ts} +90 -70
- package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -0
- package/dist/auth/role_grant_offer_notifications.js +182 -0
- package/dist/auth/role_grant_offer_queries.d.ts +242 -0
- package/dist/auth/role_grant_offer_queries.d.ts.map +1 -0
- package/dist/auth/role_grant_offer_queries.js +533 -0
- package/dist/auth/role_grant_offer_schema.d.ts +150 -0
- package/dist/auth/role_grant_offer_schema.d.ts.map +1 -0
- package/dist/auth/{permit_offer_schema.js → role_grant_offer_schema.js} +60 -36
- package/dist/auth/role_grant_queries.d.ts +231 -0
- package/dist/auth/role_grant_queries.d.ts.map +1 -0
- package/dist/auth/role_grant_queries.js +320 -0
- package/dist/auth/role_schema.d.ts +150 -40
- package/dist/auth/role_schema.d.ts.map +1 -1
- package/dist/auth/role_schema.js +144 -45
- package/dist/auth/scope_kind_schema.d.ts +96 -0
- package/dist/auth/scope_kind_schema.d.ts.map +1 -0
- package/dist/auth/scope_kind_schema.js +94 -0
- package/dist/auth/self_service_role_action_specs.d.ts +6 -1
- package/dist/auth/self_service_role_action_specs.d.ts.map +1 -1
- package/dist/auth/self_service_role_action_specs.js +3 -1
- package/dist/auth/self_service_role_actions.d.ts +34 -27
- package/dist/auth/self_service_role_actions.d.ts.map +1 -1
- package/dist/auth/self_service_role_actions.js +68 -48
- package/dist/auth/session_cookie.d.ts +43 -6
- package/dist/auth/session_cookie.d.ts.map +1 -1
- package/dist/auth/session_cookie.js +31 -5
- package/dist/auth/session_middleware.d.ts +37 -3
- package/dist/auth/session_middleware.d.ts.map +1 -1
- package/dist/auth/session_middleware.js +33 -7
- package/dist/auth/signup_routes.d.ts.map +1 -1
- package/dist/auth/signup_routes.js +48 -19
- package/dist/auth/standard_action_specs.d.ts +2 -2
- package/dist/auth/standard_action_specs.js +4 -4
- package/dist/auth/standard_rpc_actions.d.ts +23 -19
- package/dist/auth/standard_rpc_actions.d.ts.map +1 -1
- package/dist/auth/standard_rpc_actions.js +12 -12
- package/dist/db/migrate.d.ts +12 -8
- package/dist/db/migrate.d.ts.map +1 -1
- package/dist/db/migrate.js +10 -7
- package/dist/dev/setup.d.ts +2 -2
- package/dist/dev/setup.d.ts.map +1 -1
- package/dist/dev/setup.js +9 -7
- package/dist/env/load.d.ts +1 -1
- package/dist/env/load.js +1 -1
- package/dist/hono_context.d.ts +64 -5
- package/dist/hono_context.d.ts.map +1 -1
- package/dist/hono_context.js +38 -2
- package/dist/http/CLAUDE.md +264 -87
- package/dist/http/auth_shape.d.ts +191 -0
- package/dist/http/auth_shape.d.ts.map +1 -0
- package/dist/http/auth_shape.js +237 -0
- package/dist/http/common_routes.js +3 -3
- package/dist/http/db_routes.d.ts +4 -0
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +44 -7
- package/dist/http/error_schemas.d.ts +132 -19
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/error_schemas.js +132 -40
- package/dist/http/jsonrpc_errors.d.ts +27 -2
- package/dist/http/jsonrpc_errors.d.ts.map +1 -1
- package/dist/http/jsonrpc_errors.js +26 -2
- package/dist/http/pending_effects.d.ts +71 -18
- package/dist/http/pending_effects.d.ts.map +1 -1
- package/dist/http/pending_effects.js +87 -18
- package/dist/http/proxy.d.ts +52 -5
- package/dist/http/proxy.d.ts.map +1 -1
- package/dist/http/proxy.js +92 -14
- package/dist/http/route_spec.d.ts +113 -41
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +130 -52
- package/dist/http/schema_helpers.d.ts +3 -2
- package/dist/http/schema_helpers.d.ts.map +1 -1
- package/dist/http/schema_helpers.js +9 -2
- package/dist/http/surface.d.ts +2 -1
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface.js +1 -2
- package/dist/http/surface_query.d.ts +39 -35
- package/dist/http/surface_query.d.ts.map +1 -1
- package/dist/http/surface_query.js +79 -36
- package/dist/primitive_schemas.d.ts +39 -0
- package/dist/primitive_schemas.d.ts.map +1 -0
- package/dist/primitive_schemas.js +40 -0
- package/dist/realtime/sse_auth_guard.d.ts +5 -5
- package/dist/realtime/sse_auth_guard.js +9 -9
- package/dist/runtime/mock.d.ts +1 -1
- package/dist/runtime/mock.js +1 -1
- package/dist/server/app_backend.d.ts +14 -11
- package/dist/server/app_backend.d.ts.map +1 -1
- package/dist/server/app_backend.js +12 -8
- package/dist/server/app_server.d.ts +7 -7
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +36 -31
- package/dist/server/validate_nginx.d.ts +1 -1
- package/dist/server/validate_nginx.js +1 -1
- package/dist/testing/CLAUDE.md +73 -55
- package/dist/testing/admin_integration.d.ts +5 -6
- package/dist/testing/admin_integration.d.ts.map +1 -1
- package/dist/testing/admin_integration.js +100 -96
- package/dist/testing/adversarial_headers.js +1 -1
- package/dist/testing/app_server.d.ts +11 -14
- package/dist/testing/app_server.d.ts.map +1 -1
- package/dist/testing/app_server.js +18 -17
- package/dist/testing/assertions.d.ts.map +1 -1
- package/dist/testing/assertions.js +2 -1
- package/dist/testing/attack_surface.d.ts.map +1 -1
- package/dist/testing/attack_surface.js +15 -9
- package/dist/testing/audit_completeness.d.ts +2 -2
- package/dist/testing/audit_completeness.d.ts.map +1 -1
- package/dist/testing/audit_completeness.js +53 -39
- package/dist/testing/auth_apps.d.ts +5 -4
- package/dist/testing/auth_apps.d.ts.map +1 -1
- package/dist/testing/auth_apps.js +28 -22
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +5 -5
- package/dist/testing/db.d.ts +1 -1
- package/dist/testing/db.d.ts.map +1 -1
- package/dist/testing/db.js +4 -4
- package/dist/testing/db_entities.d.ts +22 -0
- package/dist/testing/db_entities.d.ts.map +1 -0
- package/dist/testing/db_entities.js +28 -0
- package/dist/testing/entities.d.ts +10 -8
- package/dist/testing/entities.d.ts.map +1 -1
- package/dist/testing/entities.js +22 -18
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +13 -14
- package/dist/testing/integration_helpers.d.ts +8 -6
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/integration_helpers.js +29 -23
- package/dist/testing/middleware.d.ts +15 -11
- package/dist/testing/middleware.d.ts.map +1 -1
- package/dist/testing/middleware.js +75 -32
- package/dist/testing/rpc_attack_surface.d.ts.map +1 -1
- package/dist/testing/rpc_attack_surface.js +40 -24
- package/dist/testing/rpc_helpers.d.ts.map +1 -1
- package/dist/testing/rpc_helpers.js +3 -1
- package/dist/testing/rpc_round_trip.d.ts +1 -1
- package/dist/testing/rpc_round_trip.d.ts.map +1 -1
- package/dist/testing/rpc_round_trip.js +14 -13
- package/dist/testing/sse_round_trip.d.ts +3 -4
- package/dist/testing/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/sse_round_trip.js +7 -11
- package/dist/testing/standard.d.ts +1 -1
- package/dist/testing/stubs.d.ts +25 -0
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +43 -2
- package/dist/testing/surface_invariants.d.ts +2 -2
- package/dist/testing/ws_round_trip.d.ts +12 -13
- package/dist/testing/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/ws_round_trip.js +24 -12
- package/dist/ui/AdminAccounts.svelte +23 -20
- package/dist/ui/AdminOverview.svelte +15 -13
- package/dist/ui/AdminOverview.svelte.d.ts.map +1 -1
- package/dist/ui/{AdminPermitHistory.svelte → AdminRoleGrantHistory.svelte} +12 -12
- package/dist/ui/AdminRoleGrantHistory.svelte.d.ts +4 -0
- package/dist/ui/AdminRoleGrantHistory.svelte.d.ts.map +1 -0
- package/dist/ui/BootstrapForm.svelte +1 -1
- package/dist/ui/CLAUDE.md +65 -59
- package/dist/ui/{PermitOfferForm.svelte → RoleGrantOfferForm.svelte} +37 -22
- package/dist/ui/RoleGrantOfferForm.svelte.d.ts +20 -0
- package/dist/ui/RoleGrantOfferForm.svelte.d.ts.map +1 -0
- package/dist/ui/{PermitOfferHistory.svelte → RoleGrantOfferHistory.svelte} +12 -12
- package/dist/ui/{PermitOfferHistory.svelte.d.ts → RoleGrantOfferHistory.svelte.d.ts} +4 -4
- package/dist/ui/RoleGrantOfferHistory.svelte.d.ts.map +1 -0
- package/dist/ui/{PermitOfferInbox.svelte → RoleGrantOfferInbox.svelte} +14 -14
- package/dist/ui/{PermitOfferInbox.svelte.d.ts → RoleGrantOfferInbox.svelte.d.ts} +4 -4
- package/dist/ui/RoleGrantOfferInbox.svelte.d.ts.map +1 -0
- package/dist/ui/SignupForm.svelte +1 -1
- package/dist/ui/SurfaceExplorer.svelte +35 -15
- package/dist/ui/SurfaceExplorer.svelte.d.ts.map +1 -1
- package/dist/ui/account_sessions_state.svelte.d.ts +2 -3
- package/dist/ui/account_sessions_state.svelte.d.ts.map +1 -1
- package/dist/ui/account_sessions_state.svelte.js +2 -3
- package/dist/ui/admin_accounts_state.svelte.d.ts +25 -18
- package/dist/ui/admin_accounts_state.svelte.d.ts.map +1 -1
- package/dist/ui/admin_accounts_state.svelte.js +28 -17
- package/dist/ui/admin_rpc_adapters.d.ts +20 -20
- package/dist/ui/admin_rpc_adapters.d.ts.map +1 -1
- package/dist/ui/admin_rpc_adapters.js +17 -17
- package/dist/ui/admin_sessions_state.svelte.d.ts +2 -2
- package/dist/ui/admin_sessions_state.svelte.js +2 -2
- package/dist/ui/audit_log_state.svelte.d.ts +7 -7
- package/dist/ui/audit_log_state.svelte.d.ts.map +1 -1
- package/dist/ui/audit_log_state.svelte.js +6 -6
- package/dist/ui/auth_state.svelte.d.ts +3 -3
- package/dist/ui/auth_state.svelte.d.ts.map +1 -1
- package/dist/ui/auth_state.svelte.js +6 -6
- package/dist/ui/format_scope.d.ts +2 -2
- package/dist/ui/format_scope.js +2 -2
- package/dist/ui/{permit_offers_state.svelte.d.ts → role_grant_offers_state.svelte.d.ts} +39 -31
- package/dist/ui/role_grant_offers_state.svelte.d.ts.map +1 -0
- package/dist/ui/{permit_offers_state.svelte.js → role_grant_offers_state.svelte.js} +25 -19
- package/dist/ui/ui_format.js +2 -2
- package/package.json +3 -3
- package/dist/auth/permit_offer_action_specs.d.ts.map +0 -1
- package/dist/auth/permit_offer_action_specs.js +0 -227
- package/dist/auth/permit_offer_actions.d.ts +0 -110
- package/dist/auth/permit_offer_actions.d.ts.map +0 -1
- package/dist/auth/permit_offer_actions.js +0 -452
- package/dist/auth/permit_offer_notifications.d.ts.map +0 -1
- package/dist/auth/permit_offer_notifications.js +0 -182
- package/dist/auth/permit_offer_queries.d.ts +0 -183
- package/dist/auth/permit_offer_queries.d.ts.map +0 -1
- package/dist/auth/permit_offer_queries.js +0 -408
- package/dist/auth/permit_offer_schema.d.ts +0 -103
- package/dist/auth/permit_offer_schema.d.ts.map +0 -1
- package/dist/auth/permit_queries.d.ts +0 -210
- package/dist/auth/permit_queries.d.ts.map +0 -1
- package/dist/auth/permit_queries.js +0 -294
- package/dist/auth/require_keeper.d.ts +0 -20
- package/dist/auth/require_keeper.d.ts.map +0 -1
- package/dist/auth/require_keeper.js +0 -35
- package/dist/auth/route_guards.d.ts +0 -21
- package/dist/auth/route_guards.d.ts.map +0 -1
- package/dist/auth/route_guards.js +0 -32
- package/dist/auth/session_lifecycle.d.ts +0 -37
- package/dist/auth/session_lifecycle.d.ts.map +0 -1
- package/dist/auth/session_lifecycle.js +0 -29
- package/dist/ui/AdminPermitHistory.svelte.d.ts +0 -4
- package/dist/ui/AdminPermitHistory.svelte.d.ts.map +0 -1
- package/dist/ui/PermitOfferForm.svelte.d.ts +0 -14
- package/dist/ui/PermitOfferForm.svelte.d.ts.map +0 -1
- package/dist/ui/PermitOfferHistory.svelte.d.ts.map +0 -1
- package/dist/ui/PermitOfferInbox.svelte.d.ts.map +0 -1
- package/dist/ui/permit_offers_state.svelte.d.ts.map +0 -1
|
@@ -1,25 +1,64 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Request context middleware and
|
|
2
|
+
* Request context middleware and role_grant checking helpers.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* for every authenticated request. Downstream handlers check
|
|
6
|
-
* permits, never flags.
|
|
4
|
+
* Two-phase identity resolution:
|
|
7
5
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* 1. **Authentication (middleware)** — `create_request_context_middleware`,
|
|
7
|
+
* `bearer_auth`, and `daemon_token_middleware` validate the credential
|
|
8
|
+
* (session cookie, bearer token, daemon token) and set `c.var.account_id`
|
|
9
|
+
* + `c.var.credential_type` on the Hono context. They do not resolve
|
|
10
|
+
* an acting actor or load role_grants; `REQUEST_CONTEXT_KEY` stays null at
|
|
11
|
+
* this stage, so account-grain identity is the only thing known.
|
|
12
|
+
* 2. **Authorization (route-spec wrapper / RPC dispatcher)** — after input
|
|
13
|
+
* validation, the per-route layer inspects the route. If the input
|
|
14
|
+
* schema declared `acting?: ActingActor` (reference equality with the
|
|
15
|
+
* canonical `ActingActor` schema) or the auth requires role_grants
|
|
16
|
+
* (`role` / `keeper`), `apply_authorization_phase` resolves the actor
|
|
17
|
+
* against `c.var.account_id` plus the validated `acting` value via
|
|
18
|
+
* `resolve_acting_actor`, builds the `{account, actor, role_grants}`
|
|
19
|
+
* context via `build_request_context`, and sets it on
|
|
20
|
+
* `REQUEST_CONTEXT_KEY` before auth guards fire. Authenticated routes
|
|
21
|
+
* that don't need an actor still get an account-only context via
|
|
22
|
+
* `build_account_context` so handler signatures stay uniform.
|
|
23
|
+
*
|
|
24
|
+
* Account-grain operations (logout, password_change, account_verify,
|
|
25
|
+
* etc.) declare neither `acting` nor role_grant-requiring auth, so no actor
|
|
26
|
+
* is resolved and their handlers see a `RequestContext` with
|
|
27
|
+
* `actor: null` + empty `role_grants`. They never trigger `actor_required`,
|
|
28
|
+
* which is what makes multi-actor logout work without first picking a
|
|
29
|
+
* persona.
|
|
30
|
+
*
|
|
31
|
+
* `build_request_context` loads `account → actor → role_grants` and verifies
|
|
32
|
+
* the `actor.account_id === account.id` binding. `refresh_role_grants`
|
|
33
|
+
* reloads role_grants on an existing context.
|
|
11
34
|
*
|
|
12
35
|
* @module
|
|
13
36
|
*/
|
|
14
37
|
import type { Context, MiddlewareHandler } from 'hono';
|
|
15
38
|
import type { Logger } from '@fuzdev/fuz_util/log.js';
|
|
16
|
-
import { type Account, type Actor, type
|
|
39
|
+
import { type Account, type Actor, type RoleGrant } from './account_schema.js';
|
|
17
40
|
import type { QueryDeps } from '../db/query_deps.js';
|
|
18
|
-
|
|
41
|
+
import type { RouteSpec } from '../http/route_spec.js';
|
|
42
|
+
import { type RouteAuth } from '../http/auth_shape.js';
|
|
43
|
+
import { ERROR_ACTOR_REQUIRED, ERROR_ACTOR_NOT_ON_ACCOUNT, ERROR_NO_ACTORS_ON_ACCOUNT, ERROR_ACCOUNT_VANISHED } from '../http/error_schemas.js';
|
|
44
|
+
/**
|
|
45
|
+
* The resolved identity context for an authenticated request.
|
|
46
|
+
*
|
|
47
|
+
* `actor` is null on account-grain routes (no `acting` field on input,
|
|
48
|
+
* no `role` / `keeper` auth) — those handlers don't trigger actor
|
|
49
|
+
* resolution. `role_grants` is empty in that case. Role grant checks
|
|
50
|
+
* (`has_role`, `has_scoped_role`, `has_any_scoped_role`) are
|
|
51
|
+
* null-tolerant on `RequestContext | null`; they additionally treat
|
|
52
|
+
* `actor: null` as "no role_grants" so callers don't have to narrow.
|
|
53
|
+
*
|
|
54
|
+
* Multi-actor invariant: when populated, `actor.account_id === account.id`.
|
|
55
|
+
* `build_request_context` enforces this; the dispatcher's authorization
|
|
56
|
+
* phase rejects with `actor_not_on_account` before reaching the handler.
|
|
57
|
+
*/
|
|
19
58
|
export interface RequestContext {
|
|
20
59
|
account: Account;
|
|
21
|
-
actor: Actor;
|
|
22
|
-
|
|
60
|
+
actor: Actor | null;
|
|
61
|
+
role_grants: Array<RoleGrant>;
|
|
23
62
|
}
|
|
24
63
|
/** Hono context variable name for the request context. */
|
|
25
64
|
export declare const REQUEST_CONTEXT_KEY = "request_context";
|
|
@@ -43,19 +82,33 @@ export declare const get_request_context: (c: Context) => RequestContext | null;
|
|
|
43
82
|
/**
|
|
44
83
|
* Get the request context, throwing if unauthenticated.
|
|
45
84
|
*
|
|
46
|
-
* Use in route handlers where
|
|
47
|
-
* (i.e., routes with `auth: {type: 'authenticated'}` or
|
|
48
|
-
* Prefer this over `get_request_context(c)!` for explicit error
|
|
85
|
+
* Use in route handlers where the dispatcher's authorization phase guarantees
|
|
86
|
+
* a context exists (i.e., routes with `auth: {type: 'authenticated'}` or
|
|
87
|
+
* stricter). Prefer this over `get_request_context(c)!` for explicit error
|
|
88
|
+
* handling.
|
|
49
89
|
*
|
|
50
90
|
* @param c - the Hono context
|
|
51
91
|
* @returns the request context (never null)
|
|
52
|
-
* @throws Error if no request context is set (
|
|
92
|
+
* @throws Error if no request context is set (dispatcher misconfiguration)
|
|
53
93
|
*/
|
|
54
94
|
export declare const require_request_context: (c: Context) => RequestContext;
|
|
55
95
|
/**
|
|
56
|
-
*
|
|
96
|
+
* Request context narrowed to a resolved acting actor.
|
|
57
97
|
*
|
|
58
|
-
*
|
|
98
|
+
* Used by handlers bound through `rpc_action` against an actor-implying
|
|
99
|
+
* spec (`auth.actor === 'required'`) — the binder's conditional return
|
|
100
|
+
* type tightens `ctx.auth` to this shape because the dispatcher's
|
|
101
|
+
* authorization phase always resolves an actor before the handler runs.
|
|
102
|
+
* The biconditional `actor !== 'none' ⟺ input declares acting?: ActingActor`
|
|
103
|
+
* is enforced at registry time.
|
|
104
|
+
*/
|
|
105
|
+
export interface RequestActorContext extends RequestContext {
|
|
106
|
+
actor: Actor;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Check if a request context has an active role_grant for a given role.
|
|
110
|
+
*
|
|
111
|
+
* Checks the role_grants already loaded in the context (no DB query).
|
|
59
112
|
* Null-tolerant — `null` ctx (unauthenticated) returns `false`. Symmetric
|
|
60
113
|
* with `has_scoped_role` / `has_any_scoped_role` so the three helpers
|
|
61
114
|
* compose freely in the same predicate (e.g.
|
|
@@ -64,39 +117,43 @@ export declare const require_request_context: (c: Context) => RequestContext;
|
|
|
64
117
|
* @param ctx - the request context, or `null` for unauthenticated callers
|
|
65
118
|
* @param role - the role to check
|
|
66
119
|
* @param now - current time (defaults to `new Date()`, pass for testability and hot-path efficiency)
|
|
67
|
-
* @returns `true` if the actor has an active
|
|
120
|
+
* @returns `true` if the actor has an active role_grant for the role
|
|
68
121
|
*/
|
|
69
122
|
export declare const has_role: (ctx: RequestContext | null, role: string, now?: Date) => boolean;
|
|
70
123
|
/**
|
|
71
|
-
* Whether the request context holds an active
|
|
124
|
+
* Whether the request context holds an active role_grant for `role` at `scope_id`.
|
|
72
125
|
*
|
|
73
|
-
* Walks the in-memory `ctx.
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
126
|
+
* Walks the in-memory `ctx.role_grants` snapshot loaded once per request by
|
|
127
|
+
* the route-spec / RPC dispatcher's authorization phase (when the route
|
|
128
|
+
* declares `acting?: ActingActor` or has role_grant-requiring auth); zero DB
|
|
129
|
+
* roundtrip per check. The "freshness" framing of a SQL re-query is
|
|
130
|
+
* illusory because the race window is between predicate and the actual
|
|
131
|
+
* mutation, not predicate and authorization load. Closing that race needs
|
|
132
|
+
* a transactional re-check inside the UPDATE/INSERT, which neither style
|
|
133
|
+
* provides.
|
|
79
134
|
*
|
|
80
|
-
* Null-tolerant — `null` ctx (unauthenticated)
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
135
|
+
* Null-tolerant — `null` ctx (unauthenticated) and account-grain
|
|
136
|
+
* contexts (`actor: null`, empty `role_grants`) both return `false`. Same
|
|
137
|
+
* convention as `has_role`; lets the helper drop into public
|
|
138
|
+
* (`{account: 'none', actor: 'none'}`) and account-grain
|
|
139
|
+
* (`{account: 'required', actor: 'none'}`) handlers without a manual
|
|
140
|
+
* narrow. See `cell_authorize` for the resource-side analog.
|
|
84
141
|
*
|
|
85
|
-
* `scope_id` semantics: in-memory `
|
|
142
|
+
* `scope_id` semantics: in-memory `role_grant.scope_id` is `string | null`, so
|
|
86
143
|
* JS `===` matches the SQL `IS NOT DISTINCT FROM` semantics exactly:
|
|
87
144
|
*
|
|
88
|
-
* - `scope_id === null` matches global
|
|
89
|
-
* - `scope_id === '<uuid>'` matches
|
|
145
|
+
* - `scope_id === null` matches global role_grants (`scope_id IS NULL`).
|
|
146
|
+
* - `scope_id === '<uuid>'` matches role_grants bound to that exact scope.
|
|
90
147
|
*
|
|
91
148
|
* @param ctx - the request context, or `null` for unauthenticated callers
|
|
92
149
|
* @param role - the role to check
|
|
93
150
|
* @param scope_id - the scope to check (`null` for global)
|
|
94
151
|
* @param now - current time (defaults to `new Date()`, pass for testability and hot-path efficiency)
|
|
95
|
-
* @returns `true` iff the actor holds an active
|
|
152
|
+
* @returns `true` iff the actor holds an active role_grant for the role at the requested scope
|
|
96
153
|
*/
|
|
97
154
|
export declare const has_scoped_role: (ctx: RequestContext | null, role: string, scope_id: string | null, now?: Date) => boolean;
|
|
98
155
|
/**
|
|
99
|
-
* Whether the request context holds an active
|
|
156
|
+
* Whether the request context holds an active role_grant for any role in `roles`
|
|
100
157
|
* at `scope_id`. Empty `roles` short-circuits to `false` — documents intent
|
|
101
158
|
* at the call site ("zero roles trivially admit no-one"). Same scope and
|
|
102
159
|
* null-tolerance semantics as `has_scoped_role`.
|
|
@@ -105,66 +162,279 @@ export declare const has_scoped_role: (ctx: RequestContext | null, role: string,
|
|
|
105
162
|
* @param roles - the roles that would admit the caller (any-of)
|
|
106
163
|
* @param scope_id - the scope to check (`null` for global)
|
|
107
164
|
* @param now - current time (defaults to `new Date()`, pass for testability)
|
|
108
|
-
* @returns `true` iff the actor holds an active
|
|
165
|
+
* @returns `true` iff the actor holds an active role_grant for any role in `roles` at the requested scope
|
|
109
166
|
*/
|
|
110
167
|
export declare const has_any_scoped_role: (ctx: RequestContext | null, roles: ReadonlyArray<string>, scope_id: string | null, now?: Date) => boolean;
|
|
111
168
|
/**
|
|
112
|
-
*
|
|
169
|
+
* Result of `resolve_acting_actor` — either an actor id or a structured
|
|
170
|
+
* error the caller maps to an HTTP response.
|
|
171
|
+
*/
|
|
172
|
+
export type ResolveActingActorResult = {
|
|
173
|
+
ok: true;
|
|
174
|
+
actor_id: string;
|
|
175
|
+
} | {
|
|
176
|
+
ok: false;
|
|
177
|
+
reason: 'no_actors';
|
|
178
|
+
} | {
|
|
179
|
+
ok: false;
|
|
180
|
+
reason: 'actor_required';
|
|
181
|
+
available: Array<{
|
|
182
|
+
id: string;
|
|
183
|
+
name: string;
|
|
184
|
+
}>;
|
|
185
|
+
} | {
|
|
186
|
+
ok: false;
|
|
187
|
+
reason: 'actor_not_on_account';
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Resolve the acting actor for an authenticated request.
|
|
191
|
+
*
|
|
192
|
+
* Called from the route-spec / RPC dispatcher's authorization phase
|
|
193
|
+
* with the authenticated account id and the validated `acting` value
|
|
194
|
+
* (from the request payload). Applies the uniform resolution rules:
|
|
195
|
+
*
|
|
196
|
+
* - `acting_actor_id` omitted + 1 actor → use it.
|
|
197
|
+
* - `acting_actor_id` omitted + 0 actors → `no_actors` (defensive —
|
|
198
|
+
* signup / bootstrap always create an actor in the same tx, so this
|
|
199
|
+
* is a server error).
|
|
200
|
+
* - `acting_actor_id` omitted + multiple actors → `actor_required` with
|
|
201
|
+
* the available list so the client can prompt; never pick silently.
|
|
202
|
+
* - `acting_actor_id` present + matches an actor on the account → use it.
|
|
203
|
+
* - `acting_actor_id` present + does not match → `actor_not_on_account`.
|
|
204
|
+
* The available list is intentionally not echoed in this branch (treat
|
|
205
|
+
* as opaque rejection).
|
|
206
|
+
*
|
|
207
|
+
* @param deps - query dependencies
|
|
208
|
+
* @param account_id - the authenticated account
|
|
209
|
+
* @param acting_actor_id - the requested acting actor id, or `undefined`
|
|
210
|
+
*/
|
|
211
|
+
export declare const resolve_acting_actor: (deps: QueryDeps, account_id: string, acting_actor_id: string | undefined) => Promise<ResolveActingActorResult>;
|
|
212
|
+
/**
|
|
213
|
+
* Create middleware that authenticates the account from a session cookie.
|
|
113
214
|
*
|
|
114
|
-
* Reads the session identity (set by session middleware), looks up
|
|
115
|
-
*
|
|
116
|
-
*
|
|
215
|
+
* Reads the session identity (set by session middleware), looks up the
|
|
216
|
+
* `auth_session`, and on a valid session sets `c.var.auth_account_id`,
|
|
217
|
+
* `CREDENTIAL_TYPE_KEY = 'session'`, and `AUTH_SESSION_TOKEN_HASH_KEY`.
|
|
218
|
+
* Touches the session (fire-and-forget). Does not load actor or role_grants;
|
|
219
|
+
* `REQUEST_CONTEXT_KEY` is left null — the route-spec / RPC dispatcher
|
|
220
|
+
* authorization phase resolves the acting actor and builds the full
|
|
221
|
+
* `RequestContext` when the route needs one.
|
|
117
222
|
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
* `require_role` or `require_auth` for enforcement.
|
|
223
|
+
* Invalid / missing session leaves all keys null and calls `next()` —
|
|
224
|
+
* `require_auth` / `require_role` enforce.
|
|
121
225
|
*
|
|
122
226
|
* @param deps - query dependencies (pool-level db for middleware)
|
|
123
227
|
* @param log - the logger instance
|
|
124
228
|
* @param session_context_key - the Hono context key where session middleware stored the session token
|
|
125
|
-
* @mutates Hono context - sets `
|
|
229
|
+
* @mutates Hono context - sets `ACCOUNT_ID_KEY`, `CREDENTIAL_TYPE_KEY`, `AUTH_SESSION_TOKEN_HASH_KEY`, and `AUTH_API_TOKEN_ID_KEY`
|
|
126
230
|
*/
|
|
127
231
|
export declare const create_request_context_middleware: (deps: QueryDeps, log: Logger, session_context_key?: string) => MiddlewareHandler;
|
|
128
232
|
/**
|
|
129
233
|
* Middleware that requires authentication.
|
|
130
234
|
*
|
|
131
|
-
* Returns 401 if
|
|
235
|
+
* Returns 401 if the auth middleware did not set `c.var.auth_account_id`.
|
|
132
236
|
*/
|
|
133
237
|
export declare const require_auth: MiddlewareHandler;
|
|
134
238
|
/**
|
|
135
|
-
* Create middleware that requires
|
|
239
|
+
* Create middleware that requires the actor to hold any of the given
|
|
240
|
+
* roles globally (`scope_id IS NULL`).
|
|
241
|
+
*
|
|
242
|
+
* Returns 401 if unauthenticated, 403 if none of the roles are present.
|
|
243
|
+
* Reads `REQUEST_CONTEXT_KEY` because role-gated routes always run the
|
|
244
|
+
* dispatcher's authorization phase before this guard (the phase sets
|
|
245
|
+
* the actor-bound `RequestContext`).
|
|
246
|
+
*
|
|
247
|
+
* Uses `has_any_scoped_role(ctx, roles, null)` so the gate matches
|
|
248
|
+
* **global / unscoped role_grants only**. A scoped role_grant
|
|
249
|
+
* (`{role: 'admin', scope_id: <some uuid>}`) does not unlock route-spec
|
|
250
|
+
* gates that are inherently global. The same scope-aware check is
|
|
251
|
+
* mirrored in `actions/action_rpc.ts` (HTTP RPC dispatcher) and
|
|
252
|
+
* `actions/register_action_ws.ts` (WS dispatcher) so all three
|
|
253
|
+
* transports agree.
|
|
254
|
+
*
|
|
255
|
+
* Multi-role disjunction (any-of) lets `auth.roles: ['admin', 'steward']`
|
|
256
|
+
* specs translate to one middleware that admits either role. Single-role
|
|
257
|
+
* routes pass `[role_name]`; the array shape is uniform.
|
|
258
|
+
*
|
|
259
|
+
* @param roles - the roles to admit (any-of)
|
|
260
|
+
*/
|
|
261
|
+
export declare const require_role: (roles: ReadonlyArray<string>) => MiddlewareHandler;
|
|
262
|
+
/**
|
|
263
|
+
* Create middleware that requires the request's `credential_type` to be
|
|
264
|
+
* one of the given values.
|
|
136
265
|
*
|
|
137
|
-
* Returns 401 if unauthenticated, 403
|
|
266
|
+
* Returns 401 if unauthenticated, 403 with
|
|
267
|
+
* `ERROR_CREDENTIAL_TYPE_REQUIRED` + `required_credential_types` echoing
|
|
268
|
+
* the spec's allowlist when the wire-side credential isn't in it.
|
|
269
|
+
* Body shape is symmetric with the role gate (`ERROR_INSUFFICIENT_PERMISSIONS` +
|
|
270
|
+
* `required_roles`) and matches what the RPC dispatcher's post-auth
|
|
271
|
+
* gate emits for the same condition. Today's only credential gate is
|
|
272
|
+
* keeper (`['daemon_token']`); future gates (`agent_token`,
|
|
273
|
+
* `group_actor_token`) reuse this literal and label themselves through
|
|
274
|
+
* the array.
|
|
138
275
|
*
|
|
139
|
-
* @param
|
|
276
|
+
* @param credential_types - allowed credential types (any-of)
|
|
140
277
|
*/
|
|
141
|
-
export declare const
|
|
278
|
+
export declare const require_credential_types: (credential_types: ReadonlyArray<string>) => MiddlewareHandler;
|
|
142
279
|
/**
|
|
143
|
-
* Reload active
|
|
280
|
+
* Reload active role_grants from the database, returning a new request context.
|
|
144
281
|
*
|
|
145
|
-
* Useful for long-lived WebSocket connections where
|
|
282
|
+
* Useful for long-lived WebSocket connections where role_grants may change
|
|
146
283
|
* (grant or revoke) during the connection lifetime. Call periodically
|
|
147
284
|
* or after receiving a revocation signal.
|
|
148
285
|
*
|
|
149
|
-
* Returns a new `RequestContext` with updated
|
|
150
|
-
* context is not mutated, making concurrent calls safe.
|
|
286
|
+
* Returns a new `RequestContext` with updated role_grants — the original
|
|
287
|
+
* context is not mutated, making concurrent calls safe. Throws when
|
|
288
|
+
* `ctx.actor` is null; account-grain contexts have no role_grants to refresh.
|
|
151
289
|
*
|
|
152
290
|
* @param ctx - the request context to refresh
|
|
153
291
|
* @param deps - query dependencies
|
|
154
|
-
* @returns a new `RequestContext` with fresh
|
|
292
|
+
* @returns a new `RequestContext` with fresh role_grants
|
|
293
|
+
* @throws Error when called on an account-grain context (`actor: null`)
|
|
155
294
|
*/
|
|
156
|
-
export declare const
|
|
295
|
+
export declare const refresh_role_grants: (ctx: RequestContext, deps: QueryDeps) => Promise<RequestContext>;
|
|
157
296
|
/**
|
|
158
|
-
* Build a full `RequestContext` from an account id
|
|
297
|
+
* Build a full `RequestContext` from an account id and an explicit
|
|
298
|
+
* actor id (already resolved via `resolve_acting_actor`).
|
|
159
299
|
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
* the account
|
|
300
|
+
* Loads `account` + the named `actor` + the actor's active role_grants.
|
|
301
|
+
* Verifies the `actor.account_id === account.id` binding so downstream
|
|
302
|
+
* handlers can trust `ctx.actor.account_id === ctx.account.id`. Returns
|
|
303
|
+
* `null` when the account is missing, the actor is missing, or the
|
|
304
|
+
* actor doesn't belong to the supplied account.
|
|
305
|
+
*
|
|
306
|
+
* Called by the route-spec / RPC dispatcher's authorization phase for
|
|
307
|
+
* routes that need an acting actor; account-grain routes use
|
|
308
|
+
* `build_account_context` instead.
|
|
164
309
|
*
|
|
165
310
|
* @param deps - query dependencies
|
|
166
311
|
* @param account_id - the account to build context for
|
|
167
|
-
* @
|
|
312
|
+
* @param actor_id - the actor this request acts as
|
|
313
|
+
* @returns a request context, or `null` if account/actor not found or mismatched
|
|
314
|
+
*/
|
|
315
|
+
export declare const build_request_context: (deps: QueryDeps, account_id: string, actor_id: string) => Promise<RequestActorContext | null>;
|
|
316
|
+
/**
|
|
317
|
+
* Build an account-only `RequestContext` (no actor, no role_grants) from
|
|
318
|
+
* an account id.
|
|
319
|
+
*
|
|
320
|
+
* Used by the dispatcher's authorization phase for authenticated routes
|
|
321
|
+
* that don't need an acting actor — account-grain operations (logout,
|
|
322
|
+
* password change, account self-service). Lets handlers read
|
|
323
|
+
* `auth.account.id` / `auth.account.username` uniformly with role_grant-bound
|
|
324
|
+
* routes; the cost is one extra `query_account_by_id` per request.
|
|
325
|
+
*
|
|
326
|
+
* Returns `null` when the account row is missing (e.g. deleted between
|
|
327
|
+
* the auth middleware's session lookup and the dispatcher) — caller
|
|
328
|
+
* surfaces that as a 500 since it represents a torn read.
|
|
329
|
+
*
|
|
330
|
+
* @param deps - query dependencies
|
|
331
|
+
* @param account_id - the account to build context for
|
|
332
|
+
* @returns an account-only request context, or `null` if the account is missing
|
|
333
|
+
*/
|
|
334
|
+
export declare const build_account_context: (deps: QueryDeps, account_id: string) => Promise<RequestContext | null>;
|
|
335
|
+
/**
|
|
336
|
+
* Resolution-failure shape returned by `apply_authorization_phase`. Each
|
|
337
|
+
* transport binds this to the appropriate wire shape — REST emits the body
|
|
338
|
+
* directly via `c.json(body, status)`; the RPC dispatcher folds it into a
|
|
339
|
+
* JSON-RPC error envelope `{jsonrpc, id, error: {code, message, data}}`.
|
|
340
|
+
*
|
|
341
|
+
* The auth phase deliberately stops short of constructing a `Response` so
|
|
342
|
+
* the same failure flows through every transport without the auth-domain
|
|
343
|
+
* code knowing about JSON-RPC. See `fuz_app/CLAUDE.md` § Cleanest
|
|
344
|
+
* architecture takes priority for the rationale.
|
|
345
|
+
*/
|
|
346
|
+
export type AuthorizationFailureBody = {
|
|
347
|
+
error: typeof ERROR_ACTOR_REQUIRED;
|
|
348
|
+
available: Array<{
|
|
349
|
+
id: string;
|
|
350
|
+
name: string;
|
|
351
|
+
}>;
|
|
352
|
+
} | {
|
|
353
|
+
error: typeof ERROR_ACTOR_NOT_ON_ACCOUNT;
|
|
354
|
+
} | {
|
|
355
|
+
error: typeof ERROR_NO_ACTORS_ON_ACCOUNT;
|
|
356
|
+
} | {
|
|
357
|
+
error: typeof ERROR_ACCOUNT_VANISHED;
|
|
358
|
+
};
|
|
359
|
+
/**
|
|
360
|
+
* Result of the authorization phase. Pure data — the auth domain stops
|
|
361
|
+
* short of touching the Hono context or producing a `Response` so HTTP
|
|
362
|
+
* RPC, WS, and REST each bind the same shape to their wire surface.
|
|
363
|
+
*
|
|
364
|
+
* - **`{ok: true, request_context}`** — `request_context` is non-null on
|
|
365
|
+
* resolved (actor-bound or account-only) outcomes; `null` for public
|
|
366
|
+
* actions (`{account: 'none', actor: 'none'}`) and for genuine anonymous
|
|
367
|
+
* access on an `'optional'` axis. Public and unauthenticated collapse
|
|
368
|
+
* to the same null `request_context`; every transport already treated
|
|
369
|
+
* them identically.
|
|
370
|
+
* - **`{ok: false, status, body}`** — 400/500 failure. `status` is
|
|
371
|
+
* narrowed to the two values the auth phase emits, so Hono's `c.json`
|
|
372
|
+
* status overload accepts the literals directly. The 500 reasons stay
|
|
373
|
+
* distinct in `body`: `no_actors_on_account` (signup invariant
|
|
374
|
+
* violation); `account_vanished` (torn read after resolve).
|
|
375
|
+
*/
|
|
376
|
+
export type AuthorizationResult = {
|
|
377
|
+
ok: true;
|
|
378
|
+
request_context: RequestContext | null;
|
|
379
|
+
} | {
|
|
380
|
+
ok: false;
|
|
381
|
+
status: 400 | 500;
|
|
382
|
+
body: AuthorizationFailureBody;
|
|
383
|
+
};
|
|
384
|
+
/**
|
|
385
|
+
* Apply the dispatcher's authorization phase against the flat-record
|
|
386
|
+
* `RouteAuth` shape. Shared by the route-spec wrapper, the HTTP RPC
|
|
387
|
+
* dispatcher, and the per-message WS dispatcher. Phase order:
|
|
388
|
+
* pre-validation 401 → input validation 400 → authorization phase →
|
|
389
|
+
* post-authorization 403.
|
|
390
|
+
*
|
|
391
|
+
* Pure data — the function does not touch a Hono context. Each transport
|
|
392
|
+
* passes `account_id` (extracted from its own credential surface) and
|
|
393
|
+
* binds the returned `AuthorizationResult` to its wire shape. The REST
|
|
394
|
+
* pipeline additionally writes `REQUEST_CONTEXT_KEY` on `c` for downstream
|
|
395
|
+
* `require_role` / `require_credential_types` middleware that still reads
|
|
396
|
+
* the resolved context off the Hono context.
|
|
397
|
+
*
|
|
398
|
+
* Branching by `auth.account` × `auth.actor`:
|
|
399
|
+
*
|
|
400
|
+
* - Both `'none'` → `{ok: true, request_context: null}`. Public actions
|
|
401
|
+
* never see a `RequestContext`.
|
|
402
|
+
* - `account_id == null` on any non-public route → same null
|
|
403
|
+
* `request_context`. The `'required'` callers were already rejected at
|
|
404
|
+
* the pre-validation gate in the dispatcher; only genuine anonymous
|
|
405
|
+
* access on an `'optional'` axis lands here.
|
|
406
|
+
* - `actor === 'none'` → builds account-only context via
|
|
407
|
+
* `build_account_context`. Null lookup → `account_vanished` 500 failure.
|
|
408
|
+
* - `actor === 'required'` → resolves the actor from `acting_value` (or
|
|
409
|
+
* single-actor account); failures map to 400 / 500.
|
|
410
|
+
* - `actor === 'optional'` → same as `'required'` except multi-actor
|
|
411
|
+
* accounts without an `acting` value fall back to account-only context
|
|
412
|
+
* (no `actor_required` 400). Bad `acting` ids still 400.
|
|
413
|
+
*
|
|
414
|
+
* 500 branches stay distinct: `ERROR_NO_ACTORS_ON_ACCOUNT` (signup
|
|
415
|
+
* invariant violation), `ERROR_ACCOUNT_VANISHED` (torn read after
|
|
416
|
+
* resolve).
|
|
417
|
+
*/
|
|
418
|
+
export declare const apply_authorization_phase: (deps: QueryDeps, account_id: string | null, auth: RouteAuth, acting_value: string | undefined) => Promise<AuthorizationResult>;
|
|
419
|
+
/**
|
|
420
|
+
* Create the route-spec authorization handler used by `apply_route_specs`.
|
|
421
|
+
*
|
|
422
|
+
* Reads `acting` off `c.var.validated_input` (or `c.var.validated_query`
|
|
423
|
+
* for GET routes) — input validation runs first, so the authorization
|
|
424
|
+
* phase consumes the typed Zod field instead of pre-parsing the body.
|
|
425
|
+
* Public routes (`auth.account === 'none' && auth.actor === 'none'`)
|
|
426
|
+
* skip the phase entirely.
|
|
427
|
+
*
|
|
428
|
+
* Per registry-time invariant 2, `auth.actor !== 'none'` ⟺ the input
|
|
429
|
+
* (or query) schema declares `acting?: ActingActor` — so reading from
|
|
430
|
+
* `c.var.validated_input.acting` / `c.var.validated_query.acting` is
|
|
431
|
+
* type-safe.
|
|
432
|
+
*
|
|
433
|
+
* Resolved contexts land on `REQUEST_CONTEXT_KEY` so the post-authorization
|
|
434
|
+
* REST middleware (`require_role`, `require_credential_types`) reads the
|
|
435
|
+
* actor-bound context off `c.var`. The HTTP RPC and WS dispatchers consume
|
|
436
|
+
* the `apply_authorization_phase` outcome directly without round-tripping
|
|
437
|
+
* through `c.var`.
|
|
168
438
|
*/
|
|
169
|
-
export declare const
|
|
439
|
+
export declare const create_fuz_authorization_handler: (deps: QueryDeps) => ((c: Context, spec: RouteSpec) => Promise<Response | void>);
|
|
170
440
|
//# sourceMappingURL=request_context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request_context.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/request_context.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"request_context.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/request_context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,KAAK,EAAC,OAAO,EAAE,iBAAiB,EAAC,MAAM,MAAM,CAAC;AACrD,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAC,KAAK,OAAO,EAAE,KAAK,KAAK,EAAwB,KAAK,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAYnG,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAQnD,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAA8B,KAAK,SAAS,EAAC,MAAM,uBAAuB,CAAC;AAClF,OAAO,EAIN,oBAAoB,EACpB,0BAA0B,EAC1B,0BAA0B,EAC1B,sBAAsB,EACtB,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,cAAc;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;CAC9B;AAED,0DAA0D;AAC1D,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AAErD;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,4BAA4B,CAAC;AAErE;;;;;GAKG;AACH,e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