@emailcheck/email-validator-js 2.12.0 → 2.13.1-beta.1

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.
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Generic cache interface that can be implemented by any cache store
3
+ * including in-memory LRU cache, Redis, Memcached, etc.
4
+ */
5
+ export interface ICacheStore<T = any> {
6
+ /**
7
+ * Get a value from the cache
8
+ * @param key - The cache key
9
+ * @returns The cached value or null/undefined if not found or expired
10
+ */
11
+ get(key: string): Promise<T | null | undefined> | T | null | undefined;
12
+ /**
13
+ * Set a value in the cache with optional TTL
14
+ * @param key - The cache key
15
+ * @param value - The value to cache
16
+ * @param ttlMs - Optional TTL in milliseconds. If not provided, use default TTL
17
+ */
18
+ set(key: string, value: T, ttlMs?: number): Promise<void> | void;
19
+ /**
20
+ * Delete a value from the cache
21
+ * @param key - The cache key
22
+ */
23
+ delete(key: string): Promise<boolean> | boolean;
24
+ /**
25
+ * Check if a key exists in the cache
26
+ * @param key - The cache key
27
+ */
28
+ has(key: string): Promise<boolean> | boolean;
29
+ /**
30
+ * Clear all values from the cache
31
+ */
32
+ clear(): Promise<void> | void;
33
+ /**
34
+ * Get the current size of the cache (number of entries)
35
+ * Returns undefined if size is not applicable (e.g., Redis)
36
+ */
37
+ size?(): number | undefined;
38
+ }
39
+ /**
40
+ * Synchronous cache interface for in-memory caches
41
+ */
42
+ export interface ISyncCacheStore<T = any> {
43
+ /**
44
+ * Get a value from the cache
45
+ * @param key - The cache key
46
+ * @returns The cached value or null/undefined if not found or expired
47
+ */
48
+ get(key: string): T | null | undefined;
49
+ /**
50
+ * Set a value in the cache with optional TTL
51
+ * @param key - The cache key
52
+ * @param value - The value to cache
53
+ * @param ttlMs - Optional TTL in milliseconds. If not provided, use default TTL
54
+ */
55
+ set(key: string, value: T, ttlMs?: number): void;
56
+ /**
57
+ * Delete a value from the cache
58
+ * @param key - The cache key
59
+ */
60
+ delete(key: string): boolean;
61
+ /**
62
+ * Check if a key exists in the cache
63
+ * @param key - The cache key
64
+ */
65
+ has(key: string): boolean;
66
+ /**
67
+ * Clear all values from the cache
68
+ */
69
+ clear(): void;
70
+ /**
71
+ * Get the current size of the cache (number of entries)
72
+ */
73
+ size?(): number;
74
+ }
75
+ /**
76
+ * Cache configuration for different cache types
77
+ */
78
+ export interface CacheConfig {
79
+ /** Maximum number of entries (for LRU caches) */
80
+ maxSize?: number;
81
+ /** Default TTL in milliseconds */
82
+ ttlMs?: number;
83
+ /** Custom cache store implementation */
84
+ store?: ICacheStore;
85
+ }
86
+ /**
87
+ * Cache holder interface for typed caches
88
+ */
89
+ export interface ICache {
90
+ mx: ICacheStore<string[]>;
91
+ disposable: ICacheStore<boolean>;
92
+ free: ICacheStore<boolean>;
93
+ domainValid: ICacheStore<boolean>;
94
+ smtp: ICacheStore<boolean | null>;
95
+ domainSuggestion: ICacheStore<{
96
+ suggested: string;
97
+ confidence: number;
98
+ } | null>;
99
+ whois: ICacheStore<any>;
100
+ }
101
+ /**
102
+ * Default TTL values in milliseconds
103
+ */
104
+ export declare const DEFAULT_CACHE_TTL: {
105
+ mx: number;
106
+ disposable: number;
107
+ free: number;
108
+ domainValid: number;
109
+ smtp: number;
110
+ domainSuggestion: number;
111
+ whois: number;
112
+ };
113
+ /**
114
+ * Default cache sizes
115
+ */
116
+ export declare const DEFAULT_CACHE_SIZE: {
117
+ mx: number;
118
+ disposable: number;
119
+ free: number;
120
+ domainValid: number;
121
+ smtp: number;
122
+ domainSuggestion: number;
123
+ whois: number;
124
+ };
package/dist/cache.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { ICache, ICacheStore } from './cache-interface';
1
2
  import type { ParsedWhoisResult } from './whois-parser';
2
3
  export declare const mxCache: import("tiny-lru").LRU<string[]>;
3
4
  export declare const disposableCache: import("tiny-lru").LRU<boolean>;
@@ -9,4 +10,31 @@ export declare const domainSuggestionCache: import("tiny-lru").LRU<{
9
10
  confidence: number;
10
11
  } | null>;
11
12
  export declare const whoisCache: import("tiny-lru").LRU<ParsedWhoisResult>;
