@semics-tech/emdash-events 1.0.0-rc.2 → 1.0.0-rc.20
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/README.md +1 -1
- package/dist/index.mjs +6 -1
- package/dist/manifest.json +6 -1
- package/dist/plugin.mjs +7 -6
- package/dist/ts/astro/lib/call.d.ts +2 -0
- package/dist/ts/astro/lib/call.js +2 -0
- package/dist/ts/astro/lib/page.d.ts +44 -0
- package/dist/ts/astro/lib/page.js +123 -0
- package/dist/ts/integration/index.d.ts +13 -0
- package/dist/ts/integration/index.js +13 -0
- package/emdash-plugin.jsonc +5 -0
- package/package.json +6 -2
- package/src/astro/AttendeeList.astro +9 -12
- package/src/astro/BookingPage.astro +71 -10
- package/src/astro/BookingStatus.astro +204 -53
- package/src/astro/BookingWidget.astro +226 -52
- package/src/astro/CancelBooking.astro +80 -0
- package/src/astro/PageBrand.astro +18 -0
- package/src/astro/PageOrganiser.astro +22 -0
- package/src/astro/TicketPass.astro +131 -33
- package/src/astro/checkout-endpoint.ts +21 -3
- package/src/astro/lib/attendees.ts +52 -4
- package/src/astro/lib/book-link.ts +46 -0
- package/src/astro/lib/call.ts +4 -0
- package/src/astro/lib/checkout-form.ts +49 -1
- package/src/astro/lib/list.ts +22 -0
- package/src/astro/lib/page.ts +143 -0
- package/src/astro/lib/pass.ts +9 -0
- package/src/astro/lib/payment.ts +6 -10
- package/src/astro/lib/widget.ts +113 -5
- package/src/astro/virtual.d.ts +25 -1
- package/src/client/forget-form.ts +16 -0
- package/src/client/picker.ts +20 -9
- package/src/client/print.ts +12 -0
- package/src/i18n/ar.ts +46 -1
- package/src/i18n/en.ts +47 -1
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
---
|
|
2
|
-
// <TicketPass>: one attendee's ticket with the check-in code
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
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
|
-
<
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
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:
|
|
114
|
+
inline-size: 100%;
|
|
77
115
|
block-size: auto;
|
|
78
116
|
aspect-ratio: 1;
|
|
79
|
-
margin: 0.5rem 0;
|
|
80
117
|
}
|
|
81
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
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 {
|
|
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
|
}
|
|
@@ -52,14 +52,32 @@ export interface AttendeeEdit {
|
|
|
52
52
|
email?: string;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
/** Statuses in which a waiver can still be signed: the
|
|
56
|
-
const OPEN = ["awaiting_signature", "awaiting_payment", "confirmed"];
|
|
55
|
+
/** Statuses in which a waiver can still be signed: the holds', and a confirmed booking's pending seats. */
|
|
56
|
+
const OPEN = ["awaiting_signature", "awaiting_payment", "awaiting_approval", "confirmed"];
|
|
57
57
|
const SEAT = /^[0-9]{1,3}$/;
|
|
58
58
|
const CODE = /^[A-Z_]{1,40}$/;
|
|
59
59
|
const MAX_TEXT = 254;
|
|
60
60
|
/** Issue codes of a refused save the page explains itself; any other issue is an invalid entry. */
|
|
61
61
|
const ISSUE_CODES = ["ATTENDEE_SIGNED", "WAIVER_EMAIL_REQUIRED", "WAIVER_TOO_MANY_EMAILS", "RATE_LIMITED"];
|
|
62
62
|
|
|
63
|
+
/** Where the after-payment waiver step shows (T160): a paid booking confirmed, or waiting for the organiser. */
|
|
64
|
+
const AFTER_PAYMENT = ["confirmed", "awaiting_approval"];
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The booking page's signing step for a waiver that comes after payment (Events Pro's `waiverAfter`, T160): `sign`
|
|
68
|
+
* when a seat signed on this device (the buyer, or a minor with the buyer as guardian) still waits, `invite` when an
|
|
69
|
+
* emailed adult does. Null for any other booking, so nothing changes for a waiver signed before payment.
|
|
70
|
+
*/
|
|
71
|
+
export function waiverStep(booking: BookingView): { sign: boolean; invite: boolean } | null {
|
|
72
|
+
if (booking.waiverAfter !== true || !AFTER_PAYMENT.includes(booking.status)) return null;
|
|
73
|
+
const rows = signingRows(booking);
|
|
74
|
+
const waiting = (booking.attendees as SigningAttendee[]).filter(
|
|
75
|
+
(a) => a.signing === "waiting" && rows?.some((r) => r.seat === a.seat),
|
|
76
|
+
);
|
|
77
|
+
if (waiting.length === 0) return null;
|
|
78
|
+
return { sign: waiting.some((a) => a.signs !== "email"), invite: waiting.some((a) => a.signs === "email") };
|
|
79
|
+
}
|
|
80
|
+
|
|
63
81
|
/** The list's rows, or null when the answer has no signing list (Free, or not a waiver booking). */
|
|
64
82
|
export function signingRows(booking: BookingView): SigningRow[] | null {
|
|
65
83
|
const list = booking.signingList;
|
|
@@ -112,7 +130,7 @@ function back(ref: string, key: "error" | "attendees", value: string): { locatio
|
|
|
112
130
|
interface Minted {
|
|
113
131
|
intent?: unknown;
|
|
114
132
|
lookup?: unknown;
|
|
115
|
-
intents?: Array<{ token?: unknown }>;
|
|
133
|
+
intents?: Array<{ token?: unknown; delivery?: unknown }>;
|
|
116
134
|
}
|
|
117
135
|
|
|
118
136
|
/**
|
|
@@ -127,12 +145,14 @@ export async function handleAttendeeAction(
|
|
|
127
145
|
booking: BookingView,
|
|
128
146
|
): Promise<{ location: string } | null> {
|
|
129
147
|
const intent = form.get("intent");
|
|
130
|
-
if (intent !== "sign-now" && intent !== "resend" && intent !== "attendees") return null;
|
|
148
|
+
if (intent !== "sign-now" && intent !== "resend" && intent !== "attendees" && intent !== "sign-waiver") return null;
|
|
131
149
|
const { ref } = access;
|
|
132
150
|
if (!options.esignPluginId) return back(ref, "error", "ESIGN_NOT_CONFIGURED");
|
|
133
151
|
const rows = signingRows(booking) ?? [];
|
|
134
152
|
const auth = { bookingRef: ref, accessToken: access.token };
|
|
135
153
|
|
|
154
|
+
if (intent === "sign-waiver") return signWaiver(ctx, auth, options, booking);
|
|
155
|
+
|
|
136
156
|
if (intent === "attendees") {
|
|
137
157
|
const attendees = readAttendeeEdits(form, rows);
|
|
138
158
|
if (attendees.length === 0) return back(ref, "error", "ATTENDEES_LOCKED");
|
|
@@ -168,3 +188,31 @@ export async function handleAttendeeAction(
|
|
|
168
188
|
if ("signed" in started) return { location: `${BOOKING_PATH}?ref=${ref}&waiver=signed` };
|
|
169
189
|
return back(ref, "error", started.error);
|
|
170
190
|
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* "Sign the waiver" after payment (T160): Events Pro's `public/booking/attendees/sign` with no seat mints an intent for every seat not
|
|
194
|
+
* signed. The emailed adults' are redeemed first (e-sign invites each once: a second press finds the envelope and
|
|
195
|
+
* sends nothing), then the first seat signed on this device opens e-sign's signing page; the next press signs the next.
|
|
196
|
+
*/
|
|
197
|
+
async function signWaiver(
|
|
198
|
+
ctx: PublicRouteContext,
|
|
199
|
+
auth: { bookingRef: string; accessToken: string },
|
|
200
|
+
options: ReceiptOptions,
|
|
201
|
+
booking: BookingView,
|
|
202
|
+
): Promise<{ location: string }> {
|
|
203
|
+
const ref = auth.bookingRef;
|
|
204
|
+
if (!waiverStep(booking) || !options.esignPluginId) return back(ref, "error", "BAD_REQUEST");
|
|
205
|
+
const minted = await post<Minted>(ctx, options.pluginId, "public/booking/attendees/sign", auth);
|
|
206
|
+
if (!minted.ok) return back(ref, "error", minted.error.code);
|
|
207
|
+
const intents = minted.data.intents ?? [];
|
|
208
|
+
for (const email of intents.filter((i) => i.delivery === "email")) {
|
|
209
|
+
const sent = await post(ctx, options.esignPluginId, "public/envelopes/from-intent", { intent: email.token });
|
|
210
|
+
if (!sent.ok) return back(ref, "error", "ATTENDEES_UNSENT");
|
|
211
|
+
}
|
|
212
|
+
const inline = intents.find((i) => i.delivery !== "email");
|
|
213
|
+
if (!inline) return back(ref, "attendees", "invited");
|
|
214
|
+
const started = await startDoorSigning(ctx, inline.token, options);
|
|
215
|
+
if ("location" in started) return started;
|
|
216
|
+
if ("signed" in started) return { location: `${BOOKING_PATH}?ref=${ref}&waiver=signed` };
|
|
217
|
+
return back(ref, "error", started.error);
|
|
218
|
+
}
|
|
@@ -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
|
+
}
|
package/src/astro/lib/call.ts
CHANGED
|
@@ -41,6 +41,8 @@ export interface PublicRouteError {
|
|
|
41
41
|
message: string;
|
|
42
42
|
/** Input validation issues, when the route reported them (`BAD_REQUEST`). */
|
|
43
43
|
issues?: PublicRouteIssue[];
|
|
44
|
+
/** Any other top-level fields of the route's refusal, e.g. Vouchers' `lookups` (T166). */
|
|
45
|
+
details?: Record<string, unknown>;
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
export type PublicRouteResult<T> =
|
|
@@ -162,10 +164,12 @@ function refusal(data: unknown): PublicRouteError | undefined {
|
|
|
162
164
|
if (!data || typeof data !== "object") return undefined;
|
|
163
165
|
const body = data as { ok?: unknown; error?: { code?: unknown; message?: unknown }; issues?: unknown };
|
|
164
166
|
if (body.ok !== false || typeof body.error?.code !== "string") return undefined;
|
|
167
|
+
const { ok: _ok, error: _error, issues: _issues, ...details } = body as Record<string, unknown>;
|
|
165
168
|
return {
|
|
166
169
|
code: body.error.code,
|
|
167
170
|
message: typeof body.error.message === "string" ? body.error.message : "Request failed",
|
|
168
171
|
...(Array.isArray(body.issues) ? { issues: body.issues as PublicRouteIssue[] } : {}),
|
|
172
|
+
...(Object.keys(details).length > 0 ? { details } : {}),
|
|
169
173
|
};
|
|
170
174
|
}
|
|
171
175
|
|
|
@@ -11,13 +11,35 @@ import {
|
|
|
11
11
|
widgetErrorLocation,
|
|
12
12
|
} from "./widget";
|
|
13
13
|
|
|
14
|
+
/** What the suite's voucher hook answers (T166): a signed `voucher-hold/1` token, or the refusal's code. */
|
|
15
|
+
export type VoucherHoldResult = { ok: true; hold: string } | { ok: false; code: string };
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Holds a gift voucher for a booking just reserved (T166, voucher/1 §8.1): the suite's `holdVoucher`, given
|
|
19
|
+
* through `eventsIntegration({ vouchers })`. Events never talks to Vouchers itself.
|
|
20
|
+
*/
|
|
21
|
+
export type VoucherHook = (
|
|
22
|
+
ctx: PublicRouteContext,
|
|
23
|
+
input: { code: string; bookingRef: string; accessToken: string },
|
|
24
|
+
) => Promise<VoucherHoldResult>;
|
|
25
|
+
|
|
14
26
|
export interface CheckoutFormOptions {
|
|
15
27
|
/** The core's plugin id. Defaults to the slug; registry installs pass their `r_…` id. */
|
|
16
28
|
pluginId?: string;
|
|
17
29
|
/** Injected for tests: makes the idempotency key when the form carries none. */
|
|
18
30
|
newKey?: () => string;
|
|
31
|
+
/** The gift voucher hold (T166); without it a typed voucher code is refused (`VOUCHER_UNAVAILABLE`). */
|
|
32
|
+
voucher?: VoucherHook;
|
|
33
|
+
/** The suite's dry run of that hold before reserving (T168); without it the hold alone decides. */
|
|
34
|
+
check?: VoucherCheckHook;
|
|
19
35
|
}
|
|
20
36
|
|
|
37
|
+
/** Checks a typed gift voucher code before anything is reserved (T168): the suite's `checkVoucher`. */
|
|
38
|
+
export type VoucherCheckHook = (
|
|
39
|
+
ctx: PublicRouteContext,
|
|
40
|
+
input: { code: string; eventId: string; ticketTypeIds: string[] },
|
|
41
|
+
) => Promise<{ ok: true } | { ok: false; code: string }>;
|
|
42
|
+
|
|
21
43
|
export interface CheckoutRedirect {
|
|
22
44
|
location: string;
|
|
23
45
|
/** The booking's access token, for an HttpOnly cookie scoped to `/booking`. Never in a URL. */
|
|
@@ -176,8 +198,22 @@ export async function handleCheckoutForm(
|
|
|
176
198
|
needsOccurrence: form.get("needsOccurrence") === "1",
|
|
177
199
|
occurrenceId,
|
|
178
200
|
});
|
|
201
|
+
// A booking request (T174a): a date and a window instead of an occurrence; both are needed.
|
|
202
|
+
const request = { date: text(form, "requestDate"), window: text(form, "requestWindow") };
|
|
203
|
+
const asks = form.get("needsRequest") === "1";
|
|
204
|
+
if (asks && !(request.date && request.window)) invalid.push("occurrence");
|
|
179
205
|
if (invalid.length > 0) return refuse("BAD_REQUEST", invalid);
|
|
180
206
|
|
|
207
|
+
// A gift voucher (T166) is held between reserve and continue; without the suite's hook it cannot be.
|
|
208
|
+
const voucherCode = text(form, "voucherCode");
|
|
209
|
+
if (voucherCode && !options.voucher) return refuse("VOUCHER_UNAVAILABLE", ["voucher"]);
|
|
210
|
+
// T168: a code the suite's check refuses never reserves, so no booking is held, cancelled and emailed.
|
|
211
|
+
if (voucherCode && options.check) {
|
|
212
|
+
const ticketTypeIds = lines.map((l) => l.ticketTypeId);
|
|
213
|
+
const checked = await options.check(ctx, { code: voucherCode, eventId, ticketTypeIds });
|
|
214
|
+
if (!checked.ok) return refuse(checked.code, ["voucher"]);
|
|
215
|
+
}
|
|
216
|
+
|
|
181
217
|
const turnstileToken = text(form, "cf-turnstile-response");
|
|
182
218
|
// Only a typed code is sent: Free's reserve refuses unknown keys, and only Pro offers the field.
|
|
183
219
|
const promoCode = text(form, "promoCode");
|
|
@@ -190,6 +226,7 @@ export async function handleCheckoutForm(
|
|
|
190
226
|
body: {
|
|
191
227
|
eventId,
|
|
192
228
|
...(occurrenceId ? { occurrenceId } : {}),
|
|
229
|
+
...(asks ? { request } : {}),
|
|
193
230
|
lines,
|
|
194
231
|
buyer,
|
|
195
232
|
idempotencyKey: text(form, "idempotencyKey") || (options.newKey ?? newIdempotencyKey)(),
|
|
@@ -210,11 +247,22 @@ export async function handleCheckoutForm(
|
|
|
210
247
|
// A resubmit of a booking that is already confirmed gets no new token: this browser has its cookie.
|
|
211
248
|
if (!accessToken) return { location: done };
|
|
212
249
|
const cookie = { name: bookingCookieName(bookingRef), value: accessToken };
|
|
250
|
+
let voucherHold: string | undefined;
|
|
251
|
+
if (voucherCode && options.voucher) {
|
|
252
|
+
const held = await options.voucher(ctx, { code: voucherCode, bookingRef, accessToken });
|
|
253
|
+
if (!held.ok) {
|
|
254
|
+
// Nothing paid yet: release the places so the corrected order can have them.
|
|
255
|
+
const body = { bookingRef, accessToken };
|
|
256
|
+
await callPublicRoute(ctx, { method: "POST", path: "public/booking/cancel", pluginId, body });
|
|
257
|
+
return refuse(held.code, ["voucher"]);
|
|
258
|
+
}
|
|
259
|
+
voucherHold = held.hold;
|
|
260
|
+
}
|
|
213
261
|
const next = await callPublicRoute<{ next?: { type?: string; url?: string } }>(ctx, {
|
|
214
262
|
method: "POST",
|
|
215
263
|
path: "public/checkout/continue",
|
|
216
264
|
pluginId,
|
|
217
|
-
body: { bookingRef, accessToken },
|
|
265
|
+
body: { bookingRef, accessToken, ...(voucherHold ? { voucherHold } : {}) },
|
|
218
266
|
});
|
|
219
267
|
if (!next.ok) return fail(next.error.code, bookingRef, cookie);
|
|
220
268
|
|
package/src/astro/lib/list.ts
CHANGED
|
@@ -62,6 +62,28 @@ const WHEN: Intl.DateTimeFormatOptions = {
|
|
|
62
62
|
timeZoneName: "short",
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
+
/** The booking widget's and the waiver page's date format: full date, short time. */
|
|
66
|
+
const AT: Intl.DateTimeFormatOptions = { dateStyle: "full", timeStyle: "short" };
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* A time on a customer page (a deadline, a hold, the booked session): local time in the event's own zone, as the
|
|
70
|
+
* session's time line reads ("Monday 9 November 2026 at 15:09", T157), without the zone's name. A missing or
|
|
71
|
+
* unknown zone shows UTC and says so; a value that is not a date is shown as it is.
|
|
72
|
+
*/
|
|
73
|
+
export function zonedAt(iso: string, timezone: string | null | undefined, locale: string): string {
|
|
74
|
+
const ms = Date.parse(iso);
|
|
75
|
+
if (!Number.isFinite(ms)) return iso;
|
|
76
|
+
const known = Boolean(timezone && isValidTimeZone(timezone));
|
|
77
|
+
const zone = known ? (timezone as string) : "UTC";
|
|
78
|
+
let time: string;
|
|
79
|
+
try {
|
|
80
|
+
time = formatInZone(ms, zone, locale, AT);
|
|
81
|
+
} catch {
|
|
82
|
+
time = formatInZone(ms, zone, "en-GB", AT); // A locale `Intl` refuses, such as `en_GB`.
|
|
83
|
+
}
|
|
84
|
+
return known ? time : `${time} (${zone})`;
|
|
85
|
+
}
|
|
86
|
+
|
|
65
87
|
const BADGES = { cancelled: "list.badge.cancelled", closed: "list.badge.closed", paused: "list.badge.paused" } as const;
|
|
66
88
|
|
|
67
89
|
/** The start in the event's own zone; a missing or unknown zone shows UTC rather than failing. */
|