feat(appearance): add per-user appearance config contract

Shared AppearanceConfig (color scheme, accent, transparency, per-tier type scale, density, reduce-motion and per-device dashboard widgets) stored as one JSON blob under the existing settings key. normalizeAppearance never throws, so a malformed/partial/future blob degrades to the neutral default and can never reach the DOM. No DB migration; the default reproduces today's look exactly.
This commit is contained in:
Maurice
2026-06-29 10:59:25 +02:00
committed by Maurice
parent d6bba454e0
commit 4742915389
6 changed files with 250 additions and 0 deletions
+5
View File
@@ -1,5 +1,6 @@
import { db } from '../db/database';
import { decrypt_api_key, maybe_encrypt_api_key } from './apiKeyCrypto';
import { normalizeAppearance } from '@trek/shared';
const ENCRYPTED_SETTING_KEYS = new Set(['webhook_url', 'ntfy_token', 'mapbox_access_token', 'llm_api_key']);
// Encrypted keys that are masked (••••••••) when returned to the client.
@@ -136,6 +137,10 @@ export function getUserSettings(userId: number): Record<string, unknown> {
}
function serializeValue(key: string, value: unknown): string {
// The appearance blob drives the DOM on the client — normalize it on the way
// in so a malformed/partial/future-versioned payload can never be stored (and
// thus never reach the writer). Unknown/invalid fields collapse to the default.
if (key === 'appearance') value = normalizeAppearance(value);
const raw = typeof value === 'object' ? JSON.stringify(value) : String(value !== undefined ? value : '');
if (ENCRYPTED_SETTING_KEYS.has(key)) return maybe_encrypt_api_key(raw) ?? raw;
return raw;