posthog-node 2.5.0 → 2.5.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,7 +1,16 @@
1
+ # 2.5.2 - 2023-02-17
2
+
3
+ 1. Fix issue where properties passed to `.identify` were not set correctly
4
+
5
+ # 2.5.1 - 2023-02-16
6
+
7
+ 1. Make sure shutdown waits for pending promises to resolve. Fixes a problem with using PostHog Node in serverless environments.
8
+
1
9
  # 2.5.0 - 2023-02-15
2
10
 
3
11
  1. Removes shared client from `posthog-node`, getting rid of some race condition bugs when capturing events.
4
12
  2. Sets minimum version of node.js to 15
13
+
5
14
  # 2.4.0 - 2023-02-02
6
15
 
7
16
  1. Adds support for overriding timestamp of capture events
package/lib/index.cjs.js CHANGED
@@ -163,7 +163,7 @@ function __spreadArray(to, from, pack) {
163
163
  return to.concat(ar || Array.prototype.slice.call(from));
164
164
  }
165
165
 
166
- var version = "2.5.0";
166
+ var version = "2.5.2";
167
167
 
168
168
  var PostHogPersistedProperty;
169
169
  (function (PostHogPersistedProperty) {
@@ -725,6 +725,7 @@ var SimpleEventEmitter = /** @class */ (function () {
725
725
  var PostHogCoreStateless = /** @class */ (function () {
726
726
  function PostHogCoreStateless(apiKey, options) {
727
727
  var _a, _b, _c, _d;
728
+ this.pendingPromises = {};
728
729
  // internal
729
730
  this._events = new SimpleEventEmitter();
730
731
  assert(apiKey, "You must pass your PostHog project's api key.");
@@ -1013,8 +1014,11 @@ var PostHogCoreStateless = /** @class */ (function () {
1013
1014
  batch: messages,
1014
1015
  sent_at: currentISOTime(),
1015
1016
  };
1017
+ var promiseUUID = generateUUID();
1016
1018
  var done = function (err) {
1017
1019
  callback === null || callback === void 0 ? void 0 : callback(err, messages);
1020
+ // remove promise from pendingPromises
1021
+ delete _this.pendingPromises[promiseUUID];
1018
1022
  _this._events.emit('flush', messages);
1019
1023
  };
1020
1024
  // Don't set the user agent if we're not on a browser. The latest spec allows
@@ -1039,7 +1043,9 @@ var PostHogCoreStateless = /** @class */ (function () {
1039
1043
  headers: { 'Content-Type': 'application/json' },
1040
1044
  body: payload,
1041
1045
  };
1042
- this.fetchWithRetry(url, fetchOptions)
1046
+ var requestPromise = this.fetchWithRetry(url, fetchOptions);
1047
+ this.pendingPromises[promiseUUID] = requestPromise;
1048
+ requestPromise
1043
1049
  .then(function () { return done(); })
1044
1050
  .catch(function (err) {
1045
1051
  if (err.response) {
@@ -1074,6 +1080,9 @@ var PostHogCoreStateless = /** @class */ (function () {
1074
1080
  clearTimeout(this._flushTimer);
1075
1081
  return [4 /*yield*/, this.flushAsync()];
1076
1082
  case 1:
1083
+ _a.sent();
1084
+ return [4 /*yield*/, Promise.allSettled(Object.values(this.pendingPromises))];
1085
+ case 2:
1077
1086
  _a.sent();
1078
1087
  return [2 /*return*/];
1079
1088
  }
@@ -2367,9 +2376,13 @@ function (_super) {
2367
2376
 
2368
2377
  PostHog.prototype.identify = function (_a) {
2369
2378
  var distinctId = _a.distinctId,
2370
- properties = _a.properties;
2379
+ properties = _a.properties; // Catch properties passed as $set and move them to the top level
2371
2380
 
2372
- _super.prototype.identifyStateless.call(this, distinctId, properties);
2381
+ var personProperties = (properties === null || properties === void 0 ? void 0 : properties.$set) || properties;
2382
+
2383
+ _super.prototype.identifyStateless.call(this, distinctId, {
2384
+ $set: personProperties
2385
+ });
2373
2386
  };
2374
2387
 
2375
2388
  PostHog.prototype.alias = function (data) {