@buoy-gg/events 7.0.9 → 7.0.11

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 (33) hide show
  1. package/lib/commonjs/components/EventsModal.js +86 -3
  2. package/lib/commonjs/components/EventsModal.js.map +1 -1
  3. package/lib/commonjs/components/UnifiedEventList.js +16 -1
  4. package/lib/commonjs/components/UnifiedEventList.js.map +1 -1
  5. package/lib/commonjs/hooks/useUnifiedEvents.js +22 -4
  6. package/lib/commonjs/hooks/useUnifiedEvents.js.map +1 -1
  7. package/lib/commonjs/sync/eventsSyncAdapter.js +99 -20
  8. package/lib/commonjs/sync/eventsSyncAdapter.js.map +1 -1
  9. package/lib/commonjs/utils/eventExportFormatter.js +65 -27
  10. package/lib/commonjs/utils/eventExportFormatter.js.map +1 -1
  11. package/lib/module/components/EventsModal.js +89 -6
  12. package/lib/module/components/EventsModal.js.map +1 -1
  13. package/lib/module/components/UnifiedEventList.js +16 -1
  14. package/lib/module/components/UnifiedEventList.js.map +1 -1
  15. package/lib/module/hooks/useUnifiedEvents.js +22 -4
  16. package/lib/module/hooks/useUnifiedEvents.js.map +1 -1
  17. package/lib/module/sync/eventsSyncAdapter.js +99 -20
  18. package/lib/module/sync/eventsSyncAdapter.js.map +1 -1
  19. package/lib/module/utils/eventExportFormatter.js +65 -27
  20. package/lib/module/utils/eventExportFormatter.js.map +1 -1
  21. package/lib/typescript/components/EventsModal.d.ts.map +1 -1
  22. package/lib/typescript/components/UnifiedEventList.d.ts +2 -0
  23. package/lib/typescript/components/UnifiedEventList.d.ts.map +1 -1
  24. package/lib/typescript/hooks/useUnifiedEvents.d.ts +3 -0
  25. package/lib/typescript/hooks/useUnifiedEvents.d.ts.map +1 -1
  26. package/lib/typescript/sync/eventsSyncAdapter.d.ts.map +1 -1
  27. package/lib/typescript/utils/eventExportFormatter.d.ts.map +1 -1
  28. package/package.json +3 -3
  29. package/src/components/EventsModal.tsx +119 -8
  30. package/src/components/UnifiedEventList.tsx +17 -0
  31. package/src/hooks/useUnifiedEvents.ts +27 -4
  32. package/src/sync/eventsSyncAdapter.ts +98 -18
  33. package/src/utils/eventExportFormatter.ts +60 -26
@@ -97,6 +97,19 @@ function isNetworkEventIgnored(
97
97
  return isUrlIgnored(url, ignoredPatterns);
98
98
  }
99
99
 
100
+ /**
101
+ * Match an event against the header search query. Searches the two fields the
102
+ * row actually renders (title/subtitle) plus a network event's full URL — the
103
+ * title only carries the path, so a query for the host or a query-string value
104
+ * would otherwise miss. `query` must already be lowercased and trimmed.
105
+ */
106
+ function matchesSearch(event: UnifiedEvent, query: string): boolean {
107
+ if (event.title.toLowerCase().includes(query)) return true;
108
+ if (event.subtitle.toLowerCase().includes(query)) return true;
109
+ const url = (event.originalEvent as { url?: unknown } | undefined)?.url;
110
+ return typeof url === "string" && url.toLowerCase().includes(query);
111
+ }
112
+
100
113
  /**
101
114
  * All possible sources for display
102
115
  */
@@ -144,6 +157,9 @@ export interface UseUnifiedEventsResult {
144
157
  filteredEvents: UnifiedEvent[];
145
158
  availableSources: SourceInfo[];
146
159
  enabledSources: Set<EventSource>;
160
+ /** Header search query (matches title, subtitle and network URL) */
161
+ searchText: string;
162
+ setSearchText: (text: string) => void;
147
163
  toggleSource: (source: EventSource) => void;
148
164
  enableAllSources: () => void;
149
165
  clearEvents: () => void;
@@ -174,6 +190,7 @@ export function useUnifiedEvents(): UseUnifiedEventsResult {
174
190
  () => new Set(DEFAULT_ENABLED_SOURCES)
175
191
  );
176
192
  const [isCapturing, setIsCapturing] = useState(true);
193
+ const [searchText, setSearchText] = useState("");
177
194
  const isStateRestoredRef = useRef(false);
178
195
 
179
196
  // Get discovered sources (which packages are installed).
@@ -321,8 +338,11 @@ export function useUnifiedEvents(): UseUnifiedEventsResult {
321
338
  return allowed;
322
339
  }, [enabledSources]);
