feat(fitbit): stop at the Web API turndown and point to Google Health

Google turns the legacy Fitbit Web API off on 30 October 2026 (support
ended on 30 September). From that day the hourly poll, the backfill,
the sleep repair and the token refresh make no call, the connect, sync
and test routes refuse with `provider_retired`, and the connection
reads as not connected to the health read and the watchdog, so the
shutdown pages nobody and asks nobody to reconnect. The connection row
and everything it imported stay.

The status envelope publishes `retirement` on the Fitbit entry (the
day, whether it has come, the successor), and the Fitbit card shows
when the connection stops, how to move to Google Health (same devices,
one more consent, tokens cannot be carried over) and that the data
stays; sync and connect grey out after the day. Both integrations can
run side by side meanwhile: every type Fitbit writes is laddered with
Fitbit just above Google Health, so a day both deliver counts once.

The test setups pin the turndown off, so the Fitbit suites do not turn
red on the day; the turndown's own tests flip it.
This commit is contained in:
Marc-André Bombeck committed 2026-10-21 12:46:14 +02:00
1 parent 1fc0268b3d
commit ba1271275f
41 files changed
+920 -39

No files matched your search

@@ -36,6 +36,7 @@ import { POST } from "../route";
import { prisma } from "@/lib/db";
import { checkRateLimit } from "@/lib/rate-limit";
import { getValidToken } from "@/lib/fitbit/sync-core";
import { isFitbitRetired } from "@/lib/fitbit/retirement";
interface ApiErrorEnvelope {
data: null;
@@ -109,6 +110,22 @@ describe("POST /api/integrations/fitbit/test", () => {
expect(global.fetch).not.toHaveBeenCalled();
});
it("answers 410 provider_retired once Google has turned the Web API off", async () => {
vi.mocked(isFitbitRetired).mockReturnValue(true);
try {
const response = await POST(emptyRequest() as never);
expect(response.status).toBe(410);
const body = (await response.json()) as ApiErrorEnvelope & {
meta?: { errorCode?: string };
};
expect(body.meta?.errorCode).toBe("provider_retired");
expect(getValidToken).not.toHaveBeenCalled();
expect(global.fetch).not.toHaveBeenCalled();
} finally {
vi.mocked(isFitbitRetired).mockReturnValue(false);
}
});
it("returns 422 when no Fitbit connection exists", async () => {
vi.mocked(getValidToken).mockResolvedValueOnce(null);
const response = await POST(emptyRequest() as never);
@@ -7,6 +7,7 @@ import { prisma } from "@/lib/db";
import { getValidToken } from "@/lib/fitbit/sync-core";
import { FITBIT_API_BASE } from "@/lib/fitbit/client";
import { safeFetch, SafeFetchError } from "@/lib/safe-fetch";
import { isFitbitRetired } from "@/lib/fitbit/retirement";
export const dynamic = "force-dynamic";
@@ -55,6 +56,14 @@ export const POST = apiHandler(async (request: NextRequest) => {
});
}
if (isFitbitRetired()) {
return apiError(
"Google has turned the Fitbit Web API off. Connect Google Health instead.",
410,
{ errorCode: "provider_retired" },
);
}
const tokenInfo = await getValidToken(user.id);
if (!tokenInfo) {
return apiError("Fitbit not connected", 422, {