@umituz/react-native-subscription 2.33.8 → 2.33.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-subscription",
3
- "version": "2.33.8",
3
+ "version": "2.33.9",
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",
@@ -6,6 +6,8 @@ import { emitCreditsUpdated } from "./syncEventEmitter";
6
6
  import { generateInitSyncId, generateStatusSyncId } from "./syncIdGenerators";
7
7
  import { NO_SUBSCRIPTION_PRODUCT_ID, DEFAULT_FREE_USER_DATA } from "./syncConstants";
8
8
 
9
+ declare const __DEV__: boolean;
10
+
9
11
  export const handleExpiredSubscription = async (userId: string): Promise<void> => {
10
12
  await getCreditsRepository().syncExpiredStatus(userId);
11
13
  emitCreditsUpdated(userId);
@@ -32,6 +34,17 @@ export const handlePremiumStatusSync = async (
32
34
  willRenew: boolean,
33
35
  periodType: PeriodType | null
34
36
  ): Promise<void> => {
37
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
38
+ console.log("[StatusChangeHandlers] handlePremiumStatusSync called:", {
39
+ userId,
40
+ isPremium,
41
+ productId,
42
+ expiresAt,
43
+ willRenew,
44
+ periodType,
45
+ });
46
+ }
47
+
35
48
  const revenueCatData: RevenueCatData = {
36
49
  expirationDate: expiresAt,
37
50
  willRenew,
@@ -45,6 +58,17 @@ export const handlePremiumStatusSync = async (
45
58
  };
46
59
 
47
60
  const statusSyncId = generateStatusSyncId(userId, isPremium);
61
+
62
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
63
+ console.log("[StatusChangeHandlers] Calling initializeCredits with:", {
64
+ userId,
65
+ statusSyncId,
66
+ productId,
67
+ source: PURCHASE_SOURCE.SETTINGS,
68
+ type: PURCHASE_TYPE.INITIAL,
69
+ });
70
+ }
71
+
48
72
  await getCreditsRepository().initializeCredits(
49
73
  userId,
50
74
  statusSyncId,
@@ -54,5 +78,13 @@ export const handlePremiumStatusSync = async (
54
78
  PURCHASE_TYPE.INITIAL
55
79
  );
56
80
 
81
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
82
+ console.log("[StatusChangeHandlers] initializeCredits completed, emitting credits updated event");
83
+ }
84
+
57
85
  emitCreditsUpdated(userId);
86
+
87
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
88
+ console.log("[StatusChangeHandlers] ✅ handlePremiumStatusSync completed successfully");
89
+ }
58
90
  };
@@ -3,12 +3,22 @@ import type { RevenueCatConfig } from "../../../revenuecat/core/types";
3
3
  import { ListenerState } from "./listeners/ListenerState";
4
4
  import { processCustomerInfo } from "./listeners/CustomerInfoHandler";
5
5
 
6
+ declare const __DEV__: boolean;
7
+
6
8
  export class CustomerInfoListenerManager {
7
9
  private state = new ListenerState();
8
10
 
9
11
  setUserId(userId: string, config: RevenueCatConfig): void {
10
12
  const wasUserChange = this.state.hasUserChanged(userId);
11
13
 
14
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
15
+ console.log("[CustomerInfoListener] setUserId called:", {
16
+ userId,
17
+ wasUserChange,
18
+ hasListener: !!this.state.listener,
19
+ });
20
+ }
21
+
12
22
  if (wasUserChange) {
13
23
  this.removeListener();
14
24
  this.state.resetRenewalState();
@@ -22,6 +32,9 @@ export class CustomerInfoListenerManager {
22
32
  }
23
33
 
24
34
  clearUserId(): void {
35
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
36
+ console.log("[CustomerInfoListener] clearUserId called");
37
+ }
25
38
  this.state.currentUserId = null;
26
39
  this.state.resetRenewalState();
27
40
  }
@@ -29,8 +42,25 @@ export class CustomerInfoListenerManager {
29
42
  setupListener(config: RevenueCatConfig): void {
30
43
  this.removeListener();
31
44
 
45
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
46
+ console.log("[CustomerInfoListener] setupListener: Registering listener");
47
+ }
48
+
32
49
  this.state.listener = async (customerInfo: CustomerInfo) => {
33
- if (!this.state.currentUserId) return;
50
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
51
+ console.log("[CustomerInfoListener] 🔔 LISTENER TRIGGERED!", {
52
+ userId: this.state.currentUserId,
53
+ activeEntitlements: Object.keys(customerInfo.entitlements.active),
54
+ entitlementsCount: Object.keys(customerInfo.entitlements.all).length,
55
+ });
56
+ }
57
+
58
+ if (!this.state.currentUserId) {
59
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
60
+ console.log("[CustomerInfoListener] No userId - skipping");
61
+ }
62
+ return;
63
+ }
34
64
 
35
65
  this.state.renewalState = await processCustomerInfo(
36
66
  customerInfo,
@@ -38,9 +68,17 @@ export class CustomerInfoListenerManager {
38
68
  this.state.renewalState,
39
69
  config
40
70
  );
71
+
72
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
73
+ console.log("[CustomerInfoListener] processCustomerInfo completed");
74
+ }
41
75
  };
