@firebase/firestore 3.3.0 → 3.3.1-canary.086df7c7e

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 (93) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/firestore/src/api/credentials.d.ts +64 -30
  3. package/dist/firestore/src/api/database.d.ts +2 -1
  4. package/dist/firestore/src/api.d.ts +2 -1
  5. package/dist/firestore/src/core/component_provider.d.ts +2 -1
  6. package/dist/firestore/src/core/firestore_client.d.ts +4 -3
  7. package/dist/firestore/src/lite-api/components.d.ts +3 -1
  8. package/dist/firestore/src/lite-api/database.d.ts +4 -2
  9. package/dist/firestore/src/platform/browser/webchannel_connection.d.ts +1 -1
  10. package/dist/firestore/src/platform/node/grpc_connection.d.ts +3 -3
  11. package/dist/firestore/src/remote/connection.d.ts +3 -3
  12. package/dist/firestore/src/remote/datastore.d.ts +2 -1
  13. package/dist/firestore/src/remote/persistent_stream.d.ts +9 -7
  14. package/dist/firestore/src/remote/rest_connection.d.ts +4 -4
  15. package/dist/firestore/test/integration/remote/stream.test.d.ts +2 -2
  16. package/dist/firestore/test/integration/util/internal_helpers.d.ts +5 -5
  17. package/dist/firestore/test/unit/remote/rest_connection.test.d.ts +1 -1
  18. package/dist/index.d.ts +2 -1
  19. package/dist/index.esm2017.js +3401 -3347
  20. package/dist/index.esm2017.js.map +1 -1
  21. package/dist/index.esm5.js +3676 -3627
  22. package/dist/index.esm5.js.map +1 -1
  23. package/dist/index.node.cjs.js +194 -101
  24. package/dist/index.node.cjs.js.map +1 -1
  25. package/dist/index.node.mjs +191 -99
  26. package/dist/index.node.mjs.map +1 -1
  27. package/dist/index.rn.js +3394 -3340
  28. package/dist/index.rn.js.map +1 -1
  29. package/dist/internal.d.ts +34 -20
  30. package/dist/lite/firestore/src/api/credentials.d.ts +64 -30
  31. package/dist/lite/firestore/src/api/database.d.ts +2 -1
  32. package/dist/lite/firestore/src/api.d.ts +2 -1
  33. package/dist/lite/firestore/src/core/component_provider.d.ts +2 -1
  34. package/dist/lite/firestore/src/core/firestore_client.d.ts +4 -3
  35. package/dist/lite/firestore/src/lite-api/components.d.ts +3 -1
  36. package/dist/lite/firestore/src/lite-api/database.d.ts +4 -2
  37. package/dist/lite/firestore/src/platform/browser/webchannel_connection.d.ts +1 -1
  38. package/dist/lite/firestore/src/platform/node/grpc_connection.d.ts +3 -3
  39. package/dist/lite/firestore/src/remote/connection.d.ts +3 -3
  40. package/dist/lite/firestore/src/remote/datastore.d.ts +2 -1
  41. package/dist/lite/firestore/src/remote/persistent_stream.d.ts +9 -7
  42. package/dist/lite/firestore/src/remote/rest_connection.d.ts +4 -4
  43. package/dist/lite/firestore/test/integration/remote/stream.test.d.ts +2 -2
  44. package/dist/lite/firestore/test/integration/util/internal_helpers.d.ts +5 -5
  45. package/dist/lite/firestore/test/unit/remote/rest_connection.test.d.ts +1 -1
  46. package/dist/lite/index.browser.esm2017.js +1378 -1364
  47. package/dist/lite/index.browser.esm2017.js.map +1 -1
  48. package/dist/lite/index.browser.esm5.js +933 -924
  49. package/dist/lite/index.browser.esm5.js.map +1 -1
  50. package/dist/lite/index.node.cjs.js +95 -60
  51. package/dist/lite/index.node.cjs.js.map +1 -1
  52. package/dist/lite/index.node.mjs +95 -60
  53. package/dist/lite/index.node.mjs.map +1 -1
  54. package/dist/lite/index.rn.esm2017.js +924 -910
  55. package/dist/lite/index.rn.esm2017.js.map +1 -1
  56. package/dist/lite/internal.d.ts +14 -13
  57. package/dist/lite/packages/firestore/dist/lite/index.browser.esm2017.d.ts +150 -149
  58. package/dist/lite/packages/firestore/src/api/credentials.d.ts +64 -30
  59. package/dist/lite/packages/firestore/src/api/database.d.ts +2 -1
  60. package/dist/lite/packages/firestore/src/api.d.ts +2 -1
  61. package/dist/lite/packages/firestore/src/core/component_provider.d.ts +2 -1
  62. package/dist/lite/packages/firestore/src/core/firestore_client.d.ts +4 -3
  63. package/dist/lite/packages/firestore/src/lite-api/components.d.ts +3 -1
  64. package/dist/lite/packages/firestore/src/lite-api/database.d.ts +4 -2
  65. package/dist/lite/packages/firestore/src/platform/browser/webchannel_connection.d.ts +1 -1
  66. package/dist/lite/packages/firestore/src/platform/node/grpc_connection.d.ts +3 -3
  67. package/dist/lite/packages/firestore/src/remote/connection.d.ts +3 -3
  68. package/dist/lite/packages/firestore/src/remote/datastore.d.ts +2 -1
  69. package/dist/lite/packages/firestore/src/remote/persistent_stream.d.ts +9 -7
  70. package/dist/lite/packages/firestore/src/remote/rest_connection.d.ts +4 -4
  71. package/dist/lite/packages/firestore/test/integration/remote/stream.test.d.ts +2 -2
  72. package/dist/lite/packages/firestore/test/integration/util/internal_helpers.d.ts +5 -5
  73. package/dist/lite/packages/firestore/test/unit/remote/rest_connection.test.d.ts +1 -1
  74. package/dist/lite/private.d.ts +14 -13
  75. package/dist/packages/firestore/dist/index.esm2017.d.ts +211 -195
  76. package/dist/packages/firestore/src/api/credentials.d.ts +64 -30
  77. package/dist/packages/firestore/src/api/database.d.ts +2 -1
  78. package/dist/packages/firestore/src/api.d.ts +2 -1
  79. package/dist/packages/firestore/src/core/component_provider.d.ts +2 -1
  80. package/dist/packages/firestore/src/core/firestore_client.d.ts +4 -3
  81. package/dist/packages/firestore/src/lite-api/components.d.ts +3 -1
  82. package/dist/packages/firestore/src/lite-api/database.d.ts +4 -2
  83. package/dist/packages/firestore/src/platform/browser/webchannel_connection.d.ts +1 -1
  84. package/dist/packages/firestore/src/platform/node/grpc_connection.d.ts +3 -3
  85. package/dist/packages/firestore/src/remote/connection.d.ts +3 -3
  86. package/dist/packages/firestore/src/remote/datastore.d.ts +2 -1
  87. package/dist/packages/firestore/src/remote/persistent_stream.d.ts +9 -7
  88. package/dist/packages/firestore/src/remote/rest_connection.d.ts +4 -4
  89. package/dist/packages/firestore/test/integration/remote/stream.test.d.ts +2 -2
  90. package/dist/packages/firestore/test/integration/util/internal_helpers.d.ts +5 -5
  91. package/dist/packages/firestore/test/unit/remote/rest_connection.test.d.ts +1 -1
  92. package/dist/private.d.ts +24 -19
  93. package/package.json +9 -9
