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
Gate portal self-hosted tools by account relevance
rcourtman35c056bc8f49
diff --git a/docs/release-control/v6/internal/PULSE_ACCOUNT_PORTAL_SPEC.md b/docs/release-control/v6/internal/PULSE_ACCOUNT_PORTAL_SPEC.mdindex 317c8276e4..e1247d25ba 100644--- a/docs/release-control/v6/internal/PULSE_ACCOUNT_PORTAL_SPEC.md+++ b/docs/release-control/v6/internal/PULSE_ACCOUNT_PORTAL_SPEC.md@@ -193,6 +193,10 @@ Core rules:must reduce `Support` to the billing escalation path only; hostedworkspace or access failure routes and task buttons must not renderwithout hosted accounts.+28. The portal bootstrap/runtime contract must carry explicit truth for+ whether self-hosted commercial history is relevant to the signed-in+ account. Hosted-only accounts must not render self-hosted licenses,+ refunds, privacy utilities, or self-hosted escalation copy by default.## Screen Modeldiff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.mdindex bf2044eefe..4e9fe7a47a 100644--- a/docs/release-control/v6/internal/subsystems/api-contracts.md+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md@@ -287,11 +287,15 @@ surface, and invite, role-change, or remove controls only appear when thematching access job is active. `Billing` follows the same shared runtimecontract: hosted billing remains the default primary path, self-hosted billingjobs open one panel at a time, and the runtime must reveal the active billing-panel on phone-width layouts instead of leaving it offscreen. `Support`-follows the same account-shape runtime contract: self-hosted-only accounts-expose only the billing escalation path and billing-specific handoff packet,-and hosted workspace/access escalation controls must not render when no hosted-account exists.+panel on phone-width layouts instead of leaving it offscreen. The same+bootstrap/runtime contract must also carry explicit truth for whether+self-hosted commercial history is relevant to the signed-in account, so+hosted-only accounts do not render self-hosted license, refund, privacy, or+self-hosted escalation paths by default. `Support` follows the same+account-shape runtime contract: self-hosted-only accounts expose only the+billing escalation path and billing-specific handoff packet, and hosted+workspace/access escalation controls must not render when no hosted account+exists.plus a package-local `tsc --noEmit` gate, so future account-shell work shouldextend the typed source boundary instead of reviving opaque global runtimeobjects, document-wide render events, or untyped embedded asset edits.diff --git a/docs/release-control/v6/internal/subsystems/cloud-paid.md b/docs/release-control/v6/internal/subsystems/cloud-paid.mdindex 780ab97a8d..15287cbac6 100644--- a/docs/release-control/v6/internal/subsystems/cloud-paid.md+++ b/docs/release-control/v6/internal/subsystems/cloud-paid.md@@ -850,6 +850,11 @@ is opened and then be revealed in-frame on narrow layouts. `Support` followsthe same account-shape rule: self-hosted-only accounts reduce to the billingescalation path and billing-specific handoff packet only, and hostedworkspace/access escalation routes must not render without hosted accounts.+That same canonical shell/runtime boundary now also owns the bootstrap truth+for when self-hosted commercial history is relevant. Hosted-only accounts must+not render self-hosted license, refund, privacy, or support-escalation copy+unless the portal bootstrap explicitly marks self-hosted commercial history as+relevant to the signed-in account.Until thatcandidate lane lands, newcommercial account work must extend the governed Pulse account shape ratherdiff --git a/internal/cloudcp/portal/bootstrap.go b/internal/cloudcp/portal/bootstrap.goindex 15aaaf0578..ee72ae34bc 100644--- a/internal/cloudcp/portal/bootstrap.go+++ b/internal/cloudcp/portal/bootstrap.go@@ -28,19 +28,20 @@ type BootstrapAccount struct {}type BootstrapData struct {- Authenticated bool `json:"authenticated"`- Email string `json:"email"`- PublicSiteURL string `json:"public_site_url"`- SupportEmail string `json:"support_email"`- CommercialAPIBaseURL string `json:"commercial_api_base_url"`- PortalPath string `json:"portal_path"`- BootstrapPath string `json:"bootstrap_path"`- MagicLinkRequestPath string `json:"magic_link_request_path"`- SignupPath string `json:"signup_path"`- LogoutPath string `json:"logout_path"`- AccountAPIBasePath string `json:"account_api_base_path"`- PortalAPIBasePath string `json:"portal_api_base_path"`- Accounts []BootstrapAccount `json:"accounts"`+ Authenticated bool `json:"authenticated"`+ Email string `json:"email"`+ HasSelfHostedCommercial bool `json:"has_self_hosted_commercial"`+ PublicSiteURL string `json:"public_site_url"`+ SupportEmail string `json:"support_email"`+ CommercialAPIBaseURL string `json:"commercial_api_base_url"`+ PortalPath string `json:"portal_path"`+ BootstrapPath string `json:"bootstrap_path"`+ MagicLinkRequestPath string `json:"magic_link_request_path"`+ SignupPath string `json:"signup_path"`+ LogoutPath string `json:"logout_path"`+ AccountAPIBasePath string `json:"account_api_base_path"`+ PortalAPIBasePath string `json:"portal_api_base_path"`+ Accounts []BootstrapAccount `json:"accounts"`}func MarshalBootstrapJSON(data BootstrapData) (template.JS, error) {@@ -51,7 +52,7 @@ func MarshalBootstrapJSON(data BootstrapData) (template.JS, error) {return template.JS(payload), nil}-func BuildBootstrapData(authenticated bool, email string, accounts []portalPageAccount) BootstrapData {+func BuildBootstrapData(authenticated bool, email string, accounts []portalPageAccount, hasSelfHostedCommercial bool) BootstrapData {bootstrapAccounts := make([]BootstrapAccount, 0, len(accounts))for _, account := range accounts {workspaces := make([]BootstrapWorkspace, 0, len(account.Workspaces))@@ -83,22 +84,23 @@ func BuildBootstrapData(authenticated bool, email string, accounts []portalPageA}return BootstrapData{- Authenticated: authenticated,- Email: email,- PublicSiteURL: defaultPublicSiteURL,- SupportEmail: defaultSupportEmail,- CommercialAPIBaseURL: defaultCommercialAPIBaseURL,- PortalPath: defaultPortalPath,- BootstrapPath: PortalBootstrapPath,- MagicLinkRequestPath: PortalMagicLinkRequestPath,- SignupPath: PortalSignupPath,- LogoutPath: defaultLogoutPath,- AccountAPIBasePath: defaultAccountAPIBasePath,- PortalAPIBasePath: defaultPortalAPIBasePath,- Accounts: bootstrapAccounts,+ Authenticated: authenticated,+ Email: email,+ HasSelfHostedCommercial: hasSelfHostedCommercial,+ PublicSiteURL: defaultPublicSiteURL,+ SupportEmail: defaultSupportEmail,+ CommercialAPIBaseURL: defaultCommercialAPIBaseURL,+ PortalPath: defaultPortalPath,+ BootstrapPath: PortalBootstrapPath,+ MagicLinkRequestPath: PortalMagicLinkRequestPath,+ SignupPath: PortalSignupPath,+ LogoutPath: defaultLogoutPath,+ AccountAPIBasePath: defaultAccountAPIBasePath,+ PortalAPIBasePath: defaultPortalAPIBasePath,+ Accounts: bootstrapAccounts,}}func BuildAnonymousBootstrapData() BootstrapData {- return BuildBootstrapData(false, "", nil)+ return BuildBootstrapData(false, "", nil, false)}diff --git a/internal/cloudcp/portal/commercial_identity.go b/internal/cloudcp/portal/commercial_identity.gonew file mode 100644index 0000000000..f1f78857cd--- /dev/null+++ b/internal/cloudcp/portal/commercial_identity.go@@ -0,0 +1,34 @@+package portal++import (+ "context"+ "strings"++ "github.com/rs/zerolog/log"+)++type CommercialIdentity struct {+ HasCommercialIdentity bool+}++type CommercialIdentityLookup func(ctx context.Context, email string) (*CommercialIdentity, error)++func resolveSelfHostedCommercial(ctx context.Context, lookup CommercialIdentityLookup, email string, accounts []portalPageAccount) bool {+ email = strings.TrimSpace(email)+ if email == "" {+ return false+ }+ if lookup == nil {+ return len(accounts) == 0+ }++ identity, err := lookup(ctx, email)+ if err != nil {+ log.Warn().Err(err).Str("email", email).Msg("cloudcp.portal: commercial identity lookup failed")+ return len(accounts) == 0+ }+ if identity == nil {+ return false+ }+ return identity.HasCommercialIdentity+}diff --git a/internal/cloudcp/portal/dist/build_manifest.json b/internal/cloudcp/portal/dist/build_manifest.jsonindex ec47023374..e5cc6629c7 100644--- a/internal/cloudcp/portal/dist/build_manifest.json+++ b/internal/cloudcp/portal/dist/build_manifest.json@@ -1,5 +1,5 @@{- "source_hash": "698217e718b15814bb146c8cbd7f962fc317e246a1dde1a9be3df3abc4f7c897",+ "source_hash": "30ae2fd08e074502921f7f7d0f942df540d1192e9e5234e6ea09387cc8593dbb","build_inputs": ["package.json","tsconfig.json",diff --git a/internal/cloudcp/portal/dist/portal_app.js b/internal/cloudcp/portal/dist/portal_app.jsindex 6f3653dc73..e66f2c2f9d 100644--- a/internal/cloudcp/portal/dist/portal_app.js+++ b/internal/cloudcp/portal/dist/portal_app.js@@ -1936,6 +1936,10 @@function hasHostedAccounts(accounts) {return accounts.length > 0;}+ function hasSelfHostedCommercial(bootstrap) {+ var accounts = Array.isArray(bootstrap.accounts) ? bootstrap.accounts : [];+ return bootstrap.has_self_hosted_commercial === true || !hasHostedAccounts(accounts);+ }function collectWorkspaces(accounts) {var results = [];for (var i = 0; i < accounts.length; i += 1) {@@ -2241,12 +2245,14 @@var accessRemovePanel = '<div class="access-job-note-panel"><div class="access-panel-heading"><h4>Remove stale access</h4><p>Use removal only when this person should no longer be on this hosted account. Owners may still be protected when they are the last owner.</p></div><div class="access-remove-points"><div class="access-remove-point"><strong>Pick the exact person</strong><span>Use the roster to remove one account member at a time.</span></div><div class="access-remove-point"><strong>Keep current owners safe</strong><span>The last owner cannot be removed until another owner exists.</span></div></div></div>';return '<section class="account-content-panel account-content-panel-access"><section class="access-management-panel access-section access-section-shell" id="access-section-' + escapeAttr(account.id) + '" data-actor-role="' + escapeAttr(account.role) + '" data-can-manage="' + escapeAttr(account.can_manage ? "true" : "false") + '"><div class="access-management-header"><div><div class="account-panel-kicker">Access</div><h3>' + accessHeaderTitle + "</h3><p>" + accessHeaderCopy + "</p>" + accessTaskStrip + '</div></div><div class="access-management-stats" id="access-stats-' + escapeAttr(account.id) + '"></div><div class="access-shell access-shell-idle" id="access-shell-' + escapeAttr(account.id) + '"><div class="access-shell-main"><div class="access-roster-column"><div class="access-roster"><div class="access-panel-heading"><h4>People on this account</h4><p>' + (account.can_manage ? "Review the hosted roster here, then open the exact access job you need." : "Review the hosted roster here. An owner or admin must make changes.") + '</p></div><div class="access-roster-list" id="access-list-' + escapeAttr(account.id) + '"><div class="access-list-message">Loading\u2026</div></div></div></div></div>' + (account.can_manage ? '<div class="access-shell-detail" id="access-detail-' + escapeAttr(account.id) + '" hidden><div class="access-task-panel" id="access-task-panel-' + escapeAttr(account.id) + '" hidden><div class="access-task-header"><div><div class="account-panel-kicker">Access task</div><h4 id="access-task-title-' + escapeAttr(account.id) + '">Invite people</h4><p id="access-task-copy-' + escapeAttr(account.id) + '"></p></div><button type="button" class="btn-secondary btn-compact" data-action="clear-access-job" data-account-id="' + escapeAttr(account.id) + '">Close panel</button></div><div class="access-task-body" id="access-task-body-invite-' + escapeAttr(account.id) + '" hidden>' + accessInvitePanel + accessRoleGuide + '</div><div class="access-task-body" id="access-task-body-change_role-' + escapeAttr(account.id) + '" hidden>' + accessChangeRolePanel + '</div><div class="access-task-body" id="access-task-body-remove-' + escapeAttr(account.id) + '" hidden>' + accessRemovePanel + "</div></div></div>" : "") + "</div></section></section>";}- function renderHostedBillingCards(accounts) {+ function renderHostedBillingCards(accounts, showSelfHostedCommercial) {var hostedBillingAccounts = accounts.filter(function(account) {return account.has_billing;});if (!hostedBillingAccounts.length) {- return '<div class="billing-task-card billing-task-card-muted"><div class="account-panel-kicker">Hosted billing</div><h3>No hosted billing attached</h3><p>Use the self-hosted billing tools below only if you are managing a self-hosted purchase.</p></div>';+ return '<div class="billing-task-card billing-task-card-muted"><div class="account-panel-kicker">Hosted billing</div><h3>No hosted billing attached</h3><p>' + escapeHTML(+ showSelfHostedCommercial ? "Use the self-hosted billing tools below only if you are managing a self-hosted purchase." : "Hosted invoices, payment methods, and subscription changes are not attached to this Pulse account right now."+ ) + "</p></div>";}return hostedBillingAccounts.map(function(account) {var actionHTML = account.can_manage ? '<button type="button" class="btn-primary btn-compact" data-action="open-billing" data-account-id="' + escapeAttr(account.id) + '">Open hosted billing</button>' : '<div class="billing-task-note">An owner or admin on this account needs to open hosted billing.</div>';@@ -2258,11 +2264,12 @@}function renderSupportSection(context) {var hasHostedAccounts2 = !!(context.bootstrap.accounts || []).length;+ var showSelfHostedCommercial = hasSelfHostedCommercial(context.bootstrap);var supportEmail = context.bootstrap.support_email || "";- var supportLead = hasHostedAccounts2 ? "Use support only when the Workspaces, Access, or Billing path has already stopped you." : "Use support only when the Billing path has already stopped you.";- var supportChips = hasHostedAccounts2 ? ["Escalation only", "Bring context", supportEmail ? "Email" : "Support"] : ["Escalation only", "Billing only", supportEmail ? "Email" : "Support"];- var routeCards = hasHostedAccounts2 ? '<div class="portal-support-route-card"><div class="account-panel-kicker">Hosted path</div><h3>Workspace or access path failed</h3><p>Go back to the hosted task first. Escalate only when the same workspace or access path still cannot finish the job.</p><div class="portal-support-points"><div class="portal-support-point"><strong>Start from the same task</strong><span>Use Workspaces for lifecycle issues and Access for roster issues before you escalate.</span></div><div class="portal-support-point"><strong>Keep the hosted context intact</strong><span>Include the account, workspace, and failed action so support inherits the same request.</span></div></div><div class="portal-support-actions"><button type="button" class="btn-secondary btn-compact" data-shell-action="activate-section" data-shell-section="workspaces">Open workspaces</button><button type="button" class="btn-secondary btn-compact" data-shell-action="activate-section" data-shell-section="access">Open access</button><a class="portal-support-link" href="mailto:' + escapeAttr(supportEmail) + '">' + escapeHTML(supportEmail) + '</a></div></div><div class="portal-support-route-card"><div class="account-panel-kicker">Billing path</div><h3>Billing path failed</h3><p>Use this route only after hosted billing or one self-hosted billing job has failed to complete cleanly.</p><div class="portal-support-points"><div class="portal-support-point"><strong>Name the billing job</strong><span>Say whether the failed path was hosted billing, licenses, refunds, or privacy.</span></div><div class="portal-support-point"><strong>Keep the request intact</strong><span>Bring the same account or billing email and the failed action instead of reopening the story.</span></div></div><div class="portal-support-actions"><button type="button" class="btn-secondary btn-compact" data-shell-action="activate-section" data-shell-section="billing">Open billing</button><a class="portal-support-link" href="mailto:' + escapeAttr(supportEmail) + '">' + escapeHTML(supportEmail) + "</a></div></div>" : '<div class="portal-support-route-card"><div class="account-panel-kicker">Billing path</div><h3>Self-hosted billing path failed</h3><p>Use this route only after a self-hosted billing, license, refund, or privacy job has failed to complete cleanly.</p><div class="portal-support-points"><div class="portal-support-point"><strong>Name the billing job</strong><span>Say whether the failed path was billing, licenses, refunds, or privacy.</span></div><div class="portal-support-point"><strong>Keep the purchase context intact</strong><span>Bring the same commercial email and the failed action instead of reopening the story.</span></div></div><div class="portal-support-actions"><button type="button" class="btn-secondary btn-compact" data-shell-action="activate-section" data-shell-section="billing">Open billing</button><a class="portal-support-link" href="mailto:' + escapeAttr(supportEmail) + '">' + escapeHTML(supportEmail) + "</a></div></div>";- var runbookSteps = hasHostedAccounts2 ? '<div class="portal-support-runbook-step"><strong>1. Failed path</strong><span>Say whether the blocked path was Workspaces, Access, hosted billing, licenses, refunds, or privacy.</span></div><div class="portal-support-runbook-step"><strong>2. Account or email</strong><span>Include the hosted account and workspace when relevant, or the commercial billing email for self-hosted work.</span></div><div class="portal-support-runbook-step"><strong>3. Failed action</strong><span>Name the exact button, form, or billing step that failed and what happened next.</span></div>' : '<div class="portal-support-runbook-step"><strong>1. Billing job</strong><span>Say whether the blocked path was billing, licenses, refunds, or privacy.</span></div><div class="portal-support-runbook-step"><strong>2. Purchase email</strong><span>Include the commercial billing email used for the self-hosted purchase.</span></div><div class="portal-support-runbook-step"><strong>3. Failed action</strong><span>Name the exact button, form, or billing step that failed and what happened next.</span></div>';+ var supportLead = hasHostedAccounts2 ? showSelfHostedCommercial ? "Use support only when the Workspaces, Access, or Billing path has already stopped you." : "Use support only when the Workspaces, Access, or hosted Billing path has already stopped you." : "Use support only when the Billing path has already stopped you.";+ var supportChips = hasHostedAccounts2 ? ["Escalation only", showSelfHostedCommercial ? "Bring context" : "Hosted only", supportEmail ? "Email" : "Support"] : ["Escalation only", "Billing only", supportEmail ? "Email" : "Support"];+ var routeCards = hasHostedAccounts2 ? '<div class="portal-support-route-card"><div class="account-panel-kicker">Hosted path</div><h3>Workspace or access path failed</h3><p>Go back to the hosted task first. Escalate only when the same workspace or access path still cannot finish the job.</p><div class="portal-support-points"><div class="portal-support-point"><strong>Start from the same task</strong><span>Use Workspaces for lifecycle issues and Access for roster issues before you escalate.</span></div><div class="portal-support-point"><strong>Keep the hosted context intact</strong><span>Include the account, workspace, and failed action so support inherits the same request.</span></div></div><div class="portal-support-actions"><button type="button" class="btn-secondary btn-compact" data-shell-action="activate-section" data-shell-section="workspaces">Open workspaces</button><button type="button" class="btn-secondary btn-compact" data-shell-action="activate-section" data-shell-section="access">Open access</button><a class="portal-support-link" href="mailto:' + escapeAttr(supportEmail) + '">' + escapeHTML(supportEmail) + '</a></div></div><div class="portal-support-route-card"><div class="account-panel-kicker">Billing path</div><h3>' + (showSelfHostedCommercial ? "Billing path failed" : "Hosted billing path failed") + "</h3><p>" + (showSelfHostedCommercial ? "Use this route only after hosted billing or one self-hosted billing job has failed to complete cleanly." : "Use this route only after hosted billing has failed to complete cleanly.") + '</p><div class="portal-support-points"><div class="portal-support-point"><strong>Name the billing job</strong><span>' + (showSelfHostedCommercial ? "Say whether the failed path was hosted billing, licenses, refunds, or privacy." : "Say whether the failed path was hosted billing.") + '</span></div><div class="portal-support-point"><strong>Keep the request intact</strong><span>' + (showSelfHostedCommercial ? "Bring the same account or billing email and the failed action instead of reopening the story." : "Bring the same hosted account and the failed billing action instead of reopening the story.") + '</span></div></div><div class="portal-support-actions"><button type="button" class="btn-secondary btn-compact" data-shell-action="activate-section" data-shell-section="billing">Open billing</button><a class="portal-support-link" href="mailto:' + escapeAttr(supportEmail) + '">' + escapeHTML(supportEmail) + "</a></div></div>" : '<div class="portal-support-route-card"><div class="account-panel-kicker">Billing path</div><h3>Self-hosted billing path failed</h3><p>Use this route only after a self-hosted billing, license, refund, or privacy job has failed to complete cleanly.</p><div class="portal-support-points"><div class="portal-support-point"><strong>Name the billing job</strong><span>Say whether the failed path was billing, licenses, refunds, or privacy.</span></div><div class="portal-support-point"><strong>Keep the purchase context intact</strong><span>Bring the same commercial email and the failed action instead of reopening the story.</span></div></div><div class="portal-support-actions"><button type="button" class="btn-secondary btn-compact" data-shell-action="activate-section" data-shell-section="billing">Open billing</button><a class="portal-support-link" href="mailto:' + escapeAttr(supportEmail) + '">' + escapeHTML(supportEmail) + "</a></div></div>";+ var runbookSteps = hasHostedAccounts2 ? '<div class="portal-support-runbook-step"><strong>1. Failed path</strong><span>' + (showSelfHostedCommercial ? "Say whether the blocked path was Workspaces, Access, hosted billing, licenses, refunds, or privacy." : "Say whether the blocked path was Workspaces, Access, or hosted billing.") + '</span></div><div class="portal-support-runbook-step"><strong>2. Account or email</strong><span>' + (showSelfHostedCommercial ? "Include the hosted account and workspace when relevant, or the commercial billing email for self-hosted work." : "Include the hosted account and workspace or hosted billing account that the failed path belongs to.") + '</span></div><div class="portal-support-runbook-step"><strong>3. Failed action</strong><span>Name the exact button, form, or billing step that failed and what happened next.</span></div>' : '<div class="portal-support-runbook-step"><strong>1. Billing job</strong><span>Say whether the blocked path was billing, licenses, refunds, or privacy.</span></div><div class="portal-support-runbook-step"><strong>2. Purchase email</strong><span>Include the commercial billing email used for the self-hosted purchase.</span></div><div class="portal-support-runbook-step"><strong>3. Failed action</strong><span>Name the exact button, form, or billing step that failed and what happened next.</span></div>';return '<section class="portal-support-panel"><div class="account-panel-kicker">Support</div><h2>Escalation only</h2><p>' + escapeHTML(supportLead) + "</p>" + renderSectionContextChips(supportChips) + '<div class="portal-support-layout"><div class="portal-support-route-grid">' + routeCards + '</div><div class="portal-support-runbook"><div class="account-panel-kicker">What to send</div><h3>Keep the escalation short</h3><p>Support should inherit the same request, not reconstruct it from scratch.</p><div class="portal-support-runbook-list">' + runbookSteps + "</div></div></div></section>";}function renderHeaderHTML(context) {@@ -2274,18 +2281,19 @@function renderAuthenticatedPortalHTML(context) {var accounts = Array.isArray(context.bootstrap.accounts) ? context.bootstrap.accounts : [];var hosted = hasHostedAccounts(accounts);+ var showSelfHostedCommercial = hasSelfHostedCommercial(context.bootstrap);var activeSection = context.activeSection || "overview";var hostedBillingCount = accounts.filter(function(account) {return account.has_billing;}).length;- var billingNote = hosted ? "Use hosted billing first when the request belongs to a hosted workspace account. Self-hosted licenses, refunds, and privacy stay separate underneath it." : "Use this billing surface only for self-hosted subscriptions, licenses, refunds, and privacy requests.";+ var billingNote = hosted ? showSelfHostedCommercial ? "Use hosted billing first when the request belongs to a hosted workspace account. Self-hosted licenses, refunds, and privacy stay separate underneath it." : "Use this billing surface only for hosted billing on your hosted workspace accounts." : "Use this billing surface only for self-hosted subscriptions, licenses, refunds, and privacy requests.";var hostedContent = accounts.length ? accounts.map(function(account) {return '<section class="account-surface"><div class="account-surface-body">' + renderAccountWorkspaceSection(account, context.accountAPIBasePath) + renderAccountAccessSection(account) + "</div></section>";}).join("") : renderNoHostedWorkspacesSection() + renderNoHostedAccessSection();return '<div class="portal-shell" data-shell-section="' + activeSection + '"><div class="portal-shell-layout">' + renderShellNavigation(accounts, context.bootstrap.support_email || "", activeSection) + '<div class="portal-shell-main">' + (accounts.length === 1 ? renderAccountContextStrip(accounts[0]) : "") + '<section class="portal-content-panel portal-content-panel-overview">' + renderShellOverviewSection(context) + '<div id="accounts-root">' + hostedContent + '</div></section><section class="portal-content-panel portal-content-panel-billing billing-section" id="billing-section"><div class="billing-header"><div><div class="account-panel-kicker">Billing</div><h2>Billing</h2>' + renderSectionContextChips([hostedBillingCount > 0 ? "Hosted billing" : "No hosted billing",- "Self-hosted tools"- ]) + '</div><div class="billing-note">' + billingNote + '</div></div><div class="billing-overview-grid">' + renderHostedBillingCards(accounts) + '</div><div class="billing-shell billing-shell-idle"><div class="billing-shell-main"><div class="billing-shell-main-head"><div class="account-panel-kicker">Self-hosted billing</div><h3>Pick the self-hosted job</h3><p>Use self-hosted billing only for self-hosted purchases. Open one path at a time when hosted billing does not apply.</p></div><div class="billing-action-list">' + renderBillingActionRow("open-manage-billing", "Self-hosted billing", "Manage subscriptions", "Billing", "Open Stripe for self-hosted plan, invoice, and payment changes.", "manage-billing-panel", "manage-inline-email", ["Plan changes", "Invoices"]) + renderBillingActionRow("open-retrieve-billing", "Licenses", "Retrieve licenses", "Licenses", "Recover the latest active self-hosted license and invoice link.", "retrieve-billing-panel", "retrieve-inline-email", ["Latest active license", "Invoice lookup"]) + renderBillingActionRow("open-refund-billing", "Refunds", "Refund requests", "Refunds", "Request a self-serve refund when the purchase is still eligible.", "refund-billing-panel", "refund-inline-email", ["Eligibility check", "Revocation"]) + renderBillingActionRow("open-data-billing", "Privacy", "Data and privacy", "Privacy", "Request export or deletion for commercial account data.", "data-billing-panel", "data-export-email", ["Export", "Deletion"]) + '</div><div class="billing-inline-support"><div class="account-panel-kicker">Escalation only</div><h4>Use Support only after Billing fails</h4><p>Escalate with the same hosted billing action or self-hosted path and the exact failed step.</p><div class="billing-inline-support-actions"><button type="button" class="btn-secondary btn-compact" data-shell-action="activate-section" data-shell-section="support">Open support</button><a class="portal-support-link" href="mailto:' + escapeAttr(context.bootstrap.support_email || "") + '">' + escapeHTML(context.bootstrap.support_email || "") + '</a></div></div></div><div class="billing-shell-detail" id="billing-detail-shell" hidden>' + renderBillingTaskPanel(+ showSelfHostedCommercial ? "Self-hosted tools" : "Hosted only"+ ]) + '</div><div class="billing-note">' + billingNote + '</div></div><div class="billing-overview-grid">' + renderHostedBillingCards(accounts, showSelfHostedCommercial) + "</div>" + (showSelfHostedCommercial ? '<div class="billing-shell billing-shell-idle"><div class="billing-shell-main"><div class="billing-shell-main-head"><div class="account-panel-kicker">Self-hosted billing</div><h3>Pick the self-hosted job</h3><p>Use self-hosted billing only for self-hosted purchases. Open one path at a time when hosted billing does not apply.</p></div><div class="billing-action-list">' + renderBillingActionRow("open-manage-billing", "Self-hosted billing", "Manage subscriptions", "Billing", "Open Stripe for self-hosted plan, invoice, and payment changes.", "manage-billing-panel", "manage-inline-email", ["Plan changes", "Invoices"]) + renderBillingActionRow("open-retrieve-billing", "Licenses", "Retrieve licenses", "Licenses", "Recover the latest active self-hosted license and invoice link.", "retrieve-billing-panel", "retrieve-inline-email", ["Latest active license", "Invoice lookup"]) + renderBillingActionRow("open-refund-billing", "Refunds", "Refund requests", "Refunds", "Request a self-serve refund when the purchase is still eligible.", "refund-billing-panel", "refund-inline-email", ["Eligibility check", "Revocation"]) + renderBillingActionRow("open-data-billing", "Privacy", "Data and privacy", "Privacy", "Request export or deletion for commercial account data.", "data-billing-panel", "data-export-email", ["Export", "Deletion"]) + '</div><div class="billing-inline-support"><div class="account-panel-kicker">Escalation only</div><h4>Use Support only after Billing fails</h4><p>Escalate with the same hosted billing action or self-hosted path and the exact failed step.</p><div class="billing-inline-support-actions"><button type="button" class="btn-secondary btn-compact" data-shell-action="activate-section" data-shell-section="support">Open support</button><a class="portal-support-link" href="mailto:' + escapeAttr(context.bootstrap.support_email || "") + '">' + escapeHTML(context.bootstrap.support_email || "") + '</a></div></div></div><div class="billing-shell-detail" id="billing-detail-shell" hidden>' + renderBillingTaskPanel("Manage subscriptions","Open Stripe for self-hosted plan, invoice, and payment changes.","manage-billing-panel",@@ -2305,7 +2313,7 @@"Request export or deletion for commercial account data.","data-billing-panel",'<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></div></section><section class="portal-content-panel portal-content-panel-support">' + renderSupportSection(context) + "</section></div></div></div>";+ ) + "</div></div>" : "") + '</section><section class="portal-content-panel portal-content-panel-support">' + renderSupportSection(context) + "</section></div></div></div>";}function renderSignedOutPortalHTML(context) {var statusHTML = "";@@ -2555,6 +2563,7 @@}function createBootstrapDefaults(embeddedBootstrap) {return {+ has_self_hosted_commercial: embeddedBootstrap.has_self_hosted_commercial === true,public_site_url: embeddedBootstrap.public_site_url || "https://pulserelay.pro",support_email: embeddedBootstrap.support_email || "[email protected]",commercial_api_base_url: embeddedBootstrap.commercial_api_base_url || "",diff --git a/internal/cloudcp/portal/frontend/src/account_runtime.test.ts b/internal/cloudcp/portal/frontend/src/account_runtime.test.tsindex d17d62dab8..e0732e8391 100644--- a/internal/cloudcp/portal/frontend/src/account_runtime.test.ts+++ b/internal/cloudcp/portal/frontend/src/account_runtime.test.ts@@ -26,6 +26,7 @@ async function flushAsync() {}const bootstrapDefaults: Omit<PortalBootstrapData, 'authenticated' | 'email' | 'accounts'> = {+ has_self_hosted_commercial: false,public_site_url: 'https://pulserelay.pro',support_email: '[email protected]',commercial_api_base_url: '/api/portal/commercial',diff --git a/internal/cloudcp/portal/frontend/src/api.test.ts b/internal/cloudcp/portal/frontend/src/api.test.tsindex ff8ad94e98..dd7196cb41 100644--- a/internal/cloudcp/portal/frontend/src/api.test.ts+++ b/internal/cloudcp/portal/frontend/src/api.test.ts@@ -6,6 +6,7 @@ import type { PortalBootstrapData } from './types';const bootstrap: PortalBootstrapData = {authenticated: true,email: '[email protected]',+ has_self_hosted_commercial: false,public_site_url: 'https://pulserelay.pro',support_email: '[email protected]',commercial_api_base_url: '/api/portal/commercial',diff --git a/internal/cloudcp/portal/frontend/src/app.test.ts b/internal/cloudcp/portal/frontend/src/app.test.tsindex e84998dbd4..b6013bf5da 100644--- a/internal/cloudcp/portal/frontend/src/app.test.ts+++ b/internal/cloudcp/portal/frontend/src/app.test.ts@@ -25,6 +25,7 @@ async function flushAsync() {}const bootstrapDefaults: Omit<PortalBootstrapData, 'authenticated' | 'email' | 'accounts'> = {+ has_self_hosted_commercial: false,public_site_url: 'https://pulserelay.pro',support_email: '[email protected]',commercial_api_base_url: '/api/portal/commercial',@@ -161,6 +162,7 @@ describe('portal app', function() {app.applyBootstrap({authenticated: true,email: '[email protected]',+ has_self_hosted_commercial: true,accounts: [{id: 'acct_1',@@ -228,6 +230,7 @@ describe('portal app', function() {var store = createPortalStore(bootstrapDefaults, {authenticated: true,email: '[email protected]',+ has_self_hosted_commercial: true,accounts: accounts,});var fetchMock = vi.fn(async function(input: RequestInfo | URL) {@@ -236,6 +239,7 @@ describe('portal app', function() {return jsonResponse({authenticated: true,email: '[email protected]',+ has_self_hosted_commercial: true,accounts: accounts,});}diff --git a/internal/cloudcp/portal/frontend/src/auth_controller.test.ts b/internal/cloudcp/portal/frontend/src/auth_controller.test.tsindex a7d900ec45..44724eb04a 100644--- a/internal/cloudcp/portal/frontend/src/auth_controller.test.ts+++ b/internal/cloudcp/portal/frontend/src/auth_controller.test.ts@@ -15,6 +15,7 @@ async function flushAsync() {}const bootstrapDefaults: Omit<PortalBootstrapData, 'authenticated' | 'email' | 'accounts'> = {+ has_self_hosted_commercial: false,public_site_url: 'https://pulserelay.pro',support_email: '[email protected]',commercial_api_base_url: '/api/portal/commercial',diff --git a/internal/cloudcp/portal/frontend/src/billing_view.test.ts b/internal/cloudcp/portal/frontend/src/billing_view.test.tsindex 9d064cedc0..26d16fcd03 100644--- a/internal/cloudcp/portal/frontend/src/billing_view.test.ts+++ b/internal/cloudcp/portal/frontend/src/billing_view.test.ts@@ -16,6 +16,7 @@ function createBootstrap(overrides: Partial<PortalBootstrapData> = {}): PortalBoreturn {authenticated: true,email: '[email protected]',+ has_self_hosted_commercial: true,public_site_url: 'https://pulserelay.pro',support_email: '[email protected]',commercial_api_base_url: '/api/portal/commercial',diff --git a/internal/cloudcp/portal/frontend/src/runtime.test.ts b/internal/cloudcp/portal/frontend/src/runtime.test.tsindex eb9290b090..c96c342121 100644--- a/internal/cloudcp/portal/frontend/src/runtime.test.ts+++ b/internal/cloudcp/portal/frontend/src/runtime.test.ts@@ -5,6 +5,7 @@ import { createBootstrapDefaults, createPortalRuntime, readPortalRuntimeHandoffdescribe('portal runtime', function() {it('derives bootstrap defaults from embedded bootstrap data', function() {var defaults = createBootstrapDefaults({+ has_self_hosted_commercial: true,public_site_url: 'https://cloud.pulserelay.pro',support_email: '[email protected]',commercial_api_base_url: '/api/portal/commercial',@@ -18,6 +19,7 @@ describe('portal runtime', function() {});expect(defaults.public_site_url).toBe('https://cloud.pulserelay.pro');+ expect(defaults.has_self_hosted_commercial).toBe(true);expect(defaults.support_email).toBe('[email protected]');expect(defaults.portal_path).toBe('/account');expect(defaults.bootstrap_path).toBe('/api/account/bootstrap');@@ -27,6 +29,7 @@ describe('portal runtime', function() {var runtime = createPortalRuntime({authenticated: true,email: '[email protected]',+ has_self_hosted_commercial: false,accounts: [],commercial_api_base_url: '/api/portal/commercial',});@@ -48,6 +51,7 @@ describe('portal runtime', function() {{authenticated: false,email: '',+ has_self_hosted_commercial: false,accounts: [],},{diff --git a/internal/cloudcp/portal/frontend/src/runtime.ts b/internal/cloudcp/portal/frontend/src/runtime.tsindex df3c5de45a..429ac15016 100644--- a/internal/cloudcp/portal/frontend/src/runtime.ts+++ b/internal/cloudcp/portal/frontend/src/runtime.ts@@ -64,6 +64,7 @@ export function createBootstrapDefaults(embeddedBootstrap: Partial<PortalBootstrapData>): Omit<PortalBootstrapData, 'authenticated' | 'email' | 'accounts'> {return {+ has_self_hosted_commercial: embeddedBootstrap.has_self_hosted_commercial === true,public_site_url: embeddedBootstrap.public_site_url || 'https://pulserelay.pro',support_email: embeddedBootstrap.support_email || '[email protected]',commercial_api_base_url: embeddedBootstrap.commercial_api_base_url || '',diff --git a/internal/cloudcp/portal/frontend/src/shell.test.ts b/internal/cloudcp/portal/frontend/src/shell.test.tsindex 8599e99330..84ef406592 100644--- a/internal/cloudcp/portal/frontend/src/shell.test.ts+++ b/internal/cloudcp/portal/frontend/src/shell.test.ts@@ -5,6 +5,7 @@ import { createPortalStore } from './store';import type { PortalBootstrapData } from './types';const bootstrapDefaults: Omit<PortalBootstrapData, 'authenticated' | 'email' | 'accounts'> = {+ has_self_hosted_commercial: false,public_site_url: 'https://pulserelay.pro',support_email: '[email protected]',commercial_api_base_url: '/api/portal/commercial',diff --git a/internal/cloudcp/portal/frontend/src/shell_view.test.ts b/internal/cloudcp/portal/frontend/src/shell_view.test.tsindex 8b77efbb4c..92e13e18e5 100644--- a/internal/cloudcp/portal/frontend/src/shell_view.test.ts+++ b/internal/cloudcp/portal/frontend/src/shell_view.test.ts@@ -13,6 +13,7 @@ function createBootstrap(overrides: Partial<PortalBootstrapData> = {}): PortalBoreturn {authenticated: true,email: '[email protected]',+ has_self_hosted_commercial: false,public_site_url: 'https://pulserelay.pro',support_email: '[email protected]',commercial_api_base_url: '/api/portal/commercial',@@ -83,7 +84,7 @@ describe('shell view', function() {expect(html).toContain('Open billing');});- it('renders authenticated portal accounts, workspaces, and service entrypoints', function() {+ it('renders authenticated portal accounts, workspaces, and hosted-only billing entrypoints', function() {var html = renderAuthenticatedPortalHTML(createContext({bootstrap: createBootstrap({@@ -204,30 +205,68 @@ describe('shell view', function() {expect(html).toContain('data-can-manage="true"');expect(html).toContain('Remove stale access');expect(html).toContain('data-action="workspace-action"');- expect(html).toContain('billing-action-row');- expect(html).toContain('billing-action-button');expect(html).toContain('Hosted billing');+ expect(html).toContain('Hosted only');+ expect(html).toContain('Use this billing surface only for hosted billing on your hosted workspace accounts.');+ expect(html).toContain('Escalation only');+ expect(html).toContain('Workspace or access path failed');+ expect(html).toContain('Hosted billing path failed');+ expect(html).toContain('Keep the escalation short');+ expect(html).toContain('What to send');+ expect(html).toContain('Open billing');+ expect(html).not.toContain('Self-hosted tools');+ expect(html).not.toContain('Self-hosted billing');+ expect(html).not.toContain('Pick the self-hosted job');+ expect(html).not.toContain('Use self-hosted billing only for self-hosted purchases.');+ expect(html).not.toContain('id="open-retrieve-billing"');+ expect(html).not.toContain('id="billing-detail-shell" hidden');+ expect(html).not.toContain('data-account-billing-action="clear-billing-panel"');+ expect(html).not.toContain('id="data-billing-panel"');+ expect(html).not.toContain('>Licenses<');+ expect(html).not.toContain('>Refunds<');+ expect(html).not.toContain('>Privacy<');+ });++ it('renders mixed billing tools only when self-hosted commercial history is relevant', function() {+ var html = renderAuthenticatedPortalHTML(+ createContext({+ bootstrap: createBootstrap({+ has_self_hosted_commercial: true,+ accounts: [+ {+ id: 'acct_mixed',+ name: 'Mixed Account',+ kind: 'cloud',+ kind_label: 'Cloud',+ role: 'owner',+ can_manage: true,+ has_billing: true,+ workspaces: [+ {+ id: 'ws_mixed',+ display_name: 'Mixed Workspace',+ state: 'active',+ healthy: true,+ health_status: 'healthy',+ },+ ],+ },+ ],+ }),+ })+ );+expect(html).toContain('Self-hosted tools');expect(html).toContain('Self-hosted billing');expect(html).toContain('Pick the self-hosted job');- expect(html).toContain('Use Support only after Billing fails');expect(html).toContain('Use hosted billing first when the request belongs to a hosted workspace account.');- expect(html).toContain('Open support');expect(html).toContain('Use self-hosted billing only for self-hosted purchases.');expect(html).toContain('id="open-retrieve-billing"');expect(html).toContain('id="billing-detail-shell" hidden');expect(html).toContain('data-account-billing-action="clear-billing-panel"');expect(html).toContain('id="data-billing-panel"');- expect(html).toContain('>Billing<');- expect(html).toContain('>Licenses<');- expect(html).toContain('>Refunds<');- expect(html).toContain('>Privacy<');- expect(html).toContain('Escalation only');- expect(html).toContain('Workspace or access path failed');expect(html).toContain('Billing path failed');- expect(html).toContain('Keep the escalation short');- expect(html).toContain('What to send');- expect(html).toContain('Open billing');+ expect(html).toContain('licenses, refunds, or privacy');});it('keeps top-level task navigation in the canonical section order', function() {diff --git a/internal/cloudcp/portal/frontend/src/shell_view.ts b/internal/cloudcp/portal/frontend/src/shell_view.tsindex 1a524127ad..ed07c50327 100644--- a/internal/cloudcp/portal/frontend/src/shell_view.ts+++ b/internal/cloudcp/portal/frontend/src/shell_view.ts@@ -72,6 +72,11 @@ function hasHostedAccounts(accounts: PortalAccountSummary[]): boolean {return accounts.length > 0;}+function hasSelfHostedCommercial(bootstrap: PortalBootstrapData): boolean {+ var accounts = Array.isArray(bootstrap.accounts) ? bootstrap.accounts : [];+ return bootstrap.has_self_hosted_commercial === true || !hasHostedAccounts(accounts);+}+function countWorkspaces(accounts: PortalAccountSummary[]): number {var total = 0;for (var i = 0; i < accounts.length; i += 1) {@@ -1036,7 +1041,7 @@ function renderAccountAccessSection(account: PortalAccountSummary): string {);}-function renderHostedBillingCards(accounts: PortalAccountSummary[]): string {+function renderHostedBillingCards(accounts: PortalAccountSummary[], showSelfHostedCommercial: boolean): string {var hostedBillingAccounts = accounts.filter(function(account) {return account.has_billing;});@@ -1045,7 +1050,10 @@ function renderHostedBillingCards(accounts: PortalAccountSummary[]): string {'<div class="billing-task-card billing-task-card-muted">' +'<div class="account-panel-kicker">Hosted billing</div>' +'<h3>No hosted billing attached</h3>' +- '<p>Use the self-hosted billing tools below only if you are managing a self-hosted purchase.</p>' ++ '<p>' + escapeHTML(showSelfHostedCommercial+ ? 'Use the self-hosted billing tools below only if you are managing a self-hosted purchase.'+ : 'Hosted invoices, payment methods, and subscription changes are not attached to this Pulse account right now.'+ ) + '</p>' +'</div>');}@@ -1087,12 +1095,15 @@ function renderBillingTaskPanel(title: string, copy: string, panelID: string, bofunction renderSupportSection(context: ShellViewContext): string {var hasHostedAccounts = !!((context.bootstrap.accounts || []).length);+ var showSelfHostedCommercial = hasSelfHostedCommercial(context.bootstrap);var supportEmail = context.bootstrap.support_email || '';var supportLead = hasHostedAccounts- ? 'Use support only when the Workspaces, Access, or Billing path has already stopped you.'+ ? (showSelfHostedCommercial+ ? 'Use support only when the Workspaces, Access, or Billing path has already stopped you.'+ : 'Use support only when the Workspaces, Access, or hosted Billing path has already stopped you.'): 'Use support only when the Billing path has already stopped you.';var supportChips = hasHostedAccounts- ? ['Escalation only', 'Bring context', supportEmail ? 'Email' : 'Support']+ ? ['Escalation only', showSelfHostedCommercial ? 'Bring context' : 'Hosted only', supportEmail ? 'Email' : 'Support']: ['Escalation only', 'Billing only', supportEmail ? 'Email' : 'Support'];var routeCards = hasHostedAccounts? (@@ -1112,11 +1123,17 @@ function renderSupportSection(context: ShellViewContext): string {'</div>' +'<div class="portal-support-route-card">' +'<div class="account-panel-kicker">Billing path</div>' +- '<h3>Billing path failed</h3>' +- '<p>Use this route only after hosted billing or one self-hosted billing job has failed to complete cleanly.</p>' ++ '<h3>' + (showSelfHostedCommercial ? 'Billing path failed' : 'Hosted billing path failed') + '</h3>' ++ '<p>' + (showSelfHostedCommercial+ ? 'Use this route only after hosted billing or one self-hosted billing job has failed to complete cleanly.'+ : 'Use this route only after hosted billing has failed to complete cleanly.') + '</p>' +'<div class="portal-support-points">' +- '<div class="portal-support-point"><strong>Name the billing job</strong><span>Say whether the failed path was hosted billing, licenses, refunds, or privacy.</span></div>' +- '<div class="portal-support-point"><strong>Keep the request intact</strong><span>Bring the same account or billing email and the failed action instead of reopening the story.</span></div>' ++ '<div class="portal-support-point"><strong>Name the billing job</strong><span>' + (showSelfHostedCommercial+ ? 'Say whether the failed path was hosted billing, licenses, refunds, or privacy.'+ : 'Say whether the failed path was hosted billing.') + '</span></div>' ++ '<div class="portal-support-point"><strong>Keep the request intact</strong><span>' + (showSelfHostedCommercial+ ? 'Bring the same account or billing email and the failed action instead of reopening the story.'+ : 'Bring the same hosted account and the failed billing action instead of reopening the story.') + '</span></div>' +'</div>' +'<div class="portal-support-actions">' +'<button type="button" class="btn-secondary btn-compact" data-shell-action="activate-section" data-shell-section="billing">Open billing</button>' +@@ -1141,8 +1158,12 @@ function renderSupportSection(context: ShellViewContext): string {);var runbookSteps = hasHostedAccounts? (- '<div class="portal-support-runbook-step"><strong>1. Failed path</strong><span>Say whether the blocked path was Workspaces, Access, hosted billing, licenses, refunds, or privacy.</span></div>' +- '<div class="portal-support-runbook-step"><strong>2. Account or email</strong><span>Include the hosted account and workspace when relevant, or the commercial billing email for self-hosted work.</span></div>' ++ '<div class="portal-support-runbook-step"><strong>1. Failed path</strong><span>' + (showSelfHostedCommercial+ ? 'Say whether the blocked path was Workspaces, Access, hosted billing, licenses, refunds, or privacy.'+ : 'Say whether the blocked path was Workspaces, Access, or hosted billing.') + '</span></div>' ++ '<div class="portal-support-runbook-step"><strong>2. Account or email</strong><span>' + (showSelfHostedCommercial+ ? 'Include the hosted account and workspace when relevant, or the commercial billing email for self-hosted work.'+ : 'Include the hosted account and workspace or hosted billing account that the failed path belongs to.') + '</span></div>' +'<div class="portal-support-runbook-step"><strong>3. Failed action</strong><span>Name the exact button, form, or billing step that failed and what happened next.</span></div>'): (@@ -1192,12 +1213,15 @@ export function renderAccountsHTML(context: ShellViewContext): string {export function renderAuthenticatedPortalHTML(context: ShellViewContext): string {var accounts = Array.isArray(context.bootstrap.accounts) ? context.bootstrap.accounts : [];var hosted = hasHostedAccounts(accounts);+ var showSelfHostedCommercial = hasSelfHostedCommercial(context.bootstrap);var activeSection = context.activeSection || 'overview';var hostedBillingCount = accounts.filter(function(account) {return account.has_billing;}).length;var billingNote = hosted- ? 'Use hosted billing first when the request belongs to a hosted workspace account. Self-hosted licenses, refunds, and privacy stay separate underneath it.'+ ? (showSelfHostedCommercial+ ? 'Use hosted billing first when the request belongs to a hosted workspace account. Self-hosted licenses, refunds, and privacy stay separate underneath it.'+ : 'Use this billing surface only for hosted billing on your hosted workspace accounts.'): 'Use this billing surface only for self-hosted subscriptions, licenses, refunds, and privacy requests.';var hostedContent = accounts.length? accounts.map(function(account) {@@ -1229,13 +1253,14 @@ export function renderAuthenticatedPortalHTML(context: ShellViewContext): string'<h2>Billing</h2>' +renderSectionContextChips([hostedBillingCount > 0 ? 'Hosted billing' : 'No hosted billing',- 'Self-hosted tools',+ showSelfHostedCommercial ? 'Self-hosted tools' : 'Hosted only',]) +'</div>' +'<div class="billing-note">' + billingNote + '</div>' +'</div>' +- '<div class="billing-overview-grid">' + renderHostedBillingCards(accounts) + '</div>' +- '<div class="billing-shell billing-shell-idle">' ++ '<div class="billing-overview-grid">' + renderHostedBillingCards(accounts, showSelfHostedCommercial) + '</div>' ++ (showSelfHostedCommercial+ ? ('<div class="billing-shell billing-shell-idle">' +'<div class="billing-shell-main">' +'<div class="billing-shell-main-head">' +'<div class="account-panel-kicker">Self-hosted billing</div>' +@@ -1294,7 +1319,8 @@ export function renderAuthenticatedPortalHTML(context: ShellViewContext): string'</a>.</div>') +'</div>' +- '</div>' ++ '</div>')+ : '') +'</section>' +'<section class="portal-content-panel portal-content-panel-support">' +renderSupportSection(context) +diff --git a/internal/cloudcp/portal/frontend/src/store.test.ts b/internal/cloudcp/portal/frontend/src/store.test.tsindex 6e37d1dcf7..a867821d5b 100644--- a/internal/cloudcp/portal/frontend/src/store.test.ts+++ b/internal/cloudcp/portal/frontend/src/store.test.ts@@ -4,6 +4,7 @@ import { createAnonymousBootstrap, createPortalStore, normalizeBootstrap } fromimport type { PortalBootstrapData } from './types';const bootstrapDefaults: Omit<PortalBootstrapData, 'authenticated' | 'email' | 'accounts'> = {+ has_self_hosted_commercial: false,public_site_url: 'https://pulserelay.pro',support_email: '[email protected]',commercial_api_base_url: '/api/portal/commercial',diff --git a/internal/cloudcp/portal/frontend/src/types.ts b/internal/cloudcp/portal/frontend/src/types.tsindex 3e6954ac32..8a5e26e3c2 100644--- a/internal/cloudcp/portal/frontend/src/types.ts+++ b/internal/cloudcp/portal/frontend/src/types.ts@@ -22,6 +22,7 @@ export interface PortalAccountSummary {export interface PortalBootstrapData {authenticated: boolean;email: string;+ has_self_hosted_commercial: boolean;public_site_url: string;support_email: string;commercial_api_base_url: string;diff --git a/internal/cloudcp/portal/handlers.go b/internal/cloudcp/portal/handlers.goindex ffeb7c87e7..fc51ea6503 100644--- a/internal/cloudcp/portal/handlers.go+++ b/internal/cloudcp/portal/handlers.go@@ -213,7 +213,7 @@ func HandlePortalWorkspaceDetail(reg *registry.TenantRegistry) http.HandlerFunc// Route: GET /api/portal/bootstrap//// Auth: control-plane session.-func HandlePortalBootstrap(sessionSvc *cpauth.Service, reg *registry.TenantRegistry) http.HandlerFunc {+func HandlePortalBootstrap(sessionSvc *cpauth.Service, reg *registry.TenantRegistry, commercialLookup CommercialIdentityLookup) http.HandlerFunc {return func(w http.ResponseWriter, r *http.Request) {if r.Method != http.MethodGet {http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)@@ -244,7 +244,7 @@ func HandlePortalBootstrap(sessionSvc *cpauth.Service, reg *registry.TenantRegisw.Header().Set("Content-Type", "application/json")w.WriteHeader(http.StatusOK)- encodeJSON(w, BuildBootstrapData(true, claims.Email, accounts))+ encodeJSON(w, BuildBootstrapData(true, claims.Email, accounts, resolveSelfHostedCommercial(r.Context(), commercialLookup, claims.Email, accounts)))}}diff --git a/internal/cloudcp/portal/handlers_test.go b/internal/cloudcp/portal/handlers_test.goindex d795384a1c..4eb307bcf8 100644--- a/internal/cloudcp/portal/handlers_test.go+++ b/internal/cloudcp/portal/handlers_test.go@@ -1,6 +1,7 @@package portalimport (+ "context""encoding/json""fmt""net/http"@@ -662,7 +663,7 @@ func TestPortalPageTemplate_AccessManagementRendered(t *testing.T) {CanManage: true,HasBilling: false,},- }))+ }, false))mustContain := []string{`id="portal-app-root"`,@@ -712,7 +713,7 @@ func TestPortalPageTemplate_TeamManagementHiddenForNonManagers(t *testing.T) {CanManage: false,HasBilling: false,},- }))+ }, false))var payload map[string]anyif err := json.Unmarshal([]byte(extractPortalBootstrapJSONFromHTML(t, html)), &payload); err != nil {@@ -746,7 +747,7 @@ func TestPortalPageTemplate_ActorRolePassedToSection(t *testing.T) {Role: role,CanManage: true,},- }))+ }, false))if !strings.Contains(html, `data-actor-role="`) {t.Fatalf("expected actor-role render seam in portal shell")}@@ -777,7 +778,7 @@ func TestPortalPageTemplate_AccountServicesRendered(t *testing.T) {KindLabel: "Cloud",Name: "Test Account",},- }))+ }, false))mustContain := []string{"<title>Pulse Account</title>",@@ -850,7 +851,7 @@ func TestBuildPortalBootstrapJSON_Contract(t *testing.T) {},},},- }))+ }, true))if err != nil {t.Fatalf("MarshalBootstrapJSON: %v", err)}@@ -866,6 +867,9 @@ func TestBuildPortalBootstrapJSON_Contract(t *testing.T) {if got := payload["email"]; got != "[email protected]" {t.Fatalf("email = %#v, want [email protected]", got)}+ if got := payload["has_self_hosted_commercial"]; got != true {+ t.Fatalf("has_self_hosted_commercial = %#v, want true", got)+ }if got := payload["commercial_api_base_url"]; got != "/api/portal/commercial" {t.Fatalf("commercial_api_base_url = %#v", got)}@@ -948,7 +952,7 @@ func TestHandlePortalBootstrap_Success(t *testing.T) {req := httptest.NewRequest(http.MethodGet, "/api/portal/bootstrap", nil)req.Header.Set("Authorization", "Bearer "+token)rec := httptest.NewRecorder()- HandlePortalBootstrap(sessionSvc, reg).ServeHTTP(rec, req)+ HandlePortalBootstrap(sessionSvc, reg, nil).ServeHTTP(rec, req)if rec.Code != http.StatusOK {t.Fatalf("status = %d, want %d (body=%q)", rec.Code, http.StatusOK, rec.Body.String())@@ -961,6 +965,9 @@ func TestHandlePortalBootstrap_Success(t *testing.T) {if got := payload["email"]; got != "[email protected]" {t.Fatalf("email = %#v", got)}+ if got := payload["has_self_hosted_commercial"]; got != false {+ t.Fatalf("has_self_hosted_commercial = %#v, want false", got)+ }if got := payload["portal_api_base_path"]; got != PortalAPIBasePath {t.Fatalf("portal_api_base_path = %#v", got)}@@ -1001,7 +1008,7 @@ func TestHandlePortalBootstrap_RequiresAuth(t *testing.T) {req := httptest.NewRequest(http.MethodGet, "/api/portal/bootstrap", nil)rec := httptest.NewRecorder()- HandlePortalBootstrap(sessionSvc, reg).ServeHTTP(rec, req)+ HandlePortalBootstrap(sessionSvc, reg, nil).ServeHTTP(rec, req)if rec.Code != http.StatusUnauthorized {t.Fatalf("status = %d, want %d", rec.Code, http.StatusUnauthorized)@@ -1018,7 +1025,7 @@ func TestHandlePortalBootstrap_RevokedSessionUnauthorized(t *testing.T) {req := httptest.NewRequest(http.MethodGet, "/api/portal/bootstrap", nil)req.Header.Set("Authorization", "Bearer "+token)rec := httptest.NewRecorder()- HandlePortalBootstrap(sessionSvc, reg).ServeHTTP(rec, req)+ HandlePortalBootstrap(sessionSvc, reg, nil).ServeHTTP(rec, req)if rec.Code != http.StatusUnauthorized {t.Fatalf("status = %d, want %d", rec.Code, http.StatusUnauthorized)@@ -1055,7 +1062,12 @@ func TestPortalBootstrapHTMLAndHandlerStayInSync(t *testing.T) {req := httptest.NewRequest(http.MethodGet, "/api/portal/bootstrap", nil)req.Header.Set("Authorization", "Bearer "+token)rec := httptest.NewRecorder()- HandlePortalBootstrap(sessionSvc, reg).ServeHTTP(rec, req)+ HandlePortalBootstrap(sessionSvc, reg, func(_ context.Context, email string) (*CommercialIdentity, error) {+ if email != "[email protected]" {+ t.Fatalf("lookup email = %q", email)+ }+ return &CommercialIdentity{HasCommercialIdentity: true}, nil+ }).ServeHTTP(rec, req)if rec.Code != http.StatusOK {t.Fatalf("bootstrap status = %d, want %d", rec.Code, http.StatusOK)}@@ -1070,7 +1082,7 @@ func TestPortalBootstrapHTMLAndHandlerStayInSync(t *testing.T) {if err != nil {t.Fatalf("loadPortalAccountsForUser: %v", err)}- html := renderPortalHTML(t, BuildBootstrapData(true, validClaims.Email, accounts))+ html := renderPortalHTML(t, BuildBootstrapData(true, validClaims.Email, accounts, true))handlerJSON := strings.TrimSpace(rec.Body.String())pageJSON := strings.TrimSpace(extractPortalBootstrapJSONFromHTML(t, html))diff --git a/internal/cloudcp/portal/page.go b/internal/cloudcp/portal/page.goindex 06bcf8437c..ebf7147bec 100644--- a/internal/cloudcp/portal/page.go+++ b/internal/cloudcp/portal/page.go@@ -59,7 +59,7 @@ var errPortalAuthRequired = errors.New("portal auth required")// Route: GET /portal// - No session or invalid session -> shows a magic-link login form// - Valid session -> shows workspace list with management actions-func HandlePortalPage(sessionSvc *cpauth.Service, reg *registry.TenantRegistry) http.HandlerFunc {+func HandlePortalPage(sessionSvc *cpauth.Service, reg *registry.TenantRegistry, commercialLookup CommercialIdentityLookup) http.HandlerFunc {return func(w http.ResponseWriter, r *http.Request) {if r.Method != http.MethodGet {http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)@@ -77,7 +77,7 @@ func HandlePortalPage(sessionSvc *cpauth.Service, reg *registry.TenantRegistry)http.Error(w, "internal error", http.StatusInternalServerError)return}- renderPortalPage(w, nonce, BuildBootstrapData(true, claims.Email, accounts))+ renderPortalPage(w, nonce, BuildBootstrapData(true, claims.Email, accounts, resolveSelfHostedCommercial(r.Context(), commercialLookup, claims.Email, accounts)))case errors.Is(err, errPortalAuthRequired):renderPortalPage(w, nonce, BuildAnonymousBootstrapData())default:diff --git a/internal/cloudcp/routes.go b/internal/cloudcp/routes.goindex 40531ee802..447f5de36b 100644--- a/internal/cloudcp/routes.go+++ b/internal/cloudcp/routes.go@@ -1,6 +1,7 @@package cloudcpimport (+ "context""net/http""strings""time"@@ -65,6 +66,22 @@ func RegisterRoutes(mux *http.ServeMux, deps *Deps) {return sessionAuth(requireAccountMembership(deps.Registry, extract, next))}accountMutationAuth := requireAnyAccountRole(registry.MemberRoleOwner, registry.MemberRoleAdmin)+ rawCommercialLookup := newCommercialIdentityLookup(deps.Config)+ portalCommercialLookup := func(ctx context.Context, email string) (*portal.CommercialIdentity, error) {+ if rawCommercialLookup == nil {+ return nil, nil+ }+ identity, err := rawCommercialLookup(ctx, email)+ if err != nil {+ return nil, err+ }+ if identity == nil {+ return nil, nil+ }+ return &portal.CommercialIdentity{+ HasCommercialIdentity: identity.HasCommercialIdentity,+ }, nil+ }// Health / readiness are unauthenticated liveness/readiness probes.mux.HandleFunc("/healthz", admin.HandleHealthz)@@ -224,7 +241,7 @@ func RegisterRoutes(mux *http.ServeMux, deps *Deps) {mux.Handle("/api/accounts/{account_id}/tenants/{tenant_id}/handoff", accountAPILimiter.Middleware(accountSessionAuth(accountIDFromPath, handoffHandler)))// MSP portal API (session + account-membership authenticated)- mux.Handle(portal.PortalBootstrapPath, portalAPILimiter.Middleware(sessionAuth(portal.HandlePortalBootstrap(deps.MagicLinks, deps.Registry))))+ mux.Handle(portal.PortalBootstrapPath, portalAPILimiter.Middleware(sessionAuth(portal.HandlePortalBootstrap(deps.MagicLinks, deps.Registry, portalCommercialLookup))))mux.Handle(portal.PortalDashboardPath, portalAPILimiter.Middleware(accountSessionAuth(accountIDFromPortalRequest, portal.HandlePortalDashboard(deps.Registry))))mux.Handle(portal.PortalWorkspacePath, portalAPILimiter.Middleware(accountSessionAuth(accountIDFromPortalRequest, portal.HandlePortalWorkspaceDetail(deps.Registry))))@@ -240,5 +257,5 @@ func RegisterRoutes(mux *http.ServeMux, deps *Deps) {// MSP/Cloud portal HTML page — self-authenticating (shows login form if no session)portalPageLimiter := NewCPRateLimiter(60, time.Minute)- mux.Handle(portal.PortalPagePath, portalPageLimiter.Middleware(http.HandlerFunc(portal.HandlePortalPage(deps.MagicLinks, deps.Registry))))+ mux.Handle(portal.PortalPagePath, portalPageLimiter.Middleware(http.HandlerFunc(portal.HandlePortalPage(deps.MagicLinks, deps.Registry, portalCommercialLookup))))}diff --git a/internal/cloudcp/routes_auth_test.go b/internal/cloudcp/routes_auth_test.goindex 051c1c0eda..2a1cfca004 100644--- a/internal/cloudcp/routes_auth_test.go+++ b/internal/cloudcp/routes_auth_test.go@@ -433,10 +433,12 @@ func TestRegisterRoutes_PortalPageSessionModes(t *testing.T) {`id="pulse-account-bootstrap"`,`id="portal-app-root"`,`"authenticated":true`,- "Account center",- "Workspace status",- "Account services",- "Self-hosted commercial services",+ "Account tasks",+ "Overview",+ "Workspaces",+ "Access",+ "Billing",+ "Support",} {if !strings.Contains(authRec.Body.String(), needle) {t.Fatalf("expected authenticated portal page to contain %q, body=%q", needle, authRec.Body.String())