@msm-platform/customer-react 0.0.0-stage → 0.2.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 +22 -0
- package/LICENSE +21 -0
- package/README.md +147 -2
- package/dist/booking.d.ts +19 -0
- package/dist/bot-check.d.ts +14 -0
- package/dist/cancellation.d.ts +8 -0
- package/dist/client.d.ts +44 -0
- package/dist/context.d.ts +24 -0
- package/dist/i18n.d.ts +160 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +1544 -0
- package/dist/layout.d.ts +21 -0
- package/dist/screens/bookings.d.ts +9 -0
- package/dist/screens/business.d.ts +11 -0
- package/dist/screens/businesses.d.ts +2 -0
- package/dist/screens/details.d.ts +2 -0
- package/dist/screens/passes.d.ts +1 -0
- package/dist/server/index.d.ts +65 -0
- package/dist/server/limits.d.ts +44 -0
- package/dist/server/session.d.ts +37 -0
- package/dist/server/turnstile.d.ts +22 -0
- package/dist/server.js +442 -0
- package/dist/sign-in.d.ts +14 -0
- package/dist/style.css +2 -0
- package/package.json +44 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@msm-platform/customer-react`. The format follows [Keep a Changelog 1.1.0](https://keepachangelog.com/en/1.1.0/), and versions follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Versions are `0.x` until engine 1.0.0: a breaking change raises the minor version and is marked **Breaking**, anything else raises the patch version.
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
6
|
+
|
|
7
|
+
## [0.2.0] - 2026-11-14
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Booking screens: the partner's businesses, a business with its event types and a week of its availability (classes with the seats left and open time slots in one list, in the business's timezone), then hold, sign-in or registration when needed (the chosen time is kept and held straight after), confirm, and the booking with the same cancel step as the bookings screen. Refusals (a full class, a taken slot, the limit of 5 unconfirmed holds, a lapsed hold, a time no longer bookable, missing access) are shown in the screens' own words. Link straight to a business or one of its services with `screen={{ businessId }}` or `screen={{ businessId, eventTypeId }}`.
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- **Breaking:** the screens open on booking. Without `screen` and `onNavigate`, the first screen is now `businesses`, the partner's businesses, instead of `bookings`; and `CustomerScreen` widens with `"businesses"`, `{ businessId }` and `{ businessId, eventTypeId }`, so a host whose `onNavigate` or `switch` covers only `bookings`, `passes` and `details` needs the new values. Pass `screen="bookings"` to keep opening on bookings.
|
|
16
|
+
|
|
17
|
+
## [0.1.0] - 2026-11-13
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- The first release: MSM's customer screens for React (phone sign-in and registration with a Cloudflare Turnstile bot check, bookings with cancellation, memberships and passes, and details), themed by nine `--msm-customer-*` CSS properties, in one stylesheet, `@msm-platform/customer-react/style.css`.
|
|
22
|
+
- The screens' server half, `@msm-platform/customer-react/server`: a Fetch handler for your server that adds your application client's credentials, keeps the customer's session in an encrypted HttpOnly cookie, and requires a limiter store, a bot check and the client's IP address.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 MSM
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,148 @@
|
|
|
1
|
-
#
|
|
1
|
+
# MSM customer screens (`@msm-platform/customer-react`)
|
|
2
2
|
|
|
3
|
-
|
|
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.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @msm-platform/customer-react
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
It depends on `@msm-platform/customer-sdk`, which the server half calls the engine through, and on `libphonenumber-js` for the phone input. Versions are `0.x` until engine 1.0.0: a breaking change raises the minor version (`0.1.x` → `0.2.0`) and is marked **Breaking** in [CHANGELOG.md](CHANGELOG.md), so a caret range such as `^0.1.0` takes only compatible releases.
|
|
10
|
+
|
|
11
|
+
## Public API
|
|
12
|
+
|
|
13
|
+
What the changelog treats as breaking to rename or remove: the exports of `.` and `./server` and the stylesheet `./style.css`; the props below, including `brand: {name, logo}`, `botCheck: {provider: "turnstile", siteKey}` and the `screen` values `businesses`, `{businessId}`, `{businessId, eventTypeId}`, `bookings`, `passes` and `details` (a new value is additive; renaming or removing one, or changing the default `businesses`, is breaking); the nine `--msm-customer-*` properties ([Theming](#theming)); the server half's options and routes, including the `botCheckToken` field; and `readCustomerSession`. Another bot-check provider would be an additive member of `botCheck`'s union; renaming `"turnstile"` or `botCheckToken` is breaking. The server half's `limiter`, `botCheck` and `clientIp` are required in every environment, and `createCustomerHandler` throws when one is missing.
|
|
14
|
+
|
|
15
|
+
## The screens
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import "@msm-platform/customer-react/style.css";
|
|
19
|
+
import { MsmCustomer } from "@msm-platform/customer-react";
|
|
20
|
+
|
|
21
|
+
<MsmCustomer
|
|
22
|
+
basePath="/msm"
|
|
23
|
+
brand={{ name: "Demo Studio", logo: "/logo.svg" }}
|
|
24
|
+
botCheck={{
|
|
25
|
+
provider: "turnstile",
|
|
26
|
+
siteKey: process.env.NEXT_PUBLIC_TURNSTILE_SITE_KEY,
|
|
27
|
+
}}
|
|
28
|
+
/>;
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
| Prop | Meaning |
|
|
32
|
+
| ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
33
|
+
| `basePath` | Where the server half is mounted, such as `/msm`. The screens call only `${basePath}/auth/*` and `${basePath}/engine/web/*`, with `X-MSM-BFF: 1`. |
|
|
34
|
+
| `brand` | Optional `{name, logo}` for the header and sign-in. Loading it is the host's job. Colours come from CSS ([Theming](#theming)). |
|
|
35
|
+
| `botCheck` | Required: `{ provider: "turnstile", siteKey }`, the partner's Cloudflare Turnstile site key. A plain object, so a server component can pass it. |
|
|
36
|
+
| `screen`, `onNavigate` | `businesses` (the default), `{ businessId }`, `{ businessId, eventTypeId }`, `bookings`, `passes` or `details`. Leave both out and the package switches screens itself; pass both to drive it from the host's URL or router, which also lets the partner's own pages link straight to a business or one of its event types. |
|
|
37
|
+
|
|
38
|
+
The browser holds no credentials: the server half adds the client's and keeps the session in an encrypted HttpOnly cookie.
|
|
39
|
+
|
|
40
|
+
### Booking
|
|
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.
|
|
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.
|
|
45
|
+
|
|
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
|
+
|
|
48
|
+
## Theming
|
|
49
|
+
|
|
50
|
+
Styles are scoped under `.msm-customer` with no global reset, in the one stylesheet above, which includes the phone input's. The screens take the height of their content, so they sit inside the partner's page. A partner themes them with these CSS custom properties on `.msm-customer` or an ancestor. They are public API: renaming one is a breaking change.
|
|
51
|
+
|
|
52
|
+
| Property | Covers | Default |
|
|
53
|
+
| ---------------------------- | ------------------------- | ----------------------------------------- |
|
|
54
|
+
| `--msm-customer-accent` | The brand colour | `#235b4b` |
|
|
55
|
+
| `--msm-customer-accent-text` | Text on the accent | `#fff` |
|
|
56
|
+
| `--msm-customer-text` | Body text | `#202e2b` |
|
|
57
|
+
| `--msm-customer-muted` | Secondary text | `#66736c` |
|
|
58
|
+
| `--msm-customer-border` | Borders | `#dce2db` for cards, `#c9d1c8` for fields |
|
|
59
|
+
| `--msm-customer-background` | Page background | `#f6f7f4` |
|
|
60
|
+
| `--msm-customer-surface` | Card and panel background | `#fff` |
|
|
61
|
+
| `--msm-customer-font` | Font family | `inherit` |
|
|
62
|
+
| `--msm-customer-radius` | Corner radius | `6px` (cards a third larger) |
|
|
63
|
+
|
|
64
|
+
```css
|
|
65
|
+
.msm-customer {
|
|
66
|
+
--msm-customer-accent: #7a2e8f;
|
|
67
|
+
--msm-customer-font: "Inter", sans-serif;
|
|
68
|
+
--msm-customer-radius: 12px;
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
They also theme the phone input inside the screens. Error and warning colours stay fixed.
|
|
73
|
+
|
|
74
|
+
## The server half (`@msm-platform/customer-react/server`)
|
|
75
|
+
|
|
76
|
+
A Fetch API handler, `Request` in and `Response` out, for the routes the screens call. It imports no React and no Node built-ins (only Fetch, WebCrypto and the customer SDK), so it runs in Next.js Route Handlers on Node or the edge, and in any other Fetch server. Mount it on one catch-all route under the screens' `basePath`:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
// app/msm/[...path]/route.ts
|
|
80
|
+
import {
|
|
81
|
+
createCustomerHandler,
|
|
82
|
+
redisLimiterStore,
|
|
83
|
+
turnstile,
|
|
84
|
+
} from "@msm-platform/customer-react/server";
|
|
85
|
+
import { createClient } from "redis";
|
|
86
|
+
|
|
87
|
+
const redis = await createClient({ url: process.env.REDIS_URL }).connect();
|
|
88
|
+
|
|
89
|
+
const handler = createCustomerHandler({
|
|
90
|
+
basePath: "/msm",
|
|
91
|
+
engineUrl: process.env.MSM_ENGINE_URL!,
|
|
92
|
+
clientId: process.env.MSM_CLIENT_ID!,
|
|
93
|
+
clientSecret: process.env.MSM_CLIENT_SECRET!,
|
|
94
|
+
sessionKeys: process.env.MSM_SESSION_KEYS!.split(","),
|
|
95
|
+
limiter: redisLimiterStore(redis),
|
|
96
|
+
botCheck: turnstile({ secretKey: process.env.TURNSTILE_SECRET_KEY! }),
|
|
97
|
+
clientIp: (request) => yourTrustedClientIp(request),
|
|
98
|
+
});
|
|
99
|
+
export {
|
|
100
|
+
handler as GET,
|
|
101
|
+
handler as POST,
|
|
102
|
+
handler as PATCH,
|
|
103
|
+
handler as PUT,
|
|
104
|
+
handler as DELETE,
|
|
105
|
+
};
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
| Option | Meaning |
|
|
109
|
+
| --------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
110
|
+
| `basePath` | Where the route is mounted; the screens' `basePath`. |
|
|
111
|
+
| `engineUrl`, `clientId`, `clientSecret` | The engine and the partner's website application client. It calls the engine through `@msm-platform/customer-sdk` in server mode, so the secret never leaves this server. |
|
|
112
|
+
| `sessionKeys` | One key or a list, each at least 32 bytes (`openssl rand -base64 32`). The first encrypts the cookie and every one decrypts, so to rotate put the new key first and keep the old one until its cookies expire. |
|
|
113
|
+
| `limiter` | Required. A `LimiterStore`: `redisLimiterStore(redis)` for a node-redis client, or `memoryLimiterStore()` for development and tests (it counts per process). |
|
|
114
|
+
| `botCheck` | Required. `turnstile({ secretKey })`, or any `(token, { ip, request }) => Promise<boolean>`. |
|
|
115
|
+
| `clientIp` | Required. The client's address, from what your platform guarantees. Return null when unknown, which refuses code requests. |
|
|
116
|
+
| `limits` | Code requests per phone (default 5 per 15 minutes) and per IP (default 5 per 10 minutes), counted together for sign-in and registration. |
|
|
117
|
+
| `limiterPrefix` | The limiter's key prefix, default `msm:customer:limit:`, for a Redis shared with other apps. |
|
|
118
|
+
|
|
119
|
+
**Never trust a header the client can set for `clientIp`.** The leftmost `X-Forwarded-For` entry is whatever the client sent, so anyone could pick a fresh address for every request. Use your platform's own client address, or the entry your trusted proxy appends, counted from the right.
|
|
120
|
+
|
|
121
|
+
### Routes
|
|
122
|
+
|
|
123
|
+
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.
|
|
124
|
+
|
|
125
|
+
| Route | Behaviour |
|
|
126
|
+
| ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
127
|
+
| `POST auth/initiate` `{phone, botCheckToken}` | Sends a sign-in code. Before the engine is called: the phone must be E.164, then the bot check (403 `BotCheckFailed`, or 503 `BotCheckUnavailable` when it cannot be made), the per-IP limit and the per-phone limit (429 `TooManyAttempts` with `Retry-After`). A limiter error or a wait over 1 s refuses with 503 `LimiterUnavailable`. |
|
|
128
|
+
| `POST auth/register/initiate` `{phone, name, botCheckToken}` | Sends a registration code, with the same checks and the same counters. |
|
|
129
|
+
| `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. |
|
|
130
|
+
| `GET auth/session` | `{sessionKey}`, or 401. |
|
|
131
|
+
| `POST auth/logout` | Revokes the session at the engine and clears the cookie. |
|
|
132
|
+
| `/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. |
|
|
133
|
+
|
|
134
|
+
Limiter keys hold SHA-256 hashes of the phone (as E.164) and the address (IPv4 as is, IPv6 by its /64), never the values themselves.
|
|
135
|
+
|
|
136
|
+
### Sessions
|
|
137
|
+
|
|
138
|
+
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.
|
|
139
|
+
|
|
140
|
+
`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.
|
|
141
|
+
|
|
142
|
+
## Development
|
|
143
|
+
|
|
144
|
+
Every string comes from the typed catalog in `src/i18n.ts` (`t(key)`); a new locale is a `Messages` object, which TypeScript makes supply every key. Dates and times use `Intl` in `en-GB` and the business's timezone from `GET /web/businesses`, or the browser's for a business that list does not include.
|
|
145
|
+
|
|
146
|
+
Tests: `pnpm exec vitest run packages/customer-react` from the root. The Redis store's tests use `REDIS_URL` when set, otherwise a throwaway `redis-server`.
|
|
147
|
+
|
|
148
|
+
The build bundles the private `@msm-platform/ui` (the phone input) into `dist/index.js` and its styles into `dist/style.css`; `ui` is a devDependency and the packed manifest has none. `pnpm test:packages` installs the packed package outside the workspace beside only the customer SDK and React. Releases follow the repository's [release runbook](https://github.com/Sveittur/msm-platform/blob/main/docs/runbooks/customer-react.md), and every release's changes are in [CHANGELOG.md](CHANGELOG.md).
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Business, Candidate } from "./client";
|
|
2
|
+
/** The candidate a customer chose to book, kept through sign-in. */
|
|
3
|
+
export interface Choice {
|
|
4
|
+
business: Business;
|
|
5
|
+
candidate: Candidate;
|
|
6
|
+
}
|
|
7
|
+
/** What the customer is booking: what, where, when and with whom. */
|
|
8
|
+
export declare function ChoiceSummary({ choice }: {
|
|
9
|
+
choice: Choice;
|
|
10
|
+
}): import("react").JSX.Element;
|
|
11
|
+
/**
|
|
12
|
+
* Books the chosen candidate for the signed-in customer: holds it at once,
|
|
13
|
+
* confirms it on the customer's word, then shows the booking with the same
|
|
14
|
+
* cancel step as the bookings screen. Refusals are in the package's words.
|
|
15
|
+
*/
|
|
16
|
+
export declare function Booking(props: {
|
|
17
|
+
choice: Choice;
|
|
18
|
+
onBack: () => void;
|
|
19
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CustomerBotCheck } from "./client";
|
|
2
|
+
/** True when the host passed a bot check this version of the screens can run. */
|
|
3
|
+
export declare function botCheckReady(botCheck: CustomerBotCheck | undefined): botCheck is CustomerBotCheck;
|
|
4
|
+
/**
|
|
5
|
+
* The bot check before a code is sent. It reports each token through
|
|
6
|
+
* `onToken` (undefined while there is none), and resets whenever `attempt`
|
|
7
|
+
* changes, because a token passes only once.
|
|
8
|
+
*/
|
|
9
|
+
export declare function BotCheckWidget(props: {
|
|
10
|
+
botCheck: CustomerBotCheck;
|
|
11
|
+
attempt: number;
|
|
12
|
+
onToken: (token: string | undefined) => void;
|
|
13
|
+
onUnavailable: () => void;
|
|
14
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { OwnBooking } from "./client";
|
|
2
|
+
/**
|
|
3
|
+
* Where a booking stands for cancelling at `now`: `open` before the late
|
|
4
|
+
* window, `late` from `lateCancellationFrom` until `cancellableUntil` (the
|
|
5
|
+
* engine still cancels, but late), `closed` from `cancellableUntil` on (the
|
|
6
|
+
* engine refuses with EventStarted), and `cancelled` once it is.
|
|
7
|
+
*/
|
|
8
|
+
export declare function cancellationState(booking: Pick<OwnBooking, "status" | "cancellableUntil" | "lateCancellationFrom">, now: Date): "open" | "late" | "closed" | "cancelled";
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type CustomerClient, type paths } from "@msm-platform/customer-sdk";
|
|
2
|
+
type Ok<Operation> = Operation extends {
|
|
3
|
+
responses: {
|
|
4
|
+
200: {
|
|
5
|
+
content: {
|
|
6
|
+
"application/json": infer Body;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
} ? Body : never;
|
|
11
|
+
export type OwnBooking = Ok<paths["/web/me/bookings"]["get"]>["items"][number];
|
|
12
|
+
export type Membership = Ok<paths["/web/me/memberships"]["get"]>[number];
|
|
13
|
+
export type Business = Ok<paths["/web/businesses"]["get"]>["items"][number];
|
|
14
|
+
export type MyDetails = Ok<paths["/web/me"]["get"]>;
|
|
15
|
+
export type EventType = Ok<paths["/web/businesses/{businessId}/event-types"]["get"]>["items"][number];
|
|
16
|
+
/** One booking candidate: a seat in a scheduled event or an open time slot. */
|
|
17
|
+
export type Candidate = Ok<paths["/web/businesses/{businessId}/availability"]["get"]>["items"][number];
|
|
18
|
+
/** The host's name and logo, which the host loads and passes in. */
|
|
19
|
+
export interface CustomerBrand {
|
|
20
|
+
name: string;
|
|
21
|
+
logo?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The bot check sign-in and registration pass before a code is sent; the
|
|
25
|
+
* server half verifies its token. Cloudflare Turnstile with the partner's
|
|
26
|
+
* site key today; another provider would be another member of this union.
|
|
27
|
+
*/
|
|
28
|
+
export type CustomerBotCheck = {
|
|
29
|
+
provider: "turnstile";
|
|
30
|
+
siteKey: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Marks a call as the portal's own; the BFF refuses its routes without it
|
|
34
|
+
* (BffHeaderRequired), which together with SameSite cookies blocks CSRF.
|
|
35
|
+
*/
|
|
36
|
+
export declare const portalFetch: typeof fetch;
|
|
37
|
+
export declare function post(basePath: string, path: string, body?: unknown): Promise<Response>;
|
|
38
|
+
/**
|
|
39
|
+
* The customer SDK in proxy mode against the BFF under `basePath`, which adds the client's
|
|
40
|
+
* credentials and the session from its HttpOnly cookie. The browser holds
|
|
41
|
+
* neither. `onUnauthorized` runs when the BFF has ended the session.
|
|
42
|
+
*/
|
|
43
|
+
export declare function createPortalClient(basePath: string, onUnauthorized: () => void): CustomerClient;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CustomerClient } from "@msm-platform/customer-sdk";
|
|
2
|
+
import type { Business } from "./client";
|
|
3
|
+
import type { MessageKey } from "./i18n";
|
|
4
|
+
/**
|
|
5
|
+
* The screen to show: the partner's businesses, one business (optionally
|
|
6
|
+
* narrowed to one event type), or one of the customer's account screens.
|
|
7
|
+
*/
|
|
8
|
+
export type CustomerScreen = "businesses" | "bookings" | "passes" | "details" | {
|
|
9
|
+
businessId: string;
|
|
10
|
+
eventTypeId?: string;
|
|
11
|
+
};
|
|
12
|
+
export interface Portal {
|
|
13
|
+
client: CustomerClient;
|
|
14
|
+
/** The partner's public businesses by ID; a business missing here is not public. */
|
|
15
|
+
businesses: Map<string, Business>;
|
|
16
|
+
/** Whether `businesses` is complete, still loading or failed to load. */
|
|
17
|
+
businessesStatus: "loading" | "ready" | "failed";
|
|
18
|
+
reloadBusinesses: () => void;
|
|
19
|
+
navigate: (screen: CustomerScreen) => void;
|
|
20
|
+
/** Ends the session on the server and returns to sign-in with this notice. */
|
|
21
|
+
signOut: (notice?: MessageKey) => Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
export declare const PortalContext: import("react").Context<Portal | null>;
|
|
24
|
+
export declare function usePortal(): Portal;
|
package/dist/i18n.d.ts
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
declare const en: {
|
|
2
|
+
readonly "app.loading": "Loading…";
|
|
3
|
+
readonly "app.loadFailed": "Something went wrong loading this page. Try again.";
|
|
4
|
+
readonly "app.retry": "Try again";
|
|
5
|
+
readonly "app.signedOut": "You were signed out because your session ended. Sign in again.";
|
|
6
|
+
readonly "app.signedOutEverywhere": "You were signed out on every device.";
|
|
7
|
+
readonly "nav.label": "Booking and my account";
|
|
8
|
+
readonly "nav.book": "Book";
|
|
9
|
+
readonly "nav.signIn": "Sign in";
|
|
10
|
+
readonly "nav.bookings": "Bookings";
|
|
11
|
+
readonly "nav.passes": "Passes";
|
|
12
|
+
readonly "nav.details": "My details";
|
|
13
|
+
readonly "nav.signOut": "Sign out";
|
|
14
|
+
readonly "signIn.heading": "Sign in";
|
|
15
|
+
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.";
|
|
19
|
+
readonly "register.name": "Your name";
|
|
20
|
+
readonly "register.toSignIn": "Already have an account? Sign in";
|
|
21
|
+
readonly "signIn.phone": "Phone number";
|
|
22
|
+
readonly "signIn.codeSent": "Enter the code we sent to {phone}.";
|
|
23
|
+
readonly "signIn.code": "Verification code";
|
|
24
|
+
readonly "signIn.sendCode": "Send code";
|
|
25
|
+
readonly "signIn.submit": "Sign in";
|
|
26
|
+
readonly "register.submit": "Create account";
|
|
27
|
+
readonly "signIn.wait": "Please wait…";
|
|
28
|
+
readonly "signIn.differentNumber": "Use a different number";
|
|
29
|
+
readonly "signIn.error.tooMany": "Too many codes requested. Try again in about {wait}.";
|
|
30
|
+
readonly "signIn.error.tooManyLater": "Too many codes requested. Try again later.";
|
|
31
|
+
readonly "signIn.error.paused": "Sign-in codes are paused for now. Try again in about {wait}.";
|
|
32
|
+
readonly "signIn.error.pausedLater": "Sign-in codes are paused for now. Try again later.";
|
|
33
|
+
readonly "signIn.error.destination": "This number can't receive sign-in codes.";
|
|
34
|
+
readonly "signIn.error.badCode": "That code is incorrect or has expired, or this number has no account yet.";
|
|
35
|
+
readonly "register.error.badCode": "That code is incorrect or has expired, or this number already has an account.";
|
|
36
|
+
readonly "signIn.error.invalid": "Check the phone number and try again.";
|
|
37
|
+
readonly "signIn.error.refused": "This number can't sign in here.";
|
|
38
|
+
readonly "signIn.error.unreachable": "The sign-in service is unreachable. Try again shortly.";
|
|
39
|
+
readonly "signIn.error.failed": "Sign-in failed. Try again shortly.";
|
|
40
|
+
readonly "signIn.error.botCheck": "We couldn't confirm you're a person. Complete the check and try again.";
|
|
41
|
+
readonly "signIn.error.botCheckUnavailable": "The security check is unavailable. Try again shortly.";
|
|
42
|
+
readonly "signIn.error.notConfigured": "Sign-in isn't set up on this site yet.";
|
|
43
|
+
readonly "wait.seconds.one": "{count} second";
|
|
44
|
+
readonly "wait.seconds.other": "{count} seconds";
|
|
45
|
+
readonly "wait.minutes.one": "{count} minute";
|
|
46
|
+
readonly "wait.minutes.other": "{count} minutes";
|
|
47
|
+
readonly "wait.hours.one": "{count} hour";
|
|
48
|
+
readonly "wait.hours.other": "{count} hours";
|
|
49
|
+
readonly "bookings.heading": "Bookings";
|
|
50
|
+
readonly "bookings.period": "Which bookings";
|
|
51
|
+
readonly "bookings.upcoming": "Upcoming";
|
|
52
|
+
readonly "bookings.past": "Past";
|
|
53
|
+
readonly "bookings.emptyUpcoming": "You have no upcoming bookings.";
|
|
54
|
+
readonly "bookings.emptyPast": "You have no past bookings.";
|
|
55
|
+
readonly "bookings.more": "Show more";
|
|
56
|
+
readonly "bookings.when": "{start} – {end}";
|
|
57
|
+
readonly "bookings.cancelled": "Cancelled";
|
|
58
|
+
readonly "bookings.cancelledLate": "Cancelled late";
|
|
59
|
+
readonly "bookings.attended": "Attended";
|
|
60
|
+
readonly "bookings.noShow": "Missed";
|
|
61
|
+
readonly "bookings.lateFrom": "Late cancellation from {time}";
|
|
62
|
+
readonly "bookings.started": "This booking can no longer be cancelled because the event has started.";
|
|
63
|
+
readonly "bookings.cancel": "Cancel booking";
|
|
64
|
+
readonly "bookings.confirmHeading": "Cancel this booking?";
|
|
65
|
+
readonly "bookings.confirmLate": "This is a late cancellation: the cancellation window has closed.";
|
|
66
|
+
readonly "bookings.confirmCredit": "The pass credit you used for this booking stays spent.";
|
|
67
|
+
readonly "bookings.confirm": "Yes, cancel";
|
|
68
|
+
readonly "bookings.keep": "Keep booking";
|
|
69
|
+
readonly "bookings.cancelling": "Cancelling…";
|
|
70
|
+
readonly "bookings.doneOnTime": "Your booking is cancelled.";
|
|
71
|
+
readonly "bookings.doneLate": "Your booking is cancelled. It counts as a late cancellation.";
|
|
72
|
+
readonly "bookings.cancelFailed": "The booking could not be cancelled. Try again.";
|
|
73
|
+
readonly "bookings.gone": "This booking no longer exists.";
|
|
74
|
+
readonly "businesses.heading": "Book";
|
|
75
|
+
readonly "businesses.intro": "Choose where you'd like to book.";
|
|
76
|
+
readonly "businesses.empty": "No businesses take bookings here yet.";
|
|
77
|
+
readonly "businesses.open": "See times";
|
|
78
|
+
readonly "business.all": "All businesses";
|
|
79
|
+
readonly "business.notFound": "This business isn't taking bookings here.";
|
|
80
|
+
readonly "business.types": "Services";
|
|
81
|
+
readonly "business.allTypes": "Everything";
|
|
82
|
+
readonly "business.typeMissing": "This service can't be booked here.";
|
|
83
|
+
readonly "business.minutes": "{minutes} min";
|
|
84
|
+
readonly "business.week": "Which week";
|
|
85
|
+
readonly "business.previousWeek": "Previous week";
|
|
86
|
+
readonly "business.nextWeek": "Next week";
|
|
87
|
+
readonly "business.weekOf": "{from} – {to}";
|
|
88
|
+
readonly "business.empty": "Nothing is open in these days.";
|
|
89
|
+
readonly "business.seatsLeft.one": "{count} seat left";
|
|
90
|
+
readonly "business.seatsLeft.other": "{count} seats left";
|
|
91
|
+
readonly "business.full": "Full";
|
|
92
|
+
readonly "business.openTime": "Open time";
|
|
93
|
+
readonly "business.with": "With {resource}";
|
|
94
|
+
readonly "business.book": "Book";
|
|
95
|
+
readonly "book.heading": "Your booking";
|
|
96
|
+
readonly "book.signInFirst": "Sign in or create an account to book this time.";
|
|
97
|
+
readonly "book.back": "Choose another time";
|
|
98
|
+
readonly "book.reserving": "Holding this time for you…";
|
|
99
|
+
readonly "book.heldUntil": "We're holding this time for you until {time}.";
|
|
100
|
+
readonly "book.confirm": "Confirm booking";
|
|
101
|
+
readonly "book.confirming": "Confirming…";
|
|
102
|
+
readonly "book.booked": "You're booked.";
|
|
103
|
+
readonly "book.toBookings": "See all my bookings";
|
|
104
|
+
readonly "book.reserveAgain": "Hold this time again";
|
|
105
|
+
readonly "book.full": "This class is full now. Choose another time.";
|
|
106
|
+
readonly "book.slotTaken": "Someone has just taken this time. Choose another.";
|
|
107
|
+
readonly "book.limit": "You already hold the most unconfirmed bookings allowed. Confirm one, or wait a few minutes for an unconfirmed one to lapse, then try again.";
|
|
108
|
+
readonly "book.expired": "We held this time for as long as we could, and it has lapsed. Hold it again if it's still free.";
|
|
109
|
+
readonly "book.notAllowed": "Booking this needs a membership or pass that covers it. Ask the business.";
|
|
110
|
+
readonly "book.unavailable": "This time can no longer be booked. Choose another.";
|
|
111
|
+
readonly "book.refused": "This business can't take your booking. Contact them.";
|
|
112
|
+
readonly "book.failed": "The booking could not be made. Try again.";
|
|
113
|
+
readonly "passes.heading": "Memberships and passes";
|
|
114
|
+
readonly "passes.empty": "You have no memberships or passes.";
|
|
115
|
+
readonly "passes.unlimited": "Unlimited";
|
|
116
|
+
readonly "passes.credits": "Credits left: {remaining} of {total}";
|
|
117
|
+
readonly "passes.validFrom": "Valid from {date}";
|
|
118
|
+
readonly "passes.validRange": "Valid {from} – {until}";
|
|
119
|
+
readonly "passes.expired": "Expired";
|
|
120
|
+
readonly "details.heading": "My details";
|
|
121
|
+
readonly "details.name": "Name";
|
|
122
|
+
readonly "details.phone": "Phone";
|
|
123
|
+
readonly "details.email": "Email";
|
|
124
|
+
readonly "details.none": "Not set";
|
|
125
|
+
readonly "details.readOnly": "Ask the business to change your phone or email.";
|
|
126
|
+
readonly "details.save": "Save";
|
|
127
|
+
readonly "details.saving": "Saving…";
|
|
128
|
+
readonly "details.saved": "Your name is saved.";
|
|
129
|
+
readonly "details.saveFailed": "Your name could not be saved. Try again.";
|
|
130
|
+
readonly "details.signOutEverywhere": "Sign out everywhere";
|
|
131
|
+
readonly "details.signOutEverywhereHint": "Ends your sessions on every phone and computer, including this one.";
|
|
132
|
+
readonly "details.signOutEverywhereFailed": "Could not sign out everywhere. Try again.";
|
|
133
|
+
};
|
|
134
|
+
export type MessageKey = keyof typeof en;
|
|
135
|
+
export type Messages = Record<MessageKey, string>;
|
|
136
|
+
type PluralBase = {
|
|
137
|
+
[K in MessageKey]: K extends `${infer Base}.other` ? Base : never;
|
|
138
|
+
}[MessageKey];
|
|
139
|
+
/** The active locale. The MVP is English, formatted as en-GB. */
|
|
140
|
+
export declare const locale = "en-GB";
|
|
141
|
+
type Params = Record<string, string | number>;
|
|
142
|
+
/** The message for `key`, with `{name}` placeholders filled from `params`. */
|
|
143
|
+
export declare function t(key: MessageKey, params?: Params): string;
|
|
144
|
+
/** A plural message chosen by `count`, which also fills `{count}`. */
|
|
145
|
+
export declare function tp(base: PluralBase, count: number, params?: Params): string;
|
|
146
|
+
export declare function formatNumber(value: number): string;
|
|
147
|
+
/**
|
|
148
|
+
* Date and time in a business's timezone, or the browser's when the business
|
|
149
|
+
* is unknown (`timeZone` undefined).
|
|
150
|
+
*/
|
|
151
|
+
export declare function formatDateTime(iso: string, timeZone?: string): string;
|
|
152
|
+
export declare function formatTime(iso: string, timeZone?: string): string;
|
|
153
|
+
export declare function formatDate(iso: string, timeZone?: string): string;
|
|
154
|
+
/** A day as a heading, such as "Tuesday 1 December", in `timeZone`. */
|
|
155
|
+
export declare function formatDay(iso: string, timeZone?: string): string;
|
|
156
|
+
/** A start and end, with the end's date left out when both fall on one day. */
|
|
157
|
+
export declare function formatRange(start: string, end: string, timeZone?: string): string;
|
|
158
|
+
/** Seconds under a minute, minutes under an hour, hours beyond that. */
|
|
159
|
+
export declare function formatWait(seconds: number): string;
|
|
160
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import "./style.css";
|
|
2
|
+
import { type CustomerBotCheck, type CustomerBrand } from "./client";
|
|
3
|
+
import { type CustomerScreen } from "./context";
|
|
4
|
+
export { cancellationState } from "./cancellation";
|
|
5
|
+
export type { CustomerBotCheck, CustomerBrand } from "./client";
|
|
6
|
+
export type { CustomerScreen } from "./context";
|
|
7
|
+
export { formatDate, formatDateTime, formatNumber, locale, type MessageKey, type Messages, t, } from "./i18n";
|
|
8
|
+
export interface MsmCustomerProps {
|
|
9
|
+
/**
|
|
10
|
+
* Where the server half (`@msm-platform/customer-react/server`) is mounted,
|
|
11
|
+
* such as `/msm`: the package calls only `${basePath}/auth/*` and
|
|
12
|
+
* `${basePath}/engine/web/*`.
|
|
13
|
+
*/
|
|
14
|
+
basePath: string;
|
|
15
|
+
/** The host's name and logo for the header and sign-in; the host loads it. */
|
|
16
|
+
brand?: CustomerBrand;
|
|
17
|
+
/**
|
|
18
|
+
* The bot check before a code is sent, such as
|
|
19
|
+
* `{ provider: "turnstile", siteKey }`; the server half checks its token.
|
|
20
|
+
*/
|
|
21
|
+
botCheck: CustomerBotCheck;
|
|
22
|
+
/**
|
|
23
|
+
* The screen to show: `businesses` (the default), a business as
|
|
24
|
+
* `{ businessId }` or one of its event types as `{ businessId, eventTypeId }`,
|
|
25
|
+
* or `bookings`, `passes` or `details`. Leave both this and `onNavigate`
|
|
26
|
+
* out to let the package switch screens itself; pass both to drive it from
|
|
27
|
+
* the host's router or URL.
|
|
28
|
+
*/
|
|
29
|
+
screen?: CustomerScreen;
|
|
30
|
+
onNavigate?: (screen: CustomerScreen) => void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* MSM's customer screens: the partner's businesses with their times to
|
|
34
|
+
* book, phone sign-in and registration when a booking or account screen
|
|
35
|
+
* needs it, then the customer's bookings, passes and details. The server
|
|
36
|
+
* half keeps the session in an encrypted HttpOnly cookie; the browser holds
|
|
37
|
+
* no credentials. Nothing here runs before mount, so it renders on a server
|
|
38
|
+
* and imports without a browser.
|
|
39
|
+
*/
|
|
40
|
+
export declare function MsmCustomer(props: MsmCustomerProps): import("react").JSX.Element;
|