@mccaskie-labs/workbench-bookings 0.2.2 → 0.3.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/dist/types.d.ts CHANGED
@@ -21,9 +21,38 @@ export interface BookingService {
21
21
  every?: number;
22
22
  /** Its own opening hours, when they differ from the business's. */
23
23
  hours?: WeekHours;
24
+ /** Booked by dated sessions the owner makes (a tour departure, a workshop, a term of classes), not by opening hours. minutes is a session's usual length and capacity its usual places. */
25
+ sessions?: boolean;
26
+ /** With calendar "resources": what a booking takes, one from each group (a practitioner and a room). Up to 3 groups. */
27
+ needs?: readonly ServiceNeed[];
24
28
  }
25
- /** Whether services share one diary (one person or room) or each has its own. */
26
- export type CalendarMode = "shared" | "per_service";
29
+ /** A person, a room or a thing bookings take, each with its own diary (calendar "resources"). */
30
+ export interface BookingResource {
31
+ /** What the customer and the owner see: "Dr Lee", "Room 1". */
32
+ title: string;
33
+ /** Default thing. A person is named in the customer's emails ("with Dr Lee"). */
34
+ kind?: "person" | "room" | "thing";
35
+ /** Its own working hours, when they differ from the service's. Hours that change week to week come through the settings option. */
36
+ hours?: WeekHours;
37
+ }
38
+ /** One thing a service needs: any one of these resources. */
39
+ export interface ServiceNeed {
40
+ /** The resources that can do it, up to 20. A resource is in one group of a service at most. */
41
+ any: readonly string[];
42
+ /** The customer may pick which one ("Anyone", or a name). One group of a service at most. */
43
+ choose?: boolean;
44
+ }
45
+ /** When a resource can be booked, from the app's own database (a roster): passed through the settings option. */
46
+ export interface ResourceTimes {
47
+ /** Its weekly hours, over bookings.json's. */
48
+ hours?: WeekHours;
49
+ /** The only spans it works (ISO 8601 pairs), such as rostered shifts. When given, hours are ignored. */
50
+ shifts?: readonly (readonly [string, string])[];
51
+ /** Spans it is away (leave, a meeting), whatever its hours say. */
52
+ away?: readonly (readonly [string, string])[];
53
+ }
54
+ /** Whether services share one diary (one person or room), each has its own, or each takes named resources (several people and rooms). */
55
+ export type CalendarMode = "shared" | "per_service" | "resources";
27
56
  /** Whether a booking is confirmed at once or waits for the owner. */
28
57
  export type ConfirmMode = "instant" | "owner_approves";
29
58
  /** workbench/bookings.json, checked. */
