import { customerPortalUrl, meshkeeApiBase } from "@/lib/config"; import { getBusinessId } from "@/lib/meshkee"; export async function POST(request: Request) { const token = request.headers.get("authorization"); if (!token) { return Response.json({ error: "login_required", redirect: customerPortalUrl }, { status: 401 }); } const businessId = await getBusinessId(); if (!businessId) { return Response.json({ error: "tenant_missing" }, { status: 500 }); } const body = await request.json(); try { const response = await fetch(`${meshkeeApiBase}/businesses/${encodeURIComponent(businessId)}/cart/items`, { method: "POST", headers: { Authorization: token, "Content-Type": "application/json", }, body: JSON.stringify(body), }); const text = await response.text(); return new Response(text, { status: response.status, headers: { "Content-Type": response.headers.get("content-type") ?? "application/json" }, }); } catch { return Response.json({ error: "cart_failed" }, { status: 502 }); } }