import { projectRef } from "@/lib/projects"; import { judgeDraft } from "@/lib/report/versions.mjs"; import { refuseCaller } from "@/lib/report/caller"; import { crossSiteRefusal } from "@/lib/report/sameOrigin.mjs"; export const dynamic = "force-dynamic"; // THE REVIEW PASS'S VERDICT ON THE DRAFT (lib/report/versions.mjs judgeDraft): one locked call -- the draft that // differs from its parent only by the walk's and the review pass's fields judges the PARENT, nothing saved; else it // is saved as the next version and that is judged. A version reviewed as itself is judged through // /api/report/takes/verdict. Terminal twin: `umtool review-pass

verdict like|maybe|no|clear`. // // POST { project, verdict: "like"|"maybe"|"no"|null, note? } -> { ok, judged, saved, entry } export async function POST(request: Request) { const refused = refuseCaller(request, "/api/report/review-pass/verdict"); if (refused) return refused; const cross = crossSiteRefusal(request.headers); if (cross) return Response.json({ error: cross }, { status: 403 }); const body = (await request.json().catch(() => null)) as { project?: string; verdict?: string | null; note?: string } | null; if (!body || typeof body !== "object") return Response.json({ error: "bad json" }, { status: 400 }); const v = body.verdict === null || body.verdict === "" ? null : body.verdict; if (v !== null && !["like", "maybe", "no"].includes(String(v))) return Response.json({ error: "verdict must be like, maybe, no or null" }, { status: 400 }); const project = await projectRef(String(body.project ?? "")); if (!project) return Response.json({ error: "no such project" }, { status: 404 }); try { const r = await judgeDraft(project, v as "like" | "maybe" | "no" | null, { note: typeof body.note === "string" ? body.note : undefined }); return Response.json({ ok: true, ...r }, { headers: { "cache-control": "no-store" } }); } catch (e) { return Response.json({ error: e instanceof Error ? e.message : String(e) }, { status: 400 }); } }