@antelopejs/dms-api 0.5.0 → 0.6.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.
- package/README.md +19 -7
- package/dist/automation/query-request-logs.js.map +1 -1
- package/dist/automation/route-unhealthy.js.map +1 -1
- package/dist/db/models/request_log.model.js.map +1 -1
- package/dist/db/models/request_log.search.js +3 -3
- package/dist/db/models/request_log.search.js.map +1 -1
- package/dist/db/tables/request_log.table.js.map +1 -1
- package/dist/guards.d.ts +22 -0
- package/dist/guards.js +57 -0
- package/dist/guards.js.map +1 -0
- package/dist/index.js.map +1 -1
- package/dist/pages/blocks.d.ts +2 -2
- package/dist/pages/blocks.js +2 -2
- package/dist/pages/blocks.js.map +1 -1
- package/dist/pages/index.js.map +1 -1
- package/dist/pages/logs.js.map +1 -1
- package/dist/pages/module.js +8 -2
- package/dist/pages/module.js.map +1 -1
- package/dist/pages/overview.js.map +1 -1
- package/dist/pages/request-table.js.map +1 -1
- package/dist/pages/routes.js.map +1 -1
- package/dist/pages/settings.js +1 -3
- package/dist/pages/settings.js.map +1 -1
- package/dist/routes/logs.js.map +1 -1
- package/dist/routes/routes.js.map +1 -1
- package/dist/routes/settings.d.ts +2 -1
- package/dist/routes/settings.js +1 -1
- package/dist/routes/settings.js.map +1 -1
- package/dist/services/activity.js.map +1 -1
- package/dist/services/attention.js +1 -1
- package/dist/services/attention.js.map +1 -1
- package/dist/services/health-rules.js.map +1 -1
- package/dist/services/introspection/auth.js +1 -2
- package/dist/services/introspection/auth.js.map +1 -1
- package/dist/services/introspection/decorators.d.ts +3 -1
- package/dist/services/introspection/decorators.js +28 -17
- package/dist/services/introspection/decorators.js.map +1 -1
- package/dist/services/introspection/errors.d.ts +1 -1
- package/dist/services/introspection/errors.js +0 -2
- package/dist/services/introspection/errors.js.map +1 -1
- package/dist/services/introspection/index.d.ts +1 -1
- package/dist/services/introspection/index.js +24 -18
- package/dist/services/introspection/index.js.map +1 -1
- package/dist/services/introspection/probe.js.map +1 -1
- package/dist/services/links.js +4 -4
- package/dist/services/links.js.map +1 -1
- package/dist/services/live.d.ts +3 -2
- package/dist/services/live.js.map +1 -1
- package/dist/services/overview-lists.d.ts +4 -4
- package/dist/services/overview-lists.js.map +1 -1
- package/dist/services/overview.d.ts +4 -4
- package/dist/services/overview.js.map +1 -1
- package/dist/services/request-log/capture.d.ts +5 -14
- package/dist/services/request-log/capture.js +28 -76
- package/dist/services/request-log/capture.js.map +1 -1
- package/dist/services/request-log/console-traffic.d.ts +12 -0
- package/dist/services/request-log/console-traffic.js +69 -0
- package/dist/services/request-log/console-traffic.js.map +1 -0
- package/dist/services/request-log/list.d.ts +1 -1
- package/dist/services/request-log/list.js.map +1 -1
- package/dist/services/request-log/read.js.map +1 -1
- package/dist/services/request-log/redaction.js +7 -6
- package/dist/services/request-log/redaction.js.map +1 -1
- package/dist/services/request-log/util.d.ts +6 -3
- package/dist/services/request-log/util.js +17 -30
- package/dist/services/request-log/util.js.map +1 -1
- package/dist/services/route-catalog.js +2 -2
- package/dist/services/route-catalog.js.map +1 -1
- package/dist/services/route-contract.d.ts +6 -1
- package/dist/services/route-contract.js +11 -12
- package/dist/services/route-contract.js.map +1 -1
- package/dist/services/route-health.d.ts +5 -1
- package/dist/services/route-health.js +4 -1
- package/dist/services/route-health.js.map +1 -1
- package/dist/services/route-statistics.d.ts +3 -4
- package/dist/services/route-statistics.js.map +1 -1
- package/dist/services/routes-sync.d.ts +2 -2
- package/dist/services/routes-sync.js +1 -2
- package/dist/services/routes-sync.js.map +1 -1
- package/dist/services/scope.js +1 -1
- package/dist/services/scope.js.map +1 -1
- package/dist/services/settings-form.d.ts +4 -3
- package/dist/services/settings-form.js +1 -1
- package/dist/services/settings-form.js.map +1 -1
- package/dist/services/settings.js.map +1 -1
- package/dist/services/statistics-write.js +4 -7
- package/dist/services/statistics-write.js.map +1 -1
- package/dist/services/traffic-samples.js.map +1 -1
- package/dist/services/traffic.js +2 -1
- package/dist/services/traffic.js.map +1 -1
- package/dist/services/window.js +1 -1
- package/dist/services/window.js.map +1 -1
- package/dist/types/constants.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/json.d.ts +2 -0
- package/dist/types/json.js +3 -0
- package/dist/types/json.js.map +1 -0
- package/frontend-vue/app/components/blocks/HealthHero.vue +8 -117
- package/frontend-vue/app/components/blocks/RequestDetail.vue +18 -153
- package/frontend-vue/app/components/blocks/RouteDocumentation.vue +2 -151
- package/frontend-vue/app/components/blocks/RouteHeader.vue +7 -8
- package/frontend-vue/app/components/blocks/RouteTester.vue +58 -1682
- package/frontend-vue/app/components/blocks/RouteTree.vue +16 -81
- package/frontend-vue/app/components/internal/HealthHeroMetrics.vue +50 -0
- package/frontend-vue/app/components/internal/RequestGeneral.vue +32 -0
- package/frontend-vue/app/components/internal/RequestTiming.vue +85 -0
- package/frontend-vue/app/components/internal/RouteInternals.vue +159 -0
- package/frontend-vue/app/components/internal/RouteTesterRequest.vue +225 -0
- package/frontend-vue/app/components/internal/RouteTesterResponse.vue +272 -0
- package/frontend-vue/app/components/internal/RouteTreeFooter.vue +62 -0
- package/frontend-vue/app/components/internal/routeTester/context.ts +8 -0
- package/frontend-vue/app/components/internal/routeTester/useTesterExtras.ts +284 -0
- package/frontend-vue/app/components/internal/routeTester/useTesterFlow.ts +637 -0
- package/frontend-vue/app/components/internal/routeTester/useTesterState.ts +601 -0
- package/frontend-vue/app/utils/health.ts +73 -0
- package/frontend-vue/app/utils/requestDrawer.ts +49 -0
- package/frontend-vue/app/utils/routeExplorer.ts +34 -0
- package/frontend-vue/app/utils/testerMasks.ts +34 -0
- package/frontend-vue/app/utils/testerRequest.ts +14 -38
- package/frontend-vue/build/backend-boundary.ts +122 -0
- package/frontend-vue/dms.frontend.build.ts +2 -0
- package/frontend-vue/eslint.config.mjs +13 -0
- package/frontend-vue/package.json +6 -3
- package/frontend-vue/pnpm-lock.yaml +348 -153
- package/frontend-vue/tests/apiErrorPresentation.test.ts +115 -0
- package/frontend-vue/tests/backend-boundary.test.ts +180 -0
- package/frontend-vue/tests/dmsServer.test.ts +11 -23
- package/frontend-vue/tests/registration.test.ts +22 -6
- package/frontend-vue/tests/stubs/server.ts +19 -0
- package/frontend-vue/tests/testerRequest.test.ts +14 -0
- package/frontend-vue/vitest.config.ts +16 -0
- package/package.json +20 -8
- package/skills/dms-api/SKILL.md +1 -1
- package/skills/dms-api/cases.json +47 -0
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
byteLength,
|
|
4
|
+
formatBytes,
|
|
5
|
+
formatClock,
|
|
6
|
+
formatMs,
|
|
7
|
+
prettyBody,
|
|
8
|
+
} from '../../utils/format'
|
|
9
|
+
import { neverSent, PROXY_TIMEOUT_MS } from '../../utils/testerRequest'
|
|
10
|
+
import ApiKeyValues from './ApiKeyValues.vue'
|
|
11
|
+
import ApiStatusBadge from './ApiStatusBadge.vue'
|
|
12
|
+
import type { TesterContext } from './routeTester/context'
|
|
13
|
+
|
|
14
|
+
// The tester's answer card: the response, its headers and what the module captured of it.
|
|
15
|
+
const props = defineProps<{ tester: TesterContext }>()
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
capturedAvailable,
|
|
19
|
+
capturedLog,
|
|
20
|
+
capturedSlow,
|
|
21
|
+
capturedState,
|
|
22
|
+
dateFormat,
|
|
23
|
+
errorCopy,
|
|
24
|
+
locale,
|
|
25
|
+
logsLink,
|
|
26
|
+
responseBody,
|
|
27
|
+
responseSize,
|
|
28
|
+
responseTab,
|
|
29
|
+
responseTabs,
|
|
30
|
+
result,
|
|
31
|
+
routeCaptured,
|
|
32
|
+
sending,
|
|
33
|
+
shortId,
|
|
34
|
+
shortcut,
|
|
35
|
+
t,
|
|
36
|
+
useSession,
|
|
37
|
+
} = props.tester
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<template>
|
|
41
|
+
<DmsCard :padded="false" class="min-w-0">
|
|
42
|
+
<div v-if="!result" class="px-4 py-10">
|
|
43
|
+
<DmsEmptyState
|
|
44
|
+
size="sm"
|
|
45
|
+
:icon="sending ? 'i-ph-hourglass-medium' : 'i-ph-paper-plane-tilt'"
|
|
46
|
+
:title="
|
|
47
|
+
sending
|
|
48
|
+
? t('api.tester.waiting_title')
|
|
49
|
+
: t('api.tester.no_response_title')
|
|
50
|
+
"
|
|
51
|
+
:description="
|
|
52
|
+
sending
|
|
53
|
+
? t('api.tester.waiting_description', {
|
|
54
|
+
seconds: PROXY_TIMEOUT_MS / 1000,
|
|
55
|
+
})
|
|
56
|
+
: t('api.tester.no_response_description', { shortcut })
|
|
57
|
+
"
|
|
58
|
+
/>
|
|
59
|
+
</div>
|
|
60
|
+
<template v-else>
|
|
61
|
+
<div
|
|
62
|
+
class="border-default flex flex-wrap items-center gap-x-3 gap-y-1 border-b px-4 py-2.5"
|
|
63
|
+
>
|
|
64
|
+
<ApiStatusBadge v-if="result.status" :status="result.status" text />
|
|
65
|
+
<DmsStatusPill
|
|
66
|
+
v-else
|
|
67
|
+
:tone="result.error === 'aborted' ? 'neutral' : 'error'"
|
|
68
|
+
dot="none"
|
|
69
|
+
:label="
|
|
70
|
+
result.error === 'aborted'
|
|
71
|
+
? t('api.tester.cancelled')
|
|
72
|
+
: t('api.tester.failed')
|
|
73
|
+
"
|
|
74
|
+
/>
|
|
75
|
+
<UTooltip :text="t('api.tester.duration_tooltip')">
|
|
76
|
+
<span class="text-muted font-mono text-[12px]" tabindex="0">
|
|
77
|
+
{{
|
|
78
|
+
t('api.tester.duration_browser', {
|
|
79
|
+
duration: formatMs(result.durationMs, locale),
|
|
80
|
+
})
|
|
81
|
+
}}
|
|
82
|
+
<template
|
|
83
|
+
v-if="result.captured && result.captured.responseTimeMs !== null"
|
|
84
|
+
>
|
|
85
|
+
·
|
|
86
|
+
<span :class="capturedSlow ? 'text-warning font-semibold' : ''">
|
|
87
|
+
{{
|
|
88
|
+
t('api.tester.duration_server', {
|
|
89
|
+
duration: formatMs(result.captured.responseTimeMs, locale),
|
|
90
|
+
})
|
|
91
|
+
}}
|
|
92
|
+
</span>
|
|
93
|
+
</template>
|
|
94
|
+
</span>
|
|
95
|
+
</UTooltip>
|
|
96
|
+
<span
|
|
97
|
+
v-if="result.body || result.bodySize"
|
|
98
|
+
class="text-muted font-mono text-[12px]"
|
|
99
|
+
>
|
|
100
|
+
{{ formatBytes(responseSize, locale) }}
|
|
101
|
+
</span>
|
|
102
|
+
<span class="grow" />
|
|
103
|
+
<UButton
|
|
104
|
+
v-if="!neverSent(result.error) && logsLink"
|
|
105
|
+
:to="logsLink"
|
|
106
|
+
size="xs"
|
|
107
|
+
variant="link"
|
|
108
|
+
trailing-icon="i-ph-arrow-right"
|
|
109
|
+
:label="
|
|
110
|
+
result.captured
|
|
111
|
+
? t('api.tester.open_captured')
|
|
112
|
+
: t('api.tester.open_logs')
|
|
113
|
+
"
|
|
114
|
+
/>
|
|
115
|
+
<UTooltip
|
|
116
|
+
v-else-if="!routeCaptured"
|
|
117
|
+
:text="t('api.tester.not_captured_hint')"
|
|
118
|
+
>
|
|
119
|
+
<span class="text-dimmed text-xs" tabindex="0">
|
|
120
|
+
{{ t('api.tester.not_captured') }}
|
|
121
|
+
</span>
|
|
122
|
+
</UTooltip>
|
|
123
|
+
</div>
|
|
124
|
+
<div class="flex flex-col gap-2 p-3">
|
|
125
|
+
<DmsBanner
|
|
126
|
+
v-if="errorCopy"
|
|
127
|
+
:tone="result.error === 'aborted' ? 'info' : 'error'"
|
|
128
|
+
size="sm"
|
|
129
|
+
:icon="errorCopy.icon"
|
|
130
|
+
:title="errorCopy.title"
|
|
131
|
+
:description="errorCopy.description"
|
|
132
|
+
/>
|
|
133
|
+
<DmsBanner
|
|
134
|
+
v-else-if="result.status === 401"
|
|
135
|
+
tone="warning"
|
|
136
|
+
size="sm"
|
|
137
|
+
icon="i-ph-lock-simple"
|
|
138
|
+
:title="t('api.tester.unauthorized_title')"
|
|
139
|
+
:description="t(`api.tester.unauthorized.${result.auth}`)"
|
|
140
|
+
>
|
|
141
|
+
<template v-if="result.auth === 'none'" #actions>
|
|
142
|
+
<UButton
|
|
143
|
+
size="xs"
|
|
144
|
+
color="neutral"
|
|
145
|
+
variant="outline"
|
|
146
|
+
:label="t('api.tester.turn_on_session')"
|
|
147
|
+
@click="useSession = true"
|
|
148
|
+
/>
|
|
149
|
+
</template>
|
|
150
|
+
</DmsBanner>
|
|
151
|
+
<UTabs
|
|
152
|
+
v-if="responseTabs.length"
|
|
153
|
+
v-model="responseTab"
|
|
154
|
+
:items="responseTabs"
|
|
155
|
+
:content="false"
|
|
156
|
+
variant="link"
|
|
157
|
+
size="sm"
|
|
158
|
+
/>
|
|
159
|
+
<template v-if="responseTab === 'captured' && capturedAvailable">
|
|
160
|
+
<p
|
|
161
|
+
v-if="capturedState === 'loading' || capturedState === 'idle'"
|
|
162
|
+
class="text-dimmed text-sm"
|
|
163
|
+
>
|
|
164
|
+
{{ t('api.tester.captured.loading') }}
|
|
165
|
+
</p>
|
|
166
|
+
<p
|
|
167
|
+
v-else-if="capturedState === 'missing'"
|
|
168
|
+
class="text-dimmed text-sm"
|
|
169
|
+
>
|
|
170
|
+
{{
|
|
171
|
+
t('api.tester.captured.missing', {
|
|
172
|
+
id: shortId(result.requestId ?? ''),
|
|
173
|
+
})
|
|
174
|
+
}}
|
|
175
|
+
</p>
|
|
176
|
+
<p v-else-if="capturedState === 'error'" class="text-error text-sm">
|
|
177
|
+
{{ t('api.tester.captured.error') }}
|
|
178
|
+
</p>
|
|
179
|
+
<div v-else-if="capturedLog" class="flex flex-col gap-3">
|
|
180
|
+
<div
|
|
181
|
+
class="text-muted flex flex-wrap items-center gap-3 font-mono text-[12px]"
|
|
182
|
+
>
|
|
183
|
+
<ApiStatusBadge :status="capturedLog.statusCode" text size="sm" />
|
|
184
|
+
<span
|
|
185
|
+
v-if="capturedLog.responseTimeMs !== null"
|
|
186
|
+
:class="capturedSlow ? 'text-warning font-semibold' : ''"
|
|
187
|
+
>
|
|
188
|
+
{{
|
|
189
|
+
t('api.tester.duration_server', {
|
|
190
|
+
duration: formatMs(capturedLog.responseTimeMs, locale),
|
|
191
|
+
})
|
|
192
|
+
}}
|
|
193
|
+
</span>
|
|
194
|
+
<span>
|
|
195
|
+
{{ formatClock(capturedLog.timestamp, dateFormat) }}
|
|
196
|
+
</span>
|
|
197
|
+
<span>{{ shortId(capturedLog._id) }}</span>
|
|
198
|
+
</div>
|
|
199
|
+
<DmsBanner
|
|
200
|
+
v-if="capturedLog.error"
|
|
201
|
+
tone="error"
|
|
202
|
+
size="sm"
|
|
203
|
+
icon="i-ph-bug"
|
|
204
|
+
:title="capturedLog.error.message"
|
|
205
|
+
/>
|
|
206
|
+
<DmsCodeSnippet
|
|
207
|
+
v-if="capturedLog.error?.stack"
|
|
208
|
+
:code="capturedLog.error.stack"
|
|
209
|
+
:title="t('api.tester.captured.stack')"
|
|
210
|
+
max-height="12rem"
|
|
211
|
+
wrap="anywhere"
|
|
212
|
+
/>
|
|
213
|
+
<div class="flex flex-col gap-1.5">
|
|
214
|
+
<p class="text-default text-xs font-medium">
|
|
215
|
+
{{ t('api.tester.captured.headers') }}
|
|
216
|
+
</p>
|
|
217
|
+
<ApiKeyValues
|
|
218
|
+
:values="capturedLog.requestHeaders"
|
|
219
|
+
:empty="t('api.request.no_headers')"
|
|
220
|
+
/>
|
|
221
|
+
</div>
|
|
222
|
+
<DmsCodeSnippet
|
|
223
|
+
v-if="capturedLog.requestBody"
|
|
224
|
+
:code="prettyBody(capturedLog.requestBody).text"
|
|
225
|
+
:title="t('api.tester.captured.body')"
|
|
226
|
+
max-height="16rem"
|
|
227
|
+
wrap="anywhere"
|
|
228
|
+
/>
|
|
229
|
+
<p
|
|
230
|
+
v-else-if="capturedLog.requestBodyOmitted"
|
|
231
|
+
class="text-dimmed text-xs"
|
|
232
|
+
>
|
|
233
|
+
{{
|
|
234
|
+
t('api.tester.captured.body_omitted', {
|
|
235
|
+
reason: t(
|
|
236
|
+
`api.tester.body_omitted.${capturedLog.requestBodyOmitted}`,
|
|
237
|
+
),
|
|
238
|
+
})
|
|
239
|
+
}}
|
|
240
|
+
</p>
|
|
241
|
+
</div>
|
|
242
|
+
</template>
|
|
243
|
+
<template v-else-if="!result.error">
|
|
244
|
+
<template v-if="responseTab === 'body'">
|
|
245
|
+
<DmsCodeSnippet
|
|
246
|
+
v-if="responseBody.text"
|
|
247
|
+
:code="responseBody.text"
|
|
248
|
+
max-height="24rem"
|
|
249
|
+
wrap="anywhere"
|
|
250
|
+
/>
|
|
251
|
+
<p v-else class="text-dimmed text-sm">
|
|
252
|
+
{{ t('api.request.no_body') }}
|
|
253
|
+
</p>
|
|
254
|
+
<p v-if="result.bodyTruncated" class="text-warning text-xs">
|
|
255
|
+
{{
|
|
256
|
+
t('api.tester.truncated_in_history', {
|
|
257
|
+
shown: formatBytes(byteLength(result.body), locale),
|
|
258
|
+
size: formatBytes(responseSize, locale),
|
|
259
|
+
})
|
|
260
|
+
}}
|
|
261
|
+
</p>
|
|
262
|
+
</template>
|
|
263
|
+
<ApiKeyValues
|
|
264
|
+
v-else
|
|
265
|
+
:values="result.headers"
|
|
266
|
+
:empty="t('api.request.no_headers')"
|
|
267
|
+
/>
|
|
268
|
+
</template>
|
|
269
|
+
</div>
|
|
270
|
+
</template>
|
|
271
|
+
</DmsCard>
|
|
272
|
+
</template>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { formatCount } from '../../utils/format'
|
|
3
|
+
import type { ExplorerRoute, RouteFolder } from '../../utils/routeExplorer'
|
|
4
|
+
|
|
5
|
+
// The route list's last line: what it shows of how many, and the folders'
|
|
6
|
+
// expand / collapse toggle.
|
|
7
|
+
defineProps<{
|
|
8
|
+
visible: ExplorerRoute[]
|
|
9
|
+
routes: ExplorerRoute[]
|
|
10
|
+
folders: RouteFolder[]
|
|
11
|
+
flatMode: boolean
|
|
12
|
+
allCollapsed: boolean
|
|
13
|
+
locale: string
|
|
14
|
+
toggleAll: () => void
|
|
15
|
+
}>()
|
|
16
|
+
|
|
17
|
+
const { t } = useI18n()
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<template>
|
|
21
|
+
<div
|
|
22
|
+
class="border-default text-dimmed flex items-center gap-2 border-t px-3 py-2 font-mono text-[11px]"
|
|
23
|
+
>
|
|
24
|
+
<!-- The count wraps rather than being cut: the toggle beside it is an
|
|
25
|
+
icon, its name in a tooltip, so the line usually holds it all. -->
|
|
26
|
+
<span class="min-w-0">
|
|
27
|
+
{{
|
|
28
|
+
t(flatMode ? 'api.routes.tree.footer_flat' : 'api.routes.tree.footer', {
|
|
29
|
+
shown: formatCount(visible.length, locale),
|
|
30
|
+
total: formatCount(routes.length, locale),
|
|
31
|
+
folders: folders.length,
|
|
32
|
+
})
|
|
33
|
+
}}
|
|
34
|
+
</span>
|
|
35
|
+
<span class="grow" />
|
|
36
|
+
<UTooltip
|
|
37
|
+
v-if="!flatMode && folders.length > 1"
|
|
38
|
+
:text="
|
|
39
|
+
allCollapsed
|
|
40
|
+
? t('api.routes.tree.expand_all')
|
|
41
|
+
: t('api.routes.tree.collapse_all')
|
|
42
|
+
"
|
|
43
|
+
>
|
|
44
|
+
<UButton
|
|
45
|
+
size="xs"
|
|
46
|
+
color="neutral"
|
|
47
|
+
variant="ghost"
|
|
48
|
+
square
|
|
49
|
+
class="shrink-0"
|
|
50
|
+
:icon="allCollapsed ? 'i-ph-caret-up-down' : 'i-ph-caret-line-up'"
|
|
51
|
+
:aria-label="
|
|
52
|
+
allCollapsed
|
|
53
|
+
? t('api.routes.tree.expand_all')
|
|
54
|
+
: t('api.routes.tree.collapse_all')
|
|
55
|
+
"
|
|
56
|
+
@click="toggleAll"
|
|
57
|
+
/>
|
|
58
|
+
</UTooltip>
|
|
59
|
+
<UKbd value="↑" size="sm" class="@max-5xl:hidden shrink-0" />
|
|
60
|
+
<UKbd value="↓" size="sm" class="@max-5xl:hidden shrink-0" />
|
|
61
|
+
</div>
|
|
62
|
+
</template>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { useTesterExtras } from './useTesterExtras'
|
|
2
|
+
import type { useTesterFlow } from './useTesterFlow'
|
|
3
|
+
import type { useTesterState } from './useTesterState'
|
|
4
|
+
|
|
5
|
+
/** Everything `RouteTester` sets up, as its private child components read it. */
|
|
6
|
+
export type TesterContext = ReturnType<typeof useTesterState> &
|
|
7
|
+
ReturnType<typeof useTesterFlow> &
|
|
8
|
+
ReturnType<typeof useTesterExtras>
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { computed, onBeforeUnmount } from 'vue'
|
|
2
|
+
import {
|
|
3
|
+
byteLength,
|
|
4
|
+
formatBytes,
|
|
5
|
+
formatMs,
|
|
6
|
+
prettyBody,
|
|
7
|
+
} from '../../../utils/format'
|
|
8
|
+
import { statusText } from '../../../utils/http'
|
|
9
|
+
import { toCurl } from '../../../utils/snippets'
|
|
10
|
+
import {
|
|
11
|
+
HISTORY_MAX,
|
|
12
|
+
type HistoryEntry,
|
|
13
|
+
loadHistory,
|
|
14
|
+
saveHistory,
|
|
15
|
+
} from '../../../utils/testerHistory'
|
|
16
|
+
import {
|
|
17
|
+
PROXY_RESPONSE_LIMIT,
|
|
18
|
+
PROXY_TIMEOUT_MS,
|
|
19
|
+
revealBidi,
|
|
20
|
+
} from '../../../utils/testerRequest'
|
|
21
|
+
import type { useTesterFlow } from './useTesterFlow'
|
|
22
|
+
import type { useTesterState } from './useTesterState'
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The rest of the tester, as `RouteTester` sets it up last: history, cURL,
|
|
26
|
+
* the keyboard, the live hold and the answer.
|
|
27
|
+
*/
|
|
28
|
+
export function useTesterExtras(
|
|
29
|
+
tester: ReturnType<typeof useTesterState> & ReturnType<typeof useTesterFlow>,
|
|
30
|
+
) {
|
|
31
|
+
const {
|
|
32
|
+
LOGS_PAGE,
|
|
33
|
+
ERROR_ICONS,
|
|
34
|
+
POINTS_TO_CAPTURED,
|
|
35
|
+
toast,
|
|
36
|
+
apiOrigin,
|
|
37
|
+
body,
|
|
38
|
+
query,
|
|
39
|
+
pathValues,
|
|
40
|
+
origin,
|
|
41
|
+
replayInfo,
|
|
42
|
+
result,
|
|
43
|
+
history,
|
|
44
|
+
sending,
|
|
45
|
+
method,
|
|
46
|
+
sentBody,
|
|
47
|
+
effectiveHeaders,
|
|
48
|
+
auth,
|
|
49
|
+
formattedBody,
|
|
50
|
+
routeCaptured,
|
|
51
|
+
t,
|
|
52
|
+
locale,
|
|
53
|
+
route,
|
|
54
|
+
session,
|
|
55
|
+
applyRequest,
|
|
56
|
+
warnLostSecrets,
|
|
57
|
+
flushDraft,
|
|
58
|
+
send,
|
|
59
|
+
showResult,
|
|
60
|
+
} = tester
|
|
61
|
+
// --- History ---
|
|
62
|
+
|
|
63
|
+
function restore(entry: HistoryEntry) {
|
|
64
|
+
applyRequest(entry.request)
|
|
65
|
+
origin.value = 'history'
|
|
66
|
+
replayInfo.value = null
|
|
67
|
+
showResult(entry.result)
|
|
68
|
+
warnLostSecrets([
|
|
69
|
+
...(entry.secretsRemoved ?? []),
|
|
70
|
+
...(entry.result.secrets ?? []),
|
|
71
|
+
])
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function clearHistory() {
|
|
75
|
+
const ref = session.activeRef
|
|
76
|
+
if (!ref) return
|
|
77
|
+
const cleared = history.value
|
|
78
|
+
history.value = []
|
|
79
|
+
saveHistory(ref, [])
|
|
80
|
+
toast.add({
|
|
81
|
+
title: t(
|
|
82
|
+
'api.tester.history_cleared',
|
|
83
|
+
{ count: cleared.length },
|
|
84
|
+
cleared.length,
|
|
85
|
+
),
|
|
86
|
+
color: 'neutral',
|
|
87
|
+
icon: 'i-ph-trash',
|
|
88
|
+
actions: [
|
|
89
|
+
{
|
|
90
|
+
label: t('api.tester.undo'),
|
|
91
|
+
color: 'neutral',
|
|
92
|
+
variant: 'outline',
|
|
93
|
+
onClick: () => {
|
|
94
|
+
const merged = [...loadHistory(ref), ...cleared].slice(
|
|
95
|
+
0,
|
|
96
|
+
HISTORY_MAX,
|
|
97
|
+
)
|
|
98
|
+
saveHistory(ref, merged)
|
|
99
|
+
if (session.activeRef === ref) history.value = merged
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// --- Copy cURL ---
|
|
107
|
+
|
|
108
|
+
function curl(): string {
|
|
109
|
+
const search: Record<string, string | string[]> = {}
|
|
110
|
+
for (const { name, value } of query) {
|
|
111
|
+
if (!name) continue
|
|
112
|
+
const known = search[name]
|
|
113
|
+
search[name] = known === undefined ? value : [...[known].flat(), value]
|
|
114
|
+
}
|
|
115
|
+
return toCurl({
|
|
116
|
+
method: method.value,
|
|
117
|
+
path: route.value?.path ?? '/',
|
|
118
|
+
origin: apiOrigin.value,
|
|
119
|
+
pathParams: { ...pathValues },
|
|
120
|
+
query: search,
|
|
121
|
+
headers: effectiveHeaders.value,
|
|
122
|
+
body: sentBody.value,
|
|
123
|
+
session: auth.value === 'session',
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function copyCurl() {
|
|
128
|
+
const copied = await navigator.clipboard.writeText(curl()).then(
|
|
129
|
+
() => true,
|
|
130
|
+
() => false,
|
|
131
|
+
)
|
|
132
|
+
if (copied) {
|
|
133
|
+
toast.add({
|
|
134
|
+
title: t('api.request.curl_copied'),
|
|
135
|
+
color: 'success',
|
|
136
|
+
icon: 'i-ph-check',
|
|
137
|
+
})
|
|
138
|
+
} else {
|
|
139
|
+
toast.add({ title: t('api.request.copy_failed'), color: 'warning' })
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** What the user typed in the body editor (not a body loaded into it). */
|
|
144
|
+
function editBody(value: string | null | undefined) {
|
|
145
|
+
const next = value ?? ''
|
|
146
|
+
if (next === body.value) return
|
|
147
|
+
body.value = next
|
|
148
|
+
origin.value = 'edited'
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function formatBody() {
|
|
152
|
+
if (formattedBody.value === null) return
|
|
153
|
+
body.value = formattedBody.value
|
|
154
|
+
origin.value = 'edited'
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// --- Keyboard ---
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Ctrl/Cmd+Enter sends from a field of the tester only, never from the rest
|
|
161
|
+
* of the page (the route filter, the command palette); `send` still asks
|
|
162
|
+
* before a write it has not confirmed.
|
|
163
|
+
*/
|
|
164
|
+
function onKey(event: KeyboardEvent) {
|
|
165
|
+
if (event.key !== 'Enter' || !(event.metaKey || event.ctrlKey)) return
|
|
166
|
+
if (event.isComposing) return
|
|
167
|
+
event.preventDefault()
|
|
168
|
+
void send()
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// --- Live hold ---
|
|
172
|
+
|
|
173
|
+
const FIELD_SELECTOR = 'input, textarea, select, [contenteditable="true"]'
|
|
174
|
+
const live = usePageLive()
|
|
175
|
+
|
|
176
|
+
function onFocusIn(event: FocusEvent) {
|
|
177
|
+
const target = event.target as HTMLElement | null
|
|
178
|
+
if (target?.closest(FIELD_SELECTOR))
|
|
179
|
+
live.hold('$api.live_mode.typing_in_tester')
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Held while the focus stays in the Tester (a field, Send), released once it
|
|
183
|
+
// leaves; the DMS releases it with the component too.
|
|
184
|
+
function onFocusOut(event: FocusEvent) {
|
|
185
|
+
const root = event.currentTarget as HTMLElement
|
|
186
|
+
const next = event.relatedTarget as Node | null
|
|
187
|
+
if (next && root.contains(next)) return
|
|
188
|
+
live.release()
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
onBeforeUnmount(() => {
|
|
192
|
+
flushDraft()
|
|
193
|
+
// A call in flight still lands in its route's history and draft.
|
|
194
|
+
session.unmounted = true
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
// --- Answer ---
|
|
198
|
+
|
|
199
|
+
const responseBody = computed(() => prettyBody(result.value?.body))
|
|
200
|
+
const responseSize = computed(() =>
|
|
201
|
+
result.value ? (result.value.bodySize ?? byteLength(result.value.body)) : 0,
|
|
202
|
+
)
|
|
203
|
+
function recordLink(id: string): string {
|
|
204
|
+
return `${LOGS_PAGE}?${new URLSearchParams({ record: id })}`
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** A path as it reads: decoded, its bidirectional controls shown. */
|
|
208
|
+
function readable(value: string): string {
|
|
209
|
+
try {
|
|
210
|
+
return revealBidi(decodeURI(value))
|
|
211
|
+
} catch {
|
|
212
|
+
return revealBidi(value)
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* The captured call, else the route's logs: only for a route the module
|
|
218
|
+
* captures and the active scope shows (the logs list is scoped).
|
|
219
|
+
*/
|
|
220
|
+
const logsLink = computed(() => {
|
|
221
|
+
const id = result.value?.captured?.id
|
|
222
|
+
if (id) return recordLink(id)
|
|
223
|
+
return route.value && routeCaptured.value && route.value.inScope !== false
|
|
224
|
+
? `${LOGS_PAGE}?${new URLSearchParams({ route: route.value.ref })}`
|
|
225
|
+
: ''
|
|
226
|
+
})
|
|
227
|
+
const errorCopy = computed(() => {
|
|
228
|
+
const value = result.value
|
|
229
|
+
if (!value?.error) return null
|
|
230
|
+
const code = value.abandoned ? 'abandoned' : value.error
|
|
231
|
+
const params = {
|
|
232
|
+
limit: formatBytes(PROXY_RESPONSE_LIMIT, locale.value),
|
|
233
|
+
seconds: PROXY_TIMEOUT_MS / 1000,
|
|
234
|
+
status: value.captured?.status ?? '',
|
|
235
|
+
message: value.message ?? '',
|
|
236
|
+
}
|
|
237
|
+
const description =
|
|
238
|
+
!routeCaptured.value && POINTS_TO_CAPTURED.has(code)
|
|
239
|
+
? 'description_uncaptured'
|
|
240
|
+
: 'description'
|
|
241
|
+
return {
|
|
242
|
+
title: t(`api.tester.errors.${code}.title`, params),
|
|
243
|
+
description: t(`api.tester.errors.${code}.${description}`, params),
|
|
244
|
+
icon: ERROR_ICONS[value.error] ?? 'i-ph-plugs',
|
|
245
|
+
}
|
|
246
|
+
})
|
|
247
|
+
const liveMessage = computed(() => {
|
|
248
|
+
const value = result.value
|
|
249
|
+
if (sending.value || !value) return ''
|
|
250
|
+
if (errorCopy.value)
|
|
251
|
+
return t('api.tester.live.failed', { title: errorCopy.value.title })
|
|
252
|
+
return t('api.tester.live.sent', {
|
|
253
|
+
status: value.status,
|
|
254
|
+
text: statusText(value.status),
|
|
255
|
+
duration: formatMs(value.durationMs, locale.value),
|
|
256
|
+
})
|
|
257
|
+
})
|
|
258
|
+
const shortcut = computed(() =>
|
|
259
|
+
typeof navigator !== 'undefined' && /Mac|iP/.test(navigator.platform)
|
|
260
|
+
? '⌘'
|
|
261
|
+
: 'Ctrl',
|
|
262
|
+
)
|
|
263
|
+
return {
|
|
264
|
+
restore,
|
|
265
|
+
clearHistory,
|
|
266
|
+
curl,
|
|
267
|
+
copyCurl,
|
|
268
|
+
editBody,
|
|
269
|
+
formatBody,
|
|
270
|
+
onKey,
|
|
271
|
+
FIELD_SELECTOR,
|
|
272
|
+
live,
|
|
273
|
+
onFocusIn,
|
|
274
|
+
onFocusOut,
|
|
275
|
+
responseBody,
|
|
276
|
+
responseSize,
|
|
277
|
+
recordLink,
|
|
278
|
+
readable,
|
|
279
|
+
logsLink,
|
|
280
|
+
errorCopy,
|
|
281
|
+
liveMessage,
|
|
282
|
+
shortcut,
|
|
283
|
+
}
|
|
284
|
+
}
|