@umituz/react-native-ai-generation-content 1.17.177 → 1.17.179

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.177",
3
+ "version": "1.17.179",
4
4
  "description": "Provider-agnostic AI generation orchestration for React Native",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -20,6 +20,10 @@ export interface UseCreationPersistenceConfig {
20
20
  readonly type: string;
21
21
  /** Collection name in Firestore (defaults to "creations") */
22
22
  readonly collectionName?: string;
23
+ /** Credit cost for this feature (passed to onCreditDeduct) */
24
+ readonly creditCost?: number;
25
+ /** Callback to deduct credits on successful processing */
26
+ readonly onCreditDeduct?: (cost: number) => Promise<void>;
23
27
  }
24
28
 
25
29
  /**
@@ -51,17 +55,19 @@ export interface UseCreationPersistenceReturn {
51
55
  * Hook that provides Firestore persistence callbacks for AI features
52
56
  *
53
57
  * @example
54
- * // In AnimeSelfieScreen:
55
- * const persistence = useCreationPersistence({ type: "anime-selfie" });
56
- * const config = useMemo(() => ({
57
- * prepareImage,
58
- * ...persistence,
59
- * }), [persistence]);
58
+ * const { deductCredit } = useDeductCredit({ userId, onCreditsExhausted: openPaywall });
59
+ * const persistence = useCreationPersistence({
60
+ * type: "anime-selfie",
61
+ * creditCost: AI_CREDIT_COST.ANIME_SELFIE,
62
+ * onCreditDeduct: async (cost) => {
63
+ * for (let i = 0; i < cost; i++) await deductCredit("image");
64
+ * },
65
+ * });
60
66
  */
61
67
  export function useCreationPersistence(
62
68
  config: UseCreationPersistenceConfig,
63
69
  ): UseCreationPersistenceReturn {
64
- const { type, collectionName = "creations" } = config;
70
+ const { type, collectionName = "creations", creditCost, onCreditDeduct } = config;
65
71
  const { userId } = useAuth();
66
72
  const queryClient = useQueryClient();
67
73
 
@@ -73,7 +79,7 @@ export function useCreationPersistence(
73
79
  const onProcessingStart = useCallback(
74
80
  <T extends BaseProcessingStartData>(data: T) => {
75
81
  if (__DEV__) {
76
- console.log("[useCreationPersistence] onProcessingStart called", { type, userId, data });
82
+ console.log("[useCreationPersistence] onProcessingStart", { type, userId });
77
83
  }
78
84
 
79
85
  if (!userId) {
@@ -86,10 +92,6 @@ export function useCreationPersistence(
86
92
  Object.entries(rest).filter(([, v]) => v !== undefined && v !== null),
87
93
  );
88
94
 
89
- if (__DEV__) {
90
- console.log("[useCreationPersistence] cleanMetadata", cleanMetadata);
91
- }
92
-
93
95
  const creation: Creation = {
94
96
  id: creationId,
95
97
  uri: "",
@@ -114,7 +116,7 @@ export function useCreationPersistence(
114
116
  const onProcessingComplete = useCallback(
115
117
  <T extends BaseProcessingResult>(result: T) => {
116
118
  if (__DEV__) {
117
- console.log("[useCreationPersistence] onProcessingComplete called", {
119
+ console.log("[useCreationPersistence] onProcessingComplete", {
118
120
  creationId: result.creationId,
119
121
  hasImageUrl: !!result.imageUrl,
120
122
  hasVideoUrl: !!result.videoUrl,
@@ -122,7 +124,7 @@ export function useCreationPersistence(
122
124
  }
123
125
 
124
126
  if (!userId || !result.creationId) {
125
- if (__DEV__) console.log("[useCreationPersistence] Missing userId or creationId, skipping");
127
+ if (__DEV__) console.log("[useCreationPersistence] Missing userId or creationId");
126
128
  return;
127
129
  }
128
130
 
@@ -133,38 +135,39 @@ export function useCreationPersistence(
133
135
  ? { videoUrl: result.videoUrl }
134
136
  : undefined;
135
137
 
136
- if (__DEV__) {
137
- console.log("[useCreationPersistence] Updating document to completed", {
138
- creationId: result.creationId,
139
- uri: uri.substring(0, 50) + "...",
140
- });
141
- }
142
-
143
138
  repository.update(userId, result.creationId, {
144
139
  uri,
145
140
  status: "completed",
146
141
  output,
147
142
  });
148
143
  queryClient.invalidateQueries({ queryKey: ["creations"] });
144
+
145
+ // Deduct credits via callback (app provides implementation)
146
+ if (creditCost && creditCost > 0 && onCreditDeduct) {
147
+ if (__DEV__) {
148
+ console.log("[useCreationPersistence] Deducting credits", { cost: creditCost });
149
+ }
150
+ onCreditDeduct(creditCost).catch((err) => {
151
+ if (__DEV__) {
152
+ console.error("[useCreationPersistence] Credit deduction failed", err);
153
+ }
154
+ });
155
+ }
149
156
  },
150
- [userId, repository, queryClient],
157
+ [userId, repository, queryClient, creditCost, onCreditDeduct],
151
158
  );
152
159
 
153
160
  const onError = useCallback(
154
161
  (error: string, creationId?: string) => {
155
162
  if (__DEV__) {
156
- console.log("[useCreationPersistence] onError called", { error, creationId });
163
+ console.log("[useCreationPersistence] onError", { error, creationId });
157
164
  }
158
165
 
159
166
  if (!userId || !creationId) {
160
- if (__DEV__) console.log("[useCreationPersistence] Missing userId or creationId, skipping");
167
+ if (__DEV__) console.log("[useCreationPersistence] Missing userId or creationId");
161
168
  return;
162
169
  }
163
170
 
164
- if (__DEV__) {
165
- console.log("[useCreationPersistence] Updating document to failed", { creationId });
166
- }
167
-
168
171
  repository.update(userId, creationId, {
169
172
  status: "failed",
170
173
  metadata: { error },