(
row: ConnectionRow,
)
| 2075 | // two distinct inputs yields one entry per variable. OAuth connections refresh |
| 2076 | // first (always single-input → `{ token: <access> }`). |
| 2077 | const resolveConnectionValues = ( |
| 2078 | row: ConnectionRow, |
| 2079 | ): Effect.Effect<Record<string, string | null>, StorageFailure | CredentialResolutionError> => |
| 2080 | Effect.gen(function* () { |
| 2081 | const provider = credentialProviders.get(row.provider); |
| 2082 | if (!provider) { |
| 2083 | return yield* new CredentialProviderNotRegisteredError({ |
| 2084 | provider: ProviderKey.make(row.provider), |
| 2085 | }); |
| 2086 | } |
| 2087 | // OAuth connections refresh their access token before resolving when |
| 2088 | // it has expired (or is within the skew window). |
| 2089 | const expiresAt = row.expires_at == null ? null : Number(row.expires_at); |
| 2090 | if (row.oauth_client != null && shouldRefreshToken({ expiresAt })) { |
| 2091 | const access = yield* refreshConnectionToken(row, provider); |
| 2092 | return { [PRIMARY_INPUT_VARIABLE]: access }; |
| 2093 | } |
| 2094 | const out: Record<string, string | null> = {}; |
| 2095 | for (const [variable, itemId] of Object.entries(connectionItemIds(row))) { |
| 2096 | out[variable] = yield* provider.get(ProviderItemId.make(itemId)); |
| 2097 | } |
| 2098 | return out; |
| 2099 | }).pipe( |
| 2100 | // CredentialProviderNotRegisteredError is part of CredentialResolution |
| 2101 | // for ctx.connections.resolveValue's StorageFailure channel — fold it. |
| 2102 | Effect.catchTag("CredentialProviderNotRegisteredError", (err) => |
| 2103 | Effect.fail( |
| 2104 | new StorageError({ |
| 2105 | message: `Credential provider "${err.provider}" is not registered.`, |
| 2106 | cause: err, |
| 2107 | }), |
| 2108 | ), |
| 2109 | ), |
| 2110 | ); |
| 2111 | |
| 2112 | /** Re-mint an OAuth connection's access token unconditionally, ignoring the |
| 2113 | * stored expiry. Drives the reactive path: the upstream just rejected the |
no test coverage detected