@mccaskie-labs/workbench-bookings 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +71 -2
- package/dist/bookings.d.ts +160 -0
- package/dist/bookings.js +446 -0
- package/dist/cli.d.ts +10 -0
- package/dist/cli.js +125 -0
- package/dist/config.d.ts +9 -0
- package/dist/config.js +165 -0
- package/dist/errors.d.ts +25 -0
- package/dist/errors.js +10 -0
- package/dist/format.d.ts +12 -0
- package/dist/format.js +24 -0
- package/dist/ical.d.ts +13 -0
- package/dist/ical.js +67 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +20 -0
- package/dist/migration.d.ts +4 -0
- package/dist/migration.js +441 -0
- package/dist/slots.d.ts +24 -0
- package/dist/slots.js +87 -0
- package/dist/starters.d.ts +31 -0
- package/dist/starters.js +29 -0
- package/dist/styles.d.ts +34 -0
- package/dist/styles.js +97 -0
- package/dist/time.d.ts +15 -0
- package/dist/time.js +82 -0
- package/dist/types.d.ts +130 -0
- package/dist/types.js +4 -0
- package/dist/ui.d.ts +131 -0
- package/dist/ui.js +208 -0
- package/dist/words.d.ts +4 -0
- package/dist/words.js +160 -0
- package/package.json +48 -4
package/dist/styles.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// The look the booking pages start with (docs/capabilities-manifest.md §10).
|
|
2
|
+
// Every element the render functions draw carries one of these classes, and
|
|
3
|
+
// every class has a default rule here, so the pages look finished out of the
|
|
4
|
+
// box and a project restyles them from its own CSS by the same names.
|
|
5
|
+
// `npx workbench-ui styles` writes these into the project's
|
|
6
|
+
// public/styles/workbench.css inside `@layer workbench`. The names are public:
|
|
7
|
+
// renaming one is a breaking change.
|
|
8
|
+
const v = (name) => `var(--wb-booking-${name})`;
|
|
9
|
+
const focus = { selector: ":focus-visible", about: "Has focus", css: `outline:none;box-shadow:0 0 0 3px ${v("focus")}` };
|
|
10
|
+
const button = `display:inline-flex;align-items:center;justify-content:center;min-height:2.75rem;padding:0 1rem;font:inherit;font-weight:600;border-radius:${v("radius")};cursor:pointer`;
|
|
11
|
+
const main = `${button};color:${v("on-accent")};background:${v("accent")};border:1px solid ${v("accent")}`;
|
|
12
|
+
const quiet = `${button};color:${v("text")};background:transparent;border:1px solid ${v("line")}`;
|
|
13
|
+
const link = `color:${v("accent")};font-weight:600;text-underline-offset:.2em`;
|
|
14
|
+
const box = `display:grid;gap:.75rem;color:${v("text")};background:${v("sunk")};padding:1rem;border-radius:${v("radius")}`;
|
|
15
|
+
const field = `box-sizing:border-box;width:100%;min-height:2.75rem;padding:.5rem .75rem;font:inherit;color:${v("text")};background:${v("surface")};border:1px solid ${v("line")};border-radius:${v("radius")}`;
|
|
16
|
+
/** The style hooks of the booking pages and the owner's list. */
|
|
17
|
+
export const BOOKING_STYLES = {
|
|
18
|
+
format: 1,
|
|
19
|
+
tool: "booking",
|
|
20
|
+
package: "@mccaskie-labs/workbench-bookings",
|
|
21
|
+
title: "Bookings",
|
|
22
|
+
prefix: "wb-booking-",
|
|
23
|
+
variables: [
|
|
24
|
+
{ name: "--wb-booking-text", value: "#e8e8ec", about: "Text" },
|
|
25
|
+
{ name: "--wb-booking-muted", value: "#9a9aa6", about: "Quieter text: places left, the status, empty days" },
|
|
26
|
+
{ name: "--wb-booking-surface", value: "#1b1b1f", about: "Background of a time button, a field and a booking in the list" },
|
|
27
|
+
{ name: "--wb-booking-sunk", value: "#141417", about: "Background of each page part" },
|
|
28
|
+
{ name: "--wb-booking-line", value: "#33333b", about: "Borders" },
|
|
29
|
+
{ name: "--wb-booking-accent", value: "#4c8dff", about: "Main buttons, links and a chosen time" },
|
|
30
|
+
{ name: "--wb-booking-on-accent", value: "#ffffff", about: "Text on a main button" },
|
|
31
|
+
{ name: "--wb-booking-pending", value: "#d9822b", about: "The edge of a request waiting for the owner" },
|
|
32
|
+
{ name: "--wb-booking-danger", value: "#e5484d", about: "Errors, and the cancel buttons' text" },
|
|
33
|
+
{ name: "--wb-booking-focus", value: "rgba(76,141,255,.4)", about: "The ring round a control with focus" },
|
|
34
|
+
{ name: "--wb-booking-radius", value: "8px", about: "Corner rounding" },
|
|
35
|
+
],
|
|
36
|
+
classes: [
|
|
37
|
+
{ name: "wb-booking-picker", element: "section", about: "The free times for a service", css: box },
|
|
38
|
+
{ name: "wb-booking-heading", element: "h2", about: "A page part's heading: Choose a time, Your details, You're booked, Bookings", css: "margin:0;font-size:1.25rem;font-weight:600" },
|
|
39
|
+
{ name: "wb-booking-service", element: "p", about: "The service's title under the heading", css: `margin:0;color:${v("muted")}` },
|
|
40
|
+
{ name: "wb-booking-days", element: "ol", about: "The days with free times", css: "list-style:none;margin:0;padding:0;display:grid;gap:1rem" },
|
|
41
|
+
{ name: "wb-booking-day", element: "li", about: "One day", css: "margin:0;display:grid;gap:.5rem" },
|
|
42
|
+
{ name: "wb-booking-date", element: "h3", about: "The day: Wednesday 2 December", css: "margin:0;font-size:1rem;font-weight:600" },
|
|
43
|
+
{ name: "wb-booking-slots", element: "form", about: "The day's times, one button each", css: "display:flex;flex-wrap:wrap;gap:.5rem;margin:0" },
|
|
44
|
+
{
|
|
45
|
+
name: "wb-booking-slot",
|
|
46
|
+
element: "button",
|
|
47
|
+
about: "One free time: 10:00 am",
|
|
48
|
+
css: `${button};min-width:6rem;color:${v("text")};background:${v("surface")};border:1px solid ${v("line")}`,
|
|
49
|
+
states: [focus, { selector: ":hover", about: "Under the pointer", css: `border-color:${v("accent")}` }],
|
|
50
|
+
},
|
|
51
|
+
{ name: "wb-booking-left", element: "span", about: "Places left at a time, for a class", css: `margin-left:.4rem;color:${v("muted")};font-weight:400;font-size:.85rem` },
|
|
52
|
+
{ name: "wb-booking-empty", element: "p", about: "No free times on these days", css: `margin:0;color:${v("muted")}` },
|
|
53
|
+
{ name: "wb-booking-more", element: "a", about: "Later dates", css: link, states: [focus] },
|
|
54
|
+
{ name: "wb-booking-details", element: "form", about: "The booking form: name, email, and phone or note when asked", css: box },
|
|
55
|
+
{ name: "wb-booking-when", element: "p", about: "The chosen service and time", css: "margin:0;font-weight:600" },
|
|
56
|
+
{ name: "wb-booking-message", element: "p", about: "Why the booking didn't go through (taken, too many)", css: `margin:0;color:${v("danger")};font-weight:600` },
|
|
57
|
+
{ name: "wb-booking-field", element: "label", about: "One field with its label", css: "display:grid;gap:.35rem" },
|
|
58
|
+
{ name: "wb-booking-label", element: "span", about: "A field's label", css: "font-weight:600;font-size:.95rem" },
|
|
59
|
+
{ name: "wb-booking-input", element: "input", about: "Name, email or phone", css: field, states: [focus] },
|
|
60
|
+
{ name: "wb-booking-select", element: "select", about: "How many places, when the service allows more than one", css: field, states: [focus] },
|
|
61
|
+
{ name: "wb-booking-textarea", element: "textarea", about: "The note, when asked", css: `${field};min-height:6rem;resize:vertical`, states: [focus] },
|
|
62
|
+
{ name: "wb-booking-error", element: "span", about: "What's wrong with a field", css: `color:${v("danger")};font-size:.9rem` },
|
|
63
|
+
{ name: "wb-booking-actions", element: "div", about: "A row of buttons and links", css: "display:flex;flex-wrap:wrap;gap:.75rem;align-items:center" },
|
|
64
|
+
{ name: "wb-booking-submit", element: "button", about: "Book, or Send request", css: main, states: [focus] },
|
|
65
|
+
{ name: "wb-booking-back", element: "a", about: "Choose another time", css: link, states: [focus] },
|
|
66
|
+
{ name: "wb-booking-done", element: "section", about: "You're booked, or Request sent", css: box },
|
|
67
|
+
{ name: "wb-booking-text", element: "p", about: "A plain line: we've emailed you", css: "margin:0" },
|
|
68
|
+
{ name: "wb-booking-status", element: "p", about: "Confirmed, Waiting for confirmation, Cancelled", css: `margin:0;color:${v("muted")};font-weight:600` },
|
|
69
|
+
{ name: "wb-booking-ics", element: "a", about: "Add to my calendar", css: quiet, states: [focus] },
|
|
70
|
+
{ name: "wb-booking-manage", element: "a", about: "Change or cancel", css: link, states: [focus] },
|
|
71
|
+
{ name: "wb-booking-page", element: "section", about: "The customer's own booking page, from their link", css: box },
|
|
72
|
+
{ name: "wb-booking-cancel-form", element: "form", about: "The cancel button's form", css: "display:contents" },
|
|
73
|
+
{ name: "wb-booking-cancel", element: "button", about: "Cancel booking", css: `${button};color:${v("danger")};background:transparent;border:1px solid ${v("line")}`, states: [focus] },
|
|
74
|
+
{ name: "wb-booking-move", element: "a", about: "Choose another time, on the customer's page", css: link, states: [focus] },
|
|
75
|
+
{ name: "wb-booking-locked", element: "p", about: "Too close to the start to change online", css: `margin:0;color:${v("muted")}` },
|
|
76
|
+
{ name: "wb-booking-list", element: "section", about: "The owner's bookings", css: box },
|
|
77
|
+
{ name: "wb-booking-mine", element: "section", about: "A signed-in member's own bookings", css: box },
|
|
78
|
+
{ name: "wb-booking-items", element: "ul", about: "The bookings", css: "list-style:none;margin:0;padding:0;display:grid;gap:.75rem" },
|
|
79
|
+
{ name: "wb-booking-item", element: "li", about: "One booking's place in the list", css: "margin:0" },
|
|
80
|
+
{
|
|
81
|
+
name: "wb-booking",
|
|
82
|
+
element: "article",
|
|
83
|
+
about: "One booking",
|
|
84
|
+
css: `display:grid;gap:.4rem;padding:.75rem;color:${v("text")};background:${v("surface")};border:1px solid ${v("line")};border-left:4px solid ${v("accent")};border-radius:${v("radius")}`,
|
|
85
|
+
},
|
|
86
|
+
{ name: "wb-booking-pending", element: "article", about: "A request waiting for the owner (added to wb-booking)", css: `border-left-color:${v("pending")}` },
|
|
87
|
+
{ name: "wb-booking-ended", element: "article", about: "A cancelled or declined booking (added to wb-booking)", css: `border-left-color:${v("line")};opacity:.7` },
|
|
88
|
+
{ name: "wb-booking-title", element: "h3", about: "The time and the service", css: "margin:0;font-size:1rem;font-weight:600" },
|
|
89
|
+
{ name: "wb-booking-who", element: "p", about: "The customer: name, email, phone", css: "margin:0;overflow-wrap:anywhere" },
|
|
90
|
+
{ name: "wb-booking-places", element: "p", about: "How many places a booking takes, when more than one", css: "margin:0;font-weight:600" },
|
|
91
|
+
{ name: "wb-booking-note", element: "p", about: "The customer's note, when asked for", css: `margin:0;color:${v("muted")};white-space:pre-wrap;overflow-wrap:anywhere` },
|
|
92
|
+
{ name: "wb-booking-form", element: "form", about: "One owner button's form", css: "display:contents" },
|
|
93
|
+
{ name: "wb-booking-approve", element: "button", about: "Accept a request", css: main, states: [focus] },
|
|
94
|
+
{ name: "wb-booking-decline", element: "button", about: "Decline a request", css: quiet, states: [focus] },
|
|
95
|
+
{ name: "wb-booking-owner-cancel", element: "button", about: "The owner cancels a booking", css: `${button};color:${v("danger")};background:transparent;border:1px solid transparent`, states: [focus] },
|
|
96
|
+
],
|
|
97
|
+
};
|
package/dist/time.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** A duration in minutes, or null when it isn't one ("3d", "12h", "30m"). */
|
|
2
|
+
export declare function durationMinutes(text: unknown): number | null;
|
|
3
|
+
/** "21:00" in minutes after midnight, or null. */
|
|
4
|
+
export declare function clockMinutes(text: unknown): number | null;
|
|
5
|
+
export declare function validZone(tz: unknown): boolean;
|
|
6
|
+
/** Today in the zone, YYYY-MM-DD. */
|
|
7
|
+
export declare function todayIn(timeZone: string, at: Date): string;
|
|
8
|
+
/** A real calendar day, YYYY-MM-DD. */
|
|
9
|
+
export declare function validDate(text: unknown): text is string;
|
|
10
|
+
/** A calendar day plus `n` days. */
|
|
11
|
+
export declare function addDays(date: string, n: number): string;
|
|
12
|
+
/** The day of the week of a calendar day, 0 Monday to 6 Sunday. */
|
|
13
|
+
export declare function weekdayIndex(date: string): number;
|
|
14
|
+
/** The instant a local day and clock time ("09:30") happen in the zone. */
|
|
15
|
+
export declare function localInstant(date: string, clock: string, timeZone: string): Date;
|
package/dist/time.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Time in the business's time zone: opening hours on the local clock (right
|
|
2
|
+
// across a daylight saving change), "today", and lengths such as "24h".
|
|
3
|
+
// Plain code, no AI. The zone helpers are workbench-nudges' own.
|
|
4
|
+
const DURATION = /^(0|[1-9][0-9]{0,3})([mhd])$/;
|
|
5
|
+
const CLOCK = /^([01][0-9]|2[0-3]):([0-5][0-9])$/;
|
|
6
|
+
/** A duration in minutes, or null when it isn't one ("3d", "12h", "30m"). */
|
|
7
|
+
export function durationMinutes(text) {
|
|
8
|
+
if (typeof text !== "string")
|
|
9
|
+
return null;
|
|
10
|
+
const m = DURATION.exec(text);
|
|
11
|
+
if (!m)
|
|
12
|
+
return null;
|
|
13
|
+
const n = Number(m[1]);
|
|
14
|
+
return m[2] === "m" ? n : m[2] === "h" ? n * 60 : n * 1440;
|
|
15
|
+
}
|
|
16
|
+
/** "21:00" in minutes after midnight, or null. */
|
|
17
|
+
export function clockMinutes(text) {
|
|
18
|
+
if (typeof text !== "string")
|
|
19
|
+
return null;
|
|
20
|
+
const m = CLOCK.exec(text);
|
|
21
|
+
return m ? Number(m[1]) * 60 + Number(m[2]) : null;
|
|
22
|
+
}
|
|
23
|
+
export function validZone(tz) {
|
|
24
|
+
if (typeof tz !== "string" || !tz)
|
|
25
|
+
return false;
|
|
26
|
+
try {
|
|
27
|
+
new Intl.DateTimeFormat("en", { timeZone: tz });
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function localParts(at, timeZone) {
|
|
35
|
+
const p = Object.fromEntries(new Intl.DateTimeFormat("en-CA", { timeZone, year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit", hourCycle: "h23" })
|
|
36
|
+
.formatToParts(at)
|
|
37
|
+
.filter((x) => x.type !== "literal")
|
|
38
|
+
.map((x) => [x.type, Number(x.value)]));
|
|
39
|
+
return { year: p.year, month: p.month, day: p.day, hour: p.hour, minute: p.minute, second: p.second };
|
|
40
|
+
}
|
|
41
|
+
/** How far the zone's clock is ahead of UTC at an instant, in milliseconds. */
|
|
42
|
+
function offsetAt(at, timeZone) {
|
|
43
|
+
const p = localParts(at, timeZone);
|
|
44
|
+
return Date.UTC(p.year, p.month - 1, p.day, p.hour, p.minute, p.second) - Math.floor(at.getTime() / 1000) * 1000;
|
|
45
|
+
}
|
|
46
|
+
/** The instant a local wall-clock time (given as if it were UTC) happens in the zone. */
|
|
47
|
+
function fromLocal(wall, timeZone) {
|
|
48
|
+
const guess = wall - offsetAt(new Date(wall), timeZone);
|
|
49
|
+
return new Date(wall - offsetAt(new Date(guess), timeZone));
|
|
50
|
+
}
|
|
51
|
+
/** Today in the zone, YYYY-MM-DD. */
|
|
52
|
+
export function todayIn(timeZone, at) {
|
|
53
|
+
const p = localParts(at, timeZone);
|
|
54
|
+
return `${p.year}-${String(p.month).padStart(2, "0")}-${String(p.day).padStart(2, "0")}`;
|
|
55
|
+
}
|
|
56
|
+
const DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
57
|
+
/** A real calendar day, YYYY-MM-DD. */
|
|
58
|
+
export function validDate(text) {
|
|
59
|
+
if (typeof text !== "string")
|
|
60
|
+
return false;
|
|
61
|
+
const m = DATE.exec(text);
|
|
62
|
+
if (!m)
|
|
63
|
+
return false;
|
|
64
|
+
const d = new Date(Date.UTC(Number(m[1]), Number(m[2]) - 1, Number(m[3])));
|
|
65
|
+
return d.toISOString().slice(0, 10) === text;
|
|
66
|
+
}
|
|
67
|
+
/** A calendar day plus `n` days. */
|
|
68
|
+
export function addDays(date, n) {
|
|
69
|
+
const [y, m, d] = date.split("-").map(Number);
|
|
70
|
+
return new Date(Date.UTC(y, m - 1, d + n)).toISOString().slice(0, 10);
|
|
71
|
+
}
|
|
72
|
+
/** The day of the week of a calendar day, 0 Monday to 6 Sunday. */
|
|
73
|
+
export function weekdayIndex(date) {
|
|
74
|
+
const [y, m, d] = date.split("-").map(Number);
|
|
75
|
+
return (new Date(Date.UTC(y, m - 1, d)).getUTCDay() + 6) % 7;
|
|
76
|
+
}
|
|
77
|
+
/** The instant a local day and clock time ("09:30") happen in the zone. */
|
|
78
|
+
export function localInstant(date, clock, timeZone) {
|
|
79
|
+
const [y, m, d] = date.split("-").map(Number);
|
|
80
|
+
const mins = clockMinutes(clock) ?? 0;
|
|
81
|
+
return fromLocal(Date.UTC(y, m - 1, d, Math.floor(mins / 60), mins % 60, 0), timeZone);
|
|
82
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/** A day of the week, as bookings.json names it. */
|
|
2
|
+
export type Weekday = "mon" | "tue" | "wed" | "thu" | "fri" | "sat" | "sun";
|
|
3
|
+
export declare const WEEKDAYS: readonly Weekday[];
|
|
4
|
+
/** Opening hours: per day, a list of ["09:00", "17:00"] spans on the 24-hour clock. A day left out is closed. */
|
|
5
|
+
export type WeekHours = Partial<Record<Weekday, readonly (readonly [string, string])[]>>;
|
|
6
|
+
/** A length of time: a whole number and m (minutes), h (hours) or d (days), such as "24h". */
|
|
7
|
+
export type Duration = `${number}${"m" | "h" | "d"}`;
|
|
8
|
+
/** One thing a customer can book: a consultation, a lesson, a class. */
|
|
9
|
+
export interface BookingService {
|
|
10
|
+
/** What the customer sees: "30-minute consultation". */
|
|
11
|
+
title: string;
|
|
12
|
+
/** How long it takes, 5 to 720 minutes. */
|
|
13
|
+
minutes: number;
|
|
14
|
+
/** Minutes kept free after it (packing up, travel), 0 to 240. Default 0. */
|
|
15
|
+
buffer?: number;
|
|
16
|
+
/** How many people can book the same time (a class), 1 to 100. Default 1. */
|
|
17
|
+
capacity?: number;
|
|
18
|
+
/** The most places one booking can take (a member bringing friends), 1 to capacity. Default 1. */
|
|
19
|
+
places?: number;
|
|
20
|
+
/** Minutes between start times, 5 to 720. Default: the service's minutes. */
|
|
21
|
+
every?: number;
|
|
22
|
+
/** Its own opening hours, when they differ from the business's. */
|
|
23
|
+
hours?: WeekHours;
|
|
24
|
+
}
|
|
25
|
+
/** Whether services share one diary (one person or room) or each has its own. */
|
|
26
|
+
export type CalendarMode = "shared" | "per_service";
|
|
27
|
+
/** Whether a booking is confirmed at once or waits for the owner. */
|
|
28
|
+
export type ConfirmMode = "instant" | "owner_approves";
|
|
29
|
+
/** workbench/bookings.json, checked. */
|
|
30
|
+
export interface BookingConfig {
|
|
31
|
+
format: 1;
|
|
32
|
+
/** Opening hours, slots, reminders and emails are in this time zone (IANA name). */
|
|
33
|
+
time_zone: string;
|
|
34
|
+
hours: WeekHours;
|
|
35
|
+
/** Days the business is closed (YYYY-MM-DD): public holidays, leave. */
|
|
36
|
+
closed?: readonly string[];
|
|
37
|
+
services: Readonly<Record<string, BookingService>>;
|
|
38
|
+
/** Default shared: any booking blocks the time for every other service. */
|
|
39
|
+
calendar?: CalendarMode;
|
|
40
|
+
/** The least notice a booking needs. Default 2h. */
|
|
41
|
+
notice?: Duration;
|
|
42
|
+
/** How many days ahead customers can book, 1 to 365. Default 60. */
|
|
43
|
+
ahead_days?: number;
|
|
44
|
+
/** Default instant. */
|
|
45
|
+
confirm?: ConfirmMode;
|
|
46
|
+
/** With owner_approves: a request the owner hasn't answered in this long is declined, and the time freed. Default 2d. */
|
|
47
|
+
hold?: Duration;
|
|
48
|
+
/** Reminder emails to the customer, each this long before the start. Up to 3. Default ["1d"]. [] for none. */
|
|
49
|
+
reminders?: readonly Duration[];
|
|
50
|
+
/** Customers can cancel or move a booking online until this long before it starts ("0m": up to the start). Default 24h. */
|
|
51
|
+
cancel_until?: Duration;
|
|
52
|
+
/** What the booking form asks besides name and email. Default: no phone, no note. */
|
|
53
|
+
ask?: {
|
|
54
|
+
phone?: "no" | "optional" | "required";
|
|
55
|
+
note?: boolean;
|
|
56
|
+
};
|
|
57
|
+
/** An email to the owner for each new booking, change and cancellation, or none. Default each. */
|
|
58
|
+
owner_email?: "each" | "none";
|
|
59
|
+
/** The owner's calendar feed: names puts the customer's name on each event. Default false (calendars leak). */
|
|
60
|
+
feed?: {
|
|
61
|
+
names?: boolean;
|
|
62
|
+
};
|
|
63
|
+
/** How many upcoming bookings one email address can hold with one account, 1 to 20. Default 3. */
|
|
64
|
+
max_per_customer?: number;
|
|
65
|
+
/** Bookings are deleted this many days after they end (or were cancelled). Default 180. */
|
|
66
|
+
retention_days?: number;
|
|
67
|
+
/** The plans feature taking bookings needs (default "bookings"). */
|
|
68
|
+
plans?: {
|
|
69
|
+
feature?: string;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export type BookingStatus = "pending" | "confirmed" | "cancelled" | "declined";
|
|
73
|
+
export declare const BOOKING_STATUSES: readonly BookingStatus[];
|
|
74
|
+
/** The customer as they gave themselves on the booking form. Kept in the app's own database only. */
|
|
75
|
+
export interface Customer {
|
|
76
|
+
name: string;
|
|
77
|
+
email: string;
|
|
78
|
+
phone?: string | null;
|
|
79
|
+
/** Only when bookings.json asks for a note. */
|
|
80
|
+
note?: string | null;
|
|
81
|
+
}
|
|
82
|
+
export interface Booking {
|
|
83
|
+
id: string;
|
|
84
|
+
account: string;
|
|
85
|
+
service: string;
|
|
86
|
+
/** ISO 8601, UTC. */
|
|
87
|
+
starts_at: string;
|
|
88
|
+
ends_at: string;
|
|
89
|
+
status: BookingStatus;
|
|
90
|
+
/** How many places it takes (1 unless the service allows more). */
|
|
91
|
+
places: number;
|
|
92
|
+
customer: Customer;
|
|
93
|
+
/** The signed-in member who booked it (the app's user id), or null for a booking made without signing in. */
|
|
94
|
+
member: string | null;
|
|
95
|
+
/** Goes up each time the booking moves or ends, for calendar apps. */
|
|
96
|
+
sequence: number;
|
|
97
|
+
/** Why it was cancelled or declined: by_customer, by_owner, not_answered, or the owner's words. */
|
|
98
|
+
reason: string | null;
|
|
99
|
+
created_at: string;
|
|
100
|
+
updated_at: string;
|
|
101
|
+
}
|
|
102
|
+
/** One free start time. */
|
|
103
|
+
export interface Slot {
|
|
104
|
+
/** ISO 8601, UTC: pass it back to book(). */
|
|
105
|
+
start: string;
|
|
106
|
+
end: string;
|
|
107
|
+
/** Places left (1 unless the service has a capacity). */
|
|
108
|
+
left: number;
|
|
109
|
+
}
|
|
110
|
+
/** One day of free times, in the business's time zone. */
|
|
111
|
+
export interface SlotDay {
|
|
112
|
+
/** YYYY-MM-DD. */
|
|
113
|
+
date: string;
|
|
114
|
+
slots: Slot[];
|
|
115
|
+
}
|
|
116
|
+
/** A booking that is holding time, as the slot finder needs it. */
|
|
117
|
+
export interface Busy {
|
|
118
|
+
service: string;
|
|
119
|
+
starts_at: string;
|
|
120
|
+
/** The end plus the service's buffer. */
|
|
121
|
+
block_end: string;
|
|
122
|
+
/** Places it takes. Default 1. */
|
|
123
|
+
places?: number;
|
|
124
|
+
}
|
|
125
|
+
export interface TickResult {
|
|
126
|
+
reminded: number;
|
|
127
|
+
/** Requests the owner didn't answer in time, now declined. */
|
|
128
|
+
expired: number;
|
|
129
|
+
emailed: number;
|
|
130
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// The shapes of workbench/bookings.json and of what the package answers
|
|
2
|
+
// (docs/capabilities/13-bookings.md, "Interface" and "Config format").
|
|
3
|
+
export const WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
|
|
4
|
+
export const BOOKING_STATUSES = ["pending", "confirmed", "cancelled", "declined"];
|
package/dist/ui.d.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { Bookings } from "./bookings.ts";
|
|
2
|
+
import { type BookingsErrorCode } from "./errors.ts";
|
|
3
|
+
import { type Words } from "./format.ts";
|
|
4
|
+
import type { Booking, BookingConfig, SlotDay } from "./types.ts";
|
|
5
|
+
interface Common {
|
|
6
|
+
/** The business's time zone (bookings.config.time_zone). */
|
|
7
|
+
timeZone: string;
|
|
8
|
+
/** Default en-AU: pass the country pack's. */
|
|
9
|
+
locale?: string;
|
|
10
|
+
t?: Words;
|
|
11
|
+
}
|
|
12
|
+
export interface PickerOptions extends Common {
|
|
13
|
+
/** Where a chosen time goes: the details page (GET, with service and start), or with `move` the project's action endpoint (POST). */
|
|
14
|
+
endpoint: string;
|
|
15
|
+
service: string;
|
|
16
|
+
/** The service's title, shown under the heading. */
|
|
17
|
+
title: string;
|
|
18
|
+
/** The address of the next days, for "Later dates". */
|
|
19
|
+
more?: string;
|
|
20
|
+
/** Moving a booking: its manage link's secret. Choosing a time then moves it at once. */
|
|
21
|
+
move?: {
|
|
22
|
+
token: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** The free times, a day at a time. Days with none are left out. */
|
|
26
|
+
export declare function renderSlotPicker(days: readonly SlotDay[], o: PickerOptions): string;
|
|
27
|
+
export type FormField = "name" | "email" | "phone" | "note" | "places";
|
|
28
|
+
export interface FormOptions extends Common {
|
|
29
|
+
/** The project's action endpoint (POST), which hands the fields to bookingAction. */
|
|
30
|
+
endpoint: string;
|
|
31
|
+
service: string;
|
|
32
|
+
title: string;
|
|
33
|
+
/** The chosen slot's start. */
|
|
34
|
+
start: string;
|
|
35
|
+
/** The most places to offer: the smaller of the service's places and the slot's left. Above 1 the form asks how many. */
|
|
36
|
+
places?: number;
|
|
37
|
+
/** bookings.config.ask. */
|
|
38
|
+
ask?: BookingConfig["ask"];
|
|
39
|
+
/** bookings.config.confirm: owner_approves says Send request. */
|
|
40
|
+
confirm?: BookingConfig["confirm"];
|
|
41
|
+
/** What the customer typed, when the form comes back with a problem. */
|
|
42
|
+
values?: Partial<Record<FormField, string>>;
|
|
43
|
+
/** The field that was wrong (bookingAction's `field`). */
|
|
44
|
+
field?: FormField;
|
|
45
|
+
/** Why it didn't go through (bookingAction's `text`). */
|
|
46
|
+
message?: string;
|
|
47
|
+
/** The free times page, for "Choose another time". */
|
|
48
|
+
back?: string;
|
|
49
|
+
}
|
|
50
|
+
/** The booking form for a chosen time. */
|
|
51
|
+
export declare function renderBookingForm(o: FormOptions): string;
|
|
52
|
+
export interface DoneOptions extends Common {
|
|
53
|
+
title: string;
|
|
54
|
+
/** The customer's own booking page (their manage link). */
|
|
55
|
+
manage?: string;
|
|
56
|
+
/** The booking's calendar file (bookings.icsFor behind the manage link's secret). */
|
|
57
|
+
ics?: string;
|
|
58
|
+
}
|
|
59
|
+
/** You're booked, or Request sent. */
|
|
60
|
+
export declare function renderBookingDone(b: Booking, o: DoneOptions): string;
|
|
61
|
+
export interface ManageOptions extends Common {
|
|
62
|
+
/** The project's action endpoint (POST). */
|
|
63
|
+
endpoint: string;
|
|
64
|
+
/** The manage link's secret. */
|
|
65
|
+
token: string;
|
|
66
|
+
title: string;
|
|
67
|
+
/** bookings.changeable(b). */
|
|
68
|
+
changeable: boolean;
|
|
69
|
+
/** The free times page in move mode. */
|
|
70
|
+
move?: string;
|
|
71
|
+
ics?: string;
|
|
72
|
+
}
|
|
73
|
+
/** The customer's own booking page, from their manage link: when, its status, and cancel or move while they still can. */
|
|
74
|
+
export declare function renderBookingManage(b: Booking, o: ManageOptions): string;
|
|
75
|
+
export interface ListOptions extends Common {
|
|
76
|
+
/** The project's owner endpoint (POST, behind the sign-in), which hands the fields to ownerBookingAction. */
|
|
77
|
+
endpoint: string;
|
|
78
|
+
/** A service's title (bookings.config.services[name].title). */
|
|
79
|
+
titleOf: (service: string) => string;
|
|
80
|
+
}
|
|
81
|
+
/** The owner's bookings, earliest first, with Accept and Decline for requests and Cancel for the rest. */
|
|
82
|
+
export declare function renderBookingList(bookings: readonly Booking[], o: ListOptions): string;
|
|
83
|
+
export interface MineOptions extends Common {
|
|
84
|
+
/** The project's action endpoint (POST, behind the member's sign-in), which hands the fields to bookingAction with the member. */
|
|
85
|
+
endpoint: string;
|
|
86
|
+
/** A service's title (bookings.config.services[name].title). */
|
|
87
|
+
titleOf: (service: string) => string;
|
|
88
|
+
/** bookings.changeable. */
|
|
89
|
+
changeable: (b: Booking) => boolean;
|
|
90
|
+
/** The booking page, for "Make a booking". */
|
|
91
|
+
book?: string;
|
|
92
|
+
}
|
|
93
|
+
/** A signed-in member's own bookings (bookings.mine), with Cancel while they still can. */
|
|
94
|
+
export declare function renderMyBookings(bookings: readonly Booking[], o: MineOptions): string;
|
|
95
|
+
export interface ActionResult {
|
|
96
|
+
status: number;
|
|
97
|
+
body: {
|
|
98
|
+
ok: true;
|
|
99
|
+
action: string;
|
|
100
|
+
booking: Booking;
|
|
101
|
+
token?: string;
|
|
102
|
+
} | {
|
|
103
|
+
ok: false;
|
|
104
|
+
error: BookingsErrorCode;
|
|
105
|
+
message: string;
|
|
106
|
+
text: string;
|
|
107
|
+
field?: FormField;
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The customer's posts, on the booking page: `book` (service, start, name,
|
|
112
|
+
* email, places when the service allows more than one, and phone or note when
|
|
113
|
+
* asked; answers the booking and its manage secret), `cancel` (token, or with
|
|
114
|
+
* a signed-in member the booking's id) and `move` (token, start). Put
|
|
115
|
+
* Turnstile or the app's rate limit in front of it. `member` is the signed-in
|
|
116
|
+
* member's id from the app's own sign-in, never from the form. `text` is the
|
|
117
|
+
* line to show the customer when it didn't go through, and `field` the field
|
|
118
|
+
* to mark.
|
|
119
|
+
*/
|
|
120
|
+
export declare function bookingAction(bookings: Bookings, body: Record<string, unknown>, ctx: {
|
|
121
|
+
account: string;
|
|
122
|
+
member?: string;
|
|
123
|
+
t?: Words;
|
|
124
|
+
}): Promise<ActionResult>;
|
|
125
|
+
/**
|
|
126
|
+
* The owner's posts, behind the app's sign-in, with the signed-in owner's
|
|
127
|
+
* account: `approve`, `decline` or `cancel` a booking. A booking of another
|
|
128
|
+
* account is answered as unknown.
|
|
129
|
+
*/
|
|
130
|
+
export declare function ownerBookingAction(bookings: Bookings, body: Record<string, unknown>, account: string): Promise<ActionResult>;
|
|
131
|
+
export {};
|