@antelopejs/dms-api 0.3.0 → 0.4.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/README.md +88 -148
- package/dist/db/models/api_settings.model.d.ts +1 -0
- package/dist/db/models/request_log.model.d.ts +1 -0
- package/dist/db/models/routes.model.d.ts +1 -0
- package/dist/db/models/routes_statistics.model.d.ts +1 -0
- package/frontend-vue/app/components/blocks/HealthHero.vue +11 -5
- package/frontend-vue/app/components/blocks/LiveTraffic.vue +3 -2
- package/frontend-vue/app/components/blocks/RequestDetail.vue +35 -33
- package/frontend-vue/app/components/blocks/RetentionInput.vue +51 -20
- package/frontend-vue/app/components/blocks/RouteTester.vue +86 -28
- package/frontend-vue/app/components/blocks/RouteTree.vue +9 -9
- package/frontend-vue/app/components/blocks/ScopeChip.vue +11 -7
- package/frontend-vue/app/composables/useClientValue.ts +18 -0
- package/frontend-vue/app/composables/useRouteDetail.ts +22 -106
- package/frontend-vue/app/utils/http.ts +10 -0
- package/frontend-vue/app/utils/testerRequest.ts +9 -7
- package/frontend-vue/dms.server.ts +9 -0
- package/frontend-vue/package.json +1 -1
- package/frontend-vue/server/tester.ts +266 -0
- package/frontend-vue/tests/clientValue.test.ts +64 -0
- package/frontend-vue/tests/dmsServer.test.ts +44 -0
- package/frontend-vue/tests/testerRequest.test.ts +1 -1
- package/frontend-vue/tests/testerRoute.test.ts +299 -0
- package/package.json +29 -13
- package/skills/dms-api/SKILL.md +31 -0
- package/frontend-vue/app/composables/useApiResource.ts +0 -92
package/README.md
CHANGED
|
@@ -1,154 +1,94 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
1
3
|
# @antelopejs/dms-api
|
|
2
4
|
|
|
3
|
-
<
|
|
4
|
-
<a href="./LICENSE"><img alt="License" src="https://img.shields.io/
|
|
5
|
-
<a href="https://discord.gg/sjK28QHrA7"><img src="https://img.shields.io/badge/Discord-18181B?logo=discord&style=for-the-badge&color=000000"
|
|
6
|
-
<a href="https://antelopejs.com"><img src="https://img.shields.io/badge/Docs-18181B?style=for-the-badge&color=000000"
|
|
5
|
+
<a href="https://www.npmjs.com/package/@antelopejs/dms-api"><img alt="npm" src="https://img.shields.io/npm/v/@antelopejs/dms-api?style=for-the-badge&labelColor=000000&color=000000"></a>
|
|
6
|
+
<a href="./LICENSE"><img alt="License" src="https://img.shields.io/npm/l/@antelopejs/dms-api?style=for-the-badge&labelColor=000000&color=000000"></a>
|
|
7
|
+
<a href="https://discord.gg/sjK28QHrA7"><img alt="Discord" src="https://img.shields.io/badge/Discord-18181B?logo=discord&style=for-the-badge&color=000000"></a>
|
|
8
|
+
<a href="https://dms.antelopejs.com/docs/modules/api"><img alt="Documentation" src="https://img.shields.io/badge/Docs-18181B?style=for-the-badge&color=000000"></a>
|
|
9
|
+
|
|
10
|
+
The API console of the AntelopeJS DMS: health, request logs, route statistics and a tester.
|
|
11
|
+
|
|
7
12
|
</div>
|
|
8
13
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
The page also pauses by itself while its browser tab is hidden and while you
|
|
40
|
-
type in the Tester, and a request table holds its rows while one of them is
|
|
41
|
-
open in the side panel (and, in the Request logs, while you read further
|
|
42
|
-
down, search or sort otherwise than newest first), saying why ("Table on
|
|
43
|
-
hold · search active"). The choice is one for the three pages, and
|
|
44
|
-
`?live=0` opens a page paused.
|
|
45
|
-
|
|
46
|
-
A request opens in a side panel on the right, on a single click on its row,
|
|
47
|
-
from every request table: the panel is titled with its method and path, J / K
|
|
48
|
-
step through the rows shown, and the URL names it (`?record=`), so a link or a
|
|
49
|
-
reload opens it again. In the Request logs, `/` opens the search and `?` the
|
|
50
|
-
list of shortcuts; in Routes, `/` opens the route filter. The DMS Shortcuts
|
|
51
|
-
page lists them. The period of a page is its period selector's (1H, 24H, 7D,
|
|
52
|
-
30D, and "All time" in the Request logs), kept in the URL
|
|
53
|
-
(`?api.period=last-24h`); without one, the page opens on the last period
|
|
54
|
-
picked on any of the three pages, else the last 24 hours. An incident of the
|
|
55
|
-
Overview opens the Request logs narrowed to its own range
|
|
56
|
-
(`?since=&until=`), a linked filter within the page's period. The tabs of a
|
|
57
|
-
route are named in the URL by their slot (`?tab=tester`).
|
|
58
|
-
Dates and times follow the user's Language & region preferences (time zone,
|
|
59
|
-
clock, date format), on a 24-hour clock by default.
|
|
60
|
-
|
|
61
|
-
This module is the dashboard for your API, not the HTTP server implementation.
|
|
62
|
-
Your application still needs an API provider such as `@antelopejs/api`, the
|
|
63
|
-
DMS runtime, and a database.
|
|
64
|
-
|
|
65
|
-
## Start with the demo
|
|
66
|
-
|
|
67
|
-
[template-dms-demo](https://github.com/AntelopeJS/template-dms-demo) already
|
|
68
|
-
loads this module and its supporting infrastructure. Follow its README to
|
|
69
|
-
install the project, start both backend and frontend processes, and create
|
|
70
|
-
the first administrator.
|
|
71
|
-
|
|
72
|
-
For an existing DMS project, add a package module entry to the `modules` map
|
|
73
|
-
in `antelope.config.ts`:
|
|
74
|
-
|
|
75
|
-
```ts
|
|
76
|
-
"dms-api": {
|
|
77
|
-
source: {
|
|
78
|
-
type: "package",
|
|
79
|
-
package: "@antelopejs/dms-api",
|
|
80
|
-
version: ">=0.0.1 <1.0.0",
|
|
81
|
-
},
|
|
82
|
-
},
|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
## What it does
|
|
17
|
+
|
|
18
|
+
- Tells whether your API is healthy, since when and why not, with traffic, errors and the slowest routes.
|
|
19
|
+
- Captures every request of your project's routes with its error, timing, headers and bodies (size-capped and redacted).
|
|
20
|
+
- Lists every registered route with its statistics and a contract inferred from code and traffic.
|
|
21
|
+
- Sends test requests from a built-in tester, logged apart from real traffic.
|
|
22
|
+
- Applies its settings (watched routes, retention, captured headers, slow threshold) without a restart.
|
|
23
|
+
|
|
24
|
+
It is the dashboard for your API, not the HTTP server: the project still needs an API provider such as `@antelopejs/api`.
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
Run the AntelopeJS CLI from the root of a project that already loads `@antelopejs/dms`:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
ajs project modules add @antelopejs/dms-api
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Quick start
|
|
35
|
+
|
|
36
|
+
The module works without configuration. Restart the backend, then the frontend, and open **Modules → API** (`/modules/api`). Review the [configuration](https://dms.antelopejs.com/docs/modules/api/configuration) before capturing real traffic: request logs can hold application data.
|
|
37
|
+
|
|
38
|
+
To try it with sample traffic, clone this repository and run its playground:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pnpm install && pnpm dev # backend
|
|
42
|
+
pnpm frontend:dev # dashboard, in a second terminal
|
|
43
|
+
pnpm --dir playground traffic # a few hundred demo requests
|
|
83
44
|
```
|
|
84
45
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
the error-rate thresholds as ratios (`0.05`), and the `api.get-api-health`
|
|
135
|
-
automation answers `failingRoutes` instead of `routesWithErrors24h`.
|
|
136
|
-
|
|
137
|
-
Request logs can contain application data. Review the capture and retention
|
|
138
|
-
settings before collecting real traffic, and use synthetic requests for
|
|
139
|
-
screenshots or shared demos. The module prunes logs and statistics hourly.
|
|
140
|
-
|
|
141
|
-
## Development
|
|
142
|
-
|
|
143
|
-
Use the pnpm version declared in `package.json`. The repository's `dev` script
|
|
144
|
-
starts its playground backend; `frontend:dev` starts the published Inertia
|
|
145
|
-
dashboard loader. The playground connects to MongoDB at
|
|
146
|
-
`mongodb://localhost:27017` unless `MONGO_URL` points it elsewhere. Run `pnpm --dir playground traffic` while the playground runs to send
|
|
147
|
-
its demo storefront routes a few hundred requests (healthy, slow, failing and
|
|
148
|
-
client errors), so every page has something to show. `pnpm build`
|
|
149
|
-
compiles the backend, and `pnpm test` runs the backend unit tests (`tests/`)
|
|
150
|
-
followed by the frontend test suite, and `pnpm knip` checks the dependencies
|
|
151
|
-
of both. To build and typecheck the frontend module against the installed
|
|
152
|
-
DMS, run `pnpm exec ajs dms verify-source -m ../frontend-vue` from
|
|
153
|
-
`playground/`; or set `DMS_FRONTEND_WORKSPACE` to the workspace generated by
|
|
154
|
-
`ajs dms prepare`, then run `pnpm --dir frontend-vue typecheck`.
|
|
46
|
+
[template-dms-demo](https://github.com/AntelopeJS/template-dms-demo) also loads the module.
|
|
47
|
+
|
|
48
|
+
## Compatibility
|
|
49
|
+
|
|
50
|
+
| Package | Version |
|
|
51
|
+
| --- | --- |
|
|
52
|
+
| `@antelopejs/dms` | `>=0.9.0 <1.0.0` |
|
|
53
|
+
| `@antelopejs/interface-dms` | `>=0.7.0 <1.0.0` |
|
|
54
|
+
| `@antelopejs/dms-frontend` (renderer) | `>=0.6.0 <0.7.0` |
|
|
55
|
+
| API provider | `@antelopejs/api` |
|
|
56
|
+
| Database | an `@antelopejs/interface-database` implementation, such as `@antelopejs/mongodb` |
|
|
57
|
+
|
|
58
|
+
On DMS 0.8, use `@antelopejs/dms-api` 0.3. Upgrading from 0.1? Read the [FAQ](https://dms.antelopejs.com/docs/modules/api/faq#upgrading-from-01).
|
|
59
|
+
|
|
60
|
+
## Documentation
|
|
61
|
+
|
|
62
|
+
- [Introduction](https://dms.antelopejs.com/docs/modules/api/introduction)
|
|
63
|
+
- [Installation](https://dms.antelopejs.com/docs/modules/api/installation)
|
|
64
|
+
- [Configuration](https://dms.antelopejs.com/docs/modules/api/configuration)
|
|
65
|
+
- [Usage](https://dms.antelopejs.com/docs/modules/api/usage/overview)
|
|
66
|
+
- [Extending](https://dms.antelopejs.com/docs/modules/api/extending)
|
|
67
|
+
- [FAQ](https://dms.antelopejs.com/docs/modules/api/faq)
|
|
68
|
+
|
|
69
|
+
The guide's sources live in [`docs/`](./docs). The package also ships the `dms-api` Claude Code skill in [`skills/`](./skills), declared under `antelopeJs.skills`.
|
|
70
|
+
|
|
71
|
+
## Contributing
|
|
72
|
+
|
|
73
|
+
Read [CONTRIBUTING.md](./CONTRIBUTING.md) before opening a pull request. Use the pnpm version declared in `package.json`. The playground connects to MongoDB at `mongodb://localhost:27017` unless `MONGO_URL` points elsewhere.
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pnpm install
|
|
77
|
+
pnpm dev # playground backend
|
|
78
|
+
pnpm frontend:dev # dashboard, in a second terminal
|
|
79
|
+
pnpm lint
|
|
80
|
+
pnpm typecheck
|
|
81
|
+
pnpm test # backend unit tests (tests/), then the frontend suite
|
|
82
|
+
pnpm knip
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
<details>
|
|
86
|
+
<summary>Repository notes</summary>
|
|
87
|
+
|
|
88
|
+
- To build and typecheck the frontend module against the installed DMS, run `pnpm exec ajs dms verify-source -m ../frontend-vue` from `playground/`, or set `DMS_FRONTEND_WORKSPACE` to the workspace generated by `ajs dms prepare` and run `pnpm --dir frontend-vue typecheck`.
|
|
89
|
+
|
|
90
|
+
</details>
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
[Apache-2.0](./LICENSE)
|
|
@@ -12,6 +12,7 @@ declare const ApiSettingsModel_base: {
|
|
|
12
12
|
delete(id: string): Promise<number>;
|
|
13
13
|
};
|
|
14
14
|
readonly schemaName: string;
|
|
15
|
+
readonly tableClass: import("@antelopejs/interface-database-decorators").Constructible<ApiSettings>;
|
|
15
16
|
fromPlainData(obj: any): ApiSettings;
|
|
16
17
|
fromDatabase(obj: any): ApiSettings | undefined;
|
|
17
18
|
toDatabase(obj: any): Record<string, any>;
|
|
@@ -64,6 +64,7 @@ declare const RequestLogModel_base: {
|
|
|
64
64
|
delete(id: string): Promise<number>;
|
|
65
65
|
};
|
|
66
66
|
readonly schemaName: string;
|
|
67
|
+
readonly tableClass: import("@antelopejs/interface-database-decorators").Constructible<RequestLog>;
|
|
67
68
|
fromPlainData(obj: any): RequestLog;
|
|
68
69
|
fromDatabase(obj: any): RequestLog | undefined;
|
|
69
70
|
toDatabase(obj: any): Record<string, any>;
|
|
@@ -12,6 +12,7 @@ declare const RouteModel_base: {
|
|
|
12
12
|
delete(id: string): Promise<number>;
|
|
13
13
|
};
|
|
14
14
|
readonly schemaName: string;
|
|
15
|
+
readonly tableClass: import("@antelopejs/interface-database-decorators").Constructible<Route>;
|
|
15
16
|
fromPlainData(obj: any): Route;
|
|
16
17
|
fromDatabase(obj: any): Route | undefined;
|
|
17
18
|
toDatabase(obj: any): Record<string, any>;
|
|
@@ -13,6 +13,7 @@ declare const RouteStatisticsModel_base: {
|
|
|
13
13
|
delete(id: string): Promise<number>;
|
|
14
14
|
};
|
|
15
15
|
readonly schemaName: string;
|
|
16
|
+
readonly tableClass: import("@antelopejs/interface-database-decorators").Constructible<RouteStatistics>;
|
|
16
17
|
fromPlainData(obj: any): RouteStatistics;
|
|
17
18
|
fromDatabase(obj: any): RouteStatistics | undefined;
|
|
18
19
|
toDatabase(obj: any): Record<string, any>;
|
|
@@ -160,8 +160,10 @@ const { formatLocale: locale } = useRegionalFormat({ locale: 'format' })
|
|
|
160
160
|
const dateFormat = useDateFormat()
|
|
161
161
|
const toast = useToast()
|
|
162
162
|
const { isLive } = usePageLive()
|
|
163
|
-
const { data, error, pending,
|
|
164
|
-
|
|
163
|
+
const { data, error, pending, refresh } = useApiData<HealthPayload>(
|
|
164
|
+
() => props.fetchUrl,
|
|
165
|
+
{ refreshOnPageRefresh: false },
|
|
166
|
+
)
|
|
165
167
|
|
|
166
168
|
// Read again on the live feed at the page's pace, and after a quiet minute:
|
|
167
169
|
// the verdict judges time too. Never while paused.
|
|
@@ -244,7 +246,7 @@ function heldFor(health: HealthPayload): string {
|
|
|
244
246
|
// A failed refresh keeps the last figures on screen: they are no longer live.
|
|
245
247
|
const stale = computed(() => !!error.value && !!data.value)
|
|
246
248
|
const staleSince = computed(() =>
|
|
247
|
-
|
|
249
|
+
data.value ? formatClock(data.value.checkedAt, dateFormat.value) : '',
|
|
248
250
|
)
|
|
249
251
|
|
|
250
252
|
const look = computed(() => (data.value ? LOOKS[data.value.verdict] : null))
|
|
@@ -337,6 +339,10 @@ const incident = computed(() => {
|
|
|
337
339
|
}
|
|
338
340
|
})
|
|
339
341
|
|
|
342
|
+
// The tooltip of the duration waits for the browser: it writes a weekday,
|
|
343
|
+
// which the server's ICU may punctuate otherwise.
|
|
344
|
+
const incidentTitle = useClientValue(() => incident.value?.title)
|
|
345
|
+
|
|
340
346
|
// One time only: once stale, the banner says when the figures date from.
|
|
341
347
|
const checked = computed(() =>
|
|
342
348
|
data.value && !stale.value
|
|
@@ -431,7 +437,7 @@ const metrics = computed<HeroMetric[]>(() => {
|
|
|
431
437
|
:aria-busy="pending"
|
|
432
438
|
:aria-label="t('api.health.label')"
|
|
433
439
|
>
|
|
434
|
-
<DmsCard v-if="pending" :padded="false" class="px-6 py-6">
|
|
440
|
+
<DmsCard v-if="pending && !data" :padded="false" class="px-6 py-6">
|
|
435
441
|
<div class="flex items-center gap-6">
|
|
436
442
|
<USkeleton class="size-16 rounded-full" />
|
|
437
443
|
<div class="flex flex-col gap-2">
|
|
@@ -554,7 +560,7 @@ const metrics = computed<HeroMetric[]>(() => {
|
|
|
554
560
|
<time
|
|
555
561
|
v-if="incident"
|
|
556
562
|
:datetime="incident.datetime"
|
|
557
|
-
:title="
|
|
563
|
+
:title="incidentTitle"
|
|
558
564
|
>
|
|
559
565
|
{{ incident.text }}
|
|
560
566
|
</time>
|
|
@@ -41,8 +41,9 @@ const { formatLocale: locale, formatNumber } = useRegionalFormat({
|
|
|
41
41
|
locale: 'format',
|
|
42
42
|
})
|
|
43
43
|
const dateFormat = useDateFormat()
|
|
44
|
-
const { data, error, pending, refresh } =
|
|
44
|
+
const { data, error, pending, refresh } = useApiData<LivePayload>(
|
|
45
45
|
() => props.fetchUrl,
|
|
46
|
+
{ refreshOnPageRefresh: false },
|
|
46
47
|
)
|
|
47
48
|
|
|
48
49
|
// The paused state is the browser's (the DMS remembers it per page), the
|
|
@@ -239,7 +240,7 @@ const share = (part: number, bar: { heights: Record<string, number> }) => {
|
|
|
239
240
|
</template>
|
|
240
241
|
|
|
241
242
|
<div class="px-3 pb-2 pt-1">
|
|
242
|
-
<div v-if="pending" class="flex h-[112px] items-end gap-[2px] px-2">
|
|
243
|
+
<div v-if="pending && !data" class="flex h-[112px] items-end gap-[2px] px-2">
|
|
243
244
|
<USkeleton
|
|
244
245
|
v-for="index in 60"
|
|
245
246
|
:key="index"
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { computed, nextTick, ref, watch } from 'vue'
|
|
2
|
+
import { computed, nextTick, onMounted, ref, watch } from 'vue'
|
|
3
3
|
import { byteLength, formatMs } from '../../utils/format'
|
|
4
|
+
import { errorStatus } from '../../utils/http'
|
|
4
5
|
import {
|
|
5
6
|
durationScale,
|
|
6
7
|
fullDateTime,
|
|
@@ -128,16 +129,20 @@ const page = computed(() => {
|
|
|
128
129
|
: ''
|
|
129
130
|
})
|
|
130
131
|
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
? `${props.detailUrl}/${encodeURIComponent(requestId.value)}`
|
|
139
|
-
: null,
|
|
132
|
+
const logRead = useApiData<RequestLog>(
|
|
133
|
+
() =>
|
|
134
|
+
requestId.value && isRequestId(requestId.value)
|
|
135
|
+
? `${props.detailUrl}/${encodeURIComponent(requestId.value)}`
|
|
136
|
+
: null,
|
|
137
|
+
// A request's log never changes once captured.
|
|
138
|
+
{ refreshOnPageRefresh: false },
|
|
140
139
|
)
|
|
140
|
+
const { error, refresh } = logRead
|
|
141
|
+
// Another request shows nothing until its log is in.
|
|
142
|
+
const log = computed(() =>
|
|
143
|
+
logRead.placeholder.value ? null : logRead.data.value,
|
|
144
|
+
)
|
|
145
|
+
const pending = computed(() => logRead.pending.value && !log.value)
|
|
141
146
|
const apiOrigin = useApiOrigin(() => log.value?.apiOrigin)
|
|
142
147
|
|
|
143
148
|
const tab = ref('overview')
|
|
@@ -308,33 +313,30 @@ const seeAlso = computed(() => {
|
|
|
308
313
|
})
|
|
309
314
|
|
|
310
315
|
// A log stored without the reason of a missing body: the body capture turned
|
|
311
|
-
// off says it. Read once per session, only then, and by an
|
|
312
|
-
// refusal leaves the generic reason.
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
{
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
watch(
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
.catch(() => undefined)
|
|
331
|
-
},
|
|
332
|
-
{ immediate: true },
|
|
316
|
+
// off says it. Read once per session, only then, in the browser, and by an
|
|
317
|
+
// owner only: a refusal leaves the generic reason.
|
|
318
|
+
const settingsSummary = useApiData<{ requestLogMaxBodyKb?: number }>(
|
|
319
|
+
SETTINGS_SUMMARY_API,
|
|
320
|
+
{ immediate: false, server: false, refreshOnPageRefresh: false },
|
|
321
|
+
)
|
|
322
|
+
|
|
323
|
+
onMounted(() =>
|
|
324
|
+
watch(
|
|
325
|
+
log,
|
|
326
|
+
(value) => {
|
|
327
|
+
if (!value || settingsSummary.status.value !== 'idle') return
|
|
328
|
+
const unexplained =
|
|
329
|
+
(!value.requestBody && !value.requestBodyOmitted) ||
|
|
330
|
+
(!value.responseBody && !value.responseBodyOmitted)
|
|
331
|
+
if (unexplained) void settingsSummary.execute()
|
|
332
|
+
},
|
|
333
|
+
{ immediate: true },
|
|
334
|
+
),
|
|
333
335
|
)
|
|
334
336
|
|
|
335
337
|
function omission(reason: string | null | undefined) {
|
|
336
338
|
if (reason) return reason
|
|
337
|
-
const summary = settingsSummary.value
|
|
339
|
+
const summary = settingsSummary.data.value
|
|
338
340
|
return summary && summary.requestLogMaxBodyKb === 0 ? 'disabled' : null
|
|
339
341
|
}
|
|
340
342
|
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
computed,
|
|
4
|
+
onBeforeUnmount,
|
|
5
|
+
onMounted,
|
|
6
|
+
ref,
|
|
7
|
+
shallowRef,
|
|
8
|
+
watch,
|
|
9
|
+
} from 'vue'
|
|
3
10
|
import {
|
|
4
11
|
createRetentionGuard,
|
|
5
12
|
isLowered,
|
|
@@ -39,7 +46,6 @@ const PREVIOUS_PERIOD_DAYS = 30
|
|
|
39
46
|
|
|
40
47
|
const { t } = useI18n()
|
|
41
48
|
const { confirm } = useConfirm()
|
|
42
|
-
const { $authFetch } = useAuthFetch()
|
|
43
49
|
const form = useEnclosingForm()
|
|
44
50
|
const { formatNumber } = useRegionalFormat({ locale: 'format' })
|
|
45
51
|
|
|
@@ -88,14 +94,16 @@ watch(
|
|
|
88
94
|
)
|
|
89
95
|
onBeforeUnmount(() => clearTimeout(impactTimer))
|
|
90
96
|
|
|
91
|
-
const
|
|
97
|
+
const impactRead = useApiData<RetentionImpact>(() =>
|
|
92
98
|
impactDays.value == null || !props.id
|
|
93
99
|
? null
|
|
94
100
|
: impactUrlOf(props.id, impactDays.value),
|
|
95
101
|
)
|
|
96
102
|
const impact = computed(() =>
|
|
97
|
-
lowered.value &&
|
|
98
|
-
|
|
103
|
+
lowered.value &&
|
|
104
|
+
impactDays.value === model.value &&
|
|
105
|
+
!impactRead.placeholder.value
|
|
106
|
+
? impactRead.data.value
|
|
99
107
|
: null,
|
|
100
108
|
)
|
|
101
109
|
|
|
@@ -139,25 +147,48 @@ function pendingChange(): RetentionChange | null {
|
|
|
139
147
|
}
|
|
140
148
|
|
|
141
149
|
/**
|
|
142
|
-
* What
|
|
143
|
-
* the change, before the field's own count came back, still says it.
|
|
150
|
+
* What each change deletes, read when the dialog opens: a save sent right
|
|
151
|
+
* after the change, before the field's own count came back, still says it.
|
|
152
|
+
* A count that cannot be read is left out of the dialog.
|
|
144
153
|
*/
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
154
|
+
const confirmed = shallowRef<RetentionChange[]>([])
|
|
155
|
+
const deletedCounts = useApiData<Array<number | undefined>>(
|
|
156
|
+
() =>
|
|
157
|
+
confirmed.value.length
|
|
158
|
+
? `dms-api:retention-confirm:${confirmed.value
|
|
159
|
+
.map((change) => impactUrlOf(change.field, change.to))
|
|
160
|
+
.join(' ')}`
|
|
161
|
+
: null,
|
|
162
|
+
({ $authFetch, signal }) =>
|
|
163
|
+
Promise.all(
|
|
164
|
+
confirmed.value.map((change) =>
|
|
165
|
+
$authFetch<RetentionImpact>(impactUrlOf(change.field, change.to), {
|
|
166
|
+
signal,
|
|
167
|
+
}).then(
|
|
168
|
+
(impact) => impact.requests,
|
|
169
|
+
() => undefined,
|
|
170
|
+
),
|
|
171
|
+
),
|
|
172
|
+
),
|
|
173
|
+
{
|
|
174
|
+
immediate: false,
|
|
175
|
+
server: false,
|
|
176
|
+
watch: false,
|
|
177
|
+
refreshOnPageRefresh: false,
|
|
178
|
+
},
|
|
179
|
+
)
|
|
157
180
|
|
|
158
181
|
/** One dialog for every lowered retention of the form, with what each deletes. */
|
|
159
182
|
async function askToConfirm(changes: RetentionChange[]): Promise<boolean> {
|
|
160
|
-
|
|
183
|
+
confirmed.value = changes
|
|
184
|
+
await deletedCounts.execute()
|
|
185
|
+
const counts = (deletedCounts.data.value ?? []).map((requests) =>
|
|
186
|
+
requests === undefined
|
|
187
|
+
? undefined
|
|
188
|
+
: t('api.settings.retention.confirm_requests', {
|
|
189
|
+
requests: formatNumber(requests),
|
|
190
|
+
}),
|
|
191
|
+
)
|
|
161
192
|
return confirm({
|
|
162
193
|
title: t('api.settings.retention.confirm_title'),
|
|
163
194
|
description: t('api.settings.retention.confirm_description'),
|