@semics-tech/emdash-events 0.0.0-bootstrap.0 → 1.0.0-rc.0

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 (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +82 -2
  3. package/dist/index.d.mts +5 -0
  4. package/dist/index.mjs +392 -0
  5. package/dist/manifest.json +401 -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 +206 -0
  15. package/package.json +79 -10
  16. package/src/astro/AddToCalendar.astro +47 -0
  17. package/src/astro/BookingBlock.astro +30 -0
  18. package/src/astro/BookingPage.astro +193 -0
  19. package/src/astro/BookingStatus.astro +106 -0
  20. package/src/astro/BookingWidget.astro +581 -0
  21. package/src/astro/CheckIn.astro +186 -0
  22. package/src/astro/DoorSignPage.astro +62 -0
  23. package/src/astro/EventCard.astro +81 -0
  24. package/src/astro/EventList.astro +83 -0
  25. package/src/astro/OptOutPage.astro +58 -0
  26. package/src/astro/PaymentReturn.astro +96 -0
  27. package/src/astro/TicketPass.astro +95 -0
  28. package/src/astro/checkout-endpoint.ts +11 -0
  29. package/src/astro/index.js +18 -0
  30. package/src/astro/lib/call.ts +185 -0
  31. package/src/astro/lib/checkout-form.ts +271 -0
  32. package/src/astro/lib/list.ts +99 -0
  33. package/src/astro/lib/opt-out.ts +49 -0
  34. package/src/astro/lib/pass.ts +35 -0
  35. package/src/astro/lib/payment.ts +73 -0
  36. package/src/astro/lib/promo.ts +162 -0
  37. package/src/astro/lib/questions.ts +107 -0
  38. package/src/astro/lib/receipt.ts +132 -0
  39. package/src/astro/lib/waitlist.ts +72 -0
  40. package/src/astro/lib/widget.ts +278 -0
  41. package/src/astro/promo-endpoint.ts +11 -0
  42. package/src/astro/virtual.d.ts +16 -0
  43. package/src/astro/waitlist-endpoint.ts +12 -0
  44. package/src/client/booking.ts +188 -0
  45. package/src/client/checkin.ts +260 -0
  46. package/src/client/payment.ts +76 -0
  47. package/src/client/receipt.ts +75 -0
  48. package/src/i18n/ar.ts +213 -0
  49. package/src/i18n/en.ts +219 -0
  50. package/src/i18n/index.ts +121 -0
package/src/i18n/en.ts ADDED
@@ -0,0 +1,219 @@
1
+ /**
2
+ * English, the source language of the Events UI kit (T102, EU-NFR-04). Every other language in this
3
+ * folder must have exactly these keys (a test checks), with the same `{placeholders}`. A key ending in
4
+ * `.one` / `.other` is a plural: other languages may add the `Intl.PluralRules` forms they need
5
+ * (`.zero`, `.two`, `.few`, `.many`). See `docs/i18n.md`.
6
+ */
7
+ export const en = {
8
+ "money.free": "Free",
9
+ "time.utc": "{time} UTC",
10
+
11
+ "list.heading": "Upcoming events",
12
+ "list.error": "Events are unavailable right now.",
13
+ "list.empty": "No upcoming events right now.",
14
+ "list.badge.cancelled": "Cancelled",
15
+ "list.badge.closed": "Sales closed",
16
+ "list.badge.paused": "Sales paused",
17
+ "list.badge.soldOut": "Sold out",
18
+ "list.priceFrom": "From {price}",
19
+
20
+ "widget.heading": "Book tickets",
21
+ "widget.unavailable": "Booking is not available for this event right now.",
22
+ "widget.turnstile": "Please complete the security check.",
23
+ "widget.date": "Date",
24
+ "widget.chooseDate": "Choose a date",
25
+ "widget.dateSoldOut": "{date} (sold out)",
26
+ "widget.promo.label": "Promo code",
27
+ "widget.promo.apply": "Apply code",
28
+ "widget.promo.update": "Update code",
29
+ "widget.tickets": "Tickets",
30
+ "widget.soldOut": "Sold out",
31
+ "widget.name": "Your name",
32
+ "widget.email": "Email",
33
+ "widget.questions": "About you",
34
+ "widget.total": "Total",
35
+ "widget.needsJs":
36
+ "This booking form uses a security check that needs JavaScript. Please turn JavaScript on to book, or contact the organiser.",
37
+ "widget.book": "Book",
38
+ "widget.field.occurrence": "Choose a date.",
39
+ "widget.field.promo": "Check the code, or leave it empty.",
40
+ "widget.field.tickets": "Choose at least one ticket.",
41
+ "widget.field.name": "Enter your name.",
42
+ "widget.field.email": "Enter a valid email address.",
43
+ "widget.error.BAD_REQUEST": "Please check the highlighted details.",
44
+ "widget.error.SOLD_OUT": "Sorry, there are not enough tickets left for that order.",
45
+ "widget.error.SALES_CLOSED": "Ticket sales for this event are closed.",
46
+ "widget.error.RATE_LIMITED": "Too many bookings from this connection. Please wait a few minutes and try again.",
47
+ "widget.error.TURNSTILE_FAILED": "The security check did not pass. Please try again.",
48
+ "widget.error.HOLD_EXPIRED": "Your hold on these tickets expired. Please start again.",
49
+ "widget.error.NOT_FOUND": "This event is not taking bookings.",
50
+ "widget.error.PROMO_INVALID": "That code is not valid for this event.",
51
+ "widget.error.PROMO_EXHAUSTED": "That code has been used up.",
52
+ "widget.error.PROMO_ORDER_TOO_LARGE":
53
+ "That code can't be used on an order this large. Order fewer ticket types at once.",
54
+ "widget.error.PROMO_UNAVAILABLE": "That code can't be used right now. Remove it to book without it.",
55
+ "widget.error.INTERNAL": "Something went wrong. Please try again.",
56
+
57
+ "waitlist.heading": "Join the waitlist",
58
+ "waitlist.intro": "If tickets come free, we email the first in line and hold the tickets for them for 24 hours.",
59
+ "waitlist.ticket": "Ticket",
60
+ "waitlist.anyTicket": "Any ticket",
61
+ "waitlist.button": "Join the waitlist",
62
+ "waitlist.joined":
63
+ "You are on the waitlist. If tickets come free we will email you, and hold them for you for 24 hours.",
64
+ "waitlist.BAD_REQUEST": "Please check your name, email, date and number of tickets.",
65
+ "waitlist.RATE_LIMITED": "Too many requests from this connection. Please wait a few minutes and try again.",
66
+ "waitlist.TURNSTILE_FAILED": "The security check did not pass. Please try again.",
67
+ "waitlist.NOT_FOUND": "This event is not taking a waitlist.",
68
+ "waitlist.INTERNAL": "Something went wrong. Please try again.",
69
+
70
+ "question.optional": "(optional)",
71
+ "question.choose": "Choose an answer",
72
+ "question.error.text": "Answer this question.",
73
+ "question.error.select": "Choose an answer.",
74
+ "question.error.checkbox": "Tick this box to continue.",
75
+
76
+ "promo.percent": "Code applied: {percent} off your order.",
77
+ "promo.fixed": "Code applied: {amount} off your order.",
78
+ "promo.unlocked": "Code applied: more tickets are now available.",
79
+ "promo.applied": "Code applied.",
80
+
81
+ "status.draft": "Started",
82
+ "status.held": "Held for you",
83
+ "status.awaiting_signature": "Waiting for signatures",
84
+ "status.awaiting_payment": "Waiting for payment",
85
+ "status.confirmed": "Confirmed",
86
+ "status.expired": "Expired",
87
+ "status.cancelled": "Cancelled",
88
+ "status.refunded": "Refunded",
89
+ "status.refunded_unavailable": "Refunded",
90
+
91
+ "booking.title": "Your booking",
92
+ "booking.status": "Booking status",
93
+ "booking.reference": "Reference",
94
+ "booking.heldUntil": "Your tickets are held until {time}.",
95
+ "booking.line": "{qty} × {name}",
96
+ "booking.total": "Total",
97
+ "booking.cancelUntil": "You can cancel until {time}.",
98
+ "booking.cancel": "Cancel booking",
99
+ "booking.cancelFailed": "We could not cancel this booking.",
100
+ "booking.offer.intro": "Tickets from the waitlist are held for you. Claim them on this device; the link works once.",
101
+ "booking.offer.button": "Claim my tickets",
102
+ "booking.open.intro": "Open your booking on this device. The link works once; after that this browser remembers it.",
103
+ "booking.open.button": "Open my booking",
104
+ "booking.passes": "Tickets",
105
+ "booking.missing": "We could not find that booking in this browser. Open the link from the device you booked with.",
106
+ "booking.empty": "Add your booking reference to view it.",
107
+ "booking.error.SOLD_OUT": "Sorry, those tickets are sold out.",
108
+ "booking.error.SALES_CLOSED": "Ticket sales for this event are closed.",
109
+ "booking.error.HOLD_EXPIRED": "Your hold on these tickets expired. Please start again.",
110
+ "booking.error.PAYMENT_FAILED": "Payment could not be started. Your tickets are held for a short time.",
111
+ "booking.error.CANCEL_NOT_ALLOWED": "This booking can no longer be cancelled online.",
112
+ "booking.error.BAD_REQUEST": "Please choose at least one ticket and fill in your name and email.",
113
+ "booking.error.LINK_INVALID":
114
+ "This booking link has expired or was already used. Open your booking on the device you booked with.",
115
+ "booking.error.OFFER_INVALID":
116
+ "This offer has ended or was already claimed. If you claimed it, your booking confirmation is on its way by email.",
117
+ "booking.error.INTERNAL": "Something went wrong. Please try again.",
118
+ "booking.waiver.signed": "Thank you: your waiver is signed.",
119
+ "booking.waiver.declined":
120
+ "The waiver was declined, so this ticket is not valid yet. You can sign it from the booking again.",
121
+ "booking.waiver.voided": "This waiver was withdrawn. Please sign it again from the booking.",
122
+ "booking.waiver.expired": "The signing link expired. Please sign the waiver again from the booking.",
123
+ "booking.waiver.failed": "We could not record that signature. Please try again from the booking.",
124
+
125
+ "pass.qr": "QR code of the check-in code",
126
+ "pass.code": "Check-in code",
127
+ "pass.status.pending": "Waiting for a signed waiver",
128
+ "pass.status.cancelled": "Cancelled",
129
+ "calendar.add": "Add to calendar",
130
+ "calendar.hint": "(.ics file)",
131
+
132
+ "payment.pending.heading": "Waiting for your payment",
133
+ "payment.pending.bodyUntil":
134
+ "If you have just paid, this page updates by itself within a minute and we will email you once the payment is confirmed. If you left the payment page, your tickets are held until {time} and you can pay now.",
135
+ "payment.pending.body":
136
+ "If you have just paid, this page updates by itself within a minute and we will email you once the payment is confirmed. If you left the payment page, your tickets are held for a short time and you can pay now.",
137
+ "payment.confirmed.heading": "Payment received",
138
+ "payment.confirmed.body": "Thank you: your payment is confirmed and so is your booking.",
139
+ "payment.expired.heading": "This booking expired",
140
+ "payment.expired.body":
141
+ "The hold ran out before a payment was confirmed. If you were charged, the payment is refunded automatically, or the booking is confirmed if the tickets are still available. Otherwise, please start again from the event page.",
142
+ "payment.cancelled.heading": "Booking cancelled",
143
+ "payment.cancelled.body": "This booking was cancelled. Any payment is refunded to the original payment method.",
144
+ "payment.refunded.heading": "Payment refunded",
145
+ "payment.refunded.body": "Your payment was refunded to the original payment method.",
146
+ "payment.refunded_unavailable.heading": "Payment refunded: tickets no longer available",
147
+ "payment.refunded_unavailable.body":
148
+ "Your payment arrived after these tickets were no longer available, so it has been refunded in full. No tickets were issued.",
149
+ "payment.checking": "Checking for your payment…",
150
+ "payment.slow":
151
+ "We have not heard back from the payment provider yet. If you paid, we will email you as soon as it is confirmed: you do not need to wait on this page.",
152
+ "payment.payNow": "Pay now",
153
+ "payment.checkAgain": "Check again",
154
+ "payment.updated": "Your booking has been updated. Reloading.",
155
+
156
+ "door.title": "Sign the waiver",
157
+ "door.signed": "The waiver is already signed and is now on record. Check the attendee in again.",
158
+ "door.opening": "Opening the signing page…",
159
+ "door.error.ESIGN_NOT_CONFIGURED": "Signing is not set up on this site.",
160
+ "door.error.INTENT_INVALID": "This signing link is not valid. Open it again from the check-in page.",
161
+ "door.error.TOKEN_EXPIRED": "This signing link has expired. Open it again from the check-in page.",
162
+ "door.error.TOKEN_REPLAYED": "This signing link was already used. Open it again from the check-in page.",
163
+ "door.error.SIGNING_UNAVAILABLE": "This waiver cannot be signed here. It may already be signed.",
164
+ "door.error.INTERNAL": "Signing could not be started. Open the link again from the check-in page.",
165
+
166
+ "checkin.title": "Check in",
167
+ "checkin.event": "Event",
168
+ "checkin.anyEvent": "Any event",
169
+ "checkin.code": "Check-in code",
170
+ "checkin.submit": "Check in",
171
+ "checkin.camera": "Scan with camera",
172
+ "checkin.stopCamera": "Stop camera",
173
+ "checkin.noCamera": "This browser cannot scan QR codes: type the code from the ticket instead.",
174
+ "checkin.needsJs": "This screen needs JavaScript. Check people in from the Attendees page in the admin.",
175
+ "checkin.signLink": "Open the signing page",
176
+ "checkin.attendee": "This attendee",
177
+ "checkin.notSignedIn.title": "Not signed in",
178
+ "checkin.notSignedIn.message": "Sign in to the admin on this device, then try again.",
179
+ "checkin.unavailable.title": "Check-in screen not available",
180
+ "checkin.unavailable.message": "The check-in screen needs Events Pro. Use the Attendees page in the admin instead.",
181
+ "checkin.failed.title": "Something went wrong",
182
+ "checkin.failed.message": "The code was not checked. Try again. Use the Attendees page in the admin instead.",
183
+ "checkin.licence.title": "Events Pro licence needed",
184
+ "checkin.licence.message":
185
+ "This site's Events Pro licence is not valid, so the check-in screen is off. Use the Attendees page in the admin instead.",
186
+ "checkin.enterCode.title": "Enter a code",
187
+ "checkin.enterCode.message": "Type or scan a check-in code.",
188
+ "checkin.checkedIn.title": "Checked in: {name}",
189
+ "checkin.checkedIn.at": "At {time}.",
190
+ "checkin.checkedIn.done": "Done.",
191
+ "checkin.already.title": "Already checked in",
192
+ "checkin.already.messageAt": "{name} was first checked in at {time}. Do not let the ticket in twice.",
193
+ "checkin.already.message": "{name} was first checked in. Do not let the ticket in twice.",
194
+ "checkin.notFound.title": "Code not found",
195
+ "checkin.notFound.message":
196
+ "No attendee has that code for this event. Check the event, or type the code from the ticket.",
197
+ "checkin.notConfirmed.title": "Cannot check in",
198
+ "checkin.notConfirmed.message": "The booking is not confirmed (status: {status}), so this ticket is not valid.",
199
+ "checkin.waiver.title": "Waiver not signed",
200
+ "checkin.waiver.messageLink":
201
+ "{name} has not signed the waiver yet. Open the signing page so they can sign on this device, then check them in again.",
202
+ "checkin.waiver.message": "{name} has not signed the waiver yet. Check them in once they have signed.",
203
+ "checkin.invalid.title": "Cannot check in",
204
+ "checkin.invalid.message": "This ticket is not valid.",
205
+ "checkin.cameraFailed.title": "Camera not available",
206
+ "checkin.cameraFailed.message": "Allow the camera, or type the code instead.",
207
+
208
+ "optOut.title": "Email preferences",
209
+ "optOut.question": "Stop reminders and event updates about booking {ref} at this address?",
210
+ "optOut.button": "Stop these emails",
211
+ "optOut.done":
212
+ "Done. You will get no more reminders or updates about this booking at this address. If the event is cancelled, we will still tell you.",
213
+ "optOut.invalid": "This link is not valid any more. Use the link in the most recent email about your booking.",
214
+
215
+ "booking.lines.one": "{count} ticket",
216
+ "booking.lines.other": "{count} tickets",
217
+ };
218
+
219
+ export type MessageKey = keyof typeof en;
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Translations of the Events UI kit (T102, EU-NFR-04). The UI half only: the sandboxed core answers with
3
+ * codes (`SOLD_OUT`, `held`, ...) and never ships a message table (R51, R58). Components take a `locale`
4
+ * (prop, else `Astro.currentLocale`, the page's locale when the site configures Astro i18n, else `en-GB`);
5
+ * its language picks the table here, falling back to English, and its direction sets `dir` on each
6
+ * component. The E-sign kit has its own copy of this module (packages never import each other, R35).
7
+ *
8
+ * Client scripts carry no text: the page renders the messages a script needs into a `data-messages`
9
+ * attribute (`clientMessages`). Adding a language: `docs/i18n.md`.
10
+ */
11
+ import { ar } from "./ar";
12
+ import { en, type MessageKey } from "./en";
13
+
14
+ export type { MessageKey };
15
+
16
+ /** Extra plural forms a language may need beyond English's `one` and `other`. */
17
+ type PluralForm = "zero" | "two" | "few" | "many";
18
+
19
+ /** A language's table: every English key, plus any extra plural forms. */
20
+ export type Messages = { [K in MessageKey]: string } & { [extra: `${string}.${PluralForm}`]: string };
21
+
22
+ /** A key with plural forms, named without its `.one` / `.other` suffix. */
23
+ export type PluralKey = MessageKey extends infer K ? (K extends `${infer Base}.other` ? Base : never) : never;
24
+
25
+ export type Vars = Record<string, string | number>;
26
+
27
+ /** The languages the kit ships, by BCP 47 language subtag. */
28
+ export const LANGUAGES: Record<string, Messages> = { en, ar };
29
+
30
+ /** Languages written right to left (whether or not a table ships for them yet). */
31
+ const RTL = new Set(["ar", "dv", "fa", "he", "ku", "ps", "sd", "ug", "ur", "yi"]);
32
+
33
+ /** The table's language for a locale (`ar-EG` -> `ar`); English when there is no table for it. */
34
+ export function languageOf(locale?: string | null): string {
35
+ const base = (locale ?? "").trim().toLowerCase().split(/[-_]/)[0] ?? "";
36
+ return Object.hasOwn(LANGUAGES, base) ? base : "en";
37
+ }
38
+
39
+ /** The writing direction of what a locale's page shows (English text for an unknown language). */
40
+ export function directionOf(locale?: string | null): "ltr" | "rtl" {
41
+ return RTL.has(languageOf(locale)) ? "rtl" : "ltr";
42
+ }
43
+
44
+ /** `{name}` placeholders filled from `vars`; unknown ones are left as they are. */
45
+ export function fill(text: string, vars?: Vars): string {
46
+ return vars ? text.replace(/\{(\w+)\}/g, (whole, name: string) => (name in vars ? String(vars[name]) : whole)) : text;
47
+ }
48
+
49
+ export interface Translator {
50
+ /** The table's language (`en`, `ar`): the value for `lang` attributes. */
51
+ lang: string;
52
+ dir: "ltr" | "rtl";
53
+ t(key: MessageKey, vars?: Vars): string;
54
+ /** The plural form of `key` for `count` by the language's rules (`count` is also a placeholder). */
55
+ plural(key: PluralKey, count: number, vars?: Vars): string;
56
+ }
57
+
58
+ const tables = LANGUAGES as Record<string, Record<string, string>>;
59
+
60
+ export function translator(locale?: string | null): Translator {
61
+ const lang = languageOf(locale);
62
+ const table = tables[lang] ?? tables.en;
63
+ const lookup = (key: string) => table?.[key] ?? tables.en?.[key] ?? key;
64
+ const rules = new Intl.PluralRules(lang);
65
+ return {
66
+ lang,
67
+ dir: directionOf(lang),
68
+ t: (key, vars) => fill(lookup(key), vars),
69
+ plural: (key, count, vars) => {
70
+ const form = `${key}.${rules.select(count)}`;
71
+ const text = table && Object.hasOwn(table, form) ? (table[form] as string) : lookup(`${key}.other`);
72
+ return fill(text, { count: new Intl.NumberFormat(lang).format(count), ...vars });
73
+ },
74
+ };
75
+ }
76
+
77
+ /** One message in a locale's language (English fallback). */
78
+ export function t(locale: string | null | undefined, key: MessageKey, vars?: Vars): string {
79
+ return translator(locale).t(key, vars);
80
+ }
81
+
82
+ /**
83
+ * The messages under `prefix` (the prefix dropped), plus every key under each of `more` (kept whole), for a
84
+ * client script's `data-messages` attribute.
85
+ */
86
+ export function clientMessages(
87
+ locale: string | null | undefined,
88
+ prefix: string,
89
+ ...more: string[]
90
+ ): Record<string, string> {
91
+ const table = tables[languageOf(locale)] ?? {};
92
+ const out: Record<string, string> = {};
93
+ for (const key of Object.keys(en)) {
94
+ const text = table[key] ?? (en as Record<string, string>)[key] ?? "";
95
+ if (key.startsWith(prefix)) out[key.slice(prefix.length)] = text;
96
+ else if (more.some((p) => key.startsWith(p))) out[key] = text;
97
+ }
98
+ return out;
99
+ }
100
+
101
+ /** The first locale given (a prop, `Astro.currentLocale`, the integration's option), else `en-GB`. */
102
+ export function pickLocale(...candidates: Array<string | null | undefined>): string {
103
+ return candidates.find((c): c is string => typeof c === "string" && c.trim() !== "") ?? "en-GB";
104
+ }
105
+
106
+ /**
107
+ * A message as text runs and the `{placeholders}` left in it, so a component can put an element (a link,
108
+ * `<strong>`) where the language puts the placeholder: `{segments(t(key)).map((s) => s.slot === "name" ? <b/> : s.text)}`.
109
+ */
110
+ export function segments(text: string): Array<{ text: string; slot?: string }> {
111
+ return text
112
+ .split(/(\{\w+\})/)
113
+ .filter((part) => part !== "")
114
+ .map((part) => (/^\{\w+\}$/.test(part) ? { text: "", slot: part.slice(1, -1) } : { text: part }));
115
+ }
116
+
117
+ /** A message split around one `{placeholder}`, so a component can put an element (a `<time>`) there. */
118
+ export function around(text: string, name: string): [string, string] {
119
+ const at = text.indexOf(`{${name}}`);
120
+ return at === -1 ? [text, ""] : [text.slice(0, at), text.slice(at + name.length + 2)];
121
+ }