Skip to content

Commit

Permalink
refactor: use latest env & force laatest dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
lykmapipo committed Apr 16, 2019
1 parent e0f6fd4 commit 7650259
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 358 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/* dependencies */
const path = require('path');
const _ = require('lodash');
const env = require('@lykmapipo/env');
const { getString } = require('@lykmapipo/env');
const kue = require('kue');
const { worker } = require('mongoose-kue');
const libPath = path.join(__dirname, 'lib');
Expand All @@ -13,8 +13,8 @@ const Message = require(path.join(libPath, 'message.model'));

/* constants */
const { TYPE_EMAIL, TYPE_SMS } = Message;
const DEFAULT_SMTP_TRANSPORT_NAME = env('DEFAULT_SMTP_TRANSPORT_NAME');
const DEFAULT_SMS_TRANSPORT_NAME = env('DEFAULT_SMS_TRANSPORT_NAME');
const DEFAULT_SMTP_TRANSPORT_NAME = getString('DEFAULT_SMTP_TRANSPORT_NAME');
const DEFAULT_SMS_TRANSPORT_NAME = getString('DEFAULT_SMS_TRANSPORT_NAME');


/**
Expand Down
11 changes: 5 additions & 6 deletions lib/message.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ const path = require('path');
const _ = require('lodash');
const async = require('async');
const mongoose = require('mongoose');
const env = require('@lykmapipo/env');
const { getString, getBoolean } = require('@lykmapipo/env');
const actions = require('mongoose-rest-actions');
const hash = require('object-hash');
const isHtml = require('is-html');
const { getBoolean } = env;
const { plugin: runInBackground, worker } = require('mongoose-kue');
const { Schema } = mongoose;
const { Mixed } = Schema.Types;
Expand All @@ -40,7 +39,7 @@ const { Mixed } = Schema.Types;
/* transports */
const ECHO_TRANSPORT_NAME = 'echo';
const DEFAULT_TRANSPORT_NAME =
env('DEFAULT_TRANSPORT_NAME', ECHO_TRANSPORT_NAME);
getString('DEFAULT_TRANSPORT_NAME', ECHO_TRANSPORT_NAME);

/* load transports */
const transports = {
Expand Down Expand Up @@ -91,11 +90,11 @@ const SEND_MODES = [SEND_MODE_PULL, SEND_MODE_PUSH];


/* model name for the message */
const MODEL_NAME = env('MODEL_NAME', 'Message');
const MODEL_NAME = getString('MODEL_NAME', 'Message');


/* collection name for the message */
const COLLECTION_NAME = env('COLLECTION_NAME', 'messages');
const COLLECTION_NAME = getString('COLLECTION_NAME', 'messages');


/* schema options */
Expand Down Expand Up @@ -813,7 +812,7 @@ MessageSchema.methods.queue = function queue() {
else {

//prepare job details
const jobType = (message.type || env('QUEUE_DEFAULT_JOB_TYPE'));
const jobType = (message.type || getString('QUEUE_DEFAULT_JOB_TYPE'));
const title = (message.subject || jobType);
const jobDefaults = ({ method: 'send', title: title, type: jobType });
const jobDetails = _.merge({}, jobDefaults, message.toObject());
Expand Down
6 changes: 2 additions & 4 deletions lib/transports/sms.infobip.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

/* dependencies */
const _ = require('lodash');
const env = require('@lykmapipo/env');
const { getString } = require('@lykmapipo/env');
const Transport = require('bipsms');


Expand Down Expand Up @@ -133,8 +133,6 @@ exports._send = function (message, done) {
text: body
});

console.log(payload);

//perform actual send
exports.transport.sendSingleSMS(payload, done);

Expand All @@ -155,7 +153,7 @@ exports._send = function (message, done) {
exports.send = function (message, done) {

//update message with transport details
message.sender = message.sender || env('SMS_INFOBIP_DEFAULT_SENDER_ID');
message.sender = message.sender || getString('SMS_INFOBIP_DEFAULT_SENDER_ID');

//perform actual sms sending
exports._send(message, done);
Expand Down
4 changes: 2 additions & 2 deletions lib/transports/sms.tz.ega.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

/* dependencies */
const _ = require('lodash');
const env = require('@lykmapipo/env');
const { getString } = require('@lykmapipo/env');
const transport = require('@lykmapipo/tz-ega-sms');


Expand Down Expand Up @@ -150,7 +150,7 @@ exports._send = function (message, done) {
exports.send = function (message, done) {

//update message with transport details
message.sender = message.sender || env('SMS_EGA_TZ_DEFAULT_SENDER_ID');
message.sender = message.sender || getString('SMS_EGA_TZ_DEFAULT_SENDER_ID');

//perform actual sms sending
exports._send(message, done);
Expand Down
13 changes: 6 additions & 7 deletions lib/transports/smtp.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
/* dependencies */
const _ = require('lodash');
const async = require('async');
const env = require('@lykmapipo/env');
const { getString, getBoolean, getNumber } = require('@lykmapipo/env');
const nodemailer = require('nodemailer');
const striptags = require('striptags');
const { getBoolean, getNumber } = env;


/**
Expand All @@ -35,21 +34,21 @@ const { getBoolean, getNumber } = env;
exports.defaults = {

//default mail sender if non provided during send
from: env('SMTP_FROM'),
from: getString('SMTP_FROM'),

//default smtp port to connect
port: getNumber('SMTP_PORT', 567),

//default smtp server hostname or IP address to connect
host: env('SMTP_HOST'),
host: getString('SMTP_HOST'),

//defines if the connection should use SSL
secure: getBoolean('SMTP_SECURE', false),

// default authentication data
auth: {
user: env('SMTP_USERNAME'), //username
pass: env('SMTP_PASSWORD') //password for the user
user: getString('SMTP_USERNAME'), //username
pass: getString('SMTP_PASSWORD') //password for the user
}

};
Expand Down Expand Up @@ -201,7 +200,7 @@ exports._send = function (message, done) {
exports.send = function (message, done) {

//ensure email sender
message.sender = message.sender || env('SMTP_FROM');
message.sender = message.sender || getString('SMTP_FROM');

//perform actual smtp sending
exports._send(message, done);
Expand Down
4 changes: 2 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/* dependencies */
const _ = require('lodash');
const phone = require('phone');
const env = require('@lykmapipo/env');
const { getString } = require('@lykmapipo/env');


/**
Expand All @@ -23,7 +23,7 @@ exports.toE164 = function (phoneNumber, countryCode) {

//try convert give phone number to e.164
try {
const _countryCode = (countryCode || env('DEFAULT_COUNTRY_CODE'));
const _countryCode = (countryCode || getString('DEFAULT_COUNTRY_CODE'));
let _phoneNumber = phone(phoneNumber, _countryCode);
_phoneNumber = _
.first(_phoneNumber).replace(/\+/g, '');
Expand Down
Loading

0 comments on commit 7650259

Please sign in to comment.