feat(nutrients): accept measurements:write tokens on the nutrient batch

A bridge such as a food tracker can now post daily nutrient totals with
the measurement token. The credential picks the source row: a scoped
token writes EXTERNAL, the native client keeps writing APPLE_HEALTH, and
the body has no say. Bridge tokens count in their own rate-limit bucket,
and the source is recorded in the audit row.

The write phase moves into writeNutrientDayTotals so the route keeps
only parsing, validation and bookkeeping. The scope guard now freezes
four doors for measurements:write. Refs #1402.
This commit is contained in:
Marc-André Bombeck committed 2026-11-17 18:47:11 +01:00
1 parent 8f96c2f0a2
commit 7c40ba8202
12 files changed
+485 -186

No files matched your search

+4 -2
View File
@@ -65,8 +65,10 @@ before treating a warning as a regression.
- `POST /api/mcp/tokens` mints `health:read` (optionally plus
`health:write`), audience-bound to `/mcp` and refused on REST writes;
- `POST /api/tokens/measurements` mints `measurements:write`, accepted by
`POST /api/measurements` and `POST /api/measurements/batch` only, on the
holder's own record only. The readings it writes carry `source: EXTERNAL`
`POST /api/measurements`, `POST /api/measurements/batch`,
`POST /api/custom-metrics/{id}/entries` and `POST /api/nutrients/batch`
only, on the holder's own record only. The readings and nutrient day
totals it writes carry `source: EXTERNAL`
and are linked to the token; whether the HealthLog app writes them into
Apple Health is the token's `mirrorToAppleHealth` setting (off by
default, changed with `PATCH /api/tokens/{id}`), resolved onto every