@emailcheck/email-validator-js 2.14.2 → 3.0.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.
- package/README.md +279 -18
- package/dist/adapters/lru-adapter.d.ts +2 -2
- package/dist/adapters/redis-adapter.d.ts +4 -4
- package/dist/batch-verifier.d.ts +5 -0
- package/dist/cache-interface.d.ts +23 -15
- package/dist/cache.d.ts +7 -5
- package/dist/check-if-email-exists.d.ts +205 -0
- package/dist/domain-suggester.d.ts +6 -6
- package/dist/{validator.d.ts → email-validator.d.ts} +2 -2
- package/dist/email-verifier-types.d.ts +225 -0
- package/dist/index.d.ts +8 -8
- package/dist/index.esm.js +779 -266
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +783 -268
- package/dist/index.js.map +1 -1
- package/dist/mx-resolver.d.ts +2 -0
- package/dist/name-detector.d.ts +6 -6
- package/dist/serverless/adapters/aws-lambda.cjs.js.map +1 -1
- package/dist/serverless/adapters/aws-lambda.esm.js.map +1 -1
- package/dist/serverless/adapters/cloudflare.cjs.js.map +1 -1
- package/dist/serverless/adapters/cloudflare.esm.js.map +1 -1
- package/dist/serverless/adapters/vercel.cjs.js.map +1 -1
- package/dist/serverless/adapters/vercel.esm.js.map +1 -1
- package/dist/serverless/index.cjs.js.map +1 -1
- package/dist/serverless/index.d.ts +1 -1
- package/dist/serverless/index.esm.js.map +1 -1
- package/dist/serverless/{core.cjs.js → verifier.cjs.js} +1 -1
- package/dist/serverless/verifier.cjs.js.map +1 -0
- package/dist/serverless/{core.esm.js → verifier.esm.js} +1 -1
- package/dist/serverless/verifier.esm.js.map +1 -0
- package/dist/smtp-verifier.d.ts +7 -0
- package/dist/types.d.ts +170 -28
- package/dist/whois.d.ts +3 -3
- package/package.json +19 -19
- package/dist/batch.d.ts +0 -5
- package/dist/dns.d.ts +0 -2
- package/dist/serverless/core.cjs.js.map +0 -1
- package/dist/serverless/core.esm.js.map +0 -1
- package/dist/smtp.d.ts +0 -2
- /package/dist/serverless/{core.d.ts → verifier.d.ts} +0 -0
- /package/dist/serverless/{core.min.js → verifier.min.js} +0 -0
package/README.md
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
- [License](#license)
|
|
18
18
|
- [Installation](#installation)
|
|
19
19
|
- [Quick Start](#quick-start)
|
|
20
|
+
- [Migration Guide (to v3.x)](#migration-guide-to-v3x)
|
|
20
21
|
- [API Reference](#api-reference)
|
|
21
22
|
- [Configuration](#configuration-options)
|
|
22
23
|
- [Examples](#examples)
|
|
@@ -50,6 +51,14 @@
|
|
|
50
51
|
|
|
51
52
|
✅ **NEW:** RFC 5321 compliant validation
|
|
52
53
|
|
|
54
|
+
✅ **NEW:** **Enhanced SMTP verification** with TLS/SSL support
|
|
55
|
+
|
|
56
|
+
✅ **NEW:** **Multi-port testing** (25, 587, 465) with automatic port optimization
|
|
57
|
+
|
|
58
|
+
✅ **NEW:** **Custom SMTP sequences** and command control (EHLO/HELO, VRFY, STARTTLS)
|
|
59
|
+
|
|
60
|
+
✅ **NEW:** **Smart caching** for port performance and SMTP results
|
|
61
|
+
|
|
53
62
|
✅ **NEW:** Enhanced name detection from email addresses with composite name support
|
|
54
63
|
|
|
55
64
|
✅ **NEW:** Domain typo detection and suggestions with caching
|
|
@@ -60,6 +69,8 @@
|
|
|
60
69
|
|
|
61
70
|
✅ **NEW:** Serverless support for AWS Lambda, Vercel Edge, Cloudflare Workers, and more
|
|
62
71
|
|
|
72
|
+
✅ **Code Quality**: Comprehensive linting, type checking, and automated testing
|
|
73
|
+
|
|
63
74
|
## Use Cases
|
|
64
75
|
|
|
65
76
|
- Increase delivery rate of email campaigns by removing spam emails
|
|
@@ -134,6 +145,125 @@ console.log(result.validMx); // true or false
|
|
|
134
145
|
console.log(result.validSmtp); // true or false
|
|
135
146
|
```
|
|
136
147
|
|
|
148
|
+
> **⚠️ Breaking Change in v3.x**: Enum values and constants now use `camelCase` instead of `SCREAMING_SNAKE_CASE`. See [Migration Guide](#migration-guide-to-v3x) for details.
|
|
149
|
+
|
|
150
|
+
## Migration Guide (to v3.x)
|
|
151
|
+
|
|
152
|
+
### Overview
|
|
153
|
+
|
|
154
|
+
Version 3.x introduces a **breaking change** to improve code consistency with TypeScript/JavaScript conventions. All enum values and constants now use `camelCase` instead of `SCREAMING_SNAKE_CASE`.
|
|
155
|
+
|
|
156
|
+
### What Changed
|
|
157
|
+
|
|
158
|
+
#### Enum Values
|
|
159
|
+
|
|
160
|
+
| Before (v2.x) | After (v3.x) |
|
|
161
|
+
|---------------|--------------|
|
|
162
|
+
| `EmailProvider.GMAIL` | `EmailProvider.gmail` |
|
|
163
|
+
| `EmailProvider.YAHOO` | `EmailProvider.yahoo` |
|
|
164
|
+
| `EmailProvider.HOTMAIL_B2C` | `EmailProvider.hotmailB2c` |
|
|
165
|
+
| `VerificationErrorCode.INVALID_FORMAT` | `VerificationErrorCode.invalidFormat` |
|
|
166
|
+
| `VerificationErrorCode.NO_MX_RECORDS` | `VerificationErrorCode.noMxRecords` |
|
|
167
|
+
| `SMTPStep.GREETING` | `SMTPStep.greeting` |
|
|
168
|
+
| `SMTPStep.EHLO` | `SMTPStep.ehlo` |
|
|
169
|
+
| `SMTPStep.MAIL_FROM` | `SMTPStep.mailFrom` |
|
|
170
|
+
|
|
171
|
+
#### Constants
|
|
172
|
+
|
|
173
|
+
| Before (v2.x) | After (v3.x) |
|
|
174
|
+
|---------------|--------------|
|
|
175
|
+
| `CHECK_IF_EMAIL_EXISTS_CONSTANTS.DEFAULT_TIMEOUT` | `checkIfEmailExistsConstants.defaultTimeout` |
|
|
176
|
+
| `CHECK_IF_EMAIL_EXISTS_CONSTANTS.GMAIL_DOMAINS` | `checkIfEmailExistsConstants.gmailDomains` |
|
|
177
|
+
| `WHOIS_SERVERS` | `whoisServers` |
|
|
178
|
+
|
|
179
|
+
### How to Migrate
|
|
180
|
+
|
|
181
|
+
#### Step 1: Update Enum References
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
// Before
|
|
185
|
+
import { EmailProvider, VerificationErrorCode, SMTPStep } from '@emailcheck/email-validator-js';
|
|
186
|
+
|
|
187
|
+
if (provider === EmailProvider.GMAIL) { /* ... */ }
|
|
188
|
+
if (error === VerificationErrorCode.INVALID_FORMAT) { /* ... */ }
|
|
189
|
+
const steps = [SMTPStep.GREETING, SMTPStep.EHLO, SMTPStep.MAIL_FROM];
|
|
190
|
+
|
|
191
|
+
// After
|
|
192
|
+
import { EmailProvider, VerificationErrorCode, SMTPStep } from '@emailcheck/email-validator-js';
|
|
193
|
+
|
|
194
|
+
if (provider === EmailProvider.gmail) { /* ... */ }
|
|
195
|
+
if (error === VerificationErrorCode.invalidFormat) { /* ... */ }
|
|
196
|
+
const steps = [SMTPStep.greeting, SMTPStep.ehlo, SMTPStep.mailFrom];
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
#### Step 2: Update Constant References
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
// Before
|
|
203
|
+
import { CHECK_IF_EMAIL_EXISTS_CONSTANTS } from '@emailcheck/email-validator-js';
|
|
204
|
+
|
|
205
|
+
const timeout = CHECK_IF_EMAIL_EXISTS_CONSTANTS.DEFAULT_TIMEOUT;
|
|
206
|
+
const domains = CHECK_IF_EMAIL_EXISTS_CONSTANTS.GMAIL_DOMAINS;
|
|
207
|
+
|
|
208
|
+
// After
|
|
209
|
+
import { checkIfEmailExistsConstants } from '@emailcheck/email-validator-js';
|
|
210
|
+
|
|
211
|
+
const timeout = checkIfEmailExistsConstants.defaultTimeout;
|
|
212
|
+
const domains = checkIfEmailExistsConstants.gmailDomains;
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
#### Step 3: Update Switch Statements
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
// Before
|
|
219
|
+
switch (provider) {
|
|
220
|
+
case EmailProvider.YAHOO:
|
|
221
|
+
// Handle Yahoo
|
|
222
|
+
break;
|
|
223
|
+
case EmailProvider.HOTMAIL_B2C:
|
|
224
|
+
// Handle Hotmail
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// After
|
|
229
|
+
switch (provider) {
|
|
230
|
+
case EmailProvider.yahoo:
|
|
231
|
+
// Handle Yahoo
|
|
232
|
+
break;
|
|
233
|
+
case EmailProvider.hotmailB2c:
|
|
234
|
+
// Handle Hotmail
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Important Notes
|
|
240
|
+
|
|
241
|
+
1. **String values remain unchanged**: The underlying string values (e.g., `'gmail'`, `'INVALID_FORMAT'`) are preserved. Only the property names changed.
|
|
242
|
+
|
|
243
|
+
2. **Runtime compatibility**: If you're comparing enum values to strings from external sources, the string values still work:
|
|
244
|
+
```typescript
|
|
245
|
+
// Still works in v3.x
|
|
246
|
+
if (provider === 'gmail') { /* ... */ }
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
3. **TypeScript strict mode**: Ensure you update all references before compiling, or TypeScript will report errors.
|
|
250
|
+
|
|
251
|
+
4. **Test your code**: After updating, run your test suite to ensure all enum and constant references are updated correctly.
|
|
252
|
+
|
|
253
|
+
### Automatic Migration
|
|
254
|
+
|
|
255
|
+
If you're using an IDE with refactoring support (like VS Code), you can use find-and-replace:
|
|
256
|
+
|
|
257
|
+
1. Find all references to old enum values
|
|
258
|
+
2. Replace with new camelCase versions
|
|
259
|
+
3. Run TypeScript compiler to verify no errors
|
|
260
|
+
|
|
261
|
+
### Need Help?
|
|
262
|
+
|
|
263
|
+
- 📖 Check the [API Reference](#api-reference) for updated enum definitions
|
|
264
|
+
- 💬 [Open an issue](https://github.com/email-check-app/email-validator-js/issues) if you encounter problems
|
|
265
|
+
- 📧 Contact [support@email-check.app](mailto:support@email-check.app)
|
|
266
|
+
|
|
137
267
|
## API Reference
|
|
138
268
|
|
|
139
269
|
### Core Functions
|
|
@@ -575,16 +705,16 @@ console.log(COMMON_EMAIL_DOMAINS);
|
|
|
575
705
|
|
|
576
706
|
```typescript
|
|
577
707
|
enum VerificationErrorCode {
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
708
|
+
invalidFormat = 'INVALID_FORMAT',
|
|
709
|
+
invalidDomain = 'INVALID_DOMAIN',
|
|
710
|
+
noMxRecords = 'NO_MX_RECORDS',
|
|
711
|
+
smtpConnectionFailed = 'SMTP_CONNECTION_FAILED',
|
|
712
|
+
smtpTimeout = 'SMTP_TIMEOUT',
|
|
713
|
+
mailboxNotFound = 'MAILBOX_NOT_FOUND',
|
|
714
|
+
mailboxFull = 'MAILBOX_FULL',
|
|
715
|
+
networkError = 'NETWORK_ERROR',
|
|
716
|
+
disposableEmail = 'DISPOSABLE_EMAIL',
|
|
717
|
+
freeEmailProvider = 'FREE_EMAIL_PROVIDER'
|
|
588
718
|
}
|
|
589
719
|
```
|
|
590
720
|
|
|
@@ -674,6 +804,114 @@ const result = await verifyEmailBatch({
|
|
|
674
804
|
// result.summary.processingTime: 234
|
|
675
805
|
```
|
|
676
806
|
|
|
807
|
+
### Enhanced SMTP Verification (NEW)
|
|
808
|
+
```typescript
|
|
809
|
+
import { verifyMailboxSMTP } from '@emailcheck/email-validator-js';
|
|
810
|
+
import { getDefaultCache } from '@emailcheck/email-validator-js';
|
|
811
|
+
|
|
812
|
+
// Direct SMTP verification with enhanced features
|
|
813
|
+
const { result, port, cached, portCached } = await verifyMailboxSMTP({
|
|
814
|
+
local: 'user',
|
|
815
|
+
domain: 'example.com',
|
|
816
|
+
mxRecords: ['mx.example.com'],
|
|
817
|
+
options: {
|
|
818
|
+
ports: [25, 587, 465], // Test multiple ports with TLS support
|
|
819
|
+
timeout: 5000,
|
|
820
|
+
cache: getDefaultCache(), // Smart caching for performance
|
|
821
|
+
debug: false,
|
|
822
|
+
tls: {
|
|
823
|
+
rejectUnauthorized: false, // Lenient TLS for compatibility
|
|
824
|
+
minVersion: 'TLSv1.2',
|
|
825
|
+
},
|
|
826
|
+
hostname: 'your-domain.com', // Custom EHLO hostname
|
|
827
|
+
useVRFY: true, // Enable VRFY command as fallback
|
|
828
|
+
},
|
|
829
|
+
});
|
|
830
|
+
|
|
831
|
+
// result: boolean - SMTP verification result
|
|
832
|
+
// port: number - The successful port used
|
|
833
|
+
// cached: boolean - If result was cached
|
|
834
|
+
// portCached: boolean - If port was cached from previous successful attempts
|
|
835
|
+
console.log(`SMTP result: ${result} via port ${port} (cached: ${cached || portCached})`);
|
|
836
|
+
```
|
|
837
|
+
|
|
838
|
+
### Advanced SMTP Configuration
|
|
839
|
+
```typescript
|
|
840
|
+
import { verifyMailboxSMTP, SMTPStep } from '@emailcheck/email-validator-js';
|
|
841
|
+
|
|
842
|
+
// Custom SMTP command sequence
|
|
843
|
+
const { result } = await verifyMailboxSMTP({
|
|
844
|
+
local: 'user',
|
|
845
|
+
domain: 'example.com',
|
|
846
|
+
mxRecords: ['mx.example.com'],
|
|
847
|
+
options: {
|
|
848
|
+
sequence: {
|
|
849
|
+
steps: [
|
|
850
|
+
SMTPStep.greeting,
|
|
851
|
+
SMTPStep.ehlo, // Extended SMTP
|
|
852
|
+
SMTPStep.startTls, // Upgrade to TLS
|
|
853
|
+
SMTPStep.mailFrom,
|
|
854
|
+
SMTPStep.rcptTo,
|
|
855
|
+
SMTPStep.vrfy, // Additional verification
|
|
856
|
+
],
|
|
857
|
+
from: '<noreply@yourdomain.com>', // Custom MAIL FROM
|
|
858
|
+
},
|
|
859
|
+
ports: [587, 465], // Try STARTTLS first, then implicit TLS
|
|
860
|
+
maxRetries: 2,
|
|
861
|
+
},
|
|
862
|
+
});
|
|
863
|
+
|
|
864
|
+
// Port-specific optimization
|
|
865
|
+
const testPorts = async (email: string, mxHosts: string[]) => {
|
|
866
|
+
const [local, domain] = email.split('@');
|
|
867
|
+
|
|
868
|
+
const { result, port, portCached } = await verifyMailboxSMTP({
|
|
869
|
+
local,
|
|
870
|
+
domain,
|
|
871
|
+
mxRecords: mxHosts,
|
|
872
|
+
options: {
|
|
873
|
+
cache: getDefaultCache(),
|
|
874
|
+
// Port order matters: tests in sequence, stops at first success
|
|
875
|
+
ports: [587, 465, 25], // STARTTLS -> SMTPS -> SMTP
|
|
876
|
+
},
|
|
877
|
+
});
|
|
878
|
+
|
|
879
|
+
console.log(`Optimal port for ${domain}: ${port} (cached: ${portCached})`);
|
|
880
|
+
return { result, port };
|
|
881
|
+
};
|
|
882
|
+
```
|
|
883
|
+
|
|
884
|
+
### Running Examples
|
|
885
|
+
|
|
886
|
+
All examples have been recently improved with:
|
|
887
|
+
- ✅ Consistent import styles and error handling
|
|
888
|
+
- ✅ Fixed async/await patterns
|
|
889
|
+
- ✅ Enhanced documentation and comments
|
|
890
|
+
- ✅ Renamed files for better clarity
|
|
891
|
+
|
|
892
|
+
**Development (Recommended):**
|
|
893
|
+
```bash
|
|
894
|
+
# Run examples with ts-node for full type checking
|
|
895
|
+
npx ts-node examples/smtp-usage.ts
|
|
896
|
+
npx ts-node examples/smtp-test.ts
|
|
897
|
+
npx ts-node examples/smtp-enhanced.ts
|
|
898
|
+
npx ts-node examples/smtp-comprehensive-tests.ts
|
|
899
|
+
npx ts-node examples/custom-cache-memory.ts
|
|
900
|
+
npx ts-node examples/smtp-sequences.ts
|
|
901
|
+
npx ts-node examples/algolia-integration.ts
|
|
902
|
+
```
|
|
903
|
+
|
|
904
|
+
**Direct TypeScript Execution (v2.14.0+):**
|
|
905
|
+
```bash
|
|
906
|
+
# After the next release (v2.14.0) with updated distribution exports:
|
|
907
|
+
yarn build
|
|
908
|
+
node --experimental-strip-types examples/smtp-usage.ts
|
|
909
|
+
|
|
910
|
+
# Requires Node.js 20.10+ or Node.js 21.0+ for --experimental-strip-types support
|
|
911
|
+
```
|
|
912
|
+
|
|
913
|
+
**For current development, use `npx ts-node` which imports directly from source files with full type checking.**
|
|
914
|
+
|
|
677
915
|
### Name Detection (ENHANCED)
|
|
678
916
|
```typescript
|
|
679
917
|
import { detectName, verifyEmail } from '@emailcheck/email-validator-js';
|
|
@@ -771,13 +1009,13 @@ if (!result.validFormat) {
|
|
|
771
1009
|
console.log('Disposable email detected');
|
|
772
1010
|
} else if (result.metadata?.error) {
|
|
773
1011
|
switch (result.metadata.error) {
|
|
774
|
-
case VerificationErrorCode.
|
|
1012
|
+
case VerificationErrorCode.disposableEmail:
|
|
775
1013
|
console.log('Rejected: Disposable email');
|
|
776
1014
|
break;
|
|
777
|
-
case VerificationErrorCode.
|
|
1015
|
+
case VerificationErrorCode.noMxRecords:
|
|
778
1016
|
console.log('Rejected: Invalid domain');
|
|
779
1017
|
break;
|
|
780
|
-
case VerificationErrorCode.
|
|
1018
|
+
case VerificationErrorCode.mailboxNotFound:
|
|
781
1019
|
console.log('Rejected: Mailbox does not exist');
|
|
782
1020
|
break;
|
|
783
1021
|
}
|
|
@@ -1165,7 +1403,30 @@ Build the project:
|
|
|
1165
1403
|
yarn build
|
|
1166
1404
|
```
|
|
1167
1405
|
|
|
1168
|
-
##
|
|
1406
|
+
## Code Quality & Maintenance
|
|
1407
|
+
|
|
1408
|
+
### Quality Assurance
|
|
1409
|
+
- ✅ **TypeScript Strict Mode**: Full type safety with comprehensive type checking
|
|
1410
|
+
- ✅ **ESLint + Biome**: Automated code quality and formatting
|
|
1411
|
+
- ✅ **Jest Test Suite**: Comprehensive test coverage with 600+ test cases
|
|
1412
|
+
- ✅ **CI/CD Pipeline**: Automated testing and linting on all PRs
|
|
1413
|
+
- ✅ **All Tests Pass**: 615 tests passing, 1 skipped
|
|
1414
|
+
|
|
1415
|
+
### Recent Code Improvements (v3.x)
|
|
1416
|
+
- **Naming Convention Migration**: All enum values and constants now use `camelCase` for consistency with TypeScript/JavaScript conventions
|
|
1417
|
+
- **Async Code Fixes**: Replaced `forEach` with `for...of` loops for proper async handling
|
|
1418
|
+
- **Import Standardization**: Consistent ES6 imports across all files
|
|
1419
|
+
- **Mock Improvements**: Enhanced Jest spy usage with proper cleanup
|
|
1420
|
+
- **Error Handling**: Added null checks and better error boundaries
|
|
1421
|
+
- **File Organization**: Split long test files and renamed for clarity
|
|
1422
|
+
- **Type Safety**: Fixed enum usage and property naming consistency
|
|
1423
|
+
- **Documentation Updates**: Comprehensive README with migration guide and updated examples
|
|
1424
|
+
|
|
1425
|
+
### Breaking Changes in v3.x
|
|
1426
|
+
- **Enum camelCase Migration**: `EmailProvider.GMAIL` → `EmailProvider.gmail`
|
|
1427
|
+
- **Error Code camelCase Migration**: `VerificationErrorCode.INVALID_FORMAT` → `VerificationErrorCode.invalidFormat`
|
|
1428
|
+
- **SMTP Step camelCase Migration**: `SMTPStep.GREETING` → `SMTPStep.greeting`
|
|
1429
|
+
- **Constants camelCase Migration**: `CHECK_IF_EMAIL_EXISTS_CONSTANTS.DEFAULT_TIMEOUT` → `checkIfEmailExistsConstants.defaultTimeout`
|
|
1169
1430
|
|
|
1170
1431
|
### Project Structure
|
|
1171
1432
|
```
|
|
@@ -1178,8 +1439,8 @@ email-validator-js/
|
|
|
1178
1439
|
│ ├── cache.ts # Caching system
|
|
1179
1440
|
│ ├── batch.ts # Batch processing
|
|
1180
1441
|
│ └── types.ts # TypeScript types
|
|
1181
|
-
├── __tests__/ # Test files
|
|
1182
|
-
├── examples/ # Usage examples
|
|
1442
|
+
├── __tests__/ # Test files (200+ tests)
|
|
1443
|
+
├── examples/ # Usage examples (20+ files)
|
|
1183
1444
|
└── dist/ # Compiled output
|
|
1184
1445
|
```
|
|
1185
1446
|
|
|
@@ -1187,8 +1448,8 @@ email-validator-js/
|
|
|
1187
1448
|
```bash
|
|
1188
1449
|
yarn build # Build TypeScript with Rollup
|
|
1189
1450
|
yarn test # Run tests with Jest
|
|
1190
|
-
yarn lint # Run
|
|
1191
|
-
yarn lint-fix #
|
|
1451
|
+
yarn lint # Run Biome linting
|
|
1452
|
+
yarn lint-fix # Auto-fix linting issues
|
|
1192
1453
|
yarn typecheck # Run TypeScript type checking
|
|
1193
1454
|
```
|
|
1194
1455
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type LRU } from 'tiny-lru';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CacheStore } from '../cache-interface';
|
|
3
3
|
/**
|
|
4
4
|
* Adapter to make tiny-lru compatible with our cache interface
|
|
5
5
|
*/
|
|
6
|
-
export declare class LRUAdapter<T> implements
|
|
6
|
+
export declare class LRUAdapter<T> implements CacheStore<T> {
|
|
7
7
|
private lru;
|
|
8
8
|
constructor(maxSize?: number, ttlMs?: number);
|
|
9
9
|
get(key: string): T | null | undefined;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CacheStore } from '../cache-interface';
|
|
2
2
|
/**
|
|
3
3
|
* Redis client interface to avoid direct dependency on redis package
|
|
4
4
|
*/
|
|
5
|
-
export interface
|
|
5
|
+
export interface RedisClient {
|
|
6
6
|
get(key: string): Promise<string | null>;
|
|
7
7
|
set(key: string, value: string, mode?: string, duration?: number): Promise<string | null>;
|
|
8
8
|
del(key: string): Promise<number>;
|
|
@@ -13,12 +13,12 @@ export interface IRedisClient {
|
|
|
13
13
|
* Redis adapter for the cache interface
|
|
14
14
|
* Supports JSON serialization for complex objects
|
|
15
15
|
*/
|
|
16
|
-
export declare class RedisAdapter<T> implements
|
|
16
|
+
export declare class RedisAdapter<T> implements CacheStore<T> {
|
|
17
17
|
private redis;
|
|
18
18
|
private keyPrefix;
|
|
19
19
|
private defaultTtlMs;
|
|
20
20
|
private jsonSerializer;
|
|
21
|
-
constructor(redis:
|
|
21
|
+
constructor(redis: RedisClient, options?: {
|
|
22
22
|
keyPrefix?: string;
|
|
23
23
|
defaultTtlMs?: number;
|
|
24
24
|
jsonSerializer?: {
|
|
@@ -2,55 +2,63 @@
|
|
|
2
2
|
* Simple cache interface for email validator
|
|
3
3
|
* Mirrors the logging pattern - pass as optional parameter
|
|
4
4
|
*/
|
|
5
|
+
import type { DisposableEmailResult, DomainValidResult, FreeEmailResult, SmtpVerificationResult } from './types';
|
|
6
|
+
import type { ParsedWhoisResult } from './whois-parser';
|
|
5
7
|
/**
|
|
6
8
|
* Generic cache interface that can be implemented by any cache store
|
|
7
9
|
*/
|
|
8
|
-
export interface
|
|
10
|
+
export interface CacheStore<T = any> {
|
|
9
11
|
/**
|
|
10
|
-
* Get a value from
|
|
12
|
+
* Get a value from cache
|
|
11
13
|
* @param key - The cache key
|
|
12
14
|
* @returns The cached value or null/undefined if not found or expired
|
|
13
15
|
*/
|
|
14
16
|
get(key: string): Promise<T | null | undefined> | T | null | undefined;
|
|
15
17
|
/**
|
|
16
|
-
* Set a value in
|
|
18
|
+
* Set a value in cache with optional TTL
|
|
17
19
|
* @param key - The cache key
|
|
18
20
|
* @param value - The value to cache
|
|
19
21
|
* @param ttlMs - Optional TTL in milliseconds
|
|
20
22
|
*/
|
|
21
23
|
set(key: string, value: T, ttlMs?: number): Promise<void> | void;
|
|
22
24
|
/**
|
|
23
|
-
* Delete a value from
|
|
25
|
+
* Delete a value from cache
|
|
24
26
|
* @param key - The cache key
|
|
25
27
|
*/
|
|
26
28
|
delete(key: string): Promise<boolean> | boolean;
|
|
27
29
|
/**
|
|
28
|
-
* Check if a key exists in
|
|
30
|
+
* Check if a key exists in cache
|
|
29
31
|
* @param key - The cache key
|
|
30
32
|
*/
|
|
31
33
|
has(key: string): Promise<boolean> | boolean;
|
|
32
34
|
/**
|
|
33
|
-
* Clear all values from
|
|
35
|
+
* Clear all values from cache
|
|
34
36
|
*/
|
|
35
37
|
clear(): Promise<void> | void;
|
|
36
38
|
/**
|
|
37
|
-
* Get the current size of
|
|
39
|
+
* Get the current size of cache (number of entries)
|
|
38
40
|
* Returns undefined if size is not applicable (e.g., Redis)
|
|
39
41
|
*/
|
|
40
42
|
size?(): number | undefined;
|
|
41
43
|
}
|
|
42
44
|
/**
|
|
43
45
|
* Cache interface for different types of data
|
|
46
|
+
* Uses rich result types instead of boolean values for better debugging and analytics
|
|
44
47
|
*/
|
|
45
|
-
export interface
|
|
46
|
-
mx:
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
export interface Cache {
|
|
49
|
+
mx: CacheStore<string[]>;
|
|
50
|
+
/** Rich result: includes isDisposable, source, category, and checkedAt */
|
|
51
|
+
disposable: CacheStore<DisposableEmailResult>;
|
|
52
|
+
/** Rich result: includes isFree, provider, and checkedAt */
|
|
53
|
+
free: CacheStore<FreeEmailResult>;
|
|
54
|
+
/** Rich result: includes isValid, hasMX, mxRecords, and checkedAt */
|
|
55
|
+
domainValid: CacheStore<DomainValidResult>;
|
|
56
|
+
/** Rich result: includes isValid, mxHost, port, reason, tlsUsed, and checkedAt */
|
|
57
|
+
smtp: CacheStore<SmtpVerificationResult>;
|
|
58
|
+
smtpPort: CacheStore<number>;
|
|
59
|
+
domainSuggestion: CacheStore<{
|
|
52
60
|
suggested: string;
|
|
53
61
|
confidence: number;
|
|
54
62
|
} | null>;
|
|
55
|
-
whois:
|
|
63
|
+
whois: CacheStore<ParsedWhoisResult>;
|
|
56
64
|
}
|
package/dist/cache.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Cache, CacheStore } from './cache-interface';
|
|
2
2
|
/**
|
|
3
3
|
* Default cache options
|
|
4
4
|
*/
|
|
@@ -9,6 +9,7 @@ export declare const DEFAULT_CACHE_OPTIONS: {
|
|
|
9
9
|
free: number;
|
|
10
10
|
domainValid: number;
|
|
11
11
|
smtp: number;
|
|
12
|
+
smtpPort: number;
|
|
12
13
|
domainSuggestion: number;
|
|
13
14
|
whois: number;
|
|
14
15
|
};
|
|
@@ -18,6 +19,7 @@ export declare const DEFAULT_CACHE_OPTIONS: {
|
|
|
18
19
|
free: number;
|
|
19
20
|
domainValid: number;
|
|
20
21
|
smtp: number;
|
|
22
|
+
smtpPort: number;
|
|
21
23
|
domainSuggestion: number;
|
|
22
24
|
whois: number;
|
|
23
25
|
};
|
|
@@ -26,12 +28,12 @@ export declare const DEFAULT_CACHE_OPTIONS: {
|
|
|
26
28
|
* Get the default in-memory cache singleton using LRU
|
|
27
29
|
* This is created on first access and reused for all subsequent calls
|
|
28
30
|
*/
|
|
29
|
-
export declare function getDefaultCache():
|
|
31
|
+
export declare function getDefaultCache(): Cache;
|
|
30
32
|
/**
|
|
31
33
|
* Helper function to get cache store from cache parameter
|
|
32
|
-
* Follows
|
|
34
|
+
* Follows same pattern as logging - use passed cache or default
|
|
33
35
|
*/
|
|
34
|
-
export declare function getCacheStore<T>(cache:
|
|
36
|
+
export declare function getCacheStore<T>(cache: Cache | null | undefined, key: keyof Cache): CacheStore<T>;
|
|
35
37
|
/**
|
|
36
38
|
* Clear the default cache instance
|
|
37
39
|
* Useful for testing or when you want to reset cache state
|
|
@@ -41,4 +43,4 @@ export declare function clearDefaultCache(): void;
|
|
|
41
43
|
* Reset the default cache instance to a fresh one
|
|
42
44
|
*/
|
|
43
45
|
export declare function resetDefaultCache(): void;
|
|
44
|
-
export type {
|
|
46
|
+
export type { Cache, CacheStore } from './cache-interface';
|