@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,637 @@
|
|
|
1
|
+
import { computed, onMounted, shallowRef, watch } from 'vue'
|
|
2
|
+
import { byteLength, formatClock } from '../../../utils/format'
|
|
3
|
+
import { errorStatus } from '../../../utils/http'
|
|
4
|
+
import {
|
|
5
|
+
type DraftRequest,
|
|
6
|
+
hasConfirmedWrite,
|
|
7
|
+
HISTORY_MAX,
|
|
8
|
+
historyEntry,
|
|
9
|
+
loadDraft,
|
|
10
|
+
loadHistory,
|
|
11
|
+
lostSecrets,
|
|
12
|
+
patchResult,
|
|
13
|
+
rememberConfirmedWrite,
|
|
14
|
+
saveCommonHeaders,
|
|
15
|
+
saveDraft,
|
|
16
|
+
saveHistory,
|
|
17
|
+
secretNames,
|
|
18
|
+
type TesterDraft,
|
|
19
|
+
} from '../../../utils/testerHistory'
|
|
20
|
+
import {
|
|
21
|
+
type CapturedRequest,
|
|
22
|
+
capturedSummary,
|
|
23
|
+
type KeyValue,
|
|
24
|
+
markedHeaders,
|
|
25
|
+
newRequestId,
|
|
26
|
+
replayFrom,
|
|
27
|
+
sendTesterRequest,
|
|
28
|
+
TesterError,
|
|
29
|
+
type TesterRequest,
|
|
30
|
+
type TesterResult,
|
|
31
|
+
} from '../../../utils/testerRequest'
|
|
32
|
+
import type {
|
|
33
|
+
CapturedRow,
|
|
34
|
+
ReadJson,
|
|
35
|
+
Row,
|
|
36
|
+
useTesterState,
|
|
37
|
+
} from './useTesterState'
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The tester's flows, as `RouteTester` sets them up after its state: the
|
|
41
|
+
* draft, a replay, sending and what the module captured of a call.
|
|
42
|
+
*/
|
|
43
|
+
export function useTesterFlow(state: ReturnType<typeof useTesterState>) {
|
|
44
|
+
const { presentError } = useApiErrorPresenter()
|
|
45
|
+
const {
|
|
46
|
+
ON_DEMAND,
|
|
47
|
+
LOGS_API,
|
|
48
|
+
ROUTE_CHANGED,
|
|
49
|
+
CAPTURE_DELAYS_MS,
|
|
50
|
+
CAPTURE_MATCH_MS,
|
|
51
|
+
DRAFT_SAVE_DELAY_MS,
|
|
52
|
+
dateFormat,
|
|
53
|
+
toast,
|
|
54
|
+
currentRoute,
|
|
55
|
+
router,
|
|
56
|
+
sourceTokens,
|
|
57
|
+
row,
|
|
58
|
+
rows,
|
|
59
|
+
bodyMode,
|
|
60
|
+
body,
|
|
61
|
+
form,
|
|
62
|
+
headers,
|
|
63
|
+
query,
|
|
64
|
+
pathValues,
|
|
65
|
+
useSession,
|
|
66
|
+
origin,
|
|
67
|
+
replayInfo,
|
|
68
|
+
result,
|
|
69
|
+
commonHeaders,
|
|
70
|
+
history,
|
|
71
|
+
tab,
|
|
72
|
+
responseTab,
|
|
73
|
+
sending,
|
|
74
|
+
capturedState,
|
|
75
|
+
capturedLog,
|
|
76
|
+
filledRef,
|
|
77
|
+
method,
|
|
78
|
+
bodyAllowed,
|
|
79
|
+
writes,
|
|
80
|
+
isDelete,
|
|
81
|
+
draftRequest,
|
|
82
|
+
example,
|
|
83
|
+
modified,
|
|
84
|
+
path,
|
|
85
|
+
sentBody,
|
|
86
|
+
auth,
|
|
87
|
+
request,
|
|
88
|
+
blocker,
|
|
89
|
+
redactedCount,
|
|
90
|
+
capturedAvailable,
|
|
91
|
+
shortId,
|
|
92
|
+
t,
|
|
93
|
+
confirm,
|
|
94
|
+
route,
|
|
95
|
+
session,
|
|
96
|
+
} = state
|
|
97
|
+
// --- Draft ---
|
|
98
|
+
|
|
99
|
+
function fill(list: Row[], values: KeyValue[]) {
|
|
100
|
+
list.splice(
|
|
101
|
+
0,
|
|
102
|
+
list.length,
|
|
103
|
+
...values.map((entry) => row(entry.name, entry.value)),
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function applyRequest(next: DraftRequest) {
|
|
108
|
+
bodyMode.value = bodyAllowed.value ? next.bodyMode : 'none'
|
|
109
|
+
body.value = next.body
|
|
110
|
+
fill(form, next.form)
|
|
111
|
+
fill(headers, next.headers)
|
|
112
|
+
fill(query, next.query)
|
|
113
|
+
for (const key of Object.keys(pathValues)) delete pathValues[key]
|
|
114
|
+
for (const name of route.value?.pathParams ?? [])
|
|
115
|
+
pathValues[name] = next.pathValues[name] ?? ''
|
|
116
|
+
useSession.value = next.useSession
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function openFirstTab() {
|
|
120
|
+
tab.value = bodyMode.value !== 'none' ? 'body' : 'headers'
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Says which credentials a restored answer was sent with that the fields no
|
|
125
|
+
* longer hold: never stored, or forgotten on reload.
|
|
126
|
+
*/
|
|
127
|
+
function warnLostSecrets(sent: string[]) {
|
|
128
|
+
const lost = lostSecrets(sent, [...headers, ...commonHeaders])
|
|
129
|
+
if (lost.length)
|
|
130
|
+
toast.add({
|
|
131
|
+
title: t('api.tester.secrets_not_kept', { names: lost.join(', ') }),
|
|
132
|
+
color: 'warning',
|
|
133
|
+
icon: 'i-ph-key',
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function resetToExample(clearResult = false) {
|
|
138
|
+
if (!example.value) return
|
|
139
|
+
applyRequest(example.value)
|
|
140
|
+
origin.value = 'example'
|
|
141
|
+
replayInfo.value = null
|
|
142
|
+
if (clearResult) showResult(null)
|
|
143
|
+
openFirstTab()
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function currentDraft(): TesterDraft | null {
|
|
147
|
+
if (!modified.value && !result.value && !replayInfo.value) return null
|
|
148
|
+
return {
|
|
149
|
+
request: draftRequest.value,
|
|
150
|
+
origin: origin.value,
|
|
151
|
+
replay: replayInfo.value,
|
|
152
|
+
result: result.value,
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
let saveTimer: ReturnType<typeof setTimeout> | undefined
|
|
157
|
+
let saveRef: string | null = null
|
|
158
|
+
|
|
159
|
+
function flushDraft() {
|
|
160
|
+
if (saveTimer === undefined || !saveRef) return
|
|
161
|
+
clearTimeout(saveTimer)
|
|
162
|
+
saveTimer = undefined
|
|
163
|
+
saveDraft(saveRef, currentDraft())
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
watch([draftRequest, origin, replayInfo, result], () => {
|
|
167
|
+
if (!session.activeRef) return
|
|
168
|
+
if (saveTimer !== undefined) clearTimeout(saveTimer)
|
|
169
|
+
saveRef = session.activeRef
|
|
170
|
+
saveTimer = setTimeout(() => {
|
|
171
|
+
saveTimer = undefined
|
|
172
|
+
if (session.activeRef && saveRef === session.activeRef)
|
|
173
|
+
saveDraft(session.activeRef, currentDraft())
|
|
174
|
+
}, DRAFT_SAVE_DELAY_MS)
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
watch(commonHeaders, () => saveCommonHeaders(rows(commonHeaders)), {
|
|
178
|
+
deep: true,
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
function loadRoute(next: string) {
|
|
182
|
+
flushDraft()
|
|
183
|
+
if (session.inFlight && session.inFlight.ref !== next) {
|
|
184
|
+
session.inFlight.controller.abort(ROUTE_CHANGED)
|
|
185
|
+
session.inFlight = null
|
|
186
|
+
sending.value = false
|
|
187
|
+
}
|
|
188
|
+
session.activeRef = next
|
|
189
|
+
filledRef.value = next
|
|
190
|
+
history.value = loadHistory(next)
|
|
191
|
+
const draft = loadDraft(next)
|
|
192
|
+
if (draft) {
|
|
193
|
+
applyRequest(draft.request)
|
|
194
|
+
origin.value = draft.origin
|
|
195
|
+
replayInfo.value = draft.replay
|
|
196
|
+
showResult(draft.result)
|
|
197
|
+
openFirstTab()
|
|
198
|
+
warnLostSecrets(draft.result?.secrets ?? [])
|
|
199
|
+
} else resetToExample(true)
|
|
200
|
+
const replayId = currentRoute.query.replay
|
|
201
|
+
if (typeof replayId === 'string' && replayId) void replay(replayId, next)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
onMounted(() =>
|
|
205
|
+
watch(
|
|
206
|
+
() => route.value?.ref,
|
|
207
|
+
(next) => {
|
|
208
|
+
if (next) loadRoute(next)
|
|
209
|
+
},
|
|
210
|
+
{ immediate: true },
|
|
211
|
+
),
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
// --- Replay ---
|
|
215
|
+
|
|
216
|
+
/** Takes `?replay=` off the URL: a replay is loaded once, on its own route. */
|
|
217
|
+
function dropReplayParam() {
|
|
218
|
+
const { replay: _replay, ...rest } = currentRoute.query
|
|
219
|
+
return router.replace({ query: rest })
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const replayedId = shallowRef<string | null>(null)
|
|
223
|
+
const replayRead = useApiData<CapturedRequest>(
|
|
224
|
+
() =>
|
|
225
|
+
replayedId.value
|
|
226
|
+
? `${LOGS_API}/${encodeURIComponent(replayedId.value)}`
|
|
227
|
+
: null,
|
|
228
|
+
ON_DEMAND,
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
async function replay(id: string, ref: string) {
|
|
232
|
+
void dropReplayParam()
|
|
233
|
+
try {
|
|
234
|
+
replayedId.value = id
|
|
235
|
+
await replayRead.execute()
|
|
236
|
+
if (replayRead.error.value) throw replayRead.error.value
|
|
237
|
+
const log = replayRead.data.value
|
|
238
|
+
if (session.activeRef !== ref || !log) return
|
|
239
|
+
const capturedRef = log.route
|
|
240
|
+
if (capturedRef !== ref) {
|
|
241
|
+
toast.add({
|
|
242
|
+
title: t('api.tester.replay_other_route', { route: capturedRef }),
|
|
243
|
+
color: 'warning',
|
|
244
|
+
icon: 'i-ph-warning',
|
|
245
|
+
})
|
|
246
|
+
return
|
|
247
|
+
}
|
|
248
|
+
const replayed = replayFrom(log)
|
|
249
|
+
applyRequest({
|
|
250
|
+
bodyMode: replayed.bodyMode,
|
|
251
|
+
body: replayed.body,
|
|
252
|
+
form: [],
|
|
253
|
+
headers: replayed.headers,
|
|
254
|
+
query: replayed.query,
|
|
255
|
+
pathValues: replayed.pathValues,
|
|
256
|
+
useSession: example.value?.useSession ?? true,
|
|
257
|
+
})
|
|
258
|
+
origin.value = 'replay'
|
|
259
|
+
replayInfo.value = {
|
|
260
|
+
id: log._id,
|
|
261
|
+
at: log.timestamp,
|
|
262
|
+
skippedHeaders: replayed.skippedHeaders,
|
|
263
|
+
bodyMissing: replayed.bodyMissing,
|
|
264
|
+
bodyOmitted: replayed.bodyOmitted,
|
|
265
|
+
bodyTruncated: replayed.bodyTruncated,
|
|
266
|
+
}
|
|
267
|
+
showResult(null)
|
|
268
|
+
openFirstTab()
|
|
269
|
+
toast.add({
|
|
270
|
+
title: t('api.tester.replayed'),
|
|
271
|
+
color: 'info',
|
|
272
|
+
icon: 'i-ph-arrow-counter-clockwise',
|
|
273
|
+
})
|
|
274
|
+
} catch (cause) {
|
|
275
|
+
presentError(cause, {
|
|
276
|
+
fallbackKey:
|
|
277
|
+
errorStatus(cause) === 404
|
|
278
|
+
? 'api.tester.replay_not_found'
|
|
279
|
+
: 'api.tester.replay_failed',
|
|
280
|
+
})
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const replayTitle = computed(() => {
|
|
285
|
+
const info = replayInfo.value
|
|
286
|
+
if (!info) return ''
|
|
287
|
+
return [
|
|
288
|
+
t('api.tester.replay_banner.title', {
|
|
289
|
+
id: shortId(info.id),
|
|
290
|
+
at: formatClock(info.at, dateFormat.value),
|
|
291
|
+
}),
|
|
292
|
+
...(info.skippedHeaders.length
|
|
293
|
+
? [
|
|
294
|
+
t(
|
|
295
|
+
'api.tester.replay_banner.headers',
|
|
296
|
+
{ count: info.skippedHeaders.length },
|
|
297
|
+
info.skippedHeaders.length,
|
|
298
|
+
),
|
|
299
|
+
]
|
|
300
|
+
: []),
|
|
301
|
+
...(redactedCount.value
|
|
302
|
+
? [
|
|
303
|
+
t(
|
|
304
|
+
'api.tester.replay_banner.redacted',
|
|
305
|
+
{ count: redactedCount.value },
|
|
306
|
+
redactedCount.value,
|
|
307
|
+
),
|
|
308
|
+
]
|
|
309
|
+
: []),
|
|
310
|
+
...(info.bodyTruncated ? [t('api.tester.replay_banner.truncated')] : []),
|
|
311
|
+
].join(' · ')
|
|
312
|
+
})
|
|
313
|
+
const replayDescription = computed(() => {
|
|
314
|
+
const info = replayInfo.value
|
|
315
|
+
if (!info) return ''
|
|
316
|
+
return info.skippedHeaders.length
|
|
317
|
+
? t('api.tester.replay_banner.skipped', {
|
|
318
|
+
names: info.skippedHeaders.join(', '),
|
|
319
|
+
})
|
|
320
|
+
: t('api.tester.replay_banner.credentials')
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
// --- Sending ---
|
|
324
|
+
|
|
325
|
+
async function confirmSend(ref: string): Promise<boolean> {
|
|
326
|
+
const firstWrite =
|
|
327
|
+
writes.value && !isDelete.value && !hasConfirmedWrite(ref)
|
|
328
|
+
const reasons: string[] = []
|
|
329
|
+
if (isDelete.value)
|
|
330
|
+
reasons.push(t('api.tester.confirm.delete', { path: path.value }))
|
|
331
|
+
else if (firstWrite)
|
|
332
|
+
reasons.push(
|
|
333
|
+
t('api.tester.confirm.write', {
|
|
334
|
+
method: method.value,
|
|
335
|
+
path: path.value,
|
|
336
|
+
}),
|
|
337
|
+
)
|
|
338
|
+
if (redactedCount.value)
|
|
339
|
+
reasons.push(
|
|
340
|
+
t(
|
|
341
|
+
'api.tester.confirm.redacted',
|
|
342
|
+
{ count: redactedCount.value },
|
|
343
|
+
redactedCount.value,
|
|
344
|
+
),
|
|
345
|
+
)
|
|
346
|
+
// A body cut at capture, sent untouched: the API gets part of it.
|
|
347
|
+
const truncated =
|
|
348
|
+
origin.value === 'replay' &&
|
|
349
|
+
!!replayInfo.value?.bodyTruncated &&
|
|
350
|
+
sentBody.value !== undefined
|
|
351
|
+
if (truncated) reasons.push(t('api.tester.confirm.truncated'))
|
|
352
|
+
if (reasons.length === 0) return true
|
|
353
|
+
session.confirming = true
|
|
354
|
+
try {
|
|
355
|
+
const confirmed = await confirm({
|
|
356
|
+
title: isDelete.value
|
|
357
|
+
? t('api.tester.confirm.delete_title')
|
|
358
|
+
: firstWrite
|
|
359
|
+
? t('api.tester.confirm.write_title')
|
|
360
|
+
: redactedCount.value
|
|
361
|
+
? t('api.tester.confirm.redacted_title')
|
|
362
|
+
: t('api.tester.confirm.truncated_title'),
|
|
363
|
+
description: reasons.join(' '),
|
|
364
|
+
color: isDelete.value ? 'error' : 'warning',
|
|
365
|
+
confirmLabel: t('api.tester.send'),
|
|
366
|
+
confirmIcon: 'i-ph-paper-plane-tilt',
|
|
367
|
+
initialFocus: 'cancel',
|
|
368
|
+
})
|
|
369
|
+
if (confirmed && firstWrite) rememberConfirmedWrite(ref)
|
|
370
|
+
return confirmed
|
|
371
|
+
} finally {
|
|
372
|
+
session.confirming = false
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
async function send() {
|
|
377
|
+
const value = route.value
|
|
378
|
+
if (sending.value || session.confirming || !value || blocker.value) return
|
|
379
|
+
const ref = value.ref
|
|
380
|
+
if (!(await confirmSend(ref))) return
|
|
381
|
+
if (session.activeRef !== ref || sending.value) return
|
|
382
|
+
// The signed mark that keeps the call out of the statistics: without it,
|
|
383
|
+
// the call would count as the API's own traffic, so it is not sent.
|
|
384
|
+
let source: string
|
|
385
|
+
try {
|
|
386
|
+
source = (await sourceTokens.get()).value
|
|
387
|
+
} catch (cause) {
|
|
388
|
+
presentError(cause, { fallbackKey: 'api.tester.source_failed' })
|
|
389
|
+
return
|
|
390
|
+
}
|
|
391
|
+
if (session.activeRef !== ref || sending.value) return
|
|
392
|
+
const requestId = newRequestId()
|
|
393
|
+
const sentPath = path.value
|
|
394
|
+
const snapshot = draftRequest.value
|
|
395
|
+
const sentAuth = auth.value
|
|
396
|
+
const outgoing: TesterRequest = {
|
|
397
|
+
...request.value,
|
|
398
|
+
headers: markedHeaders(request.value.headers, requestId, source),
|
|
399
|
+
}
|
|
400
|
+
const controller = new AbortController()
|
|
401
|
+
session.inFlight = { controller, ref }
|
|
402
|
+
sending.value = true
|
|
403
|
+
const at = Date.now()
|
|
404
|
+
const started = performance.now()
|
|
405
|
+
const sentSecrets = secretNames(outgoing.headers)
|
|
406
|
+
const common = {
|
|
407
|
+
auth: sentAuth,
|
|
408
|
+
...(sentSecrets.length ? { secrets: sentSecrets } : {}),
|
|
409
|
+
requestId,
|
|
410
|
+
at,
|
|
411
|
+
}
|
|
412
|
+
let outcome: TesterResult
|
|
413
|
+
try {
|
|
414
|
+
const answer = await sendTesterRequest(
|
|
415
|
+
sentPath,
|
|
416
|
+
window.location.origin,
|
|
417
|
+
outgoing,
|
|
418
|
+
controller.signal,
|
|
419
|
+
)
|
|
420
|
+
outcome = {
|
|
421
|
+
...answer,
|
|
422
|
+
bodySize: byteLength(answer.body),
|
|
423
|
+
durationMs: Math.round(performance.now() - started),
|
|
424
|
+
...common,
|
|
425
|
+
}
|
|
426
|
+
} catch (cause) {
|
|
427
|
+
if (cause instanceof TesterError && cause.response) {
|
|
428
|
+
presentError(cause, {
|
|
429
|
+
fallbackKey: `api.tester.errors.${cause.code}.title`,
|
|
430
|
+
})
|
|
431
|
+
return
|
|
432
|
+
}
|
|
433
|
+
outcome = {
|
|
434
|
+
status: 0,
|
|
435
|
+
durationMs: Math.round(performance.now() - started),
|
|
436
|
+
headers: {},
|
|
437
|
+
body: '',
|
|
438
|
+
error: cause instanceof TesterError ? cause.code : 'unexpected',
|
|
439
|
+
message: cause instanceof Error ? cause.message : String(cause),
|
|
440
|
+
...common,
|
|
441
|
+
}
|
|
442
|
+
} finally {
|
|
443
|
+
if (session.inFlight?.controller === controller) {
|
|
444
|
+
session.inFlight = null
|
|
445
|
+
sending.value = false
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
// An answer already in hand when the route changed is filed as it came.
|
|
449
|
+
if (controller.signal.reason === ROUTE_CHANGED && outcome.error)
|
|
450
|
+
outcome = { ...outcome, error: 'aborted', abandoned: true }
|
|
451
|
+
commit(ref, value.method, sentPath, snapshot, outcome)
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function cancel() {
|
|
455
|
+
session.inFlight?.controller.abort()
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Files a finished call under the route that sent it: its history, and the
|
|
460
|
+
* screen if it still shows that route, else its draft. A call cancelled from
|
|
461
|
+
* the screen stays off the history; one abandoned by a route change is kept,
|
|
462
|
+
* as the API may have received it.
|
|
463
|
+
*/
|
|
464
|
+
function commit(
|
|
465
|
+
ref: string,
|
|
466
|
+
sentMethod: string,
|
|
467
|
+
sentPath: string,
|
|
468
|
+
snapshot: DraftRequest,
|
|
469
|
+
outcome: TesterResult,
|
|
470
|
+
) {
|
|
471
|
+
const shown = !session.unmounted && session.activeRef === ref
|
|
472
|
+
if (outcome.error !== 'aborted' || outcome.abandoned) {
|
|
473
|
+
const entry = historyEntry(sentMethod, sentPath, snapshot, outcome)
|
|
474
|
+
const list = [entry, ...(shown ? history.value : loadHistory(ref))].slice(
|
|
475
|
+
0,
|
|
476
|
+
HISTORY_MAX,
|
|
477
|
+
)
|
|
478
|
+
if (shown) history.value = list
|
|
479
|
+
saveHistory(ref, list)
|
|
480
|
+
}
|
|
481
|
+
if (!shown) {
|
|
482
|
+
const draft = loadDraft(ref)
|
|
483
|
+
saveDraft(ref, {
|
|
484
|
+
...(draft ?? { request: snapshot, origin: 'example', replay: null }),
|
|
485
|
+
result: outcome,
|
|
486
|
+
})
|
|
487
|
+
return
|
|
488
|
+
}
|
|
489
|
+
showResult(outcome, true)
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// --- What the module captured of the call ---
|
|
493
|
+
|
|
494
|
+
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
495
|
+
|
|
496
|
+
async function findCaptured(
|
|
497
|
+
read: ReadJson,
|
|
498
|
+
target: TesterResult,
|
|
499
|
+
): Promise<CapturedRequest | null> {
|
|
500
|
+
const id = target.requestId as string
|
|
501
|
+
const page = await read<{ results: CapturedRow[] }>(
|
|
502
|
+
`${LOGS_API}?${new URLSearchParams({ requestId: id })}`,
|
|
503
|
+
)
|
|
504
|
+
// Only the call sent: a list that ignored the filter is no answer.
|
|
505
|
+
const matches = page.results.filter((item) =>
|
|
506
|
+
item.requestId === undefined
|
|
507
|
+
? page.results.length === 1
|
|
508
|
+
: item.requestId === id,
|
|
509
|
+
)
|
|
510
|
+
const found = matches[0]
|
|
511
|
+
if (
|
|
512
|
+
!found ||
|
|
513
|
+
Date.parse(found.timestamp) < target.at - CAPTURE_MATCH_MS ||
|
|
514
|
+
(found.route && session.activeRef && found.route !== session.activeRef)
|
|
515
|
+
)
|
|
516
|
+
return null
|
|
517
|
+
return read<CapturedRequest>(`${LOGS_API}/${encodeURIComponent(found._id)}`)
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
const capturedTarget = shallowRef<TesterResult | null>(null)
|
|
521
|
+
const captured = useApiData<CapturedRequest | null>(
|
|
522
|
+
() =>
|
|
523
|
+
capturedTarget.value?.requestId
|
|
524
|
+
? `dms-api:tester-captured:${capturedTarget.value.requestId}`
|
|
525
|
+
: null,
|
|
526
|
+
({ $authFetch, signal }) =>
|
|
527
|
+
findCaptured(
|
|
528
|
+
(url) => $authFetch(url, { signal }),
|
|
529
|
+
capturedTarget.value as TesterResult,
|
|
530
|
+
),
|
|
531
|
+
ON_DEMAND,
|
|
532
|
+
)
|
|
533
|
+
|
|
534
|
+
async function lookUpCaptured(target: TesterResult, retry: boolean) {
|
|
535
|
+
const id = target.requestId
|
|
536
|
+
if (!id) return
|
|
537
|
+
capturedState.value = 'loading'
|
|
538
|
+
const current = () =>
|
|
539
|
+
result.value?.requestId === id && capturedTarget.value?.requestId === id
|
|
540
|
+
for (const delay of retry ? CAPTURE_DELAYS_MS : [0]) {
|
|
541
|
+
if (delay) await wait(delay)
|
|
542
|
+
if (result.value?.requestId !== id) return
|
|
543
|
+
capturedTarget.value = target
|
|
544
|
+
await captured.execute()
|
|
545
|
+
if (!current()) return
|
|
546
|
+
if (captured.error.value) {
|
|
547
|
+
capturedState.value = 'error'
|
|
548
|
+
return
|
|
549
|
+
}
|
|
550
|
+
const log = captured.data.value
|
|
551
|
+
if (log) {
|
|
552
|
+
capturedLog.value = log
|
|
553
|
+
capturedState.value = 'found'
|
|
554
|
+
keepCaptured(id, log)
|
|
555
|
+
return
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
capturedState.value = 'missing'
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Keeps what the module captured of a call with its answer, on screen, in
|
|
563
|
+
* the draft and in the history: its server time and its record survive a
|
|
564
|
+
* return to the route. A 502 of the proxy for a call the module captured is
|
|
565
|
+
* the API answering more than the proxy returns.
|
|
566
|
+
*/
|
|
567
|
+
function keepCaptured(id: string, log: CapturedRequest) {
|
|
568
|
+
const value = result.value
|
|
569
|
+
if (value?.requestId !== id) return
|
|
570
|
+
if (value.captured && value.error !== 'proxy_failed') return
|
|
571
|
+
const patch: Partial<TesterResult> = {
|
|
572
|
+
captured: capturedSummary(log),
|
|
573
|
+
...(value.error === 'proxy_failed'
|
|
574
|
+
? { error: 'response_too_large' as const }
|
|
575
|
+
: {}),
|
|
576
|
+
}
|
|
577
|
+
result.value = { ...value, ...patch }
|
|
578
|
+
if (!session.activeRef) return
|
|
579
|
+
history.value = patchResult(history.value, id, patch)
|
|
580
|
+
saveHistory(session.activeRef, history.value)
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* Shows an answer, on its Captured tab when it failed. What the module
|
|
585
|
+
* captured is looked up for a call just made, for an answer restored before
|
|
586
|
+
* it was found (its server time and record), and when that tab is open.
|
|
587
|
+
*/
|
|
588
|
+
function showResult(value: TesterResult | null, fresh = false) {
|
|
589
|
+
result.value = value
|
|
590
|
+
capturedState.value = 'idle'
|
|
591
|
+
capturedLog.value = null
|
|
592
|
+
responseTab.value =
|
|
593
|
+
value?.error && capturedAvailable.value ? 'captured' : 'body'
|
|
594
|
+
if (
|
|
595
|
+
value &&
|
|
596
|
+
capturedAvailable.value &&
|
|
597
|
+
(fresh || responseTab.value === 'captured' || !value.captured)
|
|
598
|
+
)
|
|
599
|
+
void lookUpCaptured(value, fresh)
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
watch(responseTab, (value) => {
|
|
603
|
+
if (value === 'captured' && capturedState.value === 'idle' && result.value)
|
|
604
|
+
void lookUpCaptured(result.value, false)
|
|
605
|
+
})
|
|
606
|
+
|
|
607
|
+
const capturedSlow = computed(() => !!result.value?.captured?.slow)
|
|
608
|
+
|
|
609
|
+
return {
|
|
610
|
+
fill,
|
|
611
|
+
applyRequest,
|
|
612
|
+
openFirstTab,
|
|
613
|
+
warnLostSecrets,
|
|
614
|
+
resetToExample,
|
|
615
|
+
currentDraft,
|
|
616
|
+
flushDraft,
|
|
617
|
+
loadRoute,
|
|
618
|
+
dropReplayParam,
|
|
619
|
+
replayedId,
|
|
620
|
+
replayRead,
|
|
621
|
+
replay,
|
|
622
|
+
replayTitle,
|
|
623
|
+
replayDescription,
|
|
624
|
+
confirmSend,
|
|
625
|
+
send,
|
|
626
|
+
cancel,
|
|
627
|
+
commit,
|
|
628
|
+
wait,
|
|
629
|
+
findCaptured,
|
|
630
|
+
capturedTarget,
|
|
631
|
+
captured,
|
|
632
|
+
lookUpCaptured,
|
|
633
|
+
keepCaptured,
|
|
634
|
+
showResult,
|
|
635
|
+
capturedSlow,
|
|
636
|
+
}
|
|
637
|
+
}
|