ui/admin_accounts_state.svelte.ts

Reactive state for admin account management.

Holds one fetch AsyncSlot (list) plus three KeyedAsyncSlots — grant (offer creation, keyed by account_id:role or account_id:role:to_actor_id), revoke (role_grant revoke, keyed by role_grant_id), retract (offer retraction, keyed by offer_id). Per-row supersession is correct (clicking row B no longer aborts row A) and error(key) surfaces failure per-row. Method names use the submit_* prefix to avoid slot-name collisions.

view source

Declarations
#

6 declarations

admin_accounts_rpc_context
#

ui/admin_accounts_state.svelte.ts view source

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

Svelte context carrying the reactive AdminAccountsRpc accessor. The provisioner (typically the admin route shell) calls set(() => rpc); consumers read with const get_rpc = admin_accounts_rpc_context.get(); and either pass the accessor straight to AdminAccountsState/ AdminSessionsState or wrap it with const rpc = $derived(get_rpc()); for direct RPC calls. get() throws when no provisioner ran above the component — the adapter is required, not optional.

AdminAccountsRpc
#

ui/admin_accounts_state.svelte.ts view source

AdminAccountsRpc import type {AdminAccountsRpc} from '@fuzdev/fuz_app/ui/admin_accounts_state.svelte.js';

Narrow RPC surface consumed by AdminAccountsState. Consumers adapt their typed RPC 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. Mirrors the RoleGrantOffersRpc pattern.

Every operation flows through RPC: the listing reuses admin_account_list, grant reuses role_grant_offer_create, revoke and retract have dedicated actions, and the session / token revoke-all mutations reuse admin_session_revoke_all and admin_token_revoke_all.

Every method takes its action's input as one params object, typed from the action specs (or nothing, for an input-less listing) — Uuid-branded ids propagate from the wire through the state class to the components. The adapter built by create_admin_rpc_adapters therefore needs zero casts to bridge to the typed throwing Proxy. delete_account is the one narrowing: account_delete's input defaults to {}, which deletes the caller, so the adapter requires account_id as a Uuid — never omitted, never null.

list_accounts

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

params?

optional
returns Promise<AdminAccountListOutput>

delete_account

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

params

type AccountDeleteInput & { account_id: Branded<string, "Uuid">; }
returns Promise<AccountDeleteOutput>

undelete_account

type (params: { account_id: Branded<string, "Uuid">; acting?: Branded<string, "Uuid"> | undefined; }): Promise<{ ok: true; undeleted: boolean; }>

params

returns Promise<AccountUndeleteOutput>

list_sessions

type (params?: { acting?: Branded<string, "Uuid"> | undefined; } | undefined): Promise<{ sessions: { username: string; id: Branded<string, "SessionId">; account_id: Branded<string, "Uuid">; created_at: string; expires_at: string; }[]; }>

params?

optional
returns Promise<AdminSessionListOutput>

create_role_grant

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

revoke_role_grant

type (params: { actor_id: Branded<string, "Uuid">; role_grant_id: Branded<string, "Uuid">; reason?: string | null | undefined; acting?: Branded<string, "Uuid"> | undefined; }): Promise<...>

params

returns Promise<RoleGrantRevokeOutput>

retract_offer

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

session_revoke_all

type (params: { account_id: Branded<string, "Uuid">; acting?: Branded<string, "Uuid"> | undefined; }): Promise<{ ok: true; count: number; }>

params

token_revoke_all

type (params: { account_id: Branded<string, "Uuid">; acting?: Branded<string, "Uuid"> | undefined; }): Promise<{ ok: true; count: number; }>

params

returns Promise<AdminTokenRevokeAllOutput>

AdminAccountsState
#

ui/admin_accounts_state.svelte.ts view source

import {AdminAccountsState} from '@fuzdev/fuz_app/ui/admin_accounts_state.svelte.js';

list

type AsyncSlot<void, string>

readonly

grant

type KeyedAsyncSlot<string, RoleGrantOfferJson, string>

readonly

revoke

type KeyedAsyncSlot<Branded, void, string>

readonly

retract

type KeyedAsyncSlot<Branded, void, string>

readonly

soft_delete

type KeyedAsyncSlot<Branded, void, string>

readonly

undelete

type KeyedAsyncSlot<Branded, void, string>

readonly

accounts

type AdminAccountEntryJson[]

$state.raw

grantable_roles

type string[]

$state.raw

show_deleted

When true, fetch() includes soft-deleted (tombstoned) accounts so the admin can reactivate them. Toggled via set_show_deleted.

type boolean

$state

account_count

type number

readonly $derived

constructor

type new (options: AdminAccountsStateOptions): AdminAccountsState

options

fetch

type (): Promise<void>

returns Promise<void>

set_show_deleted

