@firebase/app 0.10.13 → 0.10.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.
package/dist/index.cjs.js CHANGED
@@ -3,7 +3,6 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var component = require('@firebase/component');
6
- var tslib = require('tslib');
7
6
  var logger$1 = require('@firebase/logger');
8
7
  var util = require('@firebase/util');
9
8
  var idb = require('idb');
@@ -24,31 +23,30 @@ var idb = require('idb');
24
23
  * See the License for the specific language governing permissions and
25
24
  * limitations under the License.
26
25
  */
27
- var PlatformLoggerServiceImpl = /** @class */ (function () {
28
- function PlatformLoggerServiceImpl(container) {
26
+ class PlatformLoggerServiceImpl {
27
+ constructor(container) {
29
28
  this.container = container;
30
29
  }
31
30
  // In initial implementation, this will be called by installations on
32
31
  // auth token refresh, and installations will send this string.
33
- PlatformLoggerServiceImpl.prototype.getPlatformInfoString = function () {
34
- var providers = this.container.getProviders();
32
+ getPlatformInfoString() {
33
+ const providers = this.container.getProviders();
35
34
  // Loop through providers and get library/version pairs from any that are
36
35
  // version components.
37
36
  return providers
38
- .map(function (provider) {
37
+ .map(provider => {
39
38
  if (isVersionServiceProvider(provider)) {
40
- var service = provider.getImmediate();
41
- return "".concat(service.library, "/").concat(service.version);
39
+ const service = provider.getImmediate();
40
+ return `${service.library}/${service.version}`;
42
41
  }
43
42
  else {
44
43
  return null;
45
44
  }
46
45
  })
47
- .filter(function (logString) { return logString; })
46
+ .filter(logString => logString)
48
47
  .join(' ');
49
- };
50
- return PlatformLoggerServiceImpl;
51
- }());
48
+ }
49
+ }
52
50
  /**
53
51
  *
54
52
  * @param provider check if this provider provides a VersionService
@@ -58,12 +56,12 @@ var PlatformLoggerServiceImpl = /** @class */ (function () {
58
56
  * provider.
59
57
  */
60
58
  function isVersionServiceProvider(provider) {
61
- var component = provider.getComponent();
59
+ const component = provider.getComponent();
62
60
  return (component === null || component === void 0 ? void 0 : component.type) === "VERSION" /* ComponentType.VERSION */;
63
61
  }
64
62
 
65
- var name$q = "@firebase/app";
66
- var version$1 = "0.10.13";
63
+ const name$q = "@firebase/app";
64
+ const version$1 = "0.10.14";
67
65
 
68
66
  /**
69
67
  * @license
@@ -81,60 +79,60 @@ var version$1 = "0.10.13";
81
79
  * See the License for the specific language governing permissions and
82
80
  * limitations under the License.
83
81
  */
84
- var logger = new logger$1.Logger('@firebase/app');
82
+ const logger = new logger$1.Logger('@firebase/app');
85
83
 
86
- var name$p = "@firebase/app-compat";
84
+ const name$p = "@firebase/app-compat";
87
85
 
88
- var name$o = "@firebase/analytics-compat";
86
+ const name$o = "@firebase/analytics-compat";
89
87
 
90
- var name$n = "@firebase/analytics";
88
+ const name$n = "@firebase/analytics";
91
89
 
92
- var name$m = "@firebase/app-check-compat";
90
+ const name$m = "@firebase/app-check-compat";
93
91
 
94
- var name$l = "@firebase/app-check";
92
+ const name$l = "@firebase/app-check";
95
93
 
96
- var name$k = "@firebase/auth";
94
+ const name$k = "@firebase/auth";
97
95
 
98
- var name$j = "@firebase/auth-compat";
96
+ const name$j = "@firebase/auth-compat";
99
97
 
100
- var name$i = "@firebase/database";
98
+ const name$i = "@firebase/database";
101
99
 
102
- var name$h = "@firebase/data-connect";
100
+ const name$h = "@firebase/data-connect";
103
101
 
104
- var name$g = "@firebase/database-compat";
102
+ const name$g = "@firebase/database-compat";
105
103
 
106
- var name$f = "@firebase/functions";
104
+ const name$f = "@firebase/functions";
107
105
 
108
- var name$e = "@firebase/functions-compat";
106
+ const name$e = "@firebase/functions-compat";
109
107
 
110
- var name$d = "@firebase/installations";
108
+ const name$d = "@firebase/installations";
111
109
 
112
- var name$c = "@firebase/installations-compat";
110
+ const name$c = "@firebase/installations-compat";
113
111
 
114
- var name$b = "@firebase/messaging";
112
+ const name$b = "@firebase/messaging";
115
113
 
116
- var name$a = "@firebase/messaging-compat";
114
+ const name$a = "@firebase/messaging-compat";
117
115
 
118
- var name$9 = "@firebase/performance";
116
+ const name$9 = "@firebase/performance";
119
117
 
120
- var name$8 = "@firebase/performance-compat";
118
+ const name$8 = "@firebase/performance-compat";
121
119
 
122
- var name$7 = "@firebase/remote-config";
120
+ const name$7 = "@firebase/remote-config";
123
121
 
124
- var name$6 = "@firebase/remote-config-compat";
122
+ const name$6 = "@firebase/remote-config-compat";
125
123
 
126
- var name$5 = "@firebase/storage";
124
+ const name$5 = "@firebase/storage";
127
125
 
128
- var name$4 = "@firebase/storage-compat";
126
+ const name$4 = "@firebase/storage-compat";
129
127
 
130
- var name$3 = "@firebase/firestore";
128
+ const name$3 = "@firebase/firestore";
131
129
 
132
- var name$2 = "@firebase/vertexai-preview";
130
+ const name$2 = "@firebase/vertexai";
133
131
 
134
- var name$1 = "@firebase/firestore-compat";
132
+ const name$1 = "@firebase/firestore-compat";
135
133
 
136
- var name = "firebase";
137
- var version = "10.14.1";
134
+ const name = "firebase";
135
+ const version = "11.0.0";
138
136
 
139
137
  /**
140
138
  * @license
@@ -152,43 +150,42 @@ var version = "10.14.1";
152
150
  * See the License for the specific language governing permissions and
153
151
  * limitations under the License.
154
152
  */
155
- var _a$1;
156
153
  /**
157
154
  * The default app name
158
155
  *
159
156
  * @internal
160
157
  */
161
- var DEFAULT_ENTRY_NAME = '[DEFAULT]';
162
- var PLATFORM_LOG_STRING = (_a$1 = {},
163
- _a$1[name$q] = 'fire-core',
164
- _a$1[name$p] = 'fire-core-compat',
165
- _a$1[name$n] = 'fire-analytics',
166
- _a$1[name$o] = 'fire-analytics-compat',
167
- _a$1[name$l] = 'fire-app-check',
168
- _a$1[name$m] = 'fire-app-check-compat',
169
- _a$1[name$k] = 'fire-auth',
170
- _a$1[name$j] = 'fire-auth-compat',
171
- _a$1[name$i] = 'fire-rtdb',
172
- _a$1[name$h] = 'fire-data-connect',
173
- _a$1[name$g] = 'fire-rtdb-compat',
174
- _a$1[name$f] = 'fire-fn',
175
- _a$1[name$e] = 'fire-fn-compat',
176
- _a$1[name$d] = 'fire-iid',
177
- _a$1[name$c] = 'fire-iid-compat',
178
- _a$1[name$b] = 'fire-fcm',
179
- _a$1[name$a] = 'fire-fcm-compat',
180
- _a$1[name$9] = 'fire-perf',
181
- _a$1[name$8] = 'fire-perf-compat',
182
- _a$1[name$7] = 'fire-rc',
183
- _a$1[name$6] = 'fire-rc-compat',
184
- _a$1[name$5] = 'fire-gcs',
185
- _a$1[name$4] = 'fire-gcs-compat',
186
- _a$1[name$3] = 'fire-fst',
187
- _a$1[name$1] = 'fire-fst-compat',
188
- _a$1[name$2] = 'fire-vertex',
189
- _a$1['fire-js'] = 'fire-js',
190
- _a$1[name] = 'fire-js-all',
191
- _a$1);
158
+ const DEFAULT_ENTRY_NAME = '[DEFAULT]';
159
+ const PLATFORM_LOG_STRING = {
160
+ [name$q]: 'fire-core',
161
+ [name$p]: 'fire-core-compat',
162
+ [name$n]: 'fire-analytics',
163
+ [name$o]: 'fire-analytics-compat',
164
+ [name$l]: 'fire-app-check',
165
+ [name$m]: 'fire-app-check-compat',
166
+ [name$k]: 'fire-auth',
167
+ [name$j]: 'fire-auth-compat',
168
+ [name$i]: 'fire-rtdb',
169
+ [name$h]: 'fire-data-connect',
170
+ [name$g]: 'fire-rtdb-compat',
171
+ [name$f]: 'fire-fn',
172
+ [name$e]: 'fire-fn-compat',
173
+ [name$d]: 'fire-iid',
174
+ [name$c]: 'fire-iid-compat',
175
+ [name$b]: 'fire-fcm',
176
+ [name$a]: 'fire-fcm-compat',
177
+ [name$9]: 'fire-perf',
178
+ [name$8]: 'fire-perf-compat',
179
+ [name$7]: 'fire-rc',
180
+ [name$6]: 'fire-rc-compat',
181
+ [name$5]: 'fire-gcs',
182
+ [name$4]: 'fire-gcs-compat',
183
+ [name$3]: 'fire-fst',
184
+ [name$1]: 'fire-fst-compat',
185
+ [name$2]: 'fire-vertex',
186
+ 'fire-js': 'fire-js',
187
+ [name]: 'fire-js-all'
188
+ };
192
189
 
193
190
  /**
194
191
  * @license
@@ -209,18 +206,18 @@ var PLATFORM_LOG_STRING = (_a$1 = {},
209
206
  /**
210
207
  * @internal
211
208
  */
212
- var _apps = new Map();
209
+ const _apps = new Map();
213
210
  /**
214
211
  * @internal
215
212
  */
216
- var _serverApps = new Map();
213
+ const _serverApps = new Map();
217
214
  /**
218
215
  * Registered components.
219
216
  *
220
217
  * @internal
221
218
  */
222
219
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
223
- var _components = new Map();
220
+ const _components = new Map();
224
221
  /**
225
222
  * @param component - the component being added to this app's container
226
223
  *
@@ -231,7 +228,7 @@ function _addComponent(app, component) {
231
228
  app.container.addComponent(component);
232
229
  }
233
230
  catch (e) {
234
- logger.debug("Component ".concat(component.name, " failed to register with FirebaseApp ").concat(app.name), e);
231
+ logger.debug(`Component ${component.name} failed to register with FirebaseApp ${app.name}`, e);
235
232
  }
236
233
  }
237
234
  /**
@@ -249,39 +246,18 @@ function _addOrOverwriteComponent(app, component) {
249
246
  * @internal
250
247
  */
251
248
  function _registerComponent(component) {
252
- var e_1, _a, e_2, _b;
253
- var componentName = component.name;
249
+ const componentName = component.name;
254
250
  if (_components.has(componentName)) {
255
- logger.debug("There were multiple attempts to register component ".concat(componentName, "."));
251
+ logger.debug(`There were multiple attempts to register component ${componentName}.`);
256
252
  return false;
257
253
  }
258
254
  _components.set(componentName, component);
259
- try {
260
- // add the component to existing app instances
261
- for (var _c = tslib.__values(_apps.values()), _d = _c.next(); !_d.done; _d = _c.next()) {
262
- var app = _d.value;
263
- _addComponent(app, component);
264
- }
265
- }
266
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
267
- finally {
268
- try {
269
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
270
- }
271
- finally { if (e_1) throw e_1.error; }
272
- }
273
- try {
274
- for (var _e = tslib.__values(_serverApps.values()), _f = _e.next(); !_f.done; _f = _e.next()) {
275
- var serverApp = _f.value;
276
- _addComponent(serverApp, component);
277
- }
255
+ // add the component to existing app instances
256
+ for (const app of _apps.values()) {
257
+ _addComponent(app, component);
278
258
  }
279
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
280
- finally {
281
- try {
282
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
283
- }
284
- finally { if (e_2) throw e_2.error; }
259
+ for (const serverApp of _serverApps.values()) {
260
+ _addComponent(serverApp, component);
285
261
  }
286
262
  return true;
287
263
  }
@@ -295,7 +271,7 @@ function _registerComponent(component) {
295
271
  * @internal
296
272
  */
297
273
  function _getProvider(app, name) {
298
- var heartbeatController = app.container
274
+ const heartbeatController = app.container
299
275
  .getProvider('heartbeat')
300
276
  .getImmediate({ optional: true });
301
277
  if (heartbeatController) {
@@ -311,8 +287,7 @@ function _getProvider(app, name) {
311
287
  *
312
288
  * @internal
313
289
  */
314
- function _removeServiceInstance(app, name, instanceIdentifier) {
315
- if (instanceIdentifier === void 0) { instanceIdentifier = DEFAULT_ENTRY_NAME; }
290
+ function _removeServiceInstance(app, name, instanceIdentifier = DEFAULT_ENTRY_NAME) {
316
291
  _getProvider(app, name).clearInstance(instanceIdentifier);
317
292
  }
318
293
  /**
@@ -362,26 +337,25 @@ function _clearComponents() {
362
337
  * See the License for the specific language governing permissions and
363
338
  * limitations under the License.
364
339
  */
365
- var _a;
366
- var ERRORS = (_a = {},
367
- _a["no-app" /* AppError.NO_APP */] = "No Firebase App '{$appName}' has been created - " +
340
+ const ERRORS = {
341
+ ["no-app" /* AppError.NO_APP */]: "No Firebase App '{$appName}' has been created - " +
368
342
  'call initializeApp() first',
369
- _a["bad-app-name" /* AppError.BAD_APP_NAME */] = "Illegal App name: '{$appName}'",
370
- _a["duplicate-app" /* AppError.DUPLICATE_APP */] = "Firebase App named '{$appName}' already exists with different options or config",
371
- _a["app-deleted" /* AppError.APP_DELETED */] = "Firebase App named '{$appName}' already deleted",
372
- _a["server-app-deleted" /* AppError.SERVER_APP_DELETED */] = 'Firebase Server App has been deleted',
373
- _a["no-options" /* AppError.NO_OPTIONS */] = 'Need to provide options, when not being deployed to hosting via source.',
374
- _a["invalid-app-argument" /* AppError.INVALID_APP_ARGUMENT */] = 'firebase.{$appName}() takes either no argument or a ' +
343
+ ["bad-app-name" /* AppError.BAD_APP_NAME */]: "Illegal App name: '{$appName}'",
344
+ ["duplicate-app" /* AppError.DUPLICATE_APP */]: "Firebase App named '{$appName}' already exists with different options or config",
345
+ ["app-deleted" /* AppError.APP_DELETED */]: "Firebase App named '{$appName}' already deleted",
346
+ ["server-app-deleted" /* AppError.SERVER_APP_DELETED */]: 'Firebase Server App has been deleted',
347
+ ["no-options" /* AppError.NO_OPTIONS */]: 'Need to provide options, when not being deployed to hosting via source.',
348
+ ["invalid-app-argument" /* AppError.INVALID_APP_ARGUMENT */]: 'firebase.{$appName}() takes either no argument or a ' +
375
349
  'Firebase App instance.',
376
- _a["invalid-log-argument" /* AppError.INVALID_LOG_ARGUMENT */] = 'First argument to `onLog` must be null or a function.',
377
- _a["idb-open" /* AppError.IDB_OPEN */] = 'Error thrown when opening IndexedDB. Original error: {$originalErrorMessage}.',
378
- _a["idb-get" /* AppError.IDB_GET */] = 'Error thrown when reading from IndexedDB. Original error: {$originalErrorMessage}.',
379
- _a["idb-set" /* AppError.IDB_WRITE */] = 'Error thrown when writing to IndexedDB. Original error: {$originalErrorMessage}.',
380
- _a["idb-delete" /* AppError.IDB_DELETE */] = 'Error thrown when deleting from IndexedDB. Original error: {$originalErrorMessage}.',
381
- _a["finalization-registry-not-supported" /* AppError.FINALIZATION_REGISTRY_NOT_SUPPORTED */] = 'FirebaseServerApp deleteOnDeref field defined but the JS runtime does not support FinalizationRegistry.',
382
- _a["invalid-server-app-environment" /* AppError.INVALID_SERVER_APP_ENVIRONMENT */] = 'FirebaseServerApp is not for use in browser environments.',
383
- _a);
384
- var ERROR_FACTORY = new util.ErrorFactory('app', 'Firebase', ERRORS);
350
+ ["invalid-log-argument" /* AppError.INVALID_LOG_ARGUMENT */]: 'First argument to `onLog` must be null or a function.',
351
+ ["idb-open" /* AppError.IDB_OPEN */]: 'Error thrown when opening IndexedDB. Original error: {$originalErrorMessage}.',
352
+ ["idb-get" /* AppError.IDB_GET */]: 'Error thrown when reading from IndexedDB. Original error: {$originalErrorMessage}.',
353
+ ["idb-set" /* AppError.IDB_WRITE */]: 'Error thrown when writing to IndexedDB. Original error: {$originalErrorMessage}.',
354
+ ["idb-delete" /* AppError.IDB_DELETE */]: 'Error thrown when deleting from IndexedDB. Original error: {$originalErrorMessage}.',
355
+ ["finalization-registry-not-supported" /* AppError.FINALIZATION_REGISTRY_NOT_SUPPORTED */]: 'FirebaseServerApp deleteOnDeref field defined but the JS runtime does not support FinalizationRegistry.',
356
+ ["invalid-server-app-environment" /* AppError.INVALID_SERVER_APP_ENVIRONMENT */]: 'FirebaseServerApp is not for use in browser environments.'
357
+ };
358
+ const ERROR_FACTORY = new util.ErrorFactory('app', 'Firebase', ERRORS);
385
359
 
386
360
  /**
387
361
  * @license
@@ -399,82 +373,56 @@ var ERROR_FACTORY = new util.ErrorFactory('app', 'Firebase', ERRORS);
399
373
  * See the License for the specific language governing permissions and
400
374
  * limitations under the License.
401
375
  */
402
- var FirebaseAppImpl = /** @class */ (function () {
403
- function FirebaseAppImpl(options, config, container) {
404
- var _this = this;
376
+ class FirebaseAppImpl {
377
+ constructor(options, config, container) {
405
378
  this._isDeleted = false;
406
- this._options = tslib.__assign({}, options);
407
- this._config = tslib.__assign({}, config);
379
+ this._options = Object.assign({}, options);
380
+ this._config = Object.assign({}, config);
408
381
  this._name = config.name;
409
382
  this._automaticDataCollectionEnabled =
410
383
  config.automaticDataCollectionEnabled;
411
384
  this._container = container;
412
- this.container.addComponent(new component.Component('app', function () { return _this; }, "PUBLIC" /* ComponentType.PUBLIC */));
385
+ this.container.addComponent(new component.Component('app', () => this, "PUBLIC" /* ComponentType.PUBLIC */));
386
+ }
387
+ get automaticDataCollectionEnabled() {
388
+ this.checkDestroyed();
389
+ return this._automaticDataCollectionEnabled;
390
+ }
391
+ set automaticDataCollectionEnabled(val) {
392
+ this.checkDestroyed();
393
+ this._automaticDataCollectionEnabled = val;
394
+ }
395
+ get name() {
396
+ this.checkDestroyed();
397
+ return this._name;
398
+ }
399
+ get options() {
400
+ this.checkDestroyed();
401
+ return this._options;
402
+ }
403
+ get config() {
404
+ this.checkDestroyed();
405
+ return this._config;
406
+ }
407
+ get container() {
408
+ return this._container;
409
+ }
410
+ get isDeleted() {
411
+ return this._isDeleted;
412
+ }
413
+ set isDeleted(val) {
414
+ this._isDeleted = val;
413
415
  }
414
- Object.defineProperty(FirebaseAppImpl.prototype, "automaticDataCollectionEnabled", {
415
- get: function () {
416
- this.checkDestroyed();
417
- return this._automaticDataCollectionEnabled;
418
- },
419
- set: function (val) {
420
- this.checkDestroyed();
421
- this._automaticDataCollectionEnabled = val;
422
- },
423
- enumerable: false,
424
- configurable: true
425
- });
426
- Object.defineProperty(FirebaseAppImpl.prototype, "name", {
427
- get: function () {
428
- this.checkDestroyed();
429
- return this._name;
430
- },
431
- enumerable: false,
432
- configurable: true
433
- });
434
- Object.defineProperty(FirebaseAppImpl.prototype, "options", {
435
- get: function () {
436
- this.checkDestroyed();
437
- return this._options;
438
- },
439
- enumerable: false,
440
- configurable: true
441
- });
442
- Object.defineProperty(FirebaseAppImpl.prototype, "config", {
443
- get: function () {
444
- this.checkDestroyed();
445
- return this._config;
446
- },
447
- enumerable: false,
448
- configurable: true
449
- });
450
- Object.defineProperty(FirebaseAppImpl.prototype, "container", {
451
- get: function () {
452
- return this._container;
453
- },
454
- enumerable: false,
455
- configurable: true
456
- });
457
- Object.defineProperty(FirebaseAppImpl.prototype, "isDeleted", {
458
- get: function () {
459
- return this._isDeleted;
460
- },
461
- set: function (val) {
462
- this._isDeleted = val;
463
- },
464
- enumerable: false,
465
- configurable: true
466
- });
467
416
  /**
468
417
  * This function will throw an Error if the App has already been deleted -
469
418
  * use before performing API actions on the App.
470
419
  */
471
- FirebaseAppImpl.prototype.checkDestroyed = function () {
420
+ checkDestroyed() {
472
421
  if (this.isDeleted) {
473
422
  throw ERROR_FACTORY.create("app-deleted" /* AppError.APP_DELETED */, { appName: this._name });
474
423
  }
475
- };
476
- return FirebaseAppImpl;
477
- }());
424
+ }
425
+ }
478
426
 
479
427
  /**
480
428
  * @license
@@ -492,57 +440,50 @@ var FirebaseAppImpl = /** @class */ (function () {
492
440
  * See the License for the specific language governing permissions and
493
441
  * limitations under the License.
494
442
  */
495
- var FirebaseServerAppImpl = /** @class */ (function (_super) {
496
- tslib.__extends(FirebaseServerAppImpl, _super);
497
- function FirebaseServerAppImpl(options, serverConfig, name, container) {
498
- var _this = this;
443
+ class FirebaseServerAppImpl extends FirebaseAppImpl {
444
+ constructor(options, serverConfig, name, container) {
499
445
  // Build configuration parameters for the FirebaseAppImpl base class.
500
- var automaticDataCollectionEnabled = serverConfig.automaticDataCollectionEnabled !== undefined
446
+ const automaticDataCollectionEnabled = serverConfig.automaticDataCollectionEnabled !== undefined
501
447
  ? serverConfig.automaticDataCollectionEnabled
502
448
  : false;
503
449
  // Create the FirebaseAppSettings object for the FirebaseAppImp constructor.
504
- var config = {
505
- name: name,
506
- automaticDataCollectionEnabled: automaticDataCollectionEnabled
450
+ const config = {
451
+ name,
452
+ automaticDataCollectionEnabled
507
453
  };
508
454
  if (options.apiKey !== undefined) {
509
455
  // Construct the parent FirebaseAppImp object.
510
- _this = _super.call(this, options, config, container) || this;
456
+ super(options, config, container);
511
457
  }
512
458
  else {
513
- var appImpl = options;
514
- _this = _super.call(this, appImpl.options, config, container) || this;
459
+ const appImpl = options;
460
+ super(appImpl.options, config, container);
515
461
  }
516
462
  // Now construct the data for the FirebaseServerAppImpl.
517
- _this._serverConfig = tslib.__assign({ automaticDataCollectionEnabled: automaticDataCollectionEnabled }, serverConfig);
518
- _this._finalizationRegistry = null;
463
+ this._serverConfig = Object.assign({ automaticDataCollectionEnabled }, serverConfig);
464
+ this._finalizationRegistry = null;
519
465
  if (typeof FinalizationRegistry !== 'undefined') {
520
- _this._finalizationRegistry = new FinalizationRegistry(function () {
521
- _this.automaticCleanup();
466
+ this._finalizationRegistry = new FinalizationRegistry(() => {
467
+ this.automaticCleanup();
522
468
  });
523
469
  }
524
- _this._refCount = 0;
525
- _this.incRefCount(_this._serverConfig.releaseOnDeref);
470
+ this._refCount = 0;
471
+ this.incRefCount(this._serverConfig.releaseOnDeref);
526
472
  // Do not retain a hard reference to the dref object, otherwise the FinalizationRegistry
527
473
  // will never trigger.
528
- _this._serverConfig.releaseOnDeref = undefined;
474
+ this._serverConfig.releaseOnDeref = undefined;
529
475
  serverConfig.releaseOnDeref = undefined;
530
476
  registerVersion(name$q, version$1, 'serverapp');
531
- return _this;
532
477
  }
533
- FirebaseServerAppImpl.prototype.toJSON = function () {
478
+ toJSON() {
534
479
  return undefined;
535
- };
536
- Object.defineProperty(FirebaseServerAppImpl.prototype, "refCount", {
537
- get: function () {
538
- return this._refCount;
539
- },
540
- enumerable: false,
541
- configurable: true
542
- });
480
+ }
481
+ get refCount() {
482
+ return this._refCount;
483
+ }
543
484
  // Increment the reference count of this server app. If an object is provided, register it
544
485
  // with the finalization registry.
545
- FirebaseServerAppImpl.prototype.incRefCount = function (obj) {
486
+ incRefCount(obj) {
546
487
  if (this.isDeleted) {
547
488
  return;
548
489
  }
@@ -550,39 +491,34 @@ var FirebaseServerAppImpl = /** @class */ (function (_super) {
550
491
  if (obj !== undefined && this._finalizationRegistry !== null) {
551
492
  this._finalizationRegistry.register(obj, this);
552
493
  }
553
- };
494
+ }
554
495
  // Decrement the reference count.
555
- FirebaseServerAppImpl.prototype.decRefCount = function () {
496
+ decRefCount() {
556
497
  if (this.isDeleted) {
557
498
  return 0;
558
499
  }
559
500
  return --this._refCount;
560
- };
501
+ }
561
502
  // Invoked by the FinalizationRegistry callback to note that this app should go through its
562
503
  // reference counts and delete itself if no reference count remain. The coordinating logic that
563
504
  // handles this is in deleteApp(...).
564
- FirebaseServerAppImpl.prototype.automaticCleanup = function () {
505
+ automaticCleanup() {
565
506
  void deleteApp(this);
566
- };
567
- Object.defineProperty(FirebaseServerAppImpl.prototype, "settings", {
568
- get: function () {
569
- this.checkDestroyed();
570
- return this._serverConfig;
571
- },
572
- enumerable: false,
573
- configurable: true
574
- });
507
+ }
508
+ get settings() {
509
+ this.checkDestroyed();
510
+ return this._serverConfig;
511
+ }
575
512
  /**
576
513
  * This function will throw an Error if the App has already been deleted -
577
514
  * use before performing API actions on the App.
578
515
  */
579
- FirebaseServerAppImpl.prototype.checkDestroyed = function () {
516
+ checkDestroyed() {
580
517
  if (this.isDeleted) {
581
518
  throw ERROR_FACTORY.create("server-app-deleted" /* AppError.SERVER_APP_DELETED */);
582
519
  }
583
- };
584
- return FirebaseServerAppImpl;
585
- }(FirebaseAppImpl));
520
+ }
521
+ }
586
522
 
587
523
  /**
588
524
  * @license
@@ -605,17 +541,15 @@ var FirebaseServerAppImpl = /** @class */ (function (_super) {
605
541
  *
606
542
  * @public
607
543
  */
608
- var SDK_VERSION = version;
609
- function initializeApp(_options, rawConfig) {
610
- var e_1, _a;
611
- if (rawConfig === void 0) { rawConfig = {}; }
612
- var options = _options;
544
+ const SDK_VERSION = version;
545
+ function initializeApp(_options, rawConfig = {}) {
546
+ let options = _options;
613
547
  if (typeof rawConfig !== 'object') {
614
- var name_1 = rawConfig;
615
- rawConfig = { name: name_1 };
548
+ const name = rawConfig;
549
+ rawConfig = { name };
616
550
  }
617
- var config = tslib.__assign({ name: DEFAULT_ENTRY_NAME, automaticDataCollectionEnabled: false }, rawConfig);
618
- var name = config.name;
551
+ const config = Object.assign({ name: DEFAULT_ENTRY_NAME, automaticDataCollectionEnabled: false }, rawConfig);
552
+ const name = config.name;
619
553
  if (typeof name !== 'string' || !name) {
620
554
  throw ERROR_FACTORY.create("bad-app-name" /* AppError.BAD_APP_NAME */, {
621
555
  appName: String(name)
@@ -625,7 +559,7 @@ function initializeApp(_options, rawConfig) {
625
559
  if (!options) {
626
560
  throw ERROR_FACTORY.create("no-options" /* AppError.NO_OPTIONS */);
627
561
  }
628
- var existingApp = _apps.get(name);
562
+ const existingApp = _apps.get(name);
629
563
  if (existingApp) {
630
564
  // return the existing app if options and config deep equal the ones in the existing app.
631
565
  if (util.deepEqual(options, existingApp.options) &&
@@ -636,26 +570,15 @@ function initializeApp(_options, rawConfig) {
636
570
  throw ERROR_FACTORY.create("duplicate-app" /* AppError.DUPLICATE_APP */, { appName: name });
637
571
  }
638
572
  }
639
- var container = new component.ComponentContainer(name);
640
- try {
641
- for (var _b = tslib.__values(_components.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
642
- var component$1 = _c.value;
643
- container.addComponent(component$1);
644
- }
573
+ const container = new component.ComponentContainer(name);
574
+ for (const component of _components.values()) {
575
+ container.addComponent(component);
645
576
  }
646
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
647
- finally {
648
- try {
649
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
650
- }
651
- finally { if (e_1) throw e_1.error; }
652
- }
653
- var newApp = new FirebaseAppImpl(options, config, container);
577
+ const newApp = new FirebaseAppImpl(options, config, container);
654
578
  _apps.set(name, newApp);
655
579
  return newApp;
656
580
  }
657
581
  function initializeServerApp(_options, _serverAppConfig) {
658
- var e_2, _a;
659
582
  if (util.isBrowser() && !util.isWebWorker()) {
660
583
  // FirebaseServerApp isn't designed to be run in browsers.
661
584
  throw ERROR_FACTORY.create("invalid-server-app-environment" /* AppError.INVALID_SERVER_APP_ENVIRONMENT */);
@@ -663,7 +586,7 @@ function initializeServerApp(_options, _serverAppConfig) {
663
586
  if (_serverAppConfig.automaticDataCollectionEnabled === undefined) {
664
587
  _serverAppConfig.automaticDataCollectionEnabled = false;
665
588
  }
666
- var appOptions;
589
+ let appOptions;
667
590
  if (_isFirebaseApp(_options)) {
668
591
  appOptions = _options.options;
669
592
  }
@@ -671,41 +594,31 @@ function initializeServerApp(_options, _serverAppConfig) {
671
594
  appOptions = _options;
672
595
  }
673
596
  // Build an app name based on a hash of the configuration options.
674
- var nameObj = tslib.__assign(tslib.__assign({}, _serverAppConfig), appOptions);
597
+ const nameObj = Object.assign(Object.assign({}, _serverAppConfig), appOptions);
675
598
  // However, Do not mangle the name based on releaseOnDeref, since it will vary between the
676
599
  // construction of FirebaseServerApp instances. For example, if the object is the request headers.
677
600
  if (nameObj.releaseOnDeref !== undefined) {
678
601
  delete nameObj.releaseOnDeref;
679
602
  }
680
- var hashCode = function (s) {
681
- return tslib.__spreadArray([], tslib.__read(s), false).reduce(function (hash, c) { return (Math.imul(31, hash) + c.charCodeAt(0)) | 0; }, 0);
603
+ const hashCode = (s) => {
604
+ return [...s].reduce((hash, c) => (Math.imul(31, hash) + c.charCodeAt(0)) | 0, 0);
682
605
  };
683
606
  if (_serverAppConfig.releaseOnDeref !== undefined) {
684
607
  if (typeof FinalizationRegistry === 'undefined') {
685
608
  throw ERROR_FACTORY.create("finalization-registry-not-supported" /* AppError.FINALIZATION_REGISTRY_NOT_SUPPORTED */, {});
686
609
  }
687
610
  }
688
- var nameString = '' + hashCode(JSON.stringify(nameObj));
689
- var existingApp = _serverApps.get(nameString);
611
+ const nameString = '' + hashCode(JSON.stringify(nameObj));
612
+ const existingApp = _serverApps.get(nameString);
690
613
  if (existingApp) {
691
614
  existingApp.incRefCount(_serverAppConfig.releaseOnDeref);
692
615
  return existingApp;
693
616
  }
694
- var container = new component.ComponentContainer(nameString);
695
- try {
696
- for (var _b = tslib.__values(_components.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
697
- var component$1 = _c.value;
698
- container.addComponent(component$1);
699
- }
700
- }
701
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
702
- finally {
703
- try {
704
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
705
- }
706
- finally { if (e_2) throw e_2.error; }
617
+ const container = new component.ComponentContainer(nameString);
618
+ for (const component of _components.values()) {
619
+ container.addComponent(component);
707
620
  }
708
- var newApp = new FirebaseServerAppImpl(appOptions, _serverAppConfig, nameString, container);
621
+ const newApp = new FirebaseServerAppImpl(appOptions, _serverAppConfig, nameString, container);
709
622
  _serverApps.set(nameString, newApp);
710
623
  return newApp;
711
624
  }
@@ -738,9 +651,8 @@ function initializeServerApp(_options, _serverAppConfig) {
738
651
  *
739
652
  * @public
740
653
  */
741
- function getApp(name) {
742
- if (name === void 0) { name = DEFAULT_ENTRY_NAME; }
743
- var app = _apps.get(name);
654
+ function getApp(name = DEFAULT_ENTRY_NAME) {
655
+ const app = _apps.get(name);
744
656
  if (!app && name === DEFAULT_ENTRY_NAME && util.getDefaultAppConfig()) {
745
657
  return initializeApp();
746
658
  }
@@ -773,37 +685,26 @@ function getApps() {
773
685
  *
774
686
  * @public
775
687
  */
776
- function deleteApp(app) {
777
- return tslib.__awaiter(this, void 0, void 0, function () {
778
- var cleanupProviders, name, firebaseServerApp;
779
- return tslib.__generator(this, function (_a) {
780
- switch (_a.label) {
781
- case 0:
782
- cleanupProviders = false;
783
- name = app.name;
784
- if (_apps.has(name)) {
785
- cleanupProviders = true;
786
- _apps.delete(name);
787
- }
788
- else if (_serverApps.has(name)) {
789
- firebaseServerApp = app;
790
- if (firebaseServerApp.decRefCount() <= 0) {
791
- _serverApps.delete(name);
792
- cleanupProviders = true;
793
- }
794
- }
795
- if (!cleanupProviders) return [3 /*break*/, 2];
796
- return [4 /*yield*/, Promise.all(app.container
797
- .getProviders()
798
- .map(function (provider) { return provider.delete(); }))];
799
- case 1:
800
- _a.sent();
801
- app.isDeleted = true;
802
- _a.label = 2;
803
- case 2: return [2 /*return*/];
804
- }
805
- });
806
- });
688
+ async function deleteApp(app) {
689
+ let cleanupProviders = false;
690
+ const name = app.name;
691
+ if (_apps.has(name)) {
692
+ cleanupProviders = true;
693
+ _apps.delete(name);
694
+ }
695
+ else if (_serverApps.has(name)) {
696
+ const firebaseServerApp = app;
697
+ if (firebaseServerApp.decRefCount() <= 0) {
698
+ _serverApps.delete(name);
699
+ cleanupProviders = true;
700
+ }
701
+ }
702
+ if (cleanupProviders) {
703
+ await Promise.all(app.container
704
+ .getProviders()
705
+ .map(provider => provider.delete()));
706
+ app.isDeleted = true;
707
+ }
807
708
  }
808
709
  /**
809
710
  * Registers a library's name and version for platform logging purposes.
@@ -817,29 +718,29 @@ function registerVersion(libraryKeyOrName, version, variant) {
817
718
  var _a;
818
719
  // TODO: We can use this check to whitelist strings when/if we set up
819
720
  // a good whitelist system.
820
- var library = (_a = PLATFORM_LOG_STRING[libraryKeyOrName]) !== null && _a !== void 0 ? _a : libraryKeyOrName;
721
+ let library = (_a = PLATFORM_LOG_STRING[libraryKeyOrName]) !== null && _a !== void 0 ? _a : libraryKeyOrName;
821
722
  if (variant) {
822
- library += "-".concat(variant);
723
+ library += `-${variant}`;
823
724
  }
824
- var libraryMismatch = library.match(/\s|\//);
825
- var versionMismatch = version.match(/\s|\//);
725
+ const libraryMismatch = library.match(/\s|\//);
726
+ const versionMismatch = version.match(/\s|\//);
826
727
  if (libraryMismatch || versionMismatch) {
827
- var warning = [
828
- "Unable to register library \"".concat(library, "\" with version \"").concat(version, "\":")
728
+ const warning = [
729
+ `Unable to register library "${library}" with version "${version}":`
829
730
  ];
830
731
  if (libraryMismatch) {
831
- warning.push("library name \"".concat(library, "\" contains illegal characters (whitespace or \"/\")"));
732
+ warning.push(`library name "${library}" contains illegal characters (whitespace or "/")`);
832
733
  }
833
734
  if (libraryMismatch && versionMismatch) {
834
735
  warning.push('and');
835
736
  }
836
737
  if (versionMismatch) {
837
- warning.push("version name \"".concat(version, "\" contains illegal characters (whitespace or \"/\")"));
738
+ warning.push(`version name "${version}" contains illegal characters (whitespace or "/")`);
838
739
  }
839
740
  logger.warn(warning.join(' '));
840
741
  return;
841
742
  }
842
- _registerComponent(new component.Component("".concat(library, "-version"), function () { return ({ library: library, version: version }); }, "VERSION" /* ComponentType.VERSION */));
743
+ _registerComponent(new component.Component(`${library}-version`, () => ({ library, version }), "VERSION" /* ComponentType.VERSION */));
843
744
  }
844
745
  /**
845
746
  * Sets log handler for all Firebase SDKs.
@@ -883,14 +784,14 @@ function setLogLevel(logLevel) {
883
784
  * See the License for the specific language governing permissions and
884
785
  * limitations under the License.
885
786
  */
886
- var DB_NAME = 'firebase-heartbeat-database';
887
- var DB_VERSION = 1;
888
- var STORE_NAME = 'firebase-heartbeat-store';
889
- var dbPromise = null;
787
+ const DB_NAME = 'firebase-heartbeat-database';
788
+ const DB_VERSION = 1;
789
+ const STORE_NAME = 'firebase-heartbeat-store';
790
+ let dbPromise = null;
890
791
  function getDbPromise() {
891
792
  if (!dbPromise) {
892
793
  dbPromise = idb.openDB(DB_NAME, DB_VERSION, {
893
- upgrade: function (db, oldVersion) {
794
+ upgrade: (db, oldVersion) => {
894
795
  // We don't use 'break' in this switch statement, the fall-through
895
796
  // behavior is what we want, because if there are multiple versions between
896
797
  // the old version and the current version, we want ALL the migrations
@@ -909,7 +810,7 @@ function getDbPromise() {
909
810
  }
910
811
  }
911
812
  }
912
- }).catch(function (e) {
813
+ }).catch(e => {
913
814
  throw ERROR_FACTORY.create("idb-open" /* AppError.IDB_OPEN */, {
914
815
  originalErrorMessage: e.message
915
816
  });
@@ -917,83 +818,50 @@ function getDbPromise() {
917
818
  }
918
819
  return dbPromise;
919
820
  }
920
- function readHeartbeatsFromIndexedDB(app) {
921
- return tslib.__awaiter(this, void 0, void 0, function () {
922
- var db, tx, result, e_1, idbGetError;
923
- return tslib.__generator(this, function (_a) {
924
- switch (_a.label) {
925
- case 0:
926
- _a.trys.push([0, 4, , 5]);
927
- return [4 /*yield*/, getDbPromise()];
928
- case 1:
929
- db = _a.sent();
930
- tx = db.transaction(STORE_NAME);
931
- return [4 /*yield*/, tx.objectStore(STORE_NAME).get(computeKey(app))];
932
- case 2:
933
- result = _a.sent();
934
- // We already have the value but tx.done can throw,
935
- // so we need to await it here to catch errors
936
- return [4 /*yield*/, tx.done];
937
- case 3:
938
- // We already have the value but tx.done can throw,
939
- // so we need to await it here to catch errors
940
- _a.sent();
941
- return [2 /*return*/, result];
942
- case 4:
943
- e_1 = _a.sent();
944
- if (e_1 instanceof util.FirebaseError) {
945
- logger.warn(e_1.message);
946
- }
947
- else {
948
- idbGetError = ERROR_FACTORY.create("idb-get" /* AppError.IDB_GET */, {
949
- originalErrorMessage: e_1 === null || e_1 === void 0 ? void 0 : e_1.message
950
- });
951
- logger.warn(idbGetError.message);
952
- }
953
- return [3 /*break*/, 5];
954
- case 5: return [2 /*return*/];
955
- }
956
- });
957
- });
821
+ async function readHeartbeatsFromIndexedDB(app) {
822
+ try {
823
+ const db = await getDbPromise();
824
+ const tx = db.transaction(STORE_NAME);
825
+ const result = await tx.objectStore(STORE_NAME).get(computeKey(app));
826
+ // We already have the value but tx.done can throw,
827
+ // so we need to await it here to catch errors
828
+ await tx.done;
829
+ return result;
830
+ }
831
+ catch (e) {
832
+ if (e instanceof util.FirebaseError) {
833
+ logger.warn(e.message);
834
+ }
835
+ else {
836
+ const idbGetError = ERROR_FACTORY.create("idb-get" /* AppError.IDB_GET */, {
837
+ originalErrorMessage: e === null || e === void 0 ? void 0 : e.message
838
+ });
839
+ logger.warn(idbGetError.message);
840
+ }
841
+ }
958
842
  }
959
- function writeHeartbeatsToIndexedDB(app, heartbeatObject) {
960
- return tslib.__awaiter(this, void 0, void 0, function () {
961
- var db, tx, objectStore, e_2, idbGetError;
962
- return tslib.__generator(this, function (_a) {
963
- switch (_a.label) {
964
- case 0:
965
- _a.trys.push([0, 4, , 5]);
966
- return [4 /*yield*/, getDbPromise()];
967
- case 1:
968
- db = _a.sent();
969
- tx = db.transaction(STORE_NAME, 'readwrite');
970
- objectStore = tx.objectStore(STORE_NAME);
971
- return [4 /*yield*/, objectStore.put(heartbeatObject, computeKey(app))];
972
- case 2:
973
- _a.sent();
974
- return [4 /*yield*/, tx.done];
975
- case 3:
976
- _a.sent();
977
- return [3 /*break*/, 5];
978
- case 4:
979
- e_2 = _a.sent();
980
- if (e_2 instanceof util.FirebaseError) {
981
- logger.warn(e_2.message);
982
- }
983
- else {
984
- idbGetError = ERROR_FACTORY.create("idb-set" /* AppError.IDB_WRITE */, {
985
- originalErrorMessage: e_2 === null || e_2 === void 0 ? void 0 : e_2.message
986
- });
987
- logger.warn(idbGetError.message);
988
- }
989
- return [3 /*break*/, 5];
990
- case 5: return [2 /*return*/];
991
- }
992
- });
993
- });
843
+ async function writeHeartbeatsToIndexedDB(app, heartbeatObject) {
844
+ try {
845
+ const db = await getDbPromise();
846
+ const tx = db.transaction(STORE_NAME, 'readwrite');
847
+ const objectStore = tx.objectStore(STORE_NAME);
848
+ await objectStore.put(heartbeatObject, computeKey(app));
849
+ await tx.done;
850
+ }
851
+ catch (e) {
852
+ if (e instanceof util.FirebaseError) {
853
+ logger.warn(e.message);
854
+ }
855
+ else {
856
+ const idbGetError = ERROR_FACTORY.create("idb-set" /* AppError.IDB_WRITE */, {
857
+ originalErrorMessage: e === null || e === void 0 ? void 0 : e.message
858
+ });
859
+ logger.warn(idbGetError.message);
860
+ }
861
+ }
994
862
  }
995
863
  function computeKey(app) {
996
- return "".concat(app.name, "!").concat(app.options.appId);
864
+ return `${app.name}!${app.options.appId}`;
997
865
  }
998
866
 
999
867
  /**
@@ -1012,12 +880,11 @@ function computeKey(app) {
1012
880
  * See the License for the specific language governing permissions and
1013
881
  * limitations under the License.
1014
882
  */
1015
- var MAX_HEADER_BYTES = 1024;
883
+ const MAX_HEADER_BYTES = 1024;
1016
884
  // 30 days
1017
- var STORED_HEARTBEAT_RETENTION_MAX_MILLIS = 30 * 24 * 60 * 60 * 1000;
1018
- var HeartbeatServiceImpl = /** @class */ (function () {
1019
- function HeartbeatServiceImpl(container) {
1020
- var _this = this;
885
+ const STORED_HEARTBEAT_RETENTION_MAX_MILLIS = 30 * 24 * 60 * 60 * 1000;
886
+ class HeartbeatServiceImpl {
887
+ constructor(container) {
1021
888
  this.container = container;
1022
889
  /**
1023
890
  * In-memory cache for heartbeats, used by getHeartbeatsHeader() to generate
@@ -1029,10 +896,10 @@ var HeartbeatServiceImpl = /** @class */ (function () {
1029
896
  * Leave public for easier testing.
1030
897
  */
1031
898
  this._heartbeatsCache = null;
1032
- var app = this.container.getProvider('app').getImmediate();
899
+ const app = this.container.getProvider('app').getImmediate();
1033
900
  this._storage = new HeartbeatStorageImpl(app);
1034
- this._heartbeatsCachePromise = this._storage.read().then(function (result) {
1035
- _this._heartbeatsCache = result;
901
+ this._heartbeatsCachePromise = this._storage.read().then(result => {
902
+ this._heartbeatsCache = result;
1036
903
  return result;
1037
904
  });
1038
905
  }
@@ -1043,57 +910,46 @@ var HeartbeatServiceImpl = /** @class */ (function () {
1043
910
  * Note that we only store one heartbeat per day. So if a heartbeat for today is
1044
911
  * already logged, subsequent calls to this function in the same day will be ignored.
1045
912
  */
1046
- HeartbeatServiceImpl.prototype.triggerHeartbeat = function () {
913
+ async triggerHeartbeat() {
1047
914
  var _a, _b;
1048
- return tslib.__awaiter(this, void 0, void 0, function () {
1049
- var platformLogger, agent, date_1, _c, e_1;
1050
- return tslib.__generator(this, function (_d) {
1051
- switch (_d.label) {
1052
- case 0:
1053
- _d.trys.push([0, 3, , 4]);
1054
- platformLogger = this.container
1055
- .getProvider('platform-logger')
1056
- .getImmediate();
1057
- agent = platformLogger.getPlatformInfoString();
1058
- date_1 = getUTCDateString();
1059
- if (!(((_a = this._heartbeatsCache) === null || _a === void 0 ? void 0 : _a.heartbeats) == null)) return [3 /*break*/, 2];
1060
- _c = this;
1061
- return [4 /*yield*/, this._heartbeatsCachePromise];
1062
- case 1:
1063
- _c._heartbeatsCache = _d.sent();
1064
- // If we failed to construct a heartbeats cache, then return immediately.
1065
- if (((_b = this._heartbeatsCache) === null || _b === void 0 ? void 0 : _b.heartbeats) == null) {
1066
- return [2 /*return*/];
1067
- }
1068
- _d.label = 2;
1069
- case 2:
1070
- // Do not store a heartbeat if one is already stored for this day
1071
- // or if a header has already been sent today.
1072
- if (this._heartbeatsCache.lastSentHeartbeatDate === date_1 ||
1073
- this._heartbeatsCache.heartbeats.some(function (singleDateHeartbeat) { return singleDateHeartbeat.date === date_1; })) {
1074
- return [2 /*return*/];
1075
- }
1076
- else {
1077
- // There is no entry for this date. Create one.
1078
- this._heartbeatsCache.heartbeats.push({ date: date_1, agent: agent });
1079
- }
1080
- // Remove entries older than 30 days.
1081
- this._heartbeatsCache.heartbeats =
1082
- this._heartbeatsCache.heartbeats.filter(function (singleDateHeartbeat) {
1083
- var hbTimestamp = new Date(singleDateHeartbeat.date).valueOf();
1084
- var now = Date.now();
1085
- return now - hbTimestamp <= STORED_HEARTBEAT_RETENTION_MAX_MILLIS;
1086
- });
1087
- return [2 /*return*/, this._storage.overwrite(this._heartbeatsCache)];
1088
- case 3:
1089
- e_1 = _d.sent();
1090
- logger.warn(e_1);
1091
- return [3 /*break*/, 4];
1092
- case 4: return [2 /*return*/];
915
+ try {
916
+ const platformLogger = this.container
917
+ .getProvider('platform-logger')
918
+ .getImmediate();
919
+ // This is the "Firebase user agent" string from the platform logger
920
+ // service, not the browser user agent.
921
+ const agent = platformLogger.getPlatformInfoString();
922
+ const date = getUTCDateString();
923
+ if (((_a = this._heartbeatsCache) === null || _a === void 0 ? void 0 : _a.heartbeats) == null) {
924
+ this._heartbeatsCache = await this._heartbeatsCachePromise;
925
+ // If we failed to construct a heartbeats cache, then return immediately.
926
+ if (((_b = this._heartbeatsCache) === null || _b === void 0 ? void 0 : _b.heartbeats) == null) {
927
+ return;
1093
928
  }
1094
- });
1095
- });
1096
- };
929
+ }
930
+ // Do not store a heartbeat if one is already stored for this day
931
+ // or if a header has already been sent today.
932
+ if (this._heartbeatsCache.lastSentHeartbeatDate === date ||
933
+ this._heartbeatsCache.heartbeats.some(singleDateHeartbeat => singleDateHeartbeat.date === date)) {
934
+ return;
935
+ }
936
+ else {
937
+ // There is no entry for this date. Create one.
938
+ this._heartbeatsCache.heartbeats.push({ date, agent });
939
+ }
940
+ // Remove entries older than 30 days.
941
+ this._heartbeatsCache.heartbeats =
942
+ this._heartbeatsCache.heartbeats.filter(singleDateHeartbeat => {
943
+ const hbTimestamp = new Date(singleDateHeartbeat.date).valueOf();
944
+ const now = Date.now();
945
+ return now - hbTimestamp <= STORED_HEARTBEAT_RETENTION_MAX_MILLIS;
946
+ });
947
+ return this._storage.overwrite(this._heartbeatsCache);
948
+ }
949
+ catch (e) {
950
+ logger.warn(e);
951
+ }
952
+ }
1097
953
  /**
1098
954
  * Returns a base64 encoded string which can be attached to the heartbeat-specific header directly.
1099
955
  * It also clears all heartbeats from memory as well as in IndexedDB.
@@ -1101,76 +957,58 @@ var HeartbeatServiceImpl = /** @class */ (function () {
1101
957
  * NOTE: Consuming product SDKs should not send the header if this method
1102
958
  * returns an empty string.
1103
959
  */
1104
- HeartbeatServiceImpl.prototype.getHeartbeatsHeader = function () {
960
+ async getHeartbeatsHeader() {
1105
961
  var _a;
1106
- return tslib.__awaiter(this, void 0, void 0, function () {
1107
- var date, _b, heartbeatsToSend, unsentEntries, headerString, e_2;
1108
- return tslib.__generator(this, function (_c) {
1109
- switch (_c.label) {
1110
- case 0:
1111
- _c.trys.push([0, 6, , 7]);
1112
- if (!(this._heartbeatsCache === null)) return [3 /*break*/, 2];
1113
- return [4 /*yield*/, this._heartbeatsCachePromise];
1114
- case 1:
1115
- _c.sent();
1116
- _c.label = 2;
1117
- case 2:
1118
- // If it's still null or the array is empty, there is no data to send.
1119
- if (((_a = this._heartbeatsCache) === null || _a === void 0 ? void 0 : _a.heartbeats) == null ||
1120
- this._heartbeatsCache.heartbeats.length === 0) {
1121
- return [2 /*return*/, ''];
1122
- }
1123
- date = getUTCDateString();
1124
- _b = extractHeartbeatsForHeader(this._heartbeatsCache.heartbeats), heartbeatsToSend = _b.heartbeatsToSend, unsentEntries = _b.unsentEntries;
1125
- headerString = util.base64urlEncodeWithoutPadding(JSON.stringify({ version: 2, heartbeats: heartbeatsToSend }));
1126
- // Store last sent date to prevent another being logged/sent for the same day.
1127
- this._heartbeatsCache.lastSentHeartbeatDate = date;
1128
- if (!(unsentEntries.length > 0)) return [3 /*break*/, 4];
1129
- // Store any unsent entries if they exist.
1130
- this._heartbeatsCache.heartbeats = unsentEntries;
1131
- // This seems more likely than emptying the array (below) to lead to some odd state
1132
- // since the cache isn't empty and this will be called again on the next request,
1133
- // and is probably safest if we await it.
1134
- return [4 /*yield*/, this._storage.overwrite(this._heartbeatsCache)];
1135
- case 3:
1136
- // This seems more likely than emptying the array (below) to lead to some odd state
1137
- // since the cache isn't empty and this will be called again on the next request,
1138
- // and is probably safest if we await it.
1139
- _c.sent();
1140
- return [3 /*break*/, 5];
1141
- case 4:
1142
- this._heartbeatsCache.heartbeats = [];
1143
- // Do not wait for this, to reduce latency.
1144
- void this._storage.overwrite(this._heartbeatsCache);
1145
- _c.label = 5;
1146
- case 5: return [2 /*return*/, headerString];
1147
- case 6:
1148
- e_2 = _c.sent();
1149
- logger.warn(e_2);
1150
- return [2 /*return*/, ''];
1151
- case 7: return [2 /*return*/];
1152
- }
1153
- });
1154
- });
1155
- };
1156
- return HeartbeatServiceImpl;
1157
- }());
962
+ try {
963
+ if (this._heartbeatsCache === null) {
964
+ await this._heartbeatsCachePromise;
965
+ }
966
+ // If it's still null or the array is empty, there is no data to send.
967
+ if (((_a = this._heartbeatsCache) === null || _a === void 0 ? void 0 : _a.heartbeats) == null ||
968
+ this._heartbeatsCache.heartbeats.length === 0) {
969
+ return '';
970
+ }
971
+ const date = getUTCDateString();
972
+ // Extract as many heartbeats from the cache as will fit under the size limit.
973
+ const { heartbeatsToSend, unsentEntries } = extractHeartbeatsForHeader(this._heartbeatsCache.heartbeats);
974
+ const headerString = util.base64urlEncodeWithoutPadding(JSON.stringify({ version: 2, heartbeats: heartbeatsToSend }));
975
+ // Store last sent date to prevent another being logged/sent for the same day.
976
+ this._heartbeatsCache.lastSentHeartbeatDate = date;
977
+ if (unsentEntries.length > 0) {
978
+ // Store any unsent entries if they exist.
979
+ this._heartbeatsCache.heartbeats = unsentEntries;
980
+ // This seems more likely than emptying the array (below) to lead to some odd state
981
+ // since the cache isn't empty and this will be called again on the next request,
982
+ // and is probably safest if we await it.
983
+ await this._storage.overwrite(this._heartbeatsCache);
984
+ }
985
+ else {
986
+ this._heartbeatsCache.heartbeats = [];
987
+ // Do not wait for this, to reduce latency.
988
+ void this._storage.overwrite(this._heartbeatsCache);
989
+ }
990
+ return headerString;
991
+ }
992
+ catch (e) {
993
+ logger.warn(e);
994
+ return '';
995
+ }
996
+ }
997
+ }
1158
998
  function getUTCDateString() {
1159
- var today = new Date();
999
+ const today = new Date();
1160
1000
  // Returns date format 'YYYY-MM-DD'
1161
1001
  return today.toISOString().substring(0, 10);
1162
1002
  }
1163
- function extractHeartbeatsForHeader(heartbeatsCache, maxSize) {
1164
- var e_3, _a;
1165
- if (maxSize === void 0) { maxSize = MAX_HEADER_BYTES; }
1003
+ function extractHeartbeatsForHeader(heartbeatsCache, maxSize = MAX_HEADER_BYTES) {
1166
1004
  // Heartbeats grouped by user agent in the standard format to be sent in
1167
1005
  // the header.
1168
- var heartbeatsToSend = [];
1006
+ const heartbeatsToSend = [];
1169
1007
  // Single date format heartbeats that are not sent.
1170
- var unsentEntries = heartbeatsCache.slice();
1171
- var _loop_1 = function (singleDateHeartbeat) {
1008
+ let unsentEntries = heartbeatsCache.slice();
1009
+ for (const singleDateHeartbeat of heartbeatsCache) {
1172
1010
  // Look for an existing entry with the same user agent.
1173
- var heartbeatEntry = heartbeatsToSend.find(function (hb) { return hb.agent === singleDateHeartbeat.agent; });
1011
+ const heartbeatEntry = heartbeatsToSend.find(hb => hb.agent === singleDateHeartbeat.agent);
1174
1012
  if (!heartbeatEntry) {
1175
1013
  // If no entry for this user agent exists, create one.
1176
1014
  heartbeatsToSend.push({
@@ -1181,7 +1019,7 @@ function extractHeartbeatsForHeader(heartbeatsCache, maxSize) {
1181
1019
  // If the header would exceed max size, remove the added heartbeat
1182
1020
  // entry and stop adding to the header.
1183
1021
  heartbeatsToSend.pop();
1184
- return "break";
1022
+ break;
1185
1023
  }
1186
1024
  }
1187
1025
  else {
@@ -1190,127 +1028,85 @@ function extractHeartbeatsForHeader(heartbeatsCache, maxSize) {
1190
1028
  // and stop adding to the header.
1191
1029
  if (countBytes(heartbeatsToSend) > maxSize) {
1192
1030
  heartbeatEntry.dates.pop();
1193
- return "break";
1031
+ break;
1194
1032
  }
1195
1033
  }
1196
1034
  // Pop unsent entry from queue. (Skipped if adding the entry exceeded
1197
1035
  // quota and the loop breaks early.)
1198
1036
  unsentEntries = unsentEntries.slice(1);
1199
- };
1200
- try {
1201
- for (var heartbeatsCache_1 = tslib.__values(heartbeatsCache), heartbeatsCache_1_1 = heartbeatsCache_1.next(); !heartbeatsCache_1_1.done; heartbeatsCache_1_1 = heartbeatsCache_1.next()) {
1202
- var singleDateHeartbeat = heartbeatsCache_1_1.value;
1203
- var state_1 = _loop_1(singleDateHeartbeat);
1204
- if (state_1 === "break")
1205
- break;
1206
- }
1207
- }
1208
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
1209
- finally {
1210
- try {
1211
- if (heartbeatsCache_1_1 && !heartbeatsCache_1_1.done && (_a = heartbeatsCache_1.return)) _a.call(heartbeatsCache_1);
1212
- }
1213
- finally { if (e_3) throw e_3.error; }
1214
1037
  }
1215
1038
  return {
1216
- heartbeatsToSend: heartbeatsToSend,
1217
- unsentEntries: unsentEntries
1039
+ heartbeatsToSend,
1040
+ unsentEntries
1218
1041
  };
1219
1042
  }
1220
- var HeartbeatStorageImpl = /** @class */ (function () {
1221
- function HeartbeatStorageImpl(app) {
1043
+ class HeartbeatStorageImpl {
1044
+ constructor(app) {
1222
1045
  this.app = app;
1223
1046
  this._canUseIndexedDBPromise = this.runIndexedDBEnvironmentCheck();
1224
1047
  }
1225
- HeartbeatStorageImpl.prototype.runIndexedDBEnvironmentCheck = function () {
1226
- return tslib.__awaiter(this, void 0, void 0, function () {
1227
- return tslib.__generator(this, function (_a) {
1228
- if (!util.isIndexedDBAvailable()) {
1229
- return [2 /*return*/, false];
1230
- }
1231
- else {
1232
- return [2 /*return*/, util.validateIndexedDBOpenable()
1233
- .then(function () { return true; })
1234
- .catch(function () { return false; })];
1235
- }
1236
- });
1237
- });
1238
- };
1048
+ async runIndexedDBEnvironmentCheck() {
1049
+ if (!util.isIndexedDBAvailable()) {
1050
+ return false;
1051
+ }
1052
+ else {
1053
+ return util.validateIndexedDBOpenable()
1054
+ .then(() => true)
1055
+ .catch(() => false);
1056
+ }
1057
+ }
1239
1058
  /**
1240
1059
  * Read all heartbeats.
1241
1060
  */
1242
- HeartbeatStorageImpl.prototype.read = function () {
1243
- return tslib.__awaiter(this, void 0, void 0, function () {
1244
- var canUseIndexedDB, idbHeartbeatObject;
1245
- return tslib.__generator(this, function (_a) {
1246
- switch (_a.label) {
1247
- case 0: return [4 /*yield*/, this._canUseIndexedDBPromise];
1248
- case 1:
1249
- canUseIndexedDB = _a.sent();
1250
- if (!!canUseIndexedDB) return [3 /*break*/, 2];
1251
- return [2 /*return*/, { heartbeats: [] }];
1252
- case 2: return [4 /*yield*/, readHeartbeatsFromIndexedDB(this.app)];
1253
- case 3:
1254
- idbHeartbeatObject = _a.sent();
1255
- if (idbHeartbeatObject === null || idbHeartbeatObject === void 0 ? void 0 : idbHeartbeatObject.heartbeats) {
1256
- return [2 /*return*/, idbHeartbeatObject];
1257
- }
1258
- else {
1259
- return [2 /*return*/, { heartbeats: [] }];
1260
- }
1261
- case 4: return [2 /*return*/];
1262
- }
1263
- });
1264
- });
1265
- };
1061
+ async read() {
1062
+ const canUseIndexedDB = await this._canUseIndexedDBPromise;
1063
+ if (!canUseIndexedDB) {
1064
+ return { heartbeats: [] };
1065
+ }
1066
+ else {
1067
+ const idbHeartbeatObject = await readHeartbeatsFromIndexedDB(this.app);
1068
+ if (idbHeartbeatObject === null || idbHeartbeatObject === void 0 ? void 0 : idbHeartbeatObject.heartbeats) {
1069
+ return idbHeartbeatObject;
1070
+ }
1071
+ else {
1072
+ return { heartbeats: [] };
1073
+ }
1074
+ }
1075
+ }
1266
1076
  // overwrite the storage with the provided heartbeats
1267
- HeartbeatStorageImpl.prototype.overwrite = function (heartbeatsObject) {
1077
+ async overwrite(heartbeatsObject) {
1268
1078
  var _a;
1269
- return tslib.__awaiter(this, void 0, void 0, function () {
1270
- var canUseIndexedDB, existingHeartbeatsObject;
1271
- return tslib.__generator(this, function (_b) {
1272
- switch (_b.label) {
1273
- case 0: return [4 /*yield*/, this._canUseIndexedDBPromise];
1274
- case 1:
1275
- canUseIndexedDB = _b.sent();
1276
- if (!!canUseIndexedDB) return [3 /*break*/, 2];
1277
- return [2 /*return*/];
1278
- case 2: return [4 /*yield*/, this.read()];
1279
- case 3:
1280
- existingHeartbeatsObject = _b.sent();
1281
- return [2 /*return*/, writeHeartbeatsToIndexedDB(this.app, {
1282
- lastSentHeartbeatDate: (_a = heartbeatsObject.lastSentHeartbeatDate) !== null && _a !== void 0 ? _a : existingHeartbeatsObject.lastSentHeartbeatDate,
1283
- heartbeats: heartbeatsObject.heartbeats
1284
- })];
1285
- }
1079
+ const canUseIndexedDB = await this._canUseIndexedDBPromise;
1080
+ if (!canUseIndexedDB) {
1081
+ return;
1082
+ }
1083
+ else {
1084
+ const existingHeartbeatsObject = await this.read();
1085
+ return writeHeartbeatsToIndexedDB(this.app, {
1086
+ lastSentHeartbeatDate: (_a = heartbeatsObject.lastSentHeartbeatDate) !== null && _a !== void 0 ? _a : existingHeartbeatsObject.lastSentHeartbeatDate,
1087
+ heartbeats: heartbeatsObject.heartbeats
1286
1088
  });
1287
- });
1288
- };
1089
+ }
1090
+ }
1289
1091
  // add heartbeats
1290
- HeartbeatStorageImpl.prototype.add = function (heartbeatsObject) {
1092
+ async add(heartbeatsObject) {
1291
1093
  var _a;
1292
- return tslib.__awaiter(this, void 0, void 0, function () {
1293
- var canUseIndexedDB, existingHeartbeatsObject;
1294
- return tslib.__generator(this, function (_b) {
1295
- switch (_b.label) {
1296
- case 0: return [4 /*yield*/, this._canUseIndexedDBPromise];
1297
- case 1:
1298
- canUseIndexedDB = _b.sent();
1299
- if (!!canUseIndexedDB) return [3 /*break*/, 2];
1300
- return [2 /*return*/];
1301
- case 2: return [4 /*yield*/, this.read()];
1302
- case 3:
1303
- existingHeartbeatsObject = _b.sent();
1304
- return [2 /*return*/, writeHeartbeatsToIndexedDB(this.app, {
1305
- lastSentHeartbeatDate: (_a = heartbeatsObject.lastSentHeartbeatDate) !== null && _a !== void 0 ? _a : existingHeartbeatsObject.lastSentHeartbeatDate,
1306
- heartbeats: tslib.__spreadArray(tslib.__spreadArray([], tslib.__read(existingHeartbeatsObject.heartbeats), false), tslib.__read(heartbeatsObject.heartbeats), false)
1307
- })];
1308
- }
1094
+ const canUseIndexedDB = await this._canUseIndexedDBPromise;
1095
+ if (!canUseIndexedDB) {
1096
+ return;
1097
+ }
1098
+ else {
1099
+ const existingHeartbeatsObject = await this.read();
1100
+ return writeHeartbeatsToIndexedDB(this.app, {
1101
+ lastSentHeartbeatDate: (_a = heartbeatsObject.lastSentHeartbeatDate) !== null && _a !== void 0 ? _a : existingHeartbeatsObject.lastSentHeartbeatDate,
1102
+ heartbeats: [
1103
+ ...existingHeartbeatsObject.heartbeats,
1104
+ ...heartbeatsObject.heartbeats
1105
+ ]
1309
1106
  });
1310
- });
1311
- };
1312
- return HeartbeatStorageImpl;
1313
- }());
1107
+ }
1108
+ }
1109
+ }
1314
1110
  /**
1315
1111
  * Calculate bytes of a HeartbeatsByUserAgent array after being wrapped
1316
1112
  * in a platform logging header JSON object, stringified, and converted
@@ -1340,12 +1136,12 @@ function countBytes(heartbeatsCache) {
1340
1136
  * limitations under the License.
1341
1137
  */
1342
1138
  function registerCoreComponents(variant) {
1343
- _registerComponent(new component.Component('platform-logger', function (container) { return new PlatformLoggerServiceImpl(container); }, "PRIVATE" /* ComponentType.PRIVATE */));
1344
- _registerComponent(new component.Component('heartbeat', function (container) { return new HeartbeatServiceImpl(container); }, "PRIVATE" /* ComponentType.PRIVATE */));
1139
+ _registerComponent(new component.Component('platform-logger', container => new PlatformLoggerServiceImpl(container), "PRIVATE" /* ComponentType.PRIVATE */));
1140
+ _registerComponent(new component.Component('heartbeat', container => new HeartbeatServiceImpl(container), "PRIVATE" /* ComponentType.PRIVATE */));
1345
1141
  // Register `app` package.
1346
1142
  registerVersion(name$q, version$1, variant);
1347
- // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation
1348
- registerVersion(name$q, version$1, 'cjs5');
1143
+ // BUILD_TARGET will be replaced by values like esm2017, cjs2017, etc during the compilation
1144
+ registerVersion(name$q, version$1, 'cjs2017');
1349
1145
  // Register platform SDK identifier (no version).
1350
1146
  registerVersion('fire-js', '');
1351
1147
  }