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

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.178",
4
4
  "description": "Provider-agnostic AI generation orchestration for React Native",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -8,6 +8,7 @@ import { useCallback, useMemo } from "react";
8
8
  import { useQueryClient } from "@tanstack/react-query";
9
9
  import { useAuth } from "@umituz/react-native-auth";
10
10
  import { createCreationsRepository } from "../../infrastructure/adapters";
11
+ import { getCreditService, isAppServicesConfigured } from "../../../../infrastructure/config/app-services.config";
11
12
  import type { Creation } from "../../domain/entities/Creation";
12
13
 
13
14
  declare const __DEV__: boolean;
@@ -20,6 +21,8 @@ export interface UseCreationPersistenceConfig {
20
21
  readonly type: string;
21
22
  /** Collection name in Firestore (defaults to "creations") */
22
23
  readonly collectionName?: string;
24
+ /** Credit cost to deduct on success (optional, defaults to 0 = no deduction) */
25
+ readonly creditCost?: number;
23
26
  }
24
27
 
25
28
  /**
@@ -118,6 +121,7 @@ export function useCreationPersistence(
118
121
  creationId: result.creationId,
119
122
  hasImageUrl: !!result.imageUrl,
120
123
  hasVideoUrl: !!result.videoUrl,
124
+ creditCost: config.creditCost,
121
125
  });
122
126
  }
123
127
 
@@ -146,8 +150,23 @@ export function useCreationPersistence(
146
150
  output,
147
151
  });
148
152
  queryClient.invalidateQueries({ queryKey: ["creations"] });
153
+
154
+ // Deduct credits on successful completion
155
+ if (config.creditCost && config.creditCost > 0 && isAppServicesConfigured()) {
156
+ const creditService = getCreditService();
157
+ if (creditService) {
158
+ if (__DEV__) {
159
+ console.log("[useCreationPersistence] Deducting credits", { cost: config.creditCost });
160
+ }
161
+ creditService.deductCredits(config.creditCost).catch((err) => {
162
+ if (__DEV__) {
163
+ console.error("[useCreationPersistence] Credit deduction failed", err);
164
+ }
165
+ });
166
+ }
167
+ }
149
168
  },
150
- [userId, repository, queryClient],
169
+ [userId, repository, queryClient, config.creditCost],
151
170
  );
152
171
 
153
172
  const onError = useCallback(