UNPKG

@mikkelscheike/email-provider-links

Version:

TypeScript library for email provider detection with 140 providers (259 domains), concurrent DNS resolution, alias normalization, and HTTPS login URL validation for login and password reset flows

145 lines 4.62 kB
/** * Concurrent DNS Detection Engine * * Implements parallel MX/TXT record lookups for 2x faster business domain detection. * Uses Promise.allSettled for fault tolerance and intelligent result merging. */ import { EmailProvider } from './api'; type MXRecordLike = { exchange?: string; }; type TXTRecordLike = string; /** * True when hostname equals pattern or is a DNS subdomain of pattern. * Avoids substring false positives (e.g. "notgoogle.com" vs "google.com"). */ export declare function hostnameMatchesPattern(hostname: string, pattern: string): boolean; /** Reset rate limiter state (for tests). */ export declare function resetDnsRateLimiter(): void; /** Override the per-minute limit (for tests / advanced config). */ export declare function setDnsRateLimit(maxPerMinute: number): void; /** * Configuration for concurrent DNS detection */ export interface ConcurrentDNSConfig { /** Timeout for DNS queries in milliseconds */ timeout: number; /** Enable parallel DNS queries (vs sequential fallback) */ enableParallel: boolean; /** Prioritize MX record matches over TXT */ prioritizeMX: boolean; /** Collect detailed debugging information */ collectDebugInfo: boolean; /** Fall back to sequential mode on parallel failure */ fallbackToSequential: boolean; } /** * Result from a single DNS query (MX or TXT) */ export interface DNSQueryResult { /** Type of DNS record queried */ type: 'mx' | 'txt'; /** Whether the query succeeded */ success: boolean; /** DNS records returned (if successful) */ records?: MXRecordLike[] | TXTRecordLike[]; /** Error information (if failed) */ error?: Error; /** Query execution time in milliseconds */ timing: number; /** Raw DNS response for debugging */ rawResponse?: unknown; } /** * Result from concurrent DNS detection */ export interface ConcurrentDNSResult { /** Detected email provider (null if none found) */ provider: EmailProvider | null; /** Method used for detection */ detectionMethod: 'mx_record' | 'txt_record' | 'both' | 'proxy_detected' | null; /** Confidence score (0-1, higher = more confident) */ confidence: number; /** Proxy service detected (if any) */ proxyService?: string; /** Detailed timing information */ timing: { mx: number; txt: number; total: number; }; /** Debug information (if enabled) */ debug?: { mxMatches: string[]; txtMatches: string[]; conflicts: boolean; queries: DNSQueryResult[]; fallbackUsed: boolean; } | undefined; } /** * Concurrent DNS Detection Engine */ export declare class ConcurrentDNSDetector { private activeQueries; cleanup(): Promise<void>; private config; private providers; constructor(providers: EmailProvider[], config?: Partial<ConcurrentDNSConfig>); /** * Detect provider for a domain using concurrent DNS lookups */ detectProvider(domain: string): Promise<ConcurrentDNSResult>; /** * Perform DNS queries in parallel using Promise.allSettled with smart optimization */ private performParallelQueries; /** * Perform DNS queries sequentially (fallback mode) */ private performSequentialQueries; /** * Query MX records with timeout */ private queryMX; /** * Query TXT records with timeout */ private queryTXT; /** * Find provider matches from DNS query results */ private findProviderMatches; /** * Match a provider against DNS query results */ private matchProvider; /** * Select the best provider match from multiple candidates */ private selectBestMatch; /** * Check if MX result has potential matches (for sequential optimization) */ private hasMXMatch; /** * Detect proxy services from DNS results */ private detectProxy; /** * Calculate timing information from query results */ private calculateTiming; /** * Wrap a promise with a timeout */ private withTimeout; } /** * Factory function to create a concurrent DNS detector */ export declare function createConcurrentDNSDetector(providers: EmailProvider[], config?: Partial<ConcurrentDNSConfig>): ConcurrentDNSDetector; export declare function clearDnsResultCache(): void; export declare function detectProviderConcurrent(domain: string, providers: EmailProvider[], config?: Partial<ConcurrentDNSConfig>): Promise<ConcurrentDNSResult>; export {}; //# sourceMappingURL=concurrent-dns.d.ts.map