@firebase/database 1.0.10 → 1.0.11-canary.01f36ea41

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,10 +1,10 @@
1
- import { _getProvider, getApp, SDK_VERSION as SDK_VERSION$1, _registerComponent, registerVersion } from '@firebase/app';
1
+ import { _isFirebaseServerApp, _getProvider, getApp, SDK_VERSION as SDK_VERSION$1, _registerComponent, registerVersion } from '@firebase/app';
2
2
  import { Component, ComponentContainer, Provider } from '@firebase/component';
3
3
  import { stringify, jsonEval, contains, assert, isNodeSdk, stringToByteArray, Sha1, base64, deepCopy, base64Encode, isMobileCordova, stringLength, Deferred, safeGet, isAdmin, isValidFormat, isEmpty, isReactNative, assertionError, map, querystring, errorPrefix, getModularInstance, getDefaultEmulatorHostnameAndPort, createMockUserToken } from '@firebase/util';
4
4
  import { Logger, LogLevel } from '@firebase/logger';
5
5
 
6
6
  const name = "@firebase/database";
7
- const version = "1.0.10";
7
+ const version = "1.0.11-canary.01f36ea41";
8
8
 
9
9
  /**
10
10
  * @license
@@ -711,15 +711,24 @@ const setTimeoutNonBlocking = function (fn, time) {
711
711
  * Abstraction around AppCheck's token fetching capabilities.
712
712
  */
713
713
  class AppCheckTokenProvider {
714
- constructor(appName_, appCheckProvider) {
715
- this.appName_ = appName_;
714
+ constructor(app, appCheckProvider) {
716
715
  this.appCheckProvider = appCheckProvider;
716
+ this.appName = app.name;
717
+ if (_isFirebaseServerApp(app) && app.settings.appCheckToken) {
718
+ this.serverAppAppCheckToken = app.settings.appCheckToken;
719
+ }
717
720
  this.appCheck = appCheckProvider === null || appCheckProvider === void 0 ? void 0 : appCheckProvider.getImmediate({ optional: true });
718
721
  if (!this.appCheck) {
719
722
  appCheckProvider === null || appCheckProvider === void 0 ? void 0 : appCheckProvider.get().then(appCheck => (this.appCheck = appCheck));
720
723
  }
721
724
  }
722
725
  getToken(forceRefresh) {
726
+ if (this.serverAppAppCheckToken) {
727
+ if (forceRefresh) {
728
+ throw new Error('Attempted reuse of `FirebaseServerApp.appCheckToken` after previous usage failed.');
729
+ }
730
+ return Promise.resolve({ token: this.serverAppAppCheckToken });
731
+ }
723
732
  if (!this.appCheck) {
724
733
  return new Promise((resolve, reject) => {
725
734
  // Support delayed initialization of FirebaseAppCheck. This allows our
@@ -743,7 +752,7 @@ class AppCheckTokenProvider {
743
752
  (_a = this.appCheckProvider) === null || _a === void 0 ? void 0 : _a.get().then(appCheck => appCheck.addTokenListener(listener));
744
753
  }
745
754
  notifyForInvalidToken() {
746
- warn(`Provided AppCheck credentials for the app named "${this.appName_}" ` +
755
+ warn(`Provided AppCheck credentials for the app named "${this.appName}" ` +
747
756
  'are invalid. This usually indicates your app was not initialized correctly.');
748
757
  }
749
758
  }
@@ -3732,7 +3741,7 @@ class PersistentConnection extends ServerActions {
3732
3741
  }
3733
3742
  this.lastConnectionEstablishedTime_ = null;
3734
3743
  }
3735
- const timeSinceLastConnectAttempt = new Date().getTime() - this.lastConnectionAttemptTime_;
3744
+ const timeSinceLastConnectAttempt = Math.max(0, new Date().getTime() - this.lastConnectionAttemptTime_);
3736
3745
  let reconnectDelay = Math.max(0, this.reconnectDelay_ - timeSinceLastConnectAttempt);
3737
3746
  reconnectDelay = Math.random() * reconnectDelay;
3738
3747
  this.log_('Trying to reconnect in ' + reconnectDelay + 'ms');
@@ -13523,7 +13532,7 @@ function repoManagerDatabaseFromApp(app, authProvider, appCheckProvider, url, no
13523
13532
  fatal('Database URL must point to the root of a Firebase Database ' +
13524
13533
  '(not including a child path).');
13525
13534
  }
13526
- const repo = repoManagerCreateRepo(repoInfo, app, authTokenProvider, new AppCheckTokenProvider(app.name, appCheckProvider));
13535
+ const repo = repoManagerCreateRepo(repoInfo, app, authTokenProvider, new AppCheckTokenProvider(app, appCheckProvider));
13527
13536
  return new Database(repo, app);
13528
13537
  }
13529
13538
  /**