@ledewire/browser 0.1.0 → 0.2.1

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 (2) hide show
  1. package/README.md +103 -0
  2. package/package.json +3 -5
package/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # @ledewire/browser
2
+
3
+ [![npm](https://img.shields.io/npm/v/@ledewire/browser)](https://www.npmjs.com/package/@ledewire/browser)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](../../LICENSE)
5
+
6
+ Browser SDK for the [LedeWire](https://api.ledewire.com/api-docs/index.html) content marketplace — embed buyer authentication, wallet funding, and content purchases on any website with a single script tag.
7
+
8
+ ## CDN — No Install Required
9
+
10
+ ```html
11
+ <!-- Pin to a major version in production -->
12
+ <script src="https://cdn.jsdelivr.net/npm/@ledewire/browser@0/dist/ledewire.min.js"></script>
13
+ <script>
14
+ const lw = Ledewire.init({ apiKey: 'your_api_key' })
15
+
16
+ // Determine what the visitor needs to do next
17
+ const state = await lw.checkout.state('content-id')
18
+ // state.checkout_state.next_required_action:
19
+ // 'authenticate' | 'fund_wallet' | 'purchase' | 'view_content'
20
+ </script>
21
+ ```
22
+
23
+ ## npm / ESM
24
+
25
+ ```bash
26
+ npm install @ledewire/browser
27
+ ```
28
+
29
+ ```ts
30
+ import { init, localStorageAdapter } from '@ledewire/browser'
31
+
32
+ const lw = init({
33
+ apiKey: 'your_api_key',
34
+ // Persist sessions across page reloads (defaults to in-memory)
35
+ storage: localStorageAdapter(),
36
+ // Called when the session expires and cannot be refreshed
37
+ onAuthExpired: () => showLoginModal(),
38
+ })
39
+ ```
40
+
41
+ ## Client Namespaces
42
+
43
+ | Namespace | Description |
44
+ | -------------- | ------------------------------------------------ |
45
+ | `lw.auth` | Buyer signup, email/password login, Google OAuth |
46
+ | `lw.wallet` | Wallet balance, fund wallet via payment session |
47
+ | `lw.purchases` | List and create content purchases |
48
+ | `lw.content` | Fetch content with buyer access info |
49
+ | `lw.checkout` | Checkout state — what action is required next |
50
+
51
+ ## Example: Full Checkout Flow
52
+
53
+ ```ts
54
+ const lw = Ledewire.init({ apiKey: 'your_api_key' })
55
+
56
+ const { checkout_state } = await lw.checkout.state('article-123')
57
+
58
+ switch (checkout_state.next_required_action) {
59
+ case 'authenticate':
60
+ await lw.auth.loginWithEmail({ email, password })
61
+ break
62
+ case 'fund_wallet':
63
+ const session = await lw.wallet.createPaymentSession({ amount_cents: 500 })
64
+ // redirect to session.payment_url
65
+ break
66
+ case 'purchase':
67
+ await lw.purchases.create({ content_id: 'article-123' })
68
+ break
69
+ case 'view_content':
70
+ const { content_type, content_body, content_uri } =
71
+ await lw.content.getWithAccess('article-123')
72
+ if (content_type === 'markdown') {
73
+ // render decoded markdown
74
+ renderMarkdown(atob(content_body))
75
+ } else {
76
+ // redirect to the gated external URI (Vimeo, PDF, etc.)
77
+ window.location.href = content_uri
78
+ }
79
+ break
80
+ }
81
+ ```
82
+
83
+ ## Token Storage
84
+
85
+ By default tokens are stored **in memory** (most secure — cleared on page unload).
86
+ Use the built-in `localStorageAdapter` to persist sessions across reloads:
87
+
88
+ ```ts
89
+ import { init, localStorageAdapter } from '@ledewire/browser'
90
+ const lw = init({ apiKey: '...', storage: localStorageAdapter() })
91
+ ```
92
+
93
+ Token refresh is handled automatically — you never need to call a refresh method manually.
94
+
95
+ ## Documentation
96
+
97
+ - [Getting Started Guide](https://ledewire.github.io/ledewire-js-sdk/guides/browser-cdn.html)
98
+ - [API Reference](https://ledewire.github.io/ledewire-js-sdk/api/)
99
+ - [Full SDK README](../../README.md)
100
+
101
+ ## License
102
+
103
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledewire/browser",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "LedeWire SDK for browsers — embed a paywall with a single script tag",
5
5
  "type": "module",
6
6
  "exports": {
@@ -25,9 +25,6 @@
25
25
  "paywall"
26
26
  ],
27
27
  "license": "MIT",
28
- "dependencies": {
29
- "@ledewire/core": "0.0.0"
30
- },
31
28
  "devDependencies": {
32
29
  "@vitest/coverage-v8": "^3.0.0",
33
30
  "jsdom": "^26.0.0",
@@ -35,7 +32,8 @@
35
32
  "typescript": "*",
36
33
  "vite": "^6.0.0",
37
34
  "vite-plugin-dts": "^4.0.0",
38
- "vitest": "^3.0.0"
35
+ "vitest": "^3.0.0",
36
+ "@ledewire/core": "0.1.0"
39
37
  },
40
38
  "publishConfig": {
41
39
  "access": "public"