@antelopejs/dms-api 0.5.1 → 0.6.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 (136) hide show
  1. package/README.md +18 -6
  2. package/dist/automation/query-request-logs.js.map +1 -1
  3. package/dist/automation/route-unhealthy.js.map +1 -1
  4. package/dist/db/models/request_log.model.js.map +1 -1
  5. package/dist/db/models/request_log.search.js +3 -3
  6. package/dist/db/models/request_log.search.js.map +1 -1
  7. package/dist/db/tables/request_log.table.js.map +1 -1
  8. package/dist/guards.d.ts +22 -0
  9. package/dist/guards.js +57 -0
  10. package/dist/guards.js.map +1 -0
  11. package/dist/index.js.map +1 -1
  12. package/dist/pages/blocks.d.ts +2 -2
  13. package/dist/pages/blocks.js +2 -2
  14. package/dist/pages/blocks.js.map +1 -1
  15. package/dist/pages/index.js.map +1 -1
  16. package/dist/pages/logs.js.map +1 -1
  17. package/dist/pages/module.js +8 -2
  18. package/dist/pages/module.js.map +1 -1
  19. package/dist/pages/overview.js.map +1 -1
  20. package/dist/pages/request-table.js.map +1 -1
  21. package/dist/pages/routes.js.map +1 -1
  22. package/dist/pages/settings.js +1 -3
  23. package/dist/pages/settings.js.map +1 -1
  24. package/dist/routes/logs.js.map +1 -1
  25. package/dist/routes/routes.js.map +1 -1
  26. package/dist/routes/settings.d.ts +2 -1
  27. package/dist/routes/settings.js +1 -1
  28. package/dist/routes/settings.js.map +1 -1
  29. package/dist/services/activity.js.map +1 -1
  30. package/dist/services/attention.js +1 -1
  31. package/dist/services/attention.js.map +1 -1
  32. package/dist/services/health-rules.js.map +1 -1
  33. package/dist/services/introspection/auth.js +1 -2
  34. package/dist/services/introspection/auth.js.map +1 -1
  35. package/dist/services/introspection/decorators.d.ts +3 -1
  36. package/dist/services/introspection/decorators.js +28 -17
  37. package/dist/services/introspection/decorators.js.map +1 -1
  38. package/dist/services/introspection/errors.d.ts +1 -1
  39. package/dist/services/introspection/errors.js +0 -2
  40. package/dist/services/introspection/errors.js.map +1 -1
  41. package/dist/services/introspection/index.d.ts +1 -1
  42. package/dist/services/introspection/index.js +24 -18
  43. package/dist/services/introspection/index.js.map +1 -1
  44. package/dist/services/introspection/probe.js.map +1 -1
  45. package/dist/services/links.js +4 -4
  46. package/dist/services/links.js.map +1 -1
  47. package/dist/services/live.d.ts +3 -2
  48. package/dist/services/live.js.map +1 -1
  49. package/dist/services/overview-lists.d.ts +4 -4
  50. package/dist/services/overview-lists.js.map +1 -1
  51. package/dist/services/overview.d.ts +4 -4
  52. package/dist/services/overview.js.map +1 -1
  53. package/dist/services/request-log/capture.d.ts +5 -14
  54. package/dist/services/request-log/capture.js +28 -76
  55. package/dist/services/request-log/capture.js.map +1 -1
  56. package/dist/services/request-log/console-traffic.d.ts +12 -0
  57. package/dist/services/request-log/console-traffic.js +69 -0
  58. package/dist/services/request-log/console-traffic.js.map +1 -0
  59. package/dist/services/request-log/list.d.ts +1 -1
  60. package/dist/services/request-log/list.js.map +1 -1
  61. package/dist/services/request-log/read.js.map +1 -1
  62. package/dist/services/request-log/redaction.js +7 -6
  63. package/dist/services/request-log/redaction.js.map +1 -1
  64. package/dist/services/request-log/util.d.ts +6 -3
  65. package/dist/services/request-log/util.js +17 -30
  66. package/dist/services/request-log/util.js.map +1 -1
  67. package/dist/services/route-catalog.js +2 -2
  68. package/dist/services/route-catalog.js.map +1 -1
  69. package/dist/services/route-contract.d.ts +6 -1
  70. package/dist/services/route-contract.js +11 -12
  71. package/dist/services/route-contract.js.map +1 -1
  72. package/dist/services/route-health.d.ts +5 -1
  73. package/dist/services/route-health.js +4 -1
  74. package/dist/services/route-health.js.map +1 -1
  75. package/dist/services/route-statistics.d.ts +3 -4
  76. package/dist/services/route-statistics.js.map +1 -1
  77. package/dist/services/routes-sync.d.ts +2 -2
  78. package/dist/services/routes-sync.js +13 -4
  79. package/dist/services/routes-sync.js.map +1 -1
  80. package/dist/services/scope.js +1 -1
  81. package/dist/services/scope.js.map +1 -1
  82. package/dist/services/settings-form.d.ts +4 -3
  83. package/dist/services/settings-form.js +1 -1
  84. package/dist/services/settings-form.js.map +1 -1
  85. package/dist/services/settings.js.map +1 -1
  86. package/dist/services/statistics-write.js +4 -7
  87. package/dist/services/statistics-write.js.map +1 -1
  88. package/dist/services/traffic-samples.js.map +1 -1
  89. package/dist/services/traffic.js +2 -1
  90. package/dist/services/traffic.js.map +1 -1
  91. package/dist/services/window.js +1 -1
  92. package/dist/services/window.js.map +1 -1
  93. package/dist/types/constants.js.map +1 -1
  94. package/dist/types/index.d.ts +1 -0
  95. package/dist/types/index.js +1 -0
  96. package/dist/types/index.js.map +1 -1
  97. package/dist/types/json.d.ts +2 -0
  98. package/dist/types/json.js +3 -0
  99. package/dist/types/json.js.map +1 -0
  100. package/frontend-vue/app/components/blocks/HealthHero.vue +8 -117
  101. package/frontend-vue/app/components/blocks/RequestDetail.vue +18 -153
  102. package/frontend-vue/app/components/blocks/RouteDocumentation.vue +2 -151
  103. package/frontend-vue/app/components/blocks/RouteHeader.vue +7 -8
  104. package/frontend-vue/app/components/blocks/RouteTester.vue +58 -1682
  105. package/frontend-vue/app/components/blocks/RouteTree.vue +16 -81
  106. package/frontend-vue/app/components/internal/HealthHeroMetrics.vue +50 -0
  107. package/frontend-vue/app/components/internal/RequestGeneral.vue +32 -0
  108. package/frontend-vue/app/components/internal/RequestTiming.vue +85 -0
  109. package/frontend-vue/app/components/internal/RouteInternals.vue +159 -0
  110. package/frontend-vue/app/components/internal/RouteTesterRequest.vue +225 -0
  111. package/frontend-vue/app/components/internal/RouteTesterResponse.vue +272 -0
  112. package/frontend-vue/app/components/internal/RouteTreeFooter.vue +62 -0
  113. package/frontend-vue/app/components/internal/routeTester/context.ts +8 -0
  114. package/frontend-vue/app/components/internal/routeTester/useTesterExtras.ts +284 -0
  115. package/frontend-vue/app/components/internal/routeTester/useTesterFlow.ts +637 -0
  116. package/frontend-vue/app/components/internal/routeTester/useTesterState.ts +601 -0
  117. package/frontend-vue/app/utils/health.ts +73 -0
  118. package/frontend-vue/app/utils/requestDrawer.ts +49 -0
  119. package/frontend-vue/app/utils/routeExplorer.ts +34 -0
  120. package/frontend-vue/app/utils/testerMasks.ts +34 -0
  121. package/frontend-vue/app/utils/testerRequest.ts +14 -38
  122. package/frontend-vue/build/backend-boundary.ts +122 -0
  123. package/frontend-vue/dms.frontend.build.ts +2 -0
  124. package/frontend-vue/eslint.config.mjs +13 -0
  125. package/frontend-vue/package.json +6 -3
  126. package/frontend-vue/pnpm-lock.yaml +348 -153
  127. package/frontend-vue/tests/apiErrorPresentation.test.ts +115 -0
  128. package/frontend-vue/tests/backend-boundary.test.ts +180 -0
  129. package/frontend-vue/tests/dmsServer.test.ts +11 -23
  130. package/frontend-vue/tests/registration.test.ts +22 -6
  131. package/frontend-vue/tests/stubs/server.ts +19 -0
  132. package/frontend-vue/tests/testerRequest.test.ts +14 -0
  133. package/frontend-vue/vitest.config.ts +16 -0
  134. package/package.json +16 -4
  135. package/skills/dms-api/SKILL.md +1 -1
  136. package/skills/dms-api/cases.json +47 -0
