posthog-node 2.2.0 → 2.2.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,3 +1,9 @@
1
+ # 2.2.2 - 2022-11-28
2
+ 1. Fix issues with timeout
3
+
4
+ # 2.2.1 - 2022-11-24
5
+ 1. Add standard 10 second timeout
6
+
1
7
  # 2.2.0 - 2022-11-18
2
8
 
3
9
  1. Add support for variant overrides for feature flag local evaluation.
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.2.0";
166
+ var version = "2.2.2";
167
167
 
168
168
  var PostHogPersistedProperty;
169
169
  (function (PostHogPersistedProperty) {
@@ -724,7 +724,7 @@ var SimpleEventEmitter = /** @class */ (function () {
724
724
  var PostHogCore = /** @class */ (function () {
725
725
  function PostHogCore(apiKey, options) {
726
726
  var _this = this;
727
- var _a, _b, _c, _d, _e;
727
+ var _a, _b, _c, _d, _e, _f;
728
728
  this.flagCallReported = {};
729
729
  // internal
730
730
  this._events = new SimpleEventEmitter();
@@ -741,7 +741,8 @@ var PostHogCore = /** @class */ (function () {
741
741
  retryCount: (_c = options === null || options === void 0 ? void 0 : options.fetchRetryCount) !== null && _c !== void 0 ? _c : 3,
742
742
  retryDelay: (_d = options === null || options === void 0 ? void 0 : options.fetchRetryDelay) !== null && _d !== void 0 ? _d : 3000,
743
743
  };
744
- this._sessionExpirationTimeSeconds = (_e = options === null || options === void 0 ? void 0 : options.sessionExpirationTimeSeconds) !== null && _e !== void 0 ? _e : 1800; // 30 minutes
744
+ this.requestTimeout = (_e = options === null || options === void 0 ? void 0 : options.requestTimeout) !== null && _e !== void 0 ? _e : 10000; // 10 seconds
745
+ this._sessionExpirationTimeSeconds = (_f = options === null || options === void 0 ? void 0 : options.sessionExpirationTimeSeconds) !== null && _f !== void 0 ? _f : 1800; // 30 minutes
745
746
  // NOTE: It is important we don't initiate anything in the constructor as some async IO may still be underway on the parent
746
747
  if ((options === null || options === void 0 ? void 0 : options.preloadFeatureFlags) !== false) {
747
748
  safeSetTimeout(function () {
@@ -1225,10 +1226,19 @@ var PostHogCore = /** @class */ (function () {
1225
1226
  });
1226
1227
  };
1227
1228
  PostHogCore.prototype.fetchWithRetry = function (url, options, retryOptions) {
1229
+ var _a;
1230
+ var _b;
1228
1231
  return __awaiter(this, void 0, void 0, function () {
1229
1232
  var _this = this;
1230
- return __generator(this, function (_a) {
1231
- return [2 /*return*/, retriable(function () { return _this.fetch(url, options); }, retryOptions || this._retryOptions)];
1233
+ return __generator(this, function (_c) {
1234
+ (_a = (_b = AbortSignal).timeout) !== null && _a !== void 0 ? _a : (_b.timeout = function timeout(ms) {
1235
+ var ctrl = new AbortController();
1236
+ setTimeout(function () { return ctrl.abort(); }, ms);
1237
+ return ctrl.signal;
1238
+ });
1239
+ return [2 /*return*/, retriable(function () {
1240
+ return _this.fetch(url, __assign({ signal: AbortSignal.timeout(_this.requestTimeout) }, options));
1241
+ }, retryOptions || this._retryOptions)];
1232
1242
  });
1233
1243
  });
1234
1244
  };
@@ -1990,6 +2000,8 @@ function () {
1990
2000
  options = {};
1991
2001
  }
1992
2002
 
2003
+ var _a;
2004
+
1993
2005
  this._sharedClient = new PostHogClient(apiKey, options);
1994
2006
 
1995
2007
  if (options.personalApiKey) {
@@ -1997,7 +2009,7 @@ function () {
1997
2009
  pollingInterval: typeof options.featureFlagsPollingInterval === 'number' ? options.featureFlagsPollingInterval : THIRTY_SECONDS,
1998
2010
  personalApiKey: options.personalApiKey,
1999
2011
  projectApiKey: apiKey,
2000
- timeout: options.requestTimeout,
2012
+ timeout: (_a = options.requestTimeout) !== null && _a !== void 0 ? _a : 10,
2001
2013
  host: this._sharedClient.host,
2002
2014
  fetch: options.fetch
2003
2015
  });