posthog-node
Advanced tools
Comparing version 2.6.0 to 3.0.0
@@ -0,1 +1,19 @@ | ||
# 3.0.0 - 2023-04-14 | ||
Breaking change: | ||
All events by default now send the `$geoip_disable` property to disable geoip lookup in app. This is because usually we don't | ||
want to update person properties to take the server's location. | ||
The same now happens for feature flag requests, where we discard the IP address of the server for matching on geoip properties like city, country, continent. | ||
To restore previous behaviour, you can set the default to False like so: | ||
```javascript | ||
const posthog = new PostHog(PH_API_KEY, { | ||
host: PH_HOST, | ||
disableGeoip: false | ||
}) | ||
``` | ||
# 2.6.0 - 2023-03-14 | ||
@@ -2,0 +20,0 @@ |
@@ -20,2 +20,3 @@ /// <reference types="node" /> | ||
captureMode?: 'json' | 'form'; | ||
disableGeoip?: boolean; | ||
}; | ||
@@ -48,2 +49,3 @@ declare enum PostHogPersistedProperty { | ||
timestamp?: Date; | ||
disableGeoip?: boolean; | ||
}; | ||
@@ -110,2 +112,3 @@ declare type PostHogFetchResponse = { | ||
private pendingPromises; | ||
private disableGeoip; | ||
private _optoutOverride; | ||
@@ -138,3 +141,3 @@ protected _events: SimpleEventEmitter; | ||
[key: string]: any; | ||
}): this; | ||
}, options?: PosthogCaptureOptions): this; | ||
/*** | ||
@@ -148,8 +151,8 @@ *** GROUPS | ||
protected getDecide(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, extraPayload?: Record<string, any>): Promise<PostHogDecideResponse | undefined>; | ||
protected getFeatureFlagStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<boolean | string | undefined>; | ||
protected getFeatureFlagPayloadStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<JsonType | undefined>; | ||
protected getFeatureFlagPayloadsStateless(distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<PostHogDecideResponse['featureFlagPayloads'] | undefined>; | ||
protected getFeatureFlagStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<boolean | string | undefined>; | ||
protected getFeatureFlagPayloadStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<JsonType | undefined>; | ||
protected getFeatureFlagPayloadsStateless(distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<PostHogDecideResponse['featureFlagPayloads'] | undefined>; | ||
protected _parsePayload(response: any): any; | ||
protected getFeatureFlagsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<PostHogDecideResponse['featureFlags'] | undefined>; | ||
protected getFeatureFlagsAndPayloadsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<{ | ||
protected getFeatureFlagsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<PostHogDecideResponse['featureFlags'] | undefined>; | ||
protected getFeatureFlagsAndPayloadsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<{ | ||
flags: PostHogDecideResponse['featureFlags'] | undefined; | ||
@@ -172,2 +175,3 @@ payloads: PostHogDecideResponse['featureFlagPayloads'] | undefined; | ||
properties?: Record<string | number, any>; | ||
disableGeoip?: boolean; | ||
} | ||
@@ -185,2 +189,3 @@ interface EventMessageV1 extends IdentifyMessageV1 { | ||
distinctId?: string; | ||
disableGeoip?: boolean; | ||
} | ||
@@ -331,7 +336,8 @@ declare type PostHogNodeV1 = { | ||
debug(enabled?: boolean): void; | ||
capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp }: EventMessageV1): void; | ||
identify({ distinctId, properties }: IdentifyMessageV1): void; | ||
capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp, disableGeoip }: EventMessageV1): void; | ||
identify({ distinctId, properties, disableGeoip }: IdentifyMessageV1): void; | ||
alias(data: { | ||
distinctId: string; | ||
alias: string; | ||
disableGeoip?: boolean; | ||
}): void; | ||
@@ -344,2 +350,3 @@ getFeatureFlag(key: string, distinctId: string, options?: { | ||
sendFeatureFlagEvents?: boolean; | ||
disableGeoip?: boolean; | ||
}): Promise<string | boolean | undefined>; | ||
@@ -352,2 +359,3 @@ getFeatureFlagPayload(key: string, distinctId: string, matchValue?: string | boolean, options?: { | ||
sendFeatureFlagEvents?: boolean; | ||
disableGeoip?: boolean; | ||
}): Promise<JsonType | undefined>; | ||
@@ -360,2 +368,3 @@ isFeatureEnabled(key: string, distinctId: string, options?: { | ||
sendFeatureFlagEvents?: boolean; | ||
disableGeoip?: boolean; | ||
}): Promise<boolean | undefined>; | ||
@@ -367,2 +376,3 @@ getAllFlags(distinctId: string, options?: { | ||
onlyEvaluateLocally?: boolean; | ||
disableGeoip?: boolean; | ||
}): Promise<Record<string, string | boolean>>; | ||
@@ -374,4 +384,5 @@ getAllFlagsAndPayloads(distinctId: string, options?: { | ||
onlyEvaluateLocally?: boolean; | ||
disableGeoip?: boolean; | ||
}): Promise<PosthogFlagsAndPayloadsResponse>; | ||
groupIdentify({ groupType, groupKey, properties, distinctId }: GroupIdentifyMessage): void; | ||
groupIdentify({ groupType, groupKey, properties, distinctId, disableGeoip }: GroupIdentifyMessage): void; | ||
reloadFeatureFlags(): Promise<void>; | ||
@@ -378,0 +389,0 @@ shutdown(): void; |
@@ -16,2 +16,3 @@ import { PostHogFetchOptions, PostHogFetchResponse, PostHogAutocaptureElement, PostHogDecideResponse, PosthogCoreOptions, PostHogEventProperties, PostHogPersistedProperty, PosthogCaptureOptions, JsonType } from './types'; | ||
private pendingPromises; | ||
private disableGeoip; | ||
private _optoutOverride; | ||
@@ -44,3 +45,3 @@ protected _events: SimpleEventEmitter; | ||
[key: string]: any; | ||
}): this; | ||
}, options?: PosthogCaptureOptions): this; | ||
/*** | ||
@@ -54,8 +55,8 @@ *** GROUPS | ||
protected getDecide(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, extraPayload?: Record<string, any>): Promise<PostHogDecideResponse | undefined>; | ||
protected getFeatureFlagStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<boolean | string | undefined>; | ||
protected getFeatureFlagPayloadStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<JsonType | undefined>; | ||
protected getFeatureFlagPayloadsStateless(distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<PostHogDecideResponse['featureFlagPayloads'] | undefined>; | ||
protected getFeatureFlagStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<boolean | string | undefined>; | ||
protected getFeatureFlagPayloadStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<JsonType | undefined>; | ||
protected getFeatureFlagPayloadsStateless(distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<PostHogDecideResponse['featureFlagPayloads'] | undefined>; | ||
protected _parsePayload(response: any): any; | ||
protected getFeatureFlagsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<PostHogDecideResponse['featureFlags'] | undefined>; | ||
protected getFeatureFlagsAndPayloadsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<{ | ||
protected getFeatureFlagsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<PostHogDecideResponse['featureFlags'] | undefined>; | ||
protected getFeatureFlagsAndPayloadsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<{ | ||
flags: PostHogDecideResponse['featureFlags'] | undefined; | ||
@@ -62,0 +63,0 @@ payloads: PostHogDecideResponse['featureFlagPayloads'] | undefined; |
@@ -20,2 +20,3 @@ /// <reference types="node" /> | ||
captureMode?: 'json' | 'form'; | ||
disableGeoip?: boolean; | ||
}; | ||
@@ -48,2 +49,3 @@ export declare enum PostHogPersistedProperty { | ||
timestamp?: Date; | ||
disableGeoip?: boolean; | ||
}; | ||
@@ -50,0 +52,0 @@ export declare type PostHogFetchResponse = { |
@@ -27,7 +27,8 @@ import { JsonType, PosthogCoreOptions, PostHogCoreStateless, PostHogFetchOptions, PostHogFetchResponse, PosthogFlagsAndPayloadsResponse, PostHogPersistedProperty } from '../../posthog-core/src'; | ||
debug(enabled?: boolean): void; | ||
capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp }: EventMessageV1): void; | ||
identify({ distinctId, properties }: IdentifyMessageV1): void; | ||
capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp, disableGeoip }: EventMessageV1): void; | ||
identify({ distinctId, properties, disableGeoip }: IdentifyMessageV1): void; | ||
alias(data: { | ||
distinctId: string; | ||
alias: string; | ||
disableGeoip?: boolean; | ||
}): void; | ||
@@ -40,2 +41,3 @@ getFeatureFlag(key: string, distinctId: string, options?: { | ||
sendFeatureFlagEvents?: boolean; | ||
disableGeoip?: boolean; | ||
}): Promise<string | boolean | undefined>; | ||
@@ -48,2 +50,3 @@ getFeatureFlagPayload(key: string, distinctId: string, matchValue?: string | boolean, options?: { | ||
sendFeatureFlagEvents?: boolean; | ||
disableGeoip?: boolean; | ||
}): Promise<JsonType | undefined>; | ||
@@ -56,2 +59,3 @@ isFeatureEnabled(key: string, distinctId: string, options?: { | ||
sendFeatureFlagEvents?: boolean; | ||
disableGeoip?: boolean; | ||
}): Promise<boolean | undefined>; | ||
@@ -63,2 +67,3 @@ getAllFlags(distinctId: string, options?: { | ||
onlyEvaluateLocally?: boolean; | ||
disableGeoip?: boolean; | ||
}): Promise<Record<string, string | boolean>>; | ||
@@ -70,4 +75,5 @@ getAllFlagsAndPayloads(distinctId: string, options?: { | ||
onlyEvaluateLocally?: boolean; | ||
disableGeoip?: boolean; | ||
}): Promise<PosthogFlagsAndPayloadsResponse>; | ||
groupIdentify({ groupType, groupKey, properties, distinctId }: GroupIdentifyMessage): void; | ||
groupIdentify({ groupType, groupKey, properties, distinctId, disableGeoip }: GroupIdentifyMessage): void; | ||
reloadFeatureFlags(): Promise<void>; | ||
@@ -74,0 +80,0 @@ shutdown(): void; |
@@ -5,2 +5,3 @@ import { JsonType } from '../../posthog-core/src'; | ||
properties?: Record<string | number, any>; | ||
disableGeoip?: boolean; | ||
} | ||
@@ -18,2 +19,3 @@ export interface EventMessageV1 extends IdentifyMessageV1 { | ||
distinctId?: string; | ||
disableGeoip?: boolean; | ||
} | ||
@@ -20,0 +22,0 @@ export declare type PropertyGroup = { |
{ | ||
"name": "posthog-node", | ||
"version": "2.6.0", | ||
"version": "3.0.0", | ||
"description": "PostHog Node.js integration", | ||
@@ -5,0 +5,0 @@ "repository": "PostHog/posthog-node", |
@@ -100,9 +100,9 @@ import { version } from '../package.json' | ||
capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp }: EventMessageV1): void { | ||
capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp, disableGeoip }: EventMessageV1): void { | ||
const _capture = (props: EventMessageV1['properties']): void => { | ||
super.captureStateless(distinctId, event, props, { timestamp }) | ||
super.captureStateless(distinctId, event, props, { timestamp, disableGeoip }) | ||
} | ||
if (sendFeatureFlags) { | ||
super.getFeatureFlagsStateless(distinctId, groups).then((flags) => { | ||
super.getFeatureFlagsStateless(distinctId, groups, undefined, undefined, disableGeoip).then((flags) => { | ||
const featureVariantProperties: Record<string, string | boolean> = {} | ||
@@ -128,13 +128,17 @@ if (flags) { | ||
identify({ distinctId, properties }: IdentifyMessageV1): void { | ||
identify({ distinctId, properties, disableGeoip }: IdentifyMessageV1): void { | ||
// Catch properties passed as $set and move them to the top level | ||
const personProperties = properties?.$set || properties | ||
super.identifyStateless(distinctId, { | ||
$set: personProperties, | ||
}) | ||
super.identifyStateless( | ||
distinctId, | ||
{ | ||
$set: personProperties, | ||
}, | ||
{ disableGeoip } | ||
) | ||
} | ||
alias(data: { distinctId: string; alias: string }): void { | ||
super.aliasStateless(data.alias, data.distinctId) | ||
alias(data: { distinctId: string; alias: string; disableGeoip?: boolean }): void { | ||
super.aliasStateless(data.alias, data.distinctId, undefined, { disableGeoip: data.disableGeoip }) | ||
} | ||
@@ -151,5 +155,6 @@ | ||
sendFeatureFlagEvents?: boolean | ||
disableGeoip?: boolean | ||
} | ||
): Promise<string | boolean | undefined> { | ||
const { groups, personProperties, groupProperties } = options || {} | ||
const { groups, personProperties, groupProperties, disableGeoip } = options || {} | ||
let { onlyEvaluateLocally, sendFeatureFlagEvents } = options || {} | ||
@@ -176,3 +181,10 @@ | ||
if (!flagWasLocallyEvaluated && !onlyEvaluateLocally) { | ||
response = await super.getFeatureFlagStateless(key, distinctId, groups, personProperties, groupProperties) | ||
response = await super.getFeatureFlagStateless( | ||
key, | ||
distinctId, | ||
groups, | ||
personProperties, | ||
groupProperties, | ||
disableGeoip | ||
) | ||
} | ||
@@ -204,2 +216,3 @@ | ||
groups, | ||
disableGeoip, | ||
}) | ||
@@ -220,5 +233,6 @@ } | ||
sendFeatureFlagEvents?: boolean | ||
disableGeoip?: boolean | ||
} | ||
): Promise<JsonType | undefined> { | ||
const { groups, personProperties, groupProperties } = options || {} | ||
const { groups, personProperties, groupProperties, disableGeoip } = options || {} | ||
let { onlyEvaluateLocally, sendFeatureFlagEvents } = options || {} | ||
@@ -255,3 +269,10 @@ let response = undefined | ||
if (!payloadWasLocallyEvaluated && !onlyEvaluateLocally) { | ||
response = await super.getFeatureFlagPayloadStateless(key, distinctId, groups, personProperties, groupProperties) | ||
response = await super.getFeatureFlagPayloadStateless( | ||
key, | ||
distinctId, | ||
groups, | ||
personProperties, | ||
groupProperties, | ||
disableGeoip | ||
) | ||
} | ||
@@ -275,2 +296,3 @@ | ||
sendFeatureFlagEvents?: boolean | ||
disableGeoip?: boolean | ||
} | ||
@@ -292,2 +314,3 @@ ): Promise<boolean | undefined> { | ||
onlyEvaluateLocally?: boolean | ||
disableGeoip?: boolean | ||
} | ||
@@ -306,5 +329,6 @@ ): Promise<Record<string, string | boolean>> { | ||
onlyEvaluateLocally?: boolean | ||
disableGeoip?: boolean | ||
} | ||
): Promise<PosthogFlagsAndPayloadsResponse> { | ||
const { groups, personProperties, groupProperties } = options || {} | ||
const { groups, personProperties, groupProperties, disableGeoip } = options || {} | ||
let { onlyEvaluateLocally } = options || {} | ||
@@ -338,3 +362,4 @@ | ||
personProperties, | ||
groupProperties | ||
groupProperties, | ||
disableGeoip | ||
) | ||
@@ -354,4 +379,4 @@ featureFlags = { | ||
groupIdentify({ groupType, groupKey, properties, distinctId }: GroupIdentifyMessage): void { | ||
super.groupIdentifyStateless(groupType, groupKey, properties, undefined, distinctId) | ||
groupIdentify({ groupType, groupKey, properties, distinctId, disableGeoip }: GroupIdentifyMessage): void { | ||
super.groupIdentifyStateless(groupType, groupKey, properties, { disableGeoip }, distinctId) | ||
} | ||
@@ -358,0 +383,0 @@ |
@@ -6,2 +6,3 @@ import { JsonType } from '../../posthog-core/src' | ||
properties?: Record<string | number, any> | ||
disableGeoip?: boolean | ||
} | ||
@@ -21,2 +22,3 @@ | ||
distinctId?: string // optional distinctId to associate message with a person | ||
disableGeoip?: boolean | ||
} | ||
@@ -23,0 +25,0 @@ |
@@ -15,3 +15,4 @@ // import { PostHog } from '../' | ||
const call = mockedFetch.mock.calls.find((x) => (x[0] as string).includes('/batch/')) | ||
// reverse mock calls array to get the last call | ||
const call = mockedFetch.mock.calls.reverse().find((x) => (x[0] as string).includes('/batch/')) | ||
if (!call) { | ||
@@ -55,3 +56,3 @@ return undefined | ||
const batchEvents = getLastBatchEvents() | ||
expect(batchEvents).toMatchObject([ | ||
expect(batchEvents).toEqual([ | ||
{ | ||
@@ -63,3 +64,10 @@ distinct_id: '123', | ||
foo: 'bar', | ||
$geoip_disable: true, | ||
$lib: 'posthog-node', | ||
$lib_version: '1.2.3', | ||
}, | ||
timestamp: expect.any(String), | ||
type: 'capture', | ||
library: 'posthog-node', | ||
library_version: '1.2.3', | ||
}, | ||
@@ -103,2 +111,3 @@ ]) | ||
foo: 'bar', | ||
$geoip_disable: true, | ||
}), | ||
@@ -124,2 +133,3 @@ library: 'posthog-node', | ||
}, | ||
$geoip_disable: true, | ||
}, | ||
@@ -143,2 +153,3 @@ }, | ||
}, | ||
$geoip_disable: true, | ||
}, | ||
@@ -161,2 +172,3 @@ }, | ||
alias: '1234', | ||
$geoip_disable: true, | ||
}, | ||
@@ -180,2 +192,79 @@ }, | ||
}) | ||
it('should respect disableGeoip setting if passed in', async () => { | ||
expect(mockedFetch).toHaveBeenCalledTimes(0) | ||
posthog.capture({ | ||
distinctId: '123', | ||
event: 'test-event', | ||
properties: { foo: 'bar' }, | ||
groups: { org: 123 }, | ||
disableGeoip: false, | ||
}) | ||
jest.runOnlyPendingTimers() | ||
const batchEvents = getLastBatchEvents() | ||
expect(batchEvents?.[0].properties).toEqual({ | ||
$groups: { org: 123 }, | ||
foo: 'bar', | ||
$lib: 'posthog-node', | ||
$lib_version: '1.2.3', | ||
}) | ||
}) | ||
it('should use default is set, and override on specific disableGeoip calls', async () => { | ||
expect(mockedFetch).toHaveBeenCalledTimes(0) | ||
const client = new PostHog('TEST_API_KEY', { | ||
host: 'http://example.com', | ||
disableGeoip: false, | ||
}) | ||
client.debug() | ||
client.capture({ distinctId: '123', event: 'test-event', properties: { foo: 'bar' }, groups: { org: 123 } }) | ||
jest.runOnlyPendingTimers() | ||
let batchEvents = getLastBatchEvents() | ||
expect(batchEvents?.[0].properties).toEqual({ | ||
$groups: { org: 123 }, | ||
foo: 'bar', | ||
$lib: 'posthog-node', | ||
$lib_version: '1.2.3', | ||
}) | ||
client.capture({ | ||
distinctId: '123', | ||
event: 'test-event', | ||
properties: { foo: 'bar' }, | ||
groups: { org: 123 }, | ||
disableGeoip: true, | ||
}) | ||
jest.runOnlyPendingTimers() | ||
batchEvents = getLastBatchEvents() | ||
console.warn(batchEvents) | ||
expect(batchEvents?.[0].properties).toEqual({ | ||
$groups: { org: 123 }, | ||
foo: 'bar', | ||
$lib: 'posthog-node', | ||
$lib_version: '1.2.3', | ||
$geoip_disable: true, | ||
}) | ||
client.capture({ | ||
distinctId: '123', | ||
event: 'test-event', | ||
properties: { foo: 'bar' }, | ||
groups: { org: 123 }, | ||
disableGeoip: false, | ||
}) | ||
jest.runOnlyPendingTimers() | ||
batchEvents = getLastBatchEvents() | ||
expect(batchEvents?.[0].properties).toEqual({ | ||
$groups: { org: 123 }, | ||
foo: 'bar', | ||
$lib: 'posthog-node', | ||
$lib_version: '1.2.3', | ||
}) | ||
await client.shutdownAsync() | ||
}) | ||
}) | ||
@@ -254,2 +343,3 @@ | ||
$lib: 'posthog-node', | ||
$geoip_disable: true, | ||
}, | ||
@@ -278,2 +368,3 @@ }, | ||
$lib: 'posthog-node', | ||
$geoip_disable: true, | ||
}, | ||
@@ -305,3 +396,2 @@ }, | ||
host: 'http://example.com', | ||
// flushAt: 1, | ||
}) | ||
@@ -316,2 +406,6 @@ }) | ||
expect(mockedFetch).toHaveBeenCalledTimes(1) | ||
expect(mockedFetch).toHaveBeenCalledWith( | ||
'http://example.com/decide/?v=3', | ||
expect.objectContaining({ method: 'POST', body: expect.stringContaining('"geoip_disable":true') }) | ||
) | ||
}) | ||
@@ -362,2 +456,3 @@ | ||
$lib_version: '1.2.3', | ||
$geoip_disable: true, | ||
}), | ||
@@ -370,4 +465,48 @@ }) | ||
expect(mockedFetch).not.toHaveBeenCalledWith(...anyLocalEvalCall) | ||
expect(mockedFetch).toHaveBeenCalledWith( | ||
'http://example.com/decide/?v=3', | ||
expect.objectContaining({ method: 'POST', body: expect.stringContaining('"geoip_disable":true') }) | ||
) | ||
}) | ||
it('captures feature flags with same geoip setting as capture', async () => { | ||
mockedFetch.mockClear() | ||
mockedFetch.mockClear() | ||
expect(mockedFetch).toHaveBeenCalledTimes(0) | ||
posthog = new PostHog('TEST_API_KEY', { | ||
host: 'http://example.com', | ||
flushAt: 1, | ||
}) | ||
posthog.capture({ | ||
distinctId: 'distinct_id', | ||
event: 'node test event', | ||
sendFeatureFlags: true, | ||
disableGeoip: false, | ||
}) | ||
expect(mockedFetch).toHaveBeenCalledWith( | ||
'http://example.com/decide/?v=3', | ||
expect.objectContaining({ method: 'POST', body: expect.not.stringContaining('geoip_disable') }) | ||
) | ||
jest.runOnlyPendingTimers() | ||
await waitForPromises() | ||
expect(getLastBatchEvents()?.[0].properties).toEqual({ | ||
$active_feature_flags: ['feature-1', 'feature-2', 'feature-variant'], | ||
'$feature/feature-1': true, | ||
'$feature/feature-2': true, | ||
'$feature/feature-variant': 'variant', | ||
$lib: 'posthog-node', | ||
$lib_version: '1.2.3', | ||
}) | ||
// no calls to `/local_evaluation` | ||
expect(mockedFetch).not.toHaveBeenCalledWith(...anyLocalEvalCall) | ||
}) | ||
it('manages memory well when sending feature flags', async () => { | ||
@@ -479,2 +618,3 @@ const flags = { | ||
locally_evaluated: true, | ||
$geoip_disable: true, | ||
}), | ||
@@ -500,2 +640,3 @@ }) | ||
personProperties: { region: 'USA', name: 'Aloha' }, | ||
disableGeoip: false, | ||
}) | ||
@@ -510,12 +651,12 @@ ).toEqual(true) | ||
event: '$feature_flag_called', | ||
properties: expect.objectContaining({ | ||
$feature_flag: 'beta-feature', | ||
$feature_flag_response: true, | ||
$lib: 'posthog-node', | ||
$lib_version: '1.2.3', | ||
locally_evaluated: true, | ||
$groups: { x: 'y' }, | ||
}), | ||
}) | ||
) | ||
expect(getLastBatchEvents()?.[0].properties).toEqual({ | ||
$feature_flag: 'beta-feature', | ||
$feature_flag_response: true, | ||
$lib: 'posthog-node', | ||
$lib_version: '1.2.3', | ||
locally_evaluated: true, | ||
$groups: { x: 'y' }, | ||
}) | ||
mockedFetch.mockClear() | ||
@@ -579,2 +720,6 @@ | ||
expect(mockedFetch).toHaveBeenCalledTimes(1) | ||
expect(mockedFetch).toHaveBeenCalledWith( | ||
'http://example.com/decide/?v=3', | ||
expect.objectContaining({ method: 'POST', body: expect.stringContaining('"geoip_disable":true') }) | ||
) | ||
}) | ||
@@ -589,3 +734,24 @@ | ||
}) | ||
it('should do getFeatureFlags with geoip disabled and enabled', async () => { | ||
expect(mockedFetch).toHaveBeenCalledTimes(0) | ||
await expect( | ||
posthog.getFeatureFlagPayload('feature-variant', '123', 'variant', { groups: { org: '123' } }) | ||
).resolves.toEqual(2) | ||
expect(mockedFetch).toHaveBeenCalledTimes(1) | ||
expect(mockedFetch).toHaveBeenCalledWith( | ||
'http://example.com/decide/?v=3', | ||
expect.objectContaining({ method: 'POST', body: expect.stringContaining('"geoip_disable":true') }) | ||
) | ||
mockedFetch.mockClear() | ||
await expect(posthog.isFeatureEnabled('feature-variant', '123', { disableGeoip: false })).resolves.toEqual(true) | ||
expect(mockedFetch).toHaveBeenCalledTimes(1) | ||
expect(mockedFetch).toHaveBeenCalledWith( | ||
'http://example.com/decide/?v=3', | ||
expect.objectContaining({ method: 'POST', body: expect.not.stringContaining('geoip_disable') }) | ||
) | ||
}) | ||
}) | ||
}) |
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
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
837320
11837
0