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.
package/lib/index.d.ts CHANGED
@@ -592,6 +592,7 @@ interface SendFeatureFlagsOptions {
592
592
  onlyEvaluateLocally?: boolean;
593
593
  personProperties?: Record<string, any>;
594
594
  groupProperties?: Record<string, Record<string, any>>;
595
+ flagKeys?: string[];
595
596
  }
596
597
  interface EventMessage extends IdentifyMessage {
597
598
  event: string;
@@ -901,6 +902,7 @@ declare abstract class PostHogBackendClient extends PostHogCoreStateless impleme
901
902
  groupProperties?: Record<string, Record<string, string>>;
902
903
  onlyEvaluateLocally?: boolean;
903
904
  disableGeoip?: boolean;
905
+ flagKeys?: string[];
904
906
  }): Promise<Record<string, FeatureFlagValue>>;
905
907
  getAllFlagsAndPayloads(distinctId: string, options?: {
906
908
  groups?: Record<string, string>;
@@ -908,6 +910,7 @@ declare abstract class PostHogBackendClient extends PostHogCoreStateless impleme
908
910
  groupProperties?: Record<string, Record<string, string>>;
909
911
  onlyEvaluateLocally?: boolean;
910
912
  disableGeoip?: boolean;
913
+ flagKeys?: string[];
911
914
  }): Promise<PostHogFlagsAndPayloadsResponse>;
912
915
  groupIdentify({ groupType, groupKey, properties, distinctId, disableGeoip }: GroupIdentifyMessage): void;
913
916
  /**
@@ -1342,7 +1342,7 @@ function snipLine(line, colno) {
1342
1342
  return newLine;
1343
1343
  }
1344
1344
 
1345
- var version = "5.5.1";
1345
+ var version = "5.6.0";
1346
1346
 
1347
1347
  var PostHogPersistedProperty;
1348
1348
  (function (PostHogPersistedProperty) {
@@ -2581,12 +2581,7 @@ class FeatureFlagsPoller {
2581
2581
  if (!this.loadedSuccessfullyOnce) {
2582
2582
  return response;
2583
2583
  }
2584
- for (const flag of this.featureFlags) {
2585
- if (key === flag.key) {
2586
- featureFlag = flag;
2587
- break;
2588
- }
2589
- }
2584
+ featureFlag = this.featureFlagsByKey[key];
2590
2585
  if (featureFlag !== undefined) {
2591
2586
  try {
2592
2587
  response = await this.computeFlagLocally(featureFlag, distinctId, groups, personProperties, groupProperties);
@@ -2622,12 +2617,13 @@ class FeatureFlagsPoller {
2622
2617
  return response;
2623
2618
  }
2624
2619
  }
2625
- async getAllFlagsAndPayloads(distinctId, groups = {}, personProperties = {}, groupProperties = {}) {
2620
+ async getAllFlagsAndPayloads(distinctId, groups = {}, personProperties = {}, groupProperties = {}, flagKeysToExplicitlyEvaluate) {
2626
2621
  await this.loadFeatureFlags();
2627
2622
  const response = {};
2628
2623
  const payloads = {};
2629
2624
  let fallbackToFlags = this.featureFlags.length == 0;
2630
- await Promise.all(this.featureFlags.map(async flag => {
2625
+ const flagsToEvaluate = flagKeysToExplicitlyEvaluate ? flagKeysToExplicitlyEvaluate.map(key => this.featureFlagsByKey[key]).filter(Boolean) : this.featureFlags;
2626
+ await Promise.all(flagsToEvaluate.map(async flag => {
2631
2627
  try {
2632
2628
  const matchValue = await this.computeFlagLocally(flag, distinctId, groups, personProperties, groupProperties);
2633
2629
  response[flag.key] = matchValue;
@@ -3580,7 +3576,8 @@ class PostHogBackendClient extends PostHogCoreStateless {
3580
3576
  async getAllFlagsAndPayloads(distinctId, options) {
3581
3577
  const {
3582
3578
  groups,
3583
- disableGeoip
3579
+ disableGeoip,
3580
+ flagKeys
3584
3581
  } = options || {};
3585
3582
  let {
3586
3583
  onlyEvaluateLocally,
@@ -3594,7 +3591,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
3594
3591
  if (onlyEvaluateLocally == undefined) {
3595
3592
  onlyEvaluateLocally = false;
3596
3593
  }
3597
- const localEvaluationResult = await this.featureFlagsPoller?.getAllFlagsAndPayloads(distinctId, groups, personProperties, groupProperties);
3594
+ const localEvaluationResult = await this.featureFlagsPoller?.getAllFlagsAndPayloads(distinctId, groups, personProperties, groupProperties, flagKeys);
3598
3595
  let featureFlags = {};
3599
3596
  let featureFlagPayloads = {};
3600
3597
  let fallbackToFlags = true;
@@ -3604,7 +3601,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
3604
3601
  fallbackToFlags = localEvaluationResult.fallbackToFlags;
3605
3602
  }
3606
3603
  if (fallbackToFlags && !onlyEvaluateLocally) {
3607
- const remoteEvaluationResult = await super.getFeatureFlagsAndPayloadsStateless(distinctId, groups, personProperties, groupProperties, disableGeoip);
3604
+ const remoteEvaluationResult = await super.getFeatureFlagsAndPayloadsStateless(distinctId, groups, personProperties, groupProperties, disableGeoip, flagKeys);
3608
3605
  featureFlags = {
3609
3606
  ...featureFlags,
3610
3607
  ...(remoteEvaluationResult.flags || {})
@@ -3704,6 +3701,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
3704
3701
  // Use properties directly from options if they exist
3705
3702
  const finalPersonProperties = sendFeatureFlagsOptions?.personProperties || {};
3706
3703
  const finalGroupProperties = sendFeatureFlagsOptions?.groupProperties || {};
3704
+ const flagKeys = sendFeatureFlagsOptions?.flagKeys;
3707
3705
  // Check if we should only evaluate locally
3708
3706
  const onlyEvaluateLocally = sendFeatureFlagsOptions?.onlyEvaluateLocally ?? false;
3709
3707
  // If onlyEvaluateLocally is true, only use local evaluation
@@ -3718,7 +3716,8 @@ class PostHogBackendClient extends PostHogCoreStateless {
3718
3716
  personProperties: finalPersonProperties,
3719
3717
  groupProperties: finalGroupProperties,
3720
3718
  disableGeoip,
3721
- onlyEvaluateLocally: true
3719
+ onlyEvaluateLocally: true,
3720
+ flagKeys
3722
3721
  });
3723
3722
  } else {
3724
3723
  // If onlyEvaluateLocally is true but we don't have local flags, return empty
@@ -3736,7 +3735,8 @@ class PostHogBackendClient extends PostHogCoreStateless {
3736
3735
  personProperties: finalPersonProperties,
3737
3736
  groupProperties: finalGroupProperties,
3738
3737
  disableGeoip,
3739
- onlyEvaluateLocally: true
3738
+ onlyEvaluateLocally: true,
3739
+ flagKeys
3740
3740
  });
3741
3741
  }
3742
3742
  // Fall back to remote evaluation if local evaluation is not available