1
0
forked from wrenn/wrenn
Files
wrenn-releases/frontend/src/lib/api/audit.ts
pptx704 3ce8fdcb02 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>
2026-03-25 05:18:04 +06:00

39 lines
1.1 KiB
TypeScript

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 : ''}`);
}