@firebase/messaging 0.12.13 → 0.12.14

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 (119) hide show
  1. package/dist/esm/index.esm2017.js +1173 -1173
  2. package/dist/esm/index.esm2017.js.map +1 -1
  3. package/dist/esm/index.sw.esm2017.js +1228 -1228
  4. package/dist/esm/index.sw.esm2017.js.map +1 -1
  5. package/dist/esm/src/api/deleteToken.d.ts +18 -18
  6. package/dist/esm/src/api/getToken.d.ts +19 -19
  7. package/dist/esm/src/api/isSupported.d.ts +30 -30
  8. package/dist/esm/src/api/onBackgroundMessage.d.ts +19 -19
  9. package/dist/esm/src/api/onMessage.d.ts +19 -19
  10. package/dist/esm/src/api/setDeliveryMetricsExportedToBigQueryEnabled.d.ts +18 -18
  11. package/dist/esm/src/api.d.ts +101 -101
  12. package/dist/esm/src/helpers/array-base64-translator.d.ts +18 -18
  13. package/dist/esm/src/helpers/array-base64-translator.test.d.ts +17 -17
  14. package/dist/esm/src/helpers/externalizePayload.d.ts +19 -19
  15. package/dist/esm/src/helpers/externalizePayload.test.d.ts +17 -17
  16. package/dist/esm/src/helpers/extract-app-config.d.ts +19 -19
  17. package/dist/esm/src/helpers/extract-app-config.test.d.ts +17 -17
  18. package/dist/esm/src/helpers/is-console-message.d.ts +18 -18
  19. package/dist/esm/src/helpers/logToFirelog.d.ts +30 -30
  20. package/dist/esm/src/helpers/logToFirelog.test.d.ts +17 -17
  21. package/dist/esm/src/helpers/logToScion.d.ts +19 -19
  22. package/dist/esm/src/helpers/migrate-old-database.d.ts +51 -51
  23. package/dist/esm/src/helpers/migrate-old-database.test.d.ts +17 -17
  24. package/dist/esm/src/helpers/register.d.ts +23 -23
  25. package/dist/esm/src/helpers/registerDefaultSw.d.ts +18 -18
  26. package/dist/esm/src/helpers/sleep.d.ts +18 -18
  27. package/dist/esm/src/helpers/sleep.test.d.ts +17 -17
  28. package/dist/esm/src/helpers/updateSwReg.d.ts +18 -18
  29. package/dist/esm/src/helpers/updateVapidKey.d.ts +18 -18
  30. package/dist/esm/src/index.d.ts +32 -32
  31. package/dist/esm/src/index.sw.d.ts +26 -26
  32. package/dist/esm/src/interfaces/app-config.d.ts +24 -24
  33. package/dist/esm/src/interfaces/internal-dependencies.d.ts +27 -27
  34. package/dist/esm/src/interfaces/internal-message-payload.d.ts +65 -46
  35. package/dist/esm/src/interfaces/logging-types.d.ts +60 -60
  36. package/dist/esm/src/interfaces/public-types.d.ts +144 -144
  37. package/dist/esm/src/interfaces/token-details.d.ts +32 -32
  38. package/dist/esm/src/internals/idb-manager.d.ts +27 -27
  39. package/dist/esm/src/internals/idb-manager.test.d.ts +17 -17
  40. package/dist/esm/src/internals/requests.d.ts +35 -35
  41. package/dist/esm/src/internals/requests.test.d.ts +17 -17
  42. package/dist/esm/src/internals/token-manager.d.ts +23 -23
  43. package/dist/esm/src/internals/token-manager.test.d.ts +17 -17
  44. package/dist/esm/src/listeners/sw-listeners.d.ts +21 -21
  45. package/dist/esm/src/listeners/sw-listeners.test.d.ts +17 -17
  46. package/dist/esm/src/listeners/window-listener.d.ts +18 -18
  47. package/dist/esm/src/messaging-service.d.ts +36 -36
  48. package/dist/esm/src/testing/compare-headers.d.ts +22 -22
  49. package/dist/esm/src/testing/compare-headers.test.d.ts +17 -17
  50. package/dist/esm/src/testing/fakes/firebase-dependencies.d.ts +25 -25
  51. package/dist/esm/src/testing/fakes/logging-object.d.ts +18 -18
  52. package/dist/esm/src/testing/fakes/messaging-service.d.ts +18 -18
  53. package/dist/esm/src/testing/fakes/service-worker.d.ts +83 -83
  54. package/dist/esm/src/testing/fakes/token-details.d.ts +18 -18
  55. package/dist/esm/src/testing/setup.d.ts +17 -17
  56. package/dist/esm/src/testing/sinon-types.d.ts +19 -19
  57. package/dist/esm/src/util/constants.d.ts +39 -39
  58. package/dist/esm/src/util/errors.d.ts +57 -57
  59. package/dist/esm/src/util/sw-types.d.ts +90 -90
  60. package/dist/index.cjs.js +1173 -1173
  61. package/dist/index.cjs.js.map +1 -1
  62. package/dist/index.sw.cjs +1228 -1228
  63. package/dist/index.sw.cjs.map +1 -1
  64. package/dist/src/api/deleteToken.d.ts +18 -18
  65. package/dist/src/api/getToken.d.ts +19 -19
  66. package/dist/src/api/isSupported.d.ts +30 -30
  67. package/dist/src/api/onBackgroundMessage.d.ts +19 -19
  68. package/dist/src/api/onMessage.d.ts +19 -19
  69. package/dist/src/api/setDeliveryMetricsExportedToBigQueryEnabled.d.ts +18 -18
  70. package/dist/src/api.d.ts +101 -101
  71. package/dist/src/helpers/array-base64-translator.d.ts +18 -18
  72. package/dist/src/helpers/array-base64-translator.test.d.ts +17 -17
  73. package/dist/src/helpers/externalizePayload.d.ts +19 -19
  74. package/dist/src/helpers/externalizePayload.test.d.ts +17 -17
  75. package/dist/src/helpers/extract-app-config.d.ts +19 -19
  76. package/dist/src/helpers/extract-app-config.test.d.ts +17 -17
  77. package/dist/src/helpers/is-console-message.d.ts +18 -18
  78. package/dist/src/helpers/logToFirelog.d.ts +30 -30
  79. package/dist/src/helpers/logToFirelog.test.d.ts +17 -17
  80. package/dist/src/helpers/logToScion.d.ts +19 -19
  81. package/dist/src/helpers/migrate-old-database.d.ts +51 -51
  82. package/dist/src/helpers/migrate-old-database.test.d.ts +17 -17
  83. package/dist/src/helpers/register.d.ts +23 -23
  84. package/dist/src/helpers/registerDefaultSw.d.ts +18 -18
  85. package/dist/src/helpers/sleep.d.ts +18 -18
  86. package/dist/src/helpers/sleep.test.d.ts +17 -17
  87. package/dist/src/helpers/updateSwReg.d.ts +18 -18
  88. package/dist/src/helpers/updateVapidKey.d.ts +18 -18
  89. package/dist/src/index.d.ts +32 -32
  90. package/dist/src/index.sw.d.ts +26 -26
  91. package/dist/src/interfaces/app-config.d.ts +24 -24
  92. package/dist/src/interfaces/internal-dependencies.d.ts +27 -27
  93. package/dist/src/interfaces/internal-message-payload.d.ts +65 -46
  94. package/dist/src/interfaces/logging-types.d.ts +60 -60
  95. package/dist/src/interfaces/public-types.d.ts +144 -144
  96. package/dist/src/interfaces/token-details.d.ts +32 -32
  97. package/dist/src/internals/idb-manager.d.ts +27 -27
  98. package/dist/src/internals/idb-manager.test.d.ts +17 -17
  99. package/dist/src/internals/requests.d.ts +35 -35
  100. package/dist/src/internals/requests.test.d.ts +17 -17
  101. package/dist/src/internals/token-manager.d.ts +23 -23
  102. package/dist/src/internals/token-manager.test.d.ts +17 -17
  103. package/dist/src/listeners/sw-listeners.d.ts +21 -21
  104. package/dist/src/listeners/sw-listeners.test.d.ts +17 -17
  105. package/dist/src/listeners/window-listener.d.ts +18 -18
  106. package/dist/src/messaging-service.d.ts +36 -36
  107. package/dist/src/testing/compare-headers.d.ts +22 -22
  108. package/dist/src/testing/compare-headers.test.d.ts +17 -17
  109. package/dist/src/testing/fakes/firebase-dependencies.d.ts +25 -25
  110. package/dist/src/testing/fakes/logging-object.d.ts +18 -18
  111. package/dist/src/testing/fakes/messaging-service.d.ts +18 -18
  112. package/dist/src/testing/fakes/service-worker.d.ts +83 -83
  113. package/dist/src/testing/fakes/token-details.d.ts +18 -18
  114. package/dist/src/testing/setup.d.ts +17 -17
  115. package/dist/src/testing/sinon-types.d.ts +19 -19
  116. package/dist/src/util/constants.d.ts +39 -39
  117. package/dist/src/util/errors.d.ts +57 -57
  118. package/dist/src/util/sw-types.d.ts +90 -90
  119. package/package.json +8 -8
@@ -4,1274 +4,1274 @@ import { openDB, deleteDB } from 'idb';
4
4
  import { ErrorFactory, isIndexedDBAvailable, validateIndexedDBOpenable, getModularInstance } from '@firebase/util';
5
5
  import { _registerComponent, _getProvider, getApp } from '@firebase/app';
6
6
 
