posthog-node 5.5.1 → 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.
@@ -1320,7 +1320,7 @@ function snipLine(line, colno) {
1320
1320
  return newLine;
1321
1321
  }
1322
1322
 
1323
- var version = "5.5.1";
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
- for (const flag of this.featureFlags) {
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
- await Promise.all(this.featureFlags.map(async flag => {
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;
@@ -3558,7 +3554,8 @@ class PostHogBackendClient extends PostHogCoreStateless {
3558
3554
  async getAllFlagsAndPayloads(distinctId, options) {
3559
3555
  const {
3560
3556
  groups,
3561
- disableGeoip
3557
+ disableGeoip,
3558
+ flagKeys
3562
3559
  } = options || {};
3563
3560
  let {
3564
3561
  onlyEvaluateLocally,
@@ -3572,7 +3569,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
3572
3569
  if (onlyEvaluateLocally == undefined) {
3573
3570
  onlyEvaluateLocally = false;
3574
3571
  }
3575
- const localEvaluationResult = await this.featureFlagsPoller?.getAllFlagsAndPayloads(distinctId, groups, personProperties, groupProperties);
3572
+ const localEvaluationResult = await this.featureFlagsPoller?.getAllFlagsAndPayloads(distinctId, groups, personProperties, groupProperties, flagKeys);
3576
3573
  let featureFlags = {};
3577
3574
  let featureFlagPayloads = {};
3578
3575
  let fallbackToFlags = true;
@@ -3582,7 +3579,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
3582
3579
  fallbackToFlags = localEvaluationResult.fallbackToFlags;
3583
3580
  }
3584
3581
  if (fallbackToFlags && !onlyEvaluateLocally) {
3585
- const remoteEvaluationResult = await super.getFeatureFlagsAndPayloadsStateless(distinctId, groups, personProperties, groupProperties, disableGeoip);
3582
+ const remoteEvaluationResult = await super.getFeatureFlagsAndPayloadsStateless(distinctId, groups, personProperties, groupProperties, disableGeoip, flagKeys);
3586
3583
  featureFlags = {
3587
3584
  ...featureFlags,
3588
3585
  ...(remoteEvaluationResult.flags || {})
@@ -3682,6 +3679,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
3682
3679
  // Use properties directly from options if they exist
3683
3680
  const finalPersonProperties = sendFeatureFlagsOptions?.personProperties || {};
3684
3681
  const finalGroupProperties = sendFeatureFlagsOptions?.groupProperties || {};
3682
+ const flagKeys = sendFeatureFlagsOptions?.flagKeys;
3685
3683
  // Check if we should only evaluate locally
3686
3684
  const onlyEvaluateLocally = sendFeatureFlagsOptions?.onlyEvaluateLocally ?? false;
3687
3685
  // If onlyEvaluateLocally is true, only use local evaluation
@@ -3696,7 +3694,8 @@ class PostHogBackendClient extends PostHogCoreStateless {
3696
3694
  personProperties: finalPersonProperties,
3697
3695
  groupProperties: finalGroupProperties,
3698
3696
  disableGeoip,
3699
- onlyEvaluateLocally: true
3697
+ onlyEvaluateLocally: true,
3698
+ flagKeys
3700
3699
  });
3701
3700
  } else {
3702
3701
  // If onlyEvaluateLocally is true but we don't have local flags, return empty
@@ -3714,7 +3713,8 @@ class PostHogBackendClient extends PostHogCoreStateless {
3714
3713
  personProperties: finalPersonProperties,
3715
3714
  groupProperties: finalGroupProperties,
3716
3715
  disableGeoip,
3717
- onlyEvaluateLocally: true
3716
+ onlyEvaluateLocally: true,
3717
+ flagKeys
3718
3718
  });
3719
3719
  }
3720
3720
  // Fall back to remote evaluation if local evaluation is not available