@wildix/xbees-conversations-utils 1.1.66 → 1.1.68
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 +61 -1
- package/dist-cjs/rateLimits/createRateLimitedStreamProxy.js +19 -3
- package/dist-es/rateLimits/constants.js +60 -0
- package/dist-es/rateLimits/createRateLimitedStreamProxy.js +20 -4
- package/dist-types/rateLimits/constants.d.ts +4 -0
- package/package.json +1 -1
|
@@ -1,12 +1,72 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_OPTIONS = exports.STREAM_RATE_LIMIT_OPTIONS_MARKER = exports.STREAM_RATE_LIMIT_COOLDOWN_KEY_PREFIX = exports.RETRY_AFTER_BUFFER_MS = exports.DEFAULT_JITTER_MS = exports.DEFAULT_RETRY_AFTER_MS = exports.DEFAULT_MAX_DELAY_MS = void 0;
|
|
3
|
+
exports.DEFAULT_OPTIONS = exports.CHANNEL_SYNC_PROXY_RESULT_METHOD_NAMES = exports.CHANNEL_SYNC_METHOD_NAMES = exports.STREAM_SYNC_METHOD_NAMES = exports.STREAM_SYNC_CHANNEL_RESULT_METHOD_NAMES = exports.STREAM_RATE_LIMIT_OPTIONS_MARKER = exports.STREAM_RATE_LIMIT_COOLDOWN_KEY_PREFIX = exports.RETRY_AFTER_BUFFER_MS = exports.DEFAULT_JITTER_MS = exports.DEFAULT_RETRY_AFTER_MS = exports.DEFAULT_MAX_DELAY_MS = void 0;
|
|
4
4
|
exports.DEFAULT_MAX_DELAY_MS = 5000;
|
|
5
5
|
exports.DEFAULT_RETRY_AFTER_MS = 10000;
|
|
6
6
|
exports.DEFAULT_JITTER_MS = 150;
|
|
7
7
|
exports.RETRY_AFTER_BUFFER_MS = 1000;
|
|
8
8
|
exports.STREAM_RATE_LIMIT_COOLDOWN_KEY_PREFIX = 'stream-rate-limit-cooldown:';
|
|
9
9
|
exports.STREAM_RATE_LIMIT_OPTIONS_MARKER = '__xbsRateLimitOptions';
|
|
10
|
+
exports.STREAM_SYNC_CHANNEL_RESULT_METHOD_NAMES = [
|
|
11
|
+
'channel',
|
|
12
|
+
'getChannelById',
|
|
13
|
+
'getChannelByMembers',
|
|
14
|
+
'hydrateActiveChannels',
|
|
15
|
+
];
|
|
16
|
+
exports.STREAM_SYNC_METHOD_NAMES = [
|
|
17
|
+
'_addChannelConfig',
|
|
18
|
+
'_buildWSPayload',
|
|
19
|
+
'_callClientListeners',
|
|
20
|
+
'_deleteUserMessageReference',
|
|
21
|
+
'_enrichAxiosOptions',
|
|
22
|
+
'_getConnectionID',
|
|
23
|
+
'_getToken',
|
|
24
|
+
'_handleClientEvent',
|
|
25
|
+
'_handleUserEvent',
|
|
26
|
+
'_hasConnectionID',
|
|
27
|
+
'_isUsingServerAuth',
|
|
28
|
+
'_logApiError',
|
|
29
|
+
'_logApiRequest',
|
|
30
|
+
'_logApiResponse',
|
|
31
|
+
'_muteStatus',
|
|
32
|
+
'_normalizeDate',
|
|
33
|
+
'_normalizeExpiration',
|
|
34
|
+
'_sayHi',
|
|
35
|
+
'_setUser',
|
|
36
|
+
'_startCleaning',
|
|
37
|
+
'_updateMemberWatcherReferences',
|
|
38
|
+
'_updateUserMessageReferences',
|
|
39
|
+
'_updateUserReferences',
|
|
40
|
+
'_validateAndGetMessageId',
|
|
41
|
+
'createAbortControllerForNextRequest',
|
|
42
|
+
'createToken',
|
|
43
|
+
'devToken',
|
|
44
|
+
'dispatchEvent',
|
|
45
|
+
'errorFromResponse',
|
|
46
|
+
'getAuthType',
|
|
47
|
+
'getUserAgent',
|
|
48
|
+
'handleEvent',
|
|
49
|
+
'handleResponse',
|
|
50
|
+
'off',
|
|
51
|
+
'on',
|
|
52
|
+
'setBaseURL',
|
|
53
|
+
'setLocalDevice',
|
|
54
|
+
'setUserAgent',
|
|
55
|
+
'userMuteStatus',
|
|
56
|
+
'verifyWebhook',
|
|
57
|
+
];
|
|
58
|
+
exports.CHANNEL_SYNC_METHOD_NAMES = [
|
|
59
|
+
'_channelURL',
|
|
60
|
+
'countUnread',
|
|
61
|
+
'countUnreadMentions',
|
|
62
|
+
'getConfig',
|
|
63
|
+
'lastMessage',
|
|
64
|
+
'lastRead',
|
|
65
|
+
'muteStatus',
|
|
66
|
+
'off',
|
|
67
|
+
'on',
|
|
68
|
+
];
|
|
69
|
+
exports.CHANNEL_SYNC_PROXY_RESULT_METHOD_NAMES = ['getClient'];
|
|
10
70
|
exports.DEFAULT_OPTIONS = {
|
|
11
71
|
maxAttempts: 3,
|
|
12
72
|
enableCooldown: true,
|
|
@@ -5,6 +5,10 @@ const constants_1 = require("./constants");
|
|
|
5
5
|
const executeWithRateLimitHandling_1 = require("./helpers/executeWithRateLimitHandling");
|
|
6
6
|
const isStreamChannelLike_1 = require("./helpers/isStreamChannelLike");
|
|
7
7
|
const splitCallArgsAndOptions_1 = require("./helpers/splitCallArgsAndOptions");
|
|
8
|
+
const STREAM_SYNC_METHODS = new Set(constants_1.STREAM_SYNC_METHOD_NAMES);
|
|
9
|
+
const STREAM_SYNC_CHANNEL_RESULT_METHODS = new Set(constants_1.STREAM_SYNC_CHANNEL_RESULT_METHOD_NAMES);
|
|
10
|
+
const CHANNEL_SYNC_METHODS = new Set(constants_1.CHANNEL_SYNC_METHOD_NAMES);
|
|
11
|
+
const CHANNEL_SYNC_PROXY_RESULT_METHODS = new Set(constants_1.CHANNEL_SYNC_PROXY_RESULT_METHOD_NAMES);
|
|
8
12
|
function normalizeStreamCallResult(result, dependencies) {
|
|
9
13
|
if (Array.isArray(result)) {
|
|
10
14
|
return result.map((item) => normalizeStreamCallResult(item, dependencies));
|
|
@@ -35,12 +39,24 @@ function wrapTarget(target, dependencies) {
|
|
|
35
39
|
if (typeof property !== 'string' || typeof value !== 'function') {
|
|
36
40
|
return value;
|
|
37
41
|
}
|
|
38
|
-
if (property
|
|
42
|
+
if (STREAM_SYNC_CHANNEL_RESULT_METHODS.has(property)) {
|
|
39
43
|
return (...args) => {
|
|
40
|
-
const
|
|
41
|
-
return normalizeStreamCallResult(
|
|
44
|
+
const result = Reflect.apply(value, originalTarget, args);
|
|
45
|
+
return normalizeStreamCallResult(result, dependencies);
|
|
42
46
|
};
|
|
43
47
|
}
|
|
48
|
+
if (CHANNEL_SYNC_PROXY_RESULT_METHODS.has(property)) {
|
|
49
|
+
return (...args) => {
|
|
50
|
+
const result = Reflect.apply(value, originalTarget, args);
|
|
51
|
+
if (typeof result === 'object' && result !== null) {
|
|
52
|
+
return wrapTarget(result, dependencies);
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (STREAM_SYNC_METHODS.has(property) || CHANNEL_SYNC_METHODS.has(property)) {
|
|
58
|
+
return (...args) => Reflect.apply(value, originalTarget, args);
|
|
59
|
+
}
|
|
44
60
|
return createRateLimitedMethodWrapper(originalTarget, value, property, dependencies);
|
|
45
61
|
},
|
|
46
62
|
});
|
|
@@ -4,6 +4,66 @@ export const DEFAULT_JITTER_MS = 150;
|
|
|
4
4
|
export const RETRY_AFTER_BUFFER_MS = 1000;
|
|
5
5
|
export const STREAM_RATE_LIMIT_COOLDOWN_KEY_PREFIX = 'stream-rate-limit-cooldown:';
|
|
6
6
|
export const STREAM_RATE_LIMIT_OPTIONS_MARKER = '__xbsRateLimitOptions';
|
|
7
|
+
export const STREAM_SYNC_CHANNEL_RESULT_METHOD_NAMES = [
|
|
8
|
+
'channel',
|
|
9
|
+
'getChannelById',
|
|
10
|
+
'getChannelByMembers',
|
|
11
|
+
'hydrateActiveChannels',
|
|
12
|
+
];
|
|
13
|
+
export const STREAM_SYNC_METHOD_NAMES = [
|
|
14
|
+
'_addChannelConfig',
|
|
15
|
+
'_buildWSPayload',
|
|
16
|
+
'_callClientListeners',
|
|
17
|
+
'_deleteUserMessageReference',
|
|
18
|
+
'_enrichAxiosOptions',
|
|
19
|
+
'_getConnectionID',
|
|
20
|
+
'_getToken',
|
|
21
|
+
'_handleClientEvent',
|
|
22
|
+
'_handleUserEvent',
|
|
23
|
+
'_hasConnectionID',
|
|
24
|
+
'_isUsingServerAuth',
|
|
25
|
+
'_logApiError',
|
|
26
|
+
'_logApiRequest',
|
|
27
|
+
'_logApiResponse',
|
|
28
|
+
'_muteStatus',
|
|
29
|
+
'_normalizeDate',
|
|
30
|
+
'_normalizeExpiration',
|
|
31
|
+
'_sayHi',
|
|
32
|
+
'_setUser',
|
|
33
|
+
'_startCleaning',
|
|
34
|
+
'_updateMemberWatcherReferences',
|
|
35
|
+
'_updateUserMessageReferences',
|
|
36
|
+
'_updateUserReferences',
|
|
37
|
+
'_validateAndGetMessageId',
|
|
38
|
+
'createAbortControllerForNextRequest',
|
|
39
|
+
'createToken',
|
|
40
|
+
'devToken',
|
|
41
|
+
'dispatchEvent',
|
|
42
|
+
'errorFromResponse',
|
|
43
|
+
'getAuthType',
|
|
44
|
+
'getUserAgent',
|
|
45
|
+
'handleEvent',
|
|
46
|
+
'handleResponse',
|
|
47
|
+
'off',
|
|
48
|
+
'on',
|
|
49
|
+
'setBaseURL',
|
|
50
|
+
'setLocalDevice',
|
|
51
|
+
'setUserAgent',
|
|
52
|
+
'userMuteStatus',
|
|
53
|
+
'verifyWebhook',
|
|
54
|
+
];
|
|
55
|
+
export const CHANNEL_SYNC_METHOD_NAMES = [
|
|
56
|
+
'_channelURL',
|
|
57
|
+
'countUnread',
|
|
58
|
+
'countUnreadMentions',
|
|
59
|
+
'getConfig',
|
|
60
|
+
'lastMessage',
|
|
61
|
+
'lastRead',
|
|
62
|
+
'muteStatus',
|
|
63
|
+
'off',
|
|
64
|
+
'on',
|
|
65
|
+
];
|
|
66
|
+
export const CHANNEL_SYNC_PROXY_RESULT_METHOD_NAMES = ['getClient'];
|
|
7
67
|
export const DEFAULT_OPTIONS = {
|
|
8
68
|
maxAttempts: 3,
|
|
9
69
|
enableCooldown: true,
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { DEFAULT_OPTIONS } from './constants';
|
|
1
|
+
import { CHANNEL_SYNC_METHOD_NAMES, CHANNEL_SYNC_PROXY_RESULT_METHOD_NAMES, DEFAULT_OPTIONS, STREAM_SYNC_CHANNEL_RESULT_METHOD_NAMES, STREAM_SYNC_METHOD_NAMES, } from './constants';
|
|
2
2
|
import { executeWithRateLimitHandling } from './helpers/executeWithRateLimitHandling';
|
|
3
3
|
import { isStreamChannelLike } from './helpers/isStreamChannelLike';
|
|
4
4
|
import { splitCallArgsAndOptions } from './helpers/splitCallArgsAndOptions';
|
|
5
|
+
const STREAM_SYNC_METHODS = new Set(STREAM_SYNC_METHOD_NAMES);
|
|
6
|
+
const STREAM_SYNC_CHANNEL_RESULT_METHODS = new Set(STREAM_SYNC_CHANNEL_RESULT_METHOD_NAMES);
|
|
7
|
+
const CHANNEL_SYNC_METHODS = new Set(CHANNEL_SYNC_METHOD_NAMES);
|
|
8
|
+
const CHANNEL_SYNC_PROXY_RESULT_METHODS = new Set(CHANNEL_SYNC_PROXY_RESULT_METHOD_NAMES);
|
|
5
9
|
function normalizeStreamCallResult(result, dependencies) {
|
|
6
10
|
if (Array.isArray(result)) {
|
|
7
11
|
return result.map((item) => normalizeStreamCallResult(item, dependencies));
|
|
@@ -32,12 +36,24 @@ function wrapTarget(target, dependencies) {
|
|
|
32
36
|
if (typeof property !== 'string' || typeof value !== 'function') {
|
|
33
37
|
return value;
|
|
34
38
|
}
|
|
35
|
-
if (property
|
|
39
|
+
if (STREAM_SYNC_CHANNEL_RESULT_METHODS.has(property)) {
|
|
36
40
|
return (...args) => {
|
|
37
|
-
const
|
|
38
|
-
return normalizeStreamCallResult(
|
|
41
|
+
const result = Reflect.apply(value, originalTarget, args);
|
|
42
|
+
return normalizeStreamCallResult(result, dependencies);
|
|
39
43
|
};
|
|
40
44
|
}
|
|
45
|
+
if (CHANNEL_SYNC_PROXY_RESULT_METHODS.has(property)) {
|
|
46
|
+
return (...args) => {
|
|
47
|
+
const result = Reflect.apply(value, originalTarget, args);
|
|
48
|
+
if (typeof result === 'object' && result !== null) {
|
|
49
|
+
return wrapTarget(result, dependencies);
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
if (STREAM_SYNC_METHODS.has(property) || CHANNEL_SYNC_METHODS.has(property)) {
|
|
55
|
+
return (...args) => Reflect.apply(value, originalTarget, args);
|
|
56
|
+
}
|
|
41
57
|
return createRateLimitedMethodWrapper(originalTarget, value, property, dependencies);
|
|
42
58
|
},
|
|
43
59
|
});
|
|
@@ -5,4 +5,8 @@ export declare const DEFAULT_JITTER_MS = 150;
|
|
|
5
5
|
export declare const RETRY_AFTER_BUFFER_MS = 1000;
|
|
6
6
|
export declare const STREAM_RATE_LIMIT_COOLDOWN_KEY_PREFIX = "stream-rate-limit-cooldown:";
|
|
7
7
|
export declare const STREAM_RATE_LIMIT_OPTIONS_MARKER = "__xbsRateLimitOptions";
|
|
8
|
+
export declare const STREAM_SYNC_CHANNEL_RESULT_METHOD_NAMES: readonly ["channel", "getChannelById", "getChannelByMembers", "hydrateActiveChannels"];
|
|
9
|
+
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"];
|
|
10
|
+
export declare const CHANNEL_SYNC_METHOD_NAMES: readonly ["_channelURL", "countUnread", "countUnreadMentions", "getConfig", "lastMessage", "lastRead", "muteStatus", "off", "on"];
|
|
11
|
+
export declare const CHANNEL_SYNC_PROXY_RESULT_METHOD_NAMES: readonly ["getClient"];
|
|
8
12
|
export declare const DEFAULT_OPTIONS: StreamRateLimitRetryOptions;
|