@profitstudio/booking-engine 0.0.0-stage → 2.0.0-beta.1
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 +562 -0
- package/LICENSE +21 -0
- package/README.md +18 -2
- package/THIRD_PARTY_NOTICES.md +41 -0
- package/bin/booking-engine.mjs +575 -0
- package/bin/connect.mjs +408 -0
- package/bin/photos.mjs +82 -0
- package/dist/admin/BookingAdmin.d.ts +22 -0
- package/dist/admin/BookingAdmin.js +337 -0
- package/dist/admin/admin.css +1423 -0
- package/dist/admin/alerts.d.ts +10 -0
- package/dist/admin/alerts.js +11 -0
- package/dist/admin/booking-detail.d.ts +37 -0
- package/dist/admin/booking-detail.js +149 -0
- package/dist/admin/content-inputs.d.ts +15 -0
- package/dist/admin/content-inputs.js +105 -0
- package/dist/admin/context.d.ts +37 -0
- package/dist/admin/context.js +8 -0
- package/dist/admin/drawer.d.ts +14 -0
- package/dist/admin/drawer.js +56 -0
- package/dist/admin/feedback.d.ts +32 -0
- package/dist/admin/feedback.js +70 -0
- package/dist/admin/fields.d.ts +27 -0
- package/dist/admin/fields.js +146 -0
- package/dist/admin/fonts/OFL-Geist-Mono.txt +93 -0
- package/dist/admin/fonts/OFL-Geist.txt +93 -0
- package/dist/admin/fonts/geist-latin-wght-normal.woff2 +0 -0
- package/dist/admin/fonts/geist-mono-latin-wght-normal.woff2 +0 -0
- package/dist/admin/icons.d.ts +66 -0
- package/dist/admin/icons.js +72 -0
- package/dist/admin/image-upload.d.ts +58 -0
- package/dist/admin/image-upload.js +111 -0
- package/dist/admin/index.d.ts +6 -0
- package/dist/admin/index.js +6 -0
- package/dist/admin/lucide.generated.d.ts +521 -0
- package/dist/admin/lucide.generated.js +76 -0
- package/dist/admin/sections/BookingsSection.d.ts +1 -0
- package/dist/admin/sections/BookingsSection.js +137 -0
- package/dist/admin/sections/EmailSection.d.ts +8 -0
- package/dist/admin/sections/EmailSection.js +182 -0
- package/dist/admin/sections/HoursSection.d.ts +1 -0
- package/dist/admin/sections/HoursSection.js +110 -0
- package/dist/admin/sections/OverviewSection.d.ts +1 -0
- package/dist/admin/sections/OverviewSection.js +427 -0
- package/dist/admin/sections/ServicesSection.d.ts +1 -0
- package/dist/admin/sections/ServicesSection.js +236 -0
- package/dist/admin/sections/SettingsSection.d.ts +10 -0
- package/dist/admin/sections/SettingsSection.js +96 -0
- package/dist/admin/sections/WebsiteSection.d.ts +1 -0
- package/dist/admin/sections/WebsiteSection.js +228 -0
- package/dist/admin/sections.d.ts +22 -0
- package/dist/admin/sections.js +29 -0
- package/dist/admin/setup.d.ts +1 -0
- package/dist/admin/setup.js +45 -0
- package/dist/admin/today.d.ts +43 -0
- package/dist/admin/today.js +115 -0
- package/dist/admin/ui.d.ts +134 -0
- package/dist/admin/ui.js +220 -0
- package/dist/calendar.d.ts +64 -0
- package/dist/calendar.js +139 -0
- package/dist/client.d.ts +147 -0
- package/dist/client.js +507 -0
- package/dist/config.d.ts +25 -0
- package/dist/config.js +120 -0
- package/dist/content/image.d.ts +20 -0
- package/dist/content/image.js +90 -0
- package/dist/content/resolve.d.ts +12 -0
- package/dist/content/resolve.js +73 -0
- package/dist/content/schema.d.ts +119 -0
- package/dist/content/schema.js +53 -0
- package/dist/content/store.d.ts +48 -0
- package/dist/content/store.js +123 -0
- package/dist/content/validate.d.ts +33 -0
- package/dist/content/validate.js +177 -0
- package/dist/errors.d.ts +19 -0
- package/dist/errors.js +94 -0
- package/dist/generated/manifest.d.ts +6 -0
- package/dist/generated/manifest.js +7 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +20 -0
- package/dist/presets/hair-salon.d.ts +8 -0
- package/dist/presets/hair-salon.js +94 -0
- package/dist/presets/index.d.ts +5 -0
- package/dist/presets/index.js +6 -0
- package/dist/preview.d.ts +18 -0
- package/dist/preview.js +134 -0
- package/dist/semver.d.ts +16 -0
- package/dist/semver.js +55 -0
- package/dist/time.d.ts +31 -0
- package/dist/time.js +138 -0
- package/dist/types.d.ts +477 -0
- package/dist/types.js +3 -0
- package/dist/vite.d.ts +52 -0
- package/dist/vite.js +150 -0
- package/docs/BUILD-A-SITE.md +203 -0
- package/docs/EMAIL-SETUP.md +224 -0
- package/docs/INTEGRATION.md +1109 -0
- package/engine.manifest.json +90 -0
- package/functions/booking-mailer/deno.json +6 -0
- package/functions/booking-mailer/index.ts +44 -0
- package/functions/booking-mailer/mailer.js +156 -0
- package/functions/booking-mailer/providers/index.js +42 -0
- package/functions/booking-mailer/providers/resend.js +75 -0
- package/functions/booking-mailer/templates.js +345 -0
- package/migrations/0001_core.sql +1673 -0
- package/migrations/0002_security_hardening.sql +711 -0
- package/migrations/0003_private_definers_and_holds.sql +808 -0
- package/migrations/0004_verified_requests.sql +1702 -0
- package/migrations/0005_scoped_mailer_credential.sql +347 -0
- package/migrations/0006_trusted_client_ip.sql +56 -0
- package/migrations/0007_site_content.sql +380 -0
- package/migrations/0008_service_images_opening_times.sql +328 -0
- package/package.json +85 -4
- package/templates/BOOKING_ENGINE.md +61 -0
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
// booking-mailer — the essential booking emails (plain text + simple HTML).
|
|
2
|
+
// ENGINE-OWNED FILE (installed by `booking-engine init` / `sync`). Do not edit.
|
|
3
|
+
//
|
|
4
|
+
// Rendering is a pure function of the queued payload: a retried email is
|
|
5
|
+
// byte-identical to the first attempt (required by idempotent delivery).
|
|
6
|
+
// Dates use the business time zone and locale; wording is English.
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {{ kind: string, payload: Record<string, any> }} mail
|
|
10
|
+
* @param {{ adminUrl?: string }} [options]
|
|
11
|
+
* @returns {{ subject: string, text: string, html: string, replyTo?: string }}
|
|
12
|
+
*/
|
|
13
|
+
export function renderEmail(mail, options = {}) {
|
|
14
|
+
const p = mail.payload ?? {};
|
|
15
|
+
const render = KINDS[mail.kind];
|
|
16
|
+
if (!render) throw new Error(`Unknown email kind "${mail.kind}"`);
|
|
17
|
+
const business = clean(p.businessName) || 'Our team';
|
|
18
|
+
const view = render(p, { business, adminUrl: options.adminUrl });
|
|
19
|
+
const contact = [clean(p.address), clean(p.businessPhone), clean(p.businessEmail)].filter(Boolean);
|
|
20
|
+
return {
|
|
21
|
+
subject: oneLine(view.subject),
|
|
22
|
+
text: [view.text.join('\n\n'), contact.length ? `—\n${business}\n${contact.join('\n')}` : `—\n${business}`].join('\n\n') + '\n',
|
|
23
|
+
html: layout({ business, preheader: view.preheader, blocks: view.html, contact }),
|
|
24
|
+
replyTo: view.replyTo ?? (clean(p.businessEmail) || undefined),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// ------------------------------------------------------------- the emails --
|
|
29
|
+
|
|
30
|
+
const KINDS = {
|
|
31
|
+
verification_code(p, { business }) {
|
|
32
|
+
const code = String(p.code ?? '');
|
|
33
|
+
const when = formatWhen(p.startsAt, p);
|
|
34
|
+
const minutes = Number(p.minutesValid) || 15;
|
|
35
|
+
return {
|
|
36
|
+
subject: `${code} is your booking code for ${business}`,
|
|
37
|
+
preheader: `Enter it to send your request for ${clean(p.serviceName)}.`,
|
|
38
|
+
text: [
|
|
39
|
+
`Your booking code for ${business}:`,
|
|
40
|
+
` ${code}`,
|
|
41
|
+
`Enter it on the booking page to send your request for ${clean(p.serviceName)} on ${when}.`,
|
|
42
|
+
`The code works for ${minutes} minutes, and the time is held for you until then.`,
|
|
43
|
+
`Didn't ask for this? Ignore this email. Nothing is booked without the code.`,
|
|
44
|
+
],
|
|
45
|
+
html: [
|
|
46
|
+
para(`Your booking code for ${esc(business)}:`),
|
|
47
|
+
codeBox(code),
|
|
48
|
+
para(`Enter it on the booking page to send your request for <strong>${esc(clean(p.serviceName))}</strong> on ${esc(when)}.`),
|
|
49
|
+
para(`The code works for ${minutes} minutes, and the time is held for you until then.`),
|
|
50
|
+
muted(`Didn’t ask for this? Ignore this email. Nothing is booked without the code.`),
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
request_received(p, { business }) {
|
|
56
|
+
const by = p.holdExpiresAt ? ` by ${formatWhen(p.holdExpiresAt, p)}` : '';
|
|
57
|
+
return {
|
|
58
|
+
subject: `Request received: ${clean(p.serviceName)}, ${formatShort(p.startsAt, p)}`,
|
|
59
|
+
preheader: `Not confirmed yet. ${business} will reply${by}.`,
|
|
60
|
+
text: [
|
|
61
|
+
greeting(p),
|
|
62
|
+
`${business} has received your booking request. It is NOT confirmed yet.`,
|
|
63
|
+
detailsText(p),
|
|
64
|
+
`${business} will confirm or decline it${by}. You will get another email either way.`,
|
|
65
|
+
],
|
|
66
|
+
html: [
|
|
67
|
+
para(esc(greeting(p))),
|
|
68
|
+
para(`${esc(business)} has received your booking request. <strong>It is not confirmed yet.</strong>`),
|
|
69
|
+
detailsHtml(p),
|
|
70
|
+
para(`${esc(business)} will confirm or decline it${esc(by)}. You will get another email either way.`),
|
|
71
|
+
],
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
booking_confirmed(p, { business }) {
|
|
76
|
+
return {
|
|
77
|
+
subject: `Confirmed: ${clean(p.serviceName)}, ${formatShort(p.startsAt, p)}`,
|
|
78
|
+
preheader: `Your appointment with ${business} is confirmed.`,
|
|
79
|
+
text: [
|
|
80
|
+
greeting(p),
|
|
81
|
+
`Your appointment with ${business} is confirmed.`,
|
|
82
|
+
detailsText(p),
|
|
83
|
+
`Need to change or cancel it? ${reach(p, business)}.`,
|
|
84
|
+
],
|
|
85
|
+
html: [
|
|
86
|
+
para(esc(greeting(p))),
|
|
87
|
+
para(`<strong>Your appointment with ${esc(business)} is confirmed.</strong>`),
|
|
88
|
+
detailsHtml(p),
|
|
89
|
+
para(`Need to change or cancel it? ${esc(reach(p, business))}.`),
|
|
90
|
+
],
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
booking_declined(p, { business }) {
|
|
95
|
+
return {
|
|
96
|
+
subject: `Not available: your request for ${formatShort(p.startsAt, p)}`,
|
|
97
|
+
preheader: `${business} could not accept this request. Nothing is booked.`,
|
|
98
|
+
text: [
|
|
99
|
+
greeting(p),
|
|
100
|
+
`Sorry, ${business} could not accept your request for ${clean(p.serviceName)} on ${formatWhen(p.startsAt, p)}. Nothing is booked.`,
|
|
101
|
+
`You are welcome to choose another time on the website${orReach(p, business)}.`,
|
|
102
|
+
],
|
|
103
|
+
html: [
|
|
104
|
+
para(esc(greeting(p))),
|
|
105
|
+
para(`Sorry, ${esc(business)} could not accept your request for <strong>${esc(clean(p.serviceName))}</strong> on ${esc(formatWhen(p.startsAt, p))}. Nothing is booked.`),
|
|
106
|
+
para(`You are welcome to choose another time on the website${esc(orReach(p, business))}.`),
|
|
107
|
+
],
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
booking_cancelled(p, { business }) {
|
|
112
|
+
return {
|
|
113
|
+
subject: `Cancelled: ${clean(p.serviceName)}, ${formatShort(p.startsAt, p)}`,
|
|
114
|
+
preheader: `${business} cancelled this appointment.`,
|
|
115
|
+
text: [
|
|
116
|
+
greeting(p),
|
|
117
|
+
`${business} has cancelled your appointment for ${clean(p.serviceName)} on ${formatWhen(p.startsAt, p)} (reference ${clean(p.reference)}).`,
|
|
118
|
+
`If this is unexpected, ${lower(reach(p, business))}.`,
|
|
119
|
+
],
|
|
120
|
+
html: [
|
|
121
|
+
para(esc(greeting(p))),
|
|
122
|
+
para(`${esc(business)} has cancelled your appointment for <strong>${esc(clean(p.serviceName))}</strong> on ${esc(formatWhen(p.startsAt, p))} (reference ${esc(clean(p.reference))}).`),
|
|
123
|
+
para(`If this is unexpected, ${esc(lower(reach(p, business)))}.`),
|
|
124
|
+
],
|
|
125
|
+
};
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
request_expired(p, { business }) {
|
|
129
|
+
return {
|
|
130
|
+
subject: `Your request for ${formatShort(p.startsAt, p)} has expired`,
|
|
131
|
+
preheader: `It was not confirmed in time. Nothing is booked.`,
|
|
132
|
+
text: [
|
|
133
|
+
greeting(p),
|
|
134
|
+
`Your request for ${clean(p.serviceName)} on ${formatWhen(p.startsAt, p)} was not confirmed in time, so it has expired. Nothing is booked.`,
|
|
135
|
+
`The time may still be free: you can book again on the website${orReach(p, business)}.`,
|
|
136
|
+
],
|
|
137
|
+
html: [
|
|
138
|
+
para(esc(greeting(p))),
|
|
139
|
+
para(`Your request for <strong>${esc(clean(p.serviceName))}</strong> on ${esc(formatWhen(p.startsAt, p))} was not confirmed in time, so it has expired. Nothing is booked.`),
|
|
140
|
+
para(`The time may still be free: you can book again on the website${esc(orReach(p, business))}.`),
|
|
141
|
+
],
|
|
142
|
+
};
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
owner_new_request(p, { adminUrl }) {
|
|
146
|
+
const name = clean(p.customerName) || 'A customer';
|
|
147
|
+
const confirmed = p.status === 'confirmed';
|
|
148
|
+
const by = p.holdExpiresAt ? ` by ${formatWhen(p.holdExpiresAt, p)}` : '';
|
|
149
|
+
const lead = confirmed
|
|
150
|
+
? `${name} booked ${clean(p.serviceName)}. It was confirmed automatically (instant confirmation is on).`
|
|
151
|
+
: `${name} requested ${clean(p.serviceName)} and verified their email address. Please confirm or decline${by}; after that the time is released.`;
|
|
152
|
+
const customer = [
|
|
153
|
+
['Name', clean(p.customerName)],
|
|
154
|
+
['Email', clean(p.customerEmail)],
|
|
155
|
+
['Phone', clean(p.customerPhone)],
|
|
156
|
+
['Notes', clean(p.notes, 1000)],
|
|
157
|
+
].filter(([, v]) => v);
|
|
158
|
+
const link = safeUrl(adminUrl);
|
|
159
|
+
return {
|
|
160
|
+
subject: `${confirmed ? 'New booking' : 'New booking request'}: ${name}, ${formatShort(p.startsAt, p)}`,
|
|
161
|
+
preheader: confirmed ? 'Confirmed automatically.' : 'Needs your confirmation.',
|
|
162
|
+
replyTo: clean(p.customerEmail) || undefined,
|
|
163
|
+
text: [
|
|
164
|
+
lead,
|
|
165
|
+
detailsText(p),
|
|
166
|
+
customer.map(([k, v]) => `${k}: ${v}`).join('\n'),
|
|
167
|
+
link ? `Open your dashboard: ${link}` : 'Open your booking dashboard to manage it.',
|
|
168
|
+
`Reply to this email to write to the customer.`,
|
|
169
|
+
],
|
|
170
|
+
html: [
|
|
171
|
+
para(esc(lead)),
|
|
172
|
+
detailsHtml(p),
|
|
173
|
+
table(customer),
|
|
174
|
+
link ? button(link, 'Open your dashboard') : para('Open your booking dashboard to manage it.'),
|
|
175
|
+
muted('Reply to this email to write to the customer.'),
|
|
176
|
+
],
|
|
177
|
+
};
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
test(p, { business }) {
|
|
181
|
+
return {
|
|
182
|
+
subject: `Test email from your booking system`,
|
|
183
|
+
preheader: `Email sending works.`,
|
|
184
|
+
text: [
|
|
185
|
+
`This is a test email from the booking system of ${business}.`,
|
|
186
|
+
`Email sending works: customers will receive their booking codes and updates from this address.`,
|
|
187
|
+
],
|
|
188
|
+
html: [
|
|
189
|
+
para(`This is a test email from the booking system of <strong>${esc(business)}</strong>.`),
|
|
190
|
+
para(`Email sending works: customers will receive their booking codes and updates from this address.`),
|
|
191
|
+
],
|
|
192
|
+
};
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
// ------------------------------------------------------------- formatting --
|
|
197
|
+
|
|
198
|
+
// Replies reach the business only when it has a public email (it becomes the
|
|
199
|
+
// Reply-To); otherwise customers are pointed to the phone, never to the
|
|
200
|
+
// unattended sending address.
|
|
201
|
+
function reach(p, business) {
|
|
202
|
+
if (clean(p.businessEmail)) return `Reply to this email or contact ${business}`;
|
|
203
|
+
const phone = clean(p.businessPhone);
|
|
204
|
+
return phone ? `Call ${business} on ${phone}` : `Contact ${business}`;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function orReach(p, business) {
|
|
208
|
+
if (clean(p.businessEmail)) return ', or reply to this email';
|
|
209
|
+
const phone = clean(p.businessPhone);
|
|
210
|
+
return phone ? `, or call ${business} on ${phone}` : '';
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const lower = (s) => s.charAt(0).toLowerCase() + s.slice(1);
|
|
214
|
+
|
|
215
|
+
function greeting(p) {
|
|
216
|
+
const name = clean(p.customerName);
|
|
217
|
+
return name ? `Hi ${name.split(/\s+/)[0]},` : 'Hello,';
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function details(p) {
|
|
221
|
+
const rows = [
|
|
222
|
+
['Service', clean(p.serviceName)],
|
|
223
|
+
['When', formatWhen(p.startsAt, p)],
|
|
224
|
+
['Reference', clean(p.reference)],
|
|
225
|
+
];
|
|
226
|
+
const price = formatPrice(p.priceCents, p.currency, p.locale);
|
|
227
|
+
if (price) rows.push(['Price', price]);
|
|
228
|
+
if (clean(p.address)) rows.push(['Where', clean(p.address)]);
|
|
229
|
+
return rows;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const detailsText = (p) => details(p).map(([k, v]) => `${k}: ${v}`).join('\n');
|
|
233
|
+
const detailsHtml = (p) => table(details(p));
|
|
234
|
+
|
|
235
|
+
function intl(locale, options) {
|
|
236
|
+
try {
|
|
237
|
+
return new Intl.DateTimeFormat(locale || 'en-US', options);
|
|
238
|
+
} catch {
|
|
239
|
+
return new Intl.DateTimeFormat('en-US', { ...options, timeZone: 'UTC' });
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export function formatWhen(iso, p) {
|
|
244
|
+
if (!iso) return '';
|
|
245
|
+
return intl(p.locale, {
|
|
246
|
+
timeZone: p.timezone || 'UTC',
|
|
247
|
+
weekday: 'long',
|
|
248
|
+
day: 'numeric',
|
|
249
|
+
month: 'long',
|
|
250
|
+
year: 'numeric',
|
|
251
|
+
hour: 'numeric',
|
|
252
|
+
minute: '2-digit',
|
|
253
|
+
}).format(new Date(iso));
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function formatShort(iso, p) {
|
|
257
|
+
if (!iso) return '';
|
|
258
|
+
return intl(p.locale, {
|
|
259
|
+
timeZone: p.timezone || 'UTC',
|
|
260
|
+
weekday: 'short',
|
|
261
|
+
day: 'numeric',
|
|
262
|
+
month: 'short',
|
|
263
|
+
hour: 'numeric',
|
|
264
|
+
minute: '2-digit',
|
|
265
|
+
}).format(new Date(iso));
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function formatPrice(cents, currency, locale) {
|
|
269
|
+
if (typeof cents !== 'number' || !currency) return '';
|
|
270
|
+
try {
|
|
271
|
+
return new Intl.NumberFormat(locale || 'en-US', { style: 'currency', currency }).format(cents / 100);
|
|
272
|
+
} catch {
|
|
273
|
+
return `${(cents / 100).toFixed(2)} ${currency}`;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** Plain text from the payload: no control characters, bounded length. */
|
|
278
|
+
function clean(value, max = 200) {
|
|
279
|
+
if (value === null || value === undefined) return '';
|
|
280
|
+
return String(value).replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/g, '').trim().slice(0, max);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const oneLine = (s) => s.replace(/\s+/g, ' ').trim().slice(0, 200);
|
|
284
|
+
|
|
285
|
+
function esc(s) {
|
|
286
|
+
return String(s)
|
|
287
|
+
.replace(/&/g, '&')
|
|
288
|
+
.replace(/</g, '<')
|
|
289
|
+
.replace(/>/g, '>')
|
|
290
|
+
.replace(/"/g, '"')
|
|
291
|
+
.replace(/'/g, ''');
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function safeUrl(url) {
|
|
295
|
+
if (!url) return '';
|
|
296
|
+
try {
|
|
297
|
+
const u = new URL(url);
|
|
298
|
+
const local = u.hostname === 'localhost' || u.hostname === '127.0.0.1';
|
|
299
|
+
return u.protocol === 'https:' || (local && u.protocol === 'http:') ? u.toString() : '';
|
|
300
|
+
} catch {
|
|
301
|
+
return '';
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// ------------------------------------------------------------------- HTML --
|
|
306
|
+
|
|
307
|
+
const FONT = "font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif";
|
|
308
|
+
|
|
309
|
+
const para = (html) => `<p style="margin:0 0 16px;font-size:16px;line-height:1.5;color:#1f2328">${html}</p>`;
|
|
310
|
+
const muted = (html) => `<p style="margin:0 0 16px;font-size:14px;line-height:1.5;color:#59636e">${html}</p>`;
|
|
311
|
+
|
|
312
|
+
function codeBox(code) {
|
|
313
|
+
return `<p style="margin:8px 0 24px;font-size:32px;font-weight:700;letter-spacing:6px;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;color:#1f2328">${esc(code)}</p>`;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function table(rows) {
|
|
317
|
+
if (!rows.length) return '';
|
|
318
|
+
const tr = rows
|
|
319
|
+
.map(
|
|
320
|
+
([k, v]) =>
|
|
321
|
+
`<tr><td style="padding:6px 16px 6px 0;font-size:14px;color:#59636e;vertical-align:top;white-space:nowrap">${esc(k)}</td>` +
|
|
322
|
+
`<td style="padding:6px 0;font-size:15px;color:#1f2328;vertical-align:top">${esc(v).replace(/\n/g, '<br>')}</td></tr>`,
|
|
323
|
+
)
|
|
324
|
+
.join('');
|
|
325
|
+
return `<table role="presentation" cellpadding="0" cellspacing="0" style="margin:0 0 20px;border-collapse:collapse">${tr}</table>`;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function button(href, label) {
|
|
329
|
+
return `<p style="margin:0 0 20px"><a href="${esc(href)}" style="display:inline-block;padding:10px 18px;border-radius:6px;background:#1f2328;color:#ffffff;text-decoration:none;font-size:15px">${esc(label)}</a></p>`;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function layout({ business, preheader, blocks, contact }) {
|
|
333
|
+
return [
|
|
334
|
+
'<!doctype html>',
|
|
335
|
+
'<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"></head>',
|
|
336
|
+
`<body style="margin:0;padding:0;background:#f6f8fa;${FONT}">`,
|
|
337
|
+
`<div style="display:none;max-height:0;overflow:hidden">${esc(preheader ?? '')}</div>`,
|
|
338
|
+
'<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#f6f8fa"><tr><td align="center" style="padding:24px 12px">',
|
|
339
|
+
'<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="max-width:560px;background:#ffffff;border:1px solid #d1d9e0;border-radius:8px">',
|
|
340
|
+
`<tr><td style="padding:24px 28px 8px;font-size:18px;font-weight:600;color:#1f2328;${FONT}">${esc(business)}</td></tr>`,
|
|
341
|
+
`<tr><td style="padding:8px 28px 12px;${FONT}">${blocks.filter(Boolean).join('')}</td></tr>`,
|
|
342
|
+
`<tr><td style="padding:16px 28px 24px;border-top:1px solid #d1d9e0;font-size:13px;line-height:1.5;color:#59636e;${FONT}">${[business, ...contact].map(esc).join('<br>')}</td></tr>`,
|
|
343
|
+
'</table></td></tr></table></body></html>',
|
|
344
|
+
].join('');
|
|
345
|
+
}
|