MCPcopy
hub / github.com/simstudioai/sim / insertAuditLog

Function insertAuditLog

packages/audit/src/log.ts:41–76  ·  view source on GitHub ↗
(params: AuditLogParams)

Source from the content-addressed store, hash-verified

39}
40
41async function insertAuditLog(params: AuditLogParams): Promise<void> {
42 const ipAddress = params.request ? getClientIp(params.request) : undefined
43 const userAgent = params.request?.headers.get('user-agent') ?? undefined
44
45 let { actorName, actorEmail } = params
46
47 if (actorName === undefined && actorEmail === undefined && params.actorId) {
48 try {
49 const [row] = await db
50 .select({ name: user.name, email: user.email })
51 .from(user)
52 .where(eq(user.id, params.actorId))
53 .limit(1)
54 actorName = row?.name ?? undefined
55 actorEmail = row?.email ?? undefined
56 } catch (error) {
57 logger.warn('Failed to resolve actor info', { error, actorId: params.actorId })
58 }
59 }
60
61 await db.insert(auditLog).values({
62 id: generateShortId(),
63 workspaceId: params.workspaceId || null,
64 actorId: params.actorId,
65 action: params.action,
66 resourceType: params.resourceType,
67 resourceId: params.resourceId,
68 actorName: actorName ?? undefined,
69 actorEmail: actorEmail ?? undefined,
70 resourceName: params.resourceName,
71 description: params.description,
72 metadata: params.metadata ?? {},
73 ipAddress,
74 userAgent,
75 })
76}

Callers 1

recordAuditFunction · 0.85

Calls 5

generateShortIdFunction · 0.90
getClientIpFunction · 0.70
getMethod · 0.65
warnMethod · 0.65
eqFunction · 0.50

Tested by

no test coverage detected