reportli 1.0.1 → 1.0.3
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/index.d.ts +8 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +210 -227
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +210 -227
- package/dist/index.mjs.map +2 -2
- package/package.json +1 -1
- package/src/index.ts +288 -250
package/dist/index.mjs
CHANGED
|
@@ -8,14 +8,64 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
8
8
|
|
|
9
9
|
// src/index.ts
|
|
10
10
|
var ENDPOINT = "https://fahikyfmgdyzejdfftox.supabase.co/functions/v1/rapid-processor";
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
var initialized = false;
|
|
12
|
+
var _config;
|
|
13
|
+
var queue = [];
|
|
14
|
+
var flushTimer = null;
|
|
15
|
+
var isFlushing = false;
|
|
16
|
+
function scheduleFlush() {
|
|
17
|
+
if (flushTimer)
|
|
18
|
+
return;
|
|
19
|
+
flushTimer = setTimeout(() => {
|
|
20
|
+
flushTimer = null;
|
|
21
|
+
flush();
|
|
22
|
+
}, 2e3);
|
|
23
|
+
}
|
|
24
|
+
async function flush() {
|
|
25
|
+
if (isFlushing || queue.length === 0)
|
|
26
|
+
return;
|
|
27
|
+
isFlushing = true;
|
|
28
|
+
const batch = queue.splice(0, 10);
|
|
29
|
+
for (const payload of batch) {
|
|
30
|
+
await sendNow(payload);
|
|
31
|
+
}
|
|
32
|
+
isFlushing = false;
|
|
33
|
+
if (queue.length > 0)
|
|
34
|
+
flush();
|
|
35
|
+
}
|
|
36
|
+
async function sendNow(payload, attempts = 3) {
|
|
37
|
+
for (let i = 0; i < attempts; i++) {
|
|
38
|
+
try {
|
|
39
|
+
const res = await fetch(ENDPOINT, {
|
|
40
|
+
method: "POST",
|
|
41
|
+
headers: {
|
|
42
|
+
"Content-Type": "application/json",
|
|
43
|
+
"x-api-key": _config?.apiKey ?? ""
|
|
44
|
+
},
|
|
45
|
+
body: JSON.stringify(payload)
|
|
46
|
+
});
|
|
47
|
+
if (res.ok)
|
|
48
|
+
return;
|
|
49
|
+
} catch {
|
|
50
|
+
}
|
|
51
|
+
await sleep(1e3 * (i + 1));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function sleep(ms) {
|
|
55
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
56
|
+
}
|
|
57
|
+
function enqueue(payload) {
|
|
58
|
+
if (queue.length >= 100)
|
|
59
|
+
return;
|
|
60
|
+
queue.push(payload);
|
|
61
|
+
scheduleFlush();
|
|
62
|
+
}
|
|
63
|
+
function sendImmediate(payload) {
|
|
64
|
+
sendNow(payload).catch(() => {
|
|
65
|
+
});
|
|
16
66
|
}
|
|
17
67
|
function getUrl() {
|
|
18
|
-
if (
|
|
68
|
+
if (typeof window !== "undefined")
|
|
19
69
|
return window.location.href;
|
|
20
70
|
try {
|
|
21
71
|
return __require("os").hostname();
|
|
@@ -24,10 +74,13 @@ function getUrl() {
|
|
|
24
74
|
}
|
|
25
75
|
}
|
|
26
76
|
function getBrowser() {
|
|
27
|
-
if (
|
|
77
|
+
if (typeof navigator !== "undefined")
|
|
28
78
|
return navigator.userAgent;
|
|
29
79
|
return `Node.js ${typeof process !== "undefined" ? process.version : "unknown"}`;
|
|
30
80
|
}
|
|
81
|
+
function getEnvironment() {
|
|
82
|
+
return _config?.environment ?? (typeof window !== "undefined" ? "browser" : "server");
|
|
83
|
+
}
|
|
31
84
|
function parseStack(stack) {
|
|
32
85
|
if (!stack)
|
|
33
86
|
return { file: "unknown", line: 0, column: 0 };
|
|
@@ -44,140 +97,79 @@ function getErrorCode(error) {
|
|
|
44
97
|
function classifyError(error, context) {
|
|
45
98
|
const msg = String(error?.message || error || "").toLowerCase();
|
|
46
99
|
const name = String(error?.name || "").toLowerCase();
|
|
47
|
-
if (
|
|
48
|
-
return {
|
|
100
|
+
if (msg.includes("stripe") || msg.includes("payment") || msg.includes("card declined") || msg.includes("checkout") || msg.includes("refund"))
|
|
101
|
+
return { category: "Payment Error", severity: "critical" };
|
|
102
|
+
if (msg.includes("jwt") || msg.includes("token expired") || msg.includes("unauthorized") || msg.includes("session") || msg.includes("oauth") || msg.includes("login failed"))
|
|
103
|
+
return { category: "Auth Error", severity: "high" };
|
|
104
|
+
if (msg.includes("supabase") || msg.includes("database") || msg.includes("query") || msg.includes("connection lost") || msg.includes("transaction") || msg.includes("duplicate key") || msg.includes("foreign key"))
|
|
105
|
+
return { category: "Database Error", severity: "critical" };
|
|
49
106
|
if (msg.includes("hydration") || msg.includes("does not match server"))
|
|
50
|
-
return {
|
|
51
|
-
if (msg.includes("invalid hook
|
|
52
|
-
return {
|
|
53
|
-
if (msg.includes("
|
|
54
|
-
return {
|
|
55
|
-
if (msg.includes("
|
|
56
|
-
return {
|
|
57
|
-
if (msg.includes("route not found") || msg.includes("404 route"))
|
|
58
|
-
return { errorType: "Route not found error", severity: "medium" };
|
|
59
|
-
if (msg.includes("failed to fetch dynamically imported") || msg.includes("dynamic import"))
|
|
60
|
-
return { errorType: "Dynamic import error", severity: "high" };
|
|
61
|
-
if (msg.includes("suspense"))
|
|
62
|
-
return { errorType: "Suspense boundary error", severity: "medium" };
|
|
63
|
-
if (name === "typeerror" || msg.startsWith("typeerror"))
|
|
64
|
-
return { errorType: "TypeError", severity: "high" };
|
|
65
|
-
if (name === "referenceerror")
|
|
66
|
-
return { errorType: "ReferenceError", severity: "critical" };
|
|
67
|
-
if (name === "rangeerror" || msg.includes("maximum call stack"))
|
|
68
|
-
return { errorType: "Stack overflow error", severity: "critical" };
|
|
69
|
-
if (name === "syntaxerror")
|
|
70
|
-
return { errorType: "SyntaxError", severity: "high" };
|
|
71
|
-
if (msg.includes("stripe") && (msg.includes("init") || msg.includes("key")))
|
|
72
|
-
return { errorType: "Stripe initialization error", severity: "critical" };
|
|
73
|
-
if (msg.includes("payment") || msg.includes("card declined"))
|
|
74
|
-
return { errorType: "Payment processing error", severity: "critical" };
|
|
75
|
-
if (msg.includes("checkout session"))
|
|
76
|
-
return { errorType: "Checkout session error", severity: "high" };
|
|
77
|
-
if (msg.includes("refund failed"))
|
|
78
|
-
return { errorType: "Refund failed error", severity: "high" };
|
|
79
|
-
if (msg.includes("supabase") || msg.includes("postgresterror"))
|
|
80
|
-
return { errorType: "Supabase query error", severity: "critical" };
|
|
81
|
-
if (msg.includes("unique constraint") || msg.includes("duplicate key"))
|
|
82
|
-
return { errorType: "Unique constraint error", severity: "high" };
|
|
83
|
-
if (msg.includes("foreign key"))
|
|
84
|
-
return { errorType: "Foreign key error", severity: "high" };
|
|
85
|
-
if (msg.includes("transaction failed") || msg.includes("rollback"))
|
|
86
|
-
return { errorType: "Transaction failed error", severity: "critical" };
|
|
87
|
-
if (msg.includes("connection lost") || msg.includes("econnrefused"))
|
|
88
|
-
return { errorType: "Connection lost error", severity: "critical" };
|
|
89
|
-
if (msg.includes("query timeout"))
|
|
90
|
-
return { errorType: "Query timeout error", severity: "high" };
|
|
91
|
-
if (msg.includes("jwt expired") || msg.includes("token expired"))
|
|
92
|
-
return { errorType: "JWT expired error", severity: "high" };
|
|
93
|
-
if (msg.includes("jwt") && msg.includes("invalid"))
|
|
94
|
-
return { errorType: "JWT verification error", severity: "high" };
|
|
95
|
-
if (msg.includes("firebase admin"))
|
|
96
|
-
return { errorType: "Firebase admin error", severity: "critical" };
|
|
97
|
-
if (msg.includes("unauthorized") || msg.includes("permission denied"))
|
|
98
|
-
return { errorType: "Unauthorized access error", severity: "high" };
|
|
99
|
-
if (msg.includes("login failed") || msg.includes("invalid credentials"))
|
|
100
|
-
return { errorType: "Login failed error", severity: "medium" };
|
|
101
|
-
if (msg.includes("session ended") || msg.includes("session expired"))
|
|
102
|
-
return { errorType: "Session ended error", severity: "medium" };
|
|
103
|
-
if (msg.includes("oauth"))
|
|
104
|
-
return { errorType: "OAuth callback error", severity: "high" };
|
|
105
|
-
if (msg.includes("cron job") || msg.includes("cron failed"))
|
|
106
|
-
return { errorType: "Cron job failed", severity: "high" };
|
|
107
|
-
if (msg.includes("queue processing") || msg.includes("bullmq"))
|
|
108
|
-
return { errorType: "Queue processing error", severity: "high" };
|
|
109
|
-
if (msg.includes("webhook"))
|
|
110
|
-
return { errorType: "Webhook delivery failed", severity: "high" };
|
|
111
|
-
if (msg.includes("retry limit"))
|
|
112
|
-
return { errorType: "Retry limit exceeded", severity: "high" };
|
|
113
|
-
if (msg.includes("out of memory") || msg.includes("heap limit"))
|
|
114
|
-
return { errorType: "Out of memory error", severity: "critical" };
|
|
115
|
-
if (msg.includes("cannot find module"))
|
|
116
|
-
return { errorType: "Module not found error", severity: "critical" };
|
|
117
|
-
if (msg.includes("email") || msg.includes("smtp") || msg.includes("sendgrid") || msg.includes("nodemailer"))
|
|
118
|
-
return { errorType: "Email sending failed", severity: "high" };
|
|
119
|
-
if (msg.includes("onesignal") || msg.includes("push notification"))
|
|
120
|
-
return { errorType: "OneSignal API error", severity: "high" };
|
|
121
|
-
if (msg.includes("file upload") || msg.includes("upload failed"))
|
|
122
|
-
return { errorType: "File upload failed", severity: "high" };
|
|
123
|
-
if (msg.includes("file size exceeded") || msg.includes("payload too large"))
|
|
124
|
-
return { errorType: "File size exceeded", severity: "medium" };
|
|
125
|
-
if (msg.includes("invalid file type") || msg.includes("mime type"))
|
|
126
|
-
return { errorType: "Invalid file type", severity: "medium" };
|
|
107
|
+
return { category: "Hydration Error", severity: "high" };
|
|
108
|
+
if (msg.includes("invalid hook") || msg.includes("rules of hooks"))
|
|
109
|
+
return { category: "Hook Error", severity: "critical" };
|
|
110
|
+
if (msg.includes("render") || msg.includes("error boundary"))
|
|
111
|
+
return { category: "Render Error", severity: "critical" };
|
|
112
|
+
if (msg.includes("dynamic import") || msg.includes("failed to fetch dynamically"))
|
|
113
|
+
return { category: "Import Error", severity: "high" };
|
|
127
114
|
if (msg.includes("cors") || msg.includes("cross-origin"))
|
|
128
|
-
return {
|
|
129
|
-
if (msg.includes("fetch failed") || msg.includes("failed to fetch"))
|
|
130
|
-
return {
|
|
115
|
+
return { category: "CORS Error", severity: "high" };
|
|
116
|
+
if (msg.includes("fetch failed") || msg.includes("failed to fetch") || name === "fetcherror")
|
|
117
|
+
return { category: "Network Error", severity: "high" };
|
|
131
118
|
if (msg.includes("timeout") || msg.includes("timed out") || msg.includes("etimedout"))
|
|
132
|
-
return {
|
|
119
|
+
return { category: "Timeout Error", severity: "medium" };
|
|
133
120
|
if (msg.includes("websocket"))
|
|
134
|
-
return {
|
|
121
|
+
return { category: "WebSocket Error", severity: "high" };
|
|
122
|
+
if (msg.includes("http 401") || msg.includes("xhr 401"))
|
|
123
|
+
return { category: "Auth Error", severity: "high" };
|
|
124
|
+
if (msg.includes("http 403") || msg.includes("xhr 403"))
|
|
125
|
+
return { category: "Auth Error", severity: "high" };
|
|
126
|
+
if (msg.includes("http 404") || msg.includes("xhr 404"))
|
|
127
|
+
return { category: "Not Found Error", severity: "medium" };
|
|
128
|
+
if (msg.includes("http 500") || msg.includes("xhr 500"))
|
|
129
|
+
return { category: "Server Error", severity: "critical" };
|
|
130
|
+
if (msg.includes("http 503") || msg.includes("xhr 503"))
|
|
131
|
+
return { category: "Server Error", severity: "critical" };
|
|
132
|
+
if (msg.includes("maximum call stack") || msg.includes("out of memory") || msg.includes("heap limit"))
|
|
133
|
+
return { category: "Memory Error", severity: "critical" };
|
|
134
|
+
if (msg.includes("cannot find module") || msg.includes("module not found"))
|
|
135
|
+
return { category: "Module Error", severity: "critical" };
|
|
136
|
+
if (msg.includes("econnrefused") || msg.includes("connection refused"))
|
|
137
|
+
return { category: "Connection Error", severity: "critical" };
|
|
138
|
+
if (msg.includes("email") || msg.includes("smtp") || msg.includes("sendgrid"))
|
|
139
|
+
return { category: "Email Error", severity: "high" };
|
|
140
|
+
if (msg.includes("cron") || msg.includes("webhook") || msg.includes("queue"))
|
|
141
|
+
return { category: "Job Error", severity: "high" };
|
|
142
|
+
if (msg.includes("upload") || msg.includes("file size") || msg.includes("invalid file"))
|
|
143
|
+
return { category: "File Error", severity: "medium" };
|
|
144
|
+
if (msg.includes("quota exceeded") || msg.includes("localstorage") || msg.includes("indexeddb"))
|
|
145
|
+
return { category: "Storage Error", severity: "medium" };
|
|
146
|
+
if (name === "typeerror")
|
|
147
|
+
return { category: "TypeError", severity: "high" };
|
|
148
|
+
if (name === "referenceerror")
|
|
149
|
+
return { category: "ReferenceError", severity: "critical" };
|
|
150
|
+
if (name === "rangeerror")
|
|
151
|
+
return { category: "RangeError", severity: "high" };
|
|
152
|
+
if (name === "syntaxerror")
|
|
153
|
+
return { category: "SyntaxError", severity: "high" };
|
|
135
154
|
if (context === "unhandledrejection")
|
|
136
|
-
return {
|
|
137
|
-
if (context === "uncaughtexception")
|
|
138
|
-
return { errorType: "Uncaught exception", severity: "high" };
|
|
155
|
+
return { category: "Promise Error", severity: "medium" };
|
|
139
156
|
if (context === "express")
|
|
140
|
-
return {
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (err instanceof Error)
|
|
145
|
-
return { name: err.name, message: err.message, stack: err.stack };
|
|
146
|
-
if (typeof err === "string")
|
|
147
|
-
return { name: "Error", message: err, stack: new Error(err).stack };
|
|
148
|
-
if (err && typeof err === "object")
|
|
149
|
-
return {
|
|
150
|
-
name: err.name || err.code || "Error",
|
|
151
|
-
message: err.message || err.reason || JSON.stringify(err),
|
|
152
|
-
stack: err.stack || new Error(err.message).stack
|
|
153
|
-
};
|
|
154
|
-
return { name: "Error", message: "Unknown error", stack: new Error().stack };
|
|
155
|
-
}
|
|
156
|
-
async function send(payload) {
|
|
157
|
-
try {
|
|
158
|
-
if (payload.message?.includes("rapid-processor"))
|
|
159
|
-
return;
|
|
160
|
-
await fetch(ENDPOINT, {
|
|
161
|
-
method: "POST",
|
|
162
|
-
headers: {
|
|
163
|
-
"Content-Type": "application/json",
|
|
164
|
-
"x-api-key": _apiKey
|
|
165
|
-
},
|
|
166
|
-
body: JSON.stringify(payload)
|
|
167
|
-
});
|
|
168
|
-
} catch {
|
|
169
|
-
}
|
|
157
|
+
return { category: "Server Error", severity: "high" };
|
|
158
|
+
if (context === "resource")
|
|
159
|
+
return { category: "Resource Error", severity: "low" };
|
|
160
|
+
return { category: "Unknown Error", severity: "medium" };
|
|
170
161
|
}
|
|
171
162
|
function buildErrorPayload(error, context) {
|
|
172
|
-
const
|
|
173
|
-
const
|
|
174
|
-
const {
|
|
163
|
+
const message = error?.message || String(error) || "Unknown error";
|
|
164
|
+
const stack = error?.stack || "";
|
|
165
|
+
const { file, line, column } = parseStack(stack);
|
|
166
|
+
const { category, severity } = classifyError(error, context);
|
|
175
167
|
return {
|
|
176
168
|
type: "ERROR",
|
|
177
|
-
apiKey:
|
|
178
|
-
message
|
|
169
|
+
apiKey: _config?.apiKey,
|
|
170
|
+
message,
|
|
179
171
|
code: getErrorCode(error),
|
|
180
|
-
stack
|
|
172
|
+
stack,
|
|
181
173
|
file,
|
|
182
174
|
line,
|
|
183
175
|
column,
|
|
@@ -185,166 +177,157 @@ function buildErrorPayload(error, context) {
|
|
|
185
177
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
186
178
|
environment: getEnvironment(),
|
|
187
179
|
browser: getBrowser(),
|
|
188
|
-
error_category:
|
|
180
|
+
error_category: category,
|
|
189
181
|
severity,
|
|
190
|
-
status: "open"
|
|
182
|
+
status: "open",
|
|
183
|
+
context: context || "auto"
|
|
191
184
|
};
|
|
192
185
|
}
|
|
193
186
|
function activateBrowserListeners() {
|
|
194
187
|
window.addEventListener("error", (event) => {
|
|
195
|
-
if (event.filename?.includes("rapid-processor"))
|
|
196
|
-
return;
|
|
197
188
|
const target = event.target;
|
|
198
|
-
if (target && target.tagName) {
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
send(buildErrorPayload({
|
|
203
|
-
name: "ResourceError",
|
|
204
|
-
message: `${tag} failed to load: ${src}`,
|
|
205
|
-
stack: `at ${window.location.href}`
|
|
206
|
-
}));
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
189
|
+
if (target && target.tagName && ["IMG", "SCRIPT", "LINK", "VIDEO", "AUDIO"].includes(target.tagName)) {
|
|
190
|
+
const src = target.src || target.href || "unknown";
|
|
191
|
+
enqueue(buildErrorPayload({ name: "ResourceError", message: `${target.tagName} failed to load: ${src}`, stack: "" }, "resource"));
|
|
192
|
+
return;
|
|
209
193
|
}
|
|
210
194
|
const err = event.error || {
|
|
211
195
|
name: "Error",
|
|
212
196
|
message: event.message,
|
|
213
|
-
stack:
|
|
197
|
+
stack: `at ${event.filename}:${event.lineno}:${event.colno}`
|
|
214
198
|
};
|
|
215
|
-
|
|
199
|
+
enqueue(buildErrorPayload(err, "window"));
|
|
216
200
|
}, true);
|
|
217
201
|
window.addEventListener("unhandledrejection", (event) => {
|
|
218
|
-
|
|
202
|
+
const err = event.reason instanceof Error ? event.reason : { name: "UnhandledRejection", message: String(event.reason || "Unhandled Promise Rejection"), stack: "" };
|
|
203
|
+
enqueue(buildErrorPayload(err, "unhandledrejection"));
|
|
219
204
|
});
|
|
220
205
|
const originalFetch = window.fetch;
|
|
221
|
-
window.fetch = async function(
|
|
222
|
-
const url = typeof
|
|
223
|
-
if (url.includes("rapid-processor")
|
|
224
|
-
return originalFetch
|
|
225
|
-
}
|
|
206
|
+
window.fetch = async function(...args) {
|
|
207
|
+
const url = typeof args[0] === "string" ? args[0] : args[0] instanceof URL ? args[0].toString() : args[0]?.url ?? "";
|
|
208
|
+
if (url.includes("rapid-processor"))
|
|
209
|
+
return originalFetch(...args);
|
|
226
210
|
try {
|
|
227
|
-
const response = await originalFetch
|
|
211
|
+
const response = await originalFetch(...args);
|
|
228
212
|
if (!response.ok) {
|
|
229
|
-
|
|
230
|
-
name: `
|
|
231
|
-
message: `HTTP ${response.status}: ${
|
|
232
|
-
stack: `${
|
|
213
|
+
enqueue(buildErrorPayload({
|
|
214
|
+
name: `HTTP_${response.status}`,
|
|
215
|
+
message: `HTTP ${response.status}: ${args[1]?.method || "GET"} ${url}`,
|
|
216
|
+
stack: `${args[1]?.method || "GET"} ${url} \u2192 ${response.status} ${response.statusText}`,
|
|
233
217
|
status: response.status
|
|
234
|
-
}));
|
|
218
|
+
}, "fetch"));
|
|
235
219
|
}
|
|
236
220
|
return response;
|
|
237
221
|
} catch (err) {
|
|
238
|
-
|
|
222
|
+
enqueue(buildErrorPayload({
|
|
239
223
|
name: "FetchError",
|
|
240
|
-
message: `Fetch failed: ${
|
|
224
|
+
message: `Fetch failed: ${args[1]?.method || "GET"} ${url} \u2014 ${err.message}`,
|
|
241
225
|
stack: err.stack
|
|
242
|
-
}));
|
|
226
|
+
}, "fetch"));
|
|
243
227
|
throw err;
|
|
244
228
|
}
|
|
245
229
|
};
|
|
246
230
|
const originalOpen = XMLHttpRequest.prototype.open;
|
|
247
231
|
const originalSend = XMLHttpRequest.prototype.send;
|
|
248
|
-
XMLHttpRequest.prototype.open = function(method, url) {
|
|
232
|
+
XMLHttpRequest.prototype.open = function(method, url, ...rest) {
|
|
249
233
|
this._r_method = method;
|
|
250
234
|
this._r_url = url;
|
|
251
|
-
return originalOpen.
|
|
235
|
+
return originalOpen.call(this, method, url, ...rest);
|
|
252
236
|
};
|
|
253
|
-
XMLHttpRequest.prototype.send = function() {
|
|
254
|
-
this.
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
return originalSend.apply(this,
|
|
237
|
+
XMLHttpRequest.prototype.send = function(...args) {
|
|
238
|
+
const url = this._r_url || "";
|
|
239
|
+
const method = this._r_method || "GET";
|
|
240
|
+
if (!url.includes("rapid-processor")) {
|
|
241
|
+
this.addEventListener("loadend", () => {
|
|
242
|
+
if (this.status >= 400 || this.status === 0) {
|
|
243
|
+
enqueue(buildErrorPayload({
|
|
244
|
+
name: `XHR_${this.status}`,
|
|
245
|
+
message: `XHR ${this.status}: ${method} ${url}`,
|
|
246
|
+
stack: `${method} ${url} \u2192 ${this.status} ${this.statusText}`,
|
|
247
|
+
status: this.status
|
|
248
|
+
}, "xhr"));
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
return originalSend.apply(this, args);
|
|
269
253
|
};
|
|
270
254
|
window.addEventListener("beforeunload", () => {
|
|
271
255
|
try {
|
|
272
|
-
navigator.sendBeacon(
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
256
|
+
navigator.sendBeacon(
|
|
257
|
+
ENDPOINT,
|
|
258
|
+
JSON.stringify({
|
|
259
|
+
type: "SDK_DISCONNECTED",
|
|
260
|
+
apiKey: _config?.apiKey,
|
|
261
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
262
|
+
environment: getEnvironment(),
|
|
263
|
+
url: getUrl()
|
|
264
|
+
})
|
|
265
|
+
);
|
|
279
266
|
} catch {
|
|
280
267
|
}
|
|
281
268
|
});
|
|
282
269
|
}
|
|
283
270
|
function activateServerListeners() {
|
|
284
271
|
process.on("uncaughtException", (error) => {
|
|
285
|
-
|
|
272
|
+
enqueue(buildErrorPayload(error, "uncaughtException"));
|
|
273
|
+
flush();
|
|
286
274
|
});
|
|
287
275
|
process.on("unhandledRejection", (reason) => {
|
|
288
|
-
|
|
276
|
+
enqueue(buildErrorPayload(
|
|
289
277
|
reason instanceof Error ? reason : { name: "UnhandledRejection", message: String(reason), stack: "" },
|
|
290
278
|
"unhandledrejection"
|
|
291
279
|
));
|
|
292
280
|
});
|
|
293
|
-
const shutdown = async () => {
|
|
294
|
-
await
|
|
281
|
+
const shutdown = async (signal) => {
|
|
282
|
+
await sendNow({
|
|
295
283
|
type: "SDK_DISCONNECTED",
|
|
296
|
-
apiKey:
|
|
284
|
+
apiKey: _config?.apiKey,
|
|
297
285
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
298
|
-
environment:
|
|
299
|
-
url: getUrl()
|
|
286
|
+
environment: getEnvironment(),
|
|
287
|
+
url: getUrl(),
|
|
288
|
+
signal
|
|
300
289
|
});
|
|
301
290
|
process.exit(0);
|
|
302
291
|
};
|
|
303
|
-
process.on("SIGTERM", shutdown);
|
|
304
|
-
process.on("SIGINT", shutdown);
|
|
292
|
+
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
|
293
|
+
process.on("SIGINT", () => shutdown("SIGINT"));
|
|
305
294
|
}
|
|
306
295
|
var Reportli = {
|
|
307
|
-
init(
|
|
308
|
-
if (
|
|
296
|
+
init(cfg) {
|
|
297
|
+
if (initialized)
|
|
309
298
|
return;
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
}
|
|
324
|
-
} else {
|
|
325
|
-
send({
|
|
326
|
-
type: "SDK_INITIALIZED",
|
|
327
|
-
apiKey: _apiKey,
|
|
328
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
329
|
-
environment: getEnvironment(),
|
|
330
|
-
url: getUrl(),
|
|
331
|
-
browser: getBrowser()
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
if (isBrowser) {
|
|
299
|
+
if (!cfg?.apiKey)
|
|
300
|
+
return;
|
|
301
|
+
_config = cfg;
|
|
302
|
+
initialized = true;
|
|
303
|
+
sendImmediate({
|
|
304
|
+
type: "SDK_INITIALIZED",
|
|
305
|
+
apiKey: cfg.apiKey,
|
|
306
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
307
|
+
environment: getEnvironment(),
|
|
308
|
+
url: getUrl(),
|
|
309
|
+
browser: getBrowser()
|
|
310
|
+
});
|
|
311
|
+
if (typeof window !== "undefined") {
|
|
335
312
|
activateBrowserListeners();
|
|
336
|
-
} else if (
|
|
313
|
+
} else if (typeof process !== "undefined" && process.versions?.node) {
|
|
337
314
|
activateServerListeners();
|
|
338
315
|
}
|
|
339
316
|
},
|
|
340
317
|
capture(error) {
|
|
341
|
-
if (!
|
|
318
|
+
if (!initialized)
|
|
319
|
+
return;
|
|
320
|
+
const err = error instanceof Error ? error : { name: "ManualCapture", message: String(error), stack: new Error().stack };
|
|
321
|
+
enqueue(buildErrorPayload(err, "manual"));
|
|
322
|
+
},
|
|
323
|
+
captureMessage(message) {
|
|
324
|
+
if (!initialized)
|
|
342
325
|
return;
|
|
343
|
-
|
|
326
|
+
enqueue(buildErrorPayload({ name: "Message", message, stack: "" }, "manual"));
|
|
344
327
|
},
|
|
345
328
|
errorHandler() {
|
|
346
329
|
return function(err, _req, _res, next) {
|
|
347
|
-
|
|
330
|
+
enqueue(buildErrorPayload(err, "express"));
|
|
348
331
|
next(err);
|
|
349
332
|
};
|
|
350
333
|
}
|