@firebase/app-check
Advanced tools
Comparing version 0.2.0-2021528231051 to 0.2.0-canary.3827d9692
# @firebase/app-check | ||
## 0.2.0-2021528231051 | ||
## 0.2.0 | ||
@@ -11,7 +11,10 @@ ### Minor Changes | ||
- Updated dependencies [[`870dd5e35`](https://github.com/firebase/firebase-js-sdk/commit/870dd5e3594f5b588bdc2801c60c6d984d1d08cc), [`56a6a9d4a`](https://github.com/firebase/firebase-js-sdk/commit/56a6a9d4af2766154584a0f66d3c4d8024d74ba5)]: | ||
- @firebase/app-check-types@0.2.0-2021528231051 | ||
- @firebase/component@0.5.4-2021528231051 | ||
- @firebase/app@0.6.28-2021528231051 | ||
- [`5d007b8fb`](https://github.com/firebase/firebase-js-sdk/commit/5d007b8fb64ac26c2f82704398965e9f3deda58a) [#5084](https://github.com/firebase/firebase-js-sdk/pull/5084) - Fixed so token listeners added through public API call the error handler while internal token listeners return the error as a token field. | ||
* [`5d31e2192`](https://github.com/firebase/firebase-js-sdk/commit/5d31e2192d0ea68a768bc7826ad5aa830c2bc36c) [#5055](https://github.com/firebase/firebase-js-sdk/pull/5055) (fixes [#5052](https://github.com/firebase/firebase-js-sdk/issues/5052)) - Fix an error causing App Check to log `HTTP status 429` errors in debug mode. | ||
* Updated dependencies [[`870dd5e35`](https://github.com/firebase/firebase-js-sdk/commit/870dd5e3594f5b588bdc2801c60c6d984d1d08cc), [`5d007b8fb`](https://github.com/firebase/firebase-js-sdk/commit/5d007b8fb64ac26c2f82704398965e9f3deda58a), [`56a6a9d4a`](https://github.com/firebase/firebase-js-sdk/commit/56a6a9d4af2766154584a0f66d3c4d8024d74ba5)]: | ||
- @firebase/app-check-types@0.2.0 | ||
- @firebase/component@0.5.4 | ||
## 0.1.4 | ||
@@ -18,0 +21,0 @@ |
@@ -828,3 +828,3 @@ 'use strict'; | ||
return tslib.__awaiter(this, void 0, void 0, function () { | ||
var tokenFromDebugExchange, _a, _b, _c, state, token, error, cachedToken, customToken, issuedAtTimeSeconds, issuedAtTimeMillis, attestedClaimsToken, e_1, interopTokenResult; | ||
var state, token, error, cachedToken, tokenFromDebugExchange, _a, _b, _c, customToken, issuedAtTimeSeconds, issuedAtTimeMillis, attestedClaimsToken, e_1, interopTokenResult; | ||
return tslib.__generator(this, function (_d) { | ||
@@ -834,18 +834,8 @@ switch (_d.label) { | ||
ensureActivated(app); | ||
if (!isDebugMode()) return [3 /*break*/, 3]; | ||
_a = exchangeToken; | ||
_b = getExchangeDebugTokenRequest; | ||
_c = [app]; | ||
return [4 /*yield*/, getDebugToken()]; | ||
case 1: return [4 /*yield*/, _a.apply(void 0, [_b.apply(void 0, _c.concat([_d.sent()])), platformLoggerProvider])]; | ||
case 2: | ||
tokenFromDebugExchange = _d.sent(); | ||
return [2 /*return*/, { token: tokenFromDebugExchange.token }]; | ||
case 3: | ||
state = getState(app); | ||
token = state.token; | ||
error = undefined; | ||
if (!!token) return [3 /*break*/, 5]; | ||
if (!!token) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, readTokenFromStorage(app)]; | ||
case 4: | ||
case 1: | ||
cachedToken = _d.sent(); | ||
@@ -858,5 +848,5 @@ if (cachedToken && isValid(cachedToken)) { | ||
} | ||
_d.label = 5; | ||
case 5: | ||
// return the cached token if it's valid | ||
_d.label = 2; | ||
case 2: | ||
// Return the cached token (from either memory or indexedDB) if it's valid | ||
if (!forceRefresh && token && isValid(token)) { | ||
@@ -867,3 +857,18 @@ return [2 /*return*/, { | ||
} | ||
_d.label = 6; | ||
if (!isDebugMode()) return [3 /*break*/, 6]; | ||
_a = exchangeToken; | ||
_b = getExchangeDebugTokenRequest; | ||
_c = [app]; | ||
return [4 /*yield*/, getDebugToken()]; | ||
case 3: return [4 /*yield*/, _a.apply(void 0, [_b.apply(void 0, _c.concat([_d.sent()])), platformLoggerProvider])]; | ||
case 4: | ||
tokenFromDebugExchange = _d.sent(); | ||
// Write debug token to indexedDB. | ||
return [4 /*yield*/, writeTokenToStorage(app, tokenFromDebugExchange)]; | ||
case 5: | ||
// Write debug token to indexedDB. | ||
_d.sent(); | ||
// Write debug token to state. | ||
setState(app, tslib.__assign(tslib.__assign({}, state), { token: tokenFromDebugExchange })); | ||
return [2 /*return*/, { token: tokenFromDebugExchange.token }]; | ||
case 6: | ||
@@ -910,3 +915,3 @@ _d.trys.push([6, 12, , 13]); | ||
}; | ||
// write the new token to the memory state as well ashe persistent storage. | ||
// write the new token to the memory state as well as the persistent storage. | ||
// Only do it if we got a valid new token | ||
@@ -925,50 +930,32 @@ setState(app, tslib.__assign(tslib.__assign({}, state), { token: token })); | ||
} | ||
function addTokenListener(app, platformLoggerProvider, listener, onError) { | ||
function addTokenListener(app, platformLoggerProvider, type, listener, onError) { | ||
var state = getState(app); | ||
var tokenListener = { | ||
next: listener, | ||
error: onError | ||
error: onError, | ||
type: type | ||
}; | ||
var newState = tslib.__assign(tslib.__assign({}, state), { tokenObservers: tslib.__spreadArray(tslib.__spreadArray([], state.tokenObservers), [tokenListener]) }); | ||
/** | ||
* DEBUG MODE | ||
* | ||
* invoke the listener once with the debug token. | ||
* Invoke the listener with the valid token, then start the token refresher | ||
*/ | ||
if (isDebugMode()) { | ||
var debugState = getDebugState(); | ||
if (debugState.enabled && debugState.token) { | ||
debugState.token.promise | ||
.then(function (token) { return listener({ token: token }); }) | ||
.catch(function () { | ||
/** Ignore errors in listeners. */ | ||
}); | ||
} | ||
if (!newState.tokenRefresher) { | ||
var tokenRefresher = createTokenRefresher(app, platformLoggerProvider); | ||
newState.tokenRefresher = tokenRefresher; | ||
} | ||
else { | ||
/** | ||
* PROD MODE | ||
* | ||
* invoke the listener with the valid token, then start the token refresher | ||
*/ | ||
if (!newState.tokenRefresher) { | ||
var tokenRefresher = createTokenRefresher(app, platformLoggerProvider); | ||
newState.tokenRefresher = tokenRefresher; | ||
} | ||
// Create the refresher but don't start it if `isTokenAutoRefreshEnabled` | ||
// is not true. | ||
if (!newState.tokenRefresher.isRunning() && | ||
state.isTokenAutoRefreshEnabled === true) { | ||
newState.tokenRefresher.start(); | ||
} | ||
// invoke the listener async immediately if there is a valid token | ||
if (state.token && isValid(state.token)) { | ||
var validToken_1 = state.token; | ||
Promise.resolve() | ||
.then(function () { return listener({ token: validToken_1.token }); }) | ||
.catch(function () { | ||
/** Ignore errors in listeners. */ | ||
}); | ||
} | ||
// Create the refresher but don't start it if `isTokenAutoRefreshEnabled` | ||
// is not true. | ||
if (!newState.tokenRefresher.isRunning() && | ||
state.isTokenAutoRefreshEnabled === true) { | ||
newState.tokenRefresher.start(); | ||
} | ||
// invoke the listener async immediately if there is a valid token | ||
if (state.token && isValid(state.token)) { | ||
var validToken_1 = state.token; | ||
Promise.resolve() | ||
.then(function () { return listener({ token: validToken_1.token }); }) | ||
.catch(function () { | ||
/** Ignore errors in listeners. */ | ||
}); | ||
} | ||
setState(app, newState); | ||
@@ -1040,14 +1027,12 @@ } | ||
try { | ||
if (observer.error) { | ||
// If this listener has an error handler, handle errors differently | ||
// from successes. | ||
if (token.error) { | ||
observer.error(token.error); | ||
} | ||
else { | ||
observer.next(token); | ||
} | ||
if (observer.type === "EXTERNAL" /* EXTERNAL */ && token.error != null) { | ||
// If this listener was added by a 3P call, send any token error to | ||
// the supplied error handler. A 3P observer always has an error | ||
// handler. | ||
observer.error(token.error); | ||
} | ||
else { | ||
// Otherwise return the token, whether or not it has an error field. | ||
// If the token has no error field, always return the token. | ||
// If this is a 2P listener, return the token, whether or not it | ||
// has an error field. | ||
observer.next(token); | ||
@@ -1057,3 +1042,3 @@ } | ||
catch (ignored) { | ||
// If any handler fails, ignore and run next handler. | ||
// Errors in the listener function itself are always ignored. | ||
} | ||
@@ -1181,3 +1166,3 @@ } | ||
} | ||
addTokenListener(app, platformLoggerProvider, nextFn, errorFn); | ||
addTokenListener(app, platformLoggerProvider, "EXTERNAL" /* EXTERNAL */, nextFn, errorFn); | ||
return function () { return removeTokenListener(app, nextFn); }; | ||
@@ -1204,2 +1189,3 @@ } | ||
return { | ||
app: app, | ||
activate: function (siteKeyOrProvider, isTokenAutoRefreshEnabled) { return activate(app, siteKeyOrProvider, isTokenAutoRefreshEnabled); }, | ||
@@ -1220,2 +1206,12 @@ setTokenAutoRefreshEnabled: function (isTokenAutoRefreshEnabled) { | ||
onNextOrObserver, onError); | ||
}, | ||
INTERNAL: { | ||
delete: function () { | ||
var tokenObservers = getState(app).tokenObservers; | ||
for (var _i = 0, tokenObservers_1 = tokenObservers; _i < tokenObservers_1.length; _i++) { | ||
var tokenObserver = tokenObservers_1[_i]; | ||
removeTokenListener(app, tokenObserver.next); | ||
} | ||
return Promise.resolve(); | ||
} | ||
} | ||
@@ -1230,3 +1226,3 @@ }; | ||
addTokenListener: function (listener) { | ||
return addTokenListener(app, platformLoggerProvider, listener); | ||
return addTokenListener(app, platformLoggerProvider, "INTERNAL" /* INTERNAL */, listener); | ||
}, | ||
@@ -1238,3 +1234,3 @@ removeTokenListener: function (listener) { return removeTokenListener(app, listener); } | ||
var name = "@firebase/app-check"; | ||
var version = "0.2.0-2021528231051"; | ||
var version = "0.2.0-canary.3827d9692"; | ||
@@ -1241,0 +1237,0 @@ /** |
@@ -822,3 +822,3 @@ import firebase from '@firebase/app'; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var tokenFromDebugExchange, _a, _b, _c, state, token, error, cachedToken, customToken, issuedAtTimeSeconds, issuedAtTimeMillis, attestedClaimsToken, e_1, interopTokenResult; | ||
var state, token, error, cachedToken, tokenFromDebugExchange, _a, _b, _c, customToken, issuedAtTimeSeconds, issuedAtTimeMillis, attestedClaimsToken, e_1, interopTokenResult; | ||
return __generator(this, function (_d) { | ||
@@ -828,18 +828,8 @@ switch (_d.label) { | ||
ensureActivated(app); | ||
if (!isDebugMode()) return [3 /*break*/, 3]; | ||
_a = exchangeToken; | ||
_b = getExchangeDebugTokenRequest; | ||
_c = [app]; | ||
return [4 /*yield*/, getDebugToken()]; | ||
case 1: return [4 /*yield*/, _a.apply(void 0, [_b.apply(void 0, _c.concat([_d.sent()])), platformLoggerProvider])]; | ||
case 2: | ||
tokenFromDebugExchange = _d.sent(); | ||
return [2 /*return*/, { token: tokenFromDebugExchange.token }]; | ||
case 3: | ||
state = getState(app); | ||
token = state.token; | ||
error = undefined; | ||
if (!!token) return [3 /*break*/, 5]; | ||
if (!!token) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, readTokenFromStorage(app)]; | ||
case 4: | ||
case 1: | ||
cachedToken = _d.sent(); | ||
@@ -852,5 +842,5 @@ if (cachedToken && isValid(cachedToken)) { | ||
} | ||
_d.label = 5; | ||
case 5: | ||
// return the cached token if it's valid | ||
_d.label = 2; | ||
case 2: | ||
// Return the cached token (from either memory or indexedDB) if it's valid | ||
if (!forceRefresh && token && isValid(token)) { | ||
@@ -861,3 +851,18 @@ return [2 /*return*/, { | ||
} | ||
_d.label = 6; | ||
if (!isDebugMode()) return [3 /*break*/, 6]; | ||
_a = exchangeToken; | ||
_b = getExchangeDebugTokenRequest; | ||
_c = [app]; | ||
return [4 /*yield*/, getDebugToken()]; | ||
case 3: return [4 /*yield*/, _a.apply(void 0, [_b.apply(void 0, _c.concat([_d.sent()])), platformLoggerProvider])]; | ||
case 4: | ||
tokenFromDebugExchange = _d.sent(); | ||
// Write debug token to indexedDB. | ||
return [4 /*yield*/, writeTokenToStorage(app, tokenFromDebugExchange)]; | ||
case 5: | ||
// Write debug token to indexedDB. | ||
_d.sent(); | ||
// Write debug token to state. | ||
setState(app, __assign(__assign({}, state), { token: tokenFromDebugExchange })); | ||
return [2 /*return*/, { token: tokenFromDebugExchange.token }]; | ||
case 6: | ||
@@ -904,3 +909,3 @@ _d.trys.push([6, 12, , 13]); | ||
}; | ||
// write the new token to the memory state as well ashe persistent storage. | ||
// write the new token to the memory state as well as the persistent storage. | ||
// Only do it if we got a valid new token | ||
@@ -919,50 +924,32 @@ setState(app, __assign(__assign({}, state), { token: token })); | ||
} | ||
function addTokenListener(app, platformLoggerProvider, listener, onError) { | ||
function addTokenListener(app, platformLoggerProvider, type, listener, onError) { | ||
var state = getState(app); | ||
var tokenListener = { | ||
next: listener, | ||
error: onError | ||
error: onError, | ||
type: type | ||
}; | ||
var newState = __assign(__assign({}, state), { tokenObservers: __spreadArray(__spreadArray([], state.tokenObservers), [tokenListener]) }); | ||
/** | ||
* DEBUG MODE | ||
* | ||
* invoke the listener once with the debug token. | ||
* Invoke the listener with the valid token, then start the token refresher | ||
*/ | ||
if (isDebugMode()) { | ||
var debugState = getDebugState(); | ||
if (debugState.enabled && debugState.token) { | ||
debugState.token.promise | ||
.then(function (token) { return listener({ token: token }); }) | ||
.catch(function () { | ||
/** Ignore errors in listeners. */ | ||
}); | ||
} | ||
if (!newState.tokenRefresher) { | ||
var tokenRefresher = createTokenRefresher(app, platformLoggerProvider); | ||
newState.tokenRefresher = tokenRefresher; | ||
} | ||
else { | ||
/** | ||
* PROD MODE | ||
* | ||
* invoke the listener with the valid token, then start the token refresher | ||
*/ | ||
if (!newState.tokenRefresher) { | ||
var tokenRefresher = createTokenRefresher(app, platformLoggerProvider); | ||
newState.tokenRefresher = tokenRefresher; | ||
} | ||
// Create the refresher but don't start it if `isTokenAutoRefreshEnabled` | ||
// is not true. | ||
if (!newState.tokenRefresher.isRunning() && | ||
state.isTokenAutoRefreshEnabled === true) { | ||
newState.tokenRefresher.start(); | ||
} | ||
// invoke the listener async immediately if there is a valid token | ||
if (state.token && isValid(state.token)) { | ||
var validToken_1 = state.token; | ||
Promise.resolve() | ||
.then(function () { return listener({ token: validToken_1.token }); }) | ||
.catch(function () { | ||
/** Ignore errors in listeners. */ | ||
}); | ||
} | ||
// Create the refresher but don't start it if `isTokenAutoRefreshEnabled` | ||
// is not true. | ||
if (!newState.tokenRefresher.isRunning() && | ||
state.isTokenAutoRefreshEnabled === true) { | ||
newState.tokenRefresher.start(); | ||
} | ||
// invoke the listener async immediately if there is a valid token | ||
if (state.token && isValid(state.token)) { | ||
var validToken_1 = state.token; | ||
Promise.resolve() | ||
.then(function () { return listener({ token: validToken_1.token }); }) | ||
.catch(function () { | ||
/** Ignore errors in listeners. */ | ||
}); | ||
} | ||
setState(app, newState); | ||
@@ -1034,14 +1021,12 @@ } | ||
try { | ||
if (observer.error) { | ||
// If this listener has an error handler, handle errors differently | ||
// from successes. | ||
if (token.error) { | ||
observer.error(token.error); | ||
} | ||
else { | ||
observer.next(token); | ||
} | ||
if (observer.type === "EXTERNAL" /* EXTERNAL */ && token.error != null) { | ||
// If this listener was added by a 3P call, send any token error to | ||
// the supplied error handler. A 3P observer always has an error | ||
// handler. | ||
observer.error(token.error); | ||
} | ||
else { | ||
// Otherwise return the token, whether or not it has an error field. | ||
// If the token has no error field, always return the token. | ||
// If this is a 2P listener, return the token, whether or not it | ||
// has an error field. | ||
observer.next(token); | ||
@@ -1051,3 +1036,3 @@ } | ||
catch (ignored) { | ||
// If any handler fails, ignore and run next handler. | ||
// Errors in the listener function itself are always ignored. | ||
} | ||
@@ -1175,3 +1160,3 @@ } | ||
} | ||
addTokenListener(app, platformLoggerProvider, nextFn, errorFn); | ||
addTokenListener(app, platformLoggerProvider, "EXTERNAL" /* EXTERNAL */, nextFn, errorFn); | ||
return function () { return removeTokenListener(app, nextFn); }; | ||
@@ -1198,2 +1183,3 @@ } | ||
return { | ||
app: app, | ||
activate: function (siteKeyOrProvider, isTokenAutoRefreshEnabled) { return activate(app, siteKeyOrProvider, isTokenAutoRefreshEnabled); }, | ||
@@ -1214,2 +1200,12 @@ setTokenAutoRefreshEnabled: function (isTokenAutoRefreshEnabled) { | ||
onNextOrObserver, onError); | ||
}, | ||
INTERNAL: { | ||
delete: function () { | ||
var tokenObservers = getState(app).tokenObservers; | ||
for (var _i = 0, tokenObservers_1 = tokenObservers; _i < tokenObservers_1.length; _i++) { | ||
var tokenObserver = tokenObservers_1[_i]; | ||
removeTokenListener(app, tokenObserver.next); | ||
} | ||
return Promise.resolve(); | ||
} | ||
} | ||
@@ -1224,3 +1220,3 @@ }; | ||
addTokenListener: function (listener) { | ||
return addTokenListener(app, platformLoggerProvider, listener); | ||
return addTokenListener(app, platformLoggerProvider, "INTERNAL" /* INTERNAL */, listener); | ||
}, | ||
@@ -1232,3 +1228,3 @@ removeTokenListener: function (listener) { return removeTokenListener(app, listener); } | ||
var name = "@firebase/app-check"; | ||
var version = "0.2.0-2021528231051"; | ||
var version = "0.2.0-canary.3827d9692"; | ||
@@ -1235,0 +1231,0 @@ /** |
@@ -732,15 +732,10 @@ import firebase from '@firebase/app'; | ||
ensureActivated(app); | ||
const state = getState(app); | ||
/** | ||
* DEBUG MODE | ||
* return the debug token directly | ||
* First check if there is a token in memory from a previous `getToken()` call. | ||
*/ | ||
if (isDebugMode()) { | ||
const tokenFromDebugExchange = await exchangeToken(getExchangeDebugTokenRequest(app, await getDebugToken()), platformLoggerProvider); | ||
return { token: tokenFromDebugExchange.token }; | ||
} | ||
const state = getState(app); | ||
let token = state.token; | ||
let error = undefined; | ||
/** | ||
* try to load token from indexedDB if it's the first time this function is called | ||
* If there is no token in memory, try to load token from indexedDB. | ||
*/ | ||
@@ -757,3 +752,3 @@ if (!token) { | ||
} | ||
// return the cached token if it's valid | ||
// Return the cached token (from either memory or indexedDB) if it's valid | ||
if (!forceRefresh && token && isValid(token)) { | ||
@@ -765,2 +760,15 @@ return { | ||
/** | ||
* DEBUG MODE | ||
* If debug mode is set, and there is no cached token, fetch a new App | ||
* Check token using the debug token, and return it directly. | ||
*/ | ||
if (isDebugMode()) { | ||
const tokenFromDebugExchange = await exchangeToken(getExchangeDebugTokenRequest(app, await getDebugToken()), platformLoggerProvider); | ||
// Write debug token to indexedDB. | ||
await writeTokenToStorage(app, tokenFromDebugExchange); | ||
// Write debug token to state. | ||
setState(app, Object.assign(Object.assign({}, state), { token: tokenFromDebugExchange })); | ||
return { token: tokenFromDebugExchange.token }; | ||
} | ||
/** | ||
* request a new token | ||
@@ -806,3 +814,3 @@ */ | ||
}; | ||
// write the new token to the memory state as well ashe persistent storage. | ||
// write the new token to the memory state as well as the persistent storage. | ||
// Only do it if we got a valid new token | ||
@@ -815,50 +823,32 @@ setState(app, Object.assign(Object.assign({}, state), { token })); | ||
} | ||
function addTokenListener(app, platformLoggerProvider, listener, onError) { | ||
function addTokenListener(app, platformLoggerProvider, type, listener, onError) { | ||
const state = getState(app); | ||
const tokenListener = { | ||
next: listener, | ||
error: onError | ||
error: onError, | ||
type | ||
}; | ||
const newState = Object.assign(Object.assign({}, state), { tokenObservers: [...state.tokenObservers, tokenListener] }); | ||
/** | ||
* DEBUG MODE | ||
* | ||
* invoke the listener once with the debug token. | ||
* Invoke the listener with the valid token, then start the token refresher | ||
*/ | ||
if (isDebugMode()) { | ||
const debugState = getDebugState(); | ||
if (debugState.enabled && debugState.token) { | ||
debugState.token.promise | ||
.then(token => listener({ token })) | ||
.catch(() => { | ||
/** Ignore errors in listeners. */ | ||
}); | ||
} | ||
if (!newState.tokenRefresher) { | ||
const tokenRefresher = createTokenRefresher(app, platformLoggerProvider); | ||
newState.tokenRefresher = tokenRefresher; | ||
} | ||
else { | ||
/** | ||
* PROD MODE | ||
* | ||
* invoke the listener with the valid token, then start the token refresher | ||
*/ | ||
if (!newState.tokenRefresher) { | ||
const tokenRefresher = createTokenRefresher(app, platformLoggerProvider); | ||
newState.tokenRefresher = tokenRefresher; | ||
} | ||
// Create the refresher but don't start it if `isTokenAutoRefreshEnabled` | ||
// is not true. | ||
if (!newState.tokenRefresher.isRunning() && | ||
state.isTokenAutoRefreshEnabled === true) { | ||
newState.tokenRefresher.start(); | ||
} | ||
// invoke the listener async immediately if there is a valid token | ||
if (state.token && isValid(state.token)) { | ||
const validToken = state.token; | ||
Promise.resolve() | ||
.then(() => listener({ token: validToken.token })) | ||
.catch(() => { | ||
/** Ignore errors in listeners. */ | ||
}); | ||
} | ||
// Create the refresher but don't start it if `isTokenAutoRefreshEnabled` | ||
// is not true. | ||
if (!newState.tokenRefresher.isRunning() && | ||
state.isTokenAutoRefreshEnabled === true) { | ||
newState.tokenRefresher.start(); | ||
} | ||
// invoke the listener async immediately if there is a valid token | ||
if (state.token && isValid(state.token)) { | ||
const validToken = state.token; | ||
Promise.resolve() | ||
.then(() => listener({ token: validToken.token })) | ||
.catch(() => { | ||
/** Ignore errors in listeners. */ | ||
}); | ||
} | ||
setState(app, newState); | ||
@@ -920,14 +910,12 @@ } | ||
try { | ||
if (observer.error) { | ||
// If this listener has an error handler, handle errors differently | ||
// from successes. | ||
if (token.error) { | ||
observer.error(token.error); | ||
} | ||
else { | ||
observer.next(token); | ||
} | ||
if (observer.type === "EXTERNAL" /* EXTERNAL */ && token.error != null) { | ||
// If this listener was added by a 3P call, send any token error to | ||
// the supplied error handler. A 3P observer always has an error | ||
// handler. | ||
observer.error(token.error); | ||
} | ||
else { | ||
// Otherwise return the token, whether or not it has an error field. | ||
// If the token has no error field, always return the token. | ||
// If this is a 2P listener, return the token, whether or not it | ||
// has an error field. | ||
observer.next(token); | ||
@@ -937,3 +925,3 @@ } | ||
catch (ignored) { | ||
// If any handler fails, ignore and run next handler. | ||
// Errors in the listener function itself are always ignored. | ||
} | ||
@@ -1052,3 +1040,3 @@ } | ||
} | ||
addTokenListener(app, platformLoggerProvider, nextFn, errorFn); | ||
addTokenListener(app, platformLoggerProvider, "EXTERNAL" /* EXTERNAL */, nextFn, errorFn); | ||
return () => removeTokenListener(app, nextFn); | ||
@@ -1075,2 +1063,3 @@ } | ||
return { | ||
app, | ||
activate: (siteKeyOrProvider, isTokenAutoRefreshEnabled) => activate(app, siteKeyOrProvider, isTokenAutoRefreshEnabled), | ||
@@ -1085,3 +1074,12 @@ setTokenAutoRefreshEnabled: (isTokenAutoRefreshEnabled) => setTokenAutoRefreshEnabled(app, isTokenAutoRefreshEnabled), | ||
*/ | ||
onNextOrObserver, onError) | ||
onNextOrObserver, onError), | ||
INTERNAL: { | ||
delete: () => { | ||
const { tokenObservers } = getState(app); | ||
for (const tokenObserver of tokenObservers) { | ||
removeTokenListener(app, tokenObserver.next); | ||
} | ||
return Promise.resolve(); | ||
} | ||
} | ||
}; | ||
@@ -1092,3 +1090,3 @@ } | ||
getToken: forceRefresh => getToken$1(app, platformLoggerProvider, forceRefresh), | ||
addTokenListener: listener => addTokenListener(app, platformLoggerProvider, listener), | ||
addTokenListener: listener => addTokenListener(app, platformLoggerProvider, "INTERNAL" /* INTERNAL */, listener), | ||
removeTokenListener: listener => removeTokenListener(app, listener) | ||
@@ -1099,3 +1097,3 @@ }; | ||
const name = "@firebase/app-check"; | ||
const version = "0.2.0-2021528231051"; | ||
const version = "0.2.0-canary.3827d9692"; | ||
@@ -1102,0 +1100,0 @@ /** |
@@ -21,3 +21,4 @@ /** | ||
import { Provider } from '@firebase/component'; | ||
export declare function factory(app: FirebaseApp, platformLoggerProvider: Provider<'platform-logger'>): FirebaseAppCheck; | ||
import { FirebaseService } from '@firebase/app-types/private'; | ||
export declare function factory(app: FirebaseApp, platformLoggerProvider: Provider<'platform-logger'>): FirebaseAppCheck & FirebaseService; | ||
export declare function internalFactory(app: FirebaseApp, platformLoggerProvider: Provider<'platform-logger'>): FirebaseAppCheckInternal; |
@@ -19,2 +19,3 @@ /** | ||
import { AppCheckTokenListener, AppCheckTokenResult } from '@firebase/app-check-interop-types'; | ||
import { ListenerType } from './state'; | ||
import { Provider } from '@firebase/component'; | ||
@@ -36,3 +37,3 @@ export declare const defaultTokenErrorData: { | ||
export declare function getToken(app: FirebaseApp, platformLoggerProvider: Provider<'platform-logger'>, forceRefresh?: boolean): Promise<AppCheckTokenResult>; | ||
export declare function addTokenListener(app: FirebaseApp, platformLoggerProvider: Provider<'platform-logger'>, listener: AppCheckTokenListener, onError?: (error: Error) => void): void; | ||
export declare function addTokenListener(app: FirebaseApp, platformLoggerProvider: Provider<'platform-logger'>, type: ListenerType, listener: AppCheckTokenListener, onError?: (error: Error) => void): void; | ||
export declare function removeTokenListener(app: FirebaseApp, listener: (token: AppCheckTokenResult) => void): void; |
@@ -28,3 +28,8 @@ /** | ||
next: AppCheckTokenListener; | ||
type: ListenerType; | ||
} | ||
export declare const enum ListenerType { | ||
'INTERNAL' = "INTERNAL", | ||
'EXTERNAL' = "EXTERNAL" | ||
} | ||
export interface AppCheckState { | ||
@@ -31,0 +36,0 @@ activated: boolean; |
{ | ||
"name": "@firebase/app-check", | ||
"version": "0.2.0-2021528231051", | ||
"version": "0.2.0-canary.3827d9692", | ||
"description": "The App Check component of the Firebase JS SDK", | ||
@@ -27,11 +27,11 @@ "author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)", | ||
"peerDependencies": { | ||
"@firebase/app": "0.6.28-2021528231051", | ||
"@firebase/app-types": "0.x" | ||
"@firebase/app": "0.6.28-canary.3827d9692", | ||
"@firebase/app-types": "0.6.2-canary.3827d9692" | ||
}, | ||
"dependencies": { | ||
"@firebase/app-check-types": "0.2.0-2021528231051", | ||
"@firebase/app-check-interop-types": "0.1.0", | ||
"@firebase/util": "1.1.0", | ||
"@firebase/component": "0.5.4-2021528231051", | ||
"@firebase/logger": "0.2.6", | ||
"@firebase/app-check-types": "0.2.0-canary.3827d9692", | ||
"@firebase/app-check-interop-types": "0.1.0-canary.3827d9692", | ||
"@firebase/util": "1.1.0-canary.3827d9692", | ||
"@firebase/component": "0.5.4-canary.3827d9692", | ||
"@firebase/logger": "0.2.6-canary.3827d9692", | ||
"tslib": "^2.1.0" | ||
@@ -41,3 +41,3 @@ }, | ||
"devDependencies": { | ||
"@firebase/app": "0.6.28-2021528231051", | ||
"@firebase/app": "0.6.28-canary.3827d9692", | ||
"rollup": "2.52.2", | ||
@@ -63,2 +63,2 @@ "@rollup/plugin-json": "4.1.0", | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
413767
4278
+ Added@firebase/app@0.6.28-canary.3827d9692(transitive)
+ Added@firebase/app-check-interop-types@0.1.0-canary.3827d9692(transitive)
+ Added@firebase/app-check-types@0.2.0-canary.3827d9692(transitive)
+ Added@firebase/app-types@0.6.2-canary.3827d9692(transitive)
+ Added@firebase/component@0.5.4-canary.3827d9692(transitive)
+ Added@firebase/logger@0.2.6-canary.3827d9692(transitive)
+ Added@firebase/util@1.1.0-canary.3827d9692(transitive)
- Removed@firebase/app@0.6.28-2021528231051(transitive)
- Removed@firebase/app-check-interop-types@0.1.0(transitive)
- Removed@firebase/app-check-types@0.2.0-2021528231051(transitive)
- Removed@firebase/app-types@0.6.20.9.3(transitive)
- Removed@firebase/component@0.5.4-2021528231051(transitive)
- Removed@firebase/logger@0.2.6(transitive)
- Removed@firebase/util@1.1.0(transitive)
Updated@firebase/app-check-interop-types@0.1.0-canary.3827d9692