@msm-platform/customer-react 0.0.0-stage → 0.1.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.
package/dist/index.js ADDED
@@ -0,0 +1,1028 @@
1
+ "use client";
2
+ import { createContext as e, useCallback as t, useContext as n, useEffect as r, useId as i, useMemo as a, useRef as o, useState as s } from "react";
3
+ import { createCustomerClient as c, isCustomerApiError as l } from "@msm-platform/customer-sdk";
4
+ import { Fragment as u, jsx as d, jsxs as f } from "react/jsx-runtime";
5
+ import { Metadata as p, getCountries as m, getCountryCallingCode as h, parsePhoneNumberFromString as g, validatePhoneNumberLength as _ } from "libphonenumber-js";
6
+ import v from "libphonenumber-js/min/metadata";
7
+ // src/client.ts
8
+ var y = (e, t) => {
9
+ let n = new Request(e, t);
10
+ return n.headers.set("X-MSM-BFF", "1"), fetch(n);
11
+ };
12
+ function b(e, t, n) {
13
+ return y(`${e}${t}`, {
14
+ method: "POST",
15
+ headers: { "content-type": "application/json" },
16
+ body: JSON.stringify(n ?? {})
17
+ });
18
+ }
19
+ function x(e, t) {
20
+ let n = c({ baseUrl: `${e}/engine` });
21
+ return n.use({
22
+ onRequest({ request: e }) {
23
+ return e.headers.set("X-MSM-BFF", "1"), e;
24
+ },
25
+ onResponse({ response: e }) {
26
+ e.status === 401 && t();
27
+ }
28
+ }), n;
29
+ }
30
+ // src/context.ts
31
+ var S = e(null);
32
+ function C() {
33
+ let e = n(S);
34
+ if (!e) throw Error("usePortal needs MsmCustomer.");
35
+ return e;
36
+ }
37
+ // src/i18n.ts
38
+ var w = {
39
+ "app.loading": "Loading…",
40
+ "app.loadFailed": "Something went wrong loading this page. Try again.",
41
+ "app.retry": "Try again",
42
+ "app.signedOut": "You were signed out because your session ended. Sign in again.",
43
+ "app.signedOutEverywhere": "You were signed out on every device.",
44
+ "nav.label": "My account",
45
+ "nav.bookings": "Bookings",
46
+ "nav.passes": "Passes",
47
+ "nav.details": "My details",
48
+ "nav.signOut": "Sign out",
49
+ "signIn.heading": "Sign in",
50
+ "signIn.intro": "We'll text a one-time code to your phone.",
51
+ "signIn.toRegister": "New here? Create an account",
52
+ "register.heading": "Create an account",
53
+ "register.intro": "Enter your name and phone. We'll text you a code.",
54
+ "register.name": "Your name",
55
+ "register.toSignIn": "Already have an account? Sign in",
56
+ "signIn.phone": "Phone number",
57
+ "signIn.codeSent": "Enter the code we sent to {phone}.",
58
+ "signIn.code": "Verification code",
59
+ "signIn.sendCode": "Send code",
60
+ "signIn.submit": "Sign in",
61
+ "register.submit": "Create account",
62
+ "signIn.wait": "Please wait…",
63
+ "signIn.differentNumber": "Use a different number",
64
+ "signIn.error.tooMany": "Too many codes requested. Try again in about {wait}.",
65
+ "signIn.error.tooManyLater": "Too many codes requested. Try again later.",
66
+ "signIn.error.paused": "Sign-in codes are paused for now. Try again in about {wait}.",
67
+ "signIn.error.pausedLater": "Sign-in codes are paused for now. Try again later.",
68
+ "signIn.error.destination": "This number can't receive sign-in codes.",
69
+ "signIn.error.badCode": "That code is incorrect or has expired, or this number has no account yet.",
70
+ "register.error.badCode": "That code is incorrect or has expired, or this number already has an account.",
71
+ "signIn.error.invalid": "Check the phone number and try again.",
72
+ "signIn.error.refused": "This number can't sign in here.",
73
+ "signIn.error.unreachable": "The sign-in service is unreachable. Try again shortly.",
74
+ "signIn.error.failed": "Sign-in failed. Try again shortly.",
75
+ "signIn.error.botCheck": "We couldn't confirm you're a person. Complete the check and try again.",
76
+ "signIn.error.botCheckUnavailable": "The security check is unavailable. Try again shortly.",
77
+ "signIn.error.notConfigured": "Sign-in isn't set up on this site yet.",
78
+ "wait.seconds.one": "{count} second",
79
+ "wait.seconds.other": "{count} seconds",
80
+ "wait.minutes.one": "{count} minute",
81
+ "wait.minutes.other": "{count} minutes",
82
+ "wait.hours.one": "{count} hour",
83
+ "wait.hours.other": "{count} hours",
84
+ "bookings.heading": "Bookings",
85
+ "bookings.period": "Which bookings",
86
+ "bookings.upcoming": "Upcoming",
87
+ "bookings.past": "Past",
88
+ "bookings.emptyUpcoming": "You have no upcoming bookings.",
89
+ "bookings.emptyPast": "You have no past bookings.",
90
+ "bookings.more": "Show more",
91
+ "bookings.when": "{start} – {end}",
92
+ "bookings.cancelled": "Cancelled",
93
+ "bookings.cancelledLate": "Cancelled late",
94
+ "bookings.attended": "Attended",
95
+ "bookings.noShow": "Missed",
96
+ "bookings.lateFrom": "Late cancellation from {time}",
97
+ "bookings.started": "This booking can no longer be cancelled because the event has started.",
98
+ "bookings.cancel": "Cancel booking",
99
+ "bookings.confirmHeading": "Cancel this booking?",
100
+ "bookings.confirmLate": "This is a late cancellation: the cancellation window has closed.",
101
+ "bookings.confirmCredit": "The pass credit you used for this booking stays spent.",
102
+ "bookings.confirm": "Yes, cancel",
103
+ "bookings.keep": "Keep booking",
104
+ "bookings.cancelling": "Cancelling…",
105
+ "bookings.doneOnTime": "Your booking is cancelled.",
106
+ "bookings.doneLate": "Your booking is cancelled. It counts as a late cancellation.",
107
+ "bookings.cancelFailed": "The booking could not be cancelled. Try again.",
108
+ "bookings.gone": "This booking no longer exists.",
109
+ "passes.heading": "Memberships and passes",
110
+ "passes.empty": "You have no memberships or passes.",
111
+ "passes.unlimited": "Unlimited",
112
+ "passes.credits": "Credits left: {remaining} of {total}",
113
+ "passes.validFrom": "Valid from {date}",
114
+ "passes.validRange": "Valid {from} – {until}",
115
+ "passes.expired": "Expired",
116
+ "details.heading": "My details",
117
+ "details.name": "Name",
118
+ "details.phone": "Phone",
119
+ "details.email": "Email",
120
+ "details.none": "Not set",
121
+ "details.readOnly": "Ask the business to change your phone or email.",
122
+ "details.save": "Save",
123
+ "details.saving": "Saving…",
124
+ "details.saved": "Your name is saved.",
125
+ "details.saveFailed": "Your name could not be saved. Try again.",
126
+ "details.signOutEverywhere": "Sign out everywhere",
127
+ "details.signOutEverywhereHint": "Ends your sessions on every phone and computer, including this one.",
128
+ "details.signOutEverywhereFailed": "Could not sign out everywhere. Try again."
129
+ }, T = "en-GB", E = w;
130
+ function D(e, t = {}) {
131
+ return E[e].replace(/\{(\w+)\}/g, (e, n) => {
132
+ let r = t[n];
133
+ return r === void 0 ? e : typeof r == "number" ? A(r) : r;
134
+ });
135
+ }
136
+ var O = new Intl.PluralRules(T);
137
+ function k(e, t, n = {}) {
138
+ let r = `${e}.${O.select(t)}`;
139
+ return D(r in E ? r : `${e}.other`, {
140
+ count: t,
141
+ ...n
142
+ });
143
+ }
144
+ function A(e) {
145
+ return new Intl.NumberFormat(T).format(e);
146
+ }
147
+ function j(e, t) {
148
+ return new Intl.DateTimeFormat(T, {
149
+ dateStyle: "medium",
150
+ timeStyle: "short",
151
+ ...t && { timeZone: t }
152
+ }).format(new Date(e));
153
+ }
154
+ function M(e, t) {
155
+ return new Intl.DateTimeFormat(T, {
156
+ timeStyle: "short",
157
+ ...t && { timeZone: t }
158
+ }).format(new Date(e));
159
+ }
160
+ function N(e, t) {
161
+ return new Intl.DateTimeFormat(T, {
162
+ dateStyle: "medium",
163
+ ...t && { timeZone: t }
164
+ }).format(new Date(e));
165
+ }
166
+ function ee(e, t, n) {
167
+ let r = N(e, n) === N(t, n);
168
+ return D("bookings.when", {
169
+ start: j(e, n),
170
+ end: r ? M(t, n) : j(t, n)
171
+ });
172
+ }
173
+ function P(e) {
174
+ if (e < 60) return k("wait.seconds", e);
175
+ let t = Math.round(e / 60);
176
+ return t < 60 ? k("wait.minutes", t) : k("wait.hours", Math.round(e / 3600));
177
+ }
178
+ // src/layout.tsx
179
+ function F({ brand: e }) {
180
+ return e ? /* @__PURE__ */ f("div", {
181
+ className: "cp-brand",
182
+ children: [e.logo && /* @__PURE__ */ d("img", {
183
+ src: e.logo,
184
+ alt: ""
185
+ }), /* @__PURE__ */ d("span", { children: e.name })]
186
+ }) : null;
187
+ }
188
+ var te = [
189
+ ["bookings", "nav.bookings"],
190
+ ["passes", "nav.passes"],
191
+ ["details", "nav.details"]
192
+ ];
193
+ function I(e) {
194
+ return /* @__PURE__ */ f("div", {
195
+ className: "cp-shell",
196
+ children: [
197
+ /* @__PURE__ */ f("header", {
198
+ className: "cp-header",
199
+ children: [/* @__PURE__ */ d(F, { brand: e.brand }), /* @__PURE__ */ d("button", {
200
+ type: "button",
201
+ className: "cp-link",
202
+ onClick: e.onSignOut,
203
+ children: D("nav.signOut")
204
+ })]
205
+ }),
206
+ /* @__PURE__ */ d("nav", {
207
+ className: "cp-nav",
208
+ "aria-label": D("nav.label"),
209
+ children: te.map(([t, n]) => /* @__PURE__ */ d("button", {
210
+ type: "button",
211
+ "aria-current": e.screen === t ? "page" : void 0,
212
+ onClick: () => e.onNavigate(t),
213
+ children: D(n)
214
+ }, t))
215
+ }),
216
+ /* @__PURE__ */ d("main", {
217
+ className: "cp-main",
218
+ children: e.children
219
+ })
220
+ ]
221
+ });
222
+ }
223
+ // src/cancellation.ts
224
+ function L(e, t) {
225
+ if (e.status === "cancelled") return "cancelled";
226
+ let n = t.getTime();
227
+ return !e.cancellableUntil || n >= Date.parse(e.cancellableUntil) ? "closed" : e.lateCancellationFrom && n >= Date.parse(e.lateCancellationFrom) ? "late" : "open";
228
+ }
229
+ // src/screens/bookings.tsx
230
+ var R = "/web/businesses/{businessId}/bookings/{bookingId}/cancel";
231
+ function ne() {
232
+ let { client: e } = C(), [n, i] = s("upcoming"), [a, o] = s(), [c, l] = s(null), [u, p] = s(!1), [m, h] = s(), g = t(async (t) => {
233
+ p(!1);
234
+ try {
235
+ let { data: r } = await e.GET("/web/me/bookings", { params: { query: {
236
+ period: n,
237
+ ...t && { cursor: t }
238
+ } } });
239
+ if (!r) return;
240
+ o((e) => t ? [...e ?? [], ...r.items] : r.items), l(r.nextCursor);
241
+ } catch {
242
+ p(!0);
243
+ }
244
+ }, [e, n]);
245
+ return r(() => {
246
+ o(void 0), h(void 0), g();
247
+ }, [g]), /* @__PURE__ */ f("section", {
248
+ className: "cp-screen",
249
+ children: [
250
+ /* @__PURE__ */ d("h1", { children: D("bookings.heading") }),
251
+ /* @__PURE__ */ d("fieldset", {
252
+ className: "cp-tabs",
253
+ "aria-label": D("bookings.period"),
254
+ children: ["upcoming", "past"].map((e) => /* @__PURE__ */ d("button", {
255
+ type: "button",
256
+ "aria-pressed": n === e,
257
+ onClick: () => i(e),
258
+ children: D(e === "upcoming" ? "bookings.upcoming" : "bookings.past")
259
+ }, e))
260
+ }),
261
+ m && /* @__PURE__ */ d("p", {
262
+ role: "status",
263
+ className: "cp-notice",
264
+ children: D(m)
265
+ }),
266
+ u ? /* @__PURE__ */ d(z, { onRetry: () => g() }) : a ? a.length === 0 ? /* @__PURE__ */ d("p", {
267
+ className: "cp-empty",
268
+ children: D(n === "upcoming" ? "bookings.emptyUpcoming" : "bookings.emptyPast")
269
+ }) : /* @__PURE__ */ d("ul", {
270
+ className: "cp-list",
271
+ children: a.map((e) => /* @__PURE__ */ d(re, {
272
+ booking: e,
273
+ onCancelled: (e, t) => {
274
+ o((t) => t?.map((t) => t.id === e.id ? e : t)), h(t ? "bookings.doneLate" : "bookings.doneOnTime");
275
+ }
276
+ }, e.id))
277
+ }) : /* @__PURE__ */ d("p", {
278
+ role: "status",
279
+ children: D("app.loading")
280
+ }),
281
+ a && c && !u && /* @__PURE__ */ d("button", {
282
+ type: "button",
283
+ className: "cp-secondary",
284
+ onClick: () => g(c),
285
+ children: D("bookings.more")
286
+ })
287
+ ]
288
+ });
289
+ }
290
+ function z({ onRetry: e }) {
291
+ return /* @__PURE__ */ f("div", {
292
+ role: "alert",
293
+ className: "cp-error",
294
+ children: [/* @__PURE__ */ d("p", { children: D("app.loadFailed") }), /* @__PURE__ */ d("button", {
295
+ type: "button",
296
+ className: "cp-secondary",
297
+ onClick: e,
298
+ children: D("app.retry")
299
+ })]
300
+ });
301
+ }
302
+ function re(e) {
303
+ let { client: t, businesses: n } = C(), { booking: r } = e, i = n.get(r.businessId)?.timezone, [a, o] = s(!1), [c, u] = s(!1), [p, m] = s(), [h, g] = s(!1), _ = h ? "closed" : L(r, /* @__PURE__ */ new Date()), v = r.creditMembershipId !== null && r.creditRestoredAt === null;
304
+ async function y() {
305
+ u(!0), m(void 0);
306
+ try {
307
+ let { data: n } = await t.POST(R, { params: { path: {
308
+ businessId: r.businessId,
309
+ bookingId: r.id
310
+ } } });
311
+ n && (o(!1), e.onCancelled({
312
+ ...r,
313
+ ...n,
314
+ cancellableUntil: null,
315
+ lateCancellationFrom: null
316
+ }, n.cancelledLate === !0));
317
+ } catch (e) {
318
+ if (l(e, "post", R)) {
319
+ if (e.code === "EventStarted") {
320
+ g(!0), o(!1);
321
+ return;
322
+ }
323
+ if (e.code === "BookingNotFound") {
324
+ m("bookings.gone");
325
+ return;
326
+ }
327
+ }
328
+ m("bookings.cancelFailed");
329
+ } finally {
330
+ u(!1);
331
+ }
332
+ }
333
+ return /* @__PURE__ */ f("li", {
334
+ className: "cp-card",
335
+ "data-state": _,
336
+ children: [
337
+ /* @__PURE__ */ f("div", {
338
+ className: "cp-card-head",
339
+ children: [/* @__PURE__ */ d("h2", { children: r.event.eventTypeName }), r.status === "cancelled" ? /* @__PURE__ */ d("span", {
340
+ className: "cp-badge",
341
+ children: D(r.cancelledLate ? "bookings.cancelledLate" : "bookings.cancelled")
342
+ }) : r.attendance ? /* @__PURE__ */ d("span", {
343
+ className: "cp-badge",
344
+ children: D(r.attendance === "attended" ? "bookings.attended" : "bookings.noShow")
345
+ }) : null]
346
+ }),
347
+ /* @__PURE__ */ d("p", { children: r.businessName }),
348
+ /* @__PURE__ */ d("p", { children: ee(r.event.startsAt, r.event.endsAt, i) }),
349
+ (_ === "open" || _ === "late") && r.lateCancellationFrom && /* @__PURE__ */ d("p", {
350
+ className: "cp-hint",
351
+ children: D("bookings.lateFrom", { time: j(r.lateCancellationFrom, i) })
352
+ }),
353
+ _ === "closed" && r.status === "confirmed" && !r.attendance && /* @__PURE__ */ d("p", {
354
+ className: "cp-hint",
355
+ children: D("bookings.started")
356
+ }),
357
+ p && /* @__PURE__ */ d("p", {
358
+ role: "alert",
359
+ children: D(p)
360
+ }),
361
+ (_ === "open" || _ === "late") && (a ? /* @__PURE__ */ f("fieldset", {
362
+ className: "cp-confirm",
363
+ children: [
364
+ /* @__PURE__ */ d("legend", { children: D("bookings.confirmHeading") }),
365
+ _ === "late" && /* @__PURE__ */ d("p", {
366
+ className: "cp-warning",
367
+ children: D("bookings.confirmLate")
368
+ }),
369
+ _ === "late" && v && /* @__PURE__ */ d("p", {
370
+ className: "cp-warning",
371
+ children: D("bookings.confirmCredit")
372
+ }),
373
+ /* @__PURE__ */ f("div", {
374
+ className: "cp-actions",
375
+ children: [/* @__PURE__ */ d("button", {
376
+ type: "button",
377
+ disabled: c,
378
+ onClick: y,
379
+ children: D(c ? "bookings.cancelling" : "bookings.confirm")
380
+ }), /* @__PURE__ */ d("button", {
381
+ type: "button",
382
+ className: "cp-secondary",
383
+ disabled: c,
384
+ onClick: () => o(!1),
385
+ children: D("bookings.keep")
386
+ })]
387
+ })
388
+ ]
389
+ }) : /* @__PURE__ */ d("button", {
390
+ type: "button",
391
+ className: "cp-secondary",
392
+ onClick: () => o(!0),
393
+ children: D("bookings.cancel")
394
+ }))
395
+ ]
396
+ });
397
+ }
398
+ // src/screens/details.tsx
399
+ function B() {
400
+ let { client: e, signOut: n } = C(), [i, a] = s(), [o, c] = s(""), [l, p] = s(!1), [m, h] = s(!1), [g, _] = s(), v = t(async () => {
401
+ p(!1);
402
+ try {
403
+ let { data: t } = await e.GET("/web/me");
404
+ t && (a(t), c(t.name));
405
+ } catch {
406
+ p(!0);
407
+ }
408
+ }, [e]);
409
+ r(() => {
410
+ v();
411
+ }, [v]);
412
+ async function y(t) {
413
+ t.preventDefault(), h(!0), _(void 0);
414
+ try {
415
+ await e.PATCH("/web/me", { body: { name: o.trim() } }), a((e) => e && {
416
+ ...e,
417
+ name: o.trim()
418
+ }), c(o.trim()), _({
419
+ key: "details.saved",
420
+ alert: !1
421
+ });
422
+ } catch {
423
+ _({
424
+ key: "details.saveFailed",
425
+ alert: !0
426
+ });
427
+ } finally {
428
+ h(!1);
429
+ }
430
+ }
431
+ async function b() {
432
+ h(!0), _(void 0);
433
+ try {
434
+ await e.DELETE("/web/me/sessions"), await n("app.signedOutEverywhere");
435
+ } catch {
436
+ _({
437
+ key: "details.signOutEverywhereFailed",
438
+ alert: !0
439
+ }), h(!1);
440
+ }
441
+ }
442
+ return /* @__PURE__ */ f("section", {
443
+ className: "cp-screen",
444
+ children: [/* @__PURE__ */ d("h1", { children: D("details.heading") }), l ? /* @__PURE__ */ d(z, { onRetry: v }) : i ? /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ f("form", {
445
+ className: "cp-card cp-form",
446
+ onSubmit: y,
447
+ "aria-busy": m,
448
+ children: [
449
+ /* @__PURE__ */ f("label", { children: [D("details.name"), /* @__PURE__ */ d("input", {
450
+ value: o,
451
+ onChange: (e) => c(e.target.value),
452
+ autoComplete: "name",
453
+ maxLength: 200,
454
+ required: !0
455
+ })] }),
456
+ /* @__PURE__ */ f("dl", { children: [
457
+ /* @__PURE__ */ d("dt", { children: D("details.phone") }),
458
+ /* @__PURE__ */ d("dd", { children: i.phone ?? D("details.none") }),
459
+ /* @__PURE__ */ d("dt", { children: D("details.email") }),
460
+ /* @__PURE__ */ d("dd", { children: i.email ?? D("details.none") })
461
+ ] }),
462
+ /* @__PURE__ */ d("p", {
463
+ className: "cp-hint",
464
+ children: D("details.readOnly")
465
+ }),
466
+ g && /* @__PURE__ */ d("p", {
467
+ role: g.alert ? "alert" : "status",
468
+ children: D(g.key)
469
+ }),
470
+ /* @__PURE__ */ d("button", {
471
+ type: "submit",
472
+ disabled: m || !o.trim() || o.trim() === i.name,
473
+ children: D(m ? "details.saving" : "details.save")
474
+ })
475
+ ]
476
+ }), /* @__PURE__ */ f("div", {
477
+ className: "cp-card cp-form",
478
+ children: [/* @__PURE__ */ d("p", {
479
+ className: "cp-hint",
480
+ children: D("details.signOutEverywhereHint")
481
+ }), /* @__PURE__ */ d("button", {
482
+ type: "button",
483
+ className: "cp-secondary",
484
+ disabled: m,
485
+ onClick: b,
486
+ children: D("details.signOutEverywhere")
487
+ })]
488
+ })] }) : /* @__PURE__ */ d("p", {
489
+ role: "status",
490
+ children: D("app.loading")
491
+ })]
492
+ });
493
+ }
494
+ // src/screens/passes.tsx
495
+ function V() {
496
+ let { client: e, businesses: n } = C(), [i, a] = s(), [o, c] = s(!1), l = t(async () => {
497
+ c(!1);
498
+ try {
499
+ let { data: t } = await e.GET("/web/me/memberships");
500
+ t && a(t);
501
+ } catch {
502
+ c(!0);
503
+ }
504
+ }, [e]);
505
+ return r(() => {
506
+ l();
507
+ }, [l]), /* @__PURE__ */ f("section", {
508
+ className: "cp-screen",
509
+ children: [/* @__PURE__ */ d("h1", { children: D("passes.heading") }), o ? /* @__PURE__ */ d(z, { onRetry: l }) : i ? i.length === 0 ? /* @__PURE__ */ d("p", {
510
+ className: "cp-empty",
511
+ children: D("passes.empty")
512
+ }) : /* @__PURE__ */ d("ul", {
513
+ className: "cp-list",
514
+ children: i.map((e) => {
515
+ let t = n.get(e.businessId), r = t?.timezone, i = e.validUntil !== null && Date.parse(e.validUntil) <= Date.now();
516
+ return /* @__PURE__ */ f("li", {
517
+ className: "cp-card",
518
+ children: [
519
+ /* @__PURE__ */ f("div", {
520
+ className: "cp-card-head",
521
+ children: [/* @__PURE__ */ d("h2", { children: e.displayName }), i && /* @__PURE__ */ d("span", {
522
+ className: "cp-badge",
523
+ children: D("passes.expired")
524
+ })]
525
+ }),
526
+ t && /* @__PURE__ */ d("p", { children: t.displayName }),
527
+ /* @__PURE__ */ d("p", {
528
+ className: "cp-credits",
529
+ children: e.creditsRemaining === null || e.creditsTotal === null ? D("passes.unlimited") : D("passes.credits", {
530
+ remaining: e.creditsRemaining,
531
+ total: e.creditsTotal
532
+ })
533
+ }),
534
+ /* @__PURE__ */ d("p", {
535
+ className: "cp-hint",
536
+ children: e.validUntil ? D("passes.validRange", {
537
+ from: N(e.validFrom, r),
538
+ until: N(e.validUntil, r)
539
+ }) : D("passes.validFrom", { date: N(e.validFrom, r) })
540
+ })
541
+ ]
542
+ }, e.id);
543
+ })
544
+ }) : /* @__PURE__ */ d("p", {
545
+ role: "status",
546
+ children: D("app.loading")
547
+ })]
548
+ });
549
+ }
550
+ // ../ui/dist/index.js
551
+ var ie = new Intl.DisplayNames(["en"], { type: "region" }), H = (e) => e.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase().trim(), U = m().map((e) => ({
552
+ code: e,
553
+ name: ie.of(e) ?? e,
554
+ callingCode: h(e),
555
+ flag: String.fromCodePoint(...[...e].map((e) => 127397 + e.charCodeAt(0)))
556
+ })).sort((e, t) => e.name.localeCompare(t.name)), ae = new Map(U.map((e) => [e.code, e])), W = (e) => ae.get(e);
557
+ function G(e) {
558
+ let t = i(), n = o(null), a = o(null), c = o(null), [l, u] = s(""), p = e.search(l), m = () => n.current?.close(), h = (t) => {
559
+ m(), e.onPick(t);
560
+ };
561
+ return r(() => {
562
+ n.current?.showModal(), a.current?.focus(), document.getElementById(`${t}-${e.selected}`)?.scrollIntoView({ block: "center" });
563
+ }, [t, e.selected]), /* @__PURE__ */ f("dialog", {
564
+ ref: n,
565
+ className: "msm-picker-dialog",
566
+ "aria-labelledby": `${t}-title`,
567
+ onClose: e.onClose,
568
+ onClick: (e) => {
569
+ e.target === n.current && m();
570
+ },
571
+ children: [
572
+ /* @__PURE__ */ f("div", {
573
+ className: "msm-picker-head",
574
+ children: [/* @__PURE__ */ d("h2", {
575
+ id: `${t}-title`,
576
+ children: e.title
577
+ }), /* @__PURE__ */ d("button", {
578
+ type: "button",
579
+ onClick: m,
580
+ children: "Close"
581
+ })]
582
+ }),
583
+ /* @__PURE__ */ d("input", {
584
+ ref: a,
585
+ className: "msm-picker-search",
586
+ type: "search",
587
+ "aria-label": e.searchLabel,
588
+ placeholder: e.searchLabel,
589
+ autoComplete: "off",
590
+ enterKeyHint: "done",
591
+ value: l,
592
+ onChange: (e) => {
593
+ u(e.target.value), c.current && (c.current.scrollTop = 0);
594
+ },
595
+ onKeyDown: (e) => {
596
+ e.key === "Enter" && (e.preventDefault(), l.trim() !== "" && p[0] && h(p[0].value));
597
+ }
598
+ }),
599
+ /* @__PURE__ */ d("ul", {
600
+ ref: c,
601
+ "aria-label": e.listLabel,
602
+ children: p.map((n, r) => /* @__PURE__ */ d("li", { children: /* @__PURE__ */ f("button", {
603
+ type: "button",
604
+ id: `${t}-${n.value}`,
605
+ "aria-current": n.value === e.selected || void 0,
606
+ className: r === 0 && l.trim() !== "" ? "msm-picker-first" : void 0,
607
+ onClick: () => h(n.value),
608
+ children: [
609
+ n.flag && /* @__PURE__ */ d("span", {
610
+ "aria-hidden": "true",
611
+ children: n.flag
612
+ }),
613
+ /* @__PURE__ */ d("span", {
614
+ className: "msm-picker-label",
615
+ children: n.label
616
+ }),
617
+ n.hint && /* @__PURE__ */ d("span", {
618
+ className: "msm-picker-hint",
619
+ children: n.hint
620
+ })
621
+ ]
622
+ }) }, n.value))
623
+ }),
624
+ p.length === 0 && /* @__PURE__ */ d("p", {
625
+ className: "msm-picker-empty",
626
+ children: e.empty(l)
627
+ })
628
+ ]
629
+ });
630
+ }
631
+ var K = new p(), q = (e) => W(e);
632
+ function J(e) {
633
+ for (let t = 1; t <= 3 && t <= e.length; t++) {
634
+ let n = e.slice(0, t), r = (v.country_calling_codes[n] ?? []).filter((e) => W(e) !== void 0), [i] = r;
635
+ if (i) return {
636
+ code: n,
637
+ first: i,
638
+ countries: r
639
+ };
640
+ }
641
+ return null;
642
+ }
643
+ function Y(e, t) {
644
+ let n = /^\s*(\+|00)/.exec(e);
645
+ if (!n) return null;
646
+ let r = e.slice(n[0].length), i = r.replace(/\D/g, ""), a = J(i);
647
+ if (!a) return null;
648
+ let o = g(`+${i}`), s = a.countries.includes(t) ? t : o?.country ?? a.first, c = 0;
649
+ for (let e = 0; e < a.code.length; c++) /\d/.test(r.charAt(c)) && e++;
650
+ return {
651
+ country: s,
652
+ text: o?.isValid() ? o.formatNational() : r.slice(c).replace(/^[\s\-().]+/, "")
653
+ };
654
+ }
655
+ function oe(e, t) {
656
+ let n = t.replace(/\D/g, "");
657
+ return n === "" ? "" : t.trim().startsWith("+") ? `+${n}` : g(t, e)?.number ?? `+${q(e).callingCode}${n}`;
658
+ }
659
+ function se(e) {
660
+ return K.selectNumberingPlan(e), K.numberingPlan?.possibleLengths() ?? [];
661
+ }
662
+ function X(e, t, n) {
663
+ if (e === "") return t ? "Enter a phone number." : "";
664
+ let r = g(e);
665
+ if (r?.isValid()) return "";
666
+ let i = e.replace(/\D/g, ""), a = J(i);
667
+ if (!a) return "Unknown country code. Choose the country from the list.";
668
+ let o = n && a.countries.includes(n) ? n : r?.country ?? a.first, s = q(o).name, c = _(i.slice(a.code.length), o);
669
+ if (c && c !== "NOT_A_NUMBER") {
670
+ let e = se(o), t = e[0] ?? 0, n = e[e.length - 1] ?? 0;
671
+ return e.length === 1 ? `Enter a ${t}-digit number for ${s}.` : e.length > 2 && n - t === e.length - 1 ? `Enter ${t} to ${n} digits for ${s}.` : `Enter ${e.slice(0, -1).join(", ")} or ${n} digits for ${s}.`;
672
+ }
673
+ return `This is not a valid number for ${s}.`;
674
+ }
675
+ function ce(e, t = !1) {
676
+ return X(e, t);
677
+ }
678
+ function Z(e, t) {
679
+ return Y(e, t) ?? {
680
+ country: t,
681
+ text: e
682
+ };
683
+ }
684
+ function le(e) {
685
+ let t = i(), n = o(null), [a, c] = s(() => ({
686
+ value: e.value,
687
+ ...Z(e.value, "IS")
688
+ })), l = a;
689
+ e.value !== a.value && (l = {
690
+ value: e.value,
691
+ ...Z(e.value, a.country)
692
+ }, c(l));
693
+ let [u, p] = s(!1), [m, h] = s(!1), g = q(l.country), _ = X(l.value, e.required ?? !1, l.country), v = u && _ !== "" ? _ : e.error ?? "", y = v !== "";
694
+ r(() => {
695
+ let e = n.current?.form;
696
+ if (!e) return;
697
+ let t = () => {
698
+ p(!0), e.querySelector("[data-msm-phone-problem]") === n.current && n.current?.focus();
699
+ };
700
+ return e.addEventListener("submit", t), () => e.removeEventListener("submit", t);
701
+ }, []);
702
+ let b = (t, n) => {
703
+ let r = oe(t, n);
704
+ c({
705
+ value: r,
706
+ country: t,
707
+ text: n
708
+ }), r !== e.value && e.onChange(r);
709
+ };
710
+ return /* @__PURE__ */ f("div", {
711
+ className: "msm-phone",
712
+ children: [
713
+ /* @__PURE__ */ d("label", {
714
+ htmlFor: `${t}-number`,
715
+ children: e.label
716
+ }),
717
+ /* @__PURE__ */ f("div", {
718
+ className: "msm-phone-row",
719
+ children: [/* @__PURE__ */ f("button", {
720
+ type: "button",
721
+ className: "msm-phone-country",
722
+ "aria-label": `Country code: ${g.name} +${g.callingCode}`,
723
+ "aria-haspopup": "dialog",
724
+ onClick: () => h(!0),
725
+ children: [
726
+ /* @__PURE__ */ d("span", {
727
+ "aria-hidden": "true",
728
+ children: g.flag
729
+ }),
730
+ "+",
731
+ g.callingCode
732
+ ]
733
+ }), /* @__PURE__ */ d("input", {
734
+ ref: n,
735
+ id: `${t}-number`,
736
+ className: "msm-phone-number",
737
+ type: "tel",
738
+ inputMode: "tel",
739
+ autoComplete: e.autoComplete ?? "tel",
740
+ value: l.text,
741
+ "aria-required": e.required,
742
+ "data-msm-phone-problem": _ === "" ? void 0 : "",
743
+ "aria-invalid": y || void 0,
744
+ "aria-describedby": y ? `${t}-problem` : void 0,
745
+ onChange: (e) => {
746
+ let t = e.target.value.replace(/[^\d\s\-().+]/g, ""), n = Y(t, l.country);
747
+ b(n?.country ?? l.country, n?.text ?? t);
748
+ },
749
+ onBlur: () => {
750
+ l.text.trim() !== "" && p(!0);
751
+ }
752
+ })]
753
+ }),
754
+ y && /* @__PURE__ */ d("p", {
755
+ id: `${t}-problem`,
756
+ className: "msm-phone-problem",
757
+ role: "alert",
758
+ children: v
759
+ }),
760
+ m && /* @__PURE__ */ d(G, {
761
+ title: "Country code",
762
+ searchLabel: "Search by country or code",
763
+ listLabel: "Countries",
764
+ empty: (e) => `No country matches “${e}”.`,
765
+ search: ue,
766
+ selected: l.country,
767
+ onClose: () => h(!1),
768
+ onPick: (e) => {
769
+ h(!1), b(e, l.text), n.current?.focus();
770
+ }
771
+ })
772
+ ]
773
+ });
774
+ }
775
+ function ue(e) {
776
+ let t = H(e).replace(/^(\+|00)/, "");
777
+ return (t === "" ? U : /^\d+$/.test(t) ? U.filter((e) => e.callingCode.startsWith(t)) : U.filter((e) => H(e.name).includes(t) || e.code.toLowerCase() === t)).map((e) => ({
778
+ value: e.code,
779
+ label: e.name,
780
+ hint: `+${e.callingCode}`,
781
+ flag: e.flag
782
+ }));
783
+ }
784
+ // src/bot-check.tsx
785
+ var Q = () => window.turnstile, de = "https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit", $;
786
+ function fe() {
787
+ let e = Q();
788
+ return e ? Promise.resolve(e) : ($ ??= new Promise((e, t) => {
789
+ let n = document.createElement("script");
790
+ n.src = de, n.async = !0;
791
+ let r = () => {
792
+ $ = void 0, n.remove(), t(/* @__PURE__ */ Error("Turnstile did not load."));
793
+ };
794
+ n.onload = () => {
795
+ let t = Q();
796
+ t ? e(t) : r();
797
+ }, n.onerror = r, document.head.append(n);
798
+ }), $);
799
+ }
800
+ function pe(e) {
801
+ return e?.provider === "turnstile" && typeof e.siteKey == "string" && e.siteKey.trim() !== "";
802
+ }
803
+ function me(e) {
804
+ let t = o(null), n = o(void 0), i = o(e);
805
+ i.current = e;
806
+ let { siteKey: a } = e.botCheck;
807
+ r(() => {
808
+ let e = !0;
809
+ return fe().then((r) => {
810
+ let o = t.current;
811
+ if (!e || !o) return;
812
+ let s = r.render(o, {
813
+ sitekey: a,
814
+ size: "flexible",
815
+ callback: (e) => i.current.onToken(e),
816
+ "refresh-expired": "auto",
817
+ "expired-callback": () => i.current.onToken(void 0),
818
+ "error-callback": () => i.current.onToken(void 0)
819
+ });
820
+ s && (n.current = {
821
+ api: r,
822
+ id: s
823
+ });
824
+ }, () => e && i.current.onUnavailable()), () => {
825
+ e = !1;
826
+ let t = n.current;
827
+ n.current = void 0, t?.api.remove(t.id);
828
+ };
829
+ }, [a]);
830
+ let { attempt: s } = e;
831
+ return r(() => {
832
+ if (s === 0) return;
833
+ let e = n.current;
834
+ i.current.onToken(void 0), e?.api.reset(e.id);
835
+ }, [s]), /* @__PURE__ */ d("div", {
836
+ className: "cp-bot-check",
837
+ ref: t
838
+ });
839
+ }
840
+ // src/sign-in.tsx
841
+ function he(e) {
842
+ let [t, n] = s("sign-in"), [i, a] = s(""), [o, c] = s(""), [l, p] = s(""), [m, h] = s(), [g, _] = s(), [v, y] = s(!1), [x, S] = s(), [C, w] = s(0), T = pe(e.botCheck) ? e.botCheck : void 0, [E, O] = s();
843
+ r(() => {
844
+ if (!E) return;
845
+ let e = setTimeout(() => {
846
+ O(void 0), _((e) => e === E.message ? void 0 : e);
847
+ }, E.seconds * 1e3);
848
+ return () => clearTimeout(e);
849
+ }, [E]);
850
+ let k = t === "register";
851
+ async function A(t) {
852
+ if (t.preventDefault(), m || !ce(o, !0) && T && x) {
853
+ y(!0), _(void 0);
854
+ try {
855
+ let t = m ? await b(e.basePath, k ? "/auth/register" : "/auth/login", {
856
+ challenge: m,
857
+ code: l
858
+ }) : k ? await b(e.basePath, "/auth/register/initiate", {
859
+ phone: o,
860
+ name: i.trim(),
861
+ botCheckToken: x
862
+ }) : await b(e.basePath, "/auth/initiate", {
863
+ phone: o,
864
+ botCheckToken: x
865
+ });
866
+ if (t.ok) {
867
+ let n = await t.json();
868
+ m ? e.onSignedIn(n.sessionKey) : h(n.challenge);
869
+ return;
870
+ }
871
+ let n = await t.json().catch(() => void 0), r = Number(t.headers.get("retry-after")), a = Number.isInteger(r) && r > 0 ? r : void 0, s = ge(t.status, n?.code, a, !!m, k);
872
+ t.status === 429 && a && !m && O({
873
+ phone: o,
874
+ seconds: a,
875
+ message: s
876
+ }), _(s);
877
+ } catch {
878
+ _(D("signIn.error.unreachable"));
879
+ } finally {
880
+ y(!1), m || w((e) => e + 1);
881
+ }
882
+ }
883
+ }
884
+ function j(e) {
885
+ n(e), h(void 0), p(""), _(void 0);
886
+ }
887
+ return /* @__PURE__ */ d("div", {
888
+ className: "cp-sign-in",
889
+ children: /* @__PURE__ */ f("form", {
890
+ onSubmit: A,
891
+ "aria-busy": v,
892
+ children: [
893
+ /* @__PURE__ */ d(F, { brand: e.brand }),
894
+ /* @__PURE__ */ d("h1", { children: D(k ? "register.heading" : "signIn.heading") }),
895
+ e.notice && !m && /* @__PURE__ */ d("p", {
896
+ role: "status",
897
+ className: "cp-notice",
898
+ children: D(e.notice)
899
+ }),
900
+ m ? /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d("p", { children: D("signIn.codeSent", { phone: o }) }), /* @__PURE__ */ f("label", { children: [D("signIn.code"), /* @__PURE__ */ d("input", {
901
+ value: l,
902
+ onChange: (e) => p(e.target.value),
903
+ inputMode: "numeric",
904
+ autoComplete: "one-time-code",
905
+ required: !0,
906
+ autoFocus: !0
907
+ })] })] }) : /* @__PURE__ */ f(u, { children: [
908
+ /* @__PURE__ */ d("p", { children: D(k ? "register.intro" : "signIn.intro") }),
909
+ k && /* @__PURE__ */ f("label", { children: [D("register.name"), /* @__PURE__ */ d("input", {
910
+ value: i,
911
+ onChange: (e) => a(e.target.value),
912
+ autoComplete: "name",
913
+ maxLength: 200,
914
+ required: !0
915
+ })] }),
916
+ /* @__PURE__ */ d(le, {
917
+ label: D("signIn.phone"),
918
+ value: o,
919
+ onChange: c,
920
+ required: !0
921
+ }),
922
+ T && /* @__PURE__ */ d(me, {
923
+ botCheck: T,
924
+ attempt: C,
925
+ onToken: S,
926
+ onUnavailable: () => _(D("signIn.error.botCheckUnavailable"))
927
+ })
928
+ ] }),
929
+ !m && !T && /* @__PURE__ */ d("p", {
930
+ role: "alert",
931
+ children: D("signIn.error.notConfigured")
932
+ }),
933
+ g && /* @__PURE__ */ d("p", {
934
+ role: "alert",
935
+ children: g
936
+ }),
937
+ /* @__PURE__ */ d("button", {
938
+ type: "submit",
939
+ disabled: v || !m && (!T || !x || E?.phone === o),
940
+ children: D(v ? "signIn.wait" : m ? k ? "register.submit" : "signIn.submit" : "signIn.sendCode")
941
+ }),
942
+ m ? /* @__PURE__ */ d("button", {
943
+ type: "button",
944
+ className: "cp-secondary",
945
+ onClick: () => j(t),
946
+ children: D("signIn.differentNumber")
947
+ }) : /* @__PURE__ */ d("button", {
948
+ type: "button",
949
+ className: "cp-link",
950
+ onClick: () => j(k ? "sign-in" : "register"),
951
+ children: D(k ? "register.toSignIn" : "signIn.toRegister")
952
+ })
953
+ ]
954
+ })
955
+ });
956
+ }
957
+ function ge(e, t, n, r, i) {
958
+ return e === 429 ? n ? D("signIn.error.tooMany", { wait: P(n) }) : D("signIn.error.tooManyLater") : !r && e === 403 && t === "BotCheckFailed" ? D("signIn.error.botCheck") : !r && e === 503 && t === "BotCheckUnavailable" ? D("signIn.error.botCheckUnavailable") : !r && e === 503 && (t === "LimiterUnavailable" || t === "ClientIpUnavailable") ? D("signIn.error.failed") : !r && e === 503 ? n ? D("signIn.error.paused", { wait: P(n) }) : D("signIn.error.pausedLater") : !r && e === 422 && t === "PhoneDestinationNotAllowed" ? D("signIn.error.destination") : r && [
959
+ 400,
960
+ 401,
961
+ 403,
962
+ 404,
963
+ 409
964
+ ].includes(e) ? D(i ? "register.error.badCode" : "signIn.error.badCode") : D(e === 400 ? "signIn.error.invalid" : e === 403 ? "signIn.error.refused" : "signIn.error.failed");
965
+ }
966
+ // src/index.tsx
967
+ function _e(e) {
968
+ let t = e.basePath.replace(/\/$/, ""), [n, i] = s(), [o, c] = s(), [l, u] = s(/* @__PURE__ */ new Map()), [f, p] = s("bookings"), m = e.screen ?? f, h = e.onNavigate ?? p, g = a(() => x(t, () => {
969
+ c("app.signedOut"), i(null);
970
+ }), [t]);
971
+ r(() => {
972
+ y(`${t}/auth/session`).then(async (e) => i(e.ok ? (await e.json()).sessionKey : null)).catch(() => i(null));
973
+ }, [t]), r(() => {
974
+ if (!n) return;
975
+ let e = !0;
976
+ return (async () => {
977
+ let t = /* @__PURE__ */ new Map(), n;
978
+ do {
979
+ let { data: e } = await g.GET("/web/businesses", { params: { query: {
980
+ limit: 100,
981
+ ...n && { cursor: n }
982
+ } } });
983
+ for (let n of e?.items ?? []) t.set(n.id, n);
984
+ n = e?.nextCursor ?? void 0;
985
+ } while (n);
986
+ e && u(t);
987
+ })().catch(() => {}), () => {
988
+ e = !1;
989
+ };
990
+ }, [g, n]);
991
+ let _ = a(() => ({
992
+ client: g,
993
+ businesses: l,
994
+ signOut: async (e) => {
995
+ await b(t, "/auth/logout").catch(() => {}), c(e), i(null);
996
+ }
997
+ }), [
998
+ g,
999
+ l,
1000
+ t
1001
+ ]);
1002
+ return /* @__PURE__ */ d("div", {
1003
+ className: "msm-customer",
1004
+ children: n === void 0 ? /* @__PURE__ */ d("p", {
1005
+ className: "cp-status",
1006
+ role: "status",
1007
+ children: D("app.loading")
1008
+ }) : n ? /* @__PURE__ */ d(S.Provider, {
1009
+ value: _,
1010
+ children: /* @__PURE__ */ d(I, {
1011
+ brand: e.brand,
1012
+ screen: m,
1013
+ onNavigate: h,
1014
+ onSignOut: () => _.signOut(),
1015
+ children: d(m === "passes" ? V : m === "details" ? B : ne, {})
1016
+ })
1017
+ }) : /* @__PURE__ */ d(he, {
1018
+ basePath: t,
1019
+ brand: e.brand,
1020
+ botCheck: e.botCheck,
1021
+ notice: o,
1022
+ onSignedIn: (e) => {
1023
+ c(void 0), i(e);
1024
+ }
1025
+ })
1026
+ });
1027
+ }
1028
+ export { _e as MsmCustomer, L as cancellationState, N as formatDate, j as formatDateTime, A as formatNumber, T as locale, D as t };