Socket
Socket
Sign inDemoInstall

@segment/analytics-node

Package Overview
Dependencies
4
Maintainers
237
Versions
41
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.1-beta.7 to 0.0.1-beta.8

dist/cjs/src/app/event-factory.js

7

CHANGELOG.md

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

- Updated dependencies [[`80e0d0a`](https://github.com/segmentio/analytics-next/commit/80e0d0a7d074422654cbebe0c3edb90e1d42ad62)]:
- @segment/analytics-core@1.1.6
## 0.0.1
### Patch Changes
- Updated dependencies [[`90b915a`](https://github.com/segmentio/analytics-next/commit/90b915ac3447d76673e98661c54bf5a0ced2a555), [`108c77e`](https://github.com/segmentio/analytics-next/commit/108c77e81a4e9d2a64eb56e78f707ae6c2ea6ed2)]:

@@ -9,0 +16,0 @@ - @segment/analytics-core@1.1.5

9

dist/cjs/package.json
{
"name": "@segment/analytics-node",
"version": "0.0.1-beta.7",
"version": "0.0.1-beta.8",
"main": "./dist/cjs/src/index.js",

@@ -36,10 +36,9 @@ "module": "./dist/esm/src/index.js",

"@lukeed/uuid": "^2.0.0",
"@segment/analytics-core": "1.1.5",
"@segment/analytics-core": "1.1.6",
"node-fetch": "^2.6.7",
"tslib": "^2.4.0"
"tslib": "^2.4.1"
},
"devDependencies": {
"@internal/config": "0.0.0",
"@types/node": "^14",
"nock": "^13.2.9"
"@types/node": "^14"
},

@@ -46,0 +45,0 @@ "packageManager": "yarn@3.2.1",

@@ -8,22 +8,11 @@ "use strict";

const segmentio_1 = require("../plugins/segmentio");
const create_node_event_factory_1 = require("../lib/create-node-event-factory");
const event_factory_1 = require("./event-factory");
const dispatch_emit_1 = require("./dispatch-emit");
const emitter_1 = require("./emitter");
const event_queue_1 = require("./event-queue");
// create a derived class since we may want to add node specific things to Context later
// While this is not a type, it is a definition
class Context extends analytics_core_1.CoreContext {
}
exports.Context = Context;
class NodePriorityQueue extends analytics_core_1.PriorityQueue {
constructor() {
super(1, []);
}
// do not use an internal "seen" map
getAttempts(ctx) {
return ctx.attempts ?? 0;
}
updateAttempts(ctx) {
ctx.attempts = this.getAttempts(ctx) + 1;
return this.getAttempts(ctx);
}
}
class Analytics extends emitter_1.NodeEmitter {

@@ -35,4 +24,4 @@ constructor(settings) {

(0, settings_1.validateSettings)(settings);
this._eventFactory = (0, create_node_event_factory_1.createNodeEventFactory)();
this._queue = new analytics_core_1.EventQueue(new NodePriorityQueue());
this._eventFactory = new event_factory_1.NodeEventFactory();
this._queue = new event_queue_1.NodeEventQueue();
const flushInterval = settings.flushInterval ?? 10000;

@@ -94,3 +83,3 @@ this._closeAndFlushDefaultTimeout = flushInterval * 1.25; // add arbitrary multiplier in case an event is in a plugin.

*/
alias({ userId, previousId, context, timestamp, integrations, }, callback) {
alias({ userId, previousId, context, timestamp, integrations }, callback) {
const segmentEvent = this._eventFactory.alias(userId, previousId, {

@@ -121,3 +110,3 @@ context,

*/
identify({ userId, anonymousId, traits = {}, context, integrations, }, callback) {
identify({ userId, anonymousId, traits = {}, context, integrations }, callback) {
const segmentEvent = this._eventFactory.identify(userId, traits, {

@@ -124,0 +113,0 @@ context,

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

const package_json_1 = require("../../../package.json");
const env_1 = require("../../lib/env");
function normalizeEvent(ctx) {
ctx.updateEvent('context.library.name', 'AnalyticsNode');
ctx.updateEvent('context.library.version', package_json_1.version);
ctx.updateEvent('_metadata.nodeVersion', process.versions.node);
const runtime = (0, env_1.detectRuntime)();
if (runtime === 'node') {
ctx.updateEvent('_metadata.nodeVersion', process.versions.node);
}
ctx.updateEvent('_metadata.runtime', runtime);
}

@@ -12,0 +17,0 @@ function createNodePlugin(publisher) {

{
"name": "@segment/analytics-node",
"version": "0.0.1-beta.7",
"version": "0.0.1-beta.8",
"main": "./dist/cjs/src/index.js",

@@ -36,10 +36,9 @@ "module": "./dist/esm/src/index.js",

"@lukeed/uuid": "^2.0.0",
"@segment/analytics-core": "1.1.5",
"@segment/analytics-core": "1.1.6",
"node-fetch": "^2.6.7",
"tslib": "^2.4.0"
"tslib": "^2.4.1"
},
"devDependencies": {
"@internal/config": "0.0.0",
"@types/node": "^14",
"nock": "^13.2.9"
"@types/node": "^14"
},

@@ -46,0 +45,0 @@ "packageManager": "yarn@3.2.1",

@@ -1,24 +0,13 @@

import { CoreContext, EventQueue, bindAll, PriorityQueue, pTimeout, } from '@segment/analytics-core';
import { bindAll, pTimeout, CoreContext, } from '@segment/analytics-core';
import { validateSettings } from './settings';
import { version } from '../../package.json';
import { createConfiguredNodePlugin } from '../plugins/segmentio';
import { createNodeEventFactory } from '../lib/create-node-event-factory';
import { NodeEventFactory } from './event-factory';
import { dispatchAndEmit } from './dispatch-emit';
import { NodeEmitter } from './emitter';
import { NodeEventQueue } from './event-queue';
// create a derived class since we may want to add node specific things to Context later
// While this is not a type, it is a definition
export class Context extends CoreContext {
}
class NodePriorityQueue extends PriorityQueue {
constructor() {
super(1, []);
}
// do not use an internal "seen" map
getAttempts(ctx) {
return ctx.attempts ?? 0;
}
updateAttempts(ctx) {
ctx.attempts = this.getAttempts(ctx) + 1;
return this.getAttempts(ctx);
}
}
export class Analytics extends NodeEmitter {

@@ -30,4 +19,4 @@ constructor(settings) {

validateSettings(settings);
this._eventFactory = createNodeEventFactory();
this._queue = new EventQueue(new NodePriorityQueue());
this._eventFactory = new NodeEventFactory();
this._queue = new NodeEventQueue();
const flushInterval = settings.flushInterval ?? 10000;

@@ -89,3 +78,3 @@ this._closeAndFlushDefaultTimeout = flushInterval * 1.25; // add arbitrary multiplier in case an event is in a plugin.

*/
alias({ userId, previousId, context, timestamp, integrations, }, callback) {
alias({ userId, previousId, context, timestamp, integrations }, callback) {
const segmentEvent = this._eventFactory.alias(userId, previousId, {

@@ -116,3 +105,3 @@ context,

*/
identify({ userId, anonymousId, traits = {}, context, integrations, }, callback) {
identify({ userId, anonymousId, traits = {}, context, integrations }, callback) {
const segmentEvent = this._eventFactory.identify(userId, traits, {

@@ -119,0 +108,0 @@ context,

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

export { Analytics, Context, } from './app/analytics-node';
export { Analytics, Context } from './app/analytics-node';
// export Analytics as both a named export and a default export (for backwards-compat. reasons)

@@ -3,0 +3,0 @@ import { Analytics } from './app/analytics-node';

import { Publisher } from './publisher';
import { version } from '../../../package.json';
import { detectRuntime } from '../../lib/env';
function normalizeEvent(ctx) {
ctx.updateEvent('context.library.name', 'AnalyticsNode');
ctx.updateEvent('context.library.version', version);
ctx.updateEvent('_metadata.nodeVersion', process.versions.node);
const runtime = detectRuntime();
if (runtime === 'node') {
ctx.updateEvent('_metadata.nodeVersion', process.versions.node);
}
ctx.updateEvent('_metadata.runtime', runtime);
}

@@ -8,0 +13,0 @@ export function createNodePlugin(publisher) {

@@ -1,40 +0,8 @@

import { EventProperties, CoreAnalytics, CoreContext, CorePlugin, CoreSegmentEvent, Integrations, CoreExtraContext, CoreAnalyticsTraits } from '@segment/analytics-core';
import { CoreAnalytics, CoreContext } from '@segment/analytics-core';
import { AnalyticsSettings } from './settings';
import { Callback } from './dispatch-emit';
import { NodeEmitter } from './emitter';
import { AliasParams, GroupParams, IdentifyParams, PageParams, TrackParams, Plugin } from './types';
export declare class Context extends CoreContext {
}
export interface Plugin extends CorePlugin {
}
declare type Timestamp = string | Date;
/**
* An ID associated with the user. Note: at least one of userId or anonymousId must be included.
**/
declare type IdentityOptions = {
userId: string;
anonymousId?: string;
} | {
userId?: string;
anonymousId: string;
};
/**
* A dictionary of extra context to attach to the call.
* Note: context differs from traits because it is not attributes of the user itself.
*/
export interface ExtraContext extends CoreExtraContext {
}
/**
* Traits are pieces of information you know about a user that are included in an identify call. These could be demographics like age or gender, account-specific like plan, or even things like whether a user has seen a particular A/B test variation. Up to you!
* Segment has reserved some traits that have semantic meanings for users, and we handle them in special ways. For example, Segment always expects email to be a string of the user’s email address.
*
* We’ll send this on to destinations like Mailchimp that require an email address for their tracking.
*
* You should only use reserved traits for their intended meaning.
*/
export interface Traits extends CoreAnalyticsTraits {
}
declare type SegmentEventType = 'track' | 'page' | 'identify' | 'alias' | 'screen';
export interface SegmentEvent extends CoreSegmentEvent {
type: SegmentEventType;
}
export declare class Analytics extends NodeEmitter implements CoreAnalytics {

@@ -64,9 +32,3 @@ private readonly _eventFactory;

*/
alias({ userId, previousId, context, timestamp, integrations, }: {
userId: string;
previousId: string;
context?: ExtraContext;
timestamp?: Timestamp;
integrations?: Integrations;
}, callback?: Callback): void;
alias({ userId, previousId, context, timestamp, integrations }: AliasParams, callback?: Callback): void;
/**

@@ -76,9 +38,3 @@ * Associates an identified user with a collective.

*/
group({ timestamp, groupId, userId, anonymousId, traits, context, integrations, }: IdentityOptions & {
groupId: string;
traits?: Traits;
context?: ExtraContext;
timestamp?: Timestamp;
integrations?: Integrations;
}, callback?: Callback): void;
group({ timestamp, groupId, userId, anonymousId, traits, context, integrations, }: GroupParams, callback?: Callback): void;
/**

@@ -88,7 +44,3 @@ * Includes a unique userId and (maybe anonymousId) and any optional traits you know about them.

*/
identify({ userId, anonymousId, traits, context, integrations, }: IdentityOptions & {
traits?: Traits;
context?: ExtraContext;
integrations?: Integrations;
}, callback?: Callback): void;
identify({ userId, anonymousId, traits, context, integrations }: IdentifyParams, callback?: Callback): void;
/**

@@ -98,10 +50,3 @@ * The page method lets you record page views on your website, along with optional extra information about the page being viewed.

*/
page({ userId, anonymousId, category, name, properties, context, timestamp, integrations, }: IdentityOptions & {
category?: string;
name?: string;
properties?: EventProperties;
timestamp?: Timestamp;
context?: ExtraContext;
integrations?: Integrations;
}, callback?: Callback): void;
page({ userId, anonymousId, category, name, properties, context, timestamp, integrations, }: PageParams, callback?: Callback): void;
/**

@@ -113,3 +58,3 @@ * Records screen views on your app, along with optional extra information

*/
screen({ userId, anonymousId, category, name, properties, context, timestamp, integrations, }: Parameters<Analytics['page']>[0], callback?: Callback): void;
screen({ userId, anonymousId, category, name, properties, context, timestamp, integrations, }: PageParams, callback?: Callback): void;
/**

@@ -119,9 +64,3 @@ * Records actions your users perform.

*/
track({ userId, anonymousId, event, properties, context, timestamp, integrations, }: IdentityOptions & {
event: string;
properties?: EventProperties;
context?: ExtraContext;
timestamp?: Timestamp;
integrations?: Integrations;
}, callback?: Callback): void;
track({ userId, anonymousId, event, properties, context, timestamp, integrations, }: TrackParams, callback?: Callback): void;
/**

@@ -131,3 +70,3 @@ * Registers one or more plugins to augment Analytics functionality.

*/
register(...plugins: CorePlugin<any, any>[]): Promise<void>;
register(...plugins: Plugin[]): Promise<void>;
/**

@@ -139,3 +78,2 @@ * Deregisters one or more plugins based on their names.

}
export {};
//# sourceMappingURL=analytics-node.d.ts.map
import { CoreEmitterContract, Emitter } from '@segment/analytics-core';
import type { SegmentEvent, Context } from './analytics-node';
import { Context } from './analytics-node';
import type { AnalyticsSettings } from './settings';
import { SegmentEvent } from './types';
/**

@@ -5,0 +6,0 @@ * Map of emitter event names to method args.

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

export { Analytics, Context, Plugin, ExtraContext, Traits, } from './app/analytics-node';
export { Analytics, Context } from './app/analytics-node';
export { ExtraContext, Plugin, Traits } from './app/types';
export type { AnalyticsSettings } from './app/settings';

@@ -3,0 +4,0 @@ import { Analytics } from './app/analytics-node';

{
"name": "@segment/analytics-node",
"version": "0.0.1-beta.7",
"version": "0.0.1-beta.8",
"main": "./dist/cjs/src/index.js",

@@ -36,10 +36,9 @@ "module": "./dist/esm/src/index.js",

"@lukeed/uuid": "^2.0.0",
"@segment/analytics-core": "1.1.5",
"@segment/analytics-core": "1.1.6",
"node-fetch": "^2.6.7",
"tslib": "^2.4.0"
"tslib": "^2.4.1"
},
"devDependencies": {
"@internal/config": "0.0.0",
"@types/node": "^14",
"nock": "^13.2.9"
"@types/node": "^14"
},

@@ -46,0 +45,0 @@ "packageManager": "yarn@3.2.1",

import {
EventProperties,
CoreAnalytics,
CoreContext,
CorePlugin,
EventFactory,

@@ -10,7 +7,4 @@ EventQueue,

bindAll,
PriorityQueue,
pTimeout,
Integrations,
CoreExtraContext,
CoreAnalyticsTraits,
CoreContext,
} from '@segment/analytics-core'

@@ -20,55 +14,20 @@ import { AnalyticsSettings, validateSettings } from './settings'

import { createConfiguredNodePlugin } from '../plugins/segmentio'
import { createNodeEventFactory } from '../lib/create-node-event-factory'
import { NodeEventFactory } from './event-factory'
import { Callback, dispatchAndEmit } from './dispatch-emit'
import { NodeEmitter } from './emitter'
import {
AliasParams,
GroupParams,
IdentifyParams,
PageParams,
TrackParams,
Plugin,
SegmentEvent,
} from './types'
import { NodeEventQueue } from './event-queue'
// create a derived class since we may want to add node specific things to Context later
// While this is not a type, it is a definition
export class Context extends CoreContext {}
export interface Plugin extends CorePlugin {}
type Timestamp = string | Date
/**
* An ID associated with the user. Note: at least one of userId or anonymousId must be included.
**/
type IdentityOptions =
| { userId: string; anonymousId?: string }
| { userId?: string; anonymousId: string }
/**
* A dictionary of extra context to attach to the call.
* Note: context differs from traits because it is not attributes of the user itself.
*/
export interface ExtraContext extends CoreExtraContext {}
/**
* Traits are pieces of information you know about a user that are included in an identify call. These could be demographics like age or gender, account-specific like plan, or even things like whether a user has seen a particular A/B test variation. Up to you!
* Segment has reserved some traits that have semantic meanings for users, and we handle them in special ways. For example, Segment always expects email to be a string of the user’s email address.
*
* We’ll send this on to destinations like Mailchimp that require an email address for their tracking.
*
* You should only use reserved traits for their intended meaning.
*/
export interface Traits extends CoreAnalyticsTraits {}
class NodePriorityQueue extends PriorityQueue<Context> {
constructor() {
super(1, [])
}
// do not use an internal "seen" map
getAttempts(ctx: Context): number {
return ctx.attempts ?? 0
}
updateAttempts(ctx: Context): number {
ctx.attempts = this.getAttempts(ctx) + 1
return this.getAttempts(ctx)
}
}
type SegmentEventType = 'track' | 'page' | 'identify' | 'alias' | 'screen'
export interface SegmentEvent extends CoreSegmentEvent {
type: SegmentEventType
}
export class Analytics extends NodeEmitter implements CoreAnalytics {

@@ -91,4 +50,4 @@ private readonly _eventFactory: EventFactory

this._eventFactory = createNodeEventFactory()
this._queue = new EventQueue(new NodePriorityQueue())
this._eventFactory = new NodeEventFactory()
this._queue = new NodeEventQueue()

@@ -167,17 +126,3 @@ const flushInterval = settings.flushInterval ?? 10000

alias(
{
userId,
previousId,
context,
timestamp,
integrations,
}: {
/* The new user id you want to associate with the user. */
userId: string
/* The previous id that the user was recognized by (this can be either a userId or an anonymousId). */
previousId: string
context?: ExtraContext
timestamp?: Timestamp
integrations?: Integrations
},
{ userId, previousId, context, timestamp, integrations }: AliasParams,
callback?: Callback

@@ -206,9 +151,3 @@ ): void {

integrations,
}: IdentityOptions & {
groupId: string
traits?: Traits
context?: ExtraContext
timestamp?: Timestamp
integrations?: Integrations
},
}: GroupParams,
callback?: Callback

@@ -232,13 +171,3 @@ ): void {

identify(
{
userId,
anonymousId,
traits = {},
context,
integrations,
}: IdentityOptions & {
traits?: Traits
context?: ExtraContext
integrations?: Integrations
},
{ userId, anonymousId, traits = {}, context, integrations }: IdentifyParams,
callback?: Callback

@@ -269,13 +198,3 @@ ): void {

integrations,
}: IdentityOptions & {
/* The category of the page. Useful for cases like ecommerce where many pages might live under a single category. */
category?: string
/* The name of the page.*/
name?: string
/* A dictionary of properties of the page. */
properties?: EventProperties
timestamp?: Timestamp
context?: ExtraContext
integrations?: Integrations
},
}: PageParams,
callback?: Callback

@@ -308,3 +227,3 @@ ): void {

integrations,
}: Parameters<Analytics['page']>[0],
}: PageParams,
callback?: Callback

@@ -335,9 +254,3 @@ ): void {

integrations,
}: IdentityOptions & {
event: string
properties?: EventProperties
context?: ExtraContext
timestamp?: Timestamp
integrations?: Integrations
},
}: TrackParams,
callback?: Callback

@@ -360,3 +273,3 @@ ): void {

*/
async register(...plugins: CorePlugin<any, any>[]): Promise<void> {
async register(...plugins: Plugin[]): Promise<void> {
return this._queue.criticalTasks.run(async () => {

@@ -363,0 +276,0 @@ const ctx = Context.system()

import { CoreEmitterContract, Emitter } from '@segment/analytics-core'
import type { SegmentEvent, Context } from './analytics-node'
import { Context } from './analytics-node'
import type { AnalyticsSettings } from './settings'
import { SegmentEvent } from './types'

@@ -5,0 +6,0 @@ /**

@@ -1,8 +0,3 @@

export {
Analytics,
Context,
Plugin,
ExtraContext,
Traits,
} from './app/analytics-node'
export { Analytics, Context } from './app/analytics-node'
export { ExtraContext, Plugin, Traits } from './app/types'
export type { AnalyticsSettings } from './app/settings'

@@ -9,0 +4,0 @@

import { CoreContext, CorePlugin } from '@segment/analytics-core'
import { Publisher, PublisherProps } from './publisher'
import { version } from '../../../package.json'
import { detectRuntime } from '../../lib/env'

@@ -8,3 +9,7 @@ function normalizeEvent(ctx: CoreContext) {

ctx.updateEvent('context.library.version', version)
ctx.updateEvent('_metadata.nodeVersion', process.versions.node)
const runtime = detectRuntime()
if (runtime === 'node') {
ctx.updateEvent('_metadata.nodeVersion', process.versions.node)
}
ctx.updateEvent('_metadata.runtime', runtime)
}

@@ -11,0 +16,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

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc