@kenkaiiii/error-mom 0.2.1 → 0.3.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-TWQL6IMO.js → chunk-LFQHPPHR.js} +49 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +6 -2
- package/dist/node.d.ts +1 -0
- package/dist/node.js +6 -2
- package/package.json +1 -1
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
// src/shared.ts
|
|
2
2
|
var SDK_NAME = "@kenkaiiii/error-mom";
|
|
3
|
-
var SDK_VERSION = "0.
|
|
3
|
+
var SDK_VERSION = "0.3.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;
|
|
7
7
|
var EMAIL = /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi;
|
|
8
|
+
function wrapFunction(capture, fn, context) {
|
|
9
|
+
return (...args) => {
|
|
10
|
+
try {
|
|
11
|
+
const result = fn(...args);
|
|
12
|
+
if (result instanceof Promise) {
|
|
13
|
+
return result.catch((error) => {
|
|
14
|
+
capture(error, context);
|
|
15
|
+
throw error;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
capture(error, context);
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
8
25
|
function redactString(value) {
|
|
9
26
|
return value.replace(URL_CREDENTIAL, "$1[REDACTED]").replace(EMAIL, "[REDACTED_EMAIL]");
|
|
10
27
|
}
|
|
@@ -92,7 +109,36 @@ var AI_PROVIDERS = [
|
|
|
92
109
|
[/(^|\.)api\.perplexity\.ai$/, "perplexity"],
|
|
93
110
|
[/(^|\.)api\.replicate\.com$/, "replicate"],
|
|
94
111
|
[/(^|\.)api-inference\.huggingface\.co$/, "huggingface"],
|
|
95
|
-
[/(^|\.)
|
|
112
|
+
[/(^|\.)router\.huggingface\.co$/, "huggingface"],
|
|
113
|
+
[/(^|\.)api\.elevenlabs\.io$/, "elevenlabs"],
|
|
114
|
+
[/(^|\.)api\.moonshot\.(ai|cn)$/, "moonshot"],
|
|
115
|
+
[/(^|\.)api\.kimi\.com$/, "moonshot"],
|
|
116
|
+
[/(^|\.)api\.z\.ai$/, "zai"],
|
|
117
|
+
[/(^|\.)open\.bigmodel\.cn$/, "zai"],
|
|
118
|
+
[/(^|\.)dashscope(-intl)?\.aliyuncs\.com$/, "qwen"],
|
|
119
|
+
[/(^|\.)api\.minimax(i)?\.(chat|com|io)$/, "minimax"],
|
|
120
|
+
[/(^|\.)api\.lingyiwanwu\.com$/, "yi"],
|
|
121
|
+
[/(^|\.)api\.stepfun\.com$/, "stepfun"],
|
|
122
|
+
[/(^|\.)api\.baichuan-ai\.com$/, "baichuan"],
|
|
123
|
+
[/(^|\.)api\.siliconflow\.(cn|com)$/, "siliconflow"],
|
|
124
|
+
[/(^|\.)api\.cerebras\.ai$/, "cerebras"],
|
|
125
|
+
[/(^|\.)api\.sambanova\.ai$/, "sambanova"],
|
|
126
|
+
[/(^|\.)api\.deepinfra\.com$/, "deepinfra"],
|
|
127
|
+
[/(^|\.)api\.novita\.ai$/, "novita"],
|
|
128
|
+
[/(^|\.)api\.hyperbolic\.xyz$/, "hyperbolic"],
|
|
129
|
+
[/(^|\.)api\.studio\.nebius\.(ai|com)$/, "nebius"],
|
|
130
|
+
[/(^|\.)models\.inference\.ai\.azure\.com$/, "github-models"],
|
|
131
|
+
[/(^|\.)models\.github\.ai$/, "github-models"],
|
|
132
|
+
[/(^|\.)ai-gateway\.vercel\.sh$/, "vercel-ai-gateway"],
|
|
133
|
+
[/(^|\.)gateway\.ai\.cloudflare\.com$/, "cloudflare-ai-gateway"],
|
|
134
|
+
[/(^|\.)api\.voyageai\.com$/, "voyage"],
|
|
135
|
+
[/(^|\.)api\.jina\.ai$/, "jina"],
|
|
136
|
+
[/(^|\.)api\.stability\.ai$/, "stability"],
|
|
137
|
+
[/(^|\.)(queue\.)?fal\.run$/, "fal"],
|
|
138
|
+
[/(^|\.)api\.assemblyai\.com$/, "assemblyai"],
|
|
139
|
+
[/(^|\.)api\.deepgram\.com$/, "deepgram"],
|
|
140
|
+
[/(^|\.)api\.lumalabs\.ai$/, "luma"],
|
|
141
|
+
[/(^|\.)api\.dev\.runwayml\.com$/, "runway"]
|
|
96
142
|
];
|
|
97
143
|
function providerForUrl(url) {
|
|
98
144
|
try {
|
|
@@ -131,6 +177,7 @@ export {
|
|
|
131
177
|
SDK_NAME,
|
|
132
178
|
SDK_VERSION,
|
|
133
179
|
MAX_BREADCRUMBS,
|
|
180
|
+
wrapFunction,
|
|
134
181
|
redactString,
|
|
135
182
|
printable,
|
|
136
183
|
createEvent,
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ interface BrowserOptions extends CommonOptions {
|
|
|
9
9
|
}
|
|
10
10
|
interface ErrorMomBrowser {
|
|
11
11
|
captureError(error: unknown, context?: CaptureContext): string;
|
|
12
|
+
wrap<A extends unknown[], R>(fn: (...args: A) => R, context?: CaptureContext): (...args: A) => R;
|
|
12
13
|
addBreadcrumb(breadcrumb: Omit<Breadcrumb, "timestamp"> & {
|
|
13
14
|
timestamp?: string;
|
|
14
15
|
}): void;
|
package/dist/index.js
CHANGED
|
@@ -6,8 +6,9 @@ import {
|
|
|
6
6
|
describeFailedRequest,
|
|
7
7
|
endpoint,
|
|
8
8
|
printable,
|
|
9
|
-
redactString
|
|
10
|
-
|
|
9
|
+
redactString,
|
|
10
|
+
wrapFunction
|
|
11
|
+
} from "./chunk-LFQHPPHR.js";
|
|
11
12
|
|
|
12
13
|
// src/index.ts
|
|
13
14
|
var clients = /* @__PURE__ */ new Map();
|
|
@@ -42,6 +43,9 @@ var BrowserClient = class {
|
|
|
42
43
|
void this.flush();
|
|
43
44
|
return event.eventId;
|
|
44
45
|
}
|
|
46
|
+
wrap(fn, context) {
|
|
47
|
+
return wrapFunction((error, ctx) => this.captureError(error, ctx), fn, context);
|
|
48
|
+
}
|
|
45
49
|
addBreadcrumb(input) {
|
|
46
50
|
this.breadcrumbs.push({
|
|
47
51
|
...input,
|
package/dist/node.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ interface NodeOptions extends CommonOptions {
|
|
|
10
10
|
}
|
|
11
11
|
interface ErrorMomNode {
|
|
12
12
|
captureError(error: unknown, context?: CaptureContext): string;
|
|
13
|
+
wrap<A extends unknown[], R>(fn: (...args: A) => R, context?: CaptureContext): (...args: A) => R;
|
|
13
14
|
addBreadcrumb(breadcrumb: Omit<Breadcrumb, "timestamp"> & {
|
|
14
15
|
timestamp?: string;
|
|
15
16
|
}): void;
|
package/dist/node.js
CHANGED
|
@@ -6,8 +6,9 @@ import {
|
|
|
6
6
|
describeFailedRequest,
|
|
7
7
|
endpoint,
|
|
8
8
|
printable,
|
|
9
|
-
redactString
|
|
10
|
-
|
|
9
|
+
redactString,
|
|
10
|
+
wrapFunction
|
|
11
|
+
} from "./chunk-LFQHPPHR.js";
|
|
11
12
|
|
|
12
13
|
// src/node.ts
|
|
13
14
|
import { createHash } from "crypto";
|
|
@@ -58,6 +59,9 @@ var NodeClient = class {
|
|
|
58
59
|
void this.flush();
|
|
59
60
|
return event.eventId;
|
|
60
61
|
}
|
|
62
|
+
wrap(fn, context) {
|
|
63
|
+
return wrapFunction((error, ctx) => this.captureError(error, ctx), fn, context);
|
|
64
|
+
}
|
|
61
65
|
addBreadcrumb(input) {
|
|
62
66
|
this.breadcrumbs.push({ ...input, timestamp: input.timestamp ?? (/* @__PURE__ */ new Date()).toISOString() });
|
|
63
67
|
if (this.breadcrumbs.length > MAX_BREADCRUMBS) this.breadcrumbs.shift();
|