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.
Files changed (228) hide show
  1. package/README.md +72 -72
  2. package/README.zh-CN.md +209 -0
  3. package/lib/commonjs/components/ClipboardTab.js +15 -16
  4. package/lib/commonjs/components/ClipboardTab.js.map +1 -1
  5. package/lib/commonjs/components/ConsoleLogTab.js +69 -202
  6. package/lib/commonjs/components/ConsoleLogTab.js.map +1 -1
  7. package/lib/commonjs/components/DebugPanel.js +230 -0
  8. package/lib/commonjs/components/DebugPanel.js.map +1 -0
  9. package/lib/commonjs/components/DebugView.js +66 -0
  10. package/lib/commonjs/components/DebugView.js.map +1 -0
  11. package/lib/commonjs/components/EnvironmentTab.js +22 -23
  12. package/lib/commonjs/components/EnvironmentTab.js.map +1 -1
  13. package/lib/commonjs/components/FeatureTabBar.js +182 -0
  14. package/lib/commonjs/components/FeatureTabBar.js.map +1 -0
  15. package/lib/commonjs/components/FloatIcon.js +187 -0
  16. package/lib/commonjs/components/FloatIcon.js.map +1 -0
  17. package/lib/commonjs/components/FloatPanelView.js +140 -723
  18. package/lib/commonjs/components/FloatPanelView.js.map +1 -1
  19. package/lib/commonjs/components/NavigationLogTab.js +8 -8
  20. package/lib/commonjs/components/NavigationLogTab.js.map +1 -1
  21. package/lib/commonjs/components/NetworkLogTab.js +179 -350
  22. package/lib/commonjs/components/NetworkLogTab.js.map +1 -1
  23. package/lib/commonjs/components/ThirdPartyLibsTab.js +8 -8
  24. package/lib/commonjs/components/ThirdPartyLibsTab.js.map +1 -1
  25. package/lib/commonjs/components/TrackLogTab.js +106 -248
  26. package/lib/commonjs/components/TrackLogTab.js.map +1 -1
  27. package/lib/commonjs/components/ZustandLogTab.js +148 -288
  28. package/lib/commonjs/components/ZustandLogTab.js.map +1 -1
  29. package/lib/commonjs/components/shared/CollapsibleSection.js +4 -4
  30. package/lib/commonjs/components/shared/CollapsibleSection.js.map +1 -1
  31. package/lib/commonjs/components/shared/CopyButton.js +3 -3
  32. package/lib/commonjs/components/shared/CopyButton.js.map +1 -1
  33. package/lib/commonjs/components/shared/LogListScreen.js +174 -0
  34. package/lib/commonjs/components/shared/LogListScreen.js.map +1 -0
  35. package/lib/commonjs/core/DebugToolkit.js +92 -112
  36. package/lib/commonjs/core/DebugToolkit.js.map +1 -1
  37. package/lib/commonjs/core/DebugToolkitProvider.js +30 -28
  38. package/lib/commonjs/core/DebugToolkitProvider.js.map +1 -1
  39. package/lib/commonjs/features/ClipboardFeature.js +6 -2
  40. package/lib/commonjs/features/ClipboardFeature.js.map +1 -1
  41. package/lib/commonjs/features/ConsoleLogFeature.js +66 -49
  42. package/lib/commonjs/features/ConsoleLogFeature.js.map +1 -1
  43. package/lib/commonjs/features/EnvironmentFeature.js +5 -13
  44. package/lib/commonjs/features/EnvironmentFeature.js.map +1 -1
  45. package/lib/commonjs/features/NavigationLogFeature.js +17 -38
  46. package/lib/commonjs/features/NavigationLogFeature.js.map +1 -1
  47. package/lib/commonjs/features/NetworkFeature.js +35 -256
  48. package/lib/commonjs/features/NetworkFeature.js.map +1 -1
  49. package/lib/commonjs/features/TrackFeature.js +17 -38
  50. package/lib/commonjs/features/TrackFeature.js.map +1 -1
  51. package/lib/commonjs/features/ZustandLogFeature.js +21 -38
  52. package/lib/commonjs/features/ZustandLogFeature.js.map +1 -1
  53. package/lib/commonjs/hooks/useNavigationLogger.js.map +1 -1
  54. package/lib/commonjs/index.js +7 -20
  55. package/lib/commonjs/index.js.map +1 -1
  56. package/lib/commonjs/initialize.js +19 -96
  57. package/lib/commonjs/initialize.js.map +1 -1
  58. package/lib/commonjs/interceptors/networkInterceptor.js +466 -0
  59. package/lib/commonjs/interceptors/networkInterceptor.js.map +1 -0
  60. package/lib/commonjs/utils/colors.js +48 -0
  61. package/lib/commonjs/utils/colors.js.map +1 -0
  62. package/lib/commonjs/utils/createChannelFeature.js +48 -0
  63. package/lib/commonjs/utils/createChannelFeature.js.map +1 -0
  64. package/lib/commonjs/utils/layout.js +8 -0
  65. package/lib/commonjs/utils/layout.js.map +1 -0
  66. package/lib/commonjs/utils/urlRewriterRegistry.js +14 -0
  67. package/lib/commonjs/utils/urlRewriterRegistry.js.map +1 -0
  68. package/lib/module/components/ClipboardTab.js +8 -8
  69. package/lib/module/components/ClipboardTab.js.map +1 -1
  70. package/lib/module/components/ConsoleLogTab.js +66 -199
  71. package/lib/module/components/ConsoleLogTab.js.map +1 -1
  72. package/lib/module/components/DebugPanel.js +225 -0
  73. package/lib/module/components/DebugPanel.js.map +1 -0
  74. package/lib/module/components/DebugView.js +61 -0
  75. package/lib/module/components/DebugView.js.map +1 -0
  76. package/lib/module/components/EnvironmentTab.js +3 -3
  77. package/lib/module/components/EnvironmentTab.js.map +1 -1
  78. package/lib/module/components/FeatureTabBar.js +177 -0
  79. package/lib/module/components/FeatureTabBar.js.map +1 -0
  80. package/lib/module/components/FloatIcon.js +182 -0
  81. package/lib/module/components/FloatIcon.js.map +1 -0
  82. package/lib/module/components/FloatPanelView.js +141 -723
  83. package/lib/module/components/FloatPanelView.js.map +1 -1
  84. package/lib/module/components/NavigationLogTab.js +1 -1
  85. package/lib/module/components/NavigationLogTab.js.map +1 -1
  86. package/lib/module/components/NetworkLogTab.js +167 -338
  87. package/lib/module/components/NetworkLogTab.js.map +1 -1
  88. package/lib/module/components/ThirdPartyLibsTab.js +1 -1
  89. package/lib/module/components/ThirdPartyLibsTab.js.map +1 -1
  90. package/lib/module/components/TrackLogTab.js +94 -236
  91. package/lib/module/components/TrackLogTab.js.map +1 -1
  92. package/lib/module/components/ZustandLogTab.js +136 -276
  93. package/lib/module/components/ZustandLogTab.js.map +1 -1
  94. package/lib/module/components/shared/CollapsibleSection.js +1 -1
  95. package/lib/module/components/shared/CollapsibleSection.js.map +1 -1
  96. package/lib/module/components/shared/CopyButton.js +1 -1
  97. package/lib/module/components/shared/CopyButton.js.map +1 -1
  98. package/lib/module/components/shared/LogListScreen.js +169 -0
  99. package/lib/module/components/shared/LogListScreen.js.map +1 -0
  100. package/lib/module/core/DebugToolkit.js +92 -111
  101. package/lib/module/core/DebugToolkit.js.map +1 -1
  102. package/lib/module/core/DebugToolkitProvider.js +31 -29
  103. package/lib/module/core/DebugToolkitProvider.js.map +1 -1
  104. package/lib/module/features/ClipboardFeature.js +6 -2
  105. package/lib/module/features/ClipboardFeature.js.map +1 -1
  106. package/lib/module/features/ConsoleLogFeature.js +65 -49
  107. package/lib/module/features/ConsoleLogFeature.js.map +1 -1
  108. package/lib/module/features/EnvironmentFeature.js +5 -13
  109. package/lib/module/features/EnvironmentFeature.js.map +1 -1
  110. package/lib/module/features/NavigationLogFeature.js +16 -38
  111. package/lib/module/features/NavigationLogFeature.js.map +1 -1
  112. package/lib/module/features/NetworkFeature.js +34 -255
  113. package/lib/module/features/NetworkFeature.js.map +1 -1
  114. package/lib/module/features/TrackFeature.js +16 -38
  115. package/lib/module/features/TrackFeature.js.map +1 -1
  116. package/lib/module/features/ZustandLogFeature.js +22 -38
  117. package/lib/module/features/ZustandLogFeature.js.map +1 -1
  118. package/lib/module/hooks/useNavigationLogger.js.map +1 -1
  119. package/lib/module/index.js +2 -3
  120. package/lib/module/index.js.map +1 -1
  121. package/lib/module/initialize.js +19 -95
  122. package/lib/module/initialize.js.map +1 -1
  123. package/lib/module/interceptors/networkInterceptor.js +460 -0
  124. package/lib/module/interceptors/networkInterceptor.js.map +1 -0
  125. package/lib/module/utils/colors.js +43 -0
  126. package/lib/module/utils/colors.js.map +1 -0
  127. package/lib/module/utils/createChannelFeature.js +44 -0
  128. package/lib/module/utils/createChannelFeature.js.map +1 -0
  129. package/lib/module/utils/layout.js +4 -0
  130. package/lib/module/utils/layout.js.map +1 -0
  131. package/lib/module/utils/urlRewriterRegistry.js +10 -0
  132. package/lib/module/utils/urlRewriterRegistry.js.map +1 -0
  133. package/lib/typescript/src/components/ClipboardTab.d.ts.map +1 -1
  134. package/lib/typescript/src/components/ConsoleLogTab.d.ts.map +1 -1
  135. package/lib/typescript/src/components/DebugPanel.d.ts +9 -0
  136. package/lib/typescript/src/components/DebugPanel.d.ts.map +1 -0
  137. package/lib/typescript/src/components/DebugView.d.ts +19 -0
  138. package/lib/typescript/src/components/DebugView.d.ts.map +1 -0
  139. package/lib/typescript/src/components/EnvironmentTab.d.ts.map +1 -1
  140. package/lib/typescript/src/components/FeatureTabBar.d.ts +13 -0
  141. package/lib/typescript/src/components/FeatureTabBar.d.ts.map +1 -0
  142. package/lib/typescript/src/components/FloatIcon.d.ts +12 -0
  143. package/lib/typescript/src/components/FloatIcon.d.ts.map +1 -0
  144. package/lib/typescript/src/components/FloatPanelView.d.ts +4 -59
  145. package/lib/typescript/src/components/FloatPanelView.d.ts.map +1 -1
  146. package/lib/typescript/src/components/NetworkLogTab.d.ts.map +1 -1
  147. package/lib/typescript/src/components/ThirdPartyLibsTab.d.ts.map +1 -1
  148. package/lib/typescript/src/components/TrackLogTab.d.ts.map +1 -1
  149. package/lib/typescript/src/components/ZustandLogTab.d.ts.map +1 -1
  150. package/lib/typescript/src/components/shared/LogListScreen.d.ts +21 -0
  151. package/lib/typescript/src/components/shared/LogListScreen.d.ts.map +1 -0
  152. package/lib/typescript/src/core/DebugToolkit.d.ts +11 -18
  153. package/lib/typescript/src/core/DebugToolkit.d.ts.map +1 -1
  154. package/lib/typescript/src/core/DebugToolkitProvider.d.ts +2 -5
  155. package/lib/typescript/src/core/DebugToolkitProvider.d.ts.map +1 -1
  156. package/lib/typescript/src/features/ClipboardFeature.d.ts +4 -0
  157. package/lib/typescript/src/features/ClipboardFeature.d.ts.map +1 -1
  158. package/lib/typescript/src/features/ConsoleLogFeature.d.ts +2 -0
  159. package/lib/typescript/src/features/ConsoleLogFeature.d.ts.map +1 -1
  160. package/lib/typescript/src/features/EnvironmentFeature.d.ts.map +1 -1
  161. package/lib/typescript/src/features/NavigationLogFeature.d.ts +2 -0
  162. package/lib/typescript/src/features/NavigationLogFeature.d.ts.map +1 -1
  163. package/lib/typescript/src/features/NetworkFeature.d.ts +7 -20
  164. package/lib/typescript/src/features/NetworkFeature.d.ts.map +1 -1
  165. package/lib/typescript/src/features/TrackFeature.d.ts +2 -0
  166. package/lib/typescript/src/features/TrackFeature.d.ts.map +1 -1
  167. package/lib/typescript/src/features/ZustandLogFeature.d.ts +2 -0
  168. package/lib/typescript/src/features/ZustandLogFeature.d.ts.map +1 -1
  169. package/lib/typescript/src/hooks/useNavigationLogger.d.ts +1 -8
  170. package/lib/typescript/src/hooks/useNavigationLogger.d.ts.map +1 -1
  171. package/lib/typescript/src/index.d.ts +5 -5
  172. package/lib/typescript/src/index.d.ts.map +1 -1
  173. package/lib/typescript/src/initialize.d.ts +3 -22
  174. package/lib/typescript/src/initialize.d.ts.map +1 -1
  175. package/lib/typescript/src/interceptors/networkInterceptor.d.ts +18 -0
  176. package/lib/typescript/src/interceptors/networkInterceptor.d.ts.map +1 -0
  177. package/lib/typescript/src/types/index.d.ts +26 -29
  178. package/lib/typescript/src/types/index.d.ts.map +1 -1
  179. package/lib/typescript/src/utils/colors.d.ts +21 -0
  180. package/lib/typescript/src/utils/colors.d.ts.map +1 -0
  181. package/lib/typescript/src/utils/createChannelFeature.d.ts +18 -0
  182. package/lib/typescript/src/utils/createChannelFeature.d.ts.map +1 -0
  183. package/lib/typescript/src/utils/layout.d.ts +2 -0
  184. package/lib/typescript/src/utils/layout.d.ts.map +1 -0
  185. package/lib/typescript/src/utils/urlRewriterRegistry.d.ts +7 -0
  186. package/lib/typescript/src/utils/urlRewriterRegistry.d.ts.map +1 -0
  187. package/package.json +5 -1
  188. package/src/components/ClipboardTab.tsx +8 -8
  189. package/src/components/ConsoleLogTab.tsx +49 -163
  190. package/src/components/DebugPanel.tsx +215 -0
  191. package/src/components/DebugView.tsx +80 -0
  192. package/src/components/EnvironmentTab.tsx +3 -3
  193. package/src/components/FeatureTabBar.tsx +204 -0
  194. package/src/components/FloatIcon.tsx +171 -0
  195. package/src/components/FloatPanelView.tsx +135 -647
  196. package/src/components/NavigationLogTab.tsx +1 -1
  197. package/src/components/NetworkLogTab.tsx +128 -269
  198. package/src/components/ThirdPartyLibsTab.tsx +3 -3
  199. package/src/components/TrackLogTab.tsx +53 -188
  200. package/src/components/ZustandLogTab.tsx +79 -181
  201. package/src/components/shared/CollapsibleSection.tsx +1 -1
  202. package/src/components/shared/CopyButton.tsx +1 -1
  203. package/src/components/shared/LogListScreen.tsx +164 -0
  204. package/src/core/DebugToolkit.tsx +114 -138
  205. package/src/core/DebugToolkitProvider.tsx +32 -38
  206. package/src/features/ClipboardFeature.ts +6 -2
  207. package/src/features/ConsoleLogFeature.ts +66 -68
  208. package/src/features/EnvironmentFeature.ts +5 -13
  209. package/src/features/NavigationLogFeature.ts +12 -42
  210. package/src/features/NetworkFeature.ts +43 -405
  211. package/src/features/TrackFeature.ts +14 -49
  212. package/src/features/ZustandLogFeature.ts +16 -42
  213. package/src/hooks/useNavigationLogger.ts +1 -6
  214. package/src/index.ts +5 -9
  215. package/src/initialize.ts +28 -120
  216. package/src/interceptors/networkInterceptor.ts +646 -0
  217. package/src/types/index.ts +25 -36
  218. package/src/utils/colors.ts +38 -0
  219. package/src/utils/createChannelFeature.ts +55 -0
  220. package/src/utils/layout.ts +1 -0
  221. package/src/utils/urlRewriterRegistry.ts +10 -0
  222. package/lib/commonjs/utils/constants.js +0 -135
  223. package/lib/commonjs/utils/constants.js.map +0 -1
  224. package/lib/module/utils/constants.js +0 -130
  225. package/lib/module/utils/constants.js.map +0 -1
  226. package/lib/typescript/src/utils/constants.d.ts +0 -96
  227. package/lib/typescript/src/utils/constants.d.ts.map +0 -1
  228. package/src/utils/constants.ts +0 -91
