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/lib/index.d.ts CHANGED
@@ -319,7 +319,7 @@ type PostHogNodeV1 = {
319
319
  }): Promise<string | boolean | undefined>;
320
320
  /**
321
321
  * @description Retrieves payload associated with the specified flag and matched value that is passed in.
322
- * (Expected to be used in conjuction with getFeatureFlag but allows for manual lookup).
322
+ * (Expected to be used in conjunction with getFeatureFlag but allows for manual lookup).
323
323
  * If matchValue isn't passed, getFeatureFlag is called implicitly.
324
324
  * Will try to evaluate for payload locally first otherwise default to network call if allowed
325
325
  *
package/lib/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createHash } from 'rusha';
2
2
 
3
- var version = "4.3.1";
3
+ var version = "4.3.2";
4
4
 
5
5
  var PostHogPersistedProperty;
6
6
  (function (PostHogPersistedProperty) {
@@ -2230,70 +2230,44 @@ class PostHog extends PostHogCoreStateless {
2230
2230
  async getFeatureFlagPayload(key, distinctId, matchValue, options) {
2231
2231
  const {
2232
2232
  groups,
2233
- disableGeoip,
2234
- onlyEvaluateLocally = false,
2233
+ disableGeoip
2234
+ } = options || {};
2235
+ let {
2236
+ onlyEvaluateLocally,
2237
+ sendFeatureFlagEvents,
2235
2238
  personProperties,
2236
2239
  groupProperties
2237
2240
  } = options || {};
2238
- const {
2239
- allPersonProperties,
2240
- allGroupProperties
2241
- } = this.addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties);
2242
- if (matchValue === undefined) {
2241
+ const adjustedProperties = this.addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties);
2242
+ personProperties = adjustedProperties.allPersonProperties;
2243
+ groupProperties = adjustedProperties.allGroupProperties;
2244
+ let response = undefined;
2245
+ // Try to get match value locally if not provided
2246
+ if (!matchValue) {
2243
2247
  matchValue = await this.getFeatureFlag(key, distinctId, {
2244
2248
  ...options,
2245
- onlyEvaluateLocally: true,
2246
- sendFeatureFlagEvents: false
2249
+ onlyEvaluateLocally: true
2247
2250
  });
2248
2251
  }
2249
- let response;
2250
- let payload;
2251
2252
  if (matchValue) {
2252
- response = matchValue;
2253
- payload = await this.featureFlagsPoller?.computeFeatureFlagPayloadLocally(key, matchValue);
2254
- } else {
2255
- response = undefined;
2256
- payload = undefined;
2253
+ response = await this.featureFlagsPoller?.computeFeatureFlagPayloadLocally(key, matchValue);
2257
2254
  }
2258
- // Determine if the payload was evaluated locally
2259
- const payloadWasLocallyEvaluated = payload !== undefined;
2260
- // Fetch final flags and payloads either locally or from the remote server
2261
- let fetchedOrLocalFlags;
2262
- let fetchedOrLocalPayloads;
2263
- if (payloadWasLocallyEvaluated || onlyEvaluateLocally) {
2264
- if (response !== undefined) {
2265
- fetchedOrLocalFlags = {
2266
- [key]: response
2267
- };
2268
- fetchedOrLocalPayloads = {
2269
- [key]: payload
2270
- };
2271
- } else {
2272
- fetchedOrLocalFlags = {};
2273
- fetchedOrLocalPayloads = {};
2274
- }
2275
- } else {
2276
- const fetchedData = await super.getFeatureFlagsAndPayloadsStateless(distinctId, groups, allPersonProperties, allGroupProperties, disableGeoip);
2277
- fetchedOrLocalFlags = fetchedData.flags || {};
2278
- fetchedOrLocalPayloads = fetchedData.payloads || {};
2255
+ // set defaults
2256
+ if (onlyEvaluateLocally == undefined) {
2257
+ onlyEvaluateLocally = false;
2279
2258
  }
2280
- const finalResponse = fetchedOrLocalFlags[key];
2281
- const finalPayload = fetchedOrLocalPayloads[key];
2282
- const finalLocallyEvaluated = payloadWasLocallyEvaluated;
2283
- this.capture({
2284
- distinctId,
2285
- event: '$feature_flag_called',
2286
- properties: {
2287
- $feature_flag: key,
2288
- $feature_flag_response: finalResponse,
2289
- $feature_flag_payload: finalPayload,
2290
- locally_evaluated: finalLocallyEvaluated,
2291
- [`$feature/${key}`]: finalResponse
2292
- },
2293
- groups,
2294
- disableGeoip
2295
- });
2296
- return finalPayload;
2259
+ if (sendFeatureFlagEvents == undefined) {
2260
+ sendFeatureFlagEvents = true;
2261
+ }
2262
+ // set defaults
2263
+ if (onlyEvaluateLocally == undefined) {
2264
+ onlyEvaluateLocally = false;
2265
+ }
2266
+ const payloadWasLocallyEvaluated = response !== undefined;
2267
+ if (!payloadWasLocallyEvaluated && !onlyEvaluateLocally) {
2268
+ response = await super.getFeatureFlagPayloadStateless(key, distinctId, groups, personProperties, groupProperties, disableGeoip);
2269
+ }
2270
+ return response;
2297
2271
  }
2298
2272
  async isFeatureEnabled(key, distinctId, options) {
2299
2273
  const feat = await this.getFeatureFlag(key, distinctId, options);