1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import { EnvironmentProviders } from '@angular/core';
|
9 | import * as i0 from '@angular/core';
|
10 | import { ModuleWithProviders } from '@angular/core';
|
11 | import { Observable } from 'rxjs';
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | declare class NgswCommChannel {
|
17 | private serviceWorker;
|
18 | readonly worker: Observable<ServiceWorker>;
|
19 | readonly registration: Observable<ServiceWorkerRegistration>;
|
20 | readonly events: Observable<TypedEvent>;
|
21 | constructor(serviceWorker: ServiceWorkerContainer | undefined);
|
22 | postMessage(action: string, payload: Object): Promise<void>;
|
23 | postMessageWithOperation(type: string, payload: Object, operationNonce: number): Promise<boolean>;
|
24 | generateNonce(): number;
|
25 | eventsOfType<T extends TypedEvent>(type: T['type'] | T['type'][]): Observable<T>;
|
26 | nextEventOfType<T extends TypedEvent>(type: T['type']): Observable<T>;
|
27 | waitForOperationCompleted(nonce: number): Promise<boolean>;
|
28 | get isEnabled(): boolean;
|
29 | }
|
30 |
|
31 | /**
|
32 | * An event emitted when the service worker has checked the version of the app on the server and it
|
33 | * didn't find a new version that it doesn't have already downloaded.
|
34 | *
|
35 | * @see {@link ecosystem/service-workers/communications Service worker communication guide}
|
36 | *
|
37 | * @publicApi
|
38 | */
|
39 | export declare interface NoNewVersionDetectedEvent {
|
40 | type: 'NO_NEW_VERSION_DETECTED';
|
41 | version: {
|
42 | hash: string;
|
43 | appData?: Object;
|
44 | };
|
45 | }
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | export declare function provideServiceWorker(script: string, options?: SwRegistrationOptions): EnvironmentProviders;
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | export declare class ServiceWorkerModule {
|
70 | |
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | static register(script: string, options?: SwRegistrationOptions): ModuleWithProviders<ServiceWorkerModule>;
|
77 | static ɵfac: i0.ɵɵFactoryDeclaration<ServiceWorkerModule, never>;
|
78 | static ɵmod: i0.ɵɵNgModuleDeclaration<ServiceWorkerModule, never, never, never>;
|
79 | static ɵinj: i0.ɵɵInjectorDeclaration<ServiceWorkerModule>;
|
80 | }
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 | export declare class SwPush {
|
162 | private sw;
|
163 | |
164 |
|
165 |
|
166 | readonly messages: Observable<object>;
|
167 | |
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 | readonly notificationClicks: Observable<{
|
179 | action: string;
|
180 | notification: NotificationOptions & {
|
181 | title: string;
|
182 | };
|
183 | }>;
|
184 | |
185 |
|
186 |
|
187 |
|
188 |
|
189 | readonly subscription: Observable<PushSubscription | null>;
|
190 | |
191 |
|
192 |
|
193 |
|
194 | get isEnabled(): boolean;
|
195 | private pushManager;
|
196 | private subscriptionChanges;
|
197 | constructor(sw: NgswCommChannel);
|
198 | /**
|
199 | * Subscribes to Web Push Notifications,
|
200 | * after requesting and receiving user permission.
|
201 | *
|
202 | * @param options An object containing the `serverPublicKey` string.
|
203 | * @returns A Promise that resolves to the new subscription object.
|
204 | */
|
205 | requestSubscription(options: {
|
206 | serverPublicKey: string;
|
207 | }): Promise<PushSubscription>;
|
208 | /**
|
209 | * Unsubscribes from Service Worker push notifications.
|
210 | *
|
211 | * @returns A Promise that is resolved when the operation succeeds, or is rejected if there is no
|
212 | * active subscription or the unsubscribe operation fails.
|
213 | */
|
214 | unsubscribe(): Promise<void>;
|
215 | private decodeBase64;
|
216 | static ɵfac: i0.ɵɵFactoryDeclaration<SwPush, never>;
|
217 | static ɵprov: i0.ɵɵInjectableDeclaration<SwPush>;
|
218 | }
|
219 |
|
220 | /**
|
221 | * Token that can be used to provide options for `ServiceWorkerModule` outside of
|
222 | * `ServiceWorkerModule.register()`.
|
223 | *
|
224 | * You can use this token to define a provider that generates the registration options at runtime,
|
225 | * for example via a function call:
|
226 | *
|
227 | * {@example service-worker/registration-options/module.ts region="registration-options"
|
228 | * header="app.module.ts"}
|
229 | *
|
230 | * @publicApi
|
231 | */
|
232 | export declare abstract class SwRegistrationOptions {
|
233 | |
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 | enabled?: boolean;
|
240 | |
241 |
|
242 |
|
243 |
|
244 |
|
245 | scope?: string;
|
246 | |
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 | registrationStrategy?: string | (() => Observable<unknown>);
|
276 | }
|
277 |
|
278 | /**
|
279 | * Subscribe to update notifications from the Service Worker, trigger update
|
280 | * checks, and forcibly activate updates.
|
281 | *
|
282 | * @see {@link ecosystem/service-workers/communications Service worker communication guide}
|
283 | *
|
284 | * @publicApi
|
285 | */
|
286 | export declare class SwUpdate {
|
287 | private sw;
|
288 | /**
|
289 | * Emits a `VersionDetectedEvent` event whenever a new version is detected on the server.
|
290 | *
|
291 | * Emits a `VersionInstallationFailedEvent` event whenever checking for or downloading a new
|
292 | * version fails.
|
293 | *
|
294 | * Emits a `VersionReadyEvent` event whenever a new version has been downloaded and is ready for
|
295 | * activation.
|
296 | */
|
297 | readonly versionUpdates: Observable<VersionEvent>;
|
298 | /**
|
299 | * Emits an `UnrecoverableStateEvent` event whenever the version of the app used by the service
|
300 | * worker to serve this client is in a broken state that cannot be recovered from without a full
|
301 | * page reload.
|
302 | */
|
303 | readonly unrecoverable: Observable<UnrecoverableStateEvent>;
|
304 | /**
|
305 | * True if the Service Worker is enabled (supported by the browser and enabled via
|
306 | * `ServiceWorkerModule`).
|
307 | */
|
308 | get isEnabled(): boolean;
|
309 | constructor(sw: NgswCommChannel);
|
310 | /**
|
311 | * Checks for an update and waits until the new version is downloaded from the server and ready
|
312 | * for activation.
|
313 | *
|
314 | * @returns a promise that
|
315 | * - resolves to `true` if a new version was found and is ready to be activated.
|
316 | * - resolves to `false` if no new version was found
|
317 | * - rejects if any error occurs
|
318 | */
|
319 | checkForUpdate(): Promise<boolean>;
|
320 | /**
|
321 | * Updates the current client (i.e. browser tab) to the latest version that is ready for
|
322 | * activation.
|
323 | *
|
324 | * In most cases, you should not use this method and instead should update a client by reloading
|
325 | * the page.
|
326 | *
|
327 | * <div class="docs-alert docs-alert-important">
|
328 | *
|
329 | * Updating a client without reloading can easily result in a broken application due to a version
|
330 | * mismatch between the application shell and other page resources,
|
331 | * such as lazy-loaded chunks, whose filenames may change between
|
332 | * versions.
|
333 | *
|
334 | * Only use this method, if you are certain it is safe for your specific use case.
|
335 | *
|
336 | * </div>
|
337 | *
|
338 | * @returns a promise that
|
339 | * - resolves to `true` if an update was activated successfully
|
340 | * - resolves to `false` if no update was available (for example, the client was already on the
|
341 | * latest version).
|
342 | * - rejects if any error occurs
|
343 | */
|
344 | activateUpdate(): Promise<boolean>;
|
345 | static ɵfac: i0.ɵɵFactoryDeclaration<SwUpdate, never>;
|
346 | static ɵprov: i0.ɵɵInjectableDeclaration<SwUpdate>;
|
347 | }
|
348 |
|
349 | declare interface TypedEvent {
|
350 | type: string;
|
351 | }
|
352 |
|
353 | /**
|
354 | * An event emitted when the version of the app used by the service worker to serve this client is
|
355 | * in a broken state that cannot be recovered from and a full page reload is required.
|
356 | *
|
357 | * For example, the service worker may not be able to retrieve a required resource, neither from the
|
358 | * cache nor from the server. This could happen if a new version is deployed to the server and the
|
359 | * service worker cache has been partially cleaned by the browser, removing some files of a previous
|
360 | * app version but not all.
|
361 | *
|
362 | * @see {@link ecosystem/service-workers/communications Service worker communication guide}
|
363 | *
|
364 | * @publicApi
|
365 | */
|
366 | export declare interface UnrecoverableStateEvent {
|
367 | type: 'UNRECOVERABLE_STATE';
|
368 | reason: string;
|
369 | }
|
370 |
|
371 | /**
|
372 | * An event emitted when the service worker has detected a new version of the app on the server and
|
373 | * is about to start downloading it.
|
374 | *
|
375 | * @see {@link ecosystem/service-workers/communications Service worker communication guide}
|
376 | *
|
377 | * @publicApi
|
378 | */
|
379 | export declare interface VersionDetectedEvent {
|
380 | type: 'VERSION_DETECTED';
|
381 | version: {
|
382 | hash: string;
|
383 | appData?: object;
|
384 | };
|
385 | }
|
386 |
|
387 | /**
|
388 | * A union of all event types that can be emitted by
|
389 | * {@link SwUpdate#versionUpdates}.
|
390 | *
|
391 | * @publicApi
|
392 | */
|
393 | export declare type VersionEvent = VersionDetectedEvent | VersionInstallationFailedEvent | VersionReadyEvent | NoNewVersionDetectedEvent;
|
394 |
|
395 | /**
|
396 | * An event emitted when the installation of a new version failed.
|
397 | * It may be used for logging/monitoring purposes.
|
398 | *
|
399 | * @see {@link ecosystem/service-workers/communications Service worker communication guide}
|
400 | *
|
401 | * @publicApi
|
402 | */
|
403 | export declare interface VersionInstallationFailedEvent {
|
404 | type: 'VERSION_INSTALLATION_FAILED';
|
405 | version: {
|
406 | hash: string;
|
407 | appData?: object;
|
408 | };
|
409 | error: string;
|
410 | }
|
411 |
|
412 | /**
|
413 | * An event emitted when a new version of the app is available.
|
414 | *
|
415 | * @see {@link ecosystem/service-workers/communications Service worker communication guide}
|
416 | *
|
417 | * @publicApi
|
418 | */
|
419 | export declare interface VersionReadyEvent {
|
420 | type: 'VERSION_READY';
|
421 | currentVersion: {
|
422 | hash: string;
|
423 | appData?: object;
|
424 | };
|
425 | latestVersion: {
|
426 | hash: string;
|
427 | appData?: object;
|
428 | };
|
429 | }
|
430 |
|
431 | export { }
|
432 |
|
\ | No newline at end of file |