18d307f52SEvan Baconimport { createCachedFetch } from './rest/client'; 2*8a424bebSJames Ideimport { CommandError } from '../utils/errors'; 38d307f52SEvan Bacon 48d307f52SEvan Bacon/** Represents version info for a particular SDK. */ 58d307f52SEvan Baconexport type SDKVersion = { 68d307f52SEvan Bacon /** @example "2.16.1" */ 78d307f52SEvan Bacon iosVersion?: string; 88d307f52SEvan Bacon /** @example "https://dpq5q02fu5f55.cloudfront.net/Exponent-2.17.4.tar.gz" */ 98d307f52SEvan Bacon iosClientUrl?: string; 108d307f52SEvan Bacon /** @example "https://dev.to/expo/expo-sdk-38-is-now-available-5aa0" */ 118d307f52SEvan Bacon releaseNoteUrl?: string; 128d307f52SEvan Bacon /** @example "2.17.4" */ 138d307f52SEvan Bacon iosClientVersion?: string; 148d307f52SEvan Bacon /** @example "https://d1ahtucjixef4r.cloudfront.net/Exponent-2.16.1.apk" */ 158d307f52SEvan Bacon androidClientUrl?: string; 168d307f52SEvan Bacon /** @example "2.16.1" */ 178d307f52SEvan Bacon androidClientVersion?: string; 188d307f52SEvan Bacon /** @example { "typescript": "~3.9.5" } */ 198d307f52SEvan Bacon relatedPackages?: Record<string, string>; 2009bb6093SEvan Bacon 2109bb6093SEvan Bacon facebookReactNativeVersion: string; 2209bb6093SEvan Bacon 2309bb6093SEvan Bacon facebookReactVersion?: string; 2409bb6093SEvan Bacon 258d307f52SEvan Bacon beta?: boolean; 268d307f52SEvan Bacon}; 278d307f52SEvan Bacon 288d307f52SEvan Baconexport type SDKVersions = Record<string, SDKVersion>; 298d307f52SEvan Bacon 308d307f52SEvan Baconexport type Versions = { 318d307f52SEvan Bacon androidUrl: string; 328d307f52SEvan Bacon androidVersion: string; 338d307f52SEvan Bacon iosUrl: string; 348d307f52SEvan Bacon iosVersion: string; 358d307f52SEvan Bacon sdkVersions: SDKVersions; 368d307f52SEvan Bacon}; 378d307f52SEvan Bacon 388d307f52SEvan Bacon/** Get versions from remote endpoint. */ 3909bb6093SEvan Baconexport async function getVersionsAsync({ 4009bb6093SEvan Bacon skipCache, 4109bb6093SEvan Bacon}: { skipCache?: boolean } = {}): Promise<Versions> { 428d307f52SEvan Bacon // Reconstruct the cached fetch since caching could be disabled. 438d307f52SEvan Bacon const fetchAsync = createCachedFetch({ 4409bb6093SEvan Bacon skipCache, 458d307f52SEvan Bacon cacheDirectory: 'versions-cache', 4632f72f58SBrent Vatne // We'll use a 5 minute cache to ensure we stay relatively up to date. 4732f72f58SBrent Vatne ttl: 1000 * 60 * 5, 488d307f52SEvan Bacon }); 498d307f52SEvan Bacon 508d307f52SEvan Bacon const results = await fetchAsync('versions/latest'); 518d307f52SEvan Bacon if (!results.ok) { 528d307f52SEvan Bacon throw new CommandError( 538d307f52SEvan Bacon 'API', 548d307f52SEvan Bacon `Unexpected response when fetching version info from Expo servers: ${results.statusText}.` 558d307f52SEvan Bacon ); 568d307f52SEvan Bacon } 578d307f52SEvan Bacon const json = await results.json(); 588d307f52SEvan Bacon return json.data; 598d307f52SEvan Bacon} 60