@umituz/react-native-ai-generation-content 1.17.27 → 1.17.28

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.27",
3
+ "version": "1.17.28",
4
4
  "description": "Provider-agnostic AI generation orchestration for React Native",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -0,0 +1,122 @@
1
+ /**
2
+ * App Services Interface
3
+ * Defines contracts for app-specific services that package uses
4
+ * Apps implement these interfaces to provide their specific logic
5
+ */
6
+
7
+ /**
8
+ * Network service interface
9
+ * Handles network availability checks
10
+ */
11
+ export interface INetworkService {
12
+ /**
13
+ * Check if device is online
14
+ */
15
+ isOnline: () => boolean;
16
+
17
+ /**
18
+ * Require network connection - throws if offline
19
+ */
20
+ requireNetwork: () => void;
21
+ }
22
+
23
+ /**
24
+ * Credit service interface
25
+ * Handles credit operations (check, deduct, refund)
26
+ */
27
+ export interface ICreditService {
28
+ /**
29
+ * Check if user has enough credits
30
+ * @param cost - Required credit amount
31
+ * @returns true if has enough credits
32
+ */
33
+ checkCredits: (cost: number) => Promise<boolean>;
34
+
35
+ /**
36
+ * Deduct credits from user balance
37
+ * @param cost - Amount to deduct
38
+ */
39
+ deductCredits: (cost: number) => Promise<void>;
40
+
41
+ /**
42
+ * Refund credits on failure (non-user caused errors)
43
+ * @param amount - Amount to refund
44
+ * @param error - Original error (used to determine if refund is applicable)
45
+ */
46
+ refundCredits: (amount: number, error?: unknown) => Promise<void>;
47
+
48
+ /**
49
+ * Calculate credit cost for operation
50
+ * @param capability - Generation capability type
51
+ * @param metadata - Additional metadata for cost calculation
52
+ */
53
+ calculateCost: (
54
+ capability: string,
55
+ metadata?: Record<string, unknown>,
56
+ ) => number;
57
+ }
58
+
59
+ /**
60
+ * Paywall service interface
61
+ * Shows paywall UI when credits insufficient
62
+ */
63
+ export interface IPaywallService {
64
+ /**
65
+ * Show paywall to user
66
+ * @param requiredCredits - Credits needed for operation
67
+ */
68
+ showPaywall: (requiredCredits: number) => void;
69
+ }
70
+
71
+ /**
72
+ * Auth service interface
73
+ * Handles user authentication
74
+ */
75
+ export interface IAuthService {
76
+ /**
77
+ * Get current user ID
78
+ * @returns User ID or null if not authenticated
79
+ */
80
+ getUserId: () => string | null;
81
+
82
+ /**
83
+ * Check if user is authenticated
84
+ */
85
+ isAuthenticated: () => boolean;
86
+
87
+ /**
88
+ * Require authenticated user - throws if not authenticated
89
+ * @returns User ID
90
+ */
91
+ requireAuth: () => string;
92
+ }
93
+
94
+ /**
95
+ * Analytics service interface (optional)
96
+ * Tracks events for analytics
97
+ */
98
+ export interface IAnalyticsService {
99
+ /**
100
+ * Track an event
101
+ * @param event - Event name
102
+ * @param data - Event data
103
+ */
104
+ track: (event: string, data: Record<string, unknown>) => void;
105
+ }
106
+
107
+ /**
108
+ * Combined app services interface
109
+ * Apps implement this to provide all required services
110
+ */
111
+ export interface IAppServices {
112
+ readonly network: INetworkService;
113
+ readonly credits: ICreditService;
114
+ readonly paywall: IPaywallService;
115
+ readonly auth: IAuthService;
116
+ readonly analytics?: IAnalyticsService;
117
+ }
118
+
119
+ /**
120
+ * Partial app services for optional configuration
121
+ */
122
+ export type PartialAppServices = Partial<IAppServices>;
@@ -4,3 +4,4 @@
4
4
  */
5
5
 
6
6
  export * from "./ai-provider.interface";
7
+ export * from "./app-services.interface";
package/src/index.ts CHANGED
@@ -29,6 +29,14 @@ export type {
29
29
  VideoFeatureType,
30
30
  ImageFeatureInputData,
31
31
  VideoFeatureInputData,
32
+ // App Services Interfaces
33
+ INetworkService,
34
+ ICreditService,
35
+ IPaywallService,
36
+ IAuthService,
37
+ IAnalyticsService,
38
+ IAppServices,
39
+ PartialAppServices,
32
40
  } from "./domain/interfaces";
33
41
 
