Socket
Socket
Sign inDemoInstall

posthog-node

Package Overview
Dependencies
Maintainers
6
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

posthog-node - npm Package Compare versions

Comparing version 3.5.0 to 3.6.0

4

CHANGELOG.md

@@ -0,1 +1,5 @@

# 3.6.0 - 2024-01-18
1. Adds support for overriding the event `uuid`
# 3.5.0 - 2024-01-09

@@ -2,0 +6,0 @@

28

lib/index.d.ts

@@ -48,3 +48,6 @@ /// <reference types="node" />

};
declare type PosthogCaptureOptions = {
declare type PostHogCaptureOptions = {
/** If provided overrides the auto-generated event ID */
uuid?: string;
/** If provided overrides the auto-generated timestamp */
timestamp?: Date;

@@ -136,13 +139,13 @@ disableGeoip?: boolean;

***/
protected identifyStateless(distinctId: string, properties?: PostHogEventProperties, options?: PosthogCaptureOptions): this;
protected identifyStateless(distinctId: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): this;
protected captureStateless(distinctId: string, event: string, properties?: {
[key: string]: any;
}, options?: PosthogCaptureOptions): this;
}, options?: PostHogCaptureOptions): this;
protected aliasStateless(alias: string, distinctId: string, properties?: {
[key: string]: any;
}, options?: PosthogCaptureOptions): this;
}, options?: PostHogCaptureOptions): this;
/***
*** GROUPS
***/
protected groupIdentifyStateless(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PosthogCaptureOptions, distinctId?: string, eventProperties?: PostHogEventProperties): this;
protected groupIdentifyStateless(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions, distinctId?: string, eventProperties?: PostHogEventProperties): this;
/***

@@ -164,3 +167,3 @@ *** FEATURE FLAGS

***/
protected enqueue(type: string, _message: any, options?: PosthogCaptureOptions): void;
protected enqueue(type: string, _message: any, options?: PostHogCaptureOptions): void;
flushAsync(): Promise<any>;

@@ -173,3 +176,3 @@ flush(callback?: (err?: any, data?: any) => void): void;

interface IdentifyMessageV1 {
interface IdentifyMessage {
distinctId: string;

@@ -179,3 +182,3 @@ properties?: Record<string | number, any>;

}
interface EventMessageV1 extends IdentifyMessageV1 {
interface EventMessage extends IdentifyMessage {
event: string;

@@ -185,2 +188,3 @@ groups?: Record<string, string | number>;

timestamp?: Date;
uuid?: string;
}

@@ -206,3 +210,3 @@ interface GroupIdentifyMessage {

*/
capture({ distinctId, event, properties, groups, sendFeatureFlags }: EventMessageV1): void;
capture({ distinctId, event, properties, groups, sendFeatureFlags }: EventMessage): void;
/**

@@ -215,3 +219,3 @@ * @description Identify lets you add metadata on your users so you can more easily identify who they are in PostHog,

*/
identify({ distinctId, properties }: IdentifyMessageV1): void;
identify({ distinctId, properties }: IdentifyMessage): void;
/**

@@ -340,4 +344,4 @@ * @description To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call.

debug(enabled?: boolean): void;
capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp, disableGeoip }: EventMessageV1): void;
identify({ distinctId, properties, disableGeoip }: IdentifyMessageV1): void;
capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp, disableGeoip, uuid, }: EventMessage): void;
identify({ distinctId, properties, disableGeoip }: IdentifyMessage): void;
alias(data: {

@@ -344,0 +348,0 @@ distinctId: string;

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

import { PostHogFetchOptions, PostHogFetchResponse, PostHogAutocaptureElement, PostHogDecideResponse, PosthogCoreOptions, PostHogEventProperties, PostHogPersistedProperty, PosthogCaptureOptions, JsonType } from './types';
import { PostHogFetchOptions, PostHogFetchResponse, PostHogAutocaptureElement, PostHogDecideResponse, PosthogCoreOptions, PostHogEventProperties, PostHogPersistedProperty, PostHogCaptureOptions, JsonType } from './types';
import { RetriableOptions } from './utils';

@@ -39,13 +39,13 @@ export * as utils from './utils';

***/
protected identifyStateless(distinctId: string, properties?: PostHogEventProperties, options?: PosthogCaptureOptions): this;
protected identifyStateless(distinctId: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): this;
protected captureStateless(distinctId: string, event: string, properties?: {
[key: string]: any;
}, options?: PosthogCaptureOptions): this;
}, options?: PostHogCaptureOptions): this;
protected aliasStateless(alias: string, distinctId: string, properties?: {
[key: string]: any;
}, options?: PosthogCaptureOptions): this;
}, options?: PostHogCaptureOptions): this;
/***
*** GROUPS
***/
protected groupIdentifyStateless(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PosthogCaptureOptions, distinctId?: string, eventProperties?: PostHogEventProperties): this;
protected groupIdentifyStateless(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions, distinctId?: string, eventProperties?: PostHogEventProperties): this;
/***

@@ -67,3 +67,3 @@ *** FEATURE FLAGS

***/
protected enqueue(type: string, _message: any, options?: PosthogCaptureOptions): void;
protected enqueue(type: string, _message: any, options?: PostHogCaptureOptions): void;
flushAsync(): Promise<any>;

