xref: /expo/packages/@expo/cli/src/api/getVersions.ts (revision 2fd75d6d)
1import { CommandError } from '../utils/errors';
2import { createCachedFetch } from './rest/client';
3
4/** Represents version info for a particular SDK. */
5export type SDKVersion = {
6  /** @example "2.16.1" */
7  iosVersion?: string;
8  /** @example "https://dpq5q02fu5f55.cloudfront.net/Exponent-2.17.4.tar.gz" */
9  iosClientUrl?: string;
10  /** @example "https://dev.to/expo/expo-sdk-38-is-now-available-5aa0" */
11  releaseNoteUrl?: string;
12  /** @example "2.17.4" */
13  iosClientVersion?: string;
14  /** @example "https://d1ahtucjixef4r.cloudfront.net/Exponent-2.16.1.apk" */
15  androidClientUrl?: string;
16  /** @example "2.16.1" */
17  androidClientVersion?: string;
18  /** @example { "typescript": "~3.9.5" } */
19  relatedPackages?: Record<string, string>;
20
21  facebookReactNativeVersion: string;
22
23  facebookReactVersion?: string;
24
25  beta?: boolean;
26};
27
28export type SDKVersions = Record<string, SDKVersion>;
29
30export type Versions = {
31  androidUrl: string;
32  androidVersion: string;
33  iosUrl: string;
34  iosVersion: string;
35  sdkVersions: SDKVersions;
36};
37
38/** Get versions from remote endpoint. */
39export async function getVersionsAsync({
40  skipCache,
41}: { skipCache?: boolean } = {}): Promise<Versions> {
42  // Reconstruct the cached fetch since caching could be disabled.
43  const fetchAsync = createCachedFetch({
44    skipCache,
45    cacheDirectory: 'versions-cache',
46    // We'll use a 5 minute cache to ensure we stay relatively up to date.
47    ttl: 1000 * 60 * 5,
48  });
49
50  const results = await fetchAsync('versions/latest');
51  if (!results.ok) {
52    throw new CommandError(
53      'API',
54      `Unexpected response when fetching version info from Expo servers: ${results.statusText}.`
55    );
56  }
57  const json = await results.json();
58  return json.data;
59}
60