ui/role_grant_offers_state.svelte.ts

Reactive state for the consentful-role-grants offer flow.

Maintains one offer cache keyed by id, seeded by the RPC list/history actions and kept live by the role-grant-offer WebSocket notifications. incoming (recipient-side pending) and outgoing (grantor-side pending) are derived views; history is the full cache ordered newest-first for the grantor/admin history view.

Wiring is transport-agnostic: the ctor accepts a narrow RPC interface the consumer adapts from their typed client, plus an account_id / actor_id getter pair (typically bound to auth_state). Notification delivery is pull-only via subscribe() — the consumer plumbs their FrontendWebsocketClient / ActionDispatcher receiver to apply_notification.

Holds one slot per RPC verb: AsyncSlots for list, list_history and create, and KeyedAsyncSlots keyed by offer id for the per-row verbs accept, decline and retract, so each row carries its own pending state and error. The cache #offers lives on the class (multiple ops write into it via #merge_offers / #remove_offer); the create slot is typed AsyncSlot<RoleGrantOfferJson> so submit_create can return the new offer via the slot's supersession-safe data path, but the other slots' data is unused (no single op owns the cache). Each terminal verb stamps the offer it answers into the cache, so history shows it whether or not its WS notification arrives. Method names use the submit_* prefix to avoid slot-name collisions; the history view stayed natural by naming the fetch slot list_history.

view source

Declarations
#

8 declarations

role_grant_offers_state_context
#

ui/role_grant_offers_state.svelte.ts view source

{ get: (error_message?: string | undefined) => RoleGrantOffersState; get_maybe: () => RoleGrantOffersState | undefined; set: (value: RoleGrantOffersState) => RoleGrantOffersState; } import {role_grant_offers_state_context} from '@fuzdev/fuz_app/ui/role_grant_offers_state.svelte.js';

Svelte context for RoleGrantOffersState. Use role_grant_offers_state_context.set(state) in the provider and role_grant_offers_state_context.get() to access.

RoleGrantOfferCreateParams
#

ui/role_grant_offers_state.svelte.ts view source

RoleGrantOfferCreateParams

type (Omit<RoleGrantOfferCreateInput, "scope_kind" | "scope_id"> & { scope_kind?: null | undefined; scope_id?: null | undefined; }) | (Omit<RoleGrantOfferCreateInput, "scope_kind" | "scope_id"> & { scope_kind: string; scope_id: Branded<string, "Uuid">; })

import type {RoleGrantOfferCreateParams} from '@fuzdev/fuz_app/ui/role_grant_offers_state.svelte.js';

Params for submit_create — RoleGrantOfferCreateInput with its scope as the paired RoleGrantOfferScope, so a lone scope_id is a type error.

RoleGrantOfferNotification
#

RoleGrantOfferScope
#

ui/role_grant_offers_state.svelte.ts view source

RoleGrantOfferScope

type { scope_kind?: null | undefined; scope_id?: null | undefined; } | { scope_kind: string; scope_id: Branded<string, "Uuid">; }

import type {RoleGrantOfferScope} from '@fuzdev/fuz_app/ui/role_grant_offers_state.svelte.js';

The scope of an offer: global (both absent / null) or scoped (both set). scope_kind and scope_id are paired on the wire — a lone scope_id is an invalid_params refusal — so the pair is one union rather than two optional fields.

RoleGrantOffersRpc
#

ui/role_grant_offers_state.svelte.ts view source

RoleGrantOffersRpc import type {RoleGrantOffersRpc} from '@fuzdev/fuz_app/ui/role_grant_offers_state.svelte.js';

Narrow RPC surface consumed by RoleGrantOffersState. Consumers adapt their typed client (e.g. a create_rpc_client Proxy) to this shape — the state class stays decoupled from the client's Result return type so tests can inject plain-function stubs. Each method takes its action's input as one params object and returns its output, both typed from the action specs, so the typed throwing client's methods bridge with no casts.

list

type (params?: { account_id?: Branded<string, "Uuid"> | null | undefined; acting?: Branded<string, "Uuid"> | undefined; } | undefined): Promise<{ offers: { id: Branded<string, "Uuid">; ... 14 more ...; resulting_role_grant_id: Branded<...> | null; }[]; }>

params?

optional
returns Promise<RoleGrantOfferListOutput>

history

type (params?: { account_id?: Branded<string, "Uuid"> | null | undefined; limit?: number | null | undefined; offset?: number | null | undefined; acting?: Branded<string, "Uuid"> | undefined; } | undefined): Promise<...>

params?

optional

create

type (params: { to_account_id: Branded<string, "Uuid">; role: string; to_actor_id?: Branded<string, "Uuid"> | null | undefined; scope_kind?: string | null | undefined; scope_id?: Branded<...> | ... 1 more ... | undefined; message?: string | ... 1 more ... | undefined; acting?: Branded<...> | undefined; }): Promise<...>

params

accept

type (params: { offer_id: Branded<string, "Uuid">; acting?: Branded<string, "Uuid"> | undefined; }): Promise<{ role_grant_id: Branded<string, "Uuid">; offer: { ...; }; superseded_offer_ids: Branded<...>[]; }>

params

decline

