Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@firebase/app-check

Package Overview
Dependencies
Maintainers
5
Versions
1341
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@firebase/app-check - npm Package Compare versions

Comparing version 0.0.900-exp.57f19127c to 0.0.900-exp.f43d0c698

70

dist/app-check-exp-public.d.ts
import { FirebaseApp } from '@firebase/app';
import { PartialObserver } from '@firebase/util';
import { Unsubscribe } from '@firebase/util';

@@ -59,2 +61,19 @@ /**

/**
* A listener that is called whenever the App Check token changes.
* @public
*/
export declare type AppCheckTokenListener = (token: AppCheckTokenResult) => void;
/**
* Result returned by `getToken()`.
* @public
*/
export declare interface AppCheckTokenResult {
/**
* The token string in JWT format.
*/
readonly token: string;
}
/**
* Custom provider class.

@@ -84,2 +103,14 @@ * @public

/**
* Get the current App Check token. Attaches to the most recent
* in-flight request if one is present. Returns null if no token
* is present and no token requests are in-flight.
*
* @param appCheckInstance - The App Check service instance.
* @param forceRefresh - If true, will always try to fetch a fresh token.
* If false, will use a cached token if found in storage.
* @public
*/
export declare function getToken(appCheckInstance: AppCheck, forceRefresh?: boolean): Promise<AppCheckTokenResult>;
/**
* Activate App Check for the given app. Can be called only once per app.

@@ -93,2 +124,38 @@ * @param app - the FirebaseApp to activate App Check for

/**
* Registers a listener to changes in the token state. There can be more
* than one listener registered at the same time for one or more
* App Check instances. The listeners call back on the UI thread whenever
* the current token associated with this App Check instance changes.
*
* @param appCheckInstance - The App Check service instance.
* @param observer - An object with `next`, `error`, and `complete`
* properties. `next` is called with an
* {@link AppCheckTokenResult}
* whenever the token changes. `error` is optional and is called if an
* error is thrown by the listener (the `next` function). `complete`
* is unused, as the token stream is unending.
*
* @returns A function that unsubscribes this listener.
* @public
*/
export declare function onTokenChanged(appCheckInstance: AppCheck, observer: PartialObserver<AppCheckTokenResult>): Unsubscribe;
/**
* Registers a listener to changes in the token state. There can be more
* than one listener registered at the same time for one or more
* App Check instances. The listeners call back on the UI thread whenever
* the current token associated with this App Check instance changes.
*
* @param appCheckInstance - The App Check service instance.
* @param onNext - When the token changes, this function is called with aa
* {@link AppCheckTokenResult}.
* @param onError - Optional. Called if there is an error thrown by the
* listener (the `onNext` function).
* @param onCompletion - Currently unused, as the token stream is unending.
* @returns A function that unsubscribes this listener.
* @public
*/
export declare function onTokenChanged(appCheckInstance: AppCheck, onNext: (tokenResult: AppCheckTokenResult) => void, onError?: (error: Error) => void, onCompletion?: () => void): Unsubscribe;
/**
* App Check provider that can obtain a reCAPTCHA V3 token and exchange it

@@ -115,2 +182,3 @@ * for an App Check token.

*
* @param appCheckInstance - The App Check service instance.
* @param isTokenAutoRefreshEnabled - If true, the SDK automatically

@@ -121,4 +189,4 @@ * refreshes App Check tokens as needed. This overrides any value set

*/
export declare function setTokenAutoRefreshEnabled(app: FirebaseApp, isTokenAutoRefreshEnabled: boolean): void;
export declare function setTokenAutoRefreshEnabled(appCheckInstance: AppCheck, isTokenAutoRefreshEnabled: boolean): void;
export { }
import { FirebaseApp } from '@firebase/app';
import { PartialObserver } from '@firebase/util';
import { Unsubscribe } from '@firebase/util';

