@tramvai/module-mocker 2.31.0 → 2.32.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/lib/server.es.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { __decorate } from 'tslib';
2
2
  import { Module, provide, commandLineListTokens, Scope } from '@tramvai/core';
3
3
  import { createPapiMethod } from '@tramvai/papi';
4
- import { LOGGER_TOKEN, ENV_MANAGER_TOKEN, FASTIFY_REQUEST, FASTIFY_RESPONSE } from '@tramvai/tokens-common';
4
+ import { LOGGER_TOKEN, ENV_MANAGER_TOKEN } from '@tramvai/tokens-common';
5
+ import { FASTIFY_REQUEST, FASTIFY_RESPONSE } from '@tramvai/tokens-server-private';
5
6
  import { SERVER_MODULE_PAPI_PUBLIC_URL, SERVER_MODULE_PAPI_PUBLIC_ROUTE } from '@tramvai/tokens-server';
6
7
  import { FileSystemMockRepository, Mocker } from '@tinkoff/mocker';
7
8
  import { createToken } from '@tinkoff/dippy';
@@ -13,6 +14,12 @@ const MOCKER_REPOSITORY = createToken('MOCKER_REPOSITORY', {
13
14
  const MOCKER_CONFIGURATION = createToken('MOCKER_CONFIGURATION');
14
15
 
15
16
  var MockerModule_1;
17
+ const compatibilityReq = (req) => {
18
+ const rawReq = req.raw;
19
+ rawReq.body = req.body;
20
+ rawReq.cookies = req.cookies;
21
+ return rawReq;
22
+ };
16
23
  let MockerModule = MockerModule_1 = class MockerModule {
17
24
  static forRoot({ config }) {
18
25
  const providers = [];
@@ -46,6 +53,10 @@ MockerModule = MockerModule_1 = __decorate([
46
53
  const mockedPath = `${papiPublicUrl}/mocker/${api}/`;
47
54
  const serverMockedUrl = `http://localhost:${envManager.get('PORT')}${mockedPath}`;
48
55
  const clientMockedUrl = `${mockedPath}`;
56
+ if (!target) {
57
+ log.warn(`Mocks for "${api}" were specified, but linked env variable was not found, ignoring these mocks.`);
58
+ return;
59
+ }
49
60
  apis[api] = { target };
50
61
  log.debug(`Mock ${env} env variable, current value is ${target}, replaced value is ${serverMockedUrl} for server and ${clientMockedUrl} for client`);
51
62
  const serverMockedEnv = {
@@ -135,9 +146,9 @@ MockerModule = MockerModule_1 = __decorate([
135
146
  path: '/mocker/*',
136
147
  async handler() {
137
148
  const { req, res } = this.deps;
138
- res.hijack();
139
149
  // TODO: fix compatibility
140
- mocker.use(req.raw, res.raw);
150
+ res.hijack();
151
+ mocker.use(compatibilityReq(req), res.raw);
141
152
  },
142
153
  deps: {
143
154
  req: FASTIFY_REQUEST,
@@ -160,7 +171,7 @@ MockerModule = MockerModule_1 = __decorate([
160
171
  const { req, res } = this.deps;
161
172
  // TODO: fix compatibility
162
173
  res.hijack();
163
- mocker.useApi(req.raw, res.raw);
174
+ mocker.useApi(compatibilityReq(req), res.raw);
164
175
  },
165
176
  deps: {
166
177
  req: FASTIFY_REQUEST,
package/lib/server.js CHANGED
@@ -6,6 +6,7 @@ var tslib = require('tslib');
6
6
  var core = require('@tramvai/core');
7
7
  var papi = require('@tramvai/papi');
8
8
  var tokensCommon = require('@tramvai/tokens-common');
9
+ var tokensServerPrivate = require('@tramvai/tokens-server-private');
9
10
  var tokensServer = require('@tramvai/tokens-server');
10
11
  var mocker = require('@tinkoff/mocker');
11
12
  var dippy = require('@tinkoff/dippy');
@@ -17,6 +18,12 @@ const MOCKER_REPOSITORY = dippy.createToken('MOCKER_REPOSITORY', {
17
18
  const MOCKER_CONFIGURATION = dippy.createToken('MOCKER_CONFIGURATION');
18
19
 
19
20
  var MockerModule_1;
21
+ const compatibilityReq = (req) => {
22
+ const rawReq = req.raw;
23
+ rawReq.body = req.body;
24
+ rawReq.cookies = req.cookies;
25
+ return rawReq;
26
+ };
20
27
  exports.MockerModule = MockerModule_1 = class MockerModule {
21
28
  static forRoot({ config }) {
22
29
  const providers = [];
@@ -50,6 +57,10 @@ exports.MockerModule = MockerModule_1 = tslib.__decorate([
50
57
  const mockedPath = `${papiPublicUrl}/mocker/${api}/`;
51
58
  const serverMockedUrl = `http://localhost:${envManager.get('PORT')}${mockedPath}`;
52
59
  const clientMockedUrl = `${mockedPath}`;
60
+ if (!target) {
61
+ log.warn(`Mocks for "${api}" were specified, but linked env variable was not found, ignoring these mocks.`);
62
+ return;
63
+ }
53
64
  apis[api] = { target };
54
65
  log.debug(`Mock ${env} env variable, current value is ${target}, replaced value is ${serverMockedUrl} for server and ${clientMockedUrl} for client`);
55
66
  const serverMockedEnv = {
@@ -139,13 +150,13 @@ exports.MockerModule = MockerModule_1 = tslib.__decorate([
139
150
  path: '/mocker/*',
140
151
  async handler() {
141
152
  const { req, res } = this.deps;
142
- res.hijack();
143
153
  // TODO: fix compatibility
144
- mocker.use(req.raw, res.raw);
154
+ res.hijack();
155
+ mocker.use(compatibilityReq(req), res.raw);
145
156
  },
146
157
  deps: {
147
- req: tokensCommon.FASTIFY_REQUEST,
148
- res: tokensCommon.FASTIFY_RESPONSE,
158
+ req: tokensServerPrivate.FASTIFY_REQUEST,
159
+ res: tokensServerPrivate.FASTIFY_RESPONSE,
149
160
  },
150
161
  });
151
162
  },
@@ -164,11 +175,11 @@ exports.MockerModule = MockerModule_1 = tslib.__decorate([
164
175
  const { req, res } = this.deps;
165
176
  // TODO: fix compatibility
166
177
  res.hijack();
167
- mocker.useApi(req.raw, res.raw);
178
+ mocker.useApi(compatibilityReq(req), res.raw);
168
179
  },
169
180
  deps: {
170
- req: tokensCommon.FASTIFY_REQUEST,
171
- res: tokensCommon.FASTIFY_RESPONSE,
181
+ req: tokensServerPrivate.FASTIFY_REQUEST,
182
+ res: tokensServerPrivate.FASTIFY_RESPONSE,
172
183
  },
173
184
  });
174
185
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-mocker",
3
- "version": "2.31.0",
3
+ "version": "2.32.0",
4
4
  "description": "",
5
5
  "main": "./lib/server.js",
6
6
  "browser": "./lib/browser.js",
@@ -24,10 +24,11 @@
24
24
  "tslib": "^2.4.0"
25
25
  },
26
26
  "peerDependencies": {
27
- "@tramvai/core": "2.31.0",
28
- "@tramvai/papi": "2.31.0",
29
- "@tramvai/tokens-common": "2.31.0",
30
- "@tramvai/tokens-server": "2.31.0",
27
+ "@tramvai/core": "2.32.0",
28
+ "@tramvai/papi": "2.32.0",
29
+ "@tramvai/tokens-common": "2.32.0",
30
+ "@tramvai/tokens-server": "2.32.0",
31
+ "@tramvai/tokens-server-private": "2.32.0",
31
32
  "@tinkoff/dippy": "0.8.6"
32
33
  },
33
34
  "license": "Apache-2.0"