posthog-node 4.5.1 → 4.6.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 +12 -0
- package/lib/index.cjs.js +33 -6
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.esm.js +33 -6
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-node/src/feature-flags.d.ts +2 -0
- package/lib/posthog-node/src/posthog-node.d.ts +1 -0
- package/package.json +1 -1
- package/src/feature-flags.ts +29 -5
- package/src/posthog-node.ts +10 -1
- package/test/feature-flags.spec.ts +79 -0
- package/test/posthog-node.spec.ts +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Next
|
|
2
2
|
|
|
3
|
+
# 4.6.0 - 2025-02-12
|
|
4
|
+
|
|
5
|
+
## Added
|
|
6
|
+
|
|
7
|
+
1. Adds ability to fetch decrypted remote config flag payloads via `getRemoteConfigPayload`
|
|
8
|
+
|
|
9
|
+
# 4.5.2 - 2025-02-12
|
|
10
|
+
|
|
11
|
+
## Fixed
|
|
12
|
+
|
|
13
|
+
1. fix: Fixed edge case where `$feature_flag_called` events were enriched with additional feature flag data when they shouldn't be.
|
|
14
|
+
|
|
3
15
|
# 4.5.1 - 2025-02-12
|
|
4
16
|
|
|
5
17
|
## Fixed
|
package/lib/index.cjs.js
CHANGED
|
@@ -7,7 +7,7 @@ var node_fs = require('node:fs');
|
|
|
7
7
|
var node_readline = require('node:readline');
|
|
8
8
|
var node_path = require('node:path');
|
|
9
9
|
|
|
10
|
-
var version = "4.
|
|
10
|
+
var version = "4.6.0";
|
|
11
11
|
|
|
12
12
|
var PostHogPersistedProperty;
|
|
13
13
|
(function (PostHogPersistedProperty) {
|
|
@@ -1759,16 +1759,19 @@ class FeatureFlagsPoller {
|
|
|
1759
1759
|
}
|
|
1760
1760
|
}
|
|
1761
1761
|
}
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
method: 'GET',
|
|
1762
|
+
getPersonalApiKeyRequestOptions(method = 'GET') {
|
|
1763
|
+
return {
|
|
1764
|
+
method,
|
|
1766
1765
|
headers: {
|
|
1767
1766
|
...this.customHeaders,
|
|
1768
1767
|
'Content-Type': 'application/json',
|
|
1769
1768
|
Authorization: `Bearer ${this.personalApiKey}`
|
|
1770
1769
|
}
|
|
1771
1770
|
};
|
|
1771
|
+
}
|
|
1772
|
+
async _requestFeatureFlagDefinitions() {
|
|
1773
|
+
const url = `${this.host}/api/feature_flag/local_evaluation?token=${this.projectApiKey}&send_cohorts`;
|
|
1774
|
+
const options = this.getPersonalApiKeyRequestOptions();
|
|
1772
1775
|
let abortTimeout = null;
|
|
1773
1776
|
if (this.timeout && typeof this.timeout === 'number') {
|
|
1774
1777
|
const controller = new AbortController();
|
|
@@ -1786,6 +1789,23 @@ class FeatureFlagsPoller {
|
|
|
1786
1789
|
stopPoller() {
|
|
1787
1790
|
clearTimeout(this.poller);
|
|
1788
1791
|
}
|
|
1792
|
+
_requestRemoteConfigPayload(flagKey) {
|
|
1793
|
+
const url = `${this.host}/api/projects/@current/feature_flags/${flagKey}/remote_config/`;
|
|
1794
|
+
const options = this.getPersonalApiKeyRequestOptions();
|
|
1795
|
+
let abortTimeout = null;
|
|
1796
|
+
if (this.timeout && typeof this.timeout === 'number') {
|
|
1797
|
+
const controller = new AbortController();
|
|
1798
|
+
abortTimeout = safeSetTimeout(() => {
|
|
1799
|
+
controller.abort();
|
|
1800
|
+
}, this.timeout);
|
|
1801
|
+
options.signal = controller.signal;
|
|
1802
|
+
}
|
|
1803
|
+
try {
|
|
1804
|
+
return this.fetch(url, options);
|
|
1805
|
+
} finally {
|
|
1806
|
+
clearTimeout(abortTimeout);
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1789
1809
|
}
|
|
1790
1810
|
// # This function takes a distinct_id and a feature flag key and returns a float between 0 and 1.
|
|
1791
1811
|
// # Given the same distinct_id and key, it'll always return the same float. These floats are
|
|
@@ -3000,8 +3020,12 @@ class PostHog extends PostHogCoreStateless {
|
|
|
3000
3020
|
// return await super.getFeatureFlagsStateless(distinctId, groups, undefined, undefined, disableGeoip)
|
|
3001
3021
|
return await _getFlags(distinctId, groups, disableGeoip);
|
|
3002
3022
|
}
|
|
3023
|
+
if (event === '$feature_flag_called') {
|
|
3024
|
+
// If we're capturing a $feature_flag_called event, we don't want to enrich the event with cached flags that may be out of date.
|
|
3025
|
+
return {};
|
|
3026
|
+
}
|
|
3003
3027
|
if ((this.featureFlagsPoller?.featureFlags?.length || 0) > 0) {
|
|
3004
|
-
// Otherwise we may as well check for the flags locally and include them if
|
|
3028
|
+
// Otherwise we may as well check for the flags locally and include them if they are already loaded
|
|
3005
3029
|
const groupsWithStringValues = {};
|
|
3006
3030
|
for (const [key, value] of Object.entries(groups || {})) {
|
|
3007
3031
|
groupsWithStringValues[key] = String(value);
|
|
@@ -3155,6 +3179,9 @@ class PostHog extends PostHogCoreStateless {
|
|
|
3155
3179
|
}
|
|
3156
3180
|
return response;
|
|
3157
3181
|
}
|
|
3182
|
+
async getRemoteConfigPayload(flagKey) {
|
|
3183
|
+
return (await this.featureFlagsPoller?._requestRemoteConfigPayload(flagKey))?.json();
|
|
3184
|
+
}
|
|
3158
3185
|
async isFeatureEnabled(key, distinctId, options) {
|
|
3159
3186
|
const feat = await this.getFeatureFlag(key, distinctId, options);
|
|
3160
3187
|
if (feat === undefined) {
|