@umituz/react-native-subscription 2.43.3 → 2.43.5

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.43.3",
3
+ "version": "2.43.5",
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",
@@ -72,11 +72,7 @@ export function createDeductCreditMutationConfig(
72
72
  );
73
73
  }
74
74
  },
75
- onSuccess: (_data: unknown, _cost: number, context: MutationContext | undefined) => {
76
- const targetUserId = context?.capturedUserId ?? userId;
77
- if (targetUserId) {
78
- queryClient.invalidateQueries({ queryKey: creditsQueryKeys.user(targetUserId) });
79
- }
80
- },
75
+ // onSuccess removed - CREDITS_UPDATED event handles invalidation
76
+ // Optimistic update already applied, event will trigger refetch if needed
81
77
  };
82
78
  }
@@ -4,7 +4,6 @@ import { getCreditsRepository } from "../../infrastructure/CreditsRepositoryMana
4
4
  import type { UseDeductCreditParams, UseDeductCreditResult } from "./types";
5
5
  import type { DeductCreditsResult } from "../../core/Credits";
6
6
  import { createDeductCreditMutationConfig, type MutationContext } from "./mutationConfig";
7
- import { creditsQueryKeys } from "../creditsQueryKeys";
8
7
 
9
8
  export const useDeductCredit = ({
10
9
  userId,
@@ -57,8 +56,7 @@ export const useDeductCredit = ({
57
56
  try {
58
57
  const result = await repository.refundCredit(userId, amount);
59
58
  if (result.success) {
60
- // Invalidate queries to refresh credit balance
61
- await queryClient.invalidateQueries({ queryKey: creditsQueryKeys.user(userId) });
59
+ // CREDITS_UPDATED event emitted by RefundCreditsCommand handles invalidation
62
60
  return true;
63
61
  }
64
62
  return false;
@@ -6,8 +6,8 @@ import {
6
6
  selectUserId,
7
7
  } from "@umituz/react-native-auth";
8
8
  import { SubscriptionManager } from "../../infrastructure/managers/SubscriptionManager";
9
+ import { SUBSCRIPTION_QUERY_KEYS } from "./subscriptionQueryKeys";
9
10
  import { getErrorMessage } from "../../../revenuecat/core/errors/RevenueCatErrorHandler";
10
- import { invalidateSubscriptionCaches } from "../../../../shared/infrastructure/react-query/utils";
11
11
 
12
12
  interface PurchaseMutationResult {
13
13
  success: boolean;
@@ -37,7 +37,14 @@ export const usePurchasePackage = () => {
37
37
  onSuccess: (result) => {
38
38
  if (result.success) {
39
39
  showSuccess("Purchase Successful", "Your subscription is now active!");
40
- invalidateSubscriptionCaches(queryClient, userId);
40
+
41
+ // Invalidate packages cache (no event listener for packages)
42
+ queryClient.invalidateQueries({ queryKey: SUBSCRIPTION_QUERY_KEYS.packages });
43
+
44
+ // Credits and subscription status are invalidated via events:
45
+ // - CREDITS_UPDATED event (SubscriptionSyncProcessor → useCredits)
46
+ // - PREMIUM_STATUS_CHANGED event (SubscriptionSyncProcessor → useSubscriptionStatus)
47
+ // No manual invalidation needed here
41
48
  } else {
42
49
  showError("Purchase Failed", "Unable to complete purchase. Please try again.");
43
50
  }
@@ -5,8 +5,8 @@ import {
5
5
  selectUserId,
6
6
  } from "@umituz/react-native-auth";
7
7
  import { SubscriptionManager } from "../../infrastructure/managers/SubscriptionManager";
8
+ import { SUBSCRIPTION_QUERY_KEYS } from "./subscriptionQueryKeys";
8
9
  import { getErrorMessage } from "../../../revenuecat/core/errors/RevenueCatErrorHandler";
9
- import { invalidateSubscriptionCaches } from "../../../../shared/infrastructure/react-query/utils";
10
10
 
11
11
  interface RestoreResult {
12
12
  success: boolean;
@@ -29,7 +29,13 @@ export const useRestorePurchase = () => {
29
29
  },
30
30
  onSuccess: (result) => {
31
31
  if (result.success) {
32
- invalidateSubscriptionCaches(queryClient, userId);
32
+ // Invalidate packages cache (no event listener for packages)
33
+ queryClient.invalidateQueries({ queryKey: SUBSCRIPTION_QUERY_KEYS.packages });
34
+
35
+ // Credits and subscription status are invalidated via events:
36
+ // - CREDITS_UPDATED event (SubscriptionSyncProcessor → useCredits)
37
+ // - PREMIUM_STATUS_CHANGED event (SubscriptionSyncProcessor → useSubscriptionStatus)
38
+ // No manual invalidation needed here
33
39
 
34
40
  if (result.productId) {
35
41
  showSuccess("Restore Successful", "Your subscription has been restored!");
@@ -42,6 +42,7 @@ export const useSubscriptionPackages = () => {
42
42
  prevUserIdRef.current = userId;
43
43
 
44
44
  if (prevUserId !== userId) {
45
+ // Clean up previous user's cache to prevent data leakage
45
46
  if (prevUserId) {
46
47
  queryClient.cancelQueries({
47
48
  queryKey: [...SUBSCRIPTION_QUERY_KEYS.packages, prevUserId],
@@ -58,9 +59,8 @@ export const useSubscriptionPackages = () => {
58
59
  });
59
60
  }
60
61
 
61
- queryClient.invalidateQueries({
62
- queryKey: [...SUBSCRIPTION_QUERY_KEYS.packages, userId ?? "anonymous"],
63
- });
62
+ // No need to invalidate - removeQueries already cleared cache
63
+ // Query will refetch automatically on mount if needed
64
64
  }
65
65
  }, [userId, queryClient]);
66
66
 
package/src/index.ts CHANGED
@@ -51,14 +51,6 @@ export {
51
51
  } from "./shared/utils/Result";
52
52
  export type { Result, Success, Failure } from "./shared/utils/Result";
53
53
 
54
- // Cache Invalidation Utilities
55
- export {
56
- invalidateSubscriptionCaches,
57
- invalidateSubscriptionStatus,
58
- invalidateCredits,
59
- invalidateAllUserData,
60
- } from "./shared/infrastructure/react-query/utils";
61
-
62
54
  // Infrastructure Layer (Services & Repositories)
63
55
  export { initializeSubscription } from "./domains/subscription/application/initializer/SubscriptionInitializer";
64
56
  export type { SubscriptionInitConfig, CreditPackageConfig } from "./domains/subscription/application/SubscriptionInitializerTypes";
@@ -1,97 +0,0 @@
1
- import type { QueryClient } from "@tanstack/react-query";
2
- import { SUBSCRIPTION_QUERY_KEYS } from "../../../../domains/subscription/infrastructure/hooks/subscriptionQueryKeys";
3
- import { subscriptionStatusQueryKeys } from "../../../../domains/subscription/presentation/useSubscriptionStatus";
4
- import { creditsQueryKeys } from "../../../../domains/credits/presentation/creditsQueryKeys";
5
-
6
- /**
7
- * Centralized cache invalidation utilities for subscription-related queries.
8
- * This ensures consistent cache invalidation across all mutations and removes code duplication.
9
- */
10
-
11
- /**
12
- * Invalidate all subscription-related caches for a specific user.
13
- * This includes:
14
- * - Subscription packages
15
- * - Subscription status
16
- * - Credits
17
- *
18
- * @param queryClient - TanStack Query client instance
19
- * @param userId - User ID to invalidate caches for
20
- */
21
- export function invalidateSubscriptionCaches(
22
- queryClient: QueryClient,
23
- userId: string | null | undefined
24
- ): void {
25
- if (!userId) {
26
- return;
27
- }
28
-
29
- // Invalidate packages (global, not user-specific)
30
- queryClient.invalidateQueries({
31
- queryKey: SUBSCRIPTION_QUERY_KEYS.packages,
32
- });
33
-
34
- // Invalidate subscription status (user-specific)
35
- queryClient.invalidateQueries({
36
- queryKey: subscriptionStatusQueryKeys.user(userId),
37
- });
38
-
39
- // Invalidate credits (user-specific)
40
- queryClient.invalidateQueries({
41
- queryKey: creditsQueryKeys.user(userId),
42
- });
43
- }
44
-
45
- /**
46
- * Invalidate only subscription status cache.
47
- * Use this when only subscription status changes, not credits.
48
- *
49
- * @param queryClient - TanStack Query client instance
50
- * @param userId - User ID to invalidate cache for
51
- */
52
- export function invalidateSubscriptionStatus(
53
- queryClient: QueryClient,
54
- userId: string | null | undefined
55
- ): void {
56
- if (!userId) {
57
- return;
58
- }
59
-
60
- queryClient.invalidateQueries({
61
- queryKey: subscriptionStatusQueryKeys.user(userId),
62
- });
63
- }
64
-
65
- /**
66
- * Invalidate only credits cache.
67
- * Use this when only credits change, not subscription status.
68
- *
69
- * @param queryClient - TanStack Query client instance
70
- * @param userId - User ID to invalidate cache for
71
- */
72
- export function invalidateCredits(
73
- queryClient: QueryClient,
74
- userId: string | null | undefined
75
- ): void {
76
- if (!userId) {
77
- return;
78
- }
79
-
80
- queryClient.invalidateQueries({
81
- queryKey: creditsQueryKeys.user(userId),
82
- });
83
- }
84
-
85
- /**
86
- * Invalidate all caches for a user (subscription + credits).
87
- * Alias for invalidateSubscriptionCaches for better semantic clarity.
88
- *
89
- * @param queryClient - TanStack Query client instance
90
- * @param userId - User ID to invalidate caches for
91
- */
92
- export function invalidateAllUserData(
93
- queryClient: QueryClient,
94
- userId: string | null | undefined
95
- ): void {
96
- invalidateSubscriptionCaches(queryClient, userId);
97
- }
@@ -1,6 +0,0 @@
1
- export {
2
- invalidateSubscriptionCaches,
3
- invalidateSubscriptionStatus,
4
- invalidateCredits,
5
- invalidateAllUserData,
6
- } from "./cacheInvalidation";