7
- /**
8
- * @license
9
- * Copyright 2019 Google LLC
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License.
22
- */
23
- const DEFAULT_VAPID_KEY = 'BDOU99-h67HcA6JeFXHbSNMu7e2yNNu3RzoMj8TM4W88jITfq7ZmPvIM1Iv-4_l2LxQcYwhqby2xGpWwzjfAnG4';
24
- const ENDPOINT = 'https://fcmregistrations.googleapis.com/v1';
25
- /** Key of FCM Payload in Notification's data field. */
26
- const FCM_MSG = 'FCM_MSG';
27
- const CONSOLE_CAMPAIGN_ID = 'google.c.a.c_id';
28
- // Defined as in proto/messaging_event.proto. Neglecting fields that are supported.
29
- const SDK_PLATFORM_WEB = 3;
30
- const EVENT_MESSAGE_DELIVERED = 1;
31
- var MessageType$1;
32
- (function (MessageType) {
33
- MessageType[MessageType["DATA_MESSAGE"] = 1] = "DATA_MESSAGE";
34
- MessageType[MessageType["DISPLAY_NOTIFICATION"] = 3] = "DISPLAY_NOTIFICATION";
7
+ /**
8
+ * @license
9
+ * Copyright 2019 Google LLC
10
+ *
11
+ * Licensed under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License.
13
+ * You may obtain a copy of the License at
14
+ *
15
+ * http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ */
23
+ const DEFAULT_VAPID_KEY = 'BDOU99-h67HcA6JeFXHbSNMu7e2yNNu3RzoMj8TM4W88jITfq7ZmPvIM1Iv-4_l2LxQcYwhqby2xGpWwzjfAnG4';
24
+ const ENDPOINT = 'https://fcmregistrations.googleapis.com/v1';
25
+ /** Key of FCM Payload in Notification's data field. */
26
+ const FCM_MSG = 'FCM_MSG';
27
+ const CONSOLE_CAMPAIGN_ID = 'google.c.a.c_id';
28
+ // Defined as in proto/messaging_event.proto. Neglecting fields that are supported.
29
+ const SDK_PLATFORM_WEB = 3;
30
+ const EVENT_MESSAGE_DELIVERED = 1;
31
+ var MessageType$1;
32
+ (function (MessageType) {
33
+ MessageType[MessageType["DATA_MESSAGE"] = 1] = "DATA_MESSAGE";
34
+ MessageType[MessageType["DISPLAY_NOTIFICATION"] = 3] = "DISPLAY_NOTIFICATION";
35
35
  })(MessageType$1 || (MessageType$1 = {}));
36
36
 
37
- /**
38
- * @license
39
- * Copyright 2018 Google LLC
40
- *
41
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
42
- * in compliance with the License. You may obtain a copy of the License at
43
- *
44
- * http://www.apache.org/licenses/LICENSE-2.0
45
- *
46
- * Unless required by applicable law or agreed to in writing, software distributed under the License
47
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
48
- * or implied. See the License for the specific language governing permissions and limitations under
49
- * the License.
50
- */
51
- var MessageType;
52
- (function (MessageType) {
53
- MessageType["PUSH_RECEIVED"] = "push-received";
54
- MessageType["NOTIFICATION_CLICKED"] = "notification-clicked";
37
+ /**
38
+ * @license
39
+ * Copyright 2018 Google LLC
40
+ *
41
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
42
+ * in compliance with the License. You may obtain a copy of the License at
43
+ *
44
+ * http://www.apache.org/licenses/LICENSE-2.0
45
+ *
46
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
47
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
48
+ * or implied. See the License for the specific language governing permissions and limitations under
49
+ * the License.
50
+ */
51
+ var MessageType;
52
+ (function (MessageType) {
53
+ MessageType["PUSH_RECEIVED"] = "push-received";
54
+ MessageType["NOTIFICATION_CLICKED"] = "notification-clicked";
55
55
  })(MessageType || (MessageType = {}));
56
56
 
57
- /**
58
- * @license
59
- * Copyright 2017 Google LLC
60
- *
61
- * Licensed under the Apache License, Version 2.0 (the "License");
62
- * you may not use this file except in compliance with the License.
63
- * You may obtain a copy of the License at
64
- *
65
- * http://www.apache.org/licenses/LICENSE-2.0
66
- *
67
- * Unless required by applicable law or agreed to in writing, software
68
- * distributed under the License is distributed on an "AS IS" BASIS,
69
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
70
- * See the License for the specific language governing permissions and
71
- * limitations under the License.
72
- */
73
- function arrayToBase64(array) {
74
- const uint8Array = new Uint8Array(array);
75
- const base64String = btoa(String.fromCharCode(...uint8Array));
76
- return base64String.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
77
- }
78
- function base64ToArray(base64String) {
79
- const padding = '='.repeat((4 - (base64String.length % 4)) % 4);
80
- const base64 = (base64String + padding)
81
- .replace(/\-/g, '+')
82
- .replace(/_/g, '/');
83
- const rawData = atob(base64);
84
- const outputArray = new Uint8Array(rawData.length);
85
- for (let i = 0; i < rawData.length; ++i) {
86
- outputArray[i] = rawData.charCodeAt(i);
87
- }
88
- return outputArray;
57
+ /**
58
+ * @license
59
+ * Copyright 2017 Google LLC
60
+ *
61
+ * Licensed under the Apache License, Version 2.0 (the "License");
62
+ * you may not use this file except in compliance with the License.
63
+ * You may obtain a copy of the License at
64
+ *
65
+ * http://www.apache.org/licenses/LICENSE-2.0
66
+ *
67
+ * Unless required by applicable law or agreed to in writing, software
68
+ * distributed under the License is distributed on an "AS IS" BASIS,
69
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
70
+ * See the License for the specific language governing permissions and
71
+ * limitations under the License.
72
+ */
73
+ function arrayToBase64(array) {
74
+ const uint8Array = new Uint8Array(array);
75
+ const base64String = btoa(String.fromCharCode(...uint8Array));
76
+ return base64String.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
77
+ }
78
+ function base64ToArray(base64String) {
79
+ const padding = '='.repeat((4 - (base64String.length % 4)) % 4);
80
+ const base64 = (base64String + padding)
81
+ .replace(/\-/g, '+')
82
+ .replace(/_/g, '/');
83
+ const rawData = atob(base64);
84
+ const outputArray = new Uint8Array(rawData.length);
85
+ for (let i = 0; i < rawData.length; ++i) {
86
+ outputArray[i] = rawData.charCodeAt(i);
87
+ }
88
+ return outputArray;
89
89
  }
90
90
 
91
- /**
92
- * @license
93
- * Copyright 2019 Google LLC
94
- *
95
- * Licensed under the Apache License, Version 2.0 (the "License");
96
- * you may not use this file except in compliance with the License.
97
- * You may obtain a copy of the License at
98
- *
99
- * http://www.apache.org/licenses/LICENSE-2.0
100
- *
101
- * Unless required by applicable law or agreed to in writing, software
102
- * distributed under the License is distributed on an "AS IS" BASIS,
103
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
104
- * See the License for the specific language governing permissions and
105
- * limitations under the License.
106
- */
107
- const OLD_DB_NAME = 'fcm_token_details_db';
108
- /**
109
- * The last DB version of 'fcm_token_details_db' was 4. This is one higher, so that the upgrade
110
- * callback is called for all versions of the old DB.
111
- */
112
- const OLD_DB_VERSION = 5;
113
- const OLD_OBJECT_STORE_NAME = 'fcm_token_object_Store';
114
- async function migrateOldDatabase(senderId) {
115
- if ('databases' in indexedDB) {
116
- // indexedDb.databases() is an IndexedDB v3 API and does not exist in all browsers. TODO: Remove
117
- // typecast when it lands in TS types.
118
- const databases = await indexedDB.databases();
119
- const dbNames = databases.map(db => db.name);
120
- if (!dbNames.includes(OLD_DB_NAME)) {
121
- // old DB didn't exist, no need to open.
122
- return null;
123
- }
124
- }
125
- let tokenDetails = null;
126
- const db = await openDB(OLD_DB_NAME, OLD_DB_VERSION, {
127
- upgrade: async (db, oldVersion, newVersion, upgradeTransaction) => {
128
- var _a;
129
- if (oldVersion < 2) {
130
- // Database too old, skip migration.
131
- return;
132
- }
133
- if (!db.objectStoreNames.contains(OLD_OBJECT_STORE_NAME)) {
134
- // Database did not exist. Nothing to do.
135
- return;
136
- }
137
- const objectStore = upgradeTransaction.objectStore(OLD_OBJECT_STORE_NAME);
138
- const value = await objectStore.index('fcmSenderId').get(senderId);
139
- await objectStore.clear();
140
- if (!value) {
141
- // No entry in the database, nothing to migrate.
142
- return;
143
- }
144
- if (oldVersion === 2) {
145
- const oldDetails = value;
146
- if (!oldDetails.auth || !oldDetails.p256dh || !oldDetails.endpoint) {
147
- return;
148
- }
149
- tokenDetails = {
150
- token: oldDetails.fcmToken,
151
- createTime: (_a = oldDetails.createTime) !== null && _a !== void 0 ? _a : Date.now(),
152
- subscriptionOptions: {
153
- auth: oldDetails.auth,
154
- p256dh: oldDetails.p256dh,
155
- endpoint: oldDetails.endpoint,
156
- swScope: oldDetails.swScope,
157
- vapidKey: typeof oldDetails.vapidKey === 'string'
158
- ? oldDetails.vapidKey
159
- : arrayToBase64(oldDetails.vapidKey)
160
- }
161
- };
162
- }
163
- else if (oldVersion === 3) {
164
- const oldDetails = value;
165
- tokenDetails = {
166
- token: oldDetails.fcmToken,
167
- createTime: oldDetails.createTime,
168
- subscriptionOptions: {
169
- auth: arrayToBase64(oldDetails.auth),
170
- p256dh: arrayToBase64(oldDetails.p256dh),
171
- endpoint: oldDetails.endpoint,
172
- swScope: oldDetails.swScope,
173
- vapidKey: arrayToBase64(oldDetails.vapidKey)
174
- }
175
- };
176
- }
177
- else if (oldVersion === 4) {
178
- const oldDetails = value;
179
- tokenDetails = {
180
- token: oldDetails.fcmToken,
181
- createTime: oldDetails.createTime,
182
- subscriptionOptions: {
183
- auth: arrayToBase64(oldDetails.auth),
184
- p256dh: arrayToBase64(oldDetails.p256dh),
185
- endpoint: oldDetails.endpoint,
186
- swScope: oldDetails.swScope,
187
- vapidKey: arrayToBase64(oldDetails.vapidKey)
188
- }
189
- };
190
- }
191
- }
192
- });
193
- db.close();
194
- // Delete all old databases.
195
- await deleteDB(OLD_DB_NAME);
196
- await deleteDB('fcm_vapid_details_db');
197
- await deleteDB('undefined');
198
- return checkTokenDetails(tokenDetails) ? tokenDetails : null;
199
- }
200
- function checkTokenDetails(tokenDetails) {
201
- if (!tokenDetails || !tokenDetails.subscriptionOptions) {
202
- return false;
203
- }
204
- const { subscriptionOptions } = tokenDetails;
205
- return (typeof tokenDetails.createTime === 'number' &&
206
- tokenDetails.createTime > 0 &&
207
- typeof tokenDetails.token === 'string' &&
208
- tokenDetails.token.length > 0 &&
209
- typeof subscriptionOptions.auth === 'string' &&
210
- subscriptionOptions.auth.length > 0 &&
211
- typeof subscriptionOptions.p256dh === 'string' &&
212
- subscriptionOptions.p256dh.length > 0 &&
213
- typeof subscriptionOptions.endpoint === 'string' &&
214
- subscriptionOptions.endpoint.length > 0 &&
215
- typeof subscriptionOptions.swScope === 'string' &&
216
- subscriptionOptions.swScope.length > 0 &&
217
- typeof subscriptionOptions.vapidKey === 'string' &&
218
- subscriptionOptions.vapidKey.length > 0);
91
+ /**
92
+ * @license
93
+ * Copyright 2019 Google LLC
94
+ *
95
+ * Licensed under the Apache License, Version 2.0 (the "License");
96
+ * you may not use this file except in compliance with the License.
97
+ * You may obtain a copy of the License at
98
+ *
99
+ * http://www.apache.org/licenses/LICENSE-2.0
100
+ *
101
+ * Unless required by applicable law or agreed to in writing, software
102
+ * distributed under the License is distributed on an "AS IS" BASIS,
103
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
104
+ * See the License for the specific language governing permissions and
105
+ * limitations under the License.
106
+ */
107
+ const OLD_DB_NAME = 'fcm_token_details_db';
108
+ /**
109
+ * The last DB version of 'fcm_token_details_db' was 4. This is one higher, so that the upgrade
110
+ * callback is called for all versions of the old DB.
111
+ */
112
+ const OLD_DB_VERSION = 5;
113
+ const OLD_OBJECT_STORE_NAME = 'fcm_token_object_Store';
114
+ async function migrateOldDatabase(senderId) {
115
+ if ('databases' in indexedDB) {
116
+ // indexedDb.databases() is an IndexedDB v3 API and does not exist in all browsers. TODO: Remove
117
+ // typecast when it lands in TS types.
118
+ const databases = await indexedDB.databases();
119
+ const dbNames = databases.map(db => db.name);
120
+ if (!dbNames.includes(OLD_DB_NAME)) {
121
+ // old DB didn't exist, no need to open.
122
+ return null;
123
+ }
124
+ }
125
+ let tokenDetails = null;
126
+ const db = await openDB(OLD_DB_NAME, OLD_DB_VERSION, {
127
+ upgrade: async (db, oldVersion, newVersion, upgradeTransaction) => {
128
+ var _a;
129
+ if (oldVersion < 2) {
130
+ // Database too old, skip migration.
131
+ return;
132
+ }
133
+ if (!db.objectStoreNames.contains(OLD_OBJECT_STORE_NAME)) {
134
+ // Database did not exist. Nothing to do.
135
+ return;
136
+ }
137
+ const objectStore = upgradeTransaction.objectStore(OLD_OBJECT_STORE_NAME);
138
+ const value = await objectStore.index('fcmSenderId').get(senderId);
139
+ await objectStore.clear();
140
+ if (!value) {
141
+ // No entry in the database, nothing to migrate.
142
+ return;
143
+ }
144
+ if (oldVersion === 2) {
145
+ const oldDetails = value;
146
+ if (!oldDetails.auth || !oldDetails.p256dh || !oldDetails.endpoint) {
147
+ return;
148
+ }
149
+ tokenDetails = {
150
+ token: oldDetails.fcmToken,
151
+ createTime: (_a = oldDetails.createTime) !== null && _a !== void 0 ? _a : Date.now(),
152
+ subscriptionOptions: {
153
+ auth: oldDetails.auth,
154
+ p256dh: oldDetails.p256dh,
155
+ endpoint: oldDetails.endpoint,
156
+ swScope: oldDetails.swScope,
157
+ vapidKey: typeof oldDetails.vapidKey === 'string'
158
+ ? oldDetails.vapidKey
159
+ : arrayToBase64(oldDetails.vapidKey)
160
+ }
161
+ };
162
+ }
163
+ else if (oldVersion === 3) {
164
+ const oldDetails = value;
165
+ tokenDetails = {
166
+ token: oldDetails.fcmToken,
167
+ createTime: oldDetails.createTime,
168
+ subscriptionOptions: {
169
+ auth: arrayToBase64(oldDetails.auth),
170
+ p256dh: arrayToBase64(oldDetails.p256dh),
171
+ endpoint: oldDetails.endpoint,
172
+ swScope: oldDetails.swScope,
173
+ vapidKey: arrayToBase64(oldDetails.vapidKey)
174
+ }
175
+ };
176
+ }
177
+ else if (oldVersion === 4) {
178
+ const oldDetails = value;
179
+ tokenDetails = {
180
+ token: oldDetails.fcmToken,
181
+ createTime: oldDetails.createTime,
182
+ subscriptionOptions: {
183
+ auth: arrayToBase64(oldDetails.auth),
184
+ p256dh: arrayToBase64(oldDetails.p256dh),
185
+ endpoint: oldDetails.endpoint,
186
+ swScope: oldDetails.swScope,
187
+ vapidKey: arrayToBase64(oldDetails.vapidKey)
188
+ }
189
+ };
190
+ }
191
+ }
192
+ });
193
+ db.close();
194
+ // Delete all old databases.
195
+ await deleteDB(OLD_DB_NAME);
196
+ await deleteDB('fcm_vapid_details_db');
197
+ await deleteDB('undefined');
198
+ return checkTokenDetails(tokenDetails) ? tokenDetails : null;
199
+ }
200
+ function checkTokenDetails(tokenDetails) {
201
+ if (!tokenDetails || !tokenDetails.subscriptionOptions) {
202
+ return false;
203
+ }
204
+ const { subscriptionOptions } = tokenDetails;
205
+ return (typeof tokenDetails.createTime === 'number' &&
206
+ tokenDetails.createTime > 0 &&
207
+ typeof tokenDetails.token === 'string' &&
208
+ tokenDetails.token.length > 0 &&
209
+ typeof subscriptionOptions.auth === 'string' &&
210
+ subscriptionOptions.auth.length > 0 &&
211
+ typeof subscriptionOptions.p256dh === 'string' &&
212
+ subscriptionOptions.p256dh.length > 0 &&
213
+ typeof subscriptionOptions.endpoint === 'string' &&
214
+ subscriptionOptions.endpoint.length > 0 &&
215
+ typeof subscriptionOptions.swScope === 'string' &&
216
+ subscriptionOptions.swScope.length > 0 &&
217
+ typeof subscriptionOptions.vapidKey === 'string' &&
218
+ subscriptionOptions.vapidKey.length > 0);
219
219
  }
220
220
 
221
- /**
222
- * @license
223
- * Copyright 2019 Google LLC
224
- *
225
- * Licensed under the Apache License, Version 2.0 (the "License");
226
- * you may not use this file except in compliance with the License.
227
- * You may obtain a copy of the License at
228
- *
229
- * http://www.apache.org/licenses/LICENSE-2.0
230
- *
231
- * Unless required by applicable law or agreed to in writing, software
232
- * distributed under the License is distributed on an "AS IS" BASIS,
233
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
234
- * See the License for the specific language governing permissions and
235
- * limitations under the License.
236
- */
237
- // Exported for tests.
238
- const DATABASE_NAME = 'firebase-messaging-database';
239
- const DATABASE_VERSION = 1;
240
- const OBJECT_STORE_NAME = 'firebase-messaging-store';
241
- let dbPromise = null;
242
- function getDbPromise() {
243
- if (!dbPromise) {
244
- dbPromise = openDB(DATABASE_NAME, DATABASE_VERSION, {
245
- upgrade: (upgradeDb, oldVersion) => {
246
- // We don't use 'break' in this switch statement, the fall-through behavior is what we want,
247
- // because if there are multiple versions between the old version and the current version, we
248
- // want ALL the migrations that correspond to those versions to run, not only the last one.
249
- // eslint-disable-next-line default-case
250
- switch (oldVersion) {
251
- case 0:
252
- upgradeDb.createObjectStore(OBJECT_STORE_NAME);
253
- }
254
- }
255
- });
256
- }
257
- return dbPromise;
258
- }
259
- /** Gets record(s) from the objectStore that match the given key. */
260
- async function dbGet(firebaseDependencies) {
261
- const key = getKey(firebaseDependencies);
262
- const db = await getDbPromise();
263
- const tokenDetails = (await db
264
- .transaction(OBJECT_STORE_NAME)
265
- .objectStore(OBJECT_STORE_NAME)
266
- .get(key));
267
- if (tokenDetails) {
268
- return tokenDetails;
269
- }
270
- else {
271
- // Check if there is a tokenDetails object in the old DB.
272
- const oldTokenDetails = await migrateOldDatabase(firebaseDependencies.appConfig.senderId);
273
- if (oldTokenDetails) {
274
- await dbSet(firebaseDependencies, oldTokenDetails);
275
- return oldTokenDetails;
276
- }
277
- }
278
- }
279
- /** Assigns or overwrites the record for the given key with the given value. */
280
- async function dbSet(firebaseDependencies, tokenDetails) {
281
- const key = getKey(firebaseDependencies);
282
- const db = await getDbPromise();
283
- const tx = db.transaction(OBJECT_STORE_NAME, 'readwrite');
284
- await tx.objectStore(OBJECT_STORE_NAME).put(tokenDetails, key);
285
- await tx.done;
286
- return tokenDetails;
287
- }
288
- /** Removes record(s) from the objectStore that match the given key. */
289
- async function dbRemove(firebaseDependencies) {
290
- const key = getKey(firebaseDependencies);
291
- const db = await getDbPromise();
292
- const tx = db.transaction(OBJECT_STORE_NAME, 'readwrite');
293
- await tx.objectStore(OBJECT_STORE_NAME).delete(key);
294
- await tx.done;
295
- }
296
- function getKey({ appConfig }) {
297
- return appConfig.appId;
221
+ /**
222
+ * @license
223
+ * Copyright 2019 Google LLC
224
+ *
225
+ * Licensed under the Apache License, Version 2.0 (the "License");
226
+ * you may not use this file except in compliance with the License.
227
+ * You may obtain a copy of the License at
228
+ *
229
+ * http://www.apache.org/licenses/LICENSE-2.0
230
+ *
231
+ * Unless required by applicable law or agreed to in writing, software
232
+ * distributed under the License is distributed on an "AS IS" BASIS,
233
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
234
+ * See the License for the specific language governing permissions and
235
+ * limitations under the License.
236
+ */
237
+ // Exported for tests.
238
+ const DATABASE_NAME = 'firebase-messaging-database';
239
+ const DATABASE_VERSION = 1;
240
+ const OBJECT_STORE_NAME = 'firebase-messaging-store';
241
+ let dbPromise = null;
242
+ function getDbPromise() {
243
+ if (!dbPromise) {
244
+ dbPromise = openDB(DATABASE_NAME, DATABASE_VERSION, {
245
+ upgrade: (upgradeDb, oldVersion) => {
246
+ // We don't use 'break' in this switch statement, the fall-through behavior is what we want,
247
+ // because if there are multiple versions between the old version and the current version, we
248
+ // want ALL the migrations that correspond to those versions to run, not only the last one.
249
+ // eslint-disable-next-line default-case
250
+ switch (oldVersion) {
251
+ case 0:
252
+ upgradeDb.createObjectStore(OBJECT_STORE_NAME);
253
+ }
254
+ }
255
+ });
256
+ }
257
+ return dbPromise;
258
+ }
259
+ /** Gets record(s) from the objectStore that match the given key. */
260
+ async function dbGet(firebaseDependencies) {
261
+ const key = getKey(firebaseDependencies);
262
+ const db = await getDbPromise();
263
+ const tokenDetails = (await db
264
+ .transaction(OBJECT_STORE_NAME)
265
+ .objectStore(OBJECT_STORE_NAME)
266
+ .get(key));
267
+ if (tokenDetails) {
268
+ return tokenDetails;
269
+ }
270
+ else {
271
+ // Check if there is a tokenDetails object in the old DB.
272
+ const oldTokenDetails = await migrateOldDatabase(firebaseDependencies.appConfig.senderId);
273
+ if (oldTokenDetails) {
274
+ await dbSet(firebaseDependencies, oldTokenDetails);
275
+ return oldTokenDetails;
276
+ }
277
+ }
278
+ }
279
+ /** Assigns or overwrites the record for the given key with the given value. */
280
+ async function dbSet(firebaseDependencies, tokenDetails) {
281
+ const key = getKey(firebaseDependencies);
282
+ const db = await getDbPromise();
283
+ const tx = db.transaction(OBJECT_STORE_NAME, 'readwrite');
284
+ await tx.objectStore(OBJECT_STORE_NAME).put(tokenDetails, key);
285
+ await tx.done;
286
+ return tokenDetails;
287
+ }
288
+ /** Removes record(s) from the objectStore that match the given key. */
289
+ async function dbRemove(firebaseDependencies) {
290
+ const key = getKey(firebaseDependencies);
291
+ const db = await getDbPromise();
292
+ const tx = db.transaction(OBJECT_STORE_NAME, 'readwrite');
293
+ await tx.objectStore(OBJECT_STORE_NAME).delete(key);
294
+ await tx.done;
295
+ }
296
+ function getKey({ appConfig }) {
297
+ return appConfig.appId;
298
298
  }
299
299
 
300
- /**
301
- * @license
302
- * Copyright 2017 Google LLC
303
- *
304
- * Licensed under the Apache License, Version 2.0 (the "License");
305
- * you may not use this file except in compliance with the License.
306
- * You may obtain a copy of the License at
307
- *
308
- * http://www.apache.org/licenses/LICENSE-2.0
309
- *
310
- * Unless required by applicable law or agreed to in writing, software
311
- * distributed under the License is distributed on an "AS IS" BASIS,
312
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
313
- * See the License for the specific language governing permissions and
314
- * limitations under the License.
315
- */
316
- const ERROR_MAP = {
317
- ["missing-app-config-values" /* ErrorCode.MISSING_APP_CONFIG_VALUES */]: 'Missing App configuration value: "{$valueName}"',
318
- ["only-available-in-window" /* ErrorCode.AVAILABLE_IN_WINDOW */]: 'This method is available in a Window context.',
319
- ["only-available-in-sw" /* ErrorCode.AVAILABLE_IN_SW */]: 'This method is available in a service worker context.',
320
- ["permission-default" /* ErrorCode.PERMISSION_DEFAULT */]: 'The notification permission was not granted and dismissed instead.',
321
- ["permission-blocked" /* ErrorCode.PERMISSION_BLOCKED */]: 'The notification permission was not granted and blocked instead.',
322
- ["unsupported-browser" /* ErrorCode.UNSUPPORTED_BROWSER */]: "This browser doesn't support the API's required to use the Firebase SDK.",
323
- ["indexed-db-unsupported" /* ErrorCode.INDEXED_DB_UNSUPPORTED */]: "This browser doesn't support indexedDb.open() (ex. Safari iFrame, Firefox Private Browsing, etc)",
324
- ["failed-service-worker-registration" /* ErrorCode.FAILED_DEFAULT_REGISTRATION */]: 'We are unable to register the default service worker. {$browserErrorMessage}',
325
- ["token-subscribe-failed" /* ErrorCode.TOKEN_SUBSCRIBE_FAILED */]: 'A problem occurred while subscribing the user to FCM: {$errorInfo}',
326
- ["token-subscribe-no-token" /* ErrorCode.TOKEN_SUBSCRIBE_NO_TOKEN */]: 'FCM returned no token when subscribing the user to push.',
327
- ["token-unsubscribe-failed" /* ErrorCode.TOKEN_UNSUBSCRIBE_FAILED */]: 'A problem occurred while unsubscribing the ' +
328
- 'user from FCM: {$errorInfo}',
329
- ["token-update-failed" /* ErrorCode.TOKEN_UPDATE_FAILED */]: 'A problem occurred while updating the user from FCM: {$errorInfo}',
330
- ["token-update-no-token" /* ErrorCode.TOKEN_UPDATE_NO_TOKEN */]: 'FCM returned no token when updating the user to push.',
331
- ["use-sw-after-get-token" /* ErrorCode.USE_SW_AFTER_GET_TOKEN */]: 'The useServiceWorker() method may only be called once and must be ' +
332
- 'called before calling getToken() to ensure your service worker is used.',
333
- ["invalid-sw-registration" /* ErrorCode.INVALID_SW_REGISTRATION */]: 'The input to useServiceWorker() must be a ServiceWorkerRegistration.',
334
- ["invalid-bg-handler" /* ErrorCode.INVALID_BG_HANDLER */]: 'The input to setBackgroundMessageHandler() must be a function.',
335
- ["invalid-vapid-key" /* ErrorCode.INVALID_VAPID_KEY */]: 'The public VAPID key must be a string.',
336
- ["use-vapid-key-after-get-token" /* ErrorCode.USE_VAPID_KEY_AFTER_GET_TOKEN */]: 'The usePublicVapidKey() method may only be called once and must be ' +
337
- 'called before calling getToken() to ensure your VAPID key is used.'
338
- };
300
+ /**
301
+ * @license
302
+ * Copyright 2017 Google LLC
303
+ *
304
+ * Licensed under the Apache License, Version 2.0 (the "License");
305
+ * you may not use this file except in compliance with the License.
306
+ * You may obtain a copy of the License at
307
+ *
308
+ * http://www.apache.org/licenses/LICENSE-2.0
309
+ *
310
+ * Unless required by applicable law or agreed to in writing, software
311
+ * distributed under the License is distributed on an "AS IS" BASIS,
312
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
313
+ * See the License for the specific language governing permissions and
314
+ * limitations under the License.
315
+ */
316
+ const ERROR_MAP = {
317
+ ["missing-app-config-values" /* ErrorCode.MISSING_APP_CONFIG_VALUES */]: 'Missing App configuration value: "{$valueName}"',
318
+ ["only-available-in-window" /* ErrorCode.AVAILABLE_IN_WINDOW */]: 'This method is available in a Window context.',
319
+ ["only-available-in-sw" /* ErrorCode.AVAILABLE_IN_SW */]: 'This method is available in a service worker context.',
320
+ ["permission-default" /* ErrorCode.PERMISSION_DEFAULT */]: 'The notification permission was not granted and dismissed instead.',
321
+ ["permission-blocked" /* ErrorCode.PERMISSION_BLOCKED */]: 'The notification permission was not granted and blocked instead.',
322
+ ["unsupported-browser" /* ErrorCode.UNSUPPORTED_BROWSER */]: "This browser doesn't support the API's required to use the Firebase SDK.",
323
+ ["indexed-db-unsupported" /* ErrorCode.INDEXED_DB_UNSUPPORTED */]: "This browser doesn't support indexedDb.open() (ex. Safari iFrame, Firefox Private Browsing, etc)",
324
+ ["failed-service-worker-registration" /* ErrorCode.FAILED_DEFAULT_REGISTRATION */]: 'We are unable to register the default service worker. {$browserErrorMessage}',
325
+ ["token-subscribe-failed" /* ErrorCode.TOKEN_SUBSCRIBE_FAILED */]: 'A problem occurred while subscribing the user to FCM: {$errorInfo}',
326
+ ["token-subscribe-no-token" /* ErrorCode.TOKEN_SUBSCRIBE_NO_TOKEN */]: 'FCM returned no token when subscribing the user to push.',
327
+ ["token-unsubscribe-failed" /* ErrorCode.TOKEN_UNSUBSCRIBE_FAILED */]: 'A problem occurred while unsubscribing the ' +
328
+ 'user from FCM: {$errorInfo}',
329
+ ["token-update-failed" /* ErrorCode.TOKEN_UPDATE_FAILED */]: 'A problem occurred while updating the user from FCM: {$errorInfo}',
330
+ ["token-update-no-token" /* ErrorCode.TOKEN_UPDATE_NO_TOKEN */]: 'FCM returned no token when updating the user to push.',
331
+ ["use-sw-after-get-token" /* ErrorCode.USE_SW_AFTER_GET_TOKEN */]: 'The useServiceWorker() method may only be called once and must be ' +
332
+ 'called before calling getToken() to ensure your service worker is used.',
333
+ ["invalid-sw-registration" /* ErrorCode.INVALID_SW_REGISTRATION */]: 'The input to useServiceWorker() must be a ServiceWorkerRegistration.',
334
+ ["invalid-bg-handler" /* ErrorCode.INVALID_BG_HANDLER */]: 'The input to setBackgroundMessageHandler() must be a function.',
335
+ ["invalid-vapid-key" /* ErrorCode.INVALID_VAPID_KEY */]: 'The public VAPID key must be a string.',
336
+ ["use-vapid-key-after-get-token" /* ErrorCode.USE_VAPID_KEY_AFTER_GET_TOKEN */]: 'The usePublicVapidKey() method may only be called once and must be ' +
337
+ 'called before calling getToken() to ensure your VAPID key is used.'
338
+ };
339
339
  const ERROR_FACTORY = new ErrorFactory('messaging', 'Messaging', ERROR_MAP);
340
340
 
341
- /**
342
- * @license
343
- * Copyright 2019 Google LLC
344
- *
345
- * Licensed under the Apache License, Version 2.0 (the "License");
346
- * you may not use this file except in compliance with the License.
347
- * You may obtain a copy of the License at
348
- *
349
- * http://www.apache.org/licenses/LICENSE-2.0
350
- *
351
- * Unless required by applicable law or agreed to in writing, software
352
- * distributed under the License is distributed on an "AS IS" BASIS,
353
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
354
- * See the License for the specific language governing permissions and
355
- * limitations under the License.
356
- */
357
- async function requestGetToken(firebaseDependencies, subscriptionOptions) {
358
- const headers = await getHeaders(firebaseDependencies);
359
- const body = getBody(subscriptionOptions);
360
- const subscribeOptions = {
361
- method: 'POST',
362
- headers,
363
- body: JSON.stringify(body)
364
- };
365
- let responseData;
366
- try {
367
- const response = await fetch(getEndpoint(firebaseDependencies.appConfig), subscribeOptions);
368
- responseData = await response.json();
369
- }
370
- catch (err) {
371
- throw ERROR_FACTORY.create("token-subscribe-failed" /* ErrorCode.TOKEN_SUBSCRIBE_FAILED */, {
372
- errorInfo: err === null || err === void 0 ? void 0 : err.toString()
373
- });
374
- }
375
- if (responseData.error) {
376
- const message = responseData.error.message;
377
- throw ERROR_FACTORY.create("token-subscribe-failed" /* ErrorCode.TOKEN_SUBSCRIBE_FAILED */, {
378
- errorInfo: message
379
- });
380
- }
381
- if (!responseData.token) {
382
- throw ERROR_FACTORY.create("token-subscribe-no-token" /* ErrorCode.TOKEN_SUBSCRIBE_NO_TOKEN */);
383
- }
384
- return responseData.token;
385
- }
386
- async function requestUpdateToken(firebaseDependencies, tokenDetails) {
387
- const headers = await getHeaders(firebaseDependencies);
388
- const body = getBody(tokenDetails.subscriptionOptions);
389
- const updateOptions = {
390
- method: 'PATCH',
391
- headers,
392
- body: JSON.stringify(body)
393
- };
394
- let responseData;
395
- try {
396
- const response = await fetch(`${getEndpoint(firebaseDependencies.appConfig)}/${tokenDetails.token}`, updateOptions);
397
- responseData = await response.json();
398
- }
399
- catch (err) {
400
- throw ERROR_FACTORY.create("token-update-failed" /* ErrorCode.TOKEN_UPDATE_FAILED */, {
401
- errorInfo: err === null || err === void 0 ? void 0 : err.toString()
402
- });
403
- }
404
- if (responseData.error) {
405
- const message = responseData.error.message;
406
- throw ERROR_FACTORY.create("token-update-failed" /* ErrorCode.TOKEN_UPDATE_FAILED */, {
407
- errorInfo: message
408
- });
409
- }
410
- if (!responseData.token) {
411
- throw ERROR_FACTORY.create("token-update-no-token" /* ErrorCode.TOKEN_UPDATE_NO_TOKEN */);
412
- }
413
- return responseData.token;
414
- }
415
- async function requestDeleteToken(firebaseDependencies, token) {
416
- const headers = await getHeaders(firebaseDependencies);
417
- const unsubscribeOptions = {
418
- method: 'DELETE',
419
- headers
420
- };
421
- try {
422
- const response = await fetch(`${getEndpoint(firebaseDependencies.appConfig)}/${token}`, unsubscribeOptions);
423
- const responseData = await response.json();
424
- if (responseData.error) {
425
- const message = responseData.error.message;
426
- throw ERROR_FACTORY.create("token-unsubscribe-failed" /* ErrorCode.TOKEN_UNSUBSCRIBE_FAILED */, {
427
- errorInfo: message
428
- });
429
- }
430
- }
431
- catch (err) {
432
- throw ERROR_FACTORY.create("token-unsubscribe-failed" /* ErrorCode.TOKEN_UNSUBSCRIBE_FAILED */, {
433
- errorInfo: err === null || err === void 0 ? void 0 : err.toString()
434
- });
435
- }
436
- }
437
- function getEndpoint({ projectId }) {
438
- return `${ENDPOINT}/projects/${projectId}/registrations`;
439
- }
440
- async function getHeaders({ appConfig, installations }) {
441
- const authToken = await installations.getToken();
442
- return new Headers({
443
- 'Content-Type': 'application/json',
444
- Accept: 'application/json',
445
- 'x-goog-api-key': appConfig.apiKey,
446
- 'x-goog-firebase-installations-auth': `FIS ${authToken}`
447
- });
448
- }
449
- function getBody({ p256dh, auth, endpoint, vapidKey }) {
450
- const body = {
451
- web: {
452
- endpoint,
453
- auth,
454
- p256dh
455
- }
456
- };
457
- if (vapidKey !== DEFAULT_VAPID_KEY) {
458
- body.web.applicationPubKey = vapidKey;
459
- }
460
- return body;
341
+ /**
342
+ * @license
343
+ * Copyright 2019 Google LLC
344
+ *
345
+ * Licensed under the Apache License, Version 2.0 (the "License");
346
+ * you may not use this file except in compliance with the License.
347
+ * You may obtain a copy of the License at
348
+ *
349
+ * http://www.apache.org/licenses/LICENSE-2.0
350
+ *
351
+ * Unless required by applicable law or agreed to in writing, software
352
+ * distributed under the License is distributed on an "AS IS" BASIS,
353
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
354
+ * See the License for the specific language governing permissions and
355
+ * limitations under the License.
356
+ */
357
+ async function requestGetToken(firebaseDependencies, subscriptionOptions) {
358
+ const headers = await getHeaders(firebaseDependencies);
359
+ const body = getBody(subscriptionOptions);
360
+ const subscribeOptions = {
361
+ method: 'POST',
362
+ headers,
363
+ body: JSON.stringify(body)
364
+ };
365
+ let responseData;
366
+ try {
367
+ const response = await fetch(getEndpoint(firebaseDependencies.appConfig), subscribeOptions);
368
+ responseData = await response.json();
369
+ }
370
+ catch (err) {
371
+ throw ERROR_FACTORY.create("token-subscribe-failed" /* ErrorCode.TOKEN_SUBSCRIBE_FAILED */, {
372
+ errorInfo: err === null || err === void 0 ? void 0 : err.toString()
373
+ });
374
+ }
375
+ if (responseData.error) {
376
+ const message = responseData.error.message;
377
+ throw ERROR_FACTORY.create("token-subscribe-failed" /* ErrorCode.TOKEN_SUBSCRIBE_FAILED */, {
378
+ errorInfo: message
379
+ });
380
+ }
381
+ if (!responseData.token) {
382
+ throw ERROR_FACTORY.create("token-subscribe-no-token" /* ErrorCode.TOKEN_SUBSCRIBE_NO_TOKEN */);
383
+ }
384
+ return responseData.token;
385
+ }
386
+ async function requestUpdateToken(firebaseDependencies, tokenDetails) {
387
+ const headers = await getHeaders(firebaseDependencies);
388
+ const body = getBody(tokenDetails.subscriptionOptions);
389
+ const updateOptions = {
390
+ method: 'PATCH',
391
+ headers,
392
+ body: JSON.stringify(body)
393
+ };
394
+ let responseData;
395
+ try {
396
+ const response = await fetch(`${getEndpoint(firebaseDependencies.appConfig)}/${tokenDetails.token}`, updateOptions);
397
+ responseData = await response.json();
398
+ }
399
+ catch (err) {
400
+ throw ERROR_FACTORY.create("token-update-failed" /* ErrorCode.TOKEN_UPDATE_FAILED */, {
401
+ errorInfo: err === null || err === void 0 ? void 0 : err.toString()
402
+ });
403
+ }
404
+ if (responseData.error) {
405
+ const message = responseData.error.message;
406
+ throw ERROR_FACTORY.create("token-update-failed" /* ErrorCode.TOKEN_UPDATE_FAILED */, {
407
+ errorInfo: message
408
+ });
409
+ }
410
+ if (!responseData.token) {
411
+ throw ERROR_FACTORY.create("token-update-no-token" /* ErrorCode.TOKEN_UPDATE_NO_TOKEN */);
412
+ }
413
+ return responseData.token;
414
+ }
415
+ async function requestDeleteToken(firebaseDependencies, token) {
416
+ const headers = await getHeaders(firebaseDependencies);
417
+ const unsubscribeOptions = {
418
+ method: 'DELETE',
419
+ headers
420
+ };
421
+ try {
422
+ const response = await fetch(`${getEndpoint(firebaseDependencies.appConfig)}/${token}`, unsubscribeOptions);
423
+ const responseData = await response.json();
424
+ if (responseData.error) {
425
+ const message = responseData.error.message;
426
+ throw ERROR_FACTORY.create("token-unsubscribe-failed" /* ErrorCode.TOKEN_UNSUBSCRIBE_FAILED */, {
427
+ errorInfo: message
428
+ });
429
+ }
430
+ }
431
+ catch (err) {
432
+ throw ERROR_FACTORY.create("token-unsubscribe-failed" /* ErrorCode.TOKEN_UNSUBSCRIBE_FAILED */, {
433
+ errorInfo: err === null || err === void 0 ? void 0 : err.toString()
434
+ });
435
+ }
436
+ }
437
+ function getEndpoint({ projectId }) {
438
+ return `${ENDPOINT}/projects/${projectId}/registrations`;
439
+ }
440
+ async function getHeaders({ appConfig, installations }) {
441
+ const authToken = await installations.getToken();
442
+ return new Headers({
443
+ 'Content-Type': 'application/json',
444
+ Accept: 'application/json',
445
+ 'x-goog-api-key': appConfig.apiKey,
446
+ 'x-goog-firebase-installations-auth': `FIS ${authToken}`
447
+ });
448
+ }
449
+ function getBody({ p256dh, auth, endpoint, vapidKey }) {
450
+ const body = {
451
+ web: {
452
+ endpoint,
453
+ auth,
454
+ p256dh
455
+ }
456
+ };
457
+ if (vapidKey !== DEFAULT_VAPID_KEY) {
458
+ body.web.applicationPubKey = vapidKey;
459
+ }
460
+ return body;
461
461
  }
462
462
 
463
- /**
464
- * @license
465
- * Copyright 2019 Google LLC
466
- *
467
- * Licensed under the Apache License, Version 2.0 (the "License");
468
- * you may not use this file except in compliance with the License.
469
- * You may obtain a copy of the License at
470
- *
471
- * http://www.apache.org/licenses/LICENSE-2.0
472
- *
473
- * Unless required by applicable law or agreed to in writing, software
474
- * distributed under the License is distributed on an "AS IS" BASIS,
475
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
476
- * See the License for the specific language governing permissions and
477
- * limitations under the License.
478
- */
479
- // UpdateRegistration will be called once every week.
480
- const TOKEN_EXPIRATION_MS = 7 * 24 * 60 * 60 * 1000; // 7 days
481
- async function getTokenInternal(messaging) {
482
- const pushSubscription = await getPushSubscription(messaging.swRegistration, messaging.vapidKey);
483
- const subscriptionOptions = {
484
- vapidKey: messaging.vapidKey,
485
- swScope: messaging.swRegistration.scope,
486
- endpoint: pushSubscription.endpoint,
487
- auth: arrayToBase64(pushSubscription.getKey('auth')),
488
- p256dh: arrayToBase64(pushSubscription.getKey('p256dh'))
489
- };
490
- const tokenDetails = await dbGet(messaging.firebaseDependencies);
491
- if (!tokenDetails) {
492
- // No token, get a new one.
493
- return getNewToken(messaging.firebaseDependencies, subscriptionOptions);
494
- }
495
- else if (!isTokenValid(tokenDetails.subscriptionOptions, subscriptionOptions)) {
496
- // Invalid token, get a new one.
497
- try {
498
- await requestDeleteToken(messaging.firebaseDependencies, tokenDetails.token);
499
- }
500
- catch (e) {
501
- // Suppress errors because of #2364
502
- console.warn(e);
503
- }
504
- return getNewToken(messaging.firebaseDependencies, subscriptionOptions);
505
- }
506
- else if (Date.now() >= tokenDetails.createTime + TOKEN_EXPIRATION_MS) {
507
- // Weekly token refresh
508
- return updateToken(messaging, {
509
- token: tokenDetails.token,
510
- createTime: Date.now(),
511
- subscriptionOptions
512
- });
513
- }
514
- else {
515
- // Valid token, nothing to do.
516
- return tokenDetails.token;
517
- }
518
- }
519
- /**
520
- * This method deletes the token from the database, unsubscribes the token from FCM, and unregisters
521
- * the push subscription if it exists.
522
- */
523
- async function deleteTokenInternal(messaging) {
524
- const tokenDetails = await dbGet(messaging.firebaseDependencies);
525
- if (tokenDetails) {
526
- await requestDeleteToken(messaging.firebaseDependencies, tokenDetails.token);
527
- await dbRemove(messaging.firebaseDependencies);
528
- }
529
- // Unsubscribe from the push subscription.
530
- const pushSubscription = await messaging.swRegistration.pushManager.getSubscription();
531
- if (pushSubscription) {
532
- return pushSubscription.unsubscribe();
533
- }
534
- // If there's no SW, consider it a success.
535
- return true;
536
- }
537
- async function updateToken(messaging, tokenDetails) {
538
- try {
539
- const updatedToken = await requestUpdateToken(messaging.firebaseDependencies, tokenDetails);
540
- const updatedTokenDetails = Object.assign(Object.assign({}, tokenDetails), { token: updatedToken, createTime: Date.now() });
541
- await dbSet(messaging.firebaseDependencies, updatedTokenDetails);
542
- return updatedToken;
543
- }
544
- catch (e) {
545
- throw e;
546
- }
547
- }
548
- async function getNewToken(firebaseDependencies, subscriptionOptions) {
549
- const token = await requestGetToken(firebaseDependencies, subscriptionOptions);
550
- const tokenDetails = {
551
- token,
552
- createTime: Date.now(),
553
- subscriptionOptions
554
- };
555
- await dbSet(firebaseDependencies, tokenDetails);
556
- return tokenDetails.token;
557
- }
558
- /**
559
- * Gets a PushSubscription for the current user.
560
- */
561
- async function getPushSubscription(swRegistration, vapidKey) {
562
- const subscription = await swRegistration.pushManager.getSubscription();
563
- if (subscription) {
564
- return subscription;
565
- }
566
- return swRegistration.pushManager.subscribe({
567
- userVisibleOnly: true,
568
- // Chrome <= 75 doesn't support base64-encoded VAPID key. For backward compatibility, VAPID key
569
- // submitted to pushManager#subscribe must be of type Uint8Array.
570
- applicationServerKey: base64ToArray(vapidKey)
571
- });
572
- }
573
- /**
574
- * Checks if the saved tokenDetails object matches the configuration provided.
575
- */
576
- function isTokenValid(dbOptions, currentOptions) {
577
- const isVapidKeyEqual = currentOptions.vapidKey === dbOptions.vapidKey;
578
- const isEndpointEqual = currentOptions.endpoint === dbOptions.endpoint;
579
- const isAuthEqual = currentOptions.auth === dbOptions.auth;
580
- const isP256dhEqual = currentOptions.p256dh === dbOptions.p256dh;
581
- return isVapidKeyEqual && isEndpointEqual && isAuthEqual && isP256dhEqual;
463
+ /**
464
+ * @license
465
+ * Copyright 2019 Google LLC
466
+ *
467
+ * Licensed under the Apache License, Version 2.0 (the "License");
468
+ * you may not use this file except in compliance with the License.
469
+ * You may obtain a copy of the License at
470
+ *
471
+ * http://www.apache.org/licenses/LICENSE-2.0
472
+ *
473
+ * Unless required by applicable law or agreed to in writing, software
474
+ * distributed under the License is distributed on an "AS IS" BASIS,
475
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
476
+ * See the License for the specific language governing permissions and
477
+ * limitations under the License.
478
+ */
479
+ // UpdateRegistration will be called once every week.
480
+ const TOKEN_EXPIRATION_MS = 7 * 24 * 60 * 60 * 1000; // 7 days
481
+ async function getTokenInternal(messaging) {
482
+ const pushSubscription = await getPushSubscription(messaging.swRegistration, messaging.vapidKey);
483
+ const subscriptionOptions = {
484
+ vapidKey: messaging.vapidKey,
485
+ swScope: messaging.swRegistration.scope,
486
+ endpoint: pushSubscription.endpoint,
487
+ auth: arrayToBase64(pushSubscription.getKey('auth')),
488
+ p256dh: arrayToBase64(pushSubscription.getKey('p256dh'))
489
+ };
490
+ const tokenDetails = await dbGet(messaging.firebaseDependencies);
491
+ if (!tokenDetails) {
492
+ // No token, get a new one.
493
+ return getNewToken(messaging.firebaseDependencies, subscriptionOptions);
494
+ }
495
+ else if (!isTokenValid(tokenDetails.subscriptionOptions, subscriptionOptions)) {
496
+ // Invalid token, get a new one.
497
+ try {
498
+ await requestDeleteToken(messaging.firebaseDependencies, tokenDetails.token);
499
+ }
500
+ catch (e) {
501
+ // Suppress errors because of #2364
502
+ console.warn(e);
503
+ }
504
+ return getNewToken(messaging.firebaseDependencies, subscriptionOptions);
505
+ }
506
+ else if (Date.now() >= tokenDetails.createTime + TOKEN_EXPIRATION_MS) {
507
+ // Weekly token refresh
508
+ return updateToken(messaging, {
509
+ token: tokenDetails.token,
510
+ createTime: Date.now(),
511
+ subscriptionOptions
512
+ });
513
+ }
514
+ else {
515
+ // Valid token, nothing to do.
516
+ return tokenDetails.token;
517
+ }
518
+ }
519
+ /**
520
+ * This method deletes the token from the database, unsubscribes the token from FCM, and unregisters
521
+ * the push subscription if it exists.
522
+ */
523
+ async function deleteTokenInternal(messaging) {
524
+ const tokenDetails = await dbGet(messaging.firebaseDependencies);
525
+ if (tokenDetails) {
526
+ await requestDeleteToken(messaging.firebaseDependencies, tokenDetails.token);
527
+ await dbRemove(messaging.firebaseDependencies);
528
+ }
529
+ // Unsubscribe from the push subscription.
530
+ const pushSubscription = await messaging.swRegistration.pushManager.getSubscription();
531
+ if (pushSubscription) {
532
+ return pushSubscription.unsubscribe();
533
+ }
534
+ // If there's no SW, consider it a success.
535
+ return true;
536
+ }
537
+ async function updateToken(messaging, tokenDetails) {
538
+ try {
539
+ const updatedToken = await requestUpdateToken(messaging.firebaseDependencies, tokenDetails);
540
+ const updatedTokenDetails = Object.assign(Object.assign({}, tokenDetails), { token: updatedToken, createTime: Date.now() });
541
+ await dbSet(messaging.firebaseDependencies, updatedTokenDetails);
542
+ return updatedToken;
543
+ }
544
+ catch (e) {
545
+ throw e;
546
+ }
547
+ }
548
+ async function getNewToken(firebaseDependencies, subscriptionOptions) {
549
+ const token = await requestGetToken(firebaseDependencies, subscriptionOptions);
550
+ const tokenDetails = {
551
+ token,
552
+ createTime: Date.now(),
553
+ subscriptionOptions
554
+ };
555
+ await dbSet(firebaseDependencies, tokenDetails);
556
+ return tokenDetails.token;
557
+ }
558
+ /**
559
+ * Gets a PushSubscription for the current user.
560
+ */
561
+ async function getPushSubscription(swRegistration, vapidKey) {
562
+ const subscription = await swRegistration.pushManager.getSubscription();
563
+ if (subscription) {
564
+ return subscription;
565
+ }
566
+ return swRegistration.pushManager.subscribe({
567
+ userVisibleOnly: true,
568
+ // Chrome <= 75 doesn't support base64-encoded VAPID key. For backward compatibility, VAPID key
569
+ // submitted to pushManager#subscribe must be of type Uint8Array.
570
+ applicationServerKey: base64ToArray(vapidKey)
571
+ });
572
+ }
573
+ /**
574
+ * Checks if the saved tokenDetails object matches the configuration provided.
575
+ */
576
+ function isTokenValid(dbOptions, currentOptions) {
577
+ const isVapidKeyEqual = currentOptions.vapidKey === dbOptions.vapidKey;
578
+ const isEndpointEqual = currentOptions.endpoint === dbOptions.endpoint;
579
+ const isAuthEqual = currentOptions.auth === dbOptions.auth;
580
+ const isP256dhEqual = currentOptions.p256dh === dbOptions.p256dh;
581
+ return isVapidKeyEqual && isEndpointEqual && isAuthEqual && isP256dhEqual;
582
582
  }
583
583
 
584
- /**
585
- * @license
586
- * Copyright 2020 Google LLC
587
- *
588
- * Licensed under the Apache License, Version 2.0 (the "License");
589
- * you may not use this file except in compliance with the License.
590
- * You may obtain a copy of the License at
591
- *
592
- * http://www.apache.org/licenses/LICENSE-2.0
593
- *
594
- * Unless required by applicable law or agreed to in writing, software
595
- * distributed under the License is distributed on an "AS IS" BASIS,
596
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
597
- * See the License for the specific language governing permissions and
598
- * limitations under the License.
599
- */
600
- function externalizePayload(internalPayload) {
601
- const payload = {
602
- from: internalPayload.from,
603
- // eslint-disable-next-line camelcase
604
- collapseKey: internalPayload.collapse_key,
605
- // eslint-disable-next-line camelcase
606
- messageId: internalPayload.fcmMessageId
607
- };
608
- propagateNotificationPayload(payload, internalPayload);
609
- propagateDataPayload(payload, internalPayload);
610
- propagateFcmOptions(payload, internalPayload);
611
- return payload;
612
- }
613
- function propagateNotificationPayload(payload, messagePayloadInternal) {
614
- if (!messagePayloadInternal.notification) {
615
- return;
616
- }
617
- payload.notification = {};
618
- const title = messagePayloadInternal.notification.title;
619
- if (!!title) {
620
- payload.notification.title = title;
621
- }
622
- const body = messagePayloadInternal.notification.body;
623
- if (!!body) {
624
- payload.notification.body = body;
625
- }
626
- const image = messagePayloadInternal.notification.image;
627
- if (!!image) {
628
- payload.notification.image = image;
629
- }
630
- const icon = messagePayloadInternal.notification.icon;
631
- if (!!icon) {
632
- payload.notification.icon = icon;
633
- }
634
- }
635
- function propagateDataPayload(payload, messagePayloadInternal) {
636
- if (!messagePayloadInternal.data) {
637
- return;
638
- }
639
- payload.data = messagePayloadInternal.data;
640
- }
641
- function propagateFcmOptions(payload, messagePayloadInternal) {
642
- var _a, _b, _c, _d, _e;
643
- // fcmOptions.link value is written into notification.click_action. see more in b/232072111
644
- if (!messagePayloadInternal.fcmOptions &&
645
- !((_a = messagePayloadInternal.notification) === null || _a === void 0 ? void 0 : _a.click_action)) {
646
- return;
647
- }
648
- payload.fcmOptions = {};
649
- const link = (_c = (_b = messagePayloadInternal.fcmOptions) === null || _b === void 0 ? void 0 : _b.link) !== null && _c !== void 0 ? _c : (_d = messagePayloadInternal.notification) === null || _d === void 0 ? void 0 : _d.click_action;
650
- if (!!link) {
651
- payload.fcmOptions.link = link;
652
- }
653
- // eslint-disable-next-line camelcase
654
- const analyticsLabel = (_e = messagePayloadInternal.fcmOptions) === null || _e === void 0 ? void 0 : _e.analytics_label;
655
- if (!!analyticsLabel) {
656
- payload.fcmOptions.analyticsLabel = analyticsLabel;
657
- }
584
+ /**
585
+ * @license
586
+ * Copyright 2020 Google LLC
587
+ *
588
+ * Licensed under the Apache License, Version 2.0 (the "License");
589
+ * you may not use this file except in compliance with the License.
590
+ * You may obtain a copy of the License at
591
+ *
592
+ * http://www.apache.org/licenses/LICENSE-2.0
593
+ *
594
+ * Unless required by applicable law or agreed to in writing, software
595
+ * distributed under the License is distributed on an "AS IS" BASIS,
596
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
597
+ * See the License for the specific language governing permissions and
598
+ * limitations under the License.
599
+ */
600
+ function externalizePayload(internalPayload) {
601
+ const payload = {
602
+ from: internalPayload.from,
603
+ // eslint-disable-next-line camelcase
604
+ collapseKey: internalPayload.collapse_key,
605
+ // eslint-disable-next-line camelcase
606
+ messageId: internalPayload.fcmMessageId
607
+ };
608
+ propagateNotificationPayload(payload, internalPayload);
609
+ propagateDataPayload(payload, internalPayload);
610
+ propagateFcmOptions(payload, internalPayload);
611
+ return payload;
612
+ }
613
+ function propagateNotificationPayload(payload, messagePayloadInternal) {
614
+ if (!messagePayloadInternal.notification) {
615
+ return;
616
+ }
617
+ payload.notification = {};
618
+ const title = messagePayloadInternal.notification.title;
619
+ if (!!title) {
620
+ payload.notification.title = title;
621
+ }
622
+ const body = messagePayloadInternal.notification.body;
623
+ if (!!body) {
624
+ payload.notification.body = body;
625
+ }
626
+ const image = messagePayloadInternal.notification.image;
627
+ if (!!image) {
628
+ payload.notification.image = image;
629
+ }
630
+ const icon = messagePayloadInternal.notification.icon;
631
+ if (!!icon) {
632
+ payload.notification.icon = icon;
633
+ }
634
+ }
635
+ function propagateDataPayload(payload, messagePayloadInternal) {
636
+ if (!messagePayloadInternal.data) {
637
+ return;
638
+ }
639
+ payload.data = messagePayloadInternal.data;
640
+ }
641
+ function propagateFcmOptions(payload, messagePayloadInternal) {
642
+ var _a, _b, _c, _d, _e;
643
+ // fcmOptions.link value is written into notification.click_action. see more in b/232072111
644
+ if (!messagePayloadInternal.fcmOptions &&
645
+ !((_a = messagePayloadInternal.notification) === null || _a === void 0 ? void 0 : _a.click_action)) {
646
+ return;
647
+ }
648
+ payload.fcmOptions = {};
649
+ const link = (_c = (_b = messagePayloadInternal.fcmOptions) === null || _b === void 0 ? void 0 : _b.link) !== null && _c !== void 0 ? _c : (_d = messagePayloadInternal.notification) === null || _d === void 0 ? void 0 : _d.click_action;
650
+ if (!!link) {
651
+ payload.fcmOptions.link = link;
652
+ }
653
+ // eslint-disable-next-line camelcase
654
+ const analyticsLabel = (_e = messagePayloadInternal.fcmOptions) === null || _e === void 0 ? void 0 : _e.analytics_label;
655
+ if (!!analyticsLabel) {
656
+ payload.fcmOptions.analyticsLabel = analyticsLabel;
657
+ }
658
658
  }
659
659
 
660
- /**
661
- * @license
662
- * Copyright 2019 Google LLC
663
- *
664
- * Licensed under the Apache License, Version 2.0 (the "License");
665
- * you may not use this file except in compliance with the License.
666
- * You may obtain a copy of the License at
667
- *
668
- * http://www.apache.org/licenses/LICENSE-2.0
669
- *
670
- * Unless required by applicable law or agreed to in writing, software
671
- * distributed under the License is distributed on an "AS IS" BASIS,
672
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
673
- * See the License for the specific language governing permissions and
674
- * limitations under the License.
675
- */
676
- function isConsoleMessage(data) {
677
- // This message has a campaign ID, meaning it was sent using the Firebase Console.
678
- return typeof data === 'object' && !!data && CONSOLE_CAMPAIGN_ID in data;
660
+ /**
661
+ * @license
662
+ * Copyright 2019 Google LLC
663
+ *
664
+ * Licensed under the Apache License, Version 2.0 (the "License");
665
+ * you may not use this file except in compliance with the License.
666
+ * You may obtain a copy of the License at
667
+ *
668
+ * http://www.apache.org/licenses/LICENSE-2.0
669
+ *
670
+ * Unless required by applicable law or agreed to in writing, software
671
+ * distributed under the License is distributed on an "AS IS" BASIS,
672
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
673
+ * See the License for the specific language governing permissions and
674
+ * limitations under the License.
675
+ */
676
+ function isConsoleMessage(data) {
677
+ // This message has a campaign ID, meaning it was sent using the Firebase Console.
678
+ return typeof data === 'object' && !!data && CONSOLE_CAMPAIGN_ID in data;
679
679
  }
680
680
 
681
- /**
682
- * @license
683
- * Copyright 2019 Google LLC
684
- *
685
- * Licensed under the Apache License, Version 2.0 (the "License");
686
- * you may not use this file except in compliance with the License.
687
- * You may obtain a copy of the License at
688
- *
689
- * http://www.apache.org/licenses/LICENSE-2.0
690
- *
691
- * Unless required by applicable law or agreed to in writing, software
692
- * distributed under the License is distributed on an "AS IS" BASIS,
693
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
694
- * See the License for the specific language governing permissions and
695
- * limitations under the License.
696
- */
697
- /** Returns a promise that resolves after given time passes. */
698
- function sleep(ms) {
699
- return new Promise(resolve => {
700
- setTimeout(resolve, ms);
701
- });
681
+ /**
682
+ * @license
683
+ * Copyright 2019 Google LLC
684
+ *
685
+ * Licensed under the Apache License, Version 2.0 (the "License");
686
+ * you may not use this file except in compliance with the License.
687
+ * You may obtain a copy of the License at
688
+ *
689
+ * http://www.apache.org/licenses/LICENSE-2.0
690
+ *
691
+ * Unless required by applicable law or agreed to in writing, software
692
+ * distributed under the License is distributed on an "AS IS" BASIS,
693
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
694
+ * See the License for the specific language governing permissions and
695
+ * limitations under the License.
696
+ */
697
+ /** Returns a promise that resolves after given time passes. */
698
+ function sleep(ms) {
699
+ return new Promise(resolve => {
700
+ setTimeout(resolve, ms);
701
+ });
702
702
  }
703
703
 
704
- /**
705
- * @license
706
- * Copyright 2019 Google LLC
707
- *
708
- * Licensed under the Apache License, Version 2.0 (the "License");
709
- * you may not use this file except in compliance with the License.
710
- * You may obtain a copy of the License at
711
- *
712
- * http://www.apache.org/licenses/LICENSE-2.0
713
- *
714
- * Unless required by applicable law or agreed to in writing, software
715
- * distributed under the License is distributed on an "AS IS" BASIS,
716
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
717
- * See the License for the specific language governing permissions and
718
- * limitations under the License.
719
- */
720
- _mergeStrings('AzSCbw63g1R0nCw85jG8', 'Iaya3yLKwmgvh7cF0q4');
721
- async function stageLog(messaging, internalPayload) {
722
- const fcmEvent = createFcmEvent(internalPayload, await messaging.firebaseDependencies.installations.getId());
723
- createAndEnqueueLogEvent(messaging, fcmEvent, internalPayload.productId);
724
- }
725
- function createFcmEvent(internalPayload, fid) {
726
- var _a, _b;
727
- const fcmEvent = {};
728
- /* eslint-disable camelcase */
729
- // some fields should always be non-null. Still check to ensure.
730
- if (!!internalPayload.from) {
731
- fcmEvent.project_number = internalPayload.from;
732
- }
733
- if (!!internalPayload.fcmMessageId) {
734
- fcmEvent.message_id = internalPayload.fcmMessageId;
735
- }
736
- fcmEvent.instance_id = fid;
737
- if (!!internalPayload.notification) {
738
- fcmEvent.message_type = MessageType$1.DISPLAY_NOTIFICATION.toString();
739
- }
740
- else {
741
- fcmEvent.message_type = MessageType$1.DATA_MESSAGE.toString();
742
- }
743
- fcmEvent.sdk_platform = SDK_PLATFORM_WEB.toString();
744
- fcmEvent.package_name = self.origin.replace(/(^\w+:|^)\/\//, '');
745
- if (!!internalPayload.collapse_key) {
746
- fcmEvent.collapse_key = internalPayload.collapse_key;
747
- }
748
- fcmEvent.event = EVENT_MESSAGE_DELIVERED.toString();
749
- if (!!((_a = internalPayload.fcmOptions) === null || _a === void 0 ? void 0 : _a.analytics_label)) {
750
- fcmEvent.analytics_label = (_b = internalPayload.fcmOptions) === null || _b === void 0 ? void 0 : _b.analytics_label;
751
- }
752
- /* eslint-enable camelcase */
753
- return fcmEvent;
754
- }
755
- function createAndEnqueueLogEvent(messaging, fcmEvent, productId) {
756
- const logEvent = {};
757
- /* eslint-disable camelcase */
758
- logEvent.event_time_ms = Math.floor(Date.now()).toString();
759
- logEvent.source_extension_json_proto3 = JSON.stringify({
760
- messaging_client_event: fcmEvent
761
- });
762
- if (!!productId) {
763
- logEvent.compliance_data = buildComplianceData(productId);
764
- }
765
- // eslint-disable-next-line camelcase
766
- messaging.logEvents.push(logEvent);
767
- }
768
- function buildComplianceData(productId) {
769
- const complianceData = {
770
- privacy_context: {
771
- prequest: {
772
- origin_associated_product_id: productId
773
- }
774
- }
775
- };
776
- return complianceData;
777
- }
778
- function _mergeStrings(s1, s2) {
779
- const resultArray = [];
780
- for (let i = 0; i < s1.length; i++) {
781
- resultArray.push(s1.charAt(i));
782
- if (i < s2.length) {
783
- resultArray.push(s2.charAt(i));
784
- }
785
- }
786
- return resultArray.join('');
704
+ /**
705
+ * @license
706
+ * Copyright 2019 Google LLC
707
+ *
708
+ * Licensed under the Apache License, Version 2.0 (the "License");
709
+ * you may not use this file except in compliance with the License.
710
+ * You may obtain a copy of the License at
711
+ *
712
+ * http://www.apache.org/licenses/LICENSE-2.0
713
+ *
714
+ * Unless required by applicable law or agreed to in writing, software
715
+ * distributed under the License is distributed on an "AS IS" BASIS,
716
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
717
+ * See the License for the specific language governing permissions and
718
+ * limitations under the License.
719
+ */
720
+ _mergeStrings('AzSCbw63g1R0nCw85jG8', 'Iaya3yLKwmgvh7cF0q4');
721
+ async function stageLog(messaging, internalPayload) {
722
+ const fcmEvent = createFcmEvent(internalPayload, await messaging.firebaseDependencies.installations.getId());
723
+ createAndEnqueueLogEvent(messaging, fcmEvent, internalPayload.productId);
724
+ }
725
+ function createFcmEvent(internalPayload, fid) {
726
+ var _a, _b;
727
+ const fcmEvent = {};
728
+ /* eslint-disable camelcase */
729
+ // some fields should always be non-null. Still check to ensure.
730
+ if (!!internalPayload.from) {
731
+ fcmEvent.project_number = internalPayload.from;
732
+ }
733
+ if (!!internalPayload.fcmMessageId) {
734
+ fcmEvent.message_id = internalPayload.fcmMessageId;
735
+ }
736
+ fcmEvent.instance_id = fid;
737
+ if (!!internalPayload.notification) {
738
+ fcmEvent.message_type = MessageType$1.DISPLAY_NOTIFICATION.toString();
739
+ }
740
+ else {
741
+ fcmEvent.message_type = MessageType$1.DATA_MESSAGE.toString();
742
+ }
743
+ fcmEvent.sdk_platform = SDK_PLATFORM_WEB.toString();
744
+ fcmEvent.package_name = self.origin.replace(/(^\w+:|^)\/\//, '');
745
+ if (!!internalPayload.collapse_key) {
746
+ fcmEvent.collapse_key = internalPayload.collapse_key;
747
+ }
748
+ fcmEvent.event = EVENT_MESSAGE_DELIVERED.toString();
749
+ if (!!((_a = internalPayload.fcmOptions) === null || _a === void 0 ? void 0 : _a.analytics_label)) {
750
+ fcmEvent.analytics_label = (_b = internalPayload.fcmOptions) === null || _b === void 0 ? void 0 : _b.analytics_label;
751
+ }
752
+ /* eslint-enable camelcase */
753
+ return fcmEvent;
754
+ }
755
+ function createAndEnqueueLogEvent(messaging, fcmEvent, productId) {
756
+ const logEvent = {};
757
+ /* eslint-disable camelcase */
758
+ logEvent.event_time_ms = Math.floor(Date.now()).toString();
759
+ logEvent.source_extension_json_proto3 = JSON.stringify({
760
+ messaging_client_event: fcmEvent
761
+ });
762
+ if (!!productId) {
763
+ logEvent.compliance_data = buildComplianceData(productId);
764
+ }
765
+ // eslint-disable-next-line camelcase
766
+ messaging.logEvents.push(logEvent);
767
+ }
768
+ function buildComplianceData(productId) {
769
+ const complianceData = {
770
+ privacy_context: {
771
+ prequest: {
772
+ origin_associated_product_id: productId
773
+ }
774
+ }
775
+ };
776
+ return complianceData;
777
+ }
778
+ function _mergeStrings(s1, s2) {
779
+ const resultArray = [];
780
+ for (let i = 0; i < s1.length; i++) {
781
+ resultArray.push(s1.charAt(i));
782
+ if (i < s2.length) {
783
+ resultArray.push(s2.charAt(i));
784
+ }
785
+ }
786
+ return resultArray.join('');
787
787
  }
788
788
 
789
- /**
790
- * @license
791
- * Copyright 2017 Google LLC
792
- *
793
- * Licensed under the Apache License, Version 2.0 (the "License");
794
- * you may not use this file except in compliance with the License.
795
- * You may obtain a copy of the License at
796
- *
797
- * http://www.apache.org/licenses/LICENSE-2.0
798
- *
799
- * Unless required by applicable law or agreed to in writing, software
800
- * distributed under the License is distributed on an "AS IS" BASIS,
801
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
802
- * See the License for the specific language governing permissions and
803
- * limitations under the License.
804
- */
805
- async function onSubChange(event, messaging) {
806
- var _a, _b;
807
- const { newSubscription } = event;
808
- if (!newSubscription) {
809
- // Subscription revoked, delete token
810
- await deleteTokenInternal(messaging);
811
- return;
812
- }
813
- const tokenDetails = await dbGet(messaging.firebaseDependencies);
814
- await deleteTokenInternal(messaging);
815
- messaging.vapidKey =
816
- (_b = (_a = tokenDetails === null || tokenDetails === void 0 ? void 0 : tokenDetails.subscriptionOptions) === null || _a === void 0 ? void 0 : _a.vapidKey) !== null && _b !== void 0 ? _b : DEFAULT_VAPID_KEY;
817
- await getTokenInternal(messaging);
818
- }
819
- async function onPush(event, messaging) {
820
- const internalPayload = getMessagePayloadInternal(event);
821
- if (!internalPayload) {
822
- // Failed to get parsed MessagePayload from the PushEvent. Skip handling the push.
823
- return;
824
- }
825
- // log to Firelog with user consent
826
- if (messaging.deliveryMetricsExportedToBigQueryEnabled) {
827
- await stageLog(messaging, internalPayload);
828
- }
829
- // foreground handling: eventually passed to onMessage hook
830
- const clientList = await getClientList();
831
- if (hasVisibleClients(clientList)) {
832
- return sendMessagePayloadInternalToWindows(clientList, internalPayload);
833
- }
834
- // background handling: display if possible and pass to onBackgroundMessage hook
835
- if (!!internalPayload.notification) {
836
- await showNotification(wrapInternalPayload(internalPayload));
837
- }
838
- if (!messaging) {
839
- return;
840
- }
841
- if (!!messaging.onBackgroundMessageHandler) {
842
- const payload = externalizePayload(internalPayload);
843
- if (typeof messaging.onBackgroundMessageHandler === 'function') {
844
- await messaging.onBackgroundMessageHandler(payload);
845
- }
846
- else {
847
- messaging.onBackgroundMessageHandler.next(payload);
848
- }
849
- }
850
- }
851
- async function onNotificationClick(event) {
852
- var _a, _b;
853
- const internalPayload = (_b = (_a = event.notification) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b[FCM_MSG];
854
- if (!internalPayload) {
855
- return;
856
- }
857
- else if (event.action) {
858
- // User clicked on an action button. This will allow developers to act on action button clicks
859
- // by using a custom onNotificationClick listener that they define.
860
- return;
861
- }
862
- // Prevent other listeners from receiving the event
863
- event.stopImmediatePropagation();
864
- event.notification.close();
865
- // Note clicking on a notification with no link set will focus the Chrome's current tab.
866
- const link = getLink(internalPayload);
867
- if (!link) {
868
- return;
869
- }
870
- // FM should only open/focus links from app's origin.
871
- const url = new URL(link, self.location.href);
872
- const originUrl = new URL(self.location.origin);
873
- if (url.host !== originUrl.host) {
874
- return;
875
- }
876
- let client = await getWindowClient(url);
877
- if (!client) {
878
- client = await self.clients.openWindow(link);
879
- // Wait three seconds for the client to initialize and set up the message handler so that it
880
- // can receive the message.
881
- await sleep(3000);
882
- }
883
- else {
884
- client = await client.focus();
885
- }
886
- if (!client) {
887
- // Window Client will not be returned if it's for a third party origin.
888
- return;
889
- }
890
- internalPayload.messageType = MessageType.NOTIFICATION_CLICKED;
891
- internalPayload.isFirebaseMessaging = true;
892
- return client.postMessage(internalPayload);
893
- }
894
- function wrapInternalPayload(internalPayload) {
895
- const wrappedInternalPayload = Object.assign({}, internalPayload.notification);
896
- // Put the message payload under FCM_MSG name so we can identify the notification as being an FCM
897
- // notification vs a notification from somewhere else (i.e. normal web push or developer generated
898
- // notification).
899
- wrappedInternalPayload.data = {
900
- [FCM_MSG]: internalPayload
901
- };
902
- return wrappedInternalPayload;
903
- }
904
- function getMessagePayloadInternal({ data }) {
905
- if (!data) {
906
- return null;
907
- }
908
- try {
909
- return data.json();
910
- }
911
- catch (err) {
912
- // Not JSON so not an FCM message.
913
- return null;
914
- }
915
- }
916
- /**
917
- * @param url The URL to look for when focusing a client.
918
- * @return Returns an existing window client or a newly opened WindowClient.
919
- */
920
- async function getWindowClient(url) {
921
- const clientList = await getClientList();
922
- for (const client of clientList) {
923
- const clientUrl = new URL(client.url, self.location.href);
924
- if (url.host === clientUrl.host) {
925
- return client;
926
- }
927
- }
928
- return null;
929
- }
930
- /**
931
- * @returns If there is currently a visible WindowClient, this method will resolve to true,
932
- * otherwise false.
933
- */
934
- function hasVisibleClients(clientList) {
935
- return clientList.some(client => client.visibilityState === 'visible' &&
936
- // Ignore chrome-extension clients as that matches the background pages of extensions, which
937
- // are always considered visible for some reason.
938
- !client.url.startsWith('chrome-extension://'));
939
- }
940
- function sendMessagePayloadInternalToWindows(clientList, internalPayload) {
941
- internalPayload.isFirebaseMessaging = true;
942
- internalPayload.messageType = MessageType.PUSH_RECEIVED;
943
- for (const client of clientList) {
944
- client.postMessage(internalPayload);
945
- }
946
- }
947
- function getClientList() {
948
- return self.clients.matchAll({
949
- type: 'window',
950
- includeUncontrolled: true
951
- // TS doesn't know that "type: 'window'" means it'll return WindowClient[]
952
- });
953
- }
954
- function showNotification(notificationPayloadInternal) {
955
- var _a;
956
- // Note: Firefox does not support the maxActions property.
957
- // https://developer.mozilla.org/en-US/docs/Web/API/notification/maxActions
958
- const { actions } = notificationPayloadInternal;
959
- const { maxActions } = Notification;
960
- if (actions && maxActions && actions.length > maxActions) {
961
- console.warn(`This browser only supports ${maxActions} actions. The remaining actions will not be displayed.`);
962
- }
963
- return self.registration.showNotification(
964
- /* title= */ (_a = notificationPayloadInternal.title) !== null && _a !== void 0 ? _a : '', notificationPayloadInternal);
965
- }
966
- function getLink(payload) {
967
- var _a, _b, _c;
968
- // eslint-disable-next-line camelcase
969
- const link = (_b = (_a = payload.fcmOptions) === null || _a === void 0 ? void 0 : _a.link) !== null && _b !== void 0 ? _b : (_c = payload.notification) === null || _c === void 0 ? void 0 : _c.click_action;
970
- if (link) {
971
- return link;
972
- }
973
- if (isConsoleMessage(payload.data)) {
974
- // Notification created in the Firebase Console. Redirect to origin.
975
- return self.location.origin;
976
- }
977
- else {
978
- return null;
979
- }
789
+ /**
790
+ * @license
791
+ * Copyright 2017 Google LLC
792
+ *
793
+ * Licensed under the Apache License, Version 2.0 (the "License");
794
+ * you may not use this file except in compliance with the License.
795
+ * You may obtain a copy of the License at
796
+ *
797
+ * http://www.apache.org/licenses/LICENSE-2.0
798
+ *
799
+ * Unless required by applicable law or agreed to in writing, software
800
+ * distributed under the License is distributed on an "AS IS" BASIS,
801
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
802
+ * See the License for the specific language governing permissions and
803
+ * limitations under the License.
804
+ */
805
+ async function onSubChange(event, messaging) {
806
+ var _a, _b;
807
+ const { newSubscription } = event;
808
+ if (!newSubscription) {
809
+ // Subscription revoked, delete token
810
+ await deleteTokenInternal(messaging);
811
+ return;
812
+ }
813
+ const tokenDetails = await dbGet(messaging.firebaseDependencies);
814
+ await deleteTokenInternal(messaging);
815
+ messaging.vapidKey =
816
+ (_b = (_a = tokenDetails === null || tokenDetails === void 0 ? void 0 : tokenDetails.subscriptionOptions) === null || _a === void 0 ? void 0 : _a.vapidKey) !== null && _b !== void 0 ? _b : DEFAULT_VAPID_KEY;
817
+ await getTokenInternal(messaging);
818
+ }
819
+ async function onPush(event, messaging) {
820
+ const internalPayload = getMessagePayloadInternal(event);
821
+ if (!internalPayload) {
822
+ // Failed to get parsed MessagePayload from the PushEvent. Skip handling the push.
823
+ return;
824
+ }
825
+ // log to Firelog with user consent
826
+ if (messaging.deliveryMetricsExportedToBigQueryEnabled) {
827
+ await stageLog(messaging, internalPayload);
828
+ }
829
+ // foreground handling: eventually passed to onMessage hook
830
+ const clientList = await getClientList();
831
+ if (hasVisibleClients(clientList)) {
832
+ return sendMessagePayloadInternalToWindows(clientList, internalPayload);
833
+ }
834
+ // background handling: display if possible and pass to onBackgroundMessage hook
835
+ if (!!internalPayload.notification) {
836
+ await showNotification(wrapInternalPayload(internalPayload));
837
+ }
838
+ if (!messaging) {
839
+ return;
840
+ }
841
+ if (!!messaging.onBackgroundMessageHandler) {
842
+ const payload = externalizePayload(internalPayload);
843
+ if (typeof messaging.onBackgroundMessageHandler === 'function') {
844
+ await messaging.onBackgroundMessageHandler(payload);
845
+ }
846
+ else {
847
+ messaging.onBackgroundMessageHandler.next(payload);
848
+ }
849
+ }
850
+ }
851
+ async function onNotificationClick(event) {
852
+ var _a, _b;
853
+ const internalPayload = (_b = (_a = event.notification) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b[FCM_MSG];
854
+ if (!internalPayload) {
855
+ return;
856
+ }
857
+ else if (event.action) {
858
+ // User clicked on an action button. This will allow developers to act on action button clicks
859
+ // by using a custom onNotificationClick listener that they define.
860
+ return;
861
+ }
862
+ // Prevent other listeners from receiving the event
863
+ event.stopImmediatePropagation();
864
+ event.notification.close();
865
+ // Note clicking on a notification with no link set will focus the Chrome's current tab.
866
+ const link = getLink(internalPayload);
867
+ if (!link) {
868
+ return;
869
+ }
870
+ // FM should only open/focus links from app's origin.
871
+ const url = new URL(link, self.location.href);
872
+ const originUrl = new URL(self.location.origin);
873
+ if (url.host !== originUrl.host) {
874
+ return;
875
+ }
876
+ let client = await getWindowClient(url);
877
+ if (!client) {
878
+ client = await self.clients.openWindow(link);
879
+ // Wait three seconds for the client to initialize and set up the message handler so that it
880
+ // can receive the message.
881
+ await sleep(3000);
882
+ }
883
+ else {
884
+ client = await client.focus();
885
+ }
886
+ if (!client) {
887
+ // Window Client will not be returned if it's for a third party origin.
888
+ return;
889
+ }
890
+ internalPayload.messageType = MessageType.NOTIFICATION_CLICKED;
891
+ internalPayload.isFirebaseMessaging = true;
892
+ return client.postMessage(internalPayload);
893
+ }
894
+ function wrapInternalPayload(internalPayload) {
895
+ const wrappedInternalPayload = Object.assign({}, internalPayload.notification);
896
+ // Put the message payload under FCM_MSG name so we can identify the notification as being an FCM
897
+ // notification vs a notification from somewhere else (i.e. normal web push or developer generated
898
+ // notification).
899
+ wrappedInternalPayload.data = {
900
+ [FCM_MSG]: internalPayload
901
+ };
902
+ return wrappedInternalPayload;
903
+ }
904
+ function getMessagePayloadInternal({ data }) {
905
+ if (!data) {
906
+ return null;
907
+ }
908
+ try {
909
+ return data.json();
910
+ }
911
+ catch (err) {
912
+ // Not JSON so not an FCM message.
913
+ return null;
914
+ }
915
+ }
916
+ /**
917
+ * @param url The URL to look for when focusing a client.
918
+ * @return Returns an existing window client or a newly opened WindowClient.
919
+ */
920
+ async function getWindowClient(url) {
921
+ const clientList = await getClientList();
922
+ for (const client of clientList) {
923
+ const clientUrl = new URL(client.url, self.location.href);
924
+ if (url.host === clientUrl.host) {
925
+ return client;
926
+ }
927
+ }
928
+ return null;
929
+ }
930
+ /**
931
+ * @returns If there is currently a visible WindowClient, this method will resolve to true,
932
+ * otherwise false.
933
+ */
934
+ function hasVisibleClients(clientList) {
935
+ return clientList.some(client => client.visibilityState === 'visible' &&
936
+ // Ignore chrome-extension clients as that matches the background pages of extensions, which
937
+ // are always considered visible for some reason.
938
+ !client.url.startsWith('chrome-extension://'));
939
+ }
940
+ function sendMessagePayloadInternalToWindows(clientList, internalPayload) {
941
+ internalPayload.isFirebaseMessaging = true;
942
+ internalPayload.messageType = MessageType.PUSH_RECEIVED;
943
+ for (const client of clientList) {
944
+ client.postMessage(internalPayload);
945
+ }
946
+ }
947
+ function getClientList() {
948
+ return self.clients.matchAll({
949
+ type: 'window',
950
+ includeUncontrolled: true
951
+ // TS doesn't know that "type: 'window'" means it'll return WindowClient[]
952
+ });
953
+ }
954
+ function showNotification(notificationPayloadInternal) {
955
+ var _a;
956
+ // Note: Firefox does not support the maxActions property.
957
+ // https://developer.mozilla.org/en-US/docs/Web/API/notification/maxActions
958
+ const { actions } = notificationPayloadInternal;
959
+ const { maxActions } = Notification;
960
+ if (actions && maxActions && actions.length > maxActions) {
961
+ console.warn(`This browser only supports ${maxActions} actions. The remaining actions will not be displayed.`);
962
+ }
963
+ return self.registration.showNotification(
964
+ /* title= */ (_a = notificationPayloadInternal.title) !== null && _a !== void 0 ? _a : '', notificationPayloadInternal);
965
+ }
966
+ function getLink(payload) {
967
+ var _a, _b, _c;
968
+ // eslint-disable-next-line camelcase
969
+ const link = (_b = (_a = payload.fcmOptions) === null || _a === void 0 ? void 0 : _a.link) !== null && _b !== void 0 ? _b : (_c = payload.notification) === null || _c === void 0 ? void 0 : _c.click_action;
970
+ if (link) {
971
+ return link;
972
+ }
973
+ if (isConsoleMessage(payload.data)) {
974
+ // Notification created in the Firebase Console. Redirect to origin.
975
+ return self.location.origin;
976
+ }
977
+ else {
978
+ return null;
979
+ }
980
980
  }
981
981
 
982
- /**
983
- * @license
984
- * Copyright 2019 Google LLC
985
- *
986
- * Licensed under the Apache License, Version 2.0 (the "License");
987
- * you may not use this file except in compliance with the License.
988
- * You may obtain a copy of the License at
989
- *
990
- * http://www.apache.org/licenses/LICENSE-2.0
991
- *
992
- * Unless required by applicable law or agreed to in writing, software
993
- * distributed under the License is distributed on an "AS IS" BASIS,
994
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
995
- * See the License for the specific language governing permissions and
996
- * limitations under the License.
997
- */
998
- function extractAppConfig(app) {
999
- if (!app || !app.options) {
1000
- throw getMissingValueError('App Configuration Object');
1001
- }
1002
- if (!app.name) {
1003
- throw getMissingValueError('App Name');
1004
- }
1005
- // Required app config keys
1006
- const configKeys = [
1007
- 'projectId',
1008
- 'apiKey',
1009
- 'appId',
1010
- 'messagingSenderId'
1011
- ];
1012
- const { options } = app;
1013
- for (const keyName of configKeys) {
1014
- if (!options[keyName]) {
1015
- throw getMissingValueError(keyName);
1016
- }
1017
- }
1018
- return {
1019
- appName: app.name,
1020
- projectId: options.projectId,
1021
- apiKey: options.apiKey,
1022
- appId: options.appId,
1023
- senderId: options.messagingSenderId
1024
- };
1025
- }
1026
- function getMissingValueError(valueName) {
1027
- return ERROR_FACTORY.create("missing-app-config-values" /* ErrorCode.MISSING_APP_CONFIG_VALUES */, {
1028
- valueName
1029
- });
982
+ /**
983
+ * @license
984
+ * Copyright 2019 Google LLC
985
+ *
986
+ * Licensed under the Apache License, Version 2.0 (the "License");
987
+ * you may not use this file except in compliance with the License.
988
+ * You may obtain a copy of the License at
989
+ *
990
+ * http://www.apache.org/licenses/LICENSE-2.0
991
+ *
992
+ * Unless required by applicable law or agreed to in writing, software
993
+ * distributed under the License is distributed on an "AS IS" BASIS,
994
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
995
+ * See the License for the specific language governing permissions and
996
+ * limitations under the License.
997
+ */
998
+ function extractAppConfig(app) {
999
+ if (!app || !app.options) {
1000
+ throw getMissingValueError('App Configuration Object');
1001
+ }
1002
+ if (!app.name) {
1003
+ throw getMissingValueError('App Name');
1004
+ }
1005
+ // Required app config keys
1006
+ const configKeys = [
1007
+ 'projectId',
1008
+ 'apiKey',
1009
+ 'appId',
1010
+ 'messagingSenderId'
1011
+ ];
1012
+ const { options } = app;
1013
+ for (const keyName of configKeys) {
1014
+ if (!options[keyName]) {
1015
+ throw getMissingValueError(keyName);
1016
+ }
1017
+ }
1018
+ return {
1019
+ appName: app.name,
1020
+ projectId: options.projectId,
1021
+ apiKey: options.apiKey,
1022
+ appId: options.appId,
1023
+ senderId: options.messagingSenderId
1024
+ };
1025
+ }
1026
+ function getMissingValueError(valueName) {
1027
+ return ERROR_FACTORY.create("missing-app-config-values" /* ErrorCode.MISSING_APP_CONFIG_VALUES */, {
1028
+ valueName
1029
+ });
1030
1030
  }
1031
1031
 
1032
- /**
1033
- * @license
1034
- * Copyright 2020 Google LLC
1035
- *
1036
- * Licensed under the Apache License, Version 2.0 (the "License");
1037
- * you may not use this file except in compliance with the License.
1038
- * You may obtain a copy of the License at
1039
- *
1040
- * http://www.apache.org/licenses/LICENSE-2.0
1041
- *
1042
- * Unless required by applicable law or agreed to in writing, software
1043
- * distributed under the License is distributed on an "AS IS" BASIS,
1044
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1045
- * See the License for the specific language governing permissions and
1046
- * limitations under the License.
1047
- */
1048
- class MessagingService {
1049
- constructor(app, installations, analyticsProvider) {
1050
- // logging is only done with end user consent. Default to false.
1051
- this.deliveryMetricsExportedToBigQueryEnabled = false;
1052
- this.onBackgroundMessageHandler = null;
1053
- this.onMessageHandler = null;
1054
- this.logEvents = [];
1055
- this.isLogServiceStarted = false;
1056
- const appConfig = extractAppConfig(app);
1057
- this.firebaseDependencies = {
1058
- app,
1059
- appConfig,
1060
- installations,
1061
- analyticsProvider
1062
- };
1063
- }
1064
- _delete() {
1065
- return Promise.resolve();
1066
- }
1032
+ /**
1033
+ * @license
1034
+ * Copyright 2020 Google LLC
1035
+ *
1036
+ * Licensed under the Apache License, Version 2.0 (the "License");
1037
+ * you may not use this file except in compliance with the License.
1038
+ * You may obtain a copy of the License at
1039
+ *
1040
+ * http://www.apache.org/licenses/LICENSE-2.0
1041
+ *
1042
+ * Unless required by applicable law or agreed to in writing, software
1043
+ * distributed under the License is distributed on an "AS IS" BASIS,
1044
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1045
+ * See the License for the specific language governing permissions and
1046
+ * limitations under the License.
1047
+ */
1048
+ class MessagingService {
1049
+ constructor(app, installations, analyticsProvider) {
1050
+ // logging is only done with end user consent. Default to false.
1051
+ this.deliveryMetricsExportedToBigQueryEnabled = false;
1052
+ this.onBackgroundMessageHandler = null;
1053
+ this.onMessageHandler = null;
1054
+ this.logEvents = [];
1055
+ this.isLogServiceStarted = false;
1056
+ const appConfig = extractAppConfig(app);
1057
+ this.firebaseDependencies = {
1058
+ app,
1059
+ appConfig,
1060
+ installations,
1061
+ analyticsProvider
1062
+ };
1063
+ }
1064
+ _delete() {
1065
+ return Promise.resolve();
1066
+ }
1067
1067
  }
1068
1068
 
1069
- /**
1070
- * @license
1071
- * Copyright 2020 Google LLC
1072
- *
1073
- * Licensed under the Apache License, Version 2.0 (the "License");
1074
- * you may not use this file except in compliance with the License.
1075
- * You may obtain a copy of the License at
1076
- *
1077
- * http://www.apache.org/licenses/LICENSE-2.0
1078
- *
1079
- * Unless required by applicable law or agreed to in writing, software
1080
- * distributed under the License is distributed on an "AS IS" BASIS,
1081
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1082
- * See the License for the specific language governing permissions and
1083
- * limitations under the License.
1084
- */
1085
- const SwMessagingFactory = (container) => {
1086
- const messaging = new MessagingService(container.getProvider('app').getImmediate(), container.getProvider('installations-internal').getImmediate(), container.getProvider('analytics-internal'));
1087
- self.addEventListener('push', e => {
1088
- e.waitUntil(onPush(e, messaging));
1089
- });
1090
- self.addEventListener('pushsubscriptionchange', e => {
1091
- e.waitUntil(onSubChange(e, messaging));
1092
- });
1093
- self.addEventListener('notificationclick', e => {
1094
- e.waitUntil(onNotificationClick(e));
1095
- });
1096
- return messaging;
1097
- };
1098
- /**
1099
- * The messaging instance registered in sw is named differently than that of in client. This is
1100
- * because both `registerMessagingInWindow` and `registerMessagingInSw` would be called in
1101
- * `messaging-compat` and component with the same name can only be registered once.
1102
- */
1103
- function registerMessagingInSw() {
1104
- _registerComponent(new Component('messaging-sw', SwMessagingFactory, "PUBLIC" /* ComponentType.PUBLIC */));
1069
+ /**
1070
+ * @license
1071
+ * Copyright 2020 Google LLC
1072
+ *
1073
+ * Licensed under the Apache License, Version 2.0 (the "License");
1074
+ * you may not use this file except in compliance with the License.
1075
+ * You may obtain a copy of the License at
1076
+ *
1077
+ * http://www.apache.org/licenses/LICENSE-2.0
1078
+ *
1079
+ * Unless required by applicable law or agreed to in writing, software
1080
+ * distributed under the License is distributed on an "AS IS" BASIS,
1081
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1082
+ * See the License for the specific language governing permissions and
1083
+ * limitations under the License.
1084
+ */
1085
+ const SwMessagingFactory = (container) => {
1086
+ const messaging = new MessagingService(container.getProvider('app').getImmediate(), container.getProvider('installations-internal').getImmediate(), container.getProvider('analytics-internal'));
1087
+ self.addEventListener('push', e => {
1088
+ e.waitUntil(onPush(e, messaging));
1089
+ });
1090
+ self.addEventListener('pushsubscriptionchange', e => {
1091
+ e.waitUntil(onSubChange(e, messaging));
1092
+ });
1093
+ self.addEventListener('notificationclick', e => {
1094
+ e.waitUntil(onNotificationClick(e));
1095
+ });
1096
+ return messaging;
1097
+ };
1098
+ /**
1099
+ * The messaging instance registered in sw is named differently than that of in client. This is
1100
+ * because both `registerMessagingInWindow` and `registerMessagingInSw` would be called in
1101
+ * `messaging-compat` and component with the same name can only be registered once.
1102
+ */
1103
+ function registerMessagingInSw() {
1104
+ _registerComponent(new Component('messaging-sw', SwMessagingFactory, "PUBLIC" /* ComponentType.PUBLIC */));
1105
1105
  }
1106
1106
 
1107
- /**
1108
- * @license
1109
- * Copyright 2020 Google LLC
1110
- *
1111
- * Licensed under the Apache License, Version 2.0 (the "License");
1112
- * you may not use this file except in compliance with the License.
1113
- * You may obtain a copy of the License at
1114
- *
1115
- * http://www.apache.org/licenses/LICENSE-2.0
1116
- *
1117
- * Unless required by applicable law or agreed to in writing, software
1118
- * distributed under the License is distributed on an "AS IS" BASIS,
1119
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1120
- * See the License for the specific language governing permissions and
1121
- * limitations under the License.
1122
- */
1123
- /**
1124
- * Checks whether all required APIs exist within SW Context
1125
- * @returns a Promise that resolves to a boolean.
1126
- *
1127
- * @public
1128
- */
1129
- async function isSwSupported() {
1130
- // firebase-js-sdk/issues/2393 reveals that idb#open in Safari iframe and Firefox private browsing
1131
- // might be prohibited to run. In these contexts, an error would be thrown during the messaging
1132
- // instantiating phase, informing the developers to import/call isSupported for special handling.
1133
- return (isIndexedDBAvailable() &&
1134
- (await validateIndexedDBOpenable()) &&
1135
- 'PushManager' in self &&
1136
- 'Notification' in self &&
1137
- ServiceWorkerRegistration.prototype.hasOwnProperty('showNotification') &&
1138
- PushSubscription.prototype.hasOwnProperty('getKey'));
1107
+ /**
1108
+ * @license
1109
+ * Copyright 2020 Google LLC
1110
+ *
1111
+ * Licensed under the Apache License, Version 2.0 (the "License");
1112
+ * you may not use this file except in compliance with the License.
1113
+ * You may obtain a copy of the License at
1114
+ *
1115
+ * http://www.apache.org/licenses/LICENSE-2.0
1116
+ *
1117
+ * Unless required by applicable law or agreed to in writing, software
1118
+ * distributed under the License is distributed on an "AS IS" BASIS,
1119
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1120
+ * See the License for the specific language governing permissions and
1121
+ * limitations under the License.
1122
+ */
1123
+ /**
1124
+ * Checks whether all required APIs exist within SW Context
1125
+ * @returns a Promise that resolves to a boolean.
1126
+ *
1127
+ * @public
1128
+ */
1129
+ async function isSwSupported() {
1130
+ // firebase-js-sdk/issues/2393 reveals that idb#open in Safari iframe and Firefox private browsing
1131
+ // might be prohibited to run. In these contexts, an error would be thrown during the messaging
1132
+ // instantiating phase, informing the developers to import/call isSupported for special handling.
1133
+ return (isIndexedDBAvailable() &&
1134
+ (await validateIndexedDBOpenable()) &&
1135
+ 'PushManager' in self &&
1136
+ 'Notification' in self &&
1137
+ ServiceWorkerRegistration.prototype.hasOwnProperty('showNotification') &&
1138
+ PushSubscription.prototype.hasOwnProperty('getKey'));
1139
1139
  }
1140
1140
 
1141
- /**
1142
- * @license
1143
- * Copyright 2020 Google LLC
1144
- *
1145
- * Licensed under the Apache License, Version 2.0 (the "License");
1146
- * you may not use this file except in compliance with the License.
1147
- * You may obtain a copy of the License at
1148
- *
1149
- * http://www.apache.org/licenses/LICENSE-2.0
1150
- *
1151
- * Unless required by applicable law or agreed to in writing, software
1152
- * distributed under the License is distributed on an "AS IS" BASIS,
1153
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1154
- * See the License for the specific language governing permissions and
1155
- * limitations under the License.
1156
- */
1157
- function onBackgroundMessage$1(messaging, nextOrObserver) {
1158
- if (self.document !== undefined) {
1159
- throw ERROR_FACTORY.create("only-available-in-sw" /* ErrorCode.AVAILABLE_IN_SW */);
1160
- }
1161
- messaging.onBackgroundMessageHandler = nextOrObserver;
1162
- return () => {
1163
- messaging.onBackgroundMessageHandler = null;
1164
- };
1141
+ /**
1142
+ * @license
1143
+ * Copyright 2020 Google LLC
1144
+ *
1145
+ * Licensed under the Apache License, Version 2.0 (the "License");
1146
+ * you may not use this file except in compliance with the License.
1147
+ * You may obtain a copy of the License at
1148
+ *
1149
+ * http://www.apache.org/licenses/LICENSE-2.0
1150
+ *
1151
+ * Unless required by applicable law or agreed to in writing, software
1152
+ * distributed under the License is distributed on an "AS IS" BASIS,
1153
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1154
+ * See the License for the specific language governing permissions and
1155
+ * limitations under the License.
1156
+ */
1157
+ function onBackgroundMessage$1(messaging, nextOrObserver) {
1158
+ if (self.document !== undefined) {
1159
+ throw ERROR_FACTORY.create("only-available-in-sw" /* ErrorCode.AVAILABLE_IN_SW */);
1160
+ }
1161
+ messaging.onBackgroundMessageHandler = nextOrObserver;
1162
+ return () => {
1163
+ messaging.onBackgroundMessageHandler = null;
1164
+ };
1165
1165
  }
1166
1166
 
1167
- /**
1168
- * @license
1169
- * Copyright 2020 Google LLC
1170
- *
1171
- * Licensed under the Apache License, Version 2.0 (the "License");
1172
- * you may not use this file except in compliance with the License.
1173
- * You may obtain a copy of the License at
1174
- *
1175
- * http://www.apache.org/licenses/LICENSE-2.0
1176
- *
1177
- * Unless required by applicable law or agreed to in writing, software
1178
- * distributed under the License is distributed on an "AS IS" BASIS,
1179
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1180
- * See the License for the specific language governing permissions and
1181
- * limitations under the License.
1182
- */
1183
- function _setDeliveryMetricsExportedToBigQueryEnabled(messaging, enable) {
1184
- messaging.deliveryMetricsExportedToBigQueryEnabled =
1185
- enable;
1167
+ /**
1168
+ * @license
1169
+ * Copyright 2020 Google LLC
1170
+ *
1171
+ * Licensed under the Apache License, Version 2.0 (the "License");
1172
+ * you may not use this file except in compliance with the License.
1173
+ * You may obtain a copy of the License at
1174
+ *
1175
+ * http://www.apache.org/licenses/LICENSE-2.0
1176
+ *
1177
+ * Unless required by applicable law or agreed to in writing, software
1178
+ * distributed under the License is distributed on an "AS IS" BASIS,
1179
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1180
+ * See the License for the specific language governing permissions and
1181
+ * limitations under the License.
1182
+ */
1183
+ function _setDeliveryMetricsExportedToBigQueryEnabled(messaging, enable) {
1184
+ messaging.deliveryMetricsExportedToBigQueryEnabled =
1185
+ enable;
1186
1186
  }
1187
1187
 
1188
- /**
1189
- * @license
1190
- * Copyright 2017 Google LLC
1191
- *
1192
- * Licensed under the Apache License, Version 2.0 (the "License");
1193
- * you may not use this file except in compliance with the License.
1194
- * You may obtain a copy of the License at
1195
- *
1196
- * http://www.apache.org/licenses/LICENSE-2.0
1197
- *
1198
- * Unless required by applicable law or agreed to in writing, software
1199
- * distributed under the License is distributed on an "AS IS" BASIS,
1200
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1201
- * See the License for the specific language governing permissions and
1202
- * limitations under the License.
1203
- */
1204
- /**
1205
- * Retrieves a Firebase Cloud Messaging instance.
1206
- *
1207
- * @returns The Firebase Cloud Messaging instance associated with the provided firebase app.
1208
- *
1209
- * @public
1210
- */
1211
- function getMessagingInSw(app = getApp()) {
1212
- // Conscious decision to make this async check non-blocking during the messaging instance
1213
- // initialization phase for performance consideration. An error would be thrown latter for
1214
- // developer's information. Developers can then choose to import and call `isSupported` for
1215
- // special handling.
1216
- isSwSupported().then(isSupported => {
1217
- // If `isSwSupported()` resolved, but returned false.
1218
- if (!isSupported) {
1219
- throw ERROR_FACTORY.create("unsupported-browser" /* ErrorCode.UNSUPPORTED_BROWSER */);
1220
- }
1221
- }, _ => {
1222
- // If `isSwSupported()` rejected.
1223
- throw ERROR_FACTORY.create("indexed-db-unsupported" /* ErrorCode.INDEXED_DB_UNSUPPORTED */);
1224
- });
1225
- return _getProvider(getModularInstance(app), 'messaging-sw').getImmediate();
1226
- }
1227
- /**
1228
- * Called when a message is received while the app is in the background. An app is considered to be
1229
- * in the background if no active window is displayed.
1230
- *
1231
- * @param messaging - The {@link Messaging} instance.
1232
- * @param nextOrObserver - This function, or observer object with `next` defined, is called when a
1233
- * message is received and the app is currently in the background.
1234
- *
1235
- * @returns To stop listening for messages execute this returned function
1236
- *
1237
- * @public
1238
- */
1239
- function onBackgroundMessage(messaging, nextOrObserver) {
1240
- messaging = getModularInstance(messaging);
1241
- return onBackgroundMessage$1(messaging, nextOrObserver);
1242
- }
1243
- /**
1244
- * Enables or disables Firebase Cloud Messaging message delivery metrics export to BigQuery. By
1245
- * default, message delivery metrics are not exported to BigQuery. Use this method to enable or
1246
- * disable the export at runtime.
1247
- *
1248
- * @param messaging - The `FirebaseMessaging` instance.
1249
- * @param enable - Whether Firebase Cloud Messaging should export message delivery metrics to
1250
- * BigQuery.
1251
- *
1252
- * @public
1253
- */
1254
- function experimentalSetDeliveryMetricsExportedToBigQueryEnabled(messaging, enable) {
1255
- messaging = getModularInstance(messaging);
1256
- return _setDeliveryMetricsExportedToBigQueryEnabled(messaging, enable);
1188
+ /**
1189
+ * @license
1190
+ * Copyright 2017 Google LLC
1191
+ *
1192
+ * Licensed under the Apache License, Version 2.0 (the "License");
1193
+ * you may not use this file except in compliance with the License.
1194
+ * You may obtain a copy of the License at
1195
+ *
1196
+ * http://www.apache.org/licenses/LICENSE-2.0
1197
+ *
1198
+ * Unless required by applicable law or agreed to in writing, software
1199
+ * distributed under the License is distributed on an "AS IS" BASIS,
1200
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1201
+ * See the License for the specific language governing permissions and
1202
+ * limitations under the License.
1203
+ */
1204
+ /**
1205
+ * Retrieves a Firebase Cloud Messaging instance.
1206
+ *
1207
+ * @returns The Firebase Cloud Messaging instance associated with the provided firebase app.
1208
+ *
1209
+ * @public
1210
+ */
1211
+ function getMessagingInSw(app = getApp()) {
1212
+ // Conscious decision to make this async check non-blocking during the messaging instance
1213
+ // initialization phase for performance consideration. An error would be thrown latter for
1214
+ // developer's information. Developers can then choose to import and call `isSupported` for
1215
+ // special handling.
1216
+ isSwSupported().then(isSupported => {
1217
+ // If `isSwSupported()` resolved, but returned false.
1218
+ if (!isSupported) {
1219
+ throw ERROR_FACTORY.create("unsupported-browser" /* ErrorCode.UNSUPPORTED_BROWSER */);
1220
+ }
1221
+ }, _ => {
1222
+ // If `isSwSupported()` rejected.
1223
+ throw ERROR_FACTORY.create("indexed-db-unsupported" /* ErrorCode.INDEXED_DB_UNSUPPORTED */);
1224
+ });
1225
+ return _getProvider(getModularInstance(app), 'messaging-sw').getImmediate();
1226
+ }
1227
+ /**
1228
+ * Called when a message is received while the app is in the background. An app is considered to be
1229
+ * in the background if no active window is displayed.
1230
+ *
1231
+ * @param messaging - The {@link Messaging} instance.
1232
+ * @param nextOrObserver - This function, or observer object with `next` defined, is called when a
1233
+ * message is received and the app is currently in the background.
1234
+ *
1235
+ * @returns To stop listening for messages execute this returned function
1236
+ *
1237
+ * @public
1238
+ */
1239
+ function onBackgroundMessage(messaging, nextOrObserver) {
1240
+ messaging = getModularInstance(messaging);
1241
+ return onBackgroundMessage$1(messaging, nextOrObserver);
1242
+ }
1243
+ /**
1244
+ * Enables or disables Firebase Cloud Messaging message delivery metrics export to BigQuery. By
1245
+ * default, message delivery metrics are not exported to BigQuery. Use this method to enable or
1246
+ * disable the export at runtime.
1247
+ *
1248
+ * @param messaging - The `FirebaseMessaging` instance.
1249
+ * @param enable - Whether Firebase Cloud Messaging should export message delivery metrics to
1250
+ * BigQuery.
1251
+ *
1252
+ * @public
1253
+ */
1254
+ function experimentalSetDeliveryMetricsExportedToBigQueryEnabled(messaging, enable) {
1255
+ messaging = getModularInstance(messaging);
1256
+ return _setDeliveryMetricsExportedToBigQueryEnabled(messaging, enable);
1257
1257
  }
1258
1258
 
1259
- /**
1260
- * @license
1261
- * Copyright 2017 Google LLC
1262
- *
1263
- * Licensed under the Apache License, Version 2.0 (the "License");
1264
- * you may not use this file except in compliance with the License.
1265
- * You may obtain a copy of the License at
1266
- *
1267
- * http://www.apache.org/licenses/LICENSE-2.0
1268
- *
1269
- * Unless required by applicable law or agreed to in writing, software
1270
- * distributed under the License is distributed on an "AS IS" BASIS,
1271
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1272
- * See the License for the specific language governing permissions and
1273
- * limitations under the License.
1274
- */
1259
+ /**
1260
+ * @license
1261
+ * Copyright 2017 Google LLC
1262
+ *
1263
+ * Licensed under the Apache License, Version 2.0 (the "License");
1264
+ * you may not use this file except in compliance with the License.
1265
+ * You may obtain a copy of the License at
1266
+ *
1267
+ * http://www.apache.org/licenses/LICENSE-2.0
1268
+ *
1269
+ * Unless required by applicable law or agreed to in writing, software
1270
+ * distributed under the License is distributed on an "AS IS" BASIS,
1271
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1272
+ * See the License for the specific language governing permissions and
1273
+ * limitations under the License.
1274
+ */
1275
1275
  registerMessagingInSw();
1276
1276
 
1277
1277
  export { experimentalSetDeliveryMetricsExportedToBigQueryEnabled, getMessagingInSw as getMessaging, isSwSupported as isSupported, onBackgroundMessage };