UNPKG

@dbs-portal/tool-mock

Version:

API mocking toolkit using MSW for DBS Portal development workflows

122 lines 3.33 kB
/** * Authentication integration for mock environments */ import type { AuthIntegrationConfig, MockAuthContext } from './types'; import type { MockUser } from '../handlers/types'; /** * Mock authentication manager */ export declare class MockAuthManager { private authContext; private config; constructor(config?: AuthIntegrationConfig); /** * Set authenticated user */ setUser(user: any, token?: string): void; /** * Clear authentication */ clearAuth(): void; /** * Get current auth context */ getAuthContext(): MockAuthContext; /** * Check if user is authenticated */ isAuthenticated(): boolean; /** * Check if user has role */ hasRole(role: string): boolean; /** * Check if user has permission */ hasPermission(permission: string): boolean; /** * Get current user */ getCurrentUser(): any; /** * Get current token */ getCurrentToken(): string | null; /** * Validate token */ validateToken(token: string): Promise<boolean>; /** * Get user from token */ getUserFromToken(token: string): Promise<any>; /** * Generate mock JWT token */ private generateMockToken; } /** * Create mock authentication manager */ export declare function createMockAuthManager(config?: AuthIntegrationConfig): MockAuthManager; /** * Setup authentication mocking with handlers */ export declare function setupAuthMocking(users?: MockUser[], config?: AuthIntegrationConfig): Promise<MockAuthManager>; /** * Mock user factory for authentication */ export declare function mockAuthUser(overrides?: Partial<MockUser>): MockUser; /** * Create admin user for testing */ export declare function createMockAdminUser(overrides?: Partial<MockUser>): MockUser; /** * Create manager user for testing */ export declare function createMockManagerUser(overrides?: Partial<MockUser>): MockUser; /** * Integration with @dbs-portal/core-auth */ export declare function integrateWithCoreAuth(authManager: MockAuthManager, coreAuthStore?: any): void; /** * Create protected route wrapper for testing */ export declare function withMockAuth(handlers: any[], _authRequirements?: { requireAuth?: boolean; requiredRoles?: string[]; requiredPermissions?: string[]; }): any[]; /** * Mock authentication hooks for React components */ export declare function createMockAuthHooks(authManager: MockAuthManager): { useAuth: () => { isAuthenticated: boolean; user: any; token: string | null; login: (credentials: any) => Promise<MockUser>; logout: () => void; }; usePermissions: () => { hasPermission: (permission: string) => boolean; hasRole: (role: string) => boolean; permissions: string[]; roles: string[]; }; useCurrentUser: () => any; }; /** * Setup authentication for Storybook */ export declare function setupStorybookAuth(defaultUser?: Partial<MockUser>): MockAuthManager; /** * Authentication state persistence for development */ export declare class MockAuthPersistence { private storageKey; save(authContext: MockAuthContext): void; load(): MockAuthContext | null; clear(): void; } //# sourceMappingURL=auth.d.ts.map