@centeredgesoft/runtime-mock-routes 2.3.0 → 2.7.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.
@@ -0,0 +1,16 @@
1
+ # See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/typescript-node/.devcontainer/base.Dockerfile
2
+
3
+ # [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 16, 14, 12, 16-bullseye, 14-bullseye, 12-bullseye, 16-buster, 14-buster, 12-buster
4
+ ARG VARIANT="16-bullseye"
5
+ FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT}
6
+
7
+ # [Optional] Uncomment this section to install additional OS packages.
8
+ # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
9
+ # && apt-get -y install --no-install-recommends <your-package-list-here>
10
+
11
+ # [Optional] Uncomment if you want to install an additional version of node using nvm
12
+ # ARG EXTRA_NODE_VERSION=10
13
+ # RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
14
+
15
+ # [Optional] Uncomment if you want to install more global node packages
16
+ # RUN su node -c "npm install -g <your-package-list -here>"
@@ -0,0 +1,32 @@
1
+ // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2
+ // https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/typescript-node
3
+ {
4
+ "name": "Node.js & TypeScript",
5
+ "build": {
6
+ "dockerfile": "Dockerfile",
7
+ // Update 'VARIANT' to pick a Node version: 16, 14, 12.
8
+ // Append -bullseye or -buster to pin to an OS version.
9
+ // Use -bullseye variants on local on arm64/Apple Silicon.
10
+ "args": {
11
+ "VARIANT": "16-bullseye"
12
+ }
13
+ },
14
+
15
+ // Set *default* container specific settings.json values on container create.
16
+ "settings": {},
17
+
18
+
19
+ // Add the IDs of extensions you want installed when the container is created.
20
+ "extensions": [
21
+ "dbaeumer.vscode-eslint"
22
+ ],
23
+
24
+ // Use 'forwardPorts' to make a list of ports inside the container available locally.
25
+ // "forwardPorts": [],
26
+
27
+ // Use 'postCreateCommand' to run commands after the container is created.
28
+ // "postCreateCommand": "yarn install",
29
+
30
+ // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
31
+ "remoteUser": "node"
32
+ }
package/README.md CHANGED
@@ -28,7 +28,7 @@ type SupportedMethod = SupportedMethodsType[number];
28
28
 
29
29
  export interface RuntimeRequestMethodBody {
30
30
  body: any;
31
- status?: number;
31
+ status?: any;
32
32
  headers?: Record<string, string>;
33
33
  }
34
34
 
@@ -4,7 +4,7 @@ export declare type SupportedMethod = SupportedMethodsType[number];
4
4
  export declare const isSupportedMethod: (obj: any) => obj is "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
5
5
  export interface RuntimeRequestMethodBody {
6
6
  body: any;
7
- status?: number;
7
+ status?: any;
8
8
  headers?: Record<string, string>;
9
9
  }
10
10
  export interface RequestParameters {
@@ -15,7 +15,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.appFactory = exports.isRuntimeRequestCollection = exports.isRuntimeRequestBody = exports.isRuntimeRequestMethodBodyCollection = exports.isRuntimeRequestMethodBody = exports.isSupportedMethod = exports.SupportedMethodsColection = void 0;
18
- const body_parser_1 = __importDefault(require("body-parser"));
19
18
  const chance_1 = __importDefault(require("chance"));
20
19
  const cors_1 = __importDefault(require("cors"));
21
20
  const express_1 = __importDefault(require("express"));
@@ -95,7 +94,9 @@ const appFactory = (runtimeCollection) => {
95
94
  }, {});
96
95
  const app = express_1.default();
97
96
  app.use(cors_1.default());
98
- app.use(body_parser_1.default.json());
97
+ app.use(express_1.default.json({
98
+ strict: false
99
+ }));
99
100
  app.get('/', (_req, res) => res.send(sort_keys_1.default(runtimeRequestCollection, { deep: true })));
