@umituz/react-native-ai-generation-content 1.17.94 → 1.17.96
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
package/src/index.ts
CHANGED
|
@@ -216,7 +216,6 @@ export type {
|
|
|
216
216
|
// Feature utils types
|
|
217
217
|
ImageSelector,
|
|
218
218
|
VideoSaver,
|
|
219
|
-
CreditChecker,
|
|
220
219
|
AlertFunction,
|
|
221
220
|
FeatureUtilsConfig,
|
|
222
221
|
// Video helpers types
|
|
@@ -280,6 +279,7 @@ export type {
|
|
|
280
279
|
UseGenerationCallbacksBuilderOptions,
|
|
281
280
|
AIFeatureCallbacksConfig,
|
|
282
281
|
AIFeatureCallbacks,
|
|
282
|
+
AIFeatureGenerationResult,
|
|
283
283
|
} from "./presentation/hooks";
|
|
284
284
|
|
|
285
285
|
// =============================================================================
|
|
@@ -1,85 +1,74 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Feature Utilities
|
|
3
|
-
*
|
|
4
|
-
* App provides implementations via dependency injection
|
|
3
|
+
* Uses ONLY configured app services - no alternatives
|
|
5
4
|
*/
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
* Image selector function type
|
|
9
|
-
*/
|
|
10
|
-
export type ImageSelector = () => Promise<string | null>;
|
|
6
|
+
import { getAuthService, getCreditService, getPaywallService, isAppServicesConfigured } from "../config/app-services.config";
|
|
11
7
|
|
|
12
|
-
|
|
13
|
-
* Video saver function type
|
|
14
|
-
*/
|
|
15
|
-
export type VideoSaver = (uri: string) => Promise<void>;
|
|
8
|
+
declare const __DEV__: boolean;
|
|
16
9
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*/
|
|
20
|
-
export type CreditChecker = (cost: number, featureName: string, type: string) => Promise<boolean>;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Alert function type
|
|
24
|
-
*/
|
|
10
|
+
export type ImageSelector = () => Promise<string | null>;
|
|
11
|
+
export type VideoSaver = (uri: string) => Promise<void>;
|
|
25
12
|
export type AlertFunction = (title: string, message: string) => void;
|
|
26
13
|
|
|
27
|
-
/**
|
|
28
|
-
* Feature utilities configuration
|
|
29
|
-
*/
|
|
30
14
|
export interface FeatureUtilsConfig {
|
|
31
15
|
selectImage: ImageSelector;
|
|
32
16
|
saveVideo: VideoSaver;
|
|
33
|
-
checkCredit: CreditChecker;
|
|
34
|
-
showSuccessAlert?: AlertFunction;
|
|
35
|
-
showErrorAlert?: AlertFunction;
|
|
36
17
|
}
|
|
37
18
|
|
|
38
|
-
/**
|
|
39
|
-
* Prepare image from URI (generic passthrough)
|
|
40
|
-
*/
|
|
41
19
|
export async function prepareImage(uri: string): Promise<string> {
|
|
42
20
|
return uri;
|
|
43
21
|
}
|
|
44
22
|
|
|
45
|
-
/**
|
|
46
|
-
* Create dev callbacks for logging
|
|
47
|
-
*/
|
|
48
23
|
export function createDevCallbacks(featureName: string) {
|
|
49
24
|
return {
|
|
50
25
|
onSuccess: (result: unknown) => {
|
|
51
|
-
if (
|
|
52
|
-
// eslint-disable-next-line no-console
|
|
53
|
-
console.log(`[${featureName}] Success:`, result);
|
|
54
|
-
}
|
|
26
|
+
if (__DEV__) console.log(`[${featureName}] Success:`, result);
|
|
55
27
|
},
|
|
56
28
|
onError: (error: unknown) => {
|
|
57
|
-
if (
|
|
58
|
-
// eslint-disable-next-line no-console
|
|
59
|
-
console.error(`[${featureName}] Error:`, error);
|
|
60
|
-
}
|
|
29
|
+
if (__DEV__) console.error(`[${featureName}] Error:`, error);
|
|
61
30
|
},
|
|
62
31
|
};
|
|
63
32
|
}
|
|
64
33
|
|
|
65
34
|
/**
|
|
66
|
-
*
|
|
35
|
+
* Credit guard - ONLY uses configured app services
|
|
67
36
|
*/
|
|
37
|
+
async function checkCreditGuard(cost: number, featureName: string): Promise<boolean> {
|
|
38
|
+
if (!isAppServicesConfigured()) {
|
|
39
|
+
throw new Error(`[${featureName}] App services not configured. Call configureAppServices() at startup.`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const authService = getAuthService();
|
|
43
|
+
const creditService = getCreditService();
|
|
44
|
+
const paywallService = getPaywallService();
|
|
45
|
+
|
|
46
|
+
if (!authService.isAuthenticated()) {
|
|
47
|
+
if (__DEV__) console.log(`[${featureName}] Auth required`);
|
|
48
|
+
try {
|
|
49
|
+
authService.requireAuth();
|
|
50
|
+
} catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const hasCredits = await creditService.checkCredits(cost);
|
|
57
|
+
if (!hasCredits) {
|
|
58
|
+
if (__DEV__) console.log(`[${featureName}] Insufficient credits`);
|
|
59
|
+
paywallService.showPaywall(cost);
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
68
66
|
export function createFeatureUtils(config: FeatureUtilsConfig) {
|
|
69
67
|
return {
|
|
70
68
|
selectImage: config.selectImage,
|
|
71
69
|
saveVideo: config.saveVideo,
|
|
72
|
-
checkCreditGuard
|
|
70
|
+
checkCreditGuard,
|
|
73
71
|
prepareImage,
|
|
74
72
|
createDevCallbacks,
|
|
75
73
|
};
|
|
76
74
|
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Hook factory for feature utilities
|
|
80
|
-
*/
|
|
81
|
-
export function createUseFeatureUtils(config: FeatureUtilsConfig) {
|
|
82
|
-
return function useFeatureUtils() {
|
|
83
|
-
return createFeatureUtils(config);
|
|
84
|
-
};
|
|
85
|
-
}
|
|
@@ -34,16 +34,19 @@ export interface AIFeatureCallbacksConfig<TRequest = unknown, TResult = unknown>
|
|
|
34
34
|
onError?: (error: string) => void;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Discriminated union result type for generation
|
|
39
|
+
*/
|
|
40
|
+
export type AIFeatureGenerationResult =
|
|
41
|
+
| { success: true; imageUrls: string[] }
|
|
42
|
+
| { success: false; error: string };
|
|
43
|
+
|
|
37
44
|
/**
|
|
38
45
|
* Universal callbacks interface that maps to all feature-specific ones
|
|
39
46
|
*/
|
|
40
47
|
export interface AIFeatureCallbacks<TRequest = unknown, TResult = unknown> {
|
|
41
48
|
// TextToImageCallbacks compatible
|
|
42
|
-
executeGeneration: (request: TRequest) => Promise<
|
|
43
|
-
success: boolean;
|
|
44
|
-
imageUrls?: string[];
|
|
45
|
-
error?: string;
|
|
46
|
-
}>;
|
|
49
|
+
executeGeneration: (request: TRequest) => Promise<AIFeatureGenerationResult>;
|
|
47
50
|
calculateCost: (multiplier?: number, _model?: string | null) => number;
|
|
48
51
|
canAfford: (cost: number) => boolean;
|
|
49
52
|
isAuthenticated: () => boolean;
|
|
@@ -103,7 +106,7 @@ export function useAIFeatureCallbacks<TRequest = unknown, TResult = unknown>(
|
|
|
103
106
|
);
|
|
104
107
|
|
|
105
108
|
const executeGeneration = useCallback(
|
|
106
|
-
async (request: TRequest) => {
|
|
109
|
+
async (request: TRequest): Promise<AIFeatureGenerationResult> => {
|
|
107
110
|
try {
|
|
108
111
|
const result = await executor(request);
|
|
109
112
|
|
|
@@ -117,11 +120,10 @@ export function useAIFeatureCallbacks<TRequest = unknown, TResult = unknown>(
|
|
|
117
120
|
onError?.(result.error);
|
|
118
121
|
}
|
|
119
122
|
|
|
120
|
-
|
|
121
|
-
success: result.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
};
|
|
123
|
+
if (result.success) {
|
|
124
|
+
return { success: true, imageUrls: result.imageUrls ?? [] };
|
|
125
|
+
}
|
|
126
|
+
return { success: false, error: result.error ?? "Unknown error" };
|
|
125
127
|
} catch (error) {
|
|
126
128
|
const message = error instanceof Error ? error.message : String(error);
|
|
127
129
|
onError?.(message);
|