@wildix/xbees-conversations-utils 1.1.61 → 1.1.62

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.
@@ -7,10 +7,15 @@ const createRateLimitExceededException_1 = require("./createRateLimitExceededExc
7
7
  const processStreamRateLimitException_1 = require("./processStreamRateLimitException");
8
8
  const RedisCooldown_1 = require("./RedisCooldown");
9
9
  function calculateRateLimitDelayMs(error, maxDelayMs) {
10
- const retryAfterMs = typeof error.retryAfter === 'number' ? error.retryAfter + constants_1.RETRY_AFTER_BUFFER_MS : constants_1.DEFAULT_RETRY_AFTER_MS;
11
- if (retryAfterMs > 0) {
10
+ const hasServerRetryAfter = typeof error.retryAfter === 'number' && error.retryAfter > 0;
11
+ const baseDelayMs = hasServerRetryAfter ? error.retryAfter + constants_1.RETRY_AFTER_BUFFER_MS : constants_1.DEFAULT_RETRY_AFTER_MS;
12
+ if (baseDelayMs > 0) {
12
13
  const jitterMs = Math.floor(Math.random() * constants_1.DEFAULT_JITTER_MS);
13
- return Math.min(maxDelayMs, retryAfterMs + jitterMs);
14
+ const computedDelayMs = baseDelayMs + jitterMs;
15
+ if (hasServerRetryAfter) {
16
+ return computedDelayMs;
17
+ }
18
+ return Math.min(maxDelayMs, computedDelayMs);
14
19
  }
15
20
  return Math.min(maxDelayMs, constants_1.DEFAULT_FIXED_RATE_LIMIT_DELAY_MS);
16
21
  }
@@ -4,10 +4,15 @@ import { createRateLimitExceededException } from './createRateLimitExceededExcep
4
4
  import { processStreamRateLimitException } from './processStreamRateLimitException';
5
5
  import { RedisCooldown } from './RedisCooldown';
6
6
  function calculateRateLimitDelayMs(error, maxDelayMs) {
7
- const retryAfterMs = typeof error.retryAfter === 'number' ? error.retryAfter + RETRY_AFTER_BUFFER_MS : DEFAULT_RETRY_AFTER_MS;
8
- if (retryAfterMs > 0) {
7
+ const hasServerRetryAfter = typeof error.retryAfter === 'number' && error.retryAfter > 0;
8
+ const baseDelayMs = hasServerRetryAfter ? error.retryAfter + RETRY_AFTER_BUFFER_MS : DEFAULT_RETRY_AFTER_MS;
9
+ if (baseDelayMs > 0) {
9
10
  const jitterMs = Math.floor(Math.random() * DEFAULT_JITTER_MS);
10
- return Math.min(maxDelayMs, retryAfterMs + jitterMs);
11
+ const computedDelayMs = baseDelayMs + jitterMs;
12
+ if (hasServerRetryAfter) {
13
+ return computedDelayMs;
14
+ }
15
+ return Math.min(maxDelayMs, computedDelayMs);
11
16
  }
12
17
  return Math.min(maxDelayMs, DEFAULT_FIXED_RATE_LIMIT_DELAY_MS);
13
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildix/xbees-conversations-utils",
3
- "version": "1.1.61",
3
+ "version": "1.1.62",
4
4
  "description": "",
5
5
  "main": "./dist-cjs/index.js",
6
6
  "module": "./dist-es/index.js",