@umituz/react-native-subscription 2.27.32 → 2.27.34

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.27.32",
3
+ "version": "2.27.34",
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",
@@ -38,7 +38,24 @@ const waitForAuthState = async (getAuth: () => FirebaseAuthLike | null, timeoutM
38
38
  export const initializeSubscription = async (config: SubscriptionInitConfig): Promise<void> => {
39
39
  const { apiKey, apiKeyIos, apiKeyAndroid, testStoreKey, entitlementId, credits, getAnonymousUserId, getFirebaseAuth, showAuthModal, onCreditsUpdated, creditPackages, timeoutMs = 10000, authStateTimeoutMs = 2000 } = config;
40
40
 
41
+ if (__DEV__) {
42
+ console.log('[DEBUG initializeSubscription] Config received:', {
43
+ hasApiKey: !!apiKey,
44
+ hasApiKeyIos: !!apiKeyIos,
45
+ hasApiKeyAndroid: !!apiKeyAndroid,
46
+ hasTestStoreKey: !!testStoreKey,
47
+ apiKeyPrefix: apiKey?.substring(0, 10),
48
+ testStoreKeyPrefix: testStoreKey?.substring(0, 10),
49
+ platform: Platform.OS,
50
+ });
51
+ }
52
+
41
53
  const key = Platform.OS === "ios" ? (apiKeyIos || apiKey || "") : (apiKeyAndroid || apiKey || "");
54
+
55
+ if (__DEV__) {
56
+ console.log('[DEBUG initializeSubscription] Resolved key:', key ? key.substring(0, 10) + '...' : 'empty');
57
+ }
58
+
42
59
  if (!key) throw new Error("API key required");
43
60
 
44
61
  configureCreditsRepository({ ...credits, creditPackageAmounts: creditPackages?.amounts });
@@ -188,6 +205,15 @@ export const initializeSubscription = async (config: SubscriptionInitConfig): Pr
188
205
  }
189
206
  };
190
207
 
