@umituz/react-native-subscription 2.37.106 → 2.37.108

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.
Files changed (24) hide show
  1. package/package.json +1 -1
  2. package/src/domains/paywall/hooks/usePaywallActions.ts +1 -1
  3. package/src/domains/revenuecat/infrastructure/services/RevenueCatInitializer.ts +1 -2
  4. package/src/domains/revenuecat/infrastructure/services/userSwitchHandler.ts +1 -24
  5. package/src/domains/subscription/application/SubscriptionSyncUtils.ts +4 -0
  6. package/src/domains/subscription/infrastructure/managers/SubscriptionManager.ts +8 -8
  7. package/src/domains/subscription/infrastructure/managers/SubscriptionManager.types.ts +2 -6
  8. package/src/domains/subscription/infrastructure/managers/premiumStatusChecker.ts +1 -2
  9. package/src/domains/subscription/infrastructure/managers/subscriptionManagerUtils.ts +4 -5
  10. package/src/domains/subscription/infrastructure/services/RevenueCatService.types.ts +1 -2
  11. package/src/domains/subscription/presentation/screens/SubscriptionDetailScreen.tsx +4 -4
  12. package/src/domains/subscription/presentation/screens/components/SubscriptionHeader.tsx +2 -1
  13. package/src/domains/subscription/utils/expirationHelpers.ts +1 -1
  14. package/src/domains/wallet/presentation/hooks/useTransactionHistory.ts +1 -1
  15. package/src/index.ts +7 -5
  16. package/src/domains/credits/presentation/deduct-credit/index.ts +0 -1
  17. package/src/domains/revenuecat/infrastructure/utils/ApiKeyResolver.ts +0 -5
  18. package/src/domains/subscription/constants/thresholds.ts +0 -1
  19. package/src/domains/subscription/infrastructure/managers/SubscriptionInternalState.ts +0 -9
  20. package/src/domains/subscription/infrastructure/managers/managerConstants.ts +0 -3
  21. package/src/domains/subscription/presentation/stores/index.ts +0 -4
  22. package/src/domains/wallet/index.ts +0 -8
  23. package/src/domains/wallet/infrastructure/repositories/transaction/index.ts +0 -1
  24. package/src/init/index.ts +0 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-subscription",
3
- "version": "2.37.106",
3
+ "version": "2.37.108",
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",
@@ -1,6 +1,6 @@
1
1
  import { useState, useCallback, useRef } from "react";
2
2
  import type { PurchasesPackage } from "react-native-purchases";
3
- import { usePurchaseLoadingStore } from "../../subscription/presentation/stores";
3
+ import { usePurchaseLoadingStore } from "../../subscription/presentation/stores/purchaseLoadingStore";
4
4
  import type { PurchaseSource } from "../../subscription/core/SubscriptionConstants";
5
5
 
