{"version":3,"file":"billing.mjs","names":[],"sources":["../../../../src/astro/routes/api/billing.ts"],"sourcesContent":["/**\n * Billing summary endpoint.\n *\n * GET /_emdash/api/billing — cost-plus balance, spend breakdown, daily trend,\n * the credit price book/markup this instance runs under, and where a top-up is\n * sent (the hosting parent's checkout). Admin-only: it exposes money.\n */\n\nimport type { APIRoute } from \"astro\";\n\nimport { requirePerm } from \"#api/authorize.js\";\nimport { apiError, handleError, unwrapResult } from \"#api/error.js\";\nimport { handleBillingSummary } from \"#api/handlers/billing.js\";\n\nexport const prerender = false;\n\nexport const GET: APIRoute = async ({ locals }) => {\n\tconst { emdash, user } = locals;\n\n\tconst denied = requirePerm(user, \"settings:manage\");\n\tif (denied) return denied;\n\n\tif (!emdash?.db) {\n\t\treturn apiError(\"NOT_CONFIGURED\", \"EmDash is not initialized\", 500);\n\t}\n\n\ttry {\n\t\treturn unwrapResult(await handleBillingSummary(emdash.db));\n\t} catch (error) {\n\t\treturn handleError(error, \"Failed to load billing\", \"BILLING_ERROR\");\n\t}\n};\n"],"mappings":";;;;;;;;AAcA,MAAa,YAAY;AAEzB,MAAa,MAAgB,OAAO,EAAE,aAAa;CAClD,MAAM,EAAE,QAAQ,SAAS;CAEzB,MAAM,SAAS,YAAY,MAAM,kBAAkB;AACnD,KAAI,OAAQ,QAAO;AAEnB,KAAI,CAAC,QAAQ,GACZ,QAAO,SAAS,kBAAkB,6BAA6B,IAAI;AAGpE,KAAI;AACH,SAAO,aAAa,MAAM,qBAAqB,OAAO,GAAG,CAAC;UAClD,OAAO;AACf,SAAO,YAAY,OAAO,0BAA0B,gBAAgB"}