( signal?: AbortSignal, )
| 27 | let latestVersionCache: Promise<string | null> | null = null; |
| 28 | |
| 29 | export async function getLatestVersion( |
| 30 | signal?: AbortSignal, |
| 31 | ): Promise<string | null> { |
| 32 | // Return cached promise if it exists |
| 33 | if (latestVersionCache) { |
| 34 | return latestVersionCache; |
| 35 | } |
| 36 | |
| 37 | // Create and cache the promise |
| 38 | latestVersionCache = (async () => { |
| 39 | try { |
| 40 | const id = getEventUserId(); |
| 41 | const response = await fetch( |
| 42 | `https://api.continue.dev/cn/info?id=${encodeURIComponent(id)}`, |
| 43 | { signal }, |
| 44 | ); |
| 45 | if (!response.ok) { |
| 46 | throw new Error(`HTTP error! status: ${response.status}`); |
| 47 | } |
| 48 | const data = await response.json(); |
| 49 | return data.version; |
| 50 | } catch (error) { |
| 51 | if (error instanceof Error && error.name === "AbortError") { |
| 52 | // Request was aborted, don't log |
| 53 | return null; |
| 54 | } |
| 55 | logger?.debug( |
| 56 | "Warning: Could not fetch latest version from api.continue.dev", |
| 57 | ); |
| 58 | return null; |
| 59 | } |
| 60 | })(); |
| 61 | |
| 62 | return latestVersionCache; |
| 63 | } |
| 64 | |
| 65 | getLatestVersion() |
| 66 | .then((version) => { |
no test coverage detected