posthog-node 4.3.1 → 4.3.2

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.2 - 2024-12-11
4
+
5
+ 1. REVERT: Fix bug where this SDK incorrectly sent `$feature_flag_called` events with null values when using `getFeatureFlagPayload`.
6
+
3
7
  # 4.3.1 - 2024-11-26
4
8
 
5
9
  1. Fix bug where this SDK incorrectly sent `$feature_flag_called` events with null values when using `getFeatureFlagPayload`.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Please see the main [PostHog docs](https://www.posthog.com/docs).
4
4
 
5
- Specifically, the [Node.js integration](https://posthog.com/docs/integrate/server/node) details.
5
+ Specifically, the [Node.js docs](https://posthog.com/docs/libraries/node) details.
6
6
 
7
7
  ## Questions?
8
8
 
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.1";
7
+ var version = "4.3.2";
8
8
 
9
9
  var PostHogPersistedProperty;
10
10
  (function (PostHogPersistedProperty) {
@@ -2234,70 +2234,44 @@ class PostHog extends PostHogCoreStateless {
2234
2234
  async getFeatureFlagPayload(key, distinctId, matchValue, options) {
2235
2235
  const {
2236
2236
  groups,
2237
- disableGeoip,
2238
- onlyEvaluateLocally = false,
2237
+ disableGeoip
2238
+ } = options || {};
2239
+ let {
2240
+ onlyEvaluateLocally,
2241
+ sendFeatureFlagEvents,
2239
2242
  personProperties,
2240
2243
  groupProperties
2241
2244
  } = options || {};
2242
- const {
2243
- allPersonProperties,
2244
- allGroupProperties
2245
- } = this.addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties);
2246
- if (matchValue === undefined) {
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) {
2247
2251
  matchValue = await this.getFeatureFlag(key, distinctId, {
2248
2252
  ...options,
2249
- onlyEvaluateLocally: true,
2250
- sendFeatureFlagEvents: false
2253
+ onlyEvaluateLocally: true
2251
2254
  });
2252
2255
  }
2253
- let response;
2254
- let payload;
2255
2256
  if (matchValue) {
2256
- response = matchValue;
2257
- payload = await this.featureFlagsPoller?.computeFeatureFlagPayloadLocally(key, matchValue);
2258
- } else {
2259
- response = undefined;
2260
- payload = undefined;
2257
+ response = await this.featureFlagsPoller?.computeFeatureFlagPayloadLocally(key, matchValue);
2261
2258
  }
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 || {};
2259
+ // set defaults
2260
+ if (onlyEvaluateLocally == undefined) {
2261
+ onlyEvaluateLocally = false;
2283
2262
  }
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;
2263
+ if (sendFeatureFlagEvents == undefined) {
2264
+ sendFeatureFlagEvents = true;
2265
+ }
2266
+ // set defaults
2267
+ if (onlyEvaluateLocally == undefined) {
2268
+ onlyEvaluateLocally = false;
2269
+ }
2270
+ const payloadWasLocallyEvaluated = response !== undefined;
2271
+ if (!payloadWasLocallyEvaluated && !onlyEvaluateLocally) {
2272
+ response = await super.getFeatureFlagPayloadStateless(key, distinctId, groups, personProperties, groupProperties, disableGeoip);
2273
+ }
2274
+ return response;
2301
2275
  }
2302
2276
  async isFeatureEnabled(key, distinctId, options) {
2303
2277
  const feat = await this.getFeatureFlag(key, distinctId, options);