import { apiRequestData } from "./http"; export type AuditLogItem = { id: string; requestId: string; actorId: string; actorName: string; actorEmail: string; action: string; targetType: string; targetId: string | null; ipAddress: string | null; userAgent: string | null; extra: Record; createdAt: string; }; export type AuditLogListResponse = { page: number; pageSize: number; total: number; items: AuditLogItem[]; }; export type AuditLogQuery = { page?: number; pageSize?: number; actorId?: string; action?: string; targetType?: string; dateFrom?: string; dateTo?: string; }; function toQueryString(query: AuditLogQuery) { const params = new URLSearchParams(); for (const [key, value] of Object.entries(query)) { if (value == null || value === "") { continue; } params.set(key, String(value)); } const encoded = params.toString(); return encoded ? `?${encoded}` : ""; } export async function fetchAuditLogs(query: AuditLogQuery) { return apiRequestData(`/api/audit-logs${toQueryString(query)}`); }