@umituz/react-native-ai-generation-content 1.17.305 → 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.305",
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,16 +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
- deductCredits?: () => Promise<void>;
14
23
  onSuccess?: (result: TResult) => void;
15
24
  onError?: (error: string) => void;
16
25
  alertMessages: {
@@ -22,20 +31,26 @@ export interface UseCoupleFutureGenerationConfig<TInput extends CoupleFutureInpu
22
31
  };
23
32
  }
24
33
 
25
- export const useCoupleFutureGeneration = <TInput extends CoupleFutureInput, TResult>(
26
- config: UseCoupleFutureGenerationConfig<TInput, TResult>
34
+ export const useCoupleFutureGeneration = <
35
+ TInput extends CoupleFutureInput,
36
+ TResult,
37
+ >(
38
+ config: UseCoupleFutureGenerationConfig<TInput, TResult>,
27
39
  ) => {
28
40
  const {
29
41
  userId,
30
42
  processResult,
31
43
  buildCreation,
32
- deductCredits,
33
44
  onSuccess,
34
45
  onError,
35
46
  alertMessages,
36
47
  } = config;
37
48
 
38
- const repository = useCallback(() => createCreationsRepository("creations"), []);
49
+ const { checkCredits, deductCredit } = useDeductCredit({ userId });
50
+ const repository = useCallback(
51
+ () => createCreationsRepository("creations"),
52
+ [],
53
+ );
39
54
 
40
55
  const generationConfig: PhotoGenerationConfig<TInput, TResult, void> = {
41
56
  generate: async (input: TInput, onProgress?: (progress: number) => void) => {
@@ -45,7 +60,7 @@ export const useCoupleFutureGeneration = <TInput extends CoupleFutureInput, TRes
45
60
  partnerBBase64: input.partnerBBase64,
46
61
  prompt: input.prompt,
47
62
  },
48
- { onProgress }
63
+ { onProgress },
49
64
  );
50
65
 
51
66
  if (!result.success || !result.imageUrl) {
@@ -65,7 +80,8 @@ export const useCoupleFutureGeneration = <TInput extends CoupleFutureInput, TRes
65
80
  }
66
81
  },
67
82
 
68
- deductCredits,
83
+ checkCredits: () => checkCredits(1),
84
+ deductCredits: () => deductCredit(1).then(() => {}),
69
85
  onSuccess,
70
86
  onError: (error: PhotoGenerationError) => {
71
87
  onError?.(error.message);