analytics-node
Advanced tools
Comparing version 2.4.0 to 2.4.1
2.4.1 / 2017-05-05 | ||
================== | ||
* Preventing webpack to bundle all lodash lib (#94) | ||
* README: fix header | ||
* README: fix badge | ||
* package: upgrade dependencies (#89) | ||
* standard (#88) | ||
* yarn (#85) | ||
* analytics-node.js@2.4.0 [ci skip] | ||
2.4.0 / 2017-03-13 | ||
@@ -3,0 +14,0 @@ ================== |
177
lib/index.js
@@ -1,14 +0,14 @@ | ||
var assert = require('assert'); | ||
var clone = require('clone'); | ||
var debug = require('debug')('analytics-node'); | ||
var noop = function(){}; | ||
var request = require('superagent'); | ||
require('superagent-retry')(request); | ||
var uid = require('crypto-token'); | ||
var version = require('../package.json').version; | ||
var extend = require('lodash').extend; | ||
var validate = require('@segment/loosely-validate-event'); | ||
var removeSlash = require('remove-trailing-slash'); | ||
var assert = require('assert') | ||
var clone = require('clone') | ||
var debug = require('debug')('analytics-node') | ||
var noop = function () {} | ||
var request = require('superagent') | ||
require('superagent-retry')(request) | ||
var uid = require('crypto-token') | ||
var version = require('../package.json').version | ||
var extend = require('lodash/extend') | ||
var validate = require('@segment/loosely-validate-event') | ||
var removeSlash = require('remove-trailing-slash') | ||
global.setImmediate = global.setImmediate || process.nextTick.bind(process); | ||
global.setImmediate = global.setImmediate || process.nextTick.bind(process) | ||
@@ -19,3 +19,3 @@ /** | ||
module.exports = Analytics; | ||
module.exports = Analytics | ||
@@ -33,11 +33,11 @@ /** | ||
function Analytics(writeKey, options){ | ||
if (!(this instanceof Analytics)) return new Analytics(writeKey, options); | ||
assert(writeKey, 'You must pass your Segment project\'s write key.'); | ||
options = options || {}; | ||
this.queue = []; | ||
this.writeKey = writeKey; | ||
this.host = removeSlash(options.host || 'https://api.segment.io'); | ||
this.flushAt = Math.max(options.flushAt, 1) || 20; | ||
this.flushAfter = options.flushAfter || 10000; | ||
function Analytics (writeKey, options) { | ||
if (!(this instanceof Analytics)) return new Analytics(writeKey, options) | ||
assert(writeKey, 'You must pass your Segment project\'s write key.') | ||
options = options || {} | ||
this.queue = [] | ||
this.writeKey = writeKey | ||
this.host = removeSlash(options.host || 'https://api.segment.io') | ||
this.flushAt = Math.max(options.flushAt, 1) || 20 | ||
this.flushAfter = options.flushAfter || 10000 | ||
} | ||
@@ -53,7 +53,7 @@ | ||
Analytics.prototype.identify = function(message, fn){ | ||
validate(message, 'identify'); | ||
this.enqueue('identify', message, fn); | ||
return this; | ||
}; | ||
Analytics.prototype.identify = function (message, fn) { | ||
validate(message, 'identify') | ||
this.enqueue('identify', message, fn) | ||
return this | ||
} | ||
@@ -68,7 +68,7 @@ /** | ||
Analytics.prototype.group = function(message, fn){ | ||
validate(message, 'group'); | ||
this.enqueue('group', message, fn); | ||
return this; | ||
}; | ||
Analytics.prototype.group = function (message, fn) { | ||
validate(message, 'group') | ||
this.enqueue('group', message, fn) | ||
return this | ||
} | ||
@@ -83,7 +83,7 @@ /** | ||
Analytics.prototype.track = function(message, fn){ | ||
validate(message, 'track'); | ||
this.enqueue('track', message, fn); | ||
return this; | ||
}; | ||
Analytics.prototype.track = function (message, fn) { | ||
validate(message, 'track') | ||
this.enqueue('track', message, fn) | ||
return this | ||
} | ||
@@ -98,7 +98,7 @@ /** | ||
Analytics.prototype.page = function(message, fn){ | ||
validate(message, 'page'); | ||
this.enqueue('page', message, fn); | ||
return this; | ||
}; | ||
Analytics.prototype.page = function (message, fn) { | ||
validate(message, 'page') | ||
this.enqueue('page', message, fn) | ||
return this | ||
} | ||
@@ -113,7 +113,7 @@ /** | ||
Analytics.prototype.screen = function(message, fn){ | ||
validate(message, 'screen'); | ||
this.enqueue('screen', message, fn); | ||
return this; | ||
}; | ||
Analytics.prototype.screen = function (message, fn) { | ||
validate(message, 'screen') | ||
this.enqueue('screen', message, fn) | ||
return this | ||
} | ||
@@ -128,7 +128,7 @@ /** | ||
Analytics.prototype.alias = function(message, fn){ | ||
validate(message, 'alias'); | ||
this.enqueue('alias', message, fn); | ||
return this; | ||
}; | ||
Analytics.prototype.alias = function (message, fn) { | ||
validate(message, 'alias') | ||
this.enqueue('alias', message, fn) | ||
return this | ||
} | ||
@@ -142,9 +142,9 @@ /** | ||
Analytics.prototype.flush = function(fn){ | ||
fn = fn || noop; | ||
if (!this.queue.length) return setImmediate(fn); | ||
Analytics.prototype.flush = function (fn) { | ||
fn = fn || noop | ||
if (!this.queue.length) return setImmediate(fn) | ||
var items = this.queue.splice(0, this.flushAt); | ||
var fns = items.map(function(_){ return _.callback; }); | ||
var batch = items.map(function(_){ return _.message; }); | ||
var items = this.queue.splice(0, this.flushAt) | ||
var fns = items.map(function (_) { return _.callback }) | ||
var batch = items.map(function (_) { return _.message }) | ||
@@ -155,7 +155,7 @@ var data = { | ||
sentAt: new Date() | ||
}; | ||
} | ||
debug('flush: %o', data); | ||
debug('flush: %o', data) | ||
var req = request | ||
request | ||
.post(this.host + '/v1/batch') | ||
@@ -165,9 +165,9 @@ .auth(this.writeKey, '') | ||
.send(data) | ||
.end(function(err, res){ | ||
err = err || error(res); | ||
fns.push(fn); | ||
fns.forEach(function(fn){ fn(err, data); }); | ||
debug('flushed: %o', data); | ||
}); | ||
}; | ||
.end(function (err, res) { | ||
err = err || error(res) | ||
fns.push(fn) | ||
fns.forEach(function (fn) { fn(err, data) }) | ||
debug('flushed: %o', data) | ||
}) | ||
} | ||
@@ -184,28 +184,28 @@ /** | ||
Analytics.prototype.enqueue = function(type, message, fn){ | ||
fn = fn || noop; | ||
message = clone(message); | ||
message.type = type; | ||
Analytics.prototype.enqueue = function (type, message, fn) { | ||
fn = fn || noop | ||
message = clone(message) | ||
message.type = type | ||
message.context = extend(message.context || {}, { | ||
library: { | ||
name: 'analytics-node', | ||
version: version, | ||
version: version | ||
} | ||
}); | ||
}) | ||
message._metadata = extend(message._metadata || {}, { nodeVersion: process.versions.node }); | ||
message._metadata = extend(message._metadata || {}, { nodeVersion: process.versions.node }) | ||
if (!message.timestamp) message.timestamp = new Date(); | ||
if (!message.messageId) message.messageId = 'node-' + uid(32); | ||
if (!message.timestamp) message.timestamp = new Date() | ||
if (!message.messageId) message.messageId = 'node-' + uid(32) | ||
debug('%s: %o', type, message); | ||
debug('%s: %o', type, message) | ||
this.queue.push({ | ||
message: message, | ||
callback: fn | ||
}); | ||
}) | ||
if (this.queue.length >= this.flushAt) this.flush(); | ||
if (this.timer) clearTimeout(this.timer); | ||
if (this.flushAfter) this.timer = setTimeout(this.flush.bind(this), this.flushAfter); | ||
}; | ||
if (this.queue.length >= this.flushAt) this.flush() | ||
if (this.timer) clearTimeout(this.timer) | ||
if (this.flushAfter) this.timer = setTimeout(this.flush.bind(this), this.flushAfter) | ||
} | ||
@@ -219,8 +219,7 @@ /** | ||
function error(res){ | ||
if (!res.error) return; | ||
var body = res.body; | ||
var msg = body.error && body.error.message | ||
|| res.status + ' ' + res.text; | ||
return new Error(msg); | ||
function error (res) { | ||
if (!res.error) return | ||
var body = res.body | ||
var msg = (body.error && body.error.message) || res.status + ' ' + res.text | ||
return new Error(msg) | ||
} |
{ | ||
"name": "analytics-node", | ||
"repository": "git://github.com/segmentio/analytics-node", | ||
"version": "2.4.0", | ||
"version": "2.4.1", | ||
"description": "The hassle-free way to integrate analytics into any node application.", | ||
@@ -24,20 +24,19 @@ "keywords": [ | ||
"@segment/loosely-validate-event": "^1.1.2", | ||
"clone": "~2.1.0", | ||
"clone": "^2.1.1", | ||
"commander": "^2.9.0", | ||
"crypto-token": "^1.0.1", | ||
"debug": "^2.2.0", | ||
"lodash": "~4.17.2", | ||
"debug": "^2.6.2", | ||
"lodash": "^4.17.4", | ||
"remove-trailing-slash": "^0.1.0", | ||
"superagent": "^3.0.0", | ||
"superagent-proxy": "^1.0.0", | ||
"superagent": "^3.5.0", | ||
"superagent-retry": "^0.6.0" | ||
}, | ||
"devDependencies": { | ||
"async": "~0.9.0", | ||
"brfs": "^1.3.0", | ||
"browserify": "^8.1.3", | ||
"express": "~3.4.8", | ||
"http-proxy": "~1.11.1", | ||
"mocha": "1.8.1", | ||
"nsp": "^2.0.2" | ||
"body-parser": "^1.17.1", | ||
"brfs": "^1.4.3", | ||
"browserify": "^14.1.0", | ||
"express": "^4.15.2", | ||
"mocha": "^3.2.0", | ||
"nsp": "^2.6.3", | ||
"standard": "^9.0.1" | ||
}, | ||
@@ -50,3 +49,8 @@ "engines": { | ||
}, | ||
"standard": { | ||
"ignore": [ | ||
"analytics-node.js" | ||
] | ||
}, | ||
"license": "MIT" | ||
} |
#analytics-node | ||
# analytics-node | ||
[![CircleCI](https://circleci.com/gh/segmentio/analytics-node.svg?style=svg)](https://circleci.com/gh/segmentio/analytics-node) | ||
[![CircleCI](https://circleci.com/gh/segmentio/analytics-node.svg?style=svg&circle-token=68654e8cd0fcd16b1f3ae9943a1d8e20e36ae6c5)](https://circleci.com/gh/segmentio/analytics-node) | ||
@@ -6,0 +6,0 @@ A node.js client for [Segment](https://segment.com) — The hassle-free way to integrate analytics into any application. |
@@ -1,10 +0,11 @@ | ||
var assert = require('assert'); | ||
var Analytics = require('..'); | ||
var async = require('async'); | ||
var server = require('./server'); | ||
/* global describe, before, beforeEach, it */ | ||
var a; | ||
var noop = function(){}; | ||
var id = 'id'; | ||
var assert = require('assert') | ||
var Analytics = require('..') | ||
var server = require('./server') | ||
var a | ||
var noop = function () {} | ||
var id = 'id' | ||
var context = { | ||
@@ -15,12 +16,12 @@ library: { | ||
} | ||
}; | ||
} | ||
describe('Analytics', function(){ | ||
before(function(done){ | ||
describe('Analytics', function () { | ||
before(function (done) { | ||
server.app | ||
.post('/v1/batch', server.fixture) | ||
.listen(server.ports.source, done); | ||
}); | ||
.listen(server.port, done) | ||
}) | ||
beforeEach(function(){ | ||
beforeEach(function () { | ||
a = Analytics('key', { | ||
@@ -30,35 +31,35 @@ host: 'http://localhost:4063', | ||
flushAfter: Infinity | ||
}); | ||
}); | ||
}) | ||
}) | ||
it('should expose a constructor', function(){ | ||
assert.equal('function', typeof Analytics); | ||
}); | ||
it('should expose a constructor', function () { | ||
assert.equal('function', typeof Analytics) | ||
}) | ||
it('should require a write key', function(){ | ||
assert.throws(Analytics, error("You must pass your Segment project's write key.")); | ||
}); | ||
it('should require a write key', function () { | ||
assert.throws(Analytics, error("You must pass your Segment project's write key.")) | ||
}) | ||
it('should not require the new keyword', function(){ | ||
assert(a instanceof Analytics); | ||
}); | ||
it('should not require the new keyword', function () { | ||
assert(a instanceof Analytics) | ||
}) | ||
it('should create a queue', function(){ | ||
assert.deepEqual(a.queue, []); | ||
}); | ||
it('should create a queue', function () { | ||
assert.deepEqual(a.queue, []) | ||
}) | ||
it('should set default options', function(){ | ||
var a = Analytics('key'); | ||
assert.equal(a.writeKey, 'key'); | ||
assert.equal(a.host, 'https://api.segment.io'); | ||
assert.equal(a.flushAt, 20); | ||
assert.equal(a.flushAfter, 10000); | ||
}); | ||
it('should set default options', function () { | ||
var a = Analytics('key') | ||
assert.equal(a.writeKey, 'key') | ||
assert.equal(a.host, 'https://api.segment.io') | ||
assert.equal(a.flushAt, 20) | ||
assert.equal(a.flushAfter, 10000) | ||
}) | ||
it('should remove trailing slashes from `.host`', function(){ | ||
var a = Analytics('key', { host: 'http://google.com/////' }); | ||
it('should remove trailing slashes from `.host`', function () { | ||
var a = Analytics('key', { host: 'http://google.com/////' }) | ||
assert.equal(a.host, 'http://google.com') | ||
}); | ||
}) | ||
it('should take options', function(){ | ||
it('should take options', function () { | ||
var a = Analytics('key', { | ||
@@ -68,111 +69,111 @@ host: 'a', | ||
flushAfter: 2 | ||
}); | ||
assert.equal(a.host, 'a'); | ||
assert.equal(a.flushAt, 1); | ||
assert.equal(a.flushAfter, 2); | ||
}); | ||
}) | ||
assert.equal(a.host, 'a') | ||
assert.equal(a.flushAt, 1) | ||
assert.equal(a.flushAfter, 2) | ||
}) | ||
it('should keep the flushAt option above zero', function(){ | ||
var a = Analytics('key', { flushAt: 0 }); | ||
assert.equal(a.flushAt, 1); | ||
}); | ||
it('should keep the flushAt option above zero', function () { | ||
var a = Analytics('key', { flushAt: 0 }) | ||
assert.equal(a.flushAt, 1) | ||
}) | ||
describe('#enqueue', function(){ | ||
it('should add a message to the queue', function(){ | ||
var date = new Date(); | ||
a.enqueue('type', { timestamp: date }, noop); | ||
describe('#enqueue', function () { | ||
it('should add a message to the queue', function () { | ||
var date = new Date() | ||
a.enqueue('type', { timestamp: date }, noop) | ||
var msg = a.queue[0].message; | ||
var callback = a.queue[0].callback; | ||
var msg = a.queue[0].message | ||
var callback = a.queue[0].callback | ||
assert.equal(callback, noop); | ||
assert.equal(msg.type, 'type'); | ||
assert.deepEqual(msg.timestamp, date); | ||
assert.deepEqual(msg.context, context); | ||
assert(msg.messageId); | ||
}); | ||
assert.equal(callback, noop) | ||
assert.equal(msg.type, 'type') | ||
assert.deepEqual(msg.timestamp, date) | ||
assert.deepEqual(msg.context, context) | ||
assert(msg.messageId) | ||
}) | ||
it('should not modify the original message', function(){ | ||
var message = { event: 'test' }; | ||
a.enqueue('type', message, noop); | ||
assert(!message.hasOwnProperty('timestamp')); | ||
}); | ||
it('should not modify the original message', function () { | ||
var message = { event: 'test' } | ||
a.enqueue('type', message, noop) | ||
assert(!message.hasOwnProperty('timestamp')) | ||
}) | ||
it('should flush the queue if it hits the max length', function(done){ | ||
a.flushAt = 1; | ||
a.flushAfter = null; | ||
a.flush = done; | ||
a.enqueue('type', {}); | ||
}); | ||
it('should flush the queue if it hits the max length', function (done) { | ||
a.flushAt = 1 | ||
a.flushAfter = null | ||
a.flush = done | ||
a.enqueue('type', {}) | ||
}) | ||
it('should flush after a period of time', function(done){ | ||
a.flushAt = Infinity; | ||
a.flushAfter = 1; | ||
a.flush = done; | ||
a.enqueue('type', {}); | ||
}); | ||
it('should flush after a period of time', function (done) { | ||
a.flushAt = Infinity | ||
a.flushAfter = 1 | ||
a.flush = done | ||
a.enqueue('type', {}) | ||
}) | ||
it('should reset an existing timer', function(done){ | ||
var i = 0; | ||
a.flushAt = Infinity; | ||
a.flushAfter = 1; | ||
a.flush = function(){ i++; }; | ||
a.enqueue('type', {}); | ||
a.enqueue('type', {}); | ||
setTimeout(function(){ | ||
assert.equal(1, i); | ||
done(); | ||
}, 1); | ||
}); | ||
it('should reset an existing timer', function (done) { | ||
var i = 0 | ||
a.flushAt = Infinity | ||
a.flushAfter = 1 | ||
a.flush = function () { i++ } | ||
a.enqueue('type', {}) | ||
a.enqueue('type', {}) | ||
setTimeout(function () { | ||
assert.equal(1, i) | ||
done() | ||
}, 1) | ||
}) | ||
it('should extend the given context', function(){ | ||
a.enqueue('type', { event: 'test', context: { name: 'travis' } }, noop); | ||
it('should extend the given context', function () { | ||
a.enqueue('type', { event: 'test', context: { name: 'travis' } }, noop) | ||
assert.deepEqual(a.queue[0].message.context, { | ||
library: { | ||
name:'analytics-node', | ||
name: 'analytics-node', | ||
version: require('../package.json').version | ||
}, | ||
name: 'travis' | ||
}); | ||
}); | ||
}) | ||
}) | ||
it('should add a message id', function(){ | ||
a.enqueue('type', { event: 'test' }, noop); | ||
var msg = a.queue[0].message; | ||
assert(msg.messageId); | ||
assert(/node-[a-zA-Z0-9]{32}/.test(msg.messageId)); | ||
it('should add a message id', function () { | ||
a.enqueue('type', { event: 'test' }, noop) | ||
var msg = a.queue[0].message | ||
assert(msg.messageId) | ||
assert(/node-[a-zA-Z0-9]{32}/.test(msg.messageId)) | ||
}) | ||
}); | ||
}) | ||
describe('#flush', function(){ | ||
it('should not fail when no items are in the queue', function(done){ | ||
a.flush(done); | ||
}); | ||
describe('#flush', function () { | ||
it('should not fail when no items are in the queue', function (done) { | ||
a.flush(done) | ||
}) | ||
it('should send a batch of items', function(done){ | ||
a.flushAt = 2; | ||
enqueue(a, [1, 2, 3]); | ||
a.flush(function(err, data){ | ||
if (err) return done(err); | ||
assert.deepEqual(data.batch, [1, 2]); | ||
assert(data.timestamp instanceof Date); | ||
assert(data.sentAt instanceof Date); | ||
done(); | ||
}); | ||
}); | ||
it('should send a batch of items', function (done) { | ||
a.flushAt = 2 | ||
enqueue(a, [1, 2, 3]) | ||
a.flush(function (err, data) { | ||
if (err) return done(err) | ||
assert.deepEqual(data.batch, [1, 2]) | ||
assert(data.timestamp instanceof Date) | ||
assert(data.sentAt instanceof Date) | ||
done() | ||
}) | ||
}) | ||
it('should callback with an HTTP error', function(done){ | ||
enqueue(a, ['error']); | ||
a.flush(function(err, data){ | ||
assert(err); | ||
assert.equal(err.message, 'Bad Request'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('should callback with an HTTP error', function (done) { | ||
enqueue(a, ['error']) | ||
a.flush(function (err, data) { | ||
assert(err) | ||
assert.equal(err.message, 'Bad Request') | ||
done() | ||
}) | ||
}) | ||
}) | ||
describe('#identify', function(){ | ||
it('should enqueue a message', function(){ | ||
var date = new Date(); | ||
a.identify({ userId: 'id', timestamp: date, messageId: id }); | ||
describe('#identify', function () { | ||
it('should enqueue a message', function () { | ||
var date = new Date() | ||
a.identify({ userId: 'id', timestamp: date, messageId: id }) | ||
assert.deepEqual(a.queue[0].message, { | ||
@@ -185,20 +186,20 @@ type: 'identify', | ||
_metadata: { nodeVersion: process.versions.node } | ||
}); | ||
}); | ||
}) | ||
}) | ||
it('should validate a message', function(){ | ||
assert.throws(a.identify, error('You must pass a message object.')); | ||
}); | ||
it('should validate a message', function () { | ||
assert.throws(a.identify, error('You must pass a message object.')) | ||
}) | ||
it('should require a userId or anonymousId', function(){ | ||
assert.throws(function(){ | ||
a.identify({}); | ||
}, error('You must pass either an "anonymousId" or a "userId".')); | ||
}); | ||
}); | ||
it('should require a userId or anonymousId', function () { | ||
assert.throws(function () { | ||
a.identify({}) | ||
}, error('You must pass either an "anonymousId" or a "userId".')) | ||
}) | ||
}) | ||
describe('#group', function(){ | ||
it('should enqueue a message', function(){ | ||
var date = new Date(); | ||
a.group({ groupId: 'group', userId: 'user', timestamp: date, messageId: id }); | ||
describe('#group', function () { | ||
it('should enqueue a message', function () { | ||
var date = new Date() | ||
a.group({ groupId: 'group', userId: 'user', timestamp: date, messageId: id }) | ||
assert.deepEqual(a.queue[0].message, { | ||
@@ -212,26 +213,26 @@ type: 'group', | ||
_metadata: { nodeVersion: process.versions.node } | ||
}); | ||
}); | ||
}) | ||
}) | ||
it('should validate a message', function(){ | ||
assert.throws(a.group, error('You must pass a message object.')); | ||
}); | ||
it('should validate a message', function () { | ||
assert.throws(a.group, error('You must pass a message object.')) | ||
}) | ||
it('should require a userId or anonymousId', function(){ | ||
assert.throws(function(){ | ||
a.group({}); | ||
}, error('You must pass either an "anonymousId" or a "userId".')); | ||
}); | ||
it('should require a userId or anonymousId', function () { | ||
assert.throws(function () { | ||
a.group({}) | ||
}, error('You must pass either an "anonymousId" or a "userId".')) | ||
}) | ||
it('should require a groupId', function(){ | ||
assert.throws(function(){ | ||
a.group({ userId: 'id' }); | ||
}, error('You must pass a "groupId".')); | ||
}); | ||
}); | ||
it('should require a groupId', function () { | ||
assert.throws(function () { | ||
a.group({ userId: 'id' }) | ||
}, error('You must pass a "groupId".')) | ||
}) | ||
}) | ||
describe('#track', function(){ | ||
it('should enqueue a message', function(){ | ||
var date = new Date(); | ||
a.track({ userId: 'id', event: 'event', timestamp: date, messageId: id }); | ||
describe('#track', function () { | ||
it('should enqueue a message', function () { | ||
var date = new Date() | ||
a.track({ userId: 'id', event: 'event', timestamp: date, messageId: id }) | ||
assert.deepEqual(a.queue[0].message, { | ||
@@ -245,8 +246,8 @@ type: 'track', | ||
_metadata: { nodeVersion: process.versions.node } | ||
}); | ||
}); | ||
}) | ||
}) | ||
it('should handle a user ids given as a number', function(){ | ||
var date = new Date(); | ||
a.track({ userId: 1, event: 'jumped the shark', timestamp: date, messageId: id }); | ||
it('should handle a user ids given as a number', function () { | ||
var date = new Date() | ||
a.track({ userId: 1, event: 'jumped the shark', timestamp: date, messageId: id }) | ||
assert.deepEqual(a.queue[0].message, { | ||
@@ -261,25 +262,25 @@ userId: 1, | ||
}) | ||
}); | ||
}) | ||
it('should validate a message', function(){ | ||
assert.throws(a.track, error('You must pass a message object.')); | ||
}); | ||
it('should validate a message', function () { | ||
assert.throws(a.track, error('You must pass a message object.')) | ||
}) | ||
it('should require a userId or anonymousId', function(){ | ||
assert.throws(function(){ | ||
a.track({}); | ||
}, error('You must pass either an "anonymousId" or a "userId".')); | ||
}); | ||
it('should require a userId or anonymousId', function () { | ||
assert.throws(function () { | ||
a.track({}) | ||
}, error('You must pass either an "anonymousId" or a "userId".')) | ||
}) | ||
it('should require an event', function(){ | ||
assert.throws(function(){ | ||
a.track({ userId: 'id' }); | ||
}, error('You must pass an "event".')); | ||
}); | ||
}); | ||
it('should require an event', function () { | ||
assert.throws(function () { | ||
a.track({ userId: 'id' }) | ||
}, error('You must pass an "event".')) | ||
}) | ||
}) | ||
describe('#page', function(){ | ||
it('should enqueue a message', function(){ | ||
var date = new Date(); | ||
a.page({ userId: 'id', timestamp: date, messageId: id }); | ||
describe('#page', function () { | ||
it('should enqueue a message', function () { | ||
var date = new Date() | ||
a.page({ userId: 'id', timestamp: date, messageId: id }) | ||
assert.deepEqual(a.queue[0].message, { | ||
@@ -292,20 +293,20 @@ type: 'page', | ||
_metadata: { nodeVersion: process.versions.node } | ||
}); | ||
}); | ||
}) | ||
}) | ||
it('should validate a message', function(){ | ||
assert.throws(a.page, error('You must pass a message object.')); | ||
}); | ||
it('should validate a message', function () { | ||
assert.throws(a.page, error('You must pass a message object.')) | ||
}) | ||
it('should require a userId or anonymousId', function(){ | ||
assert.throws(function(){ | ||
a.page({}); | ||
}, error('You must pass either an "anonymousId" or a "userId".')); | ||
}); | ||
}); | ||
it('should require a userId or anonymousId', function () { | ||
assert.throws(function () { | ||
a.page({}) | ||
}, error('You must pass either an "anonymousId" or a "userId".')) | ||
}) | ||
}) | ||
describe('#screen', function(){ | ||
it('should enqueue a message', function(){ | ||
var date = new Date(); | ||
a.screen({ userId: 'id', timestamp: date, messageId: id }); | ||
describe('#screen', function () { | ||
it('should enqueue a message', function () { | ||
var date = new Date() | ||
a.screen({ userId: 'id', timestamp: date, messageId: id }) | ||
assert.deepEqual(a.queue[0].message, { | ||
@@ -318,20 +319,20 @@ type: 'screen', | ||
_metadata: { nodeVersion: process.versions.node } | ||
}); | ||
}); | ||
}) | ||
}) | ||
it('should validate a message', function(){ | ||
assert.throws(a.screen, error('You must pass a message object.')); | ||
}); | ||
it('should validate a message', function () { | ||
assert.throws(a.screen, error('You must pass a message object.')) | ||
}) | ||
it('should require a userId or anonymousId', function(){ | ||
assert.throws(function(){ | ||
a.screen({}); | ||
}, error('You must pass either an "anonymousId" or a "userId".')); | ||
}); | ||
}); | ||
it('should require a userId or anonymousId', function () { | ||
assert.throws(function () { | ||
a.screen({}) | ||
}, error('You must pass either an "anonymousId" or a "userId".')) | ||
}) | ||
}) | ||
describe('#alias', function(){ | ||
it('should enqueue a message', function(){ | ||
var date = new Date(); | ||
a.alias({ previousId: 'previous', userId: 'id', timestamp: date, messageId: id }); | ||
describe('#alias', function () { | ||
it('should enqueue a message', function () { | ||
var date = new Date() | ||
a.alias({ previousId: 'previous', userId: 'id', timestamp: date, messageId: id }) | ||
assert.deepEqual(a.queue[0].message, { | ||
@@ -345,22 +346,22 @@ type: 'alias', | ||
_metadata: { nodeVersion: process.versions.node } | ||
}); | ||
}); | ||
}) | ||
}) | ||
it('should validate a message', function(){ | ||
assert.throws(a.alias, error('You must pass a message object.')); | ||
}); | ||
it('should validate a message', function () { | ||
assert.throws(a.alias, error('You must pass a message object.')) | ||
}) | ||
it('should require a userId', function(){ | ||
assert.throws(function(){ | ||
a.alias({}); | ||
}, error('You must pass a "userId".')); | ||
}); | ||
it('should require a userId', function () { | ||
assert.throws(function () { | ||
a.alias({}) | ||
}, error('You must pass a "userId".')) | ||
}) | ||
it('should require a previousId', function(){ | ||
assert.throws(function(){ | ||
a.alias({ userId: 'id' }); | ||
}, error('You must pass a "previousId".')); | ||
}); | ||
}); | ||
}); | ||
it('should require a previousId', function () { | ||
assert.throws(function () { | ||
a.alias({ userId: 'id' }) | ||
}, error('You must pass a "previousId".')) | ||
}) | ||
}) | ||
}) | ||
@@ -375,9 +376,9 @@ /** | ||
function enqueue(a, messages){ | ||
a.queue = messages.map(function(msg){ | ||
function enqueue (a, messages) { | ||
a.queue = messages.map(function (msg) { | ||
return { | ||
message: msg, | ||
callback: noop | ||
}; | ||
}); | ||
} | ||
}) | ||
} | ||
@@ -392,6 +393,6 @@ | ||
function error(message){ | ||
return function(err){ | ||
return err.message == message; | ||
}; | ||
function error (message) { | ||
return function (err) { | ||
return err.message === message | ||
} | ||
} |
@@ -1,21 +0,10 @@ | ||
var express = require('express'); | ||
var httpProxy = require('http-proxy'); | ||
var http = require('http'); | ||
var debug = require('debug')('analytics-node:server') | ||
var ports = exports.ports = { source: 4063, proxy: 4064 }; | ||
var express = require('express') | ||
var bodyParser = require('body-parser') | ||
/** | ||
* Proxy. | ||
* Port. | ||
*/ | ||
var proxy = httpProxy.createProxyServer(); | ||
exports.port = 4063 | ||
exports.proxy = http.createServer(function(req, res) { | ||
proxy.web(req, res, { target: 'http://localhost:' + ports.source }); | ||
}); | ||
proxy.on('proxyRes', function (proxyRes, req, res) { | ||
proxyRes.statusCode = 408; | ||
}); | ||
/** | ||
@@ -26,4 +15,3 @@ * App. | ||
exports.app = express() | ||
.use(express.bodyParser()) | ||
.use(express.basicAuth('key', '')); | ||
.use(bodyParser.json()) | ||
@@ -38,6 +26,8 @@ /** | ||
exports.fixture = function(req, res, next){ | ||
var batch = req.body.batch; | ||
if ('error' == batch[0]) return res.json(400, { error: { message: 'error' }}); | ||
res.json(200); | ||
exports.fixture = function (req, res, next) { | ||
var batch = req.body.batch | ||
if (batch[0] === 'error') { | ||
return res.json(400, { error: { message: 'error' } }) | ||
} | ||
res.json(200) | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
9
13
2
832633
23719
17
- Removedsuperagent-proxy@^1.0.0
- Removedagent-base@4.3.0(transitive)
- Removedast-types@0.16.1(transitive)
- Removedbytes@3.1.2(transitive)
- Removedco@4.6.0(transitive)
- Removeddata-uri-to-buffer@1.2.0(transitive)
- Removeddebug@3.1.0(transitive)
- Removeddeep-is@0.1.4(transitive)
- Removeddegenerator@1.0.4(transitive)
- Removeddepd@2.0.0(transitive)
- Removedes6-promise@4.2.8(transitive)
- Removedes6-promisify@5.0.0(transitive)
- Removedescodegen@1.14.3(transitive)
- Removedesprima@3.1.34.0.1(transitive)
- Removedestraverse@4.3.0(transitive)
- Removedesutils@2.0.3(transitive)
- Removedfast-levenshtein@2.0.6(transitive)
- Removedfile-uri-to-path@1.0.0(transitive)
- Removedftp@0.3.10(transitive)
- Removedget-uri@2.0.4(transitive)
- Removedhttp-errors@2.0.0(transitive)
- Removedhttp-proxy-agent@2.1.0(transitive)
- Removedhttps-proxy-agent@2.2.4(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedip@1.1.9(transitive)
- Removedisarray@0.0.1(transitive)
- Removedlevn@0.3.0(transitive)
- Removedlru-cache@4.1.5(transitive)
- Removednetmask@1.0.6(transitive)
- Removedoptionator@0.8.3(transitive)
- Removedpac-proxy-agent@2.0.2(transitive)
- Removedpac-resolver@3.0.0(transitive)
- Removedprelude-ls@1.1.2(transitive)
- Removedproxy-agent@2.3.1(transitive)
- Removedproxy-from-env@1.1.0(transitive)
- Removedpseudomap@1.0.2(transitive)
- Removedraw-body@2.5.2(transitive)
- Removedreadable-stream@1.1.14(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsetprototypeof@1.2.0(transitive)
- Removedsmart-buffer@1.1.15(transitive)
- Removedsocks@1.1.10(transitive)
- Removedsocks-proxy-agent@3.0.1(transitive)
- Removedsource-map@0.6.1(transitive)
- Removedstatuses@2.0.1(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedsuperagent-proxy@1.0.3(transitive)
- Removedthunkify@2.1.2(transitive)
- Removedtoidentifier@1.0.1(transitive)
- Removedtslib@2.6.3(transitive)
- Removedtype-check@0.3.2(transitive)
- Removedunpipe@1.0.0(transitive)
- Removedword-wrap@1.2.5(transitive)
- Removedxregexp@2.0.0(transitive)
- Removedyallist@2.1.2(transitive)
Updatedclone@^2.1.1
Updateddebug@^2.6.2
Updatedlodash@^4.17.4
Updatedsuperagent@^3.5.0