@@ -106,8 +106,8 @@ flush(callback?: (err?: any, data?: any) => void): void;

***/
identify(distinctId?: string, properties?: PostHogEventProperties, options?: PosthogCaptureOptions): this;
identify(distinctId?: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): this;
capture(event: string, properties?: {
[key: string]: any;
}, options?: PosthogCaptureOptions): this;
}, options?: PostHogCaptureOptions): this;
alias(alias: string): this;
autocapture(eventType: string, elements: PostHogAutocaptureElement[], properties?: PostHogEventProperties, options?: PosthogCaptureOptions): this;
autocapture(eventType: string, elements: PostHogAutocaptureElement[], properties?: PostHogEventProperties, options?: PostHogCaptureOptions): this;
/***

@@ -119,4 +119,4 @@ *** GROUPS

}): this;
group(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PosthogCaptureOptions): this;
groupIdentify(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PosthogCaptureOptions): this;
group(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions): this;
groupIdentify(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions): this;
/***

@@ -123,0 +123,0 @@ * PROPERTIES

@@ -48,3 +48,6 @@ /// <reference types="node" />

};
export declare type PosthogCaptureOptions = {
export declare type PostHogCaptureOptions = {
/** If provided overrides the auto-generated event ID */
uuid?: string;
/** If provided overrides the auto-generated timestamp */
timestamp?: Date;

@@ -51,0 +54,0 @@ disableGeoip?: boolean;

