Skip to content

Commit

Permalink
Merge pull request #9 from kbarbounakis/update-dependencies
Browse files Browse the repository at this point in the history
update packages
  • Loading branch information
kbarbounakis authored May 4, 2022
2 parents 32e3828 + 244e26a commit bf7824f
Show file tree
Hide file tree
Showing 15 changed files with 1,579 additions and 529 deletions.
17 changes: 14 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
{
"extends": [
"eslint:recommended",
"plugin:node/recommended"
],
"env": {
"browser": false,
"node": true,
"es6": false,
"es6": true,
"jquery": false
},
"parserOptions": {
"ecmaVersion": 2020
},
"globals": {
"jasmine": false,
"describe": false,
"it": false
"it": false,
"expect": false,
"expectAsync": false,
"beforeAll": false,
"afterAll": false
},
"extends": "eslint:recommended",
"rules": {
"no-console": "warn",
"no-invalid-this": "warn",
Expand Down
9 changes: 9 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,12 @@ test/
.theia
.vscode
.DS_Store

# test
spec
.nycrc
coverage
.nyc_output

# github
.github
6 changes: 6 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"reporter": [ "lcov", "text"],
"include": [
"*.js"
]
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Install with npm

Use `@themost/mailer` to send static html emails:

var mm = require('@themost/mailer');
import {MailHelper} from '@themost/mailer';
// init mail in the current HTTP context
mm.mailer(context).transporter({
new MailHelper(context).transporter({
service:'gmail',
auth:{
user:"user@example.com",
Expand Down Expand Up @@ -66,9 +66,9 @@ Create a file named html.ejs (Note: EJS is the default view engine for every MOS

Finally, send dynamic mail template:

import mailer from '@themost/mailer';
import {MailHelper} from '@themost/mailer';
// init mail in the current HTTP context
mailer.getMailer(context).from('user@example.com')
new MailHelper(context).from('user@example.com')
.to('friend@example.com')
.subject('Hello from user')
.template('my-first-template').send({ name: 'George' }, (err) => {
Expand Down
59 changes: 35 additions & 24 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
/**
* @license
* MOST Web Framework 2.0 Codename Blueshift
* Copyright (c) 2017, THEMOST LP All rights reserved
*
* Use of this source code is governed by an BSD-3-Clause license that can be
* found in the LICENSE file at https://themost.io/license
*/

export declare interface MailerHelper {
context: any;
body(body: string): MailerHelper;
text(text: string): MailerHelper;
subject(subject: string): MailerHelper;
from(sender: string): MailerHelper;
replyTo(reply: string): MailerHelper;
attachments(...attachment:string[]): MailerHelper;
to(recipient: string): MailerHelper;
transporter(opts: any): MailerHelper;
test(value?: boolean): MailerHelper;
cc(...cc: string[]): MailerHelper;
bcc(...bcc: string[]): MailerHelper;
template(template: string): MailerHelper;
send(data: any, callback: (err?: Error, res?: any) => void);
// MOST Web Framework Codename Zero Gravity Copyright (c) 2017-2022, THEMOST LP All rights reserved

import { ConfigurationBase } from "@themost/common";

export interface MailHelperApplication {
getConfiguration(): ConfigurationBase
}

export interface MailHelperTemplateEngine {
render(templatePath: string, data: any, callback: (err?: Error, res?: any) => void): void;
}

export interface MailHelperContext {
application: MailHelperApplication;
engine(extension: string): MailHelperTemplateEngine
}


export declare class MailerHelper {
context: MailHelperContext | any;
constructor(context: MailHelperContext | any);
body(body: string): this;
text(text: string): this;
subject(subject: string): this;
from(sender: string): this;
replyTo(reply: string): this;
attachments(...attachment:string[]): this;
to(recipient: string): this;
transporter(opts: any): this;
test(value?: boolean): this;
cc(...cc: string[]): this;
bcc(...bcc: string[]): this;
template(template: string): this;
send(data: any, callback: (err?: Error, res?: any) => void): void;
sendAsync(data: any): Promise<any>;

}

Expand Down
86 changes: 49 additions & 37 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
/**
* MOST Web Framework
* A JavaScript Web Framework
* http://themost.io
*
* Copyright (c) 2014, Kyriakos Barbounakis k.barbounakis@gmail.com, Anthi Oikonomou anthioikonomou@gmail.com
*
* Released under the BSD3-Clause license
* Date: 2015-09-24
*/
// MOST Web Framework Codename Zero Gravity Copyright (c) 2017-2022, THEMOST LP All rights reserved

var util = require('util');
var path = require('path');
var nodemailer = require('nodemailer');
Expand Down Expand Up @@ -50,7 +42,9 @@ if (typeof Array.prototype.distinct === 'undefined')
Object.defineProperty(Array.prototype, 'distinct', {
value: distinct, configurable: true, enumerable: false, writable: true
});
} catch(e) {}
} catch(e) {
//
}
}
if (!Array.prototype.distinct) { Array.prototype.distinct = distinct; }
}
Expand All @@ -59,12 +53,13 @@ if (typeof Array.prototype.distinct === 'undefined')
* @ignore
* @private
*/
// eslint-disable-next-line no-unused-vars
function argumentsArray(p) {
var arr = [], args = [];
args.push.apply(args, arguments);
args.forEach(function(x) {
//backward compatibility test
if (util.isArray(x)) {
if (Array.isArray(x)) {
arr.push.apply(arr, x);
}
else if (typeof x === 'string') {
Expand Down Expand Up @@ -149,8 +144,8 @@ MailerHelper.prototype.template = function(template) {
*
* @example
*
var mm = require("most-web-mailer");
mm.mailer(context).subject("Good morning")
const {MailHelper} = require("@themost/mailer");
new MailHelper(context).subject("Good morning")
.body("<p style='color:lightblue'>This is an HTML message</p>")
.to("user@example.com")
.send(function(err, res) {
Expand All @@ -177,8 +172,8 @@ MailerHelper.prototype.body = function(body) {
*
* @example
*
var mm = require("most-web-mailer");
mm.mailer(context).subject("Good morning")
const {MailHelper} = require("@themost/mailer");
new MailHelper(context).subject("Good morning")
.text("This is a plain text message.")
.to("user@example.com")
.send(function(err, res) {
Expand Down Expand Up @@ -252,14 +247,15 @@ MailerHelper.prototype.replyTo = function(reply) {
* @returns {MailerHelper}
*
* @example
var mm = require("most-web-mailer");
mm.mailer(context).attachments("/tmp/cv.doc","/tmp/photo.jpeg")
const {MailHelper} = require("@themost/mailer");
new MailHelper(context).attachments("/tmp/cv.doc","/tmp/photo.jpeg")
.subject("New CV")
.body("I am sending you my new CV. Best Regards.")
.send(function(err, res) {
return done(err);
});
*/
// eslint-disable-next-line no-unused-vars
MailerHelper.prototype.attachments = function(p) {
var self = this;
var arr = argumentsArray.apply(this, arguments);
Expand All @@ -285,14 +281,15 @@ MailerHelper.prototype.attachments = function(p) {
*
* @example
*
var mm = require("most-web-mailer");
mm.mailer(context).subject("Good morning")
const {MailHelper} = require("@themost/mailer");
new MailHelper(context).subject("Good morning")
.text("Have a nice day!")
.to("user@example.com", "other@example.com")
.send(function(err, res) {
return done(err);
});
*/
// eslint-disable-next-line no-unused-vars
MailerHelper.prototype.to = function(recipient) {
var p1 = argumentsArray.apply(this, arguments).join(';');
if (p1.length>0)
Expand Down Expand Up @@ -340,8 +337,8 @@ MailerHelper.prototype.transporter = function(opts) {
* @returns {MailerHelper}
*
* @example
var mm = require("most-web-mailer");
mm.mailer(context).subject("Good morning")
const {MailHelper} = require('@themost/mailer');
new MailHelper(context).subject("Good morning")
.subject("New Order")
.template("new-order-notification")
.to("employee1@example.com")
Expand All @@ -359,12 +356,12 @@ MailerHelper.prototype.test = function(value) {

/**
* Sets the message secondary recipient(s).
* @param {string} cc - A string that represents the email address of a message recipient.
* @param {...string} cc - A string that represents the email address of a message recipient.
* @returns {MailerHelper}
*
* @example
var mm = require("most-web-mailer");
mm.mailer(context).subject("Good morning")
const {MailHelper} = require('@themost/mailer');
new MailHelper(context).subject("Good morning")
.subject("New Order")
.template("new-order-notification")
.to("employee1@example.com")
Expand All @@ -373,6 +370,7 @@ MailerHelper.prototype.test = function(value) {
return done(err);
});
*/
// eslint-disable-next-line no-unused-vars
MailerHelper.prototype.cc = function(cc) {
var p1 = argumentsArray.apply(this, arguments).join(';');
if (p1.length>0)
Expand All @@ -389,15 +387,16 @@ MailerHelper.prototype.cc = function(cc) {
*
* @example
*
var mm = require("most-web-mailer");
mm.mailer(context).subject("Good morning")
const {MailHelper} = require("@themost/mailer");
new MailHelper(context).subject("Good morning")
.text("This is a plain text message.")
.to("user@example.com")
.bcc("admin1@example.com","admin2@example.com")
.send(function(err, res) {
return done(err);
});
*/
// eslint-disable-next-line no-unused-vars
MailerHelper.prototype.bcc = function(bcc) {
var p1 = argumentsArray.apply(this, arguments).join(';');
if (p1.length>0)
Expand All @@ -415,8 +414,8 @@ MailerHelper.prototype.bcc = function(bcc) {
*
* @example
*
var mm = require("most-web-mailer");
mm.mailer(context).subject("Good morning")
const {MailHelper} = require('@themost/mailer');
new MailHelper(context).subject("Good morning")
.text("This is a plain text message.")
.to("user2@example.com")
.cc("friend1@example.com","friend2@example.com")
Expand Down Expand Up @@ -512,6 +511,21 @@ MailerHelper.prototype.send = function(data, callback) {
callback(e);
}
};
/**
* Sends a mail message
* @param {*} data
*/
MailerHelper.prototype.sendAsync = function(data) {
var self = this;
return new Promise(function(resolve, reject) {
return self.send(data, function(err, result) {
if (err) {
return reject(err);
}
return resolve(result);
});
});
}

MailerHelper.prototype.getTemplatePath = function(template, extension) {
if (typeof this.context.application.mapPath === 'function') {
Expand Down Expand Up @@ -566,7 +580,7 @@ function tryDefaultSender() {
var opts = application.getConfiguration().settings['mail'] || application.getConfiguration().settings['mailSettings'];
if (typeof opts === 'undefined' || opts === null)
return;
if (util.isArray(opts.from))
if (Array.isArray(opts.from))
self.options.from = opts.from.join(';');
else if (typeof opts.from === 'string')
self.options.from = opts.from;
Expand All @@ -593,12 +607,11 @@ function tryDefaultBCC() {
var opts = application.getConfiguration().settings['mail'] || application.getConfiguration().settings['mailSettings'];
if (typeof opts === 'undefined' || opts === null)
return;
if (util.isArray(opts.bcc))
if (Array.isArray(opts.bcc))
self.options.bcc = opts.bcc.join(';');
else if (typeof opts.bcc === 'string')
self.options.bcc = opts.bcc;
}
if (typeof exports !== 'undefined') {
module.exports = {
MailHelper: MailerHelper,
/**
Expand All @@ -609,8 +622,8 @@ if (typeof exports !== 'undefined') {
*
* @example
*
var mm = require("most-web-mailer");
mm.mailer(context)
const {MailHelper} = require("@themost/mailer");
new MailHelper(context)
.to("user@example.com")
.subject("Hello Message")
.body("Hello User.").send(function(err, res) {
Expand All @@ -627,8 +640,8 @@ mm.mailer(context)
*
* @example
*
var mm = require("most-web-mailer");
mm.mailer(context)
const {MailHelper} = require('@themost/mailer');
new MailHelper(context)
.to("user@example.com")
.subject("Hello Message")
.body("Hello User.").send(function(err, res) {
Expand All @@ -639,5 +652,4 @@ mm.mailer(context)
return new MailerHelper(context);
}
};
}

Loading

0 comments on commit bf7824f

Please sign in to comment.