13
+ /**
14
+ * Set a global custom cache instance to use instead of the default LRU caches
15
+ */
16
+ export declare function setCustomCache(cache: ICache): void;
17
+ /**
18
+ * Get the current global custom cache instance
19
+ */
20
+ export declare function getCustomCache(): ICache | null;
21
+ /**
22
+ * Reset to use default LRU caches
23
+ */
24
+ export declare function resetToDefaultCache(): void;
25
+ /**
26
+ * Get cache adapter that works with passed cache, global cache, or default LRU
27
+ */
28
+ export declare function getCacheStore<T>(defaultLru: any, cacheType: keyof ICache, passedCache?: ICache | null): ICacheStore<T>;
29
+ export declare const mxCacheStore: (passedCache?: ICache | null) => ICacheStore<string[]>;
30
+ export declare const disposableCacheStore: (passedCache?: ICache | null) => ICacheStore<boolean>;
31
+ export declare const freeCacheStore: (passedCache?: ICache | null) => ICacheStore<boolean>;
32
+ export declare const domainValidCacheStore: (passedCache?: ICache | null) => ICacheStore<boolean>;
33
+ export declare const smtpCacheStore: (passedCache?: ICache | null) => ICacheStore<boolean | null>;
34
+ export declare const domainSuggestionCacheStore: (passedCache?: ICache | null) => ICacheStore<{
35
+ suggested: string;
36
+ confidence: number;
37
+ } | null>;
38
+ export declare const whoisCacheStore: (passedCache?: ICache | null) => ICacheStore<ParsedWhoisResult>;
12
39
  export declare function clearAllCaches(): void;
40
+ export type { ICache, ICacheStore } from './cache-interface';
package/dist/dns.d.ts CHANGED
@@ -1 +1,2 @@
1
- export declare function resolveMxRecords(domain: string): Promise<string[]>;
1
+ import type { ICache } from './cache-interface';
2
+ export declare function resolveMxRecords(domain: string, cache?: ICache | null): Promise<string[]>;
@@ -5,9 +5,13 @@ import type { DomainSuggestion, ISuggestDomainParams } from './types';
5
5
  */
6
6
  export declare const COMMON_EMAIL_DOMAINS: string[];
7
7
  /**
8
- * Default domain suggestion method using string similarity
8
+ * Default domain suggestion method using string similarity (sync version)
9
9
  */
10
10
  export declare function defaultDomainSuggestionMethod(domain: string, commonDomains?: string[]): DomainSuggestion | null;
11
+ /**
12
+ * Async version of default domain suggestion method
13
+ */
14
+ export declare function defaultDomainSuggestionMethodAsync(domain: string, commonDomains?: string[]): Promise<DomainSuggestion | null>;
11
15
  /**
12
16
  * Suggest a corrected domain for a potentially misspelled email domain
13
17
  * @param params - Parameters including domain and optional custom method
@@ -20,7 +24,7 @@ export declare function suggestDomain(params: ISuggestDomainParams): DomainSugge
20
24
  * @param commonDomains - Optional list of common domains to check against
21
25
  * @returns Domain suggestion with confidence score, or null if no suggestion
22
26
  */
23
- export declare function suggestEmailDomain(email: string, commonDomains?: string[]): DomainSuggestion | null;
27
+ export declare function suggestEmailDomain(email: string, commonDomains?: string[]): Promise<DomainSuggestion | null>;
24
28
  /**
25
29
  * Check if a domain is in the common domains list
26
30
  * @param domain - Domain to check
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { type DetailedVerificationResult, type IVerifyEmailParams, type IVerifyEmailResult } from './types';
1
+ import type { ICache } from './cache-interface';
2
+ import { type DetailedVerificationResult, type IVerifyEmailParams } from './types';
2
3
  export { verifyEmailBatch } from './batch';
3
4
  export { clearAllCaches } from './cache';
4
5
  export { COMMON_EMAIL_DOMAINS, defaultDomainSuggestionMethod, getDomainSimilarity, isCommonDomain, suggestDomain, suggestEmailDomain, } from './domain-suggester';
@@ -6,14 +7,10 @@ export { defaultNameDetectionMethod, detectName, detectNameFromEmail } from './n
6
7
  export * from './types';
7
8
  export { isValidEmail, isValidEmailDomain } from './validator';
8
9
  export { getDomainAge, getDomainRegistrationStatus } from './whois';
9
- export declare function isDisposableEmail(emailOrDomain: string): boolean;
10
- export declare function isFreeEmail(emailOrDomain: string): boolean;
10
+ export declare function isDisposableEmail(emailOrDomain: string, cache?: ICache | null): Promise<boolean>;
11
+ export declare function isFreeEmail(emailOrDomain: string, cache?: ICache | null): Promise<boolean>;
11
12
  export declare const domainPorts: Record<string, number>;
12
13
  /**
13
- * Verify email address with basic result format (backward compatible)
14
+ * Verify email address
14
15
  */
15
- export declare function verifyEmail(params: IVerifyEmailParams): Promise<IVerifyEmailResult>;
16
- /**
17
- * Verify email address with detailed result format
18
- */
19
- export declare function verifyEmailDetailed(params: IVerifyEmailParams): Promise<DetailedVerificationResult>;
16
+ export declare function verifyEmail(params: IVerifyEmailParams): Promise<DetailedVerificationResult>;