@buoy-gg/events 7.0.29 → 7.0.30

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.
@@ -1,596 +0,0 @@
1
- /**
2
- * UnifiedEventDetail
3
- *
4
- * Detail view for a single unified event.
5
- * Uses shared detail components from other packages when available,
6
- * falls back to generic DataViewer when packages aren't installed.
7
- */
8
-
9
- import { View, Text, StyleSheet, ScrollView } from "react-native";
10
- import { memo, useMemo, type ComponentType, type ReactNode } from "react";
11
- import {
12
- night,
13
- formatRelativeTime,
14
- copyToClipboard,
15
- parseValue,
16
- useIgnoredPatterns,
17
- } from "@buoy-gg/shared-ui";
18
- import { DataViewer } from "@buoy-gg/shared-ui/dataViewer";
19
- import { ReactQueryEventDetail } from "./ReactQueryEventDetail";
20
- import type { UnifiedEvent, EventSource } from "../types";
21
- import type {
22
- StorageEvent,
23
- AsyncStorageEvent,
24
- ReduxAction,
25
- NetworkEvent,
26
- } from "../utils/eventTransformers";
27
-
28
- // ============================================================================
29
- // Optional Component Loading
30
- // ============================================================================
31
-
32
- export interface OptionalDetailComponents {
33
- StorageEventDetailContent: ComponentType<{
34
- conversation: unknown;
35
- selectedEventIndex: number;
36
- onEventIndexChange: (index: number) => void;
37
- disableInternalFooter?: boolean;
38
- }> | null;
39
- ReduxActionDetailContent: ComponentType<{
40
- action: unknown;
41
- actions: unknown[];
42
- selectedIndex: number;
43
- onIndexChange: (index: number) => void;
44
- disableInternalFooter?: boolean;
45
- }> | null;
46
- NetworkEventDetailView: ComponentType<{
47
- event: unknown;
48
- ignoredPatterns?: Set<string>;
49
- onTogglePattern?: (value: string) => void;
50
- }> | null;
51
- RenderDetailView: ComponentType<{
52
- render: unknown;
53
- }> | null;
54
- ZustandStateDetailContent: ComponentType<{
55
- change: unknown;
56
- changes: unknown[];
57
- selectedIndex: number;
58
- onIndexChange: (index: number) => void;
59
- disableInternalFooter?: boolean;
60
- }> | null;
61
- JotaiAtomDetailContent: ComponentType<{
62
- change: unknown;
63
- changes: unknown[];
64
- selectedIndex: number;
65
- onIndexChange: (index: number) => void;
66
- disableInternalFooter?: boolean;
67
- }> | null;
68
- RouteEventDetail: ComponentType<{
69
- event: unknown;
70
- visitNumber?: number;
71
- onNavigate?: (pathname: string) => void;
72
- }> | null;
73
- }
74
-
75
- function tryLoadOptionalDetailComponents(): OptionalDetailComponents {
76
- const components: OptionalDetailComponents = {
77
- StorageEventDetailContent: null,
78
- ReduxActionDetailContent: null,
79
- NetworkEventDetailView: null,
80
- RenderDetailView: null,
81
- ZustandStateDetailContent: null,
82
- JotaiAtomDetailContent: null,
83
- RouteEventDetail: null,
84
- };
85
-
86
- // Try to load storage detail component
87
- try {
88
- // @ts-ignore - Dynamic import that may not exist
89
- const storage = require("@buoy-gg/storage");
90
- components.StorageEventDetailContent = storage.StorageEventDetailContent;
91
- } catch {
92
- // Optional dependency not installed
93
- }
94
-
95
- // Try to load redux detail component
96
- try {
97
- // @ts-ignore - Dynamic import that may not exist
98
- const redux = require("@buoy-gg/redux");
99
- components.ReduxActionDetailContent = redux.ReduxActionDetailContent;
100
- } catch {
101
- // Optional dependency not installed
102
- }
103
-
104
- // Try to load network detail component
105
- try {
106
- // @ts-ignore - Dynamic import that may not exist
107
- const network = require("@buoy-gg/network");
108
- components.NetworkEventDetailView = network.NetworkEventDetailView;
109
- } catch {
110
- // Optional dependency not installed
111
- }
112
-
113
- // Try to load render detail component
114
- try {
115
- // @ts-ignore - Dynamic import that may not exist
116
- const highlightUpdates = require("@buoy-gg/highlight-updates");
117
- components.RenderDetailView = highlightUpdates.RenderDetailView;
118
- } catch {
119
- // Optional dependency not installed
120
- }
121
-
122
- // Try to load zustand detail component
123
- try {
124
- // @ts-ignore - Dynamic import that may not exist
125
- const zustand = require("@buoy-gg/zustand");
126
- components.ZustandStateDetailContent = zustand.ZustandStateDetailContent;
127
- } catch {
128
- // Optional dependency not installed
129
- }
130
-
131
- // Try to load jotai detail component
132
- try {
133
- // @ts-ignore - Dynamic import that may not exist
134
- const jotai = require("@buoy-gg/jotai");
135
- components.JotaiAtomDetailContent = jotai.JotaiAtomDetailContent;
136
- } catch {
137
- // Optional dependency not installed
138
- }
139
-
140
- // Try to load route detail component
141
- try {
142
- // @ts-ignore - Dynamic import that may not exist
143
- const routeEvents = require("@buoy-gg/route-events");
144
- components.RouteEventDetail = routeEvents.RouteEventDetail;
145
- } catch {
146
- // Optional dependency not installed
147
- }
148
-
149
- return components;
150
- }
151
-
152
- // Cache loaded components
153
- const optionalComponents = tryLoadOptionalDetailComponents();
154
-
155
- // ============================================================================
156
- // Configuration
157
- // ============================================================================
158
-
159
- /**
160
- * Source configuration for display
161
- */
162
- const SOURCE_CONFIG: Record<EventSource, { label: string; color: string }> = {
163
- "storage-async": { label: "AsyncStorage", color: "#8B5CF6" },
164
- "storage-mmkv": { label: "MMKV", color: "#F59E0B" },
165
- redux: { label: "Redux", color: "#3B82F6" },
166
- network: { label: "Network", color: "#10B981" },
167
- "react-query": { label: "React Query", color: "#EC4899" },
168
- "react-query-query": { label: "Query", color: "#EC4899" },
169
- "react-query-mutation": { label: "Mutation", color: "#F97316" },
170
- route: { label: "Route", color: "#06B6D4" },
171
- zustand: { label: "Zustand", color: "#764ABC" },
172
- jotai: { label: "Jotai", color: "#14B8A6" },
173
- render: { label: "Render", color: "#F472B6" },
174
- };
175
-
176
- /**
177
- * Check if an event is a storage event
178
- */
179
- function isStorageEvent(source: EventSource): boolean {
180
- return source === "storage-async" || source === "storage-mmkv";
181
- }
182
-
183
- /**
184
- * Get value type from a value
185
- */
186
- function getValueType(
187
- value: unknown
188
- ): "string" | "number" | "boolean" | "null" | "undefined" | "object" | "array" {
189
- const parsed = parseValue(value);
190
- if (parsed === null) return "null";
191
- if (parsed === undefined) return "undefined";
192
- if (Array.isArray(parsed)) return "array";
193
- if (typeof parsed === "boolean") return "boolean";
194
- if (typeof parsed === "number") return "number";
195
- if (typeof parsed === "string") return "string";
196
- if (typeof parsed === "object") return "object";
197
- return "undefined";
198
- }
199
-
200
- // ============================================================================
201
- // Component
202
- // ============================================================================
203
-
204
- /** Passthrough used when no network detail wrapper is injected. */
205
- function PassThrough({ children }: { children: ReactNode }) {
206
- return <>{children}</>;
207
- }
208
-
209
- interface UnifiedEventDetailProps {
210
- event: UnifiedEvent;
211
- onBack?: () => void;
212
- /**
213
- * Optional override for the network detail component. The desktop dashboard
214
- * injects the real `@buoy-gg/network` export here because the runtime
215
- * `require("@buoy-gg/network")` fallback is unreliable in its Vite/ESM build.
216
- * When omitted, the dynamically-required component is used (works on mobile).
217
- */
218
- NetworkEventDetailViewComponent?: ComponentType<{
219
- event: unknown;
220
- ignoredPatterns?: Set<string>;
221
- onTogglePattern?: (value: string) => void;
222
- }>;
223
- /**
224
- * Optional wrapper rendered around the network detail view — e.g. the desktop
225
- * passes `NetworkBodyResolverProvider` so large request/response bodies that
226
- * were stripped from the sync snapshot can be fetched from the device on demand.
227
- */
228
- networkDetailWrapper?: ComponentType<{ children: ReactNode }>;
229
- /**
230
- * Optional override for the route detail component. The desktop dashboard
231
- * injects the real `@buoy-gg/route-events` export here for the same reason it
232
- * injects the network one (Vite/ESM can't rely on the runtime `require`).
233
- */
234
- RouteEventDetailComponent?: ComponentType<{
235
- event: unknown;
236
- visitNumber?: number;
237
- onNavigate?: (pathname: string) => void;
238
- }>;
239
- /**
240
- * Overrides for the per-tool detail pages this component renders.
241
- *
242
- * ⚠️ REQUIRED IN A BUNDLED HOST. They are normally resolved with a runtime
243
- * `require("@buoy-gg/storage")` and friends, which works under Metro but NOT
244
- * in a Vite/ESM bundle — there every one of them silently resolves to null and
245
- * opening an event falls back to the generic key/value renderer instead of
246
- * that tool's real detail page. Buoy Desktop passes all of them.
247
- *
248
- * `NetworkEventDetailViewComponent` / `RouteEventDetailComponent` above are
249
- * the older single-component form of the same thing and still win if both are
250
- * supplied.
251
- */
252
- detailComponents?: Partial<OptionalDetailComponents>;
253
- /** Navigate the host app to a route (route detail "Go to route" action). */
254
- onNavigate?: (pathname: string) => void;
255
- }
256
-
257
- export const UnifiedEventDetail = memo(function UnifiedEventDetail({
258
- event,
259
- onBack,
260
- NetworkEventDetailViewComponent,
261
- networkDetailWrapper,
262
- RouteEventDetailComponent,
263
- detailComponents,
264
- onNavigate,
265
- }: UnifiedEventDetailProps) {
266
- /**
267
- * One resolution point for every per-tool detail page: the `require`-loaded
268
- * set, overridden by whatever the host injected.
269
- */
270
- const resolved = useMemo<OptionalDetailComponents>(
271
- () => ({ ...optionalComponents, ...detailComponents }),
272
- [detailComponents]
273
- );
274
- const sourceConfig = SOURCE_CONFIG[event.source];
275
- const timestamp = new Date(event.timestamp);
276
- // Shared ignored-domain/URL patterns — drives the "Ignore Domain / Ignore URL
277
- // Pattern" toggles at the bottom of the network detail page so they actually
278
- // work here and stay in sync with the Network tool.
279
- const { values: ignoredPatternValues, toggle: toggleIgnoredPattern } =
280
- useIgnoredPatterns();
281
-
282
- // For storage events, create a conversation object to use with StorageEventDetailContent
283
- const storageConversation = useMemo(() => {
284
- if (!isStorageEvent(event.source)) return null;
285
- if (!resolved.StorageEventDetailContent) return null;
286
-
287
- const raw = event.originalEvent as AsyncStorageEvent & {
288
- storageType?: "async" | "mmkv";
289
- };
290
-
291
- /**
292
- * `timestamp` is a real `Date` in-process but an ISO STRING once the event
293
- * has crossed a sync transport, and `StorageEventDetailContent` calls
294
- * `date.getHours()` on it. `new Date(...)` is idempotent for a Date, so
295
- * normalising unconditionally costs nothing and covers both. The same
296
- * reasoning is why `event.timestamp` above is wrapped.
297
- */
298
- const originalEvent = {
299
- ...raw,
300
- timestamp: new Date(raw.timestamp),
301
- };
302
-
303
- // Create a conversation with a single event for the detail view
304
- return {
305
- key: originalEvent.data?.key || "unknown",
306
- lastEvent: originalEvent,
307
- events: [originalEvent],
308
- totalOperations: 1,
309
- currentValue: originalEvent.data?.value,
310
- valueType: getValueType(originalEvent.data?.value),
311
- storageTypes: new Set([originalEvent.storageType || "async"]) as Set<"async" | "mmkv">,
312
- };
313
- }, [event, resolved]);
314
-
315
- // For storage events, use the shared StorageEventDetailContent if available
316
- if (storageConversation && resolved.StorageEventDetailContent) {
317
- const { StorageEventDetailContent } = resolved;
318
- return (
319
- <View style={styles.container}>
320
- <StorageEventDetailContent
321
- conversation={storageConversation}
322
- selectedEventIndex={0}
323
- onEventIndexChange={() => {}}
324
- disableInternalFooter={true}
325
- />
326
- </View>
327
- );
328
- }
329
-
330
- // For Redux events, use the shared ReduxActionDetailContent if available
331
- if (event.source === "redux" && resolved.ReduxActionDetailContent) {
332
- const { ReduxActionDetailContent } = resolved;
333
- const reduxAction = event.originalEvent as ReduxAction;
334
-
335
- return (
336
- <View style={styles.container}>
337
- <ReduxActionDetailContent
338
- action={reduxAction}
339
- actions={[reduxAction]}
340
- selectedIndex={0}
341
- onIndexChange={() => {}}
342
- disableInternalFooter={true}
343
- />
344
- </View>
345
- );
346
- }
347
-
348
- // For network events, render the SAME NetworkEventDetailView the Network tool
349
- // uses. Prefer an injected component (desktop), fall back to the dynamically
350
- // required one (mobile). Wire the shared ignored-patterns so the bottom
351
- // "Ignore Domain / Ignore URL Pattern" toggles work, and wrap in the optional
352
- // body-resolver provider so large bodies can be fetched on demand.
353
- const NetworkDetailView =
354
- NetworkEventDetailViewComponent ?? resolved.NetworkEventDetailView;
355
- if (event.source === "network" && NetworkDetailView) {
356
- const networkEvent = event.originalEvent as NetworkEvent;
357
- const NetworkWrapper = networkDetailWrapper ?? PassThrough;
358
-
359
- return (
360
- <View style={styles.container}>
361
- <NetworkWrapper>
362
- <ScrollView style={styles.content}>
363
- <NetworkDetailView
364
- event={networkEvent}
365
- ignoredPatterns={ignoredPatternValues}
366
- onTogglePattern={toggleIgnoredPattern}
367
- />
368
- </ScrollView>
369
- </NetworkWrapper>
370
- </View>
371
- );
372
- }
373
-
374
- // For React Query events, use the specialized ReactQueryEventDetail
375
- if (event.source === "react-query" || event.source === "react-query-query" || event.source === "react-query-mutation") {
376
- return (
377
- <View style={styles.container}>
378
- <ReactQueryEventDetail event={event} />
379
- </View>
380
- );
381
- }
382
-
383
- // For Zustand events, use the shared ZustandStateDetailContent if available
384
- if (event.source === "zustand" && resolved.ZustandStateDetailContent) {
385
- const { ZustandStateDetailContent } = resolved;
386
- const zustandChange = event.originalEvent;
387
-
388
- return (
389
- <View style={styles.container}>
390
- <ZustandStateDetailContent
391
- change={zustandChange}
392
- changes={[zustandChange]}
393
- selectedIndex={0}
394
- onIndexChange={() => {}}
395
- disableInternalFooter={true}
396
- />
397
- </View>
398
- );
399
- }
400
-
401
- // For Jotai events, use the shared JotaiAtomDetailContent if available
402
- if (event.source === "jotai" && resolved.JotaiAtomDetailContent) {
403
- const { JotaiAtomDetailContent } = resolved;
404
- const jotaiChange = event.originalEvent;
405
-
406
- return (
407
- <View style={styles.container}>
408
- <JotaiAtomDetailContent
409
- change={jotaiChange}
410
- changes={[jotaiChange]}
411
- selectedIndex={0}
412
- onIndexChange={() => {}}
413
- disableInternalFooter={true}
414
- />
415
- </View>
416
- );
417
- }
418
-
419
- // For render events, use the RenderDetailView if available
420
- if (event.source === "render" && resolved.RenderDetailView) {
421
- const { RenderDetailView } = resolved;
422
- const renderData = event.originalEvent as { render: unknown };
423
-
424
- return (
425
- <View style={styles.container}>
426
- <ScrollView style={styles.content}>
427
- <RenderDetailView render={renderData.render} />
428
- </ScrollView>
429
- </View>
430
- );
431
- }
432
-
433
- // For route events, render the SAME RouteEventDetail the Routes tool uses.
434
- // Prefer an injected component (desktop), fall back to the dynamically required
435
- // one (mobile). onNavigate powers the "Go to route" action.
436
- const RouteDetail =
437
- RouteEventDetailComponent ?? resolved.RouteEventDetail;
438
- if (event.source === "route" && RouteDetail) {
439
- return (
440
- <View style={styles.container}>
441
- <RouteDetail event={event.originalEvent} onNavigate={onNavigate} />
442
- </View>
443
- );
444
- }
445
-
446
- // For all other events (or when specific components aren't available), show the generic detail view
447
- const getEventData = () => {
448
- return event.originalEvent;
449
- };
450
-
451
- const handleCopy = async () => {
452
- await copyToClipboard({
453
- source: event.source,
454
- timestamp: timestamp.toISOString(),
455
- title: event.title,
456
- subtitle: event.subtitle,
457
- data: getEventData(),
458
- });
459
- };
460
-
461
- return (
462
- <View style={styles.container}>
463
- <ScrollView
464
- style={styles.content}
465
- contentContainerStyle={styles.contentContainer}
466
- >
467
- {/* Source Badge */}
468
- <View style={styles.sourceBadgeRow}>
469
- <View
470
- style={[
471
- styles.sourceBadge,
472
- { backgroundColor: sourceConfig.color + "20" },
473
- ]}
474
- >
475
- <View
476
- style={[styles.sourceDot, { backgroundColor: sourceConfig.color }]}
477
- />
478
- <Text style={[styles.sourceLabel, { color: sourceConfig.color }]}>
479
- {sourceConfig.label}
480
- </Text>
481
- </View>
482
- </View>
483
-
484
- {/* Title */}
485
- <Text style={styles.title}>{event.title}</Text>
486
- <Text style={styles.subtitle}>{event.subtitle}</Text>
487
-
488
- {/* Timestamp */}
489
- <View style={styles.timestampRow}>
490
- <Text style={styles.timestampLabel}>Timestamp</Text>
491
- <Text style={styles.timestampValue}>
492
- {timestamp.toLocaleTimeString()} ({formatRelativeTime(timestamp)})
493
- </Text>
494
- </View>
495
-
496
- {/* Event Data */}
497
- <View style={styles.dataSection}>
498
- <Text style={styles.sectionLabel}>Event Data</Text>
499
- <View style={styles.dataContainer}>
500
- <DataViewer
501
- data={getEventData()}
502
- title=""
503
- showTypeFilter={true}
504
- rawMode={true}
505
- initialExpanded={true}
506
- />
507
- </View>
508
- </View>
509
- </ScrollView>
510
- </View>
511
- );
512
- });
513
-
514
- const styles = StyleSheet.create({
515
- container: {
516
- flex: 1,
517
- // Transparent so the night sheet's star field shows through.
518
- backgroundColor: "transparent",
519
- },
520
- content: {
521
- flex: 1,
522
- },
523
- contentContainer: {
524
- padding: 16,
525
- },
526
- sourceBadgeRow: {
527
- flexDirection: "row",
528
- marginBottom: 12,
529
- },
530
- sourceBadge: {
531
- flexDirection: "row",
532
- alignItems: "center",
533
- paddingHorizontal: 10,
534
- paddingVertical: 6,
535
- borderRadius: 12,
536
- gap: 6,
537
- },
538
- sourceDot: {
539
- width: 6,
540
- height: 6,
541
- borderRadius: 3,
542
- },
543
- sourceLabel: {
544
- fontSize: 12,
545
- fontWeight: "600",
546
- },
547
- title: {
548
- fontSize: 24,
549
- fontWeight: "700",
550
- color: night.color.text,
551
- marginBottom: 4,
552
- },
553
- subtitle: {
554
- fontSize: 16,
555
- color: night.color.textTertiary,
556
- marginBottom: 16,
557
- },
558
- timestampRow: {
559
- flexDirection: "row",
560
- justifyContent: "space-between",
561
- alignItems: "center",
562
- paddingVertical: 12,
563
- borderTopWidth: 1,
564
- borderTopColor: night.color.border,
565
- borderBottomWidth: 1,
566
- borderBottomColor: night.color.border,
567
- marginBottom: 16,
568
- },
569
- timestampLabel: {
570
- fontSize: 14,
571
- color: night.color.textTertiary,
572
- },
573
- timestampValue: {
574
- fontSize: 14,
575
- color: night.color.text,
576
- fontFamily: "monospace",
577
- },
578
- dataSection: {
579
- marginTop: 8,
580
- },
581
- sectionLabel: {
582
- fontSize: 12,
583
- fontWeight: "600",
584
- color: night.color.textTertiary,
585
- textTransform: "uppercase",
586
- letterSpacing: 0.5,
587
- marginBottom: 8,
588
- },
589
- dataContainer: {
590
- backgroundColor: night.color.surface,
591
- borderRadius: 8,
592
- borderWidth: 1,
593
- borderColor: night.color.border,
594
- overflow: "hidden",
595
- },
596
- });