Skip to content

Commit

Permalink
Merge pull request #15 from joshferrell/feat/hapi-plugin
Browse files Browse the repository at this point in the history
Feat/hapi plugin
  • Loading branch information
joshferrell committed Nov 29, 2017
2 parents 5b10aa0 + 86ddf39 commit 0ce3600
Show file tree
Hide file tree
Showing 102 changed files with 28,162 additions and 116,204 deletions.
15 changes: 14 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ after_script: "./scripts/greenkeeper-upload.sh"
jobs:
include:
- stage: Spec Tests
script: "./scripts/spec-test-server.sh"
script: "./scripts/spec-test-plugin.sh"
- script: "./scripts/spec-test-widgets.sh"
- stage: Deploy Widgets
script: "./scripts/deploy-widgets.sh"
Expand All @@ -23,6 +23,19 @@ jobs:
on:
branch: master
node: '8'
- stage: Deploy Plugin
script: "./scripts/deploy-plugin.sh"
before_deploy: cd $TRAVIS_BUILD_DIR/plugin
deploy:
provider: npm
email: $NPM_EMAIL
api_key:
secure: $NPM_API_KEY
skip_cleanup: true
on:
branch: master
node: '8'

notifications:
webhooks:
urls:
Expand Down
46 changes: 7 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

An email service that generates html email templates using [mjml](https://mjml.io/), then sends the emails to the requested user.

## Hapi Plugin

The plugin includes a hapi plugin which you can install and use
to send out emails by defining a route and an mjml component.

[Read More](./plugin/README.md)

## Component Library

The project includes a component library that allows users to
Expand All @@ -25,42 +32,3 @@ email templates since most of the data is static. This is to allow companies to
outbound emails to users through one Micro-Service.

[Read More](./server/README.md)

## Future Goals

The goal of the project is to eventually become a Hapi plugin that allows the creation of
email routes in a trivial manner. For instance, eventually you should be able to do this:

```js
import joi from 'joi';

//Simple React component that will be sent to users
const SimpleComponent = ({ firstName }) => (
<mjml-text>
<p>test</p>
<p>{firstName}</p>
<mjml-text>
);

const hapiRoute = {
method: 'POST',
path: '/example',
handler: {
email: {
component: SimpleComponent,
subject: 'Hi I\'m Paul!'
}
},
config: {
validate: {
payload: {
email: joi.string().email().required(),
firstName: joi.string()
}
}
}
};
```

This will create a route that will send an email to the requested user with the first name as
an optional parameter in the payload.
8 changes: 8 additions & 0 deletions plugin/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"sourceMaps": "inline",
"presets": [
"env",
"stage-3",
"react"
]
}
27 changes: 27 additions & 0 deletions plugin/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"env": {
"es6": true,
"node": true,
"jest": true
},
"plugins": ["jest"],
"extends": [
"airbnb",
"plugin:jest/recommended"
],
"parser": "babel-eslint",
"rules": {
"indent": [2, 4],
"react/jsx-indent": [2, 4],
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
"comma-dangle": ["error", "never"],
"jsx-a11y/no-redundant-roles": 2,
"react/jsx-indent-props": [2, 4],
"no-confusing-arrow": ["error", {"allowParens": true}],
"import/no-duplicates": 0,
"import/prefer-default-export": 1,
"linebreak-style": 0,
"no-warning-comments": ["warn"],
"no-underscore-dangle": [2, { "allow": ["__"] }],
}
}
61 changes: 61 additions & 0 deletions plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

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

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

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

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

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

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
*.env

