posthog-node 3.6.3 → 4.0.0-beta.1
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 +7 -0
- package/lib/index.cjs.js +1087 -2227
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +47 -25
- package/lib/index.esm.js +1087 -2227
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +44 -30
- package/lib/posthog-core/src/types.d.ts +19 -3
- package/lib/posthog-core/src/utils.d.ts +5 -4
- package/lib/posthog-node/src/posthog-node.d.ts +7 -8
- package/lib/posthog-node/src/types.d.ts +3 -1
- package/lib/posthog-node/test/test-utils.d.ts +8 -0
- package/package.json +1 -1
- package/src/posthog-node.ts +22 -14
- package/src/types.ts +3 -1
- package/test/feature-flags.spec.ts +63 -133
- package/test/posthog-node.spec.ts +1 -2
- package/test/test-utils.ts +64 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export const apiImplementation = ({
|
|
2
|
+
localFlags,
|
|
3
|
+
decideFlags,
|
|
4
|
+
decideFlagPayloads,
|
|
5
|
+
decideStatus = 200,
|
|
6
|
+
}: {
|
|
7
|
+
localFlags?: any
|
|
8
|
+
decideFlags?: any
|
|
9
|
+
decideFlagPayloads?: any
|
|
10
|
+
decideStatus?: number
|
|
11
|
+
}) => {
|
|
12
|
+
return (url: any): Promise<any> => {
|
|
13
|
+
if ((url as any).includes('/decide/')) {
|
|
14
|
+
return Promise.resolve({
|
|
15
|
+
status: decideStatus,
|
|
16
|
+
text: () => Promise.resolve('ok'),
|
|
17
|
+
json: () => {
|
|
18
|
+
if (decideStatus !== 200) {
|
|
19
|
+
return Promise.resolve(decideFlags)
|
|
20
|
+
} else {
|
|
21
|
+
return Promise.resolve({
|
|
22
|
+
featureFlags: decideFlags,
|
|
23
|
+
featureFlagPayloads: decideFlagPayloads,
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
}) as any
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if ((url as any).includes('api/feature_flag/local_evaluation?token=TEST_API_KEY&send_cohorts')) {
|
|
31
|
+
return Promise.resolve({
|
|
32
|
+
status: 200,
|
|
33
|
+
text: () => Promise.resolve('ok'),
|
|
34
|
+
json: () => Promise.resolve(localFlags),
|
|
35
|
+
}) as any
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if ((url as any).includes('batch/')) {
|
|
39
|
+
return Promise.resolve({
|
|
40
|
+
status: 200,
|
|
41
|
+
text: () => Promise.resolve('ok'),
|
|
42
|
+
json: () =>
|
|
43
|
+
Promise.resolve({
|
|
44
|
+
status: 'ok',
|
|
45
|
+
}),
|
|
46
|
+
}) as any
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return Promise.resolve({
|
|
50
|
+
status: 400,
|
|
51
|
+
text: () => Promise.resolve('ok'),
|
|
52
|
+
json: () =>
|
|
53
|
+
Promise.resolve({
|
|
54
|
+
status: 'ok',
|
|
55
|
+
}),
|
|
56
|
+
}) as any
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const anyLocalEvalCall = [
|
|
61
|
+
'http://example.com/api/feature_flag/local_evaluation?token=TEST_API_KEY&send_cohorts',
|
|
62
|
+
expect.any(Object),
|
|
63
|
+
]
|
|
64
|
+
export const anyDecideCall = ['http://example.com/decide/?v=3', expect.any(Object)]
|