UNPKG

14.6 kBTypeScriptView Raw
1import { Observable } from 'rxjs/Observable';
2/**
3 * Defines a package. All fields are non-nullable, except when retrieving the currently running package on the first run of the app,
4 * in which case only the appVersion is compulsory.
5 *
6 * !! THIS TYPE IS READ FROM NATIVE CODE AS WELL. ANY CHANGES TO THIS INTERFACE NEEDS TO BE UPDATED IN NATIVE CODE !!
7 */
8export interface IPackage {
9 deploymentKey: string;
10 description: string;
11 label: string;
12 appVersion: string;
13 isMandatory: boolean;
14 packageHash: string;
15 packageSize: number;
16 failedInstall: boolean;
17}
18/**
19 * Defines a remote package, which represents an update package available for download.
20 */
21export interface IRemotePackage extends IPackage {
22 /**
23 * The URL at which the package is available for download.
24 */
25 downloadUrl: string;
26 /**
27 * Downloads the package update from the CodePush service.
28 *
29 * @param downloadSuccess Called with one parameter, the downloaded package information, once the download completed successfully.
30 * @param downloadError Optional callback invoked in case of an error.
31 * @param downloadProgress Optional callback invoked during the download process. It is called several times with one DownloadProgress parameter.
32 */
33 download(downloadSuccess: SuccessCallback<ILocalPackage>, downloadError?: ErrorCallback, downloadProgress?: SuccessCallback<DownloadProgress>): void;
34 /**
35 * Aborts the current download session, previously started with download().
36 *
37 * @param abortSuccess Optional callback invoked if the abort operation succeeded.
38 * @param abortError Optional callback invoked in case of an error.
39 */
40 abortDownload(abortSuccess?: SuccessCallback<void>, abortError?: ErrorCallback): void;
41}
42/**
43 * Defines a local package.
44 *
45 * !! THIS TYPE IS READ FROM NATIVE CODE AS WELL. ANY CHANGES TO THIS INTERFACE NEEDS TO BE UPDATED IN NATIVE CODE !!
46 */
47export interface ILocalPackage extends IPackage {
48 /**
49 * The local storage path where this package is located.
50 */
51 localPath: string;
52 /**
53 * Indicates if the current application run is the first one after the package was applied.
54 */
55 isFirstRun: boolean;
56 /**
57 * Applies this package to the application. The application will be reloaded with this package and on every application launch this package will be loaded.
58 * On the first run after the update, the application will wait for a codePush.notifyApplicationReady() call. Once this call is made, the install operation is considered a success.
59 * Otherwise, the install operation will be marked as failed, and the application is reverted to its previous version on the next run.
60 *
61 * @param installSuccess Callback invoked if the install operation succeeded.
62 * @param installError Optional callback inovoked in case of an error.
63 * @param installOptions Optional parameter used for customizing the installation behavior.
64 */
65 install(installSuccess: SuccessCallback<InstallMode>, errorCallback?: ErrorCallback, installOptions?: InstallOptions): void;
66}
67export interface Callback<T> {
68 (error: Error, parameter: T): void;
69}
70export interface SuccessCallback<T> {
71 (result?: T): void;
72}
73export interface ErrorCallback {
74 (error?: Error): void;
75}
76/**
77 * Defines the possible result statuses of the window.codePush.sync operation.
78 */
79export declare enum SyncStatus {
80 /**
81 * The application is up to date.
82 */
83 UP_TO_DATE = 0,
84 /**
85 * An update is available, it has been downloaded, unzipped and copied to the deployment folder.
86 * After the completion of the callback invoked with SyncStatus.UPDATE_INSTALLED, the application will be reloaded with the updated code and resources.
87 */
88 UPDATE_INSTALLED = 1,
89 /**
90 * An optional update is available, but the user declined to install it. The update was not downloaded.
91 */
92 UPDATE_IGNORED = 2,
93 /**
94 * An error happened during the sync operation. This might be an error while communicating with the server, downloading or unziping the update.
95 * The console logs should contain more information about what happened. No update has been applied in this case.
96 */
97 ERROR = 3,
98 /**
99 * There is an ongoing sync in progress, so this attempt to sync has been aborted.
100 */
101 IN_PROGRESS = 4,
102 /**
103 * Intermediate status - the plugin is about to check for updates.
104 */
105 CHECKING_FOR_UPDATE = 5,
106 /**
107 * Intermediate status - a user dialog is about to be displayed. This status will be reported only if user interaction is enabled.
108 */
109 AWAITING_USER_ACTION = 6,
110 /**
111 * Intermediate status - the update package is about to be downloaded.
112 */
113 DOWNLOADING_PACKAGE = 7,
114 /**
115 * Intermediate status - the update package is about to be installed.
116 */
117 INSTALLING_UPDATE = 8,
118}
119/**
120 * Defines the available install modes for updates.
121 */
122export declare enum InstallMode {
123 /**
124 * The update will be applied to the running application immediately. The application will be reloaded with the new content immediately.
125 */
126 IMMEDIATE = 0,
127 /**
128 * The update is downloaded but not installed immediately. The new content will be available the next time the application is started.
129 */
130 ON_NEXT_RESTART = 1,
131 /**
132 * The udpate is downloaded but not installed immediately. The new content will be available the next time the application is resumed or restarted, whichever event happends first.
133 */
134 ON_NEXT_RESUME = 2,
135}
136/**
137 * Defines the install operation options.
138 */
139export interface InstallOptions {
140 /**
141 * Used to specify the InstallMode used for the install operation. This is optional and defaults to InstallMode.ON_NEXT_RESTART.
142 */
143 installMode?: InstallMode;
144 /**
145 * If installMode === ON_NEXT_RESUME, the minimum amount of time (in seconds) which needs to pass with the app in the background before an update install occurs when the app is resumed.
146 */
147 minimumBackgroundDuration?: number;
148 /**
149 * Used to specify the InstallMode used for the install operation if the update is mandatory. This is optional and defaults to InstallMode.IMMEDIATE.
150 */
151 mandatoryInstallMode?: InstallMode;
152}
153/**
154 * Defines the sync operation options.
155 */
156export interface SyncOptions extends InstallOptions {
157 /**
158 * Optional boolean flag. If set, previous updates which were rolled back will be ignored. Defaults to true.
159 */
160 ignoreFailedUpdates?: boolean;
161 /**
162 * Used to enable, disable or customize the user interaction during sync.
163 * If set to false, user interaction will be disabled. If set to true, the user will be alerted or asked to confirm new updates, based on whether the update is mandatory.
164 * To customize the user dialog, this option can be set to a custom UpdateDialogOptions instance.
165 */
166 updateDialog?: boolean | UpdateDialogOptions;
167 /**
168 * Overrides the config.xml deployment key when checking for updates.
169 */
170 deploymentKey?: string;
171}
172/**
173 * Defines the configuration options for the alert or confirmation dialog
174 */
175export interface UpdateDialogOptions {
176 /**
177 * If a mandatory update is available and this option is set, the message will be displayed to the user in an alert dialog before downloading and installing the update.
178 * The user will not be able to cancel the operation, since the update is mandatory.
179 */
180 mandatoryUpdateMessage?: string;
181 /**
182 * If an optional update is available and this option is set, the message will be displayed to the user in a confirmation dialog.
183 * If the user confirms the update, it will be downloaded and installed. Otherwise, the update update is not downloaded.
184 */
185 optionalUpdateMessage?: string;
186 /**
187 * The title of the dialog box used for interacting with the user in case of a mandatory or optional update.
188 * This title will only be used if at least one of mandatoryUpdateMessage or optionalUpdateMessage options are set.
189 */
190 updateTitle?: string;
191 /**
192 * The label of the confirmation button in case of an optional update.
193 */
194 optionalInstallButtonLabel?: string;
195 /**
196 * The label of the cancel button in case of an optional update.
197 */
198 optionalIgnoreButtonLabel?: string;
199 /**
200 * The label of the continue button in case of a mandatory update.
201 */
202 mandatoryContinueButtonLabel?: string;
203 /**
204 * Flag indicating if the update description provided by the CodePush server should be displayed in the dialog box appended to the update message.
205 */
206 appendReleaseDescription?: boolean;
207 /**
208 * Optional prefix to add to the release description.
209 */
210 descriptionPrefix?: string;
211}
212/**
213 * Defines the format of the DownloadProgress object, used to send periodical update notifications on the progress of the update download.
214 */
215export interface DownloadProgress {
216 totalBytes: number;
217 receivedBytes: number;
218}
219/**
220 * @name CodePush
221 * @description
222 * CodePush plugin for Cordova by Microsoft that supports iOS and Android.
223 *
224 * For more info, please see https://github.com/ksachdeva/ionic2-code-push-example
225 *
226 * @usage
227 * ```typescript
228 * import { CodePush } from 'ionic-native';
229 *
230 * // note - mostly error & completed methods of observable will not fire
231 * // as syncStatus will contain the current state of the update
232 * CodePush.sync().subscribe((syncStatus) => console.log(syncStatus));
233 *
234 * const downloadProgress = (progress) => { console.log(`Downloaded ${progress.receivedBytes} of ${progress.totalBytes}`); }
235 * CodePush.sync({}, downloadProgress).subscribe((syncStatus) => console.log(syncStatus));
236 *
237 * ```
238 */
239export declare class CodePush {
240 /**
241 * Get the current package information.
242 *
243 * @param packageSuccess Callback invoked with the currently deployed package information.
244 * @param packageError Optional callback invoked in case of an error.
245 * @returns {Promise<ILocalPackage>}
246 */
247 static getCurrentPackage(): Promise<ILocalPackage>;
248 /**
249 * Gets the pending package information, if any. A pending package is one that has been installed but the application still runs the old code.
250 * This happends only after a package has been installed using ON_NEXT_RESTART or ON_NEXT_RESUME mode, but the application was not restarted/resumed yet.
251 * @returns {Promise<ILocalPackage>}
252 */
253 static getPendingPackage(): Promise<ILocalPackage>;
254 /**
255 * Checks with the CodePush server if an update package is available for download.
256 *
257 * @param querySuccess Callback invoked in case of a successful response from the server.
258 * The callback takes one RemotePackage parameter. A non-null package is a valid update.
259 * A null package means the application is up to date for the current native application version.
260 * @param queryError Optional callback invoked in case of an error.
261 * @param deploymentKey Optional deployment key that overrides the config.xml setting.
262 * @returns {Promise<IRemotePackage>}
263 */
264 static checkForUpdate(deploymentKey?: string): Promise<IRemotePackage>;
265 /**
266 * Notifies the plugin that the update operation succeeded and that the application is ready.
267 * Calling this function is required on the first run after an update. On every subsequent application run, calling this function is a noop.
268 * If using sync API, calling this function is not required since sync calls it internally.
269 *
270 * @param notifySucceeded Optional callback invoked if the plugin was successfully notified.
271 * @param notifyFailed Optional callback invoked in case of an error during notifying the plugin.
272 * @returns {Promise<void>}
273 */
274 static notifyApplicationReady(): Promise<void>;
275 /**
276 * Reloads the application. If there is a pending update package installed using ON_NEXT_RESTART or ON_NEXT_RESUME modes, the update
277 * will be immediately visible to the user. Otherwise, calling this function will simply reload the current version of the application.
278 * @returns {Promise<void>}
279 */
280 static restartApplication(): Promise<void>;
281 /**
282 * Convenience method for installing updates in one method call.
283 * This method is provided for simplicity, and its behavior can be replicated by using window.codePush.checkForUpdate(), RemotePackage's download() and LocalPackage's install() methods.
284 *
285 * The algorithm of this method is the following:
286 * - Checks for an update on the CodePush server.
287 * - If an update is available
288 * - If the update is mandatory and the alertMessage is set in options, the user will be informed that the application will be updated to the latest version.
289 * The update package will then be downloaded and applied.
290 * - If the update is not mandatory and the confirmMessage is set in options, the user will be asked if they want to update to the latest version.
291 * If they decline, the syncCallback will be invoked with SyncStatus.UPDATE_IGNORED.
292 * - Otherwise, the update package will be downloaded and applied with no user interaction.
293 * - If no update is available on the server, or if a previously rolled back update is available and the ignoreFailedUpdates is set to true, the syncCallback will be invoked with the SyncStatus.UP_TO_DATE.
294 * - If an error occurs during checking for update, downloading or installing it, the syncCallback will be invoked with the SyncStatus.ERROR.
295 *
296 * @param syncCallback Optional callback to be called with the status of the sync operation.
297 * @param syncOptions Optional SyncOptions parameter configuring the behavior of the sync operation.
298 * @param downloadProgress Optional callback invoked during the download process. It is called several times with one DownloadProgress parameter.
299 * @returns {Observable<SyncStatus>}
300 *
301 */
302 static sync(syncOptions?: SyncOptions, downloadProgress?: SuccessCallback<DownloadProgress>): Observable<SyncStatus>;
303}