From 03e97b8b3bb06f3b796354175eeb06ae000bdb65 Mon Sep 17 00:00:00 2001 From: Yuchen Shi Date: Thu, 15 Apr 2021 15:11:15 -0700 Subject: [PATCH] Expose addFrameworkForLogging. (#4786) --- packages-exp/auth-compat-exp/src/auth.ts | 8 ++++++++ packages-exp/auth-exp/internal/index.ts | 10 ++++++++++ packages-exp/auth-exp/src/core/auth/auth_impl.ts | 2 +- packages-exp/auth-exp/src/core/util/version.ts | 12 +----------- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/packages-exp/auth-compat-exp/src/auth.ts b/packages-exp/auth-compat-exp/src/auth.ts index dd4b9d22f81..a4ea71f359d 100644 --- a/packages-exp/auth-compat-exp/src/auth.ts +++ b/packages-exp/auth-compat-exp/src/auth.ts @@ -170,6 +170,14 @@ export class Auth } return convertCredential(this._delegate, Promise.resolve(credential)); } + + // This function should only be called by frameworks (e.g. FirebaseUI-web) to log their usage. + // It is not intended for direct use by developer apps. NO jsdoc here to intentionally leave it + // out of autogenerated documentation pages to reduce accidental misuse. + addFrameworkForLogging(framework: string): void { + exp.addFrameworkForLogging(this._delegate, framework); + } + onAuthStateChanged( nextOrObserver: Observer | ((a: compat.User | null) => unknown), errorFn?: (error: compat.Error) => unknown, diff --git a/packages-exp/auth-exp/internal/index.ts b/packages-exp/auth-exp/internal/index.ts index aa84a0fe36d..d8da272c895 100644 --- a/packages-exp/auth-exp/internal/index.ts +++ b/packages-exp/auth-exp/internal/index.ts @@ -15,6 +15,9 @@ * limitations under the License. */ +import { _castAuth } from '../src/core/auth/auth_impl'; +import { Auth } from '../src/model/public_types'; + /** * This interface is intended only for use by @firebase/auth-compat-exp, do not use directly */ @@ -45,3 +48,10 @@ export { _getRedirectResult } from '../src/platform_browser/strategies/redirect' export { cordovaPopupRedirectResolver } from '../src/platform_cordova/popup_redirect/popup_redirect'; export { FetchProvider } from '../src/core/util/fetch_provider'; export { SAMLAuthCredential } from '../src/core/credentials/saml'; + +// This function should only be called by frameworks (e.g. FirebaseUI-web) to log their usage. +// It is not intended for direct use by developer apps. NO jsdoc here to intentionally leave it out +// of autogenerated documentation pages to reduce accidental misuse. +export function addFrameworkForLogging(auth: Auth, framework: string): void { + _castAuth(auth)._logFramework(framework); +} diff --git a/packages-exp/auth-exp/src/core/auth/auth_impl.ts b/packages-exp/auth-exp/src/core/auth/auth_impl.ts index ae52a2ae16f..31c1e991e3f 100644 --- a/packages-exp/auth-exp/src/core/auth/auth_impl.ts +++ b/packages-exp/auth-exp/src/core/auth/auth_impl.ts @@ -562,7 +562,7 @@ export class AuthImpl implements AuthInternal, _FirebaseService { private frameworks: string[] = []; private clientVersion: string; _logFramework(framework: string): void { - if (this.frameworks.includes(framework)) { + if (!framework || this.frameworks.includes(framework)) { return; } this.frameworks.push(framework); diff --git a/packages-exp/auth-exp/src/core/util/version.ts b/packages-exp/auth-exp/src/core/util/version.ts index fe84758fe1a..e8aecd48f17 100644 --- a/packages-exp/auth-exp/src/core/util/version.ts +++ b/packages-exp/auth-exp/src/core/util/version.ts @@ -31,18 +31,8 @@ export const enum ClientPlatform { WORKER = 'Worker' } -const enum ClientFramework { - // No other framework used. - DEFAULT = 'FirebaseCore-web', - // Firebase Auth used with FirebaseUI-web. - // TODO: Pass this in when used in conjunction with FirebaseUI - FIREBASEUI = 'FirebaseUI-web' -} - /* * Determine the SDK version string - * - * TODO: This should be set on the Auth object during initialization */ export function _getClientVersion( clientPlatform: ClientPlatform, @@ -65,6 +55,6 @@ export function _getClientVersion( } const reportedFrameworks = frameworks.length ? frameworks.join(',') - : ClientFramework.DEFAULT; + : 'FirebaseCore-web'; /* default value if no other framework is used */ return `${reportedPlatform}/${ClientImplementation.CORE}/${SDK_VERSION}/${reportedFrameworks}`; }