Start integrating the onboarding flow with backend 2

This commit is contained in:
Urtzi Alfaro
2025-09-04 18:59:56 +02:00
parent a11fdfba24
commit 9eedc2e5f2
30 changed files with 3432 additions and 4735 deletions

View File

@@ -1,40 +1,45 @@
// API and common response types
/**
* API Response Types - Matching actual backend implementation
*/
// Base API response structure
// Standard FastAPI response structure
export interface ApiResponse<T = any> {
data: T;
success: boolean;
data?: T;
success?: boolean;
message?: string;
detail?: string;
error?: string;
timestamp?: string;
}
// Error response structure
// FastAPI error response structure
export interface ApiError {
success: false;
error: ErrorDetail;
timestamp: string;
request_id?: string;
detail: string | ValidationError[];
type?: string;
}
export interface ErrorDetail {
message: string;
code?: string;
field?: string;
details?: Record<string, any>;
export interface ValidationError {
loc: (string | number)[];
msg: string;
type: string;
ctx?: Record<string, any>;
}
// Pagination types
// Pagination types (used by backend services)
export interface PaginatedResponse<T> {
items: T[];
total: number;
page: number;
size: number;
pages: number;
has_next: boolean;
has_prev: boolean;
items?: T[];
records?: T[]; // Some endpoints use 'records'
data?: T[]; // Some endpoints use 'data'
total?: number;
page?: number;
size?: number;
limit?: number;
offset?: number;
pages?: number;
has_next?: boolean;
has_prev?: boolean;
}
// Query parameters for API requests
export interface PaginationParams {
page?: number;
size?: number;
@@ -42,368 +47,33 @@ export interface PaginationParams {
offset?: number;
}
// Sorting and filtering
export interface SortParams {
sort_by?: string;
sort_order?: SortOrder;
order_by?: string;
order?: 'asc' | 'desc';
}
export interface FilterParams {
search?: string;
search_term?: string;
q?: string;
filters?: Record<string, any>;
[key: string]: any;
}
export interface QueryParams extends PaginationParams, SortParams, FilterParams {}
// File upload types
export interface FileUploadResponse {
file_id: string;
filename: string;
size: number;
mime_type: string;
url?: string;
download_url?: string;
expires_at?: string;
}
export interface FileUploadProgress {
loaded: number;
total: number;
percentage: number;
speed?: number;
estimated_time?: number;
}
export interface BulkOperationResponse {
total: number;
processed: number;
successful: number;
failed: number;
errors: BulkOperationError[];
warnings?: BulkOperationWarning[];
}
export interface BulkOperationError {
index: number;
item_id?: string;
error_code: string;
message: string;
field?: string;
details?: Record<string, any>;
}
export interface BulkOperationWarning {
index: number;
item_id?: string;
warning_code: string;
message: string;
suggestion?: string;
}
// Task/Job status types
// Task/Job status (used in ML training and other async operations)
export interface TaskStatus {
id: string;
task_id: string;
status: TaskStatusType;
progress: number;
message: string;
progress?: number;
message?: string;
result?: any;
error?: string;
created_at: string;
started_at?: string;
completed_at?: string;
estimated_completion?: string;
}
export interface LongRunningTask {
id: string;
name: string;
type: TaskType;
status: TaskStatusType;
progress: number;
total_steps?: number;
current_step?: number;
step_description?: string;
result_data?: any;
error_details?: TaskError;
created_by: string;
created_at: string;
updated_at: string;
}
export interface TaskError {
code: string;
message: string;
stack_trace?: string;
context?: Record<string, any>;
}
// Health check types
export interface HealthCheckResponse {
status: HealthStatus;
timestamp: string;
version: string;
uptime: number;
services: ServiceHealth[];
system_info?: SystemInfo;
}
export interface ServiceHealth {
name: string;
status: HealthStatus;
response_time_ms?: number;
error_message?: string;
dependencies?: ServiceHealth[];
}
export interface SystemInfo {
memory_usage: MemoryUsage;
cpu_usage?: number;
disk_usage?: DiskUsage;
network_stats?: NetworkStats;
}
export interface MemoryUsage {
used: number;
available: number;
total: number;
percentage: number;
}
export interface DiskUsage {
used: number;
available: number;
total: number;
percentage: number;
}
export interface NetworkStats {
bytes_sent: number;
bytes_received: number;
packets_sent: number;
packets_received: number;
}
// Audit and logging types
export interface AuditLog {
id: string;
user_id: string;
user_email: string;
tenant_id: string;
action: AuditAction;
resource_type: ResourceType;
resource_id: string;
changes?: AuditChange[];
metadata?: Record<string, any>;
ip_address: string;
user_agent: string;
timestamp: string;
}
export interface AuditChange {
field: string;
old_value?: any;
new_value?: any;
change_type: ChangeType;
}
// Cache types
export interface CacheInfo {
key: string;
size: number;
hits: number;
misses: number;
hit_rate: number;
created_at: string;
expires_at?: string;
last_accessed: string;
}
export interface CacheStats {
total_keys: number;
total_size: number;
hit_rate: number;
memory_usage: number;
cache_by_type: Record<string, CacheTypeStats>;
}
export interface CacheTypeStats {
count: number;
size: number;
hit_rate: number;
avg_ttl: number;
}
// Webhook types
export interface WebhookConfig {
id: string;
tenant_id: string;
name: string;
url: string;
events: WebhookEvent[];
secret?: string;
is_active: boolean;
retry_count: number;
timeout_seconds: number;
headers?: Record<string, string>;
created_at: string;
updated_at: string;
}
export interface WebhookDelivery {
id: string;
webhook_id: string;
event_type: WebhookEvent;
payload: Record<string, any>;
status: DeliveryStatus;
http_status?: number;
response_body?: string;
error_message?: string;
attempts: number;
delivered_at?: string;
created_at: string;
next_retry_at?: string;
}
// Rate limiting types
export interface RateLimit {
requests_per_minute: number;
requests_per_hour: number;
requests_per_day: number;
current_usage: RateLimitUsage;
reset_time: string;
}
export interface RateLimitUsage {
minute: number;
hour: number;
day: number;
percentage_used: number;
}
// Search types
export interface SearchRequest {
query: string;
filters?: SearchFilter[];
sort?: SearchSort[];
facets?: string[];
highlight?: SearchHighlight;
size?: number;
from?: number;
}
export interface SearchFilter {
field: string;
operator: FilterOperator;
value: any;
values?: any[];
}
export interface SearchSort {
field: string;
order: SortOrder;
}
export interface SearchHighlight {
fields: string[];
pre_tag?: string;
post_tag?: string;
}
export interface SearchResponse<T> {
results: T[];
total: number;
facets?: SearchFacet[];
highlights?: Record<string, string[]>;
suggestions?: SearchSuggestion[];
took_ms: number;
}
export interface SearchFacet {
field: string;
values: FacetValue[];
}
export interface FacetValue {
value: any;
count: number;
selected: boolean;
}
export interface SearchSuggestion {
text: string;
highlighted: string;
score: number;
}
// Export/Import types
export interface ExportRequest {
format: ExportFormat;
filters?: Record<string, any>;
fields?: string[];
include_metadata?: boolean;
compression?: CompressionType;
}
export interface ExportResponse {
export_id: string;
status: ExportStatus;
download_url?: string;
file_size?: number;
expires_at?: string;
created_at: string;
}
export interface ImportRequest {
file_url?: string;
file_data?: string;
format: ImportFormat;
options?: ImportOptions;
mapping?: Record<string, string>;
}
export interface ImportOptions {
skip_validation?: boolean;
update_existing?: boolean;
batch_size?: number;
dry_run?: boolean;
}
export interface ImportResponse {
import_id: string;
status: ImportStatus;
total_records?: number;
processed_records?: number;
successful_records?: number;
failed_records?: number;
errors?: ImportError[];
warnings?: ImportWarning[];
created_at: string;
}
export interface ImportError {
row: number;
field?: string;
value?: any;
error_code: string;
message: string;
}
export interface ImportWarning {
row: number;
field?: string;
value?: any;
warning_code: string;
message: string;
}
// Enums
export enum SortOrder {
ASC = 'asc',
DESC = 'desc',
}
export enum TaskStatusType {
@@ -411,153 +81,69 @@ export enum TaskStatusType {
RUNNING = 'running',
COMPLETED = 'completed',
FAILED = 'failed',
CANCELLED = 'cancelled',
PAUSED = 'paused',
CANCELLED = 'cancelled'
}
export enum TaskType {
DATA_IMPORT = 'data_import',
DATA_EXPORT = 'data_export',
REPORT_GENERATION = 'report_generation',
MODEL_TRAINING = 'model_training',
DATA_PROCESSING = 'data_processing',
BULK_OPERATION = 'bulk_operation',
SYNC_OPERATION = 'sync_operation',
// Health check types (used by monitoring endpoints)
export interface HealthCheckResponse {
status: 'healthy' | 'unhealthy' | 'degraded';
service: string;
version: string;
timestamp: string;
dependencies?: ServiceHealth[];
}
export enum HealthStatus {
HEALTHY = 'healthy',
DEGRADED = 'degraded',
UNHEALTHY = 'unhealthy',
UNKNOWN = 'unknown',
export interface ServiceHealth {
name: string;
status: 'healthy' | 'unhealthy' | 'degraded';
response_time?: number;
error?: string;
}
export enum AuditAction {
CREATE = 'create',
READ = 'read',
UPDATE = 'update',
DELETE = 'delete',
LOGIN = 'login',
LOGOUT = 'logout',
EXPORT = 'export',
IMPORT = 'import',
// File upload types
export interface FileUploadResponse {
file_id: string;
filename: string;
size: number;
content_type: string;
url?: string;
}
export enum ResourceType {
USER = 'user',
TENANT = 'tenant',
INGREDIENT = 'ingredient',
STOCK = 'stock',
PRODUCTION_BATCH = 'production_batch',
SALES_RECORD = 'sales_record',
FORECAST = 'forecast',
ORDER = 'order',
SUPPLIER = 'supplier',
RECIPE = 'recipe',
NOTIFICATION = 'notification',
// Bulk operation response
export interface BulkOperationResponse {
total: number;
processed: number;
successful: number;
failed: number;
errors?: BulkOperationError[];
}
export enum ChangeType {
CREATED = 'created',
UPDATED = 'updated',
DELETED = 'deleted',
ARCHIVED = 'archived',
RESTORED = 'restored',
export interface BulkOperationError {
index: number;
error: string;
details?: any;
}
export enum WebhookEvent {
USER_CREATED = 'user.created',
USER_UPDATED = 'user.updated',
USER_DELETED = 'user.deleted',
INVENTORY_LOW_STOCK = 'inventory.low_stock',
PRODUCTION_COMPLETED = 'production.completed',
ORDER_CREATED = 'order.created',
ORDER_UPDATED = 'order.updated',
FORECAST_GENERATED = 'forecast.generated',
ALERT_TRIGGERED = 'alert.triggered',
// Common enums
export enum SortOrder {
ASC = 'asc',
DESC = 'desc'
}
export enum DeliveryStatus {
PENDING = 'pending',
DELIVERED = 'delivered',
FAILED = 'failed',
RETRYING = 'retrying',
CANCELLED = 'cancelled',
}
export enum FilterOperator {
EQUALS = 'eq',
NOT_EQUALS = 'ne',
GREATER_THAN = 'gt',
GREATER_THAN_OR_EQUAL = 'gte',
LESS_THAN = 'lt',
LESS_THAN_OR_EQUAL = 'lte',
CONTAINS = 'contains',
STARTS_WITH = 'starts_with',
ENDS_WITH = 'ends_with',
IN = 'in',
NOT_IN = 'not_in',
IS_NULL = 'is_null',
IS_NOT_NULL = 'is_not_null',
BETWEEN = 'between',
}
export enum ExportFormat {
CSV = 'csv',
EXCEL = 'excel',
JSON = 'json',
PDF = 'pdf',
XML = 'xml',
}
export enum ImportFormat {
CSV = 'csv',
EXCEL = 'excel',
JSON = 'json',
XML = 'xml',
}
export enum CompressionType {
NONE = 'none',
ZIP = 'zip',
GZIP = 'gzip',
}
export enum ExportStatus {
PENDING = 'pending',
PROCESSING = 'processing',
COMPLETED = 'completed',
FAILED = 'failed',
EXPIRED = 'expired',
}
export enum ImportStatus {
PENDING = 'pending',
PROCESSING = 'processing',
COMPLETED = 'completed',
FAILED = 'failed',
CANCELLED = 'cancelled',
PARTIALLY_COMPLETED = 'partially_completed',
}
// Utility types for HTTP methods
// HTTP methods
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
// Generic type for API endpoints
export type ApiEndpoint<TRequest = any, TResponse = any> = {
method: HttpMethod;
path: string;
request?: TRequest;
response: TResponse;
};
// Type guards
export const isApiError = (obj: any): obj is ApiError => {
return obj && obj.success === false && obj.error && typeof obj.error.message === 'string';
return obj && typeof obj.detail === 'string';
};
export const isPaginatedResponse = <T>(obj: any): obj is PaginatedResponse<T> => {
return obj && Array.isArray(obj.items) && typeof obj.total === 'number';
return obj && (
Array.isArray(obj.items) ||
Array.isArray(obj.records) ||
Array.isArray(obj.data)
);
};
export const isTaskStatus = (obj: any): obj is TaskStatus => {

View File

@@ -1,39 +1,23 @@
// Authentication related types - Updated to match backend exactly
export interface User {
id: string;
email: string;
full_name: string; // Backend uses full_name, not name
is_active: boolean;
is_verified: boolean;
created_at: string; // ISO format datetime string
last_login?: string;
phone?: string;
language?: string;
timezone?: string;
tenant_id?: string;
role?: string; // Backend uses string, not enum
}
/**
* Authentication Types - Matching backend schemas exactly
* Based on services/auth/app/schemas/auth.py
*/
// ============================================================================
// REQUEST TYPES (Frontend -> Backend)
// ============================================================================
export interface UserRegistration {
email: string;
password: string;
full_name: string;
tenant_name?: string; // Optional in backend
role?: string; // Backend uses string, defaults to "user"
tenant_name?: string;
role?: 'user' | 'admin' | 'manager';
}
export interface UserLogin {
email: string;
password: string;
remember_me?: boolean;
}
export interface TokenResponse {
access_token: string;
refresh_token?: string;
token_type: string; // defaults to "bearer"
expires_in: number; // seconds, defaults to 3600
user?: User;
}
export interface RefreshTokenRequest {
@@ -54,6 +38,64 @@ export interface PasswordResetConfirm {
new_password: string;
}
// ============================================================================
// RESPONSE TYPES (Backend -> Frontend)
// ============================================================================
export interface UserData {
id: string;
email: string;
full_name: string;
is_active: boolean;
is_verified: boolean;
created_at: string;
tenant_id?: string;
role?: string;
}
export interface TokenResponse {
access_token: string;
refresh_token?: string;
token_type: string; // defaults to "bearer"
expires_in: number; // seconds, defaults to 3600
user?: UserData;
}
// ============================================================================
// JWT TOKEN CLAIMS (Internal)
// ============================================================================
export interface TokenClaims {
sub: string; // user ID
email: string;
full_name: string;
user_id: string;
is_verified: boolean;
tenant_id?: string;
role?: string;
type: 'access' | 'refresh';
iat: number; // issued at
exp: number; // expires at
iss: string; // issuer
}
// ============================================================================
// FRONTEND STATE TYPES
// ============================================================================
export interface AuthState {
isAuthenticated: boolean;
user: UserData | null;
token: string | null;
refreshToken: string | null;
loading: boolean;
error: string | null;
}
// ============================================================================
// AUTH SERVICE SPECIFIC TYPES
// ============================================================================
export interface TokenVerification {
valid: boolean;
user_id?: string;
@@ -62,27 +104,27 @@ export interface TokenVerification {
message?: string;
}
export interface UserResponse extends UserData {
last_login?: string;
phone?: string;
language?: string;
timezone?: string;
}
export interface UserUpdate {
full_name?: string;
phone?: string;
language?: string;
timezone?: string;
avatar_url?: string;
}
export interface AuthState {
isAuthenticated: boolean;
user: User | null;
token: string | null;
refreshToken: string | null;
loading: boolean;
error: string | null;
}
// ============================================================================
// FORM DATA TYPES (Frontend UI)
// ============================================================================
export interface LoginFormData {
email: string;
password: string;
remember_me: boolean;
}
export interface RegisterFormData {
@@ -90,17 +132,7 @@ export interface RegisterFormData {
password: string;
confirmPassword: string;
full_name: string;
tenant_name?: string; // Optional to match backend
phone?: string;
acceptTerms: boolean;
}
export interface ProfileFormData {
full_name: string;
email: string;
phone?: string;
language: string;
timezone: string;
tenant_name?: string;
}
export interface PasswordChangeFormData {
@@ -109,142 +141,40 @@ export interface PasswordChangeFormData {
confirm_password: string;
}
export interface EmailVerificationRequest {
email: string;
}
export interface EmailVerificationConfirm {
token: string;
}
export interface UserContext {
user_id: string;
email: string;
tenant_id?: string;
roles: string[];
is_verified: boolean;
permissions: string[];
}
export interface TokenClaims {
sub: string;
email: string;
full_name: string;
user_id: string;
is_verified: boolean;
tenant_id?: string;
iat: number;
exp: number;
iss: string;
roles?: string[];
permissions?: string[];
}
// ============================================================================
// UTILITY TYPES
// ============================================================================
export interface AuthError {
code: string;
message: string;
field?: string;
detail: string;
type?: string;
}
export interface MFASetup {
enabled: boolean;
secret?: string;
backup_codes?: string[];
qr_code?: string;
}
// Keep User as alias for UserData for backward compatibility
export interface User extends UserData {}
export interface MFAVerification {
token: string;
backup_code?: string;
}
// ============================================================================
// ENUMS
// ============================================================================
export interface SessionInfo {
id: string;
user_id: string;
ip_address: string;
user_agent: string;
created_at: string;
last_activity: string;
is_current: boolean;
location?: string;
device_type?: string;
}
export interface OAuthProvider {
name: string;
display_name: string;
icon: string;
color: string;
enabled: boolean;
}
// Enums - Simplified to match backend
export enum UserRole {
USER = 'user',
ADMIN = 'admin',
MANAGER = 'manager',
MANAGER = 'manager'
}
export enum AuthProvider {
EMAIL = 'email',
GOOGLE = 'google',
MICROSOFT = 'microsoft',
APPLE = 'apple',
}
// ============================================================================
// TYPE GUARDS
// ============================================================================
export enum Permission {
// User management
USER_READ = 'user:read',
USER_WRITE = 'user:write',
USER_DELETE = 'user:delete',
// Inventory
INVENTORY_READ = 'inventory:read',
INVENTORY_WRITE = 'inventory:write',
INVENTORY_DELETE = 'inventory:delete',
// Production
PRODUCTION_READ = 'production:read',
PRODUCTION_WRITE = 'production:write',
PRODUCTION_DELETE = 'production:delete',
// Sales
SALES_READ = 'sales:read',
SALES_WRITE = 'sales:write',
SALES_DELETE = 'sales:delete',
// Forecasting
FORECASTING_READ = 'forecasting:read',
FORECASTING_WRITE = 'forecasting:write',
FORECASTING_DELETE = 'forecasting:delete',
// Orders
ORDERS_READ = 'orders:read',
ORDERS_WRITE = 'orders:write',
ORDERS_DELETE = 'orders:delete',
// Procurement
PROCUREMENT_READ = 'procurement:read',
PROCUREMENT_WRITE = 'procurement:write',
PROCUREMENT_DELETE = 'procurement:delete',
// Settings
SETTINGS_READ = 'settings:read',
SETTINGS_WRITE = 'settings:write',
// Analytics
ANALYTICS_READ = 'analytics:read',
ANALYTICS_EXPORT = 'analytics:export',
// Admin
ADMIN_ALL = 'admin:all',
}
// Type guards
export const isUser = (obj: any): obj is User => {
export const isUser = (obj: any): obj is UserData => {
return obj && typeof obj.id === 'string' && typeof obj.email === 'string';
};
export const isTokenResponse = (obj: any): obj is TokenResponse => {
return obj && typeof obj.access_token === 'string' && typeof obj.token_type === 'string';
};
export const isAuthError = (obj: any): obj is AuthError => {
return obj && typeof obj.detail === 'string';
};

View File

@@ -0,0 +1,258 @@
/**
* External Data Service Types
* Weather, Traffic, and Events data
*/
// ============================================================================
// WEATHER TYPES
// ============================================================================
export interface WeatherData {
id: string;
tenant_id: string;
location_id: string;
date: string;
temperature_avg: number;
temperature_min: number;
temperature_max: number;
humidity: number;
precipitation: number;
wind_speed: number;
condition: string;
description: string;
created_at: string;
}
export interface WeatherCondition {
value: string;
label: string;
impact: 'positive' | 'negative' | 'neutral';
}
// ============================================================================
// TRAFFIC TYPES
// ============================================================================
export interface TrafficData {
id: string;
tenant_id: string;
location_id: string;
date: string;
hour: number;
traffic_level: number;
congestion_index: number;
average_speed: number;
incident_count: number;
created_at: string;
}
export interface TrafficPattern {
period: string;
average_traffic_level: number;
peak_hours: number[];
congestion_patterns: Record<string, number>;
}
// ============================================================================
// EVENTS TYPES
// ============================================================================
export interface EventData {
id: string;
tenant_id: string;
location_id: string;
event_name: string;
event_type: string;
start_date: string;
end_date: string;
expected_attendance?: number;
impact_radius_km?: number;
impact_score: number;
created_at: string;
}
export interface EventType {
value: string;
label: string;
typical_impact: 'positive' | 'negative' | 'neutral';
}
export interface CustomEventCreate {
location_id: string;
event_name: string;
event_type: string;
start_date: string;
end_date: string;
expected_attendance?: number;
impact_radius_km?: number;
impact_score?: number;
}
// ============================================================================
// LOCATION TYPES
// ============================================================================
export interface LocationConfig {
id: string;
tenant_id: string;
name: string;
latitude: number;
longitude: number;
address: string;
city: string;
country: string;
is_primary: boolean;
data_sources: {
weather_enabled: boolean;
traffic_enabled: boolean;
events_enabled: boolean;
};
created_at: string;
updated_at: string;
}
export interface LocationCreate {
name: string;
latitude: number;
longitude: number;
address: string;
city: string;
country?: string;
is_primary?: boolean;
data_sources?: LocationConfig['data_sources'];
}
// ============================================================================
// ANALYTICS TYPES
// ============================================================================
export interface ExternalFactorsImpact {
weather_impact: {
temperature_correlation: number;
precipitation_impact: number;
most_favorable_conditions: string;
};
traffic_impact: {
congestion_correlation: number;
peak_traffic_effect: number;
optimal_traffic_levels: number[];
};
events_impact: {
positive_events: EventData[];
negative_events: EventData[];
average_event_boost: number;
};
}
export interface DataQualityReport {
overall_score: number;
data_sources: Array<{
source: 'weather' | 'traffic' | 'events';
completeness: number;
freshness_hours: number;
reliability_score: number;
last_update: string;
}>;
recommendations: Array<{
priority: 'high' | 'medium' | 'low';
message: string;
action: string;
}>;
}
// ============================================================================
// CONFIGURATION TYPES
// ============================================================================
export interface DataSettings {
auto_refresh_enabled: boolean;
refresh_intervals: {
weather_minutes: number;
traffic_minutes: number;
events_hours: number;
};
data_retention_days: {
weather: number;
traffic: number;
events: number;
};
external_apis: {
weather_provider: string;
traffic_provider: string;
events_provider: string;
};
}
export interface DataSettingsUpdate {
auto_refresh_enabled?: boolean;
refresh_intervals?: {
weather_minutes?: number;
traffic_minutes?: number;
events_hours?: number;
};
data_retention_days?: {
weather?: number;
traffic?: number;
events?: number;
};
}
export interface RefreshInterval {
value: number;
label: string;
suitable_for: string[];
}
// ============================================================================
// QUERY PARAMETER TYPES
// ============================================================================
export interface WeatherDataParams {
location_id?: string;
start_date?: string;
end_date?: string;
page?: number;
size?: number;
}
export interface TrafficDataParams {
location_id?: string;
start_date?: string;
end_date?: string;
hour?: number;
page?: number;
size?: number;
}
export interface TrafficPatternsParams {
days_back?: number;
granularity?: 'hourly' | 'daily';
}
export interface EventsParams {
location_id?: string;
start_date?: string;
end_date?: string;
event_type?: string;
page?: number;
size?: number;
}
export interface ExternalFactorsParams {
location_id?: string;
start_date?: string;
end_date?: string;
}
// ============================================================================
// RESPONSE TYPES
// ============================================================================
export interface RefreshDataResponse {
message: string;
updated_records: number;
}
export interface DeleteResponse {
message: string;
}

View File

@@ -81,21 +81,85 @@ export type {
DataPreprocessing
} from './forecasting.types';
// Suppliers types
export type {
SupplierCreate,
SupplierUpdate,
SupplierResponse,
SupplierSummary,
SupplierSearchParams,
SupplierApproval,
SupplierStatistics,
PurchaseOrderItemCreate,
PurchaseOrderItemResponse,
PurchaseOrderCreate,
PurchaseOrderUpdate,
PurchaseOrderResponse,
DeliveryItemCreate,
DeliveryItemResponse,
DeliveryCreate,
DeliveryResponse,
DeliveryReceiptConfirmation,
PurchaseOrderStatus,
DeliveryStatus,
Supplier
} from './suppliers.types';
// Data types
export type {
WeatherData,
WeatherDataParams,
WeatherCondition,
TrafficData,
TrafficDataParams,
TrafficPattern,
TrafficPatternsParams,
EventData,
EventsParams,
EventType,
CustomEventCreate,
LocationConfig,
LocationCreate,
ExternalFactorsImpact,
ExternalFactorsParams,
DataQualityReport,
DataSettings,
DataSettingsUpdate,
RefreshDataResponse,
DeleteResponse,
RefreshInterval
} from './data.types';
// API and common types
export type {
ApiResponse,
ApiError,
ValidationError,
PaginatedResponse,
PaginationParams,
SortParams,
FilterParams,
QueryParams,
TaskStatus,
HealthCheckResponse
TaskStatusType,
HealthCheckResponse,
ServiceHealth,
FileUploadResponse,
BulkOperationResponse,
SortOrder,
HttpMethod
} from './api.types';
// Re-export commonly used types for convenience
export type {
User,
UserData,
UserLogin,
UserRegistration,
TokenResponse,
AuthState,
AuthError,
UserRole
} from './auth.types';
export type {
@@ -135,6 +199,16 @@ export type {
BatchStatus,
} from './forecasting.types';
export type {
SupplierResponse,
SupplierSummary,
SupplierCreate,
PurchaseOrderResponse,
DeliveryResponse,
PurchaseOrderStatus,
DeliveryStatus,
} from './suppliers.types';
export type {
ApiResponse,
ApiError,

View File

@@ -0,0 +1,166 @@
// Orders service types
export enum OrderStatus {
PENDING = 'pending',
CONFIRMED = 'confirmed',
IN_PREPARATION = 'in_preparation',
READY = 'ready',
DELIVERED = 'delivered',
CANCELLED = 'cancelled',
}
export enum OrderType {
DINE_IN = 'dine_in',
TAKEAWAY = 'takeaway',
DELIVERY = 'delivery',
CATERING = 'catering',
}
export interface OrderItem {
product_id?: string;
product_name: string;
quantity: number;
unit_price: number;
total_price: number;
notes?: string;
customizations?: Record<string, any>;
}
export interface OrderCreate {
customer_id?: string;
customer_name: string;
customer_email?: string;
customer_phone?: string;
order_type: OrderType;
items: OrderItem[];
special_instructions?: string;
delivery_address?: string;
delivery_date?: string;
delivery_time?: string;
payment_method?: string;
}
export interface OrderUpdate {
status?: OrderStatus;
customer_name?: string;
customer_email?: string;
customer_phone?: string;
special_instructions?: string;
delivery_address?: string;
delivery_date?: string;
delivery_time?: string;
estimated_completion_time?: string;
actual_completion_time?: string;
}
export interface OrderResponse {
id: string;
tenant_id: string;
order_number: string;
customer_id?: string;
customer_name: string;
customer_email?: string;
customer_phone?: string;
order_type: OrderType;
status: OrderStatus;
items: OrderItem[];
subtotal: number;
tax_amount: number;
discount_amount: number;
total_amount: number;
special_instructions?: string;
delivery_address?: string;
delivery_date?: string;
delivery_time?: string;
estimated_completion_time?: string;
actual_completion_time?: string;
payment_method?: string;
payment_status?: string;
created_at: string;
updated_at: string;
created_by?: string;
}
export interface Customer {
id: string;
tenant_id: string;
name: string;
email?: string;
phone?: string;
address?: string;
preferences?: Record<string, any>;
total_orders: number;
total_spent: number;
created_at: string;
updated_at: string;
}
export interface OrderAnalytics {
total_orders: number;
total_revenue: number;
average_order_value: number;
order_completion_rate: number;
delivery_success_rate: number;
customer_satisfaction_score?: number;
popular_products: Array<{
product_name: string;
quantity_sold: number;
revenue: number;
}>;
order_trends: Array<{
date: string;
orders: number;
revenue: number;
}>;
}
// Form data interfaces
export interface OrderFormData extends OrderCreate {}
export interface CustomerFormData {
name: string;
email?: string;
phone?: string;
address?: string;
preferences?: Record<string, any>;
}
// Filter interfaces
export interface OrderFilters {
page?: number;
size?: number;
status?: OrderStatus;
order_type?: OrderType;
customer_id?: string;
start_date?: string;
end_date?: string;
}
export interface CustomerFilters {
page?: number;
size?: number;
search?: string;
}
// Analytics interfaces
export interface OrderTrendsParams {
start_date?: string;
end_date?: string;
granularity?: 'hourly' | 'daily' | 'weekly' | 'monthly';
}
export interface OrderTrendData {
period: string;
orders: number;
revenue: number;
avg_order_value: number;
}
// Type guards
export const isOrderResponse = (obj: any): obj is OrderResponse => {
return obj && typeof obj.id === 'string' && typeof obj.order_number === 'string';
};
export const isCustomer = (obj: any): obj is Customer => {
return obj && typeof obj.id === 'string' && typeof obj.name === 'string';
};

View File

@@ -0,0 +1,379 @@
/**
* Type definitions for Suppliers Service API
* Based on backend schemas from services/suppliers/app/schemas/suppliers.py
*/
// ============================================================================
// ENUMS
// ============================================================================
export enum PurchaseOrderStatus {
DRAFT = 'draft',
PENDING = 'pending',
APPROVED = 'approved',
SENT = 'sent',
PARTIALLY_RECEIVED = 'partially_received',
RECEIVED = 'received',
CANCELLED = 'cancelled',
}
export enum DeliveryStatus {
SCHEDULED = 'scheduled',
IN_TRANSIT = 'in_transit',
DELIVERED = 'delivered',
FAILED = 'failed',
RETURNED = 'returned',
}
// ============================================================================
// SUPPLIER TYPES
// ============================================================================
export interface SupplierCreate {
name: string;
supplier_code?: string;
tax_id?: string;
registration_number?: string;
supplier_type: string;
contact_person?: string;
email?: string;
phone?: string;
mobile?: string;
website?: string;
address_line1?: string;
address_line2?: string;
city?: string;
state_province?: string;
postal_code?: string;
country?: string;
payment_terms?: string;
credit_limit?: number;
currency?: string;
standard_lead_time?: number;
minimum_order_amount?: number;
delivery_area?: string;
notes?: string;
certifications?: any;
business_hours?: any;
specializations?: any;
}
export interface SupplierUpdate {
name?: string;
supplier_code?: string;
tax_id?: string;
registration_number?: string;
supplier_type?: string;
status?: string;
contact_person?: string;
email?: string;
phone?: string;
mobile?: string;
website?: string;
address_line1?: string;
address_line2?: string;
city?: string;
state_province?: string;
postal_code?: string;
country?: string;
payment_terms?: string;
credit_limit?: number;
currency?: string;
standard_lead_time?: number;
minimum_order_amount?: number;
delivery_area?: string;
notes?: string;
certifications?: any;
business_hours?: any;
specializations?: any;
}
export interface SupplierResponse {
id: string;
tenant_id: string;
name: string;
supplier_code?: string;
tax_id?: string;
registration_number?: string;
supplier_type: string;
status: string;
contact_person?: string;
email?: string;
phone?: string;
mobile?: string;
website?: string;
address_line1?: string;
address_line2?: string;
city?: string;
state_province?: string;
postal_code?: string;
country?: string;
payment_terms: string;
credit_limit?: number;
currency: string;
standard_lead_time: number;
minimum_order_amount?: number;
delivery_area?: string;
quality_rating?: number;
delivery_rating?: number;
total_orders: number;
total_amount: number;
approved_by?: string;
approved_at?: string;
rejection_reason?: string;
notes?: string;
certifications?: any;
business_hours?: any;
specializations?: any;
created_at: string;
updated_at: string;
created_by: string;
updated_by: string;
}
export interface SupplierSummary {
id: string;
name: string;
supplier_code?: string;
supplier_type: string;
status: string;
contact_person?: string;
email?: string;
phone?: string;
city?: string;
country?: string;
quality_rating?: number;
delivery_rating?: number;
total_orders: number;
total_amount: number;
created_at: string;
}
export interface SupplierSearchParams {
search_term?: string;
supplier_type?: string;
status?: string;
limit?: number;
offset?: number;
}
export interface SupplierApproval {
action: 'approve' | 'reject';
notes?: string;
}
export interface SupplierStatistics {
total_suppliers: number;
active_suppliers: number;
pending_suppliers: number;
avg_quality_rating: number;
avg_delivery_rating: number;
total_spend: number;
}
// ============================================================================
// PURCHASE ORDER TYPES
// ============================================================================
export interface PurchaseOrderItemCreate {
inventory_product_id: string;
product_code?: string;
ordered_quantity: number;
unit_of_measure: string;
unit_price: number;
quality_requirements?: string;
item_notes?: string;
}
export interface PurchaseOrderItemResponse {
id: string;
tenant_id: string;
purchase_order_id: string;
price_list_item_id?: string;
inventory_product_id: string;
product_code?: string;
ordered_quantity: number;
unit_of_measure: string;
unit_price: number;
line_total: number;
received_quantity: number;
remaining_quantity: number;
quality_requirements?: string;
item_notes?: string;
created_at: string;
updated_at: string;
}
export interface PurchaseOrderCreate {
supplier_id: string;
reference_number?: string;
priority?: string;
required_delivery_date?: string;
delivery_address?: string;
delivery_instructions?: string;
delivery_contact?: string;
delivery_phone?: string;
tax_amount?: number;
shipping_cost?: number;
discount_amount?: number;
notes?: string;
internal_notes?: string;
terms_and_conditions?: string;
items: PurchaseOrderItemCreate[];
}
export interface PurchaseOrderUpdate {
reference_number?: string;
priority?: string;
required_delivery_date?: string;
estimated_delivery_date?: string;
delivery_address?: string;
delivery_instructions?: string;
delivery_contact?: string;
delivery_phone?: string;
tax_amount?: number;
shipping_cost?: number;
discount_amount?: number;
notes?: string;
internal_notes?: string;
terms_and_conditions?: string;
supplier_reference?: string;
}
export interface PurchaseOrderResponse {
id: string;
tenant_id: string;
supplier_id: string;
po_number: string;
reference_number?: string;
status: PurchaseOrderStatus;
priority: string;
order_date: string;
required_delivery_date?: string;
estimated_delivery_date?: string;
subtotal: number;
tax_amount: number;
shipping_cost: number;
discount_amount: number;
total_amount: number;
currency: string;
delivery_address?: string;
delivery_instructions?: string;
delivery_contact?: string;
delivery_phone?: string;
requires_approval: boolean;
approved_by?: string;
approved_at?: string;
rejection_reason?: string;
sent_to_supplier_at?: string;
supplier_confirmation_date?: string;
supplier_reference?: string;
notes?: string;
internal_notes?: string;
terms_and_conditions?: string;
created_at: string;
updated_at: string;
created_by: string;
updated_by: string;
supplier?: SupplierSummary;
items?: PurchaseOrderItemResponse[];
}
// ============================================================================
// DELIVERY TYPES
// ============================================================================
export interface DeliveryItemCreate {
purchase_order_item_id: string;
inventory_product_id: string;
ordered_quantity: number;
delivered_quantity: number;
accepted_quantity: number;
rejected_quantity?: number;
batch_lot_number?: string;
expiry_date?: string;
quality_grade?: string;
quality_issues?: string;
rejection_reason?: string;
item_notes?: string;
}
export interface DeliveryItemResponse {
id: string;
tenant_id: string;
delivery_id: string;
purchase_order_item_id: string;
inventory_product_id: string;
ordered_quantity: number;
delivered_quantity: number;
accepted_quantity: number;
rejected_quantity: number;
batch_lot_number?: string;
expiry_date?: string;
quality_grade?: string;
quality_issues?: string;
rejection_reason?: string;
item_notes?: string;
created_at: string;
updated_at: string;
}
export interface DeliveryCreate {
purchase_order_id: string;
supplier_id: string;
supplier_delivery_note?: string;
scheduled_date?: string;
estimated_arrival?: string;
delivery_address?: string;
delivery_contact?: string;
delivery_phone?: string;
carrier_name?: string;
tracking_number?: string;
notes?: string;
items: DeliveryItemCreate[];
}
export interface DeliveryResponse {
id: string;
tenant_id: string;
purchase_order_id: string;
supplier_id: string;
delivery_number: string;
supplier_delivery_note?: string;
status: DeliveryStatus;
scheduled_date?: string;
estimated_arrival?: string;
actual_arrival?: string;
completed_at?: string;
delivery_address?: string;
delivery_contact?: string;
delivery_phone?: string;
carrier_name?: string;
tracking_number?: string;
inspection_passed?: boolean;
inspection_notes?: string;
quality_issues?: any;
received_by?: string;
received_at?: string;
notes?: string;
photos?: any;
created_at: string;
updated_at: string;
created_by: string;
supplier?: SupplierSummary;
items?: DeliveryItemResponse[];
}
export interface DeliveryReceiptConfirmation {
inspection_passed?: boolean;
inspection_notes?: string;
quality_issues?: any;
notes?: string;
}
// ============================================================================
// UTILITY TYPES
// ============================================================================
// Keep legacy Supplier interface for backward compatibility
export interface Supplier extends SupplierResponse {}

View File

@@ -0,0 +1,35 @@
// ML Training service types
export interface TrainingJob {
id: string;
model_id: string;
status: 'pending' | 'running' | 'completed' | 'failed';
progress: number;
started_at?: string;
completed_at?: string;
error_message?: string;
parameters: Record<string, any>;
metrics?: Record<string, number>;
}
export interface TrainingJobCreate {
model_id: string;
parameters?: Record<string, any>;
}
export interface TrainingJobUpdate {
parameters?: Record<string, any>;
}
export enum TrainingJobStatus {
PENDING = 'pending',
RUNNING = 'running',
COMPLETED = 'completed',
FAILED = 'failed'
}
// Form data interfaces
export interface TrainingJobFormData {
model_id: string;
parameters: Record<string, any>;
}