@contrast/core 1.21.0 → 1.23.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/app-info.js CHANGED
@@ -20,7 +20,7 @@ const path = require('path');
20
20
  const fs = require('fs');
21
21
  const process = require('process');
22
22
 
23
- const MAX_ATTEMPTS = 5;
23
+ const MAX_ATTEMPTS = 10; // temporary until test dir is flattened a bit
24
24
 
25
25
  module.exports = function (core) {
26
26
  const { logger, config } = core;
package/lib/index.js CHANGED
@@ -18,23 +18,26 @@
18
18
  const EventEmitter = require('events');
19
19
 
20
20
  module.exports = function init(core = {}) {
21
- core.messages = new EventEmitter();
22
21
  core.events = {
23
22
  lifecycle: new EventEmitter(),
24
- // messages: new EventEmitter(),
25
23
  };
26
- require('./agent-info')(core);
24
+ core.messages = new EventEmitter(); // merge
25
+
27
26
  require('@contrast/config')(core);
28
- require('./logger-factory')(core);
29
- require('./effective-config')(core);
27
+ require('@contrast/logger').default(core);
28
+
29
+ require('./agent-info')(core);
30
30
  require('./system-info')(core);
31
- require('./sensitive-data-masking')(core);
32
31
  require('./app-info')(core);
32
+ require('./sensitive-data-masking')(core);
33
33
  require('./is-agent-path')(core);
34
- require('./capture-stacktrace')(core);
34
+ require('./capture-stacktrace')(core); // @contrast/info
35
+
35
36
  require('@contrast/patcher')(core);
36
- require('./contrast-methods')(core);
37
- require('@contrast/rewriter')(core);
37
+
38
+ require('@contrast/rewriter')(core); // merge contrast-methods?
39
+ require('./contrast-methods')(core); // can we remove dependency on patcher?
40
+
38
41
  require('@contrast/dep-hooks')(core);
39
42
  require('@contrast/scopes')(core);
40
43
  require('@contrast/deadzones')(core);
@@ -21,7 +21,7 @@ const os = require('os');
21
21
 
22
22
  function isUsingPM2() {
23
23
  const used = !!process.env.pmx;
24
- let version = null;
24
+ let version;
25
25
 
26
26
  for (const pathVar of ['npm_package_json', 'PWD']) {
27
27
  const packagePath = process.env[pathVar];
@@ -35,7 +35,7 @@ function isUsingPM2() {
35
35
  if (version) break;
36
36
  }
37
37
 
38
- return { used, version };
38
+ return { used, ...(version && { version }) };
39
39
  }
40
40
 
41
41
  function isDocker() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/core",
3
- "version": "1.21.0",
3
+ "version": "1.23.0",
4
4
  "description": "Preconfigured Contrast agent core services and models",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -17,17 +17,17 @@
17
17
  "test": "../scripts/test.sh"
18
18
  },
19
19
  "dependencies": {
20
- "@contrast/agentify": "1.12.0",
21
- "@contrast/common": "1.14.0",
22
- "@contrast/config": "1.16.0",
20
+ "@contrast/agentify": "1.13.0",
21
+ "@contrast/common": "1.15.0",
22
+ "@contrast/config": "1.18.0",
23
23
  "@contrast/deadzones": "1.1.0",
24
24
  "@contrast/dep-hooks": "1.2.0",
25
- "@contrast/fn-inspect": "^3.3.0",
26
- "@contrast/instrumentation": "1.1.2",
27
- "@contrast/logger": "1.4.0",
25
+ "@contrast/fn-inspect": "^3.4.0",
26
+ "@contrast/instrumentation": "1.2.0",
27
+ "@contrast/logger": "1.5.0",
28
28
  "@contrast/patcher": "1.7.0",
29
- "@contrast/reporter": "1.19.0",
29
+ "@contrast/reporter": "1.20.0",
30
30
  "@contrast/rewriter": "1.4.2",
31
31
  "@contrast/scopes": "1.4.0"
32
32
  }
33
- }
33
+ }
@@ -1,91 +0,0 @@
1
- /*
2
- * Copyright: 2023 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
-
16
- 'use strict';
17
-
18
- const REDACTED_KEYS = ['api.api_key', 'api.service_key'];
19
- const { Event, featureReaders, settingsReaders, mergeRemoteData } = require('@contrast/common');
20
- const { configOptions } = require('@contrast/config/lib/options');
21
-
22
- module.exports = function(core) {
23
- const { config, messages } = core;
24
- const effectiveConfig = createEffectiveConfig({ config, remoteData: {} });
25
- let status = '';
26
-
27
- messages.on(Event.SERVER_SETTINGS_UPDATE, (msg) => {
28
- if (!status) {
29
- status = 'Success';
30
- }
31
-
32
- mergeRemoteData(config, msg, featureReaders, setterFn, effectiveConfig);
33
- mergeRemoteData(config, msg, settingsReaders, setterFn, effectiveConfig);
34
- });
35
-
36
- core.getEffectiveConfig = function (tsFriendly = false) {
37
- return formatEffectiveConfig(effectiveConfig, tsFriendly);
38
- };
39
-
40
- return;
41
-
42
- function setterFn(target, name, value) {
43
- let remoteValue = value;
44
- if (typeof value === 'string') remoteValue = remoteValue.toLowerCase();
45
- target.set(name, {
46
- canonical_name: name,
47
- name,
48
- value: remoteValue,
49
- source: 'CONTRAST_UI',
50
- });
51
- }
52
-
53
- function createEffectiveConfig({ config }) {
54
- return new Map(configOptions.map(({ name }) => [name, {
55
- canonical_name: name,
56
- name,
57
- value: config._flat[name],
58
- source: config._sources[name]
59
- }]));
60
- }
61
-
62
- function formatEffectiveConfig(configMap, tsFriendly = false) {
63
- const effective_config = [], environment_variable = [], contrast_ui = [];
64
- Array.from(configMap.values()).forEach((v) => {
65
- if (v.value != undefined) {
66
- if (tsFriendly) {
67
- const value = REDACTED_KEYS.includes(v.name)
68
- ? `contrast-redacted-${v.name}`
69
- : v.value.toString();
70
- effective_config.push({ ...v, value });
71
- } else {
72
- effective_config.push(v);
73
- }
74
- }
75
- if (v.source === 'ENVIRONMENT_VARIABLE') environment_variable.push(v);
76
- if (v.source === 'CONTRAST_UI') contrast_ui.push(v);
77
- });
78
-
79
- const content = {
80
- report_create: new Date(),
81
- config: {
82
- status,
83
- effective_config,
84
- environment_variable,
85
- contrast_ui,
86
- }
87
- };
88
-
89
- return content;
90
- }
91
- };
@@ -1,62 +0,0 @@
1
- /*
2
- * Copyright: 2023 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
-
16
- 'use strict';
17
- const noop = () => { };
18
- const { Event } = require('@contrast/common');
19
-
20
- module.exports = function (core) {
21
- const { messages, config } = core;
22
- const cfgLogLevel = config.agent.logger.level;
23
- core.logger = {
24
- pino: require('@contrast/logger').default(core),
25
- children: [],
26
- child(opts) {
27
- const child = {
28
- pino: this.pino.child(opts),
29
- setLogLevel: this.setLogLevel
30
- };
31
- child.setLogLevel(this.pino.level);
32
- this.children.push(child);
33
- return child;
34
- },
35
- setLogLevel(level) {
36
- this.level = level;
37
- this.pino.level = level;
38
-
39
- const { levelVal, levels: { values } } = this.pino;
40
- for (const key in values) {
41
- if (levelVal > values[key]) {
42
- this[key] = noop;
43
- } else {
44
- this[key] = (...args) => this.pino[key](...args);
45
- }
46
- }
47
- }
48
- };
49
-
50
- core.logger.setLogLevel(cfgLogLevel || 'info');
51
-
52
- messages.on(Event.SERVER_SETTINGS_UPDATE, (settingsMsg) => {
53
- const tsLogLevel = settingsMsg?.logger?.level.toLowerCase();
54
- if (!cfgLogLevel && tsLogLevel && tsLogLevel !== core.logger.level) {
55
- core.logger.setLogLevel(tsLogLevel);
56
- core.logger.children.forEach((child) => {
57
- child.setLogLevel(tsLogLevel);
58
- });
59
- core.logger.info('Received new log level: %s from server-features', tsLogLevel);
60
- }
61
- });
62
- };