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