@msm-platform/customer-sdk 0.1.1 → 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 CHANGED
@@ -4,6 +4,16 @@ All notable changes to `@msm-platform/customer-sdk`. The format follows [Keep a
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.2.0] - 2026-11-15
8
+
9
+ ### Changed
10
+
11
+ - **Breaking:** `initiateLogin` and `initiateRegistration` on `/web/identity/*` require `botCheckToken`, the Turnstile token the customer's browser got from your website's widget, and `clientIp`, the customer's IPv4 or IPv6 address as your trusted proxy reports it; without them the engine answers 400 `ValidationFailed`. The engine now checks the token with the Turnstile widget MSM owns for your website and limits code requests per address, so either can answer 403 `BotCheckFailed`, 429 `TooManyAttempts` with `Retry-After`, or 503 `BotCheckUnavailable` or `LimiterUnavailable` with `Retry-After`; no code is sent then.
12
+
13
+ ### Added
14
+
15
+ - The engine limits each application client to its own request rate, 3000 requests a minute by default, counted for your server's HTTP Basic calls and your customers' sessions together. Over it any operation answers 429 `RateLimited` with `Retry-After` in seconds (1 to 60, the rest of the minute); wait that long before retrying. `RateLimited`'s description in the contract now names this limit beside the load balancer's per-IP one.
16
+
7
17
  ## [0.1.1] - 2026-11-13
8
18
 
9
19
  ### Added
package/README.md CHANGED
@@ -20,7 +20,7 @@ const msm = createCustomerClient({
20
20
  });
21
21
  ```
22
22
 
23
- **Proxy mode** is for a browser or any code that must not hold the secret. Give it only a base URL and, if needed, a custom `fetch`, and put a proxy on your server in front of the engine that adds the credentials. MSM's customer portal works this way through its BFF.
23
+ **Proxy mode** is for a browser or any code that must not hold the secret. Give it only a base URL and, if needed, a custom `fetch`, and put a proxy on your server in front of the engine that adds the credentials. MSM's customer screens (`@msm-platform/customer-react`) work this way, behind their server half on the partner's server.
24
24
 
25
25
  ```ts
26
26
  const msm = createCustomerClient({ baseUrl: "/msm", fetch: myFetch });
@@ -33,8 +33,10 @@ A customer signs in with a code sent by SMS. The session token is yours to store
33
33
  ```ts
34
34
  import { sessionHeaders } from "@msm-platform/customer-sdk";
35
35
 
36
+ // The Turnstile token the screens' widget gave the customer's browser, and the
37
+ // customer's address as your own trusted proxy reports it.
36
38
  const { data: started } = await msm.POST("/web/identity/initiateLogin", {
37
- body: { phone: "+3545550004" },
39
+ body: { phone: "+3545550004", botCheckToken, clientIp },
38
40
  });
39
41
  const { data: session } = await msm.POST("/web/identity/customerLogin", {
40
42
  body: { challenge: started!.challenge, code: "123456" },
@@ -51,7 +53,7 @@ const { data: booking } = await msm.POST(
51
53
  );
52
54
  ```
53
55
 
54
- A new customer registers the same way with `POST /web/identity/initiateRegistration` (`{ phone, name }`) and `POST /web/identity/registerCustomer`. `POST /web/identity/logout` with `{ sessionToken }` ends a session of your client. Sign-in, registration and logout are on `/web` and need your client's credentials, so call them from server mode or through your proxy; `/api` is not for website clients. A reservation holds the seat or slot for a few minutes; confirming it makes the booking.
56
+ The engine sends a code only after checking `botCheckToken` with the Turnstile widget MSM owns for your website (403 `BotCheckFailed`, or 503 `BotCheckUnavailable` when it cannot) and counting the request against `clientIp` (by default 5 code requests per address per 10 minutes, then 429 `TooManyAttempts` with `Retry-After`; 503 `LimiterUnavailable` when it cannot count). Never take `clientIp` from a header the customer can set, such as the leftmost `X-Forwarded-For` entry. A new customer registers the same way with `POST /web/identity/initiateRegistration` (`{ phone, name, botCheckToken, clientIp }`) and `POST /web/identity/registerCustomer`. `POST /web/identity/logout` with `{ sessionToken }` ends a session of your client. Sign-in, registration and logout are on `/web` and need your client's credentials, so call them from server mode or through your proxy; `/api` is not for website clients. A reservation holds the seat or slot for a few minutes; confirming it makes the booking.
55
57
 
