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.
- package/CHANGELOG.md +20 -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 +47 -3
- package/admin/js/templates/settings.html +98 -8
- 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 +34 -9
- 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/plugins/theme-roller/CLAUDE.md +9 -0
- package/plugins/theme-roller/admin/lib/themes.js +49 -0
- package/plugins/theme-roller/admin/templates/theme-roller.html +2 -0
- package/plugins/theme-roller/admin/views/theme-roller-view.js +25 -2
- package/plugins/theme-roller/docs/guide.md +1 -0
- package/plugins/theme-roller/plugin.json +1 -1
- package/plugins/theme-roller/tests/themes.test.js +20 -0
- package/public/js/site.js +1 -1
- package/server/routes/api/brand-kit.js +55 -0
- package/server/routes/api/settings.js +17 -1
- package/server/routes/favicon.js +10 -6
- package/server/server.js +2 -0
- package/server/services/adminBrand.js +8 -3
- package/server/services/brandKit.js +330 -0
- package/server/services/chat/launcher-bridge.js +2 -1
- package/server/services/emailBrand.js +31 -13
- package/server/services/launchers.js +5 -1
- package/server/services/notify.js +20 -2
- package/server/services/plugins.js +3 -0
- package/server/services/renderer.js +7 -5
- package/server/templates/page.html +1 -1
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram (free) through its routes, with Telegram swapped out by setTelegram - no test reaches Telegram.
|
|
3
|
+
* Settings live in the checkout's config/plugins.json, restored byte for byte after.
|
|
4
|
+
*/
|
|
5
|
+
import {after, before, beforeEach, test} from 'node:test';
|
|
6
|
+
import assert from 'node:assert/strict';
|
|
7
|
+
import fs from 'node:fs/promises';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import {EventEmitter} from 'node:events';
|
|
10
|
+
import Fastify from 'fastify';
|
|
11
|
+
import telegram from '../plugin.js';
|
|
12
|
+
import {setTelegram} from '../../_lib/telegram/bot.js';
|
|
13
|
+
import {savePluginState} from '../../../server/services/plugins.js';
|
|
14
|
+
|
|
15
|
+
const PLUGINS = path.resolve('config/plugins.json');
|
|
16
|
+
const TOKEN = '123456789:AAEabcdefghijklmnopqrstuvwxyz0123456';
|
|
17
|
+
const BASE = 'https://acme.test';
|
|
18
|
+
const FORMS = {
|
|
19
|
+
contact: {slug: 'contact', title: 'Contact us', fields: [
|
|
20
|
+
{name: 'name', label: 'Your name', type: 'string'},
|
|
21
|
+
{name: 'email', label: 'Email', type: 'email'},
|
|
22
|
+
{name: 'pin', label: 'PIN', type: 'password'},
|
|
23
|
+
{name: 'cv', label: 'CV', type: 'file'},
|
|
24
|
+
{name: 'ref', label: 'Ref', type: 'hidden'},
|
|
25
|
+
{name: 'message', label: 'Message', type: 'textarea'}
|
|
26
|
+
]},
|
|
27
|
+
quote: {slug: 'quote', title: 'Quote', fields: [{name: 'what', label: 'What', type: 'string'}]}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
let saved;
|
|
31
|
+
let updateId = 0;
|
|
32
|
+
let app;
|
|
33
|
+
let bus;
|
|
34
|
+
let calls;
|
|
35
|
+
let webhookUrl = '';
|
|
36
|
+
let user = {id: 'a1', name: 'Ann Admin', role: 'admin'};
|
|
37
|
+
const USERS = {a1: {id: 'a1', name: 'Ann Admin', role: 'admin'}, e1: {id: 'e1', name: 'Ed Editor', role: 'editor'}};
|
|
38
|
+
let denyManage = false;
|
|
39
|
+
|
|
40
|
+
/** The fake Bot API: records every call; getWebhookInfo answers whatever webhookUrl is. */
|
|
41
|
+
function fakeTelegram() {
|
|
42
|
+
let nextId = 100;
|
|
43
|
+
setTelegram(async (method, body) => {
|
|
44
|
+
calls.push({method, body});
|
|
45
|
+
if (method === 'getMe') return {ok: true, result: {id: 1, username: 'acme_bot'}};
|
|
46
|
+
if (method === 'getWebhookInfo') return {ok: true, result: {url: webhookUrl, pending_update_count: 0}};
|
|
47
|
+
if (method === 'setWebhook') { webhookUrl = body.url; return {ok: true, result: true}; }
|
|
48
|
+
if (method === 'deleteWebhook') { webhookUrl = ''; return {ok: true, result: true}; }
|
|
49
|
+
if (method === 'sendMessage') return {ok: true, result: {message_id: nextId++, chat: {id: body.chat_id}}};
|
|
50
|
+
return {ok: false, description: `unexpected ${method}`};
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const sent = () => calls.filter(c => c.method === 'sendMessage');
|
|
55
|
+
const settle = () => new Promise(r => setTimeout(r, 30));
|
|
56
|
+
|
|
57
|
+
async function call(method, url, body, headers) {
|
|
58
|
+
const res = await app.inject({method, url, payload: body, headers});
|
|
59
|
+
let json = null;
|
|
60
|
+
try { json = res.json(); } catch { /* not JSON */ }
|
|
61
|
+
return {status: res.statusCode, body: json};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function secret() {
|
|
65
|
+
const {getPluginStates} = await import('../../../server/services/plugins.js');
|
|
66
|
+
return getPluginStates().telegram.settings.secret;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function hook(message) {
|
|
70
|
+
return call('POST', '/webhook', {update_id: ++updateId, message}, {'x-telegram-bot-api-secret-token': await secret()});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function connectAndLink(chat = {id: -1001, type: 'supergroup', title: 'Office'}) {
|
|
74
|
+
let r = await call('POST', '/connect', {token: TOKEN, base: BASE});
|
|
75
|
+
assert.equal(r.status, 200, JSON.stringify(r.body));
|
|
76
|
+
r = await call('POST', '/link-code', {});
|
|
77
|
+
const code = r.body.linkCode;
|
|
78
|
+
await hook({message_id: 1, chat, text: `/link ${code}`});
|
|
79
|
+
return (await call('GET', '/status')).body.chats.at(-1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
before(async () => {
|
|
83
|
+
saved = await fs.readFile(PLUGINS, 'utf8').catch(() => null);
|
|
84
|
+
bus = new EventEmitter();
|
|
85
|
+
app = Fastify();
|
|
86
|
+
await app.register(telegram, {
|
|
87
|
+
auth: {
|
|
88
|
+
authenticate: async (req) => { req.user = user; },
|
|
89
|
+
requirePermission: (_key, action) => async (_req, reply) => { if (action === 'manage' && denyManage) return reply.code(403).send({error: 'No'}); }
|
|
90
|
+
},
|
|
91
|
+
hooks: {
|
|
92
|
+
on: bus.on.bind(bus),
|
|
93
|
+
notify: async (p) => { bus.emit('notification:raised', {id: 'n1', data: {severity: 'info', ...p, source: `telegram:${p.source}`, sourceLabel: 'Telegram'}}); },
|
|
94
|
+
registerNotificationSource() {}
|
|
95
|
+
},
|
|
96
|
+
getForm: async (slug) => { if (!FORMS[slug]) throw new Error('no form'); return FORMS[slug]; },
|
|
97
|
+
listForms: async () => Object.values(FORMS),
|
|
98
|
+
listSources: () => [{id: 'core:disk', label: 'Disk space', owner: 'core', ownerLabel: 'System'}, {id: 'invoice:overdue', label: 'Overdue', owner: 'invoice', ownerLabel: 'Invoice'}],
|
|
99
|
+
queueGapMs: 0, awaitUpdates: true,
|
|
100
|
+
getUser: async (id) => USERS[id] || null,
|
|
101
|
+
canReadForms: (u) => u?.role !== 'editor'
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
after(async () => {
|
|
106
|
+
setTelegram(null);
|
|
107
|
+
await app?.close();
|
|
108
|
+
delete globalThis[Symbol.for('domma.telegram')];
|
|
109
|
+
if (saved === null) await fs.rm(PLUGINS, {force: true});
|
|
110
|
+
else await fs.writeFile(PLUGINS, saved);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
beforeEach(() => {
|
|
114
|
+
calls = [];
|
|
115
|
+
webhookUrl = '';
|
|
116
|
+
denyManage = false;
|
|
117
|
+
savePluginState('telegram', {settings: {}});
|
|
118
|
+
fakeTelegram();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('connect: a bad token or http is refused; a good one sets the webhook with a secret and is never sent back', async () => {
|
|
122
|
+
assert.equal((await call('POST', '/connect', {token: 'nope', base: BASE})).status, 400);
|
|
123
|
+
assert.equal((await call('POST', '/connect', {token: TOKEN, base: 'http://acme.test'})).status, 400);
|
|
124
|
+
const r = await call('POST', '/connect', {token: TOKEN, base: BASE});
|
|
125
|
+
assert.equal(r.status, 200);
|
|
126
|
+
assert.equal(r.body.connected, true);
|
|
127
|
+
assert.equal(r.body.botName, 'acme_bot');
|
|
128
|
+
const set = calls.find(c => c.method === 'setWebhook');
|
|
129
|
+
assert.equal(set.body.url, `${BASE}/api/plugins/telegram/webhook`);
|
|
130
|
+
assert.match(set.body.secret_token, /^[0-9a-f]{48}$/);
|
|
131
|
+
assert.deepEqual(set.body.allowed_updates, ['message']);
|
|
132
|
+
const text = JSON.stringify((await call('GET', '/status')).body);
|
|
133
|
+
assert.ok(!text.includes(TOKEN), 'the token never leaves');
|
|
134
|
+
assert.ok(!text.includes(set.body.secret_token), 'nor the webhook secret');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test('connect: a bot already used elsewhere (Takeaway) is refused, and its webhook left alone', async () => {
|
|
138
|
+
webhookUrl = 'https://shop.test/api/plugins/takeaway/telegram/webhook';
|
|
139
|
+
const r = await call('POST', '/connect', {token: TOKEN, base: BASE});
|
|
140
|
+
assert.equal(r.status, 409);
|
|
141
|
+
assert.match(r.body.error, /already used by Takeaway on shop\.test/);
|
|
142
|
+
assert.equal(calls.filter(c => c.method === 'setWebhook').length, 0);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('manage is needed to connect, link and route', async () => {
|
|
146
|
+
denyManage = true;
|
|
147
|
+
assert.equal((await call('POST', '/connect', {token: TOKEN, base: BASE})).status, 403);
|
|
148
|
+
assert.equal((await call('POST', '/link-code', {})).status, 403);
|
|
149
|
+
assert.equal((await call('GET', '/status')).status, 200);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('webhook: 401 without the secret, a wrong one, or before connecting', async () => {
|
|
153
|
+
assert.equal((await call('POST', '/webhook', {message: {chat: {id: 1}, text: '/start'}})).status, 401);
|
|
154
|
+
await call('POST', '/connect', {token: TOKEN, base: BASE});
|
|
155
|
+
assert.equal((await call('POST', '/webhook', {message: {chat: {id: 1}, text: '/start'}}, {'x-telegram-bot-api-secret-token': 'x'.repeat(48)})).status, 401);
|
|
156
|
+
assert.equal((await hook({chat: {id: 1, type: 'private'}, text: '/start'})).status, 200);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('link: the one-time code links a chat once, with the default routing; a status never shows a code to a reader', async () => {
|
|
160
|
+
const c = await connectAndLink();
|
|
161
|
+
assert.equal(c.name, 'Office');
|
|
162
|
+
assert.equal(c.type, 'supergroup');
|
|
163
|
+
assert.deepEqual(c.alerts, {on: true, severities: ['warning', 'critical'], sources: []});
|
|
164
|
+
assert.deepEqual(c.forms, {on: false, all: false, slugs: [], detail: 'fields'});
|
|
165
|
+
assert.match(sent().at(-1).body.text, /Linked as <b>Office<\/b>/);
|
|
166
|
+
// Used: the code is gone, so it cannot link a second chat.
|
|
167
|
+
const st = (await call('GET', '/status')).body;
|
|
168
|
+
assert.equal(st.linkCode, '');
|
|
169
|
+
await call('POST', '/link-code', {});
|
|
170
|
+
denyManage = true;
|
|
171
|
+
assert.equal((await call('GET', '/status')).body.linkCode, '');
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test('link: five wrong codes and a chat is ignored for that code; another chat can still link', async () => {
|
|
175
|
+
await call('POST', '/connect', {token: TOKEN, base: BASE});
|
|
176
|
+
const code = (await call('POST', '/link-code', {})).body.linkCode;
|
|
177
|
+
for (let i = 0; i < 5; i++) await hook({chat: {id: 9, type: 'private', first_name: 'Eve'}, text: `/link wrong${i}`});
|
|
178
|
+
await hook({chat: {id: 9, type: 'private', first_name: 'Eve'}, text: `/link ${code}`});
|
|
179
|
+
assert.equal((await call('GET', '/status')).body.chats.length, 0);
|
|
180
|
+
assert.match(sent().at(-1).body.text, /not right or has run out/);
|
|
181
|
+
await hook({chat: {id: -7, type: 'group', title: 'Team'}, text: `/link ${code}`});
|
|
182
|
+
const chats = (await call('GET', '/status')).body.chats;
|
|
183
|
+
assert.deepEqual(chats.map(c => [c.name, c.ownerName]), [['Team', 'Ann Admin']]);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test('webhook: a repeated update_id is handled once', async () => {
|
|
187
|
+
await connectAndLink();
|
|
188
|
+
calls = [];
|
|
189
|
+
const s = await secret();
|
|
190
|
+
const body = {update_id: 777777, message: {message_id: 5, chat: {id: -1001, type: 'supergroup'}, text: '/help'}};
|
|
191
|
+
await call('POST', '/webhook', body, {'x-telegram-bot-api-secret-token': s});
|
|
192
|
+
await call('POST', '/webhook', body, {'x-telegram-bot-api-secret-token': s});
|
|
193
|
+
assert.equal(sent().length, 1);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test('owner: a chat set up by an admin never gets a notification meant for Super Admins only', async () => {
|
|
197
|
+
await connectAndLink();
|
|
198
|
+
calls = [];
|
|
199
|
+
bus.emit('notification:raised', {id: 'sa', data: {title: 'Licence', severity: 'critical', source: 'core:licence', audience: {roles: ['super-admin']}}});
|
|
200
|
+
bus.emit('notification:raised', {id: 'ad', data: {title: 'Disk', severity: 'critical', source: 'core:disk', audience: {roles: ['super-admin', 'admin']}}});
|
|
201
|
+
await settle();
|
|
202
|
+
assert.deepEqual(sent().map(s => s.body.text.split('\n')[0]), ['🚨 <b>Disk</b>']);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test('owner: forms need permission to read submissions; whoever changes the routing owns the chat', async () => {
|
|
206
|
+
const c = await connectAndLink();
|
|
207
|
+
user = USERS.e1;
|
|
208
|
+
try {
|
|
209
|
+
assert.equal((await call('PUT', `/chats/${c.id}`, {forms: {on: true, all: true}})).status, 403);
|
|
210
|
+
assert.deepEqual((await call('GET', '/status')).body.forms, [], 'an editor without the Forms permission is offered no forms');
|
|
211
|
+
// An alert change by the editor makes them the owner.
|
|
212
|
+
assert.equal((await call('PUT', `/chats/${c.id}`, {alerts: {on: true, severities: ['critical']}})).body.chats[0].ownerName, 'Ed Editor');
|
|
213
|
+
} finally {
|
|
214
|
+
user = USERS.a1;
|
|
215
|
+
}
|
|
216
|
+
calls = [];
|
|
217
|
+
bus.emit('notification:raised', {id: 'x', data: {title: 'Disk', severity: 'critical', source: 'core:disk'}});
|
|
218
|
+
await settle();
|
|
219
|
+
assert.equal(sent().length, 0, 'an editor is not in the default audience (admins and up)');
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
test('owner: survives a restart between making the code and linking; a staff session never becomes the owner', async () => {
|
|
223
|
+
await call('POST', '/connect', {token: TOKEN, base: BASE});
|
|
224
|
+
const code = (await call('POST', '/link-code', {})).body.linkCode;
|
|
225
|
+
const {getPluginStates} = await import('../../../server/services/plugins.js');
|
|
226
|
+
assert.equal(getPluginStates().telegram.settings.linkOwnerId, 'a1', 'kept with the code, not in memory');
|
|
227
|
+
await hook({chat: {id: -3, type: 'group', title: 'Ops'}, text: `/link ${code}`});
|
|
228
|
+
const c = (await call('GET', '/status')).body.chats[0];
|
|
229
|
+
assert.equal(c.ownerName, 'Ann Admin');
|
|
230
|
+
user = {id: 'dcm-staff', name: 'Dee (staff)', role: 'super-admin', dcmStaff: true};
|
|
231
|
+
try {
|
|
232
|
+
const r = await call('PUT', `/chats/${c.id}`, {alerts: {on: true, severities: ['critical']}});
|
|
233
|
+
assert.equal(r.body.chats[0].ownerName, 'Ann Admin');
|
|
234
|
+
} finally {
|
|
235
|
+
user = USERS.a1;
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test('owner: changing only the alerts leaves the forms another owner chose', async () => {
|
|
240
|
+
const c = await connectAndLink();
|
|
241
|
+
await call('PUT', `/chats/${c.id}`, {forms: {on: true, slugs: ['contact', 'quote']}});
|
|
242
|
+
user = USERS.e1;
|
|
243
|
+
try {
|
|
244
|
+
const r = await call('PUT', `/chats/${c.id}`, {alerts: {on: true, severities: ['critical']}});
|
|
245
|
+
assert.deepEqual(r.body.chats[0].forms.slugs, ['contact', 'quote']);
|
|
246
|
+
} finally {
|
|
247
|
+
user = USERS.a1;
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test('connect: a different bot replaces the old one, whose webhook is deleted', async () => {
|
|
252
|
+
await connectAndLink();
|
|
253
|
+
calls = [];
|
|
254
|
+
webhookUrl = '';
|
|
255
|
+
await call('POST', '/connect', {token: '987654321:BBEabcdefghijklmnopqrstuvwxyz0123456', base: BASE});
|
|
256
|
+
assert.ok(calls.some(c => c.method === 'deleteWebhook'));
|
|
257
|
+
assert.equal((await call('GET', '/status')).body.chats.length, 0, 'the old bot\'s chats are forgotten');
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
test('alerts: routed by severity and source; personal ones never sent; escaped', async () => {
|
|
261
|
+
const c = await connectAndLink();
|
|
262
|
+
calls = [];
|
|
263
|
+
bus.emit('notification:raised', {id: '1', data: {title: 'Disk <low>', body: 'Under 10% & falling', severity: 'warning', source: 'core:disk', sourceLabel: 'System', link: '#/settings'}});
|
|
264
|
+
bus.emit('notification:raised', {id: '2', data: {title: 'FYI', severity: 'info', source: 'core:disk'}});
|
|
265
|
+
bus.emit('notification:raised', {id: '3', data: {title: 'Your to-do', severity: 'critical', source: 'core:todo', audience: {userIds: ['a1']}}});
|
|
266
|
+
await settle();
|
|
267
|
+
assert.equal(sent().length, 1);
|
|
268
|
+
const t = sent()[0].body.text;
|
|
269
|
+
assert.match(t, /⚠️ <b>Disk <low><\/b>/);
|
|
270
|
+
assert.match(t, /Under 10% & falling/);
|
|
271
|
+
assert.match(t, /href="https:\/\/acme\.test\/admin\/#\/settings"/);
|
|
272
|
+
assert.equal(sent()[0].body.parse_mode, 'HTML');
|
|
273
|
+
// Only Invoice from now on.
|
|
274
|
+
await call('PUT', `/chats/${c.id}`, {alerts: {on: true, severities: ['warning', 'critical'], sources: ['invoice']}});
|
|
275
|
+
calls = [];
|
|
276
|
+
bus.emit('notification:raised', {id: '4', data: {title: 'Disk', severity: 'critical', source: 'core:disk'}});
|
|
277
|
+
bus.emit('notification:raised', {id: '5', data: {title: 'Overdue', severity: 'warning', source: 'invoice:overdue'}});
|
|
278
|
+
await settle();
|
|
279
|
+
assert.deepEqual(sent().map(s => s.body.text.split('\n')[0]), ['⚠️ <b>Overdue</b>']);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
test('forms: off until chosen; the answers by default, never a password, file or hidden field; title and link only on request', async () => {
|
|
283
|
+
const c = await connectAndLink();
|
|
284
|
+
const sub = {slug: 'contact', formTitle: 'Contact us', entryId: 'e1', data: {name: 'Ann <b>', email: 'ann@x.test', pin: '1234', cv: {url: '/media/cv.pdf', name: 'cv.pdf'}, ref: 'utm', message: 'Hi', extra: 'stray'}};
|
|
285
|
+
calls = [];
|
|
286
|
+
bus.emit('form:submitted', sub);
|
|
287
|
+
await settle();
|
|
288
|
+
assert.equal(sent().length, 0, 'forms are off for a new chat');
|
|
289
|
+
await call('PUT', `/chats/${c.id}`, {forms: {on: true, slugs: ['contact']}});
|
|
290
|
+
bus.emit('form:submitted', sub);
|
|
291
|
+
bus.emit('form:submitted', {...sub, slug: 'quote', formTitle: 'Quote'});
|
|
292
|
+
await settle();
|
|
293
|
+
assert.equal(sent().length, 1);
|
|
294
|
+
const t = sent()[0].body.text;
|
|
295
|
+
assert.match(t, /New Contact us entry/);
|
|
296
|
+
assert.match(t, /<b>Your name:<\/b> Ann <b>/);
|
|
297
|
+
assert.match(t, /<b>Message:<\/b> Hi/);
|
|
298
|
+
for (const never of ['1234', 'cv.pdf', '/media/', 'utm', 'stray', 'PIN', 'CV']) assert.ok(!t.includes(never), `${never} is never sent`);
|
|
299
|
+
assert.match(t, /href="https:\/\/acme\.test\/admin\/#\/forms\/contact\/submissions"/);
|
|
300
|
+
await call('PUT', `/chats/${c.id}`, {forms: {detail: 'title'}});
|
|
301
|
+
calls = [];
|
|
302
|
+
bus.emit('form:submitted', sub);
|
|
303
|
+
await settle();
|
|
304
|
+
const short = sent()[0].body.text;
|
|
305
|
+
assert.match(short, /New Contact us entry/);
|
|
306
|
+
assert.ok(!short.includes('Ann') && !short.includes('ann@x.test') && !short.includes('Hi'), 'title and link only');
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
test('a paused chat gets nothing; unlink tells the chat and forgets it', async () => {
|
|
310
|
+
const c = await connectAndLink();
|
|
311
|
+
await call('PUT', `/chats/${c.id}`, {paused: true});
|
|
312
|
+
calls = [];
|
|
313
|
+
bus.emit('notification:raised', {id: '1', data: {title: 'Disk', severity: 'critical', source: 'core:disk'}});
|
|
314
|
+
await settle();
|
|
315
|
+
assert.equal(sent().length, 0);
|
|
316
|
+
const r = await call('DELETE', `/chats/${c.id}`);
|
|
317
|
+
assert.equal(r.body.chats.length, 0);
|
|
318
|
+
await settle();
|
|
319
|
+
assert.match(sent().at(-1).body.text, /no longer linked/);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
test('test: hello, sample form, and a real notification through the bell', async () => {
|
|
323
|
+
const c = await connectAndLink();
|
|
324
|
+
calls = [];
|
|
325
|
+
assert.equal((await call('POST', '/test', {chat: c.id, kind: 'hello'})).status, 200);
|
|
326
|
+
assert.equal((await call('POST', '/test', {chat: c.id, kind: 'form', form: 'contact'})).status, 200);
|
|
327
|
+
const form = sent()[1].body.text;
|
|
328
|
+
assert.match(form, /\(Your name\)/);
|
|
329
|
+
assert.ok(!form.includes('(PIN)'));
|
|
330
|
+
calls = [];
|
|
331
|
+
assert.equal((await call('POST', '/test', {kind: 'notification', severity: 'critical'})).status, 200);
|
|
332
|
+
await settle();
|
|
333
|
+
assert.match(sent()[0].body.text, /A test notification from Telegram/);
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
test('Telegram Pro: messages the free Tool does not answer go to the registry; /link never does', async () => {
|
|
337
|
+
await connectAndLink();
|
|
338
|
+
const seen = [];
|
|
339
|
+
const reg = globalThis[Symbol.for('domma.telegram')];
|
|
340
|
+
reg.register('pro', {onMessage: async (msg, ctx) => { seen.push({text: msg.text, linked: ctx.linked?.name || null}); return true; }});
|
|
341
|
+
try {
|
|
342
|
+
await hook({chat: {id: 55, type: 'private', first_name: 'Cust'}, text: 'Do you open Sundays?'});
|
|
343
|
+
await hook({chat: {id: -1001, type: 'supergroup', title: 'Office'}, text: 'reply', reply_to_message: {message_id: 3}});
|
|
344
|
+
await hook({chat: {id: 55, type: 'private'}, text: '/link abc'});
|
|
345
|
+
assert.deepEqual(seen, [{text: 'Do you open Sundays?', linked: null}, {text: 'reply', linked: 'Office'}]);
|
|
346
|
+
assert.equal(typeof reg.services.send, 'function');
|
|
347
|
+
assert.equal(reg.services.botName(), 'acme_bot');
|
|
348
|
+
assert.ok(!JSON.stringify(reg.services.chats()).includes(TOKEN));
|
|
349
|
+
} finally {
|
|
350
|
+
reg.unregister('pro');
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
test('a group upgraded to a supergroup keeps its link', async () => {
|
|
355
|
+
await connectAndLink({id: -5, type: 'group', title: 'Team'});
|
|
356
|
+
await hook({chat: {id: -5, type: 'group'}, migrate_to_chat_id: -1009});
|
|
357
|
+
calls = [];
|
|
358
|
+
bus.emit('notification:raised', {id: '1', data: {title: 'Disk', severity: 'critical', source: 'core:disk'}});
|
|
359
|
+
await settle();
|
|
360
|
+
assert.equal(String(sent()[0].body.chat_id), '-1009');
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
test('disconnect deletes the webhook and forgets the token and chats', async () => {
|
|
364
|
+
await connectAndLink();
|
|
365
|
+
const r = await call('DELETE', '/connection');
|
|
366
|
+
assert.equal(r.body.connected, false);
|
|
367
|
+
assert.equal(r.body.chats.length, 0);
|
|
368
|
+
assert.ok(calls.some(c => c.method === 'deleteWebhook'));
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
test('count: calm total of chats; red when the webhook points elsewhere', async () => {
|
|
372
|
+
await connectAndLink();
|
|
373
|
+
let r = await call('GET', '/count');
|
|
374
|
+
assert.equal(r.body.count, 1);
|
|
375
|
+
assert.equal(r.body.inventory, true);
|
|
376
|
+
webhookUrl = 'https://elsewhere.test/hook';
|
|
377
|
+
// The badge keeps Telegram's answer for 5 minutes; a fresh status read refreshes it.
|
|
378
|
+
await call('GET', '/status');
|
|
379
|
+
r = await call('GET', '/count');
|
|
380
|
+
assert.equal(r.body.tone, 'danger');
|
|
381
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** admin/lib/arrange.js - what the screens show. */
|
|
2
|
+
import {test} from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import {alertsSummary, chatRow, connectionView, formsSummary, routingBody, routingDraft, routingPrint} from '../admin/lib/arrange.js';
|
|
5
|
+
|
|
6
|
+
const SOURCES = [{id: 'invoice:overdue', label: 'Overdue invoices', owner: 'invoice', ownerLabel: 'Invoice'}];
|
|
7
|
+
const FORMS = [{slug: 'contact', title: 'Contact us'}, {slug: 'quote', title: 'Quote'}, {slug: 'job', title: 'Jobs'}];
|
|
8
|
+
|
|
9
|
+
test('summaries', () => {
|
|
10
|
+
assert.equal(alertsSummary({on: true, severities: ['warning', 'critical'], sources: []}), 'Warning and critical alerts from every Tool');
|
|
11
|
+
assert.equal(alertsSummary({on: true, severities: ['info', 'success', 'warning', 'critical'], sources: ['invoice:overdue']}, SOURCES), 'All alerts from Overdue invoices');
|
|
12
|
+
assert.equal(alertsSummary({on: false, severities: ['critical']}), 'No alerts');
|
|
13
|
+
assert.equal(formsSummary({on: true, all: true, detail: 'fields'}), 'Every form, with the answers');
|
|
14
|
+
assert.equal(formsSummary({on: true, all: false, slugs: ['contact'], detail: 'title'}, FORMS), 'Contact us, title and link only');
|
|
15
|
+
assert.equal(formsSummary({on: true, all: false, slugs: ['contact', 'quote', 'job'], detail: 'fields'}, FORMS), '3 forms, with the answers');
|
|
16
|
+
assert.equal(formsSummary({on: true, all: false, slugs: []}), 'No forms');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('chatRow and connectionView', () => {
|
|
20
|
+
const row = chatRow({id: 'c', name: 'Office', type: 'supergroup', alerts: {on: true, severities: ['critical'], sources: []}, forms: {on: false}, lastError: 'Forbidden: bot was kicked'});
|
|
21
|
+
assert.equal(row.type, 'Group');
|
|
22
|
+
assert.equal(row.alerts, 'Critical alerts from every Tool');
|
|
23
|
+
assert.match(row.problem, /bot was kicked/);
|
|
24
|
+
assert.match(row.owner, /No owner/);
|
|
25
|
+
assert.equal(chatRow({id: 'c', name: 'x', ownerName: 'Ann'}).owner, 'Gets what Ann may see');
|
|
26
|
+
const v = connectionView({connected: true, botName: 'acme_bot', chats: [{}, {}], webhook: {ours: false, url: 'https://x'}, can: {manage: true}});
|
|
27
|
+
assert.equal(v.botAt, '@acme_bot');
|
|
28
|
+
assert.equal(v.chats, '2 linked chats');
|
|
29
|
+
assert.match(v.hookError, /somewhere else/);
|
|
30
|
+
assert.equal(connectionView({connected: true, webhook: {ours: true}}).hookError, '');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('the routing panel round-trips, and a fingerprint tells a change', () => {
|
|
34
|
+
const c = {name: 'Office', alerts: {on: true, severities: ['warning'], sources: ['invoice:overdue']}, forms: {on: true, all: false, slugs: ['quote'], detail: 'title'}};
|
|
35
|
+
const d = routingDraft(c, {sources: SOURCES, forms: FORMS});
|
|
36
|
+
assert.equal(d.allSources, false);
|
|
37
|
+
assert.equal(d.forms.quote, true);
|
|
38
|
+
assert.deepEqual(routingBody(d), {name: 'Office', alerts: {on: true, severities: ['warning'], sources: ['invoice:overdue']}, forms: {on: true, all: false, slugs: ['quote'], detail: 'title'}});
|
|
39
|
+
const changed = {...d, severities: {...d.severities, critical: true}};
|
|
40
|
+
assert.notEqual(routingPrint(changed), routingPrint(d));
|
|
41
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/** lib/messages.js - routing, what each message holds, and what is never sent. */
|
|
2
|
+
import {test} from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import {adminLink, alertText, chatsForAlert, chatsForForm, cleanName, cleanRouting, defaultRouting, fieldValue, formText, shownFields, sourceMatches} from '../lib/messages.js';
|
|
5
|
+
|
|
6
|
+
const chat = (over = {}) => ({id: 'c', chatId: '1', name: 'Office', paused: false, ...defaultRouting(), ...over});
|
|
7
|
+
|
|
8
|
+
test('defaults: warning and critical alerts from every Tool, no forms, answers when forms are chosen', () => {
|
|
9
|
+
assert.deepEqual(defaultRouting(), {alerts: {on: true, severities: ['warning', 'critical'], sources: []}, forms: {on: false, all: false, slugs: [], detail: 'fields'}});
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('cleanRouting: whitelists, keeps what a patch leaves out, bounds lists', () => {
|
|
13
|
+
const r = cleanRouting({alerts: {severities: ['critical', 'bogus', 'critical'], sources: ['invoice', 'bad id!']}, forms: {on: true, slugs: ['contact', '../x'], detail: 'everything'}});
|
|
14
|
+
assert.deepEqual(r.alerts, {on: true, severities: ['critical'], sources: ['invoice']});
|
|
15
|
+
assert.deepEqual(r.forms, {on: true, all: false, slugs: ['contact'], detail: 'fields'});
|
|
16
|
+
const kept = cleanRouting({forms: {detail: 'title'}}, r);
|
|
17
|
+
assert.deepEqual(kept.alerts, r.alerts);
|
|
18
|
+
assert.equal(kept.forms.detail, 'title');
|
|
19
|
+
assert.equal(kept.forms.on, true);
|
|
20
|
+
assert.equal(cleanRouting({forms: {slugs: Array.from({length: 500}, (_, i) => `f${i}`)}}).forms.slugs.length, 200);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('sources: empty is all; an owner takes its sources; an id only itself', () => {
|
|
24
|
+
assert.equal(sourceMatches([], 'core:disk'), true);
|
|
25
|
+
assert.equal(sourceMatches(['invoice'], 'invoice:overdue'), true);
|
|
26
|
+
assert.equal(sourceMatches(['invoice:overdue'], 'invoice:paid'), false);
|
|
27
|
+
assert.equal(sourceMatches(['core:disk'], 'core:disk'), true);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('alerts: severity, source, paused, personal', () => {
|
|
31
|
+
const chats = [chat(), chat({id: 'p', paused: true}), chat({id: 'i', alerts: {on: true, severities: ['info'], sources: []}}), chat({id: 'off', alerts: {on: false, severities: ['critical'], sources: []}})];
|
|
32
|
+
const ids = (e) => chatsForAlert(chats, e, {mayHear: () => true}).map(c => c.id);
|
|
33
|
+
assert.deepEqual(ids({data: {title: 'x', severity: 'critical', source: 'core:disk'}}), ['c']);
|
|
34
|
+
assert.deepEqual(ids({data: {title: 'x', severity: 'info', source: 'core:disk'}}), ['i']);
|
|
35
|
+
assert.deepEqual(ids({data: {title: 'x', severity: 'critical', source: 'core:todo', audience: {userIds: ['u']}}}), []);
|
|
36
|
+
assert.deepEqual(ids({data: {title: 'x', severity: 'critical', source: 'core:disk', audience: {roles: ['admin']}}}), ['c']);
|
|
37
|
+
assert.deepEqual(ids({}), []);
|
|
38
|
+
// Without the owner check passing, nothing.
|
|
39
|
+
assert.deepEqual(chatsForAlert(chats, {data: {title: 'x', severity: 'critical', source: 'core:disk'}}), []);
|
|
40
|
+
assert.deepEqual(chatsForAlert(chats, {data: {title: 'x', severity: 'critical', source: 'core:disk'}}, {mayHear: (c) => c.id !== 'c'}), []);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('forms: chosen slugs or all', () => {
|
|
44
|
+
const chats = [chat({id: 'a', forms: {on: true, all: true, slugs: [], detail: 'fields'}}), chat({id: 's', forms: {on: true, all: false, slugs: ['quote'], detail: 'title'}}), chat({id: 'n'})];
|
|
45
|
+
const yes = {mayRead: () => true};
|
|
46
|
+
assert.deepEqual(chatsForForm(chats, 'quote', yes).map(c => c.id), ['a', 's']);
|
|
47
|
+
assert.deepEqual(chatsForForm(chats, 'quote', {mayRead: (c) => c.id === 's'}).map(c => c.id), ['s']);
|
|
48
|
+
assert.deepEqual(chatsForForm(chats, 'quote').map(c => c.id), []);
|
|
49
|
+
assert.deepEqual(chatsForForm(chats, 'contact', yes).map(c => c.id), ['a']);
|
|
50
|
+
assert.deepEqual(chatsForForm(chats, ''), []);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('links: admin routes under the site, web addresses as they are, nothing else', () => {
|
|
54
|
+
assert.equal(adminLink('#/invoices/1', 'https://a.test'), 'https://a.test/admin/#/invoices/1');
|
|
55
|
+
assert.equal(adminLink('https://x.test/p', ''), 'https://x.test/p');
|
|
56
|
+
assert.equal(adminLink('#/x', ''), '');
|
|
57
|
+
assert.equal(adminLink('javascript:alert(1)', 'https://a.test'), '');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('alertText: escaped title and body, the Tool and site, a link', () => {
|
|
61
|
+
const t = alertText({data: {title: '<script>', body: 'a & b', severity: 'critical', sourceLabel: 'Invoice', link: '#/x'}}, {base: 'https://a.test', site: 'Acme "Ltd"'});
|
|
62
|
+
assert.equal(t, '🚨 <b><script></b>\na & b\n<i>Invoice · Acme "Ltd"</i>\n<a href="https://a.test/admin/#/x">Open in the admin</a>');
|
|
63
|
+
assert.ok(alertText({data: {title: 'x', body: 'y'.repeat(9000), severity: 'info'}}).length <= 4000);
|
|
64
|
+
// Escaping grows text up to six times: the limit holds after escaping, and the link survives.
|
|
65
|
+
const q = alertText({data: {title: '"'.repeat(500), body: '"'.repeat(3000), severity: 'info', link: '#/x'}}, {base: 'https://a.test'});
|
|
66
|
+
assert.ok(q.length <= 4000, String(q.length));
|
|
67
|
+
assert.ok(q.endsWith('<a href="https://a.test/admin/#/x">Open in the admin</a>'));
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('fields: the form\'s own fields in order, never secrets, files, images or hidden ones', () => {
|
|
71
|
+
const form = {fields: [
|
|
72
|
+
{name: 'b', label: 'B', type: 'string'}, {name: 'a', label: 'A', type: 'checkbox-group'},
|
|
73
|
+
{name: 'p', label: 'P', type: 'password'}, {name: 'f', label: 'F', type: 'file'}, {name: 'img', label: 'I', type: 'image'},
|
|
74
|
+
{name: 'h', label: 'H', type: 'hidden'}, {name: 'api_token', label: 'T', type: 'string'}, {name: 'ok', label: 'Agree', type: 'checkbox'},
|
|
75
|
+
{name: 'empty', label: 'E', type: 'string'}, {name: 'obj', label: 'O', type: 'string'}
|
|
76
|
+
]};
|
|
77
|
+
const data = {a: ['x', 'y'], b: 'first', p: 'pw', f: {url: '/u', name: 'n'}, img: '/media/a.png', h: 'hid', api_token: 'tok', ok: true, empty: '', obj: {url: '/x'}, stray: 's'};
|
|
78
|
+
assert.deepEqual(shownFields(form, data), [{label: 'B', value: 'first'}, {label: 'A', value: 'x, y'}, {label: 'Agree', value: 'Yes'}]);
|
|
79
|
+
assert.equal(fieldValue(0), '0');
|
|
80
|
+
assert.equal(fieldValue(NaN), '');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('formText: answers, or title and link only; a deleted form sends nothing typed', () => {
|
|
84
|
+
const form = {title: 'Contact', fields: [{name: 'm', label: 'Message', type: 'textarea'}]};
|
|
85
|
+
const sub = {slug: 'contact', formTitle: 'Contact', data: {m: 'Hello <there>'}};
|
|
86
|
+
const full = formText(sub, form, {base: 'https://a.test'});
|
|
87
|
+
assert.match(full, /<b>Message:<\/b> Hello <there>/);
|
|
88
|
+
assert.match(full, /forms\/contact\/submissions/);
|
|
89
|
+
const short = formText(sub, form, {base: 'https://a.test', detail: 'title'});
|
|
90
|
+
assert.ok(!short.includes('Hello'));
|
|
91
|
+
assert.ok(!formText(sub, null, {}).includes('Hello'));
|
|
92
|
+
assert.match(formText({...sub, ended: true}, form), /ended early/);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('formText: a long submission keeps whole answers under the limit, says the rest are in the admin, keeps the link', () => {
|
|
96
|
+
const fields = Array.from({length: 40}, (_, i) => ({name: `f${i}`, label: `Question ${i}`, type: 'textarea'}));
|
|
97
|
+
const data = Object.fromEntries(fields.map(f => [f.name, '<&>"'.repeat(150)]));
|
|
98
|
+
const t = formText({slug: 'long', formTitle: 'Long', data}, {fields}, {base: 'https://a.test'});
|
|
99
|
+
assert.ok(t.length <= 4000, String(t.length));
|
|
100
|
+
assert.match(t, /more answers in the admin/);
|
|
101
|
+
assert.ok(t.endsWith('<a href="https://a.test/admin/#/forms/long/submissions">Open the submissions</a>'));
|
|
102
|
+
// Every answer line is whole: it opens and closes its <b>, and no entity is cut.
|
|
103
|
+
for (const line of t.split('\n').filter(l => l.startsWith('<b>Question'))) assert.match(line, /^<b>Question \d+:<\/b> (<&>")+(…)?$/);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('cleanName', () => {
|
|
107
|
+
assert.equal(cleanName(' Team \n room '), 'Team room');
|
|
108
|
+
assert.equal(cleanName('', 'Office'), 'Office');
|
|
109
|
+
assert.equal(cleanName('x'.repeat(200)).length, 80);
|
|
110
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** lib/queue.js - one message a second per chat, a 429 waited out once, a full queue refused, never a throw. */
|
|
2
|
+
import {test} from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import {createQueue} from '../lib/queue.js';
|
|
5
|
+
|
|
6
|
+
function clock() {
|
|
7
|
+
let t = 0;
|
|
8
|
+
return {now: () => t, sleep: async (ms) => { t += ms; }, get t() { return t; }};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
test('spaces messages to one chat by the gap; other chats are not held up', async () => {
|
|
12
|
+
const c = clock();
|
|
13
|
+
const log = [];
|
|
14
|
+
const q = createQueue({gapMs: 1000, now: c.now, sleep: c.sleep, send: async (chat, text) => { log.push([chat, text, c.t]); return {ok: true}; }});
|
|
15
|
+
await Promise.all([q.push('a', '1'), q.push('a', '2'), q.push('a', '3')]);
|
|
16
|
+
assert.deepEqual(log.map(l => l[2]), [0, 1000, 2000]);
|
|
17
|
+
assert.deepEqual(log.map(l => l[1]), ['1', '2', '3']);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('a 429 is waited out once, then answered', async () => {
|
|
21
|
+
const c = clock();
|
|
22
|
+
let n = 0;
|
|
23
|
+
const q = createQueue({gapMs: 0, now: c.now, sleep: c.sleep, send: async () => (++n === 1 ? {ok: false, error_code: 429, parameters: {retry_after: 3}} : {ok: true})});
|
|
24
|
+
const r = await q.push('a', 'x');
|
|
25
|
+
assert.equal(r.ok, true);
|
|
26
|
+
assert.equal(n, 2);
|
|
27
|
+
assert.equal(c.t, 3000);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('a throwing send is an answer; a full lane refuses more; results are reported', async () => {
|
|
31
|
+
const seen = [];
|
|
32
|
+
let release;
|
|
33
|
+
const gate = new Promise(r => { release = r; });
|
|
34
|
+
const q = createQueue({gapMs: 0, max: 2, onResult: (chat, r) => seen.push(r.ok), send: async (chat, text) => { if (text === 'boom') throw new Error('down'); await gate; return {ok: true}; }});
|
|
35
|
+
const a = q.push('a', 'one');
|
|
36
|
+
const b = q.push('a', 'two');
|
|
37
|
+
const refused = await q.push('a', 'three');
|
|
38
|
+
assert.equal(refused.ok, false);
|
|
39
|
+
assert.match(refused.description, /Too many/);
|
|
40
|
+
assert.equal(q.waiting('a'), 2);
|
|
41
|
+
release();
|
|
42
|
+
await Promise.all([a, b]);
|
|
43
|
+
const boom = await q.push('a', 'boom');
|
|
44
|
+
assert.deepEqual(boom, {ok: false, description: 'down'});
|
|
45
|
+
assert.deepEqual(seen, [true, true, false]);
|
|
46
|
+
assert.equal(q.waiting(), 0);
|
|
47
|
+
});
|
|
@@ -40,6 +40,15 @@ label) load as id = label = name.
|
|
|
40
40
|
- The public theme switcher cannot offer custom themes (the core refuses them there): a visitor can only switch
|
|
41
41
|
between built-in themes. Say so to a site owner who expects their custom theme in the switcher.
|
|
42
42
|
|
|
43
|
+
## Unreleased: New theme from Brand Kit (Brand Kit phase 3)
|
|
44
|
+
|
|
45
|
+
**From Brand Kit** on the Roller bar: `newFromKit()` reads core's public `GET /api/brand-kit` (CMS 1.81.0+; only
|
|
46
|
+
`accent`, `colours`, `fonts.body` are used, so no newer core is needed) and `themeFromKit()` (admin/lib/themes.js, pure,
|
|
47
|
+
tests/themes.test.js) turns it into changes: accent -> `--dm-primary` + hover/active/dark/light shades, `--dm-primary-text`
|
|
48
|
+
/ `-hover-text` (black or white), `--dm-link(-hover)`; colours -> `--dm-accent-1..4`; a body font -> `--dm-font-sans`
|
|
49
|
+
(stack). All through `cleanChanges`. It loads them as a NEW unsaved theme on the current base; the Kit never changes a
|
|
50
|
+
theme (Darryl's decision) - only Save + Content > Theme do.
|
|
51
|
+
|
|
43
52
|
## 1.2.0 (2026-10-15 Tool Upgrade, second pass)
|
|
44
53
|
|
|
45
54
|
- Saved themes: All / In use / Not in use with counts, a search box, and core's skeleton on the first load
|