{"version":3,"file":"immutable-log.mjs","names":[],"sources":["../../../../src/astro/routes/api/immutable-log.ts"],"sourcesContent":["/**\n * Immutable log endpoint.\n *\n * GET /_emdash/api/immutable-log?limit=&before= — the append-only billing\n * ledger merged with the admin audit trail, newest first. `before` is an\n * exclusive ISO-timestamp cursor. Admin-only.\n */\n\nimport type { APIRoute } from \"astro\";\n\nimport { requirePerm } from \"#api/authorize.js\";\nimport { apiError, handleError, unwrapResult } from \"#api/error.js\";\nimport { handleImmutableLog } from \"#api/handlers/billing.js\";\n\nexport const prerender = false;\n\nexport const GET: APIRoute = async ({ locals, url }) => {\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\tconst limitRaw = Number(url.searchParams.get(\"limit\"));\n\tconst limit = Number.isFinite(limitRaw) && limitRaw > 0 ? Math.floor(limitRaw) : undefined;\n\tconst before = url.searchParams.get(\"before\") ?? undefined;\n\n\ttry {\n\t\treturn unwrapResult(await handleImmutableLog(emdash.db, { limit, before }));\n\t} catch (error) {\n\t\treturn handleError(error, \"Failed to load log\", \"IMMUTABLE_LOG_ERROR\");\n\t}\n};\n"],"mappings":";;;;;;;;AAcA,MAAa,YAAY;AAEzB,MAAa,MAAgB,OAAO,EAAE,QAAQ,UAAU;CACvD,MAAM,EAAE,QAAQ,SAAS;CAEzB,MAAM,SAAS,YAAY,MAAM,kBAAkB;AACnD,KAAI,OAAQ,QAAO;AAEnB,KAAI,CAAC,QAAQ,GACZ,QAAO,SAAS,kBAAkB,6BAA6B,IAAI;CAGpE,MAAM,WAAW,OAAO,IAAI,aAAa,IAAI,QAAQ,CAAC;CACtD,MAAM,QAAQ,OAAO,SAAS,SAAS,IAAI,WAAW,IAAI,KAAK,MAAM,SAAS,GAAG;CACjF,MAAM,SAAS,IAAI,aAAa,IAAI,SAAS,IAAI;AAEjD,KAAI;AACH,SAAO,aAAa,MAAM,mBAAmB,OAAO,IAAI;GAAE;GAAO;GAAQ,CAAC,CAAC;UACnE,OAAO;AACf,SAAO,YAAY,OAAO,sBAAsB,sBAAsB"}