@emailcheck/email-validator-js
Version:
Advanced email validation with MX records, SMTP verification, disposable email detection, batch processing, and caching. Production-ready with TypeScript support.
54 lines (53 loc) • 2.1 kB
TypeScript
import type { CacheStore } from '../cache-interface';
/**
* Subset of the redis client surface we depend on. Kept minimal so consumers
* can plug in `ioredis`, `node-redis`, or any compatible library without
* pulling that package as a direct dependency.
*
* `scan` is used by clear() to walk and delete keys matching our prefix —
* the previous implementation called `flushdb()`, which wipes the whole
* database and is unsafe in shared deployments.
*/
export interface RedisClient {
get(key: string): Promise<string | null>;
set(key: string, value: string, mode?: string, duration?: number): Promise<string | null>;
del(key: string | string[]): Promise<number>;
exists(key: string): Promise<number>;
scan(cursor: string | number, ...args: Array<string | number>): Promise<[string, string[]]>;
}
/**
* Redis adapter for the cache interface
* Supports JSON serialization for complex objects
*/
export declare class RedisAdapter<T> implements CacheStore<T> {
private redis;
private keyPrefix;
private defaultTtlMs;
private jsonSerializer;
constructor(redis: RedisClient, options?: {
keyPrefix?: string;
defaultTtlMs?: number;
jsonSerializer?: {
stringify: (value: T) => string;
parse: (value: string) => T;
};
});
private getKey;
/**
* Walk an arbitrary value and replace `Date` instances with a tagged
* envelope `{__type: 'Date', value: <ISO>}` so JSON.stringify can round-trip
* them. The reverse (parsing the envelope) lives in the JSON `parse` reviver
* configured in the constructor.
*/
private processDatesForSerialization;
get(key: string): Promise<T | null>;
set(key: string, value: T, ttlMs?: number): Promise<void>;
delete(key: string): Promise<boolean>;
has(key: string): Promise<boolean>;
/**
* Delete every key written by this adapter (scoped by `keyPrefix`).
* Walks the keyspace with SCAN + MATCH so we never touch unrelated keys.
*/
clear(): Promise<void>;
size(): number | undefined;
}