Socket
Socket
Sign inDemoInstall

@segment/analytics-node

Package Overview
Dependencies
Maintainers
300
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 1.2.0 to 1.3.0

29

dist/cjs/app/analytics-node.js

@@ -19,2 +19,3 @@ "use strict";

this._pendingEvents = 0;
this._isFlushing = false;
(0, settings_1.validateSettings)(settings);

@@ -52,4 +53,22 @@ this._eventFactory = new event_factory_1.NodeEventFactory();

closeAndFlush({ timeout = this._closeAndFlushDefaultTimeout, } = {}) {
this._publisher.flushAfterClose(this._pendingEvents);
this._isClosed = true;
return this.flush({ timeout, close: true });
}
/**
* Call this method to flush all existing events..
* This method also waits for any event method-specific callbacks to be triggered,
* and any of their subsequent promises to be resolved/rejected.
*/
async flush({ timeout, close = false, } = {}) {
if (this._isFlushing) {
// if we're already flushing, then we don't need to do anything
console.warn('Overlapping flush calls detected. Please wait for the previous flush to finish before calling .flush again');
return;
}
else {
this._isFlushing = true;
}
if (close) {
this._isClosed = true;
}
this._publisher.flush(this._pendingEvents);
const promise = new Promise((resolve) => {

@@ -60,4 +79,8 @@ if (!this._pendingEvents) {

else {
this.once('drained', () => resolve());
this.once('drained', () => {
resolve();
});
}
}).finally(() => {
this._isFlushing = false;
});

@@ -64,0 +87,0 @@ return timeout ? (0, analytics_core_1.pTimeout)(promise, timeout).catch(() => undefined) : promise;

2

dist/cjs/generated/version.js

@@ -5,3 +5,3 @@ "use strict";

// This file is generated.
exports.version = '1.2.0';
exports.version = '1.3.0';
//# sourceMappingURL=version.js.map

@@ -24,3 +24,3 @@ "use strict";

name: 'Segment.io',
type: 'after',
type: 'destination',
version: '1.0.0',

@@ -27,0 +27,0 @@ isLoaded: () => true,

@@ -47,8 +47,8 @@ "use strict";

}
flushAfterClose(pendingItemsCount) {
flush(pendingItemsCount) {
if (!pendingItemsCount) {
// if number of pending items is 0, there will never be anything else entering the batch, since the app is closed.
// if number of pending items is 0, there is nothing to flush
return;
}
this._closeAndFlushPendingItemsCount = pendingItemsCount;
this._flushPendingItemsCount = pendingItemsCount;
// if batch is empty, there's nothing to flush, and when things come in, enqueue will handle them.

@@ -90,3 +90,3 @@ if (!this._batch)

if (addStatus.success) {
const isExpectingNoMoreItems = batch.length === this._closeAndFlushPendingItemsCount;
const isExpectingNoMoreItems = batch.length === this._flushPendingItemsCount;
const isFull = batch.length === this._flushAt;

@@ -107,3 +107,3 @@ if (isFull || isExpectingNoMoreItems) {

if (fbAddStatus.success) {
const isExpectingNoMoreItems = fallbackBatch.length === this._closeAndFlushPendingItemsCount;
const isExpectingNoMoreItems = fallbackBatch.length === this._flushPendingItemsCount;
if (isExpectingNoMoreItems) {

@@ -124,4 +124,4 @@ this.send(fallbackBatch).catch(noop);

async send(batch) {
if (this._closeAndFlushPendingItemsCount) {
this._closeAndFlushPendingItemsCount -= batch.length;
if (this._flushPendingItemsCount) {
this._flushPendingItemsCount -= batch.length;
}

@@ -128,0 +128,0 @@ const events = batch.getEvents();

@@ -16,2 +16,3 @@ import { bindAll, pTimeout } from '@segment/analytics-core';

this._pendingEvents = 0;
this._isFlushing = false;
validateSettings(settings);

@@ -49,4 +50,22 @@ this._eventFactory = new NodeEventFactory();

closeAndFlush({ timeout = this._closeAndFlushDefaultTimeout, } = {}) {
this._publisher.flushAfterClose(this._pendingEvents);
this._isClosed = true;
return this.flush({ timeout, close: true });
}
/**
* Call this method to flush all existing events..
* This method also waits for any event method-specific callbacks to be triggered,
* and any of their subsequent promises to be resolved/rejected.
*/
async flush({ timeout, close = false, } = {}) {
if (this._isFlushing) {
// if we're already flushing, then we don't need to do anything
console.warn('Overlapping flush calls detected. Please wait for the previous flush to finish before calling .flush again');
return;
}
else {
this._isFlushing = true;
}
if (close) {
this._isClosed = true;
}
this._publisher.flush(this._pendingEvents);
const promise = new Promise((resolve) => {

@@ -57,4 +76,8 @@ if (!this._pendingEvents) {

else {
this.once('drained', () => resolve());
this.once('drained', () => {
resolve();
});
}
}).finally(() => {
this._isFlushing = false;
});

@@ -61,0 +84,0 @@ return timeout ? pTimeout(promise, timeout).catch(() => undefined) : promise;

// This file is generated.
export const version = '1.2.0';
export const version = '1.3.0';
//# sourceMappingURL=version.js.map

@@ -21,3 +21,3 @@ import { Publisher } from './publisher';

name: 'Segment.io',
type: 'after',
type: 'destination',
version: '1.0.0',

@@ -24,0 +24,0 @@ isLoaded: () => true,

@@ -44,8 +44,8 @@ import { backoff } from '@segment/analytics-core';

}
flushAfterClose(pendingItemsCount) {
flush(pendingItemsCount) {
if (!pendingItemsCount) {
// if number of pending items is 0, there will never be anything else entering the batch, since the app is closed.
// if number of pending items is 0, there is nothing to flush
return;
}
this._closeAndFlushPendingItemsCount = pendingItemsCount;
this._flushPendingItemsCount = pendingItemsCount;
// if batch is empty, there's nothing to flush, and when things come in, enqueue will handle them.

@@ -87,3 +87,3 @@ if (!this._batch)

if (addStatus.success) {
const isExpectingNoMoreItems = batch.length === this._closeAndFlushPendingItemsCount;
const isExpectingNoMoreItems = batch.length === this._flushPendingItemsCount;
const isFull = batch.length === this._flushAt;

@@ -104,3 +104,3 @@ if (isFull || isExpectingNoMoreItems) {

if (fbAddStatus.success) {
const isExpectingNoMoreItems = fallbackBatch.length === this._closeAndFlushPendingItemsCount;
const isExpectingNoMoreItems = fallbackBatch.length === this._flushPendingItemsCount;
if (isExpectingNoMoreItems) {

@@ -121,4 +121,4 @@ this.send(fallbackBatch).catch(noop);

async send(batch) {
if (this._closeAndFlushPendingItemsCount) {
this._closeAndFlushPendingItemsCount -= batch.length;
if (this._flushPendingItemsCount) {
this._flushPendingItemsCount -= batch.length;
}

@@ -125,0 +125,0 @@ const events = batch.getEvents();

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

import { NodeEmitter } from './emitter';
import { AliasParams, GroupParams, IdentifyParams, PageParams, TrackParams, Plugin } from './types';
import { AliasParams, GroupParams, IdentifyParams, PageParams, TrackParams, Plugin, FlushParams, CloseAndFlushParams } from './types';
export declare class Analytics extends NodeEmitter implements CoreAnalytics {

@@ -13,2 +13,3 @@ private readonly _eventFactory;

private readonly _publisher;
private _isFlushing;
private readonly _queue;

@@ -23,6 +24,9 @@ ready: Promise<void>;

*/
closeAndFlush({ timeout, }?: {
/** Set a maximum time permitted to wait before resolving. */
timeout?: number;
}): Promise<void>;
closeAndFlush({ timeout, }?: CloseAndFlushParams): Promise<void>;
/**
* Call this method to flush all existing events..
* This method also waits for any event method-specific callbacks to be triggered,
* and any of their subsequent promises to be resolved/rejected.
*/
flush({ timeout, close, }?: FlushParams): Promise<void>;
private _dispatch;

@@ -29,0 +33,0 @@ /**

@@ -64,2 +64,18 @@ import type { GroupTraits, UserTraits, CoreExtraContext, EventProperties, Integrations, Timestamp } from '@segment/analytics-core';

} & IdentityOptions;
export type FlushParams = {
/**
* Max time in milliseconds to wait until the resulting promise resolves.
*/
timeout?: number;
/**
* If true, will prevent new events from entering the pipeline. Default: false
*/
close?: boolean;
};
export type CloseAndFlushParams = {
/**
* Max time in milliseconds to wait until the resulting promise resolves.
*/
timeout?: FlushParams['timeout'];
};
//# sourceMappingURL=params.d.ts.map

@@ -1,2 +0,2 @@

export declare const version = "1.2.0";
export declare const version = "1.3.0";
//# sourceMappingURL=version.d.ts.map

@@ -26,3 +26,3 @@ import type { Context } from '../../app/context';

private _url;
private _closeAndFlushPendingItemsCount?;
private _flushPendingItemsCount?;
private _httpRequestTimeout;

@@ -35,3 +35,3 @@ private _emitter;

private clearBatch;
flushAfterClose(pendingItemsCount: number): void;
flush(pendingItemsCount: number): void;
/**

@@ -38,0 +38,0 @@ * Enqueues the context for future delivery.

{
"name": "@segment/analytics-node",
"version": "1.2.0",
"version": "1.3.0",
"main": "./dist/cjs/index.js",

@@ -5,0 +5,0 @@ "module": "./dist/esm/index.js",

@@ -16,2 +16,4 @@ import { CoreAnalytics, bindAll, pTimeout } from '@segment/analytics-core'

SegmentEvent,
FlushParams,
CloseAndFlushParams,
} from './types'

@@ -31,2 +33,4 @@ import { Context } from './context'

private _isFlushing = false
private readonly _queue: NodeEventQueue

@@ -83,8 +87,28 @@

timeout = this._closeAndFlushDefaultTimeout,
}: {
/** Set a maximum time permitted to wait before resolving. */
timeout?: number
} = {}): Promise<void> {
this._publisher.flushAfterClose(this._pendingEvents)
this._isClosed = true
}: CloseAndFlushParams = {}): Promise<void> {
return this.flush({ timeout, close: true })
}
/**
* Call this method to flush all existing events..
* This method also waits for any event method-specific callbacks to be triggered,
* and any of their subsequent promises to be resolved/rejected.
*/
public async flush({
timeout,
close = false,
}: FlushParams = {}): Promise<void> {
if (this._isFlushing) {
// if we're already flushing, then we don't need to do anything
console.warn(
'Overlapping flush calls detected. Please wait for the previous flush to finish before calling .flush again'
)
return
} else {
this._isFlushing = true
}
if (close) {
this._isClosed = true
}
this._publisher.flush(this._pendingEvents)
const promise = new Promise<void>((resolve) => {

@@ -94,4 +118,8 @@ if (!this._pendingEvents) {

} else {
this.once('drained', () => resolve())
this.once('drained', () => {
resolve()
})
}
}).finally(() => {
this._isFlushing = false
})

@@ -98,0 +126,0 @@ return timeout ? pTimeout(promise, timeout).catch(() => undefined) : promise

@@ -79,1 +79,19 @@ import type {

} & IdentityOptions
export type FlushParams = {
/**
* Max time in milliseconds to wait until the resulting promise resolves.
*/
timeout?: number
/**
* If true, will prevent new events from entering the pipeline. Default: false
*/
close?: boolean
}
export type CloseAndFlushParams = {
/**
* Max time in milliseconds to wait until the resulting promise resolves.
*/
timeout?: FlushParams['timeout']
}
// This file is generated.
export const version = '1.2.0'
export const version = '1.3.0'

@@ -44,3 +44,3 @@ import { Publisher, PublisherProps } from './publisher'

name: 'Segment.io',
type: 'after',
type: 'destination',
version: '1.0.0',

@@ -47,0 +47,0 @@ isLoaded: () => true,

@@ -45,3 +45,3 @@ import { backoff } from '@segment/analytics-core'

private _url: string
private _closeAndFlushPendingItemsCount?: number
private _flushPendingItemsCount?: number
private _httpRequestTimeout: number

@@ -51,2 +51,3 @@ private _emitter: NodeEmitter

private _httpClient: HTTPClient
constructor(

@@ -101,9 +102,9 @@ {

flushAfterClose(pendingItemsCount: number) {
flush(pendingItemsCount: number): void {
if (!pendingItemsCount) {
// if number of pending items is 0, there will never be anything else entering the batch, since the app is closed.
// if number of pending items is 0, there is nothing to flush
return
}
this._closeAndFlushPendingItemsCount = pendingItemsCount
this._flushPendingItemsCount = pendingItemsCount

@@ -151,3 +152,3 @@ // if batch is empty, there's nothing to flush, and when things come in, enqueue will handle them.

const isExpectingNoMoreItems =
batch.length === this._closeAndFlushPendingItemsCount
batch.length === this._flushPendingItemsCount
const isFull = batch.length === this._flushAt

@@ -173,3 +174,3 @@ if (isFull || isExpectingNoMoreItems) {

const isExpectingNoMoreItems =
fallbackBatch.length === this._closeAndFlushPendingItemsCount
fallbackBatch.length === this._flushPendingItemsCount
if (isExpectingNoMoreItems) {

@@ -190,4 +191,4 @@ this.send(fallbackBatch).catch(noop)

private async send(batch: ContextBatch) {
if (this._closeAndFlushPendingItemsCount) {
this._closeAndFlushPendingItemsCount -= batch.length
if (this._flushPendingItemsCount) {
this._flushPendingItemsCount -= batch.length
}

@@ -194,0 +195,0 @@ const events = batch.getEvents()

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

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