posthog-node 5.4.0 → 5.5.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 +49 -1
- package/lib/edge/index.cjs +35 -14
- package/lib/edge/index.cjs.map +1 -1
- package/lib/edge/index.mjs +35 -14
- package/lib/edge/index.mjs.map +1 -1
- package/lib/index.d.ts +7 -2
- package/lib/node/index.cjs +35 -14
- package/lib/node/index.cjs.map +1 -1
- package/lib/node/index.mjs +35 -14
- package/lib/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/lib/node/index.mjs
CHANGED
|
@@ -1320,7 +1320,7 @@ function snipLine(line, colno) {
|
|
|
1320
1320
|
return newLine;
|
|
1321
1321
|
}
|
|
1322
1322
|
|
|
1323
|
-
var version = "5.
|
|
1323
|
+
var version = "5.5.0";
|
|
1324
1324
|
|
|
1325
1325
|
var PostHogPersistedProperty;
|
|
1326
1326
|
(function (PostHogPersistedProperty) {
|
|
@@ -3244,7 +3244,8 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
3244
3244
|
const capturePromise = Promise.resolve().then(async () => {
|
|
3245
3245
|
if (sendFeatureFlags) {
|
|
3246
3246
|
// If we are sending feature flags, we evaluate them locally if the user prefers it, otherwise we fall back to remote evaluation
|
|
3247
|
-
|
|
3247
|
+
const sendFeatureFlagsOptions = typeof sendFeatureFlags === 'object' ? sendFeatureFlags : undefined;
|
|
3248
|
+
return await this.getFeatureFlagsForEvent(distinctId, groups, disableGeoip, sendFeatureFlagsOptions);
|
|
3248
3249
|
}
|
|
3249
3250
|
if (event === '$feature_flag_called') {
|
|
3250
3251
|
// 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.
|
|
@@ -3301,7 +3302,8 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
3301
3302
|
const capturePromise = Promise.resolve().then(async () => {
|
|
3302
3303
|
if (sendFeatureFlags) {
|
|
3303
3304
|
// If we are sending feature flags, we evaluate them locally if the user prefers it, otherwise we fall back to remote evaluation
|
|
3304
|
-
|
|
3305
|
+
const sendFeatureFlagsOptions = typeof sendFeatureFlags === 'object' ? sendFeatureFlags : undefined;
|
|
3306
|
+
return await this.getFeatureFlagsForEvent(distinctId, groups, disableGeoip, sendFeatureFlagsOptions);
|
|
3305
3307
|
}
|
|
3306
3308
|
if (event === '$feature_flag_called') {
|
|
3307
3309
|
// 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.
|
|
@@ -3668,13 +3670,32 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
3668
3670
|
groupProperties
|
|
3669
3671
|
};
|
|
3670
3672
|
}
|
|
3671
|
-
async getFeatureFlagsForEvent(distinctId, groups,
|
|
3672
|
-
//
|
|
3673
|
-
const {
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
//
|
|
3673
|
+
async getFeatureFlagsForEvent(distinctId, groups, disableGeoip, sendFeatureFlagsOptions) {
|
|
3674
|
+
// Use properties directly from options if they exist
|
|
3675
|
+
const finalPersonProperties = sendFeatureFlagsOptions?.personProperties || {};
|
|
3676
|
+
const finalGroupProperties = sendFeatureFlagsOptions?.groupProperties || {};
|
|
3677
|
+
// Check if we should only evaluate locally
|
|
3678
|
+
const onlyEvaluateLocally = sendFeatureFlagsOptions?.onlyEvaluateLocally ?? false;
|
|
3679
|
+
// If onlyEvaluateLocally is true, only use local evaluation
|
|
3680
|
+
if (onlyEvaluateLocally) {
|
|
3681
|
+
if ((this.featureFlagsPoller?.featureFlags?.length || 0) > 0) {
|
|
3682
|
+
const groupsWithStringValues = {};
|
|
3683
|
+
for (const [key, value] of Object.entries(groups || {})) {
|
|
3684
|
+
groupsWithStringValues[key] = String(value);
|
|
3685
|
+
}
|
|
3686
|
+
return await this.getAllFlags(distinctId, {
|
|
3687
|
+
groups: groupsWithStringValues,
|
|
3688
|
+
personProperties: finalPersonProperties,
|
|
3689
|
+
groupProperties: finalGroupProperties,
|
|
3690
|
+
disableGeoip,
|
|
3691
|
+
onlyEvaluateLocally: true
|
|
3692
|
+
});
|
|
3693
|
+
} else {
|
|
3694
|
+
// If onlyEvaluateLocally is true but we don't have local flags, return empty
|
|
3695
|
+
return {};
|
|
3696
|
+
}
|
|
3697
|
+
}
|
|
3698
|
+
// Prefer local evaluation if available (default behavior; I'd rather not penalize users who haven't updated to the new API but still want to use local evaluation)
|
|
3678
3699
|
if ((this.featureFlagsPoller?.featureFlags?.length || 0) > 0) {
|
|
3679
3700
|
const groupsWithStringValues = {};
|
|
3680
3701
|
for (const [key, value] of Object.entries(groups || {})) {
|
|
@@ -3682,14 +3703,14 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
3682
3703
|
}
|
|
3683
3704
|
return await this.getAllFlags(distinctId, {
|
|
3684
3705
|
groups: groupsWithStringValues,
|
|
3685
|
-
personProperties:
|
|
3686
|
-
groupProperties:
|
|
3706
|
+
personProperties: finalPersonProperties,
|
|
3707
|
+
groupProperties: finalGroupProperties,
|
|
3687
3708
|
disableGeoip,
|
|
3688
3709
|
onlyEvaluateLocally: true
|
|
3689
3710
|
});
|
|
3690
3711
|
}
|
|
3691
|
-
// Fall back to remote evaluation if local evaluation is not available
|
|
3692
|
-
return (await super.getFeatureFlagsStateless(distinctId, groups,
|
|
3712
|
+
// Fall back to remote evaluation if local evaluation is not available
|
|
3713
|
+
return (await super.getFeatureFlagsStateless(distinctId, groups, finalPersonProperties, finalGroupProperties, disableGeoip)).flags;
|
|
3693
3714
|
}
|
|
3694
3715
|
addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties) {
|
|
3695
3716
|
const allPersonProperties = {
|