posthog-node 2.0.0-alpha9 → 2.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 +25 -0
- package/README.md +0 -2
- package/index.ts +0 -3
- package/lib/index.cjs.js +950 -91
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +87 -11
- package/lib/index.esm.js +949 -89
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +19 -6
- package/lib/posthog-core/src/types.d.ts +6 -2
- package/lib/posthog-node/index.d.ts +0 -2
- package/lib/posthog-node/src/feature-flags.d.ts +50 -0
- package/lib/posthog-node/src/fetch.d.ts +2 -0
- package/lib/posthog-node/src/posthog-node.d.ts +32 -5
- package/lib/posthog-node/src/types.d.ts +69 -6
- package/package.json +4 -7
- package/src/feature-flags.ts +412 -0
- package/src/fetch.ts +20 -0
- package/src/posthog-node.ts +190 -32
- package/src/types.ts +72 -8
- package/test/feature-flags.spec.ts +3190 -0
- package/test/posthog-node.spec.ts +317 -40
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
declare type PosthogCoreOptions = {
|
|
2
3
|
host?: string;
|
|
3
4
|
flushAt?: number;
|
|
@@ -9,6 +10,21 @@ declare type PosthogCoreOptions = {
|
|
|
9
10
|
fetchRetryDelay?: number;
|
|
10
11
|
sessionExpirationTimeSeconds?: number;
|
|
11
12
|
captureMode?: 'json' | 'form';
|
|
13
|
+
};
|
|
14
|
+
declare type PostHogFetchOptions = {
|
|
15
|
+
method: 'GET' | 'POST' | 'PUT' | 'PATCH';
|
|
16
|
+
mode?: 'no-cors';
|
|
17
|
+
credentials?: 'omit';
|
|
18
|
+
headers: {
|
|
19
|
+
[key: string]: string;
|
|
20
|
+
};
|
|
21
|
+
body?: string;
|
|
22
|
+
signal?: AbortSignal;
|
|
23
|
+
};
|
|
24
|
+
declare type PostHogFetchResponse = {
|
|
25
|
+
status: number;
|
|
26
|
+
text: () => Promise<string>;
|
|
27
|
+
json: () => Promise<any>;
|
|
12
28
|
};
|
|
13
29
|
|
|
14
30
|
interface IdentifyMessageV1 {
|
|
@@ -35,7 +51,7 @@ declare type PostHogNodeV1 = {
|
|
|
35
51
|
* @param event We recommend using [verb] [noun], like movie played or movie updated to easily identify what your events mean later on.
|
|
36
52
|
* @param properties OPTIONAL | which can be a object with any information you'd like to add
|
|
37
53
|
* @param groups OPTIONAL | object of what groups are related to this event, example: { company: 'id:5' }. Can be used to analyze companies instead of users.
|
|
38
|
-
* @param sendFeatureFlags OPTIONAL | Used with experiments
|
|
54
|
+
* @param sendFeatureFlags OPTIONAL | Used with experiments. Determines whether to send feature flag values with the event.
|
|
39
55
|
*/
|
|
40
56
|
capture({ distinctId, event, properties, groups, sendFeatureFlags }: EventMessageV1): void;
|
|
41
57
|
/**
|
|
@@ -66,14 +82,47 @@ declare type PostHogNodeV1 = {
|
|
|
66
82
|
* allow you to safely deploy and roll back new features. Once you've created a feature flag in PostHog,
|
|
67
83
|
* you can use this method to check if the flag is on for a given user, allowing you to create logic to turn
|
|
68
84
|
* features on and off for different user groups or individual users.
|
|
69
|
-
* IMPORTANT: To use this method, you need to specify `personalApiKey` in your config! More info: https://posthog.com/docs/api/overview
|
|
70
85
|
* @param key the unique key of your feature flag
|
|
71
86
|
* @param distinctId the current unique id
|
|
72
|
-
* @param
|
|
73
|
-
* @param groups optional - what groups are currently active (group analytics)
|
|
87
|
+
* @param options: dict with optional parameters below
|
|
88
|
+
* @param groups optional - what groups are currently active (group analytics). Required if the flag depends on groups.
|
|
89
|
+
* @param personProperties optional - what person properties are known. Used to compute flags locally, if personalApiKey is present.
|
|
90
|
+
* @param groupProperties optional - what group properties are known. Used to compute flags locally, if personalApiKey is present.
|
|
91
|
+
* @param onlyEvaluateLocally optional - whether to only evaluate the flag locally. Defaults to false.
|
|
92
|
+
* @param sendFeatureFlagEvents optional - whether to send feature flag events. Used for Experiments. Defaults to true.
|
|
93
|
+
*
|
|
94
|
+
* @returns true if the flag is on, false if the flag is off, undefined if there was an error.
|
|
74
95
|
*/
|
|
75
|
-
isFeatureEnabled(key: string, distinctId: string,
|
|
76
|
-
|
|
96
|
+
isFeatureEnabled(key: string, distinctId: string, options?: {
|
|
97
|
+
groups?: Record<string, string>;
|
|
98
|
+
personProperties?: Record<string, string>;
|
|
99
|
+
groupProperties?: Record<string, Record<string, string>>;
|
|
100
|
+
onlyEvaluateLocally?: boolean;
|
|
101
|
+
sendFeatureFlagEvents?: boolean;
|
|
102
|
+
}): Promise<boolean | undefined>;
|
|
103
|
+
/**
|
|
104
|
+
* @description PostHog feature flags (https://posthog.com/docs/features/feature-flags)
|
|
105
|
+
* allow you to safely deploy and roll back new features. Once you've created a feature flag in PostHog,
|
|
106
|
+
* you can use this method to check if the flag is on for a given user, allowing you to create logic to turn
|
|
107
|
+
* features on and off for different user groups or individual users.
|
|
108
|
+
* @param key the unique key of your feature flag
|
|
109
|
+
* @param distinctId the current unique id
|
|
110
|
+
* @param options: dict with optional parameters below
|
|
111
|
+
* @param groups optional - what groups are currently active (group analytics). Required if the flag depends on groups.
|
|
112
|
+
* @param personProperties optional - what person properties are known. Used to compute flags locally, if personalApiKey is present.
|
|
113
|
+
* @param groupProperties optional - what group properties are known. Used to compute flags locally, if personalApiKey is present.
|
|
114
|
+
* @param onlyEvaluateLocally optional - whether to only evaluate the flag locally. Defaults to false.
|
|
115
|
+
* @param sendFeatureFlagEvents optional - whether to send feature flag events. Used for Experiments. Defaults to true.
|
|
116
|
+
*
|
|
117
|
+
* @returns true or string(for multivariates) if the flag is on, false if the flag is off, undefined if there was an error.
|
|
118
|
+
*/
|
|
119
|
+
getFeatureFlag(key: string, distinctId: string, options?: {
|
|
120
|
+
groups?: Record<string, string>;
|
|
121
|
+
personProperties?: Record<string, string>;
|
|
122
|
+
groupProperties?: Record<string, Record<string, string>>;
|
|
123
|
+
onlyEvaluateLocally?: boolean;
|
|
124
|
+
sendFeatureFlagEvents?: boolean;
|
|
125
|
+
}): Promise<string | boolean | undefined>;
|
|
77
126
|
/**
|
|
78
127
|
* @description Sets a groups properties, which allows asking questions like "Who are the most active companies"
|
|
79
128
|
* using my product in PostHog.
|
|
@@ -97,26 +146,53 @@ declare type PostHogNodeV1 = {
|
|
|
97
146
|
|
|
98
147
|
declare type PostHogOptions = PosthogCoreOptions & {
|
|
99
148
|
persistence?: 'memory';
|
|
149
|
+
personalApiKey?: string;
|
|
150
|
+
featureFlagsPollingInterval?: number;
|
|
151
|
+
requestTimeout?: number;
|
|
152
|
+
maxCacheSize?: number;
|
|
153
|
+
fetch?: (url: string, options: PostHogFetchOptions) => Promise<PostHogFetchResponse>;
|
|
100
154
|
};
|
|
101
|
-
declare class
|
|
155
|
+
declare class PostHog implements PostHogNodeV1 {
|
|
102
156
|
private _sharedClient;
|
|
157
|
+
private featureFlagsPoller?;
|
|
158
|
+
private maxCacheSize;
|
|
159
|
+
distinctIdHasSentFlagCalls: Record<string, string[]>;
|
|
103
160
|
constructor(apiKey: string, options?: PostHogOptions);
|
|
104
161
|
private reInit;
|
|
105
162
|
enable(): void;
|
|
106
163
|
disable(): void;
|
|
107
|
-
capture({ distinctId, event, properties, groups }: EventMessageV1): void;
|
|
164
|
+
capture({ distinctId, event, properties, groups, sendFeatureFlags }: EventMessageV1): void;
|
|
108
165
|
identify({ distinctId, properties }: IdentifyMessageV1): void;
|
|
109
166
|
alias(data: {
|
|
110
167
|
distinctId: string;
|
|
111
168
|
alias: string;
|
|
112
169
|
}): void;
|
|
113
|
-
getFeatureFlag(key: string, distinctId: string,
|
|
114
|
-
|
|
170
|
+
getFeatureFlag(key: string, distinctId: string, options?: {
|
|
171
|
+
groups?: Record<string, string>;
|
|
172
|
+
personProperties?: Record<string, string>;
|
|
173
|
+
groupProperties?: Record<string, Record<string, string>>;
|
|
174
|
+
onlyEvaluateLocally?: boolean;
|
|
175
|
+
sendFeatureFlagEvents?: boolean;
|
|
176
|
+
}): Promise<string | boolean | undefined>;
|
|
177
|
+
isFeatureEnabled(key: string, distinctId: string, options?: {
|
|
178
|
+
groups?: Record<string, string>;
|
|
179
|
+
personProperties?: Record<string, string>;
|
|
180
|
+
groupProperties?: Record<string, Record<string, string>>;
|
|
181
|
+
onlyEvaluateLocally?: boolean;
|
|
182
|
+
sendFeatureFlagEvents?: boolean;
|
|
183
|
+
}): Promise<boolean | undefined>;
|
|
184
|
+
getAllFlags(distinctId: string, options?: {
|
|
185
|
+
groups?: Record<string, string>;
|
|
186
|
+
personProperties?: Record<string, string>;
|
|
187
|
+
groupProperties?: Record<string, Record<string, string>>;
|
|
188
|
+
onlyEvaluateLocally?: boolean;
|
|
189
|
+
}): Promise<Record<string, string | boolean>>;
|
|
115
190
|
groupIdentify({ groupType, groupKey, properties }: GroupIdentifyMessage): void;
|
|
116
191
|
reloadFeatureFlags(): Promise<void>;
|
|
192
|
+
flush(): void;
|
|
117
193
|
shutdown(): void;
|
|
118
194
|
shutdownAsync(): Promise<void>;
|
|
119
195
|
debug(enabled?: boolean): void;
|
|
120
196
|
}
|
|
121
197
|
|
|
122
|
-
export {
|
|
198
|
+
export { PostHog, PostHogOptions };
|