npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cliam

v2.3.1

Published

Agnostic transactional email sending in Node.js environment

Downloads

716

Readme

Cliam

Github action workflow status Coverage Status CodeFactor GitHub Release GPL Licence

Transactional emails with a kick

Agnostic transactional email sending in Node.js environment :boom: :muscle: :pill:

> Why ?

To improve and facilitate the implementation, flexibility and maintenance of transactional emailing tasks.

> Features

  • Agnostic transactional email sending using web API or SMTP server. One input, one output.
  • Multiple simultaneous transporters.
  • Configuration based, not implementation based : easy switch between different modes.
  • Normalized transactions events.
  • Securized payloads.
  • Customisable default templates.

> Table of contents

  • Node.js >= 18.19.0
  • NPM >= 10.2.3

Install

> npm i cliam --save

Configure

Create a .cliamrc.js module on the root of your project.

> touch .cliamrc.js

Define a minimalist configuration in .cliamrc.js newly created:

require('dotenv').config();

module.exports = {
  "sandbox": true,
  "transporters": [
    {
      "id": "unique-transporter-key",
      "auth": {
        "username": process.env.SMTP_USERNAME,
        "password": process.env.SMTP_PWD
      },
      "options": {
        "host": process.env.SMTP_HOST,
        "port": 587,
        "secure": false
      }
    },
    {
      "id": "other-unique-transporter-key",
      "provider": "sendgrid",
      "auth": {
        "apiKey": process.env.WEB_API_SENDGRID_API_KEY,
      },
      "templates": {
        "user.welcome": "d-321bb40f548e4db8a628b4d6464ebacc",
        ...
      }
    }
  ]
}

:warning: It's strongly advised to use environment secrets to fill in sensible values like api keys. Dotenv is embedded in Cliam, so you can just write an .env file and put Dotenv on the top of your .cliamrc.js.

See cliamrc configuration wiki section for more information about availables options and configurations.

Implement

import { Cliam } from 'cliam';

// Do some stuffs ...
  
const payload = {
  meta: {
    from: { email: '[email protected]' },
    to: [
      { email: '[email protected]' }
    ],
    replyTo: { email: '[email protected]' },
    subject: 'Welcome John'
  }
  content: [
    {
      type: 'text/html',
      value: '<h1>Hello Yoda</h1><p>I use Cliam to send my emails !</p>'
    }
  ]
};

Cliam.mail('user.welcome', payload)
  .then(res => {
    console.log('Email has been delivered: ', res);
  })
  .catch(err => {
    console.log('Error while mail sending: ', err)
  });

By default, Cliam will use the first transporter found in the cliamrc file, except if you precise wich transporterId you want to use on the fly.

See email payload wiki section for more information about availables options and configurations.

:white_check_mark: I have many projects which uses differents providers, it's a hell of a thing to maintain.

This is to be forgotten with Cliam. No more worries about polymorphics inputs / outputs. Whether you are working with an A, B, C, D provider or a smtp server, your input / output will always be the same regardless of your delivery method or service provider.

:white_check_mark: I wish change from supplier, but I'm in panic about the implementation ?

Your implementation does not move, you just have to adapt a configuration file, remove your legacy code and implement some lines of code.

:white_check_mark: I don't have a subscription to a supplier, and no templates

No problem, we have all been poor once. Start with a simple SMTP server and use default templates. When your business is up, you can use a paid web api.

:white_check_mark: I did not have time to prepare the template for an important email that should be send today !

No more, you can fallback easily with a one shot default template.

:white_check_mark: I have a big problem with a provider, and my emails stay blocked in the pipe !

The same: fallback on a SMTP server. In two minutes you're ready and your mailing is back in operation.

AGPL-3.0 License