domma-cms 1.80.0 → 1.82.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/admin/css/site-settings.css +1 -1
  3. package/admin/js/lib/site-settings-arrange.js +3 -3
  4. package/admin/js/templates/docs/usage-site-settings.html +47 -3
  5. package/admin/js/templates/settings.html +98 -8
  6. package/admin/js/views/settings.js +3 -3
  7. package/docs/DommaFeatures.md +51 -2
  8. package/docs/plans/2026-11-19-brand-kit-design.md +1 -1
  9. package/docs/plugin-development.md +6 -0
  10. package/package.json +1 -1
  11. package/plugins/_lib/telegram/bot.js +120 -0
  12. package/plugins/free-tier.lock.json +34 -9
  13. package/plugins/telegram/CHANGELOG.md +5 -0
  14. package/plugins/telegram/CLAUDE.md +77 -0
  15. package/plugins/telegram/admin/css/index.css +68 -0
  16. package/plugins/telegram/admin/lib/arrange.js +103 -0
  17. package/plugins/telegram/admin/lib/kit.js +153 -0
  18. package/plugins/telegram/admin/templates/telegram.html +1 -0
  19. package/plugins/telegram/admin/views/chats.js +223 -0
  20. package/plugins/telegram/admin/views/connection.js +90 -0
  21. package/plugins/telegram/admin/views/telegram.js +89 -0
  22. package/plugins/telegram/admin/views/test.js +84 -0
  23. package/plugins/telegram/config.js +21 -0
  24. package/plugins/telegram/docs/guide.md +87 -0
  25. package/plugins/telegram/lib/messages.js +176 -0
  26. package/plugins/telegram/lib/queue.js +72 -0
  27. package/plugins/telegram/plugin.js +490 -0
  28. package/plugins/telegram/plugin.json +71 -0
  29. package/plugins/telegram/tests/api.test.js +381 -0
  30. package/plugins/telegram/tests/arrange.test.js +41 -0
  31. package/plugins/telegram/tests/messages.test.js +110 -0
  32. package/plugins/telegram/tests/queue.test.js +47 -0
  33. package/plugins/theme-roller/CLAUDE.md +9 -0
  34. package/plugins/theme-roller/admin/lib/themes.js +49 -0
  35. package/plugins/theme-roller/admin/templates/theme-roller.html +2 -0
  36. package/plugins/theme-roller/admin/views/theme-roller-view.js +25 -2
  37. package/plugins/theme-roller/docs/guide.md +1 -0
  38. package/plugins/theme-roller/plugin.json +1 -1
  39. package/plugins/theme-roller/tests/themes.test.js +20 -0
  40. package/public/js/site.js +1 -1
  41. package/server/routes/api/brand-kit.js +55 -0
  42. package/server/routes/api/settings.js +17 -1
  43. package/server/routes/favicon.js +10 -6
  44. package/server/server.js +2 -0
  45. package/server/services/adminBrand.js +8 -3
  46. package/server/services/brandKit.js +330 -0
  47. package/server/services/chat/launcher-bridge.js +2 -1
  48. package/server/services/emailBrand.js +31 -13
  49. package/server/services/launchers.js +5 -1
  50. package/server/services/notify.js +20 -2
  51. package/server/services/plugins.js +3 -0
  52. package/server/services/renderer.js +7 -5
  53. package/server/templates/page.html +1 -1
