( endpoint: string, token: string )
| 2226 | |
| 2227 | /** Fetch the user authenticated by the token. */ |
| 2228 | export async function fetchUser( |
| 2229 | endpoint: string, |
| 2230 | token: string |
| 2231 | ): Promise<Account> { |
| 2232 | const api = new API(endpoint, token) |
| 2233 | try { |
| 2234 | const [user, emails, copilotInfo, features] = await Promise.all([ |
| 2235 | api.fetchAccount(), |
| 2236 | api.fetchEmails(), |
| 2237 | api.fetchUserCopilotInfo(), |
| 2238 | api.fetchFeatureFlags(), |
| 2239 | ]) |
| 2240 | |
| 2241 | return new Account( |
| 2242 | user.login, |
| 2243 | endpoint, |
| 2244 | token, |
| 2245 | emails, |
| 2246 | user.avatar_url, |
| 2247 | user.id, |
| 2248 | user.name || user.login, |
| 2249 | user.plan?.name, |
| 2250 | copilotInfo?.copilotEndpoint, |
| 2251 | copilotInfo?.isCopilotDesktopEnabled, |
| 2252 | features, |
| 2253 | copilotInfo?.copilotLicenseType |
| 2254 | ) |
| 2255 | } catch (e) { |
| 2256 | log.warn(`fetchUser: failed with endpoint ${endpoint}`, e) |
| 2257 | throw e |
| 2258 | } |
| 2259 | } |
| 2260 | |
| 2261 | /** |
| 2262 | * Map a repository's URL to the endpoint associated with it. For example: |
no test coverage detected