@stream-io/feeds-client 0.3.42 → 0.3.43

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.
@@ -3999,7 +3999,7 @@ const getRateLimitFromResponseHeader = (response_headers) => {
3999
3999
  };
4000
4000
  return result;
4001
4001
  };
4002
- const version = "0.3.42";
4002
+ const version = "0.3.43";
4003
4003
  const axios = axiosImport.default ?? axiosImport;
4004
4004
  class ApiClient {
4005
4005
  constructor(apiKey, tokenManager, connectionIdManager, options) {
@@ -6283,6 +6283,38 @@ function handleWatchStarted() {
6283
6283
  function handleWatchStopped() {
6284
6284
  this.state.partialNext({ watch: false });
6285
6285
  }
6286
+ const DEFAULT_MAX_RETRIES = 3;
6287
+ function isRetryableError(error) {
6288
+ if (error instanceof StreamApiError) {
6289
+ const statusCode = error.metadata?.response_code;
6290
+ if (statusCode && statusCode >= 400 && statusCode < 500) {
6291
+ return false;
6292
+ }
6293
+ }
6294
+ return true;
6295
+ }
6296
+ async function withRetry(fn, options = {}) {
6297
+ const { maxRetries = DEFAULT_MAX_RETRIES, shouldRetry } = options;
6298
+ let lastError;
6299
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
6300
+ try {
6301
+ return await fn();
6302
+ } catch (error) {
6303
+ lastError = error;
6304
+ const isLastAttempt = attempt === maxRetries;
6305
+ if (isLastAttempt) {
6306
+ throw error;
6307
+ }
6308
+ const shouldRetryResult = shouldRetry ? shouldRetry(error, attempt) : isRetryableError(error);
6309
+ if (!shouldRetryResult) {
6310
+ throw error;
6311
+ }
6312
+ const delay = retryInterval(attempt + 1);
6313
+ await sleep(delay);
6314
+ }
6315
+ }
6316
+ throw lastError;
6317
+ }
6286
6318
  const isPin = (entity) => {
6287
6319
  return "activity" in entity;
6288
6320
  };
@@ -6550,7 +6582,7 @@ const _Feed = class _Feed extends FeedApi {
6550
6582
  const { last_get_or_create_request_config } = this.state.getLatestValue();
6551
6583
  if (last_get_or_create_request_config?.watch) {
6552
6584
  this.inProgressGetOrCreate = void 0;
6553
- await this.getOrCreate(last_get_or_create_request_config);
6585
+ await withRetry(() => this.getOrCreate(last_get_or_create_request_config));
6554
6586
  }
6555
6587
  }
6556
6588
  async getOrCreate(request) {
@@ -7102,7 +7134,7 @@ function handleUserUpdated(event) {
7102
7134
  }
7103
7135
  var UnhandledErrorType = /* @__PURE__ */ ((UnhandledErrorType2) => {
7104
7136
  UnhandledErrorType2["ReconnectionReconciliation"] = "reconnection-reconciliation";
7105
- UnhandledErrorType2["FetchingOwnCapabilitiesOnNewActivity"] = "fetching-own-capabilities-on-new-activity";
7137
+ UnhandledErrorType2["FetchingOwnFieldsOnNewActivity"] = "fetching-own-fields-on-new-activity";
7106
7138
  return UnhandledErrorType2;
7107
7139
  })(UnhandledErrorType || {});
7108
7140
  function updateCommentCount({
@@ -7354,7 +7386,7 @@ class FeedsClient extends FeedsApi {
7354
7386
  }).catch((error) => {
7355
7387
  this.eventDispatcher.dispatch({
7356
7388
  type: "errors.unhandled",
7357
- error_type: UnhandledErrorType.FetchingOwnCapabilitiesOnNewActivity,
7389
+ error_type: UnhandledErrorType.FetchingOwnFieldsOnNewActivity,
7358
7390
  error
7359
7391
  });
7360
7392
  });
@@ -7382,11 +7414,13 @@ class FeedsClient extends FeedsApi {
7382
7414
  const feed = feedEntries[index]?.[0] ?? (activity && getFeed.call(activity)?.feed);
7383
7415
  return [{ feed, reason: result.reason, activity_id: activity?.id }];
7384
7416
  });
7385
- this.eventDispatcher.dispatch({
7386
- type: "errors.unhandled",
7387
- error_type: UnhandledErrorType.ReconnectionReconciliation,
7388
- failures
7389
- });
7417
+ if (failures.length > 0) {
7418
+ this.eventDispatcher.dispatch({
7419
+ type: "errors.unhandled",
7420
+ error_type: UnhandledErrorType.ReconnectionReconciliation,
7421
+ failures
7422
+ });
7423
+ }
7390
7424
  }
7391
7425
  };
7392
7426
  this.pollFromState = (id) => this.polls_by_id.get(id);
@@ -7578,6 +7612,7 @@ class FeedsClient extends FeedsApi {
7578
7612
  this.polls_by_id.clear();
7579
7613
  this.activeActivities = [];
7580
7614
  this.activeFeeds = {};
7615
+ this.healthyConnectionChangedEventCount = 0;
7581
7616
  this.state.partialNext(this.initialState);
7582
7617
  this.cancelGetBatchOwnFieldsTimer();
7583
7618
  clearQueuedFeeds();
@@ -7842,7 +7877,7 @@ class FeedsClient extends FeedsApi {
7842
7877
  };
7843
7878
  }
7844
7879
  async ownBatch(request) {
7845
- const response = await super.ownBatch(request);
7880
+ const response = await withRetry(() => super.ownBatch(request));
7846
7881
  Object.entries(response.data).forEach(([fid, ownFields]) => {
7847
7882
  const feed = this.activeFeeds[fid];
7848
7883
  if (feed) {
@@ -8025,4 +8060,4 @@ export {
8025
8060
  shouldUpdateState as s,
8026
8061
  uniqueArrayMerge as u
8027
8062
  };
8028
- //# sourceMappingURL=feeds-client-BIM-XpQr.mjs.map
8063
+ //# sourceMappingURL=feeds-client-O3lXU8Bl.mjs.map