@tramvai/module-http-client 2.91.1 → 2.92.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.
- package/lib/httpClient/httpClientFactory.browser.js +3 -2
- package/lib/httpClient/httpClientFactory.d.ts +3 -1
- package/lib/httpClient/httpClientFactory.es.js +3 -2
- package/lib/httpClient/httpClientFactory.js +3 -2
- package/lib/httpClientModule.browser.js +6 -1
- package/lib/httpClientModule.es.js +6 -1
- package/lib/httpClientModule.js +5 -0
- package/package.json +13 -13
- package/tests.js +8 -2
|
@@ -11,7 +11,7 @@ const environmentDependentOptions = typeof window === 'undefined'
|
|
|
11
11
|
: {
|
|
12
12
|
defaultTimeout: 30000,
|
|
13
13
|
};
|
|
14
|
-
const httpClientFactory = ({ logger, envManager, appInfo, requestManager, headersList, createCache, makeRequestRegistry, agent, querySerializer, disableCircuitBreaker = false, defaultOptions, commandLineExecutionContext, }) => {
|
|
14
|
+
const httpClientFactory = ({ logger, envManager, appInfo, requestManager, headersList, createCache, makeRequestRegistry, agent, querySerializer, disableCircuitBreaker = false, defaultOptions, defaultInterceptors, commandLineExecutionContext, }) => {
|
|
15
15
|
return (options) => {
|
|
16
16
|
var _a;
|
|
17
17
|
if (!options.name) {
|
|
@@ -19,6 +19,7 @@ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, header
|
|
|
19
19
|
}
|
|
20
20
|
const forceDisableCache = envManager.get('HTTP_CLIENT_CACHE_DISABLED');
|
|
21
21
|
const forceDisabledCircuitBreaker = envManager.get('HTTP_CLIENT_CIRCUIT_BREAKER_DISABLED');
|
|
22
|
+
const interceptors = { interceptors: defaultInterceptors || [] };
|
|
22
23
|
const adapterOptions = mergeOptions(mergeOptions({
|
|
23
24
|
logger,
|
|
24
25
|
agent,
|
|
@@ -35,7 +36,7 @@ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, header
|
|
|
35
36
|
// TODO: remove any after [resolving](https://github.com/southpolesteve/node-abort-controller/issues/31)
|
|
36
37
|
signal: (_a = commandLineExecutionContext === null || commandLineExecutionContext === void 0 ? void 0 : commandLineExecutionContext()) === null || _a === void 0 ? void 0 : _a.abortSignal,
|
|
37
38
|
...environmentDependentOptions,
|
|
38
|
-
}, defaultOptions
|
|
39
|
+
}, defaultOptions ? mergeOptions(defaultOptions, interceptors) : interceptors), options);
|
|
39
40
|
// по умолчанию, на сервере, библиотека https://github.com/node-fetch/node-fetch
|
|
40
41
|
// отправляет заголовок "User-Agent" вида "node-fetch".
|
|
41
42
|
// для улучшения логов сервисов, в которые делают запросы tramvai приложения,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { MakeRequest } from '@tinkoff/request-core';
|
|
2
|
+
import type { HttpClientInterceptor } from '@tramvai/http-client';
|
|
2
3
|
import type { APP_INFO_TOKEN } from '@tramvai/core';
|
|
3
4
|
import type { API_CLIENT_PASS_HEADERS, HttpClientFactoryOptions, HTTP_CLIENT_AGENT, HTTP_CLIENT_FACTORY, DISABLE_CIRCUIT_BREAKER } from '@tramvai/tokens-http-client';
|
|
4
5
|
import type { LOGGER_TOKEN, CREATE_CACHE_TOKEN, ENV_MANAGER_TOKEN, REQUEST_MANAGER_TOKEN, COMMAND_LINE_EXECUTION_CONTEXT_TOKEN } from '@tramvai/tokens-common';
|
|
5
6
|
import type { QuerySerializer } from '@tinkoff/request-plugin-protocol-http';
|
|
6
7
|
import type { ExtractDependencyType, ExtractTokenType } from '@tinkoff/dippy';
|
|
7
|
-
export declare const httpClientFactory: ({ logger, envManager, appInfo, requestManager, headersList, createCache, makeRequestRegistry, agent, querySerializer, disableCircuitBreaker, defaultOptions, commandLineExecutionContext, }: {
|
|
8
|
+
export declare const httpClientFactory: ({ logger, envManager, appInfo, requestManager, headersList, createCache, makeRequestRegistry, agent, querySerializer, disableCircuitBreaker, defaultOptions, defaultInterceptors, commandLineExecutionContext, }: {
|
|
8
9
|
logger: ExtractDependencyType<typeof LOGGER_TOKEN>;
|
|
9
10
|
envManager: ExtractDependencyType<typeof ENV_MANAGER_TOKEN>;
|
|
10
11
|
appInfo: ExtractDependencyType<typeof APP_INFO_TOKEN>;
|
|
@@ -16,5 +17,6 @@ export declare const httpClientFactory: ({ logger, envManager, appInfo, requestM
|
|
|
16
17
|
querySerializer?: QuerySerializer | undefined;
|
|
17
18
|
disableCircuitBreaker: ExtractDependencyType<typeof DISABLE_CIRCUIT_BREAKER> | null;
|
|
18
19
|
defaultOptions: Partial<HttpClientFactoryOptions> | null;
|
|
20
|
+
defaultInterceptors: HttpClientInterceptor[] | null;
|
|
19
21
|
commandLineExecutionContext: ExtractDependencyType<typeof COMMAND_LINE_EXECUTION_CONTEXT_TOKEN> | null;
|
|
20
22
|
}) => ExtractTokenType<typeof HTTP_CLIENT_FACTORY>;
|
|
@@ -11,7 +11,7 @@ const environmentDependentOptions = typeof window === 'undefined'
|
|
|
11
11
|
: {
|
|
12
12
|
defaultTimeout: 30000,
|
|
13
13
|
};
|
|
14
|
-
const httpClientFactory = ({ logger, envManager, appInfo, requestManager, headersList, createCache, makeRequestRegistry, agent, querySerializer, disableCircuitBreaker = false, defaultOptions, commandLineExecutionContext, }) => {
|
|
14
|
+
const httpClientFactory = ({ logger, envManager, appInfo, requestManager, headersList, createCache, makeRequestRegistry, agent, querySerializer, disableCircuitBreaker = false, defaultOptions, defaultInterceptors, commandLineExecutionContext, }) => {
|
|
15
15
|
return (options) => {
|
|
16
16
|
var _a;
|
|
17
17
|
if (!options.name) {
|
|
@@ -19,6 +19,7 @@ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, header
|
|
|
19
19
|
}
|
|
20
20
|
const forceDisableCache = envManager.get('HTTP_CLIENT_CACHE_DISABLED');
|
|
21
21
|
const forceDisabledCircuitBreaker = envManager.get('HTTP_CLIENT_CIRCUIT_BREAKER_DISABLED');
|
|
22
|
+
const interceptors = { interceptors: defaultInterceptors || [] };
|
|
22
23
|
const adapterOptions = mergeOptions(mergeOptions({
|
|
23
24
|
logger,
|
|
24
25
|
agent,
|
|
@@ -35,7 +36,7 @@ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, header
|
|
|
35
36
|
// TODO: remove any after [resolving](https://github.com/southpolesteve/node-abort-controller/issues/31)
|
|
36
37
|
signal: (_a = commandLineExecutionContext === null || commandLineExecutionContext === void 0 ? void 0 : commandLineExecutionContext()) === null || _a === void 0 ? void 0 : _a.abortSignal,
|
|
37
38
|
...environmentDependentOptions,
|
|
38
|
-
}, defaultOptions
|
|
39
|
+
}, defaultOptions ? mergeOptions(defaultOptions, interceptors) : interceptors), options);
|
|
39
40
|
// по умолчанию, на сервере, библиотека https://github.com/node-fetch/node-fetch
|
|
40
41
|
// отправляет заголовок "User-Agent" вида "node-fetch".
|
|
41
42
|
// для улучшения логов сервисов, в которые делают запросы tramvai приложения,
|
|
@@ -20,7 +20,7 @@ const environmentDependentOptions = typeof window === 'undefined'
|
|
|
20
20
|
: {
|
|
21
21
|
defaultTimeout: 30000,
|
|
22
22
|
};
|
|
23
|
-
const httpClientFactory = ({ logger, envManager, appInfo, requestManager, headersList, createCache, makeRequestRegistry, agent, querySerializer, disableCircuitBreaker = false, defaultOptions, commandLineExecutionContext, }) => {
|
|
23
|
+
const httpClientFactory = ({ logger, envManager, appInfo, requestManager, headersList, createCache, makeRequestRegistry, agent, querySerializer, disableCircuitBreaker = false, defaultOptions, defaultInterceptors, commandLineExecutionContext, }) => {
|
|
24
24
|
return (options) => {
|
|
25
25
|
var _a;
|
|
26
26
|
if (!options.name) {
|
|
@@ -28,6 +28,7 @@ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, header
|
|
|
28
28
|
}
|
|
29
29
|
const forceDisableCache = envManager.get('HTTP_CLIENT_CACHE_DISABLED');
|
|
30
30
|
const forceDisabledCircuitBreaker = envManager.get('HTTP_CLIENT_CIRCUIT_BREAKER_DISABLED');
|
|
31
|
+
const interceptors = { interceptors: defaultInterceptors || [] };
|
|
31
32
|
const adapterOptions = tinkoffRequestHttpClientAdapter.mergeOptions(tinkoffRequestHttpClientAdapter.mergeOptions({
|
|
32
33
|
logger,
|
|
33
34
|
agent,
|
|
@@ -44,7 +45,7 @@ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, header
|
|
|
44
45
|
// TODO: remove any after [resolving](https://github.com/southpolesteve/node-abort-controller/issues/31)
|
|
45
46
|
signal: (_a = commandLineExecutionContext === null || commandLineExecutionContext === void 0 ? void 0 : commandLineExecutionContext()) === null || _a === void 0 ? void 0 : _a.abortSignal,
|
|
46
47
|
...environmentDependentOptions,
|
|
47
|
-
}, defaultOptions
|
|
48
|
+
}, defaultOptions ? tinkoffRequestHttpClientAdapter.mergeOptions(defaultOptions, interceptors) : interceptors), options);
|
|
48
49
|
// по умолчанию, на сервере, библиотека https://github.com/node-fetch/node-fetch
|
|
49
50
|
// отправляет заголовок "User-Agent" вида "node-fetch".
|
|
50
51
|
// для улучшения логов сервисов, в которые делают запросы tramvai приложения,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createToken } from '@tinkoff/dippy';
|
|
2
2
|
import { Module, provide, APP_INFO_TOKEN, Scope } from '@tramvai/core';
|
|
3
|
-
import { HTTP_CLIENT_FACTORY, API_CLIENT_PASS_HEADERS, HTTP_CLIENT_AGENT, DISABLE_CIRCUIT_BREAKER, DEFAULT_HTTP_CLIENT_FACTORY_OPTIONS, HTTP_CLIENT } from '@tramvai/tokens-http-client';
|
|
3
|
+
import { HTTP_CLIENT_FACTORY, API_CLIENT_PASS_HEADERS, HTTP_CLIENT_AGENT, DISABLE_CIRCUIT_BREAKER, DEFAULT_HTTP_CLIENT_FACTORY_OPTIONS, DEFAULT_HTTP_CLIENT_INTERCEPTORS, HTTP_CLIENT } from '@tramvai/tokens-http-client';
|
|
4
4
|
import { LOGGER_TOKEN, ENV_MANAGER_TOKEN, REQUEST_MANAGER_TOKEN, COMMAND_LINE_EXECUTION_CONTEXT_TOKEN, ENV_USED_TOKEN, CREATE_CACHE_TOKEN } from '@tramvai/tokens-common';
|
|
5
5
|
import { httpClientFactory } from './httpClient/httpClientFactory.browser.js';
|
|
6
6
|
import { PapiClientModule } from './papiClientModule.browser.browser.js';
|
|
@@ -38,6 +38,10 @@ const HttpClientModule = /* @__PURE__ */ Module({
|
|
|
38
38
|
token: DEFAULT_HTTP_CLIENT_FACTORY_OPTIONS,
|
|
39
39
|
optional: true,
|
|
40
40
|
},
|
|
41
|
+
defaultInterceptors: {
|
|
42
|
+
token: DEFAULT_HTTP_CLIENT_INTERCEPTORS,
|
|
43
|
+
optional: true,
|
|
44
|
+
},
|
|
41
45
|
commandLineExecutionContext: {
|
|
42
46
|
token: COMMAND_LINE_EXECUTION_CONTEXT_TOKEN,
|
|
43
47
|
optional: true,
|
|
@@ -50,6 +54,7 @@ const HttpClientModule = /* @__PURE__ */ Module({
|
|
|
50
54
|
return factory({
|
|
51
55
|
name: 'http-client',
|
|
52
56
|
disableCache: true,
|
|
57
|
+
enableCircuitBreaker: false,
|
|
53
58
|
});
|
|
54
59
|
},
|
|
55
60
|
deps: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createToken } from '@tinkoff/dippy';
|
|
2
2
|
import { Module, provide, APP_INFO_TOKEN, Scope } from '@tramvai/core';
|
|
3
|
-
import { HTTP_CLIENT_FACTORY, API_CLIENT_PASS_HEADERS, HTTP_CLIENT_AGENT, DISABLE_CIRCUIT_BREAKER, DEFAULT_HTTP_CLIENT_FACTORY_OPTIONS, HTTP_CLIENT } from '@tramvai/tokens-http-client';
|
|
3
|
+
import { HTTP_CLIENT_FACTORY, API_CLIENT_PASS_HEADERS, HTTP_CLIENT_AGENT, DISABLE_CIRCUIT_BREAKER, DEFAULT_HTTP_CLIENT_FACTORY_OPTIONS, DEFAULT_HTTP_CLIENT_INTERCEPTORS, HTTP_CLIENT } from '@tramvai/tokens-http-client';
|
|
4
4
|
import { LOGGER_TOKEN, ENV_MANAGER_TOKEN, REQUEST_MANAGER_TOKEN, COMMAND_LINE_EXECUTION_CONTEXT_TOKEN, ENV_USED_TOKEN, CREATE_CACHE_TOKEN } from '@tramvai/tokens-common';
|
|
5
5
|
import { httpClientFactory } from './httpClient/httpClientFactory.es.js';
|
|
6
6
|
import { PapiClientModule } from './papiClientModule.es.js';
|
|
@@ -38,6 +38,10 @@ const HttpClientModule = /* @__PURE__ */ Module({
|
|
|
38
38
|
token: DEFAULT_HTTP_CLIENT_FACTORY_OPTIONS,
|
|
39
39
|
optional: true,
|
|
40
40
|
},
|
|
41
|
+
defaultInterceptors: {
|
|
42
|
+
token: DEFAULT_HTTP_CLIENT_INTERCEPTORS,
|
|
43
|
+
optional: true,
|
|
44
|
+
},
|
|
41
45
|
commandLineExecutionContext: {
|
|
42
46
|
token: COMMAND_LINE_EXECUTION_CONTEXT_TOKEN,
|
|
43
47
|
optional: true,
|
|
@@ -50,6 +54,7 @@ const HttpClientModule = /* @__PURE__ */ Module({
|
|
|
50
54
|
return factory({
|
|
51
55
|
name: 'http-client',
|
|
52
56
|
disableCache: true,
|
|
57
|
+
enableCircuitBreaker: false,
|
|
53
58
|
});
|
|
54
59
|
},
|
|
55
60
|
deps: {
|
package/lib/httpClientModule.js
CHANGED
|
@@ -42,6 +42,10 @@ const HttpClientModule = /* @__PURE__ */ core.Module({
|
|
|
42
42
|
token: tokensHttpClient.DEFAULT_HTTP_CLIENT_FACTORY_OPTIONS,
|
|
43
43
|
optional: true,
|
|
44
44
|
},
|
|
45
|
+
defaultInterceptors: {
|
|
46
|
+
token: tokensHttpClient.DEFAULT_HTTP_CLIENT_INTERCEPTORS,
|
|
47
|
+
optional: true,
|
|
48
|
+
},
|
|
45
49
|
commandLineExecutionContext: {
|
|
46
50
|
token: tokensCommon.COMMAND_LINE_EXECUTION_CONTEXT_TOKEN,
|
|
47
51
|
optional: true,
|
|
@@ -54,6 +58,7 @@ const HttpClientModule = /* @__PURE__ */ core.Module({
|
|
|
54
58
|
return factory({
|
|
55
59
|
name: 'http-client',
|
|
56
60
|
disableCache: true,
|
|
61
|
+
enableCircuitBreaker: false,
|
|
57
62
|
});
|
|
58
63
|
},
|
|
59
64
|
deps: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/module-http-client",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.92.0",
|
|
4
4
|
"initialVersion": "0.58.99",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"watch": "tsc -w"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@tramvai/http-client": "0.2.
|
|
29
|
-
"@tramvai/tinkoff-request-http-client-adapter": "0.9.
|
|
30
|
-
"@tramvai/tokens-http-client": "2.
|
|
31
|
-
"@tramvai/tokens-common": "2.
|
|
32
|
-
"@tramvai/tokens-server": "2.
|
|
33
|
-
"@tramvai/tokens-server-private": "2.
|
|
28
|
+
"@tramvai/http-client": "0.2.9",
|
|
29
|
+
"@tramvai/tinkoff-request-http-client-adapter": "0.9.233",
|
|
30
|
+
"@tramvai/tokens-http-client": "2.92.0",
|
|
31
|
+
"@tramvai/tokens-common": "2.92.0",
|
|
32
|
+
"@tramvai/tokens-server": "2.92.0",
|
|
33
|
+
"@tramvai/tokens-server-private": "2.92.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@tinkoff/request-core": "^0.9.2",
|
|
@@ -39,12 +39,12 @@
|
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@tinkoff/utils": "^2.1.2",
|
|
42
|
-
"@tramvai/core": "2.
|
|
43
|
-
"@tramvai/module-common": "2.
|
|
44
|
-
"@tramvai/papi": "2.
|
|
45
|
-
"@tramvai/test-helpers": "2.
|
|
46
|
-
"@tramvai/test-unit": "2.
|
|
47
|
-
"@tramvai/test-mocks": "2.
|
|
42
|
+
"@tramvai/core": "2.92.0",
|
|
43
|
+
"@tramvai/module-common": "2.92.0",
|
|
44
|
+
"@tramvai/papi": "2.92.0",
|
|
45
|
+
"@tramvai/test-helpers": "2.92.0",
|
|
46
|
+
"@tramvai/test-unit": "2.92.0",
|
|
47
|
+
"@tramvai/test-mocks": "2.92.0",
|
|
48
48
|
"@tinkoff/dippy": "0.8.15",
|
|
49
49
|
"node-fetch": "^2.6.1",
|
|
50
50
|
"tslib": "^2.4.0"
|
package/tests.js
CHANGED
|
@@ -83,7 +83,7 @@ const environmentDependentOptions = typeof window === 'undefined'
|
|
|
83
83
|
: {
|
|
84
84
|
defaultTimeout: 30000,
|
|
85
85
|
};
|
|
86
|
-
const httpClientFactory = ({ logger, envManager, appInfo, requestManager, headersList, createCache, makeRequestRegistry, agent, querySerializer, disableCircuitBreaker = false, defaultOptions, commandLineExecutionContext, }) => {
|
|
86
|
+
const httpClientFactory = ({ logger, envManager, appInfo, requestManager, headersList, createCache, makeRequestRegistry, agent, querySerializer, disableCircuitBreaker = false, defaultOptions, defaultInterceptors, commandLineExecutionContext, }) => {
|
|
87
87
|
return (options) => {
|
|
88
88
|
var _a;
|
|
89
89
|
if (!options.name) {
|
|
@@ -91,6 +91,7 @@ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, header
|
|
|
91
91
|
}
|
|
92
92
|
const forceDisableCache = envManager.get('HTTP_CLIENT_CACHE_DISABLED');
|
|
93
93
|
const forceDisabledCircuitBreaker = envManager.get('HTTP_CLIENT_CIRCUIT_BREAKER_DISABLED');
|
|
94
|
+
const interceptors = { interceptors: defaultInterceptors || [] };
|
|
94
95
|
const adapterOptions = tinkoffRequestHttpClientAdapter.mergeOptions(tinkoffRequestHttpClientAdapter.mergeOptions({
|
|
95
96
|
logger,
|
|
96
97
|
agent,
|
|
@@ -107,7 +108,7 @@ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, header
|
|
|
107
108
|
// TODO: remove any after [resolving](https://github.com/southpolesteve/node-abort-controller/issues/31)
|
|
108
109
|
signal: (_a = commandLineExecutionContext === null || commandLineExecutionContext === void 0 ? void 0 : commandLineExecutionContext()) === null || _a === void 0 ? void 0 : _a.abortSignal,
|
|
109
110
|
...environmentDependentOptions,
|
|
110
|
-
}, defaultOptions
|
|
111
|
+
}, defaultOptions ? tinkoffRequestHttpClientAdapter.mergeOptions(defaultOptions, interceptors) : interceptors), options);
|
|
111
112
|
// по умолчанию, на сервере, библиотека https://github.com/node-fetch/node-fetch
|
|
112
113
|
// отправляет заголовок "User-Agent" вида "node-fetch".
|
|
113
114
|
// для улучшения логов сервисов, в которые делают запросы tramvai приложения,
|
|
@@ -219,6 +220,10 @@ const HttpClientModule = /* @__PURE__ */ core.Module({
|
|
|
219
220
|
token: tokensHttpClient.DEFAULT_HTTP_CLIENT_FACTORY_OPTIONS,
|
|
220
221
|
optional: true,
|
|
221
222
|
},
|
|
223
|
+
defaultInterceptors: {
|
|
224
|
+
token: tokensHttpClient.DEFAULT_HTTP_CLIENT_INTERCEPTORS,
|
|
225
|
+
optional: true,
|
|
226
|
+
},
|
|
222
227
|
commandLineExecutionContext: {
|
|
223
228
|
token: tokensCommon.COMMAND_LINE_EXECUTION_CONTEXT_TOKEN,
|
|
224
229
|
optional: true,
|
|
@@ -231,6 +236,7 @@ const HttpClientModule = /* @__PURE__ */ core.Module({
|
|
|
231
236
|
return factory({
|
|
232
237
|
name: 'http-client',
|
|
233
238
|
disableCache: true,
|
|
239
|
+
enableCircuitBreaker: false,
|
|
234
240
|
});
|
|
235
241
|
},
|
|
236
242
|
deps: {
|