import type { HydraCollection } from '~/utils/api' import { extractHydraMembers } from '~/utils/api' export type AuditLogAction = 'create' | 'update' | 'delete' export type AuditLogItem = { id: string '@id'?: string entityType: string entityId: string action: AuditLogAction changes: Record performedBy: string performedAt: string ipAddress: string | null requestId: string | null } export type AuditLogQuery = { page?: number entityType?: string action?: AuditLogAction } export type AuditLogPage = { items: AuditLogItem[] totalItems: number } export type AuditLogEntityType = { '@id'?: string value: string } export function useAuditLogService() { const api = useApi() async function list(params: AuditLogQuery = {}): Promise { const query: Record = {} if (params.page !== undefined) { query.page = params.page } if (params.entityType) { query.entity_type = params.entityType } if (params.action) { query.action = params.action } const data = await api.get>('/audit-logs', query) return { items: extractHydraMembers(data), totalItems: data['hydra:totalItems'] ?? data['totalItems'] ?? 0, } } async function entityTypes(): Promise { const data = await api.get>('/audit-log-entity-types') return extractHydraMembers(data).map((entry) => entry.value) } return { list, entityTypes } }