@segment/analytics.js-integration-segmentio
Advanced tools
Comparing version 3.1.1 to 3.2.0
@@ -0,1 +1,8 @@ | ||
3.2.0 / 2016-09-01 | ||
================== | ||
* Add unbundled metadata (#17) | ||
* Add bundled integrations metadata to every request (#16) | ||
3.1.1 / 2016-07-22 | ||
@@ -2,0 +9,0 @@ ================== |
@@ -13,2 +13,3 @@ 'use strict'; | ||
var json = require('json3'); | ||
var keys = require('@ndhoule/keys'); | ||
var localstorage = require('yields-store'); | ||
@@ -39,3 +40,5 @@ var md5 = require('spark-md5').hash; | ||
.option('apiKey', '') | ||
.option('apiHost', 'api.segment.io/v1'); | ||
.option('apiHost', 'api.segment.io/v1') | ||
.option('addBundledMetadata', false) | ||
.option('unbundledIntegrations', []); | ||
@@ -177,2 +180,9 @@ /** | ||
msg.sentAt = new Date(); | ||
if (this.options.addBundledMetadata) { | ||
var bundled = keys(this.analytics.Integrations); | ||
msg._metadata = { | ||
bundled: bundled, | ||
unbundled: this.options.unbundledIntegrations | ||
}; | ||
} | ||
// add some randomness to the messageId checksum | ||
@@ -179,0 +189,0 @@ msg.messageId = 'ajs-' + md5(json.stringify(msg) + uuid()); |
{ | ||
"name": "@segment/analytics.js-integration-segmentio", | ||
"description": "The Segmentio analytics.js integration.", | ||
"version": "3.1.1", | ||
"version": "3.2.0", | ||
"keywords": [ | ||
@@ -27,2 +27,3 @@ "analytics.js", | ||
"@ndhoule/extend": "^2.0.0", | ||
"@ndhoule/keys": "^2.0.0", | ||
"@segment/ad-params": "^1.0.0", | ||
@@ -29,0 +30,0 @@ "@segment/analytics.js-integration": "^2.1.0", |
@@ -282,2 +282,45 @@ 'use strict'; | ||
}); | ||
describe('unbundling', function() { | ||
var segment; | ||
beforeEach(function() { | ||
var Analytics = analytics.constructor; | ||
var ajs = new Analytics(); | ||
segment = new Segment(options); | ||
ajs.use(Segment); | ||
ajs.use(integration('other')); | ||
ajs.add(segment); | ||
ajs.initialize({ other: {} }); | ||
}); | ||
it('should add a list of bundled integrations when `addBundledMetadata` is set', function() { | ||
segment.options.addBundledMetadata = true; | ||
segment.normalize(object); | ||
assert(object); | ||
assert(object._metadata); | ||
assert.deepEqual(object._metadata.bundled, [ | ||
'Segment.io', | ||
'other' | ||
]); | ||
}); | ||
it('should add a list of unbundled integrations when `addBundledMetadata` and `unbundledIntegrations` are set', function() { | ||
segment.options.addBundledMetadata = true; | ||
segment.options.unbundledIntegrations = [ 'other2' ]; | ||
segment.normalize(object); | ||
assert(object); | ||
assert(object._metadata); | ||
assert.deepEqual(object._metadata.unbundled, [ 'other2' ]); | ||
}); | ||
it('should not add _metadata when `addBundledMetadata` is unset', function() { | ||
segment.normalize(object); | ||
assert(object); | ||
assert(!object._metadata); | ||
}); | ||
}); | ||
}); | ||
@@ -488,2 +531,21 @@ }); | ||
it('should send a normalized payload', sinon.test(function() { | ||
var xhr = sinon.useFakeXMLHttpRequest(); | ||
var spy = sinon.spy(); | ||
xhr.onCreate = spy; | ||
var payload = { | ||
key1: 'value1', | ||
key2: 'value2' | ||
}; | ||
segment.normalize = function() { return payload; }; | ||
segment.send('/i', {}); | ||
assert(spy.calledOnce); | ||
var req = spy.getCall(0).args[0]; | ||
assert.strictEqual(req.requestBody, JSON.stringify(payload)); | ||
})); | ||
// FIXME(ndhoule): See note at `isPhantomJS` definition | ||
@@ -490,0 +552,0 @@ (isPhantomJS ? xdescribe : describe)('e2e tests', function() { |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
41959
941
16
1
+ Added@ndhoule/keys@^2.0.0