@semics-tech/emdash-events 1.0.0-rc.2 → 1.0.0-rc.22

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.
@@ -0,0 +1,143 @@
1
+ // i18n-ignore-file: a stylesheet and its option names, no text for people.
2
+ /**
3
+ * The look of the plugins' own full pages (`/booking`, the suite's `/_events/waiver`), which run outside the
4
+ * site's layout: a default stylesheet built only on the `--events-*` properties, and what a site sets through
5
+ * `eventsIntegration({ page })` / `eventsSuite({ page })`. It is one exact string so the signing page can allow
6
+ * it by hash (its CSP allows nothing else inline, `ceremonyCsp`). Web APIs only (R35).
7
+ *
8
+ * The site's own layout is deliberately not wrapped around these pages: an emailed link's one-time code is in the
9
+ * URL here, and a signing page's CSP would block the layout's scripts and styles anyway.
10
+ */
11
+
12
+ /** A theme value by property: `accent` sets `--events-accent` (the signing form follows, see `PAGE_CSS`). */
13
+ export const THEME_PROPERTIES = [
14
+ "fg",
15
+ "muted",
16
+ "bg",
17
+ "border",
18
+ "accent",
19
+ "accent-fg",
20
+ "error",
21
+ "success",
22
+ "radius",
23
+ "font",
24
+ "page-bg",
25
+ "heading-font",
26
+ "heading-fg",
27
+ ] as const;
28
+ export type ThemeProperty = (typeof THEME_PROPERTIES)[number];
29
+ export interface PageBrand {
30
+ /** The site's name: the link's text, or the logo's alternative text. Also the organiser at the page's foot. */
31
+ name: string;
32
+ /** Where it links, a path on this site (default `/`). */
33
+ href?: string;
34
+ /** A logo, a path on this site. */
35
+ logo?: string;
36
+ /** The organiser's postal address, one line, at the page's foot and on a printed booking (T157). */
37
+ address?: string;
38
+ }
39
+
40
+ /** One line of text for people: 1 to 300 characters, no control characters (line breaks included). */
41
+ function oneLine(value: unknown): boolean {
42
+ if (typeof value !== "string" || !value.trim() || value.length > 300) return false;
43
+ for (let i = 0; i < value.length; i++) {
44
+ const unit = value.charCodeAt(i);
45
+ if (unit <= 0x1f || unit === 0x7f) return false;
46
+ }
47
+ return true;
48
+ }
49
+
50
+ export interface PageOptions {
51
+ /** Values for the pages' custom properties, for example `{ accent: "#1f3a2e", "page-bg": "#f6f1ea" }`. */
52
+ theme?: Partial<Record<ThemeProperty, string>>;
53
+ /** A stylesheet on this site, loaded after the defaults: for `@font-face`, or any further rules. */
54
+ stylesheet?: string;
55
+ /** The site's name or logo at the top of each page. */
56
+ brand?: PageBrand;
57
+ /** The event's page, where "Book again" goes: a path with `{slug}` (default `/events/{slug}`). */
58
+ eventPath?: string;
59
+ }
60
+
61
+ /** One line of CSS, nothing that could end the declaration, the rule or the `<style>` element. */
62
+ const THEME_VALUE = /^[^;{}<>\\@]{1,200}$/;
63
+ /** A path on this site; `;` and `,` would end a source in the signing page's CSP header. */
64
+ const SITE_PATH = /^\/(?!\/)[^\s"'<>\\;,]*$/;
65
+
66
+ /** Checks a site's page options when the site's config loads; a bad value stops the build with its name. */
67
+ export function checkPageOptions(page: PageOptions = {}): PageOptions {
68
+ const refuse = (what: string) => {
69
+ throw new Error(`page.${what} is not valid`); // i18n-ignore
70
+ };
71
+ for (const [name, value] of Object.entries(page.theme ?? {})) {
72
+ const known = (THEME_PROPERTIES as readonly string[]).includes(name);
73
+ if (!known || typeof value !== "string" || !THEME_VALUE.test(value) || /url\(/i.test(value))
74
+ refuse(`theme.${name}`);
75
+ }
76
+ const { brand, stylesheet, eventPath } = page;
77
+ if (stylesheet !== undefined && !SITE_PATH.test(stylesheet)) refuse("stylesheet");
78
+ if (eventPath !== undefined && !(SITE_PATH.test(eventPath) && eventPath.includes("{slug}"))) refuse("eventPath");
79
+ if (brand) {
80
+ if (typeof brand.name !== "string" || !brand.name.trim()) refuse("brand.name");
81
+ if (brand.href !== undefined && !SITE_PATH.test(brand.href)) refuse("brand.href");
82
+ if (brand.logo !== undefined && !SITE_PATH.test(brand.logo)) refuse("brand.logo");
83
+ if (brand.address !== undefined && !oneLine(brand.address)) refuse("brand.address");
84
+ }
85
+ return page;
86
+ }
87
+
88
+ /** The event's page for "Book again"; undefined when the booking does not know its slug. */
89
+ export function eventPageHref(slug: string | null | undefined, eventPath?: string): string | undefined {
90
+ return slug ? (eventPath ?? "/events/{slug}").replace("{slug}", encodeURIComponent(slug)) : undefined;
91
+ }
92
+
93
+ /**
94
+ * Works with no site theme at all. Zero specificity on elements, so the components' own rules win; except the card
95
+ * rule for `main`'s sections, which outranks a component's own box (`.semics-payment`, `.semics-attendee-list`) so
96
+ * every card has the same edges, width and look (T158).
97
+ */
98
+ export const PAGE_CSS = `*,*::before,*::after{box-sizing:border-box}
99
+ html{color-scheme:light;-webkit-text-size-adjust:100%}
100
+ body.semics-page{margin:0;min-block-size:100vh;background:var(--events-page-bg, #f5f4f0);color:var(--events-fg, #1a1a1a);font-family:var(--events-font, system-ui, sans-serif);font-size:1.0625rem;line-height:1.55;overflow-wrap:anywhere;
101
+ --esign-fg:var(--events-fg, #1a1a1a);--esign-muted:var(--events-muted, #4a4a4a);--esign-bg:var(--events-bg, #ffffff);--esign-border:var(--events-border, #6b6b6b);--esign-accent:var(--events-accent, #0b57d0);--esign-accent-fg:var(--events-accent-fg, #ffffff);--esign-error:var(--events-error, #b3261e);--esign-radius:var(--events-radius, 6px);--esign-font:var(--events-font, system-ui, sans-serif)}
102
+ .semics-page-brand{max-inline-size:40rem;margin-inline:auto;padding:1.25rem 1rem 0;font-family:var(--events-heading-font, inherit);font-weight:600}
103
+ .semics-page-brand a{color:var(--events-heading-fg, inherit);text-decoration:none}
104
+ .semics-page-brand img{display:block;block-size:2.5rem;inline-size:auto;max-inline-size:100%}
105
+ .semics-page-main{max-inline-size:40rem;margin-inline:auto;padding:1.5rem 1rem 2rem}
106
+ :where(.semics-page) :is(h1,h2,h3){margin:0 0 .75rem;font-family:var(--events-heading-font, inherit);color:var(--events-heading-fg, inherit);line-height:1.2}
107
+ :where(.semics-page) h1{margin-block-end:1.25rem;font-size:clamp(1.75rem,1.5rem + 1.5vw,2.25rem)}
108
+ :where(.semics-page) h2{font-size:1.25rem}
109
+ :where(.semics-page) h3{font-size:1.0625rem}
110
+ :where(.semics-page) p{margin:0 0 .75rem}
111
+ :where(.semics-page) a{color:var(--events-accent, #0b57d0);text-underline-offset:.2em}
112
+ :where(.semics-page) :focus-visible{outline:3px solid var(--events-accent, #0b57d0);outline-offset:2px}
113
+ .semics-page-main > :is(section,form:not([hidden]),.semics-ceremony){margin-block:0 1.25rem;padding:clamp(1.25rem,.9rem + 1.8vw,1.75rem);background:var(--events-bg, #ffffff);border:1px solid color-mix(in srgb,var(--events-border, #6b6b6b) 30%,transparent);border-radius:calc(var(--events-radius, 6px) + 6px);box-shadow:0 1px 2px rgb(0 0 0 / .04),0 6px 24px rgb(0 0 0 / .05);max-inline-size:none}
114
+ :where(.semics-page-main > section,.semics-page-main > form,.semics-page-main > .semics-ceremony) > :last-child{margin-block-end:0}
115
+ :where(.semics-page) [role="alert"]{padding:.75rem 1rem;border:1px solid var(--events-error, #b3261e);border-radius:var(--events-radius, 6px);background:var(--events-bg, #ffffff);color:var(--events-error, #b3261e)}
116
+ :where(.semics-page) :is(input:not([type="checkbox"],[type="radio"],[type="hidden"]),select,textarea){font:inherit;inline-size:100%;min-block-size:2.75rem;padding:.5rem .75rem;border:1px solid var(--events-border, #6b6b6b);border-radius:var(--events-radius, 6px);background:var(--events-bg, #ffffff);color:var(--events-fg, #1a1a1a)}
117
+ :where(.semics-page) label{display:block}
118
+ :where(.semics-page) fieldset{min-inline-size:0;margin:0 0 1rem;padding:0;border:0}
119
+ :where(.semics-page) legend{padding:0;margin-block-end:.5rem;font-weight:600}
120
+ :where(.semics-page) button{font:inherit;font-weight:600;min-block-size:2.75rem;padding:.625rem 1.25rem;border:1px solid var(--events-accent, #0b57d0);border-radius:var(--events-radius, 6px);background:var(--events-accent, #0b57d0);color:var(--events-accent-fg, #ffffff);cursor:pointer}
121
+ :where(.semics-page) a.semics-page-button{display:inline-block;font-weight:600;padding:.625rem 1.25rem;border:1px solid var(--events-accent, #0b57d0);border-radius:var(--events-radius, 6px);background:var(--events-accent, #0b57d0);color:var(--events-accent-fg, #ffffff);text-decoration:none}
122
+ .semics-page-actions{display:flex;flex-wrap:wrap;align-items:center;gap:.75rem 1.25rem;margin-block:0 1.25rem}
123
+ .semics-page-actions .semics-print{background:transparent;color:var(--events-accent, #0b57d0)}
124
+ .semics-page-organiser{max-inline-size:40rem;margin-inline:auto;padding:0 1rem 3rem;color:var(--events-muted, #4a4a4a);font-size:.9375rem}
125
+ .semics-page-organiser p{margin:0}
126
+ .semics-page-organiser address{font-style:normal}
127
+ @media print{
128
+ @page{margin:15mm}
129
+ body.semics-page{min-block-size:0;background:#ffffff;color:#000000;font-size:11pt}
130
+ .semics-page-brand,.semics-page-actions,.semics-page-main form,.semics-page-main button,.semics-page-main details,.semics-add-to-calendar,[data-semics-payment-live]{display:none !important}
131
+ .semics-page-main{max-inline-size:none;padding:0}
132
+ .semics-page-main > :is(section,form:not([hidden]),.semics-ceremony){box-shadow:none;border-color:#999999;break-inside:avoid}
133
+ .semics-ticket-pass{break-inside:avoid}
134
+ .semics-page-organiser{max-inline-size:none;padding:1rem 0 0;color:#000000}
135
+ }
136
+ `;
137
+
138
+ /** The stylesheet for a page: the defaults, then the site's theme. Exact: the signing page hashes this text. */
139
+ export function pageCss(page: PageOptions = {}): string {
140
+ const set = Object.entries(page.theme ?? {}) as Array<[ThemeProperty, string]>;
141
+ if (set.length === 0) return PAGE_CSS;
142
+ return `${PAGE_CSS}:root{${set.map(([name, value]) => `--events-${name}:${value}`).join(";")}}\n`;
143
+ }
@@ -33,3 +33,12 @@ export function qrPath(qr: unknown): QrPath | null {
33
33
  }
34
34
  return { size, d };
35
35
  }
36
+
37
+ /**
38
+ * A check-in code in groups of four for reading (T158): the pass draws each group as its own span, spaced by CSS, so
39
+ * the text (and a copy of it) stays the exact value door check-in takes. A short code (12 or fewer) stays whole.
40
+ */
41
+ export function codeGroups(code: string): string[] {
42
+ if (code.length <= 12) return code ? [code] : [];
43
+ return code.match(/.{1,4}/gsu) ?? [];
44
+ }
@@ -5,6 +5,7 @@
5
5
  * way" are told apart by asking the core, never by a query parameter.
6
6
  */
7
7
  import { type MessageKey, t } from "../../i18n/index";
8
+ import { zonedAt } from "./list";
8
9
  import type { BookingView } from "./widget";
9
10
 
10
11
  export type PaymentState = "confirmed" | "pending" | "expired" | "cancelled" | "refunded" | "refunded_unavailable";
@@ -19,15 +20,6 @@ export interface PaymentView {
19
20
  resume: boolean;
20
21
  }
21
22
 
22
- const utc = (iso: string, locale: string) => {
23
- try {
24
- const at = new Intl.DateTimeFormat(locale, { dateStyle: "medium", timeStyle: "short", timeZone: "UTC" });
25
- return t(locale, "time.utc", { time: at.format(new Date(iso)) });
26
- } catch {
27
- return iso;
28
- }
29
- };
30
-
31
23
  /** The provider's payment page is followed only when it is an `https:` URL (never `javascript:` or `//host`). */
32
24
  export function isPayUrl(value: unknown): value is string {
33
25
  if (typeof value !== "string" || !value.startsWith("https://")) return false;
@@ -49,13 +41,17 @@ const final = (state: PaymentState, locale: string): PaymentView => ({
49
41
  /** The payment section for a booking, or `null` when there is nothing to say about money. */
50
42
  export function paymentView(booking: BookingView, locale = "en-GB"): PaymentView | null {
51
43
  const paid = booking.totals.totalMinor > 0;
44
+ // Ran out waiting for the organiser: not about a payment (`endedNotes` says what happened).
45
+ if (booking.status === "expired" && booking.undecided) return null;
52
46
  switch (booking.status) {
53
47
  case "awaiting_payment":
54
48
  return {
55
49
  state: "pending",
56
50
  heading: t(locale, "payment.pending.heading"),
57
51
  body: booking.holdExpiresAt
58
- ? t(locale, "payment.pending.bodyUntil", { time: utc(booking.holdExpiresAt, locale) })
52
+ ? t(locale, "payment.pending.bodyUntil", {
53
+ time: zonedAt(booking.holdExpiresAt, booking.event?.timezone, locale),
54
+ })
59
55
  : t(locale, "payment.pending.body"),
60
56
  poll: true,
61
57
  resume: true,
@@ -25,6 +25,8 @@ export interface PublicEvent {
25
25
  available?: number | null;
26
26
  minPerOrder?: number | null;
27
27
  maxPerOrder?: number | null;
28
+ /** Events Pro (T174d): a per-person add-on, not a place; the widget lists it under the tickets, capped by the places. */
29
+ addon?: boolean;
28
30
  }>;
29
31
  /** Upcoming open dates, earliest first: up to 200 from the asked `from` (T130). */
30
32
  occurrences?: Array<{ id: string; startsAt: string; endsAt?: string | null; available?: number | null }>;
@@ -32,25 +34,73 @@ export interface PublicEvent {
32
34
  more?: boolean;
33
35
  /** The event sells slots of a schedule (T129): the form uses the day-then-time picker (T130). */
34
36
  slots?: boolean;
37
+ /** The event takes booking requests (T174a): the form asks for a date and a time window instead of a date. */
38
+ requests?: PublicRequests;
35
39
  /** Public Turnstile site key, when the site owner configured one. */
36
40
  turnstileSiteKey?: string;
37
41
  /** True when the event requires a signed waiver (T066): the booking form then asks for attendees. */
38
42
  waiver?: boolean;
43
+ /** Events Pro: that waiver is signed per attendee, so its seat rules can be checked before reserving. */
44
+ waiverEach?: boolean;
45
+ /** Events Pro (T160): the waiver is signed after payment (`waiverTiming: "after-payment"`), for a paid order. */
46
+ waiverAfter?: boolean;
39
47
  /** True when the core takes promo codes (Events Pro, T078): the widget then shows a code field. */
40
48
  promoCodes?: boolean;
49
+ /** True when Events Pro is paired with Vouchers (T166): the widget then shows a "Gift voucher code" field. */
50
+ vouchers?: boolean;
41
51
  /** True when a sold-out event takes a waitlist (T081): the widget then shows a "Join the waitlist" form. */
42
52
  waitlist?: boolean;
43
53
  /** Custom attendee questions (Events Pro, T080): the buyer answers them once per booking. */
44
54
  questions?: PublicQuestion[];
45
55
  }
46
56
 
57
+ /** What an event takes booking requests for (T174a): windows in local `HH:MM`, weekdays `MO`..`SU`. */
58
+ export interface PublicRequests {
59
+ windows: Array<{ id: string; label: string; start: string; end: string }>;
60
+ days: string[];
61
+ aheadDays: number;
62
+ noticeDays: number;
63
+ closedDates: string[];
64
+ }
65
+
66
+ const WEEKDAYS = ["SU", "MO", "TU", "WE", "TH", "FR", "SA"];
67
+
68
+ /**
69
+ * The dates a request may ask for (T174a), as the core checks them: allowed weekdays from `noticeDays` to
70
+ * `aheadDays` after today in the event's zone, without closed dates. `value` is the local `YYYY-MM-DD`.
71
+ */
72
+ export function requestDates(
73
+ r: PublicRequests,
74
+ zone: string,
75
+ now: number,
76
+ locale?: string,
77
+ ): Array<{ value: string; label: string }> {
78
+ let today: string;
79
+ try {
80
+ today = new Intl.DateTimeFormat("en-CA", { timeZone: zone }).format(new Date(now));
81
+ } catch {
82
+ today = new Date(now).toISOString().slice(0, 10);
83
+ }
84
+ const start = Date.parse(`${today}T00:00:00Z`);
85
+ const label = new Intl.DateTimeFormat(locale, { dateStyle: "full", timeZone: "UTC" });
86
+ const out: Array<{ value: string; label: string }> = [];
87
+ for (let i = r.noticeDays; i <= r.aheadDays; i++) {
88
+ const day = new Date(start + i * 864e5);
89
+ const value = day.toISOString().slice(0, 10);
90
+ if (r.days.includes(WEEKDAYS[day.getUTCDay()] as string) && !r.closedDates.includes(value)) {
91
+ out.push({ value, label: label.format(day) });
92
+ }
93
+ }
94
+ return out;
95
+ }
96
+
47
97
  /**
48
98
  * Ticket type names by id from a `public/event` answer, for `<BookingStatus>` (T134): the booking's
49
99
  * lines carry only ids (UUIDs for types made in the editor). A hidden type is not listed there.
50
100
  */
51
101
  /** Whether the booking page hands the booking to the suite's reconciliation: lookups, or void intents (T152). */
52
- export const reconcileWanted = (b: Pick<BookingView, "waiver"> | undefined): boolean =>
53
- Boolean(b?.waiver?.lookups || b?.waiver?.voids);
102
+ export const reconcileWanted = (b: Pick<BookingView, "waiver" | "voucher"> | undefined): boolean =>
103
+ Boolean(b?.waiver?.lookups || b?.waiver?.voids || b?.voucher?.settle);
54
104
 
55
105
  export function ticketNames(event: Pick<PublicEvent, "ticketTypes"> | undefined): Record<string, string> {
56
106
  return Object.fromEntries((event?.ticketTypes ?? []).map((t) => [t.id, t.name]));
@@ -71,9 +121,28 @@ export interface BookingView {
71
121
  bookingRef: string;
72
122
  status: string;
73
123
  eventId?: string;
74
- lines: Array<{ ticketTypeId: string; qty: number }>;
75
- totals: { totalMinor: number; currency: string };
124
+ /** `addon` (T174d): a per-person add-on line, not a place. */
125
+ lines: Array<{ ticketTypeId: string; qty: number; addon?: boolean }>;
126
+ /** `voucherMinor`: what a gift voucher paid (Events Pro, T166), already taken off `totalMinor`. */
127
+ totals: { totalMinor: number; currency: string; voucherMinor?: number };
128
+ /** Events Pro (T166): the voucher hold's signed outcome, which the suite passes to Vouchers. */
129
+ voucher?: { settle?: string | null };
76
130
  holdExpiresAt?: string;
131
+ /** The event's public info: the booked session (`startsAt`, in `timezone`) and `venue` lead the page (T157); `slug` for "Book again". */
132
+ event?: { title?: string; startsAt?: string; timezone?: string | null; venue?: string | null; slug?: string | null };
133
+ /** A booking request whose time is still to be agreed (T174a): what was asked for, "Sat 12 Dec, AM". */
134
+ requested?: string;
135
+ /**
136
+ * Events Pro (T174c): another time the organiser proposed for a request awaiting approval. The buyer accepts it or
137
+ * says it doesn't work (`public/booking/request/accept` / `.../refuse`) by `holdExpiresAt`.
138
+ */
139
+ proposed?: { startsAt: string; endsAt?: string };
140
+ /** Why the organiser declined (`status: "declined"`), when they said. */
141
+ declineReason?: string | null;
142
+ /** Declined, a price was due and no money was taken (`closeBooking`). */
143
+ notCharged?: boolean;
144
+ /** Expired, this means it ran out waiting for the organiser's decision (Pro: not one approved but left unpaid). */
145
+ undecided?: boolean;
77
146
  /** `qr`: Events Pro's QR matrix of `code` (T082), drawn by `<TicketPass>`; Free sends none. */
78
147
  attendees: Array<{ name: string; ticketTypeId?: string; status: string; code?: string; qr?: unknown }>;
79
148
  canCancel: boolean;
@@ -86,23 +155,26 @@ export interface BookingView {
86
155
  * has ended (expired, cancelled), Pro lists instead a void intent per seat not signed (T152).
87
156
  */
88
157
  waiver?: { refs: string[]; lookups?: Record<string, string>; voids?: Record<string, string> };
158
+ /** Events Pro (T160): the booking's waiver comes after payment, so a paid booking is confirmed with seats still to sign. */
159
+ waiverAfter?: boolean;
89
160
  /**
90
161
  * Events Pro (T133): a waiver booking's attendee signing list. Each attendee then also carries
91
162
  * `seat`, `signing`, `signs`, `email` and `minor` (`SigningAttendee` in `lib/attendees.ts`);
92
163
  * `editable` says whether names and emails may still be changed, until `editUntil`.
93
164
  */
94
- signingList?: { editable: boolean; editUntil?: string };
165
+ /** `minors` (T174e): a booking request, whose seats the edit form may also mark under 18. */
166
+ signingList?: { editable: boolean; editUntil?: string; minors?: boolean };
95
167
  }
96
168
 
97
169
  /** A custom question's field is `q:<question id>` (T080). */
98
170
  export type QuestionField = `q:${string}`;
99
- export type WidgetField = "occurrence" | "promo" | "tickets" | "name" | "email" | QuestionField;
171
+ export type WidgetField = "occurrence" | "promo" | "voucher" | "tickets" | "name" | "email" | QuestionField;
100
172
 
101
173
  /** Question ids safe in HTML ids, field names and the widget's error URL. */
102
174
  export const QUESTION_ID = /^[A-Za-z0-9_-]{1,64}$/;
103
175
 
104
176
  /** In form order: the first one is where focus goes. */
105
- export const WIDGET_FIELDS = ["occurrence", "promo", "tickets", "name", "email"] as const;
177
+ export const WIDGET_FIELDS = ["occurrence", "promo", "voucher", "tickets", "name", "email"] as const;
106
178
 
107
179
  export const WIDGET_PARAMS = { error: "booking_error", fields: "booking_fields", event: "booking_event" } as const;
108
180
 
@@ -121,6 +193,11 @@ const ERROR_CODES = [
121
193
  "PROMO_EXHAUSTED",
122
194
  "PROMO_ORDER_TOO_LARGE",
123
195
  "PROMO_UNAVAILABLE",
196
+ "VOUCHER_INVALID",
197
+ "VOUCHER_NO_BALANCE",
198
+ "VOUCHER_WRONG_ACTIVITY",
199
+ "VOUCHER_CURRENCY",
200
+ "VOUCHER_UNAVAILABLE",
124
201
  "INTERNAL",
125
202
  ] as const;
126
203
 
@@ -228,6 +305,8 @@ export function validateCheckoutFields(v: CheckoutFieldValues): WidgetField[] {
228
305
 
229
306
  const ISSUE_FIELDS: Array<[RegExp, WidgetField]> = [
230
307
  [/^occurrenceId/, "occurrence"],
308
+ // A refused booking request's date or window (T174a): the request's date field is the "occurrence" one.
309
+ [/^request/, "occurrence"],
231
310
  [/^lines/, "tickets"],
232
311
  [/^buyer\.name/, "name"],
233
312
  [/^buyer\.email/, "email"],
@@ -302,3 +381,36 @@ export const statusLabel = (status: string, locale?: string) =>
302
381
 
303
382
  /** English status labels (the 1.0 API; components use `statusLabel`). */
304
383
  export const STATUS_LABELS: Record<string, string> = Object.fromEntries(STATUSES.map((s) => [s, statusLabel(s, "en")]));
384
+
385
+ /**
386
+ * The booking as it stands at `now`: a hold past its deadline has lapsed even before the sweeper moves it (the core
387
+ * refuses anything on it, and the waiver page already says so), so the page shows it as expired.
388
+ */
389
+ export function asOfNow<T extends Pick<BookingView, "status" | "holdExpiresAt" | "canCancel">>(
390
+ booking: T,
391
+ now: number,
392
+ ): T {
393
+ const until = booking.holdExpiresAt ? Date.parse(booking.holdExpiresAt) : Number.NaN;
394
+ if (!(until <= now)) return booking;
395
+ const { holdExpiresAt: _gone, ...rest } = booking;
396
+ return { ...rest, status: "expired", canCancel: false } as T;
397
+ }
398
+
399
+ /** What a booking that ended without going ahead should say beyond its status (declined, or lapsed). */
400
+ export function endedNotes(
401
+ booking: Pick<BookingView, "status" | "declineReason" | "notCharged" | "undecided"> & {
402
+ totals?: BookingView["totals"];
403
+ },
404
+ locale?: string,
405
+ ) {
406
+ if (booking.status === "expired") {
407
+ if (booking.undecided) return [t(locale, "booking.undecided")];
408
+ // A paid one has the payment section's "This booking expired": only what that does not say.
409
+ return [t(locale, booking.totals?.totalMinor ? "booking.signAgain" : "booking.lapsed")];
410
+ }
411
+ if (booking.status !== "declined") return [];
412
+ return [
413
+ ...(booking.declineReason ? [t(locale, "booking.declinedReason", { reason: booking.declineReason })] : []),
414
+ ...(booking.notCharged ? [t(locale, "booking.notCharged")] : []),
415
+ ];
416
+ }
@@ -1,6 +1,8 @@
1
1
  // Provided by the integration's Vite plugin (`eventsIntegration({ pluginId })`).
2
2
  declare module "virtual:semics-events/config" {
3
3
  export const pluginId: string;
4
+ /** How the site dresses the plugin's own pages (`eventsIntegration({ page })`). */
5
+ export const page: import("./lib/page").PageOptions;
4
6
  /** The e-sign core's plugin id, or `null` when e-sign is not configured (`eventsIntegration({ esignPluginId })`). */
5
7
  export const esignPluginId: string | null;
6
8
  /**
@@ -10,7 +12,29 @@ declare module "virtual:semics-events/config" {
10
12
  export const reconcile:
11
13
  | ((
12
14
  ctx: import("./lib/call").PublicRouteContext,
13
- input: { booking: import("./lib/widget").BookingView; pluginId: string; esignPluginId: string },
15
+ input: {
16
+ booking: import("./lib/widget").BookingView;
17
+ pluginId: string;
18
+ esignPluginId: string;
19
+ vouchersPluginId?: string;
20
+ },
14
21
  ) => Promise<{ forwarded: number }>)
15
22
  | null;
23
+ /** Gift vouchers (T166): only exported with `eventsIntegration({ vouchers })`; read through a namespace import. */
24
+ export const vouchersPluginId: string | undefined;
25
+ export const holdVoucher:
26
+ | ((
27
+ ctx: import("./lib/call").PublicRouteContext,
28
+ input: { code: string; bookingRef: string; accessToken: string },
29
+ ids: { eventsPluginId: string; vouchersPluginId: string },
30
+ ) => Promise<import("./lib/checkout-form").VoucherHoldResult>)
31
+ | undefined;
32
+ /** T168: the suite's check of a code before reserving; exported with `holdVoucher`. */
33
+ export const checkVoucher:
34
+ | ((
35
+ ctx: import("./lib/call").PublicRouteContext,
36
+ input: { code: string; eventId: string; ticketTypeIds: string[] },
37
+ ids: { vouchersPluginId: string },
38
+ ) => Promise<{ ok: true } | { ok: false; code: string }>)
39
+ | undefined;
16
40
  }
@@ -72,6 +72,14 @@ export function orderTotalMinor(lines: ReadonlyArray<{ qty: number; priceMinor:
72
72
  return total;
73
73
  }
74
74
 
75
+ /**
76
+ * The most of a per-person add-on (T174d) the buyer may order: one each for the places chosen, within the add-on's
77
+ * own limit. Pro's reserve refuses more (`INVALID_QUANTITY`), so without this script the server says so.
78
+ */
79
+ export function addonMax(places: number, own: number): number {
80
+ return Math.max(0, Math.min(own, places));
81
+ }
82
+
75
83
  /** `free` is the page's word for a zero total (the widget renders it as `data-free`, T102). */
76
84
  export function formatMinor(minor: number, currency: string, locale: string, free: string): string {
77
85
  if (minor === 0) return free;
@@ -131,6 +139,17 @@ export function enhance(form: HTMLFormElement): void {
131
139
  if (button) button.disabled = false;
132
140
 
133
141
  const qtyInputs = Array.from(form.querySelectorAll<HTMLInputElement>('input[name^="qty:"]'));
142
+ // Per-person add-ons (T174d) are not places: capped live by the places chosen.
143
+ const addons = qtyInputs.filter((i) => i.dataset.addon !== undefined);
144
+ const places = qtyInputs.filter((i) => i.dataset.addon === undefined);
145
+ const capAddons = () => {
146
+ const chosen = places.reduce((n, i) => n + Math.max(qtyOf(i), 0), 0);
147
+ for (const a of addons) {
148
+ const most = addonMax(chosen, Number(a.dataset.max) || 50);
149
+ a.max = String(most);
150
+ if (qtyOf(a) > most) a.value = String(most);
151
+ }
152
+ };
134
153
  const total = form.querySelector<HTMLElement>("[data-total]");
135
154
  const totalValue = total?.querySelector<HTMLElement>("[data-total-value]");
136
155
  const updateTotal = () => {
@@ -146,8 +165,12 @@ export function enhance(form: HTMLFormElement): void {
146
165
  );
147
166
  total.hidden = false;
148
167
  };
149
- for (const input of qtyInputs) input.addEventListener("input", updateTotal);
150
- updateTotal();
168
+ const changed = () => {
169
+ capAddons();
170
+ updateTotal();
171
+ };
172
+ for (const input of qtyInputs) input.addEventListener("input", changed);
173
+ changed();
151
174
 
152
175
  form.addEventListener("submit", (event) => {
153
176
  if (form.dataset.submitting) {
@@ -158,7 +181,8 @@ export function enhance(form: HTMLFormElement): void {
158
181
  ...validateBooking({
159
182
  name: fieldValue(form, "name"),
160
183
  email: fieldValue(form, "email"),
161
- lines: qtyInputs.filter((i) => qtyOf(i) > 0).length,
184
+ // Add-ons alone are no order: only places count as lines here.
185
+ lines: places.filter((i) => qtyOf(i) > 0).length,
162
186
  needsOccurrence: fieldValue(form, "needsOccurrence") === "1",
163
187
  occurrenceId: fieldValue(form, "occurrenceId"),
164
188
  }),
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Forgets what the suite's booking form kept for a refusal (`keep-form.ts` in the suite): a person who reaches the
3
+ * booking page has got past the form, and on a shared device their details must not linger. Self-contained.
4
+ */
5
+ export function forgetKeptForms(storage: Pick<Storage, "length" | "key" | "removeItem">): void {
6
+ for (let i = storage.length - 1; i >= 0; i--) {
7
+ const key = storage.key(i);
8
+ if (key?.startsWith("semics-waiver-form:")) storage.removeItem(key);
9
+ }
10
+ }
11
+
12
+ try {
13
+ if (typeof document !== "undefined") forgetKeptForms(sessionStorage);
14
+ } catch {
15
+ // Storage is blocked: nothing was kept either.
16
+ }
@@ -60,10 +60,14 @@ export function enhancePicker(picker: HTMLElement): void {
60
60
  const radios = (group: HTMLElement) => Array.from(group.querySelectorAll<HTMLButtonElement>('[role="radio"]'));
61
61
  const isOpen = (b: HTMLElement) => b.getAttribute("aria-disabled") !== "true";
62
62
 
63
+ // The picker's own changes, which `showSelected` (below) need not follow.
64
+ let own = false;
63
65
  const setSelect = (value: string) => {
64
66
  if (select.value === value) return;
65
67
  select.value = value;
68
+ own = true;
66
69
  select.dispatchEvent(new Event("change", { bubbles: true }));
70
+ own = false;
67
71
  };
68
72
 
69
73
  const chooseTime = (button: HTMLButtonElement, focus: boolean) => {
@@ -127,15 +131,22 @@ export function enhancePicker(picker: HTMLElement): void {
127
131
  }
128
132
  }
129
133
 
130
- // A value the browser kept (back/forward, a failed submit): show its day and time.
131
- const kept =
132
- select.value && picker.querySelector<HTMLButtonElement>(`[data-occurrence="${CSS.escape(select.value)}"]`);
133
- const keptDay =
134
- kept && dayButtons.find((b) => b.dataset.day === kept.closest<HTMLElement>("[data-times]")?.dataset.times);
135
- if (kept && keptDay) {
136
- showDay(keptDay, false);
137
- chooseTime(kept, false);
138
- }
134
+ // A value the browser kept (back/forward, a failed submit): show its day and time. Also when a script sets
135
+ // the select later and says so with `change` (the suite's refused-form restore, whose script may run after
136
+ // this one, T157); the picker's own changes are skipped.
137
+ const showSelected = () => {
138
+ if (own) return;
139
+ const kept =
140
+ select.value && picker.querySelector<HTMLButtonElement>(`[data-occurrence="${CSS.escape(select.value)}"]`);
141
+ const keptDay =
142
+ kept && dayButtons.find((b) => b.dataset.day === kept.closest<HTMLElement>("[data-times]")?.dataset.times);
143
+ if (kept && keptDay) {
144
+ showDay(keptDay, false);
145
+ chooseTime(kept, false);
146
+ }
147
+ };
148
+ select.addEventListener("change", showSelected);
149
+ showSelected();
139
150
  }
140
151
 
141
152
  if (typeof document !== "undefined") {
@@ -0,0 +1,12 @@
1
+ /**
2
+ * "Print or save as PDF" on the booking page (T157): the button stays hidden without JavaScript (it could do
3
+ * nothing there; the browser's own Print still uses the page's print stylesheet). Self-contained; no text.
4
+ */
5
+ export function wirePrint(doc: Document, print: () => void): void {
6
+ for (const button of doc.querySelectorAll<HTMLButtonElement>("button[data-print]")) {
7
+ button.hidden = false;
8
+ button.addEventListener("click", () => print());
9
+ }
10
+ }
11
+
12
+ if (typeof document !== "undefined") wirePrint(document, () => window.print());