@wildix/xbees-conversations-utils 1.2.1 → 1.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.
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.executeWithRateLimitHandling = void 0;
4
- const promises_1 = require("node:timers/promises");
4
+ const tslib_1 = require("tslib");
5
5
  const constants_1 = require("../constants");
6
6
  const createRateLimitExceededException_1 = require("./createRateLimitExceededException");
7
7
  const processStreamRateLimitException_1 = require("./processStreamRateLimitException");
8
8
  const rateLimitSnapshot_1 = require("./rateLimitSnapshot");
9
9
  const RedisCooldown_1 = require("./RedisCooldown");
10
+ const sleep_1 = tslib_1.__importDefault(require("./sleep"));
10
11
  function calculateRateLimitDelayMs(error, maxDelayMs) {
11
12
  const retryAfterMs = typeof error.rateLimitReset === 'number' && error.rateLimitReset > 0 ? error.rateLimitReset : 0;
12
13
  const hasServerRetryAfter = retryAfterMs > 0;
@@ -77,7 +78,7 @@ async function executeWithRateLimitHandling(execute, operation, context, options
77
78
  operation,
78
79
  cooldown: softCooldownMs,
79
80
  });
80
- await (0, promises_1.setTimeout)(softCooldownMs);
81
+ await (0, sleep_1.default)(softCooldownMs);
81
82
  waitedForSharedCooldown = true;
82
83
  }
83
84
  const budgetCooldownMs = await RedisCooldown_1.RedisCooldown.getRemainingMs(constants_1.STREAM_BUDGET_COOLDOWN_KEY, { redis, logger }, { keyPrefix: constants_1.STREAM_BUDGET_COOLDOWN_KEY_PREFIX });
@@ -93,7 +94,7 @@ async function executeWithRateLimitHandling(execute, operation, context, options
93
94
  break;
94
95
  }
95
96
  const chunkMs = Math.min(waitMs, constants_1.BUDGET_COOLDOWN_SLEEP_CHUNK_MS, constants_1.BUDGET_DELAY_MAX_MS - totalBudgetWaitMs);
96
- await (0, promises_1.setTimeout)(chunkMs);
97
+ await (0, sleep_1.default)(chunkMs);
97
98
  totalBudgetWaitMs += chunkMs;
98
99
  waitedForSharedCooldown = true;
99
100
  }
@@ -131,7 +132,7 @@ async function executeWithRateLimitHandling(execute, operation, context, options
131
132
  rateLimitRemaining: rateLimitError.rateLimitRemaining,
132
133
  rateLimitReset: rateLimitError.rateLimitReset,
133
134
  });
134
- await (0, promises_1.setTimeout)(retryAfterMs);
135
+ await (0, sleep_1.default)(retryAfterMs);
135
136
  attempt++;
136
137
  continue;
137
138
  }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ async function sleep(ms) {
4
+ return new Promise((resolve) => setTimeout(resolve, ms));
5
+ }
6
+ exports.default = sleep;
@@ -1,9 +1,9 @@
1
- import { setTimeout as sleep } from 'node:timers/promises';
2
1
  import { BUDGET_COOLDOWN_SLEEP_CHUNK_MS, BUDGET_DELAY_MAX_MS, DEFAULT_JITTER_MS, DEFAULT_RETRY_AFTER_MS, RETRY_AFTER_BUFFER_MS, STREAM_BUDGET_COOLDOWN_KEY, STREAM_BUDGET_COOLDOWN_KEY_PREFIX, STREAM_RATE_LIMIT_COOLDOWN_KEY_PREFIX, STREAM_RATE_LIMIT_METADATA_KEY_SUFFIX, STREAM_RATE_LIMIT_SOFT_COOLDOWN_KEY, } from '../constants';
3
2
  import { createRateLimitExceededException } from './createRateLimitExceededException';
4
3
  import { processStreamRateLimitException } from './processStreamRateLimitException';
5
4
  import { parseRateLimitSnapshot, serializeRateLimitSnapshot } from './rateLimitSnapshot';
6
5
  import { RedisCooldown } from './RedisCooldown';
6
+ import sleep from './sleep';
7
7
  function calculateRateLimitDelayMs(error, maxDelayMs) {
8
8
  const retryAfterMs = typeof error.rateLimitReset === 'number' && error.rateLimitReset > 0 ? error.rateLimitReset : 0;
9
9
  const hasServerRetryAfter = retryAfterMs > 0;
@@ -0,0 +1,4 @@
1
+ async function sleep(ms) {
2
+ return new Promise((resolve) => setTimeout(resolve, ms));
3
+ }
4
+ export default sleep;
@@ -0,0 +1,2 @@
1
+ declare function sleep(ms: number): Promise<unknown>;
2
+ export default sleep;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildix/xbees-conversations-utils",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "",
5
5
  "main": "./dist-cjs/index.js",
6
6
  "module": "./dist-es/index.js",