Hello, {{name}}!
", text: "Hello, {{name}}!", domain_id: "domain_id", categories: ["welcome"], tags: ["welcome"], auto_generate: false, }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Update a template ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.template.update("template_id", { name: "Updated Template Name", html: "Hello, {{name}}! Updated.
", text: "Hello, {{name}}! Updated.", auto_generate: true, }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Delete a template ```js import 'dotenv/config'; import { MailerSend} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.template.delete("template_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ## Email Verification ### Get all email verification lists ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.emailVerification.list({ page: 1, limit: 25 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get an email verification list ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.emailVerification.single("email_verification_id", { detailed: true, page: 1, limit: 25, }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Create an email verification list ```js import 'dotenv/config'; import { MailerSend, EmailVerification } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const emailVerification = new EmailVerification("My List", [ "test1@example.com", "test2@example.com", ]); // Optional: link to an existing list and trigger verification automatically // emailVerification.setListId("existing_list_id"); // emailVerification.setVerify(true); mailerSend.emailVerification.create(emailVerification) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Verify an email list ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.emailVerification.verifyList("email_verification_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get email verification list results ```js import 'dotenv/config'; import { MailerSend, EmailVerificationResultType } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.emailVerification.getListResult("email_verification_id", { page: 1, limit: 25, results: [EmailVerificationResultType.VALID, EmailVerificationResultType.CATCH_ALL], }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Verify a single email ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.emailVerification.verifyEmail("test@example.com") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Verify a single email asynchronously ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.emailVerification.verifyEmailAsync("test@example.com") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get async email verification status ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.emailVerification.getVerifyEmailAsyncStatus("verification_job_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ## SMS ### Send SMS ```js import 'dotenv/config'; import { MailerSend, SMSParams } from "mailersend"; const mailersend = new MailerSend({ apiKey: process.env.API_KEY, }); const recipients = [ "+18332647501" ]; const smsParams = new SMSParams() .setFrom("+18332647501") .setTo(recipients) .setText("This is the text content"); await mailersend.sms.send(smsParams); ``` ### SMS personalization ```js import 'dotenv/config'; import { MailerSend, SMSParams, SMSPersonalization } from "mailersend"; const mailersend = new MailerSend({ apiKey: process.env.API_KEY, }); const recipients = [ "+18332647501", "+18332647502" ]; const personalization = [ new SMSPersonalization("+18332647501", { "name": "Dummy" }), new SMSPersonalization("+18332647502", { "name": "Not Dummy" }), ]; const smsParams = new SMSParams() .setFrom("+18332647501") .setTo(recipients) .setPersonalization(personalization) .setText("Hey {{name}} welcome to our organization"); await mailersend.sms.send(smsParams); ``` ## Phone Numbers ### Get phone number list ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.number.list({ paused: false, limit: 10, page: 1 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get phone number ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.number.single("sms_number_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Update phone number ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.number.update("sms_number_id", true) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Delete phone number ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.number.delete("sms_number_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ## Messages ### Get messages list ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.message.list({ limit: 10, page: 1 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get a message ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.message.single("sms_message_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ## Activity ### Get activity list ```js import 'dotenv/config'; import { MailerSend, SmsActivityStatusType } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.activity.list({ sms_number_id: "number_id", status: [SmsActivityStatusType.SENT, SmsActivityStatusType.DELIVERED], limit: 10, page: 1 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ## Recipients ### Get recipient list ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.recipient.list({ sms_number_id: "sms_number_id", status: "active", limit: 10, page: 1, }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get recipient ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.recipient.single("sms_recipient_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Update recipient ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.recipient.update("sms_recipient_id", "active") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ## Webhooks ### Get webhook list for a number ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.webhook.list("sms_number_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get webhook ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.webhook.single("sms_webhook_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Create webhook ```js import 'dotenv/config'; import { MailerSend, SmsWebhook, SmsWebhookEventType } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const smsWebhook = new SmsWebhook() .setName("Sms Webhook") .setUrl("https:://yourapp.com/hook") .setSmsNumberId("sms_number_id") .setEnabled(true) .setEvents([SmsWebhookEventType.SENT, SmsWebhookEventType.DELIVERED]) mailerSend.sms.webhook.create(smsWebhook) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Update webhook ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.webhook.update("sms_webhook_id", { name: "Webhook", url: "https:://yourapp.com/hook", enabled: ["sms.sent", "sms.delivered", "sms.failed"], enabled: true }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Delete webhook ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.webhook.delete("sms_webhook_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Verify webhook signature See [Utils — Verify a webhook signature](#verify-a-webhook-signature). ## Inbound ### Get inbound list ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.inbound.list({ enabled: 1, sms_number_id: "sms_number_id", limit: 10, page: 1, }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get inbound ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.inbound.single("sms_inbound_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Add inbound ```js import 'dotenv/config'; import { MailerSend, SmsInbound } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const smsInbound = new SmsInbound() .setSmsNumberId("sms_number_id") .setEnabled(true) .setName("Inbound Name") .setForwardUrl("yourapp.com/hook") .setFilter({ comparer: "equal", value: "START" }); mailerSend.sms.inbound.create(smsInbound) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Update inbound ```js import 'dotenv/config'; import { MailerSend, SmsInbound } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const smsInbound = new SmsInbound() .setSmsNumberId("sms_number_id") .setEnabled(true) .setName("Inbound Name Update") .setForwardUrl("yourapp.com/hook") .setFilter({ comparer: "equal", value: "START" }); mailerSend.sms.inbound.update("sms_inbound_id", {...smsInbound}) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Delete inbound ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.inbound.delete("sms_inbound_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ## Identity ### Get identity list ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.identity.list() .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get identity ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.identity.single("identity_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get identity by email address ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.identity.singleByEmail('email_address') .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Create identity ```js import 'dotenv/config'; import { MailerSend, Inbound, InboundFilterType } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const identity = new Identity() .setDomainId('domain_id') .setEmail('identity@yourdomain.com') .setName('Name') .setReplyToEmail('reply_identity@yourdomain.com') .setReplyToName('Reply Name') .setAddNote(false); mailerSend.email.identity.create(identity) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Update identity ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const data = { name: 'name', reply_to_name: 'Reply Name', reply_to_email: 'reply@yourdomain.com', }; mailerSend.email.identity.update('identity_id', data) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Update identity by email address ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const data = { name: 'name', reply_to_name: 'Reply Name', reply_to_email: 'reply@yourdomain.com', }; mailerSend.email.identity.updateByEmail('email_address', data) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Delete identity ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.identity.delete("identity_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Delete identity by email address ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.identity.deleteByEmail('email_address') .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Resend identity verification ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.identity.resend("identity_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ## SMTP Users ### List SMTP users ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.smtpUser.list("domain_id", { page: 1, limit: 25 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get SMTP user ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.smtpUser.single("domain_id", "smtp_user_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Create SMTP user ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.smtpUser.create("domain_id", { name: "My SMTP User", enabled: true, }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Update SMTP user ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.smtpUser.update("domain_id", "smtp_user_id", { name: "Updated SMTP User", enabled: false, }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Delete SMTP user ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.smtpUser.delete("domain_id", "smtp_user_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ## Users ### Get user list ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.user.list({ page: 1, limit: 25 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get single user ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.user.single("user_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Invite a user ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.user.create({ email: "user@example.com", role: "manager", // For role "custom", permissions is required: // permissions: ["read-activity", "read-analytics"], // templates: ["template_id"], // domains: ["domain_id"], }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Update user ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.user.update("user_id", { role: "designer", }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Delete user ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.user.delete("user_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get invite list ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.user.listInvites({ page: 1, limit: 25 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get single invite ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.user.singleInvite("invite_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Resend invite ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.user.resendInvite("invite_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Cancel invite ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.user.deleteInvite("invite_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ## DMARC Monitoring ### List monitors ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.dmarc.list({ page: 1, limit: 25 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Create monitor ```js import 'dotenv/config'; import { MailerSend, Dmarc } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const dmarc = new Dmarc("domain_id"); mailerSend.dmarc.create(dmarc) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Update monitor ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.dmarc.update("monitor_id", { wanted_dmarc_record: "v=DMARC1; p=reject;" }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Delete monitor ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.dmarc.delete("monitor_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get aggregated reports ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.dmarc.report("monitor_id", { page: 1, limit: 25 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get IP-specific reports ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.dmarc.reportByIp("monitor_id", "1.2.3.4", { page: 1, limit: 25 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get report sources ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.dmarc.reportSources("monitor_id", { date_from: 1700000000, date_to: 1700100000, status: "accepted", // optional: "accepted" | "rejected" | "quarantined" }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Mark IP as favorite ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.dmarc.addFavorite("monitor_id", "1.2.3.4") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Remove IP from favorites ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.dmarc.removeFavorite("monitor_id", "1.2.3.4") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ## Blocklist Monitoring ### List blocklist monitors ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.blocklistMonitor.list({ page: 1, limit: 25 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Get single blocklist monitor ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.blocklistMonitor.single("monitor_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Create blocklist monitor ```js import 'dotenv/config'; import { MailerSend, BlocklistMonitor } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const monitor = new BlocklistMonitor("example.com") .setName("My Domain Monitor") .setNotify(true) .setNotifyEmail("alerts@example.com"); mailerSend.blocklistMonitor.create(monitor) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Update blocklist monitor ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.blocklistMonitor.update("monitor_id", { name: "Updated Monitor Name", notify: true, notify_email: "alerts@example.com", }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ### Delete blocklist monitor ```js import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.blocklistMonitor.delete("monitor_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ## Other endpoints ### Get API quota ```js import 'dotenv/config'; import { MailerSend} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.others.getApiQuota() .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ``` ## Utils ### Verify a webhook signature Use `MailerSendUtils.verifyWebHook()` to verify the HMAC signature on incoming webhook requests. This works for both email and SMS webhooks. ```js import { MailerSendUtils } from "mailersend"; // rawBody must be the raw Buffer from the request (do not parse it as JSON first) const isValid = MailerSendUtils.verifyWebHook( rawBody, request.headers['x-mailersend-signature'], process.env.WEBHOOK_SIGNING_SECRET ); ``` # Support and Feedback In case you find any bugs, submit an issue directly here in GitHub. You are welcome to create SDK for any other programming language. If you have any troubles using our API or SDK free to contact our support by email [info@mailersend.com](mailto:info@mailersend.com) The official documentation is at [https://developers.mailersend.com](https://developers.mailersend.com) # License [The MIT License (MIT)](LICENSE) ================================================ FILE: examples/v1/activity/byCountry.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.activityByCountry({ date_from: 1443651141, date_to: 2443651141 }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/activity/byDate.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.activityByDate({ date_from: 1443651141, date_to: 2443651141, event: ["sent"] }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/activity/byReadingEnvironment.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.activityByReadingEnvironment({ date_from: 1443651141, date_to: 2443651141 }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/activity/byUserAgent.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.activityByUserAgent({ date_from: 1443651141, date_to: 2443651141 }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/activity/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.activityList({ domain_id: "xxx", }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/domains/add.js ================================================ "use strict"; require("dotenv").config(); const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.addDomain({ name: "example.com", return_path_subdomain: "rp_subdomain", custom_tracking_subdomain: "ct_subdomain", inbound_routing_subdomain: "ir_subdomain", }) .then((response) => response.json()) .then((data) => { console.log(data); }); ================================================ FILE: examples/v1/domains/delete.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteDomain({ domain_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/domains/dns.js ================================================ "use strict"; require("dotenv").config(); const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getDNS({ domain_id: "xxx", }) .then((response) => { response.json(); }) .then((data) => { console.log(data); }); ================================================ FILE: examples/v1/domains/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.domainList({ }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/domains/recipients.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.domainRecipients({ domain_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/domains/settings.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.domainSettings({ domain_id: 'xxx', send_paused: false }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/domains/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.domain({ domain_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/domains/verify.js ================================================ "use strict"; require("dotenv").config(); const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.verifyDomain({ domain_id: "xxx", }) .then((response) => { response.json(); }) .then((data) => { console.log(data); }); ================================================ FILE: examples/v1/email/advancedPersonalization.js ================================================ "use strict"; require('dotenv').config() const Recipient = require("../../src/Recipient"); const EmailParams = require("../../src/EmailParams"); const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const personalization = [ { email: "your@client.com", data: { test: 'Test Value' }, } ]; const emailParams = new EmailParams() .setFrom("your@domain.com") .setFromName("Your Name") .setRecipients(recipients) .setPersonalization(personalization) .setSubject("Subject, {{ test }}") .setHtml("This is the HTML content, {{ test }}") .setText("This is the text content, {{ test }}"); mailersend.send(emailParams); ================================================ FILE: examples/v1/email/ccBccRecipients.js ================================================ "use strict"; require('dotenv').config() const Recipient = require("../../src/Recipient"); const EmailParams = require("../../src/EmailParams"); const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const cc = [ new Recipient("your_cc@client.com", "Your CC Client") ]; const bcc = [ new Recipient("your_bcc@client.com", "Your BCC Client") ]; const emailParams = new EmailParams() .setFrom("your@domain.com") .setFromName("Your Name") .setRecipients(recipients) .setCc(cc) .setBcc(bcc) .setSubject("Subject") .setHtml("This is the HTML content") .setText("This is the text content"); mailersend.send(emailParams); ================================================ FILE: examples/v1/email/getBulkEmailRequestStatus.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getBulkEmailRequestStatus({ bulk_email_id: 'xxx' }) .then((response) => response.json()) .then((data) => { console.log(data); }); ================================================ FILE: examples/v1/email/sendAnEmail.js ================================================ "use strict"; require('dotenv').config() const Recipient = require("../../src/Recipient"); const EmailParams = require("../../src/EmailParams"); const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const emailParams = new EmailParams() .setFrom("your@domain.com") .setFromName("Your Name") .setRecipients(recipients) .setReplyTo("reply@domain.com") .setReplyToName("Reply to name") .setSubject("Subject") .setHtml("This is the HTML content") .setText("This is the text content"); mailersend.send(emailParams); ================================================ FILE: examples/v1/email/sendBulkEmail.js ================================================ "use strict"; require('dotenv').config() const Recipient = require("../../src/Recipient"); const EmailParams = require("../../src/EmailParams"); const MailerSend = require("../../src/MailerSend"); const BulkEmails = require("../../src/BulkEmails"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); const bulkEmails = new BulkEmails(); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const emailParams = new EmailParams() .setFrom("your@domain.com") .setFromName("Your Name") .setRecipients(recipients) .setSubject("Subject") .setHtml("This is the HTML content") .setText("This is the text content"); bulkEmails.addEmail(emailParams) bulkEmails.addEmails([ emailParams, emailParams ]) mailersend.sendBulk(bulkEmails) .then((response) => response.json()) .then((data) => { console.log(data); }); ================================================ FILE: examples/v1/email/sendScheduleEmail.js ================================================ "use strict"; require('dotenv').config() const Recipient = require("../../src/Recipient"); const EmailParams = require("../../src/EmailParams"); const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const emailParams = new EmailParams() .setFrom("your@domain.com") .setFromName("Your Name") .setRecipients(recipients) .setReplyTo("reply@domain.com") .setReplyToName("Reply to name") .setSubject("Subject") .setSendAt(2443651141) //set sendAt is a timestamp - min: now, max: now + 72hours .setHtml("This is the HTML content") .setText("This is the text content"); mailersend.send(emailParams); ================================================ FILE: examples/v1/email/simplePersonalization.js ================================================ "use strict"; require('dotenv').config() // const Recipient = require("../../src/Recipient"); const EmailParams = require("../../src/EmailParams"); const MailerSend = require("../../src/MailerSend"); const { default: Recipient } = require('../../src/Recipient'); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const variables = [ { email: "your@client.com", substitutions: [ { var: 'test', value: 'Test Value' } ], } ]; const emailParams = new EmailParams() .setFrom("your@domain.com") .setFromName("Your Name") .setRecipients(recipients) .setVariables(variables) .setSubject("Subject, {$test}") .setHtml("This is the HTML content, {$test}") .setText("This is the text content, {$test}"); mailersend.send(emailParams); ================================================ FILE: examples/v1/email/templatedEmail.js ================================================ "use strict"; require('dotenv').config() const Recipient = require("../../src/Recipient"); const EmailParams = require("../../src/EmailParams"); const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const emailParams = new EmailParams() .setFrom("your@domain.com") .setFromName("Your Name") .setRecipients(recipients) .setTemplateId('templateId') .setSubject("Subject") mailersend.send(emailParams); ================================================ FILE: examples/v1/email/withAttachment.js ================================================ "use strict"; require('dotenv').config() const fs = require('fs'); const Recipient = require("../../src/Recipient"); const Attachment = require("../../src/Attachment"); const EmailParams = require("../../src/EmailParams"); const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const attachments = [ new Attachment(fs.readFileSync('/path/to/file.pdf', {encoding: 'base64'}), 'file.pdf', 'attachment') ] const emailParams = new EmailParams() .setFrom("your@domain.com") .setFromName("Your Name") .setRecipients(recipients) .setAttachments(attachments) .setSubject("Subject") .setHtml("This is the HTML content") .setText("This is the text content"); mailersend.send(emailParams); ================================================ FILE: examples/v1/email-verification/create.js ================================================ "use strict"; require("dotenv").config(); const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.createEmailVerificationList({ name: "List example", emails: [ "info@mailersend.com", "test@mailersend.com" ] }) .then((response) => response.json()) .then((data) => { console.log(data); }); ================================================ FILE: examples/v1/email-verification/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.emailVerificationLists({ }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/email-verification/results.js ================================================ "use strict"; require("dotenv").config(); const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.emailVerificationResults({ email_verification_id: "xxx", }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/email-verification/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.emailVerificationList({ email_verification_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/email-verification/verify.js ================================================ "use strict"; require("dotenv").config(); const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.verifyEmailVerificationList({ email_verification_id: "xxx", }) .then((response) => response.json()) .then((data) => { console.log(data); }); ================================================ FILE: examples/v1/inbounds/create.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.createInbound({ domain_id: "xxx", name: "Test name", domain_enabled: true, inbound_domain: "test.yourdomain.com", inbound_address: "test@inbound.yourdomain.com", inbound_subdomain: "inbound", inbound_priority: 100, match_filter: { type: "match_all" }, catch_filter: { type: "catch_recipient", filters: [ { comparer: "equal", value: "test" } ] }, forwards: [ { type: "webhook", value: "https://www.yourdomain.com/hook" } ] }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/inbounds/delete.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteInbound({ inbound_id: 'xxx' }); ================================================ FILE: examples/v1/inbounds/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.inboundList() .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/inbounds/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.inbound({ inbound_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/inbounds/update.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.updateInbound({ inbound_id: "xxx", domain_id: "xxx", name: "Test name", domain_enabled: true, inbound_domain: "test.yourdomain.com", inbound_address: "test@inbound.yourdomain.com", inbound_subdomain: "inbound", inbound_priority: 100, match_filter: { type: "match_all" }, catch_filter: { type: "catch_recipient", filters: [ { comparer: "equal", value: "test" } ] }, forwards: [ { type: "webhook", value: "https://www.yourdomain.com/hook" } ] }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/messages/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.messagesList() .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/messages/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.message({ message_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/recipients/addRecipientsToBlocklist.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.addRecipientsToBlocklist({ domain_id: 'xxx', recipients: [ "test@example.com" ] }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/recipients/addRecipientsToHardBounceList.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.addRecipientsToHardBounceList({ domain_id: 'xxx', recipients: [ "test@example.com" ] }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/recipients/addRecipientsToSpamComplaintList.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.addRecipientsToSpamComplaintList({ domain_id: 'xxx', recipients: [ "test@example.com" ] }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/recipients/addRecipientsToUnsubscribeList.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.addRecipientsToUnsubscribeList({ domain_id: 'xxx', recipients: [ "test@example.com" ] }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/recipients/delete.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteRecipient({ recipient_id: 'xxx' }); ================================================ FILE: examples/v1/recipients/deleteRecipientsFromBlocklist.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteRecipientsFromBlocklist({ ids: [ "xxxxxxxxxxx", "yyyyyyyyyyy" ] }); ================================================ FILE: examples/v1/recipients/deleteRecipientsFromHardBounceList.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteRecipientsFromHardBounceList({ ids: [ "xxxxxxxxxxx", "yyyyyyyyyyy" ] }); ================================================ FILE: examples/v1/recipients/deleteRecipientsFromSpamComplaintList.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteRecipientsFromSpamComplaintList({ ids: [ "xxxxxxxxxxx", "yyyyyyyyyyy" ] }); ================================================ FILE: examples/v1/recipients/deleteRecipientsFromUnsubscribeList.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteRecipientsFromUnsubscribeList({ ids: [ "xxxxxxxxxxx", "yyyyyyyyyyy" ] }); ================================================ FILE: examples/v1/recipients/getRecipientsFromBlocklist.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getRecipientsFromBlocklist({ domain_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/recipients/getRecipientsFromHardBounceList.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getRecipientsFromHardBounceList({ domain_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/recipients/getRecipientsFromSpamComplaintList.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getRecipientsFromSpamComplaintList({ domain_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/recipients/getRecipientsFromUnsubscribeList.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getRecipientsFromUnsubscribeList({ domain_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/recipients/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.recipientsList() .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/recipients/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.recipient({ recipient_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/scheduled/delete.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteSchedule({ message_id: 'xxx' }); ================================================ FILE: examples/v1/scheduled/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.scheduleList() .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/scheduled/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.schedule({ message_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/activities/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getSmsActivities() .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/activities/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getSmsActivity({ sms_message_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/inbounds/create.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.createSmsInbound({ sms_number_id: "xxx", name: "Inbound", forward_url: "https:://yourapp.com/hook", filter: { comparer: "equal", value: "START" }, enabled: true }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/inbounds/delete.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteSmsInbound({ sms_inbound_id: 'xxx' }); ================================================ FILE: examples/v1/sms/inbounds/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getSmsInbounds() .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/inbounds/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getSmsInbound({ sms_inbound_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/inbounds/update.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.updateSmsInbound({ sms_inbound_id: "xxx", name: "Inbound", forward_url: "https:://yourapp.com/hook", filter: { comparer: "equal", value: "START" }, enabled: true }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/messages/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getSmsMessages() .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/messages/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getSmsMessage({ sms_message_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/numbers/delete.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteSmsNumber({ sms_number_id: 'xxx' }); ================================================ FILE: examples/v1/sms/numbers/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getSmsNumbers() .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/numbers/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getSmsNumber({ sms_number_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/numbers/update.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.updateSmsNumber({ sms_number_id: 'xxx', paused: false }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/recipients/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getSmsRecipients() .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/recipients/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getSmsRecipient({ sms_recipient_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/recipients/update.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.updateSmsRecipient({ sms_recipient_id: "xxx", status: "active" }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/sendAnSms.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const SmsParams = require("../../src/SmsParams"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); const to = [ "+18332647501" ]; const smsParams = new SmsParams() .setFrom("+18332647501") .setTo(to) .setText("This is the text content"); mailersend.sendSms(smsParams); ================================================ FILE: examples/v1/sms/smsPersonalization.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const SmsParams = require("../../src/SmsParams"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); const to = [ "+18332647501", "+18332647502" ]; const personalization = [ { "phone_number": "+18332647501", "data": { "name": "Dummy" } }, { "phone_number": "+18332647502", "data": { "name": "Not Dummy" } } ]; const smsParams = new SmsParams() .setFrom("+18332647501") .setTo(to) .setPersonalization(personalization) .setText("Hey {{name}} welcome to our organization"); mailersend.sendSms(smsParams); ================================================ FILE: examples/v1/sms/webhooks/create.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.createSmsWebhook({ sms_number_id: "xxx", name: "Webhook", url: "https:://yourapp.com/hook", enabled: ["sms.sent", "sms.delivered", "sms.failed"], enabled: true }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/webhooks/delete.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteSmsWebhook({ sms_webhook_id: 'xxx' }); ================================================ FILE: examples/v1/sms/webhooks/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getSmsWebhooks({ sms_number_id: 'xxx', limit: 10 }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/webhooks/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.getSmsWebhook({ sms_webhook_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/sms/webhooks/update.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.updateSmsWebhook({ sms_webhook_id: "xxx", name: "Webhook", url: "https:://yourapp.com/hook", enabled: ["sms.sent", "sms.delivered", "sms.failed"], enabled: true }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/templates/delete.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteTemplate({ template_id: 'xxx' }); ================================================ FILE: examples/v1/templates/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.templateList() .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/templates/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.template({ template_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/tokens/createToken.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.createToken({ name: "Token name", domain_id: "xxx", scopes: [ "email_full", "domains_read", "domains_full", "activity_read", "activity_full", "analytics_read", "analytics_full", "tokens_full", ] }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/tokens/deleteToken.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteToken({ token_id: "xxx" }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/tokens/updateToken.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.updateToken({ token_id: "xxx", status: "pause" }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/webhooks/create.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.createWebhook({ url: "https://example.com", name: "Webhook name", events: ["activity.sent"], domain_id: "xxx" }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/webhooks/delete.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.deleteWebhook({ webhook_id: 'xxx' }); ================================================ FILE: examples/v1/webhooks/list.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.webhooksList({ domain_id: "xxx" }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/webhooks/single.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.webhook({ webhook_id: 'xxx' }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v1/webhooks/update.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); mailersend.updateWebhook({ webhook_id: "xxx", name: "New name" }) .then(response => response.json()) .then(data => { console.log(data); }); ================================================ FILE: examples/v2/email/activity/list.js ================================================ import 'dotenv/config'; import { MailerSend, ActivityEventType } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const queryParams = { limit: 10, // Min: 10, Max: 100, Default: 25 page: 2, date_from: 1443651141, // Unix timestamp date_to: 1443651141, // Unix timestamp event: [ActivityEventType.SENT, ActivityEventType.SOFT_BOUNCED] } mailerSend.email.activity.domain("domain_id", queryParams) .then((response) => console.log(response.body)) .catch((error) => console.log(error)); ================================================ FILE: examples/v2/email/advancedPersonalization.js ================================================ import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("you@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const personalization = [ { email: "your@client.com", data: { test: 'Test Value' }, } ]; const emailParams = new EmailParams() .setFrom(sentFrom) .setTo(recipients) .setReplyTo(sentFrom) .setPersonalization(personalization) .setSubject("Subject, {{ test }}") .setHtml("This is the HTML content, {{ test }}") .setText("This is the text content, {{ test }}"); await mailerSend.email.send(emailParams); ================================================ FILE: examples/v2/email/analytics/byCountry.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.analytics.byCountry({ date_from: 1443651141, date_to: 2443651141, }).then(response => { console.log(response.body); }).catch(error => { console.log(error.body); }); ================================================ FILE: examples/v2/email/analytics/byDate.js ================================================ import 'dotenv/config'; import { ActivityEventType, MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.analytics.byDate({ date_from: 1443651141, date_to: 2443651141, event: [ActivityEventType.CLICKED, ActivityEventType.OPENED], }).then(response => { console.log(response.body); }).catch(error => { console.log(error.body); }); ================================================ FILE: examples/v2/email/analytics/byReadingEnvironment.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.analytics.byReadingEnvironment({ date_from: 1443651141, date_to: 2443651141, }).then(response => { console.log(response.body); }).catch(error => { console.log(error.body); }); ================================================ FILE: examples/v2/email/analytics/byUserAgent.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.analytics.byUserAgent({ date_from: 1443651141, date_to: 2443651141, }).then(response => { console.log(response.body); }).catch(error => { console.log(error.body); }); ================================================ FILE: examples/v2/email/ccBccRecipients.js ================================================ import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("bbbb@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const cc = [ new Recipient("your_cc@client.com", "Your Client CC") ]; const bcc = [ new Recipient("your_bcc@client.com", "Your Client BCC") ]; const emailParams = new EmailParams() .setFrom(sentFrom) .setTo(recipients) .setCc(cc) .setBcc(bcc) .setSubject("This is a Subject") .setHtml("This is the HTML content") .setText("This is the text content"); await mailerSend.email.send(emailParams); ================================================ FILE: examples/v2/email/domains/add.js ================================================ import 'dotenv/config'; import { MailerSend, Domain } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const domain = new Domain({ name: "example.com", returnPathSubdomain: "rp_subdomain", customTrackingSubdomain: "ct_subdomain", inboundRoutingSubdomain: "ir_subdomain", }) mailerSend.email.domain.create(domain) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/domains/delete.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.domain.delete("domain_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/domains/dns.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.domain.dns("domain_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/domains/list.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.domain.list() .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/domains/recipients.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.domain.recipients("domain_id", { page: 1, limit: 10 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/domains/settings.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.domain.updateSettings("domain_id", { send_paused: 1, track_clicks: 1, track_opens: 1, track_unsubscribe: 1, track_unsubscribe_html: " Unsubscribe now ", track_unsubscribe_plain: "Unsubscribe now", track_content: 1, custom_tracking_enabled: 1, custom_tracking_subdomain: "subdomain", precedence_bulk: 1, ignore_duplicated_recipients: 1, }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/domains/single.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.domain.single("domain_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/domains/verify.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.domain.verify("domain_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/getBulkEmailRequestStatus.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.getBulkStatus('bulk_email_id') // bulk email Id e.g 63af1fdb790d97105a090001 .then((response) => { console.log(response.body); }); ================================================ FILE: examples/v2/email/identities/create.js ================================================ import 'dotenv/config'; import { MailerSend, Identity } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const identity = new Identity() .setDomainId('domain_id') .setEmail('identity@yourdomain.com') .setName('Name') .setReplyToEmail('reply_identity@yourdomain.com') .setReplyToName('Reply Name') .setAddNote(false); mailerSend.email.identity.create(identity) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/identities/delete.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.identity.delete("identity_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/identities/deleteByEmail.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.identity.deleteByEmail('email_address') .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/identities/list.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.identity.list() .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/identities/single.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.identity.single("identity_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/identities/singleByEmail.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.identity.singleByEmail('email_address') .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/identities/update.js ================================================ import 'dotenv/config'; import { MailerSend, Inbound, InboundFilterType } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const data = { domain_id: 'string', email: 'email@yourdomain.com', name: 'name', personal_note: 'Personal note', reply_to_name: 'Reply Name', reply_to_email: 'repy@yourdomain.com', add_note: true, }; mailerSend.email.identity.update('identiy_id', data) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/identities/updateByEmail.js ================================================ import 'dotenv/config'; import { MailerSend, Inbound, InboundFilterType } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const data = { domain_id: 'string', email: 'email@yourdomain.com', name: 'name', personal_note: 'Personal note', reply_to_name: 'Reply Name', reply_to_email: 'repy@yourdomain.com', add_note: true, }; mailerSend.email.identity.updateByEmail('email_address', data) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/inbounds/create.js ================================================ import 'dotenv/config'; import { MailerSend, Inbound, InboundFilterType } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const inbound = new Inbound('inbound test', true, 'domain_id') .setInboundPriority(100) .setMatchFilter({ type: InboundFilterType.MATCH_ALL, }) .setForwards([ { type: "webhook", value: "https://www.yourdomain.com/hook" } ]); mailerSend.email.inbound.create(inbound) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/inbounds/delete.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.inbound.delete("inbound_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/inbounds/list.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.inbound.list() .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/inbounds/single.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.inbound.single("inbound_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/inbounds/update.js ================================================ import 'dotenv/config'; import { MailerSend, Inbound, InboundFilterType } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const inbound = new Inbound('inbound test 2', false, 'domain_id') .setMatchFilter({ type: InboundFilterType.MATCH_ALL, }) .setForwards([ { type: "webhook", value: "https://www.yourdomain.com/hook" } ]); mailerSend.email.inbound.update('inbound_id', inbound) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/messages/list.js ================================================ import 'dotenv/config'; import { MailerSend} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.message.list() .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/messages/single.js ================================================ import 'dotenv/config'; import { MailerSend} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.message.single("message_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/recipients/addRecipientsToBlocklist.js ================================================ import 'dotenv/config'; import { BlockListType, MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.recipient.blockRecipients({ domain_id: 'domain_id', recipients: [ "test@example.com" ] }, BlockListType.BLOCK_LIST) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/recipients/addRecipientsToHardBounceList.js ================================================ import 'dotenv/config'; import { BlockListType, MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.recipient.blockRecipients({ domain_id: 'domain_id', recipients: [ "test@example.com" ] }, BlockListType.HARD_BOUNCES_LIST) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/recipients/addRecipientsToSpamComplaintList.js ================================================ import 'dotenv/config'; import { BlockListType, MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.recipient.blockRecipients({ domain_id: 'domain_id', recipients: [ "test@example.com" ] }, BlockListType.SPAM_COMPLAINTS_LIST) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/recipients/addRecipientsToUnsubscribeList.js ================================================ import 'dotenv/config'; import { BlockListType, MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.recipient.blockRecipients({ domain_id: 'domain_id', recipients: [ "test@example.com" ] }, BlockListType.UNSUBSCRIBES_LIST) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/recipients/delete.js ================================================ import 'dotenv/config'; import { MailerSend} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.recipient.delete("recipient_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/recipients/deleteAllBlocklistRecipients.js ================================================ import 'dotenv/config'; import { BlockListType, MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.recipient.delAllBlockListRecipients(BlockListType.BLOCK_LIST) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/recipients/deleteRecipientsFromBlocklist.js ================================================ import 'dotenv/config'; import { BlockListType, MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.recipient.delBlockListRecipients( ["recipient_id", "recipient_id"], BlockListType.BLOCK_LIST ) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/recipients/deleteRecipientsFromHardBounceList.js ================================================ import 'dotenv/config'; import { BlockListType, MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.recipient.delBlockListRecipients( ["recipient_id", "recipient_id"], BlockListType.HARD_BOUNCES_LIST ) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/recipients/deleteRecipientsFromSpamComplaintList.js ================================================ import 'dotenv/config'; import { BlockListType, MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.recipient.delBlockListRecipients( ["recipient_id", "recipient_id"], BlockListType.SPAM_COMPLAINTS_LIST ) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/recipients/deleteRecipientsFromUnsubscribeList.js ================================================ import 'dotenv/config'; import { BlockListType, MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.recipient.delBlockListRecipients( ["recipient_id", "recipient_id"], BlockListType.UNSUBSCRIBES_LIST ) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/recipients/getRecipientsFromBlocklist.js ================================================ import 'dotenv/config'; import { BlockListType, MailerSend} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.recipient.blockList( { domain_id: "domain_id", }, BlockListType.BLOCK_LIST ) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/recipients/getRecipientsFromHardBounceList.js ================================================ import 'dotenv/config'; import { BlockListType, MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.recipient.blockList( { domain_id: "domain_id", }, BlockListType.HARD_BOUNCES_LIST ) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/recipients/getRecipientsFromSpamComplaintList.js ================================================ import 'dotenv/config'; import { BlockListType, MailerSend} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.recipient.blockList( { domain_id: "domain_id", }, BlockListType.SPAM_COMPLAINTS_LIST ) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/recipients/getRecipientsFromUnsubscribeList.js ================================================ import 'dotenv/config'; import { BlockListType, MailerSend} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.recipient.blockList( { domain_id: "domain_id", }, BlockListType.UNSUBSCRIBES_LIST ) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/recipients/list.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.recipient.list({ domain_id: "domain_id", limit: 10, }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/recipients/single.js ================================================ import 'dotenv/config'; import { MailerSend} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.recipient.single("recipient_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/scheduled/delete.js ================================================ import 'dotenv/config'; import { MailerSend} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.schedule.delete("message_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/scheduled/list.js ================================================ import 'dotenv/config'; import { MailerSend} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.schedule.list() .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/scheduled/single.js ================================================ import 'dotenv/config'; import { MailerSend} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.schedule.single("message_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/sendAnEmail.js ================================================ import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("you@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const emailParams = new EmailParams() .setFrom(sentFrom) .setTo(recipients) .setReplyTo(sentFrom) .setSubject("This is a Subject") .setHtml("This is the HTML content") .setText("This is the text content"); await mailerSend.email.send(emailParams); ================================================ FILE: examples/v2/email/sendBulkEmail.js ================================================ import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("your@yourdomain.com", "Your name"); const bulkEmails = []; const emailParams = new EmailParams() .setFrom(sentFrom) .setTo([ new Recipient("your@client.com", "Your Client") ]) .setSubject("This is a Subject") .setHtml("This is the HTML content") .setText("This is the text content"); bulkEmails.push(emailParams); const emailParams2 = new EmailParams() .setFrom(sentFrom) .setTo([ new Recipient("your_2@client.com", "Your Client 2") ]) .setSubject("This is a Subject 2") .setHtml("This is the HTML content 2") .setText("This is the text content 2"); bulkEmails.push(emailParams2); await mailerSend.email.sendBulk(bulkEmails); ================================================ FILE: examples/v2/email/sendScheduleEmail.js ================================================ import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("you@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const emailParams = new EmailParams() .setFrom(sentFrom) .setTo(recipients) .setReplyTo(sentFrom) .setSubject("This is a scheduled Subject") .setHtml("This is a scheduled HTML content") .setText("This is a scheduled text content") .setSendAt(Math.floor((new Date(Date.now()+ 30*60*1000)).getTime() / 1000)); //send in 30mins NB:param has to be a Unix timestamp e.g 2443651141 await mailerSend.email.send(emailParams); ================================================ FILE: examples/v2/email/simplePersonalization.js ================================================ import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("you@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const variables = [ { email: "your@client.com", substitutions: [ { var: 'test', value: 'Test Value' } ], } ]; const emailParams = new EmailParams() .setFrom(sentFrom) .setTo(recipients) .setReplyTo(sentFrom) .setVariables(variables) .setSubject("Subject, {$test}") .setHtml("This is the HTML content, {$test}") .setText("This is the text content, {$test}"); await mailerSend.email.send(emailParams); ================================================ FILE: examples/v2/email/templatedEmail.js ================================================ import 'dotenv/config'; import { MailerSend, EmailParams, Sender, Recipient } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("you@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const emailParams = new EmailParams() .setFrom(sentFrom) .setTo(recipients) .setReplyTo(sentFrom) .setSubject("This is a Subject") .setTemplateId('templateId'); await mailerSend.email.send(emailParams); ================================================ FILE: examples/v2/email/templates/delete.js ================================================ import 'dotenv/config'; import { MailerSend} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.template.single("domain_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/templates/list.js ================================================ import 'dotenv/config'; import { MailerSend} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.template.list({ domain_id: "domain_id" }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/templates/single.js ================================================ import 'dotenv/config'; import { MailerSend} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.template.single("domain_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/webhooks/create.js ================================================ import 'dotenv/config'; import { EmailWebhook, EmailWebhookEventType, MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const emailWebhook = new EmailWebhook() .setName("Webhook Name") .setUrl("https://example.com") .setDomainId("domain_id") .setEnabled(true) .setEvents([EmailWebhookEventType.SENT, EmailWebhookEventType.OPENED]); mailerSend.email.webhook.create(emailWebhook) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/webhooks/delete.js ================================================ import 'dotenv/config'; import { MailerSend} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.webhook.delete("webhook_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/webhooks/list.js ================================================ import 'dotenv/config'; import { MailerSend} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.webhook.list("domain_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/webhooks/single.js ================================================ import 'dotenv/config'; import { MailerSend} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.email.webhook.single("webhook_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/webhooks/update.js ================================================ import 'dotenv/config'; import { EmailWebhook, EmailWebhookEventType, MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const emailWebhook = new EmailWebhook() .setName("Webhook Name 2") .setEnabled(false) .setEvents([EmailWebhookEventType.SENT, EmailWebhookEventType.OPENED]); mailerSend.email.webhook.update("webhook_id", emailWebhook) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email/withAttachment.js ================================================ import 'dotenv/config'; import fs from "fs"; import { MailerSend, EmailParams, Sender, Recipient, Attachment } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const sentFrom = new Sender("you@yourdomain.com", "Your name"); const recipients = [ new Recipient("your@client.com", "Your Client") ]; const attachments = [ new Attachment( fs.readFileSync('/path/to/file.pdf', { encoding: 'base64' }), 'file.pdf', 'attachment' ) ] const emailParams = new EmailParams() .setFrom(sentFrom) .setTo(recipients) .setReplyTo(sentFrom) .setAttachments(attachments) .setSubject("This is a Subject") .setHtml("This is the HTML content") .setText("This is the text content"); await mailerSend.email.send(emailParams); ================================================ FILE: examples/v2/email-verification/create.js ================================================ import 'dotenv/config'; import { EmailVerification, MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const emailVerification = new EmailVerification() .setName("List example") .setEmails([ "info@mailersend.com", "test@mailersend.com" ]); mailerSend.emailVerification.create(emailVerification) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email-verification/list.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.emailVerification.list({ limit: 10, page: 1 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email-verification/results.js ================================================ import 'dotenv/config'; import { EmailVerificationResultType, MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.emailVerification.getListResult("email_verification_id",{ limit: 10, page: 1, result: [EmailVerificationResultType.CATCH_ALL, EmailVerificationResultType.DISPOSABLE] }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email-verification/single.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.emailVerification.single("email_verification_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email-verification/verifyEmail.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.emailVerification.verifyEmail("client@domain.com") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/email-verification/verifyList.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.emailVerification.verifyList("email_verification_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/others/getApiQuota.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.others.getApiQuota() .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/activities/list.js ================================================ import 'dotenv/config'; import { MailerSend, SmsActivityStatusType } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.activity.list({ sms_number_id: "number_id", status: [SmsActivityStatusType.SENT, SmsActivityStatusType.DELIVERED], limit: 10, page: 1 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/activities/single.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.activity.single("sms_message_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/inbounds/create.js ================================================ import 'dotenv/config'; import { MailerSend, SmsInbound } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const smsInbound = new SmsInbound() .setSmsNumberId("sms_number_id") .setEnabled(true) .setName("Inbound Name") .setForwardUrl("yourapp.com/hook") .setFilter({ comparer: "equal", value: "START" }); mailerSend.sms.inbound.create(smsInbound) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/inbounds/delete.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.inbound.delete("sms_inbound_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/inbounds/list.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.inbound.list({ enabled: 1, sms_number_id: "sms_number_id", limit: 10, page: 1, }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/inbounds/single.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.inbound.single("sms_inbound_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/inbounds/update.js ================================================ import 'dotenv/config'; import { MailerSend, SmsInbound } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const smsInbound = new SmsInbound() .setSmsNumberId("sms_number_id") .setEnabled(true) .setName("Inbound Name Update") .setForwardUrl("yourapp.com/hook") .setFilter({ comparer: "equal", value: "START" }); mailerSend.sms.inbound.update("sms_inbound_id", {...smsInbound}) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/messages/list.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.message.list({ limit: 10, page: 1 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/messages/single.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.message.single("sms_message_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/numbers/delete.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.number.delete("sms_number_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/numbers/list.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.number.list({ paused: false, limit: 10, page: 1 }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/numbers/single.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.number.single("sms_number_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/numbers/update.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.number.update("sms_number_id", true) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/recipients/list.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.recipient.list({ sms_number_id: "sms_number_id", status: "active", limit: 10, page: 1, }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/recipients/single.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.recipient.single("sms_recipient_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/recipients/update.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.recipient.list({ sms_number_id: "sms_number_id", status: "active", limit: 10, page: 1, }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/sendAnSms.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const SmsParams = require("../../src/SmsParams"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); const to = [ "+18332647501" ]; const smsParams = new SmsParams() .setFrom("+18332647501") .setTo(to) .setText("This is the text content"); mailersend.sendSms(smsParams); ================================================ FILE: examples/v2/sms/smsPersonalization.js ================================================ "use strict"; require('dotenv').config() const MailerSend = require("../../src/MailerSend"); const SmsParams = require("../../src/SmsParams"); const mailersend = new MailerSend({ api_key: process.env.API_KEY, }); const to = [ "+18332647501", "+18332647502" ]; const personalization = [ { "phone_number": "+18332647501", "data": { "name": "Dummy" } }, { "phone_number": "+18332647502", "data": { "name": "Not Dummy" } } ]; const smsParams = new SmsParams() .setFrom("+18332647501") .setTo(to) .setPersonalization(personalization) .setText("Hey {{name}} welcome to our organization"); mailersend.sendSms(smsParams); ================================================ FILE: examples/v2/sms/webhooks/create.js ================================================ import 'dotenv/config'; import { MailerSend, SmsWebhook, SmsWebhookEventType } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const smsWebhook = new SmsWebhook() .setName("Sms Webhook") .setUrl("https:://yourapp.com/hook") .setSmsNumberId("sms_number_id") .setEnabled(true) .setEvents([SmsWebhookEventType.SENT, SmsWebhookEventType.DELIVERED]) mailerSend.sms.webhook.create(smsWebhook) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/webhooks/delete.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.webhook.delete("sms_webhook_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/webhooks/list.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.webhook.list("sms_number_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/webhooks/single.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.webhook.single("sms_webhook_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/sms/webhooks/update.js ================================================ import 'dotenv/config'; import { MailerSend } from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.sms.webhook.update("sms_webhook_id", { name: "Webhook", url: "https:://yourapp.com/hook", enabled: ["sms.sent", "sms.delivered", "sms.failed"], enabled: true }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/tokens/createToken.js ================================================ import 'dotenv/config'; import { MailerSend, Token} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); const token = new Token() .setName("Token name") .setDomainId("domain_id") .setScopes([ "email_full", "domains_read", "domains_full", "activity_read", "activity_full", "analytics_read", "analytics_full", "tokens_full", ]); mailerSend.token.create(token) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/tokens/deleteToken.js ================================================ import 'dotenv/config'; import { MailerSend} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.token.delete("token_id") .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: examples/v2/tokens/updateToken.js ================================================ import 'dotenv/config'; import { MailerSend} from "mailersend"; const mailerSend = new MailerSend({ apiKey: process.env.API_KEY, }); mailerSend.token.updateSettings("token_id", { status: "pause", }) .then((response) => console.log(response.body)) .catch((error) => console.log(error.body)); ================================================ FILE: jestconfig.json ================================================ { "transform": { "^.+\\.(t|j)sx?$": "ts-jest" }, "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", "moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"], "coverageReporters": ["json-summary", "text", "lcov"] } ================================================ FILE: package.json ================================================ { "name": "mailersend", "version": "3.0.0", "description": "Node.js helper module for MailerSend API", "main": "./lib/index.js", "typings": "./lib/index.d.ts", "files": [ "lib/**/*" ], "directories": { "lib": "./lib" }, "repository": { "type": "git", "url": "git+https://github.com/mailersend/mailersend-nodejs.git" }, "keywords": [ "mailersend", "mailersend-ts", "mailer_send", "smtp-sender", "email-sender", "email-api", "transactional-emails", "transactional-sms", "typescript", "mailer-send", "types", "email" ], "author": "MailerSend", "license": "MIT", "bugs": { "url": "https://github.com/mailersend/mailersend-nodejs/issues" }, "homepage": "https://www.mailersend.com/", "scripts": { "build": "tsc", "watch": "tsc --watch", "test": "jest --config jestconfig.json", "prepare": "npm run build", "prepublishOnly": "npm test", "version": "git add -A src", "postversion": "git push && git push --tags" }, "dependencies": { "gaxios": "^7.0.0", "qs": "^6.11.0" }, "devDependencies": { "@types/jest": "^29.0.0", "dotenv": "^17.0.0", "jest": "^29.7.0", "jest-coverage-badges": "^1.1.2", "nock": "^14.0.0", "prettier": "^3.0.0", "ts-jest": "^29.2.6", "typescript": "^5.0.0" } } ================================================ FILE: renovate.json ================================================ { "extends": ["github>mailerlite/renovate-config:base"] } ================================================ FILE: src/__tests__/modules/Activity.test.ts ================================================ import nock from "nock"; import { ActivityModule } from "../../modules/email/Activity.module"; import { ActivityEventType } from "../../models/email/Activity"; describe("Activity Module", () => { const activityModule = new ActivityModule("test_key", "http://test.com"); it("domain", async () => { nock("http://test.com") .get("/activity/test_id") .query({ limit: 20, page: 2, date_from: 1672531200, date_to: 1675209600 }) .reply(200, { key1: "key1_value" }, { header1: "test" }); const getActivities = await activityModule.domain("test_id", { limit: 20, page: 2, date_from: 1672531200, date_to: 1675209600 }); expect(getActivities.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(getActivities.body).toMatchObject({ key1: "key1_value" }); expect(getActivities.statusCode).toBe(200); }); it("domain with event filter", async () => { nock("http://test.com") .get("/activity/test_id") .query({ date_from: 1672531200, date_to: 1675209600, "event[0]": ActivityEventType.QUEUED, "event[1]": ActivityEventType.SENT }) .reply(200, { key1: "key1_value" }, { header1: "test" }); const getActivities = await activityModule.domain("test_id", { date_from: 1672531200, date_to: 1675209600, event: [ActivityEventType.QUEUED, ActivityEventType.SENT] }); expect(getActivities.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(getActivities.body).toMatchObject({ key1: "key1_value" }); expect(getActivities.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/activities/test_activity_id").reply(200, { key1: "activity_value" }, { header1: "test" }); const result = await activityModule.single("test_activity_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "activity_value" }); expect(result.statusCode).toBe(200); }); }); ================================================ FILE: src/__tests__/modules/Analytics.test.ts ================================================ import nock from "nock"; import { AnalyticsModule } from "../../modules/email/Analytics.module"; import { ActivityEventType } from "../../models/email/Activity"; import { AnalyticsGroupByType } from "../../models"; describe("Analytics Module", () => { const analyticsModule = new AnalyticsModule("test_key", "http://test.com"); const baseParams = { date_from: 1672531200, date_to: 1675209600, domain_id: "test_domain_id" }; it("byDate", async () => { nock("http://test.com").get("/analytics/date").query(baseParams).reply(200, { key1: "date_value" }, { header1: "test" }); const result = await analyticsModule.byDate(baseParams); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "date_value" }); expect(result.statusCode).toBe(200); }); it("byCountry", async () => { nock("http://test.com").get("/analytics/country").query(baseParams).reply(200, { key1: "country_value" }, { header1: "test" }); const result = await analyticsModule.byCountry(baseParams); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "country_value" }); expect(result.statusCode).toBe(200); }); it("byUserAgent", async () => { nock("http://test.com").get("/analytics/ua-name").query(baseParams).reply(200, { key1: "ua_value" }, { header1: "test" }); const result = await analyticsModule.byUserAgent(baseParams); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "ua_value" }); expect(result.statusCode).toBe(200); }); it("byReadingEnvironment", async () => { nock("http://test.com").get("/analytics/ua-type").query(baseParams).reply(200, { key1: "ua_type_value" }, { header1: "test" }); const result = await analyticsModule.byReadingEnvironment(baseParams); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "ua_type_value" }); expect(result.statusCode).toBe(200); }); it("byDate with event and group_by", async () => { const dateParams = { ...baseParams, group_by: AnalyticsGroupByType.DAYS, event: [ActivityEventType.CLICKED, ActivityEventType.OPENED] }; nock("http://test.com").get("/analytics/date").query(dateParams).reply(200, { key1: "date_grouped_value" }, { header1: "test" }); const result = await analyticsModule.byDate(dateParams); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "date_grouped_value" }); expect(result.statusCode).toBe(200); }); it("byDate with tags and recipient_id", async () => { const params = { ...baseParams, tags: ["tag1", "tag2"], recipient_id: ["rcpt_id_1"] }; nock("http://test.com").get("/analytics/date").query(params).reply(200, { key1: "date_value" }, { header1: "test" }); const result = await analyticsModule.byDate(params); expect(result.statusCode).toBe(200); }); it("byCountry with tags and recipient_id", async () => { const params = { ...baseParams, tags: ["tag1"], recipient_id: ["rcpt_id_1"] }; nock("http://test.com").get("/analytics/country").query(params).reply(200, { key1: "country_value" }, { header1: "test" }); const result = await analyticsModule.byCountry(params); expect(result.statusCode).toBe(200); }); it("byUserAgent with tags and recipient_id", async () => { const params = { ...baseParams, tags: ["tag1"], recipient_id: ["rcpt_id_1"] }; nock("http://test.com").get("/analytics/ua-name").query(params).reply(200, { key1: "ua_value" }, { header1: "test" }); const result = await analyticsModule.byUserAgent(params); expect(result.statusCode).toBe(200); }); it("byReadingEnvironment with tags and recipient_id", async () => { const params = { ...baseParams, tags: ["tag1"], recipient_id: ["rcpt_id_1"] }; nock("http://test.com").get("/analytics/ua-type").query(params).reply(200, { key1: "ua_type_value" }, { header1: "test" }); const result = await analyticsModule.byReadingEnvironment(params); expect(result.statusCode).toBe(200); }); }); ================================================ FILE: src/__tests__/modules/BlocklistMonitor.test.ts ================================================ import nock from "nock"; import { BlocklistMonitorModule } from "../../modules/BlocklistMonitor.module"; import { BlocklistMonitor } from "../../models"; describe("Blocklist Monitor Module", () => { const blocklistMonitorModule = new BlocklistMonitorModule("test_key", "http://test.com"); it("list", async () => { const params = { page: 1, limit: 10 }; nock("http://test.com").get("/blocklist-monitoring").query(params).reply(200, { key1: "monitor_list" }, { header1: "test" }); const result = await blocklistMonitorModule.list(params); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "monitor_list" }); expect(result.statusCode).toBe(200); }); it("list with query and ordering", async () => { const params = { query: "example.com", sort_by: "name" as const, order: "asc" as const }; nock("http://test.com").get("/blocklist-monitoring").query(params).reply(200, { key1: "monitor_list" }, { header1: "test" }); const result = await blocklistMonitorModule.list(params); expect(result.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/blocklist-monitoring/test_monitor_id").reply(200, { key1: "monitor_value" }, { header1: "test" }); const result = await blocklistMonitorModule.single("test_monitor_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "monitor_value" }); expect(result.statusCode).toBe(200); }); it("create", async () => { const monitor = new BlocklistMonitor("example.com"); nock("http://test.com").post("/blocklist-monitoring", (body: any) => body.address === "example.com").reply(201, { key1: "monitor_created" }, { header1: "test" }); const result = await blocklistMonitorModule.create(monitor); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "monitor_created" }); expect(result.statusCode).toBe(201); }); it("create with all fields", async () => { const monitor = new BlocklistMonitor("example.com") .setName("My Monitor") .setNotify(true) .setNotifyEmail("alerts@example.com") .setNotifyAddress("https://example.com/webhook"); nock("http://test.com") .post("/blocklist-monitoring", (body: any) => body.address === "example.com" && body.name === "My Monitor" && body.notify === true && body.notify_email === "alerts@example.com" && body.notify_address === "https://example.com/webhook" ) .reply(201, { key1: "monitor_created" }, { header1: "test" }); const result = await blocklistMonitorModule.create(monitor); expect(result.statusCode).toBe(201); }); it("update", async () => { const data = { name: "Updated Monitor" }; nock("http://test.com").put("/blocklist-monitoring/test_monitor_id", (body: any) => body.name === "Updated Monitor").reply(200, { key1: "monitor_updated" }, { header1: "test" }); const result = await blocklistMonitorModule.update("test_monitor_id", data); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "monitor_updated" }); expect(result.statusCode).toBe(200); }); it("update with notify fields", async () => { nock("http://test.com") .put("/blocklist-monitoring/test_monitor_id", (body: any) => body.notify === true && body.notify_email === "alerts@example.com" && body.notify_address === "https://example.com/webhook" ) .reply(200, { key1: "monitor_updated" }, { header1: "test" }); const result = await blocklistMonitorModule.update("test_monitor_id", { notify: true, notify_email: "alerts@example.com", notify_address: "https://example.com/webhook", }); expect(result.statusCode).toBe(200); }); it("delete", async () => { nock("http://test.com").delete("/blocklist-monitoring/test_monitor_id").reply(204, {}, { header1: "test" }); const result = await blocklistMonitorModule.delete("test_monitor_id"); expect(result.statusCode).toBe(204); }); }); ================================================ FILE: src/__tests__/modules/Dmarc.test.ts ================================================ import nock from "nock"; import { DmarcModule } from "../../modules/Dmarc.module"; import { Dmarc } from "../../models"; describe("Dmarc Module", () => { const dmarcModule = new DmarcModule("test_key", "http://test.com"); it("list", async () => { const params = { limit: 20, page: 2 }; nock("http://test.com").get("/dmarc-monitoring").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const response = await dmarcModule.list(params); expect(response.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(response.body).toMatchObject({ key1: "key1_value" }); expect(response.statusCode).toBe(200); }); it("list with query and ordering", async () => { const params = { query: "example.com", sort_by: "created_at" as const, order: "desc" as const }; nock("http://test.com").get("/dmarc-monitoring").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const response = await dmarcModule.list(params); expect(response.statusCode).toBe(200); }); it("create", async () => { const dmarc = new Dmarc("domain_id_123"); nock("http://test.com").post("/dmarc-monitoring").reply(201, { id: "monitor_id_123" }, { header1: "test" }); const response = await dmarcModule.create(dmarc); expect(response.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(response.body).toMatchObject({ id: "monitor_id_123" }); expect(response.statusCode).toBe(201); }); it("update", async () => { nock("http://test.com").put("/dmarc-monitoring/test_id").reply(200, { key1: "key1_value" }, { header1: "test" }); const response = await dmarcModule.update("test_id", { wanted_dmarc_record: "v=DMARC1; p=reject;" }); expect(response.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(response.body).toMatchObject({ key1: "key1_value" }); expect(response.statusCode).toBe(200); }); it("delete", async () => { nock("http://test.com").delete("/dmarc-monitoring/test_id").reply(204, {}, { header1: "test" }); const response = await dmarcModule.delete("test_id"); expect(response.statusCode).toBe(204); }); it("report", async () => { const params = { limit: 10, page: 1 }; nock("http://test.com").get("/dmarc-monitoring/test_id/report").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const response = await dmarcModule.report("test_id", params); expect(response.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(response.body).toMatchObject({ key1: "key1_value" }); expect(response.statusCode).toBe(200); }); it("report with filters", async () => { const params = { date_from: "2024-01-01", date_to: "2024-01-31", search: "192.0.2.1", category: "fail", report_source: "google.com" }; nock("http://test.com").get("/dmarc-monitoring/test_id/report").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const response = await dmarcModule.report("test_id", params); expect(response.statusCode).toBe(200); }); it("reportByIp", async () => { const params = { limit: 10, page: 1 }; nock("http://test.com").get("/dmarc-monitoring/test_id/report/1.2.3.4").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const response = await dmarcModule.reportByIp("test_id", "1.2.3.4", params); expect(response.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(response.body).toMatchObject({ key1: "key1_value" }); expect(response.statusCode).toBe(200); }); it("reportByIp with filters", async () => { const params = { date_from: "2024-01-01", date_to: "2024-01-31", search: "test", category: "fail", report_source: "google.com" }; nock("http://test.com").get("/dmarc-monitoring/test_id/report/1.2.3.4").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const response = await dmarcModule.reportByIp("test_id", "1.2.3.4", params); expect(response.statusCode).toBe(200); }); it("reportSources", async () => { const params = { date_from: "2024-01-01", date_to: "2024-01-31" }; nock("http://test.com").get("/dmarc-monitoring/test_id/report-sources").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const response = await dmarcModule.reportSources("test_id", params); expect(response.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(response.body).toMatchObject({ key1: "key1_value" }); expect(response.statusCode).toBe(200); }); it("reportSources with status", async () => { const params = { date_from: "2024-01-01", date_to: "2024-01-31", status: "rejected" as const }; nock("http://test.com").get("/dmarc-monitoring/test_id/report-sources").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const response = await dmarcModule.reportSources("test_id", params); expect(response.statusCode).toBe(200); }); it("addFavorite", async () => { nock("http://test.com").put("/dmarc-monitoring/test_id/favorite/1.2.3.4").reply(200, {}, { header1: "test" }); const response = await dmarcModule.addFavorite("test_id", "1.2.3.4"); expect(response.statusCode).toBe(200); }); it("removeFavorite", async () => { nock("http://test.com").delete("/dmarc-monitoring/test_id/favorite/1.2.3.4").reply(204, {}, { header1: "test" }); const response = await dmarcModule.removeFavorite("test_id", "1.2.3.4"); expect(response.statusCode).toBe(204); }); }); ================================================ FILE: src/__tests__/modules/Domain.test.ts ================================================ import nock from "nock"; import { DomainModule } from "../../modules/email/Domain.module"; import { Domain } from "../../models"; describe("Domain Module", () => { const domainModule = new DomainModule("test_key", "http://test.com"); it("create", async () => { const domain = new Domain("mydomain.com", "rp_subdomain", "ct_subdomain", "ir_subdomain"); nock("http://test.com") .post("/domains", { name: "mydomain.com", return_path_subdomain: "rp_subdomain", custom_tracking_subdomain: "ct_subdomain", inbound_routing_subdomain: "ir_subdomain", }) .reply( 200, { id: "dle1krod2jvn8gwm", name: "mydomain.com", }, { header1: "test" }, ); const createDomain = await domainModule.create(domain); expect(createDomain.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(createDomain.body).toMatchObject({ id: "dle1krod2jvn8gwm", name: "mydomain.com" }); expect(createDomain.statusCode).toBe(200); }); it("create with only name", async () => { const domain = new Domain("mydomain.com"); nock("http://test.com") .post("/domains", { name: "mydomain.com" }) .reply(200, { id: "dle1krod2jvn8gwm", name: "mydomain.com" }, { header1: "test" }); const createDomain = await domainModule.create(domain); expect(createDomain.body).toMatchObject({ id: "dle1krod2jvn8gwm", name: "mydomain.com" }); expect(createDomain.statusCode).toBe(200); }); it("list", async () => { const params = { limit: 20, page: 2, verified: true }; nock("http://test.com").get("/domains").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const getDomains = await domainModule.list(params); expect(getDomains.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(getDomains.body).toMatchObject({ key1: "key1_value" }); expect(getDomains.statusCode).toBe(200); }); it("recipients", async () => { const params = { limit: 20, page: 2 }; nock("http://test.com") .get("/domains/test_id/recipients") .query(params) .reply(200, { key1: "key1_value" }, { header1: "test" }); const getDomains = await domainModule.recipients("test_id", params); expect(getDomains.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(getDomains.body).toMatchObject({ key1: "key1_value" }); expect(getDomains.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/domains/test_id").reply(200, { key1: "key1_value" }, { header1: "test" }); const getDomain = await domainModule.single("test_id"); expect(getDomain.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(getDomain.body).toMatchObject({ key1: "key1_value" }); expect(getDomain.statusCode).toBe(200); }); it("settings", async () => { nock("http://test.com") .put("/domains/test_id/settings", { send_paused: true, track_clicks: true, track_unsubscribe_html: "html here", }) .reply(200, { key1: "key1_value" }, { header1: "test" }); const updateSettings = await domainModule.updateSettings("test_id", { send_paused: true, track_clicks: true, track_unsubscribe_html: "html here", }); expect(updateSettings.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(updateSettings.body).toMatchObject({ key1: "key1_value" }); expect(updateSettings.statusCode).toBe(200); }); it("settings with all remaining fields", async () => { nock("http://test.com") .put("/domains/test_id/settings", { track_opens: true, track_unsubscribe: true, track_unsubscribe_plain: "Unsubscribe now", track_unsubscribe_html_enabled: true, track_unsubscribe_plain_enabled: true, track_content: true, custom_tracking_enabled: true, custom_tracking_subdomain: "track_subdomain", precedence_bulk: true, ignore_duplicated_recipients: true, }) .reply(200, { key1: "key1_value" }, { header1: "test" }); const updateSettings = await domainModule.updateSettings("test_id", { track_opens: true, track_unsubscribe: true, track_unsubscribe_plain: "Unsubscribe now", track_unsubscribe_html_enabled: true, track_unsubscribe_plain_enabled: true, track_content: true, custom_tracking_enabled: true, custom_tracking_subdomain: "track_subdomain", precedence_bulk: true, ignore_duplicated_recipients: true, }); expect(updateSettings.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(updateSettings.body).toMatchObject({ key1: "key1_value" }); expect(updateSettings.statusCode).toBe(200); }); it("delete", async () => { nock("http://test.com").delete("/domains/test_id").reply(204); const deleteDomain = await domainModule.delete("test_id"); expect(deleteDomain.statusCode).toBe(204); }); it("dns", async () => { nock("http://test.com").get("/domains/test_id/dns-records").reply(200, { key1: "dns" }, { header1: "dns-header" }); const getDNS = await domainModule.dns("test_id"); expect(getDNS.headers).toMatchObject({ header1: "dns-header", "content-type": "application/json" }); expect(getDNS.body).toMatchObject({ key1: "dns" }); expect(getDNS.statusCode).toBe(200); }); it("verify", async () => { nock("http://test.com").get("/domains/test_id/verify").reply(200, { key1: "verify" }, { header1: "verify-header" }); const verifyDomain = await domainModule.verify("test_id"); expect(verifyDomain.headers).toMatchObject({ header1: "verify-header", "content-type": "application/json" }); expect(verifyDomain.body).toMatchObject({ key1: "verify" }); expect(verifyDomain.statusCode).toBe(200); }); }); ================================================ FILE: src/__tests__/modules/Email.test.ts ================================================ import nock from "nock"; import { EmailModule } from "../../modules/Email.module"; import { EmailParams, Recipient, EmailWebhook, EmailWebhookEventType } from "../../models"; import { Attachment } from "../../models/email/Attachment"; import { ActivityModule } from "../../modules/email/Activity.module"; import { AnalyticsModule } from "../../modules/email/Analytics.module"; import { DomainModule } from "../../modules/email/Domain.module"; import { InboundModule } from "../../modules/email/Inbound.module"; import { MessageModule } from "../../modules/email/Message.module"; import { ScheduleModule } from "../../modules/email/Schedule.module"; import { RecipientModule } from "../../modules/email/Recipient.module"; import { TemplateModule } from "../../modules/email/Template.module"; import { EmailWebhookModule } from "../../modules/email/Webhook.module"; describe("Email Module", () => { const emailModule = new EmailModule("test_key", "http://test.com"); it("Constructor", () => { expect(emailModule.activity instanceof ActivityModule).toBe(true); expect(emailModule.analytics instanceof AnalyticsModule).toBe(true); expect(emailModule.domain instanceof DomainModule).toBe(true); expect(emailModule.inbound instanceof InboundModule).toBe(true); expect(emailModule.message instanceof MessageModule).toBe(true); expect(emailModule.schedule instanceof ScheduleModule).toBe(true); expect(emailModule.recipient instanceof RecipientModule).toBe(true); expect(emailModule.template instanceof TemplateModule).toBe(true); expect(emailModule.webhook instanceof EmailWebhookModule).toBe(true); }); it("send email", async () => { nock("http://test.com").post("/email").reply(202, { key1: "key1_value" }, { header1: "test" }); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setText("Some text") .setHtml("Some html"); const sendEmail = await emailModule.send(emailParams); expect(sendEmail.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(sendEmail.body).toMatchObject({ key1: "key1_value" }); expect(sendEmail.statusCode).toBe(202); }); it("send email with personalization", async () => { const personalization = [ { email: "your@client.com", data: { test: { number: 123434, } }, } ]; nock("http://test.com").post("/email").reply(202, { key1: "key1_value" }, { header1: "test" }); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setPersonalization(personalization) .setText("Some text") .setHtml("Some html"); const sendEmail = await emailModule.send(emailParams); expect(sendEmail.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(sendEmail.body).toMatchObject({ key1: "key1_value" }); expect(sendEmail.statusCode).toBe(202); }); it("send email with send_at as unix timestamp", async () => { const sendAt = 1893456000; nock("http://test.com") .post("/email", (body: any) => body.send_at === sendAt) .reply(202, {}, {}); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setText("Some text") .setSendAt(sendAt); const result = await emailModule.send(emailParams); expect(result.statusCode).toBe(202); }); it("send email with send_at as ISO string", async () => { const sendAt = "2030-01-01T12:00:00Z"; nock("http://test.com") .post("/email", (body: any) => body.send_at === sendAt) .reply(202, {}, {}); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setText("Some text") .setSendAt(sendAt); const result = await emailModule.send(emailParams); expect(result.statusCode).toBe(202); }); it("send email with attachments", async () => { const attachment = new Attachment("base64content", "file.pdf", "attachment", "attach_id"); nock("http://test.com") .post("/email", (body: any) => { const a = body.attachments[0]; return a.content === "base64content" && a.filename === "file.pdf" && a.disposition === "attachment" && a.id === "attach_id"; }) .reply(202, {}, {}); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setText("Some text") .setAttachments([attachment]); const result = await emailModule.send(emailParams); expect(result.statusCode).toBe(202); }); it("send email with template_id", async () => { nock("http://test.com") .post("/email", (body: any) => body.template_id === "tmpl_abc123") .reply(202, {}, {}); const emailParams = new EmailParams() .setTo([new Recipient("some_recipient@mail.com")]) .setTemplateId("tmpl_abc123"); const result = await emailModule.send(emailParams); expect(result.statusCode).toBe(202); }); it("send email with cc", async () => { const cc = [new Recipient("cc@example.com", "CC Person")]; nock("http://test.com") .post("/email", (body: any) => body.cc[0].email === "cc@example.com" && body.cc[0].name === "CC Person") .reply(202, {}, {}); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setText("Some text") .setCc(cc); const result = await emailModule.send(emailParams); expect(result.statusCode).toBe(202); }); it("send email with bcc", async () => { const bcc = [new Recipient("bcc@example.com", "BCC Person")]; nock("http://test.com") .post("/email", (body: any) => body.bcc[0].email === "bcc@example.com" && body.bcc[0].name === "BCC Person") .reply(202, {}, {}); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setText("Some text") .setBcc(bcc); const result = await emailModule.send(emailParams); expect(result.statusCode).toBe(202); }); it("send email with reply_to", async () => { nock("http://test.com") .post("/email", (body: any) => body.reply_to.email === "reply@example.com" && body.reply_to.name === "Reply Person") .reply(202, {}, {}); const emailParams = new EmailParams() .setFrom({ email: "some@email.com" }) .setTo([new Recipient("some_recipient@mail.com")]) .setSubject("Some subject") .setText("Some text") .setReplyTo(new Recipient("reply@example.com", "Reply Person")); const result = await emailModule.send(emailParams); expect(result.statusCode).toBe(202); }); it("send email with in_reply_to", async () => { nock("http://test.com") .post("/email", (body: any) => body.in_reply_to === "Hello {{name}}
" }; it("list", async () => { const params = { domain_id: "domain_id", page: 1, limit: 10 }; nock("http://test.com").get("/templates").query(params).reply(200, { key1: "template_list" }, { header1: "test" }); const result = await templateModule.list(params); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "template_list" }); expect(result.statusCode).toBe(200); }); it("list with no arguments", async () => { nock("http://test.com").get("/templates").reply(200, { key1: "template_list_all" }, { header1: "test" }); const result = await templateModule.list(); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "template_list_all" }); expect(result.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/templates/test_template_id").reply(200, { key1: "template_value" }, { header1: "test" }); const result = await templateModule.single("test_template_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "template_value" }); expect(result.statusCode).toBe(200); }); it("create", async () => { nock("http://test.com") .post("/templates", { name: "Test Template", text: "Hello {{name}}", html: "Hello {{name}}
" }) .reply(201, { key1: "template_created" }, { header1: "test" }); const result = await templateModule.create(templateParams); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "template_created" }); expect(result.statusCode).toBe(201); }); it("create with optional fields", async () => { const params = { name: "Test Template", text: "Hello {{name}}", html: "Hello {{name}}
", categories: ["cat1", "cat2"], domain_id: "domain_id", tags: ["tag1", "tag2"], auto_generate: true, }; nock("http://test.com") .post("/templates", { name: "Test Template", text: "Hello {{name}}", html: "Hello {{name}}
", categories: ["cat1", "cat2"], domain_id: "domain_id", tags: ["tag1", "tag2"], auto_generate: true, }) .reply(201, { key1: "template_created" }, { header1: "test" }); const result = await templateModule.create(params); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "template_created" }); expect(result.statusCode).toBe(201); }); it("update", async () => { nock("http://test.com") .put("/templates/test_template_id", { name: "Updated Template" }) .reply(200, { key1: "template_updated" }, { header1: "test" }); const result = await templateModule.update("test_template_id", { name: "Updated Template" }); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "template_updated" }); expect(result.statusCode).toBe(200); }); it("update with optional fields", async () => { const params = { name: "Updated Template", categories: ["cat1"], domain_id: "domain_id", tags: ["tag1"], text: "Hello {{name}}", html: "Hello {{name}}
", auto_generate: false, }; nock("http://test.com") .put("/templates/test_template_id", { name: "Updated Template", categories: ["cat1"], domain_id: "domain_id", tags: ["tag1"], text: "Hello {{name}}", html: "Hello {{name}}
", auto_generate: false, }) .reply(200, { key1: "template_updated" }, { header1: "test" }); const result = await templateModule.update("test_template_id", params); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "template_updated" }); expect(result.statusCode).toBe(200); }); it("delete", async () => { nock("http://test.com").delete("/templates/test_template_id").reply(200, { key1: "template_deleted" }, { header1: "test" }); const result = await templateModule.delete("test_template_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "template_deleted" }); expect(result.statusCode).toBe(200); }); }); ================================================ FILE: src/__tests__/modules/Token.test.ts ================================================ import nock from "nock"; import { TokenModule } from "../../modules/Token.module"; import { Token, TokenScopeType } from "../../models"; describe("Token Module", () => { const token = new Token("token1", [TokenScopeType.EMAIL_FULL, TokenScopeType.ANALYTICS_FULL], "domain_id_test"); const tokenModule = new TokenModule("test_key", "http://test.com"); it("list", async () => { const params = { page: 1, limit: 10 }; nock("http://test.com").get("/token").query(params).reply(200, { key1: "key1_value" }, { header1: "test" }); const result = await tokenModule.list(params); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "key1_value" }); expect(result.statusCode).toBe(200); }); it("list without params", async () => { nock("http://test.com").get("/token").reply(200, { key1: "key1_value" }, { header1: "test" }); const result = await tokenModule.list(); expect(result.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/token/test_id").reply(200, { key1: "key1_value" }, { header1: "test" }); const result = await tokenModule.single("test_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "key1_value" }); expect(result.statusCode).toBe(200); }); it("create", async () => { nock("http://test.com").post("/token", (body: any) => body.name === "token1" && Array.isArray(body.scopes) && body.scopes[0] === "email_full" && body.domain_id === "domain_id_test").reply(200, { key1: "token1_value" }, { header1: "test" }); const createToken = await tokenModule.create(token); expect(createToken.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(createToken.body).toMatchObject({ key1: "token1_value" }); expect(createToken.statusCode).toBe(200); }); it("update", async () => { nock("http://test.com").put("/token/test_id", (body: any) => body.name === "updated_token").reply(200, { key1: "key1_value" }, { header1: "test" }); const result = await tokenModule.update("test_id", { name: "updated_token" }); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "key1_value" }); expect(result.statusCode).toBe(200); }); it("update with status", async () => { nock("http://test.com") .put("/token/test_id", (body: any) => body.status === "pause") .reply(200, { key1: "key1_value" }, { header1: "test" }); const result = await tokenModule.update("test_id", { status: "pause" }); expect(result.statusCode).toBe(200); }); it("settings", async () => { nock("http://test.com").put("/token/test_id", (body: any) => body.status === "pause").reply(200, { key1: "key1_value" }, { header1: "test" }); const updateSettings = await tokenModule.updateSettings("test_id", { status: "pause" }); expect(updateSettings.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(updateSettings.body).toMatchObject({ key1: "key1_value" }); expect(updateSettings.statusCode).toBe(200); }); it("settings with name", async () => { nock("http://test.com") .put("/token/test_id", (body: any) => body.name === "renamed_token") .reply(200, { key1: "key1_value" }, { header1: "test" }); const result = await tokenModule.updateSettings("test_id", { name: "renamed_token" }); expect(result.statusCode).toBe(200); }); it("delete", async () => { nock("http://test.com").delete("/token/test_id").reply(200, { key1: "key1_value" }, { header1: "test" }); const deleteDomain = await tokenModule.delete("test_id"); expect(deleteDomain.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(deleteDomain.body).toMatchObject({ key1: "key1_value" }); expect(deleteDomain.statusCode).toBe(200); }); }); ================================================ FILE: src/__tests__/modules/User.test.ts ================================================ import nock from "nock"; import { UserModule } from "../../modules/User.module"; import { UserRole, UserPermission } from "../../models"; describe("User Module", () => { const userModule = new UserModule("test_key", "http://test.com"); it("list", async () => { const params = { page: 1, limit: 10 }; nock("http://test.com").get("/users").query(params).reply(200, { key1: "user_list" }, { header1: "test" }); const result = await userModule.list(params); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "user_list" }); expect(result.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/users/test_user_id").reply(200, { key1: "user_value" }, { header1: "test" }); const result = await userModule.single("test_user_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "user_value" }); expect(result.statusCode).toBe(200); }); it("create", async () => { const data = { email: "user@example.com", role: "admin" }; nock("http://test.com").post("/users", (body: any) => body.email === "user@example.com" && body.role === "admin").reply(201, { key1: "user_created" }, { header1: "test" }); const result = await userModule.create(data); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "user_created" }); expect(result.statusCode).toBe(201); }); it("create with all fields", async () => { nock("http://test.com") .post("/users", (body: any) => body.email === "user@example.com" && body.role === "Custom User" && Array.isArray(body.permissions) && body.permissions[0] === "read-activity" && Array.isArray(body.templates) && Array.isArray(body.domains) && body.requires_periodic_password_change === true ) .reply(201, { key1: "user_created" }, { header1: "test" }); const result = await userModule.create({ email: "user@example.com", role: UserRole.CustomUser, permissions: [UserPermission.ReadActivity, UserPermission.ReadEmail], templates: ["tmpl_123"], domains: ["domain_123"], requires_periodic_password_change: true, }); expect(result.statusCode).toBe(201); }); it("update", async () => { const data = { role: "manager" }; nock("http://test.com").put("/users/test_user_id", (body: any) => body.role === "manager").reply(200, { key1: "user_updated" }, { header1: "test" }); const result = await userModule.update("test_user_id", data); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "user_updated" }); expect(result.statusCode).toBe(200); }); it("update with permissions and domains", async () => { nock("http://test.com") .put("/users/test_user_id", (body: any) => body.role === "Custom User" && Array.isArray(body.permissions) && Array.isArray(body.domains) && body.requires_periodic_password_change === false ) .reply(200, { key1: "user_updated" }, { header1: "test" }); const result = await userModule.update("test_user_id", { role: UserRole.CustomUser, permissions: [UserPermission.ManageDomain], domains: ["domain_123"], requires_periodic_password_change: false, }); expect(result.statusCode).toBe(200); }); it("delete", async () => { nock("http://test.com").delete("/users/test_user_id").reply(204, {}, { header1: "test" }); const result = await userModule.delete("test_user_id"); expect(result.statusCode).toBe(204); }); it("listInvites", async () => { const params = { page: 1, limit: 10 }; nock("http://test.com").get("/invites").query(params).reply(200, { key1: "invite_list" }, { header1: "test" }); const result = await userModule.listInvites(params); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "invite_list" }); expect(result.statusCode).toBe(200); }); it("singleInvite", async () => { nock("http://test.com").get("/invites/test_invite_id").reply(200, { key1: "invite_value" }, { header1: "test" }); const result = await userModule.singleInvite("test_invite_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "invite_value" }); expect(result.statusCode).toBe(200); }); it("resendInvite", async () => { nock("http://test.com").post("/invites/test_invite_id/resend").reply(200, { key1: "invite_resent" }, { header1: "test" }); const result = await userModule.resendInvite("test_invite_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "invite_resent" }); expect(result.statusCode).toBe(200); }); it("deleteInvite", async () => { nock("http://test.com").delete("/invites/test_invite_id").reply(204, {}, { header1: "test" }); const result = await userModule.deleteInvite("test_invite_id"); expect(result.statusCode).toBe(204); }); }); ================================================ FILE: src/__tests__/modules/Webhook.test.ts ================================================ import nock from "nock"; import { EmailWebhookModule } from "../../modules/email/Webhook.module"; import { EmailWebhook, EmailWebhookEventType } from "../../models"; describe("Email Webhook Module", () => { const webhookModule = new EmailWebhookModule("test_key", "http://test.com"); const webhook = new EmailWebhook({ url: "https://example.com/webhook", name: "Test Webhook", events: [EmailWebhookEventType.SENT, EmailWebhookEventType.DELIVERED], domain_id: "test_domain_id", }); it("create sends POST to /webhooks with required fields", async () => { nock("http://test.com") .post("/webhooks", { url: "https://example.com/webhook", name: "Test Webhook", events: [EmailWebhookEventType.SENT, EmailWebhookEventType.DELIVERED], domain_id: "test_domain_id", }) .reply(201, { key1: "webhook_created" }, { header1: "test" }); const result = await webhookModule.create(webhook); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "webhook_created" }); expect(result.statusCode).toBe(201); }); it("create with enabled field", async () => { const webhookWithEnabled = new EmailWebhook({ url: "https://example.com/webhook", name: "Test Webhook", events: [EmailWebhookEventType.SENT], domain_id: "test_domain_id", enabled: false, }); nock("http://test.com") .post("/webhooks", (body) => body.enabled === false) .reply(201, { key1: "webhook_created" }, {}); const result = await webhookModule.create(webhookWithEnabled); expect(result.statusCode).toBe(201); }); it("create with version field", async () => { const webhookWithVersion = new EmailWebhook({ url: "https://example.com/webhook", name: "Test Webhook", events: [EmailWebhookEventType.SENT], domain_id: "test_domain_id", version: 2, }); nock("http://test.com") .post("/webhooks", (body) => body.version === 2) .reply(201, { key1: "webhook_created" }, {}); const result = await webhookModule.create(webhookWithVersion); expect(result.statusCode).toBe(201); }); it("create with editable field", async () => { const webhookWithEditable = new EmailWebhook({ url: "https://example.com/webhook", name: "Test Webhook", events: [EmailWebhookEventType.SENT], domain_id: "test_domain_id", editable: true, }); nock("http://test.com") .post("/webhooks", (body) => body.editable === true) .reply(201, { key1: "webhook_created" }, {}); const result = await webhookModule.create(webhookWithEditable); expect(result.statusCode).toBe(201); }); it("list sends GET to /webhooks with domain_id and limit", async () => { nock("http://test.com") .get("/webhooks") .query({ domain_id: "test_domain_id", limit: 10 }) .reply(200, { key1: "webhook_list" }, { header1: "test" }); const result = await webhookModule.list("test_domain_id", { limit: 10 }); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "webhook_list" }); expect(result.statusCode).toBe(200); }); it("list sends GET to /webhooks with page query param", async () => { nock("http://test.com") .get("/webhooks") .query({ domain_id: "test_domain_id", page: 2 }) .reply(200, { key1: "webhook_list" }, {}); const result = await webhookModule.list("test_domain_id", { page: 2 }); expect(result.statusCode).toBe(200); }); it("single", async () => { nock("http://test.com").get("/webhooks/test_webhook_id").reply(200, { key1: "webhook_value" }, { header1: "test" }); const result = await webhookModule.single("test_webhook_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "webhook_value" }); expect(result.statusCode).toBe(200); }); it("update sends PUT to /webhooks/{id} with body fields", async () => { nock("http://test.com") .put("/webhooks/test_webhook_id", { name: "Updated Webhook", enabled: false }) .reply(200, { key1: "webhook_updated" }, { header1: "test" }); const result = await webhookModule.update("test_webhook_id", { name: "Updated Webhook", enabled: false }); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "webhook_updated" }); expect(result.statusCode).toBe(200); }); it("update with url field", async () => { nock("http://test.com") .put("/webhooks/test_webhook_id", (body) => body.url === "https://example.com/new-hook") .reply(200, { key1: "webhook_updated" }, {}); const result = await webhookModule.update("test_webhook_id", { url: "https://example.com/new-hook" }); expect(result.statusCode).toBe(200); }); it("update with events field", async () => { nock("http://test.com") .put("/webhooks/test_webhook_id", (body) => Array.isArray(body.events) && body.events.includes(EmailWebhookEventType.CLICKED)) .reply(200, { key1: "webhook_updated" }, {}); const result = await webhookModule.update("test_webhook_id", { events: [EmailWebhookEventType.CLICKED] }); expect(result.statusCode).toBe(200); }); it("update with version field", async () => { nock("http://test.com") .put("/webhooks/test_webhook_id", (body) => body.version === 2) .reply(200, { key1: "webhook_updated" }, {}); const result = await webhookModule.update("test_webhook_id", { version: 2 }); expect(result.statusCode).toBe(200); }); it("delete", async () => { nock("http://test.com").delete("/webhooks/test_webhook_id").reply(200, { key1: "webhook_deleted" }, { header1: "test" }); const result = await webhookModule.delete("test_webhook_id"); expect(result.headers).toMatchObject({ header1: "test", "content-type": "application/json" }); expect(result.body).toMatchObject({ key1: "webhook_deleted" }); expect(result.statusCode).toBe(200); }); }); ================================================ FILE: src/__tests__/services/mailersend.utils.test.ts ================================================ import { MailerSendUtils } from "../../services/mailersend.utils"; describe("utils", () => { it("webhook check", async () => { const body = Buffer.from( '{"type":"activity.sent","domain_id":"test_domain","created_at":"2022-09-08T20:06:12.062074Z","webhook_id":"webhook_test","url":"https:\\/\\/webhook.site\\/test","data":{"object":"activity","id":"631a6250bd4f6bd6844a2307","type":"sent","created_at":"2022-09-08T20:06:12.051000Z","email":{"object":"email","id":"631a6250bd4f6bd6844a2307","created_at":"2022-09-08T20:06:11.887000Z","from":"donotreply@mailsender.com","subject":"Test Message","status":"sent","tags":null,"message":{"object":"message","id":"631a6250bd4f6bd6844a2307","created_at":"2022-09-08T20:06:11.399000Z"},"recipient":{"object":"recipient","id":"631a6250bd4f6bd6844a2307","email":"test@test.com","created_at":"2022-03-31T21:31:37.304000Z"}},"morph":null,"template_id":""}}', ); const secret = "yXdTVu1YewsKiuN2bcILlFHsljmR9kaU"; const signature = "445e75aab3d8ea9169d134189a2814f06858977bd9cdc69324264e39f47bda2e"; const isLegit = MailerSendUtils.verifyWebHook(body, signature, secret); expect(isLegit).toBeTruthy(); }); it("no body", async () => { try { MailerSendUtils.verifyWebHook(undefined as any, "test", "test"); } catch (e: any) { expect(e?.message).toBe("No raw body provided"); } }); it("no signature", async () => { try { MailerSendUtils.verifyWebHook(Buffer.from("test"), undefined as any, "test"); } catch (e: any) { expect(e?.message).toBe("No signature provided"); } }); it("no secret", async () => { try { MailerSendUtils.verifyWebHook(Buffer.from("test"), "test", undefined as any); } catch (e: any) { expect(e?.message).toBe("No secret provided"); } }); }); ================================================ FILE: src/__tests__/services/request.test.ts ================================================ import nock from "nock"; import { TokenModule } from "../../modules/Token.module"; import { Token, TokenScopeType } from "../../models"; describe("Request service test", () => { const token = new Token("token1", [TokenScopeType.EMAIL_FULL, TokenScopeType.ANALYTICS_FULL], "domain_id_test"); const tokenModule = new TokenModule("test_key", "http://test.com"); it("exception", async () => { nock("http://test.com").post("/token").reply(500, { key1: "test_exception" }, { header1: "test_exp" }); try { await tokenModule.create(token); expect(true).toBeFalsy(); } catch (e) { const exception = e as any; expect(exception.headers).toMatchObject({ header1: "test_exp", "content-type": "application/json" }); expect(exception.body).toMatchObject({ key1: "test_exception" }); expect(exception.statusCode).toBe(500); } }); }); ================================================ FILE: src/index.ts ================================================ export * from "./modules/MailerSend.module"; export * from "./models"; ================================================ FILE: src/models/BlocklistMonitor.ts ================================================ import { Pagination } from "./Pagination"; export interface BlocklistMonitorQueryParams extends Pagination { query?: string; sort_by?: 'name' | 'address' | 'created_at' | 'updated_at' | 'blocklisted'; order?: 'asc' | 'desc'; } export class BlocklistMonitor { address: string; name?: string; notify?: boolean; notify_email?: string; notify_address?: string; constructor(address: string) { this.address = address; } setAddress(address: string): BlocklistMonitor { this.address = address; return this; } setName(name: string): BlocklistMonitor { this.name = name; return this; } setNotify(notify: boolean): BlocklistMonitor { this.notify = notify; return this; } setNotifyEmail(notifyEmail: string): BlocklistMonitor { this.notify_email = notifyEmail; return this; } setNotifyAddress(notifyAddress: string): BlocklistMonitor { this.notify_address = notifyAddress; return this; } } export interface BlocklistMonitorUpdate { name?: string; notify?: boolean; notify_email?: string; notify_address?: string; } ================================================ FILE: src/models/EmailVerification.ts ================================================ import { Pagination } from "./Pagination"; export interface EmailVerificationQueryParams extends Pagination {} export interface EmailVerificationSingleQueryParams { detailed?: boolean; page?: number; limit?: number; } export interface EmailVerificationResultQueryParams extends Pagination { results?: EmailVerificationResultType[]; } export class EmailVerification { name: string; emails: string[]; list_id?: string; verify?: boolean; constructor( name: string, emails: string[], ) { this.name = name; this.emails = emails; } setName(name: string): EmailVerification { this.name = name; return this; } setEmails(emails: string[]): EmailVerification { this.emails = emails; return this; } setListId(listId: string): EmailVerification { this.list_id = listId; return this; } setVerify(verify: boolean): EmailVerification { this.verify = verify; return this; } } export enum EmailVerificationResultType { VALID = 'valid', CATCH_ALL = 'catch_all', MAILBOX_FULL = 'mailbox_full', ROLE_BASED = 'role_based', UNKNOWN = 'unknown', SYNTAX_ERROR = 'syntax_error', TYPO = 'typo', MAILBOX_NOT_FOUND = 'mailbox_not_found', DISPOSABLE = 'disposable', MAILBOX_BLOCKED = 'mailbox_blocked', FAILED = 'failed', } ================================================ FILE: src/models/Pagination.ts ================================================ export interface Pagination { page?: number; limit?: number; } ================================================ FILE: src/models/Token.ts ================================================ export class Token { name: string; domain_id?: string; scopes: TokenScopeType[]; constructor(name: string, scopes: TokenScopeType[], domainId?: string) { this.name = name; this.scopes = scopes; this.domain_id = domainId; } setName(name: string): Token { this.name = name; return this } setDomainId(domainId: string): Token { this.domain_id = domainId; return this } setScopes(scopes: TokenScopeType[]): Token { this.scopes = scopes; return this } } export enum TokenScopeType { EMAIL_FULL = "email_full", DOMAINS_FULL = "domains_full", ACTIVITY_READ = "activity_read", ACTIVITY_FULL = "activity_full", ANALYTICS_READ = "analytics_read", ANALYTICS_FULL = "analytics_full", TOKENS_FULL = "tokens_full", WEBHOOKS_FULL = "webhooks_full", TEMPLATES_FULL = "templates_full", SUPPRESSIONS_READ = 'suppressions_read', SUPPRESSIONS_FULL = 'suppressions_full', SMS_READ = 'sms_read', SMS_FULL = 'sms_full', EMAIL_VERIFICATION_READ = 'email_verification_read', EMAIL_VERIFICATION_FULL = 'email_verification_full', INBOUNDS_FULL = 'inbounds_full', RECIPIENTS_READ = 'recipients_read', RECIPIENTS_FULL = 'recipients_full', DOMAINS_READ = "domains_read", SENDER_IDENTITY_READ = "sender_identity_read", SENDER_IDENTITY_FULL = "sender_identity_full", USERS_READ = "users_read", USERS_FULL = "users_full", SMTP_USERS_READ = "smtp_users_read", SMTP_USERS_FULL = "smtp_users_full", DMARC_MONITORING_READ = "dmarc_monitoring_read", DMARC_MONITORING_FULL = "dmarc_monitoring_full", BLOCKLIST_MONITORING_READ = "blocklist_monitoring_read", BLOCKLIST_MONITORING_FULL = "blocklist_monitoring_full", WHATSAPP_FULL = "whatsapp_full", IFTTT = "ifttt", } export interface TokenUpdates { name?: string; status?: "pause" | "unpause"; } ================================================ FILE: src/models/User.ts ================================================ import { Pagination } from "./Pagination"; export interface UserQueryParams extends Pagination {} export interface UserCreate { email: string; role: UserRole | string; permissions?: UserPermission[] | string[]; templates?: string[]; domains?: string[]; requires_periodic_password_change?: boolean; } export interface UserUpdate { role?: UserRole | string; permissions?: UserPermission[] | string[]; templates?: string[]; domains?: string[]; requires_periodic_password_change?: boolean; } export interface InviteQueryParams extends Pagination {} export enum UserRole { Admin = 'Admin', Manager = 'Manager', Designer = 'Designer', Accountant = 'Accountant', CustomUser = 'Custom User', } export enum UserPermission { ReadAllTemplates = 'read-all-templates', ReadOwnTemplates = 'read-own-templates', ManageTemplates = 'manage-template', ReadFilemanager = 'read-filemanager', ManageDomain = 'manage-domain', ManageInbound = 'manage-inbound', ManageWebhook = 'manage-webhook', ControlSendings = 'control-sendings', ControlTrackingOptions = 'control-tracking-options', AccessSmtpCredentials = 'access-smtp-credentials', ViewSmtpUsers = 'view-smtp-users', ManageSmtpUsers = 'manage-smtp-users', ReadRecipient = 'read-recipient', ReadActivity = 'read-activity', ReadEmail = 'read-email', ReadAnalytics = 'read-analytics', ReadSenderIdentities = 'read-sender-identities', ManageSenderIdentities = 'manage-sender-identities', ReadEmailVerification = 'read-email-verification', ManageEmailVerification = 'manage-email-verification', ManageSms = 'manage-sms', ReadSms = 'read-sms', ManageVerifiedRecipients = 'manage-verified-recipients', ViewSmsWebhooks = 'view-sms-webhooks', ManageSmsWebhooks = 'manage-sms-webhooks', ViewSmsInbound = 'view-sms-inbound', ManageSmsInbound = 'manage-sms-inbound', UpdatePlan = 'update-plan', ManageAccount = 'manage-account', ReadInvoice = 'read-invoice', ManageApiToken = 'manage-api-token', ReadSuppressions = 'read-suppressions', ManageSuppressions = 'manage-suppressions', ReadIpAddresses = 'read-ip-addresses', ManageIpAddresses = 'manage-ip-addresses', ReadErrorLog = 'read-error-log', } ================================================ FILE: src/models/email/Activity.ts ================================================ import { Pagination } from "../Pagination"; export interface ActivityQueryParams extends Pagination { date_from: number | string; date_to: number | string; event?: ActivityEventType[]; } export enum ActivityEventType { QUEUED = "queued", SENT = "sent", DELIVERED = "delivered", SOFT_BOUNCED = "soft_bounced", HARD_BOUNCED = "hard_bounced", OPENED = "opened", OPENED_UNIQUE = "opened_unique", CLICKED = "clicked", CLICKED_UNIQUE = "clicked_unique", UNSUBSCRIBED = "unsubscribed", SPAM_COMPLAINTS = "spam_complaints", SURVEY_OPENED = "survey_opened", SURVEY_SUBMITTED = "survey_submitted", DEFERRED = "deferred", } ================================================ FILE: src/models/email/Analytics.ts ================================================ import { ActivityEventType } from "./Activity"; export interface AnalyticsOpensQueryParams { date_from: number; date_to: number; recipient_id?: string[]; tags?: string[]; domain_id?: string; } export interface AnalyticsDateQueryParams extends AnalyticsOpensQueryParams { group_by?: AnalyticsGroupByType; event?: ActivityEventType[]; } export enum AnalyticsGroupByType { DAYS = "days", WEEKS = "weeks", MONTHS = "months", YEARS = "years" } ================================================ FILE: src/models/email/Attachment.ts ================================================ export class Attachment { content: string; filename: string; disposition: 'inline' | 'attachment'; id?: string; constructor(content: string, fileName: string, disposition: 'inline' | 'attachment' = "attachment", id?: string) { this.content = content; this.filename = fileName; this.disposition = disposition; this.id = id; } } ================================================ FILE: src/models/email/Dmarc.ts ================================================ import { Pagination } from "../Pagination"; export class Dmarc { domain_id: string; constructor(domainId: string) { this.domain_id = domainId; } } export interface DmarcQueryParams extends Pagination { query?: string; sort_by?: 'created_at' | 'updated_at' | 'dmarc_valid' | 'spf_status'; order?: 'asc' | 'desc'; } export interface DmarcReportQueryParams extends Pagination { date_from?: string; date_to?: string; search?: string; category?: string; report_source?: string; } export interface DmarcReportSourcesQueryParams { date_from: string; date_to: string; status?: 'accepted' | 'rejected' | 'quarantined'; } export interface DmarcUpdate { wanted_dmarc_record: string; } ================================================ FILE: src/models/email/Domain.ts ================================================ import { Pagination } from "../Pagination"; export class Domain { name: string; return_path_subdomain?: string; custom_tracking_subdomain?: string; inbound_routing_subdomain?: string; constructor( name: string, returnPathSubdomain?: string, customTrackingSubdomain?: string, inboundRoutingSubdomain?: string, ) { this.name = name; this.return_path_subdomain = returnPathSubdomain; this.custom_tracking_subdomain = customTrackingSubdomain; this.inbound_routing_subdomain = inboundRoutingSubdomain; } } export interface DomainQueryParams extends Pagination { verified?: boolean; } export interface DomainRecipientsQueryParams extends Pagination {} export interface DomainSettings { send_paused?: boolean; track_clicks?: boolean; track_opens?: boolean; track_unsubscribe?: boolean; track_unsubscribe_html?: string; track_unsubscribe_plain?: string; track_unsubscribe_html_enabled?: boolean; track_unsubscribe_plain_enabled?: boolean; track_content?: boolean; custom_tracking_enabled?: boolean; custom_tracking_subdomain?: string; precedence_bulk?: boolean; ignore_duplicated_recipients?: boolean; } ================================================ FILE: src/models/email/EmailParams.ts ================================================ import { Recipient } from "./Recipient"; import { Sender } from "./Sender"; import { Attachment } from "./Attachment"; import { Personalization } from "../../modules/Email.module"; export class EmailParams { from?: Sender; to: Recipient[]; cc?: Recipient[]; bcc?: Recipient[]; rcpt_to?: Recipient[]; reply_to?: Recipient; subject?: string; text?: string; html?: string; send_at?: number | string; attachments?: Attachment[]; template_id?: string; in_reply_to?: string; references?: string[]; tags?: string[]; personalization?: Personalization[]; headers?: EmailHeader[]; settings?: EmailSettings; precedence_bulk?: boolean; list_unsubscribe?: string; constructor(config?: any) { this.from = config?.from; this.to = config?.to; this.cc = config?.cc; this.bcc = config?.bcc; this.rcpt_to = config?.rcptTo; this.reply_to = config?.replyTo; this.in_reply_to = config?.inReplyTo; this.subject = config?.subject; this.text = config?.text; this.html = config?.html; this.send_at = config?.sendAt; this.attachments = config?.attachments; this.template_id = config?.templateId; this.tags = config?.tags; this.personalization = config?.personalization; this.references = config?.references; this.headers = config?.headers; this.settings = config?.settings; this.precedence_bulk = config?.precedenceBulk; this.list_unsubscribe = config?.listUnsubscribe; } setFrom(from: Sender): EmailParams { this.from = from; return this; } setTo(to: Recipient[]): EmailParams { this.to = to; return this; } setCc(cc: Recipient[]): EmailParams { this.cc = cc; return this; } setBcc(bcc: Recipient[]): EmailParams { this.bcc = bcc; return this; } setRcptTo(rcptTo: Recipient[]): EmailParams { this.rcpt_to = rcptTo; return this; } setReplyTo(replyTo: Recipient): EmailParams { this.reply_to = replyTo; return this; } setInReplyTo(inReplyTo: string): EmailParams { this.in_reply_to = inReplyTo; return this; } setSubject(subject: string): EmailParams { this.subject = subject; return this; } setText(text: string): EmailParams { this.text = text; return this; } setHtml(html: string): EmailParams { this.html = html; return this; } setSendAt(sendAt: number | string): EmailParams { this.send_at = sendAt; return this; } setAttachments(attachments: Attachment[]): EmailParams { this.attachments = attachments; return this; } setTemplateId(id: string): EmailParams { this.template_id = id; return this; } setTags(tags: string[]): EmailParams { this.tags = tags; return this; } setPersonalization(personalization: Personalization[]): EmailParams { this.personalization = personalization; return this; } setPrecedenceBulk(precedenceBulk: boolean): EmailParams { this.precedence_bulk = precedenceBulk; return this; } setSettings(settings: EmailSettings): EmailParams { this.settings = settings; return this; } setReferences(references: string[]): EmailParams { this.references = references; return this; } setHeaders(headers: EmailHeader[]): EmailParams { this.headers = headers; return this; } setListUnsubscribe(listUnsubscribe: string): EmailParams { this.list_unsubscribe = listUnsubscribe; return this; } } export interface EmailSettings { track_clicks?: boolean; track_opens?: boolean; track_content?: boolean; } export interface EmailHeader { name: string; value: string; } ================================================ FILE: src/models/email/EmailWebhook.ts ================================================ export class EmailWebhook { url!: string; name!: string; events!: EmailWebhookEventType[]; domain_id!: string; enabled?: boolean; version?: number; editable?: boolean; constructor(config?: IEmailWebhook) { if (config) { this.url = config.url; this.name = config.name; this.events = config.events; this.domain_id = config.domain_id; this.enabled = config.enabled; this.version = config.version; this.editable = config.editable; } } setUrl(url: string): EmailWebhook { this.url = url; return this; } setName(name: string): EmailWebhook { this.name = name; return this; } setEvents(events: any[]): EmailWebhook { this.events = events; return this; } /** * Set domain id * @param domainId - Existing hashed domain ID. */ setDomainId(domainId: string): EmailWebhook { this.domain_id = domainId; return this; } setEnabled(enabled: boolean): EmailWebhook { this.enabled = enabled; return this; } setEditable(editable: boolean): EmailWebhook { this.editable = editable; return this; } setVersion(version: 1 | 2): EmailWebhook { this.version = version; return this; } } export enum EmailWebhookEventType { SENT = "activity.sent", DELIVERED = "activity.delivered", SOFT_BOUNCED = "activity.soft_bounced", HARD_BOUNCED = "activity.hard_bounced", OPENED = "activity.opened", OPENED_UNIQUE = "activity.opened_unique", CLICKED = "activity.clicked", CLICKED_UNIQUE = "activity.clicked_unique", UNSUBSCRIBED = "activity.unsubscribed", SPAM_COMPLAINT = "activity.spam_complaint", SURVEY_OPENED = "activity.survey_opened", SURVEY_SUBMITTED = "activity.survey_submitted", IDENTITY_VERIFIED = "sender_identity.verified", MAINTENANCE_START = "maintenance.start", MAINTENANCE_END = "maintenance.end", DEFERRED = "activity.deferred", INBOUND_FORWARD_FAILED = "inbound_forward.failed", EMAIL_SINGLE_VERIFIED = "email_single.verified", EMAIL_LIST_VERIFIED = "email_list.verified", BULK_EMAIL_COMPLETED = "bulk_email.completed", RECIPIENT_ON_HOLD_ADDED = "recipient.on_hold_added", RECIPIENT_ON_HOLD_REMOVED = "recipient.on_hold_removed", } export interface IEmailWebhook extends IEmailWebhookUpdate { domain_id: string; } export interface IEmailWebhookUpdate { url: string; name: string; events: EmailWebhookEventType[]; enabled?: boolean; version?: number; editable?: boolean; } export interface IEmailWebhookUpdateParams { url?: string; name?: string; events?: EmailWebhookEventType[]; enabled?: boolean; version?: number; editable?: boolean; } ================================================ FILE: src/models/email/Identity.ts ================================================ import { Pagination } from "../Pagination"; export class Identity { domain_id: string; email: string; name?: string; personal_note?: string; reply_to_name?: string; reply_to_email?: string; add_note?: boolean; constructor( domainId: string, email: string, name?: string, personalNote?: string, replyToName?: string, replyToEmail?: string, addNote?: boolean, ) { this.domain_id = domainId; this.email = email; this.name = name; this.personal_note = personalNote; this.reply_to_name = replyToName; this.reply_to_email = replyToEmail; this.add_note = addNote; } setDomainId(domainId: string): Identity { this.domain_id = domainId; return this; } setEmail(email: string): Identity { this.email = email; return this; } setName(name: string): Identity { this.name = name; return this; } setPersonalNote(personalNote: string): Identity { this.personal_note = personalNote; return this; } setReplyToName(replyToName: string): Identity { this.reply_to_name = replyToName; return this; } setReplyToEmail(replyToEmail: string): Identity { this.reply_to_email = replyToEmail; return this; } setAddNote(addNote: boolean): Identity { this.add_note = addNote; return this; } } export interface IdentityQueryParams extends Pagination { domain_id?: string; query?: string; order_by?: 'email' | 'created_at' | 'verified_at'; order?: 'asc' | 'desc'; } export interface IdentityUpdate { name?: string; reply_to_email?: string; reply_to_name?: string; } ================================================ FILE: src/models/email/Inbound.ts ================================================ import { Pagination } from "../Pagination"; export interface InboundQueryParams extends Pagination { domain_id?: string; } export class Inbound { name: string; domain_enabled: boolean; domain_id: string; inbound_domain?: string; inbound_priority?: number; catch_type?: 'all' | 'one'; match_type?: 'all' | 'one'; forwards?: InboundForward[]; match_filter?: MatchFilter; catch_filter?: CatchFilter; constructor( name: string, domainEnabled: boolean, domainId: string, inboundDomain?: string, inboundPriority?: number, forwards?: InboundForward[], matchFilter?: MatchFilter, catchFilter?: CatchFilter, ) { this.name = name; this.domain_enabled = domainEnabled; this.domain_id = domainId; this.inbound_domain = inboundDomain; this.inbound_priority = inboundPriority; this.forwards = forwards; this.match_filter = matchFilter; this.catch_filter = catchFilter; } setDomainId(domainId: string): Inbound { this.domain_id = domainId; return this; } setName(name: string): Inbound { this.name = name; return this; } setDomainEnabled(domainEnabled: boolean): Inbound { this.domain_enabled = domainEnabled; return this; } setInboundDomain(inboundDomain: string): Inbound { this.inbound_domain = inboundDomain; return this; } setInboundPriority(inboundPriority: number): Inbound { this.inbound_priority = inboundPriority; return this; } setForwards(forwards: InboundForward[]): Inbound { this.forwards = forwards; return this; } setMatchFilter(matchFilter: MatchFilter): Inbound { this.match_filter = matchFilter; return this; } setCatchFilter(catchFilter: CatchFilter): Inbound { this.catch_filter = catchFilter; return this; } } export class InboundUpdateParams { name: string; domain_enabled: boolean; inbound_domain?: string; inbound_priority?: number; catch_type?: 'all' | 'one'; match_type?: 'all' | 'one'; forwards?: InboundForward[]; match_filter?: MatchFilter; catch_filter?: CatchFilter; constructor( name: string, domainEnabled: boolean, inboundDomain?: string, inboundPriority?: number, forwards?: InboundForward[], matchFilter?: MatchFilter, catchFilter?: CatchFilter, ) { this.name = name; this.domain_enabled = domainEnabled; this.inbound_domain = inboundDomain; this.inbound_priority = inboundPriority; this.forwards = forwards; this.match_filter = matchFilter; this.catch_filter = catchFilter; } setName(name: string): InboundUpdateParams { this.name = name; return this; } setDomainEnabled(domainEnabled: boolean): InboundUpdateParams { this.domain_enabled = domainEnabled; return this; } setInboundDomain(inboundDomain: string): InboundUpdateParams { this.inbound_domain = inboundDomain; return this; } setInboundPriority(inboundPriority: number): InboundUpdateParams { this.inbound_priority = inboundPriority; return this; } setForwards(forwards: InboundForward[]): InboundUpdateParams { this.forwards = forwards; return this; } setMatchFilter(matchFilter: MatchFilter): InboundUpdateParams { this.match_filter = matchFilter; return this; } setCatchFilter(catchFilter: CatchFilter): InboundUpdateParams { this.catch_filter = catchFilter; return this; } } export interface InboundForward { type: 'webhook' | 'email'; value: string; } export enum InboundFilterType { CATCH_ALL = 'catch_all', CATCH_RECIPIENT = 'catch_recipient', MATCH_ALL = 'match_all', MATCH_SENDER = 'match_sender', MATCH_DOMAIN = 'match_domain', MATCH_HEADER = 'match_header', } export enum ComparerType { EQUAL = 'equal', NOT_EQUAL = 'not-equal', CONTAINS = 'contains', NOT_CONTAINS = 'not-contains', STARTS_WITH = 'starts-with', ENDS_WITH = 'ends-with', NOT_STARTS_WITH = 'not-starts-with', NOT_ENDS_WITH = 'not-ends-with', } export interface InboundFilter { comparer: ComparerType; value: string; } export interface MatchInboundFilter extends InboundFilter { key?: string; } export interface CatchFilter { type: InboundFilterType; filters?: InboundFilter[]; } export interface MatchFilter { type: InboundFilterType; filters?: MatchInboundFilter[]; } ================================================ FILE: src/models/email/Message.ts ================================================ import { Pagination } from "../Pagination"; export interface MessageQueryParams extends Pagination {} ================================================ FILE: src/models/email/Recipient.ts ================================================ import { Sender } from "./Sender"; import { Pagination } from "../Pagination"; export class Recipient extends Sender { constructor(email: string, name?: string) { super(email, name); } } export interface RecipientsQueryParams extends Pagination { domain_id?: string; } export interface BlockListQueryParams extends Pagination { domain_id?: string; } export interface OnHoldListQueryParams extends Pagination { domain_id?: string; } export interface BlockListRecipients { domain_id?: string; recipients?: string[]; patterns?: string[]; } export interface BlockListRecipientsPost { domain_id: string; recipients: string[]; } export enum BlockListType { BLOCK_LIST = 'blocklist', HARD_BOUNCES_LIST = 'hard-bounces', SPAM_COMPLAINTS_LIST = 'spam-complaints', UNSUBSCRIBES_LIST = 'unsubscribes', ON_HOLD_LIST = 'on-hold-list', } ================================================ FILE: src/models/email/Schedule.ts ================================================ import { Pagination } from "../Pagination"; export interface ScheduleQueryParams extends Pagination { domain_id?: string; status?: 'scheduled' | 'sent' | 'error'; } ================================================ FILE: src/models/email/Sender.ts ================================================ export class Sender { email: string; name?: string; constructor(email: string, name?: string) { this.email = email; this.name = name; } } ================================================ FILE: src/models/email/SmtpUser.ts ================================================ import { Pagination } from "../Pagination"; export interface SmtpUserParams { name: string; enabled?: boolean; } export interface SmtpUserQueryParams extends Pagination {} ================================================ FILE: src/models/email/Template.ts ================================================ import { Pagination } from "../Pagination"; export interface TemplateQueryParams extends Pagination { domain_id?: string; } export interface TemplateParams { name?: string; categories?: string[]; domain_id?: string; tags?: string[]; text: string; html: string; auto_generate?: boolean; } export interface TemplateUpdateParams { name?: string; categories?: string[]; domain_id?: string; tags?: string[]; text?: string; html?: string; auto_generate?: boolean; } ================================================ FILE: src/models/index.ts ================================================ export * from "./Token"; export * from "./EmailVerification"; export * from "./Pagination"; export * from "./User"; export * from "./BlocklistMonitor"; //Email Models export * from "./email/Attachment"; export * from "./email/EmailParams"; export * from "./email/EmailWebhook"; export * from "./email/Recipient"; export * from "./email/Sender"; export * from "./email/Activity"; export * from "./email/Analytics"; export * from "./email/Domain"; export * from "./email/SmtpUser"; export * from "./email/Inbound"; export * from "./email/Message"; export * from "./email/Schedule"; export * from "./email/Template"; export * from "./email/Identity"; export * from "./email/Dmarc"; //SMS Models export * from "./sms/Activity"; export * from "./sms/Message"; export * from "./sms/Number"; export * from "./sms/Inbound"; export * from "./sms/SMSParams"; export * from "./sms/SMSPersonalization"; export * from "./sms/Recipient"; export * from "./sms/Webhook"; ================================================ FILE: src/models/sms/Activity.ts ================================================ import { Pagination } from "../Pagination"; export interface SmsActivityQueryParams extends Pagination { date_from?: number; date_to?: number; status?: SmsActivityStatusType[]; sms_number_id?: string; } export enum SmsActivityStatusType { QUEUED = "queued", SENT = "sent", DELIVERED = "delivered", FAILED = "failed", PROCESSED = "processed", } ================================================ FILE: src/models/sms/Inbound.ts ================================================ import { Pagination } from "../Pagination"; export interface SmsInboundQueryParams extends Pagination { sms_number_id?: string; enabled?: boolean; } export class SmsInbound { name: string; enabled?: boolean; sms_number_id?: string; forward_url: string; filter?: SmsInboundFilter; constructor( name: string, smsNumberId: string, forwardUrl: string, enabled?: boolean, filter?: SmsInboundFilter, ) { this.name = name; this.enabled = enabled; this.sms_number_id = smsNumberId; this.forward_url = forwardUrl; this.filter = filter; } setSmsNumberId(smsNumberId: string): SmsInbound { this.sms_number_id = smsNumberId; return this; } setName(name: string): SmsInbound { this.name = name; return this; } setEnabled(enabled: boolean): SmsInbound { this.enabled = enabled; return this; } setForwardUrl(forward_url: string): SmsInbound { this.forward_url = forward_url; return this; } setFilter(filter: SmsInboundFilter): SmsInbound { this.filter = filter; return this; } } export enum SmsComparerType { EQUAL = 'equal', NOT_EQUAL = 'not-equal', CONTAINS = 'contains', NOT_CONTAINS = 'not-contains', STARTS_WITH = 'starts-with', ENDS_WITH = 'ends-with', NOT_STARTS_WITH = 'not-starts-with', NOT_ENDS_WITH = 'not-ends-with', } export interface SmsInboundFilter { comparer: SmsComparerType; value: string; } export interface SmsInboundUpdate { name?: string; enabled?: boolean; sms_number_id?: string; forward_url?: string; filter?: SmsInboundFilter; } ================================================ FILE: src/models/sms/Message.ts ================================================ import { Pagination } from "../Pagination"; export interface SmsMessageQueryParams extends Pagination {} ================================================ FILE: src/models/sms/Number.ts ================================================ import { Pagination } from "../Pagination"; export interface SmsNumberQueryParams extends Pagination { paused?: boolean; } ================================================ FILE: src/models/sms/Recipient.ts ================================================ import { Pagination } from "../Pagination"; export interface SmsRecipientQueryParams extends Pagination { status?: "active" | "opt_out"; sms_number_id?: string; } ================================================ FILE: src/models/sms/SMSParams.ts ================================================ import { SMSPersonalization } from "./SMSPersonalization"; export class SMSParams { from: string; to: string[]; text: string; personalization?: SMSPersonalization[]; constructor(config?: any) { this.from = config?.from; this.to = config?.to; this.text = config?.text; if (config?.personalization?.length) { this.personalization = config?.personalization; } } setFrom(from: string): SMSParams { this.from = from; return this; } setTo(to: string[]): SMSParams { this.to = to; return this; } setText(text: string): SMSParams { this.text = text; return this; } setPersonalization(personalization: SMSPersonalization[]): SMSParams { this.personalization = personalization; return this; } } ================================================ FILE: src/models/sms/SMSPersonalization.ts ================================================ export class SMSPersonalization { phone_number: string; data: { [key: string]: string; }; constructor(phoneNumber: string, data: { [key: string]: string }) { this.phone_number = phoneNumber; this.data = data; } } ================================================ FILE: src/models/sms/Webhook.ts ================================================ export interface SmsWebhookQueryParams { sms_number_id: string; page?: number; limit?: number; } export class SmsWebhook { url: string; name: string; events: SmsWebhookEventType[]; sms_number_id: string; enabled?: boolean; constructor( name: string, url: string, events: SmsWebhookEventType[], smsNumberId: string, enabled?: boolean ) { this.url = url; this.name = name; this.events = events; this.sms_number_id = smsNumberId; this.enabled = enabled; } setUrl(url: string): SmsWebhook { this.url = url; return this; } setName(name: string): SmsWebhook { this.name = name; return this; } setEvents(events: SmsWebhookEventType[]): SmsWebhook { this.events = events; return this; } setSmsNumberId(smsNumberId: string): SmsWebhook { this.sms_number_id = smsNumberId; return this; } setEnabled(enabled: boolean): SmsWebhook { this.enabled = enabled; return this; } } export interface SmsWebhookUpdate { url?: string; name?: string; events?: SmsWebhookEventType[]; enabled?: boolean; } export enum SmsWebhookEventType { SENT = "sms.sent", DELIVERED = "sms.delivered", FAILED = "sms.failed", } ================================================ FILE: src/modules/BlocklistMonitor.module.ts ================================================ import { RequestService, APIResponse } from "../services/request.service"; import { BlocklistMonitor, BlocklistMonitorQueryParams, BlocklistMonitorUpdate } from "../models"; export class BlocklistMonitorModule extends RequestService { constructor(apiKey: string, baseUrl: string) { super(apiKey, baseUrl); } async list(queryParams?: BlocklistMonitorQueryParams): Promise