@contrast/route-coverage 1.4.0 → 1.5.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/index.js CHANGED
@@ -52,6 +52,7 @@ module.exports = function init(core) {
52
52
  if (store && !store.route) {
53
53
  store.route = route;
54
54
  }
55
+
55
56
  // these events need source correlation
56
57
  messages.emit(Event.ROUTE_COVERAGE_OBSERVATION, {
57
58
  ...route,
@@ -17,33 +17,24 @@
17
17
  const { createSignature, patchType } = require('./../utils/route-info');
18
18
 
19
19
  module.exports = function init(core) {
20
- const { patcher, depHooks, routeCoverage, logger } = core;
20
+ const { patcher, depHooks, routeCoverage } = core;
21
21
 
22
22
  function emitRouteCoverage(url, method) {
23
23
  const event = { signature: createSignature(url, method), url, method };
24
24
  routeCoverage.discover(event);
25
25
  }
26
26
 
27
- function emitObservation(url, method) {
28
- routeCoverage.observe({ method, url });
29
- }
30
-
31
- async function routeObservationMiddleware(ctx, next) {
32
- const req = ctx.request;
27
+ const routeObservationPathClosure = ({ path }) =>
28
+ async function routeObservationMiddleware(ctx, next) {
29
+ const req = ctx.request;
33
30
 
34
- if (req) {
35
- const { url, method } = req;
36
- try {
37
- // Arbitrary basename needed to parse out path
38
- const parsedUrl = new URL(url, 'file://').pathname;
39
- emitObservation(parsedUrl, method.toLowerCase());
40
- } catch (err) {
41
- logger.error({ err, url }, 'failed to parse route');
31
+ if (req) {
32
+ const { method } = req;
33
+ routeCoverage.observe({ url: path, method: method.toLowerCase() });
42
34
  }
43
- }
44
35
 
45
- await next();
46
- }
36
+ await next();
37
+ };
47
38
 
48
39
  function registerRouteHandler(Router) {
49
40
  patcher.patch(Router.prototype, 'register', {
@@ -63,7 +54,7 @@ module.exports = function init(core) {
63
54
  });
64
55
  }
65
56
 
66
- layer.stack.unshift(routeObservationMiddleware.bind(this));
57
+ layer.stack.unshift(routeObservationPathClosure({ path }).bind(this));
67
58
  }
68
59
  });
69
60
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/route-coverage",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -14,6 +14,6 @@
14
14
  "test": "../scripts/test.sh"
15
15
  },
16
16
  "dependencies": {
17
- "@contrast/common": "1.8.0"
17
+ "@contrast/common": "1.9.0"
18
18
  }
19
19
  }