@@ -65,2 +67,19 @@ /**

/**
* A listener that is called whenever the App Check token changes.
* @public
*/
export declare type AppCheckTokenListener = (token: AppCheckTokenResult) => void;
/**
* Result returned by `getToken()`.
* @public
*/
export declare interface AppCheckTokenResult {
/**
* The token string in JWT format.
*/
readonly token: string;
}
/**
* Custom provider class.

@@ -96,2 +115,14 @@ * @public

/**
* Get the current App Check token. Attaches to the most recent
* in-flight request if one is present. Returns null if no token
* is present and no token requests are in-flight.
*
* @param appCheckInstance - The App Check service instance.
* @param forceRefresh - If true, will always try to fetch a fresh token.
* If false, will use a cached token if found in storage.
* @public
*/
export declare function getToken(appCheckInstance: AppCheck, forceRefresh?: boolean): Promise<AppCheckTokenResult>;
/**
* Activate App Check for the given app. Can be called only once per app.

@@ -105,2 +136,38 @@ * @param app - the FirebaseApp to activate App Check for

/**
* Registers a listener to changes in the token state. There can be more
* than one listener registered at the same time for one or more
* App Check instances. The listeners call back on the UI thread whenever
* the current token associated with this App Check instance changes.
*
* @param appCheckInstance - The App Check service instance.
* @param observer - An object with `next`, `error`, and `complete`
* properties. `next` is called with an
* {@link AppCheckTokenResult}
* whenever the token changes. `error` is optional and is called if an
* error is thrown by the listener (the `next` function). `complete`
* is unused, as the token stream is unending.
*
* @returns A function that unsubscribes this listener.
* @public
*/
export declare function onTokenChanged(appCheckInstance: AppCheck, observer: PartialObserver<AppCheckTokenResult>): Unsubscribe;
/**
* Registers a listener to changes in the token state. There can be more
* than one listener registered at the same time for one or more
* App Check instances. The listeners call back on the UI thread whenever
* the current token associated with this App Check instance changes.
*
* @param appCheckInstance - The App Check service instance.
* @param onNext - When the token changes, this function is called with aa
* {@link AppCheckTokenResult}.
* @param onError - Optional. Called if there is an error thrown by the
* listener (the `onNext` function).
* @param onCompletion - Currently unused, as the token stream is unending.
* @returns A function that unsubscribes this listener.
* @public
*/
export declare function onTokenChanged(appCheckInstance: AppCheck, onNext: (tokenResult: AppCheckTokenResult) => void, onError?: (error: Error) => void, onCompletion?: () => void): Unsubscribe;
/**
* App Check provider that can obtain a reCAPTCHA V3 token and exchange it

@@ -134,2 +201,3 @@ * for an App Check token.

*
* @param appCheckInstance - The App Check service instance.
* @param isTokenAutoRefreshEnabled - If true, the SDK automatically

@@ -140,4 +208,4 @@ * refreshes App Check tokens as needed. This overrides any value set

*/
export declare function setTokenAutoRefreshEnabled(app: FirebaseApp, isTokenAutoRefreshEnabled: boolean): void;
export declare function setTokenAutoRefreshEnabled(appCheckInstance: AppCheck, isTokenAutoRefreshEnabled: boolean): void;
export { }

161

dist/index.cjs.js

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

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

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

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

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

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

@@ -729,9 +729,10 @@ case 4:

