@kenkaiiii/error-mom 0.1.0 → 0.2.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/dist/{chunk-ORM4B33R.js → chunk-K7IF6NNK.js} +55 -2
- package/dist/index.js +4 -10
- package/dist/node.d.ts +1 -0
- package/dist/node.js +30 -3
- package/package.json +9 -9
- package/LICENSE +0 -21
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/shared.ts
|
|
2
2
|
var SDK_NAME = "@kenkaiiii/error-mom";
|
|
3
|
-
var SDK_VERSION = "0.
|
|
3
|
+
var SDK_VERSION = "0.2.0";
|
|
4
4
|
var MAX_BREADCRUMBS = 50;
|
|
5
5
|
var SECRET_KEY = /authorization|cookie|password|passwd|secret|token|api[-_]?key|session/i;
|
|
6
6
|
var URL_CREDENTIAL = /([?&](?:token|key|secret|password|code)=)[^&\s]*/gi;
|
|
@@ -74,6 +74,58 @@ function createEvent(value, options, breadcrumbs, runtime, captureContext = {})
|
|
|
74
74
|
function endpoint(server) {
|
|
75
75
|
return `${server.replace(/\/$/, "")}/api/v1/events`;
|
|
76
76
|
}
|
|
77
|
+
var AI_PROVIDERS = [
|
|
78
|
+
[/(^|\.)api\.anthropic\.com$/, "anthropic"],
|
|
79
|
+
[/(^|\.)api\.openai\.com$/, "openai"],
|
|
80
|
+
[/(^|\.)openai\.azure\.com$/, "azure-openai"],
|
|
81
|
+
[/(^|\.)generativelanguage\.googleapis\.com$/, "google"],
|
|
82
|
+
[/(^|\.)aiplatform\.googleapis\.com$/, "google-vertex"],
|
|
83
|
+
[/(^|\.)bedrock(-runtime)?[.\w-]*\.amazonaws\.com$/, "aws-bedrock"],
|
|
84
|
+
[/(^|\.)api\.mistral\.ai$/, "mistral"],
|
|
85
|
+
[/(^|\.)api\.groq\.com$/, "groq"],
|
|
86
|
+
[/(^|\.)api\.deepseek\.com$/, "deepseek"],
|
|
87
|
+
[/(^|\.)api\.x\.ai$/, "xai"],
|
|
88
|
+
[/(^|\.)openrouter\.ai$/, "openrouter"],
|
|
89
|
+
[/(^|\.)api\.together\.(xyz|ai)$/, "together"],
|
|
90
|
+
[/(^|\.)api\.fireworks\.ai$/, "fireworks"],
|
|
91
|
+
[/(^|\.)api\.cohere\.(ai|com)$/, "cohere"],
|
|
92
|
+
[/(^|\.)api\.perplexity\.ai$/, "perplexity"],
|
|
93
|
+
[/(^|\.)api\.replicate\.com$/, "replicate"],
|
|
94
|
+
[/(^|\.)api-inference\.huggingface\.co$/, "huggingface"],
|
|
95
|
+
[/(^|\.)api\.elevenlabs\.io$/, "elevenlabs"]
|
|
96
|
+
];
|
|
97
|
+
function providerForUrl(url) {
|
|
98
|
+
try {
|
|
99
|
+
const hostname = new URL(url).hostname;
|
|
100
|
+
for (const [pattern, provider] of AI_PROVIDERS) {
|
|
101
|
+
if (pattern.test(hostname)) return provider;
|
|
102
|
+
}
|
|
103
|
+
} catch {
|
|
104
|
+
}
|
|
105
|
+
return void 0;
|
|
106
|
+
}
|
|
107
|
+
function describeFailedRequest(method, url, status) {
|
|
108
|
+
const provider = providerForUrl(url);
|
|
109
|
+
const relevant = status >= 500 || provider !== void 0 && status >= 400;
|
|
110
|
+
if (!relevant) return void 0;
|
|
111
|
+
const cleanUrl = redactString(url);
|
|
112
|
+
const error = new Error(`${method} ${cleanUrl} returned ${status}`);
|
|
113
|
+
if (provider) {
|
|
114
|
+
const label = provider.charAt(0).toUpperCase() + provider.slice(1);
|
|
115
|
+
error.name = `${label.replace(/-(\w)/g, (_, c) => c.toUpperCase())}ApiError`;
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
error,
|
|
119
|
+
context: {
|
|
120
|
+
culprit: "fetch",
|
|
121
|
+
tags: {
|
|
122
|
+
statusCode: String(status),
|
|
123
|
+
method,
|
|
124
|
+
...provider ? { provider } : {}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
77
129
|
|
|
78
130
|
export {
|
|
79
131
|
SDK_NAME,
|
|
@@ -82,5 +134,6 @@ export {
|
|
|
82
134
|
redactString,
|
|
83
135
|
printable,
|
|
84
136
|
createEvent,
|
|
85
|
-
endpoint
|
|
137
|
+
endpoint,
|
|
138
|
+
describeFailedRequest
|
|
86
139
|
};
|
package/dist/index.js
CHANGED
|
@@ -3,10 +3,11 @@ import {
|
|
|
3
3
|
SDK_NAME,
|
|
4
4
|
SDK_VERSION,
|
|
5
5
|
createEvent,
|
|
6
|
+
describeFailedRequest,
|
|
6
7
|
endpoint,
|
|
7
8
|
printable,
|
|
8
9
|
redactString
|
|
9
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-K7IF6NNK.js";
|
|
10
11
|
|
|
11
12
|
// src/index.ts
|
|
12
13
|
var clients = /* @__PURE__ */ new Map();
|
|
@@ -138,15 +139,8 @@ var BrowserClient = class {
|
|
|
138
139
|
const method = init?.method ?? (input instanceof Request ? input.method : "GET");
|
|
139
140
|
try {
|
|
140
141
|
const response = await original(input, init);
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
new Error(`${method} ${redactString(url)} returned ${response.status}`),
|
|
144
|
-
{
|
|
145
|
-
culprit: "fetch",
|
|
146
|
-
tags: { statusCode: String(response.status), method }
|
|
147
|
-
}
|
|
148
|
-
);
|
|
149
|
-
}
|
|
142
|
+
const failure = describeFailedRequest(method, url, response.status);
|
|
143
|
+
if (failure) this.captureError(failure.error, failure.context);
|
|
150
144
|
return response;
|
|
151
145
|
} catch (error) {
|
|
152
146
|
this.captureError(error, { culprit: "fetch", tags: { method, url: redactString(url) } });
|
package/dist/node.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { Breadcrumb, ErrorEvent } from '@kenkaiiii/error-mom-protocol';
|
|
|
3
3
|
import { a as CaptureContext, C as CommonOptions } from './shared-idwux7-h.js';
|
|
4
4
|
|
|
5
5
|
interface NodeOptions extends CommonOptions {
|
|
6
|
+
captureFailedRequests?: boolean;
|
|
6
7
|
spoolDirectory?: string;
|
|
7
8
|
flushIntervalMs?: number;
|
|
8
9
|
maxQueueSize?: number;
|
package/dist/node.js
CHANGED
|
@@ -3,9 +3,11 @@ import {
|
|
|
3
3
|
SDK_NAME,
|
|
4
4
|
SDK_VERSION,
|
|
5
5
|
createEvent,
|
|
6
|
+
describeFailedRequest,
|
|
6
7
|
endpoint,
|
|
7
|
-
printable
|
|
8
|
-
|
|
8
|
+
printable,
|
|
9
|
+
redactString
|
|
10
|
+
} from "./chunk-K7IF6NNK.js";
|
|
9
11
|
|
|
10
12
|
// src/node.ts
|
|
11
13
|
import { createHash } from "crypto";
|
|
@@ -21,6 +23,7 @@ var NodeClient = class {
|
|
|
21
23
|
spoolFile;
|
|
22
24
|
handlers = [];
|
|
23
25
|
flushPromise;
|
|
26
|
+
nativeFetch;
|
|
24
27
|
constructor(options) {
|
|
25
28
|
this.options = {
|
|
26
29
|
...options,
|
|
@@ -33,6 +36,7 @@ var NodeClient = class {
|
|
|
33
36
|
this.operation = this.restoreQueue();
|
|
34
37
|
this.installProcessHandlers();
|
|
35
38
|
this.captureConsole();
|
|
39
|
+
this.captureFetchFailures();
|
|
36
40
|
this.interval = setInterval(() => void this.flush(), this.options.flushIntervalMs);
|
|
37
41
|
void this.flush();
|
|
38
42
|
}
|
|
@@ -70,7 +74,8 @@ var NodeClient = class {
|
|
|
70
74
|
if (this.queue.length === 0) return;
|
|
71
75
|
const batch = this.queue.slice(0, 50);
|
|
72
76
|
try {
|
|
73
|
-
const
|
|
77
|
+
const transport = this.nativeFetch ?? fetch;
|
|
78
|
+
const response = await transport(endpoint(this.options.server), {
|
|
74
79
|
method: "POST",
|
|
75
80
|
headers: {
|
|
76
81
|
"content-type": "application/json",
|
|
@@ -104,6 +109,28 @@ var NodeClient = class {
|
|
|
104
109
|
this.handlers.push(() => process.off("uncaughtExceptionMonitor", onUncaught));
|
|
105
110
|
this.handlers.push(() => process.off("unhandledRejection", onRejection));
|
|
106
111
|
}
|
|
112
|
+
captureFetchFailures() {
|
|
113
|
+
if (this.options.captureFailedRequests === false || typeof fetch === "undefined") return;
|
|
114
|
+
const original = fetch.bind(globalThis);
|
|
115
|
+
this.nativeFetch = original;
|
|
116
|
+
globalThis.fetch = (async (input, init) => {
|
|
117
|
+
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
118
|
+
if (url.startsWith(this.options.server)) return original(input, init);
|
|
119
|
+
const method = init?.method ?? (input instanceof Request ? input.method : "GET");
|
|
120
|
+
try {
|
|
121
|
+
const response = await original(input, init);
|
|
122
|
+
const failure = describeFailedRequest(method, url, response.status);
|
|
123
|
+
if (failure) this.captureError(failure.error, failure.context);
|
|
124
|
+
return response;
|
|
125
|
+
} catch (error) {
|
|
126
|
+
this.captureError(error, { culprit: "fetch", tags: { method, url: redactString(url) } });
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
this.handlers.push(() => {
|
|
131
|
+
globalThis.fetch = original;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
107
134
|
captureConsole() {
|
|
108
135
|
const levels = ["debug", "info", "warn", "error"];
|
|
109
136
|
for (const level of levels) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kenkaiiii/error-mom",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Automatic browser and Node.js error capture for self-hosted Error Mom",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -19,8 +19,13 @@
|
|
|
19
19
|
"dist",
|
|
20
20
|
"README.md"
|
|
21
21
|
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsup src/index.ts src/node.ts --format esm --dts --clean",
|
|
24
|
+
"check": "tsc --noEmit",
|
|
25
|
+
"test": "vitest run"
|
|
26
|
+
},
|
|
22
27
|
"dependencies": {
|
|
23
|
-
"@kenkaiiii/error-mom-protocol": "
|
|
28
|
+
"@kenkaiiii/error-mom-protocol": "workspace:*"
|
|
24
29
|
},
|
|
25
30
|
"devDependencies": {
|
|
26
31
|
"tsup": "^8.5.1",
|
|
@@ -29,10 +34,5 @@
|
|
|
29
34
|
"publishConfig": {
|
|
30
35
|
"access": "public"
|
|
31
36
|
},
|
|
32
|
-
"license": "MIT"
|
|
33
|
-
|
|
34
|
-
"build": "tsup src/index.ts src/node.ts --format esm --dts --clean",
|
|
35
|
-
"check": "tsc --noEmit",
|
|
36
|
-
"test": "vitest run"
|
|
37
|
-
}
|
|
38
|
-
}
|
|
37
|
+
"license": "MIT"
|
|
38
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Ken Kai
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|