@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/dist/semver.js ADDED
@@ -0,0 +1,55 @@
1
+ // Minimal semantic-version comparison (MAJOR.MINOR.PATCH[-pre.release]).
2
+ export function parseVersion(version) {
3
+ const m = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/.exec(version.trim());
4
+ if (!m)
5
+ return null;
6
+ return {
7
+ major: Number(m[1]),
8
+ minor: Number(m[2]),
9
+ patch: Number(m[3]),
10
+ pre: m[4] ? m[4].split('.').map((p) => (/^\d+$/.test(p) ? Number(p) : p)) : [],
11
+ };
12
+ }
13
+ /** -1, 0 or 1. Throws on an invalid version. */
14
+ export function compareVersions(a, b) {
15
+ const x = parseVersion(a);
16
+ const y = parseVersion(b);
17
+ if (!x || !y)
18
+ throw new Error(`Invalid version: ${!x ? a : b}`);
19
+ for (const key of ['major', 'minor', 'patch']) {
20
+ if (x[key] !== y[key])
21
+ return x[key] < y[key] ? -1 : 1;
22
+ }
23
+ if (!x.pre.length || !y.pre.length)
24
+ return x.pre.length === y.pre.length ? 0 : x.pre.length ? -1 : 1;
25
+ for (let i = 0; i < Math.max(x.pre.length, y.pre.length); i++) {
26
+ const p = x.pre[i];
27
+ const q = y.pre[i];
28
+ if (p === undefined)
29
+ return -1;
30
+ if (q === undefined)
31
+ return 1;
32
+ if (p === q)
33
+ continue;
34
+ if (typeof p === 'number' && typeof q === 'number')
35
+ return p < q ? -1 : 1;
36
+ if (typeof p === 'number')
37
+ return -1;
38
+ if (typeof q === 'number')
39
+ return 1;
40
+ return p < q ? -1 : 1;
41
+ }
42
+ return 0;
43
+ }
44
+ /**
45
+ * A database at `schemaVersion` can serve a client that requires `required`
46
+ * when the MAJOR matches and the database is not older. Newer minor versions
47
+ * only add, so older clients keep working.
48
+ */
49
+ export function isSchemaCompatible(schemaVersion, required) {
50
+ const s = parseVersion(schemaVersion);
51
+ const r = parseVersion(required);
52
+ if (!s || !r)
53
+ return false;
54
+ return s.major === r.major && compareVersions(schemaVersion, required) >= 0;
55
+ }
package/dist/time.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ /** Today's date in a time zone, "YYYY-MM-DD". */
2
+ export declare function todayInTimeZone(timezone: string, now?: Date): string;
3
+ /** "YYYY-MM-DD" plus n days (calendar arithmetic, no time zone involved). */
4
+ export declare function addDays(date: string, days: number): string;
5
+ /** ISO weekday of a calendar date: 1 = Monday … 7 = Sunday. */
6
+ export declare function weekdayOf(date: string): 1 | 2 | 3 | 4 | 5 | 6 | 7;
7
+ /** Format a calendar date ("YYYY-MM-DD") for display, e.g. "Tuesday, November 3". */
8
+ export declare function formatDate(date: string, locale?: string, options?: Intl.DateTimeFormatOptions): string;
9
+ /** Format an instant as a time in the business time zone, e.g. "9:30 AM". */
10
+ export declare function formatTime(instant: string, timezone: string, locale?: string, options?: Intl.DateTimeFormatOptions): string;
11
+ /** Format an instant as date and time in the business time zone. */
12
+ export declare function formatDateTime(instant: string, timezone: string, locale?: string, options?: Intl.DateTimeFormatOptions): string;
13
+ /**
14
+ * Format a business-local clock time such as an opening hour ("09:00",
15
+ * "24:00" = midnight) for display, e.g. "9:00 AM". No time zone involved.
16
+ */
17
+ export declare function formatClockTime(hhmm: string, locale?: string, options?: Intl.DateTimeFormatOptions): string;
18
+ /** A readable name for a time zone, e.g. "Pacific Time"; falls back to the IANA id. */
19
+ export declare function timeZoneLabel(timezone: string, locale?: string): string;
20
+ /** Format minor units as money, locale-aware; whole amounts without decimals: 6500 + "USD" → "$65", 4550 → "$45.50". */
21
+ export declare function formatMoney(cents: number, currency: string, locale?: string): string;
22
+ /** The visitor's device time zone, when the browser exposes it. */
23
+ export declare function deviceTimeZone(): string | null;
24
+ /** True when the visitor's device is in a different zone than the business. */
25
+ export declare function isDifferentTimeZone(businessTimeZone: string): boolean;
26
+ /** Minutes between UTC and a zone at an instant (positive east of UTC). */
27
+ export declare function timeZoneOffsetMinutes(utcMs: number, timezone: string): number;
28
+ /** The UTC instant (ms) of a local wall-clock time in a zone. "24:00" = end of day. */
29
+ export declare function zonedTimeToUtc(date: string, time: string, timezone: string): number;
30
+ /** Local "HH:MM" of an instant in a zone. */
31
+ export declare function localTimeLabel(instant: string | number, timezone: string): string;
package/dist/time.js ADDED
@@ -0,0 +1,138 @@
1
+ // Business-time helpers. Booking times are always shown in the BUSINESS time
2
+ // zone (the zone the appointment happens in), never the visitor's device zone.
3
+ // Uses only the built-in Intl API.
4
+ const DATE_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
5
+ function parseDate(date) {
6
+ const m = DATE_RE.exec(date);
7
+ if (!m)
8
+ throw new Error(`Expected a date like 2026-11-03, got "${date}"`);
9
+ return [Number(m[1]), Number(m[2]), Number(m[3])];
10
+ }
11
+ function pad(n) {
12
+ return String(n).padStart(2, '0');
13
+ }
14
+ /** Today's date in a time zone, "YYYY-MM-DD". */
15
+ export function todayInTimeZone(timezone, now = new Date()) {
16
+ const parts = new Intl.DateTimeFormat('en-CA', {
17
+ timeZone: timezone,
18
+ year: 'numeric',
19
+ month: '2-digit',
20
+ day: '2-digit',
21
+ }).formatToParts(now);
22
+ const get = (type) => parts.find((p) => p.type === type)?.value ?? '';
23
+ return `${get('year')}-${get('month')}-${get('day')}`;
24
+ }
25
+ /** "YYYY-MM-DD" plus n days (calendar arithmetic, no time zone involved). */
26
+ export function addDays(date, days) {
27
+ const [y, m, d] = parseDate(date);
28
+ const t = new Date(Date.UTC(y, m - 1, d + days));
29
+ return `${t.getUTCFullYear()}-${pad(t.getUTCMonth() + 1)}-${pad(t.getUTCDate())}`;
30
+ }
31
+ /** ISO weekday of a calendar date: 1 = Monday … 7 = Sunday. */
32
+ export function weekdayOf(date) {
33
+ const [y, m, d] = parseDate(date);
34
+ const js = new Date(Date.UTC(y, m - 1, d)).getUTCDay();
35
+ return (js === 0 ? 7 : js);
36
+ }
37
+ /** Format a calendar date ("YYYY-MM-DD") for display, e.g. "Tuesday, November 3". */
38
+ export function formatDate(date, locale, options = { weekday: 'long', month: 'long', day: 'numeric' }) {
39
+ const [y, m, d] = parseDate(date);
40
+ return new Intl.DateTimeFormat(locale, { ...options, timeZone: 'UTC' }).format(new Date(Date.UTC(y, m - 1, d)));
41
+ }
42
+ /** Format an instant as a time in the business time zone, e.g. "9:30 AM". */
43
+ export function formatTime(instant, timezone, locale, options = { hour: 'numeric', minute: '2-digit' }) {
44
+ return new Intl.DateTimeFormat(locale, { ...options, timeZone: timezone }).format(new Date(instant));
45
+ }
46
+ /** Format an instant as date and time in the business time zone. */
47
+ export function formatDateTime(instant, timezone, locale, options = { dateStyle: 'full', timeStyle: 'short' }) {
48
+ return new Intl.DateTimeFormat(locale, { ...options, timeZone: timezone }).format(new Date(instant));
49
+ }
50
+ /**
51
+ * Format a business-local clock time such as an opening hour ("09:00",
52
+ * "24:00" = midnight) for display, e.g. "9:00 AM". No time zone involved.
53
+ */
54
+ export function formatClockTime(hhmm, locale, options = { hour: 'numeric', minute: '2-digit' }) {
55
+ const m = /^(\d{2}):(\d{2})$/.exec(hhmm);
56
+ if (!m)
57
+ throw new Error(`Expected a time like 09:30, got "${hhmm}"`);
58
+ const date = new Date(Date.UTC(2000, 0, 1, Number(m[1]) % 24, Number(m[2])));
59
+ return new Intl.DateTimeFormat(locale, { ...options, timeZone: 'UTC' }).format(date);
60
+ }
61
+ /** A readable name for a time zone, e.g. "Pacific Time"; falls back to the IANA id. */
62
+ export function timeZoneLabel(timezone, locale) {
63
+ try {
64
+ const part = new Intl.DateTimeFormat(locale, { timeZone: timezone, timeZoneName: 'longGeneric' })
65
+ .formatToParts(new Date())
66
+ .find((p) => p.type === 'timeZoneName');
67
+ return part?.value ?? timezone;
68
+ }
69
+ catch {
70
+ return timezone;
71
+ }
72
+ }
73
+ /** Format minor units as money, locale-aware; whole amounts without decimals: 6500 + "USD" → "$65", 4550 → "$45.50". */
74
+ export function formatMoney(cents, currency, locale) {
75
+ const fractionDigits = new Intl.NumberFormat(locale, { style: 'currency', currency }).resolvedOptions()
76
+ .maximumFractionDigits ?? 2;
77
+ const whole = cents % 100 === 0;
78
+ return new Intl.NumberFormat(locale, {
79
+ style: 'currency',
80
+ currency,
81
+ minimumFractionDigits: whole ? 0 : fractionDigits,
82
+ maximumFractionDigits: fractionDigits,
83
+ }).format(cents / 100);
84
+ }
85
+ /** The visitor's device time zone, when the browser exposes it. */
86
+ export function deviceTimeZone() {
87
+ try {
88
+ return Intl.DateTimeFormat().resolvedOptions().timeZone || null;
89
+ }
90
+ catch {
91
+ return null;
92
+ }
93
+ }
94
+ /** True when the visitor's device is in a different zone than the business. */
95
+ export function isDifferentTimeZone(businessTimeZone) {
96
+ const device = deviceTimeZone();
97
+ if (!device)
98
+ return false;
99
+ const probe = new Date();
100
+ const fmt = (tz) => new Intl.DateTimeFormat('en-US', { timeZone: tz, hour: 'numeric', minute: 'numeric', day: 'numeric' }).format(probe);
101
+ return fmt(device) !== fmt(businessTimeZone);
102
+ }
103
+ /** Minutes between UTC and a zone at an instant (positive east of UTC). */
104
+ export function timeZoneOffsetMinutes(utcMs, timezone) {
105
+ const parts = new Intl.DateTimeFormat('en-US', {
106
+ timeZone: timezone,
107
+ hourCycle: 'h23',
108
+ year: 'numeric',
109
+ month: '2-digit',
110
+ day: '2-digit',
111
+ hour: '2-digit',
112
+ minute: '2-digit',
113
+ second: '2-digit',
114
+ }).formatToParts(new Date(utcMs));
115
+ const get = (type) => Number(parts.find((p) => p.type === type)?.value ?? '0');
116
+ const asUtc = Date.UTC(get('year'), get('month') - 1, get('day'), get('hour') % 24, get('minute'), get('second'));
117
+ return Math.round((asUtc - utcMs) / 60000);
118
+ }
119
+ /** The UTC instant (ms) of a local wall-clock time in a zone. "24:00" = end of day. */
120
+ export function zonedTimeToUtc(date, time, timezone) {
121
+ const [y, m, d] = parseDate(date);
122
+ const [hh, mm] = time.split(':').map(Number);
123
+ const naive = Date.UTC(y, m - 1, d, hh ?? 0, mm ?? 0);
124
+ let guess = naive - timeZoneOffsetMinutes(naive, timezone) * 60000;
125
+ guess = naive - timeZoneOffsetMinutes(guess, timezone) * 60000;
126
+ return guess;
127
+ }
128
+ /** Local "HH:MM" of an instant in a zone. */
129
+ export function localTimeLabel(instant, timezone) {
130
+ const parts = new Intl.DateTimeFormat('en-US', {
131
+ timeZone: timezone,
132
+ hourCycle: 'h23',
133
+ hour: '2-digit',
134
+ minute: '2-digit',
135
+ }).formatToParts(new Date(instant));
136
+ const get = (type) => parts.find((p) => p.type === type)?.value ?? '00';
137
+ return `${get('hour')}:${get('minute')}`;
138
+ }