@contrast/route-coverage 1.13.0 → 1.14.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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright: 2023 Contrast Security, Inc
1
+ Copyright: 2024 Contrast Security, Inc
2
2
  Contact: support@contrastsecurity.com
3
3
  License: Commercial
4
4
 
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2023 Contrast Security, Inc
2
+ * Copyright: 2024 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2023 Contrast Security, Inc
2
+ * Copyright: 2024 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -83,6 +83,7 @@ module.exports = function init(core) {
83
83
  require('./install/http')(core);
84
84
  require('./install/express')(core);
85
85
  require('./install/fastify')(core);
86
+ require('./install/hapi')(core);
86
87
  require('./install/koa')(core);
87
88
 
88
89
  return routeCoverage;
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2023 Contrast Security, Inc
2
+ * Copyright: 2024 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2023 Contrast Security, Inc
2
+ * Copyright: 2024 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -0,0 +1,70 @@
1
+ /*
2
+ * Copyright: 2024 Contrast Security, Inc
3
+ * Contact: support@contrastsecurity.com
4
+ * License: Commercial
5
+
6
+ * NOTICE: This Software and the patented inventions embodied within may only be
7
+ * used as part of Contrast Security’s commercial offerings. Even though it is
8
+ * made available through public repositories, use of this Software is subject to
9
+ * the applicable End User Licensing Agreement found at
10
+ * https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
11
+ * between Contrast Security and the End User. The Software may not be reverse
12
+ * engineered, modified, repackaged, sold, redistributed or otherwise used in a
13
+ * way not consistent with the End User License Agreement.
14
+ */
15
+ 'use strict';
16
+
17
+ const { toLowerCase } = require('@contrast/common');
18
+ const { createSignature, patchType } = require('./../utils/route-info');
19
+
20
+ module.exports = function init(core) {
21
+ const { patcher, depHooks, routeCoverage } = core;
22
+
23
+ function emitRouteCoverage(url, method) {
24
+ method = toLowerCase(method);
25
+ const event = { signature: createSignature(url, method), url, method, normalizedUrl: url };
26
+ routeCoverage.discover(event);
27
+ }
28
+
29
+ return core.routeCoverage.hapi = {
30
+ install() {
31
+ return depHooks.resolve({ name: '@hapi/hapi', version: '>=18 <22' }, (hapi) => {
32
+ ['server', 'Server'].forEach((server) => {
33
+ patcher.patch(hapi, server, {
34
+ name: `hapi.${server}`,
35
+ patchType,
36
+ post(data) {
37
+ patcher.patch(data.result._core.router, 'add', {
38
+ name: '_core.router.add',
39
+ patchType,
40
+ post(data) {
41
+ if (!data.args[0] || !data.result) return;
42
+
43
+ const [{ method, path }] = data.args;
44
+ if (!method || !path) return;
45
+
46
+ if (Array.isArray(method)) {
47
+ method.forEach((verb) => {
48
+ emitRouteCoverage(path, verb);
49
+ });
50
+ } else {
51
+ emitRouteCoverage(path, method);
52
+ }
53
+
54
+ patcher.patch(data.result.route.settings, 'handler', {
55
+ name: 'route.settings.handler',
56
+ patchType,
57
+ post({ args }) {
58
+ const [{ method, path, route }] = args;
59
+ routeCoverage.observe({ url: path, method: toLowerCase(method), normalizedUrl: route.path });
60
+ }
61
+ });
62
+ }
63
+ });
64
+ }
65
+ });
66
+ });
67
+ });
68
+ }
69
+ };
70
+ };
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2023 Contrast Security, Inc
2
+ * Copyright: 2024 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2023 Contrast Security, Inc
2
+ * Copyright: 2024 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2023 Contrast Security, Inc
2
+ * Copyright: 2024 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/route-coverage",
3
- "version": "1.13.0",
3
+ "version": "1.14.0",
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)",
@@ -17,6 +17,7 @@
17
17
  "test": "../scripts/test.sh"
18
18
  },
19
19
  "dependencies": {
20
- "@contrast/common": "1.16.0"
20
+ "@contrast/common": "1.16.0",
21
+ "@contrast/fn-inspect": "^4.0.0"
21
22
  }
22
23
  }