@tramvai/module-http-client 2.7.1 → 2.20.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/README.md CHANGED
@@ -101,13 +101,13 @@ The `HTTP_CLIENT` token provides a basic client for sending requests to any URLs
101
101
  **Token use:**
102
102
 
103
103
  ```tsx
104
- import { createAction } from '@tramvai/core';
104
+ import { declareAction } from '@tramvai/core';
105
105
  import { HTTP_CLIENT } from '@tramvai/tokens-http-client';
106
106
 
107
- export const fetchAction = createAction({
107
+ export const fetchAction = declareAction({
108
108
  name: 'fetch',
109
- fn: async (_, __, { httpClient }) => {
110
- const { payload, headers, status } = await httpClient.get(
109
+ async fn() {
110
+ const { payload, headers, status } = await this.deps.httpClient.get(
111
111
  'https://www.domain.com/api/endpoint'
112
112
  );
113
113
  return payload;
@@ -1,9 +1,10 @@
1
1
  import type { MakeRequest } from '@tinkoff/request-core';
2
2
  import type { APP_INFO_TOKEN } from '@tramvai/core';
3
3
  import type { API_CLIENT_PASS_HEADERS, HttpClientFactoryOptions, HTTP_CLIENT_AGENT, HTTP_CLIENT_FACTORY, DISABLE_CIRCUIT_BREAKER } from '@tramvai/tokens-http-client';
4
- import type { LOGGER_TOKEN, CREATE_CACHE_TOKEN, ENV_MANAGER_TOKEN, REQUEST_MANAGER_TOKEN } from '@tramvai/tokens-common';
4
+ import type { LOGGER_TOKEN, CREATE_CACHE_TOKEN, ENV_MANAGER_TOKEN, REQUEST_MANAGER_TOKEN, COMMAND_LINE_EXECUTION_CONTEXT_TOKEN } from '@tramvai/tokens-common';
5
+ import type { QuerySerializer } from '@tinkoff/request-plugin-protocol-http';
5
6
  import type { ExtractDependencyType, ExtractTokenType } from '@tinkoff/dippy';
6
- export declare const httpClientFactory: ({ logger, envManager, appInfo, requestManager, headersList, createCache, makeRequestRegistry, agent, disableCircuitBreaker, defaultOptions, }: {
7
+ export declare const httpClientFactory: ({ logger, envManager, appInfo, requestManager, headersList, createCache, makeRequestRegistry, agent, querySerializer, disableCircuitBreaker, defaultOptions, commandLineExecutionContext, }: {
7
8
  logger: ExtractDependencyType<typeof LOGGER_TOKEN>;
8
9
  envManager: ExtractDependencyType<typeof ENV_MANAGER_TOKEN>;
9
10
  appInfo: ExtractDependencyType<typeof APP_INFO_TOKEN>;
@@ -12,6 +13,8 @@ export declare const httpClientFactory: ({ logger, envManager, appInfo, requestM
12
13
  createCache?: ExtractDependencyType<typeof CREATE_CACHE_TOKEN>;
13
14
  makeRequestRegistry: Map<string, MakeRequest>;
14
15
  agent?: ExtractDependencyType<typeof HTTP_CLIENT_AGENT>;
16
+ querySerializer?: QuerySerializer;
15
17
  disableCircuitBreaker: ExtractDependencyType<typeof DISABLE_CIRCUIT_BREAKER>;
16
18
  defaultOptions?: Partial<HttpClientFactoryOptions>;
19
+ commandLineExecutionContext?: ExtractDependencyType<typeof COMMAND_LINE_EXECUTION_CONTEXT_TOKEN>;
17
20
  }) => ExtractTokenType<typeof HTTP_CLIENT_FACTORY>;
@@ -2,7 +2,7 @@ import { createToken } from '@tinkoff/dippy';
2
2
  import { Module, provide, Scope, APP_INFO_TOKEN } from '@tramvai/core';
3
3
  import { PAPI_SERVICE, 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';
4
4
  export * from '@tramvai/tokens-http-client';
5
- import { LOGGER_TOKEN, ENV_MANAGER_TOKEN, REQUEST_MANAGER_TOKEN, ENV_USED_TOKEN, CREATE_CACHE_TOKEN } from '@tramvai/tokens-common';
5
+ import { LOGGER_TOKEN, ENV_MANAGER_TOKEN, REQUEST_MANAGER_TOKEN, COMMAND_LINE_EXECUTION_CONTEXT_TOKEN, ENV_USED_TOKEN, CREATE_CACHE_TOKEN } from '@tramvai/tokens-common';
6
6
  import isNil from '@tinkoff/utils/is/nil';
7
7
  import compose from '@tinkoff/utils/function/compose';
8
8
  import { mergeOptions, createTinkoffRequest, HttpClientAdapter } from '@tramvai/tinkoff-request-http-client-adapter';
@@ -38,8 +38,9 @@ const environmentDependentOptions = typeof window === 'undefined'
38
38
  : {
39
39
  defaultTimeout: 30000,
40
40
  };
41
- const httpClientFactory = ({ logger, envManager, appInfo, requestManager, headersList, createCache, makeRequestRegistry, agent, disableCircuitBreaker = false, defaultOptions, }) => {
41
+ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, headersList, createCache, makeRequestRegistry, agent, querySerializer, disableCircuitBreaker = false, defaultOptions, commandLineExecutionContext, }) => {
42
42
  return (options) => {
43
+ var _a;
43
44
  if (!options.name) {
44
45
  throw Error(`You need to pass a unique field "name" for the HTTP client instance`);
45
46
  }
@@ -48,6 +49,7 @@ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, header
48
49
  const adapterOptions = mergeOptions(mergeOptions({
49
50
  logger,
50
51
  agent,
52
+ querySerializer,
51
53
  method: 'GET',
52
54
  createCache: createCache
53
55
  ? (cacheOptions) => createCache('memory', cacheOptions)
@@ -57,6 +59,7 @@ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, header
57
59
  failureThreshold: 75,
58
60
  minimumFailureCount: 10,
59
61
  },
62
+ signal: (_a = commandLineExecutionContext === null || commandLineExecutionContext === void 0 ? void 0 : commandLineExecutionContext()) === null || _a === void 0 ? void 0 : _a.abortSignal,
60
63
  ...environmentDependentOptions,
61
64
  }, defaultOptions !== null && defaultOptions !== void 0 ? defaultOptions : {}), options);
62
65
  // по умолчанию, на сервере, библиотека https://github.com/node-fetch/node-fetch
@@ -162,6 +165,10 @@ const HttpClientModule = /* @__PURE__ */ Module({
162
165
  token: DEFAULT_HTTP_CLIENT_FACTORY_OPTIONS,
163
166
  optional: true,
164
167
  },
168
+ commandLineExecutionContext: {
169
+ token: COMMAND_LINE_EXECUTION_CONTEXT_TOKEN,
170
+ optional: true,
171
+ },
165
172
  },
166
173
  }),
167
174
  provide({
package/lib/index.es.js CHANGED
@@ -2,7 +2,7 @@ import { createChildContainer, createToken } from '@tinkoff/dippy';
2
2
  import { Module, provide, Scope, DI_TOKEN, APP_INFO_TOKEN } from '@tramvai/core';
3
3
  import { PAPI_SERVICE, 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';
4
4
  export * from '@tramvai/tokens-http-client';
5
- import { LOGGER_TOKEN, ENV_MANAGER_TOKEN, REQUEST_MANAGER_TOKEN, ENV_USED_TOKEN, CREATE_CACHE_TOKEN } from '@tramvai/tokens-common';
5
+ import { LOGGER_TOKEN, ENV_MANAGER_TOKEN, REQUEST_MANAGER_TOKEN, COMMAND_LINE_EXECUTION_CONTEXT_TOKEN, ENV_USED_TOKEN, CREATE_CACHE_TOKEN } from '@tramvai/tokens-common';
6
6
  import isNil from '@tinkoff/utils/is/nil';
7
7
  import compose from '@tinkoff/utils/function/compose';
8
8
  import { mergeOptions, createTinkoffRequest, HttpClientAdapter } from '@tramvai/tinkoff-request-http-client-adapter';
@@ -68,8 +68,9 @@ const environmentDependentOptions = typeof window === 'undefined'
68
68
  : {
69
69
  defaultTimeout: 30000,
70
70
  };
71
- const httpClientFactory = ({ logger, envManager, appInfo, requestManager, headersList, createCache, makeRequestRegistry, agent, disableCircuitBreaker = false, defaultOptions, }) => {
71
+ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, headersList, createCache, makeRequestRegistry, agent, querySerializer, disableCircuitBreaker = false, defaultOptions, commandLineExecutionContext, }) => {
72
72
  return (options) => {
73
+ var _a;
73
74
  if (!options.name) {
74
75
  throw Error(`You need to pass a unique field "name" for the HTTP client instance`);
75
76
  }
@@ -78,6 +79,7 @@ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, header
78
79
  const adapterOptions = mergeOptions(mergeOptions({
79
80
  logger,
80
81
  agent,
82
+ querySerializer,
81
83
  method: 'GET',
82
84
  createCache: createCache
83
85
  ? (cacheOptions) => createCache('memory', cacheOptions)
@@ -87,6 +89,7 @@ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, header
87
89
  failureThreshold: 75,
88
90
  minimumFailureCount: 10,
89
91
  },
92
+ signal: (_a = commandLineExecutionContext === null || commandLineExecutionContext === void 0 ? void 0 : commandLineExecutionContext()) === null || _a === void 0 ? void 0 : _a.abortSignal,
90
93
  ...environmentDependentOptions,
91
94
  }, defaultOptions !== null && defaultOptions !== void 0 ? defaultOptions : {}), options);
92
95
  // по умолчанию, на сервере, библиотека https://github.com/node-fetch/node-fetch
@@ -209,6 +212,10 @@ const HttpClientModule = /* @__PURE__ */ Module({
209
212
  token: DEFAULT_HTTP_CLIENT_FACTORY_OPTIONS,
210
213
  optional: true,
211
214
  },
215
+ commandLineExecutionContext: {
216
+ token: COMMAND_LINE_EXECUTION_CONTEXT_TOKEN,
217
+ optional: true,
218
+ },
212
219
  },
213
220
  }),
214
221
  provide({
package/lib/index.js CHANGED
@@ -79,8 +79,9 @@ const environmentDependentOptions = typeof window === 'undefined'
79
79
  : {
80
80
  defaultTimeout: 30000,
81
81
  };
82
- const httpClientFactory = ({ logger, envManager, appInfo, requestManager, headersList, createCache, makeRequestRegistry, agent, disableCircuitBreaker = false, defaultOptions, }) => {
82
+ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, headersList, createCache, makeRequestRegistry, agent, querySerializer, disableCircuitBreaker = false, defaultOptions, commandLineExecutionContext, }) => {
83
83
  return (options) => {
84
+ var _a;
84
85
  if (!options.name) {
85
86
  throw Error(`You need to pass a unique field "name" for the HTTP client instance`);
86
87
  }
@@ -89,6 +90,7 @@ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, header
89
90
  const adapterOptions = tinkoffRequestHttpClientAdapter.mergeOptions(tinkoffRequestHttpClientAdapter.mergeOptions({
90
91
  logger,
91
92
  agent,
93
+ querySerializer,
92
94
  method: 'GET',
93
95
  createCache: createCache
94
96
  ? (cacheOptions) => createCache('memory', cacheOptions)
@@ -98,6 +100,7 @@ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, header
98
100
  failureThreshold: 75,
99
101
  minimumFailureCount: 10,
100
102
  },
103
+ signal: (_a = commandLineExecutionContext === null || commandLineExecutionContext === void 0 ? void 0 : commandLineExecutionContext()) === null || _a === void 0 ? void 0 : _a.abortSignal,
101
104
  ...environmentDependentOptions,
102
105
  }, defaultOptions !== null && defaultOptions !== void 0 ? defaultOptions : {}), options);
103
106
  // по умолчанию, на сервере, библиотека https://github.com/node-fetch/node-fetch
@@ -220,6 +223,10 @@ const HttpClientModule = /* @__PURE__ */ core.Module({
220
223
  token: tokensHttpClient.DEFAULT_HTTP_CLIENT_FACTORY_OPTIONS,
221
224
  optional: true,
222
225
  },
226
+ commandLineExecutionContext: {
227
+ token: tokensCommon.COMMAND_LINE_EXECUTION_CONTEXT_TOKEN,
228
+ optional: true,
229
+ },
223
230
  },
224
231
  }),
225
232
  core.provide({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-http-client",
3
- "version": "2.7.1",
3
+ "version": "2.20.0",
4
4
  "initialVersion": "0.58.99",
5
5
  "description": "",
6
6
  "main": "lib/index.js",
@@ -24,23 +24,24 @@
24
24
  "build-for-publish": "true"
25
25
  },
26
26
  "dependencies": {
27
- "@tramvai/http-client": "0.1.28",
28
- "@tramvai/tinkoff-request-http-client-adapter": "0.9.24",
29
- "@tramvai/tokens-http-client": "2.7.1",
30
- "@tramvai/tokens-common": "2.7.1",
31
- "@tramvai/tokens-server": "2.7.1"
27
+ "@tramvai/http-client": "0.2.2",
28
+ "@tramvai/tinkoff-request-http-client-adapter": "0.9.51",
29
+ "@tramvai/tokens-http-client": "2.20.0",
30
+ "@tramvai/tokens-common": "2.20.0",
31
+ "@tramvai/tokens-server": "2.20.0"
32
32
  },
33
33
  "devDependencies": {
34
- "@tinkoff/request-core": "^0.9.2"
34
+ "@tinkoff/request-core": "^0.9.2",
35
+ "@tinkoff/request-plugin-protocol-http": "^0.11.6"
35
36
  },
36
37
  "peerDependencies": {
37
38
  "@tinkoff/utils": "^2.1.2",
38
- "@tramvai/core": "2.7.1",
39
- "@tramvai/module-common": "2.7.1",
40
- "@tramvai/papi": "2.7.1",
41
- "@tramvai/test-helpers": "2.7.1",
42
- "@tramvai/test-mocks": "2.7.1",
43
- "@tinkoff/dippy": "0.7.44",
39
+ "@tramvai/core": "2.20.0",
40
+ "@tramvai/module-common": "2.20.0",
41
+ "@tramvai/papi": "2.20.0",
42
+ "@tramvai/test-helpers": "2.20.0",
43
+ "@tramvai/test-mocks": "2.20.0",
44
+ "@tinkoff/dippy": "0.8.2",
44
45
  "node-fetch": "^2.6.1",
45
46
  "tslib": "^2.0.3"
46
47
  },