@proappstore/sdk 1.1.1 → 1.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.
Files changed (2) hide show
  1. package/README.md +138 -25
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,11 +1,13 @@
1
1
  # @proappstore/sdk
2
2
 
3
- Unified SDK for paid apps on **proappstore.online**. Includes everything from `@freeappstore/sdk` (auth, kv, counters, rooms, proxy) plus subscription management and license keys.
3
+ Unified SDK for paid apps on **proappstore.online**. Includes everything from `@freeappstore/sdk` (auth, kv, counters, rooms, proxy) plus subscription management, license keys, and a per-app SQL database.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
8
  npm i @proappstore/sdk
9
+ # or
10
+ pnpm add @proappstore/sdk
9
11
  ```
10
12
 
11
13
  ## Usage
@@ -14,52 +16,163 @@ npm i @proappstore/sdk
14
16
  import { initPro } from '@proappstore/sdk'
15
17
 
16
18
  const app = initPro({ appId: 'my-app' })
19
+ ```
20
+
21
+ Options:
22
+
23
+ | Option | Default | Description |
24
+ |--------|---------|-------------|
25
+ | `appId` | (required) | Your app's unique identifier |
26
+ | `fasApiBase` | `https://api.freeappstore.online` | Free-tier backend URL |
27
+ | `proApiBase` | `https://api.proappstore.online` | Pro-tier backend URL |
28
+ | `dataApiBase` | `https://data-{appId}.proappstore.online` | Per-app data worker URL |
29
+
30
+ ## Modules
31
+
32
+ ### Auth
33
+
34
+ GitHub OAuth — shared identity across all FreeAppStore and ProAppStore apps.
17
35
 
18
- // Auth (GitHub OAuth — same identity as FreeAppStore)
36
+ ```ts
19
37
  await app.auth.init()
20
38
  app.auth.onChange((user) => console.log(user))
21
39
  app.auth.signIn()
40
+ app.auth.signOut()
41
+ ```
22
42
 
23
- // Per-user KV storage
43
+ ### KV (Per-user key-value storage)
44
+
45
+ ```ts
24
46
  await app.kv.set('profile', { name: 'Alice' })
47
+ const profile = await app.kv.get('profile')
25
48
  const keys = await app.kv.list({ prefix: 'note:' })
49
+ await app.kv.delete('profile')
50
+ ```
51
+
52
+ ### Counters (Shared atomic counters)
53
+
54
+ Cross-user counters for votes, views, leaderboards.
26
55
 
27
- // Shared counters (cross-user)
56
+ ```ts
28
57
  await app.counters.increment('views')
58
+ await app.counters.decrement('likes')
29
59
  const all = await app.counters.list()
60
+ ```
30
61
 
31
- // Real-time rooms
62
+ ### Rooms (Real-time WebSocket)
63
+
64
+ ```ts
32
65
  const room = app.rooms.join('lobby')
33
66
  room.send({ text: 'hello' })
34
67
  room.onMessage((msg) => console.log(msg))
68
+ room.onPeers((peers) => console.log(peers))
69
+ room.leave()
70
+ ```
71
+
72
+ ### Proxy (Secret-injecting API proxy)
73
+
74
+ Call third-party APIs without exposing keys to the client.
75
+
76
+ ```ts
77
+ const response = await app.proxy.fetch('/openai/chat/completions', {
78
+ method: 'POST',
79
+ body: JSON.stringify({ model: 'gpt-4', messages: [...] }),
80
+ })
81
+ ```
82
+
83
+ ### Database (Per-app SQL)
84
+
85
+ Each Pro app gets its own D1 SQL database accessed through a dedicated data worker at `data-{appId}.proappstore.online`.
86
+
87
+ ```ts
88
+ // Query rows
89
+ const { rows } = await app.db.query('SELECT * FROM users WHERE active = ?', [true])
35
90
 
36
- // Subscriptions (Stripe-powered)
91
+ // Execute writes
92
+ const { meta } = await app.db.execute('INSERT INTO users (name) VALUES (?)', ['Alice'])
93
+ console.log(meta.last_row_id) // auto-increment id
94
+
95
+ // Batch (transactional)
96
+ const results = await app.db.batch([
97
+ { sql: 'INSERT INTO orders (user_id, total) VALUES (?, ?)', params: [1, 99.99] },
98
+ { sql: 'UPDATE users SET order_count = order_count + 1 WHERE id = ?', params: [1] },
99
+ ])
100
+
101
+ // List tables
102
+ const tables = await app.db.tables()
103
+ ```
104
+
105
+ ### Subscription (Stripe-powered)
106
+
107
+ ```ts
108
+ // Check subscription status
37
109
  const sub = await app.subscription.status()
38
- if (!sub || sub.status !== 'active') {
39
- await app.subscription.openCheckout({
40
- priceId: 'price_xxx',
41
- successUrl: 'https://my-app.proappstore.online/success',
42
- cancelUrl: 'https://my-app.proappstore.online/',
43
- })
44
- }
110
+ // Returns: { status, tier, priceId, currentPeriodEnd, cancelAtPeriodEnd } | null
111
+
112
+ // Open Stripe checkout (navigates away)
113
+ await app.subscription.openCheckout({
114
+ priceId: 'price_pro_monthly',
115
+ successUrl: 'https://my-app.proappstore.online/success',
116
+ cancelUrl: 'https://my-app.proappstore.online/',
117
+ })
118
+
119
+ // Open Stripe billing portal (navigates away)
45
120
  await app.subscription.openPortal('https://my-app.proappstore.online/')
121
+ ```
122
+
123
+ ### License
46
124
 
