@semics-tech/emdash-events 1.0.0-rc.3 → 1.0.0-rc.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +1 -1
  2. package/dist/index.mjs +6 -2
  3. package/dist/manifest.json +6 -5
  4. package/dist/plugin.mjs +7 -6
  5. package/dist/ts/astro/lib/call.d.ts +2 -0
  6. package/dist/ts/astro/lib/call.js +2 -0
  7. package/dist/ts/astro/lib/page.d.ts +44 -0
  8. package/dist/ts/astro/lib/page.js +123 -0
  9. package/dist/ts/integration/index.d.ts +15 -1
  10. package/dist/ts/integration/index.js +21 -1
  11. package/emdash-plugin.jsonc +8 -3
  12. package/package.json +6 -1
  13. package/src/astro/AttendeeList.astro +36 -15
  14. package/src/astro/BookingPage.astro +72 -10
  15. package/src/astro/BookingStatus.astro +209 -54
  16. package/src/astro/BookingWidget.astro +284 -59
  17. package/src/astro/CancelBooking.astro +80 -0
  18. package/src/astro/PageBrand.astro +18 -0
  19. package/src/astro/PageOrganiser.astro +22 -0
  20. package/src/astro/SetupPage.astro +88 -0
  21. package/src/astro/TicketPass.astro +131 -33
  22. package/src/astro/checkout-endpoint.ts +21 -3
  23. package/src/astro/lib/attendees.ts +76 -10
  24. package/src/astro/lib/book-link.ts +46 -0
  25. package/src/astro/lib/call.ts +4 -0
  26. package/src/astro/lib/checkout-form.ts +49 -1
  27. package/src/astro/lib/encryption.ts +67 -0
  28. package/src/astro/lib/list.ts +22 -0
  29. package/src/astro/lib/mapping.ts +106 -0
  30. package/src/astro/lib/page.ts +143 -0
  31. package/src/astro/lib/pass.ts +9 -0
  32. package/src/astro/lib/payment.ts +6 -10
  33. package/src/astro/lib/setup.ts +129 -0
  34. package/src/astro/lib/widget.ts +172 -7
  35. package/src/astro/virtual.d.ts +25 -1
  36. package/src/client/booking.ts +42 -6
  37. package/src/client/forget-form.ts +16 -0
  38. package/src/client/picker.ts +20 -9
  39. package/src/client/print.ts +12 -0
  40. package/src/i18n/ar.ts +55 -1
  41. package/src/i18n/en.ts +57 -1