100
101
  app.post('/', (req, res) => {
101
102
  const { body } = req;
@@ -149,7 +150,10 @@ const appFactory = (runtimeCollection) => {
149
150
  headers: req.headers
150
151
  };
151
152
  if (method.status) {
152
- res.status(method.status);
153
+ const status = typeof method.status === 'function'
154
+ ? method.status(tokenParams)
155
+ : method.status;
156
+ res.status(status);
153
157
  }
154
158
  if (method.headers) {
155
159
  const processedHeaders = Object.keys(method.headers).reduce((acc, curr) => (Object.assign(Object.assign({}, acc), { [curr]: handlebars_1.default.compile(method.headers[curr])(tokenParams) })), {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centeredgesoft/runtime-mock-routes",
3
- "version": "2.3.0",
3
+ "version": "2.7.0",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
@@ -23,7 +23,6 @@
23
23
  },
24
24
  "homepage": "https://github.com/CenterEdge/runtime-mock-routes#readme",
25
25
  "dependencies": {
26
- "body-parser": "^1.19.0",
27
26
  "chance": "^1.1.7",
28
27
  "commander": "^6.2.1",
29
28
  "cors": "^2.8.5",
@@ -35,7 +34,6 @@
35
34
  "sort-keys": "^4.2.0"
36
35
  },
37
36
  "devDependencies": {
38
- "@types/body-parser": "^1.19.0",
39
37
  "@types/chance": "^1.1.1",
40
38
  "@types/cors": "^2.8.9",
41
39
  "@types/express": "^4.17.11",
package/src/appV2.test.ts CHANGED
@@ -275,6 +275,32 @@ describe('Body as Function', () => {
275
275
  })
276
276
  });
277
277
 
278
+ describe('Request Body is Simple Type', () => {
279
+ test('Send in string as JSON', async () => {
280
+ const seed: RuntimeRequestCollection = {
281
+ "/test": {
282
+ path: "/test",
283
+ methods: {
284
+ POST: {
285
+ body: JSON.stringify(true),
286
+ status: 200
287
+ }
288
+ }
289
+ }
290
+ }
291
+
292
+ const app = appFactory(seed);
293
+ expect(app).toBeDefined();
294
+
295
+ var response = await request(app)
296
+ .post('/test?id=2')
297
+ .set('Content-type', 'application/json')
298
+ .send('"test"');
299
+
300
+ expect(response.body).toEqual(true);
301
+ })
302
+ });
303
+
278
304
  describe('isRuntimeRequestMethodBodyCollection', () => {
279
305
  test('is true for valid object', () => {
280
306
  const seed: RuntimeRequestCollection = {
package/src/appV2.ts CHANGED
@@ -1,4 +1,3 @@
1
- import bodyParser from 'body-parser';
2
1
  import Chance from 'chance';
3
2
  import cors from 'cors';
4
3
  import express, { Request, Response } from 'express';
@@ -36,7 +35,7 @@ export const isSupportedMethod = (obj: any): obj is SupportedMethod => Supported
36
35
 
37
36
  export interface RuntimeRequestMethodBody {
38
37
  body: any;
39
- status?: number;
38
+ status?: any;
40
39
  headers?: Record<string, string>;
41
40
  }
42
41
 
@@ -110,7 +109,9 @@ export const appFactory = (runtimeCollection?: RuntimeRequestCollection) => {
110
109
  const app = express();
111
110
 
112
111
  app.use(cors());
113
- app.use(bodyParser.json());
112
+ app.use(express.json({
113
+ strict: false
114
+ }));
114
115
 
115
116
  app.get('/', (_req, res) => res.send(sortKeys(runtimeRequestCollection, { deep: true })));
116
117
 
@@ -195,7 +196,11 @@ export const appFactory = (runtimeCollection?: RuntimeRequestCollection) => {
195
196
  }
196
197
 
197
198
  if (method.status) {
198
- res.status(method.status);
199
+ const status = typeof method.status === 'function'
200
+ ? method.status(tokenParams)
201
+ : method.status
202
+
203
+ res.status(status);
199
204
  }
200
205
 
201
206
  if (method.headers) {