posthog-node 4.3.0 → 4.3.1

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
+ # 4.3.1 - 2024-11-26
4
+
5
+ 1. Fix bug where this SDK incorrectly sent `$feature_flag_called` events with null values when using `getFeatureFlagPayload`.
6
+
3
7
  # 4.3.0 - 2024-11-25
4
8
 
5
9
  1. Add Sentry v8 support to the Sentry integration
package/lib/index.cjs.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var rusha = require('rusha');
6
6
 
7
- var version = "4.3.0";
7
+ var version = "4.3.1";
8
8
 
9
9
  var PostHogPersistedProperty;
10
10
  (function (PostHogPersistedProperty) {
@@ -2234,44 +2234,70 @@ class PostHog extends PostHogCoreStateless {
2234
2234
  async getFeatureFlagPayload(key, distinctId, matchValue, options) {
2235
2235
  const {
2236
2236
  groups,
2237
- disableGeoip
2238
- } = options || {};
2239
- let {
2240
- onlyEvaluateLocally,
2241
- sendFeatureFlagEvents,
2237
+ disableGeoip,
2238
+ onlyEvaluateLocally = false,
2242
2239
  personProperties,
2243
2240
  groupProperties
2244
2241
  } = options || {};
2245
- const adjustedProperties = this.addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties);
2246
- personProperties = adjustedProperties.allPersonProperties;
2247
- groupProperties = adjustedProperties.allGroupProperties;
2248
- let response = undefined;
2249
- // Try to get match value locally if not provided
2250
- if (!matchValue) {
2242
+ const {
2243
+ allPersonProperties,
2244
+ allGroupProperties
2245
+ } = this.addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties);
2246
+ if (matchValue === undefined) {
2251
2247
  matchValue = await this.getFeatureFlag(key, distinctId, {
2252
2248
  ...options,
2253
- onlyEvaluateLocally: true
2249
+ onlyEvaluateLocally: true,
2250
+ sendFeatureFlagEvents: false
2254
2251
  });
2255
2252
  }
2253
+ let response;
2254
+ let payload;
2256
2255
  if (matchValue) {
2257
- response = await this.featureFlagsPoller?.computeFeatureFlagPayloadLocally(key, matchValue);
2258
- }
2259
- // set defaults
2260
- if (onlyEvaluateLocally == undefined) {
2261
- onlyEvaluateLocally = false;
2262
- }
2263
- if (sendFeatureFlagEvents == undefined) {
2264
- sendFeatureFlagEvents = true;
2265
- }
2266
- // set defaults
2267
- if (onlyEvaluateLocally == undefined) {
2268
- onlyEvaluateLocally = false;
2256
+ response = matchValue;
2257
+ payload = await this.featureFlagsPoller?.computeFeatureFlagPayloadLocally(key, matchValue);
2258
+ } else {
2259
+ response = undefined;
2260
+ payload = undefined;
2269
2261
  }
2270
- const payloadWasLocallyEvaluated = response !== undefined;
2271
- if (!payloadWasLocallyEvaluated && !onlyEvaluateLocally) {
2272
- response = await super.getFeatureFlagPayloadStateless(key, distinctId, groups, personProperties, groupProperties, disableGeoip);
2262
+ // Determine if the payload was evaluated locally
2263
+ const payloadWasLocallyEvaluated = payload !== undefined;
2264
+ // Fetch final flags and payloads either locally or from the remote server
2265
+ let fetchedOrLocalFlags;
2266
+ let fetchedOrLocalPayloads;
2267
+ if (payloadWasLocallyEvaluated || onlyEvaluateLocally) {
2268
+ if (response !== undefined) {
2269
+ fetchedOrLocalFlags = {
2270
+ [key]: response
2271
+ };
2272
+ fetchedOrLocalPayloads = {
2273
+ [key]: payload
2274
+ };
2275
+ } else {
2276
+ fetchedOrLocalFlags = {};
2277
+ fetchedOrLocalPayloads = {};
2278
+ }
2279
+ } else {
2280
+ const fetchedData = await super.getFeatureFlagsAndPayloadsStateless(distinctId, groups, allPersonProperties, allGroupProperties, disableGeoip);
2281
+ fetchedOrLocalFlags = fetchedData.flags || {};
2282
+ fetchedOrLocalPayloads = fetchedData.payloads || {};
2273
2283
  }
2274
- return response;
2284
+ const finalResponse = fetchedOrLocalFlags[key];
2285
+ const finalPayload = fetchedOrLocalPayloads[key];
2286
+ const finalLocallyEvaluated = payloadWasLocallyEvaluated;
2287
+ this.capture({
2288
+ distinctId,
2289
+ event: '$feature_flag_called',
2290
+ properties: {
2291
+ $feature_flag: key,
2292
+ $feature_flag_response: finalResponse,
2293
+ $feature_flag_payload: finalPayload,
2294
+ locally_evaluated: finalLocallyEvaluated,
2295
+ [`$feature/${key}`]: finalResponse
2296
+ },
2297
+ groups,
2298
+ disableGeoip
2299
+ });
2300
+ return finalPayload;
2275
2301
  }
2276
2302
  async isFeatureEnabled(key, distinctId, options) {
2277
2303
  const feat = await this.getFeatureFlag(key, distinctId, options);