ui/admin_rpc_adapters.ts

Admin RPC adapter helpers for consumer UIs.

Bridges a typed throwing RPC client to the four narrow admin RPC interfaces the state classes consume — AdminAccountsRpc, AdminInvitesRpc, AuditLogRpc, AppSettingsRpc. Two calls at the admin shell layout wire everything.

Intentionally admin-only despite the backend-side create_standard_rpc_actions rename (admin + role-grant-offer + account). Account-surface methods flow through account_sessions_rpc_context (wired at the self-service layout), and role-grant-offer methods that surface in the admin UI (role_grant_offer_create, role_grant_revoke, role_grant_offer_retract) live inside the AdminAccountsRpc interface — they belong to the admin UX, not a separate wire pairing. The UI side and backend factory names diverge by design.

// `api` is the typed throwing Proxy from `create_frontend_rpc_client`. provide_admin_rpc_contexts(create_admin_rpc_adapters(api));

The throwing Proxy spreads the JSON-RPC {code, message, data?} onto the thrown Error so form components (e.g. ui/RoleGrantOfferForm.svelte) can match on error.data?.reason via ERROR_ROLE_GRANT_OFFER_* constants — optional chaining is required because JSON-RPC data is spec-level optional. Consumers that need a custom unwrap strategy can construct their own object satisfying AdminRpcApi and pass it directly.

No .svelte.ts suffix — this module holds no reactive state, only method-name mappings.

view source

Declarations
#

5 declarations

AdminRpcAdapters
#

AdminRpcApi
#

ui/admin_rpc_adapters.ts view source

AdminRpcApi import type {AdminRpcApi} from '@fuzdev/fuz_app/ui/admin_rpc_adapters.js';

The wire-method surface this module needs from the typed throwing RPC client. Every method returns the unwrapped value or throws an Error carrying the JSON-RPC {code, message, data?} shape — i.e. the ThrowingApi<...> view of the corresponding action specs.

