@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,328 @@
|
|
|
1
|
+
-- ============================================================================
|
|
2
|
+
-- Profit Studio Booking Engine — migration 0008_service_images_opening_times
|
|
3
|
+
-- Engine schema version: 2.0.0-alpha.10
|
|
4
|
+
--
|
|
5
|
+
-- ENGINE-OWNED FILE. Do not edit. `booking-engine doctor` reports changes.
|
|
6
|
+
--
|
|
7
|
+
-- Additive only:
|
|
8
|
+
-- 1. Optional service images. booking.services.image is null or
|
|
9
|
+
-- { path, alt?, width?, height? }: a file under `services/` in the public
|
|
10
|
+
-- media bucket `booking-site-media` (0007: anyone may read a file by its
|
|
11
|
+
-- URL; only admins list, upload or delete; images only, 5 MB at most).
|
|
12
|
+
-- Public service data includes it. No service needs an image, and
|
|
13
|
+
-- bookings, prices and availability do not depend on it.
|
|
14
|
+
-- 2. Public opening times: each business-local date's opening hours after
|
|
15
|
+
-- closures (whole-day and partial-day), for "Open now" / "Opens at"
|
|
16
|
+
-- lines on websites. Times only — closure reasons stay admin-only.
|
|
17
|
+
--
|
|
18
|
+
-- Existing services, bookings and settings are unchanged.
|
|
19
|
+
-- ============================================================================
|
|
20
|
+
|
|
21
|
+
do $$
|
|
22
|
+
declare
|
|
23
|
+
v text;
|
|
24
|
+
begin
|
|
25
|
+
select e.schema_version into v from booking.engine_info e where e.id;
|
|
26
|
+
if v is distinct from '2.0.0-alpha.7' then
|
|
27
|
+
raise exception 'Booking Engine 0008_service_images_opening_times expects schema 2.0.0-alpha.7, found %', coalesce(v, 'none');
|
|
28
|
+
end if;
|
|
29
|
+
end
|
|
30
|
+
$$;
|
|
31
|
+
|
|
32
|
+
-- ----------------------------------------------------------------------------
|
|
33
|
+
-- 1. Service images
|
|
34
|
+
-- ----------------------------------------------------------------------------
|
|
35
|
+
|
|
36
|
+
-- A service image value: { path, alt?, width?, height? }. The path is a file
|
|
37
|
+
-- name under services/ (never site/: the website editor tidies site/ files
|
|
38
|
+
-- that its content no longer uses). CASE keeps every cast behind its type test.
|
|
39
|
+
create function booking.service_image_ok(p_image jsonb)
|
|
40
|
+
returns boolean
|
|
41
|
+
language sql
|
|
42
|
+
immutable
|
|
43
|
+
set search_path = ''
|
|
44
|
+
as $$
|
|
45
|
+
select case
|
|
46
|
+
when p_image is null or jsonb_typeof(p_image) <> 'object' then false
|
|
47
|
+
when exists (select 1 from jsonb_object_keys(p_image) k where k not in ('path', 'alt', 'width', 'height')) then false
|
|
48
|
+
when coalesce(jsonb_typeof(p_image -> 'path'), '') <> 'string' then false
|
|
49
|
+
when (p_image ->> 'path') !~ '^services/[a-z0-9][a-z0-9._-]{0,120}$' or position('..' in (p_image ->> 'path')) > 0 then false
|
|
50
|
+
when coalesce(jsonb_typeof(p_image -> 'alt'), 'string') <> 'string' then false
|
|
51
|
+
when char_length(coalesce(p_image ->> 'alt', '')) > 300 or coalesce(p_image ->> 'alt', '') ~ '[\x01-\x1f\x7f]' then false
|
|
52
|
+
when coalesce(jsonb_typeof(p_image -> 'width'), 'number') <> 'number' then false
|
|
53
|
+
when coalesce(jsonb_typeof(p_image -> 'height'), 'number') <> 'number' then false
|
|
54
|
+
when p_image ? 'width' and ((p_image ->> 'width')::numeric not between 1 and 20000
|
|
55
|
+
or (p_image ->> 'width')::numeric <> trunc((p_image ->> 'width')::numeric)) then false
|
|
56
|
+
when p_image ? 'height' and ((p_image ->> 'height')::numeric not between 1 and 20000
|
|
57
|
+
or (p_image ->> 'height')::numeric <> trunc((p_image ->> 'height')::numeric)) then false
|
|
58
|
+
else true
|
|
59
|
+
end;
|
|
60
|
+
$$;
|
|
61
|
+
|
|
62
|
+
-- The full rules are checked by booking_admin_save_service; the table keeps a
|
|
63
|
+
-- shape guarantee that needs no function privileges.
|
|
64
|
+
alter table booking.services
|
|
65
|
+
add column image jsonb
|
|
66
|
+
constraint services_image_shape check (
|
|
67
|
+
image is null
|
|
68
|
+
or (jsonb_typeof(image) = 'object'
|
|
69
|
+
and jsonb_typeof(image -> 'path') = 'string'
|
|
70
|
+
and (image ->> 'path') ~ '^services/[a-z0-9][a-z0-9._-]{0,120}$'
|
|
71
|
+
and octet_length(image::text) <= 2000)
|
|
72
|
+
);
|
|
73
|
+
comment on column booking.services.image is
|
|
74
|
+
'Optional photo: { path, alt?, width?, height? }; path is under services/ in the public bucket booking-site-media. Display only — never required to create or book a service.';
|
|
75
|
+
|
|
76
|
+
-- Admin shape: everything, now with the image.
|
|
77
|
+
create or replace function booking.service_json(sv booking.services)
|
|
78
|
+
returns jsonb
|
|
79
|
+
language sql
|
|
80
|
+
stable
|
|
81
|
+
set search_path = ''
|
|
82
|
+
as $$
|
|
83
|
+
select jsonb_build_object(
|
|
84
|
+
'id', sv.id,
|
|
85
|
+
'name', sv.name,
|
|
86
|
+
'description', sv.description,
|
|
87
|
+
'durationMinutes', sv.duration_minutes,
|
|
88
|
+
'bufferAfterMinutes', sv.buffer_after_minutes,
|
|
89
|
+
'priceCents', sv.price_cents,
|
|
90
|
+
'priceFrom', sv.price_from,
|
|
91
|
+
'isActive', sv.is_active,
|
|
92
|
+
'sortOrder', sv.sort_order,
|
|
93
|
+
'image', sv.image,
|
|
94
|
+
'createdAt', booking.iso(sv.created_at),
|
|
95
|
+
'updatedAt', booking.iso(sv.updated_at)
|
|
96
|
+
);
|
|
97
|
+
$$;
|
|
98
|
+
|
|
99
|
+
-- Public shape: unchanged fields plus the image (a public file path and its
|
|
100
|
+
-- description; nothing private).
|
|
101
|
+
create or replace function public.booking_list_services()
|
|
102
|
+
returns jsonb
|
|
103
|
+
language sql
|
|
104
|
+
stable
|
|
105
|
+
security invoker
|
|
106
|
+
set search_path = ''
|
|
107
|
+
as $$
|
|
108
|
+
select coalesce(jsonb_agg(
|
|
109
|
+
jsonb_build_object(
|
|
110
|
+
'id', sv.id,
|
|
111
|
+
'name', sv.name,
|
|
112
|
+
'description', sv.description,
|
|
113
|
+
'durationMinutes', sv.duration_minutes,
|
|
114
|
+
'priceCents', sv.price_cents,
|
|
115
|
+
'priceFrom', sv.price_from,
|
|
116
|
+
'currency', (select s.currency from booking.settings s where s.id),
|
|
117
|
+
'image', sv.image
|
|
118
|
+
) order by sv.sort_order, sv.name), '[]'::jsonb)
|
|
119
|
+
from booking.services sv
|
|
120
|
+
where sv.is_active;
|
|
121
|
+
$$;
|
|
122
|
+
comment on function public.booking_list_services() is
|
|
123
|
+
'Public. Active services in display order, each with its optional image ({ path, alt?, width?, height? } or null).';
|
|
124
|
+
|
|
125
|
+
-- Saving a service accepts `image`: an image value sets it, null removes it,
|
|
126
|
+
-- leaving it out keeps the current one.
|
|
127
|
+
create or replace function public.booking_admin_save_service(p_service jsonb)
|
|
128
|
+
returns jsonb
|
|
129
|
+
language plpgsql
|
|
130
|
+
volatile
|
|
131
|
+
security invoker
|
|
132
|
+
set search_path = ''
|
|
133
|
+
as $$
|
|
134
|
+
declare
|
|
135
|
+
v_allowed text[] := array['id', 'name', 'description', 'durationMinutes', 'bufferAfterMinutes',
|
|
136
|
+
'priceCents', 'priceFrom', 'isActive', 'sortOrder', 'image'];
|
|
137
|
+
v_key text;
|
|
138
|
+
v_id uuid;
|
|
139
|
+
v_image jsonb;
|
|
140
|
+
sv booking.services%rowtype;
|
|
141
|
+
begin
|
|
142
|
+
perform booking.require_admin();
|
|
143
|
+
if p_service is null or jsonb_typeof(p_service) <> 'object' then
|
|
144
|
+
perform booking.raise_error('INVALID_INPUT', 'service');
|
|
145
|
+
end if;
|
|
146
|
+
for v_key in select jsonb_object_keys(p_service) loop
|
|
147
|
+
if not (v_key = any (v_allowed)) then
|
|
148
|
+
perform booking.raise_error('INVALID_INPUT', v_key);
|
|
149
|
+
end if;
|
|
150
|
+
end loop;
|
|
151
|
+
|
|
152
|
+
if jsonb_typeof(p_service -> 'id') = 'string' then
|
|
153
|
+
begin
|
|
154
|
+
v_id := (p_service ->> 'id')::uuid;
|
|
155
|
+
exception when others then
|
|
156
|
+
perform booking.raise_error('INVALID_INPUT', 'id');
|
|
157
|
+
end;
|
|
158
|
+
elsif p_service ? 'id' and jsonb_typeof(p_service -> 'id') <> 'null' then
|
|
159
|
+
perform booking.raise_error('INVALID_INPUT', 'id');
|
|
160
|
+
end if;
|
|
161
|
+
|
|
162
|
+
if p_service ? 'durationMinutes' or v_id is null then
|
|
163
|
+
if booking.j_int(p_service, 'durationMinutes', 5, 720) is null then
|
|
164
|
+
perform booking.raise_error('INVALID_INPUT', 'durationMinutes');
|
|
165
|
+
end if;
|
|
166
|
+
end if;
|
|
167
|
+
|
|
168
|
+
if p_service ? 'image' and jsonb_typeof(p_service -> 'image') <> 'null' then
|
|
169
|
+
if not booking.service_image_ok(p_service -> 'image') then
|
|
170
|
+
perform booking.raise_error('INVALID_INPUT', 'image');
|
|
171
|
+
end if;
|
|
172
|
+
v_image := p_service -> 'image';
|
|
173
|
+
end if;
|
|
174
|
+
|
|
175
|
+
if v_id is null then
|
|
176
|
+
insert into booking.services (
|
|
177
|
+
name, description, duration_minutes, buffer_after_minutes, price_cents, price_from, is_active, sort_order, image
|
|
178
|
+
) values (
|
|
179
|
+
booking.j_required_text(p_service, 'name', 120),
|
|
180
|
+
booking.j_text(p_service, 'description', 2000),
|
|
181
|
+
booking.j_int(p_service, 'durationMinutes', 5, 720),
|
|
182
|
+
coalesce(booking.j_int(p_service, 'bufferAfterMinutes', 0, 240), 0),
|
|
183
|
+
booking.j_int(p_service, 'priceCents', 0, 100000000),
|
|
184
|
+
coalesce(booking.j_bool(p_service, 'priceFrom'), false),
|
|
185
|
+
coalesce(booking.j_bool(p_service, 'isActive'), true),
|
|
186
|
+
coalesce(booking.j_int(p_service, 'sortOrder', -100000, 100000), 0),
|
|
187
|
+
v_image
|
|
188
|
+
)
|
|
189
|
+
returning * into sv;
|
|
190
|
+
else
|
|
191
|
+
update booking.services set
|
|
192
|
+
name = case when p_service ? 'name' then booking.j_required_text(p_service, 'name', 120) else name end,
|
|
193
|
+
description = case when p_service ? 'description' then booking.j_text(p_service, 'description', 2000) else description end,
|
|
194
|
+
duration_minutes = case when p_service ? 'durationMinutes'
|
|
195
|
+
then booking.j_int(p_service, 'durationMinutes', 5, 720) else duration_minutes end,
|
|
196
|
+
buffer_after_minutes = case when p_service ? 'bufferAfterMinutes'
|
|
197
|
+
then coalesce(booking.j_int(p_service, 'bufferAfterMinutes', 0, 240), 0) else buffer_after_minutes end,
|
|
198
|
+
price_cents = case when p_service ? 'priceCents' then booking.j_int(p_service, 'priceCents', 0, 100000000) else price_cents end,
|
|
199
|
+
price_from = case when p_service ? 'priceFrom' then coalesce(booking.j_bool(p_service, 'priceFrom'), false) else price_from end,
|
|
200
|
+
is_active = case when p_service ? 'isActive' then coalesce(booking.j_bool(p_service, 'isActive'), true) else is_active end,
|
|
201
|
+
sort_order = case when p_service ? 'sortOrder'
|
|
202
|
+
then coalesce(booking.j_int(p_service, 'sortOrder', -100000, 100000), 0) else sort_order end,
|
|
203
|
+
image = case when p_service ? 'image' then v_image else image end
|
|
204
|
+
where id = v_id
|
|
205
|
+
returning * into sv;
|
|
206
|
+
if not found then
|
|
207
|
+
perform booking.raise_error('NOT_FOUND', 'service');
|
|
208
|
+
end if;
|
|
209
|
+
end if;
|
|
210
|
+
return booking.service_json(sv);
|
|
211
|
+
exception
|
|
212
|
+
when check_violation then
|
|
213
|
+
perform booking.raise_error('INVALID_INPUT', 'service');
|
|
214
|
+
return null;
|
|
215
|
+
end;
|
|
216
|
+
$$;
|
|
217
|
+
|
|
218
|
+
-- ----------------------------------------------------------------------------
|
|
219
|
+
-- 2. Public opening times
|
|
220
|
+
-- ----------------------------------------------------------------------------
|
|
221
|
+
|
|
222
|
+
-- Each date's opening hours (weekly hours minus that date's closures), as
|
|
223
|
+
-- business-local "HH:MM" ranges. A partial closure closes the same time window
|
|
224
|
+
-- on every date of its range, exactly as availability treats it.
|
|
225
|
+
create function booking.get_opening_times(p_from date, p_to date default null)
|
|
226
|
+
returns jsonb
|
|
227
|
+
language plpgsql
|
|
228
|
+
stable
|
|
229
|
+
security definer
|
|
230
|
+
set search_path = ''
|
|
231
|
+
as $$
|
|
232
|
+
declare
|
|
233
|
+
c_max_days constant int := 42;
|
|
234
|
+
v_to date := coalesce(p_to, p_from);
|
|
235
|
+
v_timezone text;
|
|
236
|
+
v_result jsonb;
|
|
237
|
+
begin
|
|
238
|
+
if p_from is null or not isfinite(p_from) then
|
|
239
|
+
perform booking.raise_error('INVALID_INPUT', 'from');
|
|
240
|
+
end if;
|
|
241
|
+
if not isfinite(v_to) or v_to < p_from or v_to - p_from >= c_max_days then
|
|
242
|
+
perform booking.raise_error('INVALID_INPUT', 'to');
|
|
243
|
+
end if;
|
|
244
|
+
select s.timezone into v_timezone from booking.settings s where s.id;
|
|
245
|
+
|
|
246
|
+
with days as (
|
|
247
|
+
select p_from + g.n as day
|
|
248
|
+
from generate_series(0, v_to - p_from) as g(n)
|
|
249
|
+
),
|
|
250
|
+
open_minutes as (
|
|
251
|
+
select dd.day,
|
|
252
|
+
range_agg(int4range(
|
|
253
|
+
(extract(hour from wh.start_time) * 60 + extract(minute from wh.start_time))::int,
|
|
254
|
+
(extract(hour from wh.end_time) * 60 + extract(minute from wh.end_time))::int)) as m
|
|
255
|
+
from days dd
|
|
256
|
+
join booking.working_hours wh on wh.weekday = extract(isodow from dd.day)::int
|
|
257
|
+
group by dd.day
|
|
258
|
+
),
|
|
259
|
+
closed_minutes as (
|
|
260
|
+
select dd.day,
|
|
261
|
+
range_agg(int4range(
|
|
262
|
+
coalesce((extract(hour from e.start_time) * 60 + extract(minute from e.start_time))::int, 0),
|
|
263
|
+
coalesce((extract(hour from e.end_time) * 60 + extract(minute from e.end_time))::int, 1440))) as m
|
|
264
|
+
from days dd
|
|
265
|
+
join booking.availability_exceptions e on dd.day between e.starts_on and e.ends_on
|
|
266
|
+
group by dd.day
|
|
267
|
+
)
|
|
268
|
+
select jsonb_build_object(
|
|
269
|
+
'timezone', v_timezone,
|
|
270
|
+
'from', to_char(p_from, 'YYYY-MM-DD'),
|
|
271
|
+
'to', to_char(v_to, 'YYYY-MM-DD'),
|
|
272
|
+
'days', coalesce(jsonb_agg(
|
|
273
|
+
jsonb_build_object(
|
|
274
|
+
'date', to_char(dd.day, 'YYYY-MM-DD'),
|
|
275
|
+
'hours', coalesce((
|
|
276
|
+
select jsonb_agg(
|
|
277
|
+
jsonb_build_object(
|
|
278
|
+
'start', to_char(make_interval(mins => lower(r)), 'HH24:MI'),
|
|
279
|
+
'end', to_char(make_interval(mins => upper(r)), 'HH24:MI')
|
|
280
|
+
) order by lower(r))
|
|
281
|
+
from unnest(coalesce(o.m, '{}'::int4multirange) - coalesce(c.m, '{}'::int4multirange)) as r
|
|
282
|
+
), '[]'::jsonb)
|
|
283
|
+
) order by dd.day), '[]'::jsonb)
|
|
284
|
+
)
|
|
285
|
+
into v_result
|
|
286
|
+
from days dd
|
|
287
|
+
left join open_minutes o on o.day = dd.day
|
|
288
|
+
left join closed_minutes c on c.day = dd.day;
|
|
289
|
+
|
|
290
|
+
return v_result;
|
|
291
|
+
end;
|
|
292
|
+
$$;
|
|
293
|
+
comment on function booking.get_opening_times(date, date) is
|
|
294
|
+
'PRIVILEGED (SECURITY DEFINER), private schema: reads closures to compute each date''s opening hours and returns times only — never closure reasons. Reached through public.booking_get_opening_times.';
|
|
295
|
+
|
|
296
|
+
create function public.booking_get_opening_times(p_from date, p_to date default null)
|
|
297
|
+
returns jsonb
|
|
298
|
+
language sql
|
|
299
|
+
stable
|
|
300
|
+
security invoker
|
|
301
|
+
set search_path = ''
|
|
302
|
+
as $$
|
|
303
|
+
select booking.get_opening_times(p_from, p_to);
|
|
304
|
+
$$;
|
|
305
|
+
comment on function public.booking_get_opening_times(date, date) is
|
|
306
|
+
'Public. Opening hours of each business-local date after closures (at most 42 days): { timezone, from, to, days: [{ date, hours: [{ start, end }] }] }. Times only.';
|
|
307
|
+
|
|
308
|
+
-- ----------------------------------------------------------------------------
|
|
309
|
+
-- Privileges
|
|
310
|
+
-- ----------------------------------------------------------------------------
|
|
311
|
+
|
|
312
|
+
revoke all on function
|
|
313
|
+
booking.service_image_ok(jsonb),
|
|
314
|
+
booking.get_opening_times(date, date),
|
|
315
|
+
public.booking_get_opening_times(date, date)
|
|
316
|
+
from public, anon, authenticated, service_role;
|
|
317
|
+
|
|
318
|
+
-- Admins save services through the invoker function, which checks the image.
|
|
319
|
+
grant execute on function booking.service_image_ok(jsonb) to authenticated;
|
|
320
|
+
|
|
321
|
+
-- Visitors: opening times. The private function is executable but not
|
|
322
|
+
-- reachable by URL (schema `booking` is not exposed); the wrapper is the entry.
|
|
323
|
+
grant execute on function
|
|
324
|
+
booking.get_opening_times(date, date),
|
|
325
|
+
public.booking_get_opening_times(date, date)
|
|
326
|
+
to anon, authenticated, service_role;
|
|
327
|
+
|
|
328
|
+
update booking.engine_info set schema_version = '2.0.0-alpha.10', updated_at = now() where id;
|
package/package.json
CHANGED
|
@@ -1,6 +1,87 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@profitstudio/booking-engine",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.0.0-beta.1",
|
|
4
|
+
"description": "Secure, versioned booking engine for independently owned small-business websites: Supabase migrations, a typed client, an admin dashboard and a CLI.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Youssef Es-salhi",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"booking",
|
|
9
|
+
"appointments",
|
|
10
|
+
"scheduling",
|
|
11
|
+
"supabase",
|
|
12
|
+
"small-business",
|
|
13
|
+
"react",
|
|
14
|
+
"vite",
|
|
15
|
+
"dashboard"
|
|
16
|
+
],
|
|
17
|
+
"type": "module",
|
|
18
|
+
"sideEffects": [
|
|
19
|
+
"*.css"
|
|
20
|
+
],
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./admin": {
|
|
27
|
+
"types": "./dist/admin/index.d.ts",
|
|
28
|
+
"import": "./dist/admin/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./admin.css": "./dist/admin/admin.css",
|
|
31
|
+
"./vite": {
|
|
32
|
+
"types": "./dist/vite.d.ts",
|
|
33
|
+
"import": "./dist/vite.js"
|
|
34
|
+
},
|
|
35
|
+
"./engine.manifest.json": "./engine.manifest.json",
|
|
36
|
+
"./package.json": "./package.json"
|
|
37
|
+
},
|
|
38
|
+
"bin": {
|
|
39
|
+
"booking-engine": "./bin/booking-engine.mjs"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist",
|
|
43
|
+
"bin",
|
|
44
|
+
"migrations",
|
|
45
|
+
"functions",
|
|
46
|
+
"docs",
|
|
47
|
+
"templates",
|
|
48
|
+
"engine.manifest.json",
|
|
49
|
+
"README.md",
|
|
50
|
+
"CHANGELOG.md",
|
|
51
|
+
"THIRD_PARTY_NOTICES.md"
|
|
52
|
+
],
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=20.19"
|
|
55
|
+
},
|
|
56
|
+
"bookingEngine": {
|
|
57
|
+
"schemaVersion": "2.0.0-alpha.10",
|
|
58
|
+
"requiredSchemaVersion": "2.0.0-alpha.5"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "node scripts/build.mjs",
|
|
62
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
63
|
+
},
|
|
64
|
+
"dependencies": {
|
|
65
|
+
"@supabase/supabase-js": "2.118.0"
|
|
66
|
+
},
|
|
67
|
+
"peerDependencies": {
|
|
68
|
+
"react": ">=18.2"
|
|
69
|
+
},
|
|
70
|
+
"peerDependenciesMeta": {
|
|
71
|
+
"react": {
|
|
72
|
+
"optional": true
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"@fontsource-variable/geist": "5.3.0",
|
|
77
|
+
"@fontsource-variable/geist-mono": "5.3.0",
|
|
78
|
+
"@types/react": "19.3.0",
|
|
79
|
+
"lucide-static": "1.66.0",
|
|
80
|
+
"react": "19.3.1",
|
|
81
|
+
"typescript": "6.0.3"
|
|
82
|
+
},
|
|
83
|
+
"publishConfig": {
|
|
84
|
+
"access": "public",
|
|
85
|
+
"tag": "beta"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Booking Engine — rules for this project
|
|
2
|
+
|
|
3
|
+
This project uses **@profitstudio/booking-engine** (version: see
|
|
4
|
+
`booking-engine.lock.json`). The engine owns booking data, availability, the
|
|
5
|
+
database, booking emails (the `booking-mailer` Edge Function) and the admin
|
|
6
|
+
dashboard. The public website design is yours.
|
|
7
|
+
|
|
8
|
+
Short guide: `node_modules/@profitstudio/booking-engine/docs/BUILD-A-SITE.md` · full contract: `docs/INTEGRATION.md`
|
|
9
|
+
Connect Supabase and email: `npx booking-engine connect` (INTEGRATION.md §11)
|
|
10
|
+
|
|
11
|
+
## Always
|
|
12
|
+
|
|
13
|
+
- Get booking data only through the engine instance in `src/lib/engine.ts`.
|
|
14
|
+
- Take preview sample data from a preset: the engine's `hairSalonPreset`, or the site's
|
|
15
|
+
own `Preset` for any other kind of business (INTEGRATION.md §5), also passed to
|
|
16
|
+
`<BookingAdmin presets>`.
|
|
17
|
+
- Show the slots `getAvailability()` returns; send `slot.startsAt` back unchanged.
|
|
18
|
+
- Show dates and times in the business time zone (`business.timezone`).
|
|
19
|
+
- Book in two steps: `requestBooking()` emails a 6-digit code, then `verifyBooking()`
|
|
20
|
+
with that code. Offer "Send a new code" (`resendVerificationCode()`) and
|
|
21
|
+
"Choose another time" (`cancelBookingRequest()`, then reload availability).
|
|
22
|
+
- Handle `ok: false` on every engine call (see the error table in INTEGRATION.md).
|
|
23
|
+
- Show success only when `verifyBooking()` returned `ok: true`, and say whether the
|
|
24
|
+
booking is a request (`pending`, the business will confirm) or `confirmed`.
|
|
25
|
+
- When `business.policies.onlineBookingEnabled` is false, show contact details instead of the form.
|
|
26
|
+
- Every Book button on the page reaches the booking section in every state (also while
|
|
27
|
+
booking is off, loading or failed) — never a click that does nothing.
|
|
28
|
+
- Keep the packaged admin dashboard on `/admin/` (`admin/index.html`).
|
|
29
|
+
- Make text, photos, the logo, brand colours or the heading style owner-editable by
|
|
30
|
+
declaring a field in the site's content schema (`defineSiteContent`, passed to
|
|
31
|
+
`<BookingAdmin content>`) and rendering its resolved value; the dashboard's Website
|
|
32
|
+
page builds its editor from the schema. Defaults are the website's own copy: until
|
|
33
|
+
the owner publishes, the site shows exactly them.
|
|
34
|
+
|
|
35
|
+
## Never
|
|
36
|
+
|
|
37
|
+
- Edit `supabase/migrations/*_booking_engine_*.sql`, `supabase/functions/booking-mailer/`,
|
|
38
|
+
`booking-engine.lock.json` or `node_modules`.
|
|
39
|
+
- Query booking tables, call `booking_*` RPCs, or import `@supabase/supabase-js` for booking data.
|
|
40
|
+
- Put a Supabase secret key or an email provider key (Resend `re_…`) in a `VITE_` variable,
|
|
41
|
+
in source code, in `.env` files of the website or in Git. Provider keys are Edge Function secrets.
|
|
42
|
+
- Compute availability in the browser, skip the code step or fake a confirmation
|
|
43
|
+
(preview mode saves nothing and sends no email).
|
|
44
|
+
- Send booking emails from the website or add another email service: the engine sends them.
|
|
45
|
+
- Rebuild or fork the admin dashboard.
|
|
46
|
+
- Render owner content as HTML (`dangerouslySetInnerHTML`, `innerHTML`) or build image
|
|
47
|
+
URLs yourself: render text as text, images from the resolved `src`/`alt`.
|
|
48
|
+
- Put services, prices, hours, the address, phone or email in the content schema:
|
|
49
|
+
they come from the engine.
|
|
50
|
+
- Rename or reuse a content field id once the site is live: the owner's text is stored
|
|
51
|
+
under it. Add a new id instead.
|
|
52
|
+
|
|
53
|
+
## Checks
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npx booking-engine doctor # project
|
|
57
|
+
npx booking-engine doctor --dist dist # after npm run build
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
A new feature (payments, SMS, staff…) needs a new engine version, not custom
|
|
61
|
+
database code in this project.
|