bugstack-sdk 2.2.1 → 2.3.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +139 -96
  2. package/README.md +496 -421
  3. package/bin/bugstack.cjs +6 -6
  4. package/dist/adapters/express/index.d.mts +2 -2
  5. package/dist/adapters/express/index.d.ts +2 -2
  6. package/dist/adapters/express/index.js +409 -43
  7. package/dist/adapters/express/index.js.map +1 -1
  8. package/dist/adapters/express/index.mjs +409 -43
  9. package/dist/adapters/express/index.mjs.map +1 -1
  10. package/dist/adapters/generic/index.d.mts +2 -2
  11. package/dist/adapters/generic/index.d.ts +2 -2
  12. package/dist/adapters/generic/index.js +457 -43
  13. package/dist/adapters/generic/index.js.map +1 -1
  14. package/dist/adapters/generic/index.mjs +454 -44
  15. package/dist/adapters/generic/index.mjs.map +1 -1
  16. package/dist/adapters/nextjs/index.d.mts +2 -2
  17. package/dist/adapters/nextjs/index.d.ts +2 -2
  18. package/dist/adapters/nextjs/index.js +409 -43
  19. package/dist/adapters/nextjs/index.js.map +1 -1
  20. package/dist/adapters/nextjs/index.mjs +409 -43
  21. package/dist/adapters/nextjs/index.mjs.map +1 -1
  22. package/dist/build/cli.js.map +1 -1
  23. package/dist/build/cli.mjs.map +1 -1
  24. package/dist/build/upload.js.map +1 -1
  25. package/dist/build/upload.mjs.map +1 -1
  26. package/dist/{client-DoqE7sNh.d.mts → client-B9WaTEYj.d.mts} +149 -2
  27. package/dist/{client-DoqE7sNh.d.ts → client-B9WaTEYj.d.ts} +149 -2
  28. package/dist/index.d.mts +2 -2
  29. package/dist/index.d.ts +2 -2
  30. package/dist/index.js +469 -55
  31. package/dist/index.js.map +1 -1
  32. package/dist/index.mjs +466 -56
  33. package/dist/index.mjs.map +1 -1
  34. package/dist/next-config/index.js.map +1 -1
  35. package/dist/next-config/index.mjs.map +1 -1
  36. package/package.json +107 -104
@@ -423,11 +423,442 @@ var RetryQueue = class {
423
423
  }
424
424
  };
425
425
 
426
+ // src/core/utils/stack-parser.ts
427
+ var V8_STACK_FRAME_REGEX = /^\s*at\s+(?:async\s+)?(?:(.+?)\s+\()?(?:(.+?):(\d+):(\d+))\)?$/;
428
+ function isNodeModule(filePath) {
429
+ return filePath.includes("node_modules");
430
+ }
431
+ function isInternalCode(filePath) {
432
+ return filePath.startsWith("node:") || filePath.startsWith("internal/") || // A bare name ("native", "<anonymous>") has no directory. A Windows
433
+ // path has backslashes and is app code.
434
+ !filePath.includes("/") && !filePath.includes("\\");
435
+ }
436
+ function cleanFunctionName(name) {
437
+ if (!name) return void 0;
438
+ return name.replace(/^Object\./, "").replace(/^Module\./, "").replace(/^__webpack_require__\./, "").replace(/^webpack_require\./, "").trim();
439
+ }
440
+ function parseStackTrace(stack) {
441
+ if (!stack) return [];
442
+ const lines = stack.split("\n");
443
+ const frames = [];
444
+ for (const line of lines) {
445
+ const match = V8_STACK_FRAME_REGEX.exec(line);
446
+ if (match) {
447
+ const [, functionName, file, lineStr, columnStr] = match;
448
+ const frame = {
449
+ function: cleanFunctionName(functionName),
450
+ file: file ?? void 0,
451
+ line: lineStr ? parseInt(lineStr, 10) : void 0,
452
+ column: columnStr ? parseInt(columnStr, 10) : void 0
453
+ };
454
+ if (frame.file) {
455
+ frame.isNodeModule = isNodeModule(frame.file);
456
+ frame.isInternal = isInternalCode(frame.file);
457
+ }
458
+ frames.push(frame);
459
+ }
460
+ }
461
+ return frames;
462
+ }
463
+ function getFirstAppFrame(frames) {
464
+ return frames.find((frame) => !frame.isNodeModule && !frame.isInternal);
465
+ }
466
+
426
467
  // src/core/sdk-version.ts
