import React from 'react'; /** * Shared HTTP client types + request helpers for Host and standalone dev. * Keep body/query/timeout/response parsing in one place so implementations cannot drift. */ type HttpResponseKind = 'json' | 'text' | 'blob' | 'response'; type HttpQueryValue = string | number | boolean | undefined | null | Array; type HttpQuery = Record; interface HttpOptions { /** Extra request headers (wins over auto Content-Type) */ headers?: Record; /** Timeout in ms */ timeout?: number; /** Skip authentication (Host may omit Authorization / credentials) */ skipAuth?: boolean; /** Query string params; `undefined` / `null` values are skipped */ query?: HttpQuery; /** * Response parsing mode. Default `json`. * - `json` / `text` / `blob`: throw {@link HttpError} when `!response.ok` * - `response`: return the raw {@link Response} (caller checks status / headers) */ responseKind?: HttpResponseKind; /** AbortSignal; combined with `timeout` when both are set */ signal?: AbortSignal; /** * Override Content-Type for JSON/string bodies. * Ignored for FormData / Blob / URLSearchParams / ArrayBuffer (browser sets boundary). */ contentType?: string; } interface HttpClient { get: (url: string, options?: HttpOptions) => Promise; post: (url: string, body?: unknown, options?: HttpOptions) => Promise; put: (url: string, body?: unknown, options?: HttpOptions) => Promise; patch: (url: string, body?: unknown, options?: HttpOptions) => Promise; delete: (url: string, options?: HttpOptions) => Promise; } /** * User information passed from Host to module. * 字段与 live.employees 一一对应:id / phone / name。 */ interface ModuleUser { /** 员工 id(live.employees.id) */ id: number; /** 手机号(live.employees.phone) */ phone: string; /** 姓名(live.employees.name) */ name: string; /** User role */ role: 'admin' | 'user'; /** User permissions list */ permissions: string[]; } /** * Theme configuration and controls */ interface ModuleTheme { /** Current theme mode */ mode: 'light' | 'dark'; /** Primary color (hex) */ primaryColor: string; /** Toggle theme mode */ toggle: () => void; } /** * Router service for navigation */ interface ModuleRouter { /** Current path within module */ currentPath: string; /** Dynamic route parameters (e.g., { id: '123' } from /detail/:id) */ params: Record; /** Query string parameters */ query: URLSearchParams; /** Navigate to a new path within module */ navigate: (path: string) => void; } /** * Notification service for user feedback */ interface ModuleNotifications { /** Show success notification */ success: (message: string, description?: string) => void; /** Show error notification */ error: (message: string, description?: string) => void; /** Show warning notification */ warning: (message: string, description?: string) => void; /** Show info notification */ info: (message: string, description?: string) => void; } /** * Global state for cross-module communication * Simple state store - modules can share data through this */ interface ModuleGlobalState { /** Get value by key */ get: (key: string) => T | undefined; /** Set value by key */ set: (key: string, value: T) => void; /** Subscribe to key changes, returns unsubscribe function */ subscribe: (key: string, callback: (value: unknown) => void) => () => void; /** Clear all state for current module namespace */ clear: () => void; } /** * Storage service with module namespace isolation */ interface ModuleStorage { /** Get item */ get: (key: string) => T | null; /** Set item */ set: (key: string, value: T) => void; /** Remove item */ remove: (key: string) => void; /** Clear all items for this module */ clear: () => void; } /** * Platform configuration */ interface AppConfig { /** Platform API base URL */ apiBaseUrl: string; /** Module base URL */ moduleBaseUrl: string; /** Platform version */ version: string; /** Environment: development | production */ environment: 'development' | 'production'; } /** * Platform services */ interface PlatformServices { /** HTTP client with auto-authentication */ http: HttpClient; /** Module-isolated storage */ storage: ModuleStorage; /** Platform configuration */ config: AppConfig; } /** * Complete Module Context * Provided by Host via ModuleProvider */ interface ModuleContext { /** User information */ user: ModuleUser; /** Theme configuration */ theme: ModuleTheme; /** Router service */ router: ModuleRouter; /** Notification service */ notifications: ModuleNotifications; /** Global state (cross-module communication) */ globalState: ModuleGlobalState; /** Platform services */ platform: PlatformServices; } interface CreateDevModuleContextOptions { /** Module name for storage namespace */ moduleName?: string; /** Override dev user */ user?: Partial; /** Current path within module (sync with react-router) */ currentPath?: string; /** Navigate callback (e.g. react-router navigate) */ navigate?: (path: string) => void; /** Platform config overrides */ config?: Partial; } /** * Build a ModuleContext for local `vite` development (no Stago Host). */ declare function createDevModuleContext(options?: CreateDevModuleContextOptions): ModuleContext; interface DevModuleProviderProps { children: React.ReactNode; /** Module name for dev storage namespace */ moduleName?: string; } /** * Wrap local dev routes with ModuleProvider so pages can use useModule / useModuleRequest. * Place inside react-router's BrowserRouter. */ declare function DevModuleProvider({ children, moduleName }: DevModuleProviderProps): React.JSX.Element; export { type CreateDevModuleContextOptions, DevModuleProvider, type DevModuleProviderProps, createDevModuleContext };