@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 CHANGED
@@ -1,154 +1,94 @@
1
+ <div align="center">
2
+
1
3
  # @antelopejs/dms-api
2
4
 
3
- <div align="center">
4
- <a href="./LICENSE"><img alt="License" src="https://img.shields.io/badge/license-Apache--2.0-blue?style=for-the-badge&labelColor=000000"></a>
5
- <a href="https://discord.gg/sjK28QHrA7"><img src="https://img.shields.io/badge/Discord-18181B?logo=discord&style=for-the-badge&color=000000" alt="Discord"></a>
6
- <a href="https://antelopejs.com"><img src="https://img.shields.io/badge/Docs-18181B?style=for-the-badge&color=000000" alt="Documentation"></a>
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
- `@antelopejs/dms-api` adds an API console to the AntelopeJS DMS. Open
10
- **Modules → API** (`/modules/api`):
11
-
12
- - **Overview**: is the API healthy, since when and why not, with traffic,
13
- errors, the routes needing attention and the slowest ones.
14
- - **Request logs**: every captured request, filtered by status class, method,
15
- slowness or period; a request opens with its error, timing, headers and
16
- bodies, and can be replayed in the tester.
17
- - **Routes**: every registered route with its statistics, its contract
18
- (inferred from its code and its traffic) and a tester.
19
- - **API settings**: the routes the console watches, retention, captured
20
- headers and the slow threshold.
21
-
22
- It requires `@antelopejs/dms` `>=0.8.0 <0.9.0` (`@antelopejs/interface-dms`
23
- 0.6.0) and `@antelopejs/dms-frontend` `>=0.5.2 <0.6.0`. These DMS releases
24
- bring the pieces the console is built on: the row side panel, the page's
25
- Live / Pause state and its holds, the refresh the console's own blocks share
26
- with the DMS blocks, the period kept in the URL, the column tones, the
27
- `Guard` block, the form API its settings fields use and the redirect of
28
- `/modules/api` to the Overview.
29
-
30
- The Overview, the Request logs and Routes have the DMS **Live / Pause**
31
- toggle (the L key). Live, the default, the page follows new requests as the
32
- DMS realtime channel announces them, each block, the console's own included,
33
- read again at most every 5 s (Request logs), 10 s (Overview) or 15 s
34
- (Routes), every minute once the Overview or Routes show a week or more, and
35
- on that clock while the realtime channel is down. Paused, nothing is read:
36
- the toggle says what was missed ("Paused · 40 new requests · 2 in 5xx"), the
37
- request tables keep their rows, search, sort and "Load more" included, and
38
- offer "40 new requests · 2 in 5xx · Show"; resuming reads each block once.
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
+ ![The API Overview: health verdict, routes needing attention, slowest routes and error share](./docs/images/overview.png)
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
- Install the declared modules with `pnpm exec ajs project modules install`,
86
- then restart the backend before restarting the frontend. The module registers
87
- its Vue 3 Inertia frontend module automatically through
88
- `frontend-vue/dms.frontend.ts`.
89
-
90
- ## Configuration and data handling
91
-
92
- [src/config.ts](src/config.ts) defines the supported settings, including
93
- statistics and request-log retention, the slow-request threshold, body-size
94
- limits, and the header capture allowlist. Retention uses milliseconds; body
95
- limits use bytes. Settings saved through the dashboard override the module
96
- configuration at runtime. A field set back to its module default ("Use
97
- default") holds no override; the retentions have no such button, since
98
- lowering one deletes data. An empty list of captured headers is an override
99
- of its own: no header is captured.
100
-
101
- The cURL and fetch snippets of a route and a request are written against the
102
- DMS's public API origin, its `apiBaseUrl` (read through `GetApiBaseUrl()`):
103
- set it to the URL clients reach the API at, such as `https://api.example.com`.
104
- Under `ajs dms dev` it follows the dev server.
105
-
106
- Statistics are kept 90 days by default, and the dashboard offers 30, 60 or
107
- 90 days. The 30D period compares itself with the 30 days before it, so it
108
- needs 60 days or more: with 30 days, the 30D comparison is unavailable.
109
- Request logs, which hold full requests, are kept 30 days by default,
110
- independently of the statistics. Lowering a retention from the dashboard shows how much the
111
- next hourly prune deletes and asks to confirm it.
112
-
113
- The module configuration follows the dashboard's rules: the module does not
114
- start with a value the Settings page would refuse (statistics kept other than
115
- 30, 60 or 90 days, a slow threshold off its 50 ms step, a body cap or a log
116
- retention out of bounds, a secret header to capture).
117
-
118
- The console only counts your API's traffic. Its own calls (`/api/monitoring`),
119
- the DMS's (`/dms`, the realtime channel, the page layouts, the session check,
120
- its Settings pages and their tables) and the DMS console's pages are neither
121
- logged nor counted. Requests sent from the Tester are logged, marked as such,
122
- but left out of the statistics, the health and the incidents. The Tester marks
123
- its calls with a short-lived token the module signs
124
- (`x-antelopejs-api-source`), which only a user allowed to use the Tester
125
- obtains: a client cannot leave the statistics by declaring itself the Tester.
126
- Behind several instances, give them the same `testerSourceSecret` so each one
127
- accepts the tokens of the others.
128
-
129
- ### Upgrading from 0.1
130
-
131
- The stored data of earlier versions is not migrated. Drop the
132
- `request_log`, `routes_statistics` and `migrations` tables of the `dms-api`
133
- schema when upgrading; the module creates them again. The API settings answer
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, receivedAt, refresh } =
164
- useApiResource<HealthPayload>(() => props.fetchUrl)
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
- receivedAt.value ? formatClock(receivedAt.value, dateFormat.value) : '',
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="incident.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 } = useApiResource<LivePayload>(
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
- data: log,
133
- error,
134
- pending,
135
- refresh,
136
- } = useApiResource<RequestLog>(() =>
137
- requestId.value && isRequestId(requestId.value)
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 owner only: a
312
- // refusal leaves the generic reason.
313
- // Null until asked, false once refused.
314
- const settingsSummary = useDmsState<
315
- { requestLogMaxBodyKb?: number } | false | null
316
- >('dms-api:settings-summary', () => null)
317
- const { $authFetch } = useAuthFetch()
318
-
319
- watch(
320
- log,
321
- (value) => {
322
- if (!value || settingsSummary.value !== null) return
323
- const unexplained =
324
- (!value.requestBody && !value.requestBodyOmitted) ||
325
- (!value.responseBody && !value.responseBodyOmitted)
326
- if (!unexplained) return
327
- settingsSummary.value = false
328
- $authFetch<{ requestLogMaxBodyKb?: number }>(SETTINGS_SUMMARY_API)
329
- .then((summary) => (settingsSummary.value = summary))
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 { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
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 impactResource = useApiResource<RetentionImpact>(() =>
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 && impactDays.value === model.value
98
- ? impactResource.data.value
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 a change deletes, read when the dialog opens: a save sent right after
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
- async function deletedRequests(change: RetentionChange) {
146
- try {
147
- const read = await $authFetch<RetentionImpact>(
148
- impactUrlOf(change.field, change.to),
149
- )
150
- return t('api.settings.retention.confirm_requests', {
151
- requests: formatNumber(read.requests),
152
- })
153
- } catch {
154
- return undefined
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
- const counts = await Promise.all(changes.map(deletedRequests))
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'),