@tramvai/module-http-client 7.21.1 → 7.26.8
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 +7 -0
- package/lib/httpClient/httpClientFactory.es.js +7 -0
- package/lib/httpClient/httpClientFactory.js +7 -0
- package/lib/httpClientModule.browser.js +18 -0
- package/lib/httpClientModule.es.js +18 -0
- package/lib/httpClientModule.js +22 -0
- package/package.json +15 -13
- package/tests.js +27 -1
|
@@ -37,6 +37,10 @@ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, header
|
|
|
37
37
|
...environmentDependentOptions,
|
|
38
38
|
}, defaultOptions ? mergeOptions(defaultOptions, interceptors) : interceptors), options);
|
|
39
39
|
adapterOptions.headers = {
|
|
40
|
+
// prevent CORS error when trying to set custom header in browser
|
|
41
|
+
...(options.baseUrlEnv && typeof window === 'undefined'
|
|
42
|
+
? { 'x-tramvai-service-name': options.baseUrlEnv }
|
|
43
|
+
: {}),
|
|
40
44
|
...transformUserAgent({ appInfo, envManager }),
|
|
41
45
|
...adapterOptions.headers,
|
|
42
46
|
};
|
|
@@ -50,6 +54,9 @@ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, header
|
|
|
50
54
|
if (forceDisabledCircuitBreaker === 'true') {
|
|
51
55
|
adapterOptions.enableCircuitBreaker = !forceDisabledCircuitBreaker;
|
|
52
56
|
}
|
|
57
|
+
if (options.baseUrlEnv && typeof adapterOptions.baseUrl !== 'string') {
|
|
58
|
+
adapterOptions.baseUrl = envManager.get(options.baseUrlEnv);
|
|
59
|
+
}
|
|
53
60
|
// cache @tinkoff/request instance for performance reason
|
|
54
61
|
if (!makeRequestRegistry.has(adapterOptions.name)) {
|
|
55
62
|
const tRequestOptions = { ...adapterOptions };
|
|
@@ -37,6 +37,10 @@ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, header
|
|
|
37
37
|
...environmentDependentOptions,
|
|
38
38
|
}, defaultOptions ? mergeOptions(defaultOptions, interceptors) : interceptors), options);
|
|
39
39
|
adapterOptions.headers = {
|
|
40
|
+
// prevent CORS error when trying to set custom header in browser
|
|
41
|
+
...(options.baseUrlEnv && typeof window === 'undefined'
|
|
42
|
+
? { 'x-tramvai-service-name': options.baseUrlEnv }
|
|
43
|
+
: {}),
|
|
40
44
|
...transformUserAgent({ appInfo, envManager }),
|
|
41
45
|
...adapterOptions.headers,
|
|
42
46
|
};
|
|
@@ -50,6 +54,9 @@ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, header
|
|
|
50
54
|
if (forceDisabledCircuitBreaker === 'true') {
|
|
51
55
|
adapterOptions.enableCircuitBreaker = !forceDisabledCircuitBreaker;
|
|
52
56
|
}
|
|
57
|
+
if (options.baseUrlEnv && typeof adapterOptions.baseUrl !== 'string') {
|
|
58
|
+
adapterOptions.baseUrl = envManager.get(options.baseUrlEnv);
|
|
59
|
+
}
|
|
53
60
|
// cache @tinkoff/request instance for performance reason
|
|
54
61
|
if (!makeRequestRegistry.has(adapterOptions.name)) {
|
|
55
62
|
const tRequestOptions = { ...adapterOptions };
|
|
@@ -46,6 +46,10 @@ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, header
|
|
|
46
46
|
...environmentDependentOptions,
|
|
47
47
|
}, defaultOptions ? tinkoffRequestHttpClientAdapter.mergeOptions(defaultOptions, interceptors) : interceptors), options);
|
|
48
48
|
adapterOptions.headers = {
|
|
49
|
+
// prevent CORS error when trying to set custom header in browser
|
|
50
|
+
...(options.baseUrlEnv && typeof window === 'undefined'
|
|
51
|
+
? { 'x-tramvai-service-name': options.baseUrlEnv }
|
|
52
|
+
: {}),
|
|
49
53
|
...headers.transformUserAgent({ appInfo, envManager }),
|
|
50
54
|
...adapterOptions.headers,
|
|
51
55
|
};
|
|
@@ -59,6 +63,9 @@ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, header
|
|
|
59
63
|
if (forceDisabledCircuitBreaker === 'true') {
|
|
60
64
|
adapterOptions.enableCircuitBreaker = !forceDisabledCircuitBreaker;
|
|
61
65
|
}
|
|
66
|
+
if (options.baseUrlEnv && typeof adapterOptions.baseUrl !== 'string') {
|
|
67
|
+
adapterOptions.baseUrl = envManager.get(options.baseUrlEnv);
|
|
68
|
+
}
|
|
62
69
|
// cache @tinkoff/request instance for performance reason
|
|
63
70
|
if (!makeRequestRegistry.has(adapterOptions.name)) {
|
|
64
71
|
const tRequestOptions = { ...adapterOptions };
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import noop from '@tinkoff/utils/function/noop';
|
|
1
2
|
import { declareModule, provide, commandLineListTokens, optional } from '@tramvai/core';
|
|
2
3
|
import { HTTP_CLIENT_AGENT, HTTP_CLIENT_AGENT_OPTIONS, HTTP_CLIENT_AGENT_INTERCEPTORS } from '@tramvai/tokens-http-client';
|
|
4
|
+
import { commandLineListTokens as commandLineListTokens$1 } from '@tramvai/child-app-core';
|
|
5
|
+
import { IS_CHILD_APP_DI_TOKEN } from '@tramvai/tokens-child-app';
|
|
3
6
|
import { PapiClientModule } from './papiClientModule.browser.browser.js';
|
|
4
7
|
import { providers } from './shared.browser.js';
|
|
5
8
|
|
|
@@ -46,6 +49,21 @@ const HttpClientModule = /* @__PURE__ */ declareModule({
|
|
|
46
49
|
provide: HTTP_CLIENT_AGENT_OPTIONS,
|
|
47
50
|
useValue: {},
|
|
48
51
|
}),
|
|
52
|
+
// Show an error in the development environment to prevent developers
|
|
53
|
+
// from including this module in child app dependencies, as it causes
|
|
54
|
+
// bundle size inflation and cache-related errors.
|
|
55
|
+
provide({
|
|
56
|
+
provide: commandLineListTokens$1.customerStart,
|
|
57
|
+
useFactory: ({ isChildAppRunner }) => {
|
|
58
|
+
if (process.env.NODE_ENV === 'development' && isChildAppRunner) {
|
|
59
|
+
throw new Error('HttpClientModule cannot be imported in a child app. This module must be used in host application.');
|
|
60
|
+
}
|
|
61
|
+
return noop;
|
|
62
|
+
},
|
|
63
|
+
deps: {
|
|
64
|
+
isChildAppRunner: optional(IS_CHILD_APP_DI_TOKEN),
|
|
65
|
+
},
|
|
66
|
+
}),
|
|
49
67
|
]
|
|
50
68
|
: []),
|
|
51
69
|
],
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import noop from '@tinkoff/utils/function/noop';
|
|
1
2
|
import { declareModule, provide, commandLineListTokens, optional } from '@tramvai/core';
|
|
2
3
|
import { HTTP_CLIENT_AGENT, HTTP_CLIENT_AGENT_OPTIONS, HTTP_CLIENT_AGENT_INTERCEPTORS } from '@tramvai/tokens-http-client';
|
|
4
|
+
import { commandLineListTokens as commandLineListTokens$1 } from '@tramvai/child-app-core';
|
|
5
|
+
import { IS_CHILD_APP_DI_TOKEN } from '@tramvai/tokens-child-app';
|
|
3
6
|
import { PapiClientModule } from './papiClientModule.es.js';
|
|
4
7
|
import { providers } from './shared.es.js';
|
|
5
8
|
|
|
@@ -46,6 +49,21 @@ const HttpClientModule = /* @__PURE__ */ declareModule({
|
|
|
46
49
|
provide: HTTP_CLIENT_AGENT_OPTIONS,
|
|
47
50
|
useValue: {},
|
|
48
51
|
}),
|
|
52
|
+
// Show an error in the development environment to prevent developers
|
|
53
|
+
// from including this module in child app dependencies, as it causes
|
|
54
|
+
// bundle size inflation and cache-related errors.
|
|
55
|
+
provide({
|
|
56
|
+
provide: commandLineListTokens$1.customerStart,
|
|
57
|
+
useFactory: ({ isChildAppRunner }) => {
|
|
58
|
+
if (process.env.NODE_ENV === 'development' && isChildAppRunner) {
|
|
59
|
+
throw new Error('HttpClientModule cannot be imported in a child app. This module must be used in host application.');
|
|
60
|
+
}
|
|
61
|
+
return noop;
|
|
62
|
+
},
|
|
63
|
+
deps: {
|
|
64
|
+
isChildAppRunner: optional(IS_CHILD_APP_DI_TOKEN),
|
|
65
|
+
},
|
|
66
|
+
}),
|
|
49
67
|
]
|
|
50
68
|
: []),
|
|
51
69
|
],
|
package/lib/httpClientModule.js
CHANGED
|
@@ -2,11 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var noop = require('@tinkoff/utils/function/noop');
|
|
5
6
|
var core = require('@tramvai/core');
|
|
6
7
|
var tokensHttpClient = require('@tramvai/tokens-http-client');
|
|
8
|
+
var childAppCore = require('@tramvai/child-app-core');
|
|
9
|
+
var tokensChildApp = require('@tramvai/tokens-child-app');
|
|
7
10
|
var papiClientModule = require('./papiClientModule.js');
|
|
8
11
|
var shared = require('./shared.js');
|
|
9
12
|
|
|
13
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
|
+
|
|
15
|
+
var noop__default = /*#__PURE__*/_interopDefaultLegacy(noop);
|
|
16
|
+
|
|
10
17
|
const HttpClientModule = /* @__PURE__ */ core.declareModule({
|
|
11
18
|
name: 'HttpClientModule',
|
|
12
19
|
imports: [papiClientModule.PapiClientModule],
|
|
@@ -50,6 +57,21 @@ const HttpClientModule = /* @__PURE__ */ core.declareModule({
|
|
|
50
57
|
provide: tokensHttpClient.HTTP_CLIENT_AGENT_OPTIONS,
|
|
51
58
|
useValue: {},
|
|
52
59
|
}),
|
|
60
|
+
// Show an error in the development environment to prevent developers
|
|
61
|
+
// from including this module in child app dependencies, as it causes
|
|
62
|
+
// bundle size inflation and cache-related errors.
|
|
63
|
+
core.provide({
|
|
64
|
+
provide: childAppCore.commandLineListTokens.customerStart,
|
|
65
|
+
useFactory: ({ isChildAppRunner }) => {
|
|
66
|
+
if (process.env.NODE_ENV === 'development' && isChildAppRunner) {
|
|
67
|
+
throw new Error('HttpClientModule cannot be imported in a child app. This module must be used in host application.');
|
|
68
|
+
}
|
|
69
|
+
return noop__default["default"];
|
|
70
|
+
},
|
|
71
|
+
deps: {
|
|
72
|
+
isChildAppRunner: core.optional(tokensChildApp.IS_CHILD_APP_DI_TOKEN),
|
|
73
|
+
},
|
|
74
|
+
}),
|
|
53
75
|
]
|
|
54
76
|
: []),
|
|
55
77
|
],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/module-http-client",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.26.8",
|
|
4
4
|
"initialVersion": "0.58.99",
|
|
5
5
|
"description": "",
|
|
6
6
|
"engines": {
|
|
@@ -29,29 +29,31 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@jest/globals": "^29.7.0",
|
|
32
|
+
"@tramvai/child-app-core": "7.26.8",
|
|
32
33
|
"@tramvai/http-client": "0.7.1",
|
|
33
|
-
"@tramvai/tinkoff-request-http-client-adapter": "0.14.
|
|
34
|
-
"@tramvai/tokens-
|
|
35
|
-
"@tramvai/tokens-
|
|
36
|
-
"@tramvai/tokens-
|
|
37
|
-
"@tramvai/tokens-server
|
|
34
|
+
"@tramvai/tinkoff-request-http-client-adapter": "0.14.106",
|
|
35
|
+
"@tramvai/tokens-child-app": "7.26.8",
|
|
36
|
+
"@tramvai/tokens-common": "7.26.8",
|
|
37
|
+
"@tramvai/tokens-http-client": "7.26.8",
|
|
38
|
+
"@tramvai/tokens-server": "7.26.8",
|
|
39
|
+
"@tramvai/tokens-server-private": "7.26.8",
|
|
38
40
|
"jest": "^29.7.0",
|
|
39
41
|
"undici": "^7.24.4"
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
|
42
44
|
"@tinkoff/request-core": "^0.10.0",
|
|
43
45
|
"@tinkoff/request-plugin-protocol-http": "0.16.0",
|
|
44
|
-
"@tramvai/build": "8.0.
|
|
46
|
+
"@tramvai/build": "8.0.2"
|
|
45
47
|
},
|
|
46
48
|
"peerDependencies": {
|
|
47
49
|
"@tinkoff/dippy": "^1.0.0",
|
|
48
50
|
"@tinkoff/utils": "^2.1.2",
|
|
49
|
-
"@tramvai/core": "7.
|
|
50
|
-
"@tramvai/module-common": "7.
|
|
51
|
-
"@tramvai/papi": "7.
|
|
52
|
-
"@tramvai/test-helpers": "7.
|
|
53
|
-
"@tramvai/test-mocks": "7.
|
|
54
|
-
"@tramvai/test-unit": "7.
|
|
51
|
+
"@tramvai/core": "7.26.8",
|
|
52
|
+
"@tramvai/module-common": "7.26.8",
|
|
53
|
+
"@tramvai/papi": "7.26.8",
|
|
54
|
+
"@tramvai/test-helpers": "7.26.8",
|
|
55
|
+
"@tramvai/test-mocks": "7.26.8",
|
|
56
|
+
"@tramvai/test-unit": "7.26.8",
|
|
55
57
|
"tslib": "^2.4.0"
|
|
56
58
|
},
|
|
57
59
|
"license": "Apache-2.0",
|
package/tests.js
CHANGED
|
@@ -4,8 +4,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var testHelpers = require('@tramvai/test-helpers');
|
|
6
6
|
var testMocks = require('@tramvai/test-mocks');
|
|
7
|
+
var globals = require('@jest/globals');
|
|
8
|
+
var noop = require('@tinkoff/utils/function/noop');
|
|
7
9
|
var core = require('@tramvai/core');
|
|
8
10
|
var tokensHttpClient = require('@tramvai/tokens-http-client');
|
|
11
|
+
var childAppCore = require('@tramvai/child-app-core');
|
|
12
|
+
var tokensChildApp = require('@tramvai/tokens-child-app');
|
|
9
13
|
var tokensServer = require('@tramvai/tokens-server');
|
|
10
14
|
var tokensCommon = require('@tramvai/tokens-common');
|
|
11
15
|
var find = require('@tinkoff/utils/array/find');
|
|
@@ -19,10 +23,10 @@ var pick = require('@tinkoff/utils/object/pick');
|
|
|
19
23
|
var isNil = require('@tinkoff/utils/is/nil');
|
|
20
24
|
var compose = require('@tinkoff/utils/function/compose');
|
|
21
25
|
var tinkoffRequestHttpClientAdapter = require('@tramvai/tinkoff-request-http-client-adapter');
|
|
22
|
-
var globals = require('@jest/globals');
|
|
23
26
|
|
|
24
27
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
25
28
|
|
|
29
|
+
var noop__default = /*#__PURE__*/_interopDefaultLegacy(noop);
|
|
26
30
|
var find__default = /*#__PURE__*/_interopDefaultLegacy(find);
|
|
27
31
|
var flatten__default = /*#__PURE__*/_interopDefaultLegacy(flatten);
|
|
28
32
|
var identity__default = /*#__PURE__*/_interopDefaultLegacy(identity);
|
|
@@ -188,6 +192,10 @@ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, header
|
|
|
188
192
|
...environmentDependentOptions,
|
|
189
193
|
}, defaultOptions ? tinkoffRequestHttpClientAdapter.mergeOptions(defaultOptions, interceptors) : interceptors), options);
|
|
190
194
|
adapterOptions.headers = {
|
|
195
|
+
// prevent CORS error when trying to set custom header in browser
|
|
196
|
+
...(options.baseUrlEnv && typeof window === 'undefined'
|
|
197
|
+
? { 'x-tramvai-service-name': options.baseUrlEnv }
|
|
198
|
+
: {}),
|
|
191
199
|
...transformUserAgent({ appInfo, envManager }),
|
|
192
200
|
...adapterOptions.headers,
|
|
193
201
|
};
|
|
@@ -201,6 +209,9 @@ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, header
|
|
|
201
209
|
if (forceDisabledCircuitBreaker === 'true') {
|
|
202
210
|
adapterOptions.enableCircuitBreaker = !forceDisabledCircuitBreaker;
|
|
203
211
|
}
|
|
212
|
+
if (options.baseUrlEnv && typeof adapterOptions.baseUrl !== 'string') {
|
|
213
|
+
adapterOptions.baseUrl = envManager.get(options.baseUrlEnv);
|
|
214
|
+
}
|
|
204
215
|
// cache @tinkoff/request instance for performance reason
|
|
205
216
|
if (!makeRequestRegistry.has(adapterOptions.name)) {
|
|
206
217
|
const tRequestOptions = { ...adapterOptions };
|
|
@@ -361,6 +372,21 @@ const HttpClientModule = /* @__PURE__ */ core.declareModule({
|
|
|
361
372
|
provide: tokensHttpClient.HTTP_CLIENT_AGENT_OPTIONS,
|
|
362
373
|
useValue: {},
|
|
363
374
|
}),
|
|
375
|
+
// Show an error in the development environment to prevent developers
|
|
376
|
+
// from including this module in child app dependencies, as it causes
|
|
377
|
+
// bundle size inflation and cache-related errors.
|
|
378
|
+
core.provide({
|
|
379
|
+
provide: childAppCore.commandLineListTokens.customerStart,
|
|
380
|
+
useFactory: ({ isChildAppRunner }) => {
|
|
381
|
+
if (process.env.NODE_ENV === 'development' && isChildAppRunner) {
|
|
382
|
+
throw new Error('HttpClientModule cannot be imported in a child app. This module must be used in host application.');
|
|
383
|
+
}
|
|
384
|
+
return noop__default["default"];
|
|
385
|
+
},
|
|
386
|
+
deps: {
|
|
387
|
+
isChildAppRunner: core.optional(tokensChildApp.IS_CHILD_APP_DI_TOKEN),
|
|
388
|
+
},
|
|
389
|
+
}),
|
|
364
390
|
]
|
|
365
391
|
: []),
|
|
366
392
|
],
|