ui/permit_offers_state.svelte.ts

Reactive state for the consentful-permits offer flow.

Maintains one offer cache keyed by id, seeded by the RPC list/history actions and kept live by the six permit-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 / ActionPeer receiver to apply_notification.

Declarations
#

6 declarations

view source

permit_offers_state_context
#

ui/permit_offers_state.svelte.ts view source

{ get: (error_message?: string | undefined) => PermitOffersState; get_maybe: () => PermitOffersState | undefined; set: (value: PermitOffersState) => PermitOffersState; }

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

PermitOfferNotification
#

PermitOffersRpc
#

ui/permit_offers_state.svelte.ts view source

PermitOffersRpc

Narrow RPC surface consumed by PermitOffersState. 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.

list

type () => Promise<{offers: Array<PermitOfferJson>}>

history

type (options?: { limit?: number; offset?: number; }) => Promise<{offers: Array<PermitOfferJson>}>

create

type (params: { to_account_id: string; role: string; scope_id?: string | null; message?: string | null; }) => Promise<{offer: PermitOfferJson}>

accept

type (offer_id: string) => Promise<{ permit_id: string; offer: PermitOfferJson; superseded_offer_ids: Array<string>; }>

decline

type (offer_id: string, reason?: string | null) => Promise<{ok: true}>

retract

type (offer_id: string) => Promise<{ok: true}>

PermitOffersState
#

ui/permit_offers_state.svelte.ts view source

inheritance

extends:

incoming

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

type Array<PermitOfferJson>

readonly

outgoing

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

type Array<PermitOfferJson>

readonly

history

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

type Array<PermitOfferJson>

readonly

incoming_count

type number

readonly

constructor

type new (options: PermitOffersStateOptions): PermitOffersState

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; } | undefined
optional
returns Promise<void>

create

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

type (params: { to_account_id: string; role: string; scope_id?: string | null | undefined; message?: string | null | undefined; }): Promise<{ id: string & $brand<"Uuid">; from_actor_id: string & $brand<...>; ... 11 more ...; resulting_permit_id: (string & $brand<...>) | null; } | undefined>

params
type { to_account_id: string; role: string; scope_id?: string | null | undefined; message?: string | null | undefined; }
returns Promise<{ id: string & $brand<"Uuid">; from_actor_id: string & $brand<"Uuid">; to_account_id: string & $brand<"Uuid">; role: string; scope_id: (string & $brand<...>) | null; ... 8 more ...; resulting_permit_id: (string & $brand<...>) | null; } | undefined>

accept

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

type (offer_id: string): Promise<void>

offer_id
type string
returns Promise<void>

decline

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

offer_id
type string
reason?
type string | null | undefined
optional
returns Promise<void>

retract

type (offer_id: string): Promise<void>

offer_id
type string
returns Promise<void>

subscribe

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

type (subscribe_fn: PermitOfferSubscribe): () => 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: PermitOfferNotification): void

notification
returns void

reset

Clear the cache and reset loading/error state.

type (): void

returns void

PermitOffersStateOptions
#

ui/permit_offers_state.svelte.ts view source

PermitOffersStateOptions

rpc

account_id

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

type () => string | null

actor_id

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

type () => string | null

PermitOfferSubscribe
#

Depends on
#

Imported by
#