@antelopejs/dms-api 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +61 -0
  3. package/dist/automation/get-api-health.d.ts +10 -0
  4. package/dist/automation/get-api-health.js +53 -0
  5. package/dist/automation/get-api-health.js.map +1 -0
  6. package/dist/automation/index.d.ts +2 -0
  7. package/dist/automation/index.js +19 -0
  8. package/dist/automation/index.js.map +1 -0
  9. package/dist/automation/query-request-logs.d.ts +18 -0
  10. package/dist/automation/query-request-logs.js +50 -0
  11. package/dist/automation/query-request-logs.js.map +1 -0
  12. package/dist/automation/route-unhealthy.d.ts +9 -0
  13. package/dist/automation/route-unhealthy.js +102 -0
  14. package/dist/automation/route-unhealthy.js.map +1 -0
  15. package/dist/automation/scope.d.ts +2 -0
  16. package/dist/automation/scope.js +18 -0
  17. package/dist/automation/scope.js.map +1 -0
  18. package/dist/config.d.ts +12 -0
  19. package/dist/config.js +38 -0
  20. package/dist/config.js.map +1 -0
  21. package/dist/db/index.d.ts +2 -0
  22. package/dist/db/index.js +19 -0
  23. package/dist/db/index.js.map +1 -0
  24. package/dist/db/models/api_settings.model.d.ts +23 -0
  25. package/dist/db/models/api_settings.model.js +13 -0
  26. package/dist/db/models/api_settings.model.js.map +1 -0
  27. package/dist/db/models/index.d.ts +4 -0
  28. package/dist/db/models/index.js +21 -0
  29. package/dist/db/models/index.js.map +1 -0
  30. package/dist/db/models/request_log.model.d.ts +47 -0
  31. package/dist/db/models/request_log.model.js +127 -0
  32. package/dist/db/models/request_log.model.js.map +1 -0
  33. package/dist/db/models/routes.model.d.ts +22 -0
  34. package/dist/db/models/routes.model.js +9 -0
  35. package/dist/db/models/routes.model.js.map +1 -0
  36. package/dist/db/models/routes_statistics.model.d.ts +23 -0
  37. package/dist/db/models/routes_statistics.model.js +13 -0
  38. package/dist/db/models/routes_statistics.model.js.map +1 -0
  39. package/dist/db/tables/api_settings.table.d.ts +10 -0
  40. package/dist/db/tables/api_settings.table.js +47 -0
  41. package/dist/db/tables/api_settings.table.js.map +1 -0
  42. package/dist/db/tables/index.d.ts +4 -0
  43. package/dist/db/tables/index.js +21 -0
  44. package/dist/db/tables/index.js.map +1 -0
  45. package/dist/db/tables/request_log.table.d.ts +29 -0
  46. package/dist/db/tables/request_log.table.js +107 -0
  47. package/dist/db/tables/request_log.table.js.map +1 -0
  48. package/dist/db/tables/routes.table.d.ts +11 -0
  49. package/dist/db/tables/routes.table.js +50 -0
  50. package/dist/db/tables/routes.table.js.map +1 -0
  51. package/dist/db/tables/routes_statistics.table.d.ts +9 -0
  52. package/dist/db/tables/routes_statistics.table.js +38 -0
  53. package/dist/db/tables/routes_statistics.table.js.map +1 -0
  54. package/dist/index.d.ts +9 -0
  55. package/dist/index.js +56 -0
  56. package/dist/index.js.map +1 -0
  57. package/dist/middlewares/index.d.ts +1 -0
  58. package/dist/middlewares/index.js +18 -0
  59. package/dist/middlewares/index.js.map +1 -0
  60. package/dist/middlewares/request-log-capture.d.ts +1 -0
  61. package/dist/middlewares/request-log-capture.js +6 -0
  62. package/dist/middlewares/request-log-capture.js.map +1 -0
  63. package/dist/pages/all.d.ts +4 -0
  64. package/dist/pages/all.js +21 -0
  65. package/dist/pages/all.js.map +1 -0
  66. package/dist/pages/index.d.ts +4 -0
  67. package/dist/pages/index.js +21 -0
  68. package/dist/pages/index.js.map +1 -0
  69. package/dist/pages/logs/page.d.ts +9 -0
  70. package/dist/pages/logs/page.js +29 -0
  71. package/dist/pages/logs/page.js.map +1 -0
  72. package/dist/pages/module.d.ts +1 -0
  73. package/dist/pages/module.js +12 -0
  74. package/dist/pages/module.js.map +1 -0
  75. package/dist/pages/routes/page.d.ts +9 -0
  76. package/dist/pages/routes/page.js +29 -0
  77. package/dist/pages/routes/page.js.map +1 -0
  78. package/dist/pages/settings/form.d.ts +3 -0
  79. package/dist/pages/settings/form.js +80 -0
  80. package/dist/pages/settings/form.js.map +1 -0
  81. package/dist/pages/settings/page.d.ts +9 -0
  82. package/dist/pages/settings/page.js +26 -0
  83. package/dist/pages/settings/page.js.map +1 -0
  84. package/dist/pages/summary/page.d.ts +9 -0
  85. package/dist/pages/summary/page.js +29 -0
  86. package/dist/pages/summary/page.js.map +1 -0
  87. package/dist/routes/index.d.ts +5 -0
  88. package/dist/routes/index.js +22 -0
  89. package/dist/routes/index.js.map +1 -0
  90. package/dist/routes/logs.d.ts +7 -0
  91. package/dist/routes/logs.js +128 -0
  92. package/dist/routes/logs.js.map +1 -0
  93. package/dist/routes/monitoring.d.ts +17 -0
  94. package/dist/routes/monitoring.js +101 -0
  95. package/dist/routes/monitoring.js.map +1 -0
  96. package/dist/routes/routes.d.ts +37 -0
  97. package/dist/routes/routes.js +153 -0
  98. package/dist/routes/routes.js.map +1 -0
  99. package/dist/routes/settings.d.ts +24 -0
  100. package/dist/routes/settings.js +92 -0
  101. package/dist/routes/settings.js.map +1 -0
  102. package/dist/routes/summary.d.ts +32 -0
  103. package/dist/routes/summary.js +181 -0
  104. package/dist/routes/summary.js.map +1 -0
  105. package/dist/services/index.d.ts +11 -0
  106. package/dist/services/index.js +28 -0
  107. package/dist/services/index.js.map +1 -0
  108. package/dist/services/introspection/auth.d.ts +4 -0
  109. package/dist/services/introspection/auth.js +33 -0
  110. package/dist/services/introspection/auth.js.map +1 -0
  111. package/dist/services/introspection/errors.d.ts +6 -0
  112. package/dist/services/introspection/errors.js +50 -0
  113. package/dist/services/introspection/errors.js.map +1 -0
  114. package/dist/services/introspection/index.d.ts +53 -0
  115. package/dist/services/introspection/index.js +141 -0
  116. package/dist/services/introspection/index.js.map +1 -0
  117. package/dist/services/introspection/probe.d.ts +18 -0
  118. package/dist/services/introspection/probe.js +155 -0
  119. package/dist/services/introspection/probe.js.map +1 -0
  120. package/dist/services/period.d.ts +11 -0
  121. package/dist/services/period.js +68 -0
  122. package/dist/services/period.js.map +1 -0
  123. package/dist/services/request-log/capture.d.ts +10 -0
  124. package/dist/services/request-log/capture.js +189 -0
  125. package/dist/services/request-log/capture.js.map +1 -0
  126. package/dist/services/request-log/index.d.ts +3 -0
  127. package/dist/services/request-log/index.js +12 -0
  128. package/dist/services/request-log/index.js.map +1 -0
  129. package/dist/services/request-log/prune.d.ts +2 -0
  130. package/dist/services/request-log/prune.js +10 -0
  131. package/dist/services/request-log/prune.js.map +1 -0
  132. package/dist/services/request-log/read.d.ts +6 -0
  133. package/dist/services/request-log/read.js +26 -0
  134. package/dist/services/request-log/read.js.map +1 -0
  135. package/dist/services/request-log/redaction.d.ts +4 -0
  136. package/dist/services/request-log/redaction.js +53 -0
  137. package/dist/services/request-log/redaction.js.map +1 -0
  138. package/dist/services/request-log/util.d.ts +13 -0
  139. package/dist/services/request-log/util.js +114 -0
  140. package/dist/services/request-log/util.js.map +1 -0
  141. package/dist/services/routes-sync.d.ts +5 -0
  142. package/dist/services/routes-sync.js +63 -0
  143. package/dist/services/routes-sync.js.map +1 -0
  144. package/dist/services/scope.d.ts +7 -0
  145. package/dist/services/scope.js +40 -0
  146. package/dist/services/scope.js.map +1 -0
  147. package/dist/services/settings.d.ts +20 -0
  148. package/dist/services/settings.js +86 -0
  149. package/dist/services/settings.js.map +1 -0
  150. package/dist/services/statistics-aggregate.d.ts +67 -0
  151. package/dist/services/statistics-aggregate.js +340 -0
  152. package/dist/services/statistics-aggregate.js.map +1 -0
  153. package/dist/services/statistics-prune.d.ts +2 -0
  154. package/dist/services/statistics-prune.js +25 -0
  155. package/dist/services/statistics-prune.js.map +1 -0
  156. package/dist/services/statistics-read.d.ts +4 -0
  157. package/dist/services/statistics-read.js +48 -0
  158. package/dist/services/statistics-read.js.map +1 -0
  159. package/dist/services/statistics-utils.d.ts +14 -0
  160. package/dist/services/statistics-utils.js +65 -0
  161. package/dist/services/statistics-utils.js.map +1 -0
  162. package/dist/services/statistics-write.d.ts +3 -0
  163. package/dist/services/statistics-write.js +84 -0
  164. package/dist/services/statistics-write.js.map +1 -0
  165. package/dist/services/tree.d.ts +10 -0
  166. package/dist/services/tree.js +128 -0
  167. package/dist/services/tree.js.map +1 -0
  168. package/dist/types/charts.d.ts +9 -0
  169. package/dist/types/charts.js +3 -0
  170. package/dist/types/charts.js.map +1 -0
  171. package/dist/types/constants.d.ts +31 -0
  172. package/dist/types/constants.js +49 -0
  173. package/dist/types/constants.js.map +1 -0
  174. package/dist/types/index.d.ts +3 -0
  175. package/dist/types/index.js +20 -0
  176. package/dist/types/index.js.map +1 -0
  177. package/dist/types/statistics.d.ts +17 -0
  178. package/dist/types/statistics.js +3 -0
  179. package/dist/types/statistics.js.map +1 -0
  180. package/frontend-vue/.editorconfig +12 -0
  181. package/frontend-vue/.prettierrc +12 -0
  182. package/frontend-vue/.vscode/settings.json +26 -0
  183. package/frontend-vue/app/components/ConfigurationView.vue +187 -0
  184. package/frontend-vue/app/components/DocumentationView.vue +224 -0
  185. package/frontend-vue/app/components/LogDetailDrawer.vue +178 -0
  186. package/frontend-vue/app/components/LogsView.vue +347 -0
  187. package/frontend-vue/app/components/RouteDetailTabs.vue +179 -0
  188. package/frontend-vue/app/components/RouteTree.vue +196 -0
  189. package/frontend-vue/app/components/RoutesView.vue +82 -0
  190. package/frontend-vue/app/components/StatsView.vue +268 -0
  191. package/frontend-vue/app/components/SummaryView.vue +657 -0
  192. package/frontend-vue/app/components/TesterPanel.vue +499 -0
  193. package/frontend-vue/app/components/internal/ApiMethodBadge.vue +33 -0
  194. package/frontend-vue/app/components/internal/ApiStatusBadge.vue +28 -0
  195. package/frontend-vue/app/components/internal/PeriodSelect.vue +58 -0
  196. package/frontend-vue/app/components/internal/RouteTreeNode.vue +168 -0
  197. package/frontend-vue/app/components/internal/StatusBreakdownBars.vue +162 -0
  198. package/frontend-vue/app/components/internal/StatusDonut.vue +84 -0
  199. package/frontend-vue/app/components/internal/UnitAreaChart.vue +73 -0
  200. package/frontend-vue/app/composables/useApiIntrospection.ts +344 -0
  201. package/frontend-vue/app/composables/useLogDetailDrawer.ts +50 -0
  202. package/frontend-vue/app/composables/useSelectedPeriod.ts +107 -0
  203. package/frontend-vue/app/composables/useStatsPeriods.ts +139 -0
  204. package/frontend-vue/app/custom-layouts/.gitkeep +0 -0
  205. package/frontend-vue/app/custom-pages/.gitkeep +0 -0
  206. package/frontend-vue/app/utils/httpMethod.ts +49 -0
  207. package/frontend-vue/app/utils/statusClass.ts +49 -0
  208. package/frontend-vue/app/utils/testerRequest.ts +50 -0
  209. package/frontend-vue/dms.frontend.ts +25 -0
  210. package/frontend-vue/eslint.config.mjs +16 -0
  211. package/frontend-vue/i18n/locales/en-GB.json +240 -0
  212. package/frontend-vue/i18n/locales/fr-FR.json +240 -0
  213. package/frontend-vue/package.json +35 -0
  214. package/frontend-vue/pnpm-lock.yaml +5796 -0
  215. package/frontend-vue/pnpm-workspace.yaml +2 -0
  216. package/frontend-vue/public/.gitkeep +0 -0
  217. package/frontend-vue/server/.gitkeep +0 -0
  218. package/frontend-vue/tests/periods.test.ts +145 -0
  219. package/frontend-vue/tests/persistence.test.ts +45 -0
  220. package/frontend-vue/tests/registration.test.ts +28 -0
  221. package/frontend-vue/tests/testerRequest.test.ts +95 -0
  222. package/frontend-vue/tsconfig.json +13 -0
  223. package/frontend-vue/vitest.config.ts +8 -0
  224. package/package.json +67 -0
