feat(audit): dual-write журнала в auth-portal ingest
Docker / build (push) Failing after 23s

Добавлены event_id/actorUserId и async push source_app=vps без блокировки CRUD.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Denozordec
2026-07-21 13:24:30 +07:00
co-authored by Cursor
parent 8cee00e6e3
commit a02daba69b
9 changed files with 344 additions and 11 deletions
+36
View File
@@ -0,0 +1,36 @@
import type { FastifyRequest } from 'fastify'
import type { AuthUser } from './permissions.js'
export type AuditActorContext = {
actorUserId: string | null
actorEmail: string | null
actorName: string | null
ip: string | null
}
export function actorFromAuthUser(user?: AuthUser | null): AuditActorContext {
if (!user) {
return {
actorUserId: null,
actorEmail: null,
actorName: null,
ip: null,
}
}
return {
actorUserId: user.id,
actorEmail: user.email || null,
actorName: user.name || null,
ip: null,
}
}
export function actorFromRequest(request: FastifyRequest): AuditActorContext {
const base = actorFromAuthUser(request.authUser)
const forwarded = request.headers['x-forwarded-for']
let ip: string | null = request.ip ?? null
if (typeof forwarded === 'string' && forwarded.trim()) {
ip = forwarded.split(',')[0]?.trim() ?? ip
}
return { ...base, ip }
}