@umituz/react-native-ai-generation-content 1.61.60 → 1.61.62
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-ai-generation-content",
|
|
3
|
-
"version": "1.61.
|
|
3
|
+
"version": "1.61.62",
|
|
4
4
|
"description": "Provider-agnostic AI generation orchestration for React Native with result preview components",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -1,21 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* Single hook that handles:
|
|
6
|
-
* 1. Authentication check
|
|
7
|
-
* 2. Premium subscription check
|
|
8
|
-
* 3. Credit balance check
|
|
9
|
-
* 4. Paywall display
|
|
10
|
-
*
|
|
11
|
-
* Usage:
|
|
12
|
-
* ```typescript
|
|
13
|
-
* const { requireFeature } = useAIFeatureGate({ creditCost: 1 });
|
|
14
|
-
*
|
|
15
|
-
* <AtomicButton onPress={() => requireFeature(handleGenerate)}>
|
|
16
|
-
* Generate
|
|
17
|
-
* </AtomicButton>
|
|
18
|
-
* ```
|
|
2
|
+
* AI Feature Gate Hook
|
|
3
|
+
* Handles: Auth → Credits → Paywall → Execute
|
|
19
4
|
*/
|
|
20
5
|
|
|
21
6
|
import { useCallback, useMemo } from "react";
|
|
@@ -32,80 +17,64 @@ import type {
|
|
|
32
17
|
AIFeatureGateReturn,
|
|
33
18
|
} from "../types/access-control.types";
|
|
34
19
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
20
|
+
const handlePromiseResult = (
|
|
21
|
+
result: void | Promise<void>,
|
|
22
|
+
onSuccess?: () => void,
|
|
23
|
+
onError?: (error: Error) => void,
|
|
24
|
+
): void => {
|
|
25
|
+
if (result instanceof Promise) {
|
|
26
|
+
result
|
|
27
|
+
.then(() => onSuccess?.())
|
|
28
|
+
.catch((err) => onError?.(err instanceof Error ? err : new Error(String(err))));
|
|
29
|
+
} else {
|
|
30
|
+
onSuccess?.();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export function useAIFeatureGate(options: AIFeatureGateOptions): AIFeatureGateReturn {
|
|
45
35
|
const { creditCost, onNetworkError, onSuccess, onError } = options;
|
|
46
36
|
|
|
47
|
-
// Network state
|
|
48
37
|
const { isOffline } = useOffline();
|
|
49
|
-
|
|
50
|
-
// Auth state
|
|
51
|
-
const { isAuthenticated: rawIsAuthenticated, isAnonymous } = useAuth();
|
|
38
|
+
const { isAuthenticated: rawIsAuth, isAnonymous } = useAuth();
|
|
52
39
|
const { showAuthModal } = useAuthModalStore();
|
|
53
|
-
|
|
54
|
-
// Subscription state
|
|
55
40
|
const { isPremium } = usePremium();
|
|
56
41
|
const { credits, isLoading: isCreditsLoading } = useCredits();
|
|
57
42
|
const { openPaywall } = usePaywallVisibility();
|
|
58
43
|
|
|
59
|
-
|
|
44
|
+
const isAuthenticated = rawIsAuth && !isAnonymous;
|
|
60
45
|
const isCreditsLoaded = !isCreditsLoading;
|
|
61
|
-
const isAuthenticated = rawIsAuthenticated && !isAnonymous;
|
|
62
46
|
const creditBalance = credits?.credits ?? 0;
|
|
63
47
|
const hasCredits = creditBalance >= creditCost;
|
|
64
48
|
|
|
65
|
-
// Configure feature gate from subscription package
|
|
66
49
|
const { requireFeature: requireFeatureFromPackage } = useFeatureGate({
|
|
67
50
|
isAuthenticated,
|
|
68
51
|
onShowAuthModal: (cb?: () => void) => showAuthModal(cb),
|
|
69
52
|
hasSubscription: isPremium,
|
|
70
53
|
creditBalance,
|
|
71
54
|
requiredCredits: creditCost,
|
|
72
|
-
onShowPaywall:
|
|
55
|
+
onShowPaywall: openPaywall,
|
|
73
56
|
isCreditsLoaded,
|
|
74
57
|
});
|
|
75
58
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (isPremium) return true;
|
|
81
|
-
return hasCredits;
|
|
82
|
-
}, [isOffline, isAuthenticated, isPremium, hasCredits]);
|
|
59
|
+
const canAccess = useMemo(
|
|
60
|
+
() => !isOffline && isAuthenticated && (isPremium || hasCredits),
|
|
61
|
+
[isOffline, isAuthenticated, isPremium, hasCredits],
|
|
62
|
+
);
|
|
83
63
|
|
|
84
|
-
// Wrapped requireFeature with offline check and optional callbacks
|
|
85
64
|
const requireFeature = useCallback(
|
|
86
65
|
(action: () => void | Promise<void>): void => {
|
|
87
|
-
// Network check first - must be online
|
|
88
66
|
if (isOffline) {
|
|
89
67
|
onNetworkError?.();
|
|
90
68
|
return;
|
|
91
69
|
}
|
|
92
|
-
|
|
70
|
+
|
|
71
|
+
if (!isCreditsLoaded) return;
|
|
72
|
+
|
|
93
73
|
requireFeatureFromPackage(() => {
|
|
94
|
-
|
|
95
|
-
if (result instanceof Promise) {
|
|
96
|
-
result
|
|
97
|
-
.then(() => onSuccess?.())
|
|
98
|
-
.catch((error) => {
|
|
99
|
-
const errorObj =
|
|
100
|
-
error instanceof Error ? error : new Error(String(error));
|
|
101
|
-
onError?.(errorObj);
|
|
102
|
-
});
|
|
103
|
-
} else {
|
|
104
|
-
onSuccess?.();
|
|
105
|
-
}
|
|
74
|
+
handlePromiseResult(action(), onSuccess, onError);
|
|
106
75
|
});
|
|
107
76
|
},
|
|
108
|
-
[isOffline, onNetworkError, requireFeatureFromPackage, onSuccess, onError],
|
|
77
|
+
[isOffline, isCreditsLoaded, onNetworkError, requireFeatureFromPackage, onSuccess, onError],
|
|
109
78
|
);
|
|
110
79
|
|
|
111
80
|
return {
|