import { db, schema } from './db/connection' export interface AuditLogEntry { user_id?: number action: string resource_type: string resource_id?: number details?: any ip_address?: string } export async function logAuditEvent(entry: AuditLogEntry): Promise { try { await db.insert(schema.auditLogs).values({ userId: entry.user_id || null, action: entry.action, resourceType: entry.resource_type, resourceId: entry.resource_id || null, details: entry.details ? JSON.stringify(entry.details) : null, ipAddress: entry.ip_address || null }) } catch (error) { console.error('Audit logging failed:', error) } } export const AuditActions = { CREATE: 'CREATE', UPDATE: 'UPDATE', DELETE: 'DELETE', APPROVE: 'APPROVE', REJECT: 'REJECT', LOGIN: 'LOGIN', LOGOUT: 'LOGOUT', BULK_IMPORT: 'BULK_IMPORT', EXPORT: 'EXPORT' } as const export const ResourceTypes = { SOURCE: 'source', REPORT: 'report', USER: 'user', CATEGORY: 'category', API_KEY: 'api_key' } as const