@statsig/client-core 3.32.4 → 3.32.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statsig/client-core",
3
- "version": "3.32.4",
3
+ "version": "3.32.5",
4
4
  "license": "ISC",
5
5
  "homepage": "https://github.com/statsig-io/js-client-monorepo",
6
6
  "repository": {
@@ -11,7 +11,7 @@ export declare class ErrorBoundary {
11
11
  wrap(instance: unknown, namePrefix?: string): void;
12
12
  logError(tag: string, error: unknown): void;
13
13
  logDroppedEvents(count: number, reason: string, metadata?: Record<string, unknown>): void;
14
- logEventRequestFailure(count: number, reason: string, flushType: string, statusCode: number, retries: number, failurePath?: string): void;
14
+ logEventRequestFailure(count: number, reason: string, flushType: string, statusCode: number, retries: number, failurePath?: string, failureErrorMessage?: string): void;
15
15
  getLastSeenErrorAndReset(): Error | null;
16
16
  attachErrorIfNoneExists(error: unknown): void;
17
17
  private _capture;
@@ -56,7 +56,7 @@ class ErrorBoundary {
56
56
  }
57
57
  this._onError(`statsig::log_event_dropped_event_count`, new Error(reason), true, extra);
58
58
  }
59
- logEventRequestFailure(count, reason, flushType, statusCode, retries, failurePath) {
59
+ logEventRequestFailure(count, reason, flushType, statusCode, retries, failurePath, failureErrorMessage) {
60
60
  const extra = {
61
61
  eventCount: String(count),
62
62
  flushType: flushType,
@@ -67,6 +67,10 @@ class ErrorBoundary {
67
67
  if (failurePath) {
68
68
  extra['failurePath'] = failurePath;
69
69
  }
70
+ if (typeof failureErrorMessage === 'string' &&
71
+ failureErrorMessage.length > 0) {
72
+ extra['failureErrorMessage'] = failureErrorMessage;
73
+ }
70
74
  this._onError(`statsig::log_event_failed`, new Error(reason), true, extra);
71
75
  }
72
76
  getLastSeenErrorAndReset() {
@@ -7,6 +7,7 @@ type EventSendResult = {
7
7
  success: boolean;
8
8
  statusCode: number;
9
9
  failurePath?: string;
10
+ failureErrorMessage?: string;
10
11
  };
11
12
  export declare class EventSender {
12
13
  private _network;
@@ -55,19 +55,15 @@ class EventSender {
55
55
  });
56
56
  return response;
57
57
  }
58
- return {
59
- success: false,
60
- statusCode: response.statusCode,
61
- failurePath: response.failurePath,
62
- };
58
+ return Object.assign({ success: false, statusCode: response.statusCode, failurePath: response.failurePath }, (response.failureErrorMessage
59
+ ? { failureErrorMessage: response.failureErrorMessage }
60
+ : {}));
63
61
  }
64
62
  catch (error) {
65
63
  Log_1.Log.warn('Failed to send batch:', error);
66
- return {
67
- success: false,
68
- statusCode: -1,
69
- failurePath: (_c = transportFailure.path) !== null && _c !== void 0 ? _c : failurePath,
70
- };
64
+ return Object.assign({ success: false, statusCode: -1, failurePath: (_c = transportFailure.path) !== null && _c !== void 0 ? _c : failurePath }, (transportFailure.errorMessage
65
+ ? { failureErrorMessage: transportFailure.errorMessage }
66
+ : {}));
71
67
  }
72
68
  });
73
69
  }
@@ -77,13 +73,11 @@ class EventSender {
77
73
  const result = yield this._network.post(this._getRequestData(batch), failureInfo);
78
74
  const code = (_a = result === null || result === void 0 ? void 0 : result.code) !== null && _a !== void 0 ? _a : -1;
79
75
  if (code === -1) {
80
- return {
81
- success: false,
82
- statusCode: -1,
83
- failurePath: (_b = failureInfo.path) !== null && _b !== void 0 ? _b : (result === undefined
76
+ return Object.assign({ success: false, statusCode: -1, failurePath: (_b = failureInfo.path) !== null && _b !== void 0 ? _b : (result === undefined
84
77
  ? 'event_sender_post_returned_undefined'
85
- : 'event_sender_post_returned_null'),
86
- };
78
+ : 'event_sender_post_returned_null') }, (failureInfo.errorMessage
79
+ ? { failureErrorMessage: failureInfo.errorMessage }
80
+ : {}));
87
81
  }
88
82
  return { success: code >= 200 && code < 300, statusCode: code };
89
83
  });
