@tramvai/tinkoff-request-http-client-adapter 0.11.65 → 0.11.73
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/README.md
CHANGED
|
@@ -34,6 +34,11 @@ interface TinkoffRequestOptions extends HttpClientRequest {
|
|
|
34
34
|
errorValidator?: RequestValidator;
|
|
35
35
|
// method allows you to modify the error object before sending logs from `@tinkoff/request-plugin-log`
|
|
36
36
|
errorModificator?: RequestValidator;
|
|
37
|
+
// options for caching based on etag http-header, executes only on server!
|
|
38
|
+
etagCacheOptions?: {
|
|
39
|
+
enabled: boolean;
|
|
40
|
+
lruOptions?: { ttl: number; max: number };
|
|
41
|
+
};
|
|
37
42
|
}
|
|
38
43
|
```
|
|
39
44
|
|
|
@@ -2,6 +2,7 @@ import either from '@tinkoff/utils/function/either';
|
|
|
2
2
|
import request from '@tinkoff/request-core';
|
|
3
3
|
import logPlugin from '@tinkoff/request-plugin-log';
|
|
4
4
|
import deduplicateCache from '@tinkoff/request-plugin-cache-deduplicate';
|
|
5
|
+
import etagCache from '@tinkoff/request-plugin-cache-etag';
|
|
5
6
|
import memoryCache from '@tinkoff/request-plugin-cache-memory';
|
|
6
7
|
import validate from '@tinkoff/request-plugin-validate';
|
|
7
8
|
import http, { isServerError, isNetworkFail } from '@tinkoff/request-plugin-protocol-http';
|
|
@@ -12,7 +13,7 @@ import { createAgent } from './agent/createAgent.browser.browser.js';
|
|
|
12
13
|
|
|
13
14
|
const defaultAgent = createAgent();
|
|
14
15
|
function createTinkoffRequest(options) {
|
|
15
|
-
const { logger, name, disableCache, enableCircuitBreaker, createCache, cacheTime = 30000, defaultTimeout, validator, errorValidator, errorModificator, circuitBreakerOptions = {}, getCacheKey, lruOptions = { max: 1000, maxAge: cacheTime }, allowStale = true, agent, querySerializer, retryOptions, interceptors, ...defaults } = options;
|
|
16
|
+
const { logger, name, disableCache, enableCircuitBreaker, createCache, cacheTime = 30000, defaultTimeout, validator, errorValidator, errorModificator, circuitBreakerOptions = {}, getCacheKey, lruOptions = { max: 1000, maxAge: cacheTime }, allowStale = true, agent, querySerializer, retryOptions, etagCacheOptions, interceptors, ...defaults } = options;
|
|
16
17
|
const log = logger && logger(`${name}:initialization`);
|
|
17
18
|
const plugins = [];
|
|
18
19
|
plugins.push({
|
|
@@ -100,6 +101,15 @@ function createTinkoffRequest(options) {
|
|
|
100
101
|
if (retryOptions) {
|
|
101
102
|
plugins.push(retry(retryOptions));
|
|
102
103
|
}
|
|
104
|
+
// Executes only on server
|
|
105
|
+
if (etagCacheOptions === null || etagCacheOptions === void 0 ? void 0 : etagCacheOptions.enabled) {
|
|
106
|
+
plugins.push(etagCache({
|
|
107
|
+
shouldExecute: !disableCache,
|
|
108
|
+
getCacheKey,
|
|
109
|
+
memoryConstructor: createCache,
|
|
110
|
+
lruOptions: (etagCacheOptions === null || etagCacheOptions === void 0 ? void 0 : etagCacheOptions.lruOptions) || { max: 1000, ttl: 10 * 60 * 1000 },
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
103
113
|
plugins.push(http({
|
|
104
114
|
agent: agent || defaultAgent,
|
|
105
115
|
querySerializer: querySerializer || undefined,
|
|
@@ -32,6 +32,13 @@ export interface TinkoffRequestOptions extends HttpClientBaseOptions {
|
|
|
32
32
|
retryDelay?: number | ((attempt: number) => number);
|
|
33
33
|
maxTimeout?: number;
|
|
34
34
|
};
|
|
35
|
+
etagCacheOptions?: {
|
|
36
|
+
enabled: boolean;
|
|
37
|
+
lruOptions?: {
|
|
38
|
+
ttl: number;
|
|
39
|
+
max: number;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
35
42
|
agent?: {
|
|
36
43
|
http: Agent;
|
|
37
44
|
https: Agent;
|
|
@@ -2,6 +2,7 @@ import either from '@tinkoff/utils/function/either';
|
|
|
2
2
|
import request from '@tinkoff/request-core';
|
|
3
3
|
import logPlugin from '@tinkoff/request-plugin-log';
|
|
4
4
|
import deduplicateCache from '@tinkoff/request-plugin-cache-deduplicate';
|
|
5
|
+
import etagCache from '@tinkoff/request-plugin-cache-etag';
|
|
5
6
|
import memoryCache from '@tinkoff/request-plugin-cache-memory';
|
|
6
7
|
import validate from '@tinkoff/request-plugin-validate';
|
|
7
8
|
import http, { isServerError, isNetworkFail } from '@tinkoff/request-plugin-protocol-http';
|
|
@@ -12,7 +13,7 @@ import { createAgent } from './agent/createAgent.es.js';
|
|
|
12
13
|
|
|
13
14
|
const defaultAgent = createAgent();
|
|
14
15
|
function createTinkoffRequest(options) {
|
|
15
|
-
const { logger, name, disableCache, enableCircuitBreaker, createCache, cacheTime = 30000, defaultTimeout, validator, errorValidator, errorModificator, circuitBreakerOptions = {}, getCacheKey, lruOptions = { max: 1000, maxAge: cacheTime }, allowStale = true, agent, querySerializer, retryOptions, interceptors, ...defaults } = options;
|
|
16
|
+
const { logger, name, disableCache, enableCircuitBreaker, createCache, cacheTime = 30000, defaultTimeout, validator, errorValidator, errorModificator, circuitBreakerOptions = {}, getCacheKey, lruOptions = { max: 1000, maxAge: cacheTime }, allowStale = true, agent, querySerializer, retryOptions, etagCacheOptions, interceptors, ...defaults } = options;
|
|
16
17
|
const log = logger && logger(`${name}:initialization`);
|
|
17
18
|
const plugins = [];
|
|
18
19
|
plugins.push({
|
|
@@ -100,6 +101,15 @@ function createTinkoffRequest(options) {
|
|
|
100
101
|
if (retryOptions) {
|
|
101
102
|
plugins.push(retry(retryOptions));
|
|
102
103
|
}
|
|
104
|
+
// Executes only on server
|
|
105
|
+
if (etagCacheOptions === null || etagCacheOptions === void 0 ? void 0 : etagCacheOptions.enabled) {
|
|
106
|
+
plugins.push(etagCache({
|
|
107
|
+
shouldExecute: !disableCache,
|
|
108
|
+
getCacheKey,
|
|
109
|
+
memoryConstructor: createCache,
|
|
110
|
+
lruOptions: (etagCacheOptions === null || etagCacheOptions === void 0 ? void 0 : etagCacheOptions.lruOptions) || { max: 1000, ttl: 10 * 60 * 1000 },
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
103
113
|
plugins.push(http({
|
|
104
114
|
agent: agent || defaultAgent,
|
|
105
115
|
querySerializer: querySerializer || undefined,
|
|
@@ -6,6 +6,7 @@ var either = require('@tinkoff/utils/function/either');
|
|
|
6
6
|
var request = require('@tinkoff/request-core');
|
|
7
7
|
var logPlugin = require('@tinkoff/request-plugin-log');
|
|
8
8
|
var deduplicateCache = require('@tinkoff/request-plugin-cache-deduplicate');
|
|
9
|
+
var etagCache = require('@tinkoff/request-plugin-cache-etag');
|
|
9
10
|
var memoryCache = require('@tinkoff/request-plugin-cache-memory');
|
|
10
11
|
var validate = require('@tinkoff/request-plugin-validate');
|
|
11
12
|
var http = require('@tinkoff/request-plugin-protocol-http');
|
|
@@ -20,6 +21,7 @@ var either__default = /*#__PURE__*/_interopDefaultLegacy(either);
|
|
|
20
21
|
var request__default = /*#__PURE__*/_interopDefaultLegacy(request);
|
|
21
22
|
var logPlugin__default = /*#__PURE__*/_interopDefaultLegacy(logPlugin);
|
|
22
23
|
var deduplicateCache__default = /*#__PURE__*/_interopDefaultLegacy(deduplicateCache);
|
|
24
|
+
var etagCache__default = /*#__PURE__*/_interopDefaultLegacy(etagCache);
|
|
23
25
|
var memoryCache__default = /*#__PURE__*/_interopDefaultLegacy(memoryCache);
|
|
24
26
|
var validate__default = /*#__PURE__*/_interopDefaultLegacy(validate);
|
|
25
27
|
var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
|
|
@@ -29,7 +31,7 @@ var retry__default = /*#__PURE__*/_interopDefaultLegacy(retry);
|
|
|
29
31
|
|
|
30
32
|
const defaultAgent = createAgent.createAgent();
|
|
31
33
|
function createTinkoffRequest(options) {
|
|
32
|
-
const { logger, name, disableCache, enableCircuitBreaker, createCache, cacheTime = 30000, defaultTimeout, validator, errorValidator, errorModificator, circuitBreakerOptions = {}, getCacheKey, lruOptions = { max: 1000, maxAge: cacheTime }, allowStale = true, agent, querySerializer, retryOptions, interceptors, ...defaults } = options;
|
|
34
|
+
const { logger, name, disableCache, enableCircuitBreaker, createCache, cacheTime = 30000, defaultTimeout, validator, errorValidator, errorModificator, circuitBreakerOptions = {}, getCacheKey, lruOptions = { max: 1000, maxAge: cacheTime }, allowStale = true, agent, querySerializer, retryOptions, etagCacheOptions, interceptors, ...defaults } = options;
|
|
33
35
|
const log = logger && logger(`${name}:initialization`);
|
|
34
36
|
const plugins = [];
|
|
35
37
|
plugins.push({
|
|
@@ -117,6 +119,15 @@ function createTinkoffRequest(options) {
|
|
|
117
119
|
if (retryOptions) {
|
|
118
120
|
plugins.push(retry__default["default"](retryOptions));
|
|
119
121
|
}
|
|
122
|
+
// Executes only on server
|
|
123
|
+
if (etagCacheOptions === null || etagCacheOptions === void 0 ? void 0 : etagCacheOptions.enabled) {
|
|
124
|
+
plugins.push(etagCache__default["default"]({
|
|
125
|
+
shouldExecute: !disableCache,
|
|
126
|
+
getCacheKey,
|
|
127
|
+
memoryConstructor: createCache,
|
|
128
|
+
lruOptions: (etagCacheOptions === null || etagCacheOptions === void 0 ? void 0 : etagCacheOptions.lruOptions) || { max: 1000, ttl: 10 * 60 * 1000 },
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
120
131
|
plugins.push(http__default["default"]({
|
|
121
132
|
agent: agent || defaultAgent,
|
|
122
133
|
querySerializer: querySerializer || undefined,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/tinkoff-request-http-client-adapter",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.73",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"browser": {
|
|
@@ -22,16 +22,17 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@tinkoff/request-core": "^0.9.2",
|
|
24
24
|
"@tinkoff/request-plugin-cache-deduplicate": "^0.10.1",
|
|
25
|
+
"@tinkoff/request-plugin-cache-etag": "^0.4.2",
|
|
25
26
|
"@tinkoff/request-plugin-cache-memory": "^0.10.1",
|
|
26
27
|
"@tinkoff/request-plugin-circuit-breaker": "^0.3.2",
|
|
27
28
|
"@tinkoff/request-plugin-log": "^0.9.2",
|
|
28
29
|
"@tinkoff/request-plugin-protocol-http": "^0.12.1",
|
|
30
|
+
"@tinkoff/request-plugin-retry": "^0.2.3",
|
|
29
31
|
"@tinkoff/request-plugin-transform-url": "^0.9.2",
|
|
30
32
|
"@tinkoff/request-plugin-validate": "^0.9.2",
|
|
31
|
-
"@tinkoff/request-plugin-retry": "^0.2.3",
|
|
32
33
|
"@tinkoff/utils": "^2.1.2",
|
|
33
34
|
"@tramvai/http-client": "0.4.1",
|
|
34
|
-
"@tramvai/tokens-common": "4.20.
|
|
35
|
+
"@tramvai/tokens-common": "4.20.9",
|
|
35
36
|
"tslib": "^2.4.0"
|
|
36
37
|
},
|
|
37
38
|
"sideEffects": false,
|