@fuzdev/fuz_app 0.150.0 → 0.152.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/README.md +1 -1
- package/dist/actions/CLAUDE.md +324 -299
- package/dist/actions/action_bridge.d.ts +5 -86
- package/dist/actions/action_bridge.d.ts.map +1 -1
- package/dist/actions/action_bridge.js +4 -84
- package/dist/actions/action_codegen.d.ts +8 -166
- package/dist/actions/action_codegen.d.ts.map +1 -1
- package/dist/actions/action_codegen.js +19 -95
- package/dist/actions/action_dispatcher.d.ts +10 -0
- package/dist/actions/action_dispatcher.d.ts.map +1 -1
- package/dist/actions/action_dispatcher.js +9 -6
- package/dist/actions/action_event.d.ts +1 -2
- package/dist/actions/action_event.d.ts.map +1 -1
- package/dist/actions/action_event.js +7 -13
- package/dist/actions/action_event_helpers.d.ts +1 -40
- package/dist/actions/action_event_helpers.d.ts.map +1 -1
- package/dist/actions/action_event_helpers.js +1 -25
- package/dist/actions/action_rpc.d.ts +10 -215
- package/dist/actions/action_rpc.d.ts.map +1 -1
- package/dist/actions/action_rpc.js +56 -111
- package/dist/actions/action_spec.d.ts +2 -2
- package/dist/actions/action_spec.js +2 -2
- package/dist/actions/action_types.d.ts +229 -8
- package/dist/actions/action_types.d.ts.map +1 -1
- package/dist/actions/action_types.js +56 -5
- package/dist/actions/broadcast_api.d.ts +22 -17
- package/dist/actions/broadcast_api.d.ts.map +1 -1
- package/dist/actions/broadcast_api.js +16 -27
- package/dist/actions/cancel.d.ts +4 -13
- package/dist/actions/cancel.d.ts.map +1 -1
- package/dist/actions/cancel.js +5 -17
- package/dist/actions/compile_action_registry.d.ts +1 -2
- package/dist/actions/compile_action_registry.d.ts.map +1 -1
- package/dist/actions/connection_closer.d.ts +120 -50
- package/dist/actions/connection_closer.d.ts.map +1 -1
- package/dist/actions/connection_closer.js +139 -31
- package/dist/actions/{transports_ws_backend.d.ts → connection_registry.d.ts} +120 -132
- package/dist/actions/connection_registry.d.ts.map +1 -0
- package/dist/actions/{transports_ws_backend.js → connection_registry.js} +149 -152
- package/dist/actions/frontend_rpc_client.d.ts +52 -2
- package/dist/actions/frontend_rpc_client.d.ts.map +1 -1
- package/dist/actions/frontend_rpc_client.js +42 -4
- package/dist/actions/peer_ping.d.ts +7 -9
- package/dist/actions/peer_ping.d.ts.map +1 -1
- package/dist/actions/peer_ping.js +6 -8
- package/dist/actions/peer_request.d.ts +6 -5
- package/dist/actions/peer_request.d.ts.map +1 -1
- package/dist/actions/peer_request.js +6 -5
- package/dist/actions/perform_action.d.ts +36 -28
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +60 -34
- package/dist/actions/protocol.d.ts +14 -0
- package/dist/actions/protocol.d.ts.map +1 -1
- package/dist/actions/protocol.js +18 -0
- package/dist/actions/register_action_ws.d.ts +137 -298
- package/dist/actions/register_action_ws.d.ts.map +1 -1
- package/dist/actions/register_action_ws.js +155 -923
- package/dist/actions/socket.svelte.d.ts +9 -0
- package/dist/actions/socket.svelte.d.ts.map +1 -1
- package/dist/actions/socket.svelte.js +16 -5
- package/dist/actions/transports.d.ts +88 -34
- package/dist/actions/transports.d.ts.map +1 -1
- package/dist/actions/transports.js +76 -76
- package/dist/actions/transports_http.d.ts +48 -12
- package/dist/actions/transports_http.d.ts.map +1 -1
- package/dist/actions/transports_http.js +75 -44
- package/dist/actions/transports_ws.d.ts +29 -0
- package/dist/actions/transports_ws.d.ts.map +1 -1
- package/dist/actions/transports_ws.js +34 -8
- package/dist/actions/ws_endpoint_spec.d.ts +52 -75
- package/dist/actions/ws_endpoint_spec.d.ts.map +1 -1
- package/dist/actions/ws_endpoint_spec.js +27 -10
- package/dist/actions/ws_outbound_writer.d.ts +3 -3
- package/dist/actions/ws_outbound_writer.js +3 -3
- package/dist/actions/ws_socket_session.d.ts +321 -0
- package/dist/actions/ws_socket_session.d.ts.map +1 -0
- package/dist/actions/ws_socket_session.js +783 -0
- package/dist/auth/CLAUDE.md +70 -44
- package/dist/auth/account_action_specs.d.ts +2 -0
- package/dist/auth/account_action_specs.d.ts.map +1 -1
- package/dist/auth/account_actions.d.ts +1 -1
- package/dist/auth/account_actions.d.ts.map +1 -1
- package/dist/auth/account_actions.js +9 -3
- package/dist/auth/account_queries.d.ts +10 -0
- package/dist/auth/account_queries.d.ts.map +1 -1
- package/dist/auth/account_queries.js +27 -17
- package/dist/auth/account_routes.d.ts +2 -1
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +14 -17
- package/dist/auth/account_schema.d.ts +5 -5
- package/dist/auth/account_schema.d.ts.map +1 -1
- package/dist/auth/account_schema.js +5 -2
- package/dist/auth/actor_lookup_actions.d.ts +1 -1
- package/dist/auth/actor_lookup_actions.d.ts.map +1 -1
- package/dist/auth/actor_lookup_actions.js +1 -1
- package/dist/auth/actor_search_action_specs.d.ts.map +1 -1
- package/dist/auth/actor_search_action_specs.js +2 -1
- package/dist/auth/actor_search_actions.d.ts +1 -1
- package/dist/auth/actor_search_actions.d.ts.map +1 -1
- package/dist/auth/actor_search_actions.js +1 -1
- package/dist/auth/actor_search_queries.d.ts +5 -5
- package/dist/auth/actor_search_queries.d.ts.map +1 -1
- package/dist/auth/actor_search_queries.js +7 -7
- package/dist/auth/admin_action_specs.d.ts.map +1 -1
- package/dist/auth/admin_action_specs.js +3 -1
- package/dist/auth/admin_actions.d.ts +1 -1
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +12 -42
- package/dist/auth/all_cell_actions.d.ts +6 -4
- package/dist/auth/all_cell_actions.d.ts.map +1 -1
- package/dist/auth/all_cell_actions.js +1 -1
- package/dist/auth/api_token_queries.d.ts +1 -0
- package/dist/auth/api_token_queries.d.ts.map +1 -1
- package/dist/auth/api_token_queries.js +1 -0
- package/dist/auth/audit_emitter.d.ts +3 -3
- package/dist/auth/audit_emitter.js +2 -2
- package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_route_schema.js +3 -2
- package/dist/auth/audit_log_routes.d.ts +20 -11
- package/dist/auth/audit_log_routes.d.ts.map +1 -1
- package/dist/auth/audit_log_routes.js +49 -29
- package/dist/auth/audit_log_schema.d.ts +13 -21
- package/dist/auth/audit_log_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_schema.js +10 -18
- package/dist/auth/bearer_auth.d.ts +7 -4
- package/dist/auth/bearer_auth.d.ts.map +1 -1
- package/dist/auth/bearer_auth.js +21 -15
- package/dist/auth/cell_action_helpers.d.ts +89 -0
- package/dist/auth/cell_action_helpers.d.ts.map +1 -0
- package/dist/auth/cell_action_helpers.js +113 -0
- package/dist/auth/cell_actions.d.ts +22 -13
- package/dist/auth/cell_actions.d.ts.map +1 -1
- package/dist/auth/cell_actions.js +105 -167
- package/dist/auth/cell_audit_actions.d.ts +1 -1
- package/dist/auth/cell_audit_actions.d.ts.map +1 -1
- package/dist/auth/cell_audit_actions.js +3 -12
- package/dist/auth/cell_audit_metadata.d.ts +1 -1
- package/dist/auth/cell_audit_metadata.js +1 -1
- package/dist/auth/cell_field_actions.d.ts +1 -1
- package/dist/auth/cell_field_actions.d.ts.map +1 -1
- package/dist/auth/cell_field_actions.js +16 -66
- package/dist/auth/cell_grant_action_specs.d.ts +2 -2
- package/dist/auth/cell_grant_action_specs.js +3 -3
- package/dist/auth/cell_grant_actions.d.ts +73 -11
- package/dist/auth/cell_grant_actions.d.ts.map +1 -1
- package/dist/auth/cell_grant_actions.js +63 -55
- package/dist/auth/cell_grant_audit_metadata.d.ts +6 -3
- package/dist/auth/cell_grant_audit_metadata.d.ts.map +1 -1
- package/dist/auth/cell_grant_audit_metadata.js +7 -4
- package/dist/auth/cell_item_actions.d.ts +1 -1
- package/dist/auth/cell_item_actions.d.ts.map +1 -1
- package/dist/auth/cell_item_actions.js +21 -82
- package/dist/auth/cleanup.d.ts +1 -1
- package/dist/auth/cleanup.d.ts.map +1 -1
- package/dist/auth/cleanup.js +6 -3
- package/dist/auth/credential_deadline.d.ts +3 -3
- package/dist/auth/credential_deadline.js +3 -3
- package/dist/auth/credential_type_schema.d.ts +5 -5
- package/dist/auth/credential_type_schema.js +5 -5
- package/dist/auth/daemon_token_middleware.d.ts +12 -6
- package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.js +28 -17
- package/dist/auth/deps.d.ts +4 -4
- package/dist/auth/fail_floor.d.ts +55 -0
- package/dist/auth/fail_floor.d.ts.map +1 -0
- package/dist/auth/fail_floor.js +63 -0
- package/dist/auth/invite_queries.d.ts +3 -15
- package/dist/auth/invite_queries.d.ts.map +1 -1
- package/dist/auth/invite_queries.js +3 -21
- package/dist/auth/middleware.d.ts +12 -7
- package/dist/auth/middleware.d.ts.map +1 -1
- package/dist/auth/middleware.js +42 -29
- package/dist/auth/migrations.d.ts +5 -33
- package/dist/auth/migrations.d.ts.map +1 -1
- package/dist/auth/migrations.js +9 -16
- package/dist/auth/request_context.d.ts +101 -71
- package/dist/auth/request_context.d.ts.map +1 -1
- package/dist/auth/request_context.js +137 -140
- package/dist/auth/resolved_auth.d.ts +122 -36
- package/dist/auth/resolved_auth.d.ts.map +1 -1
- package/dist/auth/resolved_auth.js +89 -38
- package/dist/auth/role_grant_offer_action_specs.d.ts +99 -14
- package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_action_specs.js +26 -13
- package/dist/auth/role_grant_offer_actions.d.ts +13 -7
- package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_actions.js +14 -12
- package/dist/auth/role_grant_offer_notifications.d.ts +3 -3
- package/dist/auth/role_grant_offer_notifications.js +1 -1
- package/dist/auth/role_grant_offer_queries.d.ts +0 -5
- package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_queries.js +9 -41
- package/dist/auth/role_grant_queries.d.ts +17 -67
- package/dist/auth/role_grant_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_queries.js +34 -106
- package/dist/auth/role_grant_sql.d.ts +42 -0
- package/dist/auth/role_grant_sql.d.ts.map +1 -0
- package/dist/auth/role_grant_sql.js +54 -0
- package/dist/auth/scope_kind_schema.d.ts +1 -1
- package/dist/auth/scope_kind_schema.js +1 -1
- package/dist/auth/self_service_role_actions.d.ts +1 -1
- package/dist/auth/self_service_role_actions.d.ts.map +1 -1
- package/dist/auth/self_service_role_actions.js +1 -1
- package/dist/auth/session_queries.d.ts +2 -1
- package/dist/auth/session_queries.d.ts.map +1 -1
- package/dist/auth/session_queries.js +2 -1
- package/dist/auth/signup_routes.d.ts +2 -1
- package/dist/auth/signup_routes.d.ts.map +1 -1
- package/dist/auth/signup_routes.js +14 -13
- package/dist/auth/standard_rpc_actions.d.ts +1 -1
- package/dist/auth/standard_rpc_actions.d.ts.map +1 -1
- package/dist/auth/token_scope.d.ts +19 -46
- package/dist/auth/token_scope.d.ts.map +1 -1
- package/dist/auth/token_scope.js +23 -41
- package/dist/db/CLAUDE.md +9 -4
- package/dist/db/cell_ddl.d.ts +5 -142
- package/dist/db/cell_ddl.d.ts.map +1 -1
- package/dist/db/cell_ddl.js +17 -16
- package/dist/db/cell_field_queries.d.ts +0 -13
- package/dist/db/cell_field_queries.d.ts.map +1 -1
- package/dist/db/cell_field_queries.js +0 -16
- package/dist/db/cell_grant_queries.d.ts +10 -5
- package/dist/db/cell_grant_queries.d.ts.map +1 -1
- package/dist/db/cell_grant_queries.js +13 -7
- package/dist/db/cell_item_queries.d.ts +0 -7
- package/dist/db/cell_item_queries.d.ts.map +1 -1
- package/dist/db/cell_item_queries.js +0 -10
- package/dist/db/cell_queries.d.ts +12 -48
- package/dist/db/cell_queries.d.ts.map +1 -1
- package/dist/db/cell_queries.js +24 -55
- package/dist/db/cell_view_sql.d.ts +1 -6
- package/dist/db/cell_view_sql.d.ts.map +1 -1
- package/dist/db/cell_view_sql.js +1 -2
- package/dist/db/fact_ddl.d.ts +5 -30
- package/dist/db/fact_ddl.d.ts.map +1 -1
- package/dist/db/fact_ddl.js +14 -13
- package/dist/db/fact_store.d.ts +11 -0
- package/dist/db/fact_store.d.ts.map +1 -1
- package/dist/db/fact_store.js +4 -1
- package/dist/db/migrate.d.ts +44 -6
- package/dist/db/migrate.d.ts.map +1 -1
- package/dist/db/migrate.js +63 -4
- package/dist/dev/setup.d.ts +18 -14
- package/dist/dev/setup.d.ts.map +1 -1
- package/dist/dev/setup.js +42 -39
- package/dist/env/dotenv.d.ts +2 -2
- package/dist/env/dotenv.js +2 -2
- package/dist/env/update_env_variable.d.ts +33 -21
- package/dist/env/update_env_variable.d.ts.map +1 -1
- package/dist/env/update_env_variable.js +54 -35
- package/dist/hono_context.d.ts +15 -90
- package/dist/hono_context.d.ts.map +1 -1
- package/dist/hono_context.js +9 -56
- package/dist/http/CLAUDE.md +35 -20
- package/dist/http/auth_shape.d.ts +1 -8
- package/dist/http/auth_shape.d.ts.map +1 -1
- package/dist/http/auth_shape.js +6 -12
- package/dist/http/common_routes.d.ts.map +1 -1
- package/dist/http/common_routes.js +3 -2
- package/dist/http/db_routes.d.ts +3 -3
- package/dist/http/db_routes.js +3 -3
- package/dist/http/error_schemas.d.ts +1 -2
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/error_schemas.js +1 -2
- package/dist/http/health_schema.d.ts +16 -0
- package/dist/http/health_schema.d.ts.map +1 -0
- package/dist/http/health_schema.js +12 -0
- package/dist/http/jsonrpc_errors.d.ts +22 -2
- package/dist/http/jsonrpc_errors.d.ts.map +1 -1
- package/dist/http/jsonrpc_errors.js +41 -3
- package/dist/http/jsonrpc_helpers.d.ts +60 -17
- package/dist/http/jsonrpc_helpers.d.ts.map +1 -1
- package/dist/http/jsonrpc_helpers.js +67 -25
- package/dist/http/origin.d.ts +30 -1
- package/dist/http/origin.d.ts.map +1 -1
- package/dist/http/origin.js +46 -9
- package/dist/http/origin_wildcard.d.ts +97 -0
- package/dist/http/origin_wildcard.d.ts.map +1 -0
- package/dist/http/origin_wildcard.js +142 -0
- package/dist/http/pending_effects.d.ts +28 -0
- package/dist/http/pending_effects.d.ts.map +1 -1
- package/dist/http/pending_effects.js +32 -1
- package/dist/http/route_spec.d.ts +4 -3
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +54 -45
- package/dist/http/surface.d.ts +1 -1
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface_query.d.ts +9 -50
- package/dist/http/surface_query.d.ts.map +1 -1
- package/dist/http/surface_query.js +48 -94
- package/dist/realtime/audit_log_sse.d.ts +180 -0
- package/dist/realtime/audit_log_sse.d.ts.map +1 -0
- package/dist/realtime/audit_log_sse.js +154 -0
- package/dist/realtime/sse.d.ts +21 -6
- package/dist/realtime/sse.d.ts.map +1 -1
- package/dist/realtime/sse.js +33 -10
- package/dist/realtime/sse_constants.d.ts +29 -2
- package/dist/realtime/sse_constants.d.ts.map +1 -1
- package/dist/realtime/sse_constants.js +35 -2
- package/dist/realtime/{subscriber_registry.d.ts → sse_registry.d.ts} +12 -12
- package/dist/realtime/sse_registry.d.ts.map +1 -0
- package/dist/realtime/{subscriber_registry.js → sse_registry.js} +4 -4
- package/dist/schema_meta.d.ts +30 -10
- package/dist/schema_meta.d.ts.map +1 -1
- package/dist/schema_meta.js +85 -21
- package/dist/sensitivity.d.ts +9 -3
- package/dist/sensitivity.d.ts.map +1 -1
- package/dist/sensitivity.js +3 -2
- package/dist/server/app_backend.d.ts +8 -5
- package/dist/server/app_backend.d.ts.map +1 -1
- package/dist/server/app_backend.js +6 -12
- package/dist/server/app_server.d.ts +62 -51
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +84 -71
- package/dist/server/app_server_context.d.ts +1 -1
- package/dist/server/app_server_context.d.ts.map +1 -1
- package/dist/server/env.d.ts +24 -20
- package/dist/server/env.d.ts.map +1 -1
- package/dist/server/env.js +24 -34
- package/dist/server/serve_fact_route.d.ts +12 -16
- package/dist/server/serve_fact_route.d.ts.map +1 -1
- package/dist/server/serve_fact_route.js +59 -34
- package/dist/server/static.d.ts.map +1 -1
- package/dist/server/static.js +2 -2
- package/dist/testing/CLAUDE.md +179 -158
- package/dist/testing/admin_integration.d.ts.map +1 -1
- package/dist/testing/admin_integration.js +10 -19
- package/dist/testing/adversarial_headers.d.ts.map +1 -1
- package/dist/testing/adversarial_headers.js +8 -0
- package/dist/testing/app_server.d.ts +9 -77
- package/dist/testing/app_server.d.ts.map +1 -1
- package/dist/testing/app_server.js +31 -112
- package/dist/testing/attack_surface.d.ts.map +1 -1
- package/dist/testing/attack_surface.js +3 -4
- package/dist/testing/audit_completeness.d.ts.map +1 -1
- package/dist/testing/audit_completeness.js +4 -5
- package/dist/testing/auth_apps.d.ts +3 -3
- package/dist/testing/auth_apps.d.ts.map +1 -1
- package/dist/testing/auth_apps.js +9 -6
- package/dist/testing/connection_closer_helpers.d.ts +8 -16
- package/dist/testing/connection_closer_helpers.d.ts.map +1 -1
- package/dist/testing/connection_closer_helpers.js +7 -20
- package/dist/testing/cross_backend/action_manifest.d.ts +15 -4
- package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
- package/dist/testing/cross_backend/action_manifest.js +13 -3
- package/dist/testing/cross_backend/action_manifest_parity.d.ts +15 -7
- package/dist/testing/cross_backend/action_manifest_parity.d.ts.map +1 -1
- package/dist/testing/cross_backend/action_manifest_parity.js +8 -1
- package/dist/testing/cross_backend/body_size.d.ts.map +1 -1
- package/dist/testing/cross_backend/body_size.js +25 -22
- package/dist/testing/cross_backend/build_test_backend_paths.d.ts +22 -3
- package/dist/testing/cross_backend/build_test_backend_paths.d.ts.map +1 -1
- package/dist/testing/cross_backend/build_test_backend_paths.js +34 -11
- package/dist/testing/cross_backend/capabilities.d.ts +13 -7
- package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_grant_role.js +2 -2
- package/dist/testing/cross_backend/cell_grant_steward.d.ts +4 -0
- package/dist/testing/cross_backend/cell_grant_steward.d.ts.map +1 -0
- package/dist/testing/cross_backend/cell_grant_steward.js +120 -0
- package/dist/testing/cross_backend/cell_relations.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_relations.js +21 -0
- package/dist/testing/cross_backend/conformance_table.d.ts +1 -1
- package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_backend_configs.d.ts +18 -4
- package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_backend_configs.js +29 -9
- package/dist/testing/cross_backend/default_spine_surface.d.ts +7 -7
- package/dist/testing/cross_backend/default_spine_surface.js +2 -2
- package/dist/testing/cross_backend/fact_serving.d.ts.map +1 -1
- package/dist/testing/cross_backend/fact_serving.js +48 -0
- package/dist/testing/cross_backend/full_spine_mount.d.ts +3 -4
- package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
- package/dist/testing/cross_backend/full_spine_mount.js +9 -2
- package/dist/testing/cross_backend/origin_scope.d.ts.map +1 -1
- package/dist/testing/cross_backend/origin_scope.js +5 -13
- package/dist/testing/cross_backend/peer_ping_ws.d.ts.map +1 -1
- package/dist/testing/cross_backend/peer_ping_ws.js +29 -4
- package/dist/testing/cross_backend/postgres_database.d.ts +32 -0
- package/dist/testing/cross_backend/postgres_database.d.ts.map +1 -1
- package/dist/testing/cross_backend/postgres_database.js +56 -1
- package/dist/testing/cross_backend/query_shape.d.ts.map +1 -1
- package/dist/testing/cross_backend/query_shape.js +18 -1
- package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +23 -1
- package/dist/testing/cross_backend/rpc_success_fixtures.js +2 -2
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts +17 -5
- package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_stub_backend_config.js +5 -4
- package/dist/testing/cross_backend/session_cap.d.ts +8 -0
- package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
- package/dist/testing/cross_backend/session_cap.js +66 -2
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +5 -4
- package/dist/testing/cross_backend/spine_suites.d.ts +4 -1
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +21 -0
- package/dist/testing/cross_backend/spine_surface_constants.d.ts +22 -7
- package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_surface_constants.js +22 -7
- package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/sse_round_trip.js +4 -3
- package/dist/testing/cross_backend/standard.d.ts +6 -12
- package/dist/testing/cross_backend/standard.d.ts.map +1 -1
- package/dist/testing/cross_backend/test_cell_grant_steward_revoke_authorize.d.ts +8 -0
- package/dist/testing/cross_backend/test_cell_grant_steward_revoke_authorize.d.ts.map +1 -0
- package/dist/testing/cross_backend/test_cell_grant_steward_revoke_authorize.js +22 -0
- package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_backdoor.js +4 -6
- package/dist/testing/cross_backend/testing_origin_check.d.ts +1 -1
- package/dist/testing/cross_backend/testing_origin_check.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_origin_check.js +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +10 -5
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +7 -6
- package/dist/testing/cross_backend/testing_server_bun.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_server_bun.js +5 -4
- package/dist/testing/cross_backend/testing_server_core.d.ts +6 -7
- package/dist/testing/cross_backend/testing_server_core.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_server_core.js +1 -1
- package/dist/testing/cross_backend/testing_server_node.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_server_node.js +13 -2
- package/dist/testing/cross_backend/token_lifetime.d.ts.map +1 -1
- package/dist/testing/cross_backend/token_lifetime.js +68 -0
- package/dist/testing/cross_backend/transport_composition.d.ts +1 -1
- package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
- package/dist/testing/cross_backend/transport_composition.js +45 -3
- package/dist/testing/cross_backend/ts_spine_backend_config.d.ts +16 -2
- package/dist/testing/cross_backend/ts_spine_backend_config.d.ts.map +1 -1
- package/dist/testing/cross_backend/ts_spine_backend_config.js +11 -8
- package/dist/testing/cross_backend/ws_action_rate_limit.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_action_rate_limit.js +30 -12
- package/dist/testing/cross_backend/ws_connection_cap.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_connection_cap.js +5 -7
- package/dist/testing/cross_backend/ws_endpoint.d.ts +2 -3
- package/dist/testing/cross_backend/ws_endpoint.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_envelope.d.ts +17 -0
- package/dist/testing/cross_backend/ws_envelope.d.ts.map +1 -0
- package/dist/testing/cross_backend/ws_envelope.js +172 -0
- package/dist/testing/cross_backend/ws_inbound_dispatch.d.ts +16 -0
- package/dist/testing/cross_backend/ws_inbound_dispatch.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_inbound_dispatch.js +8 -4
- package/dist/testing/cross_backend/ws_outbound_overflow.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_outbound_overflow.js +5 -8
- package/dist/testing/cross_backend/ws_role_gated.js +2 -2
- package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_round_trip.js +6 -4
- package/dist/{cli/daemon.d.ts → testing/daemon_info.d.ts} +15 -47
- package/dist/testing/daemon_info.d.ts.map +1 -0
- package/dist/testing/daemon_info.js +108 -0
- package/dist/testing/daemon_token_rotation.js +1 -1
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +3 -4
- package/dist/testing/db.js +2 -2
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +35 -65
- package/dist/testing/integration_helpers.d.ts +0 -15
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/integration_helpers.js +2 -42
- package/dist/testing/middleware.d.ts +20 -12
- package/dist/testing/middleware.d.ts.map +1 -1
- package/dist/testing/middleware.js +49 -40
- package/dist/testing/rate_limiting.d.ts.map +1 -1
- package/dist/testing/rate_limiting.js +13 -22
- package/dist/testing/resolved_auth.d.ts +30 -0
- package/dist/testing/resolved_auth.d.ts.map +1 -0
- package/dist/testing/resolved_auth.js +41 -0
- package/dist/testing/rpc_envelope_cases.d.ts.map +1 -1
- package/dist/testing/rpc_envelope_cases.js +3 -0
- package/dist/testing/rpc_helpers.d.ts +1 -1
- package/dist/testing/rpc_helpers.d.ts.map +1 -1
- package/dist/testing/rpc_helpers.js +2 -1
- package/dist/testing/sse_round_trip.d.ts +5 -4
- package/dist/testing/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/sse_round_trip.js +2 -2
- package/dist/testing/stubs.d.ts +2 -2
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +24 -21
- package/dist/testing/test_origin.d.ts +25 -0
- package/dist/testing/test_origin.d.ts.map +1 -0
- package/dist/testing/test_origin.js +28 -0
- package/dist/testing/transports/raw_http.d.ts +54 -0
- package/dist/testing/transports/raw_http.d.ts.map +1 -1
- package/dist/testing/transports/raw_http.js +58 -0
- package/dist/testing/transports/ws_raw_client.d.ts +8 -0
- package/dist/testing/transports/ws_raw_client.d.ts.map +1 -1
- package/dist/testing/transports/ws_raw_client.js +13 -0
- package/dist/testing/transports/ws_transport.d.ts +15 -2
- package/dist/testing/transports/ws_transport.d.ts.map +1 -1
- package/dist/testing/transports/ws_transport.js +4 -2
- package/dist/testing/ws_round_trip.d.ts +27 -25
- package/dist/testing/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/ws_round_trip.js +34 -26
- package/dist/ui/AccountSessions.svelte +48 -19
- package/dist/ui/AccountSessions.svelte.d.ts +2 -17
- package/dist/ui/AccountSessions.svelte.d.ts.map +1 -1
- package/dist/ui/AdminAccounts.svelte +6 -1
- package/dist/ui/AdminAuditLog.svelte +61 -22
- package/dist/ui/AdminAuditLog.svelte.d.ts.map +1 -1
- package/dist/ui/AdminInvites.svelte +1 -1
- package/dist/ui/AdminOverview.svelte +76 -37
- package/dist/ui/AdminOverview.svelte.d.ts.map +1 -1
- package/dist/ui/AdminRoleGrantHistory.svelte +6 -1
- package/dist/ui/AdminSessions.svelte +1 -1
- package/dist/ui/AppShell.svelte +3 -2
- package/dist/ui/AppShell.svelte.d.ts +3 -2
- package/dist/ui/AppShell.svelte.d.ts.map +1 -1
- package/dist/ui/CLAUDE.md +121 -35
- package/dist/ui/Datatable.svelte +33 -18
- package/dist/ui/Datatable.svelte.d.ts +2 -14
- package/dist/ui/Datatable.svelte.d.ts.map +1 -1
- package/dist/ui/OpenSignupToggle.svelte +10 -1
- package/dist/ui/OpenSignupToggle.svelte.d.ts.map +1 -1
- package/dist/ui/PopoverButton.svelte +13 -8
- package/dist/ui/PopoverButton.svelte.d.ts.map +1 -1
- package/dist/ui/RoleGrantOfferForm.svelte +3 -2
- package/dist/ui/RoleGrantOfferForm.svelte.d.ts +3 -2
- package/dist/ui/RoleGrantOfferForm.svelte.d.ts.map +1 -1
- package/dist/ui/RoleGrantOfferHistory.svelte +3 -3
- package/dist/ui/RoleGrantOfferInbox.svelte +19 -15
- package/dist/ui/RoleGrantOfferInbox.svelte.d.ts.map +1 -1
- package/dist/ui/SurfaceExplorer.svelte +66 -27
- package/dist/ui/SurfaceExplorer.svelte.d.ts.map +1 -1
- package/dist/ui/account_sessions_state.svelte.d.ts +7 -14
- package/dist/ui/account_sessions_state.svelte.d.ts.map +1 -1
- package/dist/ui/admin_accounts_state.svelte.d.ts +14 -9
- package/dist/ui/admin_accounts_state.svelte.d.ts.map +1 -1
- package/dist/ui/admin_accounts_state.svelte.js +6 -4
- package/dist/ui/admin_invites_state.svelte.d.ts +2 -2
- package/dist/ui/admin_invites_state.svelte.d.ts.map +1 -1
- package/dist/ui/admin_rpc_adapters.d.ts +9 -9
- package/dist/ui/admin_rpc_adapters.d.ts.map +1 -1
- package/dist/ui/admin_rpc_adapters.js +9 -9
- package/dist/ui/app_settings_state.svelte.d.ts +2 -2
- package/dist/ui/app_settings_state.svelte.d.ts.map +1 -1
- package/dist/ui/audit_log_state.svelte.d.ts +70 -13
- package/dist/ui/audit_log_state.svelte.d.ts.map +1 -1
- package/dist/ui/audit_log_state.svelte.js +239 -47
- package/dist/ui/backend_probe.svelte.d.ts +93 -0
- package/dist/ui/backend_probe.svelte.d.ts.map +1 -0
- package/dist/ui/backend_probe.svelte.js +140 -0
- package/dist/ui/format_scope.d.ts +7 -7
- package/dist/ui/format_scope.d.ts.map +1 -1
- package/dist/ui/format_scope.js +4 -4
- package/dist/ui/keyed_async_slot.svelte.d.ts +2 -2
- package/dist/ui/keyed_async_slot.svelte.js +2 -2
- package/dist/ui/popover.svelte.d.ts +18 -19
- package/dist/ui/popover.svelte.d.ts.map +1 -1
- package/dist/ui/popover.svelte.js +103 -16
- package/dist/ui/role_grant_offers_state.svelte.d.ts +41 -46
- package/dist/ui/role_grant_offers_state.svelte.d.ts.map +1 -1
- package/dist/ui/role_grant_offers_state.svelte.js +37 -19
- package/dist/ui/ui_format.d.ts +17 -0
- package/dist/ui/ui_format.d.ts.map +1 -1
- package/dist/ui/ui_format.js +20 -0
- package/package.json +9 -8
- package/dist/actions/register_ws_endpoint.d.ts +0 -79
- package/dist/actions/register_ws_endpoint.d.ts.map +0 -1
- package/dist/actions/register_ws_endpoint.js +0 -109
- package/dist/actions/transports_ws_auth_guard.d.ts +0 -96
- package/dist/actions/transports_ws_auth_guard.d.ts.map +0 -1
- package/dist/actions/transports_ws_auth_guard.js +0 -141
- package/dist/actions/transports_ws_backend.d.ts.map +0 -1
- package/dist/cli/args.d.ts +0 -55
- package/dist/cli/args.d.ts.map +0 -1
- package/dist/cli/args.js +0 -100
- package/dist/cli/config.d.ts +0 -47
- package/dist/cli/config.d.ts.map +0 -1
- package/dist/cli/config.js +0 -77
- package/dist/cli/daemon.d.ts.map +0 -1
- package/dist/cli/daemon.js +0 -181
- package/dist/cli/help.d.ts +0 -124
- package/dist/cli/help.d.ts.map +0 -1
- package/dist/cli/help.js +0 -215
- package/dist/cli/logger.d.ts +0 -46
- package/dist/cli/logger.d.ts.map +0 -1
- package/dist/cli/logger.js +0 -48
- package/dist/cli/util.d.ts +0 -36
- package/dist/cli/util.d.ts.map +0 -1
- package/dist/cli/util.js +0 -50
- package/dist/realtime/sse_auth_guard.d.ts +0 -197
- package/dist/realtime/sse_auth_guard.d.ts.map +0 -1
- package/dist/realtime/sse_auth_guard.js +0 -239
- package/dist/realtime/subscriber_registry.d.ts.map +0 -1
- package/dist/testing/bootstrap_success.d.ts +0 -29
- package/dist/testing/bootstrap_success.d.ts.map +0 -1
- package/dist/testing/bootstrap_success.js +0 -144
- package/dist/testing/mock_fs.d.ts +0 -20
- package/dist/testing/mock_fs.d.ts.map +0 -1
- package/dist/testing/mock_fs.js +0 -28
- package/dist/testing/standard.d.ts +0 -122
- package/dist/testing/standard.d.ts.map +0 -1
- package/dist/testing/standard.js +0 -73
- package/dist/testing/testing_rate_limiter.d.ts +0 -65
- package/dist/testing/testing_rate_limiter.d.ts.map +0 -1
- package/dist/testing/testing_rate_limiter.js +0 -80
|
@@ -0,0 +1,783 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The per-socket half of the WebSocket endpoint — one upgraded socket, from
|
|
3
|
+
* admission to close.
|
|
4
|
+
*
|
|
5
|
+
* `register_action_ws` (`actions/register_action_ws.ts`) mounts the upgrade
|
|
6
|
+
* route; per upgrade it reads the credential off the Hono context into a
|
|
7
|
+
* `WsSocketUpgrade` and hands that, with the endpoint-level `WsSocketEndpoint`,
|
|
8
|
+
* to `create_ws_socket_events`, whose `WSEvents` the runtime adapter drives.
|
|
9
|
+
* Nothing here reads the Hono context or imports the mount, so a socket is
|
|
10
|
+
* reachable with a fake `WSContext` and no app.
|
|
11
|
+
*
|
|
12
|
+
* The WS-specific concerns — connection lifecycle, heartbeat,
|
|
13
|
+
* cancel-notification interception, socket-scoped notify — live here; the
|
|
14
|
+
* relation to `create_rpc_endpoint` and the shared `perform_action` core is in
|
|
15
|
+
* the `register_action_ws` module doc.
|
|
16
|
+
*
|
|
17
|
+
* ## Admission: the revocation race
|
|
18
|
+
*
|
|
19
|
+
* The auth middleware resolves the credential before the handshake, and the
|
|
20
|
+
* socket exists only once `onOpen` fires. Every revocation (session revoke,
|
|
21
|
+
* logout, password change, token revoke, account delete) closes the sockets
|
|
22
|
+
* *registered* under what it revoked, so one landing in that gap would close
|
|
23
|
+
* nothing, and the socket would then be admitted on the dead credential and
|
|
24
|
+
* keep it: per-message dispatch re-authorizes the *actor*, never the session
|
|
25
|
+
* or token — and its admission could evict a live socket of the same account
|
|
26
|
+
* past the cap.
|
|
27
|
+
*
|
|
28
|
+
* `onOpen` closes the gap in three steps: register the connection **pending**
|
|
29
|
+
* (`ConnectionRegistry.register_pending` — closeable by every
|
|
30
|
+
* revocation, inert otherwise), re-read the credential, the acting actor, and
|
|
31
|
+
* the role (`recheck_admission`, which the audit stream shares), then
|
|
32
|
+
* `ConnectionRegistry.admit`. A
|
|
33
|
+
* revocation whose close ran after the registration found the pending entry,
|
|
34
|
+
* so `admit` refuses; one that committed before the re-read is seen by it. The
|
|
35
|
+
* cap is enforced only by `admit`, so a refused upgrade evicts nothing, and
|
|
36
|
+
* pending registrations never count toward it.
|
|
37
|
+
*
|
|
38
|
+
* That argument needs every revocation to close only after its commit —
|
|
39
|
+
* otherwise a close could miss the registration while the re-read still sees
|
|
40
|
+
* the credential alive. Every one does: the revocation handlers queue their
|
|
41
|
+
* close behind the commit (`queue_connection_close`), and the audit emitter
|
|
42
|
+
* announces a success row to the listeners behind it too. So no interleaving
|
|
43
|
+
* admits a revoked credential; `docs/security.md` §Connection Admission says
|
|
44
|
+
* what that rests on.
|
|
45
|
+
*
|
|
46
|
+
* The acting actor the upgrade resolved is re-read beside the credential on
|
|
47
|
+
* every endpoint, gated or not: an actor soft-deleted under its live account
|
|
48
|
+
* keeps the account's sessions and tokens and its own grant rows, so neither
|
|
49
|
+
* the credential nor the role re-read would refuse it. A tombstoned acting
|
|
50
|
+
* actor is refused like a dead credential.
|
|
51
|
+
*
|
|
52
|
+
* An endpoint gated on `required_roles` re-reads them beside the credential:
|
|
53
|
+
* its upgrade passed the role gate before the socket registered, so a role
|
|
54
|
+
* revocation landing in between would close nothing (a `role` close target
|
|
55
|
+
* matches registrations), and the socket would be admitted without the role
|
|
56
|
+
* for its lifetime. The re-read reads the acting actor's grants afresh and
|
|
57
|
+
* admits on a global grant of any listed role, as the gate did.
|
|
58
|
+
*
|
|
59
|
+
* A refused upgrade is closed with `WS_CLOSE_SESSION_REVOKED` (4001, the
|
|
60
|
+
* reason a revoked socket gets) for a dead credential or a deleted acting actor,
|
|
61
|
+
* `WS_CLOSE_PERMISSION_REVOKED` (4006) for a lost role, or
|
|
62
|
+
* `WS_CLOSE_INTERNAL_ERROR` (1011) when a re-read itself failed — fail
|
|
63
|
+
* closed, never admitted unchecked. The handshake has already answered `101`,
|
|
64
|
+
* so a refusal can only be a close frame.
|
|
65
|
+
*
|
|
66
|
+
* Once the server is shutting down (`AppServer.close` ran the registry's
|
|
67
|
+
* `close_all_connections`) a refusal is `WS_CLOSE_GOING_AWAY` instead, so the
|
|
68
|
+
* client reconnects rather than treating its credential as revoked: an upgrade
|
|
69
|
+
* pending at the close-all is closed by it — and its abort makes the refusal
|
|
70
|
+
* that follows the re-read send nothing more, even when the database closed
|
|
71
|
+
* under that re-read — and one that registers after it is born closed and
|
|
72
|
+
* skips the re-read (`ConnectionRegistry` module doc, "Shutdown").
|
|
73
|
+
*
|
|
74
|
+
* Frames that arrive before admission are queued, not dispatched: nothing runs
|
|
75
|
+
* on a credential that has not been re-read. They dispatch in arrival order
|
|
76
|
+
* once the socket is admitted and `on_socket_open` has completed, and are
|
|
77
|
+
* dropped unread on a refusal. The queue holds at most
|
|
78
|
+
* `MAX_PRE_ADMISSION_FRAMES` frames and
|
|
79
|
+
* `PRE_ADMISSION_QUEUE_BYTES_FACTOR` × `max_message_bytes` bytes; past either
|
|
80
|
+
* the socket is closed.
|
|
81
|
+
*
|
|
82
|
+
* ## Credential deadline
|
|
83
|
+
*
|
|
84
|
+
* Expiry writes nothing a revocation listener could hear, so the socket
|
|
85
|
+
* watches its own credential's expiry (`ResolvedAuth.credential_deadline`,
|
|
86
|
+
* the earlier of a session's cookie and row, an API token's row, none for a
|
|
87
|
+
* daemon token or an eternal token). From admission, a timer closes it at the
|
|
88
|
+
* deadline with `WS_CLOSE_SESSION_REVOKED` (4001) and
|
|
89
|
+
* `WS_CLOSE_CREDENTIAL_EXPIRED_REASON`. The wait is a chain of timers of at
|
|
90
|
+
* most an hour (`schedule_credential_deadline`), so a session's 30 days — past
|
|
91
|
+
* `setTimeout`'s ceiling — does not fire at once, and each wake-up checks the
|
|
92
|
+
* wall clock too, so a host suspend does not extend the deadline.
|
|
93
|
+
*
|
|
94
|
+
* ## A server-closed socket dispatches nothing
|
|
95
|
+
*
|
|
96
|
+
* A runtime adapter can keep delivering inbound frames after the server calls
|
|
97
|
+
* `ws.close(…)`, until the close handshake completes (`@hono/node-ws` does —
|
|
98
|
+
* up to the `ws` close timeout when the client withholds its close frame).
|
|
99
|
+
* So every server-side close — revocation, cap eviction, heartbeat timeout,
|
|
100
|
+
* an oversized message, a refused admission — removes the connection from the
|
|
101
|
+
* registry and aborts the socket's signal *at close time*, and `onMessage`
|
|
102
|
+
* drops any frame on a socket that has ended. A connection the registry no
|
|
103
|
+
* longer holds though nothing closed its socket (a bare `remove_connection`)
|
|
104
|
+
* is ended on its next frame (`ConnectionRegistry.is_registered`), with
|
|
105
|
+
* `WS_CLOSE_INTERNAL_ERROR` — it must not linger as a socket that reads
|
|
106
|
+
* everything and answers nothing.
|
|
107
|
+
*
|
|
108
|
+
* @module
|
|
109
|
+
*/
|
|
110
|
+
import { UnreachableError } from '@fuzdev/fuz_util/error.ts';
|
|
111
|
+
import { recheck_admission, resolved_auth_api_token_id, resolved_auth_session_hash } from '../auth/resolved_auth.js';
|
|
112
|
+
import { schedule_credential_deadline } from '../auth/credential_deadline.js';
|
|
113
|
+
import { flush_request_effects } from '../http/pending_effects.js';
|
|
114
|
+
import { jsonrpc_error_messages } from '../http/jsonrpc_errors.js';
|
|
115
|
+
import { classify_jsonrpc_message, create_jsonrpc_error_response, create_jsonrpc_notification, to_jsonrpc_params } from '../http/jsonrpc_helpers.js';
|
|
116
|
+
import { cancel_action_spec, CancelNotificationParams } from './cancel.js';
|
|
117
|
+
import { WS_CLOSE_CONNECTION_UNREGISTERED_REASON, WS_CLOSE_GOING_AWAY, WS_CLOSE_INTERNAL_ERROR, WS_CLOSE_INTERNAL_ERROR_REASON, WS_CLOSE_MESSAGE_TOO_BIG, WS_CLOSE_MESSAGE_TOO_BIG_REASON, WS_CLOSE_PERMISSION_REVOKED, WS_CLOSE_PERMISSION_REVOKED_REASON, WS_CLOSE_POLICY_VIOLATION, WS_CLOSE_PRE_ADMISSION_OVERFLOW_REASON, WS_CLOSE_CREDENTIAL_EXPIRED_REASON, WS_CLOSE_SERVER_HEARTBEAT_TIMEOUT, WS_CLOSE_SERVER_HEARTBEAT_TIMEOUT_REASON, WS_CLOSE_SESSION_REVOKED, WS_CLOSE_SOCKET_OPEN_FAILED_REASON, WS_CLOSE_SESSION_REVOKED_REASON, utf8_length, utf8_length_over } from './transports.js';
|
|
118
|
+
import { audit_unmatched_peer_response } from './peer_request.js';
|
|
119
|
+
import { perform_action, serialize_action_result } from './perform_action.js';
|
|
120
|
+
/**
|
|
121
|
+
* Max inbound frames one socket may have queued while it is still opening —
|
|
122
|
+
* between the handshake and the end of the credential re-check plus
|
|
123
|
+
* `on_socket_open`. One more closes the socket with
|
|
124
|
+
* `WS_CLOSE_POLICY_VIOLATION`.
|
|
125
|
+
*
|
|
126
|
+
* Frames sent before the socket is open wait rather than dispatch (nothing
|
|
127
|
+
* runs on a credential that has not been re-read), and a runtime adapter hands
|
|
128
|
+
* them over with no backpressure, so the wait needs a bound. This is the count
|
|
129
|
+
* half; `PRE_ADMISSION_QUEUE_BYTES_FACTOR` is the byte half.
|
|
130
|
+
*
|
|
131
|
+
* Sized so a client flushing its durable queue on reopen never meets it at the
|
|
132
|
+
* default `DEFAULT_QUEUE_MAX_SIZE` (`actions/socket.svelte.ts`). A consumer
|
|
133
|
+
* that raises the client's queue above this cap makes a full flush overflow
|
|
134
|
+
* it: the socket closes with `WS_CLOSE_POLICY_VIOLATION`, the flushed requests
|
|
135
|
+
* fail, and the client reconnects.
|
|
136
|
+
*/
|
|
137
|
+
export const MAX_PRE_ADMISSION_FRAMES = 256;
|
|
138
|
+
/**
|
|
139
|
+
* The byte budget of one socket's pre-admission queue, as a multiple of the
|
|
140
|
+
* endpoint's `max_message_bytes`: the frames queued while the socket is still
|
|
141
|
+
* opening may total at most this many maximum-size messages. The frame that
|
|
142
|
+
* would pass it closes the socket with `WS_CLOSE_POLICY_VIOLATION`.
|
|
143
|
+
*
|
|
144
|
+
* The count cap alone (`MAX_PRE_ADMISSION_FRAMES`) would let each pending
|
|
145
|
+
* socket hold that many full-size messages, and pending sockets are not
|
|
146
|
+
* capped per account — a registration that is never admitted must not be able
|
|
147
|
+
* to pin that much memory. Small requests, which is what a client flushes on
|
|
148
|
+
* reopen, meet the count cap long before this one.
|
|
149
|
+
*
|
|
150
|
+
* A client whose queued requests total more than this budget and flushes
|
|
151
|
+
* them all on reopen overflows it: the socket closes, the flushed requests
|
|
152
|
+
* fail, and the client reconnects.
|
|
153
|
+
*/
|
|
154
|
+
export const PRE_ADMISSION_QUEUE_BYTES_FACTOR = 4;
|
|
155
|
+
/**
|
|
156
|
+
* Max requests one socket may have dispatching at once. A request that
|
|
157
|
+
* arrives past it is answered `queue_overflow` with its id
|
|
158
|
+
* (`WS_INBOUND_DISPATCH_OVERFLOW_MESSAGE`) and not dispatched; the socket
|
|
159
|
+
* stays open, and the requests already running keep answering.
|
|
160
|
+
*
|
|
161
|
+
* A runtime adapter can hand frames over without awaiting the previous one's
|
|
162
|
+
* dispatch (`@hono/node-ws` does not await `onMessage`), so without a ceiling
|
|
163
|
+
* one socket could hold any number of handlers — and their pooled database
|
|
164
|
+
* work — at once. Shedding rather than queueing keeps the socket reading, so a
|
|
165
|
+
* reply to a server-initiated request still reaches the handler awaiting it.
|
|
166
|
+
* Generous, so ordinary pipelining never meets it. Same value as the Rust
|
|
167
|
+
* spine's `MAX_INBOUND_DISPATCHES_PER_CONNECTION`.
|
|
168
|
+
*
|
|
169
|
+
* Counted are the requests that passed envelope validation and are not yet
|
|
170
|
+
* answered — the entries of the socket's cancellation map. Notifications,
|
|
171
|
+
* replies to server-initiated requests, and refused frames never count.
|
|
172
|
+
*/
|
|
173
|
+
export const MAX_INBOUND_DISPATCHES_PER_CONNECTION = 128;
|
|
174
|
+
/**
|
|
175
|
+
* The `queue_overflow` message a request gets past
|
|
176
|
+
* `MAX_INBOUND_DISPATCHES_PER_CONNECTION`. Same text as the Rust spine's.
|
|
177
|
+
*/
|
|
178
|
+
export const WS_INBOUND_DISPATCH_OVERFLOW_MESSAGE = 'too many concurrent requests on this connection';
|
|
179
|
+
/**
|
|
180
|
+
* The `data.reason` of the `invalid_request` a WebSocket request gets when its
|
|
181
|
+
* id names a request still running on the same socket. The duplicate is not
|
|
182
|
+
* dispatched; the running request keeps its id, so its reply, and a `cancel`
|
|
183
|
+
* naming that id, stay its own. An id is free again once its request has been
|
|
184
|
+
* answered.
|
|
185
|
+
*/
|
|
186
|
+
export const ERROR_DUPLICATE_REQUEST_ID = 'duplicate_request_id';
|
|
187
|
+
/**
|
|
188
|
+
* Send one JSON-RPC error response frame to `connection_id` through the
|
|
189
|
+
* registry's outbound queue.
|
|
190
|
+
*/
|
|
191
|
+
const send_error_response = (registry, connection_id, id, error) => {
|
|
192
|
+
registry.send_to(connection_id, JSON.stringify(create_jsonrpc_error_response(id, error)));
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Build the Hono `WSEvents` for one upgraded socket: admission, the receive
|
|
196
|
+
* watchdog, the credential deadline, frame dispatch, and close (module doc).
|
|
197
|
+
*
|
|
198
|
+
* @param endpoint - the endpoint-level values, shared by all of its sockets
|
|
199
|
+
* @param upgrade - what the upgrade request captured for this socket
|
|
200
|
+
* @returns the adapter's `onOpen` / `onMessage` / `onClose` for the socket
|
|
201
|
+
*
|
|
202
|
+
* @internal
|
|
203
|
+
*/
|
|
204
|
+
export const create_ws_socket_events = (endpoint, upgrade) => {
|
|
205
|
+
const { path, db, log, registry, action_map, receive_timeout, receive_tick_interval, max_message_bytes, pre_admission_queue_max_bytes, on_socket_open, on_socket_close, action_ip_rate_limiter, action_account_rate_limiter, on_effect_error, required_roles } = endpoint;
|
|
206
|
+
const { client_ip, upgrade_preset, resolved, upgrade_context } = upgrade;
|
|
207
|
+
// the request context's account — `register_action_ws` holds it to the
|
|
208
|
+
// credential's before the upgrade
|
|
209
|
+
const account_id = upgrade_context.account.id;
|
|
210
|
+
// Session-based connections have a session hash for targeted
|
|
211
|
+
// revocation. Bearer/daemon connections pass null — still reachable
|
|
212
|
+
// by an `account` or `token` close target.
|
|
213
|
+
const session_hash = resolved_auth_session_hash(resolved);
|
|
214
|
+
// `api_token.id` — set only for bearer connections; enables a
|
|
215
|
+
// `token` close target to tear down just this socket on
|
|
216
|
+
// `token_revoke` without affecting the account's other sockets.
|
|
217
|
+
const api_token_id = resolved_auth_api_token_id(resolved);
|
|
218
|
+
// Per-socket abort controller — fires when the socket ends, chained
|
|
219
|
+
// into every in-flight handler's per-request controller via
|
|
220
|
+
// `AbortSignal.any`. Keeping both signals lets the client
|
|
221
|
+
// cancel-one-request-by-id (via the `cancel` notification) without
|
|
222
|
+
// tearing down the whole socket. Registered with the registry, which
|
|
223
|
+
// aborts it when it closes the connection (revocation, cap eviction),
|
|
224
|
+
// and aborted here on every other end (`end_socket`, `onClose`) — at
|
|
225
|
+
// close time, not when the close handshake lands.
|
|
226
|
+
const socket_abort_controller = new AbortController();
|
|
227
|
+
// Per-request controllers keyed by JSON-RPC request id — lets an
|
|
228
|
+
// incoming `cancel` notification abort just the matching handler.
|
|
229
|
+
// Populated on request dispatch, cleared in the handler's `finally`
|
|
230
|
+
// so a late-arriving cancel for a completed id (or a reused id)
|
|
231
|
+
// can't null-abort a freshly-arrived request. Idempotent: cancel
|
|
232
|
+
// for unknown ids no-ops. One entry per running request — a
|
|
233
|
+
// request reusing a live id is refused before it gets one — so its
|
|
234
|
+
// size is the in-flight count `MAX_INBOUND_DISPATCHES_PER_CONNECTION`
|
|
235
|
+
// bounds.
|
|
236
|
+
const pending_controllers = new Map();
|
|
237
|
+
// Identity is assembled at upgrade time so `on_socket_close` can
|
|
238
|
+
// read it — by the time the hook runs the registry record is gone,
|
|
239
|
+
// removed in `onClose` or earlier by a revocation, a connection-cap
|
|
240
|
+
// eviction, or another server-side close.
|
|
241
|
+
const identity = {
|
|
242
|
+
session_hash,
|
|
243
|
+
account_id,
|
|
244
|
+
api_token_id,
|
|
245
|
+
required_roles
|
|
246
|
+
};
|
|
247
|
+
// Captured on open, consumed on close. Undefined before onOpen
|
|
248
|
+
// fires or when a consumer never opens (e.g. immediate disconnect).
|
|
249
|
+
let captured_connection_id;
|
|
250
|
+
// Where the socket is in its life:
|
|
251
|
+
// - `opening` — from the handshake until admission and `on_socket_open`
|
|
252
|
+
// have both completed. Inbound frames are queued.
|
|
253
|
+
// - `open` — admitted; inbound frames dispatch.
|
|
254
|
+
// - `ended` — the client closed it, the server closed it, or it was
|
|
255
|
+
// refused at admission. Inbound frames are dropped: an adapter can
|
|
256
|
+
// keep delivering them until the close handshake lands.
|
|
257
|
+
let phase = 'opening';
|
|
258
|
+
// read through a function so a check after an `await` isn't narrowed
|
|
259
|
+
// to the value assigned before it
|
|
260
|
+
const phase_is = (expected) => phase === expected;
|
|
261
|
+
// Whether the connection was ever admitted — gates `on_socket_close`,
|
|
262
|
+
// the counterpart of an `on_socket_open` a refused socket never ran.
|
|
263
|
+
let was_admitted = false;
|
|
264
|
+
// The code the registry closed the pending registration with, taken
|
|
265
|
+
// before `onClose` removes it: the client's answer to that close can
|
|
266
|
+
// arrive before the re-read returns.
|
|
267
|
+
let pending_close_code = null;
|
|
268
|
+
// Frames received while `opening`, in arrival order — dispatched once
|
|
269
|
+
// the socket is open, dropped if it ends first. Each carries the
|
|
270
|
+
// settlers of the promise its `onMessage` call returned, so a caller
|
|
271
|
+
// awaiting that call (the test harnesses do) resumes when the frame
|
|
272
|
+
// has been dispatched or dropped.
|
|
273
|
+
const queued_frames = [];
|
|
274
|
+
// bytes queued so far, against `pre_admission_queue_max_bytes` — only
|
|
275
|
+
// read while the socket is opening, so never reset
|
|
276
|
+
let queued_bytes = 0;
|
|
277
|
+
const drop_queued_frames = () => {
|
|
278
|
+
for (const frame of queued_frames.splice(0))
|
|
279
|
+
frame.resolve();
|
|
280
|
+
};
|
|
281
|
+
// Receive-silence watchdog. Seeded at admission so the first window is
|
|
282
|
+
// exempt (cold-start grace — avoid killing mid-handshake sockets).
|
|
283
|
+
// Bumped by onMessage. Any incoming activity counts, not just
|
|
284
|
+
// heartbeats — chatty clients don't need to send extras.
|
|
285
|
+
let last_receive_time = 0;
|
|
286
|
+
let receive_timer = null;
|
|
287
|
+
const stop_receive_timer = () => {
|
|
288
|
+
if (receive_timer !== null) {
|
|
289
|
+
clearInterval(receive_timer);
|
|
290
|
+
receive_timer = null;
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
// The credential deadline: the socket closes when the credential it
|
|
294
|
+
// upgraded on expires (4001, `WS_CLOSE_CREDENTIAL_EXPIRED_REASON`) —
|
|
295
|
+
// expiry writes nothing a revocation listener hears. Started at
|
|
296
|
+
// admission, cancelled when the socket ends.
|
|
297
|
+
let cancel_credential_deadline = null;
|
|
298
|
+
const stop_credential_deadline = () => {
|
|
299
|
+
cancel_credential_deadline?.();
|
|
300
|
+
cancel_credential_deadline = null;
|
|
301
|
+
};
|
|
302
|
+
// The one place a socket's end is recorded, whoever ended it — the
|
|
303
|
+
// registry (revocation, cap eviction), `end_socket`, or `onClose` all
|
|
304
|
+
// abort this controller.
|
|
305
|
+
socket_abort_controller.signal.addEventListener('abort', () => {
|
|
306
|
+
phase = 'ended';
|
|
307
|
+
stop_receive_timer();
|
|
308
|
+
stop_credential_deadline();
|
|
309
|
+
drop_queued_frames();
|
|
310
|
+
}, { once: true });
|
|
311
|
+
// End the socket from the server side: unregister it and abort its
|
|
312
|
+
// signal *now* — so nothing more dispatches and in-flight handlers
|
|
313
|
+
// see `signal.aborted` while the close handshake is still in flight —
|
|
314
|
+
// then send the close frame. The registry does all three for a
|
|
315
|
+
// connection it still holds, sending the close behind the waiting
|
|
316
|
+
// frames the socket has room for and under the close deadline; a socket
|
|
317
|
+
// whose connection is already gone has nothing waiting and is closed
|
|
318
|
+
// directly.
|
|
319
|
+
const end_socket = (ws, code, reason) => {
|
|
320
|
+
const closed = captured_connection_id !== undefined &&
|
|
321
|
+
registry.close_connection(captured_connection_id, code, reason);
|
|
322
|
+
socket_abort_controller.abort();
|
|
323
|
+
if (closed)
|
|
324
|
+
return;
|
|
325
|
+
try {
|
|
326
|
+
ws.close(code, reason);
|
|
327
|
+
}
|
|
328
|
+
catch (error) {
|
|
329
|
+
log.error(`ws close ${code} failed:`, error);
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
// Refuse an upgrade at admission. A socket that already ended needs no
|
|
333
|
+
// close frame: a revocation closed its pending registration (the
|
|
334
|
+
// registry sent the 4001), the shutdown did (the 1001 — so a refusal
|
|
335
|
+
// during shutdown never sends a revocation's or a failure's code), or
|
|
336
|
+
// the client went away. Its registration is gone too — the registry
|
|
337
|
+
// removed it with its close, `onClose` with the client's — and it is
|
|
338
|
+
// not removed again here: `remove_connection` is for a socket that has
|
|
339
|
+
// closed, and would drop the close deadline of one that has not.
|
|
340
|
+
const refuse_upgrade = (ws, code, reason) => {
|
|
341
|
+
if (!socket_abort_controller.signal.aborted)
|
|
342
|
+
end_socket(ws, code, reason);
|
|
343
|
+
};
|
|
344
|
+
// Socket-scoped notification helper — routes to this socket only,
|
|
345
|
+
// matches the `ctx.notify` semantics exposed to per-message handlers.
|
|
346
|
+
// Through the registry's outbound queue, like every other frame: a
|
|
347
|
+
// handler that notifies past the connection's budget closes it.
|
|
348
|
+
const notify_socket = (connection_id) => (notify_method, notify_params) => {
|
|
349
|
+
try {
|
|
350
|
+
const notification = create_jsonrpc_notification(notify_method, to_jsonrpc_params(notify_params));
|
|
351
|
+
registry.send_to(connection_id, JSON.stringify(notification));
|
|
352
|
+
}
|
|
353
|
+
catch (error) {
|
|
354
|
+
log.error('notify send failed:', notify_method, error);
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
// Admit the upgraded socket: register it pending, re-check its
|
|
358
|
+
// credential, admit it (module doc, "Admission: the revocation
|
|
359
|
+
// race"). Returns the connection id once admitted, or `null` after
|
|
360
|
+
// refusing — the socket is then already closed.
|
|
361
|
+
const admit_upgrade = async (ws) => {
|
|
362
|
+
// Pending first, synchronously: from here every revocation finds it.
|
|
363
|
+
const connection_id = registry.register_pending(ws, identity, socket_abort_controller);
|
|
364
|
+
captured_connection_id = connection_id;
|
|
365
|
+
// Born closed — the server is shutting down, and the registry has
|
|
366
|
+
// already closed the socket with `WS_CLOSE_GOING_AWAY` — or ended
|
|
367
|
+
// otherwise before the re-read: nothing to re-read for. The removal
|
|
368
|
+
// is a no-op for a born-closed registration, which was never inserted.
|
|
369
|
+
if (socket_abort_controller.signal.aborted) {
|
|
370
|
+
registry.remove_connection(connection_id);
|
|
371
|
+
log.info(registry.is_closing()
|
|
372
|
+
? 'ws upgrade admission: refused, the server is shutting down'
|
|
373
|
+
: 'ws upgrade admission: socket ended before the re-check', connection_id, account_id);
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
if (!upgrade_preset) {
|
|
377
|
+
let recheck;
|
|
378
|
+
try {
|
|
379
|
+
// pool-level `db`: the reads must see every revocation committed
|
|
380
|
+
// before they start
|
|
381
|
+
recheck = await recheck_admission({ db }, { resolved, request_context: upgrade_context, required_roles });
|
|
382
|
+
}
|
|
383
|
+
catch (error) {
|
|
384
|
+
// fail closed — never admitted unchecked. During shutdown the
|
|
385
|
+
// database may close under the re-read; that is the shutdown's
|
|
386
|
+
// refusal, not a failure.
|
|
387
|
+
if (registry.is_closing()) {
|
|
388
|
+
log.info('ws upgrade admission: re-check ended by the shutdown', error);
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
log.error('ws upgrade admission: credential, actor, or role re-check failed', error);
|
|
392
|
+
}
|
|
393
|
+
refuse_upgrade(ws, WS_CLOSE_INTERNAL_ERROR, WS_CLOSE_INTERNAL_ERROR_REASON);
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
396
|
+
switch (recheck) {
|
|
397
|
+
case 'admitted':
|
|
398
|
+
break;
|
|
399
|
+
case 'credential_revoked':
|
|
400
|
+
log.info('ws upgrade admission: credential revoked during the upgrade', connection_id, account_id);
|
|
401
|
+
refuse_upgrade(ws, WS_CLOSE_SESSION_REVOKED, WS_CLOSE_SESSION_REVOKED_REASON);
|
|
402
|
+
return null;
|
|
403
|
+
case 'actor_inactive':
|
|
404
|
+
log.info('ws upgrade admission: acting actor deleted during the upgrade', connection_id, account_id);
|
|
405
|
+
refuse_upgrade(ws, WS_CLOSE_SESSION_REVOKED, WS_CLOSE_SESSION_REVOKED_REASON);
|
|
406
|
+
return null;
|
|
407
|
+
case 'role_revoked':
|
|
408
|
+
log.info('ws upgrade admission: role revoked during the upgrade', connection_id, account_id);
|
|
409
|
+
refuse_upgrade(ws, WS_CLOSE_PERMISSION_REVOKED, WS_CLOSE_PERMISSION_REVOKED_REASON);
|
|
410
|
+
return null;
|
|
411
|
+
default:
|
|
412
|
+
throw new UnreachableError(recheck);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
// The cap's eviction happens here, after every gate and the re-read,
|
|
416
|
+
// so a refused upgrade never closes someone else's socket.
|
|
417
|
+
if (!registry.admit(connection_id)) {
|
|
418
|
+
// why the entry closed, from the code the registry closed it with
|
|
419
|
+
const code = pending_close_code ?? registry.take_pending_close_code(connection_id);
|
|
420
|
+
log.info(code === WS_CLOSE_PERMISSION_REVOKED
|
|
421
|
+
? 'ws upgrade admission: closed by a permission revocation while pending'
|
|
422
|
+
: code === WS_CLOSE_SESSION_REVOKED
|
|
423
|
+
? 'ws upgrade admission: closed by a credential revocation while pending'
|
|
424
|
+
: code === WS_CLOSE_GOING_AWAY || registry.is_closing()
|
|
425
|
+
? 'ws upgrade admission: closed by the shutdown while pending'
|
|
426
|
+
: 'ws upgrade admission: ended while pending', connection_id, account_id);
|
|
427
|
+
refuse_upgrade(ws, WS_CLOSE_SESSION_REVOKED, WS_CLOSE_SESSION_REVOKED_REASON);
|
|
428
|
+
return null;
|
|
429
|
+
}
|
|
430
|
+
was_admitted = true;
|
|
431
|
+
return connection_id;
|
|
432
|
+
};
|
|
433
|
+
const open_socket = async (ws) => {
|
|
434
|
+
const connection_id = await admit_upgrade(ws);
|
|
435
|
+
if (connection_id === null)
|
|
436
|
+
return;
|
|
437
|
+
log.debug('ws opened', connection_id);
|
|
438
|
+
// Not on a socket that ended in the tick since `admit`, for the same
|
|
439
|
+
// reason as the heartbeat timer below.
|
|
440
|
+
if (!phase_is('ended')) {
|
|
441
|
+
cancel_credential_deadline = schedule_credential_deadline(resolved.credential_deadline, () => {
|
|
442
|
+
log.info('ws credential expired — closing', WS_CLOSE_SESSION_REVOKED, connection_id, identity.account_id);
|
|
443
|
+
end_socket(ws, WS_CLOSE_SESSION_REVOKED, WS_CLOSE_CREDENTIAL_EXPIRED_REASON);
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
// Not on a socket that ended in the tick since `admit` (a revocation
|
|
447
|
+
// can land there): its abort listener has already run, so nothing
|
|
448
|
+
// would ever stop the timer.
|
|
449
|
+
if (receive_timeout !== null && receive_tick_interval !== null && !phase_is('ended')) {
|
|
450
|
+
last_receive_time = Date.now();
|
|
451
|
+
receive_timer = setInterval(() => {
|
|
452
|
+
const now = Date.now();
|
|
453
|
+
const silence = now - last_receive_time;
|
|
454
|
+
if (silence >= receive_timeout) {
|
|
455
|
+
log.info(`receive timeout (${silence}ms) — closing ${WS_CLOSE_SERVER_HEARTBEAT_TIMEOUT}`, connection_id, identity.account_id);
|
|
456
|
+
stop_receive_timer();
|
|
457
|
+
end_socket(ws, WS_CLOSE_SERVER_HEARTBEAT_TIMEOUT, WS_CLOSE_SERVER_HEARTBEAT_TIMEOUT_REASON);
|
|
458
|
+
}
|
|
459
|
+
}, receive_tick_interval);
|
|
460
|
+
}
|
|
461
|
+
if (on_socket_open) {
|
|
462
|
+
try {
|
|
463
|
+
await on_socket_open({
|
|
464
|
+
ws,
|
|
465
|
+
connection_id,
|
|
466
|
+
identity,
|
|
467
|
+
notify: notify_socket(connection_id),
|
|
468
|
+
signal: socket_abort_controller.signal
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
catch (error) {
|
|
472
|
+
log.error('on_socket_open failed — closing socket:', error);
|
|
473
|
+
// an ended socket has no one to tell
|
|
474
|
+
if (phase_is('ended'))
|
|
475
|
+
return;
|
|
476
|
+
send_error_response(registry, connection_id, null, jsonrpc_error_messages.internal_error());
|
|
477
|
+
end_socket(ws, WS_CLOSE_INTERNAL_ERROR, WS_CLOSE_SOCKET_OPEN_FAILED_REASON);
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
// Ended while the hook ran (a revocation, the client leaving) — the
|
|
482
|
+
// queue is already dropped.
|
|
483
|
+
if (!phase_is('opening'))
|
|
484
|
+
return;
|
|
485
|
+
// Open: dispatch what arrived meanwhile, in arrival order and back
|
|
486
|
+
// to back, the way the adapter would have delivered it.
|
|
487
|
+
phase = 'open';
|
|
488
|
+
for (const frame of queued_frames.splice(0)) {
|
|
489
|
+
if (registry.is_registered(connection_id)) {
|
|
490
|
+
handle_frame(frame.data, connection_id).then(frame.resolve, frame.reject);
|
|
491
|
+
}
|
|
492
|
+
else {
|
|
493
|
+
frame.resolve();
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
// Dispatch one inbound frame on an admitted, still-registered
|
|
498
|
+
// connection.
|
|
499
|
+
const handle_frame = async (data, connection_id) => {
|
|
500
|
+
const send_error = (id, error) => send_error_response(registry, connection_id, id, error);
|
|
501
|
+
let json;
|
|
502
|
+
try {
|
|
503
|
+
json = JSON.parse(String(data));
|
|
504
|
+
}
|
|
505
|
+
catch (error) {
|
|
506
|
+
log.error('JSON parse error:', error);
|
|
507
|
+
send_error(null, jsonrpc_error_messages.parse_error());
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
// Batch JSON-RPC is not supported on the WebSocket path.
|
|
511
|
+
if (Array.isArray(json)) {
|
|
512
|
+
send_error(null, jsonrpc_error_messages.invalid_request('batch JSON-RPC requests are not supported on WebSocket'));
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
// One classifier for both transports (`classify_jsonrpc_message`,
|
|
516
|
+
// the Rust twin's order: version → method → id → params); this
|
|
517
|
+
// path applies the WebSocket semantics to its arms.
|
|
518
|
+
const classified = classify_jsonrpc_message(json);
|
|
519
|
+
switch (classified.kind) {
|
|
520
|
+
case 'invalid':
|
|
521
|
+
send_error(classified.id, classified.error);
|
|
522
|
+
return;
|
|
523
|
+
case 'response': {
|
|
524
|
+
// A reply to a server-initiated request (`peer/ping`, etc.) —
|
|
525
|
+
// routed to the pending-request registry scoped to THIS
|
|
526
|
+
// socket. An unmatched id (unsolicited, cross-connection, or
|
|
527
|
+
// already settled) resolves nothing and is dropped, so the
|
|
528
|
+
// read loop survives a junk frame.
|
|
529
|
+
const { response } = classified;
|
|
530
|
+
const matched = registry.resolve_peer_response(connection_id, response);
|
|
531
|
+
if (!matched)
|
|
532
|
+
audit_unmatched_peer_response(log, connection_id, response.id);
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
case 'notification': {
|
|
536
|
+
// `cancel` is intercepted for request-scoped cancellation;
|
|
537
|
+
// other notifications are silenced per JSON-RPC spec (consumer
|
|
538
|
+
// notification handlers are not a feature yet). Notifications
|
|
539
|
+
// stay unvalidated — they carry no id to answer an error on.
|
|
540
|
+
if (classified.method === cancel_action_spec.method) {
|
|
541
|
+
const parsed = CancelNotificationParams.safeParse(classified.params);
|
|
542
|
+
if (!parsed.success) {
|
|
543
|
+
log.debug('cancel: invalid params, ignoring', parsed.error.issues);
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
const controller = pending_controllers.get(parsed.data.request_id);
|
|
547
|
+
if (controller) {
|
|
548
|
+
controller.abort();
|
|
549
|
+
}
|
|
550
|
+
else {
|
|
551
|
+
log.debug('cancel: no pending request for id', parsed.data.request_id);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
case 'request':
|
|
557
|
+
break;
|
|
558
|
+
default:
|
|
559
|
+
throw new UnreachableError(classified);
|
|
560
|
+
}
|
|
561
|
+
const { method, id, params } = classified.request;
|
|
562
|
+
// A request is live from here until its reply is sent. One reusing
|
|
563
|
+
// a live id is refused rather than dispatched: two requests under
|
|
564
|
+
// one id would share a cancel entry and a reply id, and the first to
|
|
565
|
+
// finish would clear the other's. Checked before the ceiling — a
|
|
566
|
+
// duplicate is the client's error whatever the load, and retrying it
|
|
567
|
+
// cannot succeed while the first runs. Neither refusal reaches
|
|
568
|
+
// `perform_action`, so neither charges the action rate limiters —
|
|
569
|
+
// the same on the Rust spine.
|
|
570
|
+
if (pending_controllers.has(id)) {
|
|
571
|
+
send_error(id, jsonrpc_error_messages.invalid_request({ reason: ERROR_DUPLICATE_REQUEST_ID }));
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
// The in-flight ceiling: shed, don't queue — see
|
|
575
|
+
// `MAX_INBOUND_DISPATCHES_PER_CONNECTION`.
|
|
576
|
+
if (pending_controllers.size >= MAX_INBOUND_DISPATCHES_PER_CONNECTION) {
|
|
577
|
+
send_error(id, jsonrpc_error_messages.queue_overflow(WS_INBOUND_DISPATCH_OVERFLOW_MESSAGE));
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
// Per-action method lookup — return method_not_found before
|
|
581
|
+
// we engage the dispatch machinery. Specs without a handler
|
|
582
|
+
// (client-only / dispatcher-handled) miss action_map and
|
|
583
|
+
// surface as method_not_found just like unknown methods.
|
|
584
|
+
const action = action_map.get(method);
|
|
585
|
+
if (!action) {
|
|
586
|
+
send_error(id, jsonrpc_error_messages.method_not_found(method));
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
// Per-request controller — fires on explicit `cancel` or when the
|
|
590
|
+
// socket ends (via the socket_abort_controller chain below).
|
|
591
|
+
// Registered before dispatch, so the request is live (counted, and
|
|
592
|
+
// its id taken) from the moment it is accepted — so a cancel
|
|
593
|
+
// arriving mid-handler finds it;
|
|
594
|
+
// cleared in `finally` so late cancels for a completed id (or a
|
|
595
|
+
// future request that reuses the id) can't null-abort the wrong
|
|
596
|
+
// handler.
|
|
597
|
+
const request_controller = new AbortController();
|
|
598
|
+
pending_controllers.set(id, request_controller);
|
|
599
|
+
// Per-message side-effect queues. `pending_effects` collects
|
|
600
|
+
// eager fire-and-forget pool writes (audit emits, etc.);
|
|
601
|
+
// `post_commit_effects` collects deferred thunks pushed
|
|
602
|
+
// via `emit_after_commit` (WS notifications). Both flush
|
|
603
|
+
// in the `finally` so the next message sees a clean slate.
|
|
604
|
+
//
|
|
605
|
+
// Ordering invariant — the deferred queue starts first. Its
|
|
606
|
+
// thunks are invoked before the eager writes are awaited, so
|
|
607
|
+
// a revocation's close never waits on the audit INSERT: held
|
|
608
|
+
// behind a slow write, the socket would stay open on a
|
|
609
|
+
// credential already committed gone, and its next frame
|
|
610
|
+
// would be dispatched. The thunks that need a write (a
|
|
611
|
+
// success row's listener fan-out) await it themselves.
|
|
612
|
+
//
|
|
613
|
+
// Ordering invariant — reply-before-flush is load-bearing.
|
|
614
|
+
// A handler that revokes its own credential
|
|
615
|
+
// (`session_revoke_all`, `token_revoke` of the calling
|
|
616
|
+
// bearer) queues a close of this very socket on
|
|
617
|
+
// `post_commit_effects` (`queue_connection_close`), and
|
|
618
|
+
// the audit listeners repeat it from the same queue. The
|
|
619
|
+
// send on the success path runs before the `finally`
|
|
620
|
+
// flushes that queue, so the caller reads its reply and
|
|
621
|
+
// then the 4001 close. Inverting the order — flushing the
|
|
622
|
+
// queues before the send — would strand the caller without
|
|
623
|
+
// a reply.
|
|
624
|
+
const pending_effects = [];
|
|
625
|
+
const post_commit_effects = [];
|
|
626
|
+
const notify = notify_socket(connection_id);
|
|
627
|
+
// Server→client request seam (ActionPeer) — closes over this
|
|
628
|
+
// socket's connection_id so a handler can initiate a request to
|
|
629
|
+
// the originating client and await the reply.
|
|
630
|
+
const request_client = (request_method, request_params, request_options) => registry.request_connection(connection_id, request_method, request_params, request_options);
|
|
631
|
+
const signal = AbortSignal.any([socket_abort_controller.signal, request_controller.signal]);
|
|
632
|
+
try {
|
|
633
|
+
const result = await perform_action({
|
|
634
|
+
action,
|
|
635
|
+
raw_params: params,
|
|
636
|
+
request_id: id,
|
|
637
|
+
auth: resolved,
|
|
638
|
+
client_ip,
|
|
639
|
+
signal,
|
|
640
|
+
notify,
|
|
641
|
+
connection_id,
|
|
642
|
+
request_client,
|
|
643
|
+
preset: upgrade_preset
|
|
644
|
+
}, {
|
|
645
|
+
db,
|
|
646
|
+
pending_effects,
|
|
647
|
+
post_commit_effects,
|
|
648
|
+
log,
|
|
649
|
+
action_ip_rate_limiter,
|
|
650
|
+
action_account_rate_limiter
|
|
651
|
+
});
|
|
652
|
+
const { body: frame } = serialize_action_result(id, result, method, log);
|
|
653
|
+
// Refused when the connection is gone — closed while the handler
|
|
654
|
+
// ran, or closed by the handler's own notifications overflowing
|
|
655
|
+
// its outbound budget — so nothing follows a close frame.
|
|
656
|
+
registry.send_to(connection_id, frame);
|
|
657
|
+
}
|
|
658
|
+
finally {
|
|
659
|
+
pending_controllers.delete(id);
|
|
660
|
+
// deferred first — see the ordering invariant above
|
|
661
|
+
await flush_request_effects(pending_effects, post_commit_effects, log, on_effect_error
|
|
662
|
+
? (reason) => on_effect_error(reason, { transport: 'ws', method, path })
|
|
663
|
+
: undefined);
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
return {
|
|
667
|
+
onOpen: async (_event, ws) => {
|
|
668
|
+
// An adapter may not await this (`@hono/node-ws` doesn't), so it
|
|
669
|
+
// must never reject.
|
|
670
|
+
try {
|
|
671
|
+
await open_socket(ws);
|
|
672
|
+
}
|
|
673
|
+
catch (error) {
|
|
674
|
+
log.error('ws open failed — closing socket:', error);
|
|
675
|
+
refuse_upgrade(ws, WS_CLOSE_INTERNAL_ERROR, WS_CLOSE_INTERNAL_ERROR_REASON);
|
|
676
|
+
}
|
|
677
|
+
},
|
|
678
|
+
onMessage: (event, ws) => {
|
|
679
|
+
// A socket the server closed — or refused — dispatches nothing
|
|
680
|
+
// more, however long its client withholds the close frame.
|
|
681
|
+
if (phase_is('ended'))
|
|
682
|
+
return;
|
|
683
|
+
const size = ws_message_size_over(event.data, max_message_bytes);
|
|
684
|
+
if (size !== null) {
|
|
685
|
+
log.warn(`closing socket: ${size}-byte message exceeds the ${max_message_bytes}-byte cap`);
|
|
686
|
+
end_socket(ws, WS_CLOSE_MESSAGE_TOO_BIG, WS_CLOSE_MESSAGE_TOO_BIG_REASON);
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
if (phase_is('opening')) {
|
|
690
|
+
// Not open yet: queue, never dispatch — nothing runs on a
|
|
691
|
+
// credential that has not been re-read. Bounded by count and
|
|
692
|
+
// by bytes, since the adapter applies no backpressure.
|
|
693
|
+
const bytes = ws_message_size(event.data);
|
|
694
|
+
if (queued_frames.length >= MAX_PRE_ADMISSION_FRAMES ||
|
|
695
|
+
queued_bytes + bytes > pre_admission_queue_max_bytes) {
|
|
696
|
+
log.warn(`closing socket: pre-admission queue overflow (${queued_frames.length} frames, ${queued_bytes} + ${bytes} bytes)`);
|
|
697
|
+
end_socket(ws, WS_CLOSE_POLICY_VIOLATION, WS_CLOSE_PRE_ADMISSION_OVERFLOW_REASON);
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
queued_bytes += bytes;
|
|
701
|
+
last_receive_time = Date.now();
|
|
702
|
+
return new Promise((resolve, reject) => {
|
|
703
|
+
queued_frames.push({ data: event.data, resolve, reject });
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
// The registry is the authority on whether the connection is
|
|
707
|
+
// still live. A close it made (revocation, cap eviction) ended the
|
|
708
|
+
// socket above; a connection it no longer holds though nothing
|
|
709
|
+
// closed the socket — a bare `remove_connection` — is ended here,
|
|
710
|
+
// rather than left reading every frame and answering none, where
|
|
711
|
+
// a chatty client would also keep the heartbeat from reaping it.
|
|
712
|
+
const connection_id = captured_connection_id;
|
|
713
|
+
if (connection_id === undefined || !registry.is_registered(connection_id)) {
|
|
714
|
+
log.warn('closing socket: its connection is no longer registered', connection_id);
|
|
715
|
+
end_socket(ws, WS_CLOSE_INTERNAL_ERROR, WS_CLOSE_CONNECTION_UNREGISTERED_REASON);
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
// only a frame that is accepted counts as activity
|
|
719
|
+
last_receive_time = Date.now();
|
|
720
|
+
return handle_frame(event.data, connection_id);
|
|
721
|
+
},
|
|
722
|
+
onClose: async (event, ws) => {
|
|
723
|
+
// belt and braces: the abort listener stops the timer and the
|
|
724
|
+
// start is skipped on an ended socket, so this matters only if
|
|
725
|
+
// one of those is ever broken
|
|
726
|
+
stop_receive_timer();
|
|
727
|
+
socket_abort_controller.abort();
|
|
728
|
+
// Removed by the id captured on open — an adapter may hand each
|
|
729
|
+
// event its own `WSContext` (`@hono/bun` does), so the one this
|
|
730
|
+
// event carries can't identify the connection. And removed before
|
|
731
|
+
// the hook is awaited: the socket is gone, so a slow hook must not
|
|
732
|
+
// keep a dead entry that broadcasts still target and the
|
|
733
|
+
// per-account cap still counts.
|
|
734
|
+
if (captured_connection_id) {
|
|
735
|
+
if (!was_admitted) {
|
|
736
|
+
pending_close_code = registry.take_pending_close_code(captured_connection_id);
|
|
737
|
+
}
|
|
738
|
+
registry.remove_connection(captured_connection_id);
|
|
739
|
+
}
|
|
740
|
+
if (on_socket_close && captured_connection_id && was_admitted) {
|
|
741
|
+
try {
|
|
742
|
+
await on_socket_close({
|
|
743
|
+
ws,
|
|
744
|
+
connection_id: captured_connection_id,
|
|
745
|
+
identity
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
catch (error) {
|
|
749
|
+
log.error('on_socket_close failed:', error);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
log.debug('ws closed', captured_connection_id, {
|
|
753
|
+
code: event.code,
|
|
754
|
+
reason: event.reason
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
};
|
|
758
|
+
};
|
|
759
|
+
/**
|
|
760
|
+
* The byte size of an inbound WebSocket message — UTF-8 bytes for a text
|
|
761
|
+
* frame, the buffer or blob size for a binary one.
|
|
762
|
+
*/
|
|
763
|
+
const ws_message_size = (data) => {
|
|
764
|
+
if (typeof data === 'string')
|
|
765
|
+
return utf8_length(data);
|
|
766
|
+
if (data instanceof Blob)
|
|
767
|
+
return data.size;
|
|
768
|
+
if (data instanceof ArrayBuffer || ArrayBuffer.isView(data))
|
|
769
|
+
return data.byteLength;
|
|
770
|
+
return 0;
|
|
771
|
+
};
|
|
772
|
+
/**
|
|
773
|
+
* The byte size of an inbound WebSocket message when it exceeds `max_bytes`,
|
|
774
|
+
* else `null` — UTF-8 bytes for a text frame, the buffer or blob size for a
|
|
775
|
+
* binary one. A text frame that cannot exceed the cap is not encoded to be
|
|
776
|
+
* measured.
|
|
777
|
+
*/
|
|
778
|
+
const ws_message_size_over = (data, max_bytes) => {
|
|
779
|
+
if (typeof data === 'string')
|
|
780
|
+
return utf8_length_over(data, max_bytes);
|
|
781
|
+
const size = ws_message_size(data);
|
|
782
|
+
return size > max_bytes ? size : null;
|
|
783
|
+
};
|