*/
function getToken(app, platformLoggerProvider, forceRefresh) {
function getToken$2(appCheck, forceRefresh) {
if (forceRefresh === void 0) { forceRefresh = false; }
return tslib.__awaiter(this, void 0, void 0, function () {
var tokenFromDebugExchange, _a, _b, _c, state, token, error, cachedToken, e_1, interopTokenResult;
var app, tokenFromDebugExchange, _a, _b, _c, state, token, error, cachedToken, e_1, interopTokenResult;
return tslib.__generator(this, function (_d) {
switch (_d.label) {
case 0:
app = appCheck.app;
ensureActivated(app);

@@ -743,3 +744,3 @@ if (!isDebugMode()) return [3 /*break*/, 3];

return [4 /*yield*/, getDebugToken()];
case 1: return [4 /*yield*/, _a.apply(void 0, [_b.apply(void 0, _c.concat([_d.sent()])), platformLoggerProvider])];
case 1: return [4 /*yield*/, _a.apply(void 0, [_b.apply(void 0, _c.concat([_d.sent()])), appCheck.platformLoggerProvider])];
case 2:

@@ -810,5 +811,11 @@ tokenFromDebugExchange = _d.sent();

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

@@ -836,3 +843,3 @@ * DEBUG MODE

if (!newState.tokenRefresher) {
var tokenRefresher = createTokenRefresher(app, platformLoggerProvider);
var tokenRefresher = createTokenRefresher(appCheck);
newState.tokenRefresher = tokenRefresher;

@@ -860,4 +867,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 &&

@@ -867,6 +874,7 @@ state.tokenRefresher.isRunning()) {

}
setState(app, tslib.__assign(tslib.__assign({}, state), { tokenListeners: newListeners }));
setState(app, tslib.__assign(tslib.__assign({}, state), { tokenObservers: newObservers }));
}
function createTokenRefresher(app, platformLoggerProvider) {
function createTokenRefresher(appCheck) {
var _this = this;
var app = appCheck.app;
return new Refresher(

@@ -882,7 +890,7 @@ // Keep in mind when this fails for any reason other than the ones

if (!!state.token) return [3 /*break*/, 2];
return [4 /*yield*/, getToken(app, platformLoggerProvider)];
return [4 /*yield*/, getToken$2(appCheck)];
case 1:
result = _a.sent();
return [3 /*break*/, 4];
case 2: return [4 /*yield*/, getToken(app, platformLoggerProvider, true)];
case 2: return [4 /*yield*/, getToken$2(appCheck, true)];
case 3:

@@ -921,10 +929,21 @@ result = _a.sent();

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.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 {
// 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);
}
}
catch (e) {
// If any handler fails, ignore and run next handler.
// Errors in the listener function itself are always ignored.
}

@@ -963,4 +982,5 @@ }

var AppCheckService = /** @class */ (function () {
function AppCheckService(app) {
function AppCheckService(app, platformLoggerProvider) {
this.app = app;
this.platformLoggerProvider = platformLoggerProvider;
}

@@ -972,14 +992,12 @@ AppCheckService.prototype._delete = function () {

}());
function factory(app) {
return new AppCheckService(app);
function factory(app, platformLoggerProvider) {
return new AppCheckService(app, platformLoggerProvider);
}
function internalFactory(app, platformLoggerProvider) {
function internalFactory(appCheck) {
return {
getToken: function (forceRefresh) {
return getToken(app, platformLoggerProvider, forceRefresh);
},
getToken: function (forceRefresh) { return getToken$2(appCheck, forceRefresh); },
addTokenListener: function (listener) {
return addTokenListener(app, platformLoggerProvider, listener);
return addTokenListener(appCheck, "INTERNAL" /* INTERNAL */, listener);
},
removeTokenListener: function (listener) { return removeTokenListener(app, listener); }
removeTokenListener: function (listener) { return removeTokenListener(appCheck.app, listener); }
};

@@ -989,3 +1007,3 @@ }

var name = "@firebase/app-check-exp";
var version = "0.0.900-exp.57f19127c";
var version = "0.0.900-exp.f43d0c698";

@@ -1269,2 +1287,3 @@ /**

*
* @param appCheckInstance - The App Check service instance.
* @param isTokenAutoRefreshEnabled - If true, the SDK automatically

@@ -1275,3 +1294,4 @@ * refreshes App Check tokens as needed. This overrides any value set

*/
function setTokenAutoRefreshEnabled(app, isTokenAutoRefreshEnabled) {
function setTokenAutoRefreshEnabled(appCheckInstance, isTokenAutoRefreshEnabled) {
var app = appCheckInstance.app;
var state = getState(app);

@@ -1290,2 +1310,58 @@ // This will exist if any product libraries have called

}
/**
* Get the current App Check token. Attaches to the most recent
* in-flight request if one is present. Returns null if no token
* is present and no token requests are in-flight.
*
* @param appCheckInstance - The App Check service instance.
* @param forceRefresh - If true, will always try to fetch a fresh token.
* If false, will use a cached token if found in storage.
* @public
*/
function getToken(appCheckInstance, 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$2(appCheckInstance, forceRefresh)];
case 1:
result = _a.sent();
if (result.error) {
throw result.error;
}
return [2 /*return*/, { token: result.token }];
}
});
});
}
/**
* Wraps addTokenListener/removeTokenListener methods in an Observer
* pattern for public use.
*/
function onTokenChanged(appCheckInstance, 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(appCheckInstance, "EXTERNAL" /* EXTERNAL */, nextFn, errorFn);
return function () { return removeTokenListener(appCheckInstance.app, nextFn); };
}

@@ -1315,11 +1391,18 @@ /**

var app = container.getProvider('app-exp').getImmediate();
return factory(app);
}, "PUBLIC" /* PUBLIC */));
var platformLoggerProvider = container.getProvider('platform-logger');
return factory(app, platformLoggerProvider);
}, "PUBLIC" /* PUBLIC */)
.setInstantiationMode("EXPLICIT" /* EXPLICIT */)
/**
* Initialize app-check-internal after app-check is initialized to make AppCheck available to
* other Firebase SDKs
*/
.setInstanceCreatedCallback(function (container, _identifier, _appcheckService) {
container.getProvider(APP_CHECK_NAME_INTERNAL).initialize();
}));
// The internal interface used by other Firebase products
app._registerComponent(new component.Component(APP_CHECK_NAME_INTERNAL, function (container) {
// getImmediate for FirebaseApp will always succeed
var app = container.getProvider('app-exp').getImmediate();
var platformLoggerProvider = container.getProvider('platform-logger');
return internalFactory(app, platformLoggerProvider);
}, "PUBLIC" /* PUBLIC */));
var appCheck = container.getProvider('app-check-exp').getImmediate();
return internalFactory(appCheck);
}, "PUBLIC" /* PUBLIC */).setInstantiationMode("EXPLICIT" /* EXPLICIT */));
app.registerVersion(name, version);

