Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

libhoney

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libhoney - npm Package Compare versions

Comparing version 1.0.0-beta.9 to 1.0.0-beta.10

7

docs/package.json
{
"name": "libhoney",
"version": "1.0.0-beta.9",
"version": "1.0.0-beta.10",
"description": "Javascript library for sending data to Honeycomb",

@@ -30,3 +30,3 @@ "bugs": "https://github.com/honeycombio/libhoney-js/issues",

"babel-register": "^6.11.6",
"esdoc": "^0.4.8",
"esdoc": "^0.5.2",
"gulp": "^3.9.1",

@@ -39,4 +39,3 @@ "gulp-babel": "^6.1.2",

"mocha": "^3.0.2",
"superagent-mocker": "^0.5.2",
"esdoc": "^0.5.2"
"superagent-mocker": "^0.5.2"
},

@@ -43,0 +42,0 @@ "dependencies": {

@@ -13,4 +13,2 @@ 'use strict';

var _transmission2 = _interopRequireDefault(_transmission);
var _builder = require('./builder');

@@ -32,2 +30,3 @@

// jshint esversion: 6
/**

@@ -109,3 +108,3 @@ * @module

_this._transmission = getAndInitTransmission(_this._options.transmission, _this._options);
_this._usable = _this._transmission != null;
_this._usable = _this._transmission !== null;
_this._builder = new _builder2.default(_this);

@@ -124,8 +123,8 @@

key: '_responseCallback',
value: function _responseCallback(response) {
value: function _responseCallback(responses) {
var queue = this._responseQueue;
if (queue.length < this._options.maxResponseQueueSize) {
queue.push(response);
this._responseQueue = this._responseQueue.concat(responses);
}
this.emit("response", queue);
this.emit("response", this._responseQueue);
}

@@ -206,3 +205,3 @@

value: function validateEvent(event) {
if (!this._usable) return;
if (!this._usable) return null;

@@ -214,3 +213,3 @@ var timestamp = event.timestamp || Date.now();

console.error(".data must be an object");
return;
return null;
}

@@ -222,3 +221,3 @@ var postData;

console.error("error converting event data to JSON: " + e);
return;
return null;
}

@@ -229,3 +228,3 @@

console.error(".apiHost must be a non-empty string");
return;
return null;
}

@@ -236,3 +235,3 @@

console.error(".writeKey must be a non-empty string");
return;
return null;
}

@@ -243,3 +242,3 @@

console.error(".dataset must be a non-empty string");
return;
return null;
}

@@ -250,8 +249,7 @@

console.error(".sampleRate must be a number");
return;
return null;
}
var metadata = event.metadata;
return {
timestamp: timestamp,
return new _transmission.ValidatedEvent({ timestamp: timestamp,
apiHost: apiHost,

@@ -262,4 +260,3 @@ postData: postData,

sampleRate: sampleRate,
metadata: metadata
};
metadata: metadata });
}

@@ -480,6 +477,6 @@

if (transmission === "base") {
transmission = _transmission2.default;
transmission = _transmission.Transmission;
} else if (transmission === "worker") {
console.warn("worker implementation not ready yet. using base implementation");
transmission = _transmission2.default;
transmission = _transmission.Transmission;
} else {

@@ -495,3 +492,3 @@ throw new Error('unknown transmission implementation "' + transmission + '".');

} catch (e) {
if (transmission == _transmission2.default) {
if (transmission == _transmission.Transmission) {
throw new Error("unable to initialize base transmission implementation.", e);

@@ -502,3 +499,3 @@ }

try {
transmission = new _transmission2.default(options);
transmission = new _transmission.Transmission(options);
} catch (e) {

@@ -505,0 +502,0 @@ throw new Error("unable to initialize base transmission implementation.", e);

@@ -6,17 +6,9 @@ 'use strict';

});
exports.Transmission = exports.ValidatedEvent = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _urljoin = require('urljoin');
var _urljoin2 = _interopRequireDefault(_urljoin);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
// Copyright 2016 Hound Technology, Inc. All rights reserved.
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); // Copyright 2016 Hound Technology, Inc. All rights reserved.
// Use of this source code is governed by the Apache License 2.0
// license that can be found in the LICENSE file.
// jshint esversion: 6
/* global require, window, global */

@@ -27,7 +19,18 @@

*/
var superagent = require('superagent');
var userAgent = "libhoney-js/1.0.0-beta.9";
var _superagent = require('superagent');
var _superagent2 = _interopRequireDefault(_superagent);
var _urljoin = require('urljoin');
var _urljoin2 = _interopRequireDefault(_urljoin);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var userAgent = "libhoney-js/1.0.0-beta.10";
var _global = typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : undefined;

@@ -55,2 +58,65 @@

var partition = function partition(arr, keyfn, createfn, addfn) {
var result = Object.create(null);
arr.forEach(function (v) {
var key = keyfn(v);
if (!result[key]) {
result[key] = createfn(v);
} else {
addfn(result[key], v);
}
});
return result;
};
var BatchEndpointAggregator = function () {
function BatchEndpointAggregator(events) {
_classCallCheck(this, BatchEndpointAggregator);
this.batches = partition(events,
/* keyfn */
function (ev) {
return ev.apiHost + '_' + ev.writeKey + '_' + ev.dataset;
},
/* createfn */
function (ev) {
return {
apiHost: ev.apiHost,
writeKey: ev.writeKey,
dataset: ev.dataset,
events: [ev]
};
},
/* addfn */
function (batch, ev) {
return batch.events.push(ev);
});
}
_createClass(BatchEndpointAggregator, [{
key: 'encodeBatchEvents',
value: function encodeBatchEvents(events) {
var first = true;
var numEncoded = 0;
var encodedEvents = events.reduce(function (acc, ev) {
try {
var encodedEvent = ev.toJSON(); // directly call toJSON, not JSON.stringify, because the latter wraps it in an additional set of quotes
numEncoded++;
var newAcc = acc + (!first ? "," : "") + encodedEvent;
first = false;
return newAcc;
} catch (e) {
ev.encodeError = e;
return acc;
}
}, "");
var encoded = "[" + encodedEvents + "]";
return { encoded: encoded, numEncoded: numEncoded };
}
}]);
return BatchEndpointAggregator;
}();
/**

@@ -60,3 +126,50 @@ * @private

var Transmission = function () {
var ValidatedEvent = exports.ValidatedEvent = function () {
function ValidatedEvent(_ref) {
var timestamp = _ref.timestamp,
apiHost = _ref.apiHost,
postData = _ref.postData,
writeKey = _ref.writeKey,
dataset = _ref.dataset,
sampleRate = _ref.sampleRate,
metadata = _ref.metadata;
_classCallCheck(this, ValidatedEvent);
this.timestamp = timestamp;
this.apiHost = apiHost;
this.postData = postData;
this.writeKey = writeKey;
this.dataset = dataset;
this.sampleRate = sampleRate;
this.metadata = metadata;
}
_createClass(ValidatedEvent, [{
key: 'toJSON',
value: function toJSON() {
var fields = [];
if (this.timestamp) {
fields.push('"time":' + JSON.stringify(this.timestamp));
}
if (this.sampleRate) {
fields.push('"samplerate":' + JSON.stringify(this.sampleRate));
}
if (this.postData) {
fields.push('"data":' + this.postData);
}
return '{' + fields.join(",") + '}';
}
}]);
return ValidatedEvent;
}();
/**
* @private
*/
var Transmission = exports.Transmission = function () {
function Transmission(options) {

@@ -98,6 +211,6 @@ _classCallCheck(this, Transmission);

value: function _droppedCallback(ev, reason) {
this._responseCallback({
this._responseCallback([{
metadata: ev.metadata,
error: new Error(reason)
});
}]);
}

@@ -146,2 +259,4 @@ }, {

var batchAgg = new BatchEndpointAggregator(batch);
var finishBatch = function finishBatch() {

@@ -160,17 +275,61 @@ _this._batchCount--;

eachPromise(batch, function (ev) {
var url = (0, _urljoin2.default)(ev.apiHost, "/1/events", ev.dataset);
var req = superagent.post(url);
var batches = Object.keys(batchAgg.batches).map(function (k) {
return batchAgg.batches[k];
});
eachPromise(batches, function (batch) {
var url = (0, _urljoin2.default)(batch.apiHost, "/1/batch", batch.dataset);
var req = _superagent2.default.post(url);
var _batchAgg$encodeBatch = batchAgg.encodeBatchEvents(batch.events),
encoded = _batchAgg$encodeBatch.encoded,
numEncoded = _batchAgg$encodeBatch.numEncoded;
return new Promise(function (resolve) {
// if we failed to encode any of the events, no point in sending anything to honeycomb
if (numEncoded === 0) {
_this._responseCallback(batch.events.map(function (ev) {
return {
metadata: ev.metadata,
error: ev.encodeError
};
}));
resolve();
return;
}
var start = Date.now();
req.set('X-Hny-Team', ev.writeKey).set('X-Hny-Samplerate', ev.sampleRate).set('X-Hny-Event-Time', ev.timestamp.toISOString()).set('User-Agent', userAgent).type("json").send(ev.postData).end(function (err, res) {
// call a callback here (in our init options) so it can be used both in the node, browser, and worker contexts.
_this._responseCallback({
status_code: res ? res.status : err.status,
duration: Date.now() - start,
metadata: ev.metadata,
error: err
});
req.set('X-Hny-Team', batch.writeKey).set('User-Agent', userAgent).type("json").send(encoded).end(function (err, res) {
var end = Date.now();
if (err) {
_this._responseCallback(batch.events.map(function (ev) {
return {
status_code: ev.encodeError ? undefined : err.status,
duration: end - start,
metadata: ev.metadata,
error: ev.encodeError || err
};
}));
} else {
var response = JSON.parse(res.text);
var respIdx = 0;
_this._responseCallback(batch.events.map(function (ev) {
if (ev.encodeError) {
return {
duration: end - start,
metadata: ev.metadata,
error: ev.encodeError
};
} else {
var _res = response[respIdx++];
return {
status_code: _res.status,
duration: end - start,
metadata: ev.metadata,
error: _res.err
};
}
}));
}
// we resolve unconditionally to continue the iteration in eachSeries. errors will cause

@@ -215,4 +374,2 @@ // the event to be re-enqueued/dropped.

return Transmission;
}();
exports.default = Transmission;
}();
{
"name": "libhoney",
"version": "1.0.0-beta.9",
"version": "1.0.0-beta.10",
"description": "Javascript library for sending data to Honeycomb",

@@ -30,3 +30,3 @@ "bugs": "https://github.com/honeycombio/libhoney-js/issues",

"babel-register": "^6.11.6",
"esdoc": "^0.4.8",
"esdoc": "^0.5.2",
"gulp": "^3.9.1",

@@ -39,4 +39,3 @@ "gulp-babel": "^6.1.2",

"mocha": "^3.0.2",
"superagent-mocker": "^0.5.2",
"esdoc": "^0.5.2"
"superagent-mocker": "^0.5.2"
},

@@ -43,0 +42,0 @@ "dependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc