@antelopejs/dms-api 0.1.6 → 0.2.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 (347) 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 +4 -5
  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/frontend-vue/tests/tooltipTriggers.test.ts +51 -0
  277. package/package.json +8 -8
  278. package/dist/middlewares/index.d.ts +0 -1
  279. package/dist/middlewares/index.js +0 -18
  280. package/dist/middlewares/index.js.map +0 -1
  281. package/dist/middlewares/request-log-capture.d.ts +0 -1
  282. package/dist/middlewares/request-log-capture.js +0 -6
  283. package/dist/middlewares/request-log-capture.js.map +0 -1
  284. package/dist/pages/all.d.ts +0 -4
  285. package/dist/pages/all.js +0 -21
  286. package/dist/pages/all.js.map +0 -1
  287. package/dist/pages/logs/page.js +0 -29
  288. package/dist/pages/logs/page.js.map +0 -1
  289. package/dist/pages/routes/page.d.ts +0 -9
  290. package/dist/pages/routes/page.js +0 -29
  291. package/dist/pages/routes/page.js.map +0 -1
  292. package/dist/pages/settings/form.d.ts +0 -3
  293. package/dist/pages/settings/form.js +0 -80
  294. package/dist/pages/settings/form.js.map +0 -1
  295. package/dist/pages/settings/page.d.ts +0 -9
  296. package/dist/pages/settings/page.js +0 -26
  297. package/dist/pages/settings/page.js.map +0 -1
  298. package/dist/pages/summary/page.d.ts +0 -9
  299. package/dist/pages/summary/page.js +0 -29
  300. package/dist/pages/summary/page.js.map +0 -1
  301. package/dist/routes/monitoring.d.ts +0 -17
  302. package/dist/routes/monitoring.js +0 -101
  303. package/dist/routes/monitoring.js.map +0 -1
  304. package/dist/routes/summary.d.ts +0 -32
  305. package/dist/routes/summary.js +0 -181
  306. package/dist/routes/summary.js.map +0 -1
  307. package/dist/services/request-log/index.d.ts +0 -3
  308. package/dist/services/request-log/index.js +0 -12
  309. package/dist/services/request-log/index.js.map +0 -1
  310. package/dist/services/statistics-read.d.ts +0 -4
  311. package/dist/services/statistics-read.js +0 -48
  312. package/dist/services/statistics-read.js.map +0 -1
  313. package/dist/services/tree.d.ts +0 -10
  314. package/dist/services/tree.js +0 -128
  315. package/dist/services/tree.js.map +0 -1
  316. package/dist/types/charts.d.ts +0 -9
  317. package/dist/types/charts.js +0 -3
  318. package/dist/types/charts.js.map +0 -1
  319. package/frontend-vue/app/components/ConfigurationView.vue +0 -187
  320. package/frontend-vue/app/components/DocumentationView.vue +0 -224
  321. package/frontend-vue/app/components/LogDetailDrawer.vue +0 -178
  322. package/frontend-vue/app/components/LogsView.vue +0 -347
  323. package/frontend-vue/app/components/RouteDetailTabs.vue +0 -179
  324. package/frontend-vue/app/components/RouteTree.vue +0 -196
  325. package/frontend-vue/app/components/RoutesView.vue +0 -79
  326. package/frontend-vue/app/components/StatsView.vue +0 -268
  327. package/frontend-vue/app/components/SummaryView.vue +0 -657
  328. package/frontend-vue/app/components/TesterPanel.vue +0 -499
  329. package/frontend-vue/app/components/internal/PeriodSelect.vue +0 -58
  330. package/frontend-vue/app/components/internal/RouteTreeNode.vue +0 -168
  331. package/frontend-vue/app/components/internal/StatusBreakdownBars.vue +0 -162
  332. package/frontend-vue/app/components/internal/StatusDonut.vue +0 -84
  333. package/frontend-vue/app/components/internal/UnitAreaChart.vue +0 -73
  334. package/frontend-vue/app/composables/useApiIntrospection.ts +0 -350
  335. package/frontend-vue/app/composables/useLogDetailDrawer.ts +0 -50
  336. package/frontend-vue/app/composables/useSelectedPeriod.ts +0 -107
  337. package/frontend-vue/app/composables/useStatsPeriods.ts +0 -139
  338. package/frontend-vue/app/custom-layouts/.gitkeep +0 -0
  339. package/frontend-vue/app/custom-pages/.gitkeep +0 -0
  340. package/frontend-vue/app/utils/httpMethod.ts +0 -49
  341. package/frontend-vue/app/utils/statusClass.ts +0 -49
  342. package/frontend-vue/i18n/locales/en-GB.json +0 -240
  343. package/frontend-vue/i18n/locales/fr-FR.json +0 -240
  344. package/frontend-vue/public/.gitkeep +0 -0
  345. package/frontend-vue/server/.gitkeep +0 -0
  346. package/frontend-vue/tests/periods.test.ts +0 -145
  347. package/frontend-vue/tests/persistence.test.ts +0 -45
