New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

@firebase/app-check

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@firebase/app-check - npm Package Compare versions

Comparing version

to
0.1.4-canary.1bbdbfef3

# @firebase/app-check
## 0.1.4-202151602035
## 0.1.4

@@ -8,4 +8,3 @@ ### Patch Changes

- Updated dependencies [[`725ab4684`](https://github.com/firebase/firebase-js-sdk/commit/725ab4684ef0999a12f71e704c204a00fb030e5d)]:
- @firebase/component@0.5.3-202151602035
- @firebase/app@0.6.27-202151602035
- @firebase/component@0.5.3

@@ -12,0 +11,0 @@ ## 0.1.3

@@ -67,3 +67,3 @@ 'use strict';

activated: false,
tokenListeners: []
tokenObservers: []
};

@@ -168,3 +168,3 @@ var DEBUG_STATE = {

}
function getToken(app) {
function getToken$2(app) {
return tslib.__awaiter(this, void 0, void 0, function () {

@@ -232,70 +232,2 @@ var reCAPTCHAState, recaptcha;

*/
/**
*
* @param app
* @param siteKeyOrProvider - optional custom attestation provider
* or reCAPTCHA siteKey
* @param isTokenAutoRefreshEnabled - if true, enables auto refresh
* of appCheck token.
*/
function activate(app, siteKeyOrProvider, isTokenAutoRefreshEnabled) {
var state = getState(app);
if (state.activated) {
throw ERROR_FACTORY.create("already-activated" /* ALREADY_ACTIVATED */, {
appName: app.name
});
}
var newState = tslib.__assign(tslib.__assign({}, state), { activated: true });
if (typeof siteKeyOrProvider === 'string') {
newState.siteKey = siteKeyOrProvider;
}
else {
newState.customProvider = siteKeyOrProvider;
}
// Use value of global `automaticDataCollectionEnabled` (which
// itself defaults to false if not specified in config) if
// `isTokenAutoRefreshEnabled` param was not provided by user.
newState.isTokenAutoRefreshEnabled =
isTokenAutoRefreshEnabled === undefined
? app.automaticDataCollectionEnabled
: isTokenAutoRefreshEnabled;
setState(app, newState);
// initialize reCAPTCHA if siteKey is provided
if (newState.siteKey) {
initialize(app, newState.siteKey).catch(function () {
/* we don't care about the initialization result in activate() */
});
}
}
function setTokenAutoRefreshEnabled(app, isTokenAutoRefreshEnabled) {
var state = getState(app);
// This will exist if any product libraries have called
// `addTokenListener()`
if (state.tokenRefresher) {
if (isTokenAutoRefreshEnabled === true) {
state.tokenRefresher.start();
}
else {
state.tokenRefresher.stop();
}
}
setState(app, tslib.__assign(tslib.__assign({}, state), { isTokenAutoRefreshEnabled: isTokenAutoRefreshEnabled }));
}
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var BASE_ENDPOINT = 'https://content-firebaseappcheck.googleapis.com/v1beta';

@@ -772,3 +704,3 @@ var EXCHANGE_RECAPTCHA_TOKEN_METHOD = 'exchangeRecaptchaToken';

return tslib.__awaiter(this, void 0, void 0, function () {
var existingDebugToken, _e_1, newToken;
var existingDebugToken, newToken;
return tslib.__generator(this, function (_a) {

@@ -786,3 +718,3 @@ switch (_a.label) {

case 3:
_e_1 = _a.sent();
_a.sent();
return [3 /*break*/, 4];

@@ -952,3 +884,3 @@ case 4:

return [3 /*break*/, 11];
case 8: return [4 /*yield*/, getToken(app).catch(function (_e) {
case 8: return [4 /*yield*/, getToken$2(app).catch(function (_e) {
// reCaptcha.execute() throws null which is not very descriptive.

@@ -994,5 +926,9 @@ throw ERROR_FACTORY.create("recaptcha-error" /* RECAPTCHA_ERROR */);

}
function addTokenListener(app, platformLoggerProvider, listener) {
function addTokenListener(app, platformLoggerProvider, listener, onError) {
var state = getState(app);
var newState = tslib.__assign(tslib.__assign({}, state), { tokenListeners: tslib.__spreadArray(tslib.__spreadArray([], state.tokenListeners), [listener]) });
var tokenListener = {
next: listener,
error: onError
};
var newState = tslib.__assign(tslib.__assign({}, state), { tokenObservers: tslib.__spreadArray(tslib.__spreadArray([], state.tokenObservers), [tokenListener]) });
/**

@@ -1009,3 +945,3 @@ * DEBUG MODE

.catch(function () {
/* we don't care about exceptions thrown in listeners */
/** Ignore errors in listeners. */
});

@@ -1036,3 +972,3 @@ }

.catch(function () {
/* we don't care about exceptions thrown in listeners */
/** Ignore errors in listeners. */
});

@@ -1045,4 +981,4 @@ }

var state = getState(app);
var newListeners = state.tokenListeners.filter(function (l) { return l !== listener; });
if (newListeners.length === 0 &&
var newObservers = state.tokenObservers.filter(function (tokenObserver) { return tokenObserver.next !== listener; });
if (newObservers.length === 0 &&
state.tokenRefresher &&

@@ -1052,3 +988,3 @@ state.tokenRefresher.isRunning()) {

}
setState(app, tslib.__assign(tslib.__assign({}, state), { tokenListeners: newListeners }));
setState(app, tslib.__assign(tslib.__assign({}, state), { tokenObservers: newObservers }));
}

@@ -1105,9 +1041,22 @@ function createTokenRefresher(app, platformLoggerProvider) {

function notifyTokenListeners(app, token) {
var listeners = getState(app).tokenListeners;
for (var _i = 0, listeners_1 = listeners; _i < listeners_1.length; _i++) {
var listener = listeners_1[_i];
var observers = getState(app).tokenObservers;
for (var _i = 0, observers_1 = observers; _i < observers_1.length; _i++) {
var observer = observers_1[_i];
try {
listener(token);
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);
}
}
else {
// Otherwise return the token, whether or not it has an error field.
observer.next(token);
}
}
catch (e) {
catch (ignored) {
// If any handler fails, ignore and run next handler.

@@ -1143,3 +1092,116 @@ }

*/
function factory(app) {
/**
*
* @param app
* @param siteKeyOrProvider - optional custom attestation provider
* or reCAPTCHA siteKey
* @param isTokenAutoRefreshEnabled - if true, enables auto refresh
* of appCheck token.
*/
function activate(app, siteKeyOrProvider, isTokenAutoRefreshEnabled) {
var state = getState(app);
if (state.activated) {
throw ERROR_FACTORY.create("already-activated" /* ALREADY_ACTIVATED */, {
appName: app.name
});
}
var newState = tslib.__assign(tslib.__assign({}, state), { activated: true });
if (typeof siteKeyOrProvider === 'string') {
newState.siteKey = siteKeyOrProvider;
}
else {
newState.customProvider = siteKeyOrProvider;
}
// Use value of global `automaticDataCollectionEnabled` (which
// itself defaults to false if not specified in config) if
// `isTokenAutoRefreshEnabled` param was not provided by user.
newState.isTokenAutoRefreshEnabled =
isTokenAutoRefreshEnabled === undefined
? app.automaticDataCollectionEnabled
: isTokenAutoRefreshEnabled;
setState(app, newState);
// initialize reCAPTCHA if siteKey is provided
if (newState.siteKey) {
initialize(app, newState.siteKey).catch(function () {
/* we don't care about the initialization result in activate() */
});
}
}
function setTokenAutoRefreshEnabled(app, isTokenAutoRefreshEnabled) {
var state = getState(app);
// This will exist if any product libraries have called
// `addTokenListener()`
if (state.tokenRefresher) {
if (isTokenAutoRefreshEnabled === true) {
state.tokenRefresher.start();
}
else {
state.tokenRefresher.stop();
}
}
setState(app, tslib.__assign(tslib.__assign({}, state), { isTokenAutoRefreshEnabled: isTokenAutoRefreshEnabled }));
}
/**
* Differs from internal getToken in that it throws the error.
*/
function getToken(app, platformLoggerProvider, forceRefresh) {
return tslib.__awaiter(this, void 0, void 0, function () {
var result;
return tslib.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, getToken$1(app, platformLoggerProvider, forceRefresh)];
case 1:
result = _a.sent();
if (result.error) {
throw result.error;
}
return [2 /*return*/, { token: result.token }];
}
});
});
}
function onTokenChanged(app, platformLoggerProvider, onNextOrObserver, onError,
/**
* NOTE: Although an `onCompletion` callback can be provided, it will
* never be called because the token stream is never-ending.
* It is added only for API consistency with the observer pattern, which
* we follow in JS APIs.
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onCompletion) {
var nextFn = function () { };
var errorFn = function () { };
if (onNextOrObserver.next != null) {
nextFn = onNextOrObserver.next.bind(onNextOrObserver);
}
else {
nextFn = onNextOrObserver;
}
if (onNextOrObserver.error != null) {
errorFn = onNextOrObserver.error.bind(onNextOrObserver);
}
else if (onError) {
errorFn = onError;
}
addTokenListener(app, platformLoggerProvider, nextFn, errorFn);
return function () { return removeTokenListener(app, nextFn); };
}
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function factory(app, platformLoggerProvider) {
return {

@@ -1149,2 +1211,14 @@ activate: function (siteKeyOrProvider, isTokenAutoRefreshEnabled) { return activate(app, siteKeyOrProvider, isTokenAutoRefreshEnabled); },

return setTokenAutoRefreshEnabled(app, isTokenAutoRefreshEnabled);
},
getToken: function (forceRefresh) {
return getToken(app, platformLoggerProvider, forceRefresh);
},
onTokenChanged: function (onNextOrObserver, onError, onCompletion) {
return onTokenChanged(app, platformLoggerProvider,
/**
* This can still be an observer. Need to do this casting because
* according to Typescript: "Implementation signatures of overloads
* are not externally visible"
*/
onNextOrObserver, onError);
}

@@ -1166,3 +1240,3 @@ };

var name = "@firebase/app-check";
var version = "0.1.4-202151602035";
var version = "0.1.4-canary.1bbdbfef3";

@@ -1192,3 +1266,4 @@ /**

var app = container.getProvider('app').getImmediate();
return factory(app);
var platformLoggerProvider = container.getProvider('platform-logger');
return factory(app, platformLoggerProvider);
}, "PUBLIC" /* PUBLIC */)

@@ -1195,0 +1270,0 @@ /**

@@ -61,3 +61,3 @@ import firebase from '@firebase/app';

activated: false,
tokenListeners: []
tokenObservers: []
};

@@ -162,3 +162,3 @@ var DEBUG_STATE = {

}
function getToken(app) {
function getToken$2(app) {
return __awaiter(this, void 0, void 0, function () {

@@ -226,70 +226,2 @@ var reCAPTCHAState, recaptcha;

*/
/**
*
* @param app
* @param siteKeyOrProvider - optional custom attestation provider
* or reCAPTCHA siteKey
* @param isTokenAutoRefreshEnabled - if true, enables auto refresh
* of appCheck token.
*/
function activate(app, siteKeyOrProvider, isTokenAutoRefreshEnabled) {
var state = getState(app);
if (state.activated) {
throw ERROR_FACTORY.create("already-activated" /* ALREADY_ACTIVATED */, {
appName: app.name
});
}
var newState = __assign(__assign({}, state), { activated: true });
if (typeof siteKeyOrProvider === 'string') {
newState.siteKey = siteKeyOrProvider;
}
else {
newState.customProvider = siteKeyOrProvider;
}
// Use value of global `automaticDataCollectionEnabled` (which
// itself defaults to false if not specified in config) if
// `isTokenAutoRefreshEnabled` param was not provided by user.
newState.isTokenAutoRefreshEnabled =
isTokenAutoRefreshEnabled === undefined
? app.automaticDataCollectionEnabled
: isTokenAutoRefreshEnabled;
setState(app, newState);
// initialize reCAPTCHA if siteKey is provided
if (newState.siteKey) {
initialize(app, newState.siteKey).catch(function () {
/* we don't care about the initialization result in activate() */
});
}
}
function setTokenAutoRefreshEnabled(app, isTokenAutoRefreshEnabled) {
var state = getState(app);
// This will exist if any product libraries have called
// `addTokenListener()`
if (state.tokenRefresher) {
if (isTokenAutoRefreshEnabled === true) {
state.tokenRefresher.start();
}
else {
state.tokenRefresher.stop();
}
}
setState(app, __assign(__assign({}, state), { isTokenAutoRefreshEnabled: isTokenAutoRefreshEnabled }));
}
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var BASE_ENDPOINT = 'https://content-firebaseappcheck.googleapis.com/v1beta';

@@ -766,3 +698,3 @@ var EXCHANGE_RECAPTCHA_TOKEN_METHOD = 'exchangeRecaptchaToken';

return __awaiter(this, void 0, void 0, function () {
var existingDebugToken, _e_1, newToken;
var existingDebugToken, newToken;
return __generator(this, function (_a) {

@@ -780,3 +712,3 @@ switch (_a.label) {

case 3:
_e_1 = _a.sent();
_a.sent();
return [3 /*break*/, 4];

@@ -946,3 +878,3 @@ case 4:

return [3 /*break*/, 11];
case 8: return [4 /*yield*/, getToken(app).catch(function (_e) {
case 8: return [4 /*yield*/, getToken$2(app).catch(function (_e) {
// reCaptcha.execute() throws null which is not very descriptive.

@@ -988,5 +920,9 @@ throw ERROR_FACTORY.create("recaptcha-error" /* RECAPTCHA_ERROR */);

}
function addTokenListener(app, platformLoggerProvider, listener) {
function addTokenListener(app, platformLoggerProvider, listener, onError) {
var state = getState(app);
var newState = __assign(__assign({}, state), { tokenListeners: __spreadArray(__spreadArray([], state.tokenListeners), [listener]) });
var tokenListener = {
next: listener,
error: onError
};
var newState = __assign(__assign({}, state), { tokenObservers: __spreadArray(__spreadArray([], state.tokenObservers), [tokenListener]) });
/**

@@ -1003,3 +939,3 @@ * DEBUG MODE

.catch(function () {
/* we don't care about exceptions thrown in listeners */
/** Ignore errors in listeners. */
});

@@ -1030,3 +966,3 @@ }

.catch(function () {
/* we don't care about exceptions thrown in listeners */
/** Ignore errors in listeners. */
});

@@ -1039,4 +975,4 @@ }

var state = getState(app);
var newListeners = state.tokenListeners.filter(function (l) { return l !== listener; });
if (newListeners.length === 0 &&
var newObservers = state.tokenObservers.filter(function (tokenObserver) { return tokenObserver.next !== listener; });
if (newObservers.length === 0 &&
state.tokenRefresher &&

@@ -1046,3 +982,3 @@ state.tokenRefresher.isRunning()) {

}
setState(app, __assign(__assign({}, state), { tokenListeners: newListeners }));
setState(app, __assign(__assign({}, state), { tokenObservers: newObservers }));
}

@@ -1099,9 +1035,22 @@ function createTokenRefresher(app, platformLoggerProvider) {

function notifyTokenListeners(app, token) {
var listeners = getState(app).tokenListeners;
for (var _i = 0, listeners_1 = listeners; _i < listeners_1.length; _i++) {
var listener = listeners_1[_i];
var observers = getState(app).tokenObservers;
for (var _i = 0, observers_1 = observers; _i < observers_1.length; _i++) {
var observer = observers_1[_i];
try {
listener(token);
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);
}
}
else {
// Otherwise return the token, whether or not it has an error field.
observer.next(token);
}
}
catch (e) {
catch (ignored) {
// If any handler fails, ignore and run next handler.

@@ -1137,3 +1086,116 @@ }

*/
function factory(app) {
/**
*
* @param app
* @param siteKeyOrProvider - optional custom attestation provider
* or reCAPTCHA siteKey
* @param isTokenAutoRefreshEnabled - if true, enables auto refresh
* of appCheck token.
*/
function activate(app, siteKeyOrProvider, isTokenAutoRefreshEnabled) {
var state = getState(app);
if (state.activated) {
throw ERROR_FACTORY.create("already-activated" /* ALREADY_ACTIVATED */, {
appName: app.name
});
}
var newState = __assign(__assign({}, state), { activated: true });
if (typeof siteKeyOrProvider === 'string') {
newState.siteKey = siteKeyOrProvider;
}
else {
newState.customProvider = siteKeyOrProvider;
}
// Use value of global `automaticDataCollectionEnabled` (which
// itself defaults to false if not specified in config) if
// `isTokenAutoRefreshEnabled` param was not provided by user.
newState.isTokenAutoRefreshEnabled =
isTokenAutoRefreshEnabled === undefined
? app.automaticDataCollectionEnabled
: isTokenAutoRefreshEnabled;
setState(app, newState);
// initialize reCAPTCHA if siteKey is provided
if (newState.siteKey) {
initialize(app, newState.siteKey).catch(function () {
/* we don't care about the initialization result in activate() */
});
}
}
function setTokenAutoRefreshEnabled(app, isTokenAutoRefreshEnabled) {
var state = getState(app);
// This will exist if any product libraries have called
// `addTokenListener()`
if (state.tokenRefresher) {
if (isTokenAutoRefreshEnabled === true) {
state.tokenRefresher.start();
}
else {
state.tokenRefresher.stop();
}
}
setState(app, __assign(__assign({}, state), { isTokenAutoRefreshEnabled: isTokenAutoRefreshEnabled }));
}
/**
* Differs from internal getToken in that it throws the error.
*/
function getToken(app, platformLoggerProvider, forceRefresh) {
return __awaiter(this, void 0, void 0, function () {
var result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, getToken$1(app, platformLoggerProvider, forceRefresh)];
case 1:
result = _a.sent();
if (result.error) {
throw result.error;
}
return [2 /*return*/, { token: result.token }];
}
});
});
}
function onTokenChanged(app, platformLoggerProvider, onNextOrObserver, onError,
/**
* NOTE: Although an `onCompletion` callback can be provided, it will
* never be called because the token stream is never-ending.
* It is added only for API consistency with the observer pattern, which
* we follow in JS APIs.
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onCompletion) {
var nextFn = function () { };
var errorFn = function () { };
if (onNextOrObserver.next != null) {
nextFn = onNextOrObserver.next.bind(onNextOrObserver);
}
else {
nextFn = onNextOrObserver;
}
if (onNextOrObserver.error != null) {
errorFn = onNextOrObserver.error.bind(onNextOrObserver);
}
else if (onError) {
errorFn = onError;
}
addTokenListener(app, platformLoggerProvider, nextFn, errorFn);
return function () { return removeTokenListener(app, nextFn); };
}
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function factory(app, platformLoggerProvider) {
return {

@@ -1143,2 +1205,14 @@ activate: function (siteKeyOrProvider, isTokenAutoRefreshEnabled) { return activate(app, siteKeyOrProvider, isTokenAutoRefreshEnabled); },

return setTokenAutoRefreshEnabled(app, isTokenAutoRefreshEnabled);
},
getToken: function (forceRefresh) {
return getToken(app, platformLoggerProvider, forceRefresh);
},
onTokenChanged: function (onNextOrObserver, onError, onCompletion) {
return onTokenChanged(app, platformLoggerProvider,
/**
* This can still be an observer. Need to do this casting because
* according to Typescript: "Implementation signatures of overloads
* are not externally visible"
*/
onNextOrObserver, onError);
}

@@ -1160,3 +1234,3 @@ };

var name = "@firebase/app-check";
var version = "0.1.4-202151602035";
var version = "0.1.4-canary.1bbdbfef3";

@@ -1186,3 +1260,4 @@ /**

var app = container.getProvider('app').getImmediate();
return factory(app);
var platformLoggerProvider = container.getProvider('platform-logger');
return factory(app, platformLoggerProvider);
}, "PUBLIC" /* PUBLIC */)

@@ -1189,0 +1264,0 @@ /**

@@ -59,3 +59,3 @@ import firebase from '@firebase/app';

activated: false,
tokenListeners: []
tokenObservers: []
};

@@ -160,3 +160,3 @@ const DEBUG_STATE = {

}
async function getToken(app) {
async function getToken$2(app) {
ensureActivated(app);

@@ -215,70 +215,2 @@ // ensureActivated() guarantees that reCAPTCHAState is set

*/
/**
*
* @param app
* @param siteKeyOrProvider - optional custom attestation provider
* or reCAPTCHA siteKey
* @param isTokenAutoRefreshEnabled - if true, enables auto refresh
* of appCheck token.
*/
function activate(app, siteKeyOrProvider, isTokenAutoRefreshEnabled) {
const state = getState(app);
if (state.activated) {
throw ERROR_FACTORY.create("already-activated" /* ALREADY_ACTIVATED */, {
appName: app.name
});
}
const newState = Object.assign(Object.assign({}, state), { activated: true });
if (typeof siteKeyOrProvider === 'string') {
newState.siteKey = siteKeyOrProvider;
}
else {
newState.customProvider = siteKeyOrProvider;
}
// Use value of global `automaticDataCollectionEnabled` (which
// itself defaults to false if not specified in config) if
// `isTokenAutoRefreshEnabled` param was not provided by user.
newState.isTokenAutoRefreshEnabled =
isTokenAutoRefreshEnabled === undefined
? app.automaticDataCollectionEnabled
: isTokenAutoRefreshEnabled;
setState(app, newState);
// initialize reCAPTCHA if siteKey is provided
if (newState.siteKey) {
initialize(app, newState.siteKey).catch(() => {
/* we don't care about the initialization result in activate() */
});
}
}
function setTokenAutoRefreshEnabled(app, isTokenAutoRefreshEnabled) {
const state = getState(app);
// This will exist if any product libraries have called
// `addTokenListener()`
if (state.tokenRefresher) {
if (isTokenAutoRefreshEnabled === true) {
state.tokenRefresher.start();
}
else {
state.tokenRefresher.stop();
}
}
setState(app, Object.assign(Object.assign({}, state), { isTokenAutoRefreshEnabled }));
}
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const BASE_ENDPOINT = 'https://content-firebaseappcheck.googleapis.com/v1beta';

@@ -852,3 +784,3 @@ const EXCHANGE_RECAPTCHA_TOKEN_METHOD = 'exchangeRecaptchaToken';

else {
const attestedClaimsToken = await getToken(app).catch(_e => {
const attestedClaimsToken = await getToken$2(app).catch(_e => {
// reCaptcha.execute() throws null which is not very descriptive.

@@ -883,5 +815,9 @@ throw ERROR_FACTORY.create("recaptcha-error" /* RECAPTCHA_ERROR */);

}
function addTokenListener(app, platformLoggerProvider, listener) {
function addTokenListener(app, platformLoggerProvider, listener, onError) {
const state = getState(app);
const newState = Object.assign(Object.assign({}, state), { tokenListeners: [...state.tokenListeners, listener] });
const tokenListener = {
next: listener,
error: onError
};
const newState = Object.assign(Object.assign({}, state), { tokenObservers: [...state.tokenObservers, tokenListener] });
/**

@@ -898,3 +834,3 @@ * DEBUG MODE

.catch(() => {
/* we don't care about exceptions thrown in listeners */
/** Ignore errors in listeners. */
});

@@ -925,3 +861,3 @@ }

.catch(() => {
/* we don't care about exceptions thrown in listeners */
/** Ignore errors in listeners. */
});

@@ -934,4 +870,4 @@ }

const state = getState(app);
const newListeners = state.tokenListeners.filter(l => l !== listener);
if (newListeners.length === 0 &&
const newObservers = state.tokenObservers.filter(tokenObserver => tokenObserver.next !== listener);
if (newObservers.length === 0 &&
state.tokenRefresher &&

@@ -941,3 +877,3 @@ state.tokenRefresher.isRunning()) {

}
setState(app, Object.assign(Object.assign({}, state), { tokenListeners: newListeners }));
setState(app, Object.assign(Object.assign({}, state), { tokenObservers: newObservers }));
}

@@ -985,8 +921,21 @@ function createTokenRefresher(app, platformLoggerProvider) {

function notifyTokenListeners(app, token) {
const listeners = getState(app).tokenListeners;
for (const listener of listeners) {
const observers = getState(app).tokenObservers;
for (const observer of observers) {
try {
listener(token);
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);
}
}
else {
// Otherwise return the token, whether or not it has an error field.
observer.next(token);
}
}
catch (e) {
catch (ignored) {
// If any handler fails, ignore and run next handler.

@@ -1022,6 +971,118 @@ }

*/
function factory(app) {
/**
*
* @param app
* @param siteKeyOrProvider - optional custom attestation provider
* or reCAPTCHA siteKey
* @param isTokenAutoRefreshEnabled - if true, enables auto refresh
* of appCheck token.
*/
function activate(app, siteKeyOrProvider, isTokenAutoRefreshEnabled) {
const state = getState(app);
if (state.activated) {
throw ERROR_FACTORY.create("already-activated" /* ALREADY_ACTIVATED */, {
appName: app.name
});
}
const newState = Object.assign(Object.assign({}, state), { activated: true });
if (typeof siteKeyOrProvider === 'string') {
newState.siteKey = siteKeyOrProvider;
}
else {
newState.customProvider = siteKeyOrProvider;
}
// Use value of global `automaticDataCollectionEnabled` (which
// itself defaults to false if not specified in config) if
// `isTokenAutoRefreshEnabled` param was not provided by user.
newState.isTokenAutoRefreshEnabled =
isTokenAutoRefreshEnabled === undefined
? app.automaticDataCollectionEnabled
: isTokenAutoRefreshEnabled;
setState(app, newState);
// initialize reCAPTCHA if siteKey is provided
if (newState.siteKey) {
initialize(app, newState.siteKey).catch(() => {
/* we don't care about the initialization result in activate() */
});
}
}
function setTokenAutoRefreshEnabled(app, isTokenAutoRefreshEnabled) {
const state = getState(app);
// This will exist if any product libraries have called
// `addTokenListener()`
if (state.tokenRefresher) {
if (isTokenAutoRefreshEnabled === true) {
state.tokenRefresher.start();
}
else {
state.tokenRefresher.stop();
}
}
setState(app, Object.assign(Object.assign({}, state), { isTokenAutoRefreshEnabled }));
}
/**
* Differs from internal getToken in that it throws the error.
*/
async function getToken(app, platformLoggerProvider, forceRefresh) {
const result = await getToken$1(app, platformLoggerProvider, forceRefresh);
if (result.error) {
throw result.error;
}
return { token: result.token };
}
function onTokenChanged(app, platformLoggerProvider, onNextOrObserver, onError,
/**
* NOTE: Although an `onCompletion` callback can be provided, it will
* never be called because the token stream is never-ending.
* It is added only for API consistency with the observer pattern, which
* we follow in JS APIs.
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onCompletion) {
let nextFn = () => { };
let errorFn = () => { };
if (onNextOrObserver.next != null) {
nextFn = onNextOrObserver.next.bind(onNextOrObserver);
}
else {
nextFn = onNextOrObserver;
}
if (onNextOrObserver.error != null) {
errorFn = onNextOrObserver.error.bind(onNextOrObserver);
}
else if (onError) {
errorFn = onError;
}
addTokenListener(app, platformLoggerProvider, nextFn, errorFn);
return () => removeTokenListener(app, nextFn);
}
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function factory(app, platformLoggerProvider) {
return {
activate: (siteKeyOrProvider, isTokenAutoRefreshEnabled) => activate(app, siteKeyOrProvider, isTokenAutoRefreshEnabled),
setTokenAutoRefreshEnabled: (isTokenAutoRefreshEnabled) => setTokenAutoRefreshEnabled(app, isTokenAutoRefreshEnabled)
setTokenAutoRefreshEnabled: (isTokenAutoRefreshEnabled) => setTokenAutoRefreshEnabled(app, isTokenAutoRefreshEnabled),
getToken: forceRefresh => getToken(app, platformLoggerProvider, forceRefresh),
onTokenChanged: (onNextOrObserver, onError, onCompletion) => onTokenChanged(app, platformLoggerProvider,
/**
* This can still be an observer. Need to do this casting because
* according to Typescript: "Implementation signatures of overloads
* are not externally visible"
*/
onNextOrObserver, onError)
};

@@ -1038,3 +1099,3 @@ }

const name = "@firebase/app-check";
const version = "0.1.4-202151602035";
const version = "0.1.4-canary.1bbdbfef3";

@@ -1064,3 +1125,4 @@ /**

const app = container.getProvider('app').getImmediate();
return factory(app);
const platformLoggerProvider = container.getProvider('platform-logger');
return factory(app, platformLoggerProvider);
}, "PUBLIC" /* PUBLIC */)

@@ -1067,0 +1129,0 @@ /**

@@ -17,4 +17,6 @@ /**

*/
import { AppCheckProvider } from '@firebase/app-check-types';
import { AppCheckProvider, AppCheckTokenResult } from '@firebase/app-check-types';
import { FirebaseApp } from '@firebase/app-types';
import { Provider } from '@firebase/component';
import { PartialObserver, Unsubscribe } from '@firebase/util';
/**

@@ -30,1 +32,11 @@ *

export declare function setTokenAutoRefreshEnabled(app: FirebaseApp, isTokenAutoRefreshEnabled: boolean): void;
/**
* Differs from internal getToken in that it throws the error.
*/
export declare function getToken(app: FirebaseApp, platformLoggerProvider: Provider<'platform-logger'>, forceRefresh?: boolean): Promise<AppCheckTokenResult>;
/**
* Wraps addTokenListener/removeTokenListener methods in an Observer
* pattern for public use.
*/
export declare function onTokenChanged(app: FirebaseApp, platformLoggerProvider: Provider<'platform-logger'>, observer: PartialObserver<AppCheckTokenResult>): Unsubscribe;
export declare function onTokenChanged(app: FirebaseApp, platformLoggerProvider: Provider<'platform-logger'>, onNext: (tokenResult: AppCheckTokenResult) => void, onError?: (error: Error) => void, onCompletion?: () => void): Unsubscribe;

@@ -21,3 +21,3 @@ /**

import { Provider } from '@firebase/component';
export declare function factory(app: FirebaseApp): FirebaseAppCheck;
export declare function factory(app: FirebaseApp, platformLoggerProvider: Provider<'platform-logger'>): FirebaseAppCheck;
export declare function internalFactory(app: FirebaseApp, platformLoggerProvider: Provider<'platform-logger'>): FirebaseAppCheckInternal;

@@ -18,3 +18,3 @@ /**

import { FirebaseApp } from '@firebase/app-types';
import { AppCheckTokenResult, AppCheckTokenListener } from '@firebase/app-check-interop-types';
import { AppCheckTokenListener, AppCheckTokenResult } from '@firebase/app-check-interop-types';
import { Provider } from '@firebase/component';

@@ -36,3 +36,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): void;
export declare function removeTokenListener(app: FirebaseApp, listener: AppCheckTokenListener): void;
export declare function addTokenListener(app: FirebaseApp, platformLoggerProvider: Provider<'platform-logger'>, listener: AppCheckTokenListener, onError?: (error: Error) => void): void;
export declare function removeTokenListener(app: FirebaseApp, listener: (token: AppCheckTokenResult) => void): void;

@@ -18,6 +18,6 @@ /**

import { FirebaseApp } from '@firebase/app-types';
import { AppCheckProvider, AppCheckToken } from '@firebase/app-check-types';
import { AppCheckProvider, AppCheckToken, AppCheckTokenResult } from '@firebase/app-check-types';
import { AppCheckTokenListener } from '@firebase/app-check-interop-types';
import { Refresher } from './proactive-refresh';
import { Deferred } from '@firebase/util';
import { Deferred, PartialObserver } from '@firebase/util';
import { GreCAPTCHA } from './recaptcha';

@@ -27,5 +27,8 @@ export interface AppCheckTokenInternal extends AppCheckToken {

}
export interface AppCheckTokenObserver extends PartialObserver<AppCheckTokenResult> {
next: AppCheckTokenListener;
}
export interface AppCheckState {
activated: boolean;
tokenListeners: AppCheckTokenListener[];
tokenObservers: AppCheckTokenObserver[];
customProvider?: AppCheckProvider;

@@ -32,0 +35,0 @@ siteKey?: string;

{
"name": "@firebase/app-check",
"version": "0.1.4-202151602035",
"version": "0.1.4-canary.1bbdbfef3",
"description": "The App Check component of the Firebase JS SDK",

@@ -19,3 +19,3 @@ "author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",

"dev": "rollup -c -w",
"test": "yarn type-check && yarn test:browser",
"test": "yarn lint && yarn type-check && yarn test:browser",
"test:ci": "node ../../scripts/run_tests_in_ci.js",

@@ -28,11 +28,11 @@ "test:browser": "karma start --single-run",

"peerDependencies": {
"@firebase/app": "0.6.27-202151602035",
"@firebase/app-types": "0.x"
"@firebase/app": "0.6.27-canary.1bbdbfef3",
"@firebase/app-types": "0.6.2-canary.1bbdbfef3"
},
"dependencies": {
"@firebase/app-check-types": "0.1.0",
"@firebase/app-check-interop-types": "0.1.0",
"@firebase/util": "1.1.0",
"@firebase/component": "0.5.3-202151602035",
"@firebase/logger": "0.2.6",
"@firebase/app-check-types": "0.1.0-canary.1bbdbfef3",
"@firebase/app-check-interop-types": "0.1.0-canary.1bbdbfef3",
"@firebase/util": "1.1.0-canary.1bbdbfef3",
"@firebase/component": "0.5.3-canary.1bbdbfef3",
"@firebase/logger": "0.2.6-canary.1bbdbfef3",
"tslib": "^2.1.0"

@@ -42,6 +42,6 @@ },

"devDependencies": {
"@firebase/app": "0.6.27-202151602035",
"rollup": "2.35.1",
"@firebase/app": "0.6.27-canary.1bbdbfef3",
"rollup": "2.52.2",
"@rollup/plugin-json": "4.1.0",
"rollup-plugin-typescript2": "0.29.0",
"rollup-plugin-typescript2": "0.30.0",
"typescript": "4.2.2"

@@ -64,2 +64,2 @@ },

}
}
}

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