@contrast/common 1.39.1 → 1.40.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
@@ -38,4 +38,11 @@ export declare function safeConsoleError(...args: Parameters<typeof console.erro
38
38
  /** Suppresses output to stderr when installed by the universal agent */
39
39
  export declare function safeConsoleWarn(...args: Parameters<typeof console.warn>): void;
40
40
  export declare function normalizeURI(uri: string): string;
41
+ export interface FrameInfo {
42
+ file: string;
43
+ lineNumber: number;
44
+ method: string;
45
+ type: string | null;
46
+ }
47
+ export declare function parseStackTraceLines(lines: string[]): null | FrameInfo[];
41
48
  //# sourceMappingURL=index.d.ts.map
package/lib/index.js CHANGED
@@ -43,6 +43,7 @@ exports.set = set;
43
43
  exports.safeConsoleError = safeConsoleError;
44
44
  exports.safeConsoleWarn = safeConsoleWarn;
45
45
  exports.normalizeURI = normalizeURI;
46
+ exports.parseStackTraceLines = parseStackTraceLines;
46
47
  const constants_1 = require("./constants");
47
48
  const primordials_1 = require("./primordials");
48
49
  __exportStar(require("./constants"), exports);
@@ -192,8 +193,7 @@ function groupResultsMap(resultsMap) {
192
193
  }
193
194
  function get(obj, name) {
194
195
  let target = obj;
195
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
196
- // @ts-ignore
196
+ // @ts-expect-error ts does not handle method overloads well
197
197
  const props = StringPrototypeSplit.call(name, '.');
198
198
  for (const prop of props) {
199
199
  target = target?.[prop];
@@ -203,8 +203,7 @@ function get(obj, name) {
203
203
  return target;
204
204
  }
205
205
  function set(obj, name, value) {
206
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
207
- // @ts-ignore
206
+ // @ts-expect-error ts does not handle method overloads well
208
207
  const props = StringPrototypeSplit.call(name, '.');
209
208
  const lastProp = props.pop();
210
209
  for (const p of props) {
@@ -229,10 +228,37 @@ function safeConsoleWarn(...args) {
229
228
  function normalizeURI(uri) {
230
229
  let normalizedUri = uri;
231
230
  constants_1.URI_REGEXES.forEach(({ rx, rp }) => {
232
- //@ts-ignore
231
+ // @ts-expect-error ts does not handle method overloads well
233
232
  normalizedUri = StringPrototypeReplaceAll.call(normalizedUri, rx, rp);
234
233
  });
235
234
  return normalizedUri;
236
235
  }
237
- ;
236
+ const STACK_FRAME_LINE_PARSER = /^\s*at\s+(?:(?<async>async\s+)?(?<caller>.+?)\s+\()?(?<file>.+?):(?<line>\d+):(?<column>\d+)\)?$/;
237
+ function parseStackTraceLines(lines) {
238
+ const ret = [];
239
+ for (const line of lines) {
240
+ const match = line.match(STACK_FRAME_LINE_PARSER);
241
+ // don't include if we can't parse
242
+ if (!match?.groups)
243
+ continue;
244
+ const { caller, file, line: lineNumber } = match.groups;
245
+ let method = caller;
246
+ let typeName = null;
247
+ if (!method) {
248
+ method = '<anonymous>';
249
+ }
250
+ else if (method.indexOf('.') > 0) {
251
+ const methodIdx = method.lastIndexOf('.');
252
+ typeName = primordials_1.primordials.StringPrototypeSubstring.call(method, 0, methodIdx);
253
+ method = primordials_1.primordials.StringPrototypeSubstring.call(method, methodIdx + 1);
254
+ }
255
+ ret.push({
256
+ method: method || '<anonymous>',
257
+ file,
258
+ lineNumber: Number(lineNumber),
259
+ type: typeName
260
+ });
261
+ }
262
+ return ret;
263
+ }
238
264
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/common",
3
- "version": "1.39.1",
3
+ "version": "1.40.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)",