( fetchImpl: typeof fetch = fetch, )
| 56 | * `fetchImpl` is injectable for tests; defaults to the global `fetch`. |
| 57 | */ |
| 58 | export async function fetchLatestVersionFromCdn( |
| 59 | fetchImpl: typeof fetch = fetch, |
| 60 | ): Promise<string> { |
| 61 | const response = await fetchWithTimeout(fetchImpl, KIMI_CODE_CDN_LATEST_URL); |
| 62 | if (!response.ok) { |
| 63 | throw new Error(`CDN /latest returned HTTP ${response.status}`); |
| 64 | } |
| 65 | const raw = (await response.text()).trim(); |
| 66 | if (valid(raw) === null) { |
| 67 | throw new Error(`CDN /latest returned invalid semver: ${JSON.stringify(raw)}`); |
| 68 | } |
| 69 | return raw; |
| 70 | } |
| 71 | |
| 72 | async function fetchUpdateManifestFromCdn(fetchImpl: typeof fetch): Promise<UpdateManifest> { |
| 73 | const response = await fetchWithTimeout(fetchImpl, KIMI_CODE_CDN_LATEST_JSON_URL); |
no test coverage detected