@firebase/messaging 0.9.12 → 0.9.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  import '@firebase/installations';
2
2
  import { Component } from '@firebase/component';
3
- import { openDB, deleteDB, ErrorFactory, validateIndexedDBOpenable, isIndexedDBAvailable, areCookiesEnabled, getModularInstance } from '@firebase/util';
3
+ import { openDB, deleteDB } from 'idb';
4
+ import { ErrorFactory, validateIndexedDBOpenable, isIndexedDBAvailable, areCookiesEnabled, getModularInstance } from '@firebase/util';
4
5
  import { _registerComponent, registerVersion, getApp, _getProvider } from '@firebase/app';
5
6
 
6
7
  /**
@@ -123,69 +124,71 @@ async function migrateOldDatabase(senderId) {
123
124
  }
124
125
  }
125
126
  let tokenDetails = null;
126
- const db = await openDB(OLD_DB_NAME, OLD_DB_VERSION, async (db, oldVersion, newVersion, upgradeTransaction) => {
127
- var _a;
128
- if (oldVersion < 2) {
129
- // Database too old, skip migration.
130
- return;
131
- }
132
- if (!db.objectStoreNames.contains(OLD_OBJECT_STORE_NAME)) {
133
- // Database did not exist. Nothing to do.
134
- return;
135
- }
136
- const objectStore = upgradeTransaction.objectStore(OLD_OBJECT_STORE_NAME);
137
- const value = await objectStore.index('fcmSenderId').get(senderId);
138
- await objectStore.clear();
139
- if (!value) {
140
- // No entry in the database, nothing to migrate.
141
- return;
142
- }
143
- if (oldVersion === 2) {
144
- const oldDetails = value;
145
- if (!oldDetails.auth || !oldDetails.p256dh || !oldDetails.endpoint) {
127
+ const db = await openDB(OLD_DB_NAME, OLD_DB_VERSION, {
128
+ upgrade: async (db, oldVersion, newVersion, upgradeTransaction) => {
129
+ var _a;
130
+ if (oldVersion < 2) {
131
+ // Database too old, skip migration.
146
132
  return;
147
133
  }
148
- tokenDetails = {
149
- token: oldDetails.fcmToken,
150
- createTime: (_a = oldDetails.createTime) !== null && _a !== void 0 ? _a : Date.now(),
151
- subscriptionOptions: {
152
- auth: oldDetails.auth,
153
- p256dh: oldDetails.p256dh,
154
- endpoint: oldDetails.endpoint,
155
- swScope: oldDetails.swScope,
156
- vapidKey: typeof oldDetails.vapidKey === 'string'
157
- ? oldDetails.vapidKey
158
- : arrayToBase64(oldDetails.vapidKey)
159
- }
160
- };
161
- }
162
- else if (oldVersion === 3) {
163
- const oldDetails = value;
164
- tokenDetails = {
165
- token: oldDetails.fcmToken,
166
- createTime: oldDetails.createTime,
167
- subscriptionOptions: {
168
- auth: arrayToBase64(oldDetails.auth),
169
- p256dh: arrayToBase64(oldDetails.p256dh),
170
- endpoint: oldDetails.endpoint,
171
- swScope: oldDetails.swScope,
172
- vapidKey: arrayToBase64(oldDetails.vapidKey)
173
- }
174
- };
175
- }
176
- else if (oldVersion === 4) {
177
- const oldDetails = value;
178
- tokenDetails = {
179
- token: oldDetails.fcmToken,
180
- createTime: oldDetails.createTime,
181
- subscriptionOptions: {
182
- auth: arrayToBase64(oldDetails.auth),
183
- p256dh: arrayToBase64(oldDetails.p256dh),
184
- endpoint: oldDetails.endpoint,
185
- swScope: oldDetails.swScope,
186
- vapidKey: arrayToBase64(oldDetails.vapidKey)
134
+ if (!db.objectStoreNames.contains(OLD_OBJECT_STORE_NAME)) {
135
+ // Database did not exist. Nothing to do.
136
+ return;
137
+ }
138
+ const objectStore = upgradeTransaction.objectStore(OLD_OBJECT_STORE_NAME);
139
+ const value = await objectStore.index('fcmSenderId').get(senderId);
140
+ await objectStore.clear();
141
+ if (!value) {
142
+ // No entry in the database, nothing to migrate.
143
+ return;
144
+ }
145
+ if (oldVersion === 2) {
146
+ const oldDetails = value;
147
+ if (!oldDetails.auth || !oldDetails.p256dh || !oldDetails.endpoint) {
148
+ return;
187
149
  }
188
- };
150
+ tokenDetails = {
151
+ token: oldDetails.fcmToken,
152
+ createTime: (_a = oldDetails.createTime) !== null && _a !== void 0 ? _a : Date.now(),
153
+ subscriptionOptions: {
154
+ auth: oldDetails.auth,
155
+ p256dh: oldDetails.p256dh,
156
+ endpoint: oldDetails.endpoint,
157
+ swScope: oldDetails.swScope,
158
+ vapidKey: typeof oldDetails.vapidKey === 'string'
159
+ ? oldDetails.vapidKey
160
+ : arrayToBase64(oldDetails.vapidKey)
161
+ }
162
+ };
163
+ }
164
+ else if (oldVersion === 3) {
165
+ const oldDetails = value;
166
+ tokenDetails = {
167
+ token: oldDetails.fcmToken,
168
+ createTime: oldDetails.createTime,
169
+ subscriptionOptions: {
170
+ auth: arrayToBase64(oldDetails.auth),
171
+ p256dh: arrayToBase64(oldDetails.p256dh),
172
+ endpoint: oldDetails.endpoint,
173
+ swScope: oldDetails.swScope,
174
+ vapidKey: arrayToBase64(oldDetails.vapidKey)
175
+ }
176
+ };
177
+ }
178
+ else if (oldVersion === 4) {
179
+ const oldDetails = value;
180
+ tokenDetails = {
181
+ token: oldDetails.fcmToken,
182
+ createTime: oldDetails.createTime,
183
+ subscriptionOptions: {
184
+ auth: arrayToBase64(oldDetails.auth),
185
+ p256dh: arrayToBase64(oldDetails.p256dh),
186
+ endpoint: oldDetails.endpoint,
187
+ swScope: oldDetails.swScope,
188
+ vapidKey: arrayToBase64(oldDetails.vapidKey)
189
+ }
190
+ };
191
+ }
189
192
  }
190
193
  });
191
194
  db.close();
@@ -239,14 +242,16 @@ const OBJECT_STORE_NAME = 'firebase-messaging-store';
239
242
  let dbPromise = null;
240
243
  function getDbPromise() {
241
244
  if (!dbPromise) {
242
- dbPromise = openDB(DATABASE_NAME, DATABASE_VERSION, (upgradeDb, oldVersion) => {
243
- // We don't use 'break' in this switch statement, the fall-through behavior is what we want,
244
- // because if there are multiple versions between the old version and the current version, we
245
- // want ALL the migrations that correspond to those versions to run, not only the last one.
246
- // eslint-disable-next-line default-case
247
- switch (oldVersion) {
248
- case 0:
249
- upgradeDb.createObjectStore(OBJECT_STORE_NAME);
245
+ dbPromise = openDB(DATABASE_NAME, DATABASE_VERSION, {
246
+ upgrade: (upgradeDb, oldVersion) => {
247
+ // We don't use 'break' in this switch statement, the fall-through behavior is what we want,
248
+ // because if there are multiple versions between the old version and the current version, we
249
+ // want ALL the migrations that correspond to those versions to run, not only the last one.
250
+ // eslint-disable-next-line default-case
251
+ switch (oldVersion) {
252
+ case 0:
253
+ upgradeDb.createObjectStore(OBJECT_STORE_NAME);
254
+ }
250
255
  }
251
256
  });
252
257
  }
@@ -278,7 +283,7 @@ async function dbSet(firebaseDependencies, tokenDetails) {
278
283
  const db = await getDbPromise();
279
284
  const tx = db.transaction(OBJECT_STORE_NAME, 'readwrite');
280
285
  await tx.objectStore(OBJECT_STORE_NAME).put(tokenDetails, key);
281
- await tx.complete;
286
+ await tx.done;
282
287
  return tokenDetails;
283
288
  }
284
289
  /** Removes record(s) from the objectStore that match the given key. */
@@ -287,7 +292,7 @@ async function dbRemove(firebaseDependencies) {
287
292
  const db = await getDbPromise();
288
293
  const tx = db.transaction(OBJECT_STORE_NAME, 'readwrite');
289
294
  await tx.objectStore(OBJECT_STORE_NAME).delete(key);
290
- await tx.complete;
295
+ await tx.done;
291
296
  }
292
297
  function getKey({ appConfig }) {
293
298
  return appConfig.appId;
@@ -984,7 +989,7 @@ async function messageEventListener(messaging, event) {
984
989
  }
985
990
 
986
991
  const name = "@firebase/messaging";
987
- const version = "0.9.12";
992
+ const version = "0.9.13";
988
993
 
989
994
  /**
990
995
  * @license