@angular/service-worker 14.0.0-next.9 → 14.0.0-rc.2

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.
@@ -1,469 +1,470 @@
1
1
  /**
2
- * @license Angular v14.0.0-next.9
2
+ * @license Angular v14.0.0-rc.2
3
3
  * (c) 2010-2022 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
6
6
 
7
- import * as i0 from '@angular/core';
8
- import { ModuleWithProviders } from '@angular/core';
9
- import { Observable } from 'rxjs';
10
-
11
- /**
12
- * @publicApi
13
- */
14
- declare class NgswCommChannel {
15
- private serviceWorker;
16
- readonly worker: Observable<ServiceWorker>;
17
- readonly registration: Observable<ServiceWorkerRegistration>;
18
- readonly events: Observable<TypedEvent>;
19
- constructor(serviceWorker: ServiceWorkerContainer | undefined);
20
- postMessage(action: string, payload: Object): Promise<void>;
21
- postMessageWithOperation(type: string, payload: Object, operationNonce: number): Promise<boolean>;
22
- generateNonce(): number;
23
- eventsOfType<T extends TypedEvent>(type: T['type'] | T['type'][]): Observable<T>;
24
- nextEventOfType<T extends TypedEvent>(type: T['type']): Observable<T>;
25
- waitForOperationCompleted(nonce: number): Promise<boolean>;
26
- get isEnabled(): boolean;
27
- }
28
-
29
- /**
30
- * An event emitted when the service worker has checked the version of the app on the server and it
31
- * didn't find a new version that it doesn't have already downloaded.
32
- *
33
- * @see {@link guide/service-worker-communications Service worker communication guide}
34
- *
35
- * @publicApi
36
- */
37
- declare interface NoNewVersionDetectedEvent {
38
- type: 'NO_NEW_VERSION_DETECTED';
39
- version: {
40
- hash: string;
41
- appData?: Object;
42
- };
43
- }
44
-
45
- /**
46
- * @publicApi
47
- */
48
- export declare class ServiceWorkerModule {
49
- /**
50
- * Register the given Angular Service Worker script.
51
- *
52
- * If `enabled` is set to `false` in the given options, the module will behave as if service
53
- * workers are not supported by the browser, and the service worker will not be registered.
54
- */
55
- static register(script: string, opts?: SwRegistrationOptions): ModuleWithProviders<ServiceWorkerModule>;
56
- static ɵfac: i0.ɵɵFactoryDeclaration<ServiceWorkerModule, never>;
57
- static ɵmod: i0.ɵɵNgModuleDeclaration<ServiceWorkerModule, never, never, never>;
58
- static ɵinj: i0.ɵɵInjectorDeclaration<ServiceWorkerModule>;
59
- }
60
-
61
- /**
62
- * Subscribe and listen to
63
- * [Web Push
64
- * Notifications](https://developer.mozilla.org/en-US/docs/Web/API/Push_API/Best_Practices) through
65
- * Angular Service Worker.
66
- *
67
- * @usageNotes
68
- *
69
- * You can inject a `SwPush` instance into any component or service
70
- * as a dependency.
71
- *
72
- * <code-example path="service-worker/push/module.ts" region="inject-sw-push"
73
- * header="app.component.ts"></code-example>
74
- *
75
- * To subscribe, call `SwPush.requestSubscription()`, which asks the user for permission.
76
- * The call returns a `Promise` with a new
77
- * [`PushSubscription`](https://developer.mozilla.org/en-US/docs/Web/API/PushSubscription)
78
- * instance.
79
- *
80
- * <code-example path="service-worker/push/module.ts" region="subscribe-to-push"
81
- * header="app.component.ts"></code-example>
82
- *
83
- * A request is rejected if the user denies permission, or if the browser
84
- * blocks or does not support the Push API or ServiceWorkers.
85
- * Check `SwPush.isEnabled` to confirm status.
86
- *
87
- * Invoke Push Notifications by pushing a message with the following payload.
88
- *
89
- * ```ts
90
- * {
91
- * "notification": {
92
- * "actions": NotificationAction[],
93
- * "badge": USVString,
94
- * "body": DOMString,
95
- * "data": any,
96
- * "dir": "auto"|"ltr"|"rtl",
97
- * "icon": USVString,
98
- * "image": USVString,
99
- * "lang": DOMString,
100
- * "renotify": boolean,
101
- * "requireInteraction": boolean,
102
- * "silent": boolean,
103
- * "tag": DOMString,
104
- * "timestamp": DOMTimeStamp,
105
- * "title": DOMString,
106
- * "vibrate": number[]
107
- * }
108
- * }
109
- * ```
110
- *
111
- * Only `title` is required. See `Notification`
112
- * [instance
113
- * properties](https://developer.mozilla.org/en-US/docs/Web/API/Notification#Instance_properties).
114
- *
115
- * While the subscription is active, Service Worker listens for
116
- * [PushEvent](https://developer.mozilla.org/en-US/docs/Web/API/PushEvent)
117
- * occurrences and creates
118
- * [Notification](https://developer.mozilla.org/en-US/docs/Web/API/Notification)
119
- * instances in response.
120
- *
121
- * Unsubscribe using `SwPush.unsubscribe()`.
122
- *
123
- * An application can subscribe to `SwPush.notificationClicks` observable to be notified when a user
124
- * clicks on a notification. For example:
125
- *
126
- * <code-example path="service-worker/push/module.ts" region="subscribe-to-notification-clicks"
127
- * header="app.component.ts"></code-example>
128
- *
129
- * You can read more on handling notification clicks in the [Service worker notifications
130
- * guide](guide/service-worker-notifications).
131
- *
132
- * @see [Push Notifications](https://developers.google.com/web/fundamentals/codelabs/push-notifications/)
133
- * @see [Angular Push Notifications](https://blog.angular-university.io/angular-push-notifications/)
134
- * @see [MDN: Push API](https://developer.mozilla.org/en-US/docs/Web/API/Push_API)
135
- * @see [MDN: Notifications API](https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API)
136
- * @see [MDN: Web Push API Notifications best practices](https://developer.mozilla.org/en-US/docs/Web/API/Push_API/Best_Practices)
137
- *
138
- * @publicApi
139
- */
140
- export declare class SwPush {
141
- private sw;
142
- /**
143
- * Emits the payloads of the received push notification messages.
144
- */
145
- readonly messages: Observable<object>;
146
- /**
147
- * Emits the payloads of the received push notification messages as well as the action the user
148
- * interacted with. If no action was used the `action` property contains an empty string `''`.
149
- *
150
- * Note that the `notification` property does **not** contain a
151
- * [Notification][Mozilla Notification] object but rather a
152
- * [NotificationOptions](https://notifications.spec.whatwg.org/#dictdef-notificationoptions)
153
- * object that also includes the `title` of the [Notification][Mozilla Notification] object.
154
- *
155
- * [Mozilla Notification]: https://developer.mozilla.org/en-US/docs/Web/API/Notification
156
- */
157
- readonly notificationClicks: Observable<{
158
- action: string;
159
- notification: NotificationOptions & {
160
- title: string;
161
- };
162
- }>;
163
- /**
164
- * Emits the currently active
165
- * [PushSubscription](https://developer.mozilla.org/en-US/docs/Web/API/PushSubscription)
166
- * associated to the Service Worker registration or `null` if there is no subscription.
167
- */
168
- readonly subscription: Observable<PushSubscription | null>;
169
- /**
170
- * True if the Service Worker is enabled (supported by the browser and enabled via
171
- * `ServiceWorkerModule`).
172
- */
173
- get isEnabled(): boolean;
174
- private pushManager;
175
- private subscriptionChanges;
176
- constructor(sw: NgswCommChannel);
177
- /**
178
- * Subscribes to Web Push Notifications,
179
- * after requesting and receiving user permission.
180
- *
181
- * @param options An object containing the `serverPublicKey` string.
182
- * @returns A Promise that resolves to the new subscription object.
183
- */
184
- requestSubscription(options: {
185
- serverPublicKey: string;
186
- }): Promise<PushSubscription>;
187
- /**
188
- * Unsubscribes from Service Worker push notifications.
189
- *
190
- * @returns A Promise that is resolved when the operation succeeds, or is rejected if there is no
191
- * active subscription or the unsubscribe operation fails.
192
- */
193
- unsubscribe(): Promise<void>;
194
- private decodeBase64;
195
- static ɵfac: i0.ɵɵFactoryDeclaration<SwPush, never>;
196
- static ɵprov: i0.ɵɵInjectableDeclaration<SwPush>;
197
- }
198
-
199
- /**
200
- * Token that can be used to provide options for `ServiceWorkerModule` outside of
201
- * `ServiceWorkerModule.register()`.
202
- *
203
- * You can use this token to define a provider that generates the registration options at runtime,
204
- * for example via a function call:
205
- *
206
- * {@example service-worker/registration-options/module.ts region="registration-options"
207
- * header="app.module.ts"}
208
- *
209
- * @publicApi
210
- */
211
- export declare abstract class SwRegistrationOptions {
212
- /**
213
- * Whether the ServiceWorker will be registered and the related services (such as `SwPush` and
214
- * `SwUpdate`) will attempt to communicate and interact with it.
215
- *
216
- * Default: true
217
- */
218
- enabled?: boolean;
219
- /**
220
- * A URL that defines the ServiceWorker's registration scope; that is, what range of URLs it can
221
- * control. It will be used when calling
222
- * [ServiceWorkerContainer#register()](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register).
223
- */
224
- scope?: string;
225
- /**
226
- * Defines the ServiceWorker registration strategy, which determines when it will be registered
227
- * with the browser.
228
- *
229
- * The default behavior of registering once the application stabilizes (i.e. as soon as there are
230
- * no pending micro- and macro-tasks) is designed to register the ServiceWorker as soon as
231
- * possible but without affecting the application's first time load.
232
- *
233
- * Still, there might be cases where you want more control over when the ServiceWorker is
234
- * registered (for example, there might be a long-running timeout or polling interval, preventing
235
- * the app from stabilizing). The available option are:
236
- *
237
- * - `registerWhenStable:<timeout>`: Register as soon as the application stabilizes (no pending
238
- * micro-/macro-tasks) but no later than `<timeout>` milliseconds. If the app hasn't
239
- * stabilized after `<timeout>` milliseconds (for example, due to a recurrent asynchronous
240
- * task), the ServiceWorker will be registered anyway.
241
- * If `<timeout>` is omitted, the ServiceWorker will only be registered once the app
242
- * stabilizes.
243
- * - `registerImmediately`: Register immediately.
244
- * - `registerWithDelay:<timeout>`: Register with a delay of `<timeout>` milliseconds. For
245
- * example, use `registerWithDelay:5000` to register the ServiceWorker after 5 seconds. If
246
- * `<timeout>` is omitted, is defaults to `0`, which will register the ServiceWorker as soon
247
- * as possible but still asynchronously, once all pending micro-tasks are completed.
248
- * - An [Observable](guide/observables) factory function: A function that returns an `Observable`.
249
- * The function will be used at runtime to obtain and subscribe to the `Observable` and the
250
- * ServiceWorker will be registered as soon as the first value is emitted.
251
- *
252
- * Default: 'registerWhenStable:30000'
253
- */
254
- registrationStrategy?: string | (() => Observable<unknown>);
255
- }
256
-
257
- /**
258
- * Subscribe to update notifications from the Service Worker, trigger update
259
- * checks, and forcibly activate updates.
260
- *
261
- * @see {@link guide/service-worker-communications Service worker communication guide}
262
- *
263
- * @publicApi
264
- */
265
- export declare class SwUpdate {
266
- private sw;
267
- /**
268
- * Emits a `VersionDetectedEvent` event whenever a new version is detected on the server.
269
- *
270
- * Emits a `VersionInstallationFailedEvent` event whenever checking for or downloading a new
271
- * version fails.
272
- *
273
- * Emits a `VersionReadyEvent` event whenever a new version has been downloaded and is ready for
274
- * activation.
275
- */
276
- readonly versionUpdates: Observable<VersionEvent>;
277
- /**
278
- * Emits an `UpdateAvailableEvent` event whenever a new app version is available.
279
- *
280
- * @deprecated Use {@link versionUpdates} instead.
281
- *
282
- * The of behavior `available` can be rebuild by filtering for the `VersionReadyEvent`:
283
- * ```
284
- * import {filter, map} from 'rxjs/operators';
285
- * // ...
286
- * const updatesAvailable = swUpdate.versionUpdates.pipe(
287
- * filter((evt): evt is VersionReadyEvent => evt.type === 'VERSION_READY'),
288
- * map(evt => ({
289
- * type: 'UPDATE_AVAILABLE',
290
- * current: evt.currentVersion,
291
- * available: evt.latestVersion,
292
- * })));
293
- * ```
294
- */
295
- readonly available: Observable<UpdateAvailableEvent>;
296
- /**
297
- * Emits an `UpdateActivatedEvent` event whenever the app has been updated to a new version.
298
- *
299
- * @deprecated Use the return value of {@link SwUpdate#activateUpdate} instead.
300
- *
301
- */
302
- readonly activated: Observable<UpdateActivatedEvent>;
303
- /**
304
- * Emits an `UnrecoverableStateEvent` event whenever the version of the app used by the service
305
- * worker to serve this client is in a broken state that cannot be recovered from without a full
306
- * page reload.
307
- */
308
- readonly unrecoverable: Observable<UnrecoverableStateEvent>;
309
- /**
310
- * True if the Service Worker is enabled (supported by the browser and enabled via
311
- * `ServiceWorkerModule`).
312
- */
313
- get isEnabled(): boolean;
314
- constructor(sw: NgswCommChannel);
315
- /**
316
- * Checks for an update and waits until the new version is downloaded from the server and ready
317
- * for activation.
318
- *
319
- * @returns a promise that
320
- * - resolves to `true` if a new version was found and is ready to be activated.
321
- * - resolves to `false` if no new version was found
322
- * - rejects if any error occurs
323
- */
324
- checkForUpdate(): Promise<boolean>;
325
- /**
326
- * Updates the current client (i.e. browser tab) to the latest version that is ready for
327
- * activation.
328
- *
329
- * @returns a promise that
330
- * - resolves to `true` if an update was activated successfully
331
- * - resolves to `false` if no update was available (for example, the client was already on the
332
- * latest version).
333
- * - rejects if any error occurs
334
- */
335
- activateUpdate(): Promise<boolean>;
336
- static ɵfac: i0.ɵɵFactoryDeclaration<SwUpdate, never>;
337
- static ɵprov: i0.ɵɵInjectableDeclaration<SwUpdate>;
338
- }
339
-
340
- declare interface TypedEvent {
341
- type: string;
342
- }
343
-
344
- /**
345
- * An event emitted when the version of the app used by the service worker to serve this client is
346
- * in a broken state that cannot be recovered from and a full page reload is required.
347
- *
348
- * For example, the service worker may not be able to retrieve a required resource, neither from the
349
- * cache nor from the server. This could happen if a new version is deployed to the server and the
350
- * service worker cache has been partially cleaned by the browser, removing some files of a previous
351
- * app version but not all.
352
- *
353
- * @see {@link guide/service-worker-communications Service worker communication guide}
354
- *
355
- * @publicApi
356
- */
357
- export declare interface UnrecoverableStateEvent {
358
- type: 'UNRECOVERABLE_STATE';
359
- reason: string;
360
- }
361
-
362
- /**
363
- * An event emitted when a new version of the app has been downloaded and activated.
364
- *
365
- * @see {@link guide/service-worker-communications Service worker communication guide}
366
- *
367
- * @deprecated
368
- * This event is only emitted by the deprecated {@link SwUpdate#activated}.
369
- * Use the return value of {@link SwUpdate#activateUpdate} instead.
370
- *
371
- * @publicApi
372
- */
373
- export declare interface UpdateActivatedEvent {
374
- type: 'UPDATE_ACTIVATED';
375
- previous?: {
376
- hash: string;
377
- appData?: Object;
378
- };
379
- current: {
380
- hash: string;
381
- appData?: Object;
382
- };
383
- }
384
-
385
- /**
386
- * An event emitted when a new version of the app is available.
387
- *
388
- * @see {@link guide/service-worker-communications Service worker communication guide}
389
- *
390
- * @deprecated
391
- * This event is only emitted by the deprecated {@link SwUpdate#available}.
392
- * Use the {@link VersionReadyEvent} instead, which is emitted by {@link SwUpdate#versionUpdates}.
393
- * See {@link SwUpdate#available} docs for an example.
394
- *
395
- * @publicApi
396
- */
397
- export declare interface UpdateAvailableEvent {
398
- type: 'UPDATE_AVAILABLE';
399
- current: {
400
- hash: string;
401
- appData?: Object;
402
- };
403
- available: {
404
- hash: string;
405
- appData?: Object;
406
- };
407
- }
408
-
409
- /**
410
- * An event emitted when the service worker has detected a new version of the app on the server and
411
- * is about to start downloading it.
412
- *
413
- * @see {@link guide/service-worker-communications Service worker communication guide}
414
- *
415
- * @publicApi
416
- */
417
- export declare interface VersionDetectedEvent {
418
- type: 'VERSION_DETECTED';
419
- version: {
420
- hash: string;
421
- appData?: object;
422
- };
423
- }
424
-
425
- /**
426
- * A union of all event types that can be emitted by
427
- * {@link api/service-worker/SwUpdate#versionUpdates SwUpdate#versionUpdates}.
428
- *
429
- * @publicApi
430
- */
431
- export declare type VersionEvent = VersionDetectedEvent | VersionInstallationFailedEvent | VersionReadyEvent | NoNewVersionDetectedEvent;
432
-
433
- /**
434
- * An event emitted when the installation of a new version failed.
435
- * It may be used for logging/monitoring purposes.
436
- *
437
- * @see {@link guide/service-worker-communications Service worker communication guide}
438
- *
439
- * @publicApi
440
- */
441
- export declare interface VersionInstallationFailedEvent {
442
- type: 'VERSION_INSTALLATION_FAILED';
443
- version: {
444
- hash: string;
445
- appData?: object;
446
- };
447
- error: string;
448
- }
449
-
450
- /**
451
- * An event emitted when a new version of the app is available.
452
- *
453
- * @see {@link guide/service-worker-communications Service worker communication guide}
454
- *
455
- * @publicApi
456
- */
457
- export declare interface VersionReadyEvent {
458
- type: 'VERSION_READY';
459
- currentVersion: {
460
- hash: string;
461
- appData?: object;
462
- };
463
- latestVersion: {
464
- hash: string;
465
- appData?: object;
466
- };
467
- }
468
-
469
- export { }
7
+
8
+ import * as i0 from '@angular/core';
9
+ import { ModuleWithProviders } from '@angular/core';
10
+ import { Observable } from 'rxjs';
11
+
12
+ /**
13
+ * @publicApi
14
+ */
15
+ declare class NgswCommChannel {
16
+ private serviceWorker;
17
+ readonly worker: Observable<ServiceWorker>;
18
+ readonly registration: Observable<ServiceWorkerRegistration>;
19
+ readonly events: Observable<TypedEvent>;
20
+ constructor(serviceWorker: ServiceWorkerContainer | undefined);
21
+ postMessage(action: string, payload: Object): Promise<void>;
22
+ postMessageWithOperation(type: string, payload: Object, operationNonce: number): Promise<boolean>;
23
+ generateNonce(): number;
24
+ eventsOfType<T extends TypedEvent>(type: T['type'] | T['type'][]): Observable<T>;
25
+ nextEventOfType<T extends TypedEvent>(type: T['type']): Observable<T>;
26
+ waitForOperationCompleted(nonce: number): Promise<boolean>;
27
+ get isEnabled(): boolean;
28
+ }
29
+
30
+ /**
31
+ * An event emitted when the service worker has checked the version of the app on the server and it
32
+ * didn't find a new version that it doesn't have already downloaded.
33
+ *
34
+ * @see {@link guide/service-worker-communications Service worker communication guide}
35
+ *
36
+ * @publicApi
37
+ */
38
+ declare interface NoNewVersionDetectedEvent {
39
+ type: 'NO_NEW_VERSION_DETECTED';
40
+ version: {
41
+ hash: string;
42
+ appData?: Object;
43
+ };
44
+ }
45
+
46
+ /**
47
+ * @publicApi
48
+ */
49
+ export declare class ServiceWorkerModule {
50
+ /**
51
+ * Register the given Angular Service Worker script.
52
+ *
53
+ * If `enabled` is set to `false` in the given options, the module will behave as if service
54
+ * workers are not supported by the browser, and the service worker will not be registered.
55
+ */
56
+ static register(script: string, opts?: SwRegistrationOptions): ModuleWithProviders<ServiceWorkerModule>;
57
+ static ɵfac: i0.ɵɵFactoryDeclaration<ServiceWorkerModule, never>;
58
+ static ɵmod: i0.ɵɵNgModuleDeclaration<ServiceWorkerModule, never, never, never>;
59
+ static ɵinj: i0.ɵɵInjectorDeclaration<ServiceWorkerModule>;
60
+ }
61
+
62
+ /**
63
+ * Subscribe and listen to
64
+ * [Web Push
65
+ * Notifications](https://developer.mozilla.org/en-US/docs/Web/API/Push_API/Best_Practices) through
66
+ * Angular Service Worker.
67
+ *
68
+ * @usageNotes
69
+ *
70
+ * You can inject a `SwPush` instance into any component or service
71
+ * as a dependency.
72
+ *
73
+ * <code-example path="service-worker/push/module.ts" region="inject-sw-push"
74
+ * header="app.component.ts"></code-example>
75
+ *
76
+ * To subscribe, call `SwPush.requestSubscription()`, which asks the user for permission.
77
+ * The call returns a `Promise` with a new
78
+ * [`PushSubscription`](https://developer.mozilla.org/en-US/docs/Web/API/PushSubscription)
79
+ * instance.
80
+ *
81
+ * <code-example path="service-worker/push/module.ts" region="subscribe-to-push"
82
+ * header="app.component.ts"></code-example>
83
+ *
84
+ * A request is rejected if the user denies permission, or if the browser
85
+ * blocks or does not support the Push API or ServiceWorkers.
86
+ * Check `SwPush.isEnabled` to confirm status.
87
+ *
88
+ * Invoke Push Notifications by pushing a message with the following payload.
89
+ *
90
+ * ```ts
91
+ * {
92
+ * "notification": {
93
+ * "actions": NotificationAction[],
94
+ * "badge": USVString,
95
+ * "body": DOMString,
96
+ * "data": any,
97
+ * "dir": "auto"|"ltr"|"rtl",
98
+ * "icon": USVString,
99
+ * "image": USVString,
100
+ * "lang": DOMString,
101
+ * "renotify": boolean,
102
+ * "requireInteraction": boolean,
103
+ * "silent": boolean,
104
+ * "tag": DOMString,
105
+ * "timestamp": DOMTimeStamp,
106
+ * "title": DOMString,
107
+ * "vibrate": number[]
108
+ * }
109
+ * }
110
+ * ```
111
+ *
112
+ * Only `title` is required. See `Notification`
113
+ * [instance
114
+ * properties](https://developer.mozilla.org/en-US/docs/Web/API/Notification#Instance_properties).
115
+ *
116
+ * While the subscription is active, Service Worker listens for
117
+ * [PushEvent](https://developer.mozilla.org/en-US/docs/Web/API/PushEvent)
118
+ * occurrences and creates
119
+ * [Notification](https://developer.mozilla.org/en-US/docs/Web/API/Notification)
120
+ * instances in response.
121
+ *
122
+ * Unsubscribe using `SwPush.unsubscribe()`.
123
+ *
124
+ * An application can subscribe to `SwPush.notificationClicks` observable to be notified when a user
125
+ * clicks on a notification. For example:
126
+ *
127
+ * <code-example path="service-worker/push/module.ts" region="subscribe-to-notification-clicks"
128
+ * header="app.component.ts"></code-example>
129
+ *
130
+ * You can read more on handling notification clicks in the [Service worker notifications
131
+ * guide](guide/service-worker-notifications).
132
+ *
133
+ * @see [Push Notifications](https://developers.google.com/web/fundamentals/codelabs/push-notifications/)
134
+ * @see [Angular Push Notifications](https://blog.angular-university.io/angular-push-notifications/)
135
+ * @see [MDN: Push API](https://developer.mozilla.org/en-US/docs/Web/API/Push_API)
136
+ * @see [MDN: Notifications API](https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API)
137
+ * @see [MDN: Web Push API Notifications best practices](https://developer.mozilla.org/en-US/docs/Web/API/Push_API/Best_Practices)
138
+ *
139
+ * @publicApi
140
+ */
141
+ export declare class SwPush {
142
+ private sw;
143
+ /**
144
+ * Emits the payloads of the received push notification messages.
145
+ */
146
+ readonly messages: Observable<object>;
147
+ /**
148
+ * Emits the payloads of the received push notification messages as well as the action the user
149
+ * interacted with. If no action was used the `action` property contains an empty string `''`.
150
+ *
151
+ * Note that the `notification` property does **not** contain a
152
+ * [Notification][Mozilla Notification] object but rather a
153
+ * [NotificationOptions](https://notifications.spec.whatwg.org/#dictdef-notificationoptions)
154
+ * object that also includes the `title` of the [Notification][Mozilla Notification] object.
155
+ *
156
+ * [Mozilla Notification]: https://developer.mozilla.org/en-US/docs/Web/API/Notification
157
+ */
158
+ readonly notificationClicks: Observable<{
159
+ action: string;
160
+ notification: NotificationOptions & {
161
+ title: string;
162
+ };
163
+ }>;
164
+ /**
165
+ * Emits the currently active
166
+ * [PushSubscription](https://developer.mozilla.org/en-US/docs/Web/API/PushSubscription)
167
+ * associated to the Service Worker registration or `null` if there is no subscription.
168
+ */
169
+ readonly subscription: Observable<PushSubscription | null>;
170
+ /**
171
+ * True if the Service Worker is enabled (supported by the browser and enabled via
172
+ * `ServiceWorkerModule`).
173
+ */
174
+ get isEnabled(): boolean;
175
+ private pushManager;
176
+ private subscriptionChanges;
177
+ constructor(sw: NgswCommChannel);
178
+ /**
179
+ * Subscribes to Web Push Notifications,
180
+ * after requesting and receiving user permission.
181
+ *
182
+ * @param options An object containing the `serverPublicKey` string.
183
+ * @returns A Promise that resolves to the new subscription object.
184
+ */
185
+ requestSubscription(options: {
186
+ serverPublicKey: string;
187
+ }): Promise<PushSubscription>;
188
+ /**
189
+ * Unsubscribes from Service Worker push notifications.
190
+ *
191
+ * @returns A Promise that is resolved when the operation succeeds, or is rejected if there is no
192
+ * active subscription or the unsubscribe operation fails.
193
+ */
194
+ unsubscribe(): Promise<void>;
195
+ private decodeBase64;
196
+ static ɵfac: i0.ɵɵFactoryDeclaration<SwPush, never>;
197
+ static ɵprov: i0.ɵɵInjectableDeclaration<SwPush>;
198
+ }
199
+
200
+ /**
201
+ * Token that can be used to provide options for `ServiceWorkerModule` outside of
202
+ * `ServiceWorkerModule.register()`.
203
+ *
204
+ * You can use this token to define a provider that generates the registration options at runtime,
205
+ * for example via a function call:
206
+ *
207
+ * {@example service-worker/registration-options/module.ts region="registration-options"
208
+ * header="app.module.ts"}
209
+ *
210
+ * @publicApi
211
+ */
212
+ export declare abstract class SwRegistrationOptions {
213
+ /**
214
+ * Whether the ServiceWorker will be registered and the related services (such as `SwPush` and
215
+ * `SwUpdate`) will attempt to communicate and interact with it.
216
+ *
217
+ * Default: true
218
+ */
219
+ enabled?: boolean;
220
+ /**
221
+ * A URL that defines the ServiceWorker's registration scope; that is, what range of URLs it can
222
+ * control. It will be used when calling
223
+ * [ServiceWorkerContainer#register()](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register).
224
+ */
225
+ scope?: string;
226
+ /**
227
+ * Defines the ServiceWorker registration strategy, which determines when it will be registered
228
+ * with the browser.
229
+ *
230
+ * The default behavior of registering once the application stabilizes (i.e. as soon as there are
231
+ * no pending micro- and macro-tasks) is designed to register the ServiceWorker as soon as
232
+ * possible but without affecting the application's first time load.
233
+ *
234
+ * Still, there might be cases where you want more control over when the ServiceWorker is
235
+ * registered (for example, there might be a long-running timeout or polling interval, preventing
236
+ * the app from stabilizing). The available option are:
237
+ *
238
+ * - `registerWhenStable:<timeout>`: Register as soon as the application stabilizes (no pending
239
+ * micro-/macro-tasks) but no later than `<timeout>` milliseconds. If the app hasn't
240
+ * stabilized after `<timeout>` milliseconds (for example, due to a recurrent asynchronous
241
+ * task), the ServiceWorker will be registered anyway.
242
+ * If `<timeout>` is omitted, the ServiceWorker will only be registered once the app
243
+ * stabilizes.
244
+ * - `registerImmediately`: Register immediately.
245
+ * - `registerWithDelay:<timeout>`: Register with a delay of `<timeout>` milliseconds. For
246
+ * example, use `registerWithDelay:5000` to register the ServiceWorker after 5 seconds. If
247
+ * `<timeout>` is omitted, is defaults to `0`, which will register the ServiceWorker as soon
248
+ * as possible but still asynchronously, once all pending micro-tasks are completed.
249
+ * - An [Observable](guide/observables) factory function: A function that returns an `Observable`.
250
+ * The function will be used at runtime to obtain and subscribe to the `Observable` and the
251
+ * ServiceWorker will be registered as soon as the first value is emitted.
252
+ *
253
+ * Default: 'registerWhenStable:30000'
254
+ */
255
+ registrationStrategy?: string | (() => Observable<unknown>);
256
+ }
257
+
258
+ /**
259
+ * Subscribe to update notifications from the Service Worker, trigger update
260
+ * checks, and forcibly activate updates.
261
+ *
262
+ * @see {@link guide/service-worker-communications Service worker communication guide}
263
+ *
264
+ * @publicApi
265
+ */
266
+ export declare class SwUpdate {
267
+ private sw;
268
+ /**
269
+ * Emits a `VersionDetectedEvent` event whenever a new version is detected on the server.
270
+ *
271
+ * Emits a `VersionInstallationFailedEvent` event whenever checking for or downloading a new
272
+ * version fails.
273
+ *
274
+ * Emits a `VersionReadyEvent` event whenever a new version has been downloaded and is ready for
275
+ * activation.
276
+ */
277
+ readonly versionUpdates: Observable<VersionEvent>;
278
+ /**
279
+ * Emits an `UpdateAvailableEvent` event whenever a new app version is available.
280
+ *
281
+ * @deprecated Use {@link versionUpdates} instead.
282
+ *
283
+ * The of behavior `available` can be rebuild by filtering for the `VersionReadyEvent`:
284
+ * ```
285
+ * import {filter, map} from 'rxjs/operators';
286
+ * // ...
287
+ * const updatesAvailable = swUpdate.versionUpdates.pipe(
288
+ * filter((evt): evt is VersionReadyEvent => evt.type === 'VERSION_READY'),
289
+ * map(evt => ({
290
+ * type: 'UPDATE_AVAILABLE',
291
+ * current: evt.currentVersion,
292
+ * available: evt.latestVersion,
293
+ * })));
294
+ * ```
295
+ */
296
+ readonly available: Observable<UpdateAvailableEvent>;
297
+ /**
298
+ * Emits an `UpdateActivatedEvent` event whenever the app has been updated to a new version.
299
+ *
300
+ * @deprecated Use the return value of {@link SwUpdate#activateUpdate} instead.
301
+ *
302
+ */
303
+ readonly activated: Observable<UpdateActivatedEvent>;
304
+ /**
305
+ * Emits an `UnrecoverableStateEvent` event whenever the version of the app used by the service
306
+ * worker to serve this client is in a broken state that cannot be recovered from without a full
307
+ * page reload.
308
+ */
309
+ readonly unrecoverable: Observable<UnrecoverableStateEvent>;
310
+ /**
311
+ * True if the Service Worker is enabled (supported by the browser and enabled via
312
+ * `ServiceWorkerModule`).
313
+ */
314
+ get isEnabled(): boolean;
315
+ constructor(sw: NgswCommChannel);
316
+ /**
317
+ * Checks for an update and waits until the new version is downloaded from the server and ready
318
+ * for activation.
319
+ *
320
+ * @returns a promise that
321
+ * - resolves to `true` if a new version was found and is ready to be activated.
322
+ * - resolves to `false` if no new version was found
323
+ * - rejects if any error occurs
324
+ */
325
+ checkForUpdate(): Promise<boolean>;
326
+ /**
327
+ * Updates the current client (i.e. browser tab) to the latest version that is ready for
328
+ * activation.
329
+ *
330
+ * @returns a promise that
331
+ * - resolves to `true` if an update was activated successfully
332
+ * - resolves to `false` if no update was available (for example, the client was already on the
333
+ * latest version).
334
+ * - rejects if any error occurs
335
+ */
336
+ activateUpdate(): Promise<boolean>;
337
+ static ɵfac: i0.ɵɵFactoryDeclaration<SwUpdate, never>;
338
+ static ɵprov: i0.ɵɵInjectableDeclaration<SwUpdate>;
339
+ }
340
+
341
+ declare interface TypedEvent {
342
+ type: string;
343
+ }
344
+
345
+ /**
346
+ * An event emitted when the version of the app used by the service worker to serve this client is
347
+ * in a broken state that cannot be recovered from and a full page reload is required.
348
+ *
349
+ * For example, the service worker may not be able to retrieve a required resource, neither from the
350
+ * cache nor from the server. This could happen if a new version is deployed to the server and the
351
+ * service worker cache has been partially cleaned by the browser, removing some files of a previous
352
+ * app version but not all.
353
+ *
354
+ * @see {@link guide/service-worker-communications Service worker communication guide}
355
+ *
356
+ * @publicApi
357
+ */
358
+ export declare interface UnrecoverableStateEvent {
359
+ type: 'UNRECOVERABLE_STATE';
360
+ reason: string;
361
+ }
362
+
363
+ /**
364
+ * An event emitted when a new version of the app has been downloaded and activated.
365
+ *
366
+ * @see {@link guide/service-worker-communications Service worker communication guide}
367
+ *
368
+ * @deprecated
369
+ * This event is only emitted by the deprecated {@link SwUpdate#activated}.
370
+ * Use the return value of {@link SwUpdate#activateUpdate} instead.
371
+ *
372
+ * @publicApi
373
+ */
374
+ export declare interface UpdateActivatedEvent {
375
+ type: 'UPDATE_ACTIVATED';
376
+ previous?: {
377
+ hash: string;
378
+ appData?: Object;
379
+ };
380
+ current: {
381
+ hash: string;
382
+ appData?: Object;
383
+ };
384
+ }
385
+
386
+ /**
387
+ * An event emitted when a new version of the app is available.
388
+ *
389
+ * @see {@link guide/service-worker-communications Service worker communication guide}
390
+ *
391
+ * @deprecated
392
+ * This event is only emitted by the deprecated {@link SwUpdate#available}.
393
+ * Use the {@link VersionReadyEvent} instead, which is emitted by {@link SwUpdate#versionUpdates}.
394
+ * See {@link SwUpdate#available} docs for an example.
395
+ *
396
+ * @publicApi
397
+ */
398
+ export declare interface UpdateAvailableEvent {
399
+ type: 'UPDATE_AVAILABLE';
400
+ current: {
401
+ hash: string;
402
+ appData?: Object;
403
+ };
404
+ available: {
405
+ hash: string;
406
+ appData?: Object;
407
+ };
408
+ }
409
+
410
+ /**
411
+ * An event emitted when the service worker has detected a new version of the app on the server and
412
+ * is about to start downloading it.
413
+ *
414
+ * @see {@link guide/service-worker-communications Service worker communication guide}
415
+ *
416
+ * @publicApi
417
+ */
418
+ export declare interface VersionDetectedEvent {
419
+ type: 'VERSION_DETECTED';
420
+ version: {
421
+ hash: string;
422
+ appData?: object;
423
+ };
424
+ }
425
+
426
+ /**
427
+ * A union of all event types that can be emitted by
428
+ * {@link api/service-worker/SwUpdate#versionUpdates SwUpdate#versionUpdates}.
429
+ *
430
+ * @publicApi
431
+ */
432
+ export declare type VersionEvent = VersionDetectedEvent | VersionInstallationFailedEvent | VersionReadyEvent | NoNewVersionDetectedEvent;
433
+
434
+ /**
435
+ * An event emitted when the installation of a new version failed.
436
+ * It may be used for logging/monitoring purposes.
437
+ *
438
+ * @see {@link guide/service-worker-communications Service worker communication guide}
439
+ *
440
+ * @publicApi
441
+ */
442
+ export declare interface VersionInstallationFailedEvent {
443
+ type: 'VERSION_INSTALLATION_FAILED';
444
+ version: {
445
+ hash: string;
446
+ appData?: object;
447
+ };
448
+ error: string;
449
+ }
450
+
451
+ /**
452
+ * An event emitted when a new version of the app is available.
453
+ *
454
+ * @see {@link guide/service-worker-communications Service worker communication guide}
455
+ *
456
+ * @publicApi
457
+ */
458
+ export declare interface VersionReadyEvent {
459
+ type: 'VERSION_READY';
460
+ currentVersion: {
461
+ hash: string;
462
+ appData?: object;
463
+ };
464
+ latestVersion: {
465
+ hash: string;
466
+ appData?: object;
467
+ };
468
+ }
469
+
470
+ export { }