@contrast/instrumentation 1.8.0 → 1.10.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/http.js CHANGED
@@ -14,6 +14,7 @@
14
14
  */
15
15
  'use strict';
16
16
 
17
+ const { StringPrototypeSubstring } = require('@contrast/common');
17
18
  const { get } = require('./utils');
18
19
 
19
20
  module.exports = function(core) {
@@ -27,6 +28,12 @@ module.exports = function(core) {
27
28
  patchObjects.forEach((obj) => {
28
29
  const { name, methods, around, patchType } = obj;
29
30
  methods.forEach((method) => {
31
+ const dotIdx = name.indexOf('.');
32
+ const firstName = dotIdx > -1 ? StringPrototypeSubstring.call(name, 0, dotIdx) : name;
33
+ // check for whether the target on the module exists first to avoid these Node warnings:
34
+ // (node:12155) Warning: Accessing non-existent property 'Server' of module exports inside circular dependency
35
+ if (!(firstName in module)) return;
36
+
30
37
  const patchObj = get(module, name);
31
38
  if (!patchObj) return;
32
39
 
@@ -46,8 +53,5 @@ module.exports = function(core) {
46
53
  'https'(opts) {
47
54
  hook('https', opts.patchObjects);
48
55
  },
49
- 'spdy'(opts) {
50
- hook('spdy', opts.patchObjects);
51
- }
52
56
  };
53
57
  };
package/lib/http2.js CHANGED
@@ -60,6 +60,17 @@ module.exports = function (core) {
60
60
  });
61
61
  });
62
62
  });
63
+ },
64
+ 'spdy'(opts) {
65
+ opts.patchObjects.forEach(({ methods, patchType, around }) => {
66
+ depHooks.resolve({ name: 'spdy', file: 'lib/spdy/server.js' }, (Server) => {
67
+ patcher.patch(Server, 'create', {
68
+ name: 'spdy.Server.create',
69
+ patchType,
70
+ post: createPostHook('spdy.Server.create', patchType, methods, around),
71
+ });
72
+ });
73
+ });
63
74
  }
64
75
  };
65
76
  };
package/lib/utils.js CHANGED
@@ -14,13 +14,13 @@
14
14
  */
15
15
  'use strict';
16
16
 
17
- const { split } = require('@contrast/common');
17
+ const { StringPrototypeSplit } = require('@contrast/common');
18
18
 
19
19
  function get(obj, name) {
20
20
  if (!name) return obj;
21
21
 
22
22
  let nest = obj;
23
- for (const prop of split(name, '.')) {
23
+ for (const prop of StringPrototypeSplit.call(name, '.')) {
24
24
  nest = nest?.[prop];
25
25
  if (nest === undefined) break;
26
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/instrumentation",
3
- "version": "1.8.0",
3
+ "version": "1.10.0",
4
4
  "description": "Shared hooks and patches between Protect and Assess components",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -11,12 +11,12 @@
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
  }
22
22
  }