@umituz/react-native-subscription 2.43.4 → 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.4",
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,6 @@ import {
6
6
  selectUserId,
7
7
  } from "@umituz/react-native-auth";
8
8
  import { SubscriptionManager } from "../../infrastructure/managers/SubscriptionManager";
9
- import { subscriptionStatusQueryKeys } from "../../presentation/useSubscriptionStatus";
10
- import { creditsQueryKeys } from "../../../credits/presentation/creditsQueryKeys";
11
9
  import { SUBSCRIPTION_QUERY_KEYS } from "./subscriptionQueryKeys";
12
10
  import { getErrorMessage } from "../../../revenuecat/core/errors/RevenueCatErrorHandler";
13
11
 
@@ -40,12 +38,13 @@ export const usePurchasePackage = () => {
40
38
  if (result.success) {
41
39
  showSuccess("Purchase Successful", "Your subscription is now active!");
42
40
 
43
- // Invalidate caches after successful purchase
41
+ // Invalidate packages cache (no event listener for packages)
44
42
  queryClient.invalidateQueries({ queryKey: SUBSCRIPTION_QUERY_KEYS.packages });
45
- if (userId) {
46
- queryClient.invalidateQueries({ queryKey: subscriptionStatusQueryKeys.user(userId) });
47
- queryClient.invalidateQueries({ queryKey: creditsQueryKeys.user(userId) });
48
- }
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
49
48
  } else {
50
49
  showError("Purchase Failed", "Unable to complete purchase. Please try again.");
51
50
  }
@@ -5,8 +5,6 @@ import {
5
5
  selectUserId,
6
6
  } from "@umituz/react-native-auth";
7
7
  import { SubscriptionManager } from "../../infrastructure/managers/SubscriptionManager";
8
- import { subscriptionStatusQueryKeys } from "../../presentation/useSubscriptionStatus";
9
- import { creditsQueryKeys } from "../../../credits/presentation/creditsQueryKeys";
10
8
  import { SUBSCRIPTION_QUERY_KEYS } from "./subscriptionQueryKeys";
11
9
  import { getErrorMessage } from "../../../revenuecat/core/errors/RevenueCatErrorHandler";
12
10
 
@@ -31,12 +29,13 @@ export const useRestorePurchase = () => {
31
29
  },
32
30
  onSuccess: (result) => {
33
31
  if (result.success) {
34
- // Invalidate caches after successful restore
32
+ // Invalidate packages cache (no event listener for packages)
35
33
  queryClient.invalidateQueries({ queryKey: SUBSCRIPTION_QUERY_KEYS.packages });
36
- if (userId) {
37
- queryClient.invalidateQueries({ queryKey: subscriptionStatusQueryKeys.user(userId) });
38
- queryClient.invalidateQueries({ queryKey: creditsQueryKeys.user(userId) });
39
- }
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
40
39
 
41
40
  if (result.productId) {
42
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