@umituz/react-native-ai-generation-content 1.17.306 → 1.17.307

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.17.306",
3
+ "version": "1.17.307",
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",
@@ -43,6 +43,7 @@
43
43
  "peerDependencies": {
44
44
  "@react-navigation/native": ">=6.0.0",
45
45
  "@tanstack/react-query": ">=5.0.0",
46
+ "@umituz/react-native-subscription": ">=2.23.0",
46
47
  "@umituz/react-native-video-editor": ">=1.0.0",
47
48
  "firebase": ">=10.0.0",
48
49
  "react": ">=18.0.0",
@@ -67,6 +68,7 @@
67
68
  "@umituz/react-native-design-system": "*",
68
69
  "@umituz/react-native-firebase": "*",
69
70
  "@umituz/react-native-localization": "*",
71
+ "@umituz/react-native-subscription": "*",
70
72
  "eslint": "^9.0.0",
71
73
  "expo-apple-authentication": "^8.0.8",
72
74
  "expo-application": "^7.0.8",
@@ -1,19 +1,25 @@
1
1
  import { useCallback } from "react";
2
+ import { useDeductCredit } from "@umituz/react-native-subscription";
2
3
  import { usePhotoGeneration } from "../../../../presentation/hooks/usePhotoGeneration";
3
4
  import { executeCoupleFuture } from "../../infrastructure/executor";
4
5
  import type { CoupleFutureInput } from "../../domain/types";
5
- import type { PhotoGenerationConfig, PhotoGenerationError } from "../../../../presentation/hooks/photo-generation.types";
6
+ import type {
7
+ PhotoGenerationConfig,
8
+ PhotoGenerationError,
9
+ } from "../../../../presentation/hooks/photo-generation.types";
6
10
  import { createCreationsRepository } from "../../../../domains/creations/infrastructure/adapters";
7
11
  import type { Creation } from "../../../../domains/creations/domain/entities/Creation";
8
12
 
9
- export interface UseCoupleFutureGenerationConfig<TInput extends CoupleFutureInput, TResult> {
13
+ export interface UseCoupleFutureGenerationConfig<
14
+ TInput extends CoupleFutureInput,
15
+ TResult,
16
+ > {
10
17
  userId: string | undefined;
11
- processResult: (imageUrl: string, input: TInput) => Promise<TResult> | TResult;
18
+ processResult: (
19
+ imageUrl: string,
20
+ input: TInput,
21
+ ) => Promise<TResult> | TResult;
12
22
  buildCreation?: (result: TResult, input: TInput) => Creation | null;
13
- /** Check credits BEFORE generation starts - critical for security */
14
- checkCredits?: () => Promise<boolean>;
15
- /** Deduct credits AFTER successful generation */
16
- deductCredits?: () => Promise<void>;
17
23
  onSuccess?: (result: TResult) => void;
18
24
  onError?: (error: string) => void;
19
25
  alertMessages: {
@@ -25,21 +31,26 @@ export interface UseCoupleFutureGenerationConfig<TInput extends CoupleFutureInpu
25
31
  };
26
32
  }
27
33
 
28
- export const useCoupleFutureGeneration = <TInput extends CoupleFutureInput, TResult>(
29
- config: UseCoupleFutureGenerationConfig<TInput, TResult>
34
+ export const useCoupleFutureGeneration = <
35
+ TInput extends CoupleFutureInput,
36
+ TResult,
37
+ >(
38
+ config: UseCoupleFutureGenerationConfig<TInput, TResult>,
30
39
  ) => {
31
40
  const {
32
41
  userId,
33
42
  processResult,
34
43
  buildCreation,
35
- checkCredits,
36
- deductCredits,
37
44
  onSuccess,
38
45
  onError,
39
46
  alertMessages,
40
47
  } = config;
41
48
 
42
- const repository = useCallback(() => createCreationsRepository("creations"), []);
49
+ const { checkCredits, deductCredit } = useDeductCredit({ userId });
50
+ const repository = useCallback(
51
+ () => createCreationsRepository("creations"),
52
+ [],
53
+ );
43
54
 
44
55
  const generationConfig: PhotoGenerationConfig<TInput, TResult, void> = {
45
56
  generate: async (input: TInput, onProgress?: (progress: number) => void) => {
@@ -49,7 +60,7 @@ export const useCoupleFutureGeneration = <TInput extends CoupleFutureInput, TRes
49
60
  partnerBBase64: input.partnerBBase64,
50
61
  prompt: input.prompt,
51
62
  },
52
- { onProgress }
63
+ { onProgress },
53
64
  );
54
65
 
55
66
  if (!result.success || !result.imageUrl) {
@@ -69,8 +80,8 @@ export const useCoupleFutureGeneration = <TInput extends CoupleFutureInput, TRes
69
80
  }
70
81
  },
71
82
 
72
- checkCredits,
73
- deductCredits,
83
+ checkCredits: () => checkCredits(1),
84
+ deductCredits: () => deductCredit(1).then(() => {}),
74
85
  onSuccess,
75
86
  onError: (error: PhotoGenerationError) => {
76
87
  onError?.(error.message);