@sudobility/subscription_service 1.0.7 → 1.0.9

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 +82 -0
  3. package/package.json +2 -2
package/CLAUDE.md CHANGED
@@ -141,13 +141,6 @@ APIs using this library:
141
141
  - whisperly_api
142
142
  - ratelimit_service
143
143
 
144
- ## Testing
145
-
146
- - Framework: Vitest (vitest run)
147
- - Tests located in `tests/` directory (not alongside source)
148
- - Uses `vi.fn()` and `vi.stubGlobal("fetch", ...)` to mock HTTP calls
149
- - Tests cover: 404 handling, API errors, active entitlements, expired entitlements, sandbox filtering, test mode, multiple entitlements with earliest date
150
-
151
144
  ## Publishing
152
145
 
153
146
  ```bash
package/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # @sudobility/subscription_service
2
+
3
+ Shared backend library for subscription management using RevenueCat. Provides a `SubscriptionHelper` class that calls the RevenueCat REST API v1 to fetch user entitlements and subscription information. Server-side only.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @sudobility/subscription_service
9
+ ```
10
+
11
+ ### Peer Dependencies
12
+
13
+ - `@sudobility/types` ^1.9.53
14
+
15
+ ## Usage
16
+
17
+ ```typescript
18
+ import { SubscriptionHelper } from '@sudobility/subscription_service';
19
+ import { NONE_ENTITLEMENT } from '@sudobility/types';
20
+
21
+ const helper = new SubscriptionHelper({
22
+ revenueCatApiKey: process.env.REVENUECAT_API_KEY!,
23
+ });
24
+
25
+ // Get active entitlement names
26
+ const entitlements = await helper.getEntitlements(userId);
27
+ // Returns: ["pro"] or ["none"]
28
+
29
+ // Get full subscription info
30
+ const info = await helper.getSubscriptionInfo(userId);
31
+ // Returns: { entitlements: ["pro"], subscriptionStartedAt: Date | null }
32
+
33
+ // Check subscription status
34
+ if (!info.entitlements.includes(NONE_ENTITLEMENT)) {
35
+ // User has active subscription
36
+ }
37
+ ```
38
+
39
+ ## API
40
+
41
+ ### SubscriptionHelper
42
+
43
+ | Method | Signature | Description |
44
+ |--------|-----------|-------------|
45
+ | `getEntitlements` | `(userId, testMode?) => Promise<string[]>` | Get active entitlement names |
46
+ | `getSubscriptionInfo` | `(userId, testMode?) => Promise<SubscriptionInfo>` | Entitlements + subscription start date |
47
+
48
+ ### Configuration
49
+
50
+ ```typescript
51
+ interface SubscriptionHelperConfig {
52
+ revenueCatApiKey: string;
53
+ baseUrl?: string; // Default: https://api.revenuecat.com/v1
54
+ }
55
+ ```
56
+
57
+ ### Type Exports
58
+
59
+ | Export | Description |
60
+ |--------|-------------|
61
+ | `SubscriptionHelper` | Main API client class |
62
+ | `SubscriptionHelperConfig` | Config interface |
63
+ | `SubscriptionInfo` | Return type: `{ entitlements, subscriptionStartedAt }` |
64
+ | `RevenueCatEntitlement` | Raw entitlement from RevenueCat API |
65
+ | `RevenueCatSubscription` | Raw subscription from RevenueCat API |
66
+ | `RevenueCatSubscriberResponse` | Full subscriber response shape |
67
+ | `NONE_ENTITLEMENT` | Re-exported from `@sudobility/types` |
68
+
69
+ ## Development
70
+
71
+ ```bash
72
+ bun run verify # All checks + build (typecheck -> lint -> test -> build)
73
+ bun run build # Build ESM (tsc)
74
+ bun test # Run tests (vitest run)
75
+ bun run typecheck # TypeScript check
76
+ bun run lint # ESLint
77
+ bun run format # Prettier
78
+ ```
79
+
80
+ ## License
81
+
82
+ BUSL-1.1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sudobility/subscription_service",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Shared subscription management library using RevenueCat for entitlements",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -38,7 +38,7 @@
38
38
  "author": "Sudobility",
39
39
  "license": "BUSL-1.1",
40
40
  "peerDependencies": {
41
- "@sudobility/types": "^1.9.54"
41
+ "@sudobility/types": "^1.9.57"
42
42
  },
43
43
  "devDependencies": {
44
44
  "vitest": "^4.0.4",