1import { NewManifest, BareManifest } from 'expo-manifests';
2
3export type Manifest = NewManifest | BareManifest;
4
5/**
6 * The types of update-related events.
7 */
8export enum UpdateEventType {
9  /**
10   * A new update has finished downloading to local storage. If you would like to start using this
11   * update at any point before the user closes and restarts the app on their own, you can call
12   * [`Updates.reloadAsync()`](#reloadasync) to launch this new update.
13   */
14  UPDATE_AVAILABLE = 'updateAvailable',
15  /**
16   * No updates are available, and the most up-to-date update is already running.
17   */
18  NO_UPDATE_AVAILABLE = 'noUpdateAvailable',
19  /**
20   * An error occurred trying to fetch the latest update.
21   */
22  ERROR = 'error',
23}
24
25type UpdateCheckResultRollBackToEmbedded = {
26  /**
27   * Whether an update is available. This property is false for a roll back update.
28   */
29  isAvailable: false;
30  /**
31   * The manifest of the update when available.
32   */
33  manifest: undefined;
34  /**
35   * Whether a roll back to embedded update is available.
36   */
37  isRollBackToEmbedded: true;
38};
39
40/**
41 * The successful result of checking for a new update.
42 */
43export type UpdateCheckResultSuccess = {
44  /**
45   * Whether an update is available. This property is false for a roll back update.
46   */
47  isAvailable: true;
48  /**
49   * The manifest of the update when available.
50   */
51  manifest: Manifest;
52  /**
53   * Whether a roll back to embedded update is available.
54   */
55  isRollBackToEmbedded: false;
56};
57
58/**
59 * The failed result of checking for a new update.
60 */
61export type UpdateCheckResultFailure = {
62  /**
63   * Whether an update is available. This property is false for a roll back update.
64   */
65  isAvailable: false;
66  /**
67   * The manifest of the update when available.
68   */
69  manifest: undefined;
70  /**
71   * Whether a roll back to embedded update is available.
72   */
73  isRollBackToEmbedded: false;
74};
75
76/**
77 * The result of checking for a new update.
78 */
79export type UpdateCheckResult =
80  | UpdateCheckResultRollBackToEmbedded
81  | UpdateCheckResultSuccess
82  | UpdateCheckResultFailure;
83
84/**
85 * The successful result of fetching a new update.
86 */
87export type UpdateFetchResultSuccess = {
88  /**
89   * Whether the fetched update is new (that is, a different version than what's currently running).
90   * False when roll back to embedded is true.
91   */
92  isNew: true;
93  /**
94   * The manifest of the fetched update.
95   */
96  manifest: Manifest;
97  /**
98   * Whether the fetched update is a roll back to the embedded update.
99   */
100  isRollBackToEmbedded: false;
101};
102
103/**
104 * The failed result of fetching a new update.
105 */
106export type UpdateFetchResultFailure = {
107  /**
108   * Whether the fetched update is new (that is, a different version than what's currently running).
109   * False when roll back to embedded is true.
110   */
111  isNew: false;
112  /**
113   * The manifest of the fetched update.
114   */
115  manifest: undefined;
116  /**
117   * Whether the fetched update is a roll back to the embedded update.
118   */
119  isRollBackToEmbedded: false;
120};
121
122/**
123 * The roll back to embedded result of fetching a new update.
124 */
125type UpdateFetchResultRollBackToEmbedded = {
126  /**
127   * Whether the fetched update is new (that is, a different version than what's currently running).
128   * False when roll back to embedded is true.
129   */
130  isNew: false;
131  /**
132   * The manifest of the fetched update.
133   */
134  manifest: undefined;
135  /**
136   * Whether the fetched update is a roll back to the embedded update.
137   */
138  isRollBackToEmbedded: true;
139};
140
141/**
142 * The result of fetching a new update.
143 */
144export type UpdateFetchResult =
145  | UpdateFetchResultSuccess
146  | UpdateFetchResultFailure
147  | UpdateFetchResultRollBackToEmbedded;
148
149/**
150 * An object that is passed into each event listener when an auto-update check occurs.
151 */
152export type UpdateEvent = {
153  /**
154   * Type of the event.
155   */
156  type: UpdateEventType;
157  /**
158   * If `type` is `Updates.UpdateEventType.UPDATE_AVAILABLE`, the manifest of the newly downloaded
159   * update, and `undefined` otherwise.
160   */
161  manifest?: Manifest;
162  /**
163   * If `type` is `Updates.UpdateEventType.ERROR`, the error message, and `undefined` otherwise.
164   */
165  message?: string;
166};
167
168/**
169 * An object representing a single log entry from expo-updates logging on the client.
170 */
171export type UpdatesLogEntry = {
172  /**
173   * The time the log was written, in milliseconds since Jan 1 1970 UTC.
174   */
175  timestamp: number;
176  /**
177   * The log entry message.
178   */
179  message: string;
180  /**
181   * One of the defined code values for expo-updates log entries.
182   */
183  code: UpdatesLogEntryCode;
184  /**
185   * One of the defined log level or severity values.
186   */
187  level: UpdatesLogEntryLevel;
188  /**
189   * If present, the unique ID of an update associated with this log entry.
190   */
191  updateId?: string;
192  /**
193   * If present, the unique ID or hash of an asset associated with this log entry.
194   */
195  assetId?: string;
196  /**
197   * If present, an iOS or Android native stack trace associated with this log entry.
198   */
199  stacktrace?: string[];
200};
201
202/**
203 * The possible code values for expo-updates log entries
204 */
205export enum UpdatesLogEntryCode {
206  NONE = 'None',
207  NO_UPDATES_AVAILABLE = 'NoUpdatesAvailable',
208  UPDATE_ASSETS_NOT_AVAILABLE = 'UpdateAssetsNotAvailable',
209  UPDATE_SERVER_UNREACHABLE = 'UpdateServerUnreachable',
210  UPDATE_HAS_INVALID_SIGNATURE = 'UpdateHasInvalidSignature',
211  UPDATE_CODE_SIGNING_ERROR = 'UpdateCodeSigningError',
212  UPDATE_FAILED_TO_LOAD = 'UpdateFailedToLoad',
213  ASSETS_FAILED_TO_LOAD = 'AssetsFailedToLoad',
214  JS_RUNTIME_ERROR = 'JSRuntimeError',
215  UNKNOWN = 'Unknown',
216}
217
218/**
219 * The possible log levels for expo-updates log entries
220 */
221export enum UpdatesLogEntryLevel {
222  TRACE = 'trace',
223  DEBUG = 'debug',
224  INFO = 'info',
225  WARN = 'warn',
226  ERROR = 'error',
227  FATAL = 'fatal',
228}
229
230/**
231 * The possible settings that determine if expo-updates will check for updates on app startup.
232 * By default, Expo will check for updates every time the app is loaded. Set this to `ON_ERROR_RECOVERY` to disable automatic checking unless recovering from an error. Set this to `NEVER` to completely disable automatic checking. Must be one of `ON_LOAD` (default value), `ON_ERROR_RECOVERY`, `WIFI_ONLY`, or `NEVER`
233 */
234export enum UpdatesCheckAutomaticallyValue {
235  /**
236   * Checks for updates whenever the app is loaded. This is the default setting.
237   */
238  ON_LOAD = 'ON_LOAD',
239  /**
240   * Only checks for updates when the app starts up after an error recovery.
241   */
242  ON_ERROR_RECOVERY = 'ON_ERROR_RECOVERY',
243  /**
244   * Only checks for updates when the app starts and has a WiFi connection.
245   */
246  WIFI_ONLY = 'WIFI_ONLY',
247  /**
248   * Automatic update checks are off, and update checks must be done through the JS API.
249   */
250  NEVER = 'NEVER',
251}
252
253// @docsMissing
254/**
255 * @hidden
256 */
257export type LocalAssets = Record<string, string>;
258
259/**
260 * @hidden
261 */
262export type UpdatesNativeStateMachineContext = {
263  // The native state machine context, either read directly from a native module method,
264  // or received in a state change event. Used internally by this module and not exported publicly.
265  isUpdateAvailable: boolean;
266  isUpdatePending: boolean;
267  isChecking: boolean;
268  isDownloading: boolean;
269  isRollback: boolean;
270  isRestarting: boolean;
271  latestManifest?: Manifest;
272  downloadedManifest?: Manifest;
273  checkError?: Error;
274  downloadError?: Error;
275  lastCheckForUpdateTime?: Date;
276};
277
278/**
279 * @hidden
280 */
281export type UpdatesNativeStateChangeEvent = {
282  // Change event emitted by native
283  context: UpdatesNativeStateMachineContext;
284};
285