@firebase/firestore 3.3.1 → 3.4.0-2021111174650
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/CHANGELOG.md +6 -0
- package/dist/firestore/src/api/credentials.d.ts +64 -30
- package/dist/firestore/src/api/database.d.ts +2 -1
- package/dist/firestore/src/api.d.ts +2 -1
- package/dist/firestore/src/core/component_provider.d.ts +2 -1
- package/dist/firestore/src/core/firestore_client.d.ts +4 -3
- package/dist/firestore/src/lite-api/components.d.ts +3 -1
- package/dist/firestore/src/lite-api/database.d.ts +4 -2
- package/dist/firestore/src/platform/browser/webchannel_connection.d.ts +1 -1
- package/dist/firestore/src/platform/node/grpc_connection.d.ts +3 -3
- package/dist/firestore/src/remote/connection.d.ts +3 -3
- package/dist/firestore/src/remote/datastore.d.ts +2 -1
- package/dist/firestore/src/remote/persistent_stream.d.ts +9 -7
- package/dist/firestore/src/remote/rest_connection.d.ts +4 -4
- package/dist/firestore/test/integration/remote/stream.test.d.ts +2 -2
- package/dist/firestore/test/integration/util/internal_helpers.d.ts +5 -5
- package/dist/firestore/test/unit/remote/rest_connection.test.d.ts +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.esm2017.js +3398 -3344
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +3673 -3624
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +188 -95
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/index.node.mjs +187 -95
- package/dist/index.node.mjs.map +1 -1
- package/dist/index.rn.js +3391 -3337
- package/dist/index.rn.js.map +1 -1
- package/dist/internal.d.ts +34 -20
- package/dist/lite/firestore/src/api/credentials.d.ts +64 -30
- package/dist/lite/firestore/src/api/database.d.ts +2 -1
- package/dist/lite/firestore/src/api.d.ts +2 -1
- package/dist/lite/firestore/src/core/component_provider.d.ts +2 -1
- package/dist/lite/firestore/src/core/firestore_client.d.ts +4 -3
- package/dist/lite/firestore/src/lite-api/components.d.ts +3 -1
- package/dist/lite/firestore/src/lite-api/database.d.ts +4 -2
- package/dist/lite/firestore/src/platform/browser/webchannel_connection.d.ts +1 -1
- package/dist/lite/firestore/src/platform/node/grpc_connection.d.ts +3 -3
- package/dist/lite/firestore/src/remote/connection.d.ts +3 -3
- package/dist/lite/firestore/src/remote/datastore.d.ts +2 -1
- package/dist/lite/firestore/src/remote/persistent_stream.d.ts +9 -7
- package/dist/lite/firestore/src/remote/rest_connection.d.ts +4 -4
- package/dist/lite/firestore/test/integration/remote/stream.test.d.ts +2 -2
- package/dist/lite/firestore/test/integration/util/internal_helpers.d.ts +5 -5
- package/dist/lite/firestore/test/unit/remote/rest_connection.test.d.ts +1 -1
- package/dist/lite/index.browser.esm2017.js +1378 -1364
- package/dist/lite/index.browser.esm2017.js.map +1 -1
- package/dist/lite/index.browser.esm5.js +933 -924
- package/dist/lite/index.browser.esm5.js.map +1 -1
- package/dist/lite/index.node.cjs.js +95 -60
- package/dist/lite/index.node.cjs.js.map +1 -1
- package/dist/lite/index.node.mjs +95 -60
- package/dist/lite/index.node.mjs.map +1 -1
- package/dist/lite/index.rn.esm2017.js +924 -910
- package/dist/lite/index.rn.esm2017.js.map +1 -1
- package/dist/lite/internal.d.ts +14 -13
- package/dist/lite/packages/firestore/dist/lite/index.browser.esm2017.d.ts +150 -149
- package/dist/lite/packages/firestore/src/api/credentials.d.ts +64 -30
- package/dist/lite/packages/firestore/src/api/database.d.ts +2 -1
- package/dist/lite/packages/firestore/src/api.d.ts +2 -1
- package/dist/lite/packages/firestore/src/core/component_provider.d.ts +2 -1
- package/dist/lite/packages/firestore/src/core/firestore_client.d.ts +4 -3
- package/dist/lite/packages/firestore/src/lite-api/components.d.ts +3 -1
- package/dist/lite/packages/firestore/src/lite-api/database.d.ts +4 -2
- package/dist/lite/packages/firestore/src/platform/browser/webchannel_connection.d.ts +1 -1
- package/dist/lite/packages/firestore/src/platform/node/grpc_connection.d.ts +3 -3
- package/dist/lite/packages/firestore/src/remote/connection.d.ts +3 -3
- package/dist/lite/packages/firestore/src/remote/datastore.d.ts +2 -1
- package/dist/lite/packages/firestore/src/remote/persistent_stream.d.ts +9 -7
- package/dist/lite/packages/firestore/src/remote/rest_connection.d.ts +4 -4
- package/dist/lite/packages/firestore/test/integration/remote/stream.test.d.ts +2 -2
- package/dist/lite/packages/firestore/test/integration/util/internal_helpers.d.ts +5 -5
- package/dist/lite/packages/firestore/test/unit/remote/rest_connection.test.d.ts +1 -1
- package/dist/lite/private.d.ts +14 -13
- package/dist/packages/firestore/dist/index.esm2017.d.ts +211 -195
- package/dist/packages/firestore/src/api/credentials.d.ts +64 -30
- package/dist/packages/firestore/src/api/database.d.ts +2 -1
- package/dist/packages/firestore/src/api.d.ts +2 -1
- package/dist/packages/firestore/src/core/component_provider.d.ts +2 -1
- package/dist/packages/firestore/src/core/firestore_client.d.ts +4 -3
- package/dist/packages/firestore/src/lite-api/components.d.ts +3 -1
- package/dist/packages/firestore/src/lite-api/database.d.ts +4 -2
- package/dist/packages/firestore/src/platform/browser/webchannel_connection.d.ts +1 -1
- package/dist/packages/firestore/src/platform/node/grpc_connection.d.ts +3 -3
- package/dist/packages/firestore/src/remote/connection.d.ts +3 -3
- package/dist/packages/firestore/src/remote/datastore.d.ts +2 -1
- package/dist/packages/firestore/src/remote/persistent_stream.d.ts +9 -7
- package/dist/packages/firestore/src/remote/rest_connection.d.ts +4 -4
- package/dist/packages/firestore/test/integration/remote/stream.test.d.ts +2 -2
- package/dist/packages/firestore/test/integration/util/internal_helpers.d.ts +5 -5
- package/dist/packages/firestore/test/unit/remote/rest_connection.test.d.ts +1 -1
- package/dist/private.d.ts +24 -19
- package/package.json +1 -1
package/dist/index.node.cjs.js
CHANGED
|
@@ -19,7 +19,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
19
19
|
var module__default = /*#__PURE__*/_interopDefaultLegacy(module$1);
|
|
20
20
|
|
|
21
21
|
const name = "@firebase/firestore";
|
|
22
|
-
const version$1 = "3.
|
|
22
|
+
const version$1 = "3.4.0-2021111174650";
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* @license
|
|
@@ -72,7 +72,7 @@ User.GOOGLE_CREDENTIALS = new User('google-credentials-uid');
|
|
|
72
72
|
User.FIRST_PARTY = new User('first-party-uid');
|
|
73
73
|
User.MOCK_USER = new User('mock-user');
|
|
74
74
|
|
|
75
|
-
const version = "9.
|
|
75
|
+
const version = "9.6.0-2021111174650";
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
78
|
* @license
|
|
@@ -460,16 +460,15 @@ class OAuthToken {
|
|
|
460
460
|
constructor(value, user) {
|
|
461
461
|
this.user = user;
|
|
462
462
|
this.type = 'OAuth';
|
|
463
|
-
this.
|
|
464
|
-
|
|
465
|
-
this.authHeaders['Authorization'] = `Bearer ${value}`;
|
|
463
|
+
this.headers = new Map();
|
|
464
|
+
this.headers.set('Authorization', `Bearer ${value}`);
|
|
466
465
|
}
|
|
467
466
|
}
|
|
468
467
|
/**
|
|
469
468
|
* A CredentialsProvider that always yields an empty token.
|
|
470
469
|
* @internal
|
|
471
470
|
*/
|
|
472
|
-
class
|
|
471
|
+
class EmptyAuthCredentialsProvider {
|
|
473
472
|
getToken() {
|
|
474
473
|
return Promise.resolve(null);
|
|
475
474
|
}
|
|
@@ -484,7 +483,7 @@ class EmptyCredentialsProvider {
|
|
|
484
483
|
* A CredentialsProvider that always returns a constant token. Used for
|
|
485
484
|
* emulator token mocking.
|
|
486
485
|
*/
|
|
487
|
-
class
|
|
486
|
+
class EmulatorAuthCredentialsProvider {
|
|
488
487
|
constructor(token) {
|
|
489
488
|
this.token = token;
|
|
490
489
|
/**
|
|
@@ -507,7 +506,7 @@ class EmulatorCredentialsProvider {
|
|
|
507
506
|
this.changeListener = null;
|
|
508
507
|
}
|
|
509
508
|
}
|
|
510
|
-
class
|
|
509
|
+
class FirebaseAuthCredentialsProvider {
|
|
511
510
|
constructor(authProvider) {
|
|
512
511
|
this.authProvider = authProvider;
|
|
513
512
|
/** Tracks the current User. */
|
|
@@ -550,7 +549,7 @@ class FirebaseCredentialsProvider {
|
|
|
550
549
|
});
|
|
551
550
|
};
|
|
552
551
|
const registerAuth = (auth) => {
|
|
553
|
-
logDebug('
|
|
552
|
+
logDebug('FirebaseAuthCredentialsProvider', 'Auth detected');
|
|
554
553
|
this.auth = auth;
|
|
555
554
|
this.auth.addAuthTokenListener(this.tokenListener);
|
|
556
555
|
awaitNextToken();
|
|
@@ -567,7 +566,7 @@ class FirebaseCredentialsProvider {
|
|
|
567
566
|
}
|
|
568
567
|
else {
|
|
569
568
|
// If auth is still not available, proceed with `null` user
|
|
570
|
-
logDebug('
|
|
569
|
+
logDebug('FirebaseAuthCredentialsProvider', 'Auth not yet detected');
|
|
571
570
|
nextToken.resolve();
|
|
572
571
|
nextToken = new Deferred();
|
|
573
572
|
}
|
|
@@ -590,7 +589,7 @@ class FirebaseCredentialsProvider {
|
|
|
590
589
|
// outstanding so the response is potentially for a previous user (which
|
|
591
590
|
// user, we can't be sure).
|
|
592
591
|
if (this.tokenCounter !== initialTokenCounter) {
|
|
593
|
-
logDebug('
|
|
592
|
+
logDebug('FirebaseAuthCredentialsProvider', 'getToken aborted due to token change.');
|
|
594
593
|
return this.getToken();
|
|
595
594
|
}
|
|
596
595
|
else {
|
|
@@ -631,25 +630,17 @@ class FirebaseCredentialsProvider {
|
|
|
631
630
|
*/
|
|
632
631
|
class FirstPartyToken {
|
|
633
632
|
constructor(gapi, sessionIndex, iamToken) {
|
|
634
|
-
this.gapi = gapi;
|
|
635
|
-
this.sessionIndex = sessionIndex;
|
|
636
|
-
this.iamToken = iamToken;
|
|
637
633
|
this.type = 'FirstParty';
|
|
638
634
|
this.user = User.FIRST_PARTY;
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
const
|
|
642
|
-
'X-Goog-AuthUser': this.sessionIndex
|
|
643
|
-
};
|
|
644
|
-
// Use array notation to prevent minification
|
|
645
|
-
const authHeader = this.gapi['auth']['getAuthHeaderValueForFirstParty']([]);
|
|
635
|
+
this.headers = new Map();
|
|
636
|
+
this.headers.set('X-Goog-AuthUser', sessionIndex);
|
|
637
|
+
const authHeader = gapi['auth']['getAuthHeaderValueForFirstParty']([]);
|
|
646
638
|
if (authHeader) {
|
|
647
|
-
headers
|
|
639
|
+
this.headers.set('Authorization', authHeader);
|
|
648
640
|
}
|
|
649
|
-
if (
|
|
650
|
-
headers
|
|
641
|
+
if (iamToken) {
|
|
642
|
+
this.headers.set('X-Goog-Iam-Authorization-Token', iamToken);
|
|
651
643
|
}
|
|
652
|
-
return headers;
|
|
653
644
|
}
|
|
654
645
|
}
|
|
655
646
|
/*
|
|
@@ -657,7 +648,7 @@ class FirstPartyToken {
|
|
|
657
648
|
* to authenticate the user, using technique that is only available
|
|
658
649
|
* to applications hosted by Google.
|
|
659
650
|
*/
|
|
660
|
-
class
|
|
651
|
+
class FirstPartyAuthCredentialsProvider {
|
|
661
652
|
constructor(gapi, sessionIndex, iamToken) {
|
|
662
653
|
this.gapi = gapi;
|
|
663
654
|
this.sessionIndex = sessionIndex;
|
|
@@ -673,13 +664,97 @@ class FirstPartyCredentialsProvider {
|
|
|
673
664
|
shutdown() { }
|
|
674
665
|
invalidateToken() { }
|
|
675
666
|
}
|
|
667
|
+
class AppCheckToken {
|
|
668
|
+
constructor(value) {
|
|
669
|
+
this.value = value;
|
|
670
|
+
this.type = 'AppCheck';
|
|
671
|
+
this.headers = new Map();
|
|
672
|
+
if (value && value.length > 0) {
|
|
673
|
+
this.headers.set('x-firebase-appcheck', this.value);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
class FirebaseAppCheckTokenProvider {
|
|
678
|
+
constructor(appCheckProvider) {
|
|
679
|
+
this.appCheckProvider = appCheckProvider;
|
|
680
|
+
this.forceRefresh = false;
|
|
681
|
+
this.appCheck = null;
|
|
682
|
+
}
|
|
683
|
+
start(asyncQueue, changeListener) {
|
|
684
|
+
const onTokenChanged = tokenResult => {
|
|
685
|
+
if (tokenResult.error != null) {
|
|
686
|
+
logDebug('FirebaseAppCheckTokenProvider', `Error getting App Check token; using placeholder token instead. Error: ${tokenResult.error.message}`);
|
|
687
|
+
}
|
|
688
|
+
return changeListener(tokenResult.token);
|
|
689
|
+
};
|
|
690
|
+
this.tokenListener = (tokenResult) => {
|
|
691
|
+
asyncQueue.enqueueRetryable(() => onTokenChanged(tokenResult));
|
|
692
|
+
};
|
|
693
|
+
const registerAppCheck = (appCheck) => {
|
|
694
|
+
logDebug('FirebaseAppCheckTokenProvider', 'AppCheck detected');
|
|
695
|
+
this.appCheck = appCheck;
|
|
696
|
+
this.appCheck.addTokenListener(this.tokenListener);
|
|
697
|
+
};
|
|
698
|
+
this.appCheckProvider.onInit(appCheck => registerAppCheck(appCheck));
|
|
699
|
+
// Our users can initialize AppCheck after Firestore, so we give it
|
|
700
|
+
// a chance to register itself with the component framework.
|
|
701
|
+
setTimeout(() => {
|
|
702
|
+
if (!this.appCheck) {
|
|
703
|
+
const appCheck = this.appCheckProvider.getImmediate({ optional: true });
|
|
704
|
+
if (appCheck) {
|
|
705
|
+
registerAppCheck(appCheck);
|
|
706
|
+
}
|
|
707
|
+
else {
|
|
708
|
+
// If AppCheck is still not available, proceed without it.
|
|
709
|
+
logDebug('FirebaseAppCheckTokenProvider', 'AppCheck not yet detected');
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}, 0);
|
|
713
|
+
}
|
|
714
|
+
getToken() {
|
|
715
|
+
const forceRefresh = this.forceRefresh;
|
|
716
|
+
this.forceRefresh = false;
|
|
717
|
+
if (!this.appCheck) {
|
|
718
|
+
return Promise.resolve(null);
|
|
719
|
+
}
|
|
720
|
+
return this.appCheck.getToken(forceRefresh).then(tokenResult => {
|
|
721
|
+
if (tokenResult) {
|
|
722
|
+
hardAssert(typeof tokenResult.token === 'string');
|
|
723
|
+
return new AppCheckToken(tokenResult.token);
|
|
724
|
+
}
|
|
725
|
+
else {
|
|
726
|
+
return null;
|
|
727
|
+
}
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
invalidateToken() {
|
|
731
|
+
this.forceRefresh = true;
|
|
732
|
+
}
|
|
733
|
+
shutdown() {
|
|
734
|
+
if (this.appCheck) {
|
|
735
|
+
this.appCheck.removeTokenListener(this.tokenListener);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* An AppCheck token provider that always yields an empty token.
|
|
741
|
+
* @internal
|
|
742
|
+
*/
|
|
743
|
+
class EmptyAppCheckTokenProvider {
|
|
744
|
+
getToken() {
|
|
745
|
+
return Promise.resolve(new AppCheckToken(''));
|
|
746
|
+
}
|
|
747
|
+
invalidateToken() { }
|
|
748
|
+
start(asyncQueue, changeListener) { }
|
|
749
|
+
shutdown() { }
|
|
750
|
+
}
|
|
676
751
|
/**
|
|
677
752
|
* Builds a CredentialsProvider depending on the type of
|
|
678
753
|
* the credentials passed in.
|
|
679
754
|
*/
|
|
680
|
-
function
|
|
755
|
+
function makeAuthCredentialsProvider(credentials) {
|
|
681
756
|
if (!credentials) {
|
|
682
|
-
return new
|
|
757
|
+
return new EmptyAuthCredentialsProvider();
|
|
683
758
|
}
|
|
684
759
|
switch (credentials['type']) {
|
|
685
760
|
case 'gapi':
|
|
@@ -689,11 +764,11 @@ function makeCredentialsProvider(credentials) {
|
|
|
689
764
|
client !== null &&
|
|
690
765
|
client['auth'] &&
|
|
691
766
|
client['auth']['getAuthHeaderValueForFirstParty']));
|
|
692
|
-
return new
|
|
767
|
+
return new FirstPartyAuthCredentialsProvider(client, credentials['sessionIndex'] || '0', credentials['iamToken'] || null);
|
|
693
768
|
case 'provider':
|
|
694
769
|
return credentials['client'];
|
|
695
770
|
default:
|
|
696
|
-
throw new FirestoreError(Code.INVALID_ARGUMENT, '
|
|
771
|
+
throw new FirestoreError(Code.INVALID_ARGUMENT, 'makeAuthCredentialsProvider failed due to invalid credential type');
|
|
697
772
|
}
|
|
698
773
|
}
|
|
699
774
|
|
|
@@ -14252,15 +14327,14 @@ const require$1 = module__default["default"].createRequire(new (require('url').U
|
|
|
14252
14327
|
const { version: grpcVersion } = require$1('@grpc/grpc-js/package.json');
|
|
14253
14328
|
const LOG_TAG$9 = 'Connection';
|
|
14254
14329
|
const X_GOOG_API_CLIENT_VALUE = `gl-node/${process.versions.node} fire/${SDK_VERSION} grpc/${grpcVersion}`;
|
|
14255
|
-
function createMetadata(databasePath,
|
|
14256
|
-
hardAssert(
|
|
14330
|
+
function createMetadata(databasePath, authToken, appCheckToken, appId) {
|
|
14331
|
+
hardAssert(authToken === null || authToken.type === 'OAuth');
|
|
14257
14332
|
const metadata = new grpcJs.Metadata();
|
|
14258
|
-
if (
|
|
14259
|
-
|
|
14260
|
-
|
|
14261
|
-
|
|
14262
|
-
|
|
14263
|
-
}
|
|
14333
|
+
if (authToken) {
|
|
14334
|
+
authToken.headers.forEach((value, key) => metadata.set(key, value));
|
|
14335
|
+
}
|
|
14336
|
+
if (appCheckToken) {
|
|
14337
|
+
appCheckToken.headers.forEach((value, key) => metadata.set(key, value));
|
|
14264
14338
|
}
|
|
14265
14339
|
if (appId) {
|
|
14266
14340
|
metadata.set('X-Firebase-GMPID', appId);
|
|
@@ -14293,9 +14367,9 @@ class GrpcConnection {
|
|
|
14293
14367
|
}
|
|
14294
14368
|
return this.cachedStub;
|
|
14295
14369
|
}
|
|
14296
|
-
invokeRPC(rpcName, path, request,
|
|
14370
|
+
invokeRPC(rpcName, path, request, authToken, appCheckToken) {
|
|
14297
14371
|
const stub = this.ensureActiveStub();
|
|
14298
|
-
const metadata = createMetadata(this.databasePath,
|
|
14372
|
+
const metadata = createMetadata(this.databasePath, authToken, appCheckToken, this.databaseInfo.appId);
|
|
14299
14373
|
const jsonRequest = Object.assign({ database: this.databasePath }, request);
|
|
14300
14374
|
return nodePromise((callback) => {
|
|
14301
14375
|
logDebug(LOG_TAG$9, `RPC '${rpcName}' invoked with request:`, request);
|
|
@@ -14311,12 +14385,12 @@ class GrpcConnection {
|
|
|
14311
14385
|
});
|
|
14312
14386
|
});
|
|
14313
14387
|
}
|
|
14314
|
-
invokeStreamingRPC(rpcName, path, request,
|
|
14388
|
+
invokeStreamingRPC(rpcName, path, request, authToken, appCheckToken) {
|
|
14315
14389
|
const results = [];
|
|
14316
14390
|
const responseDeferred = new Deferred();
|
|
14317
14391
|
logDebug(LOG_TAG$9, `RPC '${rpcName}' invoked (streaming) with request:`, request);
|
|
14318
14392
|
const stub = this.ensureActiveStub();
|
|
14319
|
-
const metadata = createMetadata(this.databasePath,
|
|
14393
|
+
const metadata = createMetadata(this.databasePath, authToken, appCheckToken, this.databaseInfo.appId);
|
|
14320
14394
|
const jsonRequest = Object.assign(Object.assign({}, request), { database: this.databasePath });
|
|
14321
14395
|
const stream = stub[rpcName](jsonRequest, metadata);
|
|
14322
14396
|
stream.on('data', (response) => {
|
|
@@ -14335,9 +14409,9 @@ class GrpcConnection {
|
|
|
14335
14409
|
return responseDeferred.promise;
|
|
14336
14410
|
}
|
|
14337
14411
|
// TODO(mikelehen): This "method" is a monster. Should be refactored.
|
|
14338
|
-
openStream(rpcName,
|
|
14412
|
+
openStream(rpcName, authToken, appCheckToken) {
|
|
14339
14413
|
const stub = this.ensureActiveStub();
|
|
14340
|
-
const metadata = createMetadata(this.databasePath,
|
|
14414
|
+
const metadata = createMetadata(this.databasePath, authToken, appCheckToken, this.databaseInfo.appId);
|
|
14341
14415
|
const grpcStream = stub[rpcName](metadata);
|
|
14342
14416
|
let closed = false;
|
|
14343
14417
|
const close = (err) => {
|
|
@@ -14721,12 +14795,13 @@ const HEALTHY_TIMEOUT_MS = 10 * 1000;
|
|
|
14721
14795
|
* ListenerType: The type of the listener that will be used for callbacks
|
|
14722
14796
|
*/
|
|
14723
14797
|
class PersistentStream {
|
|
14724
|
-
constructor(queue, connectionTimerId, idleTimerId, healthTimerId, connection,
|
|
14798
|
+
constructor(queue, connectionTimerId, idleTimerId, healthTimerId, connection, authCredentialsProvider, appCheckCredentialsProvider, listener) {
|
|
14725
14799
|
this.queue = queue;
|
|
14726
14800
|
this.idleTimerId = idleTimerId;
|
|
14727
14801
|
this.healthTimerId = healthTimerId;
|
|
14728
14802
|
this.connection = connection;
|
|
14729
|
-
this.
|
|
14803
|
+
this.authCredentialsProvider = authCredentialsProvider;
|
|
14804
|
+
this.appCheckCredentialsProvider = appCheckCredentialsProvider;
|
|
14730
14805
|
this.listener = listener;
|
|
14731
14806
|
this.state = 0 /* Initial */;
|
|
14732
14807
|
/**
|
|
@@ -14881,7 +14956,8 @@ class PersistentStream {
|
|
|
14881
14956
|
// fail, however. In this case, we should get a Code.UNAUTHENTICATED error
|
|
14882
14957
|
// before we received the first message and we need to invalidate the token
|
|
14883
14958
|
// to ensure that we fetch a new token.
|
|
14884
|
-
this.
|
|
14959
|
+
this.authCredentialsProvider.invalidateToken();
|
|
14960
|
+
this.appCheckCredentialsProvider.invalidateToken();
|
|
14885
14961
|
}
|
|
14886
14962
|
// Clean up the underlying stream because we are no longer interested in events.
|
|
14887
14963
|
if (this.stream !== null) {
|
|
@@ -14905,7 +14981,10 @@ class PersistentStream {
|
|
|
14905
14981
|
const dispatchIfNotClosed = this.getCloseGuardedDispatcher(this.closeCount);
|
|
14906
14982
|
// TODO(mikelehen): Just use dispatchIfNotClosed, but see TODO below.
|
|
14907
14983
|
const closeCount = this.closeCount;
|
|
14908
|
-
|
|
14984
|
+
Promise.all([
|
|
14985
|
+
this.authCredentialsProvider.getToken(),
|
|
14986
|
+
this.appCheckCredentialsProvider.getToken()
|
|
14987
|
+
]).then(([authToken, appCheckToken]) => {
|
|
14909
14988
|
// Stream can be stopped while waiting for authentication.
|
|
14910
14989
|
// TODO(mikelehen): We really should just use dispatchIfNotClosed
|
|
14911
14990
|
// and let this dispatch onto the queue, but that opened a spec test can
|
|
@@ -14914,7 +14993,7 @@ class PersistentStream {
|
|
|
14914
14993
|
// Normally we'd have to schedule the callback on the AsyncQueue.
|
|
14915
14994
|
// However, the following calls are safe to be called outside the
|
|
14916
14995
|
// AsyncQueue since they don't chain asynchronous calls
|
|
14917
|
-
this.startStream(
|
|
14996
|
+
this.startStream(authToken, appCheckToken);
|
|
14918
14997
|
}
|
|
14919
14998
|
}, (error) => {
|
|
14920
14999
|
dispatchIfNotClosed(() => {
|
|
@@ -14923,9 +15002,9 @@ class PersistentStream {
|
|
|
14923
15002
|
});
|
|
14924
15003
|
});
|
|
14925
15004
|
}
|
|
14926
|
-
startStream(
|
|
15005
|
+
startStream(authToken, appCheckToken) {
|
|
14927
15006
|
const dispatchIfNotClosed = this.getCloseGuardedDispatcher(this.closeCount);
|
|
14928
|
-
this.stream = this.startRpc(
|
|
15007
|
+
this.stream = this.startRpc(authToken, appCheckToken);
|
|
14929
15008
|
this.stream.onOpen(() => {
|
|
14930
15009
|
dispatchIfNotClosed(() => {
|
|
14931
15010
|
this.state = 2 /* Open */;
|
|
@@ -14994,12 +15073,12 @@ class PersistentStream {
|
|
|
14994
15073
|
* sent from the server for ListenResponses.
|
|
14995
15074
|
*/
|
|
14996
15075
|
class PersistentListenStream extends PersistentStream {
|
|
14997
|
-
constructor(queue, connection,
|
|
14998
|
-
super(queue, "listen_stream_connection_backoff" /* ListenStreamConnectionBackoff */, "listen_stream_idle" /* ListenStreamIdle */, "health_check_timeout" /* HealthCheckTimeout */, connection,
|
|
15076
|
+
constructor(queue, connection, authCredentials, appCheckCredentials, serializer, listener) {
|
|
15077
|
+
super(queue, "listen_stream_connection_backoff" /* ListenStreamConnectionBackoff */, "listen_stream_idle" /* ListenStreamIdle */, "health_check_timeout" /* HealthCheckTimeout */, connection, authCredentials, appCheckCredentials, listener);
|
|
14999
15078
|
this.serializer = serializer;
|
|
15000
15079
|
}
|
|
15001
|
-
startRpc(
|
|
15002
|
-
return this.connection.openStream('Listen',
|
|
15080
|
+
startRpc(authToken, appCheckToken) {
|
|
15081
|
+
return this.connection.openStream('Listen', authToken, appCheckToken);
|
|
15003
15082
|
}
|
|
15004
15083
|
onMessage(watchChangeProto) {
|
|
15005
15084
|
// A successful response means the stream is healthy
|
|
@@ -15053,8 +15132,8 @@ class PersistentListenStream extends PersistentStream {
|
|
|
15053
15132
|
* TODO(b/33271235): Use proto types
|
|
15054
15133
|
*/
|
|
15055
15134
|
class PersistentWriteStream extends PersistentStream {
|
|
15056
|
-
constructor(queue, connection,
|
|
15057
|
-
super(queue, "write_stream_connection_backoff" /* WriteStreamConnectionBackoff */, "write_stream_idle" /* WriteStreamIdle */, "health_check_timeout" /* HealthCheckTimeout */, connection,
|
|
15135
|
+
constructor(queue, connection, authCredentials, appCheckCredentials, serializer, listener) {
|
|
15136
|
+
super(queue, "write_stream_connection_backoff" /* WriteStreamConnectionBackoff */, "write_stream_idle" /* WriteStreamIdle */, "health_check_timeout" /* HealthCheckTimeout */, connection, authCredentials, appCheckCredentials, listener);
|
|
15058
15137
|
this.serializer = serializer;
|
|
15059
15138
|
this.handshakeComplete_ = false;
|
|
15060
15139
|
}
|
|
@@ -15076,8 +15155,8 @@ class PersistentWriteStream extends PersistentStream {
|
|
|
15076
15155
|
this.writeMutations([]);
|
|
15077
15156
|
}
|
|
15078
15157
|
}
|
|
15079
|
-
startRpc(
|
|
15080
|
-
return this.connection.openStream('Write',
|
|
15158
|
+
startRpc(authToken, appCheckToken) {
|
|
15159
|
+
return this.connection.openStream('Write', authToken, appCheckToken);
|
|
15081
15160
|
}
|
|
15082
15161
|
onMessage(responseProto) {
|
|
15083
15162
|
// Always capture the last stream token.
|
|
@@ -15149,9 +15228,10 @@ class Datastore {
|
|
|
15149
15228
|
* consumption.
|
|
15150
15229
|
*/
|
|
15151
15230
|
class DatastoreImpl extends Datastore {
|
|
15152
|
-
constructor(
|
|
15231
|
+
constructor(authCredentials, appCheckCredentials, connection, serializer) {
|
|
15153
15232
|
super();
|
|
15154
|
-
this.
|
|
15233
|
+
this.authCredentials = authCredentials;
|
|
15234
|
+
this.appCheckCredentials = appCheckCredentials;
|
|
15155
15235
|
this.connection = connection;
|
|
15156
15236
|
this.serializer = serializer;
|
|
15157
15237
|
this.terminated = false;
|
|
@@ -15161,18 +15241,21 @@ class DatastoreImpl extends Datastore {
|
|
|
15161
15241
|
throw new FirestoreError(Code.FAILED_PRECONDITION, 'The client has already been terminated.');
|
|
15162
15242
|
}
|
|
15163
15243
|
}
|
|
15164
|
-
/**
|
|
15244
|
+
/** Invokes the provided RPC with auth and AppCheck tokens. */
|
|
15165
15245
|
invokeRPC(rpcName, path, request) {
|
|
15166
15246
|
this.verifyInitialized();
|
|
15167
|
-
return
|
|
15168
|
-
.getToken()
|
|
15169
|
-
.
|
|
15170
|
-
|
|
15247
|
+
return Promise.all([
|
|
15248
|
+
this.authCredentials.getToken(),
|
|
15249
|
+
this.appCheckCredentials.getToken()
|
|
15250
|
+
])
|
|
15251
|
+
.then(([authToken, appCheckToken]) => {
|
|
15252
|
+
return this.connection.invokeRPC(rpcName, path, request, authToken, appCheckToken);
|
|
15171
15253
|
})
|
|
15172
15254
|
.catch((error) => {
|
|
15173
15255
|
if (error.name === 'FirebaseError') {
|
|
15174
15256
|
if (error.code === Code.UNAUTHENTICATED) {
|
|
15175
|
-
this.
|
|
15257
|
+
this.authCredentials.invalidateToken();
|
|
15258
|
+
this.appCheckCredentials.invalidateToken();
|
|
15176
15259
|
}
|
|
15177
15260
|
throw error;
|
|
15178
15261
|
}
|
|
@@ -15181,18 +15264,21 @@ class DatastoreImpl extends Datastore {
|
|
|
15181
15264
|
}
|
|
15182
15265
|
});
|
|
15183
15266
|
}
|
|
15184
|
-
/**
|
|
15267
|
+
/** Invokes the provided RPC with streamed results with auth and AppCheck tokens. */
|
|
15185
15268
|
invokeStreamingRPC(rpcName, path, request) {
|
|
15186
15269
|
this.verifyInitialized();
|
|
15187
|
-
return
|
|
15188
|
-
.getToken()
|
|
15189
|
-
.
|
|
15190
|
-
|
|
15270
|
+
return Promise.all([
|
|
15271
|
+
this.authCredentials.getToken(),
|
|
15272
|
+
this.appCheckCredentials.getToken()
|
|
15273
|
+
])
|
|
15274
|
+
.then(([authToken, appCheckToken]) => {
|
|
15275
|
+
return this.connection.invokeStreamingRPC(rpcName, path, request, authToken, appCheckToken);
|
|
15191
15276
|
})
|
|
15192
15277
|
.catch((error) => {
|
|
15193
15278
|
if (error.name === 'FirebaseError') {
|
|
15194
15279
|
if (error.code === Code.UNAUTHENTICATED) {
|
|
15195
|
-
this.
|
|
15280
|
+
this.authCredentials.invalidateToken();
|
|
15281
|
+
this.appCheckCredentials.invalidateToken();
|
|
15196
15282
|
}
|
|
15197
15283
|
throw error;
|
|
15198
15284
|
}
|
|
@@ -15207,8 +15293,8 @@ class DatastoreImpl extends Datastore {
|
|
|
15207
15293
|
}
|
|
15208
15294
|
// TODO(firestorexp): Make sure there is only one Datastore instance per
|
|
15209
15295
|
// firestore-exp client.
|
|
15210
|
-
function newDatastore(
|
|
15211
|
-
return new DatastoreImpl(
|
|
15296
|
+
function newDatastore(authCredentials, appCheckCredentials, connection, serializer) {
|
|
15297
|
+
return new DatastoreImpl(authCredentials, appCheckCredentials, connection, serializer);
|
|
15212
15298
|
}
|
|
15213
15299
|
async function invokeCommitRpc(datastore, mutations) {
|
|
15214
15300
|
const datastoreImpl = debugCast(datastore);
|
|
@@ -15241,12 +15327,12 @@ async function invokeBatchGetDocumentsRpc(datastore, keys) {
|
|
|
15241
15327
|
function newPersistentWriteStream(datastore, queue, listener) {
|
|
15242
15328
|
const datastoreImpl = debugCast(datastore);
|
|
15243
15329
|
datastoreImpl.verifyInitialized();
|
|
15244
|
-
return new PersistentWriteStream(queue, datastoreImpl.connection, datastoreImpl.
|
|
15330
|
+
return new PersistentWriteStream(queue, datastoreImpl.connection, datastoreImpl.authCredentials, datastoreImpl.appCheckCredentials, datastoreImpl.serializer, listener);
|
|
15245
15331
|
}
|
|
15246
15332
|
function newPersistentWatchStream(datastore, queue, listener) {
|
|
15247
15333
|
const datastoreImpl = debugCast(datastore);
|
|
15248
15334
|
datastoreImpl.verifyInitialized();
|
|
15249
|
-
return new PersistentListenStream(queue, datastoreImpl.connection, datastoreImpl.
|
|
15335
|
+
return new PersistentListenStream(queue, datastoreImpl.connection, datastoreImpl.authCredentials, datastoreImpl.appCheckCredentials, datastoreImpl.serializer, listener);
|
|
15250
15336
|
}
|
|
15251
15337
|
|
|
15252
15338
|
/**
|
|
@@ -18359,7 +18445,7 @@ class OnlineComponentProvider {
|
|
|
18359
18445
|
createDatastore(cfg) {
|
|
18360
18446
|
const serializer = newSerializer(cfg.databaseInfo.databaseId);
|
|
18361
18447
|
const connection = newConnection(cfg.databaseInfo);
|
|
18362
|
-
return newDatastore(cfg.
|
|
18448
|
+
return newDatastore(cfg.authCredentials, cfg.appCheckCredentials, connection, serializer);
|
|
18363
18449
|
}
|
|
18364
18450
|
createRemoteStore(cfg) {
|
|
18365
18451
|
return newRemoteStore(this.localStore, this.datastore, cfg.asyncQueue, onlineState => syncEngineApplyOnlineStateChange(this.syncEngine, onlineState, 0 /* RemoteStore */), newConnectivityMonitor());
|
|
@@ -19117,7 +19203,7 @@ const MAX_CONCURRENT_LIMBO_RESOLUTIONS = 100;
|
|
|
19117
19203
|
* async queue that is shared by all of the other components in the system.
|
|
19118
19204
|
*/
|
|
19119
19205
|
class FirestoreClient {
|
|
19120
|
-
constructor(
|
|
19206
|
+
constructor(authCredentials, appCheckCredentials,
|
|
19121
19207
|
/**
|
|
19122
19208
|
* Asynchronous queue responsible for all of our internal processing. When
|
|
19123
19209
|
* we get incoming work from the user (via public API) or the network
|
|
@@ -19127,30 +19213,34 @@ class FirestoreClient {
|
|
|
19127
19213
|
* an async I/O to complete).
|
|
19128
19214
|
*/
|
|
19129
19215
|
asyncQueue, databaseInfo) {
|
|
19130
|
-
this.
|
|
19216
|
+
this.authCredentials = authCredentials;
|
|
19217
|
+
this.appCheckCredentials = appCheckCredentials;
|
|
19131
19218
|
this.asyncQueue = asyncQueue;
|
|
19132
19219
|
this.databaseInfo = databaseInfo;
|
|
19133
19220
|
this.user = User.UNAUTHENTICATED;
|
|
19134
19221
|
this.clientId = AutoId.newId();
|
|
19135
|
-
this.
|
|
19136
|
-
this.
|
|
19222
|
+
this.authCredentialListener = () => Promise.resolve();
|
|
19223
|
+
this.authCredentials.start(asyncQueue, async (user) => {
|
|
19137
19224
|
logDebug(LOG_TAG$2, 'Received user=', user.uid);
|
|
19138
|
-
await this.
|
|
19225
|
+
await this.authCredentialListener(user);
|
|
19139
19226
|
this.user = user;
|
|
19140
19227
|
});
|
|
19228
|
+
// Register an empty credentials change listener to activate token refresh.
|
|
19229
|
+
this.appCheckCredentials.start(asyncQueue, () => Promise.resolve());
|
|
19141
19230
|
}
|
|
19142
19231
|
async getConfiguration() {
|
|
19143
19232
|
return {
|
|
19144
19233
|
asyncQueue: this.asyncQueue,
|
|
19145
19234
|
databaseInfo: this.databaseInfo,
|
|
19146
19235
|
clientId: this.clientId,
|
|
19147
|
-
|
|
19236
|
+
authCredentials: this.authCredentials,
|
|
19237
|
+
appCheckCredentials: this.appCheckCredentials,
|
|
19148
19238
|
initialUser: this.user,
|
|
19149
19239
|
maxConcurrentLimboResolutions: MAX_CONCURRENT_LIMBO_RESOLUTIONS
|
|
19150
19240
|
};
|
|
19151
19241
|
}
|
|
19152
19242
|
setCredentialChangeListener(listener) {
|
|
19153
|
-
this.
|
|
19243
|
+
this.authCredentialListener = listener;
|
|
19154
19244
|
}
|
|
19155
19245
|
/**
|
|
19156
19246
|
* Checks that the client has not been terminated. Ensures that other methods on
|
|
@@ -19175,7 +19265,8 @@ class FirestoreClient {
|
|
|
19175
19265
|
// The credentials provider must be terminated after shutting down the
|
|
19176
19266
|
// RemoteStore as it will prevent the RemoteStore from retrieving auth
|
|
19177
19267
|
// tokens.
|
|
19178
|
-
this.
|
|
19268
|
+
this.authCredentials.shutdown();
|
|
19269
|
+
this.appCheckCredentials.shutdown();
|
|
19179
19270
|
deferred.resolve();
|
|
19180
19271
|
}
|
|
19181
19272
|
catch (e) {
|
|
@@ -19698,8 +19789,9 @@ class FirestoreSettingsImpl {
|
|
|
19698
19789
|
*/
|
|
19699
19790
|
class Firestore$1 {
|
|
19700
19791
|
/** @hideconstructor */
|
|
19701
|
-
constructor(databaseIdOrApp,
|
|
19702
|
-
this.
|
|
19792
|
+
constructor(databaseIdOrApp, _authCredentials, _appCheckCredentials) {
|
|
19793
|
+
this._authCredentials = _authCredentials;
|
|
19794
|
+
this._appCheckCredentials = _appCheckCredentials;
|
|
19703
19795
|
/**
|
|
19704
19796
|
* Whether it's a Firestore or Firestore Lite instance.
|
|
19705
19797
|
*/
|
|
@@ -19740,7 +19832,7 @@ class Firestore$1 {
|
|
|
19740
19832
|
}
|
|
19741
19833
|
this._settings = new FirestoreSettingsImpl(settings);
|
|
19742
19834
|
if (settings.credentials !== undefined) {
|
|
19743
|
-
this.
|
|
19835
|
+
this._authCredentials = makeAuthCredentialsProvider(settings.credentials);
|
|
19744
19836
|
}
|
|
19745
19837
|
}
|
|
19746
19838
|
_getSettings() {
|
|
@@ -19821,7 +19913,7 @@ function connectFirestoreEmulator(firestore, host, port, options = {}) {
|
|
|
19821
19913
|
}
|
|
19822
19914
|
user = new User(uid);
|
|
19823
19915
|
}
|
|
19824
|
-
firestore.
|
|
19916
|
+
firestore._authCredentials = new EmulatorAuthCredentialsProvider(new OAuthToken(token, user));
|
|
19825
19917
|
}
|
|
19826
19918
|
}
|
|
19827
19919
|
|
|
@@ -20450,8 +20542,8 @@ const CACHE_SIZE_UNLIMITED = LRU_COLLECTION_DISABLED;
|
|
|
20450
20542
|
*/
|
|
20451
20543
|
class Firestore extends Firestore$1 {
|
|
20452
20544
|
/** @hideconstructor */
|
|
20453
|
-
constructor(databaseIdOrApp,
|
|
20454
|
-
super(databaseIdOrApp,
|
|
20545
|
+
constructor(databaseIdOrApp, authCredentialsProvider, appCheckCredentialsProvider) {
|
|
20546
|
+
super(databaseIdOrApp, authCredentialsProvider, appCheckCredentialsProvider);
|
|
20455
20547
|
/**
|
|
20456
20548
|
* Whether it's a {@link Firestore} or Firestore Lite instance.
|
|
20457
20549
|
*/
|
|
@@ -20528,7 +20620,7 @@ function configureFirestore(firestore) {
|
|
|
20528
20620
|
var _a;
|
|
20529
20621
|
const settings = firestore._freezeSettings();
|
|
20530
20622
|
const databaseInfo = makeDatabaseInfo(firestore._databaseId, ((_a = firestore._app) === null || _a === void 0 ? void 0 : _a.options.appId) || '', firestore._persistenceKey, settings);
|
|
20531
|
-
firestore._firestoreClient = new FirestoreClient(firestore.
|
|
20623
|
+
firestore._firestoreClient = new FirestoreClient(firestore._authCredentials, firestore._appCheckCredentials, firestore._queue, databaseInfo);
|
|
20532
20624
|
}
|
|
20533
20625
|
/**
|
|
20534
20626
|
* Attempts to enable persistent storage, if possible.
|
|
@@ -20823,7 +20915,7 @@ function registerFirestore(variant, useFetchStreams = true) {
|
|
|
20823
20915
|
setSDKVersion(app.SDK_VERSION);
|
|
20824
20916
|
app._registerComponent(new component.Component('firestore', (container, { options: settings }) => {
|
|
20825
20917
|
const app = container.getProvider('app').getImmediate();
|
|
20826
|
-
const firestoreInstance = new Firestore(app, new
|
|
20918
|
+
const firestoreInstance = new Firestore(app, new FirebaseAuthCredentialsProvider(container.getProvider('auth-internal')), new FirebaseAppCheckTokenProvider(container.getProvider('app-check-internal')));
|
|
20827
20919
|
settings = Object.assign({ useFetchStreams }, settings);
|
|
20828
20920
|
firestoreInstance._setSettings(settings);
|
|
20829
20921
|
return firestoreInstance;
|
|
@@ -23514,7 +23606,8 @@ exports.Transaction = Transaction;
|
|
|
23514
23606
|
exports.WriteBatch = WriteBatch;
|
|
23515
23607
|
exports._DatabaseId = DatabaseId;
|
|
23516
23608
|
exports._DocumentKey = DocumentKey;
|
|
23517
|
-
exports.
|
|
23609
|
+
exports._EmptyAppCheckTokenProvider = EmptyAppCheckTokenProvider;
|
|
23610
|
+
exports._EmptyAuthCredentialsProvider = EmptyAuthCredentialsProvider;
|
|
23518
23611
|
exports._FieldPath = FieldPath$1;
|
|
23519
23612
|
exports._cast = cast;
|
|
23520
23613
|
exports._debugAssert = debugAssert;
|