@umituz/react-native-subscription 2.14.53 → 2.14.54
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 +1 -1
- package/src/infrastructure/services/SubscriptionInitializer.ts +0 -23
- package/src/presentation/hooks/useAuthAwarePurchase.ts +0 -3
- package/src/presentation/hooks/usePremium.ts +0 -15
- package/src/presentation/hooks/useSubscriptionStatus.ts +1 -11
- package/src/revenuecat/infrastructure/managers/SubscriptionManager.ts +10 -51
- package/src/revenuecat/infrastructure/utils/ApiKeyResolver.ts +0 -20
- package/src/revenuecat/presentation/hooks/useSubscriptionPackages.ts +9 -57
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-subscription",
|
|
3
|
-
"version": "2.14.
|
|
3
|
+
"version": "2.14.54",
|
|
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",
|
|
@@ -41,9 +41,6 @@ const waitForAuthState = async (
|
|
|
41
41
|
|
|
42
42
|
// If user already available, return immediately
|
|
43
43
|
if (auth.currentUser) {
|
|
44
|
-
if (__DEV__) {
|
|
45
|
-
console.log("[Subscription] User already available:", auth.currentUser.uid);
|
|
46
|
-
}
|
|
47
44
|
return auth.currentUser.uid;
|
|
48
45
|
}
|
|
49
46
|
|
|
@@ -51,22 +48,12 @@ const waitForAuthState = async (
|
|
|
51
48
|
return new Promise<string | undefined>((resolve) => {
|
|
52
49
|
const unsubscribe = auth.onAuthStateChanged((user) => {
|
|
53
50
|
unsubscribe();
|
|
54
|
-
if (__DEV__) {
|
|
55
|
-
console.log("[Subscription] Auth state ready:", {
|
|
56
|
-
hasUser: !!user,
|
|
57
|
-
userId: user?.uid ?? "anonymous",
|
|
58
|
-
isAnonymous: user?.isAnonymous ?? true,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
51
|
resolve(user?.uid || undefined);
|
|
62
52
|
});
|
|
63
53
|
|
|
64
54
|
// Timeout fallback - don't wait forever
|
|
65
55
|
setTimeout(() => {
|
|
66
56
|
unsubscribe();
|
|
67
|
-
if (__DEV__) {
|
|
68
|
-
console.log("[Subscription] Auth state timeout, proceeding with anonymous");
|
|
69
|
-
}
|
|
70
57
|
resolve(undefined);
|
|
71
58
|
}, timeoutMs);
|
|
72
59
|
});
|
|
@@ -110,12 +97,6 @@ export const initializeSubscription = async (
|
|
|
110
97
|
// Wait for auth state to get correct user ID
|
|
111
98
|
const initialUserId = await waitForAuthState(getFirebaseAuth, authStateTimeoutMs);
|
|
112
99
|
|
|
113
|
-
if (__DEV__) {
|
|
114
|
-
console.log("[Subscription] Initializing with user:", {
|
|
115
|
-
userId: initialUserId ?? "will use anonymous",
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
100
|
const initPromise = SubscriptionManager.initialize(initialUserId);
|
|
120
101
|
const timeoutPromise = new Promise<boolean>((_, reject) =>
|
|
121
102
|
setTimeout(
|
|
@@ -134,8 +115,4 @@ export const initializeSubscription = async (
|
|
|
134
115
|
},
|
|
135
116
|
showAuthModal,
|
|
136
117
|
});
|
|
137
|
-
|
|
138
|
-
if (__DEV__) {
|
|
139
|
-
console.log("[Subscription] Initialized successfully");
|
|
140
|
-
}
|
|
141
118
|
};
|
|
@@ -22,9 +22,6 @@ let globalAuthProvider: PurchaseAuthProvider | null = null;
|
|
|
22
22
|
*/
|
|
23
23
|
export const configureAuthProvider = (provider: PurchaseAuthProvider): void => {
|
|
24
24
|
globalAuthProvider = provider;
|
|
25
|
-
if (__DEV__) {
|
|
26
|
-
console.log("[useAuthAwarePurchase] Auth provider configured");
|
|
27
|
-
}
|
|
28
25
|
};
|
|
29
26
|
|
|
30
27
|
export interface UseAuthAwarePurchaseResult {
|
|
@@ -54,10 +54,6 @@ export interface UsePremiumResult {
|
|
|
54
54
|
* ```
|
|
55
55
|
*/
|
|
56
56
|
export const usePremium = (userId?: string): UsePremiumResult => {
|
|
57
|
-
if (__DEV__) {
|
|
58
|
-
console.log('[DEBUG usePremium] Hook called', { userId: userId || 'ANONYMOUS' });
|
|
59
|
-
}
|
|
60
|
-
|
|
61
57
|
// Fetch real subscription status from RevenueCat
|
|
62
58
|
const { isPremium: subscriptionActive, isLoading: statusLoading } =
|
|
63
59
|
useSubscriptionStatus({
|
|
@@ -75,17 +71,6 @@ export const usePremium = (userId?: string): UsePremiumResult => {
|
|
|
75
71
|
const { data: packages = [], isLoading: packagesLoading } =
|
|
76
72
|
useSubscriptionPackages(userId);
|
|
77
73
|
|
|
78
|
-
if (__DEV__) {
|
|
79
|
-
console.log('[DEBUG usePremium] State', {
|
|
80
|
-
userId: userId || 'ANONYMOUS',
|
|
81
|
-
packagesCount: packages?.length || 0,
|
|
82
|
-
packagesLoading,
|
|
83
|
-
creditsLoading,
|
|
84
|
-
statusLoading,
|
|
85
|
-
isPremium: subscriptionActive,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
74
|
// Purchase and restore mutations
|
|
90
75
|
const purchaseMutation = usePurchasePackage(userId);
|
|
91
76
|
const restoreMutation = useRestorePurchase(userId);
|
|
@@ -46,17 +46,7 @@ export const useSubscriptionStatus = ({
|
|
|
46
46
|
return { isPremium: false, expirationDate: null };
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (__DEV__) {
|
|
52
|
-
console.log("[useSubscriptionStatus] Status from RevenueCat", {
|
|
53
|
-
userId,
|
|
54
|
-
isPremium: status.isPremium,
|
|
55
|
-
expirationDate: status.expirationDate,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return status;
|
|
49
|
+
return SubscriptionManager.checkPremiumStatus();
|
|
60
50
|
},
|
|
61
51
|
enabled: enabled && !!userId && SubscriptionManager.isInitializedForUser(userId),
|
|
62
52
|
staleTime: 30 * 1000,
|
|
@@ -33,52 +33,28 @@ class SubscriptionManagerImpl {
|
|
|
33
33
|
if (config.getAnonymousUserId) {
|
|
34
34
|
this.userIdProvider.configure(config.getAnonymousUserId);
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
if (__DEV__) {
|
|
38
|
-
console.log('[DEBUG SubscriptionManager] Configured:', {
|
|
39
|
-
entitlementId: config.config.entitlementIdentifier,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
36
|
}
|
|
43
37
|
|
|
44
38
|
private ensureConfigured(): void {
|
|
45
39
|
if (!this.managerConfig || !this.packageHandler) {
|
|
46
|
-
|
|
47
|
-
if (__DEV__) {
|
|
48
|
-
console.error('[DEBUG SubscriptionManager] Not configured:', {
|
|
49
|
-
hasConfig: !!this.managerConfig,
|
|
50
|
-
hasHandler: !!this.packageHandler,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
throw error;
|
|
40
|
+
throw new Error("SubscriptionManager not configured");
|
|
54
41
|
}
|
|
55
42
|
}
|
|
56
43
|
|
|
57
44
|
private async performInitialization(userId: string): Promise<boolean> {
|
|
58
45
|
this.ensureConfigured();
|
|
59
46
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
this.serviceInstance = getRevenueCatService();
|
|
47
|
+
await initializeRevenueCatService(this.managerConfig!.config);
|
|
48
|
+
this.serviceInstance = getRevenueCatService();
|
|
63
49
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
50
|
+
if (!this.serviceInstance) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
67
53
|
|
|
68
|
-
|
|
54
|
+
this.packageHandler!.setService(this.serviceInstance);
|
|
69
55
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return result.success;
|
|
73
|
-
} catch (error) {
|
|
74
|
-
if (__DEV__) {
|
|
75
|
-
console.error('[DEBUG SubscriptionManager] Initialization failed:', {
|
|
76
|
-
error,
|
|
77
|
-
userId,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
throw error;
|
|
81
|
-
}
|
|
56
|
+
const result = await this.serviceInstance.initialize(userId);
|
|
57
|
+
return result.success;
|
|
82
58
|
}
|
|
83
59
|
|
|
84
60
|
async initialize(userId?: string): Promise<boolean> {
|
|
@@ -116,27 +92,11 @@ class SubscriptionManagerImpl {
|
|
|
116
92
|
|
|
117
93
|
async getPackages(): Promise<PurchasesPackage[]> {
|
|
118
94
|
this.ensureConfigured();
|
|
119
|
-
if (__DEV__) {
|
|
120
|
-
console.log('[DEBUG SubscriptionManager] getPackages called', {
|
|
121
|
-
hasServiceInstance: !!this.serviceInstance,
|
|
122
|
-
hasPackageHandler: !!this.packageHandler,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
95
|
if (!this.serviceInstance) {
|
|
126
|
-
if (__DEV__) {
|
|
127
|
-
console.log('[DEBUG SubscriptionManager] Creating service instance...');
|
|
128
|
-
}
|
|
129
96
|
this.serviceInstance = getRevenueCatService();
|
|
130
97
|
this.packageHandler!.setService(this.serviceInstance);
|
|
131
98
|
}
|
|
132
|
-
|
|
133
|
-
if (__DEV__) {
|
|
134
|
-
console.log('[DEBUG SubscriptionManager] fetchPackages returned', {
|
|
135
|
-
count: packages.length,
|
|
136
|
-
packages: packages.map(p => ({ id: p.identifier, type: p.packageType })),
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
return packages;
|
|
99
|
+
return this.packageHandler!.fetchPackages();
|
|
140
100
|
}
|
|
141
101
|
|
|
142
102
|
async purchasePackage(pkg: PurchasesPackage): Promise<boolean> {
|
|
@@ -178,5 +138,4 @@ class SubscriptionManagerImpl {
|
|
|
178
138
|
|
|
179
139
|
export const SubscriptionManager = new SubscriptionManagerImpl();
|
|
180
140
|
|
|
181
|
-
// Re-export types
|
|
182
141
|
export type { PremiumStatus };
|
|
@@ -31,35 +31,15 @@ export function shouldUseTestStore(config: RevenueCatConfig): boolean {
|
|
|
31
31
|
export function resolveApiKey(config: RevenueCatConfig): string | null {
|
|
32
32
|
const useTestStore = shouldUseTestStore(config);
|
|
33
33
|
|
|
34
|
-
if (__DEV__) {
|
|
35
|
-
console.log('[DEBUG ApiKeyResolver] resolveApiKey called', {
|
|
36
|
-
useTestStore,
|
|
37
|
-
hasTestStoreKey: !!config.testStoreKey,
|
|
38
|
-
hasApiKey: !!config.apiKey,
|
|
39
|
-
testStoreKeyPrefix: config.testStoreKey ? config.testStoreKey.substring(0, 10) + '...' : 'null',
|
|
40
|
-
apiKeyPrefix: config.apiKey ? config.apiKey.substring(0, 10) + '...' : 'null',
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
34
|
if (useTestStore) {
|
|
45
|
-
if (__DEV__) {
|
|
46
|
-
console.log('[DEBUG ApiKeyResolver] Using Test Store key');
|
|
47
|
-
}
|
|
48
35
|
return config.testStoreKey ?? null;
|
|
49
36
|
}
|
|
50
37
|
|
|
51
38
|
const key = config.apiKey;
|
|
52
39
|
|
|
53
40
|
if (!key || key === "" || key.includes("YOUR_")) {
|
|
54
|
-
if (__DEV__) {
|
|
55
|
-
console.log('[DEBUG ApiKeyResolver] No valid production API key');
|
|
56
|
-
}
|
|
57
41
|
return null;
|
|
58
42
|
}
|
|
59
43
|
|
|
60
|
-
if (__DEV__) {
|
|
61
|
-
console.log('[DEBUG ApiKeyResolver] Using production API key');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
44
|
return key;
|
|
65
45
|
}
|
|
@@ -18,73 +18,25 @@ import {
|
|
|
18
18
|
export const useSubscriptionPackages = (userId: string | undefined) => {
|
|
19
19
|
const isConfigured = SubscriptionManager.isConfigured();
|
|
20
20
|
|
|
21
|
-
if (__DEV__) {
|
|
22
|
-
console.log('[DEBUG useSubscriptionPackages] Hook called', {
|
|
23
|
-
userId: userId || 'ANONYMOUS',
|
|
24
|
-
isConfigured,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
21
|
return useQuery({
|
|
29
22
|
queryKey: [...SUBSCRIPTION_QUERY_KEYS.packages, userId ?? "anonymous"] as const,
|
|
30
23
|
queryFn: async () => {
|
|
31
|
-
if (__DEV__) {
|
|
32
|
-
console.log('[DEBUG useSubscriptionPackages] QueryFn executing...', { userId: userId || 'ANONYMOUS' });
|
|
33
|
-
}
|
|
34
|
-
|
|
35
24
|
// Initialize if needed (works for both authenticated and anonymous users)
|
|
36
|
-
|
|
37
|
-
if (userId) {
|
|
38
|
-
|
|
39
|
-
if (__DEV__) {
|
|
40
|
-
console.log('[DEBUG useSubscriptionPackages] Initializing for user:', userId);
|
|
41
|
-
}
|
|
42
|
-
await SubscriptionManager.initialize(userId);
|
|
43
|
-
} else {
|
|
44
|
-
if (__DEV__) {
|
|
45
|
-
console.log('[DEBUG useSubscriptionPackages] Already initialized for user:', userId);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
} else {
|
|
49
|
-
if (!SubscriptionManager.isInitialized()) {
|
|
50
|
-
if (__DEV__) {
|
|
51
|
-
console.log('[DEBUG useSubscriptionPackages] Initializing for ANONYMOUS user');
|
|
52
|
-
}
|
|
53
|
-
await SubscriptionManager.initialize(undefined);
|
|
54
|
-
} else {
|
|
55
|
-
if (__DEV__) {
|
|
56
|
-
console.log('[DEBUG useSubscriptionPackages] Already initialized for ANONYMOUS');
|
|
57
|
-
}
|
|
58
|
-
}
|
|
25
|
+
if (userId) {
|
|
26
|
+
if (!SubscriptionManager.isInitializedForUser(userId)) {
|
|
27
|
+
await SubscriptionManager.initialize(userId);
|
|
59
28
|
}
|
|
60
|
-
}
|
|
61
|
-
if (
|
|
62
|
-
|
|
29
|
+
} else {
|
|
30
|
+
if (!SubscriptionManager.isInitialized()) {
|
|
31
|
+
await SubscriptionManager.initialize(undefined);
|
|
63
32
|
}
|
|
64
|
-
throw error;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (__DEV__) {
|
|
68
|
-
console.log('[DEBUG useSubscriptionPackages] Calling getPackages...');
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const packages = await SubscriptionManager.getPackages();
|
|
72
|
-
|
|
73
|
-
if (__DEV__) {
|
|
74
|
-
console.log('[DEBUG useSubscriptionPackages] Got packages', {
|
|
75
|
-
count: packages.length,
|
|
76
|
-
packages: packages.map(p => ({
|
|
77
|
-
id: p.identifier,
|
|
78
|
-
type: p.packageType,
|
|
79
|
-
})),
|
|
80
|
-
});
|
|
81
33
|
}
|
|
82
34
|
|
|
83
|
-
return
|
|
35
|
+
return SubscriptionManager.getPackages();
|
|
84
36
|
},
|
|
85
37
|
staleTime: STALE_TIME,
|
|
86
38
|
gcTime: GC_TIME,
|
|
87
|
-
enabled: isConfigured,
|
|
88
|
-
refetchOnMount: true,
|
|
39
|
+
enabled: isConfigured,
|
|
40
|
+
refetchOnMount: true,
|
|
89
41
|
});
|
|
90
42
|
};
|