@nexmailpro/sdk
v1.0.0
Published
Official NexMailPro JavaScript SDK for browser and Node.js email verification workflows.
Maintainers
Readme
NexMailPro JavaScript SDK
Official standalone JavaScript and TypeScript SDK for the NexMailPro email verification API.
Features
- TypeScript-first API with full typings
- Browser and Node.js support
- ESM and CommonJS builds
- Zero runtime dependencies
- Typed API and transport errors
- Single email verification plus bulk verification helpers
Installation
npm install @nexmailpro/sdkRequirements
- Node.js 18+ for native
fetch - Any modern browser with the Fetch API
- Older Node.js runtimes can work if you pass a custom
fetchimplementation
Quick Start
import { NexMailProClient } from "@nexmailpro/sdk";
const client = new NexMailProClient({
apiKey: 'YOUR_API_KEY',
});
const result = await client.verifyEmail('[email protected]');
console.log(result.data.status);
console.log(result.meta?.credits_charged);CommonJS
const { NexMailProClient } = require('@nexmailpro/sdk');
const client = new NexMailProClient({
apiKey: process.env.NEXMAILPRO_API_KEY,
});
client.verifyEmail('[email protected]').then((result) => {
console.log(result.data);
});Browser Use
The SDK works in browsers, but long-lived API keys should only be used in trusted environments such as internal tools, browser extensions, or apps that proxy requests through your backend.
A runnable browser example is included in examples/browser/index.html.
API
new NexMailProClient(options)
interface NexMailProOptions {
apiKey: string;
baseUrl?: string;
timeoutMs?: number;
headers?: HeadersInit;
fetch?: typeof fetch;
userAgent?: string;
}Defaults:
baseUrl:https://nexmailpro.comtimeoutMs:15000
verifyEmail(email, payload?, requestOptions?)
Verifies a single email by calling:
POST https://nexmailpro.com/api/v1/verify/email
const response = await client.verifyEmail('[email protected]', {
source: 'signup-form',
});Response shape:
{
success: true,
message: 'Verification completed',
data: {
email: '[email protected]',
status: 'valid',
sub_status: 'deliverable',
score: 90,
is_syntax_valid: true,
has_mx: true,
domain_exists: true
},
meta: {
credits_charged: 1
}
}Bulk Helpers
The SDK also exposes typed wrappers for the currently documented bulk endpoints:
createBulkVerification(input)getBulkVerificationStatus(uuid)startBulkVerification(uuid)getBulkVerificationResults(uuid, query?)
Examples:
const bulk = await client.createBulkVerification({
title: 'May newsletter',
emails: ['[email protected]', '[email protected]'],
smtpMode: 'safe',
});
const status = await client.getBulkVerificationStatus(bulk.data.uuid);CSV uploads are supported with Blob, File, Uint8Array, ArrayBuffer, or raw CSV strings.
Error Handling
import {
NexMailProClient,
NexMailProApiError,
NexMailProTransportError,
} from '@nexmailpro/sdk';
try {
await client.verifyEmail('bad-email');
} catch (error) {
if (error instanceof NexMailProApiError) {
console.error(error.status, error.code, error.response);
} else if (error instanceof NexMailProTransportError) {
console.error(error.message);
}
}Examples
Development
npm install
npm run build
npm test
npm packLicense
MIT