type (params: { offer_id: Branded<string, "Uuid">; reason?: string | null | undefined; acting?: Branded<string, "Uuid"> | undefined; }): Promise<{ offer: { id: Branded<string, "Uuid">; ... 14 more ...; resulting_role_grant_id: Branded<...> | null; }; }>

params

retract

type (params: { offer_id: Branded<string, "Uuid">; acting?: Branded<string, "Uuid"> | undefined; }): Promise<{ offer: { id: Branded<string, "Uuid">; from_actor_id: Branded<...>; ... 13 more ...; resulting_role_grant_id: Branded<...> | null; }; }>

params

RoleGrantOffersState
#

ui/role_grant_offers_state.svelte.ts view source

import {RoleGrantOffersState} from '@fuzdev/fuz_app/ui/role_grant_offers_state.svelte.js';

list

type AsyncSlot<void, string>

readonly

list_history

type AsyncSlot<void, string>

readonly

create

type AsyncSlot<RoleGrantOfferJson, string>

readonly

accept

Per-offer accept, keyed by offer id.

type KeyedAsyncSlot<string, void, string>

readonly

decline

Per-offer decline, keyed by offer id.

type KeyedAsyncSlot<string, void, string>

readonly

retract

Per-offer retract, keyed by offer id.

type KeyedAsyncSlot<string, void, string>

readonly

incoming

Pending offers for the current account, soonest-expiring first.

type RoleGrantOfferJson[]

readonly $derived.by

outgoing

Pending offers from the current actor, newest-created first.

type RoleGrantOfferJson[]

readonly $derived.by

history

Every offer known to this state, newest-created first. Feeds the history view.

type RoleGrantOfferJson[]

readonly $derived.by

incoming_count

type number

readonly $derived

constructor

type new (options: RoleGrantOffersStateOptions): RoleGrantOffersState

options

fetch

Seed the cache with the recipient-side pending inbox.

type (): Promise<void>

returns Promise<void>

fetch_history

Seed both-directions history (includes terminal rows).

type (options?: { limit?: number | undefined; offset?: number | undefined; } | undefined): Promise<void>

options?

type { limit?: number | undefined; offset?: number | undefined; }
optional
returns Promise<void>

submit_create

Issue a new offer; merges the returned offer into the cache on success.

to_actor_id (optional) narrows the offer to a specific actor on to_account_id; omit / null for the account-grain default (any actor on the recipient account may accept). A scoped offer passes scope_kind and scope_id together; an unpaired scope (reachable from untyped callers) fails with GRANT_SCOPE_PAIRED_MESSAGE without an RPC.

type (params: RoleGrantOfferCreateParams): Promise<{ id: Branded<string, "Uuid">; from_actor_id: Branded<string, "Uuid">; to_account_id: Branded<...>; ... 12 more ...; resulting_role_grant_id: Branded<...> | null; } | undefined>

params

returns Promise<RoleGrantOfferJson | undefined>

submit_accept

Accept an offer; stamps it terminal in the cache and drops any siblings the server superseded.

type (offer_id: Branded<string, "Uuid">): Promise<void>

offer_id

type Branded
returns Promise<void>

submit_decline

Decline an offer; stamps the declined offer the server returns into the cache.

type (offer_id: Branded<string, "Uuid">, reason?: string | null | undefined): Promise<void>

offer_id

type Branded

reason?

type string | null
optional
returns Promise<void>

submit_retract

Retract an offer; stamps the retracted offer the server returns into the cache.

type (offer_id: Branded<string, "Uuid">): Promise<void>

offer_id

type Branded
returns Promise<void>

subscribe

Wire a notification subscription. The handler dispatches each matching notification into apply_notification; the returned disposer unwires.

type (subscribe_fn: RoleGrantOfferSubscribe): () => void

subscribe_fn

returns () => void

apply_notification

Reduce a single WS notification into the cache. Exposed so consumers wiring their WS receiver directly (without subscribe) and tests can drive the reducer without allocating a subscription.

type (notification: RoleGrantOfferNotification): void

notification

returns void

mutates

  • this

reset

Clear the cache and reset every slot.

type (): void

returns void

RoleGrantOffersStateOptions
#

ui/role_grant_offers_state.svelte.ts view source

RoleGrantOffersStateOptions import type {RoleGrantOffersStateOptions} from '@fuzdev/fuz_app/ui/role_grant_offers_state.svelte.js';

rpc

type RoleGrantOffersRpc

account_id

Reactive accessor for the current account id; returns null when logged out.

type (): string | null

returns string | null

actor_id

Reactive accessor for the current actor id — required to classify offers as outgoing. Returns null when unknown.

type (): string | null

returns string | null

RoleGrantOfferSubscribe
#

ui/role_grant_offers_state.svelte.ts view source

RoleGrantOfferSubscribe import type {RoleGrantOfferSubscribe} from '@fuzdev/fuz_app/ui/role_grant_offers_state.svelte.js';

Subscription primitive — consumer wires their WS receiver; returns a disposer.

(call)

type (handler: (notification: RoleGrantOfferNotification) => void): () => void

handler

type (notification: RoleGrantOfferNotification) => void
returns () => void

Depends on
#

Imported by
#