import type { NestMiddleware } from '@nestjs/common'; /** * Platform-agnostic request interface supporting Express and Fastify */ interface PlatformRequest { method: string; url: string; path?: string; routerPath?: string; headers: Record; hostname?: string; query?: Record; cookies?: Record; raw?: { url?: string; }; } /** * Platform-agnostic next function */ type PlatformNextFunction = (error?: unknown) => void; import type { MultiTenantModuleOptions } from '../interfaces'; import { TenantContextService } from '../services'; /** * Middleware that extracts tenant information from incoming requests * and establishes the tenant context for the request lifecycle */ export declare class TenantMiddleware implements NestMiddleware { private readonly tenantContext; private readonly options; private readonly logger; private readonly cache; private readonly cacheEnabled; private readonly cacheTtl; private readonly cacheMax; private readonly debug; constructor(tenantContext: TenantContextService, options: MultiTenantModuleOptions); use(req: PlatformRequest, _res: unknown, next: PlatformNextFunction): Promise; /** * Log a debug message if debug mode is enabled */ private log; /** * Resolve tenant data with optional caching */ private resolveTenant; /** * Get tenant from cache if valid */ private getFromCache; /** * Set tenant in cache with TTL */ private setInCache; /** * Clear the tenant cache * Useful for testing or when tenant data is updated */ clearCache(): void; /** * Invalidate a specific tenant from cache */ invalidateTenant(tenantId: string): boolean; /** * Get current cache statistics */ getCacheStats(): { enabled: boolean; max: number; size: number; ttl: number; }; /** * Get request path (works with both Express and Fastify) */ private getRequestPath; /** * Get request hostname (works with both Express and Fastify) */ private getRequestHostname; /** * Extract tenant ID from the request based on the configured strategy */ private extractTenantId; /** * Extract tenant ID from request header */ private extractFromHeader; /** * Extract tenant ID from subdomain * e.g., tenant1.example.com -> tenant1 */ private extractFromSubdomain; /** * Extract tenant ID from URL path * e.g., /tenant1/api/users -> tenant1 */ private extractFromPath; /** * Extract tenant ID from query parameter * e.g., /api/users?tenantId=tenant1 -> tenant1 */ private extractFromQuery; /** * Extract tenant ID from cookie * e.g., Cookie: tenant_id=tenant1 -> tenant1 */ private extractFromCookie; /** * Parse cookie header string into key-value pairs * Used as fallback when cookie-parser middleware is not available */ private parseCookieHeader; /** * Extract tenant ID from JWT token in Authorization header * Supports Bearer tokens and decodes without verification * (verification should be handled by auth guards) */ private extractFromJwt; /** * Decode JWT payload without verification * Returns null if token is invalid or malformed */ private decodeJwtPayload; /** * Get a nested value from an object using dot notation * e.g., getNestedValue({ user: { tenantId: '123' } }, 'user.tenantId') => '123' */ private getNestedValue; /** * Extract tenant ID from bearer token using resolver function * Used for opaque tokens like API keys that require database lookup */ private extractFromBearer; /** * Extract tenant ID using custom extractor function */ private extractCustom; /** * Check if the current route should be excluded from tenant extraction */ private isRouteExcluded; /** * Create event context object */ private createEventContext; /** * Trigger onTenantIdExtracted hook */ private triggerOnTenantIdExtracted; /** * Trigger onTenantResolved hook */ private triggerOnTenantResolved; /** * Trigger onTenantNotFound hook */ private triggerOnTenantNotFound; /** * Trigger onTenantMissing hook */ private triggerOnTenantMissing; /** * Trigger onTenantValidationFailed hook */ private triggerOnTenantValidationFailed; /** * Validate tenant using the configured validator */ private validateTenant; } export {}; //# sourceMappingURL=tenant.middleware.d.ts.map