Socket
Socket
Sign inDemoInstall

@segment/analytics-node

Package Overview
Dependencies
Maintainers
223
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@segment/analytics-node - npm Package Compare versions

Comparing version 0.0.1-rc.1 to 0.0.1-rc.2

7

CHANGELOG.md

@@ -7,2 +7,9 @@ # @segment/analytics-node

- Updated dependencies [[`409cae4`](https://github.com/segmentio/analytics-next/commit/409cae4b9ac404277aa44bab7428186129b42a35)]:
- @segment/analytics-core@1.1.1
## 0.0.1
### Patch Changes
- [#593](https://github.com/segmentio/analytics-next/pull/593) [`7b5d3df`](https://github.com/segmentio/analytics-next/commit/7b5d3df8d7d8e479d1dda4557297baedb3cdcf6f) Thanks [@silesky](https://github.com/silesky)! - Revise NodeJS public API. Fix core so Node SDK waits for plugins to be registered before dispatching any events.

@@ -9,0 +16,0 @@

4

dist/cjs/package.json
{
"name": "@segment/analytics-node",
"version": "0.0.1-rc.1",
"version": "0.0.1-rc.2",
"main": "./dist/cjs/src/index.js",

@@ -35,3 +35,3 @@ "module": "./dist/esm/src/index.js",

"dependencies": {
"@segment/analytics-core": "1.1.0",
"@segment/analytics-core": "1.1.1",
"node-fetch": "^2.6.7",

@@ -38,0 +38,0 @@ "tslib": "^2.4.0"

@@ -20,4 +20,4 @@ "use strict";

tslib_1.__extends(NodePriorityQueue, _super);
function NodePriorityQueue(maxAttempts) {
return _super.call(this, maxAttempts, []) || this;
function NodePriorityQueue() {
return _super.call(this, 3, []) || this;
}

@@ -45,3 +45,5 @@ // do not use an internal "seen" map

_this._eventFactory = new analytics_core_1.EventFactory();
_this.queue = new analytics_core_1.EventQueue(new NodePriorityQueue(3));
_this.queue = new analytics_core_1.EventQueue(new NodePriorityQueue());
var flushInterval = (_a = settings.flushInterval) !== null && _a !== void 0 ? _a : 10000;
_this._closeAndFlushDefaultTimeout = flushInterval * 1.25; // add arbitrary multiplier in case an event is in a plugin.
_this.ready = _this.register((0, segmentio_1.configureNodePlugin)({

@@ -51,5 +53,5 @@ writeKey: settings.writeKey,

path: settings.path,
maxAttempts: (_a = settings.maxAttempts) !== null && _a !== void 0 ? _a : 4,
maxEventsInBatch: (_b = settings.maxEventsInBatch) !== null && _b !== void 0 ? _b : 15,
maxWaitTimeInMs: (_c = settings.maxWaitTimeInMs) !== null && _c !== void 0 ? _c : 1000,
maxRetries: (_b = settings.maxRetries) !== null && _b !== void 0 ? _b : 3,
maxEventsInBatch: (_c = settings.maxEventsInBatch) !== null && _c !== void 0 ? _c : 15,
flushInterval: flushInterval,
})).then(function () { return undefined; });

@@ -74,3 +76,3 @@ _this.emit('initialize', settings);

var _this = this;
var _b = _a === void 0 ? {} : _a, timeout = _b.timeout;
var _b = _a === void 0 ? {} : _a, _c = _b.timeout, timeout = _c === void 0 ? this._closeAndFlushDefaultTimeout : _c;
this._isClosed = true;

@@ -77,0 +79,0 @@ var promise = new Promise(function (resolve) {

@@ -19,6 +19,6 @@ "use strict";

function Publisher(_a) {
var host = _a.host, path = _a.path, maxAttempts = _a.maxAttempts, maxEventsInBatch = _a.maxEventsInBatch, maxWaitTimeInMs = _a.maxWaitTimeInMs, writeKey = _a.writeKey;
this._maxAttempts = Math.max(maxAttempts, 1);
var host = _a.host, path = _a.path, maxRetries = _a.maxRetries, maxEventsInBatch = _a.maxEventsInBatch, flushInterval = _a.flushInterval, writeKey = _a.writeKey;
this._maxRetries = maxRetries;
this._maxEventsInBatch = Math.max(maxEventsInBatch, 1);
this._maxWaitTimeInMs = maxWaitTimeInMs;
this._flushInterval = flushInterval;
this._auth = Buffer.from("".concat(writeKey, ":")).toString('base64');

@@ -40,3 +40,3 @@ this._url = (0, create_url_1.tryCreateFormattedUrl)(host !== null && host !== void 0 ? host : 'https://api.segment.io', path !== null && path !== void 0 ? path : '/v1/batch');

}
}, this._maxWaitTimeInMs);
}, this._flushInterval);
return batch;

@@ -106,3 +106,3 @@ };

payload = JSON.stringify({ batch: events });
maxAttempts = this._maxAttempts;
maxAttempts = this._maxRetries + 1;
currentAttempt = 0;

@@ -109,0 +109,0 @@ _a.label = 1;

{
"name": "@segment/analytics-node",
"version": "0.0.1-rc.1",
"version": "0.0.1-rc.2",
"main": "./dist/cjs/src/index.js",

@@ -35,3 +35,3 @@ "module": "./dist/esm/src/index.js",

"dependencies": {
"@segment/analytics-core": "1.1.0",
"@segment/analytics-core": "1.1.1",
"node-fetch": "^2.6.7",

@@ -38,0 +38,0 @@ "tslib": "^2.4.0"

@@ -17,4 +17,4 @@ import { __assign, __awaiter, __extends, __generator } from "tslib";

__extends(NodePriorityQueue, _super);
function NodePriorityQueue(maxAttempts) {
return _super.call(this, maxAttempts, []) || this;
function NodePriorityQueue() {
return _super.call(this, 3, []) || this;
}

@@ -42,3 +42,5 @@ // do not use an internal "seen" map

_this._eventFactory = new EventFactory();
_this.queue = new EventQueue(new NodePriorityQueue(3));
_this.queue = new EventQueue(new NodePriorityQueue());
var flushInterval = (_a = settings.flushInterval) !== null && _a !== void 0 ? _a : 10000;
_this._closeAndFlushDefaultTimeout = flushInterval * 1.25; // add arbitrary multiplier in case an event is in a plugin.
_this.ready = _this.register(configureNodePlugin({

@@ -48,5 +50,5 @@ writeKey: settings.writeKey,

path: settings.path,
maxAttempts: (_a = settings.maxAttempts) !== null && _a !== void 0 ? _a : 4,
maxEventsInBatch: (_b = settings.maxEventsInBatch) !== null && _b !== void 0 ? _b : 15,
maxWaitTimeInMs: (_c = settings.maxWaitTimeInMs) !== null && _c !== void 0 ? _c : 1000,
maxRetries: (_b = settings.maxRetries) !== null && _b !== void 0 ? _b : 3,
maxEventsInBatch: (_c = settings.maxEventsInBatch) !== null && _c !== void 0 ? _c : 15,
flushInterval: flushInterval,
})).then(function () { return undefined; });

@@ -71,3 +73,3 @@ _this.emit('initialize', settings);

var _this = this;
var _b = _a === void 0 ? {} : _a, timeout = _b.timeout;
var _b = _a === void 0 ? {} : _a, _c = _b.timeout, timeout = _c === void 0 ? this._closeAndFlushDefaultTimeout : _c;
this._isClosed = true;

@@ -74,0 +76,0 @@ var promise = new Promise(function (resolve) {

@@ -16,6 +16,6 @@ import { __awaiter, __generator } from "tslib";

function Publisher(_a) {
var host = _a.host, path = _a.path, maxAttempts = _a.maxAttempts, maxEventsInBatch = _a.maxEventsInBatch, maxWaitTimeInMs = _a.maxWaitTimeInMs, writeKey = _a.writeKey;
this._maxAttempts = Math.max(maxAttempts, 1);
var host = _a.host, path = _a.path, maxRetries = _a.maxRetries, maxEventsInBatch = _a.maxEventsInBatch, flushInterval = _a.flushInterval, writeKey = _a.writeKey;
this._maxRetries = maxRetries;
this._maxEventsInBatch = Math.max(maxEventsInBatch, 1);
this._maxWaitTimeInMs = maxWaitTimeInMs;
this._flushInterval = flushInterval;
this._auth = Buffer.from("".concat(writeKey, ":")).toString('base64');

@@ -37,3 +37,3 @@ this._url = tryCreateFormattedUrl(host !== null && host !== void 0 ? host : 'https://api.segment.io', path !== null && path !== void 0 ? path : '/v1/batch');

}
}, this._maxWaitTimeInMs);
}, this._flushInterval);
return batch;

@@ -103,3 +103,3 @@ };

payload = JSON.stringify({ batch: events });
maxAttempts = this._maxAttempts;
maxAttempts = this._maxRetries + 1;
currentAttempt = 0;

@@ -106,0 +106,0 @@ _a.label = 1;

@@ -37,2 +37,3 @@ import { EventProperties, Traits, Emitter, CoreAnalytics, CoreContext, CorePlugin, EventQueue, CoreOptions, Callback, CoreSegmentEvent, CoreEmitterContract } from '@segment/analytics-core';

private _pendingEvents;
private readonly _closeAndFlushDefaultTimeout;
queue: EventQueue;

@@ -48,3 +49,3 @@ ready: Promise<void>;

closeAndFlush({ timeout, }?: {
/** Set a maximum time permitted to wait before resolving. Default = no maximum. */
/** Set a maximum time permitted to wait before resolving. */
timeout?: number;

@@ -51,0 +52,0 @@ }): Promise<void>;

@@ -20,5 +20,5 @@ import { CorePlugin } from '@segment/analytics-core';

/**
* The number of times to try flushing a batch. Default: 4
* The number of times to retry flushing a batch. Default: 3
*/
maxAttempts?: number;
maxRetries?: number;
/**

@@ -29,7 +29,7 @@ * The number of messages to enqueue before flushing. Default: 15

/**
* The number of milliseconds to wait before flushing the queue automatically. Default: 1000
* The number of milliseconds to wait before flushing the queue automatically. Default: 10000
*/
maxWaitTimeInMs?: number;
flushInterval?: number;
}
export declare const validateSettings: (settings: AnalyticsSettings) => void;
//# sourceMappingURL=settings.d.ts.map

@@ -5,5 +5,5 @@ import { CoreContext } from '@segment/analytics-core';

path?: string;
maxWaitTimeInMs: number;
flushInterval: number;
maxEventsInBatch: number;
maxAttempts: number;
maxRetries: number;
writeKey: string;

@@ -17,8 +17,8 @@ }

private batch?;
private _maxWaitTimeInMs;
private _flushInterval;
private _maxEventsInBatch;
private _maxAttempts;
private _maxRetries;
private _auth;
private _url;
constructor({ host, path, maxAttempts, maxEventsInBatch, maxWaitTimeInMs, writeKey, }: PublisherProps);
constructor({ host, path, maxRetries, maxEventsInBatch, flushInterval, writeKey, }: PublisherProps);
private createBatch;

@@ -25,0 +25,0 @@ private clearBatch;

{
"name": "@segment/analytics-node",
"version": "0.0.1-rc.1",
"version": "0.0.1-rc.2",
"main": "./dist/cjs/src/index.js",

@@ -35,3 +35,3 @@ "module": "./dist/esm/src/index.js",

"dependencies": {
"@segment/analytics-core": "1.1.0",
"@segment/analytics-core": "1.1.1",
"node-fetch": "^2.6.7",

@@ -38,0 +38,0 @@ "tslib": "^2.4.0"

@@ -41,4 +41,15 @@

## Complete Settings / Configuration
See [settings interface](src/app/settings.ts).
See complete list of settings in the [AnalyticsSettings interface](src/app/settings.ts).
```ts
new Analytics({
writeKey: '<MY_WRITE_KEY>',
host: 'https://api.segment.io',
path: '/v1/batch',
flushInterval: 10000,
plugins: [plugin1, plugin2],
// ... and more!
})
```
## Graceful Shutdown

@@ -45,0 +56,0 @@ ### Avoid losing events on exit!

@@ -49,4 +49,4 @@ import {

class NodePriorityQueue extends PriorityQueue<Context> {
constructor(maxAttempts: number) {
super(maxAttempts, [])
constructor() {
super(3, [])
}

@@ -77,2 +77,3 @@ // do not use an internal "seen" map

private _pendingEvents = 0
private readonly _closeAndFlushDefaultTimeout: number

@@ -87,4 +88,8 @@ queue: EventQueue

this._eventFactory = new EventFactory()
this.queue = new EventQueue(new NodePriorityQueue(3))
this.queue = new EventQueue(new NodePriorityQueue())
const flushInterval = settings.flushInterval ?? 10000
this._closeAndFlushDefaultTimeout = flushInterval * 1.25 // add arbitrary multiplier in case an event is in a plugin.
this.ready = this.register(

@@ -95,5 +100,5 @@ configureNodePlugin({

path: settings.path,
maxAttempts: settings.maxAttempts ?? 4,
maxRetries: settings.maxRetries ?? 3,
maxEventsInBatch: settings.maxEventsInBatch ?? 15,
maxWaitTimeInMs: settings.maxWaitTimeInMs ?? 1000,
flushInterval,
})

@@ -117,5 +122,5 @@ ).then(() => undefined)

public closeAndFlush({
timeout,
timeout = this._closeAndFlushDefaultTimeout,
}: {
/** Set a maximum time permitted to wait before resolving. Default = no maximum. */
/** Set a maximum time permitted to wait before resolving. */
timeout?: number

@@ -122,0 +127,0 @@ } = {}): Promise<void> {

@@ -21,5 +21,5 @@ import { CorePlugin, ValidationError } from '@segment/analytics-core'

/**
* The number of times to try flushing a batch. Default: 4
* The number of times to retry flushing a batch. Default: 3
*/
maxAttempts?: number
maxRetries?: number
/**

@@ -30,5 +30,5 @@ * The number of messages to enqueue before flushing. Default: 15

/**
* The number of milliseconds to wait before flushing the queue automatically. Default: 1000
* The number of milliseconds to wait before flushing the queue automatically. Default: 10000
*/
maxWaitTimeInMs?: number
flushInterval?: number
}

@@ -35,0 +35,0 @@

@@ -21,5 +21,5 @@ import { backoff, CoreContext } from '@segment/analytics-core'

path?: string
maxWaitTimeInMs: number
flushInterval: number
maxEventsInBatch: number
maxAttempts: number
maxRetries: number
writeKey: string

@@ -35,5 +35,5 @@ }

private _maxWaitTimeInMs: number
private _flushInterval: number
private _maxEventsInBatch: number
private _maxAttempts: number
private _maxRetries: number
private _auth: string

@@ -45,10 +45,10 @@ private _url: string

path,
maxAttempts,
maxRetries,
maxEventsInBatch,
maxWaitTimeInMs,
flushInterval,
writeKey,
}: PublisherProps) {
this._maxAttempts = Math.max(maxAttempts, 1)
this._maxRetries = maxRetries
this._maxEventsInBatch = Math.max(maxEventsInBatch, 1)
this._maxWaitTimeInMs = maxWaitTimeInMs
this._flushInterval = flushInterval
this._auth = Buffer.from(`${writeKey}:`).toString('base64')

@@ -73,3 +73,3 @@ this._url = tryCreateFormattedUrl(

}
}, this._maxWaitTimeInMs)
}, this._flushInterval)
return batch

@@ -140,3 +140,3 @@ }

const payload = JSON.stringify({ batch: events })
const maxAttempts = this._maxAttempts
const maxAttempts = this._maxRetries + 1

@@ -143,0 +143,0 @@ let currentAttempt = 0

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

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

Sorry, the diff of this file is not supported yet

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