@umituz/react-native-subscription 2.37.28 → 2.37.30

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-subscription",
3
- "version": "2.37.28",
3
+ "version": "2.37.30",
4
4
  "description": "Complete subscription management with RevenueCat, paywall UI, and credits system for React Native apps",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -9,7 +9,23 @@ declare const __DEV__: boolean;
9
9
 
10
10
  function buildSuccessResult(deps: InitializerDeps, customerInfo: CustomerInfo, offerings: any): InitializeResult {
11
11
  const isPremium = !!customerInfo.entitlements.active[deps.config.entitlementIdentifier];
12
- return { success: true, offering: offerings.current, isPremium };
12
+ return { success: true, offering: offerings?.current ?? null, isPremium };
13
+ }
14
+
15
+ /**
16
+ * Fetch offerings separately - non-fatal if it fails.
17
+ * Empty offerings (no products configured in RevenueCat dashboard) should NOT
18
+ * block SDK initialization. The SDK is still usable for premium checks, purchases, etc.
19
+ */
20
+ async function fetchOfferingsSafe(): Promise<any> {
21
+ try {
22
+ return await Purchases.getOfferings();
23
+ } catch (error) {
24
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
25
+ console.warn('[UserSwitchHandler] Offerings fetch failed (non-fatal):', error);
26
+ }
27
+ return { current: null, all: {} };
28
+ }
13
29
  }
14
30
 
15
31
  function normalizeUserId(userId: string): string | null {
@@ -87,7 +103,7 @@ async function performUserSwitch(
87
103
 
88
104
  deps.setInitialized(true);
89
105
  deps.setCurrentUserId(normalizedUserId || undefined);
90
- const offerings = await Purchases.getOfferings();
106
+ const offerings = await fetchOfferingsSafe();
91
107
 
92
108
  if (typeof __DEV__ !== 'undefined' && __DEV__) {
93
109
  console.log('[UserSwitchHandler] ✅ User switch completed successfully');
@@ -136,9 +152,11 @@ export async function handleInitialConfiguration(
136
152
  console.log('[UserSwitchHandler] ✅ Purchases.configure() successful');
137
153
  }
138
154
 
155
+ // Fetch customer info (critical) and offerings (non-fatal) separately.
156
+ // Empty offerings should NOT block initialization - SDK is still usable.
139
157
  const [customerInfo, offerings] = await Promise.all([
140
158
  Purchases.getCustomerInfo(),
141
- Purchases.getOfferings(),
159
+ fetchOfferingsSafe(),
142
160
  ]);
143
161
 
144
162
  const currentUserId = await Purchases.getAppUserID();
@@ -198,11 +216,11 @@ export async function fetchCurrentUserData(deps: InitializerDeps): Promise<Initi
198
216
  try {
199
217
  const [customerInfo, offerings] = await Promise.all([
200
218
  Purchases.getCustomerInfo(),
201
- Purchases.getOfferings(),
219
+ fetchOfferingsSafe(),
202
220
  ]);
203
221
  return buildSuccessResult(deps, customerInfo, offerings);
204
222
  } catch (error) {
205
- console.error('[UserSwitchHandler] Failed to fetch customer info/offerings for initialized user', {
223
+ console.error('[UserSwitchHandler] Failed to fetch customer info for initialized user', {
206
224
  error
207
225
  });
208
226
  return FAILED_INITIALIZATION_RESULT;
@@ -74,9 +74,13 @@ class SubscriptionManagerImpl {
74
74
  this.serviceInstance = service ?? null;
75
75
  this.ensurePackageHandlerInitialized();
76
76
 
77
- if (success) {
78
- // Notify reactive state so React components re-render and enable their queries
79
- const notifyUserId = (userId && userId.length > 0) ? userId : null;
77
+ // Always notify reactive state when service is available, even if offerings fetch failed.
78
+ // This ensures React components (useSubscriptionPackages, useSubscriptionStatus) are unblocked.
79
+ // The service IS configured and usable - empty offerings is not a fatal error.
80
+ const notifyUserId = (userId && userId.length > 0) ? userId : null;
81
+ if (service) {
82
+ initializationState.markInitialized(notifyUserId);
83
+ } else if (success) {
80
84
  initializationState.markInitialized(notifyUserId);
81
85
  }
82
86
 
@@ -54,7 +54,10 @@ export async function fetchOfferings(deps: OfferingsFetcherDeps): Promise<Purcha
54
54
  await new Promise<void>(resolve => setTimeout(resolve, FETCH_RETRY_DELAY_MS));
55
55
  continue;
56
56
  }
57
- throw new Error(`Failed to fetch offerings: ${error instanceof Error ? error.message : "Unknown error"}`);
57
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
58
+ console.warn('[OfferingsFetcher] Failed to fetch offerings after all retries:', error);
59
+ }
60
+ return null;
58
61
  }
59
62
  }
60
63
 
@@ -40,16 +40,15 @@ export class InitializationCache {
40
40
  }
41
41
 
42
42
  setPromise(promise: Promise<boolean>, userId: string): void {
43
- // Add to pending queue immediately (atomic operation)
44
- this.pendingQueue.set(userId, promise);
45
-
46
- this.initPromise = promise;
47
43
  this.promiseUserId = userId;
48
44
  this.promiseCompleted = false;
49
45
 
50
46
  const targetUserId = userId;
51
47
 
52
- promise
48
+ // Build the handled chain that ALWAYS resolves (never rejects).
49
+ // This is critical: pendingQueue must store a non-rejectable promise so that
50
+ // callers who receive it via tryAcquireInitialization never get an unhandled rejection.
51
+ const chain: Promise<boolean> = promise
53
52
  .then((result) => {
54
53
  if (result && this.promiseUserId === targetUserId) {
55
54
  this.currentUserId = targetUserId;
@@ -65,12 +64,16 @@ export class InitializationCache {
65
64
  }
66
65
  this.promiseCompleted = true;
67
66
  console.error('[InitializationCache] Initialization failed', { userId: targetUserId, error });
68
- return false;
67
+ return false as boolean;
69
68
  })
70
69
  .finally(() => {
71
70
  // Remove from queue when complete
72
71
  this.pendingQueue.delete(targetUserId);
73
72
  });
73
+
74
+ // Store the chain (not the original promise) so callers never receive a rejection
75
+ this.initPromise = chain;
76
+ this.pendingQueue.set(userId, chain);
74
77
  }
75
78
 
76
79
  getCurrentUserId(): string | null {