@umituz/react-native-subscription 2.27.111 → 2.27.112

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.27.111",
3
+ "version": "2.27.112",
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",
@@ -150,6 +150,24 @@ export async function initializeCreditsTransaction(
150
150
  creditsData.productId = metadata.productId;
151
151
  creditsData.platform = platform;
152
152
 
153
+ // Skip write if it's a status sync and data hasn't changed to save costs
154
+ if (isStatusSync && existingData) {
155
+ const hasChanged =
156
+ existingData.isPremium !== creditsData.isPremium ||
157
+ existingData.status !== creditsData.status ||
158
+ existingData.credits !== creditsData.credits ||
159
+ existingData.creditLimit !== creditsData.creditLimit ||
160
+ existingData.productId !== creditsData.productId;
161
+
162
+ if (!hasChanged) {
163
+ return {
164
+ credits: existingData.credits,
165
+ alreadyProcessed: true,
166
+ finalData: existingData
167
+ };
168
+ }
169
+ }
170
+
153
171
  transaction.set(creditsRef, creditsData, { merge: true });
154
172
 
155
173
  const finalData: UserCreditsDocumentRead = {
@@ -6,7 +6,7 @@ import { ICreditStrategy, type CreditAllocationParams } from "./ICreditStrategy"
6
6
  */
7
7
  export class SyncCreditStrategy implements ICreditStrategy {
8
8
  canHandle(params: CreditAllocationParams): boolean {
9
- return params.isStatusSync && params.existingData?.isPremium === true && params.isSubscriptionActive;
9
+ return params.isStatusSync;
10
10
  }
11
11
 
12
12
  execute(params: CreditAllocationParams): number {
@@ -69,32 +69,56 @@ export class SubscriptionSyncService {
69
69
  periodType?: PeriodType
70
70
  ) {
71
71
  try {
72
+ // Handle subscription expiration explicitly
72
73
  if (!isPremium && productId) {
73
74
  await getCreditsRepository().syncExpiredStatus(userId);
74
75
  subscriptionEventBus.emit(SUBSCRIPTION_EVENTS.CREDITS_UPDATED, userId);
75
76
  return;
76
77
  }
77
78
 
78
- // If productId is missing, we can't initialize credits fully,
79
- // but if isPremium is true, we should have it.
80
- // Fallback to 'unknown' if missing, but this might throw in CreditLimitCalculator.
81
- const validProductId = productId ?? 'unknown_product';
79
+ // If not premium and no product, this is a freemium user.
80
+ // We only want to run initializeCredits for them if it's their first time,
81
+ // which initializeCredits handles, but we should avoid doing it on every sync.
82
+ if (!isPremium && !productId) {
83
+ // Option 1: Just skip if they are already known non-premium (handled by repository check)
84
+ // For now, let's just use a more stable sync ID to allow the repository to skip if possible
85
+ const stableSyncId = `init_sync_${userId}`;
86
+
87
+ await getCreditsRepository().initializeCredits(
88
+ userId,
89
+ stableSyncId,
90
+ 'no_subscription',
91
+ PURCHASE_SOURCE.SETTINGS,
92
+ {
93
+ isPremium: false,
94
+ expirationDate: null,
95
+ willRenew: false,
96
+ periodType: null,
97
+ originalTransactionId: null
98
+ },
99
+ PURCHASE_TYPE.INITIAL
100
+ );
101
+
102
+ subscriptionEventBus.emit(SUBSCRIPTION_EVENTS.CREDITS_UPDATED, userId);
103
+ return;
104
+ }
82
105
 
106
+ // Standard status sync for premium users
83
107
  const revenueCatData: RevenueCatData = {
84
108
  expirationDate: expiresAt ?? null,
85
109
  willRenew: willRenew ?? false,
86
110
  isPremium,
87
- periodType: periodType ?? null, // Fix undefined vs null
88
- originalTransactionId: null // Initialize with null as we might not have it here
111
+ periodType: periodType ?? null,
112
+ originalTransactionId: null
89
113
  };
90
114
 
91
115
  await getCreditsRepository().initializeCredits(
92
116
  userId,
93
117
  `status_sync_${Date.now()}`,
94
- validProductId,
118
+ productId ?? 'no_subscription',
95
119
  PURCHASE_SOURCE.SETTINGS,
96
120
  revenueCatData,
97
- PURCHASE_TYPE.INITIAL // Status sync treated as Initial or Update
121
+ PURCHASE_TYPE.INITIAL
98
122
  );
99
123
 
100
124
  subscriptionEventBus.emit(SUBSCRIPTION_EVENTS.CREDITS_UPDATED, userId);
@@ -54,7 +54,7 @@ export function detectPackageType(productIdentifier: string): SubscriptionPackag
54
54
  return PACKAGE_TYPE.LIFETIME;
55
55
  }
56
56
 
57
- if (__DEV__ && productIdentifier !== 'unknown_product') {
57
+ if (__DEV__ && productIdentifier !== 'no_subscription') {
58
58
  console.warn("[PackageTypeDetector] Unknown package type for:", productIdentifier);
59
59
  }
60
60