@contrast/common 1.34.2 → 1.36.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.js CHANGED
@@ -28,7 +28,21 @@ 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.normalizeURI = 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;
31
+ exports.empties = void 0;
32
+ exports.isString = isString;
33
+ exports.isNonEmptyObject = isNonEmptyObject;
34
+ exports.encodeString = encodeString;
35
+ exports.traverseKeysAndValues = traverseKeysAndValues;
36
+ exports.traverseValues = traverseValues;
37
+ exports.traverseKeys = traverseKeys;
38
+ exports.callChildComponentMethodsSync = callChildComponentMethodsSync;
39
+ exports.callChildComponentMethods = callChildComponentMethods;
40
+ exports.groupResultsMap = groupResultsMap;
41
+ exports.get = get;
42
+ exports.set = set;
43
+ exports.safeConsoleError = safeConsoleError;
44
+ exports.safeConsoleWarn = safeConsoleWarn;
45
+ exports.normalizeURI = normalizeURI;
32
46
  const constants_1 = require("./constants");
33
47
  const primordials_1 = require("./primordials");
34
48
  __exportStar(require("./constants"), exports);
@@ -49,16 +63,13 @@ exports.empties = {
49
63
  function isString(value) {
50
64
  return typeof value === 'string' || value instanceof String;
51
65
  }
52
- exports.isString = isString;
53
66
  function isNonEmptyObject(value) {
54
67
  return !!value && typeof value === 'object' && Object.keys(value).length > 0;
55
68
  }
56
- exports.isNonEmptyObject = isNonEmptyObject;
57
69
  /* c8 ignore next 3 */
58
70
  function encodeString(str) {
59
71
  return BufferPrototypeToString.call(BufferFrom(str), 'base64');
60
72
  }
61
- exports.encodeString = encodeString;
62
73
  function traverse(obj, cb, path, traverseValues, traverseKeys, depth = Infinity) {
63
74
  let shouldKeepTraversing = true;
64
75
  let reachedDepth = 0;
@@ -115,21 +126,18 @@ function traverseKeysAndValues(obj, cb, depth) {
115
126
  }
116
127
  traverse(obj, cb, [], true, true, depth);
117
128
  }
118
- exports.traverseKeysAndValues = traverseKeysAndValues;
119
129
  function traverseValues(obj, cb, depth) {
120
130
  if (typeof obj !== 'object' || obj === null) {
121
131
  return;
122
132
  }
123
133
  traverse(obj, cb, [], true, false, depth);
124
134
  }
125
- exports.traverseValues = traverseValues;
126
135
  function traverseKeys(obj, cb, depth) {
127
136
  if (typeof obj !== 'object' || obj === null) {
128
137
  return;
129
138
  }
130
139
  traverse(obj, cb, [], false, true, depth);
131
140
  }
132
- exports.traverseKeys = traverseKeys;
133
141
  function callChildComponentMethodsSync(parent, method, order) {
134
142
  const keys = order || Object.keys(parent);
135
143
  for (const key of keys) {
@@ -137,7 +145,6 @@ function callChildComponentMethodsSync(parent, method, order) {
137
145
  component?.[method]?.();
138
146
  }
139
147
  }
140
- exports.callChildComponentMethodsSync = callChildComponentMethodsSync;
141
148
  async function callChildComponentMethods(parent, method, order) {
142
149
  const keys = order || Object.keys(parent);
143
150
  for (const key of keys) {
@@ -145,7 +152,6 @@ async function callChildComponentMethods(parent, method, order) {
145
152
  await component?.[method]?.();
146
153
  }
147
154
  }
148
- exports.callChildComponentMethods = callChildComponentMethods;
149
155
  function groupResultsMap(resultsMap) {
150
156
  const result = {
151
157
  commonResultsMap: {},
@@ -184,7 +190,6 @@ function groupResultsMap(resultsMap) {
184
190
  }, result);
185
191
  return result;
186
192
  }
187
- exports.groupResultsMap = groupResultsMap;
188
193
  function get(obj, name) {
189
194
  let target = obj;
190
195
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -197,7 +202,6 @@ function get(obj, name) {
197
202
  }
198
203
  return target;
199
204
  }
200
- exports.get = get;
201
205
  function set(obj, name, value) {
202
206
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
203
207
  // @ts-ignore
@@ -210,21 +214,18 @@ function set(obj, name, value) {
210
214
  }
211
215
  obj[lastProp] = value;
212
216
  }
213
- exports.set = set;
214
217
  /** Suppresses output to stderr when installed by the universal agent */
215
218
  function safeConsoleError(...args) {
216
219
  if (CONTRAST_INSTALLATION_TOOL === 'NONE') {
217
220
  console.error(...args);
218
221
  }
219
222
  }
220
- exports.safeConsoleError = safeConsoleError;
221
223
  /** Suppresses output to stderr when installed by the universal agent */
222
224
  function safeConsoleWarn(...args) {
223
225
  if (CONTRAST_INSTALLATION_TOOL === 'NONE') {
224
226
  console.warn(...args);
225
227
  }
226
228
  }
227
- exports.safeConsoleWarn = safeConsoleWarn;
228
229
  function normalizeURI(uri) {
229
230
  let normalizedUri = uri;
230
231
  constants_1.URI_REGEXES.forEach(({ rx, rp }) => {
@@ -233,6 +234,5 @@ function normalizeURI(uri) {
233
234
  });
234
235
  return normalizedUri;
235
236
  }
236
- exports.normalizeURI = normalizeURI;
237
237
  ;
238
238
  //# sourceMappingURL=index.js.map
@@ -1,14 +1,10 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- /// <reference types="node" />
4
- /// <reference types="node" />
5
1
  import { inspect } from 'util';
6
2
  import fs from 'fs';
7
3
  export declare const primordials: {
8
- ArrayPrototypeJoin: (separator?: string | undefined) => string;
9
- ArrayPrototypeSlice: (start?: number | undefined, end?: number | undefined) => any[];
4
+ ArrayPrototypeJoin: (separator?: string) => string;
5
+ ArrayPrototypeSlice: (start?: number, end?: number) => any[];
10
6
  BufferFrom: typeof Buffer.from;
11
- BufferPrototypeToString: (encoding?: BufferEncoding | undefined, start?: number | undefined, end?: number | undefined) => string;
7
+ BufferPrototypeToString: (encoding?: BufferEncoding, start?: number, end?: number) => string;
12
8
  StringPrototypeConcat: (...strings: string[]) => string;
13
9
  StringPrototypeMatch: {
14
10
  (regexp: string | RegExp): RegExpMatchArray | null;
@@ -16,7 +12,7 @@ export declare const primordials: {
16
12
  [Symbol.match](string: string): RegExpMatchArray | null;
17
13
  }): RegExpMatchArray | null;
18
14
  };
19
- StringPrototypeMatchAll: (regexp: RegExp) => IterableIterator<RegExpMatchArray>;
15
+ StringPrototypeMatchAll: (regexp: RegExp) => RegExpStringIterator<RegExpExecArray>;
20
16
  StringPrototypeReplace: {
21
17
  (searchValue: string | RegExp, replaceValue: string): string;
22
18
  (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string;
@@ -31,30 +27,36 @@ export declare const primordials: {
31
27
  (searchValue: string | RegExp, replaceValue: string): string;
32
28
  (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string;
33
29
  };
34
- StringPrototypeSlice: (start?: number | undefined, end?: number | undefined) => string;
30
+ StringPrototypeSlice: (start?: number, end?: number) => string;
35
31
  StringPrototypeSplit: {
36
- (separator: string | RegExp, limit?: number | undefined): string[];
32
+ (separator: string | RegExp, limit?: number): string[];
37
33
  (splitter: {
38
- [Symbol.split](string: string, limit?: number | undefined): string[];
39
- }, limit?: number | undefined): string[];
34
+ [Symbol.split](string: string, limit?: number): string[];
35
+ }, limit?: number): string[];
40
36
  };
41
- StringPrototypeSubstr: (from: number, length?: number | undefined) => string;
42
- StringPrototypeSubstring: (start: number, end?: number | undefined) => string;
37
+ StringPrototypeSubstr: (from: number, length?: number) => string;
38
+ StringPrototypeSubstring: (start: number, end?: number) => string;
43
39
  StringPrototypeToLowerCase: () => string;
44
40
  StringPrototypeToUpperCase: () => string;
45
- StringPrototypeToLocaleLowerCase: (locales?: string | string[] | undefined) => string;
46
- StringPrototypeToLocaleUpperCase: (locales?: string | string[] | undefined) => string;
41
+ StringPrototypeToLocaleLowerCase: {
42
+ (locales?: string | string[]): string;
43
+ (locales?: Intl.LocalesArgument): string;
44
+ };
45
+ StringPrototypeToLocaleUpperCase: {
46
+ (locales?: string | string[]): string;
47
+ (locales?: Intl.LocalesArgument): string;
48
+ };
47
49
  StringPrototypeTrim: () => string;
48
50
  RegExpPrototypeTest: (string: string) => boolean;
49
51
  RegExpPrototypeExec: (string: string) => RegExpExecArray | null;
50
52
  FunctionPrototypeToString: () => string;
51
- JSONParse: (text: string, reviver?: ((this: any, key: string, value: any) => any) | undefined) => any;
53
+ JSONParse: (text: string, reviver?: (this: any, key: string, value: any) => any) => any;
52
54
  JSONStringify: {
53
- (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string;
54
- (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string;
55
+ (value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string;
56
+ (value: any, replacer?: (number | string)[] | null, space?: string | number): string;
55
57
  };
56
58
  UtilInspect: typeof inspect;
57
- PathBasename: (path: string, ext?: string | undefined) => string;
59
+ PathBasename: (path: string, ext?: string) => string;
58
60
  FsOpen: typeof fs.open;
59
61
  FsOpenSync: typeof fs.openSync;
60
62
  FsReadFile: typeof fs.readFile;
package/lib/types.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { EventEmitter } from 'events';
4
2
  import { ServerResponse } from 'node:http';
5
3
  import { Event, ProtectRuleMode, Rule } from './constants';
@@ -207,7 +205,6 @@ export declare class Blocker {
207
205
  block(mode: string, ruleId: string): void;
208
206
  }
209
207
  export interface ProtectMessage {
210
- reqData: ReqData;
211
208
  blocker: Blocker;
212
209
  policy: Partial<Record<Rule, ProtectRuleMode>>;
213
210
  exclusions: any[];
@@ -226,6 +223,13 @@ export interface SourceInfo {
226
223
  port: number;
227
224
  protocol: string;
228
225
  time: number;
226
+ method: string;
227
+ rawHeaders: string[];
228
+ uriPath: string;
229
+ queries: string;
230
+ contentType?: string;
231
+ ip: string;
232
+ httpVersion: string;
229
233
  }
230
234
  /**
231
235
  * this is known as RequestStore even though, in the future, instrumentation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/common",
3
- "version": "1.34.2",
3
+ "version": "1.36.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)",
@@ -14,7 +14,7 @@
14
14
  "types": "lib/index.d.ts",
15
15
  "engines": {
16
16
  "npm": ">=6.13.7 <7 || >= 8.3.1",
17
- "node": ">= 16.9.1"
17
+ "node": ">= 18.7.0"
18
18
  },
19
19
  "scripts": {
20
20
  "build": "tsc --build src/",