@umituz/react-native-subscription 2.14.21 → 2.14.23

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.14.21",
3
+ "version": "2.14.23",
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",
@@ -3,7 +3,7 @@
3
3
  * Handles SDK initialization logic
4
4
  */
5
5
 
6
- import Purchases from "react-native-purchases";
6
+ import Purchases, { LOG_LEVEL } from "react-native-purchases";
7
7
  import type { InitializeResult } from '../../application/ports/IRevenueCatService';
8
8
  import type { RevenueCatConfig } from '../../domain/value-objects/RevenueCatConfig';
9
9
  import { getErrorMessage } from '../../domain/types/RevenueCatTypes';
@@ -24,6 +24,50 @@ export interface InitializerDeps {
24
24
 
25
25
  // Track if Purchases.configure has been called globally
26
26
  let isPurchasesConfigured = false;
27
+ let isLogHandlerConfigured = false;
28
+
29
+ /**
30
+ * Configures custom log handler to filter StoreKit 2 internal errors
31
+ * These errors occur on simulator when no prior purchases exist
32
+ */
33
+ function configureLogHandler(): void {
34
+ if (isLogHandlerConfigured) return;
35
+
36
+ Purchases.setLogHandler((logLevel, message) => {
37
+ // Filter out StoreKit 2 AppTransaction errors (normal on simulator)
38
+ const isAppTransactionError =
39
+ message.includes("Purchase was cancelled") ||
40
+ message.includes("AppTransaction") ||
41
+ message.includes("Couldn't find previous transactions");
42
+
43
+ if (isAppTransactionError) {
44
+ // Downgrade to debug level - only show in __DEV__
45
+ if (__DEV__) {
46
+ console.debug("[RevenueCat] (filtered)", message);
47
+ }
48
+ return;
49
+ }
50
+
51
+ // Normal logging for other messages
52
+ switch (logLevel) {
53
+ case LOG_LEVEL.VERBOSE:
54
+ case LOG_LEVEL.DEBUG:
55
+ if (__DEV__) console.debug("[RevenueCat]", message);
56
+ break;
57
+ case LOG_LEVEL.INFO:
58
+ if (__DEV__) console.info("[RevenueCat]", message);
59
+ break;
60
+ case LOG_LEVEL.WARN:
61
+ if (__DEV__) console.warn("[RevenueCat]", message);
62
+ break;
63
+ case LOG_LEVEL.ERROR:
64
+ console.error("[RevenueCat]", message);
65
+ break;
66
+ }
67
+ });
68
+
69
+ isLogHandlerConfigured = true;
70
+ }
27
71
 
28
72
  export async function initializeSDK(
29
73
  deps: InitializerDeps,
@@ -73,7 +117,31 @@ export async function initializeSDK(
73
117
  // Case 2: Already configured but different user or re-initializing
74
118
  if (isPurchasesConfigured) {
75
119
  try {
76
- const { customerInfo } = await Purchases.logIn(userId);
120
+ // Check if we're already logged in with this user ID
121
+ const currentAppUserId = await Purchases.getAppUserID();
122
+
123
+ if (__DEV__) {
124
+ console.log('[DEBUG RevenueCatInitializer] Current app user ID check', {
125
+ currentAppUserId,
126
+ requestedUserId: userId,
127
+ needsLogin: currentAppUserId !== userId,
128
+ });
129
+ }
130
+
131
+ // Only call logIn if the user ID is different
132
+ let customerInfo;
133
+ if (currentAppUserId !== userId) {
134
+ if (__DEV__) {
135
+ console.log('[DEBUG RevenueCatInitializer] User ID changed, calling logIn');
136
+ }
137
+ const result = await Purchases.logIn(userId);
138
+ customerInfo = result.customerInfo;
139
+ } else {
140
+ if (__DEV__) {
141
+ console.log('[DEBUG RevenueCatInitializer] Already logged in with same user ID, skipping logIn');
142
+ }
143
+ customerInfo = await Purchases.getCustomerInfo();
144
+ }
77
145
 
78
146
  deps.setInitialized(true);
79
147
  deps.setCurrentUserId(userId);
@@ -116,6 +184,9 @@ export async function initializeSDK(
116
184
  }
117
185
 
118
186
  try {
187
+ // Configure log handler before SDK initialization
188
+ configureLogHandler();
189
+
119
190
  if (__DEV__) {
120
191
  console.log('[DEBUG RevenueCatInitializer] Calling Purchases.configure', {
121
192
  apiKey: key.substring(0, 10) + '...',