posthog-node 3.4.0 → 3.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,3 +1,12 @@
1
+ # 3.6.0 - 2024-01-18
2
+
3
+ 1. Adds support for overriding the event `uuid`
4
+
5
+ # 3.5.0 - 2024-01-09
6
+
7
+ 1. When local evaluation is enabled, we automatically add flag information to all events sent to PostHog, whenever possible. This makes it easier to use these events in experiments.
8
+ 2. Fixes a bug where in some rare cases we may drop events when send_feature_flags is enabled on capture.
9
+
1
10
  # 3.4.0 - 2024-01-09
2
11
 
3
12
  1. Numeric property handling for feature flags now does the expected: When passed in a number, we do a numeric comparison. When passed in a string, we do a string comparison. Previously, we always did a string comparison.
package/lib/index.cjs.js CHANGED
@@ -158,7 +158,7 @@ function __spreadArray(to, from, pack) {
158
158
  return to.concat(ar || Array.prototype.slice.call(from));
159
159
  }
160
160
 
161
- var version = "3.4.0";
161
+ var version = "3.6.0";
162
162
 
163
163
  var PostHogPersistedProperty;
164
164
  (function (PostHogPersistedProperty) {
@@ -751,8 +751,8 @@ var PostHogCoreStateless = /** @class */ (function () {
751
751
  function PostHogCoreStateless(apiKey, options) {
752
752
  var _a, _b, _c, _d, _e;
753
753
  this.debugMode = false;
754
- this.pendingPromises = {};
755
754
  this.disableGeoip = true;
755
+ this.pendingPromises = {};
756
756
  // internal
757
757
  this._events = new SimpleEventEmitter();
758
758
  assert(apiKey, "You must pass your PostHog project's api key.");
@@ -810,6 +810,14 @@ var PostHogCoreStateless = /** @class */ (function () {
810
810
  properties: __assign(__assign({}, (payload.properties || {})), this.getCommonEventProperties()),
811
811
  };
812
812
  };
813
+ PostHogCoreStateless.prototype.addPendingPromise = function (promise) {
814
+ var _this = this;
815
+ var promiseUUID = generateUUID();
816
+ this.pendingPromises[promiseUUID] = promise;
817
+ promise.finally(function () {
818
+ delete _this.pendingPromises[promiseUUID];
819
+ });
820
+ };
813
821
  /***
814
822
  *** TRACKING
815
823
  ***/
@@ -860,6 +868,7 @@ var PostHogCoreStateless = /** @class */ (function () {
860
868
  if (extraPayload === void 0) { extraPayload = {}; }
861
869
  return __awaiter(this, void 0, void 0, function () {
862
870
  var url, fetchOptions;
871
+ var _this = this;
863
872
  return __generator(this, function (_a) {
864
873
  url = "".concat(this.host, "/decide/?v=3");
865
874
  fetchOptions = {
@@ -870,7 +879,7 @@ var PostHogCoreStateless = /** @class */ (function () {
870
879
  return [2 /*return*/, this.fetchWithRetry(url, fetchOptions)
871
880
  .then(function (response) { return response.json(); })
872
881
  .catch(function (error) {
873
- console.error('Error fetching feature flags', error);
882
+ _this._events.emit('error', error);
874
883
  return undefined;
875
884
  })];
876
885
  });
@@ -1007,7 +1016,7 @@ var PostHogCoreStateless = /** @class */ (function () {
1007
1016
  this._events.emit(type, "Library is disabled. Not sending event. To re-enable, call posthog.optIn()");
1008
1017
  return;
1009
1018
  }
1010
- var message = __assign(__assign({}, _message), { type: type, library: this.getLibraryId(), library_version: this.getLibraryVersion(), timestamp: (options === null || options === void 0 ? void 0 : options.timestamp) ? options === null || options === void 0 ? void 0 : options.timestamp : currentISOTime() });
1019
+ var message = __assign(__assign({}, _message), { type: type, library: this.getLibraryId(), library_version: this.getLibraryVersion(), timestamp: (options === null || options === void 0 ? void 0 : options.timestamp) ? options === null || options === void 0 ? void 0 : options.timestamp : currentISOTime(), uuid: (options === null || options === void 0 ? void 0 : options.uuid) ? options.uuid : generateUUID(globalThis) });
1011
1020
  var addGeoipDisableProperty = (_a = options === null || options === void 0 ? void 0 : options.disableGeoip) !== null && _a !== void 0 ? _a : this.disableGeoip;
1012
1021
  if (addGeoipDisableProperty) {
1013
1022
  if (!message.properties) {
@@ -1057,14 +1066,11 @@ var PostHogCoreStateless = /** @class */ (function () {
1057
1066
  batch: messages,
1058
1067
  sent_at: currentISOTime(),
1059
1068
  };
1060
- var promiseUUID = generateUUID();
1061
1069
  var done = function (err) {
1062
1070
  if (err) {
1063
1071
  _this._events.emit('error', err);
1064
1072
  }
1065
1073
  callback === null || callback === void 0 ? void 0 : callback(err, messages);
1066
- // remove promise from pendingPromises
1067
- delete _this.pendingPromises[promiseUUID];
1068
1074
  _this._events.emit('flush', messages);
1069
1075
  };
1070
1076
  // Don't set the user agent if we're not on a browser. The latest spec allows
@@ -1090,12 +1096,11 @@ var PostHogCoreStateless = /** @class */ (function () {
1090
1096
  body: payload,
1091
1097
  };
1092
1098
  var requestPromise = this.fetchWithRetry(url, fetchOptions);
1093
- this.pendingPromises[promiseUUID] = requestPromise;
1094
- requestPromise
1099
+ this.addPendingPromise(requestPromise
1095
1100
  .then(function () { return done(); })
1096
1101
  .catch(function (err) {
1097
1102
  done(err);
1098
- });
1103
+ }));
1099
1104
  };
1100
1105
  PostHogCoreStateless.prototype.fetchWithRetry = function (url, options, retryOptions) {
1101
1106
  var _a;
@@ -1149,7 +1154,7 @@ var PostHogCoreStateless = /** @class */ (function () {
1149
1154
  clearTimeout(this._flushTimer);
1150
1155
  _a.label = 1;
1151
1156
  case 1:
1152
- _a.trys.push([1, 4, , 5]);
1157
+ _a.trys.push([1, 5, , 6]);
1153
1158
  return [4 /*yield*/, this.flushAsync()];
1154
1159
  case 2:
1155
1160
  _a.sent();
@@ -1157,18 +1162,31 @@ var PostHogCoreStateless = /** @class */ (function () {
1157
1162
  return x.catch(function () {
1158
1163
  // ignore errors as we are shutting down and can't deal with them anyways.
1159
1164
  });
1160
- }))];
1165
+ }))
1166
+ // flush again to make sure we send all events, some of which might've been added
1167
+ // while we were waiting for the pending promises to resolve
1168
+ // For example, see sendFeatureFlags in posthog-node/src/posthog-node.ts::capture
1169
+ ];
1161
1170
  case 3:
1162
1171
  _a.sent();
1163
- return [3 /*break*/, 5];
1172
+ // flush again to make sure we send all events, some of which might've been added
1173
+ // while we were waiting for the pending promises to resolve
1174
+ // For example, see sendFeatureFlags in posthog-node/src/posthog-node.ts::capture
1175
+ return [4 /*yield*/, this.flushAsync()];
1164
1176
  case 4:
1177
+ // flush again to make sure we send all events, some of which might've been added
1178
+ // while we were waiting for the pending promises to resolve
1179
+ // For example, see sendFeatureFlags in posthog-node/src/posthog-node.ts::capture
1180
+ _a.sent();
1181
+ return [3 /*break*/, 6];
1182
+ case 5:
1165
1183
  e_2 = _a.sent();
1166
1184
  if (!isPostHogFetchError(e_2)) {
1167
1185
  throw e_2;
1168
1186
  }
1169
1187
  console.error('Error while shutting down PostHog', e_2);
1170
- return [3 /*break*/, 5];
1171
- case 5: return [2 /*return*/];
1188
+ return [3 /*break*/, 6];
1189
+ case 6: return [2 /*return*/];
1172
1190
  }
1173
1191
  });
1174
1192
  });
@@ -1760,6 +1778,8 @@ function () {
1760
1778
  };
1761
1779
 
1762
1780
  FeatureFlagsPoller.prototype.getFeatureFlag = function (key, distinctId, groups, personProperties, groupProperties) {
1781
+ var _a;
1782
+
1763
1783
  if (groups === void 0) {
1764
1784
  groups = {};
1765
1785
  }
@@ -1773,17 +1793,17 @@ function () {
1773
1793
  }
1774
1794
 
1775
1795
  return __awaiter(this, void 0, void 0, function () {
1776
- var response, featureFlag, _i, _a, flag;
1796
+ var response, featureFlag, _i, _b, flag;
1777
1797
 
1778
- return __generator(this, function (_b) {
1779
- switch (_b.label) {
1798
+ return __generator(this, function (_c) {
1799
+ switch (_c.label) {
1780
1800
  case 0:
1781
1801
  return [4
1782
1802
  /*yield*/
1783
1803
  , this.loadFeatureFlags()];
1784
1804
 
1785
1805
  case 1:
1786
- _b.sent();
1806
+ _c.sent();
1787
1807
 
1788
1808
  response = undefined;
1789
1809
  featureFlag = undefined;
@@ -1794,8 +1814,8 @@ function () {
1794
1814
  , response];
1795
1815
  }
1796
1816
 
1797
- for (_i = 0, _a = this.featureFlags; _i < _a.length; _i++) {
1798
- flag = _a[_i];
1817
+ for (_i = 0, _b = this.featureFlags; _i < _b.length; _i++) {
1818
+ flag = _b[_i];
1799
1819
 
1800
1820
  if (key === flag.key) {
1801
1821
  featureFlag = flag;
@@ -1816,7 +1836,7 @@ function () {
1816
1836
  console.debug("InconclusiveMatchError when computing flag locally: ".concat(key, ": ").concat(e));
1817
1837
  }
1818
1838
  } else if (e instanceof Error) {
1819
- console.error("Error computing flag locally: ".concat(key, ": ").concat(e));
1839
+ (_a = this.onError) === null || _a === void 0 ? void 0 : _a.call(this, new Error("Error computing flag locally: ".concat(key, ": ").concat(e)));
1820
1840
  }
1821
1841
  }
1822
1842
  }
@@ -1992,12 +2012,18 @@ function () {
1992
2012
  var groupName = this.groupTypeMapping[String(aggregation_group_type_index)];
1993
2013
 
1994
2014
  if (!groupName) {
1995
- console.warn("[FEATURE FLAGS] Unknown group type index ".concat(aggregation_group_type_index, " for feature flag ").concat(flag.key));
2015
+ if (this.debugMode) {
2016
+ console.warn("[FEATURE FLAGS] Unknown group type index ".concat(aggregation_group_type_index, " for feature flag ").concat(flag.key));
2017
+ }
2018
+
1996
2019
  throw new InconclusiveMatchError('Flag has unknown group type index');
1997
2020
  }
1998
2021
 
1999
2022
  if (!(groupName in groups)) {
2000
- console.warn("[FEATURE FLAGS] Can't compute group feature flag: ".concat(flag.key, " without group names passed in"));
2023
+ if (this.debugMode) {
2024
+ console.warn("[FEATURE FLAGS] Can't compute group feature flag: ".concat(flag.key, " without group names passed in"));
2025
+ }
2026
+
2001
2027
  return false;
2002
2028
  }
2003
2029
 
@@ -2174,15 +2200,15 @@ function () {
2174
2200
  };
2175
2201
 
2176
2202
  FeatureFlagsPoller.prototype._loadFeatureFlags = function () {
2177
- var _a;
2203
+ var _a, _b;
2178
2204
 
2179
2205
  return __awaiter(this, void 0, void 0, function () {
2180
2206
  var res, responseJson, err_1;
2181
2207
 
2182
2208
  var _this = this;
2183
2209
 
2184
- return __generator(this, function (_b) {
2185
- switch (_b.label) {
2210
+ return __generator(this, function (_c) {
2211
+ switch (_c.label) {
2186
2212
  case 0:
2187
2213
  if (this.poller) {
2188
2214
  clearTimeout(this.poller);
@@ -2192,17 +2218,17 @@ function () {
2192
2218
  this.poller = setTimeout(function () {
2193
2219
  return _this._loadFeatureFlags();
2194
2220
  }, this.pollingInterval);
2195
- _b.label = 1;
2221
+ _c.label = 1;
2196
2222
 
2197
2223
  case 1:
2198
- _b.trys.push([1, 4,, 5]);
2224
+ _c.trys.push([1, 4,, 5]);
2199
2225
 
2200
2226
  return [4
2201
2227
  /*yield*/
2202
2228
  , this._requestFeatureFlagDefinitions()];
2203
2229
 
2204
2230
  case 2:
2205
- res = _b.sent();
2231
+ res = _c.sent();
2206
2232
 
2207
2233
  if (res && res.status === 401) {
2208
2234
  throw new ClientError("Your personalApiKey is invalid. Are you sure you're not using your Project API key? More information: https://posthog.com/docs/api/overview");
@@ -2221,10 +2247,10 @@ function () {
2221
2247
  , res.json()];
2222
2248
 
2223
2249
  case 3:
2224
- responseJson = _b.sent();
2250
+ responseJson = _c.sent();
2225
2251
 
2226
2252
  if (!('flags' in responseJson)) {
2227
- console.error("Invalid response when getting feature flags: ".concat(JSON.stringify(responseJson)));
2253
+ (_a = this.onError) === null || _a === void 0 ? void 0 : _a.call(this, new Error("Invalid response when getting feature flags: ".concat(JSON.stringify(responseJson))));
2228
2254
  }
2229
2255
 
2230
2256
  this.featureFlags = responseJson.flags || [];
@@ -2239,11 +2265,11 @@ function () {
2239
2265
  , 5];
2240
2266
 
2241
2267
  case 4:
2242
- err_1 = _b.sent(); // if an error that is not an instance of ClientError is thrown
2268
+ err_1 = _c.sent(); // if an error that is not an instance of ClientError is thrown
2243
2269
  // we silently ignore the error when reloading feature flags
2244
2270
 
2245
2271
  if (err_1 instanceof ClientError) {
2246
- (_a = this.onError) === null || _a === void 0 ? void 0 : _a.call(this, err_1);
2272
+ (_b = this.onError) === null || _b === void 0 ? void 0 : _b.call(this, err_1);
2247
2273
  }
2248
2274
 
2249
2275
  return [3
@@ -2724,48 +2750,103 @@ function (_super) {
2724
2750
  groups = _a.groups,
2725
2751
  sendFeatureFlags = _a.sendFeatureFlags,
2726
2752
  timestamp = _a.timestamp,
2727
- disableGeoip = _a.disableGeoip;
2753
+ disableGeoip = _a.disableGeoip,
2754
+ uuid = _a.uuid;
2728
2755
 
2729
2756
  var _capture = function (props) {
2730
2757
  _super.prototype.captureStateless.call(_this, distinctId, event, props, {
2731
2758
  timestamp: timestamp,
2732
- disableGeoip: disableGeoip
2759
+ disableGeoip: disableGeoip,
2760
+ uuid: uuid
2733
2761
  });
2734
- };
2762
+ }; // :TRICKY: If we flush, or need to shut down, to not lose events we want this promise to resolve before we flush
2735
2763
 
2736
- if (sendFeatureFlags) {
2737
- _super.prototype.getFeatureFlagsStateless.call(this, distinctId, groups, undefined, undefined, disableGeoip).then(function (flags) {
2738
- var featureVariantProperties = {};
2739
2764
 
2740
- if (flags) {
2741
- for (var _i = 0, _a = Object.entries(flags); _i < _a.length; _i++) {
2742
- var _b = _a[_i],
2743
- feature = _b[0],
2744
- variant = _b[1];
2765
+ var capturePromise = Promise.resolve().then(function () {
2766
+ return __awaiter(_this, void 0, void 0, function () {
2767
+ var groupsWithStringValues, _i, _a, _b, key, value;
2745
2768
 
2746
- if (variant !== false) {
2747
- featureVariantProperties["$feature/".concat(feature)] = variant;
2748
- }
2769
+ var _c, _d;
2770
+
2771
+ return __generator(this, function (_e) {
2772
+ switch (_e.label) {
2773
+ case 0:
2774
+ if (!sendFeatureFlags) return [3
2775
+ /*break*/
2776
+ , 2];
2777
+ return [4
2778
+ /*yield*/
2779
+ , _super.prototype.getFeatureFlagsStateless.call(this, distinctId, groups, undefined, undefined, disableGeoip)];
2780
+
2781
+ case 1:
2782
+ // If we are sending feature flags, we need to make sure we have the latest flags
2783
+ return [2
2784
+ /*return*/
2785
+ , _e.sent()];
2786
+
2787
+ case 2:
2788
+ if (!((((_d = (_c = this.featureFlagsPoller) === null || _c === void 0 ? void 0 : _c.featureFlags) === null || _d === void 0 ? void 0 : _d.length) || 0) > 0)) return [3
2789
+ /*break*/
2790
+ , 4];
2791
+ groupsWithStringValues = {};
2792
+
2793
+ for (_i = 0, _a = Object.entries(groups || {}); _i < _a.length; _i++) {
2794
+ _b = _a[_i], key = _b[0], value = _b[1];
2795
+ groupsWithStringValues[key] = String(value);
2796
+ }
2797
+
2798
+ return [4
2799
+ /*yield*/
2800
+ , this.getAllFlags(distinctId, {
2801
+ groups: groupsWithStringValues,
2802
+ disableGeoip: disableGeoip,
2803
+ onlyEvaluateLocally: true
2804
+ })];
2805
+
2806
+ case 3:
2807
+ return [2
2808
+ /*return*/
2809
+ , _e.sent()];
2810
+
2811
+ case 4:
2812
+ return [2
2813
+ /*return*/
2814
+ , {}];
2749
2815
  }
2816
+ });
2817
+ });
2818
+ }).then(function (flags) {
2819
+ // Derive the relevant flag properties to add
2820
+ var additionalProperties = {};
2821
+
2822
+ if (flags) {
2823
+ for (var _i = 0, _a = Object.entries(flags); _i < _a.length; _i++) {
2824
+ var _b = _a[_i],
2825
+ feature = _b[0],
2826
+ variant = _b[1];
2827
+ additionalProperties["$feature/".concat(feature)] = variant;
2750
2828
  }
2829
+ }
2751
2830
 
2752
- var activeFlags = Object.keys(flags || {}).filter(function (flag) {
2753
- return (flags === null || flags === void 0 ? void 0 : flags[flag]) !== false;
2754
- });
2831
+ var activeFlags = Object.keys(flags || {}).filter(function (flag) {
2832
+ return (flags === null || flags === void 0 ? void 0 : flags[flag]) !== false;
2833
+ });
2755
2834
 
2756
- var flagProperties = __assign({
2757
- $active_feature_flags: activeFlags || undefined
2758
- }, featureVariantProperties);
2835
+ if (activeFlags.length > 0) {
2836
+ additionalProperties['$active_feature_flags'] = activeFlags;
2837
+ }
2759
2838
 
2760
- _capture(__assign(__assign(__assign({}, properties), {
2761
- $groups: groups
2762
- }), flagProperties));
2763
- });
2764
- } else {
2765
- _capture(__assign(__assign({}, properties), {
2839
+ return additionalProperties;
2840
+ }).catch(function () {
2841
+ // Something went wrong getting the flag info - we should capture the event anyways
2842
+ return {};
2843
+ }).then(function (additionalProperties) {
2844
+ // No matter what - capture the event
2845
+ _capture(__assign(__assign(__assign({}, additionalProperties), properties), {
2766
2846
  $groups: groups
2767
2847
  }));
2768
- }
2848
+ });
2849
+ this.addPendingPromise(capturePromise);
2769
2850
  };
2770
2851
 
2771
2852
  PostHog.prototype.identify = function (_a) {
@@ -2792,15 +2873,18 @@ function (_super) {
2792
2873
  var _a;
2793
2874
 
2794
2875
  return __awaiter(this, void 0, void 0, function () {
2795
- var _b, groups, personProperties, groupProperties, disableGeoip, _c, onlyEvaluateLocally, sendFeatureFlagEvents, response, flagWasLocallyEvaluated, featureFlagReportedKey;
2876
+ var _b, groups, disableGeoip, _c, onlyEvaluateLocally, sendFeatureFlagEvents, personProperties, groupProperties, adjustedProperties, response, flagWasLocallyEvaluated, featureFlagReportedKey;
2796
2877
 
2797
2878
  var _d;
2798
2879
 
2799
2880
  return __generator(this, function (_e) {
2800
2881
  switch (_e.label) {
2801
2882
  case 0:
2802
- _b = options || {}, groups = _b.groups, personProperties = _b.personProperties, groupProperties = _b.groupProperties, disableGeoip = _b.disableGeoip;
2803
- _c = options || {}, onlyEvaluateLocally = _c.onlyEvaluateLocally, sendFeatureFlagEvents = _c.sendFeatureFlagEvents; // set defaults
2883
+ _b = options || {}, groups = _b.groups, disableGeoip = _b.disableGeoip;
2884
+ _c = options || {}, onlyEvaluateLocally = _c.onlyEvaluateLocally, sendFeatureFlagEvents = _c.sendFeatureFlagEvents, personProperties = _c.personProperties, groupProperties = _c.groupProperties;
2885
+ adjustedProperties = this.addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties);
2886
+ personProperties = adjustedProperties.allPersonProperties;
2887
+ groupProperties = adjustedProperties.allGroupProperties; // set defaults
2804
2888
 
2805
2889
  if (onlyEvaluateLocally == undefined) {
2806
2890
  onlyEvaluateLocally = false;
@@ -2867,13 +2951,16 @@ function (_super) {
2867
2951
  var _a;
2868
2952
 
2869
2953
  return __awaiter(this, void 0, void 0, function () {
2870
- var _b, groups, personProperties, groupProperties, disableGeoip, _c, onlyEvaluateLocally, response, payloadWasLocallyEvaluated;
2954
+ var _b, groups, disableGeoip, _c, onlyEvaluateLocally, personProperties, groupProperties, adjustedProperties, response, payloadWasLocallyEvaluated;
2871
2955
 
2872
2956
  return __generator(this, function (_d) {
2873
2957
  switch (_d.label) {
2874
2958
  case 0:
2875
- _b = options || {}, groups = _b.groups, personProperties = _b.personProperties, groupProperties = _b.groupProperties, disableGeoip = _b.disableGeoip;
2876
- _c = options || {}, onlyEvaluateLocally = _c.onlyEvaluateLocally, _c.sendFeatureFlagEvents;
2959
+ _b = options || {}, groups = _b.groups, disableGeoip = _b.disableGeoip;
2960
+ _c = options || {}, onlyEvaluateLocally = _c.onlyEvaluateLocally, _c.sendFeatureFlagEvents, personProperties = _c.personProperties, groupProperties = _c.groupProperties;
2961
+ adjustedProperties = this.addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties);
2962
+ personProperties = adjustedProperties.allPersonProperties;
2963
+ groupProperties = adjustedProperties.allGroupProperties;
2877
2964
  response = undefined;
2878
2965
  if (!!matchValue) return [3
2879
2966
  /*break*/
@@ -2993,13 +3080,16 @@ function (_super) {
2993
3080
  var _a;
2994
3081
 
2995
3082
  return __awaiter(this, void 0, void 0, function () {
2996
- var _b, groups, personProperties, groupProperties, disableGeoip, onlyEvaluateLocally, localEvaluationResult, featureFlags, featureFlagPayloads, fallbackToDecide, remoteEvaluationResult;
3083
+ var _b, groups, disableGeoip, _c, onlyEvaluateLocally, personProperties, groupProperties, adjustedProperties, localEvaluationResult, featureFlags, featureFlagPayloads, fallbackToDecide, remoteEvaluationResult;
2997
3084
 
2998
- return __generator(this, function (_c) {
2999
- switch (_c.label) {
3085
+ return __generator(this, function (_d) {
3086
+ switch (_d.label) {
3000
3087
  case 0:
3001
- _b = options || {}, groups = _b.groups, personProperties = _b.personProperties, groupProperties = _b.groupProperties, disableGeoip = _b.disableGeoip;
3002
- onlyEvaluateLocally = (options || {}).onlyEvaluateLocally; // set defaults
3088
+ _b = options || {}, groups = _b.groups, disableGeoip = _b.disableGeoip;
3089
+ _c = options || {}, onlyEvaluateLocally = _c.onlyEvaluateLocally, personProperties = _c.personProperties, groupProperties = _c.groupProperties;
3090
+ adjustedProperties = this.addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties);
3091
+ personProperties = adjustedProperties.allPersonProperties;
3092
+ groupProperties = adjustedProperties.allGroupProperties; // set defaults
3003
3093
 
3004
3094
  if (onlyEvaluateLocally == undefined) {
3005
3095
  onlyEvaluateLocally = false;
@@ -3010,7 +3100,7 @@ function (_super) {
3010
3100
  , (_a = this.featureFlagsPoller) === null || _a === void 0 ? void 0 : _a.getAllFlagsAndPayloads(distinctId, groups, personProperties, groupProperties)];
3011
3101
 
3012
3102
  case 1:
3013
- localEvaluationResult = _c.sent();
3103
+ localEvaluationResult = _d.sent();
3014
3104
  featureFlags = {};
3015
3105
  featureFlagPayloads = {};
3016
3106
  fallbackToDecide = true;
@@ -3029,10 +3119,10 @@ function (_super) {
3029
3119
  , _super.prototype.getFeatureFlagsAndPayloadsStateless.call(this, distinctId, groups, personProperties, groupProperties, disableGeoip)];
3030
3120
 
3031
3121
  case 2:
3032
- remoteEvaluationResult = _c.sent();
3122
+ remoteEvaluationResult = _d.sent();
3033
3123
  featureFlags = __assign(__assign({}, featureFlags), remoteEvaluationResult.flags || {});
3034
3124
  featureFlagPayloads = __assign(__assign({}, featureFlagPayloads), remoteEvaluationResult.payloads || {});
3035
- _c.label = 3;
3125
+ _d.label = 3;
3036
3126
 
3037
3127
  case 3:
3038
3128
  return [2
@@ -3097,6 +3187,28 @@ function (_super) {
3097
3187
  });
3098
3188
  };
3099
3189
 
3190
+ PostHog.prototype.addLocalPersonAndGroupProperties = function (distinctId, groups, personProperties, groupProperties) {
3191
+ var allPersonProperties = __assign({
3192
+ $current_distinct_id: distinctId
3193
+ }, personProperties || {});
3194
+
3195
+ var allGroupProperties = {};
3196
+
3197
+ if (groups) {
3198
+ for (var _i = 0, _a = Object.keys(groups); _i < _a.length; _i++) {
3199
+ var groupName = _a[_i];
3200
+ allGroupProperties[groupName] = __assign({
3201
+ $group_key: groups[groupName]
3202
+ }, (groupProperties === null || groupProperties === void 0 ? void 0 : groupProperties[groupName]) || {});
3203
+ }
3204
+ }
3205
+
3206
+ return {
3207
+ allPersonProperties: allPersonProperties,
3208
+ allGroupProperties: allGroupProperties
3209
+ };
3210
+ };
3211
+
3100
3212
  return PostHog;
3101
3213
  }(PostHogCoreStateless);
3102
3214