Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
refactor(cloudcp): extract Pulse Account assets
rcourtman86862a7f9123
diff --git a/internal/cloudcp/portal/assets/login.css b/internal/cloudcp/portal/assets/login.cssnew file mode 100644index 0000000000..875b2ff1f0--- /dev/null+++ b/internal/cloudcp/portal/assets/login.css@@ -0,0 +1,15 @@+ :root { color-scheme: light; }+ body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: linear-gradient(140deg, #f8fafc, #e2e8f0); color: #0f172a; display: flex; align-items: center; justify-content: center; min-height: 100vh; }+ .card { background: #fff; border-radius: 12px; border: 1px solid #e2e8f0; box-shadow: 0 8px 30px rgba(15,23,42,.08); padding: 32px 28px; width: 100%; max-width: 400px; margin: 16px; }+ .brand { font-size: 22px; font-weight: 700; margin-bottom: 6px; }+ .subtitle { color: #64748b; font-size: 14px; margin-bottom: 24px; }+ label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }+ input { width: 100%; border: 1px solid #cbd5e1; border-radius: 8px; padding: 10px 12px; font-size: 15px; }+ input:focus { outline: 2px solid #1d4ed8; border-color: transparent; }+ .cta { margin-top: 14px; border: 0; border-radius: 10px; background: #1d4ed8; color: #fff; font-size: 15px; font-weight: 600; padding: 11px 16px; width: 100%; cursor: pointer; }+ .cta:hover { background: #1e40af; }+ .cta:disabled { opacity: 0.6; cursor: default; }+ .success { background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 8px; padding: 14px; color: #166534; font-size: 14px; line-height: 1.5; display: none; margin-top: 14px; }+ .error { background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; padding: 12px; color: #991b1b; font-size: 14px; display: none; margin-top: 14px; }+ .footer { margin-top: 20px; text-align: center; font-size: 12px; color: #94a3b8; }+ .footer a { color: #1d4ed8; text-decoration: none; }diff --git a/internal/cloudcp/portal/assets/login.js b/internal/cloudcp/portal/assets/login.jsnew file mode 100644index 0000000000..42ab411005--- /dev/null+++ b/internal/cloudcp/portal/assets/login.js@@ -0,0 +1,52 @@+var emailEl = document.getElementById('email');+var sendBtn = document.getElementById('send-btn');+var successEl = document.getElementById('success');+var errEl = document.getElementById('err-msg');++async function sendMagicLink() {+ var email = emailEl.value.trim();+ if (!email) { emailEl.focus(); return; }+ sendBtn.disabled = true;+ sendBtn.textContent = 'Sending…';+ errEl.style.display = 'none';+ try {+ var r = await fetch('/api/public/magic-link/request', {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ email: email })+ });+ if (r.ok || r.status === 404) {+ successEl.style.display = 'block';+ sendBtn.style.display = 'none';+ emailEl.style.display = 'none';+ document.querySelector('label').style.display = 'none';+ } else if (r.status === 429) {+ errEl.textContent = 'Too many requests. Please wait a moment and try again.';+ errEl.style.display = 'block';+ sendBtn.disabled = false;+ sendBtn.textContent = 'Send magic link';+ } else {+ errEl.textContent = 'Something went wrong. Please try again.';+ errEl.style.display = 'block';+ sendBtn.disabled = false;+ sendBtn.textContent = 'Send magic link';+ }+ } catch (_) {+ errEl.textContent = 'Network error. Please check your connection and try again.';+ errEl.style.display = 'block';+ sendBtn.disabled = false;+ sendBtn.textContent = 'Send magic link';+ }+}++sendBtn.onclick = sendMagicLink;+emailEl.addEventListener('keydown', function(e) { if (e.key === 'Enter') sendMagicLink(); });+document.getElementById('resend-link').onclick = function(e) {+ e.preventDefault();+ successEl.style.display = 'none';+ sendBtn.style.display = '';+ emailEl.style.display = '';+ document.querySelector('label').style.display = '';+ sendBtn.disabled = false;+ sendBtn.textContent = 'Send magic link';+};diff --git a/internal/cloudcp/portal/assets/portal.css b/internal/cloudcp/portal/assets/portal.cssnew file mode 100644index 0000000000..c923420f8f--- /dev/null+++ b/internal/cloudcp/portal/assets/portal.css@@ -0,0 +1,109 @@+ :root { color-scheme: light; }+ * { box-sizing: border-box; }+ body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: #f1f5f9; color: #0f172a; }+ header { background: #1e293b; color: #f8fafc; padding: 12px 24px; display: flex; align-items: center; justify-content: space-between; }+ header .brand { font-weight: 700; font-size: 18px; letter-spacing: -0.3px; }+ header .user-info { display: flex; align-items: center; gap: 16px; font-size: 13px; color: #94a3b8; }+ header .logout-btn { background: none; border: 1px solid #475569; color: #94a3b8; border-radius: 6px; padding: 5px 12px; cursor: pointer; font-size: 13px; }+ header .logout-btn:hover { border-color: #94a3b8; color: #f8fafc; }+ .main { max-width: 860px; margin: 32px auto; padding: 0 16px 48px; }+ .account-section { margin-bottom: 40px; }+ .account-header { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }+ .account-header h2 { margin: 0; font-size: 20px; font-weight: 700; }+ .badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.5px; }+ .badge-msp { background: #dbeafe; color: #1e40af; }+ .badge-cloud { background: #dcfce7; color: #166534; }+ .badge-individual { background: #dcfce7; color: #166534; }+ .badge-healthy { background: #dcfce7; color: #166534; }+ .badge-unhealthy { background: #fee2e2; color: #991b1b; }+ .badge-active { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }+ .badge-suspended { background: #fef9c3; color: #854d0e; border: 1px solid #fef08a; }+ .badge-failed { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }+ .badge-provisioning { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }+ .badge-canceled { background: #f1f5f9; color: #64748b; border: 1px solid #e2e8f0; }+ .badge-deleting { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }+ .workspace-list { display: flex; flex-direction: column; gap: 10px; }+ .workspace-card { background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; box-shadow: 0 1px 3px rgba(15,23,42,.04); }+ .workspace-card:hover { border-color: #cbd5e1; }+ .ws-info { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }+ .ws-name { font-weight: 600; font-size: 15px; }+ .ws-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }+ .ws-created { font-size: 11px; color: #94a3b8; }+ .ws-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }+ .btn-primary { background: #1d4ed8; color: #fff; border: 0; border-radius: 8px; padding: 8px 18px; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-block; }+ .btn-primary:hover { background: #1e40af; }+ .btn-secondary { background: #fff; color: #334155; border: 1px solid #cbd5e1; border-radius: 8px; padding: 7px 14px; font-size: 13px; font-weight: 500; cursor: pointer; }+ .btn-secondary:hover { background: #f8fafc; border-color: #94a3b8; }+ .btn-danger { background: #fff; color: #dc2626; border: 1px solid #fca5a5; border-radius: 8px; padding: 7px 14px; font-size: 13px; cursor: pointer; }+ .btn-danger:hover { background: #fef2f2; }+ .account-actions { margin-top: 14px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }+ .add-workspace-form { margin-top: 12px; display: none; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 10px; padding: 16px; }+ .add-workspace-form.visible { display: block; }+ .add-workspace-form label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }+ .add-workspace-form input { width: 100%; border: 1px solid #cbd5e1; border-radius: 8px; padding: 8px 12px; font-size: 14px; margin-bottom: 10px; }+ .add-workspace-form .form-actions { display: flex; gap: 8px; }+ .team-section { margin-top: 12px; display: none; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 10px; padding: 16px; }+ .team-section.visible { display: block; }+ .team-section h3 { margin: 0 0 12px; font-size: 15px; font-weight: 700; }+ .team-table { width: 100%; border-collapse: collapse; font-size: 14px; }+ .team-table th { text-align: left; font-size: 12px; font-weight: 600; color: #64748b; text-transform: uppercase; letter-spacing: 0.5px; padding: 6px 8px; border-bottom: 1px solid #e2e8f0; }+ .team-table td { padding: 8px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }+ .team-table select { border: 1px solid #cbd5e1; border-radius: 6px; padding: 4px 8px; font-size: 13px; background: #fff; }+ .team-table .btn-remove { background: none; border: none; color: #dc2626; cursor: pointer; font-size: 13px; padding: 4px 8px; }+ .team-table .btn-remove:hover { text-decoration: underline; }+ .team-invite { margin-top: 12px; display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }+ .team-invite label { font-size: 12px; font-weight: 600; display: block; margin-bottom: 4px; }+ .team-invite input { border: 1px solid #cbd5e1; border-radius: 8px; padding: 8px 12px; font-size: 14px; min-width: 200px; }+ .team-invite select { border: 1px solid #cbd5e1; border-radius: 6px; padding: 8px 10px; font-size: 14px; background: #fff; }+ .intro-card { background: linear-gradient(145deg, #fff, #f8fafc); border: 1px solid #dbe4f0; border-radius: 16px; padding: 22px 24px; margin-bottom: 24px; box-shadow: 0 10px 24px rgba(15,23,42,.05); }+ .intro-card h1 { margin: 0 0 8px; font-size: 26px; line-height: 1.1; }+ .intro-card p { margin: 0; color: #475569; font-size: 15px; line-height: 1.6; max-width: 760px; }+ .service-section { margin-top: 40px; }+ .service-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }+ .service-header h2 { margin: 0; font-size: 20px; font-weight: 700; }+ .service-note { font-size: 13px; color: #64748b; max-width: 680px; }+ .service-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }+ .service-card { display: block; text-decoration: none; color: inherit; background: #fff; border: 1px solid #e2e8f0; border-radius: 12px; padding: 16px; box-shadow: 0 1px 3px rgba(15,23,42,.04); }+ .service-card:hover { border-color: #93c5fd; box-shadow: 0 6px 18px rgba(29,78,216,.08); }+ .service-card-button { width: 100%; text-align: left; border: 1px solid #e2e8f0; cursor: pointer; font: inherit; }+ .service-card h3 { margin: 0 0 6px; font-size: 16px; font-weight: 700; }+ .service-card p { margin: 0; font-size: 14px; color: #64748b; line-height: 1.5; }+ .service-panel { display: none; margin-top: 14px; background: #fff; border: 1px solid #dbe4f0; border-radius: 12px; padding: 18px; }+ .service-panel.visible { display: block; }+ .service-panel h3 { margin: 0 0 8px; font-size: 17px; }+ .service-panel p { margin: 0 0 14px; font-size: 14px; color: #64748b; }+ .service-panel label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: #475569; }+ .service-panel input, .service-panel textarea { width: 100%; border: 1px solid #cbd5e1; border-radius: 8px; padding: 10px 12px; font: inherit; box-sizing: border-box; background: #fff; color: #0f172a; }+ .service-panel input:focus, .service-panel textarea:focus { outline: 2px solid #93c5fd; border-color: #1d4ed8; }+ .service-panel textarea { min-height: 120px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }+ .service-panel .form-group { margin-bottom: 14px; }+ .service-panel .form-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }+ .service-panel .helper-text { margin-top: 10px; font-size: 13px; color: #64748b; }+ .service-panel .helper-text a { color: #1d4ed8; }+ .service-panel .result-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-top: 14px; }+ .service-panel .result-meta-label { font-size: 12px; color: #64748b; margin-bottom: 4px; }+ .service-panel .result-meta-value { font-size: 14px; color: #0f172a; word-break: break-word; }+ .service-panel .subsection { margin-top: 18px; padding-top: 18px; border-top: 1px solid #e2e8f0; }+ .service-panel .subsection:first-of-type { margin-top: 0; padding-top: 0; border-top: none; }+ .service-panel .subsection h4 { margin: 0 0 8px; font-size: 15px; font-weight: 700; }+ .service-panel .warning { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; border-radius: 8px; padding: 12px; font-size: 13px; line-height: 1.5; margin-bottom: 12px; }+ .service-panel .checkbox-row { display: flex; align-items: flex-start; gap: 10px; margin: 12px 0; }+ .service-panel .checkbox-row input[type="checkbox"] { width: 18px; height: 18px; margin-top: 2px; flex-shrink: 0; }+ .service-panel .checkbox-row span { font-size: 13px; color: #475569; line-height: 1.5; }+ .service-status { margin-top: 12px; padding: 10px 12px; border-radius: 8px; font-size: 13px; display: none; }+ .service-status.visible { display: block; }+ .service-status.error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }+ .service-status.success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }+ .empty-state { background: #fff; border: 1px dashed #cbd5e1; border-radius: 10px; padding: 32px; text-align: center; color: #64748b; }+ .empty-state p { margin: 0; font-size: 15px; }+ .spinner { display: none; width: 18px; height: 18px; border: 2px solid #93c5fd; border-top-color: #1d4ed8; border-radius: 50%; animation: spin 0.6s linear infinite; }+ @keyframes spin { to { transform: rotate(360deg); } }+ .toast { position: fixed; bottom: 24px; right: 24px; background: #1e293b; color: #f8fafc; border-radius: 8px; padding: 12px 20px; font-size: 14px; display: none; z-index: 100; }+ .toast.visible { display: block; animation: fadein 0.2s; }+ @keyframes fadein { from { opacity: 0; transform: translateY(8px); } }+ .toast.error { background: #991b1b; }+ @media (max-width: 560px) {+ .workspace-card { flex-direction: column; align-items: flex-start; }+ .ws-actions { align-self: stretch; }+ .ws-actions form, .ws-actions .btn-primary { width: 100%; text-align: center; }+ }diff --git a/internal/cloudcp/portal/assets/portal.js b/internal/cloudcp/portal/assets/portal.jsnew file mode 100644index 0000000000..e332e66899--- /dev/null+++ b/internal/cloudcp/portal/assets/portal.js@@ -0,0 +1,562 @@+const LICENSE_API_BASE = 'https://license.pulserelay.pro';++function showToast(msg, isError) {+ var t = document.getElementById('toast');+ t.textContent = msg;+ t.className = 'toast visible' + (isError ? ' error' : '');+ clearTimeout(t._timer);+ t._timer = setTimeout(function() { t.className = 'toast'; }, 4000);+}++document.getElementById('logout-btn').onclick = async function() {+ this.disabled = true;+ this.textContent = 'Signing out…';+ try {+ await fetch('/auth/logout', { method: 'POST' });+ } catch(_) {}+ window.location.href = '/portal';+};++function toggleServicePanel(panelID) {+ var panels = ['manage-service-panel', 'retrieve-service-panel', 'refund-service-panel', 'data-service-panel'];+ for (var i = 0; i < panels.length; i++) {+ var panel = document.getElementById(panels[i]);+ panel.classList.toggle('visible', panels[i] === panelID ? !panel.classList.contains('visible') : false);+ }+}++function setServiceStatus(id, message, isError) {+ var el = document.getElementById(id);+ el.textContent = message;+ el.className = 'service-status visible' + (isError ? ' error' : ' success');+}++document.getElementById('open-manage-service').onclick = function() {+ toggleServicePanel('manage-service-panel');+ document.getElementById('manage-inline-email').focus();+};++document.getElementById('open-retrieve-service').onclick = function() {+ toggleServicePanel('retrieve-service-panel');+ document.getElementById('retrieve-inline-email').focus();+};++document.getElementById('open-refund-service').onclick = function() {+ toggleServicePanel('refund-service-panel');+ document.getElementById('refund-inline-email').focus();+};++document.getElementById('open-data-service').onclick = function() {+ toggleServicePanel('data-service-panel');+ document.getElementById('data-export-email').focus();+};++var pendingManageEmail = '';+var pendingRetrieveEmail = '';+var pendingExportEmail = '';+var pendingDeleteEmail = '';++document.getElementById('manage-inline-request').onclick = async function() {+ var email = document.getElementById('manage-inline-email').value.trim();+ if (!email) { document.getElementById('manage-inline-email').focus(); return; }+ this.disabled = true;+ this.textContent = 'Sending...';+ try {+ var res = await fetch(LICENSE_API_BASE + '/v1/manage/request', {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ email: email })+ });+ var data = await res.json();+ if (!res.ok) throw new Error(data.error || 'Failed to send verification code');+ pendingManageEmail = email;+ document.getElementById('manage-inline-step2').style.display = 'block';+ setServiceStatus('manage-inline-status', 'Verification code sent. Check your email.', false);+ } catch (err) {+ setServiceStatus('manage-inline-status', err.message, true);+ } finally {+ this.disabled = false;+ this.textContent = 'Send Verification Code';+ }+};++document.getElementById('manage-inline-resend').onclick = async function(e) {+ e.preventDefault();+ if (!pendingManageEmail) return;+ try {+ var res = await fetch(LICENSE_API_BASE + '/v1/manage/request', {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ email: pendingManageEmail })+ });+ var data = await res.json();+ if (!res.ok) throw new Error(data.error || 'Failed to send verification code');+ setServiceStatus('manage-inline-status', 'New verification code sent.', false);+ } catch (err) {+ setServiceStatus('manage-inline-status', err.message, true);+ }+};++document.getElementById('manage-inline-confirm').onclick = async function() {+ var code = document.getElementById('manage-inline-code').value.trim();+ if (!pendingManageEmail || !code) return;+ this.disabled = true;+ this.textContent = 'Redirecting...';+ try {+ var res = await fetch(LICENSE_API_BASE + '/v1/manage', {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ email: pendingManageEmail, code: code })+ });+ var data = await res.json();+ if (!res.ok) throw new Error(data.error || 'Failed to open customer portal');+ window.location.href = data.url;+ } catch (err) {+ setServiceStatus('manage-inline-status', err.message, true);+ this.disabled = false;+ this.textContent = 'Open Customer Portal';+ }+};++document.getElementById('retrieve-inline-request').onclick = async function() {+ var email = document.getElementById('retrieve-inline-email').value.trim();+ if (!email) { document.getElementById('retrieve-inline-email').focus(); return; }+ this.disabled = true;+ this.textContent = 'Sending...';+ document.getElementById('retrieve-inline-result').style.display = 'none';+ try {+ var res = await fetch(LICENSE_API_BASE + '/v1/retrieve-license/request', {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ email: email })+ });+ var data = await res.json();+ if (!res.ok) throw new Error(data.error || 'Failed to send verification code');+ pendingRetrieveEmail = email;+ document.getElementById('retrieve-inline-step2').style.display = 'block';+ setServiceStatus('retrieve-inline-status', 'Verification code sent. Check your email.', false);+ } catch (err) {+ setServiceStatus('retrieve-inline-status', err.message, true);+ } finally {+ this.disabled = false;+ this.textContent = 'Send Verification Code';+ }+};++document.getElementById('retrieve-inline-confirm').onclick = async function() {+ var code = document.getElementById('retrieve-inline-code').value.trim();+ if (!pendingRetrieveEmail || !code) return;+ this.disabled = true;+ this.textContent = 'Loading...';+ try {+ var res = await fetch(LICENSE_API_BASE + '/v1/retrieve-license', {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ email: pendingRetrieveEmail, code: code })+ });+ var data = await res.json();+ if (!res.ok) throw new Error(data.error || 'Failed to retrieve license');+ var license = data.license;+ document.getElementById('retrieve-inline-token').value = license.token;+ document.getElementById('retrieve-inline-tier').textContent = license.tier;+ document.getElementById('retrieve-inline-issued').textContent = new Date(license.issued_at).toLocaleString();+ document.getElementById('retrieve-inline-expires').textContent = license.expires_at ? new Date(license.expires_at).toLocaleString() : 'Does not expire';+ document.getElementById('retrieve-inline-email-value').textContent = license.email;+ document.getElementById('retrieve-inline-result').style.display = 'block';+ document.getElementById('retrieve-inline-copy').style.display = 'inline-block';+ if (license.invoice_url) {+ var invoice = document.getElementById('retrieve-inline-invoice');+ invoice.href = license.invoice_url;+ invoice.style.display = 'inline-block';+ }+ setServiceStatus('retrieve-inline-status', 'License retrieved successfully.', false);+ } catch (err) {+ setServiceStatus('retrieve-inline-status', err.message, true);+ } finally {+ this.disabled = false;+ this.textContent = 'Show License';+ }+};++document.getElementById('retrieve-inline-copy').onclick = async function() {+ var token = document.getElementById('retrieve-inline-token').value;+ if (!token) return;+ try {+ await navigator.clipboard.writeText(token);+ setServiceStatus('retrieve-inline-status', 'License key copied to clipboard.', false);+ } catch (_) {+ setServiceStatus('retrieve-inline-status', 'Failed to copy automatically. Please copy the key manually.', true);+ }+};++document.getElementById('refund-inline-submit').onclick = async function() {+ var email = document.getElementById('refund-inline-email').value.trim();+ var token = document.getElementById('refund-inline-token').value.trim();+ if (!email || !token) return;+ if (!confirm('Are you sure? This will immediately revoke the license and request the refund.')) return;+ this.disabled = true;+ this.textContent = 'Processing...';+ try {+ var res = await fetch(LICENSE_API_BASE + '/v1/self-refund', {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ email: email, token: token })+ });+ var data = await res.json();+ if (!res.ok) throw new Error(data.error || 'Refund failed');+ document.getElementById('refund-inline-token').value = '';+ setServiceStatus('refund-inline-status', 'Success! Your refund has been processed. Stripe will follow up by email.', false);+ } catch (err) {+ setServiceStatus('refund-inline-status', err.message, true);+ } finally {+ this.disabled = false;+ this.textContent = 'Process Refund';+ }+};++document.getElementById('data-export-request').onclick = async function() {+ var email = document.getElementById('data-export-email').value.trim();+ if (!email) return;+ this.disabled = true;+ this.textContent = 'Sending...';+ document.getElementById('data-export-result').style.display = 'none';+ try {+ var res = await fetch(LICENSE_API_BASE + '/v1/gdpr/request-export', {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ email: email })+ });+ var data = await res.json();+ if (!res.ok) throw new Error(data.error || 'Request failed');+ pendingExportEmail = email;+ document.getElementById('data-export-step2').style.display = 'block';+ setServiceStatus('data-export-status', 'Verification code sent. Check your email.', false);+ } catch (err) {+ setServiceStatus('data-export-status', err.message, true);+ } finally {+ this.disabled = false;+ this.textContent = 'Send Verification Code';+ }+};++document.getElementById('data-export-resend').onclick = async function(e) {+ e.preventDefault();+ if (!pendingExportEmail) return;+ try {+ var res = await fetch(LICENSE_API_BASE + '/v1/gdpr/request-export', {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ email: pendingExportEmail })+ });+ var data = await res.json();+ if (!res.ok) throw new Error(data.error || 'Request failed');+ setServiceStatus('data-export-status', 'New verification code sent.', false);+ } catch (err) {+ setServiceStatus('data-export-status', err.message, true);+ }+};++document.getElementById('data-export-confirm').onclick = async function() {+ var code = document.getElementById('data-export-code').value.trim();+ if (!pendingExportEmail || !code) return;+ this.disabled = true;+ this.textContent = 'Exporting...';+ try {+ var res = await fetch(LICENSE_API_BASE + '/v1/gdpr/export', {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ email: pendingExportEmail, code: code })+ });+ var data = await res.json();+ if (!res.ok) throw new Error(data.error || 'Export failed');+ document.getElementById('data-export-payload').value = JSON.stringify(data, null, 2);+ document.getElementById('data-export-result').style.display = 'block';+ setServiceStatus('data-export-status', 'Data export retrieved successfully.', false);+ document.getElementById('data-export-code').value = '';+ pendingExportEmail = '';+ document.getElementById('data-export-step2').style.display = 'none';+ } catch (err) {+ setServiceStatus('data-export-status', err.message, true);+ } finally {+ this.disabled = false;+ this.textContent = 'Export My Data';+ }+};++document.getElementById('data-delete-request').onclick = async function() {+ var email = document.getElementById('data-delete-email').value.trim();+ if (!email) return;+ this.disabled = true;+ this.textContent = 'Sending...';+ try {+ var res = await fetch(LICENSE_API_BASE + '/v1/gdpr/request-delete', {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ email: email })+ });+ var data = await res.json();+ if (!res.ok) throw new Error(data.error || 'Request failed');+ pendingDeleteEmail = email;+ document.getElementById('data-delete-step2').style.display = 'block';+ setServiceStatus('data-delete-status', 'Verification code sent. Check your email.', false);+ } catch (err) {+ setServiceStatus('data-delete-status', err.message, true);+ } finally {+ this.disabled = false;+ this.textContent = 'Send Verification Code';+ }+};++document.getElementById('data-delete-resend').onclick = async function(e) {+ e.preventDefault();+ if (!pendingDeleteEmail) return;+ try {+ var res = await fetch(LICENSE_API_BASE + '/v1/gdpr/request-delete', {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ email: pendingDeleteEmail })+ });+ var data = await res.json();+ if (!res.ok) throw new Error(data.error || 'Request failed');+ setServiceStatus('data-delete-status', 'New verification code sent.', false);+ } catch (err) {+ setServiceStatus('data-delete-status', err.message, true);+ }+};++document.getElementById('data-delete-confirm').onclick = async function() {+ var code = document.getElementById('data-delete-code').value.trim();+ if (!pendingDeleteEmail || !code) return;+ if (!document.getElementById('data-delete-confirm-check').checked) {+ setServiceStatus('data-delete-status', 'You must confirm that you understand this action is permanent.', true);+ return;+ }+ this.disabled = true;+ this.textContent = 'Deleting...';+ try {+ var res = await fetch(LICENSE_API_BASE + '/v1/gdpr/confirm-delete', {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ email: pendingDeleteEmail, code: code })+ });+ var data = await res.json();+ if (!res.ok) throw new Error(data.error || 'Deletion failed');+ setServiceStatus('data-delete-status', data.deleted_count > 0 && data.stripe_reminder ? data.message + ' ' + data.stripe_reminder : data.message, false);+ document.getElementById('data-delete-step2').style.display = 'none';+ document.getElementById('data-delete-code').value = '';+ document.getElementById('data-delete-confirm-check').checked = false;+ pendingDeleteEmail = '';+ } catch (err) {+ setServiceStatus('data-delete-status', err.message, true);+ } finally {+ this.disabled = false;+ this.textContent = 'Delete My Data';+ }+};++function toggleAddWorkspace(accountID) {+ var form = document.getElementById('add-ws-form-' + accountID);+ var visible = form.classList.contains('visible');+ form.classList.toggle('visible', !visible);+ if (!visible) {+ document.getElementById('ws-name-' + accountID).focus();+ }+}++async function createWorkspace(accountID) {+ var nameEl = document.getElementById('ws-name-' + accountID);+ var name = nameEl.value.trim();+ if (!name) { nameEl.focus(); return; }+ var spinner = document.getElementById('ws-spinner-' + accountID);+ spinner.style.display = 'block';+ try {+ var resp = await fetch('/api/accounts/' + accountID + '/tenants', {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ display_name: name })+ });+ if (!resp.ok) {+ var err = await resp.json().catch(function() { return {}; });+ showToast((err && err.error) || 'Failed to create workspace', true);+ return;+ }+ showToast('Workspace created!');+ setTimeout(function() { window.location.reload(); }, 800);+ } catch(e) {+ showToast('Network error. Please try again.', true);+ } finally {+ spinner.style.display = 'none';+ }+}++function suspendOrDelete(evt, accountID, tenantID, state, name) {+ evt.stopPropagation();+ var action = state === 'active' ? 'Suspend' : 'Delete';+ if (!confirm(action + ' workspace "' + name + '"?')) return;+ var method = state === 'active' ? 'PATCH' : 'DELETE';+ var body = state === 'active' ? JSON.stringify({ state: 'suspended' }) : undefined;+ fetch('/api/accounts/' + accountID + '/tenants/' + tenantID, {+ method: method,+ headers: body ? { 'Content-Type': 'application/json' } : {},+ body: body+ }).then(function(r) {+ if (r.ok) {+ showToast(action + 'd workspace.');+ setTimeout(function() { window.location.reload(); }, 800);+ } else {+ showToast('Failed to ' + action.toLowerCase() + ' workspace.', true);+ }+ }).catch(function() {+ showToast('Network error.', true);+ });+}++async function openBilling(accountID) {+ try {+ var r = await fetch('/api/portal/billing?account_id=' + encodeURIComponent(accountID), { method: 'POST' });+ if (!r.ok) {+ var err = await r.json().catch(function() { return {}; });+ showToast((err && err.error) || 'Failed to open billing portal.', true);+ return;+ }+ var data = await r.json();+ if (data && data.url) {+ window.location.href = data.url;+ } else {+ showToast('Failed to open billing portal.', true);+ }+ } catch(e) {+ showToast('Network error.', true);+ }+}++function toggleTeam(accountID) {+ var section = document.getElementById('team-section-' + accountID);+ var visible = section.classList.contains('visible');+ section.classList.toggle('visible', !visible);+ if (!visible) loadTeam(accountID);+}++function setTbodyMessage(tbody, msg, isError) {+ tbody.textContent = '';+ var tr = document.createElement('tr');+ var td = document.createElement('td');+ td.setAttribute('colspan', '3');+ td.style.cssText = 'text-align:center;padding:16px;color:' + (isError ? '#991b1b' : '#94a3b8');+ td.textContent = msg;+ tr.appendChild(td);+ tbody.appendChild(tr);+}++async function loadTeam(accountID) {+ var tbody = document.getElementById('team-list-' + accountID);+ var section = document.getElementById('team-section-' + accountID);+ var actorRole = section.getAttribute('data-actor-role') || '';+ var isOwner = actorRole === 'owner';+ setTbodyMessage(tbody, 'Loading\u2026', false);+ try {+ var r = await fetch('/api/accounts/' + encodeURIComponent(accountID) + '/members');+ if (!r.ok) { setTbodyMessage(tbody, 'Failed to load team.', true); return; }+ var members = await r.json();+ if (!members || members.length === 0) {+ setTbodyMessage(tbody, 'No team members.', false);+ return;+ }+ var allRoles = ['owner','admin','tech','read_only'];+ var nonOwnerRoles = ['admin','tech','read_only'];+ tbody.textContent = '';+ for (var i = 0; i < members.length; i++) {+ (function(m) {+ var tr = document.createElement('tr');+ var tdEmail = document.createElement('td');+ tdEmail.textContent = m.email;+ tr.appendChild(tdEmail);+ var tdRole = document.createElement('td');+ if (m.role === 'owner' && !isOwner) {+ tdRole.textContent = 'owner';+ } else {+ var sel = document.createElement('select');+ var roles = isOwner ? allRoles : nonOwnerRoles;+ for (var j = 0; j < roles.length; j++) {+ var opt = document.createElement('option');+ opt.value = roles[j];+ opt.textContent = roles[j].replace('_', ' ');+ if (m.role === roles[j]) opt.selected = true;+ sel.appendChild(opt);+ }+ sel.addEventListener('change', function() { changeRole(accountID, m.user_id, this.value); });+ tdRole.appendChild(sel);+ }+ tr.appendChild(tdRole);+ var tdAction = document.createElement('td');+ if (!(m.role === 'owner' && !isOwner)) {+ var btn = document.createElement('button');+ btn.className = 'btn-remove';+ btn.textContent = 'Remove';+ btn.addEventListener('click', function() { removeMember(accountID, m.user_id, m.email); });+ tdAction.appendChild(btn);+ }+ tr.appendChild(tdAction);+ tbody.appendChild(tr);+ })(members[i]);+ }+ } catch(e) {+ setTbodyMessage(tbody, 'Network error.', true);+ }+}++async function inviteMember(accountID) {+ var emailEl = document.getElementById('invite-email-' + accountID);+ var roleEl = document.getElementById('invite-role-' + accountID);+ var email = emailEl.value.trim();+ if (!email) { emailEl.focus(); return; }+ try {+ var r = await fetch('/api/accounts/' + encodeURIComponent(accountID) + '/members', {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ email: email, role: roleEl.value })+ });+ if (r.status === 409) { showToast('Member already exists.', true); return; }+ if (!r.ok) {+ var err = await r.text();+ showToast(err || 'Failed to invite member.', true);+ return;+ }+ emailEl.value = '';+ showToast('Member invited!');+ loadTeam(accountID);+ } catch(e) {+ showToast('Network error.', true);+ }+}++async function changeRole(accountID, userID, newRole) {+ try {+ var r = await fetch('/api/accounts/' + encodeURIComponent(accountID) + '/members/' + encodeURIComponent(userID), {+ method: 'PATCH',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ role: newRole })+ });+ if (r.status === 409) { showToast('Cannot demote last owner.', true); loadTeam(accountID); return; }+ if (!r.ok) { showToast('Failed to update role.', true); loadTeam(accountID); return; }+ showToast('Role updated.');+ } catch(e) {+ showToast('Network error.', true);+ loadTeam(accountID);+ }+}++async function removeMember(accountID, userID, email) {+ if (!confirm('Remove ' + email + ' from this account?')) return;+ try {+ var r = await fetch('/api/accounts/' + encodeURIComponent(accountID) + '/members/' + encodeURIComponent(userID), {+ method: 'DELETE'+ });+ if (r.status === 409) { showToast('Cannot remove last owner.', true); return; }+ if (!r.ok) { showToast('Failed to remove member.', true); return; }+ showToast('Member removed.');+ loadTeam(accountID);+ } catch(e) {+ showToast('Network error.', true);+ }+}diff --git a/internal/cloudcp/portal/handlers_test.go b/internal/cloudcp/portal/handlers_test.goindex 802ae0bbed..9658ca5c4d 100644--- a/internal/cloudcp/portal/handlers_test.go+++ b/internal/cloudcp/portal/handlers_test.go@@ -41,6 +41,26 @@ func doRequest(t *testing.T, h http.Handler, req *http.Request) *httptest.Responreturn rec}+func renderPortalHTML(t *testing.T, data portalPageData) string {+ t.Helper()+ rec := httptest.NewRecorder()+ renderPortalPage(rec, data.Nonce, data.Email, data.Accounts)+ if rec.Code != http.StatusOK {+ t.Fatalf("renderPortalPage returned %d", rec.Code)+ }+ return rec.Body.String()+}++func renderLoginHTML(t *testing.T, nonce string) string {+ t.Helper()+ rec := httptest.NewRecorder()+ renderLoginPage(rec, nonce)+ if rec.Code != http.StatusOK {+ t.Fatalf("renderLoginPage returned %d", rec.Code)+ }+ return rec.Body.String()+}+type dashboardResp struct {Account struct {ID string `json:"id"`@@ -604,11 +624,7 @@ func TestPortalPageTemplate_TeamManagementRendered(t *testing.T) {},}- var buf strings.Builder- if err := portalPageTmpl.Execute(&buf, data); err != nil {- t.Fatalf("template execute: %v", err)- }- html := buf.String()+ html := renderPortalHTML(t, data)// Account-specific markup (only rendered when CanManage=true).mustContain := []string{@@ -648,11 +664,7 @@ func TestPortalPageTemplate_TeamManagementHiddenForNonManagers(t *testing.T) {},}- var buf strings.Builder- if err := portalPageTmpl.Execute(&buf, data); err != nil {- t.Fatalf("template execute: %v", err)- }- html := buf.String()+ html := renderPortalHTML(t, data)// Account-specific team markup must NOT appear.mustNotContain := []string{@@ -686,11 +698,8 @@ func TestPortalPageTemplate_ActorRolePassedToSection(t *testing.T) {},},}- var buf strings.Builder- if err := portalPageTmpl.Execute(&buf, data); err != nil {- t.Fatalf("template execute: %v", err)- }- if !strings.Contains(buf.String(), `data-actor-role="`+role+`"`) {+ html := renderPortalHTML(t, data)+ if !strings.Contains(html, `data-actor-role="`+role+`"`) {t.Errorf("expected data-actor-role=%q in rendered HTML", role)}})@@ -713,11 +722,7 @@ func TestPortalPageTemplate_AccountServicesRendered(t *testing.T) {},}- var buf strings.Builder- if err := portalPageTmpl.Execute(&buf, data); err != nil {- t.Fatalf("template execute: %v", err)- }- html := buf.String()+ html := renderPortalHTML(t, data)mustContain := []string{"<title>Pulse Account</title>",@@ -749,11 +754,7 @@ func TestPortalPageTemplate_AccountServicesRendered(t *testing.T) {}func TestPortalLoginTemplate_UsesPulseAccountBranding(t *testing.T) {- var buf strings.Builder- if err := loginPageTmpl.Execute(&buf, struct{ Nonce string }{Nonce: "test-nonce"}); err != nil {- t.Fatalf("template execute: %v", err)- }- html := buf.String()+ html := renderLoginHTML(t, "test-nonce")mustContain := []string{"<title>Pulse Account — Sign In</title>",diff --git a/internal/cloudcp/portal/page.go b/internal/cloudcp/portal/page.goindex 1d44cd5c21..1917028edc 100644--- a/internal/cloudcp/portal/page.go+++ b/internal/cloudcp/portal/page.go@@ -1,6 +1,7 @@package portalimport (+ "html/template""net/http""time"@@ -38,6 +39,14 @@ type portalPageData struct {PublicSiteURL stringSupportEmail stringAccounts []portalPageAccount+ Styles template.CSS+ Script template.JS+}++type loginPageData struct {+ Nonce string+ Styles template.CSS+ Script template.JS}const (@@ -168,6 +177,8 @@ func renderPortalPage(w http.ResponseWriter, nonce, email string, accounts []porPublicSiteURL: defaultPublicSiteURL,SupportEmail: defaultSupportEmail,Accounts: accounts,+ Styles: portalStyles,+ Script: portalScript,}); err != nil {log.Error().Err(err).Msg("cloudcp.portal.page: render portal page")}@@ -176,7 +187,11 @@ func renderPortalPage(w http.ResponseWriter, nonce, email string, accounts []porfunc renderLoginPage(w http.ResponseWriter, nonce string) {w.Header().Set("Content-Type", "text/html; charset=utf-8")w.WriteHeader(http.StatusOK)- if err := loginPageTmpl.Execute(w, struct{ Nonce string }{Nonce: nonce}); err != nil {+ if err := loginPageTmpl.Execute(w, loginPageData{+ Nonce: nonce,+ Styles: loginStyles,+ Script: loginScript,+ }); err != nil {log.Error().Err(err).Msg("cloudcp.portal.page: render login page")}}diff --git a/internal/cloudcp/portal/page_templates.go b/internal/cloudcp/portal/page_templates.goindex 8fcb0841b5..39390866f5 100644--- a/internal/cloudcp/portal/page_templates.go+++ b/internal/cloudcp/portal/page_templates.go@@ -3,12 +3,33 @@ package portalimport ("embed""html/template"+ "io/fs")-//go:embed templates/portal.html templates/login.html+//go:embed templates/portal.html templates/login.html assets/portal.css assets/portal.js assets/login.css assets/login.jsvar portalTemplateFS embed.FSvar (portalPageTmpl = template.Must(template.ParseFS(portalTemplateFS, "templates/portal.html"))loginPageTmpl = template.Must(template.ParseFS(portalTemplateFS, "templates/login.html"))+ portalStyles = mustEmbeddedCSS("assets/portal.css")+ portalScript = mustEmbeddedJS("assets/portal.js")+ loginStyles = mustEmbeddedCSS("assets/login.css")+ loginScript = mustEmbeddedJS("assets/login.js"))++func mustEmbeddedCSS(path string) template.CSS {+ content, err := fs.ReadFile(portalTemplateFS, path)+ if err != nil {+ panic(err)+ }+ return template.CSS(string(content))+}++func mustEmbeddedJS(path string) template.JS {+ content, err := fs.ReadFile(portalTemplateFS, path)+ if err != nil {+ panic(err)+ }+ return template.JS(string(content))+}diff --git a/internal/cloudcp/portal/templates/login.html b/internal/cloudcp/portal/templates/login.htmlindex 2f3d3ab81a..8fdbe0e011 100644--- a/internal/cloudcp/portal/templates/login.html+++ b/internal/cloudcp/portal/templates/login.html@@ -4,23 +4,7 @@<meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Pulse Account — Sign In</title>- <style nonce="{{.Nonce}}">- :root { color-scheme: light; }- body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: linear-gradient(140deg, #f8fafc, #e2e8f0); color: #0f172a; display: flex; align-items: center; justify-content: center; min-height: 100vh; }- .card { background: #fff; border-radius: 12px; border: 1px solid #e2e8f0; box-shadow: 0 8px 30px rgba(15,23,42,.08); padding: 32px 28px; width: 100%; max-width: 400px; margin: 16px; }- .brand { font-size: 22px; font-weight: 700; margin-bottom: 6px; }- .subtitle { color: #64748b; font-size: 14px; margin-bottom: 24px; }- label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }- input { width: 100%; border: 1px solid #cbd5e1; border-radius: 8px; padding: 10px 12px; font-size: 15px; }- input:focus { outline: 2px solid #1d4ed8; border-color: transparent; }- .cta { margin-top: 14px; border: 0; border-radius: 10px; background: #1d4ed8; color: #fff; font-size: 15px; font-weight: 600; padding: 11px 16px; width: 100%; cursor: pointer; }- .cta:hover { background: #1e40af; }- .cta:disabled { opacity: 0.6; cursor: default; }- .success { background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 8px; padding: 14px; color: #166534; font-size: 14px; line-height: 1.5; display: none; margin-top: 14px; }- .error { background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; padding: 12px; color: #991b1b; font-size: 14px; display: none; margin-top: 14px; }- .footer { margin-top: 20px; text-align: center; font-size: 12px; color: #94a3b8; }- .footer a { color: #1d4ed8; text-decoration: none; }- </style>+ <style nonce="{{.Nonce}}">{{.Styles}}</style></head><body><div class="card">@@ -39,59 +23,6 @@New here? <a href="/signup">Create an account</a></div></div>-<script nonce="{{.Nonce}}">-var emailEl = document.getElementById('email');-var sendBtn = document.getElementById('send-btn');-var successEl = document.getElementById('success');-var errEl = document.getElementById('err-msg');--async function sendMagicLink() {- var email = emailEl.value.trim();- if (!email) { emailEl.focus(); return; }- sendBtn.disabled = true;- sendBtn.textContent = 'Sending…';- errEl.style.display = 'none';- try {- var r = await fetch('/api/public/magic-link/request', {- method: 'POST',- headers: { 'Content-Type': 'application/json' },- body: JSON.stringify({ email: email })- });- if (r.ok || r.status === 404) {- successEl.style.display = 'block';- sendBtn.style.display = 'none';- emailEl.style.display = 'none';- document.querySelector('label').style.display = 'none';- } else if (r.status === 429) {- errEl.textContent = 'Too many requests. Please wait a moment and try again.';- errEl.style.display = 'block';- sendBtn.disabled = false;- sendBtn.textContent = 'Send magic link';- } else {- errEl.textContent = 'Something went wrong. Please try again.';- errEl.style.display = 'block';- sendBtn.disabled = false;- sendBtn.textContent = 'Send magic link';- }- } catch (_) {- errEl.textContent = 'Network error. Please check your connection and try again.';- errEl.style.display = 'block';- sendBtn.disabled = false;- sendBtn.textContent = 'Send magic link';- }-}--sendBtn.onclick = sendMagicLink;-emailEl.addEventListener('keydown', function(e) { if (e.key === 'Enter') sendMagicLink(); });-document.getElementById('resend-link').onclick = function(e) {- e.preventDefault();- successEl.style.display = 'none';- sendBtn.style.display = '';- emailEl.style.display = '';- document.querySelector('label').style.display = '';- sendBtn.disabled = false;- sendBtn.textContent = 'Send magic link';-};-</script>+<script nonce="{{.Nonce}}">{{.Script}}</script></body></html>diff --git a/internal/cloudcp/portal/templates/portal.html b/internal/cloudcp/portal/templates/portal.htmlindex 1446ddfa7c..dca573e980 100644--- a/internal/cloudcp/portal/templates/portal.html+++ b/internal/cloudcp/portal/templates/portal.html@@ -3,117 +3,7 @@<meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Pulse Account</title>- <style nonce="{{.Nonce}}">- :root { color-scheme: light; }- * { box-sizing: border-box; }- body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: #f1f5f9; color: #0f172a; }- header { background: #1e293b; color: #f8fafc; padding: 12px 24px; display: flex; align-items: center; justify-content: space-between; }- header .brand { font-weight: 700; font-size: 18px; letter-spacing: -0.3px; }- header .user-info { display: flex; align-items: center; gap: 16px; font-size: 13px; color: #94a3b8; }- header .logout-btn { background: none; border: 1px solid #475569; color: #94a3b8; border-radius: 6px; padding: 5px 12px; cursor: pointer; font-size: 13px; }- header .logout-btn:hover { border-color: #94a3b8; color: #f8fafc; }- .main { max-width: 860px; margin: 32px auto; padding: 0 16px 48px; }- .account-section { margin-bottom: 40px; }- .account-header { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }- .account-header h2 { margin: 0; font-size: 20px; font-weight: 700; }- .badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.5px; }- .badge-msp { background: #dbeafe; color: #1e40af; }- .badge-cloud { background: #dcfce7; color: #166534; }- .badge-individual { background: #dcfce7; color: #166534; }- .badge-healthy { background: #dcfce7; color: #166534; }- .badge-unhealthy { background: #fee2e2; color: #991b1b; }- .badge-active { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }- .badge-suspended { background: #fef9c3; color: #854d0e; border: 1px solid #fef08a; }- .badge-failed { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }- .badge-provisioning { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }- .badge-canceled { background: #f1f5f9; color: #64748b; border: 1px solid #e2e8f0; }- .badge-deleting { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }- .workspace-list { display: flex; flex-direction: column; gap: 10px; }- .workspace-card { background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; box-shadow: 0 1px 3px rgba(15,23,42,.04); }- .workspace-card:hover { border-color: #cbd5e1; }- .ws-info { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }- .ws-name { font-weight: 600; font-size: 15px; }- .ws-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }- .ws-created { font-size: 11px; color: #94a3b8; }- .ws-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }- .btn-primary { background: #1d4ed8; color: #fff; border: 0; border-radius: 8px; padding: 8px 18px; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-block; }- .btn-primary:hover { background: #1e40af; }- .btn-secondary { background: #fff; color: #334155; border: 1px solid #cbd5e1; border-radius: 8px; padding: 7px 14px; font-size: 13px; font-weight: 500; cursor: pointer; }- .btn-secondary:hover { background: #f8fafc; border-color: #94a3b8; }- .btn-danger { background: #fff; color: #dc2626; border: 1px solid #fca5a5; border-radius: 8px; padding: 7px 14px; font-size: 13px; cursor: pointer; }- .btn-danger:hover { background: #fef2f2; }- .account-actions { margin-top: 14px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }- .add-workspace-form { margin-top: 12px; display: none; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 10px; padding: 16px; }- .add-workspace-form.visible { display: block; }- .add-workspace-form label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }- .add-workspace-form input { width: 100%; border: 1px solid #cbd5e1; border-radius: 8px; padding: 8px 12px; font-size: 14px; margin-bottom: 10px; }- .add-workspace-form .form-actions { display: flex; gap: 8px; }- .team-section { margin-top: 12px; display: none; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 10px; padding: 16px; }- .team-section.visible { display: block; }- .team-section h3 { margin: 0 0 12px; font-size: 15px; font-weight: 700; }- .team-table { width: 100%; border-collapse: collapse; font-size: 14px; }- .team-table th { text-align: left; font-size: 12px; font-weight: 600; color: #64748b; text-transform: uppercase; letter-spacing: 0.5px; padding: 6px 8px; border-bottom: 1px solid #e2e8f0; }- .team-table td { padding: 8px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }- .team-table select { border: 1px solid #cbd5e1; border-radius: 6px; padding: 4px 8px; font-size: 13px; background: #fff; }- .team-table .btn-remove { background: none; border: none; color: #dc2626; cursor: pointer; font-size: 13px; padding: 4px 8px; }- .team-table .btn-remove:hover { text-decoration: underline; }- .team-invite { margin-top: 12px; display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }- .team-invite label { font-size: 12px; font-weight: 600; display: block; margin-bottom: 4px; }- .team-invite input { border: 1px solid #cbd5e1; border-radius: 8px; padding: 8px 12px; font-size: 14px; min-width: 200px; }- .team-invite select { border: 1px solid #cbd5e1; border-radius: 6px; padding: 8px 10px; font-size: 14px; background: #fff; }- .intro-card { background: linear-gradient(145deg, #fff, #f8fafc); border: 1px solid #dbe4f0; border-radius: 16px; padding: 22px 24px; margin-bottom: 24px; box-shadow: 0 10px 24px rgba(15,23,42,.05); }- .intro-card h1 { margin: 0 0 8px; font-size: 26px; line-height: 1.1; }- .intro-card p { margin: 0; color: #475569; font-size: 15px; line-height: 1.6; max-width: 760px; }- .service-section { margin-top: 40px; }- .service-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }- .service-header h2 { margin: 0; font-size: 20px; font-weight: 700; }- .service-note { font-size: 13px; color: #64748b; max-width: 680px; }- .service-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }- .service-card { display: block; text-decoration: none; color: inherit; background: #fff; border: 1px solid #e2e8f0; border-radius: 12px; padding: 16px; box-shadow: 0 1px 3px rgba(15,23,42,.04); }- .service-card:hover { border-color: #93c5fd; box-shadow: 0 6px 18px rgba(29,78,216,.08); }- .service-card-button { width: 100%; text-align: left; border: 1px solid #e2e8f0; cursor: pointer; font: inherit; }- .service-card h3 { margin: 0 0 6px; font-size: 16px; font-weight: 700; }- .service-card p { margin: 0; font-size: 14px; color: #64748b; line-height: 1.5; }- .service-panel { display: none; margin-top: 14px; background: #fff; border: 1px solid #dbe4f0; border-radius: 12px; padding: 18px; }- .service-panel.visible { display: block; }- .service-panel h3 { margin: 0 0 8px; font-size: 17px; }- .service-panel p { margin: 0 0 14px; font-size: 14px; color: #64748b; }- .service-panel label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: #475569; }- .service-panel input, .service-panel textarea { width: 100%; border: 1px solid #cbd5e1; border-radius: 8px; padding: 10px 12px; font: inherit; box-sizing: border-box; background: #fff; color: #0f172a; }- .service-panel input:focus, .service-panel textarea:focus { outline: 2px solid #93c5fd; border-color: #1d4ed8; }- .service-panel textarea { min-height: 120px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }- .service-panel .form-group { margin-bottom: 14px; }- .service-panel .form-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }- .service-panel .helper-text { margin-top: 10px; font-size: 13px; color: #64748b; }- .service-panel .helper-text a { color: #1d4ed8; }- .service-panel .result-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-top: 14px; }- .service-panel .result-meta-label { font-size: 12px; color: #64748b; margin-bottom: 4px; }- .service-panel .result-meta-value { font-size: 14px; color: #0f172a; word-break: break-word; }- .service-panel .subsection { margin-top: 18px; padding-top: 18px; border-top: 1px solid #e2e8f0; }- .service-panel .subsection:first-of-type { margin-top: 0; padding-top: 0; border-top: none; }- .service-panel .subsection h4 { margin: 0 0 8px; font-size: 15px; font-weight: 700; }- .service-panel .warning { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; border-radius: 8px; padding: 12px; font-size: 13px; line-height: 1.5; margin-bottom: 12px; }- .service-panel .checkbox-row { display: flex; align-items: flex-start; gap: 10px; margin: 12px 0; }- .service-panel .checkbox-row input[type="checkbox"] { width: 18px; height: 18px; margin-top: 2px; flex-shrink: 0; }- .service-panel .checkbox-row span { font-size: 13px; color: #475569; line-height: 1.5; }- .service-status { margin-top: 12px; padding: 10px 12px; border-radius: 8px; font-size: 13px; display: none; }- .service-status.visible { display: block; }- .service-status.error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }- .service-status.success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }- .empty-state { background: #fff; border: 1px dashed #cbd5e1; border-radius: 10px; padding: 32px; text-align: center; color: #64748b; }- .empty-state p { margin: 0; font-size: 15px; }- .spinner { display: none; width: 18px; height: 18px; border: 2px solid #93c5fd; border-top-color: #1d4ed8; border-radius: 50%; animation: spin 0.6s linear infinite; }- @keyframes spin { to { transform: rotate(360deg); } }- .toast { position: fixed; bottom: 24px; right: 24px; background: #1e293b; color: #f8fafc; border-radius: 8px; padding: 12px 20px; font-size: 14px; display: none; z-index: 100; }- .toast.visible { display: block; animation: fadein 0.2s; }- @keyframes fadein { from { opacity: 0; transform: translateY(8px); } }- .toast.error { background: #991b1b; }- @media (max-width: 560px) {- .workspace-card { flex-direction: column; align-items: flex-start; }- .ws-actions { align-self: stretch; }- .ws-actions form, .ws-actions .btn-primary { width: 100%; text-align: center; }- }- </style>+ <style nonce="{{.Nonce}}">{{.Styles}}</style></head><body><header>@@ -410,569 +300,6 @@<div class="toast" id="toast"></div>-<script nonce="{{.Nonce}}">-const LICENSE_API_BASE = 'https://license.pulserelay.pro';--function showToast(msg, isError) {- var t = document.getElementById('toast');- t.textContent = msg;- t.className = 'toast visible' + (isError ? ' error' : '');- clearTimeout(t._timer);- t._timer = setTimeout(function() { t.className = 'toast'; }, 4000);-}--document.getElementById('logout-btn').onclick = async function() {- this.disabled = true;- this.textContent = 'Signing out…';- try {- await fetch('/auth/logout', { method: 'POST' });- } catch(_) {}- window.location.href = '/portal';-};--function toggleServicePanel(panelID) {- var panels = ['manage-service-panel', 'retrieve-service-panel', 'refund-service-panel', 'data-service-panel'];- for (var i = 0; i < panels.length; i++) {- var panel = document.getElementById(panels[i]);- panel.classList.toggle('visible', panels[i] === panelID ? !panel.classList.contains('visible') : false);- }-}--function setServiceStatus(id, message, isError) {- var el = document.getElementById(id);- el.textContent = message;- el.className = 'service-status visible' + (isError ? ' error' : ' success');-}--document.getElementById('open-manage-service').onclick = function() {- toggleServicePanel('manage-service-panel');- document.getElementById('manage-inline-email').focus();-};--document.getElementById('open-retrieve-service').onclick = function() {- toggleServicePanel('retrieve-service-panel');- document.getElementById('retrieve-inline-email').focus();-};--document.getElementById('open-refund-service').onclick = function() {- toggleServicePanel('refund-service-panel');- document.getElementById('refund-inline-email').focus();-};--document.getElementById('open-data-service').onclick = function() {- toggleServicePanel('data-service-panel');- document.getElementById('data-export-email').focus();-};--var pendingManageEmail = '';-var pendingRetrieveEmail = '';-var pendingExportEmail = '';-var pendingDeleteEmail = '';--document.getElementById('manage-inline-request').onclick = async function() {- var email = document.getElementById('manage-inline-email').value.trim();- if (!email) { document.getElementById('manage-inline-email').focus(); return; }- this.disabled = true;- this.textContent = 'Sending...';- try {- var res = await fetch(LICENSE_API_BASE + '/v1/manage/request', {- method: 'POST',- headers: { 'Content-Type': 'application/json' },- body: JSON.stringify({ email: email })- });- var data = await res.json();- if (!res.ok) throw new Error(data.error || 'Failed to send verification code');- pendingManageEmail = email;- document.getElementById('manage-inline-step2').style.display = 'block';- setServiceStatus('manage-inline-status', 'Verification code sent. Check your email.', false);- } catch (err) {- setServiceStatus('manage-inline-status', err.message, true);- } finally {- this.disabled = false;- this.textContent = 'Send Verification Code';- }-};--document.getElementById('manage-inline-resend').onclick = async function(e) {- e.preventDefault();- if (!pendingManageEmail) return;- try {- var res = await fetch(LICENSE_API_BASE + '/v1/manage/request', {- method: 'POST',- headers: { 'Content-Type': 'application/json' },- body: JSON.stringify({ email: pendingManageEmail })- });- var data = await res.json();- if (!res.ok) throw new Error(data.error || 'Failed to send verification code');- setServiceStatus('manage-inline-status', 'New verification code sent.', false);- } catch (err) {- setServiceStatus('manage-inline-status', err.message, true);- }-};--document.getElementById('manage-inline-confirm').onclick = async function() {- var code = document.getElementById('manage-inline-code').value.trim();- if (!pendingManageEmail || !code) return;- this.disabled = true;- this.textContent = 'Redirecting...';- try {- var res = await fetch(LICENSE_API_BASE + '/v1/manage', {- method: 'POST',- headers: { 'Content-Type': 'application/json' },- body: JSON.stringify({ email: pendingManageEmail, code: code })- });- var data = await res.json();- if (!res.ok) throw new Error(data.error || 'Failed to open customer portal');- window.location.href = data.url;- } catch (err) {- setServiceStatus('manage-inline-status', err.message, true);- this.disabled = false;- this.textContent = 'Open Customer Portal';- }-};--document.getElementById('retrieve-inline-request').onclick = async function() {- var email = document.getElementById('retrieve-inline-email').value.trim();- if (!email) { document.getElementById('retrieve-inline-email').focus(); return; }- this.disabled = true;- this.textContent = 'Sending...';- document.getElementById('retrieve-inline-result').style.display = 'none';- try {- var res = await fetch(LICENSE_API_BASE + '/v1/retrieve-license/request', {- method: 'POST',- headers: { 'Content-Type': 'application/json' },- body: JSON.stringify({ email: email })- });- var data = await res.json();- if (!res.ok) throw new Error(data.error || 'Failed to send verification code');- pendingRetrieveEmail = email;- document.getElementById('retrieve-inline-step2').style.display = 'block';- setServiceStatus('retrieve-inline-status', 'Verification code sent. Check your email.', false);- } catch (err) {- setServiceStatus('retrieve-inline-status', err.message, true);- } finally {- this.disabled = false;- this.textContent = 'Send Verification Code';- }-};--document.getElementById('retrieve-inline-confirm').onclick = async function() {- var code = document.getElementById('retrieve-inline-code').value.trim();- if (!pendingRetrieveEmail || !code) return;- this.disabled = true;- this.textContent = 'Loading...';- try {- var res = await fetch(LICENSE_API_BASE + '/v1/retrieve-license', {- method: 'POST',- headers: { 'Content-Type': 'application/json' },- body: JSON.stringify({ email: pendingRetrieveEmail, code: code })- });- var data = await res.json();- if (!res.ok) throw new Error(data.error || 'Failed to retrieve license');- var license = data.license;- document.getElementById('retrieve-inline-token').value = license.token;- document.getElementById('retrieve-inline-tier').textContent = license.tier;- document.getElementById('retrieve-inline-issued').textContent = new Date(license.issued_at).toLocaleString();- document.getElementById('retrieve-inline-expires').textContent = license.expires_at ? new Date(license.expires_at).toLocaleString() : 'Does not expire';- document.getElementById('retrieve-inline-email-value').textContent = license.email;- document.getElementById('retrieve-inline-result').style.display = 'block';- document.getElementById('retrieve-inline-copy').style.display = 'inline-block';- if (license.invoice_url) {- var invoice = document.getElementById('retrieve-inline-invoice');- invoice.href = license.invoice_url;- invoice.style.display = 'inline-block';- }- setServiceStatus('retrieve-inline-status', 'License retrieved successfully.', false);- } catch (err) {- setServiceStatus('retrieve-inline-status', err.message, true);- } finally {- this.disabled = false;- this.textContent = 'Show License';- }-};--document.getElementById('retrieve-inline-copy').onclick = async function() {- var token = document.getElementById('retrieve-inline-token').value;- if (!token) return;- try {- await navigator.clipboard.writeText(token);- setServiceStatus('retrieve-inline-status', 'License key copied to clipboard.', false);- } catch (_) {- setServiceStatus('retrieve-inline-status', 'Failed to copy automatically. Please copy the key manually.', true);- }-};--document.getElementById('refund-inline-submit').onclick = async function() {- var email = document.getElementById('refund-inline-email').value.trim();- var token = document.getElementById('refund-inline-token').value.trim();- if (!email || !token) return;- if (!confirm('Are you sure? This will immediately revoke the license and request the refund.')) return;- this.disabled = true;- this.textContent = 'Processing...';- try {- var res = await fetch(LICENSE_API_BASE + '/v1/self-refund', {- method: 'POST',- headers: { 'Content-Type': 'application/json' },- body: JSON.stringify({ email: email, token: token })- });- var data = await res.json();- if (!res.ok) throw new Error(data.error || 'Refund failed');- document.getElementById('refund-inline-token').value = '';- setServiceStatus('refund-inline-status', 'Success! Your refund has been processed. Stripe will follow up by email.', false);- } catch (err) {- setServiceStatus('refund-inline-status', err.message, true);- } finally {- this.disabled = false;- this.textContent = 'Process Refund';- }-};--document.getElementById('data-export-request').onclick = async function() {- var email = document.getElementById('data-export-email').value.trim();- if (!email) return;- this.disabled = true;- this.textContent = 'Sending...';- document.getElementById('data-export-result').style.display = 'none';- try {- var res = await fetch(LICENSE_API_BASE + '/v1/gdpr/request-export', {- method: 'POST',- headers: { 'Content-Type': 'application/json' },- body: JSON.stringify({ email: email })- });- var data = await res.json();- if (!res.ok) throw new Error(data.error || 'Request failed');- pendingExportEmail = email;- document.getElementById('data-export-step2').style.display = 'block';- setServiceStatus('data-export-status', 'Verification code sent. Check your email.', false);- } catch (err) {- setServiceStatus('data-export-status', err.message, true);- } finally {- this.disabled = false;- this.textContent = 'Send Verification Code';- }-};--document.getElementById('data-export-resend').onclick = async function(e) {- e.preventDefault();- if (!pendingExportEmail) return;- try {- var res = await fetch(LICENSE_API_BASE + '/v1/gdpr/request-export', {- method: 'POST',- headers: { 'Content-Type': 'application/json' },- body: JSON.stringify({ email: pendingExportEmail })- });- var data = await res.json();- if (!res.ok) throw new Error(data.error || 'Request failed');- setServiceStatus('data-export-status', 'New verification code sent.', false);- } catch (err) {- setServiceStatus('data-export-status', err.message, true);- }-};--document.getElementById('data-export-confirm').onclick = async function() {- var code = document.getElementById('data-export-code').value.trim();- if (!pendingExportEmail || !code) return;- this.disabled = true;- this.textContent = 'Exporting...';- try {- var res = await fetch(LICENSE_API_BASE + '/v1/gdpr/export', {- method: 'POST',- headers: { 'Content-Type': 'application/json' },- body: JSON.stringify({ email: pendingExportEmail, code: code })- });- var data = await res.json();- if (!res.ok) throw new Error(data.error || 'Export failed');- document.getElementById('data-export-payload').value = JSON.stringify(data, null, 2);- document.getElementById('data-export-result').style.display = 'block';- setServiceStatus('data-export-status', 'Data export retrieved successfully.', false);- document.getElementById('data-export-code').value = '';- pendingExportEmail = '';- document.getElementById('data-export-step2').style.display = 'none';- } catch (err) {- setServiceStatus('data-export-status', err.message, true);- } finally {- this.disabled = false;- this.textContent = 'Export My Data';- }-};--document.getElementById('data-delete-request').onclick = async function() {- var email = document.getElementById('data-delete-email').value.trim();- if (!email) return;- this.disabled = true;- this.textContent = 'Sending...';- try {- var res = await fetch(LICENSE_API_BASE + '/v1/gdpr/request-delete', {- method: 'POST',- headers: { 'Content-Type': 'application/json' },- body: JSON.stringify({ email: email })- });- var data = await res.json();- if (!res.ok) throw new Error(data.error || 'Request failed');- pendingDeleteEmail = email;- document.getElementById('data-delete-step2').style.display = 'block';- setServiceStatus('data-delete-status', 'Verification code sent. Check your email.', false);- } catch (err) {- setServiceStatus('data-delete-status', err.message, true);- } finally {- this.disabled = false;- this.textContent = 'Send Verification Code';- }-};--document.getElementById('data-delete-resend').onclick = async function(e) {- e.preventDefault();- if (!pendingDeleteEmail) return;- try {- var res = await fetch(LICENSE_API_BASE + '/v1/gdpr/request-delete', {- method: 'POST',- headers: { 'Content-Type': 'application/json' },- body: JSON.stringify({ email: pendingDeleteEmail })- });- var data = await res.json();- if (!res.ok) throw new Error(data.error || 'Request failed');- setServiceStatus('data-delete-status', 'New verification code sent.', false);- } catch (err) {- setServiceStatus('data-delete-status', err.message, true);- }-};--document.getElementById('data-delete-confirm').onclick = async function() {- var code = document.getElementById('data-delete-code').value.trim();- if (!pendingDeleteEmail || !code) return;- if (!document.getElementById('data-delete-confirm-check').checked) {- setServiceStatus('data-delete-status', 'You must confirm that you understand this action is permanent.', true);- return;- }- this.disabled = true;- this.textContent = 'Deleting...';- try {- var res = await fetch(LICENSE_API_BASE + '/v1/gdpr/confirm-delete', {- method: 'POST',- headers: { 'Content-Type': 'application/json' },- body: JSON.stringify({ email: pendingDeleteEmail, code: code })- });- var data = await res.json();- if (!res.ok) throw new Error(data.error || 'Deletion failed');- setServiceStatus('data-delete-status', data.deleted_count > 0 && data.stripe_reminder ? data.message + ' ' + data.stripe_reminder : data.message, false);- document.getElementById('data-delete-step2').style.display = 'none';- document.getElementById('data-delete-code').value = '';- document.getElementById('data-delete-confirm-check').checked = false;- pendingDeleteEmail = '';- } catch (err) {- setServiceStatus('data-delete-status', err.message, true);- } finally {- this.disabled = false;- this.textContent = 'Delete My Data';- }-};--function toggleAddWorkspace(accountID) {- var form = document.getElementById('add-ws-form-' + accountID);- var visible = form.classList.contains('visible');- form.classList.toggle('visible', !visible);- if (!visible) {- document.getElementById('ws-name-' + accountID).focus();- }-}--async function createWorkspace(accountID) {- var nameEl = document.getElementById('ws-name-' + accountID);- var name = nameEl.value.trim();- if (!name) { nameEl.focus(); return; }- var spinner = document.getElementById('ws-spinner-' + accountID);- spinner.style.display = 'block';- try {- var resp = await fetch('/api/accounts/' + accountID + '/tenants', {- method: 'POST',- headers: { 'Content-Type': 'application/json' },- body: JSON.stringify({ display_name: name })- });- if (!resp.ok) {- var err = await resp.json().catch(function() { return {}; });- showToast((err && err.error) || 'Failed to create workspace', true);- return;- }- showToast('Workspace created!');- setTimeout(function() { window.location.reload(); }, 800);- } catch(e) {- showToast('Network error. Please try again.', true);- } finally {- spinner.style.display = 'none';- }-}--function suspendOrDelete(evt, accountID, tenantID, state, name) {- evt.stopPropagation();- var action = state === 'active' ? 'Suspend' : 'Delete';- if (!confirm(action + ' workspace "' + name + '"?')) return;- var method = state === 'active' ? 'PATCH' : 'DELETE';- var body = state === 'active' ? JSON.stringify({ state: 'suspended' }) : undefined;- fetch('/api/accounts/' + accountID + '/tenants/' + tenantID, {- method: method,- headers: body ? { 'Content-Type': 'application/json' } : {},- body: body- }).then(function(r) {- if (r.ok) {- showToast(action + 'd workspace.');- setTimeout(function() { window.location.reload(); }, 800);- } else {- showToast('Failed to ' + action.toLowerCase() + ' workspace.', true);- }- }).catch(function() {- showToast('Network error.', true);- });-}--async function openBilling(accountID) {- try {- var r = await fetch('/api/portal/billing?account_id=' + encodeURIComponent(accountID), { method: 'POST' });- if (!r.ok) {- var err = await r.json().catch(function() { return {}; });- showToast((err && err.error) || 'Failed to open billing portal.', true);- return;- }- var data = await r.json();- if (data && data.url) {- window.location.href = data.url;- } else {- showToast('Failed to open billing portal.', true);- }- } catch(e) {- showToast('Network error.', true);- }-}--function toggleTeam(accountID) {- var section = document.getElementById('team-section-' + accountID);- var visible = section.classList.contains('visible');- section.classList.toggle('visible', !visible);- if (!visible) loadTeam(accountID);-}--function setTbodyMessage(tbody, msg, isError) {- tbody.textContent = '';- var tr = document.createElement('tr');- var td = document.createElement('td');- td.setAttribute('colspan', '3');- td.style.cssText = 'text-align:center;padding:16px;color:' + (isError ? '#991b1b' : '#94a3b8');- td.textContent = msg;- tr.appendChild(td);- tbody.appendChild(tr);-}--async function loadTeam(accountID) {- var tbody = document.getElementById('team-list-' + accountID);- var section = document.getElementById('team-section-' + accountID);- var actorRole = section.getAttribute('data-actor-role') || '';- var isOwner = actorRole === 'owner';- setTbodyMessage(tbody, 'Loading\u2026', false);- try {- var r = await fetch('/api/accounts/' + encodeURIComponent(accountID) + '/members');- if (!r.ok) { setTbodyMessage(tbody, 'Failed to load team.', true); return; }- var members = await r.json();- if (!members || members.length === 0) {- setTbodyMessage(tbody, 'No team members.', false);- return;- }- var allRoles = ['owner','admin','tech','read_only'];- var nonOwnerRoles = ['admin','tech','read_only'];- tbody.textContent = '';- for (var i = 0; i < members.length; i++) {- (function(m) {- var tr = document.createElement('tr');- var tdEmail = document.createElement('td');- tdEmail.textContent = m.email;- tr.appendChild(tdEmail);- var tdRole = document.createElement('td');- if (m.role === 'owner' && !isOwner) {- tdRole.textContent = 'owner';- } else {- var sel = document.createElement('select');- var roles = isOwner ? allRoles : nonOwnerRoles;- for (var j = 0; j < roles.length; j++) {- var opt = document.createElement('option');- opt.value = roles[j];- opt.textContent = roles[j].replace('_', ' ');- if (m.role === roles[j]) opt.selected = true;- sel.appendChild(opt);- }- sel.addEventListener('change', function() { changeRole(accountID, m.user_id, this.value); });- tdRole.appendChild(sel);- }- tr.appendChild(tdRole);- var tdAction = document.createElement('td');- if (!(m.role === 'owner' && !isOwner)) {- var btn = document.createElement('button');- btn.className = 'btn-remove';- btn.textContent = 'Remove';- btn.addEventListener('click', function() { removeMember(accountID, m.user_id, m.email); });- tdAction.appendChild(btn);- }- tr.appendChild(tdAction);- tbody.appendChild(tr);- })(members[i]);- }- } catch(e) {- setTbodyMessage(tbody, 'Network error.', true);- }-}--async function inviteMember(accountID) {- var emailEl = document.getElementById('invite-email-' + accountID);- var roleEl = document.getElementById('invite-role-' + accountID);- var email = emailEl.value.trim();- if (!email) { emailEl.focus(); return; }- try {- var r = await fetch('/api/accounts/' + encodeURIComponent(accountID) + '/members', {- method: 'POST',- headers: { 'Content-Type': 'application/json' },- body: JSON.stringify({ email: email, role: roleEl.value })- });- if (r.status === 409) { showToast('Member already exists.', true); return; }- if (!r.ok) {- var err = await r.text();- showToast(err || 'Failed to invite member.', true);- return;- }- emailEl.value = '';- showToast('Member invited!');- loadTeam(accountID);- } catch(e) {- showToast('Network error.', true);- }-}--async function changeRole(accountID, userID, newRole) {- try {- var r = await fetch('/api/accounts/' + encodeURIComponent(accountID) + '/members/' + encodeURIComponent(userID), {- method: 'PATCH',- headers: { 'Content-Type': 'application/json' },- body: JSON.stringify({ role: newRole })- });- if (r.status === 409) { showToast('Cannot demote last owner.', true); loadTeam(accountID); return; }- if (!r.ok) { showToast('Failed to update role.', true); loadTeam(accountID); return; }- showToast('Role updated.');- } catch(e) {- showToast('Network error.', true);- loadTeam(accountID);- }-}--async function removeMember(accountID, userID, email) {- if (!confirm('Remove ' + email + ' from this account?')) return;- try {- var r = await fetch('/api/accounts/' + encodeURIComponent(accountID) + '/members/' + encodeURIComponent(userID), {- method: 'DELETE'- });- if (r.status === 409) { showToast('Cannot remove last owner.', true); return; }- if (!r.ok) { showToast('Failed to remove member.', true); return; }- showToast('Member removed.');- loadTeam(accountID);- } catch(e) {- showToast('Network error.', true);- }-}-</script>+<script nonce="{{.Nonce}}">{{.Script}}</script></body></html>