@kenkaiiii/error-mom 0.3.1 → 0.3.3

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.
@@ -1,10 +1,11 @@
1
1
  // src/shared.ts
2
+ import {
3
+ redactStringCredentials
4
+ } from "@kenkaiiii/error-mom-protocol";
2
5
  var SDK_NAME = "@kenkaiiii/error-mom";
3
- var SDK_VERSION = "0.3.1";
6
+ var SDK_VERSION = "0.3.3";
4
7
  var MAX_BREADCRUMBS = 50;
5
8
  var SECRET_KEY = /authorization|cookie|password|passwd|secret|token|api[-_]?key|session/i;
6
- var URL_CREDENTIAL = /([?&](?:token|key|secret|password|code)=)[^&\s]*/gi;
7
- var EMAIL = /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi;
8
9
  function wrapFunction(capture, fn, context) {
9
10
  return (...args) => {
10
11
  try {
@@ -23,7 +24,7 @@ function wrapFunction(capture, fn, context) {
23
24
  };
24
25
  }
25
26
  function redactString(value) {
26
- return value.replace(URL_CREDENTIAL, "$1[REDACTED]").replace(EMAIL, "[REDACTED_EMAIL]");
27
+ return redactStringCredentials(value);
27
28
  }
28
29
  function sanitize(value, depth = 0) {
29
30
  if (depth > 5) return "[TRUNCATED]";
@@ -83,8 +84,8 @@ function createEvent(value, options, breadcrumbs, runtime, captureContext = {})
83
84
  ...typeof location !== "undefined" ? { url: redactString(location.href) } : {},
84
85
  ...captureContext.culprit ? { culprit: redactString(captureContext.culprit) } : {},
85
86
  ...options.installationId ? { installationId: options.installationId } : {},
86
- breadcrumbs: breadcrumbs.slice(-MAX_BREADCRUMBS),
87
- tags: { ...options.tags, ...captureContext.tags },
87
+ breadcrumbs: sanitize(breadcrumbs.slice(-MAX_BREADCRUMBS)),
88
+ tags: sanitize({ ...options.tags, ...captureContext.tags }),
88
89
  context: sanitize(captureContext.context ?? {}) ?? {}
89
90
  };
90
91
  }
package/dist/index.cjs CHANGED
@@ -25,12 +25,11 @@ __export(index_exports, {
25
25
  module.exports = __toCommonJS(index_exports);
26
26
 
27
27
  // src/shared.ts
28
+ var import_error_mom_protocol = require("@kenkaiiii/error-mom-protocol");
28
29
  var SDK_NAME = "@kenkaiiii/error-mom";
29
- var SDK_VERSION = "0.3.1";
30
+ var SDK_VERSION = "0.3.3";
30
31
  var MAX_BREADCRUMBS = 50;
31
32
  var SECRET_KEY = /authorization|cookie|password|passwd|secret|token|api[-_]?key|session/i;
32
- var URL_CREDENTIAL = /([?&](?:token|key|secret|password|code)=)[^&\s]*/gi;
33
- var EMAIL = /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi;
34
33
  function wrapFunction(capture, fn, context) {
35
34
  return (...args) => {
36
35
  try {
@@ -49,7 +48,7 @@ function wrapFunction(capture, fn, context) {
49
48
  };
50
49
  }
51
50
  function redactString(value) {
52
- return value.replace(URL_CREDENTIAL, "$1[REDACTED]").replace(EMAIL, "[REDACTED_EMAIL]");
51
+ return (0, import_error_mom_protocol.redactStringCredentials)(value);
53
52
  }
54
53
  function sanitize(value, depth = 0) {
55
54
  if (depth > 5) return "[TRUNCATED]";
@@ -109,8 +108,8 @@ function createEvent(value, options, breadcrumbs, runtime, captureContext = {})
109
108
  ...typeof location !== "undefined" ? { url: redactString(location.href) } : {},
110
109
  ...captureContext.culprit ? { culprit: redactString(captureContext.culprit) } : {},
111
110
  ...options.installationId ? { installationId: options.installationId } : {},
112
- breadcrumbs: breadcrumbs.slice(-MAX_BREADCRUMBS),
113
- tags: { ...options.tags, ...captureContext.tags },
111
+ breadcrumbs: sanitize(breadcrumbs.slice(-MAX_BREADCRUMBS)),
112
+ tags: sanitize({ ...options.tags, ...captureContext.tags }),
114
113
  context: sanitize(captureContext.context ?? {}) ?? {}
115
114
  };
116
115
  }
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  printable,
9
9
  redactString,
10
10
  wrapFunction
11
- } from "./chunk-W4XR2RLN.js";
11
+ } from "./chunk-UNG24UNX.js";
12
12
 
13
13
  // src/index.ts
14
14
  var clients = /* @__PURE__ */ new Map();
package/dist/node.cjs CHANGED
@@ -24,17 +24,17 @@ __export(node_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(node_exports);
26
26
  var import_node_crypto = require("crypto");
27
+ var import_node_fs = require("fs");
27
28
  var import_promises = require("fs/promises");
28
29
  var import_node_os = require("os");
29
30
  var import_node_path = require("path");
30
31
 
31
32
  // src/shared.ts
33
+ var import_error_mom_protocol = require("@kenkaiiii/error-mom-protocol");
32
34
  var SDK_NAME = "@kenkaiiii/error-mom";
33
- var SDK_VERSION = "0.3.1";
35
+ var SDK_VERSION = "0.3.3";
34
36
  var MAX_BREADCRUMBS = 50;
35
37
  var SECRET_KEY = /authorization|cookie|password|passwd|secret|token|api[-_]?key|session/i;
36
- var URL_CREDENTIAL = /([?&](?:token|key|secret|password|code)=)[^&\s]*/gi;
37
- var EMAIL = /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi;
38
38
  function wrapFunction(capture, fn, context) {
39
39
  return (...args) => {
40
40
  try {
@@ -53,7 +53,7 @@ function wrapFunction(capture, fn, context) {
53
53
  };
54
54
  }
55
55
  function redactString(value) {
56
- return value.replace(URL_CREDENTIAL, "$1[REDACTED]").replace(EMAIL, "[REDACTED_EMAIL]");
56
+ return (0, import_error_mom_protocol.redactStringCredentials)(value);
57
57
  }
58
58
  function sanitize(value, depth = 0) {
59
59
  if (depth > 5) return "[TRUNCATED]";
@@ -113,8 +113,8 @@ function createEvent(value, options, breadcrumbs, runtime, captureContext = {})
113
113
  ...typeof location !== "undefined" ? { url: redactString(location.href) } : {},
114
114
  ...captureContext.culprit ? { culprit: redactString(captureContext.culprit) } : {},
115
115
  ...options.installationId ? { installationId: options.installationId } : {},
116
- breadcrumbs: breadcrumbs.slice(-MAX_BREADCRUMBS),
117
- tags: { ...options.tags, ...captureContext.tags },
116
+ breadcrumbs: sanitize(breadcrumbs.slice(-MAX_BREADCRUMBS)),
117
+ tags: sanitize({ ...options.tags, ...captureContext.tags }),
118
118
  context: sanitize(captureContext.context ?? {}) ?? {}
119
119
  };
120
120
  }
@@ -297,10 +297,25 @@ var NodeClient = class {
297
297
  const onRejection = (reason) => {
298
298
  this.captureError(reason, { culprit: "unhandledRejection" });
299
299
  };
300
+ const onExit = () => {
301
+ this.persistQueueSync();
302
+ };
300
303
  process.on("uncaughtExceptionMonitor", onUncaught);
301
304
  process.on("unhandledRejection", onRejection);
305
+ process.on("exit", onExit);
302
306
  this.handlers.push(() => process.off("uncaughtExceptionMonitor", onUncaught));
303
307
  this.handlers.push(() => process.off("unhandledRejection", onRejection));
308
+ this.handlers.push(() => process.off("exit", onExit));
309
+ }
310
+ persistQueueSync() {
311
+ if (this.queue.length === 0) return;
312
+ try {
313
+ (0, import_node_fs.mkdirSync)(this.options.spoolDirectory, { recursive: true });
314
+ const contents = this.queue.map((event) => JSON.stringify(event)).join("\n");
315
+ (0, import_node_fs.writeFileSync)(this.spoolFile, `${contents}
316
+ `, { mode: 384 });
317
+ } catch {
318
+ }
304
319
  }
305
320
  captureFetchFailures() {
306
321
  if (this.options.captureFailedRequests === false || typeof fetch === "undefined") return;
package/dist/node.js CHANGED
@@ -8,10 +8,11 @@ import {
8
8
  printable,
9
9
  redactString,
10
10
  wrapFunction
11
- } from "./chunk-W4XR2RLN.js";
11
+ } from "./chunk-UNG24UNX.js";
12
12
 
13
13
  // src/node.ts
14
14
  import { createHash } from "crypto";
15
+ import { mkdirSync, writeFileSync } from "fs";
15
16
  import { mkdir, readFile, rename, writeFile, appendFile } from "fs/promises";
16
17
  import { homedir } from "os";
17
18
  import { join } from "path";
@@ -108,10 +109,25 @@ var NodeClient = class {
108
109
  const onRejection = (reason) => {
109
110
  this.captureError(reason, { culprit: "unhandledRejection" });
110
111
  };
112
+ const onExit = () => {
113
+ this.persistQueueSync();
114
+ };
111
115
  process.on("uncaughtExceptionMonitor", onUncaught);
112
116
  process.on("unhandledRejection", onRejection);
117
+ process.on("exit", onExit);
113
118
  this.handlers.push(() => process.off("uncaughtExceptionMonitor", onUncaught));
114
119
  this.handlers.push(() => process.off("unhandledRejection", onRejection));
120
+ this.handlers.push(() => process.off("exit", onExit));
121
+ }
122
+ persistQueueSync() {
123
+ if (this.queue.length === 0) return;
124
+ try {
125
+ mkdirSync(this.options.spoolDirectory, { recursive: true });
126
+ const contents = this.queue.map((event) => JSON.stringify(event)).join("\n");
127
+ writeFileSync(this.spoolFile, `${contents}
128
+ `, { mode: 384 });
129
+ } catch {
130
+ }
115
131
  }
116
132
  captureFetchFailures() {
117
133
  if (this.options.captureFailedRequests === false || typeof fetch === "undefined") return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kenkaiiii/error-mom",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Automatic browser and Node.js error capture for self-hosted Error Mom",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -22,7 +22,7 @@
22
22
  "README.md"
23
23
  ],
24
24
  "dependencies": {
25
- "@kenkaiiii/error-mom-protocol": "0.1.0"
25
+ "@kenkaiiii/error-mom-protocol": "0.1.1"
26
26
  },
27
27
  "devDependencies": {
28
28
  "tsup": "^8.5.1",