react-native-debug-toolkit 2.0.0 → 2.1.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/README.md +72 -72
- package/README.zh-CN.md +209 -0
- package/lib/commonjs/components/ClipboardTab.js +15 -16
- package/lib/commonjs/components/ClipboardTab.js.map +1 -1
- package/lib/commonjs/components/ConsoleLogTab.js +69 -202
- package/lib/commonjs/components/ConsoleLogTab.js.map +1 -1
- package/lib/commonjs/components/DebugPanel.js +230 -0
- package/lib/commonjs/components/DebugPanel.js.map +1 -0
- package/lib/commonjs/components/DebugView.js +66 -0
- package/lib/commonjs/components/DebugView.js.map +1 -0
- package/lib/commonjs/components/EnvironmentTab.js +22 -23
- package/lib/commonjs/components/EnvironmentTab.js.map +1 -1
- package/lib/commonjs/components/FeatureTabBar.js +182 -0
- package/lib/commonjs/components/FeatureTabBar.js.map +1 -0
- package/lib/commonjs/components/FloatIcon.js +187 -0
- package/lib/commonjs/components/FloatIcon.js.map +1 -0
- package/lib/commonjs/components/FloatPanelView.js +140 -723
- package/lib/commonjs/components/FloatPanelView.js.map +1 -1
- package/lib/commonjs/components/NavigationLogTab.js +8 -8
- package/lib/commonjs/components/NavigationLogTab.js.map +1 -1
- package/lib/commonjs/components/NetworkLogTab.js +179 -350
- package/lib/commonjs/components/NetworkLogTab.js.map +1 -1
- package/lib/commonjs/components/ThirdPartyLibsTab.js +8 -8
- package/lib/commonjs/components/ThirdPartyLibsTab.js.map +1 -1
- package/lib/commonjs/components/TrackLogTab.js +106 -248
- package/lib/commonjs/components/TrackLogTab.js.map +1 -1
- package/lib/commonjs/components/ZustandLogTab.js +148 -288
- package/lib/commonjs/components/ZustandLogTab.js.map +1 -1
- package/lib/commonjs/components/shared/CollapsibleSection.js +4 -4
- package/lib/commonjs/components/shared/CollapsibleSection.js.map +1 -1
- package/lib/commonjs/components/shared/CopyButton.js +3 -3
- package/lib/commonjs/components/shared/CopyButton.js.map +1 -1
- package/lib/commonjs/components/shared/LogListScreen.js +174 -0
- package/lib/commonjs/components/shared/LogListScreen.js.map +1 -0
- package/lib/commonjs/core/DebugToolkit.js +92 -112
- package/lib/commonjs/core/DebugToolkit.js.map +1 -1
- package/lib/commonjs/core/DebugToolkitProvider.js +30 -28
- package/lib/commonjs/core/DebugToolkitProvider.js.map +1 -1
- package/lib/commonjs/features/ClipboardFeature.js +6 -2
- package/lib/commonjs/features/ClipboardFeature.js.map +1 -1
- package/lib/commonjs/features/ConsoleLogFeature.js +66 -49
- package/lib/commonjs/features/ConsoleLogFeature.js.map +1 -1
- package/lib/commonjs/features/EnvironmentFeature.js +5 -13
- package/lib/commonjs/features/EnvironmentFeature.js.map +1 -1
- package/lib/commonjs/features/NavigationLogFeature.js +17 -38
- package/lib/commonjs/features/NavigationLogFeature.js.map +1 -1
- package/lib/commonjs/features/NetworkFeature.js +35 -256
- package/lib/commonjs/features/NetworkFeature.js.map +1 -1
- package/lib/commonjs/features/TrackFeature.js +17 -38
- package/lib/commonjs/features/TrackFeature.js.map +1 -1
- package/lib/commonjs/features/ZustandLogFeature.js +21 -38
- package/lib/commonjs/features/ZustandLogFeature.js.map +1 -1
- package/lib/commonjs/hooks/useNavigationLogger.js.map +1 -1
- package/lib/commonjs/index.js +7 -20
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/initialize.js +19 -96
- package/lib/commonjs/initialize.js.map +1 -1
- package/lib/commonjs/interceptors/networkInterceptor.js +466 -0
- package/lib/commonjs/interceptors/networkInterceptor.js.map +1 -0
- package/lib/commonjs/utils/colors.js +48 -0
- package/lib/commonjs/utils/colors.js.map +1 -0
- package/lib/commonjs/utils/createChannelFeature.js +48 -0
- package/lib/commonjs/utils/createChannelFeature.js.map +1 -0
- package/lib/commonjs/utils/layout.js +8 -0
- package/lib/commonjs/utils/layout.js.map +1 -0
- package/lib/commonjs/utils/urlRewriterRegistry.js +14 -0
- package/lib/commonjs/utils/urlRewriterRegistry.js.map +1 -0
- package/lib/module/components/ClipboardTab.js +8 -8
- package/lib/module/components/ClipboardTab.js.map +1 -1
- package/lib/module/components/ConsoleLogTab.js +66 -199
- package/lib/module/components/ConsoleLogTab.js.map +1 -1
- package/lib/module/components/DebugPanel.js +225 -0
- package/lib/module/components/DebugPanel.js.map +1 -0
- package/lib/module/components/DebugView.js +61 -0
- package/lib/module/components/DebugView.js.map +1 -0
- package/lib/module/components/EnvironmentTab.js +3 -3
- package/lib/module/components/EnvironmentTab.js.map +1 -1
- package/lib/module/components/FeatureTabBar.js +177 -0
- package/lib/module/components/FeatureTabBar.js.map +1 -0
- package/lib/module/components/FloatIcon.js +182 -0
- package/lib/module/components/FloatIcon.js.map +1 -0
- package/lib/module/components/FloatPanelView.js +141 -723
- package/lib/module/components/FloatPanelView.js.map +1 -1
- package/lib/module/components/NavigationLogTab.js +1 -1
- package/lib/module/components/NavigationLogTab.js.map +1 -1
- package/lib/module/components/NetworkLogTab.js +167 -338
- package/lib/module/components/NetworkLogTab.js.map +1 -1
- package/lib/module/components/ThirdPartyLibsTab.js +1 -1
- package/lib/module/components/ThirdPartyLibsTab.js.map +1 -1
- package/lib/module/components/TrackLogTab.js +94 -236
- package/lib/module/components/TrackLogTab.js.map +1 -1
- package/lib/module/components/ZustandLogTab.js +136 -276
- package/lib/module/components/ZustandLogTab.js.map +1 -1
- package/lib/module/components/shared/CollapsibleSection.js +1 -1
- package/lib/module/components/shared/CollapsibleSection.js.map +1 -1
- package/lib/module/components/shared/CopyButton.js +1 -1
- package/lib/module/components/shared/CopyButton.js.map +1 -1
- package/lib/module/components/shared/LogListScreen.js +169 -0
- package/lib/module/components/shared/LogListScreen.js.map +1 -0
- package/lib/module/core/DebugToolkit.js +92 -111
- package/lib/module/core/DebugToolkit.js.map +1 -1
- package/lib/module/core/DebugToolkitProvider.js +31 -29
- package/lib/module/core/DebugToolkitProvider.js.map +1 -1
- package/lib/module/features/ClipboardFeature.js +6 -2
- package/lib/module/features/ClipboardFeature.js.map +1 -1
- package/lib/module/features/ConsoleLogFeature.js +65 -49
- package/lib/module/features/ConsoleLogFeature.js.map +1 -1
- package/lib/module/features/EnvironmentFeature.js +5 -13
- package/lib/module/features/EnvironmentFeature.js.map +1 -1
- package/lib/module/features/NavigationLogFeature.js +16 -38
- package/lib/module/features/NavigationLogFeature.js.map +1 -1
- package/lib/module/features/NetworkFeature.js +34 -255
- package/lib/module/features/NetworkFeature.js.map +1 -1
- package/lib/module/features/TrackFeature.js +16 -38
- package/lib/module/features/TrackFeature.js.map +1 -1
- package/lib/module/features/ZustandLogFeature.js +22 -38
- package/lib/module/features/ZustandLogFeature.js.map +1 -1
- package/lib/module/hooks/useNavigationLogger.js.map +1 -1
- package/lib/module/index.js +2 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/initialize.js +19 -95
- package/lib/module/initialize.js.map +1 -1
- package/lib/module/interceptors/networkInterceptor.js +460 -0
- package/lib/module/interceptors/networkInterceptor.js.map +1 -0
- package/lib/module/utils/colors.js +43 -0
- package/lib/module/utils/colors.js.map +1 -0
- package/lib/module/utils/createChannelFeature.js +44 -0
- package/lib/module/utils/createChannelFeature.js.map +1 -0
- package/lib/module/utils/layout.js +4 -0
- package/lib/module/utils/layout.js.map +1 -0
- package/lib/module/utils/urlRewriterRegistry.js +10 -0
- package/lib/module/utils/urlRewriterRegistry.js.map +1 -0
- package/lib/typescript/src/components/ClipboardTab.d.ts.map +1 -1
- package/lib/typescript/src/components/ConsoleLogTab.d.ts.map +1 -1
- package/lib/typescript/src/components/DebugPanel.d.ts +9 -0
- package/lib/typescript/src/components/DebugPanel.d.ts.map +1 -0
- package/lib/typescript/src/components/DebugView.d.ts +19 -0
- package/lib/typescript/src/components/DebugView.d.ts.map +1 -0
- package/lib/typescript/src/components/EnvironmentTab.d.ts.map +1 -1
- package/lib/typescript/src/components/FeatureTabBar.d.ts +13 -0
- package/lib/typescript/src/components/FeatureTabBar.d.ts.map +1 -0
- package/lib/typescript/src/components/FloatIcon.d.ts +12 -0
- package/lib/typescript/src/components/FloatIcon.d.ts.map +1 -0
- package/lib/typescript/src/components/FloatPanelView.d.ts +4 -59
- package/lib/typescript/src/components/FloatPanelView.d.ts.map +1 -1
- package/lib/typescript/src/components/NetworkLogTab.d.ts.map +1 -1
- package/lib/typescript/src/components/ThirdPartyLibsTab.d.ts.map +1 -1
- package/lib/typescript/src/components/TrackLogTab.d.ts.map +1 -1
- package/lib/typescript/src/components/ZustandLogTab.d.ts.map +1 -1
- package/lib/typescript/src/components/shared/LogListScreen.d.ts +21 -0
- package/lib/typescript/src/components/shared/LogListScreen.d.ts.map +1 -0
- package/lib/typescript/src/core/DebugToolkit.d.ts +11 -18
- package/lib/typescript/src/core/DebugToolkit.d.ts.map +1 -1
- package/lib/typescript/src/core/DebugToolkitProvider.d.ts +2 -5
- package/lib/typescript/src/core/DebugToolkitProvider.d.ts.map +1 -1
- package/lib/typescript/src/features/ClipboardFeature.d.ts +4 -0
- package/lib/typescript/src/features/ClipboardFeature.d.ts.map +1 -1
- package/lib/typescript/src/features/ConsoleLogFeature.d.ts +2 -0
- package/lib/typescript/src/features/ConsoleLogFeature.d.ts.map +1 -1
- package/lib/typescript/src/features/EnvironmentFeature.d.ts.map +1 -1
- package/lib/typescript/src/features/NavigationLogFeature.d.ts +2 -0
- package/lib/typescript/src/features/NavigationLogFeature.d.ts.map +1 -1
- package/lib/typescript/src/features/NetworkFeature.d.ts +7 -20
- package/lib/typescript/src/features/NetworkFeature.d.ts.map +1 -1
- package/lib/typescript/src/features/TrackFeature.d.ts +2 -0
- package/lib/typescript/src/features/TrackFeature.d.ts.map +1 -1
- package/lib/typescript/src/features/ZustandLogFeature.d.ts +2 -0
- package/lib/typescript/src/features/ZustandLogFeature.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useNavigationLogger.d.ts +1 -8
- package/lib/typescript/src/hooks/useNavigationLogger.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +5 -5
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/initialize.d.ts +3 -22
- package/lib/typescript/src/initialize.d.ts.map +1 -1
- package/lib/typescript/src/interceptors/networkInterceptor.d.ts +18 -0
- package/lib/typescript/src/interceptors/networkInterceptor.d.ts.map +1 -0
- package/lib/typescript/src/types/index.d.ts +26 -29
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/colors.d.ts +21 -0
- package/lib/typescript/src/utils/colors.d.ts.map +1 -0
- package/lib/typescript/src/utils/createChannelFeature.d.ts +18 -0
- package/lib/typescript/src/utils/createChannelFeature.d.ts.map +1 -0
- package/lib/typescript/src/utils/layout.d.ts +2 -0
- package/lib/typescript/src/utils/layout.d.ts.map +1 -0
- package/lib/typescript/src/utils/urlRewriterRegistry.d.ts +7 -0
- package/lib/typescript/src/utils/urlRewriterRegistry.d.ts.map +1 -0
- package/package.json +5 -1
- package/src/components/ClipboardTab.tsx +8 -8
- package/src/components/ConsoleLogTab.tsx +49 -163
- package/src/components/DebugPanel.tsx +215 -0
- package/src/components/DebugView.tsx +80 -0
- package/src/components/EnvironmentTab.tsx +3 -3
- package/src/components/FeatureTabBar.tsx +204 -0
- package/src/components/FloatIcon.tsx +171 -0
- package/src/components/FloatPanelView.tsx +135 -647
- package/src/components/NavigationLogTab.tsx +1 -1
- package/src/components/NetworkLogTab.tsx +128 -269
- package/src/components/ThirdPartyLibsTab.tsx +3 -3
- package/src/components/TrackLogTab.tsx +53 -188
- package/src/components/ZustandLogTab.tsx +79 -181
- package/src/components/shared/CollapsibleSection.tsx +1 -1
- package/src/components/shared/CopyButton.tsx +1 -1
- package/src/components/shared/LogListScreen.tsx +164 -0
- package/src/core/DebugToolkit.tsx +114 -138
- package/src/core/DebugToolkitProvider.tsx +32 -38
- package/src/features/ClipboardFeature.ts +6 -2
- package/src/features/ConsoleLogFeature.ts +66 -68
- package/src/features/EnvironmentFeature.ts +5 -13
- package/src/features/NavigationLogFeature.ts +12 -42
- package/src/features/NetworkFeature.ts +43 -405
- package/src/features/TrackFeature.ts +14 -49
- package/src/features/ZustandLogFeature.ts +16 -42
- package/src/hooks/useNavigationLogger.ts +1 -6
- package/src/index.ts +5 -9
- package/src/initialize.ts +28 -120
- package/src/interceptors/networkInterceptor.ts +646 -0
- package/src/types/index.ts +25 -36
- package/src/utils/colors.ts +38 -0
- package/src/utils/createChannelFeature.ts +55 -0
- package/src/utils/layout.ts +1 -0
- package/src/utils/urlRewriterRegistry.ts +10 -0
- package/lib/commonjs/utils/constants.js +0 -135
- package/lib/commonjs/utils/constants.js.map +0 -1
- package/lib/module/utils/constants.js +0 -130
- package/lib/module/utils/constants.js.map +0 -1
- package/lib/typescript/src/utils/constants.d.ts +0 -96
- package/lib/typescript/src/utils/constants.d.ts.map +0 -1
- package/src/utils/constants.ts +0 -91
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_DebugToolkit","require","_DebugToolkitProvider","_initialize","_NetworkFeature","_ConsoleLogFeature","_ZustandLogFeature","_NavigationLogFeature","_TrackFeature","
|
|
1
|
+
{"version":3,"names":["_DebugToolkit","require","_DebugToolkitProvider","_DebugView","_initialize","_NetworkFeature","_ConsoleLogFeature","_ZustandLogFeature","_NavigationLogFeature","_TrackFeature","_EnvironmentFeature","_ClipboardFeature","_useNavigationLogger","_safeStringify","_copyToComputer"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,qBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAEA,IAAAG,WAAA,GAAAH,OAAA;AAIA,IAAAI,eAAA,GAAAJ,OAAA;AAEA,IAAAK,kBAAA,GAAAL,OAAA;AAEA,IAAAM,kBAAA,GAAAN,OAAA;AAEA,IAAAO,qBAAA,GAAAP,OAAA;AAEA,IAAAQ,aAAA,GAAAR,OAAA;AAEA,IAAAS,mBAAA,GAAAT,OAAA;AAEA,IAAAU,iBAAA,GAAAV,OAAA;AAGA,IAAAW,oBAAA,GAAAX,OAAA;AAGA,IAAAY,cAAA,GAAAZ,OAAA;AACA,IAAAa,eAAA,GAAAb,OAAA","ignoreList":[]}
|
|
@@ -4,22 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.initializeDebugToolkit = initializeDebugToolkit;
|
|
7
|
-
exports.isDebugMode = void 0;
|
|
8
7
|
var _DebugToolkit = require("./core/DebugToolkit");
|
|
9
8
|
var _NetworkFeature = require("./features/NetworkFeature");
|
|
10
9
|
var _ConsoleLogFeature = require("./features/ConsoleLogFeature");
|
|
11
10
|
var _ZustandLogFeature = require("./features/ZustandLogFeature");
|
|
12
11
|
var _NavigationLogFeature = require("./features/NavigationLogFeature");
|
|
13
12
|
var _TrackFeature = require("./features/TrackFeature");
|
|
14
|
-
var _ThirdPartyLibsFeature = require("./features/ThirdPartyLibsFeature");
|
|
15
13
|
var _EnvironmentFeature = require("./features/EnvironmentFeature");
|
|
16
14
|
var _ClipboardFeature = require("./features/ClipboardFeature");
|
|
17
|
-
|
|
18
|
-
const isDebugMode = exports.isDebugMode = __DEV__;
|
|
15
|
+
const isDebugMode = __DEV__;
|
|
19
16
|
|
|
20
17
|
/** Feature-specific configuration map */
|
|
21
18
|
|
|
22
19
|
/** Registry mapping feature names to creator functions */
|
|
20
|
+
// Config param requires `any` — each factory accepts a different config type.
|
|
23
21
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
22
|
const featureRegistry = {
|
|
25
23
|
network: _NetworkFeature.createNetworkFeature,
|
|
@@ -27,57 +25,20 @@ const featureRegistry = {
|
|
|
27
25
|
zustand: _ZustandLogFeature.createZustandLogFeature,
|
|
28
26
|
navigation: _NavigationLogFeature.createNavigationLogFeature,
|
|
29
27
|
track: _TrackFeature.createTrackFeature,
|
|
30
|
-
thirdPartyLibs: _ThirdPartyLibsFeature.createThirdPartyLibsFeature,
|
|
31
28
|
environment: _EnvironmentFeature.createEnvironmentFeature,
|
|
32
29
|
clipboard: _ClipboardFeature.createClipboardFeature
|
|
33
30
|
};
|
|
34
|
-
const DEFAULT_FEATURES = ['network', 'console', 'navigation', 'zustand', 'track', '
|
|
35
|
-
function resolveFeatures(features) {
|
|
36
|
-
return features.reduce((resolvedFeatures, identifier) => {
|
|
37
|
-
let feature = null;
|
|
38
|
-
if (typeof identifier === 'string') {
|
|
39
|
-
const creator = featureRegistry[identifier];
|
|
40
|
-
if (!creator) {
|
|
41
|
-
console.warn(`[DebugToolkit] Unknown feature: "${identifier}"`);
|
|
42
|
-
return resolvedFeatures;
|
|
43
|
-
}
|
|
44
|
-
feature = creator();
|
|
45
|
-
} else if (typeof identifier === 'function') {
|
|
46
|
-
try {
|
|
47
|
-
feature = identifier();
|
|
48
|
-
} catch (error) {
|
|
49
|
-
console.error('[DebugToolkit] Feature creator failed:', error);
|
|
50
|
-
return resolvedFeatures;
|
|
51
|
-
}
|
|
52
|
-
} else if (identifier && typeof identifier === 'object' && identifier.name) {
|
|
53
|
-
feature = identifier;
|
|
54
|
-
} else {
|
|
55
|
-
console.warn('[DebugToolkit] Invalid feature identifier:', identifier);
|
|
56
|
-
return resolvedFeatures;
|
|
57
|
-
}
|
|
58
|
-
if (feature) {
|
|
59
|
-
resolvedFeatures.push(feature);
|
|
60
|
-
}
|
|
61
|
-
return resolvedFeatures;
|
|
62
|
-
}, []);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Resolve feature configs to DebugFeature instances.
|
|
67
|
-
*/
|
|
31
|
+
const DEFAULT_FEATURES = ['network', 'console', 'navigation', 'zustand', 'track', 'clipboard'];
|
|
68
32
|
function resolveFeatureConfigs(configs) {
|
|
69
33
|
const features = [];
|
|
70
34
|
const entries = Object.entries(configs);
|
|
71
35
|
for (const [name, config] of entries) {
|
|
72
|
-
// Skip false/explicitly disabled
|
|
73
36
|
if (config === false) continue;
|
|
74
37
|
const creator = featureRegistry[name];
|
|
75
38
|
if (!creator) {
|
|
76
39
|
console.warn(`[DebugToolkit] Unknown feature: "${name}"`);
|
|
77
40
|
continue;
|
|
78
41
|
}
|
|
79
|
-
|
|
80
|
-
// config === true or undefined → use defaults
|
|
81
42
|
if (config === true || config === undefined) {
|
|
82
43
|
features.push(creator());
|
|
83
44
|
} else if (typeof config === 'object') {
|
|
@@ -86,76 +47,38 @@ function resolveFeatureConfigs(configs) {
|
|
|
86
47
|
}
|
|
87
48
|
return features;
|
|
88
49
|
}
|
|
50
|
+
function resolveDefaultFeatures() {
|
|
51
|
+
return DEFAULT_FEATURES.map(name => featureRegistry[name]());
|
|
52
|
+
}
|
|
89
53
|
|
|
90
54
|
/**
|
|
91
55
|
* Initialize the debug toolkit.
|
|
92
56
|
*
|
|
93
|
-
* @param featuresOrOptions - Either an array of feature inputs (legacy), or a full config object.
|
|
94
|
-
* @param options - Options when using legacy array mode.
|
|
95
|
-
*
|
|
96
57
|
* @example
|
|
97
|
-
* // Legacy mode (still supported)
|
|
98
|
-
* initializeDebugToolkit(['network', 'console'], { enabled: true });
|
|
99
|
-
*
|
|
100
|
-
* // Config object mode (recommended)
|
|
101
58
|
* initializeDebugToolkit({
|
|
102
|
-
* features: {
|
|
103
|
-
* network: { maxLogs: 100 },
|
|
104
|
-
* console: true,
|
|
105
|
-
* track: true,
|
|
106
|
-
* environment: { environments: [...] },
|
|
107
|
-
* },
|
|
59
|
+
* features: { network: true, console: true },
|
|
108
60
|
* enabled: true,
|
|
109
61
|
* });
|
|
110
62
|
*/
|
|
111
|
-
function initializeDebugToolkit(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
let enabled;
|
|
115
|
-
let doraemonProductId;
|
|
116
|
-
if (Array.isArray(featuresOrOptions)) {
|
|
117
|
-
// Legacy mode
|
|
118
|
-
resolvedFeatures = resolveFeatures(featuresOrOptions);
|
|
119
|
-
enabled = options.enabled ?? isDebugMode;
|
|
120
|
-
doraemonProductId = options.doraemonProductId;
|
|
121
|
-
} else if (featuresOrOptions && typeof featuresOrOptions === 'object' && !('name' in featuresOrOptions)) {
|
|
122
|
-
// Config object mode
|
|
123
|
-
const config = featuresOrOptions;
|
|
124
|
-
enabled = config.enabled ?? isDebugMode;
|
|
125
|
-
doraemonProductId = config.doraemonProductId;
|
|
126
|
-
if (config.features) {
|
|
127
|
-
resolvedFeatures = resolveFeatureConfigs(config.features);
|
|
128
|
-
} else {
|
|
129
|
-
resolvedFeatures = resolveFeatures(DEFAULT_FEATURES);
|
|
130
|
-
}
|
|
131
|
-
} else {
|
|
132
|
-
// Default - no args or single feature
|
|
133
|
-
resolvedFeatures = resolveFeatures(featuresOrOptions ? [featuresOrOptions] : DEFAULT_FEATURES);
|
|
134
|
-
enabled = options.enabled ?? isDebugMode;
|
|
135
|
-
doraemonProductId = options.doraemonProductId;
|
|
136
|
-
}
|
|
63
|
+
function initializeDebugToolkit(options) {
|
|
64
|
+
const enabled = options?.enabled ?? isDebugMode;
|
|
65
|
+
const resolvedFeatures = options?.features ? resolveFeatureConfigs(options.features) : resolveDefaultFeatures();
|
|
137
66
|
try {
|
|
138
|
-
|
|
139
|
-
toolkit.setEnabled(enabled);
|
|
67
|
+
_DebugToolkit.DebugToolkit.setEnabled(enabled);
|
|
140
68
|
if (!enabled) {
|
|
141
|
-
|
|
142
|
-
return
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Initialize native debug libs if configured
|
|
146
|
-
if (doraemonProductId) {
|
|
147
|
-
_NativeDebugLibs.NativeDebugLibs.installDoraemonKit(doraemonProductId);
|
|
69
|
+
_DebugToolkit.DebugToolkit.reset();
|
|
70
|
+
return _DebugToolkit.DebugToolkit;
|
|
148
71
|
}
|
|
149
|
-
|
|
150
|
-
if (
|
|
151
|
-
|
|
72
|
+
_DebugToolkit.DebugToolkit.replaceFeatures(resolvedFeatures);
|
|
73
|
+
if (_DebugToolkit.DebugToolkit.hasFeatures()) {
|
|
74
|
+
_DebugToolkit.DebugToolkit.showPanel();
|
|
152
75
|
} else {
|
|
153
|
-
|
|
76
|
+
_DebugToolkit.DebugToolkit.hidePanel();
|
|
154
77
|
}
|
|
155
|
-
return
|
|
78
|
+
return _DebugToolkit.DebugToolkit;
|
|
156
79
|
} catch (error) {
|
|
157
80
|
console.error('[DebugToolkit] Initialization failed:', error);
|
|
158
|
-
return
|
|
81
|
+
return _DebugToolkit.DebugToolkit;
|
|
159
82
|
}
|
|
160
83
|
}
|
|
161
84
|
//# sourceMappingURL=initialize.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_DebugToolkit","require","_NetworkFeature","_ConsoleLogFeature","_ZustandLogFeature","_NavigationLogFeature","_TrackFeature","
|
|
1
|
+
{"version":3,"names":["_DebugToolkit","require","_NetworkFeature","_ConsoleLogFeature","_ZustandLogFeature","_NavigationLogFeature","_TrackFeature","_EnvironmentFeature","_ClipboardFeature","isDebugMode","__DEV__","featureRegistry","network","createNetworkFeature","console","createConsoleLogFeature","zustand","createZustandLogFeature","navigation","createNavigationLogFeature","track","createTrackFeature","environment","createEnvironmentFeature","clipboard","createClipboardFeature","DEFAULT_FEATURES","resolveFeatureConfigs","configs","features","entries","Object","name","config","creator","warn","undefined","push","resolveDefaultFeatures","map","initializeDebugToolkit","options","enabled","resolvedFeatures","DebugToolkit","setEnabled","reset","replaceFeatures","hasFeatures","showPanel","hidePanel","error"],"sourceRoot":"../../src","sources":["initialize.ts"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AAEA,IAAAE,kBAAA,GAAAF,OAAA;AAEA,IAAAG,kBAAA,GAAAH,OAAA;AAEA,IAAAI,qBAAA,GAAAJ,OAAA;AAEA,IAAAK,aAAA,GAAAL,OAAA;AAEA,IAAAM,mBAAA,GAAAN,OAAA;AACA,IAAAO,iBAAA,GAAAP,OAAA;AAGA,MAAMQ,WAAW,GAAGC,OAAO;;AAE3B;;AAgBA;AACA;AACA;AACA,MAAMC,eAA8E,GAAG;EACrFC,OAAO,EAAEC,oCAAoB;EAC7BC,OAAO,EAAEC,0CAAuB;EAChCC,OAAO,EAAEC,0CAAuB;EAChCC,UAAU,EAAEC,gDAA0B;EACtCC,KAAK,EAAEC,gCAAkB;EACzBC,WAAW,EAAEC,4CAAwB;EACrCC,SAAS,EAAEC;AACb,CAAC;AAED,MAAMC,gBAAsC,GAAG,CAC7C,SAAS,EACT,SAAS,EACT,YAAY,EACZ,SAAS,EACT,OAAO,EACP,WAAW,CACZ;AAED,SAASC,qBAAqBA,CAACC,OAAuB,EAAqB;EACzE,MAAMC,QAA2B,GAAG,EAAE;EACtC,MAAMC,OAAO,GAAGC,MAAM,CAACD,OAAO,CAACF,OAAO,CAAoC;EAE1E,KAAK,MAAM,CAACI,IAAI,EAAEC,MAAM,CAAC,IAAIH,OAAO,EAAE;IACpC,IAAIG,MAAM,KAAK,KAAK,EAAE;IAEtB,MAAMC,OAAO,GAAGvB,eAAe,CAACqB,IAAI,CAAC;IACrC,IAAI,CAACE,OAAO,EAAE;MACZpB,OAAO,CAACqB,IAAI,CAAC,oCAAoCH,IAAI,GAAG,CAAC;MACzD;IACF;IAEA,IAAIC,MAAM,KAAK,IAAI,IAAIA,MAAM,KAAKG,SAAS,EAAE;MAC3CP,QAAQ,CAACQ,IAAI,CAACH,OAAO,CAAC,CAAC,CAAC;IAC1B,CAAC,MAAM,IAAI,OAAOD,MAAM,KAAK,QAAQ,EAAE;MACrCJ,QAAQ,CAACQ,IAAI,CAACH,OAAO,CAACD,MAAiC,CAAC,CAAC;IAC3D;EACF;EAEA,OAAOJ,QAAQ;AACjB;AAEA,SAASS,sBAAsBA,CAAA,EAAsB;EACnD,OAAOZ,gBAAgB,CAACa,GAAG,CAAEP,IAAI,IAAKrB,eAAe,CAACqB,IAAI,CAAC,CAAE,CAAC,CAAC;AACjE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASQ,sBAAsBA,CACpCC,OAA2B,EACN;EACrB,MAAMC,OAAO,GAAGD,OAAO,EAAEC,OAAO,IAAIjC,WAAW;EAE/C,MAAMkC,gBAAgB,GAAGF,OAAO,EAAEZ,QAAQ,GACtCF,qBAAqB,CAACc,OAAO,CAACZ,QAAQ,CAAC,GACvCS,sBAAsB,CAAC,CAAC;EAE5B,IAAI;IACFM,0BAAY,CAACC,UAAU,CAACH,OAAO,CAAC;IAEhC,IAAI,CAACA,OAAO,EAAE;MACZE,0BAAY,CAACE,KAAK,CAAC,CAAC;MACpB,OAAOF,0BAAY;IACrB;IAEAA,0BAAY,CAACG,eAAe,CAACJ,gBAAgB,CAAC;IAE9C,IAAIC,0BAAY,CAACI,WAAW,CAAC,CAAC,EAAE;MAC9BJ,0BAAY,CAACK,SAAS,CAAC,CAAC;IAC1B,CAAC,MAAM;MACLL,0BAAY,CAACM,SAAS,CAAC,CAAC;IAC1B;IAEA,OAAON,0BAAY;EACrB,CAAC,CAAC,OAAOO,KAAK,EAAE;IACdrC,OAAO,CAACqC,KAAK,CAAC,uCAAuC,EAAEA,KAAK,CAAC;IAC7D,OAAOP,0BAAY;EACrB;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.resetInterceptors = resetInterceptors;
|
|
7
|
+
exports.setupAxios = setupAxios;
|
|
8
|
+
exports.startFetch = startFetch;
|
|
9
|
+
exports.startXMLHttpRequest = startXMLHttpRequest;
|
|
10
|
+
var _urlRewriterRegistry = require("../utils/urlRewriterRegistry");
|
|
11
|
+
// ─── Axios types ───────────────────────────────────────
|
|
12
|
+
|
|
13
|
+
// ─── XMLHttpRequest types ─────────────────────────────
|
|
14
|
+
|
|
15
|
+
// ─── Shared helpers ────────────────────────────────────
|
|
16
|
+
|
|
17
|
+
function rewriteUrl(url) {
|
|
18
|
+
const rewriter = _urlRewriterRegistry.urlRewriter.get();
|
|
19
|
+
if (!rewriter) {
|
|
20
|
+
return url;
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
return rewriter(url);
|
|
24
|
+
} catch {
|
|
25
|
+
return url;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function headersToObject(headers) {
|
|
29
|
+
const result = {};
|
|
30
|
+
if (!headers) {
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
if (typeof headers.forEach === 'function') {
|
|
34
|
+
headers.forEach((value, key) => {
|
|
35
|
+
result[key] = value;
|
|
36
|
+
});
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
Object.keys(headers).forEach(key => {
|
|
40
|
+
result[key] = headers[key];
|
|
41
|
+
});
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
function getRequestSnapshot(input, init) {
|
|
45
|
+
const request = input instanceof Request ? input : null;
|
|
46
|
+
return {
|
|
47
|
+
url: typeof input === 'string' ? input : request?.url ?? String(input),
|
|
48
|
+
method: (init?.method || request?.method || 'GET').toUpperCase(),
|
|
49
|
+
headers: init?.headers ? headersToObject(init.headers) : request?.headers ? headersToObject(request.headers) : undefined,
|
|
50
|
+
body: init?.body
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
async function parseResponseBody(response) {
|
|
54
|
+
const raw = await response.clone().text();
|
|
55
|
+
if (!raw) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
return JSON.parse(raw);
|
|
60
|
+
} catch {
|
|
61
|
+
return raw;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function parseMaybeJson(raw) {
|
|
65
|
+
if (!raw) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
return JSON.parse(raw);
|
|
70
|
+
} catch {
|
|
71
|
+
return raw;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function parseRawHeaders(rawHeaders) {
|
|
75
|
+
if (!rawHeaders) {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
const headers = {};
|
|
79
|
+
rawHeaders.split(/\r?\n/).forEach(line => {
|
|
80
|
+
const separatorIndex = line.indexOf(':');
|
|
81
|
+
if (separatorIndex <= 0) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const key = line.slice(0, separatorIndex).trim();
|
|
85
|
+
const value = line.slice(separatorIndex + 1).trim();
|
|
86
|
+
if (!key) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
headers[key] = value;
|
|
90
|
+
});
|
|
91
|
+
return Object.keys(headers).length > 0 ? headers : undefined;
|
|
92
|
+
}
|
|
93
|
+
function getXMLHttpRequestConstructor() {
|
|
94
|
+
const globalWithXhr = globalThis;
|
|
95
|
+
const candidate = globalWithXhr.XMLHttpRequest;
|
|
96
|
+
if (typeof candidate !== 'function') {
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
const prototype = candidate.prototype;
|
|
100
|
+
if (!prototype || typeof prototype.open !== 'function' || typeof prototype.send !== 'function') {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
return candidate;
|
|
104
|
+
}
|
|
105
|
+
function getXhrResponseHeaders(xhr) {
|
|
106
|
+
if (typeof xhr.getAllResponseHeaders !== 'function') {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
return parseRawHeaders(xhr.getAllResponseHeaders());
|
|
111
|
+
} catch {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function getXhrResponseData(xhr) {
|
|
116
|
+
const responseType = typeof xhr.responseType === 'string' ? xhr.responseType : '';
|
|
117
|
+
if (responseType === 'json') {
|
|
118
|
+
return xhr.response;
|
|
119
|
+
}
|
|
120
|
+
if (responseType && responseType !== 'text') {
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
if (typeof xhr.responseText === 'string') {
|
|
125
|
+
return parseMaybeJson(xhr.responseText);
|
|
126
|
+
}
|
|
127
|
+
} catch {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
return typeof xhr.response === 'string' ? parseMaybeJson(xhr.response) : xhr.response;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ─── Interceptor manager (encapsulated mutable state) ──
|
|
134
|
+
|
|
135
|
+
let originalFetch = null;
|
|
136
|
+
let fetchRefCount = 0;
|
|
137
|
+
const pendingAxiosRequests = new WeakMap();
|
|
138
|
+
const axiosRegistrations = new WeakMap();
|
|
139
|
+
let originalXMLHttpRequest = null;
|
|
140
|
+
let xhrRefCount = 0;
|
|
141
|
+
const pendingXhrRequests = new WeakMap();
|
|
142
|
+
function stopFetch() {
|
|
143
|
+
fetchRefCount = Math.max(0, fetchRefCount - 1);
|
|
144
|
+
if (fetchRefCount === 0 && originalFetch) {
|
|
145
|
+
globalThis.fetch = originalFetch;
|
|
146
|
+
originalFetch = null;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function startFetch(emit) {
|
|
150
|
+
fetchRefCount += 1;
|
|
151
|
+
if (originalFetch) {
|
|
152
|
+
return () => {
|
|
153
|
+
stopFetch();
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
originalFetch = globalThis.fetch;
|
|
157
|
+
globalThis.fetch = async function interceptedFetch(input, init) {
|
|
158
|
+
const startTime = Date.now();
|
|
159
|
+
let rewrittenInput = input;
|
|
160
|
+
if (_urlRewriterRegistry.urlRewriter.get()) {
|
|
161
|
+
if (typeof input === 'string') {
|
|
162
|
+
rewrittenInput = rewriteUrl(input);
|
|
163
|
+
} else if (input instanceof Request) {
|
|
164
|
+
rewrittenInput = new Request(rewriteUrl(input.url), input);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const request = getRequestSnapshot(rewrittenInput, init);
|
|
168
|
+
try {
|
|
169
|
+
const response = await originalFetch.call(globalThis, rewrittenInput, init);
|
|
170
|
+
const duration = Date.now() - startTime;
|
|
171
|
+
try {
|
|
172
|
+
const data = await parseResponseBody(response);
|
|
173
|
+
emit({
|
|
174
|
+
timestamp: startTime,
|
|
175
|
+
duration,
|
|
176
|
+
request,
|
|
177
|
+
response: {
|
|
178
|
+
status: response.status,
|
|
179
|
+
statusText: response.statusText,
|
|
180
|
+
data
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
} catch {
|
|
184
|
+
emit({
|
|
185
|
+
timestamp: startTime,
|
|
186
|
+
duration,
|
|
187
|
+
request,
|
|
188
|
+
response: {
|
|
189
|
+
status: response.status,
|
|
190
|
+
statusText: response.statusText
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return response;
|
|
195
|
+
} catch (error) {
|
|
196
|
+
emit({
|
|
197
|
+
timestamp: startTime,
|
|
198
|
+
duration: Date.now() - startTime,
|
|
199
|
+
request,
|
|
200
|
+
error: error instanceof Error ? error.message : String(error)
|
|
201
|
+
});
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
return () => {
|
|
206
|
+
stopFetch();
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function emitXhrLog(xhr, emit, error) {
|
|
210
|
+
const pending = pendingXhrRequests.get(xhr);
|
|
211
|
+
if (!pending) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
const status = typeof xhr.status === 'number' ? xhr.status : 0;
|
|
215
|
+
const statusText = typeof xhr.statusText === 'string' ? xhr.statusText : undefined;
|
|
216
|
+
emit({
|
|
217
|
+
timestamp: pending.timestamp,
|
|
218
|
+
duration: Date.now() - pending.startTime,
|
|
219
|
+
request: {
|
|
220
|
+
url: pending.url,
|
|
221
|
+
method: pending.method,
|
|
222
|
+
headers: Object.keys(pending.headers).length > 0 ? pending.headers : undefined,
|
|
223
|
+
body: pending.body
|
|
224
|
+
},
|
|
225
|
+
response: error ? undefined : {
|
|
226
|
+
status,
|
|
227
|
+
statusText,
|
|
228
|
+
headers: getXhrResponseHeaders(xhr),
|
|
229
|
+
data: getXhrResponseData(xhr),
|
|
230
|
+
success: status >= 200 && status < 300
|
|
231
|
+
},
|
|
232
|
+
error
|
|
233
|
+
});
|
|
234
|
+
pendingXhrRequests.delete(xhr);
|
|
235
|
+
}
|
|
236
|
+
function isXhrDone(xhr) {
|
|
237
|
+
return typeof xhr.readyState === 'number' && xhr.readyState === (xhr.DONE ?? 4);
|
|
238
|
+
}
|
|
239
|
+
function attachXhrCompletion(xhr, emit) {
|
|
240
|
+
let completed = false;
|
|
241
|
+
const finish = error => {
|
|
242
|
+
if (completed) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
completed = true;
|
|
246
|
+
if (typeof xhr.removeEventListener === 'function') {
|
|
247
|
+
xhr.removeEventListener('loadend', onLoadEnd);
|
|
248
|
+
xhr.removeEventListener('error', onError);
|
|
249
|
+
xhr.removeEventListener('abort', onAbort);
|
|
250
|
+
xhr.removeEventListener('timeout', onTimeout);
|
|
251
|
+
}
|
|
252
|
+
emitXhrLog(xhr, emit, error);
|
|
253
|
+
};
|
|
254
|
+
const onLoadEnd = () => finish();
|
|
255
|
+
const onError = () => finish('XMLHttpRequest error');
|
|
256
|
+
const onAbort = () => finish('XMLHttpRequest aborted');
|
|
257
|
+
const onTimeout = () => finish('XMLHttpRequest timeout');
|
|
258
|
+
if (typeof xhr.addEventListener === 'function') {
|
|
259
|
+
xhr.addEventListener('loadend', onLoadEnd);
|
|
260
|
+
xhr.addEventListener('error', onError);
|
|
261
|
+
xhr.addEventListener('abort', onAbort);
|
|
262
|
+
xhr.addEventListener('timeout', onTimeout);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const originalOnReadyStateChange = xhr.onreadystatechange;
|
|
266
|
+
const originalOnLoadEnd = xhr.onloadend;
|
|
267
|
+
xhr.onreadystatechange = function interceptedReadyStateChange(event) {
|
|
268
|
+
originalOnReadyStateChange?.call(this, event);
|
|
269
|
+
if (isXhrDone(this)) {
|
|
270
|
+
finish();
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
xhr.onloadend = function interceptedLoadEnd(event) {
|
|
274
|
+
originalOnLoadEnd?.call(this, event);
|
|
275
|
+
finish();
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
function stopXMLHttpRequest() {
|
|
279
|
+
xhrRefCount = Math.max(0, xhrRefCount - 1);
|
|
280
|
+
if (xhrRefCount === 0 && originalXMLHttpRequest) {
|
|
281
|
+
const prototype = originalXMLHttpRequest.constructor.prototype;
|
|
282
|
+
prototype.open = originalXMLHttpRequest.open;
|
|
283
|
+
prototype.send = originalXMLHttpRequest.send;
|
|
284
|
+
if (originalXMLHttpRequest.setRequestHeader) {
|
|
285
|
+
prototype.setRequestHeader = originalXMLHttpRequest.setRequestHeader;
|
|
286
|
+
}
|
|
287
|
+
originalXMLHttpRequest = null;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
function startXMLHttpRequest(emit) {
|
|
291
|
+
xhrRefCount += 1;
|
|
292
|
+
if (originalXMLHttpRequest) {
|
|
293
|
+
return () => {
|
|
294
|
+
stopXMLHttpRequest();
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
const XMLHttpRequestConstructor = getXMLHttpRequestConstructor();
|
|
298
|
+
if (!XMLHttpRequestConstructor) {
|
|
299
|
+
return () => {
|
|
300
|
+
stopXMLHttpRequest();
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
const prototype = XMLHttpRequestConstructor.prototype;
|
|
304
|
+
const originalOpen = prototype.open;
|
|
305
|
+
const originalSend = prototype.send;
|
|
306
|
+
const originalSetRequestHeader = prototype.setRequestHeader;
|
|
307
|
+
originalXMLHttpRequest = {
|
|
308
|
+
constructor: XMLHttpRequestConstructor,
|
|
309
|
+
open: originalOpen,
|
|
310
|
+
send: originalSend,
|
|
311
|
+
setRequestHeader: originalSetRequestHeader
|
|
312
|
+
};
|
|
313
|
+
prototype.open = function interceptedOpen(method, url, async, username, password) {
|
|
314
|
+
const rewrittenUrl = _urlRewriterRegistry.urlRewriter.get() ? rewriteUrl(url) : url;
|
|
315
|
+
const now = Date.now();
|
|
316
|
+
pendingXhrRequests.set(this, {
|
|
317
|
+
method: method.toUpperCase(),
|
|
318
|
+
url: rewrittenUrl,
|
|
319
|
+
headers: {},
|
|
320
|
+
startTime: now,
|
|
321
|
+
timestamp: now
|
|
322
|
+
});
|
|
323
|
+
if (typeof password !== 'undefined') {
|
|
324
|
+
return originalOpen.call(this, method, rewrittenUrl, async, username, password);
|
|
325
|
+
}
|
|
326
|
+
if (typeof username !== 'undefined') {
|
|
327
|
+
return originalOpen.call(this, method, rewrittenUrl, async, username);
|
|
328
|
+
}
|
|
329
|
+
if (typeof async !== 'undefined') {
|
|
330
|
+
return originalOpen.call(this, method, rewrittenUrl, async);
|
|
331
|
+
}
|
|
332
|
+
return originalOpen.call(this, method, rewrittenUrl);
|
|
333
|
+
};
|
|
334
|
+
if (originalSetRequestHeader) {
|
|
335
|
+
prototype.setRequestHeader = function interceptedSetRequestHeader(name, value) {
|
|
336
|
+
const pending = pendingXhrRequests.get(this);
|
|
337
|
+
if (pending) {
|
|
338
|
+
pending.headers[name] = value;
|
|
339
|
+
}
|
|
340
|
+
return originalSetRequestHeader.call(this, name, value);
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
prototype.send = function interceptedSend(body) {
|
|
344
|
+
const pending = pendingXhrRequests.get(this);
|
|
345
|
+
if (pending) {
|
|
346
|
+
const now = Date.now();
|
|
347
|
+
pending.body = body;
|
|
348
|
+
pending.startTime = now;
|
|
349
|
+
pending.timestamp = now;
|
|
350
|
+
attachXhrCompletion(this, emit);
|
|
351
|
+
}
|
|
352
|
+
try {
|
|
353
|
+
return originalSend.call(this, body);
|
|
354
|
+
} catch (error) {
|
|
355
|
+
emitXhrLog(this, emit, error instanceof Error ? error.message : String(error));
|
|
356
|
+
throw error;
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
return () => {
|
|
360
|
+
stopXMLHttpRequest();
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
function teardownAxios(axiosInstance) {
|
|
364
|
+
const registration = axiosRegistrations.get(axiosInstance);
|
|
365
|
+
if (!registration) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
registration.refCount -= 1;
|
|
369
|
+
if (registration.refCount > 0) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
if (typeof registration.requestId === 'number') {
|
|
373
|
+
axiosInstance.interceptors.request.eject?.(registration.requestId);
|
|
374
|
+
}
|
|
375
|
+
if (typeof registration.responseId === 'number') {
|
|
376
|
+
axiosInstance.interceptors.response.eject?.(registration.responseId);
|
|
377
|
+
}
|
|
378
|
+
axiosRegistrations.delete(axiosInstance);
|
|
379
|
+
}
|
|
380
|
+
function setupAxios(axiosInstance, emit) {
|
|
381
|
+
const existing = axiosRegistrations.get(axiosInstance);
|
|
382
|
+
if (existing) {
|
|
383
|
+
existing.refCount += 1;
|
|
384
|
+
return () => {
|
|
385
|
+
teardownAxios(axiosInstance);
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
const requestId = axiosInstance.interceptors.request.use(config => {
|
|
389
|
+
if (_urlRewriterRegistry.urlRewriter.get() && config.url) {
|
|
390
|
+
const fullUrl = config.baseURL ? `${config.baseURL}${config.url}` : config.url;
|
|
391
|
+
const rewritten = rewriteUrl(fullUrl);
|
|
392
|
+
if (rewritten !== fullUrl) {
|
|
393
|
+
if (config.baseURL && rewritten.startsWith(config.baseURL)) {
|
|
394
|
+
config.url = rewritten.slice(config.baseURL.length);
|
|
395
|
+
} else {
|
|
396
|
+
config.baseURL = '';
|
|
397
|
+
config.url = rewritten;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
pendingAxiosRequests.set(config, {
|
|
402
|
+
startTime: Date.now(),
|
|
403
|
+
timestamp: Date.now()
|
|
404
|
+
});
|
|
405
|
+
return config;
|
|
406
|
+
}, error => Promise.reject(error));
|
|
407
|
+
const responseId = axiosInstance.interceptors.response.use(response => {
|
|
408
|
+
const pending = pendingAxiosRequests.get(response.config);
|
|
409
|
+
if (pending) {
|
|
410
|
+
emit({
|
|
411
|
+
timestamp: pending.timestamp,
|
|
412
|
+
duration: Date.now() - pending.startTime,
|
|
413
|
+
request: {
|
|
414
|
+
url: `${response.config.baseURL || ''}${response.config.url}`,
|
|
415
|
+
method: (response.config.method || 'GET').toUpperCase(),
|
|
416
|
+
headers: response.config.headers,
|
|
417
|
+
body: response.config.data || response.config.params
|
|
418
|
+
},
|
|
419
|
+
response: {
|
|
420
|
+
status: response.status,
|
|
421
|
+
statusText: response.statusText,
|
|
422
|
+
headers: response.headers,
|
|
423
|
+
data: response.data,
|
|
424
|
+
success: response.data && typeof response.data === 'object' ? response.data.success !== false : response.status >= 200 && response.status < 300
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
pendingAxiosRequests.delete(response.config);
|
|
428
|
+
}
|
|
429
|
+
return response;
|
|
430
|
+
}, error => {
|
|
431
|
+
if (error.config) {
|
|
432
|
+
const pending = pendingAxiosRequests.get(error.config);
|
|
433
|
+
emit({
|
|
434
|
+
timestamp: pending ? pending.timestamp : Date.now(),
|
|
435
|
+
duration: pending ? Date.now() - pending.startTime : undefined,
|
|
436
|
+
request: {
|
|
437
|
+
url: `${error.config.baseURL || ''}${error.config.url}`,
|
|
438
|
+
method: (error.config.method || 'GET').toUpperCase(),
|
|
439
|
+
headers: error.config.headers,
|
|
440
|
+
body: error.config.data || error.config.params
|
|
441
|
+
},
|
|
442
|
+
error: error.message
|
|
443
|
+
});
|
|
444
|
+
pendingAxiosRequests.delete(error.config);
|
|
445
|
+
}
|
|
446
|
+
return Promise.reject(error);
|
|
447
|
+
});
|
|
448
|
+
axiosRegistrations.set(axiosInstance, {
|
|
449
|
+
refCount: 1,
|
|
450
|
+
requestId: typeof requestId === 'number' ? requestId : undefined,
|
|
451
|
+
responseId: typeof responseId === 'number' ? responseId : undefined
|
|
452
|
+
});
|
|
453
|
+
return () => {
|
|
454
|
+
teardownAxios(axiosInstance);
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
function resetInterceptors() {
|
|
458
|
+
if (originalFetch) {
|
|
459
|
+
globalThis.fetch = originalFetch;
|
|
460
|
+
originalFetch = null;
|
|
461
|
+
}
|
|
462
|
+
fetchRefCount = 0;
|
|
463
|
+
xhrRefCount = 1;
|
|
464
|
+
stopXMLHttpRequest();
|
|
465
|
+
}
|
|
466
|
+
//# sourceMappingURL=networkInterceptor.js.map
|