@emailcheck/email-validator-js 2.13.1-beta.7 → 2.13.1-beta.9
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.
- package/README.md +135 -181
- package/dist/cache-interface.d.ts +6 -74
- package/dist/cache.d.ts +34 -30
- package/dist/domain-suggester.d.ts +4 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +88 -84
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +112 -87
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/whois.d.ts +3 -2
- package/package.json +1 -1
- package/dist/cache-factory.d.ts +0 -39
package/README.md
CHANGED
|
@@ -442,11 +442,18 @@ isValidEmailDomain('mydomain.com'); // true
|
|
|
442
442
|
isValidEmailDomain('example.invalid'); // false
|
|
443
443
|
```
|
|
444
444
|
|
|
445
|
-
####
|
|
446
|
-
Clear all internal caches (including domain suggestions).
|
|
447
|
-
|
|
445
|
+
#### Cache Management
|
|
448
446
|
```typescript
|
|
449
|
-
|
|
447
|
+
import { getDefaultCache, clearDefaultCache, resetDefaultCache } from '@emailcheck/email-validator-js';
|
|
448
|
+
|
|
449
|
+
// Get the default cache instance (singleton)
|
|
450
|
+
const defaultCache = getDefaultCache();
|
|
451
|
+
|
|
452
|
+
// Clear all entries from the default cache
|
|
453
|
+
clearDefaultCache();
|
|
454
|
+
|
|
455
|
+
// Reset to a fresh cache instance
|
|
456
|
+
resetDefaultCache();
|
|
450
457
|
```
|
|
451
458
|
|
|
452
459
|
### Types and Interfaces
|
|
@@ -797,32 +804,65 @@ clearAllCaches();
|
|
|
797
804
|
|
|
798
805
|
The library supports parameter-based cache injection, allowing you to use custom cache backends like Redis, Memcached, or any LRU-compatible cache implementation.
|
|
799
806
|
|
|
800
|
-
###
|
|
807
|
+
### 📦 Performance & Caching
|
|
808
|
+
|
|
809
|
+
The library includes a built-in LRU cache for all operations. By default, it uses a lazy-loaded singleton cache instance.
|
|
801
810
|
|
|
802
|
-
####
|
|
811
|
+
#### Default Cache Usage
|
|
803
812
|
```typescript
|
|
804
|
-
import {
|
|
805
|
-
|
|
806
|
-
//
|
|
807
|
-
const
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
smtp: 1800000, // 30 minutes for SMTP verification
|
|
813
|
+
import { verifyEmail } from '@emailcheck/email-validator-js';
|
|
814
|
+
|
|
815
|
+
// No cache setup needed - uses default LRU cache automatically
|
|
816
|
+
const result = await verifyEmail({
|
|
817
|
+
emailAddress: 'user@example.com',
|
|
818
|
+
verifyMx: true,
|
|
819
|
+
verifySmtp: true
|
|
812
820
|
});
|
|
813
821
|
|
|
822
|
+
// Subsequent calls with the same email will use cached results
|
|
823
|
+
const result2 = await verifyEmail({
|
|
824
|
+
emailAddress: 'user@example.com',
|
|
825
|
+
verifyMx: true,
|
|
826
|
+
verifySmtp: true
|
|
827
|
+
});
|
|
828
|
+
```
|
|
829
|
+
|
|
830
|
+
#### Custom Cache Implementation
|
|
831
|
+
|
|
832
|
+
Create your own cache by implementing the `ICache` interface:
|
|
833
|
+
|
|
834
|
+
```typescript
|
|
835
|
+
import { verifyEmail, type ICache, ICacheStore, DEFAULT_CACHE_OPTIONS } from '@emailcheck/email-validator-js';
|
|
836
|
+
import { LRUAdapter } from '@emailcheck/email-validator-js';
|
|
837
|
+
|
|
838
|
+
// Create custom cache with LRU adapters
|
|
839
|
+
const customCache: ICache = {
|
|
840
|
+
mx: new LRUAdapter<string[]>(DEFAULT_CACHE_OPTIONS.maxSize.mx, DEFAULT_CACHE_OPTIONS.ttl.mx),
|
|
841
|
+
disposable: new LRUAdapter<boolean>(DEFAULT_CACHE_OPTIONS.maxSize.disposable, DEFAULT_CACHE_OPTIONS.ttl.disposable),
|
|
842
|
+
free: new LRUAdapter<boolean>(DEFAULT_CACHE_OPTIONS.maxSize.free, DEFAULT_CACHE_OPTIONS.ttl.free),
|
|
843
|
+
domainValid: new LRUAdapter<boolean>(DEFAULT_CACHE_OPTIONS.maxSize.domainValid, DEFAULT_CACHE_OPTIONS.ttl.domainValid),
|
|
844
|
+
smtp: new LRUAdapter<boolean | null>(DEFAULT_CACHE_OPTIONS.maxSize.smtp, DEFAULT_CACHE_OPTIONS.ttl.smtp),
|
|
845
|
+
domainSuggestion: new LRUAdapter<{ suggested: string; confidence: number } | null>(
|
|
846
|
+
DEFAULT_CACHE_OPTIONS.maxSize.domainSuggestion,
|
|
847
|
+
DEFAULT_CACHE_OPTIONS.ttl.domainSuggestion
|
|
848
|
+
),
|
|
849
|
+
whois: new LRUAdapter<any>(DEFAULT_CACHE_OPTIONS.maxSize.whois, DEFAULT_CACHE_OPTIONS.ttl.whois),
|
|
850
|
+
};
|
|
851
|
+
|
|
814
852
|
// Use with email verification
|
|
815
853
|
const result = await verifyEmail({
|
|
816
854
|
emailAddress: 'user@mydomain.com',
|
|
817
855
|
verifyMx: true,
|
|
818
856
|
verifySmtp: true,
|
|
819
|
-
cache:
|
|
857
|
+
cache: customCache // Pass the cache instance
|
|
820
858
|
});
|
|
821
859
|
```
|
|
822
860
|
|
|
823
|
-
#### Redis Cache
|
|
861
|
+
#### Redis Cache Implementation
|
|
862
|
+
|
|
824
863
|
```typescript
|
|
825
|
-
import {
|
|
864
|
+
import { verifyEmail, type ICache, ICacheStore } from '@emailcheck/email-validator-js';
|
|
865
|
+
import { RedisAdapter } from '@emailcheck/email-validator-js';
|
|
826
866
|
import Redis from 'ioredis';
|
|
827
867
|
|
|
828
868
|
// Create Redis client
|
|
@@ -831,17 +871,41 @@ const redis = new Redis({
|
|
|
831
871
|
port: 6379,
|
|
832
872
|
});
|
|
833
873
|
|
|
834
|
-
// Create Redis cache
|
|
835
|
-
const redisCache =
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
874
|
+
// Create Redis cache
|
|
875
|
+
const redisCache: ICache = {
|
|
876
|
+
mx: new RedisAdapter(redis, {
|
|
877
|
+
keyPrefix: 'email:mx:',
|
|
878
|
+
ttl: 1800000, // 30 minutes
|
|
879
|
+
}),
|
|
880
|
+
disposable: new RedisAdapter(redis, {
|
|
881
|
+
keyPrefix: 'email:disposable:',
|
|
882
|
+
ttl: 86400000, // 24 hours
|
|
883
|
+
}),
|
|
884
|
+
free: new RedisAdapter(redis, {
|
|
885
|
+
keyPrefix: 'email:free:',
|
|
886
|
+
ttl: 86400000, // 24 hours
|
|
887
|
+
}),
|
|
888
|
+
domainValid: new RedisAdapter(redis, {
|
|
889
|
+
keyPrefix: 'email:domain:',
|
|
890
|
+
ttl: 86400000, // 24 hours
|
|
891
|
+
}),
|
|
892
|
+
smtp: new RedisAdapter(redis, {
|
|
893
|
+
keyPrefix: 'email:smtp:',
|
|
894
|
+
ttl: 1800000, // 30 minutes
|
|
895
|
+
}),
|
|
896
|
+
domainSuggestion: new RedisAdapter(redis, {
|
|
897
|
+
keyPrefix: 'email:suggest:',
|
|
898
|
+
ttl: 86400000, // 24 hours
|
|
899
|
+
}),
|
|
900
|
+
whois: new RedisAdapter(redis, {
|
|
901
|
+
keyPrefix: 'email:whois:',
|
|
902
|
+
ttl: 3600000, // 1 hour
|
|
903
|
+
}),
|
|
904
|
+
};
|
|
843
905
|
|
|
844
906
|
// Use with batch verification
|
|
907
|
+
import { verifyEmailBatch } from '@emailcheck/email-validator-js';
|
|
908
|
+
|
|
845
909
|
const batchResult = await verifyEmailBatch({
|
|
846
910
|
emailAddresses: ['user1@mydomain.com', 'user2@mydomain.com'],
|
|
847
911
|
verifyMx: true,
|
|
@@ -851,12 +915,12 @@ const batchResult = await verifyEmailBatch({
|
|
|
851
915
|
});
|
|
852
916
|
```
|
|
853
917
|
|
|
854
|
-
|
|
918
|
+
#### Custom Cache Store Implementation
|
|
855
919
|
|
|
856
920
|
Create your own cache adapter by implementing the `ICacheStore` interface:
|
|
857
921
|
|
|
858
922
|
```typescript
|
|
859
|
-
import {
|
|
923
|
+
import { verifyEmail, type ICacheStore } from '@emailcheck/email-validator-js';
|
|
860
924
|
|
|
861
925
|
class MyCustomCache<T> implements ICacheStore<T> {
|
|
862
926
|
private store = new Map<string, { value: T; expiry: number }>();
|
|
@@ -883,7 +947,15 @@ class MyCustomCache<T> implements ICacheStore<T> {
|
|
|
883
947
|
}
|
|
884
948
|
|
|
885
949
|
async has(key: string): Promise<boolean> {
|
|
886
|
-
|
|
950
|
+
const item = this.store.get(key);
|
|
951
|
+
if (!item) return false;
|
|
952
|
+
|
|
953
|
+
if (Date.now() > item.expiry) {
|
|
954
|
+
this.store.delete(key);
|
|
955
|
+
return false;
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
return true;
|
|
887
959
|
}
|
|
888
960
|
|
|
889
961
|
async clear(): Promise<void> {
|
|
@@ -895,170 +967,52 @@ class MyCustomCache<T> implements ICacheStore<T> {
|
|
|
895
967
|
}
|
|
896
968
|
}
|
|
897
969
|
|
|
898
|
-
//
|
|
899
|
-
const customCache =
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
}
|
|
906
|
-
)
|
|
970
|
+
// Use custom cache store
|
|
971
|
+
const customCache = {
|
|
972
|
+
mx: new MyCustomCache<string[]>(),
|
|
973
|
+
disposable: new MyCustomCache<boolean>(),
|
|
974
|
+
free: new MyCustomCache<boolean>(),
|
|
975
|
+
domainValid: new MyCustomCache<boolean>(),
|
|
976
|
+
smtp: new MyCustomCache<boolean | null>(),
|
|
977
|
+
domainSuggestion: new MyCustomCache<{ suggested: string; confidence: number } | null>(),
|
|
978
|
+
whois: new MyCustomCache<any>(),
|
|
979
|
+
};
|
|
907
980
|
|
|
908
|
-
// Use with verification
|
|
909
981
|
const result = await verifyEmail({
|
|
910
|
-
emailAddress: 'user@
|
|
911
|
-
verifyMx: true,
|
|
912
|
-
verifySmtp: true,
|
|
913
|
-
checkDisposable: true,
|
|
982
|
+
emailAddress: 'user@example.com',
|
|
914
983
|
cache: customCache
|
|
915
984
|
});
|
|
916
985
|
```
|
|
917
986
|
|
|
918
|
-
###
|
|
919
|
-
|
|
920
|
-
Use different cache backends for different types of data:
|
|
921
|
-
|
|
922
|
-
```typescript
|
|
923
|
-
const mixedCache = CacheFactory.createMixedCache({
|
|
924
|
-
// Use Redis for frequently accessed data
|
|
925
|
-
mx: {
|
|
926
|
-
store: redisStore, // Your Redis store implementation
|
|
927
|
-
ttlMs: 1800000
|
|
928
|
-
},
|
|
929
|
-
smtp: {
|
|
930
|
-
store: redisStore,
|
|
931
|
-
ttlMs: 900000
|
|
932
|
-
},
|
|
933
|
-
|
|
934
|
-
// Use LRU for less critical data
|
|
935
|
-
disposable: {
|
|
936
|
-
ttlMs: 86400000 // 24 hours
|
|
937
|
-
},
|
|
938
|
-
free: {
|
|
939
|
-
ttlMs: 86400000 // 24 hours
|
|
940
|
-
},
|
|
941
|
-
domainValid: {
|
|
942
|
-
ttlMs: 86400000 // 24 hours
|
|
943
|
-
}
|
|
944
|
-
});
|
|
945
|
-
|
|
946
|
-
// Verification will use appropriate cache for each operation
|
|
947
|
-
await verifyEmail({
|
|
948
|
-
emailAddress: 'user@tempmail.com',
|
|
949
|
-
verifyMx: true,
|
|
950
|
-
verifySmtp: true,
|
|
951
|
-
checkDisposable: true,
|
|
952
|
-
checkFree: true,
|
|
953
|
-
cache: mixedCache
|
|
954
|
-
});
|
|
955
|
-
```
|
|
956
|
-
|
|
957
|
-
### Cache Best Practices
|
|
987
|
+
### Cache Options
|
|
958
988
|
|
|
959
|
-
|
|
960
|
-
- MX Records: 30-60 minutes (DNS changes infrequently)
|
|
961
|
-
- SMTP Results: 15-30 minutes (Mailbox status changes)
|
|
962
|
-
- Disposable/Free Lists: 12-24 hours (Provider lists update slowly)
|
|
989
|
+
Default cache TTL and size settings:
|
|
963
990
|
|
|
964
|
-
2. **Handle Cache Errors Gracefully**:
|
|
965
991
|
```typescript
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
//
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
import { CacheFactory } from '@emailcheck/email-validator-js';
|
|
978
|
-
|
|
979
|
-
// Create cache with hit tracking
|
|
980
|
-
const cache = CacheFactory.createLRUCache();
|
|
981
|
-
let hits = 0;
|
|
982
|
-
let misses = 0;
|
|
983
|
-
|
|
984
|
-
// Wrap cache store to track metrics
|
|
985
|
-
const trackingCache = {
|
|
986
|
-
get: async (key: string) => {
|
|
987
|
-
const result = await cache.mx.get(key);
|
|
988
|
-
if (result !== null && result !== undefined) {
|
|
989
|
-
hits++;
|
|
990
|
-
} else {
|
|
991
|
-
misses++;
|
|
992
|
-
}
|
|
993
|
-
return result;
|
|
994
|
-
},
|
|
995
|
-
set: cache.mx.set.bind(cache.mx),
|
|
996
|
-
delete: cache.mx.delete.bind(cache.mx),
|
|
997
|
-
has: cache.mx.has.bind(cache.mx),
|
|
998
|
-
clear: cache.mx.clear.bind(cache.mx),
|
|
999
|
-
size: () => cache.mx.size()
|
|
992
|
+
import { DEFAULT_CACHE_OPTIONS } from '@emailcheck/email-validator-js';
|
|
993
|
+
|
|
994
|
+
// TTL (Time To Live) in milliseconds
|
|
995
|
+
DEFAULT_CACHE_OPTIONS.ttl = {
|
|
996
|
+
mx: 3600000, // 1 hour
|
|
997
|
+
disposable: 86400000, // 24 hours
|
|
998
|
+
free: 86400000, // 24 hours
|
|
999
|
+
domainValid: 86400000, // 24 hours
|
|
1000
|
+
smtp: 1800000, // 30 minutes
|
|
1001
|
+
domainSuggestion: 86400000, // 24 hours
|
|
1002
|
+
whois: 3600000, // 1 hour
|
|
1000
1003
|
};
|
|
1001
1004
|
|
|
1002
|
-
//
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
- **Disposable Check**: Domain name (e.g., `tempmail.com`)
|
|
1013
|
-
- **Free Provider Check**: Domain name (e.g., `gmail.com`)
|
|
1014
|
-
- **Domain Validation**: Domain name (e.g., `mydomain.com`)
|
|
1015
|
-
|
|
1016
|
-
### Redis Production Setup
|
|
1017
|
-
|
|
1018
|
-
For production Redis deployment:
|
|
1019
|
-
|
|
1020
|
-
```typescript
|
|
1021
|
-
import Redis from 'ioredis';
|
|
1022
|
-
import { CacheFactory } from '@emailcheck/email-validator-js';
|
|
1023
|
-
|
|
1024
|
-
// Production Redis configuration
|
|
1025
|
-
const redis = new Redis({
|
|
1026
|
-
host: process.env.REDIS_HOST || 'localhost',
|
|
1027
|
-
port: parseInt(process.env.REDIS_PORT || '6379'),
|
|
1028
|
-
password: process.env.REDIS_PASSWORD,
|
|
1029
|
-
db: parseInt(process.env.REDIS_DB || '0'),
|
|
1030
|
-
retryDelayOnFailover: 100,
|
|
1031
|
-
maxRetriesPerRequest: 3,
|
|
1032
|
-
lazyConnect: true,
|
|
1033
|
-
keepAlive: 30000,
|
|
1034
|
-
family: 4,
|
|
1035
|
-
});
|
|
1036
|
-
|
|
1037
|
-
// Handle Redis connection errors
|
|
1038
|
-
redis.on('error', (err) => {
|
|
1039
|
-
console.error('Redis connection error:', err);
|
|
1040
|
-
});
|
|
1041
|
-
|
|
1042
|
-
// Production cache with appropriate settings
|
|
1043
|
-
const productionCache = CacheFactory.createRedisCache(redis, {
|
|
1044
|
-
keyPrefix: 'prod:email:',
|
|
1045
|
-
defaultTtlMs: 3600000,
|
|
1046
|
-
// Configure for high availability
|
|
1047
|
-
jsonSerializer: {
|
|
1048
|
-
stringify: (value: any) => JSON.stringify(value),
|
|
1049
|
-
parse: (value: string) => JSON.parse(value)
|
|
1050
|
-
}
|
|
1051
|
-
});
|
|
1052
|
-
|
|
1053
|
-
// Graceful shutdown
|
|
1054
|
-
process.on('SIGTERM', async () => {
|
|
1055
|
-
await redis.quit();
|
|
1056
|
-
process.exit(0);
|
|
1057
|
-
});
|
|
1005
|
+
// Maximum number of entries per cache type
|
|
1006
|
+
DEFAULT_CACHE_OPTIONS.maxSize = {
|
|
1007
|
+
mx: 500,
|
|
1008
|
+
disposable: 1000,
|
|
1009
|
+
free: 1000,
|
|
1010
|
+
domainValid: 1000,
|
|
1011
|
+
smtp: 500,
|
|
1012
|
+
domainSuggestion: 1000,
|
|
1013
|
+
whois: 200,
|
|
1014
|
+
};
|
|
1058
1015
|
```
|
|
1059
|
-
|
|
1060
|
-
**Note:** Yahoo, Hotmail, and some providers always return `result.validSmtp: true` as they don't allow mailbox verification.
|
|
1061
|
-
|
|
1062
1016
|
## 🌐 Serverless Deployment
|
|
1063
1017
|
|
|
1064
1018
|
The package includes serverless adapters for major cloud platforms. The serverless implementation provides email validation without Node.js dependencies, making it suitable for edge computing environments.
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple cache interface for email validator
|
|
3
|
+
* Mirrors the logging pattern - pass as optional parameter
|
|
4
|
+
*/
|
|
1
5
|
/**
|
|
2
6
|
* Generic cache interface that can be implemented by any cache store
|
|
3
|
-
* including in-memory LRU cache, Redis, Memcached, etc.
|
|
4
7
|
*/
|
|
5
8
|
export interface ICacheStore<T = any> {
|
|
6
9
|
/**
|
|
@@ -13,7 +16,7 @@ export interface ICacheStore<T = any> {
|
|
|
13
16
|
* Set a value in the cache with optional TTL
|
|
14
17
|
* @param key - The cache key
|
|
15
18
|
* @param value - The value to cache
|
|
16
|
-
* @param ttlMs - Optional TTL in milliseconds
|
|
19
|
+
* @param ttlMs - Optional TTL in milliseconds
|
|
17
20
|
*/
|
|
18
21
|
set(key: string, value: T, ttlMs?: number): Promise<void> | void;
|
|
19
22
|
/**
|
|
@@ -37,54 +40,7 @@ export interface ICacheStore<T = any> {
|
|
|
37
40
|
size?(): number | undefined;
|
|
38
41
|
}
|
|
39
42
|
/**
|
|
40
|
-
*
|
|
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
|
|
43
|
+
* Cache interface for different types of data
|
|
88
44
|
*/
|
|
89
45
|
export interface ICache {
|
|
90
46
|
mx: ICacheStore<string[]>;
|
|
@@ -98,27 +54,3 @@ export interface ICache {
|
|
|
98
54
|
} | null>;
|
|
99
55
|
whois: ICacheStore<any>;
|
|
100
56
|
}
|
|
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,40 +1,44 @@
|
|
|
1
1
|
import type { ICache, ICacheStore } from './cache-interface';
|
|
2
|
-
import type { ParsedWhoisResult } from './whois-parser';
|
|
3
|
-
export declare const mxCache: import("tiny-lru").LRU<string[]>;
|
|
4
|
-
export declare const disposableCache: import("tiny-lru").LRU<boolean>;
|
|
5
|
-
export declare const freeCache: import("tiny-lru").LRU<boolean>;
|
|
6
|
-
export declare const domainValidCache: import("tiny-lru").LRU<boolean>;
|
|
7
|
-
export declare const smtpCache: import("tiny-lru").LRU<boolean | null>;
|
|
8
|
-
export declare const domainSuggestionCache: import("tiny-lru").LRU<{
|
|
9
|
-
suggested: string;
|
|
10
|
-
confidence: number;
|
|
11
|
-
} | null>;
|
|
12
|
-
export declare const whoisCache: import("tiny-lru").LRU<ParsedWhoisResult>;
|
|
13
2
|
/**
|
|
14
|
-
*
|
|
3
|
+
* Default cache options
|
|
15
4
|
*/
|
|
16
|
-
export declare
|
|
5
|
+
export declare const DEFAULT_CACHE_OPTIONS: {
|
|
6
|
+
ttl: {
|
|
7
|
+
mx: number;
|
|
8
|
+
disposable: number;
|
|
9
|
+
free: number;
|
|
10
|
+
domainValid: number;
|
|
11
|
+
smtp: number;
|
|
12
|
+
domainSuggestion: number;
|
|
13
|
+
whois: number;
|
|
14
|
+
};
|
|
15
|
+
maxSize: {
|
|
16
|
+
mx: number;
|
|
17
|
+
disposable: number;
|
|
18
|
+
free: number;
|
|
19
|
+
domainValid: number;
|
|
20
|
+
smtp: number;
|
|
21
|
+
domainSuggestion: number;
|
|
22
|
+
whois: number;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
17
25
|
/**
|
|
18
|
-
* Get the
|
|
26
|
+
* Get the default in-memory cache singleton using LRU
|
|
27
|
+
* This is created on first access and reused for all subsequent calls
|
|
19
28
|
*/
|
|
20
|
-
export declare function
|
|
29
|
+
export declare function getDefaultCache(): ICache;
|
|
21
30
|
/**
|
|
22
|
-
*
|
|
31
|
+
* Helper function to get cache store from cache parameter
|
|
32
|
+
* Follows the same pattern as logging - use passed cache or default
|
|
23
33
|
*/
|
|
24
|
-
export declare function
|
|
34
|
+
export declare function getCacheStore<T>(cache: ICache | null | undefined, key: keyof ICache): ICacheStore<T>;
|
|
25
35
|
/**
|
|
26
|
-
*
|
|
36
|
+
* Clear the default cache instance
|
|
37
|
+
* Useful for testing or when you want to reset cache state
|
|
27
38
|
*/
|
|
28
|
-
export declare function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
export declare
|
|
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>;
|
|
39
|
-
export declare function clearAllCaches(): void;
|
|
39
|
+
export declare function clearDefaultCache(): void;
|
|
40
|
+
/**
|
|
41
|
+
* Reset the default cache instance to a fresh one
|
|
42
|
+
*/
|
|
43
|
+
export declare function resetDefaultCache(): void;
|
|
40
44
|
export type { ICache, ICacheStore } from './cache-interface';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ICache } from './cache-interface';
|
|
1
2
|
import type { DomainSuggestion, ISuggestDomainParams } from './types';
|
|
2
3
|
/**
|
|
3
4
|
* List of common email domains for typo detection
|
|
@@ -11,7 +12,7 @@ export declare function defaultDomainSuggestionMethod(domain: string, commonDoma
|
|
|
11
12
|
/**
|
|
12
13
|
* Async version of default domain suggestion method
|
|
13
14
|
*/
|
|
14
|
-
export declare function defaultDomainSuggestionMethodAsync(domain: string, commonDomains?: string[]): Promise<DomainSuggestion | null>;
|
|
15
|
+
export declare function defaultDomainSuggestionMethodAsync(domain: string, commonDomains?: string[], cache?: ICache): Promise<DomainSuggestion | null>;
|
|
15
16
|
/**
|
|
16
17
|
* Suggest a corrected domain for a potentially misspelled email domain
|
|
17
18
|
* @param params - Parameters including domain and optional custom method
|
|
@@ -22,9 +23,10 @@ export declare function suggestDomain(params: ISuggestDomainParams): DomainSugge
|
|
|
22
23
|
* Convenience function to suggest domain from email address
|
|
23
24
|
* @param email - Email address to check for domain typos
|
|
24
25
|
* @param commonDomains - Optional list of common domains to check against
|
|
26
|
+
* @param cache - Optional cache instance
|
|
25
27
|
* @returns Domain suggestion with confidence score, or null if no suggestion
|
|
26
28
|
*/
|
|
27
|
-
export declare function suggestEmailDomain(email: string, commonDomains?: string[]): Promise<DomainSuggestion | null>;
|
|
29
|
+
export declare function suggestEmailDomain(email: string, commonDomains?: string[], cache?: ICache): Promise<DomainSuggestion | null>;
|
|
28
30
|
/**
|
|
29
31
|
* Check if a domain is in the common domains list
|
|
30
32
|
* @param domain - Domain to check
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type IDisposableEmailParams, type IFreeEmailParams, type IVerifyEmailPa
|
|
|
2
2
|
export * from './adapters/lru-adapter';
|
|
3
3
|
export * from './adapters/redis-adapter';
|
|
4
4
|
export { verifyEmailBatch } from './batch';
|
|
5
|
-
export
|
|
5
|
+
export * from './cache';
|
|
6
6
|
export * from './cache-interface';
|
|
7
7
|
export { COMMON_EMAIL_DOMAINS, defaultDomainSuggestionMethod, getDomainSimilarity, isCommonDomain, suggestDomain, suggestEmailDomain, } from './domain-suggester';
|
|
8
8
|
export { defaultNameDetectionMethod, detectName, detectNameFromEmail } from './name-detector';
|