@firebase/firestore 3.3.1 → 3.4.0-canary.774b2fc19

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 (99) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/firestore/compat/index.d.ts +1 -1
  3. package/dist/firestore/src/api/credentials.d.ts +64 -30
  4. package/dist/firestore/src/api/database.d.ts +2 -1
  5. package/dist/firestore/src/api.d.ts +2 -1
  6. package/dist/firestore/src/core/component_provider.d.ts +2 -1
  7. package/dist/firestore/src/core/firestore_client.d.ts +4 -3
  8. package/dist/firestore/src/lite-api/components.d.ts +3 -1
  9. package/dist/firestore/src/lite-api/database.d.ts +4 -2
  10. package/dist/firestore/src/platform/browser/webchannel_connection.d.ts +1 -1
  11. package/dist/firestore/src/platform/node/grpc_connection.d.ts +3 -3
  12. package/dist/firestore/src/remote/connection.d.ts +3 -3
  13. package/dist/firestore/src/remote/datastore.d.ts +2 -1
  14. package/dist/firestore/src/remote/persistent_stream.d.ts +9 -7
  15. package/dist/firestore/src/remote/rest_connection.d.ts +4 -4
  16. package/dist/firestore/test/integration/remote/stream.test.d.ts +2 -2
  17. package/dist/firestore/test/integration/util/internal_helpers.d.ts +5 -5
  18. package/dist/firestore/test/unit/remote/rest_connection.test.d.ts +1 -1
  19. package/dist/index.d.ts +2 -1
  20. package/dist/index.esm2017.js +3413 -3359
  21. package/dist/index.esm2017.js.map +1 -1
  22. package/dist/index.esm5.js +3688 -3639
  23. package/dist/index.esm5.js.map +1 -1
  24. package/dist/index.node.cjs.js +195 -109
  25. package/dist/index.node.cjs.js.map +1 -1
  26. package/dist/index.node.mjs +194 -105
  27. package/dist/index.node.mjs.map +1 -1
  28. package/dist/index.rn.js +3391 -3337
  29. package/dist/index.rn.js.map +1 -1
  30. package/dist/internal.d.ts +34 -20
  31. package/dist/lite/firestore/compat/index.d.ts +1 -1
  32. package/dist/lite/firestore/src/api/credentials.d.ts +64 -30
  33. package/dist/lite/firestore/src/api/database.d.ts +2 -1
  34. package/dist/lite/firestore/src/api.d.ts +2 -1
  35. package/dist/lite/firestore/src/core/component_provider.d.ts +2 -1
  36. package/dist/lite/firestore/src/core/firestore_client.d.ts +4 -3
  37. package/dist/lite/firestore/src/lite-api/components.d.ts +3 -1
  38. package/dist/lite/firestore/src/lite-api/database.d.ts +4 -2
  39. package/dist/lite/firestore/src/platform/browser/webchannel_connection.d.ts +1 -1
  40. package/dist/lite/firestore/src/platform/node/grpc_connection.d.ts +3 -3
  41. package/dist/lite/firestore/src/remote/connection.d.ts +3 -3
  42. package/dist/lite/firestore/src/remote/datastore.d.ts +2 -1
  43. package/dist/lite/firestore/src/remote/persistent_stream.d.ts +9 -7
  44. package/dist/lite/firestore/src/remote/rest_connection.d.ts +4 -4
  45. package/dist/lite/firestore/test/integration/remote/stream.test.d.ts +2 -2
  46. package/dist/lite/firestore/test/integration/util/internal_helpers.d.ts +5 -5
  47. package/dist/lite/firestore/test/unit/remote/rest_connection.test.d.ts +1 -1
  48. package/dist/lite/index.browser.esm2017.js +1379 -1365
  49. package/dist/lite/index.browser.esm2017.js.map +1 -1
  50. package/dist/lite/index.browser.esm5.js +934 -925
  51. package/dist/lite/index.browser.esm5.js.map +1 -1
  52. package/dist/lite/index.node.cjs.js +96 -61
  53. package/dist/lite/index.node.cjs.js.map +1 -1
  54. package/dist/lite/index.node.mjs +96 -61
  55. package/dist/lite/index.node.mjs.map +1 -1
  56. package/dist/lite/index.rn.esm2017.js +937 -923
  57. package/dist/lite/index.rn.esm2017.js.map +1 -1
  58. package/dist/lite/internal.d.ts +14 -13
  59. package/dist/lite/packages/firestore/babel-register.d.ts +1 -0
  60. package/dist/lite/packages/firestore/compat/index.d.ts +1 -1
  61. package/dist/lite/packages/firestore/dist/lite/index.browser.esm2017.d.ts +150 -149
  62. package/dist/lite/packages/firestore/src/api/credentials.d.ts +64 -30
  63. package/dist/lite/packages/firestore/src/api/database.d.ts +2 -1
  64. package/dist/lite/packages/firestore/src/api.d.ts +2 -1
  65. package/dist/lite/packages/firestore/src/core/component_provider.d.ts +2 -1
  66. package/dist/lite/packages/firestore/src/core/firestore_client.d.ts +4 -3
  67. package/dist/lite/packages/firestore/src/lite-api/components.d.ts +3 -1
  68. package/dist/lite/packages/firestore/src/lite-api/database.d.ts +4 -2
  69. package/dist/lite/packages/firestore/src/platform/browser/webchannel_connection.d.ts +1 -1
  70. package/dist/lite/packages/firestore/src/platform/node/grpc_connection.d.ts +3 -3
  71. package/dist/lite/packages/firestore/src/remote/connection.d.ts +3 -3
  72. package/dist/lite/packages/firestore/src/remote/datastore.d.ts +2 -1
  73. package/dist/lite/packages/firestore/src/remote/persistent_stream.d.ts +9 -7
  74. package/dist/lite/packages/firestore/src/remote/rest_connection.d.ts +4 -4
  75. package/dist/lite/packages/firestore/test/integration/remote/stream.test.d.ts +2 -2
  76. package/dist/lite/packages/firestore/test/integration/util/internal_helpers.d.ts +5 -5
  77. package/dist/lite/packages/firestore/test/unit/remote/rest_connection.test.d.ts +1 -1
  78. package/dist/lite/private.d.ts +14 -13
  79. package/dist/packages/firestore/babel-register.d.ts +1 -0
  80. package/dist/packages/firestore/compat/index.d.ts +1 -1
  81. package/dist/packages/firestore/dist/index.esm2017.d.ts +211 -195
  82. package/dist/packages/firestore/src/api/credentials.d.ts +64 -30
  83. package/dist/packages/firestore/src/api/database.d.ts +2 -1
  84. package/dist/packages/firestore/src/api.d.ts +2 -1
  85. package/dist/packages/firestore/src/core/component_provider.d.ts +2 -1
  86. package/dist/packages/firestore/src/core/firestore_client.d.ts +4 -3
  87. package/dist/packages/firestore/src/lite-api/components.d.ts +3 -1
  88. package/dist/packages/firestore/src/lite-api/database.d.ts +4 -2
  89. package/dist/packages/firestore/src/platform/browser/webchannel_connection.d.ts +1 -1
  90. package/dist/packages/firestore/src/platform/node/grpc_connection.d.ts +3 -3
  91. package/dist/packages/firestore/src/remote/connection.d.ts +3 -3
  92. package/dist/packages/firestore/src/remote/datastore.d.ts +2 -1
  93. package/dist/packages/firestore/src/remote/persistent_stream.d.ts +9 -7
  94. package/dist/packages/firestore/src/remote/rest_connection.d.ts +4 -4
  95. package/dist/packages/firestore/test/integration/remote/stream.test.d.ts +2 -2
  96. package/dist/packages/firestore/test/integration/util/internal_helpers.d.ts +5 -5
  97. package/dist/packages/firestore/test/unit/remote/rest_connection.test.d.ts +1 -1
  98. package/dist/private.d.ts +24 -19
  99. package/package.json +10 -10
