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 + permit-offer + account). Account-surface methods flow through account_sessions_rpc_context (wired at the self-service layout), and permit-offer methods that surface in the admin UI (permit_offer_create, permit_revoke, permit_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/PermitOfferForm.svelte) can match on error.data?.reason via ERROR_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.

Declarations
#

5 declarations

view source

AdminRpcAdapters
#

AdminRpcApi
#

ui/admin_rpc_adapters.ts view source

AdminRpcApi

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 () => Promise<AdminAccountListOutput>

admin_session_list

type () => Promise<AdminSessionListOutput>

admin_session_revoke_all

type ( input: AdminSessionRevokeAllInput, ) => Promise<AdminSessionRevokeAllOutput>

admin_token_revoke_all

type (input: AdminTokenRevokeAllInput) => Promise<AdminTokenRevokeAllOutput>

audit_log_list

type (input: AuditLogListInput) => Promise<AuditLogListOutput>

audit_log_permit_history

type ( input: AuditLogPermitHistoryInput, ) => Promise<AuditLogPermitHistoryOutput>

invite_list

type () => Promise<InviteListOutput>

invite_create

type (input: InviteCreateInput) => Promise<InviteCreateOutput>

invite_delete

type (input: InviteDeleteInput) => Promise<InviteDeleteOutput>

app_settings_get

type () => Promise<AppSettingsGetOutput>

app_settings_update

type (input: AppSettingsUpdateInput) => Promise<AppSettingsUpdateOutput>

permit_offer_create

type (input: PermitOfferCreateInput) => Promise<PermitOfferCreateOutput>

permit_offer_retract

type (input: PermitOfferRetractInput) => Promise<PermitOfferOkOutput>

permit_revoke

type (input: PermitRevokeInput) => Promise<PermitRevokeOutput>

create_admin_rpc_adapters
#

ui/admin_rpc_adapters.ts view source

(api: AdminRpcApi): AdminRpcAdapters

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

Method-name mapping:

| Narrow RPC method | Action spec method | | ----------------------------------- | ---------------------------- | | admin_accounts.list_accounts | admin_account_list | | admin_accounts.list_sessions | admin_session_list | | admin_accounts.grant_permit | permit_offer_create | | admin_accounts.revoke_permit | permit_revoke | | admin_accounts.retract_offer | permit_offer_retract | | admin_accounts.session_revoke_all | admin_session_revoke_all | | admin_accounts.token_revoke_all | admin_token_revoke_all | | admin_invites.list | invite_list | | admin_invites.create | invite_create | | admin_invites.delete | invite_delete | | audit_log.list | audit_log_list | | audit_log.permit_history | audit_log_permit_history | | app_settings.get | app_settings_get | | app_settings.update | app_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

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 permit/offer scope_id values as human labels across AdminAccounts, AdminPermitHistory, PermitOfferInbox, PermitOfferForm, and PermitOfferHistory. Components that accept a format_scope prop honor the prop first; the context is the fallback.

adapters

options?

type ProvideAdminRpcContextsOptions | undefined
optional

returns

void

ProvideAdminRpcContextsOptions
#

ui/admin_rpc_adapters.ts view source

ProvideAdminRpcContextsOptions

Optional knobs alongside the adapters when wiring admin contexts.

format_scope

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

Depends on
#