@umituz/react-native-ai-generation-content 1.83.46 → 1.83.48

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.83.46",
3
+ "version": "1.83.48",
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",
@@ -49,6 +49,7 @@ export const CREATION_FIELDS = {
49
49
  // AI provider metadata
50
50
  REQUEST_ID: "requestId" as const,
51
51
  MODEL: "model" as const,
52
+ PROVIDER: "provider" as const,
52
53
  } as const;
53
54
 
54
55
  /** Union type of all field names */
@@ -25,8 +25,8 @@ export interface Creation {
25
25
  readonly uri: string;
26
26
  readonly type: string;
27
27
  readonly prompt?: string;
28
+ readonly provider?: string;
28
29
  readonly metadata?: Record<string, unknown>;
29
- readonly originalUri?: string;
30
30
  readonly createdAt: Date;
31
31
  readonly isShared: boolean;
32
32
  readonly isFavorite: boolean;
@@ -53,12 +53,8 @@ interface FirebaseTimestamp {
53
53
  export interface CreationDocument {
54
54
  readonly uri?: string;
55
55
  readonly prompt?: string;
56
+ readonly provider?: string;
56
57
  readonly metadata?: Record<string, unknown>;
57
- readonly originalImage?: string;
58
- readonly originalImageUrl?: string;
59
- readonly transformedImage?: string;
60
- readonly transformedImageUrl?: string;
61
- readonly transformationType?: string;
62
58
  readonly type?: string;
63
59
  readonly status?: string;
64
60
  readonly output?: CreationOutput | null;
@@ -92,21 +88,15 @@ export function mapDocumentToCreation(
92
88
  ): Creation {
93
89
  const creationDate = toDate(data.createdAt) ?? new Date();
94
90
 
95
- // Get URI from output or direct fields
96
- const uri = data.output?.imageUrl ||
97
- data.output?.videoUrl ||
98
- data.transformedImageUrl ||
99
- data.transformedImage ||
100
- data.uri ||
101
- "";
91
+ const uri = data.output?.imageUrl || data.output?.videoUrl || data.uri || "";
102
92
 
103
93
  return {
104
94
  id,
105
95
  uri,
106
- type: data.transformationType || data.type || "unknown",
96
+ type: data.type || "unknown",
107
97
  prompt: data.prompt,
98
+ provider: data.provider,
108
99
  metadata: data.metadata,
109
- originalUri: data.originalImageUrl || data.originalImage,
110
100
  createdAt: creationDate,
111
101
  isShared: data.isShared ?? false,
112
102
  isFavorite: data.isFavorite ?? false,
@@ -25,6 +25,7 @@ export async function createCreation(
25
25
  ...(creation.status !== undefined && { status: creation.status }),
26
26
  ...(creation.output !== undefined && { output: creation.output }),
27
27
  ...(creation.prompt !== undefined && { prompt: creation.prompt }),
28
+ ...(creation.provider !== undefined && { provider: creation.provider }),
28
29
  ...(creation.requestId !== undefined && { requestId: creation.requestId }),
29
30
  ...(creation.model !== undefined && { model: creation.model }),
30
31
  ...(creation.startedAt !== undefined && { startedAt: creation.startedAt }),
@@ -25,6 +25,7 @@ export async function saveAsProcessing(
25
25
  uri: "",
26
26
  type: data.scenarioId,
27
27
  prompt: data.prompt,
28
+ provider: data.provider,
28
29
  status: "processing" as const,
29
30
  createdAt: new Date(),
30
31
  startedAt,
@@ -39,7 +40,6 @@ export async function saveAsProcessing(
39
40
  ...(data.resolution && { resolution: data.resolution }),
40
41
  ...(data.creditCost && { creditCost: data.creditCost }),
41
42
  ...(data.aspectRatio && { aspectRatio: data.aspectRatio }),
42
- ...(data.provider && { provider: data.provider }),
43
43
  ...(data.outputType && { outputType: data.outputType }),
44
44
  },
45
45
  });
@@ -4,6 +4,7 @@
4
4
  */
5
5
 
6
6
  import type { ICreationsRepository } from "../../../../creations/domain/repositories";
7
+ import type { Creation, CreationOutput } from "../../../../creations/domain/entities/Creation";
7
8
  import type { CompletedCreationData } from "./creation-persistence.types";
8
9
 
9
10
 
@@ -16,10 +17,11 @@ export async function updateToCompleted(
16
17
  creationId: string,
17
18
  data: CompletedCreationData
18
19
  ): Promise<void> {
19
- const output: { imageUrl?: string; videoUrl?: string; thumbnailUrl?: string } = {};
20
- if (data.imageUrl) output.imageUrl = data.imageUrl;
21
- if (data.videoUrl) output.videoUrl = data.videoUrl;
22
- if (data.thumbnailUrl) output.thumbnailUrl = data.thumbnailUrl;
20
+ const output: CreationOutput = {
21
+ ...(data.imageUrl && { imageUrl: data.imageUrl }),
22
+ ...(data.videoUrl && { videoUrl: data.videoUrl }),
23
+ ...(data.thumbnailUrl && { thumbnailUrl: data.thumbnailUrl }),
24
+ };
23
25
 
24
26
  const completedAt = new Date();
25
27
  const durationMs =
@@ -33,7 +35,7 @@ export async function updateToCompleted(
33
35
  output,
34
36
  completedAt,
35
37
  ...(durationMs !== undefined && { durationMs }),
36
- } as Partial<import("../../../../creations/domain/entities/Creation").Creation>);
38
+ } as Partial<Creation>);
37
39
 
38
40
  if (typeof __DEV__ !== "undefined" && __DEV__) {
39
41
  console.log("[CreationPersistence] Updated to completed", { creationId });
@@ -53,7 +55,7 @@ export async function updateToFailed(
53
55
  status: "failed" as const,
54
56
  metadata: { error },
55
57
  completedAt: new Date(),
56
- } as Partial<import("../../../../creations/domain/entities/Creation").Creation>);
58
+ } as Partial<Creation>);
57
59
 
58
60
  if (typeof __DEV__ !== "undefined" && __DEV__) {
59
61
  console.log("[CreationPersistence] Updated to failed", { creationId, error });
@@ -32,6 +32,8 @@ export interface GenericWizardFlowProps {
32
32
  readonly creditCost: number;
33
33
  /** Calculator function provided by APP - package calls this to get dynamic cost */
34
34
  readonly calculateCredits?: CreditCalculatorFn;
35
+ /** Called after successful generation to deduct credits — provided by the app */
36
+ readonly deductCredits?: (cost: number) => Promise<boolean>;
35
37
  readonly skipResultStep?: boolean;
36
38
  readonly onStepChange?: (stepId: string, stepType: StepType | string) => void;
37
39
  readonly onGenerationStart?: (
@@ -61,6 +63,7 @@ export const GenericWizardFlow: React.FC<GenericWizardFlowProps> = (props) => {
61
63
  alertMessages,
62
64
  creditCost,
63
65
  calculateCredits,
66
+ deductCredits,
64
67
  skipResultStep = false,
65
68
  onStepChange,
66
69
  onGenerationStart,
@@ -119,6 +122,7 @@ export const GenericWizardFlow: React.FC<GenericWizardFlowProps> = (props) => {
119
122
  alertMessages={alertMessages}
120
123
  creditCost={creditCost}
121
124
  calculateCredits={calculateCredits}
125
+ deductCredits={deductCredits}
122
126
  skipResultStep={skipResultStep}
123
127
  onStepChange={onStepChange}
124
128
  onGenerationStart={onGenerationStart}
@@ -34,6 +34,8 @@ interface WizardFlowContentProps {
34
34
  readonly creditCost: number;
35
35
  /** Calculator function provided by APP - package calls this to get dynamic cost */
36
36
  readonly calculateCredits?: CreditCalculatorFn;
37
+ /** Called after successful generation to deduct credits — provided by the app */
38
+ readonly deductCredits?: (cost: number) => Promise<boolean>;
37
39
  readonly skipResultStep?: boolean;
38
40
  readonly onStepChange?: (stepId: string, stepType: StepType | string) => void;
39
41
  readonly onGenerationStart?: (
@@ -60,8 +62,9 @@ export const WizardFlowContent: React.FC<WizardFlowContentProps> = (props) => {
60
62
  modelConfig,
61
63
  userId,
62
64
  alertMessages,
63
- creditCost, // Still needed for initial feature gate in parent
64
- calculateCredits, // Calculator function from APP
65
+ creditCost,
66
+ calculateCredits,
67
+ deductCredits,
65
68
  skipResultStep = false,
66
69
  onStepChange,
67
70
  onGenerationStart,
@@ -188,6 +191,7 @@ export const WizardFlowContent: React.FC<WizardFlowContentProps> = (props) => {
188
191
  isGeneratingStep: currentStep?.type === StepType.GENERATING,
189
192
  alertMessages,
190
193
  creditCost: calculatedCreditCost,
194
+ deductCredits,
191
195
  onSuccess: handlers.handleGenerationComplete,
192
196
  onError: handlers.handleGenerationError,
193
197
  onCreditsExhausted,
@@ -12,6 +12,7 @@ export interface UseVideoQueueGenerationProps {
12
12
  readonly persistence: CreationPersistence;
13
13
  readonly strategy: WizardStrategy;
14
14
  readonly creditCost?: number;
15
+ readonly deductCredits?: (cost: number) => Promise<boolean>;
15
16
  readonly onSuccess?: (result: unknown) => void;
16
17
  readonly onError?: (error: string) => void;
17
18
  }
@@ -20,6 +20,7 @@ interface UsePhotoBlockingGenerationProps {
20
20
  readonly persistence: CreationPersistence;
21
21
  readonly strategy: WizardStrategy;
22
22
  readonly creditCost?: number;
23
+ readonly deductCredits?: (cost: number) => Promise<boolean>;
23
24
  readonly alertMessages: AlertMessages;
24
25
  readonly onSuccess?: (result: unknown) => void;
25
26
  readonly onError?: (error: string) => void;
@@ -39,6 +40,7 @@ export function usePhotoBlockingGeneration(
39
40
  scenario,
40
41
  persistence,
41
42
  creditCost,
43
+ deductCredits,
42
44
  strategy,
43
45
  alertMessages,
44
46
  onSuccess,
@@ -67,9 +69,19 @@ export function usePhotoBlockingGeneration(
67
69
  }
68
70
 
69
71
  creationIdRef.current = null;
72
+
73
+ // Deduct credits after successful generation
74
+ if (deductCredits && creditCost) {
75
+ await deductCredits(creditCost).catch((err) => {
76
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
77
+ console.error("[PhotoBlockingGeneration] deductCredits error:", err);
78
+ }
79
+ });
80
+ }
81
+
70
82
  onSuccess?.(result);
71
83
  },
72
- [userId, persistence, onSuccess],
84
+ [userId, persistence, deductCredits, creditCost, onSuccess],
73
85
  );
74
86
 
75
87
  const handleError = useCallback(
@@ -16,7 +16,7 @@ import type {
16
16
  } from "./use-video-queue-generation.types";
17
17
 
18
18
  export function useVideoQueueGeneration(props: UseVideoQueueGenerationProps): UseVideoQueueGenerationReturn {
19
- const { userId, scenario, persistence, strategy, creditCost, onSuccess, onError } = props;
19
+ const { userId, scenario, persistence, strategy, creditCost, deductCredits, onSuccess, onError } = props;
20
20
 
21
21
  const creationIdRef = useRef<string | null>(null);
22
22
  const requestIdRef = useRef<string | null>(null);
@@ -111,6 +111,15 @@ export function useVideoQueueGeneration(props: UseVideoQueueGenerationProps): Us
111
111
 
112
112
  resetRefs();
113
113
 
114
+ // Deduct credits after successful generation
115
+ if (deductCredits && creditCost) {
116
+ await deductCredits(creditCost).catch((err) => {
117
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
118
+ console.error("[VideoQueue] deductCredits error:", err);
119
+ }
120
+ });
121
+ }
122
+
114
123
  if (typeof __DEV__ !== "undefined" && __DEV__) {
115
124
  console.log("[VideoQueue] 🎯 Calling onSuccess callback now...", { persistenceSucceeded });
116
125
  }
@@ -120,7 +129,7 @@ export function useVideoQueueGeneration(props: UseVideoQueueGenerationProps): Us
120
129
  console.log("[VideoQueue] ✅ onSuccess callback completed");
121
130
  }
122
131
  },
123
- [userId, persistence, onSuccess, onError, resetRefs, clearPolling],
132
+ [userId, persistence, deductCredits, creditCost, onSuccess, onError, resetRefs, clearPolling],
124
133
  );
125
134
 
126
135
  const handleError = useCallback(
@@ -28,6 +28,7 @@ export const useWizardGeneration = (props: UseWizardGenerationProps): UseWizardG
28
28
  isGeneratingStep,
29
29
  alertMessages,
30
30
  creditCost,
31
+ deductCredits,
31
32
  onSuccess,
32
33
  onError,
33
34
  onCreditsExhausted,
@@ -53,6 +54,7 @@ export const useWizardGeneration = (props: UseWizardGenerationProps): UseWizardG
53
54
  persistence,
54
55
  strategy,
55
56
  creditCost,
57
+ deductCredits,
56
58
  onSuccess,
57
59
  onError,
58
60
  });
@@ -63,6 +65,7 @@ export const useWizardGeneration = (props: UseWizardGenerationProps): UseWizardG
63
65
  persistence,
64
66
  strategy,
65
67
  creditCost,
68
+ deductCredits,
66
69
  alertMessages,
67
70
  onSuccess,
68
71
  onError,
@@ -36,6 +36,8 @@ export interface UseWizardGenerationProps {
36
36
  readonly alertMessages: AlertMessages;
37
37
  /** Credit cost for this generation - REQUIRED, determined by the app */
38
38
  readonly creditCost: number;
39
+ /** Called after successful generation to deduct credits — provided by the app */
40
+ readonly deductCredits?: (cost: number) => Promise<boolean>;
39
41
  readonly onSuccess?: (result: unknown) => void;
40
42
  readonly onError?: (error: string) => void;
41
43
  readonly onCreditsExhausted?: () => void;