@contrast/route-coverage 1.20.4 → 1.20.6

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,7 +28,7 @@ const METHODS = [
28
28
 
29
29
  const fnInspect = require('@contrast/fn-inspect');
30
30
  const { createSignature, patchType } = require('../utils/route-info');
31
- const { join, toLowerCase, isString } = require('@contrast/common');
31
+ const { ArrayPrototypeJoin, StringPrototypeToLowerCase, isString } = require('@contrast/common');
32
32
 
33
33
  module.exports = function init(core) {
34
34
  const { patcher, depHooks, routeCoverage } = core;
@@ -36,10 +36,10 @@ module.exports = function init(core) {
36
36
  const observe = (route) => routeCoverage.observe(route);
37
37
 
38
38
  const isRoute = (layer) => !!layer.route;
39
- const isRouter = (layer) => layer.name && toLowerCase(layer.name) === 'router';
39
+ const isRouter = (layer) => layer.name && StringPrototypeToLowerCase.call(layer.name) === 'router';
40
40
  const isValidPath = (path) => isString(path) || Array.isArray(path) || path instanceof RegExp;
41
- const regExpToPath = (regex) => regex?.source?.split('/?')[0].replace(/\\/g, '').replace('^', ''); //TODO: replaceAll when v14 deprecated
42
- const format = (url) => Array.isArray(url) ? `/[${join(url)}]` : url instanceof RegExp ? `/{${url.toString().slice(1, -1)}}` : url;
41
+ const regExpToPath = (regex) => regex?.source?.split('/?')[0].replaceAll('\\', '').replace('^', '');
42
+ const format = (url) => Array.isArray(url) ? `/[${ArrayPrototypeJoin.call(url)}]` : url instanceof RegExp ? `/{${url.toString().slice(1, -1)}}` : url;
43
43
  const getHandleMethod = (layer) => fnInspect.funcInfo(layer.__handle)?.file.includes('express-async-errors') ? '__handle' : 'handle';
44
44
  const getLastLayer = (router) => router?.stack[router.stack.length - 1];
45
45
 
@@ -54,7 +54,8 @@ module.exports = function init(core) {
54
54
  signature: createSignature(url, method, obj),
55
55
  url,
56
56
  normalizedUrl: url,
57
- method
57
+ method,
58
+ framework: 'express'
58
59
  };
59
60
  }
60
61
 
@@ -68,13 +69,13 @@ module.exports = function init(core) {
68
69
  const [url] = req.originalUrl.split('?');
69
70
  const { method } = req;
70
71
  if (url && method) {
71
- observe({ ...routeInfo, url, method: toLowerCase(method) });
72
+ observe({ ...routeInfo, url, method: StringPrototypeToLowerCase.call(method) });
72
73
  }
73
74
  }
74
75
  });
75
76
  }
76
77
 
