zsyp 1.2.1 → 1.2.2

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.
Files changed (2) hide show
  1. package/lib/event.js +21 -2
  2. package/package.json +1 -1
package/lib/event.js CHANGED
@@ -1,3 +1,5 @@
1
+ const { ObjectId } = require('mongodb');
2
+ const { createHash } = require('node:crypto');
1
3
  const stackParser = require('error-stack-parser');
2
4
  const { resolve } = require('./source-map');
3
5
 
@@ -27,11 +29,15 @@ async function converter(event) {
27
29
  }
28
30
 
29
31
  async function convertError(error) {
30
- const { an, av } = error;
32
+ const { an, av, stack } = error;
31
33
  const frames = safeParseStack(error).map(mapFrame);
32
34
  error.stack = await Promise.all(frames);
33
35
  delete error.type;
34
- return error;
36
+ if (stack) {
37
+ // save original stack if present
38
+ error.org_stack = stack;
39
+ }
40
+ return addHash(error);
35
41
 
36
42
  function safeParseStack(error) {
37
43
  try {
@@ -54,3 +60,16 @@ function normalizeFilename(fileName) {
54
60
  // strip hostname and leading slashes
55
61
  return file.pathname.replace(/^\/+/, '');
56
62
  }
63
+
64
+ function addHash(error) {
65
+ if (error.stack.length < 1) {
66
+ return error;
67
+ }
68
+ const hasher = createHash('shake128', { outputLength: 12 });
69
+ error.stack.some(([file, line], index) => {
70
+ hasher.update(`${file}:${line}`);
71
+ return index > 9; // only hash at most 10 stack lines
72
+ });
73
+ error._hash = new ObjectId(hasher.digest());
74
+ return error;
75
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zsyp",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "CSP violation reports logger.",
5
5
  "author": {
6
6
  "name": "Damian Krzeminski",