@@ -4,14 +4,13 @@ import { Logger, LogLevel } from '@firebase/logger';
4
4
  import { inspect, TextEncoder, TextDecoder } from 'util';
5
5
  import { createMockUserToken, getModularInstance, deepEqual, getUA, isIndexedDBAvailable, isSafari } from '@firebase/util';
6
6
  import { randomBytes as randomBytes$1 } from 'crypto';
7
- import module from 'module';
8
7
  import { credentials, loadPackageDefinition, Metadata } from '@grpc/grpc-js';
9
8
  import { dirname, resolve, join } from 'path';
10
9
  import { fileURLToPath } from 'url';
11
10
  import { loadSync } from '@grpc/proto-loader';
12
11
 
13
12
  const name = "@firebase/firestore";
14
- const version$1 = "3.3.1";
13
+ const version$1 = "3.4.0-canary.774b2fc19";
15
14
 
16
15
  /**
17
16
  * @license
@@ -64,7 +63,7 @@ User.GOOGLE_CREDENTIALS = new User('google-credentials-uid');
64
63
  User.FIRST_PARTY = new User('first-party-uid');
65
64
  User.MOCK_USER = new User('mock-user');
66
65
 
67
- const version = "9.5.0";
66
+ const version = "9.6.0-canary.774b2fc19";
68
67
 
69
68
  /**
70
69
  * @license
@@ -452,16 +451,15 @@ class OAuthToken {
452
451
  constructor(value, user) {
453
452
  this.user = user;
454
453
  this.type = 'OAuth';
455
- this.authHeaders = {};
456
- // Set the headers using Object Literal notation to avoid minification
457
- this.authHeaders['Authorization'] = `Bearer ${value}`;
454
+ this.headers = new Map();
455
+ this.headers.set('Authorization', `Bearer ${value}`);
458
456
  }
459
457
  }
460
458
  /**
461
459
  * A CredentialsProvider that always yields an empty token.
462
460
  * @internal
463
461
  */
