@extn/segi-shared 0.2.0 → 0.2.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/event-dto.d.ts +7 -0
- package/dist/fingerprint.js +77 -3
- package/dist/index.d.ts +0 -1
- package/dist/index.js +10 -1
- package/package.json +1 -8
package/dist/event-dto.d.ts
CHANGED
|
@@ -43,6 +43,13 @@ export interface SegiEventDto {
|
|
|
43
43
|
}
|
|
44
44
|
export interface SegiClientOptions {
|
|
45
45
|
projectKey: string;
|
|
46
|
+
/**
|
|
47
|
+
* Default `true`. When `false`, init is a complete no-op: nothing is sent,
|
|
48
|
+
* no listeners or recorder are attached, and a later init with
|
|
49
|
+
* `enabled: true` still works. Every public method stays safe to call.
|
|
50
|
+
* Typical use: `enabled: process.env.NODE_ENV === "production"`.
|
|
51
|
+
*/
|
|
52
|
+
enabled?: boolean;
|
|
46
53
|
/** Optional. Defaults to the segi production ingestion endpoint. Override only when self-hosting. */
|
|
47
54
|
endpoint?: string;
|
|
48
55
|
environment?: string;
|
package/dist/fingerprint.js
CHANGED
|
@@ -7,18 +7,92 @@ function normalize(value) {
|
|
|
7
7
|
return "";
|
|
8
8
|
return value
|
|
9
9
|
.replace(/0x[0-9a-fA-F]+/g, "0xX")
|
|
10
|
+
// UUIDs and long hex blobs (release shas, content hashes) embedded in the
|
|
11
|
+
// message — e.g. ChunkLoadError's "Failed to load chunk https://…/<sha>/…"
|
|
12
|
+
// — change every deploy, so mask them before fingerprinting.
|
|
13
|
+
.replace(/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi, "U")
|
|
14
|
+
.replace(/\b[0-9a-f]{16,}\b/gi, "H")
|
|
10
15
|
.replace(/\b\d{4,}\b/g, "N")
|
|
11
16
|
.replace(/[\r\n]+/g, " ")
|
|
12
17
|
.trim()
|
|
13
18
|
.slice(0, 500);
|
|
14
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* A raw stack-trace line is volatile across deploys: the URL embeds a per-build
|
|
22
|
+
* release-hash directory (e.g. `/3774fa5b…/_next/…`) and the column shifts with
|
|
23
|
+
* minification, while the *shape* of the error (function + module + line) is
|
|
24
|
+
* stable. We canonicalize a frame to `func@path:line` with the host,
|
|
25
|
+
* release/content hashes and column stripped, so the same error groups into one
|
|
26
|
+
* issue across releases and across browser stack formats.
|
|
27
|
+
*/
|
|
28
|
+
/** A path segment that is a long hex blob — a release sha or content hash. */
|
|
29
|
+
function looksLikeHash(seg) {
|
|
30
|
+
return /^[0-9a-f]{16,}$/i.test(seg);
|
|
31
|
+
}
|
|
32
|
+
function canonicalizeLocation(loc) {
|
|
33
|
+
// strip protocol + host (CDN domain / port can vary)
|
|
34
|
+
let s = loc.replace(/^[a-z]+:\/\/[^/]+/i, "");
|
|
35
|
+
// strip trailing ":line:col" — keep the line, drop the minified column
|
|
36
|
+
let line = "";
|
|
37
|
+
const m = s.match(/^(.*?):(\d+):(\d+)$/);
|
|
38
|
+
if (m) {
|
|
39
|
+
s = m[1];
|
|
40
|
+
line = ":" + m[2];
|
|
41
|
+
}
|
|
42
|
+
// mask per-build release dirs / content-hash path segments
|
|
43
|
+
s = s
|
|
44
|
+
.split("/")
|
|
45
|
+
.map((seg) => (looksLikeHash(seg) ? "*" : seg))
|
|
46
|
+
.join("/");
|
|
47
|
+
// collapse webpack/Next content-hash suffix in the filename
|
|
48
|
+
// (e.g. `main-deadbeef12.js`, `chunk.deadbeef12.js`)
|
|
49
|
+
s = s.replace(/[-.][0-9a-f]{8,}(?=\.[cm]?[jt]sx?$)/i, "");
|
|
50
|
+
// collapse the per-build hash on known *runtime* bundles — turbopack/webpack
|
|
51
|
+
// name these `turbopack-<base36>.js` / `webpack-<hash>.js` etc. with a fresh
|
|
52
|
+
// token every deploy (unlike content chunks, whose names are stable). The
|
|
53
|
+
// hash here is base36, not hex, so the rule above doesn't catch it.
|
|
54
|
+
s = s.replace(/(\/(?:turbopack|webpack|runtime|main-app|framework|main|polyfills))-[a-z0-9_]+(\.[cm]?[jt]sx?)$/i, "$1$2");
|
|
55
|
+
return s + line;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Reduce one stack line to a stable `func@location` signature, handling both
|
|
59
|
+
* V8 (`at func (loc)` / `at loc`) and WebKit/Firefox (`func@loc` / `@loc`)
|
|
60
|
+
* formats. Returns null for non-source frames (`[native code]`, `<anonymous>`).
|
|
61
|
+
*/
|
|
62
|
+
function canonicalizeFrame(line) {
|
|
63
|
+
const l = line.trim();
|
|
64
|
+
if (!l || l.includes("[native code]"))
|
|
65
|
+
return null;
|
|
66
|
+
// V8: "at func (loc)" | "at loc"
|
|
67
|
+
const v8 = l.match(/^at\s+(?:(.*?)\s+\((.*)\)|(.*))$/);
|
|
68
|
+
if (v8) {
|
|
69
|
+
const func = (v8[1] ?? "").trim();
|
|
70
|
+
const loc = (v8[2] ?? v8[3] ?? "").trim();
|
|
71
|
+
if (!/:\d+:\d+$/.test(loc) && !/\.[cm]?[jt]sx?$/.test(loc))
|
|
72
|
+
return null;
|
|
73
|
+
return (func || "?") + "@" + canonicalizeLocation(loc);
|
|
74
|
+
}
|
|
75
|
+
// WebKit / Firefox: "func@loc" | "@loc"
|
|
76
|
+
if (l.includes("@")) {
|
|
77
|
+
const at = l.lastIndexOf("@");
|
|
78
|
+
const func = l.slice(0, at).trim();
|
|
79
|
+
const loc = l.slice(at + 1).trim();
|
|
80
|
+
if (!/:\d+:\d+$/.test(loc))
|
|
81
|
+
return null;
|
|
82
|
+
return (func || "?") + "@" + canonicalizeLocation(loc);
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
15
86
|
function topStackFrame(stack) {
|
|
16
87
|
if (!stack)
|
|
17
88
|
return "";
|
|
18
89
|
const lines = stack.split("\n").map((l) => l.trim()).filter(Boolean);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
90
|
+
for (const l of lines) {
|
|
91
|
+
const canon = canonicalizeFrame(l);
|
|
92
|
+
if (canon)
|
|
93
|
+
return canon.slice(0, 300);
|
|
94
|
+
}
|
|
95
|
+
return "";
|
|
22
96
|
}
|
|
23
97
|
function generateFingerprint(input) {
|
|
24
98
|
const parts = [
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -16,4 +16,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./event-dto"), exports);
|
|
18
18
|
__exportStar(require("./scrubber"), exports);
|
|
19
|
-
|
|
19
|
+
// NOTE: fingerprint.ts is NOT re-exported here. It uses Node's `crypto`
|
|
20
|
+
// module which the browser SDK bundle cannot resolve — tsup's
|
|
21
|
+
// `noExternal: ["@extn/segi-shared"]` was inlining the entire barrel,
|
|
22
|
+
// and the resulting dynamic `require("crypto")` shim threw at script
|
|
23
|
+
// load on every page that loaded segi.min.js (visible to consumers as
|
|
24
|
+
// `Uncaught Error: Dynamic require of "crypto" is not supported`).
|
|
25
|
+
//
|
|
26
|
+
// The server (apps/api event-queue) is the only legitimate caller of
|
|
27
|
+
// `generateFingerprint`; it imports from the explicit subpath
|
|
28
|
+
// `@extn/segi-shared/fingerprint`.
|
package/package.json
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@extn/segi-shared",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Shared types and utilities used by the segi SDKs",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"types": "./dist/index.d.ts",
|
|
11
|
-
"import": "./dist/index.js",
|
|
12
|
-
"require": "./dist/index.js"
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
8
|
"files": [
|
|
16
9
|
"dist",
|
|
17
10
|
"README.md",
|