import { NextResponse, type NextRequest } from 'next/server'; import { requireAdminApi } from '@/lib/auth/admin-guard'; import { parsePageParam, parsePerPageParam } from '@/lib/admin/validators'; import { getAuditList } from '@/lib/admin/list'; export const runtime = 'nodejs'; export const dynamic = 'force-dynamic'; export async function GET(req: NextRequest) { const auth = await requireAdminApi(); if (!auth.ok) return auth.response; const url = new URL(req.url); const page = parsePageParam(url.searchParams.get('page'), 1); const perPage = parsePerPageParam(url.searchParams.get('perPage'), 50, 100); const action = url.searchParams.get('action') ?? ''; const targetType = url.searchParams.get('target_type') ?? ''; try { const { entries, total } = await getAuditList({ page, perPage, action, targetType, }); return NextResponse.json({ entries, total, page, perPage }); } catch (e) { return NextResponse.json({ error: (e as Error).message }, { status: 500 }); } }