@fuzdev/fuz_app 0.149.0 → 0.151.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/actions/CLAUDE.md +327 -300
- package/dist/actions/action_bridge.d.ts +5 -79
- package/dist/actions/action_bridge.d.ts.map +1 -1
- package/dist/actions/action_bridge.js +4 -74
- package/dist/actions/action_codegen.d.ts +8 -166
- package/dist/actions/action_codegen.d.ts.map +1 -1
- package/dist/actions/action_codegen.js +19 -95
- package/dist/actions/action_dispatcher.d.ts +10 -0
- package/dist/actions/action_dispatcher.d.ts.map +1 -1
- package/dist/actions/action_dispatcher.js +9 -6
- package/dist/actions/action_event.d.ts +1 -2
- package/dist/actions/action_event.d.ts.map +1 -1
- package/dist/actions/action_event.js +7 -13
- package/dist/actions/action_event_helpers.d.ts +1 -40
- package/dist/actions/action_event_helpers.d.ts.map +1 -1
- package/dist/actions/action_event_helpers.js +1 -25
- package/dist/actions/action_event_types.d.ts +1 -1
- package/dist/actions/action_event_types.d.ts.map +1 -1
- package/dist/actions/action_rpc.d.ts +10 -215
- package/dist/actions/action_rpc.d.ts.map +1 -1
- package/dist/actions/action_rpc.js +56 -111
- package/dist/actions/action_spec.d.ts +2 -2
- package/dist/actions/action_spec.js +2 -2
- package/dist/actions/action_types.d.ts +229 -8
- package/dist/actions/action_types.d.ts.map +1 -1
- package/dist/actions/action_types.js +56 -5
- package/dist/actions/broadcast_api.d.ts +22 -17
- package/dist/actions/broadcast_api.d.ts.map +1 -1
- package/dist/actions/broadcast_api.js +16 -27
- package/dist/actions/cancel.d.ts +4 -13
- package/dist/actions/cancel.d.ts.map +1 -1
- package/dist/actions/cancel.js +5 -17
- package/dist/actions/compile_action_registry.d.ts +1 -2
- package/dist/actions/compile_action_registry.d.ts.map +1 -1
- package/dist/actions/connection_closer.d.ts +120 -50
- package/dist/actions/connection_closer.d.ts.map +1 -1
- package/dist/actions/connection_closer.js +139 -31
- package/dist/actions/{transports_ws_backend.d.ts → connection_registry.d.ts} +120 -132
- package/dist/actions/connection_registry.d.ts.map +1 -0
- package/dist/actions/{transports_ws_backend.js → connection_registry.js} +149 -152
- package/dist/actions/frontend_rpc_client.d.ts +52 -2
- package/dist/actions/frontend_rpc_client.d.ts.map +1 -1
- package/dist/actions/frontend_rpc_client.js +42 -4
- package/dist/actions/peer_ping.d.ts +7 -9
- package/dist/actions/peer_ping.d.ts.map +1 -1
- package/dist/actions/peer_ping.js +6 -8
- package/dist/actions/peer_request.d.ts +6 -5
- package/dist/actions/peer_request.d.ts.map +1 -1
- package/dist/actions/peer_request.js +6 -5
- package/dist/actions/perform_action.d.ts +36 -28
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +60 -31
- package/dist/actions/protocol.d.ts +14 -0
- package/dist/actions/protocol.d.ts.map +1 -1
- package/dist/actions/protocol.js +18 -0
- package/dist/actions/register_action_ws.d.ts +137 -292
- package/dist/actions/register_action_ws.d.ts.map +1 -1
- package/dist/actions/register_action_ws.js +155 -903
- package/dist/actions/socket.svelte.d.ts +9 -0
- package/dist/actions/socket.svelte.d.ts.map +1 -1
- package/dist/actions/socket.svelte.js +16 -5
- package/dist/actions/transports.d.ts +88 -34
- package/dist/actions/transports.d.ts.map +1 -1
- package/dist/actions/transports.js +76 -76
- package/dist/actions/transports_http.d.ts +48 -12
- package/dist/actions/transports_http.d.ts.map +1 -1
- package/dist/actions/transports_http.js +75 -44
- package/dist/actions/transports_ws.d.ts +29 -0
- package/dist/actions/transports_ws.d.ts.map +1 -1
- package/dist/actions/transports_ws.js +34 -8
- package/dist/actions/ws_endpoint_spec.d.ts +53 -76
- package/dist/actions/ws_endpoint_spec.d.ts.map +1 -1
- package/dist/actions/ws_endpoint_spec.js +27 -10
- package/dist/actions/ws_outbound_writer.d.ts +3 -3
- package/dist/actions/ws_outbound_writer.js +3 -3
- package/dist/actions/ws_socket_session.d.ts +321 -0
- package/dist/actions/ws_socket_session.d.ts.map +1 -0
- package/dist/actions/ws_socket_session.js +783 -0
- package/dist/auth/CLAUDE.md +132 -68
- package/dist/auth/account_action_specs.d.ts +2 -0
- package/dist/auth/account_action_specs.d.ts.map +1 -1
- package/dist/auth/account_actions.d.ts +1 -1
- package/dist/auth/account_actions.d.ts.map +1 -1
- package/dist/auth/account_actions.js +9 -3
- package/dist/auth/account_queries.d.ts +10 -0
- package/dist/auth/account_queries.d.ts.map +1 -1
- package/dist/auth/account_queries.js +27 -17
- package/dist/auth/account_routes.d.ts +2 -1
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +14 -17
- package/dist/auth/account_schema.d.ts +5 -5
- package/dist/auth/account_schema.d.ts.map +1 -1
- package/dist/auth/account_schema.js +5 -2
- package/dist/auth/actor_lookup_actions.d.ts +1 -1
- package/dist/auth/actor_lookup_actions.d.ts.map +1 -1
- package/dist/auth/actor_lookup_actions.js +1 -1
- package/dist/auth/actor_lookup_queries.d.ts +3 -2
- package/dist/auth/actor_lookup_queries.d.ts.map +1 -1
- package/dist/auth/actor_lookup_queries.js +6 -3
- package/dist/auth/actor_search_action_specs.d.ts.map +1 -1
- package/dist/auth/actor_search_action_specs.js +2 -1
- package/dist/auth/actor_search_actions.d.ts +1 -1
- package/dist/auth/actor_search_actions.d.ts.map +1 -1
- package/dist/auth/actor_search_actions.js +1 -1
- package/dist/auth/actor_search_queries.d.ts +10 -7
- package/dist/auth/actor_search_queries.d.ts.map +1 -1
- package/dist/auth/actor_search_queries.js +18 -11
- package/dist/auth/admin_action_specs.d.ts +4 -4
- package/dist/auth/admin_action_specs.d.ts.map +1 -1
- package/dist/auth/admin_action_specs.js +7 -5
- package/dist/auth/admin_actions.d.ts +1 -1
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +47 -48
- package/dist/auth/all_cell_actions.d.ts +14 -3
- package/dist/auth/all_cell_actions.d.ts.map +1 -1
- package/dist/auth/all_cell_actions.js +2 -1
- package/dist/auth/api_token_queries.d.ts +1 -0
- package/dist/auth/api_token_queries.d.ts.map +1 -1
- package/dist/auth/api_token_queries.js +1 -0
- package/dist/auth/audit_emitter.d.ts +12 -6
- package/dist/auth/audit_emitter.d.ts.map +1 -1
- package/dist/auth/audit_emitter.js +11 -5
- package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_route_schema.js +3 -2
- package/dist/auth/audit_log_routes.d.ts +20 -11
- package/dist/auth/audit_log_routes.d.ts.map +1 -1
- package/dist/auth/audit_log_routes.js +49 -29
- package/dist/auth/audit_log_schema.d.ts +14 -21
- package/dist/auth/audit_log_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_schema.js +19 -23
- package/dist/auth/bearer_auth.d.ts +7 -4
- package/dist/auth/bearer_auth.d.ts.map +1 -1
- package/dist/auth/bearer_auth.js +21 -15
- package/dist/auth/bootstrap_account.d.ts +25 -1
- package/dist/auth/bootstrap_account.d.ts.map +1 -1
- package/dist/auth/bootstrap_account.js +37 -4
- package/dist/auth/bootstrap_routes.d.ts +3 -2
- package/dist/auth/bootstrap_routes.d.ts.map +1 -1
- package/dist/auth/bootstrap_routes.js +5 -4
- package/dist/auth/cell_action_helpers.d.ts +89 -0
- package/dist/auth/cell_action_helpers.d.ts.map +1 -0
- package/dist/auth/cell_action_helpers.js +113 -0
- package/dist/auth/cell_action_specs.d.ts +215 -15
- package/dist/auth/cell_action_specs.d.ts.map +1 -1
- package/dist/auth/cell_action_specs.js +103 -16
- package/dist/auth/cell_actions.d.ts +58 -27
- package/dist/auth/cell_actions.d.ts.map +1 -1
- package/dist/auth/cell_actions.js +206 -161
- package/dist/auth/cell_audit_actions.d.ts +1 -1
- package/dist/auth/cell_audit_actions.d.ts.map +1 -1
- package/dist/auth/cell_audit_actions.js +3 -12
- package/dist/auth/cell_audit_events.d.ts +1 -1
- package/dist/auth/cell_audit_events.d.ts.map +1 -1
- package/dist/auth/cell_audit_events.js +3 -2
- package/dist/auth/cell_audit_metadata.d.ts +12 -1
- package/dist/auth/cell_audit_metadata.d.ts.map +1 -1
- package/dist/auth/cell_audit_metadata.js +11 -1
- package/dist/auth/cell_field_actions.d.ts +1 -1
- package/dist/auth/cell_field_actions.d.ts.map +1 -1
- package/dist/auth/cell_field_actions.js +16 -66
- package/dist/auth/cell_grant_action_specs.d.ts +9 -2
- package/dist/auth/cell_grant_action_specs.d.ts.map +1 -1
- package/dist/auth/cell_grant_action_specs.js +10 -3
- package/dist/auth/cell_grant_actions.d.ts +105 -11
- package/dist/auth/cell_grant_actions.d.ts.map +1 -1
- package/dist/auth/cell_grant_actions.js +81 -56
- package/dist/auth/cell_grant_audit_metadata.d.ts +6 -3
- package/dist/auth/cell_grant_audit_metadata.d.ts.map +1 -1
- package/dist/auth/cell_grant_audit_metadata.js +7 -4
- package/dist/auth/cell_item_actions.d.ts +1 -1
- package/dist/auth/cell_item_actions.d.ts.map +1 -1
- package/dist/auth/cell_item_actions.js +21 -82
- package/dist/auth/cleanup.d.ts +1 -1
- package/dist/auth/cleanup.d.ts.map +1 -1
- package/dist/auth/cleanup.js +6 -3
- package/dist/auth/credential_deadline.d.ts +3 -3
- package/dist/auth/credential_deadline.js +3 -3
- package/dist/auth/credential_type_schema.d.ts +8 -7
- package/dist/auth/credential_type_schema.d.ts.map +1 -1
- package/dist/auth/credential_type_schema.js +8 -7
- package/dist/auth/daemon_token_middleware.d.ts +12 -6
- package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.js +28 -17
- package/dist/auth/deps.d.ts +4 -4
- package/dist/auth/fail_floor.d.ts +55 -0
- package/dist/auth/fail_floor.d.ts.map +1 -0
- package/dist/auth/fail_floor.js +63 -0
- package/dist/auth/invite_queries.d.ts +3 -15
- package/dist/auth/invite_queries.d.ts.map +1 -1
- package/dist/auth/invite_queries.js +3 -21
- package/dist/auth/middleware.d.ts +12 -7
- package/dist/auth/middleware.d.ts.map +1 -1
- package/dist/auth/middleware.js +42 -29
- package/dist/auth/migrations.d.ts +5 -33
- package/dist/auth/migrations.d.ts.map +1 -1
- package/dist/auth/migrations.js +9 -16
- package/dist/auth/request_context.d.ts +101 -71
- package/dist/auth/request_context.d.ts.map +1 -1
- package/dist/auth/request_context.js +137 -140
- package/dist/auth/resolved_auth.d.ts +122 -36
- package/dist/auth/resolved_auth.d.ts.map +1 -1
- package/dist/auth/resolved_auth.js +89 -38
- package/dist/auth/role_grant_offer_action_specs.d.ts +117 -16
- package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_action_specs.js +51 -16
- package/dist/auth/role_grant_offer_actions.d.ts +22 -11
- package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_actions.js +72 -19
- package/dist/auth/role_grant_offer_notifications.d.ts +6 -5
- package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_notifications.js +4 -3
- package/dist/auth/role_grant_offer_queries.d.ts +20 -5
- package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_queries.js +40 -37
- package/dist/auth/role_grant_queries.d.ts +44 -76
- package/dist/auth/role_grant_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_queries.js +73 -118
- package/dist/auth/role_grant_sql.d.ts +42 -0
- package/dist/auth/role_grant_sql.d.ts.map +1 -0
- package/dist/auth/role_grant_sql.js +54 -0
- package/dist/auth/role_schema.d.ts +14 -8
- package/dist/auth/role_schema.d.ts.map +1 -1
- package/dist/auth/role_schema.js +6 -3
- package/dist/auth/scope_kind_schema.d.ts +1 -1
- package/dist/auth/scope_kind_schema.js +1 -1
- package/dist/auth/self_service_role_actions.d.ts +1 -1
- package/dist/auth/self_service_role_actions.d.ts.map +1 -1
- package/dist/auth/self_service_role_actions.js +21 -1
- package/dist/auth/session_queries.d.ts +2 -1
- package/dist/auth/session_queries.d.ts.map +1 -1
- package/dist/auth/session_queries.js +2 -1
- package/dist/auth/signup_routes.d.ts +2 -1
- package/dist/auth/signup_routes.d.ts.map +1 -1
- package/dist/auth/signup_routes.js +14 -13
- package/dist/auth/standard_rpc_actions.d.ts +1 -1
- package/dist/auth/standard_rpc_actions.d.ts.map +1 -1
- package/dist/auth/token_scope.d.ts +19 -46
- package/dist/auth/token_scope.d.ts.map +1 -1
- package/dist/auth/token_scope.js +23 -41
- package/dist/db/CLAUDE.md +18 -6
- package/dist/db/cell_ddl.d.ts +5 -134
- package/dist/db/cell_ddl.d.ts.map +1 -1
- package/dist/db/cell_ddl.js +28 -17
- package/dist/db/cell_field_queries.d.ts +0 -13
- package/dist/db/cell_field_queries.d.ts.map +1 -1
- package/dist/db/cell_field_queries.js +0 -16
- package/dist/db/cell_grant_queries.d.ts +10 -5
- package/dist/db/cell_grant_queries.d.ts.map +1 -1
- package/dist/db/cell_grant_queries.js +13 -7
- package/dist/db/cell_item_queries.d.ts +0 -7
- package/dist/db/cell_item_queries.d.ts.map +1 -1
- package/dist/db/cell_item_queries.js +0 -10
- package/dist/db/cell_queries.d.ts +65 -55
- package/dist/db/cell_queries.d.ts.map +1 -1
- package/dist/db/cell_queries.js +85 -62
- package/dist/db/cell_view_sql.d.ts +1 -6
- package/dist/db/cell_view_sql.d.ts.map +1 -1
- package/dist/db/cell_view_sql.js +1 -2
- package/dist/db/fact_ddl.d.ts +5 -30
- package/dist/db/fact_ddl.d.ts.map +1 -1
- package/dist/db/fact_ddl.js +14 -13
- package/dist/db/fact_store.d.ts +11 -0
- package/dist/db/fact_store.d.ts.map +1 -1
- package/dist/db/fact_store.js +4 -1
- package/dist/db/migrate.d.ts +44 -6
- package/dist/db/migrate.d.ts.map +1 -1
- package/dist/db/migrate.js +63 -4
- package/dist/dev/setup.d.ts +18 -14
- package/dist/dev/setup.d.ts.map +1 -1
- package/dist/dev/setup.js +42 -39
- package/dist/env/dotenv.d.ts +2 -2
- package/dist/env/dotenv.js +2 -2
- package/dist/env/update_env_variable.d.ts +33 -21
- package/dist/env/update_env_variable.d.ts.map +1 -1
- package/dist/env/update_env_variable.js +54 -35
- package/dist/hono_context.d.ts +15 -90
- package/dist/hono_context.d.ts.map +1 -1
- package/dist/hono_context.js +9 -56
- package/dist/http/CLAUDE.md +35 -20
- package/dist/http/auth_shape.d.ts +1 -8
- package/dist/http/auth_shape.d.ts.map +1 -1
- package/dist/http/auth_shape.js +6 -12
- package/dist/http/body_limit.d.ts +3 -1
- package/dist/http/body_limit.d.ts.map +1 -1
- package/dist/http/body_limit.js +6 -1
- package/dist/http/common_routes.d.ts.map +1 -1
- package/dist/http/common_routes.js +3 -2
- package/dist/http/db_routes.d.ts +3 -3
- package/dist/http/db_routes.js +3 -3
- package/dist/http/error_schemas.d.ts +1 -2
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/error_schemas.js +1 -2
- package/dist/http/health_schema.d.ts +16 -0
- package/dist/http/health_schema.d.ts.map +1 -0
- package/dist/http/health_schema.js +12 -0
- package/dist/http/jsonrpc.d.ts +9 -0
- package/dist/http/jsonrpc.d.ts.map +1 -1
- package/dist/http/jsonrpc.js +17 -0
- package/dist/http/jsonrpc_errors.d.ts +22 -2
- package/dist/http/jsonrpc_errors.d.ts.map +1 -1
- package/dist/http/jsonrpc_errors.js +70 -23
- package/dist/http/jsonrpc_helpers.d.ts +60 -17
- package/dist/http/jsonrpc_helpers.d.ts.map +1 -1
- package/dist/http/jsonrpc_helpers.js +67 -25
- package/dist/http/origin.d.ts +30 -1
- package/dist/http/origin.d.ts.map +1 -1
- package/dist/http/origin.js +46 -9
- package/dist/http/origin_wildcard.d.ts +97 -0
- package/dist/http/origin_wildcard.d.ts.map +1 -0
- package/dist/http/origin_wildcard.js +142 -0
- package/dist/http/pending_effects.d.ts +28 -0
- package/dist/http/pending_effects.d.ts.map +1 -1
- package/dist/http/pending_effects.js +32 -1
- package/dist/http/proxy.d.ts +4 -2
- package/dist/http/proxy.d.ts.map +1 -1
- package/dist/http/proxy.js +7 -2
- package/dist/http/route_spec.d.ts +4 -3
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +54 -45
- package/dist/http/surface.d.ts +4 -2
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface.js +7 -4
- package/dist/http/surface_query.d.ts +9 -50
- package/dist/http/surface_query.d.ts.map +1 -1
- package/dist/http/surface_query.js +48 -94
- package/dist/realtime/audit_log_sse.d.ts +180 -0
- package/dist/realtime/audit_log_sse.d.ts.map +1 -0
- package/dist/realtime/audit_log_sse.js +154 -0
- package/dist/realtime/sse.d.ts +21 -6
- package/dist/realtime/sse.d.ts.map +1 -1
- package/dist/realtime/sse.js +33 -10
- package/dist/realtime/sse_constants.d.ts +29 -2
- package/dist/realtime/sse_constants.d.ts.map +1 -1
- package/dist/realtime/sse_constants.js +35 -2
- package/dist/realtime/{subscriber_registry.d.ts → sse_registry.d.ts} +12 -12
- package/dist/realtime/sse_registry.d.ts.map +1 -0
- package/dist/realtime/{subscriber_registry.js → sse_registry.js} +4 -4
- package/dist/schema_meta.d.ts +52 -1
- package/dist/schema_meta.d.ts.map +1 -1
- package/dist/schema_meta.js +123 -6
- package/dist/sensitivity.d.ts +9 -3
- package/dist/sensitivity.d.ts.map +1 -1
- package/dist/sensitivity.js +3 -2
- package/dist/server/app_backend.d.ts +8 -5
- package/dist/server/app_backend.d.ts.map +1 -1
- package/dist/server/app_backend.js +6 -12
- package/dist/server/app_server.d.ts +73 -54
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +115 -78
- package/dist/server/app_server_context.d.ts +1 -1
- package/dist/server/app_server_context.d.ts.map +1 -1
- package/dist/server/env.d.ts +24 -20
- package/dist/server/env.d.ts.map +1 -1
- package/dist/server/env.js +24 -34
- package/dist/server/serve_fact_route.d.ts +12 -16
- package/dist/server/serve_fact_route.d.ts.map +1 -1
- package/dist/server/serve_fact_route.js +59 -34
- package/dist/server/static.d.ts.map +1 -1
- package/dist/server/static.js +2 -2
- package/dist/testing/CLAUDE.md +213 -179
- package/dist/testing/admin_integration.d.ts.map +1 -1
- package/dist/testing/admin_integration.js +10 -19
- package/dist/testing/adversarial_headers.d.ts.map +1 -1
- package/dist/testing/adversarial_headers.js +8 -0
- package/dist/testing/app_server.d.ts +9 -75
- package/dist/testing/app_server.d.ts.map +1 -1
- package/dist/testing/app_server.js +31 -112
- package/dist/testing/attack_surface.d.ts.map +1 -1
- package/dist/testing/attack_surface.js +3 -4
- package/dist/testing/audit_completeness.d.ts.map +1 -1
- package/dist/testing/audit_completeness.js +4 -5
- package/dist/testing/auth_apps.d.ts +3 -3
- package/dist/testing/auth_apps.d.ts.map +1 -1
- package/dist/testing/auth_apps.js +9 -6
- package/dist/testing/connection_closer_helpers.d.ts +8 -16
- package/dist/testing/connection_closer_helpers.d.ts.map +1 -1
- package/dist/testing/connection_closer_helpers.js +7 -20
- package/dist/testing/cross_backend/action_manifest.d.ts +15 -4
- package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
- package/dist/testing/cross_backend/action_manifest.js +13 -3
- package/dist/testing/cross_backend/action_manifest_parity.d.ts +15 -7
- package/dist/testing/cross_backend/action_manifest_parity.d.ts.map +1 -1
- package/dist/testing/cross_backend/action_manifest_parity.js +8 -1
- package/dist/testing/cross_backend/actor_lookup.d.ts.map +1 -1
- package/dist/testing/cross_backend/actor_lookup.js +27 -0
- package/dist/testing/cross_backend/body_size.d.ts.map +1 -1
- package/dist/testing/cross_backend/body_size.js +25 -22
- package/dist/testing/cross_backend/build_test_backend_paths.d.ts +22 -3
- package/dist/testing/cross_backend/build_test_backend_paths.d.ts.map +1 -1
- package/dist/testing/cross_backend/build_test_backend_paths.js +34 -11
- package/dist/testing/cross_backend/capabilities.d.ts +15 -8
- package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_gated_create.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_gated_create.js +109 -13
- package/dist/testing/cross_backend/cell_grant_role.js +2 -2
- package/dist/testing/cross_backend/cell_grant_steward.d.ts +4 -0
- package/dist/testing/cross_backend/cell_grant_steward.d.ts.map +1 -0
- package/dist/testing/cross_backend/cell_grant_steward.js +120 -0
- package/dist/testing/cross_backend/cell_moderate.d.ts +7 -1
- package/dist/testing/cross_backend/cell_moderate.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_moderate.js +68 -4
- package/dist/testing/cross_backend/cell_ref_admission.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_ref_admission.js +18 -9
- package/dist/testing/cross_backend/cell_relations.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_relations.js +21 -0
- package/dist/testing/cross_backend/conformance_table.d.ts +6 -1
- package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.js +12 -10
- package/dist/testing/cross_backend/default_backend_configs.d.ts +18 -4
- package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_backend_configs.js +29 -9
- package/dist/testing/cross_backend/default_spine_surface.d.ts +7 -7
- package/dist/testing/cross_backend/default_spine_surface.js +2 -2
- package/dist/testing/cross_backend/differential.d.ts +7 -0
- package/dist/testing/cross_backend/differential.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential.js +17 -0
- package/dist/testing/cross_backend/expected_schema.json +1 -0
- package/dist/testing/cross_backend/fact_serving.d.ts.map +1 -1
- package/dist/testing/cross_backend/fact_serving.js +48 -0
- package/dist/testing/cross_backend/full_spine_mount.d.ts +3 -4
- package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
- package/dist/testing/cross_backend/full_spine_mount.js +13 -5
- package/dist/testing/cross_backend/origin_scope.d.ts.map +1 -1
- package/dist/testing/cross_backend/origin_scope.js +5 -13
- package/dist/testing/cross_backend/peer_ping_ws.d.ts.map +1 -1
- package/dist/testing/cross_backend/peer_ping_ws.js +29 -4
- package/dist/testing/cross_backend/postgres_database.d.ts +32 -0
- package/dist/testing/cross_backend/postgres_database.d.ts.map +1 -1
- package/dist/testing/cross_backend/postgres_database.js +56 -1
- package/dist/testing/cross_backend/query_shape.d.ts.map +1 -1
- package/dist/testing/cross_backend/query_shape.js +18 -1
- package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +96 -2
- package/dist/testing/cross_backend/rpc_success_fixtures.js +2 -2
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts +17 -5
- package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_stub_backend_config.js +5 -4
- package/dist/testing/cross_backend/session_cap.d.ts +8 -0
- package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
- package/dist/testing/cross_backend/session_cap.js +66 -2
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +5 -4
- package/dist/testing/cross_backend/spine_suites.d.ts +4 -1
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +21 -0
- package/dist/testing/cross_backend/spine_surface_constants.d.ts +22 -7
- package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_surface_constants.js +22 -7
- package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/sse_round_trip.js +4 -3
- package/dist/testing/cross_backend/standard.d.ts +6 -12
- package/dist/testing/cross_backend/standard.d.ts.map +1 -1
- package/dist/testing/cross_backend/test_cell_gated_create_authorize.d.ts +18 -19
- package/dist/testing/cross_backend/test_cell_gated_create_authorize.d.ts.map +1 -1
- package/dist/testing/cross_backend/test_cell_gated_create_authorize.js +66 -42
- package/dist/testing/cross_backend/test_cell_grant_steward_revoke_authorize.d.ts +8 -0
- package/dist/testing/cross_backend/test_cell_grant_steward_revoke_authorize.d.ts.map +1 -0
- package/dist/testing/cross_backend/test_cell_grant_steward_revoke_authorize.js +22 -0
- package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_backdoor.js +4 -6
- package/dist/testing/cross_backend/testing_origin_check.d.ts +1 -1
- package/dist/testing/cross_backend/testing_origin_check.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_origin_check.js +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +10 -5
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +7 -6
- package/dist/testing/cross_backend/testing_server_bun.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_server_bun.js +5 -4
- package/dist/testing/cross_backend/testing_server_core.d.ts +6 -7
- package/dist/testing/cross_backend/testing_server_core.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_server_core.js +1 -1
- package/dist/testing/cross_backend/testing_server_node.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_server_node.js +13 -2
- package/dist/testing/cross_backend/token_lifetime.d.ts.map +1 -1
- package/dist/testing/cross_backend/token_lifetime.js +68 -0
- package/dist/testing/cross_backend/transport_composition.d.ts +1 -1
- package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
- package/dist/testing/cross_backend/transport_composition.js +48 -6
- package/dist/testing/cross_backend/ts_spine_backend_config.d.ts +16 -2
- package/dist/testing/cross_backend/ts_spine_backend_config.d.ts.map +1 -1
- package/dist/testing/cross_backend/ts_spine_backend_config.js +11 -8
- package/dist/testing/cross_backend/ws_action_rate_limit.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_action_rate_limit.js +30 -12
- package/dist/testing/cross_backend/ws_connection_cap.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_connection_cap.js +5 -7
- package/dist/testing/cross_backend/ws_endpoint.d.ts +2 -3
- package/dist/testing/cross_backend/ws_endpoint.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_envelope.d.ts +17 -0
- package/dist/testing/cross_backend/ws_envelope.d.ts.map +1 -0
- package/dist/testing/cross_backend/ws_envelope.js +172 -0
- package/dist/testing/cross_backend/ws_inbound_dispatch.d.ts +16 -0
- package/dist/testing/cross_backend/ws_inbound_dispatch.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_inbound_dispatch.js +8 -4
- package/dist/testing/cross_backend/ws_outbound_overflow.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_outbound_overflow.js +5 -8
- package/dist/testing/cross_backend/ws_role_gated.js +2 -2
- package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_round_trip.js +6 -4
- package/dist/{cli/daemon.d.ts → testing/daemon_info.d.ts} +15 -47
- package/dist/testing/daemon_info.d.ts.map +1 -0
- package/dist/testing/daemon_info.js +108 -0
- package/dist/testing/daemon_token_rotation.js +1 -1
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +3 -4
- package/dist/testing/db.js +2 -2
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +35 -65
- package/dist/testing/integration_helpers.d.ts +0 -15
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/integration_helpers.js +2 -42
- package/dist/testing/middleware.d.ts +20 -12
- package/dist/testing/middleware.d.ts.map +1 -1
- package/dist/testing/middleware.js +49 -40
- package/dist/testing/rate_limiting.d.ts.map +1 -1
- package/dist/testing/rate_limiting.js +13 -22
- package/dist/testing/resolved_auth.d.ts +30 -0
- package/dist/testing/resolved_auth.d.ts.map +1 -0
- package/dist/testing/resolved_auth.js +41 -0
- package/dist/testing/rpc_envelope_cases.d.ts.map +1 -1
- package/dist/testing/rpc_envelope_cases.js +3 -0
- package/dist/testing/rpc_helpers.d.ts +1 -1
- package/dist/testing/rpc_helpers.d.ts.map +1 -1
- package/dist/testing/rpc_helpers.js +2 -1
- package/dist/testing/sse_round_trip.d.ts +5 -4
- package/dist/testing/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/sse_round_trip.js +2 -2
- package/dist/testing/stubs.d.ts +2 -2
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +24 -21
- package/dist/testing/test_origin.d.ts +25 -0
- package/dist/testing/test_origin.d.ts.map +1 -0
- package/dist/testing/test_origin.js +28 -0
- package/dist/testing/transports/raw_http.d.ts +54 -0
- package/dist/testing/transports/raw_http.d.ts.map +1 -1
- package/dist/testing/transports/raw_http.js +58 -0
- package/dist/testing/transports/ws_raw_client.d.ts +8 -0
- package/dist/testing/transports/ws_raw_client.d.ts.map +1 -1
- package/dist/testing/transports/ws_raw_client.js +13 -0
- package/dist/testing/transports/ws_transport.d.ts +15 -2
- package/dist/testing/transports/ws_transport.d.ts.map +1 -1
- package/dist/testing/transports/ws_transport.js +4 -2
- package/dist/testing/ws_round_trip.d.ts +27 -25
- package/dist/testing/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/ws_round_trip.js +34 -26
- package/dist/ui/AccountSessions.svelte +48 -19
- package/dist/ui/AccountSessions.svelte.d.ts +2 -17
- package/dist/ui/AccountSessions.svelte.d.ts.map +1 -1
- package/dist/ui/AdminAccounts.svelte +6 -1
- package/dist/ui/AdminAuditLog.svelte +61 -22
- package/dist/ui/AdminAuditLog.svelte.d.ts.map +1 -1
- package/dist/ui/AdminInvites.svelte +1 -1
- package/dist/ui/AdminOverview.svelte +76 -37
- package/dist/ui/AdminOverview.svelte.d.ts.map +1 -1
- package/dist/ui/AdminRoleGrantHistory.svelte +6 -1
- package/dist/ui/AdminSessions.svelte +1 -1
- package/dist/ui/AppShell.svelte +3 -2
- package/dist/ui/AppShell.svelte.d.ts +3 -2
- package/dist/ui/AppShell.svelte.d.ts.map +1 -1
- package/dist/ui/CLAUDE.md +121 -35
- package/dist/ui/Datatable.svelte +33 -18
- package/dist/ui/Datatable.svelte.d.ts +2 -14
- package/dist/ui/Datatable.svelte.d.ts.map +1 -1
- package/dist/ui/OpenSignupToggle.svelte +10 -1
- package/dist/ui/OpenSignupToggle.svelte.d.ts.map +1 -1
- package/dist/ui/PopoverButton.svelte +13 -8
- package/dist/ui/PopoverButton.svelte.d.ts.map +1 -1
- package/dist/ui/RoleGrantOfferForm.svelte +3 -2
- package/dist/ui/RoleGrantOfferForm.svelte.d.ts +3 -2
- package/dist/ui/RoleGrantOfferForm.svelte.d.ts.map +1 -1
- package/dist/ui/RoleGrantOfferHistory.svelte +3 -3
- package/dist/ui/RoleGrantOfferInbox.svelte +19 -15
- package/dist/ui/RoleGrantOfferInbox.svelte.d.ts.map +1 -1
- package/dist/ui/SurfaceExplorer.svelte +66 -27
- package/dist/ui/SurfaceExplorer.svelte.d.ts.map +1 -1
- package/dist/ui/account_sessions_state.svelte.d.ts +7 -14
- package/dist/ui/account_sessions_state.svelte.d.ts.map +1 -1
- package/dist/ui/admin_accounts_state.svelte.d.ts +14 -9
- package/dist/ui/admin_accounts_state.svelte.d.ts.map +1 -1
- package/dist/ui/admin_accounts_state.svelte.js +6 -4
- package/dist/ui/admin_invites_state.svelte.d.ts +2 -2
- package/dist/ui/admin_invites_state.svelte.d.ts.map +1 -1
- package/dist/ui/admin_rpc_adapters.d.ts +9 -9
- package/dist/ui/admin_rpc_adapters.d.ts.map +1 -1
- package/dist/ui/admin_rpc_adapters.js +9 -9
- package/dist/ui/app_settings_state.svelte.d.ts +2 -2
- package/dist/ui/app_settings_state.svelte.d.ts.map +1 -1
- package/dist/ui/audit_log_state.svelte.d.ts +70 -13
- package/dist/ui/audit_log_state.svelte.d.ts.map +1 -1
- package/dist/ui/audit_log_state.svelte.js +239 -47
- package/dist/ui/backend_probe.svelte.d.ts +93 -0
- package/dist/ui/backend_probe.svelte.d.ts.map +1 -0
- package/dist/ui/backend_probe.svelte.js +140 -0
- package/dist/ui/format_scope.d.ts +7 -7
- package/dist/ui/format_scope.d.ts.map +1 -1
- package/dist/ui/format_scope.js +4 -4
- package/dist/ui/keyed_async_slot.svelte.d.ts +2 -2
- package/dist/ui/keyed_async_slot.svelte.js +2 -2
- package/dist/ui/popover.svelte.d.ts +18 -19
- package/dist/ui/popover.svelte.d.ts.map +1 -1
- package/dist/ui/popover.svelte.js +103 -16
- package/dist/ui/role_grant_offers_state.svelte.d.ts +41 -46
- package/dist/ui/role_grant_offers_state.svelte.d.ts.map +1 -1
- package/dist/ui/role_grant_offers_state.svelte.js +37 -19
- package/dist/ui/ui_format.d.ts +17 -0
- package/dist/ui/ui_format.d.ts.map +1 -1
- package/dist/ui/ui_format.js +20 -0
- package/package.json +2 -1
- package/dist/actions/register_ws_endpoint.d.ts +0 -79
- package/dist/actions/register_ws_endpoint.d.ts.map +0 -1
- package/dist/actions/register_ws_endpoint.js +0 -109
- package/dist/actions/transports_ws_auth_guard.d.ts +0 -94
- package/dist/actions/transports_ws_auth_guard.d.ts.map +0 -1
- package/dist/actions/transports_ws_auth_guard.js +0 -138
- package/dist/actions/transports_ws_backend.d.ts.map +0 -1
- package/dist/cli/args.d.ts +0 -55
- package/dist/cli/args.d.ts.map +0 -1
- package/dist/cli/args.js +0 -100
- package/dist/cli/config.d.ts +0 -47
- package/dist/cli/config.d.ts.map +0 -1
- package/dist/cli/config.js +0 -77
- package/dist/cli/daemon.d.ts.map +0 -1
- package/dist/cli/daemon.js +0 -181
- package/dist/cli/help.d.ts +0 -124
- package/dist/cli/help.d.ts.map +0 -1
- package/dist/cli/help.js +0 -215
- package/dist/cli/logger.d.ts +0 -46
- package/dist/cli/logger.d.ts.map +0 -1
- package/dist/cli/logger.js +0 -48
- package/dist/cli/util.d.ts +0 -36
- package/dist/cli/util.d.ts.map +0 -1
- package/dist/cli/util.js +0 -50
- package/dist/realtime/sse_auth_guard.d.ts +0 -197
- package/dist/realtime/sse_auth_guard.d.ts.map +0 -1
- package/dist/realtime/sse_auth_guard.js +0 -238
- package/dist/realtime/subscriber_registry.d.ts.map +0 -1
- package/dist/testing/bootstrap_success.d.ts +0 -29
- package/dist/testing/bootstrap_success.d.ts.map +0 -1
- package/dist/testing/bootstrap_success.js +0 -144
- package/dist/testing/mock_fs.d.ts +0 -20
- package/dist/testing/mock_fs.d.ts.map +0 -1
- package/dist/testing/mock_fs.js +0 -28
- package/dist/testing/standard.d.ts +0 -122
- package/dist/testing/standard.d.ts.map +0 -1
- package/dist/testing/standard.js +0 -73
- package/dist/testing/testing_rate_limiter.d.ts +0 -65
- package/dist/testing/testing_rate_limiter.d.ts.map +0 -1
- package/dist/testing/testing_rate_limiter.js +0 -80
|
@@ -21,8 +21,14 @@ import type { SupersededOffer } from './role_grant_offer_schema.js';
|
|
|
21
21
|
export declare const ROLE_GRANT_COLUMNS: readonly ["id", "actor_id", "role", "scope_kind", "scope_id", "created_at", "expires_at", "revoked_at", "revoked_by", "revoked_reason", "granted_by", "source_offer_id"];
|
|
22
22
|
/**
|
|
23
23
|
* Grant a role_grant to an actor.
|
|
24
|
-
* Idempotent — if an active
|
|
25
|
-
* scope, returns
|
|
24
|
+
* Idempotent — if an active (unrevoked and unexpired) role_grant already
|
|
25
|
+
* exists for this actor, role, and scope, returns it instead of creating a
|
|
26
|
+
* duplicate. An expired but unrevoked row in the slot is first revoked
|
|
27
|
+
* (`revoked_reason = 'expired'`, `revoked_by` null — nobody chose to revoke
|
|
28
|
+
* it) so the fresh grant can take its place; returning the expired row would
|
|
29
|
+
* report a grant that confers nothing. The revoke and the insert are two
|
|
30
|
+
* statements, atomic when the caller runs them in a transaction (the action
|
|
31
|
+
* and offer-accept paths do).
|
|
26
32
|
*
|
|
27
33
|
* The `ON CONFLICT` target and the fallback `SELECT` both collapse `NULL`
|
|
28
34
|
* scopes via the same sentinel + index-side `'GLOBAL'` token used by the
|
|
@@ -37,7 +43,7 @@ export declare const ROLE_GRANT_COLUMNS: readonly ["id", "actor_id", "role", "sc
|
|
|
37
43
|
* @param deps - query dependencies
|
|
38
44
|
* @param input - the role_grant fields
|
|
39
45
|
* @returns the created or existing active role_grant
|
|
40
|
-
* @mutates `role_grant` table -
|
|
46
|
+
* @mutates `role_grant` table - revokes an expired unrevoked row at `(actor_id, role, scope_kind, scope_id)`, then inserts a row when no active role_grant matches
|
|
41
47
|
*/
|
|
42
48
|
export declare const query_create_role_grant: (deps: QueryDeps, input: CreateRoleGrantInput) => Promise<RoleGrant>;
|
|
43
49
|
/**
|
|
@@ -50,11 +56,12 @@ export declare const query_create_role_grant: (deps: QueryDeps, input: CreateRol
|
|
|
50
56
|
*/
|
|
51
57
|
export declare const query_role_grant_by_id: (deps: QueryDeps, id: Uuid) => Promise<RoleGrant | undefined>;
|
|
52
58
|
/**
|
|
53
|
-
* Look up the role of an active role_grant (constrained to a
|
|
54
|
-
* actor) plus the actor's `account_id`.
|
|
59
|
+
* Look up the role and scope of an active role_grant (constrained to a
|
|
60
|
+
* specific actor) plus the actor's `account_id`.
|
|
55
61
|
*
|
|
56
62
|
* Used by admin routes to inspect the role_grant's role before acting
|
|
57
|
-
* (e.g., enforcing the admin-grant-path gate
|
|
63
|
+
* (e.g., enforcing the admin-grant-path gate and the global-`admin` guards on
|
|
64
|
+
* revoke). The actor constraint
|
|
58
65
|
* mirrors `query_revoke_role_grant` so IDOR protection is consistent:
|
|
59
66
|
* a caller can only see role_grants belonging to the target actor.
|
|
60
67
|
*
|
|
@@ -71,10 +78,11 @@ export declare const query_role_grant_by_id: (deps: QueryDeps, id: Uuid) => Prom
|
|
|
71
78
|
* @param deps - query dependencies
|
|
72
79
|
* @param role_grant_id - the role_grant id to look up
|
|
73
80
|
* @param actor_id - the actor that must own the role_grant
|
|
74
|
-
* @returns `{role, account_id}` on a match, or `null`
|
|
81
|
+
* @returns `{role, scope_id, account_id}` on a match, or `null`
|
|
75
82
|
*/
|
|
76
83
|
export declare const query_role_grant_find_active_role_for_actor: (deps: QueryDeps, role_grant_id: string, actor_id: string) => Promise<{
|
|
77
84
|
role: string;
|
|
85
|
+
scope_id: Uuid | null;
|
|
78
86
|
account_id: Uuid;
|
|
79
87
|
} | null>;
|
|
80
88
|
/** Result of `query_revoke_role_grant` — the revoked role_grant plus any pending offers superseded by the revoke. */
|
|
@@ -120,23 +128,11 @@ export declare const query_revoke_role_grant: (deps: QueryDeps, role_grant_id: U
|
|
|
120
128
|
* Find all active (non-revoked, non-expired) role_grants for an actor.
|
|
121
129
|
*/
|
|
122
130
|
export declare const query_role_grant_find_active_for_actor: (deps: QueryDeps, actor_id: string) => Promise<Array<RoleGrant>>;
|
|
123
|
-
/**
|
|
124
|
-
* Check if an actor has an active role_grant for a given role.
|
|
125
|
-
*
|
|
126
|
-
* The `scope_id` parameter selects between global and scoped checks:
|
|
127
|
-
* - Omitted or `null` — matches a global role_grant (`scope_id IS NULL`).
|
|
128
|
-
* Pre-scope callers keep their existing semantics.
|
|
129
|
-
* - A scope uuid — matches a role_grant bound to that exact scope.
|
|
130
|
-
*
|
|
131
|
-
* The `IS NOT DISTINCT FROM` comparison handles the NULL case uniformly.
|
|
132
|
-
*/
|
|
133
|
-
export declare const query_role_grant_has_role: (deps: QueryDeps, actor_id: string, role: string, scope_id?: string | null) => Promise<boolean>;
|
|
134
131
|
/**
|
|
135
132
|
* Account-grain check: does any actor on `account_id` hold an active
|
|
136
133
|
* global role_grant for `role`?
|
|
137
134
|
*
|
|
138
|
-
*
|
|
139
|
-
* instead of a single actor — for surfaces with `auth: actor: 'none'`
|
|
135
|
+
* Keyed on the account rather than a single actor — for surfaces with `auth: actor: 'none'`
|
|
140
136
|
* that don't load `auth.role_grants` and can't use the in-memory
|
|
141
137
|
* `has_scoped_role` predicate. Joins `role_grant` → `actor`; matches
|
|
142
138
|
* only global role_grants (`scope_id IS NULL`) since the use case is
|
|
@@ -163,7 +159,7 @@ export declare const query_account_has_global_role: (deps: QueryDeps, account_id
|
|
|
163
159
|
* Like `query_account_has_global_role`, but only counts the grant when the
|
|
164
160
|
* **account and the granting actor are both active** (`deleted_at IS NULL`).
|
|
165
161
|
* Used by the last-admin branch of the removability guard: a soft-deleted admin
|
|
166
|
-
* can't log in and is excluded from `
|
|
162
|
+
* can't log in and is excluded from `query_count_active_accounts_with_global_role_for_update`,
|
|
167
163
|
* so the guard must use the same active predicate when testing whether the
|
|
168
164
|
* *target* is an admin — otherwise removing an already-tombstoned admin is
|
|
169
165
|
* falsely blocked as `cannot_delete_last_admin`. Soft-delete does **not** revoke
|
|
@@ -183,24 +179,40 @@ export declare const query_account_has_active_global_role: (deps: QueryDeps, acc
|
|
|
183
179
|
/**
|
|
184
180
|
* Count **active** accounts (`deleted_at IS NULL`) holding an active global
|
|
185
181
|
* role_grant for `role`, counting only grants on **active actors**
|
|
186
|
-
* (`act.deleted_at IS NULL`). Used by the last-admin
|
|
187
|
-
* `
|
|
182
|
+
* (`act.deleted_at IS NULL`) — and lock what it counted. Used by the last-admin
|
|
183
|
+
* guards on `account_delete` / `account_purge` and on `role_grant_revoke` of an
|
|
184
|
+
* `admin` grant: soft-delete revokes neither a tombstoned account's nor a
|
|
188
185
|
* tombstoned actor's admin grant, so an unfiltered count would include unusable
|
|
189
186
|
* admins — this joins `account` *and* filters the actor, so an account whose
|
|
190
187
|
* only admin grant sits on a tombstoned actor no longer counts (otherwise the
|
|
191
|
-
* guard could fail-open and let the last usable admin be
|
|
188
|
+
* guard could fail-open and let the last usable admin be removed).
|
|
189
|
+
*
|
|
190
|
+
* **Locks** every counted `role_grant`, `actor`, and `account` row
|
|
191
|
+
* (`FOR UPDATE`) until the caller's transaction ends, so two guards racing to
|
|
192
|
+
* remove the last two admins serialize: the second waits for the first to
|
|
193
|
+
* commit, re-reads the rows it changed, and counts one. Run it inside the
|
|
194
|
+
* transaction that does the removal. Twin of the Rust
|
|
195
|
+
* `query_count_active_accounts_with_global_role_for_update`.
|
|
196
|
+
*
|
|
197
|
+
* `exclude_role_grant_id` leaves one grant out of the count, so a revoke asks
|
|
198
|
+
* whether any active admin account would remain without that grant — an
|
|
199
|
+
* account holding the grant on two actors keeps counting through the other.
|
|
200
|
+
* The excluded grant is still locked, so two revokes of each other's grant
|
|
201
|
+
* serialize rather than deadlock.
|
|
192
202
|
*
|
|
193
203
|
* @param deps - query dependencies
|
|
194
204
|
* @param role - the role to count (e.g. `ROLE_ADMIN`)
|
|
205
|
+
* @param exclude_role_grant_id - a grant to leave out of the count (the one being revoked)
|
|
195
206
|
* @returns the number of distinct active accounts with an active global `role` grant
|
|
207
|
+
* @mutates `role_grant` / `actor` / `account` rows - row-locks the counted rows for the transaction
|
|
196
208
|
*/
|
|
197
|
-
export declare const
|
|
209
|
+
export declare const query_count_active_accounts_with_global_role_for_update: (deps: QueryDeps, role: string, exclude_role_grant_id?: Uuid | null) => Promise<number>;
|
|
198
210
|
/**
|
|
199
|
-
*
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
*
|
|
211
|
+
* Find the account ID of an account that holds an active **global** role_grant
|
|
212
|
+
* for a given role.
|
|
213
|
+
*
|
|
214
|
+
* Global-only (`scope_id IS NULL`), like every builtin read: a scoped row of
|
|
215
|
+
* the role confers nothing, so it must not resolve the keeper identity.
|
|
204
216
|
*
|
|
205
217
|
* Joins role_grant → actor → account, counting only an **active account + active
|
|
206
218
|
* actor** (`deleted_at IS NULL` on both). This *resolves* an identity (the
|
|
@@ -257,8 +269,8 @@ export interface RevokeForScopeResult {
|
|
|
257
269
|
* orphan role_grants and offers. The cascade is **role-agnostic**: anything
|
|
258
270
|
* attached to the destroyed scope is cleaned up.
|
|
259
271
|
*
|
|
260
|
-
* Both updates run as separate statements inside the caller's transaction
|
|
261
|
-
*
|
|
272
|
+
* Both updates run as separate statements inside the caller's transaction,
|
|
273
|
+
* the `role_grant` revoke first. The two halves are
|
|
262
274
|
* independent — orphan pending offers can exist at a scope with no active
|
|
263
275
|
* role_grants, so the supersede half always runs even when no role_grant was
|
|
264
276
|
* revoked.
|
|
@@ -272,48 +284,4 @@ export interface RevokeForScopeResult {
|
|
|
272
284
|
* @mutates `role_grant_offer` table - stamps `superseded_at` on every pending row at `scope_id`
|
|
273
285
|
*/
|
|
274
286
|
export declare const query_role_grant_revoke_for_scope: (deps: QueryDeps, scope_id: Uuid, revoked_by: Uuid | null, reason?: string | null) => Promise<RevokeForScopeResult>;
|
|
275
|
-
/** Result of `query_role_grant_revoke_role` — every role_grant revoked plus the pending offers superseded by the bulk revoke. */
|
|
276
|
-
export interface RevokeRoleResult {
|
|
277
|
-
/**
|
|
278
|
-
* One entry per role_grant revoked by this call. Carries the revokee's
|
|
279
|
-
* `account_id` so callers can fan out a `role_grant_revoke` notification per
|
|
280
|
-
* scope-instance. Empty array means nothing was active for `(actor, role)`.
|
|
281
|
-
*/
|
|
282
|
-
revoked: Array<{
|
|
283
|
-
role_grant_id: string;
|
|
284
|
-
role: string;
|
|
285
|
-
scope_kind: string | null;
|
|
286
|
-
scope_id: string | null;
|
|
287
|
-
account_id: string;
|
|
288
|
-
}>;
|
|
289
|
-
/**
|
|
290
|
-
* Pending offers for the actor's account+role (all scopes) superseded by
|
|
291
|
-
* the bulk revoke. Each entry carries its grantor's `from_account_id` so
|
|
292
|
-
* callers can fan out `role_grant_offer_supersede` notifications without a
|
|
293
|
-
* second round-trip.
|
|
294
|
-
*/
|
|
295
|
-
superseded_offers: Array<SupersededOffer>;
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Revoke every active role_grant an actor holds for a given role.
|
|
299
|
-
*
|
|
300
|
-
* With scoped role_grants a single actor+role tuple can hold several active
|
|
301
|
-
* role_grants (one per scope), so this revokes all of them. Pass
|
|
302
|
-
* `query_revoke_role_grant(role_grant_id, ...)` when a single scoped role_grant
|
|
303
|
-
* is the target.
|
|
304
|
-
*
|
|
305
|
-
* Also supersedes pending offers for the actor's account across every
|
|
306
|
-
* scope of this role (the actor can no longer hold the role, so any
|
|
307
|
-
* pending offer of the same role is a bypass vector).
|
|
308
|
-
*
|
|
309
|
-
* @param deps - query dependencies
|
|
310
|
-
* @param actor_id - the actor whose role_grants to revoke
|
|
311
|
-
* @param role - the role to revoke
|
|
312
|
-
* @param revoked_by - the actor who revoked it (for audit trail)
|
|
313
|
-
* @param reason - optional free-form reason, stamped on `role_grant.revoked_reason`.
|
|
314
|
-
* @returns the list of revoked role_grants (empty if none were active) and superseded pending offers
|
|
315
|
-
* @mutates `role_grant` table - sets `revoked_at`/`revoked_by`/`revoked_reason` on every active row for `(actor, role)`
|
|
316
|
-
* @mutates `role_grant_offer` table - stamps `superseded_at` on every matching pending offer
|
|
317
|
-
*/
|
|
318
|
-
export declare const query_role_grant_revoke_role: (deps: QueryDeps, actor_id: string, role: string, revoked_by: string | null, reason?: string | null) => Promise<RevokeRoleResult>;
|
|
319
287
|
//# sourceMappingURL=role_grant_queries.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"role_grant_queries.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/role_grant_queries.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAS3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"role_grant_queries.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/role_grant_queries.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAS3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAGpE;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,0KAaoB,CAAC;AAcpD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,uBAAuB,GACnC,MAAM,SAAS,EACf,OAAO,oBAAoB,KACzB,OAAO,CAAC,SAAS,CA8CnB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,GAClC,MAAM,SAAS,EACf,IAAI,IAAI,KACN,OAAO,CAAC,SAAS,GAAG,SAAS,CAI9B,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,2CAA2C,GACvD,MAAM,SAAS,EACf,eAAe,MAAM,EACrB,UAAU,MAAM,KACd,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC;IAAC,UAAU,EAAE,IAAI,CAAA;CAAE,GAAG,IAAI,CAS1E,CAAC;AAEF,qHAAqH;AACrH,MAAM,WAAW,qBAAqB;IACrC,EAAE,EAAE,IAAI,CAAC;IACT,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC;IACtB;;;;;;;;OAQG;IACH,iBAAiB,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC;CAC1C;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,uBAAuB,GACnC,MAAM,SAAS,EACf,eAAe,IAAI,EACnB,UAAU,IAAI,EACd,YAAY,IAAI,GAAG,IAAI,EACvB,SAAS,MAAM,GAAG,IAAI,KACpB,OAAO,CAAC,qBAAqB,GAAG,IAAI,CA2CtC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sCAAsC,GAClD,MAAM,SAAS,EACf,UAAU,MAAM,KACd,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAQ1B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,6BAA6B,GACzC,MAAM,SAAS,EACf,YAAY,MAAM,EAClB,MAAM,MAAM,KACV,OAAO,CAAC,OAAO,CAYjB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,oCAAoC,GAChD,MAAM,SAAS,EACf,YAAY,MAAM,EAClB,MAAM,MAAM,KACV,OAAO,CAAC,OAAO,CAgBjB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,uDAAuD,GACnE,MAAM,SAAS,EACf,MAAM,MAAM,EACZ,wBAAuB,IAAI,GAAG,IAAW,KACvC,OAAO,CAAC,MAAM,CAuBhB,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,yCAAyC,GACrD,MAAM,SAAS,EACf,MAAM,MAAM,KACV,OAAO,CAAC,MAAM,GAAG,IAAI,CAgBvB,CAAC;AAEF,8IAA8I;AAC9I,MAAM,WAAW,oBAAoB;IACpC;;;;;;;;OAQG;IACH,OAAO,EAAE,KAAK,CAAC;QACd,aAAa,EAAE,IAAI,CAAC;QACpB,IAAI,EAAE,MAAM,CAAC;QACb,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;QAC1B,QAAQ,EAAE,IAAI,CAAC;QACf,QAAQ,EAAE,IAAI,CAAC;QACf,UAAU,EAAE,IAAI,CAAC;KACjB,CAAC,CAAC;IACH;;;;;;;;;;OAUG;IACH,iBAAiB,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC;CAC1C;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,iCAAiC,GAC7C,MAAM,SAAS,EACf,UAAU,IAAI,EACd,YAAY,IAAI,GAAG,IAAI,EACvB,SAAS,MAAM,GAAG,IAAI,KACpB,OAAO,CAAC,oBAAoB,CA0C9B,CAAC"}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import { assert_row } from '../db/assert_row.js';
|
|
10
10
|
import { columns_sql, iso8601_timestamp_expr, qualify_columns } from '../db/sql_columns.js';
|
|
11
11
|
import { ROLE_GRANT_OFFER_COLUMNS, ROLE_GRANT_OFFER_SCOPE_KIND_GLOBAL_TOKEN, ROLE_GRANT_OFFER_SCOPE_SENTINEL_UUID, ROLE_GRANT_OFFER_WITH_GRANTOR_SELECT } from './role_grant_offer_ddl.js';
|
|
12
|
+
import { offer_pending_predicate, role_grant_active_sql } from './role_grant_sql.js';
|
|
12
13
|
/**
|
|
13
14
|
* The full `role_grant` column set, named explicitly so a row read fails loud
|
|
14
15
|
* on schema drift (see `ACCOUNT_COLUMNS` in `auth/account_queries.ts` for the
|
|
@@ -44,8 +45,14 @@ const role_grant_expr = iso8601_timestamp_expr(ROLE_GRANT_COLUMNS, [
|
|
|
44
45
|
])('');
|
|
45
46
|
/**
|
|
46
47
|
* Grant a role_grant to an actor.
|
|
47
|
-
* Idempotent — if an active
|
|
48
|
-
* scope, returns
|
|
48
|
+
* Idempotent — if an active (unrevoked and unexpired) role_grant already
|
|
49
|
+
* exists for this actor, role, and scope, returns it instead of creating a
|
|
50
|
+
* duplicate. An expired but unrevoked row in the slot is first revoked
|
|
51
|
+
* (`revoked_reason = 'expired'`, `revoked_by` null — nobody chose to revoke
|
|
52
|
+
* it) so the fresh grant can take its place; returning the expired row would
|
|
53
|
+
* report a grant that confers nothing. The revoke and the insert are two
|
|
54
|
+
* statements, atomic when the caller runs them in a transaction (the action
|
|
55
|
+
* and offer-accept paths do).
|
|
49
56
|
*
|
|
50
57
|
* The `ON CONFLICT` target and the fallback `SELECT` both collapse `NULL`
|
|
51
58
|
* scopes via the same sentinel + index-side `'GLOBAL'` token used by the
|
|
@@ -60,9 +67,17 @@ const role_grant_expr = iso8601_timestamp_expr(ROLE_GRANT_COLUMNS, [
|
|
|
60
67
|
* @param deps - query dependencies
|
|
61
68
|
* @param input - the role_grant fields
|
|
62
69
|
* @returns the created or existing active role_grant
|
|
63
|
-
* @mutates `role_grant` table -
|
|
70
|
+
* @mutates `role_grant` table - revokes an expired unrevoked row at `(actor_id, role, scope_kind, scope_id)`, then inserts a row when no active role_grant matches
|
|
64
71
|
*/
|
|
65
72
|
export const query_create_role_grant = async (deps, input) => {
|
|
73
|
+
// an expired row still holds the partial unique slot (`revoked_at IS NULL`)
|
|
74
|
+
await deps.db.query(`UPDATE role_grant SET revoked_at = NOW(), revoked_by = NULL, revoked_reason = 'expired'
|
|
75
|
+
WHERE actor_id = $1
|
|
76
|
+
AND role = $2
|
|
77
|
+
AND scope_kind IS NOT DISTINCT FROM $3
|
|
78
|
+
AND scope_id IS NOT DISTINCT FROM $4
|
|
79
|
+
AND revoked_at IS NULL
|
|
80
|
+
AND expires_at <= NOW()`, [input.actor_id, input.role, input.scope_kind ?? null, input.scope_id ?? null]);
|
|
66
81
|
const inserted = await deps.db.query_one(`INSERT INTO role_grant (actor_id, role, scope_kind, scope_id, expires_at, granted_by, source_offer_id)
|
|
67
82
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
68
83
|
ON CONFLICT (
|
|
@@ -103,11 +118,12 @@ export const query_create_role_grant = async (deps, input) => {
|
|
|
103
118
|
*/
|
|
104
119
|
export const query_role_grant_by_id = async (deps, id) => deps.db.query_one(`SELECT ${columns_sql(ROLE_GRANT_COLUMNS, role_grant_expr)} FROM role_grant WHERE id = $1`, [id]);
|
|
105
120
|
/**
|
|
106
|
-
* Look up the role of an active role_grant (constrained to a
|
|
107
|
-
* actor) plus the actor's `account_id`.
|
|
121
|
+
* Look up the role and scope of an active role_grant (constrained to a
|
|
122
|
+
* specific actor) plus the actor's `account_id`.
|
|
108
123
|
*
|
|
109
124
|
* Used by admin routes to inspect the role_grant's role before acting
|
|
110
|
-
* (e.g., enforcing the admin-grant-path gate
|
|
125
|
+
* (e.g., enforcing the admin-grant-path gate and the global-`admin` guards on
|
|
126
|
+
* revoke). The actor constraint
|
|
111
127
|
* mirrors `query_revoke_role_grant` so IDOR protection is consistent:
|
|
112
128
|
* a caller can only see role_grants belonging to the target actor.
|
|
113
129
|
*
|
|
@@ -124,10 +140,10 @@ export const query_role_grant_by_id = async (deps, id) => deps.db.query_one(`SEL
|
|
|
124
140
|
* @param deps - query dependencies
|
|
125
141
|
* @param role_grant_id - the role_grant id to look up
|
|
126
142
|
* @param actor_id - the actor that must own the role_grant
|
|
127
|
-
* @returns `{role, account_id}` on a match, or `null`
|
|
143
|
+
* @returns `{role, scope_id, account_id}` on a match, or `null`
|
|
128
144
|
*/
|
|
129
145
|
export const query_role_grant_find_active_role_for_actor = async (deps, role_grant_id, actor_id) => {
|
|
130
|
-
const row = await deps.db.query_one(`SELECT role_grant.role, actor.account_id
|
|
146
|
+
const row = await deps.db.query_one(`SELECT role_grant.role, role_grant.scope_id, actor.account_id
|
|
131
147
|
FROM role_grant
|
|
132
148
|
JOIN actor ON actor.id = role_grant.actor_id
|
|
133
149
|
WHERE role_grant.id = $1 AND role_grant.actor_id = $2 AND role_grant.revoked_at IS NULL`, [role_grant_id, actor_id]);
|
|
@@ -175,10 +191,7 @@ export const query_revoke_role_grant = async (deps, role_grant_id, actor_id, rev
|
|
|
175
191
|
AND o.to_account_id = a.account_id
|
|
176
192
|
AND o.role = $2
|
|
177
193
|
AND o.scope_id IS NOT DISTINCT FROM $3
|
|
178
|
-
AND o
|
|
179
|
-
AND o.declined_at IS NULL
|
|
180
|
-
AND o.retracted_at IS NULL
|
|
181
|
-
AND o.superseded_at IS NULL
|
|
194
|
+
AND ${offer_pending_predicate('o')}
|
|
182
195
|
-- raw columns; the outer grantor select formats them
|
|
183
196
|
RETURNING ${qualify_columns(ROLE_GRANT_OFFER_COLUMNS, 'o')}
|
|
184
197
|
)
|
|
@@ -197,37 +210,14 @@ export const query_revoke_role_grant = async (deps, role_grant_id, actor_id, rev
|
|
|
197
210
|
export const query_role_grant_find_active_for_actor = async (deps, actor_id) => {
|
|
198
211
|
return deps.db.query(`SELECT ${columns_sql(ROLE_GRANT_COLUMNS, role_grant_expr)} FROM role_grant
|
|
199
212
|
WHERE actor_id = $1
|
|
200
|
-
AND
|
|
201
|
-
AND (expires_at IS NULL OR expires_at > NOW())
|
|
213
|
+
AND ${role_grant_active_sql('')}
|
|
202
214
|
ORDER BY role_grant.created_at`, [actor_id]);
|
|
203
215
|
};
|
|
204
|
-
/**
|
|
205
|
-
* Check if an actor has an active role_grant for a given role.
|
|
206
|
-
*
|
|
207
|
-
* The `scope_id` parameter selects between global and scoped checks:
|
|
208
|
-
* - Omitted or `null` — matches a global role_grant (`scope_id IS NULL`).
|
|
209
|
-
* Pre-scope callers keep their existing semantics.
|
|
210
|
-
* - A scope uuid — matches a role_grant bound to that exact scope.
|
|
211
|
-
*
|
|
212
|
-
* The `IS NOT DISTINCT FROM` comparison handles the NULL case uniformly.
|
|
213
|
-
*/
|
|
214
|
-
export const query_role_grant_has_role = async (deps, actor_id, role, scope_id) => {
|
|
215
|
-
const row = await deps.db.query_one(`SELECT EXISTS(
|
|
216
|
-
SELECT 1 FROM role_grant
|
|
217
|
-
WHERE actor_id = $1
|
|
218
|
-
AND role = $2
|
|
219
|
-
AND scope_id IS NOT DISTINCT FROM $3
|
|
220
|
-
AND revoked_at IS NULL
|
|
221
|
-
AND (expires_at IS NULL OR expires_at > NOW())
|
|
222
|
-
) AS exists`, [actor_id, role, scope_id ?? null]);
|
|
223
|
-
return row?.exists ?? false;
|
|
224
|
-
};
|
|
225
216
|
/**
|
|
226
217
|
* Account-grain check: does any actor on `account_id` hold an active
|
|
227
218
|
* global role_grant for `role`?
|
|
228
219
|
*
|
|
229
|
-
*
|
|
230
|
-
* instead of a single actor — for surfaces with `auth: actor: 'none'`
|
|
220
|
+
* Keyed on the account rather than a single actor — for surfaces with `auth: actor: 'none'`
|
|
231
221
|
* that don't load `auth.role_grants` and can't use the in-memory
|
|
232
222
|
* `has_scoped_role` predicate. Joins `role_grant` → `actor`; matches
|
|
233
223
|
* only global role_grants (`scope_id IS NULL`) since the use case is
|
|
@@ -255,8 +245,7 @@ export const query_account_has_global_role = async (deps, account_id, role) => {
|
|
|
255
245
|
WHERE actor_id IN (SELECT id FROM actor WHERE account_id = $1)
|
|
256
246
|
AND role = $2
|
|
257
247
|
AND scope_id IS NULL
|
|
258
|
-
AND
|
|
259
|
-
AND (expires_at IS NULL OR expires_at > NOW())
|
|
248
|
+
AND ${role_grant_active_sql('')}
|
|
260
249
|
) AS exists`, [account_id, role]);
|
|
261
250
|
return row?.exists ?? false;
|
|
262
251
|
};
|
|
@@ -264,7 +253,7 @@ export const query_account_has_global_role = async (deps, account_id, role) => {
|
|
|
264
253
|
* Like `query_account_has_global_role`, but only counts the grant when the
|
|
265
254
|
* **account and the granting actor are both active** (`deleted_at IS NULL`).
|
|
266
255
|
* Used by the last-admin branch of the removability guard: a soft-deleted admin
|
|
267
|
-
* can't log in and is excluded from `
|
|
256
|
+
* can't log in and is excluded from `query_count_active_accounts_with_global_role_for_update`,
|
|
268
257
|
* so the guard must use the same active predicate when testing whether the
|
|
269
258
|
* *target* is an admin — otherwise removing an already-tombstoned admin is
|
|
270
259
|
* falsely blocked as `cannot_delete_last_admin`. Soft-delete does **not** revoke
|
|
@@ -290,27 +279,46 @@ export const query_account_has_active_global_role = async (deps, account_id, rol
|
|
|
290
279
|
AND act.deleted_at IS NULL
|
|
291
280
|
AND rg.role = $2
|
|
292
281
|
AND rg.scope_id IS NULL
|
|
293
|
-
AND rg
|
|
294
|
-
AND (rg.expires_at IS NULL OR rg.expires_at > NOW())
|
|
282
|
+
AND ${role_grant_active_sql('rg')}
|
|
295
283
|
) AS exists`, [account_id, role]);
|
|
296
284
|
return row?.exists ?? false;
|
|
297
285
|
};
|
|
298
286
|
/**
|
|
299
287
|
* Count **active** accounts (`deleted_at IS NULL`) holding an active global
|
|
300
288
|
* role_grant for `role`, counting only grants on **active actors**
|
|
301
|
-
* (`act.deleted_at IS NULL`). Used by the last-admin
|
|
302
|
-
* `
|
|
289
|
+
* (`act.deleted_at IS NULL`) — and lock what it counted. Used by the last-admin
|
|
290
|
+
* guards on `account_delete` / `account_purge` and on `role_grant_revoke` of an
|
|
291
|
+
* `admin` grant: soft-delete revokes neither a tombstoned account's nor a
|
|
303
292
|
* tombstoned actor's admin grant, so an unfiltered count would include unusable
|
|
304
293
|
* admins — this joins `account` *and* filters the actor, so an account whose
|
|
305
294
|
* only admin grant sits on a tombstoned actor no longer counts (otherwise the
|
|
306
|
-
* guard could fail-open and let the last usable admin be
|
|
295
|
+
* guard could fail-open and let the last usable admin be removed).
|
|
296
|
+
*
|
|
297
|
+
* **Locks** every counted `role_grant`, `actor`, and `account` row
|
|
298
|
+
* (`FOR UPDATE`) until the caller's transaction ends, so two guards racing to
|
|
299
|
+
* remove the last two admins serialize: the second waits for the first to
|
|
300
|
+
* commit, re-reads the rows it changed, and counts one. Run it inside the
|
|
301
|
+
* transaction that does the removal. Twin of the Rust
|
|
302
|
+
* `query_count_active_accounts_with_global_role_for_update`.
|
|
303
|
+
*
|
|
304
|
+
* `exclude_role_grant_id` leaves one grant out of the count, so a revoke asks
|
|
305
|
+
* whether any active admin account would remain without that grant — an
|
|
306
|
+
* account holding the grant on two actors keeps counting through the other.
|
|
307
|
+
* The excluded grant is still locked, so two revokes of each other's grant
|
|
308
|
+
* serialize rather than deadlock.
|
|
307
309
|
*
|
|
308
310
|
* @param deps - query dependencies
|
|
309
311
|
* @param role - the role to count (e.g. `ROLE_ADMIN`)
|
|
312
|
+
* @param exclude_role_grant_id - a grant to leave out of the count (the one being revoked)
|
|
310
313
|
* @returns the number of distinct active accounts with an active global `role` grant
|
|
314
|
+
* @mutates `role_grant` / `actor` / `account` rows - row-locks the counted rows for the transaction
|
|
311
315
|
*/
|
|
312
|
-
export const
|
|
313
|
-
|
|
316
|
+
export const query_count_active_accounts_with_global_role_for_update = async (deps, role, exclude_role_grant_id = null) => {
|
|
317
|
+
// `FOR UPDATE` refuses an aggregate, so the rows come back and are counted
|
|
318
|
+
// here. The excluded grant is dropped in code, not SQL: filtering it in the
|
|
319
|
+
// WHERE would leave it unlocked, and two cross-revokes (each locking only the
|
|
320
|
+
// other's grant, then updating it) would deadlock instead of serializing
|
|
321
|
+
const rows = await deps.db.query(`SELECT a.id AS account_id, rg.id AS role_grant_id
|
|
314
322
|
FROM account a
|
|
315
323
|
JOIN actor act ON act.account_id = a.id
|
|
316
324
|
JOIN role_grant rg ON rg.actor_id = act.id
|
|
@@ -318,18 +326,21 @@ export const query_count_active_accounts_with_global_role = async (deps, role) =
|
|
|
318
326
|
AND act.deleted_at IS NULL
|
|
319
327
|
AND rg.role = $1
|
|
320
328
|
AND rg.scope_id IS NULL
|
|
321
|
-
AND rg
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
return deps.db.query(`SELECT ${columns_sql(ROLE_GRANT_COLUMNS, role_grant_expr)} FROM role_grant WHERE actor_id = $1 ORDER BY role_grant.created_at DESC`, [actor_id]);
|
|
329
|
+
AND ${role_grant_active_sql('rg')}
|
|
330
|
+
FOR UPDATE`, [role]);
|
|
331
|
+
const account_ids = new Set();
|
|
332
|
+
for (const row of rows) {
|
|
333
|
+
if (row.role_grant_id !== exclude_role_grant_id)
|
|
334
|
+
account_ids.add(row.account_id);
|
|
335
|
+
}
|
|
336
|
+
return account_ids.size;
|
|
330
337
|
};
|
|
331
338
|
/**
|
|
332
|
-
* Find the account ID of an account that holds an active role_grant
|
|
339
|
+
* Find the account ID of an account that holds an active **global** role_grant
|
|
340
|
+
* for a given role.
|
|
341
|
+
*
|
|
342
|
+
* Global-only (`scope_id IS NULL`), like every builtin read: a scoped row of
|
|
343
|
+
* the role confers nothing, so it must not resolve the keeper identity.
|
|
333
344
|
*
|
|
334
345
|
* Joins role_grant → actor → account, counting only an **active account + active
|
|
335
346
|
* actor** (`deleted_at IS NULL` on both). This *resolves* an identity (the
|
|
@@ -349,10 +360,10 @@ export const query_role_grant_find_account_id_for_role = async (deps, role) => {
|
|
|
349
360
|
JOIN actor act ON act.id = p.actor_id
|
|
350
361
|
JOIN account a ON a.id = act.account_id
|
|
351
362
|
WHERE p.role = $1
|
|
363
|
+
AND p.scope_id IS NULL
|
|
352
364
|
AND a.deleted_at IS NULL
|
|
353
365
|
AND act.deleted_at IS NULL
|
|
354
|
-
AND p
|
|
355
|
-
AND (p.expires_at IS NULL OR p.expires_at > NOW())
|
|
366
|
+
AND ${role_grant_active_sql('p')}
|
|
356
367
|
ORDER BY a.id ASC
|
|
357
368
|
LIMIT 1`, [role]);
|
|
358
369
|
return row?.account_id ?? null;
|
|
@@ -367,8 +378,8 @@ export const query_role_grant_find_account_id_for_role = async (deps, role) => {
|
|
|
367
378
|
* orphan role_grants and offers. The cascade is **role-agnostic**: anything
|
|
368
379
|
* attached to the destroyed scope is cleaned up.
|
|
369
380
|
*
|
|
370
|
-
* Both updates run as separate statements inside the caller's transaction
|
|
371
|
-
*
|
|
381
|
+
* Both updates run as separate statements inside the caller's transaction,
|
|
382
|
+
* the `role_grant` revoke first. The two halves are
|
|
372
383
|
* independent — orphan pending offers can exist at a scope with no active
|
|
373
384
|
* role_grants, so the supersede half always runs even when no role_grant was
|
|
374
385
|
* revoked.
|
|
@@ -404,66 +415,10 @@ export const query_role_grant_revoke_for_scope = async (deps, scope_id, revoked_
|
|
|
404
415
|
UPDATE role_grant_offer o
|
|
405
416
|
SET superseded_at = NOW()
|
|
406
417
|
WHERE o.scope_id = $1
|
|
407
|
-
AND o
|
|
408
|
-
AND o.declined_at IS NULL
|
|
409
|
-
AND o.retracted_at IS NULL
|
|
410
|
-
AND o.superseded_at IS NULL
|
|
418
|
+
AND ${offer_pending_predicate('o')}
|
|
411
419
|
-- raw columns; the outer grantor select formats them
|
|
412
420
|
RETURNING ${qualify_columns(ROLE_GRANT_OFFER_COLUMNS, 'o')}
|
|
413
421
|
)
|
|
414
422
|
${ROLE_GRANT_OFFER_WITH_GRANTOR_SELECT}`, [scope_id]);
|
|
415
423
|
return { revoked, superseded_offers };
|
|
416
424
|
};
|
|
417
|
-
/**
|
|
418
|
-
* Revoke every active role_grant an actor holds for a given role.
|
|
419
|
-
*
|
|
420
|
-
* With scoped role_grants a single actor+role tuple can hold several active
|
|
421
|
-
* role_grants (one per scope), so this revokes all of them. Pass
|
|
422
|
-
* `query_revoke_role_grant(role_grant_id, ...)` when a single scoped role_grant
|
|
423
|
-
* is the target.
|
|
424
|
-
*
|
|
425
|
-
* Also supersedes pending offers for the actor's account across every
|
|
426
|
-
* scope of this role (the actor can no longer hold the role, so any
|
|
427
|
-
* pending offer of the same role is a bypass vector).
|
|
428
|
-
*
|
|
429
|
-
* @param deps - query dependencies
|
|
430
|
-
* @param actor_id - the actor whose role_grants to revoke
|
|
431
|
-
* @param role - the role to revoke
|
|
432
|
-
* @param revoked_by - the actor who revoked it (for audit trail)
|
|
433
|
-
* @param reason - optional free-form reason, stamped on `role_grant.revoked_reason`.
|
|
434
|
-
* @returns the list of revoked role_grants (empty if none were active) and superseded pending offers
|
|
435
|
-
* @mutates `role_grant` table - sets `revoked_at`/`revoked_by`/`revoked_reason` on every active row for `(actor, role)`
|
|
436
|
-
* @mutates `role_grant_offer` table - stamps `superseded_at` on every matching pending offer
|
|
437
|
-
*/
|
|
438
|
-
export const query_role_grant_revoke_role = async (deps, actor_id, role, revoked_by, reason) => {
|
|
439
|
-
// CTE pulls the revokee's `account_id` via a join on `actor` so callers
|
|
440
|
-
// can address the revokee without an extra round-trip.
|
|
441
|
-
const revoked = await deps.db.query(`WITH updated AS (
|
|
442
|
-
UPDATE role_grant
|
|
443
|
-
SET revoked_at = NOW(), revoked_by = $3, revoked_reason = $4
|
|
444
|
-
WHERE actor_id = $1 AND role = $2 AND revoked_at IS NULL
|
|
445
|
-
RETURNING id, role, scope_kind, scope_id, actor_id
|
|
446
|
-
)
|
|
447
|
-
SELECT u.id AS role_grant_id, u.role, u.scope_kind, u.scope_id, a.account_id
|
|
448
|
-
FROM updated u
|
|
449
|
-
JOIN actor a ON a.id = u.actor_id`, [actor_id, role, revoked_by ?? null, reason ?? null]);
|
|
450
|
-
if (revoked.length === 0) {
|
|
451
|
-
return { revoked: [], superseded_offers: [] };
|
|
452
|
-
}
|
|
453
|
-
const superseded_offers = await deps.db.query(`WITH updated AS (
|
|
454
|
-
UPDATE role_grant_offer o
|
|
455
|
-
SET superseded_at = NOW()
|
|
456
|
-
FROM actor a
|
|
457
|
-
WHERE a.id = $1
|
|
458
|
-
AND o.to_account_id = a.account_id
|
|
459
|
-
AND o.role = $2
|
|
460
|
-
AND o.accepted_at IS NULL
|
|
461
|
-
AND o.declined_at IS NULL
|
|
462
|
-
AND o.retracted_at IS NULL
|
|
463
|
-
AND o.superseded_at IS NULL
|
|
464
|
-
-- raw columns; the outer grantor select formats them
|
|
465
|
-
RETURNING ${qualify_columns(ROLE_GRANT_OFFER_COLUMNS, 'o')}
|
|
466
|
-
)
|
|
467
|
-
${ROLE_GRANT_OFFER_WITH_GRANTOR_SELECT}`, [actor_id, role]);
|
|
468
|
-
return { revoked, superseded_offers };
|
|
469
|
-
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The liveness predicates of `role_grant` and `role_grant_offer` — one
|
|
3
|
+
* spelling each, so a new terminal state or liveness condition lands in one
|
|
4
|
+
* place instead of at every query that filters on it.
|
|
5
|
+
*
|
|
6
|
+
* Twins of the Rust spine's `role_grant_active_sql` and
|
|
7
|
+
* `offer_pending_predicate` (with its `OFFER_TERMINAL_COLUMNS`). The frozen
|
|
8
|
+
* partial-index DDL (`auth/role_grant_offer_ddl.ts`, `auth/migrations.ts`)
|
|
9
|
+
* keeps its literal predicate text, since a migration body never changes.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* The SQL predicate for an **active** role grant: not revoked and not
|
|
15
|
+
* expired.
|
|
16
|
+
*
|
|
17
|
+
* The grant row's own liveness only. Whether its holder is live — the actor
|
|
18
|
+
* and its account not soft-deleted, which doesn't revoke grants — is a join
|
|
19
|
+
* the caller adds where the read needs it.
|
|
20
|
+
*
|
|
21
|
+
* @param alias - the table alias qualifying the columns, or `''` for unqualified columns
|
|
22
|
+
* @returns the predicate, with no surrounding parentheses (it is a top-level `AND` chain)
|
|
23
|
+
*/
|
|
24
|
+
export declare const role_grant_active_sql: (alias: string) => string;
|
|
25
|
+
/**
|
|
26
|
+
* The `role_grant_offer` timestamp columns that each end an offer. An offer is
|
|
27
|
+
* pending while every one is null.
|
|
28
|
+
*/
|
|
29
|
+
export declare const OFFER_TERMINAL_COLUMNS: readonly ["accepted_at", "declined_at", "retracted_at", "superseded_at"];
|
|
30
|
+
/**
|
|
31
|
+
* The still-pending predicate for a role grant offer — every
|
|
32
|
+
* `OFFER_TERMINAL_COLUMNS` entry `IS NULL`, `AND`-joined.
|
|
33
|
+
*
|
|
34
|
+
* Expiry is not part of it: an expired offer that no sweep has terminated is
|
|
35
|
+
* still pending here, and each read that must refuse one adds its own
|
|
36
|
+
* `expires_at` condition.
|
|
37
|
+
*
|
|
38
|
+
* @param alias - the table alias qualifying the columns, or `''` for unqualified columns
|
|
39
|
+
* @returns the predicate, with no surrounding parentheses
|
|
40
|
+
*/
|
|
41
|
+
export declare const offer_pending_predicate: (alias: string) => string;
|
|
42
|
+
//# sourceMappingURL=role_grant_sql.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"role_grant_sql.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/role_grant_sql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAQH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,GAAI,OAAO,MAAM,KAAG,MAIrD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,sBAAsB,0EAKzB,CAAC;AAEX;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,GAAI,OAAO,MAAM,KAAG,MACkC,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The liveness predicates of `role_grant` and `role_grant_offer` — one
|
|
3
|
+
* spelling each, so a new terminal state or liveness condition lands in one
|
|
4
|
+
* place instead of at every query that filters on it.
|
|
5
|
+
*
|
|
6
|
+
* Twins of the Rust spine's `role_grant_active_sql` and
|
|
7
|
+
* `offer_pending_predicate` (with its `OFFER_TERMINAL_COLUMNS`). The frozen
|
|
8
|
+
* partial-index DDL (`auth/role_grant_offer_ddl.ts`, `auth/migrations.ts`)
|
|
9
|
+
* keeps its literal predicate text, since a migration body never changes.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Prefix `column` with `alias`, or leave it bare when `alias` is empty.
|
|
15
|
+
*/
|
|
16
|
+
const qualify = (alias, column) => alias === '' ? column : `${alias}.${column}`;
|
|
17
|
+
/**
|
|
18
|
+
* The SQL predicate for an **active** role grant: not revoked and not
|
|
19
|
+
* expired.
|
|
20
|
+
*
|
|
21
|
+
* The grant row's own liveness only. Whether its holder is live — the actor
|
|
22
|
+
* and its account not soft-deleted, which doesn't revoke grants — is a join
|
|
23
|
+
* the caller adds where the read needs it.
|
|
24
|
+
*
|
|
25
|
+
* @param alias - the table alias qualifying the columns, or `''` for unqualified columns
|
|
26
|
+
* @returns the predicate, with no surrounding parentheses (it is a top-level `AND` chain)
|
|
27
|
+
*/
|
|
28
|
+
export const role_grant_active_sql = (alias) => {
|
|
29
|
+
const revoked_at = qualify(alias, 'revoked_at');
|
|
30
|
+
const expires_at = qualify(alias, 'expires_at');
|
|
31
|
+
return `${revoked_at} IS NULL AND (${expires_at} IS NULL OR ${expires_at} > NOW())`;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* The `role_grant_offer` timestamp columns that each end an offer. An offer is
|
|
35
|
+
* pending while every one is null.
|
|
36
|
+
*/
|
|
37
|
+
export const OFFER_TERMINAL_COLUMNS = [
|
|
38
|
+
'accepted_at',
|
|
39
|
+
'declined_at',
|
|
40
|
+
'retracted_at',
|
|
41
|
+
'superseded_at'
|
|
42
|
+
];
|
|
43
|
+
/**
|
|
44
|
+
* The still-pending predicate for a role grant offer — every
|
|
45
|
+
* `OFFER_TERMINAL_COLUMNS` entry `IS NULL`, `AND`-joined.
|
|
46
|
+
*
|
|
47
|
+
* Expiry is not part of it: an expired offer that no sweep has terminated is
|
|
48
|
+
* still pending here, and each read that must refuse one adds its own
|
|
49
|
+
* `expires_at` condition.
|
|
50
|
+
*
|
|
51
|
+
* @param alias - the table alias qualifying the columns, or `''` for unqualified columns
|
|
52
|
+
* @returns the predicate, with no surrounding parentheses
|
|
53
|
+
*/
|
|
54
|
+
export const offer_pending_predicate = (alias) => OFFER_TERMINAL_COLUMNS.map((column) => `${qualify(alias, column)} IS NULL`).join(' AND ');
|