@@ -1332,4 +1415,6 @@ }

exports.ReCaptchaV3Provider = ReCaptchaV3Provider;
exports.getToken = getToken;
exports.initializeAppCheck = initializeAppCheck;
exports.onTokenChanged = onTokenChanged;
exports.setTokenAutoRefreshEnabled = setTokenAutoRefreshEnabled;
//# sourceMappingURL=index.cjs.js.map

@@ -26,3 +26,3 @@ import { _getProvider, getApp, _registerComponent, registerVersion } from '@firebase/app';

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

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

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

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

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

@@ -725,9 +725,10 @@ case 4:

*/
function getToken(app, platformLoggerProvider, forceRefresh) {
function getToken$2(appCheck, forceRefresh) {
if (forceRefresh === void 0) { forceRefresh = false; }
return __awaiter(this, void 0, void 0, function () {
var tokenFromDebugExchange, _a, _b, _c, state, token, error, cachedToken, e_1, interopTokenResult;
var app, tokenFromDebugExchange, _a, _b, _c, state, token, error, cachedToken, e_1, interopTokenResult;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
app = appCheck.app;
ensureActivated(app);

@@ -739,3 +740,3 @@ if (!isDebugMode()) return [3 /*break*/, 3];

return [4 /*yield*/, getDebugToken()];
case 1: return [4 /*yield*/, _a.apply(void 0, [_b.apply(void 0, _c.concat([_d.sent()])), platformLoggerProvider])];
case 1: return [4 /*yield*/, _a.apply(void 0, [_b.apply(void 0, _c.concat([_d.sent()])), appCheck.platformLoggerProvider])];
case 2:

@@ -806,5 +807,11 @@ tokenFromDebugExchange = _d.sent();

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

@@ -832,3 +839,3 @@ * DEBUG MODE

if (!newState.tokenRefresher) {
var tokenRefresher = createTokenRefresher(app, platformLoggerProvider);
var tokenRefresher = createTokenRefresher(appCheck);
newState.tokenRefresher = tokenRefresher;

@@ -856,4 +863,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 &&

@@ -863,6 +870,7 @@ state.tokenRefresher.isRunning()) {

}
setState(app, __assign(__assign({}, state), { tokenListeners: newListeners }));
setState(app, __assign(__assign({}, state), { tokenObservers: newObservers }));
}
function createTokenRefresher(app, platformLoggerProvider) {
function createTokenRefresher(appCheck) {
var _this = this;
var app = appCheck.app;
return new Refresher(

@@ -878,7 +886,7 @@ // Keep in mind when this fails for any reason other than the ones

if (!!state.token) return [3 /*break*/, 2];
return [4 /*yield*/, getToken(app, platformLoggerProvider)];
return [4 /*yield*/, getToken$2(appCheck)];
case 1:
result = _a.sent();
return [3 /*break*/, 4];
case 2: return [4 /*yield*/, getToken(app, platformLoggerProvider, true)];
case 2: return [4 /*yield*/, getToken$2(appCheck, true)];
case 3:

@@ -917,10 +925,21 @@ result = _a.sent();

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.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 {
// 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);
}
}
catch (e) {
// If any handler fails, ignore and run next handler.
// Errors in the listener function itself are always ignored.
}

@@ -959,4 +978,5 @@ }

var AppCheckService = /** @class */ (function () {
function AppCheckService(app) {
function AppCheckService(app, platformLoggerProvider) {
this.app = app;
this.platformLoggerProvider = platformLoggerProvider;
}

@@ -968,14 +988,12 @@ AppCheckService.prototype._delete = function () {

}());
function factory(app) {
return new AppCheckService(app);
function factory(app, platformLoggerProvider) {
return new AppCheckService(app, platformLoggerProvider);
}
function internalFactory(app, platformLoggerProvider) {
function internalFactory(appCheck) {
return {
getToken: function (forceRefresh) {
return getToken(app, platformLoggerProvider, forceRefresh);
},
getToken: function (forceRefresh) { return getToken$2(appCheck, forceRefresh); },
addTokenListener: function (listener) {
return addTokenListener(app, platformLoggerProvider, listener);
return addTokenListener(appCheck, "INTERNAL" /* INTERNAL */, listener);
},
removeTokenListener: function (listener) { return removeTokenListener(app, listener); }
removeTokenListener: function (listener) { return removeTokenListener(appCheck.app, listener); }
};

@@ -985,3 +1003,3 @@ }

var name = "@firebase/app-check-exp";
var version = "0.0.900-exp.57f19127c";
var version = "0.0.900-exp.f43d0c698";

@@ -1265,2 +1283,3 @@ /**

*
* @param appCheckInstance - The App Check service instance.
* @param isTokenAutoRefreshEnabled - If true, the SDK automatically

@@ -1271,3 +1290,4 @@ * refreshes App Check tokens as needed. This overrides any value set

*/
function setTokenAutoRefreshEnabled(app, isTokenAutoRefreshEnabled) {
function setTokenAutoRefreshEnabled(appCheckInstance, isTokenAutoRefreshEnabled) {
var app = appCheckInstance.app;
var state = getState(app);

@@ -1286,2 +1306,58 @@ // This will exist if any product libraries have called

}
/**
* Get the current App Check token. Attaches to the most recent
* in-flight request if one is present. Returns null if no token
* is present and no token requests are in-flight.
*
* @param appCheckInstance - The App Check service instance.
* @param forceRefresh - If true, will always try to fetch a fresh token.
* If false, will use a cached token if found in storage.
* @public
*/
function getToken(appCheckInstance, 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$2(appCheckInstance, forceRefresh)];
case 1:
result = _a.sent();
if (result.error) {
throw result.error;
}
return [2 /*return*/, { token: result.token }];
}
});
});
}
/**
* Wraps addTokenListener/removeTokenListener methods in an Observer
* pattern for public use.
*/
function onTokenChanged(appCheckInstance, 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(appCheckInstance, "EXTERNAL" /* EXTERNAL */, nextFn, errorFn);
return function () { return removeTokenListener(appCheckInstance.app, nextFn); };
}

@@ -1311,11 +1387,18 @@ /**

var app = container.getProvider('app-exp').getImmediate();
return factory(app);
}, "PUBLIC" /* PUBLIC */));
var platformLoggerProvider = container.getProvider('platform-logger');
return factory(app, platformLoggerProvider);
}, "PUBLIC" /* PUBLIC */)
.setInstantiationMode("EXPLICIT" /* EXPLICIT */)
/**
* Initialize app-check-internal after app-check is initialized to make AppCheck available to
* other Firebase SDKs
*/
.setInstanceCreatedCallback(function (container, _identifier, _appcheckService) {
container.getProvider(APP_CHECK_NAME_INTERNAL).initialize();
}));
// The internal interface used by other Firebase products
_registerComponent(new Component(APP_CHECK_NAME_INTERNAL, function (container) {
// getImmediate for FirebaseApp will always succeed
var app = container.getProvider('app-exp').getImmediate();
var platformLoggerProvider = container.getProvider('platform-logger');
return internalFactory(app, platformLoggerProvider);
}, "PUBLIC" /* PUBLIC */));
var appCheck = container.getProvider('app-check-exp').getImmediate();
return internalFactory(appCheck);
}, "PUBLIC" /* PUBLIC */).setInstantiationMode("EXPLICIT" /* EXPLICIT */));
registerVersion(name, version);

