@umituz/react-native-subscription 2.14.35 → 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 +1 -1
- package/src/index.ts +1 -0
- package/src/presentation/hooks/useCredits.ts +16 -7
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",
|
package/src/index.ts
CHANGED
|
@@ -383,6 +383,7 @@ export {
|
|
|
383
383
|
type CreditAllocation,
|
|
384
384
|
} from "./utils/creditMapper";
|
|
385
385
|
|
|
386
|
+
|
|
386
387
|
// =============================================================================
|
|
387
388
|
// REVENUECAT - Errors
|
|
388
389
|
// =============================================================================
|
|
@@ -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;
|