@umituz/react-native-subscription 2.14.36 → 2.14.37
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.
|
|
3
|
+
"version": "2.14.37",
|
|
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,7 +33,6 @@
|
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"@tanstack/react-query": ">=5.0.0",
|
|
36
|
-
"@umituz/react-native-tanstack": "latest",
|
|
37
36
|
"@umituz/react-native-design-system": "latest",
|
|
38
37
|
"@umituz/react-native-firebase": "latest",
|
|
39
38
|
"@umituz/react-native-legal": "latest",
|
|
@@ -50,7 +49,6 @@
|
|
|
50
49
|
},
|
|
51
50
|
"devDependencies": {
|
|
52
51
|
"@tanstack/react-query": "^5.0.0",
|
|
53
|
-
"@umituz/react-native-tanstack": "*",
|
|
54
52
|
"@types/react": "~19.1.10",
|
|
55
53
|
"@typescript-eslint/eslint-plugin": "^8.50.1",
|
|
56
54
|
"@typescript-eslint/parser": "^8.50.1",
|
package/src/index.ts
CHANGED
|
@@ -383,10 +383,6 @@ 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
388
|
// REVENUECAT - Errors
|
|
@@ -15,19 +15,23 @@ import {
|
|
|
15
15
|
isCreditsRepositoryConfigured,
|
|
16
16
|
} from "../../infrastructure/repositories/CreditsRepositoryProvider";
|
|
17
17
|
|
|
18
|
-
const CACHE_CONFIG = {
|
|
19
|
-
staleTime: 30 * 1000,
|
|
20
|
-
gcTime: 5 * 60 * 1000,
|
|
21
|
-
};
|
|
22
|
-
|
|
23
18
|
export const creditsQueryKeys = {
|
|
24
19
|
all: ["credits"] as const,
|
|
25
20
|
user: (userId: string) => ["credits", userId] as const,
|
|
26
21
|
};
|
|
27
22
|
|
|
23
|
+
export interface CreditsCacheConfig {
|
|
24
|
+
/** Time in ms before data is considered stale. Default: 0 (always fresh) */
|
|
25
|
+
staleTime?: number;
|
|
26
|
+
/** Time in ms before inactive data is garbage collected. Default: 0 */
|
|
27
|
+
gcTime?: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
28
30
|
export interface UseCreditsParams {
|
|
29
31
|
userId: string | undefined;
|
|
30
32
|
enabled?: boolean;
|
|
33
|
+
/** Cache configuration. Default: no caching (always fresh data) */
|
|
34
|
+
cache?: CreditsCacheConfig;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
export interface UseCreditsResult {
|
|
@@ -46,10 +50,15 @@ export interface UseCreditsResult {
|
|
|
46
50
|
export const useCredits = ({
|
|
47
51
|
userId,
|
|
48
52
|
enabled = true,
|
|
53
|
+
cache,
|
|
49
54
|
}: UseCreditsParams): UseCreditsResult => {
|
|
50
55
|
const isConfigured = isCreditsRepositoryConfigured();
|
|
51
56
|
const config = getCreditsConfig();
|
|
52
57
|
|
|
58
|
+
// Default: no caching (always fresh data)
|
|
59
|
+
const staleTime = cache?.staleTime ?? 0;
|
|
60
|
+
const gcTime = cache?.gcTime ?? 0;
|
|
61
|
+
|
|
53
62
|
const { data, isLoading, error, refetch } = useQuery({
|
|
54
63
|
queryKey: creditsQueryKeys.user(userId ?? ""),
|
|
55
64
|
queryFn: async () => {
|
|
@@ -62,8 +71,8 @@ export const useCredits = ({
|
|
|
62
71
|
return result.data || null;
|
|
63
72
|
},
|
|
64
73
|
enabled: enabled && !!userId && isConfigured,
|
|
65
|
-
staleTime
|
|
66
|
-
gcTime
|
|
74
|
+
staleTime,
|
|
75
|
+
gcTime,
|
|
67
76
|
});
|
|
68
77
|
|
|
69
78
|
const credits = data ?? null;
|
|
@@ -1,45 +0,0 @@
|
|
|
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
|
-
};
|