(
row: ConnectionRow,
)
| 1980 | // two distinct inputs yields one entry per variable. OAuth connections refresh |
| 1981 | // first (always single-input → `{ token: <access> }`). |
| 1982 | const resolveConnectionValues = ( |
| 1983 | row: ConnectionRow, |
| 1984 | ): Effect.Effect<Record<string, string | null>, StorageFailure | CredentialResolutionError> => |
| 1985 | Effect.gen(function* () { |
| 1986 | const provider = credentialProviders.get(row.provider); |
| 1987 | if (!provider) { |
| 1988 | return yield* new CredentialProviderNotRegisteredError({ |
| 1989 | provider: ProviderKey.make(row.provider), |
| 1990 | }); |
| 1991 | } |
| 1992 | // OAuth connections refresh their access token before resolving when |
| 1993 | // it has expired (or is within the skew window). |
| 1994 | const expiresAt = row.expires_at == null ? null : Number(row.expires_at); |
| 1995 | if (row.oauth_client != null && shouldRefreshToken({ expiresAt })) { |
| 1996 | const access = yield* refreshConnectionToken(row, provider); |
| 1997 | return { [PRIMARY_INPUT_VARIABLE]: access }; |
| 1998 | } |
| 1999 | const out: Record<string, string | null> = {}; |
| 2000 | for (const [variable, itemId] of Object.entries(connectionItemIds(row))) { |
| 2001 | out[variable] = yield* provider.get(ProviderItemId.make(itemId)); |
| 2002 | } |
| 2003 | return out; |
| 2004 | }).pipe( |
| 2005 | // CredentialProviderNotRegisteredError is part of CredentialResolution |
| 2006 | // for ctx.connections.resolveValue's StorageFailure channel — fold it. |
| 2007 | Effect.catchTag("CredentialProviderNotRegisteredError", (err) => |
| 2008 | Effect.fail( |
| 2009 | new StorageError({ |
| 2010 | message: `Credential provider "${err.provider}" is not registered.`, |
| 2011 | cause: err, |
| 2012 | }), |
| 2013 | ), |
| 2014 | ), |
| 2015 | ); |
| 2016 | |
| 2017 | /** Re-mint an OAuth connection's access token unconditionally, ignoring the |
| 2018 | * stored expiry. Drives the reactive path: the upstream just rejected the |
no test coverage detected