@umituz/react-native-subscription 2.37.60 → 2.37.62

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,9 +1,15 @@
1
1
  {
2
2
  "name": "@umituz/react-native-subscription",
3
- "version": "2.37.60",
3
+ "version": "2.37.62",
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",
7
+ "sideEffects": false,
8
+ "exports": {
9
+ ".": "./src/index.ts",
10
+ "./init": "./src/init/index.ts",
11
+ "./package.json": "./package.json"
12
+ },
7
13
  "scripts": {
8
14
  "typecheck": "npx tsc --noEmit",
9
15
  "lint": "eslint . --fix",
@@ -73,5 +73,6 @@ export function buildCreditsData({
73
73
  ...(billingIssueTimestamp && { billingIssueDetectedAt: billingIssueTimestamp }),
74
74
  ...(metadata.store && { store: metadata.store }),
75
75
  ...(metadata.ownershipType && { ownershipType: metadata.ownershipType }),
76
+ ...(metadata.revenueCatUserId && { revenueCatUserId: metadata.revenueCatUserId }),
76
77
  };
77
78
  }
@@ -70,6 +70,7 @@ export async function initializeCreditsWithRetry(params: InitializeCreditsParams
70
70
  billingIssueDetectedAt: revenueCatData.billingIssueDetectedAt,
71
71
  store: revenueCatData.store,
72
72
  ownershipType: revenueCatData.ownershipType,
73
+ revenueCatUserId: revenueCatData.revenueCatUserId,
73
74
  type,
74
75
  }
75
76
  );
@@ -11,4 +11,5 @@ export interface RevenueCatData {
11
11
  billingIssueDetectedAt: string | null;
12
12
  store: Store | null;
13
13
  ownershipType: OwnershipType | null;
14
+ revenueCatUserId?: string | null;
14
15
  }
@@ -1,10 +1,12 @@
1
1
  import Purchases, { type CustomerInfo, type PurchasesOfferings } from "react-native-purchases";
2
+ import { doc, setDoc } from "firebase/firestore";
2
3
  import type { InitializeResult } from "../../../../shared/application/ports/IRevenueCatService";
3
4
  import type { InitializerDeps } from "./RevenueCatInitializer.types";
4
5
  import { FAILED_INITIALIZATION_RESULT } from "./initializerConstants";
5
6
  import { UserSwitchMutex } from "./UserSwitchMutex";
6
7
  import { getPremiumEntitlement } from "../../core/types";
7
8
  import type { PeriodType } from "../../../subscription/core/SubscriptionConstants";
9
+ import { requireFirestore } from "../../../../shared/infrastructure/firestore";
8
10
 
9
11
  const ANONYMOUS_CACHE_KEY = '__anonymous__';
10
12
 
@@ -39,6 +41,16 @@ function isAnonymousId(userId: string): boolean {
39
41
  return userId.startsWith('$RCAnonymous') || userId.startsWith('device_');
40
42
  }
41
43
 
44
+ async function syncRevenueCatIdToProfile(firebaseUserId: string, revenueCatUserId: string): Promise<void> {
45
+ try {
46
+ const db = requireFirestore();
47
+ const userRef = doc(db, "users", firebaseUserId);
48
+ await setDoc(userRef, { revenueCatUserId }, { merge: true });
49
+ } catch {
50
+ // Non-fatal: profile update failure should not block SDK initialization
51
+ }
52
+ }
53
+
42
54
  export async function handleUserSwitch(
43
55
  deps: InitializerDeps,
44
56
  userId: string
@@ -108,6 +120,11 @@ async function performUserSwitch(
108
120
  deps.setCurrentUserId(normalizedUserId || undefined);
109
121
  const offerings = await fetchOfferingsSafe();
110
122
 
123
+ if (normalizedUserId) {
124
+ const rcId = await Purchases.getAppUserID();
125
+ void syncRevenueCatIdToProfile(normalizedUserId, rcId);
126
+ }
127
+
111
128
  if (typeof __DEV__ !== 'undefined' && __DEV__) {
112
129
  console.log('[UserSwitchHandler] ✅ User switch completed successfully');
113
130
  }
@@ -170,6 +187,10 @@ export async function handleInitialConfiguration(
170
187
 
171
188
  const currentUserId = await Purchases.getAppUserID();
172
189
 
190
+ if (normalizedUserId) {
191
+ void syncRevenueCatIdToProfile(normalizedUserId, currentUserId);
192
+ }
193
+
173
194
  if (typeof __DEV__ !== 'undefined' && __DEV__) {
174
195
  console.log('[UserSwitchHandler] ✅ Initial configuration completed:', {
175
196
  revenueCatUserId: currentUserId,
@@ -41,6 +41,7 @@ export interface InitializeCreditsMetadata {
41
41
  billingIssueDetectedAt: string | null;
42
42
  store: Store | null;
43
43
  ownershipType: OwnershipType | null;
44
+ revenueCatUserId?: string | null;
44
45
  }
45
46
 
46
47
  export interface InitializationResult {
@@ -1,4 +1,5 @@
1
1
  import type { CustomerInfo } from "react-native-purchases";
2
+ import Purchases from "react-native-purchases";
2
3
  import type { PeriodType, PurchaseSource } from "../core/SubscriptionConstants";
3
4
  import { PURCHASE_SOURCE, PURCHASE_TYPE } from "../core/SubscriptionConstants";
4
5
  import { getCreditsRepository } from "../../credits/infrastructure/CreditsRepositoryManager";
@@ -14,6 +15,14 @@ export class SubscriptionSyncProcessor {
14
15
  private getAnonymousUserId: () => Promise<string>
15
16
  ) {}
16
17
 
18
+ private async getRevenueCatAppUserId(): Promise<string | null> {
19
+ try {
20
+ return await Purchases.getAppUserID();
21
+ } catch {
22
+ return null;
23
+ }
24
+ }
25
+
17
26
  private async getCreditsUserId(revenueCatUserId: string): Promise<string> {
18
27
  if (!revenueCatUserId || revenueCatUserId.trim().length === 0) {
19
28
  const anonymousId = await this.getAnonymousUserId();
@@ -28,6 +37,7 @@ export class SubscriptionSyncProcessor {
28
37
  async processPurchase(userId: string, productId: string, customerInfo: CustomerInfo, source?: PurchaseSource, packageType?: PackageType | null) {
29
38
  const revenueCatData = extractRevenueCatData(customerInfo, this.entitlementId);
30
39
  revenueCatData.packageType = packageType ?? null;
40
+ revenueCatData.revenueCatUserId = await this.getRevenueCatAppUserId();
31
41
  const purchaseId = generatePurchaseId(revenueCatData.originalTransactionId, productId);
32
42
 
33
43
  const creditsUserId = await this.getCreditsUserId(userId);
@@ -47,6 +57,7 @@ export class SubscriptionSyncProcessor {
47
57
  async processRenewal(userId: string, productId: string, newExpirationDate: string, customerInfo: CustomerInfo) {
48
58
  const revenueCatData = extractRevenueCatData(customerInfo, this.entitlementId);
49
59
  revenueCatData.expirationDate = newExpirationDate ?? revenueCatData.expirationDate;
60
+ revenueCatData.revenueCatUserId = await this.getRevenueCatAppUserId();
50
61
  const purchaseId = generateRenewalId(revenueCatData.originalTransactionId, productId, newExpirationDate);
51
62
 
52
63
  const creditsUserId = await this.getCreditsUserId(userId);