@interfere/types 8.1.0 → 8.1.1
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/sdk/errors.d.mts +9 -1
- package/dist/sdk/errors.d.mts.map +1 -1
- package/dist/sdk/errors.mjs +24 -1
- package/dist/sdk/errors.mjs.map +1 -1
- package/package.json +5 -5
package/dist/sdk/errors.d.mts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { ErrorMechanism, ExceptionValue } from "#sdk/plugins/payload/errors";
|
|
2
2
|
|
|
3
3
|
//#region src/sdk/errors.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* True when the root exception has at least one stack frame whose `fileName` is
|
|
6
|
+
* a browser-extension script URL. Covers extension-only stacks, extension
|
|
7
|
+
* interceptors (extension frames above app), and app errors whose stack still
|
|
8
|
+
* includes extension code (e.g. hydration) — stacks with no filenames are
|
|
9
|
+
* unchanged (returns false).
|
|
10
|
+
*/
|
|
11
|
+
declare function shouldDropBrowserExtensionNoise(exceptions: readonly ExceptionValue[]): boolean;
|
|
4
12
|
declare function toError(error: unknown): Error;
|
|
5
13
|
declare function toExceptions(error: Error, mechanism: ErrorMechanism): ExceptionValue[];
|
|
6
14
|
declare function extractFilenameFromStack(stack: string): string | null;
|
|
7
15
|
//#endregion
|
|
8
|
-
export { extractFilenameFromStack, toError, toExceptions };
|
|
16
|
+
export { extractFilenameFromStack, shouldDropBrowserExtensionNoise, toError, toExceptions };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.mts","names":[],"sources":["../../src/sdk/errors.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.d.mts","names":[],"sources":["../../src/sdk/errors.ts"],"mappings":";;;;;AA8BA;;;;;iBAAgB,+BAAA,CACd,UAAA,WAAqB,cAAA;AAAA,iBAkBP,OAAA,CAAQ,KAAA,YAAiB,KAAA;AAAA,iBAYzB,YAAA,CACd,KAAA,EAAO,KAAA,EACP,SAAA,EAAW,cAAA,GACV,cAAA;AAAA,iBAwDa,wBAAA,CAAyB,KAAA"}
|
package/dist/sdk/errors.mjs
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
import { parse } from "error-stack-parser-es";
|
|
2
2
|
//#region src/sdk/errors.ts
|
|
3
|
+
/** URL schemes used by browser extensions in stack frame `fileName` values. */
|
|
4
|
+
const BROWSER_EXTENSION_SCRIPT_URL_PREFIXES = [
|
|
5
|
+
"chrome-extension://",
|
|
6
|
+
"moz-extension://",
|
|
7
|
+
"safari-web-extension://",
|
|
8
|
+
"safari-extension://",
|
|
9
|
+
"ms-browser-extension://"
|
|
10
|
+
];
|
|
11
|
+
function isExtensionOriginated({ fileName }) {
|
|
12
|
+
return BROWSER_EXTENSION_SCRIPT_URL_PREFIXES.some((prefix) => fileName?.startsWith(prefix) ?? false);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* True when the root exception has at least one stack frame whose `fileName` is
|
|
16
|
+
* a browser-extension script URL. Covers extension-only stacks, extension
|
|
17
|
+
* interceptors (extension frames above app), and app errors whose stack still
|
|
18
|
+
* includes extension code (e.g. hydration) — stacks with no filenames are
|
|
19
|
+
* unchanged (returns false).
|
|
20
|
+
*/
|
|
21
|
+
function shouldDropBrowserExtensionNoise(exceptions) {
|
|
22
|
+
const frames = exceptions[0]?.frames;
|
|
23
|
+
if (!frames?.length) return false;
|
|
24
|
+
return frames.some(isExtensionOriginated);
|
|
25
|
+
}
|
|
3
26
|
const MAX_CAUSE_DEPTH = 5;
|
|
4
27
|
const PAREN_FILE_RE = /\((.+?)(?::\d+){1,2}\)/;
|
|
5
28
|
const AT_FILE_RE = /at\s+(.+?)(?::\d+){1,2}$/;
|
|
@@ -65,4 +88,4 @@ function normalizeFrame(frame, debugIdMap) {
|
|
|
65
88
|
};
|
|
66
89
|
}
|
|
67
90
|
//#endregion
|
|
68
|
-
export { extractFilenameFromStack, toError, toExceptions };
|
|
91
|
+
export { extractFilenameFromStack, shouldDropBrowserExtensionNoise, toError, toExceptions };
|
package/dist/sdk/errors.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.mjs","names":[],"sources":["../../src/sdk/errors.ts"],"sourcesContent":["import { parse } from \"error-stack-parser-es\";\n\nimport type { IngestedFrame } from \"#data/frame\";\nimport type {\n ErrorMechanism,\n ExceptionValue,\n} from \"#sdk/plugins/payload/errors\";\n\nconst MAX_CAUSE_DEPTH = 5;\n\nconst PAREN_FILE_RE = /\\((.+?)(?::\\d+){1,2}\\)/;\nconst AT_FILE_RE = /at\\s+(.+?)(?::\\d+){1,2}$/;\nconst SPIDERMONKEY_RE = /(?:^|@)((?:https?:\\/\\/|\\/).+?)(?::\\d+){1,2}$/;\nconst BARE_FILE_RE = /(?:^|@)(.+?)(?::\\d+){1,2}$/;\n\nexport function toError(error: unknown): Error {\n if (error instanceof Error) {\n return error;\n }\n\n if (typeof error === \"string\") {\n return new Error(error);\n }\n\n return new Error(String(error));\n}\n\nexport function toExceptions(\n error: Error,\n mechanism: ErrorMechanism\n): ExceptionValue[] {\n const debugIdMap = getDebugIdMap();\n const exceptions: ExceptionValue[] = [];\n let current: Error | undefined = error;\n\n for (let depth = 0; current && depth < MAX_CAUSE_DEPTH; depth += 1) {\n exceptions.push({\n type: current.name,\n value: current.message,\n mechanism: depth === 0 ? mechanism : undefined,\n frames: parse(current, { allowEmpty: true }).map((frame) =>\n normalizeFrame(frame, debugIdMap)\n ),\n });\n\n current = current.cause instanceof Error ? current.cause : undefined;\n }\n\n return exceptions;\n}\n\nlet cachedDebugIdMap: Map<string, string> | undefined;\nlet cachedDebugIdCount = 0;\n\nfunction getDebugIdMap(): Map<string, string> {\n const registry = (globalThis as Record<string, unknown>)[\"_debugIds\"] as\n | Record<string, string>\n | undefined;\n\n if (!registry) {\n return new Map();\n }\n\n const entries = Object.keys(registry);\n if (cachedDebugIdMap && entries.length === cachedDebugIdCount) {\n return cachedDebugIdMap;\n }\n\n const map = new Map<string, string>();\n for (const stackKey of entries) {\n const debugId = registry[stackKey];\n if (!debugId) {\n continue;\n }\n\n const filename = extractFilenameFromStack(stackKey);\n if (filename) {\n map.set(filename, debugId);\n }\n }\n\n cachedDebugIdMap = map;\n cachedDebugIdCount = entries.length;\n return map;\n}\n\nexport function extractFilenameFromStack(stack: string): string | null {\n const lines = stack.split(\"\\n\");\n for (let i = lines.length - 1; i >= 0; i--) {\n const line = lines[i];\n if (!line) {\n continue;\n }\n const match =\n line.match(PAREN_FILE_RE) ??\n line.match(AT_FILE_RE) ??\n line.match(SPIDERMONKEY_RE) ??\n line.match(BARE_FILE_RE);\n\n if (match?.[1]) {\n return match[1].trim();\n }\n }\n return null;\n}\n\nfunction normalizeFrame(\n frame: {\n fileName?: unknown;\n functionName?: unknown;\n lineNumber?: unknown;\n columnNumber?: unknown;\n source?: unknown;\n },\n debugIdMap: Map<string, string>\n): IngestedFrame {\n const fileName =\n typeof frame.fileName === \"string\" ? frame.fileName : undefined;\n\n return {\n fileName,\n functionName:\n typeof frame.functionName === \"string\" ? frame.functionName : undefined,\n lineNumber:\n typeof frame.lineNumber === \"number\" ? frame.lineNumber : undefined,\n columnNumber:\n typeof frame.columnNumber === \"number\" ? frame.columnNumber : undefined,\n source: typeof frame.source === \"string\" ? frame.source : undefined,\n debugId: fileName ? debugIdMap.get(fileName) : undefined,\n };\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"errors.mjs","names":[],"sources":["../../src/sdk/errors.ts"],"sourcesContent":["import { parse } from \"error-stack-parser-es\";\n\nimport type { IngestedFrame } from \"#data/frame\";\nimport type {\n ErrorMechanism,\n ExceptionValue,\n} from \"#sdk/plugins/payload/errors\";\n\n/** URL schemes used by browser extensions in stack frame `fileName` values. */\nconst BROWSER_EXTENSION_SCRIPT_URL_PREFIXES: readonly string[] = [\n \"chrome-extension://\",\n \"moz-extension://\",\n \"safari-web-extension://\",\n \"safari-extension://\",\n \"ms-browser-extension://\",\n];\n\nfunction isExtensionOriginated({ fileName }: IngestedFrame): boolean {\n return BROWSER_EXTENSION_SCRIPT_URL_PREFIXES.some(\n (prefix) => fileName?.startsWith(prefix) ?? false\n );\n}\n\n/**\n * True when the root exception has at least one stack frame whose `fileName` is\n * a browser-extension script URL. Covers extension-only stacks, extension\n * interceptors (extension frames above app), and app errors whose stack still\n * includes extension code (e.g. hydration) — stacks with no filenames are\n * unchanged (returns false).\n */\nexport function shouldDropBrowserExtensionNoise(\n exceptions: readonly ExceptionValue[]\n): boolean {\n const frames = exceptions[0]?.frames;\n\n if (!frames?.length) {\n return false;\n }\n\n return frames.some(isExtensionOriginated);\n}\n\nconst MAX_CAUSE_DEPTH = 5;\n\nconst PAREN_FILE_RE = /\\((.+?)(?::\\d+){1,2}\\)/;\nconst AT_FILE_RE = /at\\s+(.+?)(?::\\d+){1,2}$/;\nconst SPIDERMONKEY_RE = /(?:^|@)((?:https?:\\/\\/|\\/).+?)(?::\\d+){1,2}$/;\nconst BARE_FILE_RE = /(?:^|@)(.+?)(?::\\d+){1,2}$/;\n\nexport function toError(error: unknown): Error {\n if (error instanceof Error) {\n return error;\n }\n\n if (typeof error === \"string\") {\n return new Error(error);\n }\n\n return new Error(String(error));\n}\n\nexport function toExceptions(\n error: Error,\n mechanism: ErrorMechanism\n): ExceptionValue[] {\n const debugIdMap = getDebugIdMap();\n const exceptions: ExceptionValue[] = [];\n let current: Error | undefined = error;\n\n for (let depth = 0; current && depth < MAX_CAUSE_DEPTH; depth += 1) {\n exceptions.push({\n type: current.name,\n value: current.message,\n mechanism: depth === 0 ? mechanism : undefined,\n frames: parse(current, { allowEmpty: true }).map((frame) =>\n normalizeFrame(frame, debugIdMap)\n ),\n });\n\n current = current.cause instanceof Error ? current.cause : undefined;\n }\n\n return exceptions;\n}\n\nlet cachedDebugIdMap: Map<string, string> | undefined;\nlet cachedDebugIdCount = 0;\n\nfunction getDebugIdMap(): Map<string, string> {\n const registry = (globalThis as Record<string, unknown>)[\"_debugIds\"] as\n | Record<string, string>\n | undefined;\n\n if (!registry) {\n return new Map();\n }\n\n const entries = Object.keys(registry);\n if (cachedDebugIdMap && entries.length === cachedDebugIdCount) {\n return cachedDebugIdMap;\n }\n\n const map = new Map<string, string>();\n for (const stackKey of entries) {\n const debugId = registry[stackKey];\n if (!debugId) {\n continue;\n }\n\n const filename = extractFilenameFromStack(stackKey);\n if (filename) {\n map.set(filename, debugId);\n }\n }\n\n cachedDebugIdMap = map;\n cachedDebugIdCount = entries.length;\n return map;\n}\n\nexport function extractFilenameFromStack(stack: string): string | null {\n const lines = stack.split(\"\\n\");\n for (let i = lines.length - 1; i >= 0; i--) {\n const line = lines[i];\n if (!line) {\n continue;\n }\n const match =\n line.match(PAREN_FILE_RE) ??\n line.match(AT_FILE_RE) ??\n line.match(SPIDERMONKEY_RE) ??\n line.match(BARE_FILE_RE);\n\n if (match?.[1]) {\n return match[1].trim();\n }\n }\n return null;\n}\n\nfunction normalizeFrame(\n frame: {\n fileName?: unknown;\n functionName?: unknown;\n lineNumber?: unknown;\n columnNumber?: unknown;\n source?: unknown;\n },\n debugIdMap: Map<string, string>\n): IngestedFrame {\n const fileName =\n typeof frame.fileName === \"string\" ? frame.fileName : undefined;\n\n return {\n fileName,\n functionName:\n typeof frame.functionName === \"string\" ? frame.functionName : undefined,\n lineNumber:\n typeof frame.lineNumber === \"number\" ? frame.lineNumber : undefined,\n columnNumber:\n typeof frame.columnNumber === \"number\" ? frame.columnNumber : undefined,\n source: typeof frame.source === \"string\" ? frame.source : undefined,\n debugId: fileName ? debugIdMap.get(fileName) : undefined,\n };\n}\n"],"mappings":";;;AASA,MAAM,wCAA2D;CAC/D;CACA;CACA;CACA;CACA;CACD;AAED,SAAS,sBAAsB,EAAE,YAAoC;AACnE,QAAO,sCAAsC,MAC1C,WAAW,UAAU,WAAW,OAAO,IAAI,MAC7C;;;;;;;;;AAUH,SAAgB,gCACd,YACS;CACT,MAAM,SAAS,WAAW,IAAI;AAE9B,KAAI,CAAC,Q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AAM,MAAM,KAAK;AAC/B,MAAK,IAAI,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;EAC1C,MAAM,OAAO,MAAM;AACnB,MAAI,CAAC,KACH;EAEF,MAAM,QACJ,KAAK,MAAM,cAAc,IACzB,KAAK,MAAM,WAAW,IACtB,KAAK,MAAM,gBAAgB,IAC3B,KAAK,MAAM,aAAa;AAE1B,MAAI,QAAQ,GACV,QAAO,MAAM,GAAG,MAAM;;AAG1B,QAAO;;AAGT,SAAS,eACP,OAOA,YACe;CACf,MAAM,WACJ,OAAO,MAAM,aAAa,WAAW,MAAM,WAAW,KAAA;AAExD,QAAO;EACL;EACA,cACE,OAAO,MAAM,iBAAiB,WAAW,MAAM,eAAe,KAAA;EAChE,YACE,OAAO,MAAM,eAAe,WAAW,MAAM,aAAa,KAAA;EAC5D,cACE,OAAO,MAAM,iBAAiB,WAAW,MAAM,eAAe,KAAA;EAChE,QAAQ,OAAO,MAAM,WAAW,WAAW,MAAM,SAAS,KAAA;EAC1D,SAAS,WAAW,WAAW,IAAI,SAAS,GAAG,KAAA;EAChD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@interfere/types",
|
|
3
|
-
"version": "8.1.
|
|
3
|
+
"version": "8.1.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "TypeScript & Zod types for Interfere",
|
|
6
6
|
"keywords": [
|
|
@@ -111,12 +111,12 @@
|
|
|
111
111
|
"zod": "^4.3.6"
|
|
112
112
|
},
|
|
113
113
|
"devDependencies": {
|
|
114
|
-
"@interfere/typescript-config": "^8.1.0",
|
|
115
114
|
"@interfere/test-utils": "^1.0.0",
|
|
115
|
+
"@interfere/typescript-config": "^8.1.0",
|
|
116
116
|
"@types/node": "^24.12.0",
|
|
117
|
-
"@vitest/coverage-v8": "^4.1.
|
|
118
|
-
"tsdown": "^0.21.
|
|
117
|
+
"@vitest/coverage-v8": "^4.1.3",
|
|
118
|
+
"tsdown": "^0.21.7",
|
|
119
119
|
"typescript": "6.0.2",
|
|
120
|
-
"vitest": "^4.1.
|
|
120
|
+
"vitest": "^4.1.3"
|
|
121
121
|
}
|
|
122
122
|
}
|