@umituz/react-native-ai-generation-content 1.27.12 → 1.27.13
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.27.
|
|
3
|
+
"version": "1.27.13",
|
|
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,138 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* useGateStep Hook
|
|
3
|
-
* Handles auth and credit gate steps in wizard flow
|
|
4
|
-
*
|
|
5
|
-
* Gates are "invisible" steps that:
|
|
6
|
-
* - Auto-advance when condition is met
|
|
7
|
-
* - Show modal/paywall when blocked
|
|
8
|
-
* - Never show UI themselves
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { useEffect, useRef, useCallback } from "react";
|
|
12
|
-
import type { GateResult } from "../../../../../domain/entities/flow-config.types";
|
|
13
|
-
|
|
14
|
-
declare const __DEV__: boolean;
|
|
15
|
-
|
|
16
|
-
export interface GateCallbacks {
|
|
17
|
-
/** Called when auth is required - should show auth modal */
|
|
18
|
-
readonly onAuthRequired?: () => void;
|
|
19
|
-
/** Called when credits are exhausted - should show paywall */
|
|
20
|
-
readonly onCreditsExhausted?: () => void;
|
|
21
|
-
/** Called when gate passes - auto advance to next step */
|
|
22
|
-
readonly onGatePassed?: () => void;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface AuthGateState {
|
|
26
|
-
readonly isAuthenticated: boolean;
|
|
27
|
-
readonly isAnonymous: boolean;
|
|
28
|
-
readonly userId: string | null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface CreditGateState {
|
|
32
|
-
readonly creditBalance: number;
|
|
33
|
-
readonly requiredCredits: number;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface UseGateStepProps {
|
|
37
|
-
readonly gateType: "auth" | "credit";
|
|
38
|
-
readonly authState?: AuthGateState;
|
|
39
|
-
readonly creditState?: CreditGateState;
|
|
40
|
-
readonly callbacks: GateCallbacks;
|
|
41
|
-
readonly allowAnonymous?: boolean;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface UseGateStepReturn {
|
|
45
|
-
readonly gateResult: GateResult;
|
|
46
|
-
readonly checkGate: () => GateResult;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Hook to manage gate step logic
|
|
51
|
-
* Automatically triggers callbacks and advances when conditions are met
|
|
52
|
-
*/
|
|
53
|
-
export function useGateStep(props: UseGateStepProps): UseGateStepReturn {
|
|
54
|
-
const { gateType, authState, creditState, callbacks, allowAnonymous = false } = props;
|
|
55
|
-
|
|
56
|
-
const hasChecked = useRef(false);
|
|
57
|
-
|
|
58
|
-
const checkAuthGate = useCallback((): GateResult => {
|
|
59
|
-
if (!authState) return "pending";
|
|
60
|
-
|
|
61
|
-
const { isAuthenticated, isAnonymous, userId } = authState;
|
|
62
|
-
|
|
63
|
-
// Allow anonymous if configured
|
|
64
|
-
if (allowAnonymous && userId) {
|
|
65
|
-
return "passed";
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Must be authenticated and not anonymous
|
|
69
|
-
if (isAuthenticated && !isAnonymous && userId) {
|
|
70
|
-
return "passed";
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return "blocked";
|
|
74
|
-
}, [authState, allowAnonymous]);
|
|
75
|
-
|
|
76
|
-
const checkCreditGate = useCallback((): GateResult => {
|
|
77
|
-
if (!creditState) return "pending";
|
|
78
|
-
|
|
79
|
-
const { creditBalance, requiredCredits } = creditState;
|
|
80
|
-
|
|
81
|
-
if (creditBalance >= requiredCredits) {
|
|
82
|
-
return "passed";
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return "blocked";
|
|
86
|
-
}, [creditState]);
|
|
87
|
-
|
|
88
|
-
const checkGate = useCallback((): GateResult => {
|
|
89
|
-
if (gateType === "auth") {
|
|
90
|
-
return checkAuthGate();
|
|
91
|
-
}
|
|
92
|
-
return checkCreditGate();
|
|
93
|
-
}, [gateType, checkAuthGate, checkCreditGate]);
|
|
94
|
-
|
|
95
|
-
// Auto-check and trigger callbacks on mount
|
|
96
|
-
useEffect(() => {
|
|
97
|
-
if (hasChecked.current) return;
|
|
98
|
-
|
|
99
|
-
const result = checkGate();
|
|
100
|
-
|
|
101
|
-
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
102
|
-
console.log(`[useGateStep] ${gateType} gate check:`, result);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (result === "passed") {
|
|
106
|
-
hasChecked.current = true;
|
|
107
|
-
callbacks.onGatePassed?.();
|
|
108
|
-
} else if (result === "blocked") {
|
|
109
|
-
hasChecked.current = true;
|
|
110
|
-
if (gateType === "auth") {
|
|
111
|
-
callbacks.onAuthRequired?.();
|
|
112
|
-
} else {
|
|
113
|
-
callbacks.onCreditsExhausted?.();
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}, [gateType, checkGate, callbacks]);
|
|
117
|
-
|
|
118
|
-
// Re-check when auth/credit state changes
|
|
119
|
-
useEffect(() => {
|
|
120
|
-
if (!hasChecked.current) return;
|
|
121
|
-
|
|
122
|
-
const result = checkGate();
|
|
123
|
-
|
|
124
|
-
if (result === "passed") {
|
|
125
|
-
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
126
|
-
console.log(`[useGateStep] ${gateType} gate now passed, advancing...`);
|
|
127
|
-
}
|
|
128
|
-
callbacks.onGatePassed?.();
|
|
129
|
-
}
|
|
130
|
-
}, [authState, creditState, gateType, checkGate, callbacks]);
|
|
131
|
-
|
|
132
|
-
return {
|
|
133
|
-
gateResult: checkGate(),
|
|
134
|
-
checkGate,
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export default useGateStep;
|