UNPKG

pink-bears

Version:

Intelligent rate limiting middleware with MongoDB integration and caching for Node.js applications

33 lines (29 loc) 1.19 kB
const fs = require('fs') const {emitEvent} = require('./errorEmitter'); const {errorConstants} = require('./constants'); const axiosWrapper = require('./AxiosWrapper'); class Email{ constructor(domain, token, userId){ this.domain = domain; this.token = token; this.userId = userId; } async sendEmail(recipients, subject, template, bcc, cc){ try { const AxiosWrapper = new axiosWrapper(this.domain, this.userId); const Axios = AxiosWrapper.getAxiosInstance(); const response = await Axios.post(`${this.domain}/api/send-email`,{ "to": recipients, "subject": subject, "content": template.replace(/"/g, "'"), "bcc": bcc, "cc": cc }, { headers: { "Content-type": "application/json; charset=UTF-8", "auth": this.token } }); return { data: response?.data, status: response?.status }; }catch(error){ console.log("Error occured while making API call", error); await emitEvent(errorConstants.email, error); return { data: error.response?.data || error, status: error.response?.status || error } } } } module.exports = Email;