@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,92 @@
1
+ import { onBeforeUnmount, ref, shallowRef, watch, type Ref } from 'vue'
2
+
3
+ export interface ApiResource<T> {
4
+ data: Ref<T | null>
5
+ error: Ref<unknown>
6
+ /** First load still running: nothing to show yet. */
7
+ pending: Ref<boolean>
8
+ /** A refresh is running over data already on screen. */
9
+ refreshing: Ref<boolean>
10
+ /** When the data on screen was received. */
11
+ receivedAt: Ref<number | null>
12
+ refresh: () => Promise<void>
13
+ }
14
+
15
+ /**
16
+ * A backend payload that follows a URL. A failed refresh keeps the last data
17
+ * on screen and says so through `error`, instead of replacing the page with
18
+ * an error box; a newer request cancels the one still running.
19
+ */
20
+ export function useApiResource<T>(
21
+ url: () => string | null | undefined,
22
+ ): ApiResource<T> {
23
+ const { $authFetch } = useAuthFetch()
24
+ const data = shallowRef<T | null>(null)
25
+ const error = ref<unknown>(null)
26
+ const pending = ref(true)
27
+ const refreshing = ref(false)
28
+ const receivedAt = ref<number | null>(null)
29
+ let controller: AbortController | null = null
30
+
31
+ async function load(target: string | null | undefined) {
32
+ controller?.abort()
33
+ if (!target) {
34
+ data.value = null
35
+ pending.value = false
36
+ return
37
+ }
38
+ const current = new AbortController()
39
+ controller = current
40
+ refreshing.value = data.value !== null
41
+ try {
42
+ const response = await $authFetch<T>(target, { signal: current.signal })
43
+ if (controller !== current) return
44
+ data.value = response
45
+ error.value = null
46
+ receivedAt.value = Date.now()
47
+ } catch (cause) {
48
+ if (controller !== current) return
49
+ if ((cause as { name?: string })?.name !== 'AbortError')
50
+ error.value = cause
51
+ } finally {
52
+ if (controller === current) {
53
+ pending.value = false
54
+ refreshing.value = false
55
+ }
56
+ }
57
+ }
58
+
59
+ watch(url, (target, previous) => {
60
+ if (target === previous) return
61
+ pending.value = true
62
+ data.value = null
63
+ void load(target)
64
+ })
65
+
66
+ if (import.meta.env.SSR) {
67
+ pending.value = true
68
+ } else {
69
+ void load(url())
70
+ }
71
+
72
+ onBeforeUnmount(() => controller?.abort())
73
+
74
+ return {
75
+ data,
76
+ error,
77
+ pending,
78
+ refreshing,
79
+ receivedAt,
80
+ refresh: () => load(url()),
81
+ }
82
+ }
83
+
84
+ /** The HTTP status of a failed request, when it has one. */
85
+ export function errorStatus(error: unknown): number | undefined {
86
+ const value = error as {
87
+ statusCode?: number
88
+ status?: number
89
+ response?: { status?: number }
90
+ }
91
+ return value?.statusCode ?? value?.status ?? value?.response?.status
92
+ }
@@ -0,0 +1,23 @@
1
+ import { computed } from 'vue'
2
+ import { useUserRegionalPreferences } from '#dms-core/app/composables/user/useUserRegionalPreferences'
3
+ import { cachedDateFormat, type DateFormat } from '../utils/format'
4
+
5
+ /**
6
+ * How the console writes its dates and times: through the DMS's regional
7
+ * formatter, in the locale of the DMS's texts (`formatLocale`, `en-GB` for
8
+ * `en`) and with the user's Language & region preferences (time zone, clock,
9
+ * date format). The formats are made once each, and again when the language
10
+ * or the preferences change.
11
+ */
12
+ export function useDateFormat() {
13
+ const { formatLocale, dateTimeFormat } = useRegionalFormat({
14
+ locale: 'format',
15
+ })
16
+ const { preferences } = useUserRegionalPreferences()
17
+ return computed<DateFormat>(() => {
18
+ // Read so that a change of language or preferences makes the formats again.
19
+ void formatLocale.value
20
+ void preferences.value
21
+ return cachedDateFormat((options) => dateTimeFormat(options))
22
+ })
23
+ }
@@ -0,0 +1,33 @@
1
+ import { watch } from 'vue'
2
+
3
+ /** First status of the server errors the paused toggle counts apart. */
4
+ const SERVER_ERROR_STATUS = 500
5
+
6
+ /**
7
+ * Gives the page's DMS live toggle the server errors it missed while paused,
8
+ * after the count of new requests: "Paused · 40 new requests · 2 in 5xx",
9
+ * which the request table's paused strip shows too. The live feed
10
+ * (`topic`) tells each captured request with its `statusCode`; the
11
+ * tally starts again on resume. Browser only; the DMS clears the detail on
12
+ * resume.
13
+ */
14
+ export function useLiveMissedErrors(topic: string) {
15
+ const live = usePageLive()
16
+ let serverErrors = 0
17
+
18
+ useRealtimeTopic(topic, (event) => {
19
+ if (!live.isPaused.value || !('payload' in event)) return
20
+ const status = Number(event.payload?.statusCode)
21
+ if (!(status >= SERVER_ERROR_STATUS)) return
22
+ serverErrors += 1
23
+ live.setMissedDetail({
24
+ text: '$api.live_mode.server_errors',
25
+ params: { count: serverErrors },
26
+ tone: 'error',
27
+ })
28
+ })
29
+
30
+ watch(live.isPaused, (paused) => {
31
+ if (!paused) serverErrors = 0
32
+ })
33
+ }
@@ -0,0 +1,253 @@
1
+ import { computed, markRaw, onBeforeUnmount, ref, watch } from 'vue'
2
+ import type { RouteState } from '../utils/routeExplorer'
3
+
4
+ /** One step of the request pipeline of a route, in the order it runs. */
5
+ export interface PipelineStep {
6
+ kind: 'prefix' | 'handler' | 'postfix' | 'monitor'
7
+ name: string
8
+ location: string
9
+ priority?: number
10
+ isAuth: boolean
11
+ }
12
+
13
+ export interface InferredField {
14
+ name: string
15
+ types: string[]
16
+ required: boolean
17
+ /** Its value in the most recent body that had it, when a scalar. */
18
+ example?: string | number | boolean | null
19
+ }
20
+
21
+ export interface ParameterInfo {
22
+ index: number
23
+ name: string | null
24
+ source: string
25
+ multi: boolean
26
+ inferredType: string
27
+ modifierCount: number
28
+ rawProviderSource?: string
29
+ /** The decorator that provides it, as written in the code. */
30
+ decorator?: string
31
+ hint?: string
32
+ }
33
+
34
+ export interface PropertyInfo {
35
+ key: string
36
+ decorator: string
37
+ modifierCount: number
38
+ hint?: string
39
+ }
40
+
41
+ /** What is known of a route's authentication, from its code and traffic. */
42
+ export interface RouteAuth {
43
+ status: 'required' | 'probable' | 'unknown'
44
+ /** The guards found in the code. */
45
+ guards: string[]
46
+ /** 401 answers over the contract window. */
47
+ unauthorized: number
48
+ }
49
+
50
+ /** A parameter of a route, declared in the code or seen in its traffic. */
51
+ export interface DocumentedParameter {
52
+ name: string
53
+ in: 'path' | 'query' | 'header'
54
+ type: string
55
+ example: string | null
56
+ declared: boolean
57
+ required: boolean
58
+ }
59
+
60
+ /** A status the route answered over the contract window. */
61
+ export interface ObservedStatus {
62
+ status: number
63
+ count: number
64
+ /** The most frequent error message, null when none was recorded. */
65
+ message: string | null
66
+ /** The most frequent distinct error messages, most frequent first. */
67
+ messages: Array<{ message: string; count: number }>
68
+ /** Distinct error messages in all, `messages` included. */
69
+ messageCount: number
70
+ lastSeen: string
71
+ }
72
+
73
+ export interface RouteDetail {
74
+ ref: string
75
+ method: string
76
+ path: string
77
+ folder: string
78
+ controller: string | null
79
+ handler: string
80
+ module: string | null
81
+ own: boolean | null
82
+ requiresAuth: boolean
83
+ auth: RouteAuth
84
+ registeredAt: string | null
85
+ /**
86
+ * The first day the route was called, from the statistics kept: never
87
+ * further back than their retention. Null before any call.
88
+ */
89
+ firstCallAt?: string | null
90
+ state: RouteState
91
+ /** Minutes of traffic `state` is judged on, the same as the list's. */
92
+ healthWindowMinutes?: number
93
+ /** False when the route lies outside the active route scope. */
94
+ inScope?: boolean
95
+ /** False for a route the module leaves out of its logs (the console's own). */
96
+ captured?: boolean
97
+ /** The last call captured for the route, whatever the period. */
98
+ lastCallAt?: string | null
99
+ pathParams: string[]
100
+ parameters: DocumentedParameter[]
101
+ pipeline: PipelineStep[]
102
+ inspection: {
103
+ parameters: ParameterInfo[]
104
+ properties: PropertyInfo[]
105
+ errorCodes: Array<{ status: number; reason: string | null; source: string }>
106
+ authGuards: string[]
107
+ }
108
+ contract: {
109
+ /** The days the contract is read over, up to now. */
110
+ windowDays: number
111
+ /** Requests answered over the window, the tester's left out. */
112
+ total: number
113
+ exampleBody: unknown
114
+ bodyFields: InferredField[]
115
+ /** Successful requests the bodies and examples were read from. */
116
+ sampled: number
117
+ queryParams: string[]
118
+ statuses: ObservedStatus[]
119
+ /** Path and query of the most recent successful call. */
120
+ examplePath: Record<string, string>
121
+ exampleQuery: Record<string, string | string[]>
122
+ exampleResponse: {
123
+ status: number
124
+ body: string
125
+ json: boolean
126
+ truncated: boolean
127
+ } | null
128
+ responseKind: 'object' | 'array' | null
129
+ responseFields: InferredField[]
130
+ /** Response time of the successful calls, null without any. */
131
+ latency: { p50: number; p95: number } | null
132
+ }
133
+ /** Where clients reach the API, for the snippets; null when unknown. */
134
+ apiOrigin: string | null
135
+ }
136
+
137
+ /** The detail every block of the page reads, fetched once per route. */
138
+ interface DetailSlot {
139
+ url: string | null
140
+ data: RouteDetail | null
141
+ error: unknown
142
+ pending: boolean
143
+ refreshing: boolean
144
+ receivedAt: number | null
145
+ }
146
+
147
+ const emptySlot = (): DetailSlot => ({
148
+ url: null,
149
+ data: null,
150
+ error: null,
151
+ pending: true,
152
+ refreshing: false,
153
+ receivedAt: null,
154
+ })
155
+
156
+ /** The request still running for a slot, and the blocks reading it. */
157
+ const running = new WeakMap<object, AbortController>()
158
+ const readers = new WeakMap<object, number>()
159
+
160
+ /**
161
+ * The route the page's `?route=` names, shared by the blocks that show it:
162
+ * the header, the documentation, the tester and the parts of the page that
163
+ * wait for a valid route read one payload, loaded once per route rather than
164
+ * once per block. A newer route cancels the request still running; a failed
165
+ * refresh keeps the last data and says so through `error`.
166
+ */
167
+ export function useRouteDetail(fetchUrl: string, queryKey = 'route') {
168
+ const selection = useRouteSelection(queryKey)
169
+ const target = computed(() =>
170
+ selection.ref.value
171
+ ? `${fetchUrl}?${new URLSearchParams({ route: selection.ref.value })}`
172
+ : null,
173
+ )
174
+
175
+ // The server renders the page before anything is fetched.
176
+ if (import.meta.env.SSR) {
177
+ return {
178
+ selection,
179
+ missing: computed(() => false),
180
+ data: ref<RouteDetail | null>(null),
181
+ error: ref<unknown>(null),
182
+ pending: ref(true),
183
+ refreshing: ref(false),
184
+ receivedAt: ref<number | null>(null),
185
+ refresh: async () => {},
186
+ }
187
+ }
188
+
189
+ const { $authFetch } = useAuthFetch()
190
+ const state = useDmsState<DetailSlot>(
191
+ `dms-api-route-detail:${fetchUrl}`,
192
+ emptySlot,
193
+ )
194
+
195
+ async function load(url: string | null, force = false) {
196
+ const slot = state.value
197
+ if (!force && slot.url === url) return
198
+ running.get(slot)?.abort()
199
+ running.delete(slot)
200
+ if (slot.url !== url) {
201
+ slot.url = url
202
+ slot.data = null
203
+ slot.error = null
204
+ }
205
+ if (!url) {
206
+ slot.pending = false
207
+ return
208
+ }
209
+ const controller = new AbortController()
210
+ running.set(slot, controller)
211
+ slot.pending = slot.data === null
212
+ slot.refreshing = slot.data !== null
213
+ try {
214
+ const response = await $authFetch<RouteDetail>(url, {
215
+ signal: controller.signal,
216
+ })
217
+ if (running.get(slot) !== controller) return
218
+ slot.data = markRaw(response)
219
+ slot.error = null
220
+ slot.receivedAt = Date.now()
221
+ } catch (cause) {
222
+ if (running.get(slot) !== controller) return
223
+ if ((cause as { name?: string })?.name !== 'AbortError')
224
+ slot.error = cause
225
+ } finally {
226
+ if (running.get(slot) === controller) {
227
+ running.delete(slot)
228
+ slot.pending = false
229
+ slot.refreshing = false
230
+ }
231
+ }
232
+ }
233
+
234
+ // The first block of a page visit refreshes what an earlier visit left.
235
+ const slot = state.value
236
+ const count = readers.get(slot) ?? 0
237
+ readers.set(slot, count + 1)
238
+ onBeforeUnmount(() => readers.set(slot, (readers.get(slot) ?? 1) - 1))
239
+ if (count === 0 && slot.url !== null) void load(target.value, true)
240
+
241
+ watch(target, (url) => void load(url), { immediate: true })
242
+
243
+ return {
244
+ selection,
245
+ missing: computed(() => errorStatus(state.value.error) === 404),
246
+ data: computed(() => state.value.data),
247
+ error: computed(() => state.value.error),
248
+ pending: computed(() => state.value.pending),
249
+ refreshing: computed(() => state.value.refreshing),
250
+ receivedAt: computed(() => state.value.receivedAt),
251
+ refresh: () => load(target.value, true),
252
+ }
253
+ }
@@ -0,0 +1,43 @@
1
+ import { computed } from 'vue'
2
+ import { parseRouteRef } from '../utils/http'
3
+
4
+ /** The request the tester replays (`?replay=<id>`, `RouteTester.vue`). */
5
+ const REPLAY_QUERY_KEY = 'replay'
6
+
7
+ export interface SelectOptions {
8
+ /**
9
+ * Replace the history entry instead of adding one: for a selection the
10
+ * user did not ask for (the route a bare `/routes` opens on) and for the
11
+ * keyboard, so Back leaves the page instead of walking every route seen.
12
+ */
13
+ replace?: boolean
14
+ }
15
+
16
+ /**
17
+ * The route the Routes page shows, as `?route=METHOD%20/path` in the URL: a
18
+ * link, a reload or the back button land on the same route, and every block
19
+ * of the page reads the same value.
20
+ */
21
+ export function useRouteSelection(queryKey = 'route') {
22
+ const route = useDmsRoute()
23
+ const router = useDmsRouter()
24
+
25
+ const ref = computed<string | null>(() => {
26
+ const value = route.query[queryKey]
27
+ return typeof value === 'string' && value ? value : null
28
+ })
29
+ const parsed = computed(() => parseRouteRef(ref.value))
30
+
31
+ async function select(next: string | null, options: SelectOptions = {}) {
32
+ if (next === ref.value) return
33
+ const query = { ...route.query } as Record<string, string | string[]>
34
+ // A replayed request belongs to the route it was sent to: another route
35
+ // opens its tester blank.
36
+ delete query[REPLAY_QUERY_KEY]
37
+ if (next) query[queryKey] = next
38
+ else delete query[queryKey]
39
+ await (options.replace ? router.replace({ query }) : router.push({ query }))
40
+ }
41
+
42
+ return { ref, parsed, select }
43
+ }
@@ -0,0 +1,30 @@
1
+ import type { ComponentShortcuts } from '#dms-ui/app/types/shortcuts'
2
+
3
+ // The console's own page keys, listed on the DMS Shortcuts page. The request
4
+ // logs' search ("/"), J / K, Esc and L are the DMS table's and live
5
+ // toggle's, which list themselves.
6
+ const ROUTES = '$api.routes.shortcuts.group'
7
+ const LOGS = '$api.logs.shortcuts.group'
8
+
9
+ export default [
10
+ {
11
+ component: ROUTES,
12
+ shortcuts: [
13
+ {
14
+ key: ['/'],
15
+ descriptionKey: '$api.routes.shortcuts.filter',
16
+ component: ROUTES,
17
+ },
18
+ ],
19
+ },
20
+ {
21
+ component: LOGS,
22
+ shortcuts: [
23
+ {
24
+ key: ['?'],
25
+ descriptionKey: '$api.logs.shortcuts.help',
26
+ component: LOGS,
27
+ },
28
+ ],
29
+ },
30
+ ] satisfies ComponentShortcuts[]
@@ -0,0 +1,92 @@
1
+ import { h } from 'vue'
2
+ import ApiTesterBadge from '../components/internal/ApiTesterBadge.vue'
3
+ import { cachedDateFormat, type DateFormat } from '../utils/format'
4
+ import { fullDateTime, requestClock } from '../utils/requestDrawer'
5
+
6
+ interface TimeDisplayOptions {
7
+ milliseconds?: boolean
8
+ }
9
+
10
+ const EMPTY = '—'
11
+
12
+ // The date formats of a cell, per interface language. A plugin runs outside
13
+ // any component's setup, where the i18n composables behind useDateFormat()
14
+ // throw: the cell formats with the locale its formatter receives, through the
15
+ // DMS's regional formatter (the user's Language & region preferences).
16
+ const cellDateFormats = new Map<string, DateFormat>()
17
+ function cellDateFormat(locale: string): DateFormat {
18
+ let format = cellDateFormats.get(locale)
19
+ if (!format) {
20
+ const formatLocale = regionalFormatLocale(locale)
21
+ format = cachedDateFormat((options) =>
22
+ regionalDateTimeFormat(formatLocale, options),
23
+ )
24
+ cellDateFormats.set(locale, format)
25
+ }
26
+ return format
27
+ }
28
+
29
+ /** `source` of a request the console's Tester sent. */
30
+ const TESTER_SOURCE = 'tester'
31
+
32
+ // The cell displays the backend names with `@RegisterDisplay("api:…")`:
33
+ // methods and statuses are the DMS status pills, ids its mono display,
34
+ // durations its duration display.
35
+ export default defineDmsPlugin(() => {
36
+ const { registerDataType } = useDataTypes()
37
+
38
+ // "Yesterday, 23:42:10.120" rather than a bare time once the day changed;
39
+ // the whole date and its time zone on hover, written when hovered: every
40
+ // cell is drawn again on each "Load more", and formatting a full date costs
41
+ // more than the cell itself (about 0.1 ms, 200 ms over 2,000 rows).
42
+ registerDataType({
43
+ id: 'api:time',
44
+ formatter: {
45
+ default: (value, locale, options) => {
46
+ const dateFormat = cellDateFormat(String(locale))
47
+ return h(
48
+ 'span',
49
+ {
50
+ class: 'text-muted font-mono text-[12px] tabular-nums',
51
+ onMouseenter: (event: MouseEvent) => {
52
+ const cell = event.currentTarget as HTMLElement
53
+ if (!cell.title)
54
+ cell.title = fullDateTime(value as string, dateFormat)
55
+ },
56
+ },
57
+ requestClock(
58
+ value as string,
59
+ dateFormat,
60
+ (options as TimeDisplayOptions | undefined)?.milliseconds ?? false,
61
+ ) || EMPTY,
62
+ )
63
+ },
64
+ },
65
+ })
66
+
67
+ // The path in the mono font, as the DMS mono cell draws it, and "Tester"
68
+ // beside it when the console's Tester sent the request.
69
+ registerDataType({
70
+ id: 'api:path',
71
+ formatter: {
72
+ default: (value, _locale, _options, row) => {
73
+ const path = value === null || value === undefined ? '' : String(value)
74
+ return h(
75
+ 'span',
76
+ { class: 'flex min-w-0 max-w-full items-center gap-1.5' },
77
+ [
78
+ h(
79
+ 'span',
80
+ {
81
+ class: 'text-toned truncate font-mono text-[12.5px]',
82
+ title: path,
83
+ },
84
+ path || EMPTY,
85
+ ),
86
+ row?.source === TESTER_SOURCE ? h(ApiTesterBadge) : null,
87
+ ],
88
+ )
89
+ },
90
+ },
91
+ })
92
+ })