@angular/service-worker 12.2.7 → 13.0.0-next.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/config/config.d.ts +1 -1
  2. package/config/package.json +5 -5
  3. package/{esm2015/config/config.js → esm2020/config/config.mjs} +0 -0
  4. package/{esm2015/config/index.js → esm2020/config/index.mjs} +0 -0
  5. package/{esm2015/config/public_api.js → esm2020/config/public_api.mjs} +0 -0
  6. package/{esm2015/config/src/duration.js → esm2020/config/src/duration.mjs} +0 -0
  7. package/{esm2015/config/src/filesystem.js → esm2020/config/src/filesystem.mjs} +0 -0
  8. package/esm2020/config/src/generator.mjs +147 -0
  9. package/{esm2015/config/src/glob.js → esm2020/config/src/glob.mjs} +0 -0
  10. package/{esm2015/config/src/in.js → esm2020/config/src/in.mjs} +0 -0
  11. package/{esm2015/index.js → esm2020/index.mjs} +0 -0
  12. package/{esm2015/public_api.js → esm2020/public_api.mjs} +0 -0
  13. package/esm2020/service-worker.mjs +5 -0
  14. package/{esm2015/src/index.js → esm2020/src/index.mjs} +0 -0
  15. package/esm2020/src/low_level.mjs +78 -0
  16. package/esm2020/src/module.mjs +128 -0
  17. package/esm2020/src/push.mjs +174 -0
  18. package/esm2020/src/update.mjs +61 -0
  19. package/fesm2015/{config.js → config.mjs} +2 -9
  20. package/fesm2015/config.mjs.map +1 -0
  21. package/fesm2015/{service-worker.js → service-worker.mjs} +23 -20
  22. package/fesm2015/service-worker.mjs.map +1 -0
  23. package/fesm2020/config.mjs +267 -0
  24. package/fesm2020/config.mjs.map +1 -0
  25. package/fesm2020/service-worker.mjs +463 -0
  26. package/fesm2020/service-worker.mjs.map +1 -0
  27. package/ngsw-config.js +169 -218
  28. package/ngsw-worker.js +1416 -1586
  29. package/package.json +36 -9
  30. package/service-worker.d.ts +29 -29
  31. package/bundles/service-worker-config.umd.js +0 -626
  32. package/bundles/service-worker-config.umd.js.map +0 -1
  33. package/bundles/service-worker.umd.js +0 -804
  34. package/bundles/service-worker.umd.js.map +0 -1
  35. package/config/config.metadata.json +0 -1
  36. package/config/index.ngfactory.d.ts +0 -2
  37. package/config/index.ngsummary.d.ts +0 -2
  38. package/config/public_api.ngfactory.d.ts +0 -2
  39. package/config/public_api.ngsummary.d.ts +0 -2
  40. package/config/src/duration.ngfactory.d.ts +0 -2
  41. package/config/src/duration.ngsummary.d.ts +0 -2
  42. package/config/src/filesystem.ngfactory.d.ts +0 -2
  43. package/config/src/filesystem.ngsummary.d.ts +0 -2
  44. package/config/src/generator.ngfactory.d.ts +0 -2
  45. package/config/src/generator.ngsummary.d.ts +0 -2
  46. package/config/src/glob.ngfactory.d.ts +0 -2
  47. package/config/src/glob.ngsummary.d.ts +0 -2
  48. package/config/src/in.ngfactory.d.ts +0 -2
  49. package/config/src/in.ngsummary.d.ts +0 -2
  50. package/config.d.ts +0 -7
  51. package/config.metadata.json +0 -1
  52. package/esm2015/config/config.externs.js +0 -6
  53. package/esm2015/config/src/generator.js +0 -150
  54. package/esm2015/service-worker.externs.js +0 -6
  55. package/esm2015/service-worker.js +0 -7
  56. package/esm2015/src/low_level.js +0 -75
  57. package/esm2015/src/module.js +0 -123
  58. package/esm2015/src/push.js +0 -173
  59. package/esm2015/src/update.js +0 -60
  60. package/fesm2015/config.js.map +0 -1
  61. package/fesm2015/service-worker.js.map +0 -1
  62. package/service-worker.metadata.json +0 -1
