@umituz/react-native-subscription 2.14.53 → 2.14.55
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/domains/paywall/components/PaywallContainer.tsx +105 -0
- package/src/domains/paywall/components/PaywallContainer.types.ts +30 -0
- package/src/domains/paywall/components/index.ts +3 -0
- package/src/index.ts +2 -0
- 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.55",
|
|
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",
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PaywallContainer Component
|
|
3
|
+
* Package-driven paywall that encapsulates all logic
|
|
4
|
+
* Main app only needs to add this ONE component
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import React, { useCallback } from "react";
|
|
8
|
+
import type { PurchasesPackage } from "react-native-purchases";
|
|
9
|
+
import { usePaywallVisibility } from "../../../presentation/hooks/usePaywallVisibility";
|
|
10
|
+
import { useSubscriptionPackages } from "../../../revenuecat/presentation/hooks/useSubscriptionPackages";
|
|
11
|
+
import { usePurchasePackage } from "../../../revenuecat/presentation/hooks/usePurchasePackage";
|
|
12
|
+
import { useRestorePurchase } from "../../../revenuecat/presentation/hooks/useRestorePurchase";
|
|
13
|
+
import { PaywallModal } from "./PaywallModal";
|
|
14
|
+
import type { PaywallContainerProps } from "./PaywallContainer.types";
|
|
15
|
+
|
|
16
|
+
declare const __DEV__: boolean;
|
|
17
|
+
|
|
18
|
+
export const PaywallContainer: React.FC<PaywallContainerProps> = ({
|
|
19
|
+
userId,
|
|
20
|
+
translations,
|
|
21
|
+
mode = "subscription",
|
|
22
|
+
legalUrls,
|
|
23
|
+
features,
|
|
24
|
+
heroImage,
|
|
25
|
+
bestValueIdentifier,
|
|
26
|
+
creditsLabel,
|
|
27
|
+
onPurchaseSuccess,
|
|
28
|
+
onPurchaseError,
|
|
29
|
+
}) => {
|
|
30
|
+
const { showPaywall, closePaywall } = usePaywallVisibility();
|
|
31
|
+
const { data: packages = [], isLoading } = useSubscriptionPackages(userId ?? undefined);
|
|
32
|
+
const { mutateAsync: purchasePackage } = usePurchasePackage(userId ?? undefined);
|
|
33
|
+
const { mutateAsync: restorePurchases } = useRestorePurchase(userId ?? undefined);
|
|
34
|
+
|
|
35
|
+
const handlePurchase = useCallback(
|
|
36
|
+
async (pkg: PurchasesPackage) => {
|
|
37
|
+
try {
|
|
38
|
+
if (__DEV__) {
|
|
39
|
+
console.log("[PaywallContainer] Purchase started:", pkg.identifier);
|
|
40
|
+
}
|
|
41
|
+
const result = await purchasePackage(pkg);
|
|
42
|
+
if (result.success) {
|
|
43
|
+
if (__DEV__) {
|
|
44
|
+
console.log("[PaywallContainer] Purchase successful");
|
|
45
|
+
}
|
|
46
|
+
onPurchaseSuccess?.();
|
|
47
|
+
closePaywall();
|
|
48
|
+
}
|
|
49
|
+
} catch (error) {
|
|
50
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
51
|
+
if (__DEV__) {
|
|
52
|
+
console.error("[PaywallContainer] Purchase failed:", message);
|
|
53
|
+
}
|
|
54
|
+
onPurchaseError?.(message);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
[purchasePackage, closePaywall, onPurchaseSuccess, onPurchaseError],
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const handleRestore = useCallback(async () => {
|
|
61
|
+
try {
|
|
62
|
+
if (__DEV__) {
|
|
63
|
+
console.log("[PaywallContainer] Restore started");
|
|
64
|
+
}
|
|
65
|
+
const result = await restorePurchases();
|
|
66
|
+
if (result.success) {
|
|
67
|
+
if (__DEV__) {
|
|
68
|
+
console.log("[PaywallContainer] Restore successful");
|
|
69
|
+
}
|
|
70
|
+
onPurchaseSuccess?.();
|
|
71
|
+
closePaywall();
|
|
72
|
+
}
|
|
73
|
+
} catch (error) {
|
|
74
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
75
|
+
if (__DEV__) {
|
|
76
|
+
console.error("[PaywallContainer] Restore failed:", message);
|
|
77
|
+
}
|
|
78
|
+
onPurchaseError?.(message);
|
|
79
|
+
}
|
|
80
|
+
}, [restorePurchases, closePaywall, onPurchaseSuccess, onPurchaseError]);
|
|
81
|
+
|
|
82
|
+
if (!showPaywall) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<PaywallModal
|
|
88
|
+
visible={showPaywall}
|
|
89
|
+
onClose={closePaywall}
|
|
90
|
+
mode={mode}
|
|
91
|
+
translations={translations}
|
|
92
|
+
subscriptionPackages={packages}
|
|
93
|
+
isLoading={isLoading}
|
|
94
|
+
legalUrls={legalUrls}
|
|
95
|
+
features={features ? [...features] : undefined}
|
|
96
|
+
heroImage={heroImage}
|
|
97
|
+
bestValueIdentifier={bestValueIdentifier}
|
|
98
|
+
creditsLabel={creditsLabel}
|
|
99
|
+
onSubscriptionPurchase={handlePurchase}
|
|
100
|
+
onRestore={handleRestore}
|
|
101
|
+
/>
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
PaywallContainer.displayName = "PaywallContainer";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PaywallContainer Types
|
|
3
|
+
* Minimal props for package-driven paywall rendering
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { PaywallMode, PaywallTranslations, PaywallLegalUrls, SubscriptionFeature } from "../entities";
|
|
7
|
+
import type { ImageSourcePropType } from "react-native";
|
|
8
|
+
|
|
9
|
+
export interface PaywallContainerProps {
|
|
10
|
+
/** User ID for subscription management */
|
|
11
|
+
readonly userId: string | null;
|
|
12
|
+
/** Paywall translations - no defaults, must be provided */
|
|
13
|
+
readonly translations: PaywallTranslations;
|
|
14
|
+
/** Paywall mode - subscription, credits, or hybrid */
|
|
15
|
+
readonly mode?: PaywallMode;
|
|
16
|
+
/** Legal URLs for privacy and terms */
|
|
17
|
+
readonly legalUrls?: PaywallLegalUrls;
|
|
18
|
+
/** Feature list to display */
|
|
19
|
+
readonly features?: readonly SubscriptionFeature[];
|
|
20
|
+
/** Hero image for paywall header */
|
|
21
|
+
readonly heroImage?: ImageSourcePropType;
|
|
22
|
+
/** Best value package identifier for badge */
|
|
23
|
+
readonly bestValueIdentifier?: string;
|
|
24
|
+
/** Credits label text */
|
|
25
|
+
readonly creditsLabel?: string;
|
|
26
|
+
/** Callback when purchase succeeds */
|
|
27
|
+
readonly onPurchaseSuccess?: () => void;
|
|
28
|
+
/** Callback when purchase fails */
|
|
29
|
+
readonly onPurchaseError?: (error: string) => void;
|
|
30
|
+
}
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
* Paywall Components Index
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
export { PaywallContainer } from "./PaywallContainer";
|
|
6
|
+
export type { PaywallContainerProps } from "./PaywallContainer.types";
|
|
7
|
+
|
|
5
8
|
export { PaywallModal } from "./PaywallModal";
|
|
6
9
|
export type { PaywallModalProps } from "./PaywallModal";
|
|
7
10
|
|
package/src/index.ts
CHANGED
|
@@ -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
|
};
|