@@ -0,0 +1,80 @@
1
+ ---
2
+ // <CancelBooking>: the quiet "Cancel booking" action at the foot of the booking page (T157). The button only
3
+ // opens a confirmation (a `<details>`, no JavaScript needed); the form posts `intent=cancel` back to the page.
4
+ import { around, pickLocale, translator } from "../i18n/index";
5
+ import { zonedAt } from "./lib/list";
6
+
7
+ interface Props {
8
+ /** Where the cancel form posts. */
9
+ action: string;
10
+ /** The last moment to cancel, when there is one. */
11
+ cancelBy?: string | undefined;
12
+ /** The event's zone, for `cancelBy`. */
13
+ zone?: string | null | undefined;
14
+ locale?: string;
15
+ }
16
+
17
+ const { action, cancelBy, zone } = Astro.props;
18
+ const locale = pickLocale(Astro.props.locale, Astro.currentLocale);
19
+ const { t, lang, dir } = translator(locale);
20
+ const [cancelBefore, cancelAfter] = around(t("booking.cancelUntil"), "time");
21
+ ---
22
+ <details class="semics-events semics-cancel" lang={lang} dir={dir} data-testid="booking-cancel">
23
+ <summary>{t("booking.cancel")}</summary>
24
+ <form method="post" action={action}>
25
+ <input type="hidden" name="intent" value="cancel" />
26
+ {cancelBy && (
27
+ <p>
28
+ {cancelBefore}<time datetime={cancelBy}>{zonedAt(cancelBy, zone, locale)}</time>{cancelAfter}
29
+ </p>
30
+ )}
31
+ <p>{t("booking.cancelConfirm")}</p>
32
+ <button type="submit">{t("booking.cancelYes")}</button>
33
+ </form>
34
+ </details>
35
+
36
+ <style>
37
+ .semics-cancel {
38
+ margin-block: 1.5rem 0;
39
+ color: var(--events-fg, #1a1a1a);
40
+ }
41
+ .semics-cancel summary {
42
+ display: inline-flex;
43
+ align-items: center;
44
+ min-block-size: 2.75rem;
45
+ color: var(--events-muted, #4a4a4a);
46
+ text-decoration: underline;
47
+ text-underline-offset: 0.2em;
48
+ cursor: pointer;
49
+ }
50
+ .semics-cancel form {
51
+ margin-block-start: 0.5rem;
52
+ padding: 1rem 1.25rem;
53
+ border: 1px solid var(--events-error, #b3261e);
54
+ border-radius: var(--events-radius, 6px);
55
+ background: var(--events-bg, #ffffff);
56
+ }
57
+ .semics-cancel p {
58
+ margin: 0 0 0.75rem;
59
+ }
60
+ .semics-cancel button {
61
+ font: inherit;
62
+ min-block-size: 2.75rem;
63
+ padding: 0.5rem 1.25rem;
64
+ border: 1px solid var(--events-error, #b3261e);
65
+ border-radius: var(--events-radius, 6px);
66
+ background: var(--events-bg, #ffffff);
67
+ color: var(--events-error, #b3261e);
68
+ font-weight: 600;
69
+ cursor: pointer;
70
+ }
71
+ .semics-cancel :focus-visible {
72
+ outline: 3px solid var(--events-accent, #0b57d0);
73
+ outline-offset: 2px;
74
+ }
75
+ @media print {
76
+ .semics-cancel {
77
+ display: none;
78
+ }
79
+ }
80
+ </style>
@@ -0,0 +1,18 @@
1
+ ---
2
+ // The site's name or logo at the top of the plugins' own pages (`/booking`, `/_events/waiver`), linking
3
+ // home: those pages run outside the site's layout (`eventsIntegration({ page: { brand } })`).
4
+ import type { PageBrand } from "./lib/page";
5
+
6
+ interface Props {
7
+ brand?: PageBrand | undefined;
8
+ }
9
+
10
+ const { brand } = Astro.props;
11
+ ---
12
+ {
13
+ brand && (
14
+ <header class="semics-page-brand">
15
+ <a href={brand.href ?? "/"}>{brand.logo ? <img src={brand.logo} alt={brand.name} /> : brand.name}</a>
16
+ </header>
17
+ )
18
+ }
@@ -0,0 +1,22 @@
1
+ ---
2
+ // The organiser at the foot of the plugins' own pages (T157): the site's name and, when the site gives one,
3
+ // its address (`page.brand.address`). It stays on a printed booking, where the brand bar is hidden.
4
+ import { pickLocale, translator } from "../i18n/index";
5
+ import type { PageBrand } from "./lib/page";
6
+
7
+ interface Props {
8
+ brand?: PageBrand | undefined;
9
+ locale?: string;
10
+ }
11
+
12
+ const { brand } = Astro.props;
13
+ const { t } = translator(pickLocale(Astro.props.locale, Astro.currentLocale));
14
+ ---
15
+ {
16
+ brand && (
17
+ <footer class="semics-page-organiser" data-testid="page-organiser">
18
+ <p>{t("booking.organiser", { name: brand.name })}</p>
19
+ {brand.address && <address>{brand.address}</address>}
20
+ </footer>
21
+ )
22
+ }
@@ -0,0 +1,88 @@
1
+ ---
2
+ // i18n-ignore-file: administrators only, in English like the admin it moved from (T178).
3
+ // Injected at `/_events/setup` by the integration (T178): the Events setup check, moved off the admin's
4
+ // "Events setup" page so the sandboxed backend does not carry it. Administrators only: the host's own
5
+ // plugin-settings read checks `plugins:manage` on this visitor. It shows the field mapping, whether the
6
+ // mapped collection and fields exist, whether saved secrets can be decrypted, and whether Turnstile is set.
7
+ // No secret value is ever on the page: only notices built from readable / unreadable / unset.
8
+ // The logic is in `lib/setup.ts`; this page only renders it. Admin-only and in English, like the admin.
9
+ import { pluginId } from "virtual:semics-events/config";
10
+ import { getPluginSetting } from "emdash";
11
+ import { GET as readSettings } from "emdash/internal/routes/api/admin/plugins/_id_/settings";
12
+ import { GET as readSchema } from "emdash/internal/routes/api/schema/index";
13
+
14
+ import { type SetupView, setupCheck } from "./lib/setup";
15
+
16
+ export const prerender = false;
17
+
18
+ Astro.response.headers.set("Referrer-Policy", "no-referrer");
19
+ Astro.response.headers.set("Cache-Control", "private, no-store");
20
+
21
+ const hostUrl = (path: string) => new URL(path, Astro.url);
22
+ const settingsPath = `/_emdash/api/admin/plugins/${encodeURIComponent(pluginId)}/settings`;
23
+ const view: SetupView = await setupCheck({
24
+ locals: Astro.locals,
25
+ readSettings: () =>
26
+ readSettings({
27
+ params: { id: pluginId },
28
+ locals: Astro.locals,
29
+ request: new Request(hostUrl(settingsPath)),
30
+ } as never) as Promise<Response>,
31
+ readSchema: () =>
32
+ readSchema({ locals: Astro.locals, request: new Request(hostUrl("/_emdash/api/schema")) } as never) as Promise<Response>,
33
+ // Decrypted on the server and reduced to readable / unreadable in `lib/setup.ts`; never rendered.
34
+ readSecret: (key) => getPluginSetting(pluginId, key),
35
+ });
36
+ if (view.state === "forbidden") Astro.response.status = 403;
37
+ if (view.state === "error") Astro.response.status = 500;
38
+ const settingsHref = `/_emdash/admin/plugins-manager/${encodeURIComponent(pluginId)}/settings`;
39
+ const signIn = "/_emdash/admin";
40
+ // The page's words are English whatever the site's locale, so it says so (not the site's language).
41
+ const lang = "en";
42
+ const dir = "ltr";
43
+ ---
44
+ <!doctype html>
45
+ <html lang={lang} dir={dir}>
46
+ <head>
47
+ <meta charset="utf-8" />
48
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
49
+ <meta name="robots" content="noindex" />
50
+ <meta name="referrer" content="no-referrer" />
51
+ <title>Events setup</title>
52
+ </head>
53
+ <body>
54
+ <main class="semics-events semics-setup" data-testid="setup-page" data-state={view.state}>
55
+ <h1>Events setup</h1>
56
+ {view.state === "forbidden" && (
57
+ <p data-testid="setup-forbidden">
58
+ Sign in to the admin as an administrator, then open this page again. <a href={signIn}>Sign in</a>
59
+ </p>
60
+ )}
61
+ {view.state === "error" && (
62
+ <p role="alert" data-testid="setup-error">The setup check could not read the site's settings. Reload the page to try again.</p>
63
+ )}
64
+ {view.state === "ok" && (
65
+ <>
66
+ {view.notices.length === 0 && <p role="status" data-testid="setup-ok">The field mapping, saved secrets and Turnstile are all set up.</p>}
67
+ {view.notices.map((n) => (
68
+ <div role={n.severity === "error" ? "alert" : "status"} class={`semics-setup-notice semics-setup-${n.severity}`} data-testid="setup-notice">
69
+ <strong>{n.title}</strong>
70
+ <p>{n.message}</p>
71
+ </div>
72
+ ))}
73
+ <table data-testid="setup-fields">
74
+ <tbody>
75
+ {view.fields.map((f) => (
76
+ <tr>
77
+ <th scope="row">{f.label}</th>
78
+ <td>{f.value}</td>
79
+ </tr>
80
+ ))}
81
+ </tbody>
82
+ </table>
83
+ </>
84
+ )}
85
+ <p><a href={settingsHref}>Open plugin settings</a></p>
86
+ </main>
87
+ </body>
88
+ </html>
@@ -1,10 +1,12 @@
1
1
  ---
2
- // <TicketPass>: one attendee's ticket with the check-in code as text (EU-FR-07). With Events Pro the
3
- // core also sends the code's QR matrix (`qr`, T082), drawn here as an SVG for the door's camera; the
4
- // text code stays for typing it in. The code is grouped in fours for reading aloud; screen readers
5
- // get it character by character.
2
+ // <TicketPass>: one attendee's ticket with the check-in code (EU-FR-07). With Events Pro the core also sends the
3
+ // code's QR matrix (`qr`, T082), drawn here as an SVG for the door's camera. The code is the core's 43-character
4
+ // value, which door check-in matches exactly, so it is never shortened, only shown smaller (T158): with a QR the face
5
+ // of the pass shows none (the QR carries it) and "Show the code to type in" reveals it on screen, and a printed pass
6
+ // carries it on one small line under the QR; without a QR (Free) it is the way in and shows in full. The code is
7
+ // grouped in fours by spacing (the text stays the exact value); screen readers get it character by character.
6
8
  import { pickLocale, translator } from "../i18n/index";
7
- import { qrPath } from "./lib/pass";
9
+ import { codeGroups, qrPath } from "./lib/pass";
8
10
 
9
11
  interface Props {
10
12
  name: string;
@@ -22,38 +24,63 @@ const { t, lang, dir } = translator(pickLocale(Astro.props.locale, Astro.current
22
24
  const statusText =
23
25
  status === "pending" ? t("pass.status.pending") : status === "cancelled" ? t("pass.status.cancelled") : status;
24
26
  const spoken = code.replace(/[^A-Za-z0-9]/g, "").split("").join(" ");
27
+ const groups = codeGroups(code);
25
28
  const matrix = qrPath(qr);
26
29
  const box = matrix ? matrix.size + 8 : 0;
27
30
  ---
28
- <article class="semics-events semics-ticket-pass" lang={lang} dir={dir} data-testid="ticket-pass" data-status={status}>
29
- {event && <p class="semics-pass-event">{event}</p>}
30
- <h3 class="semics-pass-name">{name}</h3>
31
- {ticket && <p class="semics-pass-ticket">{ticket}</p>}
31
+ <article class="semics-events semics-ticket-pass" lang={lang} dir={dir} data-testid="ticket-pass" data-status={status} data-qr={matrix ? "" : undefined}>
32
32
  {matrix && (
33
- <svg
34
- class="semics-pass-qr"
35
- data-testid="ticket-qr"
36
- role="img"
37
- aria-label={t("pass.qr")}
38
- viewBox={`-4 -4 ${box} ${box}`}
39
- shape-rendering="crispEdges"
40
- >
41
- <rect x="-4" y="-4" width={box} height={box} fill="#ffffff" />
42
- <path d={matrix.d} fill="#000000" />
43
- </svg>
33
+ <div class="semics-pass-qr-box">
34
+ <svg
35
+ class="semics-pass-qr"
36
+ data-testid="ticket-qr"
37
+ role="img"
38
+ aria-label={t("pass.qr")}
39
+ viewBox={`-4 -4 ${box} ${box}`}
40
+ shape-rendering="crispEdges"
41
+ >
42
+ <rect x="-4" y="-4" width={box} height={box} fill="#ffffff" />
43
+ <path d={matrix.d} fill="#000000" />
44
+ </svg>
45
+ <p class="semics-pass-code-print" aria-hidden="true" data-testid="ticket-code-print">{groups.map((g) => <span>{g}</span>)}</p>
46
+ </div>
47
+ )}
48
+ <div class="semics-pass-text">
49
+ {event && <p class="semics-pass-event">{event}</p>}
50
+ <h3 class="semics-pass-name">{name}</h3>
51
+ {ticket && <p class="semics-pass-ticket">{ticket}</p>}
52
+ {!matrix && (
53
+ <>
54
+ <p class="semics-pass-code-label">{t("pass.code")}</p>
55
+ <p class="semics-pass-code">
56
+ <span aria-hidden="true" data-testid="ticket-code">{groups.map((g) => <span>{g}</span>)}</span>
57
+ <span class="semics-visually-hidden">{spoken}</span>
58
+ </p>
59
+ </>
60
+ )}
61
+ {status && status !== "valid" && <p class="semics-pass-status">{statusText}</p>}
62
+ </div>
63
+ {matrix && (
64
+ <details class="semics-pass-more">
65
+ <summary>{t("pass.codeShow")}</summary>
66
+ <p class="semics-pass-code">
67
+ <span aria-hidden="true" data-testid="ticket-code">{groups.map((g) => <span>{g}</span>)}</span>
68
+ <span class="semics-visually-hidden">{spoken}</span>
69
+ </p>
70
+ </details>
44
71
  )}
45
- <p class="semics-pass-code-label">{t("pass.code")}</p>
46
- <p class="semics-pass-code">
47
- <span aria-hidden="true" data-testid="ticket-code">{code}</span>
48
- <span class="semics-visually-hidden">{spoken}</span>
49
- </p>
50
- {status && status !== "valid" && <p class="semics-pass-status">{statusText}</p>}
51
72
  </article>
52
73
 
53
74
  <style>
75
+ /* The QR beside the attendee and the code (T157); stacked on a narrow screen. */
54
76
  .semics-ticket-pass {
55
77
  box-sizing: border-box;
56
- max-inline-size: 24rem;
78
+ display: flex;
79
+ flex-wrap: wrap;
80
+ align-items: center;
81
+ gap: 0.75rem 1.25rem;
82
+ max-inline-size: 32rem;
83
+ margin-block: 0 0.75rem;
57
84
  padding: 1rem;
58
85
  border: 2px dashed var(--events-border, #6b6b6b);
59
86
  border-radius: var(--events-radius, 6px);
@@ -61,6 +88,10 @@ const box = matrix ? matrix.size + 8 : 0;
61
88
  color: var(--events-fg, #1a1a1a);
62
89
  overflow-wrap: anywhere;
63
90
  }
91
+ .semics-pass-text {
92
+ flex: 1 1 12rem;
93
+ min-inline-size: 0;
94
+ }
64
95
  .semics-ticket-pass p,
65
96
  .semics-ticket-pass h3 {
66
97
  margin: 0 0 0.25rem;
@@ -70,19 +101,58 @@ const box = matrix ? matrix.size + 8 : 0;
70
101
  .semics-pass-code-label {
71
102
  color: var(--events-muted, #4a4a4a);
72
103
  }
104
+ .semics-pass-code-label {
105
+ font-size: 0.875rem;
106
+ }
107
+ .semics-pass-qr-box {
108
+ flex: none;
109
+ inline-size: min(100%, 10rem);
110
+ }
73
111
  /* Black on white in every theme: phone cameras read dark modules on a light ground. */
74
112
  .semics-pass-qr {
75
113
  display: block;
76
- inline-size: min(100%, 14rem);
114
+ inline-size: 100%;
77
115
  block-size: auto;
78
116
  aspect-ratio: 1;
79
- margin: 0.5rem 0;
80
117
  }
81
- .semics-pass-code {
118
+ /* Groups of four, spaced rather than separated, so the text is the exact code; a line breaks only between groups. */
119
+ .semics-pass-code,
120
+ .semics-pass-code-print {
82
121
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
83
- font-size: 1.75rem;
84
- letter-spacing: 0.1em;
85
- font-weight: 700;
122
+ overflow-wrap: normal;
123
+ }
124
+ .semics-pass-code {
125
+ font-size: 0.875rem;
126
+ line-height: 1.5;
127
+ letter-spacing: 0.02em;
128
+ font-weight: 600;
129
+ }
130
+ .semics-pass-code > [data-testid] {
131
+ display: block;
132
+ }
133
+ .semics-pass-code > [data-testid] > span,
134
+ .semics-pass-code-print > span {
135
+ display: inline-block;
136
+ margin-inline-end: 0.35em;
137
+ }
138
+ /* Without a QR the code is what the door types in: a little larger. */
139
+ .semics-ticket-pass:not([data-qr]) .semics-pass-code {
140
+ font-size: 0.9375rem;
141
+ }
142
+ /* The pass's full width, under the QR and the name, so the code fits one line on a desktop. */
143
+ .semics-pass-more {
144
+ flex: 1 1 100%;
145
+ }
146
+ .semics-pass-more summary {
147
+ color: var(--events-accent, #0b57d0);
148
+ font-size: 0.875rem;
149
+ cursor: pointer;
150
+ }
151
+ .semics-pass-more .semics-pass-code {
152
+ margin-block: 0.375rem 0;
153
+ }
154
+ .semics-pass-code-print {
155
+ display: none;
86
156
  }
87
157
  .semics-visually-hidden {
88
158
  position: absolute;
@@ -92,4 +162,32 @@ const box = matrix ? matrix.size + 8 : 0;
92
162
  clip-path: inset(50%);
93
163
  white-space: nowrap;
94
164
  }
165
+ @media print {
166
+ .semics-ticket-pass {
167
+ break-inside: avoid;
168
+ border-color: #000000;
169
+ color: #000000;
170
+ }
171
+ .semics-pass-qr-box {
172
+ inline-size: auto;
173
+ }
174
+ .semics-pass-qr {
175
+ inline-size: 35mm;
176
+ }
177
+ /* The QR's fallback for the door: the full code, one small line under it. */
178
+ .semics-pass-code-print {
179
+ display: block;
180
+ margin: 1.5mm 0 0;
181
+ font-size: 6.5pt;
182
+ line-height: 1.3;
183
+ white-space: nowrap;
184
+ }
185
+ .semics-pass-code-print > span {
186
+ margin-inline-end: 0.25em;
187
+ }
188
+ .semics-ticket-pass:not([data-qr]) .semics-pass-code {
189
+ font-size: 9pt;
190
+ white-space: nowrap;
191
+ }
192
+ }
95
193
  </style>
@@ -1,11 +1,29 @@
1
1
  // Injected at `/_events/checkout` by the integration. A plain form post (no JavaScript needed).
2
2
  // Cross-site posts get a 403 before anything runs (`isCrossSiteRequest`, T057).
3
- import { pluginId } from "virtual:semics-events/config";
3
+ // With `eventsIntegration({ vouchers })` a typed gift voucher code is held through the suite's hook (T166).
4
+ import * as config from "virtual:semics-events/config";
4
5
 
5
- import { type CheckoutEndpointContext, handleCheckoutRequest } from "./lib/checkout-form";
6
+ import {
7
+ type CheckoutEndpointContext,
8
+ handleCheckoutRequest,
9
+ type VoucherCheckHook,
10
+ type VoucherHook,
11
+ } from "./lib/checkout-form";
6
12
 
7
13
  export const prerender = false;
8
14
 
15
+ const { pluginId, vouchersPluginId, holdVoucher, checkVoucher } = config as Partial<typeof config> & {
16
+ pluginId: string;
17
+ };
18
+ const voucher: VoucherHook | undefined =
19
+ holdVoucher && vouchersPluginId
20
+ ? (ctx, input) => holdVoucher(ctx, input, { eventsPluginId: pluginId, vouchersPluginId })
21
+ : undefined;
22
+
23
+ // T168: the code is checked before reserving, so a refused one leaves no booking (and no "cancelled" email).
24
+ const check: VoucherCheckHook | undefined =
25
+ checkVoucher && vouchersPluginId ? (ctx, input) => checkVoucher(ctx, input, { vouchersPluginId }) : undefined;
26
+
9
27
  export function POST(ctx: CheckoutEndpointContext): Promise<Response> {
10
- return handleCheckoutRequest(ctx, { pluginId });
28
+ return handleCheckoutRequest(ctx, { pluginId, ...(voucher ? { voucher } : {}), ...(check ? { check } : {}) });
11
29
  }
@@ -17,6 +17,10 @@
17
17
  * mints, per changed seat, a `replace` intent (e-sign voids the old envelope) and, for an emailed
18
18
  * adult, the new invitation's intent, redeemed in that order.
19
19
  *
20
+ * A booking request (T174e) is booked without names: once confirmed, a seat still in the buyer's name signs by
21
+ * `none` (no Sign now, the row asks for a name and email), and the edit form may mark a seat under 18
22
+ * (`signingList.minors`).
23
+ *
20
24
  * Every outcome is a redirect to `/booking?ref=` with a code, never a typed value. Web APIs only (R35).
21
25
  */
22
26
  import { callPublicRoute, type PublicRouteContext } from "./call";
@@ -31,8 +35,8 @@ export interface SigningAttendee {
31
35
  email?: string;
32
36
  minor?: boolean;
33
37
  signing?: "signed" | "waiting";
34
- /** `email`: an adult e-sign invites by email; `inline`: signed on the buyer's device. */
35
- signs?: "inline" | "email";
38
+ /** `email`: an adult e-sign invites by email; `inline`: signed on the buyer's device; `none`: not named yet (T174e). */
39
+ signs?: "inline" | "email" | "none";
36
40
  }
37
41
 
38
42
  export interface SigningRow {
@@ -41,6 +45,8 @@ export interface SigningRow {
41
45
  email: string;
42
46
  minor: boolean;
43
47
  signed: boolean;
48
+ /** A booking request's seat not named yet (T174e). */
49
+ unnamed?: boolean;
44
50
  canSign: boolean;
45
51
  canResend: boolean;
46
52
  canEdit: boolean;
@@ -50,16 +56,36 @@ export interface AttendeeEdit {
50
56
  seat: string;
51
57
  name: string;
52
58
  email?: string;
59
+ minor?: boolean;
53
60
  }
54
61
 
55
- /** Statuses in which a waiver can still be signed: the hold's, and a confirmed booking's pending seats. */
56
- const OPEN = ["awaiting_signature", "awaiting_payment", "confirmed"];
62
+ /** Statuses in which a waiver can still be signed: the holds', and a confirmed booking's pending seats. */
63
+ const OPEN = ["awaiting_signature", "awaiting_payment", "awaiting_approval", "confirmed"];
57
64
  const SEAT = /^[0-9]{1,3}$/;
58
65
  const CODE = /^[A-Z_]{1,40}$/;
59
66
  const MAX_TEXT = 254;
60
67
  /** Issue codes of a refused save the page explains itself; any other issue is an invalid entry. */
61
68
  const ISSUE_CODES = ["ATTENDEE_SIGNED", "WAIVER_EMAIL_REQUIRED", "WAIVER_TOO_MANY_EMAILS", "RATE_LIMITED"];
62
69
 
70
+ /** Where the after-payment waiver step shows (T160): a paid booking confirmed, or waiting for the organiser. */
71
+ const AFTER_PAYMENT = ["confirmed", "awaiting_approval"];
72
+
73
+ /**
74
+ * The booking page's signing step for a waiver that comes after payment (Events Pro's `waiverAfter`, T160): `sign`
75
+ * when a seat signed on this device (the buyer, or a minor with the buyer as guardian) still waits, `invite` when an
76
+ * emailed adult does. Null for any other booking, so nothing changes for a waiver signed before payment.
77
+ */
78
+ export function waiverStep(booking: BookingView): { sign: boolean; invite: boolean } | null {
79
+ if (booking.waiverAfter !== true || !AFTER_PAYMENT.includes(booking.status)) return null;
80
+ const rows = signingRows(booking);
81
+ const waiting = (booking.attendees as SigningAttendee[]).filter(
82
+ (a) => a.signing === "waiting" && rows?.some((r) => r.seat === a.seat),
83
+ );
84
+ const sign = waiting.some((a) => a.signs !== "email" && a.signs !== "none");
85
+ const invite = waiting.some((a) => a.signs === "email");
86
+ return sign || invite ? { sign, invite } : null;
87
+ }
88
+
63
89
  /** The list's rows, or null when the answer has no signing list (Free, or not a waiver booking). */
64
90
  export function signingRows(booking: BookingView): SigningRow[] | null {
65
91
  const list = booking.signingList;
@@ -76,7 +102,8 @@ export function signingRows(booking: BookingView): SigningRow[] | null {
76
102
  email: a.email ?? "",
77
103
  minor: a.minor === true,
78
104
  signed,
79
- canSign: waiting,
105
+ unnamed: waiting && a.signs === "none",
106
+ canSign: waiting && a.signs !== "none",
80
107
  canResend: waiting && a.signs === "email",
81
108
  canEdit: waiting && list.editable === true,
82
109
  });
@@ -89,12 +116,21 @@ const text = (form: FormData, key: string): string | undefined => {
89
116
  return typeof value === "string" ? value.trim().slice(0, MAX_TEXT) : undefined;
90
117
  };
91
118
 
92
- /** The edit form's values for the editable seats (`name:<seat>`, `email:<seat>`); a minor has no email. */
93
- export function readAttendeeEdits(form: FormData, rows: readonly SigningRow[]): AttendeeEdit[] {
119
+ /**
120
+ * The edit form's values for the editable seats (`name:<seat>`, `email:<seat>`); a minor has no email. With `minors`
121
+ * (a booking request, T174e) each seat also says whether it is under 18 (`minor:<seat>`).
122
+ */
123
+ export function readAttendeeEdits(form: FormData, rows: readonly SigningRow[], minors = false): AttendeeEdit[] {
94
124
  return rows
95
125
  .filter((r) => r.canEdit)
96
126
  .map((r) => {
97
127
  const name = text(form, `name:${r.seat}`) ?? r.name;
128
+ if (minors) {
129
+ const minor = form.get(`minor:${r.seat}`) === "on";
130
+ return minor
131
+ ? { seat: r.seat, name, minor }
132
+ : { seat: r.seat, name, email: text(form, `email:${r.seat}`) ?? r.email, minor };
133
+ }
98
134
  if (r.minor) return { seat: r.seat, name };
99
135
  return { seat: r.seat, name, email: text(form, `email:${r.seat}`) ?? r.email };
100
136
  });
@@ -112,7 +148,7 @@ function back(ref: string, key: "error" | "attendees", value: string): { locatio
112
148
  interface Minted {
113
149
  intent?: unknown;
114
150
  lookup?: unknown;
115
- intents?: Array<{ token?: unknown }>;
151
+ intents?: Array<{ token?: unknown; delivery?: unknown }>;
116
152
  }
117
153
 
118
154
  /**
@@ -127,14 +163,16 @@ export async function handleAttendeeAction(
127
163
  booking: BookingView,
128
164
  ): Promise<{ location: string } | null> {
129
165
  const intent = form.get("intent");
130
- if (intent !== "sign-now" && intent !== "resend" && intent !== "attendees") return null;
166
+ if (intent !== "sign-now" && intent !== "resend" && intent !== "attendees" && intent !== "sign-waiver") return null;
131
167
  const { ref } = access;
132
168
  if (!options.esignPluginId) return back(ref, "error", "ESIGN_NOT_CONFIGURED");
133
169
  const rows = signingRows(booking) ?? [];
134
170
  const auth = { bookingRef: ref, accessToken: access.token };
135
171
 
172
+ if (intent === "sign-waiver") return signWaiver(ctx, auth, options, booking);
173
+
136
174
  if (intent === "attendees") {
137
- const attendees = readAttendeeEdits(form, rows);
175
+ const attendees = readAttendeeEdits(form, rows, booking.signingList?.minors === true);
138
176
  if (attendees.length === 0) return back(ref, "error", "ATTENDEES_LOCKED");
139
177
  const saved = await post<Minted>(ctx, options.pluginId, "public/booking/attendees", { ...auth, attendees });
140
178
  if (!saved.ok) {
@@ -168,3 +206,31 @@ export async function handleAttendeeAction(
168
206
  if ("signed" in started) return { location: `${BOOKING_PATH}?ref=${ref}&waiver=signed` };
169
207
  return back(ref, "error", started.error);
170
208
  }
209
+
210
+ /**
211
+ * "Sign the waiver" after payment (T160): Events Pro's `public/booking/attendees/sign` with no seat mints an intent for every seat not
212
+ * signed. The emailed adults' are redeemed first (e-sign invites each once: a second press finds the envelope and
213
+ * sends nothing), then the first seat signed on this device opens e-sign's signing page; the next press signs the next.
214
+ */
215
+ async function signWaiver(
216
+ ctx: PublicRouteContext,
217
+ auth: { bookingRef: string; accessToken: string },
218
+ options: ReceiptOptions,
219
+ booking: BookingView,
220
+ ): Promise<{ location: string }> {
221
+ const ref = auth.bookingRef;
222
+ if (!waiverStep(booking) || !options.esignPluginId) return back(ref, "error", "BAD_REQUEST");
223
+ const minted = await post<Minted>(ctx, options.pluginId, "public/booking/attendees/sign", auth);
224
+ if (!minted.ok) return back(ref, "error", minted.error.code);
225
+ const intents = minted.data.intents ?? [];
226
+ for (const email of intents.filter((i) => i.delivery === "email")) {
227
+ const sent = await post(ctx, options.esignPluginId, "public/envelopes/from-intent", { intent: email.token });
228
+ if (!sent.ok) return back(ref, "error", "ATTENDEES_UNSENT");
229
+ }
230
+ const inline = intents.find((i) => i.delivery !== "email");
231
+ if (!inline) return back(ref, "attendees", "invited");
232
+ const started = await startDoorSigning(ctx, inline.token, options);
233
+ if ("location" in started) return started;
234
+ if ("signed" in started) return { location: `${BOOKING_PATH}?ref=${ref}&waiver=signed` };
235
+ return back(ref, "error", started.error);
236
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * "Book with this voucher" (T171): what the booking forms need to take a buyer straight from a gift voucher to a
3
+ * booking. voucher/1 §8 keeps a code out of every URL but the voucher page's own, so the suite's voucher page
4
+ * (`/_vouchers/v?c=…&book=1`) puts the code in this short-lived HttpOnly cookie and redirects here; the form
5
+ * fills its Gift voucher field from it on the server (no JavaScript). `?ticketType=` chooses a ticket type, and
6
+ * `#book-<event>` lands on the form. Site-side only: nothing here reaches the sandboxed core.
7
+ */
8
+
9
+ export const VOUCHER_COOKIE = "semics_voucher";
10
+ export const VOUCHER_COOKIE_SECONDS = 30 * 60;
11
+ export const TICKET_TYPE_PARAM = "ticketType";
12
+
13
+ /** A code in its display form, `XXXX-XXXX-XXXX-XXXX` (voucher/1 §7). */
14
+ const DISPLAY_CODE = /^[0-9A-HJKMNP-TV-Z]{4}(?:-[0-9A-HJKMNP-TV-Z]{4}){3}$/;
15
+
16
+ /** The voucher cookie: HttpOnly, the whole site (the form can be on any page), 30 minutes. */
17
+ export function voucherCookieOptions(url: URL) {
18
+ return {
19
+ path: "/",
20
+ httpOnly: true,
21
+ sameSite: "lax" as const,
22
+ secure: url.protocol === "https:",
23
+ maxAge: VOUCHER_COOKIE_SECONDS,
24
+ };
25
+ }
26
+
27
+ /** The code to fill in from the cookie, or "" (none, malformed, or a prerendered page with no cookies). */
28
+ export function presetVoucher(cookies: { get(name: string): { value: string } | undefined } | undefined): string {
29
+ try {
30
+ const value = cookies?.get(VOUCHER_COOKIE)?.value ?? "";
31
+ return DISPLAY_CODE.test(value) ? value : "";
32
+ } catch {
33
+ return "";
34
+ }
35
+ }
36
+
37
+ /** `?ticketType=` when the form offers that type. */
38
+ export function presetTicketType(url: URL, offered: readonly string[]): string | undefined {
39
+ const id = url.searchParams.get(TICKET_TYPE_PARAM);
40
+ return id && offered.includes(id) ? id : undefined;
41
+ }
42
+
43
+ /** The booking form's anchor, the same for `<BookingWidget>` and the suite's `<BookingWithWaiver>`. */
44
+ export function bookAnchor(eventId: string): string {
45
+ return `book-${eventId.replace(/[^A-Za-z0-9_-]/g, "_")}`;
46
+ }