forked from wrenn/wrenn
Add audit logs frontend page
Infinite-scroll table with hierarchical filter dropdown, expandable metadata rows, and status-coded visual signals per event severity. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
38
frontend/src/lib/api/audit.ts
Normal file
38
frontend/src/lib/api/audit.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { apiFetch, type ApiResult } from '$lib/api/client';
|
||||
|
||||
export type AuditLog = {
|
||||
id: string;
|
||||
actor_type: 'user' | 'api_key' | 'system';
|
||||
actor_id?: string;
|
||||
actor_name?: string;
|
||||
resource_type: string;
|
||||
resource_id?: string;
|
||||
action: string;
|
||||
scope: 'team' | 'admin';
|
||||
status: 'success' | 'info' | 'warning' | 'error';
|
||||
metadata?: Record<string, unknown>;
|
||||
created_at: string;
|
||||
};
|
||||
|
||||
export type AuditListResponse = {
|
||||
items: AuditLog[];
|
||||
next_before?: string;
|
||||
next_before_id?: string;
|
||||
};
|
||||
|
||||
export async function listAuditLogs(params?: {
|
||||
before?: string;
|
||||
before_id?: string;
|
||||
resource_types?: string[];
|
||||
actions?: string[];
|
||||
limit?: number;
|
||||
}): Promise<ApiResult<AuditListResponse>> {
|
||||
const q = new URLSearchParams();
|
||||
if (params?.before) q.set('before', params.before);
|
||||
if (params?.before_id) q.set('before_id', params.before_id);
|
||||
params?.resource_types?.forEach((t) => q.append('resource_type', t));
|
||||
params?.actions?.forEach((a) => q.append('action', a));
|
||||
if (params?.limit != null) q.set('limit', String(params.limit));
|
||||
const qs = q.toString();
|
||||
return apiFetch('GET', `/api/v1/audit-logs${qs ? '?' + qs : ''}`);
|
||||
}
|
||||
Reference in New Issue
Block a user