@contrast/agentify 1.33.0 → 1.34.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/utils.js CHANGED
@@ -33,6 +33,7 @@ const { primordials: { StringPrototypeSlice, StringPrototypeSplit, StringPrototy
33
33
  * @param {string} core.nodeEngines
34
34
  */
35
35
  function preStartupValidation(core) {
36
+ assertNoExperimentalFeatureFlags();
36
37
  assertSupportedNodeVersion(core.nodeEngines || nodeEngines);
37
38
  assertSupportedPreloadUsage();
38
39
  }
@@ -56,6 +57,22 @@ function assertSupportedNodeVersion(engines) {
56
57
  }
57
58
  }
58
59
 
60
+ /**
61
+ * Checks that no experimental feature flags are used.
62
+ * @throws {Error}
63
+ */
64
+ function assertNoExperimentalFeatureFlags() {
65
+ const {
66
+ execArgv,
67
+ env: { NODE_OPTIONS },
68
+ } = process;
69
+
70
+ if (execArgv.some(arg => arg.includes('--experimental')) || NODE_OPTIONS?.includes('--experimental')) {
71
+ const msg = 'Contrast Agent does not support experimental features.';
72
+ throw new Error(msg);
73
+ }
74
+ }
75
+
59
76
  /**
60
77
  * Checks that the correct preload flag is used given running node version.
61
78
  * @throws {Error}
@@ -151,5 +168,6 @@ module.exports = {
151
168
  assertValidOpts,
152
169
  assertSupportedNodeVersion,
153
170
  assertSupportedPreloadUsage,
171
+ assertNoExperimentalFeatureFlags,
154
172
  preStartupValidation,
155
173
  };
@@ -0,0 +1,110 @@
1
+ 'use strict';
2
+
3
+ const { expect } = require('chai');
4
+ const sinon = require('sinon');
5
+
6
+ const {
7
+ assertValidOpts,
8
+ assertSupportedNodeVersion,
9
+ assertSupportedPreloadUsage,
10
+ assertNoExperimentalFeatureFlags,
11
+ } = require('./utils');
12
+
13
+ describe('preStartupValidation', function() {
14
+
15
+ describe('assertValidOpts', function() {
16
+ it('Does not validate when noValidate is true', function() {
17
+ const opts = {
18
+ noValidate: true
19
+ };
20
+ expect(assertValidOpts(opts)).to.be.undefined;
21
+ });
22
+
23
+ it('Throws an error if install order is incorrect', function() {
24
+ const opts = {
25
+ installOrder: [
26
+ 'telemetry',
27
+ 'reporter',
28
+ 'startupValidation'
29
+ ]
30
+ };
31
+ expect(() => assertValidOpts(opts)).to.throw('The \'installOrder\' option must include \'reporter\' as first element. found \'telemetry\'');
32
+ });
33
+ });
34
+
35
+ describe('assertSupportedNodeVersion', function() {
36
+
37
+ let engines;
38
+ beforeEach(function() {
39
+ engines = '>=16.9.1 <17 || >=18.7.0 <19 || >=20.6.0 <21 || >= 22.5.1 <23';
40
+ });
41
+
42
+ it('Does not throw an error if process.version is supported', function() {
43
+ sinon.stub(process, 'version').value('v22.9.0');
44
+ expect(assertSupportedNodeVersion(engines)).to.be.undefined;
45
+ });
46
+
47
+ it('Throws an error if process.version is unsupported', function() {
48
+ sinon.stub(process, 'version').value('v14.0.0');
49
+ expect(() => assertSupportedNodeVersion(engines)).to.throw('Contrast only officially supports Node LTS versions between 16.9.1 and 17, 18.7.0 and 19, 20.6.0 and 21, 22.5.1 and 23, but detected v14.0.0');
50
+ });
51
+
52
+ });
53
+
54
+ describe('assertSupportedPreloadUsage', function() {
55
+
56
+ it('does not throw an err if --import flag is used (>= 18.19.0)', function() {
57
+ sinon.stub(process, 'execArgv').value(['--import', '@contrast/agent']);
58
+ sinon.stub(process, 'version').value('v22.9.0');
59
+ expect(assertSupportedPreloadUsage()).to.be.true;
60
+ });
61
+
62
+ it('throws an err if --import flag is used (<= 18.19.0)', function() {
63
+ sinon.stub(process, 'execArgv').value(['--import', '@contrast/agent']);
64
+ sinon.stub(process, 'version').value('v18.18.0');
65
+ expect(() => assertSupportedPreloadUsage()).to.throw('Contrast requires that Node LTS versions >= 18.19.0 use the --import flag for ESM support');
66
+ });
67
+
68
+ it('throws an err if --loader flag is used (>= 18.19.0)', function() {
69
+ sinon.stub(process, 'execArgv').value(['--loader', '@contrast/agent']);
70
+ sinon.stub(process, 'version').value('v18.20.0');
71
+ expect(() => assertSupportedPreloadUsage()).to.throw('Contrast requires that Node versions less than 18.19.0 use the --loader flag for ESM support');
72
+ });
73
+
74
+ });
75
+
76
+ describe('assertNoExperimentalFeatureFlags', function() {
77
+ describe('process.execArgv', function() {
78
+ it('Does not throw an error if no experimental feature flag is used', function() {
79
+ sinon.stub(process, 'execArgv').value(['--import', '@contrast/agent']);
80
+ expect(assertNoExperimentalFeatureFlags()).to.be.undefined;
81
+ });
82
+
83
+ it('Throws an error if an experimental feature flag is used', function() {
84
+ sinon.stub(process, 'execArgv').value(['--experimental-feature', '--import', '@contrast/agent']);
85
+ expect(() => assertNoExperimentalFeatureFlags()).to.throw('Contrast Agent does not support experimental features.');
86
+ });
87
+ });
88
+
89
+ describe('NODE_OPTIONS', function() {
90
+
91
+ const origNodeOptions = process.env?.NODE_OPTIONS;
92
+
93
+ afterEach(function() {
94
+ process.env.NODE_OPTIONS = origNodeOptions;
95
+ });
96
+
97
+ it('Does not throw an error if no experimental feature flag is used', function() {
98
+ process.env.NODE_OPTIONS = '--import @contrast/agent';
99
+ expect(assertNoExperimentalFeatureFlags()).to.be.undefined;
100
+ });
101
+
102
+ it('Throws an error if an experimental feature flag is used', function() {
103
+ process.env.NODE_OPTIONS = '--experimental-feature --import @contrast/agent';
104
+ expect(() => assertNoExperimentalFeatureFlags()).to.throw('Contrast Agent does not support experimental features.');
105
+ });
106
+ });
107
+
108
+ });
109
+
110
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/agentify",
3
- "version": "1.33.0",
3
+ "version": "1.34.0",
4
4
  "description": "Configures Contrast agent services and instrumentation within an application",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -19,19 +19,19 @@
19
19
  "dependencies": {
20
20
  "@contrast/common": "1.26.0",
21
21
  "@contrast/config": "1.34.0",
22
- "@contrast/core": "1.38.0",
23
- "@contrast/deadzones": "1.8.0",
24
- "@contrast/dep-hooks": "1.6.0",
25
- "@contrast/esm-hooks": "2.12.0",
22
+ "@contrast/core": "1.39.0",
23
+ "@contrast/deadzones": "1.9.0",
24
+ "@contrast/dep-hooks": "1.7.0",
25
+ "@contrast/esm-hooks": "2.13.0",
26
26
  "@contrast/find-package-json": "^1.1.0",
27
- "@contrast/instrumentation": "1.16.0",
28
- "@contrast/logger": "1.11.0",
29
- "@contrast/metrics": "1.14.0",
30
- "@contrast/patcher": "1.10.0",
31
- "@contrast/perf": "1.1.0",
32
- "@contrast/reporter": "1.33.0",
33
- "@contrast/rewriter": "1.14.0",
34
- "@contrast/scopes": "1.7.0",
27
+ "@contrast/instrumentation": "1.17.0",
28
+ "@contrast/logger": "1.12.0",
29
+ "@contrast/metrics": "1.15.0",
30
+ "@contrast/patcher": "1.11.0",
31
+ "@contrast/perf": "1.2.0",
32
+ "@contrast/reporter": "1.34.0",
33
+ "@contrast/rewriter": "1.15.0",
34
+ "@contrast/scopes": "1.8.0",
35
35
  "semver": "^7.6.0"
36
36
  }
37
37
  }