@antelopejs/dms-api 0.1.7 → 0.3.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 (346) hide show
  1. package/README.md +99 -8
  2. package/dist/automation/get-api-health.js +4 -3
  3. package/dist/automation/get-api-health.js.map +1 -1
  4. package/dist/automation/route-unhealthy.js +2 -2
  5. package/dist/automation/route-unhealthy.js.map +1 -1
  6. package/dist/automation/scope.d.ts +0 -1
  7. package/dist/automation/scope.js +0 -7
  8. package/dist/automation/scope.js.map +1 -1
  9. package/dist/config.d.ts +4 -0
  10. package/dist/config.js +15 -9
  11. package/dist/config.js.map +1 -1
  12. package/dist/db/models/request_log.model.d.ts +37 -2
  13. package/dist/db/models/request_log.model.js +130 -35
  14. package/dist/db/models/request_log.model.js.map +1 -1
  15. package/dist/db/models/request_log.search.d.ts +5 -0
  16. package/dist/db/models/request_log.search.js +35 -0
  17. package/dist/db/models/request_log.search.js.map +1 -0
  18. package/dist/db/models/request_log.status.d.ts +5 -0
  19. package/dist/db/models/request_log.status.js +9 -0
  20. package/dist/db/models/request_log.status.js.map +1 -0
  21. package/dist/db/models/routes.model.d.ts +1 -0
  22. package/dist/db/models/routes.model.js +5 -1
  23. package/dist/db/models/routes.model.js.map +1 -1
  24. package/dist/db/models/routes_statistics.model.js +1 -1
  25. package/dist/db/models/routes_statistics.model.js.map +1 -1
  26. package/dist/db/tables/api_settings.table.d.ts +1 -0
  27. package/dist/db/tables/api_settings.table.js +4 -0
  28. package/dist/db/tables/api_settings.table.js.map +1 -1
  29. package/dist/db/tables/request_log.table.d.ts +18 -3
  30. package/dist/db/tables/request_log.table.js +34 -1
  31. package/dist/db/tables/request_log.table.js.map +1 -1
  32. package/dist/db/tables/routes.table.d.ts +1 -2
  33. package/dist/db/tables/routes.table.js.map +1 -1
  34. package/dist/db/tables/routes_statistics.table.d.ts +4 -3
  35. package/dist/db/tables/routes_statistics.table.js +5 -1
  36. package/dist/db/tables/routes_statistics.table.js.map +1 -1
  37. package/dist/index.d.ts +1 -1
  38. package/dist/index.js +9 -1
  39. package/dist/index.js.map +1 -1
  40. package/dist/memo.d.ts +5 -0
  41. package/dist/memo.js +36 -0
  42. package/dist/memo.js.map +1 -0
  43. package/dist/pages/blocks.d.ts +3 -0
  44. package/dist/pages/blocks.js +31 -0
  45. package/dist/pages/blocks.js.map +1 -0
  46. package/dist/pages/displays.d.ts +7 -0
  47. package/dist/pages/displays.js +23 -0
  48. package/dist/pages/displays.js.map +1 -0
  49. package/dist/pages/index.d.ts +5 -2
  50. package/dist/pages/index.js +5 -2
  51. package/dist/pages/index.js.map +1 -1
  52. package/dist/pages/logs.d.ts +18 -0
  53. package/dist/pages/logs.js +112 -0
  54. package/dist/pages/logs.js.map +1 -0
  55. package/dist/pages/module.d.ts +3 -0
  56. package/dist/pages/module.js +102 -6
  57. package/dist/pages/module.js.map +1 -1
  58. package/dist/pages/overview.d.ts +14 -0
  59. package/dist/pages/overview.js +215 -0
  60. package/dist/pages/overview.js.map +1 -0
  61. package/dist/pages/period.d.ts +9 -0
  62. package/dist/pages/period.js +24 -0
  63. package/dist/pages/period.js.map +1 -0
  64. package/dist/pages/request-table.d.ts +11 -0
  65. package/dist/pages/request-table.js +187 -0
  66. package/dist/pages/request-table.js.map +1 -0
  67. package/dist/pages/routes.d.ts +15 -0
  68. package/dist/pages/routes.js +269 -0
  69. package/dist/pages/routes.js.map +1 -0
  70. package/dist/pages/scope-chip.d.ts +9 -0
  71. package/dist/pages/scope-chip.js +28 -0
  72. package/dist/pages/scope-chip.js.map +1 -0
  73. package/dist/pages/{logs/page.d.ts → settings.d.ts} +3 -3
  74. package/dist/pages/settings.js +218 -0
  75. package/dist/pages/settings.js.map +1 -0
  76. package/dist/pages/toolbar.d.ts +9 -0
  77. package/dist/pages/toolbar.js +33 -0
  78. package/dist/pages/toolbar.js.map +1 -0
  79. package/dist/realtime.d.ts +2 -0
  80. package/dist/realtime.js +21 -0
  81. package/dist/realtime.js.map +1 -0
  82. package/dist/routes/index.d.ts +2 -2
  83. package/dist/routes/index.js +2 -2
  84. package/dist/routes/index.js.map +1 -1
  85. package/dist/routes/logs.d.ts +173 -2
  86. package/dist/routes/logs.js +177 -86
  87. package/dist/routes/logs.js.map +1 -1
  88. package/dist/routes/overview.d.ts +27 -0
  89. package/dist/routes/overview.js +131 -0
  90. package/dist/routes/overview.js.map +1 -0
  91. package/dist/routes/routes.d.ts +92 -28
  92. package/dist/routes/routes.js +165 -97
  93. package/dist/routes/routes.js.map +1 -1
  94. package/dist/routes/settings.d.ts +16 -11
  95. package/dist/routes/settings.js +62 -54
  96. package/dist/routes/settings.js.map +1 -1
  97. package/dist/routes/tester.d.ts +7 -0
  98. package/dist/routes/tester.js +34 -0
  99. package/dist/routes/tester.js.map +1 -0
  100. package/dist/services/activity.d.ts +49 -0
  101. package/dist/services/activity.js +207 -0
  102. package/dist/services/activity.js.map +1 -0
  103. package/dist/services/aggregate-cache.d.ts +3 -0
  104. package/dist/services/aggregate-cache.js +16 -0
  105. package/dist/services/aggregate-cache.js.map +1 -0
  106. package/dist/services/api-origin.d.ts +1 -0
  107. package/dist/services/api-origin.js +9 -0
  108. package/dist/services/api-origin.js.map +1 -0
  109. package/dist/services/attention.d.ts +45 -0
  110. package/dist/services/attention.js +203 -0
  111. package/dist/services/attention.js.map +1 -0
  112. package/dist/services/composed-text.d.ts +6 -0
  113. package/dist/services/composed-text.js +23 -0
  114. package/dist/services/composed-text.js.map +1 -0
  115. package/dist/services/health-rules.d.ts +49 -0
  116. package/dist/services/health-rules.js +233 -0
  117. package/dist/services/health-rules.js.map +1 -0
  118. package/dist/services/index.d.ts +1 -3
  119. package/dist/services/index.js +3 -3
  120. package/dist/services/index.js.map +1 -1
  121. package/dist/services/introspection/decorators.d.ts +14 -0
  122. package/dist/services/introspection/decorators.js +192 -0
  123. package/dist/services/introspection/decorators.js.map +1 -0
  124. package/dist/services/introspection/errors.js +4 -4
  125. package/dist/services/introspection/errors.js.map +1 -1
  126. package/dist/services/introspection/index.d.ts +6 -8
  127. package/dist/services/introspection/index.js +96 -32
  128. package/dist/services/introspection/index.js.map +1 -1
  129. package/dist/services/introspection/probe.d.ts +2 -1
  130. package/dist/services/introspection/probe.js +11 -0
  131. package/dist/services/introspection/probe.js.map +1 -1
  132. package/dist/services/links.d.ts +25 -0
  133. package/dist/services/links.js +72 -0
  134. package/dist/services/links.js.map +1 -0
  135. package/dist/services/live-feed.d.ts +6 -0
  136. package/dist/services/live-feed.js +18 -0
  137. package/dist/services/live-feed.js.map +1 -0
  138. package/dist/services/live.d.ts +16 -0
  139. package/dist/services/live.js +32 -0
  140. package/dist/services/live.js.map +1 -0
  141. package/dist/services/overview.d.ts +122 -0
  142. package/dist/services/overview.js +324 -0
  143. package/dist/services/overview.js.map +1 -0
  144. package/dist/services/period.d.ts +0 -9
  145. package/dist/services/period.js +5 -52
  146. package/dist/services/period.js.map +1 -1
  147. package/dist/services/request-log/access.d.ts +5 -0
  148. package/dist/services/request-log/access.js +21 -0
  149. package/dist/services/request-log/access.js.map +1 -0
  150. package/dist/services/request-log/capture.d.ts +30 -0
  151. package/dist/services/request-log/capture.js +216 -39
  152. package/dist/services/request-log/capture.js.map +1 -1
  153. package/dist/services/request-log/list.d.ts +36 -0
  154. package/dist/services/request-log/list.js +201 -0
  155. package/dist/services/request-log/list.js.map +1 -0
  156. package/dist/services/request-log/read.d.ts +15 -2
  157. package/dist/services/request-log/read.js +47 -4
  158. package/dist/services/request-log/read.js.map +1 -1
  159. package/dist/services/request-log/redaction.d.ts +16 -3
  160. package/dist/services/request-log/redaction.js +149 -27
  161. package/dist/services/request-log/redaction.js.map +1 -1
  162. package/dist/services/request-log/util.d.ts +10 -3
  163. package/dist/services/request-log/util.js +39 -22
  164. package/dist/services/request-log/util.js.map +1 -1
  165. package/dist/services/route-catalog.d.ts +62 -0
  166. package/dist/services/route-catalog.js +163 -0
  167. package/dist/services/route-catalog.js.map +1 -0
  168. package/dist/services/route-contract.d.ts +66 -0
  169. package/dist/services/route-contract.js +266 -0
  170. package/dist/services/route-contract.js.map +1 -0
  171. package/dist/services/route-health.d.ts +35 -0
  172. package/dist/services/route-health.js +179 -0
  173. package/dist/services/route-health.js.map +1 -0
  174. package/dist/services/route-statistics.d.ts +68 -0
  175. package/dist/services/route-statistics.js +277 -0
  176. package/dist/services/route-statistics.js.map +1 -0
  177. package/dist/services/routes-sync.d.ts +7 -3
  178. package/dist/services/routes-sync.js +96 -20
  179. package/dist/services/routes-sync.js.map +1 -1
  180. package/dist/services/scope.d.ts +0 -1
  181. package/dist/services/scope.js +4 -17
  182. package/dist/services/scope.js.map +1 -1
  183. package/dist/services/settings-form.d.ts +131 -0
  184. package/dist/services/settings-form.js +210 -0
  185. package/dist/services/settings-form.js.map +1 -0
  186. package/dist/services/settings.d.ts +2 -0
  187. package/dist/services/settings.js +5 -0
  188. package/dist/services/settings.js.map +1 -1
  189. package/dist/services/statistics-aggregate.d.ts +6 -41
  190. package/dist/services/statistics-aggregate.js +55 -280
  191. package/dist/services/statistics-aggregate.js.map +1 -1
  192. package/dist/services/statistics-utils.d.ts +7 -12
  193. package/dist/services/statistics-utils.js +36 -51
  194. package/dist/services/statistics-utils.js.map +1 -1
  195. package/dist/services/statistics-write.js +64 -22
  196. package/dist/services/statistics-write.js.map +1 -1
  197. package/dist/services/tester-source.d.ts +11 -0
  198. package/dist/services/tester-source.js +48 -0
  199. package/dist/services/tester-source.js.map +1 -0
  200. package/dist/services/traffic-samples.d.ts +18 -0
  201. package/dist/services/traffic-samples.js +134 -0
  202. package/dist/services/traffic-samples.js.map +1 -0
  203. package/dist/services/traffic.d.ts +43 -0
  204. package/dist/services/traffic.js +270 -0
  205. package/dist/services/traffic.js.map +1 -0
  206. package/dist/services/window.d.ts +48 -0
  207. package/dist/services/window.js +179 -0
  208. package/dist/services/window.js.map +1 -0
  209. package/dist/types/constants.d.ts +11 -20
  210. package/dist/types/constants.js +15 -25
  211. package/dist/types/constants.js.map +1 -1
  212. package/dist/types/index.d.ts +0 -1
  213. package/dist/types/index.js +0 -1
  214. package/dist/types/index.js.map +1 -1
  215. package/dist/types/statistics.d.ts +5 -3
  216. package/dist/types/statistics.js +5 -0
  217. package/dist/types/statistics.js.map +1 -1
  218. package/frontend-vue/app/components/blocks/BetaBadge.vue +20 -0
  219. package/frontend-vue/app/components/blocks/HealthHero.vue +708 -0
  220. package/frontend-vue/app/components/blocks/LiveTraffic.vue +356 -0
  221. package/frontend-vue/app/components/blocks/LogsEmptyState.vue +228 -0
  222. package/frontend-vue/app/components/blocks/LogsFilters.vue +279 -0
  223. package/frontend-vue/app/components/blocks/RequestDetail.vue +722 -0
  224. package/frontend-vue/app/components/blocks/RetentionInput.vue +227 -0
  225. package/frontend-vue/app/components/blocks/RouteDocumentation.vue +611 -0
  226. package/frontend-vue/app/components/blocks/RouteHeader.vue +320 -0
  227. package/frontend-vue/app/components/blocks/RouteTester.vue +1879 -0
  228. package/frontend-vue/app/components/blocks/RouteTree.vue +676 -0
  229. package/frontend-vue/app/components/blocks/ScopeChip.vue +89 -0
  230. package/frontend-vue/app/components/blocks/SettingNumberInput.vue +65 -0
  231. package/frontend-vue/app/components/blocks/SplitLayout.vue +41 -0
  232. package/frontend-vue/app/components/internal/ApiBody.vue +129 -0
  233. package/frontend-vue/app/components/internal/ApiJsonTree.vue +82 -0
  234. package/frontend-vue/app/components/internal/ApiKeyValues.vue +41 -0
  235. package/frontend-vue/app/components/internal/ApiMethodBadge.vue +19 -19
  236. package/frontend-vue/app/components/internal/ApiPath.vue +33 -0
  237. package/frontend-vue/app/components/internal/ApiStatusBadge.vue +20 -15
  238. package/frontend-vue/app/components/internal/ApiTesterBadge.vue +17 -0
  239. package/frontend-vue/app/composables/useApiOrigin.ts +19 -0
  240. package/frontend-vue/app/composables/useApiPeriod.ts +19 -0
  241. package/frontend-vue/app/composables/useApiResource.ts +92 -0
  242. package/frontend-vue/app/composables/useDateFormat.ts +23 -0
  243. package/frontend-vue/app/composables/useLiveMissedErrors.ts +33 -0
  244. package/frontend-vue/app/composables/useRouteDetail.ts +253 -0
  245. package/frontend-vue/app/composables/useRouteSelection.ts +43 -0
  246. package/frontend-vue/app/config/shortcuts-registry.ts +30 -0
  247. package/frontend-vue/app/plugins/displays.ts +92 -0
  248. package/frontend-vue/app/utils/format.ts +281 -0
  249. package/frontend-vue/app/utils/http.ts +127 -0
  250. package/frontend-vue/app/utils/logsQuery.ts +261 -0
  251. package/frontend-vue/app/utils/minuteHistogram.ts +116 -0
  252. package/frontend-vue/app/utils/requestDrawer.ts +257 -0
  253. package/frontend-vue/app/utils/routeExplorer.ts +206 -0
  254. package/frontend-vue/app/utils/search.ts +45 -0
  255. package/frontend-vue/app/utils/settingsForm.ts +119 -0
  256. package/frontend-vue/app/utils/snippets.ts +501 -0
  257. package/frontend-vue/app/utils/testerHistory.ts +354 -0
  258. package/frontend-vue/app/utils/testerRequest.ts +632 -11
  259. package/frontend-vue/dms.frontend.build.ts +7 -0
  260. package/frontend-vue/dms.frontend.ts +10 -3
  261. package/frontend-vue/i18n/locales/api-en-GB.json +866 -0
  262. package/frontend-vue/i18n/locales/api-fr-FR.json +866 -0
  263. package/frontend-vue/package.json +2 -6
  264. package/frontend-vue/pnpm-lock.yaml +97 -3375
  265. package/frontend-vue/tests/format.test.ts +180 -0
  266. package/frontend-vue/tests/http.test.ts +61 -0
  267. package/frontend-vue/tests/logsQuery.test.ts +255 -0
  268. package/frontend-vue/tests/minuteHistogram.test.ts +94 -0
  269. package/frontend-vue/tests/registration.test.ts +24 -7
  270. package/frontend-vue/tests/requestDrawer.test.ts +179 -0
  271. package/frontend-vue/tests/routeExplorer.test.ts +206 -0
  272. package/frontend-vue/tests/settingsForm.test.ts +155 -0
  273. package/frontend-vue/tests/snippets.test.ts +285 -0
  274. package/frontend-vue/tests/testerHistory.test.ts +295 -0
  275. package/frontend-vue/tests/testerRequest.test.ts +471 -76
  276. package/package.json +9 -9
  277. package/dist/middlewares/index.d.ts +0 -1
  278. package/dist/middlewares/index.js +0 -18
  279. package/dist/middlewares/index.js.map +0 -1
  280. package/dist/middlewares/request-log-capture.d.ts +0 -1
  281. package/dist/middlewares/request-log-capture.js +0 -6
  282. package/dist/middlewares/request-log-capture.js.map +0 -1
  283. package/dist/pages/all.d.ts +0 -4
  284. package/dist/pages/all.js +0 -21
  285. package/dist/pages/all.js.map +0 -1
  286. package/dist/pages/logs/page.js +0 -29
  287. package/dist/pages/logs/page.js.map +0 -1
  288. package/dist/pages/routes/page.d.ts +0 -9
  289. package/dist/pages/routes/page.js +0 -29
  290. package/dist/pages/routes/page.js.map +0 -1
  291. package/dist/pages/settings/form.d.ts +0 -3
  292. package/dist/pages/settings/form.js +0 -80
  293. package/dist/pages/settings/form.js.map +0 -1
  294. package/dist/pages/settings/page.d.ts +0 -9
  295. package/dist/pages/settings/page.js +0 -26
  296. package/dist/pages/settings/page.js.map +0 -1
  297. package/dist/pages/summary/page.d.ts +0 -9
  298. package/dist/pages/summary/page.js +0 -29
  299. package/dist/pages/summary/page.js.map +0 -1
  300. package/dist/routes/monitoring.d.ts +0 -17
  301. package/dist/routes/monitoring.js +0 -101
  302. package/dist/routes/monitoring.js.map +0 -1
  303. package/dist/routes/summary.d.ts +0 -32
  304. package/dist/routes/summary.js +0 -181
  305. package/dist/routes/summary.js.map +0 -1
  306. package/dist/services/request-log/index.d.ts +0 -3
  307. package/dist/services/request-log/index.js +0 -12
  308. package/dist/services/request-log/index.js.map +0 -1
  309. package/dist/services/statistics-read.d.ts +0 -4
  310. package/dist/services/statistics-read.js +0 -48
  311. package/dist/services/statistics-read.js.map +0 -1
  312. package/dist/services/tree.d.ts +0 -10
  313. package/dist/services/tree.js +0 -128
  314. package/dist/services/tree.js.map +0 -1
  315. package/dist/types/charts.d.ts +0 -9
  316. package/dist/types/charts.js +0 -3
  317. package/dist/types/charts.js.map +0 -1
  318. package/frontend-vue/app/components/ConfigurationView.vue +0 -187
  319. package/frontend-vue/app/components/DocumentationView.vue +0 -224
  320. package/frontend-vue/app/components/LogDetailDrawer.vue +0 -178
  321. package/frontend-vue/app/components/LogsView.vue +0 -347
  322. package/frontend-vue/app/components/RouteDetailTabs.vue +0 -179
  323. package/frontend-vue/app/components/RouteTree.vue +0 -196
  324. package/frontend-vue/app/components/RoutesView.vue +0 -79
  325. package/frontend-vue/app/components/StatsView.vue +0 -268
  326. package/frontend-vue/app/components/SummaryView.vue +0 -657
  327. package/frontend-vue/app/components/TesterPanel.vue +0 -499
  328. package/frontend-vue/app/components/internal/PeriodSelect.vue +0 -58
  329. package/frontend-vue/app/components/internal/RouteTreeNode.vue +0 -168
  330. package/frontend-vue/app/components/internal/StatusBreakdownBars.vue +0 -162
  331. package/frontend-vue/app/components/internal/StatusDonut.vue +0 -84
  332. package/frontend-vue/app/components/internal/UnitAreaChart.vue +0 -73
  333. package/frontend-vue/app/composables/useApiIntrospection.ts +0 -350
  334. package/frontend-vue/app/composables/useLogDetailDrawer.ts +0 -50
  335. package/frontend-vue/app/composables/useSelectedPeriod.ts +0 -107
  336. package/frontend-vue/app/composables/useStatsPeriods.ts +0 -139
  337. package/frontend-vue/app/custom-layouts/.gitkeep +0 -0
  338. package/frontend-vue/app/custom-pages/.gitkeep +0 -0
  339. package/frontend-vue/app/utils/httpMethod.ts +0 -49
  340. package/frontend-vue/app/utils/statusClass.ts +0 -49
  341. package/frontend-vue/i18n/locales/en-GB.json +0 -240
  342. package/frontend-vue/i18n/locales/fr-FR.json +0 -240
  343. package/frontend-vue/public/.gitkeep +0 -0
  344. package/frontend-vue/server/.gitkeep +0 -0
  345. package/frontend-vue/tests/periods.test.ts +0 -145
  346. package/frontend-vue/tests/persistence.test.ts +0 -45
