Apple Health (Salud): a per-profile ingest endpoint, and a tab that draws it
Tests / test (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s

An iOS automation in Health Auto Export POSTs Apple Health to /api/vitals/ingest,
and the new Salud tab (next to Plan) draws whatever arrived: steps, heart rate,
sleep, weight, oxygen, workouts and every other metric HAE can export, grouped into
cards with a trend, a sparkline and a 7/30/90/365-day range. Nothing on that screen
is an input, and the watch's workouts stay out of the history on purpose — they
carry no sets and no weights, so folding them into progression, PRs and the recovery
model would be inventing data.

The interesting part is duplicates. A five-minute automation re-sends overlapping
windows: with Date Range "Today", appending would count a day of steps again on
every run, and with "Since Last Sync", replacing would throw away everything but the
last five minutes. So the endpoint decides per payload instead. Datapoints that sit
on midnight are HAE's own day grouping, i.e. a *total*, and a day total replaces the
day it names — re-sending the same day all afternoon converges on that day's total.
Anything else is a real sample, identified by its instant plus its numbers and
stored once, which is right for overlapping and disjoint windows alike. Every sync
answers with a receipt (received / duplicates / stored), so a misconfigured
automation is visible rather than silent, and day keys come from the date the phone
wrote — never the server's clock, or every evening's steps would land on tomorrow.

Per profile and private by construction. Each profile mints its own ingest key
(Salud → ⚙), which is write-only: it can add to that one profile's health file and
cannot read a single number back, so a key leaking out of a phone is a nuisance
rather than a disclosure. It is its own credential, so rotating it disconnects a
phone without signing anybody out anywhere. The data lives in
data/vitals-<uid>.json, outside the synced state document, so a year of heart rate
never round-trips through localStorage on every device, and it is bounded on write:
400 days per metric, a 72 h dedupe ledger, the newest 300 workouts.

Two traps that only exist in production, both fixed here and both of which would
have shipped broken. api/Dockerfile copies the modules server.js imports by name,
and vitals.js was not on that list — a container that boots straight into
ERR_MODULE_NOT_FOUND. And the web container's nginx capped every /api body at 5 MB,
which a health export with Summarize Data off exceeds; that one route now gets the
API's own 32 MB while every other path keeps 5 MB, with the shared proxy settings
hoisted to server level so the two locations cannot drift apart.

Coverage: vitals.js (13 tests — overlapping, disjoint, day-grouped, raw, heart rate,
sleep, blood pressure, pruning, timezones), the routes against a real server (4 —
isolation between profiles, a key that cannot read, ten re-sends changing nothing),
the card model (18) and the screen (4). docs/HEALTH.md has the Health Auto Export
settings and the merge table; the five endpoints are in api/openapi.yaml under the
health tag, and website/api.html is rebuilt from it.
This commit is contained in:
dsantillan committed 2026-09-23 10:11:00 -04:00
1 parent 0819d03efb
commit 691e664d3f
22 files changed
+2897 -42

No files matched your search

+28
View File
@@ -1,5 +1,33 @@
# Changelog
## Sin publicar — Apple Health (Salud)
A new **Salud** tab, next to Plan, and an endpoint behind it. An iOS automation in *Health Auto
Export* POSTs Apple Health to your profile and the data shows up as read-only cards: steps, heart
rate, sleep, weight, oxygen, workouts, and every other metric HAE can export — including ones this
fork has never heard of, which land under **Other** with a humanised name and a detail sheet listing
every field the watch sent.
Per profile, and private by construction. Each profile mints its own **ingest key** (write-only: it
can add to that one profile's health file and cannot read a single number back), and rotating it
disconnects a phone without signing anybody out. The health data lives in its own
`data/vitals-<uid>.json`, outside the synced state document, so a year of heart rate never
round-trips through `localStorage` on every device.
The interesting problem was duplicates. A five-minute automation re-sends overlapping windows, and
"append" would count a day of steps again on every run while "replace" would throw away everything
but the last five minutes under a different HAE setting. The receiver decides per payload instead:
day-grouped totals replace the day they name (converging on the day's total no matter how often it
is re-sent), while real samples are identified by instant plus numbers and stored once — so a sync
every five minutes, hourly, or once a day all land the same way. `docs/HEALTH.md` has the settings,
the merge table and the one configuration that is merely approximate rather than wrong.
Also here: the watch's workouts are shown **read-only** in Salud and deliberately kept out of the
history — they carry no sets or weights, so folding them into progression, PRs and the recovery
model would be inventing data. Coverage: `api/vitals.js` (13 tests), the routes against a real
server (4), the card model (18), plus the endpoint documented in `api/openapi.yaml` and the new
`docs/HEALTH.md` setup guide.
<!-- Everything below this note is the **upstream** changelog, kept verbatim: the entries name the
project as it was called then (openGym) and reference upstream issue and merge-request
numbers. They are a record of what actually shipped, so they are deliberately not rewritten