323
340
 
324
- // Filter events by enabled sources, exclude Buoy internal events, and hide
325
- // network events matching the shared ignored-domain/URL patterns.
341
+ const normalizedSearch = searchText.trim().toLowerCase();
342
+
343
+ // Filter events by enabled sources and the header search, exclude Buoy
344
+ // internal events, and hide network events matching the shared
345
+ // ignored-domain/URL patterns.
326
346
  const allFilteredEvents = useMemo(() => {
327
347
  if (allowedEventSources.size === 0) {
328
348
  return [];
@@ -331,9 +351,10 @@ export function useUnifiedEvents(): UseUnifiedEventsResult {
331
351
  (event) =>
332
352
  allowedEventSources.has(event.source) &&
333
353
  !isBuoyInternalEvent(event) &&
334
- !isNetworkEventIgnored(event, ignoredPatterns)
354
+ !isNetworkEventIgnored(event, ignoredPatterns) &&
355
+ (normalizedSearch === "" || matchesSearch(event, normalizedSearch))
335
356
  );
336
- }, [events, allowedEventSources, ignoredPatterns]);
357
+ }, [events, allowedEventSources, ignoredPatterns, normalizedSearch]);
337
358
 
338
359
  // Apply free tier limit if not Pro
339
360
  const filteredEvents = useMemo(() => {
@@ -538,6 +559,8 @@ export function useUnifiedEvents(): UseUnifiedEventsResult {
538
559
  filteredEvents,
539
560
  availableSources,
540
561
  enabledSources,
562
+ searchText,
563
+ setSearchText,
541
564
  toggleSource,
542
565
  enableAllSources,
543
566
  clearEvents,
@@ -37,11 +37,80 @@ interface TruncatedOriginalEvent {
37
37
  note: string;
38
38
  }
39
39
 
40
+ /**
41
+ * Early-aborting size estimate. The previous guard measured with
42
+ * JSON.stringify(payload).length — an O(payload) cost to enforce a 16KB cap,
43
+ * which meant the protection itself blocked the JS thread for seconds (and
44
+ * could OOM) on enterprise-scale redux state trees. This walk accumulates
45
+ * approximate byte counts and bails as soon as the limit is exceeded, so the
46
+ * cost is O(limit) no matter how large the payload is. `cyclic` is reported
47
+ * because cyclic payloads must never reach the socket serializer.
48
+ */
49
+ function approxSizeOver(
50
+ value: unknown,
51
+ limit: number
52
+ ): { over: boolean; approxBytes: number; cyclic: boolean } {
53
+ let bytes = 0;
54
+ let cyclic = false;
55
+ const stack: unknown[] = [value];
56
+ const seen = new Set<object>();
57
+ while (stack.length > 0) {
58
+ if (bytes > limit) return { over: true, approxBytes: bytes, cyclic };
59
+ const v = stack.pop();
60
+ if (v === null || v === undefined) {
61
+ bytes += 4;
62
+ } else if (typeof v === "string") {
63
+ bytes += v.length + 2; // O(1): length read, no scan
64
+ } else if (typeof v === "number") {
65
+ bytes += 8;
66
+ } else if (typeof v === "boolean") {
67
+ bytes += 5;
68
+ } else if (typeof v === "object") {
69
+ if (seen.has(v as object)) {
70
+ cyclic = true;
71
+ continue;
72
+ }
73
+ seen.add(v as object);
74
+ if (Array.isArray(v)) {
75
+ bytes += 2 + v.length;
76
+ for (let i = 0; i < v.length; i++) stack.push(v[i]);
77
+ } else {
78
+ bytes += 2;
79
+ for (const k in v as Record<string, unknown>) {
80
+ bytes += k.length + 4;
81
+ stack.push((v as Record<string, unknown>)[k]);
82
+ }
83
+ }
84
+ } else {
85
+ bytes += 4; // function/symbol/bigint — JSON drops or errors; count nominally
86
+ }
87
+ }
88
+ return { over: bytes > limit, approxBytes: bytes, cyclic };
89
+ }
90
+
91
+ function truncatedMarker(approxBytes: number, note?: string): TruncatedOriginalEvent {
92
+ return {
93
+ __buoyTruncated: true,
94
+ approxBytes,
95
+ note:
96
+ note ??
97
+ `Payload (≥${(approxBytes / 1024).toFixed(0)}KB approx) exceeds the ${MAX_SYNC_ORIGINAL_EVENT_BYTES / 1024}KB sync limit and stayed on the device. Open the tool on-device (or use the source tool's detail action) for the full payload.`,
98
+ };
99
+ }
100
+
101
+ /** Marker replacing per-event redux state trees at the sync boundary. */
102
+ const STATE_TREE_OMITTED = {
103
+ __buoyOmitted: "state-tree",
104
+ note: "prevState/nextState stay on the device (use get_redux_state / the on-device tool).",
105
+ } as const;
106
+
40
107
  // Events are immutable once created, so compaction is computed once per event
41
108
  // object and drops out of the cache when the store evicts the event.
42
109
  const compactionCache = new WeakMap<object, unknown>();
43
110
 
44
- function compactEventForSync<T extends { originalEvent: unknown }>(event: T): T {
111
+ function compactEventForSync<T extends { source?: string; originalEvent: unknown }>(
112
+ event: T
113
+ ): T {
45
114
  const original = event.originalEvent;
46
115
  if (typeof original !== "object" || original === null) return event;
47
116
 
@@ -49,27 +118,38 @@ function compactEventForSync<T extends { originalEvent: unknown }>(event: T): T
49
118
  if (cached !== undefined) return cached as T;
50
119
 
51
120
  let result: T = event;
52
- try {
53
- const size = JSON.stringify(original)?.length ?? 0;
54
- if (size > MAX_SYNC_ORIGINAL_EVENT_BYTES) {
55
- const truncated: TruncatedOriginalEvent = {
56
- __buoyTruncated: true,
57
- approxBytes: size,
58
- note: `Payload (${(size / 1024).toFixed(0)}KB) exceeds the ${MAX_SYNC_ORIGINAL_EVENT_BYTES / 1024}KB sync limit and stayed on the device. Open the tool on-device (or use the source tool's detail action) for the full payload.`,
59
- };
60
- result = { ...event, originalEvent: truncated };
61
- }
62
- } catch {
63
- // Unserializable payloads would break the socket emit anyway — replace.
121
+
122
+ // Redux events carry the whole ReduxAction, whose prevState/nextState are
123
+ // FULL state trees — per event. Never ship (or even size-walk) those:
124
+ // drop them unconditionally before estimating, so the rest of the action
125
+ // (type/payload/meta/diff) still makes it onto the wire when it fits.
126
+ let candidate = original as Record<string, unknown>;
127
+ if (
128
+ event.source === "redux" &&
129
+ ("prevState" in candidate || "nextState" in candidate)
130
+ ) {
131
+ candidate = {
132
+ ...candidate,
133
+ prevState: STATE_TREE_OMITTED,
134
+ nextState: STATE_TREE_OMITTED,
135
+ };
136
+ result = { ...event, originalEvent: candidate };
137
+ }
138
+
139
+ const { over, approxBytes, cyclic } = approxSizeOver(
140
+ candidate,
141
+ MAX_SYNC_ORIGINAL_EVENT_BYTES
142
+ );
143
+ if (over) {
144
+ result = { ...event, originalEvent: truncatedMarker(approxBytes) };
145
+ } else if (cyclic) {
146
+ // Cyclic payloads would crash the socket serializer — never ship them.
64
147
  result = {
65
148
  ...event,
66
- originalEvent: {
67
- __buoyTruncated: true,
68
- approxBytes: -1,
69
- note: "Payload is not JSON-serializable and stayed on the device.",
70
- } satisfies TruncatedOriginalEvent,
149
+ originalEvent: truncatedMarker(-1, "Payload is not JSON-serializable (cyclic) and stayed on the device."),
71
150
  };
72
151
  }
152
+
73
153
  compactionCache.set(event as object, result);
74
154
  return result;
75
155
  }
@@ -682,6 +682,44 @@ function formatTimestamp(
682
682
  }
683
683
  }
684
684
 
685
+ /**
686
+ * Early-aborting JSON-size probe: approximate byte count, bailing as soon as
687
+ * `limit` is exceeded — O(limit), never O(payload). Measuring with
688
+ * JSON.stringify(data).length meant enforcing a 5KB cap could serialize a
689
+ * 190MB state tree first, blocking the JS thread for seconds per event.
690
+ */
691
+ function approxJsonBytesOver(
692
+ value: unknown,
693
+ limit: number
694
+ ): { over: boolean; approxBytes: number } {
695
+ let bytes = 0;
696
+ const stack: unknown[] = [value];
697
+ const seen = new Set<object>();
698
+ while (stack.length > 0) {
699
+ if (bytes > limit) return { over: true, approxBytes: bytes };
700
+ const v = stack.pop();
701
+ if (v === null || v === undefined) bytes += 4;
702
+ else if (typeof v === "string") bytes += v.length + 2;
703
+ else if (typeof v === "number") bytes += 8;
704
+ else if (typeof v === "boolean") bytes += 5;
705
+ else if (typeof v === "object") {
706
+ if (seen.has(v as object)) continue;
707
+ seen.add(v as object);
708
+ if (Array.isArray(v)) {
709
+ bytes += 2 + v.length;
710
+ for (let i = 0; i < v.length; i++) stack.push(v[i]);
711
+ } else {
712
+ bytes += 2;
713
+ for (const k in v as Record<string, unknown>) {
714
+ bytes += k.length + 4;
715
+ stack.push((v as Record<string, unknown>)[k]);
716
+ }
717
+ }
718
+ } else bytes += 4;
719
+ }
720
+ return { over: bytes > limit, approxBytes: bytes };
721
+ }
722
+
685
723
  /**
686
724
  * Truncate data based on size threshold
687
725
  */
@@ -693,18 +731,20 @@ function truncateData(
693
731
  return { data, truncated: false };
694
732
  }
695
733
 
696
- try {
697
- const json = JSON.stringify(data);
698
- const sizeKB = json.length / 1024;
699
-
700
- if (sizeKB <= thresholdKB) {
701
- return { data, truncated: false };
702
- }
703
-
734
+ // Cheap probe first — never serialize a payload just to learn it's huge.
735
+ const { over, approxBytes } = approxJsonBytesOver(data, thresholdKB * 1024);
736
+ if (over) {
704
737
  return {
705
- data: `[Data truncated - ${sizeKB.toFixed(1)}KB exceeds ${thresholdKB}KB limit]`,
738
+ data: `[Data truncated - ≥${(approxBytes / 1024).toFixed(1)}KB exceeds ${thresholdKB}KB limit]`,
706
739
  truncated: true,
707
740
  };
741
+ }
742
+
743
+ try {
744
+ // Under the cap: a real stringify is bounded by the threshold and also
745
+ // validates serializability (cycles etc.).
746
+ JSON.stringify(data);
747
+ return { data, truncated: false };
708
748
  } catch {
709
749
  return { data: "[Unable to serialize data]", truncated: true };
710
750
  }
@@ -729,18 +769,15 @@ export function estimateExportSize(
729
769
  if (settings.includeDuration) size += 15;
730
770
  size += 30; // Timestamp
731
771
 
732
- // Event data
772
+ // Event data — probe with an early-abort cap instead of fully
773
+ // serializing (an estimate never justifies an O(payload) stringify).
733
774
  if (settings.includeEventData && event.originalEvent) {
734
- try {
735
- const dataSize = JSON.stringify(event.originalEvent).length;
736
- if (settings.dataSizeThreshold === -1) {
737
- size += dataSize;
738
- } else {
739
- size += Math.min(dataSize, settings.dataSizeThreshold * 1024);
740
- }
741
- } catch {
742
- size += 50;
743
- }
775
+ const cap =
776
+ settings.dataSizeThreshold === -1
777
+ ? 1024 * 1024 // no threshold: cap the ESTIMATE at 1MB per event
778
+ : settings.dataSizeThreshold * 1024;
779
+ const { approxBytes } = approxJsonBytesOver(event.originalEvent, cap);
780
+ size += Math.min(approxBytes, cap);
744
781
  }
745
782
  }
746
783
 
@@ -1337,14 +1374,11 @@ function formatBytes(bytes: number): string {
1337
1374
  }
1338
1375
 
1339
1376
  /**
1340
- * Estimate size of data in bytes
1377
+ * Estimate size of data in bytes (early-abort probe, capped at 1MB — a size
1378
+ * label never justifies an O(payload) stringify).
1341
1379
  */
1342
1380
  function estimateDataSize(data: unknown): number {
1343
- try {
1344
- return JSON.stringify(data).length;
1345
- } catch {
1346
- return 0;
1347
- }
1381
+ return approxJsonBytesOver(data, 1024 * 1024).approxBytes;
1348
1382
  }
1349
1383
 
1350
1384
  /**