@tramvai/module-http-client 1.41.0 → 1.41.2
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/index.browser.js +3 -79
- package/lib/index.d.ts +1 -1
- package/lib/papiClientModule.browser.d.ts +2 -0
- package/lib/papiClientModule.d.ts +2 -0
- package/package.json +10 -10
package/lib/index.browser.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __decorate } from 'tslib';
|
|
2
|
-
import { createToken
|
|
2
|
+
import { createToken } from '@tinkoff/dippy';
|
|
3
3
|
import { Module, provide, Scope, APP_INFO_TOKEN } from '@tramvai/core';
|
|
4
4
|
import { PAPI_SERVICE, HTTP_CLIENT_FACTORY, API_CLIENT_PASS_HEADERS, HTTP_CLIENT } from '@tramvai/tokens-http-client';
|
|
5
5
|
import { LOGGER_TOKEN, ENV_MANAGER_TOKEN, REQUEST_MANAGER_TOKEN, ENV_USED_TOKEN, CREATE_CACHE_TOKEN } from '@tramvai/tokens-common';
|
|
@@ -10,10 +10,6 @@ import { mergeOptions, createTinkoffRequest, HttpClientAdapter } from '@tramvai/
|
|
|
10
10
|
import { SERVER_MODULE_PAPI_PUBLIC_URL } from '@tramvai/tokens-server';
|
|
11
11
|
import prop from '@tinkoff/utils/object/prop';
|
|
12
12
|
import { ApiService } from '@tramvai/http-client';
|
|
13
|
-
import find from '@tinkoff/utils/array/find';
|
|
14
|
-
import flatten from '@tinkoff/utils/array/flatten';
|
|
15
|
-
import { getPapiParameters } from '@tramvai/papi';
|
|
16
|
-
import { REQUEST, RESPONSE } from '@tramvai/module-common';
|
|
17
13
|
|
|
18
14
|
const fillHeaders = (deps) => (params) => {
|
|
19
15
|
return params;
|
|
@@ -129,7 +125,7 @@ const httpClientFactory = ({ logger, envManager, appInfo, requestManager, header
|
|
|
129
125
|
};
|
|
130
126
|
};
|
|
131
127
|
|
|
132
|
-
class PapiService
|
|
128
|
+
class PapiService extends ApiService {
|
|
133
129
|
constructor({ httpClientFactory, baseUrl }) {
|
|
134
130
|
const httpClient = httpClientFactory({
|
|
135
131
|
name: 'papi',
|
|
@@ -159,7 +155,7 @@ PapiClientModule = __decorate([
|
|
|
159
155
|
provide({
|
|
160
156
|
provide: PAPI_SERVICE,
|
|
161
157
|
scope: Scope.SINGLETON,
|
|
162
|
-
useClass: PapiService
|
|
158
|
+
useClass: PapiService,
|
|
163
159
|
deps: {
|
|
164
160
|
httpClientFactory: HTTP_CLIENT_FACTORY,
|
|
165
161
|
baseUrl: SERVER_MODULE_PAPI_PUBLIC_URL,
|
|
@@ -259,76 +255,4 @@ HttpClientModule = __decorate([
|
|
|
259
255
|
})
|
|
260
256
|
], HttpClientModule);
|
|
261
257
|
|
|
262
|
-
class PapiService {
|
|
263
|
-
constructor({ papi, di }) {
|
|
264
|
-
this.papi = flatten(papi || []);
|
|
265
|
-
this.di = di;
|
|
266
|
-
}
|
|
267
|
-
async request({ path, query, body }) {
|
|
268
|
-
var _a;
|
|
269
|
-
const papiRoute = find((papi) => getPapiParameters(papi).path === `/${path}`, this.papi);
|
|
270
|
-
if (!papiRoute) {
|
|
271
|
-
throw new Error(`papi handler '${path}' not found`);
|
|
272
|
-
}
|
|
273
|
-
const papi = getPapiParameters(papiRoute);
|
|
274
|
-
let rootDeps = {};
|
|
275
|
-
if (papi.rootDeps) {
|
|
276
|
-
rootDeps = this.di.getOfDeps(papi.rootDeps);
|
|
277
|
-
rootDeps = papi.mapRootDeps ? papi.mapRootDeps(rootDeps) : rootDeps;
|
|
278
|
-
}
|
|
279
|
-
const childDI = createChildContainer(this.di);
|
|
280
|
-
const req = { headers: { host: 'localhost' }, cookies: {}, query, body };
|
|
281
|
-
const res = {};
|
|
282
|
-
childDI.register({
|
|
283
|
-
provide: REQUEST,
|
|
284
|
-
useValue: req,
|
|
285
|
-
});
|
|
286
|
-
childDI.register({
|
|
287
|
-
provide: RESPONSE,
|
|
288
|
-
useValue: res,
|
|
289
|
-
});
|
|
290
|
-
const payload = await getPapiParameters(papiRoute).handler({
|
|
291
|
-
...rootDeps,
|
|
292
|
-
...childDI.getOfDeps((_a = papi.deps) !== null && _a !== void 0 ? _a : {}),
|
|
293
|
-
req,
|
|
294
|
-
res,
|
|
295
|
-
});
|
|
296
|
-
return { payload, status: 200, headers: {} };
|
|
297
|
-
}
|
|
298
|
-
get(path, payload, config) {
|
|
299
|
-
return this.request({
|
|
300
|
-
path,
|
|
301
|
-
...payload,
|
|
302
|
-
...config,
|
|
303
|
-
method: 'GET',
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
post(path, payload, config) {
|
|
307
|
-
return this.request({
|
|
308
|
-
path,
|
|
309
|
-
requestType: 'json',
|
|
310
|
-
...payload,
|
|
311
|
-
...config,
|
|
312
|
-
method: 'POST',
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
put(path, payload, config) {
|
|
316
|
-
return this.request({
|
|
317
|
-
path,
|
|
318
|
-
requestType: 'json',
|
|
319
|
-
...payload,
|
|
320
|
-
...config,
|
|
321
|
-
method: 'PUT',
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
delete(path, payload, config) {
|
|
325
|
-
return this.request({
|
|
326
|
-
path,
|
|
327
|
-
...payload,
|
|
328
|
-
...config,
|
|
329
|
-
method: 'DELETE',
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
258
|
export { HttpClientModule, PapiService, fillHeaderIp, fillHeaders, formatError, httpClientFactory };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { HttpClientModule } from './httpClientModule';
|
|
2
2
|
export { httpClientFactory } from './httpClient/httpClientFactory';
|
|
3
|
-
export { PapiService } from './
|
|
3
|
+
export { PapiService } from './papiClientModule';
|
|
4
4
|
export { fillHeaderIp, fillHeaders } from './utils/fillHeaders';
|
|
5
5
|
export { formatError } from './utils/errors';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/module-http-client",
|
|
3
|
-
"version": "1.41.
|
|
3
|
+
"version": "1.41.2",
|
|
4
4
|
"initialVersion": "0.58.99",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -25,21 +25,21 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@tramvai/http-client": "0.1.23",
|
|
28
|
-
"@tramvai/tinkoff-request-http-client-adapter": "0.8.
|
|
29
|
-
"@tramvai/tokens-http-client": "1.41.
|
|
30
|
-
"@tramvai/tokens-common": "1.41.
|
|
31
|
-
"@tramvai/tokens-server": "1.41.
|
|
28
|
+
"@tramvai/tinkoff-request-http-client-adapter": "0.8.189",
|
|
29
|
+
"@tramvai/tokens-http-client": "1.41.2",
|
|
30
|
+
"@tramvai/tokens-common": "1.41.2",
|
|
31
|
+
"@tramvai/tokens-server": "1.41.2"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@tinkoff/request-core": "^0.8.9"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@tinkoff/utils": "^2.1.2",
|
|
38
|
-
"@tramvai/core": "1.41.
|
|
39
|
-
"@tramvai/module-common": "1.41.
|
|
40
|
-
"@tramvai/papi": "1.41.
|
|
41
|
-
"@tramvai/test-helpers": "1.41.
|
|
42
|
-
"@tramvai/test-mocks": "1.41.
|
|
38
|
+
"@tramvai/core": "1.41.2",
|
|
39
|
+
"@tramvai/module-common": "1.41.2",
|
|
40
|
+
"@tramvai/papi": "1.41.2",
|
|
41
|
+
"@tramvai/test-helpers": "1.41.2",
|
|
42
|
+
"@tramvai/test-mocks": "1.41.2",
|
|
43
43
|
"@tinkoff/dippy": "0.7.35",
|
|
44
44
|
"node-fetch": "^2.6.1",
|
|
45
45
|
"tslib": "^2.0.3"
|