@msm-platform/customer-react 0.3.1 → 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/CHANGELOG.md CHANGED
@@ -4,6 +4,16 @@ All notable changes to `@msm-platform/customer-react`. The format follows [Keep
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.4.0] - 2026-11-16
8
+
9
+ ### Added
10
+
11
+ - The screens show images: the business's logo on the businesses list and the head of a business, an event type's image on its card in `MsmBooking`'s first step and above its times (the original, with a `srcset` and `sizes` so a narrow screen loads the smaller one), and a resource's photo on its card where the customer chooses who. Cards and thumbnails load the `small` rendition. Every image is a plain `<img>` with `width`, `height`, `loading="lazy"` and alt text, so the layout does not shift, and without an image the screens look as before. **Allow MSM's media host in your Content Security Policy:** the images load from it, so a site whose own `img-src` is restricted shows broken images until you add that origin (`img-src 'self' <media origin>`); read the host from configuration, and add it to `images.remotePatterns` if you show the images through `next/image`. The README's Images section also says how long a replaced or retired image is served. It needs the engine release with images and `@msm-platform/customer-sdk` 0.3.0.
12
+
13
+ ### Changed
14
+
15
+ - **Breaking:** sign-in is phone first. The screens ask for the phone, then the code, then a name only when the customer is new, in one form with no register mode and no "Create an account" link, in `MsmCustomer`, `MsmBooking` and `MsmSignIn`; their props are unchanged, and `onSignedIn` fires for a sign-in and a registration alike. A wrong or expired code says only "That code is incorrect or has expired." The server half's routes change for a partner that calls them directly: `POST auth/register/initiate` is removed (404); `POST auth/login` `{challenge, code}` answers `{result: "session", sessionKey}` or `{result: "nameRequired"}` instead of `{sessionKey}`, and signs a known person without a customer account straight in; `POST auth/register` takes only `{name}` and answers `{result: "session", sessionKey}`, or 401 `NotAuthenticated` without a pending registration. The engine's registration ticket is kept in a second encrypted HttpOnly cookie, `__Host-msm_customer_registration`, under your `sessionKeys`, and never reaches the browser. It needs the engine release with phone-first sign-in and `@msm-platform/customer-sdk` 0.3.0.
16
+
7
17
  ## [0.3.1] - 2026-11-15
8
18
 
9
19
  ### Added
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MSM customer screens (`@msm-platform/customer-react`)
2
2
 
