@semics-tech/emdash-events 1.0.0-rc.15 → 1.0.0-rc.16
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/index.mjs +1 -1
- package/dist/manifest.json +1 -1
- package/package.json +1 -1
- package/src/astro/BookingPage.astro +3 -0
- package/src/astro/BookingWidget.astro +36 -1
- package/src/astro/lib/book-link.ts +46 -0
- package/src/i18n/ar.ts +1 -0
- package/src/i18n/en.ts +1 -0
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
/** @type {import("emdash").PluginDescriptor} */
|
|
8
8
|
const descriptor = Object.freeze({
|
|
9
9
|
"id": "semics-events",
|
|
10
|
-
"version": "1.0.0-rc.
|
|
10
|
+
"version": "1.0.0-rc.16",
|
|
11
11
|
"format": "standard",
|
|
12
12
|
"entrypoint": "@semics-tech/emdash-events/sandbox",
|
|
13
13
|
"capabilities": [
|
package/dist/manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
} from "./lib/checkout-form";
|
|
32
32
|
import AttendeeList from "./AttendeeList.astro";
|
|
33
33
|
import { handleAttendeeAction, signingRows, waiverStep } from "./lib/attendees";
|
|
34
|
+
import { VOUCHER_COOKIE } from "./lib/book-link";
|
|
34
35
|
import { eventPageHref, pageCss } from "./lib/page";
|
|
35
36
|
import { paymentView } from "./lib/payment";
|
|
36
37
|
import { forwardReceipt } from "./lib/receipt";
|
|
@@ -168,6 +169,8 @@ if (ref && token) {
|
|
|
168
169
|
missing = true;
|
|
169
170
|
}
|
|
170
171
|
if (booking) booking = asOfNow(booking, Date.now());
|
|
172
|
+
// T171: a booking that used a gift voucher forgets the code "Book with this voucher" left for the form.
|
|
173
|
+
if ((booking?.totals?.voucherMinor ?? 0) > 0) Astro.cookies.delete(VOUCHER_COOKIE, { path: "/" });
|
|
171
174
|
// The attendee signing list's forms (T133): Sign now, Resend and Save, against the fresh answer.
|
|
172
175
|
if (booking && form && ref && token) {
|
|
173
176
|
const done = await handleAttendeeAction(ctx, form, { ref, token }, { pluginId, esignPluginId }, booking);
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { pluginId } from "virtual:semics-events/config";
|
|
7
7
|
|
|
8
8
|
import { pickLocale, translator } from "../i18n/index";
|
|
9
|
+
import { bookAnchor, presetTicketType, presetVoucher } from "./lib/book-link";
|
|
9
10
|
import { callPublicRoute } from "./lib/call";
|
|
10
11
|
import { CHECKOUT_PATH, QTY_PREFIX } from "./lib/checkout-form";
|
|
11
12
|
import { pickerFetchFrom, pickerHref, pickerParam, pickerView, usesPicker } from "./lib/picker";
|
|
@@ -86,6 +87,23 @@ const ticketTypes = [
|
|
|
86
87
|
...(takesCodes ? (promo?.hiddenTypes ?? []) : []).filter((t) => !listed.has(t.id)),
|
|
87
88
|
] as PublicEvent["ticketTypes"];
|
|
88
89
|
const onSale = data?.status === "on_sale" && ticketTypes.length > 0;
|
|
90
|
+
// "Book with this voucher" (T171): the voucher page left the code in an HttpOnly cookie (never a URL) and may
|
|
91
|
+
// name a ticket type, which starts at one ticket. A page that filled in a code must not be cached.
|
|
92
|
+
let presetCode = "";
|
|
93
|
+
if (takesVouchers) {
|
|
94
|
+
presetCode = presetVoucher(Astro.cookies);
|
|
95
|
+
if (presetCode) {
|
|
96
|
+
try {
|
|
97
|
+
Astro.response.headers.set("Cache-Control", "private, no-store");
|
|
98
|
+
} catch {
|
|
99
|
+
// Headers already sent: the cookie only reaches the buyer who has it.
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const presetType = presetTicketType(
|
|
104
|
+
Astro.url,
|
|
105
|
+
ticketTypes.filter((t) => t.available !== 0).map((t) => t.id),
|
|
106
|
+
);
|
|
89
107
|
// Many dates a day, or a slot schedule (T130): a month calendar of days, then the day's times. Without
|
|
90
108
|
// JavaScript the same month's dates show as a select grouped by day.
|
|
91
109
|
const zone = data?.timezone ?? "UTC";
|
|
@@ -133,6 +151,7 @@ const when = (iso: string) => {
|
|
|
133
151
|
</form>
|
|
134
152
|
)}
|
|
135
153
|
<form
|
|
154
|
+
id={bookAnchor(eventId)}
|
|
136
155
|
method="post"
|
|
137
156
|
action={CHECKOUT_PATH}
|
|
138
157
|
data-semics-booking
|
|
@@ -143,6 +162,11 @@ const when = (iso: string) => {
|
|
|
143
162
|
data-turnstile-message={siteKey ? t("widget.turnstile") : undefined}
|
|
144
163
|
>
|
|
145
164
|
<p class="semics-form-alert" role="alert" data-form-alert hidden={!formAlert}>{formAlert}</p>
|
|
165
|
+
{takesVouchers && (
|
|
166
|
+
<p class="semics-have-voucher">
|
|
167
|
+
<a href={`#${id}-voucher`} data-testid="have-voucher">{t("widget.voucher.have")}</a>
|
|
168
|
+
</p>
|
|
169
|
+
)}
|
|
146
170
|
<input type="hidden" name="eventId" value={eventId} />
|
|
147
171
|
<input type="hidden" name="returnTo" value={returnTo} />
|
|
148
172
|
<input type="hidden" name="idempotencyKey" value={newIdempotencyKey()} />
|
|
@@ -315,6 +339,7 @@ const when = (iso: string) => {
|
|
|
315
339
|
autocapitalize="characters"
|
|
316
340
|
spellcheck="false"
|
|
317
341
|
maxlength="64"
|
|
342
|
+
value={presetCode || undefined}
|
|
318
343
|
data-field="voucher"
|
|
319
344
|
aria-invalid={invalid("voucher")}
|
|
320
345
|
aria-describedby={errId("voucher")}
|
|
@@ -342,7 +367,7 @@ const when = (iso: string) => {
|
|
|
342
367
|
type="number"
|
|
343
368
|
inputmode="numeric"
|
|
344
369
|
name={`${QTY_PREFIX}${type.id}`}
|
|
345
|
-
value="0"
|
|
370
|
+
value={type.id === presetType ? "1" : "0"}
|
|
346
371
|
min="0"
|
|
347
372
|
max={String(max)}
|
|
348
373
|
disabled={soldOut}
|
|
@@ -851,6 +876,16 @@ const when = (iso: string) => {
|
|
|
851
876
|
background: var(--_bg);
|
|
852
877
|
color: var(--_accent);
|
|
853
878
|
}
|
|
879
|
+
.semics-have-voucher {
|
|
880
|
+
margin: 0;
|
|
881
|
+
}
|
|
882
|
+
.semics-have-voucher a {
|
|
883
|
+
color: var(--_accent);
|
|
884
|
+
}
|
|
885
|
+
.semics-booking-widget input:target {
|
|
886
|
+
outline: 3px solid var(--_accent);
|
|
887
|
+
outline-offset: 2px;
|
|
888
|
+
}
|
|
854
889
|
.semics-promo-note {
|
|
855
890
|
margin: 0;
|
|
856
891
|
color: var(--_muted);
|
|
@@ -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/i18n/ar.ts
CHANGED
|
@@ -34,6 +34,7 @@ export const ar: Messages = {
|
|
|
34
34
|
"widget.promo.apply": "تطبيق الرمز",
|
|
35
35
|
"widget.promo.update": "تحديث الرمز",
|
|
36
36
|
"widget.voucher.label": "رمز قسيمة الهدية",
|
|
37
|
+
"widget.voucher.have": "هل لديك قسيمة هدية؟",
|
|
37
38
|
"widget.tickets": "التذاكر",
|
|
38
39
|
"widget.soldOut": "نفدت التذاكر",
|
|
39
40
|
"widget.name": "اسمك",
|
package/src/i18n/en.ts
CHANGED
|
@@ -35,6 +35,7 @@ export const en = {
|
|
|
35
35
|
"widget.promo.apply": "Apply code",
|
|
36
36
|
"widget.promo.update": "Update code",
|
|
37
37
|
"widget.voucher.label": "Gift voucher code",
|
|
38
|
+
"widget.voucher.have": "Have a gift voucher?",
|
|
38
39
|
"widget.tickets": "Tickets",
|
|
39
40
|
"widget.soldOut": "Sold out",
|
|
40
41
|
"widget.name": "Your name",
|