Files
HealthLog/src/lib/measurements/external-source.ts
T
Antiheld86 5ec361abec feat(measurements): mirror EXTERNAL in Zod, keep those rows correctable
Adds the `EXTERNAL_SOURCE` leaf beside `scopes.ts` and mirrors the value in
`measurementSourceEnum` so the read shapes and the sync decoder see it. It
stays out of `WRITABLE_MEASUREMENT_SOURCES`: a source a client could assert
would prove nothing about where a reading came from, and that constant is
published to clients as `ingest.writeAllowlist`.

The value-edit gate in `PUT /api/measurements/[id]` needs the other question
answered, though — whether the number is the user's own to fix — so it now
reads a separate `USER_CORRECTABLE_MEASUREMENT_SOURCES`. The 409 that
protects a Withings row exists because the value is the provider's reading;
the hardware behind an ingest token is the user's own scale, and locking
those rows would contradict what the settings card and the Home Assistant
guide promise. That is the only site reading the wider set.
2026-09-25 06:55:17 +02:00

25 lines
1.3 KiB
TypeScript

/**
* The `MeasurementSource` value rows written through the ingest token carry.
*
* A leaf module with no imports, for the same reason `scopes.ts` next door is
* one: the two write routes, the edit gate, the Zod source enum and the
* integration suites all read this string, and none of them should inherit an
* import graph to get it. `MCP_SOURCE` (`@/lib/mcp/writes.ts`) is module-local
* because it has exactly one writer; this one does not, and two sibling
* declarations of the same literal is the drift a shared leaf exists to avoid.
*
* Not folded into `scopes.ts`. A provenance label living in a file named
* `scopes.ts` is one somebody later imports "because it was there", and the
* two answer different questions: one is what a credential may do, the other
* is what a row came from.
*
* No client may name it. It is deliberately absent from
* `WRITABLE_MEASUREMENT_SOURCES` and from the batch route's `batchSourceEnum`,
* so the only way a row acquires it is the server resolving it from the
* credential that carried the write — which is the whole point: a source a
* client could assert would prove nothing about where the reading came from.
*/
/** Provenance for a measurement pushed in under `measurements:write`. */
export const EXTERNAL_SOURCE = "EXTERNAL" as const;