@wildix/xbees-conversations-utils 1.1.63 → 1.1.65

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,15 +1,15 @@
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.DEFAULT_RETRY_AFTER_MS = exports.RETRY_AFTER_BUFFER_MS = exports.DEFAULT_JITTER_MS = exports.DEFAULT_FIXED_RATE_LIMIT_DELAY_MS = void 0;
4
- exports.DEFAULT_FIXED_RATE_LIMIT_DELAY_MS = 15000;
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;
4
+ exports.DEFAULT_MAX_DELAY_MS = 5000;
5
+ exports.DEFAULT_RETRY_AFTER_MS = 10000;
5
6
  exports.DEFAULT_JITTER_MS = 150;
6
7
  exports.RETRY_AFTER_BUFFER_MS = 1000;
7
- exports.DEFAULT_RETRY_AFTER_MS = 10000;
8
8
  exports.STREAM_RATE_LIMIT_COOLDOWN_KEY_PREFIX = 'stream-rate-limit-cooldown:';
9
9
  exports.STREAM_RATE_LIMIT_OPTIONS_MARKER = '__xbsRateLimitOptions';
10
10
  exports.DEFAULT_OPTIONS = {
11
11
  maxAttempts: 3,
12
12
  enableCooldown: true,
13
- maxDelayMs: 15000,
14
- maxRetryableDelayMs: 5000,
13
+ maxDelayMs: exports.DEFAULT_MAX_DELAY_MS,
14
+ maxRetryableDelayMs: 10000,
15
15
  };
@@ -17,7 +17,7 @@ function calculateRateLimitDelayMs(error, maxDelayMs) {
17
17
  }
18
18
  return Math.min(maxDelayMs, computedDelayMs);
19
19
  }
20
- return Math.min(maxDelayMs, constants_1.DEFAULT_FIXED_RATE_LIMIT_DELAY_MS);
20
+ return Math.min(maxDelayMs, constants_1.DEFAULT_MAX_DELAY_MS);
21
21
  }
22
22
  async function executeWithRateLimitHandling(execute, operation, context, options) {
23
23
  const { logger, redis } = context;
@@ -1,12 +1,12 @@
1
- export const DEFAULT_FIXED_RATE_LIMIT_DELAY_MS = 15000;
1
+ export const DEFAULT_MAX_DELAY_MS = 5000;
2
+ export const DEFAULT_RETRY_AFTER_MS = 10000;
2
3
  export const DEFAULT_JITTER_MS = 150;
3
4
  export const RETRY_AFTER_BUFFER_MS = 1000;
4
- export const DEFAULT_RETRY_AFTER_MS = 10000;
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
7
  export const DEFAULT_OPTIONS = {
8
8
  maxAttempts: 3,
9
9
  enableCooldown: true,
10
- maxDelayMs: 15000,
11
- maxRetryableDelayMs: 5000,
10
+ maxDelayMs: DEFAULT_MAX_DELAY_MS,
11
+ maxRetryableDelayMs: 10000,
12
12
  };
@@ -1,5 +1,5 @@
1
1
  import { setTimeout as sleep } from 'node:timers/promises';
2
- import { DEFAULT_FIXED_RATE_LIMIT_DELAY_MS, DEFAULT_JITTER_MS, DEFAULT_RETRY_AFTER_MS, RETRY_AFTER_BUFFER_MS, } from '../constants';
2
+ import { DEFAULT_MAX_DELAY_MS, DEFAULT_JITTER_MS, DEFAULT_RETRY_AFTER_MS, RETRY_AFTER_BUFFER_MS, } from '../constants';
3
3
  import { createRateLimitExceededException } from './createRateLimitExceededException';
4
4
  import { processStreamRateLimitException } from './processStreamRateLimitException';
5
5
  import { RedisCooldown } from './RedisCooldown';
@@ -14,7 +14,7 @@ function calculateRateLimitDelayMs(error, maxDelayMs) {
14
14
  }
15
15
  return Math.min(maxDelayMs, computedDelayMs);
16
16
  }
17
- return Math.min(maxDelayMs, DEFAULT_FIXED_RATE_LIMIT_DELAY_MS);
17
+ return Math.min(maxDelayMs, DEFAULT_MAX_DELAY_MS);
18
18
  }
19
19
  export async function executeWithRateLimitHandling(execute, operation, context, options) {
20
20
  const { logger, redis } = context;
@@ -1,8 +1,8 @@
1
1
  import { StreamRateLimitRetryOptions } from './types';
2
- export declare const DEFAULT_FIXED_RATE_LIMIT_DELAY_MS = 15000;
2
+ export declare const DEFAULT_MAX_DELAY_MS = 5000;
3
+ export declare const DEFAULT_RETRY_AFTER_MS = 10000;
3
4
  export declare const DEFAULT_JITTER_MS = 150;
4
5
  export declare const RETRY_AFTER_BUFFER_MS = 1000;
5
- export declare const DEFAULT_RETRY_AFTER_MS = 10000;
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
8
  export declare const DEFAULT_OPTIONS: StreamRateLimitRetryOptions;
@@ -1,6 +1,9 @@
1
1
  import { StreamChat } from 'stream-chat';
2
2
  import { StreamType } from '../stream';
3
- import { LoggerContext, RateLimited, RedisContext } from './types';
3
+ import { LoggerContext, MethodWithRateLimitOptions, RedisContext } from './types';
4
+ export type RateLimited<T extends object> = {
5
+ [Key in keyof T]: MethodWithRateLimitOptions<T[Key]>;
6
+ };
4
7
  /**
5
8
  * Creates a proxy around a Stream client that transparently applies rate-limit handling
6
9
  * to method calls and recursively wraps returned channel objects with the same behavior.
@@ -5,18 +5,15 @@ import { STREAM_RATE_LIMIT_OPTIONS_MARKER } from './constants';
5
5
  import { Logger } from '@aws-lambda-powertools/logger';
6
6
  export type StreamOperationType = keyof StreamChat<StreamType> | keyof StreamChannel;
7
7
  export interface StreamRateLimitRetryOptions {
8
+ enableCooldown: boolean;
8
9
  maxAttempts: number;
9
10
  maxDelayMs: number;
10
11
  maxRetryableDelayMs: number;
11
- enableCooldown: boolean;
12
12
  }
13
13
  export type StreamRateLimitOptionsToken = {
14
14
  [STREAM_RATE_LIMIT_OPTIONS_MARKER]: Partial<StreamRateLimitRetryOptions>;
15
15
  };
16
16
  export type MethodWithRateLimitOptions<T> = T extends (...args: infer Args) => infer Result ? T & ((...args: [...Args, StreamRateLimitOptionsToken?]) => Result) : T;
17
- export type RateLimited<T extends object> = {
18
- [Key in keyof T]: MethodWithRateLimitOptions<T[Key]>;
19
- };
20
17
  export type RedisContext = {
21
18
  redis: Redis;
22
19
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildix/xbees-conversations-utils",
3
- "version": "1.1.63",
3
+ "version": "1.1.65",
4
4
  "description": "",
5
5
  "main": "./dist-cjs/index.js",
6
6
  "module": "./dist-es/index.js",