Skip to content

Commit

Permalink
Merge pull request #1 from icapps/feature/mandrill-template-api
Browse files Browse the repository at this point in the history
WIP !!: Feature/mandrill template api
  • Loading branch information
knor-el-snor committed Feb 4, 2019
2 parents cb15504 + a0b4430 commit dd6bb67
Show file tree
Hide file tree
Showing 52 changed files with 8,298 additions and 2 deletions.
Binary file added .DS_Store
Binary file not shown.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MANDRILL_API_KEY=
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Build folder output
build

# Logs
logs
*.log
npm-debug.log*

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

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

# Dependency directories
node_modules

# Editor
.idea
.vscode

# NPM
.npm

# Yarn
.yarnclean
yarn-error.log
.DS_Store

# env files
.env*
47 changes: 47 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Source code and examples
src/
examples

# Logs
logs
*.log
npm-debug.log*

# Editor
.editorconfig
.vscode
.TODO

# Typescript
tsconfig.json

# Linter
tslint.json

# Testing and coverage
test
tests
jest.config.js

# Coverage directory used by tools like istanbul
coverage/

# NPM
.npm
.npmignore
package-lock.json
.nvmrc

# Yarn
.yarnclean
.yarnrc
yarn.lock
yarn-error.log

# Travis
.travis.yml

# Licenses
CODE_OF_CONDUCT.md
CONTRIBUTING.md
HISTORY.md
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry="https://registry.npmjs.org/"
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

language: node_js

node_js:
- "6"
- "8"
- "10"

sudo: false

cache:
directories:
- "node_modules"

script:
- npm run test:coverage

# Send coverage data to Coveralls
after_script: "cat coverage/lcov.info | node_modules/coveralls/bin/coveralls.js"
46 changes: 46 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at development@icapps.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
17 changes: 17 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Contributing

When contributing to this repository, please first discuss the change you wish to make via issue,
email, or any other method with the owners of this repository before making a change.

Please note we have a code of conduct, please follow it in all your interactions with the project.

## Pull Request Process

1. Ensure any install or build dependencies are removed before the end of the layer when doing a
build.
2. Update the README.md with details of changes to the interface, this includes new environment
variables, exposed ports, useful file locations and container parameters.
3. Increase the version numbers in any examples files and the README.md to the new version that this
Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/).
4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you
do not have permission to do that, you may request the second reviewer to merge it for you.
9 changes: 9 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Tree-house Authentication Change Log

All notable changes to this project will be documented in this file.

## [2.0.0] - 2018-03-13

### Added

- All functions fully tested
7 changes: 7 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ISC License (ISC)

Copyright 2018 iCapps

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,31 @@
# tree-house-communication
Provide easy communication to external services
# Treehouse boilerplate

Boilerplate module written in typescript

[![npm version](https://badge.fury.io/js/tree-house-boilerplate.svg)](https://badge.fury.io/js/tree-house-boilerplate)
[![Dependencies](https://david-dm.org/icapps/tree-house-boilerplate.svg)](https://david-dm.org/icapps/tree-house-boilerplate.svg)
[![Build Status](https://travis-ci.org/icapps/tree-house-boilerplate.svg?branch=master)](https://travis-ci.org/icapps/tree-house-boilerplate)
[![Coverage Status](https://coveralls.io/repos/github/icapps/tree-house-boilerplate/badge.svg)](https://coveralls.io/github/icapps/tree-house-boilerplate)

## Usage

```shell
Clone this project
```

```shell
Copy code to new git project, commit and start making your new module
```

## Tests

You can run `npm run test` to run all tests
You can run `npm run test:coverage` to run all tests with coverage report

## Authors

See the list of [contributors](https://github.com/icapps/tree-house-boilerplate/contributors) who participated in this project.

## License

This project is licensed under the ISC License - see the [LICENSE.md](LICENSE.md) file for details
2 changes: 2 additions & 0 deletions build/config/client-config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export declare function getMandrillApiKey(): string;
export declare function setMandrillApiKey(key: string): void;
13 changes: 13 additions & 0 deletions build/config/client-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
let config = {
mandrillApiKey: 'YY5pkBrTRAXKodN-0CL38g',
};
function getMandrillApiKey() {
return config.mandrillApiKey;
}
exports.getMandrillApiKey = getMandrillApiKey;
function setMandrillApiKey(key) {
config.mandrillApiKey = key;
}
exports.setMandrillApiKey = setMandrillApiKey;
2 changes: 2 additions & 0 deletions build/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './config/client-config';
export * from './lib/email.service';
7 changes: 7 additions & 0 deletions build/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./config/client-config"));
__export(require("./lib/email.service"));
2 changes: 2 additions & 0 deletions build/lib/email.service.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { ITemplateRequest } from './goodModels/ITemplateRequest';
export declare function sendEmailWithTemplate(mailInfo: ITemplateRequest): Promise<{}>;
31 changes: 31 additions & 0 deletions build/lib/email.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const mandrill = require("mandrill-api");
const config = require("../config/client-config");
const templateMapper_1 = require("../mapper/templateMapper");
if (config.getMandrillApiKey() === '')
throw new Error('No Mandrill api key provided');
const client = new mandrill.Mandrill(config.getMandrillApiKey(), process.env.LOG_LEVEL === 'debug');
function sendEmailWithTemplate(mailInfo) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
const mailingRequest = templateMapper_1.mapTemplateEmail(mailInfo);
client.messages.sendTemplate(mailingRequest, (result) => {
console.log(result);
resolve(result);
}, (error) => {
console.log(error);
reject(error);
});
});
});
}
exports.sendEmailWithTemplate = sendEmailWithTemplate;
22 changes: 22 additions & 0 deletions build/lib/goodModels/ITemplateRequest.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export interface ITemplateRequest {
templateName: string;
subject: string;
from: {
email: string;
name?: string;
};
to: ITo[];
globalContent: {
name: string;
value: string;
}[];
}
export interface ITo {
email: string;
name?: string;
type?: string;
content?: {
name: string;
value: string;
}[];
}
2 changes: 2 additions & 0 deletions build/lib/goodModels/ITemplateRequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
4 changes: 4 additions & 0 deletions build/lib/models/IMailInfo.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface IMailInfo {
subject: string;
from_email: string;
}
2 changes: 2 additions & 0 deletions build/lib/models/IMailInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
29 changes: 29 additions & 0 deletions build/lib/models/IMandrilTemplateRequest.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export interface IMandrilTemplateRequest {
template_name: string;
template_content: [];
message: {
subject: string;
from_email: string;
to: IRecipient[];
global_merge_vars: IGlobalMergeVars[];
merge_vars: IMergeVars[];
};
tags?: [];
subaccount?: string;
google_analytics_domains?: [];
}
export interface IRecipient {
email: string;
}
interface IGlobalMergeVars {
name: string;
content: string;
}
export interface IMergeVars {
rcpt: string;
vars: {
name: string;
content: string;
}[];
}
export {};
2 changes: 2 additions & 0 deletions build/lib/models/IMandrilTemplateRequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
3 changes: 3 additions & 0 deletions build/mapper/templateMapper.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { ITemplateRequest } from '../lib/goodModels/ITemplateRequest';
import { IMandrilTemplateRequest } from '../lib/models/IMandrilTemplateRequest';
export declare function mapTemplateEmail(mailInfo: ITemplateRequest): IMandrilTemplateRequest;
Loading

0 comments on commit dd6bb67

Please sign in to comment.