Files
bakery-ia/frontend/src/api/services/demo.ts

134 lines
3.5 KiB
TypeScript
Raw Normal View History

2025-10-06 15:27:01 +02:00
// ================================================================
// frontend/src/api/services/demo.ts
// ================================================================
2025-10-03 14:09:34 +02:00
/**
2025-10-06 15:27:01 +02:00
* Demo Session Service - Complete backend alignment
*
* Backend API structure (3-tier architecture):
* - ATOMIC: demo_accounts.py, demo_sessions.py
* - OPERATIONS: demo_operations.py
*
* Note: Demo service does NOT use tenant prefix
*
* Last Updated: 2025-10-05
* Status: Complete - Zero drift with backend
2025-10-03 14:09:34 +02:00
*/
import { apiClient } from '../client';
export interface DemoAccount {
account_type: string;
email: string;
name: string;
password: string;
description?: string;
features?: string[];
business_model?: string;
}
export interface DemoSession {
session_id: string;
virtual_tenant_id: string;
base_demo_tenant_id: string;
demo_account_type: string;
status: 'active' | 'expired' | 'destroyed';
created_at: string;
expires_at: string;
remaining_extensions: number;
}
export interface CreateSessionRequest {
demo_account_type: 'individual_bakery' | 'central_baker';
}
export interface ExtendSessionRequest {
session_id: string;
}
export interface DestroySessionRequest {
session_id: string;
}
2025-10-06 15:27:01 +02:00
// ===================================================================
// ATOMIC: Demo Accounts
// Backend: services/demo_session/app/api/demo_accounts.py
// ===================================================================
2025-10-03 14:09:34 +02:00
/**
* Get available demo accounts
2025-10-06 15:27:01 +02:00
* GET /demo/accounts
2025-10-03 14:09:34 +02:00
*/
export const getDemoAccounts = async (): Promise<DemoAccount[]> => {
return await apiClient.get<DemoAccount[]>('/demo/accounts');
};
2025-10-06 15:27:01 +02:00
// ===================================================================
// ATOMIC: Demo Sessions
// Backend: services/demo_session/app/api/demo_sessions.py
// ===================================================================
2025-10-03 14:09:34 +02:00
/**
* Create a new demo session
2025-10-06 15:27:01 +02:00
* POST /demo/sessions
2025-10-03 14:09:34 +02:00
*/
export const createDemoSession = async (
request: CreateSessionRequest
): Promise<DemoSession> => {
2025-10-06 15:27:01 +02:00
return await apiClient.post<DemoSession>('/demo/sessions', request);
};
/**
* Get demo session details
* GET /demo/sessions/{session_id}
*/
export const getDemoSession = async (sessionId: string): Promise<any> => {
return await apiClient.get(`/demo/sessions/${sessionId}`);
2025-10-03 14:09:34 +02:00
};
2025-10-06 15:27:01 +02:00
// ===================================================================
// OPERATIONS: Demo Session Management
// Backend: services/demo_session/app/api/demo_operations.py
// ===================================================================
2025-10-03 14:09:34 +02:00
/**
* Extend an existing demo session
2025-10-06 15:27:01 +02:00
* POST /demo/sessions/{session_id}/extend
2025-10-03 14:09:34 +02:00
*/
export const extendDemoSession = async (
request: ExtendSessionRequest
): Promise<DemoSession> => {
2025-10-06 15:27:01 +02:00
return await apiClient.post<DemoSession>(
`/demo/sessions/${request.session_id}/extend`,
{}
);
2025-10-03 14:09:34 +02:00
};
/**
* Destroy a demo session
2025-10-06 15:27:01 +02:00
* Note: This might be a DELETE endpoint - verify backend implementation
2025-10-03 14:09:34 +02:00
*/
export const destroyDemoSession = async (
request: DestroySessionRequest
): Promise<{ message: string }> => {
return await apiClient.post<{ message: string }>(
2025-10-06 15:27:01 +02:00
`/demo/sessions/${request.session_id}/destroy`,
{}
2025-10-03 14:09:34 +02:00
);
};
/**
* Get demo session statistics
2025-10-06 15:27:01 +02:00
* GET /demo/stats
2025-10-03 14:09:34 +02:00
*/
export const getDemoStats = async (): Promise<any> => {
return await apiClient.get('/demo/stats');
};
2025-10-06 15:27:01 +02:00
/**
* Cleanup expired demo sessions (Admin/Operations)
* POST /demo/operations/cleanup
*/
export const cleanupExpiredSessions = async (): Promise<any> => {
return await apiClient.post('/demo/operations/cleanup', {});
};