Skip to content

An open-source, self-hosted system for apps built with web technologies.

Validate and persist complete Appearance palette

zohayrslilehf96acf88f43e
diff --git a/scripts/contracts/appearance.ts b/scripts/contracts/appearance.ts
index ccdc83d..7265a5d 100644
--- a/scripts/contracts/appearance.ts
+++ b/scripts/contracts/appearance.ts
@@ -10,6 +10,7 @@ import { join } from "node:path"
assert.deepEqual(appearanceSchema.parse(standardAppearance), standardAppearance)
assert.throws(() => appearanceSchema.parse({}))
+assert.throws(() => appearanceSchema.parse({ ...standardAppearance, accent: standardAppearance.primary }))
assert.throws(() => appearanceSchema.parse({ ...standardAppearance, spacing: { light: 12, dark: 12 } }))
assert.throws(() => appearanceSchema.parse({
...standardAppearance,
@@ -26,6 +27,25 @@ const manager = await AppearanceManager.open(store, new UploadManager(new FileMa
assert.deepEqual(manager.value, standardAppearance)
assert(Object.isFrozen(manager.value))
+for (const role of ["background", "foreground", "primary", "secondary", "success", "warning", "danger", "info"] as const) {
+ assert.deepEqual(await store.get(`appearance:${role}`), standardAppearance[role])
+ const color = { light: "oklch(60% 0.2 260)", dark: "var(--custom-color)" }
+ await manager.update({ ...manager.value, [role]: color })
+ assert.deepEqual(manager.value[role], color)
+ assert.deepEqual(await store.get(`appearance:${role}`), color)
+ assert(Object.isFrozen(manager.value[role]))
+
+ const current = manager.value
+ for (const invalid of [undefined, { light: "red" }, { light: "red", dark: "" }]) {
+ await assert.rejects(manager.update({ ...current, [role]: invalid }))
+ assert.equal(manager.value, current)
+ assert.deepEqual(await store.get(`appearance:${role}`), color)
+ }
+}
+
+const reopened = await AppearanceManager.open(store, new UploadManager(new FileManager(directory)))
+assert.deepEqual(reopened.value, manager.value)
+
const updated = {
...standardAppearance,
background: { light: "white", dark: "black" }
diff --git a/source/server/core/appearance-manager.ts b/source/server/core/appearance-manager.ts
index 37a2c61..212f1ba 100644
--- a/source/server/core/appearance-manager.ts
+++ b/source/server/core/appearance-manager.ts
@@ -30,7 +30,12 @@ const surfaceSchema = z.strictObject({
export const appearanceSchema: z.ZodType<Appearance> = z.strictObject({
background: themed(z.string().min(1)),
foreground: themed(z.string().min(1)),
- accent: themed(z.string().min(1)),
+ primary: themed(z.string().min(1)),
+ secondary: themed(z.string().min(1)),
+ success: themed(z.string().min(1)),
+ warning: themed(z.string().min(1)),
+ danger: themed(z.string().min(1)),
+ info: themed(z.string().min(1)),
spacing: shared(bounded(appearanceLimits.spacing)),
radius: shared(bounded(appearanceLimits.radius)),
surface: themed(surfaceSchema),