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/lib/index.d.ts CHANGED
@@ -13,6 +13,7 @@ declare type PosthogCoreOptions = {
13
13
  };
14
14
  fetchRetryCount?: number;
15
15
  fetchRetryDelay?: number;
16
+ requestTimeout?: number;
16
17
  sessionExpirationTimeSeconds?: number;
17
18
  captureMode?: 'json' | 'form';
18
19
  };
package/lib/index.esm.js CHANGED
@@ -155,7 +155,7 @@ function __spreadArray(to, from, pack) {
155
155
  return to.concat(ar || Array.prototype.slice.call(from));
156
156
  }
157
157
 
158
- var version = "2.2.0";
158
+ var version = "2.2.2";
159
159
 
160
160
  var PostHogPersistedProperty;
161
161
  (function (PostHogPersistedProperty) {
@@ -716,7 +716,7 @@ var SimpleEventEmitter = /** @class */ (function () {
716
716
  var PostHogCore = /** @class */ (function () {
717
717
  function PostHogCore(apiKey, options) {
718
718
  var _this = this;
719
- var _a, _b, _c, _d, _e;
719
+ var _a, _b, _c, _d, _e, _f;
720
720
  this.flagCallReported = {};
721
721
  // internal
722
722
  this._events = new SimpleEventEmitter();
@@ -733,7 +733,8 @@ var PostHogCore = /** @class */ (function () {
733
733
  retryCount: (_c = options === null || options === void 0 ? void 0 : options.fetchRetryCount) !== null && _c !== void 0 ? _c : 3,
734
734
  retryDelay: (_d = options === null || options === void 0 ? void 0 : options.fetchRetryDelay) !== null && _d !== void 0 ? _d : 3000,
735
735
  };
736
- this._sessionExpirationTimeSeconds = (_e = options === null || options === void 0 ? void 0 : options.sessionExpirationTimeSeconds) !== null && _e !== void 0 ? _e : 1800; // 30 minutes
736
+ this.requestTimeout = (_e = options === null || options === void 0 ? void 0 : options.requestTimeout) !== null && _e !== void 0 ? _e : 10000; // 10 seconds
737
+ this._sessionExpirationTimeSeconds = (_f = options === null || options === void 0 ? void 0 : options.sessionExpirationTimeSeconds) !== null && _f !== void 0 ? _f : 1800; // 30 minutes
737
738
  // NOTE: It is important we don't initiate anything in the constructor as some async IO may still be underway on the parent
738
739
  if ((options === null || options === void 0 ? void 0 : options.preloadFeatureFlags) !== false) {
739
740
  safeSetTimeout(function () {
@@ -1217,10 +1218,19 @@ var PostHogCore = /** @class */ (function () {
1217
1218
  });
1218
1219
  };
1219
1220
  PostHogCore.prototype.fetchWithRetry = function (url, options, retryOptions) {
1221
+ var _a;
1222
+ var _b;
1220
1223
  return __awaiter(this, void 0, void 0, function () {
1221
1224
  var _this = this;
1222
- return __generator(this, function (_a) {
1223
- return [2 /*return*/, retriable(function () { return _this.fetch(url, options); }, retryOptions || this._retryOptions)];
1225
+ return __generator(this, function (_c) {
1226
+ (_a = (_b = AbortSignal).timeout) !== null && _a !== void 0 ? _a : (_b.timeout = function timeout(ms) {
1227
+ var ctrl = new AbortController();
1228
+ setTimeout(function () { return ctrl.abort(); }, ms);
1229
+ return ctrl.signal;
1230
+ });
1231
+ return [2 /*return*/, retriable(function () {
1232
+ return _this.fetch(url, __assign({ signal: AbortSignal.timeout(_this.requestTimeout) }, options));
1233
+ }, retryOptions || this._retryOptions)];
1224
1234
  });
1225
1235
  });
1226
1236
  };
@@ -1982,6 +1992,8 @@ function () {
1982
1992
  options = {};
1983
1993
  }
1984
1994
 
1995
+ var _a;
1996
+
1985
1997
  this._sharedClient = new PostHogClient(apiKey, options);
1986
1998
 
1987
1999
  if (options.personalApiKey) {
@@ -1989,7 +2001,7 @@ function () {
1989
2001
  pollingInterval: typeof options.featureFlagsPollingInterval === 'number' ? options.featureFlagsPollingInterval : THIRTY_SECONDS,
1990
2002
  personalApiKey: options.personalApiKey,
1991
2003
  projectApiKey: apiKey,
1992
- timeout: options.requestTimeout,
2004
+ timeout: (_a = options.requestTimeout) !== null && _a !== void 0 ? _a : 10,
1993
2005
  host: this._sharedClient.host,
1994
2006
  fetch: options.fetch
1995
2007
  });