@fuzdev/fuz_app 0.180.0 → 0.181.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 +14 -14
- package/dist/actions/action_rpc.d.ts +14 -5
- package/dist/actions/action_rpc.d.ts.map +1 -1
- package/dist/actions/action_rpc.js +53 -46
- package/dist/actions/action_types.d.ts +15 -12
- package/dist/actions/action_types.d.ts.map +1 -1
- package/dist/actions/perform_action.d.ts +4 -4
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +6 -6
- package/dist/actions/register_action_ws.d.ts +6 -2
- package/dist/actions/register_action_ws.d.ts.map +1 -1
- package/dist/actions/register_action_ws.js +14 -3
- package/dist/actions/ws_socket_session.js +1 -1
- package/dist/auth/CLAUDE.md +36 -30
- package/dist/auth/account_actions.d.ts.map +1 -1
- package/dist/auth/account_actions.js +18 -1
- package/dist/auth/account_queries.d.ts +69 -0
- package/dist/auth/account_queries.d.ts.map +1 -1
- package/dist/auth/account_queries.js +82 -0
- package/dist/auth/account_route_schema.d.ts +26 -16
- package/dist/auth/account_route_schema.d.ts.map +1 -1
- package/dist/auth/account_route_schema.js +10 -24
- package/dist/auth/account_routes.d.ts +4 -6
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +86 -66
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +63 -14
- package/dist/auth/api_token_queries.d.ts +16 -7
- package/dist/auth/api_token_queries.d.ts.map +1 -1
- package/dist/auth/api_token_queries.js +18 -18
- package/dist/auth/audit_log_route_schema.d.ts +1 -1
- package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
- 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 +10 -12
- package/dist/auth/audit_log_schema.js +4 -4
- package/dist/auth/bearer_auth.d.ts +4 -3
- package/dist/auth/bearer_auth.d.ts.map +1 -1
- package/dist/auth/bearer_auth.js +35 -31
- package/dist/auth/bootstrap_account.d.ts +65 -37
- package/dist/auth/bootstrap_account.d.ts.map +1 -1
- package/dist/auth/bootstrap_account.js +115 -66
- package/dist/auth/bootstrap_route_schema.d.ts +6 -2
- package/dist/auth/bootstrap_route_schema.d.ts.map +1 -1
- package/dist/auth/bootstrap_route_schema.js +7 -2
- package/dist/auth/bootstrap_routes.d.ts +50 -33
- package/dist/auth/bootstrap_routes.d.ts.map +1 -1
- package/dist/auth/bootstrap_routes.js +109 -87
- package/dist/auth/bootstrap_token_store.d.ts +60 -0
- package/dist/auth/bootstrap_token_store.d.ts.map +1 -0
- package/dist/auth/bootstrap_token_store.js +39 -0
- package/dist/auth/credential_headers.d.ts +71 -0
- package/dist/auth/credential_headers.d.ts.map +1 -0
- package/dist/auth/credential_headers.js +100 -0
- package/dist/auth/daemon_token.d.ts +13 -1
- package/dist/auth/daemon_token.d.ts.map +1 -1
- package/dist/auth/daemon_token.js +14 -2
- package/dist/auth/daemon_token_middleware.d.ts +10 -11
- package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.js +27 -29
- package/dist/auth/deps.d.ts +0 -11
- package/dist/auth/deps.d.ts.map +1 -1
- package/dist/auth/invite_queries.d.ts +18 -0
- package/dist/auth/invite_queries.d.ts.map +1 -1
- package/dist/auth/invite_queries.js +24 -0
- package/dist/auth/request_context.d.ts +26 -5
- package/dist/auth/request_context.d.ts.map +1 -1
- package/dist/auth/request_context.js +17 -10
- package/dist/auth/role_grant_offer_action_specs.d.ts +1 -1
- package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_action_specs.js +3 -2
- package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_actions.js +37 -14
- package/dist/auth/role_grant_offer_ddl.d.ts +7 -1
- package/dist/auth/role_grant_offer_ddl.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_ddl.js +9 -2
- package/dist/auth/role_grant_offer_queries.d.ts +56 -3
- package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_queries.js +93 -8
- package/dist/auth/role_grant_queries.d.ts +7 -0
- package/dist/auth/role_grant_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_queries.js +8 -0
- package/dist/auth/session_cookie.d.ts +105 -25
- package/dist/auth/session_cookie.d.ts.map +1 -1
- package/dist/auth/session_cookie.js +124 -15
- package/dist/auth/session_middleware.d.ts +83 -54
- package/dist/auth/session_middleware.d.ts.map +1 -1
- package/dist/auth/session_middleware.js +92 -66
- package/dist/auth/session_queries.d.ts +64 -4
- package/dist/auth/session_queries.d.ts.map +1 -1
- package/dist/auth/session_queries.js +53 -4
- package/dist/auth/signup_route_schema.d.ts +5 -5
- package/dist/auth/signup_route_schema.d.ts.map +1 -1
- package/dist/auth/signup_route_schema.js +4 -4
- package/dist/auth/signup_routes.d.ts.map +1 -1
- package/dist/auth/signup_routes.js +17 -14
- package/dist/auth/token_scope.d.ts +5 -7
- package/dist/auth/token_scope.d.ts.map +1 -1
- package/dist/auth/token_scope.js +5 -8
- package/dist/dev/setup.d.ts +6 -1
- package/dist/dev/setup.d.ts.map +1 -1
- package/dist/dev/setup.js +42 -34
- package/dist/hono_context.d.ts +21 -0
- package/dist/hono_context.d.ts.map +1 -1
- package/dist/hono_context.js +17 -0
- package/dist/http/CLAUDE.md +150 -43
- package/dist/http/auth_shape.d.ts +3 -3
- package/dist/http/common_routes.js +1 -1
- package/dist/http/db_routes.d.ts +4 -3
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +14 -14
- package/dist/http/dev_route_error_check.d.ts +6 -3
- package/dist/http/dev_route_error_check.d.ts.map +1 -1
- package/dist/http/dev_route_error_check.js +6 -3
- package/dist/http/dev_set_cookie_check.d.ts +53 -0
- package/dist/http/dev_set_cookie_check.d.ts.map +1 -0
- package/dist/http/dev_set_cookie_check.js +80 -0
- package/dist/http/error_schemas.d.ts +36 -1
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/error_schemas.js +39 -2
- package/dist/http/header_lines.d.ts +42 -0
- package/dist/http/header_lines.d.ts.map +1 -0
- package/dist/http/header_lines.js +80 -0
- package/dist/http/host.d.ts +12 -9
- package/dist/http/host.d.ts.map +1 -1
- package/dist/http/host.js +25 -20
- package/dist/http/origin.d.ts +7 -22
- package/dist/http/origin.d.ts.map +1 -1
- package/dist/http/origin.js +11 -25
- package/dist/http/proxy.d.ts +1 -0
- package/dist/http/proxy.d.ts.map +1 -1
- package/dist/http/proxy.js +3 -0
- package/dist/http/request_headers.d.ts +95 -0
- package/dist/http/request_headers.d.ts.map +1 -0
- package/dist/http/request_headers.js +110 -0
- package/dist/http/request_target.d.ts +134 -0
- package/dist/http/request_target.d.ts.map +1 -0
- package/dist/http/request_target.js +193 -0
- package/dist/http/route_error_check.d.ts +4 -11
- package/dist/http/route_error_check.d.ts.map +1 -1
- package/dist/http/route_error_check.js +4 -21
- package/dist/http/route_result.d.ts +127 -23
- package/dist/http/route_result.d.ts.map +1 -1
- package/dist/http/route_result.js +97 -19
- package/dist/http/route_spec.d.ts +298 -82
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +548 -71
- package/dist/http/simple_request.d.ts +19 -14
- package/dist/http/simple_request.d.ts.map +1 -1
- package/dist/http/simple_request.js +17 -29
- package/dist/http/surface.d.ts +2 -0
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface.js +4 -1
- package/dist/realtime/outbound_budget.d.ts +1 -2
- package/dist/realtime/outbound_budget.d.ts.map +1 -1
- package/dist/realtime/outbound_budget.js +1 -2
- package/dist/realtime/sse.d.ts +47 -17
- package/dist/realtime/sse.d.ts.map +1 -1
- package/dist/realtime/sse.js +115 -93
- package/dist/realtime/sse_constants.d.ts +7 -1
- package/dist/realtime/sse_constants.d.ts.map +1 -1
- package/dist/realtime/sse_constants.js +12 -1
- package/dist/realtime/sse_registry.d.ts +3 -3
- package/dist/realtime/sse_registry.js +3 -3
- package/dist/runtime/deps.d.ts +20 -4
- package/dist/runtime/deps.d.ts.map +1 -1
- package/dist/runtime/mock.d.ts +7 -1
- package/dist/runtime/mock.d.ts.map +1 -1
- package/dist/runtime/mock.js +33 -3
- package/dist/runtime/node.d.ts.map +1 -1
- package/dist/runtime/node.js +2 -1
- package/dist/runtime/secure_file.d.ts +71 -10
- package/dist/runtime/secure_file.d.ts.map +1 -1
- package/dist/runtime/secure_file.js +91 -11
- package/dist/server/app_backend.d.ts +0 -8
- package/dist/server/app_backend.d.ts.map +1 -1
- package/dist/server/app_backend.js +1 -3
- package/dist/server/app_server.d.ts +28 -17
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +52 -34
- package/dist/server/serve_fact_route.d.ts.map +1 -1
- package/dist/server/serve_fact_route.js +49 -45
- package/dist/server/static.d.ts +20 -0
- package/dist/server/static.d.ts.map +1 -1
- package/dist/server/static.js +56 -8
- package/dist/server/unmatched_route.d.ts +42 -0
- package/dist/server/unmatched_route.d.ts.map +1 -0
- package/dist/server/unmatched_route.js +64 -0
- package/dist/testing/CLAUDE.md +404 -1200
- package/dist/testing/app_server.d.ts +3 -1
- package/dist/testing/app_server.d.ts.map +1 -1
- package/dist/testing/app_server.js +4 -10
- package/dist/testing/auth_apps.d.ts.map +1 -1
- package/dist/testing/auth_apps.js +2 -1
- package/dist/testing/cross_backend/account_lifecycle.d.ts +11 -4
- package/dist/testing/cross_backend/account_lifecycle.d.ts.map +1 -1
- package/dist/testing/cross_backend/account_lifecycle.js +277 -6
- package/dist/testing/cross_backend/build_test_backend_paths.d.ts +4 -1
- package/dist/testing/cross_backend/build_test_backend_paths.d.ts.map +1 -1
- package/dist/testing/cross_backend/build_test_backend_paths.js +1 -1
- package/dist/testing/cross_backend/capabilities.d.ts +68 -5
- package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
- package/dist/testing/cross_backend/capabilities.js +20 -4
- package/dist/testing/cross_backend/cell_gated_create.js +1 -1
- package/dist/testing/cross_backend/conformance_case.d.ts +63 -21
- package/dist/testing/cross_backend/conformance_case.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.d.ts +54 -12
- package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.js +179 -23
- package/dist/testing/cross_backend/cookie_attributes.js +1 -1
- package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts +7 -1
- package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/create_dual_spawn_global_setup.js +3 -3
- package/dist/testing/cross_backend/credential_conformance.d.ts +196 -0
- package/dist/testing/cross_backend/credential_conformance.d.ts.map +1 -0
- package/dist/testing/cross_backend/credential_conformance.js +296 -0
- package/dist/testing/cross_backend/credential_conformance.json +1284 -0
- package/dist/testing/cross_backend/credential_conformance_wire.d.ts +40 -0
- package/dist/testing/cross_backend/credential_conformance_wire.d.ts.map +1 -0
- package/dist/testing/cross_backend/credential_conformance_wire.js +293 -0
- package/dist/testing/cross_backend/credential_header_robustness.d.ts +1 -3
- package/dist/testing/cross_backend/credential_header_robustness.d.ts.map +1 -1
- package/dist/testing/cross_backend/credential_header_robustness.js +24 -55
- package/dist/testing/cross_backend/credential_wire.d.ts +112 -0
- package/dist/testing/cross_backend/credential_wire.d.ts.map +1 -0
- package/dist/testing/cross_backend/credential_wire.js +188 -0
- package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_backend_configs.js +22 -2
- package/dist/testing/cross_backend/default_spine_surface.js +1 -1
- package/dist/testing/cross_backend/differential.d.ts +1 -1
- package/dist/testing/cross_backend/differential.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential.js +3 -2
- package/dist/testing/cross_backend/differential_normalize.d.ts +23 -6
- package/dist/testing/cross_backend/differential_normalize.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential_normalize.js +11 -5
- package/dist/testing/cross_backend/full_spine_mount.d.ts +1 -0
- package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
- package/dist/testing/cross_backend/full_spine_mount.js +7 -0
- package/dist/testing/cross_backend/identity_parity.d.ts.map +1 -1
- package/dist/testing/cross_backend/identity_parity.js +4 -0
- package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/in_process_setup.js +78 -4
- package/dist/testing/cross_backend/login_security.d.ts.map +1 -1
- package/dist/testing/cross_backend/login_security.js +13 -10
- package/dist/testing/cross_backend/peer_ping_ws.d.ts +1 -1
- package/dist/testing/cross_backend/peer_ping_ws.js +2 -2
- package/dist/testing/cross_backend/request_header_conformance.d.ts +174 -0
- package/dist/testing/cross_backend/request_header_conformance.d.ts.map +1 -0
- package/dist/testing/cross_backend/request_header_conformance.js +196 -0
- package/dist/testing/cross_backend/request_header_conformance.json +1158 -0
- package/dist/testing/cross_backend/request_header_conformance_wire.d.ts +39 -0
- package/dist/testing/cross_backend/request_header_conformance_wire.d.ts.map +1 -0
- package/dist/testing/cross_backend/request_header_conformance_wire.js +284 -0
- package/dist/testing/cross_backend/request_target_conformance.d.ts +298 -0
- package/dist/testing/cross_backend/request_target_conformance.d.ts.map +1 -0
- package/dist/testing/cross_backend/request_target_conformance.js +186 -0
- package/dist/testing/cross_backend/request_target_conformance.json +3765 -0
- package/dist/testing/cross_backend/request_target_conformance_wire.d.ts +32 -0
- package/dist/testing/cross_backend/request_target_conformance_wire.d.ts.map +1 -0
- package/dist/testing/cross_backend/request_target_conformance_wire.js +278 -0
- package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +173 -1
- package/dist/testing/cross_backend/role_grant_offer_notification_ws.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_offer_notification_ws.js +2 -1
- package/dist/testing/cross_backend/rpc_adversarial.d.ts +6 -4
- package/dist/testing/cross_backend/rpc_adversarial.d.ts.map +1 -1
- package/dist/testing/cross_backend/rpc_adversarial.js +5 -2
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +6 -7
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.js +4 -5
- package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
- package/dist/testing/cross_backend/session_cap.js +56 -29
- package/dist/testing/cross_backend/session_cookie_effect.d.ts +43 -0
- package/dist/testing/cross_backend/session_cookie_effect.d.ts.map +1 -0
- package/dist/testing/cross_backend/session_cookie_effect.js +103 -0
- package/dist/testing/cross_backend/session_login.d.ts +24 -0
- package/dist/testing/cross_backend/session_login.d.ts.map +1 -0
- package/dist/testing/cross_backend/session_login.js +31 -0
- package/dist/testing/cross_backend/setup.d.ts +117 -0
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +193 -9
- package/dist/testing/cross_backend/simple_request.d.ts.map +1 -1
- package/dist/testing/cross_backend/simple_request.js +5 -0
- package/dist/testing/cross_backend/spine_suites.d.ts +9 -1
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +88 -5
- package/dist/testing/cross_backend/spine_surface_constants.d.ts +1 -1
- package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_surface_constants.js +1 -0
- package/dist/testing/cross_backend/sse_round_trip.d.ts +8 -5
- package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/sse_round_trip.js +205 -64
- package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_backdoor.js +5 -2
- package/dist/testing/cross_backend/testing_credential_read.d.ts +165 -0
- package/dist/testing/cross_backend/testing_credential_read.d.ts.map +1 -0
- package/dist/testing/cross_backend/testing_credential_read.js +175 -0
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +19 -0
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +22 -6
- package/dist/testing/cross_backend/token_lifetime.d.ts.map +1 -1
- package/dist/testing/cross_backend/token_lifetime.js +58 -2
- package/dist/testing/cross_backend/transport_composition.d.ts +2 -4
- package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
- package/dist/testing/cross_backend/transport_composition.js +13 -10
- package/dist/testing/cross_backend/ts_spine_backend_config.d.ts.map +1 -1
- package/dist/testing/cross_backend/ts_spine_backend_config.js +5 -3
- package/dist/testing/cross_backend/ws_endpoint.d.ts +11 -1
- package/dist/testing/cross_backend/ws_endpoint.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_endpoint.js +19 -2
- package/dist/testing/cross_backend/ws_role_gated.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_role_gated.js +2 -3
- package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_round_trip.js +28 -12
- package/dist/testing/cross_backend/xfail.d.ts +44 -11
- package/dist/testing/cross_backend/xfail.d.ts.map +1 -1
- package/dist/testing/cross_backend/xfail.js +68 -23
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +4 -3
- package/dist/testing/integration.d.ts +1 -2
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +14 -8
- package/dist/testing/integration_helpers.d.ts +50 -3
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/integration_helpers.js +87 -9
- package/dist/testing/middleware.d.ts +2 -0
- package/dist/testing/middleware.d.ts.map +1 -1
- package/dist/testing/middleware.js +9 -2
- package/dist/testing/round_trip.d.ts +6 -2
- package/dist/testing/round_trip.d.ts.map +1 -1
- package/dist/testing/round_trip.js +17 -6
- package/dist/testing/rpc_envelope_cases.d.ts.map +1 -1
- package/dist/testing/rpc_envelope_cases.js +7 -0
- package/dist/testing/rpc_helpers.d.ts +4 -2
- package/dist/testing/rpc_helpers.d.ts.map +1 -1
- package/dist/testing/rpc_helpers.js +6 -1
- package/dist/testing/rpc_round_trip.d.ts +13 -2
- package/dist/testing/rpc_round_trip.d.ts.map +1 -1
- package/dist/testing/rpc_round_trip.js +25 -6
- package/dist/testing/schema_generators.d.ts +2 -2
- package/dist/testing/schema_generators.d.ts.map +1 -1
- package/dist/testing/schema_generators.js +4 -4
- package/dist/testing/stubs.d.ts +2 -2
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +8 -8
- package/dist/testing/transports/fetch_transport.d.ts +6 -3
- package/dist/testing/transports/fetch_transport.d.ts.map +1 -1
- package/dist/testing/transports/fetch_transport.js +31 -19
- package/dist/testing/transports/raw_http.d.ts +61 -1
- package/dist/testing/transports/raw_http.d.ts.map +1 -1
- package/dist/testing/transports/raw_http.js +61 -1
- package/dist/testing/transports/ws_raw_client.d.ts +20 -0
- package/dist/testing/transports/ws_raw_client.d.ts.map +1 -1
- package/dist/testing/transports/ws_raw_client.js +10 -4
- package/dist/testing/transports/ws_transport.d.ts +21 -1
- package/dist/testing/transports/ws_transport.d.ts.map +1 -1
- package/dist/testing/transports/ws_transport.js +58 -20
- package/package.json +1 -1
|
@@ -20,8 +20,10 @@
|
|
|
20
20
|
* So every `POST` route carries a content-type check, run first by
|
|
21
21
|
* `apply_route_specs` (`is_post_content_type_refused`, 415
|
|
22
22
|
* `unsupported_content_type`): a JSON route takes only `application/json`,
|
|
23
|
-
* bodyless or not, and a `raw_body` route takes any type that
|
|
24
|
-
* safelisted.
|
|
23
|
+
* bodyless or not, and a `raw_body` route takes any well-formed type that
|
|
24
|
+
* isn't safelisted. Both read the `Content-Type` lines the client sent through
|
|
25
|
+
* `read_content_type` (`http/request_headers.ts`), so a second line, or an
|
|
26
|
+
* empty one, is refused on every runtime. Only `POST` needs it: `PUT`, `PATCH`, and `DELETE` are never
|
|
25
27
|
* simple methods, so the browser always preflights them.
|
|
26
28
|
*
|
|
27
29
|
* The check rests on the server answering no preflight. A consumer that adds
|
|
@@ -34,30 +36,33 @@
|
|
|
34
36
|
*
|
|
35
37
|
* @module
|
|
36
38
|
*/
|
|
39
|
+
import type { HeaderRead } from './request_headers.js';
|
|
37
40
|
/**
|
|
38
41
|
* True when a browser could have sent a `POST` with this `Content-Type`
|
|
39
42
|
* cross-origin without a preflight: none, or a CORS-safelisted one.
|
|
40
43
|
*
|
|
41
|
-
*
|
|
42
|
-
* one
|
|
43
|
-
*
|
|
44
|
+
* A malformed `Content-Type` (`read_content_type` refuses it — two lines, an
|
|
45
|
+
* empty one, an essence off the grammar, a byte outside header text) counts
|
|
46
|
+
* as simple too: a browser would refuse to call some of those safelisted, so
|
|
47
|
+
* this only ever refuses too much, never too little.
|
|
44
48
|
*
|
|
45
|
-
* @param content_type - the request's `Content-Type`
|
|
49
|
+
* @param content_type - the request's `Content-Type`, as `read_content_type` read it
|
|
46
50
|
*/
|
|
47
|
-
export declare const is_cors_simple_content_type: (content_type: string
|
|
51
|
+
export declare const is_cors_simple_content_type: (content_type: HeaderRead<string>) => boolean;
|
|
48
52
|
/**
|
|
49
|
-
* True when `Content-Type` is
|
|
50
|
-
* `charset`, allowed).
|
|
53
|
+
* True when `Content-Type` is exactly one well-formed line whose essence is
|
|
54
|
+
* `application/json` (any parameters, such as `charset`, allowed).
|
|
51
55
|
*
|
|
52
|
-
* @param content_type - the request's `Content-Type`
|
|
56
|
+
* @param content_type - the request's `Content-Type`, as `read_content_type` read it
|
|
53
57
|
*/
|
|
54
|
-
export declare const is_json_content_type: (content_type: string
|
|
58
|
+
export declare const is_json_content_type: (content_type: HeaderRead<string>) => boolean;
|
|
55
59
|
/**
|
|
56
60
|
* True when a `POST` route refuses this `Content-Type`: a JSON route anything
|
|
57
|
-
* but `application/json`, a `raw_body` route a CORS-safelisted type or
|
|
61
|
+
* but `application/json`, a `raw_body` route a CORS-safelisted type, none, or
|
|
62
|
+
* a malformed one.
|
|
58
63
|
*
|
|
59
|
-
* @param content_type - the request's `Content-Type`
|
|
64
|
+
* @param content_type - the request's `Content-Type`, as `read_content_type` read it
|
|
60
65
|
* @param raw_body - the route's `RouteSpec.raw_body`
|
|
61
66
|
*/
|
|
62
|
-
export declare const is_post_content_type_refused: (content_type: string
|
|
67
|
+
export declare const is_post_content_type_refused: (content_type: HeaderRead<string>, raw_body: boolean) => boolean;
|
|
63
68
|
//# sourceMappingURL=simple_request.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simple_request.d.ts","sourceRoot":"","sources":["../../src/lib/http/simple_request.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"simple_request.d.ts","sourceRoot":"","sources":["../../src/lib/http/simple_request.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AASvD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,2BAA2B,GAAI,cAAc,UAAU,CAAC,MAAM,CAAC,KAAG,OACM,CAAC;AAEtF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAAI,cAAc,UAAU,CAAC,MAAM,CAAC,KAAG,OACC,CAAC;AAE1E;;;;;;;GAOG;AACH,eAAO,MAAM,4BAA4B,GACxC,cAAc,UAAU,CAAC,MAAM,CAAC,EAChC,UAAU,OAAO,KACf,OACwF,CAAC"}
|
|
@@ -20,8 +20,10 @@
|
|
|
20
20
|
* So every `POST` route carries a content-type check, run first by
|
|
21
21
|
* `apply_route_specs` (`is_post_content_type_refused`, 415
|
|
22
22
|
* `unsupported_content_type`): a JSON route takes only `application/json`,
|
|
23
|
-
* bodyless or not, and a `raw_body` route takes any type that
|
|
24
|
-
* safelisted.
|
|
23
|
+
* bodyless or not, and a `raw_body` route takes any well-formed type that
|
|
24
|
+
* isn't safelisted. Both read the `Content-Type` lines the client sent through
|
|
25
|
+
* `read_content_type` (`http/request_headers.ts`), so a second line, or an
|
|
26
|
+
* empty one, is refused on every runtime. Only `POST` needs it: `PUT`, `PATCH`, and `DELETE` are never
|
|
25
27
|
* simple methods, so the browser always preflights them.
|
|
26
28
|
*
|
|
27
29
|
* The check rests on the server answering no preflight. A consumer that adds
|
|
@@ -40,45 +42,31 @@ const CORS_SAFELISTED_CONTENT_TYPES = new Set([
|
|
|
40
42
|
'application/x-www-form-urlencoded',
|
|
41
43
|
'multipart/form-data'
|
|
42
44
|
]);
|
|
43
|
-
/** Any character outside visible ASCII and tab — what Rust's `HeaderValue::to_str` refuses. */
|
|
44
|
-
const NON_VISIBLE_ASCII = /[^\t\x20-\x7e]/;
|
|
45
|
-
/**
|
|
46
|
-
* The MIME essence (`type/subtype`, lowercased, parameters dropped) of a
|
|
47
|
-
* `Content-Type` value, or `null` when it holds anything but visible ASCII.
|
|
48
|
-
*/
|
|
49
|
-
const to_content_type_essence = (content_type) => {
|
|
50
|
-
if (NON_VISIBLE_ASCII.test(content_type))
|
|
51
|
-
return null;
|
|
52
|
-
return (content_type.split(';')[0] ?? '').trim().toLowerCase();
|
|
53
|
-
};
|
|
54
45
|
/**
|
|
55
46
|
* True when a browser could have sent a `POST` with this `Content-Type`
|
|
56
47
|
* cross-origin without a preflight: none, or a CORS-safelisted one.
|
|
57
48
|
*
|
|
58
|
-
*
|
|
59
|
-
* one
|
|
60
|
-
*
|
|
49
|
+
* A malformed `Content-Type` (`read_content_type` refuses it — two lines, an
|
|
50
|
+
* empty one, an essence off the grammar, a byte outside header text) counts
|
|
51
|
+
* as simple too: a browser would refuse to call some of those safelisted, so
|
|
52
|
+
* this only ever refuses too much, never too little.
|
|
61
53
|
*
|
|
62
|
-
* @param content_type - the request's `Content-Type`
|
|
54
|
+
* @param content_type - the request's `Content-Type`, as `read_content_type` read it
|
|
63
55
|
*/
|
|
64
|
-
export const is_cors_simple_content_type = (content_type) =>
|
|
65
|
-
if (content_type === undefined)
|
|
66
|
-
return true;
|
|
67
|
-
const essence = to_content_type_essence(content_type);
|
|
68
|
-
return essence === null || CORS_SAFELISTED_CONTENT_TYPES.has(essence);
|
|
69
|
-
};
|
|
56
|
+
export const is_cors_simple_content_type = (content_type) => content_type.kind !== 'one' || CORS_SAFELISTED_CONTENT_TYPES.has(content_type.value);
|
|
70
57
|
/**
|
|
71
|
-
* True when `Content-Type` is
|
|
72
|
-
* `charset`, allowed).
|
|
58
|
+
* True when `Content-Type` is exactly one well-formed line whose essence is
|
|
59
|
+
* `application/json` (any parameters, such as `charset`, allowed).
|
|
73
60
|
*
|
|
74
|
-
* @param content_type - the request's `Content-Type`
|
|
61
|
+
* @param content_type - the request's `Content-Type`, as `read_content_type` read it
|
|
75
62
|
*/
|
|
76
|
-
export const is_json_content_type = (content_type) => content_type
|
|
63
|
+
export const is_json_content_type = (content_type) => content_type.kind === 'one' && content_type.value === 'application/json';
|
|
77
64
|
/**
|
|
78
65
|
* True when a `POST` route refuses this `Content-Type`: a JSON route anything
|
|
79
|
-
* but `application/json`, a `raw_body` route a CORS-safelisted type or
|
|
66
|
+
* but `application/json`, a `raw_body` route a CORS-safelisted type, none, or
|
|
67
|
+
* a malformed one.
|
|
80
68
|
*
|
|
81
|
-
* @param content_type - the request's `Content-Type`
|
|
69
|
+
* @param content_type - the request's `Content-Type`, as `read_content_type` read it
|
|
82
70
|
* @param raw_body - the route's `RouteSpec.raw_body`
|
|
83
71
|
*/
|
|
84
72
|
export const is_post_content_type_refused = (content_type, raw_body) => raw_body ? is_cors_simple_content_type(content_type) : !is_json_content_type(content_type);
|
package/dist/http/surface.d.ts
CHANGED
|
@@ -47,6 +47,8 @@ export interface AppSurfaceRoute {
|
|
|
47
47
|
output_schema: unknown;
|
|
48
48
|
/** JSON Schema representations of error responses, keyed by HTTP status code. `null` when none. */
|
|
49
49
|
error_schemas: Record<string, unknown> | null;
|
|
50
|
+
/** The headers every answer of the route carries (`RouteSpec.response_headers`). Absent when none. */
|
|
51
|
+
response_headers?: Record<string, string>;
|
|
50
52
|
}
|
|
51
53
|
/** A middleware in the generated attack surface (JSON-serializable). */
|
|
52
54
|
export interface AppSurfaceMiddleware {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"surface.d.ts","sourceRoot":"","sources":["../../src/lib/http/surface.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAS,KAAK,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAErE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAO7E,OAAO,EAGN,KAAK,aAAa,EAClB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAA2B,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAI9E,mEAAmE;AACnE,MAAM,WAAW,eAAe;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,SAAS,CAAC;IAChB,qBAAqB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,mEAAmE;IACnE,WAAW,EAAE,OAAO,CAAC;IACrB,uEAAuE;IACvE,WAAW,EAAE,OAAO,CAAC;IACrB;;;;OAIG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB,oFAAoF;IACpF,cAAc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CAAC,eAAe,CAAC,CAAC;IACvC;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,aAAa,CAAC,sBAAsB,CAAC,CAAC;IACrD;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CACtD;AAID;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,GAAI,QAAQ,SAAS,KAAG,KAAK,CAAC,aAAa,CAc5E,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAC7B,aAAa,KAAK,CAAC,SAAS,CAAC,EAC7B,cAAc,KAAK,CAAC,oBAAoB,CAAC,KACvC,KAAK,CAAC,eAAe,CAQvB,CAAC;AA2BF;;;GAGG;AACH,eAAO,MAAM,oBAAoB,GAAI,SAAS,yBAAyB,KAAG,UA0IzE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,uBAAuB,GAAI,SAAS,yBAAyB,KAAG,cAa5E,CAAC"}
|
package/dist/http/surface.js
CHANGED
|
@@ -151,7 +151,10 @@ export const generate_app_surface = (options) => {
|
|
|
151
151
|
query_schema: r.query ? to_surface(r.query, 'input', `${route} query`) : null,
|
|
152
152
|
input_schema: to_surface(r.input, 'input', `${route} input`),
|
|
153
153
|
output_schema: to_surface(r.output, 'output', `${route} output`),
|
|
154
|
-
error_schemas
|
|
154
|
+
error_schemas,
|
|
155
|
+
...(r.response_headers && Object.keys(r.response_headers).length > 0
|
|
156
|
+
? { response_headers: { ...r.response_headers } }
|
|
157
|
+
: {})
|
|
155
158
|
};
|
|
156
159
|
}),
|
|
157
160
|
rpc_endpoints: rpc_endpoints?.length
|
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
* from anywhere, so a client that stopped reading makes the server hold what it
|
|
7
7
|
* has not taken. `OutboundBudget` is the bound on that, and it is accounting
|
|
8
8
|
* only — its owner holds the frames and decides what "waiting" means for its
|
|
9
|
-
* connection (`WsOutboundWriter` for a WebSocket, `
|
|
10
|
-
* SSE stream).
|
|
9
|
+
* connection (`WsOutboundWriter` for a WebSocket, `create_sse_stream` for an SSE stream).
|
|
11
10
|
*
|
|
12
11
|
* - **The charge.** Each waiting frame is charged its payload bytes — the
|
|
13
12
|
* UTF-8 length of its text — plus `OUTBOUND_FRAME_OVERHEAD_BYTES`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outbound_budget.d.ts","sourceRoot":"","sources":["../../src/lib/realtime/outbound_budget.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"outbound_budget.d.ts","sourceRoot":"","sources":["../../src/lib/realtime/outbound_budget.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAEhD,yEAAyE;AACzE,MAAM,WAAW,gBAAgB;IAChC,qFAAqF;IACrF,YAAY,EAAE,MAAM,CAAC;IACrB,sBAAsB;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,yEAAyE;IACzE,WAAW,EAAE,MAAM,CAAC;CACpB;AAED;;;;;GAKG;AACH,qBAAa,cAAc;;IAC1B,4BAA4B;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAK3B;;;OAGG;gBACS,SAAS,EAAE,MAAM;IAO7B,6DAA6D;IAC7D,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED,sBAAsB;IACtB,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO;IAanC;;;;;OAKG;IACH,OAAO,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAKlC;;;;OAIG;IACH,KAAK,IAAI,IAAI;IAKb;;;;OAIG;IACH,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,gBAAgB;CAGlD"}
|
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
* from anywhere, so a client that stopped reading makes the server hold what it
|
|
7
7
|
* has not taken. `OutboundBudget` is the bound on that, and it is accounting
|
|
8
8
|
* only — its owner holds the frames and decides what "waiting" means for its
|
|
9
|
-
* connection (`WsOutboundWriter` for a WebSocket, `
|
|
10
|
-
* SSE stream).
|
|
9
|
+
* connection (`WsOutboundWriter` for a WebSocket, `create_sse_stream` for an SSE stream).
|
|
11
10
|
*
|
|
12
11
|
* - **The charge.** Each waiting frame is charged its payload bytes — the
|
|
13
12
|
* UTF-8 length of its text — plus `OUTBOUND_FRAME_OVERHEAD_BYTES`.
|
package/dist/realtime/sse.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ export interface SseNotification {
|
|
|
66
66
|
/** Method-specific payload. */
|
|
67
67
|
params: unknown;
|
|
68
68
|
}
|
|
69
|
-
/** Options for `create_sse_response`. */
|
|
69
|
+
/** Options for `create_sse_stream` and `create_sse_response`. */
|
|
70
70
|
export interface SseResponseOptions {
|
|
71
71
|
/**
|
|
72
72
|
* The account the stream belongs to, named in the warning logged when the
|
|
@@ -81,34 +81,64 @@ export interface SseResponseOptions {
|
|
|
81
81
|
*/
|
|
82
82
|
keep_alive_ms?: number | null;
|
|
83
83
|
}
|
|
84
|
+
/** An open SSE stream and the body its response streams, unanswered. */
|
|
85
|
+
export interface OpenedSseStream<T> {
|
|
86
|
+
/** The controller — `send`, `close`, `on_close`. */
|
|
87
|
+
stream: SseStream<T>;
|
|
88
|
+
/**
|
|
89
|
+
* The response body: what the stream writes, read as the client reads it.
|
|
90
|
+
* Answered with `SSE_RESPONSE_HEADERS`; cancelled when the stream is not
|
|
91
|
+
* answered with.
|
|
92
|
+
*/
|
|
93
|
+
body: ReadableStream<Uint8Array>;
|
|
94
|
+
}
|
|
84
95
|
/**
|
|
85
|
-
*
|
|
96
|
+
* Open an SSE stream on a request without building its response: the
|
|
97
|
+
* controller and the body, and nothing written on the context. What a route
|
|
98
|
+
* spec's `RouteContext.open_sse` opens with (`create_app_server` hands it to
|
|
99
|
+
* `apply_route_specs`), so the response is built only when the route answers
|
|
100
|
+
* with the stream (`route_sse`), through the context and with
|
|
101
|
+
* `SSE_RESPONSE_HEADERS` — and a route that opens a stream and answers
|
|
102
|
+
* something else answers it with none of the stream's headers.
|
|
86
103
|
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* stream that is already closed, so register cleanup with `on_close` (which
|
|
96
|
-
* runs a late listener at once) before handing the stream anywhere that would
|
|
97
|
-
* count it — `SseRegistry.admit` after `on_close(pending.unsubscribe)`
|
|
98
|
-
* refuses it.
|
|
99
|
-
*
|
|
100
|
-
* Uses `hono_stream.write()` directly (not `writeSSE`) to avoid
|
|
101
|
-
* Hono's HTML callback resolution — keeps the same `data: JSON\n\n` format.
|
|
104
|
+
* The stream exists — `send`, `close`, `on_close` work — from the moment this
|
|
105
|
+
* returns. It stays open until `close()` or its client disconnects, whenever
|
|
106
|
+
* that happens — also before the response is built, which no runtime reports
|
|
107
|
+
* by cancelling a body it has not started to send. A client already gone when
|
|
108
|
+
* this is called yields a stream that is already closed, so register cleanup
|
|
109
|
+
* with `on_close` (which runs a late listener at once) before handing the
|
|
110
|
+
* stream anywhere that would count it — `SseRegistry.admit` after
|
|
111
|
+
* `on_close(pending.unsubscribe)` refuses it.
|
|
102
112
|
*
|
|
113
|
+
* Frames are written with `hono_stream.write()` (not `writeSSE`), avoiding
|
|
114
|
+
* Hono's HTML callback resolution — the `data: JSON\n\n` format as written.
|
|
103
115
|
* What the stream holds unread is bounded by `SSE_OUTBOUND_QUEUE_BYTES`; a
|
|
104
116
|
* frame past it ends the stream (module doc, "Outbound bound").
|
|
105
117
|
*
|
|
118
|
+
* @param c - the request's context, read for its client's disconnect only
|
|
119
|
+
* @param log - logger for serialization and `on_close` listener errors, and
|
|
120
|
+
* for the warning when the stream ends on its outbound budget
|
|
121
|
+
* @param options - what the overflow warning names, and the keep-alive interval
|
|
122
|
+
* @returns the `SseStream` controller and the response body
|
|
123
|
+
* @throws Error when `options.keep_alive_ms` is out of range
|
|
124
|
+
* (`validate_sse_keep_alive_ms`)
|
|
125
|
+
*/
|
|
126
|
+
export declare const create_sse_stream: <T = unknown>(c: Context, log: Logger, options?: SseResponseOptions) => OpenedSseStream<T>;
|
|
127
|
+
/**
|
|
128
|
+
* Create an SSE response for a Hono context: `create_sse_stream`, answered at
|
|
129
|
+
* once through the context with `SSE_RESPONSE_HEADERS` — the response
|
|
130
|
+
* Hono's `streamSSE` builds, so it carries the headers the middleware put on
|
|
131
|
+
* the context. For a handler outside the route-spec system; a route spec opens
|
|
132
|
+
* its stream through `RouteContext.open_sse` instead, which builds the
|
|
133
|
+
* response only when the route answers with it.
|
|
134
|
+
*
|
|
106
135
|
* @param log - logger for serialization and `on_close` listener errors, and
|
|
107
136
|
* for the warning when the stream ends on its outbound budget
|
|
108
137
|
* @param options - what the overflow warning names, and the keep-alive interval
|
|
109
138
|
* @returns object with the streaming `Response` and an `SseStream` controller
|
|
110
139
|
* @throws Error when `options.keep_alive_ms` is out of range
|
|
111
140
|
* (`validate_sse_keep_alive_ms`)
|
|
141
|
+
* @mutates `c` - writes `SSE_RESPONSE_HEADERS` on the context's headers
|
|
112
142
|
*/
|
|
113
143
|
export declare const create_sse_response: <T = unknown>(c: Context, log: Logger, options?: SseResponseOptions) => {
|
|
114
144
|
response: Response;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../src/lib/realtime/sse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAGpC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAS,KAAK,SAAS,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"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AC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,GAAG,OAAO,EAC9C,GAAG,OAAO,EACV,KAAK,MAAM,EACX,UAAU,kBAAkB,KAC1B;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAA;CAI5C,CAAC;AAEF,gFAAgF;AAChF,MAAM,WAAW,SAAS;IACzB,qEAAqE;IACrE,MAAM,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,MAAM,EAAE,SAAS,CAAC;IAClB,8DAA8D;IAC9D,WAAW,EAAE,MAAM,CAAC;IACpB,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,4BAA4B,GAAI,CAAC,SAAS,eAAe,EACrE,aAAa;IAAE,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,KAAK,IAAI,CAAA;CAAE,EAC9D,aAAa,KAAK,CAAC,SAAS,CAAC,EAC7B,KAAK,MAAM,KACT;IAAE,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,KAAK,IAAI,CAAA;CAmBjD,CAAC"}
|
package/dist/realtime/sse.js
CHANGED
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
*
|
|
31
31
|
* @module
|
|
32
32
|
*/
|
|
33
|
-
import {
|
|
33
|
+
import { SSEStreamingApi } from 'hono/streaming';
|
|
34
34
|
import { DEV } from 'esm-env';
|
|
35
35
|
import { parse } from '@fuzdev/fuz_schema/schema.ts';
|
|
36
36
|
import { utf8_length } from '../actions/transports.js';
|
|
37
37
|
import { OutboundBudget } from './outbound_budget.js';
|
|
38
|
-
import { SSE_CONNECTED_COMMENT, SSE_KEEP_ALIVE_COMMENT, SSE_KEEP_ALIVE_INTERVAL_MS, SSE_OUTBOUND_QUEUE_BYTES, validate_sse_keep_alive_ms } from './sse_constants.js';
|
|
38
|
+
import { SSE_CONNECTED_COMMENT, SSE_KEEP_ALIVE_COMMENT, SSE_KEEP_ALIVE_INTERVAL_MS, SSE_OUTBOUND_QUEUE_BYTES, SSE_RESPONSE_HEADERS, validate_sse_keep_alive_ms } from './sse_constants.js';
|
|
39
39
|
const is_node_connection_stream = (value) => {
|
|
40
40
|
if (typeof value !== 'object' || value === null)
|
|
41
41
|
return false;
|
|
@@ -93,35 +93,37 @@ const watch_client_disconnect = (c, on_gone) => {
|
|
|
93
93
|
signal.addEventListener('abort', on_gone, { once: true });
|
|
94
94
|
};
|
|
95
95
|
/**
|
|
96
|
-
*
|
|
96
|
+
* Open an SSE stream on a request without building its response: the
|
|
97
|
+
* controller and the body, and nothing written on the context. What a route
|
|
98
|
+
* spec's `RouteContext.open_sse` opens with (`create_app_server` hands it to
|
|
99
|
+
* `apply_route_specs`), so the response is built only when the route answers
|
|
100
|
+
* with the stream (`route_sse`), through the context and with
|
|
101
|
+
* `SSE_RESPONSE_HEADERS` — and a route that opens a stream and answers
|
|
102
|
+
* something else answers it with none of the stream's headers.
|
|
97
103
|
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* stream that is already closed, so register cleanup with `on_close` (which
|
|
107
|
-
* runs a late listener at once) before handing the stream anywhere that would
|
|
108
|
-
* count it — `SseRegistry.admit` after `on_close(pending.unsubscribe)`
|
|
109
|
-
* refuses it.
|
|
110
|
-
*
|
|
111
|
-
* Uses `hono_stream.write()` directly (not `writeSSE`) to avoid
|
|
112
|
-
* Hono's HTML callback resolution — keeps the same `data: JSON\n\n` format.
|
|
104
|
+
* The stream exists — `send`, `close`, `on_close` work — from the moment this
|
|
105
|
+
* returns. It stays open until `close()` or its client disconnects, whenever
|
|
106
|
+
* that happens — also before the response is built, which no runtime reports
|
|
107
|
+
* by cancelling a body it has not started to send. A client already gone when
|
|
108
|
+
* this is called yields a stream that is already closed, so register cleanup
|
|
109
|
+
* with `on_close` (which runs a late listener at once) before handing the
|
|
110
|
+
* stream anywhere that would count it — `SseRegistry.admit` after
|
|
111
|
+
* `on_close(pending.unsubscribe)` refuses it.
|
|
113
112
|
*
|
|
113
|
+
* Frames are written with `hono_stream.write()` (not `writeSSE`), avoiding
|
|
114
|
+
* Hono's HTML callback resolution — the `data: JSON\n\n` format as written.
|
|
114
115
|
* What the stream holds unread is bounded by `SSE_OUTBOUND_QUEUE_BYTES`; a
|
|
115
116
|
* frame past it ends the stream (module doc, "Outbound bound").
|
|
116
117
|
*
|
|
118
|
+
* @param c - the request's context, read for its client's disconnect only
|
|
117
119
|
* @param log - logger for serialization and `on_close` listener errors, and
|
|
118
120
|
* for the warning when the stream ends on its outbound budget
|
|
119
121
|
* @param options - what the overflow warning names, and the keep-alive interval
|
|
120
|
-
* @returns
|
|
122
|
+
* @returns the `SseStream` controller and the response body
|
|
121
123
|
* @throws Error when `options.keep_alive_ms` is out of range
|
|
122
124
|
* (`validate_sse_keep_alive_ms`)
|
|
123
125
|
*/
|
|
124
|
-
export const
|
|
126
|
+
export const create_sse_stream = (c, log, options) => {
|
|
125
127
|
validate_sse_keep_alive_ms(options?.keep_alive_ms);
|
|
126
128
|
const { promise, resolve } = Promise.withResolvers();
|
|
127
129
|
const close_listeners = [];
|
|
@@ -145,86 +147,106 @@ export const create_sse_response = (c, log, options) => {
|
|
|
145
147
|
}
|
|
146
148
|
}
|
|
147
149
|
};
|
|
148
|
-
|
|
150
|
+
// the pipe `streamSSE` builds, without its writes on the context
|
|
151
|
+
const { readable, writable } = new TransformStream();
|
|
152
|
+
const hono_stream = new SSEStreamingApi(writable, readable);
|
|
149
153
|
// charges the frames written to the stream and not yet read from it
|
|
150
154
|
const budget = new OutboundBudget(SSE_OUTBOUND_QUEUE_BYTES);
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
155
|
+
// Write one frame within the budget, or end the stream. The write settles
|
|
156
|
+
// once the response body has taken the frame, which frees its charge.
|
|
157
|
+
const write = (frame) => {
|
|
158
|
+
const bytes = utf8_length(frame);
|
|
159
|
+
if (!budget.admit(bytes)) {
|
|
160
|
+
// same line as the Rust spine's registry, so one grep finds either
|
|
161
|
+
log.warn('sse: outbound queue overflow, ending the stream', {
|
|
162
|
+
account_id: options?.account_id ?? null,
|
|
163
|
+
...budget.to_overflow(bytes)
|
|
164
|
+
});
|
|
165
|
+
budget.clear();
|
|
166
|
+
// drops what the stream still holds and ends the body; `do_close`
|
|
167
|
+
// runs as its abort listener
|
|
168
|
+
hono_stream.abort();
|
|
169
|
+
do_close();
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
void hono_stream.write(frame).then(() => {
|
|
173
|
+
// a stream that ended has had its charges cleared
|
|
174
|
+
if (!resolved && !hono_stream.aborted)
|
|
175
|
+
budget.release(bytes);
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
const stream = {
|
|
179
|
+
send(data) {
|
|
180
|
+
if (resolved || hono_stream.aborted)
|
|
168
181
|
return;
|
|
182
|
+
let frame;
|
|
183
|
+
try {
|
|
184
|
+
// JSON.stringify (no space arg) never produces literal newlines,
|
|
185
|
+
// so single-line `data:` framing is safe per the SSE spec.
|
|
186
|
+
frame = `data: ${JSON.stringify(data)}\n\n`;
|
|
169
187
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
log.error('send failed to serialize data:', e);
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
write(frame);
|
|
191
|
-
},
|
|
192
|
-
close: do_close,
|
|
193
|
-
on_close(fn) {
|
|
194
|
-
if (!resolved) {
|
|
195
|
-
close_listeners.push(fn);
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
try {
|
|
199
|
-
fn();
|
|
200
|
-
}
|
|
201
|
-
catch (e) {
|
|
202
|
-
log.error('on_close listener threw:', e);
|
|
203
|
-
}
|
|
188
|
+
catch (e) {
|
|
189
|
+
log.error('send failed to serialize data:', e);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
write(frame);
|
|
193
|
+
},
|
|
194
|
+
close: do_close,
|
|
195
|
+
on_close(fn) {
|
|
196
|
+
if (!resolved) {
|
|
197
|
+
close_listeners.push(fn);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
try {
|
|
201
|
+
fn();
|
|
202
|
+
}
|
|
203
|
+
catch (e) {
|
|
204
|
+
log.error('on_close listener threw:', e);
|
|
204
205
|
}
|
|
205
|
-
};
|
|
206
|
-
hono_stream.onAbort(do_close);
|
|
207
|
-
// flush an SSE comment to push headers through proxies (Vite, nginx),
|
|
208
|
-
// ensuring EventSource fires onopen without waiting for the first data event
|
|
209
|
-
write(SSE_CONNECTED_COMMENT);
|
|
210
|
-
const keep_alive_ms = options?.keep_alive_ms === undefined ? SSE_KEEP_ALIVE_INTERVAL_MS : options.keep_alive_ms;
|
|
211
|
-
// a client that left before this ran has closed the stream already
|
|
212
|
-
if (keep_alive_ms !== null && !resolved) {
|
|
213
|
-
keep_alive_timer = setInterval(() => {
|
|
214
|
-
if (resolved || hono_stream.aborted)
|
|
215
|
-
return;
|
|
216
|
-
write(SSE_KEEP_ALIVE_COMMENT);
|
|
217
|
-
}, keep_alive_ms);
|
|
218
|
-
// a stream left open never holds the process alive on its own
|
|
219
|
-
if (typeof keep_alive_timer === 'object')
|
|
220
|
-
keep_alive_timer.unref?.();
|
|
221
206
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
//
|
|
225
|
-
//
|
|
207
|
+
};
|
|
208
|
+
hono_stream.onAbort(do_close);
|
|
209
|
+
// flush an SSE comment to push headers through proxies (Vite, nginx),
|
|
210
|
+
// ensuring EventSource fires onopen without waiting for the first data event
|
|
211
|
+
write(SSE_CONNECTED_COMMENT);
|
|
212
|
+
const keep_alive_ms = options?.keep_alive_ms === undefined ? SSE_KEEP_ALIVE_INTERVAL_MS : options.keep_alive_ms;
|
|
213
|
+
// a frame past the budget has closed the stream already
|
|
214
|
+
if (keep_alive_ms !== null && !resolved) {
|
|
215
|
+
keep_alive_timer = setInterval(() => {
|
|
216
|
+
if (resolved || hono_stream.aborted)
|
|
217
|
+
return;
|
|
218
|
+
write(SSE_KEEP_ALIVE_COMMENT);
|
|
219
|
+
}, keep_alive_ms);
|
|
220
|
+
// a stream left open never holds the process alive on its own
|
|
221
|
+
if (typeof keep_alive_timer === 'object')
|
|
222
|
+
keep_alive_timer.unref?.();
|
|
223
|
+
}
|
|
224
|
+
// the body ends once the stream closes, as `streamSSE`'s callback ends it
|
|
225
|
+
void promise.then(() => hono_stream.close());
|
|
226
226
|
watch_client_disconnect(c, do_close);
|
|
227
|
-
return {
|
|
227
|
+
return { stream, body: hono_stream.responseReadable };
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* Create an SSE response for a Hono context: `create_sse_stream`, answered at
|
|
231
|
+
* once through the context with `SSE_RESPONSE_HEADERS` — the response
|
|
232
|
+
* Hono's `streamSSE` builds, so it carries the headers the middleware put on
|
|
233
|
+
* the context. For a handler outside the route-spec system; a route spec opens
|
|
234
|
+
* its stream through `RouteContext.open_sse` instead, which builds the
|
|
235
|
+
* response only when the route answers with it.
|
|
236
|
+
*
|
|
237
|
+
* @param log - logger for serialization and `on_close` listener errors, and
|
|
238
|
+
* for the warning when the stream ends on its outbound budget
|
|
239
|
+
* @param options - what the overflow warning names, and the keep-alive interval
|
|
240
|
+
* @returns object with the streaming `Response` and an `SseStream` controller
|
|
241
|
+
* @throws Error when `options.keep_alive_ms` is out of range
|
|
242
|
+
* (`validate_sse_keep_alive_ms`)
|
|
243
|
+
* @mutates `c` - writes `SSE_RESPONSE_HEADERS` on the context's headers
|
|
244
|
+
*/
|
|
245
|
+
export const create_sse_response = (c, log, options) => {
|
|
246
|
+
const { stream, body } = create_sse_stream(c, log, options);
|
|
247
|
+
for (const [name, value] of Object.entries(SSE_RESPONSE_HEADERS))
|
|
248
|
+
c.header(name, value);
|
|
249
|
+
return { response: c.newResponse(body), stream };
|
|
228
250
|
};
|
|
229
251
|
/**
|
|
230
252
|
* Create a broadcaster that validates events in DEV mode.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hono-free SSE wire constants, and the keep-alive interval's check.
|
|
3
3
|
*
|
|
4
|
-
* Split from `sse.ts` (which pulls `hono/streaming`
|
|
4
|
+
* Split from `sse.ts` (which pulls `hono/streaming` for `SSEStreamingApi`) so the
|
|
5
5
|
* stream-framing constants are importable by cross-process test suites
|
|
6
6
|
* asserting on the wire without dragging in the in-process Hono SSE
|
|
7
7
|
* implementation.
|
|
@@ -14,6 +14,12 @@
|
|
|
14
14
|
* SSE tests assert the stream emits this on connect.
|
|
15
15
|
*/
|
|
16
16
|
export declare const SSE_CONNECTED_COMMENT = ": connected\n\n";
|
|
17
|
+
/**
|
|
18
|
+
* The headers an SSE response answers with, in the order Hono's `streamSSE`
|
|
19
|
+
* writes them: chunked framing, the event-stream type, no caching, and a
|
|
20
|
+
* kept-alive connection.
|
|
21
|
+
*/
|
|
22
|
+
export declare const SSE_RESPONSE_HEADERS: Readonly<Record<string, string>>;
|
|
17
23
|
/**
|
|
18
24
|
* The comment line an idle SSE stream writes every
|
|
19
25
|
* `SSE_KEEP_ALIVE_INTERVAL_MS`, so a proxy that cuts a connection idle past
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sse_constants.d.ts","sourceRoot":"","sources":["../../src/lib/realtime/sse_constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,oBAAoB,CAAC;AAEvD;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,oBAAoB,CAAC;AAExD;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,QAAS,CAAC;AAEjD,oFAAoF;AACpF,eAAO,MAAM,8BAA8B,aAAgB,CAAC;AAE5D;;;;;;;;;;GAUG;AACH,eAAO,MAAM,0BAA0B,GAAI,eAAe,MAAM,GAAG,IAAI,GAAG,SAAS,KAAG,IAOrF,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,wBAAwB,QAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"sse_constants.d.ts","sourceRoot":"","sources":["../../src/lib/realtime/sse_constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,oBAAoB,CAAC;AAEvD;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAKhE,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,oBAAoB,CAAC;AAExD;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,QAAS,CAAC;AAEjD,oFAAoF;AACpF,eAAO,MAAM,8BAA8B,aAAgB,CAAC;AAE5D;;;;;;;;;;GAUG;AACH,eAAO,MAAM,0BAA0B,GAAI,eAAe,MAAM,GAAG,IAAI,GAAG,SAAS,KAAG,IAOrF,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,wBAAwB,QAAc,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hono-free SSE wire constants, and the keep-alive interval's check.
|
|
3
3
|
*
|
|
4
|
-
* Split from `sse.ts` (which pulls `hono/streaming`
|
|
4
|
+
* Split from `sse.ts` (which pulls `hono/streaming` for `SSEStreamingApi`) so the
|
|
5
5
|
* stream-framing constants are importable by cross-process test suites
|
|
6
6
|
* asserting on the wire without dragging in the in-process Hono SSE
|
|
7
7
|
* implementation.
|
|
@@ -14,6 +14,17 @@
|
|
|
14
14
|
* SSE tests assert the stream emits this on connect.
|
|
15
15
|
*/
|
|
16
16
|
export const SSE_CONNECTED_COMMENT = `: connected\n\n`;
|
|
17
|
+
/**
|
|
18
|
+
* The headers an SSE response answers with, in the order Hono's `streamSSE`
|
|
19
|
+
* writes them: chunked framing, the event-stream type, no caching, and a
|
|
20
|
+
* kept-alive connection.
|
|
21
|
+
*/
|
|
22
|
+
export const SSE_RESPONSE_HEADERS = Object.freeze({
|
|
23
|
+
'Transfer-Encoding': 'chunked',
|
|
24
|
+
'Content-Type': 'text/event-stream',
|
|
25
|
+
'Cache-Control': 'no-cache',
|
|
26
|
+
Connection: 'keep-alive'
|
|
27
|
+
});
|
|
17
28
|
/**
|
|
18
29
|
* The comment line an idle SSE stream writes every
|
|
19
30
|
* `SSE_KEEP_ALIVE_INTERVAL_MS`, so a proxy that cuts a connection idle past
|