@firebase/app-check 0.5.12 → 0.5.13-canary.0a112bd2a
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 +10 -0
- package/dist/esm/index.esm.js +84 -34
- package/dist/esm/index.esm.js.map +1 -1
- package/dist/esm/index.esm2017.js +62 -12
- package/dist/esm/index.esm2017.js.map +1 -1
- package/dist/esm/src/indexeddb.d.ts +1 -1
- package/dist/esm/src/storage.d.ts +1 -1
- package/dist/esm/src/types.d.ts +1 -0
- package/dist/index.cjs.js +84 -34
- package/dist/index.cjs.js.map +1 -1
- package/dist/src/indexeddb.d.ts +1 -1
- package/dist/src/storage.d.ts +1 -1
- package/dist/src/types.d.ts +1 -0
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @firebase/app-check
|
|
2
2
|
|
|
3
|
+
## 0.5.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`b3951c6e4`](https://github.com/firebase/firebase-js-sdk/commit/b3951c6e42559d8aa82711b71440f4adcdae3b56) [#6617](https://github.com/firebase/firebase-js-sdk/pull/6617) (fixes [#6373](https://github.com/firebase/firebase-js-sdk/issues/6373)) - Fix timer issues in App Check that caused the token to fail to refresh after the token expired, or caused rapid repeated requests attempting to do so.
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`fdd4ab464`](https://github.com/firebase/firebase-js-sdk/commit/fdd4ab464b59a107bdcc195df3f01e32efd89ed4)]:
|
|
10
|
+
- @firebase/util@1.7.0
|
|
11
|
+
- @firebase/component@0.5.18
|
|
12
|
+
|
|
3
13
|
## 0.5.12
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/dist/esm/index.esm.js
CHANGED
|
@@ -775,15 +775,30 @@ function getToken$2(appCheck, forceRefresh) {
|
|
|
775
775
|
state = getState(app);
|
|
776
776
|
token = state.token;
|
|
777
777
|
error = undefined;
|
|
778
|
-
|
|
778
|
+
/**
|
|
779
|
+
* If an invalid token was found in memory, clear token from
|
|
780
|
+
* memory and unset the local variable `token`.
|
|
781
|
+
*/
|
|
782
|
+
if (token && !isValid(token)) {
|
|
783
|
+
setState(app, __assign(__assign({}, state), { token: undefined }));
|
|
784
|
+
token = undefined;
|
|
785
|
+
}
|
|
786
|
+
if (!!token) return [3 /*break*/, 4];
|
|
779
787
|
return [4 /*yield*/, state.cachedTokenPromise];
|
|
780
788
|
case 1:
|
|
781
789
|
cachedToken = _e.sent();
|
|
782
|
-
if (cachedToken
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
case 2:
|
|
790
|
+
if (!cachedToken) return [3 /*break*/, 4];
|
|
791
|
+
if (!isValid(cachedToken)) return [3 /*break*/, 2];
|
|
792
|
+
token = cachedToken;
|
|
793
|
+
return [3 /*break*/, 4];
|
|
794
|
+
case 2:
|
|
795
|
+
// If there was an invalid token in the indexedDB cache, clear it.
|
|
796
|
+
return [4 /*yield*/, writeTokenToStorage(app, undefined)];
|
|
797
|
+
case 3:
|
|
798
|
+
// If there was an invalid token in the indexedDB cache, clear it.
|
|
799
|
+
_e.sent();
|
|
800
|
+
_e.label = 4;
|
|
801
|
+
case 4:
|
|
787
802
|
// Return the cached token (from either memory or indexedDB) if it's valid
|
|
788
803
|
if (!forceRefresh && token && isValid(token)) {
|
|
789
804
|
return [2 /*return*/, {
|
|
@@ -791,49 +806,49 @@ function getToken$2(appCheck, forceRefresh) {
|
|
|
791
806
|
}];
|
|
792
807
|
}
|
|
793
808
|
shouldCallListeners = false;
|
|
794
|
-
if (!isDebugMode()) return [3 /*break*/,
|
|
795
|
-
if (!!state.exchangeTokenPromise) return [3 /*break*/,
|
|
809
|
+
if (!isDebugMode()) return [3 /*break*/, 9];
|
|
810
|
+
if (!!state.exchangeTokenPromise) return [3 /*break*/, 6];
|
|
796
811
|
_a = state;
|
|
797
812
|
_b = exchangeToken;
|
|
798
813
|
_c = getExchangeDebugTokenRequest;
|
|
799
814
|
_d = [app];
|
|
800
815
|
return [4 /*yield*/, getDebugToken()];
|
|
801
|
-
case
|
|
802
|
-
_a.exchangeTokenPromise = _b.apply(void 0, [_c.apply(void 0, _d.concat([_e.sent()])), appCheck.heartbeatServiceProvider]).
|
|
816
|
+
case 5:
|
|
817
|
+
_a.exchangeTokenPromise = _b.apply(void 0, [_c.apply(void 0, _d.concat([_e.sent()])), appCheck.heartbeatServiceProvider]).finally(function () {
|
|
818
|
+
// Clear promise when settled - either resolved or rejected.
|
|
803
819
|
state.exchangeTokenPromise = undefined;
|
|
804
|
-
return token;
|
|
805
820
|
});
|
|
806
821
|
shouldCallListeners = true;
|
|
807
|
-
_e.label =
|
|
808
|
-
case
|
|
809
|
-
case
|
|
822
|
+
_e.label = 6;
|
|
823
|
+
case 6: return [4 /*yield*/, state.exchangeTokenPromise];
|
|
824
|
+
case 7:
|
|
810
825
|
tokenFromDebugExchange = _e.sent();
|
|
811
826
|
// Write debug token to indexedDB.
|
|
812
827
|
return [4 /*yield*/, writeTokenToStorage(app, tokenFromDebugExchange)];
|
|
813
|
-
case
|
|
828
|
+
case 8:
|
|
814
829
|
// Write debug token to indexedDB.
|
|
815
830
|
_e.sent();
|
|
816
831
|
// Write debug token to state.
|
|
817
832
|
setState(app, __assign(__assign({}, state), { token: tokenFromDebugExchange }));
|
|
818
833
|
return [2 /*return*/, { token: tokenFromDebugExchange.token }];
|
|
819
|
-
case
|
|
820
|
-
_e.trys.push([
|
|
834
|
+
case 9:
|
|
835
|
+
_e.trys.push([9, 11, , 12]);
|
|
821
836
|
// Avoid making another call to the exchange endpoint if one is in flight.
|
|
822
837
|
if (!state.exchangeTokenPromise) {
|
|
823
838
|
// state.provider is populated in initializeAppCheck()
|
|
824
839
|
// ensureActivated() at the top of this function checks that
|
|
825
840
|
// initializeAppCheck() has been called.
|
|
826
|
-
state.exchangeTokenPromise = state.provider.getToken().
|
|
841
|
+
state.exchangeTokenPromise = state.provider.getToken().finally(function () {
|
|
842
|
+
// Clear promise when settled - either resolved or rejected.
|
|
827
843
|
state.exchangeTokenPromise = undefined;
|
|
828
|
-
return token;
|
|
829
844
|
});
|
|
830
845
|
shouldCallListeners = true;
|
|
831
846
|
}
|
|
832
847
|
return [4 /*yield*/, state.exchangeTokenPromise];
|
|
833
|
-
case
|
|
848
|
+
case 10:
|
|
834
849
|
token = _e.sent();
|
|
835
|
-
return [3 /*break*/,
|
|
836
|
-
case
|
|
850
|
+
return [3 /*break*/, 12];
|
|
851
|
+
case 11:
|
|
837
852
|
e_1 = _e.sent();
|
|
838
853
|
if (e_1.code === "appCheck/" + "throttled" /* THROTTLED */) {
|
|
839
854
|
// Warn if throttled, but do not treat it as an error.
|
|
@@ -845,14 +860,35 @@ function getToken$2(appCheck, forceRefresh) {
|
|
|
845
860
|
}
|
|
846
861
|
// Always save error to be added to dummy token.
|
|
847
862
|
error = e_1;
|
|
848
|
-
return [3 /*break*/,
|
|
849
|
-
case
|
|
850
|
-
if (!!token) return [3 /*break*/,
|
|
851
|
-
//
|
|
852
|
-
//
|
|
863
|
+
return [3 /*break*/, 12];
|
|
864
|
+
case 12:
|
|
865
|
+
if (!!token) return [3 /*break*/, 13];
|
|
866
|
+
// If token is undefined, there must be an error.
|
|
867
|
+
// Return a dummy token along with the error.
|
|
853
868
|
interopTokenResult = makeDummyTokenResult(error);
|
|
854
|
-
return [3 /*break*/,
|
|
855
|
-
case
|
|
869
|
+
return [3 /*break*/, 16];
|
|
870
|
+
case 13:
|
|
871
|
+
if (!error) return [3 /*break*/, 14];
|
|
872
|
+
if (isValid(token)) {
|
|
873
|
+
// It's also possible a valid token exists, but there's also an error.
|
|
874
|
+
// (Such as if the token is almost expired, tries to refresh, and
|
|
875
|
+
// the exchange request fails.)
|
|
876
|
+
// We add a special error property here so that the refresher will
|
|
877
|
+
// count this as a failed attempt and use the backoff instead of
|
|
878
|
+
// retrying repeatedly with no delay, but any 3P listeners will not
|
|
879
|
+
// be hindered in getting the still-valid token.
|
|
880
|
+
interopTokenResult = {
|
|
881
|
+
token: token.token,
|
|
882
|
+
internalError: error
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
else {
|
|
886
|
+
// No invalid tokens should make it to this step. Memory and cached tokens
|
|
887
|
+
// are checked. Other tokens are from fresh exchanges. But just in case.
|
|
888
|
+
interopTokenResult = makeDummyTokenResult(error);
|
|
889
|
+
}
|
|
890
|
+
return [3 /*break*/, 16];
|
|
891
|
+
case 14:
|
|
856
892
|
interopTokenResult = {
|
|
857
893
|
token: token.token
|
|
858
894
|
};
|
|
@@ -860,10 +896,10 @@ function getToken$2(appCheck, forceRefresh) {
|
|
|
860
896
|
// Only do it if we got a valid new token
|
|
861
897
|
setState(app, __assign(__assign({}, state), { token: token }));
|
|
862
898
|
return [4 /*yield*/, writeTokenToStorage(app, token)];
|
|
863
|
-
case
|
|
899
|
+
case 15:
|
|
864
900
|
_e.sent();
|
|
865
|
-
_e.label =
|
|
866
|
-
case
|
|
901
|
+
_e.label = 16;
|
|
902
|
+
case 16:
|
|
867
903
|
if (shouldCallListeners) {
|
|
868
904
|
notifyTokenListeners(app, interopTokenResult);
|
|
869
905
|
}
|
|
@@ -955,10 +991,24 @@ function createTokenRefresher(appCheck) {
|
|
|
955
991
|
result = _a.sent();
|
|
956
992
|
_a.label = 4;
|
|
957
993
|
case 4:
|
|
958
|
-
|
|
994
|
+
/**
|
|
995
|
+
* getToken() always resolves. In case the result has an error field defined, it means
|
|
996
|
+
* the operation failed, and we should retry.
|
|
997
|
+
*/
|
|
959
998
|
if (result.error) {
|
|
960
999
|
throw result.error;
|
|
961
1000
|
}
|
|
1001
|
+
/**
|
|
1002
|
+
* A special `internalError` field reflects that there was an error
|
|
1003
|
+
* getting a new token from the exchange endpoint, but there's still a
|
|
1004
|
+
* previous token that's valid for now and this should be passed to 2P/3P
|
|
1005
|
+
* requests for a token. But we want this callback (`this.operation` in
|
|
1006
|
+
* `Refresher`) to throw in order to kick off the Refresher's retry
|
|
1007
|
+
* backoff. (Setting `hasSucceeded` to false.)
|
|
1008
|
+
*/
|
|
1009
|
+
if (result.internalError) {
|
|
1010
|
+
throw result.internalError;
|
|
1011
|
+
}
|
|
962
1012
|
return [2 /*return*/];
|
|
963
1013
|
}
|
|
964
1014
|
});
|
|
@@ -1063,7 +1113,7 @@ function internalFactory(appCheck) {
|
|
|
1063
1113
|
}
|
|
1064
1114
|
|
|
1065
1115
|
var name = "@firebase/app-check";
|
|
1066
|
-
var version = "0.5.
|
|
1116
|
+
var version = "0.5.13-canary.0a112bd2a";
|
|
1067
1117
|
|
|
1068
1118
|
/**
|
|
1069
1119
|
* @license
|