@@ -6,15 +6,14 @@ import { createConsoleLogFeature } from './features/ConsoleLogFeature';
6
6
  import { createZustandLogFeature } from './features/ZustandLogFeature';
7
7
  import { createNavigationLogFeature } from './features/NavigationLogFeature';
8
8
  import { createTrackFeature } from './features/TrackFeature';
9
- import { createThirdPartyLibsFeature } from './features/ThirdPartyLibsFeature';
10
9
  import { createEnvironmentFeature } from './features/EnvironmentFeature';
11
10
  import { createClipboardFeature } from './features/ClipboardFeature';
12
- import { NativeDebugLibs } from './native/NativeDebugLibs';
13
- export const isDebugMode = __DEV__;
11
+ const isDebugMode = __DEV__;
14
12
 
15
13
  /** Feature-specific configuration map */
16
14
 
17
15
  /** Registry mapping feature names to creator functions */
16
+ // Config param requires `any` — each factory accepts a different config type.
18
17
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
18
  const featureRegistry = {
20
19
  network: createNetworkFeature,
@@ -22,57 +21,20 @@ const featureRegistry = {
22
21
  zustand: createZustandLogFeature,
23
22
  navigation: createNavigationLogFeature,
24
23
  track: createTrackFeature,
25
- thirdPartyLibs: createThirdPartyLibsFeature,
26
24
  environment: createEnvironmentFeature,
27
25
  clipboard: createClipboardFeature
28
26
  };
29
- const DEFAULT_FEATURES = ['network', 'console', 'navigation', 'zustand', 'track', 'thirdPartyLibs', 'clipboard'];
30
- function resolveFeatures(features) {
31
- return features.reduce((resolvedFeatures, identifier) => {
32
- let feature = null;
33
- if (typeof identifier === 'string') {
34
- const creator = featureRegistry[identifier];
35
- if (!creator) {
36
- console.warn(`[DebugToolkit] Unknown feature: "${identifier}"`);
37
- return resolvedFeatures;
38
- }
39
- feature = creator();
40
- } else if (typeof identifier === 'function') {
41
- try {
42
- feature = identifier();
43
- } catch (error) {
44
- console.error('[DebugToolkit] Feature creator failed:', error);
45
- return resolvedFeatures;
46
- }
47
- } else if (identifier && typeof identifier === 'object' && identifier.name) {
48
- feature = identifier;
49
- } else {
50
- console.warn('[DebugToolkit] Invalid feature identifier:', identifier);
51
- return resolvedFeatures;
52
- }
53
- if (feature) {
54
- resolvedFeatures.push(feature);
55
- }
56
- return resolvedFeatures;
57
- }, []);
58
- }
59
-
60
- /**
61
- * Resolve feature configs to DebugFeature instances.
62
- */
27
+ const DEFAULT_FEATURES = ['network', 'console', 'navigation', 'zustand', 'track', 'clipboard'];
63
28
  function resolveFeatureConfigs(configs) {
64
29
  const features = [];
65
30
  const entries = Object.entries(configs);
66
31
  for (const [name, config] of entries) {
67
- // Skip false/explicitly disabled
68
32
  if (config === false) continue;
69
33
  const creator = featureRegistry[name];
70
34
  if (!creator) {
71
35
  console.warn(`[DebugToolkit] Unknown feature: "${name}"`);
72
36
  continue;
73
37
  }
74
-
75
- // config === true or undefined → use defaults
76
38
  if (config === true || config === undefined) {
77
39
  features.push(creator());
78
40
  } else if (typeof config === 'object') {
@@ -81,76 +43,38 @@ function resolveFeatureConfigs(configs) {
81
43
  }
82
44
  return features;
83
45
  }
46
+ function resolveDefaultFeatures() {
47
+ return DEFAULT_FEATURES.map(name => featureRegistry[name]());
48
+ }
84
49
 
85
50
  /**
86
51
  * Initialize the debug toolkit.
87
52
  *
88
- * @param featuresOrOptions - Either an array of feature inputs (legacy), or a full config object.
89
- * @param options - Options when using legacy array mode.
90
- *
91
53
  * @example
92
- * // Legacy mode (still supported)
93
- * initializeDebugToolkit(['network', 'console'], { enabled: true });
94
- *
95
- * // Config object mode (recommended)
96
54
  * initializeDebugToolkit({
97
- * features: {
98
- * network: { maxLogs: 100 },
99
- * console: true,
100
- * track: true,
101
- * environment: { environments: [...] },
102
- * },
55
+ * features: { network: true, console: true },
103
56
  * enabled: true,
104
57
  * });
105
58
  */
106
- export function initializeDebugToolkit(featuresOrOptions, options = {}) {
107
- // Determine which mode we're in
108
- let resolvedFeatures;
109
- let enabled;
110
- let doraemonProductId;
111
- if (Array.isArray(featuresOrOptions)) {
112
- // Legacy mode
113
- resolvedFeatures = resolveFeatures(featuresOrOptions);
114
- enabled = options.enabled ?? isDebugMode;
115
- doraemonProductId = options.doraemonProductId;
116
- } else if (featuresOrOptions && typeof featuresOrOptions === 'object' && !('name' in featuresOrOptions)) {
117
- // Config object mode
118
- const config = featuresOrOptions;
119
- enabled = config.enabled ?? isDebugMode;
120
- doraemonProductId = config.doraemonProductId;
121
- if (config.features) {
122
- resolvedFeatures = resolveFeatureConfigs(config.features);
123
- } else {
124
- resolvedFeatures = resolveFeatures(DEFAULT_FEATURES);
125
- }
126
- } else {
127
- // Default - no args or single feature
128
- resolvedFeatures = resolveFeatures(featuresOrOptions ? [featuresOrOptions] : DEFAULT_FEATURES);
129
- enabled = options.enabled ?? isDebugMode;
130
- doraemonProductId = options.doraemonProductId;
131
- }
59
+ export function initializeDebugToolkit(options) {
60
+ const enabled = options?.enabled ?? isDebugMode;
61
+ const resolvedFeatures = options?.features ? resolveFeatureConfigs(options.features) : resolveDefaultFeatures();
132
62
  try {
133
- const toolkit = DebugToolkit.getInstance(enabled);
134
- toolkit.setEnabled(enabled);
63
+ DebugToolkit.setEnabled(enabled);
135
64
  if (!enabled) {
136
- toolkit.reset();
137
- return toolkit;
138
- }
139
-
140
- // Initialize native debug libs if configured
141
- if (doraemonProductId) {
142
- NativeDebugLibs.installDoraemonKit(doraemonProductId);
65
+ DebugToolkit.reset();
66
+ return DebugToolkit;
143
67
  }
144
- toolkit.replaceFeatures(resolvedFeatures);
145
- if (toolkit.hasFeatures()) {
146
- toolkit.showPanel();
68
+ DebugToolkit.replaceFeatures(resolvedFeatures);
69
+ if (DebugToolkit.hasFeatures()) {
70
+ DebugToolkit.showPanel();
147
71
  } else {
148
- toolkit.hidePanel();
72
+ DebugToolkit.hidePanel();
149
73
  }
150
- return toolkit;
74
+ return DebugToolkit;
151
75
  } catch (error) {
152
76
  console.error('[DebugToolkit] Initialization failed:', error);
153
- return null;
77
+ return DebugToolkit;
154
78
  }
155
79
  }
156
80
  //# sourceMappingURL=initialize.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["DebugToolkit","createNetworkFeature","createConsoleLogFeature","createZustandLogFeature","createNavigationLogFeature","createTrackFeature","createThirdPartyLibsFeature","createEnvironmentFeature","createClipboardFeature","NativeDebugLibs","isDebugMode","__DEV__","featureRegistry","network","console","zustand","navigation","track","thirdPartyLibs","environment","clipboard","DEFAULT_FEATURES","resolveFeatures","features","reduce","resolvedFeatures","identifier","feature","creator","warn","error","name","push","resolveFeatureConfigs","configs","entries","Object","config","undefined","initializeDebugToolkit","featuresOrOptions","options","enabled","doraemonProductId","Array","isArray","toolkit","getInstance","setEnabled","reset","installDoraemonKit","replaceFeatures","hasFeatures","showPanel","hidePanel"],"sourceRoot":"../../src","sources":["initialize.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,qBAAqB;AAClD,SAASC,oBAAoB,QAAQ,2BAA2B;AAEhE,SAASC,uBAAuB,QAAQ,8BAA8B;AAEtE,SAASC,uBAAuB,QAAQ,8BAA8B;AAEtE,SAASC,0BAA0B,QAAQ,iCAAiC;AAE5E,SAASC,kBAAkB,QAAQ,yBAAyB;AAE5D,SAASC,2BAA2B,QAAQ,kCAAkC;AAC9E,SAASC,wBAAwB,QAAQ,+BAA+B;AACxE,SAASC,sBAAsB,QAAQ,6BAA6B;AACpE,SAASC,eAAe,QAAQ,0BAA0B;AAO1D,OAAO,MAAMC,WAAW,GAAGC,OAAO;;AAElC;;AAiBA;AACA;AACA,MAAMC,eAAgF,GAAG;EACvFC,OAAO,EAAEZ,oBAAoB;EAC7Ba,OAAO,EAAEZ,uBAAuB;EAChCa,OAAO,EAAEZ,uBAAuB;EAChCa,UAAU,EAAEZ,0BAA0B;EACtCa,KAAK,EAAEZ,kBAAkB;EACzBa,cAAc,EAAEZ,2BAA2B;EAC3Ca,WAAW,EAAEZ,wBAAwB;EACrCa,SAAS,EAAEZ;AACb,CAAC;AAED,MAAMa,gBAAsC,GAAG,CAC7C,SAAS,EACT,SAAS,EACT,YAAY,EACZ,SAAS,EACT,OAAO,EACP,gBAAgB,EAChB,WAAW,CACZ;AAED,SAASC,eAAeA,CACtBC,QAA6B,EACR;EACrB,OAAOA,QAAQ,CAACC,MAAM,CAAsB,CAACC,gBAAgB,EAAEC,UAAU,KAAK;IAC5E,IAAIC,OAAiC,GAAG,IAAI;IAE5C,IAAI,OAAOD,UAAU,KAAK,QAAQ,EAAE;MAClC,MAAME,OAAO,GAAGhB,eAAe,CAAC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AGnB,gBACjE,CAAC;IACDqB,OAAO,GAAGD,OAAO,CAACC,OAAO,IAAIhC,WAAW;IACxCiC,iBAAiB,GAAGF,OAAO,CAACE,iBAAiB;EAC/C;EAEA,IAAI;IACF,MAAMG,OAAO,GAAG9C,YAAY,CAAC+C,WAAW,CAACL,OAAO,CAAC;IACjDI,OAAO,CAACE,UAAU,CAACN,OAAO,CAAC;IAE3B,IAAI,CAACA,OAAO,EAAE;MACZI,OAAO,CAACG,KAAK,CAAC,CAAC;MACf,OAAOH,OAAO;IAChB;;IAEA;IACA,IAAIH,iBAAiB,EAAE;MACrBlC,eAAe,CAACyC,kBAAkB,CAACP,iBAAiB,CAAC;IACvD;IAEAG,OAAO,CAACK,eAAe,CAAC1B,gBAAgB,CAAC;IAEzC,IAAIqB,OAAO,CAACM,WAAW,CAAC,CAAC,EAAE;MACzBN,OAAO,CAACO,SAAS,CAAC,CAAC;IACrB,CAAC,MAAM;MACLP,OAAO,CAACQ,SAAS,CAAC,CAAC;IACrB;IAEA,OAAOR,OAAO;EAChB,CAAC,CAAC,OAAOhB,KAAK,EAAE;IACdhB,OAAO,CAACgB,KAAK,CAAC,uCAAuC,EAAEA,KAAK,CAAC;IAC7D,OAAO,IAAI;EACb;AACF","ignoreList":[]}
1
+ {"version":3,"names":["DebugToolkit","createNetworkFeature","createConsoleLogFeature","createZustandLogFeature","createNavigationLogFeature","createTrackFeature","createEnvironmentFeature","createClipboardFeature","isDebugMode","__DEV__","featureRegistry","network","console","zustand","navigation","track","environment","clipboard","DEFAULT_FEATURES","resolveFeatureConfigs","configs","features","entries","Object","name","config","creator","warn","undefined","push","resolveDefaultFeatures","map","initializeDebugToolkit","options","enabled","resolvedFeatures","setEnabled","reset","replaceFeatures","hasFeatures","showPanel","hidePanel","error"],"sourceRoot":"../../src","sources":["initialize.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,qBAAqB;AAClD,SAASC,oBAAoB,QAAQ,2BAA2B;AAEhE,SAASC,uBAAuB,QA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;IAC3D;EACF;EAEA,OAAOJ,QAAQ;AACjB;AAEA,SAASS,sBAAsBA,CAAA,EAAsB;EACnD,OAAOZ,gBAAgB,CAACa,GAAG,CAAEP,IAAI,IAAKd,eAAe,CAACc,IAAI,CAAC,CAAE,CAAC,CAAC;AACjE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASQ,sBAAsBA,CACpCC,OAA2B,EACN;EACrB,MAAMC,OAAO,GAAGD,OAAO,EAAEC,OAAO,IAAI1B,WAAW;EAE/C,MAAM2B,gBAAgB,GAAGF,OAAO,EAAEZ,QAAQ,GACtCF,qBAAqB,CAACc,OAAO,CAACZ,QAAQ,CAAC,GACvCS,sBAAsB,CAAC,CAAC;EAE5B,IAAI;IACF9B,YAAY,CAACoC,UAAU,CAACF,OAAO,CAAC;IAEhC,IAAI,CAACA,OAAO,EAAE;MACZlC,YAAY,CAACqC,KAAK,CAAC,CAAC;MACpB,OAAOrC,YAAY;IACrB;IAEAA,YAAY,CAACsC,eAAe,CAACH,gBAAgB,CAAC;IAE9C,IAAInC,YAAY,CAACuC,WAAW,CAAC,CAAC,EAAE;MAC9BvC,YAAY,CAACwC,SAAS,CAAC,CAAC;IAC1B,CAAC,MAAM;MACLxC,YAAY,CAACyC,SAAS,CAAC,CAAC;IAC1B;IAEA,OAAOzC,YAAY;EACrB,CAAC,CAAC,OAAO0C,KAAK,EAAE;IACd9B,OAAO,CAAC8B,KAAK,CAAC,uCAAuC,EAAEA,KAAK,CAAC;IAC7D,OAAO1C,YAAY;EACrB;AACF","ignoreList":[]}
@@ -0,0 +1,460 @@
1
+ "use strict";
2
+
3
+ import { urlRewriter } from '../utils/urlRewriterRegistry';
4
+
5
+ // ─── Axios types ───────────────────────────────────────
6
+
7
+ // ─── XMLHttpRequest types ─────────────────────────────
8
+
9
+ // ─── Shared helpers ────────────────────────────────────
10
+
11
+ function rewriteUrl(url) {
12
+ const rewriter = urlRewriter.get();
13
+ if (!rewriter) {
14
+ return url;
15
+ }
16
+ try {
17
+ return rewriter(url);
18
+ } catch {
19
+ return url;
20
+ }
21
+ }
22
+ function headersToObject(headers) {
23
+ const result = {};
24
+ if (!headers) {
25
+ return result;
26
+ }
27
+ if (typeof headers.forEach === 'function') {
28
+ headers.forEach((value, key) => {
29
+ result[key] = value;
30
+ });
31
+ return result;
32
+ }
33
+ Object.keys(headers).forEach(key => {
34
+ result[key] = headers[key];
35
+ });
36
+ return result;
37
+ }
38
+ function getRequestSnapshot(input, init) {
39
+ const request = input instanceof Request ? input : null;
40
+ return {
41
+ url: typeof input === 'string' ? input : request?.url ?? String(input),
42
+ method: (init?.method || request?.method || 'GET').toUpperCase(),
43
+ headers: init?.headers ? headersToObject(init.headers) : request?.headers ? headersToObject(request.headers) : undefined,
44
+ body: init?.body
45
+ };
46
+ }
47
+ async function parseResponseBody(response) {
48
+ const raw = await response.clone().text();
49
+ if (!raw) {
50
+ return undefined;
51
+ }
52
+ try {
53
+ return JSON.parse(raw);
54
+ } catch {
55
+ return raw;
56
+ }
57
+ }
58
+ function parseMaybeJson(raw) {
59
+ if (!raw) {
60
+ return undefined;
61
+ }
62
+ try {
63
+ return JSON.parse(raw);
64
+ } catch {
65
+ return raw;
66
+ }
67
+ }
68
+ function parseRawHeaders(rawHeaders) {
69
+ if (!rawHeaders) {
70
+ return undefined;
71
+ }
72
+ const headers = {};
73
+ rawHeaders.split(/\r?\n/).forEach(line => {
74
+ const separatorIndex = line.indexOf(':');
75
+ if (separatorIndex <= 0) {
76
+ return;
77
+ }
78
+ const key = line.slice(0, separatorIndex).trim();
79
+ const value = line.slice(separatorIndex + 1).trim();
80
+ if (!key) {
81
+ return;
82
+ }
83
+ headers[key] = value;
84
+ });
85
+ return Object.keys(headers).length > 0 ? headers : undefined;
86
+ }
87
+ function getXMLHttpRequestConstructor() {
88
+ const globalWithXhr = globalThis;
89
+ const candidate = globalWithXhr.XMLHttpRequest;
90
+ if (typeof candidate !== 'function') {
91
+ return undefined;
92
+ }
93
+ const prototype = candidate.prototype;
94
+ if (!prototype || typeof prototype.open !== 'function' || typeof prototype.send !== 'function') {
95
+ return undefined;
96
+ }
97
+ return candidate;
98
+ }
99
+ function getXhrResponseHeaders(xhr) {
100
+ if (typeof xhr.getAllResponseHeaders !== 'function') {
101
+ return undefined;
102
+ }
103
+ try {
104
+ return parseRawHeaders(xhr.getAllResponseHeaders());
105
+ } catch {
106
+ return undefined;
107
+ }
108
+ }
109
+ function getXhrResponseData(xhr) {
110
+ const responseType = typeof xhr.responseType === 'string' ? xhr.responseType : '';
111
+ if (responseType === 'json') {
112
+ return xhr.response;
113
+ }
114
+ if (responseType && responseType !== 'text') {
115
+ return undefined;
116
+ }
117
+ try {
118
+ if (typeof xhr.responseText === 'string') {
119
+ return parseMaybeJson(xhr.responseText);
120
+ }
121
+ } catch {
122
+ return undefined;
123
+ }
124
+ return typeof xhr.response === 'string' ? parseMaybeJson(xhr.response) : xhr.response;
125
+ }
126
+
127
+ // ─── Interceptor manager (encapsulated mutable state) ──
128
+
129
+ let originalFetch = null;
130
+ let fetchRefCount = 0;
131
+ const pendingAxiosRequests = new WeakMap();
132
+ const axiosRegistrations = new WeakMap();
133
+ let originalXMLHttpRequest = null;
134
+ let xhrRefCount = 0;
135
+ const pendingXhrRequests = new WeakMap();
136
+ function stopFetch() {
137
+ fetchRefCount = Math.max(0, fetchRefCount - 1);
138
+ if (fetchRefCount === 0 && originalFetch) {
139
+ globalThis.fetch = originalFetch;
140
+ originalFetch = null;
141
+ }
142
+ }
143
+ export function startFetch(emit) {
144
+ fetchRefCount += 1;
145
+ if (originalFetch) {
146
+ return () => {
147
+ stopFetch();
148
+ };
149
+ }
150
+ originalFetch = globalThis.fetch;
151
+ globalThis.fetch = async function interceptedFetch(input, init) {
152
+ const startTime = Date.now();
153
+ let rewrittenInput = input;
154
+ if (urlRewriter.get()) {
155
+ if (typeof input === 'string') {
156
+ rewrittenInput = rewriteUrl(input);
157
+ } else if (input instanceof Request) {
158
+ rewrittenInput = new Request(rewriteUrl(input.url), input);
159
+ }
160
+ }
161
+ const request = getRequestSnapshot(rewrittenInput, init);
162
+ try {
163
+ const response = await originalFetch.call(globalThis, rewrittenInput, init);
164
+ const duration = Date.now() - startTime;
165
+ try {
166
+ const data = await parseResponseBody(response);
167
+ emit({
168
+ timestamp: startTime,
169
+ duration,
170
+ request,
171
+ response: {
172
+ status: response.status,
173
+ statusText: response.statusText,
174
+ data
175
+ }
176
+ });
177
+ } catch {
178
+ emit({
179
+ timestamp: startTime,
180
+ duration,
181
+ request,
182
+ response: {
183
+ status: response.status,
184
+ statusText: response.statusText
185
+ }
186
+ });
187
+ }
188
+ return response;
189
+ } catch (error) {
190
+ emit({
191
+ timestamp: startTime,
192
+ duration: Date.now() - startTime,
193
+ request,
194
+ error: error instanceof Error ? error.message : String(error)
195
+ });
196
+ throw error;
197
+ }
198
+ };
199
+ return () => {
200
+ stopFetch();
201
+ };
202
+ }
203
+ function emitXhrLog(xhr, emit, error) {
204
+ const pending = pendingXhrRequests.get(xhr);
205
+ if (!pending) {
206
+ return;
207
+ }
208
+ const status = typeof xhr.status === 'number' ? xhr.status : 0;
209
+ const statusText = typeof xhr.statusText === 'string' ? xhr.statusText : undefined;
210
+ emit({
211
+ timestamp: pending.timestamp,
212
+ duration: Date.now() - pending.startTime,
213
+ request: {
214
+ url: pending.url,
215
+ method: pending.method,
216
+ headers: Object.keys(pending.headers).length > 0 ? pending.headers : undefined,
217
+ body: pending.body
218
+ },
219
+ response: error ? undefined : {
220
+ status,
221
+ statusText,
222
+ headers: getXhrResponseHeaders(xhr),
223
+ data: getXhrResponseData(xhr),
224
+ success: status >= 200 && status < 300
225
+ },
226
+ error
227
+ });
228
+ pendingXhrRequests.delete(xhr);
229
+ }
230
+ function isXhrDone(xhr) {
231
+ return typeof xhr.readyState === 'number' && xhr.readyState === (xhr.DONE ?? 4);
232
+ }
233
+ function attachXhrCompletion(xhr, emit) {
234
+ let completed = false;
235
+ const finish = error => {
236
+ if (completed) {
237
+ return;
238
+ }
239
+ completed = true;
240
+ if (typeof xhr.removeEventListener === 'function') {
241
+ xhr.removeEventListener('loadend', onLoadEnd);
242
+ xhr.removeEventListener('error', onError);
243
+ xhr.removeEventListener('abort', onAbort);
244
+ xhr.removeEventListener('timeout', onTimeout);
245
+ }
246
+ emitXhrLog(xhr, emit, error);
247
+ };
248
+ const onLoadEnd = () => finish();
249
+ const onError = () => finish('XMLHttpRequest error');
250
+ const onAbort = () => finish('XMLHttpRequest aborted');
251
+ const onTimeout = () => finish('XMLHttpRequest timeout');
252
+ if (typeof xhr.addEventListener === 'function') {
253
+ xhr.addEventListener('loadend', onLoadEnd);
254
+ xhr.addEventListener('error', onError);
255
+ xhr.addEventListener('abort', onAbort);
256
+ xhr.addEventListener('timeout', onTimeout);
257
+ return;
258
+ }
259
+ const originalOnReadyStateChange = xhr.onreadystatechange;
260
+ const originalOnLoadEnd = xhr.onloadend;
261
+ xhr.onreadystatechange = function interceptedReadyStateChange(event) {
262
+ originalOnReadyStateChange?.call(this, event);
263
+ if (isXhrDone(this)) {
264
+ finish();
265
+ }
266
+ };
267
+ xhr.onloadend = function interceptedLoadEnd(event) {
268
+ originalOnLoadEnd?.call(this, event);
269
+ finish();
270
+ };
271
+ }
272
+ function stopXMLHttpRequest() {
273
+ xhrRefCount = Math.max(0, xhrRefCount - 1);
274
+ if (xhrRefCount === 0 && originalXMLHttpRequest) {
275
+ const prototype = originalXMLHttpRequest.constructor.prototype;
276
+ prototype.open = originalXMLHttpRequest.open;
277
+ prototype.send = originalXMLHttpRequest.send;
278
+ if (originalXMLHttpRequest.setRequestHeader) {
279
+ prototype.setRequestHeader = originalXMLHttpRequest.setRequestHeader;
280
+ }
281
+ originalXMLHttpRequest = null;
282
+ }
283
+ }
284
+ export function startXMLHttpRequest(emit) {
285
+ xhrRefCount += 1;
286
+ if (originalXMLHttpRequest) {
287
+ return () => {
288
+ stopXMLHttpRequest();
289
+ };
290
+ }
291
+ const XMLHttpRequestConstructor = getXMLHttpRequestConstructor();
292
+ if (!XMLHttpRequestConstructor) {
293
+ return () => {
294
+ stopXMLHttpRequest();
295
+ };
296
+ }
297
+ const prototype = XMLHttpRequestConstructor.prototype;
298
+ const originalOpen = prototype.open;
299
+ const originalSend = prototype.send;
300
+ const originalSetRequestHeader = prototype.setRequestHeader;
301
+ originalXMLHttpRequest = {
302
+ constructor: XMLHttpRequestConstructor,
303
+ open: originalOpen,
304
+ send: originalSend,
305
+ setRequestHeader: originalSetRequestHeader
306
+ };
307
+ prototype.open = function interceptedOpen(method, url, async, username, password) {
308
+ const rewrittenUrl = urlRewriter.get() ? rewriteUrl(url) : url;
309
+ const now = Date.now();
310
+ pendingXhrRequests.set(this, {
311
+ method: method.toUpperCase(),
312
+ url: rewrittenUrl,
313
+ headers: {},
314
+ startTime: now,
315
+ timestamp: now
316
+ });
317
+ if (typeof password !== 'undefined') {
318
+ return originalOpen.call(this, method, rewrittenUrl, async, username, password);
319
+ }
320
+ if (typeof username !== 'undefined') {
321
+ return originalOpen.call(this, method, rewrittenUrl, async, username);
322
+ }
323
+ if (typeof async !== 'undefined') {
324
+ return originalOpen.call(this, method, rewrittenUrl, async);
325
+ }
326
+ return originalOpen.call(this, method, rewrittenUrl);
327
+ };
328
+ if (originalSetRequestHeader) {
329
+ prototype.setRequestHeader = function interceptedSetRequestHeader(name, value) {
330
+ const pending = pendingXhrRequests.get(this);
331
+ if (pending) {
332
+ pending.headers[name] = value;
333
+ }
334
+ return originalSetRequestHeader.call(this, name, value);
335
+ };
336
+ }
337
+ prototype.send = function interceptedSend(body) {
338
+ const pending = pendingXhrRequests.get(this);
339
+ if (pending) {
340
+ const now = Date.now();
341
+ pending.body = body;
342
+ pending.startTime = now;
343
+ pending.timestamp = now;
344
+ attachXhrCompletion(this, emit);
345
+ }
346
+ try {
347
+ return originalSend.call(this, body);
348
+ } catch (error) {
349
+ emitXhrLog(this, emit, error instanceof Error ? error.message : String(error));
350
+ throw error;
351
+ }
352
+ };
353
+ return () => {
354
+ stopXMLHttpRequest();
355
+ };
356
+ }
357
+ function teardownAxios(axiosInstance) {
358
+ const registration = axiosRegistrations.get(axiosInstance);
359
+ if (!registration) {
360
+ return;
361
+ }
362
+ registration.refCount -= 1;
363
+ if (registration.refCount > 0) {
364
+ return;
365
+ }
366
+ if (typeof registration.requestId === 'number') {
367
+ axiosInstance.interceptors.request.eject?.(registration.requestId);
368
+ }
369
+ if (typeof registration.responseId === 'number') {
370
+ axiosInstance.interceptors.response.eject?.(registration.responseId);
371
+ }
372
+ axiosRegistrations.delete(axiosInstance);
373
+ }
374
+ export function setupAxios(axiosInstance, emit) {
375
+ const existing = axiosRegistrations.get(axiosInstance);
376
+ if (existing) {
377
+ existing.refCount += 1;
378
+ return () => {
379
+ teardownAxios(axiosInstance);
380
+ };
381
+ }
382
+ const requestId = axiosInstance.interceptors.request.use(config => {
383
+ if (urlRewriter.get() && config.url) {
384
+ const fullUrl = config.baseURL ? `${config.baseURL}${config.url}` : config.url;
385
+ const rewritten = rewriteUrl(fullUrl);
386
+ if (rewritten !== fullUrl) {
387
+ if (config.baseURL && rewritten.startsWith(config.baseURL)) {
388
+ config.url = rewritten.slice(config.baseURL.length);
389
+ } else {
390
+ config.baseURL = '';
391
+ config.url = rewritten;
392
+ }
393
+ }
394
+ }
395
+ pendingAxiosRequests.set(config, {
396
+ startTime: Date.now(),
397
+ timestamp: Date.now()
398
+ });
399
+ return config;
400
+ }, error => Promise.reject(error));
401
+ const responseId = axiosInstance.interceptors.response.use(response => {
402
+ const pending = pendingAxiosRequests.get(response.config);
403
+ if (pending) {
404
+ emit({
405
+ timestamp: pending.timestamp,
406
+ duration: Date.now() - pending.startTime,
407
+ request: {
408
+ url: `${response.config.baseURL || ''}${response.config.url}`,
409
+ method: (response.config.method || 'GET').toUpperCase(),
410
+ headers: response.config.headers,
411
+ body: response.config.data || response.config.params
412
+ },
413
+ response: {
414
+ status: response.status,
415
+ statusText: response.statusText,
416
+ headers: response.headers,
417
+ data: response.data,
418
+ success: response.data && typeof response.data === 'object' ? response.data.success !== false : response.status >= 200 && response.status < 300
419
+ }
420
+ });
421
+ pendingAxiosRequests.delete(response.config);
422
+ }
423
+ return response;
424
+ }, error => {
425
+ if (error.config) {
426
+ const pending = pendingAxiosRequests.get(error.config);
427
+ emit({
428
+ timestamp: pending ? pending.timestamp : Date.now(),
429
+ duration: pending ? Date.now() - pending.startTime : undefined,
430
+ request: {
431
+ url: `${error.config.baseURL || ''}${error.config.url}`,
432
+ method: (error.config.method || 'GET').toUpperCase(),
433
+ headers: error.config.headers,
434
+ body: error.config.data || error.config.params
435
+ },
436
+ error: error.message
437
+ });
438
+ pendingAxiosRequests.delete(error.config);
439
+ }
440
+ return Promise.reject(error);
441
+ });
442
+ axiosRegistrations.set(axiosInstance, {
443
+ refCount: 1,
444
+ requestId: typeof requestId === 'number' ? requestId : undefined,
445
+ responseId: typeof responseId === 'number' ? responseId : undefined
446
+ });
447
+ return () => {
448
+ teardownAxios(axiosInstance);
449
+ };
450
+ }
451
+ export function resetInterceptors() {
452
+ if (originalFetch) {
453
+ globalThis.fetch = originalFetch;
454
+ originalFetch = null;
455
+ }
456
+ fetchRefCount = 0;
457
+ xhrRefCount = 1;
458
+ stopXMLHttpRequest();
459
+ }
460
+ //# sourceMappingURL=networkInterceptor.js.map