@monetize.software/sdk 3.0.0-alpha.0 → 3.0.0-alpha.10

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.
Files changed (129) hide show
  1. package/README.md +62 -41
  2. package/dist/chunks/PaywallUI-CQG9HCwo.js +3245 -0
  3. package/dist/chunks/PaywallUI-CQG9HCwo.js.map +1 -0
  4. package/dist/chunks/PaywallUI-DQ1Jke8b.js +26 -0
  5. package/dist/chunks/PaywallUI-DQ1Jke8b.js.map +1 -0
  6. package/dist/chunks/ar-7cgIM-Vl.js +2 -0
  7. package/dist/chunks/ar-7cgIM-Vl.js.map +1 -0
  8. package/dist/chunks/ar-B2Wg_IrC.js +126 -0
  9. package/dist/chunks/ar-B2Wg_IrC.js.map +1 -0
  10. package/dist/chunks/cs-BNo9Dx0Q.js +122 -0
  11. package/dist/chunks/cs-BNo9Dx0Q.js.map +1 -0
  12. package/dist/chunks/cs-S05PC5AC.js +2 -0
  13. package/dist/chunks/cs-S05PC5AC.js.map +1 -0
  14. package/dist/chunks/da-Bi4zBG14.js +2 -0
  15. package/dist/chunks/da-Bi4zBG14.js.map +1 -0
  16. package/dist/chunks/da-Do9Lq6En.js +122 -0
  17. package/dist/chunks/da-Do9Lq6En.js.map +1 -0
  18. package/dist/chunks/de-C8pDZNvx.js +141 -0
  19. package/dist/chunks/de-C8pDZNvx.js.map +1 -0
  20. package/dist/chunks/de-nCDB6D2W.js +2 -0
  21. package/dist/chunks/de-nCDB6D2W.js.map +1 -0
  22. package/dist/chunks/el-BrKaa978.js +2 -0
  23. package/dist/chunks/el-BrKaa978.js.map +1 -0
  24. package/dist/chunks/el-DzMNX-_P.js +126 -0
  25. package/dist/chunks/el-DzMNX-_P.js.map +1 -0
  26. package/dist/chunks/es-B-Wtyzrl.js +2 -0
  27. package/dist/chunks/es-B-Wtyzrl.js.map +1 -0
  28. package/dist/chunks/es-YrKt-q4w.js +141 -0
  29. package/dist/chunks/es-YrKt-q4w.js.map +1 -0
  30. package/dist/chunks/fi-Bh44pwZ4.js +122 -0
  31. package/dist/chunks/fi-Bh44pwZ4.js.map +1 -0
  32. package/dist/chunks/fi-D1SGXjnO.js +2 -0
  33. package/dist/chunks/fi-D1SGXjnO.js.map +1 -0
  34. package/dist/chunks/fr-Bc0pw4ws.js +141 -0
  35. package/dist/chunks/fr-Bc0pw4ws.js.map +1 -0
  36. package/dist/chunks/fr-BhYf-iKk.js +2 -0
  37. package/dist/chunks/fr-BhYf-iKk.js.map +1 -0
  38. package/dist/chunks/he-BXAaFv6Y.js +2 -0
  39. package/dist/chunks/he-BXAaFv6Y.js.map +1 -0
  40. package/dist/chunks/he-Bfm-bhe3.js +126 -0
  41. package/dist/chunks/he-Bfm-bhe3.js.map +1 -0
  42. package/dist/chunks/hi-D-O-B9Dn.js +126 -0
  43. package/dist/chunks/hi-D-O-B9Dn.js.map +1 -0
  44. package/dist/chunks/hi-xblDO0O7.js +2 -0
  45. package/dist/chunks/hi-xblDO0O7.js.map +1 -0
  46. package/dist/chunks/hu-CmIuAbLL.js +122 -0
  47. package/dist/chunks/hu-CmIuAbLL.js.map +1 -0
  48. package/dist/chunks/hu-Wa46p0y4.js +2 -0
  49. package/dist/chunks/hu-Wa46p0y4.js.map +1 -0
  50. package/dist/chunks/id-CQEo5X94.js +2 -0
  51. package/dist/chunks/id-CQEo5X94.js.map +1 -0
  52. package/dist/chunks/id-DN7IES-A.js +122 -0
  53. package/dist/chunks/id-DN7IES-A.js.map +1 -0
  54. package/dist/chunks/it-8AYCm0xz.js +2 -0
  55. package/dist/chunks/it-8AYCm0xz.js.map +1 -0
  56. package/dist/chunks/it-Cz5Nmqx5.js +141 -0
  57. package/dist/chunks/it-Cz5Nmqx5.js.map +1 -0
  58. package/dist/chunks/ja-BH9BlBh2.js +145 -0
  59. package/dist/chunks/ja-BH9BlBh2.js.map +1 -0
  60. package/dist/chunks/ja-q-COVayn.js +2 -0
  61. package/dist/chunks/ja-q-COVayn.js.map +1 -0
  62. package/dist/chunks/ko-B6HRCscZ.js +2 -0
  63. package/dist/chunks/ko-B6HRCscZ.js.map +1 -0
  64. package/dist/chunks/ko-CYV9QuYs.js +145 -0
  65. package/dist/chunks/ko-CYV9QuYs.js.map +1 -0
  66. package/dist/chunks/nl-BvkB900D.js +141 -0
  67. package/dist/chunks/nl-BvkB900D.js.map +1 -0
  68. package/dist/chunks/nl-CAd6_xlm.js +2 -0
  69. package/dist/chunks/nl-CAd6_xlm.js.map +1 -0
  70. package/dist/chunks/no-3s9_ormb.js +122 -0
  71. package/dist/chunks/no-3s9_ormb.js.map +1 -0
  72. package/dist/chunks/no-CAmz6bz6.js +2 -0
  73. package/dist/chunks/no-CAmz6bz6.js.map +1 -0
  74. package/dist/chunks/pl-C9WTGQtb.js +122 -0
  75. package/dist/chunks/pl-C9WTGQtb.js.map +1 -0
  76. package/dist/chunks/pl-DqUSTCaF.js +2 -0
  77. package/dist/chunks/pl-DqUSTCaF.js.map +1 -0
  78. package/dist/chunks/pt-8ARZnH0_.js +2 -0
  79. package/dist/chunks/pt-8ARZnH0_.js.map +1 -0
  80. package/dist/chunks/pt-uFVUv_Op.js +141 -0
  81. package/dist/chunks/pt-uFVUv_Op.js.map +1 -0
  82. package/dist/chunks/ro-BrqQ8Au-.js +122 -0
  83. package/dist/chunks/ro-BrqQ8Au-.js.map +1 -0
  84. package/dist/chunks/ro-D-NMbp2F.js +2 -0
  85. package/dist/chunks/ro-D-NMbp2F.js.map +1 -0
  86. package/dist/chunks/ru-8gbHPh0g.js +2 -0
  87. package/dist/chunks/ru-8gbHPh0g.js.map +1 -0
  88. package/dist/chunks/ru-DK594dA8.js +144 -0
  89. package/dist/chunks/ru-DK594dA8.js.map +1 -0
  90. package/dist/chunks/sv-CHNH8-mq.js +122 -0
  91. package/dist/chunks/sv-CHNH8-mq.js.map +1 -0
  92. package/dist/chunks/sv-D8a8hmx9.js +2 -0
  93. package/dist/chunks/sv-D8a8hmx9.js.map +1 -0
  94. package/dist/chunks/th-DfjUK0Y7.js +2 -0
  95. package/dist/chunks/th-DfjUK0Y7.js.map +1 -0
  96. package/dist/chunks/th-l24Pm5q-.js +126 -0
  97. package/dist/chunks/th-l24Pm5q-.js.map +1 -0
  98. package/dist/chunks/tr-ADpigSY5.js +122 -0
  99. package/dist/chunks/tr-ADpigSY5.js.map +1 -0
  100. package/dist/chunks/tr-BdBpz4tL.js +2 -0
  101. package/dist/chunks/tr-BdBpz4tL.js.map +1 -0
  102. package/dist/chunks/uk-CGqo4jek.js +144 -0
  103. package/dist/chunks/uk-CGqo4jek.js.map +1 -0
  104. package/dist/chunks/uk-Cx1zv1ao.js +2 -0
  105. package/dist/chunks/uk-Cx1zv1ao.js.map +1 -0
  106. package/dist/chunks/vi-Dk9bTu6f.js +122 -0
  107. package/dist/chunks/vi-Dk9bTu6f.js.map +1 -0
  108. package/dist/chunks/vi-oe2dW21I.js +2 -0
  109. package/dist/chunks/vi-oe2dW21I.js.map +1 -0
  110. package/dist/chunks/zh-CwczPMPp.js +2 -0
  111. package/dist/chunks/zh-CwczPMPp.js.map +1 -0
  112. package/dist/chunks/zh-LDkEV2D9.js +145 -0
  113. package/dist/chunks/zh-LDkEV2D9.js.map +1 -0
  114. package/dist/core.cjs +1 -1
  115. package/dist/core.cjs.map +1 -1
  116. package/dist/core.d.ts +265 -24
  117. package/dist/core.js +519 -313
  118. package/dist/core.js.map +1 -1
  119. package/dist/index.cjs +1 -1
  120. package/dist/index.d.ts +355 -43
  121. package/dist/index.js +14 -10
  122. package/dist/ui.cjs +1 -1
  123. package/dist/ui.d.ts +322 -44
  124. package/dist/ui.js +1 -1
  125. package/package.json +32 -31
  126. package/dist/chunks/PaywallUI-BHp9afFC.js +0 -2209
  127. package/dist/chunks/PaywallUI-BHp9afFC.js.map +0 -1
  128. package/dist/chunks/PaywallUI-Dr-6q-HL.js +0 -26
  129. package/dist/chunks/PaywallUI-Dr-6q-HL.js.map +0 -1
