@semics-tech/emdash-events 0.0.0-stage → 1.0.0-rc.1

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 (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +83 -2
  3. package/dist/index.d.mts +5 -0
  4. package/dist/index.mjs +416 -0
  5. package/dist/manifest.json +425 -0
  6. package/dist/plugin.d.mts +11 -0
  7. package/dist/plugin.mjs +7 -0
  8. package/dist/ts/astro/lib/call.d.ts +54 -0
  9. package/dist/ts/astro/lib/call.js +121 -0
  10. package/dist/ts/integration/index.d.ts +48 -0
  11. package/dist/ts/integration/index.js +76 -0
  12. package/dist/ts/ui/index.d.ts +6 -0
  13. package/dist/ts/ui/index.js +46 -0
  14. package/emdash-plugin.jsonc +222 -0
  15. package/package.json +78 -3
  16. package/src/astro/AddToCalendar.astro +47 -0
  17. package/src/astro/AttendeeList.astro +157 -0
  18. package/src/astro/BookingBlock.astro +30 -0
  19. package/src/astro/BookingPage.astro +230 -0
  20. package/src/astro/BookingStatus.astro +112 -0
  21. package/src/astro/BookingWidget.astro +776 -0
  22. package/src/astro/CheckIn.astro +186 -0
  23. package/src/astro/DoorSignPage.astro +62 -0
  24. package/src/astro/EventCard.astro +81 -0
  25. package/src/astro/EventList.astro +83 -0
  26. package/src/astro/OptOutPage.astro +58 -0
  27. package/src/astro/PaymentReturn.astro +96 -0
  28. package/src/astro/TicketPass.astro +95 -0
  29. package/src/astro/checkout-endpoint.ts +11 -0
  30. package/src/astro/index.js +18 -0
  31. package/src/astro/lib/attendees.ts +170 -0
  32. package/src/astro/lib/call.ts +185 -0
  33. package/src/astro/lib/checkout-form.ts +271 -0
  34. package/src/astro/lib/list.ts +99 -0
  35. package/src/astro/lib/opt-out.ts +49 -0
  36. package/src/astro/lib/pass.ts +35 -0
  37. package/src/astro/lib/payment.ts +73 -0
  38. package/src/astro/lib/picker.ts +245 -0
  39. package/src/astro/lib/promo.ts +162 -0
  40. package/src/astro/lib/questions.ts +107 -0
  41. package/src/astro/lib/receipt.ts +132 -0
  42. package/src/astro/lib/waitlist.ts +72 -0
  43. package/src/astro/lib/widget.ts +299 -0
  44. package/src/astro/promo-endpoint.ts +11 -0
  45. package/src/astro/virtual.d.ts +16 -0
  46. package/src/astro/waitlist-endpoint.ts +12 -0
  47. package/src/client/booking.ts +190 -0
  48. package/src/client/checkin.ts +260 -0
  49. package/src/client/payment.ts +76 -0
  50. package/src/client/picker.ts +143 -0
  51. package/src/client/receipt.ts +75 -0
  52. package/src/i18n/ar.ts +251 -0
  53. package/src/i18n/en.ts +255 -0
  54. package/src/i18n/index.ts +121 -0
@@ -0,0 +1,230 @@
1
+ ---
2
+ // Injected at `/booking` by the integration. The booking ref is in the URL; the access token is
3
+ // only ever in the HttpOnly cookie the checkout endpoint set, and goes to the core in POST bodies.
4
+ // The emailed link (`?ref=&k=<one-time code>`, R34) renders an "Open my booking" button and
5
+ // redeems nothing: only its POST swaps the code for a token, sets the cookie and redirects to
6
+ // `?ref=` without `k`, so mail scanners that prefetch links cannot use the code up.
7
+ // It is also the waiver return page (EV-FR-12): e-sign sends the signer back to `?ref=#receipt=`;
8
+ // `src/client/receipt.ts` clears the fragment and posts the receipt here, which forwards it to the
9
+ // core's `signatures/receipt` (no access token needed: the receipt is HMAC-signed) and redirects to
10
+ // `?ref=&waiver=<outcome>`.
11
+ import { esignPluginId, pluginId, reconcile } from "virtual:semics-events/config";
12
+
13
+ import { type MessageKey, pickLocale, translator } from "../i18n/index";
14
+ import AddToCalendar from "./AddToCalendar.astro";
15
+ import BookingStatus from "./BookingStatus.astro";
16
+ import PaymentReturn from "./PaymentReturn.astro";
17
+ import { callPublicRoute } from "./lib/call";
18
+ import {
19
+ bookingCookieName,
20
+ bookingCookieOptions,
21
+ claimOfferLink,
22
+ crossSiteResponse,
23
+ isCrossSiteRequest,
24
+ LINK_INVALID,
25
+ OFFER_INVALID,
26
+ redeemBookingLink,
27
+ resumePayment,
28
+ } from "./lib/checkout-form";
29
+ import AttendeeList from "./AttendeeList.astro";
30
+ import { handleAttendeeAction, signingRows } from "./lib/attendees";
31
+ import { paymentView } from "./lib/payment";
32
+ import { forwardReceipt } from "./lib/receipt";
33
+ import { type BookingView, type PublicEvent, ticketNames } from "./lib/widget";
34
+ import TicketPass from "./TicketPass.astro";
35
+
36
+ export const prerender = false;
37
+
38
+ Astro.response.headers.set("Referrer-Policy", "no-referrer");
39
+ Astro.response.headers.set("Cache-Control", "private, no-store");
40
+
41
+ // The page's language is the site's (Astro i18n), else British English (T102).
42
+ const locale = pickLocale(Astro.currentLocale);
43
+ const { t, lang, dir } = translator(locale);
44
+ const CODES = [
45
+ "SOLD_OUT",
46
+ "SALES_CLOSED",
47
+ "HOLD_EXPIRED",
48
+ "PAYMENT_FAILED",
49
+ "CANCEL_NOT_ALLOWED",
50
+ "BAD_REQUEST",
51
+ LINK_INVALID,
52
+ OFFER_INVALID,
53
+ // The attendee signing list (T133, Events Pro).
54
+ "ATTENDEE_SIGNED",
55
+ "ATTENDEES_LOCKED",
56
+ "ATTENDEE_INVALID",
57
+ "ATTENDEES_UNSENT",
58
+ "WAIVER_EMAIL_REQUIRED",
59
+ "WAIVER_TOO_MANY_EMAILS",
60
+ "RATE_LIMITED",
61
+ "SIGNING_UNAVAILABLE",
62
+ "ESIGN_NOT_CONFIGURED",
63
+ ];
64
+ const WAIVER_OUTCOMES = ["signed", "declined", "voided", "expired", "failed"];
65
+ const ATTENDEE_OUTCOMES = ["saved", "resent"];
66
+ const errorText = (code: string, fallback: MessageKey) =>
67
+ CODES.includes(code) ? t(`booking.error.${code}` as MessageKey) : t(fallback);
68
+
69
+ const url = Astro.url;
70
+ const rawRef = url.searchParams.get("ref") ?? "";
71
+ const ref = /^[0-9A-HJKMNP-TV-Z]{10}$/.test(rawRef) ? rawRef : "";
72
+ const errorCode = url.searchParams.get("error") ?? "";
73
+ const waiver = url.searchParams.get("waiver") ?? "";
74
+ const waiverNotice = WAIVER_OUTCOMES.includes(waiver) ? t(`booking.waiver.${waiver}` as MessageKey) : "";
75
+ const attendeesOutcome = url.searchParams.get("attendees") ?? "";
76
+ const attendeesNotice = ATTENDEE_OUTCOMES.includes(attendeesOutcome)
77
+ ? t(`booking.attendees.${attendeesOutcome}` as MessageKey)
78
+ : "";
79
+ let notice = errorCode ? errorText(errorCode, "booking.error.INTERNAL") : waiverNotice || attendeesNotice;
80
+ const code = url.searchParams.get("k") ?? "";
81
+ const ctx = { locals: Astro.locals, url, request: Astro.request };
82
+ // The cancel and redeem forms post here: refuse another site's posts (CSRF) before reading them.
83
+ if (isCrossSiteRequest(Astro.request, url)) return crossSiteResponse();
84
+ const form = Astro.request.method === "POST" ? await Astro.request.formData().catch(() => new FormData()) : undefined;
85
+
86
+ if (form?.get("intent") === "receipt") {
87
+ const result = await forwardReceipt(ctx, { ref: rawRef, receipt: form.get("receipt") }, { pluginId, esignPluginId });
88
+ return Astro.redirect(result.location, 303);
89
+ }
90
+ if (form?.get("intent") === "redeem") {
91
+ const k = form.get("k");
92
+ const result = await redeemBookingLink(ctx, { ref: rawRef, code: typeof k === "string" ? k : "" }, { pluginId });
93
+ if (result.cookie) Astro.cookies.set(result.cookie.name, result.cookie.value, bookingCookieOptions(url));
94
+ return Astro.redirect(result.location, 303);
95
+ }
96
+ if (form?.get("intent") === "claim") {
97
+ // A waitlist offer (T081): claimed only from this POST, like the booking link above.
98
+ const k = form.get("k");
99
+ const result = await claimOfferLink(ctx, { ref: rawRef, code: typeof k === "string" ? k : "" }, { pluginId });
100
+ if (result.cookie) Astro.cookies.set(result.cookie.name, result.cookie.value, bookingCookieOptions(url));
101
+ return Astro.redirect(result.location, 303);
102
+ }
103
+ if (form?.get("intent") === "resume") {
104
+ // "Pay now": the token is the cookie's, never a field; nothing Stripe appends to the URL is read.
105
+ const token = ref ? (Astro.cookies.get(bookingCookieName(ref))?.value ?? "") : "";
106
+ const result = await resumePayment(ctx, { ref: rawRef, token }, { pluginId });
107
+ return Astro.redirect(result.location, 303);
108
+ }
109
+ // An emailed link: show the button and touch nothing else (GET must not redeem).
110
+ const opening = Boolean(ref && code);
111
+ const offer = url.searchParams.get("offer") === "1";
112
+ const token = ref && !opening ? (Astro.cookies.get(bookingCookieName(ref))?.value ?? "") : "";
113
+
114
+ let cancelled = false;
115
+ if (ref && token && form) {
116
+ if (form.get("intent") === "cancel") {
117
+ const result = await callPublicRoute(ctx, {
118
+ method: "POST",
119
+ path: "public/booking/cancel",
120
+ pluginId,
121
+ body: { bookingRef: ref, accessToken: token },
122
+ });
123
+ if (result.ok) cancelled = true;
124
+ else notice = errorText(result.error.code, "booking.cancelFailed");
125
+ }
126
+ }
127
+
128
+ let booking: BookingView | undefined;
129
+ let missing = false;
130
+ if (ref && token) {
131
+ const result = await callPublicRoute<BookingView>(ctx, {
132
+ method: "POST",
133
+ path: "public/booking",
134
+ pluginId,
135
+ body: { bookingRef: ref, accessToken: token },
136
+ });
137
+ if (result.ok) booking = result.data;
138
+ else missing = true;
139
+ // A booking waiting for signatures is reconciled with e-sign (the suite supplies `reconcile`): a signer who
140
+ // closed the tab or signed by email has a receipt this page forwards, then it shows the booking afresh.
141
+ if (booking?.waiver?.lookups && reconcile && esignPluginId) {
142
+ const done = await reconcile(ctx, { booking, pluginId, esignPluginId });
143
+ if (done.forwarded > 0) {
144
+ const fresh = await callPublicRoute<BookingView>(ctx, {
145
+ method: "POST",
146
+ path: "public/booking",
147
+ pluginId,
148
+ body: { bookingRef: ref, accessToken: token },
149
+ });
150
+ if (fresh.ok) booking = fresh.data;
151
+ }
152
+ }
153
+ } else if (ref && !opening) {
154
+ missing = true;
155
+ }
156
+ // The attendee signing list's forms (T133): Sign now, Resend and Save, against the fresh answer.
157
+ if (booking && form && ref && token) {
158
+ const done = await handleAttendeeAction(ctx, form, { ref, token }, { pluginId, esignPluginId }, booking);
159
+ if (done) return Astro.redirect(done.location, 303);
160
+ }
161
+ // The lines name their ticket types from the event (T134): the booking itself carries only ids.
162
+ let names: Record<string, string> = {};
163
+ if (booking?.eventId) {
164
+ const event = await callPublicRoute<PublicEvent>(ctx, { path: "public/event", pluginId, body: { eventId: booking.eventId } });
165
+ if (event.ok) names = ticketNames(event.data);
166
+ }
167
+ const signingList = booking && !cancelled ? signingRows(booking) : null;
168
+ const payment = booking && !cancelled ? paymentView(booking, locale) : null;
169
+ const passes = booking && !cancelled && booking.status === "confirmed" ? booking.attendees.filter((a) => a.code) : [];
170
+ ---
171
+ <!doctype html>
172
+ <html lang={lang} dir={dir}>
173
+ <head>
174
+ <meta charset="utf-8" />
175
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
176
+ <meta name="robots" content="noindex" />
177
+ <meta name="referrer" content="no-referrer" />
178
+ <title>{t("booking.title")}</title>
179
+ </head>
180
+ <body>
181
+ <main class="semics-booking" data-testid="booking-page">
182
+ <h1>{t("booking.title")}</h1>
183
+ <form method="post" action={ref ? `/booking?ref=${ref}` : "/booking"} data-semics-fragment="receipt" hidden>
184
+ <input type="hidden" name="intent" value="receipt" />
185
+ <input type="hidden" name="receipt" value="" />
186
+ </form>
187
+ {notice && <p role="alert" data-testid="booking-notice" data-code={errorCode}>{notice}</p>}
188
+ {
189
+ opening ? (
190
+ <form method="post" action={`/booking?ref=${ref}`} class="semics-events semics-booking-open" data-testid="booking-open">
191
+ <input type="hidden" name="intent" value={offer ? "claim" : "redeem"} />
192
+ <input type="hidden" name="k" value={code} />
193
+ <p>{offer ? t("booking.offer.intro") : t("booking.open.intro")}</p>
194
+ <button type="submit">{offer ? t("booking.offer.button") : t("booking.open.button")}</button>
195
+ </form>
196
+ ) : booking ? (
197
+ <>
198
+ <BookingStatus booking={booking} cancelled={cancelled} cancelAction={`/booking?ref=${ref}`} ticketNames={names} locale={locale} />
199
+ {payment && <PaymentReturn view={payment} bookingRef={ref} action={`/booking?ref=${ref}`} locale={locale} />}
200
+ {signingList && (
201
+ <AttendeeList
202
+ rows={signingList}
203
+ action={`/booking?ref=${ref}`}
204
+ editUntil={booking.signingList?.editable ? booking.signingList.editUntil : undefined}
205
+ locale={locale}
206
+ />
207
+ )}
208
+ {passes.length > 0 && (
209
+ <section aria-labelledby="semics-passes-title">
210
+ <h2 id="semics-passes-title">{t("booking.passes")}</h2>
211
+ {passes.map((a) => (
212
+ <TicketPass name={a.name} code={a.code ?? ""} status={a.status} qr={a.qr} locale={locale} />
213
+ ))}
214
+ </section>
215
+ )}
216
+ {!cancelled && booking.status === "confirmed" && <AddToCalendar signedQuery={booking.calendar?.query} locale={locale} />}
217
+ </>
218
+ ) : missing ? (
219
+ <p data-testid="booking-missing">{t("booking.missing")}</p>
220
+ ) : !notice ? (
221
+ <p data-testid="booking-empty">{t("booking.empty")}</p>
222
+ ) : null
223
+ }
224
+ </main>
225
+ <script>
226
+ import "../client/receipt.ts";
227
+ import "../client/payment.ts";
228
+ </script>
229
+ </body>
230
+ </html>
@@ -0,0 +1,112 @@
1
+ ---
2
+ // <BookingStatus>: a booking's state, order and cancel button (EU-FR-06). Rendered by the
3
+ // `/booking` page from the `public/booking` answer; the cancel form is a plain POST back to it.
4
+ import { around, pickLocale, translator } from "../i18n/index";
5
+ import { type BookingView, formatMoney, statusLabel } from "./lib/widget";
6
+
7
+ interface Props {
8
+ booking: BookingView;
9
+ /** Shown as cancelled (the page just cancelled it). */
10
+ cancelled?: boolean;
11
+ /** Where the cancel form posts. */
12
+ cancelAction?: string;
13
+ /** Ticket type names by id, when the page knows them. */
14
+ ticketNames?: Record<string, string>;
15
+ locale?: string;
16
+ }
17
+
18
+ const { booking, cancelled = false, cancelAction, ticketNames = {} } = Astro.props;
19
+ const locale = pickLocale(Astro.props.locale, Astro.currentLocale);
20
+ const { t, plural, lang, dir } = translator(locale);
21
+ // A request awaiting approval (T131) holds its places until the organiser's deadline.
22
+ const [heldBefore, heldAfter] = around(
23
+ t(booking.status === "awaiting_approval" ? "booking.decideBy" : "booking.heldUntil"),
24
+ "time",
25
+ );
26
+ const [cancelBefore, cancelAfter] = around(t("booking.cancelUntil"), "time");
27
+ const tickets = booking.lines.reduce((n, line) => n + line.qty, 0);
28
+ const status = cancelled ? "cancelled" : booking.status;
29
+ const at = (iso: string) => {
30
+ try {
31
+ const time = new Intl.DateTimeFormat(locale, { dateStyle: "medium", timeStyle: "short", timeZone: "UTC" }).format(
32
+ new Date(iso),
33
+ );
34
+ return t("time.utc", { time });
35
+ } catch {
36
+ return iso;
37
+ }
38
+ };
39
+ ---
40
+ <section class="semics-events semics-booking-status" data-testid="booking-details" data-status={status} lang={lang} dir={dir} aria-labelledby="semics-booking-status-title">
41
+ <h2 id="semics-booking-status-title" class="semics-visually-hidden">{t("booking.status")}</h2>
42
+ <p>
43
+ {t("booking.reference")} <strong data-testid="booking-ref">{booking.bookingRef}</strong>
44
+ </p>
45
+ <p class="semics-status" data-testid="booking-status" data-status={status}>
46
+ <span class="semics-status-badge">{statusLabel(status, locale)}</span>
47
+ </p>
48
+ {
49
+ !cancelled && booking.holdExpiresAt && (
50
+ <p data-testid="booking-hold">
51
+ {heldBefore}<time datetime={booking.holdExpiresAt}>{at(booking.holdExpiresAt)}</time>{heldAfter}
52
+ </p>
53
+ )
54
+ }
55
+ <ul class="semics-lines" aria-label={plural("booking.lines", tickets)}>
56
+ {
57
+ booking.lines.map((line) => (
58
+ <li>
59
+ {ticketNames[line.ticketTypeId]
60
+ ? t("booking.line", { qty: new Intl.NumberFormat(locale).format(line.qty), name: ticketNames[line.ticketTypeId] })
61
+ : plural("booking.lines", line.qty)}
62
+ </li>
63
+ ))
64
+ }
65
+ </ul>
66
+ <p>{t("booking.total")} <strong>{formatMoney(booking.totals.totalMinor, booking.totals.currency, locale)}</strong></p>
67
+ {
68
+ booking.canCancel && !cancelled && cancelAction && (
69
+ <form method="post" action={cancelAction}>
70
+ <input type="hidden" name="intent" value="cancel" />
71
+ {booking.cancelBy && (
72
+ <p>
73
+ {cancelBefore}<time datetime={booking.cancelBy}>{at(booking.cancelBy)}</time>{cancelAfter}
74
+ </p>
75
+ )}
76
+ <button type="submit">{t("booking.cancel")}</button>
77
+ </form>
78
+ )
79
+ }
80
+ </section>
81
+
82
+ <style>
83
+ .semics-booking-status {
84
+ box-sizing: border-box;
85
+ max-inline-size: 36rem;
86
+ color: var(--events-fg, #1a1a1a);
87
+ overflow-wrap: anywhere;
88
+ }
89
+ .semics-status-badge {
90
+ display: inline-block;
91
+ padding: 0.125rem 0.5rem;
92
+ border: 1px solid currentColor;
93
+ border-radius: var(--events-radius, 6px);
94
+ font-weight: 600;
95
+ }
96
+ .semics-booking-status[data-status="confirmed"] .semics-status-badge {
97
+ color: var(--events-success, #146c2e);
98
+ }
99
+ .semics-booking-status button {
100
+ font: inherit;
101
+ min-block-size: 2.75rem;
102
+ padding: 0.5rem 1rem;
103
+ }
104
+ .semics-visually-hidden {
105
+ position: absolute;
106
+ inline-size: 1px;
107
+ block-size: 1px;
108
+ overflow: hidden;
109
+ clip-path: inset(50%);
110
+ white-space: nowrap;
111
+ }
112
+ </style>