427
- var SDK_VERSION = "2.2.1" ;
468
+ var SDK_VERSION = "2.3.0" ;
469
+
470
+ // src/core/logged-errors.ts
471
+ var DEFAULT_MAX_PER_MINUTE = 20;
472
+ var DEFAULT_REPEAT_WINDOW_MS = 5 * 6e4;
473
+ var MAX_REMEMBERED = 500;
474
+ var MESSAGE_MAX = 300;
475
+ var ANCHORED_MESSAGE_MAX = 500;
476
+ var CAUSE_STACK_MAX = 2e3;
477
+ function resolveLoggedErrorOptions(value) {
478
+ const opts = typeof value === "object" && value !== null ? value : {};
479
+ return {
480
+ console: value !== false,
481
+ messages: opts.messages ?? false,
482
+ maxPerMinute: opts.maxPerMinute ?? DEFAULT_MAX_PER_MINUTE,
483
+ repeatWindowMs: opts.repeatWindowMs ?? DEFAULT_REPEAT_WINDOW_MS,
484
+ ignore: opts.ignore ?? []
485
+ };
486
+ }
487
+ var SHARED_KEY = /* @__PURE__ */ Symbol.for("bugstack-sdk.logged-errors");
488
+ function emptyStats() {
489
+ return {
490
+ forwarded: 0,
491
+ messageOnly: 0,
492
+ dropped: {
493
+ no_error_argument: 0,
494
+ sdk_line: 0,
495
+ node_warning: 0,
496
+ ignored: 0,
497
+ already_reported: 0,
498
+ repeat: 0,
499
+ rate_limited: 0,
500
+ no_client: 0
501
+ }
502
+ };
503
+ }
504
+ function shared() {
505
+ const g = globalThis;
506
+ let s = g[SHARED_KEY];
507
+ if (!s) {
508
+ s = {
509
+ reported: /* @__PURE__ */ new WeakSet(),
510
+ sink: null,
511
+ consoleOriginal: null,
512
+ consoleWrapper: null,
513
+ busy: false,
514
+ windowStart: 0,
515
+ inWindow: 0,
516
+ lastSent: /* @__PURE__ */ new Map(),
517
+ stats: emptyStats(),
518
+ now: Date.now
519
+ };
520
+ g[SHARED_KEY] = s;
521
+ }
522
+ return s;
523
+ }
524
+ var defer = typeof setImmediate === "function" ? (fn) => void setImmediate(fn) : (fn) => void setTimeout(fn, 0);
525
+ function markErrorReported(error) {
526
+ try {
527
+ if (error !== null && typeof error === "object") shared().reported.add(error);
528
+ } catch {
529
+ }
530
+ }
531
+ function loggedErrorStats() {
532
+ const s = shared();
533
+ return {
534
+ consoleInstalled: s.consoleWrapper !== null && s.sink !== null && s.sink.options.console,
535
+ forwarded: s.stats.forwarded,
536
+ messageOnly: s.stats.messageOnly,
537
+ dropped: { ...s.stats.dropped }
538
+ };
539
+ }
540
+ function isError(value) {
541
+ if (value instanceof Error) return true;
542
+ if (value === null || typeof value !== "object") return false;
543
+ try {
544
+ const v = value;
545
+ return typeof v.message === "string" && typeof v.stack === "string";
546
+ } catch {
547
+ return false;
548
+ }
549
+ }
550
+ function findError(args) {
551
+ for (const a of args) if (isError(a)) return a;
552
+ for (const a of args) {
553
+ if (a === null || typeof a !== "object" || Array.isArray(a)) continue;
554
+ try {
555
+ const o = a;
556
+ for (const k of ["err", "error", "cause"]) if (isError(o[k])) return o[k];
557
+ } catch {
558
+ }
559
+ }
560
+ return void 0;
561
+ }
562
+ var STACK_TEXT = /(^|\n)\s*([A-Za-z_$][\w$.]*(?:Error|Exception)\b[^\n]*)\n\s+at \S/;
563
+ function findStackText(args) {
564
+ for (const a of args) {
565
+ if (typeof a !== "string") continue;
566
+ const m = STACK_TEXT.exec(a);
567
+ if (!m) continue;
568
+ const header = m[2].trim();
569
+ const colon = header.indexOf(":");
570
+ const err = new Error(colon > 0 ? header.slice(colon + 1).trim() : header);
571
+ err.name = colon > 0 ? header.slice(0, colon).trim() : "Error";
572
+ err.stack = a.slice(m.index + m[1].length).trim();
573
+ return err;
574
+ }
575
+ return void 0;
576
+ }
577
+ function messageOfArgs(args) {
578
+ const parts = [];
579
+ for (const a of args) {
580
+ if (typeof a === "string") parts.push(a);
581
+ else if (typeof a === "number" || typeof a === "boolean") parts.push(String(a));
582
+ else if (a !== null && typeof a === "object" && !Array.isArray(a) && !isError(a)) {
583
+ try {
584
+ const o = a;
585
+ for (const k of ["error", "message", "reason", "err", "msg"]) {
586
+ if (typeof o[k] === "string" && o[k].length > 0) {
587
+ parts.push(o[k]);
588
+ break;
589
+ }
590
+ }
591
+ } catch {
592
+ }
593
+ }
594
+ }
595
+ return parts.join(" ").replace(/\s+/g, " ").trim().slice(0, MESSAGE_MAX);
596
+ }
597
+ function logRoute(label) {
598
+ const tag = label?.match(/^\s*\[([A-Za-z0-9_.:/-]{1,60})\]/)?.[1];
599
+ return tag ? `log:${tag}` : "log";
600
+ }
601
+ var SDK_LINE = /^\s*\[bugstack[^\]]*\]/i;
602
+ var NODE_WARNING_LINE = /^\s*\(node:\d+\)\s+(?:\[[A-Z0-9_]+\]\s+)?\w*Warning:/;
603
+ function escapeRegExp(s) {
604
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
605
+ }
606
+ function redactText(text, redactFields) {
607
+ let out = text.replace(/\b(Bearer|Basic)\s+[A-Za-z0-9._~+/=-]{8,}/gi, "$1 [REDACTED]");
608
+ if (redactFields.length > 0) {
609
+ const names = redactFields.filter((f) => f.length > 0).map(escapeRegExp).join("|");
610
+ if (names) {
611
+ const re = new RegExp(
612
+ `(["']?\\b\\w*(?:${names})\\w*["']?\\s*[=:]\\s*)("[^"]*"|'[^']*'|[^\\s,;&)}\\]]+)`,
613
+ "gi"
614
+ );
615
+ out = out.replace(re, "$1[REDACTED]");
616
+ }
617
+ }
618
+ return out;
619
+ }
620
+ function firstFrame(stack) {
621
+ return (stack ?? "").split("\n").find((l) => /^\s+at /.test(l))?.trim() ?? "";
622
+ }
623
+ function trimLibraryFrames(stack) {
624
+ const lines = stack.split("\n");
625
+ const header = [];
626
+ let i = 0;
627
+ while (i < lines.length && !/^\s+at /.test(lines[i])) header.push(lines[i++]);
628
+ let j = i;
629
+ while (j < lines.length && /node_modules|[/\\]bugstack-sdk[/\\]|\(node:internal|^\s+at node:internal/.test(lines[j])) j++;
630
+ if (j >= lines.length) return stack;
631
+ return [...header, ...lines.slice(j)].join("\n");
632
+ }
633
+ function siteOf(label, cause) {
634
+ if (label === void 0) return "";
635
+ const first = label.split("\n")[0].trim();
636
+ if (!first || first === cause.message || first === `${cause.name}: ${cause.message}`) return "";
637
+ return first.slice(0, 200);
638
+ }
639
+ function matchesIgnore(text, ignore) {
640
+ for (const p of ignore) {
641
+ try {
642
+ if (typeof p === "string" ? text.includes(p) : p.test(text)) return true;
643
+ } catch {
644
+ }
645
+ }
646
+ return false;
647
+ }
648
+ function captureLoggedCall(args, source, boundary) {
649
+ const s = shared();
650
+ if (s.busy) return;
651
+ try {
652
+ const sink = s.sink;
653
+ if (!sink) {
654
+ s.stats.dropped.no_client += 1;
655
+ return;
656
+ }
657
+ const label = args.find((a) => typeof a === "string");
658
+ if (label !== void 0 && SDK_LINE.test(label)) {
659
+ s.stats.dropped.sdk_line += 1;
660
+ return;
661
+ }
662
+ if (label !== void 0 && NODE_WARNING_LINE.test(label)) {
663
+ s.stats.dropped.node_warning += 1;
664
+ return;
665
+ }
666
+ const cause = findError(args) ?? findStackText(args) ?? null;
667
+ if (sink.options.ignore.length > 0 && matchesIgnore(`${messageOfArgs(args)} ${cause ? `${cause.name}: ${cause.message}` : ""}`, sink.options.ignore)) {
668
+ s.stats.dropped.ignored += 1;
669
+ return;
670
+ }
671
+ let message;
672
+ if (cause) {
673
+ message = `${siteOf(label, cause) || source}: ${cause.message}`;
674
+ } else {
675
+ message = sink.options.messages ? messageOfArgs(args) : "";
676
+ if (!message) {
677
+ s.stats.dropped.no_error_argument += 1;
678
+ return;
679
+ }
680
+ }
681
+ const anchored = new Error(redactText(message, sink.redactFields).slice(0, ANCHORED_MESSAGE_MAX));
682
+ anchored.name = "LoggedError";
683
+ const capture = Error.captureStackTrace;
684
+ if (capture) capture(anchored, boundary);
685
+ if (anchored.stack) anchored.stack = trimLibraryFrames(anchored.stack);
686
+ if (cause) anchored.cause = cause;
687
+ const pending = { anchored, cause, label, source, messageOnly: !cause };
688
+ defer(() => forward(pending));
689
+ } catch {
690
+ }
691
+ }
692
+ function forward(p) {
693
+ const s = shared();
694
+ const sink = s.sink;
695
+ if (!sink) {
696
+ s.stats.dropped.no_client += 1;
697
+ return;
698
+ }
699
+ try {
700
+ if (p.cause && s.reported.has(p.cause)) {
701
+ s.stats.dropped.already_reported += 1;
702
+ return;
703
+ }
704
+ const now = s.now();
705
+ const key = p.messageOnly ? `${firstFrame(p.anchored.stack)}|message-only` : `${firstFrame(p.anchored.stack)}|${p.anchored.message}`;
706
+ const last = s.lastSent.get(key);
707
+ if (last !== void 0 && now - last < sink.options.repeatWindowMs) {
708
+ s.stats.dropped.repeat += 1;
709
+ return;
710
+ }
711
+ if (now - s.windowStart >= 6e4) {
712
+ s.windowStart = now;
713
+ s.inWindow = 0;
714
+ }
715
+ if (s.inWindow >= sink.options.maxPerMinute) {
716
+ s.stats.dropped.rate_limited += 1;
717
+ return;
718
+ }
719
+ s.inWindow += 1;
720
+ s.lastSent.set(key, now);
721
+ if (s.lastSent.size > MAX_REMEMBERED) {
722
+ const oldest = s.lastSent.keys().next().value;
723
+ if (oldest !== void 0) s.lastSent.delete(oldest);
724
+ }
725
+ if (p.cause) s.reported.add(p.cause);
726
+ const captured = buildLoggedCapturedError(p, sink);
727
+ s.busy = true;
728
+ try {
729
+ const result = sink.report(captured);
730
+ if (result && typeof result.catch === "function") {
731
+ result.catch(() => {
732
+ });
733
+ }
734
+ s.stats.forwarded += 1;
735
+ if (p.messageOnly) s.stats.messageOnly += 1;
736
+ } finally {
737
+ s.busy = false;
738
+ }
739
+ } catch {
740
+ }
741
+ }
742
+ function nodeVersion() {
743
+ try {
744
+ return typeof process !== "undefined" && process.version ? process.version : "unknown";
745
+ } catch {
746
+ return "unknown";
747
+ }
748
+ }
749
+ function buildLoggedCapturedError(p, sink) {
750
+ const stackFrames = parseStackTrace(p.anchored.stack);
751
+ const firstAppFrame = getFirstAppFrame(stackFrames);
752
+ const route = logRoute(p.label);
753
+ const metadata = {
754
+ source: p.source,
755
+ handled: true,
756
+ ...firstAppFrame && {
757
+ sourceLocation: {
758
+ file: firstAppFrame.file,
759
+ line: firstAppFrame.line,
760
+ column: firstAppFrame.column,
761
+ function: firstAppFrame.function
762
+ }
763
+ }
764
+ };
765
+ if (p.cause) {
766
+ metadata.causeName = p.cause.name;
767
+ if (p.cause.stack) metadata.causeStack = redactText(p.cause.stack, sink.redactFields).slice(0, CAUSE_STACK_MAX);
768
+ } else {
769
+ metadata.messageOnly = true;
770
+ }
771
+ return {
772
+ id: `err_${Date.now().toString(36)}_${Math.random().toString(36).substring(2, 9)}`,
773
+ name: p.anchored.name,
774
+ message: p.anchored.message,
775
+ stack: p.anchored.stack,
776
+ stackFrames,
777
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
778
+ route,
779
+ method: "LOG",
780
+ statusCode: 500,
781
+ url: route,
782
+ environment: sink.environment,
783
+ projectId: sink.projectId,
784
+ sdkVersion: SDK_VERSION,
785
+ nodeVersion: nodeVersion(),
786
+ metadata
787
+ };
788
+ }
789
+ function attachLoggedErrorSink(sink) {
790
+ try {
791
+ const s = shared();
792
+ s.sink = sink;
793
+ if (sink.options.console) installConsoleWrapper(s);
794
+ } catch {
795
+ }
796
+ }
797
+ function detachLoggedErrorSink(sink) {
798
+ try {
799
+ const s = shared();
800
+ if (s.sink !== sink) return;
801
+ s.sink = null;
802
+ if (s.consoleWrapper && typeof console !== "undefined" && console.error === s.consoleWrapper && s.consoleOriginal) {
803
+ console.error = s.consoleOriginal;
804
+ s.consoleWrapper = null;
805
+ s.consoleOriginal = null;
806
+ }
807
+ } catch {
808
+ }
809
+ }
810
+ function installConsoleWrapper(s) {
811
+ if (typeof console === "undefined" || typeof console.error !== "function") return;
812
+ if (s.consoleWrapper && console.error === s.consoleWrapper) return;
813
+ const original = console.error;
814
+ const wrapper = function consoleErrorCapturedByBugstack(...args) {
815
+ original.apply(this === void 0 ? console : this, args);
816
+ const st = shared();
817
+ if (!st.sink || !st.sink.options.console) return;
818
+ captureLoggedCall(args, "console-error", wrapper);
819
+ };
820
+ s.consoleOriginal = original;
821
+ s.consoleWrapper = wrapper;
822
+ console.error = wrapper;
823
+ }
824
+ function bugstackPinoHooks() {
825
+ const logMethod = function bugstackPinoLogMethod(inputArgs, method, level) {
826
+ if (typeof level === "number" && level >= 50) {
827
+ captureLoggedCall(inputArgs, "pino", logMethod);
828
+ }
829
+ return method.apply(this, inputArgs);
830
+ };
831
+ return { logMethod };
832
+ }
833
+ var WINSTON_LEVEL = /* @__PURE__ */ Symbol.for("level");
834
+ var WINSTON_SPLAT = /* @__PURE__ */ Symbol.for("splat");
835
+ var WINSTON_ERROR_LEVELS = /* @__PURE__ */ new Set(["error", "crit", "alert", "emerg", "fatal"]);
836
+ function bugstackWinstonFormat() {
837
+ const transform = function bugstackWinstonTransform(info) {
838
+ try {
839
+ const level = info[WINSTON_LEVEL] ?? info.level;
840
+ if (typeof level === "string" && WINSTON_ERROR_LEVELS.has(level)) {
841
+ const splat = Array.isArray(info[WINSTON_SPLAT]) ? info[WINSTON_SPLAT] : [];
842
+ const args = [];
843
+ if (typeof info.message === "string") args.push(info.message);
844
+ if (typeof info.stack === "string" && typeof info.message === "string") {
845
+ const e = new Error(info.message);
846
+ e.name = typeof info.name === "string" ? info.name : "Error";
847
+ e.stack = info.stack;
848
+ args.push(e);
849
+ }
850
+ args.push(...splat, info);
851
+ captureLoggedCall(args, "winston", transform);
852
+ }
853
+ } catch {
854
+ }
855
+ return info;
856
+ };
857
+ return { transform };
858
+ }
428
859
 
429
860
  // src/core/client.ts
430
- var DEFAULT_ENDPOINT = "http://localhost:3001/api/capture";
861
+ var DEFAULT_ENDPOINT = "https://dashboard.bugstack.ai/api/ingest/sdk";
431
862
  var DEFAULT_TIMEOUT = 5e3;
432
863
  var DEFAULT_MAX_BODY_SIZE = 1e4;
433
864
  var DEFAULT_DEDUPLICATION_WINDOW = 5 * 60 * 1e3;
@@ -454,6 +885,7 @@ var ErrorCaptureClient = class _ErrorCaptureClient {
454
885
  static instance = null;
455
886
  deduplicator;
456
887
  retryQueue;
888
+ loggedErrorSink = null;
457
889
  constructor(config) {
458
890
  const isProduction = process.env.NODE_ENV === "production";
459
891
  this.config = {
@@ -480,7 +912,8 @@ var ErrorCaptureClient = class _ErrorCaptureClient {
480
912
  dropChunkErrors: config.dropChunkErrors ?? false,
481
913
  chunkErrorsEndpoint: config.chunkErrorsEndpoint ?? deriveChunkErrorsEndpoint(
482
914
  config.endpoint ?? process.env.BUGSTACK_ENDPOINT ?? DEFAULT_ENDPOINT
483
- )
915
+ ),
916
+ captureConsoleErrors: resolveLoggedErrorOptions(config.captureConsoleErrors)
484
917
  };
485
918
  this.deduplicator = new ErrorDeduplicator(this.config.deduplicationWindow);
486
919
  this.retryQueue = new RetryQueue(
@@ -492,12 +925,23 @@ var ErrorCaptureClient = class _ErrorCaptureClient {
492
925
  debug: this.config.debug
493
926
  }
494
927
  );
928
+ if (this.config.enabled) {
929
+ this.loggedErrorSink = {
930
+ options: this.config.captureConsoleErrors,
931
+ environment: this.config.environment,
932
+ projectId: this.config.projectId,
933
+ redactFields: this.config.redactFields,
934
+ report: (error) => this.reportError(error)
935
+ };
936
+ attachLoggedErrorSink(this.loggedErrorSink);
937
+ }
495
938
  this.log("BugStack client initialized", {
496
939
  endpoint: this.config.endpoint,
497
940
  projectId: this.config.projectId,
498
941
  environment: this.config.environment,
499
942
  autoFix: this.config.autoFix,
500
- deduplicationWindow: this.config.deduplicationWindow
943
+ deduplicationWindow: this.config.deduplicationWindow,
944
+ captureConsoleErrors: this.config.captureConsoleErrors.console
501
945
  });
502
946
  }
503
947
  /**
@@ -696,6 +1140,10 @@ var ErrorCaptureClient = class _ErrorCaptureClient {
696
1140
  * Should be called when shutting down to prevent memory leaks
697
1141
  */
698
1142
  destroy() {
1143
+ if (this.loggedErrorSink) {
1144
+ detachLoggedErrorSink(this.loggedErrorSink);
1145
+ this.loggedErrorSink = null;
1146
+ }
699
1147
  this.deduplicator.destroy();
700
1148
  this.retryQueue.destroy();
701
1149
  }
@@ -735,45 +1183,6 @@ function deriveChunkErrorsEndpoint(captureEndpoint) {
735
1183
  return captureEndpoint.replace(/\/?$/, "/chunk-errors");
736
1184
  }
737
1185
 
738
- // src/core/utils/stack-parser.ts
739
- var V8_STACK_FRAME_REGEX = /^\s*at\s+(?:async\s+)?(?:(.+?)\s+\()?(?:(.+?):(\d+):(\d+))\)?$/;
740
- function isNodeModule(filePath) {
741
- return filePath.includes("node_modules");
742
- }
743
- function isInternalCode(filePath) {
744
- return filePath.startsWith("node:") || filePath.startsWith("internal/") || !filePath.includes("/");
745
- }
746
- function cleanFunctionName(name) {
747
- if (!name) return void 0;
748
- return name.replace(/^Object\./, "").replace(/^Module\./, "").replace(/^__webpack_require__\./, "").replace(/^webpack_require\./, "").trim();
749
- }
750
- function parseStackTrace(stack) {
751
- if (!stack) return [];
752
- const lines = stack.split("\n");
753
- const frames = [];
754
- for (const line of lines) {
755
- const match = V8_STACK_FRAME_REGEX.exec(line);
756
- if (match) {
757
- const [, functionName, file, lineStr, columnStr] = match;
758
- const frame = {
759
- function: cleanFunctionName(functionName),
760
- file: file ?? void 0,
761
- line: lineStr ? parseInt(lineStr, 10) : void 0,
762
- column: columnStr ? parseInt(columnStr, 10) : void 0
763
- };
764
- if (frame.file) {
765
- frame.isNodeModule = isNodeModule(frame.file);
766
- frame.isInternal = isInternalCode(frame.file);
767
- }
768
- frames.push(frame);
769
- }
770
- }
771
- return frames;
772
- }
773
- function getFirstAppFrame(frames) {
774
- return frames.find((frame) => !frame.isNodeModule && !frame.isInternal);
775
- }
776
-
777
1186
  // src/adapters/generic/index.ts
778
1187
  function generateErrorId() {
779
1188
  const timestamp = Date.now().toString(36);
@@ -837,6 +1246,7 @@ async function captureError(error, metadata) {
837
1246
  );
838
1247
  return false;
839
1248
  }
1249
+ markErrorReported(error);
840
1250
  const err = error instanceof Error ? error : new Error(String(error));
841
1251
  const capturedError = buildCapturedError(err, client, metadata);
842
1252
  return client.reportError(capturedError);
@@ -884,11 +1294,15 @@ function createErrorCapture(baseMetadata) {
884
1294
 
885
1295
  exports.BugStackClient = BugStackClient;
886
1296
  exports.ErrorCaptureClient = ErrorCaptureClient;
1297
+ exports.bugstackPinoHooks = bugstackPinoHooks;
1298
+ exports.bugstackWinstonFormat = bugstackWinstonFormat;
887
1299
  exports.captureError = captureError;
888
1300
  exports.captureException = captureException;
889
1301
  exports.createErrorCapture = createErrorCapture;
890
1302
  exports.initBugStack = initBugStack;
891
1303
  exports.installGlobalHandlers = installGlobalHandlers;
1304
+ exports.loggedErrorStats = loggedErrorStats;
1305
+ exports.markErrorReported = markErrorReported;
892
1306
  exports.wrapFunction = wrapFunction;
893
1307
  //# sourceMappingURL=index.js.map
894
1308
  //# sourceMappingURL=index.js.map