@@ -0,0 +1,601 @@
1
+ import { computed, reactive, ref, useId } from 'vue'
2
+ import { formatBytes } from '../../../utils/format'
3
+ import {
4
+ acceptsRequestBody,
5
+ isWritingMethod,
6
+ pathSegments,
7
+ } from '../../../utils/http'
8
+ import { fillPath } from '../../../utils/snippets'
9
+ import {
10
+ type BodyOrigin,
11
+ type DraftRequest,
12
+ exampleRequest,
13
+ type HistoryEntry,
14
+ isSecretHeader,
15
+ loadCommonHeaders,
16
+ type ReplayInfo,
17
+ sameRequest,
18
+ } from '../../../utils/testerHistory'
19
+ import {
20
+ type AuthMode,
21
+ authModeOf,
22
+ type BodyMode,
23
+ type CapturedRequest,
24
+ contentTypeFor,
25
+ countRedacted,
26
+ createSourceTokens,
27
+ formatJson,
28
+ inputProblem,
29
+ jsonProblem,
30
+ type KeyValue,
31
+ markedHeaders,
32
+ mergeHeaders,
33
+ neverSent,
34
+ PROXY_BODY_LIMIT,
35
+ redactedFields,
36
+ revealBidi,
37
+ serializeBody,
38
+ SIZE_PROBE_SOURCE,
39
+ TESTER_SOURCE_URL,
40
+ type TesterErrorCode,
41
+ type TesterRequest,
42
+ type TesterResult,
43
+ type TesterSourceToken,
44
+ withQueryRows,
45
+ } from '../../../utils/testerRequest'
46
+
47
+ export interface Row extends KeyValue {
48
+ id: number
49
+ }
50
+
51
+ /** A row of the logs list, as far as finding a captured call goes. */
52
+ export interface CapturedRow {
53
+ _id: string
54
+ route?: string
55
+ timestamp: string
56
+ requestId?: string
57
+ }
58
+
59
+ export type CapturedState = 'idle' | 'loading' | 'found' | 'missing' | 'error'
60
+
61
+ /** A backend read of the tester's own flows (a replay, a capture lookup). */
62
+ export type ReadJson = <R>(url: string) => Promise<R>
63
+
64
+ /** What the tester keeps outside its reactive state: the route it is on, the call in flight. */
65
+ interface TesterSession {
66
+ activeRef: string | null
67
+ inFlight: { controller: AbortController; ref: string } | null
68
+ confirming: boolean
69
+ unmounted: boolean
70
+ }
71
+
72
+ /** The props of `RouteTester`. */
73
+ export interface RouteTesterProps {
74
+ fetchUrl: string
75
+ queryKey?: string
76
+ }
77
+
78
+ /**
79
+ * The tester's state, as `RouteTester` sets it up: its constants, its
80
+ * fields and what they compute.
81
+ */
82
+ export function useTesterState(props: RouteTesterProps) {
83
+ /**
84
+ * A read the tester runs when it needs it (a replay, a lookup after a call),
85
+ * in the browser only and never again on the page's refreshes.
86
+ */
87
+ const ON_DEMAND = {
88
+ immediate: false,
89
+ server: false,
90
+ watch: false,
91
+ refreshOnPageRefresh: false,
92
+ } as const
93
+
94
+ // The tester's own reads of the request logs: by its permission, not the
95
+ // request logs page's.
96
+ const LOGS_API = '/api/monitoring/logs/tester'
97
+ const LOGS_PAGE = '/modules/api/logs'
98
+ /**
99
+ * Abort reason of a call left behind by a route change: filed under its
100
+ * route as abandoned, since the API may have received it.
101
+ */
102
+ const ROUTE_CHANGED = 'route-changed'
103
+ /** The capture is written once the answer is sent: looked for twice. */
104
+ const CAPTURE_DELAYS_MS = [400, 1500]
105
+ /** A captured call older than this is not the one just sent. */
106
+ const CAPTURE_MATCH_MS = 60_000
107
+ /** An id as long as a real one, to size the request before sending it. */
108
+ const SIZE_PROBE_ID = '00000000-0000-0000-0000-000000000000'
109
+ const DRAFT_SAVE_DELAY_MS = 250
110
+ const BODY_MODES: BodyMode[] = ['json', 'text', 'form', 'none']
111
+ const AUTH_ICONS: Record<AuthMode, string> = {
112
+ session: 'i-ph-user-check',
113
+ manual: 'i-ph-key',
114
+ none: 'i-ph-lock-simple-open',
115
+ }
116
+ const ERROR_ICONS: Partial<Record<TesterErrorCode, string>> = {
117
+ invalid_input: 'i-ph-prohibit',
118
+ body_too_large: 'i-ph-file-x',
119
+ not_authenticated: 'i-ph-sign-in',
120
+ not_owner: 'i-ph-lock-simple',
121
+ cross_origin: 'i-ph-shield-warning',
122
+ response_too_large: 'i-ph-file-x',
123
+ timeout: 'i-ph-timer',
124
+ aborted: 'i-ph-x-circle',
125
+ }
126
+ /**
127
+ * Error texts that send to the Captured tab: another text on a route the
128
+ * module does not capture.
129
+ */
130
+ const POINTS_TO_CAPTURED: ReadonlySet<string> = new Set([
131
+ 'proxy_failed',
132
+ 'timeout',
133
+ 'aborted',
134
+ 'abandoned',
135
+ ])
136
+
137
+ const { t } = useI18n()
138
+ const { formatLocale: locale } = useRegionalFormat({ locale: 'format' })
139
+ const dateFormat = useDateFormat()
140
+ const toast = useToast()
141
+ const { confirm } = useConfirm()
142
+ const { loggedIn } = useDmsUserSession()
143
+ const currentRoute = useDmsRoute()
144
+ const router = useDmsRouter()
145
+ const { $authFetch } = useAuthFetch()
146
+ const {
147
+ data: route,
148
+ pending,
149
+ selection,
150
+ } = useRouteDetail(props.fetchUrl, props.queryKey)
151
+ const apiOrigin = useApiOrigin(() => route.value?.apiOrigin)
152
+ const blockerId = useId()
153
+ // Not a `useApiData` read: each call mints a short-lived token, which must
154
+ // never be shared between calls, cached or handed over with the page.
155
+ const sourceTokens = createSourceTokens(() =>
156
+ $authFetch<TesterSourceToken>(TESTER_SOURCE_URL),
157
+ )
158
+ const bodyHintId = useId()
159
+
160
+ let nextRowId = 0
161
+ const row = (name = '', value = ''): Row => ({ id: nextRowId++, name, value })
162
+ const rows = (list: Row[]): KeyValue[] =>
163
+ list.map(({ name, value }) => ({ name, value }))
164
+
165
+ const bodyMode = ref<BodyMode>('none')
166
+ const body = ref('')
167
+ const form = reactive<Row[]>([])
168
+ const headers = reactive<Row[]>([])
169
+ const query = reactive<Row[]>([])
170
+ const pathValues = reactive<Record<string, string>>({})
171
+ const useSession = ref(true)
172
+ const origin = ref<BodyOrigin>('example')
173
+ const replayInfo = ref<ReplayInfo | null>(null)
174
+ const result = ref<TesterResult | null>(null)
175
+ const commonHeaders = reactive<Row[]>(
176
+ loadCommonHeaders().map((entry) => row(entry.name, entry.value)),
177
+ )
178
+ const history = ref<HistoryEntry[]>([])
179
+ const tab = ref('body')
180
+ const responseTab = ref('body')
181
+ const sending = ref(false)
182
+ const capturedState = ref<CapturedState>('idle')
183
+ const capturedLog = ref<CapturedRequest | null>(null)
184
+
185
+ // The route the fields belong to, the call in flight and its route.
186
+ const session: TesterSession = {
187
+ activeRef: null,
188
+ inFlight: null,
189
+ confirming: false,
190
+ unmounted: false,
191
+ }
192
+ // The route the fields were filled for: they come from this browser's drafts,
193
+ // history and headers, so the tester shows once mounted, never on a server.
194
+ const filledRef = ref<string | null>(null)
195
+
196
+ const method = computed(() => route.value?.method ?? 'GET')
197
+ const bodyAllowed = computed(() => acceptsRequestBody(method.value))
198
+ const writes = computed(() => isWritingMethod(method.value))
199
+ const isDelete = computed(() => method.value.toUpperCase() === 'DELETE')
200
+
201
+ const draftRequest = computed<DraftRequest>(() => ({
202
+ bodyMode: bodyMode.value,
203
+ body: body.value,
204
+ form: rows(form),
205
+ headers: rows(headers),
206
+ query: rows(query),
207
+ pathValues: { ...pathValues },
208
+ useSession: useSession.value,
209
+ }))
210
+
211
+ const example = computed(() =>
212
+ route.value
213
+ ? exampleRequest(
214
+ {
215
+ method: route.value.method,
216
+ pathParams: route.value.pathParams,
217
+ exampleBody: route.value.contract.exampleBody,
218
+ examplePath: route.value.contract.examplePath,
219
+ authStatus: route.value.auth.status,
220
+ },
221
+ history.value,
222
+ )
223
+ : null,
224
+ )
225
+ const modified = computed(
226
+ () => !!example.value && !sameRequest(draftRequest.value, example.value),
227
+ )
228
+
229
+ // --- The request as it leaves ---
230
+
231
+ const segments = computed(() =>
232
+ pathSegments(route.value?.path ?? '/').map((segment) => ({
233
+ ...segment,
234
+ name: segment.text.slice(1),
235
+ })),
236
+ )
237
+ const path = computed(() =>
238
+ withQueryRows(fillPath(route.value?.path ?? '/', pathValues), query),
239
+ )
240
+ const displayQuery = computed(() => {
241
+ const named = query.filter((entry) => entry.name)
242
+ return named.length
243
+ ? revealBidi(
244
+ `?${named.map((entry) => `${entry.name}=${entry.value}`).join('&')}`,
245
+ )
246
+ : ''
247
+ })
248
+ const missingPathParams = computed(() =>
249
+ (route.value?.pathParams ?? []).filter((name) => !pathValues[name]),
250
+ )
251
+
252
+ const sentBody = computed(() =>
253
+ bodyAllowed.value
254
+ ? serializeBody(bodyMode.value, body.value, form)
255
+ : undefined,
256
+ )
257
+ const impliedHeaders = computed(() => {
258
+ const implied: Record<string, string> = {}
259
+ const type = contentTypeFor(bodyMode.value)
260
+ if (sentBody.value !== undefined && type) implied['content-type'] = type
261
+ return implied
262
+ })
263
+ /** Headers as the API gets them, before the session and the tester's marks. */
264
+ const effectiveHeaders = computed(() =>
265
+ mergeHeaders(impliedHeaders.value, commonHeaders, headers),
266
+ )
267
+ const shownImpliedHeaders = computed(() =>
268
+ Object.entries(impliedHeaders.value).filter(
269
+ ([name]) =>
270
+ ![...commonHeaders, ...headers].some(
271
+ (entry) => entry.name.toLowerCase() === name,
272
+ ),
273
+ ),
274
+ )
275
+ const auth = computed(() =>
276
+ authModeOf(effectiveHeaders.value, useSession.value && loggedIn.value),
277
+ )
278
+ /** Who the call goes as; an Authorization of the headers for all routes says so. */
279
+ const authLabel = computed(() =>
280
+ auth.value === 'manual' &&
281
+ !headers.some((entry) => entry.name.toLowerCase() === 'authorization')
282
+ ? t('api.tester.auth.manual_common')
283
+ : t(`api.tester.auth.${auth.value}`),
284
+ )
285
+ const request = computed<TesterRequest>(() => ({
286
+ method: method.value,
287
+ headers: effectiveHeaders.value,
288
+ useSession: useSession.value && loggedIn.value,
289
+ ...(sentBody.value !== undefined ? { body: sentBody.value } : {}),
290
+ }))
291
+
292
+ const problem = computed(() =>
293
+ route.value
294
+ ? inputProblem(pathValues, path.value, {
295
+ ...request.value,
296
+ headers: markedHeaders(
297
+ request.value.headers,
298
+ SIZE_PROBE_ID,
299
+ SIZE_PROBE_SOURCE,
300
+ ),
301
+ })
302
+ : null,
303
+ )
304
+ /** Why Send is off, said next to it. */
305
+ const blocker = computed<string | null>(() => {
306
+ if (missingPathParams.value.length)
307
+ return t('api.tester.blocked.path_missing', {
308
+ names: missingPathParams.value.map((name) => `:${name}`).join(', '),
309
+ })
310
+ const value = problem.value
311
+ if (!value) return null
312
+ if (value.code === 'path_value')
313
+ return t('api.tester.blocked.path_value', { name: `:${value.name}` })
314
+ if (value.code === 'header')
315
+ return t('api.tester.blocked.header', { name: value.name })
316
+ return t('api.tester.blocked.too_large', {
317
+ size: formatBytes(value.size, locale.value),
318
+ limit: formatBytes(PROXY_BODY_LIMIT, locale.value),
319
+ })
320
+ })
321
+
322
+ const jsonWarning = computed(() =>
323
+ bodyAllowed.value && bodyMode.value === 'json'
324
+ ? jsonProblem(body.value)
325
+ : null,
326
+ )
327
+ const formattedBody = computed(() =>
328
+ bodyMode.value === 'json' && body.value.trim() && !jsonWarning.value
329
+ ? formatJson(body.value)
330
+ : null,
331
+ )
332
+
333
+ /** Masked values ([REDACTED]) still in what would be sent. */
334
+ const redactedCount = computed(() => {
335
+ const text =
336
+ bodyAllowed.value && ['json', 'text'].includes(bodyMode.value)
337
+ ? body.value
338
+ : ''
339
+ const fields = bodyMode.value === 'form' ? form : []
340
+ return (
341
+ countRedacted(text) +
342
+ [...headers, ...commonHeaders, ...query, ...fields].reduce(
343
+ (count, entry) => count + countRedacted(entry.value),
344
+ 0,
345
+ ) +
346
+ Object.values(pathValues).reduce(
347
+ (count, value) => count + countRedacted(value),
348
+ 0,
349
+ )
350
+ )
351
+ })
352
+ const redactedBodyFields = computed(() =>
353
+ ['json', 'text'].includes(bodyMode.value) ? redactedFields(body.value) : [],
354
+ )
355
+
356
+ // --- Tabs ---
357
+
358
+ const tabs = computed(() => [
359
+ ...(bodyAllowed.value
360
+ ? [{ label: t('api.tester.tabs.body'), value: 'body' }]
361
+ : []),
362
+ {
363
+ label: t('api.tester.tabs.headers'),
364
+ value: 'headers',
365
+ badge:
366
+ [...headers, ...commonHeaders].filter((entry) => entry.name).length ||
367
+ undefined,
368
+ },
369
+ {
370
+ label: t('api.tester.tabs.query'),
371
+ value: 'query',
372
+ badge: query.filter((entry) => entry.name).length || undefined,
373
+ },
374
+ ])
375
+
376
+ const bodyModeItems = computed(() =>
377
+ BODY_MODES.map((value) => ({
378
+ label: t(`api.tester.body_modes.${value}`),
379
+ value,
380
+ })),
381
+ )
382
+
383
+ /** Credentials typed among the headers for all routes: every route gets them. */
384
+ const commonSecrets = computed(() =>
385
+ commonHeaders
386
+ .filter((entry) => entry.value && isSecretHeader(entry.name))
387
+ .map((entry) => entry.name),
388
+ )
389
+
390
+ /** The key / value lists the open tab edits. */
391
+ const editors = computed(() => {
392
+ if (tab.value === 'headers')
393
+ return [
394
+ { key: 'headers', list: headers, add: t('api.tester.add_header') },
395
+ {
396
+ key: 'common',
397
+ list: commonHeaders,
398
+ add: t('api.tester.add_header'),
399
+ title: t('api.tester.common_headers'),
400
+ hint: t('api.tester.common_headers_hint'),
401
+ warning: commonSecrets.value.length
402
+ ? t('api.tester.common_secret', {
403
+ names: commonSecrets.value.join(', '),
404
+ })
405
+ : undefined,
406
+ },
407
+ ]
408
+ if (tab.value === 'query')
409
+ return [{ key: 'query', list: query, add: t('api.tester.add_query') }]
410
+ return [{ key: 'form', list: form, add: t('api.tester.add_field') }]
411
+ })
412
+
413
+ /** False for a route the module leaves out of its logs (the console's own). */
414
+ const routeCaptured = computed(() => route.value?.captured !== false)
415
+ const capturedAvailable = computed(
416
+ () =>
417
+ routeCaptured.value &&
418
+ !!result.value?.requestId &&
419
+ !neverSent(result.value.error),
420
+ )
421
+ const responseTabs = computed(() => [
422
+ ...(result.value?.error
423
+ ? []
424
+ : [
425
+ { label: t('api.tester.response'), value: 'body' },
426
+ {
427
+ label: t('api.tester.tabs.headers'),
428
+ value: 'headers',
429
+ badge: Object.keys(result.value?.headers ?? {}).length || undefined,
430
+ },
431
+ ]),
432
+ ...(capturedAvailable.value
433
+ ? [{ label: t('api.tester.tabs.captured'), value: 'captured' }]
434
+ : []),
435
+ ])
436
+
437
+ // --- What the line under the body says ---
438
+
439
+ const bodyHint = computed<{ text: string; tone: 'dimmed' | 'warning' }>(
440
+ () => {
441
+ const contract = route.value?.contract
442
+ if (bodyMode.value === 'none')
443
+ return { text: t('api.tester.body_hint.none'), tone: 'dimmed' }
444
+ if (origin.value === 'replay' && replayInfo.value) {
445
+ const info = replayInfo.value
446
+ if (info.bodyMissing)
447
+ return {
448
+ text: info.bodyOmitted
449
+ ? t('api.tester.body_hint.replay_missing', {
450
+ reason: t(`api.tester.body_omitted.${info.bodyOmitted}`),
451
+ })
452
+ : t('api.tester.body_hint.replay_missing_unknown'),
453
+ tone: 'warning',
454
+ }
455
+ if (info.bodyTruncated)
456
+ return {
457
+ text:
458
+ problem.value?.code === 'body_too_large'
459
+ ? t('api.tester.body_hint.replay_truncated_too_large', {
460
+ limit: formatBytes(PROXY_BODY_LIMIT, locale.value),
461
+ })
462
+ : t('api.tester.body_hint.replay_truncated'),
463
+ tone: 'warning',
464
+ }
465
+ return {
466
+ text: t('api.tester.body_hint.replay', { id: shortId(info.id) }),
467
+ tone: 'dimmed',
468
+ }
469
+ }
470
+ if (sentBody.value === undefined)
471
+ return { text: t('api.tester.body_hint.empty'), tone: 'dimmed' }
472
+ if (bodyMode.value === 'form')
473
+ return { text: t('api.tester.body_hint.form'), tone: 'dimmed' }
474
+ if (origin.value === 'history')
475
+ return { text: t('api.tester.body_hint.history'), tone: 'dimmed' }
476
+ if (origin.value === 'edited' || !contract)
477
+ return { text: '', tone: 'dimmed' }
478
+ if (contract.exampleBody !== null && contract.exampleBody !== undefined)
479
+ return { text: t('api.tester.body_hint.example'), tone: 'dimmed' }
480
+ const span = { days: contract.windowDays, count: contract.total }
481
+ if (contract.total === 0)
482
+ return {
483
+ text: t('api.tester.body_hint.no_capture', span),
484
+ tone: 'dimmed',
485
+ }
486
+ return {
487
+ text: contract.sampled
488
+ ? t(
489
+ 'api.tester.body_hint.no_json',
490
+ { ...span, count: contract.sampled },
491
+ contract.sampled,
492
+ )
493
+ : t('api.tester.body_hint.no_success', span, contract.total),
494
+ tone: 'dimmed',
495
+ }
496
+ },
497
+ )
498
+
499
+ const queryHint = computed(() => {
500
+ const contract = route.value?.contract
501
+ if (!contract) return ''
502
+ if (contract.queryParams.length)
503
+ return t('api.tester.query_known', {
504
+ names: contract.queryParams.join(', '),
505
+ })
506
+ const span = { days: contract.windowDays }
507
+ return contract.total
508
+ ? t('api.tester.query_none', span)
509
+ : t('api.tester.query_no_capture', span)
510
+ })
511
+
512
+ function shortId(id: string): string {
513
+ return id.slice(0, 8)
514
+ }
515
+
516
+ return {
517
+ ON_DEMAND,
518
+ LOGS_API,
519
+ LOGS_PAGE,
520
+ ROUTE_CHANGED,
521
+ CAPTURE_DELAYS_MS,
522
+ CAPTURE_MATCH_MS,
523
+ SIZE_PROBE_ID,
524
+ DRAFT_SAVE_DELAY_MS,
525
+ BODY_MODES,
526
+ AUTH_ICONS,
527
+ ERROR_ICONS,
528
+ POINTS_TO_CAPTURED,
529
+ dateFormat,
530
+ toast,
531
+ currentRoute,
532
+ router,
533
+ apiOrigin,
534
+ blockerId,
535
+ sourceTokens,
536
+ bodyHintId,
537
+ row,
538
+ rows,
539
+ bodyMode,
540
+ body,
541
+ form,
542
+ headers,
543
+ query,
544
+ pathValues,
545
+ useSession,
546
+ origin,
547
+ replayInfo,
548
+ result,
549
+ commonHeaders,
550
+ history,
551
+ tab,
552
+ responseTab,
553
+ sending,
554
+ capturedState,
555
+ capturedLog,
556
+ filledRef,
557
+ method,
558
+ bodyAllowed,
559
+ writes,
560
+ isDelete,
561
+ draftRequest,
562
+ example,
563
+ modified,
564
+ segments,
565
+ path,
566
+ displayQuery,
567
+ missingPathParams,
568
+ sentBody,
569
+ impliedHeaders,
570
+ effectiveHeaders,
571
+ shownImpliedHeaders,
572
+ auth,
573
+ authLabel,
574
+ request,
575
+ problem,
576
+ blocker,
577
+ jsonWarning,
578
+ formattedBody,
579
+ redactedCount,
580
+ redactedBodyFields,
581
+ tabs,
582
+ bodyModeItems,
583
+ commonSecrets,
584
+ editors,
585
+ routeCaptured,
586
+ capturedAvailable,
587
+ responseTabs,
588
+ bodyHint,
589
+ queryHint,
590
+ shortId,
591
+ t,
592
+ locale,
593
+ confirm,
594
+ loggedIn,
595
+ $authFetch,
596
+ route,
597
+ pending,
598
+ selection,
599
+ session,
600
+ }
601
+ }
@@ -0,0 +1,73 @@
1
+ export type Verdict = 'down' | 'degraded' | 'recovered' | 'operational' | 'idle'
2
+
3
+ /** Rates in percent (0–100); the figures cover the last `windowMinutes`. */
4
+ interface HealthMetrics {
5
+ serverErrorRate: number
6
+ clientErrorRate: number
7
+ /** Null when no call was measured in the window. */
8
+ p95Ms: number | null
9
+ requestsPerMinute: number
10
+ }
11
+
12
+ /** Rates in percent, like the metrics. */
13
+ interface HealthThresholds {
14
+ /** Degraded from this 5xx rate over `windowMinutes`. */
15
+ degradedServerErrorRate: number
16
+ /** Down from this 5xx rate over `downWindowMinutes`. */
17
+ downServerErrorRate: number
18
+ windowMinutes: number
19
+ downWindowMinutes: number
20
+ /** How far back the verdict looks for an incident. */
21
+ lookbackMinutes: number
22
+ /** The slow threshold of the settings: a p95 from it is slow. */
23
+ slowThresholdMs: number
24
+ }
25
+
26
+ /** What one rule reads now, over its own window. */
27
+ interface RuleWindow {
28
+ minutes: number
29
+ requests: number
30
+ serverErrors: number
31
+ serverErrorRate: number
32
+ }
33
+
34
+ export interface HealthPayload {
35
+ verdict: Verdict
36
+ /** Start of the current incident, or of the last one. */
37
+ incidentStart: string | null
38
+ /** How long the verdict has held; null when longer than the lookback. */
39
+ durationMs: number | null
40
+ checkedAt: string
41
+ metrics: HealthMetrics
42
+ /** The degraded and down rules' windows; null without any call. */
43
+ ruleWindows: { degraded: RuleWindow; down: RuleWindow } | null
44
+ thresholds: HealthThresholds
45
+ failingRoutes: number
46
+ recoveredRoutes: number
47
+ slowRoutes: number
48
+ serverErrors: number
49
+ routes: { value: number; needingAttention: number }
50
+ serverErrorsLink: string
51
+ firstRun: boolean
52
+ }
53
+
54
+ export type MetricTone = 'default' | 'warning' | 'error' | 'muted'
55
+
56
+ export interface HeroMetric {
57
+ id: string
58
+ label: string
59
+ value: string
60
+ unit?: string
61
+ sub: string
62
+ tone: MetricTone
63
+ /** A figure of context: smaller, and grey whatever its value. */
64
+ secondary?: boolean
65
+ }
66
+
67
+ export interface VerdictLook {
68
+ icon: string
69
+ text: string
70
+ dot: string
71
+ tint: string
72
+ line: string
73
+ }