@@ -0,0 +1,722 @@
1
+ <script setup lang="ts">
2
+ import { computed, nextTick, ref, watch } from 'vue'
3
+ import { byteLength, formatMs } from '../../utils/format'
4
+ import {
5
+ durationScale,
6
+ fullDateTime,
7
+ isRequestId,
8
+ NO_REDACTIONS,
9
+ originalBodySize,
10
+ type Redactions,
11
+ type RequestPivot,
12
+ requestPivots,
13
+ requestUrl,
14
+ type RouteLatency,
15
+ thresholdRatio,
16
+ withParam,
17
+ } from '../../utils/requestDrawer'
18
+ import { capturedSnippetRequest, toCurl } from '../../utils/snippets'
19
+ import ApiBody from '../internal/ApiBody.vue'
20
+ import ApiKeyValues from '../internal/ApiKeyValues.vue'
21
+ import ApiStatusBadge from '../internal/ApiStatusBadge.vue'
22
+ import ApiTesterBadge from '../internal/ApiTesterBadge.vue'
23
+
24
+ // One captured request, in the DMS side panel on the right, which a request
25
+ // table's row opens (a `sidePanel` row action, `src/pages/request-table.ts`).
26
+ // The DMS draws the panel's header: the request's method and path
27
+ // ("POST /api/orders", its `rowTitle`), "Request 3 of 50 shown", the previous
28
+ // / next buttons, J / K and close, and the not-found state of a `?record=`
29
+ // that names no stored request. Here, the top stays put: where the request
30
+ // went, how it ended, what to do with it. Below, the summary puts
31
+ // the error first, then what the request was and how long it took against
32
+ // the slow threshold; then what was sent and what came back. Every action
33
+ // leads somewhere: the tester, the route, the requests alike.
34
+
35
+ interface RequestLog {
36
+ _id: string
37
+ timestamp: string
38
+ method: string
39
+ uri: string
40
+ rawPath: string
41
+ route: string
42
+ routeRegistered: boolean
43
+ statusCode: number
44
+ /** Null when the request never reached a handler. */
45
+ responseTimeMs: number | null
46
+ slowThresholdMs: number
47
+ /** How the route behaves lately; null for a route not registered. */
48
+ routeLatency?: RouteLatency | null
49
+ /** The method of the handler that answered (GET for a HEAD it served). */
50
+ routeMethod?: string | null
51
+ /** What the capture masked, section by section. */
52
+ redactions: Redactions
53
+ /** `tester` for a request the console's tester sent. */
54
+ source?: string | null
55
+ /** Where the API answers, for the URL and the cURL; null while unknown. */
56
+ apiOrigin?: string | null
57
+ /** The `x-request-id` it came with, when it is not its id. */
58
+ requestId?: string | null
59
+ ip?: string
60
+ userAgent?: string
61
+ pathParams?: Record<string, string>
62
+ query?: Record<string, string | string[]>
63
+ requestHeaders?: Record<string, string>
64
+ requestBody?: string
65
+ requestBodyTruncated?: boolean
66
+ requestBodyOmitted?: string | null
67
+ requestBodySize?: number | null
68
+ responseHeaders?: Record<string, string>
69
+ responseBody?: string
70
+ responseBodyTruncated?: boolean
71
+ responseBodyOmitted?: string | null
72
+ responseBodySize?: number | null
73
+ error?: { message: string; stack?: string }
74
+ links: {
75
+ route: string | null
76
+ tester: string | null
77
+ sameError: string | null
78
+ sameRoute: string
79
+ samePath?: string | null
80
+ }
81
+ }
82
+
83
+ /** Where the console's pages are: the page on screen names its own links. */
84
+ const MODULE_BASE = '/modules/api'
85
+ /** Pages a link to the request logs may name as its origin (`?from=`). */
86
+ const LINK_ORIGINS = ['overview', 'routes']
87
+ /** The settings an owner reads: body capture off says why a body is missing. */
88
+ const SETTINGS_SUMMARY_API = '/api/monitoring/settings/summary'
89
+ /** Where the captured headers are listed. */
90
+ const HEADERS_SETTINGS_LINK = '/modules/api/settings#requestLogCaptureHeaders'
91
+ const TESTER_SOURCE = 'tester'
92
+ /** The icon of each list of related requests in "See also". */
93
+ const PIVOT_ICONS: Record<RequestPivot['kind'], string> = {
94
+ same_route: 'i-ph-list-magnifying-glass',
95
+ same_path: 'i-ph-path',
96
+ slow_route: 'i-ph-timer',
97
+ }
98
+
99
+ const props = defineProps<{
100
+ /** The row the table opened: its `_id` names the request. */
101
+ rowData?: { _id?: string }
102
+ /**
103
+ * Where the table reads a request in full, by its own permission (`/<id>`
104
+ * appended), so the panel opens wherever its rows show.
105
+ */
106
+ detailUrl: string
107
+ }>()
108
+
109
+ const { t } = useI18n()
110
+ const {
111
+ formatLocale: locale,
112
+ formatNumber: count,
113
+ formatRelativeTime,
114
+ } = useRegionalFormat({ locale: 'format' })
115
+ const toast = useToast()
116
+ // Read through the router, not `useDmsRoute()`: each call of it reassigns
117
+ // the route's query, which the request tables watch for their filters.
118
+ const router = useDmsRouter()
119
+
120
+ const requestId = computed(() => props.rowData?._id ?? null)
121
+
122
+ // The page the panel is open on: a link to the logs says where it came from,
123
+ // and the route on screen is not offered again.
124
+ const page = computed(() => {
125
+ const current = router.currentRoute.value.path
126
+ return current.startsWith(`${MODULE_BASE}/`)
127
+ ? current.slice(MODULE_BASE.length + 1)
128
+ : ''
129
+ })
130
+
131
+ const {
132
+ data: log,
133
+ error,
134
+ pending,
135
+ refresh,
136
+ } = useApiResource<RequestLog>(() =>
137
+ requestId.value && isRequestId(requestId.value)
138
+ ? `${props.detailUrl}/${encodeURIComponent(requestId.value)}`
139
+ : null,
140
+ )
141
+ const apiOrigin = useApiOrigin(() => log.value?.apiOrigin)
142
+
143
+ const tab = ref('overview')
144
+ const tabs = computed(() => [
145
+ { label: t('api.request.tabs.overview'), value: 'overview' },
146
+ { label: t('api.request.tabs.request'), value: 'request' },
147
+ { label: t('api.request.tabs.response'), value: 'response' },
148
+ ])
149
+
150
+ // Why nothing shows: a link naming no request, a request pruned, a role that
151
+ // lists requests but may not read them, the console not answering.
152
+ const failure = computed<'invalid' | 'not_found' | 'forbidden' | 'error'>(
153
+ () => {
154
+ if (requestId.value && !isRequestId(requestId.value)) return 'invalid'
155
+ const status = errorStatus(error.value)
156
+ if (status === 404) return 'not_found'
157
+ if (status === 401 || status === 403) return 'forbidden'
158
+ return 'error'
159
+ },
160
+ )
161
+
162
+ // Closing is the DMS header's: only a failed read offers something here.
163
+ const failureActions = computed(() =>
164
+ failure.value === 'error'
165
+ ? [
166
+ {
167
+ label: t('api.common.retry'),
168
+ icon: 'i-ph-arrow-clockwise',
169
+ onClick: () => refresh(),
170
+ },
171
+ ]
172
+ : [],
173
+ )
174
+
175
+ // --- the header ---
176
+ const url = computed(() =>
177
+ log.value
178
+ ? requestUrl(apiOrigin.value ?? '', log.value.rawPath, log.value.query)
179
+ : '',
180
+ )
181
+ const isTester = computed(() => log.value?.source === TESTER_SOURCE)
182
+ const timing = computed(() =>
183
+ log.value && log.value.responseTimeMs !== null
184
+ ? durationScale(log.value.responseTimeMs, log.value.slowThresholdMs)
185
+ : null,
186
+ )
187
+ const ratio = computed(() =>
188
+ thresholdRatio(timing.value?.ratio ?? 0, locale.value),
189
+ )
190
+
191
+ // --- the error, folded to six lines ---
192
+ const message = ref<HTMLElement | null>(null)
193
+ const messageOpen = ref(false)
194
+ const messageClamped = ref(false)
195
+
196
+ watch([message, () => log.value?.error?.message], async ([element]) => {
197
+ messageClamped.value = false
198
+ if (!element) return
199
+ await nextTick()
200
+ messageClamped.value = element.scrollHeight > element.clientHeight + 1
201
+ })
202
+
203
+ // --- the summary ---
204
+ const general = computed(() => {
205
+ const value = log.value
206
+ if (!value) return []
207
+ const rows: { key: string; label: string; value: string; copy?: boolean }[] =
208
+ [
209
+ { key: 'url', label: t('api.request.fields.url'), value: url.value },
210
+ {
211
+ key: 'date',
212
+ label: t('api.request.fields.date'),
213
+ value: `${fullDateTime(value.timestamp, dateFormat.value)} · ${formatRelativeTime(value.timestamp)}`,
214
+ },
215
+ {
216
+ key: 'route',
217
+ label: t('api.request.fields.route'),
218
+ value: value.routeRegistered
219
+ ? value.route
220
+ : `${value.route} · ${t('api.request.unmatched')}`,
221
+ },
222
+ ]
223
+ if (value.ip)
224
+ rows.push({ key: 'ip', label: t('api.request.fields.ip'), value: value.ip })
225
+ if (value.userAgent)
226
+ rows.push({
227
+ key: 'user_agent',
228
+ label: t('api.request.fields.user_agent'),
229
+ value: value.userAgent,
230
+ })
231
+ rows.push({
232
+ key: 'request_id',
233
+ label: t('api.request.fields.request_id'),
234
+ value: value._id,
235
+ copy: true,
236
+ })
237
+ if (value.requestId && value.requestId !== value._id)
238
+ rows.push({
239
+ key: 'header_request_id',
240
+ label: 'x-request-id',
241
+ value: value.requestId,
242
+ copy: true,
243
+ })
244
+ return rows
245
+ })
246
+
247
+ // --- actions ---
248
+ const curl = computed(() =>
249
+ log.value ? toCurl(capturedSnippetRequest(log.value, apiOrigin.value)) : '',
250
+ )
251
+
252
+ async function copyCurl() {
253
+ try {
254
+ await navigator.clipboard.writeText(curl.value)
255
+ toast.add({
256
+ title: t('api.request.curl_copied'),
257
+ color: 'success',
258
+ icon: 'i-ph-check',
259
+ })
260
+ } catch {
261
+ toast.add({
262
+ title: t('api.request.copy_failed'),
263
+ color: 'error',
264
+ icon: 'i-ph-warning',
265
+ })
266
+ }
267
+ }
268
+
269
+ // The tester takes over with `?replay=<id>`: it reads the request itself.
270
+ const testerLink = computed(() =>
271
+ log.value?.links.tester
272
+ ? `${log.value.links.tester}&replay=${encodeURIComponent(log.value._id)}`
273
+ : null,
274
+ )
275
+
276
+ function logsLink(href: string): string {
277
+ return LINK_ORIGINS.includes(page.value)
278
+ ? withParam(href, 'from', page.value)
279
+ : href
280
+ }
281
+
282
+ const sameErrorLink = computed(() =>
283
+ log.value?.links.sameError ? logsLink(log.value.links.sameError) : null,
284
+ )
285
+
286
+ const seeAlso = computed(() => {
287
+ const value = log.value
288
+ if (!value) return []
289
+ const onRoute =
290
+ page.value === 'routes' &&
291
+ router.currentRoute.value.query.route === value.route
292
+ return [
293
+ ...(value.links.route && !onRoute
294
+ ? [
295
+ {
296
+ label: t('api.request.open_route'),
297
+ icon: 'i-ph-tree-structure',
298
+ to: value.links.route,
299
+ },
300
+ ]
301
+ : []),
302
+ ...requestPivots(value).map((pivot) => ({
303
+ label: t(`api.request.${pivot.kind}`),
304
+ icon: PIVOT_ICONS[pivot.kind],
305
+ to: logsLink(pivot.to),
306
+ })),
307
+ ]
308
+ })
309
+
310
+ // A log stored without the reason of a missing body: the body capture turned
311
+ // off says it. Read once per session, only then, and by an owner only: a
312
+ // refusal leaves the generic reason.
313
+ // Null until asked, false once refused.
314
+ const settingsSummary = useDmsState<
315
+ { requestLogMaxBodyKb?: number } | false | null
316
+ >('dms-api:settings-summary', () => null)
317
+ const { $authFetch } = useAuthFetch()
318
+
319
+ watch(
320
+ log,
321
+ (value) => {
322
+ if (!value || settingsSummary.value !== null) return
323
+ const unexplained =
324
+ (!value.requestBody && !value.requestBodyOmitted) ||
325
+ (!value.responseBody && !value.responseBodyOmitted)
326
+ if (!unexplained) return
327
+ settingsSummary.value = false
328
+ $authFetch<{ requestLogMaxBodyKb?: number }>(SETTINGS_SUMMARY_API)
329
+ .then((summary) => (settingsSummary.value = summary))
330
+ .catch(() => undefined)
331
+ },
332
+ { immediate: true },
333
+ )
334
+
335
+ function omission(reason: string | null | undefined) {
336
+ if (reason) return reason
337
+ const summary = settingsSummary.value
338
+ return summary && summary.requestLogMaxBodyKb === 0 ? 'disabled' : null
339
+ }
340
+
341
+ const redactions = computed(() => log.value?.redactions ?? NO_REDACTIONS)
342
+ const requestSize = computed(() =>
343
+ originalBodySize(
344
+ byteLength(log.value?.requestBody ?? ''),
345
+ log.value?.requestBodyTruncated,
346
+ log.value?.requestBodySize,
347
+ log.value?.requestHeaders,
348
+ ),
349
+ )
350
+ const responseSize = computed(() =>
351
+ originalBodySize(
352
+ byteLength(log.value?.responseBody ?? ''),
353
+ log.value?.responseBodyTruncated,
354
+ log.value?.responseBodySize,
355
+ log.value?.responseHeaders,
356
+ ),
357
+ )
358
+
359
+ const dateFormat = useDateFormat()
360
+ </script>
361
+
362
+ <template>
363
+ <section class="-m-4 flex min-h-0 flex-col" :aria-busy="pending">
364
+ <header
365
+ v-if="log"
366
+ class="border-default bg-default sticky top-0 z-10 flex shrink-0 flex-col gap-2.5 border-b px-4 pt-3 sm:px-5"
367
+ >
368
+ <div class="flex min-w-0 items-center gap-1">
369
+ <bdi
370
+ class="text-muted min-w-0 truncate font-mono text-[11.5px]"
371
+ :title="url"
372
+ >
373
+ {{ url }}
374
+ </bdi>
375
+ <DmsCopyButton :value="url" :aria-label="t('api.request.copy_url')" />
376
+ </div>
377
+
378
+ <div class="flex flex-wrap items-center gap-x-3 gap-y-1.5 text-[12px]">
379
+ <ApiStatusBadge :status="log.statusCode" text size="sm" />
380
+ <span
381
+ v-if="timing"
382
+ class="font-mono tabular-nums"
383
+ :class="timing.slow ? 'text-warning font-semibold' : 'text-muted'"
384
+ >
385
+ {{ formatMs(log.responseTimeMs ?? 0, locale) }}
386
+ </span>
387
+ <UTooltip v-else :text="t('api.request.not_measured_hint')">
388
+ <span class="text-dimmed font-mono" tabindex="0">
389
+ — {{ t('api.request.not_measured') }}
390
+ </span>
391
+ </UTooltip>
392
+ <UBadge
393
+ v-if="timing?.slow"
394
+ size="sm"
395
+ color="warning"
396
+ variant="subtle"
397
+ icon="i-ph-timer"
398
+ :label="t('api.request.slow_ratio', { ratio })"
399
+ />
400
+ <ApiTesterBadge v-if="isTester" />
401
+ <span
402
+ class="text-dimmed font-mono text-[11.5px]"
403
+ :title="fullDateTime(log.timestamp, dateFormat)"
404
+ >
405
+ {{ formatRelativeTime(log.timestamp) }}
406
+ </span>
407
+ </div>
408
+
409
+ <div class="flex flex-wrap items-center gap-2">
410
+ <UButton
411
+ v-if="testerLink"
412
+ :to="testerLink"
413
+ size="sm"
414
+ icon="i-ph-paper-plane-tilt"
415
+ :label="t('api.request.replay')"
416
+ />
417
+ <UButton
418
+ size="sm"
419
+ color="neutral"
420
+ variant="outline"
421
+ icon="i-ph-terminal"
422
+ :label="t('api.request.copy_curl')"
423
+ @click="copyCurl"
424
+ />
425
+ <UButton
426
+ v-if="sameErrorLink"
427
+ :to="sameErrorLink"
428
+ size="sm"
429
+ color="neutral"
430
+ variant="outline"
431
+ icon="i-ph-copy-simple"
432
+ :label="t('api.request.same_error')"
433
+ />
434
+ <UDropdownMenu :items="seeAlso" :content="{ align: 'end' }">
435
+ <UButton
436
+ size="sm"
437
+ color="neutral"
438
+ variant="ghost"
439
+ trailing-icon="i-ph-caret-down"
440
+ :label="t('api.request.see_also')"
441
+ />
442
+ </UDropdownMenu>
443
+ </div>
444
+
445
+ <UTabs
446
+ v-model="tab"
447
+ :items="tabs"
448
+ :content="false"
449
+ variant="link"
450
+ size="sm"
451
+ />
452
+ </header>
453
+
454
+ <div class="min-h-0 flex-1 overflow-y-auto px-4 py-4 sm:px-5">
455
+ <div v-if="pending" class="flex flex-col gap-3">
456
+ <USkeleton class="h-4 w-1/2" />
457
+ <USkeleton class="h-28 w-full" />
458
+ <USkeleton class="h-20 w-full" />
459
+ </div>
460
+
461
+ <DmsEmptyState
462
+ v-else-if="!log"
463
+ variant="error"
464
+ :title="t(`api.request.${failure}_title`)"
465
+ :description="t(`api.request.${failure}_description`)"
466
+ :actions="failureActions"
467
+ />
468
+
469
+ <div v-else-if="tab === 'overview'" class="flex flex-col gap-5">
470
+ <section v-if="log.error" class="flex flex-col gap-2">
471
+ <DmsEyebrow :label="t('api.request.error')" />
472
+ <div class="border-error/40 bg-error/5 rounded-md border px-3 py-2.5">
473
+ <div class="flex items-start gap-2">
474
+ <p
475
+ ref="message"
476
+ class="text-error min-w-0 grow whitespace-pre-wrap text-sm font-semibold [overflow-wrap:anywhere]"
477
+ :class="messageOpen ? '' : 'line-clamp-6'"
478
+ >
479
+ <bdi>{{ log.error.message }}</bdi>
480
+ </p>
481
+ <DmsCopyButton
482
+ :value="log.error.message"
483
+ :aria-label="t('api.request.copy_message')"
484
+ />
485
+ </div>
486
+ <UButton
487
+ v-if="messageClamped || messageOpen"
488
+ size="xs"
489
+ color="error"
490
+ variant="link"
491
+ class="mt-1 px-0"
492
+ :label="
493
+ messageOpen
494
+ ? t('api.request.show_less')
495
+ : t('api.request.show_all')
496
+ "
497
+ :aria-expanded="messageOpen"
498
+ @click="messageOpen = !messageOpen"
499
+ />
500
+ </div>
501
+ <DmsCodeSnippet
502
+ v-if="log.error.stack"
503
+ :code="log.error.stack"
504
+ max-height="18rem"
505
+ wrap="anywhere"
506
+ />
507
+ </section>
508
+
509
+ <section class="flex flex-col gap-2">
510
+ <DmsEyebrow :label="t('api.request.general')" />
511
+ <dl
512
+ class="grid grid-cols-[max-content_minmax(0,1fr)] gap-x-4 gap-y-1.5 text-[12.5px]"
513
+ >
514
+ <template v-for="row in general" :key="row.key">
515
+ <dt class="text-muted">{{ row.label }}</dt>
516
+ <dd class="text-default flex min-w-0 items-start gap-1">
517
+ <bdi
518
+ class="min-w-0 font-mono text-[12px] [overflow-wrap:anywhere]"
519
+ >
520
+ {{ row.value }}
521
+ </bdi>
522
+ <DmsCopyButton
523
+ v-if="row.copy"
524
+ :value="row.value"
525
+ class="-my-1.5"
526
+ />
527
+ </dd>
528
+ </template>
529
+ <template v-if="isTester">
530
+ <dt class="text-muted">{{ t('api.request.fields.source') }}</dt>
531
+ <dd class="text-default">{{ t('api.request.source_tester') }}</dd>
532
+ </template>
533
+ </dl>
534
+ </section>
535
+
536
+ <section class="flex flex-col gap-2">
537
+ <DmsEyebrow :label="t('api.request.timing')" />
538
+ <template v-if="timing">
539
+ <div class="flex flex-wrap items-baseline gap-x-2 gap-y-1">
540
+ <span class="text-highlighted font-mono text-xl font-semibold">
541
+ {{ formatMs(log.responseTimeMs ?? 0, locale) }}
542
+ </span>
543
+ <span
544
+ class="text-xs"
545
+ :class="
546
+ timing.slow ? 'text-warning font-semibold' : 'text-dimmed'
547
+ "
548
+ >
549
+ {{
550
+ timing.slow
551
+ ? t('api.request.slow_ratio', { ratio })
552
+ : t('api.request.threshold_ratio', { ratio })
553
+ }}
554
+ </span>
555
+ <span
556
+ v-if="log.routeLatency"
557
+ class="text-dimmed font-mono text-xs tabular-nums"
558
+ >
559
+ {{
560
+ t(
561
+ 'api.request.route_latency',
562
+ {
563
+ days: count(log.routeLatency.windowDays),
564
+ p50: formatMs(log.routeLatency.p50, locale),
565
+ p95: formatMs(log.routeLatency.p95, locale),
566
+ },
567
+ log.routeLatency.windowDays,
568
+ )
569
+ }}
570
+ </span>
571
+ </div>
572
+ <div
573
+ class="bg-elevated relative h-2 rounded-full"
574
+ role="meter"
575
+ :aria-label="t('api.request.meter_label')"
576
+ aria-valuemin="0"
577
+ :aria-valuemax="Math.round(timing.max)"
578
+ :aria-valuenow="Math.round(log.responseTimeMs ?? 0)"
579
+ :aria-valuetext="formatMs(log.responseTimeMs ?? 0, locale)"
580
+ >
581
+ <div
582
+ class="h-full rounded-full"
583
+ :class="timing.slow ? 'bg-warning' : 'bg-primary'"
584
+ :style="{ width: `${timing.share}%` }"
585
+ />
586
+ <div
587
+ class="bg-inverted/60 absolute -inset-y-1 w-0.5 rounded-full"
588
+ :style="{ left: `${timing.threshold}%` }"
589
+ aria-hidden="true"
590
+ />
591
+ </div>
592
+ <p class="text-dimmed text-xs">
593
+ {{
594
+ t('api.request.threshold', {
595
+ threshold: formatMs(log.slowThresholdMs, locale),
596
+ })
597
+ }}
598
+ </p>
599
+ </template>
600
+ <p v-else class="text-dimmed text-sm">
601
+ {{ t('api.request.not_measured_hint') }}
602
+ </p>
603
+ </section>
604
+
605
+ <section class="flex flex-col gap-2">
606
+ <DmsEyebrow :label="t('api.request.path_params')" />
607
+ <ApiKeyValues
608
+ :values="log.pathParams"
609
+ :empty="t('api.request.no_path_params')"
610
+ />
611
+ </section>
612
+ </div>
613
+
614
+ <div v-else-if="tab === 'request'" class="flex flex-col gap-5">
615
+ <section class="flex flex-col gap-2">
616
+ <DmsEyebrow :label="t('api.request.headers')" />
617
+ <ApiKeyValues
618
+ :values="log.requestHeaders"
619
+ :empty="t('api.request.no_headers')"
620
+ />
621
+ <p
622
+ v-if="redactions.headers.length"
623
+ class="text-dimmed inline-flex items-start gap-1 text-xs"
624
+ >
625
+ <UIcon name="i-ph-eye-slash" class="mt-0.5 shrink-0" />
626
+ {{
627
+ t('api.request.redacted_headers', {
628
+ names: redactions.headers.join(', '),
629
+ })
630
+ }}
631
+ </p>
632
+ <p class="text-dimmed text-xs">
633
+ {{ t('api.request.headers_hint') }}
634
+ <ULink
635
+ :to="HEADERS_SETTINGS_LINK"
636
+ class="text-primary whitespace-nowrap hover:underline"
637
+ >
638
+ {{ t('api.request.headers_settings') }}
639
+ </ULink>
640
+ </p>
641
+ </section>
642
+ <section
643
+ v-if="log.query && Object.keys(log.query).length"
644
+ class="flex flex-col gap-2"
645
+ >
646
+ <DmsEyebrow :label="t('api.request.query')" />
647
+ <ApiKeyValues :values="log.query" :empty="''" />
648
+ <p
649
+ v-if="redactions.query > 0"
650
+ class="text-dimmed inline-flex items-center gap-1 text-xs"
651
+ >
652
+ <UIcon name="i-ph-eye-slash" />
653
+ {{
654
+ t(
655
+ 'api.request.redacted_query',
656
+ { count: count(redactions.query) },
657
+ redactions.query,
658
+ )
659
+ }}
660
+ </p>
661
+ </section>
662
+ <section class="flex flex-col gap-2">
663
+ <DmsEyebrow :label="t('api.request.body')" />
664
+ <ApiBody
665
+ kind="request"
666
+ :body="log.requestBody"
667
+ :truncated="log.requestBodyTruncated"
668
+ :omitted="omission(log.requestBodyOmitted)"
669
+ :original-size="requestSize"
670
+ :method="log.method"
671
+ />
672
+ <p
673
+ v-if="redactions.requestBody > 0"
674
+ class="text-dimmed inline-flex items-center gap-1 text-xs"
675
+ >
676
+ <UIcon name="i-ph-eye-slash" />
677
+ {{
678
+ t(
679
+ 'api.request.redacted',
680
+ { count: count(redactions.requestBody) },
681
+ redactions.requestBody,
682
+ )
683
+ }}
684
+ </p>
685
+ </section>
686
+ </div>
687
+
688
+ <div v-else class="flex flex-col gap-5">
689
+ <section class="flex flex-col gap-2">
690
+ <DmsEyebrow :label="t('api.request.headers')" />
691
+ <ApiKeyValues
692
+ :values="log.responseHeaders"
693
+ :empty="t('api.request.no_headers')"
694
+ />
695
+ </section>
696
+ <section class="flex flex-col gap-2">
697
+ <DmsEyebrow :label="t('api.request.body')" />
698
+ <ApiBody
699
+ kind="response"
700
+ :body="log.responseBody"
701
+ :truncated="log.responseBodyTruncated"
702
+ :omitted="omission(log.responseBodyOmitted)"
703
+ :original-size="responseSize"
704
+ />
705
+ <p
706
+ v-if="redactions.responseBody > 0"
707
+ class="text-dimmed inline-flex items-center gap-1 text-xs"
708
+ >
709
+ <UIcon name="i-ph-eye-slash" />
710
+ {{
711
+ t(
712
+ 'api.request.redacted',
713
+ { count: count(redactions.responseBody) },
714
+ redactions.responseBody,
715
+ )
716
+ }}
717
+ </p>
718
+ </section>
719
+ </div>
720
+ </div>
721
+ </section>
722
+ </template>