464
- class EmptyCredentialsProvider {
462
+ class EmptyAuthCredentialsProvider {
465
463
  getToken() {
466
464
  return Promise.resolve(null);
467
465
  }
@@ -476,7 +474,7 @@ class EmptyCredentialsProvider {
476
474
  * A CredentialsProvider that always returns a constant token. Used for
477
475
  * emulator token mocking.
478
476
  */
479
- class EmulatorCredentialsProvider {
477
+ class EmulatorAuthCredentialsProvider {
480
478
  constructor(token) {
481
479
  this.token = token;
482
480
  /**
@@ -499,7 +497,7 @@ class EmulatorCredentialsProvider {
499
497
  this.changeListener = null;
500
498
  }
501
499
  }
502
- class FirebaseCredentialsProvider {
500
+ class FirebaseAuthCredentialsProvider {
503
501
  constructor(authProvider) {
504
502
  this.authProvider = authProvider;
505
503
  /** Tracks the current User. */
@@ -542,7 +540,7 @@ class FirebaseCredentialsProvider {
542
540
  });
543
541
  };
544
542
  const registerAuth = (auth) => {
545
- logDebug('FirebaseCredentialsProvider', 'Auth detected');
543
+ logDebug('FirebaseAuthCredentialsProvider', 'Auth detected');
546
544
  this.auth = auth;
547
545
  this.auth.addAuthTokenListener(this.tokenListener);
548
546
  awaitNextToken();
@@ -559,7 +557,7 @@ class FirebaseCredentialsProvider {
559
557
  }
560
558
  else {
561
559
  // If auth is still not available, proceed with `null` user
562
- logDebug('FirebaseCredentialsProvider', 'Auth not yet detected');
560
+ logDebug('FirebaseAuthCredentialsProvider', 'Auth not yet detected');
563
561
  nextToken.resolve();
564
562
  nextToken = new Deferred();
565
563
  }
@@ -582,7 +580,7 @@ class FirebaseCredentialsProvider {
582
580
  // outstanding so the response is potentially for a previous user (which
583
581
  // user, we can't be sure).
584
582
  if (this.tokenCounter !== initialTokenCounter) {
585
- logDebug('FirebaseCredentialsProvider', 'getToken aborted due to token change.');
583
+ logDebug('FirebaseAuthCredentialsProvider', 'getToken aborted due to token change.');
586
584
  return this.getToken();
587
585
  }
588
586
  else {
@@ -623,25 +621,17 @@ class FirebaseCredentialsProvider {
623
621
  */
624
622
  class FirstPartyToken {
625
623
  constructor(gapi, sessionIndex, iamToken) {
626
- this.gapi = gapi;
627
- this.sessionIndex = sessionIndex;
628
- this.iamToken = iamToken;
629
624
  this.type = 'FirstParty';
630
625
  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']([]);
626
+ this.headers = new Map();
627
+ this.headers.set('X-Goog-AuthUser', sessionIndex);
628
+ const authHeader = gapi['auth']['getAuthHeaderValueForFirstParty']([]);
638
629
  if (authHeader) {
639
- headers['Authorization'] = authHeader;
630
+ this.headers.set('Authorization', authHeader);
640
631
  }
641
- if (this.iamToken) {
642
- headers['X-Goog-Iam-Authorization-Token'] = this.iamToken;
632
+ if (iamToken) {
633
+ this.headers.set('X-Goog-Iam-Authorization-Token', iamToken);
643
634
  }
644
- return headers;
645
635
  }
646
636
  }
647
637
  /*
@@ -649,7 +639,7 @@ class FirstPartyToken {
649
639
  * to authenticate the user, using technique that is only available
650
640
  * to applications hosted by Google.
651
641
  */
652
- class FirstPartyCredentialsProvider {
642
+ class FirstPartyAuthCredentialsProvider {
653
643
  constructor(gapi, sessionIndex, iamToken) {
654
644
  this.gapi = gapi;
655
645
  this.sessionIndex = sessionIndex;
@@ -665,13 +655,97 @@ class FirstPartyCredentialsProvider {
665
655
  shutdown() { }
666
656
  invalidateToken() { }
667
657
  }
658
+ class AppCheckToken {
659
+ constructor(value) {
660
+ this.value = value;
661
+ this.type = 'AppCheck';
662
+ this.headers = new Map();
663
+ if (value && value.length > 0) {
664
+ this.headers.set('x-firebase-appcheck', this.value);
665
+ }
666
+ }
667
+ }
668
+ class FirebaseAppCheckTokenProvider {
669
+ constructor(appCheckProvider) {
670
+ this.appCheckProvider = appCheckProvider;
671
+ this.forceRefresh = false;
672
+ this.appCheck = null;
673
+ }
674
+ start(asyncQueue, changeListener) {
675
+ const onTokenChanged = tokenResult => {
676
+ if (tokenResult.error != null) {
677
+ logDebug('FirebaseAppCheckTokenProvider', `Error getting App Check token; using placeholder token instead. Error: ${tokenResult.error.message}`);
678
+ }
679
+ return changeListener(tokenResult.token);
680
+ };
681
+ this.tokenListener = (tokenResult) => {
682
+ asyncQueue.enqueueRetryable(() => onTokenChanged(tokenResult));
683
+ };
684
+ const registerAppCheck = (appCheck) => {
685
+ logDebug('FirebaseAppCheckTokenProvider', 'AppCheck detected');
686
+ this.appCheck = appCheck;
687
+ this.appCheck.addTokenListener(this.tokenListener);
688
+ };
689
+ this.appCheckProvider.onInit(appCheck => registerAppCheck(appCheck));
690
+ // Our users can initialize AppCheck after Firestore, so we give it
691
+ // a chance to register itself with the component framework.
692
+ setTimeout(() => {
693
+ if (!this.appCheck) {
694
+ const appCheck = this.appCheckProvider.getImmediate({ optional: true });
695
+ if (appCheck) {
696
+ registerAppCheck(appCheck);
697
+ }
698
+ else {
699
+ // If AppCheck is still not available, proceed without it.
700
+ logDebug('FirebaseAppCheckTokenProvider', 'AppCheck not yet detected');
701
+ }
702
+ }
703
+ }, 0);
704
+ }
705
+ getToken() {
706
+ const forceRefresh = this.forceRefresh;
707
+ this.forceRefresh = false;
708
+ if (!this.appCheck) {
709
+ return Promise.resolve(null);
710
+ }
711
+ return this.appCheck.getToken(forceRefresh).then(tokenResult => {
712
+ if (tokenResult) {
713
+ hardAssert(typeof tokenResult.token === 'string');
714
+ return new AppCheckToken(tokenResult.token);
715
+ }
716
+ else {
717
+ return null;
718
+ }
719
+ });
720
+ }
721
+ invalidateToken() {
722
+ this.forceRefresh = true;
723
+ }
724
+ shutdown() {
725
+ if (this.appCheck) {
726
+ this.appCheck.removeTokenListener(this.tokenListener);
727
+ }
728
+ }
729
+ }
730
+ /**
731
+ * An AppCheck token provider that always yields an empty token.
732
+ * @internal
733
+ */
734
+ class EmptyAppCheckTokenProvider {
735
+ getToken() {
736
+ return Promise.resolve(new AppCheckToken(''));
737
+ }
738
+ invalidateToken() { }
739
+ start(asyncQueue, changeListener) { }
740
+ shutdown() { }
741
+ }
668
742
  /**
669
743
  * Builds a CredentialsProvider depending on the type of
670
744
  * the credentials passed in.
671
745
  */
672
- function makeCredentialsProvider(credentials) {
746
+ function makeAuthCredentialsProvider(credentials) {
673
747
  if (!credentials) {
674
- return new EmptyCredentialsProvider();
748
+ return new EmptyAuthCredentialsProvider();
675
749
  }
676
750
  switch (credentials['type']) {
677
751
  case 'gapi':
@@ -681,11 +755,11 @@ function makeCredentialsProvider(credentials) {
681
755
  client !== null &&
682
756
  client['auth'] &&
683
757
  client['auth']['getAuthHeaderValueForFirstParty']));
684
- return new FirstPartyCredentialsProvider(client, credentials['sessionIndex'] || '0', credentials['iamToken'] || null);
758
+ return new FirstPartyAuthCredentialsProvider(client, credentials['sessionIndex'] || '0', credentials['iamToken'] || null);
685
759
  case 'provider':
686
760
  return credentials['client'];
687
761
  default:
688
- throw new FirestoreError(Code.INVALID_ARGUMENT, 'makeCredentialsProvider failed due to invalid credential type');
762
+ throw new FirestoreError(Code.INVALID_ARGUMENT, 'makeAuthCredentialsProvider failed due to invalid credential type');
689
763
  }
690
764
  }
691
765
 
@@ -14237,22 +14311,19 @@ function nodePromise(action) {
14237
14311
  * See the License for the specific language governing permissions and
14238
14312
  * limitations under the License.
14239
14313
  */
14240
- // This is a hack fix for Node ES modules to use `require`.
14241
- // @ts-ignore To avoid using `--module es2020` flag.
14242
- const require = module.createRequire(import.meta.url);
14243
- // eslint-disable-next-line @typescript-eslint/no-require-imports
14244
- const { version: grpcVersion } = require('@grpc/grpc-js/package.json');
14314
+ // TODO: Fetch runtime version from grpc-js/package.json instead
14315
+ // when there's a cleaner way to dynamic require JSON in both Node ESM and CJS
14316
+ const grpcVersion = '1.3.7';
14245
14317
  const LOG_TAG$9 = 'Connection';
14246
14318
  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');
14319
+ function createMetadata(databasePath, authToken, appCheckToken, appId) {
14320
+ hardAssert(authToken === null || authToken.type === 'OAuth');
14249
14321
  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
- }
14322
+ if (authToken) {
14323
+ authToken.headers.forEach((value, key) => metadata.set(key, value));
14324
+ }
14325
+ if (appCheckToken) {
14326
+ appCheckToken.headers.forEach((value, key) => metadata.set(key, value));
14256
14327
  }
14257
14328
  if (appId) {
14258
14329
  metadata.set('X-Firebase-GMPID', appId);
@@ -14285,9 +14356,9 @@ class GrpcConnection {
14285
14356
  }
14286
14357
  return this.cachedStub;
14287
14358
  }
14288
- invokeRPC(rpcName, path, request, token) {
14359
+ invokeRPC(rpcName, path, request, authToken, appCheckToken) {
14289
14360
  const stub = this.ensureActiveStub();
14290
- const metadata = createMetadata(this.databasePath, token, this.databaseInfo.appId);
14361
+ const metadata = createMetadata(this.databasePath, authToken, appCheckToken, this.databaseInfo.appId);
14291
14362
  const jsonRequest = Object.assign({ database: this.databasePath }, request);
14292
14363
  return nodePromise((callback) => {
14293
14364
  logDebug(LOG_TAG$9, `RPC '${rpcName}' invoked with request:`, request);
@@ -14303,12 +14374,12 @@ class GrpcConnection {
14303
14374
  });
14304
14375
  });
14305
14376
  }
14306
- invokeStreamingRPC(rpcName, path, request, token) {
14377
+ invokeStreamingRPC(rpcName, path, request, authToken, appCheckToken) {
14307
14378
  const results = [];
14308
14379
  const responseDeferred = new Deferred();
14309
14380
  logDebug(LOG_TAG$9, `RPC '${rpcName}' invoked (streaming) with request:`, request);
14310
14381
  const stub = this.ensureActiveStub();
14311
- const metadata = createMetadata(this.databasePath, token, this.databaseInfo.appId);
14382
+ const metadata = createMetadata(this.databasePath, authToken, appCheckToken, this.databaseInfo.appId);
14312
14383
  const jsonRequest = Object.assign(Object.assign({}, request), { database: this.databasePath });
14313
14384
  const stream = stub[rpcName](jsonRequest, metadata);
14314
14385
  stream.on('data', (response) => {
@@ -14327,9 +14398,9 @@ class GrpcConnection {
14327
14398
  return responseDeferred.promise;
14328
14399
  }
14329
14400
  // TODO(mikelehen): This "method" is a monster. Should be refactored.
14330
- openStream(rpcName, token) {
14401
+ openStream(rpcName, authToken, appCheckToken) {
14331
14402
  const stub = this.ensureActiveStub();
14332
- const metadata = createMetadata(this.databasePath, token, this.databaseInfo.appId);
14403
+ const metadata = createMetadata(this.databasePath, authToken, appCheckToken, this.databaseInfo.appId);
14333
14404
  const grpcStream = stub[rpcName](metadata);
14334
14405
  let closed = false;
14335
14406
  const close = (err) => {
@@ -14409,8 +14480,8 @@ class GrpcConnection {
14409
14480
  */
14410
14481
  // __filename and __dirname globals are unavailable in ES modules
14411
14482
  // @ts-ignore To avoid using `--module es2020` flag.
14412
- const __filename = fileURLToPath(import.meta.url);
14413
- const __dirname = dirname(__filename);
14483
+ const __filenameInESM = fileURLToPath(import.meta.url);
14484
+ const __dirnameInESM = dirname(__filenameInESM);
14414
14485
  /** Used by tests so we can match @grpc/proto-loader behavior. */
14415
14486
  const protoLoaderOptions = {
14416
14487
  longs: String,
@@ -14424,7 +14495,7 @@ const protoLoaderOptions = {
14424
14495
  * @returns The GrpcObject representing our protos.
14425
14496
  */
14426
14497
  function loadProtos() {
14427
- const root = resolve(__dirname, "src/protos" );
14498
+ const root = resolve(__dirnameInESM, "src/protos" );
14428
14499
  const firestoreProtoFile = join(root, 'google/firestore/v1/firestore.proto');
14429
14500
  const packageDefinition = loadSync(firestoreProtoFile, Object.assign(Object.assign({}, protoLoaderOptions), { includeDirs: [root] }));
14430
14501
  return loadPackageDefinition(packageDefinition);
@@ -14713,12 +14784,13 @@ const HEALTHY_TIMEOUT_MS = 10 * 1000;
14713
14784
  * ListenerType: The type of the listener that will be used for callbacks
14714
14785
  */
14715
14786
  class PersistentStream {
14716
- constructor(queue, connectionTimerId, idleTimerId, healthTimerId, connection, credentialsProvider, listener) {
14787
+ constructor(queue, connectionTimerId, idleTimerId, healthTimerId, connection, authCredentialsProvider, appCheckCredentialsProvider, listener) {
14717
14788
  this.queue = queue;
14718
14789
  this.idleTimerId = idleTimerId;
14719
14790
  this.healthTimerId = healthTimerId;
14720
14791
  this.connection = connection;
14721
- this.credentialsProvider = credentialsProvider;
14792
+ this.authCredentialsProvider = authCredentialsProvider;
14793
+ this.appCheckCredentialsProvider = appCheckCredentialsProvider;
14722
14794
  this.listener = listener;
14723
14795
  this.state = 0 /* Initial */;
14724
14796
  /**
@@ -14873,7 +14945,8 @@ class PersistentStream {
14873
14945
  // fail, however. In this case, we should get a Code.UNAUTHENTICATED error
14874
14946
  // before we received the first message and we need to invalidate the token
14875
14947
  // to ensure that we fetch a new token.
14876
- this.credentialsProvider.invalidateToken();
14948
+ this.authCredentialsProvider.invalidateToken();
14949
+ this.appCheckCredentialsProvider.invalidateToken();
14877
14950
  }
14878
14951
  // Clean up the underlying stream because we are no longer interested in events.
14879
14952
  if (this.stream !== null) {
@@ -14897,7 +14970,10 @@ class PersistentStream {
14897
14970
  const dispatchIfNotClosed = this.getCloseGuardedDispatcher(this.closeCount);
14898
14971
  // TODO(mikelehen): Just use dispatchIfNotClosed, but see TODO below.
14899
14972
  const closeCount = this.closeCount;
14900
- this.credentialsProvider.getToken().then(token => {
14973
+ Promise.all([
14974
+ this.authCredentialsProvider.getToken(),
14975
+ this.appCheckCredentialsProvider.getToken()
14976
+ ]).then(([authToken, appCheckToken]) => {
14901
14977
  // Stream can be stopped while waiting for authentication.
14902
14978
  // TODO(mikelehen): We really should just use dispatchIfNotClosed
14903
14979
  // and let this dispatch onto the queue, but that opened a spec test can
@@ -14906,7 +14982,7 @@ class PersistentStream {
14906
14982
  // Normally we'd have to schedule the callback on the AsyncQueue.
14907
14983
  // However, the following calls are safe to be called outside the
14908
14984
  // AsyncQueue since they don't chain asynchronous calls
14909
- this.startStream(token);
14985
+ this.startStream(authToken, appCheckToken);
14910
14986
  }
14911
14987
  }, (error) => {
14912
14988
  dispatchIfNotClosed(() => {
@@ -14915,9 +14991,9 @@ class PersistentStream {
14915
14991
  });
14916
14992
  });
14917
14993
  }
14918
- startStream(token) {
14994
+ startStream(authToken, appCheckToken) {
14919
14995
  const dispatchIfNotClosed = this.getCloseGuardedDispatcher(this.closeCount);
14920
- this.stream = this.startRpc(token);
14996
+ this.stream = this.startRpc(authToken, appCheckToken);
14921
14997
  this.stream.onOpen(() => {
14922
14998
  dispatchIfNotClosed(() => {
14923
14999
  this.state = 2 /* Open */;
@@ -14986,12 +15062,12 @@ class PersistentStream {
14986
15062
  * sent from the server for ListenResponses.
14987
15063
  */
14988
15064
  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);
15065
+ constructor(queue, connection, authCredentials, appCheckCredentials, serializer, listener) {
15066
+ super(queue, "listen_stream_connection_backoff" /* ListenStreamConnectionBackoff */, "listen_stream_idle" /* ListenStreamIdle */, "health_check_timeout" /* HealthCheckTimeout */, connection, authCredentials, appCheckCredentials, listener);
14991
15067
  this.serializer = serializer;
14992
15068
  }
14993
- startRpc(token) {
14994
- return this.connection.openStream('Listen', token);
15069
+ startRpc(authToken, appCheckToken) {
15070
+ return this.connection.openStream('Listen', authToken, appCheckToken);
14995
15071
  }
14996
15072
  onMessage(watchChangeProto) {
14997
15073
  // A successful response means the stream is healthy
@@ -15045,8 +15121,8 @@ class PersistentListenStream extends PersistentStream {
15045
15121
  * TODO(b/33271235): Use proto types
15046
15122
  */
15047
15123
  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);
15124
+ constructor(queue, connection, authCredentials, appCheckCredentials, serializer, listener) {
15125
+ super(queue, "write_stream_connection_backoff" /* WriteStreamConnectionBackoff */, "write_stream_idle" /* WriteStreamIdle */, "health_check_timeout" /* HealthCheckTimeout */, connection, authCredentials, appCheckCredentials, listener);
15050
15126
  this.serializer = serializer;
15051
15127
  this.handshakeComplete_ = false;
15052
15128
  }
@@ -15068,8 +15144,8 @@ class PersistentWriteStream extends PersistentStream {
15068
15144
  this.writeMutations([]);
15069
15145
  }
15070
15146
  }
15071
- startRpc(token) {
15072
- return this.connection.openStream('Write', token);
15147
+ startRpc(authToken, appCheckToken) {
15148
+ return this.connection.openStream('Write', authToken, appCheckToken);
15073
15149
  }
15074
15150
  onMessage(responseProto) {
15075
15151
  // Always capture the last stream token.
@@ -15141,9 +15217,10 @@ class Datastore {
15141
15217
  * consumption.
15142
15218
  */
15143
15219
  class DatastoreImpl extends Datastore {
15144
- constructor(credentials, connection, serializer) {
15220
+ constructor(authCredentials, appCheckCredentials, connection, serializer) {
15145
15221
  super();
15146
- this.credentials = credentials;
15222
+ this.authCredentials = authCredentials;
15223
+ this.appCheckCredentials = appCheckCredentials;
15147
15224
  this.connection = connection;
15148
15225
  this.serializer = serializer;
15149
15226
  this.terminated = false;
@@ -15153,18 +15230,21 @@ class DatastoreImpl extends Datastore {
15153
15230
  throw new FirestoreError(Code.FAILED_PRECONDITION, 'The client has already been terminated.');
15154
15231
  }
15155
15232
  }
15156
- /** Gets an auth token and invokes the provided RPC. */
15233
+ /** Invokes the provided RPC with auth and AppCheck tokens. */
15157
15234
  invokeRPC(rpcName, path, request) {
15158
15235
  this.verifyInitialized();
15159
- return this.credentials
15160
- .getToken()
15161
- .then(token => {
15162
- return this.connection.invokeRPC(rpcName, path, request, token);
15236
+ return Promise.all([
15237
+ this.authCredentials.getToken(),
15238
+ this.appCheckCredentials.getToken()
15239
+ ])
15240
+ .then(([authToken, appCheckToken]) => {
15241
+ return this.connection.invokeRPC(rpcName, path, request, authToken, appCheckToken);
15163
15242
  })
15164
15243
  .catch((error) => {
15165
15244
  if (error.name === 'FirebaseError') {
15166
15245
  if (error.code === Code.UNAUTHENTICATED) {
15167
- this.credentials.invalidateToken();
15246
+ this.authCredentials.invalidateToken();
15247
+ this.appCheckCredentials.invalidateToken();
15168
15248
  }
15169
15249
  throw error;
15170
15250
  }
@@ -15173,18 +15253,21 @@ class DatastoreImpl extends Datastore {
15173
15253
  }
15174
15254
  });
15175
15255
  }
15176
- /** Gets an auth token and invokes the provided RPC with streamed results. */
15256
+ /** Invokes the provided RPC with streamed results with auth and AppCheck tokens. */
15177
15257
  invokeStreamingRPC(rpcName, path, request) {
15178
15258
  this.verifyInitialized();
15179
- return this.credentials
15180
- .getToken()
15181
- .then(token => {
15182
- return this.connection.invokeStreamingRPC(rpcName, path, request, token);
15259
+ return Promise.all([
15260
+ this.authCredentials.getToken(),
15261
+ this.appCheckCredentials.getToken()
15262
+ ])
15263
+ .then(([authToken, appCheckToken]) => {
15264
+ return this.connection.invokeStreamingRPC(rpcName, path, request, authToken, appCheckToken);
15183
15265
  })
15184
15266
  .catch((error) => {
15185
15267
  if (error.name === 'FirebaseError') {
15186
15268
  if (error.code === Code.UNAUTHENTICATED) {
15187
- this.credentials.invalidateToken();
15269
+ this.authCredentials.invalidateToken();
15270
+ this.appCheckCredentials.invalidateToken();
15188
15271
  }
15189
15272
  throw error;
15190
15273
  }
@@ -15199,8 +15282,8 @@ class DatastoreImpl extends Datastore {
15199
15282
  }
15200
15283
  // TODO(firestorexp): Make sure there is only one Datastore instance per
15201
15284
  // firestore-exp client.
15202
- function newDatastore(credentials, connection, serializer) {
15203
- return new DatastoreImpl(credentials, connection, serializer);
15285
+ function newDatastore(authCredentials, appCheckCredentials, connection, serializer) {
15286
+ return new DatastoreImpl(authCredentials, appCheckCredentials, connection, serializer);
15204
15287
  }
15205
15288
  async function invokeCommitRpc(datastore, mutations) {
15206
15289
  const datastoreImpl = debugCast(datastore);
@@ -15233,12 +15316,12 @@ async function invokeBatchGetDocumentsRpc(datastore, keys) {
15233
15316
  function newPersistentWriteStream(datastore, queue, listener) {
15234
15317
  const datastoreImpl = debugCast(datastore);
15235
15318
  datastoreImpl.verifyInitialized();
15236
- return new PersistentWriteStream(queue, datastoreImpl.connection, datastoreImpl.credentials, datastoreImpl.serializer, listener);
15319
+ return new PersistentWriteStream(queue, datastoreImpl.connection, datastoreImpl.authCredentials, datastoreImpl.appCheckCredentials, datastoreImpl.serializer, listener);
15237
15320
  }
15238
15321
  function newPersistentWatchStream(datastore, queue, listener) {
15239
15322
  const datastoreImpl = debugCast(datastore);
15240
15323
  datastoreImpl.verifyInitialized();
15241
- return new PersistentListenStream(queue, datastoreImpl.connection, datastoreImpl.credentials, datastoreImpl.serializer, listener);
15324
+ return new PersistentListenStream(queue, datastoreImpl.connection, datastoreImpl.authCredentials, datastoreImpl.appCheckCredentials, datastoreImpl.serializer, listener);
15242
15325
  }
15243
15326
 
15244
15327
  /**
@@ -18351,7 +18434,7 @@ class OnlineComponentProvider {
18351
18434
  createDatastore(cfg) {
18352
18435
  const serializer = newSerializer(cfg.databaseInfo.databaseId);
18353
18436
  const connection = newConnection(cfg.databaseInfo);
18354
- return newDatastore(cfg.credentials, connection, serializer);
18437
+ return newDatastore(cfg.authCredentials, cfg.appCheckCredentials, connection, serializer);
18355
18438
  }
18356
18439
  createRemoteStore(cfg) {
18357
18440
  return newRemoteStore(this.localStore, this.datastore, cfg.asyncQueue, onlineState => syncEngineApplyOnlineStateChange(this.syncEngine, onlineState, 0 /* RemoteStore */), newConnectivityMonitor());
@@ -19109,7 +19192,7 @@ const MAX_CONCURRENT_LIMBO_RESOLUTIONS = 100;
19109
19192
  * async queue that is shared by all of the other components in the system.
19110
19193
  */
19111
19194
  class FirestoreClient {
19112
- constructor(credentials,
19195
+ constructor(authCredentials, appCheckCredentials,
19113
19196
  /**
19114
19197
  * Asynchronous queue responsible for all of our internal processing. When
19115
19198
  * we get incoming work from the user (via public API) or the network
@@ -19119,30 +19202,34 @@ class FirestoreClient {
19119
19202
  * an async I/O to complete).
19120
19203
  */
19121
19204
  asyncQueue, databaseInfo) {
19122
- this.credentials = credentials;
19205
+ this.authCredentials = authCredentials;
19206
+ this.appCheckCredentials = appCheckCredentials;
19123
19207
  this.asyncQueue = asyncQueue;
19124
19208
  this.databaseInfo = databaseInfo;
19125
19209
  this.user = User.UNAUTHENTICATED;
19126
19210
  this.clientId = AutoId.newId();
19127
- this.credentialListener = () => Promise.resolve();
19128
- this.credentials.start(asyncQueue, async (user) => {
19211
+ this.authCredentialListener = () => Promise.resolve();
19212
+ this.authCredentials.start(asyncQueue, async (user) => {
19129
19213
  logDebug(LOG_TAG$2, 'Received user=', user.uid);
19130
- await this.credentialListener(user);
19214
+ await this.authCredentialListener(user);
19131
19215
  this.user = user;
19132
19216
  });
19217
+ // Register an empty credentials change listener to activate token refresh.
19218
+ this.appCheckCredentials.start(asyncQueue, () => Promise.resolve());
19133
19219
  }
19134
19220
  async getConfiguration() {
19135
19221
  return {
19136
19222
  asyncQueue: this.asyncQueue,
19137
19223
  databaseInfo: this.databaseInfo,
19138
19224
  clientId: this.clientId,
19139
- credentials: this.credentials,
19225
+ authCredentials: this.authCredentials,
19226
+ appCheckCredentials: this.appCheckCredentials,
19140
19227
  initialUser: this.user,
19141
19228
  maxConcurrentLimboResolutions: MAX_CONCURRENT_LIMBO_RESOLUTIONS
19142
19229
  };
19143
19230
  }
19144
19231
  setCredentialChangeListener(listener) {
19145
- this.credentialListener = listener;
19232
+ this.authCredentialListener = listener;
19146
19233
  }
19147
19234
  /**
19148
19235
  * Checks that the client has not been terminated. Ensures that other methods on
@@ -19167,7 +19254,8 @@ class FirestoreClient {
19167
19254
  // The credentials provider must be terminated after shutting down the
19168
19255
  // RemoteStore as it will prevent the RemoteStore from retrieving auth
19169
19256
  // tokens.
19170
- this.credentials.shutdown();
19257
+ this.authCredentials.shutdown();
19258
+ this.appCheckCredentials.shutdown();
19171
19259
  deferred.resolve();
19172
19260
  }
19173
19261
  catch (e) {
@@ -19690,8 +19778,9 @@ class FirestoreSettingsImpl {
19690
19778
  */
19691
19779
  class Firestore$1 {
19692
19780
  /** @hideconstructor */
19693
- constructor(databaseIdOrApp, _credentials) {
19694
- this._credentials = _credentials;
19781
+ constructor(databaseIdOrApp, _authCredentials, _appCheckCredentials) {
19782
+ this._authCredentials = _authCredentials;
19783
+ this._appCheckCredentials = _appCheckCredentials;
19695
19784
  /**
19696
19785
  * Whether it's a Firestore or Firestore Lite instance.
19697
19786
  */
@@ -19732,7 +19821,7 @@ class Firestore$1 {
19732
19821
  }
19733
19822
  this._settings = new FirestoreSettingsImpl(settings);
19734
19823
  if (settings.credentials !== undefined) {
19735
- this._credentials = makeCredentialsProvider(settings.credentials);
19824
+ this._authCredentials = makeAuthCredentialsProvider(settings.credentials);
19736
19825
  }
19737
19826
  }
19738
19827
  _getSettings() {
@@ -19813,7 +19902,7 @@ function connectFirestoreEmulator(firestore, host, port, options = {}) {
19813
19902
  }
19814
19903
  user = new User(uid);
19815
19904
  }
19816
- firestore._credentials = new EmulatorCredentialsProvider(new OAuthToken(token, user));
19905
+ firestore._authCredentials = new EmulatorAuthCredentialsProvider(new OAuthToken(token, user));
19817
19906
  }
19818
19907
  }
19819
19908
 
@@ -20442,8 +20531,8 @@ const CACHE_SIZE_UNLIMITED = LRU_COLLECTION_DISABLED;
20442
20531
  */
20443
20532
  class Firestore extends Firestore$1 {
20444
20533
  /** @hideconstructor */
20445
- constructor(databaseIdOrApp, credentialsProvider) {
20446
- super(databaseIdOrApp, credentialsProvider);
20534
+ constructor(databaseIdOrApp, authCredentialsProvider, appCheckCredentialsProvider) {
20535
+ super(databaseIdOrApp, authCredentialsProvider, appCheckCredentialsProvider);
20447
20536
  /**
20448
20537
  * Whether it's a {@link Firestore} or Firestore Lite instance.
20449
20538
  */
@@ -20520,7 +20609,7 @@ function configureFirestore(firestore) {
20520
20609
  var _a;
20521
20610
  const settings = firestore._freezeSettings();
20522
20611
  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);
20612
+ firestore._firestoreClient = new FirestoreClient(firestore._authCredentials, firestore._appCheckCredentials, firestore._queue, databaseInfo);
20524
20613
  }
20525
20614
  /**
20526
20615
  * Attempts to enable persistent storage, if possible.
@@ -20815,11 +20904,11 @@ function registerFirestore(variant, useFetchStreams = true) {
20815
20904
  setSDKVersion(SDK_VERSION$1);
20816
20905
  _registerComponent(new Component('firestore', (container, { options: settings }) => {
20817
20906
  const app = container.getProvider('app').getImmediate();
20818
- const firestoreInstance = new Firestore(app, new FirebaseCredentialsProvider(container.getProvider('auth-internal')));
20907
+ const firestoreInstance = new Firestore(app, new FirebaseAuthCredentialsProvider(container.getProvider('auth-internal')), new FirebaseAppCheckTokenProvider(container.getProvider('app-check-internal')));
20819
20908
  settings = Object.assign({ useFetchStreams }, settings);
20820
20909
  firestoreInstance._setSettings(settings);
20821
20910
  return firestoreInstance;
20822
- }, "PUBLIC" /* PUBLIC */));
20911
+ }, 'PUBLIC'));
20823
20912
  registerVersion(name, version$1, variant);
20824
20913
  // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation
20825
20914
  registerVersion(name, version$1, 'esm2017');
@@ -23484,5 +23573,5 @@ function writeBatch(firestore) {
23484
23573
  */
23485
23574
  registerFirestore('node');
23486
23575
 
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 };
23576
+ 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
23577
  //# sourceMappingURL=index.node.mjs.map