posthog-node 5.5.0 → 5.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 +8 -0
- package/lib/edge/index.cjs +23 -15
- package/lib/edge/index.cjs.map +1 -1
- package/lib/edge/index.mjs +23 -15
- package/lib/edge/index.mjs.map +1 -1
- package/lib/index.d.ts +3 -0
- package/lib/node/index.cjs +23 -15
- package/lib/node/index.cjs.map +1 -1
- package/lib/node/index.mjs +23 -15
- 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.6.0";
|
|
1324
1324
|
|
|
1325
1325
|
var PostHogPersistedProperty;
|
|
1326
1326
|
(function (PostHogPersistedProperty) {
|
|
@@ -2559,12 +2559,7 @@ class FeatureFlagsPoller {
|
|
|
2559
2559
|
if (!this.loadedSuccessfullyOnce) {
|
|
2560
2560
|
return response;
|
|
2561
2561
|
}
|
|
2562
|
-
|
|
2563
|
-
if (key === flag.key) {
|
|
2564
|
-
featureFlag = flag;
|
|
2565
|
-
break;
|
|
2566
|
-
}
|
|
2567
|
-
}
|
|
2562
|
+
featureFlag = this.featureFlagsByKey[key];
|
|
2568
2563
|
if (featureFlag !== undefined) {
|
|
2569
2564
|
try {
|
|
2570
2565
|
response = await this.computeFlagLocally(featureFlag, distinctId, groups, personProperties, groupProperties);
|
|
@@ -2600,12 +2595,13 @@ class FeatureFlagsPoller {
|
|
|
2600
2595
|
return response;
|
|
2601
2596
|
}
|
|
2602
2597
|
}
|
|
2603
|
-
async getAllFlagsAndPayloads(distinctId, groups = {}, personProperties = {}, groupProperties = {}) {
|
|
2598
|
+
async getAllFlagsAndPayloads(distinctId, groups = {}, personProperties = {}, groupProperties = {}, flagKeysToExplicitlyEvaluate) {
|
|
2604
2599
|
await this.loadFeatureFlags();
|
|
2605
2600
|
const response = {};
|
|
2606
2601
|
const payloads = {};
|
|
2607
2602
|
let fallbackToFlags = this.featureFlags.length == 0;
|
|
2608
|
-
|
|
2603
|
+
const flagsToEvaluate = flagKeysToExplicitlyEvaluate ? flagKeysToExplicitlyEvaluate.map(key => this.featureFlagsByKey[key]).filter(Boolean) : this.featureFlags;
|
|
2604
|
+
await Promise.all(flagsToEvaluate.map(async flag => {
|
|
2609
2605
|
try {
|
|
2610
2606
|
const matchValue = await this.computeFlagLocally(flag, distinctId, groups, personProperties, groupProperties);
|
|
2611
2607
|
response[flag.key] = matchValue;
|
|
@@ -2615,7 +2611,7 @@ class FeatureFlagsPoller {
|
|
|
2615
2611
|
}
|
|
2616
2612
|
} catch (e) {
|
|
2617
2613
|
if (e instanceof InconclusiveMatchError) {
|
|
2618
|
-
this.
|
|
2614
|
+
this.logMsgIfDebug(() => console.debug(`InconclusiveMatchError when computing flag locally: ${flag.key}: ${e}`));
|
|
2619
2615
|
} else if (e instanceof Error) {
|
|
2620
2616
|
this.onError?.(new Error(`Error computing flag locally: ${flag.key}: ${e}`));
|
|
2621
2617
|
}
|
|
@@ -2712,6 +2708,9 @@ class FeatureFlagsPoller {
|
|
|
2712
2708
|
let matches = false;
|
|
2713
2709
|
if (propertyType === 'cohort') {
|
|
2714
2710
|
matches = matchCohort(prop, properties, this.cohorts, this.debugMode);
|
|
2711
|
+
} else if (propertyType === 'flag') {
|
|
2712
|
+
this.logMsgIfDebug(() => console.warn(`[FEATURE FLAGS] Flag dependency filters are not supported in local evaluation. ` + `Skipping condition for flag '${flag.key}' with dependency on flag '${prop.key || 'unknown'}'`));
|
|
2713
|
+
continue;
|
|
2715
2714
|
} else {
|
|
2716
2715
|
matches = matchProperty(prop, properties, warnFunction);
|
|
2717
2716
|
}
|
|
@@ -3049,6 +3048,11 @@ function matchPropertyGroup(propertyGroup, propertyValues, cohortProperties, deb
|
|
|
3049
3048
|
let matches;
|
|
3050
3049
|
if (prop.type === 'cohort') {
|
|
3051
3050
|
matches = matchCohort(prop, propertyValues, cohortProperties, debugMode);
|
|
3051
|
+
} else if (prop.type === 'flag') {
|
|
3052
|
+
if (debugMode) {
|
|
3053
|
+
console.warn(`[FEATURE FLAGS] Flag dependency filters are not supported in local evaluation. ` + `Skipping condition with dependency on flag '${prop.key || 'unknown'}'`);
|
|
3054
|
+
}
|
|
3055
|
+
continue;
|
|
3052
3056
|
} else {
|
|
3053
3057
|
matches = matchProperty(prop, propertyValues);
|
|
3054
3058
|
}
|
|
@@ -3550,7 +3554,8 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
3550
3554
|
async getAllFlagsAndPayloads(distinctId, options) {
|
|
3551
3555
|
const {
|
|
3552
3556
|
groups,
|
|
3553
|
-
disableGeoip
|
|
3557
|
+
disableGeoip,
|
|
3558
|
+
flagKeys
|
|
3554
3559
|
} = options || {};
|
|
3555
3560
|
let {
|
|
3556
3561
|
onlyEvaluateLocally,
|
|
@@ -3564,7 +3569,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
3564
3569
|
if (onlyEvaluateLocally == undefined) {
|
|
3565
3570
|
onlyEvaluateLocally = false;
|
|
3566
3571
|
}
|
|
3567
|
-
const localEvaluationResult = await this.featureFlagsPoller?.getAllFlagsAndPayloads(distinctId, groups, personProperties, groupProperties);
|
|
3572
|
+
const localEvaluationResult = await this.featureFlagsPoller?.getAllFlagsAndPayloads(distinctId, groups, personProperties, groupProperties, flagKeys);
|
|
3568
3573
|
let featureFlags = {};
|
|
3569
3574
|
let featureFlagPayloads = {};
|
|
3570
3575
|
let fallbackToFlags = true;
|
|
@@ -3574,7 +3579,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
3574
3579
|
fallbackToFlags = localEvaluationResult.fallbackToFlags;
|
|
3575
3580
|
}
|
|
3576
3581
|
if (fallbackToFlags && !onlyEvaluateLocally) {
|
|
3577
|
-
const remoteEvaluationResult = await super.getFeatureFlagsAndPayloadsStateless(distinctId, groups, personProperties, groupProperties, disableGeoip);
|
|
3582
|
+
const remoteEvaluationResult = await super.getFeatureFlagsAndPayloadsStateless(distinctId, groups, personProperties, groupProperties, disableGeoip, flagKeys);
|
|
3578
3583
|
featureFlags = {
|
|
3579
3584
|
...featureFlags,
|
|
3580
3585
|
...(remoteEvaluationResult.flags || {})
|
|
@@ -3674,6 +3679,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
3674
3679
|
// Use properties directly from options if they exist
|
|
3675
3680
|
const finalPersonProperties = sendFeatureFlagsOptions?.personProperties || {};
|
|
3676
3681
|
const finalGroupProperties = sendFeatureFlagsOptions?.groupProperties || {};
|
|
3682
|
+
const flagKeys = sendFeatureFlagsOptions?.flagKeys;
|
|
3677
3683
|
// Check if we should only evaluate locally
|
|
3678
3684
|
const onlyEvaluateLocally = sendFeatureFlagsOptions?.onlyEvaluateLocally ?? false;
|
|
3679
3685
|
// If onlyEvaluateLocally is true, only use local evaluation
|
|
@@ -3688,7 +3694,8 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
3688
3694
|
personProperties: finalPersonProperties,
|
|
3689
3695
|
groupProperties: finalGroupProperties,
|
|
3690
3696
|
disableGeoip,
|
|
3691
|
-
onlyEvaluateLocally: true
|
|
3697
|
+
onlyEvaluateLocally: true,
|
|
3698
|
+
flagKeys
|
|
3692
3699
|
});
|
|
3693
3700
|
} else {
|
|
3694
3701
|
// If onlyEvaluateLocally is true but we don't have local flags, return empty
|
|
@@ -3706,7 +3713,8 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
3706
3713
|
personProperties: finalPersonProperties,
|
|
3707
3714
|
groupProperties: finalGroupProperties,
|
|
3708
3715
|
disableGeoip,
|
|
3709
|
-
onlyEvaluateLocally: true
|
|
3716
|
+
onlyEvaluateLocally: true,
|
|
3717
|
+
flagKeys
|
|
3710
3718
|
});
|
|
3711
3719
|
}
|
|
3712
3720
|
// Fall back to remote evaluation if local evaluation is not available
|