feat: marca Uriel Jareth Consulting, API segura para agentes, aprobacion humana y webhooks HMAC

This commit is contained in:
urieljareth
2026-11-25 00:55:18 -06:00
parent 75180b0fe4
commit 0d4f19f35d
111 changed files with 7167 additions and 1272 deletions
+46
View File
@@ -0,0 +1,46 @@
import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib/db";
import { requireActor } from "@/lib/agent-auth";
export async function GET(request: NextRequest) {
try {
const auth = await requireActor(request, { adminOnly: true, recursoTipo: "audit_log" });
if (!auth.ok) return auth.response;
const sp = request.nextUrl.searchParams;
const accion = sp.get("accion")?.trim();
const actorNombre = sp.get("actorNombre")?.trim();
const recursoId = sp.get("recursoId")?.trim();
const page = Math.max(1, parseInt(sp.get("page") || "1", 10) || 1);
const limit = Math.min(200, Math.max(1, parseInt(sp.get("limit") || "50", 10) || 50));
const where = {
...(accion && { accion: { contains: accion, mode: "insensitive" as const } }),
...(actorNombre && { actorNombre: { contains: actorNombre, mode: "insensitive" as const } }),
...(recursoId && { recursoId }),
};
const [total, data] = await Promise.all([
prisma.auditLog.count({ where }),
prisma.auditLog.findMany({
where,
orderBy: { createdAt: "desc" },
skip: (page - 1) * limit,
take: limit,
}),
]);
return NextResponse.json({
data,
meta: {
total,
page,
limit,
pages: Math.ceil(total / limit),
},
});
} catch (error: unknown) {
const msg = error instanceof Error ? error.message : "Error interno";
return NextResponse.json({ error: msg }, { status: 500 });
}
}