@flareapp/js 2.0.1 → 2.2.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/dist/index.cjs CHANGED
@@ -1,33 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- //#region \0rolldown/runtime.js
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
- key = keys[i];
13
- if (!__hasOwnProp.call(to, key) && key !== except) {
14
- __defProp(to, key, {
15
- get: ((k) => from[k]).bind(null, key),
16
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
- });
18
- }
19
- }
20
- }
21
- return to;
22
- };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
- value: mod,
25
- enumerable: true
26
- }) : target, mod));
27
-
28
- //#endregion
29
- let error_stack_parser = require("error-stack-parser");
30
- error_stack_parser = __toESM(error_stack_parser);
2
+ let _flareapp_core = require("@flareapp/core");
31
3
 
32
4
  //#region src/browser/catchWindowErrors.ts
33
5
  function catchWindowErrors() {
@@ -45,7 +17,7 @@ function catchWindowErrors() {
45
17
  flare.reportSilently(reason);
46
18
  return;
47
19
  }
48
- if (hasStack$1(reason)) {
20
+ if (hasStack(reason)) {
49
21
  const error = new Error(describeRejectionReason(reason));
50
22
  error.stack = reason.stack;
51
23
  flare.reportSilently(error);
@@ -67,177 +39,12 @@ function describeRejectionReason(reason) {
67
39
  }
68
40
  return String(reason);
69
41
  }
70
- function hasStack$1(value) {
42
+ function hasStack(value) {
71
43
  return typeof value === "object" && value !== null && "stack" in value && typeof value.stack === "string";
72
44
  }
73
45
 
74
46
  //#endregion
75
- //#region src/env/index.ts
76
- const CLIENT_VERSION = typeof process !== "undefined" && true ? "2.0.1" : "?";
77
- const KEY = typeof FLARE_JS_KEY === "undefined" ? "" : FLARE_JS_KEY;
78
- const SOURCEMAP_VERSION = typeof FLARE_SOURCEMAP_VERSION === "undefined" ? "" : FLARE_SOURCEMAP_VERSION;
79
-
80
- //#endregion
81
- //#region src/util/assert.ts
82
- function assert(value, message, debug) {
83
- if (debug && !value) console.error(`Flare JavaScript client v${CLIENT_VERSION}: ${message}`);
84
- return !!value;
85
- }
86
-
87
- //#endregion
88
- //#region src/util/convertToError.ts
89
- function convertToError(error) {
90
- if (error instanceof Error) return error;
91
- if (typeof error === "string") return new Error(error);
92
- if (typeof error === "object" && error !== null) {
93
- const obj = error;
94
- const message = typeof obj.message === "string" ? obj.message : String(error);
95
- const converted = new Error(message);
96
- if (typeof obj.stack === "string") converted.stack = obj.stack;
97
- if (typeof obj.name === "string") converted.name = obj.name;
98
- return converted;
99
- }
100
- return new Error(String(error));
101
- }
102
-
103
- //#endregion
104
- //#region src/util/assertKey.ts
105
- function assertKey(key, debug) {
106
- 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);
107
- }
108
-
109
- //#endregion
110
- //#region src/util/extractCode.ts
111
- const MAX_CODE_LENGTH = 64;
112
- function extractCode(error) {
113
- const code = error.code;
114
- if (typeof code !== "string" || code.length === 0) return;
115
- return code.slice(0, MAX_CODE_LENGTH);
116
- }
117
-
118
- //#endregion
119
- //#region src/util/flatJsonStringify.ts
120
- function flatJsonStringify(json) {
121
- return JSON.stringify(decycle(json));
122
- }
123
- function isPlainObject(value) {
124
- if (typeof value !== "object" || value === null) return false;
125
- const proto = Object.getPrototypeOf(value);
126
- return proto === Object.prototype || proto === null;
127
- }
128
- function decycle(root) {
129
- const inPath = /* @__PURE__ */ new WeakSet();
130
- function clone(node) {
131
- if (Array.isArray(node)) {
132
- if (inPath.has(node)) return "[Circular]";
133
- inPath.add(node);
134
- const result = node.map(clone);
135
- inPath.delete(node);
136
- return result;
137
- }
138
- if (isPlainObject(node)) {
139
- if (inPath.has(node)) return "[Circular]";
140
- inPath.add(node);
141
- const result = {};
142
- for (const [k, v] of Object.entries(node)) result[k] = clone(v);
143
- inPath.delete(node);
144
- return result;
145
- }
146
- return node;
147
- }
148
- return clone(root);
149
- }
150
-
151
- //#endregion
152
- //#region src/util/glowsToEvents.ts
153
- function glowsToEvents(glows) {
154
- return glows.map((glow) => ({
155
- type: "php_glow",
156
- startTimeUnixNano: Math.round(glow.microtime * 1e9),
157
- endTimeUnixNano: null,
158
- attributes: {
159
- "glow.name": String(glow.name),
160
- "glow.level": glow.messageLevel,
161
- "glow.context": glow.metaData ?? {}
162
- }
163
- }));
164
- }
165
-
166
- //#endregion
167
- //#region src/util/now.ts
168
- function now() {
169
- return Math.round(Date.now() / 1e3);
170
- }
171
-
172
- //#endregion
173
- //#region src/util/redactUrl.ts
174
- 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;
175
- function resolveDenylist(custom, replaceDefault = false, defaultDenylist = DEFAULT_URL_DENYLIST) {
176
- if (!custom) return defaultDenylist;
177
- if (replaceDefault) {
178
- const safeFlags = custom.flags.replace(/[gy]/g, "");
179
- return new RegExp(custom.source, safeFlags);
180
- }
181
- const flags = unionFlags(defaultDenylist.flags, custom.flags);
182
- return new RegExp(`(?:${defaultDenylist.source})|(?:${custom.source})`, flags);
183
- }
184
- function unionFlags(a, b) {
185
- const merged = /* @__PURE__ */ new Set();
186
- for (const flag of a + b) {
187
- if (flag === "g" || flag === "y") continue;
188
- merged.add(flag);
189
- }
190
- return [...merged].join("");
191
- }
192
- function redactFullPath(fullPath, denylist = DEFAULT_URL_DENYLIST) {
193
- const queryStart = fullPath.indexOf("?");
194
- if (queryStart === -1) return fullPath;
195
- const hashStart = fullPath.indexOf("#", queryStart);
196
- const queryEnd = hashStart === -1 ? fullPath.length : hashStart;
197
- const prefix = fullPath.slice(0, queryStart + 1);
198
- const queryString = fullPath.slice(queryStart + 1, queryEnd);
199
- const suffix = fullPath.slice(queryEnd);
200
- return `${prefix}${queryString.split("&").map((pair) => {
201
- if (pair === "") return pair;
202
- const eq = pair.indexOf("=");
203
- const rawKey = eq === -1 ? pair : pair.slice(0, eq);
204
- const decodedKey = safeDecode(rawKey);
205
- if (!denylist.test(decodedKey)) return pair;
206
- return eq === -1 ? rawKey : `${rawKey}=[redacted]`;
207
- }).join("&")}${suffix}`;
208
- }
209
- function safeDecode(value) {
210
- try {
211
- return decodeURIComponent(value);
212
- } catch {
213
- return value;
214
- }
215
- }
216
-
217
- //#endregion
218
- //#region src/api/Api.ts
219
- var Api = class {
220
- report(report, url, key, reportBrowserExtensionErrors, debug = false) {
221
- return fetch(url, {
222
- method: "POST",
223
- headers: {
224
- "Accept": "application/json",
225
- "Content-Type": "application/json",
226
- "X-Api-Token": key ?? "",
227
- "X-Report-Browser-Extension-Errors": JSON.stringify(reportBrowserExtensionErrors),
228
- "X-Flare-Client-Version": "2"
229
- },
230
- body: flatJsonStringify(report)
231
- }).then((response) => {
232
- if (debug && response.status !== 201) console.error(`Received response with status ${response.status} from Flare`);
233
- }, (error) => {
234
- if (debug) console.error(error);
235
- });
236
- }
237
- };
238
-
239
- //#endregion
240
- //#region src/context/cookie.ts
47
+ //#region src/browser/context/cookie.ts
241
48
  function cookie() {
242
49
  if (!window.document.cookie) return {};
243
50
  const cookies = {};
@@ -254,361 +61,92 @@ function cookie() {
254
61
  }
255
62
 
256
63
  //#endregion
257
- //#region src/context/request.ts
64
+ //#region src/browser/context/request.ts
258
65
  function request(urlDenylist) {
259
66
  return {
260
- "url.full": redactFullPath(window.location.href, urlDenylist),
67
+ "url.full": (0, _flareapp_core.redactUrlQuery)(window.location.href, urlDenylist),
261
68
  "user_agent.original": window.navigator.userAgent,
262
- "http.request.referrer": redactFullPath(window.document.referrer, urlDenylist),
69
+ "http.request.referrer": (0, _flareapp_core.redactUrlQuery)(window.document.referrer, urlDenylist),
263
70
  "document.ready_state": window.document.readyState
264
71
  };
265
72
  }
266
73
 
267
74
  //#endregion
268
- //#region src/context/requestData.ts
75
+ //#region src/browser/context/requestData.ts
269
76
  function requestData(urlDenylist) {
270
77
  if (!window.location.search) return {};
271
- return { "url.query": redactFullPath(window.location.search, urlDenylist).replace(/^\?/, "") };
78
+ return { "url.query": (0, _flareapp_core.redactUrlQuery)(window.location.search, urlDenylist).replace(/^\?/, "") };
272
79
  }
273
80
 
274
81
  //#endregion
275
- //#region src/context/collectAttributes.ts
276
- function collectAttributes(urlDenylist) {
277
- if (typeof window === "undefined") return {};
278
- return {
279
- ...request(urlDenylist),
280
- ...requestData(urlDenylist),
281
- ...cookie()
282
- };
283
- }
82
+ //#region src/browser/context/collectBrowser.ts
83
+ const collectBrowser = (config) => {
84
+ if (typeof window === "undefined") return { "flare.entry_point.type": "server" };
85
+ const attrs = { "flare.entry_point.type": "web" };
86
+ if (window?.location?.href) {
87
+ attrs["flare.entry_point.value"] = (0, _flareapp_core.redactUrlQuery)(window.location.href, config.urlDenylist);
88
+ if (window.location.pathname) {
89
+ attrs["flare.entry_point.handler.identifier"] = window.location.pathname;
90
+ attrs["flare.entry_point.handler.type"] = "browser";
91
+ }
92
+ }
93
+ Object.assign(attrs, request(config.urlDenylist));
94
+ Object.assign(attrs, requestData(config.urlDenylist));
95
+ Object.assign(attrs, cookie());
96
+ return attrs;
97
+ };
284
98
 
285
99
  //#endregion
286
- //#region src/stacktrace/fileReader.ts
287
- const cachedFiles = {};
288
- function getCodeSnippet(url, lineNumber, columnNumber) {
289
- return new Promise((resolve) => {
290
- if (!url || !lineNumber) return resolve({
291
- codeSnippet: { 0: `Could not read from file: missing file URL or line number. URL: ${url} lineNumber: ${lineNumber}` },
292
- trimmedColumnNumber: null
293
- });
294
- if (!isFetchableUrl(url)) return resolve({
295
- codeSnippet: { 0: `Could not read from file: unsupported URL scheme. URL: ${url}` },
296
- trimmedColumnNumber: null
297
- });
298
- readFile(url).then((fileText) => {
299
- if (!fileText) return resolve({
300
- codeSnippet: { 0: `Could not read from file: Error while opening file at URL ${url}` },
301
- trimmedColumnNumber: null
302
- });
303
- return resolve(readLinesFromFile(fileText, lineNumber, columnNumber));
304
- });
305
- });
306
- }
307
- function isFetchableUrl(url) {
308
- return /^https?:\/\//i.test(url);
309
- }
310
- function readFile(url) {
311
- if (cachedFiles[url] !== void 0) return Promise.resolve(cachedFiles[url]);
312
- return fetch(url).then((response) => {
313
- if (response.status !== 200) return null;
314
- return response.text();
315
- }).then((text) => {
316
- if (text !== null) cachedFiles[url] = text;
317
- return text;
318
- }).catch(() => null);
319
- }
320
- function readLinesFromFile(fileText, lineNumber, columnNumber, maxSnippetLineLength = 1e3, maxSnippetLines = 40) {
321
- const codeSnippet = {};
322
- let trimmedColumnNumber = null;
323
- const lines = fileText.split("\n");
324
- const errorLineIndex = lineNumber - 1;
325
- const half = Math.floor(maxSnippetLines / 2);
326
- for (let i = -half; i <= half; i++) {
327
- const currentLineIndex = errorLineIndex + i;
328
- if (currentLineIndex < 0 || !lines[currentLineIndex]) continue;
329
- const displayLine = currentLineIndex + 1;
330
- const line = lines[currentLineIndex];
331
- if (line.length > maxSnippetLineLength) {
332
- if (columnNumber && columnNumber > maxSnippetLineLength / 2) {
333
- const start = columnNumber - Math.round(maxSnippetLineLength / 2);
334
- codeSnippet[displayLine] = line.slice(start, start + maxSnippetLineLength);
335
- if (displayLine === lineNumber) trimmedColumnNumber = Math.round(maxSnippetLineLength / 2);
336
- continue;
337
- }
338
- codeSnippet[displayLine] = line.slice(0, maxSnippetLineLength) + "…";
339
- continue;
340
- }
341
- codeSnippet[displayLine] = line;
100
+ //#region src/browser/FetchFileReader.ts
101
+ /**
102
+ * Browser `FileReader` implementation that fetches source files over HTTP(S).
103
+ *
104
+ * Wired into `@flareapp/js`'s singleton so the stack-trace builder can pull
105
+ * the original source for each frame and render a code snippet around the
106
+ * offending line. The source URL comes from the frame (usually the URL of
107
+ * the JS bundle that produced the error, post-sourcemap resolution).
108
+ *
109
+ * Three safety gates:
110
+ *
111
+ * 1. **Scheme allowlist.** Only `http:` and `https:` URLs are fetched. Other
112
+ * schemes (`chrome-extension://`, `file://`, `blob:`, `data:`) return
113
+ * `null` immediately. This avoids surprise privilege boundaries (e.g.,
114
+ * pages should not read extension-internal files) and dodges CORS/CSP
115
+ * walls that would error noisily.
116
+ * 2. **Status check.** Only `200 OK` responses are used. 3xx redirects are
117
+ * handled transparently by `fetch`; 4xx/5xx fall back to `null` so the
118
+ * snippet is simply omitted from the report.
119
+ * 3. **Catch-all.** Network failures, CORS errors, and aborted requests
120
+ * return `null`. We never let a source-fetch failure leak as an error
121
+ * that the consumer page would see.
122
+ *
123
+ * The `read()` contract returns `null` on any failure path, never throws.
124
+ */
125
+ var FetchFileReader = class {
126
+ read(url) {
127
+ if (!/^https?:\/\//i.test(url)) return Promise.resolve(null);
128
+ return fetch(url).then((response) => {
129
+ if (response.status !== 200) return null;
130
+ return response.text();
131
+ }).catch(() => null);
342
132
  }
343
- return {
344
- codeSnippet,
345
- trimmedColumnNumber
346
- };
347
- }
133
+ };
348
134
 
349
135
  //#endregion
350
- //#region src/stacktrace/createStackTrace.ts
351
- function createStackTrace(error, debug) {
352
- return new Promise((resolve) => {
353
- if (!hasStack(error)) return resolve([fallbackFrame("stacktrace missing")]);
354
- let parsedFrames;
355
- try {
356
- parsedFrames = error_stack_parser.default.parse(error);
357
- } catch (parseError) {
358
- assert(false, "Couldn't parse stacktrace of below error:", debug);
359
- if (debug) {
360
- console.error(parseError);
361
- console.error(error);
362
- }
363
- return resolve([fallbackFrame("stacktrace could not be parsed")]);
364
- }
365
- Promise.all(parsedFrames.map((frame) => {
366
- return getCodeSnippet(frame.fileName, frame.lineNumber, frame.columnNumber).then((snippet) => ({
367
- lineNumber: frame.lineNumber || 1,
368
- columnNumber: frame.columnNumber || 1,
369
- method: frame.functionName || "Anonymous or unknown function",
370
- file: frame.fileName || "Unknown file",
371
- codeSnippet: snippet.codeSnippet,
372
- class: "",
373
- isApplicationFrame: isApplicationFrame(frame.fileName)
374
- }));
375
- })).then(resolve);
376
- });
377
- }
378
- function fallbackFrame(reason) {
379
- return {
380
- lineNumber: 0,
381
- columnNumber: 0,
382
- method: "unknown",
383
- file: "unknown",
384
- codeSnippet: { 0: `Could not read from file: ${reason}` },
385
- class: "unknown"
386
- };
387
- }
388
- function hasStack(err) {
389
- if (!err || typeof err !== "object") return false;
390
- const e = err;
391
- const stack = e.stack ?? e.stacktrace ?? e["opera#sourceloc"];
392
- return typeof stack === "string" && stack !== `${e.name}: ${e.message}`;
393
- }
394
- function isApplicationFrame(fileName) {
395
- if (!fileName) return true;
396
- if (/[/\\]node_modules[/\\]/.test(fileName)) return false;
397
- if (/(^|[/\\])(vendor|vendors)[.~-][^/\\]*\.js/i.test(fileName)) return false;
398
- return true;
399
- }
136
+ //#region src/env/index.ts
137
+ const CLIENT_VERSION = typeof process !== "undefined" && true ? "2.2.0" : "?";
400
138
 
401
139
  //#endregion
402
- //#region src/Flare.ts
403
- const DEFAULT_SDK_NAME = "@flareapp/js";
404
- var Flare = class {
405
- _config = {
406
- key: null,
407
- version: "",
408
- sourcemapVersionId: SOURCEMAP_VERSION,
409
- stage: "",
410
- maxGlowsPerReport: 30,
411
- ingestUrl: "https://ingress.flareapp.io/v1/errors",
412
- reportBrowserExtensionErrors: false,
413
- debug: false,
414
- urlDenylist: DEFAULT_URL_DENYLIST,
415
- replaceDefaultUrlDenylist: false,
416
- sampleRate: 1,
417
- beforeEvaluate: (error) => error,
418
- beforeSubmit: (report) => report
419
- };
420
- _glows = [];
421
- pendingAttributes = {};
422
- entryPoint = null;
423
- sdkInfo = {
424
- name: DEFAULT_SDK_NAME,
425
- version: CLIENT_VERSION
426
- };
427
- framework = null;
428
- constructor(api = new Api()) {
429
- this.api = api;
430
- }
431
- get config() {
432
- return this._config;
433
- }
434
- get glows() {
435
- return this._glows;
436
- }
437
- light(key = KEY, debug) {
438
- this._config.key = key;
439
- if (debug !== void 0) this._config.debug = debug;
440
- return this;
441
- }
442
- configure(config) {
443
- this._config = {
444
- ...this._config,
445
- ...config
446
- };
447
- if (config.sampleRate !== void 0) this._config.sampleRate = Math.max(0, Math.min(1, config.sampleRate));
448
- this._config.urlDenylist = resolveDenylist(config.urlDenylist, config.replaceDefaultUrlDenylist ?? this._config.replaceDefaultUrlDenylist);
449
- return this;
450
- }
451
- async test() {
452
- const report = await this.createReportFromError(/* @__PURE__ */ new Error("The Flare client is set up correctly!"));
453
- if (!report) return;
454
- return this.sendReport(report);
455
- }
456
- glow(name, level = "info", data = []) {
457
- const time = now();
458
- this._glows.push({
459
- name,
460
- messageLevel: level,
461
- metaData: data,
462
- time,
463
- microtime: time
464
- });
465
- if (this._glows.length > this._config.maxGlowsPerReport) this._glows = this._glows.slice(this._glows.length - this._config.maxGlowsPerReport);
466
- return this;
467
- }
468
- clearGlows() {
469
- this._glows = [];
470
- return this;
471
- }
472
- addContext(name, value) {
473
- const existing = this.pendingAttributes["context.custom"] ?? {};
474
- this.pendingAttributes["context.custom"] = {
475
- ...existing,
476
- [name]: value
477
- };
478
- return this;
479
- }
480
- addContextGroup(groupName, value) {
481
- this.pendingAttributes[`context.${groupName}`] = value;
482
- return this;
483
- }
484
- setEntryPoint(handler) {
485
- this.entryPoint = handler;
486
- return this;
487
- }
488
- setSdkInfo(info) {
489
- this.sdkInfo = info;
490
- return this;
491
- }
492
- setFramework(framework) {
493
- this.framework = framework;
494
- this.addContext("framework", framework.name.toLowerCase());
495
- return this;
496
- }
497
- async report(error, attributes = {}) {
498
- if (this._config.sampleRate < 1 && Math.random() >= this._config.sampleRate) return;
499
- const seenAtUnixNano = Date.now() * 1e6;
500
- const coerced = error instanceof Error ? error : new Error(typeof error === "string" ? error : String(error));
501
- const errorToReport = await this._config.beforeEvaluate(coerced);
502
- if (!errorToReport) return;
503
- const report = await this.createReportFromError(errorToReport, attributes, seenAtUnixNano);
504
- if (!report) return;
505
- return this.sendReport(report);
506
- }
507
- reportSilently(error, attributes = {}) {
508
- Promise.resolve(this.report(error, attributes)).catch(() => {});
509
- }
510
- async reportUnhandledRejection(message, attributes = {}) {
511
- if (Math.random() >= this._config.sampleRate) return;
512
- const seenAtUnixNano = Date.now() * 1e6;
513
- const report = this.buildReport({
514
- exceptionClass: "UnhandledRejection",
515
- message,
516
- stacktrace: [],
517
- isLog: false,
518
- level: void 0,
519
- extraAttributes: attributes,
520
- code: void 0,
521
- seenAtUnixNano
522
- });
523
- return this.sendReport(report);
524
- }
525
- async reportMessage(message, level, attributes = {}) {
526
- if (this._config.sampleRate < 1 && Math.random() >= this._config.sampleRate) return;
527
- const seenAtUnixNano = Date.now() * 1e6;
528
- const stackTrace = await createStackTrace(/* @__PURE__ */ new Error(), this._config.debug);
529
- stackTrace.shift();
530
- const report = this.buildReport({
531
- exceptionClass: "Log",
532
- message,
533
- stacktrace: stackTrace,
534
- isLog: true,
535
- level,
536
- extraAttributes: attributes,
537
- code: void 0,
538
- seenAtUnixNano
539
- });
540
- return this.sendReport(report);
541
- }
542
- async createReportFromError(error, attributes = {}, seenAtUnixNano = Date.now() * 1e6) {
543
- if (!assert(error, "No error provided.", this._config.debug)) return false;
544
- const stacktrace = await createStackTrace(error, this._config.debug);
545
- assert(stacktrace.length, "Couldn't generate stacktrace of this error: " + error, this._config.debug);
546
- const exceptionClass = error.constructor && error.constructor.name ? error.constructor.name : "undefined";
547
- return this.buildReport({
548
- exceptionClass,
549
- message: error.message,
550
- stacktrace,
551
- isLog: false,
552
- level: void 0,
553
- extraAttributes: attributes,
554
- code: extractCode(error),
555
- seenAtUnixNano
140
+ //#region src/index.ts
141
+ var Flare = class extends _flareapp_core.Flare {
142
+ constructor(api = new _flareapp_core.Api(), contextCollector = collectBrowser, fileReader = new FetchFileReader(), scopeProvider = new _flareapp_core.GlobalScopeProvider()) {
143
+ super(api, contextCollector, fileReader, scopeProvider);
144
+ this.setSdkInfo({
145
+ name: "@flareapp/js",
146
+ version: CLIENT_VERSION
556
147
  });
557
148
  }
558
- buildReport(input) {
559
- const baseAttributes = {
560
- "telemetry.sdk.language": "javascript",
561
- "telemetry.sdk.name": this.sdkInfo.name,
562
- "telemetry.sdk.version": this.sdkInfo.version,
563
- "flare.language.name": "javascript",
564
- "flare.entry_point.type": "web"
565
- };
566
- if (typeof window !== "undefined" && window?.location?.href) baseAttributes["flare.entry_point.value"] = redactFullPath(window.location.href, this._config.urlDenylist);
567
- const handlerIdentifier = this.entryPoint?.identifier ?? (typeof window !== "undefined" && window?.location?.pathname ? window.location.pathname : void 0);
568
- const handlerType = this.entryPoint?.type ?? (typeof window !== "undefined" && window ? "browser" : void 0);
569
- if (handlerIdentifier !== void 0) baseAttributes["flare.entry_point.handler.identifier"] = handlerIdentifier;
570
- if (handlerType !== void 0) baseAttributes["flare.entry_point.handler.type"] = handlerType;
571
- if (this.entryPoint?.name !== void 0) baseAttributes["flare.entry_point.handler.name"] = this.entryPoint.name;
572
- if (this.framework?.name) baseAttributes["flare.framework.name"] = this.framework.name;
573
- if (this.framework?.version) baseAttributes["flare.framework.version"] = this.framework.version;
574
- if (this._config.stage) baseAttributes["service.stage"] = this._config.stage;
575
- if (this._config.version) baseAttributes["service.version"] = this._config.version;
576
- const attributes = {
577
- ...baseAttributes,
578
- ...collectAttributes(this._config.urlDenylist),
579
- ...this.pendingAttributes,
580
- ...input.extraAttributes
581
- };
582
- const pendingCustom = this.pendingAttributes["context.custom"];
583
- const extraCustom = input.extraAttributes["context.custom"];
584
- if (pendingCustom && extraCustom && typeof pendingCustom === "object" && typeof extraCustom === "object" && !Array.isArray(pendingCustom) && !Array.isArray(extraCustom)) attributes["context.custom"] = {
585
- ...pendingCustom,
586
- ...extraCustom
587
- };
588
- const report = {
589
- exceptionClass: input.exceptionClass,
590
- message: input.message,
591
- seenAtUnixNano: input.seenAtUnixNano,
592
- stacktrace: input.stacktrace,
593
- events: glowsToEvents(this._glows),
594
- attributes
595
- };
596
- if (input.isLog) report.isLog = true;
597
- if (input.level !== void 0) report.level = input.level;
598
- if (this._config.sourcemapVersionId) report.sourcemapVersionId = this._config.sourcemapVersionId;
599
- if (input.code !== void 0) report.code = input.code;
600
- return report;
601
- }
602
- async sendReport(report) {
603
- if (!assertKey(this._config.key, this._config.debug)) return;
604
- const reportToSubmit = await this._config.beforeSubmit(report);
605
- if (!reportToSubmit) return;
606
- return this.api.report(reportToSubmit, this._config.ingestUrl, this._config.key, this._config.reportBrowserExtensionErrors, this._config.debug);
607
- }
608
149
  };
609
-
610
- //#endregion
611
- //#region src/index.ts
612
150
  const flare = new Flare();
613
151
  if (typeof window !== "undefined" && window) {
614
152
  window.flare = flare;
@@ -616,9 +154,53 @@ if (typeof window !== "undefined" && window) {
616
154
  }
617
155
 
618
156
  //#endregion
619
- exports.DEFAULT_URL_DENYLIST = DEFAULT_URL_DENYLIST;
157
+ Object.defineProperty(exports, 'DEFAULT_URL_DENYLIST', {
158
+ enumerable: true,
159
+ get: function () {
160
+ return _flareapp_core.DEFAULT_URL_DENYLIST;
161
+ }
162
+ });
620
163
  exports.Flare = Flare;
621
- exports.convertToError = convertToError;
164
+ Object.defineProperty(exports, 'GlobalScopeProvider', {
165
+ enumerable: true,
166
+ get: function () {
167
+ return _flareapp_core.GlobalScopeProvider;
168
+ }
169
+ });
170
+ Object.defineProperty(exports, 'NullFileReader', {
171
+ enumerable: true,
172
+ get: function () {
173
+ return _flareapp_core.NullFileReader;
174
+ }
175
+ });
176
+ Object.defineProperty(exports, 'Scope', {
177
+ enumerable: true,
178
+ get: function () {
179
+ return _flareapp_core.Scope;
180
+ }
181
+ });
182
+ Object.defineProperty(exports, 'convertToError', {
183
+ enumerable: true,
184
+ get: function () {
185
+ return _flareapp_core.convertToError;
186
+ }
187
+ });
622
188
  exports.flare = flare;
623
- exports.redactFullPath = redactFullPath;
624
- exports.resolveDenylist = resolveDenylist;
189
+ Object.defineProperty(exports, 'redactFullPath', {
190
+ enumerable: true,
191
+ get: function () {
192
+ return _flareapp_core.redactUrlQuery;
193
+ }
194
+ });
195
+ Object.defineProperty(exports, 'redactUrlQuery', {
196
+ enumerable: true,
197
+ get: function () {
198
+ return _flareapp_core.redactUrlQuery;
199
+ }
200
+ });
201
+ Object.defineProperty(exports, 'resolveDenylist', {
202
+ enumerable: true,
203
+ get: function () {
204
+ return _flareapp_core.resolveDenylist;
205
+ }
206
+ });