@capgo/capacitor-updater 8.0.0 → 8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CapgoCapacitorUpdater.podspec +2 -2
  2. package/Package.swift +35 -0
  3. package/README.md +667 -206
  4. package/android/build.gradle +16 -11
  5. package/android/proguard-rules.pro +28 -0
  6. package/android/src/main/AndroidManifest.xml +0 -1
  7. package/android/src/main/java/ee/forgr/capacitor_updater/BundleInfo.java +134 -194
  8. package/android/src/main/java/ee/forgr/capacitor_updater/BundleStatus.java +23 -23
  9. package/android/src/main/java/ee/forgr/capacitor_updater/Callback.java +13 -0
  10. package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java +967 -1027
  11. package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +1283 -1180
  12. package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipherV2.java +276 -0
  13. package/android/src/main/java/ee/forgr/capacitor_updater/DataManager.java +28 -0
  14. package/android/src/main/java/ee/forgr/capacitor_updater/DelayCondition.java +45 -48
  15. package/android/src/main/java/ee/forgr/capacitor_updater/DelayUntilNext.java +4 -4
  16. package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +440 -113
  17. package/android/src/main/java/ee/forgr/capacitor_updater/DownloadWorkerManager.java +101 -0
  18. package/android/src/main/java/ee/forgr/capacitor_updater/InternalUtils.java +32 -0
  19. package/dist/docs.json +1316 -473
  20. package/dist/esm/definitions.d.ts +518 -248
  21. package/dist/esm/definitions.js.map +1 -1
  22. package/dist/esm/index.d.ts +2 -2
  23. package/dist/esm/index.js +4 -4
  24. package/dist/esm/index.js.map +1 -1
  25. package/dist/esm/web.d.ts +25 -41
  26. package/dist/esm/web.js +67 -35
  27. package/dist/esm/web.js.map +1 -1
  28. package/dist/plugin.cjs.js +67 -35
  29. package/dist/plugin.cjs.js.map +1 -1
  30. package/dist/plugin.js +67 -35
  31. package/dist/plugin.js.map +1 -1
  32. package/ios/Plugin/CapacitorUpdater.swift +736 -361
  33. package/ios/Plugin/CapacitorUpdaterPlugin.swift +436 -136
  34. package/ios/Plugin/CryptoCipherV2.swift +310 -0
  35. package/ios/Plugin/InternalUtils.swift +258 -0
  36. package/package.json +33 -29
  37. package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipher.java +0 -153
  38. package/ios/Plugin/CapacitorUpdaterPlugin.h +0 -10
  39. package/ios/Plugin/CapacitorUpdaterPlugin.m +0 -27
  40. package/ios/Plugin/CryptoCipher.swift +0 -240
