(
row: ConnectionRow,
detail: string,
// The mechanism that killed the grant. An admin-policy denial is a dead
// grant too, but stamping it `credential_refresh_rejected` would bury
// the one classification that says "reconnecting cannot help".
reason: HealthCheckReason,
)
| 2292 | * which is what re-arms refresh. Best-effort: a bookkeeping write failure |
| 2293 | * must not mask the refresh failure being reported. */ |
| 2294 | const markRefreshGrantDead = ( |
| 2295 | row: ConnectionRow, |
| 2296 | detail: string, |
| 2297 | // The mechanism that killed the grant. An admin-policy denial is a dead |
| 2298 | // grant too, but stamping it `credential_refresh_rejected` would bury |
| 2299 | // the one classification that says "reconnecting cannot help". |
| 2300 | reason: HealthCheckReason, |
| 2301 | ): Effect.Effect<void, never> => { |
| 2302 | const existingState = decodeJsonColumn(row.provider_state); |
| 2303 | const mergedState = |
| 2304 | existingState != null && typeof existingState === "object" && !Array.isArray(existingState) |
| 2305 | ? (existingState as Record<string, unknown>) |
| 2306 | : {}; |
| 2307 | const health: HealthCheckResult = { |
| 2308 | status: "expired", |
| 2309 | checkedAt: Date.now(), |
| 2310 | detail, |
| 2311 | reason, |
| 2312 | }; |
| 2313 | return core |
| 2314 | .updateMany("connection", { |
| 2315 | where: (b: AnyCb) => |
| 2316 | b.and( |
| 2317 | byOwner(row.owner as Owner)(b), |
| 2318 | b("integration", "=", String(row.integration)), |
| 2319 | b("name", "=", String(row.name)), |
| 2320 | ), |
| 2321 | set: { |
| 2322 | provider_state: { |
| 2323 | ...mergedState, |
| 2324 | oauthReauthRequiredAt: Date.now(), |
| 2325 | oauthReauthRequiredDetail: detail, |
| 2326 | // Recorded beside the dead grant, not only in `last_health`: the |
| 2327 | // verdict is best-effort and buryable, while this record is the |
| 2328 | // authority every later read reconstructs from — without it, an |
| 2329 | // admin-policy denial degrades to a generic refresh rejection on |
| 2330 | // the second and every later read. |
| 2331 | oauthReauthRequiredReason: reason, |
| 2332 | }, |
| 2333 | last_health: health, |
| 2334 | updated_at: new Date(), |
| 2335 | }, |
| 2336 | }) |
| 2337 | .pipe(Effect.ignore); |
| 2338 | }; |
| 2339 | |
| 2340 | /** Write a re-minted token back: a ROTATED refresh token into the refresh |
| 2341 | * item, the access token into the connection's primary provider item, and |
no test coverage detected