3
- MSM's customer screens as a React library, and their server half for the partner's own server. The screens cover booking (the partner's businesses, a business's event types and a week of its availability, then hold, sign in if needed, confirm and cancel), phone sign-in and registration, bookings with cancellation, memberships and passes, and details (only the name is editable), with sign out and sign out everywhere. React and React DOM are peers; it does not use React Router. [`examples/customer-nextjs`](https://github.com/Sveittur/msm-platform/tree/main/examples/customer-nextjs) is the starter that mounts both halves, and the screens' dev host in this repository.
3
+ MSM's customer screens as a React library, and their server half for the partner's own server. The screens cover booking (the partner's businesses, a business's event types and a week of its availability, then hold, sign in if needed, confirm and cancel), phone-first sign-in (a new customer gives their name after the code), bookings with cancellation, memberships and passes, and details (only the name is editable), with sign out and sign out everywhere. React and React DOM are peers; it does not use React Router. [`examples/customer-nextjs`](https://github.com/Sveittur/msm-platform/tree/main/examples/customer-nextjs) is the starter that mounts both halves, and the screens' dev host in this repository.
4
4
 
5
5
  ```sh
6
6
  npm install @msm-platform/customer-react
@@ -39,9 +39,9 @@ The browser holds no credentials: the server half adds the client's and keeps th
39
39
 
40
40
  ### Booking
41
41
 
42
- Browsing needs no session: the business list, a business and its availability are public reads. Availability shows a week at a time from today in the business's timezone, events with the seats left and open time slots in one list, narrowed to one event type when the screen names one. Choosing a time holds it; a customer who is signed out signs in or registers first, and the time they chose is held straight after. The hold lasts 10 minutes, the engine's hold, and confirming turns it into a booking, shown with the same cancel step and late-cancellation wording as the bookings screen. The engine's refusals are shown in the screens' own words, picked by their code: a full event, a taken slot, the limit of 5 unconfirmed holds, a hold that lapsed before confirming (with an offer to hold it again), a time that can no longer be booked, and an event type that needs a membership or pass. Payment is not part of booking yet.
42
+ Browsing needs no session: the business list, a business and its availability are public reads. Availability shows a week at a time from today in the business's timezone, events with the seats left and open time slots in one list, narrowed to one event type when the screen names one. Choosing a time holds it; a customer who is signed out signs in first, giving their name after the code when they are new, and the time they chose is held straight after. The hold lasts 10 minutes, the engine's hold, and confirming turns it into a booking, shown with the same cancel step and late-cancellation wording as the bookings screen. The engine's refusals are shown in the screens' own words, picked by their code: a full event, a taken slot, the limit of 5 unconfirmed holds, a hold that lapsed before confirming (with an offer to hold it again), a time that can no longer be booked, and an event type that needs a membership or pass. Payment is not part of booking yet.
43
43
 
44
- Before sending a code, sign-in and registration show Cloudflare Turnstile and send its token as `botCheckToken`. The widget's script (`https://challenges.cloudflare.com/turnstile/v0/api.js`) loads only in the phone step, so a Content Security Policy needs `https://challenges.cloudflare.com` in `script-src` and `frame-src`. Without a `botCheck` prop, sign-in says it isn't set up and sends nothing. In development, Cloudflare's test site key `1x00000000000000000000AA` always passes.
44
+ Before sending a code, sign-in shows Cloudflare Turnstile and sends its token as `botCheckToken`. The widget's script (`https://challenges.cloudflare.com/turnstile/v0/api.js`) loads only in the phone step, so a Content Security Policy needs `https://challenges.cloudflare.com` in `script-src` and `frame-src`. Without a `botCheck` prop, sign-in says it isn't set up and sends nothing. In development, Cloudflare's test site key `1x00000000000000000000AA` always passes.
45
45
 
46
46
  The built entry starts with `"use client"`, so a Next.js server component can import it; it touches no browser globals at import and renders on the server (as "Loading…" until mounted).
47
47
 
@@ -59,7 +59,7 @@ import {
59
59
 
60
60
  ### `MsmBooking`
61
61
 
62
- The booking flow for one business, in steps: the customer chooses an event type; then who provides it, with Anyone first, when two or more resources can; then a time. The first step also offers See all times, every time at the business filtered by event type and by resource. A signed-out customer signs in or registers with the time kept, then holds, confirms and sees the booking with its cancel step. It has no tabs and never leaves the business.
62
+ The booking flow for one business, in steps: the customer chooses an event type; then who provides it, with Anyone first, when two or more resources can; then a time. The first step also offers See all times, every time at the business filtered by event type and by resource. A signed-out customer signs in with the time kept, and gives their name too when they are new, then holds, confirms and sees the booking with its cancel step. It has no tabs and never leaves the business.
63
63
 
64
64
  | Prop | Meaning |
65
65
  | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -80,7 +80,18 @@ Bookings, Passes and My details, with no Book tab, and sign-in in place when sig
80
80
 
81
81
  ### `MsmSignIn`
82
82
 
83
- Sign-in and registration on their own. `onSignedIn()` is called once the customer is signed in, whether they signed in or registered, and at once when they already were; `onCancel` adds a Cancel button. It never navigates: close your modal on either.
83
+ The phone-first sign-in form on its own: phone, code, and a name only when the customer is new. `onSignedIn()` is called once the customer is signed in, whether they already had an account or just registered, and at once when they already were; `onCancel` adds a Cancel button. It never navigates: close your modal on either.
84
+
85
+ ## Images
86
+
87
+ The screens show the business's logo (the businesses list and the head of a business), an event type's image (its card in `MsmBooking`'s first step, and above its times) and a resource's photo (its card where the customer chooses who). A card or thumbnail loads the `small` rendition; an event type's details offer both renditions as a `srcset` with `sizes`, so a narrow screen does not fetch the original. Every image is a plain `<img>` with its `width` and `height`, `loading="lazy"` and `alt` text, so the layout does not shift as it loads; a business, event type or resource without an image looks as it did before.
88
+
89
+ **Allow MSM's media host in your Content Security Policy.** The images load from MSM's media domain, not from your site, so a partner whose own policy restricts `img-src` sees broken images until it adds that origin: `img-src 'self' <media origin>`. MSM hands over the media host, such as `https://media.dev.xn--stafrnirmguleikar-vrb22a.is` in dev, with your client credentials; it differs per environment, so read it from configuration (the starter's `MSM_MEDIA_URL`) rather than writing it in code. If you show the images through `next/image` on your own pages, the same origin goes in `images.remotePatterns`. The screens themselves use `<img>`, not `next/image`. [`examples/customer-nextjs`](https://github.com/Sveittur/msm-platform/tree/main/examples/customer-nextjs) shows both, from `MSM_MEDIA_URL`.
90
+
91
+ **How long an image lives.** An image's URL never changes; a replaced image gets a new URL.
92
+ - A replaced image's old URL keeps working for 48 hours, so a page you cached with the old URL must revalidate within that time.
93
+ - MSM's media domain stops serving a retired image at most 48 hours plus one day after it is replaced or its owner is deleted: the 48 hours are above, and the edge's own copy lasts at most one day more.
94
+ - Copies downstream of MSM are outside MSM's control: those held by browsers, and by your own image optimizer such as `next/image`'s cache, last as long as you and the visitor's browser keep them. A partner that must remove an image sooner purges its own cache.
84
95
 
85
96
  ## Theming
86
97
 
@@ -148,19 +159,21 @@ MSM owns your website's Cloudflare Turnstile widget and keeps its secret: the en
148
159
 
149
160
  Every route needs the `X-MSM-BFF: 1` header the screens send. Browsers send a custom header cross-origin only after a CORS preflight, which the handler never approves, so another site cannot call these routes with the customer's cookie.
150
161
 
151
- | Route | Behaviour |
152
- | ------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
153
- | `POST auth/initiate` `{phone, botCheckToken}` | Asks the engine for a sign-in code with the token and `clientIp(request)`; without an address it refuses with 503 `ClientIpUnavailable` and calls nothing. The engine checks the token (403 `BotCheckFailed`, or 503 `BotCheckUnavailable` when it cannot), then counts the address (429 `TooManyAttempts` with `Retry-After`, or 503 `LimiterUnavailable`) and the phone; its refusals pass through with their status, code and `Retry-After`. |
154
- | `POST auth/register/initiate` `{phone, name, botCheckToken}` | Asks for a registration code the same way, against the same counts. |
155
- | `POST auth/login`, `POST auth/register` `{challenge, code}` | Redeems the code exactly once, never retried, and sets the session cookie. Returns `{sessionKey}`, the session's ID. |
156
- | `GET auth/session` | `{sessionKey}`, or 401. |
157
- | `POST auth/logout` | Revokes the session at the engine and clears the cookie. |
158
- | `/engine/web/*` | Proxied to the engine's `/web`, except `/web/identity/*`, with the client's credentials and the cookie's session. Only `Accept`, `Content-Type` and `Accept-Language` pass from the browser. A 401, or a successful `DELETE /engine/web/me/sessions` (sign out everywhere), clears the cookie. |
162
+ | Route | Behaviour |
163
+ | --------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
164
+ | `POST auth/initiate` `{phone, botCheckToken}` | Asks the engine for a sign-in code with the token and `clientIp(request)`; without an address it refuses with 503 `ClientIpUnavailable` and calls nothing. The engine checks the token (403 `BotCheckFailed`, or 503 `BotCheckUnavailable` when it cannot), then counts the address (429 `TooManyAttempts` with `Retry-After`, or 503 `LimiterUnavailable`) and the phone; its refusals pass through with their status, code and `Retry-After`. |
165
+ | `POST auth/login` `{challenge, code}` | Redeems the code exactly once, never retried. A customer is signed in: it sets the session cookie and returns `{result: "session", sessionKey}`, `sessionKey` being the session's ID. A phone the engine asks to register is signed in the same way when the engine needs no name, such as staff without a customer account: the handler completes the registration at once. Otherwise it returns `{result: "nameRequired"}` and keeps the engine's registration ticket in its own encrypted cookie (see [Sessions](#sessions)); the current session stays until a new one is issued. A wrong or expired code passes the engine's 401 through and drops any pending registration. |
166
+ | `POST auth/register` `{name}` | Completes the pending registration with the name and the ticket from its cookie, then sets the session cookie, drops the ticket and returns `{result: "session", sessionKey}`. Without a pending registration it answers 401 `NotAuthenticated` and calls nothing. The engine checks the name: 422 `NameRequired` and 400 `ValidationFailed` pass through and keep the ticket for a retry. Any 401 from the engine (a spent or expired ticket) drops it. |
167
+ | `GET auth/session` | `{sessionKey}`, or 401. |
168
+ | `POST auth/logout` | Revokes the session at the engine and clears both cookies. |
169
+ | `/engine/web/*` | Proxied to the engine's `/web`, except `/web/identity/*`, with the client's credentials and the cookie's session. Only `Accept`, `Content-Type` and `Accept-Language` pass from the browser. A 401, or a successful `DELETE /engine/web/me/sessions` (sign out everywhere), clears the cookie. |
159
170
 
160
171
  ### Sessions
161
172
 
162
173
  The session lives in no store: the cookie `__Host-msm_customer_session` (HttpOnly, Secure, Path=/, SameSite=Lax, expiring at the session's maximum age) holds `{sessionId, sessionToken, expiresAt}` encrypted with AES-256-GCM. The browser holds only that ciphertext; no response body carries the token. SameSite=Lax, rather than Strict, lets a customer arriving from an SMS link render as signed in on the server.
163
174
 
175
+ A pending registration lives the same way: the cookie `__Host-msm_customer_registration`, with the same attributes and expiring with the engine's ticket (10 minutes), holds `{registrationTicket, expiresAt}` encrypted with the same keys. Each cookie's name is authenticated with its value, so neither opens as the other. The browser learns only that a name is needed; no response body carries the ticket.
176
+
164
177
  `readCustomerSession(cookieValue, { sessionKeys })` reads the signed-in customer's session in the partner's own server code, such as a page that books through the customer SDK with `sessionHeaders(session.sessionToken)`, so the partner's pages and the screens share one sign-in. It returns null for a missing, undecryptable or expired cookie. It does not ask the engine, so a session revoked elsewhere reads as signed in until the engine answers 401; a caller that needs certainty calls the engine.
165
178
 
166
179
  ## Development
package/dist/client.d.ts CHANGED
@@ -11,6 +11,8 @@ type Ok<Operation> = Operation extends {
11
11
  export type OwnBooking = Ok<paths["/web/me/bookings"]["get"]>["items"][number];
12
12
  export type Membership = Ok<paths["/web/me/memberships"]["get"]>[number];
13
13
  export type Business = Ok<paths["/web/businesses"]["get"]>["items"][number];
14
+ /** An uploaded image: the original and its smaller `small` rendition. */
15
+ export type CustomerImage = NonNullable<Business["logo"]>;
14
16
  /** A confirmed booking, as the confirm route returns it. */
15
17
  export type CustomerBooking = Ok<paths["/web/businesses/{businessId}/reservations/{reservationId}/confirm"]["post"]>;
16
18
  export type MyDetails = Ok<paths["/web/me"]["get"]>;
package/dist/i18n.d.ts CHANGED
@@ -4,6 +4,7 @@ declare const en: {
4
4
  readonly "app.retry": "Try again";
5
5
  readonly "app.signedOut": "You were signed out because your session ended. Sign in again.";
6
6
  readonly "app.signedOutEverywhere": "You were signed out on every device.";
7
+ readonly "image.logo": "{name} logo";
7
8
  readonly "nav.label": "Booking and my account";
8
9
  readonly "nav.book": "Book";
9
10
  readonly "nav.signIn": "Sign in";
@@ -13,11 +14,8 @@ declare const en: {
13
14
  readonly "nav.signOut": "Sign out";
14
15
  readonly "signIn.heading": "Sign in";
15
16
  readonly "signIn.intro": "We'll text a one-time code to your phone.";
16
- readonly "signIn.toRegister": "New here? Create an account";
17
- readonly "register.heading": "Create an account";
18
- readonly "register.intro": "Enter your name and phone. We'll text you a code.";
17
+ readonly "register.intro": "One more step: what's your name?";
19
18
  readonly "register.name": "Your name";
20
- readonly "register.toSignIn": "Already have an account? Sign in";
21
19
  readonly "signIn.phone": "Phone number";
22
20
  readonly "signIn.codeSent": "Enter the code we sent to {phone}.";
23
21
  readonly "signIn.code": "Verification code";
@@ -32,8 +30,9 @@ declare const en: {
32
30
  readonly "signIn.error.paused": "Sign-in codes are paused for now. Try again in about {wait}.";
33
31
  readonly "signIn.error.pausedLater": "Sign-in codes are paused for now. Try again later.";
34
32
  readonly "signIn.error.destination": "This number can't receive sign-in codes.";
35
- readonly "signIn.error.badCode": "That code is incorrect or has expired, or this number has no account yet.";
36
- readonly "register.error.badCode": "That code is incorrect or has expired, or this number already has an account.";
33
+ readonly "signIn.error.badCode": "That code is incorrect or has expired.";
34
+ readonly "register.error.expired": "That took too long. Request a new code.";
35
+ readonly "register.error.name": "Check your name and try again.";
37
36
  readonly "signIn.error.invalid": "Check the phone number and try again.";
38
37
  readonly "signIn.error.refused": "This number can't sign in here.";
39
38
  readonly "signIn.error.unreachable": "The sign-in service is unreachable. Try again shortly.";
@@ -96,7 +95,7 @@ declare const en: {
96
95
  readonly "business.with": "With {resource}";
97
96
  readonly "business.book": "Book";
98
97
  readonly "book.heading": "Your booking";
99
- readonly "book.signInFirst": "Sign in or create an account to book this time.";
98
+ readonly "book.signInFirst": "Sign in with your phone to book this time.";
100
99
  readonly "book.back": "Choose another time";
101
100
  readonly "book.reserving": "Holding this time for you…";
102
101
  readonly "book.heldUntil": "We're holding this time for you until {time}.";
@@ -0,0 +1,14 @@
1
+ import type { CustomerImage } from "./client";
2
+ /**
3
+ * An uploaded image, or nothing when there is none. `width` and `height`
4
+ * are always set, so the browser reserves the space before the file loads.
5
+ * A card or thumbnail uses the `small` rendition alone; `full` is for a
6
+ * details view, where the browser picks the original or `small` by the
7
+ * width the image will have (`sizes` matches `.cp-detail-image`).
8
+ */
9
+ export declare function Img(props: {
10
+ image: CustomerImage | null | undefined;
11
+ alt: string;
12
+ size: "small" | "full";
13
+ className: string;
14
+ }): import("react").JSX.Element | null;