(
row: ConnectionRow,
)
| 2641 | // two distinct inputs yields one entry per variable. OAuth connections refresh |
| 2642 | // first (always single-input → `{ token: <access> }`). |
| 2643 | const resolveConnectionValues = ( |
| 2644 | row: ConnectionRow, |
| 2645 | ): Effect.Effect<Record<string, string | null>, StorageFailure | CredentialResolutionError> => |
| 2646 | Effect.gen(function* () { |
| 2647 | const provider = credentialProviders.get(row.provider); |
| 2648 | if (!provider) { |
| 2649 | return yield* new CredentialProviderNotRegisteredError({ |
| 2650 | provider: ProviderKey.make(row.provider), |
| 2651 | }); |
| 2652 | } |
| 2653 | // OAuth connections refresh their access token before resolving when |
| 2654 | // it has expired (or is within the skew window). |
| 2655 | const expiresAt = row.expires_at == null ? null : Number(row.expires_at); |
| 2656 | if (row.oauth_client != null && shouldRefreshToken({ expiresAt })) { |
| 2657 | const access = yield* refreshConnectionToken(row, provider); |
| 2658 | return { [PRIMARY_INPUT_VARIABLE]: access }; |
| 2659 | } |
| 2660 | const out: Record<string, string | null> = {}; |
| 2661 | for (const [variable, itemId] of Object.entries(connectionItemIds(row))) { |
| 2662 | out[variable] = yield* provider.get(ProviderItemId.make(itemId)); |
| 2663 | } |
| 2664 | return out; |
| 2665 | }).pipe( |
| 2666 | // CredentialProviderNotRegisteredError is part of CredentialResolution |
| 2667 | // for ctx.connections.resolveValue's StorageFailure channel — fold it. |
| 2668 | Effect.catchTag("CredentialProviderNotRegisteredError", (err) => |
| 2669 | Effect.fail( |
| 2670 | new StorageError({ |
| 2671 | message: `Credential provider "${err.provider}" is not registered.`, |
| 2672 | cause: err, |
| 2673 | }), |
| 2674 | ), |
| 2675 | ), |
| 2676 | ); |
| 2677 | |
| 2678 | /** Re-mint an OAuth connection's access token unconditionally, ignoring the |
| 2679 | * stored expiry. Drives the reactive path: the upstream just rejected the |
no test coverage detected