Fix new Frontend 4
This commit is contained in:
@@ -25,17 +25,18 @@ export interface ServiceEndpoints {
|
||||
|
||||
// Environment-based configuration
|
||||
const getEnvironmentConfig = (): ApiConfig => {
|
||||
const isProduction = process.env.NODE_ENV === 'production';
|
||||
const isDevelopment = process.env.NODE_ENV === 'development';
|
||||
// Use import.meta.env instead of process.env for Vite
|
||||
const isDevelopment = import.meta.env.DEV;
|
||||
const isProduction = import.meta.env.PROD;
|
||||
|
||||
return {
|
||||
baseURL: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000/api/v1',
|
||||
timeout: parseInt(process.env.NEXT_PUBLIC_API_TIMEOUT || '30000'),
|
||||
retries: parseInt(process.env.NEXT_PUBLIC_API_RETRIES || '3'),
|
||||
retryDelay: parseInt(process.env.NEXT_PUBLIC_API_RETRY_DELAY || '1000'),
|
||||
enableLogging: isDevelopment || process.env.NEXT_PUBLIC_API_LOGGING === 'true',
|
||||
enableCaching: process.env.NEXT_PUBLIC_API_CACHING !== 'false',
|
||||
cacheTimeout: parseInt(process.env.NEXT_PUBLIC_API_CACHE_TIMEOUT || '300000'), // 5 minutes
|
||||
baseURL: import.meta.env.VITE_API_URL || 'http://localhost:8000/api/v1',
|
||||
timeout: parseInt(import.meta.env.VITE_API_TIMEOUT || '30000'),
|
||||
retries: parseInt(import.meta.env.VITE_API_RETRIES || '3'),
|
||||
retryDelay: parseInt(import.meta.env.VITE_API_RETRY_DELAY || '1000'),
|
||||
enableLogging: isDevelopment || import.meta.env.VITE_API_LOGGING === 'true',
|
||||
enableCaching: import.meta.env.VITE_API_CACHING !== 'false',
|
||||
cacheTimeout: parseInt(import.meta.env.VITE_API_CACHE_TIMEOUT || '300000'), // 5 minutes
|
||||
};
|
||||
};
|
||||
|
||||
@@ -124,7 +125,6 @@ export const ApiVersion = {
|
||||
CURRENT: 'v1',
|
||||
} as const;
|
||||
|
||||
// Feature flags for API behavior
|
||||
export interface FeatureFlags {
|
||||
enableWebSockets: boolean;
|
||||
enableOfflineMode: boolean;
|
||||
@@ -134,9 +134,9 @@ export interface FeatureFlags {
|
||||
}
|
||||
|
||||
export const featureFlags: FeatureFlags = {
|
||||
enableWebSockets: process.env.NEXT_PUBLIC_ENABLE_WEBSOCKETS === 'true',
|
||||
enableOfflineMode: process.env.NEXT_PUBLIC_ENABLE_OFFLINE === 'true',
|
||||
enableOptimisticUpdates: process.env.NEXT_PUBLIC_ENABLE_OPTIMISTIC_UPDATES !== 'false',
|
||||
enableRequestDeduplication: process.env.NEXT_PUBLIC_ENABLE_DEDUPLICATION !== 'false',
|
||||
enableMetrics: process.env.NEXT_PUBLIC_ENABLE_METRICS === 'true',
|
||||
enableWebSockets: import.meta.env.VITE_ENABLE_WEBSOCKETS === 'true',
|
||||
enableOfflineMode: import.meta.env.VITE_ENABLE_OFFLINE === 'true',
|
||||
enableOptimisticUpdates: import.meta.env.VITE_ENABLE_OPTIMISTIC_UPDATES !== 'false',
|
||||
enableRequestDeduplication: import.meta.env.VITE_ENABLE_DEDUPLICATION !== 'false',
|
||||
enableMetrics: import.meta.env.VITE_ENABLE_METRICS === 'true',
|
||||
};
|
||||
|
||||
@@ -4,15 +4,10 @@
|
||||
* Central entry point for all API functionality
|
||||
*/
|
||||
|
||||
// Setup interceptors on import
|
||||
import { setupInterceptors } from './client/interceptors';
|
||||
setupInterceptors();
|
||||
|
||||
// Export main API client and services
|
||||
// Export main API client first
|
||||
export { apiClient } from './client';
|
||||
export { api } from './services';
|
||||
|
||||
// Export all services individually
|
||||
// Export all services
|
||||
export {
|
||||
authService,
|
||||
tenantService,
|
||||
@@ -20,7 +15,7 @@ export {
|
||||
trainingService,
|
||||
forecastingService,
|
||||
notificationService,
|
||||
healthService,
|
||||
api
|
||||
} from './services';
|
||||
|
||||
// Export all hooks
|
||||
@@ -35,37 +30,12 @@ export {
|
||||
useApiHooks,
|
||||
} from './hooks';
|
||||
|
||||
// Export WebSocket functionality
|
||||
export {
|
||||
WebSocketManager,
|
||||
useWebSocket,
|
||||
useTrainingWebSocket,
|
||||
useForecastWebSocket,
|
||||
} from './websocket';
|
||||
|
||||
// Export utilities
|
||||
export {
|
||||
ApiErrorHandler,
|
||||
ResponseProcessor,
|
||||
RequestValidator,
|
||||
DataTransformer,
|
||||
} from './utils';
|
||||
|
||||
// Export types
|
||||
export * from './types';
|
||||
|
||||
// Export interceptors for manual control
|
||||
export {
|
||||
AuthInterceptor,
|
||||
LoggingInterceptor,
|
||||
TenantInterceptor,
|
||||
ErrorRecoveryInterceptor,
|
||||
PerformanceInterceptor,
|
||||
setupInterceptors,
|
||||
} from './client/interceptors';
|
||||
|
||||
// Export configuration
|
||||
export { apiConfig, serviceEndpoints, featureFlags } from './client/config';
|
||||
|
||||
// Default export for convenience
|
||||
export default api;
|
||||
// Setup interceptors on import (move to end to avoid circular deps)
|
||||
import { setupInterceptors } from './client/interceptors';
|
||||
setupInterceptors();
|
||||
@@ -4,13 +4,24 @@
|
||||
* Central export point for all API services
|
||||
*/
|
||||
|
||||
// Import all services
|
||||
export { AuthService, authService } from './auth.service';
|
||||
export { TenantService, tenantService } from './tenant.service';
|
||||
export { DataService, dataService } from './data.service';
|
||||
export { TrainingService, trainingService } from './training.service';
|
||||
export { ForecastingService, forecastingService } from './forecasting.service';
|
||||
export { NotificationService, notificationService } from './notification.service';
|
||||
// Import and export individual services
|
||||
import { AuthService } from './auth.service';
|
||||
import { TenantService } from './tenant.service';
|
||||
import { DataService } from './data.service';
|
||||
import { TrainingService } from './training.service';
|
||||
import { ForecastingService } from './forecasting.service';
|
||||
import { NotificationService } from './notification.service';
|
||||
|
||||
// Create service instances
|
||||
export const authService = new AuthService();
|
||||
export const tenantService = new TenantService();
|
||||
export const dataService = new DataService();
|
||||
export const trainingService = new TrainingService();
|
||||
export const forecastingService = new ForecastingService();
|
||||
export const notificationService = new NotificationService();
|
||||
|
||||
// Export the classes as well
|
||||
export { AuthService, TenantService, DataService, TrainingService, ForecastingService, NotificationService };
|
||||
|
||||
// Import base client
|
||||
export { apiClient } from '../client';
|
||||
@@ -26,7 +37,6 @@ export const api = {
|
||||
training: trainingService,
|
||||
forecasting: forecastingService,
|
||||
notification: notificationService,
|
||||
client: apiClient,
|
||||
} as const;
|
||||
|
||||
// Service status checking
|
||||
|
||||
Reference in New Issue
Block a user