@@ -1326,3 +1409,3 @@ }

export { CustomProvider, ReCaptchaV3Provider, initializeAppCheck, setTokenAutoRefreshEnabled };
export { CustomProvider, ReCaptchaV3Provider, getToken, initializeAppCheck, onTokenChanged, setTokenAutoRefreshEnabled };
//# sourceMappingURL=index.esm.js.map

@@ -25,3 +25,3 @@ import { _getProvider, getApp, _registerComponent, registerVersion } from '@firebase/app';

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

@@ -643,3 +643,4 @@ const DEBUG_STATE = {

*/
async function getToken(app, platformLoggerProvider, forceRefresh = false) {
async function getToken$2(appCheck, forceRefresh = false) {
const app = appCheck.app;
ensureActivated(app);

@@ -651,3 +652,3 @@ /**

if (isDebugMode()) {
const tokenFromDebugExchange = await exchangeToken(getExchangeDebugTokenRequest(app, await getDebugToken()), platformLoggerProvider);
const tokenFromDebugExchange = await exchangeToken(getExchangeDebugTokenRequest(app, await getDebugToken()), appCheck.platformLoggerProvider);
return { token: tokenFromDebugExchange.token };

@@ -709,5 +710,11 @@ }

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

@@ -735,3 +742,3 @@ * DEBUG MODE

if (!newState.tokenRefresher) {
const tokenRefresher = createTokenRefresher(app, platformLoggerProvider);
const tokenRefresher = createTokenRefresher(appCheck);
newState.tokenRefresher = tokenRefresher;

@@ -759,4 +766,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 &&

@@ -766,5 +773,6 @@ state.tokenRefresher.isRunning()) {

}
setState(app, Object.assign(Object.assign({}, state), { tokenListeners: newListeners }));
setState(app, Object.assign(Object.assign({}, state), { tokenObservers: newObservers }));
}
function createTokenRefresher(app, platformLoggerProvider) {
function createTokenRefresher(appCheck) {
const { app } = appCheck;
return new Refresher(

@@ -779,6 +787,6 @@ // Keep in mind when this fails for any reason other than the ones

if (!state.token) {
result = await getToken(app, platformLoggerProvider);
result = await getToken$2(appCheck);
}
else {
result = await getToken(app, platformLoggerProvider, true);
result = await getToken$2(appCheck, true);
}

@@ -811,9 +819,20 @@ // getToken() always resolves. In case the result has an error field defined, it means the operation failed, and we should retry.

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.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 {
// 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);
}
}
catch (e) {
// If any handler fails, ignore and run next handler.
// Errors in the listener function itself are always ignored.
}

@@ -852,4 +871,5 @@ }

class AppCheckService {
constructor(app) {
constructor(app, platformLoggerProvider) {
this.app = app;
this.platformLoggerProvider = platformLoggerProvider;
}

@@ -860,10 +880,10 @@ _delete() {

}
function factory(app) {
return new AppCheckService(app);
function factory(app, platformLoggerProvider) {
return new AppCheckService(app, platformLoggerProvider);
}
function internalFactory(app, platformLoggerProvider) {
function internalFactory(appCheck) {
return {
getToken: forceRefresh => getToken(app, platformLoggerProvider, forceRefresh),
addTokenListener: listener => addTokenListener(app, platformLoggerProvider, listener),
removeTokenListener: listener => removeTokenListener(app, listener)
getToken: forceRefresh => getToken$2(appCheck, forceRefresh),
addTokenListener: listener => addTokenListener(appCheck, "INTERNAL" /* INTERNAL */, listener),
removeTokenListener: listener => removeTokenListener(appCheck.app, listener)
};

@@ -873,3 +893,3 @@ }

