@contrast/core 1.53.0 → 1.54.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.
@@ -15,9 +15,11 @@
15
15
  // @ts-check
16
16
  'use strict';
17
17
 
18
- const fs = require('fs/promises');
19
- const os = require('os');
20
- const v8 = require('v8');
18
+ const cp = require('node:child_process');
19
+ const fs = require('node:fs/promises');
20
+ const os = require('node:os');
21
+ const util = require('node:util');
22
+ const v8 = require('node:v8');
21
23
  const {
22
24
  primordials: { StringPrototypeMatch, StringPrototypeTrim },
23
25
  } = require('@contrast/common');
@@ -29,6 +31,8 @@ const MOUNTINFO_REGEX = /\/docker\/containers\/(.*?)\//;
29
31
  const CGROUP_REGEX = /:\/docker\/([^/]+)$/;
30
32
  const MAX_CGROUP_MEMORY_LIMIT = 2 ** 63 - 1; // Common "unlimited" value for cgroup limits
31
33
 
34
+ const exec = util.promisify(cp.exec);
35
+
32
36
  /**
33
37
  * Asynchronously determines if the current environment is running inside a
34
38
  * Docker container.
@@ -134,6 +138,27 @@ async function getDockerMemoryLimit() {
134
138
  }
135
139
  }
136
140
 
141
+ /**
142
+ * Retrieves macOS system information using the `sw_vers` command.
143
+ * Returns `null` if the command fails or is not available.
144
+ * @returns {Promise<{
145
+ * productName: string;
146
+ * productVersion: string;
147
+ * buildVersion: string;
148
+ * } | null>}
149
+ */
150
+ async function macOsInfo() {
151
+ try {
152
+ return {
153
+ productName: StringPrototypeTrim.call((await exec('sw_vers -productName')).stdout),
154
+ productVersion: StringPrototypeTrim.call((await exec('sw_vers -productVersion')).stdout),
155
+ buildVersion: StringPrototypeTrim.call((await exec('sw_vers -buildVersion')).stdout)
156
+ };
157
+ } catch {
158
+ return null;
159
+ }
160
+ }
161
+
137
162
  /**
138
163
  * @param {import('..').Core & {
139
164
  * _systemInfo: import('@contrast/common').SystemInfo | undefined;
@@ -149,11 +174,14 @@ module.exports = function (core) {
149
174
  if (core._systemInfo) return core._systemInfo;
150
175
 
151
176
  const cpus = os.cpus();
177
+ const totalmem = os.totalmem();
152
178
  const heapStats = v8.getHeapStatistics();
179
+ const free_heap_size = heapStats.heap_size_limit - heapStats.used_heap_size;
153
180
  const dockerMemoryLimit = await getDockerMemoryLimit();
154
181
 
155
182
  const osMemoryInfo = {
156
- total: humanReadableBytes(os.totalmem()),
183
+ total: humanReadableBytes(totalmem),
184
+ totalBytes: totalmem,
157
185
  };
158
186
  const linuxOsInfo = await getLinuxOsInfo();
159
187
 
@@ -180,8 +208,11 @@ module.exports = function (core) {
180
208
  version: process.version,
181
209
  memory: {
182
210
  total: humanReadableBytes(heapStats.heap_size_limit),
211
+ totalBytes: heapStats.heap_size_limit,
183
212
  used: humanReadableBytes(heapStats.used_heap_size),
184
- free: humanReadableBytes(heapStats.heap_size_limit - heapStats.used_heap_size),
213
+ usedBytes: heapStats.used_heap_size,
214
+ free: humanReadableBytes(free_heap_size),
215
+ freeBytes: free_heap_size,
185
216
  },
186
217
  },
187
218
  os: {
@@ -194,8 +225,8 @@ module.exports = function (core) {
194
225
  count: cpus.length,
195
226
  },
196
227
  memory: osMemoryInfo,
197
- id: linuxOsInfo?.file ? linuxOsInfo.id : undefined,
198
- versionId: linuxOsInfo?.file ? linuxOsInfo.version_id : undefined,
228
+ linuxInfo: linuxOsInfo?.file ? linuxOsInfo : null,
229
+ macOsInfo: await macOsInfo(),
199
230
  },
200
231
  host: {
201
232
  docker: await getDockerInfo(),
@@ -203,6 +234,7 @@ module.exports = function (core) {
203
234
  pm2: isUsingPM2(appInfo.pkg),
204
235
  memory: {
205
236
  total: dockerMemoryLimit ? humanReadableBytes(dockerMemoryLimit) : osMemoryInfo.total,
237
+ totalBytes: dockerMemoryLimit ?? osMemoryInfo.totalBytes,
206
238
  },
207
239
  },
208
240
  application: appInfo.pkg,
@@ -60,7 +60,7 @@ function addEtcAlpineReleaseToOutputData(data, outputData) {
60
60
  const defaultList = [
61
61
  { path: '/etc/os-release', parser: addOsReleaseToOutputData },
62
62
  { path: '/usr/lib/os-release', parser: addOsReleaseToOutputData },
63
- { path: '/etc/alpine-release', parser: addEtcAlpineReleaseToOutputData }
63
+ { path: '/etc/alpine-release', parser: addEtcAlpineReleaseToOutputData },
64
64
  ];
65
65
 
66
66
  /**
@@ -68,11 +68,13 @@ const defaultList = [
68
68
  * or '/etc/alpine-release'. The information in that file is distribution-dependent.
69
69
  *
70
70
  * @returns {Promise<{
71
- * file?: string;
72
- * [key: string]: string;
73
- * }>} - where object is null if not Linux, or an object with
74
- * the a file property and the key-value pairs from the file. Any quotes around the
75
- * values are removed.
71
+ * file: string;
72
+ * [key: string]: string;
73
+ * } | {
74
+ * file: undefined
75
+ * } | null>} where object is null if not Linux, or an object with the a file
76
+ * property and the key-value pairs from the file. Any quotes around the values
77
+ * are removed.
76
78
  *
77
79
  * the file property in the info object will be filled in with one of:
78
80
  * - the file path (above) used
@@ -95,7 +97,6 @@ async function linuxOsInfo(opts = {}) {
95
97
  list[i].parser(data, outputData);
96
98
 
97
99
  return outputData;
98
-
99
100
  } catch (e) {
100
101
  i += 1;
101
102
  continue;
@@ -106,7 +107,6 @@ async function linuxOsInfo(opts = {}) {
106
107
  return { file: undefined };
107
108
  }
108
109
 
109
-
110
110
  function addOsReleaseToOutputData(data, outputData) {
111
111
  const lines = data.split('\n');
112
112
 
@@ -134,4 +134,3 @@ function addOsReleaseToOutputData(data, outputData) {
134
134
  }
135
135
 
136
136
  module.exports = linuxOsInfo;
137
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/core",
3
- "version": "1.53.0",
3
+ "version": "1.54.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)",
@@ -19,12 +19,12 @@
19
19
  "test": "bash ../scripts/test.sh"
20
20
  },
21
21
  "dependencies": {
22
- "@contrast/common": "1.33.0",
23
- "@contrast/config": "1.48.0",
22
+ "@contrast/common": "1.34.0",
23
+ "@contrast/config": "1.49.0",
24
24
  "@contrast/find-package-json": "^1.1.0",
25
25
  "@contrast/fn-inspect": "^4.3.0",
26
- "@contrast/logger": "1.26.0",
27
- "@contrast/patcher": "1.25.0",
26
+ "@contrast/logger": "1.27.0",
27
+ "@contrast/patcher": "1.26.0",
28
28
  "@contrast/perf": "1.3.1",
29
29
  "@tsxper/crc32": "^2.1.3",
30
30
  "axios": "^1.7.4",