@wildix/xbees-conversations-utils 1.1.81 → 1.1.84
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/index.js +1 -2
- package/dist-cjs/normalization.js +1 -0
- package/dist-es/index.js +1 -2
- package/dist-es/normalization.js +1 -0
- package/dist-types/index.d.ts +1 -2
- package/dist-types/stream.d.ts +1 -0
- package/dist-types/types.d.ts +1 -1
- package/package.json +2 -10
- package/dist-cjs/rateLimits/RedisCooldown.js +0 -66
- package/dist-cjs/rateLimits/constants.js +0 -43
- package/dist-cjs/rateLimits/createRateLimitedStreamProxy.js +0 -92
- package/dist-cjs/rateLimits/exception/createRateLimitExceededException.js +0 -21
- package/dist-cjs/rateLimits/exception/processStreamRateLimitException.js +0 -47
- package/dist-cjs/rateLimits/executeStreamRequestWithRateLimitHandling.js +0 -94
- package/dist-cjs/rateLimits/generatedMethodNames.js +0 -320
- package/dist-cjs/rateLimits/helpers/RedisCooldown.js +0 -174
- package/dist-cjs/rateLimits/helpers/createRateLimitExceededException.js +0 -32
- package/dist-cjs/rateLimits/helpers/executeWithRateLimitHandling.js +0 -144
- package/dist-cjs/rateLimits/helpers/headerUtils.js +0 -40
- package/dist-cjs/rateLimits/helpers/isStreamChannelLike.js +0 -23
- package/dist-cjs/rateLimits/helpers/processStreamBudgetHeaders.js +0 -93
- package/dist-cjs/rateLimits/helpers/processStreamRateLimitException.js +0 -63
- package/dist-cjs/rateLimits/helpers/processStreamRateLimitHeaders.js +0 -50
- package/dist-cjs/rateLimits/helpers/rateLimitSnapshot.js +0 -31
- package/dist-cjs/rateLimits/helpers/registerStreamBudgetInterceptors.js +0 -48
- package/dist-cjs/rateLimits/helpers/registerStreamInterceptors.js +0 -58
- package/dist-cjs/rateLimits/helpers/splitCallArgsAndOptions.js +0 -21
- package/dist-cjs/rateLimits/index.js +0 -7
- package/dist-cjs/rateLimits/types.js +0 -3
- package/dist-cjs/rateLimits/withStreamRateLimitOptions.js +0 -10
- package/dist-es/rateLimits/RedisCooldown.js +0 -62
- package/dist-es/rateLimits/constants.js +0 -33
- package/dist-es/rateLimits/createRateLimitedStreamProxy.js +0 -88
- package/dist-es/rateLimits/exception/createRateLimitExceededException.js +0 -17
- package/dist-es/rateLimits/exception/processStreamRateLimitException.js +0 -37
- package/dist-es/rateLimits/executeStreamRequestWithRateLimitHandling.js +0 -93
- package/dist-es/rateLimits/generatedMethodNames.js +0 -317
- package/dist-es/rateLimits/helpers/RedisCooldown.js +0 -170
- package/dist-es/rateLimits/helpers/createRateLimitExceededException.js +0 -28
- package/dist-es/rateLimits/helpers/executeWithRateLimitHandling.js +0 -140
- package/dist-es/rateLimits/helpers/headerUtils.js +0 -34
- package/dist-es/rateLimits/helpers/isStreamChannelLike.js +0 -19
- package/dist-es/rateLimits/helpers/processStreamBudgetHeaders.js +0 -89
- package/dist-es/rateLimits/helpers/processStreamRateLimitException.js +0 -59
- package/dist-es/rateLimits/helpers/processStreamRateLimitHeaders.js +0 -46
- package/dist-es/rateLimits/helpers/rateLimitSnapshot.js +0 -26
- package/dist-es/rateLimits/helpers/registerStreamBudgetInterceptors.js +0 -44
- package/dist-es/rateLimits/helpers/registerStreamInterceptors.js +0 -54
- package/dist-es/rateLimits/helpers/splitCallArgsAndOptions.js +0 -17
- package/dist-es/rateLimits/index.js +0 -4
- package/dist-es/rateLimits/types.js +0 -1
- package/dist-es/rateLimits/withStreamRateLimitOptions.js +0 -6
- package/dist-types/rateLimits/RedisCooldown.d.ts +0 -7
- package/dist-types/rateLimits/constants.d.ts +0 -29
- package/dist-types/rateLimits/createRateLimitedStreamProxy.d.ts +0 -11
- package/dist-types/rateLimits/exception/createRateLimitExceededException.d.ts +0 -12
- package/dist-types/rateLimits/exception/processStreamRateLimitException.d.ts +0 -8
- package/dist-types/rateLimits/executeStreamRequestWithRateLimitHandling.d.ts +0 -8
- package/dist-types/rateLimits/generatedMethodNames.d.ts +0 -11
- package/dist-types/rateLimits/helpers/RedisCooldown.d.ts +0 -11
- package/dist-types/rateLimits/helpers/createRateLimitExceededException.d.ts +0 -10
- package/dist-types/rateLimits/helpers/executeWithRateLimitHandling.d.ts +0 -2
- package/dist-types/rateLimits/helpers/headerUtils.d.ts +0 -4
- package/dist-types/rateLimits/helpers/isStreamChannelLike.d.ts +0 -6
- package/dist-types/rateLimits/helpers/processStreamBudgetHeaders.d.ts +0 -9
- package/dist-types/rateLimits/helpers/processStreamRateLimitException.d.ts +0 -3
- package/dist-types/rateLimits/helpers/processStreamRateLimitHeaders.d.ts +0 -6
- package/dist-types/rateLimits/helpers/rateLimitSnapshot.d.ts +0 -3
- package/dist-types/rateLimits/helpers/registerStreamBudgetInterceptors.d.ts +0 -2
- package/dist-types/rateLimits/helpers/registerStreamInterceptors.d.ts +0 -2
- package/dist-types/rateLimits/helpers/splitCallArgsAndOptions.d.ts +0 -6
- package/dist-types/rateLimits/index.d.ts +0 -4
- package/dist-types/rateLimits/types.d.ts +0 -68
- package/dist-types/rateLimits/withStreamRateLimitOptions.d.ts +0 -6
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is auto-generated by `scripts/generateRateLimitMethodNames.mjs`.
|
|
3
|
-
* Do not edit manually.
|
|
4
|
-
*/
|
|
5
|
-
export declare const STREAM_METHOD_NAMES: readonly ["_addChannelConfig", "_buildWSPayload", "_callClientListeners", "_createImport", "_createImportURL", "_deleteUserMessageReference", "_enrichAxiosOptions", "_getConnectionID", "_getImport", "_getToken", "_handleClientEvent", "_handleUserEvent", "_hasConnectionID", "_isUsingServerAuth", "_listImports", "_logApiError", "_logApiRequest", "_logApiResponse", "_muteStatus", "_normalizeDate", "_normalizeExpiration", "_queryFlagReports", "_queryFlags", "_reviewFlagReport", "_sayHi", "_setToken", "_setupConnection", "_setUser", "_startCleaning", "_unblockMessage", "_updateMemberWatcherReferences", "_updateUserMessageReferences", "_updateUserReferences", "_validateAndGetMessageId", "addDevice", "banUser", "channel", "closeConnection", "commitMessage", "connect", "connectAnonymousUser", "connectUser", "createAbortControllerForNextRequest", "createBlockList", "createCampaign", "createChannelType", "createCommand", "createPermission", "createRole", "createSegment", "createToken", "deactivateUser", "deactivateUsers", "delete", "deleteBlockList", "deleteCampaign", "deleteChannels", "deleteChannelType", "deleteCommand", "deleteMessage", "deletePermission", "deletePushProvider", "deleteRole", "deleteSegment", "deleteUser", "deleteUsers", "devToken", "disconnect", "disconnectUser", "dispatchEvent", "doAxiosRequest", "enrichURL", "errorFromResponse", "exportChannel", "exportChannels", "exportUser", "exportUsers", "flagMessage", "flagUser", "get", "getAppSettings", "getAuthType", "getBlockList", "getCallToken", "getChannelById", "getChannelByMembers", "getChannelType", "getCommand", "getDevices", "getExportChannelStatus", "getMessage", "getPermission", "getRateLimits", "getTask", "getUnreadCount", "getUserAgent", "handleEvent", "handleResponse", "hydrateActiveChannels", "listBlockLists", "listChannelTypes", "listCommands", "listPermissions", "listPushProviders", "listRoles", "markAllRead", "markChannelsRead", "muteUser", "off", "on", "openConnection", "partialUpdateMessage", "partialUpdateUser", "partialUpdateUsers", "patch", "pinMessage", "post", "put", "queryBannedUsers", "queryCampaigns", "queryChannels", "queryMessageFlags", "queryRecipients", "querySegments", "queryUsers", "reactivateUser", "reactivateUsers", "recoverState", "removeDevice", "removeShadowBan", "restoreUsers", "resumeCampaign", "revokeTokens", "revokeUsersToken", "revokeUserToken", "scheduleCampaign", "search", "sendFile", "sendUserCustomEvent", "setAnonymousUser", "setBaseURL", "setGuestUser", "setLocalDevice", "setUser", "setUserAgent", "shadowBan", "stopCampaign", "sync", "testCampaign", "testPushSettings", "testSQSSettings", "translateMessage", "unbanUser", "unblockMessage", "unflagMessage", "unflagUser", "unmuteUser", "unpinMessage", "updateAppSettings", "updateBlockList", "updateCampaign", "updateChannelType", "updateCommand", "updateMessage", "updatePermission", "updateSegment", "updateUser", "updateUsers", "upsertPushProvider", "upsertUser", "upsertUsers", "userMuteStatus", "verifyWebhook"];
|
|
6
|
-
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"];
|
|
7
|
-
export declare const STREAM_CHANNEL_RESULT_METHOD_NAMES: readonly ["channel", "getChannelById", "getChannelByMembers", "hydrateActiveChannels", "queryChannels"];
|
|
8
|
-
export declare const STREAM_SYNC_CHANNEL_RESULT_METHOD_NAMES: readonly ["channel", "getChannelById", "getChannelByMembers", "hydrateActiveChannels"];
|
|
9
|
-
export declare const CHANNEL_METHOD_NAMES: readonly ["_callChannelListeners", "_channelURL", "_checkInitialized", "_countMessageAsUnread", "_disconnect", "_extendEventWithOwnReactions", "_handleChannelEvent", "_initializeState", "_update", "acceptInvite", "addMembers", "addModerators", "assignRoles", "banUser", "clean", "countUnread", "countUnreadMentions", "create", "createCall", "delete", "deleteFile", "deleteImage", "deleteReaction", "demoteModerators", "disableSlowMode", "enableSlowMode", "getClient", "getConfig", "getMessagesById", "getPinnedMessages", "getReactions", "getReplies", "hide", "inviteMembers", "keystroke", "lastMessage", "lastRead", "markRead", "markUnread", "mute", "muteStatus", "off", "on", "query", "queryMembers", "rejectInvite", "removeMembers", "removeShadowBan", "search", "sendAction", "sendEvent", "sendFile", "sendImage", "sendMessage", "sendReaction", "shadowBan", "show", "stopTyping", "stopWatching", "truncate", "unbanUser", "unmute", "update", "updatePartial", "watch"];
|
|
10
|
-
export declare const CHANNEL_SYNC_METHOD_NAMES: readonly ["_callChannelListeners", "_channelURL", "_checkInitialized", "_countMessageAsUnread", "_disconnect", "_extendEventWithOwnReactions", "_handleChannelEvent", "_initializeState", "clean", "countUnread", "countUnreadMentions", "getConfig", "lastMessage", "lastRead", "muteStatus", "off", "on"];
|
|
11
|
-
export declare const CHANNEL_SYNC_PROXY_RESULT_METHOD_NAMES: readonly ["getClient"];
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { LoggerContext, RedisContext, RedisCooldownOptions } from '../types';
|
|
2
|
-
export declare class RedisCooldown {
|
|
3
|
-
private static resolveRedisKey;
|
|
4
|
-
static getRemainingMs(cooldownKey: string, context: RedisContext & LoggerContext, options?: RedisCooldownOptions): Promise<number>;
|
|
5
|
-
static setRemainingMs(cooldownKey: string, cooldownMs: number, context: RedisContext & LoggerContext, options?: RedisCooldownOptions): Promise<void>;
|
|
6
|
-
static setRemainingMsExact(cooldownKey: string, cooldownMs: number, context: RedisContext & LoggerContext, options?: RedisCooldownOptions): Promise<void>;
|
|
7
|
-
static getValue(cooldownKey: string, context: RedisContext & LoggerContext, options?: RedisCooldownOptions): Promise<string | undefined>;
|
|
8
|
-
static setValueWithRemainingMs(cooldownKey: string, value: string, cooldownMs: number, context: RedisContext & LoggerContext, options?: RedisCooldownOptions): Promise<void>;
|
|
9
|
-
static setRemainingMsWithValue(cooldownKey: string, valueKey: string, value: string, cooldownMs: number, context: RedisContext & LoggerContext, options?: RedisCooldownOptions): Promise<void>;
|
|
10
|
-
static clear(cooldownKey: string, context: RedisContext & LoggerContext, options?: RedisCooldownOptions): Promise<void>;
|
|
11
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { RateLimitExceededException } from '@wildix/xbees-conversations-client';
|
|
2
|
-
import { RateLimitsInfo } from 'stream-chat';
|
|
3
|
-
type Options = {
|
|
4
|
-
rateLimit?: RateLimitsInfo;
|
|
5
|
-
message?: string;
|
|
6
|
-
operation?: string;
|
|
7
|
-
retryAfterMs?: number;
|
|
8
|
-
};
|
|
9
|
-
export declare function createRateLimitExceededException(options?: Options): RateLimitExceededException;
|
|
10
|
-
export {};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { LoggerContext, RedisContext, StreamOperationType, StreamRateLimitRetryOptions } from '../types';
|
|
2
|
-
export declare function executeWithRateLimitHandling<T>(execute: () => Promise<T>, operation: StreamOperationType, context: LoggerContext & RedisContext, options: StreamRateLimitRetryOptions): Promise<T>;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { StreamHeaders } from '../types';
|
|
2
|
-
export declare function getHeaderCaseInsensitive(headers: StreamHeaders | Record<string, unknown> | undefined, key: string): unknown;
|
|
3
|
-
export declare function parseHeaderNumber(headers: StreamHeaders | Record<string, unknown>, key: string): number | undefined;
|
|
4
|
-
export declare function normalizeResetToEpochMs(reset: number): number;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { LoggerContext, RedisContext, StreamHeaders } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Updates app-wide Stream budget cooldown in Redis based on x-budget-* headers.
|
|
4
|
-
* - If budget usage reaches the threshold (>=80%), enables cooldown for 30-60s.
|
|
5
|
-
* - If usage is between 60% and 80%, keeps a shorter cooldown.
|
|
6
|
-
* - If usage drops below 60%, clears cooldown.
|
|
7
|
-
* - If headers are missing/invalid, leaves current cooldown unchanged.
|
|
8
|
-
*/
|
|
9
|
-
export declare function processStreamBudgetHeaders(headers: StreamHeaders | undefined, context: LoggerContext & RedisContext): Promise<void>;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { LoggerContext, RedisContext, StreamHeaders } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Applies soft global throttle from x-ratelimit-* headers to smooth bursts
|
|
4
|
-
* before hard 429 throttling starts.
|
|
5
|
-
*/
|
|
6
|
-
export declare function processStreamRateLimitHeaders(headers: StreamHeaders | undefined, context: LoggerContext & RedisContext): Promise<void>;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { ArgsAndOptions } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Splits original call args and optional rate-limit options token.
|
|
4
|
-
* If no token is provided, options fallback to an empty object.
|
|
5
|
-
*/
|
|
6
|
-
export declare function splitCallArgsAndOptions(args: unknown[]): ArgsAndOptions;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import Redis from 'ioredis';
|
|
2
|
-
import { StreamChat } from 'stream-chat';
|
|
3
|
-
import { StreamChannel, StreamType } from '../stream';
|
|
4
|
-
import { STREAM_RATE_LIMIT_OPTIONS_MARKER } from './constants';
|
|
5
|
-
import { Logger } from '@aws-lambda-powertools/logger';
|
|
6
|
-
export type StreamOperationType = keyof StreamChat<StreamType> | keyof StreamChannel;
|
|
7
|
-
export interface StreamRateLimitRetryOptions {
|
|
8
|
-
enableCooldown: boolean;
|
|
9
|
-
maxAttempts: number;
|
|
10
|
-
maxDelayMs: number;
|
|
11
|
-
maxRetryableDelayMs: number;
|
|
12
|
-
}
|
|
13
|
-
export type StreamRateLimitOptionsToken = {
|
|
14
|
-
[STREAM_RATE_LIMIT_OPTIONS_MARKER]: Partial<StreamRateLimitRetryOptions>;
|
|
15
|
-
};
|
|
16
|
-
export type MethodWithRateLimitOptions<T> = T extends (...args: infer Args) => infer Result ? T & ((...args: [...Args, StreamRateLimitOptionsToken?]) => Result) : T;
|
|
17
|
-
export type RedisContext = {
|
|
18
|
-
redis: Redis;
|
|
19
|
-
};
|
|
20
|
-
export type LoggerContext = {
|
|
21
|
-
logger: Logger;
|
|
22
|
-
};
|
|
23
|
-
export type ArgsAndOptions = {
|
|
24
|
-
callArgs: unknown[];
|
|
25
|
-
callOptions: Partial<StreamRateLimitRetryOptions>;
|
|
26
|
-
};
|
|
27
|
-
/** Optional Redis key namespace override for cooldown records. */
|
|
28
|
-
export type RedisCooldownOptions = {
|
|
29
|
-
keyPrefix?: string;
|
|
30
|
-
};
|
|
31
|
-
/** Generic HTTP headers shape returned by the Stream SDK transport layer. */
|
|
32
|
-
export type StreamHeaders = Record<string, unknown>;
|
|
33
|
-
/** Parsed GetStream budget headers used to manage app-wide cooldown. */
|
|
34
|
-
export type StreamBudgetHeaders = {
|
|
35
|
-
limitMs?: number;
|
|
36
|
-
remainingMs?: number;
|
|
37
|
-
usedMs?: number;
|
|
38
|
-
};
|
|
39
|
-
export type StreamRateLimitSnapshot = {
|
|
40
|
-
limit: number;
|
|
41
|
-
remaining: number;
|
|
42
|
-
reset: number;
|
|
43
|
-
};
|
|
44
|
-
/** Axios response shape used by budget interceptor. */
|
|
45
|
-
export type StreamBudgetInterceptorResponse = {
|
|
46
|
-
headers?: StreamHeaders;
|
|
47
|
-
};
|
|
48
|
-
/** Axios error shape used by budget interceptor. */
|
|
49
|
-
export type StreamBudgetInterceptorError = {
|
|
50
|
-
response?: StreamBudgetInterceptorResponse;
|
|
51
|
-
};
|
|
52
|
-
/** Minimal axios response interceptor manager contract required by this package. */
|
|
53
|
-
export type AxiosResponseInterceptorManagerLike = {
|
|
54
|
-
use: (onFulfilled?: (response: StreamBudgetInterceptorResponse) => unknown | Promise<unknown>, onRejected?: (error: StreamBudgetInterceptorError) => unknown | Promise<unknown>) => unknown;
|
|
55
|
-
};
|
|
56
|
-
/** Minimal axios instance contract required to register budget interceptors. */
|
|
57
|
-
export type AxiosLikeWithResponseInterceptors = {
|
|
58
|
-
interceptors?: {
|
|
59
|
-
response?: AxiosResponseInterceptorManagerLike;
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
/** Stream client variants where axios transport can be discovered. */
|
|
63
|
-
export type StreamClientWithAxiosCandidates = {
|
|
64
|
-
axiosInstance?: unknown;
|
|
65
|
-
_client?: {
|
|
66
|
-
axiosInstance?: unknown;
|
|
67
|
-
};
|
|
68
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { StreamRateLimitOptionsToken, StreamRateLimitRetryOptions } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Creates a marker token that can be passed as the last argument to proxied Stream methods.
|
|
4
|
-
* The proxy strips this token from original method args and uses it as per-call retry options.
|
|
5
|
-
*/
|
|
6
|
-
export declare function withStreamRateLimitOptions(options: Partial<StreamRateLimitRetryOptions>): StreamRateLimitOptionsToken;
|