@umituz/react-native-subscription 2.10.9 → 2.10.10

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.10.9",
3
+ "version": "2.10.10",
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",
@@ -91,10 +91,6 @@ class SubscriptionManagerImpl {
91
91
  if (existingPromise) return existingPromise;
92
92
  }
93
93
 
94
- if (this.initCache.shouldReinitialize(effectiveUserId) && this.serviceInstance) {
95
- await this.serviceInstance.reset();
96
- }
97
-
98
94
  const promise = this.performInitialization(effectiveUserId);
99
95
  this.initCache.setPromise(promise, effectiveUserId);
100
96
 
@@ -107,7 +103,7 @@ class SubscriptionManagerImpl {
107
103
 
108
104
  isInitializedForUser(userId: string): boolean {
109
105
  return this.serviceInstance?.isInitialized() === true &&
110
- this.initCache.getCurrentUserId() === userId;
106
+ this.initCache.getCurrentUserId() === userId;
111
107
  }
112
108
 
113
109
  async getPackages(): Promise<PurchasesPackage[]> {
@@ -11,7 +11,6 @@ import { resolveApiKey } from "../utils/ApiKeyResolver";
11
11
  import {
12
12
  trackPackageError,
13
13
  addPackageBreadcrumb,
14
- trackPackageWarning,
15
14
  } from "@umituz/react-native-sentry";
16
15
 
17
16
  export interface InitializerDeps {
@@ -23,6 +22,9 @@ export interface InitializerDeps {
23
22
  setCurrentUserId: (userId: string) => void;
24
23
  }
25
24
 
25
+ // Track if Purchases.configure has been called globally
26
+ let isPurchasesConfigured = false;
27
+
26
28
  export async function initializeSDK(
27
29
  deps: InitializerDeps,
28
30
  userId: string,
@@ -31,71 +33,66 @@ export async function initializeSDK(
31
33
  addPackageBreadcrumb("subscription", "SDK initialization started", {
32
34
  userId,
33
35
  hasApiKey: !!apiKey,
36
+ isAlreadyConfigured: isPurchasesConfigured,
34
37
  });
35
38
 
36
39
  if (__DEV__) {
37
- console.log("[RevenueCat] initializeSDK() called with userId:", userId);
40
+ console.log("[RevenueCat] initializeSDK() called with userId:", userId, "isPurchasesConfigured:", isPurchasesConfigured);
38
41
  }
39
42
 
40
- // Check if already initialized with same userId - skip re-configuration
41
- if (deps.isInitialized()) {
42
- const currentUserId = deps.getCurrentUserId();
43
- if (currentUserId === userId) {
44
- addPackageBreadcrumb("subscription", "Already initialized, fetching current state", {
45
- userId,
46
- });
43
+ // Case 1: Already initialized with the same user ID
44
+ if (deps.isInitialized() && deps.getCurrentUserId() === userId) {
45
+ if (__DEV__) {
46
+ console.log("[RevenueCat] Already initialized with same userId, skipping configure");
47
+ }
47
48
 
48
- if (__DEV__) {
49
- console.log("[RevenueCat] Already initialized with same userId, skipping configure");
50
- }
51
- // Just fetch current state without re-configuring
52
- try {
53
- const [customerInfo, offerings] = await Promise.all([
54
- Purchases.getCustomerInfo(),
55
- Purchases.getOfferings(),
56
- ]);
57
- const entitlementId = deps.config.entitlementIdentifier;
58
- const hasPremium = !!customerInfo.entitlements.active[entitlementId];
59
- return { success: true, offering: offerings.current, hasPremium };
60
- } catch (error) {
61
- trackPackageError(
62
- error instanceof Error ? error : new Error(String(error)),
63
- {
64
- packageName: "subscription",
65
- operation: "get_current_state",
66
- userId,
67
- }
68
- );
69
-
70
- if (__DEV__) {
71
- console.log("[RevenueCat] Failed to get current state:", error);
49
+ try {
50
+ const [customerInfo, offerings] = await Promise.all([
51
+ Purchases.getCustomerInfo(),
52
+ Purchases.getOfferings(),
53
+ ]);
54
+ const entitlementId = deps.config.entitlementIdentifier;
55
+ const hasPremium = !!customerInfo.entitlements.active[entitlementId];
56
+ return { success: true, offering: offerings.current, hasPremium };
57
+ } catch (error) {
58
+ trackPackageError(
59
+ error instanceof Error ? error : new Error(String(error)),
60
+ {
61
+ packageName: "subscription",
62
+ operation: "get_current_state",
63
+ userId,
72
64
  }
73
- return { success: false, offering: null, hasPremium: false };
74
- }
75
- } else {
76
- addPackageBreadcrumb("subscription", "User changed, logging out previous user", {
77
- previousUserId: currentUserId,
78
- newUserId: userId,
79
- });
80
-
81
- if (__DEV__) {
82
- console.log("[RevenueCat] Different userId, will re-configure");
83
- }
84
- // Different userId - need to logout first
85
- try {
86
- await Purchases.logOut();
87
- } catch (error) {
88
- trackPackageWarning("subscription", "Logout failed during user change", {
89
- error: error instanceof Error ? error.message : String(error),
90
- previousUserId: currentUserId,
91
- newUserId: userId,
92
- });
93
- }
65
+ );
66
+ return { success: false, offering: null, hasPremium: false };
94
67
  }
95
68
  }
96
69
 
70
+ // Case 2: Already configured but different user or re-initializing
71
+ if (isPurchasesConfigured) {
72
+ if (__DEV__) {
73
+ console.log("[RevenueCat] SDK already configured, using logIn for userId:", userId);
74
+ }
75
+
76
+ try {
77
+ const { customerInfo } = await Purchases.logIn(userId);
78
+
79
+ deps.setInitialized(true);
80
+ deps.setCurrentUserId(userId);
97
81
 
82
+ const offerings = await Purchases.getOfferings();
83
+ const entitlementId = deps.config.entitlementIdentifier;
84
+ const hasPremium = !!customerInfo.entitlements.active[entitlementId];
85
+
86
+ return { success: true, offering: offerings.current, hasPremium };
87
+ } catch (error) {
88
+ if (__DEV__) console.warn("[RevenueCat] logIn failed:", error);
89
+ // If logIn fails, we don't necessarily want to re-configure if it's already configured
90
+ // But we can return failure
91
+ return { success: false, offering: null, hasPremium: false };
92
+ }
93
+ }
98
94
 
95
+ // Case 3: First time configuration
99
96
  const key = apiKey || resolveApiKey(deps.config);
100
97
  if (!key) {
101
98
  const error = new Error("No RevenueCat API key available");
@@ -104,38 +101,25 @@ export async function initializeSDK(
104
101
  operation: "sdk_init_no_key",
105
102
  userId,
106
103
  });
107
-
108
- if (__DEV__) {
109
- console.log("[RevenueCat] No API key available");
110
- }
111
104
  return { success: false, offering: null, hasPremium: false };
112
105
  }
113
106
 
114
107
  try {
115
108
  if (deps.isUsingTestStore()) {
116
- addPackageBreadcrumb("subscription", "Using test store configuration", {
117
- userId,
118
- });
119
-
120
109
  if (__DEV__) {
121
110
  console.log("[RevenueCat] Using Test Store key");
122
111
  }
123
112
  }
124
113
 
125
- addPackageBreadcrumb("subscription", "Configuring SDK", { userId });
126
-
127
114
  if (__DEV__) {
128
115
  console.log("[RevenueCat] Calling Purchases.configure()...");
129
116
  }
130
117
 
131
118
  await Purchases.configure({ apiKey: key, appUserID: userId });
119
+ isPurchasesConfigured = true;
132
120
  deps.setInitialized(true);
133
121
  deps.setCurrentUserId(userId);
134
122
 
135
- addPackageBreadcrumb("subscription", "SDK configured successfully", {
136
- userId,
137
- });
138
-
139
123
  if (__DEV__) {
140
124
  console.log("[RevenueCat] SDK configured successfully");
141
125
  }