@starko-one/sdk 0.0.0-stage → 0.1.0-beta.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/CHANGELOG.md +248 -0
- package/LICENSE +17 -0
- package/NOTICE +58 -0
- package/README.md +81 -2
- package/dist/api-BAFm4Lxj.d.ts +558 -0
- package/dist/api-DNrctwJu.d.cts +558 -0
- package/dist/browser/index.cjs +168 -0
- package/dist/browser/index.d.cts +131 -0
- package/dist/browser/index.d.ts +131 -0
- package/dist/browser/index.js +7 -0
- package/dist/build/rollup.cjs +22 -0
- package/dist/build/rollup.d.cts +34 -0
- package/dist/build/rollup.d.ts +34 -0
- package/dist/build/rollup.js +3 -0
- package/dist/build/vite.cjs +51 -0
- package/dist/build/vite.d.cts +23 -0
- package/dist/build/vite.d.ts +23 -0
- package/dist/build/vite.js +46 -0
- package/dist/build/webpack.cjs +18 -0
- package/dist/build/webpack.d.cts +39 -0
- package/dist/build/webpack.d.ts +39 -0
- package/dist/build/webpack.js +3 -0
- package/dist/chunk-2PM4FRM5.cjs +431 -0
- package/dist/chunk-335HNCOJ.js +249 -0
- package/dist/chunk-3AW5B2WW.js +115 -0
- package/dist/chunk-3R5TQAWD.js +216 -0
- package/dist/chunk-6H5MOPTQ.cjs +1230 -0
- package/dist/chunk-7TKNT3QJ.cjs +2487 -0
- package/dist/chunk-A4WLNFMU.cjs +220 -0
- package/dist/chunk-ALYFFOPR.cjs +134 -0
- package/dist/chunk-BVVFVRMO.js +1113 -0
- package/dist/chunk-CIHNKN62.cjs +15 -0
- package/dist/chunk-CMGCH6HD.js +1212 -0
- package/dist/chunk-D6QAPQ7L.cjs +56 -0
- package/dist/chunk-DUO5V6WZ.js +213 -0
- package/dist/chunk-EC2WZ6PG.js +90 -0
- package/dist/chunk-EFURLFJT.cjs +187 -0
- package/dist/chunk-EROUORMY.js +53 -0
- package/dist/chunk-LXBXFOAP.cjs +96 -0
- package/dist/chunk-MF6SA6DB.js +563 -0
- package/dist/chunk-N5R6ORIB.js +413 -0
- package/dist/chunk-N6R6BWHK.cjs +142 -0
- package/dist/chunk-QAGGN2T7.cjs +225 -0
- package/dist/chunk-QV4HRIDD.cjs +659 -0
- package/dist/chunk-TKNDYQB3.cjs +583 -0
- package/dist/chunk-UI5YC4TH.js +131 -0
- package/dist/chunk-VEHZYLK6.cjs +1151 -0
- package/dist/chunk-VNCWOGTI.js +12 -0
- package/dist/chunk-VWNIOGE6.js +180 -0
- package/dist/chunk-WDKRKGYF.js +608 -0
- package/dist/chunk-XOZIXBUK.js +2462 -0
- package/dist/chunk-ZS3K3SDR.cjs +258 -0
- package/dist/cli/index.cjs +2780 -0
- package/dist/common-DLFAqL2d.d.cts +36 -0
- package/dist/common-DbSXkaw6.d.ts +36 -0
- package/dist/dedupe-Bh5riD8Z.d.cts +13 -0
- package/dist/dedupe-DoYiSx-9.d.ts +13 -0
- package/dist/handler-BcnsnvhF.d.cts +82 -0
- package/dist/handler-qHzilC9T.d.ts +82 -0
- package/dist/index.cjs +309 -0
- package/dist/index.d.cts +187 -0
- package/dist/index.d.ts +187 -0
- package/dist/index.js +4 -0
- package/dist/next/client.cjs +113 -0
- package/dist/next/client.d.cts +26 -0
- package/dist/next/client.d.ts +26 -0
- package/dist/next/client.js +41 -0
- package/dist/next/config.cjs +277 -0
- package/dist/next/config.d.cts +193 -0
- package/dist/next/config.d.ts +193 -0
- package/dist/next/config.js +263 -0
- package/dist/next/index.cjs +148 -0
- package/dist/next/index.d.cts +32 -0
- package/dist/next/index.d.ts +32 -0
- package/dist/next/index.js +59 -0
- package/dist/node/index.cjs +257 -0
- package/dist/node/index.d.cts +145 -0
- package/dist/node/index.d.ts +145 -0
- package/dist/node/index.js +83 -0
- package/dist/options-BUhWuWJX.d.cts +79 -0
- package/dist/options-BUhWuWJX.d.ts +79 -0
- package/dist/react/index.cjs +107 -0
- package/dist/react/index.d.cts +84 -0
- package/dist/react/index.d.ts +84 -0
- package/dist/react/index.js +103 -0
- package/dist/scope-D1ouJm2h.d.cts +628 -0
- package/dist/scope-D1ouJm2h.d.ts +628 -0
- package/dist/server-edge-7624N3WF.cjs +51 -0
- package/dist/server-edge-BEEXWL7T.js +48 -0
- package/dist/server-node-ET4LIPEC.cjs +27 -0
- package/dist/server-node-TQUVMZUC.js +24 -0
- package/dist/session-C_WzbEN2.d.cts +4 -0
- package/dist/session-C_WzbEN2.d.ts +4 -0
- package/dist/session-propagation-Pr0Zb9Zn.d.cts +30 -0
- package/dist/session-propagation-RM5py1bp.d.ts +30 -0
- package/dist/starko.min.js +6 -0
- package/docs/browser.md +386 -0
- package/docs/configuration.md +310 -0
- package/docs/nextjs.md +488 -0
- package/docs/node.md +427 -0
- package/docs/other-backends.md +232 -0
- package/docs/privacy.md +112 -0
- package/docs/react.md +187 -0
- package/docs/source-maps.md +482 -0
- package/docs/troubleshooting.md +263 -0
- package/docs/widget.md +84 -0
- package/docs/wire-format.md +547 -0
- package/package.json +191 -4
|
@@ -0,0 +1,583 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkALYFFOPR_cjs = require('./chunk-ALYFFOPR.cjs');
|
|
4
|
+
var chunk6H5MOPTQ_cjs = require('./chunk-6H5MOPTQ.cjs');
|
|
5
|
+
var chunkCIHNKN62_cjs = require('./chunk-CIHNKN62.cjs');
|
|
6
|
+
var chunkZS3K3SDR_cjs = require('./chunk-ZS3K3SDR.cjs');
|
|
7
|
+
var chunkQV4HRIDD_cjs = require('./chunk-QV4HRIDD.cjs');
|
|
8
|
+
var chunkN6R6BWHK_cjs = require('./chunk-N6R6BWHK.cjs');
|
|
9
|
+
|
|
10
|
+
// src/browser/integrations/own-requests.ts
|
|
11
|
+
var isOwnRequest = (url) => url.indexOf(chunkN6R6BWHK_cjs.PATHS.INGEST) >= 0 || url.indexOf(chunkN6R6BWHK_cjs.PATHS.CONFIG) >= 0;
|
|
12
|
+
|
|
13
|
+
// src/browser/integrations/breadcrumbs.ts
|
|
14
|
+
var CONSOLE_LEVELS = { warn: "warning", error: "error" };
|
|
15
|
+
var MASKED = ".starko-mask,[data-starko-mask],.starko-no-capture,[data-starko-no-capture]";
|
|
16
|
+
function describeElement(el) {
|
|
17
|
+
const parts = [];
|
|
18
|
+
let node = el;
|
|
19
|
+
try {
|
|
20
|
+
for (let depth = 0; node && node.nodeType === 1 && depth < 5; depth++) {
|
|
21
|
+
let s = node.tagName.toLowerCase();
|
|
22
|
+
if (node.id) s += `#${node.id}`;
|
|
23
|
+
const cls = typeof node.className === "string" ? node.className.trim().split(/\s+/).filter((c) => c && /^[\w-]+$/.test(c)) : [];
|
|
24
|
+
for (const c of cls.slice(0, 2)) s += `.${c}`;
|
|
25
|
+
for (const a of ["type", "name", "role", "data-testid"]) {
|
|
26
|
+
const v = node.getAttribute(a);
|
|
27
|
+
if (v) s += `[${a}="${chunkQV4HRIDD_cjs.truncate(v, 30)}"]`;
|
|
28
|
+
}
|
|
29
|
+
parts.unshift(s);
|
|
30
|
+
if (node.id) break;
|
|
31
|
+
node = node.parentElement;
|
|
32
|
+
}
|
|
33
|
+
} catch {
|
|
34
|
+
}
|
|
35
|
+
const out = parts.join(" > ");
|
|
36
|
+
return out.length > 120 ? "\u2026" + out.slice(out.length - 119) : out || "<unknown>";
|
|
37
|
+
}
|
|
38
|
+
var httpLevel = (s) => !s || s >= 500 ? "error" : s >= 400 ? "warning" : void 0;
|
|
39
|
+
function samePath(url) {
|
|
40
|
+
if (!url) return url;
|
|
41
|
+
try {
|
|
42
|
+
const u = new URL(url, location.href);
|
|
43
|
+
return u.origin === location.origin ? u.pathname + u.search + u.hash : u.href;
|
|
44
|
+
} catch {
|
|
45
|
+
return url;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function breadcrumbsIntegration(opts = {}) {
|
|
49
|
+
const undo = [];
|
|
50
|
+
return {
|
|
51
|
+
name: "Breadcrumbs",
|
|
52
|
+
setup(client) {
|
|
53
|
+
if (typeof window === "undefined") return;
|
|
54
|
+
let busy = false;
|
|
55
|
+
const add = (b) => {
|
|
56
|
+
if (busy) return;
|
|
57
|
+
busy = true;
|
|
58
|
+
try {
|
|
59
|
+
client.addBreadcrumb(b);
|
|
60
|
+
} catch {
|
|
61
|
+
} finally {
|
|
62
|
+
busy = false;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const http = (category, method, url, status, error) => add({
|
|
66
|
+
timestamp: Date.now(),
|
|
67
|
+
type: "http",
|
|
68
|
+
category,
|
|
69
|
+
level: error !== void 0 ? "error" : httpLevel(status),
|
|
70
|
+
data: { method, url: chunkQV4HRIDD_cjs.truncate(url, 2048), ...error !== void 0 ? { error: chunkQV4HRIDD_cjs.truncate(chunkQV4HRIDD_cjs.safeString(error instanceof Error ? error.message : error), 200) } : { status_code: status } }
|
|
71
|
+
});
|
|
72
|
+
if (opts.console !== false && typeof console !== "undefined") {
|
|
73
|
+
for (const level of Object.keys(CONSOLE_LEVELS)) {
|
|
74
|
+
undo.push(
|
|
75
|
+
chunkQV4HRIDD_cjs.addHook(console, level, (_self, args) => {
|
|
76
|
+
if (args[0] === chunkQV4HRIDD_cjs.LOG_PREFIX) return;
|
|
77
|
+
const text = args.map((a) => typeof a === "string" ? a : chunkQV4HRIDD_cjs.safeStringify(chunkQV4HRIDD_cjs.normalize(a, 2))).join(" ");
|
|
78
|
+
add({ timestamp: Date.now(), type: "console", category: "console", level: CONSOLE_LEVELS[level], message: chunkQV4HRIDD_cjs.truncate(text, 200) });
|
|
79
|
+
})
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (opts.dom !== false && typeof document !== "undefined") {
|
|
84
|
+
const onClick = (e) => {
|
|
85
|
+
try {
|
|
86
|
+
const t = e.target;
|
|
87
|
+
if (t && typeof t.closest === "function" && t.closest(MASKED)) return;
|
|
88
|
+
add({ timestamp: Date.now(), type: "ui", category: "click", message: describeElement(t) });
|
|
89
|
+
} catch {
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
document.addEventListener("click", onClick, { capture: true, passive: true });
|
|
93
|
+
undo.push(() => document.removeEventListener("click", onClick, { capture: true }));
|
|
94
|
+
}
|
|
95
|
+
if (opts.fetch !== false) {
|
|
96
|
+
undo.push(
|
|
97
|
+
chunkQV4HRIDD_cjs.addHook(window, "fetch", (_self, args) => {
|
|
98
|
+
const input = args[0];
|
|
99
|
+
const init2 = args[1];
|
|
100
|
+
const url = typeof input === "string" ? input : input instanceof URL ? input.href : String(input && input.url || "");
|
|
101
|
+
const method = String(init2 && init2.method || (input && typeof input === "object" && "method" in input ? input.method : "GET")).toUpperCase();
|
|
102
|
+
if (isOwnRequest(url)) return;
|
|
103
|
+
return (ret) => {
|
|
104
|
+
const p = ret;
|
|
105
|
+
if (p && typeof p.then === "function") p.then((res) => http("fetch", method, url, res.status), (err) => http("fetch", method, url, 0, err));
|
|
106
|
+
};
|
|
107
|
+
})
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
if (opts.xhr !== false && typeof XMLHttpRequest === "function") {
|
|
111
|
+
const proto = XMLHttpRequest.prototype;
|
|
112
|
+
const info = /* @__PURE__ */ new WeakMap();
|
|
113
|
+
undo.push(
|
|
114
|
+
chunkQV4HRIDD_cjs.addHook(proto, "open", (self, args) => {
|
|
115
|
+
info.set(self, [String(args[0]).toUpperCase(), String(args[1])]);
|
|
116
|
+
}),
|
|
117
|
+
chunkQV4HRIDD_cjs.addHook(proto, "send", (self) => {
|
|
118
|
+
const i = info.get(self);
|
|
119
|
+
if (!i || isOwnRequest(i[1])) return;
|
|
120
|
+
const xhr = self;
|
|
121
|
+
xhr.addEventListener("loadend", () => http("xhr", i[0], i[1], xhr.status));
|
|
122
|
+
})
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
if (opts.history !== false && typeof history !== "undefined" && typeof location !== "undefined") {
|
|
126
|
+
let last = location.href;
|
|
127
|
+
const nav = (to) => {
|
|
128
|
+
try {
|
|
129
|
+
const next = to === void 0 ? location.href : new URL(String(to), location.href).href;
|
|
130
|
+
if (next === last) return;
|
|
131
|
+
add({ timestamp: Date.now(), type: "navigation", category: "navigation", data: { from: samePath(last), to: samePath(next) } });
|
|
132
|
+
last = next;
|
|
133
|
+
} catch {
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
for (const m of ["pushState", "replaceState"]) {
|
|
137
|
+
undo.push(chunkQV4HRIDD_cjs.addHook(history, m, (_self, args) => args[2] != null ? () => nav(args[2]) : void 0));
|
|
138
|
+
}
|
|
139
|
+
const onPop = () => nav(void 0);
|
|
140
|
+
window.addEventListener("popstate", onPop);
|
|
141
|
+
undo.push(() => window.removeEventListener("popstate", onPop));
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
teardown() {
|
|
145
|
+
for (const u of undo.splice(0)) {
|
|
146
|
+
try {
|
|
147
|
+
u();
|
|
148
|
+
} catch {
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// src/browser/integrations/widget-bridge.ts
|
|
156
|
+
var BRIDGE_GLOBAL = "__STARKO_BRIDGE__";
|
|
157
|
+
var BRIDGE_EVENT = "starko:bridge";
|
|
158
|
+
var TOKEN = /^[\w-]+\.[\w-]+\.[\w-]+$/;
|
|
159
|
+
var isObj = (v) => v !== null && typeof v === "object";
|
|
160
|
+
function getBridge() {
|
|
161
|
+
try {
|
|
162
|
+
const b = globalThis[BRIDGE_GLOBAL];
|
|
163
|
+
return isObj(b) ? b : void 0;
|
|
164
|
+
} catch {
|
|
165
|
+
return void 0;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function validSdkSlot(v) {
|
|
169
|
+
try {
|
|
170
|
+
return isObj(v) && typeof v.version === "string" && typeof v.getSessionId === "function" && typeof v.captureException === "function";
|
|
171
|
+
} catch {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function fromWidget(getter) {
|
|
176
|
+
try {
|
|
177
|
+
const w = (getBridge() || {}).widget;
|
|
178
|
+
return w && w[getter]();
|
|
179
|
+
} catch {
|
|
180
|
+
return void 0;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function widgetPresent() {
|
|
184
|
+
try {
|
|
185
|
+
return isObj((getBridge() || {}).widget);
|
|
186
|
+
} catch {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function widgetSessionId() {
|
|
191
|
+
const id = fromWidget("getReplaySessionId");
|
|
192
|
+
return typeof id === "string" && chunkN6R6BWHK_cjs.SESSION_ID_PATTERN.test(id) ? id : void 0;
|
|
193
|
+
}
|
|
194
|
+
function widgetClientToken() {
|
|
195
|
+
const t = fromWidget("getClientToken");
|
|
196
|
+
return typeof t === "string" && t.length <= 2048 && TOKEN.test(t) ? t : void 0;
|
|
197
|
+
}
|
|
198
|
+
function capturing() {
|
|
199
|
+
try {
|
|
200
|
+
const c = chunkQV4HRIDD_cjs.getClient();
|
|
201
|
+
if (!c || !c.isEnabled()) return false;
|
|
202
|
+
const gh = c.getIntegration("GlobalHandlers");
|
|
203
|
+
return !!gh && gh.captures !== false;
|
|
204
|
+
} catch {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
var SLOT = Object.freeze({
|
|
209
|
+
version: chunkQV4HRIDD_cjs.SDK_VERSION,
|
|
210
|
+
get capturesErrors() {
|
|
211
|
+
return capturing();
|
|
212
|
+
},
|
|
213
|
+
getSessionId: () => {
|
|
214
|
+
try {
|
|
215
|
+
const c = chunkQV4HRIDD_cjs.getClient();
|
|
216
|
+
return c && c.getSessionId() || "";
|
|
217
|
+
} catch {
|
|
218
|
+
return "";
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
captureException: (error, hint) => {
|
|
222
|
+
try {
|
|
223
|
+
const c = chunkQV4HRIDD_cjs.getClient();
|
|
224
|
+
return c ? c.captureException(error, { mechanism: { type: "widget", handled: true }, ...hint }) : "";
|
|
225
|
+
} catch {
|
|
226
|
+
return "";
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
var announced;
|
|
231
|
+
function announce() {
|
|
232
|
+
try {
|
|
233
|
+
const v = capturing();
|
|
234
|
+
announced = v;
|
|
235
|
+
if (typeof window !== "undefined" && typeof CustomEvent === "function") window.dispatchEvent(new CustomEvent(BRIDGE_EVENT, { detail: { side: "sdk", capturesErrors: v } }));
|
|
236
|
+
} catch {
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function refreshBridge() {
|
|
240
|
+
try {
|
|
241
|
+
const b = getBridge();
|
|
242
|
+
if (b && validSdkSlot(b.sdk) && capturing() !== announced) announce();
|
|
243
|
+
} catch {
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function defineSlot(log) {
|
|
247
|
+
try {
|
|
248
|
+
const g = globalThis;
|
|
249
|
+
let bridge = getBridge();
|
|
250
|
+
if (!bridge) {
|
|
251
|
+
if (g[BRIDGE_GLOBAL] != null) {
|
|
252
|
+
if (log) log("__STARKO_BRIDGE__ is not an object: running without the widget bridge");
|
|
253
|
+
return 0;
|
|
254
|
+
}
|
|
255
|
+
g[BRIDGE_GLOBAL] = bridge = {};
|
|
256
|
+
}
|
|
257
|
+
if (validSdkSlot(bridge.sdk)) return 1;
|
|
258
|
+
Object.defineProperty(bridge, "sdk", { value: SLOT, enumerable: true, writable: false, configurable: false });
|
|
259
|
+
return 2;
|
|
260
|
+
} catch {
|
|
261
|
+
if (log) log("the widget bridge's sdk slot could not be set");
|
|
262
|
+
return 0;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function widgetBridgeIntegration() {
|
|
266
|
+
let log;
|
|
267
|
+
return {
|
|
268
|
+
name: "WidgetBridge",
|
|
269
|
+
setup(client) {
|
|
270
|
+
log = client.logger.log;
|
|
271
|
+
if (defineSlot(log)) announce();
|
|
272
|
+
else announced = void 0;
|
|
273
|
+
},
|
|
274
|
+
processEvent(event) {
|
|
275
|
+
if (defineSlot(log) === 2) announce();
|
|
276
|
+
if (!event.client_token) {
|
|
277
|
+
const token = widgetClientToken();
|
|
278
|
+
if (token) event.client_token = token;
|
|
279
|
+
}
|
|
280
|
+
return event;
|
|
281
|
+
},
|
|
282
|
+
teardown() {
|
|
283
|
+
refreshBridge();
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// src/browser/integrations/console-capture.ts
|
|
289
|
+
function consoleErrorCaptureIntegration(opts = {}) {
|
|
290
|
+
let undo;
|
|
291
|
+
return {
|
|
292
|
+
name: "ConsoleErrorCapture",
|
|
293
|
+
setup(client) {
|
|
294
|
+
if (typeof console === "undefined") return;
|
|
295
|
+
let busy = false;
|
|
296
|
+
undo = chunkQV4HRIDD_cjs.addHook(console, "error", (_self, args) => {
|
|
297
|
+
if (busy || args[0] === chunkQV4HRIDD_cjs.LOG_PREFIX || opts.whenWidget && !widgetPresent()) return;
|
|
298
|
+
const err = args.find((a) => chunkQV4HRIDD_cjs.isError(a));
|
|
299
|
+
if (!err || chunkZS3K3SDR_cjs.capturedAs(err)) return;
|
|
300
|
+
busy = true;
|
|
301
|
+
try {
|
|
302
|
+
client.captureException(err, { mechanism: { type: "console", handled: true } });
|
|
303
|
+
} finally {
|
|
304
|
+
busy = false;
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
},
|
|
308
|
+
teardown() {
|
|
309
|
+
if (undo) undo();
|
|
310
|
+
undo = void 0;
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// src/browser/integrations/global-handlers.ts
|
|
316
|
+
function globalHandlersIntegration(opts = {}) {
|
|
317
|
+
const off = [];
|
|
318
|
+
const self = {
|
|
319
|
+
name: "GlobalHandlers",
|
|
320
|
+
/** The window `error` listener is installed. */
|
|
321
|
+
captures: false,
|
|
322
|
+
setup(client) {
|
|
323
|
+
if (typeof window === "undefined" || typeof window.addEventListener !== "function") return;
|
|
324
|
+
const listen = (type, fn) => {
|
|
325
|
+
const safe = (e) => {
|
|
326
|
+
try {
|
|
327
|
+
fn(e);
|
|
328
|
+
} catch (err) {
|
|
329
|
+
client.logger.warn(`${type} handler failed`, err);
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
window.addEventListener(type, safe);
|
|
333
|
+
off.push(() => window.removeEventListener(type, safe));
|
|
334
|
+
};
|
|
335
|
+
if (opts.onerror !== false) {
|
|
336
|
+
listen("error", (e) => {
|
|
337
|
+
const ev = e;
|
|
338
|
+
if (typeof ev.message !== "string" && ev.error == null) return;
|
|
339
|
+
client.captureException(ev, { mechanism: { type: "onerror", handled: false }, data: { event: ev } });
|
|
340
|
+
});
|
|
341
|
+
self.captures = true;
|
|
342
|
+
}
|
|
343
|
+
if (opts.onunhandledrejection !== false) {
|
|
344
|
+
listen("unhandledrejection", (e) => {
|
|
345
|
+
client.captureException(e, { mechanism: { type: "onunhandledrejection", handled: false }, data: { event: e } });
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
teardown() {
|
|
350
|
+
self.captures = false;
|
|
351
|
+
for (const f of off.splice(0)) f();
|
|
352
|
+
refreshBridge();
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
return self;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// src/browser/integrations/http-context.ts
|
|
359
|
+
function httpContextIntegration() {
|
|
360
|
+
return {
|
|
361
|
+
name: "HttpContext",
|
|
362
|
+
processEvent(event) {
|
|
363
|
+
if (typeof location === "undefined") return event;
|
|
364
|
+
const request = { ...event.request };
|
|
365
|
+
if (!request.url && location.href) request.url = location.href;
|
|
366
|
+
try {
|
|
367
|
+
if (!request.referrer && typeof document !== "undefined" && document.referrer) request.referrer = document.referrer;
|
|
368
|
+
} catch {
|
|
369
|
+
}
|
|
370
|
+
event.request = request;
|
|
371
|
+
return event;
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// src/browser/integrations/inbound-filters.ts
|
|
377
|
+
var NO_FILE = /^(?:<anonymous>|\[native code\]|native|<data:.*)$/;
|
|
378
|
+
var EXTENSION = /^(?:chrome|moz|safari|safari-web|ms-browser)-extension:\/\//i;
|
|
379
|
+
var STARKO_SCRIPT = /(?:starko[^\s/]*\.(?:one|me|app)|localhost:\d+)\/(?:widget(?:[.-][^\s/]*)?\.js|replay\/rrweb-record)/i;
|
|
380
|
+
var WIDGET_BUNDLE = /\/widget(?:[.-][A-Za-z0-9]+)?\.js\b/i;
|
|
381
|
+
var EMPTY = /^(?:\[object \w+\]|undefined|null|error|Non-Error promise rejection captured with value: (?:undefined|null)?)$/i;
|
|
382
|
+
var SCRIPT_ERROR = /^(?:uncaught\s+)?script error\.?$/i;
|
|
383
|
+
var RESIZE_OBSERVER = /^resizeobserver loop|resizeobserver loop (?:limit exceeded|completed with undelivered notifications)/i;
|
|
384
|
+
var ABORTED = /\baborterror\b|^(?:the )?(?:user |operation was |request |fetch was |signal is )?aborted(?: a request| without reason)?\.?$|\bthe operation was aborted\b/i;
|
|
385
|
+
var NETWORK = /^(?:typeerror: )?(?:failed to fetch|networkerror when attempting to fetch resource\.?|load failed|network request failed|network error|the internet connection appears to be offline\.?)$/i;
|
|
386
|
+
var ownScripts = /* @__PURE__ */ new Set();
|
|
387
|
+
function registerOwnScript(src) {
|
|
388
|
+
if (src) ownScripts.add(src);
|
|
389
|
+
}
|
|
390
|
+
function inboundDropReason(event) {
|
|
391
|
+
const ex = event.exception_list[0];
|
|
392
|
+
if (!ex) return null;
|
|
393
|
+
const msg = (ex.value || "").replace(/\s+/g, " ").trim();
|
|
394
|
+
const full = ex.type && ex.type !== "Error" ? `${ex.type}: ${msg}` : msg;
|
|
395
|
+
const frames = ex.mechanism && ex.mechanism.synthetic || !ex.stacktrace ? [] : ex.stacktrace.frames;
|
|
396
|
+
const hasStack = frames.length > 0;
|
|
397
|
+
const files = frames.map((f) => f.filename || "").filter((f) => f && !NO_FILE.test(f));
|
|
398
|
+
if ((!msg || EMPTY.test(msg)) && !hasStack) return "empty message";
|
|
399
|
+
if (SCRIPT_ERROR.test(msg) && !hasStack) return "cross-origin script error";
|
|
400
|
+
if (frames.slice(0, 3).some((f) => f.filename && EXTENSION.test(f.filename))) return "browser extension";
|
|
401
|
+
if (RESIZE_OBSERVER.test(msg)) return "ResizeObserver loop";
|
|
402
|
+
if (ex.type === "AbortError" || ABORTED.test(msg) || ABORTED.test(full)) return "aborted request";
|
|
403
|
+
if (NETWORK.test(msg) || NETWORK.test(full)) return "network error";
|
|
404
|
+
if (/\bnetworkerror\b/i.test(full) && !hasStack) return "network error";
|
|
405
|
+
if (files.length && files.every((f) => STARKO_SCRIPT.test(f) || ownScripts.has(f) || WIDGET_BUNDLE.test(f) && /starko/i.test(f))) return "Starko script";
|
|
406
|
+
return null;
|
|
407
|
+
}
|
|
408
|
+
function inboundFiltersIntegration() {
|
|
409
|
+
return {
|
|
410
|
+
name: "InboundFilters",
|
|
411
|
+
processEvent(event, _hint, client) {
|
|
412
|
+
const why = inboundDropReason(event);
|
|
413
|
+
if (why) {
|
|
414
|
+
client.logger.log("dropped", why);
|
|
415
|
+
return null;
|
|
416
|
+
}
|
|
417
|
+
return event;
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// src/browser/integrations/session-propagation.ts
|
|
423
|
+
function sessionPropagationIntegration() {
|
|
424
|
+
const undo = [];
|
|
425
|
+
return {
|
|
426
|
+
name: "SessionPropagation",
|
|
427
|
+
setup(client) {
|
|
428
|
+
if (typeof window === "undefined" || typeof location === "undefined") return;
|
|
429
|
+
const idFor = (url) => {
|
|
430
|
+
const u = new URL(String(url), typeof document !== "undefined" && document.baseURI || location.href);
|
|
431
|
+
return u.origin === location.origin && !isOwnRequest(u.href) && client.isEnabled() && client.getSessionId() || "";
|
|
432
|
+
};
|
|
433
|
+
undo.push(
|
|
434
|
+
chunkQV4HRIDD_cjs.addHook(window, "fetch", (_self, args) => {
|
|
435
|
+
const input = args[0];
|
|
436
|
+
const init2 = args[1];
|
|
437
|
+
const req = typeof Request === "function" && input instanceof Request ? input : void 0;
|
|
438
|
+
const id = idFor(req ? req.url : input);
|
|
439
|
+
const headers = id && new Headers(init2 && init2.headers || req && req.headers);
|
|
440
|
+
if (headers && !headers.has(chunkCIHNKN62_cjs.SESSION_HEADER)) {
|
|
441
|
+
headers.set(chunkCIHNKN62_cjs.SESSION_HEADER, id);
|
|
442
|
+
args[1] = { ...init2, headers };
|
|
443
|
+
}
|
|
444
|
+
})
|
|
445
|
+
);
|
|
446
|
+
if (typeof XMLHttpRequest !== "function") return;
|
|
447
|
+
const ids = /* @__PURE__ */ new WeakMap();
|
|
448
|
+
const proto = XMLHttpRequest.prototype;
|
|
449
|
+
undo.push(
|
|
450
|
+
chunkQV4HRIDD_cjs.addHook(proto, "open", (self, args) => {
|
|
451
|
+
ids.delete(self);
|
|
452
|
+
ids.set(self, idFor(args[1]));
|
|
453
|
+
}),
|
|
454
|
+
chunkQV4HRIDD_cjs.addHook(proto, "send", (self) => {
|
|
455
|
+
const id = ids.get(self);
|
|
456
|
+
if (id) self.setRequestHeader(chunkCIHNKN62_cjs.SESSION_HEADER, id);
|
|
457
|
+
})
|
|
458
|
+
);
|
|
459
|
+
},
|
|
460
|
+
teardown() {
|
|
461
|
+
for (const u of undo.splice(0)) u();
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// src/browser/session.ts
|
|
467
|
+
var SESSION_STORAGE_KEY = "starko:errors:session";
|
|
468
|
+
var own;
|
|
469
|
+
function getOwnSessionId() {
|
|
470
|
+
if (own) return own;
|
|
471
|
+
try {
|
|
472
|
+
const stored = sessionStorage.getItem(SESSION_STORAGE_KEY);
|
|
473
|
+
if (stored && chunkN6R6BWHK_cjs.SESSION_ID_PATTERN.test(stored)) return own = stored;
|
|
474
|
+
} catch {
|
|
475
|
+
}
|
|
476
|
+
own = chunkQV4HRIDD_cjs.uuid4();
|
|
477
|
+
try {
|
|
478
|
+
sessionStorage.setItem(SESSION_STORAGE_KEY, own);
|
|
479
|
+
} catch {
|
|
480
|
+
}
|
|
481
|
+
return own;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// src/browser/sdk.ts
|
|
485
|
+
function getDefaultIntegrations() {
|
|
486
|
+
return [
|
|
487
|
+
inboundFiltersIntegration(),
|
|
488
|
+
chunk6H5MOPTQ_cjs.dedupeIntegration(),
|
|
489
|
+
globalHandlersIntegration(),
|
|
490
|
+
breadcrumbsIntegration(),
|
|
491
|
+
httpContextIntegration(),
|
|
492
|
+
widgetBridgeIntegration(),
|
|
493
|
+
sessionPropagationIntegration(),
|
|
494
|
+
// Only while the Starko widget is on the page (it stands its own console capture down for the SDK).
|
|
495
|
+
consoleErrorCaptureIntegration({ whenWidget: true })
|
|
496
|
+
];
|
|
497
|
+
}
|
|
498
|
+
var NOT_APP = /^(?:<anonymous>|\[native code\]|native|<data:.*|(?:chrome|moz|safari|safari-web|ms-browser)-extension:.*)$/i;
|
|
499
|
+
function browserIsInApp(filename) {
|
|
500
|
+
return !filename || NOT_APP.test(filename) || /\/node_modules\//.test(filename) ? false : void 0;
|
|
501
|
+
}
|
|
502
|
+
function flushOnHideIntegration() {
|
|
503
|
+
const off = [];
|
|
504
|
+
return {
|
|
505
|
+
name: "FlushOnHide",
|
|
506
|
+
setup(client) {
|
|
507
|
+
if (typeof window === "undefined" || typeof document === "undefined") return;
|
|
508
|
+
const safe = (f) => () => {
|
|
509
|
+
try {
|
|
510
|
+
f();
|
|
511
|
+
} catch {
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
const go = safe(() => void client.flush(2e3, true));
|
|
515
|
+
const onVis = safe(() => document.visibilityState === "hidden" && go());
|
|
516
|
+
const online = safe(() => client.resume());
|
|
517
|
+
window.addEventListener("pagehide", go);
|
|
518
|
+
window.addEventListener("online", online);
|
|
519
|
+
document.addEventListener("visibilitychange", onVis);
|
|
520
|
+
off.push(
|
|
521
|
+
() => window.removeEventListener("pagehide", go),
|
|
522
|
+
() => window.removeEventListener("online", online),
|
|
523
|
+
() => document.removeEventListener("visibilitychange", onVis)
|
|
524
|
+
);
|
|
525
|
+
},
|
|
526
|
+
teardown() {
|
|
527
|
+
for (const f of off.splice(0)) f();
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
function init(options) {
|
|
532
|
+
try {
|
|
533
|
+
const previous = chunkQV4HRIDD_cjs.getClient();
|
|
534
|
+
if (previous) void previous.close(0);
|
|
535
|
+
const defaults = options.defaultIntegrations === false ? [] : Array.isArray(options.defaultIntegrations) ? options.defaultIntegrations : getDefaultIntegrations();
|
|
536
|
+
let integrations;
|
|
537
|
+
if (typeof options.integrations === "function") integrations = options.integrations(defaults);
|
|
538
|
+
else integrations = [...defaults, ...options.integrations || []];
|
|
539
|
+
if (!integrations.some((i) => i && i.name === "FlushOnHide")) integrations.push(flushOnHideIntegration());
|
|
540
|
+
let client;
|
|
541
|
+
const bridged = () => !!client.getIntegration("WidgetBridge");
|
|
542
|
+
client = new chunk6H5MOPTQ_cjs.Client({
|
|
543
|
+
...options,
|
|
544
|
+
platform: "browser",
|
|
545
|
+
framePlatform: "web:javascript",
|
|
546
|
+
sdkName: "starko.browser",
|
|
547
|
+
stackParser: chunk6H5MOPTQ_cjs.browserStackParser,
|
|
548
|
+
isInApp: browserIsInApp,
|
|
549
|
+
getSessionId: () => bridged() && widgetSessionId() || getOwnSessionId(),
|
|
550
|
+
defaultMaxEventsPerLifetime: 100,
|
|
551
|
+
transport: options.transport || chunkALYFFOPR_cjs.makeFetchTransport
|
|
552
|
+
});
|
|
553
|
+
chunkQV4HRIDD_cjs.setCurrentClient(client);
|
|
554
|
+
client.init(integrations);
|
|
555
|
+
return client;
|
|
556
|
+
} catch (err) {
|
|
557
|
+
try {
|
|
558
|
+
if (options && options.debug) console.warn("[starko] init failed", err);
|
|
559
|
+
} catch {
|
|
560
|
+
}
|
|
561
|
+
return void 0;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
exports.BRIDGE_EVENT = BRIDGE_EVENT;
|
|
566
|
+
exports.BRIDGE_GLOBAL = BRIDGE_GLOBAL;
|
|
567
|
+
exports.SESSION_STORAGE_KEY = SESSION_STORAGE_KEY;
|
|
568
|
+
exports.breadcrumbsIntegration = breadcrumbsIntegration;
|
|
569
|
+
exports.browserIsInApp = browserIsInApp;
|
|
570
|
+
exports.consoleErrorCaptureIntegration = consoleErrorCaptureIntegration;
|
|
571
|
+
exports.describeElement = describeElement;
|
|
572
|
+
exports.flushOnHideIntegration = flushOnHideIntegration;
|
|
573
|
+
exports.getBridge = getBridge;
|
|
574
|
+
exports.getDefaultIntegrations = getDefaultIntegrations;
|
|
575
|
+
exports.getOwnSessionId = getOwnSessionId;
|
|
576
|
+
exports.globalHandlersIntegration = globalHandlersIntegration;
|
|
577
|
+
exports.httpContextIntegration = httpContextIntegration;
|
|
578
|
+
exports.inboundDropReason = inboundDropReason;
|
|
579
|
+
exports.inboundFiltersIntegration = inboundFiltersIntegration;
|
|
580
|
+
exports.init = init;
|
|
581
|
+
exports.registerOwnScript = registerOwnScript;
|
|
582
|
+
exports.sessionPropagationIntegration = sessionPropagationIntegration;
|
|
583
|
+
exports.widgetBridgeIntegration = widgetBridgeIntegration;
|