@msm-platform/customer-react 0.2.0 → 0.3.1
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 +12 -0
- package/README.md +51 -27
- package/dist/account.d.ts +28 -0
- package/dist/booking-flow.d.ts +61 -0
- package/dist/booking.d.ts +5 -1
- package/dist/client.d.ts +2 -0
- package/dist/context.d.ts +5 -0
- package/dist/i18n.d.ts +13 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +1119 -619
- package/dist/layout.d.ts +8 -0
- package/dist/portal.d.ts +26 -0
- package/dist/screens/business.d.ts +71 -2
- package/dist/server/index.d.ts +8 -29
- package/dist/server.js +125 -252
- package/dist/session.d.ts +10 -0
- package/dist/sign-in-standalone.d.ts +26 -0
- package/dist/sign-in.d.ts +4 -0
- package/dist/style.css +1 -1
- package/package.json +2 -2
- package/dist/server/limits.d.ts +0 -44
- package/dist/server/turnstile.d.ts +0 -22
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 {};
|
package/dist/portal.d.ts
ADDED
|
@@ -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" | "nav.label" | "nav.book" | "nav.signIn" | "nav.bookings" | "nav.passes" | "nav.details" | "nav.signOut" | "signIn.heading" | "signIn.intro" | "signIn.toRegister" | "register.heading" | "register.intro" | "register.name" | "register.toSignIn" | "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.badCode" | "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,80 @@
|
|
|
1
|
-
import
|
|
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
|
+
displayName: string;
|
|
13
|
+
email: string | null;
|
|
14
|
+
id: string;
|
|
15
|
+
latitude: number | null;
|
|
16
|
+
logoAssetId: string | null;
|
|
17
|
+
longitude: number | null;
|
|
18
|
+
phone: string | null;
|
|
19
|
+
timezone: string;
|
|
20
|
+
} | null | undefined;
|
|
21
|
+
types: {
|
|
22
|
+
cancellationCutoffMinutes: number | null;
|
|
23
|
+
categoryId: string | null;
|
|
24
|
+
description: string | null;
|
|
25
|
+
displayName: string;
|
|
26
|
+
durationMinutes: number;
|
|
27
|
+
id: string;
|
|
28
|
+
imageAssetId: string | null;
|
|
29
|
+
requiresAccess: boolean;
|
|
30
|
+
resources: {
|
|
31
|
+
description: string | null;
|
|
32
|
+
displayName: string;
|
|
33
|
+
id: string;
|
|
34
|
+
}[];
|
|
35
|
+
timeSlotBooking: boolean;
|
|
36
|
+
}[] | undefined;
|
|
37
|
+
failed: boolean;
|
|
38
|
+
reload: () => Promise<void>;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* The screen for a catalog that has not loaded: it failed, the business is
|
|
42
|
+
* not public here, or it is still loading. Undefined once it has loaded.
|
|
43
|
+
*/
|
|
44
|
+
export declare function pendingCatalog(catalog: Catalog, back: ReactNode): import("react").JSX.Element | undefined;
|
|
45
|
+
/** The resources that provide `types`, each once, in the order they appear. */
|
|
46
|
+
export declare function resourcesOf(types: EventType[]): {
|
|
47
|
+
description: string | null;
|
|
48
|
+
displayName: string;
|
|
49
|
+
id: string;
|
|
50
|
+
}[];
|
|
51
|
+
/** The filters the business screen shows, when its host drives them. */
|
|
52
|
+
export interface BusinessFilter {
|
|
53
|
+
eventTypeId?: string;
|
|
54
|
+
resourceId?: string;
|
|
55
|
+
}
|
|
2
56
|
/**
|
|
3
57
|
* A business: its details, its event types as filters, and a week of its
|
|
4
58
|
* availability, events with seats and open time slots in one list, in the
|
|
5
|
-
* business's timezone. Choosing a candidate starts booking it.
|
|
59
|
+
* business's timezone. Choosing a candidate starts booking it. With
|
|
60
|
+
* `onFilter`, it also filters by resource, and both filters call it instead
|
|
61
|
+
* of navigating.
|
|
6
62
|
*/
|
|
7
63
|
export declare function Business(props: {
|
|
8
64
|
businessId: string;
|
|
9
65
|
eventTypeId: string | undefined;
|
|
66
|
+
resourceId?: string | undefined;
|
|
67
|
+
onFilter?: ((filter: BusinessFilter) => void) | undefined;
|
|
10
68
|
onChoose: (business: BusinessDto, candidate: Candidate) => void;
|
|
69
|
+
}): import("react").JSX.Element | undefined;
|
|
70
|
+
/** An event type's name, description and length, above its times. */
|
|
71
|
+
export declare function TypeDetails({ type }: {
|
|
72
|
+
type: EventType;
|
|
73
|
+
}): import("react").JSX.Element;
|
|
74
|
+
export declare function Availability(props: {
|
|
75
|
+
business: BusinessDto;
|
|
76
|
+
eventTypeId: string | undefined;
|
|
77
|
+
resourceId?: string | undefined;
|
|
78
|
+
onChoose: (candidate: Candidate) => void;
|
|
11
79
|
}): import("react").JSX.Element;
|
|
80
|
+
export {};
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
import { type LimiterStore } from "./limits";
|
|
2
|
-
import type { BotCheckVerifier } from "./turnstile";
|
|
3
|
-
export { type LimiterStore, memoryLimiterStore, type RedisEvalClient, redisLimiterStore, } from "./limits";
|
|
4
1
|
export { type CustomerSession, customerSessionCookie, readCustomerSession, } from "./session";
|
|
5
|
-
export { type BotCheckVerifier, turnstile } from "./turnstile";
|
|
6
|
-
/** At most `max` attempts per key in a fixed window of `windowMs`. */
|
|
7
|
-
export interface Limit {
|
|
8
|
-
max: number;
|
|
9
|
-
windowMs: number;
|
|
10
|
-
}
|
|
11
2
|
export interface CustomerHandlerOptions {
|
|
12
3
|
/** Where the handler is mounted, such as `/msm`; the screens' `basePath`. */
|
|
13
4
|
basePath: string;
|
|
@@ -22,27 +13,14 @@ export interface CustomerHandlerOptions {
|
|
|
22
13
|
* a new key goes first and the old one stays until its cookies expire.
|
|
23
14
|
*/
|
|
24
15
|
sessionKeys: string | readonly string[];
|
|
25
|
-
/** Counts code requests per IP and per phone; shared by every server instance. */
|
|
26
|
-
limiter: LimiterStore;
|
|
27
|
-
/** Checks the screens' `botCheckToken`, such as `turnstile({ secretKey })`. */
|
|
28
|
-
botCheck: BotCheckVerifier;
|
|
29
16
|
/**
|
|
30
|
-
* The
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
17
|
+
* The visitor's IP address, which the engine limits code requests by. Read
|
|
18
|
+
* it from what your platform guarantees, such as the address your trusted
|
|
19
|
+
* proxy appends: a header the visitor can set, like the leftmost
|
|
20
|
+
* `X-Forwarded-For` entry, lets anyone pick their own limit. Return null
|
|
21
|
+
* when it is unknown, which refuses code requests.
|
|
34
22
|
*/
|
|
35
23
|
clientIp: (request: Request) => string | null | undefined | Promise<string | null | undefined>;
|
|
36
|
-
/**
|
|
37
|
-
* Code requests (sign-in and registration together) per phone, default 5
|
|
38
|
-
* per 15 minutes, and per IP, default 5 per 10 minutes.
|
|
39
|
-
*/
|
|
40
|
-
limits?: {
|
|
41
|
-
phone?: Limit;
|
|
42
|
-
ip?: Limit;
|
|
43
|
-
};
|
|
44
|
-
/** Prefix of the limiter's keys; default `msm:customer:limit:`. */
|
|
45
|
-
limiterPrefix?: string;
|
|
46
24
|
fetch?: typeof globalThis.fetch;
|
|
47
25
|
}
|
|
48
26
|
/**
|
|
@@ -50,8 +28,9 @@ export interface CustomerHandlerOptions {
|
|
|
50
28
|
* catch-all route such as `app/msm/[...path]/route.ts`:
|
|
51
29
|
*
|
|
52
30
|
* - `POST auth/initiate` `{phone, botCheckToken}` and
|
|
53
|
-
* `POST auth/register/initiate` `{phone, name, botCheckToken}`
|
|
54
|
-
*
|
|
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;
|
|
55
34
|
* - `POST auth/login` and `POST auth/register` `{challenge, code}` redeem it
|
|
56
35
|
* once, never retried, and set the encrypted session cookie;
|
|
57
36
|
* - `GET auth/session` and `POST auth/logout`;
|