@wildix/xbees-conversations-utils 4.0.2 → 4.1.0

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.
Files changed (128) hide show
  1. package/dist-cjs/anonymousEmail/index.js +3 -3
  2. package/dist-cjs/normalization.js +6 -0
  3. package/dist-es/anonymousEmail/index.js +1 -1
  4. package/dist-es/normalization.js +6 -0
  5. package/dist-types/anonymousEmail/index.d.ts +0 -1
  6. package/dist-types/normalization.d.ts +25 -0
  7. package/dist-types/stream.d.ts +7 -1
  8. package/package.json +3 -3
  9. package/dist-cjs/rateLimits/RedisCooldown.js +0 -66
  10. package/dist-cjs/rateLimits/constants.js +0 -43
  11. package/dist-cjs/rateLimits/createRateLimitedStreamProxy.js +0 -92
  12. package/dist-cjs/rateLimits/exception/createRateLimitExceededException.js +0 -21
  13. package/dist-cjs/rateLimits/exception/processStreamRateLimitException.js +0 -47
  14. package/dist-cjs/rateLimits/executeStreamRequestWithRateLimitHandling.js +0 -94
  15. package/dist-cjs/rateLimits/generatedMethodNames.js +0 -320
  16. package/dist-cjs/rateLimits/helpers/RedisCooldown.js +0 -174
  17. package/dist-cjs/rateLimits/helpers/createRateLimitExceededException.js +0 -32
  18. package/dist-cjs/rateLimits/helpers/executeWithRateLimitHandling.js +0 -144
  19. package/dist-cjs/rateLimits/helpers/headerUtils.js +0 -40
  20. package/dist-cjs/rateLimits/helpers/isStreamChannelLike.js +0 -23
  21. package/dist-cjs/rateLimits/helpers/processStreamBudgetHeaders.js +0 -93
  22. package/dist-cjs/rateLimits/helpers/processStreamRateLimitException.js +0 -63
  23. package/dist-cjs/rateLimits/helpers/processStreamRateLimitHeaders.js +0 -50
  24. package/dist-cjs/rateLimits/helpers/rateLimitSnapshot.js +0 -31
  25. package/dist-cjs/rateLimits/helpers/registerStreamBudgetInterceptors.js +0 -48
  26. package/dist-cjs/rateLimits/helpers/registerStreamInterceptors.js +0 -58
  27. package/dist-cjs/rateLimits/helpers/splitCallArgsAndOptions.js +0 -21
  28. package/dist-cjs/rateLimits/index.js +0 -7
  29. package/dist-cjs/rateLimits/types.js +0 -3
  30. package/dist-cjs/rateLimits/withStreamRateLimitOptions.js +0 -10
  31. package/dist-cjs/streamRateLimitHandlingProxy/constants.js +0 -42
  32. package/dist-cjs/streamRateLimitHandlingProxy/createRateLimitedStreamProxy.js +0 -92
  33. package/dist-cjs/streamRateLimitHandlingProxy/generatedMethodNames.js +0 -320
  34. package/dist-cjs/streamRateLimitHandlingProxy/helpers/RedisCooldown.js +0 -174
  35. package/dist-cjs/streamRateLimitHandlingProxy/helpers/createRateLimitExceededException.js +0 -29
  36. package/dist-cjs/streamRateLimitHandlingProxy/helpers/executeWithRateLimitHandling.js +0 -153
  37. package/dist-cjs/streamRateLimitHandlingProxy/helpers/headerUtils.js +0 -48
  38. package/dist-cjs/streamRateLimitHandlingProxy/helpers/isStreamChannelLike.js +0 -23
  39. package/dist-cjs/streamRateLimitHandlingProxy/helpers/processStreamBudgetHeaders.js +0 -93
  40. package/dist-cjs/streamRateLimitHandlingProxy/helpers/processStreamRateLimitException.js +0 -63
  41. package/dist-cjs/streamRateLimitHandlingProxy/helpers/processStreamRateLimitHeaders.js +0 -46
  42. package/dist-cjs/streamRateLimitHandlingProxy/helpers/rateLimitSnapshot.js +0 -31
  43. package/dist-cjs/streamRateLimitHandlingProxy/helpers/registerStreamInterceptors.js +0 -64
  44. package/dist-cjs/streamRateLimitHandlingProxy/helpers/sleep.js +0 -6
  45. package/dist-cjs/streamRateLimitHandlingProxy/helpers/splitCallArgsAndOptions.js +0 -21
  46. package/dist-cjs/streamRateLimitHandlingProxy/index.js +0 -5
  47. package/dist-cjs/streamRateLimitHandlingProxy/types.js +0 -3
  48. package/dist-cjs/streamRateLimitHandlingProxy/withStreamRateLimitOptions.js +0 -10
  49. package/dist-es/rateLimits/RedisCooldown.js +0 -62
  50. package/dist-es/rateLimits/constants.js +0 -33
  51. package/dist-es/rateLimits/createRateLimitedStreamProxy.js +0 -88
  52. package/dist-es/rateLimits/exception/createRateLimitExceededException.js +0 -17
  53. package/dist-es/rateLimits/exception/processStreamRateLimitException.js +0 -37
  54. package/dist-es/rateLimits/executeStreamRequestWithRateLimitHandling.js +0 -93
  55. package/dist-es/rateLimits/generatedMethodNames.js +0 -317
  56. package/dist-es/rateLimits/helpers/RedisCooldown.js +0 -170
  57. package/dist-es/rateLimits/helpers/createRateLimitExceededException.js +0 -28
  58. package/dist-es/rateLimits/helpers/executeWithRateLimitHandling.js +0 -140
  59. package/dist-es/rateLimits/helpers/headerUtils.js +0 -34
  60. package/dist-es/rateLimits/helpers/isStreamChannelLike.js +0 -19
  61. package/dist-es/rateLimits/helpers/processStreamBudgetHeaders.js +0 -89
  62. package/dist-es/rateLimits/helpers/processStreamRateLimitException.js +0 -59
  63. package/dist-es/rateLimits/helpers/processStreamRateLimitHeaders.js +0 -46
  64. package/dist-es/rateLimits/helpers/rateLimitSnapshot.js +0 -26
  65. package/dist-es/rateLimits/helpers/registerStreamBudgetInterceptors.js +0 -44
  66. package/dist-es/rateLimits/helpers/registerStreamInterceptors.js +0 -54
  67. package/dist-es/rateLimits/helpers/splitCallArgsAndOptions.js +0 -17
  68. package/dist-es/rateLimits/index.js +0 -4
  69. package/dist-es/rateLimits/types.js +0 -1
  70. package/dist-es/rateLimits/withStreamRateLimitOptions.js +0 -6
  71. package/dist-es/streamRateLimitHandlingProxy/constants.js +0 -32
  72. package/dist-es/streamRateLimitHandlingProxy/createRateLimitedStreamProxy.js +0 -88
  73. package/dist-es/streamRateLimitHandlingProxy/generatedMethodNames.js +0 -317
  74. package/dist-es/streamRateLimitHandlingProxy/helpers/RedisCooldown.js +0 -170
  75. package/dist-es/streamRateLimitHandlingProxy/helpers/createRateLimitExceededException.js +0 -25
  76. package/dist-es/streamRateLimitHandlingProxy/helpers/executeWithRateLimitHandling.js +0 -148
  77. package/dist-es/streamRateLimitHandlingProxy/helpers/headerUtils.js +0 -42
  78. package/dist-es/streamRateLimitHandlingProxy/helpers/isStreamChannelLike.js +0 -19
  79. package/dist-es/streamRateLimitHandlingProxy/helpers/processStreamBudgetHeaders.js +0 -89
  80. package/dist-es/streamRateLimitHandlingProxy/helpers/processStreamRateLimitException.js +0 -59
  81. package/dist-es/streamRateLimitHandlingProxy/helpers/processStreamRateLimitHeaders.js +0 -42
  82. package/dist-es/streamRateLimitHandlingProxy/helpers/rateLimitSnapshot.js +0 -26
  83. package/dist-es/streamRateLimitHandlingProxy/helpers/registerStreamInterceptors.js +0 -60
  84. package/dist-es/streamRateLimitHandlingProxy/helpers/sleep.js +0 -4
  85. package/dist-es/streamRateLimitHandlingProxy/helpers/splitCallArgsAndOptions.js +0 -17
  86. package/dist-es/streamRateLimitHandlingProxy/index.js +0 -2
  87. package/dist-es/streamRateLimitHandlingProxy/types.js +0 -1
  88. package/dist-es/streamRateLimitHandlingProxy/withStreamRateLimitOptions.js +0 -6
  89. package/dist-types/rateLimits/RedisCooldown.d.ts +0 -7
  90. package/dist-types/rateLimits/constants.d.ts +0 -29
  91. package/dist-types/rateLimits/createRateLimitedStreamProxy.d.ts +0 -11
  92. package/dist-types/rateLimits/exception/createRateLimitExceededException.d.ts +0 -12
  93. package/dist-types/rateLimits/exception/processStreamRateLimitException.d.ts +0 -8
  94. package/dist-types/rateLimits/executeStreamRequestWithRateLimitHandling.d.ts +0 -8
  95. package/dist-types/rateLimits/generatedMethodNames.d.ts +0 -11
  96. package/dist-types/rateLimits/helpers/RedisCooldown.d.ts +0 -11
  97. package/dist-types/rateLimits/helpers/createRateLimitExceededException.d.ts +0 -10
  98. package/dist-types/rateLimits/helpers/executeWithRateLimitHandling.d.ts +0 -2
  99. package/dist-types/rateLimits/helpers/headerUtils.d.ts +0 -4
  100. package/dist-types/rateLimits/helpers/isStreamChannelLike.d.ts +0 -6
  101. package/dist-types/rateLimits/helpers/processStreamBudgetHeaders.d.ts +0 -9
  102. package/dist-types/rateLimits/helpers/processStreamRateLimitException.d.ts +0 -3
  103. package/dist-types/rateLimits/helpers/processStreamRateLimitHeaders.d.ts +0 -6
  104. package/dist-types/rateLimits/helpers/rateLimitSnapshot.d.ts +0 -3
  105. package/dist-types/rateLimits/helpers/registerStreamBudgetInterceptors.d.ts +0 -2
  106. package/dist-types/rateLimits/helpers/registerStreamInterceptors.d.ts +0 -2
  107. package/dist-types/rateLimits/helpers/splitCallArgsAndOptions.d.ts +0 -6
  108. package/dist-types/rateLimits/index.d.ts +0 -4
  109. package/dist-types/rateLimits/types.d.ts +0 -68
  110. package/dist-types/rateLimits/withStreamRateLimitOptions.d.ts +0 -6
  111. package/dist-types/streamRateLimitHandlingProxy/constants.d.ts +0 -28
  112. package/dist-types/streamRateLimitHandlingProxy/createRateLimitedStreamProxy.d.ts +0 -11
  113. package/dist-types/streamRateLimitHandlingProxy/generatedMethodNames.d.ts +0 -11
  114. package/dist-types/streamRateLimitHandlingProxy/helpers/RedisCooldown.d.ts +0 -11
  115. package/dist-types/streamRateLimitHandlingProxy/helpers/createRateLimitExceededException.d.ts +0 -10
  116. package/dist-types/streamRateLimitHandlingProxy/helpers/executeWithRateLimitHandling.d.ts +0 -2
  117. package/dist-types/streamRateLimitHandlingProxy/helpers/headerUtils.d.ts +0 -4
  118. package/dist-types/streamRateLimitHandlingProxy/helpers/isStreamChannelLike.d.ts +0 -6
  119. package/dist-types/streamRateLimitHandlingProxy/helpers/processStreamBudgetHeaders.d.ts +0 -9
  120. package/dist-types/streamRateLimitHandlingProxy/helpers/processStreamRateLimitException.d.ts +0 -3
  121. package/dist-types/streamRateLimitHandlingProxy/helpers/processStreamRateLimitHeaders.d.ts +0 -6
  122. package/dist-types/streamRateLimitHandlingProxy/helpers/rateLimitSnapshot.d.ts +0 -3
  123. package/dist-types/streamRateLimitHandlingProxy/helpers/registerStreamInterceptors.d.ts +0 -2
  124. package/dist-types/streamRateLimitHandlingProxy/helpers/sleep.d.ts +0 -2
  125. package/dist-types/streamRateLimitHandlingProxy/helpers/splitCallArgsAndOptions.d.ts +0 -6
  126. package/dist-types/streamRateLimitHandlingProxy/index.d.ts +0 -2
  127. package/dist-types/streamRateLimitHandlingProxy/types.d.ts +0 -68
  128. package/dist-types/streamRateLimitHandlingProxy/withStreamRateLimitOptions.d.ts +0 -6
