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