auth/role_grant_offer_notifications.ts

Role grant offer WebSocket notification specs, builders, and the narrow NotificationSender interface that decouples offer/revoke send sites from ConnectionRegistry.

These RemoteNotificationActionSpecs cover the consentful-role-grants lifecycle events the server pushes to affected accounts:

  • role_grant_offer_received → recipient's sockets when an offer is created
  • role_grant_offer_retracted → recipient's sockets when a grantor retracts
  • role_grant_offer_accepted → grantor's sockets when the recipient accepts
  • role_grant_offer_declined → grantor's sockets when the recipient declines
  • role_grant_offer_supersede → grantor's sockets when a sibling accept, a revoke of the resulting role_grant, or destruction of the parent scope row obsoletes their pending offer
  • role_grant_revoked → revokee's sockets when one of their active role_grants is revoked by the role_grant_revoke action (companion to the role_grant_revoke audit event)

Payloads are flat and normalized — RoleGrantOfferJson for the offer-lifecycle notifications (decline reason rides on offer.decline_reason, not a sibling field), and {role_grant_id, role, scope_kind, scope_id, reason} for role_grant_revoked. The revokee/grantor/recipient account id travels via the send target (the NotificationSender.send_to_account argument), not in the payload. The params schemas are @fuzdev/fuz_schema schemas.

role_grant_offer_notification_actions holds the specs as handler-less actions. to_ws_actions (actions/protocol.ts) appends them to the WS action set of an RPC list that carries the role_grant_offer actions, so the surface lists them on the WS endpoint as remote_notification methods. An inbound frame for one is still answered method_not_found, as no handler is registered. Under DEV, create_role_grant_offer_actions checks each params object it sends against its spec's input (create_validated_notification_sender); production sends unchecked.

view source

Declarations
#

28 declarations

build_role_grant_offer_accepted_notification
#

auth/role_grant_offer_notifications.ts view source

(params: { offer: { message: string | null; id: Branded<string, "Uuid">; created_at: string; expires_at: string; role: string; scope_kind: string | null; scope_id: Branded<string, "Uuid"> | null; ... 8 more ...; resulting_role_grant_id: Branded<...> | null; }; }): { ...; } & Record<...> import {build_role_grant_offer_accepted_notification} from '@fuzdev/fuz_app/auth/role_grant_offer_notifications.js';

params

returns

JsonrpcNotification

build_role_grant_offer_declined_notification
#

auth/role_grant_offer_notifications.ts view source

(params: { offer: { message: string | null; id: Branded<string, "Uuid">; created_at: string; expires_at: string; role: string; scope_kind: string | null; scope_id: Branded<string, "Uuid"> | null; ... 8 more ...; resulting_role_grant_id: Branded<...> | null; }; }): { ...; } & Record<...> import {build_role_grant_offer_declined_notification} from '@fuzdev/fuz_app/auth/role_grant_offer_notifications.js';

params

returns

JsonrpcNotification

build_role_grant_offer_received_notification
#

auth/role_grant_offer_notifications.ts view source

(params: { offer: { message: string | null; id: Branded<string, "Uuid">; created_at: string; expires_at: string; role: string; scope_kind: string | null; scope_id: Branded<string, "Uuid"> | null; ... 8 more ...; resulting_role_grant_id: Branded<...> | null; }; }): { ...; } & Record<...> import {build_role_grant_offer_received_notification} from '@fuzdev/fuz_app/auth/role_grant_offer_notifications.js';

params

returns

JsonrpcNotification

build_role_grant_offer_retracted_notification
#

auth/role_grant_offer_notifications.ts view source

(params: { offer: { message: string | null; id: Branded<string, "Uuid">; created_at: string; expires_at: string; role: string; scope_kind: string | null; scope_id: Branded<string, "Uuid"> | null; ... 8 more ...; resulting_role_grant_id: Branded<...> | null; }; }): { ...; } & Record<...> import {build_role_grant_offer_retracted_notification} from '@fuzdev/fuz_app/auth/role_grant_offer_notifications.js';

