"use client"; /** Client helper for admin APIs: adds the CSRF token (from ) and surfaces errors. */ export async function api(path: string, init: RequestInit = {}): Promise { const csrf = document.querySelector('meta[name="csrf-token"]')?.content ?? ""; const r = await fetch(path, { ...init, headers: { "content-type": "application/json", "x-csrf-token": csrf, ...(init.headers ?? {}) }, credentials: "same-origin" }); const j = await r.json().catch(() => ({})); if (!r.ok) throw new Error(j.error ?? `${r.status}`); return j as T; }