@jonathanleelx/meddle 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (361) hide show
  1. package/CONFIG_STRUCTURE.md +315 -0
  2. package/LICENSE +21 -0
  3. package/README.md +298 -0
  4. package/bin/commands/mock/add.js +92 -0
  5. package/bin/commands/mock/delete.js +58 -0
  6. package/bin/commands/mock/index.js +50 -0
  7. package/bin/commands/mock/list.js +68 -0
  8. package/bin/commands/mock/toggle.js +64 -0
  9. package/bin/commands/mock/update.js +94 -0
  10. package/bin/commands/route/active.js +141 -0
  11. package/bin/commands/route/add.js +127 -0
  12. package/bin/commands/route/create.js +77 -0
  13. package/bin/commands/route/delete.js +120 -0
  14. package/bin/commands/route/index.js +59 -0
  15. package/bin/commands/route/list.js +67 -0
  16. package/bin/commands/route/preview.js +159 -0
  17. package/bin/commands/route/show.js +111 -0
  18. package/bin/commands/route/update.js +126 -0
  19. package/bin/commands/session/create.js +166 -0
  20. package/bin/commands/session/delete.js +69 -0
  21. package/bin/commands/session/index.js +61 -0
  22. package/bin/commands/session/list.js +42 -0
  23. package/bin/commands/session/prune.js +31 -0
  24. package/bin/commands/start.js +43 -0
  25. package/bin/commands/status.js +115 -0
  26. package/bin/commands/supervise.js +106 -0
  27. package/bin/commands/url.js +30 -0
  28. package/bin/doctor.js +356 -0
  29. package/bin/index +130 -0
  30. package/bin/lib/api-client.js +72 -0
  31. package/bin/lib/file-access.js +337 -0
  32. package/bin/lib/meddle-home.js +20 -0
  33. package/bin/lib/output.js +146 -0
  34. package/bin/lib/parsers.js +127 -0
  35. package/bin/lib/proxy-detect.js +105 -0
  36. package/bin/lib/route-preview.js +180 -0
  37. package/bin/lib/session-args.js +54 -0
  38. package/bin/lib/sessions.js +213 -0
  39. package/dist/cert.d.ts +10 -0
  40. package/dist/cert.d.ts.map +1 -0
  41. package/dist/cert.js +184 -0
  42. package/dist/cert.js.map +1 -0
  43. package/dist/core/application-identity.d.ts +55 -0
  44. package/dist/core/application-identity.d.ts.map +1 -0
  45. package/dist/core/application-identity.js +321 -0
  46. package/dist/core/application-identity.js.map +1 -0
  47. package/dist/core/body-utils.d.ts +2 -0
  48. package/dist/core/body-utils.d.ts.map +1 -0
  49. package/dist/core/body-utils.js +21 -0
  50. package/dist/core/body-utils.js.map +1 -0
  51. package/dist/core/browser.d.ts +2 -0
  52. package/dist/core/browser.d.ts.map +1 -0
  53. package/dist/core/browser.js +92 -0
  54. package/dist/core/browser.js.map +1 -0
  55. package/dist/core/client-identity.d.ts +27 -0
  56. package/dist/core/client-identity.d.ts.map +1 -0
  57. package/dist/core/client-identity.js +136 -0
  58. package/dist/core/client-identity.js.map +1 -0
  59. package/dist/core/config-diagnostics.d.ts +14 -0
  60. package/dist/core/config-diagnostics.d.ts.map +1 -0
  61. package/dist/core/config-diagnostics.js +137 -0
  62. package/dist/core/config-diagnostics.js.map +1 -0
  63. package/dist/core/connect-tunnel.d.ts +5 -0
  64. package/dist/core/connect-tunnel.d.ts.map +1 -0
  65. package/dist/core/connect-tunnel.js +45 -0
  66. package/dist/core/connect-tunnel.js.map +1 -0
  67. package/dist/core/content-encoding.d.ts +2 -0
  68. package/dist/core/content-encoding.d.ts.map +1 -0
  69. package/dist/core/content-encoding.js +77 -0
  70. package/dist/core/content-encoding.js.map +1 -0
  71. package/dist/core/custom-plugin-loader.d.ts +18 -0
  72. package/dist/core/custom-plugin-loader.d.ts.map +1 -0
  73. package/dist/core/custom-plugin-loader.js +178 -0
  74. package/dist/core/custom-plugin-loader.js.map +1 -0
  75. package/dist/core/h2-pool.d.ts +4 -0
  76. package/dist/core/h2-pool.d.ts.map +1 -0
  77. package/dist/core/h2-pool.js +180 -0
  78. package/dist/core/h2-pool.js.map +1 -0
  79. package/dist/core/inspection-dispatch.d.ts +5 -0
  80. package/dist/core/inspection-dispatch.d.ts.map +1 -0
  81. package/dist/core/inspection-dispatch.js +146 -0
  82. package/dist/core/inspection-dispatch.js.map +1 -0
  83. package/dist/core/log-rate-limit.d.ts +34 -0
  84. package/dist/core/log-rate-limit.d.ts.map +1 -0
  85. package/dist/core/log-rate-limit.js +52 -0
  86. package/dist/core/log-rate-limit.js.map +1 -0
  87. package/dist/core/map-local.d.ts +4 -0
  88. package/dist/core/map-local.d.ts.map +1 -0
  89. package/dist/core/map-local.js +195 -0
  90. package/dist/core/map-local.js.map +1 -0
  91. package/dist/core/meddle-home.d.ts +13 -0
  92. package/dist/core/meddle-home.d.ts.map +1 -0
  93. package/dist/core/meddle-home.js +56 -0
  94. package/dist/core/meddle-home.js.map +1 -0
  95. package/dist/core/mock-gate.d.ts +3 -0
  96. package/dist/core/mock-gate.d.ts.map +1 -0
  97. package/dist/core/mock-gate.js +20 -0
  98. package/dist/core/mock-gate.js.map +1 -0
  99. package/dist/core/mock-handler.d.ts +5 -0
  100. package/dist/core/mock-handler.d.ts.map +1 -0
  101. package/dist/core/mock-handler.js +339 -0
  102. package/dist/core/mock-handler.js.map +1 -0
  103. package/dist/core/on-mode-gate.d.ts +4 -0
  104. package/dist/core/on-mode-gate.d.ts.map +1 -0
  105. package/dist/core/on-mode-gate.js +64 -0
  106. package/dist/core/on-mode-gate.js.map +1 -0
  107. package/dist/core/pipeline-gate.d.ts +3 -0
  108. package/dist/core/pipeline-gate.d.ts.map +1 -0
  109. package/dist/core/pipeline-gate.js +34 -0
  110. package/dist/core/pipeline-gate.js.map +1 -0
  111. package/dist/core/pipeline.d.ts +6 -0
  112. package/dist/core/pipeline.d.ts.map +1 -0
  113. package/dist/core/pipeline.js +228 -0
  114. package/dist/core/pipeline.js.map +1 -0
  115. package/dist/core/plugin-bootstrap-runner.d.ts +6 -0
  116. package/dist/core/plugin-bootstrap-runner.d.ts.map +1 -0
  117. package/dist/core/plugin-bootstrap-runner.js +148 -0
  118. package/dist/core/plugin-bootstrap-runner.js.map +1 -0
  119. package/dist/core/plugin-bootstrap.d.ts +3 -0
  120. package/dist/core/plugin-bootstrap.d.ts.map +1 -0
  121. package/dist/core/plugin-bootstrap.js +15 -0
  122. package/dist/core/plugin-bootstrap.js.map +1 -0
  123. package/dist/core/plugin-compiler.d.ts +37 -0
  124. package/dist/core/plugin-compiler.d.ts.map +1 -0
  125. package/dist/core/plugin-compiler.js +172 -0
  126. package/dist/core/plugin-compiler.js.map +1 -0
  127. package/dist/core/plugin-context-factory.d.ts +29 -0
  128. package/dist/core/plugin-context-factory.d.ts.map +1 -0
  129. package/dist/core/plugin-context-factory.js +206 -0
  130. package/dist/core/plugin-context-factory.js.map +1 -0
  131. package/dist/core/plugin-generator.d.ts +47 -0
  132. package/dist/core/plugin-generator.d.ts.map +1 -0
  133. package/dist/core/plugin-generator.js +697 -0
  134. package/dist/core/plugin-generator.js.map +1 -0
  135. package/dist/core/plugin-health.d.ts +3 -0
  136. package/dist/core/plugin-health.d.ts.map +1 -0
  137. package/dist/core/plugin-health.js +54 -0
  138. package/dist/core/plugin-health.js.map +1 -0
  139. package/dist/core/plugin-intercept.d.ts +17 -0
  140. package/dist/core/plugin-intercept.d.ts.map +1 -0
  141. package/dist/core/plugin-intercept.js +133 -0
  142. package/dist/core/plugin-intercept.js.map +1 -0
  143. package/dist/core/plugin-runtime.d.ts +33 -0
  144. package/dist/core/plugin-runtime.d.ts.map +1 -0
  145. package/dist/core/plugin-runtime.js +254 -0
  146. package/dist/core/plugin-runtime.js.map +1 -0
  147. package/dist/core/proxy-context.d.ts +3 -0
  148. package/dist/core/proxy-context.d.ts.map +1 -0
  149. package/dist/core/proxy-context.js +129 -0
  150. package/dist/core/proxy-context.js.map +1 -0
  151. package/dist/core/proxy-record.d.ts +3 -0
  152. package/dist/core/proxy-record.d.ts.map +1 -0
  153. package/dist/core/proxy-record.js +32 -0
  154. package/dist/core/proxy-record.js.map +1 -0
  155. package/dist/core/refactor-config.d.ts +6 -0
  156. package/dist/core/refactor-config.d.ts.map +1 -0
  157. package/dist/core/refactor-config.js +45 -0
  158. package/dist/core/refactor-config.js.map +1 -0
  159. package/dist/core/refactor-status.d.ts +3 -0
  160. package/dist/core/refactor-status.d.ts.map +1 -0
  161. package/dist/core/refactor-status.js +19 -0
  162. package/dist/core/refactor-status.js.map +1 -0
  163. package/dist/core/remote-access.d.ts +40 -0
  164. package/dist/core/remote-access.d.ts.map +1 -0
  165. package/dist/core/remote-access.js +281 -0
  166. package/dist/core/remote-access.js.map +1 -0
  167. package/dist/core/route-decision.d.ts +3 -0
  168. package/dist/core/route-decision.d.ts.map +1 -0
  169. package/dist/core/route-decision.js +20 -0
  170. package/dist/core/route-decision.js.map +1 -0
  171. package/dist/core/route-loader.d.ts +14 -0
  172. package/dist/core/route-loader.d.ts.map +1 -0
  173. package/dist/core/route-loader.js +94 -0
  174. package/dist/core/route-loader.js.map +1 -0
  175. package/dist/core/route-preview.d.ts +15 -0
  176. package/dist/core/route-preview.d.ts.map +1 -0
  177. package/dist/core/route-preview.js +91 -0
  178. package/dist/core/route-preview.js.map +1 -0
  179. package/dist/core/runtime-health.d.ts +92 -0
  180. package/dist/core/runtime-health.d.ts.map +1 -0
  181. package/dist/core/runtime-health.js +205 -0
  182. package/dist/core/runtime-health.js.map +1 -0
  183. package/dist/core/sessions.d.ts +19 -0
  184. package/dist/core/sessions.d.ts.map +1 -0
  185. package/dist/core/sessions.js +93 -0
  186. package/dist/core/sessions.js.map +1 -0
  187. package/dist/core/shadow-compare.d.ts +8 -0
  188. package/dist/core/shadow-compare.d.ts.map +1 -0
  189. package/dist/core/shadow-compare.js +83 -0
  190. package/dist/core/shadow-compare.js.map +1 -0
  191. package/dist/core/shadow-readiness.d.ts +4 -0
  192. package/dist/core/shadow-readiness.d.ts.map +1 -0
  193. package/dist/core/shadow-readiness.js +118 -0
  194. package/dist/core/shadow-readiness.js.map +1 -0
  195. package/dist/core/short-response.d.ts +5 -0
  196. package/dist/core/short-response.d.ts.map +1 -0
  197. package/dist/core/short-response.js +18 -0
  198. package/dist/core/short-response.js.map +1 -0
  199. package/dist/core/static-server.d.ts +9 -0
  200. package/dist/core/static-server.d.ts.map +1 -0
  201. package/dist/core/static-server.js +136 -0
  202. package/dist/core/static-server.js.map +1 -0
  203. package/dist/core/types.d.ts +590 -0
  204. package/dist/core/types.d.ts.map +1 -0
  205. package/dist/core/types.js +4 -0
  206. package/dist/core/types.js.map +1 -0
  207. package/dist/helpers.d.ts +36 -0
  208. package/dist/helpers.d.ts.map +1 -0
  209. package/dist/helpers.js +290 -0
  210. package/dist/helpers.js.map +1 -0
  211. package/dist/plugins/builtin/index.d.ts +3 -0
  212. package/dist/plugins/builtin/index.d.ts.map +1 -0
  213. package/dist/plugins/builtin/index.js +23 -0
  214. package/dist/plugins/builtin/index.js.map +1 -0
  215. package/dist/plugins/builtin/logger-plugin.d.ts +8 -0
  216. package/dist/plugins/builtin/logger-plugin.d.ts.map +1 -0
  217. package/dist/plugins/builtin/logger-plugin.js +121 -0
  218. package/dist/plugins/builtin/logger-plugin.js.map +1 -0
  219. package/dist/plugins/builtin/mock-plugin.d.ts +3 -0
  220. package/dist/plugins/builtin/mock-plugin.d.ts.map +1 -0
  221. package/dist/plugins/builtin/mock-plugin.js +99 -0
  222. package/dist/plugins/builtin/mock-plugin.js.map +1 -0
  223. package/dist/plugins/builtin/router-plugin.d.ts +3 -0
  224. package/dist/plugins/builtin/router-plugin.d.ts.map +1 -0
  225. package/dist/plugins/builtin/router-plugin.js +36 -0
  226. package/dist/plugins/builtin/router-plugin.js.map +1 -0
  227. package/dist/server/agent/model.d.ts +30 -0
  228. package/dist/server/agent/model.d.ts.map +1 -0
  229. package/dist/server/agent/model.js +143 -0
  230. package/dist/server/agent/model.js.map +1 -0
  231. package/dist/server/agent/routes.d.ts +4 -0
  232. package/dist/server/agent/routes.d.ts.map +1 -0
  233. package/dist/server/agent/routes.js +188 -0
  234. package/dist/server/agent/routes.js.map +1 -0
  235. package/dist/server/agent/runtime.d.ts +12 -0
  236. package/dist/server/agent/runtime.d.ts.map +1 -0
  237. package/dist/server/agent/runtime.js +208 -0
  238. package/dist/server/agent/runtime.js.map +1 -0
  239. package/dist/server/agent/tools.d.ts +13 -0
  240. package/dist/server/agent/tools.d.ts.map +1 -0
  241. package/dist/server/agent/tools.js +1201 -0
  242. package/dist/server/agent/tools.js.map +1 -0
  243. package/dist/server/agent/types.d.ts +56 -0
  244. package/dist/server/agent/types.d.ts.map +1 -0
  245. package/dist/server/agent/types.js +3 -0
  246. package/dist/server/agent/types.js.map +1 -0
  247. package/dist/server/config.d.ts +9 -0
  248. package/dist/server/config.d.ts.map +1 -0
  249. package/dist/server/config.js +124 -0
  250. package/dist/server/config.js.map +1 -0
  251. package/dist/server/health.d.ts +4 -0
  252. package/dist/server/health.d.ts.map +1 -0
  253. package/dist/server/health.js +22 -0
  254. package/dist/server/health.js.map +1 -0
  255. package/dist/server/index.d.ts +239 -0
  256. package/dist/server/index.d.ts.map +1 -0
  257. package/dist/server/index.js +44 -0
  258. package/dist/server/index.js.map +1 -0
  259. package/dist/server/logs.d.ts +4 -0
  260. package/dist/server/logs.d.ts.map +1 -0
  261. package/dist/server/logs.js +40 -0
  262. package/dist/server/logs.js.map +1 -0
  263. package/dist/server/mocks.d.ts +9 -0
  264. package/dist/server/mocks.d.ts.map +1 -0
  265. package/dist/server/mocks.js +103 -0
  266. package/dist/server/mocks.js.map +1 -0
  267. package/dist/server/pipeline.d.ts +16 -0
  268. package/dist/server/pipeline.d.ts.map +1 -0
  269. package/dist/server/pipeline.js +159 -0
  270. package/dist/server/pipeline.js.map +1 -0
  271. package/dist/server/plugins.d.ts +32 -0
  272. package/dist/server/plugins.d.ts.map +1 -0
  273. package/dist/server/plugins.js +795 -0
  274. package/dist/server/plugins.js.map +1 -0
  275. package/dist/server/refactor.d.ts +4 -0
  276. package/dist/server/refactor.d.ts.map +1 -0
  277. package/dist/server/refactor.js +86 -0
  278. package/dist/server/refactor.js.map +1 -0
  279. package/dist/server/rule-files.d.ts +34 -0
  280. package/dist/server/rule-files.d.ts.map +1 -0
  281. package/dist/server/rule-files.js +389 -0
  282. package/dist/server/rule-files.js.map +1 -0
  283. package/dist/server/rules.d.ts +4 -0
  284. package/dist/server/rules.d.ts.map +1 -0
  285. package/dist/server/rules.js +40 -0
  286. package/dist/server/rules.js.map +1 -0
  287. package/dist/server/sessions.d.ts +4 -0
  288. package/dist/server/sessions.d.ts.map +1 -0
  289. package/dist/server/sessions.js +20 -0
  290. package/dist/server/sessions.js.map +1 -0
  291. package/index.js +950 -0
  292. package/mcp-server.js +794 -0
  293. package/package.json +92 -0
  294. package/plugins/builtin/index.ts +25 -0
  295. package/plugins/builtin/logger-plugin.ts +126 -0
  296. package/plugins/builtin/mock-plugin.ts +112 -0
  297. package/plugins/builtin/router-plugin.ts +35 -0
  298. package/web/README.md +111 -0
  299. package/web/dist/assets/ai-config-store-DQXVJVn_.js +1 -0
  300. package/web/dist/assets/alert-COF-DIAE.js +1 -0
  301. package/web/dist/assets/arrow-right-B4Mrlj2-.js +1 -0
  302. package/web/dist/assets/babel-DsprIpXZ.js +15 -0
  303. package/web/dist/assets/body-diff-view-D7dCWajG.js +6 -0
  304. package/web/dist/assets/button-BTToMaBW.js +1 -0
  305. package/web/dist/assets/checkbox-DIBarrJx.js +1 -0
  306. package/web/dist/assets/chevron-down-CPngAx4M.js +1 -0
  307. package/web/dist/assets/chevron-right-V1DGIDbL.js +1 -0
  308. package/web/dist/assets/circle-alert-Q8cZk9Rv.js +1 -0
  309. package/web/dist/assets/circle-x-C9USji_R.js +1 -0
  310. package/web/dist/assets/code-5_eJ_XpJ.js +1 -0
  311. package/web/dist/assets/code-fixer-fQtWZ5He.js +20 -0
  312. package/web/dist/assets/copy-BYjq1hdN.js +1 -0
  313. package/web/dist/assets/detail-panel-BX_hxeI0.js +3 -0
  314. package/web/dist/assets/dist-B8XUKgXe.js +1 -0
  315. package/web/dist/assets/dist-Bb9TeEub.js +1 -0
  316. package/web/dist/assets/dist-C5nMErq8.js +1 -0
  317. package/web/dist/assets/dist-C6eaYCUo.js +1 -0
  318. package/web/dist/assets/dist-Cn0y0IRn.js +1 -0
  319. package/web/dist/assets/dist-CxdY_A67.js +5 -0
  320. package/web/dist/assets/dist-D5Dj17P8.js +1 -0
  321. package/web/dist/assets/dist-DZJ9SMlJ.js +1 -0
  322. package/web/dist/assets/es2015-CfXu88Y7.js +41 -0
  323. package/web/dist/assets/estree-BP7k0NIt.js +44 -0
  324. package/web/dist/assets/file-system-access-CtcvBfj4.js +1 -0
  325. package/web/dist/assets/global-panel-shell-ChdO0dWd.js +6 -0
  326. package/web/dist/assets/health-panel-CQeCQ7gr.js +1 -0
  327. package/web/dist/assets/html-6FIWbqxX.js +25 -0
  328. package/web/dist/assets/index-CjqaTnE_.css +2 -0
  329. package/web/dist/assets/index-L7uWxTnp.js +18 -0
  330. package/web/dist/assets/mobile-proxy-panel-Dj1iLami.js +8 -0
  331. package/web/dist/assets/mock-config-BTTCw7RK.js +1 -0
  332. package/web/dist/assets/mock-editor-panel-C-aVfFme.js +1 -0
  333. package/web/dist/assets/monaco-editor-B3brLg8j.js +11 -0
  334. package/web/dist/assets/pencil-line-Cqe41E4h.js +1 -0
  335. package/web/dist/assets/plugin-code-editor-CPjCbJ9g.js +2 -0
  336. package/web/dist/assets/plugin-config-BzmCkvz3.js +1 -0
  337. package/web/dist/assets/plugin-generator-BnEafDF9.js +2 -0
  338. package/web/dist/assets/plugin-test-dialog-BWoWsWV4.js +7 -0
  339. package/web/dist/assets/plus-tVxSydJ8.js +1 -0
  340. package/web/dist/assets/postcss-Dnf30fQU.js +61 -0
  341. package/web/dist/assets/refresh-cw-CG3HaiQT.js +1 -0
  342. package/web/dist/assets/rotate-ccw-CAYM6Vv0.js +1 -0
  343. package/web/dist/assets/route-preview-BX7sfY0O.js +1 -0
  344. package/web/dist/assets/rule-ai-assistant-panel-WBiOOUw5.js +47 -0
  345. package/web/dist/assets/rule-config-CHpVij2M.css +1 -0
  346. package/web/dist/assets/rule-config-fTIZVwg1.js +15 -0
  347. package/web/dist/assets/select-CkFOB61l.js +1 -0
  348. package/web/dist/assets/server-Cpj4KNwN.js +1 -0
  349. package/web/dist/assets/settings-panel-COCYiIUg.js +1 -0
  350. package/web/dist/assets/shield-check-OqUmVLQt.js +1 -0
  351. package/web/dist/assets/smartphone-DKeDuJTU.js +1 -0
  352. package/web/dist/assets/standalone-CjxtLKw-.js +29 -0
  353. package/web/dist/assets/switch-C-Xk56TK.js +1 -0
  354. package/web/dist/assets/syntax-highlight-DVhPdkuV.js +5 -0
  355. package/web/dist/assets/table-CT97lAYq.js +1 -0
  356. package/web/dist/assets/textarea-C6NooVK1.js +1 -0
  357. package/web/dist/assets/wand-sparkles-wkul5vje.js +1 -0
  358. package/web/dist/assets/wifi-D9M35Ajj.js +1 -0
  359. package/web/dist/assets/zap-Djo4cgux.js +1 -0
  360. package/web/dist/index.html +24 -0
  361. package/web/dist/vite.svg +1 -0
