Skip to content

armgit / Pulse

Public Imported from GitHub
0

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.

feat(cloudcp): support Pulse Account utility handoff

rcourtmanc22f96b6596a
diff --git a/internal/cloudcp/portal/dist/build_manifest.json b/internal/cloudcp/portal/dist/build_manifest.json
index 0036ffc85e..fc7302ba29 100644
--- a/internal/cloudcp/portal/dist/build_manifest.json
+++ b/internal/cloudcp/portal/dist/build_manifest.json
@@ -1,5 +1,5 @@
{
- "source_hash": "f28967eb0031c49b09af97d9d4117a7d4eb01d8125632ad125af1edd498fb944",
+ "source_hash": "ff17df3377ad8b87575ba85c1dcd1ef9b27b51b80298de843c03c4b87848e350",
"build_inputs": [
"package.json",
"tsconfig.json",
diff --git a/internal/cloudcp/portal/dist/portal_app.js b/internal/cloudcp/portal/dist/portal_app.js
index 25f4ef16c6..ef993df0ae 100644
--- a/internal/cloudcp/portal/dist/portal_app.js
+++ b/internal/cloudcp/portal/dist/portal_app.js
@@ -1597,6 +1597,37 @@
return {};
}
}
+ function normalizeHandoffEmail(value) {
+ return String(value || "").trim();
+ }
+ function normalizeHandoffService(value) {
+ switch (String(value || "").trim()) {
+ case "manage":
+ return "manage-service-panel";
+ case "retrieve":
+ return "retrieve-service-panel";
+ case "refund":
+ return "refund-service-panel";
+ case "data":
+ return "data-service-panel";
+ default:
+ return "";
+ }
+ }
+ function readPortalRuntimeHandoff(locationHref = window.location.href) {
+ try {
+ var params = new URL(locationHref).searchParams;
+ return {
+ email: normalizeHandoffEmail(params.get("email")),
+ openPanelID: normalizeHandoffService(params.get("service"))
+ };
+ } catch {
+ return {
+ email: "",
+ openPanelID: ""
+ };
+ }
+ }
function createBootstrapDefaults(embeddedBootstrap) {
return {
public_site_url: embeddedBootstrap.public_site_url || "https://pulserelay.pro",
@@ -1611,12 +1642,31 @@
portal_api_base_path: embeddedBootstrap.portal_api_base_path || "/api/portal"
};
}
- function createPortalRuntime(embeddedBootstrap = readEmbeddedBootstrap()) {
+ function createPortalRuntime(embeddedBootstrap = readEmbeddedBootstrap(), handoff = readPortalRuntimeHandoff()) {
var bootstrapDefaults = createBootstrapDefaults(embeddedBootstrap);
+ var store = createPortalStore(bootstrapDefaults, embeddedBootstrap);
+ if (handoff.email) {
+ store.updateLoginState(function(loginState) {
+ loginState.emailValue = handoff.email;
+ }, { notify: false });
+ store.updateServiceState(function(serviceState) {
+ serviceState.flows.manage.emailValue = handoff.email;
+ serviceState.flows.retrieve.emailValue = handoff.email;
+ serviceState.flows.export.emailValue = handoff.email;
+ serviceState.flows.delete.emailValue = handoff.email;
+ serviceState.refund.emailValue = handoff.email;
+ }, { notify: false });
+ }
+ if (handoff.openPanelID) {
+ store.updateServiceState(function(serviceState) {
+ serviceState.openPanelID = handoff.openPanelID;
+ }, { notify: false });
+ }
return {
bootstrapDefaults,
embeddedBootstrap,
- store: createPortalStore(bootstrapDefaults, embeddedBootstrap)
+ handoff,
+ store
};
}
diff --git a/internal/cloudcp/portal/frontend/src/runtime.test.ts b/internal/cloudcp/portal/frontend/src/runtime.test.ts
index 37cab7702a..5aeceb1651 100644
--- a/internal/cloudcp/portal/frontend/src/runtime.test.ts
+++ b/internal/cloudcp/portal/frontend/src/runtime.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
-import { createBootstrapDefaults, createPortalRuntime } from './runtime';
+import { createBootstrapDefaults, createPortalRuntime, readPortalRuntimeHandoff } from './runtime';
describe('portal runtime', function() {
it('derives bootstrap defaults from embedded bootstrap data', function() {
@@ -35,4 +35,30 @@ describe('portal runtime', function() {
expect(runtime.store.getBootstrap().email).toBe('[email protected]');
expect(runtime.bootstrapDefaults.commercial_api_base_url).toBe('https://license.pulserelay.pro');
});
+
+ it('derives canonical email and service handoff from the portal URL', function() {
+ var handoff = readPortalRuntimeHandoff('https://cloud.pulserelay.pro/portal?email=buyer%40example.com&service=retrieve');
+
+ expect(handoff.email).toBe('[email protected]');
+ expect(handoff.openPanelID).toBe('retrieve-service-panel');
+ });
+
+ it('applies email and service handoff to the initial portal store', function() {
+ var runtime = createPortalRuntime(
+ {
+ authenticated: false,
+ email: '',
+ accounts: [],
+ },
+ {
+ email: '[email protected]',
+ openPanelID: 'refund-service-panel',
+ }
+ );
+
+ expect(runtime.handoff.email).toBe('[email protected]');
+ expect(runtime.store.getLoginState().emailValue).toBe('[email protected]');
+ expect(runtime.store.getServiceState().refund.emailValue).toBe('[email protected]');
+ expect(runtime.store.getServiceState().openPanelID).toBe('refund-service-panel');
+ });
});
diff --git a/internal/cloudcp/portal/frontend/src/runtime.ts b/internal/cloudcp/portal/frontend/src/runtime.ts
index 7169a6b629..6c4f47fe31 100644
--- a/internal/cloudcp/portal/frontend/src/runtime.ts
+++ b/internal/cloudcp/portal/frontend/src/runtime.ts
@@ -2,9 +2,15 @@ import { createPortalStore } from './store';
import type { PortalStore } from './store';
import type { PortalBootstrapData } from './types';
+export interface PortalRuntimeHandoff {
+ email: string;
+ openPanelID: string;
+}
+
export interface PortalRuntime {
bootstrapDefaults: Omit<PortalBootstrapData, 'authenticated' | 'email' | 'accounts'>;
embeddedBootstrap: Partial<PortalBootstrapData>;
+ handoff: PortalRuntimeHandoff;
store: PortalStore;
}
@@ -20,6 +26,40 @@ function readEmbeddedBootstrap(): Partial<PortalBootstrapData> {
}
}
+function normalizeHandoffEmail(value: string | null): string {
+ return String(value || '').trim();
+}
+
+function normalizeHandoffService(value: string | null): string {
+ switch (String(value || '').trim()) {
+ case 'manage':
+ return 'manage-service-panel';
+ case 'retrieve':
+ return 'retrieve-service-panel';
+ case 'refund':
+ return 'refund-service-panel';
+ case 'data':
+ return 'data-service-panel';
+ default:
+ return '';
+ }
+}
+
+export function readPortalRuntimeHandoff(locationHref: string | undefined = window.location.href): PortalRuntimeHandoff {
+ try {
+ var params = new URL(locationHref).searchParams;
+ return {
+ email: normalizeHandoffEmail(params.get('email')),
+ openPanelID: normalizeHandoffService(params.get('service')),
+ };
+ } catch {
+ return {
+ email: '',
+ openPanelID: '',
+ };
+ }
+}
+
export function createBootstrapDefaults(
embeddedBootstrap: Partial<PortalBootstrapData>
): Omit<PortalBootstrapData, 'authenticated' | 'email' | 'accounts'> {
@@ -38,12 +78,32 @@ export function createBootstrapDefaults(
}
export function createPortalRuntime(
- embeddedBootstrap: Partial<PortalBootstrapData> = readEmbeddedBootstrap()
+ 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.updateServiceState(function(serviceState) {
+ serviceState.flows.manage.emailValue = handoff.email;
+ serviceState.flows.retrieve.emailValue = handoff.email;
+ serviceState.flows.export.emailValue = handoff.email;
+ serviceState.flows.delete.emailValue = handoff.email;
+ serviceState.refund.emailValue = handoff.email;
+ }, { notify: false });
+ }
+ if (handoff.openPanelID) {
+ store.updateServiceState(function(serviceState) {
+ serviceState.openPanelID = handoff.openPanelID;
+ }, { notify: false });
+ }
return {
bootstrapDefaults: bootstrapDefaults,
embeddedBootstrap: embeddedBootstrap,
- store: createPortalStore(bootstrapDefaults, embeddedBootstrap),
+ handoff: handoff,
+ store: store,
};
}