mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 23:33:29 +00:00
feat: lay down the shared v1.42 contract
Land every file the v1.42 work shares before any of it is built, so the parts built side by side never edit the same file. Schema and migrations 0379-0386: the HEALTH_CONNECT measurement source, ImportJob.kind, the air-quality columns and the per-user switch on the environment tables, sealed environment locations with nullable plaintext, managed-profile handover links, the per-type HealthKit arrival ledger, lab unit-conversion provenance, and user-defined vaccines. Every new column is annotated for the column-reader sweep. HEALTH_CONNECT reaches every exhaustive list: the source labels, the read enum (not the write allowlist), the source-priority ladder cap, now the number of sources rather than a fixed eight, and the write-path smoke test. RMSSD gets its own priority class and a 300 ms ceiling. The batch syncTrigger gains `manual`, with its label on the Apple Health card. Queues for the Health Connect import, the compaction-tombstone purge and the measurement-table maintenance are registered with stub handlers; host-metric sampling moves to every five minutes. Environment and work_mem variables reach the compose whitelist, the production example and the manifest. The proxy admits the handover link and redirects it at the edge, and the Health Connect upload bypasses the proxy body limit. The new routes answer 501 behind their final authentication and are published in the contract; backup, wipe and key rotation classify the new models and columns; the seven message bundles carry the base copy. Guards that list release-pending keys and columns fail once an entry is wired, so those lists empty themselves before the tag. Also re-anchor a login-throttle fixture to the wall clock, where its expiry is compared, and re-base the aggregate bundle cap on a measured 12 KB of new locale strings.
This commit is contained in:
1 parent
125b15bfb7
commit
e63be67b5a
82 files changed
+5099
-727
No files matched your search
@@ -381,6 +381,37 @@ const insuranceNumber: SettingCodec = {
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* v1.42 (#615) — the sealed home location. A disaster-recovery file carries
|
||||
* the ciphertext verbatim, like the insurance number, because it is restored
|
||||
* onto a host holding the same keys. A portable file leaves it out: the
|
||||
* readable home rides `homeLat` / `homeLon` / `homeLabel` until those columns
|
||||
* drop, and the receiving host's encryption backfill seals it again.
|
||||
*/
|
||||
const homeLocationSealed: SettingCodec = {
|
||||
write: (row, disasterRecovery) => {
|
||||
if (!disasterRecovery) return {};
|
||||
const sealed = row.homeLocationEncrypted;
|
||||
return {
|
||||
homeLocationEncrypted:
|
||||
sealed instanceof Uint8Array
|
||||
? Buffer.from(sealed).toString("base64")
|
||||
: null,
|
||||
};
|
||||
},
|
||||
read: (entry) => {
|
||||
if (!has(entry, "homeLocationEncrypted")) return undefined;
|
||||
const value = entry.homeLocationEncrypted;
|
||||
if (value === null) return null;
|
||||
if (typeof value !== "string") return new Refused("homeLocationEncrypted");
|
||||
const buffer = Buffer.from(value, "base64");
|
||||
if (buffer.byteLength === 0) return new Refused("homeLocationEncrypted");
|
||||
const bytes = new Uint8Array(new ArrayBuffer(buffer.byteLength));
|
||||
bytes.set(buffer);
|
||||
return bytes;
|
||||
},
|
||||
};
|
||||
|
||||
const ACCOUNT_SETTING_CODECS: Readonly<
|
||||
Record<AccountSettingColumn, SettingCodec>
|
||||
> = {
|
||||
@@ -402,6 +433,8 @@ const ACCOUNT_SETTING_CODECS: Readonly<
|
||||
homeLabel: plain("homeLabel"),
|
||||
homeTimezone: timeZone("homeTimezone", true),
|
||||
homeSince: instant("homeSince"),
|
||||
homeLocationEncrypted: homeLocationSealed,
|
||||
environmentAirQualityEnabled: plain("environmentAirQualityEnabled"),
|
||||
timezone: timeZone("timezone", false),
|
||||
locale: oneOf("locale", locales, true),
|
||||
// The vocabularies the two preference routes accept, read from their own
|
||||
|
||||
@@ -171,6 +171,10 @@ export const BACKED_UP_MODELS = [
|
||||
// re-syncs it from a provider.
|
||||
"VaccinationRecord",
|
||||
"VaccinationDocumentLink",
|
||||
// v1.42 (#1005) — the person's own vaccine definitions. A dose logged
|
||||
// against one resolves its antigens and booster rule through it, so a
|
||||
// restore without them leaves those doses as bare names.
|
||||
"CustomVaccine",
|
||||
|
||||
// ── Coach ─────────────────────────────────────────────────────────────────
|
||||
// The transcript — conversation, message, attachment — travels; see
|
||||
@@ -585,6 +589,8 @@ export const STRUCTURALLY_UNATTRIBUTABLE: Readonly<Record<string, string>> = {
|
||||
* rather than by what is cheapest to write.
|
||||
*/
|
||||
export const COVERAGE_PENDING: Readonly<Record<string, string>> = {
|
||||
CustomVaccine:
|
||||
"The person's own vaccine definitions (v1.42, #1005). Until both ends land, a restored dose that pointed at one comes back as its bare `vaccineName`: no antigens, no series position, no booster rule.",
|
||||
WorkoutRoute:
|
||||
"GPS traces. Deliberately absent from the payload today and DISCLOSED as absent in the file's own manifest, which is why this is a documented exclusion rather than a silent one — but it is still a loss for a self-hoster with no other copy.",
|
||||
WorkoutSamples:
|
||||
@@ -718,6 +724,10 @@ export const NOT_IN_BACKUP_MODELS: Readonly<Record<string, string>> = {
|
||||
"Further import source keys that were answered with an already stored document because the bytes matched. The next import run writes the same alias again the moment it meets the same bytes, so a restore loses nothing a re-run does not rebuild; and for a deleted document it restores no less than the tombstones and ledger beside it do, which do not travel either.",
|
||||
ImportJob:
|
||||
"A job record pointing at an uploaded file that the backup does not carry, so restoring it would resurrect a task with nothing to work on.",
|
||||
HealthKitTypeSync:
|
||||
"When each HealthKit type last arrived on this host and how. Diagnostic state the next sync rebuilds; restored elsewhere it would claim deliveries that host never received.",
|
||||
ManagedProfileHandover:
|
||||
"A one-time handover link: a credential, minted by a guardian and shown once. Restoring it would bring back a link that was used, withdrawn or expired, and only its hash exists to carry anyway. Same reasoning as `InviteToken`.",
|
||||
InviteToken:
|
||||
"The instance's registration ledger, minted by the operator rather than by the person, and already declared instance-scoped by the wipe plan. Restoring one account's backup must not re-open a registration code the operator retired, and the creator relation is the only thing that makes this look account-scoped at all. It surfaced here when the classification check learned to read a relation by type instead of by field name.",
|
||||
MedicationIntakeImportJob:
|
||||
@@ -914,6 +924,10 @@ export const USER_COLUMN_BACKUP_CLASS = {
|
||||
homeLabel: "SETTING",
|
||||
homeTimezone: "SETTING",
|
||||
homeSince: "SETTING",
|
||||
// v1.42 (#615) — the sealed copy of the same home location, and the
|
||||
// account's switch for the air-quality part of the module.
|
||||
homeLocationEncrypted: "SETTING",
|
||||
environmentAirQualityEnabled: "SETTING",
|
||||
// How the interface reads.
|
||||
timezone: "SETTING",
|
||||
locale: "SETTING",
|
||||
|
||||
@@ -66,9 +66,13 @@ import { roundCoarse } from "@/lib/environment/open-meteo";
|
||||
export interface EnvironmentContextBackupEntry {
|
||||
/** `YYYY-MM-DD`, anchored to the resolved location's timezone. */
|
||||
date: string;
|
||||
lat: number;
|
||||
lon: number;
|
||||
locationLabel: string;
|
||||
/**
|
||||
* Plaintext coarse location. Nullable since v1.42 (migration 0382): the
|
||||
* sealed copy replaces it once the encryption backfill has run.
|
||||
*/
|
||||
lat: number | null;
|
||||
lon: number | null;
|
||||
locationLabel: string | null;
|
||||
/**
|
||||
* Which precedence rule chose the location. Carried because it is the only
|
||||
* record that this day was NOT the home city, and because a re-resolve
|
||||
@@ -98,9 +102,10 @@ export interface EnvironmentTravelLocationBackupEntry {
|
||||
/** Inclusive `YYYY-MM-DD` bounds. Strings end to end; see the file header. */
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
lat: number;
|
||||
lon: number;
|
||||
label: string;
|
||||
/** Plaintext coarse location; nullable since v1.42 (migration 0382). */
|
||||
lat: number | null;
|
||||
lon: number | null;
|
||||
label: string | null;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
@@ -315,8 +320,8 @@ export async function restoreEnvironmentData(
|
||||
endDate: entry.endDate,
|
||||
// A file written before v1.39.4 carries 2-decimal coordinates; they
|
||||
// come back at today's privacy floor.
|
||||
lat: roundCoarse(entry.lat),
|
||||
lon: roundCoarse(entry.lon),
|
||||
lat: entry.lat == null ? null : roundCoarse(entry.lat),
|
||||
lon: entry.lon == null ? null : roundCoarse(entry.lon),
|
||||
label: entry.label,
|
||||
...(entry.createdAt ? { createdAt: new Date(entry.createdAt) } : {}),
|
||||
...(entry.updatedAt ? { updatedAt: new Date(entry.updatedAt) } : {}),
|
||||
@@ -329,8 +334,8 @@ export async function restoreEnvironmentData(
|
||||
data: payload.environmentContexts.map((entry) => ({
|
||||
userId: ownerId,
|
||||
date: entry.date,
|
||||
lat: roundCoarse(entry.lat),
|
||||
lon: roundCoarse(entry.lon),
|
||||
lat: entry.lat == null ? null : roundCoarse(entry.lat),
|
||||
lon: entry.lon == null ? null : roundCoarse(entry.lon),
|
||||
locationLabel: entry.locationLabel,
|
||||
source: entry.source,
|
||||
tempMin: entry.tempMin ?? null,
|
||||
|
||||
Reference in new issue
Block a user