package/README.md CHANGED
@@ -1,30 +1,37 @@
1
1
  # @monetize.software/sdk
2
2
 
3
- SDK 3.0 — bundled billing client и render engine пейвола. Встраивается в расширения Chrome
4
- и веб-сайты через npm / CDN, без iframe и без remote code.
3
+ SDK 3.0 — bundled billing client and paywall render engine. Renders the paywall
4
+ in a Shadow DOM modal on your page, with no iframe.
5
5
 
6
- Статус: **alpha, WIP**. См. [TODO.md](../TODO.md).
6
+ - **Websites:** install via npm and bundle, or load from a CDN (`esm.sh`/`unpkg`/`jsDelivr`).
7
+ - **Chrome extensions:** use the dedicated [`@monetize.software/sdk-extension`](https://www.npmjs.com/package/@monetize.software/sdk-extension)
8
+ package and bundle as an npm dependency — Chrome Web Store MV3 policy forbids
9
+ remote code execution, so CDN loading is **not** allowed.
7
10
 
8
- ## Три entrypoint'а
11
+ Status: **alpha**. API surface is stabilizing but may still shift between alpha
12
+ releases; see [CHANGELOG.md](CHANGELOG.md).
13
+
14
+ ## Three entrypoints
9
15
 
10
16
  ```ts
11
- // server / headless billing — только API, без UI
17
+ // server / headless billing — API only, no UI
12
18
  import { BillingClient } from '@monetize.software/sdk/core';
13
19
 
14
- // host сам показывает UI, но нужна наша модалка
20
+ // host renders its own UI but needs our modal
15
21
  import { PaywallUI } from '@monetize.software/sdk/ui';
16
22
 
17
- // все в одном — auth-слой подгружается лениво
23
+ // all in one — auth layer is loaded lazily
18
24
  import { PaywallUI } from '@monetize.software/sdk';
19
25
  ```
20
26
 
21
- ## Быстрый старт
27
+ ## Quick start
22
28
 
23
29
  ```ts
24
30
  import { PaywallUI } from '@monetize.software/sdk';
25
31
 
26
32
  const paywall = new PaywallUI({
27
33
  paywallId: 'pw_abc123',
34
+ apiOrigin: 'https://your-paywall-domain.com', // required: your custom_domain
28
35
  identity: { email: user.email, userId: user.id }
29
36
  });
30
37
 
@@ -35,46 +42,50 @@ paywall.on('checkout_started', ({ url }) => {
35
42
  document.getElementById('upgrade').onclick = () => paywall.open();
36
43
  ```
37
44
 
38
- ## Скрипты
45
+ `apiOrigin` must match the `custom_domain` configured for your paywall in the
46
+ platform. The SDK validates it against the bootstrap response and throws
47
+ `invalid_config` on mismatch.
48
+
49
+ ## Scripts
39
50
 
40
51
  ```bash
41
52
  pnpm install
42
- pnpm dev # локальная демка на http://localhost:5060/demo/
43
- pnpm build # ESM + CJS + .d.ts в dist/
53
+ pnpm dev # local demo at http://localhost:5060/demo/
54
+ pnpm build # ESM + CJS + .d.ts into dist/
44
55
  pnpm typecheck
45
56
  pnpm size # bundle-size gate
46
57
  pnpm test
47
58
  ```
48
59
 
49
- ## Архитектура (коротко)
60
+ ## Architecture (in brief)
50
61
 
51
- - **Preact** (не React) — 3KB вместо 45KB. Critical для bundle-бюджета.
52
- - **Shadow DOM** (`{ mode: 'closed' }`) — изоляция стилей.
53
- - **Tailwind v4**, скомпилированный в CSS-строку и инжектированный в shadow root.
54
- - **Server-driven layout** — JSON-схема блоков (`heading`, `price_grid`, `cta_button`, ...).
55
- SDK умеет рендерить блоки; server управляет порядком, текстами, visibility.
56
- - **Server-driven checkout** — SDK не знает провайдеров (Stripe/Paddle/Chargebee),
57
- просто открывает `checkout_url`, который вернул сервер.
62
+ - **Preact** (not React) — 3KB instead of 45KB. Critical for the bundle budget.
63
+ - **Shadow DOM** (`{ mode: 'closed' }`) — style isolation.
64
+ - **Tailwind v4**, compiled into a CSS string and injected into the shadow root.
65
+ - **Server-driven layout** — JSON schema of blocks (`heading`, `price_grid`, `cta_button`, ...).
66
+ SDK knows how to render blocks; the server controls order, copy, and visibility.
67
+ - **Server-driven checkout** — SDK is provider-agnostic (Stripe, Paddle, Freemius,
68
+ Chargebee, Overpay), it just opens the `checkout_url` returned by the server.
58
69
 
59
- ## Метированный AI-прокси (`ApiGatewayClient`)
70
+ ## Metered AI proxy (`ApiGatewayClient`)
60
71
 
61
- Платформа поддерживает прокси-вызовы к OpenAI/Anthropic/любому HTTP-API с
62
- посчётом токенов из `paywall_balances`. SDK даёт тонкий клиент к этому прокси
63
- и хранит локальное состояние балансов.
72
+ The platform supports proxying calls to OpenAI/Anthropic/any HTTP API with
73
+ token accounting against `paywall_balances`. The SDK ships a thin client to
74
+ this proxy and maintains local balance state.
64
75
 
65
76
  ```ts
66
77
  import { BillingClient, AuthClient, QuotaExceededError } from '@monetize.software/sdk/core';
67
78
 
68
- const auth = new AuthClient({ paywallId: 'pw_abc' });
69
- const billing = new BillingClient({ paywallId: 'pw_abc', auth });
79
+ const auth = new AuthClient({ paywallId: 'pw_abc', apiOrigin: 'https://your-paywall-domain.com' });
80
+ const billing = new BillingClient({ paywallId: 'pw_abc', apiOrigin: 'https://your-paywall-domain.com', auth });
70
81
  const gateway = billing.createApiGatewayClient();
71
82
 
72
83
  billing.onBalanceChange((balances) => {
73
- // Рисуем счётчик квот в UI
84
+ // Render quota counter in UI
74
85
  });
75
86
 
76
87
  try {
77
- // SSE-стрим: возвращается голый Response, без своего парсера.
88
+ // SSE stream: returns a raw Response, no built-in parser.
78
89
  const res = await gateway.call({
79
90
  providerId: 'prov_openai',
80
91
  path: '',
@@ -86,21 +97,31 @@ try {
86
97
  }
87
98
  } catch (e) {
88
99
  if (e instanceof QuotaExceededError) {
89
- paywall.open(); // upgrade-prompt
100
+ paywall.open(); // upgrade prompt
90
101
  } else throw e;
91
102
  }
92
103
  ```
93
104
 
94
- - `BillingClient.createApiGatewayClient()` подключает Bearer из `AuthClient`,
95
- оптимистично декрементит `cachedBalances` на success, ре-фетчит `/balances`
96
- на 402.
97
- - `gateway.call()` отдаёт сырой `Response`. Caller сам решает: `.json()`,
98
- `.body.getReader()`, или async-iter — всё работает из коробки `fetch`.
99
- - На 402 бросается `QuotaExceededError` с `balances`/`queryType`/`currentBalance`.
100
-
101
- ## Нет в этой версии (alpha)
102
-
103
- - Auth-слой (Google/Apple/Email) будет после hybrid-бета.
104
- - Трейлы с таймером, A/B-варианты, локализация.
105
- - Framework adapters (`@monetize/react`).
106
- - Tests.
105
+ - `BillingClient.createApiGatewayClient()` wires the Bearer from `AuthClient`,
106
+ optimistically decrements `cachedBalances` on success, and refetches `/balances`
107
+ on 402.
108
+ - `gateway.call()` returns the raw `Response`. Caller decides: `.json()`,
109
+ `.body.getReader()`, or async-iter — anything that works on a `fetch` Response.
110
+ - On 402, `QuotaExceededError` is thrown with `balances` / `queryType` / `currentBalance`.
111
+
112
+ ## What's included
113
+
114
+ - **Auth layer** — Email/password, OAuth (Google, Apple, Facebook, GitHub),
115
+ password reset and OTP confirmation flows. Lazy-loaded chunk: pay for it only
116
+ if you instantiate `AuthClient` or open the SDK with `auth: true`.
117
+ - **Trials** — time-based trial counter (LocalTrialStore on web,
118
+ RemoteTrialStore in the extension offscreen) with server-side validation.
119
+ - **Localization** — 27 bundled locales, lazy-loaded per active language; falls
120
+ back to canonical English baked into block strings.
121
+ - **Server-driven layout** — blocks, ordering, copy and visibility are owned by
122
+ the platform; the SDK renders. Live preview API for the admin editor.
123
+ - **React bindings** — see [`@monetize.software/sdk-react`](https://www.npmjs.com/package/@monetize.software/sdk-react)
124
+ for `<PaywallProvider>`, hooks and declarative gate/button components.
125
+ - **Chrome extensions** — see [`@monetize.software/sdk-extension`](https://www.npmjs.com/package/@monetize.software/sdk-extension)
126
+ for the offscreen-backed integration (single source of truth across tabs,
127
+ popups, side panels).