export type GetApiAuditExportArgs = {agentId?: string | undefined, action?: ('sign' | 'approve' | 'reject' | 'proxy') | undefined, status?: string | undefined, dateFrom: string, dateTo: string}; export type GetApiAuditExportOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Export tenant audit log rows as CSV * * GET /audit/export */ export const getApiAuditExport = async (args: GetApiAuditExportArgs, options?: GetApiAuditExportOptions) => { const {baseUrl = "http://localhost:3200", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/csv") if (args.agentId != null) query.append("agentId", String(args.agentId)) if (args.action != null) query.append("action", String(args.action)) if (args.status != null) query.append("status", String(args.status)) if (args.dateFrom != null) query.append("dateFrom", String(args.dateFrom)) if (args.dateTo != null) query.append("dateTo", String(args.dateTo)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/audit/export${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.text() };