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,169 +0,0 @@
1
- /**
2
- * Where Booking Pro (and anything else) plugs in, without Booking importing
3
- * it or it importing Booking: a registry on globalThis, the Shopping Cart's
4
- * pattern. Booking owns the data, the screens and the slot engine; an
5
- * extension registers from its `onReady` with any of:
6
- *
7
- * rules(service) -> {capacity?, companions?: string[][], maxPerDay?, waitlist?, online?, recordingAllowed?}
8
- * applied by the free engine (public/lib/slots.js)
9
- * form(service) -> [{id, label, kind, required?, options?, help?}] extra booking-form questions
10
- * answers(service, raw) -> {data, errors} cleans what the form sent (stored as ext.answers)
11
- * check(ctx) -> '' or a reason refuse a booking (ctx: {service, customer, startAt, source, bookings})
12
- * admin: {serviceEditor?, newBooking?, bookingPanel?} module paths under /plugins/<owner>/ - sections in
13
- * Booking's own slideovers (see admin/lib/extension-sections.js)
14
- * waitlistUrl - where the booking page posts "join the waiting list"
15
- * on: {made, moved, cancelled, status} - told after the fact, never waited on
16
- * tabs: [{key, label, icon, module}] - admin screens beside Booking's own
17
- * actions: [{id, icon, title, module}] - banner buttons on Booking's screens (Booking 1.4); the module's
18
- * `run(ctx, prefill)` is called on the click - and for `#/plugins/booking/<id>?...`
19
- * (a deep link from another Tool), with the prefill from the address
20
- *
21
- * Every hook is optional and guarded: one that throws counts as absent, so an
22
- * extension can never stop a booking being made. A lapsed Pro licence means
23
- * Pro never registers and every service is plain again (existing bookings keep
24
- * what they hold).
25
- *
26
- * @module booking/lib/extensions
27
- */
28
-
29
- import {PLAIN} from '../public/lib/slots.js';
30
-
31
- const KEY = Symbol.for('domma.booking');
32
- const safe = (fn, fallback) => { try { const v = fn(); return v === undefined ? fallback : v; } catch { return fallback; } };
33
- const underOwner = (owner, p) => typeof p === 'string' && p.startsWith(`/plugins/${owner}/`);
34
-
35
- export function bookingRegistry() {
36
- if (!globalThis[KEY]) {
37
- const owners = new Map();
38
- globalThis[KEY] = {
39
- // 2: rules, form, answers, check, admin sections, waitlistUrl, services.book / cancel (Booking 1.1).
40
- // 3: rules may say online (+ recordingAllowed): held as a video call (Booking 1.3).
41
- // 4: actions (banner buttons), services.openCall / callLinks, book({contactId, request}) (Booking 1.4).
42
- version: 4,
43
- services: {},
44
- register(owner, ext = {}) {
45
- if (typeof owner !== 'string' || !owner) return false;
46
- owners.set(owner, ext);
47
- return true;
48
- },
49
- unregister(owner) { owners.delete(owner); },
50
- owners: () => [...owners.keys()],
51
-
52
- /**
53
- * The rules for a service, merged over every extension. Companion
54
- * groups come back as bookable objects (active ones only).
55
- */
56
- rules(service, bookables = []) {
57
- const out = {...PLAIN, companions: [], waitlist: false, online: false, recordingAllowed: false};
58
- for (const ext of owners.values()) {
59
- if (typeof ext.rules !== 'function') continue;
60
- const r = safe(() => ext.rules(service), {}) || {};
61
- if (Number(r.capacity) > 1) out.capacity = Math.min(1000, Math.round(Number(r.capacity)));
62
- if (Number(r.maxPerDay) > 0) out.maxPerDay = Math.round(Number(r.maxPerDay));
63
- if (r.waitlist === true) out.waitlist = true;
64
- if (r.online === true) out.online = true;
65
- if (r.recordingAllowed === true) out.recordingAllowed = true;
66
- for (const group of Array.isArray(r.companions) ? r.companions : []) {
67
- const ids = new Set((Array.isArray(group) ? group : []).map(String));
68
- const members = bookables.filter(b => ids.has(b.id) && b.active !== false);
69
- if (members.length) out.companions.push(members);
70
- }
71
- }
72
- return out;
73
- },
74
-
75
- /** Extra questions for the booking form. */
76
- form(service) {
77
- const out = [];
78
- for (const ext of owners.values()) {
79
- if (typeof ext.form !== 'function') continue;
80
- for (const f of safe(() => ext.form(service), []) || []) {
81
- if (f && typeof f.id === 'string' && typeof f.label === 'string') out.push(f);
82
- }
83
- }
84
- return out;
85
- },
86
-
87
- /** Clean the form's answers: {data, errors}. */
88
- answers(service, raw) {
89
- const data = {};
90
- const errors = {};
91
- for (const ext of owners.values()) {
92
- if (typeof ext.answers !== 'function') continue;
93
- const r = safe(() => ext.answers(service, raw || {}), null);
94
- if (r?.data) Object.assign(data, r.data);
95
- if (r?.errors) Object.assign(errors, r.errors);
96
- }
97
- return {data, errors};
98
- },
99
-
100
- /** '' when every extension allows the booking, else the first reason given. */
101
- async check(ctx) {
102
- for (const ext of owners.values()) {
103
- if (typeof ext.check !== 'function') continue;
104
- try {
105
- const why = await ext.check(ctx);
106
- if (typeof why === 'string' && why) return why;
107
- } catch { /* an extension never breaks a booking */ }
108
- }
109
- return '';
110
- },
111
-
112
- /** Where the booking page sends "join the waiting list", or ''. */
113
- waitlistUrl() {
114
- for (const [owner, ext] of owners) {
115
- if (typeof ext.waitlistUrl === 'string' && ext.waitlistUrl.startsWith(`/api/plugins/${owner}/`)) return ext.waitlistUrl;
116
- }
117
- return '';
118
- },
119
-
120
- /** Admin sections extensions add to Booking's slideovers. */
121
- admin() {
122
- const out = [];
123
- for (const [owner, ext] of owners) {
124
- const a = ext.admin || {};
125
- const entry = {owner};
126
- for (const k of ['serviceEditor', 'newBooking', 'bookingPanel']) if (underOwner(owner, a[k])) entry[k] = a[k];
127
- if (Object.keys(entry).length > 1) out.push(entry);
128
- }
129
- return out;
130
- },
131
-
132
- tabs() {
133
- const out = [];
134
- for (const [owner, ext] of owners) {
135
- for (const t of Array.isArray(ext.tabs) ? ext.tabs : []) {
136
- if (typeof t?.key !== 'string' || !underOwner(owner, t.module)) continue;
137
- out.push({key: t.key, label: String(t.label || t.key), icon: String(t.icon || 'puzzle'), module: t.module, owner});
138
- }
139
- }
140
- return out;
141
- },
142
-
143
- /** Banner buttons extensions add to Booking's screens. Ids are unique; the first to claim one keeps it. */
144
- actions() {
145
- const out = [];
146
- // A deep link is #/plugins/booking/<id>: never a screen's own address.
147
- const taken = new Set(['diary', 'bookings', 'services', 'people', 'new', 'settings', ...this.tabs().map(t => t.key)]);
148
- for (const [owner, ext] of owners) {
149
- for (const a of Array.isArray(ext.actions) ? ext.actions : []) {
150
- if (typeof a?.id !== 'string' || !/^[a-z0-9-]{1,40}$/.test(a.id) || taken.has(a.id) || !underOwner(owner, a.module)) continue;
151
- taken.add(a.id);
152
- out.push({id: a.id, title: String(a.title || a.id).slice(0, 80), icon: String(a.icon || 'puzzle'), module: a.module, owner});
153
- }
154
- }
155
- return out;
156
- },
157
-
158
- /** Tell every extension; never throws, never waits. */
159
- emit(event, ...args) {
160
- for (const ext of owners.values()) {
161
- const fn = ext?.on?.[event];
162
- if (typeof fn !== 'function') continue;
163
- try { Promise.resolve(fn(...args)).catch(() => {}); } catch { /* an extension never breaks a booking */ }
164
- }
165
- }
166
- };
167
- }
168
- return globalThis[KEY];
169
- }
@@ -1,113 +0,0 @@
1
- /**
2
- * Booking's emails: one way out, and never a pretend one.
3
- *
4
- * Without an SMTP host the CMS falls back to Ethereal and "succeeds" while
5
- * delivering nothing, so with no SMTP these are simply not sent (`mailReady()`
6
- * says so, and the settings screen shows it). Copied from Waypoint Pro's
7
- * lib/mail.js - plugins cannot import each other.
8
- *
9
- * Tests swap the sender with `setMailer()`.
10
- *
11
- * @module booking/lib/mail
12
- */
13
- import {createTransport, escapeHtml, isSmtpConfigured, sendEmail} from '../../../server/services/email.js';
14
- import {getConfig} from '../../../server/config.js';
15
-
16
- let override = null;
17
- let transport = null;
18
- let transportFor = '';
19
-
20
- /** Tests only: `fn(msg)` receives every message instead. Pass null to restore. */
21
- export function setMailer(fn) { override = fn; }
22
-
23
- const site = () => { try { return getConfig('site') || {}; } catch { return {}; } };
24
-
25
- /** Can mail really leave this site? */
26
- export function mailReady() {
27
- return Boolean(override) || isSmtpConfigured(site().smtp || {});
28
- }
29
-
30
- /** The site's own address, for mail that has nobody better to go to. */
31
- export function siteAddress() {
32
- const s = site();
33
- return s.smtp?.fromAddress || s.contactEmail || '';
34
- }
35
-
36
- export const siteTitle = () => site().title || 'Our site';
37
-
38
- /**
39
- * Send one message. Returns false (and logs) rather than throwing: a lost
40
- * email must never fail the booking that caused it, and callers do not await.
41
- *
42
- * @param {{to: string, subject: string, html: string, text: string, attachments?: object[], replyTo?: string}} msg
43
- */
44
- export async function send(msg, {log} = {}) {
45
- try {
46
- if (!msg?.to) return false;
47
- if (override) { await override(msg); return true; }
48
- const s = site();
49
- const smtp = s.smtp || {};
50
- if (!isSmtpConfigured(smtp)) return false;
51
- const key = JSON.stringify([smtp.host, smtp.port, smtp.user, smtp.secure]);
52
- if (!transport || transportFor !== key) { transport = await createTransport(smtp); transportFor = key; }
53
- await sendEmail(transport, {from: smtp.fromAddress || 'noreply@example.com', fromName: smtp.fromName || s.title || 'Bookings', ...msg});
54
- return true;
55
- } catch (err) {
56
- const line = `[booking] Email to ${msg?.to} not sent: ${err?.message || err}`;
57
- try { if (typeof log?.error === 'function') log.error(line); else console.error(line); } catch { /* never */ }
58
- return false;
59
- }
60
- }
61
-
62
- /**
63
- * A short message: paragraphs, a table of details and an optional button. Everything is escaped.
64
- *
65
- * @param {{subject: string, lines?: string[], details?: [string, string][], link?: string, linkText?: string, after?: string[]}} m
66
- */
67
- export function compose({subject, lines = [], details = [], link = '', linkText = 'Open', after = []}) {
68
- const rows = details.filter(([, v]) => v).map(([k, v]) =>
69
- `<tr><td style="padding:4px 12px 4px 0;color:#666;vertical-align:top">${escapeHtml(k)}</td><td style="padding:4px 0">${escapeHtml(v)}</td></tr>`).join('');
70
- const html = [
71
- ...lines.map(l => `<p>${escapeHtml(l)}</p>`),
72
- rows ? `<table style="border-collapse:collapse;margin:8px 0 16px">${rows}</table>` : '',
73
- link ? `<p><a href="${escapeHtml(link)}" style="display:inline-block;padding:10px 18px;background:#2563eb;color:#fff;border-radius:6px;text-decoration:none">${escapeHtml(linkText)}</a></p>
74
- <p style="color:#666;font-size:13px">Or paste this into your browser: ${escapeHtml(link)}</p>` : '',
75
- ...after.map(l => `<p style="color:#444">${escapeHtml(l)}</p>`)
76
- ].join('\n');
77
- const text = [
78
- ...lines,
79
- details.filter(([, v]) => v).map(([k, v]) => `${k}: ${v}`).join('\n'),
80
- link ? `${linkText}: ${link}` : '',
81
- ...after
82
- ].filter(Boolean).join('\n\n');
83
- return {subject, html, text};
84
- }
85
-
86
- /** RFC 5545 text: escape \ ; , and newlines; fold at 75 octets (approximated by characters). */
87
- const icsText = (s) => String(s ?? '').replace(/\\/g, '\\\\').replace(/;/g, '\\;').replace(/,/g, '\\,').replace(/\r?\n/g, '\\n');
88
- const icsTime = (iso) => new Date(iso).toISOString().replace(/[-:]/g, '').replace(/\.\d{3}/, '');
89
- const fold = (line) => line.length <= 74 ? line : line.match(/.{1,73}/g).join('\r\n ');
90
-
91
- /**
92
- * An .ics for one booking - METHOD:REQUEST adds it, METHOD:CANCEL takes it off.
93
- * The UID is stable per booking, so a move replaces the entry in the customer's calendar.
94
- */
95
- export function icsFor(booking, {host = 'booking', title, location = '', description = '', cancel = false, sequence = 0}) {
96
- const lines = [
97
- 'BEGIN:VCALENDAR', 'VERSION:2.0', 'PRODID:-//Domma CMS//Booking//EN', `METHOD:${cancel ? 'CANCEL' : 'REQUEST'}`,
98
- 'BEGIN:VEVENT',
99
- `UID:booking-${booking.id}@${host}`,
100
- `SEQUENCE:${sequence}`,
101
- `DTSTAMP:${icsTime(new Date().toISOString())}`,
102
- `DTSTART:${icsTime(booking.startAt)}`,
103
- `DTEND:${icsTime(booking.endAt)}`,
104
- `SUMMARY:${icsText(title)}`,
105
- location ? `LOCATION:${icsText(location)}` : '',
106
- description ? `DESCRIPTION:${icsText(description)}` : '',
107
- `STATUS:${cancel ? 'CANCELLED' : 'CONFIRMED'}`,
108
- 'END:VEVENT', 'END:VCALENDAR'
109
- ].filter(Boolean).map(fold);
110
- return lines.join('\r\n') + '\r\n';
111
- }
112
-
113
- export {escapeHtml};