@profitstudio/booking-engine 0.0.0-stage → 2.0.0-beta.2
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 +578 -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 +29 -0
- package/dist/admin/BookingAdmin.js +338 -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 +47 -0
- package/dist/admin/booking-detail.js +159 -0
- package/dist/admin/content-inputs.d.ts +15 -0
- package/dist/admin/content-inputs.js +105 -0
- package/dist/admin/context.d.ts +41 -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 +7 -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 +184 -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 +1112 -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
package/dist/client.js
ADDED
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
import { createClient } from '@supabase/supabase-js';
|
|
2
|
+
import { BACKEND_ENV, decodeJwtRole } from './config.js';
|
|
3
|
+
import { engineError, fail, mapRemoteError, ok } from './errors.js';
|
|
4
|
+
import { ENGINE_PACKAGE, ENGINE_VERSION, REQUIRED_SCHEMA_VERSION, SCHEMA_VERSION } from './generated/manifest.js';
|
|
5
|
+
import { createPreviewData } from './preview.js';
|
|
6
|
+
import { compareVersions, isSchemaCompatible } from './semver.js';
|
|
7
|
+
import { ImageProblem, prepareSiteImage } from './content/image.js';
|
|
8
|
+
/** Website content needs this database schema (migration 0007); older ones keep booking. */
|
|
9
|
+
export const SITE_CONTENT_SCHEMA = '2.0.0-alpha.7';
|
|
10
|
+
/** Service images and opening times need this database schema (migration 0008); older ones keep everything else. */
|
|
11
|
+
export const SERVICE_MEDIA_SCHEMA = '2.0.0-alpha.10';
|
|
12
|
+
/** The Supabase Storage bucket for website images (and, under services/, service photos). */
|
|
13
|
+
export const SITE_MEDIA_BUCKET = 'booking-site-media';
|
|
14
|
+
const SITE_MEDIA_PATH = /^site\/[a-z0-9][a-z0-9._-]{0,120}$/;
|
|
15
|
+
const SERVICE_MEDIA_PATH = /^services\/[a-z0-9][a-z0-9._-]{0,120}$/;
|
|
16
|
+
const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
17
|
+
/** Refuse privileged keys in a website: they bypass Row Level Security. */
|
|
18
|
+
export function assertPublishableKey(key) {
|
|
19
|
+
if (!key)
|
|
20
|
+
return;
|
|
21
|
+
if (key.startsWith('sb_secret_') || decodeJwtRole(key) === 'service_role') {
|
|
22
|
+
throw new Error('Booking Engine: a Supabase SECRET (service_role) key was given to the website. ' +
|
|
23
|
+
'Use the publishable key (sb_publishable_…) and rotate the exposed secret key in the Supabase dashboard.');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const EMAIL_RE = /^[^@\s<>()]+@[^@\s<>()]+\.[^@\s<>()]{2,}$/;
|
|
27
|
+
const PHONE_RE = /^[0-9+()./\s-]+$/;
|
|
28
|
+
// eslint-disable-next-line no-control-regex
|
|
29
|
+
const CONTROL_RE = /[\u0000-\u001f\u007f]/;
|
|
30
|
+
// eslint-disable-next-line no-control-regex
|
|
31
|
+
const NOTES_CONTROL_RE = /[\u0001-\u0008\u000b\u000c\u000e-\u001f\u007f]/;
|
|
32
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
33
|
+
/** The same field rules the server enforces, checked first so forms get instant feedback. */
|
|
34
|
+
function checkRequest(request) {
|
|
35
|
+
const name = request?.customer?.name?.trim() ?? '';
|
|
36
|
+
const email = request?.customer?.email?.trim() ?? '';
|
|
37
|
+
const phone = request?.customer?.phone?.trim() || null;
|
|
38
|
+
const notes = request?.notes?.trim() || null;
|
|
39
|
+
if (!request?.serviceId)
|
|
40
|
+
return { ok: false, field: 'serviceId' };
|
|
41
|
+
if (!request.startsAt)
|
|
42
|
+
return { ok: false, field: 'startsAt' };
|
|
43
|
+
if (!name || name.length > 120 || CONTROL_RE.test(name))
|
|
44
|
+
return { ok: false, field: 'customer.name' };
|
|
45
|
+
if (email.length > 254 || !EMAIL_RE.test(email))
|
|
46
|
+
return { ok: false, field: 'customer.email' };
|
|
47
|
+
if (phone && (phone.length > 40 || !PHONE_RE.test(phone) || phone.replace(/\D/g, '').length < 5)) {
|
|
48
|
+
return { ok: false, field: 'customer.phone' };
|
|
49
|
+
}
|
|
50
|
+
if (notes && (notes.length > 1000 || NOTES_CONTROL_RE.test(notes)))
|
|
51
|
+
return { ok: false, field: 'notes' };
|
|
52
|
+
return { ok: true, name, email, phone, notes };
|
|
53
|
+
}
|
|
54
|
+
/** The database answers verification outcomes as data (so counted attempts persist). */
|
|
55
|
+
const VERIFY_OUTCOMES = {
|
|
56
|
+
invalid_code: 'INVALID_CODE',
|
|
57
|
+
expired: 'CODE_EXPIRED',
|
|
58
|
+
locked: 'TOO_MANY_ATTEMPTS',
|
|
59
|
+
slot_unavailable: 'SLOT_UNAVAILABLE',
|
|
60
|
+
too_many_bookings: 'TOO_MANY_BOOKINGS',
|
|
61
|
+
};
|
|
62
|
+
export function createBookingEngine(options = {}) {
|
|
63
|
+
assertPublishableKey(options.supabaseKey);
|
|
64
|
+
const url = options.supabaseUrl?.trim() || null;
|
|
65
|
+
const key = options.supabaseKey?.trim() || null;
|
|
66
|
+
if (!options.supabase && Boolean(url) !== Boolean(key)) {
|
|
67
|
+
// Half a connection is never intended: say so instead of quietly showing preview or "not available".
|
|
68
|
+
console.warn(`Booking Engine: ${url ? BACKEND_ENV.url : BACKEND_ENV.key} is set but ${url ? BACKEND_ENV.key : BACKEND_ENV.url} is empty, ` +
|
|
69
|
+
'so the website is not connected to Supabase. Set both (then restart the dev server or rebuild).');
|
|
70
|
+
}
|
|
71
|
+
let client = options.supabase ?? null;
|
|
72
|
+
if (!client && url && key) {
|
|
73
|
+
client = createClient(url, key, {
|
|
74
|
+
auth: { persistSession: true, autoRefreshToken: true, storageKey: 'booking-engine-auth' },
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
const mode = client ? 'live' : options.preview && options.allowPreview ? 'preview' : 'unconfigured';
|
|
78
|
+
const preview = mode === 'preview' && options.preview ? createPreviewData(options.preview) : null;
|
|
79
|
+
let compat = null;
|
|
80
|
+
async function fetchInfo() {
|
|
81
|
+
try {
|
|
82
|
+
const { data, error } = await client.rpc('booking_engine_info');
|
|
83
|
+
if (error)
|
|
84
|
+
return { ok: false, error: mapRemoteError(error) };
|
|
85
|
+
const schemaVersion = String(data?.schemaVersion ?? '');
|
|
86
|
+
return ok({
|
|
87
|
+
engine: ENGINE_PACKAGE,
|
|
88
|
+
packageVersion: ENGINE_VERSION,
|
|
89
|
+
schemaVersion,
|
|
90
|
+
requiredSchemaVersion: REQUIRED_SCHEMA_VERSION,
|
|
91
|
+
mode,
|
|
92
|
+
compatible: isSchemaCompatible(schemaVersion, REQUIRED_SCHEMA_VERSION),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return fail('NETWORK');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function ensureCompatible() {
|
|
100
|
+
if (!compat) {
|
|
101
|
+
compat = fetchInfo().then((result) => {
|
|
102
|
+
if (!result.ok && result.error.code === 'NETWORK')
|
|
103
|
+
compat = null; // retry next time
|
|
104
|
+
return result;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return compat;
|
|
108
|
+
}
|
|
109
|
+
async function call(fn, args) {
|
|
110
|
+
if (!client)
|
|
111
|
+
return fail(mode === 'preview' ? 'PREVIEW_MODE' : 'NOT_CONFIGURED');
|
|
112
|
+
const info = await ensureCompatible();
|
|
113
|
+
if (!info.ok)
|
|
114
|
+
return info;
|
|
115
|
+
if (!info.data.compatible) {
|
|
116
|
+
return fail('SCHEMA_INCOMPATIBLE', undefined, `The booking database is at schema ${info.data.schemaVersion || 'unknown'}; this website needs ` +
|
|
117
|
+
`${REQUIRED_SCHEMA_VERSION} or a newer ${REQUIRED_SCHEMA_VERSION.split('.')[0]}.x schema.`);
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
const { data, error } = await client.rpc(fn, args);
|
|
121
|
+
if (error)
|
|
122
|
+
return { ok: false, error: mapRemoteError(error) };
|
|
123
|
+
return ok(data);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return fail('NETWORK');
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const notLive = () => Promise.resolve(fail(mode === 'preview' ? 'PREVIEW_MODE' : 'NOT_CONFIGURED'));
|
|
130
|
+
/** A feature newer than the database fails clearly ("… needs"), and nothing else is affected. */
|
|
131
|
+
async function needsSchema(minimum, feature) {
|
|
132
|
+
const info = await ensureCompatible();
|
|
133
|
+
if (info.ok && compareVersions(info.data.schemaVersion || '0.0.0', minimum) < 0) {
|
|
134
|
+
return fail('SCHEMA_INCOMPATIBLE', undefined, `${feature} database schema ${minimum} or newer (found ${info.data.schemaVersion || 'unknown'}): ` +
|
|
135
|
+
'run npx booking-engine sync, then npx supabase@2 db push.');
|
|
136
|
+
}
|
|
137
|
+
return ok(null);
|
|
138
|
+
}
|
|
139
|
+
/** Content calls need schema 0007; on an older database they fail clearly (booking is unaffected). */
|
|
140
|
+
async function contentCall(fn, args) {
|
|
141
|
+
if (!client)
|
|
142
|
+
return fail(mode === 'preview' ? 'PREVIEW_MODE' : 'NOT_CONFIGURED');
|
|
143
|
+
const gate = await needsSchema(SITE_CONTENT_SCHEMA, 'Website content needs');
|
|
144
|
+
if (!gate.ok)
|
|
145
|
+
return gate;
|
|
146
|
+
return call(fn, args);
|
|
147
|
+
}
|
|
148
|
+
/** A stored service photo with its public URL; null when absent or not a services/ file. */
|
|
149
|
+
function toServiceImage(raw) {
|
|
150
|
+
if (!client || !raw || typeof raw !== 'object')
|
|
151
|
+
return null;
|
|
152
|
+
const value = raw;
|
|
153
|
+
if (typeof value.path !== 'string' || !SERVICE_MEDIA_PATH.test(value.path) || value.path.includes('..'))
|
|
154
|
+
return null;
|
|
155
|
+
const size = (n) => (typeof n === 'number' && Number.isInteger(n) && n > 0 ? n : null);
|
|
156
|
+
return {
|
|
157
|
+
url: client.storage.from(SITE_MEDIA_BUCKET).getPublicUrl(value.path).data.publicUrl,
|
|
158
|
+
path: value.path,
|
|
159
|
+
alt: typeof value.alt === 'string' ? value.alt : '',
|
|
160
|
+
width: size(value.width),
|
|
161
|
+
height: size(value.height),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const withImage = (service) => ({ ...service, image: toServiceImage(service.image) });
|
|
165
|
+
/** What saveService sends for a photo: path, then alt/width/height only when they hold something. */
|
|
166
|
+
function imageInput(image) {
|
|
167
|
+
if (typeof image !== 'object' || typeof image.path !== 'string' || !SERVICE_MEDIA_PATH.test(image.path))
|
|
168
|
+
return null;
|
|
169
|
+
const out = { path: image.path };
|
|
170
|
+
const alt = typeof image.alt === 'string' ? image.alt.replace(/\s+/g, ' ').trim() : '';
|
|
171
|
+
if (alt)
|
|
172
|
+
out.alt = alt;
|
|
173
|
+
for (const key of ['width', 'height']) {
|
|
174
|
+
const n = image[key];
|
|
175
|
+
if (typeof n === 'number' && Number.isInteger(n) && n > 0)
|
|
176
|
+
out[key] = n;
|
|
177
|
+
}
|
|
178
|
+
return out;
|
|
179
|
+
}
|
|
180
|
+
// Media: one bucket, two folders. site/ belongs to the website editor (which
|
|
181
|
+
// tidies what its content no longer uses); services/ to service photos.
|
|
182
|
+
async function uploadMedia(folder, file) {
|
|
183
|
+
if (!client)
|
|
184
|
+
return notLive();
|
|
185
|
+
let prepared;
|
|
186
|
+
try {
|
|
187
|
+
prepared = await prepareSiteImage(file);
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
return fail('INVALID_INPUT', 'file', error instanceof ImageProblem ? error.message : 'This image could not be read.');
|
|
191
|
+
}
|
|
192
|
+
const path = `${folder}/${globalThis.crypto.randomUUID()}.${prepared.extension}`;
|
|
193
|
+
try {
|
|
194
|
+
const { error } = await client.storage.from(SITE_MEDIA_BUCKET).upload(path, prepared.blob, {
|
|
195
|
+
contentType: prepared.type,
|
|
196
|
+
cacheControl: '31536000',
|
|
197
|
+
upsert: false,
|
|
198
|
+
});
|
|
199
|
+
if (error)
|
|
200
|
+
return storageError(error);
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
return fail('NETWORK');
|
|
204
|
+
}
|
|
205
|
+
return ok({ path, width: prepared.width, height: prepared.height });
|
|
206
|
+
}
|
|
207
|
+
async function listMedia(folder) {
|
|
208
|
+
if (!client)
|
|
209
|
+
return notLive();
|
|
210
|
+
try {
|
|
211
|
+
const { data, error } = await client.storage.from(SITE_MEDIA_BUCKET).list(folder, { limit: 1000 });
|
|
212
|
+
if (error)
|
|
213
|
+
return storageError(error);
|
|
214
|
+
return ok((data ?? []).filter((f) => f.id).map((f) => ({ path: `${folder}/${f.name}`, createdAt: f.created_at ?? null })));
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
return fail('NETWORK');
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
async function deleteMedia(pattern, paths) {
|
|
221
|
+
if (!client)
|
|
222
|
+
return notLive();
|
|
223
|
+
const safe = paths.filter((p) => pattern.test(p) && !p.includes('..'));
|
|
224
|
+
if (!safe.length)
|
|
225
|
+
return ok({ deleted: 0 });
|
|
226
|
+
try {
|
|
227
|
+
const { data, error } = await client.storage.from(SITE_MEDIA_BUCKET).remove(safe);
|
|
228
|
+
if (error)
|
|
229
|
+
return storageError(error);
|
|
230
|
+
return ok({ deleted: data?.length ?? 0 });
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
return fail('NETWORK');
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const storageError = (error) => {
|
|
237
|
+
const status = Number(error?.statusCode ?? 0);
|
|
238
|
+
const message = error?.message ?? '';
|
|
239
|
+
if (status === 401 || status === 403 || /row-level security|unauthorized/i.test(message))
|
|
240
|
+
return fail('NOT_AUTHORIZED');
|
|
241
|
+
if (status === 413 || /size|too large/i.test(message))
|
|
242
|
+
return fail('INVALID_INPUT', 'file', 'Images can be up to 5 MB.');
|
|
243
|
+
if (/mime|type/i.test(message))
|
|
244
|
+
return fail('INVALID_INPUT', 'file', 'Use a JPEG, PNG, WebP or AVIF image.');
|
|
245
|
+
return fail('UNKNOWN', undefined, message || 'The image could not be saved.');
|
|
246
|
+
};
|
|
247
|
+
const auth = {
|
|
248
|
+
async signIn(email, password) {
|
|
249
|
+
if (!client)
|
|
250
|
+
return fail('NOT_CONFIGURED');
|
|
251
|
+
try {
|
|
252
|
+
const { data, error } = await client.auth.signInWithPassword({ email: email.trim(), password });
|
|
253
|
+
if (error) {
|
|
254
|
+
const status = error.status ?? 0;
|
|
255
|
+
if (status === 429)
|
|
256
|
+
return fail('RATE_LIMITED');
|
|
257
|
+
if (!status || status >= 500)
|
|
258
|
+
return fail('NETWORK');
|
|
259
|
+
return fail('NOT_AUTHORIZED', undefined, 'Email or password is incorrect.');
|
|
260
|
+
}
|
|
261
|
+
return ok({ email: data.user?.email ?? email.trim() });
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
return fail('NETWORK');
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
async signOut() {
|
|
268
|
+
if (!client)
|
|
269
|
+
return fail('NOT_CONFIGURED');
|
|
270
|
+
const { error } = await client.auth.signOut();
|
|
271
|
+
return error ? fail('NETWORK') : ok(null);
|
|
272
|
+
},
|
|
273
|
+
async getUserEmail() {
|
|
274
|
+
if (!client)
|
|
275
|
+
return null;
|
|
276
|
+
const { data } = await client.auth.getSession();
|
|
277
|
+
return data.session?.user?.email ?? null;
|
|
278
|
+
},
|
|
279
|
+
onChange(callback) {
|
|
280
|
+
if (!client)
|
|
281
|
+
return () => { };
|
|
282
|
+
const { data } = client.auth.onAuthStateChange((_event, session) => callback(Boolean(session)));
|
|
283
|
+
return () => data.subscription.unsubscribe();
|
|
284
|
+
},
|
|
285
|
+
};
|
|
286
|
+
const live = mode === 'live';
|
|
287
|
+
const admin = {
|
|
288
|
+
whoami: () => (live ? call('booking_admin_whoami') : notLive()),
|
|
289
|
+
listBookings: (q) => live ? call('booking_admin_list_bookings', { p_from: q.from, p_to: q.to, p_statuses: q.statuses ?? null }) : notLive(),
|
|
290
|
+
setBookingStatus: (id, status) => live ? call('booking_admin_set_booking_status', { p_booking_id: id, p_status: status }) : notLive(),
|
|
291
|
+
async listServices() {
|
|
292
|
+
if (!live)
|
|
293
|
+
return notLive();
|
|
294
|
+
const result = await call('booking_admin_list_services');
|
|
295
|
+
return result.ok ? ok(result.data.map(withImage)) : result;
|
|
296
|
+
},
|
|
297
|
+
async saveService(input) {
|
|
298
|
+
if (!live)
|
|
299
|
+
return notLive();
|
|
300
|
+
const payload = { ...input };
|
|
301
|
+
delete payload.image;
|
|
302
|
+
if (input && input.image !== undefined) {
|
|
303
|
+
const gate = await needsSchema(SERVICE_MEDIA_SCHEMA, 'Service photos need');
|
|
304
|
+
if (!gate.ok)
|
|
305
|
+
return gate;
|
|
306
|
+
if (input.image === null)
|
|
307
|
+
payload.image = null;
|
|
308
|
+
else {
|
|
309
|
+
const image = imageInput(input.image);
|
|
310
|
+
if (!image)
|
|
311
|
+
return fail('INVALID_INPUT', 'image');
|
|
312
|
+
payload.image = image;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
const result = await call('booking_admin_save_service', { p_service: payload });
|
|
316
|
+
return result.ok ? ok(withImage(result.data)) : result;
|
|
317
|
+
},
|
|
318
|
+
deleteService: (id) => (live ? call('booking_admin_delete_service', { p_service_id: id }) : notLive()),
|
|
319
|
+
getWorkingHours: () => (live ? call('booking_admin_get_working_hours') : notLive()),
|
|
320
|
+
setWorkingHours: (hours) => (live ? call('booking_admin_set_working_hours', { p_hours: hours }) : notLive()),
|
|
321
|
+
listExceptions: () => (live ? call('booking_admin_list_exceptions') : notLive()),
|
|
322
|
+
addException: (input) => (live ? call('booking_admin_add_exception', { p_exception: input }) : notLive()),
|
|
323
|
+
deleteException: (id) => (live ? call('booking_admin_delete_exception', { p_exception_id: id }) : notLive()),
|
|
324
|
+
getSettings: () => (live ? call('booking_admin_get_settings') : notLive()),
|
|
325
|
+
updateSettings: (patch) => (live ? call('booking_admin_update_settings', { p_settings: patch }) : notLive()),
|
|
326
|
+
applyPreset: (preset) => live
|
|
327
|
+
? call('booking_admin_apply_preset', {
|
|
328
|
+
p_preset: { services: preset.services, workingHours: preset.workingHours, policies: preset.policies },
|
|
329
|
+
})
|
|
330
|
+
: notLive(),
|
|
331
|
+
requestDiagnostics: () => (live ? call('booking_admin_request_diagnostics') : notLive()),
|
|
332
|
+
emailStatus: () => (live ? call('booking_admin_email_status') : notLive()),
|
|
333
|
+
sendTestEmail: (recipient) => live
|
|
334
|
+
? EMAIL_RE.test(recipient?.trim() ?? '')
|
|
335
|
+
? call('booking_admin_send_test_email', { p_recipient: recipient.trim() })
|
|
336
|
+
: Promise.resolve(fail('INVALID_INPUT', 'recipient'))
|
|
337
|
+
: notLive(),
|
|
338
|
+
retryFailedEmails: () => (live ? call('booking_admin_retry_failed_emails') : notLive()),
|
|
339
|
+
getSiteContent: () => (live ? contentCall('booking_admin_get_site_content') : notLive()),
|
|
340
|
+
saveSiteContentDraft: (values, baseRevision) => live
|
|
341
|
+
? contentCall('booking_admin_save_site_content', { p_values: values, p_base_revision: baseRevision ?? null })
|
|
342
|
+
: notLive(),
|
|
343
|
+
publishSiteContent: (baseRevision) => live ? contentCall('booking_admin_publish_site_content', { p_base_revision: baseRevision ?? null }) : notLive(),
|
|
344
|
+
discardSiteContentDraft: () => (live ? contentCall('booking_admin_discard_site_content_draft') : notLive()),
|
|
345
|
+
uploadSiteImage: (file) => uploadMedia('site', file),
|
|
346
|
+
listSiteImages: () => listMedia('site'),
|
|
347
|
+
deleteSiteImages: (paths) => deleteMedia(SITE_MEDIA_PATH, paths),
|
|
348
|
+
async uploadServiceImage(file) {
|
|
349
|
+
if (!client)
|
|
350
|
+
return notLive();
|
|
351
|
+
// Checked first, so an older database never collects photos it cannot store.
|
|
352
|
+
const gate = await needsSchema(SERVICE_MEDIA_SCHEMA, 'Service photos need');
|
|
353
|
+
if (!gate.ok)
|
|
354
|
+
return gate;
|
|
355
|
+
return uploadMedia('services', file);
|
|
356
|
+
},
|
|
357
|
+
listServiceImages: () => listMedia('services'),
|
|
358
|
+
deleteServiceImages: (paths) => deleteMedia(SERVICE_MEDIA_PATH, paths),
|
|
359
|
+
};
|
|
360
|
+
return {
|
|
361
|
+
mode,
|
|
362
|
+
version: ENGINE_VERSION,
|
|
363
|
+
async getInfo() {
|
|
364
|
+
if (mode !== 'live') {
|
|
365
|
+
return ok({
|
|
366
|
+
engine: ENGINE_PACKAGE,
|
|
367
|
+
packageVersion: ENGINE_VERSION,
|
|
368
|
+
schemaVersion: SCHEMA_VERSION,
|
|
369
|
+
requiredSchemaVersion: REQUIRED_SCHEMA_VERSION,
|
|
370
|
+
mode,
|
|
371
|
+
compatible: mode === 'preview',
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
return ensureCompatible();
|
|
375
|
+
},
|
|
376
|
+
async getBusiness() {
|
|
377
|
+
if (preview)
|
|
378
|
+
return ok(preview.business);
|
|
379
|
+
return call('booking_get_business');
|
|
380
|
+
},
|
|
381
|
+
async getSiteContent() {
|
|
382
|
+
if (preview)
|
|
383
|
+
return ok({ version: 0, publishedAt: null, values: {} });
|
|
384
|
+
return contentCall('booking_get_site_content');
|
|
385
|
+
},
|
|
386
|
+
mediaUrl(path) {
|
|
387
|
+
if (!client || typeof path !== 'string' || path.includes('..'))
|
|
388
|
+
return null;
|
|
389
|
+
if (!SITE_MEDIA_PATH.test(path) && !SERVICE_MEDIA_PATH.test(path))
|
|
390
|
+
return null;
|
|
391
|
+
return client.storage.from(SITE_MEDIA_BUCKET).getPublicUrl(path).data.publicUrl;
|
|
392
|
+
},
|
|
393
|
+
async listServices() {
|
|
394
|
+
if (preview)
|
|
395
|
+
return ok(preview.services);
|
|
396
|
+
const result = await call('booking_list_services');
|
|
397
|
+
return result.ok ? ok(result.data.map(withImage)) : result;
|
|
398
|
+
},
|
|
399
|
+
async getOpeningTimes(query) {
|
|
400
|
+
if (!query?.from || !DATE_RE.test(query.from))
|
|
401
|
+
return fail('INVALID_INPUT', 'from');
|
|
402
|
+
const to = query.to ?? query.from;
|
|
403
|
+
if (!DATE_RE.test(to) || to < query.from)
|
|
404
|
+
return fail('INVALID_INPUT', 'to');
|
|
405
|
+
if (preview)
|
|
406
|
+
return preview.openingTimes(query.from, to);
|
|
407
|
+
if (!client)
|
|
408
|
+
return notLive();
|
|
409
|
+
const gate = await needsSchema(SERVICE_MEDIA_SCHEMA, 'Opening times need');
|
|
410
|
+
if (!gate.ok)
|
|
411
|
+
return gate;
|
|
412
|
+
return call('booking_get_opening_times', { p_from: query.from, p_to: to });
|
|
413
|
+
},
|
|
414
|
+
async getAvailability(query) {
|
|
415
|
+
if (!query?.serviceId)
|
|
416
|
+
return fail('INVALID_INPUT', 'serviceId');
|
|
417
|
+
if (!query.from)
|
|
418
|
+
return fail('INVALID_INPUT', 'from');
|
|
419
|
+
if (preview)
|
|
420
|
+
return preview.availability(query);
|
|
421
|
+
return call('booking_get_availability', {
|
|
422
|
+
p_service_id: query.serviceId,
|
|
423
|
+
p_from: query.from,
|
|
424
|
+
p_to: query.to ?? query.from,
|
|
425
|
+
});
|
|
426
|
+
},
|
|
427
|
+
async requestBooking(request) {
|
|
428
|
+
const checked = checkRequest(request);
|
|
429
|
+
if (!checked.ok)
|
|
430
|
+
return fail('INVALID_INPUT', checked.field);
|
|
431
|
+
if (preview) {
|
|
432
|
+
if (preview.business.policies.requirePhone && !checked.phone)
|
|
433
|
+
return fail('INVALID_INPUT', 'customer.phone');
|
|
434
|
+
return preview.requestBooking(checked.email);
|
|
435
|
+
}
|
|
436
|
+
const result = await call('booking_request', {
|
|
437
|
+
p_service_id: request.serviceId,
|
|
438
|
+
p_starts_at: request.startsAt,
|
|
439
|
+
p_customer_name: checked.name,
|
|
440
|
+
p_customer_email: checked.email,
|
|
441
|
+
p_customer_phone: checked.phone,
|
|
442
|
+
p_notes: checked.notes,
|
|
443
|
+
});
|
|
444
|
+
return result.ok ? ok({ ...result.data, delivery: 'email' }) : result;
|
|
445
|
+
},
|
|
446
|
+
async verifyBooking(input) {
|
|
447
|
+
const code = String(input?.code ?? '').replace(/[\s-]/g, '');
|
|
448
|
+
if (!input?.requestId || (!UUID_RE.test(input.requestId) && !preview))
|
|
449
|
+
return fail('INVALID_INPUT', 'requestId');
|
|
450
|
+
if (!/^\d{6}$/.test(code))
|
|
451
|
+
return fail('INVALID_INPUT', 'code');
|
|
452
|
+
if (preview)
|
|
453
|
+
return preview.verifyBooking(input.requestId);
|
|
454
|
+
const result = await call('booking_verify', {
|
|
455
|
+
p_request_id: input.requestId,
|
|
456
|
+
p_code: code,
|
|
457
|
+
});
|
|
458
|
+
if (!result.ok)
|
|
459
|
+
return result;
|
|
460
|
+
const { result: outcome, booking, attemptsLeft } = result.data;
|
|
461
|
+
if (outcome === 'verified' && booking)
|
|
462
|
+
return ok(booking);
|
|
463
|
+
const error = engineError(VERIFY_OUTCOMES[outcome] ?? 'UNKNOWN');
|
|
464
|
+
if (outcome === 'invalid_code' && typeof attemptsLeft === 'number')
|
|
465
|
+
error.attemptsLeft = attemptsLeft;
|
|
466
|
+
return { ok: false, error };
|
|
467
|
+
},
|
|
468
|
+
async resendVerificationCode(requestId) {
|
|
469
|
+
if (!requestId || (!UUID_RE.test(requestId) && !preview))
|
|
470
|
+
return fail('INVALID_INPUT', 'requestId');
|
|
471
|
+
if (preview)
|
|
472
|
+
return preview.resendCode(requestId);
|
|
473
|
+
const result = await call('booking_resend_code', { p_request_id: requestId });
|
|
474
|
+
if (!result.ok)
|
|
475
|
+
return result;
|
|
476
|
+
const r = result.data;
|
|
477
|
+
if (r.result === 'sent' && r.expiresAt) {
|
|
478
|
+
return ok({ expiresAt: r.expiresAt, resendsLeft: r.resendsLeft ?? 0, resendAfterSeconds: r.resendAfterSeconds ?? 60, delivery: 'email' });
|
|
479
|
+
}
|
|
480
|
+
if (r.result === 'too_soon')
|
|
481
|
+
return { ok: false, error: { ...engineError('RESEND_TOO_SOON'), retryAfterSeconds: r.retryAfterSeconds ?? 60 } };
|
|
482
|
+
if (r.result === 'limit_reached')
|
|
483
|
+
return fail('RESEND_LIMIT');
|
|
484
|
+
if (r.result === 'verified')
|
|
485
|
+
return fail('CONFLICT', 'already_verified');
|
|
486
|
+
return fail('CODE_EXPIRED');
|
|
487
|
+
},
|
|
488
|
+
async cancelBookingRequest(requestId) {
|
|
489
|
+
if (!requestId || (!UUID_RE.test(requestId) && !preview))
|
|
490
|
+
return fail('INVALID_INPUT', 'requestId');
|
|
491
|
+
if (preview)
|
|
492
|
+
return preview.cancelRequest(requestId);
|
|
493
|
+
const result = await call('booking_cancel_request', { p_request_id: requestId });
|
|
494
|
+
if (!result.ok)
|
|
495
|
+
return result;
|
|
496
|
+
if (result.data.result === 'verified')
|
|
497
|
+
return fail('CONFLICT', 'already_verified');
|
|
498
|
+
return ok({ released: result.data.result === 'cancelled' });
|
|
499
|
+
},
|
|
500
|
+
async createBooking() {
|
|
501
|
+
return fail('VERIFICATION_REQUIRED');
|
|
502
|
+
},
|
|
503
|
+
auth,
|
|
504
|
+
admin,
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
export { engineError };
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** The only two variables the website reads. */
|
|
2
|
+
export declare const BACKEND_ENV: {
|
|
3
|
+
readonly url: "VITE_SUPABASE_URL";
|
|
4
|
+
readonly key: "VITE_SUPABASE_PUBLISHABLE_KEY";
|
|
5
|
+
};
|
|
6
|
+
export interface BackendEnvCheck {
|
|
7
|
+
/**
|
|
8
|
+
* `configured`: both values look right. `none`: neither is set (preview mode
|
|
9
|
+
* in development, “Online booking is not available yet” in a production
|
|
10
|
+
* build). `invalid`: a build with these values would not work — see `problems`.
|
|
11
|
+
*/
|
|
12
|
+
status: 'configured' | 'none' | 'invalid';
|
|
13
|
+
/** What to fix, one sentence each (empty unless `invalid`). */
|
|
14
|
+
problems: string[];
|
|
15
|
+
}
|
|
16
|
+
/** Names other guides use for the same values. The engine reads only the two above. */
|
|
17
|
+
export declare const BACKEND_ENV_ALIASES: Readonly<Record<string, 'url' | 'key'>>;
|
|
18
|
+
/** The `role` claim of a JWT-style key (legacy Supabase keys), or null. */
|
|
19
|
+
export declare function decodeJwtRole(key: string): string | null;
|
|
20
|
+
/**
|
|
21
|
+
* Checks VITE_SUPABASE_URL and VITE_SUPABASE_PUBLISHABLE_KEY as a website build
|
|
22
|
+
* or a browser would see them. Pass the environment (e.g. Vite's `loadEnv(...)`,
|
|
23
|
+
* or `process.env`); other variables are only read to recognise a misnamed one.
|
|
24
|
+
*/
|
|
25
|
+
export declare function checkBackendEnv(env: Readonly<Record<string, string | undefined>>): BackendEnvCheck;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// The website's two public connection values, checked before they reach a
|
|
2
|
+
// build or a browser. A half-set pair, a misnamed variable or a dashboard
|
|
3
|
+
// address would otherwise deploy "successfully" and switch online booking off
|
|
4
|
+
// without a word; a secret key would be compiled into public JavaScript.
|
|
5
|
+
// Used by the Vite plugin (the build stops), the client (a console warning)
|
|
6
|
+
// and `booking-engine doctor`. Messages name variables, never their values.
|
|
7
|
+
/** The only two variables the website reads. */
|
|
8
|
+
export const BACKEND_ENV = { url: 'VITE_SUPABASE_URL', key: 'VITE_SUPABASE_PUBLISHABLE_KEY' };
|
|
9
|
+
/** Names other guides use for the same values. The engine reads only the two above. */
|
|
10
|
+
export const BACKEND_ENV_ALIASES = Object.freeze({
|
|
11
|
+
VITE_SUPABASE_ANON_KEY: 'key',
|
|
12
|
+
VITE_SUPABASE_KEY: 'key',
|
|
13
|
+
VITE_SUPABASE_PUBLIC_KEY: 'key',
|
|
14
|
+
VITE_PUBLIC_SUPABASE_URL: 'url',
|
|
15
|
+
VITE_PUBLIC_SUPABASE_ANON_KEY: 'key',
|
|
16
|
+
SUPABASE_URL: 'url',
|
|
17
|
+
SUPABASE_ANON_KEY: 'key',
|
|
18
|
+
SUPABASE_PUBLISHABLE_KEY: 'key',
|
|
19
|
+
NEXT_PUBLIC_SUPABASE_URL: 'url',
|
|
20
|
+
NEXT_PUBLIC_SUPABASE_ANON_KEY: 'key',
|
|
21
|
+
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY: 'key',
|
|
22
|
+
});
|
|
23
|
+
/** The `role` claim of a JWT-style key (legacy Supabase keys), or null. */
|
|
24
|
+
export function decodeJwtRole(key) {
|
|
25
|
+
const parts = key.split('.');
|
|
26
|
+
if (parts.length !== 3 || !parts[1])
|
|
27
|
+
return null;
|
|
28
|
+
try {
|
|
29
|
+
const json = JSON.parse(globalThis.atob(parts[1].replace(/-/g, '+').replace(/_/g, '/')));
|
|
30
|
+
return typeof json.role === 'string' ? json.role : null;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const LOOPBACK = /^(localhost|127(\.\d{1,3}){3}|\[::1\])$/;
|
|
37
|
+
const QUOTED = /^(['"]).*\1$/;
|
|
38
|
+
function urlProblem(value) {
|
|
39
|
+
const name = BACKEND_ENV.url;
|
|
40
|
+
let url;
|
|
41
|
+
try {
|
|
42
|
+
url = new URL(value);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return `${name} is not a web address. Use the Project URL from Supabase (e.g. https://abcdefghijklmnopqrst.supabase.co).`;
|
|
46
|
+
}
|
|
47
|
+
if (/(^|\.)supabase\.com$/.test(url.hostname)) {
|
|
48
|
+
const ref = /\/project\/([a-z0-9]{20})(\/|$)/.exec(url.pathname)?.[1];
|
|
49
|
+
return `${name} is a Supabase dashboard address. Use the Project URL instead: ${ref ? `https://${ref}.supabase.co` : 'https://<project-ref>.supabase.co'}.`;
|
|
50
|
+
}
|
|
51
|
+
if (url.protocol !== 'https:' && !(url.protocol === 'http:' && LOOPBACK.test(url.hostname))) {
|
|
52
|
+
return `${name} must start with https:// (http:// only for a Supabase running on this computer).`;
|
|
53
|
+
}
|
|
54
|
+
if (url.pathname !== '/' || url.search || url.hash) {
|
|
55
|
+
return `${name} must be the Project URL only, without a path: ${url.origin}`;
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
function keyProblem(value) {
|
|
60
|
+
const name = BACKEND_ENV.key;
|
|
61
|
+
if (value.startsWith('sb_secret_') || decodeJwtRole(value) === 'service_role') {
|
|
62
|
+
return (`${name} holds a SECRET key, which would be published inside the website's JavaScript. Use the publishable key ` +
|
|
63
|
+
'(sb_publishable_…), and rotate the secret key in Supabase if it was ever deployed or committed.');
|
|
64
|
+
}
|
|
65
|
+
if (/^re_[A-Za-z0-9]/.test(value)) {
|
|
66
|
+
return `${name} holds an email provider (Resend) key. It belongs only in Supabase Edge Function secrets, never in the website.`;
|
|
67
|
+
}
|
|
68
|
+
if (value.startsWith('sb_publishable_') || decodeJwtRole(value) === 'anon')
|
|
69
|
+
return null;
|
|
70
|
+
return `${name} does not look like a Supabase publishable key (sb_publishable_…, or the older anon key).`;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Checks VITE_SUPABASE_URL and VITE_SUPABASE_PUBLISHABLE_KEY as a website build
|
|
74
|
+
* or a browser would see them. Pass the environment (e.g. Vite's `loadEnv(...)`,
|
|
75
|
+
* or `process.env`); other variables are only read to recognise a misnamed one.
|
|
76
|
+
*/
|
|
77
|
+
export function checkBackendEnv(env) {
|
|
78
|
+
const value = (name) => (typeof env[name] === 'string' ? env[name].trim() : '');
|
|
79
|
+
const url = value(BACKEND_ENV.url);
|
|
80
|
+
const key = value(BACKEND_ENV.key);
|
|
81
|
+
const aliases = (kind) => Object.keys(BACKEND_ENV_ALIASES).filter((n) => (!kind || BACKEND_ENV_ALIASES[n] === kind) && value(n));
|
|
82
|
+
if (!url && !key) {
|
|
83
|
+
const found = aliases();
|
|
84
|
+
if (!found.length)
|
|
85
|
+
return { status: 'none', problems: [] };
|
|
86
|
+
return {
|
|
87
|
+
status: 'invalid',
|
|
88
|
+
problems: [
|
|
89
|
+
`Found ${found.join(', ')} but not ${BACKEND_ENV.url} and ${BACKEND_ENV.key}. The website reads exactly these two names ` +
|
|
90
|
+
'(Vite only passes variables that start with VITE_ to the browser): rename them.',
|
|
91
|
+
],
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const problems = [];
|
|
95
|
+
const missing = (name, other, kind) => {
|
|
96
|
+
const found = aliases(kind);
|
|
97
|
+
return `${other} is set but ${name} is missing${found.length ? ` (found ${found.join(', ')}: rename it to ${name})` : ''}. Set both, or neither.`;
|
|
98
|
+
};
|
|
99
|
+
if (!url)
|
|
100
|
+
problems.push(missing(BACKEND_ENV.url, BACKEND_ENV.key, 'url'));
|
|
101
|
+
if (!key)
|
|
102
|
+
problems.push(missing(BACKEND_ENV.key, BACKEND_ENV.url, 'key'));
|
|
103
|
+
for (const [name, v, check] of [
|
|
104
|
+
[BACKEND_ENV.url, url, urlProblem],
|
|
105
|
+
[BACKEND_ENV.key, key, keyProblem],
|
|
106
|
+
]) {
|
|
107
|
+
if (!v)
|
|
108
|
+
continue;
|
|
109
|
+
const inner = QUOTED.test(v) ? v.slice(1, -1).trim() : v;
|
|
110
|
+
if (inner !== v)
|
|
111
|
+
problems.push(`${name} is wrapped in quotes: enter the value without them.`);
|
|
112
|
+
// Checked even when quoted: a secret key must be named as one.
|
|
113
|
+
const problem = check(inner);
|
|
114
|
+
if (problem)
|
|
115
|
+
problems.push(problem);
|
|
116
|
+
else if (/\s/.test(inner))
|
|
117
|
+
problems.push(`${name} contains a space or a line break: copy the value again.`);
|
|
118
|
+
}
|
|
119
|
+
return problems.length ? { status: 'invalid', problems } : { status: 'configured', problems: [] };
|
|
120
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const SITE_IMAGE_TYPES: readonly ["image/jpeg", "image/png", "image/webp", "image/avif"];
|
|
2
|
+
/** The bucket's limit. */
|
|
3
|
+
export declare const SITE_IMAGE_MAX_BYTES: number;
|
|
4
|
+
/** Longest side after scaling. */
|
|
5
|
+
export declare const SITE_IMAGE_MAX_DIMENSION = 2400;
|
|
6
|
+
export interface PreparedImage {
|
|
7
|
+
blob: Blob;
|
|
8
|
+
type: string;
|
|
9
|
+
extension: string;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
}
|
|
13
|
+
export declare class ImageProblem extends Error {
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Checks the file, redraws camera photos (dropping their metadata) and scales
|
|
17
|
+
* down anything larger than needed. Throws ImageProblem with a message for the
|
|
18
|
+
* owner.
|
|
19
|
+
*/
|
|
20
|
+
export declare function prepareSiteImage(file: Blob): Promise<PreparedImage>;
|