@umituz/react-native-subscription 2.14.2 → 2.14.4

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.2",
3
+ "version": "2.14.4",
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",
@@ -98,7 +98,7 @@ export const PaywallModal: React.FC<PaywallModalProps> = React.memo((props) => {
98
98
  if (supported) {
99
99
  await Linking.openURL(url);
100
100
  }
101
- } catch (error) {
101
+ } catch {
102
102
  // Silent fail
103
103
  }
104
104
  }, []);
@@ -23,7 +23,7 @@ export const useSubscriptionModal = ({
23
23
  } finally {
24
24
  setIsProcessing(false);
25
25
  }
26
- }, [selectedPkg, onPurchase, onClose]);
26
+ }, [selectedPkg, onPurchase, onClose, isProcessing]);
27
27
 
28
28
  const handleRestore = useCallback(async () => {
29
29
  if (isProcessing) return;
@@ -33,7 +33,7 @@ export const useSubscriptionModal = ({
33
33
  } finally {
34
34
  setIsProcessing(false);
35
35
  }
36
- }, [onRestore, onClose]);
36
+ }, [onRestore, onClose, isProcessing]);
37
37
 
38
38
  return {
39
39
  selectedPkg,
package/src/index.ts CHANGED
@@ -28,6 +28,11 @@ export {
28
28
  initializeSubscriptionService,
29
29
  } from "./infrastructure/services/SubscriptionService";
30
30
 
31
+ export {
32
+ initializeSubscription,
33
+ type SubscriptionInitConfig,
34
+ } from "./infrastructure/services/SubscriptionInitializer";
35
+
31
36
  export { useSubscription } from "./presentation/hooks/useSubscription";
32
37
  export type { UseSubscriptionResult } from "./presentation/hooks/useSubscription";
33
38
 
@@ -75,6 +80,9 @@ export {
75
80
  CreditCard,
76
81
  usePaywall,
77
82
  useSubscriptionModal,
83
+ usePaywallTranslations,
84
+ type UsePaywallTranslationsParams,
85
+ type UsePaywallTranslationsResult,
78
86
  type PaywallMode,
79
87
  type PaywallTabType,
80
88
  type CreditsPackage,
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Subscription Initializer
3
+ * Single entry point for subscription system initialization
4
+ * Apps just call initializeSubscription with config
5
+ */
6
+
7
+ import type { CreditsConfig } from "../../domain/entities/Credits";
8
+ import { configureCreditsRepository } from "../repositories/CreditsRepositoryProvider";
9
+ import { SubscriptionManager } from "../../revenuecat/infrastructure/managers/SubscriptionManager";
10
+ import { configureAuthProvider } from "../../presentation/hooks/useAuthAwarePurchase";
11
+
12
+ export interface SubscriptionInitConfig {
13
+ apiKey: string;
14
+ entitlementId: string;
15
+ credits: CreditsConfig;
16
+ getAnonymousUserId: () => Promise<string>;
17
+ getFirebaseAuth: () => { currentUser: { isAnonymous: boolean } | null } | null;
18
+ showAuthModal: () => void;
19
+ onCreditsUpdated?: (userId: string) => void;
20
+ onCreditRenewal?: (userId: string, productId: string, renewalId: string) => Promise<void>;
21
+ timeoutMs?: number;
22
+ }
23
+
24
+ export const initializeSubscription = async (
25
+ config: SubscriptionInitConfig,
26
+ ): Promise<void> => {
27
+ const {
28
+ apiKey,
29
+ entitlementId,
30
+ credits,
31
+ getAnonymousUserId,
32
+ getFirebaseAuth,
33
+ showAuthModal,
34
+ onCreditsUpdated,
35
+ onCreditRenewal,
36
+ timeoutMs = 10000,
37
+ } = config;
38
+
39
+ if (!apiKey) {
40
+ throw new Error("RevenueCat API key is required");
41
+ }
42
+
43
+ configureCreditsRepository(credits);
44
+
45
+ SubscriptionManager.configure({
46
+ config: {
47
+ apiKey,
48
+ entitlementIdentifier: entitlementId,
49
+ onCreditRenewal,
50
+ onCreditsUpdated,
51
+ },
52
+ apiKey,
53
+ getAnonymousUserId,
54
+ });
55
+
56
+ const initPromise = SubscriptionManager.initialize();
57
+ const timeoutPromise = new Promise<boolean>((_, reject) =>
58
+ setTimeout(
59
+ () => reject(new Error("Subscription initialization timeout")),
60
+ timeoutMs,
61
+ ),
62
+ );
63
+
64
+ await Promise.race([initPromise, timeoutPromise]);
65
+
66
+ configureAuthProvider({
67
+ isAuthenticated: () => {
68
+ const auth = getFirebaseAuth();
69
+ const user = auth?.currentUser;
70
+ return !!(user && !user.isAnonymous);
71
+ },
72
+ showAuthModal,
73
+ });
74
+
75
+ if (__DEV__) {
76
+
77
+ console.log("[Subscription] Initialized successfully");
78
+ }
79
+ };
@@ -34,7 +34,7 @@ export const useCreditChecker = ({
34
34
 
35
35
  const checker = useMemo(
36
36
  () => createCreditChecker({ repository, getCreditType }),
37
- [getCreditType]
37
+ [getCreditType, repository]
38
38
  );
39
39
 
40
40
  return checker;
@@ -83,7 +83,7 @@ export async function initializeSDK(
83
83
  const hasPremium = !!customerInfo.entitlements.active[entitlementId];
84
84
 
85
85
  return { success: true, offering: offerings.current, hasPremium };
86
- } catch (error) {
86
+ } catch {
87
87
  // If logIn fails, we don't necessarily want to re-configure if it's already configured
88
88
  // But we can return failure
89
89
  return { success: false, offering: null, hasPremium: false };
@@ -11,7 +11,6 @@ import {
11
11
  validateIsGuest,
12
12
  validateIsPremium,
13
13
  validateFetcher,
14
- type UserTier,
15
14
  type UserTierInfo,
16
15
  type PremiumStatusFetcher,
17
16
  } from '../validation';