mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 21:10:59 +00:00
Merge branch 'feat/v144-oura-depth' into feat/v144-integrations
This commit is contained in:
commit
ae601de16f
44 files changed
+3099
-214
No files matched your search
@@ -218,12 +218,17 @@ describe("GET /api/oura/callback — issuer", () => {
|
||||
* card for up to an hour.
|
||||
*/
|
||||
describe("GET /api/oura/callback — connect-time first sync", () => {
|
||||
it("enqueues exactly one targeted oura-sync job for the connecting user", async () => {
|
||||
it("enqueues one targeted oura-sync job and the history backfill for the connecting user", async () => {
|
||||
const res = await GET(makeReq({ code: "c", state: "S", cookie: "S" }));
|
||||
|
||||
expect(res.headers.get("location")).toContain("oura=connected");
|
||||
expect(bossSend).toHaveBeenCalledTimes(1);
|
||||
expect(bossSend).toHaveBeenCalledTimes(2);
|
||||
expect(bossSend).toHaveBeenCalledWith("oura-sync", { userId: "u1" });
|
||||
expect(bossSend).toHaveBeenCalledWith(
|
||||
"oura-backfill",
|
||||
expect.objectContaining({ userId: "u1" }),
|
||||
expect.objectContaining({ singletonKey: "oura-backfill|u1" }),
|
||||
);
|
||||
});
|
||||
|
||||
it("still connects when no boss instance is available", async () => {
|
||||
|
||||
@@ -18,6 +18,11 @@ import { ouraCollectionsMissingFromGrant } from "@/lib/oura/scope";
|
||||
import { markReconnected } from "@/lib/integrations/status";
|
||||
import { OURA_SYNC_QUEUE } from "@/lib/jobs/integration-poll-queues";
|
||||
import { getGlobalBoss } from "@/lib/jobs/boss-instance";
|
||||
import { integrationBackfillSourceOptions } from "@/lib/jobs/integration-backfill-admission";
|
||||
import {
|
||||
OURA_BACKFILL_QUEUE,
|
||||
type OuraBackfillPayload,
|
||||
} from "@/lib/jobs/oura-backfill";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
/**
|
||||
@@ -143,6 +148,10 @@ async function completeCallback(
|
||||
ouraRefreshTokenEncrypted: encrypt(tokens.refresh_token),
|
||||
ouraScopeDenied:
|
||||
missing && missing.length > 0 ? missing : Prisma.DbNull,
|
||||
// Open the history backfill again: a first connect has none yet,
|
||||
// and a reconnect may grant what the old grant refused. What was
|
||||
// already walked stays in the progress note and is not read again.
|
||||
ouraBackfillCompletedAt: null,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -165,6 +174,21 @@ async function completeCallback(
|
||||
.catch((err) =>
|
||||
getEvent()?.addWarning(`oura-sync connect enqueue failed: ${err}`),
|
||||
);
|
||||
const backfill: OuraBackfillPayload = {
|
||||
userId,
|
||||
enqueuedAt: new Date().toISOString(),
|
||||
};
|
||||
await boss
|
||||
.send(
|
||||
OURA_BACKFILL_QUEUE,
|
||||
backfill,
|
||||
integrationBackfillSourceOptions(`oura-backfill|${userId}`),
|
||||
)
|
||||
.catch((err) =>
|
||||
getEvent()?.addWarning(
|
||||
`oura-backfill connect enqueue failed: ${err}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
const response = NextResponse.redirect(
|
||||
|
||||
Reference in new issue
Block a user