56
58
  The same session reads the customer's own details, bookings and passes with every business of your partner, and ends all their sessions with your client:
57
59
 
@@ -95,7 +97,7 @@ The SDK never retries a request: a 401 throws, and the next call sends the same
95
97
 
96
98
  ## Next.js server example
97
99
 
98
- [`examples/customer-nextjs`](../../examples/customer-nextjs) in the repository is a Next.js App Router server that does all of the above with server actions: phone and code sign-in with the session in an HttpOnly cookie, the business's availability, and booking (reserve, then confirm). The SDK and the secret live only in server code (`lib/msm.ts`):
100
+ [`examples/customer-nextjs`](../../examples/customer-nextjs) in the repository is a Next.js App Router site, the partner starter. It serves MSM's customer screens for sign-in and the customer's account, and its own pages use the SDK in server mode with the session the screens signed in (read from their encrypted HttpOnly cookie): the business's availability, and booking (reserve, then confirm) with server actions. The SDK and the secret live only in server code (`lib/msm.ts`):
99
101
 
100
102
  ```ts
101
103
  // lib/msm.ts, imported only by server components and server actions
@@ -378,7 +378,7 @@ export interface operations {
378
378
  };
379
379
  };
380
380
  };
381
- /** @description - `RateLimited`: The load balancer's rate limit refused the request; retry after `Retry-After` seconds */
381
+ /** @description - `RateLimited`: A rate limit refused the request: the load balancer's per IP, or the engine's per application client; retry after `Retry-After` seconds */
382
382
  429: {
383
383
  headers: {
384
384
  /** @description Seconds to wait before sending the request again */
@@ -490,7 +490,7 @@ export interface operations {
490
490
  };
491
491
  };
492
492
  };
493
- /** @description - `RateLimited`: The load balancer's rate limit refused the request; retry after `Retry-After` seconds */
493
+ /** @description - `RateLimited`: A rate limit refused the request: the load balancer's per IP, or the engine's per application client; retry after `Retry-After` seconds */
494
494
  429: {
495
495
  headers: {
496
496
  /** @description Seconds to wait before sending the request again */
@@ -632,7 +632,7 @@ export interface operations {
632
632
  };
633
633
  };
634
634
  };
635
- /** @description - `RateLimited`: The load balancer's rate limit refused the request; retry after `Retry-After` seconds */
635
+ /** @description - `RateLimited`: A rate limit refused the request: the load balancer's per IP, or the engine's per application client; retry after `Retry-After` seconds */
636
636
  429: {
637
637
  headers: {
638
638
  /** @description Seconds to wait before sending the request again */
@@ -782,7 +782,7 @@ export interface operations {
782
782
  };
783
783
  };
784
784
  };
785
- /** @description - `RateLimited`: The load balancer's rate limit refused the request; retry after `Retry-After` seconds */
785
+ /** @description - `RateLimited`: A rate limit refused the request: the load balancer's per IP, or the engine's per application client; retry after `Retry-After` seconds */
786
786
  429: {
787
787
  headers: {
788
788
  /** @description Seconds to wait before sending the request again */
@@ -953,7 +953,7 @@ export interface operations {
953
953
  };
954
954
  };
955
955
  };
956
- /** @description - `RateLimited`: The load balancer's rate limit refused the request; retry after `Retry-After` seconds */
956
+ /** @description - `RateLimited`: A rate limit refused the request: the load balancer's per IP, or the engine's per application client; retry after `Retry-After` seconds */
957
957
  429: {
958
958
  headers: {
959
959
  /** @description Seconds to wait before sending the request again */
@@ -1074,7 +1074,7 @@ export interface operations {
1074
1074
  };
1075
1075
  };
1076
1076
  };
1077
- /** @description - `RateLimited`: The load balancer's rate limit refused the request; retry after `Retry-After` seconds */
1077
+ /** @description - `RateLimited`: A rate limit refused the request: the load balancer's per IP, or the engine's per application client; retry after `Retry-After` seconds */
1078
1078
  429: {
1079
1079
  headers: {
1080
1080
  /** @description Seconds to wait before sending the request again */
@@ -1267,7 +1267,7 @@ export interface operations {
1267
1267
  };
1268
1268
  };
1269
1269
  };
1270
- /** @description - `RateLimited`: The load balancer's rate limit refused the request; retry after `Retry-After` seconds */
1270
+ /** @description - `RateLimited`: A rate limit refused the request: the load balancer's per IP, or the engine's per application client; retry after `Retry-After` seconds */
1271
1271
  429: {
1272
1272
  headers: {
1273
1273
  /** @description Seconds to wait before sending the request again */
@@ -1454,7 +1454,7 @@ export interface operations {
1454
1454
  };
1455
1455
  };
1456
1456
  };
1457
- /** @description - `RateLimited`: The load balancer's rate limit refused the request; retry after `Retry-After` seconds */
1457
+ /** @description - `RateLimited`: A rate limit refused the request: the load balancer's per IP, or the engine's per application client; retry after `Retry-After` seconds */
1458
1458
  429: {
1459
1459
  headers: {
1460
1460
  /** @description Seconds to wait before sending the request again */
@@ -1580,7 +1580,7 @@ export interface operations {
1580
1580
  };
1581
1581
  };
1582
1582
  };
1583
- /** @description - `RateLimited`: The load balancer's rate limit refused the request; retry after `Retry-After` seconds */
1583
+ /** @description - `RateLimited`: A rate limit refused the request: the load balancer's per IP, or the engine's per application client; retry after `Retry-After` seconds */
1584
1584
  429: {
1585
1585
  headers: {
1586
1586
  /** @description Seconds to wait before sending the request again */
@@ -1618,6 +1618,10 @@ export interface operations {
1618
1618
  requestBody: {
1619
1619
  content: {
1620
1620
  "application/json": {
1621
+ /** @description The Turnstile token the visitor's browser received from the application's widget */
1622
+ botCheckToken: string;
1623
+ /** @description The visitor's IP address, as the application's own trusted proxy reports it */
1624
+ clientIp: string;
1621
1625
  phone: string;
1622
1626
  };
1623
1627
  };
@@ -1667,7 +1671,10 @@ export interface operations {
1667
1671
  };
1668
1672
  };
1669
1673
  };
1670
- /** @description - `NotAuthorized`: The actor is not permitted to perform this operation */
1674
+ /**
1675
+ * @description - `BotCheckFailed`: The visitor's bot-check token did not pass the calling application's Turnstile widget
1676
+ * - `NotAuthorized`: The actor is not permitted to perform this operation
1677
+ */
1671
1678
  403: {
1672
1679
  headers: {
1673
1680
  [name: string]: unknown;
@@ -1675,7 +1682,7 @@ export interface operations {
1675
1682
  content: {
1676
1683
  "application/json": components["schemas"]["ErrorResponse"] & {
1677
1684
  /** @enum {string} */
1678
- code: "NotAuthorized";
1685
+ code: "BotCheckFailed" | "NotAuthorized";
1679
1686
  };
1680
1687
  };
1681
1688
  };
@@ -1716,7 +1723,8 @@ export interface operations {
1716
1723
  };
1717
1724
  };
1718
1725
  /**
1719
- * @description - `RateLimited`: The load balancer's rate limit refused the request; retry after `Retry-After` seconds
1726
+ * @description - `RateLimited`: A rate limit refused the request: the load balancer's per IP, or the engine's per application client; retry after `Retry-After` seconds
1727
+ * - `TooManyAttempts`: Too many sign-in codes were requested from this address; retry after `Retry-After` seconds
1720
1728
  * - `TooManyChallenges`: Too many sign-in codes were sent to this number; retry after `Retry-After` seconds
1721
1729
  */
1722
1730
  429: {
@@ -1728,7 +1736,7 @@ export interface operations {
1728
1736
  content: {
1729
1737
  "application/json": components["schemas"]["ErrorResponse"] & {
1730
1738
  /** @enum {string} */
1731
- code: "RateLimited" | "TooManyChallenges";
1739
+ code: "RateLimited" | "TooManyAttempts" | "TooManyChallenges";
1732
1740
  };
1733
1741
  };
1734
1742
  };
@@ -1745,7 +1753,9 @@ export interface operations {
1745
1753
  };
1746
1754
  };
1747
1755
  /**
1748
- * @description - `SmsBudgetExhausted`: The client's hourly SMS budget is used up; retry after `Retry-After` seconds
1756
+ * @description - `BotCheckUnavailable`: The bot check could not be made: Turnstile did not answer in time, or the calling application has no widget secret; retry after `Retry-After` seconds
1757
+ * - `LimiterUnavailable`: The per-address sign-in limit could not be counted; retry after `Retry-After` seconds
1758
+ * - `SmsBudgetExhausted`: The client's hourly SMS budget is used up; retry after `Retry-After` seconds
1749
1759
  * - `SmsDeliveryUnavailable`: The SMS could not be confirmed as sent; retry after `Retry-After` seconds
1750
1760
  */
1751
1761
  503: {
@@ -1757,7 +1767,7 @@ export interface operations {
1757
1767
  content: {
1758
1768
  "application/json": components["schemas"]["ErrorResponse"] & {
1759
1769
  /** @enum {string} */
1760
- code: "SmsBudgetExhausted" | "SmsDeliveryUnavailable";
1770
+ code: "BotCheckUnavailable" | "LimiterUnavailable" | "SmsBudgetExhausted" | "SmsDeliveryUnavailable";
1761
1771
  };
1762
1772
  };
1763
1773
  };
@@ -1773,6 +1783,10 @@ export interface operations {
1773
1783
  requestBody: {
1774
1784
  content: {
1775
1785
  "application/json": {
1786
+ /** @description The Turnstile token the visitor's browser received from the application's widget */
1787
+ botCheckToken: string;
1788
+ /** @description The visitor's IP address, as the application's own trusted proxy reports it */
1789
+ clientIp: string;
1776
1790
  name: string;
1777
1791
  phone: string;
1778
1792
  };
@@ -1823,7 +1837,10 @@ export interface operations {
1823
1837
  };
1824
1838
  };
1825
1839
  };
1826
- /** @description - `NotAuthorized`: The actor is not permitted to perform this operation */
1840
+ /**
1841
+ * @description - `BotCheckFailed`: The visitor's bot-check token did not pass the calling application's Turnstile widget
1842
+ * - `NotAuthorized`: The actor is not permitted to perform this operation
1843
+ */
1827
1844
  403: {
1828
1845
  headers: {
1829
1846
  [name: string]: unknown;
@@ -1831,7 +1848,7 @@ export interface operations {
1831
1848
  content: {
1832
1849
  "application/json": components["schemas"]["ErrorResponse"] & {
1833
1850
  /** @enum {string} */
1834
- code: "NotAuthorized";
1851
+ code: "BotCheckFailed" | "NotAuthorized";
1835
1852
  };
1836
1853
  };
1837
1854
  };
@@ -1872,7 +1889,8 @@ export interface operations {
1872
1889
  };
1873
1890
  };
1874
1891
  /**
1875
- * @description - `RateLimited`: The load balancer's rate limit refused the request; retry after `Retry-After` seconds
1892
+ * @description - `RateLimited`: A rate limit refused the request: the load balancer's per IP, or the engine's per application client; retry after `Retry-After` seconds
1893
+ * - `TooManyAttempts`: Too many sign-in codes were requested from this address; retry after `Retry-After` seconds
1876
1894
  * - `TooManyChallenges`: Too many sign-in codes were sent to this number; retry after `Retry-After` seconds
1877
1895
  */
1878
1896
  429: {
@@ -1884,7 +1902,7 @@ export interface operations {
1884
1902
  content: {
1885
1903
  "application/json": components["schemas"]["ErrorResponse"] & {
1886
1904
  /** @enum {string} */
1887
- code: "RateLimited" | "TooManyChallenges";
1905
+ code: "RateLimited" | "TooManyAttempts" | "TooManyChallenges";
1888
1906
  };
1889
1907
  };
1890
1908
  };
@@ -1901,7 +1919,9 @@ export interface operations {
1901
1919
  };
1902
1920
  };
1903
1921
  /**
1904
- * @description - `SmsBudgetExhausted`: The client's hourly SMS budget is used up; retry after `Retry-After` seconds
1922
+ * @description - `BotCheckUnavailable`: The bot check could not be made: Turnstile did not answer in time, or the calling application has no widget secret; retry after `Retry-After` seconds
1923
+ * - `LimiterUnavailable`: The per-address sign-in limit could not be counted; retry after `Retry-After` seconds
1924
+ * - `SmsBudgetExhausted`: The client's hourly SMS budget is used up; retry after `Retry-After` seconds
1905
1925
  * - `SmsDeliveryUnavailable`: The SMS could not be confirmed as sent; retry after `Retry-After` seconds
1906
1926
  */
1907
1927
  503: {
@@ -1913,7 +1933,7 @@ export interface operations {
1913
1933
  content: {
1914
1934
  "application/json": components["schemas"]["ErrorResponse"] & {
1915
1935
  /** @enum {string} */
1916
- code: "SmsBudgetExhausted" | "SmsDeliveryUnavailable";
1936
+ code: "BotCheckUnavailable" | "LimiterUnavailable" | "SmsBudgetExhausted" | "SmsDeliveryUnavailable";
1917
1937
  };
1918
1938
  };
1919
1939
  };
@@ -2012,7 +2032,7 @@ export interface operations {
2012
2032
  };
2013
2033
  };
2014
2034
  };
2015
- /** @description - `RateLimited`: The load balancer's rate limit refused the request; retry after `Retry-After` seconds */
2035
+ /** @description - `RateLimited`: A rate limit refused the request: the load balancer's per IP, or the engine's per application client; retry after `Retry-After` seconds */
2016
2036
  429: {
2017
2037
  headers: {
2018
2038
  /** @description Seconds to wait before sending the request again */
@@ -2150,7 +2170,7 @@ export interface operations {
2150
2170
  };
2151
2171
  };
2152
2172
  };
2153
- /** @description - `RateLimited`: The load balancer's rate limit refused the request; retry after `Retry-After` seconds */
2173
+ /** @description - `RateLimited`: A rate limit refused the request: the load balancer's per IP, or the engine's per application client; retry after `Retry-After` seconds */
2154
2174
  429: {
2155
2175
  headers: {
2156
2176
  /** @description Seconds to wait before sending the request again */
@@ -2230,7 +2250,7 @@ export interface operations {
2230
2250
  };
2231
2251
  };
2232
2252
  };
2233
- /** @description - `RateLimited`: The load balancer's rate limit refused the request; retry after `Retry-After` seconds */
2253
+ /** @description - `RateLimited`: A rate limit refused the request: the load balancer's per IP, or the engine's per application client; retry after `Retry-After` seconds */
2234
2254
  429: {
2235
2255
  headers: {
2236
2256
  /** @description Seconds to wait before sending the request again */
@@ -2355,7 +2375,7 @@ export interface operations {
2355
2375
  };
2356
2376
  };
2357
2377
  };
2358
- /** @description - `RateLimited`: The load balancer's rate limit refused the request; retry after `Retry-After` seconds */
2378
+ /** @description - `RateLimited`: A rate limit refused the request: the load balancer's per IP, or the engine's per application client; retry after `Retry-After` seconds */
2359
2379
  429: {
2360
2380
  headers: {
2361
2381
  /** @description Seconds to wait before sending the request again */
@@ -2494,7 +2514,7 @@ export interface operations {
2494
2514
  };
2495
2515
  };
2496
2516
  };
2497
- /** @description - `RateLimited`: The load balancer's rate limit refused the request; retry after `Retry-After` seconds */
2517
+ /** @description - `RateLimited`: A rate limit refused the request: the load balancer's per IP, or the engine's per application client; retry after `Retry-After` seconds */
2498
2518
  429: {
2499
2519
  headers: {
2500
2520
  /** @description Seconds to wait before sending the request again */
@@ -2581,7 +2601,7 @@ export interface operations {
2581
2601
  };
2582
2602
  };
2583
2603
  };
2584
- /** @description - `RateLimited`: The load balancer's rate limit refused the request; retry after `Retry-After` seconds */
2604
+ /** @description - `RateLimited`: A rate limit refused the request: the load balancer's per IP, or the engine's per application client; retry after `Retry-After` seconds */
2585
2605
  429: {
2586
2606
  headers: {
2587
2607
  /** @description Seconds to wait before sending the request again */
@@ -2693,7 +2713,7 @@ export interface operations {
2693
2713
  };
2694
2714
  };
2695
2715
  };
2696
- /** @description - `RateLimited`: The load balancer's rate limit refused the request; retry after `Retry-After` seconds */
2716
+ /** @description - `RateLimited`: A rate limit refused the request: the load balancer's per IP, or the engine's per application client; retry after `Retry-After` seconds */
2697
2717
  429: {
2698
2718
  headers: {
2699
2719
  /** @description Seconds to wait before sending the request again */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@msm-platform/customer-sdk",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Typed server-side client for MSM's customer API (/web)",
5
5
  "license": "MIT",
6
6
  "repository": {