@umituz/react-native-subscription 2.14.34 → 2.14.36

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.34",
3
+ "version": "2.14.36",
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",
@@ -33,6 +33,7 @@
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@tanstack/react-query": ">=5.0.0",
36
+ "@umituz/react-native-tanstack": "latest",
36
37
  "@umituz/react-native-design-system": "latest",
37
38
  "@umituz/react-native-firebase": "latest",
38
39
  "@umituz/react-native-legal": "latest",
@@ -49,6 +50,7 @@
49
50
  },
50
51
  "devDependencies": {
51
52
  "@tanstack/react-query": "^5.0.0",
53
+ "@umituz/react-native-tanstack": "*",
52
54
  "@types/react": "~19.1.10",
53
55
  "@typescript-eslint/eslint-plugin": "^8.50.1",
54
56
  "@typescript-eslint/parser": "^8.50.1",
package/src/index.ts CHANGED
@@ -383,6 +383,11 @@ export {
383
383
  type CreditAllocation,
384
384
  } from "./utils/creditMapper";
385
385
 
386
+ export {
387
+ invalidateCreditsCache,
388
+ invalidateAllCreditsCache,
389
+ } from "./utils/cacheInvalidation";
390
+
386
391
  // =============================================================================
387
392
  // REVENUECAT - Errors
388
393
  // =============================================================================
@@ -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
  };
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Cache Invalidation Utilities
3
+ * Centralized cache invalidation for credits and subscription queries
4
+ */
5
+
6
+ import {
7
+ getGlobalQueryClient,
8
+ hasGlobalQueryClient,
9
+ } from "@umituz/react-native-tanstack";
10
+ import { creditsQueryKeys } from "../presentation/hooks/useCredits";
11
+
12
+ declare const __DEV__: boolean;
13
+
14
+ /**
15
+ * Invalidate credits cache for a user.
16
+ * Call this after credits are deducted to ensure UI updates immediately.
17
+ */
18
+ export const invalidateCreditsCache = (userId: string): void => {
19
+ if (!hasGlobalQueryClient()) {
20
+ if (__DEV__) {
21
+ console.warn(
22
+ "[Subscription] QueryClient not available for cache invalidation",
23
+ );
24
+ }
25
+ return;
26
+ }
27
+
28
+ const queryClient = getGlobalQueryClient();
29
+ queryClient.invalidateQueries({
30
+ queryKey: creditsQueryKeys.user(userId),
31
+ });
32
+ };
33
+
34
+ /**
35
+ * Invalidate all credits cache (for all users).
36
+ * Useful when user logs out or switches accounts.
37
+ */
38
+ export const invalidateAllCreditsCache = (): void => {
39
+ if (!hasGlobalQueryClient()) return;
40
+
41
+ const queryClient = getGlobalQueryClient();
42
+ queryClient.invalidateQueries({
43
+ queryKey: creditsQueryKeys.all,
44
+ });
45
+ };