@antelopejs/dms-api 0.1.7 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +99 -8
- package/dist/automation/get-api-health.js +4 -3
- package/dist/automation/get-api-health.js.map +1 -1
- package/dist/automation/route-unhealthy.js +2 -2
- package/dist/automation/route-unhealthy.js.map +1 -1
- package/dist/automation/scope.d.ts +0 -1
- package/dist/automation/scope.js +0 -7
- package/dist/automation/scope.js.map +1 -1
- package/dist/config.d.ts +4 -0
- package/dist/config.js +15 -9
- package/dist/config.js.map +1 -1
- package/dist/db/models/request_log.model.d.ts +37 -2
- package/dist/db/models/request_log.model.js +130 -35
- package/dist/db/models/request_log.model.js.map +1 -1
- package/dist/db/models/request_log.search.d.ts +5 -0
- package/dist/db/models/request_log.search.js +35 -0
- package/dist/db/models/request_log.search.js.map +1 -0
- package/dist/db/models/request_log.status.d.ts +5 -0
- package/dist/db/models/request_log.status.js +9 -0
- package/dist/db/models/request_log.status.js.map +1 -0
- package/dist/db/models/routes.model.d.ts +1 -0
- package/dist/db/models/routes.model.js +5 -1
- package/dist/db/models/routes.model.js.map +1 -1
- package/dist/db/models/routes_statistics.model.js +1 -1
- package/dist/db/models/routes_statistics.model.js.map +1 -1
- package/dist/db/tables/api_settings.table.d.ts +1 -0
- package/dist/db/tables/api_settings.table.js +4 -0
- package/dist/db/tables/api_settings.table.js.map +1 -1
- package/dist/db/tables/request_log.table.d.ts +18 -3
- package/dist/db/tables/request_log.table.js +34 -1
- package/dist/db/tables/request_log.table.js.map +1 -1
- package/dist/db/tables/routes.table.d.ts +1 -2
- package/dist/db/tables/routes.table.js.map +1 -1
- package/dist/db/tables/routes_statistics.table.d.ts +4 -3
- package/dist/db/tables/routes_statistics.table.js +5 -1
- package/dist/db/tables/routes_statistics.table.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/memo.d.ts +5 -0
- package/dist/memo.js +36 -0
- package/dist/memo.js.map +1 -0
- package/dist/pages/blocks.d.ts +3 -0
- package/dist/pages/blocks.js +31 -0
- package/dist/pages/blocks.js.map +1 -0
- package/dist/pages/displays.d.ts +7 -0
- package/dist/pages/displays.js +23 -0
- package/dist/pages/displays.js.map +1 -0
- package/dist/pages/index.d.ts +5 -2
- package/dist/pages/index.js +5 -2
- package/dist/pages/index.js.map +1 -1
- package/dist/pages/logs.d.ts +18 -0
- package/dist/pages/logs.js +112 -0
- package/dist/pages/logs.js.map +1 -0
- package/dist/pages/module.d.ts +3 -0
- package/dist/pages/module.js +102 -6
- package/dist/pages/module.js.map +1 -1
- package/dist/pages/overview.d.ts +14 -0
- package/dist/pages/overview.js +215 -0
- package/dist/pages/overview.js.map +1 -0
- package/dist/pages/period.d.ts +9 -0
- package/dist/pages/period.js +24 -0
- package/dist/pages/period.js.map +1 -0
- package/dist/pages/request-table.d.ts +11 -0
- package/dist/pages/request-table.js +187 -0
- package/dist/pages/request-table.js.map +1 -0
- package/dist/pages/routes.d.ts +15 -0
- package/dist/pages/routes.js +269 -0
- package/dist/pages/routes.js.map +1 -0
- package/dist/pages/scope-chip.d.ts +9 -0
- package/dist/pages/scope-chip.js +28 -0
- package/dist/pages/scope-chip.js.map +1 -0
- package/dist/pages/{logs/page.d.ts → settings.d.ts} +3 -3
- package/dist/pages/settings.js +218 -0
- package/dist/pages/settings.js.map +1 -0
- package/dist/pages/toolbar.d.ts +9 -0
- package/dist/pages/toolbar.js +33 -0
- package/dist/pages/toolbar.js.map +1 -0
- package/dist/realtime.d.ts +2 -0
- package/dist/realtime.js +21 -0
- package/dist/realtime.js.map +1 -0
- package/dist/routes/index.d.ts +2 -2
- package/dist/routes/index.js +2 -2
- package/dist/routes/index.js.map +1 -1
- package/dist/routes/logs.d.ts +173 -2
- package/dist/routes/logs.js +177 -86
- package/dist/routes/logs.js.map +1 -1
- package/dist/routes/overview.d.ts +27 -0
- package/dist/routes/overview.js +131 -0
- package/dist/routes/overview.js.map +1 -0
- package/dist/routes/routes.d.ts +92 -28
- package/dist/routes/routes.js +165 -97
- package/dist/routes/routes.js.map +1 -1
- package/dist/routes/settings.d.ts +16 -11
- package/dist/routes/settings.js +62 -54
- package/dist/routes/settings.js.map +1 -1
- package/dist/routes/tester.d.ts +7 -0
- package/dist/routes/tester.js +34 -0
- package/dist/routes/tester.js.map +1 -0
- package/dist/services/activity.d.ts +49 -0
- package/dist/services/activity.js +207 -0
- package/dist/services/activity.js.map +1 -0
- package/dist/services/aggregate-cache.d.ts +3 -0
- package/dist/services/aggregate-cache.js +16 -0
- package/dist/services/aggregate-cache.js.map +1 -0
- package/dist/services/api-origin.d.ts +1 -0
- package/dist/services/api-origin.js +9 -0
- package/dist/services/api-origin.js.map +1 -0
- package/dist/services/attention.d.ts +45 -0
- package/dist/services/attention.js +203 -0
- package/dist/services/attention.js.map +1 -0
- package/dist/services/composed-text.d.ts +6 -0
- package/dist/services/composed-text.js +23 -0
- package/dist/services/composed-text.js.map +1 -0
- package/dist/services/health-rules.d.ts +49 -0
- package/dist/services/health-rules.js +233 -0
- package/dist/services/health-rules.js.map +1 -0
- package/dist/services/index.d.ts +1 -3
- package/dist/services/index.js +3 -3
- package/dist/services/index.js.map +1 -1
- package/dist/services/introspection/decorators.d.ts +14 -0
- package/dist/services/introspection/decorators.js +192 -0
- package/dist/services/introspection/decorators.js.map +1 -0
- package/dist/services/introspection/errors.js +4 -4
- package/dist/services/introspection/errors.js.map +1 -1
- package/dist/services/introspection/index.d.ts +6 -8
- package/dist/services/introspection/index.js +96 -32
- package/dist/services/introspection/index.js.map +1 -1
- package/dist/services/introspection/probe.d.ts +2 -1
- package/dist/services/introspection/probe.js +11 -0
- package/dist/services/introspection/probe.js.map +1 -1
- package/dist/services/links.d.ts +25 -0
- package/dist/services/links.js +72 -0
- package/dist/services/links.js.map +1 -0
- package/dist/services/live-feed.d.ts +6 -0
- package/dist/services/live-feed.js +18 -0
- package/dist/services/live-feed.js.map +1 -0
- package/dist/services/live.d.ts +16 -0
- package/dist/services/live.js +32 -0
- package/dist/services/live.js.map +1 -0
- package/dist/services/overview.d.ts +122 -0
- package/dist/services/overview.js +324 -0
- package/dist/services/overview.js.map +1 -0
- package/dist/services/period.d.ts +0 -9
- package/dist/services/period.js +5 -52
- package/dist/services/period.js.map +1 -1
- package/dist/services/request-log/access.d.ts +5 -0
- package/dist/services/request-log/access.js +21 -0
- package/dist/services/request-log/access.js.map +1 -0
- package/dist/services/request-log/capture.d.ts +30 -0
- package/dist/services/request-log/capture.js +216 -39
- package/dist/services/request-log/capture.js.map +1 -1
- package/dist/services/request-log/list.d.ts +36 -0
- package/dist/services/request-log/list.js +201 -0
- package/dist/services/request-log/list.js.map +1 -0
- package/dist/services/request-log/read.d.ts +15 -2
- package/dist/services/request-log/read.js +47 -4
- package/dist/services/request-log/read.js.map +1 -1
- package/dist/services/request-log/redaction.d.ts +16 -3
- package/dist/services/request-log/redaction.js +149 -27
- package/dist/services/request-log/redaction.js.map +1 -1
- package/dist/services/request-log/util.d.ts +10 -3
- package/dist/services/request-log/util.js +39 -22
- package/dist/services/request-log/util.js.map +1 -1
- package/dist/services/route-catalog.d.ts +62 -0
- package/dist/services/route-catalog.js +163 -0
- package/dist/services/route-catalog.js.map +1 -0
- package/dist/services/route-contract.d.ts +66 -0
- package/dist/services/route-contract.js +266 -0
- package/dist/services/route-contract.js.map +1 -0
- package/dist/services/route-health.d.ts +35 -0
- package/dist/services/route-health.js +179 -0
- package/dist/services/route-health.js.map +1 -0
- package/dist/services/route-statistics.d.ts +68 -0
- package/dist/services/route-statistics.js +277 -0
- package/dist/services/route-statistics.js.map +1 -0
- package/dist/services/routes-sync.d.ts +7 -3
- package/dist/services/routes-sync.js +96 -20
- package/dist/services/routes-sync.js.map +1 -1
- package/dist/services/scope.d.ts +0 -1
- package/dist/services/scope.js +4 -17
- package/dist/services/scope.js.map +1 -1
- package/dist/services/settings-form.d.ts +131 -0
- package/dist/services/settings-form.js +210 -0
- package/dist/services/settings-form.js.map +1 -0
- package/dist/services/settings.d.ts +2 -0
- package/dist/services/settings.js +5 -0
- package/dist/services/settings.js.map +1 -1
- package/dist/services/statistics-aggregate.d.ts +6 -41
- package/dist/services/statistics-aggregate.js +55 -280
- package/dist/services/statistics-aggregate.js.map +1 -1
- package/dist/services/statistics-utils.d.ts +7 -12
- package/dist/services/statistics-utils.js +36 -51
- package/dist/services/statistics-utils.js.map +1 -1
- package/dist/services/statistics-write.js +64 -22
- package/dist/services/statistics-write.js.map +1 -1
- package/dist/services/tester-source.d.ts +11 -0
- package/dist/services/tester-source.js +48 -0
- package/dist/services/tester-source.js.map +1 -0
- package/dist/services/traffic-samples.d.ts +18 -0
- package/dist/services/traffic-samples.js +134 -0
- package/dist/services/traffic-samples.js.map +1 -0
- package/dist/services/traffic.d.ts +43 -0
- package/dist/services/traffic.js +270 -0
- package/dist/services/traffic.js.map +1 -0
- package/dist/services/window.d.ts +48 -0
- package/dist/services/window.js +179 -0
- package/dist/services/window.js.map +1 -0
- package/dist/types/constants.d.ts +11 -20
- package/dist/types/constants.js +15 -25
- package/dist/types/constants.js.map +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.js +0 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/statistics.d.ts +5 -3
- package/dist/types/statistics.js +5 -0
- package/dist/types/statistics.js.map +1 -1
- package/frontend-vue/app/components/blocks/BetaBadge.vue +20 -0
- package/frontend-vue/app/components/blocks/HealthHero.vue +708 -0
- package/frontend-vue/app/components/blocks/LiveTraffic.vue +356 -0
- package/frontend-vue/app/components/blocks/LogsEmptyState.vue +228 -0
- package/frontend-vue/app/components/blocks/LogsFilters.vue +279 -0
- package/frontend-vue/app/components/blocks/RequestDetail.vue +722 -0
- package/frontend-vue/app/components/blocks/RetentionInput.vue +227 -0
- package/frontend-vue/app/components/blocks/RouteDocumentation.vue +611 -0
- package/frontend-vue/app/components/blocks/RouteHeader.vue +320 -0
- package/frontend-vue/app/components/blocks/RouteTester.vue +1879 -0
- package/frontend-vue/app/components/blocks/RouteTree.vue +676 -0
- package/frontend-vue/app/components/blocks/ScopeChip.vue +89 -0
- package/frontend-vue/app/components/blocks/SettingNumberInput.vue +65 -0
- package/frontend-vue/app/components/blocks/SplitLayout.vue +41 -0
- package/frontend-vue/app/components/internal/ApiBody.vue +129 -0
- package/frontend-vue/app/components/internal/ApiJsonTree.vue +82 -0
- package/frontend-vue/app/components/internal/ApiKeyValues.vue +41 -0
- package/frontend-vue/app/components/internal/ApiMethodBadge.vue +19 -19
- package/frontend-vue/app/components/internal/ApiPath.vue +33 -0
- package/frontend-vue/app/components/internal/ApiStatusBadge.vue +20 -15
- package/frontend-vue/app/components/internal/ApiTesterBadge.vue +17 -0
- package/frontend-vue/app/composables/useApiOrigin.ts +19 -0
- package/frontend-vue/app/composables/useApiPeriod.ts +19 -0
- package/frontend-vue/app/composables/useApiResource.ts +92 -0
- package/frontend-vue/app/composables/useDateFormat.ts +23 -0
- package/frontend-vue/app/composables/useLiveMissedErrors.ts +33 -0
- package/frontend-vue/app/composables/useRouteDetail.ts +253 -0
- package/frontend-vue/app/composables/useRouteSelection.ts +43 -0
- package/frontend-vue/app/config/shortcuts-registry.ts +30 -0
- package/frontend-vue/app/plugins/displays.ts +92 -0
- package/frontend-vue/app/utils/format.ts +281 -0
- package/frontend-vue/app/utils/http.ts +127 -0
- package/frontend-vue/app/utils/logsQuery.ts +261 -0
- package/frontend-vue/app/utils/minuteHistogram.ts +116 -0
- package/frontend-vue/app/utils/requestDrawer.ts +257 -0
- package/frontend-vue/app/utils/routeExplorer.ts +206 -0
- package/frontend-vue/app/utils/search.ts +45 -0
- package/frontend-vue/app/utils/settingsForm.ts +119 -0
- package/frontend-vue/app/utils/snippets.ts +501 -0
- package/frontend-vue/app/utils/testerHistory.ts +354 -0
- package/frontend-vue/app/utils/testerRequest.ts +632 -11
- package/frontend-vue/dms.frontend.build.ts +7 -0
- package/frontend-vue/dms.frontend.ts +10 -3
- package/frontend-vue/i18n/locales/api-en-GB.json +866 -0
- package/frontend-vue/i18n/locales/api-fr-FR.json +866 -0
- package/frontend-vue/package.json +2 -6
- package/frontend-vue/pnpm-lock.yaml +97 -3375
- package/frontend-vue/tests/format.test.ts +180 -0
- package/frontend-vue/tests/http.test.ts +61 -0
- package/frontend-vue/tests/logsQuery.test.ts +255 -0
- package/frontend-vue/tests/minuteHistogram.test.ts +94 -0
- package/frontend-vue/tests/registration.test.ts +24 -7
- package/frontend-vue/tests/requestDrawer.test.ts +179 -0
- package/frontend-vue/tests/routeExplorer.test.ts +206 -0
- package/frontend-vue/tests/settingsForm.test.ts +155 -0
- package/frontend-vue/tests/snippets.test.ts +285 -0
- package/frontend-vue/tests/testerHistory.test.ts +295 -0
- package/frontend-vue/tests/testerRequest.test.ts +471 -76
- package/frontend-vue/tests/tooltipTriggers.test.ts +51 -0
- package/package.json +8 -8
- package/dist/middlewares/index.d.ts +0 -1
- package/dist/middlewares/index.js +0 -18
- package/dist/middlewares/index.js.map +0 -1
- package/dist/middlewares/request-log-capture.d.ts +0 -1
- package/dist/middlewares/request-log-capture.js +0 -6
- package/dist/middlewares/request-log-capture.js.map +0 -1
- package/dist/pages/all.d.ts +0 -4
- package/dist/pages/all.js +0 -21
- package/dist/pages/all.js.map +0 -1
- package/dist/pages/logs/page.js +0 -29
- package/dist/pages/logs/page.js.map +0 -1
- package/dist/pages/routes/page.d.ts +0 -9
- package/dist/pages/routes/page.js +0 -29
- package/dist/pages/routes/page.js.map +0 -1
- package/dist/pages/settings/form.d.ts +0 -3
- package/dist/pages/settings/form.js +0 -80
- package/dist/pages/settings/form.js.map +0 -1
- package/dist/pages/settings/page.d.ts +0 -9
- package/dist/pages/settings/page.js +0 -26
- package/dist/pages/settings/page.js.map +0 -1
- package/dist/pages/summary/page.d.ts +0 -9
- package/dist/pages/summary/page.js +0 -29
- package/dist/pages/summary/page.js.map +0 -1
- package/dist/routes/monitoring.d.ts +0 -17
- package/dist/routes/monitoring.js +0 -101
- package/dist/routes/monitoring.js.map +0 -1
- package/dist/routes/summary.d.ts +0 -32
- package/dist/routes/summary.js +0 -181
- package/dist/routes/summary.js.map +0 -1
- package/dist/services/request-log/index.d.ts +0 -3
- package/dist/services/request-log/index.js +0 -12
- package/dist/services/request-log/index.js.map +0 -1
- package/dist/services/statistics-read.d.ts +0 -4
- package/dist/services/statistics-read.js +0 -48
- package/dist/services/statistics-read.js.map +0 -1
- package/dist/services/tree.d.ts +0 -10
- package/dist/services/tree.js +0 -128
- package/dist/services/tree.js.map +0 -1
- package/dist/types/charts.d.ts +0 -9
- package/dist/types/charts.js +0 -3
- package/dist/types/charts.js.map +0 -1
- package/frontend-vue/app/components/ConfigurationView.vue +0 -187
- package/frontend-vue/app/components/DocumentationView.vue +0 -224
- package/frontend-vue/app/components/LogDetailDrawer.vue +0 -178
- package/frontend-vue/app/components/LogsView.vue +0 -347
- package/frontend-vue/app/components/RouteDetailTabs.vue +0 -179
- package/frontend-vue/app/components/RouteTree.vue +0 -196
- package/frontend-vue/app/components/RoutesView.vue +0 -79
- package/frontend-vue/app/components/StatsView.vue +0 -268
- package/frontend-vue/app/components/SummaryView.vue +0 -657
- package/frontend-vue/app/components/TesterPanel.vue +0 -499
- package/frontend-vue/app/components/internal/PeriodSelect.vue +0 -58
- package/frontend-vue/app/components/internal/RouteTreeNode.vue +0 -168
- package/frontend-vue/app/components/internal/StatusBreakdownBars.vue +0 -162
- package/frontend-vue/app/components/internal/StatusDonut.vue +0 -84
- package/frontend-vue/app/components/internal/UnitAreaChart.vue +0 -73
- package/frontend-vue/app/composables/useApiIntrospection.ts +0 -350
- package/frontend-vue/app/composables/useLogDetailDrawer.ts +0 -50
- package/frontend-vue/app/composables/useSelectedPeriod.ts +0 -107
- package/frontend-vue/app/composables/useStatsPeriods.ts +0 -139
- package/frontend-vue/app/custom-layouts/.gitkeep +0 -0
- package/frontend-vue/app/custom-pages/.gitkeep +0 -0
- package/frontend-vue/app/utils/httpMethod.ts +0 -49
- package/frontend-vue/app/utils/statusClass.ts +0 -49
- package/frontend-vue/i18n/locales/en-GB.json +0 -240
- package/frontend-vue/i18n/locales/fr-FR.json +0 -240
- package/frontend-vue/public/.gitkeep +0 -0
- package/frontend-vue/server/.gitkeep +0 -0
- package/frontend-vue/tests/periods.test.ts +0 -145
- package/frontend-vue/tests/persistence.test.ts +0 -45
|
@@ -0,0 +1,1879 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, onBeforeUnmount, reactive, ref, useId, watch } from 'vue'
|
|
3
|
+
import {
|
|
4
|
+
byteLength,
|
|
5
|
+
formatBytes,
|
|
6
|
+
formatClock,
|
|
7
|
+
formatMs,
|
|
8
|
+
prettyBody,
|
|
9
|
+
} from '../../utils/format'
|
|
10
|
+
import {
|
|
11
|
+
acceptsRequestBody,
|
|
12
|
+
isWritingMethod,
|
|
13
|
+
pathSegments,
|
|
14
|
+
statusText,
|
|
15
|
+
} from '../../utils/http'
|
|
16
|
+
import { fillPath, toCurl } from '../../utils/snippets'
|
|
17
|
+
import {
|
|
18
|
+
authModeOf,
|
|
19
|
+
type AuthMode,
|
|
20
|
+
type BodyMode,
|
|
21
|
+
type CapturedRequest,
|
|
22
|
+
capturedSummary,
|
|
23
|
+
contentTypeFor,
|
|
24
|
+
countRedacted,
|
|
25
|
+
formatJson,
|
|
26
|
+
hasRedacted,
|
|
27
|
+
inputProblem,
|
|
28
|
+
jsonProblem,
|
|
29
|
+
type KeyValue,
|
|
30
|
+
createSourceTokens,
|
|
31
|
+
markedHeaders,
|
|
32
|
+
mergeHeaders,
|
|
33
|
+
neverSent,
|
|
34
|
+
newRequestId,
|
|
35
|
+
PROXY_BODY_LIMIT,
|
|
36
|
+
PROXY_RESPONSE_LIMIT,
|
|
37
|
+
PROXY_TIMEOUT_MS,
|
|
38
|
+
redactedFields,
|
|
39
|
+
replayFrom,
|
|
40
|
+
revealBidi,
|
|
41
|
+
sendTesterRequest,
|
|
42
|
+
serializeBody,
|
|
43
|
+
SIZE_PROBE_SOURCE,
|
|
44
|
+
TesterError,
|
|
45
|
+
type TesterSourceToken,
|
|
46
|
+
TESTER_SOURCE_URL,
|
|
47
|
+
type TesterErrorCode,
|
|
48
|
+
type TesterRequest,
|
|
49
|
+
type TesterResult,
|
|
50
|
+
withQueryRows,
|
|
51
|
+
} from '../../utils/testerRequest'
|
|
52
|
+
import {
|
|
53
|
+
type BodyOrigin,
|
|
54
|
+
type DraftRequest,
|
|
55
|
+
exampleRequest,
|
|
56
|
+
hasConfirmedWrite,
|
|
57
|
+
type HistoryEntry,
|
|
58
|
+
HISTORY_MAX,
|
|
59
|
+
historyEntry,
|
|
60
|
+
isSecretHeader,
|
|
61
|
+
loadCommonHeaders,
|
|
62
|
+
loadDraft,
|
|
63
|
+
loadHistory,
|
|
64
|
+
lostSecrets,
|
|
65
|
+
patchResult,
|
|
66
|
+
rememberConfirmedWrite,
|
|
67
|
+
type ReplayInfo,
|
|
68
|
+
sameRequest,
|
|
69
|
+
saveCommonHeaders,
|
|
70
|
+
saveDraft,
|
|
71
|
+
saveHistory,
|
|
72
|
+
secretNames,
|
|
73
|
+
type TesterDraft,
|
|
74
|
+
} from '../../utils/testerHistory'
|
|
75
|
+
import ApiKeyValues from '../internal/ApiKeyValues.vue'
|
|
76
|
+
import ApiMethodBadge from '../internal/ApiMethodBadge.vue'
|
|
77
|
+
import ApiStatusBadge from '../internal/ApiStatusBadge.vue'
|
|
78
|
+
|
|
79
|
+
// Call the selected route from the dashboard. The URL bar holds the method,
|
|
80
|
+
// the path with its parameters to fill in, and Send; the body starts from
|
|
81
|
+
// the last request the route accepted. A route keeps its draft for the
|
|
82
|
+
// session (body, headers, query, path values, last answer), across tabs,
|
|
83
|
+
// routes and pages. A call that writes data is confirmed first, and the
|
|
84
|
+
// answer shows its status, the browser and server times and what the module
|
|
85
|
+
// captured of it (`x-request-id`). `?replay=<request id>` loads a captured
|
|
86
|
+
// request once, then leaves the URL.
|
|
87
|
+
//
|
|
88
|
+
// Typing in one of its fields holds the page's live mode ("Paused · typing in
|
|
89
|
+
// the Tester"), so the route's figures do not move under the request being
|
|
90
|
+
// written; leaving the Tester releases it.
|
|
91
|
+
defineOptions({ inheritAttrs: false })
|
|
92
|
+
|
|
93
|
+
const props = withDefaults(
|
|
94
|
+
defineProps<{ fetchUrl: string; queryKey?: string }>(),
|
|
95
|
+
{
|
|
96
|
+
queryKey: 'route',
|
|
97
|
+
},
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
interface Row extends KeyValue {
|
|
101
|
+
id: number
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** A row of the logs list, as far as finding a captured call goes. */
|
|
105
|
+
interface CapturedRow {
|
|
106
|
+
_id: string
|
|
107
|
+
route?: string
|
|
108
|
+
timestamp: string
|
|
109
|
+
requestId?: string
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
type CapturedState = 'idle' | 'loading' | 'found' | 'missing' | 'error'
|
|
113
|
+
|
|
114
|
+
// The tester's own reads of the request logs: by its permission, not the
|
|
115
|
+
// request logs page's.
|
|
116
|
+
const LOGS_API = '/api/monitoring/logs/tester'
|
|
117
|
+
const LOGS_PAGE = '/modules/api/logs'
|
|
118
|
+
/**
|
|
119
|
+
* Abort reason of a call left behind by a route change: filed under its
|
|
120
|
+
* route as abandoned, since the API may have received it.
|
|
121
|
+
*/
|
|
122
|
+
const ROUTE_CHANGED = 'route-changed'
|
|
123
|
+
/** The capture is written once the answer is sent: looked for twice. */
|
|
124
|
+
const CAPTURE_DELAYS_MS = [400, 1500]
|
|
125
|
+
/** A captured call older than this is not the one just sent. */
|
|
126
|
+
const CAPTURE_MATCH_MS = 60_000
|
|
127
|
+
/** An id as long as a real one, to size the request before sending it. */
|
|
128
|
+
const SIZE_PROBE_ID = '00000000-0000-0000-0000-000000000000'
|
|
129
|
+
const DRAFT_SAVE_DELAY_MS = 250
|
|
130
|
+
const BODY_MODES: BodyMode[] = ['json', 'text', 'form', 'none']
|
|
131
|
+
const AUTH_ICONS: Record<AuthMode, string> = {
|
|
132
|
+
session: 'i-ph-user-check',
|
|
133
|
+
manual: 'i-ph-key',
|
|
134
|
+
none: 'i-ph-lock-simple-open',
|
|
135
|
+
}
|
|
136
|
+
const ERROR_ICONS: Partial<Record<TesterErrorCode, string>> = {
|
|
137
|
+
invalid_input: 'i-ph-prohibit',
|
|
138
|
+
body_too_large: 'i-ph-file-x',
|
|
139
|
+
not_authenticated: 'i-ph-sign-in',
|
|
140
|
+
not_owner: 'i-ph-lock-simple',
|
|
141
|
+
cross_origin: 'i-ph-shield-warning',
|
|
142
|
+
response_too_large: 'i-ph-file-x',
|
|
143
|
+
timeout: 'i-ph-timer',
|
|
144
|
+
aborted: 'i-ph-x-circle',
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Error texts that send to the Captured tab: another text on a route the
|
|
148
|
+
* module does not capture.
|
|
149
|
+
*/
|
|
150
|
+
const POINTS_TO_CAPTURED: ReadonlySet<string> = new Set([
|
|
151
|
+
'proxy_failed',
|
|
152
|
+
'timeout',
|
|
153
|
+
'aborted',
|
|
154
|
+
'abandoned',
|
|
155
|
+
])
|
|
156
|
+
|
|
157
|
+
const { t } = useI18n()
|
|
158
|
+
const { formatLocale: locale } = useRegionalFormat({ locale: 'format' })
|
|
159
|
+
const dateFormat = useDateFormat()
|
|
160
|
+
const toast = useToast()
|
|
161
|
+
const { confirm } = useConfirm()
|
|
162
|
+
const { loggedIn } = useUserSession()
|
|
163
|
+
const currentRoute = useDmsRoute()
|
|
164
|
+
const router = useDmsRouter()
|
|
165
|
+
const { $authFetch } = useAuthFetch()
|
|
166
|
+
const {
|
|
167
|
+
data: route,
|
|
168
|
+
pending,
|
|
169
|
+
selection,
|
|
170
|
+
} = useRouteDetail(props.fetchUrl, props.queryKey)
|
|
171
|
+
const apiOrigin = useApiOrigin(() => route.value?.apiOrigin)
|
|
172
|
+
const blockerId = useId()
|
|
173
|
+
const sourceTokens = createSourceTokens(() =>
|
|
174
|
+
$authFetch<TesterSourceToken>(TESTER_SOURCE_URL),
|
|
175
|
+
)
|
|
176
|
+
const bodyHintId = useId()
|
|
177
|
+
|
|
178
|
+
let nextRowId = 0
|
|
179
|
+
const row = (name = '', value = ''): Row => ({ id: nextRowId++, name, value })
|
|
180
|
+
const rows = (list: Row[]): KeyValue[] =>
|
|
181
|
+
list.map(({ name, value }) => ({ name, value }))
|
|
182
|
+
|
|
183
|
+
const bodyMode = ref<BodyMode>('none')
|
|
184
|
+
const body = ref('')
|
|
185
|
+
const form = reactive<Row[]>([])
|
|
186
|
+
const headers = reactive<Row[]>([])
|
|
187
|
+
const query = reactive<Row[]>([])
|
|
188
|
+
const pathValues = reactive<Record<string, string>>({})
|
|
189
|
+
const useSession = ref(true)
|
|
190
|
+
const origin = ref<BodyOrigin>('example')
|
|
191
|
+
const replayInfo = ref<ReplayInfo | null>(null)
|
|
192
|
+
const result = ref<TesterResult | null>(null)
|
|
193
|
+
const commonHeaders = reactive<Row[]>(
|
|
194
|
+
loadCommonHeaders().map((entry) => row(entry.name, entry.value)),
|
|
195
|
+
)
|
|
196
|
+
const history = ref<HistoryEntry[]>([])
|
|
197
|
+
const tab = ref('body')
|
|
198
|
+
const responseTab = ref('body')
|
|
199
|
+
const sending = ref(false)
|
|
200
|
+
const capturedState = ref<CapturedState>('idle')
|
|
201
|
+
const capturedLog = ref<CapturedRequest | null>(null)
|
|
202
|
+
|
|
203
|
+
// The route the fields belong to, the call in flight and its route.
|
|
204
|
+
let activeRef: string | null = null
|
|
205
|
+
let inFlight: { controller: AbortController; ref: string } | null = null
|
|
206
|
+
let confirming = false
|
|
207
|
+
let unmounted = false
|
|
208
|
+
|
|
209
|
+
const method = computed(() => route.value?.method ?? 'GET')
|
|
210
|
+
const bodyAllowed = computed(() => acceptsRequestBody(method.value))
|
|
211
|
+
const writes = computed(() => isWritingMethod(method.value))
|
|
212
|
+
const isDelete = computed(() => method.value.toUpperCase() === 'DELETE')
|
|
213
|
+
|
|
214
|
+
const draftRequest = computed<DraftRequest>(() => ({
|
|
215
|
+
bodyMode: bodyMode.value,
|
|
216
|
+
body: body.value,
|
|
217
|
+
form: rows(form),
|
|
218
|
+
headers: rows(headers),
|
|
219
|
+
query: rows(query),
|
|
220
|
+
pathValues: { ...pathValues },
|
|
221
|
+
useSession: useSession.value,
|
|
222
|
+
}))
|
|
223
|
+
|
|
224
|
+
const example = computed(() =>
|
|
225
|
+
route.value
|
|
226
|
+
? exampleRequest(
|
|
227
|
+
{
|
|
228
|
+
method: route.value.method,
|
|
229
|
+
pathParams: route.value.pathParams,
|
|
230
|
+
exampleBody: route.value.contract.exampleBody,
|
|
231
|
+
examplePath: route.value.contract.examplePath,
|
|
232
|
+
authStatus: route.value.auth.status,
|
|
233
|
+
},
|
|
234
|
+
history.value,
|
|
235
|
+
)
|
|
236
|
+
: null,
|
|
237
|
+
)
|
|
238
|
+
const modified = computed(
|
|
239
|
+
() => !!example.value && !sameRequest(draftRequest.value, example.value),
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
// --- The request as it leaves ---
|
|
243
|
+
|
|
244
|
+
const segments = computed(() =>
|
|
245
|
+
pathSegments(route.value?.path ?? '/').map((segment) => ({
|
|
246
|
+
...segment,
|
|
247
|
+
name: segment.text.slice(1),
|
|
248
|
+
})),
|
|
249
|
+
)
|
|
250
|
+
const path = computed(() =>
|
|
251
|
+
withQueryRows(fillPath(route.value?.path ?? '/', pathValues), query),
|
|
252
|
+
)
|
|
253
|
+
const displayQuery = computed(() => {
|
|
254
|
+
const named = query.filter((entry) => entry.name)
|
|
255
|
+
return named.length
|
|
256
|
+
? revealBidi(
|
|
257
|
+
`?${named.map((entry) => `${entry.name}=${entry.value}`).join('&')}`,
|
|
258
|
+
)
|
|
259
|
+
: ''
|
|
260
|
+
})
|
|
261
|
+
const missingPathParams = computed(() =>
|
|
262
|
+
(route.value?.pathParams ?? []).filter((name) => !pathValues[name]),
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
const sentBody = computed(() =>
|
|
266
|
+
bodyAllowed.value
|
|
267
|
+
? serializeBody(bodyMode.value, body.value, form)
|
|
268
|
+
: undefined,
|
|
269
|
+
)
|
|
270
|
+
const impliedHeaders = computed(() => {
|
|
271
|
+
const implied: Record<string, string> = {}
|
|
272
|
+
const type = contentTypeFor(bodyMode.value)
|
|
273
|
+
if (sentBody.value !== undefined && type) implied['content-type'] = type
|
|
274
|
+
return implied
|
|
275
|
+
})
|
|
276
|
+
/** Headers as the API gets them, before the session and the tester's marks. */
|
|
277
|
+
const effectiveHeaders = computed(() =>
|
|
278
|
+
mergeHeaders(impliedHeaders.value, commonHeaders, headers),
|
|
279
|
+
)
|
|
280
|
+
const shownImpliedHeaders = computed(() =>
|
|
281
|
+
Object.entries(impliedHeaders.value).filter(
|
|
282
|
+
([name]) =>
|
|
283
|
+
![...commonHeaders, ...headers].some(
|
|
284
|
+
(entry) => entry.name.toLowerCase() === name,
|
|
285
|
+
),
|
|
286
|
+
),
|
|
287
|
+
)
|
|
288
|
+
const auth = computed(() =>
|
|
289
|
+
authModeOf(effectiveHeaders.value, useSession.value && loggedIn.value),
|
|
290
|
+
)
|
|
291
|
+
/** Who the call goes as; an Authorization of the headers for all routes says so. */
|
|
292
|
+
const authLabel = computed(() =>
|
|
293
|
+
auth.value === 'manual' &&
|
|
294
|
+
!headers.some((entry) => entry.name.toLowerCase() === 'authorization')
|
|
295
|
+
? t('api.tester.auth.manual_common')
|
|
296
|
+
: t(`api.tester.auth.${auth.value}`),
|
|
297
|
+
)
|
|
298
|
+
const request = computed<TesterRequest>(() => ({
|
|
299
|
+
method: method.value,
|
|
300
|
+
headers: effectiveHeaders.value,
|
|
301
|
+
useSession: useSession.value && loggedIn.value,
|
|
302
|
+
...(sentBody.value !== undefined ? { body: sentBody.value } : {}),
|
|
303
|
+
}))
|
|
304
|
+
|
|
305
|
+
const problem = computed(() =>
|
|
306
|
+
route.value
|
|
307
|
+
? inputProblem(pathValues, path.value, {
|
|
308
|
+
...request.value,
|
|
309
|
+
headers: markedHeaders(
|
|
310
|
+
request.value.headers,
|
|
311
|
+
SIZE_PROBE_ID,
|
|
312
|
+
SIZE_PROBE_SOURCE,
|
|
313
|
+
),
|
|
314
|
+
})
|
|
315
|
+
: null,
|
|
316
|
+
)
|
|
317
|
+
/** Why Send is off, said next to it. */
|
|
318
|
+
const blocker = computed<string | null>(() => {
|
|
319
|
+
if (missingPathParams.value.length)
|
|
320
|
+
return t('api.tester.blocked.path_missing', {
|
|
321
|
+
names: missingPathParams.value.map((name) => `:${name}`).join(', '),
|
|
322
|
+
})
|
|
323
|
+
const value = problem.value
|
|
324
|
+
if (!value) return null
|
|
325
|
+
if (value.code === 'path_value')
|
|
326
|
+
return t('api.tester.blocked.path_value', { name: `:${value.name}` })
|
|
327
|
+
if (value.code === 'header')
|
|
328
|
+
return t('api.tester.blocked.header', { name: value.name })
|
|
329
|
+
return t('api.tester.blocked.too_large', {
|
|
330
|
+
size: formatBytes(value.size, locale.value),
|
|
331
|
+
limit: formatBytes(PROXY_BODY_LIMIT, locale.value),
|
|
332
|
+
})
|
|
333
|
+
})
|
|
334
|
+
|
|
335
|
+
const jsonWarning = computed(() =>
|
|
336
|
+
bodyAllowed.value && bodyMode.value === 'json'
|
|
337
|
+
? jsonProblem(body.value)
|
|
338
|
+
: null,
|
|
339
|
+
)
|
|
340
|
+
const formattedBody = computed(() =>
|
|
341
|
+
bodyMode.value === 'json' && body.value.trim() && !jsonWarning.value
|
|
342
|
+
? formatJson(body.value)
|
|
343
|
+
: null,
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
/** Masked values ([REDACTED]) still in what would be sent. */
|
|
347
|
+
const redactedCount = computed(() => {
|
|
348
|
+
const text =
|
|
349
|
+
bodyAllowed.value && ['json', 'text'].includes(bodyMode.value)
|
|
350
|
+
? body.value
|
|
351
|
+
: ''
|
|
352
|
+
const fields = bodyMode.value === 'form' ? form : []
|
|
353
|
+
return (
|
|
354
|
+
countRedacted(text) +
|
|
355
|
+
[...headers, ...commonHeaders, ...query, ...fields].reduce(
|
|
356
|
+
(count, entry) => count + countRedacted(entry.value),
|
|
357
|
+
0,
|
|
358
|
+
) +
|
|
359
|
+
Object.values(pathValues).reduce(
|
|
360
|
+
(count, value) => count + countRedacted(value),
|
|
361
|
+
0,
|
|
362
|
+
)
|
|
363
|
+
)
|
|
364
|
+
})
|
|
365
|
+
const redactedBodyFields = computed(() =>
|
|
366
|
+
['json', 'text'].includes(bodyMode.value) ? redactedFields(body.value) : [],
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
// --- Tabs ---
|
|
370
|
+
|
|
371
|
+
const tabs = computed(() => [
|
|
372
|
+
...(bodyAllowed.value
|
|
373
|
+
? [{ label: t('api.tester.tabs.body'), value: 'body' }]
|
|
374
|
+
: []),
|
|
375
|
+
{
|
|
376
|
+
label: t('api.tester.tabs.headers'),
|
|
377
|
+
value: 'headers',
|
|
378
|
+
badge:
|
|
379
|
+
[...headers, ...commonHeaders].filter((entry) => entry.name).length ||
|
|
380
|
+
undefined,
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
label: t('api.tester.tabs.query'),
|
|
384
|
+
value: 'query',
|
|
385
|
+
badge: query.filter((entry) => entry.name).length || undefined,
|
|
386
|
+
},
|
|
387
|
+
])
|
|
388
|
+
|
|
389
|
+
const bodyModeItems = computed(() =>
|
|
390
|
+
BODY_MODES.map((value) => ({
|
|
391
|
+
label: t(`api.tester.body_modes.${value}`),
|
|
392
|
+
value,
|
|
393
|
+
})),
|
|
394
|
+
)
|
|
395
|
+
|
|
396
|
+
/** Credentials typed among the headers for all routes: every route gets them. */
|
|
397
|
+
const commonSecrets = computed(() =>
|
|
398
|
+
commonHeaders
|
|
399
|
+
.filter((entry) => entry.value && isSecretHeader(entry.name))
|
|
400
|
+
.map((entry) => entry.name),
|
|
401
|
+
)
|
|
402
|
+
|
|
403
|
+
/** The key / value lists the open tab edits. */
|
|
404
|
+
const editors = computed(() => {
|
|
405
|
+
if (tab.value === 'headers')
|
|
406
|
+
return [
|
|
407
|
+
{ key: 'headers', list: headers, add: t('api.tester.add_header') },
|
|
408
|
+
{
|
|
409
|
+
key: 'common',
|
|
410
|
+
list: commonHeaders,
|
|
411
|
+
add: t('api.tester.add_header'),
|
|
412
|
+
title: t('api.tester.common_headers'),
|
|
413
|
+
hint: t('api.tester.common_headers_hint'),
|
|
414
|
+
warning: commonSecrets.value.length
|
|
415
|
+
? t('api.tester.common_secret', {
|
|
416
|
+
names: commonSecrets.value.join(', '),
|
|
417
|
+
})
|
|
418
|
+
: undefined,
|
|
419
|
+
},
|
|
420
|
+
]
|
|
421
|
+
if (tab.value === 'query')
|
|
422
|
+
return [{ key: 'query', list: query, add: t('api.tester.add_query') }]
|
|
423
|
+
return [{ key: 'form', list: form, add: t('api.tester.add_field') }]
|
|
424
|
+
})
|
|
425
|
+
|
|
426
|
+
/** False for a route the module leaves out of its logs (the console's own). */
|
|
427
|
+
const routeCaptured = computed(() => route.value?.captured !== false)
|
|
428
|
+
const capturedAvailable = computed(
|
|
429
|
+
() =>
|
|
430
|
+
routeCaptured.value &&
|
|
431
|
+
!!result.value?.requestId &&
|
|
432
|
+
!neverSent(result.value.error),
|
|
433
|
+
)
|
|
434
|
+
const responseTabs = computed(() => [
|
|
435
|
+
...(result.value?.error
|
|
436
|
+
? []
|
|
437
|
+
: [
|
|
438
|
+
{ label: t('api.tester.response'), value: 'body' },
|
|
439
|
+
{
|
|
440
|
+
label: t('api.tester.tabs.headers'),
|
|
441
|
+
value: 'headers',
|
|
442
|
+
badge: Object.keys(result.value?.headers ?? {}).length || undefined,
|
|
443
|
+
},
|
|
444
|
+
]),
|
|
445
|
+
...(capturedAvailable.value
|
|
446
|
+
? [{ label: t('api.tester.tabs.captured'), value: 'captured' }]
|
|
447
|
+
: []),
|
|
448
|
+
])
|
|
449
|
+
|
|
450
|
+
// --- What the line under the body says ---
|
|
451
|
+
|
|
452
|
+
const bodyHint = computed<{ text: string; tone: 'dimmed' | 'warning' }>(() => {
|
|
453
|
+
const contract = route.value?.contract
|
|
454
|
+
if (bodyMode.value === 'none')
|
|
455
|
+
return { text: t('api.tester.body_hint.none'), tone: 'dimmed' }
|
|
456
|
+
if (origin.value === 'replay' && replayInfo.value) {
|
|
457
|
+
const info = replayInfo.value
|
|
458
|
+
if (info.bodyMissing)
|
|
459
|
+
return {
|
|
460
|
+
text: info.bodyOmitted
|
|
461
|
+
? t('api.tester.body_hint.replay_missing', {
|
|
462
|
+
reason: t(`api.tester.body_omitted.${info.bodyOmitted}`),
|
|
463
|
+
})
|
|
464
|
+
: t('api.tester.body_hint.replay_missing_unknown'),
|
|
465
|
+
tone: 'warning',
|
|
466
|
+
}
|
|
467
|
+
if (info.bodyTruncated)
|
|
468
|
+
return {
|
|
469
|
+
text:
|
|
470
|
+
problem.value?.code === 'body_too_large'
|
|
471
|
+
? t('api.tester.body_hint.replay_truncated_too_large', {
|
|
472
|
+
limit: formatBytes(PROXY_BODY_LIMIT, locale.value),
|
|
473
|
+
})
|
|
474
|
+
: t('api.tester.body_hint.replay_truncated'),
|
|
475
|
+
tone: 'warning',
|
|
476
|
+
}
|
|
477
|
+
return {
|
|
478
|
+
text: t('api.tester.body_hint.replay', { id: shortId(info.id) }),
|
|
479
|
+
tone: 'dimmed',
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
if (sentBody.value === undefined)
|
|
483
|
+
return { text: t('api.tester.body_hint.empty'), tone: 'dimmed' }
|
|
484
|
+
if (bodyMode.value === 'form')
|
|
485
|
+
return { text: t('api.tester.body_hint.form'), tone: 'dimmed' }
|
|
486
|
+
if (origin.value === 'history')
|
|
487
|
+
return { text: t('api.tester.body_hint.history'), tone: 'dimmed' }
|
|
488
|
+
if (origin.value === 'edited' || !contract)
|
|
489
|
+
return { text: '', tone: 'dimmed' }
|
|
490
|
+
if (contract.exampleBody !== null && contract.exampleBody !== undefined)
|
|
491
|
+
return { text: t('api.tester.body_hint.example'), tone: 'dimmed' }
|
|
492
|
+
const span = { days: contract.windowDays, count: contract.total }
|
|
493
|
+
if (contract.total === 0)
|
|
494
|
+
return { text: t('api.tester.body_hint.no_capture', span), tone: 'dimmed' }
|
|
495
|
+
return {
|
|
496
|
+
text: contract.sampled
|
|
497
|
+
? t(
|
|
498
|
+
'api.tester.body_hint.no_json',
|
|
499
|
+
{ ...span, count: contract.sampled },
|
|
500
|
+
contract.sampled,
|
|
501
|
+
)
|
|
502
|
+
: t('api.tester.body_hint.no_success', span, contract.total),
|
|
503
|
+
tone: 'dimmed',
|
|
504
|
+
}
|
|
505
|
+
})
|
|
506
|
+
|
|
507
|
+
const queryHint = computed(() => {
|
|
508
|
+
const contract = route.value?.contract
|
|
509
|
+
if (!contract) return ''
|
|
510
|
+
if (contract.queryParams.length)
|
|
511
|
+
return t('api.tester.query_known', {
|
|
512
|
+
names: contract.queryParams.join(', '),
|
|
513
|
+
})
|
|
514
|
+
const span = { days: contract.windowDays }
|
|
515
|
+
return contract.total
|
|
516
|
+
? t('api.tester.query_none', span)
|
|
517
|
+
: t('api.tester.query_no_capture', span)
|
|
518
|
+
})
|
|
519
|
+
|
|
520
|
+
function shortId(id: string): string {
|
|
521
|
+
return id.slice(0, 8)
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// --- Draft ---
|
|
525
|
+
|
|
526
|
+
function fill(list: Row[], values: KeyValue[]) {
|
|
527
|
+
list.splice(
|
|
528
|
+
0,
|
|
529
|
+
list.length,
|
|
530
|
+
...values.map((entry) => row(entry.name, entry.value)),
|
|
531
|
+
)
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function applyRequest(next: DraftRequest) {
|
|
535
|
+
bodyMode.value = bodyAllowed.value ? next.bodyMode : 'none'
|
|
536
|
+
body.value = next.body
|
|
537
|
+
fill(form, next.form)
|
|
538
|
+
fill(headers, next.headers)
|
|
539
|
+
fill(query, next.query)
|
|
540
|
+
for (const key of Object.keys(pathValues)) delete pathValues[key]
|
|
541
|
+
for (const name of route.value?.pathParams ?? [])
|
|
542
|
+
pathValues[name] = next.pathValues[name] ?? ''
|
|
543
|
+
useSession.value = next.useSession
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
function openFirstTab() {
|
|
547
|
+
tab.value = bodyMode.value !== 'none' ? 'body' : 'headers'
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* Says which credentials a restored answer was sent with that the fields no
|
|
552
|
+
* longer hold: never stored, or forgotten on reload.
|
|
553
|
+
*/
|
|
554
|
+
function warnLostSecrets(sent: string[]) {
|
|
555
|
+
const lost = lostSecrets(sent, [...headers, ...commonHeaders])
|
|
556
|
+
if (lost.length)
|
|
557
|
+
toast.add({
|
|
558
|
+
title: t('api.tester.secrets_not_kept', { names: lost.join(', ') }),
|
|
559
|
+
color: 'warning',
|
|
560
|
+
icon: 'i-ph-key',
|
|
561
|
+
})
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
function resetToExample(clearResult = false) {
|
|
565
|
+
if (!example.value) return
|
|
566
|
+
applyRequest(example.value)
|
|
567
|
+
origin.value = 'example'
|
|
568
|
+
replayInfo.value = null
|
|
569
|
+
if (clearResult) showResult(null)
|
|
570
|
+
openFirstTab()
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function currentDraft(): TesterDraft | null {
|
|
574
|
+
if (!modified.value && !result.value && !replayInfo.value) return null
|
|
575
|
+
return {
|
|
576
|
+
request: draftRequest.value,
|
|
577
|
+
origin: origin.value,
|
|
578
|
+
replay: replayInfo.value,
|
|
579
|
+
result: result.value,
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
let saveTimer: ReturnType<typeof setTimeout> | undefined
|
|
584
|
+
let saveRef: string | null = null
|
|
585
|
+
|
|
586
|
+
function flushDraft() {
|
|
587
|
+
if (saveTimer === undefined || !saveRef) return
|
|
588
|
+
clearTimeout(saveTimer)
|
|
589
|
+
saveTimer = undefined
|
|
590
|
+
saveDraft(saveRef, currentDraft())
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
watch([draftRequest, origin, replayInfo, result], () => {
|
|
594
|
+
if (!activeRef) return
|
|
595
|
+
if (saveTimer !== undefined) clearTimeout(saveTimer)
|
|
596
|
+
saveRef = activeRef
|
|
597
|
+
saveTimer = setTimeout(() => {
|
|
598
|
+
saveTimer = undefined
|
|
599
|
+
if (activeRef && saveRef === activeRef) saveDraft(activeRef, currentDraft())
|
|
600
|
+
}, DRAFT_SAVE_DELAY_MS)
|
|
601
|
+
})
|
|
602
|
+
|
|
603
|
+
watch(commonHeaders, () => saveCommonHeaders(rows(commonHeaders)), {
|
|
604
|
+
deep: true,
|
|
605
|
+
})
|
|
606
|
+
|
|
607
|
+
function loadRoute(next: string) {
|
|
608
|
+
flushDraft()
|
|
609
|
+
if (inFlight && inFlight.ref !== next) {
|
|
610
|
+
inFlight.controller.abort(ROUTE_CHANGED)
|
|
611
|
+
inFlight = null
|
|
612
|
+
sending.value = false
|
|
613
|
+
}
|
|
614
|
+
activeRef = next
|
|
615
|
+
history.value = loadHistory(next)
|
|
616
|
+
const draft = loadDraft(next)
|
|
617
|
+
if (draft) {
|
|
618
|
+
applyRequest(draft.request)
|
|
619
|
+
origin.value = draft.origin
|
|
620
|
+
replayInfo.value = draft.replay
|
|
621
|
+
showResult(draft.result)
|
|
622
|
+
openFirstTab()
|
|
623
|
+
warnLostSecrets(draft.result?.secrets ?? [])
|
|
624
|
+
} else resetToExample(true)
|
|
625
|
+
const replayId = currentRoute.query.replay
|
|
626
|
+
if (typeof replayId === 'string' && replayId) void replay(replayId, next)
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
watch(
|
|
630
|
+
() => route.value?.ref,
|
|
631
|
+
(next) => {
|
|
632
|
+
if (next) loadRoute(next)
|
|
633
|
+
},
|
|
634
|
+
{ immediate: true },
|
|
635
|
+
)
|
|
636
|
+
|
|
637
|
+
// --- Replay ---
|
|
638
|
+
|
|
639
|
+
/** Takes `?replay=` off the URL: a replay is loaded once, on its own route. */
|
|
640
|
+
function dropReplayParam() {
|
|
641
|
+
const { replay: _replay, ...rest } = currentRoute.query
|
|
642
|
+
return router.replace({ query: rest })
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
async function replay(id: string, ref: string) {
|
|
646
|
+
void dropReplayParam()
|
|
647
|
+
try {
|
|
648
|
+
const log = await $authFetch<CapturedRequest>(
|
|
649
|
+
`${LOGS_API}/${encodeURIComponent(id)}`,
|
|
650
|
+
)
|
|
651
|
+
if (activeRef !== ref) return
|
|
652
|
+
const capturedRef = log.route
|
|
653
|
+
if (capturedRef !== ref) {
|
|
654
|
+
toast.add({
|
|
655
|
+
title: t('api.tester.replay_other_route', { route: capturedRef }),
|
|
656
|
+
color: 'warning',
|
|
657
|
+
icon: 'i-ph-warning',
|
|
658
|
+
})
|
|
659
|
+
return
|
|
660
|
+
}
|
|
661
|
+
const replayed = replayFrom(log)
|
|
662
|
+
applyRequest({
|
|
663
|
+
bodyMode: replayed.bodyMode,
|
|
664
|
+
body: replayed.body,
|
|
665
|
+
form: [],
|
|
666
|
+
headers: replayed.headers,
|
|
667
|
+
query: replayed.query,
|
|
668
|
+
pathValues: replayed.pathValues,
|
|
669
|
+
useSession: example.value?.useSession ?? true,
|
|
670
|
+
})
|
|
671
|
+
origin.value = 'replay'
|
|
672
|
+
replayInfo.value = {
|
|
673
|
+
id: log._id,
|
|
674
|
+
at: log.timestamp,
|
|
675
|
+
skippedHeaders: replayed.skippedHeaders,
|
|
676
|
+
bodyMissing: replayed.bodyMissing,
|
|
677
|
+
bodyOmitted: replayed.bodyOmitted,
|
|
678
|
+
bodyTruncated: replayed.bodyTruncated,
|
|
679
|
+
}
|
|
680
|
+
showResult(null)
|
|
681
|
+
openFirstTab()
|
|
682
|
+
toast.add({
|
|
683
|
+
title: t('api.tester.replayed'),
|
|
684
|
+
color: 'info',
|
|
685
|
+
icon: 'i-ph-arrow-counter-clockwise',
|
|
686
|
+
})
|
|
687
|
+
} catch (cause) {
|
|
688
|
+
// A request pruned, outside the route scope or matching no route: the
|
|
689
|
+
// logs do not open it.
|
|
690
|
+
const missing = errorStatus(cause) === 404
|
|
691
|
+
toast.add({
|
|
692
|
+
title: t(
|
|
693
|
+
missing ? 'api.tester.replay_not_found' : 'api.tester.replay_failed',
|
|
694
|
+
),
|
|
695
|
+
color: missing ? 'warning' : 'error',
|
|
696
|
+
icon: 'i-ph-warning',
|
|
697
|
+
})
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
const replayTitle = computed(() => {
|
|
702
|
+
const info = replayInfo.value
|
|
703
|
+
if (!info) return ''
|
|
704
|
+
return [
|
|
705
|
+
t('api.tester.replay_banner.title', {
|
|
706
|
+
id: shortId(info.id),
|
|
707
|
+
at: formatClock(info.at, dateFormat.value),
|
|
708
|
+
}),
|
|
709
|
+
...(info.skippedHeaders.length
|
|
710
|
+
? [
|
|
711
|
+
t(
|
|
712
|
+
'api.tester.replay_banner.headers',
|
|
713
|
+
{ count: info.skippedHeaders.length },
|
|
714
|
+
info.skippedHeaders.length,
|
|
715
|
+
),
|
|
716
|
+
]
|
|
717
|
+
: []),
|
|
718
|
+
...(redactedCount.value
|
|
719
|
+
? [
|
|
720
|
+
t(
|
|
721
|
+
'api.tester.replay_banner.redacted',
|
|
722
|
+
{ count: redactedCount.value },
|
|
723
|
+
redactedCount.value,
|
|
724
|
+
),
|
|
725
|
+
]
|
|
726
|
+
: []),
|
|
727
|
+
...(info.bodyTruncated ? [t('api.tester.replay_banner.truncated')] : []),
|
|
728
|
+
].join(' · ')
|
|
729
|
+
})
|
|
730
|
+
const replayDescription = computed(() => {
|
|
731
|
+
const info = replayInfo.value
|
|
732
|
+
if (!info) return ''
|
|
733
|
+
return info.skippedHeaders.length
|
|
734
|
+
? t('api.tester.replay_banner.skipped', {
|
|
735
|
+
names: info.skippedHeaders.join(', '),
|
|
736
|
+
})
|
|
737
|
+
: t('api.tester.replay_banner.credentials')
|
|
738
|
+
})
|
|
739
|
+
|
|
740
|
+
// --- Sending ---
|
|
741
|
+
|
|
742
|
+
async function confirmSend(ref: string): Promise<boolean> {
|
|
743
|
+
const firstWrite = writes.value && !isDelete.value && !hasConfirmedWrite(ref)
|
|
744
|
+
const reasons: string[] = []
|
|
745
|
+
if (isDelete.value)
|
|
746
|
+
reasons.push(t('api.tester.confirm.delete', { path: path.value }))
|
|
747
|
+
else if (firstWrite)
|
|
748
|
+
reasons.push(
|
|
749
|
+
t('api.tester.confirm.write', { method: method.value, path: path.value }),
|
|
750
|
+
)
|
|
751
|
+
if (redactedCount.value)
|
|
752
|
+
reasons.push(
|
|
753
|
+
t(
|
|
754
|
+
'api.tester.confirm.redacted',
|
|
755
|
+
{ count: redactedCount.value },
|
|
756
|
+
redactedCount.value,
|
|
757
|
+
),
|
|
758
|
+
)
|
|
759
|
+
// A body cut at capture, sent untouched: the API gets part of it.
|
|
760
|
+
const truncated =
|
|
761
|
+
origin.value === 'replay' &&
|
|
762
|
+
!!replayInfo.value?.bodyTruncated &&
|
|
763
|
+
sentBody.value !== undefined
|
|
764
|
+
if (truncated) reasons.push(t('api.tester.confirm.truncated'))
|
|
765
|
+
if (reasons.length === 0) return true
|
|
766
|
+
confirming = true
|
|
767
|
+
try {
|
|
768
|
+
const confirmed = await confirm({
|
|
769
|
+
title: isDelete.value
|
|
770
|
+
? t('api.tester.confirm.delete_title')
|
|
771
|
+
: firstWrite
|
|
772
|
+
? t('api.tester.confirm.write_title')
|
|
773
|
+
: redactedCount.value
|
|
774
|
+
? t('api.tester.confirm.redacted_title')
|
|
775
|
+
: t('api.tester.confirm.truncated_title'),
|
|
776
|
+
description: reasons.join(' '),
|
|
777
|
+
color: isDelete.value ? 'error' : 'warning',
|
|
778
|
+
confirmLabel: t('api.tester.send'),
|
|
779
|
+
confirmIcon: 'i-ph-paper-plane-tilt',
|
|
780
|
+
initialFocus: 'cancel',
|
|
781
|
+
})
|
|
782
|
+
if (confirmed && firstWrite) rememberConfirmedWrite(ref)
|
|
783
|
+
return confirmed
|
|
784
|
+
} finally {
|
|
785
|
+
confirming = false
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
async function send() {
|
|
790
|
+
const value = route.value
|
|
791
|
+
if (sending.value || confirming || !value || blocker.value) return
|
|
792
|
+
const ref = value.ref
|
|
793
|
+
if (!(await confirmSend(ref))) return
|
|
794
|
+
if (activeRef !== ref || sending.value) return
|
|
795
|
+
// The signed mark that keeps the call out of the statistics: without it,
|
|
796
|
+
// the call would count as the API's own traffic, so it is not sent.
|
|
797
|
+
let source: string
|
|
798
|
+
try {
|
|
799
|
+
source = (await sourceTokens.get()).value
|
|
800
|
+
} catch {
|
|
801
|
+
toast.add({
|
|
802
|
+
title: t('api.tester.source_failed'),
|
|
803
|
+
color: 'error',
|
|
804
|
+
icon: 'i-ph-warning',
|
|
805
|
+
})
|
|
806
|
+
return
|
|
807
|
+
}
|
|
808
|
+
if (activeRef !== ref || sending.value) return
|
|
809
|
+
const requestId = newRequestId()
|
|
810
|
+
const sentPath = path.value
|
|
811
|
+
const snapshot = draftRequest.value
|
|
812
|
+
const sentAuth = auth.value
|
|
813
|
+
const outgoing: TesterRequest = {
|
|
814
|
+
...request.value,
|
|
815
|
+
headers: markedHeaders(request.value.headers, requestId, source),
|
|
816
|
+
}
|
|
817
|
+
const controller = new AbortController()
|
|
818
|
+
inFlight = { controller, ref }
|
|
819
|
+
sending.value = true
|
|
820
|
+
const at = Date.now()
|
|
821
|
+
const started = performance.now()
|
|
822
|
+
const sentSecrets = secretNames(outgoing.headers)
|
|
823
|
+
const common = {
|
|
824
|
+
auth: sentAuth,
|
|
825
|
+
...(sentSecrets.length ? { secrets: sentSecrets } : {}),
|
|
826
|
+
requestId,
|
|
827
|
+
at,
|
|
828
|
+
}
|
|
829
|
+
let outcome: TesterResult
|
|
830
|
+
try {
|
|
831
|
+
const answer = await sendTesterRequest(
|
|
832
|
+
sentPath,
|
|
833
|
+
window.location.origin,
|
|
834
|
+
outgoing,
|
|
835
|
+
controller.signal,
|
|
836
|
+
)
|
|
837
|
+
outcome = {
|
|
838
|
+
...answer,
|
|
839
|
+
bodySize: byteLength(answer.body),
|
|
840
|
+
durationMs: Math.round(performance.now() - started),
|
|
841
|
+
...common,
|
|
842
|
+
}
|
|
843
|
+
} catch (cause) {
|
|
844
|
+
outcome = {
|
|
845
|
+
status: 0,
|
|
846
|
+
durationMs: Math.round(performance.now() - started),
|
|
847
|
+
headers: {},
|
|
848
|
+
body: '',
|
|
849
|
+
error: cause instanceof TesterError ? cause.code : 'unexpected',
|
|
850
|
+
message: cause instanceof Error ? cause.message : String(cause),
|
|
851
|
+
...common,
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
if (inFlight?.controller === controller) {
|
|
855
|
+
inFlight = null
|
|
856
|
+
sending.value = false
|
|
857
|
+
}
|
|
858
|
+
// An answer already in hand when the route changed is filed as it came.
|
|
859
|
+
if (controller.signal.reason === ROUTE_CHANGED && outcome.error)
|
|
860
|
+
outcome = { ...outcome, error: 'aborted', abandoned: true }
|
|
861
|
+
commit(ref, value.method, sentPath, snapshot, outcome)
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
function cancel() {
|
|
865
|
+
inFlight?.controller.abort()
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
/**
|
|
869
|
+
* Files a finished call under the route that sent it: its history, and the
|
|
870
|
+
* screen if it still shows that route, else its draft. A call cancelled from
|
|
871
|
+
* the screen stays off the history; one abandoned by a route change is kept,
|
|
872
|
+
* as the API may have received it.
|
|
873
|
+
*/
|
|
874
|
+
function commit(
|
|
875
|
+
ref: string,
|
|
876
|
+
sentMethod: string,
|
|
877
|
+
sentPath: string,
|
|
878
|
+
snapshot: DraftRequest,
|
|
879
|
+
outcome: TesterResult,
|
|
880
|
+
) {
|
|
881
|
+
const shown = !unmounted && activeRef === ref
|
|
882
|
+
if (outcome.error !== 'aborted' || outcome.abandoned) {
|
|
883
|
+
const entry = historyEntry(sentMethod, sentPath, snapshot, outcome)
|
|
884
|
+
const list = [entry, ...(shown ? history.value : loadHistory(ref))].slice(
|
|
885
|
+
0,
|
|
886
|
+
HISTORY_MAX,
|
|
887
|
+
)
|
|
888
|
+
if (shown) history.value = list
|
|
889
|
+
saveHistory(ref, list)
|
|
890
|
+
}
|
|
891
|
+
if (!shown) {
|
|
892
|
+
const draft = loadDraft(ref)
|
|
893
|
+
saveDraft(ref, {
|
|
894
|
+
...(draft ?? { request: snapshot, origin: 'example', replay: null }),
|
|
895
|
+
result: outcome,
|
|
896
|
+
})
|
|
897
|
+
return
|
|
898
|
+
}
|
|
899
|
+
showResult(outcome, true)
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
// --- What the module captured of the call ---
|
|
903
|
+
|
|
904
|
+
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
905
|
+
|
|
906
|
+
async function findCaptured(
|
|
907
|
+
target: TesterResult,
|
|
908
|
+
): Promise<CapturedRequest | null> {
|
|
909
|
+
const id = target.requestId as string
|
|
910
|
+
const page = await $authFetch<{ results: CapturedRow[] }>(
|
|
911
|
+
`${LOGS_API}?${new URLSearchParams({ requestId: id })}`,
|
|
912
|
+
)
|
|
913
|
+
// Only the call sent: a list that ignored the filter is no answer.
|
|
914
|
+
const matches = page.results.filter((item) =>
|
|
915
|
+
item.requestId === undefined
|
|
916
|
+
? page.results.length === 1
|
|
917
|
+
: item.requestId === id,
|
|
918
|
+
)
|
|
919
|
+
const found = matches[0]
|
|
920
|
+
if (
|
|
921
|
+
!found ||
|
|
922
|
+
Date.parse(found.timestamp) < target.at - CAPTURE_MATCH_MS ||
|
|
923
|
+
(found.route && activeRef && found.route !== activeRef)
|
|
924
|
+
)
|
|
925
|
+
return null
|
|
926
|
+
return $authFetch<CapturedRequest>(
|
|
927
|
+
`${LOGS_API}/${encodeURIComponent(found._id)}`,
|
|
928
|
+
)
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
async function lookUpCaptured(target: TesterResult, retry: boolean) {
|
|
932
|
+
const id = target.requestId
|
|
933
|
+
if (!id) return
|
|
934
|
+
capturedState.value = 'loading'
|
|
935
|
+
for (const delay of retry ? CAPTURE_DELAYS_MS : [0]) {
|
|
936
|
+
if (delay) await wait(delay)
|
|
937
|
+
if (result.value?.requestId !== id) return
|
|
938
|
+
try {
|
|
939
|
+
const log = await findCaptured(target)
|
|
940
|
+
if (result.value?.requestId !== id) return
|
|
941
|
+
if (log) {
|
|
942
|
+
capturedLog.value = log
|
|
943
|
+
capturedState.value = 'found'
|
|
944
|
+
keepCaptured(id, log)
|
|
945
|
+
return
|
|
946
|
+
}
|
|
947
|
+
} catch {
|
|
948
|
+
if (result.value?.requestId === id) capturedState.value = 'error'
|
|
949
|
+
return
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
capturedState.value = 'missing'
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
/**
|
|
956
|
+
* Keeps what the module captured of a call with its answer, on screen, in
|
|
957
|
+
* the draft and in the history: its server time and its record survive a
|
|
958
|
+
* return to the route. A 502 of the proxy for a call the module captured is
|
|
959
|
+
* the API answering more than the proxy returns.
|
|
960
|
+
*/
|
|
961
|
+
function keepCaptured(id: string, log: CapturedRequest) {
|
|
962
|
+
const value = result.value
|
|
963
|
+
if (value?.requestId !== id) return
|
|
964
|
+
if (value.captured && value.error !== 'proxy_failed') return
|
|
965
|
+
const patch: Partial<TesterResult> = {
|
|
966
|
+
captured: capturedSummary(log),
|
|
967
|
+
...(value.error === 'proxy_failed'
|
|
968
|
+
? { error: 'response_too_large' as const }
|
|
969
|
+
: {}),
|
|
970
|
+
}
|
|
971
|
+
result.value = { ...value, ...patch }
|
|
972
|
+
if (!activeRef) return
|
|
973
|
+
history.value = patchResult(history.value, id, patch)
|
|
974
|
+
saveHistory(activeRef, history.value)
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
/**
|
|
978
|
+
* Shows an answer, on its Captured tab when it failed. What the module
|
|
979
|
+
* captured is looked up for a call just made, for an answer restored before
|
|
980
|
+
* it was found (its server time and record), and when that tab is open.
|
|
981
|
+
*/
|
|
982
|
+
function showResult(value: TesterResult | null, fresh = false) {
|
|
983
|
+
result.value = value
|
|
984
|
+
capturedState.value = 'idle'
|
|
985
|
+
capturedLog.value = null
|
|
986
|
+
responseTab.value =
|
|
987
|
+
value?.error && capturedAvailable.value ? 'captured' : 'body'
|
|
988
|
+
if (
|
|
989
|
+
value &&
|
|
990
|
+
capturedAvailable.value &&
|
|
991
|
+
(fresh || responseTab.value === 'captured' || !value.captured)
|
|
992
|
+
)
|
|
993
|
+
void lookUpCaptured(value, fresh)
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
watch(responseTab, (value) => {
|
|
997
|
+
if (value === 'captured' && capturedState.value === 'idle' && result.value)
|
|
998
|
+
void lookUpCaptured(result.value, false)
|
|
999
|
+
})
|
|
1000
|
+
|
|
1001
|
+
const capturedSlow = computed(() => !!result.value?.captured?.slow)
|
|
1002
|
+
|
|
1003
|
+
// --- History ---
|
|
1004
|
+
|
|
1005
|
+
function restore(entry: HistoryEntry) {
|
|
1006
|
+
applyRequest(entry.request)
|
|
1007
|
+
origin.value = 'history'
|
|
1008
|
+
replayInfo.value = null
|
|
1009
|
+
showResult(entry.result)
|
|
1010
|
+
warnLostSecrets([
|
|
1011
|
+
...(entry.secretsRemoved ?? []),
|
|
1012
|
+
...(entry.result.secrets ?? []),
|
|
1013
|
+
])
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
function clearHistory() {
|
|
1017
|
+
const ref = activeRef
|
|
1018
|
+
if (!ref) return
|
|
1019
|
+
const cleared = history.value
|
|
1020
|
+
history.value = []
|
|
1021
|
+
saveHistory(ref, [])
|
|
1022
|
+
toast.add({
|
|
1023
|
+
title: t(
|
|
1024
|
+
'api.tester.history_cleared',
|
|
1025
|
+
{ count: cleared.length },
|
|
1026
|
+
cleared.length,
|
|
1027
|
+
),
|
|
1028
|
+
color: 'neutral',
|
|
1029
|
+
icon: 'i-ph-trash',
|
|
1030
|
+
actions: [
|
|
1031
|
+
{
|
|
1032
|
+
label: t('api.tester.undo'),
|
|
1033
|
+
color: 'neutral',
|
|
1034
|
+
variant: 'outline',
|
|
1035
|
+
onClick: () => {
|
|
1036
|
+
const merged = [...loadHistory(ref), ...cleared].slice(0, HISTORY_MAX)
|
|
1037
|
+
saveHistory(ref, merged)
|
|
1038
|
+
if (activeRef === ref) history.value = merged
|
|
1039
|
+
},
|
|
1040
|
+
},
|
|
1041
|
+
],
|
|
1042
|
+
})
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
// --- Copy cURL ---
|
|
1046
|
+
|
|
1047
|
+
function curl(): string {
|
|
1048
|
+
const search: Record<string, string | string[]> = {}
|
|
1049
|
+
for (const { name, value } of query) {
|
|
1050
|
+
if (!name) continue
|
|
1051
|
+
const known = search[name]
|
|
1052
|
+
search[name] = known === undefined ? value : [...[known].flat(), value]
|
|
1053
|
+
}
|
|
1054
|
+
return toCurl({
|
|
1055
|
+
method: method.value,
|
|
1056
|
+
path: route.value?.path ?? '/',
|
|
1057
|
+
origin: apiOrigin.value,
|
|
1058
|
+
pathParams: { ...pathValues },
|
|
1059
|
+
query: search,
|
|
1060
|
+
headers: effectiveHeaders.value,
|
|
1061
|
+
body: sentBody.value,
|
|
1062
|
+
session: auth.value === 'session',
|
|
1063
|
+
})
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
async function copyCurl() {
|
|
1067
|
+
try {
|
|
1068
|
+
await navigator.clipboard.writeText(curl())
|
|
1069
|
+
toast.add({
|
|
1070
|
+
title: t('api.request.curl_copied'),
|
|
1071
|
+
color: 'success',
|
|
1072
|
+
icon: 'i-ph-check',
|
|
1073
|
+
})
|
|
1074
|
+
} catch {
|
|
1075
|
+
toast.add({
|
|
1076
|
+
title: t('api.request.copy_failed'),
|
|
1077
|
+
color: 'error',
|
|
1078
|
+
icon: 'i-ph-warning',
|
|
1079
|
+
})
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
/** What the user typed in the body editor (not a body loaded into it). */
|
|
1084
|
+
function editBody(value: string | null | undefined) {
|
|
1085
|
+
const next = value ?? ''
|
|
1086
|
+
if (next === body.value) return
|
|
1087
|
+
body.value = next
|
|
1088
|
+
origin.value = 'edited'
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
function formatBody() {
|
|
1092
|
+
if (formattedBody.value === null) return
|
|
1093
|
+
body.value = formattedBody.value
|
|
1094
|
+
origin.value = 'edited'
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
// --- Keyboard ---
|
|
1098
|
+
|
|
1099
|
+
/**
|
|
1100
|
+
* Ctrl/Cmd+Enter sends from a field of the tester only, never from the rest
|
|
1101
|
+
* of the page (the route filter, the command palette); `send` still asks
|
|
1102
|
+
* before a write it has not confirmed.
|
|
1103
|
+
*/
|
|
1104
|
+
function onKey(event: KeyboardEvent) {
|
|
1105
|
+
if (event.key !== 'Enter' || !(event.metaKey || event.ctrlKey)) return
|
|
1106
|
+
if (event.isComposing) return
|
|
1107
|
+
event.preventDefault()
|
|
1108
|
+
void send()
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
// --- Live hold ---
|
|
1112
|
+
|
|
1113
|
+
const FIELD_SELECTOR = 'input, textarea, select, [contenteditable="true"]'
|
|
1114
|
+
const live = usePageLive()
|
|
1115
|
+
|
|
1116
|
+
function onFocusIn(event: FocusEvent) {
|
|
1117
|
+
const target = event.target as HTMLElement | null
|
|
1118
|
+
if (target?.closest(FIELD_SELECTOR))
|
|
1119
|
+
live.hold('$api.live_mode.typing_in_tester')
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
// Held while the focus stays in the Tester (a field, Send), released once it
|
|
1123
|
+
// leaves; the DMS releases it with the component too.
|
|
1124
|
+
function onFocusOut(event: FocusEvent) {
|
|
1125
|
+
const root = event.currentTarget as HTMLElement
|
|
1126
|
+
const next = event.relatedTarget as Node | null
|
|
1127
|
+
if (next && root.contains(next)) return
|
|
1128
|
+
live.release()
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
onBeforeUnmount(() => {
|
|
1132
|
+
flushDraft()
|
|
1133
|
+
// A call in flight still lands in its route's history and draft.
|
|
1134
|
+
unmounted = true
|
|
1135
|
+
})
|
|
1136
|
+
|
|
1137
|
+
// --- Answer ---
|
|
1138
|
+
|
|
1139
|
+
const responseBody = computed(() => prettyBody(result.value?.body))
|
|
1140
|
+
const responseSize = computed(() =>
|
|
1141
|
+
result.value ? (result.value.bodySize ?? byteLength(result.value.body)) : 0,
|
|
1142
|
+
)
|
|
1143
|
+
function recordLink(id: string): string {
|
|
1144
|
+
return `${LOGS_PAGE}?${new URLSearchParams({ record: id })}`
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
/** A path as it reads: decoded, its bidirectional controls shown. */
|
|
1148
|
+
function readable(value: string): string {
|
|
1149
|
+
try {
|
|
1150
|
+
return revealBidi(decodeURI(value))
|
|
1151
|
+
} catch {
|
|
1152
|
+
return revealBidi(value)
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
/**
|
|
1157
|
+
* The captured call, else the route's logs: only for a route the module
|
|
1158
|
+
* captures and the active scope shows (the logs list is scoped).
|
|
1159
|
+
*/
|
|
1160
|
+
const logsLink = computed(() => {
|
|
1161
|
+
const id = result.value?.captured?.id
|
|
1162
|
+
if (id) return recordLink(id)
|
|
1163
|
+
return route.value && routeCaptured.value && route.value.inScope !== false
|
|
1164
|
+
? `${LOGS_PAGE}?${new URLSearchParams({ route: route.value.ref })}`
|
|
1165
|
+
: ''
|
|
1166
|
+
})
|
|
1167
|
+
const errorCopy = computed(() => {
|
|
1168
|
+
const value = result.value
|
|
1169
|
+
if (!value?.error) return null
|
|
1170
|
+
const code = value.abandoned ? 'abandoned' : value.error
|
|
1171
|
+
const params = {
|
|
1172
|
+
limit: formatBytes(PROXY_RESPONSE_LIMIT, locale.value),
|
|
1173
|
+
seconds: PROXY_TIMEOUT_MS / 1000,
|
|
1174
|
+
status: value.captured?.status ?? '',
|
|
1175
|
+
message: value.message ?? '',
|
|
1176
|
+
}
|
|
1177
|
+
const description =
|
|
1178
|
+
!routeCaptured.value && POINTS_TO_CAPTURED.has(code)
|
|
1179
|
+
? 'description_uncaptured'
|
|
1180
|
+
: 'description'
|
|
1181
|
+
return {
|
|
1182
|
+
title: t(`api.tester.errors.${code}.title`, params),
|
|
1183
|
+
description: t(`api.tester.errors.${code}.${description}`, params),
|
|
1184
|
+
icon: ERROR_ICONS[value.error] ?? 'i-ph-plugs',
|
|
1185
|
+
}
|
|
1186
|
+
})
|
|
1187
|
+
const liveMessage = computed(() => {
|
|
1188
|
+
const value = result.value
|
|
1189
|
+
if (sending.value || !value) return ''
|
|
1190
|
+
if (errorCopy.value)
|
|
1191
|
+
return t('api.tester.live.failed', { title: errorCopy.value.title })
|
|
1192
|
+
return t('api.tester.live.sent', {
|
|
1193
|
+
status: value.status,
|
|
1194
|
+
text: statusText(value.status),
|
|
1195
|
+
duration: formatMs(value.durationMs, locale.value),
|
|
1196
|
+
})
|
|
1197
|
+
})
|
|
1198
|
+
const shortcut = computed(() =>
|
|
1199
|
+
typeof navigator !== 'undefined' && /Mac|iP/.test(navigator.platform)
|
|
1200
|
+
? '⌘'
|
|
1201
|
+
: 'Ctrl',
|
|
1202
|
+
)
|
|
1203
|
+
</script>
|
|
1204
|
+
|
|
1205
|
+
<template>
|
|
1206
|
+
<div v-if="!selection.ref.value" />
|
|
1207
|
+
<USkeleton v-else-if="pending" class="h-72" />
|
|
1208
|
+
<div
|
|
1209
|
+
v-else-if="route"
|
|
1210
|
+
class="flex flex-col gap-4"
|
|
1211
|
+
@keydown.capture="onKey"
|
|
1212
|
+
@focusin="onFocusIn"
|
|
1213
|
+
@focusout="onFocusOut"
|
|
1214
|
+
>
|
|
1215
|
+
<DmsCard :padded="false">
|
|
1216
|
+
<!-- The method and the path keep a line of their own when the card is
|
|
1217
|
+
narrow: the buttons go under them, and a long path wraps. -->
|
|
1218
|
+
<div class="flex flex-wrap items-center gap-x-3 gap-y-2 px-4 py-3">
|
|
1219
|
+
<div class="flex min-w-0 grow basis-80 items-center gap-3">
|
|
1220
|
+
<ApiMethodBadge :method="route.method" solid class="shrink-0" />
|
|
1221
|
+
<div
|
|
1222
|
+
class="text-highlighted flex min-w-0 grow flex-wrap items-center gap-y-1 font-mono text-[13px]"
|
|
1223
|
+
:title="readable(path)"
|
|
1224
|
+
>
|
|
1225
|
+
<template v-for="(segment, index) in segments" :key="index">
|
|
1226
|
+
<input
|
|
1227
|
+
v-if="segment.param"
|
|
1228
|
+
v-model="pathValues[segment.name]"
|
|
1229
|
+
type="text"
|
|
1230
|
+
spellcheck="false"
|
|
1231
|
+
:placeholder="segment.text"
|
|
1232
|
+
:aria-label="t('api.tester.path_param', { name: segment.text })"
|
|
1233
|
+
:aria-invalid="!pathValues[segment.name]"
|
|
1234
|
+
:title="
|
|
1235
|
+
hasRedacted(pathValues[segment.name])
|
|
1236
|
+
? t('api.tester.redacted_value')
|
|
1237
|
+
: undefined
|
|
1238
|
+
"
|
|
1239
|
+
class="bg-elevated focus:ring-primary mx-0.5 min-w-[4ch] max-w-full rounded px-1 py-0.5 outline-none focus:ring-2"
|
|
1240
|
+
:class="
|
|
1241
|
+
!pathValues[segment.name]
|
|
1242
|
+
? 'ring-error/60 placeholder:text-error/70 ring-1'
|
|
1243
|
+
: hasRedacted(pathValues[segment.name])
|
|
1244
|
+
? 'ring-warning ring-1'
|
|
1245
|
+
: ''
|
|
1246
|
+
"
|
|
1247
|
+
:style="{
|
|
1248
|
+
width: `${Math.min(28, Math.max(segment.text.length, (pathValues[segment.name] ?? '').length) + 2)}ch`,
|
|
1249
|
+
}"
|
|
1250
|
+
/>
|
|
1251
|
+
<span v-else class="min-w-0 break-all">{{ segment.text }}</span>
|
|
1252
|
+
</template>
|
|
1253
|
+
<span v-if="displayQuery" class="text-muted min-w-0 break-all">
|
|
1254
|
+
{{ displayQuery }}
|
|
1255
|
+
</span>
|
|
1256
|
+
</div>
|
|
1257
|
+
</div>
|
|
1258
|
+
<div class="ms-auto flex flex-wrap items-center justify-end gap-2">
|
|
1259
|
+
<UButton
|
|
1260
|
+
size="sm"
|
|
1261
|
+
color="neutral"
|
|
1262
|
+
variant="outline"
|
|
1263
|
+
icon="i-ph-terminal"
|
|
1264
|
+
:label="t('api.request.copy_curl')"
|
|
1265
|
+
@click="copyCurl"
|
|
1266
|
+
/>
|
|
1267
|
+
<UButton
|
|
1268
|
+
v-if="sending"
|
|
1269
|
+
size="sm"
|
|
1270
|
+
color="neutral"
|
|
1271
|
+
variant="soft"
|
|
1272
|
+
icon="i-ph-x"
|
|
1273
|
+
:label="t('dms.confirm.cancel')"
|
|
1274
|
+
@click="cancel"
|
|
1275
|
+
/>
|
|
1276
|
+
<UButton
|
|
1277
|
+
size="sm"
|
|
1278
|
+
icon="i-ph-paper-plane-tilt"
|
|
1279
|
+
:loading="sending"
|
|
1280
|
+
:disabled="!!blocker"
|
|
1281
|
+
:label="t('api.tester.send')"
|
|
1282
|
+
aria-keyshortcuts="Control+Enter Meta+Enter"
|
|
1283
|
+
:aria-describedby="blocker ? blockerId : undefined"
|
|
1284
|
+
@click="send"
|
|
1285
|
+
>
|
|
1286
|
+
<template #trailing>
|
|
1287
|
+
<span class="hidden gap-0.5 sm:flex" aria-hidden="true">
|
|
1288
|
+
<UKbd :value="shortcut" size="sm" />
|
|
1289
|
+
<UKbd value="↵" size="sm" />
|
|
1290
|
+
</span>
|
|
1291
|
+
</template>
|
|
1292
|
+
</UButton>
|
|
1293
|
+
</div>
|
|
1294
|
+
</div>
|
|
1295
|
+
<div
|
|
1296
|
+
class="border-default flex flex-wrap items-center gap-x-3 gap-y-1.5 border-t px-4 py-2.5 text-[12.5px]"
|
|
1297
|
+
>
|
|
1298
|
+
<label class="flex cursor-pointer items-center gap-2">
|
|
1299
|
+
<USwitch v-model="useSession" size="sm" :disabled="!loggedIn" />
|
|
1300
|
+
<span class="text-default">{{ t('api.tester.session') }}</span>
|
|
1301
|
+
</label>
|
|
1302
|
+
<span
|
|
1303
|
+
class="inline-flex items-center gap-1"
|
|
1304
|
+
:class="auth === 'manual' ? 'text-warning' : 'text-dimmed'"
|
|
1305
|
+
>
|
|
1306
|
+
<UIcon :name="AUTH_ICONS[auth]" class="size-3.5 shrink-0" />
|
|
1307
|
+
{{ authLabel }}
|
|
1308
|
+
</span>
|
|
1309
|
+
<span class="grow" />
|
|
1310
|
+
<span
|
|
1311
|
+
v-if="blocker"
|
|
1312
|
+
:id="blockerId"
|
|
1313
|
+
class="text-error inline-flex items-center gap-1"
|
|
1314
|
+
>
|
|
1315
|
+
<UIcon name="i-ph-warning-circle" class="size-3.5 shrink-0" />
|
|
1316
|
+
{{ blocker }}
|
|
1317
|
+
</span>
|
|
1318
|
+
<!-- The trigger is a plain element: the DMS components load
|
|
1319
|
+
asynchronously, and a tooltip anchored on one still loading
|
|
1320
|
+
reads an element it does not have yet (a direct load of the
|
|
1321
|
+
tab crashed on it). -->
|
|
1322
|
+
<UTooltip v-if="writes" :text="t('api.tester.writes_hint')">
|
|
1323
|
+
<span class="inline-flex rounded-full" tabindex="0">
|
|
1324
|
+
<DmsStatusPill
|
|
1325
|
+
tone="warning"
|
|
1326
|
+
icon="i-ph-warning"
|
|
1327
|
+
:mono="false"
|
|
1328
|
+
:label="t('api.tester.writes')"
|
|
1329
|
+
/>
|
|
1330
|
+
</span>
|
|
1331
|
+
</UTooltip>
|
|
1332
|
+
</div>
|
|
1333
|
+
<div v-if="replayInfo" class="border-default border-t px-4 py-2.5">
|
|
1334
|
+
<DmsBanner
|
|
1335
|
+
tone="info"
|
|
1336
|
+
size="sm"
|
|
1337
|
+
icon="i-ph-arrow-counter-clockwise"
|
|
1338
|
+
:title="replayTitle"
|
|
1339
|
+
:description="replayDescription"
|
|
1340
|
+
dismissible
|
|
1341
|
+
@dismiss="replayInfo = null"
|
|
1342
|
+
>
|
|
1343
|
+
<template #actions>
|
|
1344
|
+
<UButton
|
|
1345
|
+
:to="recordLink(replayInfo.id)"
|
|
1346
|
+
size="xs"
|
|
1347
|
+
color="neutral"
|
|
1348
|
+
variant="outline"
|
|
1349
|
+
:label="t('api.tester.replay_banner.open')"
|
|
1350
|
+
/>
|
|
1351
|
+
</template>
|
|
1352
|
+
</DmsBanner>
|
|
1353
|
+
</div>
|
|
1354
|
+
</DmsCard>
|
|
1355
|
+
|
|
1356
|
+
<div class="grid gap-4 xl:grid-cols-2 xl:items-start">
|
|
1357
|
+
<DmsCard :padded="false" class="@container min-w-0">
|
|
1358
|
+
<div
|
|
1359
|
+
class="border-default flex flex-wrap items-center gap-x-2 border-b px-3"
|
|
1360
|
+
>
|
|
1361
|
+
<!-- overflow-x-auto alone turns overflow-y to auto: the active
|
|
1362
|
+
tab's underline would show a scrollbar. -->
|
|
1363
|
+
<UTabs
|
|
1364
|
+
v-model="tab"
|
|
1365
|
+
:items="tabs"
|
|
1366
|
+
:content="false"
|
|
1367
|
+
variant="link"
|
|
1368
|
+
size="sm"
|
|
1369
|
+
class="min-w-0 grow overflow-x-auto overflow-y-hidden"
|
|
1370
|
+
/>
|
|
1371
|
+
<template v-if="modified">
|
|
1372
|
+
<span class="text-dimmed inline-flex items-center gap-1.5 text-xs">
|
|
1373
|
+
<span
|
|
1374
|
+
class="bg-warning size-1.5 rounded-full"
|
|
1375
|
+
aria-hidden="true"
|
|
1376
|
+
/>
|
|
1377
|
+
{{ t('api.tester.draft_modified') }}
|
|
1378
|
+
</span>
|
|
1379
|
+
<UButton
|
|
1380
|
+
size="xs"
|
|
1381
|
+
color="neutral"
|
|
1382
|
+
variant="ghost"
|
|
1383
|
+
icon="i-ph-arrow-counter-clockwise"
|
|
1384
|
+
:label="t('api.tester.reset')"
|
|
1385
|
+
@click="resetToExample()"
|
|
1386
|
+
/>
|
|
1387
|
+
</template>
|
|
1388
|
+
</div>
|
|
1389
|
+
<div class="p-3">
|
|
1390
|
+
<div
|
|
1391
|
+
v-if="tab === 'body' && bodyAllowed"
|
|
1392
|
+
class="mb-2 flex flex-wrap items-center gap-2"
|
|
1393
|
+
>
|
|
1394
|
+
<USelect
|
|
1395
|
+
v-model="bodyMode"
|
|
1396
|
+
:items="bodyModeItems"
|
|
1397
|
+
size="xs"
|
|
1398
|
+
class="w-36"
|
|
1399
|
+
:aria-label="t('api.tester.body_mode')"
|
|
1400
|
+
/>
|
|
1401
|
+
<span class="grow" />
|
|
1402
|
+
<UButton
|
|
1403
|
+
v-if="bodyMode === 'json'"
|
|
1404
|
+
size="xs"
|
|
1405
|
+
color="neutral"
|
|
1406
|
+
variant="outline"
|
|
1407
|
+
icon="i-ph-brackets-curly"
|
|
1408
|
+
:disabled="formattedBody === null || formattedBody === body"
|
|
1409
|
+
:label="t('api.tester.format')"
|
|
1410
|
+
@click="formatBody"
|
|
1411
|
+
/>
|
|
1412
|
+
</div>
|
|
1413
|
+
|
|
1414
|
+
<template
|
|
1415
|
+
v-if="
|
|
1416
|
+
tab === 'body' &&
|
|
1417
|
+
bodyAllowed &&
|
|
1418
|
+
(bodyMode === 'json' || bodyMode === 'text')
|
|
1419
|
+
"
|
|
1420
|
+
>
|
|
1421
|
+
<DmsInputCode
|
|
1422
|
+
:key="bodyMode"
|
|
1423
|
+
:model-value="body"
|
|
1424
|
+
:language="bodyMode === 'json' ? 'json' : 'text'"
|
|
1425
|
+
:min-lines="12"
|
|
1426
|
+
:max-lines="24"
|
|
1427
|
+
:aria-describedby="bodyHintId"
|
|
1428
|
+
@update:model-value="editBody"
|
|
1429
|
+
/>
|
|
1430
|
+
</template>
|
|
1431
|
+
|
|
1432
|
+
<div
|
|
1433
|
+
v-else-if="tab !== 'body' || (bodyAllowed && bodyMode === 'form')"
|
|
1434
|
+
class="flex flex-col gap-4"
|
|
1435
|
+
>
|
|
1436
|
+
<div
|
|
1437
|
+
v-if="tab === 'headers' && shownImpliedHeaders.length"
|
|
1438
|
+
class="text-dimmed flex flex-col gap-1 font-mono text-xs"
|
|
1439
|
+
>
|
|
1440
|
+
<span v-for="[name, value] in shownImpliedHeaders" :key="name">
|
|
1441
|
+
{{ name }}: {{ value }}
|
|
1442
|
+
<span class="font-sans">
|
|
1443
|
+
· {{ t('api.tester.implied_header') }}
|
|
1444
|
+
</span>
|
|
1445
|
+
</span>
|
|
1446
|
+
</div>
|
|
1447
|
+
<div
|
|
1448
|
+
v-for="editor in editors"
|
|
1449
|
+
:key="editor.key"
|
|
1450
|
+
class="@sm:gap-2 flex flex-col gap-3"
|
|
1451
|
+
>
|
|
1452
|
+
<p
|
|
1453
|
+
v-if="editor.title"
|
|
1454
|
+
class="text-default border-default border-t pt-3 text-xs font-medium"
|
|
1455
|
+
>
|
|
1456
|
+
{{ editor.title }}
|
|
1457
|
+
</p>
|
|
1458
|
+
<!-- In a narrow card the name takes a line of its own, the
|
|
1459
|
+
value and its button the next: a name is never cut. -->
|
|
1460
|
+
<div
|
|
1461
|
+
v-for="(entry, index) in editor.list"
|
|
1462
|
+
:key="entry.id"
|
|
1463
|
+
class="@sm:flex-nowrap flex flex-wrap gap-2"
|
|
1464
|
+
>
|
|
1465
|
+
<UInput
|
|
1466
|
+
v-model="entry.name"
|
|
1467
|
+
size="sm"
|
|
1468
|
+
class="@sm:w-2/5 w-full font-mono"
|
|
1469
|
+
:placeholder="t('dms.form.key_value.key')"
|
|
1470
|
+
:aria-label="t('dms.form.key_value.key')"
|
|
1471
|
+
/>
|
|
1472
|
+
<UInput
|
|
1473
|
+
v-model="entry.value"
|
|
1474
|
+
size="sm"
|
|
1475
|
+
class="min-w-0 flex-1 font-mono"
|
|
1476
|
+
:placeholder="t('dms.form.key_value.value')"
|
|
1477
|
+
:aria-label="t('dms.form.key_value.value')"
|
|
1478
|
+
:color="hasRedacted(entry.value) ? 'warning' : undefined"
|
|
1479
|
+
:highlight="hasRedacted(entry.value)"
|
|
1480
|
+
:title="
|
|
1481
|
+
hasRedacted(entry.value)
|
|
1482
|
+
? t('api.tester.redacted_value')
|
|
1483
|
+
: undefined
|
|
1484
|
+
"
|
|
1485
|
+
/>
|
|
1486
|
+
<UButton
|
|
1487
|
+
size="sm"
|
|
1488
|
+
color="neutral"
|
|
1489
|
+
variant="ghost"
|
|
1490
|
+
icon="i-ph-x"
|
|
1491
|
+
:aria-label="t('api.tester.remove')"
|
|
1492
|
+
@click="editor.list.splice(index, 1)"
|
|
1493
|
+
/>
|
|
1494
|
+
</div>
|
|
1495
|
+
<div>
|
|
1496
|
+
<UButton
|
|
1497
|
+
size="xs"
|
|
1498
|
+
color="neutral"
|
|
1499
|
+
variant="outline"
|
|
1500
|
+
icon="i-ph-plus"
|
|
1501
|
+
:label="editor.add"
|
|
1502
|
+
@click="editor.list.push(row())"
|
|
1503
|
+
/>
|
|
1504
|
+
</div>
|
|
1505
|
+
<p v-if="editor.hint" class="text-dimmed text-xs">
|
|
1506
|
+
{{ editor.hint }}
|
|
1507
|
+
</p>
|
|
1508
|
+
<p
|
|
1509
|
+
v-if="editor.warning"
|
|
1510
|
+
class="text-warning inline-flex items-start gap-1 text-xs"
|
|
1511
|
+
>
|
|
1512
|
+
<UIcon name="i-ph-key" class="mt-px size-3.5 shrink-0" />
|
|
1513
|
+
{{ editor.warning }}
|
|
1514
|
+
</p>
|
|
1515
|
+
</div>
|
|
1516
|
+
<p v-if="tab !== 'body'" class="text-dimmed text-xs">
|
|
1517
|
+
<template v-if="tab === 'headers'">
|
|
1518
|
+
{{ t('api.tester.headers_hint') }}
|
|
1519
|
+
{{ t('api.tester.marks_hint') }}
|
|
1520
|
+
</template>
|
|
1521
|
+
<template v-else-if="tab === 'query'">{{ queryHint }}</template>
|
|
1522
|
+
</p>
|
|
1523
|
+
</div>
|
|
1524
|
+
|
|
1525
|
+
<template v-if="tab === 'body' && bodyAllowed">
|
|
1526
|
+
<p v-if="jsonWarning" class="text-warning mt-1.5 text-xs">
|
|
1527
|
+
{{ t('api.tester.json_warning', { message: jsonWarning }) }}
|
|
1528
|
+
</p>
|
|
1529
|
+
<p
|
|
1530
|
+
v-if="redactedBodyFields.length"
|
|
1531
|
+
class="text-warning mt-1.5 text-xs"
|
|
1532
|
+
>
|
|
1533
|
+
{{
|
|
1534
|
+
t(
|
|
1535
|
+
'api.tester.body_redacted',
|
|
1536
|
+
{
|
|
1537
|
+
count: redactedBodyFields.length,
|
|
1538
|
+
names: redactedBodyFields.join(', '),
|
|
1539
|
+
},
|
|
1540
|
+
redactedBodyFields.length,
|
|
1541
|
+
)
|
|
1542
|
+
}}
|
|
1543
|
+
</p>
|
|
1544
|
+
<p
|
|
1545
|
+
v-if="bodyHint.text"
|
|
1546
|
+
:id="bodyHintId"
|
|
1547
|
+
class="mt-1.5 text-xs"
|
|
1548
|
+
:class="
|
|
1549
|
+
bodyHint.tone === 'warning' ? 'text-warning' : 'text-dimmed'
|
|
1550
|
+
"
|
|
1551
|
+
>
|
|
1552
|
+
{{ bodyHint.text }}
|
|
1553
|
+
</p>
|
|
1554
|
+
</template>
|
|
1555
|
+
</div>
|
|
1556
|
+
</DmsCard>
|
|
1557
|
+
|
|
1558
|
+
<DmsCard :padded="false" class="min-w-0">
|
|
1559
|
+
<div v-if="!result" class="px-4 py-10">
|
|
1560
|
+
<DmsEmptyState
|
|
1561
|
+
size="sm"
|
|
1562
|
+
:icon="sending ? 'i-ph-hourglass-medium' : 'i-ph-paper-plane-tilt'"
|
|
1563
|
+
:title="
|
|
1564
|
+
sending
|
|
1565
|
+
? t('api.tester.waiting_title')
|
|
1566
|
+
: t('api.tester.no_response_title')
|
|
1567
|
+
"
|
|
1568
|
+
:description="
|
|
1569
|
+
sending
|
|
1570
|
+
? t('api.tester.waiting_description', {
|
|
1571
|
+
seconds: PROXY_TIMEOUT_MS / 1000,
|
|
1572
|
+
})
|
|
1573
|
+
: t('api.tester.no_response_description', { shortcut })
|
|
1574
|
+
"
|
|
1575
|
+
/>
|
|
1576
|
+
</div>
|
|
1577
|
+
<template v-else>
|
|
1578
|
+
<div
|
|
1579
|
+
class="border-default flex flex-wrap items-center gap-x-3 gap-y-1 border-b px-4 py-2.5"
|
|
1580
|
+
>
|
|
1581
|
+
<ApiStatusBadge v-if="result.status" :status="result.status" text />
|
|
1582
|
+
<DmsStatusPill
|
|
1583
|
+
v-else
|
|
1584
|
+
:tone="result.error === 'aborted' ? 'neutral' : 'error'"
|
|
1585
|
+
dot="none"
|
|
1586
|
+
:label="
|
|
1587
|
+
result.error === 'aborted'
|
|
1588
|
+
? t('api.tester.cancelled')
|
|
1589
|
+
: t('api.tester.failed')
|
|
1590
|
+
"
|
|
1591
|
+
/>
|
|
1592
|
+
<UTooltip :text="t('api.tester.duration_tooltip')">
|
|
1593
|
+
<span class="text-muted font-mono text-[12px]" tabindex="0">
|
|
1594
|
+
{{
|
|
1595
|
+
t('api.tester.duration_browser', {
|
|
1596
|
+
duration: formatMs(result.durationMs, locale),
|
|
1597
|
+
})
|
|
1598
|
+
}}
|
|
1599
|
+
<template
|
|
1600
|
+
v-if="
|
|
1601
|
+
result.captured && result.captured.responseTimeMs !== null
|
|
1602
|
+
"
|
|
1603
|
+
>
|
|
1604
|
+
·
|
|
1605
|
+
<span
|
|
1606
|
+
:class="capturedSlow ? 'text-warning font-semibold' : ''"
|
|
1607
|
+
>
|
|
1608
|
+
{{
|
|
1609
|
+
t('api.tester.duration_server', {
|
|
1610
|
+
duration: formatMs(
|
|
1611
|
+
result.captured.responseTimeMs,
|
|
1612
|
+
locale,
|
|
1613
|
+
),
|
|
1614
|
+
})
|
|
1615
|
+
}}
|
|
1616
|
+
</span>
|
|
1617
|
+
</template>
|
|
1618
|
+
</span>
|
|
1619
|
+
</UTooltip>
|
|
1620
|
+
<span
|
|
1621
|
+
v-if="result.body || result.bodySize"
|
|
1622
|
+
class="text-muted font-mono text-[12px]"
|
|
1623
|
+
>
|
|
1624
|
+
{{ formatBytes(responseSize, locale) }}
|
|
1625
|
+
</span>
|
|
1626
|
+
<span class="grow" />
|
|
1627
|
+
<UButton
|
|
1628
|
+
v-if="!neverSent(result.error) && logsLink"
|
|
1629
|
+
:to="logsLink"
|
|
1630
|
+
size="xs"
|
|
1631
|
+
variant="link"
|
|
1632
|
+
trailing-icon="i-ph-arrow-right"
|
|
1633
|
+
:label="
|
|
1634
|
+
result.captured
|
|
1635
|
+
? t('api.tester.open_captured')
|
|
1636
|
+
: t('api.tester.open_logs')
|
|
1637
|
+
"
|
|
1638
|
+
/>
|
|
1639
|
+
<UTooltip
|
|
1640
|
+
v-else-if="!routeCaptured"
|
|
1641
|
+
:text="t('api.tester.not_captured_hint')"
|
|
1642
|
+
>
|
|
1643
|
+
<span class="text-dimmed text-xs" tabindex="0">
|
|
1644
|
+
{{ t('api.tester.not_captured') }}
|
|
1645
|
+
</span>
|
|
1646
|
+
</UTooltip>
|
|
1647
|
+
</div>
|
|
1648
|
+
<div class="flex flex-col gap-2 p-3">
|
|
1649
|
+
<DmsBanner
|
|
1650
|
+
v-if="errorCopy"
|
|
1651
|
+
:tone="result.error === 'aborted' ? 'info' : 'error'"
|
|
1652
|
+
size="sm"
|
|
1653
|
+
:icon="errorCopy.icon"
|
|
1654
|
+
:title="errorCopy.title"
|
|
1655
|
+
:description="errorCopy.description"
|
|
1656
|
+
/>
|
|
1657
|
+
<DmsBanner
|
|
1658
|
+
v-else-if="result.status === 401"
|
|
1659
|
+
tone="warning"
|
|
1660
|
+
size="sm"
|
|
1661
|
+
icon="i-ph-lock-simple"
|
|
1662
|
+
:title="t('api.tester.unauthorized_title')"
|
|
1663
|
+
:description="t(`api.tester.unauthorized.${result.auth}`)"
|
|
1664
|
+
>
|
|
1665
|
+
<template v-if="result.auth === 'none'" #actions>
|
|
1666
|
+
<UButton
|
|
1667
|
+
size="xs"
|
|
1668
|
+
color="neutral"
|
|
1669
|
+
variant="outline"
|
|
1670
|
+
:label="t('api.tester.turn_on_session')"
|
|
1671
|
+
@click="useSession = true"
|
|
1672
|
+
/>
|
|
1673
|
+
</template>
|
|
1674
|
+
</DmsBanner>
|
|
1675
|
+
<UTabs
|
|
1676
|
+
v-if="responseTabs.length"
|
|
1677
|
+
v-model="responseTab"
|
|
1678
|
+
:items="responseTabs"
|
|
1679
|
+
:content="false"
|
|
1680
|
+
variant="link"
|
|
1681
|
+
size="sm"
|
|
1682
|
+
/>
|
|
1683
|
+
<template v-if="responseTab === 'captured' && capturedAvailable">
|
|
1684
|
+
<p
|
|
1685
|
+
v-if="capturedState === 'loading' || capturedState === 'idle'"
|
|
1686
|
+
class="text-dimmed text-sm"
|
|
1687
|
+
>
|
|
1688
|
+
{{ t('api.tester.captured.loading') }}
|
|
1689
|
+
</p>
|
|
1690
|
+
<p
|
|
1691
|
+
v-else-if="capturedState === 'missing'"
|
|
1692
|
+
class="text-dimmed text-sm"
|
|
1693
|
+
>
|
|
1694
|
+
{{
|
|
1695
|
+
t('api.tester.captured.missing', {
|
|
1696
|
+
id: shortId(result.requestId ?? ''),
|
|
1697
|
+
})
|
|
1698
|
+
}}
|
|
1699
|
+
</p>
|
|
1700
|
+
<p
|
|
1701
|
+
v-else-if="capturedState === 'error'"
|
|
1702
|
+
class="text-error text-sm"
|
|
1703
|
+
>
|
|
1704
|
+
{{ t('api.tester.captured.error') }}
|
|
1705
|
+
</p>
|
|
1706
|
+
<div v-else-if="capturedLog" class="flex flex-col gap-3">
|
|
1707
|
+
<div
|
|
1708
|
+
class="text-muted flex flex-wrap items-center gap-3 font-mono text-[12px]"
|
|
1709
|
+
>
|
|
1710
|
+
<ApiStatusBadge
|
|
1711
|
+
:status="capturedLog.statusCode"
|
|
1712
|
+
text
|
|
1713
|
+
size="sm"
|
|
1714
|
+
/>
|
|
1715
|
+
<span
|
|
1716
|
+
v-if="capturedLog.responseTimeMs !== null"
|
|
1717
|
+
:class="capturedSlow ? 'text-warning font-semibold' : ''"
|
|
1718
|
+
>
|
|
1719
|
+
{{
|
|
1720
|
+
t('api.tester.duration_server', {
|
|
1721
|
+
duration: formatMs(capturedLog.responseTimeMs, locale),
|
|
1722
|
+
})
|
|
1723
|
+
}}
|
|
1724
|
+
</span>
|
|
1725
|
+
<span>
|
|
1726
|
+
{{ formatClock(capturedLog.timestamp, dateFormat) }}
|
|
1727
|
+
</span>
|
|
1728
|
+
<span>{{ shortId(capturedLog._id) }}</span>
|
|
1729
|
+
</div>
|
|
1730
|
+
<DmsBanner
|
|
1731
|
+
v-if="capturedLog.error"
|
|
1732
|
+
tone="error"
|
|
1733
|
+
size="sm"
|
|
1734
|
+
icon="i-ph-bug"
|
|
1735
|
+
:title="capturedLog.error.message"
|
|
1736
|
+
/>
|
|
1737
|
+
<DmsCodeSnippet
|
|
1738
|
+
v-if="capturedLog.error?.stack"
|
|
1739
|
+
:code="capturedLog.error.stack"
|
|
1740
|
+
:title="t('api.tester.captured.stack')"
|
|
1741
|
+
max-height="12rem"
|
|
1742
|
+
wrap="anywhere"
|
|
1743
|
+
/>
|
|
1744
|
+
<div class="flex flex-col gap-1.5">
|
|
1745
|
+
<p class="text-default text-xs font-medium">
|
|
1746
|
+
{{ t('api.tester.captured.headers') }}
|
|
1747
|
+
</p>
|
|
1748
|
+
<ApiKeyValues
|
|
1749
|
+
:values="capturedLog.requestHeaders"
|
|
1750
|
+
:empty="t('api.request.no_headers')"
|
|
1751
|
+
/>
|
|
1752
|
+
</div>
|
|
1753
|
+
<DmsCodeSnippet
|
|
1754
|
+
v-if="capturedLog.requestBody"
|
|
1755
|
+
:code="prettyBody(capturedLog.requestBody).text"
|
|
1756
|
+
:title="t('api.tester.captured.body')"
|
|
1757
|
+
max-height="16rem"
|
|
1758
|
+
wrap="anywhere"
|
|
1759
|
+
/>
|
|
1760
|
+
<p
|
|
1761
|
+
v-else-if="capturedLog.requestBodyOmitted"
|
|
1762
|
+
class="text-dimmed text-xs"
|
|
1763
|
+
>
|
|
1764
|
+
{{
|
|
1765
|
+
t('api.tester.captured.body_omitted', {
|
|
1766
|
+
reason: t(
|
|
1767
|
+
`api.tester.body_omitted.${capturedLog.requestBodyOmitted}`,
|
|
1768
|
+
),
|
|
1769
|
+
})
|
|
1770
|
+
}}
|
|
1771
|
+
</p>
|
|
1772
|
+
</div>
|
|
1773
|
+
</template>
|
|
1774
|
+
<template v-else-if="!result.error">
|
|
1775
|
+
<template v-if="responseTab === 'body'">
|
|
1776
|
+
<DmsCodeSnippet
|
|
1777
|
+
v-if="responseBody.text"
|
|
1778
|
+
:code="responseBody.text"
|
|
1779
|
+
max-height="24rem"
|
|
1780
|
+
wrap="anywhere"
|
|
1781
|
+
/>
|
|
1782
|
+
<p v-else class="text-dimmed text-sm">
|
|
1783
|
+
{{ t('api.request.no_body') }}
|
|
1784
|
+
</p>
|
|
1785
|
+
<p v-if="result.bodyTruncated" class="text-warning text-xs">
|
|
1786
|
+
{{
|
|
1787
|
+
t('api.tester.truncated_in_history', {
|
|
1788
|
+
shown: formatBytes(byteLength(result.body), locale),
|
|
1789
|
+
size: formatBytes(responseSize, locale),
|
|
1790
|
+
})
|
|
1791
|
+
}}
|
|
1792
|
+
</p>
|
|
1793
|
+
</template>
|
|
1794
|
+
<ApiKeyValues
|
|
1795
|
+
v-else
|
|
1796
|
+
:values="result.headers"
|
|
1797
|
+
:empty="t('api.request.no_headers')"
|
|
1798
|
+
/>
|
|
1799
|
+
</template>
|
|
1800
|
+
</div>
|
|
1801
|
+
</template>
|
|
1802
|
+
</DmsCard>
|
|
1803
|
+
</div>
|
|
1804
|
+
|
|
1805
|
+
<DmsCard :title="t('api.tester.history')" :padded="false">
|
|
1806
|
+
<template #actions>
|
|
1807
|
+
<span class="text-dimmed text-xs">
|
|
1808
|
+
{{ t('api.tester.history_hint') }}
|
|
1809
|
+
</span>
|
|
1810
|
+
<UButton
|
|
1811
|
+
v-if="history.length"
|
|
1812
|
+
size="xs"
|
|
1813
|
+
color="neutral"
|
|
1814
|
+
variant="ghost"
|
|
1815
|
+
:label="t('api.tester.clear')"
|
|
1816
|
+
@click="clearHistory"
|
|
1817
|
+
/>
|
|
1818
|
+
</template>
|
|
1819
|
+
<p v-if="history.length === 0" class="text-dimmed px-4 py-4 text-sm">
|
|
1820
|
+
{{ t('api.tester.history_empty') }}
|
|
1821
|
+
</p>
|
|
1822
|
+
<ul v-else class="divide-default divide-y">
|
|
1823
|
+
<li v-for="entry in history" :key="entry.at">
|
|
1824
|
+
<button
|
|
1825
|
+
type="button"
|
|
1826
|
+
class="hover:bg-elevated flex w-full items-center gap-3 px-4 py-2 text-left text-[12.5px]"
|
|
1827
|
+
@click="restore(entry)"
|
|
1828
|
+
>
|
|
1829
|
+
<ApiMethodBadge :method="entry.method" size="sm" />
|
|
1830
|
+
<ApiStatusBadge
|
|
1831
|
+
v-if="entry.result.status"
|
|
1832
|
+
:status="entry.result.status"
|
|
1833
|
+
size="sm"
|
|
1834
|
+
/>
|
|
1835
|
+
<DmsStatusPill
|
|
1836
|
+
v-else
|
|
1837
|
+
:tone="entry.result.error === 'aborted' ? 'neutral' : 'error'"
|
|
1838
|
+
dot="none"
|
|
1839
|
+
size="sm"
|
|
1840
|
+
:label="
|
|
1841
|
+
entry.result.error === 'aborted'
|
|
1842
|
+
? t('api.tester.cancelled')
|
|
1843
|
+
: t('api.tester.failed')
|
|
1844
|
+
"
|
|
1845
|
+
/>
|
|
1846
|
+
<span class="text-default min-w-0 grow truncate font-mono">
|
|
1847
|
+
{{ readable(entry.path) }}
|
|
1848
|
+
</span>
|
|
1849
|
+
<span
|
|
1850
|
+
v-if="entry.result.abandoned"
|
|
1851
|
+
class="text-dimmed shrink-0 text-xs"
|
|
1852
|
+
>
|
|
1853
|
+
{{ t('api.tester.history_abandoned') }}
|
|
1854
|
+
</span>
|
|
1855
|
+
<span
|
|
1856
|
+
v-if="entry.result.auth !== 'session'"
|
|
1857
|
+
class="text-dimmed text-xs"
|
|
1858
|
+
>
|
|
1859
|
+
{{ t(`api.tester.auth_short.${entry.result.auth}`) }}
|
|
1860
|
+
</span>
|
|
1861
|
+
<span
|
|
1862
|
+
v-if="entry.result.bodySize"
|
|
1863
|
+
class="text-dimmed font-mono text-[11px]"
|
|
1864
|
+
>
|
|
1865
|
+
{{ formatBytes(entry.result.bodySize, locale) }}
|
|
1866
|
+
</span>
|
|
1867
|
+
<span class="text-muted font-mono text-[11px]">
|
|
1868
|
+
{{ formatMs(entry.result.durationMs, locale) }}
|
|
1869
|
+
</span>
|
|
1870
|
+
<span class="text-dimmed font-mono text-[11px]">
|
|
1871
|
+
{{ formatClock(entry.at, dateFormat) }}
|
|
1872
|
+
</span>
|
|
1873
|
+
</button>
|
|
1874
|
+
</li>
|
|
1875
|
+
</ul>
|
|
1876
|
+
</DmsCard>
|
|
1877
|
+
<p class="sr-only" aria-live="polite">{{ liveMessage }}</p>
|
|
1878
|
+
</div>
|
|
1879
|
+
</template>
|