import { NextRequest, NextResponse } from "next/server"; import { toErrorResponse } from "@/lib/render-pipeline/errors"; import { requirePipelineAdmin } from "@/lib/render-pipeline/session-auth"; import { markDelivered } from "@/lib/render-pipeline/deliveries"; import { recordShareSchema } from "@/lib/render-pipeline/delivery-handoff"; // ── POST /api/deliveries/{id}/delivered (E19) ──────────────────────────────── // // The upload link has been sent to the client. Takes who it was sent to, and // moves every packaged export to DELIVERED — the end of the pipeline. export async function POST( req: NextRequest, { params }: { params: Promise<{ packageId: string }> } ) { try { const user = await requirePipelineAdmin(); const { packageId } = await params; const parsed = recordShareSchema.safeParse(await req.json().catch(() => null)); if (!parsed.success) { return NextResponse.json( { error: parsed.error.issues[0]?.message ?? "Invalid request", details: parsed.error.issues }, { status: 422 } ); } const result = await markDelivered(packageId, parsed.data, user.id); return NextResponse.json(result); } catch (err) { const { body, status } = toErrorResponse(err); return NextResponse.json(body, { status }); } }