42
76
 
43
77
  Purchases.addCustomerInfoUpdateListener(this.state.listener);
78
+
79
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
80
+ console.log("[CustomerInfoListener] Listener registered successfully");
81
+ }
44
82
  }
45
83
 
46
84
  removeListener(): void {
@@ -3,6 +3,8 @@ import type { RevenueCatConfig } from "../../../../revenuecat/core/types";
3
3
  import { syncPremiumStatus } from "../../utils/PremiumStatusSyncer";
4
4
  import { detectRenewal, updateRenewalState, type RenewalState } from "../../utils/renewal";
5
5
 
6
+ declare const __DEV__: boolean;
7
+
6
8
  async function handleRenewal(
7
9
  userId: string,
8
10
  productId: string,
@@ -67,13 +69,34 @@ export async function processCustomerInfo(
67
69
  renewalState: RenewalState,
68
70
  config: RevenueCatConfig
69
71
  ): Promise<RenewalState> {
72
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
73
+ console.log("[CustomerInfoHandler] processCustomerInfo called:", {
74
+ userId,
75
+ renewalState,
76
+ entitlementId: config.entitlementIdentifier,
77
+ activeEntitlements: Object.keys(customerInfo.entitlements.active),
78
+ });
79
+ }
80
+
70
81
  const renewalResult = detectRenewal(
71
82
  renewalState,
72
83
  customerInfo,
73
84
  config.entitlementIdentifier
74
85
  );
75
86
 
87
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
88
+ console.log("[CustomerInfoHandler] Renewal detection result:", {
89
+ isRenewal: renewalResult.isRenewal,
90
+ isPlanChange: renewalResult.isPlanChange,
91
+ productId: renewalResult.productId,
92
+ previousProductId: renewalResult.previousProductId,
93
+ });
94
+ }
95
+
76
96
  if (renewalResult.isRenewal) {
97
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
98
+ console.log("[CustomerInfoHandler] Handling renewal");
99
+ }
77
100
  await handleRenewal(
78
101
  userId,
79
102
  renewalResult.productId!,
@@ -84,6 +107,9 @@ export async function processCustomerInfo(
84
107
  }
85
108
 
86
109
  if (renewalResult.isPlanChange) {
110
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
111
+ console.log("[CustomerInfoHandler] Handling plan change");
112
+ }
87
113
  await handlePlanChange(
88
114
  userId,
89
115
  renewalResult.productId!,
@@ -95,6 +121,9 @@ export async function processCustomerInfo(
95
121
  }
96
122
 
97
123
  if (!renewalResult.isRenewal && !renewalResult.isPlanChange) {
124
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
125
+ console.log("[CustomerInfoHandler] Handling premium status sync (new purchase or status update)");
126
+ }
98
127
  await handlePremiumStatusSync(config, userId, customerInfo);
99
128
  }
100
129
 
@@ -22,6 +22,8 @@ async function executeConsumablePurchase(
22
22
  };
23
23
  }
24
24
 
25
+ declare const __DEV__: boolean;
26
+
25
27
  async function executeSubscriptionPurchase(
26
28
  config: RevenueCatConfig,
27
29
  userId: string,
@@ -32,13 +34,30 @@ async function executeSubscriptionPurchase(
32
34
  const isPremium = !!customerInfo.entitlements.active[entitlementIdentifier];
33
35
  const source = getSavedPurchase()?.source;
34
36
 
35
- if (isPremium) {
36
- await syncPremiumStatus(config, userId, customerInfo);
37
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
38
+ console.log("[PurchaseExecutor] executeSubscriptionPurchase:", {
39
+ userId,
40
+ productId,
41
+ isPremium,
42
+ entitlementIdentifier,
43
+ activeEntitlements: Object.keys(customerInfo.entitlements.active),
44
+ source,
45
+ });
46
+ }
47
+
48
+ await syncPremiumStatus(config, userId, customerInfo);
49
+
50
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
51
+ console.log("[PurchaseExecutor] syncPremiumStatus completed");
37
52
  }
38
53
 
39
54
  await notifyPurchaseCompleted(config, userId, productId, customerInfo, source);
40
55
  clearSavedPurchase();
41
56
 
57
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
58
+ console.log("[PurchaseExecutor] Purchase flow completed successfully");
59
+ }
60
+
42
61
  return {
43
62
  success: true,
44
63
  isPremium,
@@ -8,12 +8,26 @@ import type { RevenueCatConfig } from "../../../revenuecat/core/types";
8
8
  import type { PurchaseSource } from "../../../subscription/core/SubscriptionConstants";
9
9
  import { getPremiumEntitlement } from "../../../revenuecat/core/types";
10
10
 
11
+ declare const __DEV__: boolean;
12
+
11
13
  export async function syncPremiumStatus(
12
14
  config: RevenueCatConfig,
13
15
  userId: string,
14
16
  customerInfo: CustomerInfo
15
17
  ): Promise<void> {
18
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
19
+ console.log("[PremiumStatusSyncer] syncPremiumStatus called:", {
20
+ userId,
21
+ hasCallback: !!config.onPremiumStatusChanged,
22
+ entitlementId: config.entitlementIdentifier,
23
+ activeEntitlements: Object.keys(customerInfo.entitlements.active),
24
+ });
25
+ }
26
+
16
27
  if (!config.onPremiumStatusChanged) {
28
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
29
+ console.log("[PremiumStatusSyncer] No onPremiumStatusChanged callback - skipping");
30
+ }
17
31
  return;
18
32
  }
19
33
 
@@ -22,8 +36,21 @@ export async function syncPremiumStatus(
22
36
  config.entitlementIdentifier
23
37
  );
24
38
 
39
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
40
+ console.log("[PremiumStatusSyncer] Premium entitlement:", {
41
+ found: !!premiumEntitlement,
42
+ productId: premiumEntitlement?.productIdentifier,
43
+ expirationDate: premiumEntitlement?.expirationDate,
44
+ willRenew: premiumEntitlement?.willRenew,
45
+ periodType: premiumEntitlement?.periodType,
46
+ });
47
+ }
48
+
25
49
  try {
26
50
  if (premiumEntitlement) {
51
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
52
+ console.log("[PremiumStatusSyncer] Calling onPremiumStatusChanged with premium=true");
53
+ }
27
54
  await config.onPremiumStatusChanged(
28
55
  userId,
29
56
  true,
@@ -33,8 +60,14 @@ export async function syncPremiumStatus(
33
60
  premiumEntitlement.periodType as "NORMAL" | "INTRO" | "TRIAL" | undefined
34
61
  );
35
62
  } else {
63
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
64
+ console.log("[PremiumStatusSyncer] Calling onPremiumStatusChanged with premium=false");
65
+ }
36
66
  await config.onPremiumStatusChanged(userId, false, undefined, undefined, undefined, undefined);
37
67
  }
68
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
69
+ console.log("[PremiumStatusSyncer] onPremiumStatusChanged completed successfully");
70
+ }
38
71
  } catch (error) {
39
72
  console.error('[PremiumStatusSyncer] Premium status change callback failed', {
40
73
  userId,