UNPKG

@dbs-portal/tool-mock

Version:

API mocking toolkit using MSW for DBS Portal development workflows

182 lines 5.22 kB
/** * Integration types for core package compatibility */ import type { RequestHandler } from 'msw'; import type { MockConfig, MockAuthContext } from '../core/types'; export type { MockAuthContext } from '../core/types'; /** * Mock-aware API client configuration */ export interface MockAwareApiClientConfig { /** Base URL for real API */ baseURL: string; /** Base URL for mock API (optional, defaults to baseURL) */ mockBaseURL?: string; /** Enable mocking */ enableMocking?: boolean; /** Mock configuration */ mockConfig?: Partial<MockConfig>; /** Custom mock handlers */ mockHandlers?: RequestHandler[]; /** Timeout for requests */ timeout?: number; /** Default headers */ headers?: Record<string, string>; /** Request interceptors */ interceptors?: { request?: Array<(config: any) => any>; response?: Array<(response: any) => any>; }; } /** * Environment-aware API client configuration */ export interface EnvironmentAwareApiClientConfig { /** Production configuration */ production: Partial<MockAwareApiClientConfig>; /** Development configuration */ development: Partial<MockAwareApiClientConfig>; /** Testing configuration */ testing: Partial<MockAwareApiClientConfig>; /** Staging configuration */ staging?: Partial<MockAwareApiClientConfig>; } /** * Mock API client interface */ export interface MockAwareApiClient { /** Make GET request */ get<T = any>(url: string, config?: any): Promise<T>; /** Make POST request */ post<T = any>(url: string, data?: any, config?: any): Promise<T>; /** Make PUT request */ put<T = any>(url: string, data?: any, config?: any): Promise<T>; /** Make PATCH request */ patch<T = any>(url: string, data?: any, config?: any): Promise<T>; /** Make DELETE request */ delete<T = any>(url: string, config?: any): Promise<T>; /** Check if mocking is enabled */ isMocking(): boolean; /** Get current configuration */ getConfig(): MockAwareApiClientConfig; /** Update configuration */ updateConfig(config: Partial<MockAwareApiClientConfig>): void; } /** * Auth integration configuration */ export interface AuthIntegrationConfig { /** Mock authentication context */ mockAuthContext?: MockAuthContext; /** Custom token validator */ tokenValidator?: (token: string) => boolean | Promise<boolean>; /** Custom user provider */ userProvider?: (token: string) => any | Promise<any>; /** Auth endpoints */ endpoints?: { login?: string; logout?: string; refresh?: string; me?: string; }; } /** * Query integration configuration */ export interface QueryIntegrationConfig { /** Default query options */ defaultOptions?: { staleTime?: number; cacheTime?: number; retry?: number | boolean; refetchOnWindowFocus?: boolean; }; /** Mock query keys */ mockQueryKeys?: Record<string, any[]>; /** Custom query key factory */ queryKeyFactory?: (endpoint: string, params?: any) => any[]; } /** * Zustand integration configuration */ export interface ZustandIntegrationConfig { /** Store configurations */ stores?: Record<string, { initialState?: any; mockData?: any; actions?: Record<string, (...args: any[]) => any>; }>; /** Global mock state */ globalMockState?: any; } /** * Mock service configuration */ export interface MockServiceConfig { /** Service name */ name: string; /** Base path */ basePath: string; /** Mock handlers */ handlers: RequestHandler[]; /** Service dependencies */ dependencies?: string[]; /** Service metadata */ metadata?: { version?: string; description?: string; tags?: string[]; }; } /** * Integration plugin interface */ export interface IntegrationPlugin { /** Plugin name */ name: string; /** Plugin version */ version: string; /** Initialize plugin */ initialize(config: any): Promise<void> | void; /** Cleanup plugin */ cleanup(): Promise<void> | void; /** Get plugin handlers */ getHandlers(): RequestHandler[]; /** Check if plugin is enabled */ isEnabled(): boolean; } /** * Mock module configuration */ export interface MockModuleConfig { /** Module name */ name: string; /** Module handlers */ handlers: RequestHandler[]; /** Module dependencies */ dependencies?: string[]; /** Auto-register handlers */ autoRegister?: boolean; /** Module metadata */ metadata?: { version?: string; description?: string; author?: string; }; } /** * HTTP client wrapper configuration */ export interface HttpClientWrapperConfig { /** Original HTTP client instance */ client: any; /** Mock configuration */ mockConfig?: Partial<MockConfig>; /** Request transformer */ requestTransformer?: (config: any) => any; /** Response transformer */ responseTransformer?: (response: any) => any; /** Error transformer */ errorTransformer?: (error: any) => any; } //# sourceMappingURL=types.d.ts.map