@@ -0,0 +1,330 @@
1
+ /**
2
+ * The Brand Kit - one site-wide brand (Site Settings > Branding > Brand Kit, `site.json` `brandKit`).
3
+ *
4
+ * Everything that presents the site - automated emails first (services/emailBrand.js), then
5
+ * plugins through `hooks.brandKit()` and the public `GET /api/brand-kit` - reads the brand from
6
+ * here instead of keeping its own copy. Nothing is migrated: an empty Kit field falls back to
7
+ * what the site already had (`brand`, `title`, `logo`, `contactEmail`, the footer's email and
8
+ * address, `baseUrl`), so a site looks the same until its owner fills the Kit in.
9
+ *
10
+ * The Kit never changes the theme (Darryl, 2026-11-19): its colours are the brand's, not tokens.
11
+ *
12
+ * Website and sign-in defaults (phase 3): once a site has SAVED its Kit (`savedBrand()`), the Kit
13
+ * fills what the site's own settings leave empty - the favicon (routes/favicon.js), a completely
14
+ * blank navbar brand (`navBrand()`, renderer.js), the admin name and logos (adminBrand.js), a chat
15
+ * launcher's accent and avatar (`chatBrandDefaults()`) and og:site_name. A site that never saved a
16
+ * Kit renders exactly as before.
17
+ * Plan: docs/plans/2026-11-19-brand-kit-design.md.
18
+ *
19
+ * @module services/brandKit
20
+ */
21
+ import fs from 'node:fs';
22
+ import path from 'node:path';
23
+ import {config} from '../config.js';
24
+
25
+ /** Fonts the Kit offers: safe fonts everywhere, Google fonts with a safe fallback. */
26
+ export const KIT_FONTS = {
27
+ '': {label: 'Site default', stack: 'Arial, Helvetica, sans-serif'},
28
+ arial: {label: 'Arial', stack: 'Arial, Helvetica, sans-serif'},
29
+ helvetica: {label: 'Helvetica', stack: 'Helvetica, Arial, sans-serif'},
30
+ verdana: {label: 'Verdana', stack: 'Verdana, Geneva, sans-serif'},
31
+ tahoma: {label: 'Tahoma', stack: 'Tahoma, Verdana, sans-serif'},
32
+ trebuchet: {label: 'Trebuchet MS', stack: '"Trebuchet MS", Helvetica, sans-serif'},
33
+ georgia: {label: 'Georgia', stack: 'Georgia, "Times New Roman", serif'},
34
+ times: {label: 'Times New Roman', stack: '"Times New Roman", Times, serif'},
35
+ inter: {label: 'Inter', stack: 'Inter, Arial, sans-serif', google: 'Inter'},
36
+ roboto: {label: 'Roboto', stack: 'Roboto, Arial, sans-serif', google: 'Roboto'},
37
+ 'open-sans': {label: 'Open Sans', stack: '"Open Sans", Arial, sans-serif', google: 'Open Sans'},
38
+ lato: {label: 'Lato', stack: 'Lato, Arial, sans-serif', google: 'Lato'},
39
+ montserrat: {label: 'Montserrat', stack: 'Montserrat, Arial, sans-serif', google: 'Montserrat'},
40
+ poppins: {label: 'Poppins', stack: 'Poppins, Arial, sans-serif', google: 'Poppins'},
41
+ nunito: {label: 'Nunito', stack: 'Nunito, Arial, sans-serif', google: 'Nunito'},
42
+ merriweather: {label: 'Merriweather', stack: 'Merriweather, Georgia, serif', google: 'Merriweather'},
43
+ 'playfair-display': {label: 'Playfair Display', stack: '"Playfair Display", Georgia, serif', google: 'Playfair Display'},
44
+ 'source-serif': {label: 'Source Serif 4', stack: '"Source Serif 4", Georgia, serif', google: 'Source Serif 4'}
45
+ };
46
+
47
+ export const MAX_KIT_COLOURS = 4;
48
+
49
+ const TEXT_LIMITS = {name: 120, legalName: 160, shortName: 40, footerLine: 300, smallPrint: 1200,
50
+ email: 160, phone: 40, address: 400, website: 300, companyNumber: 40, vatNumber: 40};
51
+
52
+ const clean = (value, max) => typeof value === 'string'
53
+ ? value.replace(/\r\n?/g, '\n').replace(/[\u0000-\u0009\u000b-\u001f\u007f]/g, ' ').trim().slice(0, max) : '';
54
+ const oneLine = (value, max) => clean(value, max).replace(/\n+/g, ' ');
55
+ const HEX = /^#[\da-f]{6}$/i;
56
+ const EMAIL = /^[^\s@<>"]+@[^\s@<>"]+\.[^\s@<>"]+$/;
57
+
58
+ /** A path on the site (`/media/...`, no climbing out) or an https address, else ''. */
59
+ export function kitImage(value) {
60
+ const v = oneLine(value, 2000);
61
+ if (!v) return '';
62
+ if (v.startsWith('/') && !v.startsWith('//')) {
63
+ let decoded;
64
+ try { decoded = decodeURIComponent(v); } catch { return ''; }
65
+ return /(^|\/)\.\.(\/|$)|\\|[?#]/.test(decoded) ? '' : v;
66
+ }
67
+ try {
68
+ const url = new URL(v);
69
+ return url.protocol === 'https:' && !url.username && !url.password ? url.href : '';
70
+ } catch { return ''; }
71
+ }
72
+
73
+ function kitWebsite(value) {
74
+ const v = oneLine(value, TEXT_LIMITS.website);
75
+ if (!v) return '';
76
+ try {
77
+ const url = new URL(/^https?:\/\//i.test(v) ? v : `https://${v}`);
78
+ return ['http:', 'https:'].includes(url.protocol) && !url.username && !url.password ? url.href.replace(/\/$/, '') : '';
79
+ } catch { return ''; }
80
+ }
81
+
82
+ /**
83
+ * The Kit as stored: every field cleaned, unknown fields dropped. Throws a plain-English
84
+ * Error for what the owner must fix (a colour or an email address that is not one).
85
+ *
86
+ * @param {object} value
87
+ * @param {{now?: () => string}} [opts]
88
+ */
89
+ export function normaliseBrandKit(value, {now = () => new Date().toISOString()} = {}) {
90
+ if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error('Brand Kit: send an object.');
91
+ const accent = oneLine(value.accent, 7);
92
+ if (accent && !HEX.test(accent)) throw new Error('Brand Kit: the accent colour must be a six-digit colour, such as #2563eb.');
93
+ const colours = (Array.isArray(value.colours) ? value.colours : []).slice(0, 20)
94
+ .map(c => ({name: oneLine(c?.name, 40), hex: oneLine(c?.hex, 7)}))
95
+ .filter(c => c.name || c.hex).slice(0, MAX_KIT_COLOURS);
96
+ for (const c of colours) {
97
+ if (!HEX.test(c.hex)) throw new Error(`Brand Kit: "${c.name || 'a colour'}" needs a six-digit colour, such as #0f766e.`);
98
+ }
99
+ const fonts = {};
100
+ for (const key of ['heading', 'body']) {
101
+ const id = oneLine(value.fonts?.[key], 40);
102
+ fonts[key] = Object.hasOwn(KIT_FONTS, id) ? id : '';
103
+ }
104
+ const c = value.contact && typeof value.contact === 'object' ? value.contact : {};
105
+ const email = oneLine(c.email, TEXT_LIMITS.email);
106
+ if (email && !EMAIL.test(email)) throw new Error('Brand Kit: the contact email is not an email address.');
107
+ const website = oneLine(c.website, TEXT_LIMITS.website);
108
+ if (website && (!kitWebsite(website) || !new URL(kitWebsite(website)).hostname.includes('.'))) throw new Error('Brand Kit: the website must be an address such as https://example.com.');
109
+ return {
110
+ name: oneLine(value.name, TEXT_LIMITS.name),
111
+ legalName: oneLine(value.legalName, TEXT_LIMITS.legalName),
112
+ shortName: oneLine(value.shortName, TEXT_LIMITS.shortName),
113
+ logo: kitImage(value.logo),
114
+ logoDark: kitImage(value.logoDark),
115
+ mark: kitImage(value.mark),
116
+ accent: accent.toLowerCase(),
117
+ colours: colours.map(x => ({name: x.name, hex: x.hex.toLowerCase()})),
118
+ fonts,
119
+ contact: {
120
+ email, website: kitWebsite(website),
121
+ phone: oneLine(c.phone, TEXT_LIMITS.phone),
122
+ address: clean(c.address, TEXT_LIMITS.address),
123
+ companyNumber: oneLine(c.companyNumber, TEXT_LIMITS.companyNumber),
124
+ vatNumber: oneLine(c.vatNumber, TEXT_LIMITS.vatNumber)
125
+ },
126
+ footerLine: oneLine(value.footerLine, TEXT_LIMITS.footerLine),
127
+ smallPrint: clean(value.smallPrint, TEXT_LIMITS.smallPrint),
128
+ updatedAt: now()
129
+ };
130
+ }
131
+
132
+ /**
133
+ * A logo the site already had (`brand.logo`, `logo`), as loosely as emails read it before the Kit:
134
+ * a path on the site or an http(s) address, query strings allowed. Never `//` or other schemes.
135
+ */
136
+ function legacyImage(value) {
137
+ const v = oneLine(value, 2000);
138
+ if (!v) return '';
139
+ if (v.startsWith('/') && !v.startsWith('//')) return /\\/.test(v) ? '' : v;
140
+ try {
141
+ const url = new URL(v);
142
+ return ['http:', 'https:'].includes(url.protocol) && !url.username && !url.password ? url.href : '';
143
+ } catch { return ''; }
144
+ }
145
+
146
+ /** The site's address (`baseUrl`, else `url`) as an origin, or ''. */
147
+ export function siteOriginOf(site = {}) {
148
+ for (const v of [site.baseUrl, site.url]) {
149
+ try {
150
+ const url = new URL(String(v ?? ''));
151
+ if (['http:', 'https:'].includes(url.protocol)) return url.origin;
152
+ } catch { /* not set */ }
153
+ }
154
+ return '';
155
+ }
156
+
157
+ /** A Kit image made absolute against the site's address; '' when it cannot be. */
158
+ export function absoluteImage(value, origin) {
159
+ const v = kitImage(value) || legacyImage(value);
160
+ if (!v) return '';
161
+ if (/^https?:\/\//i.test(v)) return v;
162
+ try { return origin ? new URL(v, origin).href : ''; } catch { return ''; }
163
+ }
164
+
165
+ const isSvg = (v) => /\.svg(?:[?#]|$)/i.test(String(v || ''));
166
+
167
+ /**
168
+ * The site's brand, resolved: the Kit, with what the site already had for every empty field.
169
+ * Images stay as stored (Media paths); callers that need absolute addresses use absoluteImage().
170
+ *
171
+ * @param {object} site - config/site.json
172
+ */
173
+ export function siteBrand(site = {}) {
174
+ const raw = site.brandKit && typeof site.brandKit === 'object' ? site.brandKit : {};
175
+ let kit;
176
+ try { kit = normaliseBrandKit(raw, {now: () => raw.updatedAt || ''}); }
177
+ catch { kit = normaliseBrandKit({}, {now: () => ''}); }
178
+ const footer = site.footer || {};
179
+ const contactEmail = [kit.contact.email, site.contactEmail, footer.email].map(v => oneLine(v, 160)).find(v => EMAIL.test(v)) || '';
180
+ // '' when the site has no name at all: each reader picks its own last resort (emails: the SMTP From name).
181
+ const name = kit.name || oneLine(site.brand?.text, 120) || oneLine(site.title, 120);
182
+ const social = Object.fromEntries(Object.entries(site.social || {})
183
+ .filter(([, v]) => typeof v === 'string' && /^https?:\/\//i.test(v.trim())).map(([k, v]) => [k, v.trim()]));
184
+ return {
185
+ name,
186
+ legalName: kit.legalName,
187
+ shortName: kit.shortName || name,
188
+ logo: kit.logo || legacyImage(site.brand?.logo) || legacyImage(site.logo),
189
+ logoDark: kit.logoDark,
190
+ mark: kit.mark,
191
+ accent: kit.accent,
192
+ colours: kit.colours,
193
+ fonts: {heading: kit.fonts.heading, body: kit.fonts.body},
194
+ contact: {
195
+ ...kit.contact, email: contactEmail,
196
+ address: kit.contact.address || clean(footer.address, 400),
197
+ website: kit.contact.website || siteOriginOf(site)
198
+ },
199
+ social,
200
+ footerLine: kit.footerLine,
201
+ smallPrint: kit.smallPrint,
202
+ updatedAt: kit.updatedAt
203
+ };
204
+ }
205
+
206
+ /** "Acme Ltd · Company number 01234567 · VAT GB123456789 · 1 Mill Lane, Leeds" - '' when none. */
207
+ export function legalLine(brand) {
208
+ const parts = [brand.legalName,
209
+ brand.contact?.companyNumber ? `Company number ${brand.contact.companyNumber}` : '',
210
+ brand.contact?.vatNumber ? `VAT ${brand.contact.vatNumber}` : '',
211
+ String(brand.contact?.address || '').replace(/\s*\n\s*/g, ', ')].filter(Boolean);
212
+ return parts.length > 1 || brand.legalName ? parts.join(' · ') : '';
213
+ }
214
+
215
+ /** The media file behind a `/media/...` address, or null (outside Media, or not one). */
216
+ export function mediaFile(src, mediaDir = config.content?.mediaDir) {
217
+ if (typeof src !== 'string' || !src.startsWith('/media/') || !mediaDir) return null;
218
+ let rel;
219
+ try { rel = decodeURIComponent(src.slice(7).split(/[?#]/)[0]); } catch { return null; }
220
+ if (!rel || rel.includes('\0') || rel.includes('\\')) return null;
221
+ const root = path.resolve(mediaDir);
222
+ const file = path.resolve(root, rel);
223
+ return file.startsWith(root + path.sep) ? file : null;
224
+ }
225
+
226
+ export const MAX_SVG_BYTES = 1024 * 1024;
227
+
228
+ /**
229
+ * The logo an email can show: a raster logo as it is; an SVG one through the PNG copy
230
+ * (`GET /api/brand-kit/logo.png`), since many mail programs show no SVG - only when that copy
231
+ * can be made (the file is in Media and not too big), else '' and the email shows the name.
232
+ * The copy's address carries the file's time, so a replaced logo is fetched afresh.
233
+ */
234
+ export function emailLogo(brand, origin, {mediaDir} = {}) {
235
+ if (!brand.logo) return '';
236
+ if (!isSvg(brand.logo)) return absoluteImage(brand.logo, origin);
237
+ if (!origin) return '';
238
+ const file = mediaFile(brand.logo, mediaDir);
239
+ if (!file) return '';
240
+ let stat;
241
+ try { stat = fs.statSync(file); } catch { return ''; }
242
+ if (!stat.isFile() || stat.size > MAX_SVG_BYTES) return '';
243
+ return `${origin}/api/brand-kit/logo.png?v=${Math.round(stat.mtimeMs)}-${stat.size}`;
244
+ }
245
+
246
+ /** A font id -> {stack, google?}. */
247
+ export function kitFont(id) {
248
+ return KIT_FONTS[id] || KIT_FONTS[''];
249
+ }
250
+
251
+ /**
252
+ * The Kit's OWN fields, to use as DEFAULTS for the site's other settings: the cleaned Kit once it
253
+ * has been saved, else null - so a site that never saved one looks exactly as it did. Unlike
254
+ * siteBrand() nothing here falls back to the site's other settings (they are what it fills in for).
255
+ *
256
+ * @returns {{name, legalName, shortName, logo, logoDark, mark, accent, colours, fonts, contact, ...}|null}
257
+ */
258
+ export function savedBrand(site = {}) {
259
+ const raw = site?.brandKit && typeof site.brandKit === 'object' ? site.brandKit : null;
260
+ if (!raw?.updatedAt) return null;
261
+ try { return normaliseBrandKit(raw, {now: () => raw.updatedAt}); } catch { return null; }
262
+ }
263
+
264
+ /** Black or white, whichever reads on a colour. */
265
+ export function inkOn(hex) {
266
+ if (!HEX.test(String(hex || ''))) return '#ffffff';
267
+ const [r, g, b] = [1, 3, 5].map(i => parseInt(hex.slice(i, i + 2), 16) / 255)
268
+ .map(c => (c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4));
269
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b > 0.4 ? '#111111' : '#ffffff';
270
+ }
271
+
272
+ /**
273
+ * The public navbar's brand (`site.brand`): the site's own, untouched, unless it is completely
274
+ * blank (no text, logo or icon) - then the saved Kit's logo (a full logo carries the name, so it
275
+ * stands alone; its name is the image's alt text), else its name.
276
+ */
277
+ export function navBrand(site = {}) {
278
+ const own = site.brand && typeof site.brand === 'object' && !Array.isArray(site.brand) ? site.brand : {};
279
+ if (own.text || own.logo || own.icon) return own;
280
+ const b = savedBrand(site);
281
+ if (!b) return own;
282
+ if (b.logo) return {...own, logo: b.logo, ...(b.name ? {alt: b.name} : {})};
283
+ return b.name ? {...own, text: b.name} : own;
284
+ }
285
+
286
+ /**
287
+ * A chat launcher's look (normaliseLauncherChat + characterChat), with the saved Kit's accent (and
288
+ * black or white text on it) and square mark as the bot's picture where the launcher sets none.
289
+ * A character keeps its own art, so no mark is put in for one.
290
+ */
291
+ export function chatBrandDefaults(chat, site = {}) {
292
+ if (!chat || typeof chat !== 'object') return chat;
293
+ const b = savedBrand(site);
294
+ if (!b) return chat;
295
+ const out = {...chat};
296
+ if (!out.accent && b.accent) {
297
+ out.accent = b.accent;
298
+ if (!out.accentText) out.accentText = inkOn(b.accent);
299
+ }
300
+ // The launcher's own rule: a picture on this site only.
301
+ if (!out.avatar && !out.character && /^\/[A-Za-z0-9._~\-/%]+$/.test(b.mark || '')) out.avatar = b.mark;
302
+ return out;
303
+ }
304
+
305
+ /** What anyone may read (`GET /api/brand-kit`): the brand as the site presents it, absolute addresses. */
306
+ export function publicBrandKit(site = {}) {
307
+ const b = siteBrand(site);
308
+ const origin = siteOriginOf(site);
309
+ const font = (id) => ({id, label: kitFont(id).label, stack: kitFont(id).stack, google: kitFont(id).google || ''});
310
+ return {
311
+ name: b.name, legalName: b.legalName, shortName: b.shortName,
312
+ logo: absoluteImage(b.logo, origin) || b.logo, logoDark: absoluteImage(b.logoDark, origin) || b.logoDark,
313
+ mark: absoluteImage(b.mark, origin) || b.mark,
314
+ accent: b.accent, colours: b.colours,
315
+ fonts: {heading: font(b.fonts.heading), body: font(b.fonts.body)},
316
+ contact: b.contact, social: b.social,
317
+ footerLine: b.footerLine, smallPrint: b.smallPrint, legalLine: legalLine(b),
318
+ // Whether the owner has saved a Kit (the Theme Roller offers "New theme from Brand Kit" then).
319
+ saved: Boolean(b.updatedAt)
320
+ };
321
+ }
322
+
323
+ /** Admin problems the Kit can have (Site Settings' Needs attention). Plain text. */
324
+ export function brandKitProblems(site = {}) {
325
+ const b = siteBrand(site);
326
+ if (isSvg(b.logo) && !siteOriginOf(site)) {
327
+ return [{tone: 'warn', tab: 'branding', text: 'Your logo is an SVG and there is no Site URL - emails cannot show it and use your name instead. Set the Site URL on the General tab.'}];
328
+ }
329
+ return [];
330
+ }
@@ -14,6 +14,7 @@
14
14
  import {normaliseLauncherChat} from './settings.js';
15
15
  import {getConfig} from '../../config.js';
16
16
  import {characterChat} from '../../../public/js/characters.mjs';
17
+ import {chatBrandDefaults} from '../brandKit.js';
17
18
 
18
19
  let loader = () => import('../launchers.js');
19
20
 
@@ -57,7 +58,7 @@ export async function chatLauncher(id) {
57
58
  if (list === null) return null;
58
59
  const found = list.find(l => l && String(l.id) === id);
59
60
  return found ? {id, place: found.place === 'admin' ? 'admin' : found.place === 'both' ? 'both' : 'site',
60
- chat: characterChat(normaliseLauncherChat(found.chat), getConfig('site').characters)} : null;
61
+ chat: chatBrandDefaults(characterChat(normaliseLauncherChat(found.chat), getConfig('site').characters), getConfig('site'))} : null;
61
62
  }
62
63
 
63
64
  /**
@@ -1,4 +1,5 @@
1
1
  /** Shared, opt-in presentation for automated site emails. No SMTP or runtime writes. */
2
+ import {emailLogo, kitFont, legalLine, siteBrand} from './brandKit.js';
2
3
  const esc = value => String(value ?? '').replace(/[&<>"']/g, c => ({'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;'}[c]));
3
4
  const clean = (value, max = 300) => typeof value === 'string' ? value.replace(/[\u0000-\u001f\u007f]/g, ' ').trim().slice(0, max) : '';
4
5
  const hex = value => /^#[\da-f]{6}$/i.test(value || '');
@@ -12,19 +13,36 @@ export const EMAIL_FAMILIES = {
12
13
  gift: 'A gift for you', offer: 'An offer for you', licence: 'Your licence'
13
14
  };
14
15
 
15
- /** Site identity, with explicit email overrides. Never use the admin identity on customer mail. */
16
+ /**
17
+ * The brand an email shows: the site's Brand Kit (services/brandKit.js, which falls back to the
18
+ * public brand), with Site Settings > SMTP > Email identity (`emailBrand`) as email-only overrides
19
+ * on top. Never the admin identity on customer mail.
20
+ */
16
21
  export function emailBrand(site = {}) {
17
22
  const override = site.emailBrand || {};
23
+ const kit = siteBrand(site);
18
24
  const base = emailUrl(site.baseUrl) || emailUrl(site.url);
19
- const colour = /^#[\da-f]{3}$/i.test(override.accent || '') ? '#' + override.accent.slice(1).split('').map(c => c + c).join('') : override.accent;
20
- const accent = hex(colour) ? colour : '#2563eb';
21
- const support = clean(override.supportEmail || site.contactEmail);
25
+ const own = (v) => /^#[\da-f]{3}$/i.test(v || '') ? '#' + v.slice(1).split('').map(c => c + c).join('') : v;
26
+ const accent = [own(override.accent), kit.accent].find(hex) || '#2563eb';
27
+ const support = clean(override.supportEmail || kit.contact.email);
28
+ const origin = base ? new URL(base).origin : '';
29
+ const logo = override.logo
30
+ ? (/\.svg(?:[?#]|$)/i.test(override.logo) ? '' : emailUrl(override.logo, base))
31
+ : emailLogo(kit, origin);
32
+ const font = kitFont(kit.fonts.body);
22
33
  return {
23
- name: clean(override.name || site.brand?.text || site.title || site.smtp?.fromName || 'Our team', 120),
24
- logo: /\.svg(?:[?#]|$)/i.test(override.logo || site.brand?.logo || site.logo || '') ? '' : emailUrl(override.logo || site.brand?.logo || site.logo, base),
34
+ name: clean(override.name || kit.name || site.smtp?.fromName || 'Our team', 120),
35
+ logo,
25
36
  accent, ink: accentInk(accent), link: accentInk(accent) === '#000000' ? '#0f172a' : accent, base,
26
37
  supportEmail: /^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(support) ? support : '',
27
- footer: clean(override.footer, 600)
38
+ footer: clean(override.footer || kit.footerLine, 600),
39
+ legal: clean(legalLine(kit), 600),
40
+ smallPrint: clean(kit.smallPrint.replace(/\n+/g, ' '), 1200),
41
+ font: font.stack.replace(/[^\w\s,"-]/g, ''),
42
+ headingFont: kitFont(kit.fonts.heading).stack.replace(/[^\w\s,"-]/g, ''),
43
+ fontHref: [font.google, kitFont(kit.fonts.heading).google].filter(Boolean)
44
+ .filter((f, i, a) => a.indexOf(f) === i)
45
+ .map(f => `https://fonts.googleapis.com/css2?family=${encodeURIComponent(f).replace(/%20/g, '+')}:wght@400;700&display=swap`)
28
46
  };
29
47
  }
30
48
 
@@ -86,16 +104,16 @@ export function brandEmail(message, {site = {}, family = 'automation', title, pr
86
104
  const contact = brand.supportEmail ? `<a href="mailto:${esc(brand.supportEmail)}" style="color:#64748b;">${esc(brand.supportEmail)}</a>` : '';
87
105
  const website = brand.base ? `<a href="${esc(brand.base)}" style="color:#64748b;">Visit ${esc(brand.name)}</a>` : '';
88
106
  const logo = brand.logo ? `<img src="${esc(brand.logo)}" alt="${esc(brand.name)}" width="160" style="display:block;max-width:160px;max-height:64px;width:auto;height:auto;border:0;margin-bottom:14px;">` : '';
89
- const html = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="color-scheme" content="light dark"><title>${esc(heading)}</title><style>@media(max-width:600px){.dm-email-pad{padding:24px 20px!important}.dm-email-shell{border-radius:0!important}}@media(prefers-color-scheme:dark){.dm-email-page{background:#111827!important}.dm-email-shell,.dm-email-content{background:#1f2937!important;color:#f1f5f9!important}.dm-email-title,.dm-email-brand div{color:#fff!important}.dm-email-panel{background:#334155!important;color:#f1f5f9!important}.dm-email-panel td{color:inherit!important}.dm-email-preserve{background:#fff!important;color:#334155!important}.dm-email-preserve .dm-email-title{color:#0f172a!important}.dm-email-link{color:#93c5fd!important}.dm-email-footer a{color:#cbd5e1!important}.dm-email-footer{background:#172033!important;color:#cbd5e1!important}}</style></head>
107
+ const html = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="color-scheme" content="light dark"><title>${esc(heading)}</title>${brand.fontHref.map(href => `<link rel="stylesheet" href="${esc(href)}">`).join('')}<style>@media(max-width:600px){.dm-email-pad{padding:24px 20px!important}.dm-email-shell{border-radius:0!important}}@media(prefers-color-scheme:dark){.dm-email-page{background:#111827!important}.dm-email-shell,.dm-email-content{background:#1f2937!important;color:#f1f5f9!important}.dm-email-title,.dm-email-brand div{color:#fff!important}.dm-email-panel{background:#334155!important;color:#f1f5f9!important}.dm-email-panel td{color:inherit!important}.dm-email-preserve{background:#fff!important;color:#334155!important}.dm-email-preserve .dm-email-title{color:#0f172a!important}.dm-email-link{color:#93c5fd!important}.dm-email-footer a{color:#cbd5e1!important}.dm-email-footer{background:#172033!important;color:#cbd5e1!important}}</style></head>
90
108
  <body class="dm-email-page" style="margin:0;padding:0;background:#edf1f6;"><div style="display:none;max-height:0;overflow:hidden;mso-hide:all;">${esc(preheader)}</div>
91
- <table data-domma-email="1" role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" class="dm-email-page" style="background:#edf1f6;font:15px/1.65 Arial,Helvetica,sans-serif;color:#334155;"><tr><td align="center" style="padding:36px 12px;">
109
+ <table data-domma-email="1" role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" class="dm-email-page" style="background:#edf1f6;font:15px/1.65 ${esc(brand.font)};color:#334155;"><tr><td align="center" style="padding:36px 12px;">
92
110
  <table role="presentation" width="600" cellpadding="0" cellspacing="0" border="0" class="dm-email-shell" style="width:100%;max-width:600px;background:#fff;border:1px solid #dce3ed;border-radius:12px;overflow:hidden;">
93
111
  <tr><td bgcolor="${brand.accent}" style="height:6px;font-size:0;line-height:6px;background:${brand.accent};">&nbsp;</td></tr>
94
- <tr><td class="dm-email-pad dm-email-brand" style="padding:28px 36px 20px;">${logo}<div style="font-size:18px;font-weight:700;color:#0f172a;">${esc(brand.name)}</div><div style="margin-top:4px;font-size:11px;font-weight:700;letter-spacing:1.4px;text-transform:uppercase;color:#64748b;">${esc(label)}</div></td></tr>
95
- <tr><td class="dm-email-pad dm-email-content${blocks ? '' : ' dm-email-preserve'}" style="padding:8px 36px 32px;background:#fff;color:#334155;"><h1 class="dm-email-title" style="font:700 26px/1.25 Arial,Helvetica,sans-serif;color:#0f172a;margin:0 0 24px;">${esc(heading)}</h1><!--dm-email-body-->${content.html}<!--/dm-email-body--></td></tr>
96
- <tr><td class="dm-email-pad dm-email-footer" style="padding:22px 36px;background:#f8fafc;border-top:1px solid #e2e8f0;font:12px/1.6 Arial,Helvetica,sans-serif;color:#64748b;"><strong>${esc(brand.name)}</strong>${brand.footer ? `<p style="margin:8px 0;">${esc(brand.footer)}</p>` : ''}<p style="margin:8px 0 0;">${[website, contact].filter(Boolean).join(' &nbsp;·&nbsp; ')}</p></td></tr>
112
+ <tr><td class="dm-email-pad dm-email-brand" style="padding:28px 36px 20px;">${logo}<div style="font:700 18px/1.3 ${esc(brand.headingFont)};color:#0f172a;">${esc(brand.name)}</div><div style="margin-top:4px;font-size:11px;font-weight:700;letter-spacing:1.4px;text-transform:uppercase;color:#64748b;">${esc(label)}</div></td></tr>
113
+ <tr><td class="dm-email-pad dm-email-content${blocks ? '' : ' dm-email-preserve'}" style="padding:8px 36px 32px;background:#fff;color:#334155;"><h1 class="dm-email-title" style="font:700 26px/1.25 ${esc(brand.headingFont)};color:#0f172a;margin:0 0 24px;">${esc(heading)}</h1><!--dm-email-body-->${content.html}<!--/dm-email-body--></td></tr>
114
+ <tr><td class="dm-email-pad dm-email-footer" style="padding:22px 36px;background:#f8fafc;border-top:1px solid #e2e8f0;font:12px/1.6 ${esc(brand.font)};color:#64748b;"><strong>${esc(brand.name)}</strong>${brand.footer ? `<p style="margin:8px 0;">${esc(brand.footer)}</p>` : ''}<p style="margin:8px 0 0;">${[website, contact].filter(Boolean).join(' &nbsp;·&nbsp; ')}</p>${brand.legal ? `<p style="margin:10px 0 0;font-size:11px;">${esc(brand.legal)}</p>` : ''}${brand.smallPrint ? `<p style="margin:6px 0 0;font-size:11px;">${esc(brand.smallPrint)}</p>` : ''}</td></tr>
97
115
  </table></td></tr></table></body></html>`;
98
- const text = [brand.name, label, heading, content.text, brand.footer, brand.base, brand.supportEmail].filter(Boolean).join('\n\n');
116
+ const text = [brand.name, label, heading, content.text, brand.footer, brand.base, brand.supportEmail, brand.legal, brand.smallPrint].filter(Boolean).join('\n\n');
99
117
  return {...message, html, text};
100
118
  }
101
119
 
@@ -16,6 +16,7 @@
16
16
  */
17
17
  import {getConfig, saveConfig} from '../config.js';
18
18
  import {characterChat} from '../../public/js/characters.mjs';
19
+ import {chatBrandDefaults} from './brandKit.js';
19
20
  import * as cache from './cache/index.js';
20
21
  import {isToolEnabled} from './tools.js';
21
22
  import {
@@ -105,7 +106,10 @@ export function launchersForPage(urlPath, user) {
105
106
  /** A launcher as the browser gets it, the chat with its character applied. */
106
107
  function pageLauncher(l) {
107
108
  const out = publicLauncher(l);
108
- if (out.chat) out.chat = characterChat(out.chat, getConfig('site').characters);
109
+ if (out.chat) {
110
+ const site = getConfig('site');
111
+ out.chat = chatBrandDefaults(characterChat(out.chat, site.characters), site);
112
+ }
109
113
  return out;
110
114
  }
111
115
 
@@ -29,6 +29,7 @@ import {randomUUID} from 'crypto';
29
29
  import {config, getConfig, saveConfig} from '../config.js';
30
30
  import {getAdapter} from './adapterRegistry.js';
31
31
  import {getEffectiveRoles} from './userRoles.js';
32
+ import {hooks} from './hooks.js';
32
33
 
33
34
  const SLUG = 'notifications';
34
35
  export const SEVERITIES = ['info', 'success', 'warning', 'critical'];
@@ -258,7 +259,10 @@ async function write(p) {
258
259
  const worse = RANK[data.severity] > RANK[existing.data.severity];
259
260
  const merged = {...existing.data, ...data, createdAt: worse ? now : existing.data.createdAt,
260
261
  readBy: worse ? [] : existing.data.readBy || [], dismissedBy: worse ? [] : existing.data.dismissedBy || []};
261
- return adapter.update(SLUG, existing.id, {...existing, data: merged, meta: {...(existing.meta || {}), updatedAt: now}});
262
+ const updated = await adapter.update(SLUG, existing.id, {...existing, data: merged, meta: {...(existing.meta || {}), updatedAt: now}});
263
+ // The same thing still going on is not news; the same thing grown worse is.
264
+ if (worse) raised(updated);
265
+ return updated;
262
266
  }
263
267
  }
264
268
 
@@ -266,11 +270,25 @@ async function write(p) {
266
270
  log.warn?.(`[notify] ${data.source} has sent ${RATE_CAP} in the last hour - holding the rest.`);
267
271
  return null;
268
272
  }
269
- return adapter.insert(SLUG, {
273
+ const entry = await adapter.insert(SLUG, {
270
274
  id: randomUUID(),
271
275
  data: {...data, createdAt: now, readBy: [], dismissedBy: []},
272
276
  meta: {createdAt: now, updatedAt: now, source: data.source}
273
277
  });
278
+ raised(entry);
279
+ return entry;
280
+ }
281
+
282
+ /**
283
+ * Tell listeners (the Telegram Tool, for one) that a notification was stored:
284
+ * `hooks.on('notification:raised', (entry) => …)`, with the stored entry. Only
285
+ * news is told - a new one, or a repeat that grew worse - never a quiet repeat,
286
+ * a switched-off source or one held by the cap. The bus already keeps a failing
287
+ * listener from reaching here; the try is for an entry that is not one.
288
+ */
289
+ function raised(entry) {
290
+ if (!entry?.data) return;
291
+ try { hooks.emit('notification:raised', entry); } catch (err) { log.warn?.(`[notify] notification:raised: ${err.message}`); }
274
292
  }
275
293
 
276
294
  /**
@@ -36,6 +36,7 @@ import {
36
36
  } from './hooks.js';
37
37
  import {registerPluginResource, unregisterPluginResourcesByPlugin} from './permissionRegistry.js';
38
38
  import {registerThemeProvider} from './themeSettings.js';
39
+ import {siteBrand} from './brandKit.js';
39
40
  import {registerAdminAssistant} from './adminAssistant.js';
40
41
  import {classifyEntitlement, mayLoad} from './pluginEntitlement.js';
41
42
  import {notifierFor} from './notify.js';
@@ -592,6 +593,8 @@ export async function registerPlugins(fastify) {
592
593
  // calls sitemapChanged() when they change; otherwise they show within ten minutes.
593
594
  registerSitemapSource: (source) => registerSitemapSource({...source, owner: manifest.name}),
594
595
  sitemapChanged: () => cacheInvalidateTags(['sitemap']).catch(() => {}),
596
+ // The site's Brand Kit, resolved (services/brandKit.js) - read it at use, it changes on save.
597
+ brandKit: () => siteBrand(getConfig('site')),
595
598
  on: hooks.on.bind(hooks), ...pluginRoleHooks(manifest.name),
596
599
  // Notifications (0.80) - notify, resolveNotification, registerNotificationSource,
597
600
  // stamped with the plugin's name (its source ids are `<plugin>:<id>`).
@@ -7,6 +7,7 @@ import fs from 'fs/promises';
7
7
  import path from 'path';
8
8
  import {fileURLToPath} from 'url';
9
9
  import {getConfig} from '../config.js';
10
+ import {navBrand, savedBrand} from './brandKit.js';
10
11
  import {getInjectionSnippets} from './plugins.js';
11
12
  import {applyTransforms} from './hooks.js';
12
13
  import {contentsPaint, readContentsOverride, resolveContents} from './pageContents.js';
@@ -459,7 +460,7 @@ export async function renderPage(page, opts = {}) {
459
460
  // navigation.json.bak file so a restored backup keeps working.
460
461
  const navigation = navMenu
461
462
  ? {
462
- brand: site.brand || {},
463
+ brand: navBrand(site),
463
464
  items: navItemsDecorated,
464
465
  variant: navMenu.variant || 'default',
465
466
  position: navMenu.position || 'sticky',
@@ -488,7 +489,7 @@ export async function renderPage(page, opts = {}) {
488
489
  ...(navMenu.class && {class: navMenu.class}),
489
490
  ...(navMenu.style && {style: navMenu.style})
490
491
  }
491
- : (await readLegacyNavBackup()) || {brand: site.brand || {}, items: []};
492
+ : (await readLegacyNavBackup()) || {brand: navBrand(site), items: []};
492
493
 
493
494
  // Inside a launcher's panel the layout is the body alone, whatever the page asks for.
494
495
  const preset = embed
@@ -855,7 +856,8 @@ function buildSeoMeta({page, site, baseUrl, title, description, image}) {
855
856
  ogType: page.seo?.ogType || 'article',
856
857
  noindex: page.seo?.noindex === true,
857
858
  canonical,
858
- siteName: site.title || '',
859
+ // A saved Brand Kit's name is the business's; else the site title as before.
860
+ siteName: savedBrand(site)?.name || site.title || '',
859
861
  twitterSite: site.social?.twitter || '',
860
862
  og: {},
861
863
  twitter: {},
@@ -1309,7 +1311,7 @@ export async function renderBlogPage(templatePath, data = {}, seoMeta = {}) {
1309
1311
  // navigation.json.bak file so a restored backup keeps working.
1310
1312
  const navigation = navMenu
1311
1313
  ? {
1312
- brand: site.brand || {},
1314
+ brand: navBrand(site),
1313
1315
  items: navItemsDecorated,
1314
1316
  variant: navMenu.variant || 'default',
1315
1317
  position: navMenu.position || 'sticky',
@@ -1335,7 +1337,7 @@ export async function renderBlogPage(templatePath, data = {}, seoMeta = {}) {
1335
1337
  ...(navMenu.class && {class: navMenu.class}),
1336
1338
  ...(navMenu.style && {style: navMenu.style})
1337
1339
  }
1338
- : (await readLegacyNavBackup()) || {brand: site.brand || {}, items: []};
1340
+ : (await readLegacyNavBackup()) || {brand: navBrand(site), items: []};
1339
1341
 
1340
1342
  // Replace {{key}} tokens in the plugin fragment with data values
1341
1343
  const renderedFragment = fragment.replace(/\{\{(\w+)\}\}/g, (_, key) => {
@@ -189,7 +189,7 @@
189
189
  <script src="/public/js/form-logic-engine.js?v=20261031-forms-reduce-motion" defer></script>
190
190
 
191
191
  <!-- Site initialisation -->
192
- <script src="/public/js/site.js?v=20261115-table-titles-2" type="module"></script>
192
+ <script src="/public/js/site.js?v=20261120-brand-kit-logo" type="module"></script>
193
193
  <script src="/public/js/collection-context.js?v=20261010-utf8-payloads" type="module"></script>
194
194
  {{ctxMenusModule}}
195
195
  <!-- [image zoom] pictures' full-size view - only on a page that has one -->