posthog-node 4.3.2 → 4.4.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 +4 -0
- package/benchmarks/rusha-vs-native.mjs +70 -0
- package/lib/index.cjs.js +6 -4
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +20 -5
- package/lib/index.esm.js +6 -4
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/types.d.ts +4 -1
- package/lib/posthog-node/src/types.d.ts +16 -4
- package/package.json +4 -4
- package/src/feature-flags.ts +2 -3
- package/src/types.ts +16 -4
- package/tsconfig.json +2 -2
- package/src/types/rusha.d.ts +0 -23
|
@@ -49,6 +49,8 @@ export declare enum PostHogPersistedProperty {
|
|
|
49
49
|
Props = "props",
|
|
50
50
|
FeatureFlags = "feature_flags",
|
|
51
51
|
FeatureFlagPayloads = "feature_flag_payloads",
|
|
52
|
+
BootstrapFeatureFlags = "bootstrap_feature_flags",
|
|
53
|
+
BootstrapFeatureFlagPayloads = "bootstrap_feature_flag_payloads",
|
|
52
54
|
OverrideFeatureFlags = "override_feature_flags",
|
|
53
55
|
Queue = "queue",
|
|
54
56
|
OptedOut = "opted_out",
|
|
@@ -58,7 +60,8 @@ export declare enum PostHogPersistedProperty {
|
|
|
58
60
|
GroupProperties = "group_properties",
|
|
59
61
|
InstalledAppBuild = "installed_app_build",
|
|
60
62
|
InstalledAppVersion = "installed_app_version",
|
|
61
|
-
SessionReplay = "session_replay"
|
|
63
|
+
SessionReplay = "session_replay",
|
|
64
|
+
DecideEndpointWasHit = "decide_endpoint_was_hit"
|
|
62
65
|
}
|
|
63
66
|
export type PostHogFetchOptions = {
|
|
64
67
|
method: 'GET' | 'POST' | 'PUT' | 'PATCH';
|
|
@@ -140,13 +140,25 @@ export type PostHogNodeV1 = {
|
|
|
140
140
|
}): Promise<string | boolean | undefined>;
|
|
141
141
|
/**
|
|
142
142
|
* @description Retrieves payload associated with the specified flag and matched value that is passed in.
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
143
|
+
*
|
|
144
|
+
* IMPORTANT: The `matchValue` parameter should be the value you previously obtained from `getFeatureFlag()`.
|
|
145
|
+
* If matchValue isn't passed (or is undefined), this method will automatically call `getFeatureFlag()`
|
|
146
|
+
* internally to fetch the flag value, which could result in a network call to the PostHog server if this flag can
|
|
147
|
+
* not be evaluated locally. This means that omitting `matchValue` will potentially:
|
|
148
|
+
* - Bypass local evaluation
|
|
149
|
+
* - Count as an additional flag evaluation against your quota
|
|
150
|
+
* - Impact performance due to the extra network request
|
|
151
|
+
*
|
|
152
|
+
* Example usage:
|
|
153
|
+
* ```js
|
|
154
|
+
* const flagValue = await client.getFeatureFlag('my-flag', distinctId);
|
|
155
|
+
* const payload = await client.getFeatureFlagPayload('my-flag', distinctId, flagValue);
|
|
156
|
+
* ```
|
|
146
157
|
*
|
|
147
158
|
* @param key the unique key of your feature flag
|
|
148
159
|
* @param distinctId the current unique id
|
|
149
|
-
* @param matchValue
|
|
160
|
+
* @param matchValue The flag value previously obtained from calling `getFeatureFlag()`. Can be a string or boolean.
|
|
161
|
+
* To avoid extra network calls, pass this parameter when you can.
|
|
150
162
|
* @param options: dict with optional parameters below
|
|
151
163
|
* @param onlyEvaluateLocally optional - whether to only evaluate the flag locally. Defaults to false.
|
|
152
164
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "posthog-node",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"description": "PostHog Node.js integration",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
"module": "lib/index.esm.js",
|
|
24
24
|
"types": "lib/index.d.ts",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"axios": "^1.7.4"
|
|
27
|
-
"rusha": "^0.8.14"
|
|
26
|
+
"axios": "^1.7.4"
|
|
28
27
|
},
|
|
29
28
|
"devDependencies": {
|
|
30
29
|
"@types/node": "^18.0.0",
|
|
31
|
-
"commander": "^9.3.0"
|
|
30
|
+
"commander": "^9.3.0",
|
|
31
|
+
"mitata": "^1.0.21"
|
|
32
32
|
},
|
|
33
33
|
"keywords": [
|
|
34
34
|
"posthog",
|
package/src/feature-flags.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createHash } from '
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
2
|
import { FeatureFlagCondition, FlagProperty, PostHogFeatureFlag, PropertyGroup } from './types'
|
|
3
3
|
import { JsonType, PostHogFetchOptions, PostHogFetchResponse } from 'posthog-core/src'
|
|
4
4
|
import { safeSetTimeout } from 'posthog-core/src/utils'
|
|
@@ -458,8 +458,7 @@ class FeatureFlagsPoller {
|
|
|
458
458
|
// # uniformly distributed between 0 and 1, so if we want to show this feature to 20% of traffic
|
|
459
459
|
// # we can do _hash(key, distinct_id) < 0.2
|
|
460
460
|
function _hash(key: string, distinctId: string, salt: string = ''): number {
|
|
461
|
-
|
|
462
|
-
const sha1Hash = createHash()
|
|
461
|
+
const sha1Hash = createHash('sha1')
|
|
463
462
|
sha1Hash.update(`${key}.${distinctId}${salt}`)
|
|
464
463
|
return parseInt(sha1Hash.digest('hex').slice(0, 15), 16) / LONG_SCALE
|
|
465
464
|
}
|
package/src/types.ts
CHANGED
|
@@ -158,13 +158,25 @@ export type PostHogNodeV1 = {
|
|
|
158
158
|
|
|
159
159
|
/**
|
|
160
160
|
* @description Retrieves payload associated with the specified flag and matched value that is passed in.
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
161
|
+
*
|
|
162
|
+
* IMPORTANT: The `matchValue` parameter should be the value you previously obtained from `getFeatureFlag()`.
|
|
163
|
+
* If matchValue isn't passed (or is undefined), this method will automatically call `getFeatureFlag()`
|
|
164
|
+
* internally to fetch the flag value, which could result in a network call to the PostHog server if this flag can
|
|
165
|
+
* not be evaluated locally. This means that omitting `matchValue` will potentially:
|
|
166
|
+
* - Bypass local evaluation
|
|
167
|
+
* - Count as an additional flag evaluation against your quota
|
|
168
|
+
* - Impact performance due to the extra network request
|
|
169
|
+
*
|
|
170
|
+
* Example usage:
|
|
171
|
+
* ```js
|
|
172
|
+
* const flagValue = await client.getFeatureFlag('my-flag', distinctId);
|
|
173
|
+
* const payload = await client.getFeatureFlagPayload('my-flag', distinctId, flagValue);
|
|
174
|
+
* ```
|
|
164
175
|
*
|
|
165
176
|
* @param key the unique key of your feature flag
|
|
166
177
|
* @param distinctId the current unique id
|
|
167
|
-
* @param matchValue
|
|
178
|
+
* @param matchValue The flag value previously obtained from calling `getFeatureFlag()`. Can be a string or boolean.
|
|
179
|
+
* To avoid extra network calls, pass this parameter when you can.
|
|
168
180
|
* @param options: dict with optional parameters below
|
|
169
181
|
* @param onlyEvaluateLocally optional - whether to only evaluate the flag locally. Defaults to false.
|
|
170
182
|
*
|
package/tsconfig.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "../tsconfig.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
|
-
"types": ["node"
|
|
5
|
-
"typeRoots": ["./node_modules/@types", "../node_modules/@types"
|
|
4
|
+
"types": ["node"],
|
|
5
|
+
"typeRoots": ["./node_modules/@types", "../node_modules/@types"]
|
|
6
6
|
}
|
|
7
7
|
}
|
package/src/types/rusha.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// Adjusted from type definitions for rusha 0.8
|
|
2
|
-
// Project: https://github.com/srijs/rusha#readme
|
|
3
|
-
// Definitions by: Jacopo Scazzosi <https://github.com/jacoscaz>
|
|
4
|
-
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
5
|
-
// Minimum TypeScript Version: 4.0
|
|
6
|
-
|
|
7
|
-
/// <reference types="node" />
|
|
8
|
-
|
|
9
|
-
interface Hash {
|
|
10
|
-
update(value: string | number[] | ArrayBuffer | Buffer): Hash
|
|
11
|
-
digest(encoding?: undefined): ArrayBuffer
|
|
12
|
-
digest(encoding: 'hex'): string
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interface Rusha {
|
|
16
|
-
createHash(): Hash
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
declare const Rusha: Rusha
|
|
20
|
-
|
|
21
|
-
declare module 'rusha' {
|
|
22
|
-
export = Rusha
|
|
23
|
-
}
|