const name = "@firebase/app-check-exp";
const version = "0.0.900-exp.57f19127c";
const version = "0.0.900-exp.f43d0c698";

@@ -1126,2 +1146,3 @@ /**

*
* @param appCheckInstance - The App Check service instance.
* @param isTokenAutoRefreshEnabled - If true, the SDK automatically

@@ -1132,3 +1153,4 @@ * refreshes App Check tokens as needed. This overrides any value set

*/
function setTokenAutoRefreshEnabled(app, isTokenAutoRefreshEnabled) {
function setTokenAutoRefreshEnabled(appCheckInstance, isTokenAutoRefreshEnabled) {
const app = appCheckInstance.app;
const state = getState(app);

@@ -1147,2 +1169,49 @@ // This will exist if any product libraries have called

}
/**
* Get the current App Check token. Attaches to the most recent
* in-flight request if one is present. Returns null if no token
* is present and no token requests are in-flight.
*
* @param appCheckInstance - The App Check service instance.
* @param forceRefresh - If true, will always try to fetch a fresh token.
* If false, will use a cached token if found in storage.
* @public
*/
async function getToken(appCheckInstance, forceRefresh) {
const result = await getToken$2(appCheckInstance, forceRefresh);
if (result.error) {
throw result.error;
}
return { token: result.token };
}
/**
* Wraps addTokenListener/removeTokenListener methods in an Observer
* pattern for public use.
*/
function onTokenChanged(appCheckInstance, 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(appCheckInstance, "EXTERNAL" /* EXTERNAL */, nextFn, errorFn);
return () => removeTokenListener(appCheckInstance.app, nextFn);
}

@@ -1172,11 +1241,18 @@ /**

const app = container.getProvider('app-exp').getImmediate();
return factory(app);
}, "PUBLIC" /* PUBLIC */));
const platformLoggerProvider = container.getProvider('platform-logger');
return factory(app, platformLoggerProvider);
}, "PUBLIC" /* PUBLIC */)
.setInstantiationMode("EXPLICIT" /* EXPLICIT */)
/**
* Initialize app-check-internal after app-check is initialized to make AppCheck available to
* other Firebase SDKs
*/
.setInstanceCreatedCallback((container, _identifier, _appcheckService) => {
container.getProvider(APP_CHECK_NAME_INTERNAL).initialize();
}));
// The internal interface used by other Firebase products
_registerComponent(new Component(APP_CHECK_NAME_INTERNAL, container => {
// getImmediate for FirebaseApp will always succeed
const app = container.getProvider('app-exp').getImmediate();
const platformLoggerProvider = container.getProvider('platform-logger');
return internalFactory(app, platformLoggerProvider);
}, "PUBLIC" /* PUBLIC */));
const appCheck = container.getProvider('app-check-exp').getImmediate();
return internalFactory(appCheck);
}, "PUBLIC" /* PUBLIC */).setInstantiationMode("EXPLICIT" /* EXPLICIT */));
registerVersion(name, version);