Consumers pass the typed throwing Proxy returned by create_frontend_rpc_client directly. Structural typing means any superset (e.g. the consumer's full ThrowingApi<ActionsApi>) is assignable as long as these methods are present at these signatures.

admin_account_list

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

input?

optional
returns Promise<AdminAccountListOutput>

account_delete

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

input

returns Promise<AccountDeleteOutput>

account_undelete

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

input

returns Promise<AccountUndeleteOutput>

admin_session_list

type (input?: { 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; }[]; }>

input?

optional
returns Promise<AdminSessionListOutput>

admin_session_revoke_all

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

input

admin_token_revoke_all

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

input

returns Promise<AdminTokenRevokeAllOutput>

audit_log_list

type (input?: { event_type?: string | null | undefined; outcome?: "success" | "failure" | null | undefined; account_id?: Branded<string, "Uuid"> | null | undefined; limit?: number | null | undefined; offset?: number | ... 1 more ... | undefined; since_seq?: number | ... 1 more ... | undefined; acting?: Branded<...> | undefined; } | undefined): Promise<...>

input?

optional
returns Promise<AuditLogListOutput>

audit_log_role_grant_history

type (input?: { limit?: number | null | undefined; offset?: number | null | undefined; acting?: Branded<string, "Uuid"> | undefined; } | undefined): Promise<{ events: { username: string | null; ... 11 more ...; metadata: Record<...> | null; }[]; }>

input?

optional

invite_list

type (input?: { acting?: Branded<string, "Uuid"> | undefined; } | undefined): Promise<{ invites: { created_by_username: string | null; claimed_by_username: string | null; id: Branded<string, "Uuid">; ... 5 more ...; created_by: Branded<...> | null; }[]; }>

input?

optional
returns Promise<InviteListOutput>

invite_create

type (input: { email?: string | null | undefined; username?: string | null | undefined; acting?: Branded<string, "Uuid"> | undefined; }): Promise<{ ok: true; invite: { id: Branded<string, "Uuid">; ... 5 more ...; created_by: Branded<...> | null; }; }>

input

returns Promise<InviteCreateOutput>

invite_delete

type (input: { invite_id: Branded<string, "Uuid">; acting?: Branded<string, "Uuid"> | undefined; }): Promise<{ ok: true; }>

input

returns Promise<InviteDeleteOutput>

app_settings_get

type (input?: { acting?: Branded<string, "Uuid"> | undefined; } | undefined): Promise<{ settings: { updated_by_username: string | null; open_signup: boolean; updated_at: string | null; updated_by: Branded<...> | null; }; }>

input?

optional
returns Promise<AppSettingsGetOutput>

app_settings_update

type (input: { open_signup: boolean; acting?: Branded<string, "Uuid"> | undefined; }): Promise<{ ok: true; settings: { updated_by_username: string | null; open_signup: boolean; updated_at: string | null; updated_by: Branded<...> | null; }; }>

input

returns Promise<AppSettingsUpdateOutput>

role_grant_offer_create

type (input: { 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<...>

input

role_grant_offer_retract

type (input: { 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; }; }>

input

role_grant_revoke

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

input

returns Promise<RoleGrantRevokeOutput>

create_admin_rpc_adapters
#

ui/admin_rpc_adapters.ts view source

(api: AdminRpcApi): AdminRpcAdapters import {create_admin_rpc_adapters} from '@fuzdev/fuz_app/ui/admin_rpc_adapters.js';

Build the four admin RPC adapters from a typed throwing RPC client.

Method-name mapping:

Narrow RPC methodAction spec method
admin_accounts.list_accountsadmin_account_list
admin_accounts.delete_accountaccount_delete (soft)
admin_accounts.undelete_accountaccount_undelete
admin_accounts.list_sessionsadmin_session_list
admin_accounts.create_role_grantrole_grant_offer_create
admin_accounts.revoke_role_grantrole_grant_revoke
admin_accounts.retract_offerrole_grant_offer_retract
admin_accounts.session_revoke_alladmin_session_revoke_all
admin_accounts.token_revoke_alladmin_token_revoke_all
admin_invites.listinvite_list
admin_invites.createinvite_create
admin_invites.deleteinvite_delete
audit_log.listaudit_log_list
audit_log.role_grant_historyaudit_log_role_grant_history
app_settings.getapp_settings_get
app_settings.updateapp_settings_update

All four adapter factories call through the same api — consumers pass the typed throwing Proxy from create_frontend_rpc_client once, regardless of how many admin surfaces they mount.

api

returns

AdminRpcAdapters

provide_admin_rpc_contexts
#

ui/admin_rpc_adapters.ts view source

(adapters: AdminRpcAdapters, options?: ProvideAdminRpcContextsOptions | undefined): void import {provide_admin_rpc_contexts} from '@fuzdev/fuz_app/ui/admin_rpc_adapters.js';

Wire all four admin RPC contexts in a single call.

Call once at the admin shell layout (e.g. src/routes/admin/+layout.svelte) with adapters built from create_admin_rpc_adapters. Every Admin*.svelte component that reads a context below this point sees the adapters.

Each context accessor reads adapters.{domain} on every invocation, so mutating an adapter field on the same object propagates. Replacing the whole adapter set requires calling provide_admin_rpc_contexts again during init — in practice this is one-shot at layout mount.

Pass options.format_scope to render role_grant/offer scope_id values as human labels across AdminAccounts, AdminRoleGrantHistory, RoleGrantOfferInbox, RoleGrantOfferForm, and RoleGrantOfferHistory. Components that accept a format_scope prop honor the prop first; the context is the fallback.

adapters

options?

optional

returns

void

ProvideAdminRpcContextsOptions
#

ui/admin_rpc_adapters.ts view source

ProvideAdminRpcContextsOptions import type {ProvideAdminRpcContextsOptions} from '@fuzdev/fuz_app/ui/admin_rpc_adapters.js';

Optional knobs alongside the adapters when wiring admin contexts.

format_scope?

Render {scope_id, role} as a human label across role-grant-display components. Omit (or return null) to fall back to the truncated uuid.

type (args: { scope_id: string | null; role: string; }): string | null

args

type { scope_id: string | null; role: string; }
returns string | null

Depends on
#