@umituz/react-native-subscription 2.14.33 → 2.14.35

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.33",
3
+ "version": "2.14.35",
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
@@ -274,6 +274,7 @@ export {
274
274
  getCreditsRepository,
275
275
  getCreditsConfig,
276
276
  resetCreditsRepository,
277
+ isCreditsRepositoryConfigured,
277
278
  } from "./infrastructure/repositories/CreditsRepositoryProvider";
278
279
 
279
280
  // =============================================================================
@@ -24,6 +24,13 @@ export function configureCreditsRepository(config: Partial<CreditsConfig>): void
24
24
  globalRepository = createCreditsRepository(globalConfig);
25
25
  }
26
26
 
27
+ /**
28
+ * Check if credits repository is configured
29
+ */
30
+ export function isCreditsRepositoryConfigured(): boolean {
31
+ return globalRepository !== null;
32
+ }
33
+
27
34
  /**
28
35
  * Get the configured credits repository
29
36
  * Throws if repository not configured
@@ -12,6 +12,7 @@ declare const __DEV__: boolean;
12
12
  import {
13
13
  getCreditsRepository,
14
14
  getCreditsConfig,
15
+ isCreditsRepositoryConfigured,
15
16
  } from "../../infrastructure/repositories/CreditsRepositoryProvider";
16
17
 
17
18
  const CACHE_CONFIG = {
@@ -46,20 +47,21 @@ export const useCredits = ({
46
47
  userId,
47
48
  enabled = true,
48
49
  }: UseCreditsParams): UseCreditsResult => {
49
- const repository = getCreditsRepository();
50
+ const isConfigured = isCreditsRepositoryConfigured();
50
51
  const config = getCreditsConfig();
51
52
 
52
53
  const { data, isLoading, error, refetch } = useQuery({
53
54
  queryKey: creditsQueryKeys.user(userId ?? ""),
54
55
  queryFn: async () => {
55
- if (!userId) return null;
56
+ if (!userId || !isConfigured) return null;
57
+ const repository = getCreditsRepository();
56
58
  const result = await repository.getCredits(userId);
57
59
  if (!result.success) {
58
60
  throw new Error(result.error?.message || "Failed to fetch credits");
59
61
  }
60
62
  return result.data || null;
61
63
  },
62
- enabled: enabled && !!userId,
64
+ enabled: enabled && !!userId && isConfigured,
63
65
  staleTime: CACHE_CONFIG.staleTime,
64
66
  gcTime: CACHE_CONFIG.gcTime,
65
67
  });
@@ -98,6 +98,10 @@ class SubscriptionManagerImpl {
98
98
  return promise;
99
99
  }
100
100
 
101
+ isConfigured(): boolean {
102
+ return this.managerConfig !== null && this.packageHandler !== null;
103
+ }
104
+
101
105
  isInitialized(): boolean {
102
106
  return this.serviceInstance?.isInitialized() ?? false;
103
107
  }
@@ -17,8 +17,13 @@ import {
17
17
  * Works for both authenticated and anonymous users
18
18
  */
19
19
  export const useSubscriptionPackages = (userId: string | undefined) => {
20
+ const isConfigured = SubscriptionManager.isConfigured();
21
+
20
22
  if (__DEV__) {
21
- console.log('[DEBUG useSubscriptionPackages] Hook called', { userId: userId || 'ANONYMOUS' });
23
+ console.log('[DEBUG useSubscriptionPackages] Hook called', {
24
+ userId: userId || 'ANONYMOUS',
25
+ isConfigured,
26
+ });
22
27
  }
23
28
 
24
29
  return useQuery({
@@ -89,7 +94,7 @@ export const useSubscriptionPackages = (userId: string | undefined) => {
89
94
  },
90
95
  staleTime: STALE_TIME,
91
96
  gcTime: GC_TIME,
92
- enabled: true, // Always enabled - works for both authenticated and anonymous users
97
+ enabled: isConfigured, // Only enabled when SubscriptionManager is configured
93
98
  refetchOnMount: "always", // Always refetch to get fresh packages (fixes cached empty results)
94
99
  });
95
100
  };