@dhyasama/totem-models 8.0.2 → 8.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/helpers.js +27 -0
- package/lib/Activity.js +5 -11
- package/package.json +3 -3
package/helpers.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
const _ = require('underscore');
|
|
4
4
|
const mongoose = require('mongoose');
|
|
5
|
+
const rangeCheck = require('range_check');
|
|
6
|
+
const request = require('request');
|
|
7
|
+
const utilities = require('@dhyasama/totem-utilities');
|
|
5
8
|
|
|
6
9
|
const cleanOrg = module.exports.cleanOrg = function cleanOrg(doc, customerId) {
|
|
7
10
|
|
|
@@ -49,6 +52,30 @@ const getDefaultOptions = module.exports.getDefaultOptions = function getDefault
|
|
|
49
52
|
|
|
50
53
|
};
|
|
51
54
|
|
|
55
|
+
const getGeolocation = module.exports.getGeolocation = function getGeolocation(ip, cb) {
|
|
56
|
+
|
|
57
|
+
if (!rangeCheck.validIp(ip)) { return cb(null, {}); }
|
|
58
|
+
|
|
59
|
+
request('https://freegeoip.net/json/' + ip, function (error, response, body) {
|
|
60
|
+
|
|
61
|
+
if (error) {
|
|
62
|
+
return cb(error, null);
|
|
63
|
+
}
|
|
64
|
+
else if (response && response.statusCode !== 200) {
|
|
65
|
+
return cb(new Error('non-200 status code from geoip (' + response.statusCode + ')'), null);
|
|
66
|
+
}
|
|
67
|
+
else if (!utilities.isValidJson(body)) {
|
|
68
|
+
return cb(new Error('invalid json from geoip'), null);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
return cb(null, JSON.parse(body));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
};
|
|
78
|
+
|
|
52
79
|
const getPeopleSources = module.exports.getPeopleSources = function getPeopleSources(people) {
|
|
53
80
|
|
|
54
81
|
if (!people) { return []; }
|
package/lib/Activity.js
CHANGED
|
@@ -5,10 +5,8 @@ module.exports = function(mongoose, config) {
|
|
|
5
5
|
var
|
|
6
6
|
|
|
7
7
|
Schema = mongoose.Schema,
|
|
8
|
-
Geoip = require('@dhyasama/ffvc-geoip'),
|
|
9
|
-
geoip = new Geoip(),
|
|
10
8
|
async = require('async'),
|
|
11
|
-
|
|
9
|
+
helpers = require('../helpers');
|
|
12
10
|
|
|
13
11
|
var Activity = new Schema({
|
|
14
12
|
|
|
@@ -46,8 +44,6 @@ module.exports = function(mongoose, config) {
|
|
|
46
44
|
|
|
47
45
|
});
|
|
48
46
|
|
|
49
|
-
|
|
50
|
-
|
|
51
47
|
Activity.statics.add = function(username, type, remoteAddress, url, filename, callback) {
|
|
52
48
|
|
|
53
49
|
var self = this;
|
|
@@ -76,11 +72,6 @@ module.exports = function(mongoose, config) {
|
|
|
76
72
|
|
|
77
73
|
};
|
|
78
74
|
|
|
79
|
-
var getGeolocation = function(cb) {
|
|
80
|
-
if (!rangeCheck.validIp(remoteAddress)) return cb(null, {});
|
|
81
|
-
geoip.locate(remoteAddress, cb);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
75
|
var asyncFinally = function(err, results) {
|
|
85
76
|
|
|
86
77
|
var activity = results ? results[0] : {};
|
|
@@ -111,7 +102,10 @@ module.exports = function(mongoose, config) {
|
|
|
111
102
|
|
|
112
103
|
};
|
|
113
104
|
|
|
114
|
-
async.parallel([
|
|
105
|
+
async.parallel([
|
|
106
|
+
getActivity,
|
|
107
|
+
helpers.getGeolocation.bind(null, remoteAddress)
|
|
108
|
+
], asyncFinally);
|
|
115
109
|
|
|
116
110
|
};
|
|
117
111
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhyasama/totem-models",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.3",
|
|
4
4
|
"author": "Jason Reynolds",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"description": "Models for Totem platform",
|
|
@@ -12,8 +12,7 @@
|
|
|
12
12
|
"registry": "https://registry.npmjs.org/"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@dhyasama/
|
|
16
|
-
"@dhyasama/ffvc-utilities": "^2.7.5",
|
|
15
|
+
"@dhyasama/totem-utilities": "^3.0.0",
|
|
17
16
|
"async": "^2.6.3",
|
|
18
17
|
"awesome-phonenumber": "^1.0.14",
|
|
19
18
|
"bluebird": "^3.7.0",
|
|
@@ -22,6 +21,7 @@
|
|
|
22
21
|
"mongoose-deep-populate": "^3.0.0",
|
|
23
22
|
"mongoose-filter-denormalize": "^0.2.1",
|
|
24
23
|
"range_check": "^1.4.0",
|
|
24
|
+
"request": "^2.88.0",
|
|
25
25
|
"underscore": "~1.5.0",
|
|
26
26
|
"validator": "^5.4.0"
|
|
27
27
|
},
|