/** * Billing summary endpoint. * * GET /_emdash/api/billing — cost-plus balance, spend breakdown, daily trend, * the credit price book/markup this instance runs under, and where a top-up is * sent (the hosting parent's checkout). Admin-only: it exposes money. */ import type { APIRoute } from "astro"; import { requirePerm } from "#api/authorize.js"; import { apiError, handleError, unwrapResult } from "#api/error.js"; import { handleBillingSummary } from "#api/handlers/billing.js"; export const prerender = false; export const GET: APIRoute = async ({ locals }) => { const { emdash, user } = locals; const denied = requirePerm(user, "settings:manage"); if (denied) return denied; if (!emdash?.db) { return apiError("NOT_CONFIGURED", "EmDash is not initialized", 500); } try { return unwrapResult(await handleBillingSummary(emdash.db)); } catch (error) { return handleError(error, "Failed to load billing", "BILLING_ERROR"); } };