1import Constants from 'expo-constants';
2
3/**
4 * The types of update-related events.
5 */
6export enum UpdateEventType {
7  /**
8   * A new update has finished downloading to local storage. If you would like to start using this
9   * update at any point before the user closes and restarts the app on their own, you can call
10   * [`Updates.reloadAsync()`](#reloadasync) to launch this new update.
11   */
12  UPDATE_AVAILABLE = 'updateAvailable',
13  /**
14   * No updates are available, and the most up-to-date update is already running.
15   */
16  NO_UPDATE_AVAILABLE = 'noUpdateAvailable',
17  /**
18   * An error occurred trying to fetch the latest update.
19   */
20  ERROR = 'error',
21}
22
23// @docsMissing
24// TODO(eric): move source of truth for manifest type to this module
25/**
26 * @hidden
27 */
28export type ClassicManifest = typeof Constants.manifest;
29
30// @docsMissing
31/**
32 * @hidden
33 */
34export type Manifest = ClassicManifest | typeof Constants.manifest2;
35// modern manifest type is intentionally not exported, since the plan is to call it just "Manifest"
36// in the future
37
38type UpdateCheckResultRollBackToEmbedded = {
39  /**
40   * This property is false for a roll back update.
41   */
42  isAvailable: false;
43  /**
44   * No manifest, since this is a roll back update.
45   */
46  manifest: undefined;
47  /**
48   * Signifies that a roll back update is available.
49   */
50  isRollBackToEmbedded: true;
51};
52
53/**
54 * The successful result of checking for a new update.
55 */
56export type UpdateCheckResultSuccess = {
57  /**
58   * Signifies that an update is available.
59   */
60  isAvailable: true;
61  /**
62   * The manifest of the available update.
63   */
64  manifest: Manifest;
65  /**
66   * This property is false for a new update.
67   */
68  isRollBackToEmbedded: false;
69};
70
71/**
72 * The failed result of checking for a new update.
73 */
74export type UpdateCheckResultFailure = {
75  /**
76   * Signifies that the app is already running the latest available update.
77   */
78  isAvailable: false;
79  /**
80   * No manifest, since the app is already running the latest available version.
81   */
82  manifest: undefined;
83  /**
84   * Signifies that no roll back update is available.
85   */
86  isRollBackToEmbedded: false;
87};
88
89/**
90 * The result of checking for a new update.
91 */
92export type UpdateCheckResult =
93  | UpdateCheckResultRollBackToEmbedded
94  | UpdateCheckResultSuccess
95  | UpdateCheckResultFailure;
96
97/**
98 * The successful result of fetching a new update.
99 */
100export type UpdateFetchResultSuccess = {
101  /**
102   * Signifies that the fetched bundle is new (that is, a different version than what's currently
103   * running).
104   */
105  isNew: true;
106  /**
107   * The manifest of the newly downloaded update.
108   */
109  manifest: Manifest;
110};
111
112/**
113 * The failed result of fetching a new update.
114 */
115export type UpdateFetchResultFailure = {
116  /**
117   * Signifies that the fetched bundle is the same as version which is currently running.
118   */
119  isNew: false;
120  /**
121   * No manifest, since there is no update.
122   */
123  manifest: undefined;
124};
125
126/**
127 * The rollback to embedded result of fetching a new update.
128 */
129type UpdateFetchResultRollbackToEmbedded = {
130  /**
131   * Signifies that the update was a roll back to the embedded update.
132   */
133  isRollBackToEmbedded: true;
134};
135
136/**
137 * The result of fetching a new update.
138 */
139export type UpdateFetchResult =
140  | UpdateFetchResultSuccess
141  | UpdateFetchResultFailure
142  | UpdateFetchResultRollbackToEmbedded;
143
144/**
145 * An object that is passed into each event listener when an auto-update check occurs.
146 */
147export type UpdateEvent = {
148  /**
149   * Type of the event.
150   */
151  type: UpdateEventType;
152  /**
153   * If `type` is `Updates.UpdateEventType.UPDATE_AVAILABLE`, the manifest of the newly downloaded
154   * update, and `undefined` otherwise.
155   */
156  manifest?: Manifest;
157  /**
158   * If `type` is `Updates.UpdateEventType.ERROR`, the error message, and `undefined` otherwise.
159   */
160  message?: string;
161};
162
163/**
164 * An object representing a single log entry from expo-updates logging on the client.
165 */
166export type UpdatesLogEntry = {
167  /**
168   * The time the log was written, in milliseconds since Jan 1 1970 UTC.
169   */
170  timestamp: number;
171  /**
172   * The log entry message.
173   */
174  message: string;
175  /**
176   * One of the defined code values for expo-updates log entries.
177   */
178  code: UpdatesLogEntryCode;
179  /**
180   * One of the defined log level or severity values.
181   */
182  level: UpdatesLogEntryLevel;
183  /**
184   * If present, the unique ID of an update associated with this log entry.
185   */
186  updateId?: string;
187  /**
188   * If present, the unique ID or hash of an asset associated with this log entry.
189   */
190  assetId?: string;
191  /**
192   * If present, an iOS or Android native stack trace associated with this log entry.
193   */
194  stacktrace?: string[];
195};
196
197/**
198 * The possible code values for expo-updates log entries
199 */
200export enum UpdatesLogEntryCode {
201  NONE = 'None',
202  NO_UPDATES_AVAILABLE = 'NoUpdatesAvailable',
203  UPDATE_ASSETS_NOT_AVAILABLE = 'UpdateAssetsNotAvailable',
204  UPDATE_SERVER_UNREACHABLE = 'UpdateServerUnreachable',
205  UPDATE_HAS_INVALID_SIGNATURE = 'UpdateHasInvalidSignature',
206  UPDATE_CODE_SIGNING_ERROR = 'UpdateCodeSigningError',
207  UPDATE_FAILED_TO_LOAD = 'UpdateFailedToLoad',
208  ASSETS_FAILED_TO_LOAD = 'AssetsFailedToLoad',
209  JS_RUNTIME_ERROR = 'JSRuntimeError',
210  UNKNOWN = 'Unknown',
211}
212
213/**
214 * The possible log levels for expo-updates log entries
215 */
216export enum UpdatesLogEntryLevel {
217  TRACE = 'trace',
218  DEBUG = 'debug',
219  INFO = 'info',
220  WARN = 'warn',
221  ERROR = 'error',
222  FATAL = 'fatal',
223}
224
225// @docsMissing
226/**
227 * @hidden
228 */
229export type LocalAssets = Record<string, string>;
230