@@ -1,804 +0,0 @@
1
- /**
2
- * @license Angular v12.2.7
3
- * (c) 2010-2021 Google LLC. https://angular.io/
4
- * License: MIT
5
- */
6
-
7
- (function (global, factory) {
8
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common'), require('@angular/core'), require('rxjs'), require('rxjs/operators')) :
9
- typeof define === 'function' && define.amd ? define('@angular/service-worker', ['exports', '@angular/common', '@angular/core', 'rxjs', 'rxjs/operators'], factory) :
10
- (global = global || self, factory((global.ng = global.ng || {}, global.ng.serviceWorker = {}), global.ng.common, global.ng.core, global.rxjs, global.rxjs.operators));
11
- }(this, (function (exports, common, core, rxjs, operators) { 'use strict';
12
-
13
- /*! *****************************************************************************
14
- Copyright (c) Microsoft Corporation.
15
-
16
- Permission to use, copy, modify, and/or distribute this software for any
17
- purpose with or without fee is hereby granted.
18
-
19
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
20
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
21
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
22
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
23
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
24
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
25
- PERFORMANCE OF THIS SOFTWARE.
26
- ***************************************************************************** */
27
- /* global Reflect, Promise */
28
- var extendStatics = function (d, b) {
29
- extendStatics = Object.setPrototypeOf ||
30
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
31
- function (d, b) { for (var p in b)
32
- if (Object.prototype.hasOwnProperty.call(b, p))
33
- d[p] = b[p]; };
34
- return extendStatics(d, b);
35
- };
36
- function __extends(d, b) {
37
- if (typeof b !== "function" && b !== null)
38
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
39
- extendStatics(d, b);
40
- function __() { this.constructor = d; }
41
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
42
- }
43
- var __assign = function () {
44
- __assign = Object.assign || function __assign(t) {
45
- for (var s, i = 1, n = arguments.length; i < n; i++) {
46
- s = arguments[i];
47
- for (var p in s)
48
- if (Object.prototype.hasOwnProperty.call(s, p))
49
- t[p] = s[p];
50
- }
51
- return t;
52
- };
53
- return __assign.apply(this, arguments);
54
- };
55
- function __rest(s, e) {
56
- var t = {};
57
- for (var p in s)
58
- if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
59
- t[p] = s[p];
60
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
61
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
62
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
63
- t[p[i]] = s[p[i]];
64
- }
65
- return t;
66
- }
67
- function __decorate(decorators, target, key, desc) {
68
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
69
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
70
- r = Reflect.decorate(decorators, target, key, desc);
71
- else
72
- for (var i = decorators.length - 1; i >= 0; i--)
73
- if (d = decorators[i])
74
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
75
- return c > 3 && r && Object.defineProperty(target, key, r), r;
76
- }
77
- function __param(paramIndex, decorator) {
78
- return function (target, key) { decorator(target, key, paramIndex); };
79
- }
80
- function __metadata(metadataKey, metadataValue) {
81
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
82
- return Reflect.metadata(metadataKey, metadataValue);
83
- }
84
- function __awaiter(thisArg, _arguments, P, generator) {
85
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
86
- return new (P || (P = Promise))(function (resolve, reject) {
87
- function fulfilled(value) { try {
88
- step(generator.next(value));
89
- }
90
- catch (e) {
91
- reject(e);
92
- } }
93
- function rejected(value) { try {
94
- step(generator["throw"](value));
95
- }
96
- catch (e) {
97
- reject(e);
98
- } }
99
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
100
- step((generator = generator.apply(thisArg, _arguments || [])).next());
101
- });
102
- }
103
- function __generator(thisArg, body) {
104
- var _ = { label: 0, sent: function () { if (t[0] & 1)
105
- throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
106
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
107
- function verb(n) { return function (v) { return step([n, v]); }; }
108
- function step(op) {
109
- if (f)
110
- throw new TypeError("Generator is already executing.");
111
- while (_)
112
- try {
113
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
114
- return t;
115
- if (y = 0, t)
116
- op = [op[0] & 2, t.value];
117
- switch (op[0]) {
118
- case 0:
119
- case 1:
120
- t = op;
121
- break;
122
- case 4:
123
- _.label++;
124
- return { value: op[1], done: false };
125
- case 5:
126
- _.label++;
127
- y = op[1];
128
- op = [0];
129
- continue;
130
- case 7:
131
- op = _.ops.pop();
132
- _.trys.pop();
133
- continue;
134
- default:
135
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
136
- _ = 0;
137
- continue;
138
- }
139
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
140
- _.label = op[1];
141
- break;
142
- }
143
- if (op[0] === 6 && _.label < t[1]) {
144
- _.label = t[1];
145
- t = op;
146
- break;
147
- }
148
- if (t && _.label < t[2]) {
149
- _.label = t[2];
150
- _.ops.push(op);
151
- break;
152
- }
153
- if (t[2])
154
- _.ops.pop();
155
- _.trys.pop();
156
- continue;
157
- }
158
- op = body.call(thisArg, _);
159
- }
160
- catch (e) {
161
- op = [6, e];
162
- y = 0;
163
- }
164
- finally {
165
- f = t = 0;
166
- }
167
- if (op[0] & 5)
168
- throw op[1];
169
- return { value: op[0] ? op[1] : void 0, done: true };
170
- }
171
- }
172
- var __createBinding = Object.create ? (function (o, m, k, k2) {
173
- if (k2 === undefined)
174
- k2 = k;
175
- Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
176
- }) : (function (o, m, k, k2) {
177
- if (k2 === undefined)
178
- k2 = k;
179
- o[k2] = m[k];
180
- });
181
- function __exportStar(m, o) {
182
- for (var p in m)
183
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
184
- __createBinding(o, m, p);
185
- }
186
- function __values(o) {
187
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
188
- if (m)
189
- return m.call(o);
190
- if (o && typeof o.length === "number")
191
- return {
192
- next: function () {
193
- if (o && i >= o.length)
194
- o = void 0;
195
- return { value: o && o[i++], done: !o };
196
- }
197
- };
198
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
199
- }
200
- function __read(o, n) {
201
- var m = typeof Symbol === "function" && o[Symbol.iterator];
202
- if (!m)
203
- return o;
204
- var i = m.call(o), r, ar = [], e;
205
- try {
206
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
207
- ar.push(r.value);
208
- }
209
- catch (error) {
210
- e = { error: error };
211
- }
212
- finally {
213
- try {
214
- if (r && !r.done && (m = i["return"]))
215
- m.call(i);
216
- }
217
- finally {
218
- if (e)
219
- throw e.error;
220
- }
221
- }
222
- return ar;
223
- }
224
- /** @deprecated */
225
- function __spread() {
226
- for (var ar = [], i = 0; i < arguments.length; i++)
227
- ar = ar.concat(__read(arguments[i]));
228
- return ar;
229
- }
230
- /** @deprecated */
231
- function __spreadArrays() {
232
- for (var s = 0, i = 0, il = arguments.length; i < il; i++)
233
- s += arguments[i].length;
234
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
235
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
236
- r[k] = a[j];
237
- return r;
238
- }
239
- function __spreadArray(to, from, pack) {
240
- if (pack || arguments.length === 2)
241
- for (var i = 0, l = from.length, ar; i < l; i++) {
242
- if (ar || !(i in from)) {
243
- if (!ar)
244
- ar = Array.prototype.slice.call(from, 0, i);
245
- ar[i] = from[i];
246
- }
247
- }
248
- return to.concat(ar || Array.prototype.slice.call(from));
249
- }
250
- function __await(v) {
251
- return this instanceof __await ? (this.v = v, this) : new __await(v);
252
- }
253
- function __asyncGenerator(thisArg, _arguments, generator) {
254
- if (!Symbol.asyncIterator)
255
- throw new TypeError("Symbol.asyncIterator is not defined.");
256
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
257
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
258
- function verb(n) { if (g[n])
259
- i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
260
- function resume(n, v) { try {
261
- step(g[n](v));
262
- }
263
- catch (e) {
264
- settle(q[0][3], e);
265
- } }
266
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
267
- function fulfill(value) { resume("next", value); }
268
- function reject(value) { resume("throw", value); }
269
- function settle(f, v) { if (f(v), q.shift(), q.length)
270
- resume(q[0][0], q[0][1]); }
271
- }
272
- function __asyncDelegator(o) {
273
- var i, p;
274
- return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
275
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
276
- }
277
- function __asyncValues(o) {
278
- if (!Symbol.asyncIterator)
279
- throw new TypeError("Symbol.asyncIterator is not defined.");
280
- var m = o[Symbol.asyncIterator], i;
281
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
282
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
283
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
284
- }
285
- function __makeTemplateObject(cooked, raw) {
286
- if (Object.defineProperty) {
287
- Object.defineProperty(cooked, "raw", { value: raw });
288
- }
289
- else {
290
- cooked.raw = raw;
291
- }
292
- return cooked;
293
- }
294
- ;
295
- var __setModuleDefault = Object.create ? (function (o, v) {
296
- Object.defineProperty(o, "default", { enumerable: true, value: v });
297
- }) : function (o, v) {
298
- o["default"] = v;
299
- };
300
- function __importStar(mod) {
301
- if (mod && mod.__esModule)
302
- return mod;
303
- var result = {};
304
- if (mod != null)
305
- for (var k in mod)
306
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
307
- __createBinding(result, mod, k);
308
- __setModuleDefault(result, mod);
309
- return result;
310
- }
311
- function __importDefault(mod) {
312
- return (mod && mod.__esModule) ? mod : { default: mod };
313
- }
314
- function __classPrivateFieldGet(receiver, state, kind, f) {
315
- if (kind === "a" && !f)
316
- throw new TypeError("Private accessor was defined without a getter");
317
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
318
- throw new TypeError("Cannot read private member from an object whose class did not declare it");
319
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
320
- }
321
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
322
- if (kind === "m")
323
- throw new TypeError("Private method is not writable");
324
- if (kind === "a" && !f)
325
- throw new TypeError("Private accessor was defined without a setter");
326
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
327
- throw new TypeError("Cannot write private member to an object whose class did not declare it");
328
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
329
- }
330
-
331
- /**
332
- * @license
333
- * Copyright Google LLC All Rights Reserved.
334
- *
335
- * Use of this source code is governed by an MIT-style license that can be
336
- * found in the LICENSE file at https://angular.io/license
337
- */
338
- var ERR_SW_NOT_SUPPORTED = 'Service workers are disabled or not supported by this browser';
339
- function errorObservable(message) {
340
- return rxjs.defer(function () { return rxjs.throwError(new Error(message)); });
341
- }
342
- /**
343
- * @publicApi
344
- */
345
- var NgswCommChannel = /** @class */ (function () {
346
- function NgswCommChannel(serviceWorker) {
347
- this.serviceWorker = serviceWorker;
348
- if (!serviceWorker) {
349
- this.worker = this.events = this.registration = errorObservable(ERR_SW_NOT_SUPPORTED);
350
- }
351
- else {
352
- var controllerChangeEvents = rxjs.fromEvent(serviceWorker, 'controllerchange');
353
- var controllerChanges = controllerChangeEvents.pipe(operators.map(function () { return serviceWorker.controller; }));
354
- var currentController = rxjs.defer(function () { return rxjs.of(serviceWorker.controller); });
355
- var controllerWithChanges = rxjs.concat(currentController, controllerChanges);
356
- this.worker = controllerWithChanges.pipe(operators.filter(function (c) { return !!c; }));
357
- this.registration = (this.worker.pipe(operators.switchMap(function () { return serviceWorker.getRegistration(); })));
358
- var rawEvents = rxjs.fromEvent(serviceWorker, 'message');
359
- var rawEventPayload = rawEvents.pipe(operators.map(function (event) { return event.data; }));
360
- var eventsUnconnected = rawEventPayload.pipe(operators.filter(function (event) { return event && event.type; }));
361
- var events = eventsUnconnected.pipe(operators.publish());
362
- events.connect();
363
- this.events = events;
364
- }
365
- }
366
- NgswCommChannel.prototype.postMessage = function (action, payload) {
367
- return this.worker
368
- .pipe(operators.take(1), operators.tap(function (sw) {
369
- sw.postMessage(Object.assign({ action: action }, payload));
370
- }))
371
- .toPromise()
372
- .then(function () { return undefined; });
373
- };
374
- NgswCommChannel.prototype.postMessageWithStatus = function (type, payload, nonce) {
375
- var waitForStatus = this.waitForStatus(nonce);
376
- var postMessage = this.postMessage(type, payload);
377
- return Promise.all([waitForStatus, postMessage]).then(function () { return undefined; });
378
- };
379
- NgswCommChannel.prototype.generateNonce = function () {
380
- return Math.round(Math.random() * 10000000);
381
- };
382
- NgswCommChannel.prototype.eventsOfType = function (type) {
383
- var filterFn = function (event) { return event.type === type; };
384
- return this.events.pipe(operators.filter(filterFn));
385
- };
386
- NgswCommChannel.prototype.nextEventOfType = function (type) {
387
- return this.eventsOfType(type).pipe(operators.take(1));
388
- };
389
- NgswCommChannel.prototype.waitForStatus = function (nonce) {
390
- return this.eventsOfType('STATUS')
391
- .pipe(operators.filter(function (event) { return event.nonce === nonce; }), operators.take(1), operators.map(function (event) {
392
- if (event.status) {
393
- return undefined;
394
- }
395
- throw new Error(event.error);
396
- }))
397
- .toPromise();
398
- };
399
- Object.defineProperty(NgswCommChannel.prototype, "isEnabled", {
400
- get: function () {
401
- return !!this.serviceWorker;
402
- },
403
- enumerable: false,
404
- configurable: true
405
- });
406
- return NgswCommChannel;
407
- }());
408
-
409
- /**
410
- * @license
411
- * Copyright Google LLC All Rights Reserved.
412
- *
413
- * Use of this source code is governed by an MIT-style license that can be
414
- * found in the LICENSE file at https://angular.io/license
415
- */
416
- /**
417
- * Subscribe and listen to
418
- * [Web Push
419
- * Notifications](https://developer.mozilla.org/en-US/docs/Web/API/Push_API/Best_Practices) through
420
- * Angular Service Worker.
421
- *
422
- * @usageNotes
423
- *
424
- * You can inject a `SwPush` instance into any component or service
425
- * as a dependency.
426
- *
427
- * <code-example path="service-worker/push/module.ts" region="inject-sw-push"
428
- * header="app.component.ts"></code-example>
429
- *
430
- * To subscribe, call `SwPush.requestSubscription()`, which asks the user for permission.
431
- * The call returns a `Promise` with a new
432
- * [`PushSubscription`](https://developer.mozilla.org/en-US/docs/Web/API/PushSubscription)
433
- * instance.
434
- *
435
- * <code-example path="service-worker/push/module.ts" region="subscribe-to-push"
436
- * header="app.component.ts"></code-example>
437
- *
438
- * A request is rejected if the user denies permission, or if the browser
439
- * blocks or does not support the Push API or ServiceWorkers.
440
- * Check `SwPush.isEnabled` to confirm status.
441
- *
442
- * Invoke Push Notifications by pushing a message with the following payload.
443
- *
444
- * ```ts
445
- * {
446
- * "notification": {
447
- * "actions": NotificationAction[],
448
- * "badge": USVString,
449
- * "body": DOMString,
450
- * "data": any,
451
- * "dir": "auto"|"ltr"|"rtl",
452
- * "icon": USVString,
453
- * "image": USVString,
454
- * "lang": DOMString,
455
- * "renotify": boolean,
456
- * "requireInteraction": boolean,
457
- * "silent": boolean,
458
- * "tag": DOMString,
459
- * "timestamp": DOMTimeStamp,
460
- * "title": DOMString,
461
- * "vibrate": number[]
462
- * }
463
- * }
464
- * ```
465
- *
466
- * Only `title` is required. See `Notification`
467
- * [instance
468
- * properties](https://developer.mozilla.org/en-US/docs/Web/API/Notification#Instance_properties).
469
- *
470
- * While the subscription is active, Service Worker listens for
471
- * [PushEvent](https://developer.mozilla.org/en-US/docs/Web/API/PushEvent)
472
- * occurrences and creates
473
- * [Notification](https://developer.mozilla.org/en-US/docs/Web/API/Notification)
474
- * instances in response.
475
- *
476
- * Unsubscribe using `SwPush.unsubscribe()`.
477
- *
478
- * An application can subscribe to `SwPush.notificationClicks` observable to be notified when a user
479
- * clicks on a notification. For example:
480
- *
481
- * <code-example path="service-worker/push/module.ts" region="subscribe-to-notification-clicks"
482
- * header="app.component.ts"></code-example>
483
- *
484
- * You can read more on handling notification clicks in the [Service worker notifications
485
- * guide](guide/service-worker-notifications).
486
- *
487
- * @see [Push Notifications](https://developers.google.com/web/fundamentals/codelabs/push-notifications/)
488
- * @see [Angular Push Notifications](https://blog.angular-university.io/angular-push-notifications/)
489
- * @see [MDN: Push API](https://developer.mozilla.org/en-US/docs/Web/API/Push_API)
490
- * @see [MDN: Notifications API](https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API)
491
- * @see [MDN: Web Push API Notifications best practices](https://developer.mozilla.org/en-US/docs/Web/API/Push_API/Best_Practices)
492
- *
493
- * @publicApi
494
- */
495
- var SwPush = /** @class */ (function () {
496
- function SwPush(sw) {
497
- this.sw = sw;
498
- this.subscriptionChanges = new rxjs.Subject();
499
- if (!sw.isEnabled) {
500
- this.messages = rxjs.NEVER;
501
- this.notificationClicks = rxjs.NEVER;
502
- this.subscription = rxjs.NEVER;
503
- return;
504
- }
505
- this.messages = this.sw.eventsOfType('PUSH').pipe(operators.map(function (message) { return message.data; }));
506
- this.notificationClicks =
507
- this.sw.eventsOfType('NOTIFICATION_CLICK').pipe(operators.map(function (message) { return message.data; }));
508
- this.pushManager = this.sw.registration.pipe(operators.map(function (registration) { return registration.pushManager; }));
509
- var workerDrivenSubscriptions = this.pushManager.pipe(operators.switchMap(function (pm) { return pm.getSubscription(); }));
510
- this.subscription = rxjs.merge(workerDrivenSubscriptions, this.subscriptionChanges);
511
- }
512
- Object.defineProperty(SwPush.prototype, "isEnabled", {
513
- /**
514
- * True if the Service Worker is enabled (supported by the browser and enabled via
515
- * `ServiceWorkerModule`).
516
- */
517
- get: function () {
518
- return this.sw.isEnabled;
519
- },
520
- enumerable: false,
521
- configurable: true
522
- });
523
- /**
524
- * Subscribes to Web Push Notifications,
525
- * after requesting and receiving user permission.
526
- *
527
- * @param options An object containing the `serverPublicKey` string.
528
- * @returns A Promise that resolves to the new subscription object.
529
- */
530
- SwPush.prototype.requestSubscription = function (options) {
531
- var _this = this;
532
- if (!this.sw.isEnabled) {
533
- return Promise.reject(new Error(ERR_SW_NOT_SUPPORTED));
534
- }
535
- var pushOptions = { userVisibleOnly: true };
536
- var key = this.decodeBase64(options.serverPublicKey.replace(/_/g, '/').replace(/-/g, '+'));
537
- var applicationServerKey = new Uint8Array(new ArrayBuffer(key.length));
538
- for (var i = 0; i < key.length; i++) {
539
- applicationServerKey[i] = key.charCodeAt(i);
540
- }
541
- pushOptions.applicationServerKey = applicationServerKey;
542
- return this.pushManager.pipe(operators.switchMap(function (pm) { return pm.subscribe(pushOptions); }), operators.take(1))
543
- .toPromise()
544
- .then(function (sub) {
545
- _this.subscriptionChanges.next(sub);
546
- return sub;
547
- });
548
- };
549
- /**
550
- * Unsubscribes from Service Worker push notifications.
551
- *
552
- * @returns A Promise that is resolved when the operation succeeds, or is rejected if there is no
553
- * active subscription or the unsubscribe operation fails.
554
- */
555
- SwPush.prototype.unsubscribe = function () {
556
- var _this = this;
557
- if (!this.sw.isEnabled) {
558
- return Promise.reject(new Error(ERR_SW_NOT_SUPPORTED));
559
- }
560
- var doUnsubscribe = function (sub) {
561
- if (sub === null) {
562
- throw new Error('Not subscribed to push notifications.');
563
- }
564
- return sub.unsubscribe().then(function (success) {
565
- if (!success) {
566
- throw new Error('Unsubscribe failed!');
567
- }
568
- _this.subscriptionChanges.next(null);
569
- });
570
- };
571
- return this.subscription.pipe(operators.take(1), operators.switchMap(doUnsubscribe)).toPromise();
572
- };
573
- SwPush.prototype.decodeBase64 = function (input) {
574
- return atob(input);
575
- };
576
- return SwPush;
577
- }());
578
- SwPush.decorators = [
579
- { type: core.Injectable }
580
- ];
581
- SwPush.ctorParameters = function () { return [
582
- { type: NgswCommChannel }
583
- ]; };
584
-
585
- /**
586
- * @license
587
- * Copyright Google LLC All Rights Reserved.
588
- *
589
- * Use of this source code is governed by an MIT-style license that can be
590
- * found in the LICENSE file at https://angular.io/license
591
- */
592
- /**
593
- * Subscribe to update notifications from the Service Worker, trigger update
594
- * checks, and forcibly activate updates.
595
- *
596
- * @see {@link guide/service-worker-communications Service worker communication guide}
597
- *
598
- * @publicApi
599
- */
600
- var SwUpdate = /** @class */ (function () {
601
- function SwUpdate(sw) {
602
- this.sw = sw;
603
- if (!sw.isEnabled) {
604
- this.available = rxjs.NEVER;
605
- this.activated = rxjs.NEVER;
606
- this.unrecoverable = rxjs.NEVER;
607
- return;
608
- }
609
- this.available = this.sw.eventsOfType('UPDATE_AVAILABLE');
610
- this.activated = this.sw.eventsOfType('UPDATE_ACTIVATED');
611
- this.unrecoverable = this.sw.eventsOfType('UNRECOVERABLE_STATE');
612
- }
613
- Object.defineProperty(SwUpdate.prototype, "isEnabled", {
614
- /**
615
- * True if the Service Worker is enabled (supported by the browser and enabled via
616
- * `ServiceWorkerModule`).
617
- */
618
- get: function () {
619
- return this.sw.isEnabled;
620
- },
621
- enumerable: false,
622
- configurable: true
623
- });
624
- SwUpdate.prototype.checkForUpdate = function () {
625
- if (!this.sw.isEnabled) {
626
- return Promise.reject(new Error(ERR_SW_NOT_SUPPORTED));
627
- }
628
- var statusNonce = this.sw.generateNonce();
629
- return this.sw.postMessageWithStatus('CHECK_FOR_UPDATES', { statusNonce: statusNonce }, statusNonce);
630
- };
631
- SwUpdate.prototype.activateUpdate = function () {
632
- if (!this.sw.isEnabled) {
633
- return Promise.reject(new Error(ERR_SW_NOT_SUPPORTED));
634
- }
635
- var statusNonce = this.sw.generateNonce();
636
- return this.sw.postMessageWithStatus('ACTIVATE_UPDATE', { statusNonce: statusNonce }, statusNonce);
637
- };
638
- return SwUpdate;
639
- }());
640
- SwUpdate.decorators = [
641
- { type: core.Injectable }
642
- ];
643
- SwUpdate.ctorParameters = function () { return [
644
- { type: NgswCommChannel }
645
- ]; };
646
-
647
- /**
648
- * Token that can be used to provide options for `ServiceWorkerModule` outside of
649
- * `ServiceWorkerModule.register()`.
650
- *
651
- * You can use this token to define a provider that generates the registration options at runtime,
652
- * for example via a function call:
653
- *
654
- * {@example service-worker/registration-options/module.ts region="registration-options"
655
- * header="app.module.ts"}
656
- *
657
- * @publicApi
658
- */
659
- var SwRegistrationOptions = /** @class */ (function () {
660
- function SwRegistrationOptions() {
661
- }
662
- return SwRegistrationOptions;
663
- }());
664
- var SCRIPT = new core.InjectionToken('NGSW_REGISTER_SCRIPT');
665
- function ngswAppInitializer(injector, script, options, platformId) {
666
- var initializer = function () {
667
- if (!(common.isPlatformBrowser(platformId) && ('serviceWorker' in navigator) &&
668
- options.enabled !== false)) {
669
- return;
670
- }
671
- // Wait for service worker controller changes, and fire an INITIALIZE action when a new SW
672
- // becomes active. This allows the SW to initialize itself even if there is no application
673
- // traffic.
674
- navigator.serviceWorker.addEventListener('controllerchange', function () {
675
- if (navigator.serviceWorker.controller !== null) {
676
- navigator.serviceWorker.controller.postMessage({ action: 'INITIALIZE' });
677
- }
678
- });
679
- var readyToRegister$;
680
- if (typeof options.registrationStrategy === 'function') {
681
- readyToRegister$ = options.registrationStrategy();
682
- }
683
- else {
684
- var _a = __read((options.registrationStrategy || 'registerWhenStable:30000').split(':')), strategy = _a[0], args = _a.slice(1);
685
- switch (strategy) {
686
- case 'registerImmediately':
687
- readyToRegister$ = rxjs.of(null);
688
- break;
689
- case 'registerWithDelay':
690
- readyToRegister$ = delayWithTimeout(+args[0] || 0);
691
- break;
692
- case 'registerWhenStable':
693
- readyToRegister$ = !args[0] ? whenStable(injector) :
694
- rxjs.merge(whenStable(injector), delayWithTimeout(+args[0]));
695
- break;
696
- default:
697
- // Unknown strategy.
698
- throw new Error("Unknown ServiceWorker registration strategy: " + options.registrationStrategy);
699
- }
700
- }
701
- // Don't return anything to avoid blocking the application until the SW is registered.
702
- // Also, run outside the Angular zone to avoid preventing the app from stabilizing (especially
703
- // given that some registration strategies wait for the app to stabilize).
704
- // Catch and log the error if SW registration fails to avoid uncaught rejection warning.
705
- var ngZone = injector.get(core.NgZone);
706
- ngZone.runOutsideAngular(function () { return readyToRegister$.pipe(operators.take(1)).subscribe(function () { return navigator.serviceWorker.register(script, { scope: options.scope })
707
- .catch(function (err) { return console.error('Service worker registration failed with:', err); }); }); });
708
- };
709
- return initializer;
710
- }
711
- function delayWithTimeout(timeout) {
712
- return rxjs.of(null).pipe(operators.delay(timeout));
713
- }
714
- function whenStable(injector) {
715
- var appRef = injector.get(core.ApplicationRef);
716
- return appRef.isStable.pipe(operators.filter(function (stable) { return stable; }));
717
- }
718
- function ngswCommChannelFactory(opts, platformId) {
719
- return new NgswCommChannel(common.isPlatformBrowser(platformId) && opts.enabled !== false ? navigator.serviceWorker :
720
- undefined);
721
- }
722
- /**
723
- * @publicApi
724
- */
725
- var ServiceWorkerModule = /** @class */ (function () {
726
- function ServiceWorkerModule() {
727
- }
728
- /**
729
- * Register the given Angular Service Worker script.
730
- *
731
- * If `enabled` is set to `false` in the given options, the module will behave as if service
732
- * workers are not supported by the browser, and the service worker will not be registered.
733
- */
734
- ServiceWorkerModule.register = function (script, opts) {
735
- if (opts === void 0) { opts = {}; }
736
- return {
737
- ngModule: ServiceWorkerModule,
738
- providers: [
739
- { provide: SCRIPT, useValue: script },
740
- { provide: SwRegistrationOptions, useValue: opts },
741
- {
742
- provide: NgswCommChannel,
743
- useFactory: ngswCommChannelFactory,
744
- deps: [SwRegistrationOptions, core.PLATFORM_ID]
745
- },
746
- {
747
- provide: core.APP_INITIALIZER,
748
- useFactory: ngswAppInitializer,
749
- deps: [core.Injector, SCRIPT, SwRegistrationOptions, core.PLATFORM_ID],
750
- multi: true,
751
- },
752
- ],
753
- };
754
- };
755
- return ServiceWorkerModule;
756
- }());
757
- ServiceWorkerModule.decorators = [
758
- { type: core.NgModule, args: [{
759
- providers: [SwPush, SwUpdate],
760
- },] }
761
- ];
762
-
763
- /**
764
- * @license
765
- * Copyright Google LLC All Rights Reserved.
766
- *
767
- * Use of this source code is governed by an MIT-style license that can be
768
- * found in the LICENSE file at https://angular.io/license
769
- */
770
-
771
- /**
772
- * @license
773
- * Copyright Google LLC All Rights Reserved.
774
- *
775
- * Use of this source code is governed by an MIT-style license that can be
776
- * found in the LICENSE file at https://angular.io/license
777
- */
778
- // This file only reexports content of the `src` folder. Keep it that way.
779
-
780
- /**
781
- * @license
782
- * Copyright Google LLC All Rights Reserved.
783
- *
784
- * Use of this source code is governed by an MIT-style license that can be
785
- * found in the LICENSE file at https://angular.io/license
786
- */
787
-
788
- /**
789
- * Generated bundle index. Do not edit.
790
- */
791
-
792
- exports.ServiceWorkerModule = ServiceWorkerModule;
793
- exports.SwPush = SwPush;
794
- exports.SwRegistrationOptions = SwRegistrationOptions;
795
- exports.SwUpdate = SwUpdate;
796
- exports.ɵangular_packages_service_worker_service_worker_a = NgswCommChannel;
797
- exports.ɵangular_packages_service_worker_service_worker_b = SCRIPT;
798
- exports.ɵangular_packages_service_worker_service_worker_c = ngswAppInitializer;
799
- exports.ɵangular_packages_service_worker_service_worker_d = ngswCommChannelFactory;
800
-
801
- Object.defineProperty(exports, '__esModule', { value: true });
802
-
803
- })));
804
- //# sourceMappingURL=service-worker.umd.js.map