@tramvai/module-http-client 2.22.0 → 2.24.3
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.es.js +25 -23
- package/lib/index.js +24 -22
- package/package.json +12 -11
- package/tests.js +24 -22
package/lib/index.es.js
CHANGED
|
@@ -14,7 +14,8 @@ import find from '@tinkoff/utils/array/find';
|
|
|
14
14
|
import { BaseHttpClient } from '@tramvai/http-client';
|
|
15
15
|
export * from '@tramvai/http-client';
|
|
16
16
|
import { getPapiParameters } from '@tramvai/papi';
|
|
17
|
-
import { REQUEST, RESPONSE } from '@tramvai/module-common';
|
|
17
|
+
import { REQUEST, RESPONSE, FASTIFY_REQUEST, FASTIFY_RESPONSE } from '@tramvai/module-common';
|
|
18
|
+
import { PAPI_EXECUTOR } from '@tramvai/tokens-server-private';
|
|
18
19
|
|
|
19
20
|
const fillHeaderIp = ({ requestManager, }) => {
|
|
20
21
|
if (!requestManager) {
|
|
@@ -132,34 +133,35 @@ class PapiService extends BaseHttpClient {
|
|
|
132
133
|
this.di = di;
|
|
133
134
|
}
|
|
134
135
|
async request({ path, query, body }) {
|
|
135
|
-
var _a;
|
|
136
136
|
const papiRoute = find((papi) => getPapiParameters(papi).path === `/${path}`, this.papi);
|
|
137
137
|
if (!papiRoute) {
|
|
138
138
|
throw new Error(`papi handler '${path}' not found`);
|
|
139
139
|
}
|
|
140
|
-
|
|
141
|
-
let rootDeps = {};
|
|
142
|
-
if (papi.rootDeps) {
|
|
143
|
-
rootDeps = this.di.getOfDeps(papi.rootDeps);
|
|
144
|
-
rootDeps = papi.mapRootDeps ? papi.mapRootDeps(rootDeps) : rootDeps;
|
|
145
|
-
}
|
|
146
|
-
const childDI = createChildContainer(this.di);
|
|
140
|
+
getPapiParameters(papiRoute);
|
|
147
141
|
const req = { headers: { host: 'localhost' }, cookies: {}, query, body };
|
|
148
142
|
const res = {};
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
143
|
+
const fastifyReq = { raw: req };
|
|
144
|
+
const fastifyRes = { raw: res };
|
|
145
|
+
const childDi = createChildContainer(this.di, [
|
|
146
|
+
{
|
|
147
|
+
provide: REQUEST,
|
|
148
|
+
useValue: req,
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
provide: RESPONSE,
|
|
152
|
+
useValue: res,
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
provide: FASTIFY_REQUEST,
|
|
156
|
+
useValue: fastifyReq,
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
provide: FASTIFY_RESPONSE,
|
|
160
|
+
useValue: fastifyRes,
|
|
161
|
+
},
|
|
162
|
+
]);
|
|
163
|
+
const papiExecutor = childDi.get(PAPI_EXECUTOR);
|
|
164
|
+
const payload = await papiExecutor(papiRoute);
|
|
163
165
|
return { payload, status: 200, headers: {} };
|
|
164
166
|
}
|
|
165
167
|
}
|
package/lib/index.js
CHANGED
|
@@ -17,6 +17,7 @@ var find = require('@tinkoff/utils/array/find');
|
|
|
17
17
|
var httpClient = require('@tramvai/http-client');
|
|
18
18
|
var papi = require('@tramvai/papi');
|
|
19
19
|
var moduleCommon = require('@tramvai/module-common');
|
|
20
|
+
var tokensServerPrivate = require('@tramvai/tokens-server-private');
|
|
20
21
|
|
|
21
22
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
22
23
|
|
|
@@ -143,34 +144,35 @@ class PapiService extends httpClient.BaseHttpClient {
|
|
|
143
144
|
this.di = di;
|
|
144
145
|
}
|
|
145
146
|
async request({ path, query, body }) {
|
|
146
|
-
var _a;
|
|
147
147
|
const papiRoute = find__default["default"]((papi$1) => papi.getPapiParameters(papi$1).path === `/${path}`, this.papi);
|
|
148
148
|
if (!papiRoute) {
|
|
149
149
|
throw new Error(`papi handler '${path}' not found`);
|
|
150
150
|
}
|
|
151
|
-
|
|
152
|
-
let rootDeps = {};
|
|
153
|
-
if (papi$1.rootDeps) {
|
|
154
|
-
rootDeps = this.di.getOfDeps(papi$1.rootDeps);
|
|
155
|
-
rootDeps = papi$1.mapRootDeps ? papi$1.mapRootDeps(rootDeps) : rootDeps;
|
|
156
|
-
}
|
|
157
|
-
const childDI = dippy.createChildContainer(this.di);
|
|
151
|
+
papi.getPapiParameters(papiRoute);
|
|
158
152
|
const req = { headers: { host: 'localhost' }, cookies: {}, query, body };
|
|
159
153
|
const res = {};
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
154
|
+
const fastifyReq = { raw: req };
|
|
155
|
+
const fastifyRes = { raw: res };
|
|
156
|
+
const childDi = dippy.createChildContainer(this.di, [
|
|
157
|
+
{
|
|
158
|
+
provide: moduleCommon.REQUEST,
|
|
159
|
+
useValue: req,
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
provide: moduleCommon.RESPONSE,
|
|
163
|
+
useValue: res,
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
provide: moduleCommon.FASTIFY_REQUEST,
|
|
167
|
+
useValue: fastifyReq,
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
provide: moduleCommon.FASTIFY_RESPONSE,
|
|
171
|
+
useValue: fastifyRes,
|
|
172
|
+
},
|
|
173
|
+
]);
|
|
174
|
+
const papiExecutor = childDi.get(tokensServerPrivate.PAPI_EXECUTOR);
|
|
175
|
+
const payload = await papiExecutor(papiRoute);
|
|
174
176
|
return { payload, status: 200, headers: {} };
|
|
175
177
|
}
|
|
176
178
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/module-http-client",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.24.3",
|
|
4
4
|
"initialVersion": "0.58.99",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -27,10 +27,11 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@tramvai/http-client": "0.2.2",
|
|
30
|
-
"@tramvai/tinkoff-request-http-client-adapter": "0.9.
|
|
31
|
-
"@tramvai/tokens-http-client": "2.
|
|
32
|
-
"@tramvai/tokens-common": "2.
|
|
33
|
-
"@tramvai/tokens-server": "2.
|
|
30
|
+
"@tramvai/tinkoff-request-http-client-adapter": "0.9.60",
|
|
31
|
+
"@tramvai/tokens-http-client": "2.24.3",
|
|
32
|
+
"@tramvai/tokens-common": "2.24.3",
|
|
33
|
+
"@tramvai/tokens-server": "2.24.3",
|
|
34
|
+
"@tramvai/tokens-server-private": "2.24.3"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@tinkoff/request-core": "^0.9.2",
|
|
@@ -38,12 +39,12 @@
|
|
|
38
39
|
},
|
|
39
40
|
"peerDependencies": {
|
|
40
41
|
"@tinkoff/utils": "^2.1.2",
|
|
41
|
-
"@tramvai/core": "2.
|
|
42
|
-
"@tramvai/module-common": "2.
|
|
43
|
-
"@tramvai/papi": "2.
|
|
44
|
-
"@tramvai/test-helpers": "2.
|
|
45
|
-
"@tramvai/test-mocks": "2.
|
|
46
|
-
"@tinkoff/dippy": "0.8.
|
|
42
|
+
"@tramvai/core": "2.24.3",
|
|
43
|
+
"@tramvai/module-common": "2.24.3",
|
|
44
|
+
"@tramvai/papi": "2.24.3",
|
|
45
|
+
"@tramvai/test-helpers": "2.24.3",
|
|
46
|
+
"@tramvai/test-mocks": "2.24.3",
|
|
47
|
+
"@tinkoff/dippy": "0.8.3",
|
|
47
48
|
"node-fetch": "^2.6.1",
|
|
48
49
|
"tslib": "^2.0.3"
|
|
49
50
|
},
|
package/tests.js
CHANGED
|
@@ -20,6 +20,7 @@ var find = require('@tinkoff/utils/array/find');
|
|
|
20
20
|
var httpClient = require('@tramvai/http-client');
|
|
21
21
|
var papi = require('@tramvai/papi');
|
|
22
22
|
var moduleCommon = require('@tramvai/module-common');
|
|
23
|
+
var tokensServerPrivate = require('@tramvai/tokens-server-private');
|
|
23
24
|
|
|
24
25
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
25
26
|
|
|
@@ -147,34 +148,35 @@ class PapiService extends httpClient.BaseHttpClient {
|
|
|
147
148
|
this.di = di;
|
|
148
149
|
}
|
|
149
150
|
async request({ path, query, body }) {
|
|
150
|
-
var _a;
|
|
151
151
|
const papiRoute = find__default["default"]((papi$1) => papi.getPapiParameters(papi$1).path === `/${path}`, this.papi);
|
|
152
152
|
if (!papiRoute) {
|
|
153
153
|
throw new Error(`papi handler '${path}' not found`);
|
|
154
154
|
}
|
|
155
|
-
|
|
156
|
-
let rootDeps = {};
|
|
157
|
-
if (papi$1.rootDeps) {
|
|
158
|
-
rootDeps = this.di.getOfDeps(papi$1.rootDeps);
|
|
159
|
-
rootDeps = papi$1.mapRootDeps ? papi$1.mapRootDeps(rootDeps) : rootDeps;
|
|
160
|
-
}
|
|
161
|
-
const childDI = dippy.createChildContainer(this.di);
|
|
155
|
+
papi.getPapiParameters(papiRoute);
|
|
162
156
|
const req = { headers: { host: 'localhost' }, cookies: {}, query, body };
|
|
163
157
|
const res = {};
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
158
|
+
const fastifyReq = { raw: req };
|
|
159
|
+
const fastifyRes = { raw: res };
|
|
160
|
+
const childDi = dippy.createChildContainer(this.di, [
|
|
161
|
+
{
|
|
162
|
+
provide: moduleCommon.REQUEST,
|
|
163
|
+
useValue: req,
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
provide: moduleCommon.RESPONSE,
|
|
167
|
+
useValue: res,
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
provide: moduleCommon.FASTIFY_REQUEST,
|
|
171
|
+
useValue: fastifyReq,
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
provide: moduleCommon.FASTIFY_RESPONSE,
|
|
175
|
+
useValue: fastifyRes,
|
|
176
|
+
},
|
|
177
|
+
]);
|
|
178
|
+
const papiExecutor = childDi.get(tokensServerPrivate.PAPI_EXECUTOR);
|
|
179
|
+
const payload = await papiExecutor(papiRoute);
|
|
178
180
|
return { payload, status: 200, headers: {} };
|
|
179
181
|
}
|
|
180
182
|
}
|