@@ -1,28 +0,0 @@
1
- import { StreamRateLimitRetryOptions } from './types';
2
- export { CHANNEL_METHOD_NAMES, CHANNEL_SYNC_METHOD_NAMES, CHANNEL_SYNC_PROXY_RESULT_METHOD_NAMES, STREAM_CHANNEL_RESULT_METHOD_NAMES, STREAM_METHOD_NAMES, STREAM_SYNC_CHANNEL_RESULT_METHOD_NAMES, STREAM_SYNC_METHOD_NAMES, } from './generatedMethodNames';
3
- export declare const DEFAULT_RETRY_AFTER_MS = 10000;
4
- export declare const DEFAULT_JITTER_MS = 150;
5
- export declare const RETRY_AFTER_BUFFER_MS = 1000;
6
- export declare const STREAM_RATE_LIMIT_COOLDOWN_KEY_PREFIX = "stream-rate-limit-cooldown:";
7
- export declare const STREAM_BUDGET_COOLDOWN_KEY_PREFIX = "stream-budget-cooldown:";
8
- export declare const STREAM_RATE_LIMIT_OPTIONS_MARKER = "__xbsRateLimitOptions";
9
- export declare const STREAM_RATE_LIMIT_SOFT_COOLDOWN_KEY = "stream-rate-limit-soft-global";
10
- export declare const STREAM_RATE_LIMIT_METADATA_KEY_SUFFIX = ":meta";
11
- export declare const STREAM_BUDGET_COOLDOWN_KEY = "stream-budget-global";
12
- export declare const BUDGET_THRESHOLD = 0.8;
13
- export declare const BUDGET_DELAY_MIN_MS = 30000;
14
- export declare const BUDGET_DELAY_MAX_MS = 60000;
15
- export declare const BUDGET_CLEAR_USAGE_THRESHOLD = 0.6;
16
- export declare const BUDGET_RELAXED_USAGE_THRESHOLD = 0.7;
17
- export declare const BUDGET_RELAXED_DELAY_MIN_MS = 5000;
18
- export declare const BUDGET_RELAXED_DELAY_MAX_MS = 10000;
19
- export declare const BUDGET_MINIMAL_DELAY_MIN_MS = 1000;
20
- export declare const BUDGET_MINIMAL_DELAY_MAX_MS = 2000;
21
- export declare const BUDGET_COOLDOWN_SLEEP_CHUNK_MS = 3000;
22
- export declare const SOFT_THROTTLE_USAGE_LOW = 0.7;
23
- export declare const SOFT_THROTTLE_USAGE_MEDIUM = 0.85;
24
- export declare const SOFT_THROTTLE_USAGE_HIGH = 0.95;
25
- export declare const SOFT_THROTTLE_DELAY_LOW_MS = 500;
26
- export declare const SOFT_THROTTLE_DELAY_MEDIUM_MS = 1500;
27
- export declare const SOFT_THROTTLE_DELAY_HIGH_MS = 3000;
28
- export declare const DEFAULT_OPTIONS: StreamRateLimitRetryOptions;
@@ -1,11 +0,0 @@
1
- import { StreamChat } from 'stream-chat';
2
- import { StreamType } from '../stream';
3
- import { LoggerContext, MethodWithRateLimitOptions, RedisContext } from './types';
4
- export type RateLimited<T extends object> = {
5
- [Key in keyof T]: MethodWithRateLimitOptions<T[Key]>;
6
- };
7
- /**
8
- * Creates a proxy around a Stream client that transparently applies rate-limit handling
9
- * to method calls and recursively wraps returned channel objects with the same behavior.
10
- */
11
- export declare function createRateLimitedStreamProxy(stream: StreamChat<StreamType>, context: LoggerContext & RedisContext): RateLimited<StreamChat<StreamType>>;
@@ -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,6 +0,0 @@
1
- /**
2
- * Detects Stream channel-like objects.
3
- * These objects should be correctly wrapped to keep rate-limit behavior
4
- * on methods returned from other proxied calls.
5
- */
6
- export declare function isStreamChannelLike(value: unknown): value is object;
@@ -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,3 +0,0 @@
1
- import { RateLimitExceededException } from '@wildix/xbees-conversations-client';
2
- import { Logger } from '@aws-lambda-powertools/logger';
3
- export declare function processStreamRateLimitException(error: unknown, logger: Logger): RateLimitExceededException | undefined;
@@ -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,3 +0,0 @@
1
- import { StreamRateLimitSnapshot } from '../types';
2
- export declare function serializeRateLimitSnapshot(snapshot: StreamRateLimitSnapshot): string;
3
- export declare function parseRateLimitSnapshot(snapshot: string | null | undefined): StreamRateLimitSnapshot | undefined;
@@ -1,2 +0,0 @@
1
- import { LoggerContext, RedisContext } from '../types';
2
- export declare function registerStreamInterceptors(stream: unknown, context: LoggerContext & RedisContext): void;
@@ -1,2 +0,0 @@
1
- declare function sleep(ms: number): Promise<unknown>;
2
- export default sleep;
@@ -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,2 +0,0 @@
1
- export * from './createRateLimitedStreamProxy';
2
- export * from './withStreamRateLimitOptions';
@@ -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;