From 439bd9e0272c10cb27bf269ae5b29e75130f067e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Thu, 14 May 2026 16:38:35 +0200 Subject: [PATCH 1/2] Fill in default config values when key is missing from database Previously we'd just use an empty object, but this might not be a valid value if the schema specifies required properties. If those required properties have defaults, we can fill them in like this. Also verify that an empty object is valid for every registered config schema, so you can't have a schema that would cause errors when the client tries to render it. --- src/plugins/configStore.js | 18 ++++++++++-------- src/schemas/socialAuth.json | 3 ++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/plugins/configStore.js b/src/plugins/configStore.js index d90cc916..16a53cf0 100644 --- a/src/plugins/configStore.js +++ b/src/plugins/configStore.js @@ -131,7 +131,13 @@ class ConfigStore { * @public */ register(key, schema) { - this.#validators.set(key, this.#ajv.compile(schema)); + const validate = this.#ajv.compile(schema); + + if (!validate({})) { + throw new Error(`configStore.register: configuration schema ${key} must support a default object`); + } + + this.#validators.set(key, validate); } /** @@ -203,13 +209,9 @@ class ConfigStore { const configs = Object.create(null); for (const [key, validate] of this.#validators.entries()) { const row = results.find((m) => m.name === key); - if (row) { - const value = JSON.parse(/** @type {string} */ (row.value)); - validate(value); - configs[key] = value; - } else { - configs[key] = {}; - } + configs[key] = row ? JSON.parse(/** @type {string} */ (row.value)) : {}; + // Let the validator fill in defaults + validate(configs[key]); } return configs; } diff --git a/src/schemas/socialAuth.json b/src/schemas/socialAuth.json index 85c24a9f..1684f6bf 100644 --- a/src/schemas/socialAuth.json +++ b/src/schemas/socialAuth.json @@ -58,5 +58,6 @@ "default": {} } }, - "required": ["google"] + "required": ["google"], + "default": {} } From 2a1384b42421628d441582cc0391d55c3950f35f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Thu, 14 May 2026 16:42:22 +0200 Subject: [PATCH 2/2] Add metadata for MOTD config schema --- src/plugins/motd.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/plugins/motd.js b/src/plugins/motd.js index 98eb5eb5..21259c50 100644 --- a/src/plugins/motd.js +++ b/src/plugins/motd.js @@ -12,9 +12,15 @@ class MOTD { this.#uw = uw; uw.config.register(CONFIG_MOTD, { + title: 'Message of the day', + description: 'Display a welcome message at the top of the chat when a user joins.', type: 'object', properties: { - text: { type: 'string', nullable: true }, + text: { + title: 'Message', + type: 'string', + nullable: true, + }, }, }); }