diff --git a/backend/coreconfig/coreconfig.go b/backend/coreconfig/coreconfig.go index e85e8d5..67ff1cd 100644 --- a/backend/coreconfig/coreconfig.go +++ b/backend/coreconfig/coreconfig.go @@ -126,7 +126,7 @@ func normalizeInfo(info Info) Info { // Handler is the X-Internal-Auth-gated PUT /api/core-services/internal endpoint // ProjectConfigurator calls to push a fresh Info: mount it at that path (see // ProjectConfigurator/README.md) behind a secret check for this service's own -// INTERNAL_SERVICE_SECRET (the same value ProjectConfigurator and CarrierNode were configured +// SECRET (the same value ProjectConfigurator and CarrierNode were configured // with - an empty secret refuses every caller, the same fail-closed default ProjectConfigurator's // own internal-auth-gated routes use). func Handler(secret string, store *Store) http.HandlerFunc { diff --git a/packages/node-backend/README.md b/packages/node-backend/README.md index 9411a61..5fc10ba 100644 --- a/packages/node-backend/README.md +++ b/packages/node-backend/README.md @@ -44,7 +44,7 @@ coreConfig.onUpdate((info) => authClient.setBaseUrl(info.authGuardUrl)); // in your own route for PUT /api/core-services/internal: app.put('/api/core-services/internal', (req, res) => { - if (req.get('X-Internal-Auth') !== process.env.INTERNAL_SERVICE_SECRET) { + if (req.get('X-Internal-Auth') !== process.env.SECRET) { return res.status(401).json({ error: 'internal service authentication required' }); } const info = coreConfig.set(req.body); diff --git a/packages/node-backend/src/coreconfig.js b/packages/node-backend/src/coreconfig.js index 1a8cb00..32ff499 100644 --- a/packages/node-backend/src/coreconfig.js +++ b/packages/node-backend/src/coreconfig.js @@ -12,7 +12,7 @@ * Framework-agnostic: this module has no HTTP server of its own. A service * wires the actual `PUT /api/core-services/internal` route in its own * framework (Express, plain `http`, ...), gated behind its own - * INTERNAL_SERVICE_SECRET check the same way its other internal-service + * SECRET check the same way its other internal-service * routes already are, decodes the JSON body with `Info.fromJSON`, and calls * `store.set(info)` - see `Store.set`'s doc comment for a minimal Express * example. @@ -118,7 +118,7 @@ export class Store { * the other value. Returns the resulting Info. Minimal Express usage: * * app.put('/api/core-services/internal', (req, res) => { - * if (req.get('X-Internal-Auth') !== process.env.INTERNAL_SERVICE_SECRET) { + * if (req.get('X-Internal-Auth') !== process.env.SECRET) { * return res.status(401).json({ error: 'internal service authentication required' }); * } * const info = coreConfigStore.set(Info.fromJSON(req.body)); diff --git a/packages/python-backend/README.md b/packages/python-backend/README.md index 7aebf24..824c8dd 100644 --- a/packages/python-backend/README.md +++ b/packages/python-backend/README.md @@ -97,7 +97,7 @@ core_config.on_update(lambda info: auth_client.set_base_url(info.auth_guard_url) # in your framework's route for PUT /api/core-services/internal: async def push_core_services(request): - if request.headers.get("X-Internal-Auth") != INTERNAL_SERVICE_SECRET: + if request.headers.get("X-Internal-Auth") != SECRET: raise HTTPException(status_code=401) body = await request.json() info = core_config.set(CoreConfigInfo.from_json(body)) diff --git a/packages/python-backend/src/shared_backend/coreconfig.py b/packages/python-backend/src/shared_backend/coreconfig.py index fb95c69..dc95981 100644 --- a/packages/python-backend/src/shared_backend/coreconfig.py +++ b/packages/python-backend/src/shared_backend/coreconfig.py @@ -11,7 +11,7 @@ Framework-agnostic, like the rest of this package (see the top-level README's "HTTP framework adapters stay in each service" note): this module has no HTTP server of its own. A service wires the actual PUT /api/core-services/internal route in its own framework (FastAPI, -aiohttp, ...), gated behind its own INTERNAL_SERVICE_SECRET check the same +aiohttp, ...), gated behind its own SECRET check the same way its other internal-service routes already are, decodes the JSON body into an `Info`, and calls `Store.set(info)` -- see `Store.set`'s doc comment for a minimal FastAPI example. @@ -108,7 +108,7 @@ class Store: @app.put("/api/core-services/internal") async def push_core_services(request: Request): - if request.headers.get("X-Internal-Auth") != INTERNAL_SERVICE_SECRET: + if request.headers.get("X-Internal-Auth") != SECRET: raise HTTPException(status_code=401) body = await request.json() info = core_config_store.set(Info.from_json(body)) diff --git a/packages/web-ui/src/lib/components/AppShell.svelte b/packages/web-ui/src/lib/components/AppShell.svelte index 3770f35..dec5990 100644 --- a/packages/web-ui/src/lib/components/AppShell.svelte +++ b/packages/web-ui/src/lib/components/AppShell.svelte @@ -1,9 +1,11 @@
diff --git a/packages/web-ui/src/lib/components/PrimaryColorPicker.svelte b/packages/web-ui/src/lib/components/PrimaryColorPicker.svelte new file mode 100644 index 0000000..a90e49b --- /dev/null +++ b/packages/web-ui/src/lib/components/PrimaryColorPicker.svelte @@ -0,0 +1,115 @@ + + +
+ {label} +
+ + {#each PRIMARY_COLOR_PALETTE as color (color.name)} + + {/each} +
+ {#if selected} + {primaryColorByName(selected)?.name} + {:else} + Default + {/if} +
+ + diff --git a/packages/web-ui/src/lib/index.ts b/packages/web-ui/src/lib/index.ts index ab33761..a571e34 100644 --- a/packages/web-ui/src/lib/index.ts +++ b/packages/web-ui/src/lib/index.ts @@ -12,6 +12,7 @@ export { default as NotificationStack } from './components/NotificationStack.sve export { default as PageHeader } from './components/PageHeader.svelte'; export { default as Pagination } from './components/Pagination.svelte'; export { default as ProfileDialog } from './components/ProfileDialog.svelte'; +export { default as PrimaryColorPicker } from './components/PrimaryColorPicker.svelte'; export { default as SectionTitle } from './components/SectionTitle.svelte'; export { default as SettingsDialog } from './components/SettingsDialog.svelte'; export { default as StatusDialog } from './components/StatusDialog.svelte'; @@ -19,6 +20,16 @@ export { default as StatusWidget } from './components/StatusWidget.svelte'; export { default as TotpSettings } from './components/TotpSettings.svelte'; export { default as UserManagement } from './components/UserManagement.svelte'; export { notifications, notify } from './notifications.svelte'; +export { + PRIMARY_COLOR_PALETTE, + applyPrimaryColor, + initPrimaryColor, + primaryColorByName, + setPrimaryColor, + setPrimaryColorUser, + storedPrimaryColor, +} from './primary-color.svelte'; +export type { PaletteColor } from './primary-color.svelte'; export type { NotificationEntry, NotificationVariant } from './notifications.svelte'; export type { AboutLink, diff --git a/packages/web-ui/src/lib/primary-color.svelte.ts b/packages/web-ui/src/lib/primary-color.svelte.ts new file mode 100644 index 0000000..fd515a9 --- /dev/null +++ b/packages/web-ui/src/lib/primary-color.svelte.ts @@ -0,0 +1,122 @@ +export type PaletteColor = { name: string; dark: string; light: string; darkFg: string } + +export const PRIMARY_COLOR_PALETTE: PaletteColor[] = [ + { name: 'Vermilion', dark: '#f59080', light: '#db3e24', darkFg: '#2b110d' }, + { name: 'Tangerine', dark: '#fb923c', light: '#c2410c', darkFg: '#2b1206' }, + { name: 'Marigold', dark: '#f5b380', light: '#db7524', darkFg: '#2b1a0d' }, + { name: 'Amber', dark: '#f5ca80', light: '#b87d14', darkFg: '#2b200d' }, + { name: 'Gold', dark: '#f5e280', light: '#b89d14', darkFg: '#2b260d' }, + { name: 'Honey', dark: '#f1f580', light: '#b2b814', darkFg: '#2a2b0d' }, + { name: 'Chartreuse', dark: '#daf580', light: '#92b814', darkFg: '#242b0d' }, + { name: 'Lime', dark: '#c3f580', light: '#72b814', darkFg: '#1e2b0d' }, + { name: 'Spring Green', dark: '#abf580', light: '#51b814', darkFg: '#182b0d' }, + { name: 'Shamrock', dark: '#94f580', light: '#44db24', darkFg: '#122b0d' }, + { name: 'Emerald', dark: '#80f582', light: '#24db28', darkFg: '#0d2b0d' }, + { name: 'Jade', dark: '#80f599', light: '#24db4c', darkFg: '#0d2b13' }, + { name: 'Clover', dark: '#22c55e', light: '#16a34a', darkFg: '#052e14' }, + { name: 'Mint', dark: '#80f5bc', light: '#24db83', darkFg: '#0d2b1d' }, + { name: 'Seafoam', dark: '#80f5d4', light: '#24dba8', darkFg: '#0d2b23' }, + { name: 'Turquoise', dark: '#80f5ec', light: '#24dbce', darkFg: '#0d2b29' }, + { name: 'Aqua', dark: '#80e5f5', light: '#24c3db', darkFg: '#0d272b' }, + { name: 'Cyan', dark: '#80cef5', light: '#249edb', darkFg: '#0d212b' }, + { name: 'Sky Blue', dark: '#80b6f5', light: '#2479db', darkFg: '#0d1b2b' }, + { name: 'Cornflower', dark: '#3b82f6', light: '#2563eb', darkFg: '#0a1733' }, + { name: 'Indigo', dark: '#99a1d7', light: '#4355b9', darkFg: '#12162b' }, + { name: 'Iris', dark: '#818cf8', light: '#4f46e5', darkFg: '#12102e' }, + { name: 'Periwinkle', dark: '#9880f5', light: '#4a24db', darkFg: '#130d2b' }, + { name: 'Violet', dark: '#ae80f5', light: '#6d24db', darkFg: '#190d2b' }, + { name: 'Purple', dark: '#c580f5', light: '#9124db', darkFg: '#1f0d2b' }, + { name: 'Orchid', dark: '#dc80f5', light: '#b424db', darkFg: '#250d2b' }, + { name: 'Magenta', dark: '#f280f5', light: '#d824db', darkFg: '#2b0d2b' }, + { name: 'Fuchsia', dark: '#f580e0', light: '#db24bb', darkFg: '#2b0d26' }, + { name: 'Pink', dark: '#f580ca', light: '#db2498', darkFg: '#2b0d20' }, + { name: 'Rose', dark: '#f580b3', light: '#db2474', darkFg: '#2b0d1a' }, + { name: 'Ruby', dark: '#f5809c', light: '#db2451', darkFg: '#2b0d14' }, + { name: 'Crimson', dark: '#f58086', light: '#db242d', darkFg: '#2b0d0e' }, +] + +const paletteByName = Object.fromEntries(PRIMARY_COLOR_PALETTE.map((color) => [color.name, color])) as Record< + string, + PaletteColor +> +const primaryVars = ['--color-primary', '--color-accent', '--color-ring'] +const foregroundVars = ['--color-primary-fg', '--color-accent-fg'] +const activeUserAttribute = 'data-primary-color-user' +const activeProjects = new Set() + +function normalizeUserKey(userKey: string): string { + return userKey.trim().toLowerCase() || 'anonymous' +} + +function activeUserKey(): string { + if (typeof document === 'undefined') return 'anonymous' + return normalizeUserKey(document.documentElement.getAttribute(activeUserAttribute) || '') +} + +function storageKey(projectKey: string, userKey = activeUserKey()): string { + const project = encodeURIComponent(projectKey.trim().toLowerCase() || 'application') + const user = encodeURIComponent(normalizeUserKey(userKey)) + return `primary-color:${project}:${user}` +} + +function readStoredColor(projectKey: string): string { + try { + return localStorage.getItem(storageKey(projectKey)) || '' + } catch { + return '' + } +} + +export function applyPrimaryColor(_projectKey: string, colorName: string): void { + if (typeof document === 'undefined') return + const color = paletteByName[colorName] + const root = document.documentElement.style + if (!color) { + for (const name of [...primaryVars, ...foregroundVars]) root.removeProperty(name) + return + } + const dark = document.documentElement.getAttribute('data-theme') === 'dark' + const primary = dark ? color.dark : color.light + const foreground = dark ? color.darkFg : '#ffffff' + for (const name of primaryVars) root.setProperty(name, primary) + for (const name of foregroundVars) root.setProperty(name, foreground) +} + +export function setPrimaryColor(projectKey: string, colorName: string): void { + try { + const key = storageKey(projectKey) + if (colorName) localStorage.setItem(key, colorName) + else localStorage.removeItem(key) + } catch { + // The current page still receives the selected color if storage is unavailable. + } + applyPrimaryColor(projectKey, colorName) +} + +export function setPrimaryColorUser(userKey: string): void { + if (typeof document === 'undefined') return + document.documentElement.setAttribute(activeUserAttribute, normalizeUserKey(userKey)) + for (const projectKey of activeProjects) { + applyPrimaryColor(projectKey, readStoredColor(projectKey)) + } +} + +export function initPrimaryColor(projectKey: string, userKey = ''): () => void { + if (typeof document === 'undefined') return () => undefined + if (userKey) setPrimaryColorUser(userKey) + activeProjects.add(projectKey.trim().toLowerCase() || 'application') + const stored = readStoredColor(projectKey) + applyPrimaryColor(projectKey, stored) + const observer = new MutationObserver(() => applyPrimaryColor(projectKey, readStoredColor(projectKey))) + observer.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'] }) + return () => observer.disconnect() +} + +export function storedPrimaryColor(projectKey: string): string { + const stored = readStoredColor(projectKey) + return paletteByName[stored] ? stored : '' +} + +export function primaryColorByName(name: string): PaletteColor | undefined { + return paletteByName[name] +}