(input: CreateAuditLogInput)
| 23 | * so a logging failure never breaks the main operation. |
| 24 | */ |
| 25 | export const createAuditLog = async (input: CreateAuditLogInput) => { |
| 26 | try { |
| 27 | const licensed = await hasValidLicense(input.organizationId); |
| 28 | if (!licensed) return; |
| 29 | |
| 30 | await db.insert(auditLog).values({ |
| 31 | organizationId: input.organizationId, |
| 32 | userId: input.userId, |
| 33 | userEmail: input.userEmail, |
| 34 | userRole: input.userRole, |
| 35 | action: input.action, |
| 36 | resourceType: input.resourceType, |
| 37 | resourceId: input.resourceId, |
| 38 | resourceName: input.resourceName, |
| 39 | metadata: input.metadata ? JSON.stringify(input.metadata) : undefined, |
| 40 | }); |
| 41 | } catch (err) { |
| 42 | console.error("[audit-log] Failed to create audit log entry:", err); |
| 43 | } |
| 44 | }; |
| 45 | |
| 46 | export interface GetAuditLogsInput { |
| 47 | organizationId: string; |
no test coverage detected