(
row: ConnectionRow,
)
| 1738 | // two distinct inputs yields one entry per variable. OAuth connections refresh |
| 1739 | // first (always single-input → `{ token: <access> }`). |
| 1740 | const resolveConnectionValues = ( |
| 1741 | row: ConnectionRow, |
| 1742 | ): Effect.Effect<Record<string, string | null>, StorageFailure | CredentialResolutionError> => |
| 1743 | Effect.gen(function* () { |
| 1744 | const provider = credentialProviders.get(row.provider); |
| 1745 | if (!provider) { |
| 1746 | return yield* new CredentialProviderNotRegisteredError({ |
| 1747 | provider: ProviderKey.make(row.provider), |
| 1748 | }); |
| 1749 | } |
| 1750 | // OAuth connections refresh their access token before resolving when |
| 1751 | // it has expired (or is within the skew window). |
| 1752 | const expiresAt = row.expires_at == null ? null : Number(row.expires_at); |
| 1753 | if (row.oauth_client != null && shouldRefreshToken({ expiresAt })) { |
| 1754 | const access = yield* refreshConnectionToken(row, provider); |
| 1755 | return { [PRIMARY_INPUT_VARIABLE]: access }; |
| 1756 | } |
| 1757 | const out: Record<string, string | null> = {}; |
| 1758 | for (const [variable, itemId] of Object.entries(connectionItemIds(row))) { |
| 1759 | out[variable] = yield* provider.get(ProviderItemId.make(itemId)); |
| 1760 | } |
| 1761 | return out; |
| 1762 | }).pipe( |
| 1763 | // CredentialProviderNotRegisteredError is part of CredentialResolution |
| 1764 | // for ctx.connections.resolveValue's StorageFailure channel — fold it. |
| 1765 | Effect.catchTag("CredentialProviderNotRegisteredError", (err) => |
| 1766 | Effect.fail( |
| 1767 | new StorageError({ |
| 1768 | message: `Credential provider "${err.provider}" is not registered.`, |
| 1769 | cause: err, |
| 1770 | }), |
| 1771 | ), |
| 1772 | ), |
| 1773 | ); |
| 1774 | |
| 1775 | /** Re-mint an OAuth connection's access token unconditionally, ignoring the |
| 1776 | * stored expiry. Drives the reactive path: the upstream just rejected the |
no test coverage detected