params

returns

JsonrpcNotification

build_role_grant_offer_supersede_notification
#

auth/role_grant_offer_notifications.ts view source

(params: { reason: "sibling_accepted" | "role_grant_revoked" | "scope_destroyed"; offer: { message: string | null; id: Branded<string, "Uuid">; created_at: string; expires_at: string; ... 11 more ...; resulting_role_grant_id: Branded<...> | null; }; cause_id: Branded<...>; }): { ...; } & Record<...> import {build_role_grant_offer_supersede_notification} from '@fuzdev/fuz_app/auth/role_grant_offer_notifications.js';

params

returns

JsonrpcNotification

build_role_grant_revoked_notification
#

create_validated_notification_sender
#

auth/role_grant_offer_notifications.ts view source

(sender: NotificationSender, log: Logger): NotificationSender import {create_validated_notification_sender} from '@fuzdev/fuz_app/auth/role_grant_offer_notifications.js';

Wrap a NotificationSender so that under DEV each role_grant_offer notification it sends has its params checked against its spec's input, a mismatch logged as an error the way DEV output validation logs one; the notification is sent either way, unchanged. A method that is no role_grant_offer notification passes unchecked. In production the sender is returned as it is.

sender

the sender to wrap

log

where a mismatch is logged

type Logger

returns

NotificationSender

sender in production, else a checking wrapper around it

NotificationSender
#

auth/role_grant_offer_notifications.ts view source

NotificationSender import type {NotificationSender} from '@fuzdev/fuz_app/auth/role_grant_offer_notifications.js';

Narrow structural capability for sending a JSON-RPC notification to every socket bound to an account.

ConnectionRegistry satisfies this interface — its send_to_account(account_id, message) signature accepts the broader JsonrpcMessageFromServerToClient type, which is contravariantly compatible with JsonrpcNotification here. The interface stays local so handlers don't couple to the concrete registry, and tests can inject a capturing stub with no WS machinery.

Returns the number of sockets the notification was sent to — callers typically ignore it (used by telemetry / tests).

send_to_account