@@ -0,0 +1,657 @@
1
+ <script setup lang="ts">
2
+ import { computed, onMounted, ref, watch } from 'vue'
3
+ import type {
4
+ ActivityItem,
5
+ HistoryPoint,
6
+ MonitoringPayload,
7
+ RouteAggregate,
8
+ StatusBreakdown,
9
+ SummaryPayload,
10
+ WatchListItem,
11
+ } from '../composables/useApiIntrospection'
12
+ import ApiMethodBadge from './internal/ApiMethodBadge.vue'
13
+ import ApiStatusBadge from './internal/ApiStatusBadge.vue'
14
+ import PeriodSelect from './internal/PeriodSelect.vue'
15
+ import StatusBreakdownBars from './internal/StatusBreakdownBars.vue'
16
+ import StatusDonut from './internal/StatusDonut.vue'
17
+ import { STATUS_CLASSES } from '../utils/statusClass'
18
+
19
+ // Overview page (apiv2-overview): beta banner + 6 stat-cards +
20
+ // traffic area chart + status donut + needs-attention + slowest routes +
21
+ // recent requests table + activity feed. Composed entirely from the DMS
22
+ // primitives (DmsKpiCard / DmsChart / DmsActivityItem / DmsCard / DmsBanner)
23
+ // so the theme is inherited, not ported.
24
+ const {
25
+ getSummary,
26
+ getSummaryHistory,
27
+ getStatusBreakdown,
28
+ getWatchList,
29
+ getActivity,
30
+ getMonitoring,
31
+ } = useApiIntrospection()
32
+
33
+ const { t } = useI18n()
34
+ const route = useDmsRoute()
35
+ const router = useDmsRouter()
36
+
37
+ // Traffic-chart accents, pinned to the DMS reference: cyan requests against
38
+ // red errors. The status-class palette lives in STATUS_CLASSES — this chart
39
+ // merges the two error classes, so it is a different pair of colours.
40
+ const C_REQUESTS = '#4dd9e6'
41
+ const C_ERRORS = '#f87171'
42
+
43
+ // Window from the period filter shared with the Routes and Logs pages; null
44
+ // until <PeriodSelect> resolves one, which is what holds the fetches below.
45
+ const period = ref<string | null>(null)
46
+
47
+ const uriFilter = ref('')
48
+ const breakdownView = ref<'bars' | 'donut'>('bars')
49
+
50
+ const summary = ref<SummaryPayload | null>(null)
51
+ const history = ref<HistoryPoint[]>([])
52
+ const breakdown = ref<StatusBreakdown | null>(null)
53
+ const watchList = ref<WatchListItem[]>([])
54
+ const activity = ref<ActivityItem[]>([])
55
+ const monitoring = ref<MonitoringPayload | null>(null)
56
+ const error = ref<string | null>(null)
57
+ const loading = ref(true)
58
+
59
+ function fail(e: unknown) {
60
+ error.value = e instanceof Error ? e.message : String(e)
61
+ }
62
+
63
+ /**
64
+ * The KPIs, the watch-list and the activity feed take no period, so they are
65
+ * not held behind the retention round-trip <PeriodSelect> needs before it can
66
+ * name a window — they go out on mount and land while it is still resolving.
67
+ */
68
+ async function loadWindowless() {
69
+ try {
70
+ const [s, w, a] = await Promise.all([
71
+ getSummary(),
72
+ getWatchList(5),
73
+ getActivity(),
74
+ ])
75
+ summary.value = s
76
+ watchList.value = w
77
+ activity.value = a
78
+ } catch (e) {
79
+ fail(e)
80
+ }
81
+ }
82
+
83
+ async function loadForPeriod() {
84
+ const window = period.value
85
+ if (!window) return
86
+ loading.value = true
87
+ error.value = null
88
+ try {
89
+ const [hist, bd, mon] = await Promise.all([
90
+ getSummaryHistory(window),
91
+ getStatusBreakdown(window),
92
+ getMonitoring({ period: window }),
93
+ ])
94
+ history.value = hist
95
+ breakdown.value = bd
96
+ monitoring.value = mon
97
+ } catch (e) {
98
+ fail(e)
99
+ } finally {
100
+ loading.value = false
101
+ }
102
+ }
103
+
104
+ /** Refresh button: everything, whatever it depends on. */
105
+ async function load() {
106
+ await Promise.all([loadWindowless(), loadForPeriod()])
107
+ }
108
+
109
+ onMounted(loadWindowless)
110
+
111
+ // The window owns the fetches that depend on it: the first runs as soon as
112
+ // <PeriodSelect> resolves one, and every later change re-runs it. Nothing fires
113
+ // while `period` is null, which is also what keeps SSR from fetching (the
114
+ // selector resolves on mount, client-side).
115
+ watch(period, () => void loadForPeriod(), { immediate: true })
116
+
117
+ // Beta banner body: the reference design bolds a few key phrases. The i18n
118
+ // string marks them with **…** (per-locale, so each translation owns its own
119
+ // emphasis); we split on those markers into normal/bold segments — no v-html.
120
+ const betaSegments = computed(() =>
121
+ t('page.api.summary.beta.description')
122
+ .split(/\*\*(.+?)\*\*/g)
123
+ .map((text, index) => ({ text, bold: index % 2 === 1 })),
124
+ )
125
+
126
+ // --- Stat cards (6) ---------------------------------------------------------
127
+ interface StatCard {
128
+ label: string
129
+ value: number
130
+ unit?: string
131
+ icon: string
132
+ }
133
+
134
+ const statCards = computed<StatCard[]>(() => {
135
+ const k = summary.value?.kpis
136
+ if (!k) return []
137
+ return [
138
+ {
139
+ label: t('page.api.summary.kpis.total_routes'),
140
+ value: k.totalRoutes,
141
+ icon: 'i-ph-tree-structure',
142
+ },
143
+ {
144
+ label: t('page.api.summary.kpis.calls_today'),
145
+ value: k.callsToday,
146
+ icon: 'i-ph-activity',
147
+ },
148
+ {
149
+ label: t('page.api.summary.kpis.avg_latency'),
150
+ value: Math.round(k.averageLatencyMs),
151
+ unit: 'ms',
152
+ icon: 'i-ph-gauge',
153
+ },
154
+ {
155
+ label: t('page.api.summary.kpis.errors_24h'),
156
+ value: k.errors24h,
157
+ icon: 'i-ph-x-circle',
158
+ },
159
+ {
160
+ label: t('page.api.summary.kpis.routes_with_errors_24h'),
161
+ value: k.routesWithErrors24h,
162
+ icon: 'i-ph-warning',
163
+ },
164
+ {
165
+ label: t('page.api.summary.kpis.slow_routes'),
166
+ value: k.slowRoutesCount,
167
+ icon: 'i-ph-clock',
168
+ },
169
+ ]
170
+ })
171
+
172
+ // --- Traffic chart (area, requests vs errors) ------------------------------
173
+ const trafficSeries = computed(() => [
174
+ {
175
+ name: t('page.api.summary.history.requests'),
176
+ data: history.value.map((p) => ({ x: p.label, y: p.success })),
177
+ color: C_REQUESTS,
178
+ },
179
+ {
180
+ name: t('page.api.summary.history.errors'),
181
+ data: history.value.map((p) => ({
182
+ x: p.label,
183
+ y: p.clientErrors + p.serverErrors,
184
+ })),
185
+ color: C_ERRORS,
186
+ },
187
+ ])
188
+
189
+ const hasTraffic = computed(() =>
190
+ history.value.some((p) => p.success + p.clientErrors + p.serverErrors > 0),
191
+ )
192
+
193
+ // --- Status breakdown -------------------------------------------------------
194
+ const breakdownTotal = computed(() => breakdown.value?.total ?? 0)
195
+
196
+ const donutSegments = computed(() => {
197
+ const b = breakdown.value
198
+ if (!b) return []
199
+ return STATUS_CLASSES.map((s) => ({
200
+ label: t(s.i18nKey),
201
+ value: b[s.key],
202
+ color: s.color,
203
+ }))
204
+ })
205
+
206
+ const breakdownViewItems = computed(() => [
207
+ { label: t('page.api.summary.breakdown.by_day'), value: 'bars' },
208
+ { label: t('page.api.summary.breakdown.donut'), value: 'donut' },
209
+ ])
210
+
211
+ // --- Needs attention --------------------------------------------------------
212
+ const filteredWatch = computed(() => {
213
+ const q = uriFilter.value.trim().toLowerCase()
214
+ if (!q) return watchList.value
215
+ return watchList.value.filter((w) => w.uri.toLowerCase().includes(q))
216
+ })
217
+
218
+ function severityFor(item: WatchListItem): {
219
+ color: 'error' | 'warning'
220
+ label: string
221
+ } {
222
+ if (item.flag === 'broken')
223
+ return { color: 'error', label: t('page.api.summary.watch.severity_critical') }
224
+ return { color: 'warning', label: t('page.api.summary.watch.severity_warning') }
225
+ }
226
+
227
+ // --- Slowest routes ---------------------------------------------------------
228
+ const slowest = computed<RouteAggregate[]>(() => {
229
+ const q = uriFilter.value.trim().toLowerCase()
230
+ const list = monitoring.value?.slowest.filter((r) => r.requestsCount > 0) ?? []
231
+ if (!q) return list
232
+ return list.filter((r) => r.uri.toLowerCase().includes(q))
233
+ })
234
+
235
+ // --- Recent requests --------------------------------------------------------
236
+ const recent = computed(() => {
237
+ const q = uriFilter.value.trim().toLowerCase()
238
+ const list = monitoring.value?.recent ?? []
239
+ if (!q) return list
240
+ return list.filter((r) => r.uri.toLowerCase().includes(q))
241
+ })
242
+
243
+ // --- Drill-downs --------------------------------------------------------------
244
+ // Route rows (needs-attention, slowest, error activity) jump to the Logs page
245
+ // pre-filtered on the route URI; recent-request rows open the full log in the
246
+ // same drawer as the Logs page. The module pages share the
247
+ // /modules/<module>/<page> prefix, so swap the last path segment to stay
248
+ // mount-point agnostic.
249
+ function goToLogs(uri: string) {
250
+ // Carry the window the user was looking at, or a period-scoped row (e.g. a
251
+ // slowest route whose only traffic is days old) lands on a narrower list than
252
+ // the one the row came from. Both pages speak the same `Nd` values, so it
253
+ // travels as-is. Rows only exist once a window resolved, so the null branch
254
+ // is just there to keep the query clean.
255
+ const logsPeriod = period.value
256
+ void router.push({
257
+ path: route.path.replace(/[^/]+$/, 'logs'),
258
+ query: logsPeriod ? { search: uri, period: logsPeriod } : { search: uri },
259
+ })
260
+ }
261
+
262
+ const { loadingDetailId, openLogDetail } = useLogDetailDrawer()
263
+
264
+ // --- Helpers ----------------------------------------------------------------
265
+ function fmtPct(rate: number): string {
266
+ return `${(Math.round(rate * 10000) / 100).toFixed(2)}%`
267
+ }
268
+
269
+ function fmtTime(ts: string): string {
270
+ return new Date(ts).toLocaleTimeString()
271
+ }
272
+
273
+ function activityAgo(ts: string): string {
274
+ const diff = Date.now() - new Date(ts).getTime()
275
+ const m = Math.floor(diff / 60_000)
276
+ if (m < 1) return t('page.api.summary.activity.ago_now')
277
+ if (m < 60) return t('page.api.summary.activity.ago_minutes', { n: m })
278
+ const h = Math.floor(m / 60)
279
+ if (h < 24) return t('page.api.summary.activity.ago_hours', { n: h })
280
+ return t('page.api.summary.activity.ago_days', { n: Math.floor(h / 24) })
281
+ }
282
+ </script>
283
+
284
+ <template>
285
+ <div class="flex w-full flex-col gap-5 p-6">
286
+ <!-- Beta banner -->
287
+ <DmsBanner
288
+ icon="i-ph-info"
289
+ color="warning"
290
+ :title="$t('page.api.summary.beta.title')"
291
+ >
292
+ <template #description>
293
+ <span>
294
+ <template v-for="(seg, i) in betaSegments" :key="i"
295
+ ><strong v-if="seg.bold" class="font-semibold text-toned">{{
296
+ seg.text
297
+ }}</strong
298
+ ><template v-else>{{ seg.text }}</template></template
299
+ >
300
+ </span>
301
+ </template>
302
+ </DmsBanner>
303
+
304
+ <!-- Page head -->
305
+ <header class="flex flex-wrap items-center gap-4">
306
+ <div
307
+ class="grid size-11 shrink-0 place-items-center rounded-xl bg-primary/10 text-primary"
308
+ >
309
+ <UIcon name="i-ph-gauge" class="size-[22px]" />
310
+ </div>
311
+ <div class="min-w-0 flex-1">
312
+ <h1 class="text-2xl font-semibold tracking-tight text-highlighted">
313
+ {{ $t('page.api.summary.title') }}
314
+ </h1>
315
+ <p class="text-sm text-muted">
316
+ {{ $t('page.api.summary.description') }}
317
+ </p>
318
+ </div>
319
+ <div class="flex items-center gap-2.5">
320
+ <UInput
321
+ v-model="uriFilter"
322
+ icon="i-ph-funnel"
323
+ size="sm"
324
+ :placeholder="$t('page.api.summary.filter_placeholder')"
325
+ class="w-56"
326
+ />
327
+ <PeriodSelect v-model="period" class="w-32" />
328
+ <UButton
329
+ icon="i-ph-arrow-clockwise"
330
+ color="neutral"
331
+ variant="subtle"
332
+ size="sm"
333
+ :loading="loading"
334
+ @click="load"
335
+ >
336
+ {{ $t('page.api.logs.refresh') }}
337
+ </UButton>
338
+ </div>
339
+ </header>
340
+
341
+ <div
342
+ v-if="error"
343
+ class="rounded-lg border border-error bg-error/10 p-3 text-sm text-error"
344
+ >
345
+ {{ error }}
346
+ </div>
347
+
348
+ <template v-else>
349
+ <!-- Stat cards -->
350
+ <div
351
+ v-if="statCards.length"
352
+ class="grid grid-cols-2 gap-4 sm:grid-cols-3 xl:grid-cols-6"
353
+ >
354
+ <DmsKpiCard
355
+ v-for="c in statCards"
356
+ :key="c.label"
357
+ variant="stat"
358
+ :show-delta="false"
359
+ :title="c.label"
360
+ :icon="c.icon"
361
+ :static-value="c.value"
362
+ :value-format="c.unit ? 'number' : 'compact'"
363
+ :compare-label="c.unit"
364
+ />
365
+ </div>
366
+ <div v-else class="grid grid-cols-2 gap-4 sm:grid-cols-3 xl:grid-cols-6">
367
+ <DmsCard v-for="i in 6" :key="i" :padded="false" class="p-5">
368
+ <USkeleton class="h-3 w-3/5" />
369
+ <USkeleton class="mt-3 h-7 w-2/5" />
370
+ </DmsCard>
371
+ </div>
372
+
373
+ <!-- Traffic chart + status breakdown -->
374
+ <div class="grid grid-cols-1 gap-5 xl:grid-cols-2">
375
+ <DmsCard :padded="false" class="overflow-hidden">
376
+ <div class="flex items-start justify-between gap-3 px-5 pt-5 sm:px-6">
377
+ <div>
378
+ <h2 class="text-base font-semibold text-highlighted">
379
+ {{ $t('page.api.summary.history.title') }}
380
+ </h2>
381
+ <p class="text-sm text-dimmed">
382
+ {{ $t('page.api.summary.history.subtitle') }}
383
+ </p>
384
+ </div>
385
+ <div class="flex items-center gap-3 text-xs text-muted">
386
+ <span class="flex items-center gap-1.5">
387
+ <span
388
+ class="size-2.5 rounded-full"
389
+ :style="{ background: C_REQUESTS }"
390
+ />
391
+ {{ $t('page.api.summary.history.requests') }}
392
+ </span>
393
+ <span class="flex items-center gap-1.5">
394
+ <span
395
+ class="size-2.5 rounded-full"
396
+ :style="{ background: C_ERRORS }"
397
+ />
398
+ {{ $t('page.api.summary.history.errors') }}
399
+ </span>
400
+ </div>
401
+ </div>
402
+ <div class="px-2 pb-2 pt-2">
403
+ <DmsChart
404
+ v-if="hasTraffic"
405
+ type="area"
406
+ :static-dataset="trafficSeries"
407
+ :smooth="true"
408
+ :show-legend="false"
409
+ :color="[C_REQUESTS, C_ERRORS]"
410
+ height="300px"
411
+ />
412
+ <div
413
+ v-else
414
+ class="flex flex-col items-center justify-center gap-2 text-dimmed"
415
+ style="height: 300px"
416
+ >
417
+ <UIcon name="i-ph-chart-line" class="size-7" />
418
+ <small>{{ $t('page.api.summary.history.empty') }}</small>
419
+ </div>
420
+ </div>
421
+ </DmsCard>
422
+
423
+ <DmsCard :padded="false" class="overflow-hidden">
424
+ <div class="flex items-start justify-between gap-3 px-5 pt-5 sm:px-6">
425
+ <div>
426
+ <h2 class="text-base font-semibold text-highlighted">
427
+ {{ $t('page.api.summary.breakdown.title') }}
428
+ </h2>
429
+ <p class="text-sm text-dimmed">
430
+ {{ $t('page.api.summary.breakdown.subtitle') }}
431
+ </p>
432
+ </div>
433
+ <DmsSegmented
434
+ v-model="breakdownView"
435
+ :items="breakdownViewItems"
436
+ :aria-label="$t('page.api.summary.breakdown.title')"
437
+ />
438
+ </div>
439
+ <div class="px-2 pb-4 pt-3">
440
+ <template v-if="breakdownTotal > 0">
441
+ <StatusDonut
442
+ v-if="breakdownView === 'donut'"
443
+ :segments="donutSegments"
444
+ :total="breakdownTotal"
445
+ :center-sub-label="$t('page.api.summary.breakdown.responses')"
446
+ />
447
+ <StatusBreakdownBars v-else :history="history" />
448
+ </template>
449
+ <div
450
+ v-else
451
+ class="flex flex-col items-center justify-center gap-2 text-dimmed"
452
+ style="height: 280px"
453
+ >
454
+ <UIcon name="i-ph-chart-donut" class="size-7" />
455
+ <small>{{ $t('page.api.summary.breakdown.empty') }}</small>
456
+ </div>
457
+ </div>
458
+ </DmsCard>
459
+ </div>
460
+
461
+ <!-- Needs attention + slowest routes -->
462
+ <div class="grid grid-cols-1 gap-5 xl:grid-cols-2">
463
+ <DmsCard :padded="false" class="overflow-hidden">
464
+ <div
465
+ class="flex items-center justify-between gap-3 border-b border-default px-5 py-4 sm:px-6"
466
+ >
467
+ <div>
468
+ <h2 class="text-base font-semibold text-highlighted">
469
+ {{ $t('page.api.summary.watch.title') }}
470
+ </h2>
471
+ <p class="text-sm text-dimmed">
472
+ {{ $t('page.api.summary.watch.subtitle') }}
473
+ </p>
474
+ </div>
475
+ <UBadge color="neutral" variant="subtle">{{ filteredWatch.length }}</UBadge>
476
+ </div>
477
+ <div
478
+ v-if="filteredWatch.length === 0"
479
+ class="flex flex-col items-center gap-2 px-6 py-8 text-center"
480
+ >
481
+ <UIcon name="i-ph-check-circle" class="size-7 text-success" />
482
+ <b class="text-sm text-highlighted">
483
+ {{ $t('page.api.summary.watch.empty_title') }}
484
+ </b>
485
+ <small class="text-dimmed">
486
+ {{ $t('page.api.summary.watch.empty_description') }}
487
+ </small>
488
+ </div>
489
+ <div v-else class="divide-y divide-default">
490
+ <DmsActivityItem
491
+ v-for="item in filteredWatch"
492
+ :key="item.routeKey"
493
+ mono
494
+ class="cursor-pointer"
495
+ @click="goToLogs(item.uri)"
496
+ >
497
+ <ApiMethodBadge :method="item.method" />
498
+ <span class="truncate">{{ item.uri }}</span>
499
+ <template #subtitle>
500
+ {{ item.requestsLast24h }}
501
+ {{ $t('page.api.summary.watch.requests_24h') }}
502
+ · <span class="text-error">{{ fmtPct(item.errorRate) }}</span>
503
+ · {{ Math.round(item.averageLatencyMs) }} ms
504
+ </template>
505
+ <template #trailing>
506
+ <UBadge :color="severityFor(item).color" variant="subtle" size="sm">
507
+ {{ severityFor(item).label }}
508
+ </UBadge>
509
+ </template>
510
+ </DmsActivityItem>
511
+ </div>
512
+ </DmsCard>
513
+
514
+ <DmsCard :padded="false" class="overflow-hidden">
515
+ <div class="border-b border-default px-5 py-4 sm:px-6">
516
+ <h2 class="text-base font-semibold text-highlighted">
517
+ {{ $t('page.api.summary.slowest.title') }}
518
+ </h2>
519
+ <p class="text-sm text-dimmed">
520
+ {{ $t('page.api.summary.slowest.subtitle') }}
521
+ </p>
522
+ </div>
523
+ <div
524
+ v-if="slowest.length === 0"
525
+ class="flex flex-col items-center gap-2 px-6 py-8 text-center"
526
+ >
527
+ <UIcon name="i-ph-clock" class="size-7 text-dimmed" />
528
+ <small class="text-dimmed">{{ $t('page.api.summary.slowest.empty') }}</small>
529
+ </div>
530
+ <div v-else class="divide-y divide-default">
531
+ <DmsActivityItem
532
+ v-for="r in slowest"
533
+ :key="r.routeKey"
534
+ mono
535
+ class="cursor-pointer"
536
+ @click="goToLogs(r.uri)"
537
+ >
538
+ <ApiMethodBadge :method="r.method" />
539
+ <span class="truncate">{{ r.uri }}</span>
540
+ <template #trailing>
541
+ <span class="text-toned">{{ Math.round(r.averageLatencyMs) }} ms</span>
542
+ <span class="ml-3 text-dimmed">{{ Math.round(r.maxLatencyMs) }} ms</span>
543
+ </template>
544
+ </DmsActivityItem>
545
+ </div>
546
+ </DmsCard>
547
+ </div>
548
+
549
+ <!-- Recent requests + activity -->
550
+ <div class="grid grid-cols-1 gap-5 xl:grid-cols-2">
551
+ <DmsCard :padded="false" class="overflow-hidden">
552
+ <div class="border-b border-default px-5 py-4 sm:px-6">
553
+ <h2 class="text-base font-semibold text-highlighted">
554
+ {{ $t('page.api.summary.recent.title') }}
555
+ </h2>
556
+ <p class="text-sm text-dimmed">
557
+ {{ $t('page.api.summary.recent.subtitle') }}
558
+ </p>
559
+ </div>
560
+ <div class="overflow-x-auto">
561
+ <table class="w-full text-sm">
562
+ <thead>
563
+ <tr
564
+ class="border-b border-default text-left font-mono text-[10px] uppercase tracking-widest text-dimmed"
565
+ >
566
+ <th class="px-5 py-2.5 sm:px-6">
567
+ {{ $t('page.api.summary.recent.col_time') }}
568
+ </th>
569
+ <th class="px-2 py-2.5">{{ $t('page.api.summary.recent.col_method') }}</th>
570
+ <th class="px-2 py-2.5">{{ $t('page.api.summary.recent.col_path') }}</th>
571
+ <th class="px-2 py-2.5">{{ $t('page.api.summary.recent.col_status') }}</th>
572
+ <th class="px-5 py-2.5 text-right sm:px-6">
573
+ {{ $t('page.api.summary.recent.col_ms') }}
574
+ </th>
575
+ </tr>
576
+ </thead>
577
+ <tbody>
578
+ <tr v-if="recent.length === 0">
579
+ <td colspan="5" class="px-6 py-8 text-center text-dimmed">
580
+ {{ $t('page.api.summary.recent.empty') }}
581
+ </td>
582
+ </tr>
583
+ <tr
584
+ v-for="row in recent"
585
+ :key="row._id"
586
+ class="cursor-pointer border-b border-default/60 last:border-0 hover:bg-elevated/40"
587
+ @click="openLogDetail(row)"
588
+ >
589
+ <td class="px-5 py-2 font-mono text-xs text-muted sm:px-6">
590
+ {{ fmtTime(row.timestamp) }}
591
+ </td>
592
+ <td class="px-2 py-2">
593
+ <ApiMethodBadge :method="row.method" />
594
+ </td>
595
+ <td class="px-2 py-2 font-mono text-xs text-toned">{{ row.uri }}</td>
596
+ <td class="px-2 py-2">
597
+ <ApiStatusBadge :status="row.statusCode" />
598
+ </td>
599
+ <td class="px-5 py-2 text-right font-mono text-xs text-muted sm:px-6">
600
+ {{ Math.round(row.responseTimeMs) }}
601
+ <UIcon
602
+ v-if="loadingDetailId === row._id"
603
+ name="i-ph-spinner"
604
+ class="ml-1 animate-spin"
605
+ />
606
+ </td>
607
+ </tr>
608
+ </tbody>
609
+ </table>
610
+ </div>
611
+ </DmsCard>
612
+
613
+ <DmsCard :padded="false" class="overflow-hidden">
614
+ <div class="border-b border-default px-5 py-4 sm:px-6">
615
+ <h2 class="text-base font-semibold text-highlighted">
616
+ {{ $t('page.api.summary.activity.title') }}
617
+ </h2>
618
+ <p class="text-sm text-dimmed">
619
+ {{ $t('page.api.summary.activity.subtitle') }}
620
+ </p>
621
+ </div>
622
+ <div
623
+ v-if="activity.length === 0"
624
+ class="flex flex-col items-center gap-2 px-6 py-8 text-center"
625
+ >
626
+ <UIcon name="i-ph-clock" class="size-7 text-dimmed" />
627
+ <small class="text-dimmed">
628
+ {{ $t('page.api.summary.activity.empty_description') }}
629
+ </small>
630
+ </div>
631
+ <div v-else class="divide-y divide-default">
632
+ <DmsActivityItem
633
+ v-for="(item, idx) in activity"
634
+ :key="`${item.kind}-${item.timestamp}-${idx}`"
635
+ :icon="item.kind === 'error' ? 'i-ph-x-circle' : 'i-ph-plus'"
636
+ :icon-color="item.kind === 'error' ? 'error' : 'success'"
637
+ :trailing="activityAgo(item.timestamp)"
638
+ :class="item.kind === 'error' ? 'cursor-pointer' : ''"
639
+ @click="item.kind === 'error' && goToLogs(item.uri)"
640
+ >
641
+ <span>
642
+ {{
643
+ item.kind === 'error'
644
+ ? $t('page.api.summary.activity.error')
645
+ : $t('page.api.summary.activity.route_created')
646
+ }}
647
+ </span>
648
+ <ApiMethodBadge :method="item.method" />
649
+ <span class="truncate font-mono text-[12px]">{{ item.uri }}</span>
650
+ <ApiStatusBadge v-if="item.statusCode" :status="item.statusCode" />
651
+ </DmsActivityItem>
652
+ </div>
653
+ </DmsCard>
654
+ </div>
655
+ </template>
656
+ </div>
657
+ </template>