@sudobility/subscription_lib 0.0.6 → 0.0.7

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.
@@ -1 +1 @@
1
- {"version":3,"file":"revenuecat-web.d.ts","sourceRoot":"","sources":["../../src/adapters/revenuecat-web.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAKV,mBAAmB,EACpB,MAAM,kBAAkB,CAAC;AAW1B;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAEzE;AAmCD;;;GAGG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,MAAM,EACd,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAkCf;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAM1C;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,mBAAmB,CA8L7D"}
1
+ {"version":3,"file":"revenuecat-web.d.ts","sourceRoot":"","sources":["../../src/adapters/revenuecat-web.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAKV,mBAAmB,EACpB,MAAM,kBAAkB,CAAC;AAW1B;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAEzE;AA0BD;;;GAGG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,MAAM,EACd,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAkCf;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAM1C;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,mBAAmB,CAyM7D"}
@@ -16,32 +16,23 @@ let apiKey = null;
16
16
  export function configureRevenueCatAdapter(revenueCatApiKey) {
17
17
  apiKey = revenueCatApiKey;
18
18
  }
19
- /**
20
- * Get or create an anonymous user ID for RevenueCat.
21
- * RevenueCat web SDK requires a user ID, so we generate one for anonymous users.
22
- */
23
- function getAnonymousUserId() {
24
- const STORAGE_KEY = 'rc_anonymous_user_id';
25
- let anonId = localStorage.getItem(STORAGE_KEY);
26
- if (!anonId) {
27
- anonId = `anon_${globalThis.crypto.randomUUID()}`;
28
- localStorage.setItem(STORAGE_KEY, anonId);
29
- }
30
- return anonId;
31
- }
32
19
  /**
33
20
  * Lazily initialize RevenueCat SDK when first needed.
34
- * Uses anonymous user ID if no user is logged in.
21
+ * Requires a user to be set first via setRevenueCatUser().
35
22
  */
36
23
  async function ensureInitialized() {
37
24
  if (!apiKey) {
38
25
  throw new Error('RevenueCat not configured');
39
26
  }
27
+ if (!currentUserId) {
28
+ throw new Error('RevenueCat user not set. Call setRevenueCatUser() first.');
29
+ }
40
30
  if (!purchasesInstance) {
41
31
  const SDK = await import('@revenuecat/purchases-js');
42
- // Use current user ID or anonymous ID - RevenueCat web SDK requires a user ID
43
- const userId = currentUserId || getAnonymousUserId();
44
- purchasesInstance = SDK.Purchases.configure({ apiKey, appUserId: userId });
32
+ purchasesInstance = SDK.Purchases.configure({
33
+ apiKey,
34
+ appUserId: currentUserId,
35
+ });
45
36
  }
46
37
  return purchasesInstance;
47
38
  }
@@ -109,6 +100,11 @@ export function createRevenueCatAdapter() {
109
100
  }
110
101
  },
111
102
  async getOfferings() {
103
+ // Return empty offerings if no user is set
104
+ if (!currentUserId) {
105
+ console.log('[revenuecat-web] No user set, returning empty offerings');
106
+ return { all: {}, current: null };
107
+ }
112
108
  try {
113
109
  const purchases = await ensureInitialized();
114
110
  const offerings = await purchases.getOfferings();
@@ -195,6 +191,10 @@ export function createRevenueCatAdapter() {
195
191
  }
196
192
  },
197
193
  async getCustomerInfo() {
194
+ // Return empty customer info if no user is set
195
+ if (!currentUserId) {
196
+ return { activeSubscriptions: [], entitlements: { active: {} } };
197
+ }
198
198
  try {
199
199
  const purchases = await ensureInitialized();
200
200
  const customerInfo = await purchases.getCustomerInfo();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sudobility/subscription_lib",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Cross-platform subscription management with RevenueCat adapter pattern",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",