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

feathers-sendwithus

v0.1.0

Published

Feathers service for sending mailers with sendwithus.com.

Downloads

112

Readme

feathers-sendwithus

Build Status

Feathers service for sending mailers with sendwithus.

STATUS: Under development (used in production since 0.0.4)

Installation

npm install --save feathers-sendwithus

Usage

const sendwithusService = require('feathers-sendwithus');

module.exports = function() {
  const app = this;
  const config = app.get('mailer').sendwithus;
  app.use('/mailers', sendwithusService(config));
};

Client usage:

Data is just passed to the sendwithus api except template which is mapped using the template mapper.

app.service('/mailers').create({
  template: 'friendly-name',
  sender: { address: '[email protected]' },
  recipient: { address: '[email protected]' },
});

Works with batches too:

app.service('/mailers').create([{
  template: 'forgotten-password',
  sender: { address: '[email protected]' },
  recipient: { address: '[email protected]' },
}, {
  template: 'confirmation-email',
  sender: { address: '[email protected]' },
  recipient: { address: '[email protected]' },
}]);

This will use the [`sendwithus` batch api](https://www.sendwithus.com/docs/api#batch-api-requests).
In batch mode (data is an array) the request will always succeed, and return the result of each request.

## Configuration

`apiKey` - Sendwithus api key (Required)

`templateNameMapping` - Will map template names to IDs when doing api calls (default: `true`)

`templateNameCacheExpiry` - Duration before templates are fetched again to be
                            mapped. *Set larger or smaller depending on how
                            often you create new templates or change template names
                            (default 1h (one hour))

`templateMapper` - Custom function which maps templates (default: the built in cached template mapper)
                   e.g.

`batchChunkSize` - default: 10, for the batch api, how many sends to chunk together in a request. Sendwithus [recommend 10](https://www.sendwithus.com/docs/api#batch-api).

## Custom template mapper

`templateMapper` is responsible for mapping given template names (data.template) to template ids that sendwithus understands.
We implement one that fetches all templates and caches it until `templateNameCacheExpiry` time passes.
You can mix ids and names, it will just map the names it finds and leave the rest.

If you want to do your own mapping, say if you want to hard code the template names and ids in a config
to remove the need for fetching you could implement your own mapper:

```javascript
const myMap = { friendly: 'templateId' };

const service = sendwithusService({
  ...
  // @param names {Array} Array of template names passed into service (one for single call, multiple for batch)
  // @returns {Promise} Promise containing ONLY template ids
  templateMapper: names => Promise.resolve(names.map(n => myMap[n] || n)),
});

service.create({
template: 'friendly',
...
}) will send { template: 'templateId' };