domma-cms 1.36.0 → 1.37.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 (52) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/bin/lib/left-free-tier.js +4 -1
  3. package/bin/update.js +4 -0
  4. package/docs/DommaFeatures.md +8 -6
  5. package/docs/plugin-development.md +2 -2
  6. package/package.json +1 -1
  7. package/plugins/docs/tests/plugin.test.js +2 -0
  8. package/plugins/free-tier.lock.json +2 -50
  9. package/server/services/siteGitignore.js +1 -1
  10. package/plugins/booking/CLAUDE.md +0 -204
  11. package/plugins/booking/admin/css/index.css +0 -192
  12. package/plugins/booking/admin/lib/details.js +0 -58
  13. package/plugins/booking/admin/lib/diary-layout.js +0 -158
  14. package/plugins/booking/admin/lib/drafts.js +0 -139
  15. package/plugins/booking/admin/lib/email.js +0 -191
  16. package/plugins/booking/admin/lib/extension-sections.js +0 -160
  17. package/plugins/booking/admin/lib/kit.js +0 -471
  18. package/plugins/booking/admin/templates/booking.html +0 -1
  19. package/plugins/booking/admin/views/booking.js +0 -216
  20. package/plugins/booking/admin/views/bookings.js +0 -132
  21. package/plugins/booking/admin/views/diary.js +0 -382
  22. package/plugins/booking/admin/views/panels.js +0 -603
  23. package/plugins/booking/admin/views/people.js +0 -318
  24. package/plugins/booking/admin/views/services.js +0 -264
  25. package/plugins/booking/admin/views/settings.js +0 -222
  26. package/plugins/booking/collections/booking-bookables.json +0 -17
  27. package/plugins/booking/collections/booking-bookings.json +0 -18
  28. package/plugins/booking/collections/booking-services.json +0 -17
  29. package/plugins/booking/config.js +0 -36
  30. package/plugins/booking/docs/guide.md +0 -73
  31. package/plugins/booking/inject/body.html +0 -1
  32. package/plugins/booking/lib/call.js +0 -88
  33. package/plugins/booking/lib/extensions.js +0 -169
  34. package/plugins/booking/lib/mail.js +0 -113
  35. package/plugins/booking/lib/store.js +0 -392
  36. package/plugins/booking/plugin.js +0 -905
  37. package/plugins/booking/plugin.json +0 -81
  38. package/plugins/booking/plugin.public.js +0 -175
  39. package/plugins/booking/public/booking.css +0 -159
  40. package/plugins/booking/public/booking.js +0 -808
  41. package/plugins/booking/public/lib/clean.js +0 -141
  42. package/plugins/booking/public/lib/page-format.js +0 -121
  43. package/plugins/booking/public/lib/slots.js +0 -247
  44. package/plugins/booking/public/lib/time.js +0 -131
  45. package/plugins/booking/templates/booking.html +0 -5
  46. package/plugins/booking/tests/admin-diary.test.js +0 -81
  47. package/plugins/booking/tests/admin-drafts.test.js +0 -67
  48. package/plugins/booking/tests/api.test.js +0 -651
  49. package/plugins/booking/tests/email.test.js +0 -69
  50. package/plugins/booking/tests/public.test.js +0 -72
  51. package/plugins/booking/tests/pure.test.js +0 -189
  52. package/plugins/booking/tests/seo.test.js +0 -71
