@tramvai/tinkoff-request-http-client-adapter 0.8.259 → 0.8.263

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,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import type { ContextState, MakeRequest } from '@tinkoff/request-core';
2
+ import type { ContextState, MakeRequest, Request } from '@tinkoff/request-core';
3
3
  import type { Options as CircuitBreakerOptions } from '@tinkoff/request-plugin-circuit-breaker';
4
4
  import type { HttpClientBaseOptions } from '@tramvai/http-client';
5
5
  import type { LOGGER_TOKEN } from '@tramvai/tokens-common';
@@ -20,6 +20,11 @@ export interface TinkoffRequestOptions extends HttpClientBaseOptions {
20
20
  errorValidator?: RequestValidator;
21
21
  errorModificator?: RequestValidator;
22
22
  circuitBreakerOptions?: CircuitBreakerOptions;
23
+ getCacheKey?: (request: Request) => string;
24
+ lruOptions?: {
25
+ maxAge: number;
26
+ max: number;
27
+ };
23
28
  agent?: {
24
29
  http: Agent;
25
30
  https: Agent;
@@ -14,7 +14,7 @@ const createAgent = () => { };
14
14
 
15
15
  const defaultAgent = createAgent();
16
16
  function createTinkoffRequest(options) {
17
- const { logger, name, disableCache, enableCircuitBreaker, createCache, cacheTime = 30000, defaultTimeout, validator, errorValidator, errorModificator, circuitBreakerOptions = {}, agent, ...defaults } = options;
17
+ const { logger, name, disableCache, enableCircuitBreaker, createCache, cacheTime = 30000, defaultTimeout, validator, errorValidator, errorModificator, circuitBreakerOptions = {}, getCacheKey, lruOptions = { max: 1000, maxAge: cacheTime }, agent, ...defaults } = options;
18
18
  const log = logger && logger(`${name}:initialization`);
19
19
  const plugins = [];
20
20
  plugins.push({
@@ -65,11 +65,12 @@ function createTinkoffRequest(options) {
65
65
  }));
66
66
  plugins.push(memoryCache({
67
67
  shouldExecute: !disableCache,
68
- lruOptions: { max: 1000, maxAge: cacheTime },
68
+ lruOptions,
69
69
  allowStale: true,
70
+ getCacheKey,
70
71
  memoryConstructor: createCache,
71
72
  }));
72
- plugins.push(deduplicateCache());
73
+ plugins.push(deduplicateCache(getCacheKey ? { getCacheKey } : undefined));
73
74
  if (enableCircuitBreaker) {
74
75
  plugins.push(circuitBreaker({
75
76
  isSystemError: either(isServerError, isNetworkFail),
package/lib/index.es.js CHANGED
@@ -24,7 +24,7 @@ const createAgent = (options = {
24
24
 
25
25
  const defaultAgent = createAgent();
26
26
  function createTinkoffRequest(options) {
27
- const { logger, name, disableCache, enableCircuitBreaker, createCache, cacheTime = 30000, defaultTimeout, validator, errorValidator, errorModificator, circuitBreakerOptions = {}, agent, ...defaults } = options;
27
+ const { logger, name, disableCache, enableCircuitBreaker, createCache, cacheTime = 30000, defaultTimeout, validator, errorValidator, errorModificator, circuitBreakerOptions = {}, getCacheKey, lruOptions = { max: 1000, maxAge: cacheTime }, agent, ...defaults } = options;
28
28
  const log = logger && logger(`${name}:initialization`);
29
29
  const plugins = [];
30
30
  plugins.push({
@@ -75,11 +75,12 @@ function createTinkoffRequest(options) {
75
75
  }));
76
76
  plugins.push(memoryCache({
77
77
  shouldExecute: !disableCache,
78
- lruOptions: { max: 1000, maxAge: cacheTime },
78
+ lruOptions,
79
79
  allowStale: true,
80
+ getCacheKey,
80
81
  memoryConstructor: createCache,
81
82
  }));
82
- plugins.push(deduplicateCache());
83
+ plugins.push(deduplicateCache(getCacheKey ? { getCacheKey } : undefined));
83
84
  if (enableCircuitBreaker) {
84
85
  plugins.push(circuitBreaker({
85
86
  isSystemError: either(isServerError, isNetworkFail),
package/lib/index.js CHANGED
@@ -43,7 +43,7 @@ const createAgent = (options = {
43
43
 
44
44
  const defaultAgent = createAgent();
45
45
  function createTinkoffRequest(options) {
46
- const { logger, name, disableCache, enableCircuitBreaker, createCache, cacheTime = 30000, defaultTimeout, validator, errorValidator, errorModificator, circuitBreakerOptions = {}, agent, ...defaults } = options;
46
+ const { logger, name, disableCache, enableCircuitBreaker, createCache, cacheTime = 30000, defaultTimeout, validator, errorValidator, errorModificator, circuitBreakerOptions = {}, getCacheKey, lruOptions = { max: 1000, maxAge: cacheTime }, agent, ...defaults } = options;
47
47
  const log = logger && logger(`${name}:initialization`);
48
48
  const plugins = [];
49
49
  plugins.push({
@@ -94,11 +94,12 @@ function createTinkoffRequest(options) {
94
94
  }));
95
95
  plugins.push(memoryCache__default["default"]({
96
96
  shouldExecute: !disableCache,
97
- lruOptions: { max: 1000, maxAge: cacheTime },
97
+ lruOptions,
98
98
  allowStale: true,
99
+ getCacheKey,
99
100
  memoryConstructor: createCache,
100
101
  }));
101
- plugins.push(deduplicateCache__default["default"]());
102
+ plugins.push(deduplicateCache__default["default"](getCacheKey ? { getCacheKey } : undefined));
102
103
  if (enableCircuitBreaker) {
103
104
  plugins.push(circuitBreaker__default["default"]({
104
105
  isSystemError: either__default["default"](http$1.isServerError, http$1.isNetworkFail),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/tinkoff-request-http-client-adapter",
3
- "version": "0.8.259",
3
+ "version": "0.8.263",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "browser": {
@@ -31,7 +31,7 @@
31
31
  "@tinkoff/request-plugin-validate": "^0.8.8",
32
32
  "@tinkoff/utils": "^2.1.2",
33
33
  "@tramvai/http-client": "0.1.25",
34
- "@tramvai/tokens-common": "1.65.0",
34
+ "@tramvai/tokens-common": "1.67.0",
35
35
  "tslib": "^2.0.3"
36
36
  },
37
37
  "sideEffects": false,