@contrast/route-coverage 1.7.0 → 1.9.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.
@@ -28,6 +28,7 @@ const METHODS = [
28
28
  // eslint-disable-next-line node/no-extraneous-require
29
29
  const fnInspect = require('@contrast/fn-inspect');
30
30
  const { createSignature, patchType } = require('../utils/route-info');
31
+ const { join, replace, toLowerCase } = require('@contrast/common');
31
32
 
32
33
  /**
33
34
  * @param {import('..').Core & {
@@ -43,9 +44,9 @@ module.exports = function init(core) {
43
44
 
44
45
  function formatUrl(url) {
45
46
  if (Array.isArray(url)) {
46
- return `/[${url.join(', ')}]`;
47
+ return `/[${join(url, ', ')}]`;
47
48
  } else if (url instanceof RegExp) {
48
- return `/{${url.toString().replace(/(^\/?)|(\/?$)/g, '')}}`;
49
+ return `/{${replace(url.toString(), /(^\/?)|(\/?$)/g, '')}}`;
49
50
  } else {
50
51
  return url;
51
52
  }
@@ -75,7 +76,7 @@ module.exports = function init(core) {
75
76
  patchType,
76
77
  post(data) {
77
78
  const [req] = data.args;
78
- const method = req?.method?.toLowerCase();
79
+ const method = req?.method && toLowerCase(req.method);
79
80
  const url = `${req.baseUrl}${req._parsedUrl.pathname}`;
80
81
  const { signature } = signatureMap.get(route.signature);
81
82
  if (method) routeCoverage.observe({ signature, url, method });
@@ -16,6 +16,7 @@
16
16
  'use strict';
17
17
 
18
18
  const { createSignature } = require('./../utils/route-info');
19
+ const { toLowerCase } = require('@contrast/common');
19
20
 
20
21
  /** @typedef {Parameters<import('fastify3.0.0').onRouteHookHandler>[0]} RouteOptions */
21
22
 
@@ -67,7 +68,7 @@ module.exports = function init(core) {
67
68
  * @param {string} method
68
69
  */
69
70
  function emitRouteCoverage(url, method) {
70
- method = method.toLowerCase();
71
+ method = toLowerCase(method);
71
72
  const event = { signature: createSignature(url, method), url, method };
72
73
  routeCoverage.discover(event);
73
74
  }
@@ -77,7 +78,7 @@ module.exports = function init(core) {
77
78
  * @param {string=} method
78
79
  */
79
80
  function emitObservation(url, method) {
80
- method = method?.toLowerCase();
81
+ method = method && toLowerCase(method);
81
82
  routeCoverage.observe({ method, url });
82
83
  }
83
84
 
@@ -15,6 +15,7 @@
15
15
  'use strict';
16
16
 
17
17
  const { createSignature, patchType } = require('./../utils/route-info');
18
+ const { toLowerCase } = require('@contrast/common');
18
19
 
19
20
  module.exports = function init(core) {
20
21
  const { patcher, depHooks, routeCoverage } = core;
@@ -30,7 +31,7 @@ module.exports = function init(core) {
30
31
 
31
32
  if (req) {
32
33
  const { method } = req;
33
- routeCoverage.observe({ url: path, method: method.toLowerCase() });
34
+ routeCoverage.observe({ url: path, method: toLowerCase(method || '') });
34
35
  }
35
36
 
36
37
  await next();
@@ -50,7 +51,7 @@ module.exports = function init(core) {
50
51
  emitRouteCoverage(path, 'use');
51
52
  } else {
52
53
  methods.forEach((method) => {
53
- emitRouteCoverage(path, method.toLowerCase());
54
+ emitRouteCoverage(path, toLowerCase(method || ''));
54
55
  });
55
56
  }
56
57
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/route-coverage",
3
- "version": "1.7.0",
3
+ "version": "1.9.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.11.0"
17
+ "@contrast/common": "1.13.0"
18
18
  }
19
19
  }