diff --git a/package.json b/package.json index b8d71f489..81a338f5c 100644 --- a/package.json +++ b/package.json @@ -34,14 +34,14 @@ "flake-idgen": "^1.0.0", "ioredis": "^1.14.0", "jsonwebtoken": "^5.5.4", - "lodash": "^3.10.1", + "lodash": "^4.0.0", "moment": "^2.11.1", "ms-amqp-conf": "^0.2.0", - "ms-amqp-transport": "^1.1.0", + "ms-amqp-transport": "^1.1.3", "ms-mailer-client": "^1.0.0", "ms-mailer-templates": "^0.3.0", "ms-validation": "^1.0.1", - "mservice": "^1.3.0", + "mservice": "^1.5.0", "node-uuid": "^1.4.7", "password-generator": "^2.0.2", "redis-filtered-sort": "^1.1.1", @@ -50,7 +50,7 @@ "urlsafe-base64": "^1.0.0" }, "devDependencies": { - "babel-cli": "^6.4.0", + "babel-cli": "^6.4.5", "babel-eslint": "^5.0.0-beta6", "babel-preset-es2015": "^6.3.13", "babel-preset-stage-0": "^6.3.13", diff --git a/src/actions/list.js b/src/actions/list.js index 20265a3e4..473b38c7f 100644 --- a/src/actions/list.js +++ b/src/actions/list.js @@ -1,7 +1,8 @@ const Promise = require('bluebird'); const redisKey = require('../utils/key.js'); -const ld = require('lodash'); +const mapValues = require('lodash/mapValues'); const { filter: transformFilter } = require('redis-filtered-sort'); +const JSONParse = JSON.parse.bind(JSON); module.exports = function iterateOverActiveUsers(opts) { const { redis, config } = this; @@ -43,7 +44,7 @@ module.exports = function iterateOverActiveUsers(opts) { const account = { id, metadata: { - [audience]: data ? ld.mapValues(data, JSON.parse, JSON) : {}, + [audience]: data ? mapValues(data, JSONParse) : {}, }, }; diff --git a/src/actions/register.js b/src/actions/register.js index c1d1a66b9..bd3299394 100644 --- a/src/actions/register.js +++ b/src/actions/register.js @@ -1,7 +1,8 @@ const Promise = require('bluebird'); const Errors = require('common-errors'); const request = require('request-promise'); -const ld = require('lodash'); +const defaults = require('lodash/defaults'); +const pick = require('lodash/pick'); const setMetadata = require('../utils/updateMetadata.js'); const scrypt = require('../utils/scrypt.js'); const redisKey = require('../utils/key.js'); @@ -80,7 +81,7 @@ function makeCaptchaCheck(redis, username, captcha, captchaConfig) { } }) .then(function verifyGoogleCaptcha() { - return request.post({ uri, qs: ld.defaults(captcha, { secret }), json: true }) + return request.post({ uri, qs: defaults(captcha, { secret }), json: true }) .then(function captchaSuccess(body) { if (!body.success) { return Promise.reject({ statusCode: 200, error: body }); @@ -89,7 +90,7 @@ function makeCaptchaCheck(redis, username, captcha, captchaConfig) { return true; }) .catch(function captchaError(err) { - const errData = JSON.stringify(ld.pick(err, ['statusCode', 'error'])); + const errData = JSON.stringify(pick(err, ['statusCode', 'error'])); throw new Errors.HttpStatusError(412, fmt('Captcha response: %s', errData)); }); }); diff --git a/src/custom/cappasity-users-activate.js b/src/custom/cappasity-users-activate.js index e418c5d81..1709a4636 100644 --- a/src/custom/cappasity-users-activate.js +++ b/src/custom/cappasity-users-activate.js @@ -1,4 +1,4 @@ -const ld = require('lodash'); +const find = require('lodash/find'); const moment = require('moment'); const setMetadata = require('../utils/updateMetadata.js'); @@ -17,7 +17,7 @@ module.exports = function mixPlan(username, audience) { .publishAndWait(route, id, { timeout: 5000 }) .bind(this) .then(function mix(plan) { - const subscription = ld.findWhere(plan.subs, { name: 'month' }); + const subscription = find(plan.subs, ['name', 'month']); const nextCycle = moment().add(1, 'month').valueOf(); const update = { username, diff --git a/src/users.js b/src/users.js index d11b8d574..4bc42e197 100644 --- a/src/users.js +++ b/src/users.js @@ -3,7 +3,7 @@ const path = require('path'); const Mailer = require('ms-mailer-client'); const Promise = require('bluebird'); const Errors = require('common-errors'); -const ld = require('lodash'); +const merge = require('lodash/merge'); const fsort = require('redis-filtered-sort'); const { NotImplementedError } = Errors; @@ -121,7 +121,7 @@ module.exports = class Users extends Mservice { * @return {Users} */ constructor(opts = {}) { - super(ld.merge({}, Users.defaultOpts, opts)); + super(merge({}, Users.defaultOpts, opts)); const config = this.config; const { error } = this.validateSync('config', config); diff --git a/src/utils/getMetadata.js b/src/utils/getMetadata.js index 5bf6e862d..e99ec6e71 100644 --- a/src/utils/getMetadata.js +++ b/src/utils/getMetadata.js @@ -1,7 +1,8 @@ -const ld = require('lodash'); +const mapValues = require('lodash/mapValues'); const redisKey = require('../utils/key.js'); const Promise = require('bluebird'); const { isArray } = Array; +const JSONParse = JSON.parse.bind(JSON); module.exports = function getMetadata(username, _audience) { const { redis } = this; @@ -15,7 +16,7 @@ module.exports = function getMetadata(username, _audience) { audience.forEach(function transform(aud, idx) { const datum = data[idx]; if (datum) { - output[aud] = ld.mapValues(datum, JSON.parse, JSON); + output[aud] = mapValues(datum, JSONParse); } else { output[aud] = {}; } diff --git a/src/utils/updateMetadata.js b/src/utils/updateMetadata.js index 849bad5ec..4eedc9f1c 100644 --- a/src/utils/updateMetadata.js +++ b/src/utils/updateMetadata.js @@ -1,5 +1,6 @@ -const ld = require('lodash'); +const mapValues = require('lodash/mapValues'); const redisKey = require('../utils/key.js'); +const JSONStringify = JSON.stringify.bind(JSON); /** * Updates metadata on a user object @@ -23,7 +24,7 @@ module.exports = function updateMetadata(opts) { const $setKeys = $set && Object.keys($set); const $setLength = $setKeys && $setKeys.length || 0; if ($setLength > 0) { - pipeline.hmset(metadataKey, ld.mapValues($set, JSON.stringify, JSON)); + pipeline.hmset(metadataKey, mapValues($set, JSONStringify)); } const $incr = metadata.$incr; diff --git a/test/suites/list.js b/test/suites/list.js index 6a0ef392d..e243eeff4 100644 --- a/test/suites/list.js +++ b/test/suites/list.js @@ -29,7 +29,10 @@ describe('#list', function listSuite() { promises.push(this.users._redis .pipeline() .sadd(userSet, user.id) - .hmset(redisKey(user.id, 'metadata', audience), ld.mapValues(user.metadata, JSON.stringify, JSON)) + .hmset( + redisKey(user.id, 'metadata', audience), + ld.mapValues(user.metadata, JSON.stringify.bind(JSON)) + ) .exec() ); });