208
+ if (__DEV__) {
209
+ console.log('[DEBUG initializeSubscription] Configuring SubscriptionManager with:', {
210
+ apiKeyPrefix: key.substring(0, 10),
211
+ hasTestStoreKey: !!testStoreKey,
212
+ testStoreKeyPrefix: testStoreKey?.substring(0, 10),
213
+ entitlementId,
214
+ });
215
+ }
216
+
191
217
  SubscriptionManager.configure({
192
218
  config: {
193
219
  apiKey: key,
@@ -48,9 +48,6 @@ export interface UsePaywallVisibilityResult {
48
48
  }
49
49
 
50
50
  export function usePaywallVisibility(): UsePaywallVisibilityResult {
51
- if (typeof __DEV__ !== 'undefined' && __DEV__) {
52
- console.log('[usePaywallVisibility] Hook called');
53
- }
54
51
  const state = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
55
52
 
56
53
  const setShowPaywall = useCallback((visible: boolean, source?: PurchaseSource) => {
@@ -33,9 +33,6 @@ export interface UsePremiumResult {
33
33
  }
34
34
 
35
35
  export const usePremium = (): UsePremiumResult => {
36
- if (typeof __DEV__ !== 'undefined' && __DEV__) {
37
- console.log('[usePremium] Hook called');
38
- }
39
36
  const { isPremium: subscriptionActive, isLoading: statusLoading } = useSubscriptionStatus();
40
37
  const { credits, isLoading: creditsLoading } = useCredits();
41
38
 
@@ -30,7 +30,16 @@ export class PackageHandler {
30
30
  }
31
31
 
32
32
  async fetchPackages(): Promise<PurchasesPackage[]> {
33
+ if (__DEV__) {
34
+ console.log('[DEBUG PackageHandler] fetchPackages called', {
35
+ hasService: !!this.service,
36
+ isInitialized: this.service?.isInitialized(),
37
+ });
38
+ }
33
39
  if (!this.service?.isInitialized()) {
40
+ if (__DEV__) {
41
+ console.log('[DEBUG PackageHandler] Service not initialized, returning empty');
42
+ }
34
43
  return [];
35
44
  }
36
45
 
@@ -95,6 +95,13 @@ class SubscriptionManagerImpl {
95
95
  }
96
96
 
97
97
  async getPackages(): Promise<PurchasesPackage[]> {
98
+ if (__DEV__) {
99
+ console.log('[DEBUG SubscriptionManager] getPackages called', {
100
+ isConfigured: this.isConfigured(),
101
+ isInitialized: this.isInitialized(),
102
+ hasServiceInstance: !!this.serviceInstance,
103
+ });
104
+ }
98
105
  this.ensureConfigured();
99
106
  if (!this.serviceInstance) {
100
107
  this.serviceInstance = getRevenueCatService();
@@ -57,11 +57,22 @@ function buildSuccessResult(
57
57
  return { success: true, offering: offerings.current, hasPremium };
58
58
  }
59
59
 
60
+ declare const __DEV__: boolean;
61
+
60
62
  export async function initializeSDK(
61
63
  deps: InitializerDeps,
62
64
  userId: string,
63
65
  apiKey?: string
64
66
  ): Promise<InitializeResult> {
67
+ if (__DEV__) {
68
+ console.log('[DEBUG RevenueCatInitializer] initializeSDK called', {
69
+ userId,
70
+ hasApiKey: !!apiKey,
71
+ isInitialized: deps.isInitialized(),
72
+ currentUserId: deps.getCurrentUserId(),
73
+ isPurchasesConfigured,
74
+ });
75
+ }
65
76
  // Case 1: Already initialized with the same user ID
66
77
  if (deps.isInitialized() && deps.getCurrentUserId() === userId) {
67
78
  try {
@@ -110,9 +121,25 @@ export async function initializeSDK(
110
121
  return { success: false, offering: null, hasPremium: false };
111
122
  }
112
123
 
124
+ if (__DEV__) {
125
+ console.log('[DEBUG RevenueCatInitializer] Config received:', {
126
+ hasApiKey: !!deps.config.apiKey,
127
+ hasTestStoreKey: !!deps.config.testStoreKey,
128
+ apiKeyPrefix: deps.config.apiKey?.substring(0, 10),
129
+ testStoreKeyPrefix: deps.config.testStoreKey?.substring(0, 10),
130
+ });
131
+ }
132
+
113
133
  const key = apiKey || resolveApiKey(deps.config);
114
134
 
135
+ if (__DEV__) {
136
+ console.log('[DEBUG RevenueCatInitializer] Resolved key:', key ? key.substring(0, 10) + '...' : 'null');
137
+ }
138
+
115
139
  if (!key) {
140
+ if (__DEV__) {
141
+ console.log('[DEBUG RevenueCatInitializer] No API key available, returning failure');
142
+ }
116
143
  return { success: false, offering: null, hasPremium: false };
117
144
  }
118
145
 
@@ -122,6 +149,9 @@ export async function initializeSDK(
122
149
  try {
123
150
  configureLogHandler();
124
151
 
152
+ if (__DEV__) {
153
+ console.log('[DEBUG RevenueCatInitializer] Configuring Purchases SDK with userId:', userId);
154
+ }
125
155
  await Purchases.configure({
126
156
  apiKey: key,
127
157
  appUserID: userId,
@@ -130,11 +160,21 @@ export async function initializeSDK(
130
160
  deps.setInitialized(true);
131
161
  deps.setCurrentUserId(userId);
132
162
 
163
+ if (__DEV__) {
164
+ console.log('[DEBUG RevenueCatInitializer] Purchases configured, fetching customer info and offerings...');
165
+ }
133
166
  const [customerInfo, offerings] = await Promise.all([
134
167
  Purchases.getCustomerInfo(),
135
168
  Purchases.getOfferings(),
136
169
  ]);
137
170
 
171
+ if (__DEV__) {
172
+ console.log('[DEBUG RevenueCatInitializer] Init complete', {
173
+ hasOfferings: !!offerings.current,
174
+ offeringsIdentifier: offerings.current?.identifier,
175
+ packagesCount: offerings.current?.availablePackages?.length ?? 0,
176
+ });
177
+ }
138
178
  return buildSuccessResult(deps, customerInfo, offerings);
139
179
  } catch (error) {
140
180
  getErrorMessage(error, "RevenueCat init failed");
@@ -7,6 +7,8 @@
7
7
  import type { RevenueCatConfig } from '../../domain/value-objects/RevenueCatConfig';
8
8
  import { isTestStoreEnvironment } from "./ExpoGoDetector";
9
9
 
10
+ declare const __DEV__: boolean;
11
+
10
12
  /**
11
13
  * Check if Test Store key should be used
12
14
  * CRITICAL: Never use test store in production builds
@@ -31,15 +33,33 @@ export function shouldUseTestStore(config: RevenueCatConfig): boolean {
31
33
  export function resolveApiKey(config: RevenueCatConfig): string | null {
32
34
  const useTestStore = shouldUseTestStore(config);
33
35
 
36
+ if (__DEV__) {
37
+ console.log('[DEBUG resolveApiKey] called', {
38
+ useTestStore,
39
+ hasTestStoreKey: !!config.testStoreKey,
40
+ hasApiKey: !!config.apiKey,
41
+ apiKeyPrefix: config.apiKey?.substring(0, 10),
42
+ });
43
+ }
44
+
34
45
  if (useTestStore) {
46
+ if (__DEV__) {
47
+ console.log('[DEBUG resolveApiKey] Using test store key');
48
+ }
35
49
  return config.testStoreKey ?? null;
36
50
  }
37
51
 
38
52
  const key = config.apiKey;
39
53
 
40
54
  if (!key || key === "" || key.includes("YOUR_")) {
55
+ if (__DEV__) {
56
+ console.log('[DEBUG resolveApiKey] No valid API key found');
57
+ }
41
58
  return null;
42
59
  }
43
60
 
61
+ if (__DEV__) {
62
+ console.log('[DEBUG resolveApiKey] Using production API key:', key.substring(0, 10) + '...');
63
+ }
44
64
  return key;
45
65
  }