# built babel directory
build
31 changes: 31 additions & 0 deletions plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# ![Hapi Maily](http://i.imgur.com/Ko5GT7a.png?1) Hapi Maily
[![Join the chat at https://gitter.im/hapi-smiles/hapi-maily](https://img.shields.io/gitter/room/nwjs/nw.js.svg?style=flat-square)](https://gitter.im/hapi-smiles/hapi-maily?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Build Status](https://img.shields.io/travis/joshferrell/hapi-maily/master.svg?style=flat-square)](https://travis-ci.org/joshferrell/hapi-maily)
[![Coverage Status](https://img.shields.io/coveralls/joshferrell/hapi-maily/master.svg?style=flat-square)](https://coveralls.io/github/joshferrell/hapi-maily?branch=master)

This is a plugin for sending out emails by defining a custom handler. When the route is hit, an
email is sent to the user in the email attribute of the payload.

## Install

You can add the module to your Hapi Server using npm or yarn
```sh
npm install hapi-maily --save
# or
yarn add hapi-maily
```

## Documentation
### [Options Reference](./docs/options-reference.md)

Read about options for the plugin and route options. Useful if you wish to extend the plugin
beyond the setup used in the [example server](../server).

[Read More](./docs/options-reference.md)

## Quick Start

In your Hapi apps main JavaScript file add the following code to a created Hapi server object.
You will also add the routes for your API as described on the [hapijs documentation](http://hapijs.com).

For an example server see the [example hapi server](../server). To see a simple implementation.
61 changes: 61 additions & 0 deletions plugin/docs/options-reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# 1.0.0 Options Reference

## Plugin Options

### Required
* `transport`: (function) A nodemailer transporter that has been configured
* `fromAddress`: (string) The email address that emails will be sent from.

### Optional
* `env`: (string enum) The current environment that server is running in, valid options below.
* development
* local
* production
* `templateSettings`: (object) Settings that will be passed to all templates, see theme options below.

## Route Options

### Required
* `component`: (function) A React component that uses [mjml](http://mjml.io) for rendering
* `subject`: (string) A email subject that will be sent to the email client.

## Template Settings

All template options are optional. If address, header image, or contact is not passed to the plugin, then props are required for their components.

If a value is set for anything, all values will be overwritten. For instance, if a color template setting is set, secondary, danger, success, etc. will no longer be available unless used in the new value.

If a setting is included, then the nested values will be required if marked as such.

* `colors`: (object) An object that includes a key (e.g. primary) and a hex string (e.g. `'#ECECEC'`).
* `primary`: (string) A primary color to be used, **required**
* `header`: (object) An object that affects the header settings
* `img`: (object) An object that includes image data for headers
* `src`: (string) A url for the image source **required**
* `alt`: (string) An alt tag describing the image **required**
* `address`: (object) An object that has address information for use in address components
* `name`: (string) **required**
* `addressLine1`: (string) **required**
* `addressLine2`: (string) **required**
* `city`: (string) **required**
* `state`: (string) **required**
* `zip`: (string) **required**
* `country` (string) **required**
* `contact` (array[object]) An array of objects with contact information
* `name`: (string) Name describing the contact method
* `value`: (string) Value of what will actually be displayed to user **required**
* `href`: (string) Link for the contact (e.g. `'mailto:noreply@gmail.com'`)
* `type`: (string enum) The type of contact. See below for possible values. **required**
* phone
* email
* website
* fax

### Default Template Settings

* `colors`: An object including possible color types
* `primary`: <span style="display: inline-block; background-color: #9b59b6; width: 15px; height: 15px; margin-right:5px;"></span>#9b59b6
* `secondary`: <span style="display: inline-block; background-color: #95a5a6; width: 15px; height: 15px; margin-right:5px;"></span>#95a5a6
* `danger`: <span style="display: inline-block; background-color: #f64747; width: 15px; height: 15px; margin-right:5px;"></span>#f64747
* `success`: <span style="display: inline-block; background-color: #2ecc71; width: 15px; height: 15px; margin-right:5px;"></span>#2ecc71
* `warning`: <span style="display: inline-block; background-color: #e67e22; width: 15px; height: 15px; margin-right:5px;"></span>#e67e22
44 changes: 44 additions & 0 deletions plugin/lib/email/create-interface.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 73 additions & 0 deletions plugin/lib/email/handle-email.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0ce3600

Please sign in to comment.