docfast/src/utils/billing-templates.ts
DocFast CEO b491052f69
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 18m0s
refactor: extract billing HTML templates into billing-templates.ts (TDD)
- Extract renderSuccessPage() and renderAlreadyProvisionedPage() from billing.ts
- Share common styles via SHARED_STYLES constant
- 11 TDD tests: content rendering, XSS escaping, structure validation
- billing.ts: 369 → 334 lines (-35 lines, inline HTML removed)
- 647 tests passing (59 files), 0 tsc errors
2026-03-10 17:03:44 +01:00

41 lines
1.9 KiB
TypeScript

import { escapeHtml } from "./html.js";
const SHARED_STYLES = `
body { font-family: system-ui; background: #0a0a0a; color: #e8e8e8; display: flex; align-items: center; justify-content: center; min-height: 100vh; margin: 0; }
.card { background: #141414; border: 1px solid #222; border-radius: 16px; padding: 48px; max-width: 500px; text-align: center; }
h1 { color: #4f9; margin-bottom: 8px; }
p { color: #888; line-height: 1.6; }
a { color: #4f9; }
`;
export function renderSuccessPage(apiKey: string): string {
const escaped = escapeHtml(apiKey);
return `<!DOCTYPE html>
<html><head><title>Welcome to DocFast Pro!</title>
<style>${SHARED_STYLES}
.key { background: #1a1a1a; border: 1px solid #333; border-radius: 8px; padding: 16px; margin: 24px 0; font-family: monospace; font-size: 0.9rem; word-break: break-all; cursor: pointer; }
.key:hover { border-color: #4f9; }
</style></head><body>
<div class="card">
<h1>🎉 Welcome to Pro!</h1>
<p>Your API key:</p>
<div class="key" style="position:relative">${escaped}<button data-copy="${escaped}" style="position:absolute;top:8px;right:8px;background:#4f9;color:#0a0a0a;border:none;border-radius:4px;padding:4px 12px;cursor:pointer;font-size:0.8rem;font-family:system-ui">Copy</button></div>
<p><strong>Save this key!</strong> It won't be shown again.</p>
<p>5,000 PDFs/month • All endpoints • Priority support</p>
<p><a href="/docs">View API docs →</a></p>
</div>
<script src="/copy-helper.js"></script>
</body></html>`;
}
export function renderAlreadyProvisionedPage(): string {
return `<!DOCTYPE html>
<html><head><title>DocFast Pro — Key Already Provisioned</title>
<style>${SHARED_STYLES}</style></head><body>
<div class="card">
<h1>✅ Key Already Provisioned</h1>
<p>A Pro API key has already been created for this purchase.</p>
<p>If you lost your key, use the <a href="/docs#key-recovery">key recovery feature</a>.</p>
<p><a href="/docs">View API docs →</a></p>
</div></body></html>`;
}