6
6
  interface UsePaywallActionsParams {
@@ -1,5 +1,4 @@
1
1
  import type { InitializeResult } from "../../../../shared/application/ports/IRevenueCatService";
2
- import { resolveApiKey } from "../utils/ApiKeyResolver";
3
2
  import type { InitializerDeps } from "./RevenueCatInitializer.types";
4
3
  import { FAILED_INITIALIZATION_RESULT, CONFIGURATION_RETRY_DELAY_MS, MAX_INIT_RETRIES } from "./initializerConstants";
5
4
  import { configState } from "./ConfigurationStateManager";
@@ -40,7 +39,7 @@ export async function initializeSDK(
40
39
  return initializeSDK(deps, userId, apiKey, configStartRetryCount);
41
40
  }
42
41
 
43
- const key = apiKey || resolveApiKey(deps.config);
42
+ const key = apiKey || deps.config.apiKey || null;
44
43
  if (!key) {
45
44
  return FAILED_INITIALIZATION_RESULT;
46
45
  }
@@ -1,12 +1,10 @@
1
1
  import Purchases, { type CustomerInfo, type PurchasesOfferings } from "react-native-purchases";
2
- import { doc, setDoc } from "firebase/firestore";
3
2
  import type { InitializeResult } from "../../../../shared/application/ports/IRevenueCatService";
4
3
  import type { InitializerDeps } from "./RevenueCatInitializer.types";
5
4
  import { FAILED_INITIALIZATION_RESULT } from "./initializerConstants";
6
5
  import { UserSwitchMutex } from "./UserSwitchMutex";
7
6
  import { getPremiumEntitlement } from "../../core/types";
8
7
  import { ANONYMOUS_CACHE_KEY, type PeriodType } from "../../../subscription/core/SubscriptionConstants";
9
- import { requireFirestore } from "../../../../shared/infrastructure/firestore";
10
8
 
11
9
  declare const __DEV__: boolean;
12
10
 
@@ -39,17 +37,6 @@ function isAnonymousId(userId: string): boolean {
39
37
  return userId.startsWith('$RCAnonymous') || userId.startsWith('device_');
40
38
  }
41
39
 
42
- async function syncRevenueCatIdToProfile(firebaseUserId: string, revenueCatUserId: string): Promise<void> {
43
- try {
44
- const db = requireFirestore();
45
- const userRef = doc(db, "users", firebaseUserId);
46
- await setDoc(userRef, { revenueCatUserId }, { merge: true });
47
- } catch (error) {
48
- // Non-fatal: profile update failure should not block SDK initialization
49
- console.warn('[UserSwitchHandler] Failed to sync RevenueCat ID to profile:', error instanceof Error ? error.message : String(error));
50
- }
51
- }
52
-
53
40
  export async function handleUserSwitch(
54
41
  deps: InitializerDeps,
55
42
  userId: string
@@ -119,11 +106,6 @@ async function performUserSwitch(
119
106
  deps.setCurrentUserId(normalizedUserId || undefined);
120
107
  const offerings = await fetchOfferingsSafe();
121
108
 
122
- if (normalizedUserId) {
123
- const rcId = await Purchases.getAppUserID();
124
- void syncRevenueCatIdToProfile(normalizedUserId, rcId);
125
- }
126
-
127
109
  if (typeof __DEV__ !== 'undefined' && __DEV__) {
128
110
  console.log('[UserSwitchHandler] User switch completed successfully');
129
111
  }
@@ -184,13 +166,8 @@ export async function handleInitialConfiguration(
184
166
  fetchOfferingsSafe(),
185
167
  ]);
186
168
 
187
- const currentUserId = await Purchases.getAppUserID();
188
-
189
- if (normalizedUserId) {
190
- void syncRevenueCatIdToProfile(normalizedUserId, currentUserId);
191
- }
192
-
193
169
  if (typeof __DEV__ !== 'undefined' && __DEV__) {
170
+ const currentUserId = await Purchases.getAppUserID();
194
171
  console.log('[UserSwitchHandler] Initial configuration completed:', {
195
172
  revenueCatUserId: currentUserId,
196
173
  activeEntitlements: Object.keys(customerInfo.entitlements.active),
@@ -39,6 +39,10 @@ export const extractRevenueCatData = (customerInfo: CustomerInfo, entitlementId:
39
39
  return {
40
40
  expirationDate: entitlement.expirationDate ?? null,
41
41
  willRenew: entitlement.willRenew ?? null,
42
+ // Maps SDK's `storeTransactionId` (current transaction ID from Apple/Google)
43
+ // to our domain's `originalTransactionId`. Used as dedup key in processedTransactions.
44
+ // Note: The SDK does not expose `original_store_transaction_id` (the first purchase's
45
+ // ID that stays constant across renewals) — only available via server-side webhooks.
42
46
  originalTransactionId: subscription?.storeTransactionId ?? null,
43
47
  periodType: validatePeriodType(entitlement.periodType),
44
48
  packageType: null,
@@ -1,7 +1,7 @@
1
1
  import type { PurchasesPackage } from "react-native-purchases";
2
2
  import type { IRevenueCatService } from "../../../../shared/application/ports/IRevenueCatService";
3
3
  import type { PackageHandler } from "../handlers/PackageHandler";
4
- import { SubscriptionInternalState } from "./SubscriptionInternalState";
4
+ import { InitializationCache } from "../utils/InitializationCache";
5
5
  import { ensureServiceAvailable, getCurrentUserIdOrThrow } from "./subscriptionManagerUtils";
6
6
  import type { SubscriptionManagerConfig, PremiumStatus, RestoreResultInfo } from "./SubscriptionManager.types";
7
7
  import { createPackageHandler } from "./packageHandlerFactory";
@@ -14,7 +14,7 @@ import { ANONYMOUS_CACHE_KEY } from "../../core/SubscriptionConstants";
14
14
  class SubscriptionManagerImpl {
15
15
  private managerConfig: SubscriptionManagerConfig | null = null;
16
16
  private serviceInstance: IRevenueCatService | null = null;
17
- private state = new SubscriptionInternalState();
17
+ private initCache = new InitializationCache();
18
18
  private packageHandler: PackageHandler | null = null;
19
19
 
20
20
  configure(config: SubscriptionManagerConfig): void {
@@ -45,7 +45,7 @@ class SubscriptionManagerImpl {
45
45
  }
46
46
 
47
47
  const cacheKey = actualUserId || ANONYMOUS_CACHE_KEY;
48
- const { shouldInit, existingPromise } = this.state.initCache.tryAcquireInitialization(cacheKey);
48
+ const { shouldInit, existingPromise } = this.initCache.tryAcquireInitialization(cacheKey);
49
49
 
50
50
  if (!shouldInit && existingPromise) {
51
51
  if (typeof __DEV__ !== 'undefined' && __DEV__) {
@@ -59,7 +59,7 @@ class SubscriptionManagerImpl {
59
59
 
60
60
  const realUserId = actualUserId || null;
61
61
  const promise = this.performInitialization(actualUserId);
62
- this.state.initCache.setPromise(promise, cacheKey, realUserId);
62
+ this.initCache.setPromise(promise, cacheKey, realUserId);
63
63
  return promise;
64
64
  }
65
65
 
@@ -87,7 +87,7 @@ class SubscriptionManagerImpl {
87
87
  }
88
88
 
89
89
  isInitializedForUser = (userId: string): boolean =>
90
- !!(this.serviceInstance?.isInitialized() && this.state.initCache.getCurrentUserId() === userId);
90
+ !!(this.serviceInstance?.isInitialized() && this.initCache.getCurrentUserId() === userId);
91
91
 
92
92
  async getPackages(): Promise<PurchasesPackage[]> {
93
93
  this.ensureConfigured();
@@ -109,7 +109,7 @@ class SubscriptionManagerImpl {
109
109
  });
110
110
  }
111
111
  this.ensurePackageHandlerInitialized();
112
- const resolvedUserId = explicitUserId || getCurrentUserIdOrThrow(this.state);
112
+ const resolvedUserId = explicitUserId || getCurrentUserIdOrThrow(this.initCache);
113
113
  const result = await purchasePackageOperation(pkg, this.managerConfig, resolvedUserId, this.packageHandler!);
114
114
  return result;
115
115
  }
@@ -120,7 +120,7 @@ class SubscriptionManagerImpl {
120
120
  await this.initialize(explicitUserId);
121
121
  }
122
122
  this.ensurePackageHandlerInitialized();
123
- const resolvedUserId = explicitUserId || getCurrentUserIdOrThrow(this.state);
123
+ const resolvedUserId = explicitUserId || getCurrentUserIdOrThrow(this.initCache);
124
124
  return restoreOperation(this.managerConfig, resolvedUserId, this.packageHandler!);
125
125
  }
126
126
 
@@ -133,7 +133,7 @@ class SubscriptionManagerImpl {
133
133
 
134
134
  async reset(): Promise<void> {
135
135
  await this.serviceInstance?.reset();
136
- this.state.reset();
136
+ this.initCache.reset();
137
137
  this.serviceInstance = null;
138
138
  this.packageHandler = null;
139
139
  initializationState.reset();
@@ -1,14 +1,10 @@
1
1
  import type { RevenueCatConfig } from "../../../revenuecat/core/types";
2
2
  import type { PremiumStatus } from "../handlers/PurchaseStatusResolver";
3
+ import type { RestoreResultInfo } from "../handlers/package-operations/types";
3
4
 
4
5
  export interface SubscriptionManagerConfig {
5
6
  config: RevenueCatConfig;
6
7
  apiKey: string;
7
8
  }
8
9
 
9
- export type { PremiumStatus };
10
-
11
- export interface RestoreResultInfo {
12
- success: boolean;
13
- productId: string | null;
14
- }
10
+ export type { PremiumStatus, RestoreResultInfo };
@@ -1,7 +1,6 @@
1
1
  import type { IRevenueCatService } from "../../../../shared/application/ports/IRevenueCatService";
2
2
  import type { PackageHandler } from "../handlers/PackageHandler";
3
3
  import type { PremiumStatus } from "./SubscriptionManager.types";
4
- import { ERROR_MESSAGES } from "./managerConstants";
5
4
 
6
5
  export const checkPremiumStatusFromService = async (
7
6
  service: IRevenueCatService,
@@ -10,7 +9,7 @@ export const checkPremiumStatusFromService = async (
10
9
  const customerInfo = await service.getCustomerInfo();
11
10
 
12
11
  if (!customerInfo) {
13
- throw new Error(ERROR_MESSAGES.CUSTOMER_INFO_NOT_AVAILABLE);
12
+ throw new Error("Customer info not available");
14
13
  }
15
14
 
16
15
  return packageHandler.checkPremiumStatusFromInfo(customerInfo);
@@ -1,7 +1,7 @@
1
1
  import type { SubscriptionManagerConfig } from "./SubscriptionManager.types";
2
-
3
2
  import type { IRevenueCatService } from "../../../../shared/application/ports/IRevenueCatService";
4
- import { SubscriptionInternalState } from "./SubscriptionInternalState";
3
+ import { getRevenueCatService } from "../services/revenueCatServiceInstance";
4
+ import type { InitializationCache } from "../utils/InitializationCache";
5
5
 
6
6
  export function ensureConfigured(config: SubscriptionManagerConfig | null): void {
7
7
  if (!config) {
@@ -9,8 +9,8 @@ export function ensureConfigured(config: SubscriptionManagerConfig | null): void
9
9
  }
10
10
  }
11
11
 
12
- export function getCurrentUserIdOrThrow(state: SubscriptionInternalState): string {
13
- const userId = state.initCache.getCurrentUserId();
12
+ export function getCurrentUserIdOrThrow(initCache: InitializationCache): string {
13
+ const userId = initCache.getCurrentUserId();
14
14
  if (userId == null) {
15
15
  throw new Error("SubscriptionManager not initialized - no current user ID available");
16
16
  }
@@ -24,7 +24,6 @@ export function getOrCreateService(
24
24
  return currentInstance;
25
25
  }
26
26
 
27
- const { getRevenueCatService } = require("../services/revenueCatServiceInstance");
28
27
  const serviceInstance = getRevenueCatService();
29
28
 
30
29
  if (!serviceInstance) {
@@ -2,7 +2,6 @@ import Purchases from "react-native-purchases";
2
2
  import type { PurchasesOffering, PurchasesPackage, CustomerInfo } from "react-native-purchases";
3
3
  import type { IRevenueCatService, InitializeResult, PurchaseResult, RestoreResult } from "../../../../shared/application/ports/IRevenueCatService";
4
4
  import type { RevenueCatConfig } from "../../../revenuecat/core/types";
5
- import { resolveApiKey } from "../../../revenuecat/infrastructure/utils/ApiKeyResolver";
6
5
  import { initializeSDK } from "../../../revenuecat/infrastructure/services/RevenueCatInitializer";
7
6
  import { fetchOfferings } from "./OfferingsFetcher";
8
7
  import { handlePurchase } from "./PurchaseHandler";
@@ -19,7 +18,7 @@ export class RevenueCatService implements IRevenueCatService {
19
18
  this.listenerManager = new CustomerInfoListenerManager();
20
19
  }
21
20
 
22
- getRevenueCatKey = (): string | null => resolveApiKey(this.stateManager.getConfig());
21
+ getRevenueCatKey = (): string | null => this.stateManager.getConfig().apiKey || null;
23
22
 
24
23
  isInitialized = (): boolean => this.stateManager.isInitialized();
25
24
 
@@ -1,9 +1,13 @@
1
1
  import React, { useMemo, useState, useCallback } from "react";
2
2
  import { StyleSheet, View, Pressable, Alert } from "react-native";
3
+ import Purchases from "react-native-purchases";
3
4
  import { AtomicIcon, AtomicText } from "@umituz/react-native-design-system/atoms";
4
5
  import { NavigationHeader } from "@umituz/react-native-design-system/molecules";
5
6
  import { useAppDesignTokens } from "@umituz/react-native-design-system/theme";
7
+ import { useAuthStore, selectUserId } from "@umituz/react-native-auth";
6
8
  import { ScreenLayout } from "../../../../shared/presentation";
9
+ import { getCreditsRepository } from "../../../credits/infrastructure/CreditsRepositoryManager";
10
+ import { subscriptionEventBus, SUBSCRIPTION_EVENTS } from "../../../../shared/infrastructure/SubscriptionEventBus";
7
11
  import { SubscriptionHeader } from "./components/SubscriptionHeader";
8
12
  import { CreditsList } from "./components/CreditsList";
9
13
  import { UpgradePrompt } from "./components/UpgradePrompt";
@@ -109,9 +113,6 @@ const DevTestPanel: React.FC<{ statusType: string }> = ({ statusType }) => {
109
113
  }, [loading]);
110
114
 
111
115
  const handleCancel = useCallback(() => run("Cancel", async () => {
112
- const { useAuthStore, selectUserId } = require("@umituz/react-native-auth");
113
- const { getCreditsRepository } = require("../../../credits/infrastructure/CreditsRepositoryManager");
114
- const { subscriptionEventBus, SUBSCRIPTION_EVENTS } = require("../../../../shared/infrastructure/SubscriptionEventBus");
115
116
  const userId = selectUserId(useAuthStore.getState());
116
117
  if (!userId) throw new Error("No userId found");
117
118
  await getCreditsRepository().syncExpiredStatus(userId);
@@ -119,7 +120,6 @@ const DevTestPanel: React.FC<{ statusType: string }> = ({ statusType }) => {
119
120
  }), [run]);
120
121
 
121
122
  const handleRestore = useCallback(() => run("Restore", async () => {
122
- const Purchases = require("react-native-purchases").default;
123
123
  await Purchases.restorePurchases();
124
124
  }), [run]);
125
125
 
@@ -5,9 +5,10 @@ import { useAppDesignTokens } from "@umituz/react-native-design-system/theme";
5
5
  import { PremiumStatusBadge } from "../../components/details/PremiumStatusBadge";
6
6
  import type { SubscriptionHeaderProps } from "./SubscriptionHeader.types";
7
7
  import { createSubscriptionHeaderStyles } from "./SubscriptionHeader.styles";
8
- import { EXPIRATION_WARNING_THRESHOLD_DAYS as EXPIRING_SOON_THRESHOLD_DAYS } from "../../../constants/thresholds";
9
8
  import { SubscriptionHeaderContent } from "./SubscriptionHeaderContent";
10
9
 
10
+ const EXPIRING_SOON_THRESHOLD_DAYS = 7;
11
+
11
12
  export const SubscriptionHeader: React.FC<SubscriptionHeaderProps> = ({
12
13
  statusType,
13
14
  showExpirationDate,
@@ -1,4 +1,4 @@
1
- import { EXPIRATION_WARNING_THRESHOLD_DAYS } from '../constants/thresholds';
1
+ const EXPIRATION_WARNING_THRESHOLD_DAYS = 7;
2
2
 
3
3
  export function shouldHighlightExpiration(daysRemaining: number | null | undefined): boolean {
4
4
  return daysRemaining !== null && daysRemaining !== undefined && daysRemaining > 0 && daysRemaining <= EXPIRATION_WARNING_THRESHOLD_DAYS;
@@ -6,7 +6,7 @@ import type {
6
6
  CreditLog,
7
7
  TransactionRepositoryConfig,
8
8
  } from "../../domain/types/transaction.types";
9
- import { TransactionRepository } from "../../infrastructure/repositories/transaction";
9
+ import { TransactionRepository } from "../../infrastructure/repositories/transaction/TransactionRepository";
10
10
 
11
11
  const transactionQueryKeys = {
12
12
  all: ["transactions"] as const,
package/src/index.ts CHANGED
@@ -37,7 +37,7 @@ export {
37
37
  // Presentation Layer - Hooks
38
38
  export { useAuthAwarePurchase } from "./domains/subscription/presentation/useAuthAwarePurchase";
39
39
  export { useCredits } from "./domains/credits/presentation/useCredits";
40
- export { useDeductCredit } from "./domains/credits/presentation/deduct-credit";
40
+ export { useDeductCredit } from "./domains/credits/presentation/deduct-credit/useDeductCredit";
41
41
  export { useFeatureGate } from "./domains/subscription/presentation/useFeatureGate";
42
42
  export { usePaywallVisibility, paywallControl } from "./domains/subscription/presentation/usePaywallVisibility";
43
43
  export { usePremium } from "./domains/subscription/presentation/usePremium";
@@ -94,11 +94,13 @@ export {
94
94
  createSubscriptionInitModule,
95
95
  cleanupSubscriptionModule,
96
96
  type SubscriptionInitModuleConfig,
97
- } from './init';
97
+ } from './init/createSubscriptionInitModule';
98
98
 
99
99
  // Wallet Domain
100
100
  export {
101
101
  WalletScreen as WalletScreenContainer,
102
- type WalletScreenProps,
103
- type WalletScreenTranslations,
104
- } from './domains/wallet';
102
+ } from './domains/wallet/presentation/screens/WalletScreen';
103
+ export type {
104
+ WalletScreenProps,
105
+ WalletScreenTranslations,
106
+ } from './domains/wallet/presentation/screens/WalletScreen.types';
@@ -1 +0,0 @@
1
- export { useDeductCredit } from "./useDeductCredit";
@@ -1,5 +0,0 @@
1
- import type { RevenueCatConfig } from '../../core/types';
2
-
3
- export function resolveApiKey(config: RevenueCatConfig): string | null {
4
- return config.apiKey || null;
5
- }
@@ -1 +0,0 @@
1
- export const EXPIRATION_WARNING_THRESHOLD_DAYS = 7;
@@ -1,9 +0,0 @@
1
- import { InitializationCache } from "../utils/InitializationCache";
2
-
3
- export class SubscriptionInternalState {
4
- public initCache = new InitializationCache();
5
-
6
- reset() {
7
- this.initCache.reset();
8
- }
9
- }
@@ -1,3 +0,0 @@
1
- export const ERROR_MESSAGES = {
2
- CUSTOMER_INFO_NOT_AVAILABLE: "Customer info not available",
3
- } as const;
@@ -1,4 +0,0 @@
1
- export {
2
- usePurchaseLoadingStore,
3
- selectIsPurchasing,
4
- } from "./purchaseLoadingStore";
@@ -1,8 +0,0 @@
1
- export {
2
- WalletScreen,
3
- } from "./presentation/screens/WalletScreen";
4
-
5
- export type {
6
- WalletScreenProps,
7
- WalletScreenTranslations,
8
- } from "./presentation/screens/WalletScreen.types";
@@ -1 +0,0 @@
1
- export { TransactionRepository } from "./TransactionRepository";
package/src/init/index.ts DELETED
@@ -1,5 +0,0 @@
1
- export {
2
- createSubscriptionInitModule,
3
- cleanupSubscriptionModule,
4
- type SubscriptionInitModuleConfig,
5
- } from './createSubscriptionInitModule';