@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.
@@ -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 type { Channel, ConfirmRequest, Confirmation, Hold, Locale, PublicRoom, PublicSite, RoomAvailability } from './types';
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?: 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;
@@ -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
- export type Locale = 'es' | 'ca' | 'en';
7
- export type Localized = Partial<Record<Locale, string>>;
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: Locale;
110
- locales: Locale[];
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
- locale?: Locale;
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.1.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/",