import { NextResponse } from "next/server"; import { withAuth } from "@/lib/api-auth"; import { apiError, handleApiError } from "@/lib/api-errors"; import { deleteEndpoint, EndpointError, getEndpoint, updateEndpoint } from "@/lib/endpoints"; export const dynamic = "force-dynamic"; const fail = (err: unknown) => (err instanceof EndpointError ? apiError(err.status, err.code, err.message) : handleApiError(err)); export const GET = withAuth>(async (_req, { params }) => { const e = await getEndpoint((await params).id); return e ? NextResponse.json(e) : apiError(404, "not_found", "Endpoint not found."); }); /** Change an endpoint; leave `apiKey` out to keep the stored key, send "" to remove it. */ export const PATCH = withAuth>(async (req, { params }) => { try { return NextResponse.json(await updateEndpoint((await params).id, await req.json())); } catch (err) { return fail(err); } }); /** Delete an endpoint; its runs stay (with their snapshot). */ export const DELETE = withAuth>(async (_req, { params }) => { try { await deleteEndpoint((await params).id); return new NextResponse(null, { status: 204 }); } catch (err) { return fail(err); } });