@wildix/xbees-conversations-utils 1.1.74 → 1.1.75
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/dist-cjs/rateLimits/constants.js +3 -3
- package/dist-cjs/rateLimits/helpers/createRateLimitExceededException.js +4 -4
- package/dist-cjs/rateLimits/helpers/executeWithRateLimitHandling.js +16 -2
- package/dist-es/rateLimits/constants.js +3 -3
- package/dist-es/rateLimits/helpers/createRateLimitExceededException.js +4 -4
- package/dist-es/rateLimits/helpers/executeWithRateLimitHandling.js +16 -2
- package/dist-types/rateLimits/constants.d.ts +3 -3
- package/package.json +1 -1
|
@@ -16,9 +16,9 @@ exports.BUDGET_DELAY_MAX_MS = 60000;
|
|
|
16
16
|
exports.SOFT_THROTTLE_USAGE_LOW = 0.7;
|
|
17
17
|
exports.SOFT_THROTTLE_USAGE_MEDIUM = 0.85;
|
|
18
18
|
exports.SOFT_THROTTLE_USAGE_HIGH = 0.95;
|
|
19
|
-
exports.SOFT_THROTTLE_DELAY_LOW_MS =
|
|
20
|
-
exports.SOFT_THROTTLE_DELAY_MEDIUM_MS =
|
|
21
|
-
exports.SOFT_THROTTLE_DELAY_HIGH_MS =
|
|
19
|
+
exports.SOFT_THROTTLE_DELAY_LOW_MS = 500;
|
|
20
|
+
exports.SOFT_THROTTLE_DELAY_MEDIUM_MS = 1500;
|
|
21
|
+
exports.SOFT_THROTTLE_DELAY_HIGH_MS = 3000;
|
|
22
22
|
exports.STREAM_SYNC_CHANNEL_RESULT_METHOD_NAMES = [
|
|
23
23
|
'channel',
|
|
24
24
|
'getChannelById',
|
|
@@ -6,9 +6,9 @@ const constants_1 = require("../constants");
|
|
|
6
6
|
function toPositiveMilliseconds(milliseconds) {
|
|
7
7
|
return Math.max(0, Math.ceil(milliseconds));
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function toHttpDateFromDelayMs(delayMs) {
|
|
10
10
|
const positiveDelayMs = toPositiveMilliseconds(delayMs);
|
|
11
|
-
return
|
|
11
|
+
return new Date(Date.now() + positiveDelayMs).toUTCString();
|
|
12
12
|
}
|
|
13
13
|
function createRateLimitExceededException(options = {}) {
|
|
14
14
|
const { rateLimit, message, operation, retryAfterMs = constants_1.DEFAULT_RETRY_AFTER_MS } = options;
|
|
@@ -16,7 +16,7 @@ function createRateLimitExceededException(options = {}) {
|
|
|
16
16
|
const retryAfterFromResetMs = rateLimit?.reset ? rateLimit.reset - Date.now() : undefined;
|
|
17
17
|
const effectiveRetryAfterMs = retryAfterFromResetMs ?? retryAfterMs;
|
|
18
18
|
const retryAfterMilliseconds = toPositiveMilliseconds(effectiveRetryAfterMs);
|
|
19
|
-
const
|
|
19
|
+
const retryAfterHttpDate = toHttpDateFromDelayMs(effectiveRetryAfterMs);
|
|
20
20
|
const rateLimitResetMilliseconds = rateLimit?.reset
|
|
21
21
|
? toPositiveMilliseconds(retryAfterFromResetMs ?? 0)
|
|
22
22
|
: retryAfterMilliseconds;
|
|
@@ -24,7 +24,7 @@ function createRateLimitExceededException(options = {}) {
|
|
|
24
24
|
$metadata: {},
|
|
25
25
|
message: message || defaultMessage,
|
|
26
26
|
rateLimitRemaining: rateLimit?.remaining || 0,
|
|
27
|
-
retryAfter:
|
|
27
|
+
retryAfter: retryAfterHttpDate,
|
|
28
28
|
rateLimit: rateLimit?.limit?.toString() || 'unknown',
|
|
29
29
|
rateLimitReset: rateLimitResetMilliseconds,
|
|
30
30
|
});
|
|
@@ -7,6 +7,20 @@ const createRateLimitExceededException_1 = require("./createRateLimitExceededExc
|
|
|
7
7
|
const processStreamRateLimitException_1 = require("./processStreamRateLimitException");
|
|
8
8
|
const RedisCooldown_1 = require("./RedisCooldown");
|
|
9
9
|
function normalizeRetryAfterToDelayMs(retryAfter) {
|
|
10
|
+
if (typeof retryAfter === 'string') {
|
|
11
|
+
const asDateMs = Date.parse(retryAfter);
|
|
12
|
+
if (!Number.isNaN(asDateMs)) {
|
|
13
|
+
return Math.max(0, Math.round(asDateMs - Date.now()));
|
|
14
|
+
}
|
|
15
|
+
const asSeconds = Number(retryAfter);
|
|
16
|
+
if (Number.isFinite(asSeconds) && asSeconds > 0) {
|
|
17
|
+
return Math.max(0, Math.round(asSeconds * 1000));
|
|
18
|
+
}
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
if (typeof retryAfter !== 'number' || !Number.isFinite(retryAfter) || retryAfter <= 0) {
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
10
24
|
if (retryAfter > 1000000000) {
|
|
11
25
|
return Math.max(0, Math.round(retryAfter * 1000 - Date.now()));
|
|
12
26
|
}
|
|
@@ -16,8 +30,8 @@ function normalizeRetryAfterToDelayMs(retryAfter) {
|
|
|
16
30
|
return Math.max(0, Math.round(retryAfter * 1000));
|
|
17
31
|
}
|
|
18
32
|
function calculateRateLimitDelayMs(error, maxDelayMs) {
|
|
19
|
-
const
|
|
20
|
-
const
|
|
33
|
+
const retryAfterMsFromError = normalizeRetryAfterToDelayMs(error.retryAfter);
|
|
34
|
+
const hasServerRetryAfter = retryAfterMsFromError > 0;
|
|
21
35
|
const baseDelayMs = hasServerRetryAfter ? retryAfterMsFromError + constants_1.RETRY_AFTER_BUFFER_MS : constants_1.DEFAULT_RETRY_AFTER_MS;
|
|
22
36
|
if (baseDelayMs > 0) {
|
|
23
37
|
const jitterMs = Math.floor(Math.random() * constants_1.DEFAULT_JITTER_MS);
|
|
@@ -13,9 +13,9 @@ export const BUDGET_DELAY_MAX_MS = 60000;
|
|
|
13
13
|
export const SOFT_THROTTLE_USAGE_LOW = 0.7;
|
|
14
14
|
export const SOFT_THROTTLE_USAGE_MEDIUM = 0.85;
|
|
15
15
|
export const SOFT_THROTTLE_USAGE_HIGH = 0.95;
|
|
16
|
-
export const SOFT_THROTTLE_DELAY_LOW_MS =
|
|
17
|
-
export const SOFT_THROTTLE_DELAY_MEDIUM_MS =
|
|
18
|
-
export const SOFT_THROTTLE_DELAY_HIGH_MS =
|
|
16
|
+
export const SOFT_THROTTLE_DELAY_LOW_MS = 500;
|
|
17
|
+
export const SOFT_THROTTLE_DELAY_MEDIUM_MS = 1500;
|
|
18
|
+
export const SOFT_THROTTLE_DELAY_HIGH_MS = 3000;
|
|
19
19
|
export const STREAM_SYNC_CHANNEL_RESULT_METHOD_NAMES = [
|
|
20
20
|
'channel',
|
|
21
21
|
'getChannelById',
|
|
@@ -3,9 +3,9 @@ import { DEFAULT_RETRY_AFTER_MS } from '../constants';
|
|
|
3
3
|
function toPositiveMilliseconds(milliseconds) {
|
|
4
4
|
return Math.max(0, Math.ceil(milliseconds));
|
|
5
5
|
}
|
|
6
|
-
function
|
|
6
|
+
function toHttpDateFromDelayMs(delayMs) {
|
|
7
7
|
const positiveDelayMs = toPositiveMilliseconds(delayMs);
|
|
8
|
-
return
|
|
8
|
+
return new Date(Date.now() + positiveDelayMs).toUTCString();
|
|
9
9
|
}
|
|
10
10
|
export function createRateLimitExceededException(options = {}) {
|
|
11
11
|
const { rateLimit, message, operation, retryAfterMs = DEFAULT_RETRY_AFTER_MS } = options;
|
|
@@ -13,7 +13,7 @@ export function createRateLimitExceededException(options = {}) {
|
|
|
13
13
|
const retryAfterFromResetMs = rateLimit?.reset ? rateLimit.reset - Date.now() : undefined;
|
|
14
14
|
const effectiveRetryAfterMs = retryAfterFromResetMs ?? retryAfterMs;
|
|
15
15
|
const retryAfterMilliseconds = toPositiveMilliseconds(effectiveRetryAfterMs);
|
|
16
|
-
const
|
|
16
|
+
const retryAfterHttpDate = toHttpDateFromDelayMs(effectiveRetryAfterMs);
|
|
17
17
|
const rateLimitResetMilliseconds = rateLimit?.reset
|
|
18
18
|
? toPositiveMilliseconds(retryAfterFromResetMs ?? 0)
|
|
19
19
|
: retryAfterMilliseconds;
|
|
@@ -21,7 +21,7 @@ export function createRateLimitExceededException(options = {}) {
|
|
|
21
21
|
$metadata: {},
|
|
22
22
|
message: message || defaultMessage,
|
|
23
23
|
rateLimitRemaining: rateLimit?.remaining || 0,
|
|
24
|
-
retryAfter:
|
|
24
|
+
retryAfter: retryAfterHttpDate,
|
|
25
25
|
rateLimit: rateLimit?.limit?.toString() || 'unknown',
|
|
26
26
|
rateLimitReset: rateLimitResetMilliseconds,
|
|
27
27
|
});
|
|
@@ -4,6 +4,20 @@ import { createRateLimitExceededException } from './createRateLimitExceededExcep
|
|
|
4
4
|
import { processStreamRateLimitException } from './processStreamRateLimitException';
|
|
5
5
|
import { RedisCooldown } from './RedisCooldown';
|
|
6
6
|
function normalizeRetryAfterToDelayMs(retryAfter) {
|
|
7
|
+
if (typeof retryAfter === 'string') {
|
|
8
|
+
const asDateMs = Date.parse(retryAfter);
|
|
9
|
+
if (!Number.isNaN(asDateMs)) {
|
|
10
|
+
return Math.max(0, Math.round(asDateMs - Date.now()));
|
|
11
|
+
}
|
|
12
|
+
const asSeconds = Number(retryAfter);
|
|
13
|
+
if (Number.isFinite(asSeconds) && asSeconds > 0) {
|
|
14
|
+
return Math.max(0, Math.round(asSeconds * 1000));
|
|
15
|
+
}
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
if (typeof retryAfter !== 'number' || !Number.isFinite(retryAfter) || retryAfter <= 0) {
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
7
21
|
if (retryAfter > 1000000000) {
|
|
8
22
|
return Math.max(0, Math.round(retryAfter * 1000 - Date.now()));
|
|
9
23
|
}
|
|
@@ -13,8 +27,8 @@ function normalizeRetryAfterToDelayMs(retryAfter) {
|
|
|
13
27
|
return Math.max(0, Math.round(retryAfter * 1000));
|
|
14
28
|
}
|
|
15
29
|
function calculateRateLimitDelayMs(error, maxDelayMs) {
|
|
16
|
-
const
|
|
17
|
-
const
|
|
30
|
+
const retryAfterMsFromError = normalizeRetryAfterToDelayMs(error.retryAfter);
|
|
31
|
+
const hasServerRetryAfter = retryAfterMsFromError > 0;
|
|
18
32
|
const baseDelayMs = hasServerRetryAfter ? retryAfterMsFromError + RETRY_AFTER_BUFFER_MS : DEFAULT_RETRY_AFTER_MS;
|
|
19
33
|
if (baseDelayMs > 0) {
|
|
20
34
|
const jitterMs = Math.floor(Math.random() * DEFAULT_JITTER_MS);
|
|
@@ -14,9 +14,9 @@ export declare const BUDGET_DELAY_MAX_MS = 60000;
|
|
|
14
14
|
export declare const SOFT_THROTTLE_USAGE_LOW = 0.7;
|
|
15
15
|
export declare const SOFT_THROTTLE_USAGE_MEDIUM = 0.85;
|
|
16
16
|
export declare const SOFT_THROTTLE_USAGE_HIGH = 0.95;
|
|
17
|
-
export declare const SOFT_THROTTLE_DELAY_LOW_MS =
|
|
18
|
-
export declare const SOFT_THROTTLE_DELAY_MEDIUM_MS =
|
|
19
|
-
export declare const SOFT_THROTTLE_DELAY_HIGH_MS =
|
|
17
|
+
export declare const SOFT_THROTTLE_DELAY_LOW_MS = 500;
|
|
18
|
+
export declare const SOFT_THROTTLE_DELAY_MEDIUM_MS = 1500;
|
|
19
|
+
export declare const SOFT_THROTTLE_DELAY_HIGH_MS = 3000;
|
|
20
20
|
export declare const STREAM_SYNC_CHANNEL_RESULT_METHOD_NAMES: readonly ["channel", "getChannelById", "getChannelByMembers", "hydrateActiveChannels"];
|
|
21
21
|
export declare const STREAM_SYNC_METHOD_NAMES: readonly ["_addChannelConfig", "_buildWSPayload", "_callClientListeners", "_deleteUserMessageReference", "_enrichAxiosOptions", "_getConnectionID", "_getToken", "_handleClientEvent", "_handleUserEvent", "_hasConnectionID", "_isUsingServerAuth", "_logApiError", "_logApiRequest", "_logApiResponse", "_muteStatus", "_normalizeDate", "_normalizeExpiration", "_sayHi", "_setUser", "_startCleaning", "_updateMemberWatcherReferences", "_updateUserMessageReferences", "_updateUserReferences", "_validateAndGetMessageId", "createAbortControllerForNextRequest", "createToken", "devToken", "dispatchEvent", "errorFromResponse", "getAuthType", "getUserAgent", "handleEvent", "handleResponse", "off", "on", "setBaseURL", "setLocalDevice", "setUserAgent", "userMuteStatus", "verifyWebhook"];
|
|
22
22
|
export declare const CHANNEL_SYNC_METHOD_NAMES: readonly ["_channelURL", "countUnread", "countUnreadMentions", "getConfig", "lastMessage", "lastRead", "muteStatus", "off", "on"];
|