Add actor data to request

This commit is contained in:
Owen
2025-10-22 14:27:21 -07:00
parent f748c5dbe4
commit f2c31d3ca6
6 changed files with 79 additions and 44 deletions

View File

@@ -27,9 +27,10 @@ export async function logRequestAudit(
action: boolean;
reason: number;
resourceId?: number;
orgId?: string;
location?: string;
user?: { username: string; userId: string; orgId: string };
apiKey?: { name: string; apiKeyId: string; orgId: string };
user?: { username: string; userId: string; };
apiKey?: { name: string | null; apiKeyId: string; };
metadata?: any;
// userAgent?: string;
},
@@ -47,32 +48,23 @@ export async function logRequestAudit(
}
) {
try {
let orgId: string | undefined;
let actorType: string | undefined;
let actor: string | undefined;
let actorId: string | undefined;
const user = data.user;
if (user) {
orgId = user.orgId;
actorType = "user";
actor = user.username;
actorId = user.userId;
}
const apiKey = data.apiKey;
if (apiKey) {
orgId = apiKey.orgId;
actorType = "apiKey";
actor = apiKey.name;
actor = apiKey.name || apiKey.apiKeyId;
actorId = apiKey.apiKeyId;
}
if (!orgId) {
logger.warn("logRequestAudit: No organization context found");
orgId = "org_7g93l5xu7p61q14";
// return;
}
// if (!actorType || !actor || !actorId) {
// logger.warn("logRequestAudit: Incomplete actor information");
// return;
@@ -107,7 +99,7 @@ export async function logRequestAudit(
await db.insert(requestAuditLog).values({
timestamp,
orgId,
orgId: data.orgId,
actorType,
actor,
actorId,