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