ui/audit_log_state.svelte.ts

Reactive state for the audit log viewer.

Two fetch primitives (fetch for events, fetch_role_grant_history for the grant/revoke shortcut) flow through an injected RPC adapter; the SSE stream continues to use EventSource directly — streams aren't an RPC concern.

Holds AsyncSlots for list (the main event list), role_grant_history (the dedicated role-grant history endpoint), and gap_fill (the catch-up fetch run each time the stream opens). Data lives on the class so SSE pushes and gap-fill calls update it directly; both merge by seq, so events stays newest-first however they interleave.

view source

Declarations
#

7 declarations

audit_log_filter_matches
#

ui/audit_log_state.svelte.ts view source

(event: { id: Branded<string, "Uuid">; seq: number; event_type: string; outcome: "success" | "failure"; actor_id: Branded<string, "Uuid"> | null; account_id: Branded<string, "Uuid"> | null; ... 4 more ...; metadata: Record<...> | null; }, filter: AuditLogFilter | undefined): boolean import {audit_log_filter_matches} from '@fuzdev/fuz_app/ui/audit_log_state.svelte.js';

Whether an event passes an AuditLogFilter — the client-side twin of the list query's filter conditions, applied to live stream events.

event

the event to test

filter

the filter; absent or empty fields match everything

type AuditLogFilter | undefined

returns

boolean

audit_log_rpc_context
#

ui/audit_log_state.svelte.ts view source

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

Svelte context carrying the reactive AuditLogRpc accessor. Mirrors admin_accounts_rpc_context. get() throws when no provisioner ran above the component — the adapter is required.

AuditLogFilter
#

ui/audit_log_state.svelte.ts view source

AuditLogFilter import type {AuditLogFilter} from '@fuzdev/fuz_app/ui/audit_log_state.svelte.js';

The filter fields of AuditLogListInput — what AuditLogState.subscribe applies to live events and to its gap fill, matching what a fetch with the same fields returns. account_id matches either side of an event (account_id or target_account_id), as the list query does.

account_id?

type Branded | null

event_type?

type string | null

outcome?

type "success" | "failure" | null

AuditLogRpc
#

ui/audit_log_state.svelte.ts view source

AuditLogRpc import type {AuditLogRpc} from '@fuzdev/fuz_app/ui/audit_log_state.svelte.js';

Narrow RPC surface consumed by AuditLogState. Consumers adapt their typed RPC client to this shape. Mirrors AdminAccountsRpc / AdminInvitesRpc. Method signatures track the wire spec inputs/outputs directly so the adapter needs no casts.

list

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

params?

optional
returns Promise<AuditLogListOutput>

role_grant_history

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

params?

optional

AuditLogState
#

ui/audit_log_state.svelte.ts view source

import {AuditLogState} from '@fuzdev/fuz_app/ui/audit_log_state.svelte.js';

list

type AsyncSlot<void, string>

readonly

role_grant_history

type AsyncSlot<void, string>

readonly

gap_fill

The catch-up fetch run each time the stream opens; its error surfaces a failed fill.

type AsyncSlot<void, string>

readonly

events

type AuditLogEventWithUsernamesJson[]

$state.raw

role_grant_history_events

type RoleGrantHistoryEventJson[]

$state.raw

count

type number

readonly $derived

stream_status

Lifecycle of the SSE stream — see AuditLogStreamStatus.

type AuditLogStreamStatus

$state.raw

gap_truncated

Whether a gap fill hit its row limit, so events between the last one seen and the stream's reopening may be missing. Cleared by fetch, which replaces the list (as is a failed gap_fill).

type boolean

$state.raw

constructor

type new (options: AuditLogStateOptions): AuditLogState

options

fetch

Load a page of events, replacing events.

While the stream is live, events it delivered after the page's newest one that match the fetch's filter are kept, so a fetch answering mid-stream doesn't drop them. A newest-page fetch aborts an in-flight gap fill, which its own query covers, and when the stream opened before the list matched its filter or while the fetch was in flight, runs that open's gap fill from the fetched page.

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

options?

the list input; its filter fields become the list's filter

optional
returns Promise<void>

mutates

  • this

fetch_role_grant_history

type (limit?: number | undefined, offset?: number | undefined): Promise<void>

limit?

type number
optional

offset?

type number
optional
returns Promise<void>

subscribe

Connect to the SSE stream for realtime audit events.

Live events matching filter merge into events by seq. EventSource reconnects on transient errors (stream_status reads 'connecting'); each open runs a gap fill from the last seq seen, with the same filter. A refused reconnect ends the stream ('closed') — call subscribe again to retry. Gap fills run only while events was fetched with the same filter: an open the list doesn't match yet defers its fill to the fetch with the stream's filter, and live events under another filter than the list's merge only when they match the list's filter too, without advancing the anchor.

type (filter?: AuditLogFilter | undefined): () => void

filter?

which events to keep; omit for all

optional
returns () => void

cleanup function that closes the connection

mutates

  • this

disconnect

Close the SSE connection and abort an in-flight gap fill.

type (): void

returns void

mutates

  • this

AuditLogStateOptions
#

ui/audit_log_state.svelte.ts view source

AuditLogStateOptions import type {AuditLogStateOptions} from '@fuzdev/fuz_app/ui/audit_log_state.svelte.js';

get_rpc

Reactive accessor for the RPC adapter. Matches the get_rpc pattern on AdminAccountsState. The SSE stream uses EventSource directly and is independent of this adapter.

type (): AuditLogRpc

returns AuditLogRpc

stream_url?

SSE stream URL. Defaults to the shipped admin audit-log stream route.

type string

AuditLogStreamStatus
#

ui/audit_log_state.svelte.ts view source

AuditLogStreamStatus

type "off" | "connecting" | "open" | "closed"

import type {AuditLogStreamStatus} from '@fuzdev/fuz_app/ui/audit_log_state.svelte.js';

Lifecycle of the audit SSE stream.

  • 'off' — not subscribed (initial, or after disconnect)
  • 'connecting' — opening, or EventSource is retrying after a transient error
  • 'open' — connected and receiving events
  • 'closed' — the stream gave up: the server refused the reconnect (a revoked credential or a lost role answers it with 401/403), so EventSource stopped retrying; call subscribe again to retry

Depends on
#

Imported by
#