@centeredgesoft/runtime-mock-routes 2.10.1 → 2.10.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.
@@ -103,19 +103,26 @@ const appFactory = (runtimeCollection) => {
103
103
  if (process.env.LOG_MOCK_REQUESTS === 'true') {
104
104
  const logger = api_logs_1.logs.getLogger('mock-requests-logger');
105
105
  app.use((req, res, next) => {
106
- // log the request
106
+ let severity = api_logs_1.SeverityNumber.INFO;
107
+ let severityText = 'INFO';
108
+ // Log root requests as trace
109
+ if (req.path === '/') {
110
+ severity = api_logs_1.SeverityNumber.TRACE;
111
+ severityText = 'TRACE';
112
+ }
113
+ // Log the request
107
114
  logger.emit({
108
- severityNumber: api_logs_1.SeverityNumber.INFO,
109
- severityText: 'INFO',
115
+ severityNumber: severity,
116
+ severityText: severityText,
110
117
  body: `Request ${req.path}`,
111
118
  attributes: {
112
- 'http.headers': req.headers,
113
119
  'http.method': req.method,
114
120
  'http.url': req.url,
115
121
  'http.request_body': req.body,
122
+ 'http.request_headers': req.headers,
116
123
  }
117
124
  });
118
- // log the response
125
+ // Log the response
119
126
  const originalSend = res.send;
120
127
  let firstSend = true;
121
128
  res.send = function (body) {
@@ -123,14 +130,15 @@ const appFactory = (runtimeCollection) => {
123
130
  // For some reason send gets called twice per request, this ensures we only log once
124
131
  firstSend = false;
125
132
  logger.emit({
126
- severityNumber: api_logs_1.SeverityNumber.INFO,
127
- severityText: 'INFO',
133
+ severityNumber: severity,
134
+ severityText: severityText,
128
135
  body: `Response ${req.path}`,
129
136
  attributes: {
130
137
  'http.status_code': res.statusCode,
131
138
  'http.method': req.method,
132
139
  'http.url': req.url,
133
140
  'http.response_body': body,
141
+ 'http.response_headers': res.getHeaders()
134
142
  }
135
143
  });
136
144
  }
@@ -192,9 +200,12 @@ const appFactory = (runtimeCollection) => {
192
200
  headers: req.headers
193
201
  };
194
202
  if (method.status) {
195
- const status = typeof method.status === 'function'
203
+ let status = typeof method.status === 'function'
196
204
  ? method.status(tokenParams)
197
205
  : method.status;
206
+ if (typeof status === 'string') {
207
+ status = parseInt(status);
208
+ }
198
209
  res.status(status);
199
210
  }
200
211
  if (method.headers) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centeredgesoft/runtime-mock-routes",
3
- "version": "2.10.1",
3
+ "version": "2.10.3",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
package/src/appV2.ts CHANGED
@@ -121,20 +121,30 @@ export const appFactory = (runtimeCollection?: RuntimeRequestCollection) => {
121
121
  const logger = logs.getLogger('mock-requests-logger');
122
122
 
123
123
  app.use((req, res, next) => {
124
- // log the request
124
+
125
+ let severity = SeverityNumber.INFO;
126
+ let severityText = 'INFO';
127
+
128
+ // Log root requests as trace
129
+ if (req.path === '/') {
130
+ severity = SeverityNumber.TRACE;
131
+ severityText = 'TRACE';
132
+ }
133
+
134
+ // Log the request
125
135
  logger.emit({
126
- severityNumber: SeverityNumber.INFO,
127
- severityText: 'INFO',
136
+ severityNumber: severity,
137
+ severityText: severityText,
128
138
  body: `Request ${req.path}`,
129
139
  attributes: {
130
- 'http.headers': req.headers,
131
140
  'http.method': req.method,
132
141
  'http.url': req.url,
133
142
  'http.request_body': req.body,
143
+ 'http.request_headers': req.headers,
134
144
  }
135
145
  });
136
146
 
137
- // log the response
147
+ // Log the response
138
148
  const originalSend = res.send;
139
149
  let firstSend = true;
140
150
  res.send = function (body) {
@@ -143,14 +153,15 @@ export const appFactory = (runtimeCollection?: RuntimeRequestCollection) => {
143
153
  firstSend = false;
144
154
 
145
155
  logger.emit({
146
- severityNumber: SeverityNumber.INFO,
147
- severityText: 'INFO',
156
+ severityNumber: severity,
157
+ severityText: severityText,
148
158
  body: `Response ${req.path}`,
149
159
  attributes: {
150
160
  'http.status_code': res.statusCode,
151
161
  'http.method': req.method,
152
162
  'http.url': req.url,
153
163
  'http.response_body': body,
164
+ 'http.response_headers': res.getHeaders()
154
165
  }
155
166
  });
156
167
  }
@@ -245,9 +256,13 @@ export const appFactory = (runtimeCollection?: RuntimeRequestCollection) => {
245
256
  }
246
257
 
247
258
  if (method.status) {
248
- const status = typeof method.status === 'function'
249
- ? method.status(tokenParams)
250
- : method.status
259
+ let status = typeof method.status === 'function'
260
+ ? method.status(tokenParams)
261
+ : method.status
262
+
263
+ if (typeof status === 'string') {
264
+ status = parseInt(status);
265
+ }
251
266
 
252
267
  res.status(status);
253
268
  }
@@ -301,7 +316,7 @@ export const appFactory = (runtimeCollection?: RuntimeRequestCollection) => {
301
316
  app.put(/\/.*/, catchAllHandler);
302
317
  app.patch(/\/.*/, catchAllHandler);
303
318
  app.delete(/\/.*/, catchAllHandler);
304
-
319
+
305
320
  Object.defineProperty(app, 'runtimeRequestCollection', {
306
321
  get: () => {
307
322
  return cloneDeep(runtimeRequestCollection);