@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.
Files changed (114) hide show
  1. package/CHANGELOG.md +578 -0
  2. package/LICENSE +21 -0
  3. package/README.md +18 -2
  4. package/THIRD_PARTY_NOTICES.md +41 -0
  5. package/bin/booking-engine.mjs +575 -0
  6. package/bin/connect.mjs +408 -0
  7. package/bin/photos.mjs +82 -0
  8. package/dist/admin/BookingAdmin.d.ts +29 -0
  9. package/dist/admin/BookingAdmin.js +338 -0
  10. package/dist/admin/admin.css +1423 -0
  11. package/dist/admin/alerts.d.ts +10 -0
  12. package/dist/admin/alerts.js +11 -0
  13. package/dist/admin/booking-detail.d.ts +47 -0
  14. package/dist/admin/booking-detail.js +159 -0
  15. package/dist/admin/content-inputs.d.ts +15 -0
  16. package/dist/admin/content-inputs.js +105 -0
  17. package/dist/admin/context.d.ts +41 -0
  18. package/dist/admin/context.js +8 -0
  19. package/dist/admin/drawer.d.ts +14 -0
  20. package/dist/admin/drawer.js +56 -0
  21. package/dist/admin/feedback.d.ts +32 -0
  22. package/dist/admin/feedback.js +70 -0
  23. package/dist/admin/fields.d.ts +27 -0
  24. package/dist/admin/fields.js +146 -0
  25. package/dist/admin/fonts/OFL-Geist-Mono.txt +93 -0
  26. package/dist/admin/fonts/OFL-Geist.txt +93 -0
  27. package/dist/admin/fonts/geist-latin-wght-normal.woff2 +0 -0
  28. package/dist/admin/fonts/geist-mono-latin-wght-normal.woff2 +0 -0
  29. package/dist/admin/icons.d.ts +66 -0
  30. package/dist/admin/icons.js +72 -0
  31. package/dist/admin/image-upload.d.ts +58 -0
  32. package/dist/admin/image-upload.js +111 -0
  33. package/dist/admin/index.d.ts +7 -0
  34. package/dist/admin/index.js +6 -0
  35. package/dist/admin/lucide.generated.d.ts +521 -0
  36. package/dist/admin/lucide.generated.js +76 -0
  37. package/dist/admin/sections/BookingsSection.d.ts +1 -0
  38. package/dist/admin/sections/BookingsSection.js +137 -0
  39. package/dist/admin/sections/EmailSection.d.ts +8 -0
  40. package/dist/admin/sections/EmailSection.js +184 -0
  41. package/dist/admin/sections/HoursSection.d.ts +1 -0
  42. package/dist/admin/sections/HoursSection.js +110 -0
  43. package/dist/admin/sections/OverviewSection.d.ts +1 -0
  44. package/dist/admin/sections/OverviewSection.js +427 -0
  45. package/dist/admin/sections/ServicesSection.d.ts +1 -0
  46. package/dist/admin/sections/ServicesSection.js +236 -0
  47. package/dist/admin/sections/SettingsSection.d.ts +10 -0
  48. package/dist/admin/sections/SettingsSection.js +96 -0
  49. package/dist/admin/sections/WebsiteSection.d.ts +1 -0
  50. package/dist/admin/sections/WebsiteSection.js +228 -0
  51. package/dist/admin/sections.d.ts +22 -0
  52. package/dist/admin/sections.js +29 -0
  53. package/dist/admin/setup.d.ts +1 -0
  54. package/dist/admin/setup.js +45 -0
  55. package/dist/admin/today.d.ts +43 -0
  56. package/dist/admin/today.js +115 -0
  57. package/dist/admin/ui.d.ts +134 -0
  58. package/dist/admin/ui.js +220 -0
  59. package/dist/calendar.d.ts +64 -0
  60. package/dist/calendar.js +139 -0
  61. package/dist/client.d.ts +147 -0
  62. package/dist/client.js +507 -0
  63. package/dist/config.d.ts +25 -0
  64. package/dist/config.js +120 -0
  65. package/dist/content/image.d.ts +20 -0
  66. package/dist/content/image.js +90 -0
  67. package/dist/content/resolve.d.ts +12 -0
  68. package/dist/content/resolve.js +73 -0
  69. package/dist/content/schema.d.ts +119 -0
  70. package/dist/content/schema.js +53 -0
  71. package/dist/content/store.d.ts +48 -0
  72. package/dist/content/store.js +123 -0
  73. package/dist/content/validate.d.ts +33 -0
  74. package/dist/content/validate.js +177 -0
  75. package/dist/errors.d.ts +19 -0
  76. package/dist/errors.js +94 -0
  77. package/dist/generated/manifest.d.ts +6 -0
  78. package/dist/generated/manifest.js +7 -0
  79. package/dist/index.d.ts +20 -0
  80. package/dist/index.js +20 -0
  81. package/dist/presets/hair-salon.d.ts +8 -0
  82. package/dist/presets/hair-salon.js +94 -0
  83. package/dist/presets/index.d.ts +5 -0
  84. package/dist/presets/index.js +6 -0
  85. package/dist/preview.d.ts +18 -0
  86. package/dist/preview.js +134 -0
  87. package/dist/semver.d.ts +16 -0
  88. package/dist/semver.js +55 -0
  89. package/dist/time.d.ts +31 -0
  90. package/dist/time.js +138 -0
  91. package/dist/types.d.ts +477 -0
  92. package/dist/types.js +3 -0
  93. package/dist/vite.d.ts +52 -0
  94. package/dist/vite.js +150 -0
  95. package/docs/BUILD-A-SITE.md +203 -0
  96. package/docs/EMAIL-SETUP.md +224 -0
  97. package/docs/INTEGRATION.md +1112 -0
  98. package/engine.manifest.json +90 -0
  99. package/functions/booking-mailer/deno.json +6 -0
  100. package/functions/booking-mailer/index.ts +44 -0
  101. package/functions/booking-mailer/mailer.js +156 -0
  102. package/functions/booking-mailer/providers/index.js +42 -0
  103. package/functions/booking-mailer/providers/resend.js +75 -0
  104. package/functions/booking-mailer/templates.js +345 -0
  105. package/migrations/0001_core.sql +1673 -0
  106. package/migrations/0002_security_hardening.sql +711 -0
  107. package/migrations/0003_private_definers_and_holds.sql +808 -0
  108. package/migrations/0004_verified_requests.sql +1702 -0
  109. package/migrations/0005_scoped_mailer_credential.sql +347 -0
  110. package/migrations/0006_trusted_client_ip.sql +56 -0
  111. package/migrations/0007_site_content.sql +380 -0
  112. package/migrations/0008_service_images_opening_times.sql +328 -0
  113. package/package.json +85 -4
  114. package/templates/BOOKING_ENGINE.md +61 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,578 @@