@@ -35,7 +64,9 @@ export interface BookingConfig {
35
64
  /** Days the business is closed (YYYY-MM-DD): public holidays, leave. */
36
65
  closed?: readonly string[];
37
66
  services: Readonly<Record<string, BookingService>>;
38
- /** Default shared: any booking blocks the time for every other service. */
67
+ /** With calendar "resources": the people, rooms and things services need, up to 100. */
68
+ resources?: Readonly<Record<string, BookingResource>>;
69
+ /** Default shared: any booking blocks the time for every other service. per_service: each service has its own diary. resources: a service is free when one of each resource it needs is. */
39
70
  calendar?: CalendarMode;
40
71
  /** The least notice a booking needs. Default 2h. */
41
72
  notice?: Duration;
@@ -64,6 +95,12 @@ export interface BookingConfig {
64
95
  max_per_customer?: number;
65
96
  /** Bookings are deleted this many days after they end (or were cancelled). Default 180. */
66
97
  retention_days?: number;
98
+ /** The waiting list for full sessions: how long an offered place is held for the person offered it. Default 12h. */
99
+ waitlist?: {
100
+ offer?: Duration;
101
+ };
102
+ /** A session with a minimum that hasn't reached it this long before it starts is put to the owner (run it or cancel it). Default 2d. */
103
+ run_check?: Duration;
67
104
  /** The plans feature taking bookings needs (default "bookings"). */
68
105
  plans?: {
69
106
  feature?: string;
@@ -89,7 +126,13 @@ export interface Booking {
89
126
  status: BookingStatus;
90
127
  /** How many places it takes (1 unless the service allows more). */
91
128
  places: number;
129
+ /** The resources it holds, one from each of the service's needs ([] for a service that needs none). */
130
+ resources: string[];
92
131
  customer: Customer;
132
+ /** The session it holds places on, or null. */
133
+ session: string | null;
134
+ /** The series (a term) it holds places on in every session, or null. */
135
+ series: string | null;
93
136
  /** The signed-in member who booked it (the app's user id), or null for a booking made without signing in. */
94
137
  member: string | null;
95
138
  /** Goes up each time the booking moves or ends, for calendar apps. */
@@ -106,6 +149,8 @@ export interface Slot {
106
149
  end: string;
107
150
  /** Places left (1 unless the service has a capacity). */
108
151
  left: number;
152
+ /** When the service lets the customer choose: the resources of that group free at this time. */
153
+ choices?: string[];
109
154
  }
110
155
  /** One day of free times, in the business's time zone. */
111
156
  export interface SlotDay {
@@ -121,10 +166,90 @@ export interface Busy {
121
166
  block_end: string;
122
167
  /** Places it takes. Default 1. */
123
168
  places?: number;
169
+ /** The resources it holds. */
170
+ resources?: readonly string[];
171
+ }
172
+ /** A dated thing people book places on: a departure, a workshop, one class of a term, a stop on a schedule. */
173
+ export interface Session {
174
+ id: string;
175
+ account: string;
176
+ /** A service in bookings.json with "sessions": true. */
177
+ service: string;
178
+ /** The series (a term) it belongs to, or null. */
179
+ series: string | null;
180
+ /** ISO 8601, UTC. */
181
+ starts_at: string;
182
+ ends_at: string;
183
+ /** Where it is, in the owner's words. */
184
+ place: string | null;
185
+ /** A map link (https) for the place. */
186
+ map_url: string | null;
187
+ /** The owner's public note: "Bring a hat". */
188
+ note: string | null;
189
+ capacity: number;
190
+ /** The fewest places it runs with, or null. */
191
+ min_places: number | null;
192
+ /** False for an entry that is only shown (a stop on a location schedule). */
193
+ bookable: boolean;
194
+ status: "open" | "cancelled";
195
+ /** Why it was cancelled, in the owner's words. */
196
+ reason: string | null;
197
+ /** Places taken, with those held for waiting list offers. */
198
+ taken: number;
199
+ /** Places left. */
200
+ left: number;
201
+ /** People waiting for a place. */
202
+ waiting: number;
203
+ sequence: number;
204
+ }
205
+ /** What the owner gives to make or change a session. */
206
+ export interface SessionInput {
207
+ service: string;
208
+ start: string | Date;
209
+ /** Default: the start plus the service's minutes. */
210
+ end?: string | Date;
211
+ place?: string | null;
212
+ map_url?: string | null;
213
+ note?: string | null;
214
+ /** Default: the service's capacity. 1 to 1000. */
215
+ capacity?: number;
216
+ min_places?: number | null;
217
+ /** Default true. */
218
+ bookable?: boolean;
219
+ }
220
+ /** Someone waiting for a place on a full session or series. */
221
+ export interface WaitEntry {
222
+ id: string;
223
+ account: string;
224
+ session: string | null;
225
+ series: string | null;
226
+ places: number;
227
+ customer: {
228
+ name: string;
229
+ email: string;
230
+ phone: string | null;
231
+ };
232
+ member: string | null;
233
+ /** waiting, offered (a place is held until offered_until), booked, expired or left. */
234
+ status: "waiting" | "offered" | "booked" | "expired" | "left";
235
+ offered_until: string | null;
236
+ /** The booking an accepted offer made. */
237
+ booking: string | null;
238
+ created_at: string;
239
+ }
240
+ /** One person on a session's list for the day. */
241
+ export interface RollEntry {
242
+ booking: Booking;
243
+ /** Whether they came; null until marked. */
244
+ came: boolean | null;
124
245
  }
125
246
  export interface TickResult {
126
247
  reminded: number;
127
248
  /** Requests the owner didn't answer in time, now declined. */
128
249
  expired: number;
129
250
  emailed: number;
251
+ /** Places offered to people on a waiting list. */
252
+ offered: number;
253
+ /** Sessions below their minimum, put to the owner. */
254
+ short: number;
130
255
  }
package/dist/ui.d.ts CHANGED
@@ -2,12 +2,25 @@ import type { Bookings } from "./bookings.ts";
2
2
  import { BookingsError, type BookingsErrorCode } from "./errors.ts";
3
3
  import { type Words } from "./format.ts";
4
4
  import type { Booking, BookingConfig, SlotDay } from "./types.ts";
5
- interface Common {
5
+ export declare const esc: (s: string) => string;
6
+ export declare const hidden: (name: string, value: string) => string;
7
+ export interface Common {
6
8
  /** The business's time zone (bookings.config.time_zone). */
7
9
  timeZone: string;
8
10
  /** Default en-AU: pass the country pack's. */
9
11
  locale?: string;
10
12
  t?: Words;
13
+ /** What to call the resources a booking holds (bookings.resourceTitles): drawn as "With Dr Lee, Room 1" where a booking is shown. */
14
+ resourceTitles?: (b: Booking) => readonly string[];
15
+ }
16
+ /** One resource the customer can choose on the free times page. */
17
+ export interface PickerChoice {
18
+ /** The resource's name in bookings.json. */
19
+ name: string;
20
+ /** Its title: "Dr Lee". */
21
+ title: string;
22
+ /** The free times page for this choice. */
23
+ href: string;
11
24
  }
12
25
  export interface PickerOptions extends Common {
13
26
  /** Where a chosen time goes: the details page (GET, with service and start), or with `move` the project's action endpoint (POST). */
@@ -21,6 +34,12 @@ export interface PickerOptions extends Common {
21
34
  move?: {
22
35
  token: string;
23
36
  };
37
+ /** When the service lets customers choose who with: the choices, the free times page for "Anyone available", and the one chosen (the days passed in are then that resource's, from slots(..., { with })). */
38
+ choose?: {
39
+ options: readonly PickerChoice[];
40
+ anyone: string;
41
+ chosen?: string;
42
+ };
24
43
  }
25
44
  /** The free times, a day at a time. Days with none are left out. */
26
45
  export declare function renderSlotPicker(days: readonly SlotDay[], o: PickerOptions): string;
@@ -46,7 +65,14 @@ export interface FormOptions extends Common {
46
65
  message?: string;
47
66
  /** The free times page, for "Choose another time". */
48
67
  back?: string;
68
+ /** The resource the customer chose on the free times page: sent back with the form and shown under the time. */
69
+ with?: {
70
+ name: string;
71
+ title: string;
72
+ };
49
73
  }
74
+ /** The fields every booking form asks: name, email, and phone, places and a note when asked. */
75
+ export declare function detailFields(o: Pick<FormOptions, "values" | "field" | "ask" | "places" | "t">): string;
50
76
  /** The booking form for a chosen time. */
51
77
  export declare function renderBookingForm(o: FormOptions): string;
52
78
  export interface DoneOptions extends Common {
@@ -66,7 +92,7 @@ export interface ManageOptions extends Common {
66
92
  title: string;
67
93
  /** bookings.changeable(b). */
68
94
  changeable: boolean;
69
- /** The free times page in move mode. */
95
+ /** The free times page in move mode (for a booking on a session: the dates page in move mode). */
70
96
  move?: string;
71
97
  ics?: string;
72
98
  }
@@ -110,6 +136,11 @@ export interface ActionResult {
110
136
  /** The error behind a refusal, for the app's own log. Never send it: for store_failed and bad_config its message is the database's or the settings check's. */
111
137
  cause?: BookingsError;
112
138
  }
139
+ export declare function failed(e: unknown, o: {
140
+ t?: Words;
141
+ max?: number;
142
+ }): ActionResult;
143
+ export declare const str: (v: unknown) => string;
113
144
  /**
114
145
  * The customer's posts, on the booking page: `book` (service, start, name,
115
146
  * email, places when the service allows more than one, and phone or note when
@@ -131,4 +162,3 @@ export declare function bookingAction(bookings: Bookings, body: Record<string, u
131
162
  * account is answered as unknown.
132
163
  */
133
164
  export declare function ownerBookingAction(bookings: Bookings, body: Record<string, unknown>, account: string): Promise<ActionResult>;
134
- export {};
package/dist/ui.js CHANGED
@@ -8,8 +8,8 @@
8
8
  // (BOOKING_STYLES), and every button is at least 44 px tall.
9
9
  import { BookingsError } from "./errors.js";
10
10
  import { dayText, DEFAULT_LOCALE, timeText, whenText, words } from "./format.js";
11
- const esc = (s) => s.replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]);
12
- const hidden = (name, value) => `<input type="hidden" name="${esc(name)}" value="${esc(value)}">`;
11
+ export const esc = (s) => s.replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]);
12
+ export const hidden = (name, value) => `<input type="hidden" name="${esc(name)}" value="${esc(value)}">`;
13
13
  /** The free times, a day at a time. Days with none are left out. */
14
14
  export function renderSlotPicker(days, o) {
15
15
  const say = words(o.t);
@@ -19,17 +19,21 @@ export function renderSlotPicker(days, o) {
19
19
  const buttons = d.slots
20
20
  .map((s) => `<button class="wb-booking-slot" type="submit" name="start" value="${esc(s.start)}">${esc(timeText(s.start, o.timeZone, locale))}${s.left > 1 ? `<span class="wb-booking-left">${esc(say("picker.left", { left: s.left }))}</span>` : ""}</button>`)
21
21
  .join("");
22
- const fields = o.move ? `${hidden("action", "move")}${hidden("token", o.move.token)}` : hidden("service", o.service);
22
+ const fields = o.move ? `${hidden("action", "move")}${hidden("token", o.move.token)}` : `${hidden("service", o.service)}${o.choose?.chosen ? hidden("with", o.choose.chosen) : ""}`;
23
23
  return `<form class="wb-booking-slots" method="${o.move ? "post" : "get"}" action="${esc(o.endpoint)}">${fields}${buttons}</form>`;
24
24
  };
25
25
  const list = open.length
26
26
  ? `<ol class="wb-booking-days">${open.map((d) => `<li class="wb-booking-day"><h3 class="wb-booking-date">${esc(dayText(d.date, locale))}</h3>${form(d)}</li>`).join("")}</ol>`
27
27
  : `<p class="wb-booking-empty">${esc(say("picker.empty"))}</p>`;
28
28
  const more = o.more ? `<a class="wb-booking-more" href="${esc(o.more)}">${esc(say("picker.more"))}</a>` : "";
29
- return `<section class="wb-booking-picker"><h2 class="wb-booking-heading">${esc(say("picker.title"))}</h2><p class="wb-booking-service">${esc(o.title)}</p>${list}${more}</section>`;
29
+ const choice = (href, label, on) => `<li class="wb-booking-choice-item"><a class="wb-booking-choice${on ? " wb-booking-choice-on" : ""}" href="${esc(href)}"${on ? ' aria-current="true"' : ""}>${esc(label)}</a></li>`;
30
+ const choose = o.choose && !o.move
31
+ ? `<nav class="wb-booking-choose" aria-label="${esc(say("picker.choose"))}"><p class="wb-booking-choose-label">${esc(say("picker.choose"))}</p><ul class="wb-booking-choices">${choice(o.choose.anyone, say("picker.anyone"), !o.choose.chosen)}${o.choose.options.map((c) => choice(c.href, c.title, c.name === o.choose.chosen)).join("")}</ul></nav>`
32
+ : "";
33
+ return `<section class="wb-booking-picker"><h2 class="wb-booking-heading">${esc(say("picker.title"))}</h2><p class="wb-booking-service">${esc(o.title)}</p>${choose}${list}${more}</section>`;
30
34
  }
31
- /** The booking form for a chosen time. */
32
- export function renderBookingForm(o) {
35
+ /** The fields every booking form asks: name, email, and phone, places and a note when asked. */
36
+ export function detailFields(o) {
33
37
  const say = words(o.t);
34
38
  const v = o.values ?? {};
35
39
  const phone = o.ask?.phone ?? "no";
@@ -37,13 +41,6 @@ export function renderBookingForm(o) {
37
41
  const aria = (f) => (o.field === f ? ` aria-invalid="true" aria-describedby="wb-booking-error-${f}"` : "");
38
42
  const input = (f, label, type, auto, required) => `<label class="wb-booking-field"><span class="wb-booking-label">${esc(label)}</span><input class="wb-booking-input" type="${type}" name="${f}" autocomplete="${auto}" maxlength="${f === "email" ? 254 : f === "phone" ? 40 : 100}"${required ? " required" : ""} value="${esc(v[f] ?? "")}"${aria(f)}>${err(f)}</label>`;
39
43
  return [
40
- `<form class="wb-booking-details" method="post" action="${esc(o.endpoint)}">`,
41
- `<h2 class="wb-booking-heading">${esc(say("form.title"))}</h2>`,
42
- `<p class="wb-booking-when">${esc(o.title)}, ${esc(whenText(o.start, o.timeZone, o.locale ?? DEFAULT_LOCALE))}</p>`,
43
- o.message ? `<p class="wb-booking-message" role="alert">${esc(o.message)}</p>` : "",
44
- hidden("action", "book"),
45
- hidden("service", o.service),
46
- hidden("start", o.start),
47
44
  input("name", say("form.name"), "text", "name", true),
48
45
  input("email", say("form.email"), "email", "email", true),
49
46
  phone === "no" ? "" : input("phone", say(phone === "required" ? "form.phone" : "form.phone_optional"), "tel", "tel", phone === "required"),
@@ -53,11 +50,31 @@ export function renderBookingForm(o) {
53
50
  o.ask?.note
54
51
  ? `<label class="wb-booking-field"><span class="wb-booking-label">${esc(say("form.note"))}</span><textarea class="wb-booking-textarea" name="note" rows="4" maxlength="1000"${aria("note")}>${esc(v.note ?? "")}</textarea>${err("note")}</label>`
55
52
  : "",
53
+ ].join("");
54
+ }
55
+ /** The booking form for a chosen time. */
56
+ export function renderBookingForm(o) {
57
+ const say = words(o.t);
58
+ return [
59
+ `<form class="wb-booking-details" method="post" action="${esc(o.endpoint)}">`,
60
+ `<h2 class="wb-booking-heading">${esc(say("form.title"))}</h2>`,
61
+ `<p class="wb-booking-when">${esc(o.title)}, ${esc(whenText(o.start, o.timeZone, o.locale ?? DEFAULT_LOCALE))}</p>`,
62
+ o.message ? `<p class="wb-booking-message" role="alert">${esc(o.message)}</p>` : "",
63
+ hidden("action", "book"),
64
+ hidden("service", o.service),
65
+ hidden("start", o.start),
66
+ o.with ? `${hidden("with", o.with.name)}<p class="wb-booking-with">${esc(say("with", { who: o.with.title }))}</p>` : "",
67
+ detailFields(o),
56
68
  `<div class="wb-booking-actions"><button class="wb-booking-submit" type="submit">${esc(say(o.confirm === "owner_approves" ? "form.submit_request" : "form.submit"))}</button>`,
57
69
  o.back ? `<a class="wb-booking-back" href="${esc(o.back)}">${esc(say("form.back"))}</a>` : "",
58
70
  "</div></form>",
59
71
  ].join("");
60
72
  }
73
+ /** "With Dr Lee, Room 1", when the page was given the resources' titles and the booking holds any. */
74
+ function withLine(b, o) {
75
+ const titles = o.resourceTitles?.(b) ?? [];
76
+ return titles.length ? `<p class="wb-booking-with">${esc(words(o.t)("with", { who: titles.join(", ") }))}</p>` : "";
77
+ }
61
78
  /** You're booked, or Request sent. */
62
79
  export function renderBookingDone(b, o) {
63
80
  const say = words(o.t);
@@ -66,7 +83,7 @@ export function renderBookingDone(b, o) {
66
83
  !pending && o.ics ? `<a class="wb-booking-ics" href="${esc(o.ics)}" download="booking.ics">${esc(say("done.ics"))}</a>` : "",
67
84
  o.manage ? `<a class="wb-booking-manage" href="${esc(o.manage)}">${esc(say("done.manage"))}</a>` : "",
68
85
  ].join("");
69
- return `<section class="wb-booking-done" role="status"><h2 class="wb-booking-heading">${esc(say(pending ? "done.pending.title" : "done.confirmed.title"))}</h2><p class="wb-booking-when">${esc(o.title)}, ${esc(whenText(b.starts_at, o.timeZone, o.locale ?? DEFAULT_LOCALE))}</p><p class="wb-booking-text">${esc(say(pending ? "done.pending.body" : "done.confirmed.body"))}</p>${links ? `<div class="wb-booking-actions">${links}</div>` : ""}</section>`;
86
+ return `<section class="wb-booking-done" role="status"><h2 class="wb-booking-heading">${esc(say(pending ? "done.pending.title" : "done.confirmed.title"))}</h2><p class="wb-booking-when">${esc(o.title)}, ${esc(whenText(b.starts_at, o.timeZone, o.locale ?? DEFAULT_LOCALE))}</p>${withLine(b, o)}<p class="wb-booking-text">${esc(say(pending ? "done.pending.body" : "done.confirmed.body"))}</p>${links ? `<div class="wb-booking-actions">${links}</div>` : ""}</section>`;
70
87
  }
71
88
  /** The customer's own booking page, from their manage link: when, its status, and cancel or move while they still can. */
72
89
  export function renderBookingManage(b, o) {
@@ -75,9 +92,9 @@ export function renderBookingManage(b, o) {
75
92
  const actions = !live
76
93
  ? ""
77
94
  : o.changeable
78
- ? `<div class="wb-booking-actions">${o.move ? `<a class="wb-booking-move" href="${esc(o.move)}">${esc(say("manage.move"))}</a>` : ""}${b.status === "confirmed" && o.ics ? `<a class="wb-booking-ics" href="${esc(o.ics)}" download="booking.ics">${esc(say("done.ics"))}</a>` : ""}<form class="wb-booking-cancel-form" method="post" action="${esc(o.endpoint)}">${hidden("action", "cancel")}${hidden("token", o.token)}<button class="wb-booking-cancel" type="submit">${esc(say("manage.cancel"))}</button></form></div>`
95
+ ? `<div class="wb-booking-actions">${o.move ? `<a class="wb-booking-move" href="${esc(o.move)}">${esc(say(b.session ? "manage.move_session" : "manage.move"))}</a>` : ""}${b.status === "confirmed" && o.ics ? `<a class="wb-booking-ics" href="${esc(o.ics)}" download="booking.ics">${esc(say("done.ics"))}</a>` : ""}<form class="wb-booking-cancel-form" method="post" action="${esc(o.endpoint)}">${hidden("action", "cancel")}${hidden("token", o.token)}<button class="wb-booking-cancel" type="submit">${esc(say("manage.cancel"))}</button></form></div>`
79
96
  : `<p class="wb-booking-locked">${esc(say("manage.locked"))}</p>`;
80
- return `<section class="wb-booking-page"><h2 class="wb-booking-heading">${esc(say("manage.title"))}</h2><p class="wb-booking-when">${esc(o.title)}, ${esc(whenText(b.starts_at, o.timeZone, o.locale ?? DEFAULT_LOCALE))}</p><p class="wb-booking-status">${esc(say(`status.${b.status}`))}</p>${actions}</section>`;
97
+ return `<section class="wb-booking-page"><h2 class="wb-booking-heading">${esc(say("manage.title"))}</h2><p class="wb-booking-when">${esc(o.title)}, ${esc(whenText(b.starts_at, o.timeZone, o.locale ?? DEFAULT_LOCALE))}</p>${withLine(b, o)}<p class="wb-booking-status">${esc(say(`status.${b.status}`))}</p>${actions}</section>`;
81
98
  }
82
99
  /** The owner's bookings, earliest first, with Accept and Decline for requests and Cancel for the rest. */
83
100
  export function renderBookingList(bookings, o) {
@@ -96,7 +113,7 @@ export function renderBookingList(bookings, o) {
96
113
  : b.status === "confirmed"
97
114
  ? form(b, "cancel", "wb-booking-owner-cancel", say("list.cancel"))
98
115
  : "";
99
- return `<li class="wb-booking-item"><article class="${cls}" id="wb-booking-${esc(b.id)}"><h3 class="wb-booking-title">${esc(whenText(b.starts_at, o.timeZone, locale))} · ${esc(o.titleOf(b.service))}</h3><p class="wb-booking-who">${esc(who)}</p>${b.places > 1 ? `<p class="wb-booking-places">${esc(say("list.places", { places: b.places }))}</p>` : ""}${b.customer.note ? `<p class="wb-booking-note">${esc(b.customer.note)}</p>` : ""}<p class="wb-booking-status">${esc(say(`status.${b.status}`))}</p>${buttons ? `<div class="wb-booking-actions">${buttons}</div>` : ""}</article></li>`;
116
+ return `<li class="wb-booking-item"><article class="${cls}" id="wb-booking-${esc(b.id)}"><h3 class="wb-booking-title">${esc(whenText(b.starts_at, o.timeZone, locale))} · ${esc(o.titleOf(b.service))}</h3><p class="wb-booking-who">${esc(who)}</p>${withLine(b, o)}${b.places > 1 ? `<p class="wb-booking-places">${esc(say("list.places", { places: b.places }))}</p>` : ""}${b.customer.note ? `<p class="wb-booking-note">${esc(b.customer.note)}</p>` : ""}<p class="wb-booking-status">${esc(say(`status.${b.status}`))}</p>${buttons ? `<div class="wb-booking-actions">${buttons}</div>` : ""}</article></li>`;
100
117
  };
101
118
  return `<section class="wb-booking-list">${head}<ul class="wb-booking-items">${bookings.map(item).join("")}</ul></section>`;
102
119
  }
@@ -116,7 +133,7 @@ export function renderMyBookings(bookings, o) {
116
133
  : o.changeable(b)
117
134
  ? `<div class="wb-booking-actions"><form class="wb-booking-cancel-form" method="post" action="${esc(o.endpoint)}">${hidden("action", "cancel")}${hidden("booking", b.id)}<button class="wb-booking-cancel" type="submit">${esc(say("mine.cancel"))}</button></form></div>`
118
135
  : `<p class="wb-booking-locked">${esc(say("manage.locked"))}</p>`;
119
- return `<li class="wb-booking-item"><article class="${cls}" id="wb-booking-${esc(b.id)}"><h3 class="wb-booking-title">${esc(whenText(b.starts_at, o.timeZone, locale))} · ${esc(o.titleOf(b.service))}</h3>${b.places > 1 ? `<p class="wb-booking-places">${esc(say("list.places", { places: b.places }))}</p>` : ""}<p class="wb-booking-status">${esc(say(`status.${b.status}`))}</p>${action}</article></li>`;
136
+ return `<li class="wb-booking-item"><article class="${cls}" id="wb-booking-${esc(b.id)}"><h3 class="wb-booking-title">${esc(whenText(b.starts_at, o.timeZone, locale))} · ${esc(o.titleOf(b.service))}</h3>${withLine(b, o)}${b.places > 1 ? `<p class="wb-booking-places">${esc(say("list.places", { places: b.places }))}</p>` : ""}<p class="wb-booking-status">${esc(say(`status.${b.status}`))}</p>${action}</article></li>`;
120
137
  };
121
138
  return `<section class="wb-booking-mine">${head}<ul class="wb-booking-items">${bookings.map(item).join("")}</ul>${book}</section>`;
122
139
  }
@@ -131,17 +148,22 @@ const STATUS = {
131
148
  too_many: 409,
132
149
  too_late: 409,
133
150
  unknown_booking: 404,
151
+ unknown_session: 404,
152
+ waitlist: 409,
153
+ not_full: 409,
154
+ already_waiting: 409,
155
+ too_small: 409,
134
156
  not_allowed: 403,
135
157
  store_failed: 502,
136
158
  };
137
- function failed(e, o) {
159
+ export function failed(e, o) {
138
160
  if (!(e instanceof BookingsError))
139
161
  throw e;
140
162
  const say = words(o.t);
141
163
  const field = e.code === "bad_input" ? /^(name|email|phone|note|places):/.exec(e.message)?.[1] : undefined;
142
164
  const text = field !== undefined
143
165
  ? say(`form.error.${field}`)
144
- : e.code === "taken" || e.code === "not_open" || e.code === "too_late" || e.code === "not_allowed" || e.code === "unknown_booking"
166
+ : e.code === "taken" || e.code === "not_open" || e.code === "too_late" || e.code === "not_allowed" || e.code === "unknown_booking" || e.code === "unknown_session" || e.code === "waitlist" || e.code === "not_full" || e.code === "already_waiting" || e.code === "too_small"
145
167
  ? say(`error.${e.code}`)
146
168
  : e.code === "too_many"
147
169
  ? say("error.too_many", { max: o.max ?? 3 })
@@ -149,7 +171,7 @@ function failed(e, o) {
149
171
  const message = INTERNAL.has(e.code) ? "bookings: it failed on the app's side (the detail is in ActionResult.cause, for the log)" : e.message;
150
172
  return { status: STATUS[e.code], body: { ok: false, error: e.code, message, text, ...(field ? { field } : {}) }, cause: e };
151
173
  }
152
- const str = (v) => (typeof v === "string" ? v : "");
174
+ export const str = (v) => (typeof v === "string" ? v : "");
153
175
  /**
154
176
  * The customer's posts, on the booking page: `book` (service, start, name,
155
177
  * email, places when the service allows more than one, and phone or note when
@@ -172,6 +194,7 @@ export async function bookingAction(bookings, body, ctx) {
172
194
  customer: { name: str(body.name), email: str(body.email), phone: str(body.phone), note: str(body.note) },
173
195
  ...(body.places !== undefined && body.places !== "" ? { places: /^[0-9]{1,3}$/.test(str(body.places)) ? Number(body.places) : NaN } : {}),
174
196
  ...(ctx.member ? { member: ctx.member } : {}),
197
+ ...(str(body.with) ? { with: str(body.with) } : {}),
175
198
  });
176
199
  return { status: 201, body: { ok: true, action, booking, token } };
177
200
  }
package/dist/words.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const BOOKING_WORD_KEYS: readonly ["picker.title", "picker.empty", "picker.more", "picker.left", "form.title", "form.name", "form.email", "form.phone", "form.phone_optional", "form.note", "form.places", "form.error.places", "form.submit", "form.submit_request", "form.back", "form.error.name", "form.error.email", "form.error.phone", "form.error.note", "error.taken", "error.not_open", "error.too_many", "error.too_late", "error.not_allowed", "error.unknown_booking", "error.failed", "done.confirmed.title", "done.confirmed.body", "done.pending.title", "done.pending.body", "done.ics", "done.manage", "manage.title", "manage.cancel", "manage.move", "manage.locked", "status.pending", "status.confirmed", "status.cancelled", "status.declined", "list.title", "list.empty", "list.approve", "list.decline", "list.cancel", "list.places", "mine.title", "mine.empty", "mine.cancel", "mine.book", "email.hello", "email.booked.subject", "email.booked.body", "email.requested.subject", "email.requested.body", "email.confirmed.subject", "email.confirmed.body", "email.declined.subject", "email.declined.body", "email.cancelled.subject", "email.cancelled.body", "email.moved.subject", "email.moved.body", "email.reminder.subject", "email.reminder.body", "email.places", "email.manage", "email.calendar", "email.owner.new.subject", "email.owner.request.subject", "email.owner.cancelled.subject", "email.owner.moved.subject", "email.owner.body", "email.owner.open", "email.owner.footer"];
1
+ export declare const BOOKING_WORD_KEYS: readonly ["picker.title", "picker.empty", "picker.more", "picker.left", "picker.choose", "picker.anyone", "with", "form.title", "form.name", "form.email", "form.phone", "form.phone_optional", "form.note", "form.places", "form.error.places", "form.submit", "form.submit_request", "form.back", "form.error.name", "form.error.email", "form.error.phone", "form.error.note", "error.taken", "error.not_open", "error.too_many", "error.too_late", "error.not_allowed", "error.unknown_booking", "error.failed", "done.confirmed.title", "done.confirmed.body", "done.pending.title", "done.pending.body", "done.ics", "done.manage", "manage.title", "manage.cancel", "manage.move", "manage.locked", "status.pending", "status.confirmed", "status.cancelled", "status.declined", "list.title", "list.empty", "list.approve", "list.decline", "list.cancel", "list.places", "mine.title", "mine.empty", "mine.cancel", "mine.book", "email.hello", "email.booked.subject", "email.booked.body", "email.requested.subject", "email.requested.body", "email.confirmed.subject", "email.confirmed.body", "email.declined.subject", "email.declined.body", "email.cancelled.subject", "email.cancelled.body", "email.moved.subject", "email.moved.body", "email.reminder.subject", "email.reminder.body", "email.places", "email.with", "email.manage", "email.calendar", "email.owner.new.subject", "email.owner.request.subject", "email.owner.cancelled.subject", "email.owner.moved.subject", "email.owner.body", "email.owner.open", "email.owner.footer", "error.waitlist", "error.not_full", "error.already_waiting", "error.too_small", "error.unknown_session", "session.title", "session.empty", "session.left", "session.full", "session.cancelled", "session.started", "session.book", "session.wait", "session.map", "session.series", "session.form.wait_title", "session.form.wait_body", "session.form.submit_wait", "session.form.back", "session.dates", "wait.title", "wait.waiting", "wait.offered", "wait.booked", "wait.expired", "wait.left", "wait.accept", "wait.decline", "wait.leave", "manage.move_session", "sessions.title", "sessions.empty", "sessions.add", "sessions.booked", "sessions.waiting", "sessions.min", "sessions.show_only", "sessions.edit", "sessions.roll", "sessions.cancel", "sessions.reason", "editor.title_new", "editor.title_edit", "editor.service", "editor.date", "editor.start", "editor.end", "editor.place", "editor.map", "editor.note", "editor.capacity", "editor.min", "editor.bookable", "editor.weeks", "editor.term", "editor.save", "editor.back", "roll.title", "roll.empty", "roll.came", "roll.missed", "roll.clear", "roll.back", "email.where", "email.map", "email.session_note", "email.dates", "email.reason", "email.session_cancelled.subject", "email.session_cancelled.body", "email.date_cancelled.subject", "email.date_cancelled.body", "email.waiting.subject", "email.waiting.body", "email.waiting.link", "email.offer.subject", "email.offer.body", "email.offer.link", "email.owner.short.subject", "email.owner.short.body", "email.owner.short.open"];
2
2
  export type BookingWordKey = (typeof BOOKING_WORD_KEYS)[number];
3
3
  /** The words in Australian English, as `ui.wbbooking.<key>` would hold them. */
4
4
  export declare const BOOKING_WORDS: Readonly<Record<BookingWordKey, string>>;