@umituz/react-native-subscription 2.12.32 → 2.12.34

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.12.32",
3
+ "version": "2.12.34",
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",
package/src/index.ts CHANGED
@@ -239,10 +239,9 @@ export {
239
239
  } from "./presentation/hooks/usePaywallVisibility";
240
240
 
241
241
  export {
242
- usePremiumWithConfig,
243
- type UsePremiumWithConfigParams,
244
- type UsePremiumWithConfigResult,
245
- } from "./presentation/hooks/usePremiumWithConfig";
242
+ usePremium,
243
+ type UsePremiumResult,
244
+ } from "./presentation/hooks/usePremium";
246
245
 
247
246
  export {
248
247
  useAuthSubscriptionSync,
@@ -1,81 +1,88 @@
1
1
  /**
2
- * usePremiumWithConfig Hook
3
- * Premium status from TanStack Query (credits)
4
- * Subscription state from TanStack Query
5
- * Generic implementation for 100+ apps with auth provider abstraction
6
- *
7
- * Note: Credit allocation is handled by CustomerInfo Listener (onCreditRenewal)
8
- * configured in SubscriptionManager. Manual credit initialization removed to
9
- * prevent duplicate allocation.
2
+ * usePremium Hook
3
+ * Complete subscription management for 100+ apps
4
+ * Works for both authenticated and anonymous users
10
5
  */
11
6
 
12
- import { useCallback } from "react";
13
- import type { PurchasesPackage } from "react-native-purchases";
14
- import type { UserCredits } from "../../domain/entities/Credits";
15
- import { useCredits } from "./useCredits";
7
+ import { useCallback } from 'react';
8
+ import type { PurchasesPackage } from 'react-native-purchases';
9
+ import type { UserCredits } from '../../domain/entities/Credits';
10
+ import { useCredits } from './useCredits';
16
11
  import {
17
12
  useSubscriptionPackages,
18
13
  usePurchasePackage,
19
14
  useRestorePurchase,
20
- } from "../../revenuecat/presentation/hooks/useSubscriptionQueries";
21
- import { usePaywallVisibility } from "./usePaywallVisibility";
22
-
23
- export interface UsePremiumWithConfigParams {
24
- /** Function to get current user ID (can be from Firebase, Supabase, etc.) */
25
- getUserId: () => string | null | undefined;
26
- /** Enable/disable credits query */
27
- enabled?: boolean;
28
- }
15
+ } from '../../revenuecat/presentation/hooks/useSubscriptionQueries';
16
+ import { usePaywallVisibility } from './usePaywallVisibility';
29
17
 
30
- export interface UsePremiumWithConfigResult {
18
+ export interface UsePremiumResult {
19
+ /** User has active premium subscription */
31
20
  isPremium: boolean;
21
+ /** Loading credits or packages */
32
22
  isLoading: boolean;
23
+ /** Available subscription packages */
33
24
  packages: PurchasesPackage[];
25
+ /** User's credits (null if not premium) */
34
26
  credits: UserCredits | null;
27
+ /** Paywall visibility state */
35
28
  showPaywall: boolean;
29
+ /** Purchase a subscription package */
36
30
  purchasePackage: (pkg: PurchasesPackage) => Promise<boolean>;
31
+ /** Restore previous purchases */
37
32
  restorePurchase: () => Promise<boolean>;
33
+ /** Set paywall visibility */
38
34
  setShowPaywall: (show: boolean) => void;
35
+ /** Close paywall */
39
36
  closePaywall: () => void;
37
+ /** Open paywall */
40
38
  openPaywall: () => void;
41
39
  }
42
40
 
43
- export const usePremiumWithConfig = (
44
- params: UsePremiumWithConfigParams,
45
- ): UsePremiumWithConfigResult => {
46
- const { getUserId, enabled = true } = params;
47
- const userId = getUserId() ?? undefined;
48
-
41
+ /**
42
+ * Complete premium subscription management
43
+ *
44
+ * @param userId - User ID (undefined for anonymous users)
45
+ * @returns Premium status, packages, and subscription actions
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const { isPremium, packages, purchasePackage } = usePremium(userId);
50
+ * ```
51
+ */
52
+ export const usePremium = (userId?: string): UsePremiumResult => {
53
+ // Fetch user credits (server state)
49
54
  const { credits, isLoading: creditsLoading } = useCredits({
50
55
  userId,
51
- enabled: enabled && !!userId,
56
+ enabled: !!userId,
52
57
  });
53
58
 
59
+ // Fetch subscription packages (works for anonymous too)
54
60
  const { data: packages = [], isLoading: packagesLoading } =
55
61
  useSubscriptionPackages(userId);
62
+
63
+ // Purchase and restore mutations
56
64
  const purchaseMutation = usePurchasePackage(userId);
57
65
  const restoreMutation = useRestorePurchase(userId);
58
66
 
67
+ // Paywall visibility state
59
68
  const { showPaywall, setShowPaywall, closePaywall, openPaywall } =
60
69
  usePaywallVisibility();
61
70
 
62
- // User is premium if they have credits
63
- // NOTE: This assumes credits system = premium subscription
64
- // If your app uses CustomerInfo for premium status, use useCustomerInfo() instead
71
+ // Premium status = has credits
65
72
  const isPremium = credits !== null;
66
73
 
74
+ // Purchase handler
67
75
  const handlePurchase = useCallback(
68
76
  async (pkg: PurchasesPackage): Promise<boolean> => {
69
77
  const success = await purchaseMutation.mutateAsync(pkg);
70
- // Credit allocation handled by CustomerInfo Listener (onCreditRenewal)
71
78
  return success;
72
79
  },
73
80
  [purchaseMutation],
74
81
  );
75
82
 
83
+ // Restore handler
76
84
  const handleRestore = useCallback(async (): Promise<boolean> => {
77
85
  const success = await restoreMutation.mutateAsync();
78
- // Credit allocation handled by CustomerInfo Listener (onCreditRenewal)
79
86
  return success;
80
87
  }, [restoreMutation]);
81
88