@fuzdev/fuz_app 0.180.0 → 0.182.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 +38 -20
- package/dist/actions/action_rpc.d.ts +25 -6
- package/dist/actions/action_rpc.d.ts.map +1 -1
- package/dist/actions/action_rpc.js +56 -48
- package/dist/actions/action_types.d.ts +31 -13
- package/dist/actions/action_types.d.ts.map +1 -1
- package/dist/actions/action_types.js +1 -1
- package/dist/actions/notification_sender.d.ts +83 -0
- package/dist/actions/notification_sender.d.ts.map +1 -0
- package/dist/actions/notification_sender.js +85 -0
- package/dist/actions/perform_action.d.ts +13 -4
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +27 -18
- package/dist/actions/register_action_ws.d.ts +20 -2
- package/dist/actions/register_action_ws.d.ts.map +1 -1
- package/dist/actions/register_action_ws.js +17 -5
- package/dist/actions/ws_socket_session.d.ts +3 -0
- package/dist/actions/ws_socket_session.d.ts.map +1 -1
- package/dist/actions/ws_socket_session.js +3 -2
- package/dist/auth/CLAUDE.md +84 -59
- package/dist/auth/account_actions.d.ts.map +1 -1
- package/dist/auth/account_actions.js +30 -3
- package/dist/auth/account_queries.d.ts +213 -2
- package/dist/auth/account_queries.d.ts.map +1 -1
- package/dist/auth/account_queries.js +255 -2
- 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 +5 -7
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +110 -89
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +117 -25
- package/dist/auth/api_token_queries.d.ts +29 -12
- package/dist/auth/api_token_queries.d.ts.map +1 -1
- package/dist/auth/api_token_queries.js +42 -27
- 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 +37 -32
- 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 +39 -30
- package/dist/auth/deps.d.ts +10 -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 +97 -76
- package/dist/auth/request_context.d.ts.map +1 -1
- package/dist/auth/request_context.js +93 -104
- package/dist/auth/resolved_auth.d.ts +10 -5
- package/dist/auth/resolved_auth.d.ts.map +1 -1
- package/dist/auth/resolved_auth.js +2 -2
- package/dist/auth/role_grant_offer_action_specs.d.ts +2 -2
- package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_action_specs.js +5 -3
- package/dist/auth/role_grant_offer_actions.d.ts +7 -11
- package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_actions.js +97 -106
- 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_notifications.d.ts +87 -38
- package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_notifications.js +75 -22
- package/dist/auth/role_grant_offer_queries.d.ts +143 -9
- package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_queries.js +266 -66
- package/dist/auth/role_grant_offer_schema.js +1 -1
- package/dist/auth/role_grant_queries.d.ts +57 -10
- package/dist/auth/role_grant_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_queries.js +81 -22
- package/dist/auth/role_grant_sql.d.ts +21 -0
- package/dist/auth/role_grant_sql.d.ts.map +1 -1
- package/dist/auth/role_grant_sql.js +21 -0
- package/dist/auth/self_service_role_actions.d.ts.map +1 -1
- package/dist/auth/self_service_role_actions.js +9 -2
- 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 +95 -14
- package/dist/auth/session_queries.d.ts.map +1 -1
- package/dist/auth/session_queries.js +98 -19
- 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/standard_rpc_actions.d.ts +6 -19
- package/dist/auth/standard_rpc_actions.d.ts.map +1 -1
- package/dist/auth/standard_rpc_actions.js +5 -6
- package/dist/auth/token_scope.d.ts +6 -8
- package/dist/auth/token_scope.d.ts.map +1 -1
- package/dist/auth/token_scope.js +6 -9
- 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 +156 -48
- package/dist/http/auth_shape.d.ts +4 -4
- 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 +45 -22
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/error_schemas.js +53 -26
- 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 +299 -83
- 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 +4 -4
- package/dist/server/app_server.d.ts +54 -33
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +69 -41
- package/dist/server/serve_fact_route.d.ts +3 -3
- package/dist/server/serve_fact_route.d.ts.map +1 -1
- package/dist/server/serve_fact_route.js +59 -55
- 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 +406 -1202
- 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 +5 -9
- package/dist/testing/auth_apps.d.ts.map +1 -1
- package/dist/testing/auth_apps.js +3 -2
- 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 +320 -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.d.ts +1 -26
- package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_spine_surface.js +3 -7
- 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 +4 -10
- package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
- package/dist/testing/cross_backend/full_spine_mount.js +11 -4
- 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 +5 -4
- 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 +185 -31
- 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 +82 -34
- 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 +3 -1
- package/dist/testing/middleware.d.ts.map +1 -1
- package/dist/testing/middleware.js +14 -7
- package/dist/testing/resolved_auth.d.ts +3 -1
- package/dist/testing/resolved_auth.d.ts.map +1 -1
- package/dist/testing/resolved_auth.js +4 -4
- 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 +13 -10
- 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/dist/testing/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/ws_round_trip.js +8 -4
- package/package.json +1 -1
package/dist/testing/stubs.js
CHANGED
|
@@ -12,6 +12,7 @@ import { REST_FORBIDDEN_ORIGIN } from '../http/error_schemas.js';
|
|
|
12
12
|
import { body_limit_middleware_shape } from '../http/body_limit_schema.js';
|
|
13
13
|
import { host_gate_middleware_shape } from '../http/host.js';
|
|
14
14
|
import { create_realtime_closer } from '../actions/connection_closer.js';
|
|
15
|
+
import { create_realtime_notification_sender } from '../actions/notification_sender.js';
|
|
15
16
|
import { Db } from '../db/db.js';
|
|
16
17
|
import { attach_route_handler, prefix_route_specs } from '../http/route_spec.js';
|
|
17
18
|
import { route_raw } from '../http/route_result.js';
|
|
@@ -93,7 +94,7 @@ export const create_stub_db = () => new Db({
|
|
|
93
94
|
transaction: async (fn) => fn(create_stub_db())
|
|
94
95
|
});
|
|
95
96
|
/** Stub handler that answers a 200 `stub` text response, as a raw result. */
|
|
96
|
-
export const stub_handler = () => route_raw(
|
|
97
|
+
export const stub_handler = () => route_raw({ status: 200, headers: { 'Content-Type': 'text/plain;charset=UTF-8' }, body: 'stub' });
|
|
97
98
|
/**
|
|
98
99
|
* A route spec for a surface that is described and never served — a
|
|
99
100
|
* backend's routes declared from their shapes: `shape` with a handler that
|
|
@@ -161,16 +162,17 @@ export const create_stub_audit_sse = () => {
|
|
|
161
162
|
* Create no-op `AppDeps` for auth surface testing.
|
|
162
163
|
*/
|
|
163
164
|
export const create_stub_app_deps = () => ({
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
165
|
+
// `sign` answers a string, as a keyring does: `create_app_server` mints a
|
|
166
|
+
// sample session cookie at assembly and refuses a value that is none
|
|
167
|
+
keyring: create_noop_stub('keyring', {
|
|
168
|
+
sign: async (value) => `${value}.stub_signature`
|
|
169
|
+
}),
|
|
169
170
|
password: create_noop_stub('password'),
|
|
170
171
|
db: stub_db,
|
|
171
172
|
log: new Logger('test', { level: 'off' }),
|
|
172
173
|
audit: create_test_audit_emitter(),
|
|
173
|
-
connection_closer: create_realtime_closer()
|
|
174
|
+
connection_closer: create_realtime_closer(),
|
|
175
|
+
notification_sender: create_realtime_notification_sender()
|
|
174
176
|
});
|
|
175
177
|
/**
|
|
176
178
|
* Create a stub `AppBackend` with no database behind it — no migration
|
|
@@ -242,7 +244,7 @@ export const create_stub_app_server_context = (session_options) => {
|
|
|
242
244
|
return {
|
|
243
245
|
deps: backend.deps,
|
|
244
246
|
backend,
|
|
245
|
-
bootstrap_status: { available: false
|
|
247
|
+
bootstrap_status: { available: false },
|
|
246
248
|
session_options,
|
|
247
249
|
login_ip_rate_limiter: null,
|
|
248
250
|
signup_ip_rate_limiter: null,
|
|
@@ -319,7 +321,8 @@ export const create_test_app_surface_spec = (options) => {
|
|
|
319
321
|
actions: endpoint.actions,
|
|
320
322
|
log: ctx.deps.log,
|
|
321
323
|
action_ip_rate_limiter: ctx.action_ip_rate_limiter,
|
|
322
|
-
action_account_rate_limiter: ctx.action_account_rate_limiter
|
|
324
|
+
action_account_rate_limiter: ctx.action_account_rate_limiter,
|
|
325
|
+
notification_sender: ctx.deps.notification_sender
|
|
323
326
|
});
|
|
324
327
|
}) ?? [];
|
|
325
328
|
// Resolve ws endpoints (mirrors create_app_server). Surface-only —
|
|
@@ -337,7 +340,7 @@ export const create_test_app_surface_spec = (options) => {
|
|
|
337
340
|
// and `live` modes; omitted for `disabled` / undefined. Surface generation
|
|
338
341
|
// uses an `available: false` placeholder regardless of mode — the handler
|
|
339
342
|
// short-circuits to 403 ALREADY_BOOTSTRAPPED, which is what surface tests
|
|
340
|
-
// assert on.
|
|
343
|
+
// assert on. A live token store is passed through for shape symmetry only.
|
|
341
344
|
const bootstrap_route_specs = options.bootstrap && options.bootstrap.mode !== 'disabled'
|
|
342
345
|
? prefix_route_specs(options.bootstrap.route_prefix ?? '/api/account', [
|
|
343
346
|
// Surface generation reads the route shape only — the live hono
|
|
@@ -18,7 +18,10 @@ import '../assert_dev_env.js';
|
|
|
18
18
|
* The cookie jar is intentionally simple — it does not honour `Domain`,
|
|
19
19
|
* `Path`, `Expires`, or `SameSite` attributes. Cross-process tests
|
|
20
20
|
* always hit a single host:port, so name-keyed last-write-wins matches
|
|
21
|
-
* the behaviour real browsers exhibit against the same surface.
|
|
21
|
+
* the behaviour real browsers exhibit against the same surface. It does
|
|
22
|
+
* honour a `Max-Age` of zero or less, dropping the cookie as a browser does:
|
|
23
|
+
* a cleared session cookie kept as `name=` would be re-sent as an invalid
|
|
24
|
+
* cookie, which both spines answer by clearing it again.
|
|
22
25
|
*
|
|
23
26
|
* @module
|
|
24
27
|
*/
|
|
@@ -64,8 +67,8 @@ export interface FetchTransport extends RpcTestTransport {
|
|
|
64
67
|
/**
|
|
65
68
|
* Build a cookie-threading transport pinned to `options.base_url`. The
|
|
66
69
|
* returned function carries a private `Map<name, cookie-head>` jar that
|
|
67
|
-
* updates on every response's `Set-Cookie`
|
|
68
|
-
* subsequent request.
|
|
70
|
+
* updates on every response's `Set-Cookie` (a `Max-Age<=0` one deletes its
|
|
71
|
+
* cookie) and re-sends on every subsequent request.
|
|
69
72
|
*
|
|
70
73
|
* Request rewriting:
|
|
71
74
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch_transport.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/transports/fetch_transport.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAE9B
|
|
1
|
+
{"version":3,"file":"fetch_transport.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/transports/fetch_transport.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,yDAAyD;AACzD,MAAM,WAAW,qBAAqB;IACrC,0EAA0E;IAC1E,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B;;;;;OAKG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACjD;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAe,SAAQ,gBAAgB;IACvD;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,aAAa,CAAC,MAAM,CAAC,CAAC;CAC9C;AAsCD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,sBAAsB,GAAI,SAAS,qBAAqB,KAAG,cAmCvE,CAAC"}
|
|
@@ -1,26 +1,44 @@
|
|
|
1
1
|
import '../assert_dev_env.js';
|
|
2
2
|
/**
|
|
3
|
-
* Parse
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* don't affect cross-process test
|
|
3
|
+
* Parse a `Set-Cookie` value: its `name=value` head, and whether it deletes
|
|
4
|
+
* the cookie — a `Max-Age` of zero or less, which is how both spines clear
|
|
5
|
+
* the session cookie. Returns `null` for malformed inputs (missing `=`, empty
|
|
6
|
+
* name). Every other attribute is dropped — the jar is name-keyed, and
|
|
7
|
+
* `Expires`, `Path`, `Domain` and `SameSite` don't affect cross-process test
|
|
8
|
+
* plumbing.
|
|
8
9
|
*/
|
|
9
10
|
const parse_set_cookie = (value) => {
|
|
10
|
-
const
|
|
11
|
+
const [head_part, ...attributes] = value.split(';');
|
|
12
|
+
const head = head_part.trim();
|
|
11
13
|
const eq = head.indexOf('=');
|
|
12
14
|
if (eq <= 0)
|
|
13
15
|
return null;
|
|
14
16
|
const name = head.slice(0, eq).trim();
|
|
15
17
|
if (!name)
|
|
16
18
|
return null;
|
|
17
|
-
|
|
19
|
+
const deleted = attributes.some((attribute) => {
|
|
20
|
+
const [attribute_name, attribute_value] = attribute.split('=', 2);
|
|
21
|
+
return (attribute_name.trim().toLowerCase() === 'max-age' &&
|
|
22
|
+
/^-?\d+$/.test(attribute_value?.trim() ?? '') &&
|
|
23
|
+
Number(attribute_value) <= 0);
|
|
24
|
+
});
|
|
25
|
+
return { name, cookie: head, deleted };
|
|
26
|
+
};
|
|
27
|
+
/** Apply one `Set-Cookie` value to a jar, as a browser does: set, or delete on `Max-Age<=0`. */
|
|
28
|
+
const apply_set_cookie = (jar, raw) => {
|
|
29
|
+
const parsed = parse_set_cookie(raw);
|
|
30
|
+
if (!parsed)
|
|
31
|
+
return;
|
|
32
|
+
if (parsed.deleted)
|
|
33
|
+
jar.delete(parsed.name);
|
|
34
|
+
else
|
|
35
|
+
jar.set(parsed.name, parsed.cookie);
|
|
18
36
|
};
|
|
19
37
|
/**
|
|
20
38
|
* Build a cookie-threading transport pinned to `options.base_url`. The
|
|
21
39
|
* returned function carries a private `Map<name, cookie-head>` jar that
|
|
22
|
-
* updates on every response's `Set-Cookie`
|
|
23
|
-
* subsequent request.
|
|
40
|
+
* updates on every response's `Set-Cookie` (a `Max-Age<=0` one deletes its
|
|
41
|
+
* cookie) and re-sends on every subsequent request.
|
|
24
42
|
*
|
|
25
43
|
* Request rewriting:
|
|
26
44
|
*
|
|
@@ -36,11 +54,8 @@ export const create_fetch_transport = (options) => {
|
|
|
36
54
|
const { base_url, initial_cookies, origin } = options;
|
|
37
55
|
const jar = new Map();
|
|
38
56
|
if (initial_cookies) {
|
|
39
|
-
for (const raw of initial_cookies)
|
|
40
|
-
|
|
41
|
-
if (parsed)
|
|
42
|
-
jar.set(parsed.name, parsed.cookie);
|
|
43
|
-
}
|
|
57
|
+
for (const raw of initial_cookies)
|
|
58
|
+
apply_set_cookie(jar, raw);
|
|
44
59
|
}
|
|
45
60
|
const default_origin = origin === null ? null : (origin ?? base_url);
|
|
46
61
|
const cookies = () => Array.from(jar.values());
|
|
@@ -59,11 +74,8 @@ export const create_fetch_transport = (options) => {
|
|
|
59
74
|
// one response (Headers.get() collapses to a single comma-joined
|
|
60
75
|
// string). Node 19.7+ ships it; vitest's runtime supports it.
|
|
61
76
|
const set_cookies = response.headers.getSetCookie();
|
|
62
|
-
for (const raw of set_cookies)
|
|
63
|
-
|
|
64
|
-
if (parsed)
|
|
65
|
-
jar.set(parsed.name, parsed.cookie);
|
|
66
|
-
}
|
|
77
|
+
for (const raw of set_cookies)
|
|
78
|
+
apply_set_cookie(jar, raw);
|
|
67
79
|
return response;
|
|
68
80
|
});
|
|
69
81
|
// Attach the cookies() accessor onto the callable. Using a property
|
|
@@ -60,6 +60,52 @@ export interface RawHttpResponse {
|
|
|
60
60
|
* @param request_bytes - the bytes to send, `latin1`-encoded
|
|
61
61
|
*/
|
|
62
62
|
export declare const raw_http_exchange: (base_url: string, request_bytes: string, options: RawHttpExchangeOptions) => Promise<RawHttpExchange>;
|
|
63
|
+
/** One request for `raw_http_request`: its request line, header lines, and body. */
|
|
64
|
+
export interface RawHttpRequest {
|
|
65
|
+
/** The request method. */
|
|
66
|
+
readonly method: string;
|
|
67
|
+
/** Request target, e.g. `/api/rpc`. */
|
|
68
|
+
readonly path: string;
|
|
69
|
+
/**
|
|
70
|
+
* The `Host` to send — a base URL's `host` — or `null` to write no `Host`
|
|
71
|
+
* line of its own, for a request whose `header_lines` carry the `Host`
|
|
72
|
+
* lines it means to send.
|
|
73
|
+
*/
|
|
74
|
+
readonly host: string | null;
|
|
75
|
+
/**
|
|
76
|
+
* The header lines after `Host`, each `Name: value`, written in order and
|
|
77
|
+
* as given — a name may repeat, which is what `fetch` cannot send. Nothing
|
|
78
|
+
* is defaulted: no `Origin`, no `Connection`, no credential.
|
|
79
|
+
*/
|
|
80
|
+
readonly header_lines: ReadonlyArray<string>;
|
|
81
|
+
/**
|
|
82
|
+
* The body, `latin1` (one character a byte). When given, `Content-Length`
|
|
83
|
+
* is written after the header lines.
|
|
84
|
+
*/
|
|
85
|
+
readonly body?: string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Frame an HTTP/1.1 request from its header lines: the request line, `Host`
|
|
89
|
+
* (unless `host` is `null`), each line of `header_lines`, `Content-Length` when there is a body, the
|
|
90
|
+
* blank line, the body.
|
|
91
|
+
*
|
|
92
|
+
* The lines go out as written. A CR or LF inside one ends it early, so a
|
|
93
|
+
* caller that puts one there means to split the line.
|
|
94
|
+
*
|
|
95
|
+
* @param request - the method, target, host, header lines and body
|
|
96
|
+
* @returns the request's bytes, for `raw_http_exchange`
|
|
97
|
+
*/
|
|
98
|
+
export declare const raw_http_request: (request: RawHttpRequest) => string;
|
|
99
|
+
/**
|
|
100
|
+
* Every value of one header in the first response of a raw byte stream, in
|
|
101
|
+
* the order the server wrote them — `raw_http_parse_response` keeps only the
|
|
102
|
+
* last, which loses all but one `Set-Cookie`.
|
|
103
|
+
*
|
|
104
|
+
* @param raw - the bytes read so far, `latin1`-decoded
|
|
105
|
+
* @param name - the header name, in any case
|
|
106
|
+
* @returns the header's values, outer whitespace stripped; `[]` when the head is incomplete or carries none
|
|
107
|
+
*/
|
|
108
|
+
export declare const raw_http_header_values: (raw: string, name: string) => Array<string>;
|
|
63
109
|
/** One head-only request for `raw_http_send_head`: where it goes and what it declares. */
|
|
64
110
|
export interface RawHttpHeadRequest {
|
|
65
111
|
/**
|
|
@@ -136,6 +182,13 @@ export declare const raw_http_header_lines: (headers: Record<string, string>) =>
|
|
|
136
182
|
* @returns the parsed value, or `undefined` when the body is not JSON
|
|
137
183
|
*/
|
|
138
184
|
export declare const raw_http_parse_json: (body: string) => unknown;
|
|
185
|
+
/**
|
|
186
|
+
* The REST error code of a response body — its `error` member — or `null`
|
|
187
|
+
* for a body that names none (not JSON, no `error` string).
|
|
188
|
+
*
|
|
189
|
+
* @param response - the parsed response
|
|
190
|
+
*/
|
|
191
|
+
export declare const raw_http_error_code: (response: RawHttpResponse) => string | null;
|
|
139
192
|
/**
|
|
140
193
|
* Count HTTP response status lines in a raw byte stream. Deliberately
|
|
141
194
|
* **unanchored** (no `^`/`m`): a second pipelined response is concatenated
|
|
@@ -154,8 +207,15 @@ export declare const raw_http_first_status: (raw: string) => number | null;
|
|
|
154
207
|
* A response carrying neither is delimited by the connection closing, which
|
|
155
208
|
* the bytes alone don't show, so its body is whatever followed the head.
|
|
156
209
|
*
|
|
210
|
+
* The answer to a `HEAD` has no body whatever its framing headers say
|
|
211
|
+
* (RFC 9110 §9.3.2): with `head_request` its body is whatever followed the
|
|
212
|
+
* head, which a conforming server leaves empty.
|
|
213
|
+
*
|
|
157
214
|
* @param raw - the bytes read so far, `latin1`-decoded
|
|
215
|
+
* @param options - `head_request`: the request was a `HEAD`
|
|
158
216
|
* @returns the response, or `null` when the head or the framed body is incomplete
|
|
159
217
|
*/
|
|
160
|
-
export declare const raw_http_parse_response: (raw: string
|
|
218
|
+
export declare const raw_http_parse_response: (raw: string, options?: {
|
|
219
|
+
readonly head_request?: boolean;
|
|
220
|
+
}) => RawHttpResponse | null;
|
|
161
221
|
//# sourceMappingURL=raw_http.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"raw_http.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/transports/raw_http.ts"],"names":[],"mappings":"AAAA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on a mid-write close is expected
|
|
67
67
|
socket.on('close', () => finish(true));
|
|
68
68
|
});
|
|
69
|
+
/**
|
|
70
|
+
* Frame an HTTP/1.1 request from its header lines: the request line, `Host`
|
|
71
|
+
* (unless `host` is `null`), each line of `header_lines`, `Content-Length` when there is a body, the
|
|
72
|
+
* blank line, the body.
|
|
73
|
+
*
|
|
74
|
+
* The lines go out as written. A CR or LF inside one ends it early, so a
|
|
75
|
+
* caller that puts one there means to split the line.
|
|
76
|
+
*
|
|
77
|
+
* @param request - the method, target, host, header lines and body
|
|
78
|
+
* @returns the request's bytes, for `raw_http_exchange`
|
|
79
|
+
*/
|
|
80
|
+
export const raw_http_request = (request) => {
|
|
81
|
+
const { method, path, host, header_lines, body } = request;
|
|
82
|
+
return (`${method} ${path} HTTP/1.1\r\n` +
|
|
83
|
+
(host === null ? '' : `Host: ${host}\r\n`) +
|
|
84
|
+
header_lines.map((line) => `${line}\r\n`).join('') +
|
|
85
|
+
(body === undefined ? '' : `Content-Length: ${body.length}\r\n`) +
|
|
86
|
+
'\r\n' +
|
|
87
|
+
(body ?? ''));
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Every value of one header in the first response of a raw byte stream, in
|
|
91
|
+
* the order the server wrote them — `raw_http_parse_response` keeps only the
|
|
92
|
+
* last, which loses all but one `Set-Cookie`.
|
|
93
|
+
*
|
|
94
|
+
* @param raw - the bytes read so far, `latin1`-decoded
|
|
95
|
+
* @param name - the header name, in any case
|
|
96
|
+
* @returns the header's values, outer whitespace stripped; `[]` when the head is incomplete or carries none
|
|
97
|
+
*/
|
|
98
|
+
export const raw_http_header_values = (raw, name) => {
|
|
99
|
+
const head_end = raw.indexOf('\r\n\r\n');
|
|
100
|
+
if (head_end === -1)
|
|
101
|
+
return [];
|
|
102
|
+
const lower_name = name.toLowerCase();
|
|
103
|
+
const values = [];
|
|
104
|
+
for (const line of raw.slice(0, head_end).split('\r\n').slice(1)) {
|
|
105
|
+
const colon = line.indexOf(':');
|
|
106
|
+
if (colon > 0 && line.slice(0, colon).trim().toLowerCase() === lower_name) {
|
|
107
|
+
values.push(line.slice(colon + 1).trim());
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return values;
|
|
111
|
+
};
|
|
69
112
|
/** Lowercased names of the headers `raw_http_send_head` writes itself. */
|
|
70
113
|
const SEND_HEAD_WRITTEN_HEADERS = ['host', 'content-length'];
|
|
71
114
|
/**
|
|
@@ -153,6 +196,16 @@ export const raw_http_parse_json = (body) => {
|
|
|
153
196
|
return undefined;
|
|
154
197
|
}
|
|
155
198
|
};
|
|
199
|
+
/**
|
|
200
|
+
* The REST error code of a response body — its `error` member — or `null`
|
|
201
|
+
* for a body that names none (not JSON, no `error` string).
|
|
202
|
+
*
|
|
203
|
+
* @param response - the parsed response
|
|
204
|
+
*/
|
|
205
|
+
export const raw_http_error_code = (response) => {
|
|
206
|
+
const body = raw_http_parse_json(response.body);
|
|
207
|
+
return typeof body?.error === 'string' ? body.error : null;
|
|
208
|
+
};
|
|
156
209
|
/**
|
|
157
210
|
* Count HTTP response status lines in a raw byte stream. Deliberately
|
|
158
211
|
* **unanchored** (no `^`/`m`): a second pipelined response is concatenated
|
|
@@ -200,10 +253,15 @@ const decode_chunked = (raw) => {
|
|
|
200
253
|
* A response carrying neither is delimited by the connection closing, which
|
|
201
254
|
* the bytes alone don't show, so its body is whatever followed the head.
|
|
202
255
|
*
|
|
256
|
+
* The answer to a `HEAD` has no body whatever its framing headers say
|
|
257
|
+
* (RFC 9110 §9.3.2): with `head_request` its body is whatever followed the
|
|
258
|
+
* head, which a conforming server leaves empty.
|
|
259
|
+
*
|
|
203
260
|
* @param raw - the bytes read so far, `latin1`-decoded
|
|
261
|
+
* @param options - `head_request`: the request was a `HEAD`
|
|
204
262
|
* @returns the response, or `null` when the head or the framed body is incomplete
|
|
205
263
|
*/
|
|
206
|
-
export const raw_http_parse_response = (raw) => {
|
|
264
|
+
export const raw_http_parse_response = (raw, options) => {
|
|
207
265
|
const head_end = raw.indexOf('\r\n\r\n');
|
|
208
266
|
if (head_end === -1)
|
|
209
267
|
return null;
|
|
@@ -220,6 +278,8 @@ export const raw_http_parse_response = (raw) => {
|
|
|
220
278
|
}
|
|
221
279
|
const status = Number(status_match[1]);
|
|
222
280
|
const rest = raw.slice(head_end + 4);
|
|
281
|
+
if (options?.head_request)
|
|
282
|
+
return { status, headers, body: rest };
|
|
223
283
|
if (headers['transfer-encoding']?.toLowerCase().includes('chunked')) {
|
|
224
284
|
const body = decode_chunked(rest);
|
|
225
285
|
return body === null ? null : { status, headers, body };
|
|
@@ -18,6 +18,12 @@ export interface RawWsFrame {
|
|
|
18
18
|
}
|
|
19
19
|
/** A WebSocket client that sends frames and never answers a close. */
|
|
20
20
|
export interface RawWsClient {
|
|
21
|
+
/**
|
|
22
|
+
* The server's `101` response head as it arrived, `latin1`-decoded, through
|
|
23
|
+
* its closing blank line — for reading the headers an accepted upgrade
|
|
24
|
+
* carries (`raw_http_header_values`).
|
|
25
|
+
*/
|
|
26
|
+
handshake: string;
|
|
21
27
|
/** Every frame the server sent, in order. */
|
|
22
28
|
frames: Array<RawWsFrame>;
|
|
23
29
|
/** Send one masked text frame. */
|
|
@@ -34,8 +40,22 @@ export interface RawWsConnectOptions {
|
|
|
34
40
|
hostname?: string;
|
|
35
41
|
/** The WebSocket endpoint path (e.g. `/api/ws`). */
|
|
36
42
|
path: string;
|
|
43
|
+
/**
|
|
44
|
+
* The `Host` line's value, or `null` to write none — for an upgrade whose
|
|
45
|
+
* `header_lines` carry the `Host` lines it means to send.
|
|
46
|
+
*
|
|
47
|
+
* @default `${hostname}:${port}`
|
|
48
|
+
*/
|
|
49
|
+
host?: string | null;
|
|
37
50
|
/** Extra upgrade request headers — `Cookie`, `Origin`. */
|
|
38
51
|
headers?: Record<string, string>;
|
|
52
|
+
/**
|
|
53
|
+
* Header lines written after `headers`, each `Name: value`, in order and as
|
|
54
|
+
* given, `latin1` (one character a byte) — a name may repeat, and a byte
|
|
55
|
+
* above `0x7F` goes out as itself. For an upgrade whose credential lines
|
|
56
|
+
* must reach the server exactly as a test spells them.
|
|
57
|
+
*/
|
|
58
|
+
header_lines?: ReadonlyArray<string>;
|
|
39
59
|
/**
|
|
40
60
|
* Text frames to write in the **same TCP write** as the upgrade request, so
|
|
41
61
|
* they are in the server's hands before the handshake is answered — and so
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws_raw_client.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/transports/ws_raw_client.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAuB9B,uCAAuC;AACvC,eAAO,MAAM,kBAAkB,IAAM,CAAC;AACtC,wCAAwC;AACxC,eAAO,MAAM,mBAAmB,IAAM,CAAC;AAEvC;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAKnE,CAAC;AAEF,iCAAiC;AACjC,MAAM,WAAW,UAAU;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,sEAAsE;AACtE,MAAM,WAAW,WAAW;IAC3B,6CAA6C;IAC7C,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IAC1B,kCAAkC;IAClC,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,oFAAoF;IACpF,QAAQ,EAAE,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,OAAO,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IAClG,wDAAwD;IACxD,OAAO,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,oCAAoC;AACpC,MAAM,WAAW,mBAAmB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,IAAI,EAAE,M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AAU,CAAC,CAAC;IAClG,wDAAwD;IACxD,OAAO,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,oCAAoC;AACpC,MAAM,WAAW,mBAAmB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC;;;;;OAKG;IACH,YAAY,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACrC;;;;OAIG;IACH,SAAS,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CAClC;AAED,wCAAwC;AACxC,eAAO,MAAM,eAAe,GAAI,OAAO,UAAU,KAAG,OAA+C,CAAC;AAEpG,4EAA4E;AAC5E,eAAO,MAAM,iBAAiB,GAAI,OAAO,UAAU,KAAG,MAAM,GAAG,IACE,CAAC;AAwClE;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,mBAAmB,KAAG,OAAO,CAAC,WAAW,CAkG9E,CAAC"}
|
|
@@ -89,13 +89,14 @@ const take_frames = (buffer) => {
|
|
|
89
89
|
* @throws Error when the upgrade is refused or the connection fails
|
|
90
90
|
*/
|
|
91
91
|
export const connect_raw_ws = (options) => new Promise((resolve, reject) => {
|
|
92
|
-
const { port, hostname = '127.0.0.1', path, headers = {}, pipelined = [] } = options;
|
|
92
|
+
const { port, hostname = '127.0.0.1', path, host = `${hostname}:${port}`, headers = {}, header_lines = [], pipelined = [] } = options;
|
|
93
93
|
const socket = connect(port, hostname);
|
|
94
94
|
const frames = [];
|
|
95
95
|
const waiters = [];
|
|
96
96
|
let buffer = Buffer.alloc(0);
|
|
97
97
|
let upgraded = false;
|
|
98
98
|
const client = {
|
|
99
|
+
handshake: '',
|
|
99
100
|
frames,
|
|
100
101
|
send_text: (text) => {
|
|
101
102
|
socket.write(encode_client_text(text));
|
|
@@ -125,17 +126,21 @@ export const connect_raw_ws = (options) => new Promise((resolve, reject) => {
|
|
|
125
126
|
socket.on('connect', () => {
|
|
126
127
|
const request = [
|
|
127
128
|
`GET ${path} HTTP/1.1`,
|
|
128
|
-
`Host: ${
|
|
129
|
+
...(host === null ? [] : [`Host: ${host}`]),
|
|
129
130
|
'Upgrade: websocket',
|
|
130
131
|
'Connection: Upgrade',
|
|
131
132
|
`Sec-WebSocket-Key: ${randomBytes(16).toString('base64')}`,
|
|
132
133
|
'Sec-WebSocket-Version: 13',
|
|
133
134
|
...Object.entries(headers).map(([name, value]) => `${name}: ${value}`),
|
|
134
|
-
'',
|
|
135
135
|
''
|
|
136
136
|
].join('\r\n');
|
|
137
|
+
const raw_lines = header_lines.map((line) => `${line}\r\n`).join('') + '\r\n';
|
|
137
138
|
// one write, so the pipelined frames can't trail the handshake
|
|
138
|
-
socket.write(Buffer.concat([
|
|
139
|
+
socket.write(Buffer.concat([
|
|
140
|
+
Buffer.from(request, 'utf-8'),
|
|
141
|
+
Buffer.from(raw_lines, 'latin1'),
|
|
142
|
+
...pipelined.map(encode_client_text)
|
|
143
|
+
]));
|
|
139
144
|
});
|
|
140
145
|
socket.on('data', (chunk) => {
|
|
141
146
|
buffer = Buffer.concat([buffer, chunk]);
|
|
@@ -150,6 +155,7 @@ export const connect_raw_ws = (options) => new Promise((resolve, reject) => {
|
|
|
150
155
|
return;
|
|
151
156
|
}
|
|
152
157
|
upgraded = true;
|
|
158
|
+
client.handshake = buffer.subarray(0, end + 4).toString('latin1');
|
|
153
159
|
buffer = buffer.subarray(end + 4);
|
|
154
160
|
resolve(client);
|
|
155
161
|
}
|
|
@@ -13,6 +13,24 @@ export interface WsTransportClient extends WsClient {
|
|
|
13
13
|
*/
|
|
14
14
|
send_text: (text: string) => Promise<void>;
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* How long a refused upgrade's body may take to arrive before the transport
|
|
18
|
+
* closes the connection and rejects with what came — a refusal whose body
|
|
19
|
+
* never ends would otherwise leave the open pending forever.
|
|
20
|
+
*/
|
|
21
|
+
export declare const WS_REFUSAL_BODY_TIMEOUT_MS = 1000;
|
|
22
|
+
/**
|
|
23
|
+
* A WebSocket upgrade the server answered with an HTTP response instead of
|
|
24
|
+
* `101` — the refusal's status and body, so a test can tell an origin refusal
|
|
25
|
+
* (403) from a missing credential (401) instead of accepting any failure.
|
|
26
|
+
*/
|
|
27
|
+
export declare class WsUpgradeRefusedError extends Error {
|
|
28
|
+
/** The refusal's HTTP status. */
|
|
29
|
+
readonly status: number;
|
|
30
|
+
/** The refusal's body as text (empty when it had none). */
|
|
31
|
+
readonly body: string;
|
|
32
|
+
constructor(url: string, status: number, body: string);
|
|
33
|
+
}
|
|
16
34
|
/** Construction options for `create_ws_transport`. */
|
|
17
35
|
export interface WsTransportOptions {
|
|
18
36
|
/** Base URL the binary is reachable at — e.g. `http://localhost:8788`. Converted to `ws://` for the upgrade. */
|
|
@@ -73,7 +91,9 @@ export interface WsTransportOptions {
|
|
|
73
91
|
* use this directly; one that waits for a push (a broadcast, a targeted
|
|
74
92
|
* notification) opens with `create_admitted_ws_transport` instead.
|
|
75
93
|
*
|
|
76
|
-
* @throws
|
|
94
|
+
* @throws WsUpgradeRefusedError if the server answers the upgrade with an
|
|
95
|
+
* HTTP response, carrying its status and body
|
|
96
|
+
* @throws Error if the upgrade fails otherwise (network) — the rejection
|
|
77
97
|
* message carries the underlying error so the test surfaces the real
|
|
78
98
|
* cause rather than hanging.
|
|
79
99
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws_transport.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/transports/ws_transport.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"ws_transport.d.ts","sourceRoot":"","sources":["../../../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B,GAC/B,SAAS,kBAAkB,KACzB,OAAO,CAAC,iBAAiB,CAwL3B,CAAC;AAEF,mFAAmF;AACnF,eAAO,MAAM,qBAAqB,aAAa,CAAC;AAEhD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,4BAA4B,GACxC,SAAS,kBAAkB,KACzB,OAAO,CAAC,iBAAiB,CAS3B,CAAC"}
|
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
import '../assert_dev_env.js';
|
|
2
|
-
/**
|
|
3
|
-
* Cross-process WebSocket transport.
|
|
4
|
-
*
|
|
5
|
-
* Implements the shared `WsClient` interface (see `testing/transports/ws_client.ts`) over a
|
|
6
|
-
* real `WebSocket` upgrade against a spawned test binary. The cookie
|
|
7
|
-
* captured by the sibling `FetchTransport` on bootstrap is threaded onto
|
|
8
|
-
* the upgrade request so the WS session authenticates as the same
|
|
9
|
-
* account.
|
|
10
|
-
*
|
|
11
|
-
* Uses the `ws` npm package — Node's native `WebSocket` (from undici)
|
|
12
|
-
* follows the WHATWG spec strictly and doesn't accept custom request
|
|
13
|
-
* headers on construction, so cookie-on-upgrade requires the `ws`
|
|
14
|
-
* package's `headers` option. fuz_app declares `ws` as an optional
|
|
15
|
-
* peerDependency — consumers wiring cross-process tests install it
|
|
16
|
-
* themselves (`npm install --save-dev ws`).
|
|
17
|
-
*
|
|
18
|
-
* @module
|
|
19
|
-
*/
|
|
20
2
|
import { WebSocket } from 'ws';
|
|
21
3
|
import { WS_CLIENT_DEFAULT_TIMEOUT_MS, deliver_inbound, is_response_for } from './ws_client.js';
|
|
22
4
|
import { create_jsonrpc_request } from '../../http/jsonrpc_helpers.js';
|
|
23
5
|
import { heartbeat_action_spec } from '../../actions/heartbeat.js';
|
|
6
|
+
/**
|
|
7
|
+
* How long a refused upgrade's body may take to arrive before the transport
|
|
8
|
+
* closes the connection and rejects with what came — a refusal whose body
|
|
9
|
+
* never ends would otherwise leave the open pending forever.
|
|
10
|
+
*/
|
|
11
|
+
export const WS_REFUSAL_BODY_TIMEOUT_MS = 1000;
|
|
12
|
+
/**
|
|
13
|
+
* A WebSocket upgrade the server answered with an HTTP response instead of
|
|
14
|
+
* `101` — the refusal's status and body, so a test can tell an origin refusal
|
|
15
|
+
* (403) from a missing credential (401) instead of accepting any failure.
|
|
16
|
+
*/
|
|
17
|
+
export class WsUpgradeRefusedError extends Error {
|
|
18
|
+
/** The refusal's HTTP status. */
|
|
19
|
+
status;
|
|
20
|
+
/** The refusal's body as text (empty when it had none). */
|
|
21
|
+
body;
|
|
22
|
+
constructor(url, status, body) {
|
|
23
|
+
super(`ws upgrade to ${url} refused: Unexpected server response: ${status}`);
|
|
24
|
+
this.name = 'WsUpgradeRefusedError';
|
|
25
|
+
this.status = status;
|
|
26
|
+
this.body = body;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
24
29
|
/**
|
|
25
30
|
* Build a real-upgrade WS client pinned to `options.base_url` + `ws_path`.
|
|
26
31
|
*
|
|
@@ -37,7 +42,9 @@ import { heartbeat_action_spec } from '../../actions/heartbeat.js';
|
|
|
37
42
|
* use this directly; one that waits for a push (a broadcast, a targeted
|
|
38
43
|
* notification) opens with `create_admitted_ws_transport` instead.
|
|
39
44
|
*
|
|
40
|
-
* @throws
|
|
45
|
+
* @throws WsUpgradeRefusedError if the server answers the upgrade with an
|
|
46
|
+
* HTTP response, carrying its status and body
|
|
47
|
+
* @throws Error if the upgrade fails otherwise (network) — the rejection
|
|
41
48
|
* message carries the underlying error so the test surfaces the real
|
|
42
49
|
* cause rather than hanging.
|
|
43
50
|
*/
|
|
@@ -90,7 +97,9 @@ export const create_ws_transport = async (options) => {
|
|
|
90
97
|
// Wait for the upgrade to complete (or fail) before resolving the
|
|
91
98
|
// factory promise. Suite bodies expect a connected client back.
|
|
92
99
|
await new Promise((resolve, reject) => {
|
|
100
|
+
let settled = false;
|
|
93
101
|
const on_open = () => {
|
|
102
|
+
settled = true;
|
|
94
103
|
socket.on('error', (err) => {
|
|
95
104
|
// Post-open errors stash for diagnostics; close handler
|
|
96
105
|
// resolves the close() awaiters whether or not error fired.
|
|
@@ -99,10 +108,39 @@ export const create_ws_transport = async (options) => {
|
|
|
99
108
|
resolve();
|
|
100
109
|
};
|
|
101
110
|
const on_error = (err) => {
|
|
111
|
+
if (settled)
|
|
112
|
+
return;
|
|
113
|
+
settled = true;
|
|
102
114
|
reject(new Error(`ws upgrade to ${ws_url} failed: ${err.message}`));
|
|
103
115
|
};
|
|
116
|
+
// A listener here takes the refused response over from `ws`, which would
|
|
117
|
+
// otherwise abort with only the status in an error message; read the
|
|
118
|
+
// body, then close the connection. The socket is captured on entry: a
|
|
119
|
+
// finished response drops its `socket`, so `req.destroy()` alone would
|
|
120
|
+
// leave the connection open. A body that never ends is cut off after
|
|
121
|
+
// `WS_REFUSAL_BODY_TIMEOUT_MS`, rejecting with what arrived.
|
|
122
|
+
const on_unexpected_response = (req, res) => {
|
|
123
|
+
const tcp = res.socket;
|
|
124
|
+
const chunks = [];
|
|
125
|
+
const finish = () => {
|
|
126
|
+
clearTimeout(body_timer);
|
|
127
|
+
req.destroy();
|
|
128
|
+
tcp?.destroy();
|
|
129
|
+
if (settled)
|
|
130
|
+
return;
|
|
131
|
+
settled = true;
|
|
132
|
+
const body = Buffer.concat(chunks).toString('utf-8');
|
|
133
|
+
reject(new WsUpgradeRefusedError(ws_url, res.statusCode ?? 0, body));
|
|
134
|
+
};
|
|
135
|
+
const body_timer = setTimeout(finish, WS_REFUSAL_BODY_TIMEOUT_MS);
|
|
136
|
+
res.on('data', (chunk) => chunks.push(chunk));
|
|
137
|
+
res.once('end', finish);
|
|
138
|
+
res.once('close', finish);
|
|
139
|
+
res.once('error', finish);
|
|
140
|
+
};
|
|
104
141
|
socket.once('open', on_open);
|
|
105
|
-
socket.
|
|
142
|
+
socket.on('error', on_error);
|
|
143
|
+
socket.once('unexpected-response', on_unexpected_response);
|
|
106
144
|
});
|
|
107
145
|
const is_closed = () => socket.readyState === WebSocket.CLOSING || socket.readyState === WebSocket.CLOSED;
|
|
108
146
|
const wait_for_close = (timeout_ms = default_timeout) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws_round_trip.d.ts","sourceRoot":"","sources":["../../src/lib/testing/ws_round_trip.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAQ,MAAM,MAAM,CAAC;AAC1C,OAAO,EACN,SAAS,EAET,KAAK,gBAAgB,EAErB,KAAK,QAAQ,EACb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAe,KAAK,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAsB,KAAK,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAEpG,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAOtF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAG/E,OAAO,EAMN,KAAK,QAAQ,EACb,KAAK,kBAAkB,EAEvB,MAAM,2BAA2B,CAAC;AAMnC;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC5B;;;;OAIG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB,yFAAyF;IACzF,OAAO,EAAE,OAAO,CAAC;IACjB,+EAA+E;IAC/E,UAAU,EAAE,OAAO,CAAC;IACpB,yEAAyE;IACzE,SAAS,EAAE,MAAM,IAAI,CAAC;CACtB;AAED;;;;GAI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