@sudobility/consumables_client 0.0.9 → 0.0.11

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 (3) hide show
  1. package/CLAUDE.md +0 -7
  2. package/README.md +86 -0
  3. package/package.json +3 -3
package/CLAUDE.md CHANGED
@@ -131,13 +131,6 @@ Dependency direction: `consumables_pages` --> `consumables_client` --> `consumab
131
131
  - **RN adapter defaults source to "apple"**: The React Native adapter currently always returns `"apple"` as the purchase source. Platform detection for Android ("google") is not implemented.
132
132
  - **`removeComments: true` in tsconfig**: JSDoc comments are stripped from the build output. This is intentional for bundle size but means consumers cannot see inline docs from `dist/`.
133
133
 
134
- ## Testing
135
-
136
- - Run tests: `bun test` (uses vitest)
137
- - Tests use **mocked adapters** -- they do not call real RevenueCat or backend APIs.
138
- - When adding new functionality, write tests using the mock adapter pattern found in existing test files.
139
- - Test hooks by verifying they respond correctly to singleton events (balance changes, purchase completions).
140
-
141
134
  ## Publishing
142
135
 
143
136
  - Package: `@sudobility/consumables_client` (public on npm)
package/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # @sudobility/consumables_client
2
+
3
+ Cross-platform consumable credits client with RevenueCat adapter pattern.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @sudobility/consumables_client
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import {
15
+ initializeConsumables,
16
+ setConsumablesUserId,
17
+ onConsumablesBalanceChange,
18
+ ConsumablesService,
19
+ createRevenueCatWebAdapter,
20
+ createRevenueCatRNAdapter,
21
+ } from '@sudobility/consumables_client';
22
+
23
+ // Initialize at app startup
24
+ initializeConsumables({ adapter, apiClient });
25
+
26
+ // Set user on auth change
27
+ setConsumablesUserId(userId, email);
28
+
29
+ // React hooks
30
+ import {
31
+ useBalance,
32
+ useConsumableProducts,
33
+ usePurchaseCredits,
34
+ usePurchaseHistory,
35
+ useUsageHistory,
36
+ } from '@sudobility/consumables_client';
37
+ ```
38
+
39
+ ## API
40
+
41
+ ### Core
42
+
43
+ | Export | Description |
44
+ |--------|-------------|
45
+ | `ConsumablesService` | Core orchestration class (caching, purchase flow, usage) |
46
+ | `initializeConsumables(config)` | Module-level singleton initialization |
47
+ | `setConsumablesUserId(userId, email?)` | Set user on auth state changes |
48
+ | `onConsumablesBalanceChange(listener)` | Subscribe to balance changes (returns unsubscribe) |
49
+ | `onConsumablesUserIdChange(listener)` | Subscribe to user changes (returns unsubscribe) |
50
+
51
+ ### Adapters
52
+
53
+ | Export | Description |
54
+ |--------|-------------|
55
+ | `ConsumablesAdapter` | Interface for platform-specific RevenueCat adapters |
56
+ | Web adapter | Wraps `@revenuecat/purchases-js` (lazy-loaded) |
57
+ | RN adapter | Wraps `react-native-purchases` (lazy-loaded) |
58
+
59
+ ### Hooks
60
+
61
+ | Hook | Description |
62
+ |------|-------------|
63
+ | `useBalance()` | Current credit balance (subscribes to changes) |
64
+ | `useConsumableProducts(offeringId)` | Available credit packages from an offering |
65
+ | `usePurchaseCredits()` | Purchase flow with `isPurchasing` state |
66
+ | `usePurchaseHistory(limit?)` | Paginated purchase audit trail |
67
+ | `useUsageHistory(limit?)` | Paginated usage audit trail |
68
+
69
+ ### Types
70
+
71
+ `CreditPackage`, `CreditOffering`, `CreditBalance`, `ConsumablePurchaseResult`, `ConsumablePurchaseParams`
72
+
73
+ ## Development
74
+
75
+ ```bash
76
+ bun run build # Build ESM via tsc
77
+ bun run dev # Watch mode
78
+ bun test # Run tests (vitest)
79
+ bun run typecheck # TypeScript check
80
+ bun run lint # ESLint
81
+ bun run format # Prettier format
82
+ ```
83
+
84
+ ## License
85
+
86
+ BUSL-1.1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sudobility/consumables_client",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "Cross-platform consumable credits client with RevenueCat adapter pattern",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -38,7 +38,7 @@
38
38
  "prepublishOnly": "bun run build"
39
39
  },
40
40
  "peerDependencies": {
41
- "@sudobility/types": "^1.9.54",
41
+ "@sudobility/types": "^1.9.57",
42
42
  "react": "^18.0.0 || ^19.0.0",
43
43
  "@revenuecat/purchases-js": "^1.0.0",
44
44
  "react-native-purchases": ">=7.0.0"
@@ -54,7 +54,7 @@
54
54
  "devDependencies": {
55
55
  "@eslint/js": "^10.0.1",
56
56
  "@revenuecat/purchases-js": "^1.1.3",
57
- "@sudobility/types": "^1.9.54",
57
+ "@sudobility/types": "^1.9.57",
58
58
  "@types/bun": "^1.2.8",
59
59
  "@types/node": "^22.0.0",
60
60
  "@types/react": "^19.2.5",