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

barke

v0.1.0

Published

A simple node library for Embarke, built off SendGrid's node library

Downloads

4

Readme

barke

A simple node library for Embarke, built off SendGrid's node library.

Usage

This library may be used just as SendGrid's Node library, however it further implements Embarke's API options:

var barke = require("barke")("your_embarke_username", "your_embarke_password");
barke.send({
  to:             "[email protected]",
  from:           "[email protected]",
  subject:        "Hello World",
  text:           "My first email through Embarke.",
  embarkeapi:     { 
    sendDate:     new Date(), 
    maxSendHours: 24,
    campaignId:   "My Campaign",
    mailAccount:  "esp-account-username",
    tags:         ["My custom tag1", "My tag 2"]
  }
}, function(err, json) {
  if (err) { return console.error(err); }
  console.log(json);
});

Email

Email helps you more powerfully prepare your message to be sent, it is built off SendGrid's Email Object.

To get started create an Email object where params is a javascript object. You can pass in as much or as little to params as you want.

var barke = require("barke")(api_user, api_key);
var email = new barke.Email(params);

Sample

Here is a sample for using it.

var barke = require("barke")(api_user, api_key);
var email = new barke.Email({
  to:            "[email protected]",
  from:          "[email protected]",
  subject:       "Subject goes here",
  text:          "Hello world",
  embarkeapi: {
    sendDate:     new Date(),
    maxSendHours: 24,
	campaignId:   "My Campaign",
	mailAccount:  "esp-account-username",
	tags:         ["My custom tag1", "My tag 2"]
  }
});
barke.send(email, function(err, json) {
  if (err) { return console.error(err); }
  console.log(json);
});

Available params

var params = {
  smtpapi:  new sengrid.SmtpapiHeaders(),
  embarkeapi: {
    sendDate: (new Date() | ""),
    maxSendHours: null,
    campaignId: "",
    mailAccount: "",
    tags: []
  }
  to:       [],
  toname:   [],
  from:     "",
  fromname: "",
  subject:  "",
  text:     "",
  html:     "",
  bcc:      [],
  replyto:  "",
  date:     new Date(),
  files: [
    {
      filename:     "",           // required only if file.content is used.
      contentType:  "",           // optional
      cid:          "",           // optional, used to specify cid for inline content
      path:         "",           //
      url:          "",           // == One of these three options is required
      content:      ("" | Buffer) //
    }
  ],
  file_data:  {},
  headers:    {}
};

NOTE: anything that is available in the Email constructor is available for use in the barke.send function.

Setting params

You can set params like you would for any standard JavaScript object.

var barke  = require("barke")(api_user, api_key);
var email     = new barke.Email({to: "[email protected]"});
email.to      = "[email protected]";
email.subject = "This is a subject";
email.embarkeapi.maxSendHours = 48;

SendGrid Default Parameters

There are a number of SendGrid default parameters that can be set using a variety of methods provided in the SendGrid Node Library Documentation.

Embarke Specific Parameters

A description of these parameters and their meanings can be found in the Embarke API docs.

setSendDate

You may set the send date a variety of ways.

Setting a send date with no options sets the date to the current time. (This is also the default, if you do nothing.)

var email = new barke.Email(); 
email.setSendDate();
barke.send(email, function(err, json) { });

You can set the send date with a Date object.

var email = new barke.Email(); 
var date = new Date("2011-11-11T11:11:11.111Z");
email.setSendDate(date);
barke.send(email, function(err, json) { });

You can set the send date with a string.

var email = new barke.Email(); 
email.setSendDate("2011-11-11T11:11:11.111Z");
barke.send(email, function(err, json) { });
setMaxSendHours
var email = new barke.Email(); 
email.setMaxSendHours(20);
barke.send(email, function(err, json) { });
setCampaignId
var email = new barke.Email(); 
email.setMaxSendHours("The Coolest Campaign Ever");
barke.send(email, function(err, json) { });
setMailAccount
var email = new barke.Email(); 
email.setMailAccount("my-sendgrid-account");
barke.send(email, function(err, json) { });
addTag

You may add multiple tags using addTag.

var email = new barke.Email(); 
email.addTag("happy");
email.addTag("go");
email.addTag("lucky");
barke.send(email, function(err, json) { });
setTags

You may set the tags using setTags.

var email = new barke.Email(); 
email.setTags(["super", "nifty"]);
barke.send(email, function(err, json) { });

You may also provide a string if you wish.

var email = new barke.Email(); 
email.setTags("awesome");
barke.send(email, function(err, json) { });

Options

All options provided by the options parameter are passed through to sendgrid-nodejs, to learn more about what they do see the options in the library's readme.

Issues

When filing an issue please include your package.json and the output of npm ls barke to help us isolate and reproduce the issue

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Running Tests

The existing tests can be run using Mocha with the following command:

npm test

You can run individual tests with the following command:

./node_modules/.bin/mocha [path to test].js

Future

In the future, it would be great to tear out embarkeapi to create an Embarke header generator, similar to SendGrid's smtpapi generator.

License

Licensed under the MIT License.

Significant portions of this README and library are taken from or inspired by sendgrid-nodejs and smtpapi-nodejs, both are licensed MIT.