Skip to content

Commit

Permalink
in the beginning
Browse files Browse the repository at this point in the history
  • Loading branch information
ahdinosaur committed Feb 28, 2016
0 parents commit ea67e37
Show file tree
Hide file tree
Showing 11 changed files with 275 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .babelrc
@@ -0,0 +1,4 @@
{
"plugins": [ "add-module-exports" ],
"presets": [ "es2015" ]
}
13 changes: 13 additions & 0 deletions .editorconfig
@@ -0,0 +1,13 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
31 changes: 31 additions & 0 deletions .gitignore
@@ -0,0 +1,31 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# Commenting this out is preferred by some people, see
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules

# Users Environment Variables
.lock-wscript

# The compiled/babelified modules
lib/
30 changes: 30 additions & 0 deletions .jshintrc
@@ -0,0 +1,30 @@
{
"node": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
"latedef": "nofunc",
"newcap": false,
"noarg": true,
"quotmark": "single",
"regexp": true,
"undef": true,
"unused": true,
"strict": false,
"trailing": true,
"smarttabs": true,
"white": false,
"node": true,
"globals": {
"it": true,
"describe": true,
"before": true,
"beforeEach": true,
"after": true,
"afterEach": true
}
}
8 changes: 8 additions & 0 deletions .npmignore
@@ -0,0 +1,8 @@
.editorconfig
.jshintrc
.travis.yml
.babelrc
.idea/
src/
test/
!lib/
4 changes: 4 additions & 0 deletions .travis.yml
@@ -0,0 +1,4 @@
language: node_js
node_js:
- 'node'
- 'iojs'
22 changes: 22 additions & 0 deletions LICENSE
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 Feathers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

20 changes: 20 additions & 0 deletions README.md
@@ -0,0 +1,20 @@
# feathers-mailer

[![Build Status](https://travis-ci.org/ahdinosaur/feathers-mailer.png?branch=master)](https://travis-ci.org/ahdinosaur/feathers-mailer)

> Feathers mailer service
## About


## Changelog

__0.1.0__

- Initial release

## License

Copyright (c) 2015

Licensed under the [MIT license](LICENSE).
58 changes: 58 additions & 0 deletions package.json
@@ -0,0 +1,58 @@
{
"name": "feathers-mailer",
"description": "Feathers mailer service",
"version": "0.0.0",
"homepage": "https://github.com/ahdinosaur/feathers-mailer",
"main": "lib/",
"keywords": [
"feathers",
"feathers-plugin"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/ahdinosaur/feathers-mailer.git"
},
"author": {
"name": "Feathers contributors",
"email": "hello@feathersjs.com",
"url": "https://feathersjs.com"
},
"contributors": [],
"bugs": {
"url": "https://github.com/ahdinosaur/feathers-mailer/issues"
},
"engines": {
"node": ">= 0.12.0"
},
"scripts": {
"prepublish": "npm run compile",
"publish": "git push origin && git push origin --tags",
"release:patch": "npm version patch && npm publish",
"release:minor": "npm version minor && npm publish",
"release:major": "npm version major && npm publish",
"compile": "rm -rf lib/ && babel -d lib/ src/",
"watch": "babel --watch -d lib/ src/",
"jshint": "jshint src/. test/. --config",
"mocha": "mocha test/ --compilers js:babel-core/register",
"test": "npm run compile && npm run jshint && npm run mocha"
},
"directories": {
"lib": "lib"
},
"dependencies": {
"debug": "^2.2.0",
"nodemailer": "^2.2.1"
},
"devDependencies": {
"address-rfc2822": "^1.0.0",
"babel-cli": "^6.5.1",
"babel-core": "^6.5.2",
"babel-plugin-add-module-exports": "^0.1.2",
"babel-preset-es2015": "^6.5.0",
"feathers": "^2.0.0",
"jshint": "^2.9.1",
"mocha": "^2.4.5",
"nodemailer-stub-transport": "^1.0.0"
}
}
44 changes: 44 additions & 0 deletions src/index.js
@@ -0,0 +1,44 @@
if(!global._babelPolyfill) { require('babel-polyfill'); }

import makeDebug from 'debug';
import Proto from 'uberproto';
import Mailer from 'nodemailer';
//import errors from 'feathers-errors';

const debug = makeDebug('feathers-mailer');

class Service {
constructor (options) {
debug('constructor', options);
if (!options) {
throw new Error('feathers-mailer: constructor `options` must be provided');
}

if (!options.Model) {
throw new Error('feathers-mailer: constructor `options.Model` must be provided');
}

this.Model = Mailer.createTransport(
options.Model,
options.defaults
);
this.id = options.id || 'id';
}

extend (obj) {
return Proto.extend(obj, this);
}

create (body, params, cb) {
debug('create', body, params);
// TODO maybe body should be text/html field
// and params is rest of options
this.Model.sendMail(body, cb);
}
}

export default function init(options) {
return new Service(options);
}

init.Service = Service;
41 changes: 41 additions & 0 deletions test/index.test.js
@@ -0,0 +1,41 @@
import assert from 'assert';
import createMailer from '../src';
import stubTransport from 'nodemailer-stub-transport';
import addressParser from 'address-rfc2822';

describe('feathers-mailer', () => {
it('is CommonJS compatible', () => {
assert.equal(typeof require('../lib'), 'function');
});

it('basic functionality', done => {
assert.equal(typeof createMailer, 'function', 'exports function');
const mailer = createMailer({
Model: stubTransport()
});
let mailData = {
from: '"Alice" <alice@example.com>',
to: ['bob@example.com', '"Carol" <carol@example.com>'],
subject: 'The revolution will not be televised',
text: `
You will not be able to stay home, brother.
You will not be able to plug in, turn on and cop out.
You will not be able to lose yourself on skag and
skip out for beer during commercials,
Because the revolution will not be televised.
`
};
mailer.create(mailData, {}, function (err, info) {
assert.ifError(err);
assert.equal(info.envelope.from, getEmailAddress(mailData.from));
assert.deepEqual(info.envelope.to, mailData.to.map(getEmailAddress));
assert.ok(info.messageId);
assert.ok(info.response.toString());
done();
});
});
});

function getEmailAddress (contact) {
return addressParser.parse(contact)[0].address;
}

0 comments on commit ea67e37

Please sign in to comment.