34
42
  export {
@@ -85,6 +93,23 @@ export {
85
93
  getPromptRequiredModes,
86
94
  } from "./domain/constants/processing-modes.constants";
87
95
 
96
+ // =============================================================================
97
+ // INFRASTRUCTURE LAYER - App Services Configuration
98
+ // =============================================================================
99
+
100
+ export {
101
+ configureAppServices,
102
+ updateAppServices,
103
+ getAppServices,
104
+ isAppServicesConfigured,
105
+ resetAppServices,
106
+ getNetworkService,
107
+ getCreditService,
108
+ getPaywallService,
109
+ getAuthService,
110
+ getAnalyticsService,
111
+ } from "./infrastructure/config";
112
+
88
113
  // =============================================================================
89
114
  // INFRASTRUCTURE LAYER - Services
90
115
  // =============================================================================
@@ -0,0 +1,122 @@
1
+ /**
2
+ * App Services Configuration
3
+ * Singleton for storing app-provided service implementations
4
+ */
5
+
6
+ import type { IAppServices, PartialAppServices } from "../../domain/interfaces/app-services.interface";
7
+
8
+ declare const __DEV__: boolean;
9
+
10
+ let appServices: IAppServices | null = null;
11
+
12
+ /**
13
+ * Default no-op implementations for optional services
14
+ */
15
+ const defaultAnalytics = {
16
+ track: () => {
17
+ // No-op by default
18
+ },
19
+ };
20
+
21
+ /**
22
+ * Configure app services
23
+ * Must be called before using any generation features
24
+ * @param services - App-specific service implementations
25
+ */
26
+ export function configureAppServices(services: IAppServices): void {
27
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
28
+ // eslint-disable-next-line no-console
29
+ console.log("[AppServices] Configuring app services");
30
+ }
31
+
32
+ appServices = {
33
+ ...services,
34
+ analytics: services.analytics || defaultAnalytics,
35
+ };
36
+ }
37
+
38
+ /**
39
+ * Update specific app services
40
+ * Useful for lazy initialization
41
+ * @param updates - Partial service updates
42
+ */
43
+ export function updateAppServices(updates: PartialAppServices): void {
44
+ if (!appServices) {
45
+ throw new Error(
46
+ "[AppServices] Must call configureAppServices before updateAppServices",
47
+ );
48
+ }
49
+
50
+ appServices = {
51
+ ...appServices,
52
+ ...updates,
53
+ };
54
+ }
55
+
56
+ /**
57
+ * Get configured app services
58
+ * @throws Error if services not configured
59
+ */
60
+ export function getAppServices(): IAppServices {
61
+ if (!appServices) {
62
+ throw new Error(
63
+ "[AppServices] App services not configured. Call configureAppServices first.",
64
+ );
65
+ }
66
+
67
+ return appServices;
68
+ }
69
+
70
+ /**
71
+ * Check if app services are configured
72
+ */
73
+ export function isAppServicesConfigured(): boolean {
74
+ return appServices !== null;
75
+ }
76
+
77
+ /**
78
+ * Reset app services (useful for testing)
79
+ */
80
+ export function resetAppServices(): void {
81
+ appServices = null;
82
+ }
83
+
84
+ /**
85
+ * Get network service
86
+ * @throws Error if not configured
87
+ */
88
+ export function getNetworkService(): IAppServices["network"] {
89
+ return getAppServices().network;
90
+ }
91
+
92
+ /**
93
+ * Get credit service
94
+ * @throws Error if not configured
95
+ */
96
+ export function getCreditService(): IAppServices["credits"] {
97
+ return getAppServices().credits;
98
+ }
99
+
100
+ /**
101
+ * Get paywall service
102
+ * @throws Error if not configured
103
+ */
104
+ export function getPaywallService(): IAppServices["paywall"] {
105
+ return getAppServices().paywall;
106
+ }
107
+
108
+ /**
109
+ * Get auth service
110
+ * @throws Error if not configured
111
+ */
112
+ export function getAuthService(): IAppServices["auth"] {
113
+ return getAppServices().auth;
114
+ }
115
+
116
+ /**
117
+ * Get analytics service
118
+ * @throws Error if not configured
119
+ */
120
+ export function getAnalyticsService(): IAppServices["analytics"] {
121
+ return getAppServices().analytics;
122
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Infrastructure Config Exports
3
+ */
4
+
5
+ export {
6
+ configureAppServices,
7
+ updateAppServices,
8
+ getAppServices,
9
+ isAppServicesConfigured,
10
+ resetAppServices,
11
+ getNetworkService,
12
+ getCreditService,
13
+ getPaywallService,
14
+ getAuthService,
15
+ getAnalyticsService,
16
+ } from "./app-services.config";