@antelopejs/dms-api 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -0
- package/README.md +61 -0
- package/dist/automation/get-api-health.d.ts +10 -0
- package/dist/automation/get-api-health.js +53 -0
- package/dist/automation/get-api-health.js.map +1 -0
- package/dist/automation/index.d.ts +2 -0
- package/dist/automation/index.js +19 -0
- package/dist/automation/index.js.map +1 -0
- package/dist/automation/query-request-logs.d.ts +18 -0
- package/dist/automation/query-request-logs.js +50 -0
- package/dist/automation/query-request-logs.js.map +1 -0
- package/dist/automation/route-unhealthy.d.ts +9 -0
- package/dist/automation/route-unhealthy.js +102 -0
- package/dist/automation/route-unhealthy.js.map +1 -0
- package/dist/automation/scope.d.ts +2 -0
- package/dist/automation/scope.js +18 -0
- package/dist/automation/scope.js.map +1 -0
- package/dist/config.d.ts +12 -0
- package/dist/config.js +38 -0
- package/dist/config.js.map +1 -0
- package/dist/db/index.d.ts +2 -0
- package/dist/db/index.js +19 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/models/api_settings.model.d.ts +23 -0
- package/dist/db/models/api_settings.model.js +13 -0
- package/dist/db/models/api_settings.model.js.map +1 -0
- package/dist/db/models/index.d.ts +4 -0
- package/dist/db/models/index.js +21 -0
- package/dist/db/models/index.js.map +1 -0
- package/dist/db/models/request_log.model.d.ts +47 -0
- package/dist/db/models/request_log.model.js +127 -0
- package/dist/db/models/request_log.model.js.map +1 -0
- package/dist/db/models/routes.model.d.ts +22 -0
- package/dist/db/models/routes.model.js +9 -0
- package/dist/db/models/routes.model.js.map +1 -0
- package/dist/db/models/routes_statistics.model.d.ts +23 -0
- package/dist/db/models/routes_statistics.model.js +13 -0
- package/dist/db/models/routes_statistics.model.js.map +1 -0
- package/dist/db/tables/api_settings.table.d.ts +10 -0
- package/dist/db/tables/api_settings.table.js +47 -0
- package/dist/db/tables/api_settings.table.js.map +1 -0
- package/dist/db/tables/index.d.ts +4 -0
- package/dist/db/tables/index.js +21 -0
- package/dist/db/tables/index.js.map +1 -0
- package/dist/db/tables/request_log.table.d.ts +29 -0
- package/dist/db/tables/request_log.table.js +107 -0
- package/dist/db/tables/request_log.table.js.map +1 -0
- package/dist/db/tables/routes.table.d.ts +11 -0
- package/dist/db/tables/routes.table.js +50 -0
- package/dist/db/tables/routes.table.js.map +1 -0
- package/dist/db/tables/routes_statistics.table.d.ts +9 -0
- package/dist/db/tables/routes_statistics.table.js +38 -0
- package/dist/db/tables/routes_statistics.table.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/middlewares/index.d.ts +1 -0
- package/dist/middlewares/index.js +18 -0
- package/dist/middlewares/index.js.map +1 -0
- package/dist/middlewares/request-log-capture.d.ts +1 -0
- package/dist/middlewares/request-log-capture.js +6 -0
- package/dist/middlewares/request-log-capture.js.map +1 -0
- package/dist/pages/all.d.ts +4 -0
- package/dist/pages/all.js +21 -0
- package/dist/pages/all.js.map +1 -0
- package/dist/pages/index.d.ts +4 -0
- package/dist/pages/index.js +21 -0
- package/dist/pages/index.js.map +1 -0
- package/dist/pages/logs/page.d.ts +9 -0
- package/dist/pages/logs/page.js +29 -0
- package/dist/pages/logs/page.js.map +1 -0
- package/dist/pages/module.d.ts +1 -0
- package/dist/pages/module.js +12 -0
- package/dist/pages/module.js.map +1 -0
- package/dist/pages/routes/page.d.ts +9 -0
- package/dist/pages/routes/page.js +29 -0
- package/dist/pages/routes/page.js.map +1 -0
- package/dist/pages/settings/form.d.ts +3 -0
- package/dist/pages/settings/form.js +80 -0
- package/dist/pages/settings/form.js.map +1 -0
- package/dist/pages/settings/page.d.ts +9 -0
- package/dist/pages/settings/page.js +26 -0
- package/dist/pages/settings/page.js.map +1 -0
- package/dist/pages/summary/page.d.ts +9 -0
- package/dist/pages/summary/page.js +29 -0
- package/dist/pages/summary/page.js.map +1 -0
- package/dist/routes/index.d.ts +5 -0
- package/dist/routes/index.js +22 -0
- package/dist/routes/index.js.map +1 -0
- package/dist/routes/logs.d.ts +7 -0
- package/dist/routes/logs.js +128 -0
- package/dist/routes/logs.js.map +1 -0
- package/dist/routes/monitoring.d.ts +17 -0
- package/dist/routes/monitoring.js +101 -0
- package/dist/routes/monitoring.js.map +1 -0
- package/dist/routes/routes.d.ts +37 -0
- package/dist/routes/routes.js +153 -0
- package/dist/routes/routes.js.map +1 -0
- package/dist/routes/settings.d.ts +24 -0
- package/dist/routes/settings.js +92 -0
- package/dist/routes/settings.js.map +1 -0
- package/dist/routes/summary.d.ts +32 -0
- package/dist/routes/summary.js +181 -0
- package/dist/routes/summary.js.map +1 -0
- package/dist/services/index.d.ts +11 -0
- package/dist/services/index.js +28 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/introspection/auth.d.ts +4 -0
- package/dist/services/introspection/auth.js +33 -0
- package/dist/services/introspection/auth.js.map +1 -0
- package/dist/services/introspection/errors.d.ts +6 -0
- package/dist/services/introspection/errors.js +50 -0
- package/dist/services/introspection/errors.js.map +1 -0
- package/dist/services/introspection/index.d.ts +53 -0
- package/dist/services/introspection/index.js +141 -0
- package/dist/services/introspection/index.js.map +1 -0
- package/dist/services/introspection/probe.d.ts +18 -0
- package/dist/services/introspection/probe.js +155 -0
- package/dist/services/introspection/probe.js.map +1 -0
- package/dist/services/period.d.ts +11 -0
- package/dist/services/period.js +68 -0
- package/dist/services/period.js.map +1 -0
- package/dist/services/request-log/capture.d.ts +10 -0
- package/dist/services/request-log/capture.js +189 -0
- package/dist/services/request-log/capture.js.map +1 -0
- package/dist/services/request-log/index.d.ts +3 -0
- package/dist/services/request-log/index.js +12 -0
- package/dist/services/request-log/index.js.map +1 -0
- package/dist/services/request-log/prune.d.ts +2 -0
- package/dist/services/request-log/prune.js +10 -0
- package/dist/services/request-log/prune.js.map +1 -0
- package/dist/services/request-log/read.d.ts +6 -0
- package/dist/services/request-log/read.js +26 -0
- package/dist/services/request-log/read.js.map +1 -0
- package/dist/services/request-log/redaction.d.ts +4 -0
- package/dist/services/request-log/redaction.js +53 -0
- package/dist/services/request-log/redaction.js.map +1 -0
- package/dist/services/request-log/util.d.ts +13 -0
- package/dist/services/request-log/util.js +114 -0
- package/dist/services/request-log/util.js.map +1 -0
- package/dist/services/routes-sync.d.ts +5 -0
- package/dist/services/routes-sync.js +63 -0
- package/dist/services/routes-sync.js.map +1 -0
- package/dist/services/scope.d.ts +7 -0
- package/dist/services/scope.js +40 -0
- package/dist/services/scope.js.map +1 -0
- package/dist/services/settings.d.ts +20 -0
- package/dist/services/settings.js +86 -0
- package/dist/services/settings.js.map +1 -0
- package/dist/services/statistics-aggregate.d.ts +67 -0
- package/dist/services/statistics-aggregate.js +340 -0
- package/dist/services/statistics-aggregate.js.map +1 -0
- package/dist/services/statistics-prune.d.ts +2 -0
- package/dist/services/statistics-prune.js +25 -0
- package/dist/services/statistics-prune.js.map +1 -0
- package/dist/services/statistics-read.d.ts +4 -0
- package/dist/services/statistics-read.js +48 -0
- package/dist/services/statistics-read.js.map +1 -0
- package/dist/services/statistics-utils.d.ts +14 -0
- package/dist/services/statistics-utils.js +65 -0
- package/dist/services/statistics-utils.js.map +1 -0
- package/dist/services/statistics-write.d.ts +3 -0
- package/dist/services/statistics-write.js +84 -0
- package/dist/services/statistics-write.js.map +1 -0
- package/dist/services/tree.d.ts +10 -0
- package/dist/services/tree.js +128 -0
- package/dist/services/tree.js.map +1 -0
- package/dist/types/charts.d.ts +9 -0
- package/dist/types/charts.js +3 -0
- package/dist/types/charts.js.map +1 -0
- package/dist/types/constants.d.ts +31 -0
- package/dist/types/constants.js +49 -0
- package/dist/types/constants.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +20 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/statistics.d.ts +17 -0
- package/dist/types/statistics.js +3 -0
- package/dist/types/statistics.js.map +1 -0
- package/frontend-vue/.editorconfig +12 -0
- package/frontend-vue/.prettierrc +12 -0
- package/frontend-vue/.vscode/settings.json +26 -0
- package/frontend-vue/app/components/ConfigurationView.vue +187 -0
- package/frontend-vue/app/components/DocumentationView.vue +224 -0
- package/frontend-vue/app/components/LogDetailDrawer.vue +178 -0
- package/frontend-vue/app/components/LogsView.vue +347 -0
- package/frontend-vue/app/components/RouteDetailTabs.vue +179 -0
- package/frontend-vue/app/components/RouteTree.vue +196 -0
- package/frontend-vue/app/components/RoutesView.vue +82 -0
- package/frontend-vue/app/components/StatsView.vue +268 -0
- package/frontend-vue/app/components/SummaryView.vue +657 -0
- package/frontend-vue/app/components/TesterPanel.vue +499 -0
- package/frontend-vue/app/components/internal/ApiMethodBadge.vue +33 -0
- package/frontend-vue/app/components/internal/ApiStatusBadge.vue +28 -0
- package/frontend-vue/app/components/internal/PeriodSelect.vue +58 -0
- package/frontend-vue/app/components/internal/RouteTreeNode.vue +168 -0
- package/frontend-vue/app/components/internal/StatusBreakdownBars.vue +162 -0
- package/frontend-vue/app/components/internal/StatusDonut.vue +84 -0
- package/frontend-vue/app/components/internal/UnitAreaChart.vue +73 -0
- package/frontend-vue/app/composables/useApiIntrospection.ts +344 -0
- package/frontend-vue/app/composables/useLogDetailDrawer.ts +50 -0
- package/frontend-vue/app/composables/useSelectedPeriod.ts +107 -0
- package/frontend-vue/app/composables/useStatsPeriods.ts +139 -0
- 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 +49 -0
- package/frontend-vue/app/utils/statusClass.ts +49 -0
- package/frontend-vue/app/utils/testerRequest.ts +50 -0
- package/frontend-vue/dms.frontend.ts +25 -0
- package/frontend-vue/eslint.config.mjs +16 -0
- package/frontend-vue/i18n/locales/en-GB.json +240 -0
- package/frontend-vue/i18n/locales/fr-FR.json +240 -0
- package/frontend-vue/package.json +35 -0
- package/frontend-vue/pnpm-lock.yaml +5796 -0
- package/frontend-vue/pnpm-workspace.yaml +2 -0
- package/frontend-vue/public/.gitkeep +0 -0
- package/frontend-vue/server/.gitkeep +0 -0
- package/frontend-vue/tests/periods.test.ts +145 -0
- package/frontend-vue/tests/persistence.test.ts +45 -0
- package/frontend-vue/tests/registration.test.ts +28 -0
- package/frontend-vue/tests/testerRequest.test.ts +95 -0
- package/frontend-vue/tsconfig.json +13 -0
- package/frontend-vue/vitest.config.ts +8 -0
- package/package.json +67 -0
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
|
3
|
+
import type {
|
|
4
|
+
ParameterInfo,
|
|
5
|
+
RouteInspection,
|
|
6
|
+
} from '../composables/useApiIntrospection'
|
|
7
|
+
import { httpMethodColor } from '../utils/httpMethod'
|
|
8
|
+
import { sendTesterRequest, type TesterRequest } from '../utils/testerRequest'
|
|
9
|
+
|
|
10
|
+
interface HeaderRow {
|
|
11
|
+
name: string
|
|
12
|
+
value: string
|
|
13
|
+
id: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface PathParamRow {
|
|
17
|
+
name: string
|
|
18
|
+
value: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface HistoryEntry {
|
|
22
|
+
id: string
|
|
23
|
+
timestamp: number
|
|
24
|
+
method: string
|
|
25
|
+
url: string
|
|
26
|
+
headers: Record<string, string>
|
|
27
|
+
body?: string
|
|
28
|
+
pathParams?: Record<string, string>
|
|
29
|
+
useSession?: boolean
|
|
30
|
+
status?: number
|
|
31
|
+
durationMs?: number
|
|
32
|
+
responseSnippet?: string
|
|
33
|
+
ok: boolean
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const props = defineProps<{
|
|
37
|
+
route: RouteInspection
|
|
38
|
+
}>()
|
|
39
|
+
|
|
40
|
+
const HISTORY_MAX = 25
|
|
41
|
+
const HISTORY_PREVIEW_BYTES = 200
|
|
42
|
+
const SUCCESS_STATUS_MIN = 200
|
|
43
|
+
const SUCCESS_STATUS_MAX = 300
|
|
44
|
+
|
|
45
|
+
const config = useDmsRuntimeConfig()
|
|
46
|
+
const { loggedIn } = useUserSession()
|
|
47
|
+
|
|
48
|
+
const baseURL = computed(() => {
|
|
49
|
+
const dmsApi = (config.public as Record<string, unknown>).dmsApi as
|
|
50
|
+
| { baseURL?: string }
|
|
51
|
+
| undefined
|
|
52
|
+
return dmsApi?.baseURL ?? ''
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const useSessionAuth = ref(true)
|
|
56
|
+
const canUseSession = computed(() => loggedIn.value)
|
|
57
|
+
|
|
58
|
+
const pathParams = reactive<PathParamRow[]>([])
|
|
59
|
+
const headers = reactive<HeaderRow[]>([])
|
|
60
|
+
const requestBody = ref('')
|
|
61
|
+
const sending = ref(false)
|
|
62
|
+
const response = ref<{
|
|
63
|
+
status: number
|
|
64
|
+
durationMs: number
|
|
65
|
+
headers: Record<string, string>
|
|
66
|
+
body: string
|
|
67
|
+
bodyIsJson: boolean
|
|
68
|
+
error?: string
|
|
69
|
+
} | null>(null)
|
|
70
|
+
const history = ref<HistoryEntry[]>([])
|
|
71
|
+
|
|
72
|
+
const methodHasBody = computed(() =>
|
|
73
|
+
/^(?:post|put|patch|delete)$/i.test(props.route.method),
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
const renderedUrl = computed(() => {
|
|
77
|
+
let url = props.route.location
|
|
78
|
+
for (const { name, value } of pathParams) {
|
|
79
|
+
if (!name) continue
|
|
80
|
+
url = url.replace(`:${name}`, encodeURIComponent(value || `:${name}`))
|
|
81
|
+
}
|
|
82
|
+
return url.startsWith('/') ? url : `/${url}`
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
const fullUrl = computed(() => `${baseURL.value}${renderedUrl.value}`)
|
|
86
|
+
|
|
87
|
+
const methodBadgeColor = computed(() => httpMethodColor(props.route.method))
|
|
88
|
+
|
|
89
|
+
function historyKey(routeId: string): string {
|
|
90
|
+
return `dmsApi.tester.history.${routeId}`
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function loadHistory() {
|
|
94
|
+
if (typeof window === 'undefined') return
|
|
95
|
+
try {
|
|
96
|
+
const raw = window.localStorage.getItem(historyKey(props.route.id))
|
|
97
|
+
history.value = raw ? (JSON.parse(raw) as HistoryEntry[]) : []
|
|
98
|
+
} catch {
|
|
99
|
+
history.value = []
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function saveHistory() {
|
|
104
|
+
if (typeof window === 'undefined') return
|
|
105
|
+
try {
|
|
106
|
+
window.localStorage.setItem(
|
|
107
|
+
historyKey(props.route.id),
|
|
108
|
+
JSON.stringify(history.value.slice(0, HISTORY_MAX)),
|
|
109
|
+
)
|
|
110
|
+
} catch {
|
|
111
|
+
/* quota or disabled storage — ignore */
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function pathParamsFromLocation(location: string): string[] {
|
|
116
|
+
const out: string[] = []
|
|
117
|
+
for (const seg of location.split('/')) {
|
|
118
|
+
if (seg.startsWith(':')) out.push(seg.slice(1))
|
|
119
|
+
else if (seg.startsWith('::')) out.push(seg.slice(2))
|
|
120
|
+
}
|
|
121
|
+
return out
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function nameOf(p: ParameterInfo): string {
|
|
125
|
+
return p.name ?? `param_${p.index}`
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function cryptoId(): string {
|
|
129
|
+
return `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function resetFromRoute() {
|
|
133
|
+
pathParams.length = 0
|
|
134
|
+
for (const name of pathParamsFromLocation(props.route.location)) {
|
|
135
|
+
pathParams.push({ name, value: '' })
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
headers.length = 0
|
|
139
|
+
if (methodHasBody.value) {
|
|
140
|
+
headers.push({
|
|
141
|
+
name: 'Content-Type',
|
|
142
|
+
value: 'application/json',
|
|
143
|
+
id: cryptoId(),
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const bodyParam = props.route.parameters.find((p) => p.source === 'body')
|
|
148
|
+
if (methodHasBody.value && bodyParam) {
|
|
149
|
+
requestBody.value = '{\n \n}'
|
|
150
|
+
} else {
|
|
151
|
+
requestBody.value = ''
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
for (const p of props.route.parameters) {
|
|
155
|
+
if (p.source === 'header') {
|
|
156
|
+
headers.push({ name: nameOf(p), value: '', id: cryptoId() })
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
response.value = null
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function addHeader() {
|
|
164
|
+
headers.push({ name: '', value: '', id: cryptoId() })
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function removeHeader(id: string) {
|
|
168
|
+
const idx = headers.findIndex((h) => h.id === id)
|
|
169
|
+
if (idx >= 0) headers.splice(idx, 1)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function buildHeaderRecord(): Record<string, string> {
|
|
173
|
+
const out: Record<string, string> = {}
|
|
174
|
+
for (const h of headers) {
|
|
175
|
+
if (!h.name) continue
|
|
176
|
+
out[h.name] = h.value
|
|
177
|
+
}
|
|
178
|
+
return out
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function buildPathParamRecord(): Record<string, string> {
|
|
182
|
+
return Object.fromEntries(pathParams.map(({ name, value }) => [name, value]))
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function handleTesterResponse(
|
|
186
|
+
result: Awaited<ReturnType<typeof sendTesterRequest>>,
|
|
187
|
+
request: TesterRequest,
|
|
188
|
+
url: string,
|
|
189
|
+
started: number,
|
|
190
|
+
) {
|
|
191
|
+
const durationMs = Math.round(performance.now() - started)
|
|
192
|
+
const isJson = /json/i.test(result.headers['content-type'] ?? '')
|
|
193
|
+
response.value = {
|
|
194
|
+
status: result.status,
|
|
195
|
+
durationMs,
|
|
196
|
+
headers: result.headers,
|
|
197
|
+
body: isJson ? safePretty(result.body) : result.body,
|
|
198
|
+
bodyIsJson: isJson,
|
|
199
|
+
}
|
|
200
|
+
pushHistory({
|
|
201
|
+
id: cryptoId(),
|
|
202
|
+
timestamp: Date.now(),
|
|
203
|
+
method: request.method,
|
|
204
|
+
url,
|
|
205
|
+
headers: request.headers,
|
|
206
|
+
body: methodHasBody.value ? requestBody.value : undefined,
|
|
207
|
+
pathParams: buildPathParamRecord(),
|
|
208
|
+
useSession: request.useSession,
|
|
209
|
+
status: result.status,
|
|
210
|
+
durationMs,
|
|
211
|
+
responseSnippet: result.body.slice(0, HISTORY_PREVIEW_BYTES),
|
|
212
|
+
ok:
|
|
213
|
+
result.status >= SUCCESS_STATUS_MIN && result.status < SUCCESS_STATUS_MAX,
|
|
214
|
+
})
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function handleTesterError(
|
|
218
|
+
error: unknown,
|
|
219
|
+
request: TesterRequest,
|
|
220
|
+
url: string,
|
|
221
|
+
started: number,
|
|
222
|
+
) {
|
|
223
|
+
const durationMs = Math.round(performance.now() - started)
|
|
224
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
225
|
+
response.value = {
|
|
226
|
+
status: 0,
|
|
227
|
+
durationMs,
|
|
228
|
+
headers: {},
|
|
229
|
+
body: message,
|
|
230
|
+
bodyIsJson: false,
|
|
231
|
+
error: message,
|
|
232
|
+
}
|
|
233
|
+
pushHistory({
|
|
234
|
+
id: cryptoId(),
|
|
235
|
+
timestamp: Date.now(),
|
|
236
|
+
method: request.method,
|
|
237
|
+
url,
|
|
238
|
+
headers: request.headers,
|
|
239
|
+
body: methodHasBody.value ? requestBody.value : undefined,
|
|
240
|
+
pathParams: buildPathParamRecord(),
|
|
241
|
+
useSession: request.useSession,
|
|
242
|
+
durationMs,
|
|
243
|
+
responseSnippet: message,
|
|
244
|
+
ok: false,
|
|
245
|
+
})
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async function send() {
|
|
249
|
+
if (sending.value) return
|
|
250
|
+
sending.value = true
|
|
251
|
+
response.value = null
|
|
252
|
+
const url = fullUrl.value
|
|
253
|
+
const request: TesterRequest = {
|
|
254
|
+
method: props.route.method.toUpperCase(),
|
|
255
|
+
headers: buildHeaderRecord(),
|
|
256
|
+
useSession: useSessionAuth.value && canUseSession.value,
|
|
257
|
+
}
|
|
258
|
+
if (methodHasBody.value && requestBody.value.trim().length > 0) {
|
|
259
|
+
request.body = requestBody.value
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const started = performance.now()
|
|
263
|
+
try {
|
|
264
|
+
const result = await sendTesterRequest(url, window.location.origin, request)
|
|
265
|
+
handleTesterResponse(result, request, url, started)
|
|
266
|
+
} catch (error) {
|
|
267
|
+
handleTesterError(error, request, url, started)
|
|
268
|
+
} finally {
|
|
269
|
+
sending.value = false
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function pushHistory(entry: HistoryEntry) {
|
|
274
|
+
history.value.unshift(entry)
|
|
275
|
+
if (history.value.length > HISTORY_MAX) history.value.length = HISTORY_MAX
|
|
276
|
+
saveHistory()
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function recall(entry: HistoryEntry) {
|
|
280
|
+
headers.length = 0
|
|
281
|
+
for (const [name, value] of Object.entries(entry.headers)) {
|
|
282
|
+
headers.push({ name, value, id: cryptoId() })
|
|
283
|
+
}
|
|
284
|
+
for (const pathParam of pathParams) {
|
|
285
|
+
pathParam.value = entry.pathParams?.[pathParam.name] ?? pathParam.value
|
|
286
|
+
}
|
|
287
|
+
if (entry.body !== undefined) requestBody.value = entry.body
|
|
288
|
+
if (entry.useSession !== undefined) useSessionAuth.value = entry.useSession
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function clearHistory() {
|
|
292
|
+
history.value = []
|
|
293
|
+
saveHistory()
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function safePretty(text: string): string {
|
|
297
|
+
try {
|
|
298
|
+
return JSON.stringify(JSON.parse(text), null, 2)
|
|
299
|
+
} catch {
|
|
300
|
+
return text
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function statusColor(s?: number): string {
|
|
305
|
+
if (!s || s === 0) return 'error'
|
|
306
|
+
if (s >= 500) return 'error'
|
|
307
|
+
if (s >= 400) return 'warning'
|
|
308
|
+
if (s >= 300) return 'info'
|
|
309
|
+
return 'success'
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
watch(
|
|
313
|
+
() => props.route.id,
|
|
314
|
+
() => {
|
|
315
|
+
resetFromRoute()
|
|
316
|
+
loadHistory()
|
|
317
|
+
},
|
|
318
|
+
{ immediate: true },
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
onMounted(loadHistory)
|
|
322
|
+
</script>
|
|
323
|
+
|
|
324
|
+
<template>
|
|
325
|
+
<div class="flex w-full flex-col gap-4">
|
|
326
|
+
<!-- URL preview + send -->
|
|
327
|
+
<div class="flex flex-wrap items-center gap-2">
|
|
328
|
+
<UBadge :color="methodBadgeColor" variant="solid">
|
|
329
|
+
{{ route.method.toUpperCase() }}
|
|
330
|
+
</UBadge>
|
|
331
|
+
<code
|
|
332
|
+
class="bg-elevated text-highlighted grow rounded px-3 py-2 font-mono text-sm"
|
|
333
|
+
>
|
|
334
|
+
{{ fullUrl }}
|
|
335
|
+
</code>
|
|
336
|
+
<UButton
|
|
337
|
+
:loading="sending"
|
|
338
|
+
:disabled="sending"
|
|
339
|
+
color="primary"
|
|
340
|
+
icon="i-ph-paper-plane-tilt"
|
|
341
|
+
@click="send"
|
|
342
|
+
>
|
|
343
|
+
{{ $t('page.api.routes.tester.send') }}
|
|
344
|
+
</UButton>
|
|
345
|
+
</div>
|
|
346
|
+
|
|
347
|
+
<!-- Auth toggle -->
|
|
348
|
+
<label
|
|
349
|
+
class="text-muted flex items-center gap-2 self-start text-xs"
|
|
350
|
+
:class="{ 'opacity-60': !canUseSession }"
|
|
351
|
+
>
|
|
352
|
+
<USwitch v-model="useSessionAuth" :disabled="!canUseSession" size="xs" />
|
|
353
|
+
<span class="flex items-center gap-1">
|
|
354
|
+
<UIcon name="i-ph-shield-check" />
|
|
355
|
+
{{ $t('page.api.routes.tester.use_current_user') }}
|
|
356
|
+
</span>
|
|
357
|
+
<span class="text-dimmed">
|
|
358
|
+
{{
|
|
359
|
+
canUseSession
|
|
360
|
+
? $t('page.api.routes.tester.use_current_user_description')
|
|
361
|
+
: $t('page.api.routes.tester.auth_unavailable')
|
|
362
|
+
}}
|
|
363
|
+
</span>
|
|
364
|
+
</label>
|
|
365
|
+
|
|
366
|
+
<!-- Path params -->
|
|
367
|
+
<section v-if="pathParams.length > 0" class="flex flex-col gap-2">
|
|
368
|
+
<h4 class="text-highlighted text-sm font-semibold">
|
|
369
|
+
{{ $t('page.api.routes.tester.path_params') }}
|
|
370
|
+
</h4>
|
|
371
|
+
<div
|
|
372
|
+
v-for="(p, idx) in pathParams"
|
|
373
|
+
:key="p.name + idx"
|
|
374
|
+
class="grid grid-cols-[160px_1fr] gap-3"
|
|
375
|
+
>
|
|
376
|
+
<code class="text-muted self-center font-mono text-xs">
|
|
377
|
+
:{{ p.name }}
|
|
378
|
+
</code>
|
|
379
|
+
<UInput v-model="p.value" :placeholder="p.name" />
|
|
380
|
+
</div>
|
|
381
|
+
</section>
|
|
382
|
+
|
|
383
|
+
<!-- Headers -->
|
|
384
|
+
<section class="flex flex-col gap-2">
|
|
385
|
+
<div class="flex items-center justify-between">
|
|
386
|
+
<h4 class="text-highlighted text-sm font-semibold">
|
|
387
|
+
{{ $t('page.api.routes.tester.headers') }}
|
|
388
|
+
</h4>
|
|
389
|
+
<UButton size="xs" variant="ghost" icon="i-ph-plus" @click="addHeader">
|
|
390
|
+
{{ $t('page.api.routes.tester.add_header') }}
|
|
391
|
+
</UButton>
|
|
392
|
+
</div>
|
|
393
|
+
<div
|
|
394
|
+
v-for="h in headers"
|
|
395
|
+
:key="h.id"
|
|
396
|
+
class="grid grid-cols-[1fr_2fr_auto] gap-2"
|
|
397
|
+
>
|
|
398
|
+
<UInput
|
|
399
|
+
v-model="h.name"
|
|
400
|
+
:placeholder="$t('page.api.routes.tester.header_name')"
|
|
401
|
+
/>
|
|
402
|
+
<UInput
|
|
403
|
+
v-model="h.value"
|
|
404
|
+
:placeholder="$t('page.api.routes.tester.header_value')"
|
|
405
|
+
/>
|
|
406
|
+
<UButton
|
|
407
|
+
size="xs"
|
|
408
|
+
variant="ghost"
|
|
409
|
+
color="neutral"
|
|
410
|
+
icon="i-ph-x"
|
|
411
|
+
@click="removeHeader(h.id)"
|
|
412
|
+
/>
|
|
413
|
+
</div>
|
|
414
|
+
<p v-if="headers.length === 0" class="text-dimmed text-xs">
|
|
415
|
+
{{ $t('page.api.routes.tester.no_headers') }}
|
|
416
|
+
</p>
|
|
417
|
+
</section>
|
|
418
|
+
|
|
419
|
+
<!-- Body -->
|
|
420
|
+
<section v-if="methodHasBody" class="flex flex-col gap-2">
|
|
421
|
+
<h4 class="text-highlighted text-sm font-semibold">
|
|
422
|
+
{{ $t('page.api.routes.tester.body') }}
|
|
423
|
+
</h4>
|
|
424
|
+
<UTextarea v-model="requestBody" :rows="8" class="font-mono text-xs" />
|
|
425
|
+
</section>
|
|
426
|
+
|
|
427
|
+
<!-- Response panel -->
|
|
428
|
+
<section v-if="response" class="flex flex-col gap-2">
|
|
429
|
+
<div class="flex items-center gap-2">
|
|
430
|
+
<h4 class="text-highlighted text-sm font-semibold">
|
|
431
|
+
{{ $t('page.api.routes.tester.response') }}
|
|
432
|
+
</h4>
|
|
433
|
+
<UBadge :color="statusColor(response.status)" variant="subtle">
|
|
434
|
+
{{ response.status || $t('page.api.routes.tester.network_error') }}
|
|
435
|
+
</UBadge>
|
|
436
|
+
<span class="text-dimmed text-xs">{{ response.durationMs }} ms</span>
|
|
437
|
+
</div>
|
|
438
|
+
|
|
439
|
+
<div
|
|
440
|
+
v-if="Object.keys(response.headers).length > 0"
|
|
441
|
+
class="flex flex-col gap-1"
|
|
442
|
+
>
|
|
443
|
+
<p class="text-dimmed text-xs uppercase">
|
|
444
|
+
{{ $t('page.api.routes.tester.response_headers') }}
|
|
445
|
+
</p>
|
|
446
|
+
<dl class="grid grid-cols-[max-content_1fr] gap-x-4 gap-y-1 text-xs">
|
|
447
|
+
<template v-for="(value, name) in response.headers" :key="name">
|
|
448
|
+
<dt class="text-muted font-mono">{{ name }}</dt>
|
|
449
|
+
<dd class="break-all font-mono">{{ value }}</dd>
|
|
450
|
+
</template>
|
|
451
|
+
</dl>
|
|
452
|
+
</div>
|
|
453
|
+
|
|
454
|
+
<div class="flex flex-col gap-1">
|
|
455
|
+
<p class="text-dimmed text-xs uppercase">
|
|
456
|
+
{{ $t('page.api.routes.tester.response_body') }}
|
|
457
|
+
</p>
|
|
458
|
+
<pre class="bg-elevated max-h-96 overflow-auto rounded p-3 text-xs">{{
|
|
459
|
+
response.body
|
|
460
|
+
}}</pre>
|
|
461
|
+
</div>
|
|
462
|
+
</section>
|
|
463
|
+
|
|
464
|
+
<!-- History -->
|
|
465
|
+
<section v-if="history.length > 0" class="flex flex-col gap-2">
|
|
466
|
+
<div class="flex items-center justify-between">
|
|
467
|
+
<h4 class="text-highlighted text-sm font-semibold">
|
|
468
|
+
{{ $t('page.api.routes.tester.history') }}
|
|
469
|
+
</h4>
|
|
470
|
+
<UButton
|
|
471
|
+
size="xs"
|
|
472
|
+
variant="ghost"
|
|
473
|
+
color="neutral"
|
|
474
|
+
icon="i-ph-trash"
|
|
475
|
+
@click="clearHistory"
|
|
476
|
+
>
|
|
477
|
+
{{ $t('page.api.routes.tester.clear_history') }}
|
|
478
|
+
</UButton>
|
|
479
|
+
</div>
|
|
480
|
+
<ul class="space-y-1">
|
|
481
|
+
<li
|
|
482
|
+
v-for="entry in history"
|
|
483
|
+
:key="entry.id"
|
|
484
|
+
class="border-default bg-elevated/40 hover:bg-elevated flex cursor-pointer items-center gap-3 rounded border px-3 py-2"
|
|
485
|
+
@click="recall(entry)"
|
|
486
|
+
>
|
|
487
|
+
<UBadge :color="statusColor(entry.status)" variant="subtle" size="xs">
|
|
488
|
+
{{ entry.status || 'ERR' }}
|
|
489
|
+
</UBadge>
|
|
490
|
+
<span class="text-dimmed text-xs">{{ entry.durationMs }} ms</span>
|
|
491
|
+
<span class="grow truncate font-mono text-xs">{{ entry.url }}</span>
|
|
492
|
+
<span class="text-dimmed text-xs">
|
|
493
|
+
{{ new Date(entry.timestamp).toLocaleTimeString() }}
|
|
494
|
+
</span>
|
|
495
|
+
</li>
|
|
496
|
+
</ul>
|
|
497
|
+
</section>
|
|
498
|
+
</div>
|
|
499
|
+
</template>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
import { httpMethodColor } from '../../utils/httpMethod'
|
|
4
|
+
|
|
5
|
+
// HTTP-method badge. The DMS look is a flat, tinted, mono pill — in
|
|
6
|
+
// `@antelopejs/dms-frontend` that's `<UBadge variant="subtle">` with a
|
|
7
|
+
// per-verb semantic color. The verb → color mapping (the API-specific bit)
|
|
8
|
+
// lives in the shared `httpMethodColor` helper; the flat surface and its
|
|
9
|
+
// colors are inherited from the DMS theme.
|
|
10
|
+
const props = withDefaults(
|
|
11
|
+
defineProps<{
|
|
12
|
+
method: string
|
|
13
|
+
size?: 'sm' | 'md' | 'lg'
|
|
14
|
+
}>(),
|
|
15
|
+
{ size: 'sm' },
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
const upper = computed(() => props.method.toUpperCase())
|
|
19
|
+
const label = computed(() => (upper.value === '*' ? 'ALL' : upper.value))
|
|
20
|
+
|
|
21
|
+
const color = computed(() => httpMethodColor(upper.value))
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<template>
|
|
25
|
+
<UBadge
|
|
26
|
+
:color="color"
|
|
27
|
+
variant="subtle"
|
|
28
|
+
:size="size"
|
|
29
|
+
class="font-mono font-semibold tracking-wide"
|
|
30
|
+
>
|
|
31
|
+
{{ label }}
|
|
32
|
+
</UBadge>
|
|
33
|
+
</template>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
|
|
4
|
+
// HTTP status-code badge. Flat DMS look via `<UBadge variant="subtle">`; this
|
|
5
|
+
// wrapper owns the status-class → color mapping. 2xx→success, 3xx→info,
|
|
6
|
+
// 4xx→warning, 5xx→error (0 / network error → error).
|
|
7
|
+
const props = withDefaults(
|
|
8
|
+
defineProps<{
|
|
9
|
+
status: number
|
|
10
|
+
size?: 'sm' | 'md' | 'lg'
|
|
11
|
+
}>(),
|
|
12
|
+
{ size: 'sm' },
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
const color = computed<'success' | 'info' | 'warning' | 'error'>(() => {
|
|
16
|
+
if (!props.status) return 'error'
|
|
17
|
+
if (props.status >= 500) return 'error'
|
|
18
|
+
if (props.status >= 400) return 'warning'
|
|
19
|
+
if (props.status >= 300) return 'info'
|
|
20
|
+
return 'success'
|
|
21
|
+
})
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<template>
|
|
25
|
+
<UBadge :color="color" variant="subtle" :size="size" class="font-mono tabular-nums">
|
|
26
|
+
{{ status || 'ERR' }}
|
|
27
|
+
</UBadge>
|
|
28
|
+
</template>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { onMounted, ref } from 'vue'
|
|
3
|
+
import type { PeriodKind } from '../../composables/useStatsPeriods'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The period filter shared by the Overview, Routes and Logs pages.
|
|
7
|
+
*
|
|
8
|
+
* Owning the whole cycle here — read the retention, build the options, resolve
|
|
9
|
+
* the starting window, persist every change — is what keeps the three pages
|
|
10
|
+
* identical. They only see the resolved `Nd`/`Nh` value.
|
|
11
|
+
*
|
|
12
|
+
* `null` until the retention answers: pages hold off fetching rather than
|
|
13
|
+
* request a window nobody picked, which would otherwise be a wasted round-trip
|
|
14
|
+
* (or one past the retention) followed by a second for the real value.
|
|
15
|
+
*/
|
|
16
|
+
const props = withDefaults(
|
|
17
|
+
defineProps<{
|
|
18
|
+
/** Which retention bounds the list. */
|
|
19
|
+
kind?: PeriodKind
|
|
20
|
+
/** `?period=` deep link, when the page accepts one. */
|
|
21
|
+
deepLink?: string
|
|
22
|
+
size?: 'xs' | 'sm' | 'md'
|
|
23
|
+
class?: string
|
|
24
|
+
}>(),
|
|
25
|
+
{ kind: 'stats', size: 'sm', deepLink: undefined, class: undefined },
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
const model = defineModel<string | null>({ required: true })
|
|
29
|
+
|
|
30
|
+
const { options, load } = useStatsPeriods(props.kind)
|
|
31
|
+
const { resolve, set } = useSelectedPeriod()
|
|
32
|
+
|
|
33
|
+
const ready = ref(false)
|
|
34
|
+
|
|
35
|
+
onMounted(async () => {
|
|
36
|
+
const fallback = await load()
|
|
37
|
+
model.value = resolve(props.deepLink, options.value, fallback)
|
|
38
|
+
ready.value = true
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
function onChange(value: string) {
|
|
42
|
+
model.value = value
|
|
43
|
+
set(value)
|
|
44
|
+
}
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<template>
|
|
48
|
+
<USelect
|
|
49
|
+
v-if="ready"
|
|
50
|
+
:model-value="model ?? undefined"
|
|
51
|
+
:items="options"
|
|
52
|
+
:size="size"
|
|
53
|
+
:class="props.class"
|
|
54
|
+
:aria-label="$t('page.api.filters.period')"
|
|
55
|
+
@update:model-value="onChange"
|
|
56
|
+
/>
|
|
57
|
+
<USkeleton v-else class="h-8 w-28" :class="props.class" />
|
|
58
|
+
</template>
|