Comparing version 1.0.0-beta.8 to 1.0.0-beta.9
{ | ||
"name": "libhoney", | ||
"version": "1.0.0-beta.8", | ||
"version": "1.0.0-beta.9", | ||
"description": "Javascript library for sending data to Honeycomb", | ||
@@ -38,3 +38,4 @@ "bugs": "https://github.com/honeycombio/libhoney-js/issues", | ||
"mocha": "^3.0.2", | ||
"superagent-mocker": "^0.5.2" | ||
"superagent-mocker": "^0.5.2", | ||
"esdoc": "^0.5.2" | ||
}, | ||
@@ -41,0 +42,0 @@ "dependencies": { |
@@ -7,4 +7,2 @@ "use strict"; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
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. | ||
@@ -71,2 +69,10 @@ // Use of this source code is governed by the Apache License 2.0 | ||
/** | ||
* If set, specifies the timestamp associated with this event. If unset, | ||
* defaults to Date.now(); | ||
* | ||
* @type {Date} | ||
*/ | ||
this.timestamp = null; | ||
(0, _foreach2.default)(fields, function (v, k) { | ||
@@ -129,10 +135,3 @@ return _this.addField(k, v); | ||
value: function addField(name, val) { | ||
if ((typeof val === "undefined" ? "undefined" : _typeof(val)) === "object") { | ||
// JS reports typeof == object for a lot of things that we don't need additional processing to handle | ||
if (val === null || val instanceof Boolean || val instanceof Number || val instanceof Date || val instanceof String) { | ||
// these are fine | ||
} else { | ||
val = JSON.stringify(val); | ||
} | ||
} else if (val == undefined) { | ||
if (val == undefined) { | ||
val = null; | ||
@@ -139,0 +138,0 @@ } |
@@ -37,3 +37,2 @@ 'use strict'; | ||
var defaults = Object.freeze({ | ||
// host to send data to | ||
apiHost: "https://api.honeycomb.io/", | ||
@@ -57,9 +56,9 @@ | ||
// the maximum number of pending events we allow in our queue before they get batched | ||
// the maximum number of pending events we allow in our to-be-batched-and-transmitted queue before dropping them. | ||
pendingWorkCapacity: 10000, | ||
// the maximum number of s we enqueue before we drop. | ||
// the maximum number of responses we enqueue before we begin dropping them. | ||
maxResponseQueueSize: 1000, | ||
// if this is false, all sending is disabled. useful for disabling libhoney when testing | ||
// if this is set to true, all sending is disabled. useful for disabling libhoney when testing | ||
disabled: false | ||
@@ -69,3 +68,5 @@ }); | ||
/** | ||
* Represents a honeycomb context. Each honeycomb context has | ||
* libhoney aims to make it as easy as possible to create events and send them on into Honeycomb. | ||
* | ||
* See https://honeycomb.io/docs for background on this library. | ||
* @class | ||
@@ -78,5 +79,17 @@ */ | ||
/** | ||
* constructs a libhoney context. | ||
* Constructs a libhoney context in order to configure default behavior, | ||
* though each of its members (`apiHost`, `writeKey`, `dataset`, and | ||
* `sampleRate`) may in fact be overridden on a specific Builder or Event. | ||
* | ||
* @param {Object} [opts] overrides for the defaults | ||
* @param {string} [opts.apiHost=https://api.honeycomb.io] - Server host to receive Honeycomb events. | ||
* @param {string} opts.writeKey - Write key for your Honeycomb team. (Required) | ||
* @param {string} opts.dataset - Name of the dataset that should contain this event. The dataset will be created for your team if it doesn't already exist. | ||
* @param {number} [opts.sampleRate=1] - Sample rate of data. If set, causes us to send 1/sampleRate of events and drop the rest. | ||
* @param {number} [opts.batchSizeTrigger=50] - We send a batch to the API when this many outstanding events exist in our event queue. | ||
* @param {number} [opts.batchTimeTrigger=100] - We send a batch to the API after this many milliseconds have passed. | ||
* @param {number} [opts.maxConcurrentBatches=10] - We process batches concurrently to increase parallelism while sending. | ||
* @param {number} [opts.pendingWorkCapacity=10000] - The maximum number of pending events we allow to accumulate in our sending queue before dropping them. | ||
* @param {number} [opts.maxResponseQueueSize=1000] - The maximum number of responses we enqueue before dropping them. | ||
* @param {boolean} [opts.disabled=false] - Disable transmission of events to the specified `apiHost`, particularly useful for testing or development. | ||
* @constructor | ||
@@ -86,3 +99,5 @@ * @example | ||
* let honey = new Libhoney({ | ||
* sampleRate: 10 | ||
* writeKey: "YOUR_WRITE_KEY", | ||
* dataset: "honeycomb-js-example", | ||
* // disabled: true // uncomment when testing or in development | ||
* }); | ||
@@ -146,54 +161,8 @@ */ | ||
value: function sendEvent(event) { | ||
if (!this._usable) return; | ||
var timestamp = event.timestamp || Date.now(); | ||
if (typeof timestamp === 'string' || typeof timestamp === 'number') timestamp = new Date(timestamp); | ||
if (_typeof(event.data) !== 'object' || event.data === null) { | ||
console.error(".data must be an object"); | ||
var transmitEvent = this.validateEvent(event); | ||
if (!transmitEvent) { | ||
return; | ||
} | ||
var postData; | ||
try { | ||
postData = JSON.stringify(event.data); | ||
} catch (e) { | ||
console.error("error converting event data to JSON: " + e); | ||
return; | ||
} | ||
var apiHost = event.apiHost; | ||
if (typeof apiHost !== 'string' || apiHost === "") { | ||
console.error(".apiHost must be a non-empty string"); | ||
return; | ||
} | ||
var writeKey = event.writeKey; | ||
if (typeof writeKey !== 'string' || writeKey === "") { | ||
console.error(".writeKey must be a non-empty string"); | ||
return; | ||
} | ||
var dataset = event.dataset; | ||
if (typeof dataset !== 'string' || dataset === "") { | ||
console.error(".dataset must be a non-empty string"); | ||
return; | ||
} | ||
var sampleRate = event.sampleRate; | ||
if (typeof sampleRate !== 'number') { | ||
console.error(".sampleRate must be a number"); | ||
return; | ||
} | ||
var metadata = event.metadata; | ||
this._transmission.sendEvent({ | ||
timestamp: timestamp, | ||
apiHost: apiHost, | ||
postData: postData, | ||
writeKey: writeKey, | ||
dataset: dataset, | ||
sampleRate: sampleRate, | ||
metadata: metadata | ||
}); | ||
this._transmission.sendEvent(transmitEvent); | ||
} | ||
@@ -220,2 +189,21 @@ | ||
value: function sendPresampledEvent(event) { | ||
var transmitEvent = this.validateEvent(event); | ||
if (!transmitEvent) { | ||
return; | ||
} | ||
this._transmission.sendPresampledEvent(transmitEvent); | ||
} | ||
/** | ||
* validateEvent takes an event and validates its structure and contents. | ||
* | ||
* @returns {Object} the validated libhoney Event. May return undefined if | ||
* the event was invalid in some way or unable to be sent. | ||
* @private | ||
*/ | ||
}, { | ||
key: 'validateEvent', | ||
value: function validateEvent(event) { | ||
if (!this._usable) return; | ||
@@ -263,4 +251,3 @@ | ||
var metadata = event.metadata; | ||
this._transmission.sendPresampledEvent({ | ||
return { | ||
timestamp: timestamp, | ||
@@ -273,3 +260,3 @@ apiHost: apiHost, | ||
metadata: metadata | ||
}); | ||
}; | ||
} | ||
@@ -276,0 +263,0 @@ |
@@ -29,3 +29,3 @@ 'use strict'; | ||
var userAgent = "libhoney-js/1.0.0-beta.8"; | ||
var userAgent = "libhoney-js/1.0.0-beta.9"; | ||
@@ -32,0 +32,0 @@ var _global = typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : undefined; |
{ | ||
"name": "libhoney", | ||
"version": "1.0.0-beta.8", | ||
"version": "1.0.0-beta.9", | ||
"description": "Javascript library for sending data to Honeycomb", | ||
@@ -38,3 +38,4 @@ "bugs": "https://github.com/honeycombio/libhoney-js/issues", | ||
"mocha": "^3.0.2", | ||
"superagent-mocker": "^0.5.2" | ||
"superagent-mocker": "^0.5.2", | ||
"esdoc": "^0.5.2" | ||
}, | ||
@@ -41,0 +42,0 @@ "dependencies": { |
@@ -1,4 +0,4 @@ | ||
# libhoney [![Build Status](https://travis-ci.org/honeycombio/libhoney-js.svg?branch=master)](https://travis-ci.org/honeycombio/libhoney-js) | ||
# libhoney [![Build Status](https://travis-ci.org/honeycombio/libhoney-js.svg?branch=master)](https://travis-ci.org/honeycombio/libhoney-js) [![npm version](https://badge.fury.io/js/libhoney.svg)](https://badge.fury.io/js/libhoney) | ||
A node module for interacting with [Honeycomb](https://honeycomb.io). (See here for more information about [using Honeycomb](https://honeycomb.io/intro/) and [its libraries](https://honeycomb.io/docs/send-data/sdks).) | ||
A node module for interacting with [Honeycomb](https://honeycomb.io). (For more information, see the [documentation](https://honeycomb.io/docs/) and [JavaScript SDK guide](https://honeycomb.io/docs/connect/javascript).) | ||
@@ -15,3 +15,3 @@ **NOT** for use in browser-side JavaScript applications. Write keys are your auth tokens for sending data to Honeycomb and should be kept secure -- they're not per-site keys. Don't leave yourself vulnerable to malicious users. | ||
An API reference is available at https://honeycombio.github.io/libhoney-js/ | ||
An API reference is available at https://doc.esdoc.org/github.com/honeycombio/libhoney-js/ | ||
@@ -23,5 +23,5 @@ ## Example | ||
```js | ||
var libhoney = require('libhoney').default; | ||
import Libhoney from 'libhoney'; | ||
var hny = new libhoney({ | ||
let hny = new Libhoney({ | ||
writeKey: "YOUR_WRITE_KEY", | ||
@@ -28,0 +28,0 @@ dataset: "honeycomb-js-example" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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
60358
1126