Toggle whether soft-deleted accounts appear in the listing, then re-fetch. Tombstoned rows are surfaced so an admin can reactivate them via submit_undelete.

type (value: boolean): Promise<void>

value

type boolean
returns Promise<void>

submit_delete

Soft-delete an account (reversible tombstone) via account_delete. Keyed by account_id so per-row spinners/errors stay independent. Refreshes the listing on success so the row drops out (active view) or flips to its tombstoned state (show_deleted view).

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

account_id

type Branded
returns Promise<void>

submit_undelete

Reactivate a soft-deleted account via account_undelete (admin-only). Keyed by account_id; refreshes the listing on success so the row returns to active state.

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

account_id

type Branded
returns Promise<void>

submit_grant

Offer the role to the recipient via the role_grant_offer_create RPC. Server returns the pending offer; the recipient must accept before the role_grant materializes. Returns the offer payload on success so callers can drive follow-up UX (e.g. seed RoleGrantOffersState.outgoing).

A re-offer from the same admin to the same (account, role) refreshes the existing pending row — the returned offer id is stable across those calls.

to_actor_id (optional) narrows the offer to a specific actor on account_id; the keyed-slot key stays at account_id:role for the account-grain default (so existing consumers keep working) and becomes account_id:role:to_actor_id when actor-targeted, so the two variants can be in flight without colliding on the per-row spinner.

type (account_id: Branded<string, "Uuid">, role: string, to_actor_id?: Branded<string, "Uuid"> | null | undefined): Promise<{ id: Branded<string, "Uuid">; ... 14 more ...; resulting_role_grant_id: Branded<...> | null; } | undefined>

account_id

type Branded

role

type string

to_actor_id?

type Branded | null
optional
returns Promise<RoleGrantOfferJson | undefined>

submit_revoke

Revoke an active role_grant via the role_grant_revoke RPC.

actor_id is the natural key — role_grants are actor-scoped, and the admin UI reads row.actor.id straight from the listing, so the state class takes it directly rather than deriving it from account_id. The optional reason is stamped on role_grant.revoked_reason and surfaced on the revokee's WS notification.

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

actor_id

type Branded

role_grant_id

type Branded

reason?

type string | null
optional
returns Promise<void>

submit_retract

Retract a pending offer the admin issued via the role_grant_offer_retract RPC. The action handles auth, audit, and the role_grant_offer_retracted WS notification.

After success, refetches the listing so pending_offers drops the row and the "+ {role}" button un-hides.

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

offer_id

type Branded
returns Promise<void>

AdminAccountsStateOptions
#

ui/admin_accounts_state.svelte.ts view source

AdminAccountsStateOptions import type {AdminAccountsStateOptions} from '@fuzdev/fuz_app/ui/admin_accounts_state.svelte.js';

get_rpc

Reactive accessor for the RPC adapter. Matches RoleGrantOffersStateOptions.account_id / actor_id pattern — lets the component pass a $props()-sourced rpc without tripping Svelte's state_referenced_locally warning.

type (): AdminAccountsRpc

can_offer_global_role
#

ui/admin_accounts_state.svelte.ts view source

(entry: Pick<{ account: { updated_at: string; updated_by: Branded<string, "Uuid"> | null; deleted_at: string | null; id: Branded<string, "Uuid">; username: string; email: string | null; email_verified: boolean; created_at: string; }; actor: { ...; } | null; role_grants: { ...; }[]; pending_offers: { ...; }[]; }, "role_grants" | "pending_offers">, role: string, now?: Date): boolean import {can_offer_global_role} from '@fuzdev/fuz_app/ui/admin_accounts_state.svelte.js';

Whether a listing row can be offered a global grant of role — the test behind AdminAccounts' + role button, which submit_grant backs with an unscoped offer. Only what the offer would duplicate rules it out: a global grant of the role, or a pending global offer of it. A grant or offer scoped to one resource is a different grant, so it doesn't.

entry

the account's listing row

type Pick<AdminAccountEntryJson, "role_grants" | "pending_offers">

role

the role the button would offer

type string

now?

current time for the grant-expiry check (defaults to new Date(), pass for testability); pending offers are taken as listed — the listing returns only unexpired ones

type Date
optional default new Date()

returns

boolean

grant_key
#

ui/admin_accounts_state.svelte.ts view source

(account_id: Branded<string, "Uuid">, role: string, to_actor_id?: Branded<string, "Uuid"> | null | undefined): string import {grant_key} from '@fuzdev/fuz_app/ui/admin_accounts_state.svelte.js';

Compose the grant keyed-slot key for an offer. Account-grain offers key on ${account_id}:${role}; actor-targeted offers add the actor suffix so the two variants can be in flight simultaneously without colliding on per-row spinners.

account_id

type Branded

role

type string

to_actor_id?

type Branded | null
optional

returns

string

Depends on
#

Imported by
#