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