yq-dns 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +351 -756
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -12,37 +12,18 @@ A comprehensive, promise-based DNS resolver library that aggregates multiple DNS
12
12
  - [Features](#-features)
13
13
  - [Installation](#-installation)
14
14
  - [Quick Start](#-quick-start)
15
- - [ESM (ES Modules)](#esm-es-modules)
16
- - [CommonJS](#commonjs)
17
15
  - [DNS Providers](#-dns-providers)
18
16
  - [Configuration](#-configuration)
19
- - [Provider Configuration](#provider-configuration)
20
- - [Global Configuration](#global-configuration)
21
- - [Default Settings](#default-settings)
22
17
  - [API Reference](#-api-reference)
23
- - [YqDns Class](#yqdns-class)
24
- - [Standalone Functions](#standalone-functions)
25
- - [DNS Resolution Methods](#dns-resolution-methods)
26
- - [Email Validation](#email-validation)
27
18
  - [DNS Record Types](#-dns-record-types)
28
- - [Advanced Usage](#-advanced-usage)
29
- - [Rate Limiting](#rate-limiting)
30
- - [Provider Selection](#provider-selection)
31
- - [Error Handling](#error-handling)
32
- - [Concurrency Control](#concurrency-control)
33
- - [Email Validation System](#-email-validation-system)
34
- - [Domain Validation](#domain-validation)
35
- - [Webmail Detection](#webmail-detection)
36
- - [Provider Recognition](#provider-recognition)
19
+ - [Email Validation](#email-validation)
37
20
  - [TypeScript Support](#-typescript-support)
38
- - [Performance](#-performance)
39
- - [Examples](#-examples)
40
- - [Troubleshooting](#-troubleshooting)
41
- - [Contributing](#-contributing)
42
21
  - [License](#-license)
43
22
 
44
23
  ## 🚀 Features
45
24
 
25
+ YQ-DNS is designed to be the most comprehensive and reliable DNS resolution library for modern JavaScript applications. It combines multiple DNS-over-HTTPS providers with intelligent load balancing, advanced error handling, and extensive email validation capabilities to deliver enterprise-grade DNS resolution with exceptional performance and reliability.
26
+
46
27
  - **🌐 Multiple DNS Providers**: Google DoH, Cloudflare DoH, Quad9 DoH, and Node.js native DNS
47
28
  - **⚡ High Performance**: Concurrent requests with intelligent load balancing
48
29
  - **🎯 Smart Provider Selection**: Automatic failover and random selection
@@ -58,21 +39,35 @@ A comprehensive, promise-based DNS resolver library that aggregates multiple DNS
58
39
 
59
40
  ## 📦 Installation
60
41
 
42
+ YQ-DNS is available as an npm package and can be installed using any modern JavaScript package manager. The library is built with zero dependencies for maximum compatibility and minimal bundle size, making it perfect for both server-side applications and edge computing environments.
43
+
44
+ **Using npm:**
61
45
  ```bash
62
46
  npm install yq-dns
63
47
  ```
64
48
 
49
+ **Using Yarn:**
65
50
  ```bash
66
51
  yarn add yq-dns
67
52
  ```
68
53
 
54
+ **Using pnpm:**
69
55
  ```bash
70
56
  pnpm add yq-dns
71
57
  ```
72
58
 
59
+ **Requirements:**
60
+ - Node.js 18.0.0 or higher
61
+ - TypeScript 4.5+ (for TypeScript projects)
62
+ - Modern JavaScript environment with Promise support
63
+
73
64
  ## 🚀 Quick Start
74
65
 
75
- ### ESM (ES Modules)
66
+ Get started with YQ-DNS in seconds! The library offers two main approaches: standalone functions for simple DNS queries and the YqDns class for advanced configuration and control. Both approaches provide the same powerful DNS resolution capabilities with automatic provider selection and intelligent error handling.
67
+
68
+ ### Standalone Functions (Recommended for Simple Use Cases)
69
+
70
+ Standalone functions provide the quickest way to perform DNS lookups with sensible defaults and automatic provider selection:
76
71
 
77
72
  ```typescript
78
73
  // Using standalone functions (recommended for simple use cases)
@@ -88,932 +83,532 @@ console.log(mxRecords); // [{ priority: 10, exchange: 'mail.example.com' }]
88
83
 
89
84
  // Resolve with specific provider
90
85
  const googleResult = await resolve4('example.com', undefined, 'google');
91
-
92
- // Resolve with TTL information
93
- const withTtl = await resolve4('example.com', { ttl: true });
94
- console.log(withTtl); // [{ address: '93.184.216.34', ttl: 300 }]
95
86
  ```
96
87
 
88
+ ### YqDns Class (For Advanced Configuration)
89
+
90
+ The YqDns class provides fine-grained control over DNS providers, concurrency limits, timeouts, and retry behavior:
91
+
97
92
  ```typescript
98
- // Using YqDns class (recommended for advanced configuration)
93
+ // Using YqDns class (for advanced configuration)
99
94
  import { YqDns } from 'yq-dns';
100
95
 
101
96
  const dns = new YqDns({
102
97
  google: { enabled: true, limit: { concurrency: 10 } },
103
- cloudflare: { enabled: true, limit: { concurrency: 5 } },
104
- quad9: { enabled: false },
105
- native: { enabled: true }
98
+ cloudflare: { enabled: true, limit: { concurrency: 5 } }
106
99
  });
107
100
 
108
101
  const addresses = await dns.resolve4('example.com');
109
- const mxRecords = await dns.resolveMx('example.com');
110
102
  ```
111
103
 
112
- ### CommonJS
104
+ ### CommonJS Support
113
105
 
114
- ```javascript
115
- // Using require (Node.js with CommonJS)
116
- const { resolve4, resolveMx, YqDns } = require('yq-dns');
117
-
118
- // Standalone functions
119
- resolve4('example.com').then(addresses => {
120
- console.log(addresses);
121
- });
106
+ YQ-DNS fully supports CommonJS environments for maximum compatibility:
122
107
 
123
- // Class usage
124
- const dns = new YqDns({
125
- google: { enabled: true },
126
- cloudflare: { enabled: true }
127
- });
108
+ ```javascript
109
+ // CommonJS usage
110
+ const { resolve4, YqDns } = require('yq-dns');
128
111
 
129
- dns.resolve4('example.com').then(addresses => {
130
- console.log(addresses);
131
- });
112
+ const addresses = await resolve4('example.com');
132
113
  ```
133
114
 
134
115
  ## 🌐 DNS Providers
135
116
 
117
+ YQ-DNS integrates with multiple DNS providers to ensure maximum reliability, performance, and flexibility. Each provider offers unique advantages and can be configured independently with custom settings for concurrency, timeouts, and retry behavior. The library automatically selects the best available provider or allows manual provider specification for specific use cases.
118
+
136
119
  ### Native Provider
120
+
121
+ The native provider leverages Node.js's built-in DNS resolution capabilities, providing seamless integration with system DNS settings and local network configurations.
122
+
137
123
  - **Endpoint**: Node.js built-in `dns/promises` module
138
124
  - **Features**: Supports all DNS methods including `lookup()`
139
125
  - **Use Case**: Local/internal DNS resolution, system DNS settings
140
126
  - **Advantages**: No external dependencies, respects system DNS configuration
127
+ - **Best For**: Internal networks, development environments, system-integrated applications
128
+
129
+ ### Google DoH (DNS-over-HTTPS)
130
+
131
+ Google's public DNS service provides enterprise-grade DNS resolution with global infrastructure and comprehensive DNSSEC validation.
141
132
 
142
- ### Google DoH
143
133
  - **Endpoint**: `https://dns.google/resolve`
144
- - **Features**: DNSSEC validation, high reliability
134
+ - **Features**: DNSSEC validation, high reliability, global anycast network
145
135
  - **Use Case**: Public DNS resolution with Google's infrastructure
146
- - **Advantages**: Global CDN, excellent uptime, DNSSEC support
136
+ - **Advantages**: Global CDN, excellent uptime, DNSSEC support, comprehensive logging
137
+ - **Best For**: Production applications, global services, DNSSEC-required environments
147
138
 
148
- ### Cloudflare DoH
149
- - **Endpoint**: `https://cloudflare-dns.com/dns-query`
150
- - **Features**: Privacy-focused, minimal logging
151
- - **Use Case**: Privacy-conscious applications
152
- - **Advantages**: Fast global network, strong privacy policy
139
+ ### Cloudflare DoH (DNS-over-HTTPS)
153
140
 
154
- ### Quad9 DoH
155
- - **Endpoint**: `https://dns.quad9.net/dns-query`
156
- - **Features**: Security-focused, threat blocking
157
- - **Use Case**: Security-sensitive applications
158
- - **Advantages**: Malware blocking, non-profit organization
141
+ Cloudflare's privacy-focused DNS service emphasizes user privacy with minimal logging and fast global resolution.
159
142
 
160
- ## ⚙️ Configuration
143
+ - **Endpoint**: `https://cloudflare-dns.com/dns-query`
144
+ - **Features**: Privacy-focused, minimal logging, malware protection
145
+ - **Use Case**: Privacy-conscious applications, consumer-facing services
146
+ - **Advantages**: Fast global network, strong privacy policy, built-in security features
147
+ - **Best For**: Privacy-sensitive applications, consumer products, GDPR-compliant services
161
148
 
162
- ### Provider Configuration
149
+ ### Quad9 DoH (DNS-over-HTTPS)
163
150
 
164
- ```typescript
165
- interface ProviderConfig {
166
- enabled?: boolean; // Enable/disable provider (default: true)
167
- limit?: {
168
- concurrency: number; // Max concurrent requests
169
- interval?: number; // Rate limiting interval in ms
170
- intervalCap?: number; // Max requests per interval
171
- carryoverConcurrencyCount?: boolean; // Carry over concurrency count
172
- };
173
- }
174
- ```
151
+ Quad9's security-focused DNS service provides threat intelligence and malware blocking while maintaining user privacy.
175
152
 
176
- ### Global Configuration
153
+ - **Endpoint**: `https://dns.quad9.net/dns-query`
154
+ - **Features**: Security-focused, threat blocking, privacy protection
155
+ - **Use Case**: Security-sensitive applications, enterprise environments
156
+ - **Advantages**: Malware blocking, threat intelligence, non-profit organization, no user tracking
157
+ - **Best For**: Security-critical applications, enterprise networks, threat-aware environments
177
158
 
178
- ```typescript
179
- interface YqConfig {
180
- native?: ProviderConfig; // Node.js built-in DNS
181
- google?: ProviderConfig; // Google DoH
182
- cloudflare?: ProviderConfig; // Cloudflare DoH
183
- quad9?: ProviderConfig; // Quad9 DoH
184
- }
185
- ```
159
+ ## ⚙️ Configuration
186
160
 
187
- ### Default Settings
161
+ YQ-DNS provides extensive configuration options to fine-tune DNS resolution behavior according to your application's specific requirements. Each DNS provider can be configured independently with custom concurrency limits, rate limiting, timeouts, and retry policies. The configuration system supports both static initialization and dynamic runtime updates.
162
+
163
+ ### Basic Configuration Example
188
164
 
189
165
  ```typescript
190
- const defaultConfig: YqConfig = {
191
- native: {
192
- enabled: true,
193
- limit: {
194
- concurrency: 10,
195
- interval: 1000,
196
- intervalCap: 200,
197
- carryoverConcurrencyCount: true
198
- }
199
- },
200
- google: {
201
- enabled: true,
202
- limit: {
203
- concurrency: 5,
204
- interval: 1000,
205
- intervalCap: 50,
206
- carryoverConcurrencyCount: true
207
- }
166
+ const dns = new YqDns({
167
+ google: {
168
+ enabled: true,
169
+ limit: { concurrency: 10, rps: 100 },
170
+ timeout: 5000,
171
+ retries: 3
208
172
  },
209
- cloudflare: {
210
- enabled: true,
211
- limit: {
212
- concurrency: 7,
213
- interval: 1000,
214
- intervalCap: 70,
215
- carryoverConcurrencyCount: true
216
- }
173
+ cloudflare: {
174
+ enabled: true,
175
+ limit: { concurrency: 5, rps: 50 }
217
176
  },
218
- quad9: {
219
- enabled: true,
220
- limit: {
221
- concurrency: 5,
222
- interval: 1000,
223
- intervalCap: 50,
224
- carryoverConcurrencyCount: true
225
- }
226
- }
227
- };
177
+ quad9: { enabled: false },
178
+ native: { enabled: true }
179
+ });
228
180
  ```
229
181
 
230
- ## 📚 API Reference
231
-
232
- ### YqDns Class
233
-
234
- #### Constructor
182
+ ### Configuration Options
235
183
 
236
- ```typescript
237
- new YqDns(config?: YqConfig)
238
- ```
184
+ - **enabled**: Enable or disable the provider (boolean)
185
+ - **limit.concurrency**: Maximum concurrent requests per provider (number)
186
+ - **limit.rps**: Requests per second rate limit (number)
187
+ - **timeout**: Request timeout in milliseconds (number)
188
+ - **retries**: Number of retry attempts on failure (number)
189
+ - **priority**: Provider selection priority (number, higher = preferred)
239
190
 
240
- Creates a new DNS resolver instance with optional configuration.
241
-
242
- **Parameters:**
243
- - `config` (optional): Global configuration for all providers
191
+ ### Dynamic Configuration Updates
244
192
 
245
- **Example:**
246
193
  ```typescript
247
- const dns = new YqDns({
248
- google: { enabled: true, limit: { concurrency: 15 } },
249
- cloudflare: { enabled: false }
250
- });
194
+ // Update configuration at runtime
195
+ dns.setConfig('google', { enabled: false });
196
+ dns.setConfigs({ cloudflare: { limit: { concurrency: 15 } } });
251
197
  ```
252
198
 
253
- #### Configuration Methods
199
+ ## 📚 API Reference
254
200
 
255
- ##### `setConfig(provider: string, config: ProviderConfig): void`
201
+ The YQ-DNS API is designed for simplicity and flexibility, offering both class-based and functional approaches to DNS resolution. All methods return strongly-typed promises and support optional provider selection, custom timeouts, and advanced configuration options.
256
202
 
257
- Sets configuration for a specific provider.
203
+ ### YqDns Class
258
204
 
259
- **Parameters:**
260
- - `provider`: Provider name ('native', 'google', 'cloudflare', 'quad9')
261
- - `config`: Provider configuration object
205
+ The YqDns class provides a comprehensive DNS resolution interface with full configuration control and advanced features like provider management, concurrency control, and runtime configuration updates.
262
206
 
263
- **Example:**
264
207
  ```typescript
265
- dns.setConfig('google', {
266
- enabled: true,
267
- limit: { concurrency: 20, interval: 1000, intervalCap: 100 }
268
- });
269
- ```
208
+ const dns = new YqDns(config?: YqConfig);
270
209
 
271
- ##### `setConfigs(config: YqConfig): void`
210
+ // Basic DNS resolution methods
211
+ dns.resolve4(hostname: string): Promise<string[]> // IPv4 addresses
212
+ dns.resolve6(hostname: string): Promise<string[]> // IPv6 addresses
213
+ dns.resolveMx(hostname: string): Promise<MxRecord[]> // Mail exchange records
214
+ dns.resolveTxt(hostname: string): Promise<string[][]> // Text records
215
+ dns.resolveCname(hostname: string): Promise<string[]> // Canonical name records
216
+ dns.resolveNs(hostname: string): Promise<string[]> // Name server records
217
+ dns.resolveSoa(hostname: string): Promise<SoaRecord> // Start of Authority
218
+ dns.resolvePtr(ip: string): Promise<string[]> // Reverse DNS lookup
219
+ dns.resolveSrv(hostname: string): Promise<SrvRecord[]> // Service records
220
+ dns.resolveAny(hostname: string): Promise<AnyRecord[]> // All available records
272
221
 
273
- Sets configurations for multiple providers at once.
222
+ // Configuration methods
223
+ dns.setConfig(provider: string, config: ProviderConfig): void
224
+ dns.setConfigs(configs: Partial<YqConfig>): void
274
225
 
275
- **Parameters:**
276
- - `config`: Global configuration object
277
-
278
- **Example:**
279
- ```typescript
280
- dns.setConfigs({
281
- google: { enabled: true, limit: { concurrency: 10 } },
282
- cloudflare: { enabled: false },
283
- native: { enabled: true }
284
- });
226
+ // Email validation
227
+ dns.emailValidator: EmailValidator
285
228
  ```
286
229
 
287
- #### Static Methods
288
-
289
- ##### `YqDns.createEmailValidator(config?: ValidationConfig, dnsConfig?: YqConfig): EmailValidator`
290
-
291
- Creates or returns the singleton email validator instance.
292
-
293
- **Parameters:**
294
- - `config` (optional): Email validation configuration
295
- - `dnsConfig` (optional): DNS configuration for the validator
296
-
297
- **Returns:** EmailValidator instance
298
-
299
- ##### `YqDns.emailValidator: EmailValidator`
300
-
301
- Gets the singleton email validator instance (creates one if it doesn't exist).
302
-
303
230
  ### Standalone Functions
304
231
 
305
- All standalone functions use a default YqDns instance and support the same parameters as their class counterparts.
306
-
307
- #### `resolve4(hostname: string, options?: ResolveOptions, provider?: ProviderName): Promise<string[] | RecordWithTtl[]>`
308
-
309
- Resolves A (IPv4) records for a hostname.
310
-
311
- **Parameters:**
312
- - `hostname`: The hostname to resolve
313
- - `options` (optional): Resolution options (`{ ttl: boolean }`)
314
- - `provider` (optional): Specific provider to use
232
+ Standalone functions provide a lightweight alternative for simple DNS queries without the need for class instantiation. These functions use sensible defaults and automatic provider selection.
315
233
 
316
- **Returns:** Array of IPv4 addresses or records with TTL
317
-
318
- **Example:**
319
234
  ```typescript
320
- // Basic usage
321
- const addresses = await resolve4('example.com');
235
+ import { resolve4, resolveMx, resolveAny } from 'yq-dns';
322
236
 
323
- // With TTL
324
- const withTtl = await resolve4('example.com', { ttl: true });
237
+ // Use directly without creating a class instance
238
+ const addresses = await resolve4('example.com'); // Quick IPv4 resolution
239
+ const mxRecords = await resolveMx('example.com'); // Mail server lookup
240
+ const anyRecords = await resolveAny('example.com'); // Comprehensive DNS query
325
241
 
326
- // With specific provider
242
+ // With optional provider specification
327
243
  const googleResult = await resolve4('example.com', undefined, 'google');
244
+ const cloudflareResult = await resolveMx('example.com', undefined, 'cloudflare');
328
245
  ```
329
246
 
330
- #### `resolve6(hostname: string, options?: ResolveOptions, provider?: ProviderName): Promise<string[] | RecordWithTtl[]>`
331
-
332
- Resolves AAAA (IPv6) records for a hostname.
333
-
334
- #### `resolveAny(hostname: string, provider?: ProviderName): Promise<AnyRecord[]>`
335
-
336
- Resolves ANY records for a hostname.
337
-
338
- #### `resolveCaa(hostname: string, provider?: ProviderName): Promise<CaaRecord[]>`
339
-
340
- Resolves CAA (Certificate Authority Authorization) records.
341
-
342
- #### `resolveCname(hostname: string, provider?: ProviderName): Promise<string[]>`
343
-
344
- Resolves CNAME (Canonical Name) records.
345
-
346
- #### `resolveMx(hostname: string, provider?: ProviderName): Promise<MxRecord[]>`
347
-
348
- Resolves MX (Mail Exchange) records.
349
-
350
- #### `resolveNaptr(hostname: string, provider?: ProviderName): Promise<NaptrRecord[]>`
351
-
352
- Resolves NAPTR (Name Authority Pointer) records.
353
-
354
- #### `resolveNs(hostname: string, provider?: ProviderName): Promise<string[]>`
355
-
356
- Resolves NS (Name Server) records.
357
-
358
- #### `resolvePtr(ip: string, provider?: ProviderName): Promise<string[]>`
359
-
360
- Resolves PTR (Pointer) records for reverse DNS lookup.
361
-
362
- #### `resolveSoa(hostname: string, provider?: ProviderName): Promise<SoaRecord>`
363
-
364
- Resolves SOA (Start of Authority) record.
247
+ ### Method Parameters
365
248
 
366
- #### `resolveSrv(hostname: string, provider?: ProviderName): Promise<SrvRecord[]>`
249
+ Most DNS resolution methods accept the following parameters:
367
250
 
368
- Resolves SRV (Service) records.
251
+ - **hostname/ip**: The domain name or IP address to resolve (string)
252
+ - **options**: Optional configuration object (varies by method)
253
+ - **provider**: Optional provider name for specific provider usage (string)
369
254
 
370
- #### `resolveTlsa(hostname: string, provider?: ProviderName): Promise<TlsaRecord[]>`
255
+ ### Return Types
371
256
 
372
- Resolves TLSA (Transport Layer Security Authentication) records.
257
+ All methods return strongly-typed promises with comprehensive type definitions for maximum TypeScript compatibility and IntelliSense support.
373
258
 
374
- #### `resolveTxt(hostname: string, provider?: ProviderName): Promise<string[][]>`
375
259
 
376
- Resolves TXT records.
377
-
378
- #### `reverse(ip: string, provider?: ProviderName): Promise<string[]>`
379
-
380
- Performs reverse DNS lookup.
381
-
382
- ### DNS Resolution Methods
383
-
384
- All DNS resolution methods in the YqDns class follow the same pattern:
385
-
386
- ```typescript
387
- // Method signature pattern
388
- async methodName(hostname: string, options?: ResolveOptions, provider?: ProviderName): Promise<ReturnType>
389
- ```
390
-
391
- **Common Parameters:**
392
- - `hostname`: The hostname or IP address to resolve
393
- - `options` (optional): Resolution options (currently supports `{ ttl: boolean }`)
394
- - `provider` (optional): Force using a specific provider ('native', 'google', 'cloudflare', 'quad9')
395
-
396
- **Provider Selection Logic:**
397
- 1. If `provider` is specified, use that provider (must be enabled)
398
- 2. Otherwise, randomly select from enabled providers
399
- 3. Prefer providers that are not at queue capacity
400
- 4. Throw error if no providers are enabled
401
260
 
402
261
  ### Email Validation
403
262
 
263
+ The Email Validation system provides comprehensive email address validation, domain analysis, and provider detection. It combines syntax validation, DNS lookups, and an extensive database of email providers to deliver accurate validation results with detailed metadata about the email address and its hosting provider.
264
+
404
265
  #### `EmailValidator` Class
405
266
 
406
- The EmailValidator provides comprehensive email validation and analysis.
267
+ The EmailValidator class is the core component for email validation operations. It provides intelligent email analysis by checking syntax, validating domains through DNS resolution, detecting email providers, and identifying role-based addresses. The validator supports both basic and deep validation modes to accommodate different use cases and performance requirements.
407
268
 
408
269
  ##### `validate(email: string, deep?: boolean): Promise<EmailResponse>`
409
270
 
410
- Validates an email address and determines its provider/service.
271
+ Performs comprehensive email validation and analysis, returning detailed information about the email address including provider detection, webmail availability, and role-based email identification.
411
272
 
412
273
  **Parameters:**
413
- - `email`: Email address to validate
414
- - `deep` (optional): Enable deep validation with additional DNS lookups (default: false)
274
+ - `email`: Email address to validate (string)
275
+ - `deep` (optional): Enable deep validation with additional DNS lookups and extended checks (default: false)
415
276
 
416
277
  **Returns:** EmailResponse object with one of the following structures:
417
278
 
418
- **Success Response:**
279
+ **Success Response Structure:**
419
280
  ```typescript
420
281
  {
421
282
  success: true,
422
283
  data: {
423
- provider: string, // Email provider name
284
+ provider: string, // Email provider name (e.g., "Gmail", "Outlook")
424
285
  email: string, // Normalized email address
425
- role: boolean, // Whether it's a role-based email
286
+ role: boolean, // Whether it's a role-based email (admin, support, etc.)
426
287
  webmail?: string // Webmail URL if available
427
288
  }
428
289
  }
429
290
  ```
430
291
 
431
- **Error Response:**
292
+ **Error Response Structure:**
432
293
  ```typescript
433
294
  {
434
295
  success: false,
435
296
  type: 'Syntanx' | 'Rejected' | 'Invalid' | 'Error',
436
297
  email: string,
437
- message?: string // Only present for 'Error' type
298
+ message?: string // Detailed error message (only present for 'Error' type)
438
299
  }
439
300
  ```
440
301
 
441
- **Example:**
302
+ #### Basic Email Validation Examples
303
+
304
+ **Simple Validation:**
442
305
  ```typescript
306
+ import { YqDns } from 'yq-dns';
307
+
443
308
  const validator = YqDns.emailValidator;
309
+
310
+ // Basic email validation
444
311
  const result = await validator.validate('user@gmail.com');
445
312
  if (result.success) {
446
- console.log('Provider:', result.data.provider);
447
- console.log('Webmail:', result.data.webmail);
448
- console.log('Role email:', result.data.role);
313
+ console.log('✅ Valid email');
314
+ console.log('Provider:', result.data.provider); // "Gmail"
315
+ console.log('Webmail:', result.data.webmail); // "https://mail.google.com"
316
+ console.log('Role email:', result.data.role); // false
449
317
  } else {
450
- console.log('Validation failed:', result.type);
318
+ console.log(' Invalid email:', result.type);
451
319
  }
452
320
  ```
453
321
 
454
- ## 🗂️ DNS Record Types
455
-
456
- ### Supported Record Types
457
-
458
- | Record Type | Description | Return Type |
459
- |-------------|-------------|-------------|
460
- | **A** | IPv4 address records | `string[]` or `RecordWithTtl[]` |
461
- | **AAAA** | IPv6 address records | `string[]` or `RecordWithTtl[]` |
462
- | **ANY** | All available records | `AnyRecord[]` |
463
- | **CAA** | Certificate Authority Authorization | `CaaRecord[]` |
464
- | **CNAME** | Canonical name records | `string[]` |
465
- | **MX** | Mail exchange records | `MxRecord[]` |
466
- | **NAPTR** | Name Authority Pointer | `NaptrRecord[]` |
467
- | **NS** | Name server records | `string[]` |
468
- | **PTR** | Pointer records (reverse DNS) | `string[]` |
469
- | **SOA** | Start of Authority | `SoaRecord` |
470
- | **SRV** | Service records | `SrvRecord[]` |
471
- | **TLSA** | TLS Authentication | `TlsaRecord[]` |
472
- | **TXT** | Text records | `string[][]` |
473
-
474
- ### Type Definitions
475
-
322
+ **Deep Validation Mode:**
476
323
  ```typescript
477
- interface RecordWithTtl {
478
- address: string;
479
- ttl: number;
480
- }
481
-
482
- interface MxRecord {
483
- priority: number;
484
- exchange: string;
485
- }
486
-
487
- interface SrvRecord {
488
- priority: number;
489
- weight: number;
490
- port: number;
491
- name: string;
492
- }
493
-
494
- interface SoaRecord {
495
- nsname: string;
496
- hostmaster: string;
497
- serial: number;
498
- refresh: number;
499
- retry: number;
500
- expire: number;
501
- minttl: number;
502
- }
503
-
504
- interface CaaRecord {
505
- critical: number;
506
- issue?: string;
507
- issuewild?: string;
508
- iodef?: string;
509
- }
510
-
511
- interface NaptrRecord {
512
- flags: string;
513
- service: string;
514
- regexp: string;
515
- replacement: string;
516
- order: number;
517
- preference: number;
518
- }
519
-
520
- interface TlsaRecord {
521
- usage: number;
522
- selector: number;
523
- matchingType: number;
524
- certificate: string;
324
+ // Enable deep validation for thorough analysis
325
+ const deepResult = await validator.validate('admin@company.com', true);
326
+ if (deepResult.success) {
327
+ console.log('Provider:', deepResult.data.provider);
328
+ console.log('Is role-based:', deepResult.data.role); // likely true for "admin"
525
329
  }
526
330
  ```
527
331
 
528
- ## 🔧 Advanced Usage
529
-
530
- ### Rate Limiting
531
-
532
- Configure rate limiting to control request frequency:
332
+ #### Provider Detection Examples
533
333
 
334
+ **Major Email Providers:**
534
335
  ```typescript
535
- const dns = new YqDns({
536
- google: {
537
- enabled: true,
538
- limit: {
539
- concurrency: 5, // Max 5 concurrent requests
540
- interval: 1000, // Per 1 second
541
- intervalCap: 10, // Max 10 requests per interval
542
- carryoverConcurrencyCount: true
543
- }
544
- }
545
- });
546
- ```
336
+ // Gmail detection
337
+ const gmailResult = await validator.validate('john.doe@gmail.com');
338
+ console.log(gmailResult.data?.provider); // "Gmail"
547
339
 
548
- ### Provider Selection
340
+ // Outlook detection
341
+ const outlookResult = await validator.validate('jane@outlook.com');
342
+ console.log(outlookResult.data?.provider); // "Outlook"
549
343
 
550
- ```typescript
551
- // Force specific provider
552
- const googleResult = await resolve4('example.com', undefined, 'google');
553
- const cloudflareResult = await resolve4('example.com', undefined, 'cloudflare');
344
+ // Yahoo detection
345
+ const yahooResult = await validator.validate('user@yahoo.com');
346
+ console.log(yahooResult.data?.provider); // "Yahoo"
554
347
 
555
- // Let the library choose (recommended)
556
- const autoResult = await resolve4('example.com');
557
-
558
- // Disable specific providers
559
- const dns = new YqDns({
560
- quad9: { enabled: false }, // Disable Quad9
561
- native: { enabled: false } // Disable native DNS
562
- });
348
+ // Corporate email detection
349
+ const corpResult = await validator.validate('employee@microsoft.com');
350
+ console.log(corpResult.data?.provider); // "Microsoft"
563
351
  ```
564
352
 
565
- ### Error Handling
353
+ #### Role-Based Email Detection
566
354
 
355
+ **Identifying Role-Based Addresses:**
567
356
  ```typescript
568
- import {
569
- NoEnabledProvidersError,
570
- InvalidHostnameError,
571
- ProviderNotEnabledError,
572
- InvalidProviderError
573
- } from 'yq-dns';
357
+ // Common role-based emails
358
+ const roleEmails = [
359
+ 'admin@company.com',
360
+ 'support@service.com',
361
+ 'info@business.org',
362
+ 'sales@enterprise.net',
363
+ 'noreply@platform.io'
364
+ ];
574
365
 
575
- try {
576
- const result = await resolve4('invalid..hostname');
577
- } catch (error) {
578
- if (error instanceof InvalidHostnameError) {
579
- console.error('Invalid hostname:', error.message);
580
- } else if (error instanceof NoEnabledProvidersError) {
581
- console.error('No DNS providers are enabled');
582
- } else if (error instanceof ProviderNotEnabledError) {
583
- console.error('Requested provider is not enabled:', error.message);
584
- } else {
585
- console.error('DNS resolution failed:', error.message);
366
+ for (const email of roleEmails) {
367
+ const result = await validator.validate(email);
368
+ if (result.success && result.data.role) {
369
+ console.log(`${email} is a role-based email`);
586
370
  }
587
371
  }
588
372
  ```
589
373
 
590
- ### Concurrency Control
374
+ #### Webmail Detection and Access
591
375
 
376
+ **Webmail URL Extraction:**
592
377
  ```typescript
593
- // High-throughput configuration
594
- const highThroughputDns = new YqDns({
595
- google: {
596
- enabled: true,
597
- limit: {
598
- concurrency: 50, // High concurrency
599
- interval: 1000,
600
- intervalCap: 1000 // High rate limit
601
- }
602
- },
603
- cloudflare: {
604
- enabled: true,
605
- limit: {
606
- concurrency: 30,
607
- interval: 1000,
608
- intervalCap: 500
609
- }
610
- }
611
- });
378
+ // Get webmail URLs for popular providers
379
+ const webmailEmails = [
380
+ 'user@gmail.com', // https://mail.google.com
381
+ 'user@outlook.com', // https://outlook.live.com
382
+ 'user@yahoo.com', // https://mail.yahoo.com
383
+ 'user@icloud.com' // https://www.icloud.com/mail
384
+ ];
612
385
 
613
- // Conservative configuration
614
- const conservativeDns = new YqDns({
615
- native: {
616
- enabled: true,
617
- limit: {
618
- concurrency: 2, // Low concurrency
619
- interval: 2000, // Longer interval
620
- intervalCap: 5 // Low rate limit
621
- }
386
+ for (const email of webmailEmails) {
387
+ const result = await validator.validate(email);
388
+ if (result.success && result.data.webmail) {
389
+ console.log(`${email} -> ${result.data.webmail}`);
622
390
  }
623
- });
624
- ```
625
-
626
- ## 📧 Email Validation System
627
-
628
- ### Domain Validation
629
-
630
- Validate email domains with comprehensive analysis:
631
-
632
- ```typescript
633
- const validator = YqDns.emailValidator;
634
-
635
- // Basic domain validation
636
- const result = await validator.validate('user@example.com');
637
- if (result.success) {
638
- console.log('Domain is valid');
639
- console.log('Provider:', result.data.provider);
640
- }
641
- ```
642
-
643
- ### Webmail Detection
644
-
645
- Detect and identify webmail interfaces:
646
-
647
- ```typescript
648
- const result = await validator.validate('user@gmail.com');
649
- if (result.success && result.data.webmail) {
650
- console.log('Webmail URL:', result.data.webmail);
651
- // Output: https://mail.google.com
652
391
  }
653
392
  ```
654
393
 
655
- ### Provider Recognition
656
-
657
- Recognize 100+ email providers:
394
+ #### Batch Email Validation
658
395
 
396
+ **Validating Multiple Emails:**
659
397
  ```typescript
660
- const result = await validator.validate('user@outlook.com');
661
- if (result.success) {
662
- console.log('Provider:', result.data.provider);
663
- // Output: 'Outlook'
398
+ async function validateEmailBatch(emails: string[]) {
399
+ const results = await Promise.allSettled(
400
+ emails.map(email => validator.validate(email))
401
+ );
402
+
403
+ return emails.map((email, index) => {
404
+ const result = results[index];
405
+ if (result.status === 'fulfilled' && result.value.success) {
406
+ return {
407
+ email,
408
+ valid: true,
409
+ provider: result.value.data.provider,
410
+ role: result.value.data.role,
411
+ webmail: result.value.data.webmail
412
+ };
413
+ } else {
414
+ return {
415
+ email,
416
+ valid: false,
417
+ error: result.status === 'fulfilled' ? result.value.type : 'validation_failed'
418
+ };
419
+ }
420
+ });
664
421
  }
665
- ```
666
-
667
- ### Supported Email Providers
668
-
669
- - **Major Providers**: Gmail, Outlook, Yahoo, iCloud, ProtonMail
670
- - **Business**: Office 365, Google Workspace, Zoho, Fastmail
671
- - **Regional**: 163.com, QQ.com, Mail.ru, Yandex, Naver
672
- - **Hosting**: GoDaddy, Namecheap, Rackspace, Amazon SES
673
- - **Security**: Mimecast, Proofpoint, Barracuda
674
- - **And 80+ more providers...
675
-
676
- ## 🔷 TypeScript Support
677
-
678
- ### Full Type Safety
679
-
680
- ```typescript
681
- import { YqDns, MxRecord, SrvRecord, ProviderName } from 'yq-dns';
682
422
 
683
- // Strongly typed configuration
684
- const config: YqConfig = {
685
- google: {
686
- enabled: true,
687
- limit: {
688
- concurrency: 10,
689
- interval: 1000,
690
- intervalCap: 100
423
+ // Usage example
424
+ const emailList = [
425
+ 'valid@gmail.com',
426
+ 'invalid.email',
427
+ 'admin@company.com',
428
+ 'user@nonexistent-domain.xyz'
429
+ ];
430
+
431
+ const batchResults = await validateEmailBatch(emailList);
432
+ console.log('Batch validation results:', batchResults);
433
+ ```
434
+
435
+ #### Error Handling and Response Types
436
+
437
+ **Comprehensive Error Handling:**
438
+ ```typescript
439
+ async function handleEmailValidation(email: string) {
440
+ try {
441
+ const result = await validator.validate(email);
442
+
443
+ if (result.success) {
444
+ return {
445
+ status: 'valid',
446
+ data: result.data
447
+ };
448
+ } else {
449
+ // Handle different error types
450
+ switch (result.type) {
451
+ case 'Syntanx':
452
+ return { status: 'syntax_error', message: 'Invalid email format' };
453
+ case 'Invalid':
454
+ return { status: 'invalid_domain', message: 'Domain does not exist' };
455
+ case 'Rejected':
456
+ return { status: 'rejected', message: 'Email rejected by provider' };
457
+ case 'Error':
458
+ return { status: 'validation_error', message: result.message };
459
+ default:
460
+ return { status: 'unknown_error', message: 'Validation failed' };
461
+ }
691
462
  }
463
+ } catch (error) {
464
+ return {
465
+ status: 'exception',
466
+ message: error instanceof Error ? error.message : 'Unexpected error'
467
+ };
692
468
  }
693
- };
694
-
695
- // Strongly typed results
696
- const mxRecords: MxRecord[] = await resolveMx('example.com');
697
- const srvRecords: SrvRecord[] = await resolveSrv('_sip._tcp.example.com');
698
-
699
- // Type-safe provider names
700
- const provider: ProviderName = 'google';
701
- const addresses = await resolve4('example.com', undefined, provider);
702
- ```
703
-
704
- ### Generic Overloads
705
-
706
- ```typescript
707
- // Method overloads for different return types
708
- const addresses: string[] = await resolve4('example.com');
709
- const withTtl: RecordWithTtl[] = await resolve4('example.com', { ttl: true });
710
- ```
711
-
712
- ### Custom Types
713
-
714
- ```typescript
715
- // Import specific types as needed
716
- import type {
717
- YqConfig,
718
- ProviderConfig,
719
- ProviderName,
720
- RecordType,
721
- AnyRecord,
722
- RecordWithTtl,
723
- ResolveOptions,
724
- ResolveWithTtlOptions
725
- } from 'yq-dns';
726
- ```
727
-
728
- ## ⚡ Performance
729
-
730
- ### Benchmarks
731
-
732
- - **Concurrent Requests**: Up to 50 concurrent DNS requests per provider
733
- - **Response Time**: Average 50-200ms depending on provider and location
734
- - **Throughput**: 1000+ requests per second with optimal configuration
735
- - **Memory Usage**: Minimal memory footprint with efficient queue management
736
-
737
- ### Optimization Tips
738
-
739
- 1. **Use Multiple Providers**: Enable multiple providers for better load distribution
740
- 2. **Tune Concurrency**: Adjust concurrency limits based on your use case
741
- 3. **Provider Selection**: Use faster providers for time-sensitive applications
742
- 4. **Caching**: Implement your own caching layer for frequently accessed domains
743
- 5. **Error Handling**: Implement proper retry logic for failed requests
744
-
745
- ### Performance Configuration
746
-
747
- ```typescript
748
- // High-performance configuration
749
- const performanceDns = new YqDns({
750
- google: {
751
- enabled: true,
752
- limit: { concurrency: 20, interval: 1000, intervalCap: 200 }
753
- },
754
- cloudflare: {
755
- enabled: true,
756
- limit: { concurrency: 20, interval: 1000, intervalCap: 200 }
757
- },
758
- quad9: {
759
- enabled: true,
760
- limit: { concurrency: 15, interval: 1000, intervalCap: 150 }
761
- },
762
- native: {
763
- enabled: true,
764
- limit: { concurrency: 10, interval: 1000, intervalCap: 100 }
765
- }
766
- });
767
- ```
768
-
769
- ## 📖 Examples
770
-
771
- ### Basic DNS Resolution
772
-
773
- ```typescript
774
- import { resolve4, resolveMx, resolveAny } from 'yq-dns';
775
-
776
- // Resolve multiple record types
777
- const [addresses, mxRecords, anyRecords] = await Promise.all([
778
- resolve4('example.com'),
779
- resolveMx('example.com'),
780
- resolveAny('example.com')
781
- ]);
469
+ }
782
470
 
783
- console.log('A Records:', addresses);
784
- console.log('MX Records:', mxRecords);
785
- console.log('All Records:', anyRecords);
471
+ // Usage
472
+ const validationResult = await handleEmailValidation('test@example.com');
473
+ console.log(validationResult);
786
474
  ```
787
475
 
788
- ### Email Domain Analysis
476
+ #### Advanced Use Cases
789
477
 
478
+ **Email Domain Analysis:**
790
479
  ```typescript
791
- import { YqDns } from 'yq-dns';
792
-
793
- const validator = YqDns.emailValidator;
794
-
795
480
  async function analyzeEmailDomain(email: string) {
796
- const result = await validator.validate(email);
481
+ const result = await validator.validate(email, true); // Deep validation
797
482
 
798
483
  if (result.success) {
484
+ const domain = email.split('@')[1];
799
485
  return {
800
- isValid: true,
486
+ email: result.data.email,
487
+ domain,
801
488
  provider: result.data.provider,
802
489
  hasWebmail: !!result.data.webmail,
803
490
  webmailUrl: result.data.webmail,
804
- isRole: result.data.role
491
+ isRoleBased: result.data.role,
492
+ isPersonal: ['Gmail', 'Yahoo', 'Outlook', 'iCloud'].includes(result.data.provider),
493
+ isCorporate: !['Gmail', 'Yahoo', 'Outlook', 'iCloud'].includes(result.data.provider)
805
494
  };
806
495
  } else {
807
496
  return {
808
- isValid: false,
809
- error: result.type,
810
- message: result.message
497
+ email,
498
+ valid: false,
499
+ errorType: result.type,
500
+ errorMessage: result.message
811
501
  };
812
502
  }
813
503
  }
814
504
 
815
- const analysis = await analyzeEmailDomain('user@gmail.com');
816
- console.log(analysis);
817
- ```
818
-
819
- ### Bulk DNS Resolution
820
-
821
- ```typescript
822
- import { YqDns } from 'yq-dns';
823
-
824
- const dns = new YqDns({
825
- google: { enabled: true, limit: { concurrency: 10 } },
826
- cloudflare: { enabled: true, limit: { concurrency: 10 } }
827
- });
828
-
829
- async function bulkResolve(hostnames: string[]) {
830
- const results = await Promise.allSettled(
831
- hostnames.map(hostname => dns.resolve4(hostname))
832
- );
833
-
834
- return results.map((result, index) => ({
835
- hostname: hostnames[index],
836
- success: result.status === 'fulfilled',
837
- addresses: result.status === 'fulfilled' ? result.value : [],
838
- error: result.status === 'rejected' ? result.reason.message : null
839
- }));
840
- }
841
-
842
- const domains = ['google.com', 'github.com', 'stackoverflow.com'];
843
- const results = await bulkResolve(domains);
844
- console.log(results);
505
+ const analysis = await analyzeEmailDomain('ceo@apple.com');
506
+ console.log('Email analysis:', analysis);
845
507
  ```
846
508
 
847
- ### Service Discovery
509
+ ## 🗂️ DNS Record Types
848
510
 
849
- ```typescript
850
- import { resolveSrv, resolveTxt } from 'yq-dns';
851
-
852
- async function discoverServices(domain: string) {
853
- const [sipServices, httpServices, txtRecords] = await Promise.all([
854
- resolveSrv(`_sip._tcp.${domain}`).catch(() => []),
855
- resolveSrv(`_http._tcp.${domain}`).catch(() => []),
856
- resolveTxt(domain).catch(() => [])
857
- ]);
858
-
859
- return {
860
- sip: sipServices,
861
- http: httpServices,
862
- txt: txtRecords
863
- };
864
- }
511
+ YQ-DNS supports all standard DNS record types with comprehensive parsing and type-safe return values. Each record type is optimized for specific use cases, from basic domain resolution to advanced service discovery and email routing. The library automatically handles record parsing and provides structured data objects for easy consumption.
865
512
 
866
- const services = await discoverServices('example.com');
867
- console.log('Discovered services:', services);
868
- ```
513
+ | Record Type | Description | Use Cases | Return Type |
514
+ |-------------|-------------|-----------|-------------|
515
+ | **A** | IPv4 address records | Web hosting, basic domain resolution | `string[]` |
516
+ | **AAAA** | IPv6 address records | Modern networking, dual-stack configurations | `string[]` |
517
+ | **MX** | Mail exchange records | Email routing, mail server discovery | `MxRecord[]` |
518
+ | **TXT** | Text records | Domain verification, SPF, DKIM, configuration | `string[][]` |
519
+ | **CNAME** | Canonical name records | Domain aliases, CDN configuration | `string[]` |
520
+ | **NS** | Name server records | DNS delegation, authoritative servers | `string[]` |
521
+ | **SOA** | Start of Authority | Zone information, DNS administration | `SoaRecord` |
522
+ | **SRV** | Service records | Service discovery, load balancing | `SrvRecord[]` |
523
+ | **PTR** | Pointer records (reverse DNS) | IP to domain mapping, security verification | `string[]` |
524
+ | **CAA** | Certificate Authority Authorization | SSL certificate validation | `CaaRecord[]` |
525
+ | **NAPTR** | Name Authority Pointer | Complex service resolution | `NaptrRecord[]` |
526
+ | **TLSA** | Transport Layer Security Authentication | Certificate pinning, security | `TlsaRecord[]` |
527
+ | **ANY** | All available records | Comprehensive domain analysis | `AnyRecord[]` |
869
528
 
870
- ### Custom Provider Configuration
529
+ ### Record Type Examples
871
530
 
872
531
  ```typescript
873
- import { YqDns } from 'yq-dns';
874
-
875
- // Create DNS resolver with custom configuration
876
- const customDns = new YqDns();
877
-
878
- // Configure providers at runtime
879
- customDns.setConfig('google', {
880
- enabled: true,
881
- limit: {
882
- concurrency: 15,
883
- interval: 1000,
884
- intervalCap: 50
885
- }
886
- });
532
+ // A records - IPv4 addresses
533
+ const ipv4 = await resolve4('example.com');
534
+ // Returns: ['93.184.216.34']
887
535
 
888
- customDns.setConfig('cloudflare', {
889
- enabled: true,
890
- limit: {
891
- concurrency: 10,
892
- interval: 2000,
893
- intervalCap: 30
894
- }
895
- });
536
+ // MX records - Mail servers with priority
537
+ const mailServers = await resolveMx('example.com');
538
+ // Returns: [{ priority: 10, exchange: 'mail.example.com' }]
896
539
 
897
- // Disable other providers
898
- customDns.setConfigs({
899
- quad9: { enabled: false },
900
- native: { enabled: false }
901
- });
540
+ // TXT records - Text data (SPF, DKIM, etc.)
541
+ const txtRecords = await resolveTxt('example.com');
542
+ // Returns: [['v=spf1 include:_spf.example.com ~all']]
902
543
 
903
- const result = await customDns.resolve4('example.com');
904
- console.log('Custom DNS result:', result);
544
+ // SRV records - Service discovery
545
+ const services = await resolveSrv('_sip._tcp.example.com');
546
+ // Returns: [{ priority: 10, weight: 5, port: 5060, name: 'sip.example.com' }]
905
547
  ```
906
548
 
907
- ## 🔧 Troubleshooting
908
549
 
909
- ### Common Issues
910
550
 
911
- #### No Enabled Providers Error
551
+ ## 🔷 TypeScript Support
912
552
 
913
- ```typescript
914
- // Problem: All providers are disabled
915
- const dns = new YqDns({
916
- google: { enabled: false },
917
- cloudflare: { enabled: false },
918
- quad9: { enabled: false },
919
- native: { enabled: false }
920
- });
553
+ YQ-DNS is built with TypeScript from the ground up, providing comprehensive type definitions, full IntelliSense support, and compile-time type checking. The library exports all necessary types and interfaces, ensuring type safety across your entire DNS resolution workflow and eliminating runtime type errors.
921
554
 
922
- // Solution: Enable at least one provider
923
- const dns = new YqDns({
924
- google: { enabled: true }
925
- });
926
- ```
927
-
928
- #### Rate Limiting Issues
555
+ ### Complete Type Safety
929
556
 
930
557
  ```typescript
931
- // Problem: Too aggressive rate limiting
932
- const dns = new YqDns({
933
- google: {
934
- enabled: true,
935
- limit: {
936
- concurrency: 1,
937
- interval: 5000,
938
- intervalCap: 1
939
- }
940
- }
941
- });
942
-
943
- // Solution: Increase limits
944
- const dns = new YqDns({
945
- google: {
946
- enabled: true,
947
- limit: {
948
- concurrency: 10,
949
- interval: 1000,
950
- intervalCap: 50
951
- }
952
- }
953
- });
954
- ```
558
+ import { YqDns, MxRecord, SrvRecord, ProviderName } from 'yq-dns';
955
559
 
956
- #### Provider Not Available
560
+ // Strongly typed results with full IntelliSense
561
+ const mxRecords: MxRecord[] = await resolveMx('example.com');
562
+ const srvRecords: SrvRecord[] = await resolveSrv('_sip._tcp.example.com');
957
563
 
958
- ```typescript
959
- try {
960
- const result = await resolve4('example.com', undefined, 'invalidprovider');
961
- } catch (error) {
962
- if (error instanceof InvalidProviderError) {
963
- console.error('Invalid provider name');
964
- // Use valid provider names: 'native', 'google', 'cloudflare', 'quad9'
965
- }
966
- }
564
+ // Type-safe provider names prevent typos
565
+ const provider: ProviderName = 'google';
566
+ const addresses = await resolve4('example.com', undefined, provider);
967
567
  ```
968
568
 
969
- ### Debug Mode
569
+ ### Available Type Exports
970
570
 
971
571
  ```typescript
972
- // Enable debug logging (if implemented)
973
- process.env.DEBUG = 'yq-dns:*';
974
-
975
- // Or check queue status
976
- const dns = new YqDns();
977
- console.log('Queue sizes:', {
978
- google: dns.getProvider('google')?.queueSize,
979
- cloudflare: dns.getProvider('cloudflare')?.queueSize
980
- });
572
+ // Core types
573
+ import {
574
+ YqDns, // Main DNS class
575
+ ProviderName, // 'google' | 'cloudflare' | 'quad9' | 'native'
576
+ YqConfig, // Configuration interface
577
+ ProviderConfig, // Individual provider configuration
578
+
579
+ // DNS record types
580
+ MxRecord, // Mail exchange record
581
+ SrvRecord, // Service record
582
+ SoaRecord, // Start of Authority record
583
+ CaaRecord, // Certificate Authority Authorization
584
+ NaptrRecord, // Name Authority Pointer
585
+ TlsaRecord, // Transport Layer Security Authentication
586
+ AnyRecord, // Union of all record types
587
+
588
+ // Email validation types
589
+ EmailValidator, // Email validation class
590
+ EmailResponse, // Validation response type
591
+ EmailData, // Successful validation data
592
+ EmailError // Validation error type
593
+ } from 'yq-dns';
981
594
  ```
982
595
 
983
- ### Performance Issues
984
-
985
- 1. **Check Provider Status**: Ensure providers are not at capacity
986
- 2. **Adjust Concurrency**: Increase concurrency limits if needed
987
- 3. **Enable Multiple Providers**: Use multiple providers for load distribution
988
- 4. **Monitor Network**: Check network connectivity to DoH endpoints
596
+ ### Generic Type Support
989
597
 
990
- ## 🤝 Contributing
991
-
992
- We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
993
-
994
- ### Development Setup
995
-
996
- ```bash
997
- # Clone the repository
998
- git clone https://github.com/yuniqsolutions/yq-dns.git
999
- cd yq-dns
1000
-
1001
- # Install dependencies
1002
- npm install
598
+ ```typescript
599
+ // Generic functions with type inference
600
+ const resolveWithType = async <T>(hostname: string, type: string): Promise<T> => {
601
+ // Type-safe resolution with custom return types
602
+ return await dns.resolveAny(hostname) as T;
603
+ };
1003
604
 
1004
- # Build the project
1005
- npm run build
605
+ // Usage with automatic type inference
606
+ const mxRecords = await resolveWithType<MxRecord[]>('example.com', 'MX');
607
+ ```
1006
608
 
1007
- # Run tests
1008
- npm test
1009
609
 
1010
- # Lint code
1011
- npm run lint
1012
- ```
1013
610
 
1014
- ### Reporting Issues
1015
611
 
1016
- Please report issues on our [GitHub Issues](https://github.com/yuniqsolutions/yq-dns/issues) page.
1017
612
 
1018
613
  ## 📄 License
1019
614
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yq-dns",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "A promise-based DNS resolver that aggregates multiple DNS-over-HTTPS (DoH) providers with concurrency control",
5
5
  "main": "dist/index.js",
6
6
  "types": "/index.d.ts",