import { JsonType, PosthogCoreOptions, PostHogCoreStateless, PostHogFetchOptions, PostHogFetchResponse, PosthogFlagsAndPayloadsResponse, PostHogPersistedProperty } from '../../posthog-core/src';
import { EventMessageV1, GroupIdentifyMessage, IdentifyMessageV1, PostHogNodeV1 } from './types';
import { EventMessage, GroupIdentifyMessage, IdentifyMessage, PostHogNodeV1 } from './types';
export declare type PostHogOptions = PosthogCoreOptions & {

@@ -27,4 +27,4 @@ persistence?: 'memory';

debug(enabled?: boolean): void;
capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp, disableGeoip }: EventMessageV1): void;
identify({ distinctId, properties, disableGeoip }: IdentifyMessageV1): void;
capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp, disableGeoip, uuid, }: EventMessage): void;
identify({ distinctId, properties, disableGeoip }: IdentifyMessage): void;
alias(data: {

@@ -31,0 +31,0 @@ distinctId: string;

import { JsonType } from '../../posthog-core/src';
export interface IdentifyMessageV1 {
export interface IdentifyMessage {
distinctId: string;

@@ -7,3 +7,3 @@ properties?: Record<string | number, any>;

}
export interface EventMessageV1 extends IdentifyMessageV1 {
export interface EventMessage extends IdentifyMessage {
event: string;

@@ -13,2 +13,3 @@ groups?: Record<string, string | number>;

timestamp?: Date;
uuid?: string;
}

@@ -72,3 +73,3 @@ export interface GroupIdentifyMessage {

*/
capture({ distinctId, event, properties, groups, sendFeatureFlags }: EventMessageV1): void;
capture({ distinctId, event, properties, groups, sendFeatureFlags }: EventMessage): void;
/**

@@ -81,3 +82,3 @@ * @description Identify lets you add metadata on your users so you can more easily identify who they are in PostHog,

*/
identify({ distinctId, properties }: IdentifyMessageV1): void;
identify({ distinctId, properties }: IdentifyMessage): void;
/**

@@ -84,0 +85,0 @@ * @description To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call.

{
"name": "posthog-node",
"version": "3.5.0",
"version": "3.6.0",
"description": "PostHog Node.js integration",

@@ -5,0 +5,0 @@ "repository": {

@@ -13,3 +13,3 @@ import { version } from '../package.json'

import { PostHogMemoryStorage } from '../../posthog-core/src/storage-memory'
import { EventMessageV1, GroupIdentifyMessage, IdentifyMessageV1, PostHogNodeV1 } from './types'
import { EventMessage, GroupIdentifyMessage, IdentifyMessage, PostHogNodeV1 } from './types'
import { FeatureFlagsPoller } from './feature-flags'

@@ -104,5 +104,14 @@ import fetch from './fetch'

capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp, disableGeoip }: EventMessageV1): void {
const _capture = (props: EventMessageV1['properties']): void => {
super.captureStateless(distinctId, event, props, { timestamp, disableGeoip })
capture({
distinctId,
event,
properties,
groups,
sendFeatureFlags,
timestamp,
disableGeoip,
uuid,
}: EventMessage): void {
const _capture = (props: EventMessage['properties']): void => {
super.captureStateless(distinctId, event, props, { timestamp, disableGeoip, uuid })
}

@@ -160,3 +169,3 @@

identify({ distinctId, properties, disableGeoip }: IdentifyMessageV1): void {
identify({ distinctId, properties, disableGeoip }: IdentifyMessage): void {
// Catch properties passed as $set and move them to the top level

@@ -163,0 +172,0 @@ const personProperties = properties?.$set || properties

import { JsonType } from '../../posthog-core/src'
export interface IdentifyMessageV1 {
export interface IdentifyMessage {
distinctId: string

@@ -9,3 +9,3 @@ properties?: Record<string | number, any>

export interface EventMessageV1 extends IdentifyMessageV1 {
export interface EventMessage extends IdentifyMessage {
event: string

@@ -15,2 +15,3 @@ groups?: Record<string, string | number> // Mapping of group type to group id

timestamp?: Date
uuid?: string
}

@@ -80,3 +81,3 @@

*/
capture({ distinctId, event, properties, groups, sendFeatureFlags }: EventMessageV1): void
capture({ distinctId, event, properties, groups, sendFeatureFlags }: EventMessage): void

@@ -90,3 +91,3 @@ /**

*/
identify({ distinctId, properties }: IdentifyMessageV1): void
identify({ distinctId, properties }: IdentifyMessage): void

@@ -93,0 +94,0 @@ /**

@@ -149,2 +149,3 @@ // import { PostHog } from '../'

timestamp: expect.any(String),
uuid: expect.any(String),
},

@@ -151,0 +152,0 @@ ])

@@ -7,2 +7,3 @@ // import { PostHog } from '../'

import { waitForPromises, wait } from '../../posthog-core/test/test-utils/test-utils'
import { generateUUID } from 'posthog-core/src/utils'

@@ -70,2 +71,3 @@ jest.mock('../package.json', () => ({ version: '1.2.3' }))

},
uuid: expect.any(String),
timestamp: expect.any(String),

@@ -190,2 +192,3 @@ type: 'capture',

event: 'custom-time',
uuid: expect.any(String),
},

@@ -195,2 +198,19 @@ ])

it('should allow overriding uuid', async () => {
expect(mockedFetch).toHaveBeenCalledTimes(0)
const uuid = generateUUID()
posthog.capture({ event: 'custom-time', distinctId: '123', uuid })
await waitForPromises()
jest.runOnlyPendingTimers()
const batchEvents = getLastBatchEvents()
expect(batchEvents).toMatchObject([
{
distinct_id: '123',
timestamp: expect.any(String),
event: 'custom-time',
uuid: uuid,
},
])
})
it('should respect disableGeoip setting if passed in', async () => {

@@ -197,0 +217,0 @@ expect(mockedFetch).toHaveBeenCalledTimes(0)

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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