@tramvai/tinkoff-request-http-client-adapter 0.8.240 → 0.8.246
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/httpClientAdapter.d.ts +2 -5
- package/lib/index.browser.js +12 -53
- package/lib/index.es.js +12 -53
- package/lib/index.js +12 -53
- package/package.json +3 -3
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { MakeRequest } from '@tinkoff/request-core';
|
|
2
|
+
import { BaseHttpClient } from '@tramvai/http-client';
|
|
2
3
|
import type { HttpClient, HttpClientBaseOptions, HttpClientRequest, HttpClientResponse } from '@tramvai/http-client';
|
|
3
|
-
export declare class HttpClientAdapter implements HttpClient {
|
|
4
|
+
export declare class HttpClientAdapter extends BaseHttpClient implements HttpClient {
|
|
4
5
|
private options;
|
|
5
6
|
private tinkoffRequest;
|
|
6
7
|
constructor({ options, tinkoffRequest, }: {
|
|
@@ -8,10 +9,6 @@ export declare class HttpClientAdapter implements HttpClient {
|
|
|
8
9
|
tinkoffRequest: MakeRequest;
|
|
9
10
|
});
|
|
10
11
|
request<R = any>(req: HttpClientRequest): Promise<HttpClientResponse<R>>;
|
|
11
|
-
get(path: string, payload?: Pick<HttpClientRequest, 'query' | 'headers'>, config?: Omit<HttpClientRequest, 'url' | 'query' | 'body' | 'headers'>): Promise<HttpClientResponse<any>>;
|
|
12
|
-
post<R = any>(path: string, payload?: Pick<HttpClientRequest, 'query' | 'body' | 'headers'>, config?: Omit<HttpClientRequest, 'url' | 'query' | 'body' | 'headers'>): Promise<HttpClientResponse<R>>;
|
|
13
|
-
put<R = any>(path: string, payload?: Pick<HttpClientRequest, 'query' | 'body' | 'headers'>, config?: Omit<HttpClientRequest, 'url' | 'query' | 'body' | 'headers'>): Promise<HttpClientResponse<R>>;
|
|
14
|
-
delete<R = any>(path: string, payload?: Pick<HttpClientRequest, 'query' | 'headers'>, config?: Omit<HttpClientRequest, 'url' | 'query' | 'body' | 'headers'>): Promise<HttpClientResponse<R>>;
|
|
15
12
|
fork(forkOptions?: HttpClientRequest, mergeOptionsConfig?: {
|
|
16
13
|
replace?: boolean;
|
|
17
14
|
}): HttpClientAdapter;
|
package/lib/index.browser.js
CHANGED
|
@@ -7,6 +7,7 @@ import validate from '@tinkoff/request-plugin-validate';
|
|
|
7
7
|
import http, { isServerError, isNetworkFail, getStatus, getHeaders } from '@tinkoff/request-plugin-protocol-http';
|
|
8
8
|
import transformUrl from '@tinkoff/request-plugin-transform-url';
|
|
9
9
|
import circuitBreaker from '@tinkoff/request-plugin-circuit-breaker';
|
|
10
|
+
import { BaseHttpClient } from '@tramvai/http-client';
|
|
10
11
|
import compose from '@tinkoff/utils/function/compose';
|
|
11
12
|
|
|
12
13
|
const createAgent = () => { };
|
|
@@ -123,29 +124,21 @@ function mergeOptions(options, nextOptions, config) {
|
|
|
123
124
|
...nextOptions.headers,
|
|
124
125
|
},
|
|
125
126
|
};
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
? compose(nextOptions.modifyResponse, options.modifyResponse)
|
|
136
|
-
: nextOptions.modifyResponse || options.modifyResponse;
|
|
137
|
-
}
|
|
138
|
-
if (nextOptions.modifyError || options.modifyError) {
|
|
139
|
-
result.modifyError =
|
|
140
|
-
options.modifyError && nextOptions.modifyError
|
|
141
|
-
? compose(nextOptions.modifyError, options.modifyError)
|
|
142
|
-
: nextOptions.modifyError || options.modifyError;
|
|
143
|
-
}
|
|
127
|
+
const composeModifier = (modifier) => {
|
|
128
|
+
if (options[modifier] && nextOptions[modifier]) {
|
|
129
|
+
// eslint-disable-next-line no-param-reassign
|
|
130
|
+
result[modifier] = compose(nextOptions[modifier], options[modifier]);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
composeModifier('modifyRequest');
|
|
134
|
+
composeModifier('modifyResponse');
|
|
135
|
+
composeModifier('modifyError');
|
|
144
136
|
return result;
|
|
145
137
|
}
|
|
146
138
|
|
|
147
|
-
class HttpClientAdapter {
|
|
139
|
+
class HttpClientAdapter extends BaseHttpClient {
|
|
148
140
|
constructor({ options, tinkoffRequest, }) {
|
|
141
|
+
super();
|
|
149
142
|
this.options = options;
|
|
150
143
|
this.tinkoffRequest = tinkoffRequest;
|
|
151
144
|
}
|
|
@@ -184,40 +177,6 @@ class HttpClientAdapter {
|
|
|
184
177
|
throw modifyError ? modifyError(errorWithMeta, adaptedReq) : errorWithMeta;
|
|
185
178
|
}
|
|
186
179
|
}
|
|
187
|
-
get(path, payload = {}, config = {}) {
|
|
188
|
-
return this.request({
|
|
189
|
-
path,
|
|
190
|
-
...payload,
|
|
191
|
-
...config,
|
|
192
|
-
method: 'GET',
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
post(path, payload, config) {
|
|
196
|
-
return this.request({
|
|
197
|
-
path,
|
|
198
|
-
requestType: 'json',
|
|
199
|
-
...payload,
|
|
200
|
-
...config,
|
|
201
|
-
method: 'POST',
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
put(path, payload, config) {
|
|
205
|
-
return this.request({
|
|
206
|
-
path,
|
|
207
|
-
requestType: 'json',
|
|
208
|
-
...payload,
|
|
209
|
-
...config,
|
|
210
|
-
method: 'PUT',
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
delete(path, payload = {}, config = {}) {
|
|
214
|
-
return this.request({
|
|
215
|
-
path,
|
|
216
|
-
...payload,
|
|
217
|
-
...config,
|
|
218
|
-
method: 'DELETE',
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
180
|
fork(forkOptions = {}, mergeOptionsConfig = {}) {
|
|
222
181
|
return new HttpClientAdapter({
|
|
223
182
|
options: mergeOptions(this.options, forkOptions, mergeOptionsConfig),
|
package/lib/index.es.js
CHANGED
|
@@ -9,6 +9,7 @@ import transformUrl from '@tinkoff/request-plugin-transform-url';
|
|
|
9
9
|
import circuitBreaker from '@tinkoff/request-plugin-circuit-breaker';
|
|
10
10
|
import http from 'http';
|
|
11
11
|
import https from 'https';
|
|
12
|
+
import { BaseHttpClient } from '@tramvai/http-client';
|
|
12
13
|
import compose from '@tinkoff/utils/function/compose';
|
|
13
14
|
|
|
14
15
|
const createAgent = (options = {
|
|
@@ -133,29 +134,21 @@ function mergeOptions(options, nextOptions, config) {
|
|
|
133
134
|
...nextOptions.headers,
|
|
134
135
|
},
|
|
135
136
|
};
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
? compose(nextOptions.modifyResponse, options.modifyResponse)
|
|
146
|
-
: nextOptions.modifyResponse || options.modifyResponse;
|
|
147
|
-
}
|
|
148
|
-
if (nextOptions.modifyError || options.modifyError) {
|
|
149
|
-
result.modifyError =
|
|
150
|
-
options.modifyError && nextOptions.modifyError
|
|
151
|
-
? compose(nextOptions.modifyError, options.modifyError)
|
|
152
|
-
: nextOptions.modifyError || options.modifyError;
|
|
153
|
-
}
|
|
137
|
+
const composeModifier = (modifier) => {
|
|
138
|
+
if (options[modifier] && nextOptions[modifier]) {
|
|
139
|
+
// eslint-disable-next-line no-param-reassign
|
|
140
|
+
result[modifier] = compose(nextOptions[modifier], options[modifier]);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
composeModifier('modifyRequest');
|
|
144
|
+
composeModifier('modifyResponse');
|
|
145
|
+
composeModifier('modifyError');
|
|
154
146
|
return result;
|
|
155
147
|
}
|
|
156
148
|
|
|
157
|
-
class HttpClientAdapter {
|
|
149
|
+
class HttpClientAdapter extends BaseHttpClient {
|
|
158
150
|
constructor({ options, tinkoffRequest, }) {
|
|
151
|
+
super();
|
|
159
152
|
this.options = options;
|
|
160
153
|
this.tinkoffRequest = tinkoffRequest;
|
|
161
154
|
}
|
|
@@ -194,40 +187,6 @@ class HttpClientAdapter {
|
|
|
194
187
|
throw modifyError ? modifyError(errorWithMeta, adaptedReq) : errorWithMeta;
|
|
195
188
|
}
|
|
196
189
|
}
|
|
197
|
-
get(path, payload = {}, config = {}) {
|
|
198
|
-
return this.request({
|
|
199
|
-
path,
|
|
200
|
-
...payload,
|
|
201
|
-
...config,
|
|
202
|
-
method: 'GET',
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
post(path, payload, config) {
|
|
206
|
-
return this.request({
|
|
207
|
-
path,
|
|
208
|
-
requestType: 'json',
|
|
209
|
-
...payload,
|
|
210
|
-
...config,
|
|
211
|
-
method: 'POST',
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
put(path, payload, config) {
|
|
215
|
-
return this.request({
|
|
216
|
-
path,
|
|
217
|
-
requestType: 'json',
|
|
218
|
-
...payload,
|
|
219
|
-
...config,
|
|
220
|
-
method: 'PUT',
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
delete(path, payload = {}, config = {}) {
|
|
224
|
-
return this.request({
|
|
225
|
-
path,
|
|
226
|
-
...payload,
|
|
227
|
-
...config,
|
|
228
|
-
method: 'DELETE',
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
190
|
fork(forkOptions = {}, mergeOptionsConfig = {}) {
|
|
232
191
|
return new HttpClientAdapter({
|
|
233
192
|
options: mergeOptions(this.options, forkOptions, mergeOptionsConfig),
|
package/lib/index.js
CHANGED
|
@@ -13,6 +13,7 @@ var transformUrl = require('@tinkoff/request-plugin-transform-url');
|
|
|
13
13
|
var circuitBreaker = require('@tinkoff/request-plugin-circuit-breaker');
|
|
14
14
|
var http = require('http');
|
|
15
15
|
var https = require('https');
|
|
16
|
+
var httpClient = require('@tramvai/http-client');
|
|
16
17
|
var compose = require('@tinkoff/utils/function/compose');
|
|
17
18
|
|
|
18
19
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -152,29 +153,21 @@ function mergeOptions(options, nextOptions, config) {
|
|
|
152
153
|
...nextOptions.headers,
|
|
153
154
|
},
|
|
154
155
|
};
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
? compose__default["default"](nextOptions.modifyResponse, options.modifyResponse)
|
|
165
|
-
: nextOptions.modifyResponse || options.modifyResponse;
|
|
166
|
-
}
|
|
167
|
-
if (nextOptions.modifyError || options.modifyError) {
|
|
168
|
-
result.modifyError =
|
|
169
|
-
options.modifyError && nextOptions.modifyError
|
|
170
|
-
? compose__default["default"](nextOptions.modifyError, options.modifyError)
|
|
171
|
-
: nextOptions.modifyError || options.modifyError;
|
|
172
|
-
}
|
|
156
|
+
const composeModifier = (modifier) => {
|
|
157
|
+
if (options[modifier] && nextOptions[modifier]) {
|
|
158
|
+
// eslint-disable-next-line no-param-reassign
|
|
159
|
+
result[modifier] = compose__default["default"](nextOptions[modifier], options[modifier]);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
composeModifier('modifyRequest');
|
|
163
|
+
composeModifier('modifyResponse');
|
|
164
|
+
composeModifier('modifyError');
|
|
173
165
|
return result;
|
|
174
166
|
}
|
|
175
167
|
|
|
176
|
-
class HttpClientAdapter {
|
|
168
|
+
class HttpClientAdapter extends httpClient.BaseHttpClient {
|
|
177
169
|
constructor({ options, tinkoffRequest, }) {
|
|
170
|
+
super();
|
|
178
171
|
this.options = options;
|
|
179
172
|
this.tinkoffRequest = tinkoffRequest;
|
|
180
173
|
}
|
|
@@ -213,40 +206,6 @@ class HttpClientAdapter {
|
|
|
213
206
|
throw modifyError ? modifyError(errorWithMeta, adaptedReq) : errorWithMeta;
|
|
214
207
|
}
|
|
215
208
|
}
|
|
216
|
-
get(path, payload = {}, config = {}) {
|
|
217
|
-
return this.request({
|
|
218
|
-
path,
|
|
219
|
-
...payload,
|
|
220
|
-
...config,
|
|
221
|
-
method: 'GET',
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
post(path, payload, config) {
|
|
225
|
-
return this.request({
|
|
226
|
-
path,
|
|
227
|
-
requestType: 'json',
|
|
228
|
-
...payload,
|
|
229
|
-
...config,
|
|
230
|
-
method: 'POST',
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
put(path, payload, config) {
|
|
234
|
-
return this.request({
|
|
235
|
-
path,
|
|
236
|
-
requestType: 'json',
|
|
237
|
-
...payload,
|
|
238
|
-
...config,
|
|
239
|
-
method: 'PUT',
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
delete(path, payload = {}, config = {}) {
|
|
243
|
-
return this.request({
|
|
244
|
-
path,
|
|
245
|
-
...payload,
|
|
246
|
-
...config,
|
|
247
|
-
method: 'DELETE',
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
209
|
fork(forkOptions = {}, mergeOptionsConfig = {}) {
|
|
251
210
|
return new HttpClientAdapter({
|
|
252
211
|
options: mergeOptions(this.options, forkOptions, mergeOptionsConfig),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/tinkoff-request-http-client-adapter",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.246",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"browser": {
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"@tinkoff/request-plugin-transform-url": "^0.8.8",
|
|
31
31
|
"@tinkoff/request-plugin-validate": "^0.8.8",
|
|
32
32
|
"@tinkoff/utils": "^2.1.2",
|
|
33
|
-
"@tramvai/http-client": "0.1.
|
|
34
|
-
"@tramvai/tokens-common": "1.
|
|
33
|
+
"@tramvai/http-client": "0.1.25",
|
|
34
|
+
"@tramvai/tokens-common": "1.58.0",
|
|
35
35
|
"tslib": "^2.0.3"
|
|
36
36
|
},
|
|
37
37
|
"sideEffects": false,
|