@@ -1187,3 +1263,3 @@ }

export { CustomProvider, ReCaptchaV3Provider, initializeAppCheck, setTokenAutoRefreshEnabled };
export { CustomProvider, ReCaptchaV3Provider, getToken, initializeAppCheck, onTokenChanged, setTokenAutoRefreshEnabled };
//# sourceMappingURL=index.esm2017.js.map

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

*/
import { AppCheck, AppCheckOptions } from './public-types';
import { AppCheck, AppCheckOptions, AppCheckTokenResult } from './public-types';
import { FirebaseApp } from "@firebase/app";
import { PartialObserver, Unsubscribe } from '@firebase/util';
import { AppCheckService } from './factory';

@@ -37,2 +38,3 @@ declare module '@firebase/component' {

*
* @param appCheckInstance - The App Check service instance.
* @param isTokenAutoRefreshEnabled - If true, the SDK automatically

@@ -43,2 +45,47 @@ * refreshes App Check tokens as needed. This overrides any value set

*/
export declare function setTokenAutoRefreshEnabled(app: FirebaseApp, isTokenAutoRefreshEnabled: boolean): void;
export declare function setTokenAutoRefreshEnabled(appCheckInstance: AppCheck, isTokenAutoRefreshEnabled: boolean): void;
/**
* Get the current App Check token. Attaches to the most recent
* in-flight request if one is present. Returns null if no token
* is present and no token requests are in-flight.
*
* @param appCheckInstance - The App Check service instance.
* @param forceRefresh - If true, will always try to fetch a fresh token.
* If false, will use a cached token if found in storage.
* @public
*/
export declare function getToken(appCheckInstance: AppCheck, forceRefresh?: boolean): Promise<AppCheckTokenResult>;
/**
* Registers a listener to changes in the token state. There can be more
* than one listener registered at the same time for one or more
* App Check instances. The listeners call back on the UI thread whenever
* the current token associated with this App Check instance changes.
*
* @param appCheckInstance - The App Check service instance.
* @param observer - An object with `next`, `error`, and `complete`
* properties. `next` is called with an
* {@link AppCheckTokenResult}
* whenever the token changes. `error` is optional and is called if an
* error is thrown by the listener (the `next` function). `complete`
* is unused, as the token stream is unending.
*
* @returns A function that unsubscribes this listener.
* @public
*/
export declare function onTokenChanged(appCheckInstance: AppCheck, observer: PartialObserver<AppCheckTokenResult>): Unsubscribe;
/**
* Registers a listener to changes in the token state. There can be more
* than one listener registered at the same time for one or more
* App Check instances. The listeners call back on the UI thread whenever
* the current token associated with this App Check instance changes.
*
* @param appCheckInstance - The App Check service instance.
* @param onNext - When the token changes, this function is called with aa
* {@link AppCheckTokenResult}.
* @param onError - Optional. Called if there is an error thrown by the
* listener (the `onNext` function).
* @param onCompletion - Currently unused, as the token stream is unending.
* @returns A function that unsubscribes this listener.
* @public
*/
export declare function onTokenChanged(appCheckInstance: AppCheck, onNext: (tokenResult: AppCheckTokenResult) => void, onError?: (error: Error) => void, onCompletion?: () => void): Unsubscribe;

@@ -26,6 +26,7 @@ /**

app: FirebaseApp;
constructor(app: FirebaseApp);
platformLoggerProvider: Provider<'platform-logger'>;
constructor(app: FirebaseApp, platformLoggerProvider: Provider<'platform-logger'>);
_delete(): Promise<void>;
}
export declare function factory(app: FirebaseApp): AppCheckService;
export declare function internalFactory(app: FirebaseApp, platformLoggerProvider: Provider<'platform-logger'>): FirebaseAppCheckInternal;
export declare function factory(app: FirebaseApp, platformLoggerProvider: Provider<'platform-logger'>): AppCheckService;
export declare function internalFactory(appCheck: AppCheckService): FirebaseAppCheckInternal;

@@ -18,4 +18,5 @@ /**

import { FirebaseApp } from "@firebase/app";
import { AppCheckTokenResult, AppCheckTokenListener } from './types';
import { Provider } from '@firebase/component';
import { AppCheckTokenResult, ListenerType } from './types';
import { AppCheckTokenListener } from './public-types';
import { AppCheckService } from './factory';
export declare const defaultTokenErrorData: {

@@ -35,4 +36,4 @@ error: string;

*/
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 getToken(appCheck: AppCheckService, forceRefresh?: boolean): Promise<AppCheckTokenResult>;
export declare function addTokenListener(appCheck: AppCheckService, type: ListenerType, listener: AppCheckTokenListener, onError?: (error: Error) => void): void;
export declare function removeTokenListener(app: FirebaseApp, listener: AppCheckTokenListener): void;

@@ -70,1 +70,16 @@ /**

}
/**
* Result returned by `getToken()`.
* @public
*/
export interface AppCheckTokenResult {
/**
* The token string in JWT format.
*/
readonly token: string;
}
/**
* A listener that is called whenever the App Check token changes.
* @public
*/
export declare type AppCheckTokenListener = (token: AppCheckTokenResult) => void;

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

import { FirebaseApp } from "@firebase/app";
import { AppCheckProvider, AppCheckTokenInternal, AppCheckTokenListener } from './types';
import { AppCheckProvider, AppCheckTokenInternal, AppCheckTokenObserver } from './types';
import { Refresher } from './proactive-refresh';

@@ -25,3 +25,3 @@ import { Deferred } from '@firebase/util';

activated: boolean;
tokenListeners: AppCheckTokenListener[];
tokenObservers: AppCheckTokenObserver[];
provider?: AppCheckProvider;

@@ -28,0 +28,0 @@ token?: AppCheckTokenInternal;

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

import { FirebaseApp } from "@firebase/app";
import { AppCheckToken } from './public-types';
import { PartialObserver } from '@firebase/util';
import { AppCheckToken, AppCheckTokenListener } from './public-types';
export interface FirebaseAppCheckInternal {

@@ -25,3 +26,10 @@ getToken(forceRefresh?: boolean): Promise<AppCheckTokenResult>;

}
export declare type AppCheckTokenListener = (token: AppCheckTokenResult) => void;
export interface AppCheckTokenObserver extends PartialObserver<AppCheckTokenResult> {
next: AppCheckTokenListener;
type: ListenerType;
}
export declare const enum ListenerType {
'INTERNAL' = "INTERNAL",
'EXTERNAL' = "EXTERNAL"
}
export interface AppCheckTokenResult {

@@ -28,0 +36,0 @@ readonly token: string;

@@ -20,5 +20,6 @@ /**

import { Provider } from '@firebase/component';
import { CustomProvider } from '../src';
import { AppCheck, CustomProvider } from '../src';
export declare const FAKE_SITE_KEY = "fake-site-key";
export declare function getFakeApp(overrides?: Record<string, any>): FirebaseApp;
export declare function getFakeAppCheck(app: FirebaseApp): AppCheck;
export declare function getFullApp(): FirebaseApp;

@@ -25,0 +26,0 @@ export declare function getFakeCustomTokenProvider(): CustomProvider;

{
"name": "@firebase/app-check",
"version": "0.0.900-exp.57f19127c",
"version": "0.0.900-exp.f43d0c698",
"private": false,

@@ -30,3 +30,3 @@ "description": "An App Check package for new firebase packages",

"peerDependencies": {
"@firebase/app": "0.0.900-exp.57f19127c"
"@firebase/app": "0.0.900-exp.f43d0c698"
},

@@ -42,7 +42,7 @@ "dependencies": {

"@firebase/app-exp": "0.0.900",
"rollup": "2.33.2",
"rollup": "2.52.2",
"@rollup/plugin-commonjs": "17.1.0",
"@rollup/plugin-json": "4.1.0",
"@rollup/plugin-node-resolve": "11.2.0",
"rollup-plugin-typescript2": "0.29.0",
"rollup-plugin-typescript2": "0.30.0",
"typescript": "4.2.2"

@@ -49,0 +49,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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc