posthog-node 2.6.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/lib/index.cjs.js +173 -66
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +21 -10
- package/lib/index.esm.js +173 -66
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +7 -6
- package/lib/posthog-core/src/types.d.ts +2 -0
- package/lib/posthog-core/src/utils.d.ts +1 -1
- package/lib/posthog-node/src/posthog-node.d.ts +9 -3
- package/lib/posthog-node/src/types.d.ts +2 -0
- package/package.json +1 -1
- package/src/feature-flags.ts +1 -1
- package/src/fetch.ts +4 -2
- package/src/posthog-node.ts +42 -17
- package/src/types.ts +2 -0
- package/test/feature-flags.spec.ts +43 -6
- package/test/posthog-node.spec.ts +194 -15
|
@@ -13,6 +13,7 @@ export declare abstract class PostHogCoreStateless {
|
|
|
13
13
|
private removeDebugCallback?;
|
|
14
14
|
private debugMode;
|
|
15
15
|
private pendingPromises;
|
|
16
|
+
private disableGeoip;
|
|
16
17
|
private _optoutOverride;
|
|
17
18
|
protected _events: SimpleEventEmitter;
|
|
18
19
|
protected _flushTimer?: any;
|
|
@@ -40,7 +41,7 @@ export declare abstract class PostHogCoreStateless {
|
|
|
40
41
|
}, options?: PosthogCaptureOptions): this;
|
|
41
42
|
protected aliasStateless(alias: string, distinctId: string, properties?: {
|
|
42
43
|
[key: string]: any;
|
|
43
|
-
}): this;
|
|
44
|
+
}, options?: PosthogCaptureOptions): this;
|
|
44
45
|
/***
|
|
45
46
|
*** GROUPS
|
|
46
47
|
***/
|
|
@@ -49,12 +50,12 @@ export declare abstract class PostHogCoreStateless {
|
|
|
49
50
|
*** FEATURE FLAGS
|
|
50
51
|
***/
|
|
51
52
|
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>;
|
|
52
|
-
protected getFeatureFlagStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string
|
|
53
|
-
protected getFeatureFlagPayloadStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string
|
|
54
|
-
protected getFeatureFlagPayloadsStateless(distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string
|
|
53
|
+
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>;
|
|
54
|
+
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>;
|
|
55
|
+
protected getFeatureFlagPayloadsStateless(distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<PostHogDecideResponse['featureFlagPayloads'] | undefined>;
|
|
55
56
|
protected _parsePayload(response: any): any;
|
|
56
|
-
protected getFeatureFlagsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string
|
|
57
|
-
protected getFeatureFlagsAndPayloadsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string
|
|
57
|
+
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>;
|
|
58
|
+
protected getFeatureFlagsAndPayloadsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<{
|
|
58
59
|
flags: PostHogDecideResponse['featureFlags'] | undefined;
|
|
59
60
|
payloads: PostHogDecideResponse['featureFlagPayloads'] | undefined;
|
|
60
61
|
}>;
|
|
@@ -17,6 +17,7 @@ export declare type PosthogCoreOptions = {
|
|
|
17
17
|
requestTimeout?: number;
|
|
18
18
|
sessionExpirationTimeSeconds?: number;
|
|
19
19
|
captureMode?: 'json' | 'form';
|
|
20
|
+
disableGeoip?: boolean;
|
|
20
21
|
};
|
|
21
22
|
export declare enum PostHogPersistedProperty {
|
|
22
23
|
AnonymousId = "anonymous_id",
|
|
@@ -44,6 +45,7 @@ export declare type PostHogFetchOptions = {
|
|
|
44
45
|
};
|
|
45
46
|
export declare type PosthogCaptureOptions = {
|
|
46
47
|
timestamp?: Date;
|
|
48
|
+
disableGeoip?: boolean;
|
|
47
49
|
};
|
|
48
50
|
export declare type PostHogFetchResponse = {
|
|
49
51
|
status: number;
|
|
@@ -3,7 +3,7 @@ export declare function removeTrailingSlash(url: string): string;
|
|
|
3
3
|
export interface RetriableOptions {
|
|
4
4
|
retryCount?: number;
|
|
5
5
|
retryDelay?: number;
|
|
6
|
-
retryCheck?: (err: any) =>
|
|
6
|
+
retryCheck?: (err: any) => boolean;
|
|
7
7
|
}
|
|
8
8
|
export declare function retriable<T>(fn: () => Promise<T>, props?: RetriableOptions): Promise<T>;
|
|
9
9
|
export declare function generateUUID(globalThis?: any): string;
|
|
@@ -24,11 +24,12 @@ export declare class PostHog extends PostHogCoreStateless implements PostHogNode
|
|
|
24
24
|
enable(): void;
|
|
25
25
|
disable(): void;
|
|
26
26
|
debug(enabled?: boolean): void;
|
|
27
|
-
capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp }: EventMessageV1): void;
|
|
28
|
-
identify({ distinctId, properties }: IdentifyMessageV1): void;
|
|
27
|
+
capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp, disableGeoip }: EventMessageV1): void;
|
|
28
|
+
identify({ distinctId, properties, disableGeoip }: IdentifyMessageV1): void;
|
|
29
29
|
alias(data: {
|
|
30
30
|
distinctId: string;
|
|
31
31
|
alias: string;
|
|
32
|
+
disableGeoip?: boolean;
|
|
32
33
|
}): void;
|
|
33
34
|
getFeatureFlag(key: string, distinctId: string, options?: {
|
|
34
35
|
groups?: Record<string, string>;
|
|
@@ -36,6 +37,7 @@ export declare class PostHog extends PostHogCoreStateless implements PostHogNode
|
|
|
36
37
|
groupProperties?: Record<string, Record<string, string>>;
|
|
37
38
|
onlyEvaluateLocally?: boolean;
|
|
38
39
|
sendFeatureFlagEvents?: boolean;
|
|
40
|
+
disableGeoip?: boolean;
|
|
39
41
|
}): Promise<string | boolean | undefined>;
|
|
40
42
|
getFeatureFlagPayload(key: string, distinctId: string, matchValue?: string | boolean, options?: {
|
|
41
43
|
groups?: Record<string, string>;
|
|
@@ -43,6 +45,7 @@ export declare class PostHog extends PostHogCoreStateless implements PostHogNode
|
|
|
43
45
|
groupProperties?: Record<string, Record<string, string>>;
|
|
44
46
|
onlyEvaluateLocally?: boolean;
|
|
45
47
|
sendFeatureFlagEvents?: boolean;
|
|
48
|
+
disableGeoip?: boolean;
|
|
46
49
|
}): Promise<JsonType | undefined>;
|
|
47
50
|
isFeatureEnabled(key: string, distinctId: string, options?: {
|
|
48
51
|
groups?: Record<string, string>;
|
|
@@ -50,20 +53,23 @@ export declare class PostHog extends PostHogCoreStateless implements PostHogNode
|
|
|
50
53
|
groupProperties?: Record<string, Record<string, string>>;
|
|
51
54
|
onlyEvaluateLocally?: boolean;
|
|
52
55
|
sendFeatureFlagEvents?: boolean;
|
|
56
|
+
disableGeoip?: boolean;
|
|
53
57
|
}): Promise<boolean | undefined>;
|
|
54
58
|
getAllFlags(distinctId: string, options?: {
|
|
55
59
|
groups?: Record<string, string>;
|
|
56
60
|
personProperties?: Record<string, string>;
|
|
57
61
|
groupProperties?: Record<string, Record<string, string>>;
|
|
58
62
|
onlyEvaluateLocally?: boolean;
|
|
63
|
+
disableGeoip?: boolean;
|
|
59
64
|
}): Promise<Record<string, string | boolean>>;
|
|
60
65
|
getAllFlagsAndPayloads(distinctId: string, options?: {
|
|
61
66
|
groups?: Record<string, string>;
|
|
62
67
|
personProperties?: Record<string, string>;
|
|
63
68
|
groupProperties?: Record<string, Record<string, string>>;
|
|
64
69
|
onlyEvaluateLocally?: boolean;
|
|
70
|
+
disableGeoip?: boolean;
|
|
65
71
|
}): Promise<PosthogFlagsAndPayloadsResponse>;
|
|
66
|
-
groupIdentify({ groupType, groupKey, properties, distinctId }: GroupIdentifyMessage): void;
|
|
72
|
+
groupIdentify({ groupType, groupKey, properties, distinctId, disableGeoip }: GroupIdentifyMessage): void;
|
|
67
73
|
reloadFeatureFlags(): Promise<void>;
|
|
68
74
|
shutdown(): void;
|
|
69
75
|
shutdownAsync(): Promise<void>;
|
|
@@ -2,6 +2,7 @@ import { JsonType } from '../../posthog-core/src';
|
|
|
2
2
|
export interface IdentifyMessageV1 {
|
|
3
3
|
distinctId: string;
|
|
4
4
|
properties?: Record<string | number, any>;
|
|
5
|
+
disableGeoip?: boolean;
|
|
5
6
|
}
|
|
6
7
|
export interface EventMessageV1 extends IdentifyMessageV1 {
|
|
7
8
|
event: string;
|
|
@@ -14,6 +15,7 @@ export interface GroupIdentifyMessage {
|
|
|
14
15
|
groupKey: string;
|
|
15
16
|
properties?: Record<string | number, any>;
|
|
16
17
|
distinctId?: string;
|
|
18
|
+
disableGeoip?: boolean;
|
|
17
19
|
}
|
|
18
20
|
export declare type PropertyGroup = {
|
|
19
21
|
type: 'AND' | 'OR';
|
package/package.json
CHANGED
package/src/feature-flags.ts
CHANGED
package/src/fetch.ts
CHANGED
|
@@ -10,11 +10,13 @@ export const fetch = async (url: string, options: PostHogFetchOptions): Promise<
|
|
|
10
10
|
method: options.method.toLowerCase(),
|
|
11
11
|
data: options.body,
|
|
12
12
|
signal: options.signal,
|
|
13
|
+
// fetch only throws on network errors, not on HTTP errors
|
|
14
|
+
validateStatus: () => true,
|
|
13
15
|
})
|
|
14
16
|
|
|
15
17
|
return {
|
|
16
18
|
status: res.status,
|
|
17
|
-
text: () => res.data,
|
|
18
|
-
json: () => res.data,
|
|
19
|
+
text: async () => res.data,
|
|
20
|
+
json: async () => res.data,
|
|
19
21
|
}
|
|
20
22
|
}
|
package/src/posthog-node.ts
CHANGED
|
@@ -97,13 +97,13 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
97
97
|
this.featureFlagsPoller?.debug(enabled)
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp }: EventMessageV1): void {
|
|
100
|
+
capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp, disableGeoip }: EventMessageV1): void {
|
|
101
101
|
const _capture = (props: EventMessageV1['properties']): void => {
|
|
102
|
-
super.captureStateless(distinctId, event, props, { timestamp })
|
|
102
|
+
super.captureStateless(distinctId, event, props, { timestamp, disableGeoip })
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
if (sendFeatureFlags) {
|
|
106
|
-
super.getFeatureFlagsStateless(distinctId, groups).then((flags) => {
|
|
106
|
+
super.getFeatureFlagsStateless(distinctId, groups, undefined, undefined, disableGeoip).then((flags) => {
|
|
107
107
|
const featureVariantProperties: Record<string, string | boolean> = {}
|
|
108
108
|
if (flags) {
|
|
109
109
|
for (const [feature, variant] of Object.entries(flags)) {
|
|
@@ -124,17 +124,21 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
identify({ distinctId, properties }: IdentifyMessageV1): void {
|
|
127
|
+
identify({ distinctId, properties, disableGeoip }: IdentifyMessageV1): void {
|
|
128
128
|
// Catch properties passed as $set and move them to the top level
|
|
129
129
|
const personProperties = properties?.$set || properties
|
|
130
130
|
|
|
131
|
-
super.identifyStateless(
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
super.identifyStateless(
|
|
132
|
+
distinctId,
|
|
133
|
+
{
|
|
134
|
+
$set: personProperties,
|
|
135
|
+
},
|
|
136
|
+
{ disableGeoip }
|
|
137
|
+
)
|
|
134
138
|
}
|
|
135
139
|
|
|
136
|
-
alias(data: { distinctId: string; alias: string }): void {
|
|
137
|
-
super.aliasStateless(data.alias, data.distinctId)
|
|
140
|
+
alias(data: { distinctId: string; alias: string; disableGeoip?: boolean }): void {
|
|
141
|
+
super.aliasStateless(data.alias, data.distinctId, undefined, { disableGeoip: data.disableGeoip })
|
|
138
142
|
}
|
|
139
143
|
|
|
140
144
|
async getFeatureFlag(
|
|
@@ -146,9 +150,10 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
146
150
|
groupProperties?: Record<string, Record<string, string>>
|
|
147
151
|
onlyEvaluateLocally?: boolean
|
|
148
152
|
sendFeatureFlagEvents?: boolean
|
|
153
|
+
disableGeoip?: boolean
|
|
149
154
|
}
|
|
150
155
|
): Promise<string | boolean | undefined> {
|
|
151
|
-
const { groups, personProperties, groupProperties } = options || {}
|
|
156
|
+
const { groups, personProperties, groupProperties, disableGeoip } = options || {}
|
|
152
157
|
let { onlyEvaluateLocally, sendFeatureFlagEvents } = options || {}
|
|
153
158
|
|
|
154
159
|
// set defaults
|
|
@@ -170,7 +175,14 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
170
175
|
const flagWasLocallyEvaluated = response !== undefined
|
|
171
176
|
|
|
172
177
|
if (!flagWasLocallyEvaluated && !onlyEvaluateLocally) {
|
|
173
|
-
response = await super.getFeatureFlagStateless(
|
|
178
|
+
response = await super.getFeatureFlagStateless(
|
|
179
|
+
key,
|
|
180
|
+
distinctId,
|
|
181
|
+
groups,
|
|
182
|
+
personProperties,
|
|
183
|
+
groupProperties,
|
|
184
|
+
disableGeoip
|
|
185
|
+
)
|
|
174
186
|
}
|
|
175
187
|
|
|
176
188
|
const featureFlagReportedKey = `${key}_${response}`
|
|
@@ -197,6 +209,7 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
197
209
|
locally_evaluated: flagWasLocallyEvaluated,
|
|
198
210
|
},
|
|
199
211
|
groups,
|
|
212
|
+
disableGeoip,
|
|
200
213
|
})
|
|
201
214
|
}
|
|
202
215
|
return response
|
|
@@ -212,9 +225,10 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
212
225
|
groupProperties?: Record<string, Record<string, string>>
|
|
213
226
|
onlyEvaluateLocally?: boolean
|
|
214
227
|
sendFeatureFlagEvents?: boolean
|
|
228
|
+
disableGeoip?: boolean
|
|
215
229
|
}
|
|
216
230
|
): Promise<JsonType | undefined> {
|
|
217
|
-
const { groups, personProperties, groupProperties } = options || {}
|
|
231
|
+
const { groups, personProperties, groupProperties, disableGeoip } = options || {}
|
|
218
232
|
let { onlyEvaluateLocally, sendFeatureFlagEvents } = options || {}
|
|
219
233
|
let response = undefined
|
|
220
234
|
|
|
@@ -246,7 +260,14 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
246
260
|
const payloadWasLocallyEvaluated = response !== undefined
|
|
247
261
|
|
|
248
262
|
if (!payloadWasLocallyEvaluated && !onlyEvaluateLocally) {
|
|
249
|
-
response = await super.getFeatureFlagPayloadStateless(
|
|
263
|
+
response = await super.getFeatureFlagPayloadStateless(
|
|
264
|
+
key,
|
|
265
|
+
distinctId,
|
|
266
|
+
groups,
|
|
267
|
+
personProperties,
|
|
268
|
+
groupProperties,
|
|
269
|
+
disableGeoip
|
|
270
|
+
)
|
|
250
271
|
}
|
|
251
272
|
|
|
252
273
|
try {
|
|
@@ -265,6 +286,7 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
265
286
|
groupProperties?: Record<string, Record<string, string>>
|
|
266
287
|
onlyEvaluateLocally?: boolean
|
|
267
288
|
sendFeatureFlagEvents?: boolean
|
|
289
|
+
disableGeoip?: boolean
|
|
268
290
|
}
|
|
269
291
|
): Promise<boolean | undefined> {
|
|
270
292
|
const feat = await this.getFeatureFlag(key, distinctId, options)
|
|
@@ -281,6 +303,7 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
281
303
|
personProperties?: Record<string, string>
|
|
282
304
|
groupProperties?: Record<string, Record<string, string>>
|
|
283
305
|
onlyEvaluateLocally?: boolean
|
|
306
|
+
disableGeoip?: boolean
|
|
284
307
|
}
|
|
285
308
|
): Promise<Record<string, string | boolean>> {
|
|
286
309
|
const response = await this.getAllFlagsAndPayloads(distinctId, options)
|
|
@@ -294,9 +317,10 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
294
317
|
personProperties?: Record<string, string>
|
|
295
318
|
groupProperties?: Record<string, Record<string, string>>
|
|
296
319
|
onlyEvaluateLocally?: boolean
|
|
320
|
+
disableGeoip?: boolean
|
|
297
321
|
}
|
|
298
322
|
): Promise<PosthogFlagsAndPayloadsResponse> {
|
|
299
|
-
const { groups, personProperties, groupProperties } = options || {}
|
|
323
|
+
const { groups, personProperties, groupProperties, disableGeoip } = options || {}
|
|
300
324
|
let { onlyEvaluateLocally } = options || {}
|
|
301
325
|
|
|
302
326
|
// set defaults
|
|
@@ -325,7 +349,8 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
325
349
|
distinctId,
|
|
326
350
|
groups,
|
|
327
351
|
personProperties,
|
|
328
|
-
groupProperties
|
|
352
|
+
groupProperties,
|
|
353
|
+
disableGeoip
|
|
329
354
|
)
|
|
330
355
|
featureFlags = {
|
|
331
356
|
...featureFlags,
|
|
@@ -340,8 +365,8 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
340
365
|
return { featureFlags, featureFlagPayloads }
|
|
341
366
|
}
|
|
342
367
|
|
|
343
|
-
groupIdentify({ groupType, groupKey, properties, distinctId }: GroupIdentifyMessage): void {
|
|
344
|
-
super.groupIdentifyStateless(groupType, groupKey, properties,
|
|
368
|
+
groupIdentify({ groupType, groupKey, properties, distinctId, disableGeoip }: GroupIdentifyMessage): void {
|
|
369
|
+
super.groupIdentifyStateless(groupType, groupKey, properties, { disableGeoip }, distinctId)
|
|
345
370
|
}
|
|
346
371
|
|
|
347
372
|
async reloadFeatureFlags(): Promise<void> {
|
package/src/types.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { JsonType } from '../../posthog-core/src'
|
|
|
3
3
|
export interface IdentifyMessageV1 {
|
|
4
4
|
distinctId: string
|
|
5
5
|
properties?: Record<string | number, any>
|
|
6
|
+
disableGeoip?: boolean
|
|
6
7
|
}
|
|
7
8
|
|
|
8
9
|
export interface EventMessageV1 extends IdentifyMessageV1 {
|
|
@@ -17,6 +18,7 @@ export interface GroupIdentifyMessage {
|
|
|
17
18
|
groupKey: string // Unique identifier for the group
|
|
18
19
|
properties?: Record<string | number, any>
|
|
19
20
|
distinctId?: string // optional distinctId to associate message with a person
|
|
21
|
+
disableGeoip?: boolean
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
export type PropertyGroup = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// import { PostHog } from '../'
|
|
1
|
+
// import { PostHog, PostHogOptions } from '../'
|
|
2
2
|
// Uncomment below line while developing to not compile code everytime
|
|
3
|
-
import { PostHog as PostHog } from '../src/posthog-node'
|
|
3
|
+
import { PostHog as PostHog, PostHogOptions } from '../src/posthog-node'
|
|
4
4
|
import { matchProperty, InconclusiveMatchError } from '../src/feature-flags'
|
|
5
5
|
jest.mock('../src/fetch')
|
|
6
6
|
import { fetch } from '../src/fetch'
|
|
@@ -9,6 +9,10 @@ jest.spyOn(global.console, 'debug').mockImplementation()
|
|
|
9
9
|
|
|
10
10
|
const mockedFetch = jest.mocked(fetch, true)
|
|
11
11
|
|
|
12
|
+
const posthogImmediateResolveOptions: PostHogOptions = {
|
|
13
|
+
fetchRetryCount: 0,
|
|
14
|
+
}
|
|
15
|
+
|
|
12
16
|
export const apiImplementation = ({
|
|
13
17
|
localFlags,
|
|
14
18
|
decideFlags,
|
|
@@ -105,6 +109,7 @@ describe('local evaluation', () => {
|
|
|
105
109
|
posthog = new PostHog('TEST_API_KEY', {
|
|
106
110
|
host: 'http://example.com',
|
|
107
111
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
112
|
+
...posthogImmediateResolveOptions,
|
|
108
113
|
})
|
|
109
114
|
|
|
110
115
|
expect(
|
|
@@ -151,6 +156,7 @@ describe('local evaluation', () => {
|
|
|
151
156
|
posthog = new PostHog('TEST_API_KEY', {
|
|
152
157
|
host: 'http://example.com',
|
|
153
158
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
159
|
+
...posthogImmediateResolveOptions,
|
|
154
160
|
})
|
|
155
161
|
|
|
156
162
|
// # groups not passed in, hence false
|
|
@@ -231,6 +237,7 @@ describe('local evaluation', () => {
|
|
|
231
237
|
posthog = new PostHog('TEST_API_KEY', {
|
|
232
238
|
host: 'http://example.com',
|
|
233
239
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
240
|
+
...posthogImmediateResolveOptions,
|
|
234
241
|
})
|
|
235
242
|
// # group_type_mappings not present, so fallback to `/decide`
|
|
236
243
|
expect(
|
|
@@ -304,6 +311,7 @@ describe('local evaluation', () => {
|
|
|
304
311
|
posthog = new PostHog('TEST_API_KEY', {
|
|
305
312
|
host: 'http://example.com',
|
|
306
313
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
314
|
+
...posthogImmediateResolveOptions,
|
|
307
315
|
})
|
|
308
316
|
|
|
309
317
|
expect(
|
|
@@ -336,6 +344,7 @@ describe('local evaluation', () => {
|
|
|
336
344
|
groups: {},
|
|
337
345
|
person_properties: { region: 'USA', email: 'a@b.com' },
|
|
338
346
|
group_properties: {},
|
|
347
|
+
geoip_disable: true,
|
|
339
348
|
}),
|
|
340
349
|
})
|
|
341
350
|
)
|
|
@@ -354,6 +363,7 @@ describe('local evaluation', () => {
|
|
|
354
363
|
groups: {},
|
|
355
364
|
person_properties: { doesnt_matter: '1' },
|
|
356
365
|
group_properties: {},
|
|
366
|
+
geoip_disable: true,
|
|
357
367
|
}),
|
|
358
368
|
})
|
|
359
369
|
)
|
|
@@ -424,6 +434,7 @@ describe('local evaluation', () => {
|
|
|
424
434
|
posthog = new PostHog('TEST_API_KEY', {
|
|
425
435
|
host: 'http://example.com',
|
|
426
436
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
437
|
+
...posthogImmediateResolveOptions,
|
|
427
438
|
})
|
|
428
439
|
|
|
429
440
|
// # beta-feature fallbacks to decide because property type is unknown
|
|
@@ -486,6 +497,7 @@ describe('local evaluation', () => {
|
|
|
486
497
|
posthog = new PostHog('TEST_API_KEY', {
|
|
487
498
|
host: 'http://example.com',
|
|
488
499
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
500
|
+
...posthogImmediateResolveOptions,
|
|
489
501
|
})
|
|
490
502
|
|
|
491
503
|
// # beta-feature should fallback to decide because property type is unknown
|
|
@@ -534,6 +546,7 @@ describe('local evaluation', () => {
|
|
|
534
546
|
posthog = new PostHog('TEST_API_KEY', {
|
|
535
547
|
host: 'http://example.com',
|
|
536
548
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
549
|
+
...posthogImmediateResolveOptions,
|
|
537
550
|
})
|
|
538
551
|
|
|
539
552
|
// # beta-feature resolves to False
|
|
@@ -574,12 +587,20 @@ describe('local evaluation', () => {
|
|
|
574
587
|
posthog = new PostHog('TEST_API_KEY', {
|
|
575
588
|
host: 'http://example.com',
|
|
576
589
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
590
|
+
...posthogImmediateResolveOptions,
|
|
591
|
+
})
|
|
592
|
+
|
|
593
|
+
let err: any = null
|
|
594
|
+
posthog.on('error', (e) => {
|
|
595
|
+
err = e
|
|
577
596
|
})
|
|
578
597
|
|
|
579
598
|
// # beta-feature2 falls back to decide, which on error returns undefined
|
|
580
599
|
expect(await posthog.getFeatureFlag('beta-feature2', 'some-distinct-id')).toEqual(undefined)
|
|
581
600
|
expect(await posthog.isFeatureEnabled('beta-feature2', 'some-distinct-id')).toEqual(undefined)
|
|
582
601
|
expect(mockedFetch).toHaveBeenCalledWith(...anyDecideCall)
|
|
602
|
+
await posthog.shutdownAsync()
|
|
603
|
+
expect(err).toHaveProperty('name', 'PostHogFetchHttpError')
|
|
583
604
|
})
|
|
584
605
|
|
|
585
606
|
it('experience continuity flags are not evaluated locally', async () => {
|
|
@@ -610,6 +631,7 @@ describe('local evaluation', () => {
|
|
|
610
631
|
posthog = new PostHog('TEST_API_KEY', {
|
|
611
632
|
host: 'http://example.com',
|
|
612
633
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
634
|
+
...posthogImmediateResolveOptions,
|
|
613
635
|
})
|
|
614
636
|
|
|
615
637
|
// # beta-feature2 falls back to decide, which on error returns default
|
|
@@ -678,6 +700,7 @@ describe('local evaluation', () => {
|
|
|
678
700
|
posthog = new PostHog('TEST_API_KEY', {
|
|
679
701
|
host: 'http://example.com',
|
|
680
702
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
703
|
+
...posthogImmediateResolveOptions,
|
|
681
704
|
})
|
|
682
705
|
|
|
683
706
|
// # beta-feature value overridden by /decide
|
|
@@ -761,6 +784,7 @@ describe('local evaluation', () => {
|
|
|
761
784
|
posthog = new PostHog('TEST_API_KEY', {
|
|
762
785
|
host: 'http://example.com',
|
|
763
786
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
787
|
+
...posthogImmediateResolveOptions,
|
|
764
788
|
})
|
|
765
789
|
|
|
766
790
|
// # beta-feature value overridden by /decide
|
|
@@ -833,6 +857,7 @@ describe('local evaluation', () => {
|
|
|
833
857
|
posthog = new PostHog('TEST_API_KEY', {
|
|
834
858
|
host: 'http://example.com',
|
|
835
859
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
860
|
+
...posthogImmediateResolveOptions,
|
|
836
861
|
})
|
|
837
862
|
|
|
838
863
|
// # beta-feature2 has no value
|
|
@@ -914,6 +939,7 @@ describe('local evaluation', () => {
|
|
|
914
939
|
posthog = new PostHog('TEST_API_KEY', {
|
|
915
940
|
host: 'http://example.com',
|
|
916
941
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
942
|
+
...posthogImmediateResolveOptions,
|
|
917
943
|
})
|
|
918
944
|
|
|
919
945
|
expect(
|
|
@@ -938,6 +964,7 @@ describe('local evaluation', () => {
|
|
|
938
964
|
posthog = new PostHog('TEST_API_KEY', {
|
|
939
965
|
host: 'http://example.com',
|
|
940
966
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
967
|
+
...posthogImmediateResolveOptions,
|
|
941
968
|
})
|
|
942
969
|
|
|
943
970
|
expect(await posthog.getAllFlags('distinct-id')).toEqual({
|
|
@@ -963,6 +990,7 @@ describe('local evaluation', () => {
|
|
|
963
990
|
posthog = new PostHog('TEST_API_KEY', {
|
|
964
991
|
host: 'http://example.com',
|
|
965
992
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
993
|
+
...posthogImmediateResolveOptions,
|
|
966
994
|
})
|
|
967
995
|
|
|
968
996
|
expect((await posthog.getAllFlagsAndPayloads('distinct-id')).featureFlagPayloads).toEqual({
|
|
@@ -1019,6 +1047,7 @@ describe('local evaluation', () => {
|
|
|
1019
1047
|
posthog = new PostHog('TEST_API_KEY', {
|
|
1020
1048
|
host: 'http://example.com',
|
|
1021
1049
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
1050
|
+
...posthogImmediateResolveOptions,
|
|
1022
1051
|
})
|
|
1023
1052
|
|
|
1024
1053
|
expect(await posthog.getAllFlags('distinct-id')).toEqual({ 'beta-feature': true, 'disabled-feature': false })
|
|
@@ -1077,6 +1106,7 @@ describe('local evaluation', () => {
|
|
|
1077
1106
|
posthog = new PostHog('TEST_API_KEY', {
|
|
1078
1107
|
host: 'http://example.com',
|
|
1079
1108
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
1109
|
+
...posthogImmediateResolveOptions,
|
|
1080
1110
|
})
|
|
1081
1111
|
|
|
1082
1112
|
expect((await posthog.getAllFlagsAndPayloads('distinct-id')).featureFlagPayloads).toEqual({ 'beta-feature': 'new' })
|
|
@@ -1129,6 +1159,7 @@ describe('local evaluation', () => {
|
|
|
1129
1159
|
posthog = new PostHog('TEST_API_KEY', {
|
|
1130
1160
|
host: 'http://example.com',
|
|
1131
1161
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
1162
|
+
...posthogImmediateResolveOptions,
|
|
1132
1163
|
})
|
|
1133
1164
|
|
|
1134
1165
|
expect(await posthog.getAllFlags('distinct-id')).toEqual({ 'beta-feature': true, 'disabled-feature': false })
|
|
@@ -1236,6 +1267,7 @@ describe('local evaluation', () => {
|
|
|
1236
1267
|
posthog = new PostHog('TEST_API_KEY', {
|
|
1237
1268
|
host: 'http://example.com',
|
|
1238
1269
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
1270
|
+
...posthogImmediateResolveOptions,
|
|
1239
1271
|
})
|
|
1240
1272
|
|
|
1241
1273
|
expect(
|
|
@@ -1317,6 +1349,7 @@ describe('local evaluation', () => {
|
|
|
1317
1349
|
posthog = new PostHog('TEST_API_KEY', {
|
|
1318
1350
|
host: 'http://example.com',
|
|
1319
1351
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
1352
|
+
...posthogImmediateResolveOptions,
|
|
1320
1353
|
})
|
|
1321
1354
|
|
|
1322
1355
|
expect(
|
|
@@ -1406,6 +1439,7 @@ describe('local evaluation', () => {
|
|
|
1406
1439
|
posthog = new PostHog('TEST_API_KEY', {
|
|
1407
1440
|
host: 'http://example.com',
|
|
1408
1441
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
1442
|
+
...posthogImmediateResolveOptions,
|
|
1409
1443
|
})
|
|
1410
1444
|
|
|
1411
1445
|
expect(
|
|
@@ -1487,6 +1521,7 @@ describe('local evaluation', () => {
|
|
|
1487
1521
|
posthog = new PostHog('TEST_API_KEY', {
|
|
1488
1522
|
host: 'http://example.com',
|
|
1489
1523
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
1524
|
+
...posthogImmediateResolveOptions,
|
|
1490
1525
|
})
|
|
1491
1526
|
|
|
1492
1527
|
expect(
|
|
@@ -1558,6 +1593,7 @@ describe('local evaluation', () => {
|
|
|
1558
1593
|
posthog = new PostHog('TEST_API_KEY', {
|
|
1559
1594
|
host: 'http://example.com',
|
|
1560
1595
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
1596
|
+
...posthogImmediateResolveOptions,
|
|
1561
1597
|
})
|
|
1562
1598
|
|
|
1563
1599
|
expect(
|
|
@@ -1630,6 +1666,7 @@ describe('local evaluation', () => {
|
|
|
1630
1666
|
posthog = new PostHog('TEST_API_KEY', {
|
|
1631
1667
|
host: 'http://example.com',
|
|
1632
1668
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
1669
|
+
...posthogImmediateResolveOptions,
|
|
1633
1670
|
})
|
|
1634
1671
|
|
|
1635
1672
|
expect(
|
|
@@ -1680,6 +1717,7 @@ describe('local evaluation', () => {
|
|
|
1680
1717
|
posthog = new PostHog('TEST_API_KEY', {
|
|
1681
1718
|
host: 'http://example.com',
|
|
1682
1719
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
1720
|
+
...posthogImmediateResolveOptions,
|
|
1683
1721
|
})
|
|
1684
1722
|
|
|
1685
1723
|
expect(
|
|
@@ -1760,6 +1798,7 @@ describe('local evaluation', () => {
|
|
|
1760
1798
|
posthog = new PostHog('TEST_API_KEY', {
|
|
1761
1799
|
host: 'http://example.com',
|
|
1762
1800
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
1801
|
+
...posthogImmediateResolveOptions,
|
|
1763
1802
|
})
|
|
1764
1803
|
|
|
1765
1804
|
expect(
|
|
@@ -1988,10 +2027,6 @@ describe('consistency tests', () => {
|
|
|
1988
2027
|
let posthog: PostHog
|
|
1989
2028
|
jest.useFakeTimers()
|
|
1990
2029
|
|
|
1991
|
-
afterEach(async () => {
|
|
1992
|
-
await posthog.shutdownAsync()
|
|
1993
|
-
})
|
|
1994
|
-
|
|
1995
2030
|
it('is consistent for simple flags', () => {
|
|
1996
2031
|
const flags = {
|
|
1997
2032
|
flags: [
|
|
@@ -2013,6 +2048,7 @@ describe('consistency tests', () => {
|
|
|
2013
2048
|
posthog = new PostHog('TEST_API_KEY', {
|
|
2014
2049
|
host: 'http://example.com',
|
|
2015
2050
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
2051
|
+
...posthogImmediateResolveOptions,
|
|
2016
2052
|
})
|
|
2017
2053
|
|
|
2018
2054
|
const results = [
|
|
@@ -3055,6 +3091,7 @@ describe('consistency tests', () => {
|
|
|
3055
3091
|
posthog = new PostHog('TEST_API_KEY', {
|
|
3056
3092
|
host: 'http://example.com',
|
|
3057
3093
|
personalApiKey: 'TEST_PERSONAL_API_KEY',
|
|
3094
|
+
...posthogImmediateResolveOptions,
|
|
3058
3095
|
})
|
|
3059
3096
|
|
|
3060
3097
|
const results = [
|