@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.
- package/README.md +62 -41
- package/dist/chunks/PaywallUI-CQG9HCwo.js +3245 -0
- package/dist/chunks/PaywallUI-CQG9HCwo.js.map +1 -0
- package/dist/chunks/PaywallUI-DQ1Jke8b.js +26 -0
- package/dist/chunks/PaywallUI-DQ1Jke8b.js.map +1 -0
- package/dist/chunks/ar-7cgIM-Vl.js +2 -0
- package/dist/chunks/ar-7cgIM-Vl.js.map +1 -0
- package/dist/chunks/ar-B2Wg_IrC.js +126 -0
- package/dist/chunks/ar-B2Wg_IrC.js.map +1 -0
- package/dist/chunks/cs-BNo9Dx0Q.js +122 -0
- package/dist/chunks/cs-BNo9Dx0Q.js.map +1 -0
- package/dist/chunks/cs-S05PC5AC.js +2 -0
- package/dist/chunks/cs-S05PC5AC.js.map +1 -0
- package/dist/chunks/da-Bi4zBG14.js +2 -0
- package/dist/chunks/da-Bi4zBG14.js.map +1 -0
- package/dist/chunks/da-Do9Lq6En.js +122 -0
- package/dist/chunks/da-Do9Lq6En.js.map +1 -0
- package/dist/chunks/de-C8pDZNvx.js +141 -0
- package/dist/chunks/de-C8pDZNvx.js.map +1 -0
- package/dist/chunks/de-nCDB6D2W.js +2 -0
- package/dist/chunks/de-nCDB6D2W.js.map +1 -0
- package/dist/chunks/el-BrKaa978.js +2 -0
- package/dist/chunks/el-BrKaa978.js.map +1 -0
- package/dist/chunks/el-DzMNX-_P.js +126 -0
- package/dist/chunks/el-DzMNX-_P.js.map +1 -0
- package/dist/chunks/es-B-Wtyzrl.js +2 -0
- package/dist/chunks/es-B-Wtyzrl.js.map +1 -0
- package/dist/chunks/es-YrKt-q4w.js +141 -0
- package/dist/chunks/es-YrKt-q4w.js.map +1 -0
- package/dist/chunks/fi-Bh44pwZ4.js +122 -0
- package/dist/chunks/fi-Bh44pwZ4.js.map +1 -0
- package/dist/chunks/fi-D1SGXjnO.js +2 -0
- package/dist/chunks/fi-D1SGXjnO.js.map +1 -0
- package/dist/chunks/fr-Bc0pw4ws.js +141 -0
- package/dist/chunks/fr-Bc0pw4ws.js.map +1 -0
- package/dist/chunks/fr-BhYf-iKk.js +2 -0
- package/dist/chunks/fr-BhYf-iKk.js.map +1 -0
- package/dist/chunks/he-BXAaFv6Y.js +2 -0
- package/dist/chunks/he-BXAaFv6Y.js.map +1 -0
- package/dist/chunks/he-Bfm-bhe3.js +126 -0
- package/dist/chunks/he-Bfm-bhe3.js.map +1 -0
- package/dist/chunks/hi-D-O-B9Dn.js +126 -0
- package/dist/chunks/hi-D-O-B9Dn.js.map +1 -0
- package/dist/chunks/hi-xblDO0O7.js +2 -0
- package/dist/chunks/hi-xblDO0O7.js.map +1 -0
- package/dist/chunks/hu-CmIuAbLL.js +122 -0
- package/dist/chunks/hu-CmIuAbLL.js.map +1 -0
- package/dist/chunks/hu-Wa46p0y4.js +2 -0
- package/dist/chunks/hu-Wa46p0y4.js.map +1 -0
- package/dist/chunks/id-CQEo5X94.js +2 -0
- package/dist/chunks/id-CQEo5X94.js.map +1 -0
- package/dist/chunks/id-DN7IES-A.js +122 -0
- package/dist/chunks/id-DN7IES-A.js.map +1 -0
- package/dist/chunks/it-8AYCm0xz.js +2 -0
- package/dist/chunks/it-8AYCm0xz.js.map +1 -0
- package/dist/chunks/it-Cz5Nmqx5.js +141 -0
- package/dist/chunks/it-Cz5Nmqx5.js.map +1 -0
- package/dist/chunks/ja-BH9BlBh2.js +145 -0
- package/dist/chunks/ja-BH9BlBh2.js.map +1 -0
- package/dist/chunks/ja-q-COVayn.js +2 -0
- package/dist/chunks/ja-q-COVayn.js.map +1 -0
- package/dist/chunks/ko-B6HRCscZ.js +2 -0
- package/dist/chunks/ko-B6HRCscZ.js.map +1 -0
- package/dist/chunks/ko-CYV9QuYs.js +145 -0
- package/dist/chunks/ko-CYV9QuYs.js.map +1 -0
- package/dist/chunks/nl-BvkB900D.js +141 -0
- package/dist/chunks/nl-BvkB900D.js.map +1 -0
- package/dist/chunks/nl-CAd6_xlm.js +2 -0
- package/dist/chunks/nl-CAd6_xlm.js.map +1 -0
- package/dist/chunks/no-3s9_ormb.js +122 -0
- package/dist/chunks/no-3s9_ormb.js.map +1 -0
- package/dist/chunks/no-CAmz6bz6.js +2 -0
- package/dist/chunks/no-CAmz6bz6.js.map +1 -0
- package/dist/chunks/pl-C9WTGQtb.js +122 -0
- package/dist/chunks/pl-C9WTGQtb.js.map +1 -0
- package/dist/chunks/pl-DqUSTCaF.js +2 -0
- package/dist/chunks/pl-DqUSTCaF.js.map +1 -0
- package/dist/chunks/pt-8ARZnH0_.js +2 -0
- package/dist/chunks/pt-8ARZnH0_.js.map +1 -0
- package/dist/chunks/pt-uFVUv_Op.js +141 -0
- package/dist/chunks/pt-uFVUv_Op.js.map +1 -0
- package/dist/chunks/ro-BrqQ8Au-.js +122 -0
- package/dist/chunks/ro-BrqQ8Au-.js.map +1 -0
- package/dist/chunks/ro-D-NMbp2F.js +2 -0
- package/dist/chunks/ro-D-NMbp2F.js.map +1 -0
- package/dist/chunks/ru-8gbHPh0g.js +2 -0
- package/dist/chunks/ru-8gbHPh0g.js.map +1 -0
- package/dist/chunks/ru-DK594dA8.js +144 -0
- package/dist/chunks/ru-DK594dA8.js.map +1 -0
- package/dist/chunks/sv-CHNH8-mq.js +122 -0
- package/dist/chunks/sv-CHNH8-mq.js.map +1 -0
- package/dist/chunks/sv-D8a8hmx9.js +2 -0
- package/dist/chunks/sv-D8a8hmx9.js.map +1 -0
- package/dist/chunks/th-DfjUK0Y7.js +2 -0
- package/dist/chunks/th-DfjUK0Y7.js.map +1 -0
- package/dist/chunks/th-l24Pm5q-.js +126 -0
- package/dist/chunks/th-l24Pm5q-.js.map +1 -0
- package/dist/chunks/tr-ADpigSY5.js +122 -0
- package/dist/chunks/tr-ADpigSY5.js.map +1 -0
- package/dist/chunks/tr-BdBpz4tL.js +2 -0
- package/dist/chunks/tr-BdBpz4tL.js.map +1 -0
- package/dist/chunks/uk-CGqo4jek.js +144 -0
- package/dist/chunks/uk-CGqo4jek.js.map +1 -0
- package/dist/chunks/uk-Cx1zv1ao.js +2 -0
- package/dist/chunks/uk-Cx1zv1ao.js.map +1 -0
- package/dist/chunks/vi-Dk9bTu6f.js +122 -0
- package/dist/chunks/vi-Dk9bTu6f.js.map +1 -0
- package/dist/chunks/vi-oe2dW21I.js +2 -0
- package/dist/chunks/vi-oe2dW21I.js.map +1 -0
- package/dist/chunks/zh-CwczPMPp.js +2 -0
- package/dist/chunks/zh-CwczPMPp.js.map +1 -0
- package/dist/chunks/zh-LDkEV2D9.js +145 -0
- package/dist/chunks/zh-LDkEV2D9.js.map +1 -0
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +265 -24
- package/dist/core.js +519 -313
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +355 -43
- package/dist/index.js +14 -10
- package/dist/ui.cjs +1 -1
- package/dist/ui.d.ts +322 -44
- package/dist/ui.js +1 -1
- package/package.json +32 -31
- package/dist/chunks/PaywallUI-BHp9afFC.js +0 -2209
- package/dist/chunks/PaywallUI-BHp9afFC.js.map +0 -1
- package/dist/chunks/PaywallUI-Dr-6q-HL.js +0 -26
- 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
|
|
4
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 —
|
|
17
|
+
// server / headless billing — API only, no UI
|
|
12
18
|
import { BillingClient } from '@monetize.software/sdk/core';
|
|
13
19
|
|
|
14
|
-
// host
|
|
20
|
+
// host renders its own UI but needs our modal
|
|
15
21
|
import { PaywallUI } from '@monetize.software/sdk/ui';
|
|
16
22
|
|
|
17
|
-
//
|
|
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 #
|
|
43
|
-
pnpm build # ESM + CJS + .d.ts
|
|
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** (
|
|
52
|
-
- **Shadow DOM** (`{ mode: 'closed' }`) —
|
|
53
|
-
- **Tailwind v4**,
|
|
54
|
-
- **Server-driven layout** — JSON
|
|
55
|
-
SDK
|
|
56
|
-
- **Server-driven checkout** — SDK
|
|
57
|
-
|
|
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
|
-
##
|
|
70
|
+
## Metered AI proxy (`ApiGatewayClient`)
|
|
60
71
|
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
//
|
|
84
|
+
// Render quota counter in UI
|
|
74
85
|
});
|
|
75
86
|
|
|
76
87
|
try {
|
|
77
|
-
// SSE
|
|
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
|
|
100
|
+
paywall.open(); // upgrade prompt
|
|
90
101
|
} else throw e;
|
|
91
102
|
}
|
|
92
103
|
```
|
|
93
104
|
|
|
94
|
-
- `BillingClient.createApiGatewayClient()`
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
- `gateway.call()`
|
|
98
|
-
`.body.getReader()`,
|
|
99
|
-
-
|
|
100
|
-
|
|
101
|
-
##
|
|
102
|
-
|
|
103
|
-
- Auth
|
|
104
|
-
-
|
|
105
|
-
|
|
106
|
-
-
|
|
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).
|