🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@segment/analytics-core

Package Overview
Dependencies
Maintainers
284
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@segment/analytics-core - npm Package Compare versions

Comparing version

to
1.5.0

7

dist/cjs/events/index.js

@@ -9,2 +9,6 @@ "use strict";

var assertions_1 = require("../validation/assertions");
/**
* This is currently only used by node.js, but the original idea was to have something that could be shared between browser and node.
* Unfortunately, there are some differences in the way the two environments handle events, so this is not currently shared.
*/
var EventFactory = /** @class */ (function () {

@@ -104,2 +108,3 @@ function EventFactory(settings) {

'timestamp',
'messageId',
];

@@ -144,3 +149,3 @@ delete options['integrations'];

var body = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({ timestamp: new Date() }, rest), { integrations: allIntegrations, context: context }), overrides);
var evt = tslib_1.__assign(tslib_1.__assign({}, body), { messageId: this.createMessageId() });
var evt = tslib_1.__assign(tslib_1.__assign({}, body), { messageId: options.messageId || this.createMessageId() });
(0, assertions_1.validateEvent)(evt);

@@ -147,0 +152,0 @@ return evt;

35

dist/cjs/queue/event-queue.js

@@ -37,20 +37,21 @@ "use strict";

switch (_a.label) {
case 0: return [4 /*yield*/, Promise.resolve(plugin.load(ctx, instance))
.then(function () {
_this.plugins.push(plugin);
})
.catch(function (err) {
if (plugin.type === 'destination') {
_this.failedInitializations.push(plugin.name);
console.warn(plugin.name, err);
ctx.log('warn', 'Failed to load destination', {
plugin: plugin.name,
error: err,
});
return;
}
throw err;
})];
case 1:
case 0:
if (!(plugin.type === 'destination' && plugin.name !== 'Segment.io')) return [3 /*break*/, 1];
plugin.load(ctx, instance).catch(function (err) {
_this.failedInitializations.push(plugin.name);
_this.emit('initialization_failure', plugin);
console.warn(plugin.name, err);
ctx.log('warn', 'Failed to load destination', {
plugin: plugin.name,
error: err,
});
_this.plugins = _this.plugins.filter(function (p) { return p === plugin; });
});
return [3 /*break*/, 3];
case 1: return [4 /*yield*/, plugin.load(ctx, instance)];
case 2:
_a.sent();
_a.label = 3;
case 3:
this.plugins.push(plugin);
return [2 /*return*/];

@@ -57,0 +58,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateEvent = exports.assertTraits = exports.assertTrackEventProperties = exports.assertTrackEventName = exports.assertEventType = exports.assertEventExists = exports.assertUserIdentity = void 0;
exports.validateEvent = exports.assertMessageId = exports.assertTraits = exports.assertTrackEventProperties = exports.assertTrackEventName = exports.assertEventType = exports.assertEventExists = exports.assertUserIdentity = void 0;
var errors_1 = require("./errors");

@@ -54,5 +54,12 @@ var helpers_1 = require("./helpers");

exports.assertTraits = assertTraits;
function assertMessageId(event) {
if (!(0, helpers_1.isString)(event.messageId)) {
throw new errors_1.ValidationError('.messageId', stringError);
}
}
exports.assertMessageId = assertMessageId;
function validateEvent(event) {
assertEventExists(event);
assertEventType(event);
assertMessageId(event);
if (event.type === 'track') {

@@ -59,0 +66,0 @@ assertTrackEventName(event);

@@ -6,2 +6,6 @@ import { __assign, __rest } from "tslib";

import { validateEvent } from '../validation/assertions';
/**
* This is currently only used by node.js, but the original idea was to have something that could be shared between browser and node.
* Unfortunately, there are some differences in the way the two environments handle events, so this is not currently shared.
*/
var EventFactory = /** @class */ (function () {

@@ -101,2 +105,3 @@ function EventFactory(settings) {

'timestamp',
'messageId',
];

@@ -141,3 +146,3 @@ delete options['integrations'];

var body = __assign(__assign(__assign({ timestamp: new Date() }, rest), { integrations: allIntegrations, context: context }), overrides);
var evt = __assign(__assign({}, body), { messageId: this.createMessageId() });
var evt = __assign(__assign({}, body), { messageId: options.messageId || this.createMessageId() });
validateEvent(evt);

@@ -144,0 +149,0 @@ return evt;

@@ -34,20 +34,21 @@ import { __awaiter, __extends, __generator } from "tslib";

switch (_a.label) {
case 0: return [4 /*yield*/, Promise.resolve(plugin.load(ctx, instance))
.then(function () {
_this.plugins.push(plugin);
})
.catch(function (err) {
if (plugin.type === 'destination') {
_this.failedInitializations.push(plugin.name);
console.warn(plugin.name, err);
ctx.log('warn', 'Failed to load destination', {
plugin: plugin.name,
error: err,
});
return;
}
throw err;
})];
case 1:
case 0:
if (!(plugin.type === 'destination' && plugin.name !== 'Segment.io')) return [3 /*break*/, 1];
plugin.load(ctx, instance).catch(function (err) {
_this.failedInitializations.push(plugin.name);
_this.emit('initialization_failure', plugin);
console.warn(plugin.name, err);
ctx.log('warn', 'Failed to load destination', {
plugin: plugin.name,
error: err,
});
_this.plugins = _this.plugins.filter(function (p) { return p === plugin; });
});
return [3 /*break*/, 3];
case 1: return [4 /*yield*/, plugin.load(ctx, instance)];
case 2:
_a.sent();
_a.label = 3;
case 3:
this.plugins.push(plugin);
return [2 /*return*/];

@@ -54,0 +55,0 @@ }

@@ -45,5 +45,11 @@ import { ValidationError } from './errors';

}
export function assertMessageId(event) {
if (!isString(event.messageId)) {
throw new ValidationError('.messageId', stringError);
}
}
export function validateEvent(event) {
assertEventExists(event);
assertEventType(event);
assertMessageId(event);
if (event.type === 'track') {

@@ -50,0 +56,0 @@ assertTrackEventName(event);

@@ -8,2 +8,6 @@ export * from './interfaces';

}
/**
* This is currently only used by node.js, but the original idea was to have something that could be shared between browser and node.
* Unfortunately, there are some differences in the way the two environments handle events, so this is not currently shared.
*/
export declare class EventFactory {

@@ -10,0 +14,0 @@ createMessageId: EventFactorySettings['createMessageId'];

@@ -24,2 +24,8 @@ import { CoreContext } from '../context';

traits?: Traits;
/**
* Override the messageId. Under normal circumstances, this is not recommended -- but neccessary for deduping events.
*
* **Currently, This option only works in `@segment/analytics-node`.**
*/
messageId?: string;
[key: string]: any;

@@ -26,0 +32,0 @@ }

@@ -14,2 +14,3 @@ import { CoreAnalytics } from '../analytics';

flush: [ctx: Ctx, delivered: boolean];
initialization_failure: [CorePlugin<Ctx>];
};

@@ -16,0 +17,0 @@ export declare abstract class CoreEventQueue<Ctx extends CoreContext = CoreContext, Plugin extends CorePlugin<Ctx> = CorePlugin<Ctx>> extends Emitter<EventQueueEmitterContract<Ctx>> {

@@ -8,3 +8,4 @@ import { CoreSegmentEvent } from '../events';

export declare function assertTraits(event: CoreSegmentEvent): void;
export declare function assertMessageId(event: CoreSegmentEvent): void;
export declare function validateEvent(event?: CoreSegmentEvent | null): void;
//# sourceMappingURL=assertions.d.ts.map
{
"name": "@segment/analytics-core",
"version": "1.4.1",
"version": "1.5.0",
"repository": {

@@ -37,3 +37,3 @@ "type": "git",

"@lukeed/uuid": "^2.0.0",
"@segment/analytics-generic-utils": "1.1.1",
"@segment/analytics-generic-utils": "1.2.0",
"dset": "^3.1.2",

@@ -40,0 +40,0 @@ "tslib": "^2.4.1"

@@ -22,2 +22,6 @@ export * from './interfaces'

/**
* This is currently only used by node.js, but the original idea was to have something that could be shared between browser and node.
* Unfortunately, there are some differences in the way the two environments handle events, so this is not currently shared.
*/
export class EventFactory {

@@ -205,2 +209,3 @@ createMessageId: EventFactorySettings['createMessageId']

'timestamp',
'messageId',
]

@@ -276,3 +281,3 @@

...body,
messageId: this.createMessageId(),
messageId: options.messageId || this.createMessageId(),
}

@@ -279,0 +284,0 @@

@@ -36,2 +36,8 @@ import { CoreContext } from '../context'

traits?: Traits
/**
* Override the messageId. Under normal circumstances, this is not recommended -- but neccessary for deduping events.
*
* **Currently, This option only works in `@segment/analytics-node`.**
*/
messageId?: string
// ugh, this is ugly, but we allow literally any property to be passed to options (which get spread onto the event)

@@ -38,0 +44,0 @@ [key: string]: any

@@ -19,2 +19,3 @@ import { CoreAnalytics } from '../analytics'

flush: [ctx: Ctx, delivered: boolean]
initialization_failure: [CorePlugin<Ctx>]
}

@@ -53,21 +54,20 @@

): Promise<void> {
await Promise.resolve(plugin.load(ctx, instance))
.then(() => {
this.plugins.push(plugin)
})
.catch((err) => {
if (plugin.type === 'destination') {
this.failedInitializations.push(plugin.name)
console.warn(plugin.name, err)
if (plugin.type === 'destination' && plugin.name !== 'Segment.io') {
plugin.load(ctx, instance).catch((err) => {
this.failedInitializations.push(plugin.name)
this.emit('initialization_failure', plugin)
console.warn(plugin.name, err)
ctx.log('warn', 'Failed to load destination', {
plugin: plugin.name,
error: err,
})
ctx.log('warn', 'Failed to load destination', {
plugin: plugin.name,
error: err,
})
return
}
this.plugins = this.plugins.filter((p) => p === plugin)
})
} else {
await plugin.load(ctx, instance)
}
throw err
})
this.plugins.push(plugin)
}

@@ -74,0 +74,0 @@

@@ -58,5 +58,12 @@ import { CoreSegmentEvent } from '../events'

export function assertMessageId(event: CoreSegmentEvent): void {
if (!isString(event.messageId)) {
throw new ValidationError('.messageId', stringError)
}
}
export function validateEvent(event?: CoreSegmentEvent | null) {
assertEventExists(event)
assertEventType(event)
assertMessageId(event)

@@ -63,0 +70,0 @@ if (event.type === 'track') {

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

Sorry, the diff of this file is not supported yet