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