Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

campaign

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

campaign - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

src/providers/console.js

18

campaign.js

@@ -5,9 +5,9 @@ 'use strict';

var emailService = require('./src/emailService.js');
var consoleClient = require('./src/client/consoleClient.js');
var mandrillClient = require('./src/client/mandrillClient.js');
var nodemailerClient = require('./src/client/nodemailerClient.js');
var consoleProvider = require('./src/providers/console.js');
var mandrillProvider = require('./src/providers/mandrill.js');
var nodemailerProvider = require('./src/providers/nodemailer.js');
function api (options) {
if (!options.client) {
options.client = mandrillClient(options);
if (!options.provider) {
options.provider = mandrillProvider(options);
}

@@ -22,8 +22,8 @@ if (!options.layout) {

api.defaultLayout = path.join(__dirname, 'templates/layout.mu');
api.clients = {
console: consoleClient,
mandrill: mandrillClient,
nodemailer: nodemailerClient
api.providers = {
console: consoleProvider,
mandrill: mandrillProvider,
nodemailer: nodemailerProvider
};
module.exports = api;

@@ -0,1 +1,5 @@

# 1.1.0 Providing for the family
- Renamed confusing `client` definition as `provider`, which is more accurate.
# 1.0.1 Mailbox

@@ -2,0 +6,0 @@

@@ -14,3 +14,3 @@ {

},
"version": "1.0.1",
"version": "1.1.0",
"licenses": "MIT",

@@ -17,0 +17,0 @@ "keywords": [

@@ -7,3 +7,3 @@ ![campaign.png][9]

It uses [Mustache][6] to fill out the email templates, and [Mandrill][1] to actually send the emails, although providing your own service to actually send the emails is easy.
It uses [Mustache][6] to fill out the email templates, and [Mandrill][1] <sub>_(by default)_</sub> to send the emails, although providing your own [`provider`](#providers) to actually send the emails is easy.

@@ -21,3 +21,3 @@ # Reference

- [Debugging](#debugging)
- [Clients](#clients)
- [Providers](#providers)
- [License](#license)

@@ -41,3 +41,3 @@

<sub>_(the default client needs an API keep for [Mandrill][1], read on)_</sub>
<sub>_(the default provider needs an API key for [Mandrill][1], read on)_</sub>

@@ -53,2 +53,8 @@ Send emails!

# Screenshot
Here is a screenshot of an email sent using this library, as seen on [Pony Foo][3] subscriptions, in production. This email is using the default layout provided by `campaign`.
![sample.png][8]
# Client Options

@@ -65,3 +71,3 @@

"from": "<not provided>",
"client": "<defaults>",
"provider": "<default>",
"trap": false,

@@ -83,3 +89,3 @@ "headerImage": "<not provided>",

At the time they host [the source code][2] in Bit Bucket, which is kind of cryptic, but you can read through it nonetheless.
At the time they host [their API's source code][2] in Bit Bucket, which is kind of weird, but you can read through it nonetheless.

@@ -90,10 +96,8 @@ You need to provide an API key in `apiKey`, and that's all there is to it. You might prefer to _ignore this configuration option_, and merely set `process.env.MANDRILL_APIKEY`. That works, too.

The `from` address for our emails. The `client` is responsible for trying to make it look like that's the send address. Not necessarily used for authentication.
The `from` address for our emails. The `provider` is responsible for trying to make it look like that's the send address. Not necessarily used for authentication.
### `client`
### `provider`
You can actually use other email clients, providing your own. To do so, you need to provide a `client` object. The `client` object should have a `send` function, which takes a `model`, and a `done` callback.
You can use other email providers, [creating your own or choosing one](#providers) that comes with `campaign`. To implement it yourself, you need to create a custom `provider` object. The `provider` object should have a `send` function, which takes a `model`, and a `done` callback. You can [read more about custom providers](#creating-custom-providers) below.
Given that I originally worked with Mandrill, the `client` API is based on [their API client][2]. I'll add details upon request.
### `headerImage`

@@ -152,7 +156,7 @@

If you want to provide the template with images other than the optional header when creating the `campaign` client, you can provide a list of file paths and names (to reference them in your templates), as shown below.
If you want to provide the template with embedded images _(other than the [optional email header](#headerimage) when creating the `campaign` client)_ you can set `images` to a list of file paths and names (to later reference them in your templates), as shown below.
```js
[
{ name: 'housing', file: path.join(__dirname, 'housing.png')}
{ name: 'housing', file: path.join(__dirname, 'housing.png') }
]

@@ -169,9 +173,9 @@ ```

Configuration specifically used by the Mandrill client.
Configuration specifically used by the Mandrill provider.
Mandrill allows you to add dynamic content to your templates, and this feature is supported by the default Mandrill client in `campaign`, out the box. Read more about [merge variables][4].
Mandrill allows you to add dynamic content to your templates, and this feature is supported by the default Mandrill provider in `campaign`, out the box. Read more about [merge variables][4].
##### `mandrill.merge`
Given that Mandrill's `merge` API is **fairly obscure**, we process it in our client, so that you can configure it assigning something like what's below to `mandrill.merge`.
Given that Mandrill's `merge` API is **fairly obscure**, we process it in our provider, so that you can configure it assigning something like what's below to `mandrill.merge`, which is cleaner than what Mandrill expects you to put together.

@@ -233,3 +237,3 @@ ```json

In this case, the `_header` would whether a header image was provided. Then, `generated` contains the moment the email was rendered, using the `'YYYY/MM/DD HH:mm, UTC Z'` format string. Lastly, `trapped` contains the metadata extracted from the model when `trap` is set to `true`, in the [client options](#client-options).
In this case, the `_header` variable would contain whether a header image was provided. Then, `generated` contains the moment the email was rendered, passing the `'YYYY/MM/DD HH:mm, UTC Z'` format string to [`moment`][11]. Lastly, `trapped` contains the metadata extracted from the model when `trap` is set to `true`, in the [client options](#client-options).

@@ -280,11 +284,7 @@ ### Styling the `layout`

That'd be a perfect use for merge variables, which were described above in the [send options](#email-sending-options). Remember, those are just supported by Mandrill, though. They [deal with those][4] after you make a request to their API.
That'd be a perfect use for merge variables, which were described above in the [send options](#email-sending-options). Remember, those are just supported by Mandrill, though. Mandrill [deals with merge variables][4] after you make a request to their API, replacing them with the values assigned to each recipient.
Here is a screenshot of an email sent using this library by the [Pony Foo blog][3], in production.
![sample.png][8]
# Debugging
To help you debug, an alternative `client` is provided. Set it up like this:
To help you debug, an alternative `provider` is available. Set it up like this:

@@ -294,3 +294,3 @@ ```js

var client = campaign({
client: campaign.clients.console()
provider: campaign.providers.console()
});

@@ -303,9 +303,9 @@

# Clients
# Providers
There are a few clients you can use. The default client sends mails through [Mandrill][1]. There is also a `console` logging client, [explained above](#debugging), and a `nodemailer` client, detailed below.
There are a few different providers you can use. The default provider sends mails through [Mandrill][1]. There is also a `console` logging provider, [explained above](#debugging), and a `nodemailer` provider, detailed below.
### Using `nodemailer`
To use with `nodemailer`, simply use that client.
To use with `nodemailer`, simply use that provider.

@@ -324,3 +324,3 @@ ```js

var client = campaign({
client: campaign.clients.nodemailer({
provider: campaign.providers.nodemailer({
transport: smtp,

@@ -339,7 +339,7 @@ transform: function (options) {

### Making your own client
### Creating custom providers
If the existing clients don't satisfy your needs, you may provide your own. The `client` option just needs to be an object with a `send` method. For an example, check out the [`nodemailer` client source code][10].
If the existing providers don't satisfy your needs, you may provide your own. The `provider` option just needs to be an object with a `send` method. For an example, check out the [`nodemailer` provider source code][10].
You can easily write your own email sender, like this.
You can easily write your own `campaign` provider, like this.

@@ -349,3 +349,3 @@ ```js

var client = campaign({
client: {
provider: {
send: function (model, done) {

@@ -360,3 +360,3 @@ // use the data in the model to send your email messages

If you decide to go for your own client, `campaign` will still prove useful thanks to its templating features.
If you decide to go for your own provider, `campaign` will still prove useful thanks to its templating features.

@@ -377,2 +377,3 @@ # License

[9]: http://i.imgur.com/cBFalWm.png
[10]: https://github.com/bevacqua/campaign/blob/master/src/client/nodemailerClient.js
[10]: https://github.com/bevacqua/campaign/blob/master/src/providers/nodemailer.js
[11]: http://momentjs.com

@@ -18,4 +18,4 @@ 'use strict';

function clientSend (next) {
options.client.send(model, next);
function providerSend (next) {
options.provider.send(model, next);
}

@@ -32,3 +32,3 @@

]),
clientSend
providerSend
], done);

@@ -35,0 +35,0 @@ }

@@ -7,3 +7,3 @@ 'use strict';

trap: 'nicolasbevacqua@gmail.com',
client: campaign.clients.console()
provider: campaign.providers.console()
});

@@ -10,0 +10,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc