UNPKG

mailisk

Version:

Mailisk library for NodeJS

101 lines (99 loc) 3.35 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { MailiskClient: () => MailiskClient }); module.exports = __toCommonJS(src_exports); // src/mailisk.ts var import_axios = __toESM(require("axios")); var import_nodemailer = __toESM(require("nodemailer")); var MailiskClient = class { constructor({ apiKey, baseUrl }) { this.axiosInstance = import_axios.default.create({ headers: { "X-Api-Key": apiKey }, baseURL: baseUrl || "https://api.mailisk.com/" }); } axiosInstance; async listNamespaces() { return (await this.axiosInstance.get("api/namespaces")).data; } async sendVirtualEmail(namespace, params) { const smtpSettings = await this.getSmtpSettings(namespace); const transport = import_nodemailer.default.createTransport({ host: smtpSettings.data.host, port: smtpSettings.data.port, secure: false, auth: { user: smtpSettings.data.username, pass: smtpSettings.data.password } }); const { from, to, subject, text, html } = params; await transport.sendMail({ from, to, subject, text, html }); transport.close(); } async searchInbox(namespace, params, config) { let _params = { ...params }; if (params?.from_timestamp === void 0 || params?.from_timestamp === null) { _params.from_timestamp = Math.floor(new Date().getTime() / 1e3) - 15 * 60; } if (params?.wait !== false) { _params.wait = true; } let _config = { ...config }; if (!config?.maxRedirects) { _config.maxRedirects = 99999; } if (_params.wait && !config?.timeout) { _config.timeout = 1e3 * 60 * 5; } return (await this.axiosInstance.get(`api/emails/${namespace}/inbox`, { ..._config, params: _params })).data; } async getSmtpSettings(namespace) { const result = await this.axiosInstance.get(`api/smtp/${namespace}`); return result.data; } }; __name(MailiskClient, "MailiskClient"); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { MailiskClient }); //# sourceMappingURL=index.js.map