@flareapp/js 1.2.1 → 2.0.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/CHANGELOG.md +33 -30
- package/README.md +26 -5
- package/dist/index.cjs +603 -0
- package/dist/index.d.cts +122 -0
- package/dist/index.d.mts +109 -96
- package/dist/index.mjs +516 -548
- package/package.json +29 -13
- package/.release-it.json +0 -17
- package/dist/index.d.ts +0 -109
- package/dist/index.js +0 -640
- package/src/Flare.ts +0 -203
- package/src/api/Api.ts +0 -27
- package/src/api/index.ts +0 -2
- package/src/api/mapToV2Wire.ts +0 -120
- package/src/api/v2WireTypes.ts +0 -39
- package/src/browser/catchWindowErrors.ts +0 -72
- package/src/browser/index.ts +0 -1
- package/src/context/collectContext.ts +0 -18
- package/src/context/cookie.ts +0 -24
- package/src/context/index.ts +0 -1
- package/src/context/request.ts +0 -10
- package/src/context/requestData.ts +0 -13
- package/src/env/index.ts +0 -12
- package/src/index.ts +0 -14
- package/src/solutions/getSolutions.ts +0 -35
- package/src/solutions/index.ts +0 -1
- package/src/stacktrace/createStackTrace.ts +0 -69
- package/src/stacktrace/fileReader.ts +0 -96
- package/src/stacktrace/index.ts +0 -1
- package/src/types.ts +0 -76
- package/src/util/assert.ts +0 -9
- package/src/util/assertKey.ts +0 -11
- package/src/util/assertSolutionProvider.ts +0 -12
- package/src/util/flatJsonStringify.ts +0 -25
- package/src/util/flattenOnce.ts +0 -5
- package/src/util/glowsToEvents.ts +0 -17
- package/src/util/index.ts +0 -7
- package/src/util/now.ts +0 -3
package/dist/index.mjs
CHANGED
|
@@ -1,602 +1,570 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import ErrorStackParser from "error-stack-parser";
|
|
2
|
+
|
|
3
|
+
//#region src/browser/catchWindowErrors.ts
|
|
4
|
+
function catchWindowErrors() {
|
|
5
|
+
if (typeof window === "undefined") return;
|
|
6
|
+
window.addEventListener("error", (event) => {
|
|
7
|
+
const flare = window.flare;
|
|
8
|
+
if (!flare) return;
|
|
9
|
+
if (event.error instanceof Error) Promise.resolve(flare.report(event.error)).catch(() => {});
|
|
10
|
+
});
|
|
11
|
+
window.addEventListener("unhandledrejection", (event) => {
|
|
12
|
+
const flare = window.flare;
|
|
13
|
+
if (!flare) return;
|
|
14
|
+
const reason = event.reason;
|
|
15
|
+
if (reason instanceof Error) {
|
|
16
|
+
Promise.resolve(flare.report(reason)).catch(() => {});
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (hasStack$1(reason)) {
|
|
20
|
+
const error = new Error(describeRejectionReason(reason));
|
|
21
|
+
error.stack = reason.stack;
|
|
22
|
+
Promise.resolve(flare.report(error)).catch(() => {});
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
Promise.resolve(flare.reportUnhandledRejection(describeRejectionReason(reason))).catch(() => {});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function describeRejectionReason(reason) {
|
|
29
|
+
if (typeof reason === "string") return reason;
|
|
30
|
+
if (reason && typeof reason === "object") {
|
|
31
|
+
const message = reason.message;
|
|
32
|
+
if (typeof message === "string") return message;
|
|
33
|
+
try {
|
|
34
|
+
return JSON.stringify(reason);
|
|
35
|
+
} catch {
|
|
36
|
+
return "Unhandled promise rejection (non-serializable reason)";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return String(reason);
|
|
40
|
+
}
|
|
41
|
+
function hasStack$1(value) {
|
|
42
|
+
return typeof value === "object" && value !== null && "stack" in value && typeof value.stack === "string";
|
|
43
|
+
}
|
|
5
44
|
|
|
6
|
-
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/env/index.ts
|
|
47
|
+
const CLIENT_VERSION = typeof process !== "undefined" && true ? "2.0.0" : "?";
|
|
48
|
+
const KEY = typeof FLARE_JS_KEY === "undefined" ? "" : FLARE_JS_KEY;
|
|
49
|
+
const SOURCEMAP_VERSION = typeof FLARE_SOURCEMAP_VERSION === "undefined" ? "" : FLARE_SOURCEMAP_VERSION;
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/util/assert.ts
|
|
7
53
|
function assert(value, message, debug) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
return !!value;
|
|
54
|
+
if (debug && !value) console.error(`Flare JavaScript client v${CLIENT_VERSION}: ${message}`);
|
|
55
|
+
return !!value;
|
|
12
56
|
}
|
|
13
57
|
|
|
14
|
-
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/util/assertKey.ts
|
|
15
60
|
function assertKey(key, debug) {
|
|
16
|
-
|
|
17
|
-
key,
|
|
18
|
-
"The client was not yet initialised with an API key. Run client.light('<flare-project-key>') when you initialise your app. If you are running in dev mode and didn't run the light command on purpose, you can ignore this error.",
|
|
19
|
-
debug
|
|
20
|
-
);
|
|
61
|
+
return assert(key, "The client was not yet initialised with an API key. Run client.light('<flare-project-key>') when you initialise your app. If you are running in dev mode and didn't run the light command on purpose, you can ignore this error.", debug);
|
|
21
62
|
}
|
|
22
63
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/util/extractCode.ts
|
|
66
|
+
const MAX_CODE_LENGTH = 64;
|
|
67
|
+
function extractCode(error) {
|
|
68
|
+
const code = error.code;
|
|
69
|
+
if (typeof code !== "string" || code.length === 0) return;
|
|
70
|
+
return code.slice(0, MAX_CODE_LENGTH);
|
|
30
71
|
}
|
|
31
72
|
|
|
32
|
-
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/util/flatJsonStringify.ts
|
|
33
75
|
function flatJsonStringify(json) {
|
|
34
|
-
|
|
35
|
-
const path = [];
|
|
36
|
-
return JSON.stringify(json, function(_key, value) {
|
|
37
|
-
if (typeof value !== "object" || value === null) {
|
|
38
|
-
return value;
|
|
39
|
-
}
|
|
40
|
-
while (path.length > 0 && path[path.length - 1] !== this) {
|
|
41
|
-
const popped = path.pop();
|
|
42
|
-
ancestors.delete(popped);
|
|
43
|
-
}
|
|
44
|
-
if (ancestors.has(value)) {
|
|
45
|
-
return "[Circular]";
|
|
46
|
-
}
|
|
47
|
-
ancestors.add(value);
|
|
48
|
-
path.push(value);
|
|
49
|
-
return value;
|
|
50
|
-
});
|
|
76
|
+
return JSON.stringify(decycle(json));
|
|
51
77
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
78
|
+
function isPlainObject(value) {
|
|
79
|
+
if (typeof value !== "object" || value === null) return false;
|
|
80
|
+
const proto = Object.getPrototypeOf(value);
|
|
81
|
+
return proto === Object.prototype || proto === null;
|
|
82
|
+
}
|
|
83
|
+
function decycle(root) {
|
|
84
|
+
const inPath = /* @__PURE__ */ new WeakSet();
|
|
85
|
+
function clone(node) {
|
|
86
|
+
if (Array.isArray(node)) {
|
|
87
|
+
if (inPath.has(node)) return "[Circular]";
|
|
88
|
+
inPath.add(node);
|
|
89
|
+
const result = node.map(clone);
|
|
90
|
+
inPath.delete(node);
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
if (isPlainObject(node)) {
|
|
94
|
+
if (inPath.has(node)) return "[Circular]";
|
|
95
|
+
inPath.add(node);
|
|
96
|
+
const result = {};
|
|
97
|
+
for (const [k, v] of Object.entries(node)) result[k] = clone(v);
|
|
98
|
+
inPath.delete(node);
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
return node;
|
|
102
|
+
}
|
|
103
|
+
return clone(root);
|
|
58
104
|
}
|
|
59
105
|
|
|
60
|
-
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/util/glowsToEvents.ts
|
|
61
108
|
function glowsToEvents(glows) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
109
|
+
return glows.map((glow) => ({
|
|
110
|
+
type: "php_glow",
|
|
111
|
+
startTimeUnixNano: Math.round(glow.microtime * 1e9),
|
|
112
|
+
endTimeUnixNano: null,
|
|
113
|
+
attributes: {
|
|
114
|
+
"glow.name": String(glow.name),
|
|
115
|
+
"glow.level": glow.messageLevel,
|
|
116
|
+
"glow.context": glow.metaData ?? {}
|
|
117
|
+
}
|
|
118
|
+
}));
|
|
72
119
|
}
|
|
73
120
|
|
|
74
|
-
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/util/now.ts
|
|
75
123
|
function now() {
|
|
76
|
-
|
|
124
|
+
return Math.round(Date.now() / 1e3);
|
|
77
125
|
}
|
|
78
126
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
function
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
wire.exceptionClass = report.exception_class;
|
|
91
|
-
}
|
|
92
|
-
if (report.message != null) {
|
|
93
|
-
wire.message = report.message;
|
|
94
|
-
}
|
|
95
|
-
if (report.sourcemap_version_id) {
|
|
96
|
-
wire.sourcemapVersionId = report.sourcemap_version_id;
|
|
97
|
-
}
|
|
98
|
-
return wire;
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/util/redactUrl.ts
|
|
129
|
+
const DEFAULT_URL_DENYLIST = /password|passwd|pwd|token|secret|authorization|\bauth\b|bearer|oauth|credentials?|cookie|api[-_]?key|private[-_]?key|session|csrf|xsrf|\bpin\b|\bssn\b|card[-_]?number|\bcvv\b/i;
|
|
130
|
+
function resolveDenylist(custom, replaceDefault = false, defaultDenylist = DEFAULT_URL_DENYLIST) {
|
|
131
|
+
if (!custom) return defaultDenylist;
|
|
132
|
+
if (replaceDefault) {
|
|
133
|
+
const safeFlags = custom.flags.replace(/[gy]/g, "");
|
|
134
|
+
return new RegExp(custom.source, safeFlags);
|
|
135
|
+
}
|
|
136
|
+
const flags = unionFlags(defaultDenylist.flags, custom.flags);
|
|
137
|
+
return new RegExp(`(?:${defaultDenylist.source})|(?:${custom.source})`, flags);
|
|
99
138
|
}
|
|
100
|
-
function
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
out.columnNumber = frame.column_number;
|
|
108
|
-
}
|
|
109
|
-
if (frame.method) {
|
|
110
|
-
out.method = frame.method;
|
|
111
|
-
}
|
|
112
|
-
if (frame.class) {
|
|
113
|
-
out.class = frame.class;
|
|
114
|
-
}
|
|
115
|
-
if (frame.code_snippet) {
|
|
116
|
-
out.codeSnippet = frame.code_snippet;
|
|
117
|
-
}
|
|
118
|
-
return out;
|
|
139
|
+
function unionFlags(a, b) {
|
|
140
|
+
const merged = /* @__PURE__ */ new Set();
|
|
141
|
+
for (const flag of a + b) {
|
|
142
|
+
if (flag === "g" || flag === "y") continue;
|
|
143
|
+
merged.add(flag);
|
|
144
|
+
}
|
|
145
|
+
return [...merged].join("");
|
|
119
146
|
}
|
|
120
|
-
function
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
const context = report.context ?? {};
|
|
138
|
-
if (context.request?.url) attrs["url.full"] = String(context.request.url);
|
|
139
|
-
if (context.request?.useragent) attrs["user_agent.original"] = String(context.request.useragent);
|
|
140
|
-
if (context.request?.referrer) attrs["http.request.referrer"] = String(context.request.referrer);
|
|
141
|
-
if (context.request?.readyState) attrs["document.ready_state"] = String(context.request.readyState);
|
|
142
|
-
if (context.request_data?.queryString) {
|
|
143
|
-
attrs["url.query"] = context.request_data.queryString;
|
|
144
|
-
}
|
|
145
|
-
if (context.cookies) {
|
|
146
|
-
attrs["http.request.cookies"] = context.cookies;
|
|
147
|
-
}
|
|
148
|
-
const custom = buildCustomContext(context);
|
|
149
|
-
if (Object.keys(custom).length > 0) {
|
|
150
|
-
attrs["context.custom"] = custom;
|
|
151
|
-
}
|
|
152
|
-
return attrs;
|
|
147
|
+
function redactFullPath(fullPath, denylist = DEFAULT_URL_DENYLIST) {
|
|
148
|
+
const queryStart = fullPath.indexOf("?");
|
|
149
|
+
if (queryStart === -1) return fullPath;
|
|
150
|
+
const hashStart = fullPath.indexOf("#", queryStart);
|
|
151
|
+
const queryEnd = hashStart === -1 ? fullPath.length : hashStart;
|
|
152
|
+
const prefix = fullPath.slice(0, queryStart + 1);
|
|
153
|
+
const queryString = fullPath.slice(queryStart + 1, queryEnd);
|
|
154
|
+
const suffix = fullPath.slice(queryEnd);
|
|
155
|
+
return `${prefix}${queryString.split("&").map((pair) => {
|
|
156
|
+
if (pair === "") return pair;
|
|
157
|
+
const eq = pair.indexOf("=");
|
|
158
|
+
const rawKey = eq === -1 ? pair : pair.slice(0, eq);
|
|
159
|
+
const decodedKey = safeDecode(rawKey);
|
|
160
|
+
if (!denylist.test(decodedKey)) return pair;
|
|
161
|
+
return eq === -1 ? rawKey : `${rawKey}=[redacted]`;
|
|
162
|
+
}).join("&")}${suffix}`;
|
|
153
163
|
}
|
|
154
|
-
function
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const added = context.context;
|
|
161
|
-
if (added && typeof added === "object") {
|
|
162
|
-
for (const key of Object.keys(added)) {
|
|
163
|
-
custom[key] = added[key];
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return custom;
|
|
164
|
+
function safeDecode(value) {
|
|
165
|
+
try {
|
|
166
|
+
return decodeURIComponent(value);
|
|
167
|
+
} catch {
|
|
168
|
+
return value;
|
|
169
|
+
}
|
|
167
170
|
}
|
|
168
171
|
|
|
169
|
-
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/api/Api.ts
|
|
170
174
|
var Api = class {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
(error) => console.error(error)
|
|
189
|
-
);
|
|
190
|
-
}
|
|
175
|
+
report(report, url, key, reportBrowserExtensionErrors, debug = false) {
|
|
176
|
+
return fetch(url, {
|
|
177
|
+
method: "POST",
|
|
178
|
+
headers: {
|
|
179
|
+
"Accept": "application/json",
|
|
180
|
+
"Content-Type": "application/json",
|
|
181
|
+
"X-Api-Token": key ?? "",
|
|
182
|
+
"X-Report-Browser-Extension-Errors": JSON.stringify(reportBrowserExtensionErrors),
|
|
183
|
+
"X-Flare-Client-Version": "2"
|
|
184
|
+
},
|
|
185
|
+
body: flatJsonStringify(report)
|
|
186
|
+
}).then((response) => {
|
|
187
|
+
if (debug && response.status !== 201) console.error(`Received response with status ${response.status} from Flare`);
|
|
188
|
+
}, (error) => {
|
|
189
|
+
if (debug) console.error(error);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
191
192
|
};
|
|
192
193
|
|
|
193
|
-
|
|
194
|
+
//#endregion
|
|
195
|
+
//#region src/context/cookie.ts
|
|
194
196
|
function cookie() {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
if (Object.keys(cookies).length === 0) {
|
|
209
|
-
return {};
|
|
210
|
-
}
|
|
211
|
-
return { cookies };
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// src/context/request.ts
|
|
215
|
-
function request() {
|
|
216
|
-
return {
|
|
217
|
-
request: {
|
|
218
|
-
url: window.document.location.href,
|
|
219
|
-
useragent: window.navigator.userAgent,
|
|
220
|
-
referrer: window.document.referrer,
|
|
221
|
-
readyState: window.document.readyState
|
|
222
|
-
}
|
|
223
|
-
};
|
|
197
|
+
if (!window.document.cookie) return {};
|
|
198
|
+
const cookies = {};
|
|
199
|
+
window.document.cookie.split("; ").forEach((rawCookie) => {
|
|
200
|
+
const idx = rawCookie.indexOf("=");
|
|
201
|
+
if (idx === -1) {
|
|
202
|
+
cookies[rawCookie] = "";
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const name = rawCookie.slice(0, idx);
|
|
206
|
+
cookies[name] = rawCookie.slice(idx + 1);
|
|
207
|
+
});
|
|
208
|
+
return { "http.request.cookies": cookies };
|
|
224
209
|
}
|
|
225
210
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
return { request_data: { queryString } };
|
|
211
|
+
//#endregion
|
|
212
|
+
//#region src/context/request.ts
|
|
213
|
+
function request(urlDenylist) {
|
|
214
|
+
return {
|
|
215
|
+
"url.full": redactFullPath(window.location.href, urlDenylist),
|
|
216
|
+
"user_agent.original": window.navigator.userAgent,
|
|
217
|
+
"http.request.referrer": redactFullPath(window.document.referrer, urlDenylist),
|
|
218
|
+
"document.ready_state": window.document.readyState
|
|
219
|
+
};
|
|
236
220
|
}
|
|
237
221
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
return {
|
|
244
|
-
...cookie(),
|
|
245
|
-
...request(),
|
|
246
|
-
...requestData(),
|
|
247
|
-
...additionalContext
|
|
248
|
-
};
|
|
222
|
+
//#endregion
|
|
223
|
+
//#region src/context/requestData.ts
|
|
224
|
+
function requestData(urlDenylist) {
|
|
225
|
+
if (!window.location.search) return {};
|
|
226
|
+
return { "url.query": redactFullPath(window.location.search, urlDenylist).replace(/^\?/, "") };
|
|
249
227
|
}
|
|
250
228
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
);
|
|
261
|
-
Promise.all(canSolves).then((resolvedCanSolves) => {
|
|
262
|
-
const solutionPromises = [];
|
|
263
|
-
resolvedCanSolves.forEach((canSolve, i) => {
|
|
264
|
-
if (canSolve) {
|
|
265
|
-
solutionPromises.push(
|
|
266
|
-
Promise.resolve(solutionProviders[i].getSolutions(error, extraSolutionParameters))
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
Promise.all(solutionPromises).then((solutions) => {
|
|
271
|
-
resolve(flattenOnce(solutions));
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
});
|
|
229
|
+
//#endregion
|
|
230
|
+
//#region src/context/collectAttributes.ts
|
|
231
|
+
function collectAttributes(urlDenylist) {
|
|
232
|
+
if (typeof window === "undefined") return {};
|
|
233
|
+
return {
|
|
234
|
+
...request(urlDenylist),
|
|
235
|
+
...requestData(urlDenylist),
|
|
236
|
+
...cookie()
|
|
237
|
+
};
|
|
275
238
|
}
|
|
276
239
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
// src/stacktrace/fileReader.ts
|
|
281
|
-
var cachedFiles = {};
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region src/stacktrace/fileReader.ts
|
|
242
|
+
const cachedFiles = {};
|
|
282
243
|
function getCodeSnippet(url, lineNumber, columnNumber) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
});
|
|
244
|
+
return new Promise((resolve) => {
|
|
245
|
+
if (!url || !lineNumber) return resolve({
|
|
246
|
+
codeSnippet: { 0: `Could not read from file: missing file URL or line number. URL: ${url} lineNumber: ${lineNumber}` },
|
|
247
|
+
trimmedColumnNumber: null
|
|
248
|
+
});
|
|
249
|
+
if (!isFetchableUrl(url)) return resolve({
|
|
250
|
+
codeSnippet: { 0: `Could not read from file: unsupported URL scheme. URL: ${url}` },
|
|
251
|
+
trimmedColumnNumber: null
|
|
252
|
+
});
|
|
253
|
+
readFile(url).then((fileText) => {
|
|
254
|
+
if (!fileText) return resolve({
|
|
255
|
+
codeSnippet: { 0: `Could not read from file: Error while opening file at URL ${url}` },
|
|
256
|
+
trimmedColumnNumber: null
|
|
257
|
+
});
|
|
258
|
+
return resolve(readLinesFromFile(fileText, lineNumber, columnNumber));
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
function isFetchableUrl(url) {
|
|
263
|
+
return /^https?:\/\//i.test(url);
|
|
304
264
|
}
|
|
305
265
|
function readFile(url) {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
}).catch(() => null);
|
|
266
|
+
if (cachedFiles[url] !== void 0) return Promise.resolve(cachedFiles[url]);
|
|
267
|
+
return fetch(url).then((response) => {
|
|
268
|
+
if (response.status !== 200) return null;
|
|
269
|
+
return response.text();
|
|
270
|
+
}).then((text) => {
|
|
271
|
+
if (text !== null) cachedFiles[url] = text;
|
|
272
|
+
return text;
|
|
273
|
+
}).catch(() => null);
|
|
315
274
|
}
|
|
316
275
|
function readLinesFromFile(fileText, lineNumber, columnNumber, maxSnippetLineLength = 1e3, maxSnippetLines = 40) {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
276
|
+
const codeSnippet = {};
|
|
277
|
+
let trimmedColumnNumber = null;
|
|
278
|
+
const lines = fileText.split("\n");
|
|
279
|
+
const errorLineIndex = lineNumber - 1;
|
|
280
|
+
const half = Math.floor(maxSnippetLines / 2);
|
|
281
|
+
for (let i = -half; i <= half; i++) {
|
|
282
|
+
const currentLineIndex = errorLineIndex + i;
|
|
283
|
+
if (currentLineIndex < 0 || !lines[currentLineIndex]) continue;
|
|
284
|
+
const displayLine = currentLineIndex + 1;
|
|
285
|
+
const line = lines[currentLineIndex];
|
|
286
|
+
if (line.length > maxSnippetLineLength) {
|
|
287
|
+
if (columnNumber && columnNumber > maxSnippetLineLength / 2) {
|
|
288
|
+
const start = columnNumber - Math.round(maxSnippetLineLength / 2);
|
|
289
|
+
codeSnippet[displayLine] = line.slice(start, start + maxSnippetLineLength);
|
|
290
|
+
if (displayLine === lineNumber) trimmedColumnNumber = Math.round(maxSnippetLineLength / 2);
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
codeSnippet[displayLine] = line.slice(0, maxSnippetLineLength) + "…";
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
codeSnippet[displayLine] = line;
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
codeSnippet,
|
|
300
|
+
trimmedColumnNumber
|
|
301
|
+
};
|
|
342
302
|
}
|
|
343
303
|
|
|
344
|
-
|
|
304
|
+
//#endregion
|
|
305
|
+
//#region src/stacktrace/createStackTrace.ts
|
|
345
306
|
function createStackTrace(error, debug) {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
file: frame.fileName || "Unknown file",
|
|
372
|
-
code_snippet: snippet.codeSnippet,
|
|
373
|
-
trimmed_column_number: snippet.trimmedColumnNumber,
|
|
374
|
-
class: ""
|
|
375
|
-
});
|
|
376
|
-
});
|
|
377
|
-
});
|
|
378
|
-
})
|
|
379
|
-
).then(resolve);
|
|
380
|
-
});
|
|
307
|
+
return new Promise((resolve) => {
|
|
308
|
+
if (!hasStack(error)) return resolve([fallbackFrame("stacktrace missing")]);
|
|
309
|
+
let parsedFrames;
|
|
310
|
+
try {
|
|
311
|
+
parsedFrames = ErrorStackParser.parse(error);
|
|
312
|
+
} catch (parseError) {
|
|
313
|
+
assert(false, "Couldn't parse stacktrace of below error:", debug);
|
|
314
|
+
if (debug) {
|
|
315
|
+
console.error(parseError);
|
|
316
|
+
console.error(error);
|
|
317
|
+
}
|
|
318
|
+
return resolve([fallbackFrame("stacktrace could not be parsed")]);
|
|
319
|
+
}
|
|
320
|
+
Promise.all(parsedFrames.map((frame) => {
|
|
321
|
+
return getCodeSnippet(frame.fileName, frame.lineNumber, frame.columnNumber).then((snippet) => ({
|
|
322
|
+
lineNumber: frame.lineNumber || 1,
|
|
323
|
+
columnNumber: frame.columnNumber || 1,
|
|
324
|
+
method: frame.functionName || "Anonymous or unknown function",
|
|
325
|
+
file: frame.fileName || "Unknown file",
|
|
326
|
+
codeSnippet: snippet.codeSnippet,
|
|
327
|
+
class: "",
|
|
328
|
+
isApplicationFrame: isApplicationFrame(frame.fileName)
|
|
329
|
+
}));
|
|
330
|
+
})).then(resolve);
|
|
331
|
+
});
|
|
381
332
|
}
|
|
382
|
-
function fallbackFrame(
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
};
|
|
333
|
+
function fallbackFrame(reason) {
|
|
334
|
+
return {
|
|
335
|
+
lineNumber: 0,
|
|
336
|
+
columnNumber: 0,
|
|
337
|
+
method: "unknown",
|
|
338
|
+
file: "unknown",
|
|
339
|
+
codeSnippet: { 0: `Could not read from file: ${reason}` },
|
|
340
|
+
class: "unknown"
|
|
341
|
+
};
|
|
392
342
|
}
|
|
393
343
|
function hasStack(err) {
|
|
394
|
-
|
|
344
|
+
if (!err || typeof err !== "object") return false;
|
|
345
|
+
const e = err;
|
|
346
|
+
const stack = e.stack ?? e.stacktrace ?? e["opera#sourceloc"];
|
|
347
|
+
return typeof stack === "string" && stack !== `${e.name}: ${e.message}`;
|
|
348
|
+
}
|
|
349
|
+
function isApplicationFrame(fileName) {
|
|
350
|
+
if (!fileName) return true;
|
|
351
|
+
if (/[/\\]node_modules[/\\]/.test(fileName)) return false;
|
|
352
|
+
if (/(^|[/\\])(vendor|vendors)[.~-][^/\\]*\.js/i.test(fileName)) return false;
|
|
353
|
+
return true;
|
|
395
354
|
}
|
|
396
355
|
|
|
397
|
-
|
|
356
|
+
//#endregion
|
|
357
|
+
//#region src/Flare.ts
|
|
358
|
+
const DEFAULT_SDK_NAME = "@flareapp/js";
|
|
398
359
|
var Flare = class {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
360
|
+
_config = {
|
|
361
|
+
key: null,
|
|
362
|
+
version: "",
|
|
363
|
+
sourcemapVersionId: SOURCEMAP_VERSION,
|
|
364
|
+
stage: "",
|
|
365
|
+
maxGlowsPerReport: 30,
|
|
366
|
+
ingestUrl: "https://ingress.flareapp.io/v1/errors",
|
|
367
|
+
reportBrowserExtensionErrors: false,
|
|
368
|
+
debug: false,
|
|
369
|
+
urlDenylist: DEFAULT_URL_DENYLIST,
|
|
370
|
+
replaceDefaultUrlDenylist: false,
|
|
371
|
+
sampleRate: 1,
|
|
372
|
+
beforeEvaluate: (error) => error,
|
|
373
|
+
beforeSubmit: (report) => report
|
|
374
|
+
};
|
|
375
|
+
_glows = [];
|
|
376
|
+
pendingAttributes = {};
|
|
377
|
+
entryPoint = null;
|
|
378
|
+
sdkInfo = {
|
|
379
|
+
name: DEFAULT_SDK_NAME,
|
|
380
|
+
version: CLIENT_VERSION
|
|
381
|
+
};
|
|
382
|
+
framework = null;
|
|
383
|
+
constructor(api = new Api()) {
|
|
384
|
+
this.api = api;
|
|
385
|
+
}
|
|
386
|
+
get config() {
|
|
387
|
+
return this._config;
|
|
388
|
+
}
|
|
389
|
+
get glows() {
|
|
390
|
+
return this._glows;
|
|
391
|
+
}
|
|
392
|
+
light(key = KEY, debug) {
|
|
393
|
+
this._config.key = key;
|
|
394
|
+
if (debug !== void 0) this._config.debug = debug;
|
|
395
|
+
return this;
|
|
396
|
+
}
|
|
397
|
+
configure(config) {
|
|
398
|
+
this._config = {
|
|
399
|
+
...this._config,
|
|
400
|
+
...config
|
|
401
|
+
};
|
|
402
|
+
if (config.sampleRate !== void 0) this._config.sampleRate = Math.max(0, Math.min(1, config.sampleRate));
|
|
403
|
+
this._config.urlDenylist = resolveDenylist(config.urlDenylist, config.replaceDefaultUrlDenylist ?? this._config.replaceDefaultUrlDenylist);
|
|
404
|
+
return this;
|
|
405
|
+
}
|
|
406
|
+
async test() {
|
|
407
|
+
const report = await this.createReportFromError(/* @__PURE__ */ new Error("The Flare client is set up correctly!"));
|
|
408
|
+
if (!report) return;
|
|
409
|
+
return this.sendReport(report);
|
|
410
|
+
}
|
|
411
|
+
glow(name, level = "info", data = []) {
|
|
412
|
+
const time = now();
|
|
413
|
+
this._glows.push({
|
|
414
|
+
name,
|
|
415
|
+
messageLevel: level,
|
|
416
|
+
metaData: data,
|
|
417
|
+
time,
|
|
418
|
+
microtime: time
|
|
419
|
+
});
|
|
420
|
+
if (this._glows.length > this._config.maxGlowsPerReport) this._glows = this._glows.slice(this._glows.length - this._config.maxGlowsPerReport);
|
|
421
|
+
return this;
|
|
422
|
+
}
|
|
423
|
+
clearGlows() {
|
|
424
|
+
this._glows = [];
|
|
425
|
+
return this;
|
|
426
|
+
}
|
|
427
|
+
addContext(name, value) {
|
|
428
|
+
const existing = this.pendingAttributes["context.custom"] ?? {};
|
|
429
|
+
this.pendingAttributes["context.custom"] = {
|
|
430
|
+
...existing,
|
|
431
|
+
[name]: value
|
|
432
|
+
};
|
|
433
|
+
return this;
|
|
434
|
+
}
|
|
435
|
+
addContextGroup(groupName, value) {
|
|
436
|
+
this.pendingAttributes[`context.${groupName}`] = value;
|
|
437
|
+
return this;
|
|
438
|
+
}
|
|
439
|
+
setEntryPoint(handler) {
|
|
440
|
+
this.entryPoint = handler;
|
|
441
|
+
return this;
|
|
442
|
+
}
|
|
443
|
+
setSdkInfo(info) {
|
|
444
|
+
this.sdkInfo = info;
|
|
445
|
+
return this;
|
|
446
|
+
}
|
|
447
|
+
setFramework(framework) {
|
|
448
|
+
this.framework = framework;
|
|
449
|
+
return this;
|
|
450
|
+
}
|
|
451
|
+
async report(error, attributes = {}) {
|
|
452
|
+
if (this._config.sampleRate < 1 && Math.random() >= this._config.sampleRate) return;
|
|
453
|
+
const seenAtUnixNano = Date.now() * 1e6;
|
|
454
|
+
const coerced = error instanceof Error ? error : new Error(typeof error === "string" ? error : String(error));
|
|
455
|
+
const errorToReport = await this._config.beforeEvaluate(coerced);
|
|
456
|
+
if (!errorToReport) return;
|
|
457
|
+
const report = await this.createReportFromError(errorToReport, attributes, seenAtUnixNano);
|
|
458
|
+
if (!report) return;
|
|
459
|
+
return this.sendReport(report);
|
|
460
|
+
}
|
|
461
|
+
async reportUnhandledRejection(message, attributes = {}) {
|
|
462
|
+
if (Math.random() >= this._config.sampleRate) return;
|
|
463
|
+
const seenAtUnixNano = Date.now() * 1e6;
|
|
464
|
+
const report = this.buildReport({
|
|
465
|
+
exceptionClass: "UnhandledRejection",
|
|
466
|
+
message,
|
|
467
|
+
stacktrace: [],
|
|
468
|
+
isLog: false,
|
|
469
|
+
level: void 0,
|
|
470
|
+
extraAttributes: attributes,
|
|
471
|
+
code: void 0,
|
|
472
|
+
seenAtUnixNano
|
|
473
|
+
});
|
|
474
|
+
return this.sendReport(report);
|
|
475
|
+
}
|
|
476
|
+
async reportMessage(message, level, attributes = {}) {
|
|
477
|
+
if (this._config.sampleRate < 1 && Math.random() >= this._config.sampleRate) return;
|
|
478
|
+
const seenAtUnixNano = Date.now() * 1e6;
|
|
479
|
+
const stackTrace = await createStackTrace(/* @__PURE__ */ new Error(), this._config.debug);
|
|
480
|
+
stackTrace.shift();
|
|
481
|
+
const report = this.buildReport({
|
|
482
|
+
exceptionClass: "Log",
|
|
483
|
+
message,
|
|
484
|
+
stacktrace: stackTrace,
|
|
485
|
+
isLog: true,
|
|
486
|
+
level,
|
|
487
|
+
extraAttributes: attributes,
|
|
488
|
+
code: void 0,
|
|
489
|
+
seenAtUnixNano
|
|
490
|
+
});
|
|
491
|
+
return this.sendReport(report);
|
|
492
|
+
}
|
|
493
|
+
async createReportFromError(error, attributes = {}, seenAtUnixNano = Date.now() * 1e6) {
|
|
494
|
+
if (!assert(error, "No error provided.", this._config.debug)) return false;
|
|
495
|
+
const stacktrace = await createStackTrace(error, this._config.debug);
|
|
496
|
+
assert(stacktrace.length, "Couldn't generate stacktrace of this error: " + error, this._config.debug);
|
|
497
|
+
const exceptionClass = error.constructor && error.constructor.name ? error.constructor.name : "undefined";
|
|
498
|
+
return this.buildReport({
|
|
499
|
+
exceptionClass,
|
|
500
|
+
message: error.message,
|
|
501
|
+
stacktrace,
|
|
502
|
+
isLog: false,
|
|
503
|
+
level: void 0,
|
|
504
|
+
extraAttributes: attributes,
|
|
505
|
+
code: extractCode(error),
|
|
506
|
+
seenAtUnixNano
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
buildReport(input) {
|
|
510
|
+
const baseAttributes = {
|
|
511
|
+
"telemetry.sdk.language": "javascript",
|
|
512
|
+
"telemetry.sdk.name": this.sdkInfo.name,
|
|
513
|
+
"telemetry.sdk.version": this.sdkInfo.version,
|
|
514
|
+
"flare.language.name": "javascript",
|
|
515
|
+
"flare.entry_point.type": "web"
|
|
516
|
+
};
|
|
517
|
+
if (typeof window !== "undefined" && window?.location?.href) baseAttributes["flare.entry_point.value"] = redactFullPath(window.location.href, this._config.urlDenylist);
|
|
518
|
+
const handlerIdentifier = this.entryPoint?.identifier ?? (typeof window !== "undefined" && window?.location?.pathname ? window.location.pathname : void 0);
|
|
519
|
+
const handlerType = this.entryPoint?.type ?? (typeof window !== "undefined" && window ? "browser" : void 0);
|
|
520
|
+
if (handlerIdentifier !== void 0) baseAttributes["flare.entry_point.handler.identifier"] = handlerIdentifier;
|
|
521
|
+
if (handlerType !== void 0) baseAttributes["flare.entry_point.handler.type"] = handlerType;
|
|
522
|
+
if (this.entryPoint?.name !== void 0) baseAttributes["flare.entry_point.handler.name"] = this.entryPoint.name;
|
|
523
|
+
if (this.framework?.name) baseAttributes["flare.framework.name"] = this.framework.name;
|
|
524
|
+
if (this.framework?.version) baseAttributes["flare.framework.version"] = this.framework.version;
|
|
525
|
+
if (this._config.stage) baseAttributes["service.stage"] = this._config.stage;
|
|
526
|
+
if (this._config.version) baseAttributes["service.version"] = this._config.version;
|
|
527
|
+
const attributes = {
|
|
528
|
+
...baseAttributes,
|
|
529
|
+
...collectAttributes(this._config.urlDenylist),
|
|
530
|
+
...this.pendingAttributes,
|
|
531
|
+
...input.extraAttributes
|
|
532
|
+
};
|
|
533
|
+
const pendingCustom = this.pendingAttributes["context.custom"];
|
|
534
|
+
const extraCustom = input.extraAttributes["context.custom"];
|
|
535
|
+
if (pendingCustom && extraCustom && typeof pendingCustom === "object" && typeof extraCustom === "object" && !Array.isArray(pendingCustom) && !Array.isArray(extraCustom)) attributes["context.custom"] = {
|
|
536
|
+
...pendingCustom,
|
|
537
|
+
...extraCustom
|
|
538
|
+
};
|
|
539
|
+
const report = {
|
|
540
|
+
exceptionClass: input.exceptionClass,
|
|
541
|
+
message: input.message,
|
|
542
|
+
seenAtUnixNano: input.seenAtUnixNano,
|
|
543
|
+
stacktrace: input.stacktrace,
|
|
544
|
+
events: glowsToEvents(this._glows),
|
|
545
|
+
attributes
|
|
546
|
+
};
|
|
547
|
+
if (input.isLog) report.isLog = true;
|
|
548
|
+
if (input.level !== void 0) report.level = input.level;
|
|
549
|
+
if (this._config.sourcemapVersionId) report.sourcemapVersionId = this._config.sourcemapVersionId;
|
|
550
|
+
if (input.code !== void 0) report.code = input.code;
|
|
551
|
+
return report;
|
|
552
|
+
}
|
|
553
|
+
async sendReport(report) {
|
|
554
|
+
if (!assertKey(this._config.key, this._config.debug)) return;
|
|
555
|
+
const reportToSubmit = await this._config.beforeSubmit(report);
|
|
556
|
+
if (!reportToSubmit) return;
|
|
557
|
+
return this.api.report(reportToSubmit, this._config.ingestUrl, this._config.key, this._config.reportBrowserExtensionErrors, this._config.debug);
|
|
558
|
+
}
|
|
536
559
|
};
|
|
537
560
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
return;
|
|
542
|
-
}
|
|
543
|
-
const flare2 = window.flare;
|
|
544
|
-
if (!window || !flare2) {
|
|
545
|
-
return;
|
|
546
|
-
}
|
|
547
|
-
window.addEventListener("error", (event) => {
|
|
548
|
-
if (event.error) {
|
|
549
|
-
flare2.report(event.error);
|
|
550
|
-
}
|
|
551
|
-
});
|
|
552
|
-
window.addEventListener("unhandledrejection", (event) => {
|
|
553
|
-
const reason = event.reason;
|
|
554
|
-
if (reason instanceof Error) {
|
|
555
|
-
flare2.report(reason);
|
|
556
|
-
return;
|
|
557
|
-
}
|
|
558
|
-
if (hasStack2(reason)) {
|
|
559
|
-
const error = new Error(rejectionReasonToMessage(reason));
|
|
560
|
-
error.stack = reason.stack;
|
|
561
|
-
flare2.report(error);
|
|
562
|
-
return;
|
|
563
|
-
}
|
|
564
|
-
flare2.reportMessage(rejectionReasonToMessage(reason), {}, "UnhandledPromiseRejection");
|
|
565
|
-
});
|
|
566
|
-
}
|
|
567
|
-
function rejectionReasonToMessage(reason) {
|
|
568
|
-
if (typeof reason === "string") {
|
|
569
|
-
return reason;
|
|
570
|
-
}
|
|
571
|
-
if (reason == null) {
|
|
572
|
-
return `Unhandled promise rejection (${reason})`;
|
|
573
|
-
}
|
|
574
|
-
if (typeof reason === "object") {
|
|
575
|
-
if ("message" in reason && typeof reason.message === "string") {
|
|
576
|
-
return reason.message;
|
|
577
|
-
}
|
|
578
|
-
try {
|
|
579
|
-
const json = JSON.stringify(reason);
|
|
580
|
-
if (json && json !== "{}") {
|
|
581
|
-
return `Unhandled promise rejection: ${json}`;
|
|
582
|
-
}
|
|
583
|
-
} catch {
|
|
584
|
-
}
|
|
585
|
-
return "Unhandled promise rejection with non-serializable object";
|
|
586
|
-
}
|
|
587
|
-
return `Unhandled promise rejection: ${String(reason)}`;
|
|
588
|
-
}
|
|
589
|
-
function hasStack2(value) {
|
|
590
|
-
return typeof value === "object" && value !== null && "stack" in value && typeof value.stack === "string";
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
// src/index.ts
|
|
594
|
-
var flare = new Flare();
|
|
561
|
+
//#endregion
|
|
562
|
+
//#region src/index.ts
|
|
563
|
+
const flare = new Flare();
|
|
595
564
|
if (typeof window !== "undefined" && window) {
|
|
596
|
-
|
|
597
|
-
|
|
565
|
+
window.flare = flare;
|
|
566
|
+
catchWindowErrors();
|
|
598
567
|
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
};
|
|
568
|
+
|
|
569
|
+
//#endregion
|
|
570
|
+
export { DEFAULT_URL_DENYLIST, Flare, flare, redactFullPath, resolveDenylist };
|