(
ref: ConnectionRef,
options?: {
/** Skip the probe and return the persisted verdict when it is younger
* than this. The server owns the freshness decision so N open tabs
* revalidating on load cannot stampede an upstream. Omit = always
* probe (the manual "Check now"). */
readonly ifStaleMs?: number;
},
)
| 3339 | }); |
| 3340 | |
| 3341 | const connectionCheckHealth = ( |
| 3342 | ref: ConnectionRef, |
| 3343 | options?: { |
| 3344 | /** Skip the probe and return the persisted verdict when it is younger |
| 3345 | * than this. The server owns the freshness decision so N open tabs |
| 3346 | * revalidating on load cannot stampede an upstream. Omit = always |
| 3347 | * probe (the manual "Check now"). */ |
| 3348 | readonly ifStaleMs?: number; |
| 3349 | }, |
| 3350 | ): Effect.Effect< |
| 3351 | HealthCheckResult, |
| 3352 | ConnectionNotFoundError | IntegrationNotFoundError | StorageFailure |
| 3353 | > => |
| 3354 | Effect.gen(function* () { |
| 3355 | const connectionRow = yield* findConnectionRow(ref); |
| 3356 | if (!connectionRow) { |
| 3357 | return yield* new ConnectionNotFoundError({ |
| 3358 | owner: ref.owner, |
| 3359 | integration: ref.integration, |
| 3360 | name: ref.name, |
| 3361 | }); |
| 3362 | } |
| 3363 | if (options?.ifStaleMs !== undefined) { |
| 3364 | const cached = Option.getOrNull(decodeLastHealth(connectionRow.last_health)); |
| 3365 | if (cached && Date.now() - cached.checkedAt < options.ifStaleMs) { |
| 3366 | yield* annotateHealthVerdict("cache", cached); |
| 3367 | return cached; |
| 3368 | } |
| 3369 | } |
| 3370 | const integrationRow = yield* findIntegrationRow(ref.integration); |
| 3371 | if (!integrationRow) { |
| 3372 | return yield* new IntegrationNotFoundError({ slug: ref.integration }); |
| 3373 | } |
| 3374 | const runtime = runtimes.get(integrationRow.plugin_id); |
| 3375 | const check = runtime?.plugin.checkHealth; |
| 3376 | if (!runtime || !check) { |
| 3377 | const result = unknownHealth(); |
| 3378 | yield* annotateHealthVerdict("no_capability", result); |
| 3379 | return result; |
| 3380 | } |
| 3381 | const spec = describeHealthCheckForRow(integrationRow) ?? undefined; |
| 3382 | if (spec === undefined && connectionRow.oauth_client != null) { |
| 3383 | // No probe operation is declared, so "healthy" here means only "the |
| 3384 | // credential resolved (refreshing if due)" — a refresh failure is |
| 3385 | // the one real signal this path can produce, and it must not hide |
| 3386 | // inside a green span. |
| 3387 | const result = yield* oauthCredentialHealthWithoutProbe(connectionRow); |
| 3388 | yield* annotateHealthVerdict("credential_only", result); |
| 3389 | yield* persistHealthResult(ref, result); |
| 3390 | return result; |
| 3391 | } |
| 3392 | |
| 3393 | const result = yield* Effect.gen(function* () { |
| 3394 | const values = yield* resolveConnectionValues(connectionRow); |
| 3395 | const record = rowToIntegrationRecord( |
| 3396 | integrationRow, |
| 3397 | describeAuthMethodsForRow(integrationRow), |
| 3398 | ); |
nothing calls this directly
no test coverage detected