@angular/service-worker 13.0.0-next.11 → 13.0.0-next.15

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,5 +1,5 @@
1
1
  /**
2
- * @license Angular v13.0.0-next.11
2
+ * @license Angular v13.0.0-next.15
3
3
  * (c) 2010-2021 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
@@ -56,26 +56,32 @@ class NgswCommChannel {
56
56
  .toPromise()
57
57
  .then(() => undefined);
58
58
  }
59
- postMessageWithStatus(type, payload, nonce) {
60
- const waitForStatus = this.waitForStatus(nonce);
59
+ postMessageWithOperation(type, payload, operationNonce) {
60
+ const waitForOperationCompleted = this.waitForOperationCompleted(operationNonce);
61
61
  const postMessage = this.postMessage(type, payload);
62
- return Promise.all([waitForStatus, postMessage]).then(() => undefined);
62
+ return Promise.all([postMessage, waitForOperationCompleted]).then(([, result]) => result);
63
63
  }
64
64
  generateNonce() {
65
65
  return Math.round(Math.random() * 10000000);
66
66
  }
67
67
  eventsOfType(type) {
68
- const filterFn = (event) => event.type === type;
68
+ let filterFn;
69
+ if (typeof type === 'string') {
70
+ filterFn = (event) => event.type === type;
71
+ }
72
+ else {
73
+ filterFn = (event) => type.includes(event.type);
74
+ }
69
75
  return this.events.pipe(filter(filterFn));
70
76
  }
71
77
  nextEventOfType(type) {
72
78
  return this.eventsOfType(type).pipe(take(1));
73
79
  }
74
- waitForStatus(nonce) {
75
- return this.eventsOfType('STATUS')
80
+ waitForOperationCompleted(nonce) {
81
+ return this.eventsOfType('OPERATION_COMPLETED')
76
82
  .pipe(filter(event => event.nonce === nonce), take(1), map(event => {
77
- if (event.status) {
78
- return undefined;
83
+ if (event.result !== undefined) {
84
+ return event.result;
79
85
  }
80
86
  throw new Error(event.error);
81
87
  }))
@@ -248,9 +254,9 @@ class SwPush {
248
254
  return atob(input);
249
255
  }
250
256
  }
251
- SwPush.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0-next.11", ngImport: i0, type: SwPush, deps: [{ token: NgswCommChannel }], target: i0.ɵɵFactoryTarget.Injectable });
252
- SwPush.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.0-next.11", ngImport: i0, type: SwPush });
253
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0-next.11", ngImport: i0, type: SwPush, decorators: [{
257
+ SwPush.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0-next.15", ngImport: i0, type: SwPush, deps: [{ token: NgswCommChannel }], target: i0.ɵɵFactoryTarget.Injectable });
258
+ SwPush.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.0-next.15", ngImport: i0, type: SwPush });
259
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0-next.15", ngImport: i0, type: SwPush, decorators: [{
254
260
  type: Injectable
255
261
  }], ctorParameters: function () { return [{ type: NgswCommChannel }]; } });
256
262
 
@@ -273,12 +279,18 @@ class SwUpdate {
273
279
  constructor(sw) {
274
280
  this.sw = sw;
275
281
  if (!sw.isEnabled) {
282
+ this.versionUpdates = NEVER;
276
283
  this.available = NEVER;
277
284
  this.activated = NEVER;
278
285
  this.unrecoverable = NEVER;
279
286
  return;
280
287
  }
281
- this.available = this.sw.eventsOfType('UPDATE_AVAILABLE');
288
+ this.versionUpdates = this.sw.eventsOfType(['VERSION_DETECTED', 'VERSION_INSTALLATION_FAILED', 'VERSION_READY']);
289
+ this.available = this.versionUpdates.pipe(filter((evt) => evt.type === 'VERSION_READY'), map(evt => ({
290
+ type: 'UPDATE_AVAILABLE',
291
+ current: evt.currentVersion,
292
+ available: evt.latestVersion,
293
+ })));
282
294
  this.activated = this.sw.eventsOfType('UPDATE_ACTIVATED');
283
295
  this.unrecoverable = this.sw.eventsOfType('UNRECOVERABLE_STATE');
284
296
  }
@@ -289,24 +301,43 @@ class SwUpdate {
289
301
  get isEnabled() {
290
302
  return this.sw.isEnabled;
291
303
  }
304
+ /**
305
+ * Checks for an update and waits until the new version is downloaded from the server and ready
306
+ * for activation.
307
+ *
308
+ * @returns a promise that
309
+ * - resolves to `true` if a new version was found and is ready to be activated.
310
+ * - resolves to `false` if no new version was found
311
+ * - rejects if any error occurs
312
+ */
292
313
  checkForUpdate() {
293
314
  if (!this.sw.isEnabled) {
294
315
  return Promise.reject(new Error(ERR_SW_NOT_SUPPORTED));
295
316
  }
296
- const statusNonce = this.sw.generateNonce();
297
- return this.sw.postMessageWithStatus('CHECK_FOR_UPDATES', { statusNonce }, statusNonce);
317
+ const nonce = this.sw.generateNonce();
318
+ return this.sw.postMessageWithOperation('CHECK_FOR_UPDATES', { nonce }, nonce);
298
319
  }
320
+ /**
321
+ * Updates the current client (i.e. browser tab) to the latest version that is ready for
322
+ * activation.
323
+ *
324
+ * @returns a promise that
325
+ * - resolves to `true` if an update was activated successfully
326
+ * - resolves to `false` if no update was available (for example, the client was already on the
327
+ * latest version).
328
+ * - rejects if any error occurs
329
+ */
299
330
  activateUpdate() {
300
331
  if (!this.sw.isEnabled) {
301
332
  return Promise.reject(new Error(ERR_SW_NOT_SUPPORTED));
302
333
  }
303
- const statusNonce = this.sw.generateNonce();
304
- return this.sw.postMessageWithStatus('ACTIVATE_UPDATE', { statusNonce }, statusNonce);
334
+ const nonce = this.sw.generateNonce();
335
+ return this.sw.postMessageWithOperation('ACTIVATE_UPDATE', { nonce }, nonce);
305
336
  }
306
337
  }
307
- SwUpdate.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0-next.11", ngImport: i0, type: SwUpdate, deps: [{ token: NgswCommChannel }], target: i0.ɵɵFactoryTarget.Injectable });
308
- SwUpdate.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.0-next.11", ngImport: i0, type: SwUpdate });
309
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0-next.11", ngImport: i0, type: SwUpdate, decorators: [{
338
+ SwUpdate.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0-next.15", ngImport: i0, type: SwUpdate, deps: [{ token: NgswCommChannel }], target: i0.ɵɵFactoryTarget.Injectable });
339
+ SwUpdate.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.0-next.15", ngImport: i0, type: SwUpdate });
340
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0-next.15", ngImport: i0, type: SwUpdate, decorators: [{
310
341
  type: Injectable
311
342
  }], ctorParameters: function () { return [{ type: NgswCommChannel }]; } });
312
343
 
@@ -420,10 +451,10 @@ class ServiceWorkerModule {
420
451
  };
421
452
  }
422
453
  }
423
- ServiceWorkerModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0-next.11", ngImport: i0, type: ServiceWorkerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
424
- ServiceWorkerModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.0-next.11", ngImport: i0, type: ServiceWorkerModule });
425
- ServiceWorkerModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.0-next.11", ngImport: i0, type: ServiceWorkerModule, providers: [SwPush, SwUpdate] });
426
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0-next.11", ngImport: i0, type: ServiceWorkerModule, decorators: [{
454
+ ServiceWorkerModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0-next.15", ngImport: i0, type: ServiceWorkerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
455
+ ServiceWorkerModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.0-next.15", ngImport: i0, type: ServiceWorkerModule });
456
+ ServiceWorkerModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.0-next.15", ngImport: i0, type: ServiceWorkerModule, providers: [SwPush, SwUpdate] });
457
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0-next.15", ngImport: i0, type: ServiceWorkerModule, decorators: [{
427
458
  type: NgModule,