@@ -11,7 +11,7 @@ import { fileURLToPath } from 'url';
11
11
  import { loadSync } from '@grpc/proto-loader';
12
12
 
13
13
  const name = "@firebase/firestore";
14
- const version$1 = "3.3.0";
14
+ const version$1 = "3.3.1-canary.086df7c7e";
15
15
 
16
16
  /**
17
17
  * @license
@@ -64,7 +64,7 @@ User.GOOGLE_CREDENTIALS = new User('google-credentials-uid');
64
64
  User.FIRST_PARTY = new User('first-party-uid');
65
65
  User.MOCK_USER = new User('mock-user');
66
66
 
67
- const version = "9.4.0";
67
+ const version = "9.5.0-canary.086df7c7e";
68
68
 
69
69
  /**
70
70
  * @license
@@ -452,16 +452,15 @@ class OAuthToken {
452
452
  constructor(value, user) {
453
453
  this.user = user;
454
454
  this.type = 'OAuth';
455
- this.authHeaders = {};
456
- // Set the headers using Object Literal notation to avoid minification
457
- this.authHeaders['Authorization'] = `Bearer ${value}`;
455
+ this.headers = new Map();
456
+ this.headers.set('Authorization', `Bearer ${value}`);
458
457
  }
459
458
  }
460
459
  /**
461
460
  * A CredentialsProvider that always yields an empty token.
462
461
  * @internal
463
462
  */
464
- class EmptyCredentialsProvider {
463
+ class EmptyAuthCredentialsProvider {
465
464
  getToken() {
466
465
  return Promise.resolve(null);
467
466
  }
@@ -476,7 +475,7 @@ class EmptyCredentialsProvider {
476
475
  * A CredentialsProvider that always returns a constant token. Used for
477
476
  * emulator token mocking.
478
477
  */
479
- class EmulatorCredentialsProvider {
478
+ class EmulatorAuthCredentialsProvider {
480
479
  constructor(token) {
481
480
  this.token = token;
482
481
  /**
@@ -499,7 +498,7 @@ class EmulatorCredentialsProvider {
499
498
  this.changeListener = null;
500
499
  }
501
500
  }
502
- class FirebaseCredentialsProvider {
501
+ class FirebaseAuthCredentialsProvider {
503
502
  constructor(authProvider) {
504
503
  this.authProvider = authProvider;
505
504
  /** Tracks the current User. */
@@ -542,7 +541,7 @@ class FirebaseCredentialsProvider {
542
541
  });
543
542
  };
544
543
  const registerAuth = (auth) => {
545
- logDebug('FirebaseCredentialsProvider', 'Auth detected');
544
+ logDebug('FirebaseAuthCredentialsProvider', 'Auth detected');
546
545
  this.auth = auth;
547
546
  this.auth.addAuthTokenListener(this.tokenListener);
548
547
  awaitNextToken();
@@ -559,7 +558,7 @@ class FirebaseCredentialsProvider {
559
558
  }
560
559
  else {
561
560
  // If auth is still not available, proceed with `null` user
562
- logDebug('FirebaseCredentialsProvider', 'Auth not yet detected');
561
+ logDebug('FirebaseAuthCredentialsProvider', 'Auth not yet detected');
563
562
  nextToken.resolve();
564
563
  nextToken = new Deferred();
565
564
  }
@@ -582,7 +581,7 @@ class FirebaseCredentialsProvider {
582
581
  // outstanding so the response is potentially for a previous user (which
583
582
  // user, we can't be sure).
584
583
  if (this.tokenCounter !== initialTokenCounter) {
585
- logDebug('FirebaseCredentialsProvider', 'getToken aborted due to token change.');
584
+ logDebug('FirebaseAuthCredentialsProvider', 'getToken aborted due to token change.');
586
585
  return this.getToken();
587
586
  }
588
587
  else {
@@ -623,25 +622,17 @@ class FirebaseCredentialsProvider {
623
622
  */
624
623
  class FirstPartyToken {
625
624
  constructor(gapi, sessionIndex, iamToken) {
626
- this.gapi = gapi;
627
- this.sessionIndex = sessionIndex;
628
- this.iamToken = iamToken;
629
625
  this.type = 'FirstParty';
630
626
  this.user = User.FIRST_PARTY;
631
- }
632
- get authHeaders() {
633
- const headers = {
634
- 'X-Goog-AuthUser': this.sessionIndex
635
- };
636
- // Use array notation to prevent minification
637
- const authHeader = this.gapi['auth']['getAuthHeaderValueForFirstParty']([]);
627
+ this.headers = new Map();
628
+ this.headers.set('X-Goog-AuthUser', sessionIndex);
629
+ const authHeader = gapi['auth']['getAuthHeaderValueForFirstParty']([]);
638
630
  if (authHeader) {
639
- headers['Authorization'] = authHeader;
631
+ this.headers.set('Authorization', authHeader);
640
632
  }
641
- if (this.iamToken) {
642
- headers['X-Goog-Iam-Authorization-Token'] = this.iamToken;
633
+ if (iamToken) {
634
+ this.headers.set('X-Goog-Iam-Authorization-Token', iamToken);
643
635
  }
644
- return headers;
645
636
  }
646
637
  }
647
638
  /*
@@ -649,7 +640,7 @@ class FirstPartyToken {
649
640
  * to authenticate the user, using technique that is only available
650
641
  * to applications hosted by Google.
651
642
  */
652
- class FirstPartyCredentialsProvider {
643
+ class FirstPartyAuthCredentialsProvider {
653
644
  constructor(gapi, sessionIndex, iamToken) {
654
645
  this.gapi = gapi;
655
646
  this.sessionIndex = sessionIndex;
@@ -665,13 +656,97 @@ class FirstPartyCredentialsProvider {
665
656
  shutdown() { }
666
657
  invalidateToken() { }
667
658
  }
659
+ class AppCheckToken {
660
+ constructor(value) {
661
+ this.value = value;
662
+ this.type = 'AppCheck';
663
+ this.headers = new Map();
664
+ if (value && value.length > 0) {
665
+ this.headers.set('x-firebase-appcheck', this.value);
666
+ }
667
+ }
668
+ }
669
+ class FirebaseAppCheckTokenProvider {
670
+ constructor(appCheckProvider) {
671
+ this.appCheckProvider = appCheckProvider;
672
+ this.forceRefresh = false;
673
+ this.appCheck = null;
674
+ }
675
+ start(asyncQueue, changeListener) {
676
+ const onTokenChanged = tokenResult => {
677
+ if (tokenResult.error != null) {
678
+ logDebug('FirebaseAppCheckTokenProvider', `Error getting App Check token; using placeholder token instead. Error: ${tokenResult.error.message}`);
679
+ }
680
+ return changeListener(tokenResult.token);
681
+ };
682
+ this.tokenListener = (tokenResult) => {
683
+ asyncQueue.enqueueRetryable(() => onTokenChanged(tokenResult));
684
+ };
685
+ const registerAppCheck = (appCheck) => {
686
+ logDebug('FirebaseAppCheckTokenProvider', 'AppCheck detected');
687
+ this.appCheck = appCheck;
688
+ this.appCheck.addTokenListener(this.tokenListener);
689
+ };
690
+ this.appCheckProvider.onInit(appCheck => registerAppCheck(appCheck));
691
+ // Our users can initialize AppCheck after Firestore, so we give it
692
+ // a chance to register itself with the component framework.
693
+ setTimeout(() => {
694
+ if (!this.appCheck) {
695
+ const appCheck = this.appCheckProvider.getImmediate({ optional: true });
696
+ if (appCheck) {
697
+ registerAppCheck(appCheck);
698
+ }
699
+ else {
700
+ // If AppCheck is still not available, proceed without it.
701
+ logDebug('FirebaseAppCheckTokenProvider', 'AppCheck not yet detected');
702
+ }
703
+ }
704
+ }, 0);
705
+ }
706
+ getToken() {
707
+ const forceRefresh = this.forceRefresh;
708
+ this.forceRefresh = false;
709
+ if (!this.appCheck) {
710
+ return Promise.resolve(null);
711
+ }
712
+ return this.appCheck.getToken(forceRefresh).then(tokenResult => {
713
+ if (tokenResult) {
714
+ hardAssert(typeof tokenResult.token === 'string');
715
+ return new AppCheckToken(tokenResult.token);
716
+ }
717
+ else {
718
+ return null;
719
+ }
720
+ });
721
+ }
722
+ invalidateToken() {
723
+ this.forceRefresh = true;
724
+ }
725
+ shutdown() {
726
+ if (this.appCheck) {
727
+ this.appCheck.removeTokenListener(this.tokenListener);
728
+ }
729
+ }
730
+ }
731
+ /**
732
+ * An AppCheck token provider that always yields an empty token.
733
+ * @internal
734
+ */
735
+ class EmptyAppCheckTokenProvider {
736
+ getToken() {
737
+ return Promise.resolve(new AppCheckToken(''));
738
+ }
739
+ invalidateToken() { }
740
+ start(asyncQueue, changeListener) { }
741
+ shutdown() { }
742
+ }
668
743
  /**
669
744
  * Builds a CredentialsProvider depending on the type of
670
745
  * the credentials passed in.
671
746
  */
672
- function makeCredentialsProvider(credentials) {
747
+ function makeAuthCredentialsProvider(credentials) {
673
748
  if (!credentials) {
674
- return new EmptyCredentialsProvider();
749
+ return new EmptyAuthCredentialsProvider();
675
750
  }
676
751
  switch (credentials['type']) {
677
752
  case 'gapi':
@@ -681,11 +756,11 @@ function makeCredentialsProvider(credentials) {
681
756
  client !== null &&
682
757
  client['auth'] &&
683
758
  client['auth']['getAuthHeaderValueForFirstParty']));
684
- return new FirstPartyCredentialsProvider(client, credentials['sessionIndex'] || '0', credentials['iamToken'] || null);
759
+ return new FirstPartyAuthCredentialsProvider(client, credentials['sessionIndex'] || '0', credentials['iamToken'] || null);
685
760
  case 'provider':
686
761
  return credentials['client'];
687
762
  default:
688
- throw new FirestoreError(Code.INVALID_ARGUMENT, 'makeCredentialsProvider failed due to invalid credential type');
763
+ throw new FirestoreError(Code.INVALID_ARGUMENT, 'makeAuthCredentialsProvider failed due to invalid credential type');
689
764
  }
690
765
  }
691
766
 
@@ -11268,10 +11343,10 @@ class IndexedDbPersistence {
11268
11343
  // accesses internal state. We execute this code directly during shutdown
11269
11344
  // to make sure it gets a chance to run.
11270
11345
  this.markClientZombied();
11271
- if (isSafari() && navigator.appVersion.match(`Version/14`)) {
11272
- // On Safari 14, we do not run any cleanup actions as it might trigger
11273
- // a bug that prevents Safari from re-opening IndexedDB during the
11274
- // next page load.
11346
+ if (isSafari() && navigator.appVersion.match(/Version\/1[45]/)) {
11347
+ // On Safari 14 and 15, we do not run any cleanup actions as it might
11348
+ // trigger a bug that prevents Safari from re-opening IndexedDB during
11349
+ // the next page load.
11275
11350
  // See https://bugs.webkit.org/show_bug.cgi?id=226547
11276
11351
  this.queue.enterRestrictedMode(/* purgeExistingTasks= */ true);
11277
11352
  }
@@ -14244,15 +14319,14 @@ const require = module.createRequire(import.meta.url);
14244
14319
  const { version: grpcVersion } = require('@grpc/grpc-js/package.json');
14245
14320
  const LOG_TAG$9 = 'Connection';
14246
14321
  const X_GOOG_API_CLIENT_VALUE = `gl-node/${process.versions.node} fire/${SDK_VERSION} grpc/${grpcVersion}`;
14247
- function createMetadata(databasePath, token, appId) {
14248
- hardAssert(token === null || token.type === 'OAuth');
14322
+ function createMetadata(databasePath, authToken, appCheckToken, appId) {
14323
+ hardAssert(authToken === null || authToken.type === 'OAuth');
14249
14324
  const metadata = new Metadata();
14250
- if (token) {
14251
- for (const header in token.authHeaders) {
14252
- if (token.authHeaders.hasOwnProperty(header)) {
14253
- metadata.set(header, token.authHeaders[header]);
14254
- }
14255
- }
14325
+ if (authToken) {
14326
+ authToken.headers.forEach((value, key) => metadata.set(key, value));
14327
+ }
14328
+ if (appCheckToken) {
14329
+ appCheckToken.headers.forEach((value, key) => metadata.set(key, value));
14256
14330
  }
14257
14331
  if (appId) {
14258
14332
  metadata.set('X-Firebase-GMPID', appId);
@@ -14285,9 +14359,9 @@ class GrpcConnection {
14285
14359
  }
14286
14360
  return this.cachedStub;
14287
14361
  }
14288
- invokeRPC(rpcName, path, request, token) {
14362
+ invokeRPC(rpcName, path, request, authToken, appCheckToken) {
14289
14363
  const stub = this.ensureActiveStub();
14290
- const metadata = createMetadata(this.databasePath, token, this.databaseInfo.appId);
14364
+ const metadata = createMetadata(this.databasePath, authToken, appCheckToken, this.databaseInfo.appId);
14291
14365
  const jsonRequest = Object.assign({ database: this.databasePath }, request);
14292
14366
  return nodePromise((callback) => {
14293
14367
  logDebug(LOG_TAG$9, `RPC '${rpcName}' invoked with request:`, request);
@@ -14303,12 +14377,12 @@ class GrpcConnection {
14303
14377
  });
14304
14378
  });
14305
14379
  }
14306
- invokeStreamingRPC(rpcName, path, request, token) {
14380
+ invokeStreamingRPC(rpcName, path, request, authToken, appCheckToken) {
14307
14381
  const results = [];
14308
14382
  const responseDeferred = new Deferred();
14309
14383
  logDebug(LOG_TAG$9, `RPC '${rpcName}' invoked (streaming) with request:`, request);
14310
14384
  const stub = this.ensureActiveStub();
14311
- const metadata = createMetadata(this.databasePath, token, this.databaseInfo.appId);
14385
+ const metadata = createMetadata(this.databasePath, authToken, appCheckToken, this.databaseInfo.appId);
14312
14386
  const jsonRequest = Object.assign(Object.assign({}, request), { database: this.databasePath });
14313
14387
  const stream = stub[rpcName](jsonRequest, metadata);
14314
14388
  stream.on('data', (response) => {
@@ -14327,9 +14401,9 @@ class GrpcConnection {
14327
14401
  return responseDeferred.promise;
14328
14402
  }
14329
14403
  // TODO(mikelehen): This "method" is a monster. Should be refactored.
14330
- openStream(rpcName, token) {
14404
+ openStream(rpcName, authToken, appCheckToken) {
14331
14405
  const stub = this.ensureActiveStub();
14332
- const metadata = createMetadata(this.databasePath, token, this.databaseInfo.appId);
14406
+ const metadata = createMetadata(this.databasePath, authToken, appCheckToken, this.databaseInfo.appId);
14333
14407
  const grpcStream = stub[rpcName](metadata);
14334
14408
  let closed = false;
14335
14409
  const close = (err) => {
@@ -14713,12 +14787,13 @@ const HEALTHY_TIMEOUT_MS = 10 * 1000;
14713
14787
  * ListenerType: The type of the listener that will be used for callbacks
14714
14788
  */
14715
14789
  class PersistentStream {
14716
- constructor(queue, connectionTimerId, idleTimerId, healthTimerId, connection, credentialsProvider, listener) {
14790
+ constructor(queue, connectionTimerId, idleTimerId, healthTimerId, connection, authCredentialsProvider, appCheckCredentialsProvider, listener) {
14717
14791
  this.queue = queue;
14718
14792
  this.idleTimerId = idleTimerId;
14719
14793
  this.healthTimerId = healthTimerId;
14720
14794
  this.connection = connection;
14721
- this.credentialsProvider = credentialsProvider;
14795
+ this.authCredentialsProvider = authCredentialsProvider;
14796
+ this.appCheckCredentialsProvider = appCheckCredentialsProvider;
14722
14797
  this.listener = listener;
14723
14798
  this.state = 0 /* Initial */;
14724
14799
  /**
@@ -14873,7 +14948,8 @@ class PersistentStream {
14873
14948
  // fail, however. In this case, we should get a Code.UNAUTHENTICATED error
14874
14949
  // before we received the first message and we need to invalidate the token
14875
14950
  // to ensure that we fetch a new token.
14876
- this.credentialsProvider.invalidateToken();
14951
+ this.authCredentialsProvider.invalidateToken();
14952
+ this.appCheckCredentialsProvider.invalidateToken();
14877
14953
  }
14878
14954
  // Clean up the underlying stream because we are no longer interested in events.
14879
14955
  if (this.stream !== null) {
@@ -14897,7 +14973,10 @@ class PersistentStream {
14897
14973
  const dispatchIfNotClosed = this.getCloseGuardedDispatcher(this.closeCount);
14898
14974
  // TODO(mikelehen): Just use dispatchIfNotClosed, but see TODO below.
14899
14975
  const closeCount = this.closeCount;
14900
- this.credentialsProvider.getToken().then(token => {
14976
+ Promise.all([
14977
+ this.authCredentialsProvider.getToken(),
14978
+ this.appCheckCredentialsProvider.getToken()
14979
+ ]).then(([authToken, appCheckToken]) => {
14901
14980
  // Stream can be stopped while waiting for authentication.
14902
14981
  // TODO(mikelehen): We really should just use dispatchIfNotClosed
14903
14982
  // and let this dispatch onto the queue, but that opened a spec test can
@@ -14906,7 +14985,7 @@ class PersistentStream {
14906
14985
  // Normally we'd have to schedule the callback on the AsyncQueue.
14907
14986
  // However, the following calls are safe to be called outside the
14908
14987
  // AsyncQueue since they don't chain asynchronous calls
14909
- this.startStream(token);
14988
+ this.startStream(authToken, appCheckToken);
14910
14989
  }
14911
14990
  }, (error) => {
14912
14991
  dispatchIfNotClosed(() => {
@@ -14915,9 +14994,9 @@ class PersistentStream {
14915
14994
  });
14916
14995
  });
14917
14996
  }
14918
- startStream(token) {
14997
+ startStream(authToken, appCheckToken) {
14919
14998
  const dispatchIfNotClosed = this.getCloseGuardedDispatcher(this.closeCount);
14920
- this.stream = this.startRpc(token);
14999
+ this.stream = this.startRpc(authToken, appCheckToken);
14921
15000
  this.stream.onOpen(() => {
14922
15001
  dispatchIfNotClosed(() => {
14923
15002
  this.state = 2 /* Open */;
@@ -14986,12 +15065,12 @@ class PersistentStream {
14986
15065
  * sent from the server for ListenResponses.
14987
15066
  */
14988
15067
  class PersistentListenStream extends PersistentStream {
14989
- constructor(queue, connection, credentials, serializer, listener) {
14990
- super(queue, "listen_stream_connection_backoff" /* ListenStreamConnectionBackoff */, "listen_stream_idle" /* ListenStreamIdle */, "health_check_timeout" /* HealthCheckTimeout */, connection, credentials, listener);
15068
+ constructor(queue, connection, authCredentials, appCheckCredentials, serializer, listener) {
15069
+ super(queue, "listen_stream_connection_backoff" /* ListenStreamConnectionBackoff */, "listen_stream_idle" /* ListenStreamIdle */, "health_check_timeout" /* HealthCheckTimeout */, connection, authCredentials, appCheckCredentials, listener);
14991
15070
  this.serializer = serializer;
14992
15071
  }
14993
- startRpc(token) {
14994
- return this.connection.openStream('Listen', token);
15072
+ startRpc(authToken, appCheckToken) {
15073
+ return this.connection.openStream('Listen', authToken, appCheckToken);
14995
15074
  }
14996
15075
  onMessage(watchChangeProto) {
14997
15076
  // A successful response means the stream is healthy
@@ -15045,8 +15124,8 @@ class PersistentListenStream extends PersistentStream {
15045
15124
  * TODO(b/33271235): Use proto types
15046
15125
  */
15047
15126
  class PersistentWriteStream extends PersistentStream {
15048
- constructor(queue, connection, credentials, serializer, listener) {
15049
- super(queue, "write_stream_connection_backoff" /* WriteStreamConnectionBackoff */, "write_stream_idle" /* WriteStreamIdle */, "health_check_timeout" /* HealthCheckTimeout */, connection, credentials, listener);
15127
+ constructor(queue, connection, authCredentials, appCheckCredentials, serializer, listener) {
15128
+ super(queue, "write_stream_connection_backoff" /* WriteStreamConnectionBackoff */, "write_stream_idle" /* WriteStreamIdle */, "health_check_timeout" /* HealthCheckTimeout */, connection, authCredentials, appCheckCredentials, listener);
15050
15129
  this.serializer = serializer;
15051
15130
  this.handshakeComplete_ = false;
15052
15131
  }
@@ -15068,8 +15147,8 @@ class PersistentWriteStream extends PersistentStream {
15068
15147
  this.writeMutations([]);
15069
15148
  }
15070
15149
  }
15071
- startRpc(token) {
15072
- return this.connection.openStream('Write', token);
15150
+ startRpc(authToken, appCheckToken) {
15151
+ return this.connection.openStream('Write', authToken, appCheckToken);
15073
15152
  }
15074
15153
  onMessage(responseProto) {
15075
15154
  // Always capture the last stream token.
@@ -15141,9 +15220,10 @@ class Datastore {
15141
15220
  * consumption.
15142
15221
  */
15143
15222
  class DatastoreImpl extends Datastore {
15144
- constructor(credentials, connection, serializer) {
15223
+ constructor(authCredentials, appCheckCredentials, connection, serializer) {
15145
15224
  super();
15146
- this.credentials = credentials;
15225
+ this.authCredentials = authCredentials;
15226
+ this.appCheckCredentials = appCheckCredentials;
15147
15227
  this.connection = connection;
15148
15228
  this.serializer = serializer;
15149
15229
  this.terminated = false;
@@ -15153,18 +15233,21 @@ class DatastoreImpl extends Datastore {
15153
15233
  throw new FirestoreError(Code.FAILED_PRECONDITION, 'The client has already been terminated.');
15154
15234
  }
15155
15235
  }
15156
- /** Gets an auth token and invokes the provided RPC. */
15236
+ /** Invokes the provided RPC with auth and AppCheck tokens. */
15157
15237
  invokeRPC(rpcName, path, request) {
15158
15238
  this.verifyInitialized();
15159
- return this.credentials
15160
- .getToken()
15161
- .then(token => {
15162
- return this.connection.invokeRPC(rpcName, path, request, token);
15239
+ return Promise.all([
15240
+ this.authCredentials.getToken(),
15241
+ this.appCheckCredentials.getToken()
15242
+ ])
15243
+ .then(([authToken, appCheckToken]) => {
15244
+ return this.connection.invokeRPC(rpcName, path, request, authToken, appCheckToken);
15163
15245
  })
15164
15246
  .catch((error) => {
15165
15247
  if (error.name === 'FirebaseError') {
15166
15248
  if (error.code === Code.UNAUTHENTICATED) {
15167
- this.credentials.invalidateToken();
15249
+ this.authCredentials.invalidateToken();
15250
+ this.appCheckCredentials.invalidateToken();
15168
15251
  }
15169
15252
  throw error;
15170
15253
  }
@@ -15173,18 +15256,21 @@ class DatastoreImpl extends Datastore {
15173
15256
  }
15174
15257
  });
15175
15258
  }
15176
- /** Gets an auth token and invokes the provided RPC with streamed results. */
15259
+ /** Invokes the provided RPC with streamed results with auth and AppCheck tokens. */
15177
15260
  invokeStreamingRPC(rpcName, path, request) {
15178
15261
  this.verifyInitialized();
15179
- return this.credentials
15180
- .getToken()
15181
- .then(token => {
15182
- return this.connection.invokeStreamingRPC(rpcName, path, request, token);
15262
+ return Promise.all([
15263
+ this.authCredentials.getToken(),
15264
+ this.appCheckCredentials.getToken()
15265
+ ])
15266
+ .then(([authToken, appCheckToken]) => {
15267
+ return this.connection.invokeStreamingRPC(rpcName, path, request, authToken, appCheckToken);
15183
15268
  })
15184
15269
  .catch((error) => {
15185
15270
  if (error.name === 'FirebaseError') {
15186
15271
  if (error.code === Code.UNAUTHENTICATED) {
15187
- this.credentials.invalidateToken();
15272
+ this.authCredentials.invalidateToken();
15273
+ this.appCheckCredentials.invalidateToken();
15188
15274
  }
15189
15275
  throw error;
15190
15276
  }
@@ -15199,8 +15285,8 @@ class DatastoreImpl extends Datastore {
15199
15285
  }
15200
15286
  // TODO(firestorexp): Make sure there is only one Datastore instance per
15201
15287
  // firestore-exp client.
15202
- function newDatastore(credentials, connection, serializer) {
15203
- return new DatastoreImpl(credentials, connection, serializer);
15288
+ function newDatastore(authCredentials, appCheckCredentials, connection, serializer) {
15289
+ return new DatastoreImpl(authCredentials, appCheckCredentials, connection, serializer);
15204
15290
  }
15205
15291
  async function invokeCommitRpc(datastore, mutations) {
15206
15292
  const datastoreImpl = debugCast(datastore);
@@ -15233,12 +15319,12 @@ async function invokeBatchGetDocumentsRpc(datastore, keys) {
15233
15319
  function newPersistentWriteStream(datastore, queue, listener) {
15234
15320
  const datastoreImpl = debugCast(datastore);
15235
15321
  datastoreImpl.verifyInitialized();
15236
- return new PersistentWriteStream(queue, datastoreImpl.connection, datastoreImpl.credentials, datastoreImpl.serializer, listener);
15322
+ return new PersistentWriteStream(queue, datastoreImpl.connection, datastoreImpl.authCredentials, datastoreImpl.appCheckCredentials, datastoreImpl.serializer, listener);
15237
15323
  }
15238
15324
  function newPersistentWatchStream(datastore, queue, listener) {
15239
15325
  const datastoreImpl = debugCast(datastore);
15240
15326
  datastoreImpl.verifyInitialized();
15241
- return new PersistentListenStream(queue, datastoreImpl.connection, datastoreImpl.credentials, datastoreImpl.serializer, listener);
15327
+ return new PersistentListenStream(queue, datastoreImpl.connection, datastoreImpl.authCredentials, datastoreImpl.appCheckCredentials, datastoreImpl.serializer, listener);
15242
15328
  }
15243
15329
 
15244
15330
  /**
@@ -18351,7 +18437,7 @@ class OnlineComponentProvider {
18351
18437
  createDatastore(cfg) {
18352
18438
  const serializer = newSerializer(cfg.databaseInfo.databaseId);
18353
18439
  const connection = newConnection(cfg.databaseInfo);
18354
- return newDatastore(cfg.credentials, connection, serializer);
18440
+ return newDatastore(cfg.authCredentials, cfg.appCheckCredentials, connection, serializer);
18355
18441
  }
18356
18442
  createRemoteStore(cfg) {
18357
18443
  return newRemoteStore(this.localStore, this.datastore, cfg.asyncQueue, onlineState => syncEngineApplyOnlineStateChange(this.syncEngine, onlineState, 0 /* RemoteStore */), newConnectivityMonitor());
@@ -19109,7 +19195,7 @@ const MAX_CONCURRENT_LIMBO_RESOLUTIONS = 100;
19109
19195
  * async queue that is shared by all of the other components in the system.
19110
19196
  */
19111
19197
  class FirestoreClient {
19112
- constructor(credentials,
19198
+ constructor(authCredentials, appCheckCredentials,
19113
19199
  /**
19114
19200
  * Asynchronous queue responsible for all of our internal processing. When
19115
19201
  * we get incoming work from the user (via public API) or the network
@@ -19119,30 +19205,34 @@ class FirestoreClient {
19119
19205
  * an async I/O to complete).
19120
19206
  */
19121
19207
  asyncQueue, databaseInfo) {
19122
- this.credentials = credentials;
19208
+ this.authCredentials = authCredentials;
19209
+ this.appCheckCredentials = appCheckCredentials;
19123
19210
  this.asyncQueue = asyncQueue;
19124
19211
  this.databaseInfo = databaseInfo;
19125
19212
  this.user = User.UNAUTHENTICATED;
19126
19213
  this.clientId = AutoId.newId();
19127
- this.credentialListener = () => Promise.resolve();
19128
- this.credentials.start(asyncQueue, async (user) => {
19214
+ this.authCredentialListener = () => Promise.resolve();
19215
+ this.authCredentials.start(asyncQueue, async (user) => {
19129
19216
  logDebug(LOG_TAG$2, 'Received user=', user.uid);
19130
- await this.credentialListener(user);
19217
+ await this.authCredentialListener(user);
19131
19218
  this.user = user;
19132
19219
  });
19220
+ // Register an empty credentials change listener to activate token refresh.
19221
+ this.appCheckCredentials.start(asyncQueue, () => Promise.resolve());
19133
19222
  }
19134
19223
  async getConfiguration() {
19135
19224
  return {
19136
19225
  asyncQueue: this.asyncQueue,
19137
19226
  databaseInfo: this.databaseInfo,
19138
19227
  clientId: this.clientId,
19139
- credentials: this.credentials,
19228
+ authCredentials: this.authCredentials,
19229
+ appCheckCredentials: this.appCheckCredentials,
19140
19230
  initialUser: this.user,
19141
19231
  maxConcurrentLimboResolutions: MAX_CONCURRENT_LIMBO_RESOLUTIONS
19142
19232
  };
19143
19233
  }
19144
19234
  setCredentialChangeListener(listener) {
19145
- this.credentialListener = listener;
19235
+ this.authCredentialListener = listener;
19146
19236
  }
19147
19237
  /**
19148
19238
  * Checks that the client has not been terminated. Ensures that other methods on
@@ -19167,7 +19257,8 @@ class FirestoreClient {
19167
19257
  // The credentials provider must be terminated after shutting down the
19168
19258
  // RemoteStore as it will prevent the RemoteStore from retrieving auth
19169
19259
  // tokens.
19170
- this.credentials.shutdown();
19260
+ this.authCredentials.shutdown();
19261
+ this.appCheckCredentials.shutdown();
19171
19262
  deferred.resolve();
19172
19263
  }
19173
19264
  catch (e) {
@@ -19690,8 +19781,9 @@ class FirestoreSettingsImpl {
19690
19781
  */
19691
19782
  class Firestore$1 {
19692
19783
  /** @hideconstructor */
19693
- constructor(databaseIdOrApp, _credentials) {
19694
- this._credentials = _credentials;
19784
+ constructor(databaseIdOrApp, _authCredentials, _appCheckCredentials) {
19785
+ this._authCredentials = _authCredentials;
19786
+ this._appCheckCredentials = _appCheckCredentials;
19695
19787
  /**
19696
19788
  * Whether it's a Firestore or Firestore Lite instance.
19697
19789
  */
@@ -19732,7 +19824,7 @@ class Firestore$1 {
19732
19824
  }
19733
19825
  this._settings = new FirestoreSettingsImpl(settings);
19734
19826
  if (settings.credentials !== undefined) {
19735
- this._credentials = makeCredentialsProvider(settings.credentials);
19827
+ this._authCredentials = makeAuthCredentialsProvider(settings.credentials);
19736
19828
  }
19737
19829
  }
19738
19830
  _getSettings() {
@@ -19813,7 +19905,7 @@ function connectFirestoreEmulator(firestore, host, port, options = {}) {
19813
19905
  }
19814
19906
  user = new User(uid);
19815
19907
  }
19816
- firestore._credentials = new EmulatorCredentialsProvider(new OAuthToken(token, user));
19908
+ firestore._authCredentials = new EmulatorAuthCredentialsProvider(new OAuthToken(token, user));
19817
19909
  }
19818
19910
  }
19819
19911
 
@@ -20442,8 +20534,8 @@ const CACHE_SIZE_UNLIMITED = LRU_COLLECTION_DISABLED;
20442
20534
  */
20443
20535
  class Firestore extends Firestore$1 {
20444
20536
  /** @hideconstructor */
20445
- constructor(databaseIdOrApp, credentialsProvider) {
20446
- super(databaseIdOrApp, credentialsProvider);
20537
+ constructor(databaseIdOrApp, authCredentialsProvider, appCheckCredentialsProvider) {
20538
+ super(databaseIdOrApp, authCredentialsProvider, appCheckCredentialsProvider);
20447
20539
  /**
20448
20540
  * Whether it's a {@link Firestore} or Firestore Lite instance.
20449
20541
  */
@@ -20520,7 +20612,7 @@ function configureFirestore(firestore) {
20520
20612
  var _a;
20521
20613
  const settings = firestore._freezeSettings();
20522
20614
  const databaseInfo = makeDatabaseInfo(firestore._databaseId, ((_a = firestore._app) === null || _a === void 0 ? void 0 : _a.options.appId) || '', firestore._persistenceKey, settings);
20523
- firestore._firestoreClient = new FirestoreClient(firestore._credentials, firestore._queue, databaseInfo);
20615
+ firestore._firestoreClient = new FirestoreClient(firestore._authCredentials, firestore._appCheckCredentials, firestore._queue, databaseInfo);
20524
20616
  }
20525
20617
  /**
20526
20618
  * Attempts to enable persistent storage, if possible.
@@ -20815,7 +20907,7 @@ function registerFirestore(variant, useFetchStreams = true) {
20815
20907
  setSDKVersion(SDK_VERSION$1);
20816
20908
  _registerComponent(new Component('firestore', (container, { options: settings }) => {
20817
20909
  const app = container.getProvider('app').getImmediate();
20818
- const firestoreInstance = new Firestore(app, new FirebaseCredentialsProvider(container.getProvider('auth-internal')));
20910
+ const firestoreInstance = new Firestore(app, new FirebaseAuthCredentialsProvider(container.getProvider('auth-internal')), new FirebaseAppCheckTokenProvider(container.getProvider('app-check-internal')));
20819
20911
  settings = Object.assign({ useFetchStreams }, settings);
20820
20912
  firestoreInstance._setSettings(settings);
20821
20913
  return firestoreInstance;
@@ -23484,5 +23576,5 @@ function writeBatch(firestore) {
23484
23576
  */
23485
23577
  registerFirestore('node');
23486
23578
 
23487
- export { AbstractUserDataWriter, Bytes, CACHE_SIZE_UNLIMITED, CollectionReference, DocumentReference, DocumentSnapshot, FieldPath, FieldValue, Firestore, FirestoreError, GeoPoint, LoadBundleTask, Query, QueryConstraint, QueryDocumentSnapshot, QuerySnapshot, SnapshotMetadata, Timestamp, Transaction, WriteBatch, DatabaseId as _DatabaseId, DocumentKey as _DocumentKey, EmptyCredentialsProvider as _EmptyCredentialsProvider, FieldPath$1 as _FieldPath, cast as _cast, debugAssert as _debugAssert, isBase64Available as _isBase64Available, logWarn as _logWarn, validateIsNotUsedTogether as _validateIsNotUsedTogether, addDoc, arrayRemove, arrayUnion, clearIndexedDbPersistence, collection, collectionGroup, connectFirestoreEmulator, deleteDoc, deleteField, disableNetwork, doc, documentId, enableIndexedDbPersistence, enableMultiTabIndexedDbPersistence, enableNetwork, endAt, endBefore, ensureFirestoreConfigured, executeWrite, getDoc, getDocFromCache, getDocFromServer, getDocs, getDocsFromCache, getDocsFromServer, getFirestore, increment, initializeFirestore, limit, limitToLast, loadBundle, namedQuery, onSnapshot, onSnapshotsInSync, orderBy, query, queryEqual, refEqual, runTransaction, serverTimestamp, setDoc, setLogLevel, snapshotEqual, startAfter, startAt, terminate, updateDoc, waitForPendingWrites, where, writeBatch };
23579
+ export { AbstractUserDataWriter, Bytes, CACHE_SIZE_UNLIMITED, CollectionReference, DocumentReference, DocumentSnapshot, FieldPath, FieldValue, Firestore, FirestoreError, GeoPoint, LoadBundleTask, Query, QueryConstraint, QueryDocumentSnapshot, QuerySnapshot, SnapshotMetadata, Timestamp, Transaction, WriteBatch, DatabaseId as _DatabaseId, DocumentKey as _DocumentKey, EmptyAppCheckTokenProvider as _EmptyAppCheckTokenProvider, EmptyAuthCredentialsProvider as _EmptyAuthCredentialsProvider, FieldPath$1 as _FieldPath, cast as _cast, debugAssert as _debugAssert, isBase64Available as _isBase64Available, logWarn as _logWarn, validateIsNotUsedTogether as _validateIsNotUsedTogether, addDoc, arrayRemove, arrayUnion, clearIndexedDbPersistence, collection, collectionGroup, connectFirestoreEmulator, deleteDoc, deleteField, disableNetwork, doc, documentId, enableIndexedDbPersistence, enableMultiTabIndexedDbPersistence, enableNetwork, endAt, endBefore, ensureFirestoreConfigured, executeWrite, getDoc, getDocFromCache, getDocFromServer, getDocs, getDocsFromCache, getDocsFromServer, getFirestore, increment, initializeFirestore, limit, limitToLast, loadBundle, namedQuery, onSnapshot, onSnapshotsInSync, orderBy, query, queryEqual, refEqual, runTransaction, serverTimestamp, setDoc, setLogLevel, snapshotEqual, startAfter, startAt, terminate, updateDoc, waitForPendingWrites, where, writeBatch };
23488
23580
  //# sourceMappingURL=index.node.mjs.map