findmailx
Version:
FindMailX API client
102 lines (98 loc) • 2.97 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
AuthenticationError: () => AuthenticationError,
FindMailXClient: () => FindMailXClient,
FindMailXError: () => FindMailXError,
NoCreditsError: () => NoCreditsError,
RateLimitError: () => RateLimitError
});
module.exports = __toCommonJS(src_exports);
// 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";
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
AuthenticationError,
FindMailXClient,
FindMailXError,
NoCreditsError,
RateLimitError
});