react-native-debug-toolkit 0.6.3 → 2.0.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/LICENSE +21 -0
- package/README.md +150 -212
- package/lib/commonjs/components/ClipboardTab.js +92 -0
- package/lib/commonjs/components/ClipboardTab.js.map +1 -0
- package/lib/commonjs/components/ConsoleLogTab.js +295 -0
- package/lib/commonjs/components/ConsoleLogTab.js.map +1 -0
- package/lib/commonjs/components/EnvironmentTab.js +288 -0
- package/lib/commonjs/components/EnvironmentTab.js.map +1 -0
- package/lib/commonjs/components/FloatPanelView.js +797 -0
- package/lib/commonjs/components/FloatPanelView.js.map +1 -0
- package/lib/commonjs/components/NavigationLogTab.js +131 -0
- package/lib/commonjs/components/NavigationLogTab.js.map +1 -0
- package/lib/commonjs/components/NetworkLogTab.js +575 -0
- package/lib/commonjs/components/NetworkLogTab.js.map +1 -0
- package/lib/commonjs/components/ThirdPartyLibsTab.js +97 -0
- package/lib/commonjs/components/ThirdPartyLibsTab.js.map +1 -0
- package/lib/commonjs/components/TrackLogTab.js +372 -0
- package/lib/commonjs/components/TrackLogTab.js.map +1 -0
- package/lib/commonjs/components/ZustandLogTab.js +451 -0
- package/lib/commonjs/components/ZustandLogTab.js.map +1 -0
- package/lib/commonjs/components/shared/CollapsibleSection.js +84 -0
- package/lib/commonjs/components/shared/CollapsibleSection.js.map +1 -0
- package/lib/commonjs/components/shared/CopyButton.js +64 -0
- package/lib/commonjs/components/shared/CopyButton.js.map +1 -0
- package/lib/commonjs/components/shared/JsonView.js +157 -0
- package/lib/commonjs/components/shared/JsonView.js.map +1 -0
- package/lib/commonjs/core/DebugToolkit.js +142 -0
- package/lib/commonjs/core/DebugToolkit.js.map +1 -0
- package/lib/commonjs/core/DebugToolkitProvider.js +64 -0
- package/lib/commonjs/core/DebugToolkitProvider.js.map +1 -0
- package/lib/commonjs/features/ClipboardFeature.js +17 -0
- package/lib/commonjs/features/ClipboardFeature.js.map +1 -0
- package/lib/commonjs/features/ConsoleLogFeature.js +98 -0
- package/lib/commonjs/features/ConsoleLogFeature.js.map +1 -0
- package/lib/commonjs/features/EnvironmentFeature.js +168 -0
- package/lib/commonjs/features/EnvironmentFeature.js.map +1 -0
- package/lib/commonjs/features/NavigationLogFeature.js +60 -0
- package/lib/commonjs/features/NavigationLogFeature.js.map +1 -0
- package/lib/commonjs/features/NetworkFeature.js +328 -0
- package/lib/commonjs/features/NetworkFeature.js.map +1 -0
- package/lib/commonjs/features/ThirdPartyLibsFeature.js +51 -0
- package/lib/commonjs/features/ThirdPartyLibsFeature.js.map +1 -0
- package/lib/commonjs/features/TrackFeature.js +55 -0
- package/lib/commonjs/features/TrackFeature.js.map +1 -0
- package/lib/commonjs/features/ZustandLogFeature.js +76 -0
- package/lib/commonjs/features/ZustandLogFeature.js.map +1 -0
- package/lib/commonjs/hooks/useNavigationLogger.js +78 -0
- package/lib/commonjs/hooks/useNavigationLogger.js.map +1 -0
- package/lib/commonjs/hooks/useSlideDetailAnimation.js +53 -0
- package/lib/commonjs/hooks/useSlideDetailAnimation.js.map +1 -0
- package/lib/commonjs/index.js +165 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/initialize.js +161 -0
- package/lib/commonjs/initialize.js.map +1 -0
- package/lib/commonjs/native/NativeDebugLibs.js +58 -0
- package/lib/commonjs/native/NativeDebugLibs.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/types/index.js +6 -0
- package/lib/commonjs/types/index.js.map +1 -0
- package/lib/commonjs/utils/constants.js +135 -0
- package/lib/commonjs/utils/constants.js.map +1 -0
- package/lib/commonjs/utils/copyToComputer.js +97 -0
- package/lib/commonjs/utils/copyToComputer.js.map +1 -0
- package/lib/commonjs/utils/createEventChannel.js +21 -0
- package/lib/commonjs/utils/createEventChannel.js.map +1 -0
- package/lib/commonjs/utils/createObservableStore.js +38 -0
- package/lib/commonjs/utils/createObservableStore.js.map +1 -0
- package/lib/commonjs/utils/safeStringify.js +27 -0
- package/lib/commonjs/utils/safeStringify.js.map +1 -0
- package/lib/module/components/ClipboardTab.js +86 -0
- package/lib/module/components/ClipboardTab.js.map +1 -0
- package/lib/module/components/ConsoleLogTab.js +290 -0
- package/lib/module/components/ConsoleLogTab.js.map +1 -0
- package/lib/module/components/EnvironmentTab.js +282 -0
- package/lib/module/components/EnvironmentTab.js.map +1 -0
- package/lib/module/components/FloatPanelView.js +791 -0
- package/lib/module/components/FloatPanelView.js.map +1 -0
- package/lib/module/components/NavigationLogTab.js +126 -0
- package/lib/module/components/NavigationLogTab.js.map +1 -0
- package/lib/module/components/NetworkLogTab.js +570 -0
- package/lib/module/components/NetworkLogTab.js.map +1 -0
- package/lib/module/components/ThirdPartyLibsTab.js +91 -0
- package/lib/module/components/ThirdPartyLibsTab.js.map +1 -0
- package/lib/module/components/TrackLogTab.js +367 -0
- package/lib/module/components/TrackLogTab.js.map +1 -0
- package/lib/module/components/ZustandLogTab.js +446 -0
- package/lib/module/components/ZustandLogTab.js.map +1 -0
- package/lib/module/components/shared/CollapsibleSection.js +78 -0
- package/lib/module/components/shared/CollapsibleSection.js.map +1 -0
- package/lib/module/components/shared/CopyButton.js +58 -0
- package/lib/module/components/shared/CopyButton.js.map +1 -0
- package/lib/module/components/shared/JsonView.js +152 -0
- package/lib/module/components/shared/JsonView.js.map +1 -0
- package/lib/module/core/DebugToolkit.js +137 -0
- package/lib/module/core/DebugToolkit.js.map +1 -0
- package/lib/module/core/DebugToolkitProvider.js +58 -0
- package/lib/module/core/DebugToolkitProvider.js.map +1 -0
- package/lib/module/features/ClipboardFeature.js +12 -0
- package/lib/module/features/ClipboardFeature.js.map +1 -0
- package/lib/module/features/ConsoleLogFeature.js +93 -0
- package/lib/module/features/ConsoleLogFeature.js.map +1 -0
- package/lib/module/features/EnvironmentFeature.js +164 -0
- package/lib/module/features/EnvironmentFeature.js.map +1 -0
- package/lib/module/features/NavigationLogFeature.js +54 -0
- package/lib/module/features/NavigationLogFeature.js.map +1 -0
- package/lib/module/features/NetworkFeature.js +322 -0
- package/lib/module/features/NetworkFeature.js.map +1 -0
- package/lib/module/features/ThirdPartyLibsFeature.js +46 -0
- package/lib/module/features/ThirdPartyLibsFeature.js.map +1 -0
- package/lib/module/features/TrackFeature.js +49 -0
- package/lib/module/features/TrackFeature.js.map +1 -0
- package/lib/module/features/ZustandLogFeature.js +69 -0
- package/lib/module/features/ZustandLogFeature.js.map +1 -0
- package/lib/module/hooks/useNavigationLogger.js +74 -0
- package/lib/module/hooks/useNavigationLogger.js.map +1 -0
- package/lib/module/hooks/useSlideDetailAnimation.js +50 -0
- package/lib/module/hooks/useSlideDetailAnimation.js.map +1 -0
- package/lib/module/index.js +29 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/initialize.js +156 -0
- package/lib/module/initialize.js.map +1 -0
- package/lib/module/native/NativeDebugLibs.js +54 -0
- package/lib/module/native/NativeDebugLibs.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types/index.js +4 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/utils/constants.js +130 -0
- package/lib/module/utils/constants.js.map +1 -0
- package/lib/module/utils/copyToComputer.js +91 -0
- package/lib/module/utils/copyToComputer.js.map +1 -0
- package/lib/module/utils/createEventChannel.js +17 -0
- package/lib/module/utils/createEventChannel.js.map +1 -0
- package/lib/module/utils/createObservableStore.js +34 -0
- package/lib/module/utils/createObservableStore.js.map +1 -0
- package/lib/module/utils/safeStringify.js +23 -0
- package/lib/module/utils/safeStringify.js.map +1 -0
- package/lib/typescript/src/components/ClipboardTab.d.ts +4 -0
- package/lib/typescript/src/components/ClipboardTab.d.ts.map +1 -0
- package/lib/typescript/src/components/ConsoleLogTab.d.ts +4 -0
- package/lib/typescript/src/components/ConsoleLogTab.d.ts.map +1 -0
- package/lib/typescript/src/components/EnvironmentTab.d.ts +4 -0
- package/lib/typescript/src/components/EnvironmentTab.d.ts.map +1 -0
- package/lib/typescript/src/components/FloatPanelView.d.ts +64 -0
- package/lib/typescript/src/components/FloatPanelView.d.ts.map +1 -0
- package/lib/typescript/src/components/NavigationLogTab.d.ts +4 -0
- package/lib/typescript/src/components/NavigationLogTab.d.ts.map +1 -0
- package/lib/typescript/src/components/NetworkLogTab.d.ts +4 -0
- package/lib/typescript/src/components/NetworkLogTab.d.ts.map +1 -0
- package/lib/typescript/src/components/ThirdPartyLibsTab.d.ts +4 -0
- package/lib/typescript/src/components/ThirdPartyLibsTab.d.ts.map +1 -0
- package/lib/typescript/src/components/TrackLogTab.d.ts +4 -0
- package/lib/typescript/src/components/TrackLogTab.d.ts.map +1 -0
- package/lib/typescript/src/components/ZustandLogTab.d.ts +4 -0
- package/lib/typescript/src/components/ZustandLogTab.d.ts.map +1 -0
- package/lib/typescript/src/components/shared/CollapsibleSection.d.ts +9 -0
- package/lib/typescript/src/components/shared/CollapsibleSection.d.ts.map +1 -0
- package/lib/typescript/src/components/shared/CopyButton.d.ts +12 -0
- package/lib/typescript/src/components/shared/CopyButton.d.ts.map +1 -0
- package/lib/typescript/src/components/shared/JsonView.d.ts +6 -0
- package/lib/typescript/src/components/shared/JsonView.d.ts.map +1 -0
- package/lib/typescript/src/core/DebugToolkit.d.ts +27 -0
- package/lib/typescript/src/core/DebugToolkit.d.ts.map +1 -0
- package/lib/typescript/src/core/DebugToolkitProvider.d.ts +18 -0
- package/lib/typescript/src/core/DebugToolkitProvider.d.ts.map +1 -0
- package/lib/typescript/src/features/ClipboardFeature.d.ts +3 -0
- package/lib/typescript/src/features/ClipboardFeature.d.ts.map +1 -0
- package/lib/typescript/src/features/ConsoleLogFeature.d.ts +7 -0
- package/lib/typescript/src/features/ConsoleLogFeature.d.ts.map +1 -0
- package/lib/typescript/src/features/EnvironmentFeature.d.ts +8 -0
- package/lib/typescript/src/features/EnvironmentFeature.d.ts.map +1 -0
- package/lib/typescript/src/features/NavigationLogFeature.d.ts +8 -0
- package/lib/typescript/src/features/NavigationLogFeature.d.ts.map +1 -0
- package/lib/typescript/src/features/NetworkFeature.d.ts +28 -0
- package/lib/typescript/src/features/NetworkFeature.d.ts.map +1 -0
- package/lib/typescript/src/features/ThirdPartyLibsFeature.d.ts +3 -0
- package/lib/typescript/src/features/ThirdPartyLibsFeature.d.ts.map +1 -0
- package/lib/typescript/src/features/TrackFeature.d.ts +12 -0
- package/lib/typescript/src/features/TrackFeature.d.ts.map +1 -0
- package/lib/typescript/src/features/ZustandLogFeature.d.ts +29 -0
- package/lib/typescript/src/features/ZustandLogFeature.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useNavigationLogger.d.ts +20 -0
- package/lib/typescript/src/hooks/useNavigationLogger.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useSlideDetailAnimation.d.ts +11 -0
- package/lib/typescript/src/hooks/useSlideDetailAnimation.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +26 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/initialize.d.ts +51 -0
- package/lib/typescript/src/initialize.d.ts.map +1 -0
- package/lib/typescript/src/native/NativeDebugLibs.d.ts +11 -0
- package/lib/typescript/src/native/NativeDebugLibs.d.ts.map +1 -0
- package/lib/typescript/src/types/index.d.ts +112 -0
- package/lib/typescript/src/types/index.d.ts.map +1 -0
- package/lib/typescript/src/utils/constants.d.ts +96 -0
- package/lib/typescript/src/utils/constants.d.ts.map +1 -0
- package/lib/typescript/src/utils/copyToComputer.d.ts +30 -0
- package/lib/typescript/src/utils/copyToComputer.d.ts.map +1 -0
- package/lib/typescript/src/utils/createEventChannel.d.ts +7 -0
- package/lib/typescript/src/utils/createEventChannel.d.ts.map +1 -0
- package/lib/typescript/src/utils/createObservableStore.d.ts +9 -0
- package/lib/typescript/src/utils/createObservableStore.d.ts.map +1 -0
- package/lib/typescript/src/utils/safeStringify.d.ts +6 -0
- package/lib/typescript/src/utils/safeStringify.d.ts.map +1 -0
- package/package.json +63 -24
- package/src/components/ClipboardTab.tsx +81 -0
- package/src/components/ConsoleLogTab.tsx +209 -0
- package/src/components/EnvironmentTab.tsx +276 -0
- package/src/components/FloatPanelView.tsx +714 -0
- package/src/components/NavigationLogTab.tsx +66 -0
- package/src/components/NetworkLogTab.tsx +411 -0
- package/src/components/ThirdPartyLibsTab.tsx +63 -0
- package/src/components/TrackLogTab.tsx +245 -0
- package/src/components/ZustandLogTab.tsx +305 -0
- package/src/components/shared/CollapsibleSection.tsx +78 -0
- package/src/components/shared/CopyButton.tsx +68 -0
- package/src/components/shared/JsonView.tsx +125 -0
- package/src/core/DebugToolkit.tsx +174 -0
- package/src/core/DebugToolkitProvider.tsx +89 -0
- package/src/features/ClipboardFeature.ts +11 -0
- package/src/features/ConsoleLogFeature.ts +118 -0
- package/src/features/EnvironmentFeature.ts +194 -0
- package/src/features/NavigationLogFeature.ts +74 -0
- package/src/features/NetworkFeature.ts +488 -0
- package/src/features/ThirdPartyLibsFeature.ts +42 -0
- package/src/features/TrackFeature.ts +69 -0
- package/src/features/ZustandLogFeature.ts +127 -0
- package/src/hooks/useNavigationLogger.ts +107 -0
- package/src/hooks/useSlideDetailAnimation.ts +45 -0
- package/src/index.ts +52 -0
- package/src/initialize.ts +214 -0
- package/src/native/NativeDebugLibs.ts +74 -0
- package/src/types/index.ts +138 -0
- package/src/utils/constants.ts +91 -0
- package/src/utils/copyToComputer.ts +104 -0
- package/src/utils/createEventChannel.ts +22 -0
- package/src/utils/createObservableStore.ts +42 -0
- package/src/utils/safeStringify.ts +25 -0
- package/.cursor/rules/react-native.mdc +0 -41
- package/README.zh-CN.md +0 -230
- package/android/build.gradle +0 -34
- package/android/src/main/AndroidManifest.xml +0 -8
- package/android/src/main/java/com/reactnative/debuglibs/BuildTypeModule.java +0 -44
- package/android/src/main/java/com/reactnative/debuglibs/BuildTypePackage.java +0 -25
- package/android/src/main/java/com/reactnative/debuglibs/RNDebugLibsModule.java +0 -75
- package/android/src/main/java/com/reactnative/debuglibs/RNDebugLibsPackage.java +0 -28
- package/index.js +0 -41
- package/ios/BuildTypeModule.h +0 -9
- package/ios/BuildTypeModule.m +0 -42
- package/ios/RNDebugLibs.h +0 -10
- package/ios/RNDebugLibs.m +0 -79
- package/lib/DebugToolKit.js +0 -126
- package/lib/EnvironmentManager.ts +0 -80
- package/lib/NativeDebugLibs.js +0 -67
- package/lib/features/ConsoleLogFeature.js +0 -70
- package/lib/features/NavigationLogFeature.js +0 -45
- package/lib/features/NetworkFeature.js +0 -389
- package/lib/features/PerformanceFeature.js +0 -390
- package/lib/features/ThirdPartyLibsFeature.js +0 -63
- package/lib/features/TrackFeature.js +0 -94
- package/lib/features/ZustandLogFeature.js +0 -44
- package/lib/hooks/useNavigationLogger.js +0 -92
- package/lib/index.js +0 -114
- package/lib/navigation/NavigationLogger.js +0 -1
- package/lib/types/TrackTypes.ts +0 -92
- package/lib/utils/DebugConst.js +0 -67
- package/lib/utils/StorageUtils.js +0 -80
- package/lib/views/ConsoleLogDetails.js +0 -314
- package/lib/views/FloatPanelView.js +0 -697
- package/lib/views/HttpLogDetails.js +0 -648
- package/lib/views/NavigationLogDetails.js +0 -302
- package/lib/views/RestartModal.js +0 -75
- package/lib/views/SubViewConsoleLogs.js +0 -209
- package/lib/views/SubViewEnvironment.js +0 -73
- package/lib/views/SubViewHTTPLogs.js +0 -235
- package/lib/views/SubViewNavigationLogs.js +0 -199
- package/lib/views/SubViewPerformance.js +0 -515
- package/lib/views/SubViewThirdPartyLibs.js +0 -239
- package/lib/views/SubViewTrackLogs.js +0 -318
- package/lib/views/SubViewZustandLogs.js +0 -279
- package/lib/views/TabView.js +0 -66
- package/lib/views/TrackLogDetails.js +0 -481
- package/lib/views/ZustandLogDetails.js +0 -355
- package/react-native-debug-toolkit.podspec +0 -25
- package/react-native.config.js +0 -18
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
const MAX_LOGS = 200; // Max number of console logs to store
|
|
2
|
-
const logs = [];
|
|
3
|
-
const originalConsole = {}; // Store original console methods
|
|
4
|
-
|
|
5
|
-
const _interceptConsole = () => {
|
|
6
|
-
const levels = ['log', 'info', 'warn', 'error'];
|
|
7
|
-
levels.forEach(level => {
|
|
8
|
-
if (typeof console[level] === 'function') { // Check if it's actually a function
|
|
9
|
-
originalConsole[level] = console[level]; // Store original
|
|
10
|
-
|
|
11
|
-
console[level] = (...args) => {
|
|
12
|
-
// Call original console method first
|
|
13
|
-
originalConsole[level].apply(console, args); // Use apply for proper context
|
|
14
|
-
|
|
15
|
-
// Add log entry
|
|
16
|
-
if (logs.length >= MAX_LOGS) {
|
|
17
|
-
logs.shift(); // Remove the oldest log if limit is reached
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Store log data
|
|
21
|
-
logs.push({
|
|
22
|
-
timestamp: new Date(),
|
|
23
|
-
level: level,
|
|
24
|
-
data: args, // Store all arguments passed to console[level]
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// TODO: Notify UI if needed
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const _restoreConsole = () => {
|
|
34
|
-
Object.keys(originalConsole).forEach(level => {
|
|
35
|
-
if (originalConsole[level]) {
|
|
36
|
-
console[level] = originalConsole[level];
|
|
37
|
-
delete originalConsole[level]; // Clean up stored method
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const setup = () => {
|
|
43
|
-
_interceptConsole();
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const getData = () => {
|
|
47
|
-
return logs;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const cleanup = () => {
|
|
51
|
-
_restoreConsole();
|
|
52
|
-
logs.length = 0; // More efficient way to clear array
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// Factory function remains similar but uses the module-level functions
|
|
56
|
-
export const createConsoleLogFeature = () => {
|
|
57
|
-
// Ensure setup is only called once if multiple features might be created (though unlikely for console)
|
|
58
|
-
// A simple flag could work here if needed, but maybe setup belongs in the main toolkit init.
|
|
59
|
-
return {
|
|
60
|
-
name: 'console',
|
|
61
|
-
label: 'Console Logs',
|
|
62
|
-
setup: setup, // Reference module-level function
|
|
63
|
-
getData: getData, // Reference module-level function
|
|
64
|
-
cleanup: cleanup, // Reference module-level function
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
// Note: This refactor removes the class structure entirely, relying on module scope
|
|
69
|
-
// for the "singleton" nature. Decide if this fits the overall pattern of other features.
|
|
70
|
-
// The original class-based singleton is also perfectly valid.
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
const MAX_LOGS = 200; // Max number of navigation logs to store
|
|
2
|
-
const logs = [];
|
|
3
|
-
const originalNavigationMethods = {}; // Store original navigation methods
|
|
4
|
-
|
|
5
|
-
const setup = () => {
|
|
6
|
-
// Note: Actual navigation interception will be done in the main app code
|
|
7
|
-
// This is just a setup function for compatibility with the feature API
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
// Function to add navigation log
|
|
11
|
-
export const addNavigationLog = (action, from, to, startTime, duration, debugLog) => {
|
|
12
|
-
// Store log data
|
|
13
|
-
logs.push({
|
|
14
|
-
timestamp: new Date(),
|
|
15
|
-
action: action, // push, pop, replace, etc.
|
|
16
|
-
from: from, // source route info
|
|
17
|
-
to: to, // destination route info
|
|
18
|
-
startTime: startTime,
|
|
19
|
-
duration: duration,
|
|
20
|
-
debugLog: debugLog,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
// Trim logs if they exceed the maximum limit
|
|
24
|
-
if (logs.length > MAX_LOGS) {
|
|
25
|
-
logs.splice(0, logs.length - MAX_LOGS);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const getData = () => {
|
|
30
|
-
return logs;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const cleanup = () => {
|
|
34
|
-
logs.length = 0; // Clear array
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export const createNavigationLogFeature = () => {
|
|
38
|
-
return {
|
|
39
|
-
name: 'navigation',
|
|
40
|
-
label: 'Navigation Logs',
|
|
41
|
-
setup: setup,
|
|
42
|
-
getData: getData,
|
|
43
|
-
cleanup: cleanup,
|
|
44
|
-
};
|
|
45
|
-
};
|
|
@@ -1,389 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
|
|
3
|
-
class NetworkFeature {
|
|
4
|
-
static instance = null
|
|
5
|
-
static MAX_LOGS = 200
|
|
6
|
-
|
|
7
|
-
constructor() {
|
|
8
|
-
if (NetworkFeature.instance) {
|
|
9
|
-
return NetworkFeature.instance
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
this.logs = []
|
|
13
|
-
this.pendingAxiosRequests = new Map()
|
|
14
|
-
this.originalFetch = null
|
|
15
|
-
this.blacklist = [] // URL patterns to exclude from logging
|
|
16
|
-
|
|
17
|
-
NetworkFeature.instance = this
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
setup() {
|
|
21
|
-
|
|
22
|
-
// this._interceptFetch()
|
|
23
|
-
return this
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
getData() {
|
|
27
|
-
return this.logs
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
cleanup() {
|
|
31
|
-
if (this.originalFetch) {
|
|
32
|
-
global.fetch = this.originalFetch
|
|
33
|
-
this.originalFetch = null
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
this.logs = []
|
|
37
|
-
this.pendingAxiosRequests.clear()
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Check if a URL matches any pattern in the blacklist
|
|
41
|
-
isUrlBlacklisted(url) {
|
|
42
|
-
if (!url) return false
|
|
43
|
-
|
|
44
|
-
return this.blacklist.some(pattern => {
|
|
45
|
-
if (pattern instanceof RegExp) {
|
|
46
|
-
return pattern.test(url)
|
|
47
|
-
}
|
|
48
|
-
return url.includes(pattern)
|
|
49
|
-
})
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Add a URL pattern to blacklist
|
|
53
|
-
addUrlToBlacklist(pattern) {
|
|
54
|
-
if (!this.blacklist.some(p =>
|
|
55
|
-
(p instanceof RegExp && pattern instanceof RegExp) ?
|
|
56
|
-
p.toString() === pattern.toString() : p === pattern)) {
|
|
57
|
-
this.blacklist.push(pattern)
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Remove a URL pattern from blacklist
|
|
62
|
-
removeUrlFromBlacklist(pattern) {
|
|
63
|
-
this.blacklist = this.blacklist.filter(p =>
|
|
64
|
-
(p instanceof RegExp && pattern instanceof RegExp) ?
|
|
65
|
-
p.toString() !== pattern.toString() : p !== pattern)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Clear all patterns from blacklist
|
|
69
|
-
clearBlacklist() {
|
|
70
|
-
this.blacklist = []
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
setupAxiosInterceptors(axiosInstance) {
|
|
74
|
-
|
|
75
|
-
axiosInstance.interceptors.request.use(
|
|
76
|
-
(config) => {
|
|
77
|
-
// Generate a unique ID if one doesn't exist
|
|
78
|
-
if (!config.headers) {
|
|
79
|
-
config.headers = {}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (!config.headers['X-Request-Id']) {
|
|
83
|
-
config.headers['X-Request-Id'] =
|
|
84
|
-
Date.now().toString() + Math.random().toString(36).substring(2, 10)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const trackId = config.headers['X-Request-Id']
|
|
88
|
-
this.pendingAxiosRequests.set(trackId, {
|
|
89
|
-
timestamp: new Date(),
|
|
90
|
-
startTime: Date.now(),
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
return config
|
|
94
|
-
},
|
|
95
|
-
(error) => {
|
|
96
|
-
this.logAxiosError(error)
|
|
97
|
-
return Promise.reject(error)
|
|
98
|
-
},
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
axiosInstance.interceptors.response.use(
|
|
102
|
-
(response) => {
|
|
103
|
-
this.logAxiosResponse(response)
|
|
104
|
-
return response
|
|
105
|
-
},
|
|
106
|
-
(error) => {
|
|
107
|
-
this.logAxiosError(error)
|
|
108
|
-
return Promise.reject(error)
|
|
109
|
-
},
|
|
110
|
-
)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
logAxiosResponse(response) {
|
|
114
|
-
if (!response || !response.config || !response.config.headers) {
|
|
115
|
-
return
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const trackId = response.config.headers['X-Request-Id']
|
|
119
|
-
const pendingRequest = this.pendingAxiosRequests.get(trackId)
|
|
120
|
-
|
|
121
|
-
if (!pendingRequest) {
|
|
122
|
-
return
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const url = `${response.config.baseURL || ''}${response.config.url}`
|
|
126
|
-
|
|
127
|
-
// Skip logging if URL is blacklisted
|
|
128
|
-
if (this.isUrlBlacklisted(url)) {
|
|
129
|
-
this.pendingAxiosRequests.delete(trackId)
|
|
130
|
-
return
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (this.logs.length >= NetworkFeature.MAX_LOGS) {
|
|
134
|
-
this.logs.shift()
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// Calculate duration
|
|
138
|
-
const duration = Date.now() - pendingRequest.startTime
|
|
139
|
-
|
|
140
|
-
const logEntry = {
|
|
141
|
-
timestamp: pendingRequest.timestamp,
|
|
142
|
-
duration: Math.round(duration),
|
|
143
|
-
request: {
|
|
144
|
-
url: url,
|
|
145
|
-
method: response.config.method?.toUpperCase() || 'GET',
|
|
146
|
-
headers: response.config.headers,
|
|
147
|
-
body: response.config.data || response.config.params,
|
|
148
|
-
},
|
|
149
|
-
response: {
|
|
150
|
-
status: response.status,
|
|
151
|
-
statusText: response.statusText,
|
|
152
|
-
headers: response.headers,
|
|
153
|
-
},
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (response.data && typeof response.data === 'object') {
|
|
157
|
-
logEntry.response.success = response.data.success !== false
|
|
158
|
-
logEntry.response.data = response.data
|
|
159
|
-
} else {
|
|
160
|
-
logEntry.response.success =
|
|
161
|
-
response.status >= 200 && response.status < 300
|
|
162
|
-
|
|
163
|
-
if (response.data) {
|
|
164
|
-
logEntry.response.data = response.data
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
this.logs.push(logEntry)
|
|
169
|
-
this.pendingAxiosRequests.delete(trackId)
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
logAxiosError(error) {
|
|
173
|
-
if (!error.config) {
|
|
174
|
-
return
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (!error.config.headers) {
|
|
178
|
-
error.config.headers = {}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const trackId = error.config.headers['X-Request-Id']
|
|
182
|
-
const pendingRequest = this.pendingAxiosRequests.get(trackId)
|
|
183
|
-
|
|
184
|
-
const startTime = pendingRequest
|
|
185
|
-
? pendingRequest.startTime
|
|
186
|
-
: Date.now() - 100
|
|
187
|
-
|
|
188
|
-
const url = `${error.config.baseURL || ''}${error.config.url}`
|
|
189
|
-
|
|
190
|
-
// Skip logging if URL is blacklisted
|
|
191
|
-
if (this.isUrlBlacklisted(url)) {
|
|
192
|
-
this.pendingAxiosRequests.delete(trackId)
|
|
193
|
-
return
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (this.logs.length >= NetworkFeature.MAX_LOGS) {
|
|
197
|
-
this.logs.shift()
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const duration = Date.now() - startTime
|
|
201
|
-
|
|
202
|
-
const logEntry = {
|
|
203
|
-
timestamp: pendingRequest ? pendingRequest.timestamp : new Date(),
|
|
204
|
-
duration: Math.round(duration),
|
|
205
|
-
request: {
|
|
206
|
-
url: url,
|
|
207
|
-
method: error.config.method?.toUpperCase() || 'GET',
|
|
208
|
-
headers: error.config.headers,
|
|
209
|
-
body: error.config.data || error.config.params,
|
|
210
|
-
},
|
|
211
|
-
error: error.message,
|
|
212
|
-
success: false,
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
if (error.response && error.response.data) {
|
|
216
|
-
logEntry.response = {
|
|
217
|
-
status: error.response.status,
|
|
218
|
-
statusText: error.response.statusText,
|
|
219
|
-
headers: error.response.headers,
|
|
220
|
-
data: error.response.data,
|
|
221
|
-
success: false,
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
this.logs.push(logEntry)
|
|
226
|
-
this.pendingAxiosRequests.delete(trackId)
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
_interceptFetch() {
|
|
230
|
-
|
|
231
|
-
this.originalFetch = global.fetch
|
|
232
|
-
|
|
233
|
-
global.fetch = async (...args) => {
|
|
234
|
-
const request = args[0]
|
|
235
|
-
const options = args[1] || {}
|
|
236
|
-
const startTime = Date.now()
|
|
237
|
-
|
|
238
|
-
try {
|
|
239
|
-
const response = await this.originalFetch(...args)
|
|
240
|
-
this._logFetchResponse(request, options, response.clone(), startTime)
|
|
241
|
-
return response
|
|
242
|
-
} catch (error) {
|
|
243
|
-
this._logFetchError(request, options, error, startTime)
|
|
244
|
-
throw error
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
_logFetchResponse(request, options, response, startTime) {
|
|
250
|
-
const requestUrl = typeof request === 'string' ? request : request.url
|
|
251
|
-
|
|
252
|
-
// Skip logging if URL is blacklisted
|
|
253
|
-
if (this.isUrlBlacklisted(requestUrl)) {
|
|
254
|
-
return
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
if (this.logs.length >= NetworkFeature.MAX_LOGS) {
|
|
258
|
-
this.logs.shift()
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
const duration = Date.now() - startTime
|
|
262
|
-
|
|
263
|
-
const commonData = {
|
|
264
|
-
timestamp: new Date(),
|
|
265
|
-
duration: Math.round(duration),
|
|
266
|
-
request: {
|
|
267
|
-
url: requestUrl,
|
|
268
|
-
method: options.method || 'GET',
|
|
269
|
-
headers: options.headers || {},
|
|
270
|
-
body: options.body,
|
|
271
|
-
},
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// Try to parse JSON response
|
|
275
|
-
response
|
|
276
|
-
.text()
|
|
277
|
-
.then((text) => {
|
|
278
|
-
let responseData
|
|
279
|
-
let success = response.status >= 200 && response.status < 300
|
|
280
|
-
|
|
281
|
-
try {
|
|
282
|
-
// Try to parse as JSON
|
|
283
|
-
if (text) {
|
|
284
|
-
responseData = JSON.parse(text)
|
|
285
|
-
|
|
286
|
-
// Use API success flag if available
|
|
287
|
-
if (responseData && typeof responseData.success !== 'undefined') {
|
|
288
|
-
success = !!responseData.success
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
} catch (e) {
|
|
292
|
-
// Not JSON, use text response
|
|
293
|
-
responseData = text
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
const logEntry = {
|
|
297
|
-
...commonData,
|
|
298
|
-
response: {
|
|
299
|
-
status: response.status,
|
|
300
|
-
statusText: response.statusText,
|
|
301
|
-
headers: this._headersToObject(response.headers),
|
|
302
|
-
data: responseData,
|
|
303
|
-
success: success,
|
|
304
|
-
},
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
this.logs.push(logEntry)
|
|
308
|
-
})
|
|
309
|
-
.catch((err) => {
|
|
310
|
-
// Fallback for when we can't read the response body
|
|
311
|
-
const logEntry = {
|
|
312
|
-
...commonData,
|
|
313
|
-
response: {
|
|
314
|
-
status: response.status,
|
|
315
|
-
statusText: response.statusText,
|
|
316
|
-
headers: this._headersToObject(response.headers),
|
|
317
|
-
success: response.status >= 200 && response.status < 300,
|
|
318
|
-
},
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
this.logs.push(logEntry)
|
|
322
|
-
})
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
_logFetchError(request, options, error, startTime) {
|
|
326
|
-
const requestUrl = typeof request === 'string' ? request : request.url
|
|
327
|
-
|
|
328
|
-
// Skip logging if URL is blacklisted
|
|
329
|
-
if (this.isUrlBlacklisted(requestUrl)) {
|
|
330
|
-
return
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
if (this.logs.length >= NetworkFeature.MAX_LOGS) {
|
|
334
|
-
this.logs.shift()
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
const duration = Date.now() - startTime
|
|
338
|
-
|
|
339
|
-
this.logs.push({
|
|
340
|
-
timestamp: new Date(),
|
|
341
|
-
duration: Math.round(duration),
|
|
342
|
-
request: {
|
|
343
|
-
url: requestUrl,
|
|
344
|
-
method: options.method || 'GET',
|
|
345
|
-
headers: options.headers || {},
|
|
346
|
-
body: options.body,
|
|
347
|
-
},
|
|
348
|
-
error: error.message,
|
|
349
|
-
success: false,
|
|
350
|
-
})
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
// Utility to convert Headers object to plain object
|
|
354
|
-
_headersToObject(headers) {
|
|
355
|
-
const result = {}
|
|
356
|
-
|
|
357
|
-
if (headers && typeof headers.forEach === 'function') {
|
|
358
|
-
headers.forEach((value, key) => {
|
|
359
|
-
result[key] = value
|
|
360
|
-
})
|
|
361
|
-
} else if (headers) {
|
|
362
|
-
// Fallback for non-standard headers object
|
|
363
|
-
Object.keys(headers).forEach((key) => {
|
|
364
|
-
result[key] = headers[key]
|
|
365
|
-
})
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
return result
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
export const createNetworkFeature = () => {
|
|
373
|
-
const feature = new NetworkFeature()
|
|
374
|
-
|
|
375
|
-
return {
|
|
376
|
-
name: 'network',
|
|
377
|
-
label: 'Network Logs',
|
|
378
|
-
setup: () => feature.setup(),
|
|
379
|
-
getData: () => feature.getData(),
|
|
380
|
-
cleanup: () => feature.cleanup(),
|
|
381
|
-
setupAxiosInterceptors: (axiosInstance) =>
|
|
382
|
-
feature.setupAxiosInterceptors(axiosInstance),
|
|
383
|
-
// Expose blacklist management methods
|
|
384
|
-
addUrlToBlacklist: (pattern) => feature.addUrlToBlacklist(pattern),
|
|
385
|
-
removeUrlFromBlacklist: (pattern) => feature.removeUrlFromBlacklist(pattern),
|
|
386
|
-
clearBlacklist: () => feature.clearBlacklist(),
|
|
387
|
-
getBlacklist: () => feature.blacklist,
|
|
388
|
-
}
|
|
389
|
-
}
|