@umituz/react-native-subscription 2.14.3 → 2.14.4
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/PaywallModal.tsx +1 -1
- package/src/domains/paywall/hooks/useSubscriptionModal.ts +2 -2
- package/src/index.ts +5 -0
- package/src/infrastructure/services/SubscriptionInitializer.ts +79 -0
- package/src/presentation/hooks/useCreditChecker.ts +1 -1
- package/src/revenuecat/infrastructure/services/RevenueCatInitializer.ts +1 -1
- package/src/utils/__tests__/validation.test.ts +0 -1
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.4",
|
|
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",
|
|
@@ -23,7 +23,7 @@ export const useSubscriptionModal = ({
|
|
|
23
23
|
} finally {
|
|
24
24
|
setIsProcessing(false);
|
|
25
25
|
}
|
|
26
|
-
}, [selectedPkg, onPurchase, onClose]);
|
|
26
|
+
}, [selectedPkg, onPurchase, onClose, isProcessing]);
|
|
27
27
|
|
|
28
28
|
const handleRestore = useCallback(async () => {
|
|
29
29
|
if (isProcessing) return;
|
|
@@ -33,7 +33,7 @@ export const useSubscriptionModal = ({
|
|
|
33
33
|
} finally {
|
|
34
34
|
setIsProcessing(false);
|
|
35
35
|
}
|
|
36
|
-
}, [onRestore, onClose]);
|
|
36
|
+
}, [onRestore, onClose, isProcessing]);
|
|
37
37
|
|
|
38
38
|
return {
|
|
39
39
|
selectedPkg,
|
package/src/index.ts
CHANGED
|
@@ -28,6 +28,11 @@ export {
|
|
|
28
28
|
initializeSubscriptionService,
|
|
29
29
|
} from "./infrastructure/services/SubscriptionService";
|
|
30
30
|
|
|
31
|
+
export {
|
|
32
|
+
initializeSubscription,
|
|
33
|
+
type SubscriptionInitConfig,
|
|
34
|
+
} from "./infrastructure/services/SubscriptionInitializer";
|
|
35
|
+
|
|
31
36
|
export { useSubscription } from "./presentation/hooks/useSubscription";
|
|
32
37
|
export type { UseSubscriptionResult } from "./presentation/hooks/useSubscription";
|
|
33
38
|
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subscription Initializer
|
|
3
|
+
* Single entry point for subscription system initialization
|
|
4
|
+
* Apps just call initializeSubscription with config
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { CreditsConfig } from "../../domain/entities/Credits";
|
|
8
|
+
import { configureCreditsRepository } from "../repositories/CreditsRepositoryProvider";
|
|
9
|
+
import { SubscriptionManager } from "../../revenuecat/infrastructure/managers/SubscriptionManager";
|
|
10
|
+
import { configureAuthProvider } from "../../presentation/hooks/useAuthAwarePurchase";
|
|
11
|
+
|
|
12
|
+
export interface SubscriptionInitConfig {
|
|
13
|
+
apiKey: string;
|
|
14
|
+
entitlementId: string;
|
|
15
|
+
credits: CreditsConfig;
|
|
16
|
+
getAnonymousUserId: () => Promise<string>;
|
|
17
|
+
getFirebaseAuth: () => { currentUser: { isAnonymous: boolean } | null } | null;
|
|
18
|
+
showAuthModal: () => void;
|
|
19
|
+
onCreditsUpdated?: (userId: string) => void;
|
|
20
|
+
onCreditRenewal?: (userId: string, productId: string, renewalId: string) => Promise<void>;
|
|
21
|
+
timeoutMs?: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const initializeSubscription = async (
|
|
25
|
+
config: SubscriptionInitConfig,
|
|
26
|
+
): Promise<void> => {
|
|
27
|
+
const {
|
|
28
|
+
apiKey,
|
|
29
|
+
entitlementId,
|
|
30
|
+
credits,
|
|
31
|
+
getAnonymousUserId,
|
|
32
|
+
getFirebaseAuth,
|
|
33
|
+
showAuthModal,
|
|
34
|
+
onCreditsUpdated,
|
|
35
|
+
onCreditRenewal,
|
|
36
|
+
timeoutMs = 10000,
|
|
37
|
+
} = config;
|
|
38
|
+
|
|
39
|
+
if (!apiKey) {
|
|
40
|
+
throw new Error("RevenueCat API key is required");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
configureCreditsRepository(credits);
|
|
44
|
+
|
|
45
|
+
SubscriptionManager.configure({
|
|
46
|
+
config: {
|
|
47
|
+
apiKey,
|
|
48
|
+
entitlementIdentifier: entitlementId,
|
|
49
|
+
onCreditRenewal,
|
|
50
|
+
onCreditsUpdated,
|
|
51
|
+
},
|
|
52
|
+
apiKey,
|
|
53
|
+
getAnonymousUserId,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const initPromise = SubscriptionManager.initialize();
|
|
57
|
+
const timeoutPromise = new Promise<boolean>((_, reject) =>
|
|
58
|
+
setTimeout(
|
|
59
|
+
() => reject(new Error("Subscription initialization timeout")),
|
|
60
|
+
timeoutMs,
|
|
61
|
+
),
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
await Promise.race([initPromise, timeoutPromise]);
|
|
65
|
+
|
|
66
|
+
configureAuthProvider({
|
|
67
|
+
isAuthenticated: () => {
|
|
68
|
+
const auth = getFirebaseAuth();
|
|
69
|
+
const user = auth?.currentUser;
|
|
70
|
+
return !!(user && !user.isAnonymous);
|
|
71
|
+
},
|
|
72
|
+
showAuthModal,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
if (__DEV__) {
|
|
76
|
+
|
|
77
|
+
console.log("[Subscription] Initialized successfully");
|
|
78
|
+
}
|
|
79
|
+
};
|
|
@@ -83,7 +83,7 @@ export async function initializeSDK(
|
|
|
83
83
|
const hasPremium = !!customerInfo.entitlements.active[entitlementId];
|
|
84
84
|
|
|
85
85
|
return { success: true, offering: offerings.current, hasPremium };
|
|
86
|
-
} catch
|
|
86
|
+
} catch {
|
|
87
87
|
// If logIn fails, we don't necessarily want to re-configure if it's already configured
|
|
88
88
|
// But we can return failure
|
|
89
89
|
return { success: false, offering: null, hasPremium: false };
|