diff --git a/README.md b/README.md index ffb80d9..cfcc1a6 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ AuthGuard integration has three states: Because AuthGuard doesn't know "this is CollabTable's initial account" and can't answer "have any accounts been registered yet" (it's a shared identity store other projects and other CollabTable instances may already use), the one-time setup screen is instead gated by a small local flag in Postgres, independent of AuthGuard's own state. -`AUTHGUARD_URL` and `CARRIERNODE_URL` are also only the bootstrap fallback: once CollabTable is registered in ProjectConfigurator's Projects workspace, ProjectConfigurator pushes both values here automatically (`PUT /api/core-services/internal`, `X-Internal-Auth`-gated with `INTERNAL_SERVICE_SECRET`) and keeps them current with no restart — see `Core/ProjectConfigurator/README.md`'s "Pushing core service info to other projects". This means `AUTHGUARD_URL` no longer needs to be set at all for a registered deployment: it stays "pending" until the first push. A push never overrides `AUTH_DISABLED=true`; it only ever retargets an already-enabled AuthGuard connection. CarrierNode isn't used by any feature here yet, but the client is wired and ready. +`AUTHGUARD_URL` and `CARRIERNODE_URL` are also only the bootstrap fallback: once CollabTable is registered in ProjectConfigurator's Projects workspace, ProjectConfigurator pushes both values here automatically (`PUT /api/core-services/internal`, `X-Internal-Auth`-gated with `SECRET`) and keeps them current with no restart — see `Core/ProjectConfigurator/README.md`'s "Pushing core service info to other projects". This means `AUTHGUARD_URL` no longer needs to be set at all for a registered deployment: it stays "pending" until the first push. A push never overrides `AUTH_DISABLED=true`; it only ever retargets an already-enabled AuthGuard connection. CarrierNode isn't used by any feature here yet, but the client is wired and ready. The device-sync API token (generated from the dashboard's Settings page, used by the Android app's `Authorization: Bearer` header for `/api/lists`, `/api/fields`, `/api/items`, `/api/sync`, and notification polling) is unrelated to AuthGuard and unaffected by whether it's configured: it's a long-lived per-account credential for a user's own devices, not a browser session, and stays entirely local to CollabTable's own Postgres. @@ -49,7 +49,7 @@ The device-sync API token (generated from the dashboard's Settings page, used by | `AUTHGUARD_URL` | No | unset (pending) | Optional bootstrap/override base URL of the AuthGuard identity service. Leaving it unset does not disable authentication — it leaves the service "pending" until ProjectConfigurator pushes a URL, failing closed on auth calls until then. Use `AUTH_DISABLED` to actually turn auth off. | | `AUTH_DISABLED` | No | `false` | Set `true` to disable authentication entirely (no login screen, nothing gated, every request treated as authenticated) — for local development or a standalone deployment with no AuthGuard integration at all. | | `CARRIERNODE_URL` | No | unset | Base URL of a CarrierNode instance. Bootstrap fallback only — see below; not used by any feature here yet. | -| `INTERNAL_SERVICE_SECRET` | No | unset (push endpoint refuses every caller) | Shared secret, the same value CarrierNode/ProjectConfigurator were configured with, checked against `X-Internal-Auth` on `PUT /api/core-services/internal`. | +| `SECRET` | No | unset (push endpoint refuses every caller) | Shared secret, the same value CarrierNode/ProjectConfigurator were configured with, checked against `X-Internal-Auth` on `PUT /api/core-services/internal`. | | `PORT` | No | `8080` | HTTP listen port | | `APP_VERSION` | No | `dev` | Version label shown on the dashboard's About page | | `COOKIE_SECURE` | No | `false` | Set `true` once served over HTTPS, to mark cookies `Secure` | diff --git a/backend/.env.example b/backend/.env.example index 463c3d9..11557b5 100644 --- a/backend/.env.example +++ b/backend/.env.example @@ -38,9 +38,8 @@ COOKIE_SECURE=false # see Core/ProjectConfigurator/README.md's "Pushing core service info to # other projects". That push is itself authenticated with this secret, so it # still needs to be set even though AUTHGUARD_URL/CARRIERNODE_URL don't. A -# push never overrides AUTH_DISABLED=true; it only ever retargets an -# already-enabled AuthGuard connection. -# INTERNAL_SERVICE_SECRET= +# push never overrides AUTH_DISABLED=true; it only ever retargets an +# already-enabled AuthGuard connection. ################################################################# # PostgreSQL configuration @@ -63,4 +62,9 @@ DB_INIT_RETRY_MAX_ATTEMPTS=0 SYNC_MAX_FUTURE_SKEW_MS=0 # Notification retention period in milliseconds (default: 7 days) -NOTIF_RETENTION_MS=604800000 +NOTIF_RETENTION_MS=604800000 + +# Required shared-service authentication secret. +SECRET=change-me-to-a-long-random-value +# Set true only for local development or a standalone deployment. +AUTH_DISABLED=false diff --git a/backend/server.go b/backend/server.go index cd2d485..07b0ff0 100644 --- a/backend/server.go +++ b/backend/server.go @@ -44,6 +44,11 @@ func main() { fmt.Fprintln(os.Stderr, "DATABASE_URL environment variable is required") os.Exit(1) } + internalServiceSecret := strings.TrimSpace(os.Getenv("SECRET")) + if internalServiceSecret == "" { + fmt.Fprintln(os.Stderr, "SECRET environment variable is required") + os.Exit(1) + } ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -84,7 +89,6 @@ func main() { // auth.SetAuthGuardBaseURL retargets the live AuthGuard client sharedauth.Service holds // internally on every push, so AuthGuard moving to a new URL takes effect without a restart -- it // is a no-op when this service was constructed in auth-disabled mode (AUTH_DISABLED=true above). - internalServiceSecret := strings.TrimSpace(os.Getenv("INTERNAL_SERVICE_SECRET")) carrierNodeURL := strings.TrimSpace(os.Getenv("CARRIERNODE_URL")) coreConfig := coreconfig.NewStore(coreconfig.Info{AuthGuardURL: authGuardURL, CarrierNodeURL: carrierNodeURL}) coreConfig.OnUpdate(func(info coreconfig.Info) { diff --git a/frontend/src/lib/features/layout/SettingsDialog.svelte b/frontend/src/lib/features/layout/SettingsDialog.svelte index 8464a3e..228bf73 100644 --- a/frontend/src/lib/features/layout/SettingsDialog.svelte +++ b/frontend/src/lib/features/layout/SettingsDialog.svelte @@ -1,7 +1,7 @@
diff --git a/shared/packages/web-ui/src/lib/components/PrimaryColorPicker.svelte b/shared/packages/web-ui/src/lib/components/PrimaryColorPicker.svelte new file mode 100644 index 0000000..a90e49b --- /dev/null +++ b/shared/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/shared/packages/web-ui/src/lib/index.ts b/shared/packages/web-ui/src/lib/index.ts index ab33761..a571e34 100644 --- a/shared/packages/web-ui/src/lib/index.ts +++ b/shared/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/shared/packages/web-ui/src/lib/primary-color.svelte.ts b/shared/packages/web-ui/src/lib/primary-color.svelte.ts new file mode 100644 index 0000000..fd515a9 --- /dev/null +++ b/shared/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] +}