UNPKG

findmailx

Version:

FindMailX API client

71 lines (69 loc) 1.77 kB
// src/client.ts var FindMailXClient = class { constructor(options) { this.apiKey = options.apiKey; this.baseUrl = options.baseUrl ?? "https://www.findmailx.com/api/v1"; } async findEmail(options) { const params = new URLSearchParams({ api_key: this.apiKey, domain: options.domain }); if (options.fullName) { params.append("full_name", options.fullName); } else if (options.firstName && options.lastName) { params.append("first_name", options.firstName); params.append("last_name", options.lastName); } else { throw new Error( "Either fullName or both firstName and lastName must be provided" ); } const response = await fetch( `${this.baseUrl}/email-finder?${params.toString()}` ); return response.json(); } async verifyEmail(email) { const params = new URLSearchParams({ api_key: this.apiKey, email }); const response = await fetch( `${this.baseUrl}/email-verifier?${params.toString()}` ); return response.json(); } }; // src/errors.ts var FindMailXError = class extends Error { constructor(message) { super(message); this.name = "FindMailXError"; } }; var AuthenticationError = class extends FindMailXError { constructor() { super("Invalid API key"); this.name = "AuthenticationError"; } }; var RateLimitError = class extends FindMailXError { constructor() { super("Rate limit exceeded"); this.name = "RateLimitError"; } }; var NoCreditsError = class extends FindMailXError { constructor() { super("You are out of credits"); this.name = "NoCreditsError"; } }; export { AuthenticationError, FindMailXClient, FindMailXError, NoCreditsError, RateLimitError };