import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; const HERE = path.dirname(fileURLToPath(import.meta.url)); export function reviewHtmlPath(fallback) { const env = process.env.STAFF_UI_HTML; const shared = path.join(HERE, '..', 'public', 'review.html'); const sibling = path.join(HERE, '..', '..', 'verae-staff-ui', 'public', 'review.html'); for (const p of [env, shared, sibling, fallback]) { if (p && fs.existsSync(p)) return p; } return fallback; } export function loadReviewHtml(opts, fallback) { const file = reviewHtmlPath(fallback); let html = fs.readFileSync(file, 'utf8'); const map = { '{{TITLE}}': opts.title || 'Staff review', '{{KICKER}}': opts.kicker || 'staff', '{{LEDE}}': opts.lede || 'Review prepaid balance, credits, usage, and payments in dollars.', }; for (const [k, v] of Object.entries(map)) html = html.split(k).join(v); return html; }