Files
HealthLog/prisma/migrations/0050_withings_connection_scope/migration.sql
T
Marc-André Bombeck 5a9612822e feat(withings): OAuth scope upgrade + reconnect banner
v1.4.25 W5d. The Withings Activity / Sleep endpoints sit behind the
`user.activity` OAuth scope which v1.4.24-and-earlier connections
never requested. This commit ships the scope plumbing + reconnect
surface so existing users can opt in to step / active energy /
distance / floors-climbed ingest with a single click.

  - Schema: `WithingsConnection.scope` nullable column. NULL =
    legacy connection that's never re-authed since v1.4.25.
  - Migration 0050 — additive column add.
  - Client: `WITHINGS_OAUTH_SCOPE = "user.metrics,user.activity"`
    + `parseWithingsScope` / `hasActivityScope` helpers.
  - Callback: persists `scope: WITHINGS_OAUTH_SCOPE` on every
    successful exchange, so reconnecting upgrades the row.
  - Status route: exposes `scope` + `hasActivityScope` so the UI
    can render the reconnect banner conditionally.
  - Settings → Integrations: paint a reconnect banner when the
    user has an active connection AND `hasActivityScope === false`.
    Click → /api/withings/connect → standard OAuth flow.
  - i18n: EN + DE strings for the banner +
    `measurements.types.{fatFreeMass,fatMass,muscleMass,
    skinTemperature,pulseWaveVelocity,vascularAge,visceralFat}`.
  - 5 new unit tests covering the scope helpers.

Note: the Activity sync routine itself
(`POST /v2/measure?action=getactivity`) lands in v1.4.26. Shipping the
scope upgrade now means users only reconnect once instead of twice.

Cross-source dedup protection is already in place via the W5e
foundation (`pickCanonicalSourceRows`): once Activity sync lands AND
a user also has Apple Health passthrough (v1.5), the per-day picker
prevents double-counting cumulative metrics from two sources.
2026-05-14 14:13:58 +02:00

21 lines
890 B
SQL

-- v1.4.25 W5d — Withings OAuth scope tracking.
--
-- Adds a nullable `scope` column to `withings_connections` so the
-- ingest path + the Settings UI can tell which OAuth permissions a
-- given connection holds. Legacy v1.4.24 connections sit on
-- `user.metrics` only; v1.4.25 starts requesting
-- `user.metrics,user.activity` for new connections so the activity /
-- sleep endpoints unlock.
--
-- The Settings → Integrations card surfaces a reconnect banner for
-- legacy connections (`scope IS NULL` OR scope NOT LIKE
-- '%user.activity%') so the user can re-auth and gain step / active
-- energy / distance ingest.
--
-- Forward-only, additive. NULL is the documented "legacy connection"
-- sentinel; existing rows stay NULL and continue to read every
-- `user.metrics`-gated endpoint exactly as before.
ALTER TABLE "withings_connections"
ADD COLUMN IF NOT EXISTS "scope" TEXT;