47
- // License keys
125
+ Per-app license key validation.
126
+
127
+ ```ts
128
+ // Get current user's license (requires auth)
48
129
  const license = await app.license.current()
49
- const valid = await app.license.validate('KEY-123')
130
+ // Returns: { key, appId, issuedAt, expiresAt } | null
131
+
132
+ // Validate any key (no auth required)
133
+ const valid = await app.license.validate('LIC-ABC-123')
50
134
  ```
51
135
 
52
- ## Modules
136
+ ## ProShell Component
137
+
138
+ A React component that handles auth gates, subscription checks, and renders a platform-level shell with topbar and user menu.
139
+
140
+ ```tsx
141
+ import { initPro } from '@proappstore/sdk'
142
+ import { ProShell } from '@proappstore/sdk/shell'
143
+
144
+ const app = initPro({ appId: 'meetup' })
145
+
146
+ export default function App() {
147
+ return (
148
+ <ProShell app={app} appName="Meetup">
149
+ <MeetupApp />
150
+ </ProShell>
151
+ )
152
+ }
153
+ ```
154
+
155
+ Props:
156
+
157
+ | Prop | Type | Description |
158
+ |------|------|-------------|
159
+ | `app` | `ProAppStore` | SDK instance from `initPro()` |
160
+ | `children` | `ReactNode` | App content (rendered only when gates pass) |
161
+ | `appName` | `string?` | Name shown in the topbar |
162
+ | `allowFree` | `boolean?` | Skip subscription gate (default: `false`) |
163
+
164
+ ProShell handles:
165
+ - Auth initialization and sign-in gate
166
+ - Subscription check and upgrade wall (unless `allowFree=true`)
167
+ - Topbar with avatar, app name, and user menu (sign out, manage billing, delete account)
168
+
169
+ ## Per-app SQL Database
170
+
171
+ Each Pro app is provisioned with a dedicated Cloudflare D1 database fronted by a data worker (`data-{appId}.proappstore.online`). The SDK's `db` module provides a typed client for this worker.
172
+
173
+ The database is per-user isolated at the auth layer — all requests require a valid Bearer token. The data worker validates the token against the FAS auth API before executing queries.
53
174
 
54
- | Module | Source | Description |
55
- |--------|--------|-------------|
56
- | `auth` | FAS | GitHub OAuth, SSO across all apps |
57
- | `kv` | FAS | Per-user key-value store (list, get, set, delete, getMany) |
58
- | `counters` | FAS | Shared atomic counters (votes, views, leaderboards) |
59
- | `rooms` | FAS | Real-time WebSocket rooms (presence, chat, collab) |
60
- | `proxy` | FAS | Secret-injecting API proxy for third-party services |
61
- | `subscription` | Pro | Stripe checkout, portal, status |
62
- | `license` | Pro | Per-app license key validation |
175
+ Tables are user-defined (create them via `db.execute('CREATE TABLE IF NOT EXISTS ...')`). The schema is entirely up to the app developer.
63
176
 
64
177
  ## License
65
178
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proappstore/sdk",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "Browser SDK for paid apps on proappstore.online — subscriptions, license keys, premium modules.",
5
5
  "license": "MIT",
6
6
  "type": "module",