1.0.1 • Published 5 years ago

freetier v1.0.1

Weekly downloads
1
License
Apache-2.0
Repository
github
Last release
5 years ago

freetier

A JavaScript SDK for free services on the Internet.

This SDK package allows developers to consume only free tier plans from internet service vendors(AWS SES, SendGrid etc.). It will automatically swith to other services when one is exceeding the free tier usage quota.

It's highly recommended that you should switch to the paid plans for more stable and comprehensive services from the vendors once your project/business starts to have decent traffic. And you can still use this SDK as a service integration tool for paid plans.

Sending email

const { sendEmail } = require('freetier');

/** This function will send email using only freetier plans provided by ElasticEmail and SendGrid
 * Make sure you have both ElasticEmail and SendGrid accounts setup and timezone configured before
 * using this function
 */
sendEmail({
  to: 'RECIPIENT_EMAIL',
  from: 'SENDER_EMAIL',
  subject: 'subject',
  message: 'message',
  recipient: 'recipient',
  sender: 'sender',
}, {
    elasticEmail: { apiKey: elasticemailApiKey, dailyLimit: elasticemailDailyLimit },
    sendGrid: { apiKey: sendgridApiKey, dailyLimit: sendgridDailyLimit },
  }).then(data => {
    console.log(data);
  }).catch(err => {
    console.log(err);
  });

You can also use ElasticEmail or SendGrid client directly

const { ElasticEmail, SendGrid } = require('freetier/email');

const ee = new ElasticEmail('API_KEY');

ee.getUsage(from, to).then(data=>{
    ...
}).catch(err=>{
    ...
})

ee.sendEmail(to, from, subject, message, recipient, sender, replyTo).then(data=>{
    ...
}).catch(err=>{
    ...
})



const sg = new SendGrid('API_KEY');

sg.getUsage(from, to).then(data=>{
    ...
}).catch(err=>{
    ...
})

sg.sendEmail(to, from, subject, message, recipient, sender, replyTo).then(data=>{
    ...
}).catch(err=>{
    ...
})
ClassMethodArgumentsReturn
email/elasticemail/ElasticEmailgetUsagefrom: String|Required|YYYY-MM-DDto: String|Required|YYYY-MM-DDPromise
email/elasticemail/ElasticEmailsendEmailto: String|Required|recipient emailfrom: String|Required|Sender emailsubject: String|Required|Email subjectmessage: String|Required|Email content (HTML allowed)recipient: String|Optional|Recipient namesender: String|Optional|Sender namereplyTo: String|Optional|Reply-to emailPromise
email/sendgrid/SendGridgetUsagefrom: String|Required|YYYY-MM-DDto: String|Required|YYYY-MM-DDPromise
email/sendgrid/SendGridsendEmailto: String|Required|recipient emailfrom: String|Required|Sender emailsubject: String|Required|Email subjectmessage: String|Required|Email content (HTML allowed)recipient: String|Optional|Recipient namesender: String|Optional|Sender namereplyTo: String|Optional|Reply-to emailPromise

Integrations with vendors

Make sure you have the correct timezone setting on all vendors' dashboard page, otherwise the auto switch of email providers won't work properly

Unit testing

Make sure you have a .env file with api keys configured.

sendgridApiKey=OBTAIN_THIS_FROM_SENDGRID_DASHBOARD
elasticemailApiKey=OBTAIN_THIS_FROM_ELASTICEMAIL_DASHBOARD