@@ -1,191 +0,0 @@
1
- /**
2
- * Email someone from this Tool: Email Pro's compose window when the user can
3
- * send from it, otherwise the device's mail program through `mailto:`.
4
- *
5
- * Core makes the choice (`/admin/js/lib/mail-compose.js`, CMS 1.6.61+). It is
6
- * imported at RUN time, never statically, so this Tool still loads on an older
7
- * core - where every action keeps the plain `mailto:` it always had.
8
- *
9
- * `emailTo()` is for menu actions; `routeMailLinks()` is for a visible
10
- * `<a href="mailto:…">` - the link stays a link (copy, hover, middle-click all
11
- * still work) and a plain click goes the same way as the menu action.
12
- *
13
- * @module booking/admin/lib/email
14
- */
15
-
16
- const CORE = '/admin/js/lib/mail-compose.js';
17
- let core = null;
18
-
19
- /** The core module, or null on a core without it. Asked once. */
20
- const loadCore = () => (core ??= import(CORE).catch(() => null));
21
-
22
- /** Longest subject or body carried (as core's). */
23
- const MAX_TEXT = 2000;
24
- /** Longest mailto: handed to the device - mail programs cut or refuse longer ones. */
25
- const MAX_MAILTO = 1800;
26
-
27
- /**
28
- * Something that can only be an email address: one @, no spaces or line
29
- * breaks, nothing that would start another recipient or a query.
30
- *
31
- * @param {*} value
32
- * @returns {boolean}
33
- */
34
- export function looksLikeAddress(value) {
35
- return typeof value === 'string' && /^[^\s@<>,;"?&]+@[^\s@<>,;"?&]+$/.test(value);
36
- }
37
-
38
- /** Valid addresses only, once each (ignoring case), from a string, `{address}`/`{email}`, or a list. */
39
- function addressesOf(list) {
40
- const seen = new Set();
41
- return (Array.isArray(list) ? list : list == null ? [] : [list])
42
- .map(x => String(typeof x === 'string' ? x : (x?.address ?? x?.email ?? '')).trim())
43
- .filter(a => looksLikeAddress(a) && !seen.has(a.toLowerCase()) && seen.add(a.toLowerCase()));
44
- }
45
-
46
- /** Trim and cap; a subject loses its line breaks (they would be a header). */
47
- function cleanText(value, {oneLine = false} = {}) {
48
- let text = String(value ?? '');
49
- if (oneLine) text = text.replace(/[\r\n]+/g, ' ');
50
- return text.slice(0, MAX_TEXT).trim();
51
- }
52
-
53
- /**
54
- * The request as a `mailto:` link (the fallback on an older core).
55
- *
56
- * @param {{to?: *, cc?: *, bcc?: *, subject?: string, body?: string}} request
57
- * @returns {string}
58
- */
59
- export function mailtoHref({to, cc, bcc, subject, body} = {}) {
60
- const enc = (list) => addressesOf(list).map(a => encodeURIComponent(a).replace(/%40/g, '@')).join(',');
61
- const s = cleanText(subject, {oneLine: true});
62
- const b = cleanText(body);
63
- const query = [];
64
- if (enc(cc)) query.push(`cc=${enc(cc)}`);
65
- if (enc(bcc)) query.push(`bcc=${enc(bcc)}`);
66
- if (s) query.push(`subject=${encodeURIComponent(s)}`);
67
- if (b) query.push(`body=${encodeURIComponent(b)}`);
68
- return `mailto:${enc(to)}${query.length ? `?${query.join('&')}` : ''}`;
69
- }
70
-
71
- /** Copy text: the clipboard, else the old copy command, else a box to copy it from by hand. */
72
- async function copyText(text) {
73
- try {
74
- await navigator.clipboard.writeText(text);
75
- return true;
76
- } catch { /* next */ }
77
- const box = document.createElement('textarea');
78
- box.className = 'form-input';
79
- box.readOnly = true;
80
- box.rows = 6;
81
- box.value = text;
82
- try {
83
- box.style.position = 'fixed';
84
- box.style.opacity = '0';
85
- document.body.appendChild(box);
86
- box.select();
87
- if (document.execCommand('copy')) return true;
88
- } catch { /* next */ } finally {
89
- box.remove();
90
- box.style.position = '';
91
- box.style.opacity = '';
92
- }
93
- const modal = E.modal({title: 'Copy the addresses', size: 'medium', buttons: [{id: 'close', text: 'Close', variant: 'secondary'}]});
94
- modal.element.appendChild(box); // light DOM: setContent would strip the textarea
95
- modal.open();
96
- box.select();
97
- return false;
98
- }
99
-
100
- /**
101
- * Hand the request to the device's mail program - unless the link would be
102
- * too long for it, when the addresses are copied instead and the toast says
103
- * what did not go.
104
- */
105
- async function openMailto(request) {
106
- const href = mailtoHref(request);
107
- if (href.length <= MAX_MAILTO) {
108
- location.href = href;
109
- return 'mailto';
110
- }
111
- const all = addressesOf([...addressesOf(request.to), ...addressesOf(request.cc), ...addressesOf(request.bcc)]);
112
- const copied = all.length ? await copyText(all.join(', ')) : false;
113
- const lost = [cleanText(request.subject) && 'the subject', cleanText(request.body) && 'the message'].filter(Boolean);
114
- E.toast(`Too long for your mail program to open. ${all.length
115
- ? `${copied ? 'The' : 'Copy the'} ${all.length} address${all.length === 1 ? '' : 'es'}${copied ? ' are copied' : ''} - paste them into Bcc of a new email.` : ''}${lost.length ? ` Not carried over: ${lost.join(' and ')}.` : ''}`,
116
- {type: 'warning', duration: 9000});
117
- return 'copied';
118
- }
119
-
120
- const decode = (s) => { try { return decodeURIComponent(s); } catch { return s; } };
121
-
122
- /**
123
- * A `mailto:` link read back into a request (what a visible link carries).
124
- * When the address part holds anything that is not an address, the query
125
- * is ignored: an address stored as `me@x.com?body=…` must not prefill a message.
126
- *
127
- * @param {string} href
128
- * @returns {null|{to: string[], cc: string[], bcc: string[], subject: string, body: string}}
129
- */
130
- export function parseMailto(href) {
131
- const m = String(href ?? '').match(/^mailto:([^?]*)(?:\?(.*))?$/i);
132
- if (!m) return null;
133
- const split = (s) => decode(s || '').split(/[,;]/).map(x => x.trim()).filter(Boolean);
134
- const named = split(m[1]);
135
- const out = {to: addressesOf(named), cc: [], bcc: [], subject: '', body: ''};
136
- if (named.some(a => !looksLikeAddress(a))) return out;
137
- for (const pair of (m[2] || '').split('&')) {
138
- const i = pair.indexOf('=');
139
- if (i < 1) continue;
140
- const key = pair.slice(0, i).toLowerCase();
141
- const value = pair.slice(i + 1);
142
- if (key === 'to') out.to = addressesOf([...out.to, ...split(value)]);
143
- else if (key === 'cc' || key === 'bcc') out[key] = addressesOf([...out[key], ...split(value)]);
144
- else if (key === 'subject') out.subject = cleanText(decode(value), {oneLine: true});
145
- else if (key === 'body') out.body = cleanText(decode(value));
146
- }
147
- return out;
148
- }
149
-
150
- /**
151
- * Email someone. Recipients are `{name, address}`, `{name, email}` or bare
152
- * addresses; several people belong in `bcc`, so nobody sees the others.
153
- * With nobody to address (a link to pass on) compose still opens, To empty.
154
- *
155
- * @param {{to?: *, cc?: *, bcc?: *, subject?: string, body?: string}} request
156
- * @returns {Promise<'compose'|'mailto'|'copied'|'none'>}
157
- */
158
- export async function emailTo(request = {}) {
159
- const mail = await loadCore();
160
- if (!mail) return openMailto(request);
161
- const r = mail.composeRequest(request);
162
- if (r.to.length || r.cc.length || r.bcc.length) return mail.openEmail(r);
163
- if (await mail.emailReady()) {
164
- location.hash = mail.composeHash(r);
165
- return 'compose';
166
- }
167
- location.href = mail.mailtoHref(r);
168
- return 'mailto';
169
- }
170
-
171
- /**
172
- * Send plain clicks on the `mailto:` links inside `root` through `emailTo()`.
173
- * A modified click (new tab/window) or one already handled is left alone.
174
- *
175
- * @param {Element} root
176
- * @returns {() => void} removes the listener
177
- */
178
- export function routeMailLinks(root) {
179
- if (!root) return () => {};
180
- const onClick = (e) => {
181
- if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
182
- const a = e.target?.closest?.('a[href^="mailto:" i]');
183
- if (!a || !root.contains(a)) return;
184
- const request = parseMailto(a.getAttribute('href'));
185
- if (!request) return;
186
- e.preventDefault();
187
- emailTo(request);
188
- };
189
- root.addEventListener('click', onClick);
190
- return () => root.removeEventListener('click', onClick);
191
- }
@@ -1,160 +0,0 @@
1
- /**
2
- * Sections other Tools add to Booking's own slideovers - the host.
3
- *
4
- * THE CONTRACT (Booking 1.1; Booking Pro is the first to use it)
5
- *
6
- * GET /api/plugins/booking/bootstrap returns
7
- * `sections: [{owner, serviceEditor?, newBooking?, bookingPanel?}]`
8
- * - module paths under /plugins/<owner>/, from what an extension registered
9
- * (Booking's lib/extensions.js `admin`).
10
- *
11
- * Each module exports `async mount(el, ctx)` and returns an object with any of:
12
- * values() serviceEditor: the owner's settings for the service - saved as
13
- * `service.ext[owner]`. newBooking: `{answers?, ext?}` - the host sends
14
- * `body.answers` (merged over every section) and `body.ext[owner]`.
15
- * validate() '' when all is well, else a message; the host shows it and does not save.
16
- * after(booking) newBooking only: awaited after the booking is made (a failure is
17
- * toasted; the booking stays made).
18
- * dirty() true when the section holds changes (the slideover asks before closing).
19
- * destroy() called when the slideover closes.
20
- *
21
- * ctx = {
22
- * kind: 'serviceEditor' | 'newBooking' | 'bookingPanel',
23
- * owner,
24
- * service, serviceEditor: the service being edited (null when new);
25
- * newBooking: the service picked so far (null when none)
26
- * onServiceChange(fn) newBooking: fn(service|null) whenever the pick changes
27
- * booking, bookingPanel: the booking shown
28
- * bookables, services, settings,
29
- * api: {request(method, path, body), get(path), post(path, body), put(path, body), delete(path)}
30
- * the admin's request helper; paths are under /api - e.g. '/plugins/booking-pro/series'.
31
- * A failure throws with `status` and `body` (the server's answer).
32
- * kit, the admin's tool-kit (openMenuAt, onceClosed, helpPopovers, ...)
33
- * helpPopovers(el), wire the help popovers (data-help="...") inside el (returns the teardown)
34
- * onChange(), mark the slideover as changed
35
- * refresh() bookingPanel: reopen the booking with fresh data
36
- * }
37
- *
38
- * The host puts one bordered `<section class="bk-ext" data-owner="...">` per
39
- * extension after Booking's own fields. A module that fails to load or mount
40
- * leaves a short muted note - never a broken slideover.
41
- *
42
- * @module booking/admin/lib/extension-sections
43
- */
44
-
45
- import {loadKit, request} from './kit.js';
46
-
47
- const say = (el, text) => {
48
- el.innerHTML = '';
49
- const p = document.createElement('p');
50
- p.className = 'bk-note';
51
- p.textContent = text;
52
- el.appendChild(p);
53
- };
54
-
55
- export const sectionApi = {
56
- request,
57
- get: (p) => request('GET', p),
58
- post: (p, b) => request('POST', p, b ?? {}),
59
- put: (p, b) => request('PUT', p, b ?? {}),
60
- delete: (p) => request('DELETE', p)
61
- };
62
-
63
- /**
64
- * Mount every extension's section of one kind into `box`.
65
- *
66
- * @param {HTMLElement} box
67
- * @param {'serviceEditor'|'newBooking'|'bookingPanel'} kind
68
- * @param {object} opts - {boot, service?, booking?, onChange?, refresh?}
69
- * @returns {Promise<{ready: Promise<void>, validate(): string, values(): Object<string, object>, answers(): object, extFor(): object,
70
- * after(booking): Promise<void>, dirty(): boolean, serviceChanged(service): void, destroy(): void}>}
71
- */
72
- export function mountSections(box, kind, {boot, service = null, booking = null, onChange = () => {}, refresh = () => {}}) {
73
- const mounted = []; // {owner, api}
74
- const listeners = [];
75
- let gone = false;
76
- const entries = (boot?.sections || []).filter(s => s && typeof s[kind] === 'string' && s[kind].startsWith(`/plugins/${s.owner}/`));
77
-
78
- const ready = (async () => {
79
- if (!entries.length) return;
80
- const kit = await loadKit();
81
- for (const entry of entries) {
82
- if (gone) return;
83
- const el = document.createElement('section');
84
- el.className = 'bk-ext';
85
- el.dataset.owner = entry.owner;
86
- box.appendChild(el);
87
- const ctx = {
88
- kind, owner: entry.owner, service, booking,
89
- onServiceChange: (fn) => { if (typeof fn === 'function') listeners.push(fn); },
90
- bookables: boot.bookables, services: boot.services, settings: boot.settings,
91
- api: sectionApi, kit, helpPopovers: (el2) => kit.helpPopovers(el2), onChange, refresh
92
- };
93
- try {
94
- const mod = await import(entry[kind]);
95
- if (gone) return;
96
- const mount = mod.mount || mod.default?.mount;
97
- if (typeof mount !== 'function') throw new Error('no mount()');
98
- const api = (await mount(el, ctx)) || {};
99
- if (gone) { try { api.destroy?.(); } catch { /* never */ } return; }
100
- mounted.push({owner: entry.owner, api});
101
- window.I?.scan?.(el);
102
- } catch (err) {
103
- console.warn(`[booking] ${entry.owner} section (${kind}) could not load:`, err);
104
- say(el, `This part (from ${entry.owner}) could not be loaded just now.`);
105
- }
106
- }
107
- })();
108
-
109
- const call = (m, name, ...args) => { try { return m.api[name]?.(...args); } catch (err) { console.warn(`[booking] ${m.owner}.${name}:`, err); return undefined; } };
110
-
111
- return {
112
- ready,
113
- /** The first problem any section reports, or ''. */
114
- validate() {
115
- for (const m of mounted) {
116
- const why = call(m, 'validate');
117
- if (typeof why === 'string' && why) return why;
118
- }
119
- return '';
120
- },
121
- /** {owner: values()} for every section that gives any. */
122
- values() {
123
- const out = {};
124
- for (const m of mounted) {
125
- const v = call(m, 'values');
126
- if (v && typeof v === 'object') out[m.owner] = v;
127
- }
128
- return out;
129
- },
130
- /** newBooking: every section's answers, merged. */
131
- answers() {
132
- const out = {};
133
- for (const v of Object.values(this.values())) if (v.answers && typeof v.answers === 'object') Object.assign(out, v.answers);
134
- return out;
135
- },
136
- /** newBooking: {owner: ext} for body.ext. */
137
- extFor() {
138
- const out = {};
139
- for (const [owner, v] of Object.entries(this.values())) if (v.ext && typeof v.ext === 'object') out[owner] = v.ext;
140
- return out;
141
- },
142
- async after(b) {
143
- for (const m of mounted) {
144
- if (typeof m.api.after !== 'function') continue;
145
- try { await m.api.after(b); } catch (err) {
146
- E.toast(`Booked, but ${m.owner} could not finish: ${err?.message || err}`, {type: 'warning', duration: 8000});
147
- }
148
- }
149
- },
150
- dirty: () => mounted.some(m => call(m, 'dirty') === true),
151
- serviceChanged(svc) {
152
- for (const fn of listeners) { try { fn(svc || null); } catch (err) { console.warn('[booking] onServiceChange:', err); } }
153
- },
154
- destroy() {
155
- gone = true;
156
- for (const m of mounted) call(m, 'destroy');
157
- mounted.length = 0;
158
- }
159
- };
160
- }