@@ -1,8 +1,8 @@
1
- import type { PluginListenerHandle } from "@capacitor/core";
2
- declare module "@capacitor/cli" {
1
+ import type { PluginListenerHandle } from '@capacitor/core';
2
+ declare module '@capacitor/cli' {
3
3
  interface PluginsConfig {
4
4
  /**
5
- * These configuration values are available:
5
+ * CapacitorUpdater can be configured with these options:
6
6
  */
7
7
  CapacitorUpdater?: {
8
8
  /**
@@ -14,6 +14,15 @@ declare module "@capacitor/cli" {
14
14
  * @example 1000 // (1 second)
15
15
  */
16
16
  appReadyTimeout?: number;
17
+ /**
18
+ * Configure the number of milliseconds the native plugin should wait before considering API timeout.
19
+ *
20
+ * Only available for Android and iOS.
21
+ *
22
+ * @default 20 // (20 second)
23
+ * @example 10 // (10 second)
24
+ */
25
+ responseTimeout?: number;
17
26
  /**
18
27
  * Configure whether the plugin should use automatically delete failed bundles.
19
28
  *
@@ -55,27 +64,37 @@ declare module "@capacitor/cli" {
55
64
  *
56
65
  * Only available for Android and iOS.
57
66
  *
58
- * @default https://api.capgo.app/auto_update
67
+ * @default https://plugin.capgo.app/updates
59
68
  * @example https://example.com/api/auto_update
60
69
  */
61
70
  updateUrl?: string;
71
+ /**
72
+ * Configure the URL / endpoint for channel operations.
73
+ *
74
+ * Only available for Android and iOS.
75
+ *
76
+ * @default https://plugin.capgo.app/channel_self
77
+ * @example https://example.com/api/channel
78
+ */
79
+ channelUrl?: string;
62
80
  /**
63
81
  * Configure the URL / endpoint to which update statistics are sent.
64
82
  *
65
83
  * Only available for Android and iOS. Set to "" to disable stats reporting.
66
84
  *
67
- * @default https://api.capgo.app/stats
85
+ * @default https://plugin.capgo.app/stats
68
86
  * @example https://example.com/api/stats
69
87
  */
70
88
  statsUrl?: string;
71
89
  /**
72
- * Configure the private key for end to end live update encryption.
90
+ * Configure the public key for end to end live update encryption Version 2
73
91
  *
74
92
  * Only available for Android and iOS.
75
93
  *
76
94
  * @default undefined
95
+ * @since 6.2.0
77
96
  */
78
- privateKey?: string;
97
+ publicKey?: string;
79
98
  /**
80
99
  * Configure the current version of the app. This will be used for the first update request.
81
100
  * If not set, the plugin will get the version from the native code.
@@ -86,368 +105,619 @@ declare module "@capacitor/cli" {
86
105
  * @since 4.17.48
87
106
  */
88
107
  version?: string;
108
+ /**
109
+ * Make the plugin direct install the update when the app what just updated/installed. Only for autoUpdate mode.
110
+ *
111
+ * Only available for Android and iOS.
112
+ *
113
+ * @default undefined
114
+ * @since 5.1.0
115
+ */
116
+ directUpdate?: boolean;
117
+ /**
118
+ * Configure the delay period for period update check. the unit is in seconds.
119
+ *
120
+ * Only available for Android and iOS.
121
+ * Cannot be less than 600 seconds (10 minutes).
122
+ *
123
+ * @default 600 // (10 minutes)
124
+ */
125
+ periodCheckDelay?: number;
126
+ /**
127
+ * Configure the CLI to use a local server for testing or self-hosted update server.
128
+ *
129
+ *
130
+ * @default undefined
131
+ * @since 4.17.48
132
+ */
133
+ localS3?: boolean;
134
+ /**
135
+ * Configure the CLI to use a local server for testing or self-hosted update server.
136
+ *
137
+ *
138
+ * @default undefined
139
+ * @since 4.17.48
140
+ */
141
+ localHost?: string;
142
+ /**
143
+ * Configure the CLI to use a local server for testing or self-hosted update server.
144
+ *
145
+ *
146
+ * @default undefined
147
+ * @since 4.17.48
148
+ */
149
+ localWebHost?: string;
150
+ /**
151
+ * Configure the CLI to use a local server for testing or self-hosted update server.
152
+ *
153
+ *
154
+ * @default undefined
155
+ * @since 4.17.48
156
+ */
157
+ localSupa?: string;
158
+ /**
159
+ * Configure the CLI to use a local server for testing.
160
+ *
161
+ *
162
+ * @default undefined
163
+ * @since 4.17.48
164
+ */
165
+ localSupaAnon?: string;
166
+ /**
167
+ * Configure the CLI to use a local api for testing.
168
+ *
169
+ *
170
+ * @default undefined
171
+ * @since 6.3.3
172
+ */
173
+ localApi?: string;
174
+ /**
175
+ * Configure the CLI to use a local file api for testing.
176
+ *
177
+ *
178
+ * @default undefined
179
+ * @since 6.3.3
180
+ */
181
+ localApiFiles?: string;
182
+ /**
183
+ * Allow the plugin to modify the updateUrl, statsUrl and channelUrl dynamically from the JavaScript side.
184
+ *
185
+ *
186
+ * @default false
187
+ * @since 5.4.0
188
+ */
189
+ allowModifyUrl?: boolean;
190
+ /**
191
+ * Set the default channel for the app in the config.
192
+ *
193
+ *
194
+ *
195
+ * @default undefined
196
+ * @since 5.5.0
197
+ */
198
+ defaultChannel?: string;
199
+ /**
200
+ * Configure the app id for the app in the config.
201
+ *
202
+ * @default undefined
203
+ * @since 6.0.0
204
+ */
205
+ appId?: string;
206
+ /**
207
+ * Configure the plugin to keep the URL path after a reload.
208
+ * WARNING: When a reload is triggered, 'window.history' will be cleared.
209
+ *
210
+ * @default false
211
+ * @since 6.8.0
212
+ */
213
+ keepUrlPathAfterReload?: boolean;
89
214
  };
90
215
  }
91
216
  }
92
- export interface noNeedEvent {
93
- /**
94
- * Current status of download, between 0 and 100.
95
- *
96
- * @since 4.0.0
97
- */
98
- bundle: BundleInfo;
99
- }
100
- export interface updateAvailableEvent {
101
- /**
102
- * Current status of download, between 0 and 100.
103
- *
104
- * @since 4.0.0
105
- */
106
- bundle: BundleInfo;
107
- }
108
- export interface channelRes {
109
- /**
110
- * Current status of set channel
111
- *
112
- * @since 4.7.0
113
- */
114
- status: string;
115
- error?: any;
116
- message?: any;
117
- }
118
- export interface getChannelRes {
119
- /**
120
- * Current status of get channel
121
- *
122
- * @since 4.8.0
123
- */
124
- channel?: string;
125
- error?: any;
126
- message?: any;
127
- status?: string;
128
- allowSet?: boolean;
129
- }
130
- export interface DownloadEvent {
131
- /**
132
- * Current status of download, between 0 and 100.
133
- *
134
- * @since 4.0.0
135
- */
136
- percent: number;
137
- bundle: BundleInfo;
138
- }
139
- export interface MajorAvailableEvent {
217
+ export interface CapacitorUpdaterPlugin {
140
218
  /**
141
- * Emit when a new major bundle is available.
219
+ * Notify Capacitor Updater that the current bundle is working (a rollback will occur if this method is not called on every app launch)
220
+ * By default this method should be called in the first 10 sec after app launch, otherwise a rollback will occur.
221
+ * Change this behaviour with {@link appReadyTimeout}
142
222
  *
143
- * @since 4.0.0
223
+ * @returns {Promise<AppReadyResult>} an Promise resolved directly
224
+ * @throws {Error}
144
225
  */
145
- version: string;
146
- }
147
- export interface DownloadFailedEvent {
226
+ notifyAppReady(): Promise<AppReadyResult>;
148
227
  /**
149
- * Emit when a download fail.
228
+ * Set the updateUrl for the app, this will be used to check for updates.
150
229
  *
151
- * @since 4.0.0
230
+ * @param options contains the URL to use for checking for updates.
231
+ * @returns {Promise<void>}
232
+ * @throws {Error}
233
+ * @since 5.4.0
152
234
  */
153
- version: string;
154
- }
155
- export interface DownloadCompleteEvent {
235
+ setUpdateUrl(options: UpdateUrl): Promise<void>;
156
236
  /**
157
- * Emit when a new update is available.
237
+ * Set the statsUrl for the app, this will be used to send statistics. Passing an empty string will disable statistics gathering.
158
238
  *
159
- * @since 4.0.0
239
+ * @param options contains the URL to use for sending statistics.
240
+ * @returns {Promise<void>}
241
+ * @throws {Error}
242
+ * @since 5.4.0
160
243
  */
161
- bundle: BundleInfo;
162
- }
163
- export interface UpdateFailedEvent {
244
+ setStatsUrl(options: StatsUrl): Promise<void>;
164
245
  /**
165
- * Emit when a update failed to install.
246
+ * Set the channelUrl for the app, this will be used to set the channel.
166
247
  *
167
- * @since 4.0.0
248
+ * @param options contains the URL to use for setting the channel.
249
+ * @returns {Promise<void>}
250
+ * @throws {Error}
251
+ * @since 5.4.0
168
252
  */
169
- bundle: BundleInfo;
170
- }
171
- export interface latestVersion {
172
- /**
173
- * Res of getLatest method
174
- *
175
- * @since 4.0.0
176
- */
177
- version: string;
178
- major?: boolean;
179
- message?: string;
180
- sessionKey?: string;
181
- error?: string;
182
- old?: string;
183
- url?: string;
184
- }
185
- export interface BundleInfo {
186
- id: string;
187
- version: string;
188
- downloaded: string;
189
- checksum: string;
190
- status: BundleStatus;
191
- }
192
- export interface SetChannelOptions {
193
- channel: string;
194
- }
195
- export interface SetCustomIdOptions {
196
- customId: string;
197
- }
198
- export interface DelayCondition {
199
- /**
200
- * Set up delay conditions in setMultiDelay
201
- * @param value is useless for @param kind "kill", optional for "background" (default value: "0") and required for "nativeVersion" and "date"
202
- */
203
- kind: DelayUntilNext;
204
- value?: string;
205
- }
206
- export type BundleStatus = "success" | "error" | "pending" | "downloading";
207
- export type DelayUntilNext = "background" | "kill" | "nativeVersion" | "date";
208
- export type DownloadChangeListener = (state: DownloadEvent) => void;
209
- export type NoNeedListener = (state: noNeedEvent) => void;
210
- export type UpdateAvailabledListener = (state: updateAvailableEvent) => void;
211
- export type DownloadFailedListener = (state: DownloadFailedEvent) => void;
212
- export type DownloadCompleteListener = (state: DownloadCompleteEvent) => void;
213
- export type MajorAvailableListener = (state: MajorAvailableEvent) => void;
214
- export type UpdateFailedListener = (state: UpdateFailedEvent) => void;
215
- export type AppReloadedListener = (state: void) => void;
216
- export interface CapacitorUpdaterPlugin {
217
- /**
218
- * Notify Capacitor Updater that the current bundle is working (a rollback will occur of this method is not called on every app launch)
219
- * By default this method should be called in the first 10 sec after app launch, otherwise a rollback will occur.
220
- * Change this behaviour with {@link appReadyTimeout}
221
- *
222
- * @returns {Promise<BundleInfo>} an Promise resolved directly
223
- * @throws An error if something went wrong
224
- */
225
- notifyAppReady(): Promise<BundleInfo>;
253
+ setChannelUrl(options: ChannelUrl): Promise<void>;
226
254
  /**
227
255
  * Download a new bundle from the provided URL, it should be a zip file, with files inside or with a unique id inside with all your files
228
256
  *
257
+ * @example const bundle = await CapacitorUpdater.download({ url: `https://example.com/versions/${version}/dist.zip`, version });
229
258
  * @returns {Promise<BundleInfo>} The {@link BundleInfo} for the specified bundle.
230
- * @param url The URL of the bundle zip file (e.g: dist.zip) to be downloaded. (This can be any URL. E.g: Amazon S3, a github tag, any other place you've hosted your bundle.)
231
- * @param version set the version code/name of this bundle/version
232
- * @example https://example.com/versions/{version}/dist.zip
259
+ * @param options The {@link DownloadOptions} for downloading a new bundle zip.
233
260
  */
234
- download(options: {
235
- url: string;
236
- version: string;
237
- sessionKey?: string;
238
- checksum?: string;
239
- }): Promise<BundleInfo>;
261
+ download(options: DownloadOptions): Promise<BundleInfo>;
240
262
  /**
241
263
  * Set the next bundle to be used when the app is reloaded.
242
264
  *
265
+ * @param options Contains the ID of the next Bundle to set on next app launch. {@link BundleInfo.id}
243
266
  * @returns {Promise<BundleInfo>} The {@link BundleInfo} for the specified bundle id.
244
- * @param id The bundle id to set as current, next time the app is reloaded. See {@link BundleInfo.id}
245
- * @throws An error if there are is no index.html file inside the bundle folder.
267
+ * @throws {Error} When there is no index.html file inside the bundle folder.
246
268
  */
247
- next(options: {
248
- id: string;
249
- }): Promise<BundleInfo>;
269
+ next(options: BundleId): Promise<BundleInfo>;
250
270
  /**
251
271
  * Set the current bundle and immediately reloads the app.
252
272
  *
253
- * @param id The bundle id to set as current. See {@link BundleInfo.id}
254
- * @returns {Promise<Void>} An empty promise.
255
- * @throws An error if there are is no index.html file inside the bundle folder.
273
+ * @param options A {@link BundleId} object containing the new bundle id to set as current.
274
+ * @returns {Promise<void>}
275
+ * @throws {Error} When there are is no index.html file inside the bundle folder.
256
276
  */
257
- set(options: {
258
- id: string;
259
- }): Promise<void>;
277
+ set(options: BundleId): Promise<void>;
260
278
  /**
261
- * Delete bundle in storage
279
+ * Deletes the specified bundle from the native app storage. Use with {@link list} to get the stored Bundle IDs.
262
280
  *
263
- * @returns {Promise<void>} an empty Promise when the bundle is deleted
264
- * @param id The bundle id to delete (note, this is the bundle id, NOT the version name)
265
- * @throws An error if the something went wrong
281
+ * @param options A {@link BundleId} object containing the ID of a bundle to delete (note, this is the bundle id, NOT the version name)
282
+ * @returns {Promise<void>} When the bundle is deleted
283
+ * @throws {Error}
266
284
  */
267
- delete(options: {
268
- id: string;
269
- }): Promise<void>;
285
+ delete(options: BundleId): Promise<void>;
270
286
  /**
271
- * Get all available bundles
287
+ * Get all locally downloaded bundles in your app
272
288
  *
273
- * @returns {Promise<{bundles: BundleInfo[]}>} an Promise witht the bundles list
274
- * @throws An error if the something went wrong
289
+ * @returns {Promise<BundleListResult>} A Promise containing the {@link BundleListResult.bundles}
290
+ * @param options The {@link ListOptions} for listing bundles
291
+ * @throws {Error}
275
292
  */
276
- list(): Promise<{
277
- bundles: BundleInfo[];
278
- }>;
293
+ list(options?: ListOptions): Promise<BundleListResult>;
279
294
  /**
280
- * Set the `builtin` bundle (the one sent to Apple store / Google play store ) as current bundle
295
+ * Reset the app to the `builtin` bundle (the one sent to Apple App Store / Google Play Store ) or the last successfully loaded bundle.
281
296
  *
282
- * @returns {Promise<void>} an empty Promise
283
- * @param toLastSuccessful [false] if yes it reset to to the last successfully loaded bundle instead of `builtin`
284
- * @throws An error if the something went wrong
297
+ * @param options Containing {@link ResetOptions.toLastSuccessful}, `true` resets to the builtin bundle and `false` will reset to the last successfully loaded bundle.
298
+ * @returns {Promise<void>}
299
+ * @throws {Error}
285
300
  */
286
- reset(options?: {
287
- toLastSuccessful?: boolean;
288
- }): Promise<void>;
301
+ reset(options?: ResetOptions): Promise<void>;
289
302
  /**
290
- * Get the current bundle, if none are set it returns `builtin`, currentNative is the original bundle installed on the device
303
+ * Get the current bundle, if none are set it returns `builtin`. currentNative is the original bundle installed on the device
291
304
  *
292
- * @returns {Promise<{ bundle: BundleInfo, native: string }>} an Promise with the current bundle info
293
- * @throws An error if the something went wrong
305
+ * @returns {Promise<CurrentBundleResult>} A Promise evaluating to the {@link CurrentBundleResult}
306
+ * @throws {Error}
294
307
  */
295
- current(): Promise<{
296
- bundle: BundleInfo;
297
- native: string;
298
- }>;
308
+ current(): Promise<CurrentBundleResult>;
299
309
  /**
300
310
  * Reload the view
301
311
  *
302
- * @returns {Promise<void>} an Promise resolved when the view is reloaded
303
- * @throws An error if the something went wrong
312
+ * @returns {Promise<void>} A Promise which is resolved when the view is reloaded
313
+ * @throws {Error}
304
314
  */
305
315
  reload(): Promise<void>;
306
316
  /**
307
- * Set DelayCondition, skip updates until one of the conditions is met
308
- *
309
- * @returns {Promise<void>} an Promise resolved directly
310
- * @param options are the {@link DelayCondition} list to set
317
+ * Sets a {@link DelayCondition} array containing conditions that the Plugin will use to delay the update.
318
+ * After all conditions are met, the update process will run start again as usual, so update will be installed after a backgrounding or killing the app.
319
+ * For the `date` kind, the value should be an iso8601 date string.
320
+ * For the `background` kind, the value should be a number in milliseconds.
321
+ * For the `nativeVersion` kind, the value should be the version number.
322
+ * For the `kill` kind, the value is not used.
323
+ * The function has unconsistent behavior the option kill do trigger the update after the first kill and not after the next background like other options. This will be fixed in a future major release.
311
324
  *
312
325
  * @example
313
- * setMultiDelay({ delayConditions: [{ kind: 'kill' }, { kind: 'background', value: '300000' }] })
314
- * // installs the update after the user kills the app or after a background of 300000 ms (5 minutes)
315
- *
326
+ * // Delay the update after the user kills the app or after a background of 300000 ms (5 minutes)
327
+ * await CapacitorUpdater.setMultiDelay({ delayConditions: [{ kind: 'kill' }, { kind: 'background', value: '300000' }] })
316
328
  * @example
317
- * setMultiDelay({ delayConditions: [{ kind: 'date', value: '2022-09-14T06:14:11.920Z' }] })
318
- * // installs the update after the specific iso8601 date is expired
319
- *
329
+ * // Delay the update after the specific iso8601 date is expired
330
+ * await CapacitorUpdater.setMultiDelay({ delayConditions: [{ kind: 'date', value: '2022-09-14T06:14:11.920Z' }] })
320
331
  * @example
321
- * setMultiDelay({ delayConditions: [{ kind: 'background' }] })
322
- * // installs the update after the the first background (default behaviour without setting delay)
323
- *
324
- * @throws An error if the something went wrong
332
+ * // Delay the update after the first background (default behaviour without setting delay)
333
+ * await CapacitorUpdater.setMultiDelay({ delayConditions: [{ kind: 'background' }] })
334
+ * @param options Containing the {@link MultiDelayConditions} array of conditions to set
335
+ * @returns {Promise<void>}
336
+ * @throws {Error}
325
337
  * @since 4.3.0
326
338
  */
327
- setMultiDelay(options: {
328
- delayConditions: DelayCondition[];
329
- }): Promise<void>;
339
+ setMultiDelay(options: MultiDelayConditions): Promise<void>;
330
340
  /**
331
- * Cancel delay to updates as usual
341
+ * Cancels a {@link DelayCondition} to process an update immediately.
332
342
  *
333
- * @returns {Promise<void>} an Promise resolved directly
334
- * @throws An error if the something went wrong
343
+ * @returns {Promise<void>}
344
+ * @throws {Error}
335
345
  * @since 4.0.0
336
346
  */
337
347
  cancelDelay(): Promise<void>;
338
348
  /**
339
349
  * Get Latest bundle available from update Url
340
350
  *
341
- * @returns {Promise<latestVersion>} an Promise resolved when url is loaded
342
- * @throws An error if the something went wrong
351
+ * @returns {Promise<LatestVersion>} A Promise resolved when url is loaded
352
+ * @throws {Error}
343
353
  * @since 4.0.0
344
354
  */
345
- getLatest(): Promise<latestVersion>;
355
+ getLatest(options?: GetLatestOptions): Promise<LatestVersion>;
346
356
  /**
347
- * Set Channel for this device
357
+ * Sets the channel for this device. The channel has to allow for self assignment for this to work.
358
+ * Do not use this method to set the channel at boot when `autoUpdate` is enabled in the {@link PluginsConfig}.
359
+ * This method is to set the channel after the app is ready.
360
+ * This methods send to Capgo backend a request to link the device ID to the channel. Capgo can accept or refuse depending of the setting of your channel.
361
+ *
362
+ *
348
363
  *
349
- * @returns {Promise<channelRes>} an Promise resolved when channel is set
350
- * @param options is the {@link SetChannelOptions} channel to set
351
- * @throws An error if the something went wrong
364
+ * @param options Is the {@link SetChannelOptions} channel to set
365
+ * @returns {Promise<ChannelRes>} A Promise which is resolved when the new channel is set
366
+ * @throws {Error}
352
367
  * @since 4.7.0
353
368
  */
354
- setChannel(options: SetChannelOptions): Promise<channelRes>;
369
+ setChannel(options: SetChannelOptions): Promise<ChannelRes>;
355
370
  /**
356
- * get Channel for this device
371
+ * Unset the channel for this device. The device will then return to the default channel
357
372
  *
358
- * @returns {Promise<channelRes>} an Promise resolved with channel info
359
- * @throws An error if the something went wrong
373
+ * @returns {Promise<ChannelRes>} A Promise resolved when channel is set
374
+ * @throws {Error}
375
+ * @since 4.7.0
376
+ */
377
+ unsetChannel(options: UnsetChannelOptions): Promise<void>;
378
+ /**
379
+ * Get the channel for this device
380
+ *
381
+ * @returns {Promise<ChannelRes>} A Promise that resolves with the channel info
382
+ * @throws {Error}
360
383
  * @since 4.8.0
361
384
  */
362
- getChannel(): Promise<getChannelRes>;
385
+ getChannel(): Promise<GetChannelRes>;
363
386
  /**
364
- * Set Channel for this device
387
+ * Set a custom ID for this device
365
388
  *
366
- * @returns {Promise<void>} an Promise resolved instantly
367
389
  * @param options is the {@link SetCustomIdOptions} customId to set
368
- * @throws An error if the something went wrong
390
+ * @returns {Promise<void>} an Promise resolved instantly
391
+ * @throws {Error}
369
392
  * @since 4.9.0
370
393
  */
371
394
  setCustomId(options: SetCustomIdOptions): Promise<void>;
372
395
  /**
373
- * Listen for download event in the App, let you know when the download is started, loading and finished
396
+ * Get the native app version or the builtin version if set in config
397
+ *
398
+ * @returns {Promise<BuiltinVersion>} A Promise with version for this device
399
+ * @since 5.2.0
400
+ */
401
+ getBuiltinVersion(): Promise<BuiltinVersion>;
402
+ /**
403
+ * Get unique ID used to identify device (sent to auto update server)
404
+ *
405
+ * @returns {Promise<DeviceId>} A Promise with id for this device
406
+ * @throws {Error}
407
+ */
408
+ getDeviceId(): Promise<DeviceId>;
409
+ /**
410
+ * Get the native Capacitor Updater plugin version (sent to auto update server)
411
+ *
412
+ * @returns {Promise<PluginVersion>} A Promise with Plugin version
413
+ * @throws {Error}
414
+ */
415
+ getPluginVersion(): Promise<PluginVersion>;
416
+ /**
417
+ * Get the state of auto update config.
418
+ *
419
+ * @returns {Promise<AutoUpdateEnabled>} The status for auto update. Evaluates to `false` in manual mode.
420
+ * @throws {Error}
421
+ */
422
+ isAutoUpdateEnabled(): Promise<AutoUpdateEnabled>;
423
+ /**
424
+ * Remove all listeners for this plugin.
425
+ *
426
+ * @since 1.0.0
427
+ */
428
+ removeAllListeners(): Promise<void>;
429
+ /**
430
+ * Listen for bundle download event in the App. Fires once a download has started, during downloading and when finished.
374
431
  *
375
432
  * @since 2.0.11
376
433
  */
377
- addListener(eventName: "download", listenerFunc: DownloadChangeListener): Promise<PluginListenerHandle> & PluginListenerHandle;
434
+ addListener(eventName: 'download', listenerFunc: (state: DownloadEvent) => void): Promise<PluginListenerHandle>;
378
435
  /**
379
- * Listen for no need to update event, usefull when you want force check every time the app is launched
436
+ * Listen for no need to update event, useful when you want force check every time the app is launched
380
437
  *
381
438
  * @since 4.0.0
382
439
  */
383
- addListener(eventName: "noNeedUpdate", listenerFunc: NoNeedListener): Promise<PluginListenerHandle> & PluginListenerHandle;
440
+ addListener(eventName: 'noNeedUpdate', listenerFunc: (state: NoNeedEvent) => void): Promise<PluginListenerHandle>;
384
441
  /**
385
- * Listen for availbale update event, usefull when you want to force check every time the app is launched
442
+ * Listen for available update event, useful when you want to force check every time the app is launched
386
443
  *
387
444
  * @since 4.0.0
388
445
  */
389
- addListener(eventName: "updateAvailable", listenerFunc: UpdateAvailabledListener): Promise<PluginListenerHandle> & PluginListenerHandle;
446
+ addListener(eventName: 'updateAvailable', listenerFunc: (state: UpdateAvailableEvent) => void): Promise<PluginListenerHandle>;
390
447
  /**
391
- * Listen for download event in the App, let you know when the download is started, loading and finished
448
+ * Listen for downloadComplete events.
392
449
  *
393
450
  * @since 4.0.0
394
451
  */
395
- addListener(eventName: "downloadComplete", listenerFunc: DownloadCompleteListener): Promise<PluginListenerHandle> & PluginListenerHandle;
452
+ addListener(eventName: 'downloadComplete', listenerFunc: (state: DownloadCompleteEvent) => void): Promise<PluginListenerHandle>;
396
453
  /**
397
454
  * Listen for Major update event in the App, let you know when major update is blocked by setting disableAutoUpdateBreaking
398
455
  *
399
456
  * @since 2.3.0
400
457
  */
401
- addListener(eventName: "majorAvailable", listenerFunc: MajorAvailableListener): Promise<PluginListenerHandle> & PluginListenerHandle;
458
+ addListener(eventName: 'majorAvailable', listenerFunc: (state: MajorAvailableEvent) => void): Promise<PluginListenerHandle>;
402
459
  /**
403
460
  * Listen for update fail event in the App, let you know when update has fail to install at next app start
404
461
  *
405
462
  * @since 2.3.0
406
463
  */
407
- addListener(eventName: "updateFailed", listenerFunc: UpdateFailedListener): Promise<PluginListenerHandle> & PluginListenerHandle;
464
+ addListener(eventName: 'updateFailed', listenerFunc: (state: UpdateFailedEvent) => void): Promise<PluginListenerHandle>;
408
465
  /**
409
- * Listen for download fail event in the App, let you know when download has fail finished
466
+ * Listen for download fail event in the App, let you know when a bundle download has failed
410
467
  *
411
468
  * @since 4.0.0
412
469
  */
413
- addListener(eventName: "downloadFailed", listenerFunc: DownloadFailedListener): Promise<PluginListenerHandle> & PluginListenerHandle;
470
+ addListener(eventName: 'downloadFailed', listenerFunc: (state: DownloadFailedEvent) => void): Promise<PluginListenerHandle>;
414
471
  /**
415
- * Listen for download fail event in the App, let you know when download has fail finished
472
+ * Listen for reload event in the App, let you know when reload has happened
416
473
  *
417
474
  * @since 4.3.0
418
475
  */
419
- addListener(eventName: "appReloaded", listenerFunc: AppReloadedListener): Promise<PluginListenerHandle> & PluginListenerHandle;
476
+ addListener(eventName: 'appReloaded', listenerFunc: () => void): Promise<PluginListenerHandle>;
420
477
  /**
421
- * Get unique ID used to identify device (sent to auto update server)
478
+ * Listen for app ready event in the App, let you know when app is ready to use
422
479
  *
423
- * @returns {Promise<{ deviceId: string }>} an Promise with id for this device
424
- * @throws An error if the something went wrong
480
+ * @since 5.1.0
425
481
  */
426
- getDeviceId(): Promise<{
427
- deviceId: string;
428
- }>;
482
+ addListener(eventName: 'appReady', listenerFunc: (state: AppReadyEvent) => void): Promise<PluginListenerHandle>;
429
483
  /**
430
- * Get the native Capacitor Updater plugin version (sent to auto update server)
484
+ * Get if auto update is available (not disabled by serverUrl).
431
485
  *
432
- * @returns {Promise<{ id: string }>} an Promise with version for this device
433
- * @throws An error if the something went wrong
486
+ * @returns {Promise<AutoUpdateAvailable>} The availability status for auto update. Evaluates to `false` when serverUrl is set.
487
+ * @throws {Error}
434
488
  */
435
- getPluginVersion(): Promise<{
436
- version: string;
437
- }>;
489
+ isAutoUpdateAvailable(): Promise<AutoUpdateAvailable>;
438
490
  /**
439
- * Get the state of auto update config. This will return `false` in manual mode.
491
+ * Get the next bundle that will be used when the app reloads.
492
+ * Returns null if no next bundle is set.
440
493
  *
441
- * @returns {Promise<{enabled: boolean}>} The status for auto update.
442
- * @throws An error if the something went wrong
494
+ * @returns {Promise<BundleInfo | null>} A Promise that resolves with the next bundle information or null
495
+ * @throws {Error}
496
+ * @since 6.8.0
443
497
  */
444
- isAutoUpdateEnabled(): Promise<{
445
- enabled: boolean;
446
- }>;
498
+ getNextBundle(): Promise<BundleInfo | null>;
499
+ }
500
+ export type BundleStatus = 'success' | 'error' | 'pending' | 'downloading';
501
+ export type DelayUntilNext = 'background' | 'kill' | 'nativeVersion' | 'date';
502
+ export interface NoNeedEvent {
447
503
  /**
448
- * Remove all listeners for this plugin.
504
+ * Current status of download, between 0 and 100.
449
505
  *
450
- * @since 1.0.0
506
+ * @since 4.0.0
451
507
  */
452
- removeAllListeners(): Promise<void>;
508
+ bundle: BundleInfo;
509
+ }
510
+ export interface UpdateAvailableEvent {
511
+ /**
512
+ * Current status of download, between 0 and 100.
513
+ *
514
+ * @since 4.0.0
515
+ */
516
+ bundle: BundleInfo;
517
+ }
518
+ export interface ChannelRes {
519
+ /**
520
+ * Current status of set channel
521
+ *
522
+ * @since 4.7.0
523
+ */
524
+ status: string;
525
+ error?: string;
526
+ message?: string;
527
+ }
528
+ export interface GetChannelRes {
529
+ /**
530
+ * Current status of get channel
531
+ *
532
+ * @since 4.8.0
533
+ */
534
+ channel?: string;
535
+ error?: string;
536
+ message?: string;
537
+ status?: string;
538
+ allowSet?: boolean;
539
+ }
540
+ export interface DownloadEvent {
541
+ /**
542
+ * Current status of download, between 0 and 100.
543
+ *
544
+ * @since 4.0.0
545
+ */
546
+ percent: number;
547
+ bundle: BundleInfo;
548
+ }
549
+ export interface MajorAvailableEvent {
550
+ /**
551
+ * Emit when a new major bundle is available.
552
+ *
553
+ * @since 4.0.0
554
+ */
555
+ version: string;
556
+ }
557
+ export interface DownloadFailedEvent {
558
+ /**
559
+ * Emit when a download fail.
560
+ *
561
+ * @since 4.0.0
562
+ */
563
+ version: string;
564
+ }
565
+ export interface DownloadCompleteEvent {
566
+ /**
567
+ * Emit when a new update is available.
568
+ *
569
+ * @since 4.0.0
570
+ */
571
+ bundle: BundleInfo;
572
+ }
573
+ export interface UpdateFailedEvent {
574
+ /**
575
+ * Emit when a update failed to install.
576
+ *
577
+ * @since 4.0.0
578
+ */
579
+ bundle: BundleInfo;
580
+ }
581
+ export interface AppReadyEvent {
582
+ /**
583
+ * Emitted when the app is ready to use.
584
+ *
585
+ * @since 5.2.0
586
+ */
587
+ bundle: BundleInfo;
588
+ status: string;
589
+ }
590
+ export interface ManifestEntry {
591
+ file_name: string | null;
592
+ file_hash: string | null;
593
+ download_url: string | null;
594
+ }
595
+ export interface LatestVersion {
596
+ /**
597
+ * Result of getLatest method
598
+ *
599
+ * @since 4.0.0
600
+ */
601
+ version: string;
602
+ /**
603
+ * @since 6
604
+ */
605
+ checksum?: string;
606
+ major?: boolean;
607
+ message?: string;
608
+ sessionKey?: string;
609
+ error?: string;
610
+ old?: string;
611
+ url?: string;
612
+ /**
613
+ * @since 6.1
614
+ */
615
+ manifest?: ManifestEntry[];
616
+ }
617
+ export interface BundleInfo {
618
+ id: string;
619
+ version: string;
620
+ downloaded: string;
621
+ checksum: string;
622
+ status: BundleStatus;
623
+ }
624
+ export interface SetChannelOptions {
625
+ channel: string;
626
+ triggerAutoUpdate?: boolean;
627
+ }
628
+ export interface UnsetChannelOptions {
629
+ triggerAutoUpdate?: boolean;
630
+ }
631
+ export interface SetCustomIdOptions {
632
+ customId: string;
633
+ }
634
+ export interface DelayCondition {
635
+ /**
636
+ * Set up delay conditions in setMultiDelay
637
+ * @param value is useless for @param kind "kill", optional for "background" (default value: "0") and required for "nativeVersion" and "date"
638
+ */
639
+ kind: DelayUntilNext;
640
+ value?: string;
641
+ }
642
+ export interface GetLatestOptions {
643
+ /**
644
+ * The channel to get the latest version for
645
+ * The channel must allow 'self_assign' for this to work
646
+ * @since 6.8.0
647
+ * @default undefined
648
+ */
649
+ channel?: string;
650
+ }
651
+ export interface AppReadyResult {
652
+ bundle: BundleInfo;
653
+ }
654
+ export interface UpdateUrl {
655
+ url: string;
656
+ }
657
+ export interface StatsUrl {
658
+ url: string;
659
+ }
660
+ export interface ChannelUrl {
661
+ url: string;
662
+ }
663
+ export interface DownloadOptions {
664
+ /**
665
+ * The URL of the bundle zip file (e.g: dist.zip) to be downloaded. (This can be any URL. E.g: Amazon S3, a GitHub tag, any other place you've hosted your bundle.)
666
+ */
667
+ url?: string;
668
+ /**
669
+ * The version code/name of this bundle/version
670
+ */
671
+ version: string;
672
+ /**
673
+ * The session key for the update
674
+ * @since 4.0.0
675
+ * @default undefined
676
+ */
677
+ sessionKey?: string;
678
+ /**
679
+ * The checksum for the update
680
+ * @since 4.0.0
681
+ * @default undefined
682
+ */
683
+ checksum?: string;
684
+ }
685
+ export interface BundleId {
686
+ id: string;
687
+ }
688
+ export interface BundleListResult {
689
+ bundles: BundleInfo[];
690
+ }
691
+ export interface ResetOptions {
692
+ toLastSuccessful: boolean;
693
+ }
694
+ export interface ListOptions {
695
+ /**
696
+ * Whether to return the raw bundle list or the manifest. If true, the list will attempt to read the internal database instead of files on disk.
697
+ * @since 6.14.0
698
+ * @default false
699
+ */
700
+ raw?: boolean;
701
+ }
702
+ export interface CurrentBundleResult {
703
+ bundle: BundleInfo;
704
+ native: string;
705
+ }
706
+ export interface MultiDelayConditions {
707
+ delayConditions: DelayCondition[];
708
+ }
709
+ export interface BuiltinVersion {
710
+ version: string;
711
+ }
712
+ export interface DeviceId {
713
+ deviceId: string;
714
+ }
715
+ export interface PluginVersion {
716
+ version: string;
717
+ }
718
+ export interface AutoUpdateEnabled {
719
+ enabled: boolean;
720
+ }
721
+ export interface AutoUpdateAvailable {
722
+ available: boolean;
453
723
  }