neverbounce
Version:
An API wrapper for the NeverBounce API
42 lines (41 loc) • 1.75 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const NeverBounce_js_1 = __importDefault(require("../src/NeverBounce.js"));
const dotenv_1 = __importDefault(require("dotenv"));
// Load environment variables from .local.env file
dotenv_1.default.config();
// Initialize NeverBounce client with API key from environment variables
const client = new NeverBounce_js_1.default({
apiKey: process.env.NEVERBOUNCE_API_KEY
});
// Confirm POE (Proof of Email)
client.poe.confirm('support@neverbounce.com', 0, // Valid result code (0 = valid)
'e3173fdbbdce6bad26522dae792911f2', // Confirmation token
'NBPOE-TXN-5942940c09669' // Transaction ID
)
.then((resp) => console.log('[THEN]', resp))
.catch((err) => console.log('[THEN] ERROR: ' + err.message));
// Alternative using async/await
async function confirmPOE(email, result, confirmationToken, transactionId) {
try {
const response = await client.poe.confirm(email, result, confirmationToken, transactionId);
console.log('[ASYNC] POE confirmation successful!');
console.log(`[ASYNC] Token confirmed: ${response.token_confirmed}`);
}
catch (err) {
if (err instanceof Error) {
console.error('[ASYNC] Error confirming POE:', err.message);
}
else {
console.error('[ASYNC] Unknown error occurred');
}
}
}
// Run the async version with specific parameters
confirmPOE('support@neverbounce.com', 0, // Valid result code (0 = valid)
'e3173fdbbdce6bad26522dae792911f2', // Confirmation token
'NBPOE-TXN-5942940c09669' // Transaction ID
);