type (account_id: Branded<string, "Uuid">, message: { method: string; jsonrpc: "2.0"; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>): number

account_id

type Branded

message

returns number

ROLE_GRANT_OFFER_ACCEPTED_NOTIFICATION_METHOD
#

role_grant_offer_accepted_notification_spec
#

auth/role_grant_offer_notifications.ts view source

{ method: string; kind: "remote_notification"; initiator: "backend"; auth: null; side_effects: true; input: Schema<{ offer: { message: string | null; id: Branded<string, "Uuid">; created_at: string; ... 12 more ...; resulting_role_grant_id: Branded<...> | null; }; }, { ...; }, "object", { ...; }>; output: Schema<...... import {role_grant_offer_accepted_notification_spec} from '@fuzdev/fuz_app/auth/role_grant_offer_notifications.js';

ROLE_GRANT_OFFER_DECLINED_NOTIFICATION_METHOD
#

role_grant_offer_declined_notification_spec
#

auth/role_grant_offer_notifications.ts view source

{ method: string; kind: "remote_notification"; initiator: "backend"; auth: null; side_effects: true; input: Schema<{ offer: { message: string | null; id: Branded<string, "Uuid">; created_at: string; ... 12 more ...; resulting_role_grant_id: Branded<...> | null; }; }, { ...; }, "object", { ...; }>; output: Schema<...... import {role_grant_offer_declined_notification_spec} from '@fuzdev/fuz_app/auth/role_grant_offer_notifications.js';

role_grant_offer_notification_actions
#

auth/role_grant_offer_notifications.ts view source

readonly Action<ActionSpecUnion>[]

type readonly Action<ActionSpecUnion>[]

import {role_grant_offer_notification_actions} from '@fuzdev/fuz_app/auth/role_grant_offer_notifications.js';

The role_grant_offer notifications as handler-less actions, for a WS action set: to_ws_actions (actions/protocol.ts) appends them when the RPC list carries the role_grant_offer actions, so the WS endpoint's surface lists them as remote_notification methods. With no handler they never reach dispatch, so an inbound frame for one is answered method_not_found.

role_grant_offer_notification_specs
#

auth/role_grant_offer_notifications.ts view source

EventSpec[]

type EventSpec[]

import {role_grant_offer_notification_specs} from '@fuzdev/fuz_app/auth/role_grant_offer_notifications.js';

The role_grant_offer notifications as EventSpecs, derived through create_action_event_spec. The notifications go to an account's WS sockets through NotificationSender, never over SSE, and the WS surface lists them through role_grant_offer_notification_actions; these are for a consumer that wants them as event specs, as to broadcast them on an SSE channel of its own.

ROLE_GRANT_OFFER_RECEIVED_NOTIFICATION_METHOD
#

role_grant_offer_received_notification_spec
#

auth/role_grant_offer_notifications.ts view source

{ method: string; kind: "remote_notification"; initiator: "backend"; auth: null; side_effects: true; input: Schema<{ offer: { message: string | null; id: Branded<string, "Uuid">; created_at: string; ... 12 more ...; resulting_role_grant_id: Branded<...> | null; }; }, { ...; }, "object", { ...; }>; output: Schema<...... import {role_grant_offer_received_notification_spec} from '@fuzdev/fuz_app/auth/role_grant_offer_notifications.js';

ROLE_GRANT_OFFER_RETRACTED_NOTIFICATION_METHOD
#

role_grant_offer_retracted_notification_spec
#

auth/role_grant_offer_notifications.ts view source

{ method: string; kind: "remote_notification"; initiator: "backend"; auth: null; side_effects: true; input: Schema<{ offer: { message: string | null; id: Branded<string, "Uuid">; created_at: string; ... 12 more ...; resulting_role_grant_id: Branded<...> | null; }; }, { ...; }, "object", { ...; }>; output: Schema<...... import {role_grant_offer_retracted_notification_spec} from '@fuzdev/fuz_app/auth/role_grant_offer_notifications.js';

ROLE_GRANT_OFFER_SUPERSEDE_NOTIFICATION_METHOD
#

role_grant_offer_supersede_notification_spec
#

auth/role_grant_offer_notifications.ts view source

{ method: string; kind: "remote_notification"; initiator: "backend"; auth: null; side_effects: true; input: Schema<{ reason: "sibling_accepted" | "role_grant_revoked" | "scope_destroyed"; offer: { ...; }; cause_id: Branded<...>; }, { ...; }, "object", { ...; }>; output: Schema<...>; async: true; description: string; } import {role_grant_offer_supersede_notification_spec} from '@fuzdev/fuz_app/auth/role_grant_offer_notifications.js';

ROLE_GRANT_REVOKED_NOTIFICATION_METHOD
#

role_grant_revoked_notification_spec
#

auth/role_grant_offer_notifications.ts view source

{ method: string; kind: "remote_notification"; initiator: "backend"; auth: null; side_effects: true; input: Schema<{ role: string; scope_kind: string | null; scope_id: Branded<string, "Uuid"> | null; reason: string | null; role_grant_id: Branded<...>; }, { ...; }, "object", { ...; }>; output: Schema<...>; async: tru... import {role_grant_revoked_notification_spec} from '@fuzdev/fuz_app/auth/role_grant_offer_notifications.js';

RoleGrantOfferAcceptedParams
#

auth/role_grant_offer_notifications.ts view source

value + type

{ offer: { message: string | null; id: Branded<string, "Uuid">; created_at: string; expires_at: string; role: string; scope_kind: string | null; scope_id: Branded<string, "Uuid"> | null; ... 8 more ...; resulting_role_grant_id: Branded<...> | null; }; } import {RoleGrantOfferAcceptedParams} from '@fuzdev/fuz_app/auth/role_grant_offer_notifications.js';

Params for role_grant_offer_accepted — recipient accepted the offer.

offer

type RoleGrantOfferJson

RoleGrantOfferDeclinedParams
#

auth/role_grant_offer_notifications.ts view source

value + type

{ offer: { message: string | null; id: Branded<string, "Uuid">; created_at: string; expires_at: string; role: string; scope_kind: string | null; scope_id: Branded<string, "Uuid"> | null; ... 8 more ...; resulting_role_grant_id: Branded<...> | null; }; } import {RoleGrantOfferDeclinedParams} from '@fuzdev/fuz_app/auth/role_grant_offer_notifications.js';

Params for role_grant_offer_declined. The decline reason (if any) rides along inside offer.decline_reason — the DB stamps it on the offer row during decline, so a sibling reason field would just duplicate it.

offer

type RoleGrantOfferJson

RoleGrantOfferReceivedParams
#

auth/role_grant_offer_notifications.ts view source

value + type

{ offer: { message: string | null; id: Branded<string, "Uuid">; created_at: string; expires_at: string; role: string; scope_kind: string | null; scope_id: Branded<string, "Uuid"> | null; ... 8 more ...; resulting_role_grant_id: Branded<...> | null; }; } import {RoleGrantOfferReceivedParams} from '@fuzdev/fuz_app/auth/role_grant_offer_notifications.js';

Params for role_grant_offer_received — offer delivered to its recipient.

offer

type RoleGrantOfferJson

RoleGrantOfferRetractedParams
#

auth/role_grant_offer_notifications.ts view source

value + type

{ offer: { message: string | null; id: Branded<string, "Uuid">; created_at: string; expires_at: string; role: string; scope_kind: string | null; scope_id: Branded<string, "Uuid"> | null; ... 8 more ...; resulting_role_grant_id: Branded<...> | null; }; } import {RoleGrantOfferRetractedParams} from '@fuzdev/fuz_app/auth/role_grant_offer_notifications.js';

Params for role_grant_offer_retracted — grantor-side retraction.

offer

type RoleGrantOfferJson

RoleGrantOfferSupersedeParams
#

auth/role_grant_offer_notifications.ts view source

value + type

{ reason: "sibling_accepted" | "role_grant_revoked" | "scope_destroyed"; offer: { message: string | null; id: Branded<string, "Uuid">; created_at: string; expires_at: string; ... 11 more ...; resulting_role_grant_id: Branded<...> | null; }; cause_id: Branded<...>; } import {RoleGrantOfferSupersedeParams} from '@fuzdev/fuz_app/auth/role_grant_offer_notifications.js';

Params for role_grant_offer_supersede. Fires to the grantor's sockets when their pending offer is obsoleted — either by a sibling accept (reason: 'sibling_accepted'), by revoke of the resulting role_grant or of one of the grantor's own (reason: 'role_grant_revoked'), or by deletion of the parent scope row the offer was bound to (reason: 'scope_destroyed'). cause_id points at the accepted offer id, the revoked role_grant id, or the destroyed scope row id respectively.

reason

type "sibling_accepted" | "role_grant_revoked" | "scope_destroyed"

offer

type RoleGrantOfferJson

cause_id

type Branded

RoleGrantRevokedParams
#

auth/role_grant_offer_notifications.ts view source

value + type

{ role: string; scope_kind: string | null; scope_id: Branded<string, "Uuid"> | null; reason: string | null; role_grant_id: Branded<string, "Uuid">; } import {RoleGrantRevokedParams} from '@fuzdev/fuz_app/auth/role_grant_offer_notifications.js';

Params for role_grant_revoked. Delivered to the revokee's sockets when one of their active role_grants is revoked. Flat wire shape — revoked_by is admin-UI-visible but deliberately omitted here (the revokee doesn't need to learn the admin's identity). Target account is implicit in the send target. scope_kind and scope_id are the revoked grant's pair, both null for a global grant; both keys are required.

role

type string

scope_kind

type string | null

scope_id

type Branded | null

reason

type string | null

role_grant_id

type Branded

Depends on
#

Imported by
#