domma-cms 1.80.0 → 1.81.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.
- package/CHANGELOG.md +13 -0
- package/admin/css/site-settings.css +1 -1
- package/admin/js/lib/site-settings-arrange.js +3 -3
- package/admin/js/templates/docs/usage-site-settings.html +29 -3
- package/admin/js/templates/settings.html +94 -4
- package/admin/js/views/settings.js +3 -3
- package/docs/DommaFeatures.md +51 -2
- package/docs/plans/2026-11-19-brand-kit-design.md +1 -1
- package/docs/plugin-development.md +6 -0
- package/package.json +1 -1
- package/plugins/_lib/telegram/bot.js +120 -0
- package/plugins/free-tier.lock.json +26 -1
- package/plugins/telegram/CHANGELOG.md +5 -0
- package/plugins/telegram/CLAUDE.md +77 -0
- package/plugins/telegram/admin/css/index.css +68 -0
- package/plugins/telegram/admin/lib/arrange.js +103 -0
- package/plugins/telegram/admin/lib/kit.js +153 -0
- package/plugins/telegram/admin/templates/telegram.html +1 -0
- package/plugins/telegram/admin/views/chats.js +223 -0
- package/plugins/telegram/admin/views/connection.js +90 -0
- package/plugins/telegram/admin/views/telegram.js +89 -0
- package/plugins/telegram/admin/views/test.js +84 -0
- package/plugins/telegram/config.js +21 -0
- package/plugins/telegram/docs/guide.md +87 -0
- package/plugins/telegram/lib/messages.js +176 -0
- package/plugins/telegram/lib/queue.js +72 -0
- package/plugins/telegram/plugin.js +490 -0
- package/plugins/telegram/plugin.json +71 -0
- package/plugins/telegram/tests/api.test.js +381 -0
- package/plugins/telegram/tests/arrange.test.js +41 -0
- package/plugins/telegram/tests/messages.test.js +110 -0
- package/plugins/telegram/tests/queue.test.js +47 -0
- package/server/routes/api/brand-kit.js +55 -0
- package/server/routes/api/settings.js +17 -1
- package/server/server.js +2 -0
- package/server/services/brandKit.js +268 -0
- package/server/services/emailBrand.js +31 -13
- package/server/services/notify.js +20 -2
- package/server/services/plugins.js +3 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {normaliseEmailBrand} from '../../services/emailBrand.js';
|
|
2
|
+
import {brandKitProblems, normaliseBrandKit} from '../../services/brandKit.js';
|
|
2
3
|
import {EMAIL_EXAMPLES, emailExample} from '../../services/emailExamples.js';
|
|
3
4
|
/**
|
|
4
5
|
* Settings API
|
|
@@ -60,6 +61,10 @@ export function settingsBadge(site = {}, cacheStats = {}) {
|
|
|
60
61
|
if ((cc.enabled !== false || measurementIdOf(site)) && !String(cc.privacyPolicyUrl || '').trim()) {
|
|
61
62
|
problems.push({tone: 'warn', text: 'Cookie banner without a privacy policy', meta: 'it links to nothing'});
|
|
62
63
|
}
|
|
64
|
+
// An SVG logo reaches email as a PNG copy at the site's address - without one, emails show the name.
|
|
65
|
+
if (brandKitProblems(site).length) {
|
|
66
|
+
problems.push({tone: 'warn', text: 'SVG logo and no Site URL', meta: 'emails show your name instead of the logo'});
|
|
67
|
+
}
|
|
63
68
|
const danger = problems.some(p => p.tone === 'danger');
|
|
64
69
|
const n = problems.length;
|
|
65
70
|
return {
|
|
@@ -136,7 +141,9 @@ export async function settingsRoutes(fastify) {
|
|
|
136
141
|
const ALLOWED_KEYS = new Set([
|
|
137
142
|
'title', 'tagline', 'description', 'logo', 'favicon',
|
|
138
143
|
'theme', 'adminTheme', 'fontFamily', 'fontSize',
|
|
139
|
-
'smtp', 'emailBrand', 'footer',
|
|
144
|
+
'smtp', 'emailBrand', 'footer',
|
|
145
|
+
// The site-wide brand (Site Settings > Branding > Brand Kit) - services/brandKit.js.
|
|
146
|
+
'brandKit', 'analytics', 'social', 'locale',
|
|
140
147
|
'layoutOptions', 'seo', 'backToTop', 'goToBottom', 'cookieConsent', 'breadcrumbs', 'autoTheme',
|
|
141
148
|
'adminBrand',
|
|
142
149
|
// The screen `#/` (Dashboard) opens - see services/adminHome.js.
|
|
@@ -259,6 +266,11 @@ export async function settingsRoutes(fastify) {
|
|
|
259
266
|
merged.motion = normaliseMotionSettings(next, merged.footer);
|
|
260
267
|
}
|
|
261
268
|
}
|
|
269
|
+
if ('brandKit' in data) {
|
|
270
|
+
// Replaced whole, never merged: the Kit is one object the screen sends complete.
|
|
271
|
+
try { merged.brandKit = normaliseBrandKit(data.brandKit); }
|
|
272
|
+
catch (err) { return reply.code(400).send({error: err.message}); }
|
|
273
|
+
}
|
|
262
274
|
if ('emailBrand' in data) {
|
|
263
275
|
try { merged.emailBrand = normaliseEmailBrand(merged.emailBrand); }
|
|
264
276
|
catch (err) { return reply.code(400).send({error: err.message}); }
|
|
@@ -292,6 +304,10 @@ export async function settingsRoutes(fastify) {
|
|
|
292
304
|
|
|
293
305
|
fastify.post('/settings/email-preview', canRead, async (request, reply) => {
|
|
294
306
|
const site = getConfig('site');
|
|
307
|
+
if (request.body?.brandKit !== undefined) {
|
|
308
|
+
try { site.brandKit = normaliseBrandKit(request.body.brandKit); }
|
|
309
|
+
catch (err) { return reply.code(400).send({error: err.message}); }
|
|
310
|
+
}
|
|
295
311
|
if (request.body?.emailBrand !== undefined) {
|
|
296
312
|
try { site.emailBrand = normaliseEmailBrand(request.body.emailBrand); }
|
|
297
313
|
catch (err) { return reply.code(400).send({error: err.message}); }
|
package/server/server.js
CHANGED
|
@@ -529,6 +529,7 @@ await app.register(authRoutes, { prefix: '/api' });
|
|
|
529
529
|
|
|
530
530
|
const { pagesRoutes } = await import('./routes/api/pages.js');
|
|
531
531
|
const { settingsRoutes } = await import('./routes/api/settings.js');
|
|
532
|
+
const {brandKitRoutes} = await import('./routes/api/brand-kit.js');
|
|
532
533
|
const { themeRoutes } = await import('./routes/api/theme.js');
|
|
533
534
|
const { layoutsRoutes } = await import('./routes/api/layouts.js');
|
|
534
535
|
const { navigationRoutes } = await import('./routes/api/navigation.js');
|
|
@@ -574,6 +575,7 @@ const {scaffoldRoutes} = await import('./routes/api/scaffold.js');
|
|
|
574
575
|
|
|
575
576
|
await app.register(pagesRoutes, { prefix: '/api' });
|
|
576
577
|
await app.register(settingsRoutes, { prefix: '/api' });
|
|
578
|
+
await app.register(brandKitRoutes, { prefix: '/api' });
|
|
577
579
|
await app.register(layoutsRoutes, { prefix: '/api' });
|
|
578
580
|
await app.register(navigationRoutes, { prefix: '/api' });
|
|
579
581
|
await app.register(menusRoutes, {prefix: '/api'});
|
|
@@ -0,0 +1,268 @@
|
|
|
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
|
+
* Plan: docs/plans/2026-11-19-brand-kit-design.md.
|
|
12
|
+
*
|
|
13
|
+
* @module services/brandKit
|
|
14
|
+
*/
|
|
15
|
+
import fs from 'node:fs';
|
|
16
|
+
import path from 'node:path';
|
|
17
|
+
import {config} from '../config.js';
|
|
18
|
+
|
|
19
|
+
/** Fonts the Kit offers: safe fonts everywhere, Google fonts with a safe fallback. */
|
|
20
|
+
export const KIT_FONTS = {
|
|
21
|
+
'': {label: 'Site default', stack: 'Arial, Helvetica, sans-serif'},
|
|
22
|
+
arial: {label: 'Arial', stack: 'Arial, Helvetica, sans-serif'},
|
|
23
|
+
helvetica: {label: 'Helvetica', stack: 'Helvetica, Arial, sans-serif'},
|
|
24
|
+
verdana: {label: 'Verdana', stack: 'Verdana, Geneva, sans-serif'},
|
|
25
|
+
tahoma: {label: 'Tahoma', stack: 'Tahoma, Verdana, sans-serif'},
|
|
26
|
+
trebuchet: {label: 'Trebuchet MS', stack: '"Trebuchet MS", Helvetica, sans-serif'},
|
|
27
|
+
georgia: {label: 'Georgia', stack: 'Georgia, "Times New Roman", serif'},
|
|
28
|
+
times: {label: 'Times New Roman', stack: '"Times New Roman", Times, serif'},
|
|
29
|
+
inter: {label: 'Inter', stack: 'Inter, Arial, sans-serif', google: 'Inter'},
|
|
30
|
+
roboto: {label: 'Roboto', stack: 'Roboto, Arial, sans-serif', google: 'Roboto'},
|
|
31
|
+
'open-sans': {label: 'Open Sans', stack: '"Open Sans", Arial, sans-serif', google: 'Open Sans'},
|
|
32
|
+
lato: {label: 'Lato', stack: 'Lato, Arial, sans-serif', google: 'Lato'},
|
|
33
|
+
montserrat: {label: 'Montserrat', stack: 'Montserrat, Arial, sans-serif', google: 'Montserrat'},
|
|
34
|
+
poppins: {label: 'Poppins', stack: 'Poppins, Arial, sans-serif', google: 'Poppins'},
|
|
35
|
+
nunito: {label: 'Nunito', stack: 'Nunito, Arial, sans-serif', google: 'Nunito'},
|
|
36
|
+
merriweather: {label: 'Merriweather', stack: 'Merriweather, Georgia, serif', google: 'Merriweather'},
|
|
37
|
+
'playfair-display': {label: 'Playfair Display', stack: '"Playfair Display", Georgia, serif', google: 'Playfair Display'},
|
|
38
|
+
'source-serif': {label: 'Source Serif 4', stack: '"Source Serif 4", Georgia, serif', google: 'Source Serif 4'}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const MAX_KIT_COLOURS = 4;
|
|
42
|
+
|
|
43
|
+
const TEXT_LIMITS = {name: 120, legalName: 160, shortName: 40, footerLine: 300, smallPrint: 1200,
|
|
44
|
+
email: 160, phone: 40, address: 400, website: 300, companyNumber: 40, vatNumber: 40};
|
|
45
|
+
|
|
46
|
+
const clean = (value, max) => typeof value === 'string'
|
|
47
|
+
? value.replace(/\r\n?/g, '\n').replace(/[\u0000-\u0009\u000b-\u001f\u007f]/g, ' ').trim().slice(0, max) : '';
|
|
48
|
+
const oneLine = (value, max) => clean(value, max).replace(/\n+/g, ' ');
|
|
49
|
+
const HEX = /^#[\da-f]{6}$/i;
|
|
50
|
+
const EMAIL = /^[^\s@<>"]+@[^\s@<>"]+\.[^\s@<>"]+$/;
|
|
51
|
+
|
|
52
|
+
/** A path on the site (`/media/...`, no climbing out) or an https address, else ''. */
|
|
53
|
+
export function kitImage(value) {
|
|
54
|
+
const v = oneLine(value, 2000);
|
|
55
|
+
if (!v) return '';
|
|
56
|
+
if (v.startsWith('/') && !v.startsWith('//')) {
|
|
57
|
+
let decoded;
|
|
58
|
+
try { decoded = decodeURIComponent(v); } catch { return ''; }
|
|
59
|
+
return /(^|\/)\.\.(\/|$)|\\|[?#]/.test(decoded) ? '' : v;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const url = new URL(v);
|
|
63
|
+
return url.protocol === 'https:' && !url.username && !url.password ? url.href : '';
|
|
64
|
+
} catch { return ''; }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function kitWebsite(value) {
|
|
68
|
+
const v = oneLine(value, TEXT_LIMITS.website);
|
|
69
|
+
if (!v) return '';
|
|
70
|
+
try {
|
|
71
|
+
const url = new URL(/^https?:\/\//i.test(v) ? v : `https://${v}`);
|
|
72
|
+
return ['http:', 'https:'].includes(url.protocol) && !url.username && !url.password ? url.href.replace(/\/$/, '') : '';
|
|
73
|
+
} catch { return ''; }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The Kit as stored: every field cleaned, unknown fields dropped. Throws a plain-English
|
|
78
|
+
* Error for what the owner must fix (a colour or an email address that is not one).
|
|
79
|
+
*
|
|
80
|
+
* @param {object} value
|
|
81
|
+
* @param {{now?: () => string}} [opts]
|
|
82
|
+
*/
|
|
83
|
+
export function normaliseBrandKit(value, {now = () => new Date().toISOString()} = {}) {
|
|
84
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error('Brand Kit: send an object.');
|
|
85
|
+
const accent = oneLine(value.accent, 7);
|
|
86
|
+
if (accent && !HEX.test(accent)) throw new Error('Brand Kit: the accent colour must be a six-digit colour, such as #2563eb.');
|
|
87
|
+
const colours = (Array.isArray(value.colours) ? value.colours : []).slice(0, 20)
|
|
88
|
+
.map(c => ({name: oneLine(c?.name, 40), hex: oneLine(c?.hex, 7)}))
|
|
89
|
+
.filter(c => c.name || c.hex).slice(0, MAX_KIT_COLOURS);
|
|
90
|
+
for (const c of colours) {
|
|
91
|
+
if (!HEX.test(c.hex)) throw new Error(`Brand Kit: "${c.name || 'a colour'}" needs a six-digit colour, such as #0f766e.`);
|
|
92
|
+
}
|
|
93
|
+
const fonts = {};
|
|
94
|
+
for (const key of ['heading', 'body']) {
|
|
95
|
+
const id = oneLine(value.fonts?.[key], 40);
|
|
96
|
+
fonts[key] = Object.hasOwn(KIT_FONTS, id) ? id : '';
|
|
97
|
+
}
|
|
98
|
+
const c = value.contact && typeof value.contact === 'object' ? value.contact : {};
|
|
99
|
+
const email = oneLine(c.email, TEXT_LIMITS.email);
|
|
100
|
+
if (email && !EMAIL.test(email)) throw new Error('Brand Kit: the contact email is not an email address.');
|
|
101
|
+
const website = oneLine(c.website, TEXT_LIMITS.website);
|
|
102
|
+
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.');
|
|
103
|
+
return {
|
|
104
|
+
name: oneLine(value.name, TEXT_LIMITS.name),
|
|
105
|
+
legalName: oneLine(value.legalName, TEXT_LIMITS.legalName),
|
|
106
|
+
shortName: oneLine(value.shortName, TEXT_LIMITS.shortName),
|
|
107
|
+
logo: kitImage(value.logo),
|
|
108
|
+
logoDark: kitImage(value.logoDark),
|
|
109
|
+
mark: kitImage(value.mark),
|
|
110
|
+
accent: accent.toLowerCase(),
|
|
111
|
+
colours: colours.map(x => ({name: x.name, hex: x.hex.toLowerCase()})),
|
|
112
|
+
fonts,
|
|
113
|
+
contact: {
|
|
114
|
+
email, website: kitWebsite(website),
|
|
115
|
+
phone: oneLine(c.phone, TEXT_LIMITS.phone),
|
|
116
|
+
address: clean(c.address, TEXT_LIMITS.address),
|
|
117
|
+
companyNumber: oneLine(c.companyNumber, TEXT_LIMITS.companyNumber),
|
|
118
|
+
vatNumber: oneLine(c.vatNumber, TEXT_LIMITS.vatNumber)
|
|
119
|
+
},
|
|
120
|
+
footerLine: oneLine(value.footerLine, TEXT_LIMITS.footerLine),
|
|
121
|
+
smallPrint: clean(value.smallPrint, TEXT_LIMITS.smallPrint),
|
|
122
|
+
updatedAt: now()
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* A logo the site already had (`brand.logo`, `logo`), as loosely as emails read it before the Kit:
|
|
128
|
+
* a path on the site or an http(s) address, query strings allowed. Never `//` or other schemes.
|
|
129
|
+
*/
|
|
130
|
+
function legacyImage(value) {
|
|
131
|
+
const v = oneLine(value, 2000);
|
|
132
|
+
if (!v) return '';
|
|
133
|
+
if (v.startsWith('/') && !v.startsWith('//')) return /\\/.test(v) ? '' : v;
|
|
134
|
+
try {
|
|
135
|
+
const url = new URL(v);
|
|
136
|
+
return ['http:', 'https:'].includes(url.protocol) && !url.username && !url.password ? url.href : '';
|
|
137
|
+
} catch { return ''; }
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** The site's address (`baseUrl`, else `url`) as an origin, or ''. */
|
|
141
|
+
export function siteOriginOf(site = {}) {
|
|
142
|
+
for (const v of [site.baseUrl, site.url]) {
|
|
143
|
+
try {
|
|
144
|
+
const url = new URL(String(v ?? ''));
|
|
145
|
+
if (['http:', 'https:'].includes(url.protocol)) return url.origin;
|
|
146
|
+
} catch { /* not set */ }
|
|
147
|
+
}
|
|
148
|
+
return '';
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** A Kit image made absolute against the site's address; '' when it cannot be. */
|
|
152
|
+
export function absoluteImage(value, origin) {
|
|
153
|
+
const v = kitImage(value) || legacyImage(value);
|
|
154
|
+
if (!v) return '';
|
|
155
|
+
if (/^https?:\/\//i.test(v)) return v;
|
|
156
|
+
try { return origin ? new URL(v, origin).href : ''; } catch { return ''; }
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const isSvg = (v) => /\.svg(?:[?#]|$)/i.test(String(v || ''));
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* The site's brand, resolved: the Kit, with what the site already had for every empty field.
|
|
163
|
+
* Images stay as stored (Media paths); callers that need absolute addresses use absoluteImage().
|
|
164
|
+
*
|
|
165
|
+
* @param {object} site - config/site.json
|
|
166
|
+
*/
|
|
167
|
+
export function siteBrand(site = {}) {
|
|
168
|
+
const raw = site.brandKit && typeof site.brandKit === 'object' ? site.brandKit : {};
|
|
169
|
+
let kit;
|
|
170
|
+
try { kit = normaliseBrandKit(raw, {now: () => raw.updatedAt || ''}); }
|
|
171
|
+
catch { kit = normaliseBrandKit({}, {now: () => ''}); }
|
|
172
|
+
const footer = site.footer || {};
|
|
173
|
+
const contactEmail = [kit.contact.email, site.contactEmail, footer.email].map(v => oneLine(v, 160)).find(v => EMAIL.test(v)) || '';
|
|
174
|
+
// '' when the site has no name at all: each reader picks its own last resort (emails: the SMTP From name).
|
|
175
|
+
const name = kit.name || oneLine(site.brand?.text, 120) || oneLine(site.title, 120);
|
|
176
|
+
const social = Object.fromEntries(Object.entries(site.social || {})
|
|
177
|
+
.filter(([, v]) => typeof v === 'string' && /^https?:\/\//i.test(v.trim())).map(([k, v]) => [k, v.trim()]));
|
|
178
|
+
return {
|
|
179
|
+
name,
|
|
180
|
+
legalName: kit.legalName,
|
|
181
|
+
shortName: kit.shortName || name,
|
|
182
|
+
logo: kit.logo || legacyImage(site.brand?.logo) || legacyImage(site.logo),
|
|
183
|
+
logoDark: kit.logoDark,
|
|
184
|
+
mark: kit.mark,
|
|
185
|
+
accent: kit.accent,
|
|
186
|
+
colours: kit.colours,
|
|
187
|
+
fonts: {heading: kit.fonts.heading, body: kit.fonts.body},
|
|
188
|
+
contact: {
|
|
189
|
+
...kit.contact, email: contactEmail,
|
|
190
|
+
address: kit.contact.address || clean(footer.address, 400),
|
|
191
|
+
website: kit.contact.website || siteOriginOf(site)
|
|
192
|
+
},
|
|
193
|
+
social,
|
|
194
|
+
footerLine: kit.footerLine,
|
|
195
|
+
smallPrint: kit.smallPrint,
|
|
196
|
+
updatedAt: kit.updatedAt
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** "Acme Ltd · Company number 01234567 · VAT GB123456789 · 1 Mill Lane, Leeds" - '' when none. */
|
|
201
|
+
export function legalLine(brand) {
|
|
202
|
+
const parts = [brand.legalName,
|
|
203
|
+
brand.contact?.companyNumber ? `Company number ${brand.contact.companyNumber}` : '',
|
|
204
|
+
brand.contact?.vatNumber ? `VAT ${brand.contact.vatNumber}` : '',
|
|
205
|
+
String(brand.contact?.address || '').replace(/\s*\n\s*/g, ', ')].filter(Boolean);
|
|
206
|
+
return parts.length > 1 || brand.legalName ? parts.join(' · ') : '';
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** The media file behind a `/media/...` address, or null (outside Media, or not one). */
|
|
210
|
+
export function mediaFile(src, mediaDir = config.content?.mediaDir) {
|
|
211
|
+
if (typeof src !== 'string' || !src.startsWith('/media/') || !mediaDir) return null;
|
|
212
|
+
let rel;
|
|
213
|
+
try { rel = decodeURIComponent(src.slice(7).split(/[?#]/)[0]); } catch { return null; }
|
|
214
|
+
if (!rel || rel.includes('\0') || rel.includes('\\')) return null;
|
|
215
|
+
const root = path.resolve(mediaDir);
|
|
216
|
+
const file = path.resolve(root, rel);
|
|
217
|
+
return file.startsWith(root + path.sep) ? file : null;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export const MAX_SVG_BYTES = 1024 * 1024;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* The logo an email can show: a raster logo as it is; an SVG one through the PNG copy
|
|
224
|
+
* (`GET /api/brand-kit/logo.png`), since many mail programs show no SVG - only when that copy
|
|
225
|
+
* can be made (the file is in Media and not too big), else '' and the email shows the name.
|
|
226
|
+
* The copy's address carries the file's time, so a replaced logo is fetched afresh.
|
|
227
|
+
*/
|
|
228
|
+
export function emailLogo(brand, origin, {mediaDir} = {}) {
|
|
229
|
+
if (!brand.logo) return '';
|
|
230
|
+
if (!isSvg(brand.logo)) return absoluteImage(brand.logo, origin);
|
|
231
|
+
if (!origin) return '';
|
|
232
|
+
const file = mediaFile(brand.logo, mediaDir);
|
|
233
|
+
if (!file) return '';
|
|
234
|
+
let stat;
|
|
235
|
+
try { stat = fs.statSync(file); } catch { return ''; }
|
|
236
|
+
if (!stat.isFile() || stat.size > MAX_SVG_BYTES) return '';
|
|
237
|
+
return `${origin}/api/brand-kit/logo.png?v=${Math.round(stat.mtimeMs)}-${stat.size}`;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** A font id -> {stack, google?}. */
|
|
241
|
+
export function kitFont(id) {
|
|
242
|
+
return KIT_FONTS[id] || KIT_FONTS[''];
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/** What anyone may read (`GET /api/brand-kit`): the brand as the site presents it, absolute addresses. */
|
|
246
|
+
export function publicBrandKit(site = {}) {
|
|
247
|
+
const b = siteBrand(site);
|
|
248
|
+
const origin = siteOriginOf(site);
|
|
249
|
+
const font = (id) => ({id, label: kitFont(id).label, stack: kitFont(id).stack, google: kitFont(id).google || ''});
|
|
250
|
+
return {
|
|
251
|
+
name: b.name, legalName: b.legalName, shortName: b.shortName,
|
|
252
|
+
logo: absoluteImage(b.logo, origin) || b.logo, logoDark: absoluteImage(b.logoDark, origin) || b.logoDark,
|
|
253
|
+
mark: absoluteImage(b.mark, origin) || b.mark,
|
|
254
|
+
accent: b.accent, colours: b.colours,
|
|
255
|
+
fonts: {heading: font(b.fonts.heading), body: font(b.fonts.body)},
|
|
256
|
+
contact: b.contact, social: b.social,
|
|
257
|
+
footerLine: b.footerLine, smallPrint: b.smallPrint, legalLine: legalLine(b)
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** Admin problems the Kit can have (Site Settings' Needs attention). Plain text. */
|
|
262
|
+
export function brandKitProblems(site = {}) {
|
|
263
|
+
const b = siteBrand(site);
|
|
264
|
+
if (isSvg(b.logo) && !siteOriginOf(site)) {
|
|
265
|
+
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.'}];
|
|
266
|
+
}
|
|
267
|
+
return [];
|
|
268
|
+
}
|
|
@@ -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 => ({'&': '&', '<': '<', '>': '>', '"': '"', "'": '''}[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
|
-
/**
|
|
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
|
|
20
|
-
const accent =
|
|
21
|
-
const support = clean(override.supportEmail ||
|
|
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 ||
|
|
24
|
-
logo
|
|
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
|
|
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
|
|
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};"> </td></tr>
|
|
94
|
-
<tr><td class="dm-email-pad dm-email-brand" style="padding:28px 36px 20px;">${logo}<div style="font
|
|
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
|
|
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
|
|
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(' · ')}</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
|
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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>`).
|