@sudobility/subscription_lib 0.0.19 → 0.0.20
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 +96 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# @sudobility/subscription_lib
|
|
2
|
+
|
|
3
|
+
Cross-platform subscription management library that abstracts RevenueCat SDK differences between web and React Native behind a unified adapter interface.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @sudobility/subscription_lib
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Peer Dependencies
|
|
12
|
+
|
|
13
|
+
- `react` ^18.0.0 || ^19.0.0
|
|
14
|
+
- `@sudobility/types` ^1.9.53
|
|
15
|
+
- `@revenuecat/purchases-js` ^1.0.0 (web only, optional)
|
|
16
|
+
- `react-native-purchases` >= 7.0.0 (React Native only, optional)
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import {
|
|
22
|
+
initializeSubscription,
|
|
23
|
+
configureRevenueCatAdapter,
|
|
24
|
+
createRevenueCatAdapter,
|
|
25
|
+
useSubscriptions,
|
|
26
|
+
useUserSubscription,
|
|
27
|
+
useSubscribable,
|
|
28
|
+
} from '@sudobility/subscription_lib';
|
|
29
|
+
|
|
30
|
+
// App startup
|
|
31
|
+
configureRevenueCatAdapter(REVENUECAT_API_KEY);
|
|
32
|
+
initializeSubscription({
|
|
33
|
+
adapter: createRevenueCatAdapter(),
|
|
34
|
+
freeTier: { packageId: 'free', displayName: 'Free' },
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// React hooks
|
|
38
|
+
const { offer, isLoading } = useSubscriptions('default');
|
|
39
|
+
const { subscription } = useUserSubscription();
|
|
40
|
+
const { subscribablePackageIds } = useSubscribable('default');
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## API
|
|
44
|
+
|
|
45
|
+
### Core Singleton
|
|
46
|
+
|
|
47
|
+
| Function | Description |
|
|
48
|
+
|----------|-------------|
|
|
49
|
+
| `initializeSubscription(config)` | Initialize with adapter + free tier config |
|
|
50
|
+
| `setSubscriptionUserId(id, email?)` | Set current user, triggers reload |
|
|
51
|
+
| `refreshSubscription()` | Reload offerings + customer info |
|
|
52
|
+
| `getSubscriptionInstance()` | Get the SubscriptionService singleton |
|
|
53
|
+
|
|
54
|
+
### Hooks
|
|
55
|
+
|
|
56
|
+
| Hook | Description |
|
|
57
|
+
|------|-------------|
|
|
58
|
+
| `useSubscriptions(offerId)` | Fetch offer/product catalog (cached) |
|
|
59
|
+
| `useUserSubscription()` | Current user subscription status |
|
|
60
|
+
| `useSubscriptionPeriods(offerId)` | Available billing periods, sorted |
|
|
61
|
+
| `useSubscriptionForPeriod(offerId, period)` | Packages for a period, sorted by price |
|
|
62
|
+
| `useSubscribable(offerId)` | Upgrade-eligible package IDs |
|
|
63
|
+
|
|
64
|
+
### Built-in Adapters
|
|
65
|
+
|
|
66
|
+
- **Web**: `configureRevenueCatAdapter`, `createRevenueCatAdapter`, `setRevenueCatUser`, `clearRevenueCatUser`
|
|
67
|
+
- **React Native**: `configureRevenueCatRNAdapter`, `createRevenueCatRNAdapter`, `setRevenueCatRNUser`, `clearRevenueCatRNUser`
|
|
68
|
+
|
|
69
|
+
### Utilities
|
|
70
|
+
|
|
71
|
+
`parseISO8601Period`, `getPeriodRank`, `comparePeriods`, `calculatePackageLevels`, `findUpgradeablePackages`
|
|
72
|
+
|
|
73
|
+
### Key Types
|
|
74
|
+
|
|
75
|
+
`SubscriptionAdapter`, `SubscriptionOffer`, `SubscriptionPackage`, `CurrentSubscription`, `FreeTierConfig`, `SubscriptionPeriod`
|
|
76
|
+
|
|
77
|
+
## Development
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
bun run build # Compile TS to dist/
|
|
81
|
+
bun run dev # Watch mode (tsc --watch)
|
|
82
|
+
bun test # Run tests (vitest run)
|
|
83
|
+
bun run typecheck # TypeScript check
|
|
84
|
+
bun run lint # ESLint
|
|
85
|
+
bun run format # Prettier
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Pre-commit:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
bun run typecheck && bun run lint && bun test && bun run build
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
BUSL-1.1
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sudobility/subscription_lib",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"description": "Cross-platform subscription management with RevenueCat adapter pattern",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"prepublishOnly": "bun run verify"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@sudobility/types": "^1.9.
|
|
33
|
+
"@sudobility/types": "^1.9.57",
|
|
34
34
|
"react": "^18.0.0 || ^19.0.0",
|
|
35
35
|
"@revenuecat/purchases-js": "^1.0.0",
|
|
36
36
|
"react-native-purchases": ">=7.0.0"
|