(
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,
)
| 2158 | * which is what re-arms refresh. Best-effort: a bookkeeping write failure |
| 2159 | * must not mask the refresh failure being reported. */ |
| 2160 | const markRefreshGrantDead = ( |
| 2161 | row: ConnectionRow, |
| 2162 | detail: string, |
| 2163 | // The mechanism that killed the grant. An admin-policy denial is a dead |
| 2164 | // grant too, but stamping it `credential_refresh_rejected` would bury |
| 2165 | // the one classification that says "reconnecting cannot help". |
| 2166 | reason: HealthCheckReason, |
| 2167 | ): Effect.Effect<void, never> => { |
| 2168 | const existingState = decodeJsonColumn(row.provider_state); |
| 2169 | const mergedState = |
| 2170 | existingState != null && typeof existingState === "object" && !Array.isArray(existingState) |
| 2171 | ? (existingState as Record<string, unknown>) |
| 2172 | : {}; |
| 2173 | const health: HealthCheckResult = { |
| 2174 | status: "expired", |
| 2175 | checkedAt: Date.now(), |
| 2176 | detail, |
| 2177 | reason, |
| 2178 | }; |
| 2179 | return core |
| 2180 | .updateMany("connection", { |
| 2181 | where: (b: AnyCb) => |
| 2182 | b.and( |
| 2183 | byOwner(row.owner as Owner)(b), |
| 2184 | b("integration", "=", String(row.integration)), |
| 2185 | b("name", "=", String(row.name)), |
| 2186 | ), |
| 2187 | set: { |
| 2188 | provider_state: { |
| 2189 | ...mergedState, |
| 2190 | oauthReauthRequiredAt: Date.now(), |
| 2191 | oauthReauthRequiredDetail: detail, |
| 2192 | // Recorded beside the dead grant, not only in `last_health`: the |
| 2193 | // verdict is best-effort and buryable, while this record is the |
| 2194 | // authority every later read reconstructs from — without it, an |
| 2195 | // admin-policy denial degrades to a generic refresh rejection on |
| 2196 | // the second and every later read. |
| 2197 | oauthReauthRequiredReason: reason, |
| 2198 | }, |
| 2199 | last_health: health, |
| 2200 | updated_at: new Date(), |
| 2201 | }, |
| 2202 | }) |
| 2203 | .pipe(Effect.ignore); |
| 2204 | }; |
| 2205 | |
| 2206 | /** Write a re-minted token back: a ROTATED refresh token into the refresh |
| 2207 | * item, the access token into the connection's primary provider item, and |
no test coverage detected