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): split Pulse Account shell views
rcourtman3e12a5a789ca
diff --git a/internal/cloudcp/portal/dist/build_manifest.json b/internal/cloudcp/portal/dist/build_manifest.jsonindex 8ff10a6612..b57053052f 100644--- a/internal/cloudcp/portal/dist/build_manifest.json+++ b/internal/cloudcp/portal/dist/build_manifest.json@@ -1,5 +1,5 @@{- "source_hash": "649178debfd541a371f48db730d2beb552cc2d4a37467fd2c88f7732d5563313",+ "source_hash": "02327e893b4f909b2352c5c218a0f4600c7d1dba1b38d3fc8daeb1249dde2672","build_inputs": ["package.json","tsconfig.json",@@ -7,6 +7,7 @@"src/index.ts","src/account_controller.ts","src/shell.ts",+ "src/shell_view.ts","src/services.ts","src/runtime.ts","src/types.ts",diff --git a/internal/cloudcp/portal/dist/portal_app.js b/internal/cloudcp/portal/dist/portal_app.jsindex da0aeacb5a..d35bef363f 100644--- a/internal/cloudcp/portal/dist/portal_app.js+++ b/internal/cloudcp/portal/dist/portal_app.js@@ -418,28 +418,7 @@});}- // src/shell.ts- var portalBootstrap = getBootstrap();- var LICENSE_API_BASE = getCommercialAPIBaseURL();- var PORTAL_PATH = getPortalPath();- var BOOTSTRAP_PATH = getBootstrapPath();- var MAGIC_LINK_REQUEST_PATH = getMagicLinkRequestPath();- var SIGNUP_PATH = getSignupPath();- var LOGOUT_PATH = getLogoutPath();- var ACCOUNT_API_BASE_PATH = getAccountAPIBasePath();- var PORTAL_API_BASE_PATH = getPortalAPIBasePath();- var loginState = {- emailValue: "",- sending: false,- success: false,- error: ""- };- function getElement2(id) {- return document.getElementById(id);- }- function asHTMLElement2(target) {- return target instanceof HTMLElement ? target : null;- }+ // src/shell_view.tsfunction escapeHTML(value) {return String(value || "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");}@@ -448,7 +427,7 @@}function formatWorkspaceDate(value) {if (!value) return "";- var date = new Date(value);+ var date = new Date(String(value));if (Number.isNaN(date.getTime())) return "";return date.toLocaleDateString(void 0, { month: "short", day: "numeric", year: "numeric" });}@@ -458,22 +437,13 @@if (role === "tech") return '<span class="badge" style="background:#f1f5f9;color:#64748b">Tech</span>';return "";}- function renderHeader() {- var userInfo = document.getElementById("portal-user-info");- if (!userInfo) return;- if (portalBootstrap.authenticated) {- userInfo.innerHTML = "<span>" + escapeHTML(portalBootstrap.email || "") + '</span><button class="logout-btn" id="logout-btn" type="button">Sign out</button>';- return;- }- userInfo.innerHTML = '<a class="logout-btn" href="' + escapeAttr(SIGNUP_PATH) + '" style="text-decoration:none">Create account</a>';- }- function renderWorkspaceCard(account, workspace) {+ function renderWorkspaceCard(account, workspace, accountAPIBasePath) {var state = String(workspace.state || "");var safeState = escapeHTML(state);var createdLabel = formatWorkspaceDate(workspace.created_at);var openAction = "";if (state === "active") {- openAction = '<form method="POST" action="' + escapeAttr(ACCOUNT_API_BASE_PATH + "/" + account.id + "/tenants/" + workspace.id + "/handoff") + '"><button type="submit" class="btn-primary">Open \u2192</button></form>';+ openAction = '<form method="POST" action="' + escapeAttr(accountAPIBasePath + "/" + account.id + "/tenants/" + workspace.id + "/handoff") + '"><button type="submit" class="btn-primary">Open \u2192</button></form>';} else {openAction = '<span style="font-size:13px;color:#94a3b8">' + safeState + "</span>";}@@ -484,14 +454,14 @@var createdMeta = createdLabel ? '<span class="ws-created">Created ' + escapeHTML(createdLabel) + "</span>" : "";return '<div class="workspace-card"><div class="ws-info"><span class="ws-name">' + escapeHTML(workspace.display_name) + '</span><div class="ws-meta">' + (workspace.healthy ? '<span class="badge badge-healthy">Healthy</span>' : '<span class="badge badge-unhealthy">Checking</span>') + '<span class="badge badge-' + safeState + '">' + safeState + "</span>" + createdMeta + '</div></div><div class="ws-actions">' + openAction + manageAction + "</div></div>";}- function renderAccountSection(account) {+ function renderAccountSection(account, accountAPIBasePath) {var workspaces = Array.isArray(account.workspaces) ? account.workspaces : [];var workspaceHTML = "";if (workspaces.length === 0) {workspaceHTML = '<div class="empty-state"><p>No workspaces yet. Create one to get started.</p></div>';} else {workspaceHTML = '<div class="workspace-list">' + workspaces.map(function(workspace) {- return renderWorkspaceCard(account, workspace);+ return renderWorkspaceCard(account, workspace, accountAPIBasePath);}).join("") + "</div>";}var actions = "";@@ -506,36 +476,77 @@}return '<section class="account-section"><div class="account-header"><h2>' + escapeHTML(account.name) + '</h2><span class="badge badge-' + escapeHTML(account.kind) + '">' + escapeHTML(account.kind_label) + "</span>" + roleBadgeHTML(account.role) + "</div>" + workspaceHTML + actions + teamSection + addWorkspaceForm + "</section>";}- function renderAccounts(accounts) {- var root = document.getElementById("accounts-root");- if (!root) return;- var safeAccounts = Array.isArray(accounts) ? accounts : [];+ function renderHeaderHTML(context) {+ if (context.bootstrap.authenticated) {+ return "<span>" + escapeHTML(context.bootstrap.email || "") + '</span><button class="logout-btn" id="logout-btn" type="button">Sign out</button>';+ }+ return '<a class="logout-btn" href="' + escapeAttr(context.signupPath) + '" style="text-decoration:none">Create account</a>';+ }+ function renderAccountsHTML(context) {+ var safeAccounts = Array.isArray(context.bootstrap.accounts) ? context.bootstrap.accounts : [];if (safeAccounts.length === 0) {- root.innerHTML = '<div class="empty-state" style="margin-top:48px"><p>No workspaces found. If you just signed up, check your email for setup instructions.</p><p style="margin-top:12px;font-size:13px">Need help? Contact <a href="mailto:' + escapeAttr(portalBootstrap.support_email || "") + '" style="color:#1d4ed8">' + escapeHTML(portalBootstrap.support_email || "") + "</a></p></div>";- return;+ return '<div class="empty-state" style="margin-top:48px"><p>No workspaces found. If you just signed up, check your email for setup instructions.</p><p style="margin-top:12px;font-size:13px">Need help? Contact <a href="mailto:' + escapeAttr(context.bootstrap.support_email || "") + '" style="color:#1d4ed8">' + escapeHTML(context.bootstrap.support_email || "") + "</a></p></div>";}- root.innerHTML = safeAccounts.map(renderAccountSection).join("");+ return safeAccounts.map(function(account) {+ return renderAccountSection(account, context.accountAPIBasePath);+ }).join("");}- function renderAuthenticatedPortal() {- return '<section class="intro-card"><h1>Pulse Account</h1><p>Manage Cloud workspaces, MSP access, and self-hosted commercial account services from one account surface. Hosted workspace lifecycle lives here today, and the self-hosted billing, license recovery, refund, and privacy tools below now share the same Pulse Account shell instead of staying fragmented across public utility pages.</p></section><div id="accounts-root"></div><section class="service-section"><div class="service-header"><h2>Other account services</h2><div class="service-note">Self-hosted commercial account actions now live here. The public utility pages remain as compatibility entry points, not the primary account surface.</div></div><div class="service-grid"><button class="service-card service-card-button" type="button" id="open-manage-service" data-account-service-action="open-service-panel" data-account-service-panel="manage-service-panel" data-account-service-focus="manage-inline-email"><h3>Manage subscriptions</h3><p>Open Stripe billing access for existing self-hosted subscriptions without leaving the Pulse Account shell.</p></button><button class="service-card service-card-button" type="button" id="open-retrieve-service" data-account-service-action="open-service-panel" data-account-service-panel="retrieve-service-panel" data-account-service-focus="retrieve-inline-email"><h3>Retrieve licenses</h3><p>Recover the latest active self-hosted license and invoice link for a commercial email address.</p></button><button class="service-card service-card-button" type="button" id="open-refund-service" data-account-service-action="open-service-panel" data-account-service-panel="refund-service-panel" data-account-service-focus="refund-inline-email"><h3>Refund requests</h3><p>Request an immediate self-serve refund for eligible self-hosted purchases with explicit revocation confirmation.</p></button><button class="service-card service-card-button" type="button" id="open-data-service" data-account-service-action="open-service-panel" data-account-service-panel="data-service-panel" data-account-service-focus="data-export-email"><h3>Data and privacy</h3><p>Request commercial data export or deletion without leaving the account shell.</p></button></div><div class="service-panel" id="manage-service-panel"><div id="manage-service-root"></div></div><div class="service-panel" id="retrieve-service-panel"><div id="retrieve-service-root"></div></div><div class="service-panel" id="refund-service-panel"><div id="refund-service-root"></div></div><div class="service-panel" id="data-service-panel"><h3>Data and privacy</h3><p>Request export or deletion of the commercial data tied to an email address. Payment data held directly by Stripe still requires support handling.</p><div class="subsection"><div id="data-export-root"></div></div><div class="subsection"><div id="data-delete-root"></div></div><div class="helper-text">Payment-card data stays with Stripe. For Stripe deletion support, contact <a href="mailto:' + escapeAttr(portalBootstrap.support_email || "") + '">' + escapeHTML(portalBootstrap.support_email || "") + "</a>.</div></div></section>";+ function renderAuthenticatedPortalHTML(context) {+ return '<section class="intro-card"><h1>Pulse Account</h1><p>Manage Cloud workspaces, MSP access, and self-hosted commercial account services from one account surface. Hosted workspace lifecycle lives here today, and the self-hosted billing, license recovery, refund, and privacy tools below now share the same Pulse Account shell instead of staying fragmented across public utility pages.</p></section><div id="accounts-root">' + renderAccountsHTML(context) + '</div><section class="service-section"><div class="service-header"><h2>Other account services</h2><div class="service-note">Self-hosted commercial account actions now live here. The public utility pages remain as compatibility entry points, not the primary account surface.</div></div><div class="service-grid"><button class="service-card service-card-button" type="button" id="open-manage-service" data-account-service-action="open-service-panel" data-account-service-panel="manage-service-panel" data-account-service-focus="manage-inline-email"><h3>Manage subscriptions</h3><p>Open Stripe billing access for existing self-hosted subscriptions without leaving the Pulse Account shell.</p></button><button class="service-card service-card-button" type="button" id="open-retrieve-service" data-account-service-action="open-service-panel" data-account-service-panel="retrieve-service-panel" data-account-service-focus="retrieve-inline-email"><h3>Retrieve licenses</h3><p>Recover the latest active self-hosted license and invoice link for a commercial email address.</p></button><button class="service-card service-card-button" type="button" id="open-refund-service" data-account-service-action="open-service-panel" data-account-service-panel="refund-service-panel" data-account-service-focus="refund-inline-email"><h3>Refund requests</h3><p>Request an immediate self-serve refund for eligible self-hosted purchases with explicit revocation confirmation.</p></button><button class="service-card service-card-button" type="button" id="open-data-service" data-account-service-action="open-service-panel" data-account-service-panel="data-service-panel" data-account-service-focus="data-export-email"><h3>Data and privacy</h3><p>Request commercial data export or deletion without leaving the account shell.</p></button></div><div class="service-panel" id="manage-service-panel"><div id="manage-service-root"></div></div><div class="service-panel" id="retrieve-service-panel"><div id="retrieve-service-root"></div></div><div class="service-panel" id="refund-service-panel"><div id="refund-service-root"></div></div><div class="service-panel" id="data-service-panel"><h3>Data and privacy</h3><p>Request export or deletion of the commercial data tied to an email address. Payment data held directly by Stripe still requires support handling.</p><div class="subsection"><div id="data-export-root"></div></div><div class="subsection"><div id="data-delete-root"></div></div><div class="helper-text">Payment-card data stays with Stripe. For Stripe deletion support, contact <a href="mailto:' + escapeAttr(context.bootstrap.support_email || "") + '">' + escapeHTML(context.bootstrap.support_email || "") + "</a>.</div></div></section>";}- function renderSignedOutPortal() {+ function renderSignedOutPortalHTML(context) {var statusHTML = "";- if (loginState.error) {- statusHTML = '<div class="service-status visible error">' + escapeHTML(loginState.error) + "</div>";- } else if (loginState.success) {+ if (context.loginState.error) {+ statusHTML = '<div class="service-status visible error">' + escapeHTML(context.loginState.error) + "</div>";+ } else if (context.loginState.success) {statusHTML = `<div class="service-status visible success">Magic link sent. Check your inbox and click the link to sign in.<br><br><strong>Don't see it?</strong> <a href="#" data-portal-action="resend-magic-link">Send a new link</a>.</div>`;}- return '<section class="intro-card"><h1>Pulse Account</h1><p>Sign in to manage Cloud workspaces, MSP access, and commercial account services from one account surface.</p></section><section class="service-section"><div class="service-panel visible"><h3>Sign in</h3><p>Enter the commercial email address for your Pulse account. I will send a magic link so you can open Pulse Account without managing a password.</p><div class="form-group"><label for="portal-login-email">Email address</label><input id="portal-login-email" type="email" autocomplete="email" placeholder="[email protected]" value="' + escapeAttr(loginState.emailValue || "") + '" data-portal-input="login-email"></div><div class="form-actions"><button class="btn-primary" id="portal-login-send" type="button" data-portal-action="send-magic-link">' + (loginState.sending ? "Sending\u2026" : "Send magic link") + '</button><a class="btn-secondary" href="' + escapeAttr(SIGNUP_PATH) + '" style="text-decoration:none">Create an account</a></div>' + statusHTML + "</div></section>";+ return '<section class="intro-card"><h1>Pulse Account</h1><p>Sign in to manage Cloud workspaces, MSP access, and commercial account services from one account surface.</p></section><section class="service-section"><div class="service-panel visible"><h3>Sign in</h3><p>Enter the commercial email address for your Pulse account. I will send a magic link so you can open Pulse Account without managing a password.</p><div class="form-group"><label for="portal-login-email">Email address</label><input id="portal-login-email" type="email" autocomplete="email" placeholder="[email protected]" value="' + escapeAttr(context.loginState.emailValue || "") + '" data-portal-input="login-email"></div><div class="form-actions"><button class="btn-primary" id="portal-login-send" type="button" data-portal-action="send-magic-link">' + (context.loginState.sending ? "Sending\u2026" : "Send magic link") + '</button><a class="btn-secondary" href="' + escapeAttr(context.signupPath) + '" style="text-decoration:none">Create an account</a></div>' + statusHTML + "</div></section>";+ }++ // src/shell.ts+ var portalBootstrap = getBootstrap();+ var LICENSE_API_BASE = getCommercialAPIBaseURL();+ var PORTAL_PATH = getPortalPath();+ var BOOTSTRAP_PATH = getBootstrapPath();+ var MAGIC_LINK_REQUEST_PATH = getMagicLinkRequestPath();+ var SIGNUP_PATH = getSignupPath();+ var LOGOUT_PATH = getLogoutPath();+ var ACCOUNT_API_BASE_PATH = getAccountAPIBasePath();+ var PORTAL_API_BASE_PATH = getPortalAPIBasePath();+ var loginState = {+ emailValue: "",+ sending: false,+ success: false,+ error: ""+ };+ function getElement2(id) {+ return document.getElementById(id);+ }+ function asHTMLElement2(target) {+ return target instanceof HTMLElement ? target : null;+ }+ function renderHeader() {+ var userInfo = document.getElementById("portal-user-info");+ if (!userInfo) return;+ userInfo.innerHTML = renderHeaderHTML({+ bootstrap: portalBootstrap,+ loginState,+ signupPath: SIGNUP_PATH,+ accountAPIBasePath: ACCOUNT_API_BASE_PATH+ });}function renderPortalApp() {renderHeader();var root = document.getElementById("portal-app-root");if (!root) return;- root.innerHTML = portalBootstrap.authenticated ? renderAuthenticatedPortal() : renderSignedOutPortal();- if (portalBootstrap.authenticated) {- renderAccounts(portalBootstrap.accounts || []);- }+ var context = {+ bootstrap: portalBootstrap,+ loginState,+ signupPath: SIGNUP_PATH,+ accountAPIBasePath: ACCOUNT_API_BASE_PATH+ };+ root.innerHTML = portalBootstrap.authenticated ? renderAuthenticatedPortalHTML(context) : renderSignedOutPortalHTML(context);notifyPortalRender();}function applyBootstrap(data) {diff --git a/internal/cloudcp/portal/frontend/build.mjs b/internal/cloudcp/portal/frontend/build.mjsindex 72d3a8609f..8aa6028bf0 100644--- a/internal/cloudcp/portal/frontend/build.mjs+++ b/internal/cloudcp/portal/frontend/build.mjs@@ -20,6 +20,7 @@ const buildInputs = ['src/index.ts','src/account_controller.ts','src/shell.ts',+ 'src/shell_view.ts','src/services.ts','src/runtime.ts','src/types.ts',diff --git a/internal/cloudcp/portal/frontend/src/shell.ts b/internal/cloudcp/portal/frontend/src/shell.tsindex 91ba6790bf..b12631273d 100644--- a/internal/cloudcp/portal/frontend/src/shell.ts+++ b/internal/cloudcp/portal/frontend/src/shell.ts@@ -13,6 +13,11 @@ import {setBootstrap,} from './runtime';import { installAccountController } from './account_controller';+import {+ renderAuthenticatedPortalHTML,+ renderHeaderHTML,+ renderSignedOutPortalHTML,+} from './shell_view';import type { PortalBootstrapData, PortalLoginState } from './types';var portalBootstrap: PortalBootstrapData = getBootstrap();@@ -43,322 +48,30 @@ function asHTMLElement(target: EventTarget | null): HTMLElement | null {return target instanceof HTMLElement ? target : null;}-function escapeHTML(value) {- return String(value || '')- .replace(/&/g, '&')- .replace(/</g, '<')- .replace(/>/g, '>')- .replace(/"/g, '"')- .replace(/'/g, ''');-}--function escapeAttr(value) {- return escapeHTML(value);-}--function formatWorkspaceDate(value) {- if (!value) return '';- var date = new Date(value);- if (Number.isNaN(date.getTime())) return '';- return date.toLocaleDateString(undefined, { month: 'short', day: 'numeric', year: 'numeric' });-}--function roleBadgeHTML(role) {- if (role === 'owner') return '<span class="badge" style="background:#f1f5f9;color:#64748b">Owner</span>';- if (role === 'admin') return '<span class="badge" style="background:#f1f5f9;color:#64748b">Admin</span>';- if (role === 'tech') return '<span class="badge" style="background:#f1f5f9;color:#64748b">Tech</span>';- return '';-}-function renderHeader() {var userInfo = document.getElementById('portal-user-info');if (!userInfo) return;- if (portalBootstrap.authenticated) {- userInfo.innerHTML =- '<span>' + escapeHTML(portalBootstrap.email || '') + '</span>' +- '<button class="logout-btn" id="logout-btn" type="button">Sign out</button>';- return;- }- userInfo.innerHTML =- '<a class="logout-btn" href="' + escapeAttr(SIGNUP_PATH) + '" style="text-decoration:none">Create account</a>';-}--function renderWorkspaceCard(account, workspace) {- var state = String(workspace.state || '');- var safeState = escapeHTML(state);- var createdLabel = formatWorkspaceDate(workspace.created_at);- var openAction = '';- if (state === 'active') {- openAction =- '<form method="POST" action="' +- escapeAttr(ACCOUNT_API_BASE_PATH + '/' + account.id + '/tenants/' + workspace.id + '/handoff') +- '">' +- '<button type="submit" class="btn-primary">Open →</button>' +- '</form>';- } else {- openAction = '<span style="font-size:13px;color:#94a3b8">' + safeState + '</span>';- }-- var manageAction = '';- if (account.can_manage && (state === 'active' || state === 'suspended' || state === 'failed')) {- manageAction =- '<button type="button" class="btn-danger" data-action="workspace-manage" data-account-id="' +- escapeAttr(account.id) +- '" data-workspace-id="' +- escapeAttr(workspace.id) +- '" data-workspace-state="' +- escapeAttr(state) +- '" data-workspace-name="' +- escapeAttr(workspace.display_name) +- '">⋯</button>';- }-- var createdMeta = createdLabel ? '<span class="ws-created">Created ' + escapeHTML(createdLabel) + '</span>' : '';- return (- '<div class="workspace-card">' +- '<div class="ws-info">' +- '<span class="ws-name">' + escapeHTML(workspace.display_name) + '</span>' +- '<div class="ws-meta">' +- (workspace.healthy- ? '<span class="badge badge-healthy">Healthy</span>'- : '<span class="badge badge-unhealthy">Checking</span>') +- '<span class="badge badge-' + safeState + '">' + safeState + '</span>' +- createdMeta +- '</div>' +- '</div>' +- '<div class="ws-actions">' +- openAction +- manageAction +- '</div>' +- '</div>'- );-}--function renderAccountSection(account) {- var workspaces = Array.isArray(account.workspaces) ? account.workspaces : [];- var workspaceHTML = '';- if (workspaces.length === 0) {- workspaceHTML = '<div class="empty-state"><p>No workspaces yet. Create one to get started.</p></div>';- } else {- workspaceHTML =- '<div class="workspace-list">' +- workspaces.map(function(workspace) {- return renderWorkspaceCard(account, workspace);- }).join('') +- '</div>';- }-- var actions = '';- var teamSection = '';- var addWorkspaceForm = '';- if (account.can_manage) {- actions =- '<div class="account-actions">' +- (account.kind === 'msp'- ? '<button type="button" class="btn-secondary" id="add-ws-btn-' +- escapeAttr(account.id) +- '" data-action="toggle-add-workspace" data-account-id="' +- escapeAttr(account.id) +- '">+ Add workspace</button>'- : '') +- (account.has_billing- ? '<button type="button" class="btn-secondary" data-action="open-billing" data-account-id="' +- escapeAttr(account.id) +- '">Manage billing</button>'- : '') +- '<button type="button" class="btn-secondary" id="team-btn-' +- escapeAttr(account.id) +- '" data-action="toggle-team" data-account-id="' +- escapeAttr(account.id) +- '">Manage team</button>' +- '</div>';-- teamSection =- '<div class="team-section" id="team-section-' +- escapeAttr(account.id) +- '" data-actor-role="' +- escapeAttr(account.role) +- '">' +- '<h3>Team members</h3>' +- '<table class="team-table">' +- '<thead><tr><th>Email</th><th>Role</th><th></th></tr></thead>' +- '<tbody id="team-list-' +- escapeAttr(account.id) +- '">' +- '<tr><td colspan="3" style="color:#94a3b8;text-align:center;padding:16px">Loading…</td></tr>' +- '</tbody>' +- '</table>' +- '<div class="team-invite">' +- '<div><label for="invite-email-' +- escapeAttr(account.id) +- '">Email</label><input type="email" id="invite-email-' +- escapeAttr(account.id) +- '" placeholder="[email protected]" autocomplete="off"></div>' +- '<div><label for="invite-role-' +- escapeAttr(account.id) +- '">Role</label><select id="invite-role-' +- escapeAttr(account.id) +- '"><option value="admin">Admin</option><option value="tech">Tech</option><option value="read_only">Read-only</option></select></div>' +- '<button type="button" class="btn-primary" style="padding:8px 14px;font-size:13px" data-action="invite-member" data-account-id="' +- escapeAttr(account.id) +- '">Invite</button>' +- '</div>' +- '</div>';-- if (account.kind === 'msp') {- addWorkspaceForm =- '<div class="add-workspace-form" id="add-ws-form-' +- escapeAttr(account.id) +- '">' +- '<label for="ws-name-' +- escapeAttr(account.id) +- '">Workspace name (e.g. client name)</label>' +- '<input type="text" id="ws-name-' +- escapeAttr(account.id) +- '" placeholder="Acme Corp" maxlength="80" autocomplete="off">' +- '<div class="form-actions">' +- '<button type="button" class="btn-primary" data-action="create-workspace" data-account-id="' +- escapeAttr(account.id) +- '">Create workspace</button>' +- '<button type="button" class="btn-secondary" data-action="toggle-add-workspace" data-account-id="' +- escapeAttr(account.id) +- '">Cancel</button>' +- '<div class="spinner" id="ws-spinner-' +- escapeAttr(account.id) +- '"></div>' +- '</div>' +- '</div>';- }- }-- return (- '<section class="account-section">' +- '<div class="account-header">' +- '<h2>' + escapeHTML(account.name) + '</h2>' +- '<span class="badge badge-' + escapeHTML(account.kind) + '">' + escapeHTML(account.kind_label) + '</span>' +- roleBadgeHTML(account.role) +- '</div>' +- workspaceHTML +- actions +- teamSection +- addWorkspaceForm +- '</section>'- );-}--function renderAccounts(accounts) {- var root = document.getElementById('accounts-root');- if (!root) return;- var safeAccounts = Array.isArray(accounts) ? accounts : [];- if (safeAccounts.length === 0) {- root.innerHTML =- '<div class="empty-state" style="margin-top:48px">' +- '<p>No workspaces found. If you just signed up, check your email for setup instructions.</p>' +- '<p style="margin-top:12px;font-size:13px">Need help? Contact <a href="mailto:' +- escapeAttr(portalBootstrap.support_email || '') +- '" style="color:#1d4ed8">' +- escapeHTML(portalBootstrap.support_email || '') +- '</a></p>' +- '</div>';- return;- }- root.innerHTML = safeAccounts.map(renderAccountSection).join('');-}--function renderAuthenticatedPortal() {- return (- '<section class="intro-card">' +- '<h1>Pulse Account</h1>' +- '<p>Manage Cloud workspaces, MSP access, and self-hosted commercial account services from one account surface. Hosted workspace lifecycle lives here today, and the self-hosted billing, license recovery, refund, and privacy tools below now share the same Pulse Account shell instead of staying fragmented across public utility pages.</p>' +- '</section>' +- '<div id="accounts-root"></div>' +- '<section class="service-section">' +- '<div class="service-header">' +- '<h2>Other account services</h2>' +- '<div class="service-note">Self-hosted commercial account actions now live here. The public utility pages remain as compatibility entry points, not the primary account surface.</div>' +- '</div>' +- '<div class="service-grid">' +- '<button class="service-card service-card-button" type="button" id="open-manage-service" data-account-service-action="open-service-panel" data-account-service-panel="manage-service-panel" data-account-service-focus="manage-inline-email">' +- '<h3>Manage subscriptions</h3>' +- '<p>Open Stripe billing access for existing self-hosted subscriptions without leaving the Pulse Account shell.</p>' +- '</button>' +- '<button class="service-card service-card-button" type="button" id="open-retrieve-service" data-account-service-action="open-service-panel" data-account-service-panel="retrieve-service-panel" data-account-service-focus="retrieve-inline-email">' +- '<h3>Retrieve licenses</h3>' +- '<p>Recover the latest active self-hosted license and invoice link for a commercial email address.</p>' +- '</button>' +- '<button class="service-card service-card-button" type="button" id="open-refund-service" data-account-service-action="open-service-panel" data-account-service-panel="refund-service-panel" data-account-service-focus="refund-inline-email">' +- '<h3>Refund requests</h3>' +- '<p>Request an immediate self-serve refund for eligible self-hosted purchases with explicit revocation confirmation.</p>' +- '</button>' +- '<button class="service-card service-card-button" type="button" id="open-data-service" data-account-service-action="open-service-panel" data-account-service-panel="data-service-panel" data-account-service-focus="data-export-email">' +- '<h3>Data and privacy</h3>' +- '<p>Request commercial data export or deletion without leaving the account shell.</p>' +- '</button>' +- '</div>' +- '<div class="service-panel" id="manage-service-panel"><div id="manage-service-root"></div></div>' +- '<div class="service-panel" id="retrieve-service-panel"><div id="retrieve-service-root"></div></div>' +- '<div class="service-panel" id="refund-service-panel"><div id="refund-service-root"></div></div>' +- '<div class="service-panel" id="data-service-panel">' +- '<h3>Data and privacy</h3>' +- '<p>Request export or deletion of the commercial data tied to an email address. Payment data held directly by Stripe still requires support handling.</p>' +- '<div class="subsection"><div id="data-export-root"></div></div>' +- '<div class="subsection"><div id="data-delete-root"></div></div>' +- '<div class="helper-text">Payment-card data stays with Stripe. For Stripe deletion support, contact <a href="mailto:' +- escapeAttr(portalBootstrap.support_email || '') +- '">' +- escapeHTML(portalBootstrap.support_email || '') +- '</a>.</div>' +- '</div>' +- '</section>'- );-}--function renderSignedOutPortal() {- var statusHTML = '';- if (loginState.error) {- statusHTML = '<div class="service-status visible error">' + escapeHTML(loginState.error) + '</div>';- } else if (loginState.success) {- statusHTML =- '<div class="service-status visible success">' +- 'Magic link sent. Check your inbox and click the link to sign in.' +- '<br><br><strong>Don\'t see it?</strong> <a href="#" data-portal-action="resend-magic-link">Send a new link</a>.' +- '</div>';- }- return (- '<section class="intro-card">' +- '<h1>Pulse Account</h1>' +- '<p>Sign in to manage Cloud workspaces, MSP access, and commercial account services from one account surface.</p>' +- '</section>' +- '<section class="service-section">' +- '<div class="service-panel visible">' +- '<h3>Sign in</h3>' +- '<p>Enter the commercial email address for your Pulse account. I will send a magic link so you can open Pulse Account without managing a password.</p>' +- '<div class="form-group">' +- '<label for="portal-login-email">Email address</label>' +- '<input id="portal-login-email" type="email" autocomplete="email" placeholder="[email protected]" value="' +- escapeAttr(loginState.emailValue || '') +- '" data-portal-input="login-email">' +- '</div>' +- '<div class="form-actions">' +- '<button class="btn-primary" id="portal-login-send" type="button" data-portal-action="send-magic-link">' +- (loginState.sending ? 'Sending…' : 'Send magic link') +- '</button>' +- '<a class="btn-secondary" href="' + escapeAttr(SIGNUP_PATH) + '" style="text-decoration:none">Create an account</a>' +- '</div>' +- statusHTML +- '</div>' +- '</section>'- );+ userInfo.innerHTML = renderHeaderHTML({+ bootstrap: portalBootstrap,+ loginState: loginState,+ signupPath: SIGNUP_PATH,+ accountAPIBasePath: ACCOUNT_API_BASE_PATH,+ });}function renderPortalApp() {renderHeader();var root = document.getElementById('portal-app-root');if (!root) return;- root.innerHTML = portalBootstrap.authenticated ? renderAuthenticatedPortal() : renderSignedOutPortal();- if (portalBootstrap.authenticated) {- renderAccounts(portalBootstrap.accounts || []);- }+ var context = {+ bootstrap: portalBootstrap,+ loginState: loginState,+ signupPath: SIGNUP_PATH,+ accountAPIBasePath: ACCOUNT_API_BASE_PATH,+ };+ root.innerHTML = portalBootstrap.authenticated+ ? renderAuthenticatedPortalHTML(context)+ : renderSignedOutPortalHTML(context);notifyPortalRender();}diff --git a/internal/cloudcp/portal/frontend/src/shell_view.ts b/internal/cloudcp/portal/frontend/src/shell_view.tsnew file mode 100644index 0000000000..9162212ea9--- /dev/null+++ b/internal/cloudcp/portal/frontend/src/shell_view.ts@@ -0,0 +1,318 @@+import type {+ PortalAccountSummary,+ PortalBootstrapData,+ PortalLoginState,+ PortalWorkspaceSummary,+} from './types';++export interface ShellViewContext {+ bootstrap: PortalBootstrapData;+ loginState: PortalLoginState;+ signupPath: string;+ accountAPIBasePath: string;+}++function escapeHTML(value: unknown): string {+ return String(value || '')+ .replace(/&/g, '&')+ .replace(/</g, '<')+ .replace(/>/g, '>')+ .replace(/"/g, '"')+ .replace(/'/g, ''');+}++function escapeAttr(value: unknown): string {+ return escapeHTML(value);+}++function formatWorkspaceDate(value: unknown): string {+ if (!value) return '';+ var date = new Date(String(value));+ if (Number.isNaN(date.getTime())) return '';+ return date.toLocaleDateString(undefined, { month: 'short', day: 'numeric', year: 'numeric' });+}++function roleBadgeHTML(role: string): string {+ if (role === 'owner') return '<span class="badge" style="background:#f1f5f9;color:#64748b">Owner</span>';+ if (role === 'admin') return '<span class="badge" style="background:#f1f5f9;color:#64748b">Admin</span>';+ if (role === 'tech') return '<span class="badge" style="background:#f1f5f9;color:#64748b">Tech</span>';+ return '';+}++function renderWorkspaceCard(account: PortalAccountSummary, workspace: PortalWorkspaceSummary, accountAPIBasePath: string): string {+ var state = String(workspace.state || '');+ var safeState = escapeHTML(state);+ var createdLabel = formatWorkspaceDate(workspace.created_at);+ var openAction = '';+ if (state === 'active') {+ openAction =+ '<form method="POST" action="' ++ escapeAttr(accountAPIBasePath + '/' + account.id + '/tenants/' + workspace.id + '/handoff') ++ '">' ++ '<button type="submit" class="btn-primary">Open →</button>' ++ '</form>';+ } else {+ openAction = '<span style="font-size:13px;color:#94a3b8">' + safeState + '</span>';+ }++ var manageAction = '';+ if (account.can_manage && (state === 'active' || state === 'suspended' || state === 'failed')) {+ manageAction =+ '<button type="button" class="btn-danger" data-action="workspace-manage" data-account-id="' ++ escapeAttr(account.id) ++ '" data-workspace-id="' ++ escapeAttr(workspace.id) ++ '" data-workspace-state="' ++ escapeAttr(state) ++ '" data-workspace-name="' ++ escapeAttr(workspace.display_name) ++ '">⋯</button>';+ }++ var createdMeta = createdLabel ? '<span class="ws-created">Created ' + escapeHTML(createdLabel) + '</span>' : '';+ return (+ '<div class="workspace-card">' ++ '<div class="ws-info">' ++ '<span class="ws-name">' + escapeHTML(workspace.display_name) + '</span>' ++ '<div class="ws-meta">' ++ (workspace.healthy+ ? '<span class="badge badge-healthy">Healthy</span>'+ : '<span class="badge badge-unhealthy">Checking</span>') ++ '<span class="badge badge-' + safeState + '">' + safeState + '</span>' ++ createdMeta ++ '</div>' ++ '</div>' ++ '<div class="ws-actions">' ++ openAction ++ manageAction ++ '</div>' ++ '</div>'+ );+}++function renderAccountSection(account: PortalAccountSummary, accountAPIBasePath: string): string {+ var workspaces = Array.isArray(account.workspaces) ? account.workspaces : [];+ var workspaceHTML = '';+ if (workspaces.length === 0) {+ workspaceHTML = '<div class="empty-state"><p>No workspaces yet. Create one to get started.</p></div>';+ } else {+ workspaceHTML =+ '<div class="workspace-list">' ++ workspaces.map(function(workspace) {+ return renderWorkspaceCard(account, workspace, accountAPIBasePath);+ }).join('') ++ '</div>';+ }++ var actions = '';+ var teamSection = '';+ var addWorkspaceForm = '';+ if (account.can_manage) {+ actions =+ '<div class="account-actions">' ++ (account.kind === 'msp'+ ? '<button type="button" class="btn-secondary" id="add-ws-btn-' ++ escapeAttr(account.id) ++ '" data-action="toggle-add-workspace" data-account-id="' ++ escapeAttr(account.id) ++ '">+ Add workspace</button>'+ : '') ++ (account.has_billing+ ? '<button type="button" class="btn-secondary" data-action="open-billing" data-account-id="' ++ escapeAttr(account.id) ++ '">Manage billing</button>'+ : '') ++ '<button type="button" class="btn-secondary" id="team-btn-' ++ escapeAttr(account.id) ++ '" data-action="toggle-team" data-account-id="' ++ escapeAttr(account.id) ++ '">Manage team</button>' ++ '</div>';++ teamSection =+ '<div class="team-section" id="team-section-' ++ escapeAttr(account.id) ++ '" data-actor-role="' ++ escapeAttr(account.role) ++ '">' ++ '<h3>Team members</h3>' ++ '<table class="team-table">' ++ '<thead><tr><th>Email</th><th>Role</th><th></th></tr></thead>' ++ '<tbody id="team-list-' ++ escapeAttr(account.id) ++ '">' ++ '<tr><td colspan="3" style="color:#94a3b8;text-align:center;padding:16px">Loading…</td></tr>' ++ '</tbody>' ++ '</table>' ++ '<div class="team-invite">' ++ '<div><label for="invite-email-' ++ escapeAttr(account.id) ++ '">Email</label><input type="email" id="invite-email-' ++ escapeAttr(account.id) ++ '" placeholder="[email protected]" autocomplete="off"></div>' ++ '<div><label for="invite-role-' ++ escapeAttr(account.id) ++ '">Role</label><select id="invite-role-' ++ escapeAttr(account.id) ++ '"><option value="admin">Admin</option><option value="tech">Tech</option><option value="read_only">Read-only</option></select></div>' ++ '<button type="button" class="btn-primary" style="padding:8px 14px;font-size:13px" data-action="invite-member" data-account-id="' ++ escapeAttr(account.id) ++ '">Invite</button>' ++ '</div>' ++ '</div>';++ if (account.kind === 'msp') {+ addWorkspaceForm =+ '<div class="add-workspace-form" id="add-ws-form-' ++ escapeAttr(account.id) ++ '">' ++ '<label for="ws-name-' ++ escapeAttr(account.id) ++ '">Workspace name (e.g. client name)</label>' ++ '<input type="text" id="ws-name-' ++ escapeAttr(account.id) ++ '" placeholder="Acme Corp" maxlength="80" autocomplete="off">' ++ '<div class="form-actions">' ++ '<button type="button" class="btn-primary" data-action="create-workspace" data-account-id="' ++ escapeAttr(account.id) ++ '">Create workspace</button>' ++ '<button type="button" class="btn-secondary" data-action="toggle-add-workspace" data-account-id="' ++ escapeAttr(account.id) ++ '">Cancel</button>' ++ '<div class="spinner" id="ws-spinner-' ++ escapeAttr(account.id) ++ '"></div>' ++ '</div>' ++ '</div>';+ }+ }++ return (+ '<section class="account-section">' ++ '<div class="account-header">' ++ '<h2>' + escapeHTML(account.name) + '</h2>' ++ '<span class="badge badge-' + escapeHTML(account.kind) + '">' + escapeHTML(account.kind_label) + '</span>' ++ roleBadgeHTML(account.role) ++ '</div>' ++ workspaceHTML ++ actions ++ teamSection ++ addWorkspaceForm ++ '</section>'+ );+}++export function renderHeaderHTML(context: ShellViewContext): string {+ if (context.bootstrap.authenticated) {+ return (+ '<span>' + escapeHTML(context.bootstrap.email || '') + '</span>' ++ '<button class="logout-btn" id="logout-btn" type="button">Sign out</button>'+ );+ }+ return '<a class="logout-btn" href="' + escapeAttr(context.signupPath) + '" style="text-decoration:none">Create account</a>';+}++export function renderAccountsHTML(context: ShellViewContext): string {+ var safeAccounts = Array.isArray(context.bootstrap.accounts) ? context.bootstrap.accounts : [];+ if (safeAccounts.length === 0) {+ return (+ '<div class="empty-state" style="margin-top:48px">' ++ '<p>No workspaces found. If you just signed up, check your email for setup instructions.</p>' ++ '<p style="margin-top:12px;font-size:13px">Need help? Contact <a href="mailto:' ++ escapeAttr(context.bootstrap.support_email || '') ++ '" style="color:#1d4ed8">' ++ escapeHTML(context.bootstrap.support_email || '') ++ '</a></p>' ++ '</div>'+ );+ }+ return safeAccounts.map(function(account) {+ return renderAccountSection(account, context.accountAPIBasePath);+ }).join('');+}++export function renderAuthenticatedPortalHTML(context: ShellViewContext): string {+ return (+ '<section class="intro-card">' ++ '<h1>Pulse Account</h1>' ++ '<p>Manage Cloud workspaces, MSP access, and self-hosted commercial account services from one account surface. Hosted workspace lifecycle lives here today, and the self-hosted billing, license recovery, refund, and privacy tools below now share the same Pulse Account shell instead of staying fragmented across public utility pages.</p>' ++ '</section>' ++ '<div id="accounts-root">' + renderAccountsHTML(context) + '</div>' ++ '<section class="service-section">' ++ '<div class="service-header">' ++ '<h2>Other account services</h2>' ++ '<div class="service-note">Self-hosted commercial account actions now live here. The public utility pages remain as compatibility entry points, not the primary account surface.</div>' ++ '</div>' ++ '<div class="service-grid">' ++ '<button class="service-card service-card-button" type="button" id="open-manage-service" data-account-service-action="open-service-panel" data-account-service-panel="manage-service-panel" data-account-service-focus="manage-inline-email">' ++ '<h3>Manage subscriptions</h3>' ++ '<p>Open Stripe billing access for existing self-hosted subscriptions without leaving the Pulse Account shell.</p>' ++ '</button>' ++ '<button class="service-card service-card-button" type="button" id="open-retrieve-service" data-account-service-action="open-service-panel" data-account-service-panel="retrieve-service-panel" data-account-service-focus="retrieve-inline-email">' ++ '<h3>Retrieve licenses</h3>' ++ '<p>Recover the latest active self-hosted license and invoice link for a commercial email address.</p>' ++ '</button>' ++ '<button class="service-card service-card-button" type="button" id="open-refund-service" data-account-service-action="open-service-panel" data-account-service-panel="refund-service-panel" data-account-service-focus="refund-inline-email">' ++ '<h3>Refund requests</h3>' ++ '<p>Request an immediate self-serve refund for eligible self-hosted purchases with explicit revocation confirmation.</p>' ++ '</button>' ++ '<button class="service-card service-card-button" type="button" id="open-data-service" data-account-service-action="open-service-panel" data-account-service-panel="data-service-panel" data-account-service-focus="data-export-email">' ++ '<h3>Data and privacy</h3>' ++ '<p>Request commercial data export or deletion without leaving the account shell.</p>' ++ '</button>' ++ '</div>' ++ '<div class="service-panel" id="manage-service-panel"><div id="manage-service-root"></div></div>' ++ '<div class="service-panel" id="retrieve-service-panel"><div id="retrieve-service-root"></div></div>' ++ '<div class="service-panel" id="refund-service-panel"><div id="refund-service-root"></div></div>' ++ '<div class="service-panel" id="data-service-panel">' ++ '<h3>Data and privacy</h3>' ++ '<p>Request export or deletion of the commercial data tied to an email address. Payment data held directly by Stripe still requires support handling.</p>' ++ '<div class="subsection"><div id="data-export-root"></div></div>' ++ '<div class="subsection"><div id="data-delete-root"></div></div>' ++ '<div class="helper-text">Payment-card data stays with Stripe. For Stripe deletion support, contact <a href="mailto:' ++ escapeAttr(context.bootstrap.support_email || '') ++ '">' ++ escapeHTML(context.bootstrap.support_email || '') ++ '</a>.</div>' ++ '</div>' ++ '</section>'+ );+}++export function renderSignedOutPortalHTML(context: ShellViewContext): string {+ var statusHTML = '';+ if (context.loginState.error) {+ statusHTML = '<div class="service-status visible error">' + escapeHTML(context.loginState.error) + '</div>';+ } else if (context.loginState.success) {+ statusHTML =+ '<div class="service-status visible success">' ++ 'Magic link sent. Check your inbox and click the link to sign in.' ++ '<br><br><strong>Don\'t see it?</strong> <a href="#" data-portal-action="resend-magic-link">Send a new link</a>.' ++ '</div>';+ }+ return (+ '<section class="intro-card">' ++ '<h1>Pulse Account</h1>' ++ '<p>Sign in to manage Cloud workspaces, MSP access, and commercial account services from one account surface.</p>' ++ '</section>' ++ '<section class="service-section">' ++ '<div class="service-panel visible">' ++ '<h3>Sign in</h3>' ++ '<p>Enter the commercial email address for your Pulse account. I will send a magic link so you can open Pulse Account without managing a password.</p>' ++ '<div class="form-group">' ++ '<label for="portal-login-email">Email address</label>' ++ '<input id="portal-login-email" type="email" autocomplete="email" placeholder="[email protected]" value="' ++ escapeAttr(context.loginState.emailValue || '') ++ '" data-portal-input="login-email">' ++ '</div>' ++ '<div class="form-actions">' ++ '<button class="btn-primary" id="portal-login-send" type="button" data-portal-action="send-magic-link">' ++ (context.loginState.sending ? 'Sending…' : 'Send magic link') ++ '</button>' ++ '<a class="btn-secondary" href="' + escapeAttr(context.signupPath) + '" style="text-decoration:none">Create an account</a>' ++ '</div>' ++ statusHTML ++ '</div>' ++ '</section>'+ );+}