77
- function traverse(path = '', stack, depth = 0) {
78
+ function traverse(stack, path = '', depth = 0) {
78
79
  path = format(path);
79
80
  stack.forEach((layer) => {
80
81
  if (isRoute(layer)) {
@@ -84,7 +85,7 @@ module.exports = function init(core) {
84
85
  patchHandle(layer, routeInfo);
85
86
  } else if (isRouter(layer)) {
86
87
  const regexPath = regExpToPath(layer.regexp);
87
- if (depth < 3) traverse(path + regexPath, layer.handle.stack, depth += 1);
88
+ if (depth < 3) traverse(layer.handle.stack, path + regexPath, depth += 1);
88
89
  } else {
89
90
  const regexPath = regExpToPath(layer.regexp);
90
91
  const routeInfo = createRouteInfo(path + regexPath, 'use');
@@ -107,7 +108,7 @@ module.exports = function init(core) {
107
108
  const handlers = Array.isArray(fn) ? fn : [fn];
108
109
  handlers.forEach((layer) => {
109
110
  if (isRouter(layer)) {
110
- traverse(path, layer.stack);
111
+ traverse(layer.stack, path);
111
112
  } else if (path) {
112
113
  const routeInfo = createRouteInfo(format(path), 'use', 'App');
113
114
  discover(routeInfo);
@@ -16,7 +16,7 @@
16
16
  'use strict';
17
17
 
18
18
  const { createSignature } = require('./../utils/route-info');
19
- const { toLowerCase } = require('@contrast/common');
19
+ const { StringPrototypeToLowerCase } = require('@contrast/common');
20
20
 
21
21
  /** @typedef {Parameters<import('fastify-3.0.0').onRouteHookHandler>[0]} RouteOptions */
22
22
 
@@ -69,8 +69,8 @@ module.exports = function init(core) {
69
69
  * @param {string} method
70
70
  */
71
71
  function emitRouteCoverage(url, method) {
72
- method = toLowerCase(method);
73
- const event = { signature: createSignature(url, method), url, method, normalizedUrl: url };
72
+ method = StringPrototypeToLowerCase.call(method);
73
+ const event = { signature: createSignature(url, method), url, method, normalizedUrl: url, framework: 'fastify' };
74
74
  routeCoverage.discover(event);
75
75
  }
76
76
 
@@ -80,7 +80,7 @@ module.exports = function init(core) {
80
80
  * @param {string=} method
81
81
  */
82
82
  function emitObservation(url, normalizedUrl, method) {
83
- method = method && toLowerCase(method);
83
+ method = method && StringPrototypeToLowerCase.call(method);
84
84
  routeCoverage.observe({ method, url, normalizedUrl });
85
85
  }
86
86
 
@@ -14,15 +14,15 @@
14
14
  */
15
15
  'use strict';
16
16
 
17
- const { toLowerCase } = require('@contrast/common');
17
+ const { StringPrototypeToLowerCase } = require('@contrast/common');
18
18
  const { createSignature, patchType } = require('./../utils/route-info');
19
19
 
20
20
  module.exports = function init(core) {
21
21
  const { patcher, depHooks, routeCoverage } = core;
22
22
 
23
23
  function emitRouteCoverage(url, method) {
24
- method = toLowerCase(method);
25
- const event = { signature: createSignature(url, method), url, method, normalizedUrl: url };
24
+ method = StringPrototypeToLowerCase.call(method);
25
+ const event = { signature: createSignature(url, method), url, method, normalizedUrl: url, framework: 'hapi' };
26
26
  routeCoverage.discover(event);
27
27
  }
28
28
 
@@ -56,7 +56,7 @@ module.exports = function init(core) {
56
56
  patchType,
57
57
  post({ args }) {
58
58
  const [{ method, path, route }] = args;
59
- routeCoverage.observe({ url: path, method: toLowerCase(method), normalizedUrl: route.path });
59
+ routeCoverage.observe({ url: path, method: StringPrototypeToLowerCase.call(method), normalizedUrl: route.path });
60
60
  }
61
61
  });
62
62
  }
@@ -14,14 +14,14 @@
14
14
  */
15
15
  'use strict';
16
16
 
17
- const { toLowerCase } = require('@contrast/common');
17
+ const { StringPrototypeToLowerCase } = require('@contrast/common');
18
18
  const { createSignature, patchType } = require('./../utils/route-info');
19
19
 
20
20
  module.exports = function init(core) {
21
21
  const { patcher, depHooks, routeCoverage } = core;
22
22
 
23
23
  function emitRouteCoverage(url, method) {
24
- const event = { signature: createSignature(url, method), url, method, normalizedUrl: url };
24
+ const event = { signature: createSignature(url, method), url, method, normalizedUrl: url, framework: 'koa' };
25
25
  routeCoverage.discover(event);
26
26
  }
27
27
 
@@ -32,7 +32,7 @@ module.exports = function init(core) {
32
32
  if (req) {
33
33
  const { url: reqUrl, method } = req;
34
34
  const [url] = reqUrl.split(/\?/);
35
- routeCoverage.observe({ url, method: toLowerCase(method || ''), normalizedUrl: path });
35
+ routeCoverage.observe({ url, method: StringPrototypeToLowerCase.call(method || ''), normalizedUrl: path });
36
36
  }
37
37
 
38
38
  await next();
@@ -57,7 +57,7 @@ module.exports = function init(core) {
57
57
  emitRouteCoverage(path, 'use');
58
58
  } else {
59
59
  methods.forEach((method) => {
60
- emitRouteCoverage(path, toLowerCase(method || ''));
60
+ emitRouteCoverage(path, StringPrototypeToLowerCase.call(method || ''));
61
61
  });
62
62
  }
63
63
 
@@ -14,7 +14,7 @@
14
14
  */
15
15
  'use strict';
16
16
 
17
- const { toLowerCase, isString } = require('@contrast/common');
17
+ const { StringPrototypeToLowerCase, isString } = require('@contrast/common');
18
18
  const { createSignature, patchType } = require('../utils/route-info');
19
19
 
20
20
  module.exports = function init(core) {
@@ -23,12 +23,13 @@ module.exports = function init(core) {
23
23
  const observe = (route) => routeCoverage.observe(route);
24
24
 
25
25
  function createRoute(url, method) {
26
- method = toLowerCase(method);
26
+ method = StringPrototypeToLowerCase.call(method);
27
27
  return {
28
28
  signature: createSignature(url, method, 'Server'),
29
29
  method,
30
30
  url,
31
- normalizedUrl: url
31
+ normalizedUrl: url,
32
+ framework: 'restify'
32
33
  };
33
34
  }
34
35
 
@@ -56,7 +57,7 @@ module.exports = function init(core) {
56
57
  const [req] = args;
57
58
  const { url: reqUrl, method } = req;
58
59
  const [url] = reqUrl.split('?');
59
- observe({ ...routeInfo, method: toLowerCase(method), url });
60
+ observe({ ...routeInfo, method: StringPrototypeToLowerCase.call(method), url });
60
61
  }
61
62
  });
62
63
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/route-coverage",
3
- "version": "1.20.4",
3
+ "version": "1.20.6",
4
4
  "description": "Handles route discovery and observation",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -11,13 +11,13 @@
11
11
  "types": "lib/index.d.ts",
12
12
  "engines": {
13
13
  "npm": ">=6.13.7 <7 || >= 8.3.1",
14
- "node": ">= 14.18.0"
14
+ "node": ">= 16.9.1"
15
15
  },
16
16
  "scripts": {
17
17
  "test": "../scripts/test.sh"
18
18
  },
19
19
  "dependencies": {
20
- "@contrast/common": "1.21.0",
20
+ "@contrast/common": "1.21.2",
21
21
  "@contrast/fn-inspect": "^4.0.0"
22
22
  }
23
23
  }