@contrast/common 1.30.0 → 1.32.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/index.d.ts CHANGED
@@ -5,6 +5,14 @@ export * from './primordials';
5
5
  interface TraverseCallback {
6
6
  (path: any[], type: 'Key' | 'Value', value: any, obj: any): unknown;
7
7
  }
8
+ export declare const empties: {
9
+ OBJECT: Readonly<{}>;
10
+ ARRAY: readonly never[];
11
+ UNTRACKED_VALUE_OBJ: Readonly<{
12
+ value: null;
13
+ tracked: false;
14
+ }>;
15
+ };
8
16
  /**
9
17
  * Returns true if the value passed is either a primitive string or a
10
18
  * String object.
@@ -25,4 +33,8 @@ export declare function groupResultsMap(resultsMap: Partial<ResultMap>): {
25
33
  };
26
34
  export declare function get(obj: any, name: string): any;
27
35
  export declare function set(obj: Record<string, any>, name: string, value: any): void;
36
+ /** Suppresses output to stderr when installed by the universal agent */
37
+ export declare function safeConsoleError(...args: Parameters<typeof console.error>): void;
38
+ /** Suppresses output to stderr when installed by the universal agent */
39
+ export declare function safeConsoleWarn(...args: Parameters<typeof console.warn>): void;
28
40
  //# sourceMappingURL=index.d.ts.map
package/lib/index.js CHANGED
@@ -28,13 +28,19 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
28
28
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
29
29
  };
30
30
  Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.set = exports.get = exports.groupResultsMap = exports.callChildComponentMethods = exports.callChildComponentMethodsSync = exports.traverseKeys = exports.traverseValues = exports.traverseKeysAndValues = exports.encodeString = exports.isNonEmptyObject = exports.isString = void 0;
31
+ exports.safeConsoleWarn = exports.safeConsoleError = exports.set = exports.get = exports.groupResultsMap = exports.callChildComponentMethods = exports.callChildComponentMethodsSync = exports.traverseKeys = exports.traverseValues = exports.traverseKeysAndValues = exports.encodeString = exports.isNonEmptyObject = exports.isString = exports.empties = void 0;
32
32
  const constants_1 = require("./constants");
33
33
  const primordials_1 = require("./primordials");
34
34
  __exportStar(require("./constants"), exports);
35
35
  __exportStar(require("./types"), exports);
36
36
  __exportStar(require("./primordials"), exports);
37
+ const { CONTRAST_INSTALLATION_TOOL = 'NONE' } = process.env;
37
38
  const { StringPrototypeSplit, BufferFrom, BufferPrototypeToString } = primordials_1.primordials;
39
+ exports.empties = {
40
+ OBJECT: Object.freeze({}),
41
+ ARRAY: Object.freeze([]),
42
+ UNTRACKED_VALUE_OBJ: Object.freeze({ value: null, tracked: false })
43
+ };
38
44
  /**
39
45
  * Returns true if the value passed is either a primitive string or a
40
46
  * String object.
@@ -205,4 +211,18 @@ function set(obj, name, value) {
205
211
  obj[lastProp] = value;
206
212
  }
207
213
  exports.set = set;
214
+ /** Suppresses output to stderr when installed by the universal agent */
215
+ function safeConsoleError(...args) {
216
+ if (CONTRAST_INSTALLATION_TOOL === 'NONE') {
217
+ console.error(...args);
218
+ }
219
+ }
220
+ exports.safeConsoleError = safeConsoleError;
221
+ /** Suppresses output to stderr when installed by the universal agent */
222
+ function safeConsoleWarn(...args) {
223
+ if (CONTRAST_INSTALLATION_TOOL === 'NONE') {
224
+ console.warn(...args);
225
+ }
226
+ }
227
+ exports.safeConsoleWarn = safeConsoleWarn;
208
228
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,9 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ /// <reference types="node" />
3
5
  import { inspect } from 'util';
6
+ import fs from 'fs';
4
7
  export declare const primordials: {
5
8
  ArrayPrototypeJoin: (separator?: string | undefined) => string;
6
9
  ArrayPrototypeSlice: (start?: number | undefined, end?: number | undefined) => any[];
@@ -52,5 +55,11 @@ export declare const primordials: {
52
55
  };
53
56
  UtilInspect: typeof inspect;
54
57
  PathBasename: (path: string, ext?: string | undefined) => string;
58
+ FsOpen: typeof fs.open;
59
+ FsOpenSync: typeof fs.openSync;
60
+ FsReadFile: typeof fs.readFile;
61
+ FsReadFileSync: typeof fs.readFileSync;
62
+ FsPromisesOpen: typeof fs.promises.open;
63
+ FsPromiseReadFile: typeof fs.promises.readFile;
55
64
  };
56
65
  //# sourceMappingURL=primordials.d.ts.map
@@ -13,10 +13,15 @@
13
13
  * engineered, modified, repackaged, sold, redistributed or otherwise used in a
14
14
  * way not consistent with the End User License Agreement.
15
15
  */
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
16
19
  Object.defineProperty(exports, "__esModule", { value: true });
17
20
  exports.primordials = void 0;
18
21
  const util_1 = require("util");
19
22
  const path_1 = require("path");
23
+ const fs_1 = __importDefault(require("fs"));
24
+ const promises_1 = __importDefault(require("fs/promises"));
20
25
  exports.primordials = {
21
26
  // arrays
22
27
  ArrayPrototypeJoin: Array.prototype.join,
@@ -48,6 +53,14 @@ exports.primordials = {
48
53
  JSONParse: JSON.parse,
49
54
  JSONStringify: JSON.stringify,
50
55
  UtilInspect: util_1.inspect,
51
- PathBasename: path_1.basename
56
+ PathBasename: path_1.basename,
57
+ // fs
58
+ FsOpen: fs_1.default.open,
59
+ FsOpenSync: fs_1.default.openSync,
60
+ FsReadFile: fs_1.default.readFile,
61
+ FsReadFileSync: fs_1.default.readFileSync,
62
+ // fs/promises
63
+ FsPromisesOpen: promises_1.default.open,
64
+ FsPromiseReadFile: promises_1.default.readFile,
52
65
  };
53
66
  //# sourceMappingURL=primordials.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/common",
3
- "version": "1.30.0",
3
+ "version": "1.32.0",
4
4
  "description": "Shared constants and utilities for all Contrast Agent modules",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",