@msm-platform/customer-react 0.3.0 → 0.4.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/layout.d.ts CHANGED
@@ -1,9 +1,15 @@
1
1
  import type { ReactNode } from "react";
2
2
  import type { CustomerBrand } from "./client";
3
3
  import type { CustomerScreen } from "./context";
4
+ import { type MessageKey } from "./i18n";
4
5
  export declare function BrandMark({ brand }: {
5
6
  brand: CustomerBrand | undefined;
6
7
  }): import("react").JSX.Element | null;
8
+ type Tab = "businesses" | "bookings" | "passes" | "details";
9
+ export type Tabs = [Tab, MessageKey][];
10
+ /** The account's own screens, without booking. */
11
+ export declare const accountTabs: Tabs;
12
+ export declare const allTabs: Tabs;
7
13
  /**
8
14
  * The shell around every screen, signed in or not: brand header with sign
9
15
  * in or out, navigation between booking and the account screens, and the
@@ -11,6 +17,7 @@ export declare function BrandMark({ brand }: {
11
17
  */
12
18
  export declare function AccountLayout(props: {
13
19
  brand: CustomerBrand | undefined;
20
+ tabs: Tabs;
14
21
  screen: CustomerScreen;
15
22
  signedIn: boolean;
16
23
  /** The sign-in form is on screen, so the header offers no second one. */
@@ -19,3 +26,4 @@ export declare function AccountLayout(props: {
19
26
  onSignOut: () => void;
20
27
  children: ReactNode;
21
28
  }): import("react").JSX.Element;
29
+ export {};
@@ -0,0 +1,26 @@
1
+ import { type ReactNode } from "react";
2
+ import { type CustomerScreen, type Portal } from "./context";
3
+ /**
4
+ * What every screen component shares: the session on `basePath`, the
5
+ * client, the partner's public businesses and sign-out, as the `Portal`
6
+ * its screens read.
7
+ */
8
+ export declare function useCustomerPortal(options: {
9
+ basePath: string;
10
+ navigate: (screen: CustomerScreen) => void;
11
+ /** Whether the screens may lead to the business list and the account. */
12
+ accountNavigation: boolean;
13
+ onSessionChange: ((signedIn: boolean) => void) | undefined;
14
+ }): {
15
+ basePath: string;
16
+ sessionKey: import("./session").SessionState;
17
+ notice: "app.loading" | "app.loadFailed" | "app.retry" | "app.signedOut" | "app.signedOutEverywhere" | "image.logo" | "nav.label" | "nav.book" | "nav.signIn" | "nav.bookings" | "nav.passes" | "nav.details" | "nav.signOut" | "signIn.heading" | "signIn.intro" | "register.intro" | "register.name" | "signIn.phone" | "signIn.codeSent" | "signIn.code" | "signIn.sendCode" | "signIn.submit" | "register.submit" | "signIn.wait" | "signIn.differentNumber" | "signIn.cancel" | "signIn.error.tooMany" | "signIn.error.tooManyLater" | "signIn.error.paused" | "signIn.error.pausedLater" | "signIn.error.destination" | "signIn.error.badCode" | "register.error.expired" | "register.error.name" | "signIn.error.invalid" | "signIn.error.refused" | "signIn.error.unreachable" | "signIn.error.failed" | "signIn.error.botCheck" | "signIn.error.botCheckUnavailable" | "signIn.error.notConfigured" | "wait.seconds.one" | "wait.seconds.other" | "wait.minutes.one" | "wait.minutes.other" | "wait.hours.one" | "wait.hours.other" | "bookings.heading" | "bookings.period" | "bookings.upcoming" | "bookings.past" | "bookings.emptyUpcoming" | "bookings.emptyPast" | "bookings.more" | "bookings.when" | "bookings.cancelled" | "bookings.cancelledLate" | "bookings.attended" | "bookings.noShow" | "bookings.lateFrom" | "bookings.started" | "bookings.cancel" | "bookings.confirmHeading" | "bookings.confirmLate" | "bookings.confirmCredit" | "bookings.confirm" | "bookings.keep" | "bookings.cancelling" | "bookings.doneOnTime" | "bookings.doneLate" | "bookings.cancelFailed" | "bookings.gone" | "businesses.heading" | "businesses.intro" | "businesses.empty" | "businesses.open" | "business.all" | "business.notFound" | "business.types" | "business.allTypes" | "business.resources" | "business.anyResource" | "business.typeMissing" | "business.minutes" | "business.week" | "business.previousWeek" | "business.nextWeek" | "business.weekOf" | "business.empty" | "business.seatsLeft.one" | "business.seatsLeft.other" | "business.full" | "business.openTime" | "business.with" | "business.book" | "book.heading" | "book.signInFirst" | "book.back" | "book.reserving" | "book.heldUntil" | "book.confirm" | "book.confirming" | "book.booked" | "book.toBookings" | "book.done" | "book.close" | "book.chooseType" | "book.noTypes" | "book.seeAll" | "book.chooseResource" | "book.anyResource" | "book.anyResourceHint" | "book.toTypes" | "book.otherResource" | "book.reserveAgain" | "book.full" | "book.slotTaken" | "book.limit" | "book.expired" | "book.notAllowed" | "book.unavailable" | "book.refused" | "book.failed" | "passes.heading" | "passes.empty" | "passes.unlimited" | "passes.credits" | "passes.validFrom" | "passes.validRange" | "passes.expired" | "details.heading" | "details.name" | "details.phone" | "details.email" | "details.none" | "details.readOnly" | "details.save" | "details.saving" | "details.saved" | "details.saveFailed" | "details.signOutEverywhere" | "details.signOutEverywhereHint" | "details.signOutEverywhereFailed" | undefined;
18
+ portal: Portal;
19
+ signedInAs: (next: string) => void;
20
+ };
21
+ /** The scoped root every screen component renders, "Loading…" until the session is known. */
22
+ export declare function CustomerRoot(props: {
23
+ portal: Portal;
24
+ loading: boolean;
25
+ children: ReactNode;
26
+ }): import("react").JSX.Element;
@@ -1,11 +1,134 @@
1
- import type { Business as BusinessDto, Candidate } from "../client";
1
+ import { type ReactNode } from "react";
2
+ import type { Business as BusinessDto, Candidate, EventType } from "../client";
3
+ /** The date of `at` in `timeZone`, as YYYY-MM-DD; today by default. */
4
+ export declare function localDate(timeZone: string, at?: Date): string;
5
+ /** The calendar date `count` days after `date` (YYYY-MM-DD). */
6
+ export declare function addDays(date: string, count: number): string;
7
+ type Catalog = ReturnType<typeof useCatalog>;
8
+ /** A business and its event types, the public reads every booking step needs. */
9
+ export declare function useCatalog(businessId: string): {
10
+ business: {
11
+ address: string | null;
12
+ brandColor: string | null;
13
+ cover: {
14
+ height: number;
15
+ small: {
16
+ height: number;
17
+ url: string;
18
+ width: number;
19
+ };
20
+ url: string;
21
+ width: number;
22
+ } | null;
23
+ description: string | null;
24
+ displayName: string;
25
+ email: string | null;
26
+ id: string;
27
+ latitude: number | null;
28
+ logo: {
29
+ height: number;
30
+ small: {
31
+ height: number;
32
+ url: string;
33
+ width: number;
34
+ };
35
+ url: string;
36
+ width: number;
37
+ } | null;
38
+ longitude: number | null;
39
+ phone: string | null;
40
+ timezone: string;
41
+ } | null | undefined;
42
+ types: {
43
+ cancellationCutoffMinutes: number | null;
44
+ categoryId: string | null;
45
+ description: string | null;
46
+ displayName: string;
47
+ durationMinutes: number;
48
+ id: string;
49
+ image: {
50
+ height: number;
51
+ small: {
52
+ height: number;
53
+ url: string;
54
+ width: number;
55
+ };
56
+ url: string;
57
+ width: number;
58
+ } | null;
59
+ requiresAccess: boolean;
60
+ resources: {
61
+ description: string | null;
62
+ displayName: string;
63
+ id: string;
64
+ image: {
65
+ height: number;
66
+ small: {
67
+ height: number;
68
+ url: string;
69
+ width: number;
70
+ };
71
+ url: string;
72
+ width: number;
73
+ } | null;
74
+ }[];
75
+ timeSlotBooking: boolean;
76
+ }[] | undefined;
77
+ failed: boolean;
78
+ reload: () => Promise<void>;
79
+ };
80
+ /**
81
+ * The screen for a catalog that has not loaded: it failed, the business is
82
+ * not public here, or it is still loading. Undefined once it has loaded.
83
+ */
84
+ export declare function pendingCatalog(catalog: Catalog, back: ReactNode): import("react").JSX.Element | undefined;
85
+ /** The resources that provide `types`, each once, in the order they appear. */
86
+ export declare function resourcesOf(types: EventType[]): {
87
+ description: string | null;
88
+ displayName: string;
89
+ id: string;
90
+ image: {
91
+ height: number;
92
+ small: {
93
+ height: number;
94
+ url: string;
95
+ width: number;
96
+ };
97
+ url: string;
98
+ width: number;
99
+ } | null;
100
+ }[];
101
+ /** The filters the business screen shows, when its host drives them. */
102
+ export interface BusinessFilter {
103
+ eventTypeId?: string;
104
+ resourceId?: string;
105
+ }
2
106
  /**
3
107
  * A business: its details, its event types as filters, and a week of its
4
108
  * availability, events with seats and open time slots in one list, in the
5
- * business's timezone. Choosing a candidate starts booking it.
109
+ * business's timezone. Choosing a candidate starts booking it. With
110
+ * `onFilter`, it also filters by resource, and both filters call it instead
111
+ * of navigating.
6
112
  */
7
113
  export declare function Business(props: {
8
114
  businessId: string;
9
115
  eventTypeId: string | undefined;
116
+ resourceId?: string | undefined;
117
+ onFilter?: ((filter: BusinessFilter) => void) | undefined;
10
118
  onChoose: (business: BusinessDto, candidate: Candidate) => void;
119
+ }): import("react").JSX.Element | undefined;
120
+ /** The business's logo beside its name and address, above its screen. */
121
+ export declare function BusinessHead({ business }: {
122
+ business: BusinessDto;
123
+ }): import("react").JSX.Element;
124
+ /** An event type's image, name, description and length, above its times. */
125
+ export declare function TypeDetails({ type }: {
126
+ type: EventType;
127
+ }): import("react").JSX.Element;
128
+ export declare function Availability(props: {
129
+ business: BusinessDto;
130
+ eventTypeId: string | undefined;
131
+ resourceId?: string | undefined;
132
+ onChoose: (candidate: Candidate) => void;
11
133
  }): import("react").JSX.Element;
134
+ export {};
@@ -27,12 +27,16 @@ export interface CustomerHandlerOptions {
27
27
  * The routes MSM's customer screens call under their `basePath`, for one
28
28
  * catch-all route such as `app/msm/[...path]/route.ts`:
29
29
  *
30
- * - `POST auth/initiate` `{phone, botCheckToken}` and
31
- * `POST auth/register/initiate` `{phone, name, botCheckToken}` ask the
32
- * engine for a code with the token and `clientIp(request)`; the engine
33
- * checks the bot check and limits per address and per phone;
34
- * - `POST auth/login` and `POST auth/register` `{challenge, code}` redeem it
35
- * once, never retried, and set the encrypted session cookie;
30
+ * - `POST auth/initiate` `{phone, botCheckToken}` asks the engine for a code
31
+ * with the token and `clientIp(request)`; the engine checks the bot check
32
+ * and limits per address and per phone;
33
+ * - `POST auth/login` `{challenge, code}` redeems it once, never retried.
34
+ * A customer gets the encrypted session cookie. A phone the engine asks to
35
+ * register gets it too when no name is needed, since the handler completes
36
+ * the registration at once; otherwise the answer is `nameRequired` and the
37
+ * engine's registration ticket goes into its own encrypted cookie;
38
+ * - `POST auth/register` `{name}` completes that registration with the
39
+ * ticket from the cookie and sets the session cookie;
36
40
  * - `GET auth/session` and `POST auth/logout`;
37
41
  * - `/engine/web/*`, except `/web/identity/*`, proxied to the engine with the
38
42
  * client's credentials and the cookie's session.
@@ -13,13 +13,27 @@ export interface CustomerSession {
13
13
  */
14
14
  export declare function sessionKeyList(keys: string | readonly string[]): string[];
15
15
  /**
16
- * AES-256-GCM keys derived with HKDF-SHA256 from the partner's keys, so any
17
- * long random string works as a key. The first encrypts; every one decrypts.
16
+ * The cookie that holds a pending registration's encrypted ticket, between
17
+ * a code the engine answered with `nameRequired` and the customer's name.
18
18
  */
19
+ export declare const customerRegistrationCookie = "__Host-msm_customer_registration";
20
+ /** A pending registration, as its cookie holds it. Server-side only. */
21
+ export interface PendingRegistration {
22
+ registrationTicket: string;
23
+ /** When the engine stops accepting the ticket (ISO 8601). */
24
+ expiresAt: string;
25
+ }
26
+ /** The session cookie's cipher. */
19
27
  export declare function sessionCipher(keys: readonly string[]): {
20
- seal(session: CustomerSession): Promise<string>;
21
- /** The cookie's session, or null when no key opens it or it has expired. */
22
- open(value: string | undefined): Promise<CustomerSession | null>;
28
+ seal(value: CustomerSession): Promise<string>;
29
+ /** The cookie's value, or null when no key opens it or it has expired. */
30
+ open(cookie: string | undefined): Promise<CustomerSession | null>;
31
+ };
32
+ /** The pending registration cookie's cipher. */
33
+ export declare function registrationCipher(keys: readonly string[]): {
34
+ seal(value: PendingRegistration): Promise<string>;
35
+ /** The cookie's value, or null when no key opens it or it has expired. */
36
+ open(cookie: string | undefined): Promise<PendingRegistration | null>;
23
37
  };
24
38
  /**
25
39
  * The signed-in customer's session for the partner's own server code, such as