(
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,
)
| 2243 | * which is what re-arms refresh. Best-effort: a bookkeeping write failure |
| 2244 | * must not mask the refresh failure being reported. */ |
| 2245 | const markRefreshGrantDead = ( |
| 2246 | row: ConnectionRow, |
| 2247 | detail: string, |
| 2248 | // The mechanism that killed the grant. An admin-policy denial is a dead |
| 2249 | // grant too, but stamping it `credential_refresh_rejected` would bury |
| 2250 | // the one classification that says "reconnecting cannot help". |
| 2251 | reason: HealthCheckReason, |
| 2252 | ): Effect.Effect<void, never> => { |
| 2253 | const existingState = decodeJsonColumn(row.provider_state); |
| 2254 | const mergedState = |
| 2255 | existingState != null && typeof existingState === "object" && !Array.isArray(existingState) |
| 2256 | ? (existingState as Record<string, unknown>) |
| 2257 | : {}; |
| 2258 | const health: HealthCheckResult = { |
| 2259 | status: "expired", |
| 2260 | checkedAt: Date.now(), |
| 2261 | detail, |
| 2262 | reason, |
| 2263 | }; |
| 2264 | return core |
| 2265 | .updateMany("connection", { |
| 2266 | where: (b: AnyCb) => |
| 2267 | b.and( |
| 2268 | byOwner(row.owner as Owner)(b), |
| 2269 | b("integration", "=", String(row.integration)), |
| 2270 | b("name", "=", String(row.name)), |
| 2271 | ), |
| 2272 | set: { |
| 2273 | provider_state: { |
| 2274 | ...mergedState, |
| 2275 | oauthReauthRequiredAt: Date.now(), |
| 2276 | oauthReauthRequiredDetail: detail, |
| 2277 | // Recorded beside the dead grant, not only in `last_health`: the |
| 2278 | // verdict is best-effort and buryable, while this record is the |
| 2279 | // authority every later read reconstructs from — without it, an |
| 2280 | // admin-policy denial degrades to a generic refresh rejection on |
| 2281 | // the second and every later read. |
| 2282 | oauthReauthRequiredReason: reason, |
| 2283 | }, |
| 2284 | last_health: health, |
| 2285 | updated_at: new Date(), |
| 2286 | }, |
| 2287 | }) |
| 2288 | .pipe(Effect.ignore); |
| 2289 | }; |
| 2290 | |
| 2291 | /** Write a re-minted token back: a ROTATED refresh token into the refresh |
| 2292 | * item, the access token into the connection's primary provider item, and |
no test coverage detected