@mrcharles/sdk 0.1.0 → 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/README.md +20 -1
- package/dist/mrcharles.esm.js +685 -19
- package/dist/mrcharles.esm.js.map +12 -10
- package/dist/mrcharles.min.js +2 -2
- package/dist/mrcharles.min.js.map +12 -10
- package/dist/types/client.d.ts +16 -0
- package/dist/types/embed.d.ts +3 -1
- package/dist/types/env.d.ts +7 -1
- package/dist/types/format.d.ts +24 -0
- package/dist/types/http.d.ts +1 -1
- package/dist/types/i18n.d.ts +50 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/links.d.ts +4 -3
- package/dist/types/rooms.d.ts +15 -3
- package/dist/types/types.d.ts +8 -5
- package/package.json +1 -1
package/dist/types/rooms.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Http } from './http';
|
|
2
2
|
import { MrCharlesError } from './errors';
|
|
3
3
|
import type { Links } from './links';
|
|
4
|
-
import
|
|
4
|
+
import { type Locale, type LocaleInput } from './i18n';
|
|
5
|
+
import type { Channel, ConfirmRequest, Confirmation, Hold, PublicRoom, PublicSite, RoomAvailability } from './types';
|
|
5
6
|
export type RoomStep = 'slot' | 'details' | 'verify' | 'pay' | 'done' | 'expired';
|
|
6
7
|
export interface RoomBookingState {
|
|
7
8
|
step: RoomStep;
|
|
@@ -12,7 +13,11 @@ export interface RoomBookingState {
|
|
|
12
13
|
confirmation: Confirmation | null;
|
|
13
14
|
/** Last error from any action; cleared on the next successful one */
|
|
14
15
|
error: MrCharlesError | null;
|
|
16
|
+
/** `error` as a sentence in the flow's language — show this one. */
|
|
17
|
+
errorMessage: string | null;
|
|
15
18
|
busy: boolean;
|
|
19
|
+
/** Language of the flow's strings and of the guest's messages. */
|
|
20
|
+
locale: Locale;
|
|
16
21
|
}
|
|
17
22
|
export interface GuestDetails {
|
|
18
23
|
date: string;
|
|
@@ -21,7 +26,8 @@ export interface GuestDetails {
|
|
|
21
26
|
guestName: string;
|
|
22
27
|
channel: Channel;
|
|
23
28
|
contact: string;
|
|
24
|
-
locale
|
|
29
|
+
/** Language of the guest's code and confirmation; defaults to the flow's locale. */
|
|
30
|
+
locale?: LocaleInput;
|
|
25
31
|
captchaToken?: string;
|
|
26
32
|
}
|
|
27
33
|
export interface RoomBookingOptions {
|
|
@@ -29,6 +35,8 @@ export interface RoomBookingOptions {
|
|
|
29
35
|
roomId: string;
|
|
30
36
|
/** Called on every state change */
|
|
31
37
|
onChange?: (state: RoomBookingState) => void;
|
|
38
|
+
/** Language for strings, errors and the guest's messages. Defaults to the client's locale, then the site's default. */
|
|
39
|
+
locale?: LocaleInput;
|
|
32
40
|
}
|
|
33
41
|
export interface RoomBooking {
|
|
34
42
|
readonly state: RoomBookingState;
|
|
@@ -55,10 +63,14 @@ export interface RoomBooking {
|
|
|
55
63
|
/** Forget the hold and start over (new idempotency key). Keeps site and availability. */
|
|
56
64
|
reset(): void;
|
|
57
65
|
destroy(): void;
|
|
66
|
+
/** Translate a UI string in the flow's language: `flow.t('action.confirm')`. */
|
|
67
|
+
t(key: string, params?: Record<string, string | number>): string;
|
|
68
|
+
/** Switch language mid-flow (a language switcher on the page). */
|
|
69
|
+
setLocale(locale: LocaleInput): void;
|
|
58
70
|
}
|
|
59
71
|
/**
|
|
60
72
|
* The whole guest flow for one room as a small state machine: availability →
|
|
61
73
|
* hold → code → confirm, with the expiry timer, idempotency key and error
|
|
62
74
|
* classification handled. Render it with any UI.
|
|
63
75
|
*/
|
|
64
|
-
export declare function createRoomBooking(http: Http, links: Links, opts: RoomBookingOptions): RoomBooking;
|
|
76
|
+
export declare function createRoomBooking(http: Http, links: Links, opts: RoomBookingOptions, clientLocale?: () => LocaleInput | undefined): RoomBooking;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
* Mirrors apps/backend-api/internal/sites/dto.go and the lesson DTOs; the
|
|
4
4
|
* API adds fields without notice but never removes or renames one within v1.
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
export type
|
|
6
|
+
import type { HostedLocale, Locale } from './i18n';
|
|
7
|
+
export type { HostedLocale, Locale, LocaleInput } from './i18n';
|
|
8
|
+
/** Per-language strings from the site payload: `{ es, ca, en }`. Use `pick()` to read one. */
|
|
9
|
+
export type Localized = Partial<Record<HostedLocale, string>>;
|
|
8
10
|
export type PaymentMode = 'card' | 'on_site';
|
|
9
11
|
export type Channel = 'phone' | 'email';
|
|
10
12
|
export interface OperatingHours {
|
|
@@ -106,8 +108,8 @@ export interface PublicSiteConfig {
|
|
|
106
108
|
title: string;
|
|
107
109
|
description: string;
|
|
108
110
|
};
|
|
109
|
-
defaultLocale:
|
|
110
|
-
locales:
|
|
111
|
+
defaultLocale: HostedLocale;
|
|
112
|
+
locales: HostedLocale[];
|
|
111
113
|
status: string;
|
|
112
114
|
customDomain: string | null;
|
|
113
115
|
canonicalHost: string;
|
|
@@ -163,7 +165,8 @@ export interface HoldRequest {
|
|
|
163
165
|
channel: Channel;
|
|
164
166
|
/** E.164 phone (+34…) when channel is phone; an address when email */
|
|
165
167
|
contact: string;
|
|
166
|
-
|
|
168
|
+
/** Language of the code, confirmation and reminders. Hosted locales only; the SDK maps others for you. */
|
|
169
|
+
locale?: HostedLocale | Locale;
|
|
167
170
|
/** One per attempt; reuse it when retrying the same request */
|
|
168
171
|
idempotencyKey: string;
|
|
169
172
|
/** Required when the site payload has captchaSiteKey */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrcharles/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Mr Charles booking SDK \u2014 put studio room bookings and teacher lessons on any website.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://developers.mrcharles.app/integrate/sdk/",
|