1
+ # Changelog — @profitstudio/booking-engine
2
+
3
+ ## 2.0.0-beta.2 — 2026-11-04
4
+
5
+ A dashboard option for public demos. **No migration** (schema 2.0.0-alpha.10),
6
+ no client or Edge Function change, and no change for existing sites.
7
+
8
+ **Added:**
9
+
10
+ - `<BookingAdmin emailDelivery="none">` (optional; default `'live'`) for an
11
+ installation that never emails anyone — a public demo or a showcase. The
12
+ dashboard then never says a customer gets an email: the answer footnote under a
13
+ request, the toast after Confirm / Decline / Cancel and the Decline / Cancel
14
+ dialogs say that no email is sent from the demo, and the Email page's subtitle
15
+ starts with "This demo sends no email". Without the prop (or with `'live'`)
16
+ every text is exactly as in 2.0.0-beta.1. Type: `EmailDelivery` from
17
+ `@profitstudio/booking-engine/admin`.
18
+
19
+ ## 2.0.0-beta.1 — 2026-11-03
20
+
21
+ First public beta, after the hosted rehearsal (a real Supabase project, Resend,
22
+ GitHub and a Hostinger Node.js app; a real booking verified through Gmail).
23
+ **No migration** (schema 2.0.0-alpha.10) and no website code change.
24
+
25
+ **Fixed:**
26
+
27
+ - `connect` no longer stops before the email setup when the owner's Supabase
28
+ login does not exist yet: it deploys and wires the mailer, then lists the
29
+ login as the owner's step (exit code 2).
30
+ - `init` and `connect` add `supabase/.temp/` to `.gitignore`: the Supabase CLI
31
+ writes the project's link there (project ref, database host and user), and
32
+ `supabase init` does not always add its own ignore file.
33
+
34
+ **Added:**
35
+
36
+ - `connect --site-url https://yourdomain.com` stores the existing optional
37
+ secret `BOOKING_ADMIN_URL` (`…/admin/`), so owner alerts get an “Open your
38
+ dashboard” button. Only https addresses; without it nothing changes and
39
+ `connect` says how to add it.
40
+ - The dashboard warns on every page when the daily code-email limit
41
+ (`maxVerificationEmailsPerDay`) is used up — the same count and 24-hour window
42
+ the database uses to refuse new codes.
43
+
44
+ **Docs and prompt:** every Book button on a site must reach the booking section
45
+ in every state (booking off, loading, no services, a load error) — BUILD-A-SITE
46
+ §4, `BOOKING_ENGINE.md` and the Bootstrap Prompt.
47
+
48
+ ## 2.0.0-alpha.13 — 2026-11-03
49
+
50
+ Phase 5C: a shorter setup for tutorial viewers and less AI work per site. **No
51
+ migration** (schema 2.0.0-alpha.10) and no website code change.
52
+
53
+ **Added:**
54
+
55
+ - **`npx booking-engine connect [--admin <email>] [--yes] [--check]`** — connects
56
+ the site to its Supabase project and turns on booking emails with the Supabase
57
+ CLI (`npx supabase@2`): `config.toml`, link, the engine migrations (listed,
58
+ then applied after a yes), the dashboard owner, the mailer deploy (no Docker),
59
+ the mailer SQL one statement at a time and its token stored as the secret
60
+ `BOOKING_MAILER_TOKEN` through a private temporary file — never printed. It
61
+ works only on the project in `.env.local`, refuses a folder linked to another
62
+ one, checks before it acts, is safe to repeat, and stops at the owner's parts
63
+ (sign-in, Auth user, Resend key) with the exact action (exit code 2).
64
+ `--check` changes nothing. It ends by pointing at the alerts address.
65
+ - **`npx booking-engine photos [manifest]`** — crops a site's photos to their
66
+ frames and writes AVIF + WebP at the listed widths without camera data, with
67
+ the project's own `sharp`.
68
+ - **`docs/BUILD-A-SITE.md`** — the short guide (≈ ¼ of INTEGRATION.md): every
69
+ file to wire, the booking API and error table, content, photos, checks.
70
+
71
+ **Changed:** `init` points at the short guide and at `connect`; `mailer-sql`
72
+ prints the same statements `connect` runs; INTEGRATION.md §11 leads with
73
+ `connect` (the manual commands stay as a fallback); EMAIL-SETUP.md likewise.
74
+
75
+ ## 2.0.0-alpha.12 — 2026-11-02
76
+
77
+ Phase 5B: the owner-alert setup gap, and public-release preparation. **No
78
+ migration** (schema 2.0.0-alpha.10) and no website code change. After
79
+ upgrading: `npm install` + `sync`, then rebuild.
80
+
81
+ **Changed (dashboard):**
82
+
83
+ - **New-request alerts are part of setting up.** Every new request is emailed to
84
+ “Send new-request alerts to”, or else to the public business email; with
85
+ neither, nobody was told — silently. Now:
86
+ - *Finish setting up* (Today) has the step “Choose where new-request alerts
87
+ go”, which opens the Email page with that field focused; the test-email
88
+ step names the address (“Send a test email to …”) and opens the test form.
89
+ - The Email page warns while no address is set, says where alerts go once
90
+ one is (its old line “You are emailed about every new request” was not
91
+ always true), and **online booking can only be switched on with a working
92
+ email and an alerts address**. The test email goes to the alerts address
93
+ by default, also right after it is saved.
94
+ - Today's status strip shows “New-request alerts: no address”, and every page
95
+ warns while online booking is on without one (businesses that went live
96
+ before alpha.12). Nothing switches online booking off by itself.
97
+ - “Connect your backend” gives the right advice for where it appears: in
98
+ preview, `.env.local` and a restart; in a production build made without the
99
+ variables, the host's environment variables and a new build (it used to say
100
+ `.env.local` on live sites too).
101
+ - Commands in messages use the pinned Supabase CLI (`npx supabase@2 db push`).
102
+
103
+ **Fixed:**
104
+
105
+ - `defaultSiteContent` / the content store: list items' image fields are `null`
106
+ in the defaults, as typed, also when a default item leaves the image out (they
107
+ were `undefined`).
108
+ - `formatMoney`'s comment showed “$65.00”; whole amounts are “$65”.
109
+
110
+ **Docs (from two fresh-agent site builds):** label times from `slot.time` (a
111
+ device with outdated time-zone data can be an hour off); en-CA times end in a
112
+ period; a calm alternative to resend countdowns and “few left” for briefs that
113
+ rule out pressure; a scrolling day rail at 320 px (with `minmax(0, 1fr)`);
114
+ every preset policy is required, how `preview.business` merges, and that
115
+ preview shows online booking on; `src/content/site.ts` runs in Node during the
116
+ build.
117
+
118
+ **Package:**
119
+
120
+ - `THIRD_PARTY_NOTICES.md` (Lucide icons, ISC; Geist fonts, OFL; the runtime
121
+ dependencies) ships in the package. The Lucide licence in the icon file is a
122
+ legal comment (`/*! @license ISC */`) that bundlers keep when asked.
123
+ - The build fails when `docs/INTEGRATION.md` or `README.md` names another
124
+ version than `package.json` (published versions are immutable, and the
125
+ install line ships inside the package).
126
+
127
+ ## 2.0.0-alpha.11 — 2026-11-02
128
+
129
+ Phase 5A, distribution readiness: what a clean project outside the engine's
130
+ workspace needs. **No migration** (the database stays at schema
131
+ 2.0.0-alpha.10) and no website code change. After upgrading: `npm install` +
132
+ `sync` (it updates the lock and `BOOKING_ENGINE.md`), then rebuild.
133
+
134
+ **Added:**
135
+
136
+ - **`checkBackendEnv(env)`** and `BACKEND_ENV` / `BACKEND_ENV_ALIASES`: checks
137
+ `VITE_SUPABASE_URL` and `VITE_SUPABASE_PUBLISHABLE_KEY` as a build or a
138
+ browser sees them — `configured`, `none` or `invalid` with one sentence per
139
+ problem, naming variables, never values.
140
+
141
+ **Changed:**
142
+
143
+ - **The Vite plugin stops the build on an unusable connection**, before any
144
+ request: half a pair, a misnamed variable (`VITE_SUPABASE_ANON_KEY`, names
145
+ without `VITE_`…), a Supabase dashboard address or a path instead of the
146
+ Project URL, `http://` (except a Supabase on this computer), quotes or
147
+ spaces, and a secret or Resend key — which used to be compiled into the
148
+ public JavaScript when the project was reachable. `SITE_CONTENT_OPTIONAL=1`
149
+ does not bypass it. A build with neither variable still succeeds and its log
150
+ says that online booking will be off on the live site.
151
+ - The client warns in the console when only one of the two values is set
152
+ (it used to fall back to preview or “not available” without a word).
153
+ - **`booking-engine doctor`** runs the same check on the `.env` files, as
154
+ `npm run dev` and a production build read them (quotes and inline comments
155
+ handled like Vite; the shell's variables win).
156
+ - **CLI hints pin the Supabase CLI to `npx supabase@2`**, the line the engine is
157
+ verified with: Supabase CLI 3.0.0 became npm's `latest` on 2026-11-02 and
158
+ asks to confirm with a default of No. It passes the engine's migration checks
159
+ (init, config.toml, dry run, push, upgrade with data, history, no-op re-push);
160
+ its deploy and link steps are not verified yet.
161
+ - **The mailer deploy adds `--use-api`** (bundled on Supabase's servers): no
162
+ Docker on the owner's computer. `init`'s next steps now follow
163
+ INTEGRATION.md §11, including `supabase init`.
164
+ - Docs: presets for any kind of business (a site's own `Preset` for preview
165
+ data and `<BookingAdmin presets>`, INTEGRATION.md §5 and §10); installing
166
+ from a tarball (§3); the build's connection check (§12); doctor (§14); the
167
+ `admin/index.html` template links the site's icon (no 404 in the console).
168
+ EMAIL-SETUP.md no longer points to the engine's private repository.
169
+
170
+ **Builder kit and checks (outside the package):** the Bootstrap Prompt's
171
+ scaffold step survives a folder that is not empty — `npm create vite@latest .`
172
+ exits 0 without creating anything when it finds even a `.DS_Store` or a
173
+ `.claude/` folder — and installs with `--save-exact`; niches without a built-in
174
+ preset get `init` without `--preset` and write their own preset
175
+ (`render-prompt.mjs` also accepts a niche file path). New
176
+ `npm run verify:clean-install`: a clean project outside the workspace (a
177
+ physiotherapy site) installs the packed engine and is checked from the scaffold
178
+ to a fresh-clone build, connected to a local backend — 29/29.
179
+
180
+ ## 2.0.0-alpha.10 — 2026-11-02
181
+
182
+ Phase 4B review: optional service photos, honest opening times, and the
183
+ owner's review adjustments to the dashboard. **Migration `0008`** (schema
184
+ 2.0.0-alpha.10) is additive: existing services, bookings, prices and
185
+ availability do not change, and no website code has to change. After
186
+ upgrading: `npm install` + `sync`, `supabase db push`, a rebuild. Until the
187
+ migration is applied, photos and opening times answer `SCHEMA_INCOMPATIBLE`
188
+ (with the command to run) and everything else works as before — the client
189
+ still accepts databases from schema 2.0.0-alpha.5.
190
+
191
+ **Added:**
192
+
193
+ - **Optional service photos.** `Service.image` / `AdminService.image`:
194
+ `{ url, path, alt, width, height } | null`. The owner adds, replaces and
195
+ removes them in the dashboard; `saveService({ id, image })` (an upload sets
196
+ it, `null` removes it, leaving it out keeps it); `admin.uploadServiceImage`
197
+ (checked, scaled and stripped of camera data in the browser),
198
+ `admin.listServiceImages`, `admin.deleteServiceImages`. Files go to the
199
+ existing `booking-site-media` bucket under `services/` (same admin-only
200
+ policies), apart from the website editor's `site/` folder and its tidy-up.
201
+ The database accepts only that folder and a strict shape. No service needs a
202
+ photo, and the engine imposes no layout: sites render photos in their own
203
+ style (INTEGRATION.md §6).
204
+ - **`getOpeningTimes({ from, to? })`**: each business-local date's opening
205
+ hours after whole-day and partial-day closures (at most 42 days), for "Open
206
+ now" lines. Times only — closure reasons stay private. Preview mode answers
207
+ with the weekly hours.
208
+ - `localTimeLabel(instant, timezone)` → `'HH:MM'` in the business zone (to
209
+ compare with opening hours); `SERVICE_MEDIA_SCHEMA`; types `ServiceImage`,
210
+ `ServiceImageInput`, `OpeningTimes`, `OpeningTimesDay`, `OpeningTimesQuery`.
211
+ - `mediaUrl()` also resolves service photo paths.
212
+
213
+ **Changed (dashboard):**
214
+
215
+ - **Services:** a Photo field per service — add (button or drop a file),
216
+ replace, remove (with Undo), and a one-line description for screen readers;
217
+ thumbnails in the list (a quiet tile for services without one). After a save
218
+ that replaced or removed a photo, or a deleted service, unused `services/`
219
+ files older than a day are removed. On a database older than alpha.10 the
220
+ field says what to run and everything else still saves.
221
+ - **Today:** the requests panel starts compact — the count, the three most
222
+ urgent requests (two on phones) with Decline / Confirm, "Show all N" in
223
+ place and Open in Bookings; holds that have ended are named in its header;
224
+ any request opens its booking. The schedule now fits in the first screen.
225
+ - **Today's schedule:** every appointment shows the richest label that fits
226
+ whole (name, service and time — down to the time alone; never cut mid-word);
227
+ blocks open their booking by click, tap or keyboard, with a visible focus
228
+ ring (alpha.9's entrance animation hid it).
229
+ - The Website editor's image fields also accept a dropped file (shared upload
230
+ component).
231
+
232
+ **Reference site and builder kit (outside the package):** Copper & Comb shows
233
+ service photos in "The menu" — on pointer screens a captioned plate beside the
234
+ typeset menu follows the service pointed at or focused; on touch screens a row
235
+ of plates captioned with the service names (price and Book stay in the menu) — and is unchanged when no service
236
+ has a photo. Four AI-generated sample photos (Cut & Style, Blow-Dry & Style,
237
+ Balayage, Deep Conditioning Treatment) are seed data the owner replaces in the
238
+ dashboard. The booking month is calmer (one mark per day at most: a dot for
239
+ open, "n left", struck-through full days, quiet closed days) and the
240
+ appointment slip stands as tall as the calendar. "Open now" lines use
241
+ `getOpeningTimes`, so partial-day closures show ("Closed now · reopens today
242
+ at 2:00 PM"), with the previous behaviour as the fallback; the 14-day
243
+ availability "outlook" now loads only when the booking call to action comes
244
+ near. The builder kit asks generated sites to treat service photos as
245
+ optional engine data in their own design and to base "Open now" on
246
+ `getOpeningTimes`.
247
+
248
+ **Local test stack (repository only):** the gateway serves the Storage API —
249
+ uploads, lists and deletes run as the caller's role against the real bucket
250
+ policies; bucket size and type limits apply; public files by URL — so photo
251
+ permissions and the owner's upload workflow are tested locally.
252
+
253
+ ## 2.0.0-alpha.9 — 2026-11-02
254
+
255
+ Phase 4B: the "Studio" dashboard and calendar helpers for booking interfaces.
256
+ No migration: the database stays at schema 2.0.0-alpha.7 and the client
257
+ accepts the same databases as before. After upgrading: `npm install` + `sync`,
258
+ a rebuild, and — if the site themes the dashboard — the theme change below.
259
+
260
+ **Breaking (dashboard theme):** the dashboard now keeps its own design for
261
+ every business. Only `--pbe-accent` and `--pbe-accent-text`, set for both
262
+ `data-mode="light"` and `data-mode="dark"`, brand it; every other `--pbe-*`
263
+ theme variable is ignored (INTEGRATION.md §10, "Upgrading a dashboard theme
264
+ from 2.0.0-alpha.8"). A site that set none gets a neutral graphite accent.
265
+
266
+ **Added:**
267
+
268
+ - Calendar view helpers (INTEGRATION.md §8–§9): `monthGrid` (whole weeks plus
269
+ the range to request — at most 42 days, so one `getAvailability` call fills a
270
+ month), `monthOf`, `addMonths`, `daysInMonth`, `firstDayOfWeek`,
271
+ `startOfWeek`, `weekDates`, `partOfDay` / `groupSlotsByPartOfDay` /
272
+ `PARTS_OF_DAY` (Morning before 12:00, Afternoon before 17:00, Evening),
273
+ `isFewLeft` / `FEW_LEFT_MAX` and `nextAvailableDay`. They only reshape data
274
+ the server returned, on calendar-date strings: no availability is computed
275
+ in the browser.
276
+ - The dashboard ships its fonts: Geist and Geist Mono (OFL, licences included)
277
+ in `dist/admin/fonts/`, loaded by `admin.css` through relative URLs (any
278
+ bundler that resolves CSS `url()` — Vite does). Nothing reaches the public site.
279
+
280
+ **Changed (dashboard):**
281
+
282
+ - New design system: separately tuned Light and Dark palettes with clear
283
+ surface steps and three text tiers (every text tier ≥ 4.5:1 on every
284
+ surface), one component family, Lucide icons (ISC) in one stroke and three sizes.
285
+ - Shell: sidebar with the business mark in the accent, grouped navigation, the
286
+ count of requests waiting, the website's state, a booking search (⌘K /
287
+ Ctrl+K) and the appearance switch; a top bar with the business's clock and
288
+ time zone; a compact layout from 900 to 1199 px; below 900 px a top bar, a
289
+ bottom tab bar and a More sheet (with the appearance switch).
290
+ - **Today:** requests that need an answer lead the page (accent-tinted, soonest
291
+ hold first, live countdown, inline Confirm / Decline); KPI tiles for today
292
+ (with the last 14 days), the next 7 days, booked time today and booked value
293
+ this week (honest "from" prices, requests counted apart); a one-lane schedule
294
+ with a now line; Now & next; closures ahead; system health; the setup checklist.
295
+ - **Bookings:** Upcoming / Needs your answer / Past 30 days / Cancelled; a search
296
+ a year back and ahead (name, email, phone, reference, service); a table
297
+ grouped by day; a detail panel (docked from 1200 px, a dialog below, a sheet
298
+ on phones) with the hold, contact links, verification, the reference with a
299
+ copy button, the activity and only the actions valid for the status. Decline
300
+ and Cancel ask first, in the dashboard's own dialogs.
301
+ - Status labels: Request, Confirmed, Done, Cancelled, No-show, Hold expired;
302
+ the "Needs confirmation" view is now "Needs your answer".
303
+ - Website editor, Services (the editor opens in a drawer), Hours & closures,
304
+ Email & online booking, Booking policies and Business follow the new system;
305
+ settings enable Save only when something changed; sign-in shows the business.
306
+
307
+ **Reference site and builder kit (outside the package):** the Copper & Comb
308
+ demo now shows the owner-approved "Atelier" website (Newsreader + Instrument
309
+ Sans) and a focused booking view at `#book` built on the helpers above — field
310
+ ids unchanged; its brand colours are now checked against the new surfaces
311
+ (`#f4eee4` light, `#2a1e17` dark). The builder kit asks generated sites for the
312
+ same booking pattern and for an accent-only dashboard theme.
313
+
314
+ ## 2.0.0-alpha.8 — 2026-11-01
315
+
316
+ Dashboard redesign (Phase 4, Visual Excellence). No migration: the database
317
+ stays at schema 2.0.0-alpha.7, and the client accepts the same databases as
318
+ before. Nothing to do after upgrading besides `npm install` + `sync` and a
319
+ rebuild; a site's theme keeps working (its `--pbe-*` tokens still apply).
320
+
321
+ **Changed:**
322
+
323
+ - New application shell: a sidebar with the business mark, icons and a count of
324
+ requests waiting (desktop); below 900 px a slim top bar and a bottom tab bar
325
+ (Today, Bookings, Website, Services, More — the rest opens as a sheet).
326
+ - New **Today** landing page: requests waiting, today and the next 7 days,
327
+ the website's publish state, upcoming appointments, setup progress, email
328
+ health and quick actions. Bookings open on a sub-view via `#bookings/pending`.
329
+ - Bookings: one surface per day with dividers, times in the business's own
330
+ format ("9:00 AM to 10:00 AM"), a readable time zone ("Pacific Time"),
331
+ Confirm as the primary action, quiet Decline/Cancel.
332
+ - Website editor on phones: a section picker instead of a scrolling tab row; a
333
+ more compact save bar.
334
+ - Email & online booking: the technical wiring is folded into "Technical
335
+ details" (opened automatically when something is wrong); the email log shows
336
+ 8 rows with "Show all".
337
+ - Design tokens: refined neutrals, type scale, radius and elevation for light
338
+ and dark; new `--pbe-sidebar`, `--pbe-accent-soft`, `--pbe-shadow-lg`.
339
+ - Accessibility: a skip link, `aria-current` navigation, the pending count as a
340
+ description (link names stay "Bookings"), 44 px phone actions.
341
+
342
+ ## 2.0.0-alpha.7 — 2026-11-01
343
+
344
+ Owner customization. Migration `0007_site_content` (new objects only; booking
345
+ data, functions and privileges unchanged). The client still accepts an alpha.5
346
+ database for booking (`requiredSchemaVersion` stays 2.0.0-alpha.5); the new
347
+ content methods answer `SCHEMA_INCOMPATIBLE` until 0007 is pushed. After
348
+ upgrading: `sync`, `db push`, redeploy `booking-mailer` (INTEGRATION.md §13).
349
+
350
+ **Added:**
351
+
352
+ - Website content (INTEGRATION.md §15): a site declares what its owner may edit
353
+ with `defineSiteContent` — text, long text, links, images, colours (with a
354
+ WCAG contrast floor), choices, toggles and lists — and renders typed values
355
+ from `createSiteContentStore` (build-time snapshot or cached copy on the first
356
+ paint, then the published copy). Defaults are the site's own copy.
357
+ - Draft → preview → publish: `getSiteContent()` (public, published only),
358
+ `admin.getSiteContent/saveSiteContentDraft/publishSiteContent/
359
+ discardSiteContentDraft` with optimistic concurrency, and an admin-only
360
+ `?preview=draft` on the real site. The database validates every document
361
+ (keys, plain text, sizes, image paths).
362
+ - Images: Storage bucket `booking-site-media` — public reads, admin-only
363
+ list/upload/delete, JPEG/PNG/WebP/AVIF only, 5 MB, no overwrites;
364
+ `admin.uploadSiteImage` (camera photos are redrawn in the browser so their
365
+ EXIF data — e.g. the GPS position — is never published; large images are
366
+ downscaled to WebP), `mediaUrl(path)`.
367
+ - `readSiteContentSnapshot` / `siteContentSnapshotTag`, and the Vite plugin
368
+ `publishedSiteContent` (`@profitstudio/booking-engine/vite`) that bakes the
369
+ published content and the search title/description into a static build. If a
370
+ configured backend cannot be read, the build **fails** (the host keeps the
371
+ live site) instead of publishing the defaults; `SITE_CONTENT_OPTIONAL=1`
372
+ builds with the defaults on purpose.
373
+ - Dashboard **Website** section (`<BookingAdmin content>`), built from the
374
+ site's schema: section tabs, per-field limits and errors, image upload with
375
+ alt text, colour contrast, lists, unsaved-changes guard.
376
+ - Dashboard theme: Light / Dark / System switch (kept per browser), root
377
+ `data-mode`, a complete token set (`--pbe-surface-hover`, `--pbe-border-strong`,
378
+ input, status `-bg`/`-border`, `--pbe-shadow`…) with a dark set; on phones the
379
+ header wraps instead of overflowing.
380
+ - Website editor: the save bar names the fields that block saving and their
381
+ section (tabs marked in red); counters stay next to “Use default”; labels and
382
+ tags wrap cleanly on phones.
383
+
384
+ **Changed:**
385
+
386
+ - Customer emails say “reply to this email” only when replies reach the
387
+ business (a public business email is set, used as Reply-To); otherwise they
388
+ point to the phone number, or simply to contacting the business.
389
+ - `BOOKING_ENGINE.md` (replaced by `sync`) gains the website-content rules.
390
+
391
+ ## 2.0.0-alpha.6 — 2026-11-01
392
+
393
+ Security patch from the hosted verification. Migration `0006_trusted_client_ip`
394
+ (no data change). Nothing to do after upgrading besides the usual `sync` +
395
+ `db push`; the client is unchanged and still accepts an alpha.5 database
396
+ (`requiredSchemaVersion` stays 2.0.0-alpha.5).
397
+
398
+ **Fixed:**
399
+
400
+ - Per-client limits identify a caller only by `cf-connecting-ip`, the header
401
+ the platform's edge sets (Cloudflare, in front of every hosted Supabase
402
+ project, refuses requests that send their own). `x-real-ip` and
403
+ `x-forwarded-for` are no longer read: on hosted Supabase the first
404
+ `x-forwarded-for` entry is whatever the client sent, so where
405
+ `cf-connecting-ip` was missing a client could have opened fresh rate-limit
406
+ buckets at will. Without a usable `cf-connecting-ip` a request now shares the
407
+ `unknown` bucket, limited by the site-wide hourly cap (fail-closed).
408
+
409
+ ## 2.0.0-alpha.5 — 2026-11-01
410
+
411
+ Phase 2C hardening from the review of the email path (ADR 0003). Migration
412
+ `0005_scoped_mailer_credential` (existing data and queued emails preserved).
413
+
414
+ **Changed — action needed after upgrading:**
415
+
416
+ - The database now starts `booking-mailer` with a **mailer-only token**
417
+ instead of a Supabase secret key. The function accepts only that token
418
+ (constant-time comparison; 503 when its secret is missing) and no Supabase
419
+ key at all. After `npx booking-engine sync` + `npx supabase db push`:
420
+ 1. `npx supabase functions deploy booking-mailer --no-verify-jwt`;
421
+ 2. run the new `npx booking-engine mailer-sql` output in the SQL Editor and
422
+ copy the `booking_mailer_token` it returns into the Edge Function secret
423
+ `BOOKING_MAILER_TOKEN`;
424
+ 3. **delete the `booking_mailer` secret key** alpha.4 asked you to create
425
+ (Project Settings → API Keys). The migration already removed its copy from
426
+ Vault.
427
+ - `EmailStatus.wiring` is now `{ pgNet, configured, schedule, lastStart }`;
428
+ `counts` gains `oldestQueuedAt` and `retryable`. `requiredSchemaVersion` is
429
+ 2.0.0-alpha.5.
430
+
431
+ **Added:**
432
+
433
+ - The dashboard shows the mailer's answer to its last start (200, 401 token
434
+ mismatch, 503 secret missing, 404 not deployed) and a warning on every page
435
+ while emails fail or wait for more than 5 minutes.
436
+ - `admin.retryFailedEmails()` / **Retry failed emails**: emails that failed in
437
+ the last 23 hours go back in the queue (codes excepted); Resend's 24-hour
438
+ idempotency means nobody receives one twice.
439
+ - `booking.configure_mailer(url, p_rotate)` (owner only) returns the token and
440
+ a setup check.
441
+
442
+ **Fixed:**
443
+
444
+ - `booking-engine doctor --dist` without a folder no longer crashes (it means
445
+ `dist`); an absolute folder (e.g. a downloaded copy of the live site) works;
446
+ a folder that does not exist is an error instead of a silent pass.
447
+ - The `supabase/config.toml` comment written by `init`/`sync` and the `doctor`
448
+ message about `verify_jwt` no longer say the mailer takes a secret key;
449
+ `sync` replaces the alpha.4 comment.
450
+
451
+ ## 2.0.0-alpha.4 — 2026-11-01
452
+
453
+ Phase 2B: verified booking requests and essential emails. Migration
454
+ `0004_verified_requests` (existing data preserved) and a new engine-owned Edge
455
+ Function, `supabase/functions/booking-mailer/` (design: ADR 0002).
456
+
457
+ **Breaking (alpha):**
458
+
459
+ - `createBooking()` / `booking_create` are closed and return
460
+ `VERIFICATION_REQUIRED`. Booking is now two steps: `requestBooking()` holds
461
+ the time for the verification window (default 15 min) and emails a 6-digit
462
+ code; `verifyBooking({ requestId, code })` turns it into a request
463
+ (`pending`) or a booking (`confirmed`). `resendVerificationCode()` sends a
464
+ new code (60 s apart, at most 3, same window; `resendsLeft` is returned from
465
+ the start). `cancelBookingRequest(requestId)` releases a hold at once when
466
+ the visitor chooses another time. Requests and confirmations keep their
467
+ shapes.
468
+ - **Online booking is off after the upgrade** (`onlineBookingEnabled`) until a
469
+ test email has been delivered and the owner switches it on. Requests
470
+ meanwhile return `BOOKING_DISABLED`; sites should show contact details.
471
+ - `requiredSchemaVersion` is 2.0.0-alpha.4: an alpha.4 client needs the alpha.4
472
+ database.
473
+
474
+ **Added:**
475
+
476
+ - One-time codes: CSPRNG, stored only as a salted SHA-256 hash, 5 attempts,
477
+ single use, idempotent verification (a retried verify returns the same
478
+ booking). The time is rechecked when the code is right. Unverified requests
479
+ are invisible to the owner and are deleted when they lapse.
480
+ - Instant confirmation (`autoConfirm`) is available again — for verified
481
+ requests only. The per-email booking cap applies at verification.
482
+ - Emails: code, request received, confirmed, declined, cancelled, request
483
+ expired, owner alert, test — queued in a transactional outbox (one row per
484
+ de-duplication key), sent by `booking-mailer` through Resend with the outbox
485
+ id as idempotency key, retried after 1/4/16/64 minutes, codes removed once
486
+ sent. A small provider interface keeps Resend replaceable.
487
+ - The database starts the mailer itself (pg_net + Vault; `booking-engine
488
+ mailer-sql` prints the one-time SQL) and a pg_cron job handles retries and
489
+ expiry notices. The function accepts only a project secret key
490
+ (`@supabase/server`, `auth: 'secret:*'`, deployed with `--no-verify-jwt`).
491
+ A broken email setup never blocks a booking.
492
+ - Abuse and cost limits: per address 5 code emails/hour and 10/day; site-wide
493
+ code emails per day (owner setting, default 50 — fits Resend's free plan);
494
+ test emails 10/hour. Existing per-client and site-wide request limits stay.
495
+ - Owner settings: `ownerNotificationEmail` (default: public email),
496
+ `verificationWindowMinutes` (5–30), `maxVerificationEmailsPerDay`,
497
+ `onlineBookingEnabled`. `AdminBooking.emailVerified`.
498
+ - Admin: **Email & online booking** section (delivery health, wiring check,
499
+ test email, recent emails with masked addresses, email settings, the
500
+ online-booking switch); instant confirmation in Booking policies; setup
501
+ checklist items; decline/cancel messages say whether the client is emailed.
502
+ - CLI: `init`/`sync` install and update the mailer function (hash-locked; an
503
+ edited file is never overwritten), add `[functions.booking-mailer]
504
+ verify_jwt = false` to `supabase/config.toml`, verify the package before
505
+ writing anything; `doctor` checks the function, finds email provider keys
506
+ in env files, source and build output, and warns about remaining
507
+ `createBooking()` calls; new `mailer-sql`.
508
+ - Docs: `docs/EMAIL-SETUP.md` (domain, DNS, sender, limits, costs, testing,
509
+ troubleshooting); INTEGRATION.md §6–§8, §11, “Upgrading from alpha.3”.
510
+
511
+ **Upgrade from alpha.3:** install, `npx booking-engine sync`, `npx supabase db
512
+ push`, email setup (EMAIL-SETUP.md), deploy the function, update the website's
513
+ booking flow (INTEGRATION.md, “Upgrading from 2.0.0-alpha.3”), send a test
514
+ email, switch online booking on.
515
+
516
+ ## 2.0.0-alpha.3 — 2026-11-01
517
+
518
+ Phase 2A: privileged-function boundary and booking holds. Migration
519
+ `0003_private_definers_and_holds` (existing data preserved).
520
+
521
+ - **No SECURITY DEFINER function in an exposed schema.** The two privileged
522
+ operations moved to the private schema (`booking.get_availability`,
523
+ `booking.create_booking`); `public.booking_get_availability` and
524
+ `public.booking_create` are SECURITY INVOKER wrappers with unchanged
525
+ signatures and results. Supabase's linter (splinter) reports no warnings.
526
+ - **Booking holds.** A website request holds its time until `holdExpiresAt`
527
+ (new owner setting `pendingHoldMinutes`, default 24 h, never past the
528
+ start). A lapsed hold stops blocking availability and is released in the
529
+ same transaction as an overlapping new booking. New status `expired`; the
530
+ owner can still confirm an expired request while its time is free
531
+ (otherwise `CONFLICT` / `slot_taken`). Lapsed requests no longer count
532
+ against the per-email limit.
533
+ - **Instant confirmation disabled** until requests can be verified by email:
534
+ `autoConfirm` is forced off (database constraint) and refused by the admin
535
+ API. *Behaviour change:* sites that had it on now receive requests.
536
+ - New admin-only `requestDiagnostics()` / `booking_admin_request_diagnostics()`
537
+ to verify, on a real host, which request headers identify the caller.
538
+ - `BookingConfirmation.holdExpiresAt`, `AdminBooking.holdExpiresAt`,
539
+ `BookingPolicies.pendingHoldMinutes`, `AdminSettings.pendingHoldMinutes`
540
+ added (additive).
541
+ - Admin: Expired badge with Confirm/Decline, “time held until …”, the hold
542
+ window in Booking policies; tables become cards on phones (fixes overflow).
543
+ - Explicit deny-all policies on the two definer-only tables.
544
+
545
+ ## 2.0.0-alpha.2 — 2026-11-01
546
+
547
+ Security hardening after an independent review. Migration `0002_security_hardening`
548
+ (additive; existing data preserved; signatures unchanged).
549
+
550
+ - `booking_create` rejects non-finite (`infinity`) and out-of-window start times
551
+ before computing slots; slot generation is bounded for every input.
552
+ - Rate limits hold under concurrent requests (per-email and per-client
553
+ transaction locks). IPv6 clients are grouped by /64. A missing, blank or
554
+ invalid client IP is one shared, limited bucket.
555
+ - New owner setting `maxWebsiteBookingsPerHour` (default 30): a site-wide cap
556
+ on new website bookings per rolling hour.
557
+ - `RATE_LIMITED` no longer says which limit was hit, and limits are checked
558
+ after the slot check, so the endpoint does not reveal whether an email
559
+ address has upcoming bookings.
560
+ - Client identifiers in `request_log` are hashed with a per-installation salt.
561
+ - `service_role` (server-side callers) can use the public read functions.
562
+ - `booking.add_admin` requires a confirmed email; `booking.remove_admin`
563
+ fails loudly when no admin matched.
564
+
565
+ Integration (from the first prompt-first build):
566
+
567
+ - `createBooking` checks every field rule in the browser too, so preview mode
568
+ reports the same `INVALID_INPUT` fields as the server, including
569
+ `requirePhone`.
570
+ - New helpers `formatClockTime` (opening hours, `24:00`) and `timeZoneLabel`.
571
+ - Admin theme variables have zero-specificity defaults; the full list is documented.
572
+ - INTEGRATION.md: preview time zone and sample data, field rules, admin-only
573
+ codes, known 2.0 limits.
574
+
575
+ ## 2.0.0-alpha.1 — 2026-11-01
576
+
577
+ First local alpha: schema, availability and booking functions, RLS, typed
578
+ client, preview mode, admin dashboard, CLI, Hair Salon preset.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Youssef Es-salhi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,19 @@
1
- # Temporary Holding Version
1
+ # @profitstudio/booking-engine
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Secure, versioned booking engine for independently owned small-business
4
+ websites (Supabase + React). It provides the database migrations, a typed
5
+ client, availability and booking logic enforced in Postgres, an admin
6
+ dashboard (with owner editing of the website's declared content) and a CLI. The public website is built around it — by hand or with
7
+ an AI builder.
8
+
9
+ - Build a site (the short guide): [docs/BUILD-A-SITE.md](docs/BUILD-A-SITE.md)
10
+ - Integration contract: [docs/INTEGRATION.md](docs/INTEGRATION.md)
11
+ - Booking emails (Resend, DNS, limits, costs): [docs/EMAIL-SETUP.md](docs/EMAIL-SETUP.md)
12
+ - Changes and upgrade notes: [CHANGELOG.md](CHANGELOG.md)
13
+ - Versions: see `engine.manifest.json`
14
+
15
+ **Status:** 2.0.0-beta.2 — public beta (owner-editable website content, the Studio dashboard, calendar helpers for booking UIs, optional service photos, opening times with closures; builds check the Supabase connection; the dashboard asks where new-request alerts go; `connect` sets up Supabase and email, `photos` prepares a site's photos). Install the exact version.
16
+
17
+ ## Licence
18
+
19
+ MIT © 2026 Youssef Es-salhi — see `LICENSE`. Bundled third-party icons and fonts keep their own licences (`THIRD_PARTY_NOTICES.md`).
@@ -0,0 +1,41 @@
1
+ # Third-party notices — @profitstudio/booking-engine
2
+
3
+ Parts of other projects that this package contains or installs. The package's
4
+ own licence is the `license` field of its `package.json`.
5
+
6
+ ## Included in the package
7
+
8
+ | Component | Where | Licence | Notice |
9
+ |---|---|---|---|
10
+ | Lucide icons (54 icons from lucide-static 1.66.0, as SVG path data) | `dist/admin/lucide.generated.js` | ISC | The full licence is the `/*! @license ISC … */` comment at the top of that file, and below |
11
+ | Geist and Geist Mono variable fonts (latin), from @fontsource-variable 5.3.0 | `dist/admin/fonts/` | SIL Open Font License 1.1 | `OFL-Geist.txt` and `OFL-Geist-Mono.txt` next to the fonts |
12
+
13
+ ## Installed or loaded alongside (not included)
14
+
15
+ | Component | How | Licence |
16
+ |---|---|---|
17
+ | @supabase/supabase-js 2.118.0 | npm dependency of this package | MIT |
18
+ | React | the website's own dependency (peer) | MIT |
19
+ | @supabase/server 1.9.2 | imported by the `booking-mailer` Edge Function when Supabase deploys it (`deno.json`) | MIT |
20
+
21
+ ## Keeping the notices in a website build
22
+
23
+ Minifiers drop comments by default, including licence comments. To keep
24
+ `/*! … */` licence comments in a Vite 8 production build, add to
25
+ `vite.config.ts`: `build: { rolldownOptions: { output: { comments: { legal: true } } } }`.
26
+
27
+ ## Lucide — ISC License
28
+
29
+ Copyright (c) 2026 Lucide Icons and Contributors
30
+
31
+ Permission to use, copy, modify, and/or distribute this software for any
32
+ purpose with or without fee is hereby granted, provided that the above
33
+ copyright notice and this permission notice appear in all copies.
34
+
35
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
36
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
37
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
38
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
39
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
40
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
41
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.