@fuzdev/fuz_app 0.181.0 → 0.183.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 +2 -0
- package/dist/actions/CLAUDE.md +28 -10
- package/dist/actions/action_rpc.d.ts +11 -1
- package/dist/actions/action_rpc.d.ts.map +1 -1
- package/dist/actions/action_rpc.js +3 -2
- package/dist/actions/action_types.d.ts +16 -1
- 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 +9 -0
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +22 -13
- package/dist/actions/register_action_ws.d.ts +14 -0
- package/dist/actions/register_action_ws.d.ts.map +1 -1
- package/dist/actions/register_action_ws.js +3 -2
- 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 +2 -1
- package/dist/auth/CLAUDE.md +113 -70
- package/dist/auth/account_actions.d.ts.map +1 -1
- package/dist/auth/account_actions.js +13 -3
- package/dist/auth/account_queries.d.ts +158 -16
- package/dist/auth/account_queries.d.ts.map +1 -1
- package/dist/auth/account_queries.js +189 -18
- package/dist/auth/account_routes.d.ts +6 -4
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +98 -92
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +93 -45
- package/dist/auth/api_token_queries.d.ts +13 -5
- package/dist/auth/api_token_queries.d.ts.map +1 -1
- package/dist/auth/api_token_queries.js +24 -9
- package/dist/auth/audit_emitter.d.ts +75 -84
- package/dist/auth/audit_emitter.d.ts.map +1 -1
- package/dist/auth/audit_emitter.js +83 -71
- package/dist/auth/audit_log_schema.d.ts +10 -5
- package/dist/auth/audit_log_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_schema.js +22 -6
- package/dist/auth/bearer_auth.d.ts.map +1 -1
- package/dist/auth/bearer_auth.js +3 -2
- package/dist/auth/bootstrap_account.d.ts +31 -13
- package/dist/auth/bootstrap_account.d.ts.map +1 -1
- package/dist/auth/bootstrap_account.js +34 -15
- package/dist/auth/bootstrap_routes.d.ts +1 -1
- package/dist/auth/bootstrap_routes.d.ts.map +1 -1
- package/dist/auth/bootstrap_routes.js +7 -14
- package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.js +12 -1
- package/dist/auth/deps.d.ts +18 -5
- package/dist/auth/deps.d.ts.map +1 -1
- package/dist/auth/deps.js +3 -2
- package/dist/auth/request_context.d.ts +73 -73
- package/dist/auth/request_context.d.ts.map +1 -1
- package/dist/auth/request_context.js +78 -96
- package/dist/auth/resolved_auth.d.ts +16 -11
- package/dist/auth/resolved_auth.d.ts.map +1 -1
- package/dist/auth/resolved_auth.js +6 -6
- package/dist/auth/role_grant_offer_action_specs.d.ts +1 -1
- package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_action_specs.js +2 -1
- package/dist/auth/role_grant_offer_actions.d.ts +32 -12
- package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_actions.js +91 -116
- 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 +155 -18
- package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_queries.js +262 -73
- package/dist/auth/role_grant_offer_schema.js +1 -1
- package/dist/auth/role_grant_queries.d.ts +43 -52
- package/dist/auth/role_grant_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_queries.js +50 -74
- 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 +17 -21
- package/dist/auth/session_queries.d.ts +40 -16
- package/dist/auth/session_queries.d.ts.map +1 -1
- package/dist/auth/session_queries.js +68 -29
- package/dist/auth/signup_routes.d.ts.map +1 -1
- package/dist/auth/signup_routes.js +90 -38
- 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 +1 -1
- package/dist/auth/token_scope.js +1 -1
- package/dist/db/sql_columns.d.ts +1 -1
- package/dist/db/sql_columns.js +1 -1
- package/dist/http/CLAUDE.md +22 -16
- package/dist/http/auth_shape.d.ts +1 -1
- package/dist/http/db_routes.d.ts +7 -22
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +72 -72
- package/dist/http/error_schemas.d.ts +9 -21
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/error_schemas.js +14 -24
- package/dist/http/pending_effects.d.ts +42 -4
- package/dist/http/pending_effects.d.ts.map +1 -1
- package/dist/http/pending_effects.js +34 -4
- package/dist/http/route_spec.d.ts +2 -2
- package/dist/server/app_backend.d.ts.map +1 -1
- package/dist/server/app_backend.js +3 -1
- package/dist/server/app_server.d.ts +69 -18
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +74 -10
- package/dist/server/serve_fact_route.d.ts +3 -3
- package/dist/server/serve_fact_route.js +12 -12
- package/dist/testing/CLAUDE.md +259 -790
- package/dist/testing/adversarial_404.d.ts +6 -1
- package/dist/testing/adversarial_404.d.ts.map +1 -1
- package/dist/testing/adversarial_404.js +38 -17
- package/dist/testing/app_server.d.ts +20 -140
- package/dist/testing/app_server.d.ts.map +1 -1
- package/dist/testing/app_server.js +48 -125
- package/dist/testing/audit_drift_guard.d.ts +11 -6
- package/dist/testing/audit_drift_guard.d.ts.map +1 -1
- package/dist/testing/audit_drift_guard.js +15 -8
- package/dist/testing/auth_apps.js +1 -1
- package/dist/testing/cross_backend/account_lifecycle.d.ts.map +1 -1
- package/dist/testing/cross_backend/account_lifecycle.js +43 -0
- package/dist/testing/cross_backend/audit_cross_helpers.d.ts +12 -9
- package/dist/testing/cross_backend/audit_cross_helpers.d.ts.map +1 -1
- package/dist/testing/cross_backend/audit_cross_helpers.js +13 -14
- package/dist/testing/cross_backend/capabilities.d.ts +9 -6
- package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
- package/dist/testing/cross_backend/capabilities.js +11 -7
- package/dist/testing/cross_backend/capability_mounts.d.ts +103 -0
- package/dist/testing/cross_backend/capability_mounts.d.ts.map +1 -0
- package/dist/testing/cross_backend/capability_mounts.js +423 -0
- package/dist/testing/cross_backend/cell_moderate.js +2 -2
- package/dist/testing/cross_backend/cell_relations.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_relations.js +12 -11
- package/dist/testing/cross_backend/conformance_principal.d.ts +54 -0
- package/dist/testing/cross_backend/conformance_principal.d.ts.map +1 -0
- package/dist/testing/cross_backend/conformance_principal.js +283 -0
- package/dist/testing/cross_backend/conformance_table.d.ts +2 -50
- package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.js +2 -270
- package/dist/testing/cross_backend/credential_deadline.d.ts.map +1 -1
- package/dist/testing/cross_backend/credential_deadline.js +2 -0
- package/dist/testing/cross_backend/credential_wire.d.ts +1 -1
- package/dist/testing/cross_backend/credential_wire.d.ts.map +1 -1
- package/dist/testing/cross_backend/db_state_diff.d.ts +72 -0
- package/dist/testing/cross_backend/db_state_diff.d.ts.map +1 -0
- package/dist/testing/cross_backend/db_state_diff.js +444 -0
- package/dist/testing/cross_backend/declared_skips.d.ts +68 -0
- package/dist/testing/cross_backend/declared_skips.d.ts.map +1 -0
- package/dist/testing/cross_backend/declared_skips.js +132 -0
- 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 +2 -6
- package/dist/testing/cross_backend/differential.d.ts +11 -2
- package/dist/testing/cross_backend/differential.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential.js +35 -11
- package/dist/testing/cross_backend/differential_normalize.d.ts +12 -0
- package/dist/testing/cross_backend/differential_normalize.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential_normalize.js +16 -0
- package/dist/testing/cross_backend/full_spine_mount.d.ts +3 -10
- package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
- package/dist/testing/cross_backend/full_spine_mount.js +4 -4
- package/dist/testing/cross_backend/in_process_setup.d.ts +22 -12
- package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/in_process_setup.js +151 -134
- package/dist/testing/cross_backend/login_security.d.ts +12 -0
- package/dist/testing/cross_backend/login_security.d.ts.map +1 -1
- package/dist/testing/cross_backend/login_security.js +21 -4
- package/dist/testing/cross_backend/request_target_conformance_wire.d.ts +0 -2
- package/dist/testing/cross_backend/request_target_conformance_wire.d.ts.map +1 -1
- package/dist/testing/cross_backend/request_target_conformance_wire.js +3 -1
- package/dist/testing/cross_backend/revocation_drivers.d.ts +18 -5
- package/dist/testing/cross_backend/revocation_drivers.d.ts.map +1 -1
- package/dist/testing/cross_backend/revocation_drivers.js +18 -10
- package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts +1 -1
- package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts.map +1 -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 +33 -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 +183 -30
- package/dist/testing/cross_backend/role_grant_participation.js +4 -4
- package/dist/testing/cross_backend/rpc_adversarial.js +1 -1
- package/dist/testing/cross_backend/session_cap.d.ts +2 -2
- package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
- package/dist/testing/cross_backend/session_cap.js +48 -16
- package/dist/testing/cross_backend/setup.d.ts +31 -1
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +32 -1
- package/dist/testing/cross_backend/spine_suites.d.ts +123 -12
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +454 -57
- 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 +9 -1
- package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/sse_round_trip.js +123 -27
- package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_backdoor.js +4 -2
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +59 -27
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +66 -42
- 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 +7 -3
- package/dist/testing/cross_backend/ws_round_trip.d.ts +5 -0
- package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_round_trip.js +54 -8
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +3 -0
- package/dist/testing/db.d.ts +0 -32
- package/dist/testing/db.d.ts.map +1 -1
- package/dist/testing/db.js +0 -86
- package/dist/testing/db_entities.d.ts +14 -0
- package/dist/testing/db_entities.d.ts.map +1 -1
- package/dist/testing/db_entities.js +17 -0
- package/dist/testing/db_invariant_queries.d.ts +259 -0
- package/dist/testing/db_invariant_queries.d.ts.map +1 -0
- package/dist/testing/db_invariant_queries.js +400 -0
- package/dist/testing/db_invariants.d.ts +106 -0
- package/dist/testing/db_invariants.d.ts.map +1 -0
- package/dist/testing/db_invariants.gen.sql.d.ts +11 -0
- package/dist/testing/db_invariants.gen.sql.d.ts.map +1 -0
- package/dist/testing/db_invariants.gen.sql.js +13 -0
- package/dist/testing/db_invariants.js +141 -0
- package/dist/testing/db_invariants.sql +152 -0
- package/dist/testing/describe_db.d.ts +36 -0
- package/dist/testing/describe_db.d.ts.map +1 -0
- package/dist/testing/describe_db.js +71 -0
- package/dist/testing/integration.d.ts +6 -9
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +9 -13
- package/dist/testing/integration_helpers.d.ts +1 -1
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/middleware.d.ts +1 -1
- package/dist/testing/middleware.js +5 -5
- package/dist/testing/rate_limiting.d.ts +1 -1
- package/dist/testing/rate_limiting.d.ts.map +1 -1
- package/dist/testing/rate_limiting.js +3 -2
- 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/role_grant_helpers.d.ts +1 -1
- package/dist/testing/role_grant_helpers.d.ts.map +1 -1
- package/dist/testing/round_trip.d.ts.map +1 -1
- package/dist/testing/round_trip.js +3 -0
- package/dist/testing/rpc_attack_surface.d.ts +8 -6
- package/dist/testing/rpc_attack_surface.d.ts.map +1 -1
- package/dist/testing/rpc_attack_surface.js +69 -6
- package/dist/testing/rpc_round_trip.d.ts +1 -1
- package/dist/testing/rpc_round_trip.d.ts.map +1 -1
- package/dist/testing/rpc_round_trip.js +3 -0
- package/dist/testing/sse_round_trip.d.ts +1 -1
- package/dist/testing/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/sse_round_trip.js +13 -4
- package/dist/testing/stubs.d.ts +4 -2
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +15 -7
- package/dist/testing/test_app.d.ts +166 -0
- package/dist/testing/test_app.d.ts.map +1 -0
- package/dist/testing/test_app.js +124 -0
- 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/README.md
CHANGED
|
@@ -21,6 +21,8 @@ For more see the <a href="https://github.com/fuzdev/fuz_app/discussions">discuss
|
|
|
21
21
|
fuz_app is part of the Fuz stack
|
|
22
22
|
([fuz.dev](https://www.fuz.dev/), [@fuzdev](https://github.com/fuzdev)).
|
|
23
23
|
|
|
24
|
+
AI disclosure: this codebase is LLM-generated with uneven human review.
|
|
25
|
+
|
|
24
26
|
> ⚠️ This is a pre-alpha release, not ready for production.
|
|
25
27
|
> There are no known security vulnerabilities,
|
|
26
28
|
> and security has been \_the\_ primary focus for the initial release,
|
package/dist/actions/CLAUDE.md
CHANGED
|
@@ -179,13 +179,14 @@ and `FrontendActionHandlers`.
|
|
|
179
179
|
|
|
180
180
|
## Single JSON-RPC 2.0 endpoint (`actions/action_rpc.ts`)
|
|
181
181
|
|
|
182
|
-
`create_rpc_endpoint({path, actions, log, action_ip_rate_limiter, action_account_rate_limiter}): RouteSpec[]`
|
|
182
|
+
`create_rpc_endpoint({path, actions, log, action_ip_rate_limiter, action_account_rate_limiter, notification_sender}): RouteSpec[]`
|
|
183
183
|
produces **two** route specs on the same path (GET + POST) that share one
|
|
184
184
|
internal dispatcher. The two limiters are required `RateLimiter | null` with
|
|
185
185
|
no default — `null` is the explicit off switch — and the same holds on
|
|
186
186
|
`register_action_ws`, so a hand mount can't run
|
|
187
187
|
unthrottled by omission. `create_app_server` passes its own to every endpoint
|
|
188
|
-
it mounts (../../../docs/usage.md §Rate limiters).
|
|
188
|
+
it mounts (../../../docs/usage.md §Rate limiters). `notification_sender` is
|
|
189
|
+
required on both the same way (§Notification sender). Per-action auth lives inside the dispatcher; the outer routes
|
|
189
190
|
use `auth: {account: 'none', actor: 'none'}` and `transaction: false`.
|
|
190
191
|
|
|
191
192
|
The HTTP RPC dispatcher is a thin shim around `perform_action`
|
|
@@ -247,6 +248,7 @@ interface ActionContext {
|
|
|
247
248
|
credential_type: BuiltinCredentialType | null; // same value the credential_types gate consumed
|
|
248
249
|
log: Logger;
|
|
249
250
|
notify: (method, params) => void; // HTTP: DEV-mode warn + drop; WS: socket-scoped
|
|
251
|
+
notification_sender: NotificationSender; // every socket of an account, on every mounted registry; never null
|
|
250
252
|
signal: AbortSignal; // HTTP: client-disconnect; WS: AbortSignal.any([socket_close, request_cancel])
|
|
251
253
|
}
|
|
252
254
|
|
|
@@ -300,7 +302,8 @@ anonymous — the authorization phase reads its account, the post-authorization
|
|
|
300
302
|
gates its type and scope, `ActionContext` its type and session hash),
|
|
301
303
|
`client_ip`, `signal`, `notify`, optional `connection_id`, optional `preset`.
|
|
302
304
|
`PerformActionDeps` carries `db` (pool-level), `pending_effects`, `log`,
|
|
303
|
-
the two rate limiters
|
|
305
|
+
the two rate limiters, and `notification_sender` — put on the context, wrapped
|
|
306
|
+
under DEV in `create_validated_notification_sender` once per dispatch. Audit writes are out-of-band: factories close over
|
|
304
307
|
`AppDeps.audit` independently.
|
|
305
308
|
|
|
306
309
|
Authorization-phase resolution failures from the auth domain come back as
|
|
@@ -594,8 +597,8 @@ Fan-out, to admitted connections only, each returning how many connections
|
|
|
594
597
|
accepted the message: `broadcast(notification)` to every connection;
|
|
595
598
|
`broadcast_filtered(message, predicate)` runs per-connection ACL predicate over
|
|
596
599
|
`ConnectionIdentity`; `send_to_account` wraps `broadcast_filtered` and
|
|
597
|
-
structurally satisfies `NotificationSender` (
|
|
598
|
-
notifications). A server→client request has no broadcast form; it targets one
|
|
600
|
+
structurally satisfies `NotificationSender` (§Notification sender; the
|
|
601
|
+
role-grant-offer sends: `auth/CLAUDE.md` §WS notifications). A server→client request has no broadcast form; it targets one
|
|
599
602
|
connection (`request_connection`, below).
|
|
600
603
|
|
|
601
604
|
Server→client request/response (ActionPeer): `request_connection(connection_id,
|
|
@@ -738,10 +741,10 @@ the twin of the Rust `ConnectionCloseTarget::from_audit_event` — then calls
|
|
|
738
741
|
(`auth/audit_log_schema.ts`), and a row missing its key (an empty string
|
|
739
742
|
included) maps to nothing:
|
|
740
743
|
|
|
741
|
-
- `session` (`session_revoke`) → `{kind: 'session', session_hash: metadata.session_id}`
|
|
744
|
+
- `session` (`session_revoke`, `logout`) → `{kind: 'session', session_hash: metadata.session_id}`
|
|
742
745
|
- `token` (`token_revoke`) → `{kind: 'token', api_token_id: metadata.token_id}`
|
|
743
746
|
- `account` (`session_revoke_all`, `token_revoke_all`, `password_change`,
|
|
744
|
-
`
|
|
747
|
+
`account_delete`, `account_purge`) →
|
|
745
748
|
`{kind: 'account', account_id: target_account_id ?? account_id}`
|
|
746
749
|
- `role` (`role_grant_revoke`) → `{kind: 'role', account_id: target_account_id ??
|
|
747
750
|
account_id, role: metadata.role}` when the revoked grant was global
|
|
@@ -759,6 +762,20 @@ identifiers, and an outcome outside the enum is no revocation. Reacting to them
|
|
|
759
762
|
another user's connection by guessing a session hash or token id. Twin of the
|
|
760
763
|
Rust spine's `register_revocation_guard`.
|
|
761
764
|
|
|
765
|
+
## Notification sender (`actions/notification_sender.ts`)
|
|
766
|
+
|
|
767
|
+
`NotificationSender` (`send_to_account(account_id, message): number`, which a
|
|
768
|
+
`ConnectionRegistry` satisfies) is what a handler sends through, as
|
|
769
|
+
`ctx.notification_sender` on every `ActionContext`, so no factory takes one.
|
|
770
|
+
`AppDeps.notification_sender` is the backend's `RealtimeNotificationSender`,
|
|
771
|
+
one fan-out over every WS registry (twin of the Rust
|
|
772
|
+
`backend.notification_sender()`); `create_app_server` adds each registry it
|
|
773
|
+
mounts and removes it on `close` or a failed assembly. Both dispatchers
|
|
774
|
+
require it; a hand mount passes `backend.deps.notification_sender` (or
|
|
775
|
+
`noop_notification_sender`) and adds its own registry
|
|
776
|
+
(../../../docs/usage.md §WebSocket Endpoint). Membership and failure rules:
|
|
777
|
+
TSDoc. The role-grant-offer sends: `auth/CLAUDE.md` §WS notifications.
|
|
778
|
+
|
|
762
779
|
## WebSocket endpoints
|
|
763
780
|
|
|
764
781
|
### `create_app_server.ws_endpoints` — canonical mount surface
|
|
@@ -768,7 +785,8 @@ of `WsEndpointSpec` or a factory
|
|
|
768
785
|
`(ctx: AppServerContext) => ReadonlyArray<WsEndpointSpec>`; factory form
|
|
769
786
|
runs after server context is assembled so action lists can depend on
|
|
770
787
|
`ctx.deps` / `ctx.action_*_rate_limiter`. Each entry is auto-mounted via
|
|
771
|
-
`register_action_ws` against the assembled Hono app
|
|
788
|
+
`register_action_ws` against the assembled Hono app, and its registry added to
|
|
789
|
+
`deps.notification_sender` and `deps.connection_closer`.
|
|
772
790
|
|
|
773
791
|
`upgrade_websocket: UpgradeWebSocket` is the Hono runtime adapter's
|
|
774
792
|
module-level helper — `upgradeWebSocket` from `@hono/bun`, or from
|
|
@@ -982,8 +1000,8 @@ flush against other frames: frames on an admitted socket are not serialized
|
|
|
982
1000
|
`onMessage` — `@hono/node-server` doesn't), so a message's effects can still be
|
|
983
1001
|
in flight when the caller reads its reply and when the next message
|
|
984
1002
|
dispatches. A test that reads the audit log after a WS reply awaits
|
|
985
|
-
`_testing_drain_effects` first,
|
|
986
|
-
|
|
1003
|
+
`_testing_drain_effects` first, which awaits the emitter's in-flight writes
|
|
1004
|
+
(`src/lib/testing/CLAUDE.md`). The deferred thunks are
|
|
987
1005
|
invoked first and the eager writes awaited after, so a revocation's close never
|
|
988
1006
|
waits on a slow audit INSERT — held behind one, the socket would stay open on a
|
|
989
1007
|
credential already committed gone and dispatch its next frame. The deferred
|
|
@@ -16,6 +16,7 @@ import type { Logger } from '@fuzdev/fuz_util/log.ts';
|
|
|
16
16
|
import type { RpcAction } from './action_types.js';
|
|
17
17
|
import { type RouteSpec } from '../http/route_spec.js';
|
|
18
18
|
import type { RateLimiter } from '../rate_limiter.js';
|
|
19
|
+
import type { NotificationSender } from './notification_sender.js';
|
|
19
20
|
/**
|
|
20
21
|
* The `Cache-Control` every answer of the RPC endpoint's `GET` route carries
|
|
21
22
|
* — a read is per caller and per moment, so nothing may store it. Declared as
|
|
@@ -56,6 +57,15 @@ export interface CreateRpcEndpointOptions {
|
|
|
56
57
|
* Share one instance with the WebSocket action dispatcher.
|
|
57
58
|
*/
|
|
58
59
|
action_account_rate_limiter: RateLimiter | null;
|
|
60
|
+
/**
|
|
61
|
+
* What every handler's `ctx.notification_sender` sends through. Required,
|
|
62
|
+
* with no default, like the limiters: a sender left out would drop every
|
|
63
|
+
* notification silently. `create_app_server` passes the backend's
|
|
64
|
+
* (`AppDeps.notification_sender`), which reaches the WebSocket registries
|
|
65
|
+
* it mounts; a hand mount with no live connection to reach passes
|
|
66
|
+
* `noop_notification_sender`.
|
|
67
|
+
*/
|
|
68
|
+
notification_sender: NotificationSender;
|
|
59
69
|
}
|
|
60
70
|
/**
|
|
61
71
|
* Single JSON-RPC 2.0 endpoint — the canonical RPC transport binding.
|
|
@@ -96,7 +106,7 @@ export interface CreateRpcEndpointOptions {
|
|
|
96
106
|
* middleware's scope (`assert_credential_routes_in_auth_scope`) whether it
|
|
97
107
|
* arrives as `rpc_endpoints` or through `create_route_specs`.
|
|
98
108
|
*
|
|
99
|
-
* @param options - endpoint path, actions, logger,
|
|
109
|
+
* @param options - endpoint path, actions, logger, the two action rate limiters, and the notification sender
|
|
100
110
|
* @returns route specs (GET + POST) ready for `apply_route_specs`
|
|
101
111
|
* @throws Error if two actions share the same `spec.method` (registration-time
|
|
102
112
|
* duplicate detection); also throws if any action's `spec.input` is a null
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action_rpc.d.ts","sourceRoot":"","sources":["../../src/lib/actions/action_rpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAa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SAAS,wBAAwB,KAAG,KAAK,CAAC,SAAS,CAkOtF,CAAC"}
|
|
@@ -83,7 +83,7 @@ const envelope_response = (envelope, status) => route_raw({ status, headers: JSO
|
|
|
83
83
|
* middleware's scope (`assert_credential_routes_in_auth_scope`) whether it
|
|
84
84
|
* arrives as `rpc_endpoints` or through `create_route_specs`.
|
|
85
85
|
*
|
|
86
|
-
* @param options - endpoint path, actions, logger,
|
|
86
|
+
* @param options - endpoint path, actions, logger, the two action rate limiters, and the notification sender
|
|
87
87
|
* @returns route specs (GET + POST) ready for `apply_route_specs`
|
|
88
88
|
* @throws Error if two actions share the same `spec.method` (registration-time
|
|
89
89
|
* duplicate detection); also throws if any action's `spec.input` is a null
|
|
@@ -92,7 +92,7 @@ const envelope_response = (envelope, status) => route_raw({ status, headers: JSO
|
|
|
92
92
|
* or its `spec.output` is a void schema.
|
|
93
93
|
*/
|
|
94
94
|
export const create_rpc_endpoint = (options) => {
|
|
95
|
-
const { path: endpoint_path, actions, log, action_ip_rate_limiter, action_account_rate_limiter } = options;
|
|
95
|
+
const { path: endpoint_path, actions, log, action_ip_rate_limiter, action_account_rate_limiter, notification_sender } = options;
|
|
96
96
|
const { action_map } = compile_action_registry(actions, 'RPC action');
|
|
97
97
|
/**
|
|
98
98
|
* HTTP-shape dispatch shim — the GET/POST entry points share this:
|
|
@@ -143,6 +143,7 @@ export const create_rpc_endpoint = (options) => {
|
|
|
143
143
|
pending_effects: route.pending_effects,
|
|
144
144
|
post_commit_effects: route.post_commit_effects,
|
|
145
145
|
log,
|
|
146
|
+
notification_sender,
|
|
146
147
|
action_ip_rate_limiter,
|
|
147
148
|
action_account_rate_limiter
|
|
148
149
|
});
|
|
@@ -27,6 +27,7 @@ import type { BuiltinCredentialType } from '../auth/credential_type_schema.js';
|
|
|
27
27
|
import type { Db } from '../db/db.js';
|
|
28
28
|
import type { JsonrpcRequestId } from '../http/jsonrpc.js';
|
|
29
29
|
import type { RequestClient } from './peer_request.js';
|
|
30
|
+
import type { NotificationSender } from './notification_sender.js';
|
|
30
31
|
/**
|
|
31
32
|
* A spec paired with its optional handler — the composable unit passed to
|
|
32
33
|
* `register_action_ws` and `create_rpc_client`. The server uses both
|
|
@@ -133,6 +134,20 @@ export interface ActionContext {
|
|
|
133
134
|
* the notification method this handler is expected to emit.
|
|
134
135
|
*/
|
|
135
136
|
notify: (method: string, params: unknown) => void;
|
|
137
|
+
/**
|
|
138
|
+
* Sends a server-initiated notification to every live WebSocket connection
|
|
139
|
+
* of any account, from a handler on either transport — unlike `notify`,
|
|
140
|
+
* which reaches only the originating connection. The dispatcher supplies
|
|
141
|
+
* the backend's sender (`AppDeps.notification_sender`), which reaches
|
|
142
|
+
* every WebSocket registry the server mounts, so a send from an HTTP RPC
|
|
143
|
+
* handler reaches the account's sockets; with no WebSocket endpoint
|
|
144
|
+
* mounted it reaches no one. Queue sends after the commit
|
|
145
|
+
* (`emit_after_commit`, or `queue_offer_notification` for the role-grant
|
|
146
|
+
* notifications), never inline. Under DEV each role_grant_offer
|
|
147
|
+
* notification's params are checked against its spec
|
|
148
|
+
* (`create_validated_notification_sender`).
|
|
149
|
+
*/
|
|
150
|
+
notification_sender: NotificationSender;
|
|
136
151
|
/**
|
|
137
152
|
* AbortSignal that fires when the originating request is cancelled
|
|
138
153
|
* (client disconnect on HTTP, socket close or per-request cancel
|
|
@@ -232,7 +247,7 @@ export type HandlerForSpec<TSpec extends RequestResponseActionSpec> = HandlerFor
|
|
|
232
247
|
* runtime guarantee without a manual narrowing call.
|
|
233
248
|
*
|
|
234
249
|
* Fits fuz_app's factory-closure pattern (handlers close over
|
|
235
|
-
* `grantable_roles`, `
|
|
250
|
+
* `grantable_roles`, `connection_closer`, etc.).
|
|
236
251
|
* zzz uses a different shape — a codegen-keyed `Record<Method, Handler>`
|
|
237
252
|
* map typed via generated `ActionInputs`/`ActionOutputs` — which works when
|
|
238
253
|
* handlers are pure (no closure state) and specs are codegen-enumerated.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action_types.d.ts","sourceRoot":"","sources":["../../src/lib/actions/action_types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAE1D,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,EACX,mBAAmB,EACnB,cAAc,EACd,qBAAqB,EACrB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"action_types.d.ts","sourceRoot":"","sources":["../../src/lib/actions/action_types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAE1D,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,EACX,mBAAmB,EACnB,cAAc,EACd,qBAAqB,EACrB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACtC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E,OAAO,CAAC,GAClC,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEnC;;;;;;;;GAQG;AACH,MAAM,MAAM,cAAc,CAAC,KAAK,SAAS,yBAAyB,IAAI,cAAc,CACnF,qBAAqB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EACpC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,EACrB,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CACtB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,eAAO,MAAM,UAAU,GAAI,KAAK,SAAS,yBAAyB,EACjE,MAAM,KAAK,EACX,SAAS,cAAc,CAAC,KAAK,CAAC,KAC5B,SAGD,CAAC"}
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
* runtime guarantee without a manual narrowing call.
|
|
38
38
|
*
|
|
39
39
|
* Fits fuz_app's factory-closure pattern (handlers close over
|
|
40
|
-
* `grantable_roles`, `
|
|
40
|
+
* `grantable_roles`, `connection_closer`, etc.).
|
|
41
41
|
* zzz uses a different shape — a codegen-keyed `Record<Method, Handler>`
|
|
42
42
|
* map typed via generated `ActionInputs`/`ActionOutputs` — which works when
|
|
43
43
|
* handlers are pure (no closure state) and specs are codegen-enumerated.
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pushing a server-initiated JSON-RPC notification to an account's live
|
|
3
|
+
* WebSocket connections.
|
|
4
|
+
*
|
|
5
|
+
* **Why the handler context carries it.** A notification carries a domain
|
|
6
|
+
* payload (an offer, a revoked grant) that only the handler holds, so the
|
|
7
|
+
* handler builds the message and queues the send after its commit
|
|
8
|
+
* (`queue_offer_notification` in `auth/role_grant_offer_notifications.ts`).
|
|
9
|
+
* `perform_action` puts the sender on every `ActionContext`, so no action
|
|
10
|
+
* factory takes one and none can be wired with the wrong one: an offer
|
|
11
|
+
* created over HTTP RPC must reach the recipient's sockets on the WebSocket
|
|
12
|
+
* registry, which a sender bound to any other registry would miss silently.
|
|
13
|
+
*
|
|
14
|
+
* **Why a fan-out.** `create_app_backend` puts one
|
|
15
|
+
* `RealtimeNotificationSender` on `AppDeps.notification_sender`, and
|
|
16
|
+
* `create_app_server` adds every WebSocket connection registry it mounts.
|
|
17
|
+
* The registries are created at mount, after the RPC and WebSocket action
|
|
18
|
+
* factories run, so a sender read at send time is the only one that reaches
|
|
19
|
+
* them. A server mounting no WebSocket endpoint holds an empty fan-out, and
|
|
20
|
+
* its sends reach no one.
|
|
21
|
+
*
|
|
22
|
+
* Twin of the Rust spine's `NotificationSender` and `NoopNotificationSender`;
|
|
23
|
+
* the Rust backend serves one connection registry on every endpoint, which
|
|
24
|
+
* the fan-out stands in for.
|
|
25
|
+
*
|
|
26
|
+
* @module
|
|
27
|
+
*/
|
|
28
|
+
import type { Uuid } from '../primitive_schemas.js';
|
|
29
|
+
import type { JsonrpcNotification } from '../http/jsonrpc.js';
|
|
30
|
+
/**
|
|
31
|
+
* Send a JSON-RPC notification to every admitted socket bound to an account.
|
|
32
|
+
*
|
|
33
|
+
* `ConnectionRegistry` satisfies this structurally — its `send_to_account`
|
|
34
|
+
* accepts the broader `JsonrpcMessageFromServerToClient`. The interface
|
|
35
|
+
* stays narrow so handlers don't couple to the concrete registry and tests
|
|
36
|
+
* can capture sends with no WebSocket machinery.
|
|
37
|
+
*
|
|
38
|
+
* Returns how many sockets accepted the notification — bookkeeping, not a
|
|
39
|
+
* delivery receipt; `0` means the account has no live socket.
|
|
40
|
+
*/
|
|
41
|
+
export interface NotificationSender {
|
|
42
|
+
send_to_account: (account_id: Uuid, message: JsonrpcNotification) => number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A `NotificationSender` that sends nothing — for a hand-mounted dispatcher
|
|
46
|
+
* whose actions have no live connection to reach.
|
|
47
|
+
*/
|
|
48
|
+
export declare const noop_notification_sender: NotificationSender;
|
|
49
|
+
/**
|
|
50
|
+
* One `NotificationSender` over every WebSocket connection registry of a
|
|
51
|
+
* backend.
|
|
52
|
+
*
|
|
53
|
+
* Each send reaches every member and returns the sum, so an account with
|
|
54
|
+
* sockets on two registries hears the notification on each. A member that
|
|
55
|
+
* throws does not stop the others: every member is called, then the first
|
|
56
|
+
* error is thrown for the caller (the post-commit flush) to log.
|
|
57
|
+
*/
|
|
58
|
+
export interface RealtimeNotificationSender extends NotificationSender {
|
|
59
|
+
/**
|
|
60
|
+
* Add a registry's sender, returning a remover for this addition.
|
|
61
|
+
*
|
|
62
|
+
* Membership is by reference: a sender added twice — two endpoints sharing
|
|
63
|
+
* one registry — is one member, and every send reaches it once, so no
|
|
64
|
+
* socket hears a notification twice. Each `add` is counted, and its
|
|
65
|
+
* remover releases only that count: the sender stays a member until every
|
|
66
|
+
* addition is removed. Calling a remover again is a no-op.
|
|
67
|
+
*
|
|
68
|
+
* @param sender - the registry's sender
|
|
69
|
+
* @returns a remover for this addition, idempotent
|
|
70
|
+
*/
|
|
71
|
+
add: (sender: NotificationSender) => () => void;
|
|
72
|
+
/** Count of distinct members — introspection for tests and diagnostics. */
|
|
73
|
+
member_count: () => number;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Create an empty `RealtimeNotificationSender`.
|
|
77
|
+
*
|
|
78
|
+
* `create_app_backend` creates the one on `AppDeps.notification_sender`, and
|
|
79
|
+
* `create_app_server` adds each WebSocket connection registry it mounts,
|
|
80
|
+
* removing them when its assembly fails or the server closes.
|
|
81
|
+
*/
|
|
82
|
+
export declare const create_realtime_notification_sender: () => RealtimeNotificationSender;
|
|
83
|
+
//# sourceMappingURL=notification_sender.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification_sender.d.ts","sourceRoot":"","sources":["../../src/lib/actions/notification_sender.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE9D;;;;;;;;;;GAUG;AACH,MAAM,WAAW,kBAAkB;IAClC,eAAe,EAAE,CAAC,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,mBAAmB,KAAK,MAAM,CAAC;CAC5E;AAED;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,kBAErC,CAAC;AAEH;;;;;;;;GAQG;AACH,MAAM,WAAW,0BAA2B,SAAQ,kBAAkB;IACrE;;;;;;;;;;;OAWG;IACH,GAAG,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,MAAM,IAAI,CAAC;IAChD,2EAA2E;IAC3E,YAAY,EAAE,MAAM,MAAM,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mCAAmC,QAAO,0BAqCtD,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pushing a server-initiated JSON-RPC notification to an account's live
|
|
3
|
+
* WebSocket connections.
|
|
4
|
+
*
|
|
5
|
+
* **Why the handler context carries it.** A notification carries a domain
|
|
6
|
+
* payload (an offer, a revoked grant) that only the handler holds, so the
|
|
7
|
+
* handler builds the message and queues the send after its commit
|
|
8
|
+
* (`queue_offer_notification` in `auth/role_grant_offer_notifications.ts`).
|
|
9
|
+
* `perform_action` puts the sender on every `ActionContext`, so no action
|
|
10
|
+
* factory takes one and none can be wired with the wrong one: an offer
|
|
11
|
+
* created over HTTP RPC must reach the recipient's sockets on the WebSocket
|
|
12
|
+
* registry, which a sender bound to any other registry would miss silently.
|
|
13
|
+
*
|
|
14
|
+
* **Why a fan-out.** `create_app_backend` puts one
|
|
15
|
+
* `RealtimeNotificationSender` on `AppDeps.notification_sender`, and
|
|
16
|
+
* `create_app_server` adds every WebSocket connection registry it mounts.
|
|
17
|
+
* The registries are created at mount, after the RPC and WebSocket action
|
|
18
|
+
* factories run, so a sender read at send time is the only one that reaches
|
|
19
|
+
* them. A server mounting no WebSocket endpoint holds an empty fan-out, and
|
|
20
|
+
* its sends reach no one.
|
|
21
|
+
*
|
|
22
|
+
* Twin of the Rust spine's `NotificationSender` and `NoopNotificationSender`;
|
|
23
|
+
* the Rust backend serves one connection registry on every endpoint, which
|
|
24
|
+
* the fan-out stands in for.
|
|
25
|
+
*
|
|
26
|
+
* @module
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* A `NotificationSender` that sends nothing — for a hand-mounted dispatcher
|
|
30
|
+
* whose actions have no live connection to reach.
|
|
31
|
+
*/
|
|
32
|
+
export const noop_notification_sender = Object.freeze({
|
|
33
|
+
send_to_account: () => 0
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* Create an empty `RealtimeNotificationSender`.
|
|
37
|
+
*
|
|
38
|
+
* `create_app_backend` creates the one on `AppDeps.notification_sender`, and
|
|
39
|
+
* `create_app_server` adds each WebSocket connection registry it mounts,
|
|
40
|
+
* removing them when its assembly fails or the server closes.
|
|
41
|
+
*/
|
|
42
|
+
export const create_realtime_notification_sender = () => {
|
|
43
|
+
// member → how many additions hold it; iteration order is first addition
|
|
44
|
+
const members = new Map();
|
|
45
|
+
return Object.freeze({
|
|
46
|
+
add: (sender) => {
|
|
47
|
+
members.set(sender, (members.get(sender) ?? 0) + 1);
|
|
48
|
+
let removed = false;
|
|
49
|
+
return () => {
|
|
50
|
+
if (removed)
|
|
51
|
+
return;
|
|
52
|
+
removed = true;
|
|
53
|
+
const count = members.get(sender);
|
|
54
|
+
if (count === undefined)
|
|
55
|
+
return;
|
|
56
|
+
if (count <= 1)
|
|
57
|
+
members.delete(sender);
|
|
58
|
+
else
|
|
59
|
+
members.set(sender, count - 1);
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
member_count: () => members.size,
|
|
63
|
+
send_to_account: (account_id, message) => {
|
|
64
|
+
let count = 0;
|
|
65
|
+
let failed = false;
|
|
66
|
+
let first_error;
|
|
67
|
+
for (const member of members.keys()) {
|
|
68
|
+
try {
|
|
69
|
+
count += member.send_to_account(account_id, message);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
// keep going — one registry's failure must not keep the
|
|
73
|
+
// notification from the account's sockets on another
|
|
74
|
+
if (!failed) {
|
|
75
|
+
failed = true;
|
|
76
|
+
first_error = error;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (failed)
|
|
81
|
+
throw first_error;
|
|
82
|
+
return count;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
};
|
|
@@ -71,6 +71,7 @@ import { type JsonrpcRequestId, type JsonrpcErrorObject } from '../http/jsonrpc.
|
|
|
71
71
|
import type { RateLimiter } from '../rate_limiter.js';
|
|
72
72
|
import type { RpcAction } from './action_types.js';
|
|
73
73
|
import type { RequestClient } from './peer_request.js';
|
|
74
|
+
import type { NotificationSender } from './notification_sender.js';
|
|
74
75
|
/**
|
|
75
76
|
* Per-call inputs to `perform_action`. Each transport assembles this from
|
|
76
77
|
* its wire envelope + connection identity.
|
|
@@ -138,6 +139,14 @@ export interface PerformActionDeps {
|
|
|
138
139
|
post_commit_effects: Array<() => void | Promise<void>>;
|
|
139
140
|
/** Logger threaded into `ActionContext.log`. */
|
|
140
141
|
log: Logger;
|
|
142
|
+
/**
|
|
143
|
+
* Threaded into `ActionContext.notification_sender` — the backend's one
|
|
144
|
+
* sender on both transports, so a send from an HTTP handler reaches the
|
|
145
|
+
* WebSocket registries. Under DEV the handler gets it wrapped in
|
|
146
|
+
* `create_validated_notification_sender`, so every send site is checked
|
|
147
|
+
* as DEV output validation checks every result.
|
|
148
|
+
*/
|
|
149
|
+
notification_sender: NotificationSender;
|
|
141
150
|
/** Per-IP limiter (shared across transports). `null` disables. */
|
|
142
151
|
action_ip_rate_limiter: RateLimiter | null;
|
|
143
152
|
/** Per-account limiter (shared across transports). `null` disables. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perform_action.d.ts","sourceRoot":"","sources":["../../src/lib/actions/perform_action.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAS,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACvF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAGN,KAAK,cAAc,EACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAGN,KAAK,YAAY,EACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAOtC,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EAGvB,MAAM,oBAAoB,CAAC;AAkB5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,KAAK,EAAgC,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACjF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"perform_action.d.ts","sourceRoot":"","sources":["../../src/lib/actions/perform_action.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAS,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACvF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAGN,KAAK,cAAc,EACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAGN,KAAK,YAAY,EACjB,MAAM,0BAA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error_messages, jsonrpc_error_code_to_http_status, http_status_to_jsonrpc_error_code, JSONRPC_ERROR_CODES, dev_only, to_thrown_jsonrpc_error } from '../http/jsonrpc_errors.js';
|
|
77
77
|
import { ERROR_AUTHENTICATION_REQUIRED, ERROR_INSUFFICIENT_PERMISSIONS, ERROR_CREDENTIAL_TYPE_REQUIRED, ERROR_PARAMS_NUL, ERROR_PARAMS_PROTO_KEY, ERROR_TOKEN_SCOPE_REQUIRED } from '../http/error_schemas.js';
|
|
78
78
|
import { is_public_auth, needs_actor, parse_acting } from '../http/auth_shape.js';
|
|
79
|
+
import { create_validated_notification_sender } from '../auth/role_grant_offer_notifications.js';
|
|
79
80
|
import { token_scope_admits_method, token_scope_method_capability } from '../auth/token_scope.js';
|
|
80
81
|
/**
|
|
81
82
|
* The shared dispatch core. Pure data — no Hono context, no socket. Each
|
|
@@ -89,12 +90,12 @@ import { token_scope_admits_method, token_scope_method_capability } from '../aut
|
|
|
89
90
|
*/
|
|
90
91
|
export const perform_action = async (input, deps) => {
|
|
91
92
|
const { action, raw_params, request_id: id, credential, client_ip, signal, notify, connection_id, request_client, preset } = input;
|
|
92
|
-
const { db, pending_effects, post_commit_effects, log, action_ip_rate_limiter, action_account_rate_limiter } = deps;
|
|
93
|
+
const { db, pending_effects, post_commit_effects, log, notification_sender, action_ip_rate_limiter, action_account_rate_limiter } = deps;
|
|
93
94
|
const { spec, handler } = action;
|
|
94
95
|
const action_auth = spec.auth;
|
|
95
|
-
const
|
|
96
|
+
const account = credential?.account ?? null;
|
|
96
97
|
// step 1: pre-authorization auth — 401 short-circuit.
|
|
97
|
-
const pre = check_action_auth_pre_authorization(action_auth,
|
|
98
|
+
const pre = check_action_auth_pre_authorization(action_auth, account?.id ?? null);
|
|
98
99
|
if (pre)
|
|
99
100
|
return error_result(pre);
|
|
100
101
|
// step 2: authorization phase. `acting` reads off the raw params rather
|
|
@@ -114,12 +115,16 @@ export const perform_action = async (input, deps) => {
|
|
|
114
115
|
// dispatcher does.
|
|
115
116
|
let result;
|
|
116
117
|
try {
|
|
117
|
-
result = await apply_authorization_phase({ db },
|
|
118
|
+
result = await apply_authorization_phase({ db }, account, action_auth, read_acting(action_auth, raw_params));
|
|
118
119
|
}
|
|
119
120
|
catch (err) {
|
|
120
121
|
return thrown_error_result(err, `authorization phase error: ${spec.method}`, log);
|
|
121
122
|
}
|
|
122
123
|
if (!result.ok) {
|
|
124
|
+
// an account removed since its credential was read: the dead
|
|
125
|
+
// credential's 401, as the pre-authorization gate answers it
|
|
126
|
+
if (result.status === 401)
|
|
127
|
+
return error_result(unauthenticated_error());
|
|
123
128
|
const { error: reason, ...rest } = result.body;
|
|
124
129
|
const code = http_status_to_jsonrpc_error_code(result.status);
|
|
125
130
|
return {
|
|
@@ -212,6 +217,7 @@ export const perform_action = async (input, deps) => {
|
|
|
212
217
|
session_hash: resolved_auth_session_hash(credential),
|
|
213
218
|
log,
|
|
214
219
|
notify,
|
|
220
|
+
notification_sender: create_validated_notification_sender(notification_sender, log),
|
|
215
221
|
signal
|
|
216
222
|
};
|
|
217
223
|
const output = await handler(validated_input, action_context);
|
|
@@ -321,18 +327,21 @@ const read_acting = (auth, raw_params) => {
|
|
|
321
327
|
*/
|
|
322
328
|
const check_action_auth_pre_authorization = (auth, account_id) => {
|
|
323
329
|
if (auth.account === 'required' || auth.actor === 'required') {
|
|
324
|
-
if (account_id == null)
|
|
325
|
-
|
|
326
|
-
// credential / role gates) so a 401 can be asserted on reason, not
|
|
327
|
-
// just status. The reason is generic — it leaks nothing about
|
|
328
|
-
// whether a credential was present or what the route demanded.
|
|
329
|
-
return jsonrpc_error_messages.unauthenticated('unauthenticated', {
|
|
330
|
-
reason: ERROR_AUTHENTICATION_REQUIRED
|
|
331
|
-
});
|
|
332
|
-
}
|
|
330
|
+
if (account_id == null)
|
|
331
|
+
return unauthenticated_error();
|
|
333
332
|
}
|
|
334
333
|
return null;
|
|
335
334
|
};
|
|
335
|
+
/**
|
|
336
|
+
* The dead or missing credential's 401. Carries the reason on
|
|
337
|
+
* `error.data.reason` (symmetric with the 403 credential / role gates) so a
|
|
338
|
+
* 401 can be asserted on reason, not just status. The reason is generic — it
|
|
339
|
+
* leaks nothing about whether a credential was present or what the route
|
|
340
|
+
* demanded.
|
|
341
|
+
*/
|
|
342
|
+
const unauthenticated_error = () => jsonrpc_error_messages.unauthenticated('unauthenticated', {
|
|
343
|
+
reason: ERROR_AUTHENTICATION_REQUIRED
|
|
344
|
+
});
|
|
336
345
|
/**
|
|
337
346
|
* The credential-type 403 — one builder, so the dispatcher's gate below and a
|
|
338
347
|
* handler that gates a credential channel on its input (`account_delete`'s
|
|
@@ -65,6 +65,7 @@ import { type Logger as LoggerType } from '@fuzdev/fuz_util/log.ts';
|
|
|
65
65
|
import type { RoleName } from '../auth/role_schema.js';
|
|
66
66
|
import type { EffectErrorContext } from '../http/pending_effects.js';
|
|
67
67
|
import type { RateLimiter } from '../rate_limiter.js';
|
|
68
|
+
import type { NotificationSender } from './notification_sender.js';
|
|
68
69
|
import type { Db } from '../db/db.js';
|
|
69
70
|
import { type Action } from './action_types.js';
|
|
70
71
|
import type { RealtimeCloser } from './connection_closer.js';
|
|
@@ -252,6 +253,19 @@ export interface RegisterActionWsOptions {
|
|
|
252
253
|
* dispatcher.
|
|
253
254
|
*/
|
|
254
255
|
action_account_rate_limiter: RateLimiter | null;
|
|
256
|
+
/**
|
|
257
|
+
* What every handler's `ctx.notification_sender` sends through — the
|
|
258
|
+
* backend's (`AppDeps.notification_sender`), the one `create_app_server`
|
|
259
|
+
* passes, so a frame's action notifies sockets on every registry the
|
|
260
|
+
* backend mounts, not just this endpoint's. Required, with no default: a
|
|
261
|
+
* sender left out would drop every notification silently. Unlike
|
|
262
|
+
* `connection_closer`, it is only sent through: this endpoint's registry
|
|
263
|
+
* joins the backend's sender when `create_app_server` adds it, so a hand
|
|
264
|
+
* mount over that sender adds the returned registry itself
|
|
265
|
+
* (`RealtimeNotificationSender.add`). A harness with one registry passes
|
|
266
|
+
* that registry; `noop_notification_sender` sends nothing.
|
|
267
|
+
*/
|
|
268
|
+
notification_sender: NotificationSender;
|
|
255
269
|
/**
|
|
256
270
|
* Called when an eager pending effect of a frame's action rejects, after
|
|
257
271
|
* the rejection is logged — the WS half of `create_app_server`'s
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register_action_ws.d.ts","sourceRoot":"","sources":["../../src/lib/actions/register_action_ws.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAU,KAAK,MAAM,IAAI,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAS5E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAOvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"register_action_ws.d.ts","sourceRoot":"","sources":["../../src/lib/actions/register_action_ws.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAU,KAAK,MAAM,IAAI,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAS5E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAOvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,M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,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC;;;;;;;;;;;;;;;;OAgBG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,qDAAqD;IACrD,GAAG,CAAC,EAAE,UAAU,CAAC;IACjB;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,iBAAiB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClE;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE,kBAAkB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE;;;;;;;;OAQG;IACH,sBAAsB,EAAE,WAAW,GAAG,IAAI,CAAC;IAC3C;;;;;;OAMG;IACH,2BAA2B,EAAE,WAAW,GAAG,IAAI,CAAC;IAChD;;;;;;;;;;;OAWG;IACH,mBAAmB,EAAE,kBAAkB,CAAC;IACxC;;;;;OAKG;IACH,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,kBAAkB,KAAK,IAAI,CAAC;CACxE;AAED,sCAAsC;AACtC,MAAM,WAAW,sBAAsB;IACtC,wEAAwE;IACxE,QAAQ,EAAE,kBAAkB,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,uBAAuB,KAAG,sBAuLrE,CAAC"}
|
|
@@ -153,7 +153,7 @@ export const register_action_ws = (options) => {
|
|
|
153
153
|
throw new Error(`register_action_ws: outbound_queue_bytes configures the registry created for ${options.path}, ` +
|
|
154
154
|
'but a registry was supplied — set the budget on that ConnectionRegistry instead');
|
|
155
155
|
}
|
|
156
|
-
const { path, app, upgradeWebSocket, actions, db, receive_timeout = DEFAULT_WS_RECEIVE_TIMEOUT, allowed_origins, max_message_bytes = DEFAULT_WS_MAX_MESSAGE_BYTES, log = new Logger('[ws]'), on_socket_open, on_socket_close, action_ip_rate_limiter, action_account_rate_limiter, on_effect_error, required_roles = [] } = options;
|
|
156
|
+
const { path, app, upgradeWebSocket, actions, db, receive_timeout = DEFAULT_WS_RECEIVE_TIMEOUT, allowed_origins, max_message_bytes = DEFAULT_WS_MAX_MESSAGE_BYTES, log = new Logger('[ws]'), on_socket_open, on_socket_close, action_ip_rate_limiter, action_account_rate_limiter, notification_sender, on_effect_error, required_roles = [] } = options;
|
|
157
157
|
const registry = options.registry ??
|
|
158
158
|
new ConnectionRegistry({
|
|
159
159
|
max_connections_per_account: options.max_connections_per_account,
|
|
@@ -202,6 +202,7 @@ export const register_action_ws = (options) => {
|
|
|
202
202
|
on_socket_close,
|
|
203
203
|
action_ip_rate_limiter,
|
|
204
204
|
action_account_rate_limiter,
|
|
205
|
+
notification_sender,
|
|
205
206
|
on_effect_error,
|
|
206
207
|
required_roles
|
|
207
208
|
};
|
|
@@ -249,7 +250,7 @@ export const register_action_ws = (options) => {
|
|
|
249
250
|
if (resolved === null) {
|
|
250
251
|
throw new Error(`register_action_ws: no resolved credential for the upgrade on ${path} — is the auth middleware wired?`);
|
|
251
252
|
}
|
|
252
|
-
if (resolved.
|
|
253
|
+
if (resolved.account.id !== upgrade_context.account.id) {
|
|
253
254
|
throw new Error(`register_action_ws: the credential and the request context name different accounts for the upgrade on ${path}`);
|
|
254
255
|
}
|
|
255
256
|
// Test escape hatch — captured once at upgrade. perform_action
|
|
@@ -115,6 +115,7 @@ import type { RoleName } from '../auth/role_schema.js';
|
|
|
115
115
|
import { type ResolvedAuth } from '../auth/resolved_auth.js';
|
|
116
116
|
import { type EffectErrorContext } from '../http/pending_effects.js';
|
|
117
117
|
import type { RateLimiter } from '../rate_limiter.js';
|
|
118
|
+
import type { NotificationSender } from './notification_sender.js';
|
|
118
119
|
import type { Db } from '../db/db.js';
|
|
119
120
|
import type { RpcAction } from './action_types.js';
|
|
120
121
|
import type { ConnectionRegistry, ConnectionIdentity } from './connection_registry.js';
|
|
@@ -279,6 +280,8 @@ export interface WsSocketEndpoint {
|
|
|
279
280
|
action_ip_rate_limiter: RateLimiter | null;
|
|
280
281
|
/** Per-account action rate limiter; `null` turns the account check off. */
|
|
281
282
|
action_account_rate_limiter: RateLimiter | null;
|
|
283
|
+
/** What every handler's `ctx.notification_sender` sends through. */
|
|
284
|
+
notification_sender: NotificationSender;
|
|
282
285
|
/** Called when an eager pending effect of a frame's action rejects; `undefined` for none. */
|
|
283
286
|
on_effect_error: ((error: unknown, context: EffectErrorContext) => void) | undefined;
|
|
284
287
|
/** Roles the endpoint's upgrade is gated on; empty for an ungated endpoint. */
|