1import type { Manifest } from './Updates.types'; 2 3/** 4 * Structure encapsulating information on the currently running app 5 * (either the embedded bundle or a downloaded update). 6 */ 7export type CurrentlyRunningInfo = { 8 /** 9 * The UUID that uniquely identifies the currently running update if `expo-updates` is enabled. The 10 * UUID is represented in its canonical string form (`xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`) and 11 * will always use lowercase letters. In development mode, or any other environment in which 12 * `expo-updates` is disabled, this value is undefined. 13 */ 14 updateId?: string; 15 /** 16 * The channel name of the current build, if configured for use with EAS Update; undefined otherwise. 17 */ 18 channel?: string; 19 /** 20 * If `expo-updates` is enabled, this is a `Date` object representing the creation time of the update 21 * that's currently running (whether it was embedded or downloaded at runtime). 22 * 23 * In development mode, or any other environment in which `expo-updates` is disabled, this value is 24 * undefined. 25 */ 26 createdAt?: Date; 27 /** 28 * This will be true if the currently running update is the one embedded in the build, 29 * and not one downloaded from the updates server. 30 */ 31 isEmbeddedLaunch: boolean; 32 /** 33 * `expo-updates` does its very best to always launch monotonically newer versions of your app so 34 * you don't need to worry about backwards compatibility when you put out an update. In very rare 35 * cases, it's possible that `expo-updates` may need to fall back to the update that's embedded in 36 * the app binary, even after newer updates have been downloaded and run (an "emergency launch"). 37 * This boolean will be `true` if the app is launching under this fallback mechanism and `false` 38 * otherwise. If you are concerned about backwards compatibility of future updates to your app, you 39 * can use this constant to provide special behavior for this rare case. 40 */ 41 isEmergencyLaunch: boolean; 42 /** 43 * If `expo-updates` is enabled, this is the 44 * [manifest](https://docs.expo.dev/versions/latest/sdk/updates/#updatesmanifest) object for the update that's currently 45 * running. 46 * 47 * In development mode, or any other environment in which `expo-updates` is disabled, this object is 48 * empty. 49 */ 50 manifest?: Partial<Manifest>; 51 /** 52 * The runtime version of the current build. 53 */ 54 runtimeVersion?: string; 55}; 56 57/** 58 * The different possible types of updates. 59 * Currently, the only supported type is `UpdateInfoType.NEW`, indicating a new update that can be downloaded and launched 60 * on the device. 61 * In future, other types of updates may be added to this list. 62 */ 63export enum UpdateInfoType { 64 /** 65 * This is the type for new updates found on or downloaded from the update server, that are launchable on the device. 66 */ 67 NEW = 'new', 68 /** 69 * This type is used when an update is a directive to roll back to the embedded bundle. 70 */ 71 ROLLBACK = 'rollback', 72} 73 74/** 75 * Structure representing a new update. 76 */ 77type UpdateInfoNew = { 78 /** 79 * The type of update. 80 */ 81 type: UpdateInfoType.NEW; 82 /** 83 * For updates of type `UpdateInfoType.NEW`, this is 84 * a string that uniquely identifies the update. For the manifests used in the current Expo Updates protocol (including 85 * EAS Update), this represents the update's UUID in its canonical string form (`xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`) 86 * and will always use lowercase letters. 87 */ 88 updateId: string; 89 /** 90 * For all types of updates, this is 91 * a `Date` object representing the creation time or commit time of the update. 92 */ 93 createdAt: Date; 94 /** 95 * For updates of type `UpdateInfoType.NEW`, this is 96 * the [manifest](https://docs.expo.dev/versions/latest/sdk/constants/#manifest) for the update. 97 */ 98 manifest: Manifest; 99}; 100 101/** 102 * Structure representing a rollback directive. 103 */ 104type UpdateInfoRollback = { 105 /** 106 * The type of update. 107 */ 108 type: UpdateInfoType.ROLLBACK; 109 /** 110 * For updates of type `UpdateInfoType.ROLLBACK`, this is undefined. 111 */ 112 updateId: undefined; 113 /** 114 * For all types of updates, this is 115 * a `Date` object representing the creation time or commit time of the update. 116 */ 117 createdAt: Date; 118 /** 119 * For updates of type `UpdateInfoType.ROLLBACK`, this is undefined. 120 */ 121 manifest: undefined; 122}; 123 124/** 125 * Combined structure representing any type of update. 126 */ 127export type UpdateInfo = UpdateInfoNew | UpdateInfoRollback; 128 129/** 130 * The structures and methods returned by `useUpdates()`. 131 */ 132export type UseUpdatesReturnType = { 133 /** 134 * Information on the currently running app 135 */ 136 currentlyRunning: CurrentlyRunningInfo; 137 /** 138 * If a new available update has been found, either by using checkForUpdate(), 139 * or by the `UpdateEvent` listener in `useUpdates()`, 140 * this will contain the information for that update. 141 */ 142 availableUpdate?: UpdateInfo; 143 /** 144 * If an available update has been downloaded, this will contain the information 145 * for that update. 146 */ 147 downloadedUpdate?: UpdateInfo; 148 /** 149 * True if a new available update has been found, false otherwise. 150 */ 151 isUpdateAvailable: boolean; 152 /** 153 * True if a new available update is available and has been downloaded. 154 */ 155 isUpdatePending: boolean; 156 /** 157 * True if the app is currently checking for a new available update from the server. 158 */ 159 isChecking: boolean; 160 /** 161 * True if the app is currently downloading an update from the server. 162 */ 163 isDownloading: boolean; 164 /** 165 * If an error is returned from either the startup check for updates, or a call to `checkForUpdateAsync()`, 166 * the error description will appear here. 167 */ 168 checkError?: Error; 169 /** 170 * If an error is returned from either a startup update download, or a call to `fetchUpdateAsync()`, 171 * the error description will appear here. 172 */ 173 downloadError?: Error; 174 /** 175 * If an error occurs during initialization of `useUpdates()`, the error description will appear here. 176 */ 177 initializationError?: Error; 178 /** 179 * A `Date` object representing the last time this client checked for an available update, 180 * or `undefined` if no check has yet occurred since the app started. Does not persist across 181 * app reloads or restarts. 182 */ 183 lastCheckForUpdateTimeSinceRestart?: Date; 184}; 185