UNPKG

secure-2fa

Version:

A secure, developer-friendly Node.js package for email-based OTP (2FA) with strong security controls

47 lines 1.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MailgunAdapter = void 0; class MailgunAdapter { constructor(config) { this.apiKey = config.apiKey; this.domain = config.domain; this.defaultFrom = config.from || `noreply@${config.domain}`; } async sendEmail(params) { try { // Dynamic import to avoid bundling issues const mailgun = require('mailgun.js'); const mg = mailgun.client({ username: 'api', key: this.apiKey }); const messageData = { from: params.from || this.defaultFrom, to: params.to, subject: params.subject }; if (params.html) { messageData.html = params.html; } if (params.text) { messageData.text = params.text; } await mg.messages.create(this.domain, messageData); } catch (error) { throw new Error(`Failed to send email via Mailgun: ${error instanceof Error ? error.message : 'Unknown error'}`); } } async verifyConnection() { try { // Dynamic import to avoid bundling issues const mailgun = require('mailgun.js'); const mg = mailgun.client({ username: 'api', key: this.apiKey }); // Try to get domain info to verify connection await mg.domains.get(this.domain); return true; } catch (error) { return false; } } } exports.MailgunAdapter = MailgunAdapter; //# sourceMappingURL=mailgun-adapter.js.map