@kravc/dos 1.7.1 → 1.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kravc/dos",
3
- "version": "1.7.1",
3
+ "version": "1.7.2",
4
4
  "description": "Convention-based, easy-to-use library for building API-driven serverless services.",
5
5
  "keywords": [
6
6
  "Service",
@@ -20,7 +20,7 @@
20
20
  "src": "src"
21
21
  },
22
22
  "scripts": {
23
- "test": "eslint src/ examples/ && NODE_PATH=./ nyc mocha \"./src/**/*.spec.js\""
23
+ "test": "eslint src/ examples/ && NODE_APP_INSTANCE=test NODE_PATH=./ nyc mocha \"./src/**/*.spec.js\""
24
24
  },
25
25
  "author": "Alexander Kravets <a@kra.vc>",
26
26
  "license": "ISC",
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
 
3
+ const logRequest = require('./logRequest')
3
4
  const createContext = require('./createContext')
4
5
  const specMiddleware = require('./specMiddleware')
5
6
 
@@ -11,6 +12,8 @@ const handler = (service, _createContext = createContext, _middleware = specMidd
11
12
 
12
13
  if (result) { return result }
13
14
 
15
+ logRequest(context)
16
+
14
17
  return service.process(context)
15
18
  }
16
19
  }
@@ -0,0 +1,33 @@
1
+ 'use strict'
2
+
3
+ const isTestEnvironment = process.env.NODE_APP_INSTANCE === 'test'
4
+
5
+ const logRequest = context => {
6
+ if (isTestEnvironment) {
7
+ return
8
+ }
9
+
10
+ const {
11
+ operationId,
12
+ baseUrl,
13
+ query,
14
+ mutation,
15
+ requestId,
16
+ requestReceivedAt
17
+ } = context
18
+
19
+ const metadata = {
20
+ baseUrl,
21
+ requestId,
22
+ requestReceivedAt,
23
+ query,
24
+ }
25
+
26
+ if (mutation) {
27
+ metadata.mutation = mutation
28
+ }
29
+
30
+ console.log(operationId, metadata)
31
+ }
32
+
33
+ module.exports = logRequest