@buoy-gg/events 2.1.1

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 (84) hide show
  1. package/LICENSE +58 -0
  2. package/README.md +55 -0
  3. package/lib/commonjs/components/EventsCopySettingsView.js +645 -0
  4. package/lib/commonjs/components/EventsModal.js +263 -0
  5. package/lib/commonjs/components/ReactQueryEventDetail.js +428 -0
  6. package/lib/commonjs/components/UnifiedEventDetail.js +370 -0
  7. package/lib/commonjs/components/UnifiedEventFilters.js +113 -0
  8. package/lib/commonjs/components/UnifiedEventItem.js +349 -0
  9. package/lib/commonjs/components/UnifiedEventList.js +154 -0
  10. package/lib/commonjs/components/UnifiedEventViewer.js +126 -0
  11. package/lib/commonjs/hooks/useUnifiedEvents.js +237 -0
  12. package/lib/commonjs/index.js +205 -0
  13. package/lib/commonjs/package.json +1 -0
  14. package/lib/commonjs/preset.js +66 -0
  15. package/lib/commonjs/stores/unifiedEventStore.js +413 -0
  16. package/lib/commonjs/types/copySettings.js +220 -0
  17. package/lib/commonjs/types/index.js +17 -0
  18. package/lib/commonjs/utils/autoDiscoverEventSources.js +640 -0
  19. package/lib/commonjs/utils/badgeSelectionStorage.js +58 -0
  20. package/lib/commonjs/utils/copySettingsStorage.js +66 -0
  21. package/lib/commonjs/utils/correlationUtils.js +130 -0
  22. package/lib/commonjs/utils/eventExportFormatter.js +1095 -0
  23. package/lib/commonjs/utils/eventTransformers.js +496 -0
  24. package/lib/module/components/EventsCopySettingsView.js +641 -0
  25. package/lib/module/components/EventsModal.js +259 -0
  26. package/lib/module/components/ReactQueryEventDetail.js +424 -0
  27. package/lib/module/components/UnifiedEventDetail.js +366 -0
  28. package/lib/module/components/UnifiedEventFilters.js +109 -0
  29. package/lib/module/components/UnifiedEventItem.js +345 -0
  30. package/lib/module/components/UnifiedEventList.js +150 -0
  31. package/lib/module/components/UnifiedEventViewer.js +122 -0
  32. package/lib/module/hooks/useUnifiedEvents.js +234 -0
  33. package/lib/module/index.js +77 -0
  34. package/lib/module/preset.js +62 -0
  35. package/lib/module/stores/unifiedEventStore.js +387 -0
  36. package/lib/module/types/copySettings.js +215 -0
  37. package/lib/module/types/index.js +37 -0
  38. package/lib/module/utils/autoDiscoverEventSources.js +633 -0
  39. package/lib/module/utils/badgeSelectionStorage.js +52 -0
  40. package/lib/module/utils/copySettingsStorage.js +61 -0
  41. package/lib/module/utils/correlationUtils.js +120 -0
  42. package/lib/module/utils/eventExportFormatter.js +1085 -0
  43. package/lib/module/utils/eventTransformers.js +487 -0
  44. package/lib/typescript/components/EventsCopySettingsView.d.ts +16 -0
  45. package/lib/typescript/components/EventsModal.d.ts +16 -0
  46. package/lib/typescript/components/ReactQueryEventDetail.d.ts +15 -0
  47. package/lib/typescript/components/UnifiedEventDetail.d.ts +15 -0
  48. package/lib/typescript/components/UnifiedEventFilters.d.ts +21 -0
  49. package/lib/typescript/components/UnifiedEventItem.d.ts +26 -0
  50. package/lib/typescript/components/UnifiedEventList.d.ts +27 -0
  51. package/lib/typescript/components/UnifiedEventViewer.d.ts +8 -0
  52. package/lib/typescript/hooks/useUnifiedEvents.d.ts +30 -0
  53. package/lib/typescript/index.d.ts +28 -0
  54. package/lib/typescript/preset.d.ts +62 -0
  55. package/lib/typescript/stores/unifiedEventStore.d.ts +146 -0
  56. package/lib/typescript/types/copySettings.d.ts +179 -0
  57. package/lib/typescript/types/index.d.ts +73 -0
  58. package/lib/typescript/utils/autoDiscoverEventSources.d.ts +74 -0
  59. package/lib/typescript/utils/badgeSelectionStorage.d.ts +21 -0
  60. package/lib/typescript/utils/copySettingsStorage.d.ts +21 -0
  61. package/lib/typescript/utils/correlationUtils.d.ts +36 -0
  62. package/lib/typescript/utils/eventExportFormatter.d.ts +49 -0
  63. package/lib/typescript/utils/eventTransformers.d.ts +119 -0
  64. package/package.json +91 -0
  65. package/src/components/EventsCopySettingsView.tsx +742 -0
  66. package/src/components/EventsModal.tsx +328 -0
  67. package/src/components/ReactQueryEventDetail.tsx +413 -0
  68. package/src/components/UnifiedEventDetail.tsx +371 -0
  69. package/src/components/UnifiedEventFilters.tsx +156 -0
  70. package/src/components/UnifiedEventItem.tsx +396 -0
  71. package/src/components/UnifiedEventList.tsx +197 -0
  72. package/src/components/UnifiedEventViewer.tsx +132 -0
  73. package/src/hooks/useUnifiedEvents.ts +288 -0
  74. package/src/index.tsx +112 -0
  75. package/src/preset.tsx +57 -0
  76. package/src/stores/unifiedEventStore.ts +405 -0
  77. package/src/types/copySettings.ts +269 -0
  78. package/src/types/index.ts +96 -0
  79. package/src/utils/autoDiscoverEventSources.ts +690 -0
  80. package/src/utils/badgeSelectionStorage.ts +51 -0
  81. package/src/utils/copySettingsStorage.ts +61 -0
  82. package/src/utils/correlationUtils.ts +146 -0
  83. package/src/utils/eventExportFormatter.ts +1233 -0
  84. package/src/utils/eventTransformers.ts +567 -0
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * useUnifiedEvents Hook
5
+ *
6
+ * Main hook for consuming unified events from all sources.
7
+ * Automatically discovers and subscribes to available event sources.
8
+ */
9
+
10
+ import { useState, useEffect, useCallback, useMemo, useRef } from "react";
11
+ import { useFeatureGate } from "@buoy-gg/shared-ui";
12
+ import { subscribe, subscribeToStorage, subscribeToRedux, subscribeToNetwork, subscribeToReactQuery, subscribeToRoutes, unsubscribeAll, getSourceCounts, clearEvents as clearStoreEvents, getAvailableEventSources } from "../stores/unifiedEventStore";
13
+ import { saveEnabledSources, loadEnabledSources } from "../utils/badgeSelectionStorage";
14
+ import { getSourceDisplayConfig } from "../utils/autoDiscoverEventSources";
15
+
16
+ /** Max events for non-Pro users */
17
+ const FREE_TIER_MAX_EVENTS = 25;
18
+
19
+ /**
20
+ * All possible sources for display
21
+ */
22
+ const ALL_DISPLAY_SOURCES = ["storage-async", "redux", "network", "react-query-query", "react-query-mutation", "route"];
23
+
24
+ /**
25
+ * Map display sources to actual event sources they should match
26
+ */
27
+ const SOURCE_TO_EVENT_SOURCES = {
28
+ "storage-async": ["storage-async", "storage-mmkv"],
29
+ "storage-mmkv": ["storage-mmkv"],
30
+ redux: ["redux"],
31
+ network: ["network"],
32
+ "react-query": ["react-query", "react-query-query"],
33
+ "react-query-query": ["react-query", "react-query-query"],
34
+ "react-query-mutation": ["react-query-mutation"],
35
+ route: ["route"]
36
+ };
37
+
38
+ /**
39
+ * Map event sources to their parent discovery ID
40
+ */
41
+ const EVENT_SOURCE_TO_DISCOVERY_ID = {
42
+ "storage-async": "storage",
43
+ "storage-mmkv": "storage",
44
+ redux: "redux",
45
+ network: "network",
46
+ "react-query": "react-query",
47
+ "react-query-query": "react-query",
48
+ "react-query-mutation": "react-query",
49
+ route: "route-events"
50
+ };
51
+ export function useUnifiedEvents() {
52
+ const {
53
+ isPro
54
+ } = useFeatureGate();
55
+ const [events, setEvents] = useState([]);
56
+ const [enabledSources, setEnabledSources] = useState(() => new Set(ALL_DISPLAY_SOURCES));
57
+ const [isCapturing, setIsCapturing] = useState(true);
58
+ const isStateRestoredRef = useRef(false);
59
+
60
+ // Get discovered sources (which packages are installed)
61
+ const discoveredSources = useMemo(() => {
62
+ return getAvailableEventSources();
63
+ }, []);
64
+
65
+ // Get available display sources (only show sources for installed packages)
66
+ const availableDisplaySources = useMemo(() => {
67
+ return ALL_DISPLAY_SOURCES.filter(displaySource => {
68
+ const eventSources = SOURCE_TO_EVENT_SOURCES[displaySource] || [displaySource];
69
+ // Check if any of the event sources for this display source are available
70
+ return eventSources.some(es => discoveredSources.has(es));
71
+ });
72
+ }, [discoveredSources]);
73
+
74
+ // Subscribe to store changes and start capturing on mount
75
+ useEffect(() => {
76
+ // Subscribe to store updates
77
+ const unsubscribe = subscribe(newEvents => {
78
+ setEvents(newEvents);
79
+ });
80
+
81
+ // Start capturing from all available sources
82
+ // These functions are now safe - they check if the source is available
83
+ subscribeToStorage();
84
+ subscribeToRedux();
85
+ subscribeToNetwork();
86
+ subscribeToReactQuery();
87
+ subscribeToRoutes();
88
+ return unsubscribe;
89
+ }, []);
90
+
91
+ // Restore saved badge selection state on mount
92
+ useEffect(() => {
93
+ const restoreState = async () => {
94
+ const savedSources = await loadEnabledSources();
95
+ if (savedSources && savedSources.length > 0) {
96
+ // Filter to only include valid sources that still exist and are available
97
+ const validSources = savedSources.filter(s => availableDisplaySources.includes(s));
98
+ if (validSources.length > 0) {
99
+ setEnabledSources(new Set(validSources));
100
+ } else {
101
+ // If no saved sources are valid, enable all available sources
102
+ setEnabledSources(new Set(availableDisplaySources));
103
+ }
104
+ } else {
105
+ // No saved state - enable all available sources
106
+ setEnabledSources(new Set(availableDisplaySources));
107
+ }
108
+ isStateRestoredRef.current = true;
109
+ };
110
+ restoreState();
111
+ }, [availableDisplaySources]);
112
+
113
+ // Persist enabled sources whenever they change (after initial restoration)
114
+ useEffect(() => {
115
+ if (!isStateRestoredRef.current) {
116
+ return;
117
+ }
118
+ saveEnabledSources(Array.from(enabledSources));
119
+ }, [enabledSources]);
120
+
121
+ // Build set of all event sources that should be shown
122
+ const allowedEventSources = useMemo(() => {
123
+ const allowed = new Set();
124
+ enabledSources.forEach(displaySource => {
125
+ const eventSources = SOURCE_TO_EVENT_SOURCES[displaySource];
126
+ if (eventSources) {
127
+ eventSources.forEach(s => allowed.add(s));
128
+ }
129
+ });
130
+ return allowed;
131
+ }, [enabledSources]);
132
+
133
+ // Filter events by enabled sources
134
+ const allFilteredEvents = useMemo(() => {
135
+ if (allowedEventSources.size === 0) {
136
+ return [];
137
+ }
138
+ return events.filter(event => allowedEventSources.has(event.source));
139
+ }, [events, allowedEventSources]);
140
+
141
+ // Apply free tier limit if not Pro
142
+ const filteredEvents = useMemo(() => {
143
+ if (isPro) {
144
+ return allFilteredEvents;
145
+ }
146
+ return allFilteredEvents.slice(0, FREE_TIER_MAX_EVENTS);
147
+ }, [allFilteredEvents, isPro]);
148
+
149
+ // Calculate hidden events count for free tier
150
+ const hiddenEventsCount = useMemo(() => {
151
+ if (isPro) {
152
+ return 0;
153
+ }
154
+ return Math.max(0, allFilteredEvents.length - FREE_TIER_MAX_EVENTS);
155
+ }, [allFilteredEvents, isPro]);
156
+
157
+ // Get all available sources with counts, sorted: enabled first, disabled last
158
+ const availableSources = useMemo(() => {
159
+ const counts = getSourceCounts();
160
+ const sources = availableDisplaySources.map(source => {
161
+ const eventSources = SOURCE_TO_EVENT_SOURCES[source] || [source];
162
+ const totalCount = eventSources.reduce((sum, s) => sum + (counts[s] || 0), 0);
163
+ const displayConfig = getSourceDisplayConfig(source);
164
+ return {
165
+ source,
166
+ ...displayConfig,
167
+ count: totalCount,
168
+ enabled: enabledSources.has(source)
169
+ };
170
+ });
171
+
172
+ // Sort: enabled first, then disabled
173
+ return sources.sort((a, b) => {
174
+ if (a.enabled && !b.enabled) return -1;
175
+ if (!a.enabled && b.enabled) return 1;
176
+ return 0;
177
+ });
178
+ }, [events, enabledSources, availableDisplaySources]);
179
+ const toggleSource = useCallback(source => {
180
+ setEnabledSources(prev => {
181
+ const next = new Set(prev);
182
+ if (next.has(source)) {
183
+ next.delete(source);
184
+ } else {
185
+ next.add(source);
186
+ }
187
+ return next;
188
+ });
189
+ }, []);
190
+ const enableAllSources = useCallback(() => {
191
+ setEnabledSources(new Set(availableDisplaySources));
192
+ }, [availableDisplaySources]);
193
+ const clearEvents = useCallback(() => {
194
+ clearStoreEvents();
195
+ }, []);
196
+ const startCapturing = useCallback(() => {
197
+ subscribeToStorage();
198
+ subscribeToRedux();
199
+ subscribeToNetwork();
200
+ subscribeToReactQuery();
201
+ subscribeToRoutes();
202
+ setIsCapturing(true);
203
+ }, []);
204
+ const stopCapturing = useCallback(() => {
205
+ unsubscribeAll();
206
+ setIsCapturing(false);
207
+ }, []);
208
+ const toggleCapturing = useCallback(() => {
209
+ if (isCapturing) {
210
+ stopCapturing();
211
+ } else {
212
+ startCapturing();
213
+ }
214
+ }, [isCapturing, startCapturing, stopCapturing]);
215
+ return {
216
+ events,
217
+ filteredEvents,
218
+ availableSources,
219
+ enabledSources,
220
+ toggleSource,
221
+ enableAllSources,
222
+ clearEvents,
223
+ totalCount: events.length,
224
+ filteredCount: filteredEvents.length,
225
+ isCapturing,
226
+ startCapturing,
227
+ stopCapturing,
228
+ toggleCapturing,
229
+ discoveredSources,
230
+ hiddenEventsCount,
231
+ isPro
232
+ };
233
+ }
234
+ //# sourceMappingURL=useUnifiedEvents.js.map
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * @buoy-gg/events
5
+ *
6
+ * Unified event timeline for all DevTools sources.
7
+ * Shows events from Storage, Redux, Network, React Query, etc.
8
+ * in a single chronological view.
9
+ *
10
+ * PUBLIC API - Only these exports are supported for external use.
11
+ * Internal stores and subscription mechanisms are not exported to prevent
12
+ * bypassing the tool's intended usage patterns.
13
+ */
14
+
15
+ // =============================================================================
16
+ // PRESET (Primary entry point for users)
17
+ // =============================================================================
18
+ export { eventsToolPreset, createEventsTool } from "./preset";
19
+
20
+ // =============================================================================
21
+ // MAIN COMPONENT
22
+ // =============================================================================
23
+ export { UnifiedEventViewer } from "./components/UnifiedEventViewer";
24
+
25
+ // =============================================================================
26
+ // HOOKS (For consuming event data)
27
+ // =============================================================================
28
+ export { useUnifiedEvents } from "./hooks/useUnifiedEvents";
29
+
30
+ // =============================================================================
31
+ // TYPES
32
+ // =============================================================================
33
+
34
+ // =============================================================================
35
+ // COPY SETTINGS (Configuration types and presets)
36
+ // =============================================================================
37
+ export { DEFAULT_COPY_SETTINGS, COPY_PRESETS, PRESET_METADATA, detectActivePreset } from "./types/copySettings";
38
+
39
+ // =============================================================================
40
+ // UI COMPONENTS (For custom implementations)
41
+ // =============================================================================
42
+ export { UnifiedEventItem } from "./components/UnifiedEventItem";
43
+ export { UnifiedEventList } from "./components/UnifiedEventList";
44
+ export { UnifiedEventFilters } from "./components/UnifiedEventFilters";
45
+ export { UnifiedEventDetail } from "./components/UnifiedEventDetail";
46
+ export { ReactQueryEventDetail } from "./components/ReactQueryEventDetail";
47
+ export { EventsCopySettingsView } from "./components/EventsCopySettingsView";
48
+
49
+ // =============================================================================
50
+ // CORRELATION UTILITIES (For linking related events)
51
+ // =============================================================================
52
+ export { findRelatedEvents, hasRelatedEvents, getRelatedEventsCount, buildCorrelationCountMap, getCorrelationGroup, getCorrelationLabel, getCorrelationColor } from "./utils/correlationUtils";
53
+
54
+ // =============================================================================
55
+ // EXPORT UTILITIES (For generating formatted exports)
56
+ // =============================================================================
57
+ export { generateExport, generateMarkdownExport, generateJsonExport, generatePlaintextExport, estimateExportSize, getExportSummary, filterEvents } from "./utils/eventExportFormatter";
58
+ // =============================================================================
59
+ // COPY SETTINGS STORAGE (For persisting export preferences)
60
+ // =============================================================================
61
+ export { loadCopySettings, saveCopySettings, clearCopySettings } from "./utils/copySettingsStorage";
62
+
63
+ // =============================================================================
64
+ // INTERNAL EXPORTS (For @buoy-gg/* packages only - not part of public API)
65
+ // These are NOT exported to prevent users from bypassing the unified event
66
+ // system. Event subscription should go through the proper tool integration.
67
+ // =============================================================================
68
+ // NOTE: The following are intentionally NOT exported:
69
+ // - unifiedEventStore (internal store)
70
+ // - subscribeToStorage, unsubscribeFromStorage (internal subscription)
71
+ // - subscribeToRedux, unsubscribeFromRedux (internal subscription)
72
+ // - subscribeToNetwork, unsubscribeFromNetwork (internal subscription)
73
+ // - subscribeToReactQuery, unsubscribeFromReactQuery (internal subscription)
74
+ // - subscribeToRoutes, unsubscribeFromRoutes (internal subscription)
75
+ // - getEvents, getActiveSources, getSourceCounts (internal store operations)
76
+ // - clearEvents, subscribe, getEventCount (internal store operations)
77
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Pre-configured Events tool for FloatingDevTools
5
+ *
6
+ * This preset provides a unified event timeline showing events
7
+ * from all DevTools sources (Storage, Redux, Network, etc.)
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * import { eventsToolPreset } from '@buoy-gg/events';
12
+ *
13
+ * const installedApps = [
14
+ * eventsToolPreset, // That's it!
15
+ * // ...other tools
16
+ * ];
17
+ * ```
18
+ */
19
+
20
+ import { EventsIcon, EVENTS_ICON_COLOR } from "@buoy-gg/floating-tools-core";
21
+ import { EventsModal } from "./components/EventsModal";
22
+
23
+ /**
24
+ * Pre-configured Events tool for FloatingDevTools.
25
+ * Shows a unified timeline of events from all sources:
26
+ * - AsyncStorage operations
27
+ * - MMKV operations (coming soon)
28
+ * - Redux actions (coming soon)
29
+ * - Network requests (coming soon)
30
+ * - React Query events (coming soon)
31
+ */
32
+ import { jsx as _jsx } from "react/jsx-runtime";
33
+ export const eventsToolPreset = {
34
+ id: "events",
35
+ name: "EVENTS",
36
+ description: "Unified event timeline",
37
+ slot: "both",
38
+ icon: ({
39
+ size,
40
+ color
41
+ }) => /*#__PURE__*/_jsx(EventsIcon, {
42
+ size: size,
43
+ color: color || EVENTS_ICON_COLOR
44
+ }),
45
+ component: EventsModal,
46
+ props: {
47
+ enableSharedModalDimensions: false
48
+ }
49
+ };
50
+
51
+ /**
52
+ * Create a custom Events tool configuration.
53
+ * Use this if you want to override default settings.
54
+ */
55
+ export function createEventsTool(options = {}) {
56
+ return {
57
+ ...eventsToolPreset,
58
+ name: options.name ?? eventsToolPreset.name,
59
+ description: options.description ?? eventsToolPreset.description
60
+ };
61
+ }
62
+ //# sourceMappingURL=preset.js.map