package/package.json ADDED
@@ -0,0 +1,92 @@
1
+ {
2
+ "name": "@jonathanleelx/meddle",
3
+ "version": "0.0.1",
4
+ "description": "A simple development proxy server with custom routing rules, mock responses, HTTPS interception, and a plugin system",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "build": "tsc",
8
+ "build:watch": "tsc --watch",
9
+ "prebuild": "rm -rf dist",
10
+ "prepack": "npm run build:web && npm run build",
11
+ "prepublishOnly": "npm run build && npm run test",
12
+ "start": "npm run build && node index.js",
13
+ "start:plugin:off": "MEDDLE_PLUGIN_MODE=off npm start",
14
+ "start:plugin:shadow": "MEDDLE_PLUGIN_MODE=shadow npm start",
15
+ "start:plugin:on": "MEDDLE_PLUGIN_MODE=on npm start",
16
+ "smoke:refactor": "node scripts/refactor-smoke.js",
17
+ "drill:rollout": "node scripts/plugin-rollout-drill.js",
18
+ "test": "vitest run",
19
+ "test:identity": "pnpm run build && node scripts/application-identity-smoke.js",
20
+ "test:e2e": "npm run build:web && npm run build && node tests/e2e/interactions.e2e.cjs",
21
+ "test:e2e:rule-drag": "npm run build:web && npm run build && node tests/e2e/rule-drag.e2e.cjs",
22
+ "test:watch": "vitest",
23
+ "test:refactor": "npm run build && node -c index.js && npm test",
24
+ "bench:logs": "node scripts/log-performance-benchmark.js",
25
+ "start:open": "npm run build && node index.js --open",
26
+ "doctor": "node bin/doctor.js",
27
+ "mcp": "node mcp-server.js",
28
+ "build:web": "cd web && pnpm run build",
29
+ "dev:web": "cd web && pnpm run dev",
30
+ "setup:web": "cd web && pnpm install"
31
+ },
32
+ "bin": {
33
+ "meddle": "bin/index"
34
+ },
35
+ "files": [
36
+ "bin/",
37
+ "dist/",
38
+ "web/dist/",
39
+ "index.js",
40
+ "mcp-server.js",
41
+ "plugins/",
42
+ "LICENSE",
43
+ "CONFIG_STRUCTURE.md",
44
+ "README.md"
45
+ ],
46
+ "keywords": [
47
+ "proxy",
48
+ "dev-proxy",
49
+ "mock",
50
+ "https-proxy",
51
+ "debug",
52
+ "development",
53
+ "plugin"
54
+ ],
55
+ "author": "JonathanLee-LX",
56
+ "license": "MIT",
57
+ "repository": {
58
+ "type": "git",
59
+ "url": "git+https://github.com/JonathanLee-LX/meddle.git"
60
+ },
61
+ "homepage": "https://github.com/JonathanLee-LX/meddle#readme",
62
+ "bugs": {
63
+ "url": "https://github.com/JonathanLee-LX/meddle/issues"
64
+ },
65
+ "engines": {
66
+ "node": ">=18.0.0"
67
+ },
68
+ "dependencies": {
69
+ "@modelcontextprotocol/sdk": "^1.29.0",
70
+ "chalk": "^4.1.2",
71
+ "chokidar": "^3.6.0",
72
+ "debug": "^4.4.3",
73
+ "esbuild": "^0.27.7",
74
+ "express": "^5.2.1",
75
+ "inquirer": "^8.2.7",
76
+ "node-easy-cert": "^1.3.3",
77
+ "portfinder": "^1.0.38",
78
+ "puppeteer-core": "^24.43.1",
79
+ "ws": "^8.21.0",
80
+ "zod": "^4.4.3"
81
+ },
82
+ "devDependencies": {
83
+ "@types/debug": "^4.1.13",
84
+ "@types/express": "^5.0.6",
85
+ "@types/node": "^18.19.130",
86
+ "@types/ws": "^8.18.1",
87
+ "@vitest/coverage-v8": "^4.1.9",
88
+ "nodemon": "^2.0.22",
89
+ "typescript": "^5.9.3",
90
+ "vitest": "^4.1.9"
91
+ }
92
+ }
@@ -0,0 +1,25 @@
1
+ import { Plugin, BuiltinPluginsOptions } from '../../core/types';
2
+
3
+ export function createBuiltinPlugins(options: BuiltinPluginsOptions): Plugin[] {
4
+ const plugins: Plugin[] = [];
5
+
6
+ if (options.enableMock) {
7
+ plugins.push(options.createMockPlugin({
8
+ findMatch: options.findMockMatch!,
9
+ }));
10
+ }
11
+
12
+ if (options.enableRouter) {
13
+ plugins.push(options.createRouterPlugin({
14
+ getRuleMap: options.getRuleMap!,
15
+ getExcludeMap: options.getExcludeMap,
16
+ getRouteRules: options.getRouteRules,
17
+ }));
18
+ }
19
+
20
+ if (options.enableLogger && options.loggerPlugin) {
21
+ plugins.push(options.loggerPlugin);
22
+ }
23
+
24
+ return plugins;
25
+ }
@@ -0,0 +1,126 @@
1
+ import { Plugin, LoggerPluginOptions, HookContext, ResponseContext, ErrorContext, LoggerEntry, LoggerSummary } from '../../core/types';
2
+
3
+ type StatusBucket = '2xx' | '3xx' | '4xx' | '5xx' | 'other';
4
+
5
+ interface LoggerPlugin extends Plugin {
6
+ getRecentEntries(): LoggerEntry[];
7
+ getSummary(): LoggerSummary;
8
+ }
9
+
10
+ export function createBuiltinLoggerPlugin(options: LoggerPluginOptions = {}): LoggerPlugin {
11
+ const maxEntries = typeof options.maxEntries === 'number' ? options.maxEntries : 1000;
12
+ const entries: LoggerEntry[] = [];
13
+ const counters = {
14
+ totalResponses: 0,
15
+ totalErrors: 0,
16
+ byMethod: Object.create(null) as Record<string, number>,
17
+ byStatusBucket: {
18
+ '2xx': 0,
19
+ '3xx': 0,
20
+ '4xx': 0,
21
+ '5xx': 0,
22
+ other: 0,
23
+ },
24
+ duration: {
25
+ min: null as number | null,
26
+ max: null as number | null,
27
+ sum: 0,
28
+ },
29
+ };
30
+
31
+ return {
32
+ manifest: {
33
+ id: 'builtin.logger',
34
+ name: 'Builtin Logger Plugin',
35
+ version: '1.0.0',
36
+ apiVersion: '1.x',
37
+ type: 'builtin',
38
+ permissions: ['proxy:read', 'storage:write'],
39
+ hooks: ['onRequestStart', 'onAfterResponse', 'onError'],
40
+ priority: 90,
41
+ },
42
+ async setup() {},
43
+ onRequestStart(ctx: HookContext): void {
44
+ ctx.meta._pluginRequestStartAt = Date.now();
45
+ },
46
+ onAfterResponse(ctx: ResponseContext): void {
47
+ const startAt = (ctx.meta._pluginRequestStartAt as number) || Date.now();
48
+ const duration = Date.now() - startAt;
49
+ const statusCode = ctx.response.statusCode;
50
+ const method = String(ctx.request.method || 'UNKNOWN').toUpperCase();
51
+
52
+ // 获取路由匹配信息
53
+ const matchedRule = ctx.meta.matchedRule;
54
+ const matchedTarget = ctx.meta.matchedTarget;
55
+ const mockRuleId = ctx.meta.mockRuleId;
56
+ const mockRuleName = ctx.meta.mockRuleName;
57
+ const routerMatched = ctx.meta.routerMatched;
58
+
59
+ // 判断命中类型
60
+ let hitType: 'route' | 'mock' | 'direct' = 'direct';
61
+ if (mockRuleId) {
62
+ hitType = 'mock';
63
+ } else if (routerMatched) {
64
+ hitType = 'route';
65
+ }
66
+
67
+ entries.push({
68
+ type: 'response',
69
+ method,
70
+ url: ctx.request.url,
71
+ statusCode,
72
+ duration,
73
+ ts: Date.now(),
74
+ matchedRule,
75
+ matchedTarget,
76
+ mockRuleId,
77
+ mockRuleName,
78
+ hitType,
79
+ });
80
+
81
+ counters.totalResponses += 1;
82
+ counters.byMethod[method] = (counters.byMethod[method] || 0) + 1;
83
+ const bucket = statusToBucket(statusCode);
84
+ counters.byStatusBucket[bucket] += 1;
85
+ counters.duration.sum += duration;
86
+ counters.duration.min = counters.duration.min == null ? duration : Math.min(counters.duration.min, duration);
87
+ counters.duration.max = counters.duration.max == null ? duration : Math.max(counters.duration.max, duration);
88
+
89
+ if (entries.length > maxEntries) entries.shift();
90
+ },
91
+ onError(ctx: ErrorContext): void {
92
+ entries.push({
93
+ type: 'error',
94
+ phase: ctx.phase,
95
+ message: ctx.error ? ctx.error.message : 'unknown',
96
+ ts: Date.now(),
97
+ });
98
+ counters.totalErrors += 1;
99
+ if (entries.length > maxEntries) entries.shift();
100
+ },
101
+ getRecentEntries(): LoggerEntry[] {
102
+ return entries.slice();
103
+ },
104
+ getSummary(): LoggerSummary {
105
+ return {
106
+ totalResponses: counters.totalResponses,
107
+ totalErrors: counters.totalErrors,
108
+ byMethod: { ...counters.byMethod },
109
+ byStatusBucket: { ...counters.byStatusBucket },
110
+ avgDuration: counters.totalResponses > 0
111
+ ? Number((counters.duration.sum / counters.totalResponses).toFixed(2))
112
+ : 0,
113
+ minDuration: counters.duration.min,
114
+ maxDuration: counters.duration.max,
115
+ };
116
+ },
117
+ };
118
+ }
119
+
120
+ function statusToBucket(statusCode: number): StatusBucket {
121
+ if (statusCode >= 200 && statusCode < 300) return '2xx';
122
+ if (statusCode >= 300 && statusCode < 400) return '3xx';
123
+ if (statusCode >= 400 && statusCode < 500) return '4xx';
124
+ if (statusCode >= 500 && statusCode < 600) return '5xx';
125
+ return 'other';
126
+ }
@@ -0,0 +1,112 @@
1
+ import { Plugin, MockPluginOptions, HookContext } from '../../core/types';
2
+
3
+ /**
4
+ * 检测响应体的 Content-Type
5
+ */
6
+ function detectContentType(body: string): string {
7
+ if (!body || typeof body !== 'string') {
8
+ return 'text/plain; charset=utf-8';
9
+ }
10
+
11
+ const trimmed = body.trim();
12
+
13
+ // 检测 JSON
14
+ if ((trimmed.startsWith('{') && trimmed.endsWith('}')) ||
15
+ (trimmed.startsWith('[') && trimmed.endsWith(']'))) {
16
+ try {
17
+ JSON.parse(trimmed);
18
+ return 'application/json; charset=utf-8';
19
+ } catch {
20
+ // 继续检测其他类型
21
+ }
22
+ }
23
+
24
+ // 检测 HTML
25
+ if (trimmed.startsWith('<!DOCTYPE') ||
26
+ trimmed.startsWith('<html') ||
27
+ /<[a-z][\s\S]*>/i.test(trimmed)) {
28
+ return 'text/html; charset=utf-8';
29
+ }
30
+
31
+ // 检测 XML
32
+ if (trimmed.startsWith('<?xml')) {
33
+ return 'application/xml; charset=utf-8';
34
+ }
35
+
36
+ // 检测 CSS
37
+ if (/[a-z-]+\s*\{[\s\S]*\}/i.test(trimmed) ||
38
+ /@(media|keyframes|import|font-face)/i.test(trimmed)) {
39
+ return 'text/css; charset=utf-8';
40
+ }
41
+
42
+ // 检测 JavaScript
43
+ if (/(function|const|let|var|class|import|export|=>)/i.test(trimmed)) {
44
+ return 'application/javascript; charset=utf-8';
45
+ }
46
+
47
+ // 默认为纯文本
48
+ return 'text/plain; charset=utf-8';
49
+ }
50
+
51
+ export function createBuiltinMockPlugin(options: MockPluginOptions): Plugin {
52
+ const findMatch = options.findMatch;
53
+
54
+ return {
55
+ manifest: {
56
+ id: 'builtin.mock',
57
+ name: 'Builtin Mock Plugin',
58
+ version: '1.0.0',
59
+ apiVersion: '1.x',
60
+ type: 'builtin',
61
+ permissions: ['proxy:read', 'response:shortcircuit'],
62
+ hooks: ['onBeforeProxy'],
63
+ priority: 20,
64
+ },
65
+ async setup() {},
66
+ async onBeforeProxy(ctx: HookContext): Promise<void> {
67
+ if (!ctx || !ctx.request) return;
68
+
69
+ const rule = findMatch(ctx.request.url || '', ctx.request.method);
70
+ if (!rule) return;
71
+ if (rule.bodyType && rule.bodyType !== 'inline') return;
72
+
73
+ const delay = Number(rule.delay || 0);
74
+ if (delay > 0) {
75
+ await new Promise((resolve) => setTimeout(resolve, delay));
76
+ }
77
+
78
+ ctx.meta.mockRuleId = rule.id;
79
+ ctx.meta.mockRuleName = rule.name || '';
80
+
81
+ // 检测或使用自定义的 Content-Type
82
+ const ruleHeaders = rule.headers || {};
83
+ const hasContentType = Object.keys(ruleHeaders).some(
84
+ key => key.toLowerCase() === 'content-type'
85
+ );
86
+ const contentType = hasContentType
87
+ ? undefined // 保留 rule.headers 中的 Content-Type
88
+ : detectContentType(rule.body || '');
89
+
90
+ const responseHeaders: Record<string, string> = {
91
+ 'X-Mock-Rule': encodeURIComponent(rule.name || String(rule.id || '')),
92
+ 'Access-Control-Allow-Origin': '*',
93
+ 'Access-Control-Allow-Methods': '*',
94
+ 'Access-Control-Allow-Headers': '*',
95
+ };
96
+
97
+ // 如果没有自定义 Content-Type,则使用检测到的类型
98
+ if (contentType) {
99
+ responseHeaders['Content-Type'] = contentType;
100
+ }
101
+
102
+ // 合并自定义响应头(会覆盖默认的 Content-Type)
103
+ Object.assign(responseHeaders, ruleHeaders);
104
+
105
+ ctx.respond({
106
+ statusCode: rule.statusCode || 200,
107
+ headers: responseHeaders,
108
+ body: rule.body || '',
109
+ });
110
+ },
111
+ };
112
+ }
@@ -0,0 +1,35 @@
1
+ import { Plugin, RouterPluginOptions, HookContext } from '../../core/types';
2
+ import { findMatchedRouteRule } from '../../helpers';
3
+
4
+ export function createBuiltinRouterPlugin(options: RouterPluginOptions): Plugin {
5
+ const getRouteRules = options.getRouteRules;
6
+
7
+ return {
8
+ manifest: {
9
+ id: 'builtin.router',
10
+ name: 'Builtin Router Plugin',
11
+ version: '1.0.0',
12
+ apiVersion: '1.x',
13
+ type: 'builtin',
14
+ permissions: ['proxy:read', 'proxy:write'],
15
+ hooks: ['onBeforeProxy'],
16
+ priority: 30,
17
+ },
18
+ async setup() {},
19
+ onBeforeProxy(ctx: HookContext): void {
20
+ const sourceUrl = ctx.request && ctx.request.url;
21
+ if (!sourceUrl) return;
22
+
23
+ const routeRules = getRouteRules?.();
24
+ if (!routeRules?.length) return;
25
+
26
+ const matched = findMatchedRouteRule(sourceUrl, routeRules);
27
+ if (matched) {
28
+ ctx.setTarget(matched.resolvedUrl);
29
+ ctx.meta.routerMatched = true;
30
+ ctx.meta.matchedRule = matched.entry.pattern;
31
+ ctx.meta.matchedTarget = matched.resolvedUrl;
32
+ }
33
+ },
34
+ };
35
+ }
package/web/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # React + TypeScript + Vite
2
+
3
+ This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4
+
5
+ Currently, two official plugins are available:
6
+
7
+ - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
8
+ - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9
+
10
+ ## React Compiler
11
+
12
+ The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
13
+
14
+ ## Expanding the ESLint configuration
15
+
16
+ If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
17
+
18
+ ```js
19
+ export default defineConfig([
20
+ globalIgnores(['dist']),
21
+ {
22
+ files: ['**/*.{ts,tsx}'],
23
+ extends: [
24
+ // Other configs...
25
+
26
+ // Remove tseslint.configs.recommended and replace with this
27
+ tseslint.configs.recommendedTypeChecked,
28
+ // Alternatively, use this for stricter rules
29
+ tseslint.configs.strictTypeChecked,
30
+ // Optionally, add this for stylistic rules
31
+ tseslint.configs.stylisticTypeChecked,
32
+
33
+ // Other configs...
34
+ ],
35
+ languageOptions: {
36
+ parserOptions: {
37
+ project: ['./tsconfig.node.json', './tsconfig.app.json'],
38
+ tsconfigRootDir: import.meta.dirname,
39
+ },
40
+ // other options...
41
+ },
42
+ },
43
+ ])
44
+ ```
45
+
46
+ You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
47
+
48
+ ```js
49
+ // eslint.config.js
50
+ import reactX from 'eslint-plugin-react-x'
51
+ import reactDom from 'eslint-plugin-react-dom'
52
+
53
+ export default defineConfig([
54
+ globalIgnores(['dist']),
55
+ {
56
+ files: ['**/*.{ts,tsx}'],
57
+ extends: [
58
+ // Other configs...
59
+ // Enable lint rules for React
60
+ reactX.configs['recommended-typescript'],
61
+ // Enable lint rules for React DOM
62
+ reactDom.configs.recommended,
63
+ ],
64
+ languageOptions: {
65
+ parserOptions: {
66
+ project: ['./tsconfig.node.json', './tsconfig.app.json'],
67
+ tsconfigRootDir: import.meta.dirname,
68
+ },
69
+ // other options...
70
+ },
71
+ },
72
+ ])
73
+ ```
74
+
75
+ ## 环境变量配置
76
+
77
+ 本项目支持通过环境变量自定义Mock功能的语法高亮和验证性能参数。
78
+
79
+ ### 快速开始
80
+
81
+ 1. 复制环境变量示例文件:
82
+ ```bash
83
+ cp .env.example .env
84
+ ```
85
+
86
+ 2. 根据需要编辑 `.env` 文件中的配置项
87
+
88
+ 3. 重新构建项目:
89
+ ```bash
90
+ pnpm run build
91
+ ```
92
+
93
+ ### 可配置参数
94
+
95
+ - `VITE_MAX_HIGHLIGHT_SIZE` - 最大高亮文件大小(字节,默认: 2097152 / 2MB)
96
+ - `VITE_MAX_HIGHLIGHT_LINES` - 最大高亮行数(默认: 10000)
97
+ - `VITE_MAX_JSON_MATCHES` - JSON最大匹配数(默认: 50000)
98
+ - `VITE_MAX_HTML_MATCHES` - HTML最大匹配数(默认: 30000)
99
+ - `VITE_MAX_JS_MATCHES` - JavaScript最大匹配数(默认: 30000)
100
+ - `VITE_ENABLE_RULE_GRAPH_VIEW` - 是否开启规则页的“图表视图”(默认: `false`)
101
+
102
+ ### 详细文档
103
+
104
+ 查看 [ENV_CONFIG.md](./ENV_CONFIG.md) 了解详细的配置说明和性能调优建议。
105
+
106
+ ### 验证配置
107
+
108
+ 运行以下命令检查当前配置:
109
+ ```bash
110
+ node test-env-config.cjs
111
+ ```
@@ -0,0 +1 @@
1
+ var e=`meddle-ai-config`,t={enabled:!1,provider:`openai`,apiKey:``,baseUrl:``,model:``},n={openai:`https://api.openai.com/v1/chat/completions`,anthropic:`https://api.anthropic.com/v1/messages`},r={openai:`gpt-4o-mini`,anthropic:`claude-3-5-sonnet-20241022`};function i(){try{let t=localStorage.getItem(e);if(t){let e=JSON.parse(t);return e.baseUrl||=n[e.provider],e.model||=r[e.provider],e.models||=[],e}}catch(e){console.error(`读取AI配置失败:`,e)}return a()||{...t,models:[]}}function a(){return null}function o(t){try{localStorage.setItem(e,JSON.stringify(t))}catch(e){throw console.error(`保存AI配置失败:`,e),Error(`保存配置失败`)}}function s(){try{localStorage.removeItem(e)}catch(e){console.error(`重置AI配置失败:`,e)}}function c(e){return e.enabled&&!!e.apiKey&&!!e.baseUrl&&!!e.model}function l(e){return{baseUrl:n[e],model:r[e]}}function u(e){if(!e.models||e.models.length===0)return null;if(e.activeModelId){let t=e.models.find(t=>t.id===e.activeModelId);if(t)return t}return e.models[0]}function d(e,t){let n={...t,id:Date.now().toString()},r=[...e.models||[],n];return{...e,models:r,activeModelId:e.activeModelId||n.id}}function f(e,t){let n=(e.models||[]).filter(e=>e.id!==t),r=e.activeModelId;return e.activeModelId===t&&n.length>0&&(r=n[0].id),{...e,models:n,activeModelId:r}}function p(e,t){return{...e,activeModelId:t}}export{l as a,o as c,u as i,p as l,f as n,c as o,i as r,s,d as t};
@@ -0,0 +1 @@
1
+ import{a as e,c as t,f as n,n as r,u as i}from"./button-BTToMaBW.js";n(i(),1);var a=e(),o=t(`relative w-full rounded-lg border px-4 py-3 text-sm grid gap-1`,{variants:{variant:{default:`bg-background text-foreground`,destructive:`border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive`}},defaultVariants:{variant:`default`}});function s({className:e,variant:t,...n}){return(0,a.jsx)(`div`,{role:`alert`,className:r(o({variant:t}),e),...n})}function c({className:e,...t}){return(0,a.jsx)(`h5`,{className:r(`mb-1 font-medium leading-none tracking-tight`,e),...t})}function l({className:e,...t}){return(0,a.jsx)(`div`,{className:r(`text-sm [&_p]:leading-relaxed`,e),...t})}export{l as n,c as r,s as t};
@@ -0,0 +1 @@
1
+ import{l as e}from"./button-BTToMaBW.js";var t=e(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]);export{t};