@tramvai/tinkoff-request-http-client-adapter 0.8.256 → 0.8.261

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),
@@ -186,17 +187,8 @@ class HttpClientAdapter extends BaseHttpClient {
186
187
  }
187
188
 
188
189
  function createAdapter(options) {
189
- const { logger, name, disableCache, createCache, cacheTime, defaultTimeout, validator, errorValidator, errorModificator, agent, modifyRequest = (req) => req, modifyResponse = (res) => res, modifyError = (err) => err, ...httpClientOptions } = options;
190
190
  const tinkoffRequest = createTinkoffRequest(options);
191
- const httpClientAdapter = new HttpClientAdapter({
192
- options: {
193
- modifyRequest,
194
- modifyResponse,
195
- modifyError,
196
- ...httpClientOptions,
197
- },
198
- tinkoffRequest,
199
- });
191
+ const httpClientAdapter = new HttpClientAdapter({ options, tinkoffRequest });
200
192
  return httpClientAdapter;
201
193
  }
202
194
 
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),
@@ -196,17 +197,8 @@ class HttpClientAdapter extends BaseHttpClient {
196
197
  }
197
198
 
198
199
  function createAdapter(options) {
199
- const { logger, name, disableCache, createCache, cacheTime, defaultTimeout, validator, errorValidator, errorModificator, agent, modifyRequest = (req) => req, modifyResponse = (res) => res, modifyError = (err) => err, ...httpClientOptions } = options;
200
200
  const tinkoffRequest = createTinkoffRequest(options);
201
- const httpClientAdapter = new HttpClientAdapter({
202
- options: {
203
- modifyRequest,
204
- modifyResponse,
205
- modifyError,
206
- ...httpClientOptions,
207
- },
208
- tinkoffRequest,
209
- });
201
+ const httpClientAdapter = new HttpClientAdapter({ options, tinkoffRequest });
210
202
  return httpClientAdapter;
211
203
  }
212
204
 
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),
@@ -215,17 +216,8 @@ class HttpClientAdapter extends httpClient.BaseHttpClient {
215
216
  }
216
217
 
217
218
  function createAdapter(options) {
218
- const { logger, name, disableCache, createCache, cacheTime, defaultTimeout, validator, errorValidator, errorModificator, agent, modifyRequest = (req) => req, modifyResponse = (res) => res, modifyError = (err) => err, ...httpClientOptions } = options;
219
219
  const tinkoffRequest = createTinkoffRequest(options);
220
- const httpClientAdapter = new HttpClientAdapter({
221
- options: {
222
- modifyRequest,
223
- modifyResponse,
224
- modifyError,
225
- ...httpClientOptions,
226
- },
227
- tinkoffRequest,
228
- });
220
+ const httpClientAdapter = new HttpClientAdapter({ options, tinkoffRequest });
229
221
  return httpClientAdapter;
230
222
  }
231
223
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/tinkoff-request-http-client-adapter",
3
- "version": "0.8.256",
3
+ "version": "0.8.261",
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.63.1",
34
+ "@tramvai/tokens-common": "1.66.0",
35
35
  "tslib": "^2.0.3"
36
36
  },
37
37
  "sideEffects": false,