@@ -0,0 +1,285 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import {
3
+ capturedSnippetRequest,
4
+ fillPath,
5
+ routeSnippetRequest,
6
+ toCurl,
7
+ toFetch,
8
+ withQuery,
9
+ } from '../app/utils/snippets'
10
+ import { closestMatch } from '../app/utils/search'
11
+ import {
12
+ cachedDateFormat,
13
+ formatClock,
14
+ formatMs,
15
+ prettyBody,
16
+ } from '../app/utils/format'
17
+
18
+ describe('snippets', () => {
19
+ const request = {
20
+ method: 'post',
21
+ path: '/api/orders',
22
+ origin: 'https://api.acme.test',
23
+ headers: { 'content-type': 'application/json' },
24
+ body: `{"note":"it's"}`,
25
+ }
26
+
27
+ it('writes a cURL command that survives quotes', () => {
28
+ expect(toCurl(request)).toBe(
29
+ [
30
+ "curl -X POST 'https://api.acme.test/api/orders'",
31
+ " -H 'content-type: application/json'",
32
+ ` -d '{"note":"it'\\''s"}'`,
33
+ ].join(' \\\n'),
34
+ )
35
+ })
36
+
37
+ it('writes a fetch call', () => {
38
+ expect(toFetch(request)).toBe(
39
+ [
40
+ 'await fetch("https://api.acme.test/api/orders", {',
41
+ ' method: "POST",',
42
+ ' headers: {',
43
+ ' "content-type": "application/json",',
44
+ ' },',
45
+ ` body: JSON.stringify({"note":"it's"}),`,
46
+ '})',
47
+ ].join('\n'),
48
+ )
49
+ })
50
+
51
+ it('says where the API and the token come from when it cannot fill them', () => {
52
+ const curl = toCurl({
53
+ method: 'GET',
54
+ path: '/api/customers/:id',
55
+ origin: null,
56
+ session: true,
57
+ })
58
+ expect(curl).toContain('# API_URL: the public URL of the API')
59
+ expect(curl).toContain('# TOKEN: a DMS access token')
60
+ expect(curl).toContain(
61
+ `# TOKEN=$(curl -s -X POST "$API_URL/api/auth/login"`,
62
+ )
63
+ expect(curl).toContain('# ID: value of the path parameter :id')
64
+ expect(curl).toContain(`curl -X GET "$API_URL/api/customers/$ID" \\`)
65
+ expect(curl).toContain(` -H "authorization: Bearer $TOKEN"`)
66
+ })
67
+
68
+ it('fills the path and the query of the last successful call', () => {
69
+ const curl = toCurl(
70
+ routeSnippetRequest(
71
+ {
72
+ method: 'GET',
73
+ path: '/api/customers/:id',
74
+ requiresAuth: false,
75
+ contract: {
76
+ exampleBody: null,
77
+ examplePath: { id: 'C-00988' },
78
+ exampleQuery: { expand: ['orders', 'notes'] },
79
+ },
80
+ },
81
+ 'http://127.0.0.1:5011',
82
+ false,
83
+ ),
84
+ )
85
+ expect(curl).toBe(
86
+ "curl -X GET 'http://127.0.0.1:5011/api/customers/C-00988?expand=orders&expand=notes'",
87
+ )
88
+ })
89
+
90
+ it('turns masked values into variables, never sends [REDACTED]', () => {
91
+ const snippet = capturedSnippetRequest(
92
+ {
93
+ method: 'POST',
94
+ rawPath: '/api/login',
95
+ query: { token: '[REDACTED]', page: '2' },
96
+ requestHeaders: {
97
+ host: '127.0.0.1:5011',
98
+ 'content-length': '42',
99
+ 'accept-encoding': 'gzip, deflate',
100
+ 'x-api-key': '[REDACTED]',
101
+ },
102
+ requestBody:
103
+ '{"email":"a@b.c","password":"[REDACTED]","payment":{"apiKey":"[REDACTED]"}}',
104
+ },
105
+ 'http://127.0.0.1:5011',
106
+ )
107
+ const curl = toCurl(snippet)
108
+ const command = curl
109
+ .split('\n')
110
+ .filter((line) => !line.startsWith('#'))
111
+ .join('\n')
112
+ expect(command).not.toMatch(/REDACTED/)
113
+ expect(curl).toContain(
114
+ '# TOKEN: query parameter token, masked as [REDACTED]',
115
+ )
116
+ expect(curl).toContain('# X_API_KEY: header x-api-key, masked')
117
+ expect(curl).toContain('# PASSWORD: body field password, masked')
118
+ expect(curl).toContain('# API_KEY: body field apiKey, masked')
119
+ expect(curl).toContain(
120
+ `curl -X POST "http://127.0.0.1:5011/api/login?token=$TOKEN&page=2" \\`,
121
+ )
122
+ expect(curl).toContain(' --compressed \\')
123
+ expect(curl).not.toContain('accept-encoding')
124
+ expect(curl).not.toContain('host:')
125
+ expect(curl).toContain(` -H "x-api-key: $X_API_KEY"`)
126
+ expect(curl).toContain(
127
+ ` -d '{"email":"a@b.c","password":"'"$PASSWORD"'","payment":{"apiKey":"'"$API_KEY"'"}}'`,
128
+ )
129
+ const fetch = toFetch(snippet)
130
+ expect(fetch).toContain("const PASSWORD = '' // body field password")
131
+ expect(fetch).toContain(
132
+ 'body: JSON.stringify({"email":"a@b.c","password":PASSWORD,"payment":{"apiKey":API_KEY}}),',
133
+ )
134
+ expect(fetch).toContain(
135
+ 'await fetch(`http://127.0.0.1:5011/api/login?token=${TOKEN}&page=2`, {',
136
+ )
137
+ })
138
+
139
+ it('names masked form values and warns about a truncated body', () => {
140
+ const curl = toCurl(
141
+ capturedSnippetRequest(
142
+ {
143
+ method: 'POST',
144
+ rawPath: '/login',
145
+ requestBody: 'user=ann&password=%5BREDACTED%5D',
146
+ requestBodyTruncated: true,
147
+ },
148
+ 'http://api.test',
149
+ ),
150
+ )
151
+ expect(curl).toContain('# PASSWORD: body value, masked')
152
+ expect(curl).toContain('# Warning: the body was truncated when captured')
153
+ expect(curl).toContain(` -d "user=ann&password=$PASSWORD"`)
154
+ })
155
+
156
+ it('says the body was not captured instead of sending none silently', () => {
157
+ const omitted = (method: string, reason: string | null) =>
158
+ toCurl(
159
+ capturedSnippetRequest(
160
+ {
161
+ method,
162
+ rawPath: '/api/orders',
163
+ requestHeaders: { 'content-type': 'application/json' },
164
+ requestBodyOmitted: reason,
165
+ },
166
+ 'http://api.test',
167
+ ),
168
+ )
169
+ const curl = omitted('POST', 'malformed')
170
+ expect(curl).toContain(
171
+ '# Warning: the body was not captured (its JSON was invalid): add it before running',
172
+ )
173
+ expect(curl).not.toContain(' -d ')
174
+ expect(omitted('POST', 'not-json')).toContain(
175
+ '(only JSON bodies are captured)',
176
+ )
177
+ // Sent empty, or a method that sends none: nothing is missing.
178
+ expect(omitted('POST', 'empty')).not.toContain('Warning')
179
+ expect(omitted('GET', 'not-read')).not.toContain('Warning')
180
+ expect(
181
+ toFetch(
182
+ capturedSnippetRequest(
183
+ { method: 'PUT', rawPath: '/a', requestBodyOmitted: 'too-large' },
184
+ 'http://api.test',
185
+ ),
186
+ ),
187
+ ).toContain(
188
+ '// Warning: the body was not captured (it was larger than the maximum body size)',
189
+ )
190
+ })
191
+
192
+ it('turns a card number masked in a text into a variable of its own', () => {
193
+ const snippet = capturedSnippetRequest(
194
+ {
195
+ method: 'POST',
196
+ rawPath: '/api/orders',
197
+ requestBody:
198
+ '{"note":"paid with [REDACTED] thanks","cardNumber":"[REDACTED]"}',
199
+ },
200
+ 'http://api.test',
201
+ )
202
+ const curl = toCurl(snippet)
203
+ expect(curl).toContain(
204
+ '# CARD_NUMBER: a card number in the text of body field note, masked as [REDACTED]',
205
+ )
206
+ expect(curl).toContain('# CARD_NUMBER_2: body field cardNumber, masked')
207
+ expect(curl).toContain(
208
+ ` -d '{"note":"paid with '"$CARD_NUMBER"' thanks","cardNumber":"'"$CARD_NUMBER_2"'"}'`,
209
+ )
210
+ expect(toFetch(snippet)).toContain(
211
+ 'body: `{"note":"paid with ${CARD_NUMBER} thanks","cardNumber":"${CARD_NUMBER_2}"}`,',
212
+ )
213
+ })
214
+
215
+ it('makes up no body for a route whose calls showed none', () => {
216
+ const curl = toCurl(
217
+ routeSnippetRequest(
218
+ {
219
+ method: 'DELETE',
220
+ path: '/api/orders/:id',
221
+ requiresAuth: false,
222
+ contract: { exampleBody: null, examplePath: { id: '10431' } },
223
+ },
224
+ 'http://127.0.0.1:5011',
225
+ true,
226
+ ),
227
+ )
228
+ expect(curl).toBe("curl -X DELETE 'http://127.0.0.1:5011/api/orders/10431'")
229
+ const seen = toCurl(
230
+ routeSnippetRequest(
231
+ {
232
+ method: 'POST',
233
+ path: '/api/orders',
234
+ requiresAuth: false,
235
+ contract: { exampleBody: { customerId: 'C-1' } },
236
+ },
237
+ 'http://127.0.0.1:5011',
238
+ true,
239
+ ),
240
+ )
241
+ expect(seen).toContain(" -H 'content-type: application/json'")
242
+ expect(seen).toContain(` -d '{"customerId":"C-1"}'`)
243
+ })
244
+
245
+ it('fills path params and leaves the empty ones visible', () => {
246
+ expect(fillPath('/api/orders/:id/lines/:line', { id: 'A 1' })).toBe(
247
+ '/api/orders/A%201/lines/:line',
248
+ )
249
+ expect(withQuery('/api/orders', { page: '2', empty: '' })).toBe(
250
+ '/api/orders?page=2',
251
+ )
252
+ })
253
+ })
254
+
255
+ describe('closestMatch', () => {
256
+ it('finds the route a typo meant', () => {
257
+ expect(
258
+ closestMatch('refnd', ['/api/orders/:id/refund', '/api/customers']),
259
+ ).toBe('/api/orders/:id/refund')
260
+ expect(closestMatch('zzzzzz', ['/api/orders'])).toBeNull()
261
+ })
262
+ })
263
+
264
+ describe('format', () => {
265
+ it('writes durations and times of requests', () => {
266
+ expect(formatMs(48, 'en')).toBe('48 ms')
267
+ expect(formatMs(12_400, 'en')).toBe('12.4 s')
268
+ const now = new Date('2026-10-07T14:31:58.412')
269
+ const en = cachedDateFormat(
270
+ (options) => new Intl.DateTimeFormat('en-GB', options),
271
+ )
272
+ expect(formatClock(now, en, true, now)).toBe('14:31:58.412')
273
+ expect(formatClock(new Date('2026-09-28T14:31:58'), en, false, now)).toBe(
274
+ '28 Sept, 14:31:58',
275
+ )
276
+ })
277
+
278
+ it('pretty-prints JSON bodies only', () => {
279
+ expect(prettyBody('{"a":1}')).toEqual({
280
+ text: '{\n "a": 1\n}',
281
+ json: true,
282
+ })
283
+ expect(prettyBody('plain')).toEqual({ text: 'plain', json: false })
284
+ })
285
+ })
@@ -0,0 +1,295 @@
1
+ import { beforeEach, describe, expect, it } from 'vitest'
2
+ import {
3
+ type DraftRequest,
4
+ exampleRequest,
5
+ hasConfirmedWrite,
6
+ type HistoryEntry,
7
+ historyEntry,
8
+ lastSuccessfulPathValues,
9
+ loadCommonHeaders,
10
+ loadDraft,
11
+ loadHistory,
12
+ lostSecrets,
13
+ patchResult,
14
+ rememberConfirmedWrite,
15
+ sameRequest,
16
+ saveCommonHeaders,
17
+ saveDraft,
18
+ saveHistory,
19
+ secretNames,
20
+ } from '../app/utils/testerHistory'
21
+ import type { TesterResult } from '../app/utils/testerRequest'
22
+
23
+ function memoryStorage(store: Map<string, string>) {
24
+ return {
25
+ getItem: (key: string) => store.get(key) ?? null,
26
+ setItem: (key: string, value: string) => store.set(key, value),
27
+ removeItem: (key: string) => store.delete(key),
28
+ get length() {
29
+ return store.size
30
+ },
31
+ key: (index: number) => [...store.keys()][index] ?? null,
32
+ }
33
+ }
34
+
35
+ const local = new Map<string, string>()
36
+ const session = new Map<string, string>()
37
+ Object.assign(globalThis, {
38
+ window: {
39
+ localStorage: memoryStorage(local),
40
+ sessionStorage: memoryStorage(session),
41
+ },
42
+ })
43
+
44
+ function request(overrides: Partial<DraftRequest> = {}): DraftRequest {
45
+ return {
46
+ bodyMode: 'json',
47
+ body: '{}',
48
+ form: [],
49
+ headers: [
50
+ { name: 'Authorization', value: 'Bearer secret' },
51
+ { name: 'content-type', value: 'application/json' },
52
+ ],
53
+ query: [],
54
+ pathValues: {},
55
+ useSession: true,
56
+ ...overrides,
57
+ }
58
+ }
59
+
60
+ function result(overrides: Partial<TesterResult> = {}): TesterResult {
61
+ return {
62
+ status: 201,
63
+ durationMs: 12,
64
+ headers: {},
65
+ body: 'x'.repeat(10_000),
66
+ auth: 'manual',
67
+ at: 1,
68
+ ...overrides,
69
+ }
70
+ }
71
+
72
+ function entry(at: number): HistoryEntry {
73
+ return {
74
+ at,
75
+ method: 'POST',
76
+ path: '/api/orders',
77
+ request: request(),
78
+ result: result({ at }),
79
+ }
80
+ }
81
+
82
+ describe('tester history', () => {
83
+ beforeEach(() => {
84
+ local.clear()
85
+ session.clear()
86
+ })
87
+
88
+ it('keeps 25 calls per route, without credentials, cutting bodies but not their size', () => {
89
+ saveHistory(
90
+ 'POST /api/orders',
91
+ Array.from({ length: 30 }, (_, index) => entry(index)),
92
+ )
93
+ const saved = loadHistory('POST /api/orders')
94
+ expect(saved).toHaveLength(25)
95
+ expect(saved[0].request.headers).toEqual([
96
+ { name: 'content-type', value: 'application/json' },
97
+ ])
98
+ expect(saved[0].result.body.length).toBe(4096)
99
+ expect(saved[0].result.bodySize).toBe(10_000)
100
+ expect(saved[0].result.bodyTruncated).toBe(true)
101
+ })
102
+
103
+ it('ignores what it cannot read', () => {
104
+ local.set('dmsApi.tester.history.GET /x', '{not json')
105
+ expect(loadHistory('GET /x')).toEqual([])
106
+ local.set(
107
+ 'dmsApi.tester.history.GET /y',
108
+ JSON.stringify([{ at: 1, path: '/y', query: {}, result: {} }]),
109
+ )
110
+ expect(loadHistory('GET /y')).toEqual([])
111
+ })
112
+
113
+ it('says which credentials an entry left out', () => {
114
+ const made = historyEntry('POST', '/api/orders', request(), result())
115
+ expect(made.request.headers).toEqual([
116
+ { name: 'content-type', value: 'application/json' },
117
+ ])
118
+ expect(made.secretsRemoved).toEqual(['Authorization'])
119
+ })
120
+
121
+ it('finds the path values of the last successful call', () => {
122
+ const calls: HistoryEntry[] = [
123
+ {
124
+ ...entry(3),
125
+ request: request({ pathValues: { id: 'TS-404' } }),
126
+ result: result({ status: 404 }),
127
+ },
128
+ {
129
+ ...entry(2),
130
+ request: request({ pathValues: { id: '10477' } }),
131
+ result: result({ status: 200 }),
132
+ },
133
+ ]
134
+ expect(lastSuccessfulPathValues(calls, ['id'])).toEqual({ id: '10477' })
135
+ expect(lastSuccessfulPathValues(calls, ['other'])).toEqual({})
136
+ expect(lastSuccessfulPathValues(calls, [])).toEqual({})
137
+ })
138
+
139
+ it('keeps what the module captured with the call it belongs to', () => {
140
+ const calls = [
141
+ { ...entry(2), result: result({ at: 2, requestId: 'a' }) },
142
+ { ...entry(1), result: result({ at: 1, requestId: 'b' }) },
143
+ ]
144
+ const captured = {
145
+ id: 'log-a',
146
+ status: 500,
147
+ responseTimeMs: 9,
148
+ slow: false,
149
+ }
150
+ const patched = patchResult(calls, 'a', { captured })
151
+ expect(patched[0].result.captured).toEqual(captured)
152
+ expect(patched[1]).toBe(calls[1])
153
+ })
154
+
155
+ it('says which credentials a restored call no longer holds', () => {
156
+ expect(
157
+ secretNames({ Authorization: 'x', accept: '*/*', Cookie: 'c' }),
158
+ ).toEqual(['Authorization', 'Cookie'])
159
+ const sent = ['Authorization', 'authorization', 'X-Api-Key']
160
+ expect(lostSecrets(sent, [])).toEqual(['Authorization', 'X-Api-Key'])
161
+ expect(
162
+ lostSecrets(sent, [
163
+ { name: 'AUTHORIZATION', value: 'Bearer x' },
164
+ { name: 'x-api-key', value: '' },
165
+ ]),
166
+ ).toEqual(['X-Api-Key'])
167
+ })
168
+ })
169
+
170
+ describe('tester drafts', () => {
171
+ beforeEach(() => {
172
+ local.clear()
173
+ session.clear()
174
+ })
175
+
176
+ it('keeps a draft per route for the session, credentials in memory only', () => {
177
+ saveDraft('POST /api/orders', {
178
+ request: request({ body: '{"edited":true}' }),
179
+ origin: 'edited',
180
+ replay: null,
181
+ result: result(),
182
+ })
183
+ const stored = session.get('dmsApi.tester.draft.POST /api/orders') ?? ''
184
+ expect(stored).not.toContain('Bearer secret')
185
+ const draft = loadDraft('POST /api/orders')
186
+ expect(draft?.request.body).toBe('{"edited":true}')
187
+ expect(draft?.request.headers).toContainEqual({
188
+ name: 'Authorization',
189
+ value: 'Bearer secret',
190
+ })
191
+ expect(draft?.result?.status).toBe(201)
192
+ expect(loadDraft('GET /api/orders')).toBeNull()
193
+ saveDraft('POST /api/orders', null)
194
+ expect(loadDraft('POST /api/orders')).toBeNull()
195
+ })
196
+
197
+ it('tells an edited request from its starting point', () => {
198
+ const start = request({ headers: [] })
199
+ expect(
200
+ sameRequest(start, { ...start, headers: [{ name: '', value: '' }] }),
201
+ ).toBe(true)
202
+ expect(sameRequest(start, { ...start, body: '{"a":1}' })).toBe(false)
203
+ expect(
204
+ sameRequest(
205
+ { ...start, bodyMode: 'none', body: 'x' },
206
+ { ...start, bodyMode: 'none', body: 'y' },
207
+ ),
208
+ ).toBe(true)
209
+ })
210
+
211
+ it('starts without a body for GET and DELETE, with the session only where auth is expected', () => {
212
+ const history: HistoryEntry[] = [
213
+ {
214
+ ...entry(1),
215
+ request: request({ pathValues: { id: '10477' } }),
216
+ result: result({ status: 200 }),
217
+ },
218
+ ]
219
+ const route = (
220
+ method: string,
221
+ authStatus: 'required' | 'probable' | 'unknown',
222
+ exampleBody: unknown = null,
223
+ ) => ({ method, pathParams: ['id'], exampleBody, authStatus })
224
+ expect(exampleRequest(route('DELETE', 'required'), history)).toMatchObject({
225
+ bodyMode: 'none',
226
+ body: '',
227
+ pathValues: { id: '10477' },
228
+ useSession: true,
229
+ })
230
+ expect(exampleRequest(route('GET', 'probable'), [])).toMatchObject({
231
+ bodyMode: 'none',
232
+ body: '',
233
+ useSession: true,
234
+ })
235
+ expect(
236
+ exampleRequest(route('POST', 'unknown', { a: 1 }), []),
237
+ ).toMatchObject({
238
+ bodyMode: 'json',
239
+ body: '{\n "a": 1\n}',
240
+ headers: [],
241
+ useSession: false,
242
+ })
243
+ expect(exampleRequest(route('PATCH', 'unknown'), [])).toMatchObject({
244
+ bodyMode: 'json',
245
+ body: '',
246
+ pathValues: { id: '' },
247
+ })
248
+ })
249
+
250
+ it('falls back on the path of the route’s last successful call, decoded', () => {
251
+ const route = {
252
+ method: 'GET',
253
+ pathParams: ['id'],
254
+ exampleBody: null,
255
+ examplePath: { id: 'commande-%C3%A9' },
256
+ authStatus: 'unknown' as const,
257
+ }
258
+ expect(exampleRequest(route, []).pathValues).toEqual({ id: 'commande-é' })
259
+ expect(
260
+ exampleRequest(route, [
261
+ {
262
+ ...entry(1),
263
+ request: request({ pathValues: { id: '10477' } }),
264
+ result: result({ status: 204 }),
265
+ },
266
+ ]).pathValues,
267
+ ).toEqual({ id: '10477' })
268
+ })
269
+
270
+ it('keeps the headers of every route in this browser, credentials until reload', () => {
271
+ saveCommonHeaders([
272
+ { name: 'x-env', value: 'qa' },
273
+ { name: 'Cookie', value: 'sid=1' },
274
+ { name: '', value: '' },
275
+ ])
276
+ expect(local.get('dmsApi.tester.commonHeaders')).toBe(
277
+ JSON.stringify([{ name: 'x-env', value: 'qa' }]),
278
+ )
279
+ expect(loadCommonHeaders()).toEqual([
280
+ { name: 'x-env', value: 'qa' },
281
+ { name: 'Cookie', value: 'sid=1' },
282
+ ])
283
+ })
284
+
285
+ it('remembers the routes a write was confirmed on, for the session', () => {
286
+ expect(hasConfirmedWrite('POST /api/orders')).toBe(false)
287
+ rememberConfirmedWrite('POST /api/orders')
288
+ rememberConfirmedWrite('POST /api/orders')
289
+ expect(hasConfirmedWrite('POST /api/orders')).toBe(true)
290
+ expect(hasConfirmedWrite('PUT /api/orders/:id')).toBe(false)
291
+ expect(session.get('dmsApi.tester.confirmedWrites')).toBe(
292
+ JSON.stringify(['POST /api/orders']),
293
+ )
294
+ })
295
+ })