posthog-node 3.1.0 → 3.1.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,3 +1,7 @@
1
+ # 3.1.1 - 2023-04-26
2
+
3
+ 1. Replace crypto library with pure-js rusha library which makes posthog-node work with Cloudflare Workers in Next.js edge runtime.
4
+
1
5
  # 3.1.0 - 2023-04-19
2
6
 
3
7
  1. Some small fixes to incorrect types
package/lib/index.cjs.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var crypto = require('crypto');
5
+ var rusha = require('rusha');
6
6
  var axios = require('axios');
7
7
 
8
8
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -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 = "3.1.0";
166
+ var version = "3.1.1";
167
167
 
168
168
  var PostHogPersistedProperty;
169
169
  (function (PostHogPersistedProperty) {
@@ -1153,7 +1153,11 @@ var PostHogCoreStateless = /** @class */ (function () {
1153
1153
  return [4 /*yield*/, this.flushAsync()];
1154
1154
  case 2:
1155
1155
  _a.sent();
1156
- return [4 /*yield*/, Promise.allSettled(Object.values(this.pendingPromises))];
1156
+ return [4 /*yield*/, Promise.all(Object.values(this.pendingPromises).map(function (x) {
1157
+ return x.catch(function () {
1158
+ // ignore errors as we are shutting down and can't deal with them anyways.
1159
+ });
1160
+ }))];
1157
1161
  case 3:
1158
1162
  _a.sent();
1159
1163
  return [3 /*break*/, 5];
@@ -1185,12 +1189,6 @@ var PostHogCoreStateless = /** @class */ (function () {
1185
1189
  _this.flagCallReported = {};
1186
1190
  _this.sendFeatureFlagEvent = (_b = options === null || options === void 0 ? void 0 : options.sendFeatureFlagEvent) !== null && _b !== void 0 ? _b : true;
1187
1191
  _this._sessionExpirationTimeSeconds = (_c = options === null || options === void 0 ? void 0 : options.sessionExpirationTimeSeconds) !== null && _c !== void 0 ? _c : 1800; // 30 minutes
1188
- // NOTE: It is important we don't initiate anything in the constructor as some async IO may still be underway on the parent
1189
- if ((options === null || options === void 0 ? void 0 : options.preloadFeatureFlags) !== false) {
1190
- safeSetTimeout(function () {
1191
- _this.reloadFeatureFlags();
1192
- }, 1);
1193
- }
1194
1192
  return _this;
1195
1193
  }
1196
1194
  PostHogCore.prototype.setupBootstrap = function (options) {
@@ -1305,9 +1303,7 @@ var PostHogCoreStateless = /** @class */ (function () {
1305
1303
  // We keep the AnonymousId to be used by decide calls and identify to link the previousId
1306
1304
  this.setPersistedProperty(PostHogPersistedProperty.AnonymousId, previousDistinctId);
1307
1305
  this.setPersistedProperty(PostHogPersistedProperty.DistinctId, distinctId);
1308
- if (this.getFeatureFlags()) {
1309
- this.reloadFeatureFlags();
1310
- }
1306
+ this.reloadFeatureFlags();
1311
1307
  }
1312
1308
  _super.prototype.identifyStateless.call(this, distinctId, allProperties, options);
1313
1309
  return this;
@@ -1347,7 +1343,7 @@ var PostHogCoreStateless = /** @class */ (function () {
1347
1343
  this.register({
1348
1344
  $groups: __assign(__assign({}, existingGroups), groups),
1349
1345
  });
1350
- if (Object.keys(groups).find(function (type) { return existingGroups[type] !== groups[type]; }) && this.getFeatureFlags()) {
1346
+ if (Object.keys(groups).find(function (type) { return existingGroups[type] !== groups[type]; })) {
1351
1347
  this.reloadFeatureFlags();
1352
1348
  }
1353
1349
  return this;
@@ -2288,9 +2284,10 @@ function () {
2288
2284
  function _hash(key, distinctId, salt) {
2289
2285
  if (salt === void 0) {
2290
2286
  salt = '';
2291
- }
2287
+ } // rusha is a fast sha1 implementation in pure javascript
2288
+
2292
2289
 
2293
- var sha1Hash = crypto.createHash('sha1');
2290
+ var sha1Hash = rusha.createHash();
2294
2291
  sha1Hash.update("".concat(key, ".").concat(distinctId).concat(salt));
2295
2292
  return parseInt(sha1Hash.digest('hex').slice(0, 15), 16) / LONG_SCALE;
2296
2293
  }