From 691e664d3fce62f20053f0420ae007324a42fb2a Mon Sep 17 00:00:00 2001 From: Daniel Santillan Date: Wed, 23 Sep 2026 10:11:00 -0400 Subject: [PATCH] Apple Health (Salud): a per-profile ingest endpoint, and a tab that draws it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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-.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. --- CHANGELOG.md | 28 ++ CLAUDE.md | 22 +- README.md | 1 + api/Dockerfile | 7 +- api/openapi.yaml | 272 +++++++++++++++ api/server.js | 166 ++++++++- api/test/server-vitals.test.js | 239 +++++++++++++ api/test/vitals.test.js | 288 +++++++++++++++ api/vitals.js | 405 ++++++++++++++++++++++ docs/HEALTH.md | 185 ++++++++++ frontend/src/App.jsx | 5 + frontend/src/components/TabBar.jsx | 4 +- frontend/src/index.css | 29 ++ frontend/src/lib/audit.js | 11 +- frontend/src/lib/vitals-view.js | 355 +++++++++++++++++++ frontend/src/lib/vitals-view.test.js | 206 +++++++++++ frontend/src/locales/es.js | 140 ++++++++ frontend/src/views/Health.jsx | 276 +++++++++++++++ frontend/src/views/Health.render.test.jsx | 112 ++++++ frontend/src/views/Settings.jsx | 5 + web/nginx.conf.template | 77 ++-- website/api.html | 106 +++++- 22 files changed, 2897 insertions(+), 42 deletions(-) create mode 100644 api/test/server-vitals.test.js create mode 100644 api/test/vitals.test.js create mode 100644 api/vitals.js create mode 100644 docs/HEALTH.md create mode 100644 frontend/src/lib/vitals-view.js create mode 100644 frontend/src/lib/vitals-view.test.js create mode 100644 frontend/src/views/Health.jsx create mode 100644 frontend/src/views/Health.render.test.jsx diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b3acae..b2a9df1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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-.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. +