428
459
  args: [{
429
460
  providers: [SwPush, SwUpdate],
@@ -1 +1 @@
1
- {"version":3,"file":"service-worker.mjs","sources":["../../../../../../packages/service-worker/src/low_level.ts","../../../../../../packages/service-worker/src/push.ts","../../../../../../packages/service-worker/src/update.ts","../../../../../../packages/service-worker/src/module.ts","../../../../../../packages/service-worker/src/index.ts","../../../../../../packages/service-worker/public_api.ts","../../../../../../packages/service-worker/index.ts","../../../../../../packages/service-worker/service-worker.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {concat, ConnectableObservable, defer, fromEvent, Observable, of, throwError} from 'rxjs';\nimport {filter, map, publish, switchMap, take, tap} from 'rxjs/operators';\n\nexport const ERR_SW_NOT_SUPPORTED = 'Service workers are disabled or not supported by this browser';\n\n/**\n * An event emitted when a new version of the app is available.\n *\n * @see {@link guide/service-worker-communications Service worker communication guide}\n *\n * @publicApi\n */\nexport interface UpdateAvailableEvent {\n type: 'UPDATE_AVAILABLE';\n current: {hash: string, appData?: Object};\n available: {hash: string, appData?: Object};\n}\n\n/**\n * An event emitted when a new version of the app has been downloaded and activated.\n *\n * @see {@link guide/service-worker-communications Service worker communication guide}\n *\n * @publicApi\n */\nexport interface UpdateActivatedEvent {\n type: 'UPDATE_ACTIVATED';\n previous?: {hash: string, appData?: Object};\n current: {hash: string, appData?: Object};\n}\n\n/**\n * An event emitted when the version of the app used by the service worker to serve this client is\n * in a broken state that cannot be recovered from and a full page reload is required.\n *\n * For example, the service worker may not be able to retrieve a required resource, neither from the\n * cache nor from the server. This could happen if a new version is deployed to the server and the\n * service worker cache has been partially cleaned by the browser, removing some files of a previous\n * app version but not all.\n *\n * @see {@link guide/service-worker-communications Service worker communication guide}\n *\n * @publicApi\n */\nexport interface UnrecoverableStateEvent {\n type: 'UNRECOVERABLE_STATE';\n reason: string;\n}\n\n/**\n * An event emitted when a `PushEvent` is received by the service worker.\n */\nexport interface PushEvent {\n type: 'PUSH';\n data: any;\n}\n\nexport type IncomingEvent = UpdateAvailableEvent|UpdateActivatedEvent|UnrecoverableStateEvent;\n\nexport interface TypedEvent {\n type: string;\n}\n\ninterface StatusEvent {\n type: 'STATUS';\n nonce: number;\n status: boolean;\n error?: string;\n}\n\n\nfunction errorObservable(message: string): Observable<any> {\n return defer(() => throwError(new Error(message)));\n}\n\n/**\n * @publicApi\n */\nexport class NgswCommChannel {\n readonly worker: Observable<ServiceWorker>;\n\n readonly registration: Observable<ServiceWorkerRegistration>;\n\n readonly events: Observable<TypedEvent>;\n\n constructor(private serviceWorker: ServiceWorkerContainer|undefined) {\n if (!serviceWorker) {\n this.worker = this.events = this.registration = errorObservable(ERR_SW_NOT_SUPPORTED);\n } else {\n const controllerChangeEvents = fromEvent(serviceWorker, 'controllerchange');\n const controllerChanges = controllerChangeEvents.pipe(map(() => serviceWorker.controller));\n const currentController = defer(() => of(serviceWorker.controller));\n const controllerWithChanges = concat(currentController, controllerChanges);\n\n this.worker = controllerWithChanges.pipe(filter((c): c is ServiceWorker => !!c));\n\n this.registration = <Observable<ServiceWorkerRegistration>>(\n this.worker.pipe(switchMap(() => serviceWorker.getRegistration())));\n\n const rawEvents = fromEvent<MessageEvent>(serviceWorker, 'message');\n const rawEventPayload = rawEvents.pipe(map(event => event.data));\n const eventsUnconnected = rawEventPayload.pipe(filter(event => event && event.type));\n const events = eventsUnconnected.pipe(publish()) as ConnectableObservable<IncomingEvent>;\n events.connect();\n\n this.events = events;\n }\n }\n\n postMessage(action: string, payload: Object): Promise<void> {\n return this.worker\n .pipe(take(1), tap((sw: ServiceWorker) => {\n sw.postMessage({\n action,\n ...payload,\n });\n }))\n .toPromise()\n .then(() => undefined);\n }\n\n postMessageWithStatus(type: string, payload: Object, nonce: number): Promise<void> {\n const waitForStatus = this.waitForStatus(nonce);\n const postMessage = this.postMessage(type, payload);\n return Promise.all([waitForStatus, postMessage]).then(() => undefined);\n }\n\n generateNonce(): number {\n return Math.round(Math.random() * 10000000);\n }\n\n eventsOfType<T extends TypedEvent>(type: T['type']): Observable<T> {\n const filterFn = (event: TypedEvent): event is T => event.type === type;\n return this.events.pipe(filter(filterFn));\n }\n\n nextEventOfType<T extends TypedEvent>(type: T['type']): Observable<T> {\n return this.eventsOfType(type).pipe(take(1));\n }\n\n waitForStatus(nonce: number): Promise<void> {\n return this.eventsOfType<StatusEvent>('STATUS')\n .pipe(filter(event => event.nonce === nonce), take(1), map(event => {\n if (event.status) {\n return undefined;\n }\n throw new Error(event.error!);\n }))\n .toPromise();\n }\n\n get isEnabled(): boolean {\n return !!this.serviceWorker;\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {Injectable} from '@angular/core';\nimport {merge, NEVER, Observable, Subject} from 'rxjs';\nimport {map, switchMap, take} from 'rxjs/operators';\n\nimport {ERR_SW_NOT_SUPPORTED, NgswCommChannel, PushEvent} from './low_level';\n\n\n/**\n * Subscribe and listen to\n * [Web Push\n * Notifications](https://developer.mozilla.org/en-US/docs/Web/API/Push_API/Best_Practices) through\n * Angular Service Worker.\n *\n * @usageNotes\n *\n * You can inject a `SwPush` instance into any component or service\n * as a dependency.\n *\n * <code-example path=\"service-worker/push/module.ts\" region=\"inject-sw-push\"\n * header=\"app.component.ts\"></code-example>\n *\n * To subscribe, call `SwPush.requestSubscription()`, which asks the user for permission.\n * The call returns a `Promise` with a new\n * [`PushSubscription`](https://developer.mozilla.org/en-US/docs/Web/API/PushSubscription)\n * instance.\n *\n * <code-example path=\"service-worker/push/module.ts\" region=\"subscribe-to-push\"\n * header=\"app.component.ts\"></code-example>\n *\n * A request is rejected if the user denies permission, or if the browser\n * blocks or does not support the Push API or ServiceWorkers.\n * Check `SwPush.isEnabled` to confirm status.\n *\n * Invoke Push Notifications by pushing a message with the following payload.\n *\n * ```ts\n * {\n * \"notification\": {\n * \"actions\": NotificationAction[],\n * \"badge\": USVString,\n * \"body\": DOMString,\n * \"data\": any,\n * \"dir\": \"auto\"|\"ltr\"|\"rtl\",\n * \"icon\": USVString,\n * \"image\": USVString,\n * \"lang\": DOMString,\n * \"renotify\": boolean,\n * \"requireInteraction\": boolean,\n * \"silent\": boolean,\n * \"tag\": DOMString,\n * \"timestamp\": DOMTimeStamp,\n * \"title\": DOMString,\n * \"vibrate\": number[]\n * }\n * }\n * ```\n *\n * Only `title` is required. See `Notification`\n * [instance\n * properties](https://developer.mozilla.org/en-US/docs/Web/API/Notification#Instance_properties).\n *\n * While the subscription is active, Service Worker listens for\n * [PushEvent](https://developer.mozilla.org/en-US/docs/Web/API/PushEvent)\n * occurrences and creates\n * [Notification](https://developer.mozilla.org/en-US/docs/Web/API/Notification)\n * instances in response.\n *\n * Unsubscribe using `SwPush.unsubscribe()`.\n *\n * An application can subscribe to `SwPush.notificationClicks` observable to be notified when a user\n * clicks on a notification. For example:\n *\n * <code-example path=\"service-worker/push/module.ts\" region=\"subscribe-to-notification-clicks\"\n * header=\"app.component.ts\"></code-example>\n *\n * You can read more on handling notification clicks in the [Service worker notifications\n * guide](guide/service-worker-notifications).\n *\n * @see [Push Notifications](https://developers.google.com/web/fundamentals/codelabs/push-notifications/)\n * @see [Angular Push Notifications](https://blog.angular-university.io/angular-push-notifications/)\n * @see [MDN: Push API](https://developer.mozilla.org/en-US/docs/Web/API/Push_API)\n * @see [MDN: Notifications API](https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API)\n * @see [MDN: Web Push API Notifications best practices](https://developer.mozilla.org/en-US/docs/Web/API/Push_API/Best_Practices)\n *\n * @publicApi\n */\n@Injectable()\nexport class SwPush {\n /**\n * Emits the payloads of the received push notification messages.\n */\n readonly messages: Observable<object>;\n\n /**\n * Emits the payloads of the received push notification messages as well as the action the user\n * interacted with. If no action was used the `action` property contains an empty string `''`.\n *\n * Note that the `notification` property does **not** contain a\n * [Notification][Mozilla Notification] object but rather a\n * [NotificationOptions](https://notifications.spec.whatwg.org/#dictdef-notificationoptions)\n * object that also includes the `title` of the [Notification][Mozilla Notification] object.\n *\n * [Mozilla Notification]: https://developer.mozilla.org/en-US/docs/Web/API/Notification\n */\n readonly notificationClicks: Observable<{\n action: string; notification: NotificationOptions &\n {\n title: string\n }\n }>;\n\n /**\n * Emits the currently active\n * [PushSubscription](https://developer.mozilla.org/en-US/docs/Web/API/PushSubscription)\n * associated to the Service Worker registration or `null` if there is no subscription.\n */\n readonly subscription: Observable<PushSubscription|null>;\n\n /**\n * True if the Service Worker is enabled (supported by the browser and enabled via\n * `ServiceWorkerModule`).\n */\n get isEnabled(): boolean {\n return this.sw.isEnabled;\n }\n\n // TODO(issue/24571): remove '!'.\n private pushManager!: Observable<PushManager>;\n private subscriptionChanges = new Subject<PushSubscription|null>();\n\n constructor(private sw: NgswCommChannel) {\n if (!sw.isEnabled) {\n this.messages = NEVER;\n this.notificationClicks = NEVER;\n this.subscription = NEVER;\n return;\n }\n\n this.messages = this.sw.eventsOfType<PushEvent>('PUSH').pipe(map(message => message.data));\n\n this.notificationClicks =\n this.sw.eventsOfType('NOTIFICATION_CLICK').pipe(map((message: any) => message.data));\n\n this.pushManager = this.sw.registration.pipe(map(registration => registration.pushManager));\n\n const workerDrivenSubscriptions = this.pushManager.pipe(switchMap(pm => pm.getSubscription()));\n this.subscription = merge(workerDrivenSubscriptions, this.subscriptionChanges);\n }\n\n /**\n * Subscribes to Web Push Notifications,\n * after requesting and receiving user permission.\n *\n * @param options An object containing the `serverPublicKey` string.\n * @returns A Promise that resolves to the new subscription object.\n */\n requestSubscription(options: {serverPublicKey: string}): Promise<PushSubscription> {\n if (!this.sw.isEnabled) {\n return Promise.reject(new Error(ERR_SW_NOT_SUPPORTED));\n }\n const pushOptions: PushSubscriptionOptionsInit = {userVisibleOnly: true};\n let key = this.decodeBase64(options.serverPublicKey.replace(/_/g, '/').replace(/-/g, '+'));\n let applicationServerKey = new Uint8Array(new ArrayBuffer(key.length));\n for (let i = 0; i < key.length; i++) {\n applicationServerKey[i] = key.charCodeAt(i);\n }\n pushOptions.applicationServerKey = applicationServerKey;\n\n return this.pushManager.pipe(switchMap(pm => pm.subscribe(pushOptions)), take(1))\n .toPromise()\n .then(sub => {\n this.subscriptionChanges.next(sub);\n return sub;\n });\n }\n\n /**\n * Unsubscribes from Service Worker push notifications.\n *\n * @returns A Promise that is resolved when the operation succeeds, or is rejected if there is no\n * active subscription or the unsubscribe operation fails.\n */\n unsubscribe(): Promise<void> {\n if (!this.sw.isEnabled) {\n return Promise.reject(new Error(ERR_SW_NOT_SUPPORTED));\n }\n\n const doUnsubscribe = (sub: PushSubscription|null) => {\n if (sub === null) {\n throw new Error('Not subscribed to push notifications.');\n }\n\n return sub.unsubscribe().then(success => {\n if (!success) {\n throw new Error('Unsubscribe failed!');\n }\n\n this.subscriptionChanges.next(null);\n });\n };\n\n return this.subscription.pipe(take(1), switchMap(doUnsubscribe)).toPromise();\n }\n\n private decodeBase64(input: string): string {\n return atob(input);\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {Injectable} from '@angular/core';\nimport {NEVER, Observable} from 'rxjs';\n\nimport {ERR_SW_NOT_SUPPORTED, NgswCommChannel, UnrecoverableStateEvent, UpdateActivatedEvent, UpdateAvailableEvent} from './low_level';\n\n\n\n/**\n * Subscribe to update notifications from the Service Worker, trigger update\n * checks, and forcibly activate updates.\n *\n * @see {@link guide/service-worker-communications Service worker communication guide}\n *\n * @publicApi\n */\n@Injectable()\nexport class SwUpdate {\n /**\n * Emits an `UpdateAvailableEvent` event whenever a new app version is available.\n */\n readonly available: Observable<UpdateAvailableEvent>;\n\n /**\n * Emits an `UpdateActivatedEvent` event whenever the app has been updated to a new version.\n */\n readonly activated: Observable<UpdateActivatedEvent>;\n\n /**\n * Emits an `UnrecoverableStateEvent` event whenever the version of the app used by the service\n * worker to serve this client is in a broken state that cannot be recovered from without a full\n * page reload.\n */\n readonly unrecoverable: Observable<UnrecoverableStateEvent>;\n\n /**\n * True if the Service Worker is enabled (supported by the browser and enabled via\n * `ServiceWorkerModule`).\n */\n get isEnabled(): boolean {\n return this.sw.isEnabled;\n }\n\n constructor(private sw: NgswCommChannel) {\n if (!sw.isEnabled) {\n this.available = NEVER;\n this.activated = NEVER;\n this.unrecoverable = NEVER;\n return;\n }\n this.available = this.sw.eventsOfType<UpdateAvailableEvent>('UPDATE_AVAILABLE');\n this.activated = this.sw.eventsOfType<UpdateActivatedEvent>('UPDATE_ACTIVATED');\n this.unrecoverable = this.sw.eventsOfType<UnrecoverableStateEvent>('UNRECOVERABLE_STATE');\n }\n\n checkForUpdate(): Promise<void> {\n if (!this.sw.isEnabled) {\n return Promise.reject(new Error(ERR_SW_NOT_SUPPORTED));\n }\n const statusNonce = this.sw.generateNonce();\n return this.sw.postMessageWithStatus('CHECK_FOR_UPDATES', {statusNonce}, statusNonce);\n }\n\n activateUpdate(): Promise<void> {\n if (!this.sw.isEnabled) {\n return Promise.reject(new Error(ERR_SW_NOT_SUPPORTED));\n }\n const statusNonce = this.sw.generateNonce();\n return this.sw.postMessageWithStatus('ACTIVATE_UPDATE', {statusNonce}, statusNonce);\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {isPlatformBrowser} from '@angular/common';\nimport {APP_INITIALIZER, ApplicationRef, InjectionToken, Injector, ModuleWithProviders, NgModule, NgZone, PLATFORM_ID} from '@angular/core';\nimport {merge, Observable, of} from 'rxjs';\nimport {delay, filter, take} from 'rxjs/operators';\n\nimport {NgswCommChannel} from './low_level';\nimport {SwPush} from './push';\nimport {SwUpdate} from './update';\n\n/**\n * Token that can be used to provide options for `ServiceWorkerModule` outside of\n * `ServiceWorkerModule.register()`.\n *\n * You can use this token to define a provider that generates the registration options at runtime,\n * for example via a function call:\n *\n * {@example service-worker/registration-options/module.ts region=\"registration-options\"\n * header=\"app.module.ts\"}\n *\n * @publicApi\n */\nexport abstract class SwRegistrationOptions {\n /**\n * Whether the ServiceWorker will be registered and the related services (such as `SwPush` and\n * `SwUpdate`) will attempt to communicate and interact with it.\n *\n * Default: true\n */\n enabled?: boolean;\n\n /**\n * A URL that defines the ServiceWorker's registration scope; that is, what range of URLs it can\n * control. It will be used when calling\n * [ServiceWorkerContainer#register()](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register).\n */\n scope?: string;\n\n /**\n * Defines the ServiceWorker registration strategy, which determines when it will be registered\n * with the browser.\n *\n * The default behavior of registering once the application stabilizes (i.e. as soon as there are\n * no pending micro- and macro-tasks) is designed to register the ServiceWorker as soon as\n * possible but without affecting the application's first time load.\n *\n * Still, there might be cases where you want more control over when the ServiceWorker is\n * registered (for example, there might be a long-running timeout or polling interval, preventing\n * the app from stabilizing). The available option are:\n *\n * - `registerWhenStable:<timeout>`: Register as soon as the application stabilizes (no pending\n * micro-/macro-tasks) but no later than `<timeout>` milliseconds. If the app hasn't\n * stabilized after `<timeout>` milliseconds (for example, due to a recurrent asynchronous\n * task), the ServiceWorker will be registered anyway.\n * If `<timeout>` is omitted, the ServiceWorker will only be registered once the app\n * stabilizes.\n * - `registerImmediately`: Register immediately.\n * - `registerWithDelay:<timeout>`: Register with a delay of `<timeout>` milliseconds. For\n * example, use `registerWithDelay:5000` to register the ServiceWorker after 5 seconds. If\n * `<timeout>` is omitted, is defaults to `0`, which will register the ServiceWorker as soon\n * as possible but still asynchronously, once all pending micro-tasks are completed.\n * - An [Observable](guide/observables) factory function: A function that returns an `Observable`.\n * The function will be used at runtime to obtain and subscribe to the `Observable` and the\n * ServiceWorker will be registered as soon as the first value is emitted.\n *\n * Default: 'registerWhenStable:30000'\n */\n registrationStrategy?: string|(() => Observable<unknown>);\n}\n\nexport const SCRIPT = new InjectionToken<string>('NGSW_REGISTER_SCRIPT');\n\nexport function ngswAppInitializer(\n injector: Injector, script: string, options: SwRegistrationOptions,\n platformId: string): Function {\n const initializer = () => {\n if (!(isPlatformBrowser(platformId) && ('serviceWorker' in navigator) &&\n options.enabled !== false)) {\n return;\n }\n\n // Wait for service worker controller changes, and fire an INITIALIZE action when a new SW\n // becomes active. This allows the SW to initialize itself even if there is no application\n // traffic.\n navigator.serviceWorker.addEventListener('controllerchange', () => {\n if (navigator.serviceWorker.controller !== null) {\n navigator.serviceWorker.controller.postMessage({action: 'INITIALIZE'});\n }\n });\n\n let readyToRegister$: Observable<unknown>;\n\n if (typeof options.registrationStrategy === 'function') {\n readyToRegister$ = options.registrationStrategy();\n } else {\n const [strategy, ...args] =\n (options.registrationStrategy || 'registerWhenStable:30000').split(':');\n\n switch (strategy) {\n case 'registerImmediately':\n readyToRegister$ = of(null);\n break;\n case 'registerWithDelay':\n readyToRegister$ = delayWithTimeout(+args[0] || 0);\n break;\n case 'registerWhenStable':\n readyToRegister$ = !args[0] ? whenStable(injector) :\n merge(whenStable(injector), delayWithTimeout(+args[0]));\n break;\n default:\n // Unknown strategy.\n throw new Error(\n `Unknown ServiceWorker registration strategy: ${options.registrationStrategy}`);\n }\n }\n\n // Don't return anything to avoid blocking the application until the SW is registered.\n // Also, run outside the Angular zone to avoid preventing the app from stabilizing (especially\n // given that some registration strategies wait for the app to stabilize).\n // Catch and log the error if SW registration fails to avoid uncaught rejection warning.\n const ngZone = injector.get(NgZone);\n ngZone.runOutsideAngular(\n () => readyToRegister$.pipe(take(1)).subscribe(\n () =>\n navigator.serviceWorker.register(script, {scope: options.scope})\n .catch(err => console.error('Service worker registration failed with:', err))));\n };\n return initializer;\n}\n\nfunction delayWithTimeout(timeout: number): Observable<unknown> {\n return of(null).pipe(delay(timeout));\n}\n\nfunction whenStable(injector: Injector): Observable<unknown> {\n const appRef = injector.get(ApplicationRef);\n return appRef.isStable.pipe(filter(stable => stable));\n}\n\nexport function ngswCommChannelFactory(\n opts: SwRegistrationOptions, platformId: string): NgswCommChannel {\n return new NgswCommChannel(\n isPlatformBrowser(platformId) && opts.enabled !== false ? navigator.serviceWorker :\n undefined);\n}\n\n/**\n * @publicApi\n */\n@NgModule({\n providers: [SwPush, SwUpdate],\n})\nexport class ServiceWorkerModule {\n /**\n * Register the given Angular Service Worker script.\n *\n * If `enabled` is set to `false` in the given options, the module will behave as if service\n * workers are not supported by the browser, and the service worker will not be registered.\n */\n static register(script: string, opts: SwRegistrationOptions = {}):\n ModuleWithProviders<ServiceWorkerModule> {\n return {\n ngModule: ServiceWorkerModule,\n providers: [\n {provide: SCRIPT, useValue: script},\n {provide: SwRegistrationOptions, useValue: opts},\n {\n provide: NgswCommChannel,\n useFactory: ngswCommChannelFactory,\n deps: [SwRegistrationOptions, PLATFORM_ID]\n },\n {\n provide: APP_INITIALIZER,\n useFactory: ngswAppInitializer,\n deps: [Injector, SCRIPT, SwRegistrationOptions, PLATFORM_ID],\n multi: true,\n },\n ],\n };\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\n/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nexport {UnrecoverableStateEvent, UpdateActivatedEvent, UpdateAvailableEvent} from './low_level';\nexport {ServiceWorkerModule, SwRegistrationOptions} from './module';\nexport {SwPush} from './push';\nexport {SwUpdate} from './update';\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\n/**\n * @module\n * @description\n * Entry point for all public APIs of this package.\n */\nexport * from './src/index';\n\n// This file only reexports content of the `src` folder. Keep it that way.\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\n// This file is not used to build this module. It is only used during editing\n// by the TypeScript language service and during build for verification. `ngc`\n// replaces this file with production index.ts when it rewrites private symbol\n// names.\n\nexport * from './public_api';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;AAWO,MAAM,oBAAoB,GAAG,+DAA+D,CAAC;AAoEpG,SAAS,eAAe,CAAC,OAAe;IACtC,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACrD,CAAC;AAED;;;MAGa,eAAe;IAO1B,YAAoB,aAA+C;QAA/C,kBAAa,GAAb,aAAa,CAAkC;QACjE,IAAI,CAAC,aAAa,EAAE;YAClB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,GAAG,eAAe,CAAC,oBAAoB,CAAC,CAAC;SACvF;aAAM;YACL,MAAM,sBAAsB,GAAG,SAAS,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC;YAC5E,MAAM,iBAAiB,GAAG,sBAAsB,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC;YAC3F,MAAM,iBAAiB,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC;YACpE,MAAM,qBAAqB,GAAG,MAAM,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;YAE3E,IAAI,CAAC,MAAM,GAAG,qBAAqB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAyB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAEjF,IAA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AM,CAAC,MAAM,IAAI,MAAM,CAAC,CAAC,CAAC;AACxD,CAAC;SAEe,sBAAsB,CAClC,IAA2B,EAAE,UAAkB;IACjD,OAAO,IAAI,eAAe,CACtB,iBAAiB,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,OAAO,KAAK,KAAK,GAAG,SAAS,CAAC,aAAa;QACvB,SAAS,CAAC,CAAC;AAC3E,CAAC;AAED;;;MAMa,mBAAmB;;;;;;;IAO9B,OAAO,QAAQ,CAAC,MAAc,EAAE,OAA8B,EAAE;QAE9D,OAAO;YACL,QAAQ,EAAE,mBAAmB;YAC7B,SAAS,EAAE;gBACT,EAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAC;gBACnC,EAAC,OAAO,EAAE,qBAAqB,EAAE,QAAQ,EAAE,IAAI,EAAC;gBAChD;oBACE,OAAO,EAAE,eAAe;oBACxB,UAAU,EAAE,sBAAsB;oBAClC,IAAI,EAAE,CAAC,qBAAqB,EAAE,WAAW,CAAC;iBAC3C;gBACD;oBACE,OAAO,EAAE,eAAe;oBACxB,UAAU,EAAE,kBAAkB;oBAC9B,IAAI,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,qBAAqB,EAAE,WAAW,CAAC;oBAC5D,KAAK,EAAE,IAAI;iBACZ;aACF;SACF,CAAC;KACH;;2HA3BU,mBAAmB;4HAAnB,mBAAmB;4HAAnB,mBAAmB,aAFnB,CAAC,MAAM,EAAE,QAAQ,CAAC;sGAElB,mBAAmB;kBAH/B,QAAQ;mBAAC;oBACR,SAAS,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC;iBAC9B;;;AC9JD;;;;;;;;ACAA;;;;;;;AAeA;;ACfA;;;;;;;;ACAA;;;;;;"}
1
+ {"version":3,"file":"service-worker.mjs","sources":["../../../../../../packages/service-worker/src/low_level.ts","../../../../../../packages/service-worker/src/push.ts","../../../../../../packages/service-worker/src/update.ts","../../../../../../packages/service-worker/src/module.ts","../../../../../../packages/service-worker/src/index.ts","../../../../../../packages/service-worker/public_api.ts","../../../../../../packages/service-worker/index.ts","../../../../../../packages/service-worker/service-worker.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {concat, ConnectableObservable, defer, fromEvent, Observable, of, throwError} from 'rxjs';\nimport {filter, map, publish, switchMap, take, tap} from 'rxjs/operators';\n\nexport const ERR_SW_NOT_SUPPORTED = 'Service workers are disabled or not supported by this browser';\n\n/**\n * An event emitted when a new version of the app is available.\n *\n * @see {@link guide/service-worker-communications Service worker communication guide}\n *\n * @deprecated\n * This event is only emitted by the deprecated {@link SwUpdate#available}.\n * Use the {@link VersionReadyEvent} instead, which is emitted by {@link SwUpdate#versionUpdates}.\n * See {@link SwUpdate#available} docs for an example.\n *\n * @publicApi\n */\nexport interface UpdateAvailableEvent {\n type: 'UPDATE_AVAILABLE';\n current: {hash: string, appData?: Object};\n available: {hash: string, appData?: Object};\n}\n\n/**\n * An event emitted when a new version of the app has been downloaded and activated.\n *\n * @see {@link guide/service-worker-communications Service worker communication guide}\n *\n * @deprecated\n * This event is only emitted by the deprecated {@link SwUpdate#activated}.\n * Use the return value of {@link SwUpdate#activateUpdate} instead.\n *\n * @publicApi\n */\nexport interface UpdateActivatedEvent {\n type: 'UPDATE_ACTIVATED';\n previous?: {hash: string, appData?: Object};\n current: {hash: string, appData?: Object};\n}\n\n/**\n * An event emitted when the service worker has detected a new version of the app on the server and\n * is about to start downloading it.\n *\n * @see {@link guide/service-worker-communications Service worker communication guide}\n *\n * @publicApi\n */\nexport interface VersionDetectedEvent {\n type: 'VERSION_DETECTED';\n version: {hash: string; appData?: object;};\n}\n\n/**\n * An event emitted when the installation of a new version failed.\n * It may be used for logging/monitoring purposes.\n *\n * @see {@link guide/service-worker-communications Service worker communication guide}\n *\n * @publicApi\n */\nexport interface VersionInstallationFailedEvent {\n type: 'VERSION_INSTALLATION_FAILED';\n version: {hash: string; appData?: object;};\n error: string;\n}\n\n/**\n * An event emitted when a new version of the app is available.\n *\n * @see {@link guide/service-worker-communications Service worker communication guide}\n *\n * @publicApi\n */\nexport interface VersionReadyEvent {\n type: 'VERSION_READY';\n currentVersion: {hash: string; appData?: object;};\n latestVersion: {hash: string; appData?: object;};\n}\n\n\n/**\n * A union of all event types that can be emitted by\n * {@link api/service-worker/SwUpdate#versionUpdates SwUpdate#versionUpdates}.\n *\n * @publicApi\n */\nexport type VersionEvent = VersionDetectedEvent|VersionInstallationFailedEvent|VersionReadyEvent;\n\n/**\n * An event emitted when the version of the app used by the service worker to serve this client is\n * in a broken state that cannot be recovered from and a full page reload is required.\n *\n * For example, the service worker may not be able to retrieve a required resource, neither from the\n * cache nor from the server. This could happen if a new version is deployed to the server and the\n * service worker cache has been partially cleaned by the browser, removing some files of a previous\n * app version but not all.\n *\n * @see {@link guide/service-worker-communications Service worker communication guide}\n *\n * @publicApi\n */\nexport interface UnrecoverableStateEvent {\n type: 'UNRECOVERABLE_STATE';\n reason: string;\n}\n\n/**\n * An event emitted when a `PushEvent` is received by the service worker.\n */\nexport interface PushEvent {\n type: 'PUSH';\n data: any;\n}\n\nexport type IncomingEvent = UpdateActivatedEvent|UnrecoverableStateEvent|VersionEvent;\n\nexport interface TypedEvent {\n type: string;\n}\n\ntype OperationCompletedEvent = {\n type: 'OPERATION_COMPLETED'; nonce: number; result: boolean;\n}|{\n type: 'OPERATION_COMPLETED';\n nonce: number;\n result?: undefined;\n error: string;\n};\n\n\nfunction errorObservable(message: string): Observable<any> {\n return defer(() => throwError(new Error(message)));\n}\n\n/**\n * @publicApi\n */\nexport class NgswCommChannel {\n readonly worker: Observable<ServiceWorker>;\n\n readonly registration: Observable<ServiceWorkerRegistration>;\n\n readonly events: Observable<TypedEvent>;\n\n constructor(private serviceWorker: ServiceWorkerContainer|undefined) {\n if (!serviceWorker) {\n this.worker = this.events = this.registration = errorObservable(ERR_SW_NOT_SUPPORTED);\n } else {\n const controllerChangeEvents = fromEvent(serviceWorker, 'controllerchange');\n const controllerChanges = controllerChangeEvents.pipe(map(() => serviceWorker.controller));\n const currentController = defer(() => of(serviceWorker.controller));\n const controllerWithChanges = concat(currentController, controllerChanges);\n\n this.worker = controllerWithChanges.pipe(filter((c): c is ServiceWorker => !!c));\n\n this.registration = <Observable<ServiceWorkerRegistration>>(\n this.worker.pipe(switchMap(() => serviceWorker.getRegistration())));\n\n const rawEvents = fromEvent<MessageEvent>(serviceWorker, 'message');\n const rawEventPayload = rawEvents.pipe(map(event => event.data));\n const eventsUnconnected = rawEventPayload.pipe(filter(event => event && event.type));\n const events = eventsUnconnected.pipe(publish()) as ConnectableObservable<IncomingEvent>;\n events.connect();\n\n this.events = events;\n }\n }\n\n postMessage(action: string, payload: Object): Promise<void> {\n return this.worker\n .pipe(take(1), tap((sw: ServiceWorker) => {\n sw.postMessage({\n action,\n ...payload,\n });\n }))\n .toPromise()\n .then(() => undefined);\n }\n\n postMessageWithOperation(type: string, payload: Object, operationNonce: number):\n Promise<boolean> {\n const waitForOperationCompleted = this.waitForOperationCompleted(operationNonce);\n const postMessage = this.postMessage(type, payload);\n return Promise.all([postMessage, waitForOperationCompleted]).then(([, result]) => result);\n }\n\n generateNonce(): number {\n return Math.round(Math.random() * 10000000);\n }\n\n eventsOfType<T extends TypedEvent>(type: T['type']|T['type'][]): Observable<T> {\n let filterFn: (event: TypedEvent) => event is T;\n if (typeof type === 'string') {\n filterFn = (event: TypedEvent): event is T => event.type === type;\n } else {\n filterFn = (event: TypedEvent): event is T => type.includes(event.type);\n }\n return this.events.pipe(filter(filterFn));\n }\n\n nextEventOfType<T extends TypedEvent>(type: T['type']): Observable<T> {\n return this.eventsOfType(type).pipe(take(1));\n }\n\n waitForOperationCompleted(nonce: number): Promise<boolean> {\n return this.eventsOfType<OperationCompletedEvent>('OPERATION_COMPLETED')\n .pipe(filter(event => event.nonce === nonce), take(1), map(event => {\n if (event.result !== undefined) {\n return event.result;\n }\n throw new Error(event.error!);\n }))\n .toPromise();\n }\n\n get isEnabled(): boolean {\n return !!this.serviceWorker;\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {Injectable} from '@angular/core';\nimport {merge, NEVER, Observable, Subject} from 'rxjs';\nimport {map, switchMap, take} from 'rxjs/operators';\n\nimport {ERR_SW_NOT_SUPPORTED, NgswCommChannel, PushEvent} from './low_level';\n\n\n/**\n * Subscribe and listen to\n * [Web Push\n * Notifications](https://developer.mozilla.org/en-US/docs/Web/API/Push_API/Best_Practices) through\n * Angular Service Worker.\n *\n * @usageNotes\n *\n * You can inject a `SwPush` instance into any component or service\n * as a dependency.\n *\n * <code-example path=\"service-worker/push/module.ts\" region=\"inject-sw-push\"\n * header=\"app.component.ts\"></code-example>\n *\n * To subscribe, call `SwPush.requestSubscription()`, which asks the user for permission.\n * The call returns a `Promise` with a new\n * [`PushSubscription`](https://developer.mozilla.org/en-US/docs/Web/API/PushSubscription)\n * instance.\n *\n * <code-example path=\"service-worker/push/module.ts\" region=\"subscribe-to-push\"\n * header=\"app.component.ts\"></code-example>\n *\n * A request is rejected if the user denies permission, or if the browser\n * blocks or does not support the Push API or ServiceWorkers.\n * Check `SwPush.isEnabled` to confirm status.\n *\n * Invoke Push Notifications by pushing a message with the following payload.\n *\n * ```ts\n * {\n * \"notification\": {\n * \"actions\": NotificationAction[],\n * \"badge\": USVString,\n * \"body\": DOMString,\n * \"data\": any,\n * \"dir\": \"auto\"|\"ltr\"|\"rtl\",\n * \"icon\": USVString,\n * \"image\": USVString,\n * \"lang\": DOMString,\n * \"renotify\": boolean,\n * \"requireInteraction\": boolean,\n * \"silent\": boolean,\n * \"tag\": DOMString,\n * \"timestamp\": DOMTimeStamp,\n * \"title\": DOMString,\n * \"vibrate\": number[]\n * }\n * }\n * ```\n *\n * Only `title` is required. See `Notification`\n * [instance\n * properties](https://developer.mozilla.org/en-US/docs/Web/API/Notification#Instance_properties).\n *\n * While the subscription is active, Service Worker listens for\n * [PushEvent](https://developer.mozilla.org/en-US/docs/Web/API/PushEvent)\n * occurrences and creates\n * [Notification](https://developer.mozilla.org/en-US/docs/Web/API/Notification)\n * instances in response.\n *\n * Unsubscribe using `SwPush.unsubscribe()`.\n *\n * An application can subscribe to `SwPush.notificationClicks` observable to be notified when a user\n * clicks on a notification. For example:\n *\n * <code-example path=\"service-worker/push/module.ts\" region=\"subscribe-to-notification-clicks\"\n * header=\"app.component.ts\"></code-example>\n *\n * You can read more on handling notification clicks in the [Service worker notifications\n * guide](guide/service-worker-notifications).\n *\n * @see [Push Notifications](https://developers.google.com/web/fundamentals/codelabs/push-notifications/)\n * @see [Angular Push Notifications](https://blog.angular-university.io/angular-push-notifications/)\n * @see [MDN: Push API](https://developer.mozilla.org/en-US/docs/Web/API/Push_API)\n * @see [MDN: Notifications API](https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API)\n * @see [MDN: Web Push API Notifications best practices](https://developer.mozilla.org/en-US/docs/Web/API/Push_API/Best_Practices)\n *\n * @publicApi\n */\n@Injectable()\nexport class SwPush {\n /**\n * Emits the payloads of the received push notification messages.\n */\n readonly messages: Observable<object>;\n\n /**\n * Emits the payloads of the received push notification messages as well as the action the user\n * interacted with. If no action was used the `action` property contains an empty string `''`.\n *\n * Note that the `notification` property does **not** contain a\n * [Notification][Mozilla Notification] object but rather a\n * [NotificationOptions](https://notifications.spec.whatwg.org/#dictdef-notificationoptions)\n * object that also includes the `title` of the [Notification][Mozilla Notification] object.\n *\n * [Mozilla Notification]: https://developer.mozilla.org/en-US/docs/Web/API/Notification\n */\n readonly notificationClicks: Observable<{\n action: string; notification: NotificationOptions &\n {\n title: string\n }\n }>;\n\n /**\n * Emits the currently active\n * [PushSubscription](https://developer.mozilla.org/en-US/docs/Web/API/PushSubscription)\n * associated to the Service Worker registration or `null` if there is no subscription.\n */\n readonly subscription: Observable<PushSubscription|null>;\n\n /**\n * True if the Service Worker is enabled (supported by the browser and enabled via\n * `ServiceWorkerModule`).\n */\n get isEnabled(): boolean {\n return this.sw.isEnabled;\n }\n\n // TODO(issue/24571): remove '!'.\n private pushManager!: Observable<PushManager>;\n private subscriptionChanges = new Subject<PushSubscription|null>();\n\n constructor(private sw: NgswCommChannel) {\n if (!sw.isEnabled) {\n this.messages = NEVER;\n this.notificationClicks = NEVER;\n this.subscription = NEVER;\n return;\n }\n\n this.messages = this.sw.eventsOfType<PushEvent>('PUSH').pipe(map(message => message.data));\n\n this.notificationClicks =\n this.sw.eventsOfType('NOTIFICATION_CLICK').pipe(map((message: any) => message.data));\n\n this.pushManager = this.sw.registration.pipe(map(registration => registration.pushManager));\n\n const workerDrivenSubscriptions = this.pushManager.pipe(switchMap(pm => pm.getSubscription()));\n this.subscription = merge(workerDrivenSubscriptions, this.subscriptionChanges);\n }\n\n /**\n * Subscribes to Web Push Notifications,\n * after requesting and receiving user permission.\n *\n * @param options An object containing the `serverPublicKey` string.\n * @returns A Promise that resolves to the new subscription object.\n */\n requestSubscription(options: {serverPublicKey: string}): Promise<PushSubscription> {\n if (!this.sw.isEnabled) {\n return Promise.reject(new Error(ERR_SW_NOT_SUPPORTED));\n }\n const pushOptions: PushSubscriptionOptionsInit = {userVisibleOnly: true};\n let key = this.decodeBase64(options.serverPublicKey.replace(/_/g, '/').replace(/-/g, '+'));\n let applicationServerKey = new Uint8Array(new ArrayBuffer(key.length));\n for (let i = 0; i < key.length; i++) {\n applicationServerKey[i] = key.charCodeAt(i);\n }\n pushOptions.applicationServerKey = applicationServerKey;\n\n return this.pushManager.pipe(switchMap(pm => pm.subscribe(pushOptions)), take(1))\n .toPromise()\n .then(sub => {\n this.subscriptionChanges.next(sub);\n return sub;\n });\n }\n\n /**\n * Unsubscribes from Service Worker push notifications.\n *\n * @returns A Promise that is resolved when the operation succeeds, or is rejected if there is no\n * active subscription or the unsubscribe operation fails.\n */\n unsubscribe(): Promise<void> {\n if (!this.sw.isEnabled) {\n return Promise.reject(new Error(ERR_SW_NOT_SUPPORTED));\n }\n\n const doUnsubscribe = (sub: PushSubscription|null) => {\n if (sub === null) {\n throw new Error('Not subscribed to push notifications.');\n }\n\n return sub.unsubscribe().then(success => {\n if (!success) {\n throw new Error('Unsubscribe failed!');\n }\n\n this.subscriptionChanges.next(null);\n });\n };\n\n return this.subscription.pipe(take(1), switchMap(doUnsubscribe)).toPromise();\n }\n\n private decodeBase64(input: string): string {\n return atob(input);\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {Injectable} from '@angular/core';\nimport {NEVER, Observable} from 'rxjs';\nimport {filter, map} from 'rxjs/operators';\n\nimport {ERR_SW_NOT_SUPPORTED, NgswCommChannel, UnrecoverableStateEvent, UpdateActivatedEvent, UpdateAvailableEvent, VersionEvent, VersionReadyEvent} from './low_level';\n\n\n\n/**\n * Subscribe to update notifications from the Service Worker, trigger update\n * checks, and forcibly activate updates.\n *\n * @see {@link guide/service-worker-communications Service worker communication guide}\n *\n * @publicApi\n */\n@Injectable()\nexport class SwUpdate {\n /**\n * Emits a `VersionDetectedEvent` event whenever a new version is detected on the server.\n *\n * Emits a `VersionInstallationFailedEvent` event whenever checking for or downloading a new\n * version fails.\n *\n * Emits a `VersionReadyEvent` event whenever a new version has been downloaded and is ready for\n * activation.\n */\n readonly versionUpdates: Observable<VersionEvent>;\n\n /**\n * Emits an `UpdateAvailableEvent` event whenever a new app version is available.\n *\n * @deprecated Use {@link versionUpdates} instead.\n *\n * The of behavior `available` can be rebuild by filtering for the `VersionReadyEvent`:\n * ```\n * import {filter, map} from 'rxjs/operators';\n * // ...\n * const updatesAvailable = swUpdate.versionUpdates.pipe(\n * filter((evt): evt is VersionReadyEvent => evt.type === 'VERSION_READY'),\n * map(evt => ({\n * type: 'UPDATE_AVAILABLE',\n * current: evt.currentVersion,\n * available: evt.latestVersion,\n * })));\n * ```\n */\n readonly available: Observable<UpdateAvailableEvent>;\n\n /**\n * Emits an `UpdateActivatedEvent` event whenever the app has been updated to a new version.\n *\n * @deprecated Use the return value of {@link SwUpdate#activateUpdate} instead.\n *\n */\n readonly activated: Observable<UpdateActivatedEvent>;\n\n /**\n * Emits an `UnrecoverableStateEvent` event whenever the version of the app used by the service\n * worker to serve this client is in a broken state that cannot be recovered from without a full\n * page reload.\n */\n readonly unrecoverable: Observable<UnrecoverableStateEvent>;\n\n /**\n * True if the Service Worker is enabled (supported by the browser and enabled via\n * `ServiceWorkerModule`).\n */\n get isEnabled(): boolean {\n return this.sw.isEnabled;\n }\n\n constructor(private sw: NgswCommChannel) {\n if (!sw.isEnabled) {\n this.versionUpdates = NEVER;\n this.available = NEVER;\n this.activated = NEVER;\n this.unrecoverable = NEVER;\n return;\n }\n this.versionUpdates = this.sw.eventsOfType<VersionEvent>(\n ['VERSION_DETECTED', 'VERSION_INSTALLATION_FAILED', 'VERSION_READY']);\n this.available = this.versionUpdates.pipe(\n filter((evt: VersionEvent): evt is VersionReadyEvent => evt.type === 'VERSION_READY'),\n map(evt => ({\n type: 'UPDATE_AVAILABLE',\n current: evt.currentVersion,\n available: evt.latestVersion,\n })));\n this.activated = this.sw.eventsOfType<UpdateActivatedEvent>('UPDATE_ACTIVATED');\n this.unrecoverable = this.sw.eventsOfType<UnrecoverableStateEvent>('UNRECOVERABLE_STATE');\n }\n\n /**\n * Checks for an update and waits until the new version is downloaded from the server and ready\n * for activation.\n *\n * @returns a promise that\n * - resolves to `true` if a new version was found and is ready to be activated.\n * - resolves to `false` if no new version was found\n * - rejects if any error occurs\n */\n checkForUpdate(): Promise<boolean> {\n if (!this.sw.isEnabled) {\n return Promise.reject(new Error(ERR_SW_NOT_SUPPORTED));\n }\n const nonce = this.sw.generateNonce();\n return this.sw.postMessageWithOperation('CHECK_FOR_UPDATES', {nonce}, nonce);\n }\n\n /**\n * Updates the current client (i.e. browser tab) to the latest version that is ready for\n * activation.\n *\n * @returns a promise that\n * - resolves to `true` if an update was activated successfully\n * - resolves to `false` if no update was available (for example, the client was already on the\n * latest version).\n * - rejects if any error occurs\n */\n activateUpdate(): Promise<boolean> {\n if (!this.sw.isEnabled) {\n return Promise.reject(new Error(ERR_SW_NOT_SUPPORTED));\n }\n const nonce = this.sw.generateNonce();\n return this.sw.postMessageWithOperation('ACTIVATE_UPDATE', {nonce}, nonce);\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {isPlatformBrowser} from '@angular/common';\nimport {APP_INITIALIZER, ApplicationRef, InjectionToken, Injector, ModuleWithProviders, NgModule, NgZone, PLATFORM_ID} from '@angular/core';\nimport {merge, Observable, of} from 'rxjs';\nimport {delay, filter, take} from 'rxjs/operators';\n\nimport {NgswCommChannel} from './low_level';\nimport {SwPush} from './push';\nimport {SwUpdate} from './update';\n\n/**\n * Token that can be used to provide options for `ServiceWorkerModule` outside of\n * `ServiceWorkerModule.register()`.\n *\n * You can use this token to define a provider that generates the registration options at runtime,\n * for example via a function call:\n *\n * {@example service-worker/registration-options/module.ts region=\"registration-options\"\n * header=\"app.module.ts\"}\n *\n * @publicApi\n */\nexport abstract class SwRegistrationOptions {\n /**\n * Whether the ServiceWorker will be registered and the related services (such as `SwPush` and\n * `SwUpdate`) will attempt to communicate and interact with it.\n *\n * Default: true\n */\n enabled?: boolean;\n\n /**\n * A URL that defines the ServiceWorker's registration scope; that is, what range of URLs it can\n * control. It will be used when calling\n * [ServiceWorkerContainer#register()](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register).\n */\n scope?: string;\n\n /**\n * Defines the ServiceWorker registration strategy, which determines when it will be registered\n * with the browser.\n *\n * The default behavior of registering once the application stabilizes (i.e. as soon as there are\n * no pending micro- and macro-tasks) is designed to register the ServiceWorker as soon as\n * possible but without affecting the application's first time load.\n *\n * Still, there might be cases where you want more control over when the ServiceWorker is\n * registered (for example, there might be a long-running timeout or polling interval, preventing\n * the app from stabilizing). The available option are:\n *\n * - `registerWhenStable:<timeout>`: Register as soon as the application stabilizes (no pending\n * micro-/macro-tasks) but no later than `<timeout>` milliseconds. If the app hasn't\n * stabilized after `<timeout>` milliseconds (for example, due to a recurrent asynchronous\n * task), the ServiceWorker will be registered anyway.\n * If `<timeout>` is omitted, the ServiceWorker will only be registered once the app\n * stabilizes.\n * - `registerImmediately`: Register immediately.\n * - `registerWithDelay:<timeout>`: Register with a delay of `<timeout>` milliseconds. For\n * example, use `registerWithDelay:5000` to register the ServiceWorker after 5 seconds. If\n * `<timeout>` is omitted, is defaults to `0`, which will register the ServiceWorker as soon\n * as possible but still asynchronously, once all pending micro-tasks are completed.\n * - An [Observable](guide/observables) factory function: A function that returns an `Observable`.\n * The function will be used at runtime to obtain and subscribe to the `Observable` and the\n * ServiceWorker will be registered as soon as the first value is emitted.\n *\n * Default: 'registerWhenStable:30000'\n */\n registrationStrategy?: string|(() => Observable<unknown>);\n}\n\nexport const SCRIPT = new InjectionToken<string>('NGSW_REGISTER_SCRIPT');\n\nexport function ngswAppInitializer(\n injector: Injector, script: string, options: SwRegistrationOptions,\n platformId: string): Function {\n const initializer = () => {\n if (!(isPlatformBrowser(platformId) && ('serviceWorker' in navigator) &&\n options.enabled !== false)) {\n return;\n }\n\n // Wait for service worker controller changes, and fire an INITIALIZE action when a new SW\n // becomes active. This allows the SW to initialize itself even if there is no application\n // traffic.\n navigator.serviceWorker.addEventListener('controllerchange', () => {\n if (navigator.serviceWorker.controller !== null) {\n navigator.serviceWorker.controller.postMessage({action: 'INITIALIZE'});\n }\n });\n\n let readyToRegister$: Observable<unknown>;\n\n if (typeof options.registrationStrategy === 'function') {\n readyToRegister$ = options.registrationStrategy();\n } else {\n const [strategy, ...args] =\n (options.registrationStrategy || 'registerWhenStable:30000').split(':');\n\n switch (strategy) {\n case 'registerImmediately':\n readyToRegister$ = of(null);\n break;\n case 'registerWithDelay':\n readyToRegister$ = delayWithTimeout(+args[0] || 0);\n break;\n case 'registerWhenStable':\n readyToRegister$ = !args[0] ? whenStable(injector) :\n merge(whenStable(injector), delayWithTimeout(+args[0]));\n break;\n default:\n // Unknown strategy.\n throw new Error(\n `Unknown ServiceWorker registration strategy: ${options.registrationStrategy}`);\n }\n }\n\n // Don't return anything to avoid blocking the application until the SW is registered.\n // Also, run outside the Angular zone to avoid preventing the app from stabilizing (especially\n // given that some registration strategies wait for the app to stabilize).\n // Catch and log the error if SW registration fails to avoid uncaught rejection warning.\n const ngZone = injector.get(NgZone);\n ngZone.runOutsideAngular(\n () => readyToRegister$.pipe(take(1)).subscribe(\n () =>\n navigator.serviceWorker.register(script, {scope: options.scope})\n .catch(err => console.error('Service worker registration failed with:', err))));\n };\n return initializer;\n}\n\nfunction delayWithTimeout(timeout: number): Observable<unknown> {\n return of(null).pipe(delay(timeout));\n}\n\nfunction whenStable(injector: Injector): Observable<unknown> {\n const appRef = injector.get(ApplicationRef);\n return appRef.isStable.pipe(filter(stable => stable));\n}\n\nexport function ngswCommChannelFactory(\n opts: SwRegistrationOptions, platformId: string): NgswCommChannel {\n return new NgswCommChannel(\n isPlatformBrowser(platformId) && opts.enabled !== false ? navigator.serviceWorker :\n undefined);\n}\n\n/**\n * @publicApi\n */\n@NgModule({\n providers: [SwPush, SwUpdate],\n})\nexport class ServiceWorkerModule {\n /**\n * Register the given Angular Service Worker script.\n *\n * If `enabled` is set to `false` in the given options, the module will behave as if service\n * workers are not supported by the browser, and the service worker will not be registered.\n */\n static register(script: string, opts: SwRegistrationOptions = {}):\n ModuleWithProviders<ServiceWorkerModule> {\n return {\n ngModule: ServiceWorkerModule,\n providers: [\n {provide: SCRIPT, useValue: script},\n {provide: SwRegistrationOptions, useValue: opts},\n {\n provide: NgswCommChannel,\n useFactory: ngswCommChannelFactory,\n deps: [SwRegistrationOptions, PLATFORM_ID]\n },\n {\n provide: APP_INITIALIZER,\n useFactory: ngswAppInitializer,\n deps: [Injector, SCRIPT, SwRegistrationOptions, PLATFORM_ID],\n multi: true,\n },\n ],\n };\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\n/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nexport {UnrecoverableStateEvent, UpdateActivatedEvent, UpdateAvailableEvent, VersionDetectedEvent, VersionEvent, VersionInstallationFailedEvent, VersionReadyEvent,} from './low_level';\nexport {ServiceWorkerModule, SwRegistrationOptions} from './module';\nexport {SwPush} from './push';\nexport {SwUpdate} from './update';\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\n/**\n * @module\n * @description\n * Entry point for all public APIs of this package.\n */\nexport * from './src/index';\n\n// This file only reexports content of the `src` folder. Keep it that way.\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\n// This file is not used to build this module. It is only used during editing\n// by the TypeScript language service and during build for verification. `ngc`\n// replaces this file with production index.ts when it rewrites private symbol\n// names.\n\nexport * from './public_api';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;AAWO,MAAM,oBAAoB,GAAG,+DAA+D,CAAC;AAgIpG,SAAS,eAAe,CAAC,OAAe;IACtC,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACrD,CAAC;AAED;;;MAGa,eAAe;IAO1B,YAAoB,aAA+C;QAA/C,kBAAa,GAAb,aAAa,CAAkC;QACjE,IAAI,CAAC,aAAa,EAAE;YAClB,IAAI,CAAC,MAAM,GAA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AAM,IAAI,MAAM,CAAC,CAAC,CAAC;AACxD,CAAC;SAEe,sBAAsB,CAClC,IAA2B,EAAE,UAAkB;IACjD,OAAO,IAAI,eAAe,CACtB,iBAAiB,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,OAAO,KAAK,KAAK,GAAG,SAAS,CAAC,aAAa;QACvB,SAAS,CAAC,CAAC;AAC3E,CAAC;AAED;;;MAMa,mBAAmB;;;;;;;IAO9B,OAAO,QAAQ,CAAC,MAAc,EAAE,OAA8B,EAAE;QAE9D,OAAO;YACL,QAAQ,EAAE,mBAAmB;YAC7B,SAAS,EAAE;gBACT,EAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAC;gBACnC,EAAC,OAAO,EAAE,qBAAqB,EAAE,QAAQ,EAAE,IAAI,EAAC;gBAChD;oBACE,OAAO,EAAE,eAAe;oBACxB,UAAU,EAAE,sBAAsB;oBAClC,IAAI,EAAE,CAAC,qBAAqB,EAAE,WAAW,CAAC;iBAC3C;gBACD;oBACE,OAAO,EAAE,eAAe;oBACxB,UAAU,EAAE,kBAAkB;oBAC9B,IAAI,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,qBAAqB,EAAE,WAAW,CAAC;oBAC5D,KAAK,EAAE,IAAI;iBACZ;aACF;SACF,CAAC;KACH;;2HA3BU,mBAAmB;4HAAnB,mBAAmB;4HAAnB,mBAAmB,aAFnB,CAAC,MAAM,EAAE,QAAQ,CAAC;sGAElB,mBAAmB;kBAH/B,QAAQ;mBAAC;oBACR,SAAS,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC;iBAC9B;;;AC9JD;;;;;;;;ACAA;;;;;;;AAeA;;ACfA;;;;;;;;ACAA;;;;;;"}
package/ngsw-config.js CHANGED
@@ -3,7 +3,7 @@
3
3
  import {createRequire as __cjsCompatRequire} from 'module';
4
4
  const require = __cjsCompatRequire(import.meta.url);
5
5
 
6
- // bazel-out/darwin-fastbuild-ST-2e5f3376adb5/bin/packages/service-worker/cli/main.mjs
6
+ // bazel-out/k8-fastbuild-ST-2e5f3376adb5/bin/packages/service-worker/cli/main.mjs
7
7
  import { Generator } from "@angular/service-worker/config";
8
8
  import {
9
9
  readFileSync as readFileSync2
@@ -12,7 +12,7 @@ import {
12
12
  join as join2
13
13
  } from "path";
14
14
 
15
- // bazel-out/darwin-fastbuild-ST-2e5f3376adb5/bin/packages/service-worker/cli/filesystem.mjs
15
+ // bazel-out/k8-fastbuild-ST-2e5f3376adb5/bin/packages/service-worker/cli/filesystem.mjs
16
16
  import {
17
17
  readFileSync,
18
18
  readdirSync,
@@ -24,7 +24,7 @@ import {
24
24
  posix
25
25
  } from "path";
26
26
 
27
- // bazel-out/darwin-fastbuild-ST-2e5f3376adb5/bin/packages/service-worker/cli/sha1.mjs
27
+ // bazel-out/k8-fastbuild-ST-2e5f3376adb5/bin/packages/service-worker/cli/sha1.mjs
28
28
  function sha1Binary(buffer) {
29
29
  const words32 = arrayBufferToWords32(buffer, Endian.Big);
30
30
  return _sha1(words32, buffer.byteLength * 8);
@@ -126,7 +126,7 @@ function byteStringToHexString(str) {
126
126
  return hex.toLowerCase();
127
127
  }
128
128
 
129
- // bazel-out/darwin-fastbuild-ST-2e5f3376adb5/bin/packages/service-worker/cli/filesystem.mjs
129
+ // bazel-out/k8-fastbuild-ST-2e5f3376adb5/bin/packages/service-worker/cli/filesystem.mjs
130
130
  var NodeFilesystem = class {
131
131
  constructor(base) {
132
132
  this.base = base;
@@ -155,7 +155,7 @@ var NodeFilesystem = class {
155
155
  }
156
156
  };
157
157
 
158
- // bazel-out/darwin-fastbuild-ST-2e5f3376adb5/bin/packages/service-worker/cli/main.mjs
158
+ // bazel-out/k8-fastbuild-ST-2e5f3376adb5/bin/packages/service-worker/cli/main.mjs
159
159
  var cwd = process.cwd();
160
160
  var distDir = join2(cwd, process.argv[2]);
161
161
  var config = join2(cwd, process.argv[3]);
package/ngsw-worker.js CHANGED
@@ -1633,7 +1633,7 @@
1633
1633
  * Use of this source code is governed by an MIT-style license that can be
1634
1634
  * found in the LICENSE file at https://angular.io/license
1635
1635
  */
1636
- const SW_VERSION = '13.0.0-next.11';
1636
+ const SW_VERSION = '13.0.0-next.15';
1637
1637
  const DEBUG_LOG_BUFFER_SIZE = 100;
1638
1638
  class DebugHandler {
1639
1639
  constructor(driver, adapter) {
@@ -2079,13 +2079,12 @@ ${msgIdle}`, { headers: this.adapter.newHeaders({ 'Content-Type': 'text/plain' }
2079
2079
  }
2080
2080
  async handleMessage(msg, from) {
2081
2081
  if (isMsgCheckForUpdates(msg)) {
2082
- const action = (async () => {
2083
- await this.checkForUpdate();
2084
- })();
2085
- await this.reportStatus(from, action, msg.statusNonce);
2082
+ const action = this.checkForUpdate();
2083
+ await this.completeOperation(from, action, msg.nonce);
2086
2084
  }
2087
2085
  else if (isMsgActivateUpdate(msg)) {
2088
- await this.reportStatus(from, this.updateClient(from), msg.statusNonce);
2086
+ const action = this.updateClient(from);
2087
+ await this.completeOperation(from, action, msg.nonce);
2089
2088
  }
2090
2089
  }
2091
2090
  async handlePush(data) {
@@ -2148,16 +2147,17 @@ ${msgIdle}`, { headers: this.adapter.newHeaders({ 'Content-Type': 'text/plain' }
2148
2147
  // As per the spec windowClients are `sorted in the most recently focused order`
2149
2148
  return windowClients[0];
2150
2149
  }
2151
- async reportStatus(client, promise, nonce) {
2152
- const response = { type: 'STATUS', nonce, status: true };
2150
+ async completeOperation(client, promise, nonce) {
2151
+ const response = { type: 'OPERATION_COMPLETED', nonce };
2153
2152
  try {
2154
- await promise;
2155
- client.postMessage(response);
2153
+ client.postMessage({
2154
+ ...response,
2155
+ result: await promise,
2156
+ });
2156
2157
  }
2157
2158
  catch (e) {
2158
2159
  client.postMessage({
2159
2160
  ...response,
2160
- status: false,
2161
2161
  error: e.toString(),
2162
2162
  });
2163
2163
  }
@@ -2168,7 +2168,7 @@ ${msgIdle}`, { headers: this.adapter.newHeaders({ 'Content-Type': 'text/plain' }
2168
2168
  const existing = this.clientVersionMap.get(client.id);
2169
2169
  if (existing === this.latestHash) {
2170
2170
  // Nothing to do, this client is already on the latest version.
2171
- return;
2171
+ return false;
2172
2172
  }
2173
2173
  // Switch the client over.
2174
2174
  let previous = undefined;
@@ -2189,6 +2189,7 @@ ${msgIdle}`, { headers: this.adapter.newHeaders({ 'Content-Type': 'text/plain' }
2189
2189
  current: this.mergeHashWithAppData(current.manifest, this.latestHash),
2190
2190
  };
2191
2191
  client.postMessage(notice);
2192
+ return true;
2192
2193
  }
2193
2194
  async handleFetch(event) {
2194
2195
  try {
@@ -2522,28 +2523,34 @@ ${msgIdle}`, { headers: this.adapter.newHeaders({ 'Content-Type': 'text/plain' }
2522
2523
  }
2523
2524
  }
2524
2525
  async setupUpdate(manifest, hash) {
2525
- const newVersion = new AppVersion(this.scope, this.adapter, this.db, this.idle, this.debugger, manifest, hash);
2526
- // Firstly, check if the manifest version is correct.
2527
- if (manifest.configVersion !== SUPPORTED_CONFIG_VERSION) {
2528
- await this.deleteAllCaches();
2529
- await this.scope.registration.unregister();
2530
- throw new Error(`Invalid config version: expected ${SUPPORTED_CONFIG_VERSION}, got ${manifest.configVersion}.`);
2531
- }
2532
- // Cause the new version to become fully initialized. If this fails, then the
2533
- // version will not be available for use.
2534
- await newVersion.initializeFully(this);
2535
- // Install this as an active version of the app.
2536
- this.versions.set(hash, newVersion);
2537
- // Future new clients will use this hash as the latest version.
2538
- this.latestHash = hash;
2539
- // If we are in `EXISTING_CLIENTS_ONLY` mode (meaning we didn't have a clean copy of the last
2540
- // latest version), we can now recover to `NORMAL` mode and start accepting new clients.
2541
- if (this.state === DriverReadyState.EXISTING_CLIENTS_ONLY) {
2542
- this.state = DriverReadyState.NORMAL;
2543
- this.stateMessage = '(nominal)';
2526
+ try {
2527
+ const newVersion = new AppVersion(this.scope, this.adapter, this.db, this.idle, this.debugger, manifest, hash);
2528
+ // Firstly, check if the manifest version is correct.
2529
+ if (manifest.configVersion !== SUPPORTED_CONFIG_VERSION) {
2530
+ await this.deleteAllCaches();
2531
+ await this.scope.registration.unregister();
2532
+ throw new Error(`Invalid config version: expected ${SUPPORTED_CONFIG_VERSION}, got ${manifest.configVersion}.`);
2533
+ }
2534
+ // Cause the new version to become fully initialized. If this fails, then the
2535
+ // version will not be available for use.
2536
+ await newVersion.initializeFully(this);
2537
+ // Install this as an active version of the app.
2538
+ this.versions.set(hash, newVersion);
2539
+ // Future new clients will use this hash as the latest version.
2540
+ this.latestHash = hash;
2541
+ // If we are in `EXISTING_CLIENTS_ONLY` mode (meaning we didn't have a clean copy of the last
2542
+ // latest version), we can now recover to `NORMAL` mode and start accepting new clients.
2543
+ if (this.state === DriverReadyState.EXISTING_CLIENTS_ONLY) {
2544
+ this.state = DriverReadyState.NORMAL;
2545
+ this.stateMessage = '(nominal)';
2546
+ }
2547
+ await this.sync();
2548
+ await this.notifyClientsAboutVersionReady(manifest, hash);
2549
+ }
2550
+ catch (e) {
2551
+ await this.notifyClientsAboutVersionInstallationFailed(manifest, hash, e);
2552
+ throw e;
2544
2553
  }
2545
- await this.sync();
2546
- await this.notifyClientsAboutUpdate(newVersion);
2547
2554
  }
2548
2555
  async checkForUpdate() {
2549
2556
  let hash = '(unknown)';
@@ -2560,6 +2567,7 @@ ${msgIdle}`, { headers: this.adapter.newHeaders({ 'Content-Type': 'text/plain' }
2560
2567
  if (this.versions.has(hash)) {
2561
2568
  return false;
2562
2569
  }
2570
+ await this.notifyClientsAboutVersionDetected(manifest, hash);
2563
2571
  await this.setupUpdate(manifest, hash);
2564
2572
  return true;
2565
2573
  }
@@ -2705,7 +2713,33 @@ ${msgIdle}`, { headers: this.adapter.newHeaders({ 'Content-Type': 'text/plain' }
2705
2713
  }
2706
2714
  }));
2707
2715
  }
2708
- async notifyClientsAboutUpdate(next) {
2716
+ async notifyClientsAboutVersionInstallationFailed(manifest, hash, error) {
2717
+ await this.initialized;
2718
+ const clients = await this.scope.clients.matchAll();
2719
+ await Promise.all(clients.map(async (client) => {
2720
+ // Send a notice.
2721
+ client.postMessage({
2722
+ type: 'VERSION_INSTALLATION_FAILED',
2723
+ version: this.mergeHashWithAppData(manifest, hash),
2724
+ error: errorToString(error),
2725
+ });
2726
+ }));
2727
+ }
2728
+ async notifyClientsAboutVersionDetected(manifest, hash) {
2729
+ await this.initialized;
2730
+ const clients = await this.scope.clients.matchAll();
2731
+ await Promise.all(clients.map(async (client) => {
2732
+ // Firstly, determine which version this client is on.
2733
+ const version = this.clientVersionMap.get(client.id);
2734
+ if (version === undefined) {
2735
+ // Unmapped client - assume it's the latest.
2736
+ return;
2737
+ }
2738
+ // Send a notice.
2739
+ client.postMessage({ type: 'VERSION_DETECTED', version: this.mergeHashWithAppData(manifest, hash) });
2740
+ }));
2741
+ }
2742
+ async notifyClientsAboutVersionReady(manifest, hash) {
2709
2743
  await this.initialized;
2710
2744
  const clients = await this.scope.clients.matchAll();
2711
2745
  await Promise.all(clients.map(async (client) => {
@@ -2722,9 +2756,9 @@ ${msgIdle}`, { headers: this.adapter.newHeaders({ 'Content-Type': 'text/plain' }
2722
2756
  const current = this.versions.get(version);
2723
2757
  // Send a notice.
2724
2758
  const notice = {
2725
- type: 'UPDATE_AVAILABLE',
2726
- current: this.mergeHashWithAppData(current.manifest, version),
2727
- available: this.mergeHashWithAppData(next.manifest, this.latestHash),
2759
+ type: 'VERSION_READY',
2760
+ currentVersion: this.mergeHashWithAppData(current.manifest, version),
2761
+ latestVersion: this.mergeHashWithAppData(manifest, hash),
2728
2762
  };
2729
2763
  client.postMessage(notice);
2730
2764
  }));
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@angular/service-worker",
3
- "version": "13.0.0-next.11",
3
+ "version": "13.0.0-next.15",
4
4
  "description": "Angular - service worker tooling!",
5
5
  "author": "angular",
6
6
  "license": "MIT",
7
7
  "engines": {
8
- "node": "^12.14.1 || >=14.0.0"
8
+ "node": "^12.20.0 || ^14.15.0 || >=16.10.0"
9
9
  },
10
10
  "exports": {
11
11
  "./ngsw-worker.js": {
@@ -22,12 +22,16 @@
22
22
  },
23
23
  ".": {
24
24
  "types": "./service-worker.d.ts",
25
+ "esm2020": "./esm2020/service-worker.mjs",
26
+ "es2020": "./fesm2020/service-worker.mjs",
25
27
  "es2015": "./fesm2015/service-worker.mjs",
26
28
  "node": "./fesm2015/service-worker.mjs",
27
29
  "default": "./fesm2020/service-worker.mjs"
28
30
  },
29
31
  "./config": {
30
32
  "types": "./config/config.d.ts",
33
+ "esm2020": "./esm2020/config/config.mjs",
34
+ "es2020": "./fesm2020/config.mjs",
31
35
  "es2015": "./fesm2015/config.mjs",
32
36
  "node": "./fesm2015/config.mjs",
33
37
  "default": "./fesm2020/config.mjs"
@@ -37,8 +41,8 @@
37
41
  "tslib": "^2.3.0"
38
42
  },
39
43
  "peerDependencies": {
40
- "@angular/core": "13.0.0-next.11",
41
- "@angular/common": "13.0.0-next.11"
44
+ "@angular/core": "13.0.0-next.15",
45
+ "@angular/common": "13.0.0-next.15"
42
46
  },
43
47
  "repository": {
44
48
  "type": "git",