@umituz/react-native-subscription 2.41.8 → 2.41.10

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.41.8",
3
+ "version": "2.41.10",
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",
@@ -2,7 +2,7 @@ import { useQuery, useQueryClient } from "@umituz/react-native-design-system/tan
2
2
  import { useCallback, useMemo, useEffect } from "react";
3
3
  import { useAuthStore, selectUserId } from "@umituz/react-native-auth";
4
4
  import { subscriptionEventBus, SUBSCRIPTION_EVENTS } from "../../../shared/infrastructure/SubscriptionEventBus";
5
- import { NO_CACHE_QUERY_CONFIG } from "../../../shared/infrastructure/react-query/queryConfig";
5
+ import { SHORT_CACHE_CONFIG } from "../../../shared/infrastructure/react-query/queryConfig";
6
6
  import { usePreviousUserCleanup } from "../../../shared/infrastructure/react-query/hooks/usePreviousUserCleanup";
7
7
  import {
8
8
  getCreditsRepository,
@@ -13,6 +13,7 @@ import { calculateSafePercentage, canAffordAmount } from "../utils/creditValidat
13
13
  import { isAuthenticated } from "../../subscription/utils/authGuards";
14
14
  import { creditsQueryKeys } from "./creditsQueryKeys";
15
15
  import type { UseCreditsResult, CreditsLoadStatus } from "./useCredits.types";
16
+ import type { UserCredits } from "../core/Credits";
16
17
 
17
18
  const deriveLoadStatus = (
18
19
  queryStatus: "pending" | "error" | "success",
@@ -32,7 +33,7 @@ export const useCredits = (): UseCreditsResult => {
32
33
  const hasUser = isAuthenticated(userId);
33
34
  const queryEnabled = hasUser && isConfigured;
34
35
 
35
- const { data, status, error, refetch } = useQuery({
36
+ const { data, status, error, refetch } = useQuery<UserCredits | null, Error>({
36
37
  queryKey: creditsQueryKeys.user(userId),
37
38
  queryFn: async () => {
38
39
  if (!hasUser || !isConfigured) return null;
@@ -47,7 +48,7 @@ export const useCredits = (): UseCreditsResult => {
47
48
  return result.data ?? null;
48
49
  },
49
50
  enabled: queryEnabled,
50
- ...NO_CACHE_QUERY_CONFIG,
51
+ ...SHORT_CACHE_CONFIG,
51
52
  });
52
53
 
53
54
  const queryClient = useQueryClient();
@@ -6,7 +6,7 @@ import { initializationState } from "../infrastructure/state/initializationState
6
6
  import { subscriptionEventBus, SUBSCRIPTION_EVENTS } from "../../../shared/infrastructure/SubscriptionEventBus";
7
7
  import { SubscriptionStatusResult } from "./useSubscriptionStatus.types";
8
8
  import { isAuthenticated } from "../utils/authGuards";
9
- import { NO_CACHE_QUERY_CONFIG } from "../../../shared/infrastructure/react-query/queryConfig";
9
+ import { SHORT_CACHE_CONFIG } from "../../../shared/infrastructure/react-query/queryConfig";
10
10
  import { usePreviousUserCleanup } from "../../../shared/infrastructure/react-query/hooks/usePreviousUserCleanup";
11
11
 
12
12
  export const subscriptionStatusQueryKeys = {
@@ -43,7 +43,7 @@ export const useSubscriptionStatus = (): SubscriptionStatusResult => {
43
43
  return SubscriptionManager.checkPremiumStatus();
44
44
  },
45
45
  enabled: queryEnabled,
46
- ...NO_CACHE_QUERY_CONFIG,
46
+ ...SHORT_CACHE_CONFIG,
47
47
  });
48
48
 
49
49
  usePreviousUserCleanup(userId, queryClient, subscriptionStatusQueryKeys.user);
@@ -1,7 +1,7 @@
1
1
  import { useQuery } from "@umituz/react-native-design-system/tanstack";
2
2
  import { useMemo } from "react";
3
3
  import { useAuthStore, selectUserId } from "@umituz/react-native-auth";
4
- import { NO_CACHE_QUERY_CONFIG } from "../../../../shared/infrastructure/react-query/queryConfig";
4
+ import { MEDIUM_CACHE_CONFIG } from "../../../../shared/infrastructure/react-query/queryConfig";
5
5
  import type {
6
6
  CreditLog,
7
7
  TransactionRepositoryConfig,
@@ -56,7 +56,7 @@ export function useTransactionHistory({
56
56
  return result.data ?? [];
57
57
  },
58
58
  enabled: hasUser,
59
- ...NO_CACHE_QUERY_CONFIG,
59
+ ...MEDIUM_CACHE_CONFIG,
60
60
  });
61
61
 
62
62
  const transactions = data ?? [];
@@ -1,7 +1,41 @@
1
- export const NO_CACHE_QUERY_CONFIG = {
2
- gcTime: 0,
3
- staleTime: 0,
4
- refetchOnMount: "always" as const,
5
- refetchOnWindowFocus: "always" as const,
6
- refetchOnReconnect: "always" as const,
1
+ /**
2
+ * Query cache configurations for optimal performance
3
+ * Uses event-based invalidation via subscriptionEventBus for real-time updates
4
+ */
5
+
6
+ /**
7
+ * Short-lived cache for frequently changing data (credits, subscription status)
8
+ * Events automatically invalidate the cache, so we can safely cache for 60s
9
+ */
10
+ export const SHORT_CACHE_CONFIG = {
11
+ gcTime: 1000 * 60, // 1 minute - keep in memory for 1 minute
12
+ staleTime: 1000 * 30, // 30 seconds - consider stale after 30s
13
+ refetchOnMount: false, // Don't refetch on mount if cache exists
14
+ refetchOnWindowFocus: false, // Don't refetch on app focus
15
+ refetchOnReconnect: true, // Refetch on reconnect only
7
16
  };
17
+
18
+ /**
19
+ * Medium cache for relatively stable data (packages, transaction history)
20
+ */
21
+ export const MEDIUM_CACHE_CONFIG = {
22
+ gcTime: 1000 * 60 * 5, // 5 minutes
23
+ staleTime: 1000 * 60 * 2, // 2 minutes
24
+ refetchOnMount: false,
25
+ refetchOnWindowFocus: false,
26
+ refetchOnReconnect: true,
27
+ };
28
+
29
+ /**
30
+ * Long cache for rarely changing data (config, metadata)
31
+ */
32
+ export const LONG_CACHE_CONFIG = {
33
+ gcTime: 1000 * 60 * 30, // 30 minutes
34
+ staleTime: 1000 * 60 * 10, // 10 minutes
35
+ refetchOnMount: false,
36
+ refetchOnWindowFocus: false,
37
+ refetchOnReconnect: true,
38
+ };
39
+
40
+ /** @deprecated Use SHORT_CACHE_CONFIG instead */
41
+ export const NO_CACHE_QUERY_CONFIG = SHORT_CACHE_CONFIG;