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.

refactor(cloudcp): factor Pulse Account runtime creation

rcourtman7e42cb16f5b1
diff --git a/internal/cloudcp/portal/dist/build_manifest.json b/internal/cloudcp/portal/dist/build_manifest.json
index 77c97af17b..f4493e9405 100644
--- a/internal/cloudcp/portal/dist/build_manifest.json
+++ b/internal/cloudcp/portal/dist/build_manifest.json
@@ -1,5 +1,5 @@
{
- "source_hash": "255f67aa247da18eafb4e062dbc9c92b71a4bcd188e28e5ddfded4e3451e7fce",
+ "source_hash": "a60b0c0002a91c72c4127150533ff4570e3cd5448a3394b281f7fa79832f8c8c",
"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 507ae7fe99..ce1016057d 100644
--- a/internal/cloudcp/portal/dist/portal_app.js
+++ b/internal/cloudcp/portal/dist/portal_app.js
@@ -678,133 +678,6 @@
};
}
- // src/store.ts
- function createAnonymousBootstrap(bootstrapDefaults2, overrides = {}) {
- return {
- authenticated: false,
- email: "",
- ...bootstrapDefaults2,
- ...overrides,
- accounts: normalizeAccounts(overrides.accounts)
- };
- }
- function normalizeBootstrap(bootstrapDefaults2, raw) {
- return createAnonymousBootstrap(bootstrapDefaults2, raw || {});
- }
- function createPortalStore(bootstrapDefaults2, initialBootstrap) {
- var bootstrapState = normalizeBootstrap(bootstrapDefaults2, initialBootstrap);
- var accountState = createPortalAccountState();
- var loginState = createPortalLoginState();
- var serviceState = createPortalServiceState();
- syncLoginStateBootstrapEmail(loginState, bootstrapState.email || "");
- syncServiceStateBootstrapEmail(serviceState, bootstrapState.email || "");
- var accountSubscribers = /* @__PURE__ */ new Set();
- var bootstrapSubscribers = /* @__PURE__ */ new Set();
- var loginSubscribers = /* @__PURE__ */ new Set();
- var serviceSubscribers = /* @__PURE__ */ new Set();
- function notify(subscribers) {
- subscribers.forEach(function(listener) {
- listener();
- });
- }
- return {
- getBootstrap: function() {
- return bootstrapState;
- },
- getAccountState: function() {
- return accountState;
- },
- getLoginState: function() {
- return loginState;
- },
- getServiceState: function() {
- return serviceState;
- },
- setBootstrap: function(nextBootstrap) {
- bootstrapState = normalizeBootstrap(bootstrapDefaults2, nextBootstrap);
- syncLoginStateBootstrapEmail(loginState, bootstrapState.email || "");
- syncServiceStateBootstrapEmail(serviceState, bootstrapState.email || "");
- notify(bootstrapSubscribers);
- return bootstrapState;
- },
- updateAccountState: function(mutator, options) {
- mutator(accountState);
- if (!options || options.notify !== false) {
- notify(accountSubscribers);
- }
- return accountState;
- },
- updateLoginState: function(mutator, options) {
- mutator(loginState);
- if (!options || options.notify !== false) {
- notify(loginSubscribers);
- }
- return loginState;
- },
- updateServiceState: function(mutator, options) {
- mutator(serviceState);
- if (!options || options.notify !== false) {
- notify(serviceSubscribers);
- }
- return serviceState;
- },
- subscribeBootstrap: function(listener) {
- bootstrapSubscribers.add(listener);
- return function() {
- bootstrapSubscribers.delete(listener);
- };
- },
- subscribeAccount: function(listener) {
- accountSubscribers.add(listener);
- return function() {
- accountSubscribers.delete(listener);
- };
- },
- subscribeLogin: function(listener) {
- loginSubscribers.add(listener);
- return function() {
- loginSubscribers.delete(listener);
- };
- },
- subscribeServices: function(listener) {
- serviceSubscribers.add(listener);
- return function() {
- serviceSubscribers.delete(listener);
- };
- }
- };
- }
- function normalizeAccounts(accounts) {
- return Array.isArray(accounts) ? accounts : [];
- }
-
- // src/runtime.ts
- function readEmbeddedBootstrap() {
- const bootstrapEl = document.getElementById("pulse-account-bootstrap");
- if (!bootstrapEl) {
- return {};
- }
- try {
- return JSON.parse(bootstrapEl.textContent || "{}");
- } catch {
- return {};
- }
- }
- var embeddedBootstrap = readEmbeddedBootstrap();
- var bootstrapDefaults = {
- 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 || "",
- 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: embeddedBootstrap.signup_path || "/signup",
- 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"
- };
- var portalStore = createPortalStore(bootstrapDefaults, embeddedBootstrap);
-
// src/services_view.ts
function getElement3(id) {
return document.getElementById(id);
@@ -1496,6 +1369,141 @@
renderPortalApp();
}
+ // src/store.ts
+ function createAnonymousBootstrap(bootstrapDefaults, overrides = {}) {
+ return {
+ authenticated: false,
+ email: "",
+ ...bootstrapDefaults,
+ ...overrides,
+ accounts: normalizeAccounts(overrides.accounts)
+ };
+ }
+ function normalizeBootstrap(bootstrapDefaults, raw) {
+ return createAnonymousBootstrap(bootstrapDefaults, raw || {});
+ }
+ function createPortalStore(bootstrapDefaults, initialBootstrap) {
+ var bootstrapState = normalizeBootstrap(bootstrapDefaults, initialBootstrap);
+ var accountState = createPortalAccountState();
+ var loginState = createPortalLoginState();
+ var serviceState = createPortalServiceState();
+ syncLoginStateBootstrapEmail(loginState, bootstrapState.email || "");
+ syncServiceStateBootstrapEmail(serviceState, bootstrapState.email || "");
+ var accountSubscribers = /* @__PURE__ */ new Set();
+ var bootstrapSubscribers = /* @__PURE__ */ new Set();
+ var loginSubscribers = /* @__PURE__ */ new Set();
+ var serviceSubscribers = /* @__PURE__ */ new Set();
+ function notify(subscribers) {
+ subscribers.forEach(function(listener) {
+ listener();
+ });
+ }
+ return {
+ getBootstrap: function() {
+ return bootstrapState;
+ },
+ getAccountState: function() {
+ return accountState;
+ },
+ getLoginState: function() {
+ return loginState;
+ },
+ getServiceState: function() {
+ return serviceState;
+ },
+ setBootstrap: function(nextBootstrap) {
+ bootstrapState = normalizeBootstrap(bootstrapDefaults, nextBootstrap);
+ syncLoginStateBootstrapEmail(loginState, bootstrapState.email || "");
+ syncServiceStateBootstrapEmail(serviceState, bootstrapState.email || "");
+ notify(bootstrapSubscribers);
+ return bootstrapState;
+ },
+ updateAccountState: function(mutator, options) {
+ mutator(accountState);
+ if (!options || options.notify !== false) {
+ notify(accountSubscribers);
+ }
+ return accountState;
+ },
+ updateLoginState: function(mutator, options) {
+ mutator(loginState);
+ if (!options || options.notify !== false) {
+ notify(loginSubscribers);
+ }
+ return loginState;
+ },
+ updateServiceState: function(mutator, options) {
+ mutator(serviceState);
+ if (!options || options.notify !== false) {
+ notify(serviceSubscribers);
+ }
+ return serviceState;
+ },
+ subscribeBootstrap: function(listener) {
+ bootstrapSubscribers.add(listener);
+ return function() {
+ bootstrapSubscribers.delete(listener);
+ };
+ },
+ subscribeAccount: function(listener) {
+ accountSubscribers.add(listener);
+ return function() {
+ accountSubscribers.delete(listener);
+ };
+ },
+ subscribeLogin: function(listener) {
+ loginSubscribers.add(listener);
+ return function() {
+ loginSubscribers.delete(listener);
+ };
+ },
+ subscribeServices: function(listener) {
+ serviceSubscribers.add(listener);
+ return function() {
+ serviceSubscribers.delete(listener);
+ };
+ }
+ };
+ }
+ function normalizeAccounts(accounts) {
+ return Array.isArray(accounts) ? accounts : [];
+ }
+
+ // src/runtime.ts
+ function readEmbeddedBootstrap() {
+ const bootstrapEl = document.getElementById("pulse-account-bootstrap");
+ if (!bootstrapEl) {
+ return {};
+ }
+ try {
+ return JSON.parse(bootstrapEl.textContent || "{}");
+ } catch {
+ return {};
+ }
+ }
+ function createBootstrapDefaults(embeddedBootstrap) {
+ return {
+ 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 || "",
+ 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: embeddedBootstrap.signup_path || "/signup",
+ 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"
+ };
+ }
+ function createPortalRuntime(embeddedBootstrap = readEmbeddedBootstrap()) {
+ var bootstrapDefaults = createBootstrapDefaults(embeddedBootstrap);
+ return {
+ bootstrapDefaults,
+ embeddedBootstrap,
+ store: createPortalStore(bootstrapDefaults, embeddedBootstrap)
+ };
+ }
+
// src/app.ts
function installPortalApp(deps) {
function applyBootstrap(data) {
@@ -1556,9 +1564,10 @@
};
}
function startPortalApp() {
+ var runtime = createPortalRuntime();
return installPortalApp({
- bootstrapDefaults,
- store: portalStore
+ bootstrapDefaults: runtime.bootstrapDefaults,
+ store: runtime.store
});
}
diff --git a/internal/cloudcp/portal/frontend/src/app.test.ts b/internal/cloudcp/portal/frontend/src/app.test.ts
index 18e71523d4..c2e4b7fd84 100644
--- a/internal/cloudcp/portal/frontend/src/app.test.ts
+++ b/internal/cloudcp/portal/frontend/src/app.test.ts
@@ -1,6 +1,7 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { installPortalApp } from './app';
+import { createBootstrapDefaults, createPortalRuntime } from './runtime';
import { createPortalStore } from './store';
import type { PortalBootstrapData } from './types';
@@ -94,4 +95,26 @@ describe('portal app', function() {
expect(store.getBootstrap().email).toBe('');
expect(store.getBootstrap().accounts).toEqual([]);
});
+
+ it('starts from the owned runtime factory instead of import-time globals', function() {
+ document.body.innerHTML = `
+ <script id="pulse-account-bootstrap" type="application/json">
+ {"authenticated":true,"email":"[email protected]","public_site_url":"https://cloud.pulserelay.pro","accounts":[]}
+ </script>
+ <div id="portal-user-info"></div>
+ <div id="portal-app-root"></div>
+ <div id="toast"></div>
+ `;
+
+ var runtime = createPortalRuntime({
+ authenticated: true,
+ email: '[email protected]',
+ public_site_url: 'https://cloud.pulserelay.pro',
+ accounts: [],
+ });
+
+ expect(runtime.bootstrapDefaults.public_site_url).toBe('https://cloud.pulserelay.pro');
+ expect(runtime.store.getBootstrap().authenticated).toBe(true);
+ expect(runtime.store.getBootstrap().email).toBe('[email protected]');
+ });
});
diff --git a/internal/cloudcp/portal/frontend/src/app.ts b/internal/cloudcp/portal/frontend/src/app.ts
index c8bff89712..c9475e8dc8 100644
--- a/internal/cloudcp/portal/frontend/src/app.ts
+++ b/internal/cloudcp/portal/frontend/src/app.ts
@@ -1,10 +1,10 @@
import { installAccountController } from './account_controller';
import { installAccountRuntime } from './account_runtime';
import { installAuthController } from './auth_controller';
-import { bootstrapDefaults, portalStore } from './runtime';
import { installServicesRuntime } from './services';
import { installShell } from './shell';
import { createAnonymousBootstrap } from './store';
+import { createPortalRuntime } from './runtime';
import type { PortalStore } from './store';
import type { PortalBootstrapData } from './types';
@@ -90,8 +90,9 @@ export function installPortalApp(deps: PortalAppDeps): PortalApp {
}
export function startPortalApp(): PortalApp {
+ var runtime = createPortalRuntime();
return installPortalApp({
- bootstrapDefaults: bootstrapDefaults,
- store: portalStore,
+ bootstrapDefaults: runtime.bootstrapDefaults,
+ store: runtime.store,
});
}
diff --git a/internal/cloudcp/portal/frontend/src/runtime.test.ts b/internal/cloudcp/portal/frontend/src/runtime.test.ts
new file mode 100644
index 0000000000..37cab7702a
--- /dev/null
+++ b/internal/cloudcp/portal/frontend/src/runtime.test.ts
@@ -0,0 +1,38 @@
+import { describe, expect, it } from 'vitest';
+
+import { createBootstrapDefaults, createPortalRuntime } from './runtime';
+
+describe('portal runtime', function() {
+ it('derives bootstrap defaults from embedded bootstrap data', function() {
+ var defaults = createBootstrapDefaults({
+ public_site_url: 'https://cloud.pulserelay.pro',
+ support_email: '[email protected]',
+ commercial_api_base_url: 'https://license.pulserelay.pro',
+ portal_path: '/account',
+ bootstrap_path: '/api/account/bootstrap',
+ magic_link_request_path: '/api/public/account/magic-link/request',
+ signup_path: '/join',
+ logout_path: '/signout',
+ account_api_base_path: '/api/account-links',
+ portal_api_base_path: '/api/account',
+ });
+
+ expect(defaults.public_site_url).toBe('https://cloud.pulserelay.pro');
+ expect(defaults.support_email).toBe('[email protected]');
+ expect(defaults.portal_path).toBe('/account');
+ expect(defaults.bootstrap_path).toBe('/api/account/bootstrap');
+ });
+
+ it('creates a store from runtime bootstrap input', function() {
+ var runtime = createPortalRuntime({
+ authenticated: true,
+ email: '[email protected]',
+ accounts: [],
+ commercial_api_base_url: 'https://license.pulserelay.pro',
+ });
+
+ expect(runtime.store.getBootstrap().authenticated).toBe(true);
+ expect(runtime.store.getBootstrap().email).toBe('[email protected]');
+ expect(runtime.bootstrapDefaults.commercial_api_base_url).toBe('https://license.pulserelay.pro');
+ });
+});
diff --git a/internal/cloudcp/portal/frontend/src/runtime.ts b/internal/cloudcp/portal/frontend/src/runtime.ts
index aa82897228..7169a6b629 100644
--- a/internal/cloudcp/portal/frontend/src/runtime.ts
+++ b/internal/cloudcp/portal/frontend/src/runtime.ts
@@ -1,6 +1,13 @@
import { createPortalStore } from './store';
+import type { PortalStore } from './store';
import type { PortalBootstrapData } from './types';
+export interface PortalRuntime {
+ bootstrapDefaults: Omit<PortalBootstrapData, 'authenticated' | 'email' | 'accounts'>;
+ embeddedBootstrap: Partial<PortalBootstrapData>;
+ store: PortalStore;
+}
+
function readEmbeddedBootstrap(): Partial<PortalBootstrapData> {
const bootstrapEl = document.getElementById('pulse-account-bootstrap');
if (!bootstrapEl) {
@@ -13,19 +20,30 @@ function readEmbeddedBootstrap(): Partial<PortalBootstrapData> {
}
}
-const embeddedBootstrap = readEmbeddedBootstrap();
-
-export const bootstrapDefaults: Omit<PortalBootstrapData, 'authenticated' | 'email' | 'accounts'> = {
- 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 || '',
- 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: embeddedBootstrap.signup_path || '/signup',
- 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 createBootstrapDefaults(
+ embeddedBootstrap: Partial<PortalBootstrapData>
+): Omit<PortalBootstrapData, 'authenticated' | 'email' | 'accounts'> {
+ return {
+ 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 || '',
+ 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: embeddedBootstrap.signup_path || '/signup',
+ 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 const portalStore = createPortalStore(bootstrapDefaults, embeddedBootstrap);
+export function createPortalRuntime(
+ embeddedBootstrap: Partial<PortalBootstrapData> = readEmbeddedBootstrap()
+): PortalRuntime {
+ var bootstrapDefaults = createBootstrapDefaults(embeddedBootstrap);
+ return {
+ bootstrapDefaults: bootstrapDefaults,
+ embeddedBootstrap: embeddedBootstrap,
+ store: createPortalStore(bootstrapDefaults, embeddedBootstrap),
+ };
+}