@@ -91,13 +85,11 @@ class EventSender {
91
85
  _sendEventsViaBeacon(batch, failureInfo) {
92
86
  var _a;
93
87
  const success = this._network.beacon(this._getRequestData(batch), failureInfo);
94
- return {
95
- success,
96
- statusCode: success ? 200 : -1,
97
- failurePath: success
88
+ return Object.assign({ success, statusCode: success ? 200 : -1, failurePath: success
98
89
  ? undefined
99
- : (_a = failureInfo.path) !== null && _a !== void 0 ? _a : 'beacon_send_false',
100
- };
90
+ : (_a = failureInfo.path) !== null && _a !== void 0 ? _a : 'beacon_send_false' }, (!success && failureInfo.errorMessage
91
+ ? { failureErrorMessage: failureInfo.errorMessage }
92
+ : {}));
101
93
  }
102
94
  _getRequestData(batch) {
103
95
  return {
@@ -44,6 +44,7 @@ export declare class FlushCoordinator {
44
44
  private _prepareQueueForFlush;
45
45
  containsAtLeastOneFullBatch(): boolean;
46
46
  convertPendingEventsToBatches(): number;
47
+ private _isRetryableBatch;
47
48
  private _handleFailure;
48
49
  loadAndRetryShutdownFailedEvents(): Promise<void>;
49
50
  private _getStorageKey;
@@ -21,6 +21,13 @@ const SafeJs_1 = require("./SafeJs");
21
21
  const SessionID_1 = require("./SessionID");
22
22
  const StatsigOptionsCommon_1 = require("./StatsigOptionsCommon");
23
23
  const StorageProvider_1 = require("./StorageProvider");
24
+ const RETRYABLE_NO_RESPONSE_FAILURE_PATHS = new Set([
25
+ 'network_request_timed_out_no_response',
26
+ 'network_request_exception_no_response',
27
+ 'event_sender_post_returned_null',
28
+ 'event_sender_post_returned_undefined',
29
+ 'event_sender_post_exception',
30
+ ]);
24
31
  class FlushCoordinator {
25
32
  constructor(batchQueue, pendingEvents, onPrepareFlush,
26
33
  // For Event Sender
@@ -254,7 +261,7 @@ class FlushCoordinator {
254
261
  return true;
255
262
  }
256
263
  this._flushInterval.adjustForFailure();
257
- this._handleFailure(batch, flushType, result.statusCode, result.failurePath);
264
+ this._handleFailure(batch, flushType, result.statusCode, result.failurePath, result.failureErrorMessage);
258
265
  return false;
259
266
  });
260
267
  }
@@ -283,23 +290,34 @@ class FlushCoordinator {
283
290
  const allEvents = this._pendingEvents.takeAll();
284
291
  return this._batchQueue.createBatches(allEvents);
285
292
  }
286
- _handleFailure(batch, flushType, statusCode, failurePath) {
293
+ _isRetryableBatch(statusCode, failurePath) {
294
+ if (NetworkCore_1.RETRYABLE_CODES.has(statusCode)) {
295
+ return true;
296
+ }
297
+ if (statusCode === -1 &&
298
+ failurePath &&
299
+ RETRYABLE_NO_RESPONSE_FAILURE_PATHS.has(failurePath)) {
300
+ return true;
301
+ }
302
+ return false;
303
+ }
304
+ _handleFailure(batch, flushType, statusCode, failurePath, failureErrorMessage) {
287
305
  if (flushType === FlushTypes_1.FlushType.Shutdown) {
288
306
  Log_1.Log.warn(`${flushType} flush failed during shutdown. ` +
289
307
  `${batch.events.length} event(s) will be saved to storage for retry in next session.`);
290
308
  this._saveShutdownFailedEventsToStorage(batch.events);
291
309
  return;
292
310
  }
293
- if (!NetworkCore_1.RETRYABLE_CODES.has(statusCode)) {
311
+ if (!this._isRetryableBatch(statusCode, failurePath)) {
294
312
  Log_1.Log.warn(`${flushType} flush failed after ${batch.attempts} attempt(s). ` +
295
313
  `${batch.events.length} event(s) will be dropped. Non-retryable error: ${statusCode}`);
296
- this._errorBoundary.logEventRequestFailure(batch.events.length, `non-retryable error`, flushType, statusCode, batch.attempts, failurePath);
314
+ this._errorBoundary.logEventRequestFailure(batch.events.length, `non-retryable error`, flushType, statusCode, batch.attempts, failurePath, failureErrorMessage);
297
315
  return;
298
316
  }
299
317
  if (batch.attempts >= EventRetryConstants_1.EventRetryConstants.MAX_RETRY_ATTEMPTS) {
300
318
  Log_1.Log.warn(`${flushType} flush failed after ${batch.attempts} attempt(s). ` +
301
319
  `${batch.events.length} event(s) will be dropped.`);
302
- this._errorBoundary.logEventRequestFailure(batch.events.length, `max retry attempts exceeded`, flushType, statusCode, batch.attempts, failurePath);
320
+ this._errorBoundary.logEventRequestFailure(batch.events.length, `max retry attempts exceeded`, flushType, statusCode, batch.attempts, failurePath, failureErrorMessage);
303
321
  return;
304
322
  }
305
323
  batch.incrementAttempts();
@@ -26,6 +26,7 @@ export type RequestArgsWithData = Flatten<RequestArgs & {
26
26
  } & DataFlags>;
27
27
  export type RequestFailureInfo = {
28
28
  path?: string;
29
+ errorMessage?: string;
29
30
  };
30
31
  type BeaconRequestArgs = Pick<RequestArgsWithData, 'data' | 'sdkKey' | 'urlConfig' | 'params' | 'isCompressable' | 'attempt'>;
31
32
  type NetworkResponse = {
@@ -210,6 +210,9 @@ class NetworkCore {
210
210
  failureInfo.path = timedOut
211
211
  ? 'network_request_timed_out_no_response'
212
212
  : 'network_request_exception_no_response';
213
+ if (errorMessage) {
214
+ failureInfo.errorMessage = errorMessage;
215
+ }
213
216
  }
214
217
  }
215
218
  return null;
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "3.32.4";
1
+ export declare const SDK_VERSION = "3.32.5";
2
2
  export type StatsigMetadata = {
3
3
  readonly [key: string]: string | undefined | null;
4
4
  readonly appVersion?: string;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StatsigMetadataProvider = exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = '3.32.4';
4
+ exports.SDK_VERSION = '3.32.5';
5
5
  let metadata = {
6
6
  sdkVersion: exports.SDK_VERSION,
7
7
  sdkType: 'js-mono', // js-mono is overwritten by Precomp and OnDevice clients