@umituz/react-native-subscription 2.22.4 → 2.22.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.22.4",
3
+ "version": "2.22.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",
@@ -2,6 +2,8 @@
2
2
  * Credits Repository
3
3
  */
4
4
 
5
+ declare const __DEV__: boolean;
6
+
5
7
  import { doc, getDoc, runTransaction, serverTimestamp, type Firestore, type Transaction } from "firebase/firestore";
6
8
  import { BaseRepository, getFirestore } from "@umituz/react-native-firebase";
7
9
  import type { CreditsConfig, CreditsResult, DeductCreditsResult } from "../../domain/entities/Credits";
@@ -23,13 +25,26 @@ export class CreditsRepository extends BaseRepository {
23
25
 
24
26
  async getCredits(userId: string): Promise<CreditsResult> {
25
27
  const db = getFirestore();
26
- if (!db) return { success: false, error: { message: "No DB", code: "DB_ERR" } };
28
+ if (!db) {
29
+ if (__DEV__) console.log("[CreditsRepository] No Firestore instance");
30
+ return { success: false, error: { message: "No DB", code: "DB_ERR" } };
31
+ }
27
32
  try {
28
- const snap = await getDoc(this.getRef(db, userId));
29
- if (!snap.exists()) return { success: true, data: undefined };
33
+ const ref = this.getRef(db, userId);
34
+ if (__DEV__) console.log("[CreditsRepository] Fetching credits:", { userId: userId.slice(0, 8), path: ref.path });
35
+ const snap = await getDoc(ref);
36
+ if (!snap.exists()) {
37
+ if (__DEV__) console.log("[CreditsRepository] No credits document found");
38
+ return { success: true, data: undefined };
39
+ }
30
40
  const d = snap.data() as UserCreditsDocumentRead;
31
- return { success: true, data: CreditsMapper.toEntity(d) };
32
- } catch (e: any) { return { success: false, error: { message: e.message, code: "FETCH_ERR" } }; }
41
+ const entity = CreditsMapper.toEntity(d);
42
+ if (__DEV__) console.log("[CreditsRepository] Credits fetched:", { credits: entity.credits, limit: entity.creditLimit });
43
+ return { success: true, data: entity };
44
+ } catch (e: any) {
45
+ if (__DEV__) console.error("[CreditsRepository] Fetch error:", e.message);
46
+ return { success: false, error: { message: e.message, code: "FETCH_ERR" } };
47
+ }
33
48
  }
34
49
 
35
50
  async initializeCredits(
@@ -5,6 +5,8 @@
5
5
  * Generic and reusable - uses config from module-level provider.
6
6
  */
7
7
 
8
+ declare const __DEV__: boolean;
9
+
8
10
  import { useQuery } from "@tanstack/react-query";
9
11
  import { useCallback, useMemo } from "react";
10
12
  import type { UserCredits } from "../../domain/entities/Credits";
@@ -61,18 +63,35 @@ export const useCredits = ({
61
63
  const staleTime = cache?.staleTime ?? DEFAULT_STALE_TIME;
62
64
  const gcTime = cache?.gcTime ?? DEFAULT_GC_TIME;
63
65
 
66
+ const queryEnabled = enabled && !!userId && isConfigured;
67
+
68
+ if (__DEV__) {
69
+ console.log("[useCredits] Query state:", {
70
+ userId: userId?.slice(0, 8),
71
+ enabled,
72
+ isConfigured,
73
+ queryEnabled,
74
+ });
75
+ }
76
+
64
77
  const { data, isLoading, error, refetch } = useQuery({
65
78
  queryKey: creditsQueryKeys.user(userId ?? ""),
66
79
  queryFn: async () => {
67
- if (!userId || !isConfigured) return null;
80
+ if (!userId || !isConfigured) {
81
+ if (__DEV__) console.log("[useCredits] Query skipped:", { hasUserId: !!userId, isConfigured });
82
+ return null;
83
+ }
84
+ if (__DEV__) console.log("[useCredits] Executing queryFn for userId:", userId.slice(0, 8));
68
85
  const repository = getCreditsRepository();
69
86
  const result = await repository.getCredits(userId);
70
87
  if (!result.success) {
88
+ if (__DEV__) console.error("[useCredits] Query failed:", result.error?.message);
71
89
  throw new Error(result.error?.message || "Failed to fetch credits");
72
90
  }
91
+ if (__DEV__) console.log("[useCredits] Query success:", { hasData: !!result.data, credits: result.data?.credits });
73
92
  return result.data || null;
74
93
  },
75
- enabled: enabled && !!userId && isConfigured,
94
+ enabled: queryEnabled,
76
95
  staleTime,
77
96
  gcTime,
78
97
  refetchOnMount: true, // Refetch when component mounts