mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-11-30 01:32:00 +01:00
Exercised the full provider portal as a pilot MSP would and fixed what made it feel broken: - The signed-out portal promised "a sign-in link is on the way" even when the control plane has no email provider (the bundle default), and team invitations silently sent nothing. The portal bootstrap now carries email_sign_in_available and provider_hosted_mode; the sign-in page shows the host command that actually prints a link, and the invite panel says invitation emails are not sent and how to hand over a link instead. - New "provider-msp portal-link --email" CLI mints a one-time portal link for an account member or pending invitee, so teammates can sign in at all on email-less installs (bootstrap only covers the owner). - Portal sessions were fixed at 12h; CP_SESSION_TTL now configures them and provider-hosted MSP mode defaults to 7 days. - Creating a client past the license cap showed a generic "Failed to create workspace." toast: the limit error is now a JSON payload with current/limit, the API client no longer drops non-JSON error bodies (double body read), and the toast explains the license limit. - Copy polish: provider-mode sign-in intro (no refunds/privacy register), least-privilege default invite role, queue tile label matches "Client onboarding", softer Support tab with a docs/MSP.md pointer, setup.sh summary now prints the bootstrap next step and day-2 sign-in commands, .env.example and docs/MSP.md document portal sign-in and sessions. Contracts updated (cloud-paid, api-contracts, deployment-installability, security-privacy) with verification pins in tenant_handlers_test, config_test, magiclink_test, and provider_msp_deploy_test. Verified live against a dockerless control plane: portal-link for an invitee redeems, promotes the invitation, and sets a 7-day session; the at-cap toast shows the license copy; portal vitest suite and cloudcp/auth/account/installtests Go suites pass.
164 lines
6.1 KiB
TypeScript
164 lines
6.1 KiB
TypeScript
import { createPortalStore } from './store';
|
|
import type { PortalStore } from './store';
|
|
import type { PortalBootstrapData } from './types';
|
|
|
|
export interface PortalRuntimeHandoff {
|
|
email: string;
|
|
openBillingPanelID: string;
|
|
upgradePortalHandoffID: string;
|
|
upgradeFeatureKey: string;
|
|
upgradeTrialRequested: boolean;
|
|
}
|
|
|
|
export interface PortalRuntime {
|
|
bootstrapDefaults: Omit<PortalBootstrapData, 'authenticated' | 'email' | 'accounts'>;
|
|
embeddedBootstrap: Partial<PortalBootstrapData>;
|
|
handoff: PortalRuntimeHandoff;
|
|
store: PortalStore;
|
|
}
|
|
|
|
function readEmbeddedBootstrap(): Partial<PortalBootstrapData> {
|
|
const bootstrapEl = document.getElementById('pulse-account-bootstrap');
|
|
if (!bootstrapEl) {
|
|
return {};
|
|
}
|
|
try {
|
|
return JSON.parse(bootstrapEl.textContent || '{}') as Partial<PortalBootstrapData>;
|
|
} catch {
|
|
return {};
|
|
}
|
|
}
|
|
|
|
function normalizeHandoffEmail(value: string | null): string {
|
|
return String(value || '').trim();
|
|
}
|
|
|
|
function normalizeUpgradePortalHandoffID(
|
|
value: string | null | undefined,
|
|
): string {
|
|
var trimmed = String(value || '').trim();
|
|
if (!trimmed) return '';
|
|
return /^[A-Za-z0-9_-]+$/.test(trimmed) ? trimmed : '';
|
|
}
|
|
|
|
function normalizeHandoffBillingPanel(value: string | null): string {
|
|
switch (String(value || '').trim()) {
|
|
case 'upgrade':
|
|
return 'upgrade-billing-panel';
|
|
case 'manage':
|
|
return 'manage-billing-panel';
|
|
case 'retrieve':
|
|
return 'retrieve-billing-panel';
|
|
case 'refund':
|
|
return 'refund-billing-panel';
|
|
case 'data':
|
|
return 'data-billing-panel';
|
|
default:
|
|
return '';
|
|
}
|
|
}
|
|
|
|
function normalizeUpgradeFeatureKey(value: string | null): string {
|
|
return String(value || '').trim();
|
|
}
|
|
|
|
function normalizeUpgradeTrialRequested(value: string | null): boolean {
|
|
var trimmed = String(value || '').trim().toLowerCase();
|
|
return trimmed === '1' || trimmed === 'true';
|
|
}
|
|
|
|
export function readPortalRuntimeHandoff(
|
|
locationHref: string | undefined = window.location.href,
|
|
): PortalRuntimeHandoff {
|
|
try {
|
|
var params = new URL(locationHref).searchParams;
|
|
var upgradePortalHandoffID = normalizeUpgradePortalHandoffID(params.get('portal_handoff_id'));
|
|
var openBillingPanelID = normalizeHandoffBillingPanel(params.get('service'));
|
|
if (!openBillingPanelID && upgradePortalHandoffID) {
|
|
openBillingPanelID = 'upgrade-billing-panel';
|
|
}
|
|
return {
|
|
email: normalizeHandoffEmail(params.get('email')),
|
|
openBillingPanelID: openBillingPanelID,
|
|
upgradePortalHandoffID: upgradePortalHandoffID,
|
|
upgradeFeatureKey: normalizeUpgradeFeatureKey(params.get('feature')),
|
|
upgradeTrialRequested: normalizeUpgradeTrialRequested(params.get('trial')),
|
|
};
|
|
} catch {
|
|
return {
|
|
email: '',
|
|
openBillingPanelID: '',
|
|
upgradePortalHandoffID: '',
|
|
upgradeFeatureKey: '',
|
|
upgradeTrialRequested: false,
|
|
};
|
|
}
|
|
}
|
|
|
|
export function createBootstrapDefaults(
|
|
embeddedBootstrap: Partial<PortalBootstrapData>
|
|
): Omit<PortalBootstrapData, 'authenticated' | 'email' | 'accounts'> {
|
|
var signupPath = typeof embeddedBootstrap.signup_path === 'string'
|
|
? embeddedBootstrap.signup_path
|
|
: '/signup';
|
|
return {
|
|
has_self_hosted_commercial: embeddedBootstrap.has_self_hosted_commercial === true,
|
|
// Default to available so Pulse-hosted cloud (which always has email)
|
|
// never hides the sign-in form if the flag is missing from an older payload.
|
|
email_sign_in_available: embeddedBootstrap.email_sign_in_available !== false,
|
|
provider_hosted_mode: embeddedBootstrap.provider_hosted_mode === true,
|
|
public_site_url: embeddedBootstrap.public_site_url || 'https://pulserelay.pro',
|
|
support_email: embeddedBootstrap.support_email || 'support@pulserelay.pro',
|
|
commercial_api_base_url: embeddedBootstrap.commercial_api_base_url || '',
|
|
portal_path: embeddedBootstrap.portal_path || '/portal',
|
|
bootstrap_path: embeddedBootstrap.bootstrap_path || '/api/portal/bootstrap',
|
|
magic_link_request_path: embeddedBootstrap.magic_link_request_path || '/api/public/magic-link/request',
|
|
signup_path: signupPath,
|
|
logout_path: embeddedBootstrap.logout_path || '/auth/logout',
|
|
account_api_base_path: embeddedBootstrap.account_api_base_path || '/api/accounts',
|
|
portal_api_base_path: embeddedBootstrap.portal_api_base_path || '/api/portal',
|
|
};
|
|
}
|
|
|
|
export function createPortalRuntime(
|
|
embeddedBootstrap: Partial<PortalBootstrapData> = readEmbeddedBootstrap(),
|
|
handoff: PortalRuntimeHandoff = readPortalRuntimeHandoff()
|
|
): PortalRuntime {
|
|
var bootstrapDefaults = createBootstrapDefaults(embeddedBootstrap);
|
|
var store = createPortalStore(bootstrapDefaults, embeddedBootstrap);
|
|
if (handoff.email) {
|
|
store.updateLoginState(function(loginState) {
|
|
loginState.emailValue = handoff.email;
|
|
}, { notify: false });
|
|
store.updateBillingState(function(billingState) {
|
|
billingState.flows.manage.emailValue = handoff.email;
|
|
billingState.flows.retrieve.emailValue = handoff.email;
|
|
billingState.flows.export.emailValue = handoff.email;
|
|
billingState.flows.delete.emailValue = handoff.email;
|
|
billingState.refund.emailValue = handoff.email;
|
|
}, { notify: false });
|
|
}
|
|
if (handoff.openBillingPanelID) {
|
|
store.setActiveShellSection('billing');
|
|
store.updateBillingState(function(billingState) {
|
|
billingState.openBillingPanelID = handoff.openBillingPanelID;
|
|
billingState.upgradePortalHandoffID = handoff.upgradePortalHandoffID;
|
|
billingState.upgradeFeatureKey = handoff.upgradeFeatureKey;
|
|
billingState.upgradeTrialRequested = handoff.upgradeTrialRequested;
|
|
}, { notify: false });
|
|
} else if (handoff.upgradeFeatureKey || handoff.upgradePortalHandoffID) {
|
|
store.setActiveShellSection('billing');
|
|
store.updateBillingState(function(billingState) {
|
|
billingState.upgradePortalHandoffID = handoff.upgradePortalHandoffID;
|
|
billingState.upgradeFeatureKey = handoff.upgradeFeatureKey;
|
|
billingState.upgradeTrialRequested = handoff.upgradeTrialRequested;
|
|
}, { notify: false });
|
|
}
|
|
return {
|
|
bootstrapDefaults: bootstrapDefaults,
|
|
embeddedBootstrap: embeddedBootstrap,
|
|
handoff: handoff,
|
|
store: store,
|
|
};
|
|
}
|