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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Next
2
2
 
3
+ # 5.6.0 – 2025-07-15
4
+
5
+ 1. Added support for filtering feature flags with flagKeys parameter in sendFeatureFlags options
6
+
3
7
  # 5.5.1 – 2025-07-15
4
8
 
5
9
  1. wrap `InconclusiveMatchError`s in `logMsgIfDebug` for local flag evaluations on `sendFeatureFlags`
@@ -937,7 +937,7 @@ function setupExpressErrorHandler(_posthog, app) {
937
937
  });
938
938
  }
939
939
 
940
- var version = "5.5.1";
940
+ var version = "5.6.0";
941
941
 
942
942
  var PostHogPersistedProperty;
943
943
  (function (PostHogPersistedProperty) {
@@ -2176,12 +2176,7 @@ class FeatureFlagsPoller {
2176
2176
  if (!this.loadedSuccessfullyOnce) {
2177
2177
  return response;
2178
2178
  }
2179
- for (const flag of this.featureFlags) {
2180
- if (key === flag.key) {
2181
- featureFlag = flag;
2182
- break;
2183
- }
2184
- }
2179
+ featureFlag = this.featureFlagsByKey[key];
2185
2180
  if (featureFlag !== undefined) {
2186
2181
  try {
2187
2182
  response = await this.computeFlagLocally(featureFlag, distinctId, groups, personProperties, groupProperties);
@@ -2217,12 +2212,13 @@ class FeatureFlagsPoller {
2217
2212
  return response;
2218
2213
  }
2219
2214
  }
2220
- async getAllFlagsAndPayloads(distinctId, groups = {}, personProperties = {}, groupProperties = {}) {
2215
+ async getAllFlagsAndPayloads(distinctId, groups = {}, personProperties = {}, groupProperties = {}, flagKeysToExplicitlyEvaluate) {
2221
2216
  await this.loadFeatureFlags();
2222
2217
  const response = {};
2223
2218
  const payloads = {};
2224
2219
  let fallbackToFlags = this.featureFlags.length == 0;
2225
- await Promise.all(this.featureFlags.map(async flag => {
2220
+ const flagsToEvaluate = flagKeysToExplicitlyEvaluate ? flagKeysToExplicitlyEvaluate.map(key => this.featureFlagsByKey[key]).filter(Boolean) : this.featureFlags;
2221
+ await Promise.all(flagsToEvaluate.map(async flag => {
2226
2222
  try {
2227
2223
  const matchValue = await this.computeFlagLocally(flag, distinctId, groups, personProperties, groupProperties);
2228
2224
  response[flag.key] = matchValue;
@@ -3175,7 +3171,8 @@ class PostHogBackendClient extends PostHogCoreStateless {
3175
3171
  async getAllFlagsAndPayloads(distinctId, options) {
3176
3172
  const {
3177
3173
  groups,
3178
- disableGeoip
3174
+ disableGeoip,
3175
+ flagKeys
3179
3176
  } = options || {};
3180
3177
  let {
3181
3178
  onlyEvaluateLocally,
@@ -3189,7 +3186,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
3189
3186
  if (onlyEvaluateLocally == undefined) {
3190
3187
  onlyEvaluateLocally = false;
3191
3188
  }
3192
- const localEvaluationResult = await this.featureFlagsPoller?.getAllFlagsAndPayloads(distinctId, groups, personProperties, groupProperties);
3189
+ const localEvaluationResult = await this.featureFlagsPoller?.getAllFlagsAndPayloads(distinctId, groups, personProperties, groupProperties, flagKeys);
3193
3190
  let featureFlags = {};
3194
3191
  let featureFlagPayloads = {};
3195
3192
  let fallbackToFlags = true;
@@ -3199,7 +3196,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
3199
3196
  fallbackToFlags = localEvaluationResult.fallbackToFlags;
3200
3197
  }
3201
3198
  if (fallbackToFlags && !onlyEvaluateLocally) {
3202
- const remoteEvaluationResult = await super.getFeatureFlagsAndPayloadsStateless(distinctId, groups, personProperties, groupProperties, disableGeoip);
3199
+ const remoteEvaluationResult = await super.getFeatureFlagsAndPayloadsStateless(distinctId, groups, personProperties, groupProperties, disableGeoip, flagKeys);
3203
3200
  featureFlags = {
3204
3201
  ...featureFlags,
3205
3202
  ...(remoteEvaluationResult.flags || {})
@@ -3299,6 +3296,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
3299
3296
  // Use properties directly from options if they exist
3300
3297
  const finalPersonProperties = sendFeatureFlagsOptions?.personProperties || {};
3301
3298
  const finalGroupProperties = sendFeatureFlagsOptions?.groupProperties || {};
3299
+ const flagKeys = sendFeatureFlagsOptions?.flagKeys;
3302
3300
  // Check if we should only evaluate locally
3303
3301
  const onlyEvaluateLocally = sendFeatureFlagsOptions?.onlyEvaluateLocally ?? false;
3304
3302
  // If onlyEvaluateLocally is true, only use local evaluation
@@ -3313,7 +3311,8 @@ class PostHogBackendClient extends PostHogCoreStateless {
3313
3311
  personProperties: finalPersonProperties,
3314
3312
  groupProperties: finalGroupProperties,
3315
3313
  disableGeoip,
3316
- onlyEvaluateLocally: true
3314
+ onlyEvaluateLocally: true,
3315
+ flagKeys
3317
3316
  });
3318
3317
  } else {
3319
3318
  // If onlyEvaluateLocally is true but we don't have local flags, return empty
@@ -3331,7 +3330,8 @@ class PostHogBackendClient extends PostHogCoreStateless {
3331
3330
  personProperties: finalPersonProperties,
3332
3331
  groupProperties: finalGroupProperties,
3333
3332
  disableGeoip,
3334
- onlyEvaluateLocally: true
3333
+ onlyEvaluateLocally: true,
3334
+ flagKeys
3335
3335
  });
3336
3336
  }
3337
3337
  // Fall back to remote evaluation if local evaluation is not available