From 776790f0e81cb30bf00fde1f893ebdce5107f0f4 Mon Sep 17 00:00:00 2001 From: Feiyang1 Date: Wed, 17 Feb 2021 16:16:55 -0800 Subject: [PATCH 01/13] remove auth-types package --- .../src/model/application_verifier.ts | 2 +- packages-exp/auth-exp/src/model/auth.ts | 2 +- packages-exp/auth-exp/src/model/id_token.ts | 2 +- .../auth-exp/src/model/popup_redirect.ts | 2 +- .../src/model/public_types.ts} | 16 +++++----- packages-exp/auth-exp/src/model/user.ts | 2 +- packages-exp/auth-types-exp/README.md | 3 -- .../auth-types-exp/api-extractor.json | 5 ---- packages-exp/auth-types-exp/package.json | 29 ------------------- packages-exp/auth-types-exp/tsconfig.json | 9 ------ 10 files changed, 13 insertions(+), 59 deletions(-) rename packages-exp/{auth-types-exp/index.d.ts => auth-exp/src/model/public_types.ts} (98%) delete mode 100644 packages-exp/auth-types-exp/README.md delete mode 100644 packages-exp/auth-types-exp/api-extractor.json delete mode 100644 packages-exp/auth-types-exp/package.json delete mode 100644 packages-exp/auth-types-exp/tsconfig.json diff --git a/packages-exp/auth-exp/src/model/application_verifier.ts b/packages-exp/auth-exp/src/model/application_verifier.ts index 1342a409ed1..a8c314df623 100644 --- a/packages-exp/auth-exp/src/model/application_verifier.ts +++ b/packages-exp/auth-exp/src/model/application_verifier.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from './public_types'; export interface ApplicationVerifier extends externs.ApplicationVerifier { /** diff --git a/packages-exp/auth-exp/src/model/auth.ts b/packages-exp/auth-exp/src/model/auth.ts index 4d6ae94d7b8..778e8ea2de9 100644 --- a/packages-exp/auth-exp/src/model/auth.ts +++ b/packages-exp/auth-exp/src/model/auth.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from './public_types'; import { ErrorFactory } from '@firebase/util'; import { AuthErrorCode, AuthErrorParams } from '../core/errors'; diff --git a/packages-exp/auth-exp/src/model/id_token.ts b/packages-exp/auth-exp/src/model/id_token.ts index ca2836f19de..bf6af083bc2 100644 --- a/packages-exp/auth-exp/src/model/id_token.ts +++ b/packages-exp/auth-exp/src/model/id_token.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { ProviderId } from '@firebase/auth-types-exp'; +import { ProviderId } from './public_types'; import { PhoneOrOauthTokenResponse } from '../api/authentication/mfa'; diff --git a/packages-exp/auth-exp/src/model/popup_redirect.ts b/packages-exp/auth-exp/src/model/popup_redirect.ts index b07edf07efa..bb0253678ac 100644 --- a/packages-exp/auth-exp/src/model/popup_redirect.ts +++ b/packages-exp/auth-exp/src/model/popup_redirect.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from './public_types'; import { FirebaseError } from '@firebase/util'; import { AuthPopup } from '../platform_browser/util/popup'; diff --git a/packages-exp/auth-types-exp/index.d.ts b/packages-exp/auth-exp/src/model/public_types.ts similarity index 98% rename from packages-exp/auth-types-exp/index.d.ts rename to packages-exp/auth-exp/src/model/public_types.ts index e5da22aec87..a4cf376ff27 100644 --- a/packages-exp/auth-types-exp/index.d.ts +++ b/packages-exp/auth-exp/src/model/public_types.ts @@ -508,7 +508,7 @@ export interface ActionCodeSettings { * * @public */ -export abstract class ActionCodeURL { +export declare abstract class ActionCodeURL { /** * The API key of the email action link. */ @@ -573,7 +573,7 @@ export interface ApplicationVerifier { * * @public */ -export abstract class RecaptchaVerifier implements ApplicationVerifier { +export declare abstract class RecaptchaVerifier implements ApplicationVerifier { constructor( /** * The reCAPTCHA container parameter. @@ -637,7 +637,7 @@ export abstract class RecaptchaVerifier implements ApplicationVerifier { * * @public */ -export abstract class AuthCredential { +export declare abstract class AuthCredential { /** * Static method to deserialize a JSON representation of an object into an {@link @firebase/auth-types#AuthCredential}. * @@ -680,7 +680,7 @@ export abstract class AuthCredential { * * @public */ -export abstract class OAuthCredential extends AuthCredential { +export declare abstract class OAuthCredential extends AuthCredential { /** * Static method to deserialize a JSON representation of an object into an * {@link @firebase/auth-types#AuthCredential}. @@ -715,7 +715,7 @@ export abstract class OAuthCredential extends AuthCredential { * * @public */ -export abstract class PhoneAuthCredential extends AuthCredential { +export declare abstract class PhoneAuthCredential extends AuthCredential { /** {@inheritdoc @firebase/auth-types#AuthCredential.fromJSON} */ static fromJSON(json: object | string): PhoneAuthCredential | null; /** {@inheritdoc @firebase/auth-types#AuthCredential.toJSON} */ @@ -739,7 +739,7 @@ export interface AuthProvider { * * @public */ -export abstract class EmailAuthProvider implements AuthProvider { +export declare abstract class EmailAuthProvider implements AuthProvider { private constructor(); /** * Always set to {@link @firebase/auth-types#ProviderId.PASSWORD}, even for email link. @@ -821,7 +821,7 @@ export abstract class EmailAuthProvider implements AuthProvider { * * @public */ -export class PhoneAuthProvider implements AuthProvider { +export declare class PhoneAuthProvider implements AuthProvider { /** Always set to {@link @firebase/auth-types#ProviderId.PHONE}. */ static readonly PROVIDER_ID: ProviderId; /** Always set to {@link @firebase/auth-types#SignInMethod.PHONE}. */ @@ -1205,7 +1205,7 @@ export interface PhoneMultiFactorAssertion extends MultiFactorAssertion {} * * @public */ -export abstract class PhoneMultiFactorGenerator { +export declare abstract class PhoneMultiFactorGenerator { /** * The identifier of the phone second factor: {@link @firebase/auth-types#ProviderId.PHONE}. */ diff --git a/packages-exp/auth-exp/src/model/user.ts b/packages-exp/auth-exp/src/model/user.ts index dfec0715e7e..c243931c8b7 100644 --- a/packages-exp/auth-exp/src/model/user.ts +++ b/packages-exp/auth-exp/src/model/user.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from './public_types'; import { NextFn } from '@firebase/util'; import { APIUserInfo } from '../api/account_management/account'; import { FinalizeMfaResponse } from '../api/authentication/mfa'; diff --git a/packages-exp/auth-types-exp/README.md b/packages-exp/auth-types-exp/README.md deleted file mode 100644 index e63106206bf..00000000000 --- a/packages-exp/auth-types-exp/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @firebase/auth-types-exp - -**This package is not intended for direct usage, and should only be used via the officially supported [firebase](https://www.npmjs.com/package/firebase) package.** diff --git a/packages-exp/auth-types-exp/api-extractor.json b/packages-exp/auth-types-exp/api-extractor.json deleted file mode 100644 index 42f37a88c4b..00000000000 --- a/packages-exp/auth-types-exp/api-extractor.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": "../../config/api-extractor.json", - // Point it to your entry point d.ts file. - "mainEntryPointFilePath": "/index.d.ts" -} \ No newline at end of file diff --git a/packages-exp/auth-types-exp/package.json b/packages-exp/auth-types-exp/package.json deleted file mode 100644 index ae035c14da0..00000000000 --- a/packages-exp/auth-types-exp/package.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "@firebase/auth-types-exp", - "private": true, - "version": "0.0.900", - "description": "@firebase/auth-exp Types", - "author": "Firebase (https://firebase.google.com/)", - "license": "Apache-2.0", - "scripts": { - "test": "tsc", - "api-report": "api-extractor run --local --verbose", - "predoc": "node ../../scripts/exp/remove-exp.js temp", - "doc": "api-documenter markdown --input temp --output docs", - "build:doc": "yarn api-report && yarn doc" - }, - "files": [ - "index.d.ts" - ], - "repository": { - "directory": "packages-exp/auth-types-exp", - "type": "git", - "url": "https://github.com/firebase/firebase-js-sdk.git" - }, - "bugs": { - "url": "https://github.com/firebase/firebase-js-sdk/issues" - }, - "devDependencies": { - "typescript": "4.0.5" - } -} diff --git a/packages-exp/auth-types-exp/tsconfig.json b/packages-exp/auth-types-exp/tsconfig.json deleted file mode 100644 index 9a785433d90..00000000000 --- a/packages-exp/auth-types-exp/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../config/tsconfig.base.json", - "compilerOptions": { - "noEmit": true - }, - "exclude": [ - "dist/**/*" - ] -} From 57ec0d0a4e3959fe534238f8f1083f4641b5af8c Mon Sep 17 00:00:00 2001 From: Feiyang1 Date: Wed, 17 Feb 2021 16:21:00 -0800 Subject: [PATCH 02/13] remove dependencies --- .changeset/config.json | 1 - common/api-review/auth-types-exp.api.md | 423 ------------------------ packages-exp/auth-exp/package.json | 1 - 3 files changed, 425 deletions(-) delete mode 100644 common/api-review/auth-types-exp.api.md diff --git a/.changeset/config.json b/.changeset/config.json index 30f30ffa8e9..91baed6433c 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -18,7 +18,6 @@ "@firebase/analytics-types-exp", "@firebase/auth-exp", "@firebase/auth-compat", - "@firebase/auth-types-exp", "@firebase/functions-compat", "@firebase/functions-exp", "@firebase/functions-types-exp", diff --git a/common/api-review/auth-types-exp.api.md b/common/api-review/auth-types-exp.api.md deleted file mode 100644 index c6723eea17c..00000000000 --- a/common/api-review/auth-types-exp.api.md +++ /dev/null @@ -1,423 +0,0 @@ -## API Report File for "@firebase/auth-types-exp" - -> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). - -```ts - -import { CompleteFn } from '@firebase/util'; -import { ErrorFn } from '@firebase/util'; -import { FirebaseError } from '@firebase/util'; -import { NextFn } from '@firebase/util'; -import { Observer } from '@firebase/util'; -import { Unsubscribe } from '@firebase/util'; - -// @public -export interface ActionCodeInfo { - data: { - email?: string | null; - multiFactorInfo?: MultiFactorInfo | null; - previousEmail?: string | null; - }; - operation: ActionCodeOperation; -} - -// @public -export const enum ActionCodeOperation { - EMAIL_SIGNIN = 'EMAIL_SIGNIN', - PASSWORD_RESET = 'PASSWORD_RESET', - RECOVER_EMAIL = 'RECOVER_EMAIL', - REVERT_SECOND_FACTOR_ADDITION = 'REVERT_SECOND_FACTOR_ADDITION', - VERIFY_AND_CHANGE_EMAIL = 'VERIFY_AND_CHANGE_EMAIL', - VERIFY_EMAIL = 'VERIFY_EMAIL' -} - -// @public -export interface ActionCodeSettings { - android?: { - installApp?: boolean; - minimumVersion?: string; - packageName: string; - }; - dynamicLinkDomain?: string; - handleCodeInApp?: boolean; - iOS?: { - bundleId: string; - }; - url: string; -} - -// @public -export abstract class ActionCodeURL { - readonly apiKey: string; - readonly code: string; - readonly continueUrl: string | null; - readonly languageCode: string | null; - readonly operation: ActionCodeOperation; - static parseLink(link: string): ActionCodeURL | null; - readonly tenantId: string | null; -} - -// @public -export interface AdditionalUserInfo { - readonly isNewUser: boolean; - readonly profile: Record | null; - readonly providerId: string | null; - readonly username?: string | null; -} - -// @public -export interface ApplicationVerifier { - readonly type: string; - verify(): Promise; -} - -// @public -export interface Auth { - readonly config: Config; - readonly currentUser: User | null; - languageCode: string | null; - readonly name: string; - onAuthStateChanged( - nextOrObserver: NextOrObserver, - error?: ErrorFn, - completed?: CompleteFn - ): Unsubscribe; - onIdTokenChanged( - nextOrObserver: NextOrObserver, - error?: ErrorFn, - completed?: CompleteFn - ): Unsubscribe; - setPersistence(persistence: Persistence): Promise; - readonly settings: AuthSettings; - signOut(): Promise; - tenantId: string | null; - updateCurrentUser(user: User | null): Promise; - useDeviceLanguage(): void; - useEmulator(url: string, options?: { disableWarnings: boolean }): void; -} - -// @public -export abstract class AuthCredential { - static fromJSON(json: object | string): AuthCredential | null; - - readonly providerId: string; - - readonly signInMethod: string; - - toJSON(): object; -} - -// @public -export interface AuthError extends FirebaseError { - readonly appName: string; - readonly email?: string; - readonly phoneNumber?: string; - readonly tenantid?: string; -} - -// @public -export interface AuthErrorMap {} - -// @public -export interface AuthProvider { - readonly providerId: string; -} - -// @public -export interface AuthSettings { - appVerificationDisabledForTesting: boolean; -} - -// @public -export interface Config { - apiHost: string; - apiKey: string; - apiScheme: string; - authDomain?: string; - sdkClientVersion: string; - tokenApiHost: string; -} - -// @public -export interface ConfirmationResult { - confirm(verificationCode: string): Promise; - readonly verificationId: string; -} - -// @public -export abstract class EmailAuthProvider implements AuthProvider { - static credential(email: string, password: string): AuthCredential; - static credentialWithLink( - auth: Auth, - email: string, - emailLink: string - ): AuthCredential; - static readonly EMAIL_LINK_SIGN_IN_METHOD: SignInMethod; - static readonly EMAIL_PASSWORD_SIGN_IN_METHOD: SignInMethod; - static readonly PROVIDER_ID: ProviderId; - readonly providerId: ProviderId; -} - -// @public -export const enum FactorId { - PHONE = 'phone' -} - -// @public -export interface IdTokenResult { - authTime: string; - claims: ParsedToken; - expirationTime: string; - issuedAtTime: string; - signInProvider: string | null; - signInSecondFactor: string | null; - token: string; -} - -// @public -export interface MultiFactorAssertion { - readonly factorId: FactorId; -} - -// @public -export interface MultiFactorError extends AuthError { - readonly operationType: OperationType; -} - -// @public -export interface MultiFactorInfo { - readonly displayName?: string | null; - readonly enrollmentTime: string; - readonly factorId: FactorId; - readonly uid: string; -} - -// @public -export abstract class MultiFactorResolver { - readonly hints: MultiFactorInfo[]; - resolveSignIn(assertion: MultiFactorAssertion): Promise; - readonly session: MultiFactorSession; -} - -// @public -export interface MultiFactorSession {} - -// @public -export interface MultiFactorUser { - enroll( - assertion: MultiFactorAssertion, - displayName?: string | null - ): Promise; - readonly enrolledFactors: MultiFactorInfo[]; - getSession(): Promise; - unenroll(option: MultiFactorInfo | string): Promise; -} - -// @public -export type NextOrObserver = NextFn | Observer; - -// @public -export abstract class OAuthCredential extends AuthCredential { - readonly accessToken?: string; - - static fromJSON(json: object | string): OAuthCredential | null; - - readonly idToken?: string; - - readonly secret?: string; -} - -// @public -export const enum OperationType { - LINK = 'link', - REAUTHENTICATE = 'reauthenticate', - SIGN_IN = 'signIn' -} - -// @public -export interface ParsedToken { - [key: string]: string | object | undefined; - 'auth_time'?: string; - 'exp'?: string; - 'firebase'?: { - 'sign_in_provider'?: string; - 'sign_in_second_factor'?: string; - }; - 'iat'?: string; - 'sub'?: string; -} - -// @public -export interface Persistence { - readonly type: 'SESSION' | 'LOCAL' | 'NONE'; -} - -// @public -export abstract class PhoneAuthCredential extends AuthCredential { - // (undocumented) - static fromJSON(json: object | string): PhoneAuthCredential | null; - // (undocumented) - toJSON(): object; -} - -// @public -export class PhoneAuthProvider implements AuthProvider { - constructor(auth?: Auth | null); - static credential( - verificationId: string, - verificationCode: string - ): AuthCredential; - static readonly PHONE_SIGN_IN_METHOD: SignInMethod; - static readonly PROVIDER_ID: ProviderId; - readonly providerId: ProviderId; - verifyPhoneNumber( - phoneInfoOptions: PhoneInfoOptions | string, - applicationVerifier: ApplicationVerifier - ): Promise; -} - -// @public -export type PhoneInfoOptions = - | PhoneSingleFactorInfoOptions - | PhoneMultiFactorEnrollInfoOptions - | PhoneMultiFactorSignInInfoOptions; - -// @public -export interface PhoneMultiFactorAssertion extends MultiFactorAssertion {} - -// @public -export interface PhoneMultiFactorEnrollInfoOptions { - phoneNumber: string; - session: MultiFactorSession; -} - -// @public -export abstract class PhoneMultiFactorGenerator { - static assertion( - phoneAuthCredential: PhoneAuthCredential - ): PhoneMultiFactorAssertion; - static FACTOR_ID: ProviderId; -} - -// @public -export interface PhoneMultiFactorSignInInfoOptions { - multiFactorHint?: MultiFactorInfo; - multiFactorUid?: string; - session: MultiFactorSession; -} - -// @public -export interface PhoneSingleFactorInfoOptions { - phoneNumber: string; -} - -// @public -export interface PopupRedirectResolver {} - -// @public -export const enum ProviderId { - // (undocumented) - ANONYMOUS = 'anonymous', - // (undocumented) - CUSTOM = 'custom', - // (undocumented) - FACEBOOK = 'facebook.com', - // (undocumented) - FIREBASE = 'firebase', - // (undocumented) - GITHUB = 'github.com', - // (undocumented) - GOOGLE = 'google.com', - // (undocumented) - PASSWORD = 'password', - // (undocumented) - PHONE = 'phone', - // (undocumented) - TWITTER = 'twitter.com' -} - -// @public -export interface ReactNativeAsyncStorage { - getItem(key: string): Promise; - removeItem(key: string): Promise; - setItem(key: string, value: string): Promise; -} - -// @public -export abstract class RecaptchaVerifier implements ApplicationVerifier { - constructor( - container: any | string, - parameters?: Object | null, - auth?: Auth | null - ); - clear(): void; - render(): Promise; - readonly type: string; - verify(): Promise; -} - -// @public -export const enum SignInMethod { - // (undocumented) - ANONYMOUS = 'anonymous', - // (undocumented) - EMAIL_LINK = 'emailLink', - // (undocumented) - EMAIL_PASSWORD = 'password', - // (undocumented) - FACEBOOK = 'facebook.com', - // (undocumented) - GITHUB = 'github.com', - // (undocumented) - GOOGLE = 'google.com', - // (undocumented) - PHONE = 'phone', - // (undocumented) - TWITTER = 'twitter.com' -} - -// @public -export interface User extends UserInfo { - delete(): Promise; - readonly emailVerified: boolean; - getIdToken(forceRefresh?: boolean): Promise; - getIdTokenResult(forceRefresh?: boolean): Promise; - readonly isAnonymous: boolean; - readonly metadata: UserMetadata; - readonly providerData: UserInfo[]; - readonly refreshToken: string; - reload(): Promise; - readonly tenantId: string | null; - toJSON(): object; -} - -// @public -export interface UserCredential { - operationType: OperationType; - providerId: string | null; - user: User; -} - -// @public -export interface UserInfo { - readonly displayName: string | null; - readonly email: string | null; - readonly phoneNumber: string | null; - readonly photoURL: string | null; - readonly providerId: string; - readonly uid: string; -} - -// @public -export interface UserMetadata { - readonly creationTime?: string; - readonly lastSignInTime?: string; -} - -// @public -export type UserProfile = Record; - - -// (No @packageDocumentation comment for this package) - -``` diff --git a/packages-exp/auth-exp/package.json b/packages-exp/auth-exp/package.json index eac4da93c06..8b487e17958 100644 --- a/packages-exp/auth-exp/package.json +++ b/packages-exp/auth-exp/package.json @@ -43,7 +43,6 @@ "@firebase/logger": "0.2.6", "@firebase/util": "0.3.4", "@firebase/component": "0.1.21", - "@firebase/auth-types-exp": "0.0.900", "node-fetch": "2.6.1", "tslib": "^1.11.1" }, From 95ebfee1c9dd4a895a63adaae2dee6faa41133e2 Mon Sep 17 00:00:00 2001 From: Feiyang1 Date: Wed, 17 Feb 2021 16:42:20 -0800 Subject: [PATCH 03/13] save progress --- packages-exp/auth-exp/index.cordova.ts | 2 +- packages-exp/auth-exp/index.node.ts | 2 +- packages-exp/auth-exp/index.rn.ts | 2 +- packages-exp/auth-exp/index.ts | 45 +---------------- packages-exp/auth-exp/index.webworker.ts | 2 +- .../api/account_management/account.test.ts | 2 +- .../src/api/account_management/account.ts | 2 +- .../account_management/email_and_password.ts | 2 +- .../src/api/account_management/profile.ts | 2 +- .../src/api/authentication/create_auth_uri.ts | 2 +- .../api/authentication/custom_token.test.ts | 2 +- .../src/api/authentication/custom_token.ts | 2 +- .../authentication/email_and_password.test.ts | 2 +- .../api/authentication/email_and_password.ts | 2 +- .../src/api/authentication/email_link.ts | 2 +- .../auth-exp/src/api/authentication/idp.ts | 2 +- .../auth-exp/src/api/authentication/mfa.ts | 2 +- .../src/api/authentication/recaptcha.ts | 2 +- .../src/api/authentication/sign_up.ts | 2 +- .../src/api/authentication/sms.test.ts | 2 +- .../auth-exp/src/api/authentication/sms.ts | 8 +-- .../auth-exp/src/api/authentication/token.ts | 50 ++++++++++--------- packages-exp/auth-exp/src/api/index.ts | 2 +- .../api/project_config/get_project_config.ts | 2 +- .../auth-exp/src/core/action_code_url.test.ts | 2 +- .../auth-exp/src/core/action_code_url.ts | 27 +++++----- .../auth-exp/src/core/auth/auth_impl.ts | 2 +- .../auth-exp/src/core/auth/emulator.ts | 2 +- .../auth-exp/src/core/auth/initialize.test.ts | 2 +- .../auth-exp/src/core/auth/initialize.ts | 2 +- .../auth-exp/src/core/auth/register.ts | 2 +- .../src/core/credentials/email.test.ts | 2 +- .../auth-exp/src/core/credentials/email.ts | 2 +- .../src/core/credentials/oauth.test.ts | 2 +- .../auth-exp/src/core/credentials/oauth.ts | 2 +- .../auth-exp/src/core/credentials/phone.ts | 2 +- packages-exp/auth-exp/src/core/errors.test.ts | 2 +- packages-exp/auth-exp/src/core/errors.ts | 2 +- packages-exp/auth-exp/src/core/index.ts | 2 +- .../src/core/persistence/in_memory.ts | 2 +- .../auth-exp/src/core/providers/email.test.ts | 2 +- .../auth-exp/src/core/providers/email.ts | 2 +- .../src/core/providers/facebook.test.ts | 2 +- .../auth-exp/src/core/providers/facebook.ts | 2 +- .../src/core/providers/github.test.ts | 2 +- .../auth-exp/src/core/providers/github.ts | 2 +- .../src/core/providers/google.test.ts | 2 +- .../auth-exp/src/core/providers/google.ts | 2 +- .../auth-exp/src/core/providers/oauth.test.ts | 2 +- .../auth-exp/src/core/providers/oauth.ts | 2 +- .../src/core/providers/twitter.test.ts | 2 +- .../auth-exp/src/core/providers/twitter.ts | 2 +- .../abstract_popup_redirect_operation.test.ts | 2 +- .../core/strategies/action_code_settings.ts | 2 +- .../src/core/strategies/anonymous.test.ts | 2 +- .../auth-exp/src/core/strategies/anonymous.ts | 2 +- .../src/core/strategies/credential.test.ts | 2 +- .../src/core/strategies/credential.ts | 4 +- .../src/core/strategies/custom_token.test.ts | 2 +- .../src/core/strategies/custom_token.ts | 2 +- .../src/core/strategies/email.test.ts | 2 +- .../auth-exp/src/core/strategies/email.ts | 2 +- .../strategies/email_and_password.test.ts | 2 +- .../src/core/strategies/email_and_password.ts | 2 +- .../src/core/strategies/email_link.test.ts | 4 +- .../src/core/strategies/email_link.ts | 2 +- .../auth-exp/src/core/strategies/idp.test.ts | 2 +- .../auth-exp/src/core/strategies/idp.ts | 2 +- .../src/core/strategies/redirect.test.ts | 2 +- .../src/core/user/account_info.test.ts | 2 +- .../auth-exp/src/core/user/account_info.ts | 2 +- .../core/user/additional_user_info.test.ts | 2 +- .../src/core/user/additional_user_info.ts | 2 +- .../src/core/user/id_token_result.test.ts | 2 +- .../auth-exp/src/core/user/id_token_result.ts | 2 +- .../src/core/user/link_unlink.test.ts | 2 +- .../auth-exp/src/core/user/link_unlink.ts | 2 +- .../src/core/user/reauthenticate.test.ts | 2 +- .../auth-exp/src/core/user/reauthenticate.ts | 2 +- .../auth-exp/src/core/user/reload.test.ts | 2 +- packages-exp/auth-exp/src/core/user/reload.ts | 2 +- .../core/user/user_credential_impl.test.ts | 2 +- .../src/core/user/user_credential_impl.ts | 2 +- .../auth-exp/src/core/user/user_impl.ts | 2 +- .../auth-exp/src/core/user/user_metadata.ts | 2 +- packages-exp/auth-exp/src/core/util/assert.ts | 2 +- .../auth-exp/src/core/util/handler.ts | 2 +- .../auth-exp/src/core/util/resolver.ts | 2 +- .../auth-exp/src/mfa/mfa_assertion.ts | 2 +- packages-exp/auth-exp/src/mfa/mfa_error.ts | 2 +- .../auth-exp/src/mfa/mfa_info.test.ts | 2 +- packages-exp/auth-exp/src/mfa/mfa_info.ts | 2 +- .../auth-exp/src/mfa/mfa_resolver.test.ts | 2 +- packages-exp/auth-exp/src/mfa/mfa_resolver.ts | 2 +- packages-exp/auth-exp/src/mfa/mfa_session.ts | 2 +- .../auth-exp/src/mfa/mfa_user.test.ts | 2 +- packages-exp/auth-exp/src/mfa/mfa_user.ts | 2 +- .../src/platform_browser/auth.test.ts | 2 +- .../mfa/assertions/phone.test.ts | 2 +- .../platform_browser/mfa/assertions/phone.ts | 2 +- .../persistence/indexed_db.ts | 2 +- .../persistence/local_storage.ts | 2 +- .../persistence/session_storage.ts | 2 +- .../platform_browser/popup_redirect.test.ts | 2 +- .../src/platform_browser/popup_redirect.ts | 2 +- .../src/platform_browser/providers/phone.ts | 2 +- .../recaptcha/recaptcha_verifier.ts | 2 +- .../platform_browser/strategies/phone.test.ts | 2 +- .../src/platform_browser/strategies/phone.ts | 2 +- .../platform_browser/strategies/popup.test.ts | 2 +- .../src/platform_browser/strategies/popup.ts | 2 +- .../strategies/redirect.test.ts | 2 +- .../platform_browser/strategies/redirect.ts | 2 +- .../popup_redirect/popup_redirect.test.ts | 2 +- .../popup_redirect/popup_redirect.ts | 2 +- .../platform_cordova/popup_redirect/utils.ts | 2 +- .../platform_cordova/strategies/redirect.ts | 2 +- .../persistence/react_native.test.ts | 2 +- .../persistence/react_native.ts | 2 +- 119 files changed, 164 insertions(+), 200 deletions(-) diff --git a/packages-exp/auth-exp/index.cordova.ts b/packages-exp/auth-exp/index.cordova.ts index 7ba6ecde020..989928a0936 100644 --- a/packages-exp/auth-exp/index.cordova.ts +++ b/packages-exp/auth-exp/index.cordova.ts @@ -23,7 +23,7 @@ */ import { FirebaseApp } from '@firebase/app-exp'; -import { Auth } from '@firebase/auth-types-exp'; +import { Auth } from './src/model/public_types'; import { indexedDBLocalPersistence } from './src/platform_browser/persistence/indexed_db'; import { initializeAuth } from './src'; diff --git a/packages-exp/auth-exp/index.node.ts b/packages-exp/auth-exp/index.node.ts index 60293365131..c5e5c12e0ac 100644 --- a/packages-exp/auth-exp/index.node.ts +++ b/packages-exp/auth-exp/index.node.ts @@ -25,7 +25,7 @@ import * as fetchImpl from 'node-fetch'; import { FirebaseApp } from '@firebase/app-exp'; -import { Auth } from '@firebase/auth-types-exp'; +import { Auth } from './src/model/public_types'; import { initializeAuth } from './src'; import { registerAuth } from './src/core/auth/register'; diff --git a/packages-exp/auth-exp/index.rn.ts b/packages-exp/auth-exp/index.rn.ts index 3695dc14ef5..75ce948da75 100644 --- a/packages-exp/auth-exp/index.rn.ts +++ b/packages-exp/auth-exp/index.rn.ts @@ -25,7 +25,7 @@ import { AsyncStorage } from 'react-native'; import { FirebaseApp } from '@firebase/app-exp'; -import { Auth } from '@firebase/auth-types-exp'; +import { Auth } from './src/model/public_types'; import { initializeAuth } from './src'; import { registerAuth } from './src/core/auth/register'; diff --git a/packages-exp/auth-exp/index.ts b/packages-exp/auth-exp/index.ts index bf228a6ef3b..0e54d9cba4a 100644 --- a/packages-exp/auth-exp/index.ts +++ b/packages-exp/auth-exp/index.ts @@ -23,48 +23,7 @@ import { ClientPlatform } from './src/core/util/version'; import { browserLocalPersistence } from './src/platform_browser/persistence/local_storage'; import { indexedDBLocalPersistence } from './src/platform_browser/persistence/indexed_db'; import { browserPopupRedirectResolver } from './src/platform_browser/popup_redirect'; - -import { - // Enums - ActionCodeOperation, - FactorId, - OperationType, - ProviderId, - SignInMethod, - // Interfaces - ActionCodeInfo, - ActionCodeSettings, - AdditionalUserInfo, - ApplicationVerifier, - Auth, - AuthError, - AuthErrorMap, - AuthProvider, - AuthSettings, - Config, - ConfirmationResult, - IdTokenResult, - MultiFactorAssertion, - MultiFactorError, - MultiFactorInfo, - MultiFactorResolver, - MultiFactorSession, - MultiFactorUser, - ParsedToken, - Persistence, - PhoneMultiFactorAssertion, - PhoneMultiFactorEnrollInfoOptions, - PhoneMultiFactorSignInInfoOptions, - PhoneSingleFactorInfoOptions, - PopupRedirectResolver, - ReactNativeAsyncStorage, - User, - UserCredential, - UserInfo, - UserMetadata, - UserProfile, - PhoneInfoOptions -} from '@firebase/auth-types-exp'; +import { Auth } from './src/model/public_types'; // Public types export { @@ -107,7 +66,7 @@ export { UserMetadata, UserProfile, PhoneInfoOptions -}; +} from './src/model/public_types'; // Core functionality shared by all clients export * from './src'; diff --git a/packages-exp/auth-exp/index.webworker.ts b/packages-exp/auth-exp/index.webworker.ts index 31363390013..e9fefb3691b 100644 --- a/packages-exp/auth-exp/index.webworker.ts +++ b/packages-exp/auth-exp/index.webworker.ts @@ -16,7 +16,7 @@ */ import { _getProvider, FirebaseApp } from '@firebase/app-exp'; -import { Auth } from '@firebase/auth-types-exp'; +import { Auth } from './src/model/public_types'; import { AuthImpl } from './src/core/auth/auth_impl'; import { _initializeAuthInstance } from './src/core/auth/initialize'; diff --git a/packages-exp/auth-exp/src/api/account_management/account.test.ts b/packages-exp/auth-exp/src/api/account_management/account.test.ts index 7f1d4ba65a6..ff1cf27c4e3 100644 --- a/packages-exp/auth-exp/src/api/account_management/account.test.ts +++ b/packages-exp/auth-exp/src/api/account_management/account.test.ts @@ -18,7 +18,7 @@ import { expect, use } from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; -import { ProviderId } from '@firebase/auth-types-exp'; +import { ProviderId } from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; import { Endpoint, HttpHeader } from '../'; diff --git a/packages-exp/auth-exp/src/api/account_management/account.ts b/packages-exp/auth-exp/src/api/account_management/account.ts index 4c2a13b9b97..100e50ec010 100644 --- a/packages-exp/auth-exp/src/api/account_management/account.ts +++ b/packages-exp/auth-exp/src/api/account_management/account.ts @@ -17,7 +17,7 @@ import { Endpoint, HttpMethod, _performApiRequest } from '../index'; import { MfaEnrollment } from './mfa'; -import { Auth } from '@firebase/auth-types-exp'; +import { Auth } from '../../model/public_types'; export interface DeleteAccountRequest { idToken: string; diff --git a/packages-exp/auth-exp/src/api/account_management/email_and_password.ts b/packages-exp/auth-exp/src/api/account_management/email_and_password.ts index d45d98cff1f..09bf1b3a2af 100644 --- a/packages-exp/auth-exp/src/api/account_management/email_and_password.ts +++ b/packages-exp/auth-exp/src/api/account_management/email_and_password.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { ActionCodeOperation, Auth } from '@firebase/auth-types-exp'; +import { ActionCodeOperation, Auth } from '../../model/public_types'; import { Endpoint, HttpMethod, _performApiRequest } from '../index'; import { IdTokenResponse } from '../../model/id_token'; diff --git a/packages-exp/auth-exp/src/api/account_management/profile.ts b/packages-exp/auth-exp/src/api/account_management/profile.ts index 73c7cd2336b..d206d7ed1c6 100644 --- a/packages-exp/auth-exp/src/api/account_management/profile.ts +++ b/packages-exp/auth-exp/src/api/account_management/profile.ts @@ -17,7 +17,7 @@ import { Endpoint, HttpMethod, _performApiRequest } from '../index'; import { IdTokenResponse } from '../../model/id_token'; -import { Auth } from '@firebase/auth-types-exp'; +import { Auth } from '../../model/public_types'; export interface UpdateProfileRequest { idToken: string; diff --git a/packages-exp/auth-exp/src/api/authentication/create_auth_uri.ts b/packages-exp/auth-exp/src/api/authentication/create_auth_uri.ts index 97955adbc13..b268289f90d 100644 --- a/packages-exp/auth-exp/src/api/authentication/create_auth_uri.ts +++ b/packages-exp/auth-exp/src/api/authentication/create_auth_uri.ts @@ -16,7 +16,7 @@ */ import { Endpoint, HttpMethod, _performApiRequest } from '../index'; -import { Auth } from '@firebase/auth-types-exp'; +import { Auth } from '../../model/public_types'; export interface CreateAuthUriRequest { identifier: string; diff --git a/packages-exp/auth-exp/src/api/authentication/custom_token.test.ts b/packages-exp/auth-exp/src/api/authentication/custom_token.test.ts index bc39e27c804..2ac7f736d06 100644 --- a/packages-exp/auth-exp/src/api/authentication/custom_token.test.ts +++ b/packages-exp/auth-exp/src/api/authentication/custom_token.test.ts @@ -18,7 +18,7 @@ import { expect, use } from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; -import { ProviderId } from '@firebase/auth-types-exp'; +import { ProviderId } from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; import { Endpoint, HttpHeader } from '../'; diff --git a/packages-exp/auth-exp/src/api/authentication/custom_token.ts b/packages-exp/auth-exp/src/api/authentication/custom_token.ts index 40ea6192298..7d03d549631 100644 --- a/packages-exp/auth-exp/src/api/authentication/custom_token.ts +++ b/packages-exp/auth-exp/src/api/authentication/custom_token.ts @@ -17,7 +17,7 @@ import { Endpoint, HttpMethod, _performSignInRequest } from '../index'; import { IdTokenResponse } from '../../model/id_token'; -import { Auth } from '@firebase/auth-types-exp'; +import { Auth } from '../../model/public_types'; export interface SignInWithCustomTokenRequest { token: string; diff --git a/packages-exp/auth-exp/src/api/authentication/email_and_password.test.ts b/packages-exp/auth-exp/src/api/authentication/email_and_password.test.ts index 609ac8f3295..3a7786153da 100644 --- a/packages-exp/auth-exp/src/api/authentication/email_and_password.test.ts +++ b/packages-exp/auth-exp/src/api/authentication/email_and_password.test.ts @@ -18,7 +18,7 @@ import { expect, use } from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; -import { ActionCodeOperation } from '@firebase/auth-types-exp'; +import { ActionCodeOperation } from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; import { Endpoint, HttpHeader } from '../'; diff --git a/packages-exp/auth-exp/src/api/authentication/email_and_password.ts b/packages-exp/auth-exp/src/api/authentication/email_and_password.ts index a808e041dfb..e0cea7ab357 100644 --- a/packages-exp/auth-exp/src/api/authentication/email_and_password.ts +++ b/packages-exp/auth-exp/src/api/authentication/email_and_password.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { ActionCodeOperation, Auth } from '@firebase/auth-types-exp'; +import { ActionCodeOperation, Auth } from '../../model/public_types'; import { Endpoint, diff --git a/packages-exp/auth-exp/src/api/authentication/email_link.ts b/packages-exp/auth-exp/src/api/authentication/email_link.ts index 4b70642cacd..804d369a9de 100644 --- a/packages-exp/auth-exp/src/api/authentication/email_link.ts +++ b/packages-exp/auth-exp/src/api/authentication/email_link.ts @@ -17,7 +17,7 @@ import { _performSignInRequest, Endpoint, HttpMethod } from '../index'; import { IdTokenResponse } from '../../model/id_token'; -import { Auth } from '@firebase/auth-types-exp'; +import { Auth } from '../../model/public_types'; export interface SignInWithEmailLinkRequest { email: string; diff --git a/packages-exp/auth-exp/src/api/authentication/idp.ts b/packages-exp/auth-exp/src/api/authentication/idp.ts index 65bd8cc9512..f5f2cd736c6 100644 --- a/packages-exp/auth-exp/src/api/authentication/idp.ts +++ b/packages-exp/auth-exp/src/api/authentication/idp.ts @@ -17,7 +17,7 @@ import { Endpoint, HttpMethod, _performSignInRequest } from '../index'; import { IdToken, IdTokenResponse } from '../../model/id_token'; -import { Auth } from '@firebase/auth-types-exp'; +import { Auth } from '../../model/public_types'; export interface SignInWithIdpRequest { requestUri: string; diff --git a/packages-exp/auth-exp/src/api/authentication/mfa.ts b/packages-exp/auth-exp/src/api/authentication/mfa.ts index a928af4b59a..165c0ad918f 100644 --- a/packages-exp/auth-exp/src/api/authentication/mfa.ts +++ b/packages-exp/auth-exp/src/api/authentication/mfa.ts @@ -16,7 +16,7 @@ */ import { _performApiRequest, Endpoint, HttpMethod } from '../index'; -import { Auth } from '@firebase/auth-types-exp'; +import { Auth } from '../../model/public_types'; import { IdTokenResponse } from '../../model/id_token'; import { MfaEnrollment } from '../account_management/mfa'; import { SignInWithIdpResponse } from './idp'; diff --git a/packages-exp/auth-exp/src/api/authentication/recaptcha.ts b/packages-exp/auth-exp/src/api/authentication/recaptcha.ts index 945c84cbfa1..0d5812b1e6f 100644 --- a/packages-exp/auth-exp/src/api/authentication/recaptcha.ts +++ b/packages-exp/auth-exp/src/api/authentication/recaptcha.ts @@ -16,7 +16,7 @@ */ import { Endpoint, HttpMethod, _performApiRequest } from '../index'; -import { Auth } from '@firebase/auth-types-exp'; +import { Auth } from '../../model/public_types'; interface GetRecaptchaParamResponse { recaptchaSiteKey?: string; diff --git a/packages-exp/auth-exp/src/api/authentication/sign_up.ts b/packages-exp/auth-exp/src/api/authentication/sign_up.ts index db5a60d1d37..80e6df87bee 100644 --- a/packages-exp/auth-exp/src/api/authentication/sign_up.ts +++ b/packages-exp/auth-exp/src/api/authentication/sign_up.ts @@ -17,7 +17,7 @@ import { Endpoint, HttpMethod, _performSignInRequest } from '../index'; import { IdTokenResponse } from '../../model/id_token'; -import { Auth } from '@firebase/auth-types-exp'; +import { Auth } from '../../model/public_types'; export interface SignUpRequest { returnSecureToken?: boolean; diff --git a/packages-exp/auth-exp/src/api/authentication/sms.test.ts b/packages-exp/auth-exp/src/api/authentication/sms.test.ts index b1ff8a3c923..9173fb6c3dd 100644 --- a/packages-exp/auth-exp/src/api/authentication/sms.test.ts +++ b/packages-exp/auth-exp/src/api/authentication/sms.test.ts @@ -18,7 +18,7 @@ import { expect, use } from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; -import { ProviderId } from '@firebase/auth-types-exp'; +import { ProviderId } from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; import { Endpoint, HttpHeader } from '../'; diff --git a/packages-exp/auth-exp/src/api/authentication/sms.ts b/packages-exp/auth-exp/src/api/authentication/sms.ts index bd892176427..7aba53e85fe 100644 --- a/packages-exp/auth-exp/src/api/authentication/sms.ts +++ b/packages-exp/auth-exp/src/api/authentication/sms.ts @@ -24,7 +24,7 @@ import { import { AuthErrorCode } from '../../core/errors'; import { IdTokenResponse } from '../../model/id_token'; import { ServerError, ServerErrorMap } from '../errors'; -import { Auth } from '@firebase/auth-types-exp'; +import { Auth } from '../../model/public_types'; export interface SendPhoneVerificationCodeRequest { phoneNumber: string; @@ -87,9 +87,9 @@ interface VerifyPhoneNumberForExistingRequest operation: 'REAUTH'; } -const VERIFY_PHONE_NUMBER_FOR_EXISTING_ERROR_MAP_: Partial> = { +const VERIFY_PHONE_NUMBER_FOR_EXISTING_ERROR_MAP_: Partial< + ServerErrorMap +> = { [ServerError.USER_NOT_FOUND]: AuthErrorCode.USER_DELETED }; diff --git a/packages-exp/auth-exp/src/api/authentication/token.ts b/packages-exp/auth-exp/src/api/authentication/token.ts index 8801c5fd137..66fb461d157 100644 --- a/packages-exp/auth-exp/src/api/authentication/token.ts +++ b/packages-exp/auth-exp/src/api/authentication/token.ts @@ -25,7 +25,7 @@ import { HttpMethod } from '../index'; import { FetchProvider } from '../../core/util/fetch_provider'; -import { Auth } from '@firebase/auth-types-exp'; +import { Auth } from '../../model/public_types'; export const enum Endpoint { TOKEN = '/v1/token' @@ -48,30 +48,32 @@ export async function requestStsToken( auth: Auth, refreshToken: string ): Promise { - const response = await _performFetchWithErrorHandling< - RequestStsTokenServerResponse - >(auth, {}, () => { - const body = querystring({ - 'grant_type': 'refresh_token', - 'refresh_token': refreshToken - }).slice(1); - const { tokenApiHost, apiKey, sdkClientVersion } = auth.config; - const url = _getFinalTarget( - auth, - tokenApiHost, - Endpoint.TOKEN, - `key=${apiKey}` - ); + const response = await _performFetchWithErrorHandling( + auth, + {}, + () => { + const body = querystring({ + 'grant_type': 'refresh_token', + 'refresh_token': refreshToken + }).slice(1); + const { tokenApiHost, apiKey, sdkClientVersion } = auth.config; + const url = _getFinalTarget( + auth, + tokenApiHost, + Endpoint.TOKEN, + `key=${apiKey}` + ); - return FetchProvider.fetch()(url, { - method: HttpMethod.POST, - headers: { - 'X-Client-Version': sdkClientVersion, - 'Content-Type': 'application/x-www-form-urlencoded' - }, - body - }); - }); + return FetchProvider.fetch()(url, { + method: HttpMethod.POST, + headers: { + 'X-Client-Version': sdkClientVersion, + 'Content-Type': 'application/x-www-form-urlencoded' + }, + body + }); + } + ); // The response comes back in snake_case. Convert to camel: return { diff --git a/packages-exp/auth-exp/src/api/index.ts b/packages-exp/auth-exp/src/api/index.ts index ea3e1cf764b..6c8c15eea50 100644 --- a/packages-exp/auth-exp/src/api/index.ts +++ b/packages-exp/auth-exp/src/api/index.ts @@ -22,7 +22,7 @@ import { _createError, _fail } from '../core/util/assert'; import { Delay } from '../core/util/delay'; import { _emulatorUrl } from '../core/util/emulator'; import { FetchProvider } from '../core/util/fetch_provider'; -import { Auth } from '@firebase/auth-types-exp'; +import { Auth } from '../model/public_types'; import { Auth as AuthInternal } from '../model/auth'; import { IdTokenResponse, TaggedWithTokenResponse } from '../model/id_token'; import { IdTokenMfaResponse } from './authentication/mfa'; diff --git a/packages-exp/auth-exp/src/api/project_config/get_project_config.ts b/packages-exp/auth-exp/src/api/project_config/get_project_config.ts index b3869d3a24e..48df651f33c 100644 --- a/packages-exp/auth-exp/src/api/project_config/get_project_config.ts +++ b/packages-exp/auth-exp/src/api/project_config/get_project_config.ts @@ -16,7 +16,7 @@ */ import { _performApiRequest, Endpoint, HttpMethod } from '../index'; -import { Auth } from '@firebase/auth-types-exp'; +import { Auth } from '../../model/public_types'; export interface GetProjectConfigRequest {} diff --git a/packages-exp/auth-exp/src/core/action_code_url.test.ts b/packages-exp/auth-exp/src/core/action_code_url.test.ts index 0f741bc78ec..9896886f593 100644 --- a/packages-exp/auth-exp/src/core/action_code_url.test.ts +++ b/packages-exp/auth-exp/src/core/action_code_url.test.ts @@ -17,7 +17,7 @@ import { expect } from 'chai'; -import { ActionCodeOperation } from '@firebase/auth-types-exp'; +import { ActionCodeOperation } from '../model/public_types'; import { ActionCodeURL } from './action_code_url'; diff --git a/packages-exp/auth-exp/src/core/action_code_url.ts b/packages-exp/auth-exp/src/core/action_code_url.ts index e416ad1c8ba..0e7cb0db243 100644 --- a/packages-exp/auth-exp/src/core/action_code_url.ts +++ b/packages-exp/auth-exp/src/core/action_code_url.ts @@ -15,7 +15,10 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import { + ActionCodeOperation, + ActionCodeURL as ActionCodeURLType +} from '../model/public_types'; import { AuthErrorCode } from './errors'; import { _assert } from './util/assert'; @@ -38,20 +41,20 @@ const enum QueryField { * * @param mode */ -function parseMode(mode: string | null): externs.ActionCodeOperation | null { +function parseMode(mode: string | null): ActionCodeOperation | null { switch (mode) { case 'recoverEmail': - return externs.ActionCodeOperation.RECOVER_EMAIL; + return ActionCodeOperation.RECOVER_EMAIL; case 'resetPassword': - return externs.ActionCodeOperation.PASSWORD_RESET; + return ActionCodeOperation.PASSWORD_RESET; case 'signIn': - return externs.ActionCodeOperation.EMAIL_SIGNIN; + return ActionCodeOperation.EMAIL_SIGNIN; case 'verifyEmail': - return externs.ActionCodeOperation.VERIFY_EMAIL; + return ActionCodeOperation.VERIFY_EMAIL; case 'verifyAndChangeEmail': - return externs.ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL; + return ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL; case 'revertSecondFactorAddition': - return externs.ActionCodeOperation.REVERT_SECOND_FACTOR_ADDITION; + return ActionCodeOperation.REVERT_SECOND_FACTOR_ADDITION; default: return null; } @@ -80,7 +83,7 @@ function parseDeepLink(url: string): string { * * @public */ -export class ActionCodeURL implements externs.ActionCodeURL { +export class ActionCodeURL implements ActionCodeURLType { /** {@inheritDoc @firebase/auth-types#ActionCodeURL.apiKey} */ readonly apiKey: string; /** {@inheritDoc @firebase/auth-types#ActionCodeURL.code} */ @@ -90,7 +93,7 @@ export class ActionCodeURL implements externs.ActionCodeURL { /** {@inheritDoc @firebase/auth-types#ActionCodeURL.languageCode} */ readonly languageCode: string | null; /** {@inheritDoc @firebase/auth-types#ActionCodeURL.operation} */ - readonly operation: externs.ActionCodeOperation; + readonly operation: ActionCodeOperation; /** {@inheritDoc @firebase/auth-types#ActionCodeURL.tenantId} */ readonly tenantId: string | null; @@ -116,7 +119,7 @@ export class ActionCodeURL implements externs.ActionCodeURL { } /** {@inheritDoc @firebase/auth-types#ActionCodeURL.parseLink} */ - static parseLink(link: string): externs.ActionCodeURL | null { + static parseLink(link: string): ActionCodeURL | null { const actionLink = parseDeepLink(link); try { return new ActionCodeURL(actionLink); @@ -131,6 +134,6 @@ export class ActionCodeURL implements externs.ActionCodeURL { * * @public */ -export function parseActionCodeURL(link: string): externs.ActionCodeURL | null { +export function parseActionCodeURL(link: string): ActionCodeURL | null { return ActionCodeURL.parseLink(link); } 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 657bc76c01a..3f85f2177b0 100644 --- a/packages-exp/auth-exp/src/core/auth/auth_impl.ts +++ b/packages-exp/auth-exp/src/core/auth/auth_impl.ts @@ -16,7 +16,7 @@ */ import { _FirebaseService, FirebaseApp } from '@firebase/app-exp'; -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { CompleteFn, createSubscribe, diff --git a/packages-exp/auth-exp/src/core/auth/emulator.ts b/packages-exp/auth-exp/src/core/auth/emulator.ts index 302e422d44a..70613d10624 100644 --- a/packages-exp/auth-exp/src/core/auth/emulator.ts +++ b/packages-exp/auth-exp/src/core/auth/emulator.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { AuthErrorCode } from '../errors'; import { _assert } from '../util/assert'; import { _castAuth } from './auth_impl'; diff --git a/packages-exp/auth-exp/src/core/auth/initialize.test.ts b/packages-exp/auth-exp/src/core/auth/initialize.test.ts index 2dcde861765..ed2dead37d0 100644 --- a/packages-exp/auth-exp/src/core/auth/initialize.test.ts +++ b/packages-exp/auth-exp/src/core/auth/initialize.test.ts @@ -21,7 +21,7 @@ import { FirebaseApp, _FirebaseService } from '@firebase/app-exp'; -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { isNode } from '@firebase/util'; import { expect } from 'chai'; diff --git a/packages-exp/auth-exp/src/core/auth/initialize.ts b/packages-exp/auth-exp/src/core/auth/initialize.ts index 77e7e875045..232ae3c99f8 100644 --- a/packages-exp/auth-exp/src/core/auth/initialize.ts +++ b/packages-exp/auth-exp/src/core/auth/initialize.ts @@ -16,7 +16,7 @@ */ import { _getProvider, FirebaseApp } from '@firebase/app-exp'; -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { Dependencies } from '../../model/auth'; import { AuthErrorCode } from '../errors'; diff --git a/packages-exp/auth-exp/src/core/auth/register.ts b/packages-exp/auth-exp/src/core/auth/register.ts index 26d195d938d..e0657c2ab73 100644 --- a/packages-exp/auth-exp/src/core/auth/register.ts +++ b/packages-exp/auth-exp/src/core/auth/register.ts @@ -16,7 +16,7 @@ */ import { _registerComponent, registerVersion } from '@firebase/app-exp'; -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { Component, ComponentType } from '@firebase/component'; import { version } from '../../../package.json'; diff --git a/packages-exp/auth-exp/src/core/credentials/email.test.ts b/packages-exp/auth-exp/src/core/credentials/email.test.ts index a39fde9c873..b0d02f2f50c 100644 --- a/packages-exp/auth-exp/src/core/credentials/email.test.ts +++ b/packages-exp/auth-exp/src/core/credentials/email.test.ts @@ -18,7 +18,7 @@ import { expect, use } from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; -import { ProviderId, SignInMethod } from '@firebase/auth-types-exp'; +import { ProviderId, SignInMethod } from '../../model/public_types'; import { mockEndpoint } from '../../../test/helpers/api/helper'; import { testAuth, TestAuth } from '../../../test/helpers/mock_auth'; diff --git a/packages-exp/auth-exp/src/core/credentials/email.ts b/packages-exp/auth-exp/src/core/credentials/email.ts index f02655895bc..9a2c101f7a4 100644 --- a/packages-exp/auth-exp/src/core/credentials/email.ts +++ b/packages-exp/auth-exp/src/core/credentials/email.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { updateEmailPassword } from '../../api/account_management/email_and_password'; import { signInWithPassword } from '../../api/authentication/email_and_password'; diff --git a/packages-exp/auth-exp/src/core/credentials/oauth.test.ts b/packages-exp/auth-exp/src/core/credentials/oauth.test.ts index 93413685567..dd0cff17d2f 100644 --- a/packages-exp/auth-exp/src/core/credentials/oauth.test.ts +++ b/packages-exp/auth-exp/src/core/credentials/oauth.test.ts @@ -17,7 +17,7 @@ import { expect } from 'chai'; -import { ProviderId, SignInMethod } from '@firebase/auth-types-exp'; +import { ProviderId, SignInMethod } from '../../model/public_types'; import { mockEndpoint } from '../../../test/helpers/api/helper'; import { TEST_ID_TOKEN_RESPONSE } from '../../../test/helpers/id_token_response'; diff --git a/packages-exp/auth-exp/src/core/credentials/oauth.ts b/packages-exp/auth-exp/src/core/credentials/oauth.ts index 8a2f239c783..e484c6358f8 100644 --- a/packages-exp/auth-exp/src/core/credentials/oauth.ts +++ b/packages-exp/auth-exp/src/core/credentials/oauth.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { querystring } from '@firebase/util'; import { diff --git a/packages-exp/auth-exp/src/core/credentials/phone.ts b/packages-exp/auth-exp/src/core/credentials/phone.ts index d4422dcf5c1..cc803917224 100644 --- a/packages-exp/auth-exp/src/core/credentials/phone.ts +++ b/packages-exp/auth-exp/src/core/credentials/phone.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { PhoneOrOauthTokenResponse } from '../../api/authentication/mfa'; import { diff --git a/packages-exp/auth-exp/src/core/errors.test.ts b/packages-exp/auth-exp/src/core/errors.test.ts index 3eb281526bf..73526d664a4 100644 --- a/packages-exp/auth-exp/src/core/errors.test.ts +++ b/packages-exp/auth-exp/src/core/errors.test.ts @@ -23,7 +23,7 @@ import { ErrorMapRetriever, AuthErrorParams } from './errors'; -import { AuthErrorMap } from '@firebase/auth-types-exp'; +import { AuthErrorMap } from '../model/public_types'; import { ErrorFactory } from '@firebase/util'; function getErrorFactory( diff --git a/packages-exp/auth-exp/src/core/errors.ts b/packages-exp/auth-exp/src/core/errors.ts index d1c435b7851..3e4577f7378 100644 --- a/packages-exp/auth-exp/src/core/errors.ts +++ b/packages-exp/auth-exp/src/core/errors.ts @@ -16,7 +16,7 @@ */ // eslint-disable-next-line import/no-extraneous-dependencies -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../model/public_types'; import { ErrorFactory, ErrorMap } from '@firebase/util'; import { IdTokenMfaResponse } from '../api/authentication/mfa'; diff --git a/packages-exp/auth-exp/src/core/index.ts b/packages-exp/auth-exp/src/core/index.ts index 4d6dc1f0d26..955ea0066f2 100644 --- a/packages-exp/auth-exp/src/core/index.ts +++ b/packages-exp/auth-exp/src/core/index.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../model/public_types'; import { CompleteFn, ErrorFn, Unsubscribe } from '@firebase/util'; export { debugErrorMap, prodErrorMap } from './errors'; diff --git a/packages-exp/auth-exp/src/core/persistence/in_memory.ts b/packages-exp/auth-exp/src/core/persistence/in_memory.ts index 5f30f6fce59..5829bf5c18e 100644 --- a/packages-exp/auth-exp/src/core/persistence/in_memory.ts +++ b/packages-exp/auth-exp/src/core/persistence/in_memory.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { Persistence, diff --git a/packages-exp/auth-exp/src/core/providers/email.test.ts b/packages-exp/auth-exp/src/core/providers/email.test.ts index 08aa6a9f39a..9fc94392a1a 100644 --- a/packages-exp/auth-exp/src/core/providers/email.test.ts +++ b/packages-exp/auth-exp/src/core/providers/email.test.ts @@ -18,7 +18,7 @@ import { expect, use } from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; -import { ProviderId, SignInMethod } from '@firebase/auth-types-exp'; +import { ProviderId, SignInMethod } from '../../model/public_types'; // eslint-disable-next-line import/no-extraneous-dependencies import { FirebaseError } from '@firebase/util'; diff --git a/packages-exp/auth-exp/src/core/providers/email.ts b/packages-exp/auth-exp/src/core/providers/email.ts index 17ac1848555..d98231ca150 100644 --- a/packages-exp/auth-exp/src/core/providers/email.ts +++ b/packages-exp/auth-exp/src/core/providers/email.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { ActionCodeURL } from '../action_code_url'; import { EmailAuthCredential } from '../credentials/email'; diff --git a/packages-exp/auth-exp/src/core/providers/facebook.test.ts b/packages-exp/auth-exp/src/core/providers/facebook.test.ts index 113c1f43915..dcf310dee64 100644 --- a/packages-exp/auth-exp/src/core/providers/facebook.test.ts +++ b/packages-exp/auth-exp/src/core/providers/facebook.test.ts @@ -21,7 +21,7 @@ import { OperationType, ProviderId, SignInMethod -} from '@firebase/auth-types-exp'; +} from '../../model/public_types'; import { TEST_ID_TOKEN_RESPONSE } from '../../../test/helpers/id_token_response'; import { testUser, testAuth } from '../../../test/helpers/mock_auth'; diff --git a/packages-exp/auth-exp/src/core/providers/facebook.ts b/packages-exp/auth-exp/src/core/providers/facebook.ts index e0aacc0667d..1f6dcaaf5c1 100644 --- a/packages-exp/auth-exp/src/core/providers/facebook.ts +++ b/packages-exp/auth-exp/src/core/providers/facebook.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; import { TaggedWithTokenResponse } from '../../model/id_token'; diff --git a/packages-exp/auth-exp/src/core/providers/github.test.ts b/packages-exp/auth-exp/src/core/providers/github.test.ts index 6a48da8f8ea..3a0f8bb29a1 100644 --- a/packages-exp/auth-exp/src/core/providers/github.test.ts +++ b/packages-exp/auth-exp/src/core/providers/github.test.ts @@ -21,7 +21,7 @@ import { OperationType, ProviderId, SignInMethod -} from '@firebase/auth-types-exp'; +} from '../../model/public_types'; import { TEST_ID_TOKEN_RESPONSE } from '../../../test/helpers/id_token_response'; import { testUser, testAuth } from '../../../test/helpers/mock_auth'; diff --git a/packages-exp/auth-exp/src/core/providers/github.ts b/packages-exp/auth-exp/src/core/providers/github.ts index 6bfebbd6357..737294d6da4 100644 --- a/packages-exp/auth-exp/src/core/providers/github.ts +++ b/packages-exp/auth-exp/src/core/providers/github.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; import { TaggedWithTokenResponse } from '../../model/id_token'; diff --git a/packages-exp/auth-exp/src/core/providers/google.test.ts b/packages-exp/auth-exp/src/core/providers/google.test.ts index f68db311629..4df94d378b5 100644 --- a/packages-exp/auth-exp/src/core/providers/google.test.ts +++ b/packages-exp/auth-exp/src/core/providers/google.test.ts @@ -21,7 +21,7 @@ import { OperationType, ProviderId, SignInMethod -} from '@firebase/auth-types-exp'; +} from '../../model/public_types'; import { TEST_ID_TOKEN_RESPONSE } from '../../../test/helpers/id_token_response'; import { testUser, testAuth } from '../../../test/helpers/mock_auth'; diff --git a/packages-exp/auth-exp/src/core/providers/google.ts b/packages-exp/auth-exp/src/core/providers/google.ts index 0d25e2779a1..6c316931efc 100644 --- a/packages-exp/auth-exp/src/core/providers/google.ts +++ b/packages-exp/auth-exp/src/core/providers/google.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; import { SignInWithIdpResponse } from '../../api/authentication/idp'; diff --git a/packages-exp/auth-exp/src/core/providers/oauth.test.ts b/packages-exp/auth-exp/src/core/providers/oauth.test.ts index 02ecb6c12d4..cf9ca42ba99 100644 --- a/packages-exp/auth-exp/src/core/providers/oauth.test.ts +++ b/packages-exp/auth-exp/src/core/providers/oauth.test.ts @@ -21,7 +21,7 @@ import { OperationType, ProviderId, SignInMethod -} from '@firebase/auth-types-exp'; +} from '../../model/public_types'; import { TEST_ID_TOKEN_RESPONSE } from '../../../test/helpers/id_token_response'; import { testUser, testAuth } from '../../../test/helpers/mock_auth'; diff --git a/packages-exp/auth-exp/src/core/providers/oauth.ts b/packages-exp/auth-exp/src/core/providers/oauth.ts index 275807fb636..59cefb8a75b 100644 --- a/packages-exp/auth-exp/src/core/providers/oauth.ts +++ b/packages-exp/auth-exp/src/core/providers/oauth.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { _assert } from '../util/assert'; import { AuthErrorCode } from '../errors'; diff --git a/packages-exp/auth-exp/src/core/providers/twitter.test.ts b/packages-exp/auth-exp/src/core/providers/twitter.test.ts index 70ed3b8dcaf..8e8f766eb37 100644 --- a/packages-exp/auth-exp/src/core/providers/twitter.test.ts +++ b/packages-exp/auth-exp/src/core/providers/twitter.test.ts @@ -38,7 +38,7 @@ import { OperationType, ProviderId, SignInMethod -} from '@firebase/auth-types-exp'; +} from '../../model/public_types'; import { TEST_ID_TOKEN_RESPONSE } from '../../../test/helpers/id_token_response'; import { testUser, testAuth } from '../../../test/helpers/mock_auth'; diff --git a/packages-exp/auth-exp/src/core/providers/twitter.ts b/packages-exp/auth-exp/src/core/providers/twitter.ts index ffb3fc61d13..7b5553e9ec8 100644 --- a/packages-exp/auth-exp/src/core/providers/twitter.ts +++ b/packages-exp/auth-exp/src/core/providers/twitter.ts @@ -32,7 +32,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; import { SignInWithIdpResponse } from '../../api/authentication/idp'; diff --git a/packages-exp/auth-exp/src/core/strategies/abstract_popup_redirect_operation.test.ts b/packages-exp/auth-exp/src/core/strategies/abstract_popup_redirect_operation.test.ts index 9bfb696a5fa..ba275124a10 100644 --- a/packages-exp/auth-exp/src/core/strategies/abstract_popup_redirect_operation.test.ts +++ b/packages-exp/auth-exp/src/core/strategies/abstract_popup_redirect_operation.test.ts @@ -20,7 +20,7 @@ import * as chaiAsPromised from 'chai-as-promised'; import * as sinon from 'sinon'; import * as sinonChai from 'sinon-chai'; -import { OperationType, ProviderId } from '@firebase/auth-types-exp'; +import { OperationType, ProviderId } from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; import { TEST_ID_TOKEN_RESPONSE } from '../../../test/helpers/id_token_response'; diff --git a/packages-exp/auth-exp/src/core/strategies/action_code_settings.ts b/packages-exp/auth-exp/src/core/strategies/action_code_settings.ts index 5e57f128763..1c93bc7155d 100644 --- a/packages-exp/auth-exp/src/core/strategies/action_code_settings.ts +++ b/packages-exp/auth-exp/src/core/strategies/action_code_settings.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { ActionCodeSettings, Auth } from '@firebase/auth-types-exp'; +import { ActionCodeSettings, Auth } from '../../model/public_types'; import { GetOobCodeRequest } from '../../api/authentication/email_and_password'; import { AuthErrorCode } from '../errors'; diff --git a/packages-exp/auth-exp/src/core/strategies/anonymous.test.ts b/packages-exp/auth-exp/src/core/strategies/anonymous.test.ts index 279541f3852..887878fe5d1 100644 --- a/packages-exp/auth-exp/src/core/strategies/anonymous.test.ts +++ b/packages-exp/auth-exp/src/core/strategies/anonymous.test.ts @@ -17,7 +17,7 @@ import { expect } from 'chai'; -import { OperationType } from '@firebase/auth-types-exp'; +import { OperationType } from '../../model/public_types'; import { mockEndpoint } from '../../../test/helpers/api/helper'; import { testAuth, testUser, TestAuth } from '../../../test/helpers/mock_auth'; diff --git a/packages-exp/auth-exp/src/core/strategies/anonymous.ts b/packages-exp/auth-exp/src/core/strategies/anonymous.ts index 71ded6c42c6..5b456e2be7b 100644 --- a/packages-exp/auth-exp/src/core/strategies/anonymous.ts +++ b/packages-exp/auth-exp/src/core/strategies/anonymous.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { signUp } from '../../api/authentication/sign_up'; import { User } from '../../model/user'; import { UserCredentialImpl } from '../user/user_credential_impl'; diff --git a/packages-exp/auth-exp/src/core/strategies/credential.test.ts b/packages-exp/auth-exp/src/core/strategies/credential.test.ts index f0908c66f9b..74e788cbe6e 100644 --- a/packages-exp/auth-exp/src/core/strategies/credential.test.ts +++ b/packages-exp/auth-exp/src/core/strategies/credential.test.ts @@ -23,7 +23,7 @@ import { OperationType, ProviderId, SignInMethod -} from '@firebase/auth-types-exp'; +} from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; import { mockEndpoint } from '../../../test/helpers/api/helper'; diff --git a/packages-exp/auth-exp/src/core/strategies/credential.ts b/packages-exp/auth-exp/src/core/strategies/credential.ts index d2540e1daee..05a31883f08 100644 --- a/packages-exp/auth-exp/src/core/strategies/credential.ts +++ b/packages-exp/auth-exp/src/core/strategies/credential.ts @@ -15,8 +15,8 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; -import { OperationType, UserCredential } from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; +import { OperationType, UserCredential } from '../../model/public_types'; import { _processCredentialSavingMfaContextIfNecessary } from '../../mfa/mfa_error'; import { Auth } from '../../model/auth'; diff --git a/packages-exp/auth-exp/src/core/strategies/custom_token.test.ts b/packages-exp/auth-exp/src/core/strategies/custom_token.test.ts index 39a789df543..61f0701c99b 100644 --- a/packages-exp/auth-exp/src/core/strategies/custom_token.test.ts +++ b/packages-exp/auth-exp/src/core/strategies/custom_token.test.ts @@ -18,7 +18,7 @@ import { expect, use } from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; -import { OperationType } from '@firebase/auth-types-exp'; +import { OperationType } from '../../model/public_types'; import { mockEndpoint } from '../../../test/helpers/api/helper'; import { testAuth, TestAuth } from '../../../test/helpers/mock_auth'; diff --git a/packages-exp/auth-exp/src/core/strategies/custom_token.ts b/packages-exp/auth-exp/src/core/strategies/custom_token.ts index 8ba413f6479..e9c595e9136 100644 --- a/packages-exp/auth-exp/src/core/strategies/custom_token.ts +++ b/packages-exp/auth-exp/src/core/strategies/custom_token.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { signInWithCustomToken as getIdTokenResponse } from '../../api/authentication/custom_token'; import { IdTokenResponse } from '../../model/id_token'; diff --git a/packages-exp/auth-exp/src/core/strategies/email.test.ts b/packages-exp/auth-exp/src/core/strategies/email.test.ts index 4724321a1f7..5adf310c4cd 100644 --- a/packages-exp/auth-exp/src/core/strategies/email.test.ts +++ b/packages-exp/auth-exp/src/core/strategies/email.test.ts @@ -20,7 +20,7 @@ import * as chaiAsPromised from 'chai-as-promised'; import { restore, SinonStub, stub } from 'sinon'; import * as sinonChai from 'sinon-chai'; -import { ActionCodeOperation, ProviderId } from '@firebase/auth-types-exp'; +import { ActionCodeOperation, ProviderId } from '../../model/public_types'; import { FirebaseError, isNode } from '@firebase/util'; import { mockEndpoint } from '../../../test/helpers/api/helper'; diff --git a/packages-exp/auth-exp/src/core/strategies/email.ts b/packages-exp/auth-exp/src/core/strategies/email.ts index 35345c688ce..32aabd504f8 100644 --- a/packages-exp/auth-exp/src/core/strategies/email.ts +++ b/packages-exp/auth-exp/src/core/strategies/email.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { createAuthUri, diff --git a/packages-exp/auth-exp/src/core/strategies/email_and_password.test.ts b/packages-exp/auth-exp/src/core/strategies/email_and_password.test.ts index 25b72d592e8..3dc2a24e6b4 100644 --- a/packages-exp/auth-exp/src/core/strategies/email_and_password.test.ts +++ b/packages-exp/auth-exp/src/core/strategies/email_and_password.test.ts @@ -19,7 +19,7 @@ import { expect, use } from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; import * as sinonChai from 'sinon-chai'; -import { ActionCodeOperation, OperationType } from '@firebase/auth-types-exp'; +import { ActionCodeOperation, OperationType } from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; import { mockEndpoint } from '../../../test/helpers/api/helper'; diff --git a/packages-exp/auth-exp/src/core/strategies/email_and_password.ts b/packages-exp/auth-exp/src/core/strategies/email_and_password.ts index 3c0d59fc287..b73b3053d4e 100644 --- a/packages-exp/auth-exp/src/core/strategies/email_and_password.ts +++ b/packages-exp/auth-exp/src/core/strategies/email_and_password.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import * as account from '../../api/account_management/email_and_password'; import * as authentication from '../../api/authentication/email_and_password'; diff --git a/packages-exp/auth-exp/src/core/strategies/email_link.test.ts b/packages-exp/auth-exp/src/core/strategies/email_link.test.ts index 6ee44a338ab..043839742fc 100644 --- a/packages-exp/auth-exp/src/core/strategies/email_link.test.ts +++ b/packages-exp/auth-exp/src/core/strategies/email_link.test.ts @@ -19,8 +19,8 @@ import { expect, use } from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; import * as sinonChai from 'sinon-chai'; -import * as externs from '@firebase/auth-types-exp'; -import { OperationType } from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; +import { OperationType } from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; import { mockEndpoint } from '../../../test/helpers/api/helper'; diff --git a/packages-exp/auth-exp/src/core/strategies/email_link.ts b/packages-exp/auth-exp/src/core/strategies/email_link.ts index a2230beb93a..61c79ad0665 100644 --- a/packages-exp/auth-exp/src/core/strategies/email_link.ts +++ b/packages-exp/auth-exp/src/core/strategies/email_link.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import * as api from '../../api/authentication/email_and_password'; import { ActionCodeURL } from '../action_code_url'; diff --git a/packages-exp/auth-exp/src/core/strategies/idp.test.ts b/packages-exp/auth-exp/src/core/strategies/idp.test.ts index d93af58451e..c2f40d17491 100644 --- a/packages-exp/auth-exp/src/core/strategies/idp.test.ts +++ b/packages-exp/auth-exp/src/core/strategies/idp.test.ts @@ -20,7 +20,7 @@ import * as sinonChai from 'sinon-chai'; import { expect, use } from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; -import { OperationType } from '@firebase/auth-types-exp'; +import { OperationType } from '../../model/public_types'; import { mockEndpoint } from '../../../test/helpers/api/helper'; import { TEST_ID_TOKEN_RESPONSE } from '../../../test/helpers/id_token_response'; diff --git a/packages-exp/auth-exp/src/core/strategies/idp.ts b/packages-exp/auth-exp/src/core/strategies/idp.ts index 4365198195e..56979d15131 100644 --- a/packages-exp/auth-exp/src/core/strategies/idp.ts +++ b/packages-exp/auth-exp/src/core/strategies/idp.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { signInWithIdp, SignInWithIdpRequest diff --git a/packages-exp/auth-exp/src/core/strategies/redirect.test.ts b/packages-exp/auth-exp/src/core/strategies/redirect.test.ts index a4de3750c7c..7170d6b4793 100644 --- a/packages-exp/auth-exp/src/core/strategies/redirect.test.ts +++ b/packages-exp/auth-exp/src/core/strategies/redirect.test.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import * as sinon from 'sinon'; import { _getInstance } from '../util/instantiator'; import { diff --git a/packages-exp/auth-exp/src/core/user/account_info.test.ts b/packages-exp/auth-exp/src/core/user/account_info.test.ts index d87de40c490..3e29b4dd1f2 100644 --- a/packages-exp/auth-exp/src/core/user/account_info.test.ts +++ b/packages-exp/auth-exp/src/core/user/account_info.test.ts @@ -20,7 +20,7 @@ import * as chaiAsPromised from 'chai-as-promised'; import * as sinon from 'sinon'; import * as sinonChai from 'sinon-chai'; -import { ProviderId, UserInfo } from '@firebase/auth-types-exp'; +import { ProviderId, UserInfo } from '../../model/public_types'; import { mockEndpoint } from '../../../test/helpers/api/helper'; import { TestAuth, testAuth, testUser } from '../../../test/helpers/mock_auth'; diff --git a/packages-exp/auth-exp/src/core/user/account_info.ts b/packages-exp/auth-exp/src/core/user/account_info.ts index 68bc55fa1a0..04bd34e7782 100644 --- a/packages-exp/auth-exp/src/core/user/account_info.ts +++ b/packages-exp/auth-exp/src/core/user/account_info.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { updateEmailPassword as apiUpdateEmailPassword, diff --git a/packages-exp/auth-exp/src/core/user/additional_user_info.test.ts b/packages-exp/auth-exp/src/core/user/additional_user_info.test.ts index a091e814e83..898e7cf8fce 100644 --- a/packages-exp/auth-exp/src/core/user/additional_user_info.test.ts +++ b/packages-exp/auth-exp/src/core/user/additional_user_info.test.ts @@ -17,7 +17,7 @@ import { expect } from 'chai'; -import { OperationType, ProviderId } from '@firebase/auth-types-exp'; +import { OperationType, ProviderId } from '../../model/public_types'; import { IdTokenResponse, IdTokenResponseKind } from '../../model/id_token'; import { diff --git a/packages-exp/auth-exp/src/core/user/additional_user_info.ts b/packages-exp/auth-exp/src/core/user/additional_user_info.ts index 13d5b446f3b..2e8e4c37458 100644 --- a/packages-exp/auth-exp/src/core/user/additional_user_info.ts +++ b/packages-exp/auth-exp/src/core/user/additional_user_info.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { IdTokenResponse, IdTokenResponseKind } from '../../model/id_token'; import { _parseToken } from './id_token_result'; import { UserCredential } from '../../model/user'; diff --git a/packages-exp/auth-exp/src/core/user/id_token_result.test.ts b/packages-exp/auth-exp/src/core/user/id_token_result.test.ts index 572ed08e465..24db89c52bb 100644 --- a/packages-exp/auth-exp/src/core/user/id_token_result.test.ts +++ b/packages-exp/auth-exp/src/core/user/id_token_result.test.ts @@ -19,7 +19,7 @@ import { expect, use } from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; import * as sinon from 'sinon'; -import { ProviderId } from '@firebase/auth-types-exp'; +import { ProviderId } from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; import { makeJWT } from '../../../test/helpers/jwt'; diff --git a/packages-exp/auth-exp/src/core/user/id_token_result.ts b/packages-exp/auth-exp/src/core/user/id_token_result.ts index 304ab8ae5c3..8bcf16a8a21 100644 --- a/packages-exp/auth-exp/src/core/user/id_token_result.ts +++ b/packages-exp/auth-exp/src/core/user/id_token_result.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { base64Decode } from '@firebase/util'; import { User } from '../../model/user'; diff --git a/packages-exp/auth-exp/src/core/user/link_unlink.test.ts b/packages-exp/auth-exp/src/core/user/link_unlink.test.ts index 512a8865c4c..5cb8eaaed2f 100644 --- a/packages-exp/auth-exp/src/core/user/link_unlink.test.ts +++ b/packages-exp/auth-exp/src/core/user/link_unlink.test.ts @@ -18,7 +18,7 @@ import { expect, use } from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; -import { ProviderId } from '@firebase/auth-types-exp'; +import { ProviderId } from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; import { mockEndpoint } from '../../../test/helpers/api/helper'; diff --git a/packages-exp/auth-exp/src/core/user/link_unlink.ts b/packages-exp/auth-exp/src/core/user/link_unlink.ts index 10b9453bc0c..4013dd7fa68 100644 --- a/packages-exp/auth-exp/src/core/user/link_unlink.ts +++ b/packages-exp/auth-exp/src/core/user/link_unlink.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { deleteLinkedAccounts } from '../../api/account_management/account'; import { User, UserCredential } from '../../model/user'; diff --git a/packages-exp/auth-exp/src/core/user/reauthenticate.test.ts b/packages-exp/auth-exp/src/core/user/reauthenticate.test.ts index a7d2c647d09..2df2f33f50e 100644 --- a/packages-exp/auth-exp/src/core/user/reauthenticate.test.ts +++ b/packages-exp/auth-exp/src/core/user/reauthenticate.test.ts @@ -23,7 +23,7 @@ import { OperationType, ProviderId, SignInMethod -} from '@firebase/auth-types-exp'; +} from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; import { mockEndpoint } from '../../../test/helpers/api/helper'; diff --git a/packages-exp/auth-exp/src/core/user/reauthenticate.ts b/packages-exp/auth-exp/src/core/user/reauthenticate.ts index 20b7c050b52..c76920ded46 100644 --- a/packages-exp/auth-exp/src/core/user/reauthenticate.ts +++ b/packages-exp/auth-exp/src/core/user/reauthenticate.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { OperationType } from '@firebase/auth-types-exp'; +import { OperationType } from '../../model/public_types'; import { _processCredentialSavingMfaContextIfNecessary } from '../../mfa/mfa_error'; import { User } from '../../model/user'; diff --git a/packages-exp/auth-exp/src/core/user/reload.test.ts b/packages-exp/auth-exp/src/core/user/reload.test.ts index d0bcf69f090..4e890f1ed42 100644 --- a/packages-exp/auth-exp/src/core/user/reload.test.ts +++ b/packages-exp/auth-exp/src/core/user/reload.test.ts @@ -20,7 +20,7 @@ import * as chaiAsPromised from 'chai-as-promised'; import * as sinon from 'sinon'; import * as sinonChai from 'sinon-chai'; -import { ProviderId, UserInfo } from '@firebase/auth-types-exp'; +import { ProviderId, UserInfo } from '../../model/public_types'; import { mockEndpoint } from '../../../test/helpers/api/helper'; import { testAuth, TestAuth, testUser } from '../../../test/helpers/mock_auth'; diff --git a/packages-exp/auth-exp/src/core/user/reload.ts b/packages-exp/auth-exp/src/core/user/reload.ts index 74da7868555..32cc831abbc 100644 --- a/packages-exp/auth-exp/src/core/user/reload.ts +++ b/packages-exp/auth-exp/src/core/user/reload.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { getAccountInfo, diff --git a/packages-exp/auth-exp/src/core/user/user_credential_impl.test.ts b/packages-exp/auth-exp/src/core/user/user_credential_impl.test.ts index b6ad020a356..5c8630211ec 100644 --- a/packages-exp/auth-exp/src/core/user/user_credential_impl.test.ts +++ b/packages-exp/auth-exp/src/core/user/user_credential_impl.test.ts @@ -20,7 +20,7 @@ import * as chaiAsPromised from 'chai-as-promised'; import * as sinon from 'sinon'; import * as sinonChai from 'sinon-chai'; -import { OperationType, ProviderId } from '@firebase/auth-types-exp'; +import { OperationType, ProviderId } from '../../model/public_types'; import { mockEndpoint } from '../../../test/helpers/api/helper'; import { TEST_ID_TOKEN_RESPONSE } from '../../../test/helpers/id_token_response'; diff --git a/packages-exp/auth-exp/src/core/user/user_credential_impl.ts b/packages-exp/auth-exp/src/core/user/user_credential_impl.ts index 4ca738b6cb2..13bc5f0b01a 100644 --- a/packages-exp/auth-exp/src/core/user/user_credential_impl.ts +++ b/packages-exp/auth-exp/src/core/user/user_credential_impl.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { PhoneOrOauthTokenResponse } from '../../api/authentication/mfa'; import { IdTokenResponse } from '../../model/id_token'; diff --git a/packages-exp/auth-exp/src/core/user/user_impl.ts b/packages-exp/auth-exp/src/core/user/user_impl.ts index 07e821db460..8f32f03e3dc 100644 --- a/packages-exp/auth-exp/src/core/user/user_impl.ts +++ b/packages-exp/auth-exp/src/core/user/user_impl.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { NextFn } from '@firebase/util'; import { diff --git a/packages-exp/auth-exp/src/core/user/user_metadata.ts b/packages-exp/auth-exp/src/core/user/user_metadata.ts index ffd9fd4ee9d..b71c6324999 100644 --- a/packages-exp/auth-exp/src/core/user/user_metadata.ts +++ b/packages-exp/auth-exp/src/core/user/user_metadata.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { utcTimestampToDateString } from '../util/time'; diff --git a/packages-exp/auth-exp/src/core/util/assert.ts b/packages-exp/auth-exp/src/core/util/assert.ts index 8020f6c3829..1feee771918 100644 --- a/packages-exp/auth-exp/src/core/util/assert.ts +++ b/packages-exp/auth-exp/src/core/util/assert.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; import { Auth } from '../../model/auth'; import { diff --git a/packages-exp/auth-exp/src/core/util/handler.ts b/packages-exp/auth-exp/src/core/util/handler.ts index 5ea0fe3e21c..e7ce782d2d6 100644 --- a/packages-exp/auth-exp/src/core/util/handler.ts +++ b/packages-exp/auth-exp/src/core/util/handler.ts @@ -16,7 +16,7 @@ */ import { SDK_VERSION } from '@firebase/app-exp'; -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { ApiKey, AppName, Auth } from '../../model/auth'; import { AuthEventType } from '../../model/popup_redirect'; import { AuthErrorCode } from '../errors'; diff --git a/packages-exp/auth-exp/src/core/util/resolver.ts b/packages-exp/auth-exp/src/core/util/resolver.ts index f604452b187..6c424debe5f 100644 --- a/packages-exp/auth-exp/src/core/util/resolver.ts +++ b/packages-exp/auth-exp/src/core/util/resolver.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { Auth } from '../../model/auth'; import { PopupRedirectResolver } from '../../model/popup_redirect'; import { AuthErrorCode } from '../errors'; diff --git a/packages-exp/auth-exp/src/mfa/mfa_assertion.ts b/packages-exp/auth-exp/src/mfa/mfa_assertion.ts index d4ce8993038..4cbb20dc107 100644 --- a/packages-exp/auth-exp/src/mfa/mfa_assertion.ts +++ b/packages-exp/auth-exp/src/mfa/mfa_assertion.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../model/public_types'; import { debugFail } from '../core/util/assert'; import { MultiFactorSession, MultiFactorSessionType } from './mfa_session'; import { FinalizeMfaResponse } from '../api/authentication/mfa'; diff --git a/packages-exp/auth-exp/src/mfa/mfa_error.ts b/packages-exp/auth-exp/src/mfa/mfa_error.ts index 9eb23fc65e1..580d2da739e 100644 --- a/packages-exp/auth-exp/src/mfa/mfa_error.ts +++ b/packages-exp/auth-exp/src/mfa/mfa_error.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../model/public_types'; import { FirebaseError } from '@firebase/util'; import { Auth } from '../model/auth'; import { IdTokenResponse } from '../model/id_token'; diff --git a/packages-exp/auth-exp/src/mfa/mfa_info.test.ts b/packages-exp/auth-exp/src/mfa/mfa_info.test.ts index d3ab67158fe..cc9d9fe6562 100644 --- a/packages-exp/auth-exp/src/mfa/mfa_info.test.ts +++ b/packages-exp/auth-exp/src/mfa/mfa_info.test.ts @@ -18,7 +18,7 @@ import { expect, use } from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; -import { ProviderId } from '@firebase/auth-types-exp'; +import { ProviderId } from '../model/public_types'; import { FirebaseError } from '@firebase/util'; import { testAuth, TestAuth } from '../../test/helpers/mock_auth'; diff --git a/packages-exp/auth-exp/src/mfa/mfa_info.ts b/packages-exp/auth-exp/src/mfa/mfa_info.ts index 7e116e494d8..679bb4dd4c7 100644 --- a/packages-exp/auth-exp/src/mfa/mfa_info.ts +++ b/packages-exp/auth-exp/src/mfa/mfa_info.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../model/public_types'; import { PhoneMfaEnrollment, MfaEnrollment diff --git a/packages-exp/auth-exp/src/mfa/mfa_resolver.test.ts b/packages-exp/auth-exp/src/mfa/mfa_resolver.test.ts index 80a987a7418..472af597d75 100644 --- a/packages-exp/auth-exp/src/mfa/mfa_resolver.test.ts +++ b/packages-exp/auth-exp/src/mfa/mfa_resolver.test.ts @@ -19,7 +19,7 @@ import { expect, use } from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; import * as sinon from 'sinon'; -import { FactorId, OperationType, ProviderId } from '@firebase/auth-types-exp'; +import { FactorId, OperationType, ProviderId } from '../model/public_types'; import { FirebaseError } from '@firebase/util'; import { mockEndpoint } from '../../test/helpers/api/helper'; diff --git a/packages-exp/auth-exp/src/mfa/mfa_resolver.ts b/packages-exp/auth-exp/src/mfa/mfa_resolver.ts index 7f714fb9daf..07a4ab15032 100644 --- a/packages-exp/auth-exp/src/mfa/mfa_resolver.ts +++ b/packages-exp/auth-exp/src/mfa/mfa_resolver.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../model/public_types'; import { _castAuth } from '../core/auth/auth_impl'; import { AuthErrorCode } from '../core/errors'; diff --git a/packages-exp/auth-exp/src/mfa/mfa_session.ts b/packages-exp/auth-exp/src/mfa/mfa_session.ts index 4748efd4035..60658bd7b88 100644 --- a/packages-exp/auth-exp/src/mfa/mfa_session.ts +++ b/packages-exp/auth-exp/src/mfa/mfa_session.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../model/public_types'; export const enum MultiFactorSessionType { ENROLL = 'enroll', diff --git a/packages-exp/auth-exp/src/mfa/mfa_user.test.ts b/packages-exp/auth-exp/src/mfa/mfa_user.test.ts index 0df9da50afb..e2e8d743767 100644 --- a/packages-exp/auth-exp/src/mfa/mfa_user.test.ts +++ b/packages-exp/auth-exp/src/mfa/mfa_user.test.ts @@ -19,7 +19,7 @@ import { expect, use } from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; import * as sinon from 'sinon'; -import { FactorId } from '@firebase/auth-types-exp'; +import { FactorId } from '../model/public_types'; import { mockEndpoint } from '../../test/helpers/api/helper'; import { testAuth, testUser, TestAuth } from '../../test/helpers/mock_auth'; diff --git a/packages-exp/auth-exp/src/mfa/mfa_user.ts b/packages-exp/auth-exp/src/mfa/mfa_user.ts index be2ff51b59c..4593dd2ec29 100644 --- a/packages-exp/auth-exp/src/mfa/mfa_user.ts +++ b/packages-exp/auth-exp/src/mfa/mfa_user.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../model/public_types'; import { withdrawMfa } from '../api/account_management/mfa'; import { AuthErrorCode } from '../core/errors'; diff --git a/packages-exp/auth-exp/src/platform_browser/auth.test.ts b/packages-exp/auth-exp/src/platform_browser/auth.test.ts index 056ad863457..f3a1714aada 100644 --- a/packages-exp/auth-exp/src/platform_browser/auth.test.ts +++ b/packages-exp/auth-exp/src/platform_browser/auth.test.ts @@ -21,7 +21,7 @@ import * as sinon from 'sinon'; import * as sinonChai from 'sinon-chai'; import { FirebaseApp } from '@firebase/app-exp'; -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { testAuth, testUser } from '../../test/helpers/mock_auth'; import { AuthImpl, DefaultConfig } from '../core/auth/auth_impl'; diff --git a/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.test.ts b/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.test.ts index cf72fa883e4..f0a93c7710d 100644 --- a/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.test.ts +++ b/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.test.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { ProviderId } from '@firebase/auth-types-exp'; +import { ProviderId } from '../../model/public_types'; import { expect, use } from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; diff --git a/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.ts b/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.ts index 226552f3add..93cacf4bea2 100644 --- a/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.ts +++ b/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../../model/public_types'; import { MultiFactorAssertion } from '../../../mfa/mfa_assertion'; import { Auth } from '../../../model/auth'; diff --git a/packages-exp/auth-exp/src/platform_browser/persistence/indexed_db.ts b/packages-exp/auth-exp/src/platform_browser/persistence/indexed_db.ts index 524f3541a70..3d8a389371c 100644 --- a/packages-exp/auth-exp/src/platform_browser/persistence/indexed_db.ts +++ b/packages-exp/auth-exp/src/platform_browser/persistence/indexed_db.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { PersistedBlob, Persistence, diff --git a/packages-exp/auth-exp/src/platform_browser/persistence/local_storage.ts b/packages-exp/auth-exp/src/platform_browser/persistence/local_storage.ts index c3b911315f5..2c30b9880c2 100644 --- a/packages-exp/auth-exp/src/platform_browser/persistence/local_storage.ts +++ b/packages-exp/auth-exp/src/platform_browser/persistence/local_storage.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { getUA } from '@firebase/util'; import { diff --git a/packages-exp/auth-exp/src/platform_browser/persistence/session_storage.ts b/packages-exp/auth-exp/src/platform_browser/persistence/session_storage.ts index 006958a3664..880ae64b1b4 100644 --- a/packages-exp/auth-exp/src/platform_browser/persistence/session_storage.ts +++ b/packages-exp/auth-exp/src/platform_browser/persistence/session_storage.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { Persistence, diff --git a/packages-exp/auth-exp/src/platform_browser/popup_redirect.test.ts b/packages-exp/auth-exp/src/platform_browser/popup_redirect.test.ts index 99b3a958ba7..c8a1a89fc5e 100644 --- a/packages-exp/auth-exp/src/platform_browser/popup_redirect.test.ts +++ b/packages-exp/auth-exp/src/platform_browser/popup_redirect.test.ts @@ -21,7 +21,7 @@ import * as sinon from 'sinon'; import * as sinonChai from 'sinon-chai'; import { SDK_VERSION } from '@firebase/app-exp'; -import { Config, ProviderId } from '@firebase/auth-types-exp'; +import { Config, ProviderId } from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; import { diff --git a/packages-exp/auth-exp/src/platform_browser/popup_redirect.ts b/packages-exp/auth-exp/src/platform_browser/popup_redirect.ts index af5dda39437..62ed6e7c6f8 100644 --- a/packages-exp/auth-exp/src/platform_browser/popup_redirect.ts +++ b/packages-exp/auth-exp/src/platform_browser/popup_redirect.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../model/public_types'; import { AuthEventManager } from '../core/auth/auth_event_manager'; import { AuthErrorCode } from '../core/errors'; diff --git a/packages-exp/auth-exp/src/platform_browser/providers/phone.ts b/packages-exp/auth-exp/src/platform_browser/providers/phone.ts index 9700cca1ff6..44ad3992421 100644 --- a/packages-exp/auth-exp/src/platform_browser/providers/phone.ts +++ b/packages-exp/auth-exp/src/platform_browser/providers/phone.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { SignInWithPhoneNumberResponse } from '../../api/authentication/sms'; import { ApplicationVerifier } from '../../model/application_verifier'; diff --git a/packages-exp/auth-exp/src/platform_browser/recaptcha/recaptcha_verifier.ts b/packages-exp/auth-exp/src/platform_browser/recaptcha/recaptcha_verifier.ts index aa7b9492cca..da8c0545c5c 100644 --- a/packages-exp/auth-exp/src/platform_browser/recaptcha/recaptcha_verifier.ts +++ b/packages-exp/auth-exp/src/platform_browser/recaptcha/recaptcha_verifier.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { getRecaptchaParams } from '../../api/authentication/recaptcha'; import { _castAuth } from '../../core/auth/auth_impl'; import { AuthErrorCode } from '../../core/errors'; diff --git a/packages-exp/auth-exp/src/platform_browser/strategies/phone.test.ts b/packages-exp/auth-exp/src/platform_browser/strategies/phone.test.ts index ccad0f343aa..583ab35872e 100644 --- a/packages-exp/auth-exp/src/platform_browser/strategies/phone.test.ts +++ b/packages-exp/auth-exp/src/platform_browser/strategies/phone.test.ts @@ -20,7 +20,7 @@ import * as chaiAsPromised from 'chai-as-promised'; import * as sinon from 'sinon'; import * as sinonChai from 'sinon-chai'; -import { OperationType, ProviderId } from '@firebase/auth-types-exp'; +import { OperationType, ProviderId } from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; import { mockEndpoint } from '../../../test/helpers/api/helper'; diff --git a/packages-exp/auth-exp/src/platform_browser/strategies/phone.ts b/packages-exp/auth-exp/src/platform_browser/strategies/phone.ts index 171c4d78641..89e3858e79c 100644 --- a/packages-exp/auth-exp/src/platform_browser/strategies/phone.ts +++ b/packages-exp/auth-exp/src/platform_browser/strategies/phone.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { startEnrollPhoneMfa } from '../../api/account_management/mfa'; import { startSignInPhoneMfa } from '../../api/authentication/mfa'; diff --git a/packages-exp/auth-exp/src/platform_browser/strategies/popup.test.ts b/packages-exp/auth-exp/src/platform_browser/strategies/popup.test.ts index 070b937b79c..4d3fc55d882 100644 --- a/packages-exp/auth-exp/src/platform_browser/strategies/popup.test.ts +++ b/packages-exp/auth-exp/src/platform_browser/strategies/popup.test.ts @@ -24,7 +24,7 @@ import { OperationType, PopupRedirectResolver, ProviderId -} from '@firebase/auth-types-exp'; +} from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; import { delay } from '../../../test/helpers/delay'; diff --git a/packages-exp/auth-exp/src/platform_browser/strategies/popup.ts b/packages-exp/auth-exp/src/platform_browser/strategies/popup.ts index 12244bfe759..2003780d3b7 100644 --- a/packages-exp/auth-exp/src/platform_browser/strategies/popup.ts +++ b/packages-exp/auth-exp/src/platform_browser/strategies/popup.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { _castAuth } from '../../core/auth/auth_impl'; import { AuthErrorCode } from '../../core/errors'; diff --git a/packages-exp/auth-exp/src/platform_browser/strategies/redirect.test.ts b/packages-exp/auth-exp/src/platform_browser/strategies/redirect.test.ts index 648202afeb2..4c88d9f6305 100644 --- a/packages-exp/auth-exp/src/platform_browser/strategies/redirect.test.ts +++ b/packages-exp/auth-exp/src/platform_browser/strategies/redirect.test.ts @@ -20,7 +20,7 @@ import * as chaiAsPromised from 'chai-as-promised'; import * as sinon from 'sinon'; import * as sinonChai from 'sinon-chai'; -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { delay } from '../../../test/helpers/delay'; import { BASE_AUTH_EVENT } from '../../../test/helpers/iframe_event'; diff --git a/packages-exp/auth-exp/src/platform_browser/strategies/redirect.ts b/packages-exp/auth-exp/src/platform_browser/strategies/redirect.ts index 9755255f65c..1df18e67ad9 100644 --- a/packages-exp/auth-exp/src/platform_browser/strategies/redirect.ts +++ b/packages-exp/auth-exp/src/platform_browser/strategies/redirect.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { OAuthProvider } from '../../core'; import { _castAuth } from '../../core/auth/auth_impl'; diff --git a/packages-exp/auth-exp/src/platform_cordova/popup_redirect/popup_redirect.test.ts b/packages-exp/auth-exp/src/platform_cordova/popup_redirect/popup_redirect.test.ts index 8c3859c42b0..8fc96f7bc87 100644 --- a/packages-exp/auth-exp/src/platform_cordova/popup_redirect/popup_redirect.test.ts +++ b/packages-exp/auth-exp/src/platform_cordova/popup_redirect/popup_redirect.test.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import * as sinon from 'sinon'; import * as chaiAsPromised from 'chai-as-promised'; import * as sinonChai from 'sinon-chai'; diff --git a/packages-exp/auth-exp/src/platform_cordova/popup_redirect/popup_redirect.ts b/packages-exp/auth-exp/src/platform_cordova/popup_redirect/popup_redirect.ts index b93e2b257bd..87790a6fdaf 100644 --- a/packages-exp/auth-exp/src/platform_cordova/popup_redirect/popup_redirect.ts +++ b/packages-exp/auth-exp/src/platform_cordova/popup_redirect/popup_redirect.ts @@ -16,7 +16,7 @@ */ import '../plugins'; -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { browserSessionPersistence } from '../../platform_browser/persistence/session_storage'; import { Auth } from '../../model/auth'; import { diff --git a/packages-exp/auth-exp/src/platform_cordova/popup_redirect/utils.ts b/packages-exp/auth-exp/src/platform_cordova/popup_redirect/utils.ts index e9d1b76d6ab..00b11fda491 100644 --- a/packages-exp/auth-exp/src/platform_cordova/popup_redirect/utils.ts +++ b/packages-exp/auth-exp/src/platform_cordova/popup_redirect/utils.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { AuthErrorCode } from '../../core/errors'; import { debugAssert, diff --git a/packages-exp/auth-exp/src/platform_cordova/strategies/redirect.ts b/packages-exp/auth-exp/src/platform_cordova/strategies/redirect.ts index 7e810031b15..6ab4c0f5570 100644 --- a/packages-exp/auth-exp/src/platform_cordova/strategies/redirect.ts +++ b/packages-exp/auth-exp/src/platform_cordova/strategies/redirect.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { _castAuth } from '../../core/auth/auth_impl'; import { AuthErrorCode } from '../../core/errors'; import { OAuthProvider } from '../../core/providers/oauth'; diff --git a/packages-exp/auth-exp/src/platform_react_native/persistence/react_native.test.ts b/packages-exp/auth-exp/src/platform_react_native/persistence/react_native.test.ts index 36a9b62c530..6c20283cb22 100644 --- a/packages-exp/auth-exp/src/platform_react_native/persistence/react_native.test.ts +++ b/packages-exp/auth-exp/src/platform_react_native/persistence/react_native.test.ts @@ -17,7 +17,7 @@ import { expect } from 'chai'; -import { ReactNativeAsyncStorage } from '@firebase/auth-types-exp'; +import { ReactNativeAsyncStorage } from '../../model/public_types'; import { testUser, testAuth } from '../../../test/helpers/mock_auth'; import { _getInstance } from '../../core/util/instantiator'; diff --git a/packages-exp/auth-exp/src/platform_react_native/persistence/react_native.ts b/packages-exp/auth-exp/src/platform_react_native/persistence/react_native.ts index 8d349a60a23..71be2ce654c 100644 --- a/packages-exp/auth-exp/src/platform_react_native/persistence/react_native.ts +++ b/packages-exp/auth-exp/src/platform_react_native/persistence/react_native.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '../../model/public_types'; import { Persistence, From e41b7f18d7878ffd7ea19bb56289ff9bb04c6256 Mon Sep 17 00:00:00 2001 From: Feiyang1 Date: Wed, 17 Feb 2021 22:25:56 -0800 Subject: [PATCH 04/13] Use named imports --- common/api-review/auth-exp.api.md | 600 ++++++++++++------ .../demo/src/worker/service-worker.ts | 3 +- .../auth-exp/demo/src/worker/web-worker.ts | 5 +- packages-exp/auth-exp/index.ts | 2 +- packages-exp/auth-exp/index.webworker.ts | 4 +- packages-exp/auth-exp/internal/index.ts | 7 +- packages-exp/auth-exp/rollup.config.shared.js | 120 ++-- .../src/api/account_management/mfa.ts | 8 +- packages-exp/auth-exp/src/api/index.ts | 2 +- .../src/core/auth/auth_event_manager.ts | 4 +- .../auth-exp/src/core/auth/auth_impl.test.ts | 24 +- .../auth-exp/src/core/auth/auth_impl.ts | 104 +-- .../auth-exp/src/core/auth/emulator.test.ts | 6 +- .../auth-exp/src/core/auth/emulator.ts | 4 +- .../src/core/auth/firebase_internal.test.ts | 10 +- .../src/core/auth/firebase_internal.ts | 12 +- .../auth-exp/src/core/auth/initialize.test.ts | 50 +- .../auth-exp/src/core/auth/initialize.ts | 11 +- .../auth-exp/src/core/auth/register.ts | 8 +- .../src/core/credentials/auth_credential.ts | 11 +- .../auth-exp/src/core/credentials/email.ts | 39 +- .../auth-exp/src/core/credentials/index.ts | 2 +- .../auth-exp/src/core/credentials/oauth.ts | 15 +- .../src/core/credentials/phone.test.ts | 25 +- .../auth-exp/src/core/credentials/phone.ts | 35 +- packages-exp/auth-exp/src/core/errors.ts | 12 +- packages-exp/auth-exp/src/core/index.ts | 26 +- .../src/core/persistence/in_memory.test.ts | 4 +- .../src/core/persistence/in_memory.ts | 8 +- .../auth-exp/src/core/persistence/index.ts | 3 +- .../persistence_user_manager.test.ts | 10 +- .../persistence/persistence_user_manager.ts | 20 +- .../auth-exp/src/core/providers/email.ts | 15 +- .../auth-exp/src/core/providers/facebook.ts | 33 +- .../auth-exp/src/core/providers/github.ts | 33 +- .../auth-exp/src/core/providers/google.ts | 33 +- .../auth-exp/src/core/providers/oauth.ts | 38 +- .../auth-exp/src/core/providers/twitter.ts | 33 +- .../abstract_popup_redirect_operation.test.ts | 4 +- .../abstract_popup_redirect_operation.ts | 40 +- .../auth-exp/src/core/strategies/anonymous.ts | 14 +- .../src/core/strategies/credential.test.ts | 14 +- .../src/core/strategies/credential.ts | 49 +- .../src/core/strategies/custom_token.test.ts | 4 +- .../src/core/strategies/custom_token.ts | 8 +- .../src/core/strategies/email.test.ts | 6 +- .../auth-exp/src/core/strategies/email.ts | 27 +- .../strategies/email_and_password.test.ts | 6 +- .../src/core/strategies/email_and_password.ts | 53 +- .../src/core/strategies/email_link.test.ts | 12 +- .../src/core/strategies/email_link.ts | 24 +- .../auth-exp/src/core/strategies/idp.test.ts | 4 +- .../auth-exp/src/core/strategies/idp.ts | 39 +- .../src/core/strategies/redirect.test.ts | 45 +- .../auth-exp/src/core/strategies/redirect.ts | 14 +- .../src/core/user/account_info.test.ts | 4 +- .../auth-exp/src/core/user/account_info.ts | 26 +- .../core/user/additional_user_info.test.ts | 10 +- .../src/core/user/additional_user_info.ts | 48 +- .../src/core/user/id_token_result.test.ts | 4 +- .../auth-exp/src/core/user/id_token_result.ts | 17 +- .../src/core/user/invalidation.test.ts | 10 +- .../auth-exp/src/core/user/invalidation.ts | 4 +- .../src/core/user/link_unlink.test.ts | 4 +- .../auth-exp/src/core/user/link_unlink.ts | 26 +- .../src/core/user/proactive_refresh.test.ts | 4 +- .../src/core/user/proactive_refresh.ts | 4 +- .../src/core/user/reauthenticate.test.ts | 9 +- .../auth-exp/src/core/user/reauthenticate.ts | 4 +- .../auth-exp/src/core/user/reload.test.ts | 4 +- packages-exp/auth-exp/src/core/user/reload.ts | 22 +- .../auth-exp/src/core/user/token_manager.ts | 9 +- .../core/user/user_credential_impl.test.ts | 4 +- .../src/core/user/user_credential_impl.ts | 36 +- .../auth-exp/src/core/user/user_impl.ts | 28 +- .../auth-exp/src/core/user/user_metadata.ts | 4 +- packages-exp/auth-exp/src/core/util/assert.ts | 23 +- .../auth-exp/src/core/util/handler.ts | 10 +- .../auth-exp/src/core/util/resolver.ts | 12 +- .../src/core/util/validate_origin.test.ts | 4 +- .../auth-exp/src/core/util/validate_origin.ts | 4 +- .../auth-exp/src/mfa/mfa_assertion.ts | 19 +- packages-exp/auth-exp/src/mfa/mfa_error.ts | 31 +- .../auth-exp/src/mfa/mfa_info.test.ts | 6 +- packages-exp/auth-exp/src/mfa/mfa_info.ts | 21 +- .../auth-exp/src/mfa/mfa_resolver.test.ts | 35 +- packages-exp/auth-exp/src/mfa/mfa_resolver.ts | 57 +- .../auth-exp/src/mfa/mfa_session.test.ts | 18 +- packages-exp/auth-exp/src/mfa/mfa_session.ts | 20 +- .../auth-exp/src/mfa/mfa_user.test.ts | 36 +- packages-exp/auth-exp/src/mfa/mfa_user.ts | 52 +- .../src/model/application_verifier.ts | 4 +- packages-exp/auth-exp/src/model/auth.ts | 45 +- .../auth-exp/src/model/popup_redirect.ts | 32 +- packages-exp/auth-exp/src/model/user.ts | 32 +- .../src/platform_browser/auth.test.ts | 81 ++- .../src/platform_browser/iframe/gapi.ts | 6 +- .../src/platform_browser/iframe/iframe.ts | 8 +- .../mfa/assertions/phone.test.ts | 25 +- .../platform_browser/mfa/assertions/phone.ts | 45 +- .../persistence/indexed_db.test.ts | 16 +- .../persistence/indexed_db.ts | 8 +- .../persistence/local_storage.test.ts | 6 +- .../persistence/local_storage.ts | 8 +- .../persistence/session_storage.test.ts | 6 +- .../persistence/session_storage.ts | 8 +- .../platform_browser/popup_redirect.test.ts | 6 +- .../src/platform_browser/popup_redirect.ts | 26 +- .../src/platform_browser/providers/phone.ts | 47 +- .../recaptcha/recaptcha_loader.ts | 8 +- .../recaptcha/recaptcha_mock.ts | 4 +- .../recaptcha/recaptcha_verifier.ts | 15 +- .../platform_browser/strategies/phone.test.ts | 38 +- .../src/platform_browser/strategies/phone.ts | 81 +-- .../platform_browser/strategies/popup.test.ts | 6 +- .../src/platform_browser/strategies/popup.ts | 52 +- .../strategies/redirect.test.ts | 79 +-- .../platform_browser/strategies/redirect.ts | 48 +- .../src/platform_browser/util/popup.test.ts | 4 +- .../src/platform_browser/util/popup.ts | 4 +- .../platform_cordova/popup_redirect/events.ts | 17 +- .../popup_redirect/popup_redirect.test.ts | 10 +- .../popup_redirect/popup_redirect.ts | 25 +- .../platform_cordova/popup_redirect/utils.ts | 12 +- .../platform_cordova/strategies/redirect.ts | 12 +- .../persistence/react_native.test.ts | 4 +- .../persistence/react_native.ts | 10 +- .../test/helpers/integration/helpers.ts | 2 +- .../auth-exp/test/helpers/mock_auth.ts | 12 +- .../test/helpers/mock_auth_credential.ts | 14 +- .../helpers/mock_popup_redirect_resolver.ts | 11 +- .../test/integration/flows/anonymous.test.ts | 5 +- .../test/integration/flows/email.test.ts | 6 +- .../test/integration/flows/phone.test.ts | 8 +- 134 files changed, 1858 insertions(+), 1409 deletions(-) diff --git a/common/api-review/auth-exp.api.md b/common/api-review/auth-exp.api.md index f5f119a7748..752cac75161 100644 --- a/common/api-review/auth-exp.api.md +++ b/common/api-review/auth-exp.api.md @@ -4,60 +4,54 @@ ```ts -import { ActionCodeInfo } from '@firebase/auth-types-exp'; -import { ActionCodeOperation } from '@firebase/auth-types-exp'; -import { ActionCodeSettings } from '@firebase/auth-types-exp'; -import { AdditionalUserInfo } from '@firebase/auth-types-exp'; -import { ApplicationVerifier } from '@firebase/auth-types-exp'; -import { Auth } from '@firebase/auth-types-exp'; -import { AuthError } from '@firebase/auth-types-exp'; -import { AuthErrorMap } from '@firebase/auth-types-exp'; -import { AuthProvider } from '@firebase/auth-types-exp'; -import { AuthSettings } from '@firebase/auth-types-exp'; import { CompleteFn } from '@firebase/util'; -import { Config } from '@firebase/auth-types-exp'; -import { ConfirmationResult } from '@firebase/auth-types-exp'; import { ErrorFactory } from '@firebase/util'; import { ErrorFn } from '@firebase/util'; -import * as externs from '@firebase/auth-types-exp'; -import { FactorId } from '@firebase/auth-types-exp'; import { FirebaseApp } from '@firebase/app-exp'; import { FirebaseError } from '@firebase/util'; -import { IdTokenResult } from '@firebase/auth-types-exp'; -import { MultiFactorAssertion } from '@firebase/auth-types-exp'; -import { MultiFactorError } from '@firebase/auth-types-exp'; -import { MultiFactorInfo } from '@firebase/auth-types-exp'; -import { MultiFactorResolver } from '@firebase/auth-types-exp'; -import { MultiFactorSession } from '@firebase/auth-types-exp'; -import { MultiFactorUser } from '@firebase/auth-types-exp'; import { NextFn } from '@firebase/util'; -import { OperationType } from '@firebase/auth-types-exp'; -import { ParsedToken } from '@firebase/auth-types-exp'; -import { Persistence } from '@firebase/auth-types-exp'; -import { PhoneInfoOptions } from '@firebase/auth-types-exp'; -import { PhoneMultiFactorAssertion } from '@firebase/auth-types-exp'; -import { PhoneMultiFactorEnrollInfoOptions } from '@firebase/auth-types-exp'; -import { PhoneMultiFactorSignInInfoOptions } from '@firebase/auth-types-exp'; -import { PhoneSingleFactorInfoOptions } from '@firebase/auth-types-exp'; -import { PopupRedirectResolver } from '@firebase/auth-types-exp'; -import { ProviderId } from '@firebase/auth-types-exp'; -import { ReactNativeAsyncStorage } from '@firebase/auth-types-exp'; -import { SignInMethod } from '@firebase/auth-types-exp'; +import { Observer } from '@firebase/util'; import { Unsubscribe } from '@firebase/util'; -import { User } from '@firebase/auth-types-exp'; -import { UserCredential } from '@firebase/auth-types-exp'; -import { UserInfo } from '@firebase/auth-types-exp'; -import { UserMetadata } from '@firebase/auth-types-exp'; -import { UserProfile } from '@firebase/auth-types-exp'; -export { ActionCodeInfo } +// @public +export interface ActionCodeInfo { + data: { + email?: string | null; + multiFactorInfo?: MultiFactorInfo | null; + previousEmail?: string | null; + }; + operation: ActionCodeOperation; +} -export { ActionCodeOperation } +// @public +export const enum ActionCodeOperation { + EMAIL_SIGNIN = "EMAIL_SIGNIN", + PASSWORD_RESET = "PASSWORD_RESET", + RECOVER_EMAIL = "RECOVER_EMAIL", + REVERT_SECOND_FACTOR_ADDITION = "REVERT_SECOND_FACTOR_ADDITION", + VERIFY_AND_CHANGE_EMAIL = "VERIFY_AND_CHANGE_EMAIL", + VERIFY_EMAIL = "VERIFY_EMAIL" +} -export { ActionCodeSettings } +// @public +export interface ActionCodeSettings { + android?: { + installApp?: boolean; + minimumVersion?: string; + packageName: string; + }; + dynamicLinkDomain?: string; + handleCodeInApp?: boolean; + iOS?: { + bundleId: string; + }; + url: string; +} +// Warning: (ae-forgotten-export) The symbol "ActionCodeURL" needs to be exported by the entry point index.d.ts +// // @public (undocumented) -export class ActionCodeURL implements externs.ActionCodeURL { +export class ActionCodeURL implements ActionCodeURL_2 { // @internal constructor(actionLink: string); // (undocumented) @@ -69,37 +63,64 @@ export class ActionCodeURL implements externs.ActionCodeURL { // (undocumented) readonly languageCode: string | null; // (undocumented) - readonly operation: externs.ActionCodeOperation; + readonly operation: ActionCodeOperation; // (undocumented) - static parseLink(link: string): externs.ActionCodeURL | null; + static parseLink(link: string): ActionCodeURL | null; // (undocumented) readonly tenantId: string | null; } -export { AdditionalUserInfo } - -export { ApplicationVerifier } +// @public +export interface AdditionalUserInfo { + readonly isNewUser: boolean; + readonly profile: Record | null; + readonly providerId: string | null; + readonly username?: string | null; +} // @public -export function applyActionCode(auth: externs.Auth, oobCode: string): Promise; +export interface ApplicationVerifier { + readonly type: string; + verify(): Promise; +} -export { Auth } +// @public +export function applyActionCode(auth: Auth, oobCode: string): Promise; + +// @public +export interface Auth { + readonly config: Config; + readonly currentUser: User | null; + // Warning: (ae-forgotten-export) The symbol "EmulatorConfig" needs to be exported by the entry point index.d.ts + readonly emulatorConfig: EmulatorConfig | null; + languageCode: string | null; + readonly name: string; + // Warning: (ae-forgotten-export) The symbol "NextOrObserver" needs to be exported by the entry point index.d.ts + onAuthStateChanged(nextOrObserver: NextOrObserver, error?: ErrorFn, completed?: CompleteFn): Unsubscribe; + onIdTokenChanged(nextOrObserver: NextOrObserver, error?: ErrorFn, completed?: CompleteFn): Unsubscribe; + setPersistence(persistence: Persistence): Promise; + readonly settings: AuthSettings; + signOut(): Promise; + tenantId: string | null; + updateCurrentUser(user: User | null): Promise; + useDeviceLanguage(): void; +} // @public (undocumented) export class AuthCredential { // @internal protected constructor(providerId: string, signInMethod: string); - // Warning: (ae-forgotten-export) The symbol "Auth" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "AuthInternal" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "PhoneOrOauthTokenResponse" needs to be exported by the entry point index.d.ts // // @internal (undocumented) - _getIdTokenResponse(_auth: Auth_2): Promise; + _getIdTokenResponse(_auth: AuthInternal): Promise; // @internal (undocumented) - _getReauthenticationResolver(_auth: Auth_2): Promise; + _getReauthenticationResolver(_auth: AuthInternal): Promise; // Warning: (ae-forgotten-export) The symbol "IdTokenResponse" needs to be exported by the entry point index.d.ts // // @internal (undocumented) - _linkToIdToken(_auth: Auth_2, _idToken: string): Promise; + _linkToIdToken(_auth: AuthInternal, _idToken: string): Promise; // (undocumented) readonly providerId: string; // (undocumented) @@ -108,47 +129,75 @@ export class AuthCredential { toJSON(): object; } -export { AuthError } +// @public +export interface AuthError extends FirebaseError { + readonly appName: string; + readonly email?: string; + readonly phoneNumber?: string; + readonly tenantid?: string; +} -export { AuthErrorMap } +// @public +export interface AuthErrorMap { +} -export { AuthProvider } +// @public +export interface AuthProvider { + readonly providerId: string; +} -export { AuthSettings } +// @public +export interface AuthSettings { + appVerificationDisabledForTesting: boolean; +} // @public -export const browserLocalPersistence: externs.Persistence; +export const browserLocalPersistence: Persistence; // @public -export const browserPopupRedirectResolver: externs.PopupRedirectResolver; +export const browserPopupRedirectResolver: PopupRedirectResolver; // @public -export const browserSessionPersistence: externs.Persistence; +export const browserSessionPersistence: Persistence; // @public -export function checkActionCode(auth: externs.Auth, oobCode: string): Promise; +export function checkActionCode(auth: Auth, oobCode: string): Promise; -export { Config } +// @public +export interface Config { + apiHost: string; + apiKey: string; + apiScheme: string; + authDomain?: string; + sdkClientVersion: string; + tokenApiHost: string; +} -export { ConfirmationResult } +// @public +export interface ConfirmationResult { + confirm(verificationCode: string): Promise; + readonly verificationId: string; +} // @public -export function confirmPasswordReset(auth: externs.Auth, oobCode: string, newPassword: string): Promise; +export function confirmPasswordReset(auth: Auth, oobCode: string, newPassword: string): Promise; // @public -export function createUserWithEmailAndPassword(auth: externs.Auth, email: string, password: string): Promise; +export function createUserWithEmailAndPassword(auth: Auth, email: string, password: string): Promise; // @public export type CustomParameters = Record; // @public -export const debugErrorMap: externs.AuthErrorMap; +export const debugErrorMap: AuthErrorMap; // @public -export function deleteUser(user: externs.User): Promise; +export function deleteUser(user: User): Promise; +// Warning: (ae-forgotten-export) The symbol "AuthCredential" needs to be exported by the entry point index.d.ts +// // @public -export class EmailAuthCredential extends AuthCredential implements externs.AuthCredential { +export class EmailAuthCredential extends AuthCredential implements AuthCredential_2 { // (undocumented) readonly email: string; // @internal (undocumented) @@ -158,11 +207,11 @@ export class EmailAuthCredential extends AuthCredential implements externs.AuthC // (undocumented) static fromJSON(json: object | string): EmailAuthCredential | null; // @internal (undocumented) - _getIdTokenResponse(auth: Auth_2): Promise; + _getIdTokenResponse(auth: AuthInternal): Promise; // @internal (undocumented) - _getReauthenticationResolver(auth: Auth_2): Promise; + _getReauthenticationResolver(auth: AuthInternal): Promise; // @internal (undocumented) - _linkToIdToken(auth: Auth_2, idToken: string): Promise; + _linkToIdToken(auth: AuthInternal, idToken: string): Promise; // (undocumented) readonly password: string; // (undocumented) @@ -171,120 +220,162 @@ export class EmailAuthCredential extends AuthCredential implements externs.AuthC toJSON(): object; } +// Warning: (ae-forgotten-export) The symbol "EmailAuthProvider" needs to be exported by the entry point index.d.ts +// // @public (undocumented) -export class EmailAuthProvider implements externs.EmailAuthProvider { +export class EmailAuthProvider implements EmailAuthProvider_2 { // (undocumented) static credential(email: string, password: string): EmailAuthCredential; // (undocumented) static credentialWithLink(email: string, emailLink: string): EmailAuthCredential; // (undocumented) - static readonly EMAIL_LINK_SIGN_IN_METHOD = externs.SignInMethod.EMAIL_LINK; + static readonly EMAIL_LINK_SIGN_IN_METHOD = SignInMethod.EMAIL_LINK; // (undocumented) - static readonly EMAIL_PASSWORD_SIGN_IN_METHOD = externs.SignInMethod.EMAIL_PASSWORD; + static readonly EMAIL_PASSWORD_SIGN_IN_METHOD = SignInMethod.EMAIL_PASSWORD; // (undocumented) - static readonly PROVIDER_ID = externs.ProviderId.PASSWORD; + static readonly PROVIDER_ID = ProviderId.PASSWORD; // (undocumented) - readonly providerId = externs.ProviderId.PASSWORD; + readonly providerId = ProviderId.PASSWORD; } // @public export class FacebookAuthProvider extends OAuthProvider { constructor(); - static credential(accessToken: string): externs.OAuthCredential; - static credentialFromError(error: FirebaseError): externs.OAuthCredential | null; - static credentialFromResult(userCredential: externs.UserCredential): externs.OAuthCredential | null; - static readonly FACEBOOK_SIGN_IN_METHOD = externs.SignInMethod.FACEBOOK; - static readonly PROVIDER_ID = externs.ProviderId.FACEBOOK; + // Warning: (ae-forgotten-export) The symbol "OAuthCredential" needs to be exported by the entry point index.d.ts + static credential(accessToken: string): OAuthCredential_2; + static credentialFromError(error: FirebaseError): OAuthCredential_2 | null; + static credentialFromResult(userCredential: UserCredential): OAuthCredential_2 | null; + static readonly FACEBOOK_SIGN_IN_METHOD = SignInMethod.FACEBOOK; + static readonly PROVIDER_ID = ProviderId.FACEBOOK; } -export { FactorId } +// @public +export const enum FactorId { + PHONE = "phone" +} // @public -export function fetchSignInMethodsForEmail(auth: externs.Auth, email: string): Promise; +export function fetchSignInMethodsForEmail(auth: Auth, email: string): Promise; // @public -export function getAdditionalUserInfo(userCredential: externs.UserCredential): externs.AdditionalUserInfo | null; +export function getAdditionalUserInfo(userCredential: UserCredential): AdditionalUserInfo | null; // @public export function getAuth(app: FirebaseApp): Auth; // @public -export function getIdToken(user: externs.User, forceRefresh?: boolean): Promise; +export function getIdToken(user: User, forceRefresh?: boolean): Promise; // @public -export function getIdTokenResult(user: externs.User, forceRefresh?: boolean): Promise; +export function getIdTokenResult(user: User, forceRefresh?: boolean): Promise; +// Warning: (ae-forgotten-export) The symbol "MultiFactorError" needs to be exported by the entry point index.d.ts +// // @public -export function getMultiFactorResolver(auth: externs.Auth, error: externs.MultiFactorError): externs.MultiFactorResolver; +export function getMultiFactorResolver(auth: Auth, error: MultiFactorError_2): MultiFactorResolver; // @public -export function getRedirectResult(auth: externs.Auth, resolver?: externs.PopupRedirectResolver): Promise; +export function getRedirectResult(auth: Auth, resolver?: PopupRedirectResolver): Promise; // @public export class GithubAuthProvider extends OAuthProvider { constructor(); - static credential(accessToken: string): externs.OAuthCredential; - static credentialFromError(error: FirebaseError): externs.OAuthCredential | null; - static credentialFromResult(userCredential: externs.UserCredential): externs.OAuthCredential | null; - static readonly GITHUB_SIGN_IN_METHOD = externs.SignInMethod.GITHUB; - static readonly PROVIDER_ID = externs.ProviderId.GITHUB; + static credential(accessToken: string): OAuthCredential_2; + static credentialFromError(error: FirebaseError): OAuthCredential_2 | null; + static credentialFromResult(userCredential: UserCredential): OAuthCredential_2 | null; + static readonly GITHUB_SIGN_IN_METHOD = SignInMethod.GITHUB; + static readonly PROVIDER_ID = ProviderId.GITHUB; } // @public export class GoogleAuthProvider extends OAuthProvider { constructor(); - static credential(idToken?: string | null, accessToken?: string | null): externs.OAuthCredential; - static credentialFromError(error: FirebaseError): externs.OAuthCredential | null; - static credentialFromResult(userCredential: externs.UserCredential): externs.OAuthCredential | null; - static readonly GOOGLE_SIGN_IN_METHOD = externs.SignInMethod.GOOGLE; - static readonly PROVIDER_ID = externs.ProviderId.GOOGLE; + static credential(idToken?: string | null, accessToken?: string | null): OAuthCredential_2; + static credentialFromError(error: FirebaseError): OAuthCredential_2 | null; + static credentialFromResult(userCredential: UserCredential): OAuthCredential_2 | null; + static readonly GOOGLE_SIGN_IN_METHOD = SignInMethod.GOOGLE; + static readonly PROVIDER_ID = ProviderId.GOOGLE; } -export { IdTokenResult } +// @public +export interface IdTokenResult { + authTime: string; + claims: ParsedToken; + expirationTime: string; + issuedAtTime: string; + signInProvider: string | null; + signInSecondFactor: string | null; + token: string; +} // @public -export const indexedDBLocalPersistence: externs.Persistence; +export const indexedDBLocalPersistence: Persistence; // Warning: (ae-forgotten-export) The symbol "Dependencies" needs to be exported by the entry point index.d.ts // // @public (undocumented) -export function initializeAuth(app: FirebaseApp, deps?: Dependencies): externs.Auth; +export function initializeAuth(app: FirebaseApp, deps?: Dependencies): Auth; // @public -export const inMemoryPersistence: externs.Persistence; +export const inMemoryPersistence: Persistence; // @public -export function isSignInWithEmailLink(auth: externs.Auth, emailLink: string): boolean; +export function isSignInWithEmailLink(auth: Auth, emailLink: string): boolean; // @public -export function linkWithCredential(user: externs.User, credential: externs.AuthCredential): Promise; +export function linkWithCredential(user: User, credential: AuthCredential_2): Promise; // @public -export function linkWithPhoneNumber(user: externs.User, phoneNumber: string, appVerifier: externs.ApplicationVerifier): Promise; +export function linkWithPhoneNumber(user: User, phoneNumber: string, appVerifier: ApplicationVerifier): Promise; // @public -export function linkWithPopup(user: externs.User, provider: externs.AuthProvider, resolver?: externs.PopupRedirectResolver): Promise; +export function linkWithPopup(user: User, provider: AuthProvider, resolver?: PopupRedirectResolver): Promise; // @public -export function linkWithRedirect(user: externs.User, provider: externs.AuthProvider, resolver?: externs.PopupRedirectResolver): Promise; +export function linkWithRedirect(user: User, provider: AuthProvider, resolver?: PopupRedirectResolver): Promise; // @public -export function multiFactor(user: externs.User): externs.MultiFactorUser; +export function multiFactor(user: User): MultiFactorUser; -export { MultiFactorAssertion } +// @public +export interface MultiFactorAssertion { + readonly factorId: FactorId; +} -export { MultiFactorError } +// @public +export interface MultiFactorError extends AuthError { + readonly operationType: OperationType; +} -export { MultiFactorInfo } +// @public +export interface MultiFactorInfo { + readonly displayName?: string | null; + readonly enrollmentTime: string; + readonly factorId: FactorId; + readonly uid: string; +} -export { MultiFactorResolver } +// @public +export interface MultiFactorResolver { + readonly hints: MultiFactorInfo[]; + resolveSignIn(assertion: MultiFactorAssertion): Promise; + readonly session: MultiFactorSession; +} -export { MultiFactorSession } +// @public +export interface MultiFactorSession { +} -export { MultiFactorUser } +// @public +export interface MultiFactorUser { + enroll(assertion: MultiFactorAssertion, displayName?: string | null): Promise; + readonly enrolledFactors: MultiFactorInfo[]; + getSession(): Promise; + unenroll(option: MultiFactorInfo | string): Promise; +} // @public (undocumented) -export class OAuthCredential extends AuthCredential implements externs.OAuthCredential { +export class OAuthCredential extends AuthCredential implements OAuthCredential_2 { // (undocumented) accessToken?: string; // (undocumented) @@ -294,13 +385,13 @@ export class OAuthCredential extends AuthCredential implements externs.OAuthCred // @internal (undocumented) static _fromParams(params: OAuthCredentialParams): OAuthCredential; // @internal (undocumented) - _getIdTokenResponse(auth: Auth_2): Promise; + _getIdTokenResponse(auth: AuthInternal): Promise; // @internal (undocumented) - _getReauthenticationResolver(auth: Auth_2): Promise; + _getReauthenticationResolver(auth: AuthInternal): Promise; // (undocumented) idToken?: string; // @internal (undocumented) - _linkToIdToken(auth: Auth_2, idToken: string): Promise; + _linkToIdToken(auth: AuthInternal, idToken: string): Promise; // @internal (undocumented) nonce?: string; // (undocumented) @@ -317,41 +408,62 @@ export interface OAuthCredentialOptions { } // @public -export class OAuthProvider implements externs.AuthProvider { +export class OAuthProvider implements AuthProvider { constructor(providerId: string); - addScope(scope: string): externs.AuthProvider; - credential(params: OAuthCredentialOptions): externs.OAuthCredential; - static credentialFromError(error: FirebaseError): externs.OAuthCredential | null; + addScope(scope: string): AuthProvider; + credential(params: OAuthCredentialOptions): OAuthCredential_2; + static credentialFromError(error: FirebaseError): OAuthCredential_2 | null; // (undocumented) - static credentialFromJSON(json: object | string): externs.OAuthCredential; - static credentialFromResult(userCredential: externs.UserCredential): externs.OAuthCredential | null; + static credentialFromJSON(json: object | string): OAuthCredential_2; + static credentialFromResult(userCredential: UserCredential): OAuthCredential_2 | null; // @internal (undocumented) defaultLanguageCode: string | null; getCustomParameters(): CustomParameters; getScopes(): string[]; // (undocumented) readonly providerId: string; - setCustomParameters(customOAuthParameters: CustomParameters): externs.AuthProvider; + setCustomParameters(customOAuthParameters: CustomParameters): AuthProvider; setDefaultLanguage(languageCode: string | null): void; } // @public -export function onAuthStateChanged(auth: externs.Auth, nextOrObserver: externs.NextOrObserver, error?: ErrorFn, completed?: CompleteFn): Unsubscribe; +export function onAuthStateChanged(auth: Auth, nextOrObserver: NextOrObserver, error?: ErrorFn, completed?: CompleteFn): Unsubscribe; // @public -export function onIdTokenChanged(auth: externs.Auth, nextOrObserver: externs.NextOrObserver, error?: ErrorFn, completed?: CompleteFn): Unsubscribe; +export function onIdTokenChanged(auth: Auth, nextOrObserver: NextOrObserver, error?: ErrorFn, completed?: CompleteFn): Unsubscribe; -export { OperationType } +// @public +export const enum OperationType { + LINK = "link", + REAUTHENTICATE = "reauthenticate", + SIGN_IN = "signIn" +} // @public (undocumented) -export function parseActionCodeURL(link: string): externs.ActionCodeURL | null; - -export { ParsedToken } +export function parseActionCodeURL(link: string): ActionCodeURL | null; + +// @public +export interface ParsedToken { + [key: string]: string | object | undefined; + 'auth_time'?: string; + 'exp'?: string; + 'firebase'?: { + 'sign_in_provider'?: string; + 'sign_in_second_factor'?: string; + }; + 'iat'?: string; + 'sub'?: string; +} -export { Persistence } +// @public +export interface Persistence { + readonly type: 'SESSION' | 'LOCAL' | 'NONE'; +} +// Warning: (ae-forgotten-export) The symbol "PhoneAuthCredential" needs to be exported by the entry point index.d.ts +// // @public (undocumented) -export class PhoneAuthCredential extends AuthCredential implements externs.PhoneAuthCredential { +export class PhoneAuthCredential extends AuthCredential implements PhoneAuthCredential_2 { // (undocumented) static fromJSON(json: object | string): PhoneAuthCredential | null; // @internal (undocumented) @@ -359,11 +471,11 @@ export class PhoneAuthCredential extends AuthCredential implements externs.Phone // @internal (undocumented) static _fromVerification(verificationId: string, verificationCode: string): PhoneAuthCredential; // @internal (undocumented) - _getIdTokenResponse(auth: Auth_2): Promise; + _getIdTokenResponse(auth: AuthInternal): Promise; // @internal (undocumented) - _getReauthenticationResolver(auth: Auth_2): Promise; + _getReauthenticationResolver(auth: AuthInternal): Promise; // @internal (undocumented) - _linkToIdToken(auth: Auth_2, idToken: string): Promise; + _linkToIdToken(auth: AuthInternal, idToken: string): Promise; // Warning: (ae-forgotten-export) The symbol "SignInWithPhoneNumberRequest" needs to be exported by the entry point index.d.ts // // @internal (undocumented) @@ -372,66 +484,113 @@ export class PhoneAuthCredential extends AuthCredential implements externs.Phone toJSON(): object; } +// Warning: (ae-forgotten-export) The symbol "PhoneAuthProvider" needs to be exported by the entry point index.d.ts +// // @public (undocumented) -export class PhoneAuthProvider implements externs.PhoneAuthProvider { - constructor(auth: externs.Auth); +export class PhoneAuthProvider implements PhoneAuthProvider_2 { + constructor(auth: Auth); // (undocumented) static credential(verificationId: string, verificationCode: string): PhoneAuthCredential; // (undocumented) - static credentialFromResult(userCredential: externs.UserCredential): externs.AuthCredential | null; + static credentialFromResult(userCredential: UserCredential): AuthCredential_2 | null; // (undocumented) - static readonly PHONE_SIGN_IN_METHOD = externs.SignInMethod.PHONE; + static readonly PHONE_SIGN_IN_METHOD = SignInMethod.PHONE; // (undocumented) - static readonly PROVIDER_ID = externs.ProviderId.PHONE; + static readonly PROVIDER_ID = ProviderId.PHONE; // (undocumented) - readonly providerId = externs.ProviderId.PHONE; + readonly providerId = ProviderId.PHONE; // (undocumented) - verifyPhoneNumber(phoneOptions: externs.PhoneInfoOptions | string, applicationVerifier: externs.ApplicationVerifier): Promise; + verifyPhoneNumber(phoneOptions: PhoneInfoOptions | string, applicationVerifier: ApplicationVerifier): Promise; } -export { PhoneInfoOptions } +// @public +export type PhoneInfoOptions = PhoneSingleFactorInfoOptions | PhoneMultiFactorEnrollInfoOptions | PhoneMultiFactorSignInInfoOptions; -export { PhoneMultiFactorAssertion } +// @public +export interface PhoneMultiFactorAssertion extends MultiFactorAssertion { +} -export { PhoneMultiFactorEnrollInfoOptions } +// @public +export interface PhoneMultiFactorEnrollInfoOptions { + phoneNumber: string; + session: MultiFactorSession; +} +// Warning: (ae-forgotten-export) The symbol "PhoneMultiFactorGenerator" needs to be exported by the entry point index.d.ts +// // @public (undocumented) -export class PhoneMultiFactorGenerator implements externs.PhoneMultiFactorGenerator { +export class PhoneMultiFactorGenerator implements PhoneMultiFactorGenerator_2 { // (undocumented) - static assertion(credential: externs.PhoneAuthCredential): externs.PhoneMultiFactorAssertion; + static assertion(credential: PhoneAuthCredential_2): PhoneMultiFactorAssertion; } -export { PhoneMultiFactorSignInInfoOptions } +// @public +export interface PhoneMultiFactorSignInInfoOptions { + multiFactorHint?: MultiFactorInfo; + multiFactorUid?: string; + session: MultiFactorSession; +} -export { PhoneSingleFactorInfoOptions } +// @public +export interface PhoneSingleFactorInfoOptions { + phoneNumber: string; +} -export { PopupRedirectResolver } +// @public +export interface PopupRedirectResolver { +} // @public -export const prodErrorMap: externs.AuthErrorMap; +export const prodErrorMap: AuthErrorMap; -export { ProviderId } +// @public +export const enum ProviderId { + // (undocumented) + ANONYMOUS = "anonymous", + // (undocumented) + CUSTOM = "custom", + // (undocumented) + FACEBOOK = "facebook.com", + // (undocumented) + FIREBASE = "firebase", + // (undocumented) + GITHUB = "github.com", + // (undocumented) + GOOGLE = "google.com", + // (undocumented) + PASSWORD = "password", + // (undocumented) + PHONE = "phone", + // (undocumented) + TWITTER = "twitter.com" +} -export { ReactNativeAsyncStorage } +// @public +export interface ReactNativeAsyncStorage { + getItem(key: string): Promise; + removeItem(key: string): Promise; + setItem(key: string, value: string): Promise; +} // @public -export function reauthenticateWithCredential(user: externs.User, credential: externs.AuthCredential): Promise; +export function reauthenticateWithCredential(user: User, credential: AuthCredential_2): Promise; // @public -export function reauthenticateWithPhoneNumber(user: externs.User, phoneNumber: string, appVerifier: externs.ApplicationVerifier): Promise; +export function reauthenticateWithPhoneNumber(user: User, phoneNumber: string, appVerifier: ApplicationVerifier): Promise; // @public -export function reauthenticateWithPopup(user: externs.User, provider: externs.AuthProvider, resolver?: externs.PopupRedirectResolver): Promise; +export function reauthenticateWithPopup(user: User, provider: AuthProvider, resolver?: PopupRedirectResolver): Promise; // @public -export function reauthenticateWithRedirect(user: externs.User, provider: externs.AuthProvider, resolver?: externs.PopupRedirectResolver): Promise; +export function reauthenticateWithRedirect(user: User, provider: AuthProvider, resolver?: PopupRedirectResolver): Promise; -// Warning: (ae-forgotten-export) The symbol "ApplicationVerifier" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "RecaptchaVerifier" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "ApplicationVerifierInternal" needs to be exported by the entry point index.d.ts // // @public (undocumented) -export class RecaptchaVerifier implements externs.RecaptchaVerifier, ApplicationVerifier_2 { +export class RecaptchaVerifier implements RecaptchaVerifier_2, ApplicationVerifierInternal { // Warning: (ae-forgotten-export) The symbol "Parameters" needs to be exported by the entry point index.d.ts - constructor(containerOrId: HTMLElement | string, parameters: Parameters_2, authExtern: externs.Auth); + constructor(containerOrId: HTMLElement | string, parameters: Parameters_2, authExtern: Auth); // (undocumented) clear(): void; // Warning: (ae-forgotten-export) The symbol "ReCaptchaLoader" needs to be exported by the entry point index.d.ts @@ -449,104 +608,153 @@ export class RecaptchaVerifier implements externs.RecaptchaVerifier, Application } // @public -export function reload(user: externs.User): Promise; +export function reload(user: User): Promise; // @public -export function sendEmailVerification(user: externs.User, actionCodeSettings?: externs.ActionCodeSettings | null): Promise; +export function sendEmailVerification(user: User, actionCodeSettings?: ActionCodeSettings | null): Promise; // @public -export function sendPasswordResetEmail(auth: externs.Auth, email: string, actionCodeSettings?: externs.ActionCodeSettings): Promise; +export function sendPasswordResetEmail(auth: Auth, email: string, actionCodeSettings?: ActionCodeSettings): Promise; // @public -export function sendSignInLinkToEmail(auth: externs.Auth, email: string, actionCodeSettings?: externs.ActionCodeSettings): Promise; +export function sendSignInLinkToEmail(auth: Auth, email: string, actionCodeSettings?: ActionCodeSettings): Promise; // @public -export function setPersistence(auth: externs.Auth, persistence: externs.Persistence): Promise; +export function setPersistence(auth: Auth, persistence: Persistence): Promise; // @public -export function signInAnonymously(auth: externs.Auth): Promise; +export function signInAnonymously(auth: Auth): Promise; -export { SignInMethod } +// @public +export const enum SignInMethod { + // (undocumented) + ANONYMOUS = "anonymous", + // (undocumented) + EMAIL_LINK = "emailLink", + // (undocumented) + EMAIL_PASSWORD = "password", + // (undocumented) + FACEBOOK = "facebook.com", + // (undocumented) + GITHUB = "github.com", + // (undocumented) + GOOGLE = "google.com", + // (undocumented) + PHONE = "phone", + // (undocumented) + TWITTER = "twitter.com" +} // @public -export function signInWithCredential(auth: externs.Auth, credential: externs.AuthCredential): Promise; +export function signInWithCredential(auth: Auth, credential: AuthCredential_2): Promise; // @public -export function signInWithCustomToken(auth: externs.Auth, customToken: string): Promise; +export function signInWithCustomToken(auth: Auth, customToken: string): Promise; // @public -export function signInWithEmailAndPassword(auth: externs.Auth, email: string, password: string): Promise; +export function signInWithEmailAndPassword(auth: Auth, email: string, password: string): Promise; // @public -export function signInWithEmailLink(auth: externs.Auth, email: string, emailLink?: string): Promise; +export function signInWithEmailLink(auth: Auth, email: string, emailLink?: string): Promise; // @public -export function signInWithPhoneNumber(auth: externs.Auth, phoneNumber: string, appVerifier: externs.ApplicationVerifier): Promise; +export function signInWithPhoneNumber(auth: Auth, phoneNumber: string, appVerifier: ApplicationVerifier): Promise; // @public -export function signInWithPopup(auth: externs.Auth, provider: externs.AuthProvider, resolver?: externs.PopupRedirectResolver): Promise; +export function signInWithPopup(auth: Auth, provider: AuthProvider, resolver?: PopupRedirectResolver): Promise; // @public -export function signInWithRedirect(auth: externs.Auth, provider: externs.AuthProvider, resolver?: externs.PopupRedirectResolver): Promise; +export function signInWithRedirect(auth: Auth, provider: AuthProvider, resolver?: PopupRedirectResolver): Promise; // @public -export function signOut(auth: externs.Auth): Promise; +export function signOut(auth: Auth): Promise; // @public export class TwitterAuthProvider extends OAuthProvider { constructor(); - static credential(token: string, secret: string): externs.OAuthCredential; - static credentialFromError(error: FirebaseError): externs.OAuthCredential | null; - static credentialFromResult(userCredential: externs.UserCredential): externs.OAuthCredential | null; + static credential(token: string, secret: string): OAuthCredential_2; + static credentialFromError(error: FirebaseError): OAuthCredential_2 | null; + static credentialFromResult(userCredential: UserCredential): OAuthCredential_2 | null; // (undocumented) - static readonly PROVIDER_ID = externs.ProviderId.TWITTER; + static readonly PROVIDER_ID = ProviderId.TWITTER; // (undocumented) - static readonly TWITTER_SIGN_IN_METHOD = externs.SignInMethod.TWITTER; + static readonly TWITTER_SIGN_IN_METHOD = SignInMethod.TWITTER; } // @public -export function unlink(user: externs.User, providerId: externs.ProviderId): Promise; +export function unlink(user: User, providerId: ProviderId): Promise; // @public -export function updateCurrentUser(auth: externs.Auth, user: externs.User | null): Promise; +export function updateCurrentUser(auth: Auth, user: User | null): Promise; // @public -export function updateEmail(user: externs.User, newEmail: string): Promise; +export function updateEmail(user: User, newEmail: string): Promise; // @public -export function updatePassword(user: externs.User, newPassword: string): Promise; +export function updatePassword(user: User, newPassword: string): Promise; // @public -export function updatePhoneNumber(user: externs.User, credential: externs.PhoneAuthCredential): Promise; +export function updatePhoneNumber(user: User, credential: PhoneAuthCredential_2): Promise; // Warning: (ae-forgotten-export) The symbol "Profile" needs to be exported by the entry point index.d.ts // // @public -export function updateProfile(user: externs.User, { displayName, photoURL: photoUrl }: Profile): Promise; +export function updateProfile(user: User, { displayName, photoURL: photoUrl }: Profile): Promise; // @public -export function useAuthEmulator(auth: externs.Auth, url: string, options?: { +export function useAuthEmulator(auth: Auth, url: string, options?: { disableWarnings: boolean; }): void; // @public -export function useDeviceLanguage(auth: externs.Auth): void; +export function useDeviceLanguage(auth: Auth): void; -export { User } +// @public +export interface User extends UserInfo { + delete(): Promise; + readonly emailVerified: boolean; + getIdToken(forceRefresh?: boolean): Promise; + getIdTokenResult(forceRefresh?: boolean): Promise; + readonly isAnonymous: boolean; + readonly metadata: UserMetadata; + readonly providerData: UserInfo[]; + readonly refreshToken: string; + reload(): Promise; + readonly tenantId: string | null; + toJSON(): object; +} -export { UserCredential } +// @public +export interface UserCredential { + operationType: OperationType; + providerId: string | null; + user: User; +} -export { UserInfo } +// @public +export interface UserInfo { + readonly displayName: string | null; + readonly email: string | null; + readonly phoneNumber: string | null; + readonly photoURL: string | null; + readonly providerId: string; + readonly uid: string; +} -export { UserMetadata } +// @public +export interface UserMetadata { + readonly creationTime?: string; + readonly lastSignInTime?: string; +} -export { UserProfile } +// @public +export type UserProfile = Record; // @public -export function verifyBeforeUpdateEmail(user: externs.User, newEmail: string, actionCodeSettings?: externs.ActionCodeSettings | null): Promise; +export function verifyBeforeUpdateEmail(user: User, newEmail: string, actionCodeSettings?: ActionCodeSettings | null): Promise; // @public -export function verifyPasswordResetCode(auth: externs.Auth, code: string): Promise; +export function verifyPasswordResetCode(auth: Auth, code: string): Promise; // (No @packageDocumentation comment for this package) diff --git a/packages-exp/auth-exp/demo/src/worker/service-worker.ts b/packages-exp/auth-exp/demo/src/worker/service-worker.ts index 564e46517d4..d6316465619 100644 --- a/packages-exp/auth-exp/demo/src/worker/service-worker.ts +++ b/packages-exp/auth-exp/demo/src/worker/service-worker.ts @@ -21,8 +21,7 @@ * mode. */ import { initializeApp } from '@firebase/app-exp'; -import { getAuth } from '@firebase/auth-exp'; -import { User } from '@firebase/auth-types-exp'; +import { getAuth, User } from '@firebase/auth-exp'; import { config } from '../config'; diff --git a/packages-exp/auth-exp/demo/src/worker/web-worker.ts b/packages-exp/auth-exp/demo/src/worker/web-worker.ts index af6186b942b..b6a20defd0d 100644 --- a/packages-exp/auth-exp/demo/src/worker/web-worker.ts +++ b/packages-exp/auth-exp/demo/src/worker/web-worker.ts @@ -23,9 +23,10 @@ import { signInAnonymously, signInWithCredential, signInWithEmailAndPassword, - updateProfile + updateProfile, + OAuthCredential, + User } from '@firebase/auth-exp'; -import { OAuthCredential, User } from '@firebase/auth-types-exp'; import { config } from '../config'; diff --git a/packages-exp/auth-exp/index.ts b/packages-exp/auth-exp/index.ts index 0e54d9cba4a..c87b72d4628 100644 --- a/packages-exp/auth-exp/index.ts +++ b/packages-exp/auth-exp/index.ts @@ -104,7 +104,7 @@ export { RecaptchaVerifier } from './src/platform_browser/recaptcha/recaptcha_ve export { browserPopupRedirectResolver } from './src/platform_browser/popup_redirect'; // MFA -export { PhoneMultiFactorGenerator } from './src/platform_browser/mfa/assertions/phone'; +export { PhoneMultiFactorGeneratorImpl as PhoneMultiFactorGenerator } from './src/platform_browser/mfa/assertions/phone'; /** * Initializes an Auth instance with platform specific default dependencies. diff --git a/packages-exp/auth-exp/index.webworker.ts b/packages-exp/auth-exp/index.webworker.ts index e9fefb3691b..e50de0b702e 100644 --- a/packages-exp/auth-exp/index.webworker.ts +++ b/packages-exp/auth-exp/index.webworker.ts @@ -21,7 +21,7 @@ import { Auth } from './src/model/public_types'; import { AuthImpl } from './src/core/auth/auth_impl'; import { _initializeAuthInstance } from './src/core/auth/initialize'; import { _ComponentName, registerAuth } from './src/core/auth/register'; -import { Persistence } from './src/core/persistence'; +import { PersistenceInternal } from './src/core/persistence'; import { _getInstance } from './src/core/util/instantiator'; import { ClientPlatform } from './src/core/util/version'; import { indexedDBLocalPersistence } from './src/platform_browser/persistence/indexed_db'; @@ -45,7 +45,7 @@ export function getAuth(app: FirebaseApp): Auth { // This promise is intended to float; auth initialization happens in the // background, meanwhile the auth object may be used by the app. // eslint-disable-next-line @typescript-eslint/no-floating-promises - _getInstance(indexedDBLocalPersistence) + _getInstance(indexedDBLocalPersistence) ._isAvailable() .then(avail => { const deps = avail ? { persistence: indexedDBLocalPersistence } : {}; diff --git a/packages-exp/auth-exp/internal/index.ts b/packages-exp/auth-exp/internal/index.ts index bcec1430866..32fadd398b2 100644 --- a/packages-exp/auth-exp/internal/index.ts +++ b/packages-exp/auth-exp/internal/index.ts @@ -22,11 +22,14 @@ export * from '../index'; export { SignInWithIdpResponse } from '../src/api/authentication/idp'; export { AuthErrorCode } from '../src/core/errors'; -export { Persistence } from '../src/core/persistence'; +export { PersistenceInternal as Persistence } from '../src/core/persistence'; export { _persistenceKeyName } from '../src/core/persistence/persistence_user_manager'; export { UserImpl } from '../src/core/user/user_impl'; export { _getInstance } from '../src/core/util/instantiator'; -export { UserCredential, UserParameters } from '../src/model/user'; +export { + UserCredentialInternal as UserCredential, + UserParameters +} from '../src/model/user'; export { registerAuth } from '../src/core/auth/register'; export { DefaultConfig, AuthImpl } from '../src/core/auth/auth_impl'; diff --git a/packages-exp/auth-exp/rollup.config.shared.js b/packages-exp/auth-exp/rollup.config.shared.js index 81d65847521..db2299ef127 100644 --- a/packages-exp/auth-exp/rollup.config.shared.js +++ b/packages-exp/auth-exp/rollup.config.shared.js @@ -57,69 +57,69 @@ export function getConfig({ isReleaseBuild }) { output: [{ dir: 'dist/esm5', format: 'esm', sourcemap: true }], plugins: es5BuildPlugins, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) - }, + } /** * Web Worker Build (compiled without DOM) */ - { - input: 'index.webworker.ts', - output: [{ file: pkg.webworker, format: 'es', sourcemap: true }], - plugins: [ - ...commonPlugins, - getTypesScriptPlugin({ - isReleaseBuild, - compilerOptions: { - lib: [ - // Remove dom after we figure out why navigator stuff doesn't exist - 'dom', - 'es2015', - 'webworker' - ] - } - }) - ], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) - }, - /** - * Node.js Build - */ - { - input: { - index: 'index.node.ts', - internal: 'internal/index.ts' - }, - output: [{ dir: 'dist/node', format: 'cjs', sourcemap: true }], - plugins: es5BuildPlugins, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) - }, - /** - * Cordova Builds - */ - { - input: { - index: 'index.cordova.ts', - internal: 'internal/index.ts' - }, - output: [{ dir: 'dist/cordova', format: 'es', sourcemap: true }], - plugins: es5BuildPlugins, - external: id => - [...deps, 'cordova'].some(dep => id === dep || id.startsWith(`${dep}/`)) - }, - /** - * React Native Builds - */ - { - input: { - index: 'index.rn.ts', - internal: 'internal/index.ts' - }, - output: [{ dir: 'dist/rn', format: 'cjs', sourcemap: true }], - plugins: es5BuildPlugins, - external: id => - [...deps, 'react-native'].some( - dep => id === dep || id.startsWith(`${dep}/`) - ) - } + // { + // input: 'index.webworker.ts', + // output: [{ file: pkg.webworker, format: 'es', sourcemap: true }], + // plugins: [ + // ...commonPlugins, + // getTypesScriptPlugin({ + // isReleaseBuild, + // compilerOptions: { + // lib: [ + // // Remove dom after we figure out why navigator stuff doesn't exist + // 'dom', + // 'es2015', + // 'webworker' + // ] + // } + // }) + // ], + // external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) + // }, + // /** + // * Node.js Build + // */ + // { + // input: { + // index: 'index.node.ts', + // internal: 'internal/index.ts' + // }, + // output: [{ dir: 'dist/node', format: 'cjs', sourcemap: true }], + // plugins: es5BuildPlugins, + // external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) + // }, + // /** + // * Cordova Builds + // */ + // { + // input: { + // index: 'index.cordova.ts', + // internal: 'internal/index.ts' + // }, + // output: [{ dir: 'dist/cordova', format: 'es', sourcemap: true }], + // plugins: es5BuildPlugins, + // external: id => + // [...deps, 'cordova'].some(dep => id === dep || id.startsWith(`${dep}/`)) + // }, + // /** + // * React Native Builds + // */ + // { + // input: { + // index: 'index.rn.ts', + // internal: 'internal/index.ts' + // }, + // output: [{ dir: 'dist/rn', format: 'cjs', sourcemap: true }], + // plugins: es5BuildPlugins, + // external: id => + // [...deps, 'react-native'].some( + // dep => id === dep || id.startsWith(`${dep}/`) + // ) + // } ]; /** diff --git a/packages-exp/auth-exp/src/api/account_management/mfa.ts b/packages-exp/auth-exp/src/api/account_management/mfa.ts index 7b9223f52eb..f2e8e2008cb 100644 --- a/packages-exp/auth-exp/src/api/account_management/mfa.ts +++ b/packages-exp/auth-exp/src/api/account_management/mfa.ts @@ -18,7 +18,7 @@ import { Endpoint, HttpMethod, _performApiRequest } from '../index'; import { SignInWithPhoneNumberRequest } from '../authentication/sms'; import { FinalizeMfaResponse } from '../authentication/mfa'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; /** * MFA Info as returned by the API @@ -57,7 +57,7 @@ export interface StartPhoneMfaEnrollmentResponse { } export function startEnrollPhoneMfa( - auth: Auth, + auth: AuthInternal, request: Omit ): Promise { return _performApiRequest< @@ -80,7 +80,7 @@ export interface FinalizePhoneMfaEnrollmentResponse extends FinalizeMfaResponse {} export function finalizeEnrollPhoneMfa( - auth: Auth, + auth: AuthInternal, request: Omit ): Promise { return _performApiRequest< @@ -101,7 +101,7 @@ export interface WithdrawMfaRequest { export interface WithdrawMfaResponse extends FinalizeMfaResponse {} export function withdrawMfa( - auth: Auth, + auth: AuthInternal, request: Omit ): Promise { return _performApiRequest( diff --git a/packages-exp/auth-exp/src/api/index.ts b/packages-exp/auth-exp/src/api/index.ts index 6c8c15eea50..5c3d8284d7f 100644 --- a/packages-exp/auth-exp/src/api/index.ts +++ b/packages-exp/auth-exp/src/api/index.ts @@ -23,7 +23,7 @@ import { Delay } from '../core/util/delay'; import { _emulatorUrl } from '../core/util/emulator'; import { FetchProvider } from '../core/util/fetch_provider'; import { Auth } from '../model/public_types'; -import { Auth as AuthInternal } from '../model/auth'; +import { AuthInternal as AuthInternal } from '../model/auth'; import { IdTokenResponse, TaggedWithTokenResponse } from '../model/id_token'; import { IdTokenMfaResponse } from './authentication/mfa'; import { SERVER_ERROR_MAP, ServerError, ServerErrorMap } from './errors'; diff --git a/packages-exp/auth-exp/src/core/auth/auth_event_manager.ts b/packages-exp/auth-exp/src/core/auth/auth_event_manager.ts index 43b7663b997..1a5347f5308 100644 --- a/packages-exp/auth-exp/src/core/auth/auth_event_manager.ts +++ b/packages-exp/auth-exp/src/core/auth/auth_event_manager.ts @@ -22,7 +22,7 @@ import { EventManager } from '../../model/popup_redirect'; import { AuthErrorCode } from '../errors'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; import { _createError } from '../util/assert'; // The amount of time to store the UIDs of seen events; this is @@ -36,7 +36,7 @@ export class AuthEventManager implements EventManager { protected hasHandledPotentialRedirect = false; private lastProcessedEventTime = Date.now(); - constructor(private readonly auth: Auth) {} + constructor(private readonly auth: AuthInternal) {} registerConsumer(authEventConsumer: AuthEventConsumer): void { this.consumers.add(authEventConsumer); diff --git a/packages-exp/auth-exp/src/core/auth/auth_impl.test.ts b/packages-exp/auth-exp/src/core/auth/auth_impl.test.ts index f202e79033e..db266d0f9f4 100644 --- a/packages-exp/auth-exp/src/core/auth/auth_impl.test.ts +++ b/packages-exp/auth-exp/src/core/auth/auth_impl.test.ts @@ -24,9 +24,9 @@ import { FirebaseApp } from '@firebase/app-exp'; import { FirebaseError } from '@firebase/util'; import { testAuth, testUser } from '../../../test/helpers/mock_auth'; -import { Auth } from '../../model/auth'; -import { User } from '../../model/user'; -import { Persistence } from '../persistence'; +import { AuthInternal } from '../../model/auth'; +import { UserInternal } from '../../model/user'; +import { PersistenceInternal } from '../persistence'; import { inMemoryPersistence } from '../persistence/in_memory'; import { _getInstance } from '../util/instantiator'; import * as navigator from '../util/navigator'; @@ -47,8 +47,8 @@ const FAKE_APP: FirebaseApp = { }; describe('core/auth/auth_impl', () => { - let auth: Auth; - let persistenceStub: sinon.SinonStubbedInstance; + let auth: AuthInternal; + let persistenceStub: sinon.SinonStubbedInstance; beforeEach(async () => { persistenceStub = sinon.stub(_getInstance(inMemoryPersistence)); @@ -203,7 +203,7 @@ describe('core/auth/auth_impl', () => { }); describe('user logs in/out, tokens refresh', () => { - let user: User; + let user: UserInternal; let authStateCallback: sinon.SinonSpy; let idTokenCallback: sinon.SinonSpy; @@ -326,7 +326,7 @@ describe('core/auth/auth_impl', () => { }); context('now logged in', () => { - let user: User; + let user: UserInternal; beforeEach(() => { user = testUser(auth, 'uid'); @@ -344,7 +344,7 @@ describe('core/auth/auth_impl', () => { }); context('previously logged in', () => { - let user: User; + let user: UserInternal; beforeEach(async () => { user = testUser(auth, 'uid', undefined, true); @@ -400,9 +400,9 @@ describe('core/auth/auth_impl', () => { await auth._onStorageEvent(); expect(auth.currentUser?.uid).to.eq(user.uid); - expect((auth.currentUser as User)?.stsTokenManager.accessToken).to.eq( - 'new-access-token' - ); + expect( + (auth.currentUser as UserInternal)?.stsTokenManager.accessToken + ).to.eq('new-access-token'); expect(authStateCallback).not.to.have.been.called; expect(idTokenCallback).to.have.been.called; }); @@ -442,7 +442,7 @@ describe('core/auth/auth_impl', () => { ); await authImpl._delete(); await authImpl._initializeWithPersistence([ - persistenceStub as Persistence + persistenceStub as PersistenceInternal ]); expect(authImpl.currentUser).to.be.null; }); 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 3f85f2177b0..bddb14d1262 100644 --- a/packages-exp/auth-exp/src/core/auth/auth_impl.ts +++ b/packages-exp/auth-exp/src/core/auth/auth_impl.ts @@ -16,7 +16,17 @@ */ import { _FirebaseService, FirebaseApp } from '@firebase/app-exp'; -import * as externs from '../../model/public_types'; +import { + Auth, + AuthErrorMap, + AuthSettings, + EmulatorConfig, + NextOrObserver, + Persistence, + PopupRedirectResolver, + User, + UserCredential +} from '../../model/public_types'; import { CompleteFn, createSubscribe, @@ -28,16 +38,16 @@ import { Unsubscribe } from '@firebase/util'; -import { Auth, ConfigInternal } from '../../model/auth'; -import { PopupRedirectResolver } from '../../model/popup_redirect'; -import { User } from '../../model/user'; +import { AuthInternal, ConfigInternal } from '../../model/auth'; +import { PopupRedirectResolverInternal } from '../../model/popup_redirect'; +import { UserInternal } from '../../model/user'; import { AuthErrorCode, AuthErrorParams, ErrorMapRetriever, _DEFAULT_AUTH_ERROR_FACTORY } from '../errors'; -import { Persistence } from '../persistence'; +import { PersistenceInternal } from '../persistence'; import { KeyName, PersistenceUserManager @@ -57,15 +67,15 @@ export const enum DefaultConfig { API_SCHEME = 'https' } -export class AuthImpl implements Auth, _FirebaseService { - currentUser: externs.User | null = null; - emulatorConfig: externs.EmulatorConfig | null = null; +export class AuthImpl implements AuthInternal, _FirebaseService { + currentUser: User | null = null; + emulatorConfig: EmulatorConfig | null = null; private operations = Promise.resolve(); private persistenceManager?: PersistenceUserManager; private redirectPersistenceManager?: PersistenceUserManager; - private authStateSubscription = new Subscription(this); - private idTokenSubscription = new Subscription(this); - private redirectUser: User | null = null; + private authStateSubscription = new Subscription(this); + private idTokenSubscription = new Subscription(this); + private redirectUser: UserInternal | null = null; private isProactiveRefreshEnabled = false; private redirectInitializerError: Error | null = null; @@ -75,7 +85,7 @@ export class AuthImpl implements Auth, _FirebaseService { _isInitialized = false; _deleted = false; _initializationPromise: Promise | null = null; - _popupRedirectResolver: PopupRedirectResolver | null = null; + _popupRedirectResolver: PopupRedirectResolverInternal | null = null; _errorFactory: ErrorFactory< AuthErrorCode, AuthErrorParams @@ -89,7 +99,7 @@ export class AuthImpl implements Auth, _FirebaseService { languageCode: string | null = null; tenantId: string | null = null; - settings: externs.AuthSettings = { appVerificationDisabledForTesting: false }; + settings: AuthSettings = { appVerificationDisabledForTesting: false }; constructor( public readonly app: FirebaseApp, @@ -99,8 +109,8 @@ export class AuthImpl implements Auth, _FirebaseService { } _initializeWithPersistence( - persistenceHierarchy: Persistence[], - popupRedirectResolver?: externs.PopupRedirectResolver + persistenceHierarchy: PersistenceInternal[], + popupRedirectResolver?: PopupRedirectResolver ): Promise { if (popupRedirectResolver) { this._popupRedirectResolver = _getInstance(popupRedirectResolver); @@ -169,10 +179,10 @@ export class AuthImpl implements Auth, _FirebaseService { } private async initializeCurrentUser( - popupRedirectResolver?: externs.PopupRedirectResolver + popupRedirectResolver?: PopupRedirectResolver ): Promise { // First check to see if we have a pending redirect event. - let storedUser = (await this.assertedPersistence.getCurrentUser()) as User | null; + let storedUser = (await this.assertedPersistence.getCurrentUser()) as UserInternal | null; if (popupRedirectResolver && this.config.authDomain) { await this.getOrInitRedirectPersistenceManager(); const redirectUserEventId = this.redirectUser?._redirectEventId; @@ -187,7 +197,7 @@ export class AuthImpl implements Auth, _FirebaseService { (!redirectUserEventId || redirectUserEventId === storedUserEventId) && result?.user ) { - storedUser = result.user as User; + storedUser = result.user as UserInternal; } } @@ -220,8 +230,8 @@ export class AuthImpl implements Auth, _FirebaseService { } private async tryRedirectSignIn( - redirectResolver: externs.PopupRedirectResolver - ): Promise { + redirectResolver: PopupRedirectResolver + ): Promise { // The redirect user needs to be checked (and signed in if available) // during auth initialization. All of the normal sign in and link/reauth // flows call back into auth and push things onto the promise queue. We @@ -238,7 +248,7 @@ export class AuthImpl implements Auth, _FirebaseService { // _completeRedirectFn) with an optional parameter that instructs all of // the underlying auth operations to skip anything that mutates auth state. - let result: externs.UserCredential | null = null; + let result: UserCredential | null = null; try { // We know this._popupRedirectResolver is set since redirectResolver // is passed in. The _completeRedirectFn expects the unwrapped extern. @@ -255,7 +265,9 @@ export class AuthImpl implements Auth, _FirebaseService { return result; } - private async reloadAndSetCurrentUserOrClear(user: User): Promise { + private async reloadAndSetCurrentUserOrClear( + user: UserInternal + ): Promise { try { await _reloadWithoutSaving(user); } catch (e) { @@ -277,10 +289,10 @@ export class AuthImpl implements Auth, _FirebaseService { this._deleted = true; } - async updateCurrentUser(userExtern: externs.User | null): Promise { + async updateCurrentUser(userExtern: User | null): Promise { // The public updateCurrentUser method needs to make a copy of the user, // and also needs to verify that the app matches - const user = userExtern as User | null; + const user = userExtern as UserInternal | null; _assert( !user || user.auth.name === this.name, this, @@ -290,7 +302,7 @@ export class AuthImpl implements Auth, _FirebaseService { return this._updateCurrentUser(user && user._clone()); } - async _updateCurrentUser(user: externs.User | null): Promise { + async _updateCurrentUser(user: User | null): Promise { if (this._deleted) { return; } @@ -303,7 +315,7 @@ export class AuthImpl implements Auth, _FirebaseService { } return this.queue(async () => { - await this.directlySetCurrentUser(user as User | null); + await this.directlySetCurrentUser(user as UserInternal | null); this.notifyAuthListeners(); }); } @@ -317,7 +329,7 @@ export class AuthImpl implements Auth, _FirebaseService { return this._updateCurrentUser(null); } - setPersistence(persistence: externs.Persistence): Promise { + setPersistence(persistence: Persistence): Promise { return this.queue(async () => { await this.assertedPersistence.setPersistence(_getInstance(persistence)); }); @@ -327,7 +339,7 @@ export class AuthImpl implements Auth, _FirebaseService { return this.assertedPersistence.persistence.type; } - _updateErrorMap(errorMap: externs.AuthErrorMap): void { + _updateErrorMap(errorMap: AuthErrorMap): void { this._errorFactory = new ErrorFactory( 'auth', 'Firebase', @@ -336,7 +348,7 @@ export class AuthImpl implements Auth, _FirebaseService { } onAuthStateChanged( - nextOrObserver: externs.NextOrObserver, + nextOrObserver: NextOrObserver, error?: ErrorFn, completed?: CompleteFn ): Unsubscribe { @@ -349,7 +361,7 @@ export class AuthImpl implements Auth, _FirebaseService { } onIdTokenChanged( - nextOrObserver: externs.NextOrObserver, + nextOrObserver: NextOrObserver, error?: ErrorFn, completed?: CompleteFn ): Unsubscribe { @@ -371,8 +383,8 @@ export class AuthImpl implements Auth, _FirebaseService { } async _setRedirectUser( - user: User | null, - popupRedirectResolver?: externs.PopupRedirectResolver + user: UserInternal | null, + popupRedirectResolver?: PopupRedirectResolver ): Promise { const redirectManager = await this.getOrInitRedirectPersistenceManager( popupRedirectResolver @@ -383,10 +395,10 @@ export class AuthImpl implements Auth, _FirebaseService { } private async getOrInitRedirectPersistenceManager( - popupRedirectResolver?: externs.PopupRedirectResolver + popupRedirectResolver?: PopupRedirectResolver ): Promise { if (!this.redirectPersistenceManager) { - const resolver: PopupRedirectResolver | null = + const resolver: PopupRedirectResolverInternal | null = (popupRedirectResolver && _getInstance(popupRedirectResolver)) || this._popupRedirectResolver; _assert(resolver, this, AuthErrorCode.ARGUMENT_ERROR); @@ -401,7 +413,7 @@ export class AuthImpl implements Auth, _FirebaseService { return this.redirectPersistenceManager; } - async _redirectUserForId(id: string): Promise { + async _redirectUserForId(id: string): Promise { // Make sure we've cleared any pending persistence actions if we're not in // the initializer if (this._isInitialized) { @@ -419,14 +431,14 @@ export class AuthImpl implements Auth, _FirebaseService { return null; } - async _persistUserIfCurrent(user: User): Promise { + async _persistUserIfCurrent(user: UserInternal): Promise { if (user === this.currentUser) { return this.queue(async () => this.directlySetCurrentUser(user)); } } /** Notifies listeners only if the user is current */ - _notifyListenersIfCurrent(user: User): void { + _notifyListenersIfCurrent(user: UserInternal): void { if (user === this.currentUser) { this.notifyAuthListeners(); } @@ -451,8 +463,8 @@ export class AuthImpl implements Auth, _FirebaseService { } /** Returns the current user cast as the internal type */ - get _currentUser(): User { - return this.currentUser as User; + get _currentUser(): UserInternal { + return this.currentUser as UserInternal; } private notifyAuthListeners(): void { @@ -470,8 +482,8 @@ export class AuthImpl implements Auth, _FirebaseService { } private registerStateListener( - subscription: Subscription, - nextOrObserver: externs.NextOrObserver, + subscription: Subscription, + nextOrObserver: NextOrObserver, error?: ErrorFn, completed?: CompleteFn ): Unsubscribe { @@ -504,7 +516,9 @@ export class AuthImpl implements Auth, _FirebaseService { * should only be called from within a queued callback. This is necessary * because the queue shouldn't rely on another queued callback. */ - private async directlySetCurrentUser(user: User | null): Promise { + private async directlySetCurrentUser( + user: UserInternal | null + ): Promise { if (this.currentUser && this.currentUser !== user) { this._currentUser._stopProactiveRefresh(); if (user && this.isProactiveRefreshEnabled) { @@ -539,8 +553,8 @@ export class AuthImpl implements Auth, _FirebaseService { * * @param auth Auth object passed in from developer */ -export function _castAuth(auth: externs.Auth): Auth { - return (auth as unknown) as Auth; +export function _castAuth(auth: Auth): AuthInternal { + return (auth as unknown) as AuthInternal; } /** Helper class to wrap subscriber logic */ @@ -550,7 +564,7 @@ class Subscription { observer => (this.observer = observer) ); - constructor(readonly auth: Auth) {} + constructor(readonly auth: AuthInternal) {} get next(): NextFn { _assert(this.observer, this.auth, AuthErrorCode.INTERNAL_ERROR); diff --git a/packages-exp/auth-exp/src/core/auth/emulator.test.ts b/packages-exp/auth-exp/src/core/auth/emulator.test.ts index 6ce6b7d2522..933123afa75 100644 --- a/packages-exp/auth-exp/src/core/auth/emulator.test.ts +++ b/packages-exp/auth-exp/src/core/auth/emulator.test.ts @@ -26,7 +26,7 @@ import { endpointUrl, mockEndpoint } from '../../../test/helpers/api/helper'; import { testAuth, TestAuth, testUser } from '../../../test/helpers/mock_auth'; import * as fetch from '../../../test/helpers/mock_fetch'; import { Endpoint } from '../../api'; -import { User } from '../../model/user'; +import { UserInternal } from '../../model/user'; import { _castAuth } from './auth_impl'; import { useAuthEmulator } from './emulator'; @@ -35,7 +35,7 @@ use(chaiAsPromised); describe('core/auth/emulator', () => { let auth: TestAuth; - let user: User; + let user: UserInternal; let normalEndpoint: fetch.Route; let emulatorEndpoint: fetch.Route; @@ -183,7 +183,7 @@ describe('core/auth/emulator', () => { it('also stringifies the current user', () => { auth.currentUser = ({ toJSON: (): object => ({ foo: 'bar' }) - } as unknown) as User; + } as unknown) as UserInternal; expect(JSON.stringify(auth)).to.eq( '{"apiKey":"test-api-key","authDomain":"localhost",' + '"appName":"test-app","currentUser":{"foo":"bar"}}' diff --git a/packages-exp/auth-exp/src/core/auth/emulator.ts b/packages-exp/auth-exp/src/core/auth/emulator.ts index 70613d10624..85d24fbfd28 100644 --- a/packages-exp/auth-exp/src/core/auth/emulator.ts +++ b/packages-exp/auth-exp/src/core/auth/emulator.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { Auth } from '../../model/public_types'; import { AuthErrorCode } from '../errors'; import { _assert } from '../util/assert'; import { _castAuth } from './auth_impl'; @@ -41,7 +41,7 @@ import { _castAuth } from './auth_impl'; * @public */ export function useAuthEmulator( - auth: externs.Auth, + auth: Auth, url: string, options?: { disableWarnings: boolean } ): void { diff --git a/packages-exp/auth-exp/src/core/auth/firebase_internal.test.ts b/packages-exp/auth-exp/src/core/auth/firebase_internal.test.ts index 80e1b0fab65..87ed66e3ac8 100644 --- a/packages-exp/auth-exp/src/core/auth/firebase_internal.test.ts +++ b/packages-exp/auth-exp/src/core/auth/firebase_internal.test.ts @@ -21,14 +21,14 @@ import * as sinon from 'sinon'; import * as chaiAsPromised from 'chai-as-promised'; import { testAuth, testUser } from '../../../test/helpers/mock_auth'; -import { Auth } from '../../model/auth'; -import { User } from '../../model/user'; -import { AuthInternal } from './firebase_internal'; +import { AuthInternal } from '../../model/auth'; +import { UserInternal } from '../../model/user'; +import { AuthInterop } from './firebase_internal'; use(chaiAsPromised); describe('core/auth/firebase_internal', () => { - let auth: Auth; + let auth: AuthInternal; let authInternal: AuthInternal; beforeEach(async () => { auth = await testAuth(); @@ -90,7 +90,7 @@ describe('core/auth/firebase_internal', () => { context('token listeners', () => { let isProactiveRefresh = false; - let user: User; + let user: UserInternal; beforeEach(async () => { user = testUser(auth, 'uid', undefined, true); diff --git a/packages-exp/auth-exp/src/core/auth/firebase_internal.ts b/packages-exp/auth-exp/src/core/auth/firebase_internal.ts index f2096d0d0e6..fcde523050c 100644 --- a/packages-exp/auth-exp/src/core/auth/firebase_internal.ts +++ b/packages-exp/auth-exp/src/core/auth/firebase_internal.ts @@ -18,8 +18,8 @@ import { Unsubscribe } from '@firebase/util'; import { FirebaseAuthInternal } from '@firebase/auth-interop-types'; -import { Auth } from '../../model/auth'; -import { User } from '../../model/user'; +import { AuthInternal } from '../../model/auth'; +import { UserInternal } from '../../model/user'; import { _assert } from '../util/assert'; import { AuthErrorCode } from '../errors'; @@ -27,13 +27,13 @@ interface TokenListener { (tok: string | null): unknown; } -export class AuthInternal implements FirebaseAuthInternal { +export class AuthInterop implements FirebaseAuthInternal { private readonly internalListeners: Map< TokenListener, Unsubscribe > = new Map(); - constructor(private readonly auth: Auth) {} + constructor(private readonly auth: AuthInternal) {} getUid(): string | null { this.assertAuthConfigured(); @@ -60,7 +60,9 @@ export class AuthInternal implements FirebaseAuthInternal { } const unsubscribe = this.auth.onIdTokenChanged(user => { - listener((user as User | null)?.stsTokenManager.accessToken || null); + listener( + (user as UserInternal | null)?.stsTokenManager.accessToken || null + ); }); this.internalListeners.set(listener, unsubscribe); this.updateProactiveRefresh(); diff --git a/packages-exp/auth-exp/src/core/auth/initialize.test.ts b/packages-exp/auth-exp/src/core/auth/initialize.test.ts index ed2dead37d0..1bc859c7c03 100644 --- a/packages-exp/auth-exp/src/core/auth/initialize.test.ts +++ b/packages-exp/auth-exp/src/core/auth/initialize.test.ts @@ -21,22 +21,28 @@ import { FirebaseApp, _FirebaseService } from '@firebase/app-exp'; -import * as externs from '../../model/public_types'; +import { + Auth, + AuthProvider, + Persistence as PersistencePublic, + PopupRedirectResolver, + UserCredential +} from '../../model/public_types'; import { isNode } from '@firebase/util'; import { expect } from 'chai'; import { inMemoryPersistence } from '../../../internal'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; import { - PopupRedirectResolver, + PopupRedirectResolverInternal, AuthEventType, EventManager, AuthEventConsumer } from '../../model/popup_redirect'; import { AuthPopup } from '../../platform_browser/util/popup'; import { - Persistence, + PersistenceInternal, PersistenceType, PersistenceValue, StorageEventListener @@ -48,7 +54,7 @@ import { registerAuth } from './register'; describe('core/auth/initialize', () => { let fakeApp: FirebaseApp; - class FakeSessionPersistence implements Persistence { + class FakeSessionPersistence implements PersistenceInternal { static type: 'SESSION' = 'SESSION'; readonly type = PersistenceType.SESSION; storage: Record = {}; @@ -73,12 +79,12 @@ describe('core/auth/initialize', () => { } } - const fakeSessionPersistence: externs.Persistence = FakeSessionPersistence; + const fakeSessionPersistence: PersistencePublic = FakeSessionPersistence; - class FakePopupRedirectResolver implements PopupRedirectResolver { + class FakePopupRedirectResolver implements PopupRedirectResolverInternal { readonly _redirectPersistence = fakeSessionPersistence; - async _initialize(_auth: Auth): Promise { + async _initialize(_auth: AuthInternal): Promise { return new (class implements EventManager { registerConsumer(_authEventConsumer: AuthEventConsumer): void { return; @@ -89,37 +95,37 @@ describe('core/auth/initialize', () => { })(); } async _openPopup( - _auth: Auth, - _provider: externs.AuthProvider, + _auth: AuthInternal, + _provider: AuthProvider, _authType: AuthEventType, _eventId?: string ): Promise { return new AuthPopup(null); } _openRedirect( - _auth: Auth, - _provider: externs.AuthProvider, + _auth: AuthInternal, + _provider: AuthProvider, _authType: AuthEventType, _eventId?: string ): Promise { return new Promise((_, reject) => reject()); } _isIframeWebStorageSupported( - _auth: Auth, + _auth: AuthInternal, cb: (support: boolean) => unknown ): void { cb(true); } async _completeRedirectFn( - _auth: externs.Auth, - _resolver: externs.PopupRedirectResolver, + _auth: Auth, + _resolver: PopupRedirectResolver, _bypassAuthState: boolean - ): Promise { + ): Promise { return null; } } - const fakePopupRedirectResolver: externs.PopupRedirectResolver = FakePopupRedirectResolver; + const fakePopupRedirectResolver: PopupRedirectResolver = FakePopupRedirectResolver; before(() => { registerAuth(ClientPlatform.BROWSER); @@ -139,7 +145,7 @@ describe('core/auth/initialize', () => { describe('initializeAuth', () => { it('should work with no deps', async () => { - const auth = initializeAuth(fakeApp) as Auth; + const auth = initializeAuth(fakeApp) as AuthInternal; await auth._initializationPromise; expect(auth.name).to.eq(fakeApp.name); @@ -161,7 +167,7 @@ describe('core/auth/initialize', () => { it('should set persistence', async () => { const auth = initializeAuth(fakeApp, { persistence: fakeSessionPersistence - }) as Auth; + }) as AuthInternal; await auth._initializationPromise; expect(auth._getPersistence()).to.eq('SESSION'); @@ -170,7 +176,7 @@ describe('core/auth/initialize', () => { it('should set persistence with fallback', async () => { const auth = initializeAuth(fakeApp, { persistence: [fakeSessionPersistence, inMemoryPersistence] - }) as Auth; + }) as AuthInternal; await auth._initializationPromise; expect(auth._getPersistence()).to.eq('SESSION'); @@ -179,7 +185,7 @@ describe('core/auth/initialize', () => { it('should set resolver', async () => { const auth = initializeAuth(fakeApp, { popupRedirectResolver: fakePopupRedirectResolver - }) as Auth; + }) as AuthInternal; await auth._initializationPromise; expect(auth._popupRedirectResolver).to.be.instanceof( @@ -190,7 +196,7 @@ describe('core/auth/initialize', () => { it('should abort initialization if deleted synchronously', async () => { const auth = initializeAuth(fakeApp, { popupRedirectResolver: fakePopupRedirectResolver - }) as Auth; + }) as AuthInternal; await ((auth as unknown) as _FirebaseService)._delete(); await auth._initializationPromise; diff --git a/packages-exp/auth-exp/src/core/auth/initialize.ts b/packages-exp/auth-exp/src/core/auth/initialize.ts index 232ae3c99f8..cfb3d0fe655 100644 --- a/packages-exp/auth-exp/src/core/auth/initialize.ts +++ b/packages-exp/auth-exp/src/core/auth/initialize.ts @@ -16,20 +16,17 @@ */ import { _getProvider, FirebaseApp } from '@firebase/app-exp'; -import * as externs from '../../model/public_types'; +import { Auth } from '../../model/public_types'; import { Dependencies } from '../../model/auth'; import { AuthErrorCode } from '../errors'; -import { Persistence } from '../persistence'; +import { PersistenceInternal } from '../persistence'; import { _fail } from '../util/assert'; import { _getInstance } from '../util/instantiator'; import { AuthImpl } from './auth_impl'; /** @public */ -export function initializeAuth( - app: FirebaseApp, - deps?: Dependencies -): externs.Auth { +export function initializeAuth(app: FirebaseApp, deps?: Dependencies): Auth { const provider = _getProvider(app, 'auth-exp'); if (provider.isInitialized()) { @@ -51,7 +48,7 @@ export function _initializeAuthInstance( const hierarchy = (Array.isArray(persistence) ? persistence : [persistence] - ).map(_getInstance); + ).map(_getInstance); if (deps?.errorMap) { auth._updateErrorMap(deps.errorMap); } diff --git a/packages-exp/auth-exp/src/core/auth/register.ts b/packages-exp/auth-exp/src/core/auth/register.ts index e0657c2ab73..7baa42428b1 100644 --- a/packages-exp/auth-exp/src/core/auth/register.ts +++ b/packages-exp/auth-exp/src/core/auth/register.ts @@ -16,7 +16,7 @@ */ import { _registerComponent, registerVersion } from '@firebase/app-exp'; -import * as externs from '../../model/public_types'; +import { Config } from '../../model/public_types'; import { Component, ComponentType } from '@firebase/component'; import { version } from '../../../package.json'; @@ -24,7 +24,7 @@ import { AuthErrorCode } from '../errors'; import { _assert } from '../util/assert'; import { _getClientVersion, ClientPlatform } from '../util/version'; import { _castAuth, AuthImpl, DefaultConfig } from './auth_impl'; -import { AuthInternal } from './firebase_internal'; +import { AuthInterop } from './firebase_internal'; export const enum _ComponentName { AUTH = 'auth-exp', @@ -58,7 +58,7 @@ export function registerAuth(clientPlatform: ClientPlatform): void { const { apiKey, authDomain } = app.options; return (app => { _assert(apiKey, AuthErrorCode.INVALID_API_KEY, { appName: app.name }); - const config: externs.Config = { + const config: Config = { apiKey, authDomain, apiHost: DefaultConfig.API_HOST, @@ -80,7 +80,7 @@ export function registerAuth(clientPlatform: ClientPlatform): void { const auth = _castAuth( container.getProvider(_ComponentName.AUTH).getImmediate()! ); - return (auth => new AuthInternal(auth))(auth); + return (auth => new AuthInterop(auth))(auth); }, ComponentType.PRIVATE ) diff --git a/packages-exp/auth-exp/src/core/credentials/auth_credential.ts b/packages-exp/auth-exp/src/core/credentials/auth_credential.ts index 0ca02c1dda5..f5f47a117a0 100644 --- a/packages-exp/auth-exp/src/core/credentials/auth_credential.ts +++ b/packages-exp/auth-exp/src/core/credentials/auth_credential.ts @@ -16,7 +16,7 @@ */ import { PhoneOrOauthTokenResponse } from '../../api/authentication/mfa'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; import { IdTokenResponse } from '../../model/id_token'; import { debugFail } from '../util/assert'; @@ -38,15 +38,18 @@ export class AuthCredential { } /** @internal */ - _getIdTokenResponse(_auth: Auth): Promise { + _getIdTokenResponse(_auth: AuthInternal): Promise { return debugFail('not implemented'); } /** @internal */ - _linkToIdToken(_auth: Auth, _idToken: string): Promise { + _linkToIdToken( + _auth: AuthInternal, + _idToken: string + ): Promise { return debugFail('not implemented'); } /** @internal */ - _getReauthenticationResolver(_auth: Auth): Promise { + _getReauthenticationResolver(_auth: AuthInternal): Promise { return debugFail('not implemented'); } } diff --git a/packages-exp/auth-exp/src/core/credentials/email.ts b/packages-exp/auth-exp/src/core/credentials/email.ts index 9a2c101f7a4..2bd8d37c47e 100644 --- a/packages-exp/auth-exp/src/core/credentials/email.ts +++ b/packages-exp/auth-exp/src/core/credentials/email.ts @@ -15,7 +15,11 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { + AuthCredential as AuthCredentialPublic, + ProviderId, + SignInMethod +} from '../../model/public_types'; import { updateEmailPassword } from '../../api/account_management/email_and_password'; import { signInWithPassword } from '../../api/authentication/email_and_password'; @@ -23,7 +27,7 @@ import { signInWithEmailLink, signInWithEmailLinkForLinking } from '../../api/authentication/email_link'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; import { IdTokenResponse } from '../../model/id_token'; import { AuthErrorCode } from '../errors'; import { _fail } from '../util/assert'; @@ -41,15 +45,15 @@ import { AuthCredential } from './auth_credential'; */ export class EmailAuthCredential extends AuthCredential - implements externs.AuthCredential { + implements AuthCredentialPublic { /** @internal */ private constructor( readonly email: string, readonly password: string, - signInMethod: externs.SignInMethod, + signInMethod: SignInMethod, readonly tenantId: string | null = null ) { - super(externs.ProviderId.PASSWORD, signInMethod); + super(ProviderId.PASSWORD, signInMethod); } /** @internal */ @@ -60,7 +64,7 @@ export class EmailAuthCredential return new EmailAuthCredential( email, password, - externs.SignInMethod.EMAIL_PASSWORD + SignInMethod.EMAIL_PASSWORD ); } @@ -73,7 +77,7 @@ export class EmailAuthCredential return new EmailAuthCredential( email, oobCode, - externs.SignInMethod.EMAIL_LINK, + SignInMethod.EMAIL_LINK, tenantId ); } @@ -92,9 +96,9 @@ export class EmailAuthCredential static fromJSON(json: object | string): EmailAuthCredential | null { const obj = typeof json === 'string' ? JSON.parse(json) : json; if (obj?.email && obj?.password) { - if (obj.signInMethod === externs.SignInMethod.EMAIL_PASSWORD) { + if (obj.signInMethod === SignInMethod.EMAIL_PASSWORD) { return this._fromEmailAndPassword(obj.email, obj.password); - } else if (obj.signInMethod === externs.SignInMethod.EMAIL_LINK) { + } else if (obj.signInMethod === SignInMethod.EMAIL_LINK) { return this._fromEmailAndCode(obj.email, obj.password, obj.tenantId); } } @@ -102,15 +106,15 @@ export class EmailAuthCredential } /** @internal */ - async _getIdTokenResponse(auth: Auth): Promise { + async _getIdTokenResponse(auth: AuthInternal): Promise { switch (this.signInMethod) { - case externs.SignInMethod.EMAIL_PASSWORD: + case SignInMethod.EMAIL_PASSWORD: return signInWithPassword(auth, { returnSecureToken: true, email: this.email, password: this.password }); - case externs.SignInMethod.EMAIL_LINK: + case SignInMethod.EMAIL_LINK: return signInWithEmailLink(auth, { email: this.email, oobCode: this.password @@ -121,16 +125,19 @@ export class EmailAuthCredential } /** @internal */ - async _linkToIdToken(auth: Auth, idToken: string): Promise { + async _linkToIdToken( + auth: AuthInternal, + idToken: string + ): Promise { switch (this.signInMethod) { - case externs.SignInMethod.EMAIL_PASSWORD: + case SignInMethod.EMAIL_PASSWORD: return updateEmailPassword(auth, { idToken, returnSecureToken: true, email: this.email, password: this.password }); - case externs.SignInMethod.EMAIL_LINK: + case SignInMethod.EMAIL_LINK: return signInWithEmailLinkForLinking(auth, { idToken, email: this.email, @@ -142,7 +149,7 @@ export class EmailAuthCredential } /** @internal */ - _getReauthenticationResolver(auth: Auth): Promise { + _getReauthenticationResolver(auth: AuthInternal): Promise { return this._getIdTokenResponse(auth); } } diff --git a/packages-exp/auth-exp/src/core/credentials/index.ts b/packages-exp/auth-exp/src/core/credentials/index.ts index a3ec8ce895f..44988c34deb 100644 --- a/packages-exp/auth-exp/src/core/credentials/index.ts +++ b/packages-exp/auth-exp/src/core/credentials/index.ts @@ -21,4 +21,4 @@ export { AuthCredential } from './auth_credential'; export { EmailAuthCredential } from './email'; export { OAuthCredential } from './oauth'; -export { PhoneAuthCredential } from './phone'; +export { PhoneAuthCredentialImpl as PhoneAuthCredential } from './phone'; diff --git a/packages-exp/auth-exp/src/core/credentials/oauth.ts b/packages-exp/auth-exp/src/core/credentials/oauth.ts index e484c6358f8..de20ad7309a 100644 --- a/packages-exp/auth-exp/src/core/credentials/oauth.ts +++ b/packages-exp/auth-exp/src/core/credentials/oauth.ts @@ -15,14 +15,14 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { OAuthCredential as OAuthCredentialPublic } from '../../model/public_types'; import { querystring } from '@firebase/util'; import { signInWithIdp, SignInWithIdpRequest } from '../../api/authentication/idp'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; import { IdTokenResponse } from '../../model/id_token'; import { AuthErrorCode } from '../errors'; import { _fail } from '../util/assert'; @@ -56,7 +56,7 @@ export interface OAuthCredentialParams { */ export class OAuthCredential extends AuthCredential - implements externs.OAuthCredential { + implements OAuthCredentialPublic { /** {@inheritdoc @firebase/auth-types#OAuthCredential.idToken} @readonly */ idToken?: string; /** {@inheritdoc @firebase/auth-types#OAuthCredential.accessToken} @readonly */ @@ -127,20 +127,23 @@ export class OAuthCredential } /** @internal */ - _getIdTokenResponse(auth: Auth): Promise { + _getIdTokenResponse(auth: AuthInternal): Promise { const request = this.buildRequest(); return signInWithIdp(auth, request); } /** @internal */ - _linkToIdToken(auth: Auth, idToken: string): Promise { + _linkToIdToken( + auth: AuthInternal, + idToken: string + ): Promise { const request = this.buildRequest(); request.idToken = idToken; return signInWithIdp(auth, request); } /** @internal */ - _getReauthenticationResolver(auth: Auth): Promise { + _getReauthenticationResolver(auth: AuthInternal): Promise { const request = this.buildRequest(); request.autoCreate = false; return signInWithIdp(auth, request); diff --git a/packages-exp/auth-exp/src/core/credentials/phone.test.ts b/packages-exp/auth-exp/src/core/credentials/phone.test.ts index 1dedb5a8cff..e450f431d08 100644 --- a/packages-exp/auth-exp/src/core/credentials/phone.test.ts +++ b/packages-exp/auth-exp/src/core/credentials/phone.test.ts @@ -22,7 +22,7 @@ import { testAuth, TestAuth } from '../../../test/helpers/mock_auth'; import * as fetch from '../../../test/helpers/mock_fetch'; import { Endpoint } from '../../api'; import { IdTokenResponse, IdTokenResponseKind } from '../../model/id_token'; -import { PhoneAuthCredential } from '../credentials/phone'; +import { PhoneAuthCredentialImpl } from '../credentials/phone'; describe('core/credentials/phone', () => { let auth: TestAuth; @@ -46,7 +46,7 @@ describe('core/credentials/phone', () => { }; it('calls the endpoint with session and code', async () => { - const cred = PhoneAuthCredential._fromVerification( + const cred = PhoneAuthCredentialImpl._fromVerification( 'session-info', 'code' ); @@ -61,7 +61,7 @@ describe('core/credentials/phone', () => { }); it('calls the endpoint with proof and number', async () => { - const cred = PhoneAuthCredential._fromTokenResponse( + const cred = PhoneAuthCredentialImpl._fromTokenResponse( 'number', 'temp-proof' ); @@ -86,7 +86,7 @@ describe('core/credentials/phone', () => { }; it('calls the endpoint with session and code', async () => { - const cred = PhoneAuthCredential._fromVerification( + const cred = PhoneAuthCredentialImpl._fromVerification( 'session-info', 'code' ); @@ -102,7 +102,7 @@ describe('core/credentials/phone', () => { }); it('calls the endpoint with proof and number', async () => { - const cred = PhoneAuthCredential._fromTokenResponse( + const cred = PhoneAuthCredentialImpl._fromTokenResponse( 'number', 'temp-proof' ); @@ -120,7 +120,7 @@ describe('core/credentials/phone', () => { context('#toJSON', () => { it('fills out the object with everything that is set', () => { - const cred = PhoneAuthCredential._fromVerification('id', 'code'); + const cred = PhoneAuthCredentialImpl._fromVerification('id', 'code'); expect(cred.toJSON()).to.eql({ providerId: 'phone', @@ -130,7 +130,10 @@ describe('core/credentials/phone', () => { }); it('omits missing fields', () => { - const cred = PhoneAuthCredential._fromTokenResponse('number', 'proof'); + const cred = PhoneAuthCredentialImpl._fromTokenResponse( + 'number', + 'proof' + ); expect(cred.toJSON()).to.eql({ providerId: 'phone', @@ -142,7 +145,9 @@ describe('core/credentials/phone', () => { context('.fromJSON', () => { it('works if passed a string', () => { - const cred = PhoneAuthCredential.fromJSON('{"phoneNumber": "number"}'); + const cred = PhoneAuthCredentialImpl.fromJSON( + '{"phoneNumber": "number"}' + ); expect(cred?.toJSON()).to.eql({ providerId: 'phone', phoneNumber: 'number' @@ -150,7 +155,7 @@ describe('core/credentials/phone', () => { }); it('works if passed an object', () => { - const cred = PhoneAuthCredential.fromJSON({ + const cred = PhoneAuthCredentialImpl.fromJSON({ temporaryProof: 'proof', phoneNumber: 'number', verificationId: 'id', @@ -166,7 +171,7 @@ describe('core/credentials/phone', () => { }); it('returns null if object contains no matching fields', () => { - expect(PhoneAuthCredential.fromJSON({})).to.be.null; + expect(PhoneAuthCredentialImpl.fromJSON({})).to.be.null; }); }); }); diff --git a/packages-exp/auth-exp/src/core/credentials/phone.ts b/packages-exp/auth-exp/src/core/credentials/phone.ts index cc803917224..c0d0cff24d1 100644 --- a/packages-exp/auth-exp/src/core/credentials/phone.ts +++ b/packages-exp/auth-exp/src/core/credentials/phone.ts @@ -15,7 +15,11 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { + PhoneAuthCredential, + ProviderId, + SignInMethod +} from '../../model/public_types'; import { PhoneOrOauthTokenResponse } from '../../api/authentication/mfa'; import { @@ -24,7 +28,7 @@ import { SignInWithPhoneNumberRequest, verifyPhoneNumberForExisting } from '../../api/authentication/sms'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; import { IdTokenResponse } from '../../model/id_token'; import { AuthCredential } from './auth_credential'; @@ -40,36 +44,39 @@ export interface PhoneAuthCredentialParameters { * * @public */ -export class PhoneAuthCredential +export class PhoneAuthCredentialImpl extends AuthCredential - implements externs.PhoneAuthCredential { + implements PhoneAuthCredential { private constructor(private readonly params: PhoneAuthCredentialParameters) { - super(externs.ProviderId.PHONE, externs.SignInMethod.PHONE); + super(ProviderId.PHONE, SignInMethod.PHONE); } /** @internal */ static _fromVerification( verificationId: string, verificationCode: string - ): PhoneAuthCredential { - return new PhoneAuthCredential({ verificationId, verificationCode }); + ): PhoneAuthCredentialImpl { + return new PhoneAuthCredentialImpl({ verificationId, verificationCode }); } /** @internal */ static _fromTokenResponse( phoneNumber: string, temporaryProof: string - ): PhoneAuthCredential { - return new PhoneAuthCredential({ phoneNumber, temporaryProof }); + ): PhoneAuthCredentialImpl { + return new PhoneAuthCredentialImpl({ phoneNumber, temporaryProof }); } /** @internal */ - _getIdTokenResponse(auth: Auth): Promise { + _getIdTokenResponse(auth: AuthInternal): Promise { return signInWithPhoneNumber(auth, this._makeVerificationRequest()); } /** @internal */ - _linkToIdToken(auth: Auth, idToken: string): Promise { + _linkToIdToken( + auth: AuthInternal, + idToken: string + ): Promise { return linkWithPhoneNumber(auth, { idToken, ...this._makeVerificationRequest() @@ -77,7 +84,7 @@ export class PhoneAuthCredential } /** @internal */ - _getReauthenticationResolver(auth: Auth): Promise { + _getReauthenticationResolver(auth: AuthInternal): Promise { return verifyPhoneNumberForExisting(auth, this._makeVerificationRequest()); } @@ -121,7 +128,7 @@ export class PhoneAuthCredential } /** {@inheritdoc @firebase/auth-types#fromJSON} */ - static fromJSON(json: object | string): PhoneAuthCredential | null { + static fromJSON(json: object | string): PhoneAuthCredentialImpl | null { if (typeof json === 'string') { json = JSON.parse(json); } @@ -141,7 +148,7 @@ export class PhoneAuthCredential return null; } - return new PhoneAuthCredential({ + return new PhoneAuthCredentialImpl({ verificationId, verificationCode, phoneNumber, diff --git a/packages-exp/auth-exp/src/core/errors.ts b/packages-exp/auth-exp/src/core/errors.ts index 3e4577f7378..d41f2e0cde6 100644 --- a/packages-exp/auth-exp/src/core/errors.ts +++ b/packages-exp/auth-exp/src/core/errors.ts @@ -16,7 +16,7 @@ */ // eslint-disable-next-line import/no-extraneous-dependencies -import * as externs from '../model/public_types'; +import { AuthCredential, AuthErrorMap, User } from '../model/public_types'; import { ErrorFactory, ErrorMap } from '@firebase/util'; import { IdTokenMfaResponse } from '../api/authentication/mfa'; @@ -354,7 +354,7 @@ function _debugErrorMap(): ErrorMap { }; } -export interface ErrorMapRetriever extends externs.AuthErrorMap { +export interface ErrorMapRetriever extends AuthErrorMap { (): ErrorMap; } @@ -377,7 +377,7 @@ function _prodErrorMap(): ErrorMap { * * @public */ -export const debugErrorMap: externs.AuthErrorMap = _debugErrorMap; +export const debugErrorMap: AuthErrorMap = _debugErrorMap; /** * A minimal error map with all verbose error messages stripped. @@ -386,15 +386,15 @@ export const debugErrorMap: externs.AuthErrorMap = _debugErrorMap; * * @public */ -export const prodErrorMap: externs.AuthErrorMap = _prodErrorMap; +export const prodErrorMap: AuthErrorMap = _prodErrorMap; export interface NamedErrorParams { appName: AppName; - credential?: externs.AuthCredential; + credential?: AuthCredential; email?: string; phoneNumber?: string; tenantId?: string; - user?: externs.User; + user?: User; serverResponse?: object; } diff --git a/packages-exp/auth-exp/src/core/index.ts b/packages-exp/auth-exp/src/core/index.ts index 955ea0066f2..a0422cf2bd2 100644 --- a/packages-exp/auth-exp/src/core/index.ts +++ b/packages-exp/auth-exp/src/core/index.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '../model/public_types'; +import { Auth, NextOrObserver, Persistence, User } from '../model/public_types'; import { CompleteFn, ErrorFn, Unsubscribe } from '@firebase/util'; export { debugErrorMap, prodErrorMap } from './errors'; @@ -43,8 +43,8 @@ export { debugErrorMap, prodErrorMap } from './errors'; * @public */ export function setPersistence( - auth: externs.Auth, - persistence: externs.Persistence + auth: Auth, + persistence: Persistence ): Promise { return auth.setPersistence(persistence); } @@ -60,8 +60,8 @@ export function setPersistence( * @public */ export function onIdTokenChanged( - auth: externs.Auth, - nextOrObserver: externs.NextOrObserver, + auth: Auth, + nextOrObserver: NextOrObserver, error?: ErrorFn, completed?: CompleteFn ): Unsubscribe { @@ -81,8 +81,8 @@ export function onIdTokenChanged( * @public */ export function onAuthStateChanged( - auth: externs.Auth, - nextOrObserver: externs.NextOrObserver, + auth: Auth, + nextOrObserver: NextOrObserver, error?: ErrorFn, completed?: CompleteFn ): Unsubscribe { @@ -95,7 +95,7 @@ export function onAuthStateChanged( * * @public */ -export function useDeviceLanguage(auth: externs.Auth): void { +export function useDeviceLanguage(auth: Auth): void { auth.useDeviceLanguage(); } /** @@ -117,8 +117,8 @@ export function useDeviceLanguage(auth: externs.Auth): void { * @public */ export function updateCurrentUser( - auth: externs.Auth, - user: externs.User | null + auth: Auth, + user: User | null ): Promise { return auth.updateCurrentUser(user); } @@ -129,7 +129,7 @@ export function updateCurrentUser( * * @public */ -export function signOut(auth: externs.Auth): Promise { +export function signOut(auth: Auth): Promise { return auth.signOut(); } @@ -140,7 +140,7 @@ export { useAuthEmulator } from './auth/emulator'; export { AuthCredential } from './credentials'; export { EmailAuthCredential } from './credentials/email'; export { OAuthCredential } from './credentials/oauth'; -export { PhoneAuthCredential } from './credentials/phone'; +export { PhoneAuthCredentialImpl as PhoneAuthCredential } from './credentials/phone'; // persistence export { inMemoryPersistence } from './persistence/in_memory'; @@ -212,6 +212,6 @@ export { reload } from './user/reload'; * * @public */ -export async function deleteUser(user: externs.User): Promise { +export async function deleteUser(user: User): Promise { return user.delete(); } diff --git a/packages-exp/auth-exp/src/core/persistence/in_memory.test.ts b/packages-exp/auth-exp/src/core/persistence/in_memory.test.ts index 9b913230031..9686f1af3bc 100644 --- a/packages-exp/auth-exp/src/core/persistence/in_memory.test.ts +++ b/packages-exp/auth-exp/src/core/persistence/in_memory.test.ts @@ -19,10 +19,10 @@ import { expect } from 'chai'; import { testUser, testAuth } from '../../../test/helpers/mock_auth'; import { _getInstance } from '../util/instantiator'; -import { Persistence, PersistenceType } from './'; +import { PersistenceInternal, PersistenceType } from './'; import { inMemoryPersistence } from './in_memory'; -const persistence: Persistence = _getInstance(inMemoryPersistence); +const persistence: PersistenceInternal = _getInstance(inMemoryPersistence); describe('core/persistence/in_memory', () => { it('should work with persistence type', async () => { diff --git a/packages-exp/auth-exp/src/core/persistence/in_memory.ts b/packages-exp/auth-exp/src/core/persistence/in_memory.ts index 5829bf5c18e..9b9c909ebaa 100644 --- a/packages-exp/auth-exp/src/core/persistence/in_memory.ts +++ b/packages-exp/auth-exp/src/core/persistence/in_memory.ts @@ -15,16 +15,16 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { Persistence } from '../../model/public_types'; import { - Persistence, + PersistenceInternal, PersistenceType, PersistenceValue, StorageEventListener } from '../persistence'; -export class InMemoryPersistence implements Persistence { +export class InMemoryPersistence implements PersistenceInternal { static type: 'NONE' = 'NONE'; readonly type = PersistenceType.NONE; storage: Record = {}; @@ -62,4 +62,4 @@ export class InMemoryPersistence implements Persistence { * * @public */ -export const inMemoryPersistence: externs.Persistence = InMemoryPersistence; +export const inMemoryPersistence: Persistence = InMemoryPersistence; diff --git a/packages-exp/auth-exp/src/core/persistence/index.ts b/packages-exp/auth-exp/src/core/persistence/index.ts index 71f98470d3d..b231d4cdc86 100644 --- a/packages-exp/auth-exp/src/core/persistence/index.ts +++ b/packages-exp/auth-exp/src/core/persistence/index.ts @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { Persistence } from '../../model/public_types'; export const enum PersistenceType { SESSION = 'SESSION', @@ -35,7 +36,7 @@ export interface StorageEventListener { (value: PersistenceValue | null): void; } -export interface Persistence { +export interface PersistenceInternal extends Persistence { type: PersistenceType; _isAvailable(): Promise; _set(key: string, value: PersistenceValue): Promise; diff --git a/packages-exp/auth-exp/src/core/persistence/persistence_user_manager.test.ts b/packages-exp/auth-exp/src/core/persistence/persistence_user_manager.test.ts index 1cce6c683cf..d95f6a21052 100644 --- a/packages-exp/auth-exp/src/core/persistence/persistence_user_manager.test.ts +++ b/packages-exp/auth-exp/src/core/persistence/persistence_user_manager.test.ts @@ -23,7 +23,7 @@ import * as sinonChai from 'sinon-chai'; import { testAuth, testUser, TestAuth } from '../../../test/helpers/mock_auth'; import { UserImpl } from '../user/user_impl'; import { _getInstance } from '../util/instantiator'; -import { Persistence, PersistenceType, StorageEventListener } from './'; +import { PersistenceInternal, PersistenceType, StorageEventListener } from './'; import { inMemoryPersistence } from './in_memory'; import { KeyName, PersistenceUserManager } from './persistence_user_manager'; @@ -32,10 +32,10 @@ chai.use(sinonChai); function makePersistence( type = PersistenceType.NONE ): { - persistence: Persistence; - stub: sinon.SinonStubbedInstance; + persistence: PersistenceInternal; + stub: sinon.SinonStubbedInstance; } { - const persistence: Persistence = { + const persistence: PersistenceInternal = { type, _isAvailable: () => Promise.resolve(true), _set: async () => {}, @@ -113,7 +113,7 @@ describe('core/persistence/persistence_user_manager', () => { }); describe('manager methods', () => { - let persistenceStub: sinon.SinonStubbedInstance; + let persistenceStub: sinon.SinonStubbedInstance; let manager: PersistenceUserManager; beforeEach(async () => { diff --git a/packages-exp/auth-exp/src/core/persistence/persistence_user_manager.ts b/packages-exp/auth-exp/src/core/persistence/persistence_user_manager.ts index 93b65acd7e4..3533152bfa3 100644 --- a/packages-exp/auth-exp/src/core/persistence/persistence_user_manager.ts +++ b/packages-exp/auth-exp/src/core/persistence/persistence_user_manager.ts @@ -15,9 +15,9 @@ * limitations under the License. */ -import { ApiKey, AppName, Auth } from '../../model/auth'; -import { User } from '../../model/user'; -import { PersistedBlob, Persistence } from '../persistence'; +import { ApiKey, AppName, AuthInternal } from '../../model/auth'; +import { UserInternal } from '../../model/user'; +import { PersistedBlob, PersistenceInternal } from '../persistence'; import { UserImpl } from '../user/user_impl'; import { _getInstance } from '../util/instantiator'; import { inMemoryPersistence } from './in_memory'; @@ -46,8 +46,8 @@ export class PersistenceUserManager { private readonly boundEventHandler: () => void; private constructor( - public persistence: Persistence, - private readonly auth: Auth, + public persistence: PersistenceInternal, + private readonly auth: AuthInternal, private readonly userKey: string ) { const { config, name } = this.auth; @@ -61,11 +61,11 @@ export class PersistenceUserManager { this.persistence._addListener(this.fullUserKey, this.boundEventHandler); } - setCurrentUser(user: User): Promise { + setCurrentUser(user: UserInternal): Promise { return this.persistence._set(this.fullUserKey, user.toJSON()); } - async getCurrentUser(): Promise { + async getCurrentUser(): Promise { const blob = await this.persistence._get(this.fullUserKey); return blob ? UserImpl._fromJSON(this.auth, blob) : null; } @@ -81,7 +81,7 @@ export class PersistenceUserManager { ); } - async setPersistence(newPersistence: Persistence): Promise { + async setPersistence(newPersistence: PersistenceInternal): Promise { if (this.persistence.type === newPersistence.type) { return; } @@ -101,8 +101,8 @@ export class PersistenceUserManager { } static async create( - auth: Auth, - persistenceHierarchy: Persistence[], + auth: AuthInternal, + persistenceHierarchy: PersistenceInternal[], userKey = KeyName.AUTH_USER ): Promise { if (!persistenceHierarchy.length) { diff --git a/packages-exp/auth-exp/src/core/providers/email.ts b/packages-exp/auth-exp/src/core/providers/email.ts index d98231ca150..62d078518ea 100644 --- a/packages-exp/auth-exp/src/core/providers/email.ts +++ b/packages-exp/auth-exp/src/core/providers/email.ts @@ -15,7 +15,11 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { + EmailAuthProvider as EmailAuthProviderPublic, + ProviderId, + SignInMethod +} from '../../model/public_types'; import { ActionCodeURL } from '../action_code_url'; import { EmailAuthCredential } from '../credentials/email'; @@ -27,14 +31,13 @@ import { _assert } from '../util/assert'; * * @public */ -export class EmailAuthProvider implements externs.EmailAuthProvider { +export class EmailAuthProvider implements EmailAuthProviderPublic { /** {@inheritdoc @firebase/auth-types#EmailAuthProvider.PROVIDER_ID} */ - static readonly PROVIDER_ID = externs.ProviderId.PASSWORD; + static readonly PROVIDER_ID = ProviderId.PASSWORD; /** {@inheritdoc @firebase/auth-types#EmailAuthProvider.EMAIL_PASSWORD_SIGN_IN_METHOD} */ - static readonly EMAIL_PASSWORD_SIGN_IN_METHOD = - externs.SignInMethod.EMAIL_PASSWORD; + static readonly EMAIL_PASSWORD_SIGN_IN_METHOD = SignInMethod.EMAIL_PASSWORD; /** {@inheritdoc @firebase/auth-types#EmailAuthProvider.EMAIL_LINK_SIGN_IN_METHOD} */ - static readonly EMAIL_LINK_SIGN_IN_METHOD = externs.SignInMethod.EMAIL_LINK; + static readonly EMAIL_LINK_SIGN_IN_METHOD = SignInMethod.EMAIL_LINK; /** {@inheritdoc @firebase/auth-types#EmailAuthProvider.providerId} */ readonly providerId = EmailAuthProvider.PROVIDER_ID; diff --git a/packages-exp/auth-exp/src/core/providers/facebook.ts b/packages-exp/auth-exp/src/core/providers/facebook.ts index 1f6dcaaf5c1..fea4e6a99aa 100644 --- a/packages-exp/auth-exp/src/core/providers/facebook.ts +++ b/packages-exp/auth-exp/src/core/providers/facebook.ts @@ -15,12 +15,17 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { + OAuthCredential, + ProviderId, + SignInMethod, + UserCredential +} from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; import { TaggedWithTokenResponse } from '../../model/id_token'; -import { UserCredential } from '../../model/user'; -import { OAuthCredential } from '../credentials/oauth'; +import { UserCredentialInternal } from '../../model/user'; +import { OAuthCredential as OAuthCredentialImpl } from '../credentials/oauth'; import { OAuthProvider } from './oauth'; /** @@ -64,12 +69,12 @@ import { OAuthProvider } from './oauth'; */ export class FacebookAuthProvider extends OAuthProvider { /** Always set to {@link @firebase/auth-types#SignInMethod.FACEBOOK}. */ - static readonly FACEBOOK_SIGN_IN_METHOD = externs.SignInMethod.FACEBOOK; + static readonly FACEBOOK_SIGN_IN_METHOD = SignInMethod.FACEBOOK; /** Always set to {@link @firebase/auth-types#ProviderId.FACEBOOK}. */ - static readonly PROVIDER_ID = externs.ProviderId.FACEBOOK; + static readonly PROVIDER_ID = ProviderId.FACEBOOK; constructor() { - super(externs.ProviderId.FACEBOOK); + super(ProviderId.FACEBOOK); } /** @@ -84,8 +89,8 @@ export class FacebookAuthProvider extends OAuthProvider { * * @param accessToken - Facebook access token. */ - static credential(accessToken: string): externs.OAuthCredential { - return OAuthCredential._fromParams({ + static credential(accessToken: string): OAuthCredential { + return OAuthCredentialImpl._fromParams({ providerId: FacebookAuthProvider.PROVIDER_ID, signInMethod: FacebookAuthProvider.FACEBOOK_SIGN_IN_METHOD, accessToken @@ -98,10 +103,10 @@ export class FacebookAuthProvider extends OAuthProvider { * @param userCredential - The user credential. */ static credentialFromResult( - userCredential: externs.UserCredential - ): externs.OAuthCredential | null { + userCredential: UserCredential + ): OAuthCredential | null { return FacebookAuthProvider.credentialFromTaggedObject( - userCredential as UserCredential + userCredential as UserCredentialInternal ); } @@ -111,9 +116,7 @@ export class FacebookAuthProvider extends OAuthProvider { * * @param userCredential - The user credential. */ - static credentialFromError( - error: FirebaseError - ): externs.OAuthCredential | null { + static credentialFromError(error: FirebaseError): OAuthCredential | null { return FacebookAuthProvider.credentialFromTaggedObject( (error.customData || {}) as TaggedWithTokenResponse ); @@ -121,7 +124,7 @@ export class FacebookAuthProvider extends OAuthProvider { private static credentialFromTaggedObject({ _tokenResponse: tokenResponse - }: TaggedWithTokenResponse): externs.OAuthCredential | null { + }: TaggedWithTokenResponse): OAuthCredential | null { if (!tokenResponse || !('oauthAccessToken' in tokenResponse)) { return null; } diff --git a/packages-exp/auth-exp/src/core/providers/github.ts b/packages-exp/auth-exp/src/core/providers/github.ts index 737294d6da4..33ecefd0bf1 100644 --- a/packages-exp/auth-exp/src/core/providers/github.ts +++ b/packages-exp/auth-exp/src/core/providers/github.ts @@ -15,12 +15,17 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { + OAuthCredential, + ProviderId, + SignInMethod, + UserCredential +} from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; import { TaggedWithTokenResponse } from '../../model/id_token'; -import { UserCredential } from '../../model/user'; -import { OAuthCredential } from '../credentials/oauth'; +import { UserCredentialInternal } from '../../model/user'; +import { OAuthCredential as OAuthCredentialImpl } from '../credentials/oauth'; import { OAuthProvider } from './oauth'; /** @@ -67,12 +72,12 @@ import { OAuthProvider } from './oauth'; */ export class GithubAuthProvider extends OAuthProvider { /** Always set to {@link @firebase/auth-types#SignInMethod.GITHUB}. */ - static readonly GITHUB_SIGN_IN_METHOD = externs.SignInMethod.GITHUB; + static readonly GITHUB_SIGN_IN_METHOD = SignInMethod.GITHUB; /** Always set to {@link @firebase/auth-types#ProviderId.GITHUB}. */ - static readonly PROVIDER_ID = externs.ProviderId.GITHUB; + static readonly PROVIDER_ID = ProviderId.GITHUB; constructor() { - super(externs.ProviderId.GITHUB); + super(ProviderId.GITHUB); } /** @@ -80,8 +85,8 @@ export class GithubAuthProvider extends OAuthProvider { * * @param accessToken - Github access token. */ - static credential(accessToken: string): externs.OAuthCredential { - return OAuthCredential._fromParams({ + static credential(accessToken: string): OAuthCredential { + return OAuthCredentialImpl._fromParams({ providerId: GithubAuthProvider.PROVIDER_ID, signInMethod: GithubAuthProvider.GITHUB_SIGN_IN_METHOD, accessToken @@ -94,10 +99,10 @@ export class GithubAuthProvider extends OAuthProvider { * @param userCredential - The user credential. */ static credentialFromResult( - userCredential: externs.UserCredential - ): externs.OAuthCredential | null { + userCredential: UserCredential + ): OAuthCredential | null { return GithubAuthProvider.credentialFromTaggedObject( - userCredential as UserCredential + userCredential as UserCredentialInternal ); } @@ -107,9 +112,7 @@ export class GithubAuthProvider extends OAuthProvider { * * @param userCredential - The user credential. */ - static credentialFromError( - error: FirebaseError - ): externs.OAuthCredential | null { + static credentialFromError(error: FirebaseError): OAuthCredential | null { return GithubAuthProvider.credentialFromTaggedObject( (error.customData || {}) as TaggedWithTokenResponse ); @@ -117,7 +120,7 @@ export class GithubAuthProvider extends OAuthProvider { private static credentialFromTaggedObject({ _tokenResponse: tokenResponse - }: TaggedWithTokenResponse): externs.OAuthCredential | null { + }: TaggedWithTokenResponse): OAuthCredential | null { if (!tokenResponse || !('oauthAccessToken' in tokenResponse)) { return null; } diff --git a/packages-exp/auth-exp/src/core/providers/google.ts b/packages-exp/auth-exp/src/core/providers/google.ts index 6c316931efc..8ed4a7927e1 100644 --- a/packages-exp/auth-exp/src/core/providers/google.ts +++ b/packages-exp/auth-exp/src/core/providers/google.ts @@ -15,13 +15,18 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { + OAuthCredential, + ProviderId, + SignInMethod, + UserCredential +} from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; import { SignInWithIdpResponse } from '../../api/authentication/idp'; import { TaggedWithTokenResponse } from '../../model/id_token'; -import { UserCredential } from '../../model/user'; -import { OAuthCredential } from '../credentials/oauth'; +import { UserCredentialInternal } from '../../model/user'; +import { OAuthCredential as OAuthCredentialImpl } from '../credentials/oauth'; import { OAuthProvider } from './oauth'; /** @@ -67,12 +72,12 @@ import { OAuthProvider } from './oauth'; */ export class GoogleAuthProvider extends OAuthProvider { /** Always set to {@link @firebase/auth-types#SignInMethod.GOOGLE}. */ - static readonly GOOGLE_SIGN_IN_METHOD = externs.SignInMethod.GOOGLE; + static readonly GOOGLE_SIGN_IN_METHOD = SignInMethod.GOOGLE; /** Always set to {@link @firebase/auth-types#ProviderId.GOOGLE}. */ - static readonly PROVIDER_ID = externs.ProviderId.GOOGLE; + static readonly PROVIDER_ID = ProviderId.GOOGLE; constructor() { - super(externs.ProviderId.GOOGLE); + super(ProviderId.GOOGLE); this.addScope('profile'); } @@ -92,8 +97,8 @@ export class GoogleAuthProvider extends OAuthProvider { static credential( idToken?: string | null, accessToken?: string | null - ): externs.OAuthCredential { - return OAuthCredential._fromParams({ + ): OAuthCredential { + return OAuthCredentialImpl._fromParams({ providerId: GoogleAuthProvider.PROVIDER_ID, signInMethod: GoogleAuthProvider.GOOGLE_SIGN_IN_METHOD, idToken, @@ -107,10 +112,10 @@ export class GoogleAuthProvider extends OAuthProvider { * @param userCredential - The user credential. */ static credentialFromResult( - userCredential: externs.UserCredential - ): externs.OAuthCredential | null { + userCredential: UserCredential + ): OAuthCredential | null { return GoogleAuthProvider.credentialFromTaggedObject( - userCredential as UserCredential + userCredential as UserCredentialInternal ); } /** @@ -119,9 +124,7 @@ export class GoogleAuthProvider extends OAuthProvider { * * @param userCredential - The user credential. */ - static credentialFromError( - error: FirebaseError - ): externs.OAuthCredential | null { + static credentialFromError(error: FirebaseError): OAuthCredential | null { return GoogleAuthProvider.credentialFromTaggedObject( (error.customData || {}) as TaggedWithTokenResponse ); @@ -129,7 +132,7 @@ export class GoogleAuthProvider extends OAuthProvider { private static credentialFromTaggedObject({ _tokenResponse: tokenResponse - }: TaggedWithTokenResponse): externs.OAuthCredential | null { + }: TaggedWithTokenResponse): OAuthCredential | null { if (!tokenResponse) { return null; } diff --git a/packages-exp/auth-exp/src/core/providers/oauth.ts b/packages-exp/auth-exp/src/core/providers/oauth.ts index 59cefb8a75b..082817bfe0e 100644 --- a/packages-exp/auth-exp/src/core/providers/oauth.ts +++ b/packages-exp/auth-exp/src/core/providers/oauth.ts @@ -15,13 +15,17 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { + AuthProvider, + OAuthCredential, + UserCredential +} from '../../model/public_types'; import { _assert } from '../util/assert'; import { AuthErrorCode } from '../errors'; -import { OAuthCredential } from '../credentials/oauth'; -import { UserCredential } from '../../model/user'; +import { OAuthCredential as OAuthCredentialImpl } from '../credentials/oauth'; +import { UserCredentialInternal } from '../../model/user'; import { FirebaseError } from '@firebase/util'; import { TaggedWithTokenResponse } from '../../model/id_token'; import { SignInWithIdpResponse } from '../../../internal'; @@ -100,7 +104,7 @@ export interface OAuthCredentialOptions { * ``` * @public */ -export class OAuthProvider implements externs.AuthProvider { +export class OAuthProvider implements AuthProvider { /** @internal */ defaultLanguageCode: string | null = null; /** @internal */ @@ -115,13 +119,13 @@ export class OAuthProvider implements externs.AuthProvider { */ constructor(readonly providerId: string) {} - static credentialFromJSON(json: object | string): externs.OAuthCredential { + static credentialFromJSON(json: object | string): OAuthCredential { const obj = typeof json === 'string' ? JSON.parse(json) : json; _assert( 'providerId' in obj && 'signInMethod' in obj, AuthErrorCode.ARGUMENT_ERROR ); - return OAuthCredential._fromParams(obj); + return OAuthCredentialImpl._fromParams(obj); } /** @@ -145,10 +149,10 @@ export class OAuthProvider implements externs.AuthProvider { * @param params - Either the options object containing the ID token, access token and raw nonce * or the ID token string. */ - credential(params: OAuthCredentialOptions): externs.OAuthCredential { + credential(params: OAuthCredentialOptions): OAuthCredential { _assert(params.idToken && params.accessToken, AuthErrorCode.ARGUMENT_ERROR); // For OAuthCredential, sign in method is same as providerId. - return OAuthCredential._fromParams({ + return OAuthCredentialImpl._fromParams({ providerId: this.providerId, signInMethod: this.providerId, ...params @@ -174,9 +178,7 @@ export class OAuthProvider implements externs.AuthProvider { * * @param customOAuthParameters - The custom OAuth parameters to pass in the OAuth request. */ - setCustomParameters( - customOAuthParameters: CustomParameters - ): externs.AuthProvider { + setCustomParameters(customOAuthParameters: CustomParameters): AuthProvider { this.customParameters = customOAuthParameters; return this; } @@ -193,7 +195,7 @@ export class OAuthProvider implements externs.AuthProvider { * * @param scope - Provider OAuth scope to add. */ - addScope(scope: string): externs.AuthProvider { + addScope(scope: string): AuthProvider { // If not already added, add scope to list. if (!this.scopes.includes(scope)) { this.scopes.push(scope); @@ -214,10 +216,10 @@ export class OAuthProvider implements externs.AuthProvider { * @param userCredential - The user credential. */ static credentialFromResult( - userCredential: externs.UserCredential - ): externs.OAuthCredential | null { + userCredential: UserCredential + ): OAuthCredential | null { return OAuthProvider.oauthCredentialFromTaggedObject( - userCredential as UserCredential + userCredential as UserCredentialInternal ); } /** @@ -226,9 +228,7 @@ export class OAuthProvider implements externs.AuthProvider { * * @param userCredential - The user credential. */ - static credentialFromError( - error: FirebaseError - ): externs.OAuthCredential | null { + static credentialFromError(error: FirebaseError): OAuthCredential | null { return OAuthProvider.oauthCredentialFromTaggedObject( (error.customData || {}) as TaggedWithTokenResponse ); @@ -238,7 +238,7 @@ export class OAuthProvider implements externs.AuthProvider { // subclasses private static oauthCredentialFromTaggedObject({ _tokenResponse: tokenResponse - }: TaggedWithTokenResponse): externs.OAuthCredential | null { + }: TaggedWithTokenResponse): OAuthCredential | null { if (!tokenResponse) { return null; } diff --git a/packages-exp/auth-exp/src/core/providers/twitter.ts b/packages-exp/auth-exp/src/core/providers/twitter.ts index 7b5553e9ec8..1a2bd730765 100644 --- a/packages-exp/auth-exp/src/core/providers/twitter.ts +++ b/packages-exp/auth-exp/src/core/providers/twitter.ts @@ -32,13 +32,18 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { + OAuthCredential, + ProviderId, + SignInMethod, + UserCredential +} from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; import { SignInWithIdpResponse } from '../../api/authentication/idp'; import { TaggedWithTokenResponse } from '../../model/id_token'; -import { UserCredential } from '../../model/user'; -import { OAuthCredential } from '../credentials/oauth'; +import { UserCredentialInternal } from '../../model/user'; +import { OAuthCredential as OAuthCredentialImpl } from '../credentials/oauth'; import { OAuthProvider } from './oauth'; /** @@ -81,11 +86,11 @@ import { OAuthProvider } from './oauth'; * @public */ export class TwitterAuthProvider extends OAuthProvider { - static readonly TWITTER_SIGN_IN_METHOD = externs.SignInMethod.TWITTER; - static readonly PROVIDER_ID = externs.ProviderId.TWITTER; + static readonly TWITTER_SIGN_IN_METHOD = SignInMethod.TWITTER; + static readonly PROVIDER_ID = ProviderId.TWITTER; constructor() { - super(externs.ProviderId.TWITTER); + super(ProviderId.TWITTER); } /** @@ -94,8 +99,8 @@ export class TwitterAuthProvider extends OAuthProvider { * @param token - Twitter access token. * @param secret - Twitter secret. */ - static credential(token: string, secret: string): externs.OAuthCredential { - return OAuthCredential._fromParams({ + static credential(token: string, secret: string): OAuthCredential { + return OAuthCredentialImpl._fromParams({ providerId: TwitterAuthProvider.PROVIDER_ID, signInMethod: TwitterAuthProvider.TWITTER_SIGN_IN_METHOD, oauthToken: token, @@ -109,10 +114,10 @@ export class TwitterAuthProvider extends OAuthProvider { * @param userCredential - The user credential. */ static credentialFromResult( - userCredential: externs.UserCredential - ): externs.OAuthCredential | null { + userCredential: UserCredential + ): OAuthCredential | null { return TwitterAuthProvider.credentialFromTaggedObject( - userCredential as UserCredential + userCredential as UserCredentialInternal ); } @@ -122,9 +127,7 @@ export class TwitterAuthProvider extends OAuthProvider { * * @param userCredential - The user credential. */ - static credentialFromError( - error: FirebaseError - ): externs.OAuthCredential | null { + static credentialFromError(error: FirebaseError): OAuthCredential | null { return TwitterAuthProvider.credentialFromTaggedObject( (error.customData || {}) as TaggedWithTokenResponse ); @@ -132,7 +135,7 @@ export class TwitterAuthProvider extends OAuthProvider { private static credentialFromTaggedObject({ _tokenResponse: tokenResponse - }: TaggedWithTokenResponse): externs.OAuthCredential | null { + }: TaggedWithTokenResponse): OAuthCredential | null { if (!tokenResponse) { return null; } diff --git a/packages-exp/auth-exp/src/core/strategies/abstract_popup_redirect_operation.test.ts b/packages-exp/auth-exp/src/core/strategies/abstract_popup_redirect_operation.test.ts index ba275124a10..fbdee4d6d95 100644 --- a/packages-exp/auth-exp/src/core/strategies/abstract_popup_redirect_operation.test.ts +++ b/packages-exp/auth-exp/src/core/strategies/abstract_popup_redirect_operation.test.ts @@ -31,7 +31,7 @@ import { AuthEvent, AuthEventType, EventManager, - PopupRedirectResolver + PopupRedirectResolverInternal } from '../../model/popup_redirect'; import { AuthEventManager } from '../auth/auth_event_manager'; import { AuthErrorCode } from '../errors'; @@ -59,7 +59,7 @@ class WrapperOperation extends AbstractPopupRedirectOperation { describe('core/strategies/abstract_popup_redirect_operation', () => { let auth: TestAuth; - let resolver: PopupRedirectResolver; + let resolver: PopupRedirectResolverInternal; let eventManager: EventManager; let idpStubs: sinon.SinonStubbedInstance; diff --git a/packages-exp/auth-exp/src/core/strategies/abstract_popup_redirect_operation.ts b/packages-exp/auth-exp/src/core/strategies/abstract_popup_redirect_operation.ts index 0e4c909462a..477b63919de 100644 --- a/packages-exp/auth-exp/src/core/strategies/abstract_popup_redirect_operation.ts +++ b/packages-exp/auth-exp/src/core/strategies/abstract_popup_redirect_operation.ts @@ -22,9 +22,9 @@ import { AuthEventConsumer, AuthEventType, EventManager, - PopupRedirectResolver + PopupRedirectResolverInternal } from '../../model/popup_redirect'; -import { User, UserCredential } from '../../model/user'; +import { UserInternal, UserCredentialInternal } from '../../model/user'; import { AuthErrorCode } from '../errors'; import { debugAssert, _fail } from '../util/assert'; import { @@ -34,10 +34,10 @@ import { IdpTask, IdpTaskParams } from '../strategies/idp'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; interface PendingPromise { - resolve: (cred: UserCredential | null) => void; + resolve: (cred: UserCredentialInternal | null) => void; reject: (error: Error) => void; } @@ -54,10 +54,10 @@ export abstract class AbstractPopupRedirectOperation abstract eventId: string | null; constructor( - protected readonly auth: Auth, + protected readonly auth: AuthInternal, filter: AuthEventType | AuthEventType[], - protected readonly resolver: PopupRedirectResolver, - protected user?: User, + protected readonly resolver: PopupRedirectResolverInternal, + protected user?: UserInternal, private readonly bypassAuthState = false ) { this.filter = Array.isArray(filter) ? filter : [filter]; @@ -65,18 +65,20 @@ export abstract class AbstractPopupRedirectOperation abstract onExecution(): Promise; - execute(): Promise { - return new Promise(async (resolve, reject) => { - this.pendingPromise = { resolve, reject }; - - try { - this.eventManager = await this.resolver._initialize(this.auth); - await this.onExecution(); - this.eventManager.registerConsumer(this); - } catch (e) { - this.reject(e); + execute(): Promise { + return new Promise( + async (resolve, reject) => { + this.pendingPromise = { resolve, reject }; + + try { + this.eventManager = await this.resolver._initialize(this.auth); + await this.onExecution(); + this.eventManager.registerConsumer(this); + } catch (e) { + this.reject(e); + } } - }); + ); } async onAuthEvent(event: AuthEvent): Promise { @@ -123,7 +125,7 @@ export abstract class AbstractPopupRedirectOperation } } - protected resolve(cred: UserCredential | null): void { + protected resolve(cred: UserCredentialInternal | null): void { debugAssert(this.pendingPromise, 'Pending promise was never set'); this.pendingPromise.resolve(cred); this.unregisterAndCleanUp(); diff --git a/packages-exp/auth-exp/src/core/strategies/anonymous.ts b/packages-exp/auth-exp/src/core/strategies/anonymous.ts index 5b456e2be7b..917d7dad105 100644 --- a/packages-exp/auth-exp/src/core/strategies/anonymous.ts +++ b/packages-exp/auth-exp/src/core/strategies/anonymous.ts @@ -15,9 +15,9 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { Auth, OperationType, UserCredential } from '../../model/public_types'; import { signUp } from '../../api/authentication/sign_up'; -import { User } from '../../model/user'; +import { UserInternal } from '../../model/user'; import { UserCredentialImpl } from '../user/user_credential_impl'; import { _castAuth } from '../auth/auth_impl'; @@ -32,16 +32,14 @@ import { _castAuth } from '../auth/auth_impl'; * * @public */ -export async function signInAnonymously( - auth: externs.Auth -): Promise { +export async function signInAnonymously(auth: Auth): Promise { const authInternal = _castAuth(auth); if (authInternal.currentUser?.isAnonymous) { // If an anonymous user is already signed in, no need to sign them in again. return new UserCredentialImpl({ - user: authInternal.currentUser as User, + user: authInternal.currentUser as UserInternal, providerId: null, - operationType: externs.OperationType.SIGN_IN + operationType: OperationType.SIGN_IN }); } const response = await signUp(authInternal, { @@ -49,7 +47,7 @@ export async function signInAnonymously( }); const userCredential = await UserCredentialImpl._fromIdTokenResponse( authInternal, - externs.OperationType.SIGN_IN, + OperationType.SIGN_IN, response, true ); diff --git a/packages-exp/auth-exp/src/core/strategies/credential.test.ts b/packages-exp/auth-exp/src/core/strategies/credential.test.ts index 74e788cbe6e..837ec2bd5e6 100644 --- a/packages-exp/auth-exp/src/core/strategies/credential.test.ts +++ b/packages-exp/auth-exp/src/core/strategies/credential.test.ts @@ -36,7 +36,7 @@ import { APIUserInfo } from '../../api/account_management/account'; import { IdTokenMfaResponse } from '../../api/authentication/mfa'; import { MultiFactorError } from '../../mfa/mfa_error'; import { IdTokenResponse, IdTokenResponseKind } from '../../model/id_token'; -import { User, UserCredential } from '../../model/user'; +import { UserInternal, UserCredentialInternal } from '../../model/user'; import { AuthCredential } from '../credentials'; import { AuthErrorCode } from '../errors'; import { @@ -72,7 +72,7 @@ describe('core/strategies/credential', () => { let authCredential: AuthCredential; let auth: TestAuth; let getAccountInfoEndpoint: mockFetch.Route; - let user: User; + let user: UserInternal; beforeEach(async () => { auth = await testAuth(); @@ -99,7 +99,9 @@ describe('core/strategies/credential', () => { auth, authCredential ); - expect((rest as UserCredential)._tokenResponse).to.eq(idTokenResponse); + expect((rest as UserCredentialInternal)._tokenResponse).to.eq( + idTokenResponse + ); expect(user.uid).to.eq('local-id'); expect(user.displayName).to.eq('display-name'); expect(operationType).to.eq(OperationType.SIGN_IN); @@ -182,7 +184,7 @@ describe('core/strategies/credential', () => { } = await reauthenticateWithCredential(user, authCredential); expect(operationType).to.eq(OperationType.REAUTHENTICATE); expect(newUser).to.eq(user); - expect((rest as UserCredential)._tokenResponse).to.eql({ + expect((rest as UserCredentialInternal)._tokenResponse).to.eql({ ...idTokenResponse, idToken: makeJWT({ sub: 'uid' }) }); @@ -220,7 +222,9 @@ describe('core/strategies/credential', () => { } = await linkWithCredential(user, authCredential); expect(operationType).to.eq(OperationType.LINK); expect(newUser).to.eq(user); - expect((rest as UserCredential)._tokenResponse).to.eq(idTokenResponse); + expect((rest as UserCredentialInternal)._tokenResponse).to.eq( + idTokenResponse + ); }); }); }); diff --git a/packages-exp/auth-exp/src/core/strategies/credential.ts b/packages-exp/auth-exp/src/core/strategies/credential.ts index 05a31883f08..c09f267c137 100644 --- a/packages-exp/auth-exp/src/core/strategies/credential.ts +++ b/packages-exp/auth-exp/src/core/strategies/credential.ts @@ -15,21 +15,26 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; -import { OperationType, UserCredential } from '../../model/public_types'; +import { + OperationType, + UserCredential, + Auth, + AuthCredential, + User +} from '../../model/public_types'; import { _processCredentialSavingMfaContextIfNecessary } from '../../mfa/mfa_error'; -import { Auth } from '../../model/auth'; -import { User } from '../../model/user'; -import { AuthCredential } from '../credentials'; +import { AuthInternal } from '../../model/auth'; +import { UserInternal } from '../../model/user'; +import { AuthCredential as AuthCredentialImpl } from '../credentials'; import { _assertLinkedStatus, _link } from '../user/link_unlink'; import { _reauthenticate } from '../user/reauthenticate'; import { UserCredentialImpl } from '../user/user_credential_impl'; import { _castAuth } from '../auth/auth_impl'; export async function _signInWithCredential( - auth: Auth, - credential: AuthCredential, + auth: AuthInternal, + credential: AuthCredentialImpl, bypassAuthState = false ): Promise { const operationType = OperationType.SIGN_IN; @@ -62,10 +67,13 @@ export async function _signInWithCredential( * @public */ export async function signInWithCredential( - auth: externs.Auth, - credential: externs.AuthCredential -): Promise { - return _signInWithCredential(_castAuth(auth), credential as AuthCredential); + auth: Auth, + credential: AuthCredential +): Promise { + return _signInWithCredential( + _castAuth(auth), + credential as AuthCredentialImpl + ); } /** @@ -80,14 +88,14 @@ export async function signInWithCredential( * @public */ export async function linkWithCredential( - user: externs.User, - credential: externs.AuthCredential + user: User, + credential: AuthCredential ): Promise { - const userInternal = user as User; + const userInternal = user as UserInternal; await _assertLinkedStatus(false, userInternal, credential.providerId); - return _link(userInternal, credential as AuthCredential); + return _link(userInternal, credential as AuthCredentialImpl); } /** @@ -104,8 +112,11 @@ export async function linkWithCredential( * @public */ export async function reauthenticateWithCredential( - user: externs.User, - credential: externs.AuthCredential -): Promise { - return _reauthenticate(user as User, credential as AuthCredential); + user: User, + credential: AuthCredential +): Promise { + return _reauthenticate( + user as UserInternal, + credential as AuthCredentialImpl + ); } diff --git a/packages-exp/auth-exp/src/core/strategies/custom_token.test.ts b/packages-exp/auth-exp/src/core/strategies/custom_token.test.ts index 61f0701c99b..082b678dad3 100644 --- a/packages-exp/auth-exp/src/core/strategies/custom_token.test.ts +++ b/packages-exp/auth-exp/src/core/strategies/custom_token.test.ts @@ -26,7 +26,7 @@ import * as mockFetch from '../../../test/helpers/mock_fetch'; import { Endpoint } from '../../api'; import { APIUserInfo } from '../../api/account_management/account'; import { IdTokenResponse, IdTokenResponseKind } from '../../model/id_token'; -import { UserCredential } from '../../model/user'; +import { UserCredentialInternal } from '../../model/user'; import { signInWithCustomToken } from './custom_token'; use(chaiAsPromised); @@ -75,7 +75,7 @@ describe('core/strategies/signInWithCustomToken', () => { } = (await signInWithCustomToken( auth, 'look-at-me-im-a-jwt' - )) as UserCredential; + )) as UserCredentialInternal; expect(_tokenResponse).to.eql(idTokenResponse); expect(user.uid).to.eq('local-id'); expect(user.displayName).to.eq('display-name'); diff --git a/packages-exp/auth-exp/src/core/strategies/custom_token.ts b/packages-exp/auth-exp/src/core/strategies/custom_token.ts index e9c595e9136..ce798b6dd3c 100644 --- a/packages-exp/auth-exp/src/core/strategies/custom_token.ts +++ b/packages-exp/auth-exp/src/core/strategies/custom_token.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { Auth, OperationType, UserCredential } from '../../model/public_types'; import { signInWithCustomToken as getIdTokenResponse } from '../../api/authentication/custom_token'; import { IdTokenResponse } from '../../model/id_token'; @@ -39,9 +39,9 @@ import { _castAuth } from '../auth/auth_impl'; * @public */ export async function signInWithCustomToken( - auth: externs.Auth, + auth: Auth, customToken: string -): Promise { +): Promise { const response: IdTokenResponse = await getIdTokenResponse(auth, { token: customToken, returnSecureToken: true @@ -49,7 +49,7 @@ export async function signInWithCustomToken( const authInternal = _castAuth(auth); const cred = await UserCredentialImpl._fromIdTokenResponse( authInternal, - externs.OperationType.SIGN_IN, + OperationType.SIGN_IN, response ); await authInternal._updateCurrentUser(cred.user); diff --git a/packages-exp/auth-exp/src/core/strategies/email.test.ts b/packages-exp/auth-exp/src/core/strategies/email.test.ts index 5adf310c4cd..2a7911958be 100644 --- a/packages-exp/auth-exp/src/core/strategies/email.test.ts +++ b/packages-exp/auth-exp/src/core/strategies/email.test.ts @@ -28,7 +28,7 @@ import { testAuth, TestAuth, testUser } from '../../../test/helpers/mock_auth'; import * as mockFetch from '../../../test/helpers/mock_fetch'; import { Endpoint } from '../../api'; import { ServerError } from '../../api/errors'; -import { User } from '../../model/user'; +import { UserInternal } from '../../model/user'; import { fetchSignInMethodsForEmail, sendEmailVerification, @@ -103,7 +103,7 @@ describe('core/strategies/fetchSignInMethodsForEmail', () => { describe('core/strategies/sendEmailVerification', () => { const email = 'foo@bar.com'; const idToken = 'access-token'; - let user: User; + let user: UserInternal; let auth: TestAuth; let reloadStub: SinonStub; @@ -209,7 +209,7 @@ describe('core/strategies/verifyBeforeUpdateEmail', () => { const email = 'foo@bar.com'; const newEmail = 'newemail@bar.com'; const idToken = 'access-token'; - let user: User; + let user: UserInternal; let auth: TestAuth; let reloadStub: SinonStub; diff --git a/packages-exp/auth-exp/src/core/strategies/email.ts b/packages-exp/auth-exp/src/core/strategies/email.ts index 32aabd504f8..3eb5b8f3dbe 100644 --- a/packages-exp/auth-exp/src/core/strategies/email.ts +++ b/packages-exp/auth-exp/src/core/strategies/email.ts @@ -15,14 +15,19 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { + ActionCodeOperation, + ActionCodeSettings, + Auth, + User +} from '../../model/public_types'; import { createAuthUri, CreateAuthUriRequest } from '../../api/authentication/create_auth_uri'; import * as api from '../../api/authentication/email_and_password'; -import { User } from '../../model/user'; +import { UserInternal } from '../../model/user'; import { _getCurrentUrl, _isHttpOrHttps } from '../util/location'; import { _setActionCodeSettingsOnRequest } from './action_code_settings'; @@ -41,7 +46,7 @@ import { _setActionCodeSettingsOnRequest } from './action_code_settings'; * @public */ export async function fetchSignInMethodsForEmail( - auth: externs.Auth, + auth: Auth, email: string ): Promise { // createAuthUri returns an error if continue URI is not http or https. @@ -89,13 +94,13 @@ export async function fetchSignInMethodsForEmail( * @public */ export async function sendEmailVerification( - user: externs.User, - actionCodeSettings?: externs.ActionCodeSettings | null + user: User, + actionCodeSettings?: ActionCodeSettings | null ): Promise { - const userInternal = user as User; + const userInternal = user as UserInternal; const idToken = await user.getIdToken(); const request: api.VerifyEmailRequest = { - requestType: externs.ActionCodeOperation.VERIFY_EMAIL, + requestType: ActionCodeOperation.VERIFY_EMAIL, idToken }; if (actionCodeSettings) { @@ -148,14 +153,14 @@ export async function sendEmailVerification( * @public */ export async function verifyBeforeUpdateEmail( - user: externs.User, + user: User, newEmail: string, - actionCodeSettings?: externs.ActionCodeSettings | null + actionCodeSettings?: ActionCodeSettings | null ): Promise { - const userInternal = user as User; + const userInternal = user as UserInternal; const idToken = await user.getIdToken(); const request: api.VerifyAndChangeEmailRequest = { - requestType: externs.ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL, + requestType: ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL, idToken, newEmail }; diff --git a/packages-exp/auth-exp/src/core/strategies/email_and_password.test.ts b/packages-exp/auth-exp/src/core/strategies/email_and_password.test.ts index 3dc2a24e6b4..e0b60903aa9 100644 --- a/packages-exp/auth-exp/src/core/strategies/email_and_password.test.ts +++ b/packages-exp/auth-exp/src/core/strategies/email_and_password.test.ts @@ -28,7 +28,7 @@ import * as mockFetch from '../../../test/helpers/mock_fetch'; import { Endpoint } from '../../api'; import { APIUserInfo } from '../../api/account_management/account'; import { ServerError } from '../../api/errors'; -import { UserCredential } from '../../model/user'; +import { UserCredentialInternal } from '../../model/user'; import { applyActionCode, checkActionCode, @@ -391,7 +391,7 @@ describe('core/strategies/email_and_password/createUserWithEmailAndPassword', () auth, 'some-email', 'some-password' - )) as UserCredential; + )) as UserCredentialInternal; expect(_tokenResponse).to.eql({ idToken: 'id-token', refreshToken: 'refresh-token', @@ -434,7 +434,7 @@ describe('core/strategies/email_and_password/signInWithEmailAndPassword', () => auth, 'some-email', 'some-password' - )) as UserCredential; + )) as UserCredentialInternal; expect(_tokenResponse).to.eql({ idToken: 'id-token', refreshToken: 'refresh-token', diff --git a/packages-exp/auth-exp/src/core/strategies/email_and_password.ts b/packages-exp/auth-exp/src/core/strategies/email_and_password.ts index b73b3053d4e..bc8d8c3abc5 100644 --- a/packages-exp/auth-exp/src/core/strategies/email_and_password.ts +++ b/packages-exp/auth-exp/src/core/strategies/email_and_password.ts @@ -15,12 +15,19 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { + ActionCodeInfo, + ActionCodeOperation, + ActionCodeSettings, + Auth, + OperationType, + UserCredential +} from '../../model/public_types'; import * as account from '../../api/account_management/email_and_password'; import * as authentication from '../../api/authentication/email_and_password'; import { signUp } from '../../api/authentication/sign_up'; -import { MultiFactorInfo } from '../../mfa/mfa_info'; +import { MultiFactorInfoImpl } from '../../mfa/mfa_info'; import { EmailAuthProvider } from '../providers/email'; import { UserCredentialImpl } from '../user/user_credential_impl'; import { _assert } from '../util/assert'; @@ -62,12 +69,12 @@ import { AuthErrorCode } from '../errors'; * @public */ export async function sendPasswordResetEmail( - auth: externs.Auth, + auth: Auth, email: string, - actionCodeSettings?: externs.ActionCodeSettings + actionCodeSettings?: ActionCodeSettings ): Promise { const request: authentication.PasswordResetRequest = { - requestType: externs.ActionCodeOperation.PASSWORD_RESET, + requestType: ActionCodeOperation.PASSWORD_RESET, email }; if (actionCodeSettings) { @@ -87,7 +94,7 @@ export async function sendPasswordResetEmail( * @public */ export async function confirmPasswordReset( - auth: externs.Auth, + auth: Auth, oobCode: string, newPassword: string ): Promise { @@ -107,7 +114,7 @@ export async function confirmPasswordReset( * @public */ export async function applyActionCode( - auth: externs.Auth, + auth: Auth, oobCode: string ): Promise { await account.applyActionCode(auth, { oobCode }); @@ -124,9 +131,9 @@ export async function applyActionCode( * @public */ export async function checkActionCode( - auth: externs.Auth, + auth: Auth, oobCode: string -): Promise { +): Promise { const response = await account.resetPassword(auth, { oobCode }); // Email could be empty only if the request type is EMAIL_SIGNIN or @@ -138,12 +145,12 @@ export async function checkActionCode( const operation = response.requestType; _assert(operation, auth, AuthErrorCode.INTERNAL_ERROR); switch (operation) { - case externs.ActionCodeOperation.EMAIL_SIGNIN: + case ActionCodeOperation.EMAIL_SIGNIN: break; - case externs.ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL: + case ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL: _assert(response.newEmail, auth, AuthErrorCode.INTERNAL_ERROR); break; - case externs.ActionCodeOperation.REVERT_SECOND_FACTOR_ADDITION: + case ActionCodeOperation.REVERT_SECOND_FACTOR_ADDITION: _assert(response.mfaInfo, auth, AuthErrorCode.INTERNAL_ERROR); // fall through default: @@ -151,9 +158,9 @@ export async function checkActionCode( } // The multi-factor info for revert second factor addition - let multiFactorInfo: MultiFactorInfo | null = null; + let multiFactorInfo: MultiFactorInfoImpl | null = null; if (response.mfaInfo) { - multiFactorInfo = MultiFactorInfo._fromServerResponse( + multiFactorInfo = MultiFactorInfoImpl._fromServerResponse( _castAuth(auth), response.mfaInfo ); @@ -162,13 +169,11 @@ export async function checkActionCode( return { data: { email: - (response.requestType === - externs.ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL + (response.requestType === ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL ? response.newEmail : response.email) || null, previousEmail: - (response.requestType === - externs.ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL + (response.requestType === ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL ? response.email : response.newEmail) || null, multiFactorInfo @@ -188,7 +193,7 @@ export async function checkActionCode( * @public */ export async function verifyPasswordResetCode( - auth: externs.Auth, + auth: Auth, code: string ): Promise { const { data } = await checkActionCode(auth, code); @@ -214,10 +219,10 @@ export async function verifyPasswordResetCode( * @public */ export async function createUserWithEmailAndPassword( - auth: externs.Auth, + auth: Auth, email: string, password: string -): Promise { +): Promise { const authInternal = _castAuth(auth); const response = await signUp(auth, { returnSecureToken: true, @@ -227,7 +232,7 @@ export async function createUserWithEmailAndPassword( const userCredential = await UserCredentialImpl._fromIdTokenResponse( authInternal, - externs.OperationType.SIGN_IN, + OperationType.SIGN_IN, response ); await authInternal._updateCurrentUser(userCredential.user); @@ -252,10 +257,10 @@ export async function createUserWithEmailAndPassword( * @public */ export function signInWithEmailAndPassword( - auth: externs.Auth, + auth: Auth, email: string, password: string -): Promise { +): Promise { return signInWithCredential( auth, EmailAuthProvider.credential(email, password) diff --git a/packages-exp/auth-exp/src/core/strategies/email_link.test.ts b/packages-exp/auth-exp/src/core/strategies/email_link.test.ts index 043839742fc..b0a4f061e44 100644 --- a/packages-exp/auth-exp/src/core/strategies/email_link.test.ts +++ b/packages-exp/auth-exp/src/core/strategies/email_link.test.ts @@ -19,7 +19,7 @@ import { expect, use } from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; import * as sinonChai from 'sinon-chai'; -import * as externs from '../../model/public_types'; +import { ActionCodeOperation } from '../../model/public_types'; import { OperationType } from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; @@ -29,7 +29,7 @@ import * as mockFetch from '../../../test/helpers/mock_fetch'; import { Endpoint } from '../../api'; import { APIUserInfo } from '../../api/account_management/account'; import { ServerError } from '../../api/errors'; -import { UserCredential } from '../../model/user'; +import { UserCredentialInternal } from '../../model/user'; import { isSignInWithEmailLink, sendSignInLinkToEmail, @@ -60,7 +60,7 @@ describe('core/strategies/sendSignInLinkToEmail', () => { url: 'continue-url' }); expect(mock.calls[0].request).to.eql({ - requestType: externs.ActionCodeOperation.EMAIL_SIGNIN, + requestType: ActionCodeOperation.EMAIL_SIGNIN, email, canHandleCodeInApp: true, continueUrl: 'continue-url' @@ -112,7 +112,7 @@ describe('core/strategies/sendSignInLinkToEmail', () => { }); expect(mock.calls[0].request).to.eql({ - requestType: externs.ActionCodeOperation.EMAIL_SIGNIN, + requestType: ActionCodeOperation.EMAIL_SIGNIN, email, continueUrl: 'my-url', dynamicLinkDomain: 'fdl-domain', @@ -138,7 +138,7 @@ describe('core/strategies/sendSignInLinkToEmail', () => { dynamicLinkDomain: 'fdl-domain' }); expect(mock.calls[0].request).to.eql({ - requestType: externs.ActionCodeOperation.EMAIL_SIGNIN, + requestType: ActionCodeOperation.EMAIL_SIGNIN, email, continueUrl: 'my-url', dynamicLinkDomain: 'fdl-domain', @@ -248,7 +248,7 @@ describe('core/strategies/email_and_password/signInWithEmailLink', () => { auth, 'some-email', actionLink - )) as UserCredential; + )) as UserCredentialInternal; expect(_tokenResponse).to.eql({ idToken: 'id-token', refreshToken: 'refresh-token', diff --git a/packages-exp/auth-exp/src/core/strategies/email_link.ts b/packages-exp/auth-exp/src/core/strategies/email_link.ts index 61c79ad0665..c0c918d6b7f 100644 --- a/packages-exp/auth-exp/src/core/strategies/email_link.ts +++ b/packages-exp/auth-exp/src/core/strategies/email_link.ts @@ -15,7 +15,12 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { + ActionCodeOperation, + ActionCodeSettings, + Auth, + UserCredential +} from '../../model/public_types'; import * as api from '../../api/authentication/email_and_password'; import { ActionCodeURL } from '../action_code_url'; @@ -65,12 +70,12 @@ import { _assert } from '../util/assert'; * @public */ export async function sendSignInLinkToEmail( - auth: externs.Auth, + auth: Auth, email: string, - actionCodeSettings?: externs.ActionCodeSettings + actionCodeSettings?: ActionCodeSettings ): Promise { const request: api.EmailSignInRequest = { - requestType: externs.ActionCodeOperation.EMAIL_SIGNIN, + requestType: ActionCodeOperation.EMAIL_SIGNIN, email }; _assert( @@ -93,12 +98,9 @@ export async function sendSignInLinkToEmail( * * @public */ -export function isSignInWithEmailLink( - auth: externs.Auth, - emailLink: string -): boolean { +export function isSignInWithEmailLink(auth: Auth, emailLink: string): boolean { const actionCodeUrl = ActionCodeURL.parseLink(emailLink); - return actionCodeUrl?.operation === externs.ActionCodeOperation.EMAIL_SIGNIN; + return actionCodeUrl?.operation === ActionCodeOperation.EMAIL_SIGNIN; } /** @@ -139,10 +141,10 @@ export function isSignInWithEmailLink( * @public */ export async function signInWithEmailLink( - auth: externs.Auth, + auth: Auth, email: string, emailLink?: string -): Promise { +): Promise { const credential = EmailAuthProvider.credentialWithLink( email, emailLink || _getCurrentUrl() diff --git a/packages-exp/auth-exp/src/core/strategies/idp.test.ts b/packages-exp/auth-exp/src/core/strategies/idp.test.ts index c2f40d17491..87e0c4ac303 100644 --- a/packages-exp/auth-exp/src/core/strategies/idp.test.ts +++ b/packages-exp/auth-exp/src/core/strategies/idp.test.ts @@ -28,7 +28,7 @@ import { makeJWT } from '../../../test/helpers/jwt'; import { testAuth, testUser, TestAuth } from '../../../test/helpers/mock_auth'; import * as fetch from '../../../test/helpers/mock_fetch'; import { Endpoint } from '../../api'; -import { User } from '../../model/user'; +import { UserInternal } from '../../model/user'; import * as reauthenticate from '../../core/user/reauthenticate'; import * as linkUnlink from '../../core/user/link_unlink'; import * as credential from '../../core/strategies/credential'; @@ -41,7 +41,7 @@ use(sinonChai); describe('core/strategies/idb', () => { let auth: TestAuth; - let user: User; + let user: UserInternal; let signInEndpoint: fetch.Route; beforeEach(async () => { diff --git a/packages-exp/auth-exp/src/core/strategies/idp.ts b/packages-exp/auth-exp/src/core/strategies/idp.ts index 56979d15131..a4ebea9997e 100644 --- a/packages-exp/auth-exp/src/core/strategies/idp.ts +++ b/packages-exp/auth-exp/src/core/strategies/idp.ts @@ -15,15 +15,15 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { ProviderId } from '../../model/public_types'; import { signInWithIdp, SignInWithIdpRequest } from '../../api/authentication/idp'; import { PhoneOrOauthTokenResponse } from '../../api/authentication/mfa'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; import { IdTokenResponse } from '../../model/id_token'; -import { User, UserCredential } from '../../model/user'; +import { UserInternal, UserCredentialInternal } from '../../model/user'; import { AuthCredential } from '../credentials'; import { _link as _linkUser } from '../user/link_unlink'; import { _reauthenticate } from '../user/reauthenticate'; @@ -32,32 +32,37 @@ import { _signInWithCredential } from './credential'; import { AuthErrorCode } from '../errors'; export interface IdpTaskParams { - auth: Auth; + auth: AuthInternal; requestUri: string; sessionId?: string; tenantId?: string; postBody?: string; pendingToken?: string; - user?: User; + user?: UserInternal; bypassAuthState?: boolean; } -export type IdpTask = (params: IdpTaskParams) => Promise; +export type IdpTask = ( + params: IdpTaskParams +) => Promise; class IdpCredential extends AuthCredential { constructor(readonly params: IdpTaskParams) { - super(externs.ProviderId.CUSTOM, externs.ProviderId.CUSTOM); + super(ProviderId.CUSTOM, ProviderId.CUSTOM); } - _getIdTokenResponse(auth: Auth): Promise { + _getIdTokenResponse(auth: AuthInternal): Promise { return signInWithIdp(auth, this._buildIdpRequest()); } - _linkToIdToken(auth: Auth, idToken: string): Promise { + _linkToIdToken( + auth: AuthInternal, + idToken: string + ): Promise { return signInWithIdp(auth, this._buildIdpRequest(idToken)); } - _getReauthenticationResolver(auth: Auth): Promise { + _getReauthenticationResolver(auth: AuthInternal): Promise { return signInWithIdp(auth, this._buildIdpRequest()); } @@ -80,15 +85,19 @@ class IdpCredential extends AuthCredential { } } -export function _signIn(params: IdpTaskParams): Promise { +export function _signIn( + params: IdpTaskParams +): Promise { return _signInWithCredential( params.auth, new IdpCredential(params), params.bypassAuthState - ) as Promise; + ) as Promise; } -export function _reauth(params: IdpTaskParams): Promise { +export function _reauth( + params: IdpTaskParams +): Promise { const { auth, user } = params; _assert(user, auth, AuthErrorCode.INTERNAL_ERROR); return _reauthenticate( @@ -98,7 +107,9 @@ export function _reauth(params: IdpTaskParams): Promise { ); } -export async function _link(params: IdpTaskParams): Promise { +export async function _link( + params: IdpTaskParams +): Promise { const { auth, user } = params; _assert(user, auth, AuthErrorCode.INTERNAL_ERROR); return _linkUser(user, new IdpCredential(params), params.bypassAuthState); diff --git a/packages-exp/auth-exp/src/core/strategies/redirect.test.ts b/packages-exp/auth-exp/src/core/strategies/redirect.test.ts index 7170d6b4793..bc847589849 100644 --- a/packages-exp/auth-exp/src/core/strategies/redirect.test.ts +++ b/packages-exp/auth-exp/src/core/strategies/redirect.test.ts @@ -15,7 +15,12 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { + AuthError, + OperationType, + PopupRedirectResolver, + ProviderId +} from '../../model/public_types'; import * as sinon from 'sinon'; import { _getInstance } from '../util/instantiator'; import { @@ -25,16 +30,16 @@ import { testUser } from '../../../test/helpers/mock_auth'; import { makeMockPopupRedirectResolver } from '../../../test/helpers/mock_popup_redirect_resolver'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; import { AuthEventManager } from '../auth/auth_event_manager'; import { RedirectAction, _clearRedirectOutcomes } from './redirect'; import { AuthEvent, AuthEventType, - PopupRedirectResolver + PopupRedirectResolverInternal } from '../../model/popup_redirect'; import { BASE_AUTH_EVENT } from '../../../test/helpers/iframe_event'; -import { Persistence } from '../persistence'; +import { PersistenceInternal } from '../persistence'; import { InMemoryPersistence } from '../persistence/in_memory'; import { UserCredentialImpl } from '../user/user_credential_impl'; import * as idpTasks from '../strategies/idp'; @@ -47,17 +52,17 @@ const OTHER_EVENT_ID = 'wrong-id'; class RedirectPersistence extends InMemoryPersistence {} describe('core/strategies/redirect', () => { - let auth: Auth; + let auth: AuthInternal; let redirectAction: RedirectAction; let eventManager: AuthEventManager; - let resolver: externs.PopupRedirectResolver; + let resolver: PopupRedirectResolver; let idpStubs: sinon.SinonStubbedInstance; beforeEach(async () => { eventManager = new AuthEventManager(({} as unknown) as TestAuth); idpStubs = sinon.stub(idpTasks); resolver = makeMockPopupRedirectResolver(eventManager); - _getInstance( + _getInstance( resolver )._redirectPersistence = RedirectPersistence; auth = await testAuth(); @@ -81,7 +86,9 @@ describe('core/strategies/redirect', () => { } async function reInitAuthWithRedirectUser(eventId: string): Promise { - const redirectPersistence: Persistence = _getInstance(RedirectPersistence); + const redirectPersistence: PersistenceInternal = _getInstance( + RedirectPersistence + ); const mainPersistence = new MockPersistenceLayer(); const oldAuth = await testAuth(); const user = testUser(oldAuth, 'uid'); @@ -98,8 +105,8 @@ describe('core/strategies/redirect', () => { it('completes with the cred', async () => { const cred = new UserCredentialImpl({ user: testUser(auth, 'uid'), - providerId: externs.ProviderId.GOOGLE, - operationType: externs.OperationType.SIGN_IN + providerId: ProviderId.GOOGLE, + operationType: OperationType.SIGN_IN }); idpStubs._signIn.returns(Promise.resolve(cred)); const promise = redirectAction.execute(); @@ -112,8 +119,8 @@ describe('core/strategies/redirect', () => { it('returns the same value if called multiple times', async () => { const cred = new UserCredentialImpl({ user: testUser(auth, 'uid'), - providerId: externs.ProviderId.GOOGLE, - operationType: externs.OperationType.SIGN_IN + providerId: ProviderId.GOOGLE, + operationType: OperationType.SIGN_IN }); idpStubs._signIn.returns(Promise.resolve(cred)); const promise = redirectAction.execute(); @@ -131,8 +138,8 @@ describe('core/strategies/redirect', () => { const cred = new UserCredentialImpl({ user: testUser(auth, 'uid'), - providerId: externs.ProviderId.GOOGLE, - operationType: externs.OperationType.LINK + providerId: ProviderId.GOOGLE, + operationType: OperationType.LINK }); idpStubs._link.returns(Promise.resolve(cred)); const promise = redirectAction.execute(); @@ -149,8 +156,8 @@ describe('core/strategies/redirect', () => { const cred = new UserCredentialImpl({ user: testUser(auth, 'uid'), - providerId: externs.ProviderId.GOOGLE, - operationType: externs.OperationType.LINK + providerId: ProviderId.GOOGLE, + operationType: OperationType.LINK }); idpStubs._link.returns(Promise.resolve(cred)); const promise = redirectAction.execute(); @@ -166,7 +173,7 @@ describe('core/strategies/redirect', () => { type: AuthEventType.UNKNOWN, error: { code: `auth/${AuthErrorCode.NO_AUTH_EVENT}` - } as externs.AuthError + } as AuthError }); expect(await promise).to.be.null; }); @@ -176,8 +183,8 @@ describe('core/strategies/redirect', () => { const cred = new UserCredentialImpl({ user: testUser(auth, 'uid'), - providerId: externs.ProviderId.GOOGLE, - operationType: externs.OperationType.REAUTHENTICATE + providerId: ProviderId.GOOGLE, + operationType: OperationType.REAUTHENTICATE }); idpStubs._reauth.returns(Promise.resolve(cred)); const promise = redirectAction.execute(); diff --git a/packages-exp/auth-exp/src/core/strategies/redirect.ts b/packages-exp/auth-exp/src/core/strategies/redirect.ts index 677b728a9e2..254f31f9c54 100644 --- a/packages-exp/auth-exp/src/core/strategies/redirect.ts +++ b/packages-exp/auth-exp/src/core/strategies/redirect.ts @@ -15,28 +15,28 @@ * limitations under the License. */ -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; import { AuthEvent, AuthEventType, - PopupRedirectResolver + PopupRedirectResolverInternal } from '../../model/popup_redirect'; -import { UserCredential } from '../../model/user'; +import { UserCredentialInternal } from '../../model/user'; import { AbstractPopupRedirectOperation } from './abstract_popup_redirect_operation'; // We only get one redirect outcome for any one auth, so just store it // in here. const redirectOutcomeMap: Map< string, - () => Promise + () => Promise > = new Map(); export class RedirectAction extends AbstractPopupRedirectOperation { eventId = null; constructor( - auth: Auth, - resolver: PopupRedirectResolver, + auth: AuthInternal, + resolver: PopupRedirectResolverInternal, bypassAuthState = false ) { super( @@ -57,7 +57,7 @@ export class RedirectAction extends AbstractPopupRedirectOperation { * Override the execute function; if we already have a redirect result, then * just return it. */ - async execute(): Promise { + async execute(): Promise { let readyOutcome = redirectOutcomeMap.get(this.auth._key()); if (!readyOutcome) { try { diff --git a/packages-exp/auth-exp/src/core/user/account_info.test.ts b/packages-exp/auth-exp/src/core/user/account_info.test.ts index 3e29b4dd1f2..7c33f05de79 100644 --- a/packages-exp/auth-exp/src/core/user/account_info.test.ts +++ b/packages-exp/auth-exp/src/core/user/account_info.test.ts @@ -26,7 +26,7 @@ import { mockEndpoint } from '../../../test/helpers/api/helper'; import { TestAuth, testAuth, testUser } from '../../../test/helpers/mock_auth'; import * as fetch from '../../../test/helpers/mock_fetch'; import { Endpoint } from '../../api'; -import { User } from '../../model/user'; +import { UserInternal } from '../../model/user'; import { updateEmail, updatePassword, updateProfile } from './account_info'; use(chaiAsPromised); @@ -42,7 +42,7 @@ const PASSWORD_PROVIDER: UserInfo = { }; describe('core/user/profile', () => { - let user: User; + let user: UserInternal; let auth: TestAuth; beforeEach(async () => { diff --git a/packages-exp/auth-exp/src/core/user/account_info.ts b/packages-exp/auth-exp/src/core/user/account_info.ts index 04bd34e7782..62c4444f0ff 100644 --- a/packages-exp/auth-exp/src/core/user/account_info.ts +++ b/packages-exp/auth-exp/src/core/user/account_info.ts @@ -15,14 +15,14 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { ProviderId, User } from '../../model/public_types'; import { updateEmailPassword as apiUpdateEmailPassword, UpdateEmailPasswordRequest } from '../../api/account_management/email_and_password'; import { updateProfile as apiUpdateProfile } from '../../api/account_management/profile'; -import { User } from '../../model/user'; +import { UserInternal } from '../../model/user'; import { _logoutIfInvalidated } from './invalidation'; interface Profile { @@ -39,14 +39,14 @@ interface Profile { * @public */ export async function updateProfile( - user: externs.User, + user: User, { displayName, photoURL: photoUrl }: Profile ): Promise { if (displayName === undefined && photoUrl === undefined) { return; } - const userInternal = user as User; + const userInternal = user as UserInternal; const idToken = await user.getIdToken(); const profileRequest = { idToken, @@ -64,7 +64,7 @@ export async function updateProfile( // Update the password provider as well const passwordProvider = userInternal.providerData.find( - ({ providerId }) => providerId === externs.ProviderId.PASSWORD + ({ providerId }) => providerId === ProviderId.PASSWORD ); if (passwordProvider) { passwordProvider.displayName = user.displayName; @@ -90,11 +90,8 @@ export async function updateProfile( * * @public */ -export function updateEmail( - user: externs.User, - newEmail: string -): Promise { - return updateEmailOrPassword(user as User, newEmail, null); +export function updateEmail(user: User, newEmail: string): Promise { + return updateEmailOrPassword(user as UserInternal, newEmail, null); } /** @@ -110,15 +107,12 @@ export function updateEmail( * * @public */ -export function updatePassword( - user: externs.User, - newPassword: string -): Promise { - return updateEmailOrPassword(user as User, null, newPassword); +export function updatePassword(user: User, newPassword: string): Promise { + return updateEmailOrPassword(user as UserInternal, null, newPassword); } async function updateEmailOrPassword( - user: User, + user: UserInternal, email: string | null, password: string | null ): Promise { diff --git a/packages-exp/auth-exp/src/core/user/additional_user_info.test.ts b/packages-exp/auth-exp/src/core/user/additional_user_info.test.ts index 898e7cf8fce..34e314bf4c1 100644 --- a/packages-exp/auth-exp/src/core/user/additional_user_info.test.ts +++ b/packages-exp/auth-exp/src/core/user/additional_user_info.test.ts @@ -26,8 +26,8 @@ import { } from './additional_user_info'; import { base64Encode } from '@firebase/util'; import { UserCredentialImpl } from './user_credential_impl'; -import { Auth } from '../../model/auth'; -import { User, UserCredential } from '../../model/user'; +import { AuthInternal } from '../../model/auth'; +import { UserInternal, UserCredentialInternal } from '../../model/user'; import { testAuth, testUser } from '../../../test/helpers/mock_auth'; import { makeJWT } from '../../../test/helpers/jwt'; @@ -228,9 +228,9 @@ describe('core/user/additional_user_info', () => { }); describe('getAdditionalUserInfo()', () => { - let auth: Auth; - let user: User; - let cred: UserCredential; + let auth: AuthInternal; + let user: UserInternal; + let cred: UserCredentialInternal; beforeEach(async () => { auth = await testAuth(); user = testUser(auth, 'uid'); diff --git a/packages-exp/auth-exp/src/core/user/additional_user_info.ts b/packages-exp/auth-exp/src/core/user/additional_user_info.ts index 2e8e4c37458..200a0ff11ae 100644 --- a/packages-exp/auth-exp/src/core/user/additional_user_info.ts +++ b/packages-exp/auth-exp/src/core/user/additional_user_info.ts @@ -15,10 +15,14 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { + AdditionalUserInfo, + ProviderId, + UserCredential +} from '../../model/public_types'; import { IdTokenResponse, IdTokenResponseKind } from '../../model/id_token'; import { _parseToken } from './id_token_result'; -import { UserCredential } from '../../model/user'; +import { UserCredentialInternal } from '../../model/user'; /** * Parse the `AdditionalUserInfo` from the ID token response. @@ -26,7 +30,7 @@ import { UserCredential } from '../../model/user'; */ export function _fromIdTokenResponse( idTokenResponse?: IdTokenResponse -): externs.AdditionalUserInfo | null { +): AdditionalUserInfo | null { if (!idTokenResponse) { return null; } @@ -43,9 +47,9 @@ export function _fromIdTokenResponse( ]; if (signInProvider) { const filteredProviderId = - signInProvider !== externs.ProviderId.ANONYMOUS && - signInProvider !== externs.ProviderId.CUSTOM - ? (signInProvider as externs.ProviderId) + signInProvider !== ProviderId.ANONYMOUS && + signInProvider !== ProviderId.CUSTOM + ? (signInProvider as ProviderId) : null; // Uses generic class in accordance with the legacy SDK. return new GenericAdditionalUserInfo(isNewUser, filteredProviderId); @@ -55,30 +59,30 @@ export function _fromIdTokenResponse( return null; } switch (providerId) { - case externs.ProviderId.FACEBOOK: + case ProviderId.FACEBOOK: return new FacebookAdditionalUserInfo(isNewUser, profile); - case externs.ProviderId.GITHUB: + case ProviderId.GITHUB: return new GithubAdditionalUserInfo(isNewUser, profile); - case externs.ProviderId.GOOGLE: + case ProviderId.GOOGLE: return new GoogleAdditionalUserInfo(isNewUser, profile); - case externs.ProviderId.TWITTER: + case ProviderId.TWITTER: return new TwitterAdditionalUserInfo( isNewUser, profile, idTokenResponse.screenName || null ); - case externs.ProviderId.CUSTOM: - case externs.ProviderId.ANONYMOUS: + case ProviderId.CUSTOM: + case ProviderId.ANONYMOUS: return new GenericAdditionalUserInfo(isNewUser, null); default: return new GenericAdditionalUserInfo(isNewUser, providerId, profile); } } -class GenericAdditionalUserInfo implements externs.AdditionalUserInfo { +class GenericAdditionalUserInfo implements AdditionalUserInfo { constructor( readonly isNewUser: boolean, - readonly providerId: externs.ProviderId | null, + readonly providerId: ProviderId | null, readonly profile: Record = {} ) {} } @@ -86,7 +90,7 @@ class GenericAdditionalUserInfo implements externs.AdditionalUserInfo { class FederatedAdditionalUserInfoWithUsername extends GenericAdditionalUserInfo { constructor( isNewUser: boolean, - providerId: externs.ProviderId, + providerId: ProviderId, profile: Record, readonly username: string | null ) { @@ -96,7 +100,7 @@ class FederatedAdditionalUserInfoWithUsername extends GenericAdditionalUserInfo class FacebookAdditionalUserInfo extends GenericAdditionalUserInfo { constructor(isNewUser: boolean, profile: Record) { - super(isNewUser, externs.ProviderId.FACEBOOK, profile); + super(isNewUser, ProviderId.FACEBOOK, profile); } } @@ -104,7 +108,7 @@ class GithubAdditionalUserInfo extends FederatedAdditionalUserInfoWithUsername { constructor(isNewUser: boolean, profile: Record) { super( isNewUser, - externs.ProviderId.GITHUB, + ProviderId.GITHUB, profile, typeof profile?.login === 'string' ? profile?.login : null ); @@ -113,7 +117,7 @@ class GithubAdditionalUserInfo extends FederatedAdditionalUserInfoWithUsername { class GoogleAdditionalUserInfo extends GenericAdditionalUserInfo { constructor(isNewUser: boolean, profile: Record) { - super(isNewUser, externs.ProviderId.GOOGLE, profile); + super(isNewUser, ProviderId.GOOGLE, profile); } } @@ -123,7 +127,7 @@ class TwitterAdditionalUserInfo extends FederatedAdditionalUserInfoWithUsername profile: Record, screenName: string | null ) { - super(isNewUser, externs.ProviderId.TWITTER, profile, screenName); + super(isNewUser, ProviderId.TWITTER, profile, screenName); } } @@ -135,9 +139,9 @@ class TwitterAdditionalUserInfo extends FederatedAdditionalUserInfoWithUsername * @public */ export function getAdditionalUserInfo( - userCredential: externs.UserCredential -): externs.AdditionalUserInfo | null { - const { user, _tokenResponse } = userCredential as UserCredential; + userCredential: UserCredential +): AdditionalUserInfo | null { + const { user, _tokenResponse } = userCredential as UserCredentialInternal; if (user.isAnonymous && !_tokenResponse) { // Handle the special case where signInAnonymously() gets called twice. // No network call is made so there's nothing to actually fill this in diff --git a/packages-exp/auth-exp/src/core/user/id_token_result.test.ts b/packages-exp/auth-exp/src/core/user/id_token_result.test.ts index 24db89c52bb..82e5f70079b 100644 --- a/packages-exp/auth-exp/src/core/user/id_token_result.test.ts +++ b/packages-exp/auth-exp/src/core/user/id_token_result.test.ts @@ -24,7 +24,7 @@ import { FirebaseError } from '@firebase/util'; import { makeJWT } from '../../../test/helpers/jwt'; import { testAuth, testUser } from '../../../test/helpers/mock_auth'; -import { User } from '../../model/user'; +import { UserInternal } from '../../model/user'; import { getIdTokenResult } from './id_token_result'; use(chaiAsPromised); @@ -34,7 +34,7 @@ const MAY_2 = new Date('May 2, 2020'); const MAY_3 = new Date('May 3, 2020'); describe('core/user/id_token_result', () => { - let user: User; + let user: UserInternal; beforeEach(async () => { user = testUser(await testAuth(), 'uid'); diff --git a/packages-exp/auth-exp/src/core/user/id_token_result.ts b/packages-exp/auth-exp/src/core/user/id_token_result.ts index 8bcf16a8a21..a6dd280036b 100644 --- a/packages-exp/auth-exp/src/core/user/id_token_result.ts +++ b/packages-exp/auth-exp/src/core/user/id_token_result.ts @@ -15,10 +15,10 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { IdTokenResult, ParsedToken, User } from '../../model/public_types'; import { base64Decode } from '@firebase/util'; -import { User } from '../../model/user'; +import { UserInternal } from '../../model/user'; import { _assert } from '../util/assert'; import { _logError } from '../util/log'; import { utcTimestampToDateString } from '../util/time'; @@ -36,10 +36,7 @@ import { AuthErrorCode } from '../errors'; * * @public */ -export function getIdToken( - user: externs.User, - forceRefresh = false -): Promise { +export function getIdToken(user: User, forceRefresh = false): Promise { return user.getIdToken(forceRefresh); } @@ -56,10 +53,10 @@ export function getIdToken( * @public */ export async function getIdTokenResult( - user: externs.User, + user: User, forceRefresh = false -): Promise { - const userInternal = user as User; +): Promise { + const userInternal = user as UserInternal; const token = await user.getIdToken(forceRefresh); const claims = _parseToken(token); @@ -94,7 +91,7 @@ function secondsStringToMilliseconds(seconds: string): number { return Number(seconds) * 1000; } -export function _parseToken(token: string): externs.ParsedToken | null { +export function _parseToken(token: string): ParsedToken | null { const [algorithm, payload, signature] = token.split('.'); if ( algorithm === undefined || diff --git a/packages-exp/auth-exp/src/core/user/invalidation.test.ts b/packages-exp/auth-exp/src/core/user/invalidation.test.ts index df56250c2c0..9d596bed448 100644 --- a/packages-exp/auth-exp/src/core/user/invalidation.test.ts +++ b/packages-exp/auth-exp/src/core/user/invalidation.test.ts @@ -21,8 +21,8 @@ import * as chaiAsPromised from 'chai-as-promised'; import { FirebaseError } from '@firebase/util'; import { testAuth, testUser } from '../../../test/helpers/mock_auth'; -import { Auth } from '../../model/auth'; -import { User } from '../../model/user'; +import { AuthInternal } from '../../model/auth'; +import { UserInternal } from '../../model/user'; import { AuthErrorCode } from '../errors'; import { _logoutIfInvalidated } from './invalidation'; import { _createError } from '../util/assert'; @@ -30,8 +30,8 @@ import { _createError } from '../util/assert'; use(chaiAsPromised); describe('core/user/invalidation', () => { - let user: User; - let auth: Auth; + let user: UserInternal; + let auth: AuthInternal; beforeEach(async () => { auth = await testAuth(); @@ -81,7 +81,7 @@ describe('core/user/invalidation', () => { }); context('with another logged in user', () => { - let user2: User; + let user2: UserInternal; beforeEach(async () => { user2 = testUser(auth, 'uid2'); diff --git a/packages-exp/auth-exp/src/core/user/invalidation.ts b/packages-exp/auth-exp/src/core/user/invalidation.ts index 0ae3c3a4eaa..718e800b2aa 100644 --- a/packages-exp/auth-exp/src/core/user/invalidation.ts +++ b/packages-exp/auth-exp/src/core/user/invalidation.ts @@ -17,11 +17,11 @@ import { FirebaseError } from '@firebase/util'; -import { User } from '../../model/user'; +import { UserInternal } from '../../model/user'; import { AuthErrorCode } from '../errors'; export async function _logoutIfInvalidated( - user: User, + user: UserInternal, promise: Promise, bypassAuthState = false ): Promise { diff --git a/packages-exp/auth-exp/src/core/user/link_unlink.test.ts b/packages-exp/auth-exp/src/core/user/link_unlink.test.ts index 5cb8eaaed2f..a2bb6d271da 100644 --- a/packages-exp/auth-exp/src/core/user/link_unlink.test.ts +++ b/packages-exp/auth-exp/src/core/user/link_unlink.test.ts @@ -26,13 +26,13 @@ import { testAuth, TestAuth, testUser } from '../../../test/helpers/mock_auth'; import * as fetch from '../../../test/helpers/mock_fetch'; import { Endpoint } from '../../api'; import { APIUserInfo } from '../../api/account_management/account'; -import { User } from '../../model/user'; +import { UserInternal } from '../../model/user'; import { _assertLinkedStatus, unlink } from './link_unlink'; use(chaiAsPromised); describe('core/user/link_unlink', () => { - let user: User; + let user: UserInternal; let auth: TestAuth; let getAccountInfoEndpoint: fetch.Route; diff --git a/packages-exp/auth-exp/src/core/user/link_unlink.ts b/packages-exp/auth-exp/src/core/user/link_unlink.ts index 4013dd7fa68..923deb26185 100644 --- a/packages-exp/auth-exp/src/core/user/link_unlink.ts +++ b/packages-exp/auth-exp/src/core/user/link_unlink.ts @@ -15,10 +15,10 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { OperationType, ProviderId, User } from '../../model/public_types'; import { deleteLinkedAccounts } from '../../api/account_management/account'; -import { User, UserCredential } from '../../model/user'; +import { UserInternal, UserCredentialInternal } from '../../model/user'; import { AuthCredential } from '../credentials'; import { AuthErrorCode } from '../errors'; import { _assert } from '../util/assert'; @@ -36,10 +36,10 @@ import { UserCredentialImpl } from './user_credential_impl'; * @public */ export async function unlink( - user: externs.User, - providerId: externs.ProviderId -): Promise { - const userInternal = user as User; + user: User, + providerId: ProviderId +): Promise { + const userInternal = user as UserInternal; await _assertLinkedStatus(true, userInternal, providerId); const { providerUserInfo } = await deleteLinkedAccounts(userInternal.auth, { idToken: await user.getIdToken(), @@ -51,7 +51,7 @@ export async function unlink( userInternal.providerData = user.providerData.filter(pd => providersLeft.has(pd.providerId) ); - if (!providersLeft.has(externs.ProviderId.PHONE)) { + if (!providersLeft.has(ProviderId.PHONE)) { userInternal.phoneNumber = null; } @@ -60,25 +60,21 @@ export async function unlink( } export async function _link( - user: User, + user: UserInternal, credential: AuthCredential, bypassAuthState = false -): Promise { +): Promise { const response = await _logoutIfInvalidated( user, credential._linkToIdToken(user.auth, await user.getIdToken()), bypassAuthState ); - return UserCredentialImpl._forOperation( - user, - externs.OperationType.LINK, - response - ); + return UserCredentialImpl._forOperation(user, OperationType.LINK, response); } export async function _assertLinkedStatus( expected: boolean, - user: User, + user: UserInternal, provider: string ): Promise { await _reloadWithoutSaving(user); diff --git a/packages-exp/auth-exp/src/core/user/proactive_refresh.test.ts b/packages-exp/auth-exp/src/core/user/proactive_refresh.test.ts index aab514f4666..abdb0f9ca8c 100644 --- a/packages-exp/auth-exp/src/core/user/proactive_refresh.test.ts +++ b/packages-exp/auth-exp/src/core/user/proactive_refresh.test.ts @@ -21,7 +21,7 @@ import * as sinon from 'sinon'; import * as sinonChai from 'sinon-chai'; import { testAuth, testUser } from '../../../test/helpers/mock_auth'; -import { User } from '../../model/user'; +import { UserInternal } from '../../model/user'; import { AuthErrorCode } from '../errors'; import { _createError } from '../util/assert'; import { Duration, ProactiveRefresh } from './proactive_refresh'; @@ -30,7 +30,7 @@ use(chaiAsPromised); use(sinonChai); describe('core/user/proactive_refresh', () => { - let user: User; + let user: UserInternal; let proactiveRefresh: ProactiveRefresh; let getTokenStub: sinon.SinonStub; let clock: sinon.SinonFakeTimers; diff --git a/packages-exp/auth-exp/src/core/user/proactive_refresh.ts b/packages-exp/auth-exp/src/core/user/proactive_refresh.ts index e26d7fa6695..1ba9a3efe2f 100644 --- a/packages-exp/auth-exp/src/core/user/proactive_refresh.ts +++ b/packages-exp/auth-exp/src/core/user/proactive_refresh.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { User } from '../../model/user'; +import { UserInternal } from '../../model/user'; import { AuthErrorCode } from '../errors'; // Refresh the token five minutes before expiration @@ -35,7 +35,7 @@ export class ProactiveRefresh { private timerId: any | null = null; private errorBackoff = Duration.RETRY_BACKOFF_MIN; - constructor(private readonly user: User) {} + constructor(private readonly user: UserInternal) {} _start(): void { if (this.isRunning) { diff --git a/packages-exp/auth-exp/src/core/user/reauthenticate.test.ts b/packages-exp/auth-exp/src/core/user/reauthenticate.test.ts index 2df2f33f50e..aaeb1423d4e 100644 --- a/packages-exp/auth-exp/src/core/user/reauthenticate.test.ts +++ b/packages-exp/auth-exp/src/core/user/reauthenticate.test.ts @@ -36,7 +36,7 @@ import { Endpoint } from '../../api'; import { IdTokenMfaResponse } from '../../api/authentication/mfa'; import { MultiFactorError } from '../../mfa/mfa_error'; import { IdTokenResponse } from '../../model/id_token'; -import { User, UserCredential } from '../../model/user'; +import { UserInternal, UserCredentialInternal } from '../../model/user'; import { AuthCredential } from '../credentials'; import { AuthErrorCode } from '../errors'; import { _reauthenticate } from './reauthenticate'; @@ -46,7 +46,7 @@ use(chaiAsPromised); describe('core/user/reauthenticate', () => { let credential: AuthCredential; - let user: User; + let user: UserInternal; beforeEach(async () => { fetch.setUp(); @@ -173,7 +173,10 @@ describe('core/user/reauthenticate', () => { users: [{ localId: 'uid' }] }); - const cred = (await _reauthenticate(user, credential)) as UserCredential; + const cred = (await _reauthenticate( + user, + credential + )) as UserCredentialInternal; expect(cred.operationType).to.eq(OperationType.REAUTHENTICATE); expect(cred._tokenResponse).to.eq(response); diff --git a/packages-exp/auth-exp/src/core/user/reauthenticate.ts b/packages-exp/auth-exp/src/core/user/reauthenticate.ts index c76920ded46..71b901a03f9 100644 --- a/packages-exp/auth-exp/src/core/user/reauthenticate.ts +++ b/packages-exp/auth-exp/src/core/user/reauthenticate.ts @@ -18,7 +18,7 @@ import { OperationType } from '../../model/public_types'; import { _processCredentialSavingMfaContextIfNecessary } from '../../mfa/mfa_error'; -import { User } from '../../model/user'; +import { UserInternal } from '../../model/user'; import { AuthCredential } from '../credentials'; import { AuthErrorCode } from '../errors'; import { _assert, _fail } from '../util/assert'; @@ -27,7 +27,7 @@ import { _logoutIfInvalidated } from './invalidation'; import { UserCredentialImpl } from './user_credential_impl'; export async function _reauthenticate( - user: User, + user: UserInternal, credential: AuthCredential, bypassAuthState = false ): Promise { diff --git a/packages-exp/auth-exp/src/core/user/reload.test.ts b/packages-exp/auth-exp/src/core/user/reload.test.ts index 4e890f1ed42..134847f3010 100644 --- a/packages-exp/auth-exp/src/core/user/reload.test.ts +++ b/packages-exp/auth-exp/src/core/user/reload.test.ts @@ -32,7 +32,7 @@ import { } from '../../api/account_management/account'; import { _reloadWithoutSaving, reload } from './reload'; import { UserMetadata } from './user_metadata'; -import { User } from '../../model/user'; +import { UserInternal } from '../../model/user'; use(chaiAsPromised); use(sinonChai); @@ -169,7 +169,7 @@ describe('core/user/reload', () => { }); context('anonymous carryover', () => { - let user: User; + let user: UserInternal; beforeEach(() => { user = testUser(auth, 'abc', '', true); }); diff --git a/packages-exp/auth-exp/src/core/user/reload.ts b/packages-exp/auth-exp/src/core/user/reload.ts index 32cc831abbc..9f8d151dac7 100644 --- a/packages-exp/auth-exp/src/core/user/reload.ts +++ b/packages-exp/auth-exp/src/core/user/reload.ts @@ -15,19 +15,19 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { User, UserInfo } from '../../model/public_types'; import { getAccountInfo, ProviderUserInfo } from '../../api/account_management/account'; -import { User } from '../../model/user'; +import { UserInternal } from '../../model/user'; import { AuthErrorCode } from '../errors'; import { _assert } from '../util/assert'; import { _logoutIfInvalidated } from './invalidation'; import { UserMetadata } from './user_metadata'; -export async function _reloadWithoutSaving(user: User): Promise { +export async function _reloadWithoutSaving(user: UserInternal): Promise { const auth = user.auth; const idToken = await user.getIdToken(); const response = await _logoutIfInvalidated( @@ -57,7 +57,7 @@ export async function _reloadWithoutSaving(user: User): Promise { !(user.email && coreAccount.passwordHash) && !providerData?.length; const isAnonymous = !oldIsAnonymous ? false : newIsAnonymous; - const updates: Partial = { + const updates: Partial = { uid: coreAccount.localId, displayName: coreAccount.displayName || null, photoURL: coreAccount.photoUrl || null, @@ -80,8 +80,8 @@ export async function _reloadWithoutSaving(user: User): Promise { * * @public */ -export async function reload(user: externs.User): Promise { - const userInternal: User = user as User; +export async function reload(user: User): Promise { + const userInternal: UserInternal = user as UserInternal; await _reloadWithoutSaving(userInternal); // Even though the current user hasn't changed, update @@ -92,18 +92,16 @@ export async function reload(user: externs.User): Promise { } function mergeProviderData( - original: externs.UserInfo[], - newData: externs.UserInfo[] -): externs.UserInfo[] { + original: UserInfo[], + newData: UserInfo[] +): UserInfo[] { const deduped = original.filter( o => !newData.some(n => n.providerId === o.providerId) ); return [...deduped, ...newData]; } -function extractProviderData( - providers: ProviderUserInfo[] -): externs.UserInfo[] { +function extractProviderData(providers: ProviderUserInfo[]): UserInfo[] { return providers.map(({ providerId, ...provider }) => { return { providerId, diff --git a/packages-exp/auth-exp/src/core/user/token_manager.ts b/packages-exp/auth-exp/src/core/user/token_manager.ts index b4ec47889d6..44f8f68b71a 100644 --- a/packages-exp/auth-exp/src/core/user/token_manager.ts +++ b/packages-exp/auth-exp/src/core/user/token_manager.ts @@ -17,7 +17,7 @@ import { FinalizeMfaResponse } from '../../api/authentication/mfa'; import { requestStsToken } from '../../api/authentication/token'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; import { IdTokenResponse } from '../../model/id_token'; import { AuthErrorCode } from '../errors'; import { PersistedBlob } from '../persistence'; @@ -67,7 +67,10 @@ export class StsTokenManager { ); } - async getToken(auth: Auth, forceRefresh = false): Promise { + async getToken( + auth: AuthInternal, + forceRefresh = false + ): Promise { _assert( !this.accessToken || this.refreshToken, auth, @@ -90,7 +93,7 @@ export class StsTokenManager { this.refreshToken = null; } - private async refresh(auth: Auth, oldToken: string): Promise { + private async refresh(auth: AuthInternal, oldToken: string): Promise { const { accessToken, refreshToken, expiresIn } = await requestStsToken( auth, oldToken diff --git a/packages-exp/auth-exp/src/core/user/user_credential_impl.test.ts b/packages-exp/auth-exp/src/core/user/user_credential_impl.test.ts index 5c8630211ec..4f864257b1c 100644 --- a/packages-exp/auth-exp/src/core/user/user_credential_impl.test.ts +++ b/packages-exp/auth-exp/src/core/user/user_credential_impl.test.ts @@ -29,7 +29,7 @@ import * as mockFetch from '../../../test/helpers/mock_fetch'; import { Endpoint } from '../../api'; import { APIUserInfo } from '../../api/account_management/account'; import { IdTokenResponse, IdTokenResponseKind } from '../../model/id_token'; -import { User } from '../../model/user'; +import { UserInternal } from '../../model/user'; import { UserCredentialImpl } from './user_credential_impl'; use(chaiAsPromised); @@ -96,7 +96,7 @@ describe('core/user/user_credential_impl', () => { }); describe('forOperation', () => { - let user: User; + let user: UserInternal; beforeEach(async () => { user = testUser(auth, 'uid', 'email', true); diff --git a/packages-exp/auth-exp/src/core/user/user_credential_impl.ts b/packages-exp/auth-exp/src/core/user/user_credential_impl.ts index 13bc5f0b01a..38ef13eafcf 100644 --- a/packages-exp/auth-exp/src/core/user/user_credential_impl.ts +++ b/packages-exp/auth-exp/src/core/user/user_credential_impl.ts @@ -15,27 +15,27 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { OperationType, ProviderId } from '../../model/public_types'; import { PhoneOrOauthTokenResponse } from '../../api/authentication/mfa'; import { IdTokenResponse } from '../../model/id_token'; -import { User, UserCredential } from '../../model/user'; +import { UserInternal, UserCredentialInternal } from '../../model/user'; import { UserImpl } from './user_impl'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; interface UserCredentialParams { - readonly user: User; - readonly providerId: externs.ProviderId | null; + readonly user: UserInternal; + readonly providerId: ProviderId | null; readonly _tokenResponse?: PhoneOrOauthTokenResponse; - readonly operationType: externs.OperationType; + readonly operationType: OperationType; } export class UserCredentialImpl - implements UserCredential, UserCredentialParams { - readonly user: User; - readonly providerId: externs.ProviderId | null; + implements UserCredentialInternal, UserCredentialParams { + readonly user: UserInternal; + readonly providerId: ProviderId | null; readonly _tokenResponse: PhoneOrOauthTokenResponse | undefined; - readonly operationType: externs.OperationType; + readonly operationType: OperationType; constructor(params: UserCredentialParams) { this.user = params.user; @@ -45,11 +45,11 @@ export class UserCredentialImpl } static async _fromIdTokenResponse( - auth: Auth, - operationType: externs.OperationType, + auth: AuthInternal, + operationType: OperationType, idTokenResponse: IdTokenResponse, isAnonymous: boolean = false - ): Promise { + ): Promise { const user = await UserImpl._fromIdTokenResponse( auth, idTokenResponse, @@ -66,8 +66,8 @@ export class UserCredentialImpl } static async _forOperation( - user: User, - operationType: externs.OperationType, + user: UserInternal, + operationType: OperationType, response: PhoneOrOauthTokenResponse ): Promise { await user._updateTokensIfNecessary(response, /* reload */ true); @@ -81,15 +81,13 @@ export class UserCredentialImpl } } -function providerIdForResponse( - response: IdTokenResponse -): externs.ProviderId | null { +function providerIdForResponse(response: IdTokenResponse): ProviderId | null { if (response.providerId) { return response.providerId; } if ('phoneNumber' in response) { - return externs.ProviderId.PHONE; + return ProviderId.PHONE; } return null; diff --git a/packages-exp/auth-exp/src/core/user/user_impl.ts b/packages-exp/auth-exp/src/core/user/user_impl.ts index 8f32f03e3dc..7483995b363 100644 --- a/packages-exp/auth-exp/src/core/user/user_impl.ts +++ b/packages-exp/auth-exp/src/core/user/user_impl.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { IdTokenResult, ProviderId } from '../../model/public_types'; import { NextFn } from '@firebase/util'; import { @@ -23,9 +23,13 @@ import { deleteAccount } from '../../api/account_management/account'; import { FinalizeMfaResponse } from '../../api/authentication/mfa'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; import { IdTokenResponse } from '../../model/id_token'; -import { MutableUserInfo, User, UserParameters } from '../../model/user'; +import { + MutableUserInfo, + UserInternal, + UserParameters +} from '../../model/user'; import { AuthErrorCode } from '../errors'; import { PersistedBlob } from '../persistence'; import { _assert } from '../util/assert'; @@ -47,15 +51,15 @@ function assertStringOrUndefined( ); } -export class UserImpl implements User { +export class UserImpl implements UserInternal { // For the user object, provider is always Firebase. - readonly providerId = externs.ProviderId.FIREBASE; + readonly providerId = ProviderId.FIREBASE; stsTokenManager: StsTokenManager; // Last known accessToken so we know when it changes private accessToken: string | null; uid: string; - auth: Auth; + auth: AuthInternal; emailVerified = false; isAnonymous = false; tenantId: string | null = null; @@ -103,7 +107,7 @@ export class UserImpl implements User { return accessToken; } - getIdTokenResult(forceRefresh?: boolean): Promise { + getIdTokenResult(forceRefresh?: boolean): Promise { return getIdTokenResult(this, forceRefresh); } @@ -114,7 +118,7 @@ export class UserImpl implements User { private reloadUserInfo: APIUserInfo | null = null; private reloadListener: NextFn | null = null; - _assign(user: User): void { + _assign(user: UserInternal): void { if (this === user) { return; } @@ -131,7 +135,7 @@ export class UserImpl implements User { this.stsTokenManager._assign(user.stsTokenManager); } - _clone(): User { + _clone(): UserInternal { return new UserImpl({ ...this, stsTokenManager: this.stsTokenManager._clone() @@ -222,7 +226,7 @@ export class UserImpl implements User { return this.stsTokenManager.refreshToken || ''; } - static _fromJSON(auth: Auth, object: PersistedBlob): User { + static _fromJSON(auth: AuthInternal, object: PersistedBlob): UserInternal { const displayName = object.displayName ?? undefined; const email = object.email ?? undefined; const phoneNumber = object.phoneNumber ?? undefined; @@ -297,10 +301,10 @@ export class UserImpl implements User { * @param idTokenResponse */ static async _fromIdTokenResponse( - auth: Auth, + auth: AuthInternal, idTokenResponse: IdTokenResponse, isAnonymous: boolean = false - ): Promise { + ): Promise { const stsTokenManager = new StsTokenManager(); stsTokenManager.updateFromServerResponse(idTokenResponse); diff --git a/packages-exp/auth-exp/src/core/user/user_metadata.ts b/packages-exp/auth-exp/src/core/user/user_metadata.ts index b71c6324999..7dccb3281ce 100644 --- a/packages-exp/auth-exp/src/core/user/user_metadata.ts +++ b/packages-exp/auth-exp/src/core/user/user_metadata.ts @@ -15,11 +15,11 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { UserMetadata as UserMetadataType } from '../../model/public_types'; import { utcTimestampToDateString } from '../util/time'; -export class UserMetadata implements externs.UserMetadata { +export class UserMetadata implements UserMetadataType { creationTime?: string; lastSignInTime?: string; diff --git a/packages-exp/auth-exp/src/core/util/assert.ts b/packages-exp/auth-exp/src/core/util/assert.ts index 1feee771918..71d755b0b6e 100644 --- a/packages-exp/auth-exp/src/core/util/assert.ts +++ b/packages-exp/auth-exp/src/core/util/assert.ts @@ -15,9 +15,9 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { Auth } from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; import { _DEFAULT_AUTH_ERROR_FACTORY, AuthErrorCode, @@ -52,12 +52,12 @@ export function _fail( : [AuthErrorParams[K]] ): never; export function _fail( - auth: externs.Auth, + auth: Auth, code: K, ...data: {} extends LessAppName ? [LessAppName?] : [LessAppName] ): never; export function _fail( - authOrCode: externs.Auth | K, + authOrCode: Auth | K, ...rest: unknown[] ): never { throw createErrorInternal(authOrCode, ...rest); @@ -70,19 +70,19 @@ export function _createError( : [AuthErrorParams[K]] ): FirebaseError; export function _createError( - auth: externs.Auth, + auth: Auth, code: K, ...data: {} extends LessAppName ? [LessAppName?] : [LessAppName] ): FirebaseError; export function _createError( - authOrCode: externs.Auth | K, + authOrCode: Auth | K, ...rest: unknown[] ): FirebaseError { return createErrorInternal(authOrCode, ...rest); } function createErrorInternal( - authOrCode: externs.Auth | K, + authOrCode: Auth | K, ...rest: unknown[] ): FirebaseError { if (typeof authOrCode !== 'string') { @@ -92,7 +92,10 @@ function createErrorInternal( fullParams[0].appName = authOrCode.name; } - return (authOrCode as Auth)._errorFactory.create(code, ...fullParams); + return (authOrCode as AuthInternal)._errorFactory.create( + code, + ...fullParams + ); } return _DEFAULT_AUTH_ERROR_FACTORY.create( @@ -110,13 +113,13 @@ export function _assert( ): asserts assertion; export function _assert( assertion: unknown, - auth: externs.Auth, + auth: Auth, code: K, ...data: {} extends LessAppName ? [LessAppName?] : [LessAppName] ): asserts assertion; export function _assert( assertion: unknown, - authOrCode: externs.Auth | K, + authOrCode: Auth | K, ...rest: unknown[] ): asserts assertion { if (!assertion) { diff --git a/packages-exp/auth-exp/src/core/util/handler.ts b/packages-exp/auth-exp/src/core/util/handler.ts index e7ce782d2d6..63cfc3b874b 100644 --- a/packages-exp/auth-exp/src/core/util/handler.ts +++ b/packages-exp/auth-exp/src/core/util/handler.ts @@ -16,8 +16,8 @@ */ import { SDK_VERSION } from '@firebase/app-exp'; -import * as externs from '../../model/public_types'; -import { ApiKey, AppName, Auth } from '../../model/auth'; +import { AuthProvider } from '../../model/public_types'; +import { ApiKey, AppName, AuthInternal } from '../../model/auth'; import { AuthEventType } from '../../model/popup_redirect'; import { AuthErrorCode } from '../errors'; import { OAuthProvider } from '../providers/oauth'; @@ -54,8 +54,8 @@ type WidgetParams = { } & { [key: string]: string | undefined }; export function _getRedirectUrl( - auth: Auth, - provider: externs.AuthProvider, + auth: AuthInternal, + provider: AuthProvider, authType: AuthEventType, redirectUrl?: string, eventId?: string, @@ -112,7 +112,7 @@ export function _getRedirectUrl( return url.toString(); } -function getHandlerBase({ config }: Auth): string { +function getHandlerBase({ config }: AuthInternal): string { if (!config.emulator) { return `https://${config.authDomain}/${WIDGET_PATH}`; } diff --git a/packages-exp/auth-exp/src/core/util/resolver.ts b/packages-exp/auth-exp/src/core/util/resolver.ts index 6c424debe5f..2e7d8422bd1 100644 --- a/packages-exp/auth-exp/src/core/util/resolver.ts +++ b/packages-exp/auth-exp/src/core/util/resolver.ts @@ -15,9 +15,9 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; -import { Auth } from '../../model/auth'; -import { PopupRedirectResolver } from '../../model/popup_redirect'; +import { PopupRedirectResolver } from '../../model/public_types'; +import { AuthInternal } from '../../model/auth'; +import { PopupRedirectResolverInternal } from '../../model/popup_redirect'; import { AuthErrorCode } from '../errors'; import { _assert } from './assert'; import { _getInstance } from './instantiator'; @@ -28,9 +28,9 @@ import { _getInstance } from './instantiator'; * object. If neither are available, this function errors w/ an argument error. */ export function _withDefaultResolver( - auth: Auth, - resolverOverride: externs.PopupRedirectResolver | undefined -): PopupRedirectResolver { + auth: AuthInternal, + resolverOverride: PopupRedirectResolver | undefined +): PopupRedirectResolverInternal { if (resolverOverride) { return _getInstance(resolverOverride); } diff --git a/packages-exp/auth-exp/src/core/util/validate_origin.test.ts b/packages-exp/auth-exp/src/core/util/validate_origin.test.ts index b87774460a2..efc3795e1a6 100644 --- a/packages-exp/auth-exp/src/core/util/validate_origin.test.ts +++ b/packages-exp/auth-exp/src/core/util/validate_origin.test.ts @@ -25,14 +25,14 @@ import { mockEndpoint } from '../../../test/helpers/api/helper'; import { testAuth } from '../../../test/helpers/mock_auth'; import * as fetch from '../../../test/helpers/mock_fetch'; import { Endpoint } from '../../api'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; import * as location from './location'; import { _validateOrigin } from './validate_origin'; use(chaiAsPromised); describe('core/util/validate_origin', () => { - let auth: Auth; + let auth: AuthInternal; let authorizedDomains: string[]; let currentUrl: string; beforeEach(async () => { diff --git a/packages-exp/auth-exp/src/core/util/validate_origin.ts b/packages-exp/auth-exp/src/core/util/validate_origin.ts index f228babfcb6..a377a49c857 100644 --- a/packages-exp/auth-exp/src/core/util/validate_origin.ts +++ b/packages-exp/auth-exp/src/core/util/validate_origin.ts @@ -16,7 +16,7 @@ */ import { _getProjectConfig } from '../../api/project_config/get_project_config'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; import { AuthErrorCode } from '../errors'; import { _fail } from './assert'; import { _getCurrentUrl } from './location'; @@ -24,7 +24,7 @@ import { _getCurrentUrl } from './location'; const IP_ADDRESS_REGEX = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/; const HTTP_REGEX = /^https?/; -export async function _validateOrigin(auth: Auth): Promise { +export async function _validateOrigin(auth: AuthInternal): Promise { // Skip origin validation if we are in an emulated environment if (auth.config.emulator) { return; diff --git a/packages-exp/auth-exp/src/mfa/mfa_assertion.ts b/packages-exp/auth-exp/src/mfa/mfa_assertion.ts index 4cbb20dc107..ea22545ac9f 100644 --- a/packages-exp/auth-exp/src/mfa/mfa_assertion.ts +++ b/packages-exp/auth-exp/src/mfa/mfa_assertion.ts @@ -14,19 +14,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import * as externs from '../model/public_types'; +import { FactorId, MultiFactorAssertion } from '../model/public_types'; import { debugFail } from '../core/util/assert'; -import { MultiFactorSession, MultiFactorSessionType } from './mfa_session'; +import { MultiFactorSessionImpl, MultiFactorSessionType } from './mfa_session'; import { FinalizeMfaResponse } from '../api/authentication/mfa'; -import { Auth } from '../model/auth'; +import { AuthInternal } from '../model/auth'; -export abstract class MultiFactorAssertion - implements externs.MultiFactorAssertion { - protected constructor(readonly factorId: externs.FactorId) {} +export abstract class MultiFactorAssertionImpl implements MultiFactorAssertion { + protected constructor(readonly factorId: FactorId) {} _process( - auth: Auth, - session: MultiFactorSession, + auth: AuthInternal, + session: MultiFactorSessionImpl, displayName?: string | null ): Promise { switch (session.type) { @@ -40,12 +39,12 @@ export abstract class MultiFactorAssertion } abstract _finalizeEnroll( - auth: Auth, + auth: AuthInternal, idToken: string, displayName?: string | null ): Promise; abstract _finalizeSignIn( - auth: Auth, + auth: AuthInternal, mfaPendingCredential: string ): Promise; } diff --git a/packages-exp/auth-exp/src/mfa/mfa_error.ts b/packages-exp/auth-exp/src/mfa/mfa_error.ts index 580d2da739e..d0af68a3bf1 100644 --- a/packages-exp/auth-exp/src/mfa/mfa_error.ts +++ b/packages-exp/auth-exp/src/mfa/mfa_error.ts @@ -15,18 +15,21 @@ * limitations under the License. */ -import * as externs from '../model/public_types'; +import { + MultiFactorError as MultiFactorErrorPublic, + OperationType +} from '../model/public_types'; import { FirebaseError } from '@firebase/util'; -import { Auth } from '../model/auth'; +import { AuthInternal } from '../model/auth'; import { IdTokenResponse } from '../model/id_token'; import { AuthErrorCode } from '../core/errors'; -import { User } from '../model/user'; +import { UserInternal } from '../model/user'; import { AuthCredential } from '../core/credentials'; import { IdTokenMfaResponse } from '../api/authentication/mfa'; export class MultiFactorError extends FirebaseError - implements externs.MultiFactorError { + implements MultiFactorErrorPublic { readonly name = 'FirebaseError'; readonly code: string; readonly appName: string; @@ -35,10 +38,10 @@ export class MultiFactorError readonly tenantId?: string; private constructor( - auth: Auth, + auth: AuthInternal, error: FirebaseError, - readonly operationType: externs.OperationType, - readonly user?: User + readonly operationType: OperationType, + readonly user?: UserInternal ) { super(error.code, error.message); // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work @@ -51,23 +54,23 @@ export class MultiFactorError } static _fromErrorAndOperation( - auth: Auth, + auth: AuthInternal, error: FirebaseError, - operationType: externs.OperationType, - user?: User + operationType: OperationType, + user?: UserInternal ): MultiFactorError { return new MultiFactorError(auth, error, operationType, user); } } export function _processCredentialSavingMfaContextIfNecessary( - auth: Auth, - operationType: externs.OperationType, + auth: AuthInternal, + operationType: OperationType, credential: AuthCredential, - user?: User + user?: UserInternal ): Promise { const idTokenProvider = - operationType === externs.OperationType.REAUTHENTICATE + operationType === OperationType.REAUTHENTICATE ? credential._getReauthenticationResolver(auth) : credential._getIdTokenResponse(auth); diff --git a/packages-exp/auth-exp/src/mfa/mfa_info.test.ts b/packages-exp/auth-exp/src/mfa/mfa_info.test.ts index cc9d9fe6562..59d292f1e18 100644 --- a/packages-exp/auth-exp/src/mfa/mfa_info.test.ts +++ b/packages-exp/auth-exp/src/mfa/mfa_info.test.ts @@ -23,7 +23,7 @@ import { FirebaseError } from '@firebase/util'; import { testAuth, TestAuth } from '../../test/helpers/mock_auth'; import { PhoneMfaEnrollment } from '../api/account_management/mfa'; -import { MultiFactorInfo } from './mfa_info'; +import { MultiFactorInfoImpl } from './mfa_info'; use(chaiAsPromised); @@ -45,7 +45,7 @@ describe('core/mfa/mfa_info/MultiFactorInfo', () => { }; it('should create a valid MfaInfo', () => { - const mfaInfo = MultiFactorInfo._fromServerResponse( + const mfaInfo = MultiFactorInfoImpl._fromServerResponse( auth, enrollmentInfo ); @@ -65,7 +65,7 @@ describe('core/mfa/mfa_info/MultiFactorInfo', () => { it('should throw an error', () => { expect(() => - MultiFactorInfo._fromServerResponse( + MultiFactorInfoImpl._fromServerResponse( auth, enrollmentInfo as PhoneMfaEnrollment ) diff --git a/packages-exp/auth-exp/src/mfa/mfa_info.ts b/packages-exp/auth-exp/src/mfa/mfa_info.ts index 679bb4dd4c7..f89bcf990b4 100644 --- a/packages-exp/auth-exp/src/mfa/mfa_info.ts +++ b/packages-exp/auth-exp/src/mfa/mfa_info.ts @@ -15,33 +15,30 @@ * limitations under the License. */ -import * as externs from '../model/public_types'; +import { FactorId, MultiFactorInfo } from '../model/public_types'; import { PhoneMfaEnrollment, MfaEnrollment } from '../api/account_management/mfa'; import { AuthErrorCode } from '../core/errors'; import { _fail } from '../core/util/assert'; -import { Auth } from '../model/auth'; +import { AuthInternal } from '../model/auth'; -export abstract class MultiFactorInfo implements externs.MultiFactorInfo { +export abstract class MultiFactorInfoImpl implements MultiFactorInfo { readonly uid: string; readonly displayName?: string | null; readonly enrollmentTime: string; - protected constructor( - readonly factorId: externs.FactorId, - response: MfaEnrollment - ) { + protected constructor(readonly factorId: FactorId, response: MfaEnrollment) { this.uid = response.mfaEnrollmentId; this.enrollmentTime = new Date(response.enrolledAt).toUTCString(); this.displayName = response.displayName; } static _fromServerResponse( - auth: Auth, + auth: AuthInternal, enrollment: MfaEnrollment - ): MultiFactorInfo { + ): MultiFactorInfoImpl { if ('phoneInfo' in enrollment) { return PhoneMultiFactorInfo._fromServerResponse(auth, enrollment); } @@ -49,16 +46,16 @@ export abstract class MultiFactorInfo implements externs.MultiFactorInfo { } } -export class PhoneMultiFactorInfo extends MultiFactorInfo { +export class PhoneMultiFactorInfo extends MultiFactorInfoImpl { readonly phoneNumber: string; private constructor(response: PhoneMfaEnrollment) { - super(externs.FactorId.PHONE, response); + super(FactorId.PHONE, response); this.phoneNumber = response.phoneInfo; } static _fromServerResponse( - _auth: Auth, + _auth: AuthInternal, enrollment: MfaEnrollment ): PhoneMultiFactorInfo { return new PhoneMultiFactorInfo(enrollment); diff --git a/packages-exp/auth-exp/src/mfa/mfa_resolver.test.ts b/packages-exp/auth-exp/src/mfa/mfa_resolver.test.ts index 472af597d75..dfd6c95583d 100644 --- a/packages-exp/auth-exp/src/mfa/mfa_resolver.test.ts +++ b/packages-exp/auth-exp/src/mfa/mfa_resolver.test.ts @@ -27,13 +27,16 @@ import { testAuth, testUser, TestAuth } from '../../test/helpers/mock_auth'; import * as mockFetch from '../../test/helpers/mock_fetch'; import { Endpoint } from '../api'; import { APIUserInfo } from '../api/account_management/account'; -import { PhoneAuthCredential } from '../core/credentials/phone'; +import { PhoneAuthCredentialImpl } from '../core/credentials/phone'; import { AuthErrorCode } from '../core/errors'; -import { User, UserCredential } from '../model/user'; -import { MultiFactorAssertion } from './mfa_assertion'; -import { PhoneMultiFactorAssertion } from '../platform_browser/mfa/assertions/phone'; +import { UserInternal, UserCredentialInternal } from '../model/user'; +import { MultiFactorAssertionImpl } from './mfa_assertion'; +import { PhoneMultiFactorAssertionImpl } from '../platform_browser/mfa/assertions/phone'; import { MultiFactorError } from './mfa_error'; -import { getMultiFactorResolver, MultiFactorResolver } from './mfa_resolver'; +import { + getMultiFactorResolver, + MultiFactorResolverImpl +} from './mfa_resolver'; import { _createError } from '../core/util/assert'; import { makeJWT } from '../../test/helpers/jwt'; use(chaiAsPromised); @@ -70,17 +73,17 @@ describe('core/mfa/mfa_resolver/MultiFactorResolver', () => { }); describe('MultiFactorResolver', () => { - let assertion: MultiFactorAssertion; - let secondFactorCredential: PhoneAuthCredential; - let resolver: MultiFactorResolver; + let assertion: MultiFactorAssertionImpl; + let secondFactorCredential: PhoneAuthCredentialImpl; + let resolver: MultiFactorResolverImpl; beforeEach(() => { mockFetch.setUp(); - secondFactorCredential = PhoneAuthCredential._fromVerification( + secondFactorCredential = PhoneAuthCredentialImpl._fromVerification( 'verification-id', 'verification-code' ); - assertion = PhoneMultiFactorAssertion._fromCredential( + assertion = PhoneMultiFactorAssertionImpl._fromCredential( secondFactorCredential ); }); @@ -127,13 +130,13 @@ describe('core/mfa/mfa_resolver/MultiFactorResolver', () => { underlyingError, OperationType.SIGN_IN ); - resolver = MultiFactorResolver._fromError(auth, error); + resolver = MultiFactorResolverImpl._fromError(auth, error); }); it('finalizes the sign in flow', async () => { const userCredential = (await resolver.resolveSignIn( assertion - )) as UserCredential; + )) as UserCredentialInternal; expect(userCredential.user.uid).to.eq('local-id'); expect(await userCredential.user.getIdToken()).to.eq(finalIdToken); expect(userCredential.user.stsTokenManager.expirationTime).to.eq( @@ -156,7 +159,7 @@ describe('core/mfa/mfa_resolver/MultiFactorResolver', () => { }); context('reauthentication', () => { - let user: User; + let user: UserInternal; beforeEach(() => { user = testUser(auth, 'local-id', undefined, true); @@ -166,13 +169,13 @@ describe('core/mfa/mfa_resolver/MultiFactorResolver', () => { OperationType.REAUTHENTICATE, user ); - resolver = MultiFactorResolver._fromError(auth, error); + resolver = MultiFactorResolverImpl._fromError(auth, error); }); it('finalizes the reauth flow', async () => { const userCredential = (await resolver.resolveSignIn( assertion - )) as UserCredential; + )) as UserCredentialInternal; expect(userCredential.user).to.eq(user); expect(await userCredential.user.getIdToken()).to.eq(finalIdToken); expect(userCredential.user.stsTokenManager.expirationTime).to.eq( @@ -212,7 +215,7 @@ describe('core/mfa/mfa_resolver/MultiFactorResolver', () => { }); context('reauthentication', () => { - let user: User; + let user: UserInternal; beforeEach(() => { user = testUser(auth, 'local-id', undefined, true); diff --git a/packages-exp/auth-exp/src/mfa/mfa_resolver.ts b/packages-exp/auth-exp/src/mfa/mfa_resolver.ts index 07a4ab15032..a33886a82e0 100644 --- a/packages-exp/auth-exp/src/mfa/mfa_resolver.ts +++ b/packages-exp/auth-exp/src/mfa/mfa_resolver.ts @@ -15,35 +15,40 @@ * limitations under the License. */ -import * as externs from '../model/public_types'; +import { + Auth, + MultiFactorResolver, + OperationType, + UserCredential +} from '../model/public_types'; import { _castAuth } from '../core/auth/auth_impl'; import { AuthErrorCode } from '../core/errors'; import { UserCredentialImpl } from '../core/user/user_credential_impl'; import { _assert, _fail } from '../core/util/assert'; -import { UserCredential } from '../model/user'; -import { MultiFactorAssertion } from './mfa_assertion'; +import { UserCredentialInternal } from '../model/user'; +import { MultiFactorAssertionImpl } from './mfa_assertion'; import { MultiFactorError } from './mfa_error'; -import { MultiFactorInfo } from './mfa_info'; -import { MultiFactorSession } from './mfa_session'; +import { MultiFactorInfoImpl } from './mfa_info'; +import { MultiFactorSessionImpl } from './mfa_session'; -export class MultiFactorResolver implements externs.MultiFactorResolver { +export class MultiFactorResolverImpl implements MultiFactorResolver { private constructor( - readonly session: MultiFactorSession, - readonly hints: MultiFactorInfo[], + readonly session: MultiFactorSessionImpl, + readonly hints: MultiFactorInfoImpl[], private readonly signInResolver: ( - assertion: MultiFactorAssertion - ) => Promise + assertion: MultiFactorAssertionImpl + ) => Promise ) {} /** @internal */ static _fromError( - authExtern: externs.Auth, + authExtern: Auth, error: MultiFactorError - ): MultiFactorResolver { + ): MultiFactorResolverImpl { const auth = _castAuth(authExtern); const hints = (error.serverResponse.mfaInfo || []).map(enrollment => - MultiFactorInfo._fromServerResponse(auth, enrollment) + MultiFactorInfoImpl._fromServerResponse(auth, enrollment) ); _assert( @@ -51,14 +56,16 @@ export class MultiFactorResolver implements externs.MultiFactorResolver { auth, AuthErrorCode.INTERNAL_ERROR ); - const session = MultiFactorSession._fromMfaPendingCredential( + const session = MultiFactorSessionImpl._fromMfaPendingCredential( error.serverResponse.mfaPendingCredential ); - return new MultiFactorResolver( + return new MultiFactorResolverImpl( session, hints, - async (assertion: MultiFactorAssertion): Promise => { + async ( + assertion: MultiFactorAssertionImpl + ): Promise => { const mfaResponse = await assertion._process(auth, session); // Clear out the unneeded fields from the old login response delete error.serverResponse.mfaInfo; @@ -73,7 +80,7 @@ export class MultiFactorResolver implements externs.MultiFactorResolver { // TODO: we should collapse this switch statement into UserCredentialImpl._forOperation and have it support the SIGN_IN case switch (error.operationType) { - case externs.OperationType.SIGN_IN: + case OperationType.SIGN_IN: const userCredential = await UserCredentialImpl._fromIdTokenResponse( auth, error.operationType, @@ -81,7 +88,7 @@ export class MultiFactorResolver implements externs.MultiFactorResolver { ); await auth._updateCurrentUser(userCredential.user); return userCredential; - case externs.OperationType.REAUTHENTICATE: + case OperationType.REAUTHENTICATE: _assert(error.user, auth, AuthErrorCode.INTERNAL_ERROR); return UserCredentialImpl._forOperation( error.user, @@ -96,9 +103,9 @@ export class MultiFactorResolver implements externs.MultiFactorResolver { } async resolveSignIn( - assertionExtern: externs.MultiFactorAssertion - ): Promise { - const assertion = assertionExtern as MultiFactorAssertion; + assertionExtern: MultiFactorAssertionImpl + ): Promise { + const assertion = assertionExtern as MultiFactorAssertionImpl; return this.signInResolver(assertion); } } @@ -114,9 +121,9 @@ export class MultiFactorResolver implements externs.MultiFactorResolver { * @public */ export function getMultiFactorResolver( - auth: externs.Auth, - error: externs.MultiFactorError -): externs.MultiFactorResolver { + auth: Auth, + error: MultiFactorError +): MultiFactorResolver { const errorInternal = error as MultiFactorError; _assert(error.operationType, auth, AuthErrorCode.ARGUMENT_ERROR); _assert( @@ -125,5 +132,5 @@ export function getMultiFactorResolver( AuthErrorCode.ARGUMENT_ERROR ); - return MultiFactorResolver._fromError(auth, errorInternal); + return MultiFactorResolverImpl._fromError(auth, errorInternal); } diff --git a/packages-exp/auth-exp/src/mfa/mfa_session.test.ts b/packages-exp/auth-exp/src/mfa/mfa_session.test.ts index fd4701399d4..ec603fd5f83 100644 --- a/packages-exp/auth-exp/src/mfa/mfa_session.test.ts +++ b/packages-exp/auth-exp/src/mfa/mfa_session.test.ts @@ -17,7 +17,7 @@ import { expect, use } from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; -import { MultiFactorSession, MultiFactorSessionType } from './mfa_session'; +import { MultiFactorSessionImpl, MultiFactorSessionType } from './mfa_session'; use(chaiAsPromised); @@ -25,7 +25,7 @@ describe('core/mfa/mfa_session/MultiFactorSession', () => { describe('toJSON', () => { context('ENROLL', () => { it('should serialize correctly', () => { - const mfaSession = MultiFactorSession._fromIdtoken('id-token'); + const mfaSession = MultiFactorSessionImpl._fromIdtoken('id-token'); expect(mfaSession.toJSON()).to.eql({ multiFactorSession: { idToken: 'id-token' } }); @@ -34,7 +34,7 @@ describe('core/mfa/mfa_session/MultiFactorSession', () => { context('SIGN_IN', () => { it('should serialize correctly', () => { - const mfaSession = MultiFactorSession._fromMfaPendingCredential( + const mfaSession = MultiFactorSessionImpl._fromMfaPendingCredential( 'mfa-pending-credential' ); expect(mfaSession.toJSON()).to.eql({ @@ -47,10 +47,10 @@ describe('core/mfa/mfa_session/MultiFactorSession', () => { describe('.fromJSON', () => { context('ENROLL', () => { it('should deserialize correctly', () => { - const mfaSession = MultiFactorSession.fromJSON({ + const mfaSession = MultiFactorSessionImpl.fromJSON({ multiFactorSession: { idToken: 'id-token' } }); - expect(mfaSession).to.be.instanceOf(MultiFactorSession); + expect(mfaSession).to.be.instanceOf(MultiFactorSessionImpl); expect(mfaSession!.type).to.eq(MultiFactorSessionType.ENROLL); expect(mfaSession!.credential).to.eq('id-token'); }); @@ -58,10 +58,10 @@ describe('core/mfa/mfa_session/MultiFactorSession', () => { context('SIGN_IN', () => { it('should deserialize correctly', () => { - const mfaSession = MultiFactorSession.fromJSON({ + const mfaSession = MultiFactorSessionImpl.fromJSON({ multiFactorSession: { pendingCredential: 'mfa-pending-credential' } }); - expect(mfaSession).to.be.instanceOf(MultiFactorSession); + expect(mfaSession).to.be.instanceOf(MultiFactorSessionImpl); expect(mfaSession!.type).to.eq(MultiFactorSessionType.SIGN_IN); expect(mfaSession!.credential).to.eq('mfa-pending-credential'); }); @@ -69,8 +69,8 @@ describe('core/mfa/mfa_session/MultiFactorSession', () => { context('invalid', () => { it('should return null', () => { - expect(MultiFactorSession.fromJSON({ multiFactorSession: {} })).to.be - .null; + expect(MultiFactorSessionImpl.fromJSON({ multiFactorSession: {} })).to + .be.null; }); }); }); diff --git a/packages-exp/auth-exp/src/mfa/mfa_session.ts b/packages-exp/auth-exp/src/mfa/mfa_session.ts index 60658bd7b88..f9b8452d06d 100644 --- a/packages-exp/auth-exp/src/mfa/mfa_session.ts +++ b/packages-exp/auth-exp/src/mfa/mfa_session.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import * as externs from '../model/public_types'; +import { MultiFactorSession } from '../model/public_types'; export const enum MultiFactorSessionType { ENROLL = 'enroll', @@ -28,20 +28,20 @@ interface SerializedMultiFactorSession { }; } -export class MultiFactorSession implements externs.MultiFactorSession { +export class MultiFactorSessionImpl implements MultiFactorSession { private constructor( readonly type: MultiFactorSessionType, readonly credential: string ) {} - static _fromIdtoken(idToken: string): MultiFactorSession { - return new MultiFactorSession(MultiFactorSessionType.ENROLL, idToken); + static _fromIdtoken(idToken: string): MultiFactorSessionImpl { + return new MultiFactorSessionImpl(MultiFactorSessionType.ENROLL, idToken); } static _fromMfaPendingCredential( mfaPendingCredential: string - ): MultiFactorSession { - return new MultiFactorSession( + ): MultiFactorSessionImpl { + return new MultiFactorSessionImpl( MultiFactorSessionType.SIGN_IN, mfaPendingCredential ); @@ -61,14 +61,16 @@ export class MultiFactorSession implements externs.MultiFactorSession { static fromJSON( obj: Partial - ): MultiFactorSession | null { + ): MultiFactorSessionImpl | null { if (obj?.multiFactorSession) { if (obj.multiFactorSession?.pendingCredential) { - return MultiFactorSession._fromMfaPendingCredential( + return MultiFactorSessionImpl._fromMfaPendingCredential( obj.multiFactorSession.pendingCredential ); } else if (obj.multiFactorSession?.idToken) { - return MultiFactorSession._fromIdtoken(obj.multiFactorSession.idToken); + return MultiFactorSessionImpl._fromIdtoken( + obj.multiFactorSession.idToken + ); } } return null; diff --git a/packages-exp/auth-exp/src/mfa/mfa_user.test.ts b/packages-exp/auth-exp/src/mfa/mfa_user.test.ts index e2e8d743767..44188171e66 100644 --- a/packages-exp/auth-exp/src/mfa/mfa_user.test.ts +++ b/packages-exp/auth-exp/src/mfa/mfa_user.test.ts @@ -28,30 +28,30 @@ import { Endpoint } from '../api'; import { APIUserInfo } from '../api/account_management/account'; import { FinalizeMfaResponse } from '../api/authentication/mfa'; import { ServerError } from '../api/errors'; -import { User } from '../model/user'; -import { MultiFactorInfo } from './mfa_info'; -import { MultiFactorSession, MultiFactorSessionType } from './mfa_session'; -import { multiFactor, MultiFactorUser } from './mfa_user'; -import { MultiFactorAssertion } from './mfa_assertion'; -import { Auth } from '../model/auth'; +import { UserInternal } from '../model/user'; +import { MultiFactorInfoImpl } from './mfa_info'; +import { MultiFactorSessionImpl, MultiFactorSessionType } from './mfa_session'; +import { multiFactor, MultiFactorUserImpl } from './mfa_user'; +import { MultiFactorAssertionImpl } from './mfa_assertion'; +import { AuthInternal } from '../model/auth'; import { makeJWT } from '../../test/helpers/jwt'; use(chaiAsPromised); -class MockMultiFactorAssertion extends MultiFactorAssertion { +class MockMultiFactorAssertion extends MultiFactorAssertionImpl { constructor(readonly response: FinalizeMfaResponse) { super(FactorId.PHONE); } async _finalizeEnroll( - _auth: Auth, + _auth: AuthInternal, _idToken: string, _displayName?: string | null ): Promise { return this.response; } async _finalizeSignIn( - _auth: Auth, + _auth: AuthInternal, _mfaPendingCredential: string ): Promise { return this.response; @@ -61,14 +61,16 @@ class MockMultiFactorAssertion extends MultiFactorAssertion { describe('core/mfa/mfa_user/MultiFactorUser', () => { const idToken = makeJWT({ 'exp': '3600', 'iat': '1200' }); let auth: TestAuth; - let mfaUser: MultiFactorUser; + let mfaUser: MultiFactorUserImpl; let clock: sinon.SinonFakeTimers; beforeEach(async () => { auth = await testAuth(); mockFetch.setUp(); clock = sinon.useFakeTimers(); - mfaUser = MultiFactorUser._fromUser(testUser(auth, 'uid', undefined, true)); + mfaUser = MultiFactorUserImpl._fromUser( + testUser(auth, 'uid', undefined, true) + ); }); afterEach(() => { @@ -78,14 +80,14 @@ describe('core/mfa/mfa_user/MultiFactorUser', () => { describe('getSession', () => { it('should return the id token', async () => { - const mfaSession = (await mfaUser.getSession()) as MultiFactorSession; + const mfaSession = (await mfaUser.getSession()) as MultiFactorSessionImpl; expect(mfaSession.type).to.eq(MultiFactorSessionType.ENROLL); expect(mfaSession.credential).to.eq('access-token'); }); }); describe('enroll', () => { - let assertion: MultiFactorAssertion; + let assertion: MultiFactorAssertionImpl; const serverUser: APIUserInfo = { localId: 'local-id', @@ -146,13 +148,13 @@ describe('core/mfa/mfa_user/MultiFactorUser', () => { refreshToken: 'refresh-token' }; - const mfaInfo = MultiFactorInfo._fromServerResponse(auth, { + const mfaInfo = MultiFactorInfoImpl._fromServerResponse(auth, { mfaEnrollmentId: 'mfa-id', enrolledAt: Date.now(), phoneInfo: 'phone-info' }); - const otherMfaInfo = MultiFactorInfo._fromServerResponse(auth, { + const otherMfaInfo = MultiFactorInfoImpl._fromServerResponse(auth, { mfaEnrollmentId: 'other-mfa-id', enrolledAt: Date.now(), phoneInfo: 'other-phone-info' @@ -238,7 +240,7 @@ describe('core/mfa/mfa_user/MultiFactorUser', () => { describe('core/mfa/mfa_user/multiFactor', () => { let auth: TestAuth; - let user: User; + let user: UserInternal; beforeEach(async () => { auth = await testAuth(); @@ -247,7 +249,7 @@ describe('core/mfa/mfa_user/multiFactor', () => { it('can be used to a create a MultiFactorUser', () => { const mfaUser = multiFactor(user); - expect((mfaUser as MultiFactorUser).user).to.eq(user); + expect((mfaUser as MultiFactorUserImpl).user).to.eq(user); }); it('should only create one instance of an MFA user per User', () => { diff --git a/packages-exp/auth-exp/src/mfa/mfa_user.ts b/packages-exp/auth-exp/src/mfa/mfa_user.ts index 4593dd2ec29..66fa8af5c5a 100644 --- a/packages-exp/auth-exp/src/mfa/mfa_user.ts +++ b/packages-exp/auth-exp/src/mfa/mfa_user.ts @@ -14,43 +14,49 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import * as externs from '../model/public_types'; +import { + MultiFactorAssertion, + MultiFactorInfo, + MultiFactorSession, + MultiFactorUser, + User +} from '../model/public_types'; import { withdrawMfa } from '../api/account_management/mfa'; import { AuthErrorCode } from '../core/errors'; import { _logoutIfInvalidated } from '../core/user/invalidation'; -import { User } from '../model/user'; -import { MultiFactorAssertion } from './mfa_assertion'; -import { MultiFactorInfo } from './mfa_info'; -import { MultiFactorSession } from './mfa_session'; +import { UserInternal } from '../model/user'; +import { MultiFactorAssertionImpl } from './mfa_assertion'; +import { MultiFactorInfoImpl } from './mfa_info'; +import { MultiFactorSessionImpl } from './mfa_session'; -export class MultiFactorUser implements externs.MultiFactorUser { - enrolledFactors: externs.MultiFactorInfo[] = []; +export class MultiFactorUserImpl implements MultiFactorUser { + enrolledFactors: MultiFactorInfo[] = []; - private constructor(readonly user: User) { + private constructor(readonly user: UserInternal) { user._onReload(userInfo => { if (userInfo.mfaInfo) { this.enrolledFactors = userInfo.mfaInfo.map(enrollment => - MultiFactorInfo._fromServerResponse(user.auth, enrollment) + MultiFactorInfoImpl._fromServerResponse(user.auth, enrollment) ); } }); } - static _fromUser(user: User): MultiFactorUser { - return new MultiFactorUser(user); + static _fromUser(user: UserInternal): MultiFactorUserImpl { + return new MultiFactorUserImpl(user); } - async getSession(): Promise { - return MultiFactorSession._fromIdtoken(await this.user.getIdToken()); + async getSession(): Promise { + return MultiFactorSessionImpl._fromIdtoken(await this.user.getIdToken()); } async enroll( - assertionExtern: externs.MultiFactorAssertion, + assertionExtern: MultiFactorAssertion, displayName?: string | null ): Promise { - const assertion = assertionExtern as MultiFactorAssertion; - const session = (await this.getSession()) as MultiFactorSession; + const assertion = assertionExtern as MultiFactorAssertionImpl; + const session = (await this.getSession()) as MultiFactorSessionImpl; const finalizeMfaResponse = await _logoutIfInvalidated( this.user, assertion._process(this.user.auth, session, displayName) @@ -64,7 +70,7 @@ export class MultiFactorUser implements externs.MultiFactorUser { return this.user.reload(); } - async unenroll(infoOrUid: externs.MultiFactorInfo | string): Promise { + async unenroll(infoOrUid: MultiFactorInfo | string): Promise { const mfaEnrollmentId = typeof infoOrUid === 'string' ? infoOrUid : infoOrUid.uid; const idToken = await this.user.getIdToken(); @@ -94,10 +100,7 @@ export class MultiFactorUser implements externs.MultiFactorUser { } } -const multiFactorUserCache = new WeakMap< - externs.User, - externs.MultiFactorUser ->(); +const multiFactorUserCache = new WeakMap(); /** * The {@link @firebase/auth-types#MultiFactorUser} corresponding to the user. @@ -109,9 +112,12 @@ const multiFactorUserCache = new WeakMap< * * @public */ -export function multiFactor(user: externs.User): externs.MultiFactorUser { +export function multiFactor(user: User): MultiFactorUser { if (!multiFactorUserCache.has(user)) { - multiFactorUserCache.set(user, MultiFactorUser._fromUser(user as User)); + multiFactorUserCache.set( + user, + MultiFactorUserImpl._fromUser(user as UserInternal) + ); } return multiFactorUserCache.get(user)!; } diff --git a/packages-exp/auth-exp/src/model/application_verifier.ts b/packages-exp/auth-exp/src/model/application_verifier.ts index a8c314df623..d23f625ee11 100644 --- a/packages-exp/auth-exp/src/model/application_verifier.ts +++ b/packages-exp/auth-exp/src/model/application_verifier.ts @@ -15,9 +15,9 @@ * limitations under the License. */ -import * as externs from './public_types'; +import { ApplicationVerifier } from './public_types'; -export interface ApplicationVerifier extends externs.ApplicationVerifier { +export interface ApplicationVerifierInternal extends ApplicationVerifier { /** * @internal */ diff --git a/packages-exp/auth-exp/src/model/auth.ts b/packages-exp/auth-exp/src/model/auth.ts index 778e8ea2de9..a88caeb742a 100644 --- a/packages-exp/auth-exp/src/model/auth.ts +++ b/packages-exp/auth-exp/src/model/auth.ts @@ -15,18 +15,27 @@ * limitations under the License. */ -import * as externs from './public_types'; +import { + Auth, + AuthErrorMap, + AuthSettings, + Config, + EmulatorConfig, + Persistence, + PopupRedirectResolver, + User +} from './public_types'; import { ErrorFactory } from '@firebase/util'; import { AuthErrorCode, AuthErrorParams } from '../core/errors'; -import { PopupRedirectResolver } from './popup_redirect'; -import { User } from './user'; +import { PopupRedirectResolverInternal } from './popup_redirect'; +import { UserInternal } from './user'; export type AppName = string; export type ApiKey = string; export type AuthDomain = string; -export interface ConfigInternal extends externs.Config { +export interface ConfigInternal extends Config { /** * @readonly */ @@ -35,24 +44,24 @@ export interface ConfigInternal extends externs.Config { }; } -export interface Auth extends externs.Auth { - currentUser: externs.User | null; - emulatorConfig: externs.EmulatorConfig | null; +export interface AuthInternal extends Auth { + currentUser: User | null; + emulatorConfig: EmulatorConfig | null; _canInitEmulator: boolean; _isInitialized: boolean; _initializationPromise: Promise | null; - _updateCurrentUser(user: User | null): Promise; + _updateCurrentUser(user: UserInternal | null): Promise; _onStorageEvent(): void; - _notifyListenersIfCurrent(user: User): void; - _persistUserIfCurrent(user: User): Promise; + _notifyListenersIfCurrent(user: UserInternal): void; + _persistUserIfCurrent(user: UserInternal): Promise; _setRedirectUser( - user: User | null, - popupRedirectResolver?: externs.PopupRedirectResolver + user: UserInternal | null, + popupRedirectResolver?: PopupRedirectResolver ): Promise; - _redirectUserForId(id: string): Promise; - _popupRedirectResolver: PopupRedirectResolver | null; + _redirectUserForId(id: string): Promise; + _popupRedirectResolver: PopupRedirectResolverInternal | null; _key(): string; _startProactiveRefresh(): void; _stopProactiveRefresh(): void; @@ -62,7 +71,7 @@ export interface Auth extends externs.Auth { readonly config: ConfigInternal; languageCode: string | null; tenantId: string | null; - readonly settings: externs.AuthSettings; + readonly settings: AuthSettings; _errorFactory: ErrorFactory; useDeviceLanguage(): void; @@ -70,7 +79,7 @@ export interface Auth extends externs.Auth { } export interface Dependencies { - persistence?: externs.Persistence | externs.Persistence[]; - popupRedirectResolver?: externs.PopupRedirectResolver; - errorMap?: externs.AuthErrorMap; + persistence?: Persistence | Persistence[]; + popupRedirectResolver?: PopupRedirectResolver; + errorMap?: AuthErrorMap; } diff --git a/packages-exp/auth-exp/src/model/popup_redirect.ts b/packages-exp/auth-exp/src/model/popup_redirect.ts index bb0253678ac..02fab78bfb2 100644 --- a/packages-exp/auth-exp/src/model/popup_redirect.ts +++ b/packages-exp/auth-exp/src/model/popup_redirect.ts @@ -15,11 +15,17 @@ * limitations under the License. */ -import * as externs from './public_types'; +import { + Auth, + AuthProvider, + Persistence, + PopupRedirectResolver, + UserCredential +} from './public_types'; import { FirebaseError } from '@firebase/util'; import { AuthPopup } from '../platform_browser/util/popup'; -import { Auth } from './auth'; +import { AuthInternal } from './auth'; export const enum EventFilter { POPUP, @@ -73,30 +79,30 @@ export interface EventManager { unregisterConsumer(authEventConsumer: AuthEventConsumer): void; } -export interface PopupRedirectResolver extends externs.PopupRedirectResolver { - _initialize(auth: Auth): Promise; +export interface PopupRedirectResolverInternal extends PopupRedirectResolver { + _initialize(auth: AuthInternal): Promise; _openPopup( - auth: Auth, - provider: externs.AuthProvider, + auth: AuthInternal, + provider: AuthProvider, authType: AuthEventType, eventId?: string ): Promise; _openRedirect( - auth: Auth, - provider: externs.AuthProvider, + auth: AuthInternal, + provider: AuthProvider, authType: AuthEventType, eventId?: string ): Promise; _isIframeWebStorageSupported( - auth: Auth, + auth: AuthInternal, cb: (support: boolean) => unknown ): void; - _redirectPersistence: externs.Persistence; + _redirectPersistence: Persistence; // This is needed so that auth does not have a hard dependency on redirect _completeRedirectFn: ( - auth: externs.Auth, - resolver: externs.PopupRedirectResolver, + auth: Auth, + resolver: PopupRedirectResolver, bypassAuthState: boolean - ) => Promise; + ) => Promise; } diff --git a/packages-exp/auth-exp/src/model/user.ts b/packages-exp/auth-exp/src/model/user.ts index c243931c8b7..22deb5c06fd 100644 --- a/packages-exp/auth-exp/src/model/user.ts +++ b/packages-exp/auth-exp/src/model/user.ts @@ -15,23 +15,29 @@ * limitations under the License. */ -import * as externs from './public_types'; +import { + IdTokenResult, + ProviderId, + User, + UserCredential, + UserInfo +} from './public_types'; import { NextFn } from '@firebase/util'; import { APIUserInfo } from '../api/account_management/account'; import { FinalizeMfaResponse } from '../api/authentication/mfa'; import { PersistedBlob } from '../core/persistence'; import { StsTokenManager } from '../core/user/token_manager'; import { UserMetadata } from '../core/user/user_metadata'; -import { Auth } from './auth'; +import { AuthInternal } from './auth'; import { IdTokenResponse, TaggedWithTokenResponse } from './id_token'; export type MutableUserInfo = { - -readonly [K in keyof externs.UserInfo]: externs.UserInfo[K]; + -readonly [K in keyof UserInfo]: UserInfo[K]; }; export interface UserParameters { uid: string; - auth: Auth; + auth: AuthInternal; stsTokenManager: StsTokenManager; displayName?: string | null; @@ -46,14 +52,14 @@ export interface UserParameters { lastLoginAt?: string | null; } -export interface User extends externs.User { +export interface UserInternal extends User { displayName: string | null; email: string | null; phoneNumber: string | null; photoURL: string | null; - auth: Auth; - providerId: externs.ProviderId.FIREBASE; + auth: AuthInternal; + providerId: ProviderId.FIREBASE; refreshToken: string; emailVerified: boolean; tenantId: string | null; @@ -68,22 +74,22 @@ export interface User extends externs.User { reload?: boolean ): Promise; - _assign(user: User): void; - _clone(): User; + _assign(user: UserInternal): void; + _clone(): UserInternal; _onReload: (cb: NextFn) => void; _notifyReloadListener: NextFn; _startProactiveRefresh: () => void; _stopProactiveRefresh: () => void; getIdToken(forceRefresh?: boolean): Promise; - getIdTokenResult(forceRefresh?: boolean): Promise; + getIdTokenResult(forceRefresh?: boolean): Promise; reload(): Promise; delete(): Promise; toJSON(): PersistedBlob; } -export interface UserCredential - extends externs.UserCredential, +export interface UserCredentialInternal + extends UserCredential, TaggedWithTokenResponse { - user: User; + user: UserInternal; } diff --git a/packages-exp/auth-exp/src/platform_browser/auth.test.ts b/packages-exp/auth-exp/src/platform_browser/auth.test.ts index f3a1714aada..cfce3a4b2ca 100644 --- a/packages-exp/auth-exp/src/platform_browser/auth.test.ts +++ b/packages-exp/auth-exp/src/platform_browser/auth.test.ts @@ -21,13 +21,18 @@ import * as sinon from 'sinon'; import * as sinonChai from 'sinon-chai'; import { FirebaseApp } from '@firebase/app-exp'; -import * as externs from '../../model/public_types'; +import { + Auth, + OperationType, + Persistence, + PopupRedirectResolver +} from '../model/public_types'; import { testAuth, testUser } from '../../test/helpers/mock_auth'; import { AuthImpl, DefaultConfig } from '../core/auth/auth_impl'; import { _initializeAuthInstance } from '../core/auth/initialize'; import { AuthErrorCode } from '../core/errors'; -import { Persistence } from '../core/persistence'; +import { PersistenceInternal } from '../core/persistence'; import { browserLocalPersistence } from './persistence/local_storage'; import { browserSessionPersistence } from './persistence/session_storage'; import { inMemoryPersistence } from '../core/persistence/in_memory'; @@ -35,11 +40,11 @@ import { PersistenceUserManager } from '../core/persistence/persistence_user_man import * as reload from '../core/user/reload'; import { _getInstance } from '../core/util/instantiator'; import { _getClientVersion, ClientPlatform } from '../core/util/version'; -import { Auth } from '../model/auth'; +import { AuthInternal } from '../model/auth'; import { browserPopupRedirectResolver } from './popup_redirect'; -import { PopupRedirectResolver } from '../model/popup_redirect'; +import { PopupRedirectResolverInternal } from '../model/popup_redirect'; import { UserCredentialImpl } from '../core/user/user_credential_impl'; -import { User } from '../model/user'; +import { UserInternal } from '../model/user'; import { _createError } from '../core/util/assert'; use(sinonChai); @@ -55,8 +60,8 @@ const FAKE_APP: FirebaseApp = { }; describe('core/auth/auth_impl', () => { - let auth: Auth; - let persistenceStub: sinon.SinonStubbedInstance; + let auth: AuthInternal; + let persistenceStub: sinon.SinonStubbedInstance; beforeEach(async () => { persistenceStub = sinon.stub(_getInstance(inMemoryPersistence)); @@ -77,7 +82,9 @@ describe('core/auth/auth_impl', () => { describe('#setPersistence', () => { it('swaps underlying persistence', async () => { const newPersistence = browserLocalPersistence; - const newStub = sinon.stub(_getInstance(newPersistence)); + const newStub = sinon.stub( + _getInstance(newPersistence) + ); persistenceStub._get.returns( Promise.resolve(testUser(auth, 'test').toJSON()) ); @@ -99,7 +106,7 @@ describe('core/auth/initializeAuth', () => { describe('persistence manager creation', () => { let createManagerStub: sinon.SinonSpy; let reloadStub: sinon.SinonStub; - let oldAuth: Auth; + let oldAuth: AuthInternal; let completeRedirectFnStub: sinon.SinonStub; beforeEach(async () => { @@ -110,17 +117,19 @@ describe('core/auth/initializeAuth', () => { .returns(Promise.resolve()); completeRedirectFnStub = sinon .stub( - _getInstance(browserPopupRedirectResolver), + _getInstance( + browserPopupRedirectResolver + ), '_completeRedirectFn' ) .returns(Promise.resolve(null)); }); async function initAndWait( - persistence: externs.Persistence | externs.Persistence[], - popupRedirectResolver?: externs.PopupRedirectResolver, + persistence: Persistence | Persistence[], + popupRedirectResolver?: PopupRedirectResolver, authDomain = FAKE_APP.options.authDomain - ): Promise { + ): Promise { const auth = new AuthImpl(FAKE_APP, { apiKey: FAKE_APP.options.apiKey!, apiHost: DefaultConfig.API_HOST, @@ -149,7 +158,7 @@ describe('core/auth/initializeAuth', () => { it('pulls the user from storage', async () => { sinon - .stub(_getInstance(inMemoryPersistence), '_get') + .stub(_getInstance(inMemoryPersistence), '_get') .returns(Promise.resolve(testUser(oldAuth, 'uid').toJSON())); const auth = await initAndWait(inMemoryPersistence); expect(auth.currentUser!.uid).to.eq('uid'); @@ -170,10 +179,13 @@ describe('core/auth/initializeAuth', () => { const user = testUser(oldAuth, 'uid'); user._redirectEventId = 'event-id'; sinon - .stub(_getInstance(inMemoryPersistence), '_get') + .stub(_getInstance(inMemoryPersistence), '_get') .returns(Promise.resolve(user.toJSON())); sinon - .stub(_getInstance(browserSessionPersistence), '_get') + .stub( + _getInstance(browserSessionPersistence), + '_get' + ) .returns(Promise.resolve(user.toJSON())); await initAndWait(inMemoryPersistence); expect(reload._reloadWithoutSaving).not.to.have.been.called; @@ -181,10 +193,13 @@ describe('core/auth/initializeAuth', () => { it('reloads non-redirect users', async () => { sinon - .stub(_getInstance(inMemoryPersistence), '_get') + .stub(_getInstance(inMemoryPersistence), '_get') .returns(Promise.resolve(testUser(oldAuth, 'uid').toJSON())); sinon - .stub(_getInstance(browserSessionPersistence), '_get') + .stub( + _getInstance(browserSessionPersistence), + '_get' + ) .returns(Promise.resolve(null)); await initAndWait(inMemoryPersistence); @@ -196,10 +211,13 @@ describe('core/auth/initializeAuth', () => { user._redirectEventId = 'event-id'; sinon - .stub(_getInstance(inMemoryPersistence), '_get') + .stub(_getInstance(inMemoryPersistence), '_get') .returns(Promise.resolve(user.toJSON())); sinon - .stub(_getInstance(browserSessionPersistence), '_get') + .stub( + _getInstance(browserSessionPersistence), + '_get' + ) .returns(Promise.resolve(user.toJSON())); await initAndWait(inMemoryPersistence, browserPopupRedirectResolver); @@ -211,12 +229,15 @@ describe('core/auth/initializeAuth', () => { user._redirectEventId = 'event-id'; sinon - .stub(_getInstance(inMemoryPersistence), '_get') + .stub(_getInstance(inMemoryPersistence), '_get') .returns(Promise.resolve(user.toJSON())); user._redirectEventId = 'some-other-id'; sinon - .stub(_getInstance(browserSessionPersistence), '_get') + .stub( + _getInstance(browserSessionPersistence), + '_get' + ) .returns(Promise.resolve(user.toJSON())); await initAndWait(inMemoryPersistence, browserPopupRedirectResolver); @@ -224,7 +245,9 @@ describe('core/auth/initializeAuth', () => { }); it('Nulls out the current user if reload fails', async () => { - const stub = sinon.stub(_getInstance(inMemoryPersistence)); + const stub = sinon.stub( + _getInstance(inMemoryPersistence) + ); stub._get.returns(Promise.resolve(testUser(oldAuth, 'uid').toJSON())); stub._remove.returns(Promise.resolve()); reloadStub.returns( @@ -240,7 +263,9 @@ describe('core/auth/initializeAuth', () => { }); it('Keeps current user if reload fails with network error', async () => { - const stub = sinon.stub(_getInstance(inMemoryPersistence)); + const stub = sinon.stub( + _getInstance(inMemoryPersistence) + ); stub._get.returns(Promise.resolve(testUser(oldAuth, 'uid').toJSON())); stub._remove.returns(Promise.resolve()); reloadStub.returns( @@ -271,7 +296,7 @@ describe('core/auth/initializeAuth', () => { context('#tryRedirectSignIn', () => { it('returns null and clears the redirect user in case of error', async () => { const stub = sinon.stub( - _getInstance(browserSessionPersistence) + _getInstance(browserSessionPersistence) ); stub._remove.returns(Promise.resolve()); completeRedirectFnStub.returns(Promise.reject(new Error('no'))); @@ -290,12 +315,12 @@ describe('core/auth/initializeAuth', () => { }); it('signs in the redirect user if found', async () => { - let user: User | null = null; - completeRedirectFnStub.callsFake((auth: Auth) => { + let user: UserInternal | null = null; + completeRedirectFnStub.callsFake((auth: AuthInternal) => { user = testUser(auth, 'uid', 'redirectUser@test.com'); return Promise.resolve( new UserCredentialImpl({ - operationType: externs.OperationType.SIGN_IN, + operationType: OperationType.SIGN_IN, user, providerId: null }) diff --git a/packages-exp/auth-exp/src/platform_browser/iframe/gapi.ts b/packages-exp/auth-exp/src/platform_browser/iframe/gapi.ts index 200d2e9d97f..cc637546544 100644 --- a/packages-exp/auth-exp/src/platform_browser/iframe/gapi.ts +++ b/packages-exp/auth-exp/src/platform_browser/iframe/gapi.ts @@ -18,7 +18,7 @@ import { AuthErrorCode } from '../../core/errors'; import { _createError } from '../../core/util/assert'; import { Delay } from '../../core/util/delay'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; import { _window } from '../auth_window'; import * as js from '../load_js'; @@ -54,7 +54,7 @@ function resetUnloadedGapiModules(): void { } } -function loadGapi(auth: Auth): Promise { +function loadGapi(auth: AuthInternal): Promise { return new Promise((resolve, reject) => { // Function to run when gapi.load is ready. function loadGapiIframe(): void { @@ -113,7 +113,7 @@ function loadGapi(auth: Auth): Promise { } let cachedGApiLoader: Promise | null = null; -export function _loadGapi(auth: Auth): Promise { +export function _loadGapi(auth: AuthInternal): Promise { cachedGApiLoader = cachedGApiLoader || loadGapi(auth); return cachedGApiLoader; } diff --git a/packages-exp/auth-exp/src/platform_browser/iframe/iframe.ts b/packages-exp/auth-exp/src/platform_browser/iframe/iframe.ts index e8c819bd277..251fd92976c 100644 --- a/packages-exp/auth-exp/src/platform_browser/iframe/iframe.ts +++ b/packages-exp/auth-exp/src/platform_browser/iframe/iframe.ts @@ -22,7 +22,7 @@ import { AuthErrorCode } from '../../core/errors'; import { _assert, _createError } from '../../core/util/assert'; import { Delay } from '../../core/util/delay'; import { _emulatorUrl } from '../../core/util/emulator'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; import { _window } from '../auth_window'; import * as gapiLoader from './gapi'; @@ -39,7 +39,7 @@ const IFRAME_ATTRIBUTES = { } }; -function getIframeUrl(auth: Auth): string { +function getIframeUrl(auth: AuthInternal): string { const config = auth.config; _assert(config.authDomain, auth, AuthErrorCode.MISSING_AUTH_DOMAIN); const url = config.emulator @@ -57,7 +57,9 @@ function getIframeUrl(auth: Auth): string { return `${url}?${querystring(params).slice(1)}`; } -export async function _openIframe(auth: Auth): Promise { +export async function _openIframe( + auth: AuthInternal +): Promise { const context = await gapiLoader._loadGapi(auth); const gapi = _window().gapi; _assert(gapi, auth, AuthErrorCode.INTERNAL_ERROR); diff --git a/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.test.ts b/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.test.ts index f0a93c7710d..e93dbddacc9 100644 --- a/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.test.ts +++ b/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.test.ts @@ -24,18 +24,21 @@ import { testAuth, TestAuth } from '../../../../test/helpers/mock_auth'; import * as mockFetch from '../../../../test/helpers/mock_fetch'; import { Endpoint } from '../../../api'; import { FinalizeMfaResponse } from '../../../api/authentication/mfa'; -import { PhoneAuthCredential } from '../../../core/credentials/phone'; -import { MultiFactorSession } from '../../../mfa/mfa_session'; +import { PhoneAuthCredentialImpl } from '../../../core/credentials/phone'; +import { MultiFactorSessionImpl } from '../../../mfa/mfa_session'; import { PhoneAuthProvider } from '../../providers/phone'; -import { PhoneMultiFactorAssertion, PhoneMultiFactorGenerator } from './phone'; +import { + PhoneMultiFactorAssertionImpl, + PhoneMultiFactorGeneratorImpl +} from './phone'; use(chaiAsPromised); describe('platform_browser/mfa/phone', () => { let auth: TestAuth; - let credential: PhoneAuthCredential; - let assertion: PhoneMultiFactorAssertion; - let session: MultiFactorSession; + let credential: PhoneAuthCredentialImpl; + let assertion: PhoneMultiFactorAssertionImpl; + let session: MultiFactorSessionImpl; const serverResponse: FinalizeMfaResponse = { idToken: 'final-id-token', @@ -49,13 +52,13 @@ describe('platform_browser/mfa/phone', () => { 'verification-id', 'verification-code' ); - assertion = PhoneMultiFactorAssertion._fromCredential(credential); + assertion = PhoneMultiFactorAssertionImpl._fromCredential(credential); }); afterEach(mockFetch.tearDown); describe('enroll', () => { beforeEach(() => { - session = MultiFactorSession._fromIdtoken('enrollment-id-token'); + session = MultiFactorSessionImpl._fromIdtoken('enrollment-id-token'); }); it('should finalize the MFA enrollment', async () => { @@ -102,7 +105,7 @@ describe('platform_browser/mfa/phone', () => { describe('sign_in', () => { beforeEach(() => { - session = MultiFactorSession._fromMfaPendingCredential( + session = MultiFactorSessionImpl._fromMfaPendingCredential( 'mfa-pending-credential' ); }); @@ -128,7 +131,7 @@ describe('platform_browser/mfa/phone', () => { describe('core/mfa/phone/PhoneMultiFactorGenerator', () => { describe('.assertion', () => { - let credential: PhoneAuthCredential; + let credential: PhoneAuthCredentialImpl; beforeEach(async () => { credential = PhoneAuthProvider.credential( @@ -138,7 +141,7 @@ describe('core/mfa/phone/PhoneMultiFactorGenerator', () => { }); it('can be used to create an assertion', () => { - const assertion = PhoneMultiFactorGenerator.assertion(credential); + const assertion = PhoneMultiFactorGeneratorImpl.assertion(credential); expect(assertion.factorId).to.eq(ProviderId.PHONE); }); }); diff --git a/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.ts b/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.ts index 93cacf4bea2..bd60b8d395c 100644 --- a/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.ts +++ b/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.ts @@ -14,12 +14,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import * as externs from '../../../model/public_types'; +import { + FactorId, + PhoneAuthCredential, + PhoneMultiFactorAssertion, + PhoneMultiFactorGenerator +} from '../../../model/public_types'; -import { MultiFactorAssertion } from '../../../mfa/mfa_assertion'; -import { Auth } from '../../../model/auth'; +import { MultiFactorAssertionImpl } from '../../../mfa/mfa_assertion'; +import { AuthInternal } from '../../../model/auth'; import { finalizeEnrollPhoneMfa } from '../../../api/account_management/mfa'; -import { PhoneAuthCredential } from '../../../core/credentials/phone'; +import { PhoneAuthCredentialImpl } from '../../../core/credentials/phone'; import { finalizeSignInPhoneMfa, FinalizeMfaResponse @@ -30,23 +35,23 @@ import { * * @public */ -export class PhoneMultiFactorAssertion - extends MultiFactorAssertion - implements externs.PhoneMultiFactorAssertion { - private constructor(private readonly credential: PhoneAuthCredential) { - super(externs.FactorId.PHONE); +export class PhoneMultiFactorAssertionImpl + extends MultiFactorAssertionImpl + implements PhoneMultiFactorAssertion { + private constructor(private readonly credential: PhoneAuthCredentialImpl) { + super(FactorId.PHONE); } /** @internal */ static _fromCredential( - credential: PhoneAuthCredential - ): PhoneMultiFactorAssertion { - return new PhoneMultiFactorAssertion(credential); + credential: PhoneAuthCredentialImpl + ): PhoneMultiFactorAssertionImpl { + return new PhoneMultiFactorAssertionImpl(credential); } /** @internal */ _finalizeEnroll( - auth: Auth, + auth: AuthInternal, idToken: string, displayName?: string | null ): Promise { @@ -59,7 +64,7 @@ export class PhoneMultiFactorAssertion /** @internal */ _finalizeSignIn( - auth: Auth, + auth: AuthInternal, mfaPendingCredential: string ): Promise { return finalizeSignInPhoneMfa(auth, { @@ -73,16 +78,14 @@ export class PhoneMultiFactorAssertion * {@inheritdoc @firebase/auth-types#PhoneMultiFactorGenerator} * @public */ -export class PhoneMultiFactorGenerator - implements externs.PhoneMultiFactorGenerator { +export class PhoneMultiFactorGeneratorImpl + implements PhoneMultiFactorGenerator { private constructor() {} /** {@inheritdoc @firebase/auth-types#PhoneMultiFactorGenerator.assertion} */ - static assertion( - credential: externs.PhoneAuthCredential - ): externs.PhoneMultiFactorAssertion { - return PhoneMultiFactorAssertion._fromCredential( - credential as PhoneAuthCredential + static assertion(credential: PhoneAuthCredential): PhoneMultiFactorAssertion { + return PhoneMultiFactorAssertionImpl._fromCredential( + credential as PhoneAuthCredentialImpl ); } } diff --git a/packages-exp/auth-exp/src/platform_browser/persistence/indexed_db.test.ts b/packages-exp/auth-exp/src/platform_browser/persistence/indexed_db.test.ts index a400dc22048..93ecbc89086 100644 --- a/packages-exp/auth-exp/src/platform_browser/persistence/indexed_db.test.ts +++ b/packages-exp/auth-exp/src/platform_browser/persistence/indexed_db.test.ts @@ -20,7 +20,7 @@ import * as sinon from 'sinon'; import * as sinonChai from 'sinon-chai'; import { FakeServiceWorker } from '../../../test/helpers/fake_service_worker'; import { testAuth, testUser } from '../../../test/helpers/mock_auth'; -import { Persistence, PersistenceType } from '../../core/persistence'; +import { PersistenceInternal, PersistenceType } from '../../core/persistence'; import { SingletonInstantiator, _getInstance @@ -43,12 +43,14 @@ import { use(sinonChai); -interface TestPersistence extends Persistence { +interface TestPersistence extends PersistenceInternal { _workerInitializationPromise: Promise; } describe('platform_browser/persistence/indexed_db', () => { - const persistence: Persistence = _getInstance(indexedDBLocalPersistence); + const persistence: PersistenceInternal = _getInstance( + indexedDBLocalPersistence + ); afterEach(sinon.restore); @@ -194,9 +196,7 @@ describe('platform_browser/persistence/indexed_db', () => { sender = new Sender(serviceWorker); sinon.stub(workerUtil, '_isWorker').returns(true); sinon.stub(workerUtil, '_getWorkerGlobalScope').returns(serviceWorker); - persistence = new ((indexedDBLocalPersistence as unknown) as SingletonInstantiator< - TestPersistence - >)(); + persistence = new ((indexedDBLocalPersistence as unknown) as SingletonInstantiator)(); db = await _openDatabase(); }); @@ -270,9 +270,7 @@ describe('platform_browser/persistence/indexed_db', () => { sinon .stub(workerUtil, '_getServiceWorkerController') .returns(serviceWorker); - persistence = new ((indexedDBLocalPersistence as unknown) as SingletonInstantiator< - TestPersistence - >)(); + persistence = new ((indexedDBLocalPersistence as unknown) as SingletonInstantiator)(); }); it('should send a ping on init', async () => { diff --git a/packages-exp/auth-exp/src/platform_browser/persistence/indexed_db.ts b/packages-exp/auth-exp/src/platform_browser/persistence/indexed_db.ts index 3d8a389371c..22d8c139dd0 100644 --- a/packages-exp/auth-exp/src/platform_browser/persistence/indexed_db.ts +++ b/packages-exp/auth-exp/src/platform_browser/persistence/indexed_db.ts @@ -15,10 +15,10 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { Persistence } from '../../model/public_types'; import { PersistedBlob, - Persistence, + PersistenceInternal as InternalPersistence, PersistenceType, PersistenceValue, StorageEventListener, @@ -160,7 +160,7 @@ function deleteObject(db: IDBDatabase, key: string): Promise { export const _POLLING_INTERVAL_MS = 800; export const _TRANSACTION_RETRY_COUNT = 3; -class IndexedDBLocalPersistence implements Persistence { +class IndexedDBLocalPersistence implements InternalPersistence { static type: 'LOCAL' = 'LOCAL'; type = PersistenceType.LOCAL; @@ -441,4 +441,4 @@ class IndexedDBLocalPersistence implements Persistence { * * @public */ -export const indexedDBLocalPersistence: externs.Persistence = IndexedDBLocalPersistence; +export const indexedDBLocalPersistence: Persistence = IndexedDBLocalPersistence; diff --git a/packages-exp/auth-exp/src/platform_browser/persistence/local_storage.test.ts b/packages-exp/auth-exp/src/platform_browser/persistence/local_storage.test.ts index 4bcc2ca9be0..dd5b713eded 100644 --- a/packages-exp/auth-exp/src/platform_browser/persistence/local_storage.test.ts +++ b/packages-exp/auth-exp/src/platform_browser/persistence/local_storage.test.ts @@ -21,7 +21,7 @@ import * as sinonChai from 'sinon-chai'; import { testAuth, testUser } from '../../../test/helpers/mock_auth'; import { PersistedBlob, - Persistence, + PersistenceInternal, PersistenceType } from '../../core/persistence'; import { _getInstance } from '../../core/util/instantiator'; @@ -30,7 +30,9 @@ import { browserLocalPersistence, _POLLING_INTERVAL_MS } from './local_storage'; use(sinonChai); describe('platform_browser/persistence/local_storage', () => { - const persistence: Persistence = _getInstance(browserLocalPersistence); + const persistence: PersistenceInternal = _getInstance( + browserLocalPersistence + ); beforeEach(() => { localStorage.clear(); diff --git a/packages-exp/auth-exp/src/platform_browser/persistence/local_storage.ts b/packages-exp/auth-exp/src/platform_browser/persistence/local_storage.ts index 2c30b9880c2..9cc53e4f7e7 100644 --- a/packages-exp/auth-exp/src/platform_browser/persistence/local_storage.ts +++ b/packages-exp/auth-exp/src/platform_browser/persistence/local_storage.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { Persistence } from '../../model/public_types'; import { getUA } from '@firebase/util'; import { @@ -26,7 +26,7 @@ import { _isIE10 } from '../../core/util/browser'; import { - Persistence, + PersistenceInternal as InternalPersistence, PersistenceType, StorageEventListener } from '../../core/persistence'; @@ -45,7 +45,7 @@ const IE10_LOCAL_STORAGE_SYNC_DELAY = 10; class BrowserLocalPersistence extends BrowserPersistenceClass - implements Persistence { + implements InternalPersistence { static type: 'LOCAL' = 'LOCAL'; constructor() { @@ -247,4 +247,4 @@ class BrowserLocalPersistence * * @public */ -export const browserLocalPersistence: externs.Persistence = BrowserLocalPersistence; +export const browserLocalPersistence: Persistence = BrowserLocalPersistence; diff --git a/packages-exp/auth-exp/src/platform_browser/persistence/session_storage.test.ts b/packages-exp/auth-exp/src/platform_browser/persistence/session_storage.test.ts index 9f7e63049a3..2ea2dea6039 100644 --- a/packages-exp/auth-exp/src/platform_browser/persistence/session_storage.test.ts +++ b/packages-exp/auth-exp/src/platform_browser/persistence/session_storage.test.ts @@ -20,7 +20,7 @@ import * as sinon from 'sinon'; import { testAuth, testUser } from '../../../test/helpers/mock_auth'; import { PersistedBlob, - Persistence, + PersistenceInternal, PersistenceType } from '../../core/persistence'; import { _getInstance } from '../../core/util/instantiator'; @@ -34,7 +34,9 @@ describe('platform_browser/persistence/session_storage', () => { afterEach(() => sinon.restore()); describe('browserSessionPersistence', () => { - const persistence: Persistence = _getInstance(browserSessionPersistence); + const persistence: PersistenceInternal = _getInstance( + browserSessionPersistence + ); it('should work with persistence type', async () => { const key = 'my-super-special-persistence-type'; diff --git a/packages-exp/auth-exp/src/platform_browser/persistence/session_storage.ts b/packages-exp/auth-exp/src/platform_browser/persistence/session_storage.ts index 880ae64b1b4..c6f78e08bfd 100644 --- a/packages-exp/auth-exp/src/platform_browser/persistence/session_storage.ts +++ b/packages-exp/auth-exp/src/platform_browser/persistence/session_storage.ts @@ -15,10 +15,10 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { Persistence } from '../../model/public_types'; import { - Persistence, + PersistenceInternal as InternalPersistence, PersistenceType, StorageEventListener } from '../../core/persistence'; @@ -26,7 +26,7 @@ import { BrowserPersistenceClass } from './browser'; class BrowserSessionPersistence extends BrowserPersistenceClass - implements Persistence { + implements InternalPersistence { static type: 'SESSION' = 'SESSION'; constructor() { @@ -50,4 +50,4 @@ class BrowserSessionPersistence * * @public */ -export const browserSessionPersistence: externs.Persistence = BrowserSessionPersistence; +export const browserSessionPersistence: Persistence = BrowserSessionPersistence; diff --git a/packages-exp/auth-exp/src/platform_browser/popup_redirect.test.ts b/packages-exp/auth-exp/src/platform_browser/popup_redirect.test.ts index c8a1a89fc5e..8d2a3d00b11 100644 --- a/packages-exp/auth-exp/src/platform_browser/popup_redirect.test.ts +++ b/packages-exp/auth-exp/src/platform_browser/popup_redirect.test.ts @@ -38,7 +38,7 @@ import { AuthEvent, AuthEventType, GapiAuthEvent, - PopupRedirectResolver + PopupRedirectResolverInternal } from '../model/popup_redirect'; import * as authWindow from './auth_window'; import * as gapiLoader from './iframe/gapi'; @@ -48,14 +48,14 @@ use(chaiAsPromised); use(sinonChai); describe('platform_browser/popup_redirect', () => { - let resolver: PopupRedirectResolver; + let resolver: PopupRedirectResolverInternal; let auth: TestAuth; let onIframeMessage: (event: GapiAuthEvent) => Promise; let iframeSendStub: sinon.SinonStub; beforeEach(async () => { auth = await testAuth(); - resolver = new (browserPopupRedirectResolver as SingletonInstantiator)(); + resolver = new (browserPopupRedirectResolver as SingletonInstantiator)(); sinon.stub(validateOrigin, '_validateOrigin').returns(Promise.resolve()); iframeSendStub = sinon.stub(); diff --git a/packages-exp/auth-exp/src/platform_browser/popup_redirect.ts b/packages-exp/auth-exp/src/platform_browser/popup_redirect.ts index 62ed6e7c6f8..f6663812392 100644 --- a/packages-exp/auth-exp/src/platform_browser/popup_redirect.ts +++ b/packages-exp/auth-exp/src/platform_browser/popup_redirect.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '../model/public_types'; +import { AuthProvider, PopupRedirectResolver } from '../model/public_types'; import { AuthEventManager } from '../core/auth/auth_event_manager'; import { AuthErrorCode } from '../core/errors'; @@ -23,13 +23,13 @@ import { _assert, debugAssert, _fail } from '../core/util/assert'; import { _generateEventId } from '../core/util/event_id'; import { _getCurrentUrl } from '../core/util/location'; import { _validateOrigin } from '../core/util/validate_origin'; -import { Auth } from '../model/auth'; +import { AuthInternal } from '../model/auth'; import { AuthEventType, EventManager, GapiAuthEvent, GapiOutcome, - PopupRedirectResolver + PopupRedirectResolverInternal } from '../model/popup_redirect'; import { _setWindowLocation } from './auth_window'; import { _openIframe } from './iframe/iframe'; @@ -53,7 +53,7 @@ interface ManagerOrPromise { promise?: Promise; } -class BrowserPopupRedirectResolver implements PopupRedirectResolver { +class BrowserPopupRedirectResolver implements PopupRedirectResolverInternal { private readonly eventManagers: Record = {}; private readonly iframes: Record = {}; private readonly originValidationPromises: Record> = {}; @@ -63,8 +63,8 @@ class BrowserPopupRedirectResolver implements PopupRedirectResolver { // Wrapping in async even though we don't await anywhere in order // to make sure errors are raised as promise rejections async _openPopup( - auth: Auth, - provider: externs.AuthProvider, + auth: AuthInternal, + provider: AuthProvider, authType: AuthEventType, eventId?: string ): Promise { @@ -85,8 +85,8 @@ class BrowserPopupRedirectResolver implements PopupRedirectResolver { } async _openRedirect( - auth: Auth, - provider: externs.AuthProvider, + auth: AuthInternal, + provider: AuthProvider, authType: AuthEventType, eventId?: string ): Promise { @@ -97,7 +97,7 @@ class BrowserPopupRedirectResolver implements PopupRedirectResolver { return new Promise(() => {}); } - _initialize(auth: Auth): Promise { + _initialize(auth: AuthInternal): Promise { const key = auth._key(); if (this.eventManagers[key]) { const { manager, promise } = this.eventManagers[key]; @@ -114,7 +114,7 @@ class BrowserPopupRedirectResolver implements PopupRedirectResolver { return promise; } - private async initAndGetManager(auth: Auth): Promise { + private async initAndGetManager(auth: AuthInternal): Promise { const iframe = await _openIframe(auth); const manager = new AuthEventManager(auth); iframe.register( @@ -135,7 +135,7 @@ class BrowserPopupRedirectResolver implements PopupRedirectResolver { } _isIframeWebStorageSupported( - auth: Auth, + auth: AuthInternal, cb: (supported: boolean) => unknown ): void { const iframe = this.iframes[auth._key()]; @@ -154,7 +154,7 @@ class BrowserPopupRedirectResolver implements PopupRedirectResolver { ); } - private originValidation(auth: Auth): Promise { + private originValidation(auth: AuthInternal): Promise { const key = auth._key(); if (!this.originValidationPromises[key]) { this.originValidationPromises[key] = _validateOrigin(auth); @@ -172,4 +172,4 @@ class BrowserPopupRedirectResolver implements PopupRedirectResolver { * * @public */ -export const browserPopupRedirectResolver: externs.PopupRedirectResolver = BrowserPopupRedirectResolver; +export const browserPopupRedirectResolver: PopupRedirectResolver = BrowserPopupRedirectResolver; diff --git a/packages-exp/auth-exp/src/platform_browser/providers/phone.ts b/packages-exp/auth-exp/src/platform_browser/providers/phone.ts index 44ad3992421..f7212ac4ee0 100644 --- a/packages-exp/auth-exp/src/platform_browser/providers/phone.ts +++ b/packages-exp/auth-exp/src/platform_browser/providers/phone.ts @@ -15,13 +15,22 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { + Auth, + PhoneAuthProvider as PhoneAuthProviderType, + PhoneInfoOptions, + ProviderId, + SignInMethod, + ApplicationVerifier, + UserCredential, + AuthCredential +} from '../../model/public_types'; import { SignInWithPhoneNumberResponse } from '../../api/authentication/sms'; -import { ApplicationVerifier } from '../../model/application_verifier'; -import { Auth } from '../../model/auth'; -import { UserCredential } from '../../model/user'; -import { PhoneAuthCredential } from '../../core/credentials/phone'; +import { ApplicationVerifierInternal as ApplicationVerifierInternal } from '../../model/application_verifier'; +import { AuthInternal as AuthInternal } from '../../model/auth'; +import { UserCredentialInternal as UserCredentialInternal } from '../../model/user'; +import { PhoneAuthCredentialImpl } from '../../core/credentials/phone'; import { AuthErrorCode } from '../../core/errors'; import { _verifyPhoneNumber } from '../strategies/phone'; import { _assert, _fail } from '../../core/util/assert'; @@ -31,29 +40,29 @@ import { _castAuth } from '../../core/auth/auth_impl'; * {@inheritdoc @firebase/auth-types#PhoneAuthProvider} * @public */ -export class PhoneAuthProvider implements externs.PhoneAuthProvider { +export class PhoneAuthProvider implements PhoneAuthProviderType { /** {@inheritdoc @firebase/auth-types#PhoneAuthProvider.PROVIDER_ID} */ - static readonly PROVIDER_ID = externs.ProviderId.PHONE; + static readonly PROVIDER_ID = ProviderId.PHONE; /** {@inheritdoc @firebase/auth-types#PhoneAuthProvider.PHONE_SIGN_IN_METHOD} */ - static readonly PHONE_SIGN_IN_METHOD = externs.SignInMethod.PHONE; + static readonly PHONE_SIGN_IN_METHOD = SignInMethod.PHONE; /** {@inheritdoc @firebase/auth-types#PhoneAuthProvider.providerId} */ readonly providerId = PhoneAuthProvider.PROVIDER_ID; - private readonly auth: Auth; + private readonly auth: AuthInternal; - constructor(auth: externs.Auth) { + constructor(auth: Auth) { this.auth = _castAuth(auth); } /** {@inheritdoc @firebase/auth-types#PhoneAuthProvider.verifyPhoneNumber} */ verifyPhoneNumber( - phoneOptions: externs.PhoneInfoOptions | string, - applicationVerifier: externs.ApplicationVerifier + phoneOptions: PhoneInfoOptions | string, + applicationVerifier: ApplicationVerifier ): Promise { return _verifyPhoneNumber( this.auth, phoneOptions, - applicationVerifier as ApplicationVerifier + applicationVerifier as ApplicationVerifierInternal ); } @@ -61,17 +70,17 @@ export class PhoneAuthProvider implements externs.PhoneAuthProvider { static credential( verificationId: string, verificationCode: string - ): PhoneAuthCredential { - return PhoneAuthCredential._fromVerification( + ): PhoneAuthCredentialImpl { + return PhoneAuthCredentialImpl._fromVerification( verificationId, verificationCode ); } static credentialFromResult( - userCredential: externs.UserCredential - ): externs.AuthCredential | null { - const credential = userCredential as UserCredential; + userCredential: UserCredential + ): AuthCredential | null { + const credential = userCredential as UserCredentialInternal; _assert( credential._tokenResponse, credential.user.auth, @@ -82,7 +91,7 @@ export class PhoneAuthProvider implements externs.PhoneAuthProvider { temporaryProof } = credential._tokenResponse as SignInWithPhoneNumberResponse; if (phoneNumber && temporaryProof) { - return PhoneAuthCredential._fromTokenResponse( + return PhoneAuthCredentialImpl._fromTokenResponse( phoneNumber, temporaryProof ); diff --git a/packages-exp/auth-exp/src/platform_browser/recaptcha/recaptcha_loader.ts b/packages-exp/auth-exp/src/platform_browser/recaptcha/recaptcha_loader.ts index 97afe888579..e1d09045bdf 100644 --- a/packages-exp/auth-exp/src/platform_browser/recaptcha/recaptcha_loader.ts +++ b/packages-exp/auth-exp/src/platform_browser/recaptcha/recaptcha_loader.ts @@ -20,7 +20,7 @@ import { querystring } from '@firebase/util'; import { AuthErrorCode } from '../../core/errors'; import { _assert, _createError } from '../../core/util/assert'; import { Delay } from '../../core/util/delay'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; import { _window } from '../auth_window'; import * as jsHelpers from '../load_js'; import { Recaptcha } from './recaptcha'; @@ -33,7 +33,7 @@ const NETWORK_TIMEOUT_DELAY = new Delay(30000, 60000); const RECAPTCHA_BASE = 'https://www.google.com/recaptcha/api.js?'; export interface ReCaptchaLoader { - load(auth: Auth, hl?: string): Promise; + load(auth: AuthInternal, hl?: string): Promise; clearedOneInstance(): void; } @@ -45,7 +45,7 @@ export class ReCaptchaLoaderImpl implements ReCaptchaLoader { private counter = 0; private readonly librarySeparatelyLoaded = !!_window().grecaptcha; - load(auth: Auth, hl = ''): Promise { + load(auth: AuthInternal, hl = ''): Promise { _assert(isHostLanguageValid(hl), auth, AuthErrorCode.ARGUMENT_ERROR); if (this.shouldResolveImmediately(hl)) { @@ -119,7 +119,7 @@ function isHostLanguageValid(hl: string): boolean { } export class MockReCaptchaLoaderImpl implements ReCaptchaLoader { - async load(auth: Auth): Promise { + async load(auth: AuthInternal): Promise { return new MockReCaptcha(auth); } diff --git a/packages-exp/auth-exp/src/platform_browser/recaptcha/recaptcha_mock.ts b/packages-exp/auth-exp/src/platform_browser/recaptcha/recaptcha_mock.ts index 2f78e9509a9..8839d511014 100644 --- a/packages-exp/auth-exp/src/platform_browser/recaptcha/recaptcha_mock.ts +++ b/packages-exp/auth-exp/src/platform_browser/recaptcha/recaptcha_mock.ts @@ -17,7 +17,7 @@ import { AuthErrorCode } from '../../core/errors'; import { _assert } from '../../core/util/assert'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; import { Parameters, Recaptcha } from './recaptcha'; export const _SOLVE_TIME_MS = 500; @@ -34,7 +34,7 @@ export class MockReCaptcha implements Recaptcha { private counter = _WIDGET_ID_START; _widgets = new Map(); - constructor(private readonly auth: Auth) {} + constructor(private readonly auth: AuthInternal) {} render(container: string | HTMLElement, parameters?: Parameters): number { const id = this.counter; diff --git a/packages-exp/auth-exp/src/platform_browser/recaptcha/recaptcha_verifier.ts b/packages-exp/auth-exp/src/platform_browser/recaptcha/recaptcha_verifier.ts index da8c0545c5c..74ba21d5bd9 100644 --- a/packages-exp/auth-exp/src/platform_browser/recaptcha/recaptcha_verifier.ts +++ b/packages-exp/auth-exp/src/platform_browser/recaptcha/recaptcha_verifier.ts @@ -15,14 +15,17 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { + Auth, + RecaptchaVerifier as RecaptchaVerifierType +} from '../../model/public_types'; import { getRecaptchaParams } from '../../api/authentication/recaptcha'; import { _castAuth } from '../../core/auth/auth_impl'; import { AuthErrorCode } from '../../core/errors'; import { _assert } from '../../core/util/assert'; import { _isHttpOrHttps } from '../../core/util/location'; -import { ApplicationVerifier } from '../../model/application_verifier'; -import { Auth } from '../../model/auth'; +import { ApplicationVerifierInternal } from '../../model/application_verifier'; +import { AuthInternal } from '../../model/auth'; import { _window } from '../auth_window'; import { _isWorker } from '../util/worker'; import { Parameters, Recaptcha } from './recaptcha'; @@ -46,7 +49,7 @@ type TokenCallback = (token: string) => void; * @public */ export class RecaptchaVerifier - implements externs.RecaptchaVerifier, ApplicationVerifier { + implements RecaptchaVerifierType, ApplicationVerifierInternal { readonly type = RECAPTCHA_VERIFIER_TYPE; private destroyed = false; private widgetId: number | null = null; @@ -54,7 +57,7 @@ export class RecaptchaVerifier private readonly isInvisible: boolean; private readonly tokenChangeListeners = new Set(); private renderPromise: Promise | null = null; - private readonly auth: Auth; + private readonly auth: AuthInternal; /** @internal */ readonly _recaptchaLoader: ReCaptchaLoader; @@ -65,7 +68,7 @@ export class RecaptchaVerifier private readonly parameters: Parameters = { ...DEFAULT_PARAMS }, - authExtern: externs.Auth + authExtern: Auth ) { this.auth = _castAuth(authExtern); this.isInvisible = this.parameters.size === 'invisible'; diff --git a/packages-exp/auth-exp/src/platform_browser/strategies/phone.test.ts b/packages-exp/auth-exp/src/platform_browser/strategies/phone.test.ts index 583ab35872e..3b7928f44e6 100644 --- a/packages-exp/auth-exp/src/platform_browser/strategies/phone.test.ts +++ b/packages-exp/auth-exp/src/platform_browser/strategies/phone.test.ts @@ -28,14 +28,14 @@ import { makeJWT } from '../../../test/helpers/jwt'; import { testAuth, testUser, TestAuth } from '../../../test/helpers/mock_auth'; import * as fetch from '../../../test/helpers/mock_fetch'; import { Endpoint } from '../../api'; -import { MultiFactorInfo } from '../../mfa/mfa_info'; -import { MultiFactorSession } from '../../mfa/mfa_session'; -import { multiFactor, MultiFactorUser } from '../../mfa/mfa_user'; -import { ApplicationVerifier } from '../../model/application_verifier'; +import { MultiFactorInfoImpl } from '../../mfa/mfa_info'; +import { MultiFactorSessionImpl } from '../../mfa/mfa_session'; +import { multiFactor, MultiFactorUserImpl } from '../../mfa/mfa_user'; +import { ApplicationVerifierInternal } from '../../model/application_verifier'; import { IdTokenResponse, IdTokenResponseKind } from '../../model/id_token'; -import { User } from '../../model/user'; +import { UserInternal } from '../../model/user'; import { RecaptchaVerifier } from '../../platform_browser/recaptcha/recaptcha_verifier'; -import { PhoneAuthCredential } from '../../core/credentials/phone'; +import { PhoneAuthCredentialImpl } from '../../core/credentials/phone'; import { _verifyPhoneNumber, linkWithPhoneNumber, @@ -49,7 +49,7 @@ use(sinonChai); describe('platform_browser/strategies/phone', () => { let auth: TestAuth; - let verifier: ApplicationVerifier; + let verifier: ApplicationVerifierInternal; let sendCodeEndpoint: fetch.Route; beforeEach(async () => { @@ -118,7 +118,7 @@ describe('platform_browser/strategies/phone', () => { describe('linkWithPhoneNumber', () => { let getAccountInfoEndpoint: fetch.Route; - let user: User; + let user: UserInternal; beforeEach(() => { getAccountInfoEndpoint = mockEndpoint(Endpoint.GET_ACCOUNT_INFO, { @@ -196,7 +196,7 @@ describe('platform_browser/strategies/phone', () => { }); describe('reauthenticateWithPhoneNumber', () => { - let user: User; + let user: UserInternal; beforeEach(() => { mockEndpoint(Endpoint.GET_ACCOUNT_INFO, { @@ -310,8 +310,8 @@ describe('platform_browser/strategies/phone', () => { }); context('MFA', () => { - let user: User; - let mfaUser: MultiFactorUser; + let user: UserInternal; + let mfaUser: MultiFactorUserImpl; beforeEach(() => { mockEndpoint(Endpoint.GET_ACCOUNT_INFO, { @@ -319,7 +319,7 @@ describe('platform_browser/strategies/phone', () => { }); user = testUser(auth, 'uid', 'email', true); - mfaUser = multiFactor(user) as MultiFactorUser; + mfaUser = multiFactor(user) as MultiFactorUserImpl; }); it('works with an enrollment flow', async () => { @@ -328,7 +328,7 @@ describe('platform_browser/strategies/phone', () => { sessionInfo: 'session-info' } }); - const session = (await mfaUser.getSession()) as MultiFactorSession; + const session = (await mfaUser.getSession()) as MultiFactorSessionImpl; const sessionInfo = await _verifyPhoneNumber( auth, { phoneNumber: 'number', session }, @@ -351,10 +351,10 @@ describe('platform_browser/strategies/phone', () => { sessionInfo: 'session-info' } }); - const session = MultiFactorSession._fromMfaPendingCredential( + const session = MultiFactorSessionImpl._fromMfaPendingCredential( 'mfa-pending-credential' ); - const mfaInfo = MultiFactorInfo._fromServerResponse(auth, { + const mfaInfo = MultiFactorInfoImpl._fromServerResponse(auth, { mfaEnrollmentId: 'mfa-enrollment-id', enrolledAt: Date.now(), phoneInfo: 'phone-number-from-enrollment' @@ -388,7 +388,7 @@ describe('platform_browser/strategies/phone', () => { it('throws if the verifier type is not recaptcha', async () => { const mutVerifier: { - -readonly [K in keyof ApplicationVerifier]: ApplicationVerifier[K]; + -readonly [K in keyof ApplicationVerifierInternal]: ApplicationVerifierInternal[K]; } = verifier; mutVerifier.type = 'not-recaptcha-thats-for-sure'; await expect( @@ -414,10 +414,10 @@ describe('platform_browser/strategies/phone', () => { }); describe('updatePhoneNumber', () => { - let user: User; + let user: UserInternal; let reloadMock: fetch.Route; let signInMock: fetch.Route; - let credential: PhoneAuthCredential; + let credential: PhoneAuthCredentialImpl; let idToken: string; beforeEach(() => { @@ -429,7 +429,7 @@ describe('platform_browser/strategies/phone', () => { idToken, refreshToken: 'refresh-token' }); - credential = PhoneAuthCredential._fromVerification( + credential = PhoneAuthCredentialImpl._fromVerification( 'session-info', 'code' ); diff --git a/packages-exp/auth-exp/src/platform_browser/strategies/phone.ts b/packages-exp/auth-exp/src/platform_browser/strategies/phone.ts index 89e3858e79c..5137058bfbb 100644 --- a/packages-exp/auth-exp/src/platform_browser/strategies/phone.ts +++ b/packages-exp/auth-exp/src/platform_browser/strategies/phone.ts @@ -15,42 +15,51 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { + ApplicationVerifier, + Auth, + ConfirmationResult, + PhoneAuthCredential, + PhoneInfoOptions, + ProviderId, + User, + UserCredential +} from '../../model/public_types'; import { startEnrollPhoneMfa } from '../../api/account_management/mfa'; import { startSignInPhoneMfa } from '../../api/authentication/mfa'; import { sendPhoneVerificationCode } from '../../api/authentication/sms'; -import { ApplicationVerifier } from '../../model/application_verifier'; -import { PhoneAuthCredential } from '../../core/credentials/phone'; +import { ApplicationVerifierInternal } from '../../model/application_verifier'; +import { PhoneAuthCredentialImpl } from '../../core/credentials/phone'; import { AuthErrorCode } from '../../core/errors'; import { _assertLinkedStatus, _link } from '../../core/user/link_unlink'; import { _assert } from '../../core/util/assert'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; import { linkWithCredential, reauthenticateWithCredential, signInWithCredential } from '../../core/strategies/credential'; import { - MultiFactorSession, + MultiFactorSessionImpl, MultiFactorSessionType } from '../../mfa/mfa_session'; -import { User } from '../../model/user'; +import { UserInternal } from '../../model/user'; import { RECAPTCHA_VERIFIER_TYPE } from '../recaptcha/recaptcha_verifier'; import { _castAuth } from '../../core/auth/auth_impl'; interface OnConfirmationCallback { - (credential: PhoneAuthCredential): Promise; + (credential: PhoneAuthCredentialImpl): Promise; } -class ConfirmationResult implements externs.ConfirmationResult { +class ConfirmationResultImpl implements ConfirmationResult { constructor( readonly verificationId: string, private readonly onConfirmation: OnConfirmationCallback ) {} - confirm(verificationCode: string): Promise { - const authCredential = PhoneAuthCredential._fromVerification( + confirm(verificationCode: string): Promise { + const authCredential = PhoneAuthCredentialImpl._fromVerification( this.verificationId, verificationCode ); @@ -86,16 +95,16 @@ class ConfirmationResult implements externs.ConfirmationResult { * @public */ export async function signInWithPhoneNumber( - auth: externs.Auth, + auth: Auth, phoneNumber: string, - appVerifier: externs.ApplicationVerifier -): Promise { + appVerifier: ApplicationVerifier +): Promise { const verificationId = await _verifyPhoneNumber( _castAuth(auth), phoneNumber, - appVerifier as ApplicationVerifier + appVerifier as ApplicationVerifierInternal ); - return new ConfirmationResult(verificationId, cred => + return new ConfirmationResultImpl(verificationId, cred => signInWithCredential(auth, cred) ); } @@ -110,18 +119,18 @@ export async function signInWithPhoneNumber( * @public */ export async function linkWithPhoneNumber( - user: externs.User, + user: User, phoneNumber: string, - appVerifier: externs.ApplicationVerifier -): Promise { - const userInternal = user as User; - await _assertLinkedStatus(false, userInternal, externs.ProviderId.PHONE); + appVerifier: ApplicationVerifier +): Promise { + const userInternal = user as UserInternal; + await _assertLinkedStatus(false, userInternal, ProviderId.PHONE); const verificationId = await _verifyPhoneNumber( userInternal.auth, phoneNumber, - appVerifier as ApplicationVerifier + appVerifier as ApplicationVerifierInternal ); - return new ConfirmationResult(verificationId, cred => + return new ConfirmationResultImpl(verificationId, cred => linkWithCredential(user, cred) ); } @@ -138,17 +147,17 @@ export async function linkWithPhoneNumber( * @public */ export async function reauthenticateWithPhoneNumber( - user: externs.User, + user: User, phoneNumber: string, - appVerifier: externs.ApplicationVerifier -): Promise { - const userInternal = user as User; + appVerifier: ApplicationVerifier +): Promise { + const userInternal = user as UserInternal; const verificationId = await _verifyPhoneNumber( userInternal.auth, phoneNumber, - appVerifier as ApplicationVerifier + appVerifier as ApplicationVerifierInternal ); - return new ConfirmationResult(verificationId, cred => + return new ConfirmationResultImpl(verificationId, cred => reauthenticateWithCredential(user, cred) ); } @@ -158,9 +167,9 @@ export async function reauthenticateWithPhoneNumber( * */ export async function _verifyPhoneNumber( - auth: Auth, - options: externs.PhoneInfoOptions | string, - verifier: ApplicationVerifier + auth: AuthInternal, + options: PhoneInfoOptions | string, + verifier: ApplicationVerifierInternal ): Promise { const recaptchaToken = await verifier.verify(); @@ -176,7 +185,7 @@ export async function _verifyPhoneNumber( AuthErrorCode.ARGUMENT_ERROR ); - let phoneInfoOptions: externs.PhoneInfoOptions; + let phoneInfoOptions: PhoneInfoOptions; if (typeof options === 'string') { phoneInfoOptions = { @@ -187,7 +196,7 @@ export async function _verifyPhoneNumber( } if ('session' in phoneInfoOptions) { - const session = phoneInfoOptions.session as MultiFactorSession; + const session = phoneInfoOptions.session as MultiFactorSessionImpl; if ('phoneNumber' in phoneInfoOptions) { _assert( @@ -254,8 +263,8 @@ export async function _verifyPhoneNumber( * @public */ export async function updatePhoneNumber( - user: externs.User, - credential: externs.PhoneAuthCredential + user: User, + credential: PhoneAuthCredential ): Promise { - await _link(user as User, credential as PhoneAuthCredential); + await _link(user as UserInternal, credential as PhoneAuthCredentialImpl); } diff --git a/packages-exp/auth-exp/src/platform_browser/strategies/popup.test.ts b/packages-exp/auth-exp/src/platform_browser/strategies/popup.test.ts index 4d3fc55d882..1954d0844f7 100644 --- a/packages-exp/auth-exp/src/platform_browser/strategies/popup.test.ts +++ b/packages-exp/auth-exp/src/platform_browser/strategies/popup.test.ts @@ -33,7 +33,7 @@ import { testAuth, testUser, TestAuth } from '../../../test/helpers/mock_auth'; import { makeMockPopupRedirectResolver } from '../../../test/helpers/mock_popup_redirect_resolver'; import { stubTimeouts, TimerMap } from '../../../test/helpers/timeout_stub'; import { AuthEvent, AuthEventType } from '../../model/popup_redirect'; -import { User } from '../../model/user'; +import { UserInternal } from '../../model/user'; import { AuthEventManager } from '../../core/auth/auth_event_manager'; import { AuthErrorCode } from '../../core/errors'; import { OAuthProvider } from '../../core/providers/oauth'; @@ -271,7 +271,7 @@ describe('platform_browser/strategies/popup', () => { }); context('linkWithPopup', () => { - let user: User; + let user: UserInternal; beforeEach(() => { user = testUser(auth, 'uid'); }); @@ -452,7 +452,7 @@ describe('platform_browser/strategies/popup', () => { }); context('reauthenticateWithPopup', () => { - let user: User; + let user: UserInternal; beforeEach(() => { user = testUser(auth, 'uid'); }); diff --git a/packages-exp/auth-exp/src/platform_browser/strategies/popup.ts b/packages-exp/auth-exp/src/platform_browser/strategies/popup.ts index 2003780d3b7..5cff26b1cd2 100644 --- a/packages-exp/auth-exp/src/platform_browser/strategies/popup.ts +++ b/packages-exp/auth-exp/src/platform_browser/strategies/popup.ts @@ -15,7 +15,13 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { + Auth, + AuthProvider, + PopupRedirectResolver, + User, + UserCredential +} from '../../model/public_types'; import { _castAuth } from '../../core/auth/auth_impl'; import { AuthErrorCode } from '../../core/errors'; @@ -23,12 +29,12 @@ import { OAuthProvider } from '../../core/providers/oauth'; import { _assert, debugAssert, _createError } from '../../core/util/assert'; import { Delay } from '../../core/util/delay'; import { _generateEventId } from '../../core/util/event_id'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; import { AuthEventType, - PopupRedirectResolver + PopupRedirectResolverInternal } from '../../model/popup_redirect'; -import { User } from '../../model/user'; +import { UserInternal } from '../../model/user'; import { _withDefaultResolver } from '../../core/util/resolver'; import { AuthPopup } from '../util/popup'; import { AbstractPopupRedirectOperation } from '../../core/strategies/abstract_popup_redirect_operation'; @@ -71,10 +77,10 @@ export const _POLL_WINDOW_CLOSE_TIMEOUT = new Delay(2000, 10000); * @public */ export async function signInWithPopup( - auth: externs.Auth, - provider: externs.AuthProvider, - resolver?: externs.PopupRedirectResolver -): Promise { + auth: Auth, + provider: AuthProvider, + resolver?: PopupRedirectResolver +): Promise { const authInternal = _castAuth(auth); _assert( provider instanceof OAuthProvider, @@ -118,11 +124,11 @@ export async function signInWithPopup( * @public */ export async function reauthenticateWithPopup( - user: externs.User, - provider: externs.AuthProvider, - resolver?: externs.PopupRedirectResolver -): Promise { - const userInternal = user as User; + user: User, + provider: AuthProvider, + resolver?: PopupRedirectResolver +): Promise { + const userInternal = user as UserInternal; _assert( provider instanceof OAuthProvider, userInternal.auth, @@ -165,11 +171,11 @@ export async function reauthenticateWithPopup( * @public */ export async function linkWithPopup( - user: externs.User, - provider: externs.AuthProvider, - resolver?: externs.PopupRedirectResolver -): Promise { - const userInternal = user as User; + user: User, + provider: AuthProvider, + resolver?: PopupRedirectResolver +): Promise { + const userInternal = user as UserInternal; _assert( provider instanceof OAuthProvider, userInternal.auth, @@ -201,11 +207,11 @@ class PopupOperation extends AbstractPopupRedirectOperation { private pollId: number | null = null; constructor( - auth: Auth, + auth: AuthInternal, filter: AuthEventType, - private readonly provider: externs.AuthProvider, - resolver: PopupRedirectResolver, - user?: User + private readonly provider: AuthProvider, + resolver: PopupRedirectResolverInternal, + user?: UserInternal ) { super(auth, filter, resolver, user); if (PopupOperation.currentPopupAction) { @@ -215,7 +221,7 @@ class PopupOperation extends AbstractPopupRedirectOperation { PopupOperation.currentPopupAction = this; } - async executeNotNull(): Promise { + async executeNotNull(): Promise { const result = await this.execute(); _assert(result, this.auth, AuthErrorCode.INTERNAL_ERROR); return result; diff --git a/packages-exp/auth-exp/src/platform_browser/strategies/redirect.test.ts b/packages-exp/auth-exp/src/platform_browser/strategies/redirect.test.ts index 4c88d9f6305..40d2a83cf7b 100644 --- a/packages-exp/auth-exp/src/platform_browser/strategies/redirect.test.ts +++ b/packages-exp/auth-exp/src/platform_browser/strategies/redirect.test.ts @@ -20,7 +20,12 @@ import * as chaiAsPromised from 'chai-as-promised'; import * as sinon from 'sinon'; import * as sinonChai from 'sinon-chai'; -import * as externs from '../../model/public_types'; +import { + AuthError, + OperationType, + PopupRedirectResolver, + ProviderId +} from '../../model/public_types'; import { delay } from '../../../test/helpers/delay'; import { BASE_AUTH_EVENT } from '../../../test/helpers/iframe_event'; @@ -34,12 +39,12 @@ import { makeMockPopupRedirectResolver } from '../../../test/helpers/mock_popup_ import { AuthEvent, AuthEventType, - PopupRedirectResolver + PopupRedirectResolverInternal } from '../../model/popup_redirect'; -import { User } from '../../model/user'; +import { UserInternal } from '../../model/user'; import { AuthEventManager } from '../../core/auth/auth_event_manager'; import { AuthErrorCode } from '../../core/errors'; -import { Persistence } from '../../core/persistence'; +import { PersistenceInternal } from '../../core/persistence'; import { InMemoryPersistence } from '../../core/persistence/in_memory'; import { OAuthProvider } from '../../core/providers/oauth'; import * as link from '../../core/user/link_unlink'; @@ -68,14 +73,14 @@ describe('platform_browser/strategies/redirect', () => { let auth: TestAuth; let eventManager: AuthEventManager; let provider: OAuthProvider; - let resolver: externs.PopupRedirectResolver; + let resolver: PopupRedirectResolver; let idpStubs: sinon.SinonStubbedInstance; beforeEach(async () => { eventManager = new AuthEventManager(({} as unknown) as TestAuth); - provider = new OAuthProvider(externs.ProviderId.GOOGLE); + provider = new OAuthProvider(ProviderId.GOOGLE); resolver = makeMockPopupRedirectResolver(eventManager); - _getInstance( + _getInstance( resolver )._redirectPersistence = RedirectPersistence; auth = await testAuth(resolver); @@ -90,7 +95,7 @@ describe('platform_browser/strategies/redirect', () => { context('signInWithRedirect', () => { it('redirects the window', async () => { const spy = sinon.spy( - _getInstance(resolver), + _getInstance(resolver), '_openRedirect' ); await signInWithRedirect(auth, provider, resolver); @@ -103,7 +108,7 @@ describe('platform_browser/strategies/redirect', () => { it('redirects the window with auth fallback resolver', async () => { const spy = sinon.spy( - _getInstance(resolver), + _getInstance(resolver), '_openRedirect' ); await signInWithRedirect(auth, provider); @@ -124,7 +129,7 @@ describe('platform_browser/strategies/redirect', () => { }); context('linkWithRedirect', () => { - let user: User; + let user: UserInternal; beforeEach(async () => { user = testUser(auth, 'uid', 'email', true); @@ -134,7 +139,7 @@ describe('platform_browser/strategies/redirect', () => { it('redirects the window', async () => { const spy = sinon.spy( - _getInstance(resolver), + _getInstance(resolver), '_openRedirect' ); await linkWithRedirect(user, provider, resolver); @@ -147,7 +152,7 @@ describe('platform_browser/strategies/redirect', () => { it('redirects the window with auth fallback resolver', async () => { const spy = sinon.spy( - _getInstance(resolver), + _getInstance(resolver), '_openRedirect' ); await linkWithRedirect(user, provider); @@ -167,7 +172,7 @@ describe('platform_browser/strategies/redirect', () => { }); it('persists the redirect user and current user', async () => { - const redirectPersistence: Persistence = _getInstance( + const redirectPersistence: PersistenceInternal = _getInstance( RedirectPersistence ); sinon.spy(redirectPersistence, '_set'); @@ -187,7 +192,7 @@ describe('platform_browser/strategies/redirect', () => { it('persists the redirect user but not current user if diff currentUser', async () => { await auth._updateCurrentUser(testUser(auth, 'not-uid', 'email', true)); - const redirectPersistence: Persistence = _getInstance( + const redirectPersistence: PersistenceInternal = _getInstance( RedirectPersistence ); sinon.spy(redirectPersistence, '_set'); @@ -204,7 +209,7 @@ describe('platform_browser/strategies/redirect', () => { }); context('reauthenticateWithRedirect', () => { - let user: User; + let user: UserInternal; beforeEach(async () => { user = testUser(auth, 'uid', 'email', true); @@ -213,7 +218,7 @@ describe('platform_browser/strategies/redirect', () => { it('redirects the window', async () => { const spy = sinon.spy( - _getInstance(resolver), + _getInstance(resolver), '_openRedirect' ); await reauthenticateWithRedirect(user, provider, resolver); @@ -226,7 +231,7 @@ describe('platform_browser/strategies/redirect', () => { it('redirects the window with auth fallback resolver', async () => { const spy = sinon.spy( - _getInstance(resolver), + _getInstance(resolver), '_openRedirect' ); await reauthenticateWithRedirect(user, provider); @@ -245,7 +250,7 @@ describe('platform_browser/strategies/redirect', () => { }); it('persists the redirect user and current user', async () => { - const redirectPersistence: Persistence = _getInstance( + const redirectPersistence: PersistenceInternal = _getInstance( RedirectPersistence ); sinon.spy(redirectPersistence, '_set'); @@ -265,7 +270,7 @@ describe('platform_browser/strategies/redirect', () => { it('persists the redirect user but not current user if diff currentUser', async () => { await auth._updateCurrentUser(testUser(auth, 'not-uid', 'email', true)); - const redirectPersistence: Persistence = _getInstance( + const redirectPersistence: PersistenceInternal = _getInstance( RedirectPersistence ); sinon.spy(redirectPersistence, '_set'); @@ -294,7 +299,7 @@ describe('platform_browser/strategies/redirect', () => { } async function reInitAuthWithRedirectUser(eventId: string): Promise { - const redirectPersistence: Persistence = _getInstance( + const redirectPersistence: PersistenceInternal = _getInstance( RedirectPersistence ); const mainPersistence = new MockPersistenceLayer(); @@ -314,8 +319,8 @@ describe('platform_browser/strategies/redirect', () => { it('completes the proper flow', async () => { const cred = new UserCredentialImpl({ user: testUser(auth, 'uid'), - providerId: externs.ProviderId.GOOGLE, - operationType: externs.OperationType.SIGN_IN + providerId: ProviderId.GOOGLE, + operationType: OperationType.SIGN_IN }); idpStubs._signIn.returns(Promise.resolve(cred)); const promise = getRedirectResult(auth, resolver); @@ -328,8 +333,8 @@ describe('platform_browser/strategies/redirect', () => { it('returns the same value if called multiple times', async () => { const cred = new UserCredentialImpl({ user: testUser(auth, 'uid'), - providerId: externs.ProviderId.GOOGLE, - operationType: externs.OperationType.SIGN_IN + providerId: ProviderId.GOOGLE, + operationType: OperationType.SIGN_IN }); idpStubs._signIn.returns(Promise.resolve(cred)); const promise = getRedirectResult(auth, resolver); @@ -347,8 +352,8 @@ describe('platform_browser/strategies/redirect', () => { const cred = new UserCredentialImpl({ user: testUser(auth, 'uid'), - providerId: externs.ProviderId.GOOGLE, - operationType: externs.OperationType.LINK + providerId: ProviderId.GOOGLE, + operationType: OperationType.LINK }); idpStubs._link.returns(Promise.resolve(cred)); const promise = getRedirectResult(auth, resolver); @@ -365,8 +370,8 @@ describe('platform_browser/strategies/redirect', () => { const cred = new UserCredentialImpl({ user: testUser(auth, 'uid'), - providerId: externs.ProviderId.GOOGLE, - operationType: externs.OperationType.LINK + providerId: ProviderId.GOOGLE, + operationType: OperationType.LINK }); idpStubs._link.returns(Promise.resolve(cred)); const promise = getRedirectResult(auth, resolver); @@ -382,7 +387,7 @@ describe('platform_browser/strategies/redirect', () => { type: AuthEventType.UNKNOWN, error: { code: `auth/${AuthErrorCode.NO_AUTH_EVENT}` - } as externs.AuthError + } as AuthError }); expect(await promise).to.be.null; }); @@ -392,8 +397,8 @@ describe('platform_browser/strategies/redirect', () => { const cred = new UserCredentialImpl({ user: testUser(auth, 'uid'), - providerId: externs.ProviderId.GOOGLE, - operationType: externs.OperationType.REAUTHENTICATE + providerId: ProviderId.GOOGLE, + operationType: OperationType.REAUTHENTICATE }); idpStubs._reauth.returns(Promise.resolve(cred)); const promise = getRedirectResult(auth, resolver); @@ -406,15 +411,15 @@ describe('platform_browser/strategies/redirect', () => { it('removes the redirect user and clears eventId from currentuser', async () => { await reInitAuthWithRedirectUser(MATCHING_EVENT_ID); - const redirectPersistence: Persistence = _getInstance( + const redirectPersistence: PersistenceInternal = _getInstance( RedirectPersistence ); sinon.spy(redirectPersistence, '_remove'); const cred = new UserCredentialImpl({ user: auth._currentUser!, - providerId: externs.ProviderId.GOOGLE, - operationType: externs.OperationType.LINK + providerId: ProviderId.GOOGLE, + operationType: OperationType.LINK }); idpStubs._link.returns(Promise.resolve(cred)); const promise = getRedirectResult(auth, resolver); @@ -430,15 +435,15 @@ describe('platform_browser/strategies/redirect', () => { it('does not mutate authstate if bypassAuthState is true', async () => { await reInitAuthWithRedirectUser(MATCHING_EVENT_ID); - const redirectPersistence: Persistence = _getInstance( + const redirectPersistence: PersistenceInternal = _getInstance( RedirectPersistence ); sinon.spy(redirectPersistence, '_remove'); const cred = new UserCredentialImpl({ user: auth._currentUser!, - providerId: externs.ProviderId.GOOGLE, - operationType: externs.OperationType.LINK + providerId: ProviderId.GOOGLE, + operationType: OperationType.LINK }); idpStubs._link.returns(Promise.resolve(cred)); const promise = _getRedirectResult(auth, resolver, true); diff --git a/packages-exp/auth-exp/src/platform_browser/strategies/redirect.ts b/packages-exp/auth-exp/src/platform_browser/strategies/redirect.ts index 1df18e67ad9..a2dd6b3407a 100644 --- a/packages-exp/auth-exp/src/platform_browser/strategies/redirect.ts +++ b/packages-exp/auth-exp/src/platform_browser/strategies/redirect.ts @@ -15,7 +15,13 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { + Auth, + AuthProvider, + PopupRedirectResolver, + User, + UserCredential +} from '../../model/public_types'; import { OAuthProvider } from '../../core'; import { _castAuth } from '../../core/auth/auth_impl'; @@ -24,7 +30,7 @@ import { _assertLinkedStatus } from '../../core/user/link_unlink'; import { _assert } from '../../core/util/assert'; import { _generateEventId } from '../../core/util/event_id'; import { AuthEventType } from '../../model/popup_redirect'; -import { User } from '../../model/user'; +import { UserInternal } from '../../model/user'; import { _withDefaultResolver } from '../../core/util/resolver'; import { RedirectAction } from '../../core/strategies/redirect'; @@ -68,9 +74,9 @@ import { RedirectAction } from '../../core/strategies/redirect'; * @public */ export async function signInWithRedirect( - auth: externs.Auth, - provider: externs.AuthProvider, - resolver?: externs.PopupRedirectResolver + auth: Auth, + provider: AuthProvider, + resolver?: PopupRedirectResolver ): Promise { const authInternal = _castAuth(auth); _assert( @@ -115,11 +121,11 @@ export async function signInWithRedirect( * @public */ export async function reauthenticateWithRedirect( - user: externs.User, - provider: externs.AuthProvider, - resolver?: externs.PopupRedirectResolver + user: User, + provider: AuthProvider, + resolver?: PopupRedirectResolver ): Promise { - const userInternal = user as User; + const userInternal = user as UserInternal; _assert( provider instanceof OAuthProvider, userInternal.auth, @@ -164,11 +170,11 @@ export async function reauthenticateWithRedirect( * @public */ export async function linkWithRedirect( - user: externs.User, - provider: externs.AuthProvider, - resolver?: externs.PopupRedirectResolver + user: User, + provider: AuthProvider, + resolver?: PopupRedirectResolver ): Promise { - const userInternal = user as User; + const userInternal = user as UserInternal; _assert( provider instanceof OAuthProvider, userInternal.auth, @@ -228,18 +234,18 @@ export async function linkWithRedirect( * @public */ export async function getRedirectResult( - auth: externs.Auth, - resolver?: externs.PopupRedirectResolver -): Promise { + auth: Auth, + resolver?: PopupRedirectResolver +): Promise { await _castAuth(auth)._initializationPromise; return _getRedirectResult(auth, resolver, false); } export async function _getRedirectResult( - auth: externs.Auth, - resolverExtern?: externs.PopupRedirectResolver, + auth: Auth, + resolverExtern?: PopupRedirectResolver, bypassAuthState = false -): Promise { +): Promise { const authInternal = _castAuth(auth); const resolver = _withDefaultResolver(authInternal, resolverExtern); const action = new RedirectAction(authInternal, resolver, bypassAuthState); @@ -247,14 +253,14 @@ export async function _getRedirectResult( if (result && !bypassAuthState) { delete result.user._redirectEventId; - await authInternal._persistUserIfCurrent(result.user as User); + await authInternal._persistUserIfCurrent(result.user as UserInternal); await authInternal._setRedirectUser(null, resolverExtern); } return result; } -async function prepareUserForRedirect(user: User): Promise { +async function prepareUserForRedirect(user: UserInternal): Promise { const eventId = _generateEventId(`${user.uid}:::`); user._redirectEventId = eventId; await user.auth._setRedirectUser(user); diff --git a/packages-exp/auth-exp/src/platform_browser/util/popup.test.ts b/packages-exp/auth-exp/src/platform_browser/util/popup.test.ts index 001c528916e..33e75b5feea 100644 --- a/packages-exp/auth-exp/src/platform_browser/util/popup.test.ts +++ b/packages-exp/auth-exp/src/platform_browser/util/popup.test.ts @@ -23,14 +23,14 @@ import { FirebaseError } from '@firebase/util'; import * as utils from '@firebase/util'; import { _open, AuthPopup } from './popup'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; import { testAuth } from '../../../test/helpers/mock_auth'; use(sinonChai); describe('platform_browser/util/popup', () => { let windowOpenStub: sinon.SinonStub; - let auth: Auth; + let auth: AuthInternal; let popupStub: sinon.SinonStubbedInstance; function setUA(ua: string): void { diff --git a/packages-exp/auth-exp/src/platform_browser/util/popup.ts b/packages-exp/auth-exp/src/platform_browser/util/popup.ts index da37f4b30b7..13e324b30be 100644 --- a/packages-exp/auth-exp/src/platform_browser/util/popup.ts +++ b/packages-exp/auth-exp/src/platform_browser/util/popup.ts @@ -24,7 +24,7 @@ import { _isFirefox, _isIOSStandalone } from '../../core/util/browser'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; const BASE_POPUP_OPTIONS = { location: 'yes', @@ -54,7 +54,7 @@ export class AuthPopup { } export function _open( - auth: Auth, + auth: AuthInternal, url?: string, name?: string, width = DEFAULT_WIDTH, diff --git a/packages-exp/auth-exp/src/platform_cordova/popup_redirect/events.ts b/packages-exp/auth-exp/src/platform_cordova/popup_redirect/events.ts index bf8f33f9a00..b5cd09e65a6 100644 --- a/packages-exp/auth-exp/src/platform_cordova/popup_redirect/events.ts +++ b/packages-exp/auth-exp/src/platform_cordova/popup_redirect/events.ts @@ -18,14 +18,14 @@ import { querystringDecode } from '@firebase/util'; import { AuthEventManager } from '../../core/auth/auth_event_manager'; import { AuthErrorCode } from '../../core/errors'; -import { PersistedBlob, Persistence } from '../../core/persistence'; +import { PersistedBlob, PersistenceInternal } from '../../core/persistence'; import { KeyName, _persistenceKeyName } from '../../core/persistence/persistence_user_manager'; import { _createError } from '../../core/util/assert'; import { _getInstance } from '../../core/util/instantiator'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; import { AuthEvent, AuthEventType } from '../../model/popup_redirect'; import { browserLocalPersistence } from '../../platform_browser/persistence/local_storage'; @@ -70,7 +70,7 @@ export class CordovaAuthEventManager extends AuthEventManager { * Generates a (partial) {@link AuthEvent}. */ export function _generateNewEvent( - auth: Auth, + auth: AuthInternal, type: AuthEventType, eventId: string | null = null ): AuthEvent { @@ -85,7 +85,10 @@ export function _generateNewEvent( }; } -export function _savePartialEvent(auth: Auth, event: AuthEvent): Promise { +export function _savePartialEvent( + auth: AuthInternal, + event: AuthEvent +): Promise { return storage()._set( persistenceKey(auth), (event as object) as PersistedBlob @@ -93,7 +96,7 @@ export function _savePartialEvent(auth: Auth, event: AuthEvent): Promise { } export async function _getAndRemoveEvent( - auth: Auth + auth: AuthInternal ): Promise { const event = (await storage()._get( persistenceKey(auth) @@ -162,11 +165,11 @@ function generateSessionId(): string { return chars.join(''); } -function storage(): Persistence { +function storage(): PersistenceInternal { return _getInstance(browserLocalPersistence); } -function persistenceKey(auth: Auth): string { +function persistenceKey(auth: AuthInternal): string { return _persistenceKeyName(KeyName.AUTH_EVENT, auth.config.apiKey, auth.name); } diff --git a/packages-exp/auth-exp/src/platform_cordova/popup_redirect/popup_redirect.test.ts b/packages-exp/auth-exp/src/platform_cordova/popup_redirect/popup_redirect.test.ts index 8fc96f7bc87..1112565dfeb 100644 --- a/packages-exp/auth-exp/src/platform_cordova/popup_redirect/popup_redirect.test.ts +++ b/packages-exp/auth-exp/src/platform_cordova/popup_redirect/popup_redirect.test.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { AuthProvider } from '../../model/public_types'; import * as sinon from 'sinon'; import * as chaiAsPromised from 'chai-as-promised'; import * as sinonChai from 'sinon-chai'; @@ -26,7 +26,7 @@ import { AuthEvent, AuthEventType, EventManager, - PopupRedirectResolver + PopupRedirectResolverInternal } from '../../model/popup_redirect'; import { cordovaPopupRedirectResolver } from './popup_redirect'; import { GoogleAuthProvider } from '../../core/providers/google'; @@ -47,8 +47,8 @@ describe('platform_cordova/popup_redirect/popup_redirect', () => { const NO_EVENT_TIMER_ID = 10001; let auth: TestAuth; - let resolver: PopupRedirectResolver; - let provider: externs.AuthProvider; + let resolver: PopupRedirectResolverInternal; + let provider: AuthProvider; let utilsStubs: sinon.SinonStubbedInstance; let eventsStubs: sinon.SinonStubbedInstance>; let universalLinksCb: @@ -58,7 +58,7 @@ describe('platform_cordova/popup_redirect/popup_redirect', () => { beforeEach(async () => { auth = await testAuth(); - resolver = new (cordovaPopupRedirectResolver as SingletonInstantiator)(); + resolver = new (cordovaPopupRedirectResolver as SingletonInstantiator)(); provider = new GoogleAuthProvider(); utilsStubs = sinon.stub(utils); eventsStubs = { diff --git a/packages-exp/auth-exp/src/platform_cordova/popup_redirect/popup_redirect.ts b/packages-exp/auth-exp/src/platform_cordova/popup_redirect/popup_redirect.ts index 87790a6fdaf..dfa13bfb573 100644 --- a/packages-exp/auth-exp/src/platform_cordova/popup_redirect/popup_redirect.ts +++ b/packages-exp/auth-exp/src/platform_cordova/popup_redirect/popup_redirect.ts @@ -16,13 +16,13 @@ */ import '../plugins'; -import * as externs from '../../model/public_types'; +import { AuthProvider, PopupRedirectResolver } from '../../model/public_types'; import { browserSessionPersistence } from '../../platform_browser/persistence/session_storage'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; import { AuthEvent, AuthEventType, - PopupRedirectResolver + PopupRedirectResolverInternal } from '../../model/popup_redirect'; import { AuthPopup } from '../../platform_browser/util/popup'; import { _createError, _fail } from '../../core/util/assert'; @@ -48,13 +48,13 @@ import { AuthEventManager } from '../../core/auth/auth_event_manager'; */ const INITIAL_EVENT_TIMEOUT_MS = 500; -class CordovaPopupRedirectResolver implements PopupRedirectResolver { +class CordovaPopupRedirectResolver implements PopupRedirectResolverInternal { readonly _redirectPersistence = browserSessionPersistence; private readonly eventManagers = new Map(); _completeRedirectFn = async (): Promise => null; - async _initialize(auth: Auth): Promise { + async _initialize(auth: AuthInternal): Promise { const key = auth._key(); let manager = this.eventManagers.get(key); if (!manager) { @@ -65,13 +65,13 @@ class CordovaPopupRedirectResolver implements PopupRedirectResolver { return manager; } - _openPopup(auth: Auth): Promise { + _openPopup(auth: AuthInternal): Promise { _fail(auth, AuthErrorCode.OPERATION_NOT_SUPPORTED); } async _openRedirect( - auth: Auth, - provider: externs.AuthProvider, + auth: AuthInternal, + provider: AuthProvider, authType: AuthEventType, eventId?: string ): Promise { @@ -88,13 +88,16 @@ class CordovaPopupRedirectResolver implements PopupRedirectResolver { } _isIframeWebStorageSupported( - _auth: Auth, + _auth: AuthInternal, _cb: (support: boolean) => unknown ): void { throw new Error('Method not implemented.'); } - private attachCallbackListeners(auth: Auth, manager: AuthEventManager): void { + private attachCallbackListeners( + auth: AuthInternal, + manager: AuthEventManager + ): void { const noEventTimeout = setTimeout(async () => { // We didn't see that initial event. Clear any pending object and // dispatch no event @@ -158,7 +161,7 @@ class CordovaPopupRedirectResolver implements PopupRedirectResolver { * * @public */ -export const cordovaPopupRedirectResolver: externs.PopupRedirectResolver = CordovaPopupRedirectResolver; +export const cordovaPopupRedirectResolver: PopupRedirectResolver = CordovaPopupRedirectResolver; function generateNoEvent(): AuthEvent { return { diff --git a/packages-exp/auth-exp/src/platform_cordova/popup_redirect/utils.ts b/packages-exp/auth-exp/src/platform_cordova/popup_redirect/utils.ts index 00b11fda491..4eb78b69a09 100644 --- a/packages-exp/auth-exp/src/platform_cordova/popup_redirect/utils.ts +++ b/packages-exp/auth-exp/src/platform_cordova/popup_redirect/utils.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { AuthProvider } from '../../model/public_types'; import { AuthErrorCode } from '../../core/errors'; import { debugAssert, @@ -25,7 +25,7 @@ import { } from '../../core/util/assert'; import { _isAndroid, _isIOS, _isIOS7Or8 } from '../../core/util/browser'; import { _getRedirectUrl } from '../../core/util/handler'; -import { Auth } from '../../model/auth'; +import { AuthInternal } from '../../model/auth'; import { AuthEvent } from '../../model/popup_redirect'; /** @@ -38,9 +38,9 @@ const REDIRECT_TIMEOUT_MS = 2000; * Generates the URL for the OAuth handler. */ export async function _generateHandlerUrl( - auth: Auth, + auth: AuthInternal, event: AuthEvent, - provider: externs.AuthProvider + provider: AuthProvider ): Promise { debugAssert(event.sessionId, 'AuthEvent did not contain a session ID'); const sessionDigest = await computeSha256(event.sessionId); @@ -107,7 +107,7 @@ interface PassiveAuthEventListener { * are detached and any browser tabs left open will be closed. */ export async function _waitForAppResume( - auth: Auth, + auth: AuthInternal, eventListener: PassiveAuthEventListener, iabRef: InAppBrowserRef | null ): Promise { @@ -184,7 +184,7 @@ export async function _waitForAppResume( * if the configuration is correct; otherwise it throws an error with the * missing plugin. */ -export function _checkCordovaConfiguration(auth: Auth): void { +export function _checkCordovaConfiguration(auth: AuthInternal): void { // Check all dependencies installed. // https://github.com/nordnet/cordova-universal-links-plugin // Note that cordova-universal-links-plugin has been abandoned. diff --git a/packages-exp/auth-exp/src/platform_cordova/strategies/redirect.ts b/packages-exp/auth-exp/src/platform_cordova/strategies/redirect.ts index 6ab4c0f5570..8d1a5f3027c 100644 --- a/packages-exp/auth-exp/src/platform_cordova/strategies/redirect.ts +++ b/packages-exp/auth-exp/src/platform_cordova/strategies/redirect.ts @@ -15,7 +15,11 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { + Auth, + AuthProvider, + PopupRedirectResolver +} from '../../model/public_types'; import { _castAuth } from '../../core/auth/auth_impl'; import { AuthErrorCode } from '../../core/errors'; import { OAuthProvider } from '../../core/providers/oauth'; @@ -27,9 +31,9 @@ import { AuthEventType } from '../../model/popup_redirect'; // It's likely we can just reuse that code export async function signInWithRedirect( - auth: externs.Auth, - provider: externs.AuthProvider, - resolver?: externs.PopupRedirectResolver + auth: Auth, + provider: AuthProvider, + resolver?: PopupRedirectResolver ): Promise { const authInternal = _castAuth(auth); _assert( diff --git a/packages-exp/auth-exp/src/platform_react_native/persistence/react_native.test.ts b/packages-exp/auth-exp/src/platform_react_native/persistence/react_native.test.ts index 6c20283cb22..63524fff70f 100644 --- a/packages-exp/auth-exp/src/platform_react_native/persistence/react_native.test.ts +++ b/packages-exp/auth-exp/src/platform_react_native/persistence/react_native.test.ts @@ -23,7 +23,7 @@ import { testUser, testAuth } from '../../../test/helpers/mock_auth'; import { _getInstance } from '../../core/util/instantiator'; import { PersistedBlob, - Persistence, + PersistenceInternal, PersistenceType } from '../../core/persistence'; import { getReactNativePersistence } from './react_native'; @@ -53,7 +53,7 @@ class FakeAsyncStorage implements ReactNativeAsyncStorage { describe('core/persistence/react', () => { const fakeAsyncStorage = new FakeAsyncStorage(); - const persistence: Persistence = _getInstance( + const persistence: PersistenceInternal = _getInstance( getReactNativePersistence(fakeAsyncStorage) ); diff --git a/packages-exp/auth-exp/src/platform_react_native/persistence/react_native.ts b/packages-exp/auth-exp/src/platform_react_native/persistence/react_native.ts index 71be2ce654c..58d605ec3b6 100644 --- a/packages-exp/auth-exp/src/platform_react_native/persistence/react_native.ts +++ b/packages-exp/auth-exp/src/platform_react_native/persistence/react_native.ts @@ -15,10 +15,10 @@ * limitations under the License. */ -import * as externs from '../../model/public_types'; +import { Persistence, ReactNativeAsyncStorage } from '../../model/public_types'; import { - Persistence, + PersistenceInternal, PersistenceType, PersistenceValue, STORAGE_AVAILABLE_KEY, @@ -41,9 +41,9 @@ import { debugFail } from '../../core/util/assert'; */ export function getReactNativePersistence( - storage: externs.ReactNativeAsyncStorage -): externs.Persistence { - return class implements Persistence { + storage: ReactNativeAsyncStorage +): Persistence { + return class implements PersistenceInternal { static type: 'LOCAL' = 'LOCAL'; readonly type: PersistenceType = PersistenceType.LOCAL; diff --git a/packages-exp/auth-exp/test/helpers/integration/helpers.ts b/packages-exp/auth-exp/test/helpers/integration/helpers.ts index dfc05cffe31..c86ae267fbf 100644 --- a/packages-exp/auth-exp/test/helpers/integration/helpers.ts +++ b/packages-exp/auth-exp/test/helpers/integration/helpers.ts @@ -16,7 +16,7 @@ */ import { deleteApp, initializeApp } from '@firebase/app-exp'; -import { Auth, User } from '@firebase/auth-types-exp'; +import { Auth, User } from '../../../src/model/public_types'; import { getAuth } from '../../../index'; import { _generateEventId } from '../../../src/core/util/event_id'; diff --git a/packages-exp/auth-exp/test/helpers/mock_auth.ts b/packages-exp/auth-exp/test/helpers/mock_auth.ts index 2cd2beeaa62..0932ae044cb 100644 --- a/packages-exp/auth-exp/test/helpers/mock_auth.ts +++ b/packages-exp/auth-exp/test/helpers/mock_auth.ts @@ -16,7 +16,7 @@ */ import { FirebaseApp } from '@firebase/app-exp'; -import { PopupRedirectResolver } from '@firebase/auth-types-exp'; +import { PopupRedirectResolver } from '../../src/model/public_types'; import { debugErrorMap } from '../../src'; import { AuthImpl } from '../../src/core/auth/auth_impl'; @@ -24,8 +24,8 @@ import { PersistedBlob } from '../../src/core/persistence'; import { InMemoryPersistence } from '../../src/core/persistence/in_memory'; import { StsTokenManager } from '../../src/core/user/token_manager'; import { UserImpl } from '../../src/core/user/user_impl'; -import { Auth } from '../../src/model/auth'; -import { User } from '../../src/model/user'; +import { AuthInternal } from '../../src/model/auth'; +import { UserInternal } from '../../src/model/user'; export const TEST_HOST = 'localhost'; export const TEST_TOKEN_HOST = 'localhost/token'; @@ -78,11 +78,11 @@ export async function testAuth( } export function testUser( - auth: Auth, + auth: AuthInternal, uid: string, email?: string, fakeTokens = false -): User { +): UserInternal { // Create a token manager that's valid off the bat to avoid refresh calls const stsTokenManager = new StsTokenManager(); if (fakeTokens) { @@ -95,7 +95,7 @@ export function testUser( return new UserImpl({ uid, - auth: auth as Auth, + auth: auth as AuthInternal, stsTokenManager, email }); diff --git a/packages-exp/auth-exp/test/helpers/mock_auth_credential.ts b/packages-exp/auth-exp/test/helpers/mock_auth_credential.ts index 9b6ff77419a..f165c628b8b 100644 --- a/packages-exp/auth-exp/test/helpers/mock_auth_credential.ts +++ b/packages-exp/auth-exp/test/helpers/mock_auth_credential.ts @@ -15,11 +15,11 @@ * limitations under the License. */ -import { ProviderId, SignInMethod } from '@firebase/auth-types-exp'; +import { ProviderId, SignInMethod } from '../../src/model/public_types'; import { PhoneOrOauthTokenResponse } from '../../src/api/authentication/mfa'; import { AuthCredential } from '../../src/core/credentials'; -import { Auth } from '../../src/model/auth'; +import { AuthInternal } from '../../src/model/auth'; import { IdTokenResponse } from '../../src/model/id_token'; export class MockAuthCredential implements AuthCredential { @@ -36,18 +36,22 @@ export class MockAuthCredential implements AuthCredential { throw new Error('Method not implemented.'); } - async _getIdTokenResponse(_auth: Auth): Promise { + async _getIdTokenResponse( + _auth: AuthInternal + ): Promise { throw new Error('Method not implemented.'); } async _linkToIdToken( - _auth: Auth, + _auth: AuthInternal, _idToken: string ): Promise { throw new Error('Method not implemented.'); } - async _getReauthenticationResolver(_auth: Auth): Promise { + async _getReauthenticationResolver( + _auth: AuthInternal + ): Promise { throw new Error('Method not implemented.'); } } diff --git a/packages-exp/auth-exp/test/helpers/mock_popup_redirect_resolver.ts b/packages-exp/auth-exp/test/helpers/mock_popup_redirect_resolver.ts index 3751ed1008b..e989f097c63 100644 --- a/packages-exp/auth-exp/test/helpers/mock_popup_redirect_resolver.ts +++ b/packages-exp/auth-exp/test/helpers/mock_popup_redirect_resolver.ts @@ -15,12 +15,15 @@ * limitations under the License. */ -import { Persistence, PopupRedirectResolver } from '@firebase/auth-types-exp'; +import { + Persistence, + PopupRedirectResolver +} from '../../src/model/public_types'; import { AuthEventManager } from '../../src/core/auth/auth_event_manager'; import { AuthPopup } from '../../src/platform_browser/util/popup'; import { EventManager } from '../../src/model/popup_redirect'; -import { Auth } from '../../src/model/auth'; +import { AuthInternal } from '../../src/model/auth'; /** * Generates a PopupRedirectResolver that can be used by the oauth methods. @@ -33,7 +36,9 @@ export function makeMockPopupRedirectResolver( ): PopupRedirectResolver { return class implements PopupRedirectResolver { async _initialize(): Promise { - return eventManager || new AuthEventManager(({} as unknown) as Auth); + return ( + eventManager || new AuthEventManager(({} as unknown) as AuthInternal) + ); } async _openPopup(): Promise { diff --git a/packages-exp/auth-exp/test/integration/flows/anonymous.test.ts b/packages-exp/auth-exp/test/integration/flows/anonymous.test.ts index 615cf3f488e..c1c0b8b5f14 100644 --- a/packages-exp/auth-exp/test/integration/flows/anonymous.test.ts +++ b/packages-exp/auth-exp/test/integration/flows/anonymous.test.ts @@ -25,10 +25,11 @@ import { signInAnonymously, signInWithEmailAndPassword, updateEmail, - updatePassword + updatePassword, + Auth, + OperationType // eslint-disable-next-line import/no-extraneous-dependencies } from '@firebase/auth-exp'; -import { Auth, OperationType } from '@firebase/auth-types-exp'; import { FirebaseError } from '@firebase/util'; import { diff --git a/packages-exp/auth-exp/test/integration/flows/email.test.ts b/packages-exp/auth-exp/test/integration/flows/email.test.ts index 574caaae96b..7a44f653675 100644 --- a/packages-exp/auth-exp/test/integration/flows/email.test.ts +++ b/packages-exp/auth-exp/test/integration/flows/email.test.ts @@ -24,10 +24,12 @@ import { reload, signInWithCredential, signInWithEmailAndPassword, - updateProfile + updateProfile, + Auth, + OperationType, + UserCredential // eslint-disable-next-line import/no-extraneous-dependencies } from '@firebase/auth-exp'; -import { Auth, OperationType, UserCredential } from '@firebase/auth-types-exp'; import { FirebaseError } from '@firebase/util'; import { diff --git a/packages-exp/auth-exp/test/integration/flows/phone.test.ts b/packages-exp/auth-exp/test/integration/flows/phone.test.ts index 48dd3bd888c..07faeb78477 100644 --- a/packages-exp/auth-exp/test/integration/flows/phone.test.ts +++ b/packages-exp/auth-exp/test/integration/flows/phone.test.ts @@ -26,15 +26,13 @@ import { signInAnonymously, signInWithPhoneNumber, unlink, - updatePhoneNumber - // eslint-disable-next-line import/no-extraneous-dependencies -} from '@firebase/auth-exp'; -import { + updatePhoneNumber, Auth, OperationType, ProviderId, UserCredential -} from '@firebase/auth-types-exp'; + // eslint-disable-next-line import/no-extraneous-dependencies +} from '@firebase/auth-exp'; import { FirebaseError } from '@firebase/util'; import { From 982633d7d646fe733c20f236d9885447c8091895 Mon Sep 17 00:00:00 2001 From: Feiyang1 Date: Wed, 17 Feb 2021 22:54:31 -0800 Subject: [PATCH 05/13] fix tests --- packages-exp/auth-exp/package.json | 2 +- packages-exp/auth-exp/src/core/auth/firebase_internal.test.ts | 4 ++-- packages-exp/auth-exp/src/core/strategies/email_link.test.ts | 3 +-- packages-exp/auth-exp/src/model/public_types.ts | 3 ++- .../src/platform_browser/mfa/assertions/phone.test.ts | 2 +- .../auth-exp/src/platform_browser/popup_redirect.test.ts | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages-exp/auth-exp/package.json b/packages-exp/auth-exp/package.json index 8b487e17958..8335c616f83 100644 --- a/packages-exp/auth-exp/package.json +++ b/packages-exp/auth-exp/package.json @@ -29,7 +29,7 @@ "test:browser:unit:debug": "karma start --auto-watch --unit", "test:cordova": "karma start --single-run --cordova", "test:cordova:debug": "karma start --auto-watch --cordova", - "test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'src/!(platform_browser|platform_react_native|platform_cordova)/**/*.test.ts' --file index.node.ts --config ../../config/mocharc.node.js", + "test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'src/!(platform_browser|platform_react_native|platform_cordova)/**/*.test.ts' --file index.node.ts --file src/platform_browser/iframe/gapi.iframes.ts --config ../../config/mocharc.node.js", "api-report": "api-extractor run --local --verbose", "predoc": "node ../../scripts/exp/remove-exp.js temp", "doc": "api-documenter markdown --input temp --output docs", diff --git a/packages-exp/auth-exp/src/core/auth/firebase_internal.test.ts b/packages-exp/auth-exp/src/core/auth/firebase_internal.test.ts index 87ed66e3ac8..edf2e7fee3f 100644 --- a/packages-exp/auth-exp/src/core/auth/firebase_internal.test.ts +++ b/packages-exp/auth-exp/src/core/auth/firebase_internal.test.ts @@ -29,10 +29,10 @@ use(chaiAsPromised); describe('core/auth/firebase_internal', () => { let auth: AuthInternal; - let authInternal: AuthInternal; + let authInternal: AuthInterop; beforeEach(async () => { auth = await testAuth(); - authInternal = new AuthInternal(auth); + authInternal = new AuthInterop(auth); }); afterEach(() => { diff --git a/packages-exp/auth-exp/src/core/strategies/email_link.test.ts b/packages-exp/auth-exp/src/core/strategies/email_link.test.ts index b0a4f061e44..0f2e2a3ac4b 100644 --- a/packages-exp/auth-exp/src/core/strategies/email_link.test.ts +++ b/packages-exp/auth-exp/src/core/strategies/email_link.test.ts @@ -19,8 +19,7 @@ import { expect, use } from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; import * as sinonChai from 'sinon-chai'; -import { ActionCodeOperation } from '../../model/public_types'; -import { OperationType } from '../../model/public_types'; +import { ActionCodeOperation, OperationType } from '../../model/public_types'; import { FirebaseError } from '@firebase/util'; import { mockEndpoint } from '../../../test/helpers/api/helper'; diff --git a/packages-exp/auth-exp/src/model/public_types.ts b/packages-exp/auth-exp/src/model/public_types.ts index a4cf376ff27..b1ff5abce97 100644 --- a/packages-exp/auth-exp/src/model/public_types.ts +++ b/packages-exp/auth-exp/src/model/public_types.ts @@ -584,6 +584,7 @@ export declare abstract class RecaptchaVerifier implements ApplicationVerifier { * an element ID. The corresponding element must also must be in the DOM at the time of * initialization. */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any container: any | string, /** * The optional reCAPTCHA parameters. @@ -594,7 +595,7 @@ export declare abstract class RecaptchaVerifier implements ApplicationVerifier { * configure this upon rendering. For an invisible reCAPTCHA, a size key must have the value * 'invisible'. */ - parameters?: Object | null, + parameters?: object | null, /** * The corresponding Firebase Auth instance. * diff --git a/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.test.ts b/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.test.ts index e93dbddacc9..4e54410bc98 100644 --- a/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.test.ts +++ b/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.test.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { ProviderId } from '../../model/public_types'; +import { ProviderId } from '../../../model/public_types'; import { expect, use } from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; diff --git a/packages-exp/auth-exp/src/platform_browser/popup_redirect.test.ts b/packages-exp/auth-exp/src/platform_browser/popup_redirect.test.ts index 8d2a3d00b11..881ae5b12a5 100644 --- a/packages-exp/auth-exp/src/platform_browser/popup_redirect.test.ts +++ b/packages-exp/auth-exp/src/platform_browser/popup_redirect.test.ts @@ -21,7 +21,7 @@ import * as sinon from 'sinon'; import * as sinonChai from 'sinon-chai'; import { SDK_VERSION } from '@firebase/app-exp'; -import { Config, ProviderId } from '../../model/public_types'; +import { Config, ProviderId } from '../model/public_types'; import { FirebaseError } from '@firebase/util'; import { From 3e653fc3c94f1b792d64ee8bc065e4603281f412 Mon Sep 17 00:00:00 2001 From: Feiyang1 Date: Thu, 18 Feb 2021 10:58:29 -0800 Subject: [PATCH 06/13] auth-compat update --- packages-exp/auth-compat-exp/package.json | 1 - packages-exp/auth-compat-exp/src/auth.test.ts | 2 +- packages-exp/auth-compat-exp/src/auth.ts | 2 +- packages-exp/auth-compat-exp/src/persistence.ts | 2 +- packages-exp/auth-compat-exp/src/phone_auth_provider.ts | 2 +- packages-exp/auth-compat-exp/src/user_credential.ts | 5 +++-- packages-exp/auth-exp/package.json | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages-exp/auth-compat-exp/package.json b/packages-exp/auth-compat-exp/package.json index 99af2d7daec..a364fb45bc9 100644 --- a/packages-exp/auth-compat-exp/package.json +++ b/packages-exp/auth-compat-exp/package.json @@ -28,7 +28,6 @@ "dependencies": { "@firebase/auth-types": "0.10.1", "@firebase/auth-exp": "0.0.900", - "@firebase/auth-types-exp": "0.0.900", "@firebase/component": "0.1.21", "@firebase/util": "0.3.4", "tslib": "^1.11.1" diff --git a/packages-exp/auth-compat-exp/src/auth.test.ts b/packages-exp/auth-compat-exp/src/auth.test.ts index d30b11d4cb7..5b031ea29cc 100644 --- a/packages-exp/auth-compat-exp/src/auth.test.ts +++ b/packages-exp/auth-compat-exp/src/auth.test.ts @@ -17,7 +17,7 @@ import { FirebaseApp } from '@firebase/app-compat'; import * as impl from '@firebase/auth-exp/internal'; -import { Config } from '@firebase/auth-types-exp'; +import { Config } from '@firebase/auth-exp'; import { expect, use } from 'chai'; import * as sinon from 'sinon'; import * as sinonChai from 'sinon-chai'; diff --git a/packages-exp/auth-compat-exp/src/auth.ts b/packages-exp/auth-compat-exp/src/auth.ts index 4a57fb663ac..cd5136c355b 100644 --- a/packages-exp/auth-compat-exp/src/auth.ts +++ b/packages-exp/auth-compat-exp/src/auth.ts @@ -18,7 +18,7 @@ import { FirebaseApp, _FirebaseService } from '@firebase/app-compat'; import * as impl from '@firebase/auth-exp/internal'; import * as compat from '@firebase/auth-types'; -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '@firebase/auth-exp'; import { ErrorFn, isIndexedDBAvailable, diff --git a/packages-exp/auth-compat-exp/src/persistence.ts b/packages-exp/auth-compat-exp/src/persistence.ts index 920a87814ca..de5767d96ed 100644 --- a/packages-exp/auth-compat-exp/src/persistence.ts +++ b/packages-exp/auth-compat-exp/src/persistence.ts @@ -16,7 +16,7 @@ */ import { _assert, AuthErrorCode } from '@firebase/auth-exp/internal'; -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '@firebase/auth-exp'; import { isIndexedDBAvailable, isNode, isReactNative } from '@firebase/util'; import { _isWebStorageSupported, _isWorker } from './platform'; diff --git a/packages-exp/auth-compat-exp/src/phone_auth_provider.ts b/packages-exp/auth-compat-exp/src/phone_auth_provider.ts index 448e850ad4a..539ae47a454 100644 --- a/packages-exp/auth-compat-exp/src/phone_auth_provider.ts +++ b/packages-exp/auth-compat-exp/src/phone_auth_provider.ts @@ -17,7 +17,7 @@ import * as impl from '@firebase/auth-exp/internal'; import * as compat from '@firebase/auth-types'; -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '@firebase/auth-exp'; import firebase from '@firebase/app-compat'; import { unwrap, Wrapper } from './wrap'; diff --git a/packages-exp/auth-compat-exp/src/user_credential.ts b/packages-exp/auth-compat-exp/src/user_credential.ts index 628340ebb19..00d5c2f1fa7 100644 --- a/packages-exp/auth-compat-exp/src/user_credential.ts +++ b/packages-exp/auth-compat-exp/src/user_credential.ts @@ -17,7 +17,7 @@ import * as impl from '@firebase/auth-exp/internal'; import * as compat from '@firebase/auth-types'; -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '@firebase/auth-exp'; import { User } from './user'; function credentialFromResponse( @@ -30,7 +30,8 @@ function credentialFromResponse( // Handle phone Auth credential responses, as they have a different format // from other backend responses (i.e. no providerId). if ('temporaryProof' in _tokenResponse && 'phoneNumber' in _tokenResponse) { - return impl.PhoneAuthProvider.credentialFromResult(userCredential); + // return impl.PhoneAuthProvider.credentialFromResult(userCredential); + return impl.PhoneAuthProvider.credentialFromResult({} as any); } // Email and password is not supported as there is no situation where the // server would return the password to the client. diff --git a/packages-exp/auth-exp/package.json b/packages-exp/auth-exp/package.json index 8335c616f83..59a01fdf803 100644 --- a/packages-exp/auth-exp/package.json +++ b/packages-exp/auth-exp/package.json @@ -64,7 +64,7 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "dist/esm5/index.d.ts", + "typings": "dist/auth-exp.d.ts", "nyc": { "extension": [ ".ts" From 6b5f3661010228fd0f23794bb51d371d2616bf42 Mon Sep 17 00:00:00 2001 From: Feiyang1 Date: Thu, 18 Feb 2021 15:34:48 -0800 Subject: [PATCH 07/13] remove classes from public types --- common/api-review/auth-exp.api.md | 130 ++---- packages-exp/auth-exp/index.ts | 2 +- .../auth-exp/src/core/action_code_url.ts | 45 +- .../src/core/credentials/auth_credential.ts | 25 +- .../auth-exp/src/core/credentials/email.ts | 27 +- .../auth-exp/src/core/credentials/index.ts | 2 +- .../auth-exp/src/core/credentials/oauth.ts | 40 +- .../src/core/credentials/phone.test.ts | 25 +- .../auth-exp/src/core/credentials/phone.ts | 28 +- packages-exp/auth-exp/src/core/errors.ts | 3 +- packages-exp/auth-exp/src/core/index.ts | 2 +- .../auth-exp/src/core/providers/email.ts | 66 ++- .../auth-exp/src/core/providers/facebook.ts | 5 +- .../auth-exp/src/core/providers/github.ts | 5 +- .../auth-exp/src/core/providers/google.ts | 5 +- .../auth-exp/src/core/providers/oauth.ts | 12 +- .../auth-exp/src/core/providers/twitter.ts | 5 +- .../src/core/strategies/credential.ts | 19 +- .../auth-exp/src/mfa/mfa_resolver.test.ts | 6 +- .../auth-exp/src/model/public_types.ts | 410 +----------------- .../mfa/assertions/phone.test.ts | 10 +- .../platform_browser/mfa/assertions/phone.ts | 28 +- .../src/platform_browser/providers/phone.ts | 99 ++++- .../recaptcha/recaptcha_verifier.ts | 57 ++- .../platform_browser/strategies/phone.test.ts | 6 +- .../src/platform_browser/strategies/phone.ts | 9 +- 26 files changed, 414 insertions(+), 657 deletions(-) diff --git a/common/api-review/auth-exp.api.md b/common/api-review/auth-exp.api.md index 752cac75161..2507ad333dc 100644 --- a/common/api-review/auth-exp.api.md +++ b/common/api-review/auth-exp.api.md @@ -48,25 +48,16 @@ export interface ActionCodeSettings { url: string; } -// Warning: (ae-forgotten-export) The symbol "ActionCodeURL" needs to be exported by the entry point index.d.ts -// -// @public (undocumented) -export class ActionCodeURL implements ActionCodeURL_2 { +// @public +export class ActionCodeURL { // @internal constructor(actionLink: string); - // (undocumented) readonly apiKey: string; - // (undocumented) readonly code: string; - // (undocumented) readonly continueUrl: string | null; - // (undocumented) readonly languageCode: string | null; - // (undocumented) readonly operation: ActionCodeOperation; - // (undocumented) static parseLink(link: string): ActionCodeURL | null; - // (undocumented) readonly tenantId: string | null; } @@ -106,10 +97,12 @@ export interface Auth { useDeviceLanguage(): void; } -// @public (undocumented) +// @public export class AuthCredential { // @internal - protected constructor(providerId: string, signInMethod: string); + protected constructor( + providerId: string, + signInMethod: string); // Warning: (ae-forgotten-export) The symbol "AuthInternal" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "PhoneOrOauthTokenResponse" needs to be exported by the entry point index.d.ts // @@ -121,11 +114,8 @@ export class AuthCredential { // // @internal (undocumented) _linkToIdToken(_auth: AuthInternal, _idToken: string): Promise; - // (undocumented) readonly providerId: string; - // (undocumented) readonly signInMethod: string; - // (undocumented) toJSON(): object; } @@ -194,17 +184,14 @@ export const debugErrorMap: AuthErrorMap; // @public export function deleteUser(user: User): Promise; -// Warning: (ae-forgotten-export) The symbol "AuthCredential" needs to be exported by the entry point index.d.ts -// // @public -export class EmailAuthCredential extends AuthCredential implements AuthCredential_2 { +export class EmailAuthCredential extends AuthCredential { // (undocumented) readonly email: string; // @internal (undocumented) static _fromEmailAndCode(email: string, oobCode: string, tenantId?: string | null): EmailAuthCredential; // @internal (undocumented) static _fromEmailAndPassword(email: string, password: string): EmailAuthCredential; - // (undocumented) static fromJSON(json: object | string): EmailAuthCredential | null; // @internal (undocumented) _getIdTokenResponse(auth: AuthInternal): Promise; @@ -216,35 +203,25 @@ export class EmailAuthCredential extends AuthCredential implements AuthCredentia readonly password: string; // (undocumented) readonly tenantId: string | null; - // (undocumented) toJSON(): object; } -// Warning: (ae-forgotten-export) The symbol "EmailAuthProvider" needs to be exported by the entry point index.d.ts -// -// @public (undocumented) -export class EmailAuthProvider implements EmailAuthProvider_2 { - // (undocumented) +// @public +export class EmailAuthProvider implements AuthProvider { static credential(email: string, password: string): EmailAuthCredential; - // (undocumented) static credentialWithLink(email: string, emailLink: string): EmailAuthCredential; - // (undocumented) static readonly EMAIL_LINK_SIGN_IN_METHOD = SignInMethod.EMAIL_LINK; - // (undocumented) static readonly EMAIL_PASSWORD_SIGN_IN_METHOD = SignInMethod.EMAIL_PASSWORD; - // (undocumented) static readonly PROVIDER_ID = ProviderId.PASSWORD; - // (undocumented) readonly providerId = ProviderId.PASSWORD; } // @public export class FacebookAuthProvider extends OAuthProvider { constructor(); - // Warning: (ae-forgotten-export) The symbol "OAuthCredential" needs to be exported by the entry point index.d.ts - static credential(accessToken: string): OAuthCredential_2; - static credentialFromError(error: FirebaseError): OAuthCredential_2 | null; - static credentialFromResult(userCredential: UserCredential): OAuthCredential_2 | null; + static credential(accessToken: string): OAuthCredential; + static credentialFromError(error: FirebaseError): OAuthCredential | null; + static credentialFromResult(userCredential: UserCredential): OAuthCredential | null; static readonly FACEBOOK_SIGN_IN_METHOD = SignInMethod.FACEBOOK; static readonly PROVIDER_ID = ProviderId.FACEBOOK; } @@ -280,9 +257,9 @@ export function getRedirectResult(auth: Auth, resolver?: PopupRedirectResolver): // @public export class GithubAuthProvider extends OAuthProvider { constructor(); - static credential(accessToken: string): OAuthCredential_2; - static credentialFromError(error: FirebaseError): OAuthCredential_2 | null; - static credentialFromResult(userCredential: UserCredential): OAuthCredential_2 | null; + static credential(accessToken: string): OAuthCredential; + static credentialFromError(error: FirebaseError): OAuthCredential | null; + static credentialFromResult(userCredential: UserCredential): OAuthCredential | null; static readonly GITHUB_SIGN_IN_METHOD = SignInMethod.GITHUB; static readonly PROVIDER_ID = ProviderId.GITHUB; } @@ -290,9 +267,9 @@ export class GithubAuthProvider extends OAuthProvider { // @public export class GoogleAuthProvider extends OAuthProvider { constructor(); - static credential(idToken?: string | null, accessToken?: string | null): OAuthCredential_2; - static credentialFromError(error: FirebaseError): OAuthCredential_2 | null; - static credentialFromResult(userCredential: UserCredential): OAuthCredential_2 | null; + static credential(idToken?: string | null, accessToken?: string | null): OAuthCredential; + static credentialFromError(error: FirebaseError): OAuthCredential | null; + static credentialFromResult(userCredential: UserCredential): OAuthCredential | null; static readonly GOOGLE_SIGN_IN_METHOD = SignInMethod.GOOGLE; static readonly PROVIDER_ID = ProviderId.GOOGLE; } @@ -323,7 +300,7 @@ export const inMemoryPersistence: Persistence; export function isSignInWithEmailLink(auth: Auth, emailLink: string): boolean; // @public -export function linkWithCredential(user: User, credential: AuthCredential_2): Promise; +export function linkWithCredential(user: User, credential: AuthCredential): Promise; // @public export function linkWithPhoneNumber(user: User, phoneNumber: string, appVerifier: ApplicationVerifier): Promise; @@ -374,11 +351,9 @@ export interface MultiFactorUser { unenroll(option: MultiFactorInfo | string): Promise; } -// @public (undocumented) -export class OAuthCredential extends AuthCredential implements OAuthCredential_2 { - // (undocumented) +// @public +export class OAuthCredential extends AuthCredential { accessToken?: string; - // (undocumented) static fromJSON(json: string | object): OAuthCredential | null; // Warning: (ae-forgotten-export) The symbol "OAuthCredentialParams" needs to be exported by the entry point index.d.ts // @@ -388,15 +363,12 @@ export class OAuthCredential extends AuthCredential implements OAuthCredential_2 _getIdTokenResponse(auth: AuthInternal): Promise; // @internal (undocumented) _getReauthenticationResolver(auth: AuthInternal): Promise; - // (undocumented) idToken?: string; // @internal (undocumented) _linkToIdToken(auth: AuthInternal, idToken: string): Promise; // @internal (undocumented) nonce?: string; - // (undocumented) secret?: string; - // (undocumented) toJSON(): object; } @@ -411,11 +383,11 @@ export interface OAuthCredentialOptions { export class OAuthProvider implements AuthProvider { constructor(providerId: string); addScope(scope: string): AuthProvider; - credential(params: OAuthCredentialOptions): OAuthCredential_2; - static credentialFromError(error: FirebaseError): OAuthCredential_2 | null; + credential(params: OAuthCredentialOptions): OAuthCredential; + static credentialFromError(error: FirebaseError): OAuthCredential | null; // (undocumented) - static credentialFromJSON(json: object | string): OAuthCredential_2; - static credentialFromResult(userCredential: UserCredential): OAuthCredential_2 | null; + static credentialFromJSON(json: object | string): OAuthCredential; + static credentialFromResult(userCredential: UserCredential): OAuthCredential | null; // @internal (undocumented) defaultLanguageCode: string | null; getCustomParameters(): CustomParameters; @@ -460,10 +432,10 @@ export interface Persistence { readonly type: 'SESSION' | 'LOCAL' | 'NONE'; } -// Warning: (ae-forgotten-export) The symbol "PhoneAuthCredential" needs to be exported by the entry point index.d.ts -// -// @public (undocumented) -export class PhoneAuthCredential extends AuthCredential implements PhoneAuthCredential_2 { +// @public +export class PhoneAuthCredential extends AuthCredential { + // Warning: (ae-unresolved-inheritdoc-reference) The @inheritDoc reference could not be resolved: No member was found with name "fromJSON" + // // (undocumented) static fromJSON(json: object | string): PhoneAuthCredential | null; // @internal (undocumented) @@ -480,26 +452,18 @@ export class PhoneAuthCredential extends AuthCredential implements PhoneAuthCred // // @internal (undocumented) _makeVerificationRequest(): SignInWithPhoneNumberRequest; - // (undocumented) toJSON(): object; } -// Warning: (ae-forgotten-export) The symbol "PhoneAuthProvider" needs to be exported by the entry point index.d.ts -// -// @public (undocumented) -export class PhoneAuthProvider implements PhoneAuthProvider_2 { +// @public +export class PhoneAuthProvider { constructor(auth: Auth); - // (undocumented) static credential(verificationId: string, verificationCode: string): PhoneAuthCredential; // (undocumented) - static credentialFromResult(userCredential: UserCredential): AuthCredential_2 | null; - // (undocumented) + static credentialFromResult(userCredential: UserCredential): AuthCredential | null; static readonly PHONE_SIGN_IN_METHOD = SignInMethod.PHONE; - // (undocumented) static readonly PROVIDER_ID = ProviderId.PHONE; - // (undocumented) readonly providerId = ProviderId.PHONE; - // (undocumented) verifyPhoneNumber(phoneOptions: PhoneInfoOptions | string, applicationVerifier: ApplicationVerifier): Promise; } @@ -516,12 +480,9 @@ export interface PhoneMultiFactorEnrollInfoOptions { session: MultiFactorSession; } -// Warning: (ae-forgotten-export) The symbol "PhoneMultiFactorGenerator" needs to be exported by the entry point index.d.ts -// -// @public (undocumented) -export class PhoneMultiFactorGenerator implements PhoneMultiFactorGenerator_2 { - // (undocumented) - static assertion(credential: PhoneAuthCredential_2): PhoneMultiFactorAssertion; +// @public +export class PhoneMultiFactorGenerator { + static assertion(credential: PhoneAuthCredential): PhoneMultiFactorAssertion; } // @public @@ -573,7 +534,7 @@ export interface ReactNativeAsyncStorage { } // @public -export function reauthenticateWithCredential(user: User, credential: AuthCredential_2): Promise; +export function reauthenticateWithCredential(user: User, credential: AuthCredential): Promise; // @public export function reauthenticateWithPhoneNumber(user: User, phoneNumber: string, appVerifier: ApplicationVerifier): Promise; @@ -584,26 +545,21 @@ export function reauthenticateWithPopup(user: User, provider: AuthProvider, reso // @public export function reauthenticateWithRedirect(user: User, provider: AuthProvider, resolver?: PopupRedirectResolver): Promise; -// Warning: (ae-forgotten-export) The symbol "RecaptchaVerifier" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "ApplicationVerifierInternal" needs to be exported by the entry point index.d.ts // -// @public (undocumented) -export class RecaptchaVerifier implements RecaptchaVerifier_2, ApplicationVerifierInternal { +// @public +export class RecaptchaVerifier implements ApplicationVerifierInternal { // Warning: (ae-forgotten-export) The symbol "Parameters" needs to be exported by the entry point index.d.ts constructor(containerOrId: HTMLElement | string, parameters: Parameters_2, authExtern: Auth); - // (undocumented) clear(): void; // Warning: (ae-forgotten-export) The symbol "ReCaptchaLoader" needs to be exported by the entry point index.d.ts // // @internal (undocumented) readonly _recaptchaLoader: ReCaptchaLoader; - // (undocumented) render(): Promise; // @internal (undocumented) _reset(): void; - // (undocumented) readonly type = "recaptcha"; - // (undocumented) verify(): Promise; } @@ -646,7 +602,7 @@ export const enum SignInMethod { } // @public -export function signInWithCredential(auth: Auth, credential: AuthCredential_2): Promise; +export function signInWithCredential(auth: Auth, credential: AuthCredential): Promise; // @public export function signInWithCustomToken(auth: Auth, customToken: string): Promise; @@ -672,9 +628,9 @@ export function signOut(auth: Auth): Promise; // @public export class TwitterAuthProvider extends OAuthProvider { constructor(); - static credential(token: string, secret: string): OAuthCredential_2; - static credentialFromError(error: FirebaseError): OAuthCredential_2 | null; - static credentialFromResult(userCredential: UserCredential): OAuthCredential_2 | null; + static credential(token: string, secret: string): OAuthCredential; + static credentialFromError(error: FirebaseError): OAuthCredential | null; + static credentialFromResult(userCredential: UserCredential): OAuthCredential | null; // (undocumented) static readonly PROVIDER_ID = ProviderId.TWITTER; // (undocumented) @@ -694,7 +650,7 @@ export function updateEmail(user: User, newEmail: string): Promise; export function updatePassword(user: User, newPassword: string): Promise; // @public -export function updatePhoneNumber(user: User, credential: PhoneAuthCredential_2): Promise; +export function updatePhoneNumber(user: User, credential: PhoneAuthCredential): Promise; // Warning: (ae-forgotten-export) The symbol "Profile" needs to be exported by the entry point index.d.ts // diff --git a/packages-exp/auth-exp/index.ts b/packages-exp/auth-exp/index.ts index c87b72d4628..0e54d9cba4a 100644 --- a/packages-exp/auth-exp/index.ts +++ b/packages-exp/auth-exp/index.ts @@ -104,7 +104,7 @@ export { RecaptchaVerifier } from './src/platform_browser/recaptcha/recaptcha_ve export { browserPopupRedirectResolver } from './src/platform_browser/popup_redirect'; // MFA -export { PhoneMultiFactorGeneratorImpl as PhoneMultiFactorGenerator } from './src/platform_browser/mfa/assertions/phone'; +export { PhoneMultiFactorGenerator } from './src/platform_browser/mfa/assertions/phone'; /** * Initializes an Auth instance with platform specific default dependencies. diff --git a/packages-exp/auth-exp/src/core/action_code_url.ts b/packages-exp/auth-exp/src/core/action_code_url.ts index 0e7cb0db243..ea353138728 100644 --- a/packages-exp/auth-exp/src/core/action_code_url.ts +++ b/packages-exp/auth-exp/src/core/action_code_url.ts @@ -15,10 +15,7 @@ * limitations under the License. */ -import { - ActionCodeOperation, - ActionCodeURL as ActionCodeURLType -} from '../model/public_types'; +import { ActionCodeOperation } from '../model/public_types'; import { AuthErrorCode } from './errors'; import { _assert } from './util/assert'; @@ -79,22 +76,36 @@ function parseDeepLink(url: string): string { } /** - * {@inheritDoc @firebase/auth-types#ActionCodeURL} + * A utility class to parse email action URLs such as password reset, email verification, + * email link sign in, etc. * * @public */ -export class ActionCodeURL implements ActionCodeURLType { - /** {@inheritDoc @firebase/auth-types#ActionCodeURL.apiKey} */ +export class ActionCodeURL { + /** + * The API key of the email action link. + */ readonly apiKey: string; - /** {@inheritDoc @firebase/auth-types#ActionCodeURL.code} */ + /** + * The action code of the email action link. + */ readonly code: string; - /** {@inheritDoc @firebase/auth-types#ActionCodeURL.continueUrl} */ + /** + * The continue URL of the email action link. Null if not provided. + */ readonly continueUrl: string | null; - /** {@inheritDoc @firebase/auth-types#ActionCodeURL.languageCode} */ + /** + * The language code of the email action link. Null if not provided. + */ readonly languageCode: string | null; - /** {@inheritDoc @firebase/auth-types#ActionCodeURL.operation} */ + /** + * The action performed by the email action link. It returns from one of the types from + * {@link ActionCodeInfo} + */ readonly operation: ActionCodeOperation; - /** {@inheritDoc @firebase/auth-types#ActionCodeURL.tenantId} */ + /** + * The tenant ID of the email action link. Null if the email action is from the parent project. + */ readonly tenantId: string | null; /** @@ -118,7 +129,15 @@ export class ActionCodeURL implements ActionCodeURLType { this.tenantId = uri.searchParams.get(QueryField.TENANT_ID); } - /** {@inheritDoc @firebase/auth-types#ActionCodeURL.parseLink} */ + /** + * Parses the email action link string and returns an {@link ActionCodeURL} if the link is valid, + * otherwise returns null. + * + * @param link - The email action link string. + * @returns The ActionCodeURL object, or null if the link is invalid. + * + * @public + */ static parseLink(link: string): ActionCodeURL | null { const actionLink = parseDeepLink(link); try { diff --git a/packages-exp/auth-exp/src/core/credentials/auth_credential.ts b/packages-exp/auth-exp/src/core/credentials/auth_credential.ts index f5f47a117a0..7b118704812 100644 --- a/packages-exp/auth-exp/src/core/credentials/auth_credential.ts +++ b/packages-exp/auth-exp/src/core/credentials/auth_credential.ts @@ -21,18 +21,39 @@ import { IdTokenResponse } from '../../model/id_token'; import { debugFail } from '../util/assert'; /** - * {@inheritdoc @firebase/auth-types#AuthCredential} + * Interface that represents the credentials returned by an {@link AuthProvider}. + * + * @remarks + * Implementations specify the details about each auth provider's credential requirements. * * @public */ export class AuthCredential { /** @internal */ protected constructor( + /** + * The authentication provider ID for the credential. + * + * @remarks + * For example, 'facebook.com', or 'google.com'. + */ readonly providerId: string, + /** + * The authentication sign in method for the credential. + * + * @remarks + * For example, {@link SignInMethod.EMAIL_PASSWORD}, or + * {@link SignInMethod.EMAIL_LINK}. This corresponds to the sign-in method + * identifier as returned in {@link fetchSignInMethodsForEmail}. + */ readonly signInMethod: string ) {} - /** {@inheritdoc @firebase/auth-types#AuthCredential.toJSON} */ + /** + * Returns a JSON-serializable representation of this object. + * + * @returns a JSON-serializable representation of this object. + */ toJSON(): object { return debugFail('not implemented'); } diff --git a/packages-exp/auth-exp/src/core/credentials/email.ts b/packages-exp/auth-exp/src/core/credentials/email.ts index 2bd8d37c47e..8a152c3e2e8 100644 --- a/packages-exp/auth-exp/src/core/credentials/email.ts +++ b/packages-exp/auth-exp/src/core/credentials/email.ts @@ -15,11 +15,7 @@ * limitations under the License. */ -import { - AuthCredential as AuthCredentialPublic, - ProviderId, - SignInMethod -} from '../../model/public_types'; +import { ProviderId, SignInMethod } from '../../model/public_types'; import { updateEmailPassword } from '../../api/account_management/email_and_password'; import { signInWithPassword } from '../../api/authentication/email_and_password'; @@ -35,17 +31,15 @@ import { AuthCredential } from './auth_credential'; /** * Interface that represents the credentials returned by {@link EmailAuthProvider} for - * {@link @firebase/auth-types#ProviderId.PASSWORD} + * {@link ProviderId.PASSWORD} * * @remarks - * Covers both {@link @firebase/auth-types#SignInMethod.EMAIL_PASSWORD} and - * {@link @firebase/auth-types#SignInMethod.EMAIL_LINK}. + * Covers both {@link SignInMethod.EMAIL_PASSWORD} and + * {@link SignInMethod.EMAIL_LINK}. * * @public */ -export class EmailAuthCredential - extends AuthCredential - implements AuthCredentialPublic { +export class EmailAuthCredential extends AuthCredential { /** @internal */ private constructor( readonly email: string, @@ -82,7 +76,7 @@ export class EmailAuthCredential ); } - /** {@inheritdoc @firebase/auth-types#AuthCredential.toJSON} */ + /** {@inheritdoc AuthCredential.toJSON} */ toJSON(): object { return { email: this.email, @@ -92,7 +86,14 @@ export class EmailAuthCredential }; } - /** {@inheritdoc @firebase/auth-types#AuthCredential.fromJSON} */ + /** + * Static method to deserialize a JSON representation of an object into an {@link AuthCredential}. + * + * @param json - Either `object` or the stringified representation of the object. When string is + * provided, `JSON.parse` would be called first. + * + * @returns If the JSON input does not represent an {@link AuthCredential}, null is returned. + */ static fromJSON(json: object | string): EmailAuthCredential | null { const obj = typeof json === 'string' ? JSON.parse(json) : json; if (obj?.email && obj?.password) { diff --git a/packages-exp/auth-exp/src/core/credentials/index.ts b/packages-exp/auth-exp/src/core/credentials/index.ts index 44988c34deb..3585da618b0 100644 --- a/packages-exp/auth-exp/src/core/credentials/index.ts +++ b/packages-exp/auth-exp/src/core/credentials/index.ts @@ -21,4 +21,4 @@ export { AuthCredential } from './auth_credential'; export { EmailAuthCredential } from './email'; export { OAuthCredential } from './oauth'; -export { PhoneAuthCredentialImpl as PhoneAuthCredential } from './phone'; +export { PhoneAuthCredential as PhoneAuthCredential } from './phone'; diff --git a/packages-exp/auth-exp/src/core/credentials/oauth.ts b/packages-exp/auth-exp/src/core/credentials/oauth.ts index de20ad7309a..6afc5537671 100644 --- a/packages-exp/auth-exp/src/core/credentials/oauth.ts +++ b/packages-exp/auth-exp/src/core/credentials/oauth.ts @@ -15,7 +15,6 @@ * limitations under the License. */ -import { OAuthCredential as OAuthCredentialPublic } from '../../model/public_types'; import { querystring } from '@firebase/util'; import { @@ -50,18 +49,31 @@ export interface OAuthCredentialParams { } /** - * {@inheritdoc @firebase/auth-types#OAuthCredential} + * Represents the OAuth credentials returned by an {@link OAuthProvider}. + * + * @remarks + * Implementations specify the details about each auth provider's credential requirements. * * @public */ -export class OAuthCredential - extends AuthCredential - implements OAuthCredentialPublic { - /** {@inheritdoc @firebase/auth-types#OAuthCredential.idToken} @readonly */ +export class OAuthCredential extends AuthCredential { + /** + * The OAuth ID token associated with the credential if it belongs to an OIDC provider, + * such as `google.com`. + * @readonly + */ idToken?: string; - /** {@inheritdoc @firebase/auth-types#OAuthCredential.accessToken} @readonly */ + /** + * The OAuth access token associated with the credential if it belongs to an + * {@link OAuthProvider}, such as `facebook.com`, `twitter.com`, etc. + * @readonly + */ accessToken?: string; - /** {@inheritdoc @firebase/auth-types#OAuthCredential.secret} @readonly */ + /** + * The OAuth access token secret associated with the credential if it belongs to an OAuth 1.0 + * provider, such as `twitter.com`. + * @readonly + */ secret?: string; /** @internal */ nonce?: string; @@ -100,7 +112,7 @@ export class OAuthCredential return cred; } - /** {@inheritdoc @firebase/auth-types#OAuthCredential.toJSON} */ + /** {@inheritdoc AuthCredential.toJSON} */ toJSON(): object { return { idToken: this.idToken, @@ -113,7 +125,15 @@ export class OAuthCredential }; } - /** {@inheritdoc @firebase/auth-types#OAuthCredential.fromJSON} */ + /** + * Static method to deserialize a JSON representation of an object into an + * {@link AuthCredential}. + * + * @param json - Input can be either Object or the stringified representation of the object. + * When string is provided, JSON.parse would be called first. + * + * @returns If the JSON input does not represent an {@link AuthCredential}, null is returned. + */ static fromJSON(json: string | object): OAuthCredential | null { const obj = typeof json === 'string' ? JSON.parse(json) : json; const { providerId, signInMethod, ...rest }: Partial = obj; diff --git a/packages-exp/auth-exp/src/core/credentials/phone.test.ts b/packages-exp/auth-exp/src/core/credentials/phone.test.ts index e450f431d08..1dedb5a8cff 100644 --- a/packages-exp/auth-exp/src/core/credentials/phone.test.ts +++ b/packages-exp/auth-exp/src/core/credentials/phone.test.ts @@ -22,7 +22,7 @@ import { testAuth, TestAuth } from '../../../test/helpers/mock_auth'; import * as fetch from '../../../test/helpers/mock_fetch'; import { Endpoint } from '../../api'; import { IdTokenResponse, IdTokenResponseKind } from '../../model/id_token'; -import { PhoneAuthCredentialImpl } from '../credentials/phone'; +import { PhoneAuthCredential } from '../credentials/phone'; describe('core/credentials/phone', () => { let auth: TestAuth; @@ -46,7 +46,7 @@ describe('core/credentials/phone', () => { }; it('calls the endpoint with session and code', async () => { - const cred = PhoneAuthCredentialImpl._fromVerification( + const cred = PhoneAuthCredential._fromVerification( 'session-info', 'code' ); @@ -61,7 +61,7 @@ describe('core/credentials/phone', () => { }); it('calls the endpoint with proof and number', async () => { - const cred = PhoneAuthCredentialImpl._fromTokenResponse( + const cred = PhoneAuthCredential._fromTokenResponse( 'number', 'temp-proof' ); @@ -86,7 +86,7 @@ describe('core/credentials/phone', () => { }; it('calls the endpoint with session and code', async () => { - const cred = PhoneAuthCredentialImpl._fromVerification( + const cred = PhoneAuthCredential._fromVerification( 'session-info', 'code' ); @@ -102,7 +102,7 @@ describe('core/credentials/phone', () => { }); it('calls the endpoint with proof and number', async () => { - const cred = PhoneAuthCredentialImpl._fromTokenResponse( + const cred = PhoneAuthCredential._fromTokenResponse( 'number', 'temp-proof' ); @@ -120,7 +120,7 @@ describe('core/credentials/phone', () => { context('#toJSON', () => { it('fills out the object with everything that is set', () => { - const cred = PhoneAuthCredentialImpl._fromVerification('id', 'code'); + const cred = PhoneAuthCredential._fromVerification('id', 'code'); expect(cred.toJSON()).to.eql({ providerId: 'phone', @@ -130,10 +130,7 @@ describe('core/credentials/phone', () => { }); it('omits missing fields', () => { - const cred = PhoneAuthCredentialImpl._fromTokenResponse( - 'number', - 'proof' - ); + const cred = PhoneAuthCredential._fromTokenResponse('number', 'proof'); expect(cred.toJSON()).to.eql({ providerId: 'phone', @@ -145,9 +142,7 @@ describe('core/credentials/phone', () => { context('.fromJSON', () => { it('works if passed a string', () => { - const cred = PhoneAuthCredentialImpl.fromJSON( - '{"phoneNumber": "number"}' - ); + const cred = PhoneAuthCredential.fromJSON('{"phoneNumber": "number"}'); expect(cred?.toJSON()).to.eql({ providerId: 'phone', phoneNumber: 'number' @@ -155,7 +150,7 @@ describe('core/credentials/phone', () => { }); it('works if passed an object', () => { - const cred = PhoneAuthCredentialImpl.fromJSON({ + const cred = PhoneAuthCredential.fromJSON({ temporaryProof: 'proof', phoneNumber: 'number', verificationId: 'id', @@ -171,7 +166,7 @@ describe('core/credentials/phone', () => { }); it('returns null if object contains no matching fields', () => { - expect(PhoneAuthCredentialImpl.fromJSON({})).to.be.null; + expect(PhoneAuthCredential.fromJSON({})).to.be.null; }); }); }); diff --git a/packages-exp/auth-exp/src/core/credentials/phone.ts b/packages-exp/auth-exp/src/core/credentials/phone.ts index c0d0cff24d1..340b84b498c 100644 --- a/packages-exp/auth-exp/src/core/credentials/phone.ts +++ b/packages-exp/auth-exp/src/core/credentials/phone.ts @@ -15,11 +15,7 @@ * limitations under the License. */ -import { - PhoneAuthCredential, - ProviderId, - SignInMethod -} from '../../model/public_types'; +import { ProviderId, SignInMethod } from '../../model/public_types'; import { PhoneOrOauthTokenResponse } from '../../api/authentication/mfa'; import { @@ -40,13 +36,11 @@ export interface PhoneAuthCredentialParameters { } /** - * {@inheritdoc @firebase/auth-types#PhoneAuthCredential} + * Represents the credentials returned by {@link PhoneAuthProvider}. * * @public */ -export class PhoneAuthCredentialImpl - extends AuthCredential - implements PhoneAuthCredential { +export class PhoneAuthCredential extends AuthCredential { private constructor(private readonly params: PhoneAuthCredentialParameters) { super(ProviderId.PHONE, SignInMethod.PHONE); } @@ -55,16 +49,16 @@ export class PhoneAuthCredentialImpl static _fromVerification( verificationId: string, verificationCode: string - ): PhoneAuthCredentialImpl { - return new PhoneAuthCredentialImpl({ verificationId, verificationCode }); + ): PhoneAuthCredential { + return new PhoneAuthCredential({ verificationId, verificationCode }); } /** @internal */ static _fromTokenResponse( phoneNumber: string, temporaryProof: string - ): PhoneAuthCredentialImpl { - return new PhoneAuthCredentialImpl({ phoneNumber, temporaryProof }); + ): PhoneAuthCredential { + return new PhoneAuthCredential({ phoneNumber, temporaryProof }); } /** @internal */ @@ -106,7 +100,7 @@ export class PhoneAuthCredentialImpl }; } - /** {@inheritdoc @firebase/auth-types#toJSON} */ + /** {@inheritdoc AuthCredential.toJSON} */ toJSON(): object { const obj: Record = { providerId: this.providerId @@ -127,8 +121,8 @@ export class PhoneAuthCredentialImpl return obj; } - /** {@inheritdoc @firebase/auth-types#fromJSON} */ - static fromJSON(json: object | string): PhoneAuthCredentialImpl | null { + /** {@inheritdoc AuthCredential.fromJSON} */ + static fromJSON(json: object | string): PhoneAuthCredential | null { if (typeof json === 'string') { json = JSON.parse(json); } @@ -148,7 +142,7 @@ export class PhoneAuthCredentialImpl return null; } - return new PhoneAuthCredentialImpl({ + return new PhoneAuthCredential({ verificationId, verificationCode, phoneNumber, diff --git a/packages-exp/auth-exp/src/core/errors.ts b/packages-exp/auth-exp/src/core/errors.ts index d41f2e0cde6..09ed38f037c 100644 --- a/packages-exp/auth-exp/src/core/errors.ts +++ b/packages-exp/auth-exp/src/core/errors.ts @@ -16,11 +16,12 @@ */ // eslint-disable-next-line import/no-extraneous-dependencies -import { AuthCredential, AuthErrorMap, User } from '../model/public_types'; +import { AuthErrorMap, User } from '../model/public_types'; import { ErrorFactory, ErrorMap } from '@firebase/util'; import { IdTokenMfaResponse } from '../api/authentication/mfa'; import { AppName } from '../model/auth'; +import { AuthCredential } from './credentials'; /** * Enumeration of Firebase Auth error codes. diff --git a/packages-exp/auth-exp/src/core/index.ts b/packages-exp/auth-exp/src/core/index.ts index a0422cf2bd2..ff9e2b85fdf 100644 --- a/packages-exp/auth-exp/src/core/index.ts +++ b/packages-exp/auth-exp/src/core/index.ts @@ -140,7 +140,7 @@ export { useAuthEmulator } from './auth/emulator'; export { AuthCredential } from './credentials'; export { EmailAuthCredential } from './credentials/email'; export { OAuthCredential } from './credentials/oauth'; -export { PhoneAuthCredentialImpl as PhoneAuthCredential } from './credentials/phone'; +export { PhoneAuthCredential } from './credentials/phone'; // persistence export { inMemoryPersistence } from './persistence/in_memory'; diff --git a/packages-exp/auth-exp/src/core/providers/email.ts b/packages-exp/auth-exp/src/core/providers/email.ts index 62d078518ea..9e11e11eb1d 100644 --- a/packages-exp/auth-exp/src/core/providers/email.ts +++ b/packages-exp/auth-exp/src/core/providers/email.ts @@ -16,9 +16,9 @@ */ import { - EmailAuthProvider as EmailAuthProviderPublic, ProviderId, - SignInMethod + SignInMethod, + AuthProvider } from '../../model/public_types'; import { ActionCodeURL } from '../action_code_url'; @@ -27,26 +27,72 @@ import { AuthErrorCode } from '../errors'; import { _assert } from '../util/assert'; /** - * {@inheritdoc @firebase/auth-types#EmailAuthProvider} + * Provider for generating {@link EmailAuthCredential}. * * @public */ -export class EmailAuthProvider implements EmailAuthProviderPublic { - /** {@inheritdoc @firebase/auth-types#EmailAuthProvider.PROVIDER_ID} */ +export class EmailAuthProvider implements AuthProvider { + /** + * Always set to {@link ProviderId.PASSWORD}, even for email link. + */ static readonly PROVIDER_ID = ProviderId.PASSWORD; - /** {@inheritdoc @firebase/auth-types#EmailAuthProvider.EMAIL_PASSWORD_SIGN_IN_METHOD} */ + /** + * Always set to {@link SignInMethod.EMAIL_PASSWORD}. + */ static readonly EMAIL_PASSWORD_SIGN_IN_METHOD = SignInMethod.EMAIL_PASSWORD; - /** {@inheritdoc @firebase/auth-types#EmailAuthProvider.EMAIL_LINK_SIGN_IN_METHOD} */ + /** + * Always set to {@link SignInMethod.EMAIL_LINK}. + */ static readonly EMAIL_LINK_SIGN_IN_METHOD = SignInMethod.EMAIL_LINK; - /** {@inheritdoc @firebase/auth-types#EmailAuthProvider.providerId} */ + /** + * Always set to {@link ProviderId.PASSWORD}, even for email link. + */ readonly providerId = EmailAuthProvider.PROVIDER_ID; - /** {@inheritdoc @firebase/auth-types#EmailAuthProvider.credential} */ + /** + * Initialize an {@link AuthCredential} using an email and password. + * + * @example + * ```javascript + * const authCredential = EmailAuthProvider.credential(email, password); + * const userCredential = await signInWithCredential(auth, authCredential); + * ``` + * + * @example + * ```javascript + * const userCredential = await signInWithEmailAndPassword(auth, email, password); + * ``` + * + * @param email - Email address. + * @param password - User account password. + * @returns The auth provider credential. + */ static credential(email: string, password: string): EmailAuthCredential { return EmailAuthCredential._fromEmailAndPassword(email, password); } - /** {@inheritdoc @firebase/auth-types#EmailAuthProvider.credentialWithLink} */ + /** + * Initialize an {@link AuthCredential} using an email and an email link after a sign in with + * email link operation. + * + * @example + * ```javascript + * const authCredential = EmailAuthProvider.credentialWithLink(auth, email, emailLink); + * const userCredential = await signInWithCredential(auth, authCredential); + * ``` + * + * @example + * ```javascript + * await sendSignInLinkToEmail(auth, email); + * // Obtain emailLink from user. + * const userCredential = await signInWithEmailLink(auth, email, emailLink); + * ``` + * + * @param auth - The Auth instance used to verify the link. + * @param email - Email address. + * @param emailLink - Sign-in email link. + * @returns - The auth provider credential. + */ static credentialWithLink( email: string, emailLink: string diff --git a/packages-exp/auth-exp/src/core/providers/facebook.ts b/packages-exp/auth-exp/src/core/providers/facebook.ts index fea4e6a99aa..98eb052e35b 100644 --- a/packages-exp/auth-exp/src/core/providers/facebook.ts +++ b/packages-exp/auth-exp/src/core/providers/facebook.ts @@ -16,7 +16,6 @@ */ import { - OAuthCredential, ProviderId, SignInMethod, UserCredential @@ -25,7 +24,7 @@ import { FirebaseError } from '@firebase/util'; import { TaggedWithTokenResponse } from '../../model/id_token'; import { UserCredentialInternal } from '../../model/user'; -import { OAuthCredential as OAuthCredentialImpl } from '../credentials/oauth'; +import { OAuthCredential } from '../credentials/oauth'; import { OAuthProvider } from './oauth'; /** @@ -90,7 +89,7 @@ export class FacebookAuthProvider extends OAuthProvider { * @param accessToken - Facebook access token. */ static credential(accessToken: string): OAuthCredential { - return OAuthCredentialImpl._fromParams({ + return OAuthCredential._fromParams({ providerId: FacebookAuthProvider.PROVIDER_ID, signInMethod: FacebookAuthProvider.FACEBOOK_SIGN_IN_METHOD, accessToken diff --git a/packages-exp/auth-exp/src/core/providers/github.ts b/packages-exp/auth-exp/src/core/providers/github.ts index 33ecefd0bf1..dbbb6c5bbf6 100644 --- a/packages-exp/auth-exp/src/core/providers/github.ts +++ b/packages-exp/auth-exp/src/core/providers/github.ts @@ -16,7 +16,6 @@ */ import { - OAuthCredential, ProviderId, SignInMethod, UserCredential @@ -25,7 +24,7 @@ import { FirebaseError } from '@firebase/util'; import { TaggedWithTokenResponse } from '../../model/id_token'; import { UserCredentialInternal } from '../../model/user'; -import { OAuthCredential as OAuthCredentialImpl } from '../credentials/oauth'; +import { OAuthCredential } from '../credentials/oauth'; import { OAuthProvider } from './oauth'; /** @@ -86,7 +85,7 @@ export class GithubAuthProvider extends OAuthProvider { * @param accessToken - Github access token. */ static credential(accessToken: string): OAuthCredential { - return OAuthCredentialImpl._fromParams({ + return OAuthCredential._fromParams({ providerId: GithubAuthProvider.PROVIDER_ID, signInMethod: GithubAuthProvider.GITHUB_SIGN_IN_METHOD, accessToken diff --git a/packages-exp/auth-exp/src/core/providers/google.ts b/packages-exp/auth-exp/src/core/providers/google.ts index 8ed4a7927e1..35bbf69963d 100644 --- a/packages-exp/auth-exp/src/core/providers/google.ts +++ b/packages-exp/auth-exp/src/core/providers/google.ts @@ -16,7 +16,6 @@ */ import { - OAuthCredential, ProviderId, SignInMethod, UserCredential @@ -26,7 +25,7 @@ import { FirebaseError } from '@firebase/util'; import { SignInWithIdpResponse } from '../../api/authentication/idp'; import { TaggedWithTokenResponse } from '../../model/id_token'; import { UserCredentialInternal } from '../../model/user'; -import { OAuthCredential as OAuthCredentialImpl } from '../credentials/oauth'; +import { OAuthCredential } from '../credentials/oauth'; import { OAuthProvider } from './oauth'; /** @@ -98,7 +97,7 @@ export class GoogleAuthProvider extends OAuthProvider { idToken?: string | null, accessToken?: string | null ): OAuthCredential { - return OAuthCredentialImpl._fromParams({ + return OAuthCredential._fromParams({ providerId: GoogleAuthProvider.PROVIDER_ID, signInMethod: GoogleAuthProvider.GOOGLE_SIGN_IN_METHOD, idToken, diff --git a/packages-exp/auth-exp/src/core/providers/oauth.ts b/packages-exp/auth-exp/src/core/providers/oauth.ts index 082817bfe0e..0ff6142eeef 100644 --- a/packages-exp/auth-exp/src/core/providers/oauth.ts +++ b/packages-exp/auth-exp/src/core/providers/oauth.ts @@ -15,16 +15,12 @@ * limitations under the License. */ -import { - AuthProvider, - OAuthCredential, - UserCredential -} from '../../model/public_types'; +import { AuthProvider, UserCredential } from '../../model/public_types'; import { _assert } from '../util/assert'; import { AuthErrorCode } from '../errors'; -import { OAuthCredential as OAuthCredentialImpl } from '../credentials/oauth'; +import { OAuthCredential } from '../credentials/oauth'; import { UserCredentialInternal } from '../../model/user'; import { FirebaseError } from '@firebase/util'; import { TaggedWithTokenResponse } from '../../model/id_token'; @@ -125,7 +121,7 @@ export class OAuthProvider implements AuthProvider { 'providerId' in obj && 'signInMethod' in obj, AuthErrorCode.ARGUMENT_ERROR ); - return OAuthCredentialImpl._fromParams(obj); + return OAuthCredential._fromParams(obj); } /** @@ -152,7 +148,7 @@ export class OAuthProvider implements AuthProvider { credential(params: OAuthCredentialOptions): OAuthCredential { _assert(params.idToken && params.accessToken, AuthErrorCode.ARGUMENT_ERROR); // For OAuthCredential, sign in method is same as providerId. - return OAuthCredentialImpl._fromParams({ + return OAuthCredential._fromParams({ providerId: this.providerId, signInMethod: this.providerId, ...params diff --git a/packages-exp/auth-exp/src/core/providers/twitter.ts b/packages-exp/auth-exp/src/core/providers/twitter.ts index 1a2bd730765..1e926fb29a9 100644 --- a/packages-exp/auth-exp/src/core/providers/twitter.ts +++ b/packages-exp/auth-exp/src/core/providers/twitter.ts @@ -33,7 +33,6 @@ */ import { - OAuthCredential, ProviderId, SignInMethod, UserCredential @@ -43,7 +42,7 @@ import { FirebaseError } from '@firebase/util'; import { SignInWithIdpResponse } from '../../api/authentication/idp'; import { TaggedWithTokenResponse } from '../../model/id_token'; import { UserCredentialInternal } from '../../model/user'; -import { OAuthCredential as OAuthCredentialImpl } from '../credentials/oauth'; +import { OAuthCredential } from '../credentials/oauth'; import { OAuthProvider } from './oauth'; /** @@ -100,7 +99,7 @@ export class TwitterAuthProvider extends OAuthProvider { * @param secret - Twitter secret. */ static credential(token: string, secret: string): OAuthCredential { - return OAuthCredentialImpl._fromParams({ + return OAuthCredential._fromParams({ providerId: TwitterAuthProvider.PROVIDER_ID, signInMethod: TwitterAuthProvider.TWITTER_SIGN_IN_METHOD, oauthToken: token, diff --git a/packages-exp/auth-exp/src/core/strategies/credential.ts b/packages-exp/auth-exp/src/core/strategies/credential.ts index c09f267c137..ad1893f9d28 100644 --- a/packages-exp/auth-exp/src/core/strategies/credential.ts +++ b/packages-exp/auth-exp/src/core/strategies/credential.ts @@ -19,14 +19,13 @@ import { OperationType, UserCredential, Auth, - AuthCredential, User } from '../../model/public_types'; import { _processCredentialSavingMfaContextIfNecessary } from '../../mfa/mfa_error'; import { AuthInternal } from '../../model/auth'; import { UserInternal } from '../../model/user'; -import { AuthCredential as AuthCredentialImpl } from '../credentials'; +import { AuthCredential } from '../credentials'; import { _assertLinkedStatus, _link } from '../user/link_unlink'; import { _reauthenticate } from '../user/reauthenticate'; import { UserCredentialImpl } from '../user/user_credential_impl'; @@ -34,7 +33,7 @@ import { _castAuth } from '../auth/auth_impl'; export async function _signInWithCredential( auth: AuthInternal, - credential: AuthCredentialImpl, + credential: AuthCredential, bypassAuthState = false ): Promise { const operationType = OperationType.SIGN_IN; @@ -70,10 +69,7 @@ export async function signInWithCredential( auth: Auth, credential: AuthCredential ): Promise { - return _signInWithCredential( - _castAuth(auth), - credential as AuthCredentialImpl - ); + return _signInWithCredential(_castAuth(auth), credential); } /** @@ -95,7 +91,7 @@ export async function linkWithCredential( await _assertLinkedStatus(false, userInternal, credential.providerId); - return _link(userInternal, credential as AuthCredentialImpl); + return _link(userInternal, credential); } /** @@ -104,7 +100,7 @@ export async function linkWithCredential( * @remarks * Use before operations such as {@link updatePassword} that require tokens from recent sign-in * attempts. This method can be used to recover from a - * {@link AuthErrorCode.CREDENTIAL_TOO_OLD_LOGIN_AGAIN} error. + * {@link debugErrorMap.CREDENTIAL_TOO_OLD_LOGIN_AGAIN} error. * * @param user - The user. * @param credential - The auth credential. @@ -115,8 +111,5 @@ export async function reauthenticateWithCredential( user: User, credential: AuthCredential ): Promise { - return _reauthenticate( - user as UserInternal, - credential as AuthCredentialImpl - ); + return _reauthenticate(user as UserInternal, credential); } diff --git a/packages-exp/auth-exp/src/mfa/mfa_resolver.test.ts b/packages-exp/auth-exp/src/mfa/mfa_resolver.test.ts index dfd6c95583d..73eadafc084 100644 --- a/packages-exp/auth-exp/src/mfa/mfa_resolver.test.ts +++ b/packages-exp/auth-exp/src/mfa/mfa_resolver.test.ts @@ -27,7 +27,7 @@ import { testAuth, testUser, TestAuth } from '../../test/helpers/mock_auth'; import * as mockFetch from '../../test/helpers/mock_fetch'; import { Endpoint } from '../api'; import { APIUserInfo } from '../api/account_management/account'; -import { PhoneAuthCredentialImpl } from '../core/credentials/phone'; +import { PhoneAuthCredential } from '../core/credentials/phone'; import { AuthErrorCode } from '../core/errors'; import { UserInternal, UserCredentialInternal } from '../model/user'; import { MultiFactorAssertionImpl } from './mfa_assertion'; @@ -74,12 +74,12 @@ describe('core/mfa/mfa_resolver/MultiFactorResolver', () => { describe('MultiFactorResolver', () => { let assertion: MultiFactorAssertionImpl; - let secondFactorCredential: PhoneAuthCredentialImpl; + let secondFactorCredential: PhoneAuthCredential; let resolver: MultiFactorResolverImpl; beforeEach(() => { mockFetch.setUp(); - secondFactorCredential = PhoneAuthCredentialImpl._fromVerification( + secondFactorCredential = PhoneAuthCredential._fromVerification( 'verification-id', 'verification-code' ); diff --git a/packages-exp/auth-exp/src/model/public_types.ts b/packages-exp/auth-exp/src/model/public_types.ts index b1ff5abce97..d10c8fbec70 100644 --- a/packages-exp/auth-exp/src/model/public_types.ts +++ b/packages-exp/auth-exp/src/model/public_types.ts @@ -386,21 +386,21 @@ export interface ActionCodeInfo { * The data associated with the action code. * * @remarks - * For the {@link Operation.PASSWORD_RESET}, {@link Operation.VERIFY_EMAIL}, and - * {@link Operation.RECOVER_EMAIL} actions, this object contains an email field with the address + * For the {@link ActionCodeOperation.PASSWORD_RESET}, {@link ActionCodeOperation.VERIFY_EMAIL}, and + * {@link ActionCodeOperation.RECOVER_EMAIL} actions, this object contains an email field with the address * the email was sent to. * - * For the {@link Operation.RECOVER_EMAIL} action, which allows a user to undo an email address + * For the {@link ActionCodeOperation.RECOVER_EMAIL} action, which allows a user to undo an email address * change, this object also contains a `previousEmail` field with the user account's current * email address. After the action completes, the user's email address will revert to the value * in the `email` field from the value in `previousEmail` field. * - * For the {@link Operation.VERIFY_AND_CHANGE_EMAIL} action, which allows a user to verify the + * For the {@link ActionCodeOperation.VERIFY_AND_CHANGE_EMAIL} action, which allows a user to verify the * email before updating it, this object contains a `previousEmail` field with the user account's * email address before updating. After the action completes, the user's email address will be * updated to the value in the `email` field from the value in `previousEmail` field. * - * For the {@link Operation.REVERT_SECOND_FACTOR_ADDITION} action, which allows a user to + * For the {@link ActionCodeOperation.REVERT_SECOND_FACTOR_ADDITION} action, which allows a user to * unenroll a newly added second factor, this object contains a `multiFactorInfo` field with * the information about the second factor. For phone second factor, the `multiFactorInfo` * is a {@link MultiFactorInfo} object, which contains the phone number. @@ -502,51 +502,6 @@ export interface ActionCodeSettings { dynamicLinkDomain?: string; } -/** - * A utility class to parse email action URLs such as password reset, email verification, - * email link sign in, etc. - * - * @public - */ -export declare abstract class ActionCodeURL { - /** - * The API key of the email action link. - */ - readonly apiKey: string; - /** - * The action code of the email action link. - */ - readonly code: string; - /** - * The continue URL of the email action link. Null if not provided. - */ - readonly continueUrl: string | null; - /** - * The language code of the email action link. Null if not provided. - */ - readonly languageCode: string | null; - /** - * The action performed by the email action link. It returns from one of the types from - * {@link @firebase/auth-types#ActionCodeInfo} - */ - readonly operation: ActionCodeOperation; - /** - * The tenant ID of the email action link. Null if the email action is from the parent project. - */ - readonly tenantId: string | null; - - /** - * Parses the email action link string and returns an {@link ActionCodeURL} if the link is valid, - * otherwise returns null. - * - * @param link - The email action link string. - * @returns The ActionCodeURL object, or null if the link is invalid. - * - * @public - */ - static parseLink(link: string): ActionCodeURL | null; -} - /** * A verifier for domain verification and abuse prevention. * @@ -568,161 +523,6 @@ export interface ApplicationVerifier { verify(): Promise; } -/** - * An {@link https://www.google.com/recaptcha/ | reCAPTCHA}-based application verifier. - * - * @public - */ -export declare abstract class RecaptchaVerifier implements ApplicationVerifier { - constructor( - /** - * The reCAPTCHA container parameter. - * - * @remarks - * This has different meaning depending on whether the reCAPTCHA is hidden or visible. For a - * visible reCAPTCHA the container must be empty. If a string is used, it has to correspond to - * an element ID. The corresponding element must also must be in the DOM at the time of - * initialization. - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - container: any | string, - /** - * The optional reCAPTCHA parameters. - * - * @remarks - * Check the reCAPTCHA docs for a comprehensive list. All parameters are accepted except for - * the sitekey. Firebase Auth backend provisions a reCAPTCHA for each project and will - * configure this upon rendering. For an invisible reCAPTCHA, a size key must have the value - * 'invisible'. - */ - parameters?: object | null, - /** - * The corresponding Firebase Auth instance. - * - * @remarks - * If none is provided, the default Firebase Auth instance is used. A Firebase Auth instance - * must be initialized with an API key, otherwise an error will be thrown. - */ - auth?: Auth | null - ); - /** - * Clears the reCAPTCHA widget from the page and destroys the instance. - */ - clear(): void; - /** - * Renders the reCAPTCHA widget on the page. - * - * @returns A Promise that resolves with the reCAPTCHA widget ID. - */ - render(): Promise; - /** - * The application verifier type. - * - * @remarks - * For a reCAPTCHA verifier, this is 'recaptcha'. - */ - readonly type: string; - /** - * Waits for the user to solve the reCAPTCHA and resolves with the reCAPTCHA token. - * - * @returns A Promise for the reCAPTCHA token. - */ - verify(): Promise; -} - -/** - * Interface that represents the credentials returned by an {@link @firebase/auth-types#AuthProvider}. - * - * @remarks - * Implementations specify the details about each auth provider's credential requirements. - * - * @public - */ -export declare abstract class AuthCredential { - /** - * Static method to deserialize a JSON representation of an object into an {@link @firebase/auth-types#AuthCredential}. - * - * @param json - Either `object` or the stringified representation of the object. When string is - * provided, `JSON.parse` would be called first. - * - * @returns If the JSON input does not represent an {@link @firebase/auth-types#AuthCredential}, null is returned. - */ - static fromJSON(json: object | string): AuthCredential | null; - - /** - * The authentication provider ID for the credential. - * - * @remarks - * For example, 'facebook.com', or 'google.com'. - */ - readonly providerId: string; - /** - * The authentication sign in method for the credential. - * - * @remarks - * For example, {@link @firebase/auth-types#SignInMethod.EMAIL_PASSWORD}, or - * {@link @firebase/auth-types#SignInMethod.EMAIL_LINK}. This corresponds to the sign-in method - * identifier as returned in {@link @firebase/auth#fetchSignInMethodsForEmail}. - */ - readonly signInMethod: string; - /** - * Returns a JSON-serializable representation of this object. - * - * @returns a JSON-serializable representation of this object. - */ - toJSON(): object; -} - -/** - * Interface that represents the OAuth credentials returned by an {@link @firebase/auth#OAuthProvider}. - * - * @remarks - * Implementations specify the details about each auth provider's credential requirements. - * - * @public - */ -export declare abstract class OAuthCredential extends AuthCredential { - /** - * Static method to deserialize a JSON representation of an object into an - * {@link @firebase/auth-types#AuthCredential}. - * - * @param json - Input can be either Object or the stringified representation of the object. - * When string is provided, JSON.parse would be called first. - * - * @returns If the JSON input does not represent an {@link @firebase/auth-types#AuthCredential}, null is returned. - */ - static fromJSON(json: object | string): OAuthCredential | null; - - /** - * The OAuth access token associated with the credential if it belongs to an - * {@link @firebase/auth#OAuthProvider}, such as `facebook.com`, `twitter.com`, etc. - */ - readonly accessToken?: string; - /** - * The OAuth ID token associated with the credential if it belongs to an OIDC provider, - * such as `google.com`. - */ - readonly idToken?: string; - /** - * The OAuth access token secret associated with the credential if it belongs to an OAuth 1.0 - * provider, such as `twitter.com`. - */ - readonly secret?: string; -} - -/** - * Interface that represents the credentials returned by a - * {@link @firebase/auth#PhoneAuthProvider}. - * - * @public - */ -export declare abstract class PhoneAuthCredential extends AuthCredential { - /** {@inheritdoc @firebase/auth-types#AuthCredential.fromJSON} */ - static fromJSON(json: object | string): PhoneAuthCredential | null; - /** {@inheritdoc @firebase/auth-types#AuthCredential.toJSON} */ - toJSON(): object; -} - /** * Interface that represents an auth provider, used to facilitate creating {@link @firebase/auth-types#AuthCredential}. * @@ -735,176 +535,6 @@ export interface AuthProvider { readonly providerId: string; } -/** - * Provider for generating {@link @firebase/auth#EmailAuthCredential}. - * - * @public - */ -export declare abstract class EmailAuthProvider implements AuthProvider { - private constructor(); - /** - * Always set to {@link @firebase/auth-types#ProviderId.PASSWORD}, even for email link. - */ - static readonly PROVIDER_ID: ProviderId; - /** - * Always set to {@link @firebase/auth-types#SignInMethod.EMAIL_PASSWORD}. - */ - static readonly EMAIL_PASSWORD_SIGN_IN_METHOD: SignInMethod; - /** - * Always set to {@link @firebase/auth-types#SignInMethod.EMAIL_LINK}. - */ - static readonly EMAIL_LINK_SIGN_IN_METHOD: SignInMethod; - /** - * Initialize an {@link @firebase/auth-types#AuthCredential} using an email and password. - * - * @example - * ```javascript - * const authCredential = EmailAuthProvider.credential(email, password); - * const userCredential = await signInWithCredential(auth, authCredential); - * ``` - * - * @example - * ```javascript - * const userCredential = await signInWithEmailAndPassword(auth, email, password); - * ``` - * - * @param email - Email address. - * @param password - User account password. - * @returns The auth provider credential. - */ - static credential(email: string, password: string): AuthCredential; - /** - * Initialize an {@link @firebase/auth-types#AuthCredential} using an email and an email link after a sign in with - * email link operation. - * - * @example - * ```javascript - * const authCredential = EmailAuthProvider.credentialWithLink(auth, email, emailLink); - * const userCredential = await signInWithCredential(auth, authCredential); - * ``` - * - * @example - * ```javascript - * await sendSignInLinkToEmail(auth, email); - * // Obtain emailLink from user. - * const userCredential = await signInWithEmailLink(auth, email, emailLink); - * ``` - * - * @param auth - The Auth instance used to verify the link. - * @param email - Email address. - * @param emailLink - Sign-in email link. - * @returns - The auth provider credential. - */ - static credentialWithLink( - auth: Auth, - email: string, - emailLink: string - ): AuthCredential; - /** - * Always set to {@link @firebase/auth-types#ProviderId.PASSWORD}, even for email link. - */ - readonly providerId: ProviderId; -} - -/** - * Provider for generating an {@link @firebase/auth#PhoneAuthCredential}. - * - * @example - * ```javascript - * // 'recaptcha-container' is the ID of an element in the DOM. - * const applicationVerifier = new RecaptchaVerifier('recaptcha-container'); - * const provider = new PhoneAuthProvider(auth); - * const verificationId = await provider.verifyPhoneNumber('+16505550101', applicationVerifier); - * // Obtain the verificationCode from the user. - * const phoneCredential = PhoneAuthProvider.credential(verificationId, verificationCode); - * const userCredential = await signInWithCredential(auth, phoneCredential); - * ``` - * - * @public - */ -export declare class PhoneAuthProvider implements AuthProvider { - /** Always set to {@link @firebase/auth-types#ProviderId.PHONE}. */ - static readonly PROVIDER_ID: ProviderId; - /** Always set to {@link @firebase/auth-types#SignInMethod.PHONE}. */ - static readonly PHONE_SIGN_IN_METHOD: SignInMethod; - /** - * Creates a phone auth credential, given the verification ID from - * {@link @firebase/auth#PhoneAuthProvider.verifyPhoneNumber} and the code that was sent to the user's - * mobile device. - * - * @example - * ```javascript - * const provider = new PhoneAuthProvider(auth); - * const verificationId = provider.verifyPhoneNumber(phoneNumber, applicationVerifier); - * // Obtain verificationCode from the user. - * const authCredential = PhoneAuthProvider.credential(verificationId, verificationCode); - * const userCredential = signInWithCredential(auth, authCredential); - * ``` - * - * @example - * An alternative flow is provided using the `signInWithPhoneNumber` method. - * ```javascript - * const confirmationResult = await signInWithPhoneNumber(auth, phoneNumber, applicationVerifier); - * // Obtain verificationCode from the user. - * const userCredential = await confirmationResult.confirm(verificationCode); - * ``` - * - * @param verificationId - The verification ID returned from {@link @firebase/auth#PhoneAuthProvider.verifyPhoneNumber}. - * @param verificationCode - The verification code sent to the user's mobile device. - * - * @returns The auth provider credential. - */ - static credential( - verificationId: string, - verificationCode: string - ): AuthCredential; - /** - * @param auth - The Firebase Auth instance in which sign-ins should occur. - * - * @remarks - * Uses the default Auth instance if unspecified. - */ - constructor(auth?: Auth | null); - /** Always set to {@link @firebase/auth-types#ProviderId.PHONE}. */ - readonly providerId: ProviderId; - - /** - * - * Starts a phone number authentication flow by sending a verification code to the given phone - * number. - * - * @example - * ```javascript - * const provider = new PhoneAuthProvider(auth); - * const verificationId = await provider.verifyPhoneNumber(phoneNumber, applicationVerifier); - * // Obtain verificationCode from the user. - * const authCredential = PhoneAuthProvider.credential(verificationId, verificationCode); - * const userCredential = await signInWithCredential(auth, authCredential); - * ``` - * - * @example - * An alternative flow is provided using the `signInWithPhoneNumber` method. - * ```javascript - * const confirmationResult = signInWithPhoneNumber(auth, phoneNumber, applicationVerifier); - * // Obtain verificationCode from the user. - * const userCredential = confirmationResult.confirm(verificationCode); - * ``` - * - * @param phoneInfoOptions - The user's {@link @firebase/auth-types#PhoneInfoOptions}. The phone number should be in - * E.164 format (e.g. +16505550101). - * @param applicationVerifier - For abuse prevention, this method also requires a - * {@link @firebase/auth-types#ApplicationVerifier}. This SDK includes a reCAPTCHA-based implementation, - * {@link RecaptchaVerifier}. - * - * @returns A Promise for a verification ID that can be passed to - * {@link @firebase/auth#PhoneAuthProvider.credential} to identify this flow.. - */ - verifyPhoneNumber( - phoneInfoOptions: PhoneInfoOptions | string, - applicationVerifier: ApplicationVerifier - ): Promise; -} - /** * An enum of factors that may be used for multifactor authentication. * @@ -1201,28 +831,6 @@ export interface MultiFactorUser { */ export interface PhoneMultiFactorAssertion extends MultiFactorAssertion {} -/** - * Provider for generating a {@link @firebase/auth-types#PhoneMultiFactorAssertion}. - * - * @public - */ -export declare abstract class PhoneMultiFactorGenerator { - /** - * The identifier of the phone second factor: {@link @firebase/auth-types#ProviderId.PHONE}. - */ - static FACTOR_ID: ProviderId; - /** - * Provides a {@link @firebase/auth-types#PhoneMultiFactorAssertion} to confirm ownership of the phone second factor. - * - * @param phoneAuthCredential - A credential provided by {@link @firebase/auth#PhoneAuthProvider.credential}. - * @returns A {@link @firebase/auth-types#PhoneMultiFactorAssertion} which can be used with - * {@link @firebase/auth-types#MultiFactorResolver.resolveSignIn} - */ - static assertion( - phoneAuthCredential: PhoneAuthCredential - ): PhoneMultiFactorAssertion; -} - /** * The information required to verify the ownership of a phone number. * @@ -1314,12 +922,12 @@ export interface ReactNativeAsyncStorage { */ export interface User extends UserInfo { /** - * Whether the email has been verified with {@link @firebase/auth#sendEmailVerification} and - * {@link @firebase/auth#applyActionCode}. + * Whether the email has been verified with {@link sendEmailVerification} and + * {@link applyActionCode}. */ readonly emailVerified: boolean; /** - * Whether the user is authenticated using the {@link @firebase/auth-types@ProviderId.ANONYMOUS} provider. + * Whether the user is authenticated using the {@link ProviderId.ANONYMOUS} provider. */ readonly isAnonymous: boolean; /** @@ -1545,7 +1153,7 @@ export interface EmulatorConfig { /** * A mapping of error codes to error messages. * - * @discussion + * @remarks * * While error messages are useful for debugging (providing verbose textual * context around what went wrong), these strings take up a lot of space in the diff --git a/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.test.ts b/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.test.ts index 4e54410bc98..285934e12f1 100644 --- a/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.test.ts +++ b/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.test.ts @@ -24,19 +24,19 @@ import { testAuth, TestAuth } from '../../../../test/helpers/mock_auth'; import * as mockFetch from '../../../../test/helpers/mock_fetch'; import { Endpoint } from '../../../api'; import { FinalizeMfaResponse } from '../../../api/authentication/mfa'; -import { PhoneAuthCredentialImpl } from '../../../core/credentials/phone'; +import { PhoneAuthCredential } from '../../../core/credentials/phone'; import { MultiFactorSessionImpl } from '../../../mfa/mfa_session'; import { PhoneAuthProvider } from '../../providers/phone'; import { PhoneMultiFactorAssertionImpl, - PhoneMultiFactorGeneratorImpl + PhoneMultiFactorGenerator } from './phone'; use(chaiAsPromised); describe('platform_browser/mfa/phone', () => { let auth: TestAuth; - let credential: PhoneAuthCredentialImpl; + let credential: PhoneAuthCredential; let assertion: PhoneMultiFactorAssertionImpl; let session: MultiFactorSessionImpl; @@ -131,7 +131,7 @@ describe('platform_browser/mfa/phone', () => { describe('core/mfa/phone/PhoneMultiFactorGenerator', () => { describe('.assertion', () => { - let credential: PhoneAuthCredentialImpl; + let credential: PhoneAuthCredential; beforeEach(async () => { credential = PhoneAuthProvider.credential( @@ -141,7 +141,7 @@ describe('core/mfa/phone/PhoneMultiFactorGenerator', () => { }); it('can be used to create an assertion', () => { - const assertion = PhoneMultiFactorGeneratorImpl.assertion(credential); + const assertion = PhoneMultiFactorGenerator.assertion(credential); expect(assertion.factorId).to.eq(ProviderId.PHONE); }); }); diff --git a/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.ts b/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.ts index bd60b8d395c..7467e7071d8 100644 --- a/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.ts +++ b/packages-exp/auth-exp/src/platform_browser/mfa/assertions/phone.ts @@ -16,35 +16,33 @@ */ import { FactorId, - PhoneAuthCredential, - PhoneMultiFactorAssertion, - PhoneMultiFactorGenerator + PhoneMultiFactorAssertion } from '../../../model/public_types'; import { MultiFactorAssertionImpl } from '../../../mfa/mfa_assertion'; import { AuthInternal } from '../../../model/auth'; import { finalizeEnrollPhoneMfa } from '../../../api/account_management/mfa'; -import { PhoneAuthCredentialImpl } from '../../../core/credentials/phone'; +import { PhoneAuthCredential } from '../../../core/credentials/phone'; import { finalizeSignInPhoneMfa, FinalizeMfaResponse } from '../../../api/authentication/mfa'; /** - * {@inheritdoc @firebase/auth-types#PhoneMultiFactorAssertion} + * {@inheritdoc PhoneMultiFactorAssertion} * * @public */ export class PhoneMultiFactorAssertionImpl extends MultiFactorAssertionImpl implements PhoneMultiFactorAssertion { - private constructor(private readonly credential: PhoneAuthCredentialImpl) { + private constructor(private readonly credential: PhoneAuthCredential) { super(FactorId.PHONE); } /** @internal */ static _fromCredential( - credential: PhoneAuthCredentialImpl + credential: PhoneAuthCredential ): PhoneMultiFactorAssertionImpl { return new PhoneMultiFactorAssertionImpl(credential); } @@ -75,17 +73,23 @@ export class PhoneMultiFactorAssertionImpl } /** - * {@inheritdoc @firebase/auth-types#PhoneMultiFactorGenerator} + * Provider for generating a {@link PhoneMultiFactorAssertion}. + * * @public */ -export class PhoneMultiFactorGeneratorImpl - implements PhoneMultiFactorGenerator { +export class PhoneMultiFactorGenerator { private constructor() {} - /** {@inheritdoc @firebase/auth-types#PhoneMultiFactorGenerator.assertion} */ + /** + * Provides a {@link PhoneMultiFactorAssertion} to confirm ownership of the phone second factor. + * + * @param phoneAuthCredential - A credential provided by {@link PhoneAuthProvider.credential}. + * @returns A {@link PhoneMultiFactorAssertion} which can be used with + * {@link MultiFactorResolver.resolveSignIn} + */ static assertion(credential: PhoneAuthCredential): PhoneMultiFactorAssertion { return PhoneMultiFactorAssertionImpl._fromCredential( - credential as PhoneAuthCredentialImpl + credential as PhoneAuthCredential ); } } diff --git a/packages-exp/auth-exp/src/platform_browser/providers/phone.ts b/packages-exp/auth-exp/src/platform_browser/providers/phone.ts index f7212ac4ee0..009b6333493 100644 --- a/packages-exp/auth-exp/src/platform_browser/providers/phone.ts +++ b/packages-exp/auth-exp/src/platform_browser/providers/phone.ts @@ -17,44 +17,89 @@ import { Auth, - PhoneAuthProvider as PhoneAuthProviderType, PhoneInfoOptions, ProviderId, SignInMethod, ApplicationVerifier, - UserCredential, - AuthCredential + UserCredential } from '../../model/public_types'; import { SignInWithPhoneNumberResponse } from '../../api/authentication/sms'; import { ApplicationVerifierInternal as ApplicationVerifierInternal } from '../../model/application_verifier'; import { AuthInternal as AuthInternal } from '../../model/auth'; import { UserCredentialInternal as UserCredentialInternal } from '../../model/user'; -import { PhoneAuthCredentialImpl } from '../../core/credentials/phone'; +import { PhoneAuthCredential } from '../../core/credentials/phone'; import { AuthErrorCode } from '../../core/errors'; import { _verifyPhoneNumber } from '../strategies/phone'; import { _assert, _fail } from '../../core/util/assert'; import { _castAuth } from '../../core/auth/auth_impl'; +import { AuthCredential } from '../../core'; /** - * {@inheritdoc @firebase/auth-types#PhoneAuthProvider} + * Provider for generating an {@link PhoneAuthCredential}. + * + * @example + * ```javascript + * // 'recaptcha-container' is the ID of an element in the DOM. + * const applicationVerifier = new RecaptchaVerifier('recaptcha-container'); + * const provider = new PhoneAuthProvider(auth); + * const verificationId = await provider.verifyPhoneNumber('+16505550101', applicationVerifier); + * // Obtain the verificationCode from the user. + * const phoneCredential = PhoneAuthProvider.credential(verificationId, verificationCode); + * const userCredential = await signInWithCredential(auth, phoneCredential); + * ``` + * * @public */ -export class PhoneAuthProvider implements PhoneAuthProviderType { - /** {@inheritdoc @firebase/auth-types#PhoneAuthProvider.PROVIDER_ID} */ +export class PhoneAuthProvider { + /** Always set to {@link ProviderId.PHONE}. */ static readonly PROVIDER_ID = ProviderId.PHONE; - /** {@inheritdoc @firebase/auth-types#PhoneAuthProvider.PHONE_SIGN_IN_METHOD} */ + /** Always set to {@link SignInMethod.PHONE}. */ static readonly PHONE_SIGN_IN_METHOD = SignInMethod.PHONE; - /** {@inheritdoc @firebase/auth-types#PhoneAuthProvider.providerId} */ + /** Always set to {@link ProviderId.PHONE}. */ readonly providerId = PhoneAuthProvider.PROVIDER_ID; private readonly auth: AuthInternal; + /** + * @param auth - The Firebase Auth instance in which sign-ins should occur. + * + */ constructor(auth: Auth) { this.auth = _castAuth(auth); } - /** {@inheritdoc @firebase/auth-types#PhoneAuthProvider.verifyPhoneNumber} */ + /** + * + * Starts a phone number authentication flow by sending a verification code to the given phone + * number. + * + * @example + * ```javascript + * const provider = new PhoneAuthProvider(auth); + * const verificationId = await provider.verifyPhoneNumber(phoneNumber, applicationVerifier); + * // Obtain verificationCode from the user. + * const authCredential = PhoneAuthProvider.credential(verificationId, verificationCode); + * const userCredential = await signInWithCredential(auth, authCredential); + * ``` + * + * @example + * An alternative flow is provided using the `signInWithPhoneNumber` method. + * ```javascript + * const confirmationResult = signInWithPhoneNumber(auth, phoneNumber, applicationVerifier); + * // Obtain verificationCode from the user. + * const userCredential = confirmationResult.confirm(verificationCode); + * ``` + * + * @param phoneInfoOptions - The user's {@link PhoneInfoOptions}. The phone number should be in + * E.164 format (e.g. +16505550101). + * @param applicationVerifier - For abuse prevention, this method also requires a + * {@link ApplicationVerifier}. This SDK includes a reCAPTCHA-based implementation, + * {@link RecaptchaVerifier}. + * + * @returns A Promise for a verification ID that can be passed to + * {@link PhoneAuthProvider.credential} to identify this flow.. + */ verifyPhoneNumber( phoneOptions: PhoneInfoOptions | string, applicationVerifier: ApplicationVerifier @@ -66,12 +111,38 @@ export class PhoneAuthProvider implements PhoneAuthProviderType { ); } - /** {@inheritdoc @firebase/auth-types#PhoneAuthProvider.credential} */ + /** + * Creates a phone auth credential, given the verification ID from + * {@link PhoneAuthProvider.verifyPhoneNumber} and the code that was sent to the user's + * mobile device. + * + * @example + * ```javascript + * const provider = new PhoneAuthProvider(auth); + * const verificationId = provider.verifyPhoneNumber(phoneNumber, applicationVerifier); + * // Obtain verificationCode from the user. + * const authCredential = PhoneAuthProvider.credential(verificationId, verificationCode); + * const userCredential = signInWithCredential(auth, authCredential); + * ``` + * + * @example + * An alternative flow is provided using the `signInWithPhoneNumber` method. + * ```javascript + * const confirmationResult = await signInWithPhoneNumber(auth, phoneNumber, applicationVerifier); + * // Obtain verificationCode from the user. + * const userCredential = await confirmationResult.confirm(verificationCode); + * ``` + * + * @param verificationId - The verification ID returned from {@link PhoneAuthProvider.verifyPhoneNumber}. + * @param verificationCode - The verification code sent to the user's mobile device. + * + * @returns The auth provider credential. + */ static credential( verificationId: string, verificationCode: string - ): PhoneAuthCredentialImpl { - return PhoneAuthCredentialImpl._fromVerification( + ): PhoneAuthCredential { + return PhoneAuthCredential._fromVerification( verificationId, verificationCode ); @@ -91,7 +162,7 @@ export class PhoneAuthProvider implements PhoneAuthProviderType { temporaryProof } = credential._tokenResponse as SignInWithPhoneNumberResponse; if (phoneNumber && temporaryProof) { - return PhoneAuthCredentialImpl._fromTokenResponse( + return PhoneAuthCredential._fromTokenResponse( phoneNumber, temporaryProof ); diff --git a/packages-exp/auth-exp/src/platform_browser/recaptcha/recaptcha_verifier.ts b/packages-exp/auth-exp/src/platform_browser/recaptcha/recaptcha_verifier.ts index 74ba21d5bd9..c68c0b3fd78 100644 --- a/packages-exp/auth-exp/src/platform_browser/recaptcha/recaptcha_verifier.ts +++ b/packages-exp/auth-exp/src/platform_browser/recaptcha/recaptcha_verifier.ts @@ -15,10 +15,7 @@ * limitations under the License. */ -import { - Auth, - RecaptchaVerifier as RecaptchaVerifierType -} from '../../model/public_types'; +import { Auth } from '../../model/public_types'; import { getRecaptchaParams } from '../../api/authentication/recaptcha'; import { _castAuth } from '../../core/auth/auth_impl'; import { AuthErrorCode } from '../../core/errors'; @@ -45,11 +42,17 @@ const DEFAULT_PARAMS: Parameters = { type TokenCallback = (token: string) => void; /** - * {@inheritdoc @firebase/auth-types#RecaptchaVerifier} + * An {@link https://www.google.com/recaptcha/ | reCAPTCHA}-based application verifier. + * * @public */ -export class RecaptchaVerifier - implements RecaptchaVerifierType, ApplicationVerifierInternal { +export class RecaptchaVerifier implements ApplicationVerifierInternal { + /** + * The application verifier type. + * + * @remarks + * For a reCAPTCHA verifier, this is 'recaptcha'. + */ readonly type = RECAPTCHA_VERIFIER_TYPE; private destroyed = false; private widgetId: number | null = null; @@ -63,6 +66,30 @@ export class RecaptchaVerifier readonly _recaptchaLoader: ReCaptchaLoader; private recaptcha: Recaptcha | null = null; + /** + * + * @param containerOrId - The reCAPTCHA container parameter. + * + * @remarks + * This has different meaning depending on whether the reCAPTCHA is hidden or visible. For a + * visible reCAPTCHA the container must be empty. If a string is used, it has to correspond to + * an element ID. The corresponding element must also must be in the DOM at the time of + * initialization. + * + * @param parameters - The optional reCAPTCHA parameters. + * + * @remarks + * Check the reCAPTCHA docs for a comprehensive list. All parameters are accepted except for + * the sitekey. Firebase Auth backend provisions a reCAPTCHA for each project and will + * configure this upon rendering. For an invisible reCAPTCHA, a size key must have the value + * 'invisible'. + * + * @param authExtern - The corresponding Firebase Auth instance. + * + * @remarks + * If none is provided, the default Firebase Auth instance is used. A Firebase Auth instance + * must be initialized with an API key, otherwise an error will be thrown. + */ constructor( containerOrId: HTMLElement | string, private readonly parameters: Parameters = { @@ -94,7 +121,11 @@ export class RecaptchaVerifier // TODO: Figure out if sdk version is needed } - /** {@inheritdoc @firebase/auth-types#RecaptchaVerifier.verify} */ + /** + * Waits for the user to solve the reCAPTCHA and resolves with the reCAPTCHA token. + * + * @returns A Promise for the reCAPTCHA token. + */ async verify(): Promise { this.assertNotDestroyed(); const id = await this.render(); @@ -121,7 +152,11 @@ export class RecaptchaVerifier }); } - /** {@inheritdoc @firebase/auth-types#RecaptchaVerifier.render} */ + /** + * Renders the reCAPTCHA widget on the page. + * + * @returns A Promise that resolves with the reCAPTCHA widget ID. + */ render(): Promise { try { this.assertNotDestroyed(); @@ -152,7 +187,9 @@ export class RecaptchaVerifier } } - /** {@inheritdoc @firebase/auth-types#RecaptchaVerifier.clear} */ + /** + * Clears the reCAPTCHA widget from the page and destroys the instance. + */ clear(): void { this.assertNotDestroyed(); this.destroyed = true; diff --git a/packages-exp/auth-exp/src/platform_browser/strategies/phone.test.ts b/packages-exp/auth-exp/src/platform_browser/strategies/phone.test.ts index 3b7928f44e6..da7ae45be29 100644 --- a/packages-exp/auth-exp/src/platform_browser/strategies/phone.test.ts +++ b/packages-exp/auth-exp/src/platform_browser/strategies/phone.test.ts @@ -35,7 +35,7 @@ import { ApplicationVerifierInternal } from '../../model/application_verifier'; import { IdTokenResponse, IdTokenResponseKind } from '../../model/id_token'; import { UserInternal } from '../../model/user'; import { RecaptchaVerifier } from '../../platform_browser/recaptcha/recaptcha_verifier'; -import { PhoneAuthCredentialImpl } from '../../core/credentials/phone'; +import { PhoneAuthCredential } from '../../core/credentials/phone'; import { _verifyPhoneNumber, linkWithPhoneNumber, @@ -417,7 +417,7 @@ describe('platform_browser/strategies/phone', () => { let user: UserInternal; let reloadMock: fetch.Route; let signInMock: fetch.Route; - let credential: PhoneAuthCredentialImpl; + let credential: PhoneAuthCredential; let idToken: string; beforeEach(() => { @@ -429,7 +429,7 @@ describe('platform_browser/strategies/phone', () => { idToken, refreshToken: 'refresh-token' }); - credential = PhoneAuthCredentialImpl._fromVerification( + credential = PhoneAuthCredential._fromVerification( 'session-info', 'code' ); diff --git a/packages-exp/auth-exp/src/platform_browser/strategies/phone.ts b/packages-exp/auth-exp/src/platform_browser/strategies/phone.ts index 5137058bfbb..08011922061 100644 --- a/packages-exp/auth-exp/src/platform_browser/strategies/phone.ts +++ b/packages-exp/auth-exp/src/platform_browser/strategies/phone.ts @@ -19,7 +19,6 @@ import { ApplicationVerifier, Auth, ConfirmationResult, - PhoneAuthCredential, PhoneInfoOptions, ProviderId, User, @@ -30,7 +29,7 @@ import { startEnrollPhoneMfa } from '../../api/account_management/mfa'; import { startSignInPhoneMfa } from '../../api/authentication/mfa'; import { sendPhoneVerificationCode } from '../../api/authentication/sms'; import { ApplicationVerifierInternal } from '../../model/application_verifier'; -import { PhoneAuthCredentialImpl } from '../../core/credentials/phone'; +import { PhoneAuthCredential } from '../../core/credentials/phone'; import { AuthErrorCode } from '../../core/errors'; import { _assertLinkedStatus, _link } from '../../core/user/link_unlink'; import { _assert } from '../../core/util/assert'; @@ -49,7 +48,7 @@ import { RECAPTCHA_VERIFIER_TYPE } from '../recaptcha/recaptcha_verifier'; import { _castAuth } from '../../core/auth/auth_impl'; interface OnConfirmationCallback { - (credential: PhoneAuthCredentialImpl): Promise; + (credential: PhoneAuthCredential): Promise; } class ConfirmationResultImpl implements ConfirmationResult { @@ -59,7 +58,7 @@ class ConfirmationResultImpl implements ConfirmationResult { ) {} confirm(verificationCode: string): Promise { - const authCredential = PhoneAuthCredentialImpl._fromVerification( + const authCredential = PhoneAuthCredential._fromVerification( this.verificationId, verificationCode ); @@ -266,5 +265,5 @@ export async function updatePhoneNumber( user: User, credential: PhoneAuthCredential ): Promise { - await _link(user as UserInternal, credential as PhoneAuthCredentialImpl); + await _link(user as UserInternal, credential as PhoneAuthCredential); } From e6b93b3766f78340108098bb1ff9518f28715775 Mon Sep 17 00:00:00 2001 From: Feiyang1 Date: Thu, 18 Feb 2021 15:39:49 -0800 Subject: [PATCH 08/13] fix links in comments --- packages-exp/auth-exp/src/core/errors.ts | 4 ++-- packages-exp/auth-exp/src/core/index.ts | 8 ++++---- .../auth-exp/src/core/persistence/in_memory.ts | 2 +- .../auth-exp/src/core/providers/facebook.ts | 10 +++++----- packages-exp/auth-exp/src/core/providers/github.ts | 10 +++++----- packages-exp/auth-exp/src/core/providers/google.ts | 10 +++++----- packages-exp/auth-exp/src/core/providers/oauth.ts | 4 ++-- .../auth-exp/src/core/providers/twitter.ts | 6 +++--- .../auth-exp/src/core/strategies/credential.ts | 4 ++-- packages-exp/auth-exp/src/core/strategies/email.ts | 8 ++++---- .../src/core/strategies/email_and_password.ts | 2 +- .../auth-exp/src/core/strategies/email_link.ts | 2 +- .../auth-exp/src/core/user/additional_user_info.ts | 2 +- packages-exp/auth-exp/src/mfa/mfa_resolver.ts | 4 ++-- packages-exp/auth-exp/src/mfa/mfa_user.ts | 2 +- packages-exp/auth-exp/src/model/public_types.ts | 14 +++++++------- .../src/platform_browser/persistence/indexed_db.ts | 2 +- .../platform_browser/persistence/local_storage.ts | 2 +- .../persistence/session_storage.ts | 2 +- .../src/platform_browser/popup_redirect.ts | 2 +- .../src/platform_browser/strategies/phone.ts | 12 ++++++------ .../src/platform_browser/strategies/popup.ts | 6 +++--- .../src/platform_browser/strategies/redirect.ts | 12 ++++++------ .../popup_redirect/popup_redirect.ts | 2 +- 24 files changed, 66 insertions(+), 66 deletions(-) diff --git a/packages-exp/auth-exp/src/core/errors.ts b/packages-exp/auth-exp/src/core/errors.ts index 09ed38f037c..e80178fa630 100644 --- a/packages-exp/auth-exp/src/core/errors.ts +++ b/packages-exp/auth-exp/src/core/errors.ts @@ -374,7 +374,7 @@ function _prodErrorMap(): ErrorMap { /** * A verbose error map with detailed descriptions for most error codes. * - * See discussion at {@link @firebase/auth-types#AuthErrorMap} + * See discussion at {@link AuthErrorMap} * * @public */ @@ -383,7 +383,7 @@ export const debugErrorMap: AuthErrorMap = _debugErrorMap; /** * A minimal error map with all verbose error messages stripped. * - * See discussion at {@link @firebase/auth-types#AuthErrorMap} + * See discussion at {@link AuthErrorMap} * * @public */ diff --git a/packages-exp/auth-exp/src/core/index.ts b/packages-exp/auth-exp/src/core/index.ts index ff9e2b85fdf..7162a911569 100644 --- a/packages-exp/auth-exp/src/core/index.ts +++ b/packages-exp/auth-exp/src/core/index.ts @@ -37,7 +37,7 @@ export { debugErrorMap, prodErrorMap } from './errors'; * ``` * * @param auth - The Auth instance. - * @param persistence - The {@link @firebase/auth-types#Persistence} to use. + * @param persistence - The {@link Persistence} to use. * @returns A promise that resolves once the persistence change has completed * * @public @@ -99,8 +99,8 @@ export function useDeviceLanguage(auth: Auth): void { auth.useDeviceLanguage(); } /** - * Asynchronously sets the provided user as {@link @firebase/auth-types#Auth.currentUser} on the - * {@link @firebase/auth-types#Auth} instance. + * Asynchronously sets the provided user as {@link Auth.currentUser} on the + * {@link Auth} instance. * * @remarks * A new instance copy of the user provided will be made and set as currentUser. @@ -112,7 +112,7 @@ export function useDeviceLanguage(auth: Auth): void { * project. * * @param auth - The Auth instance. - * @param user - The new {@link @firebase/auth-types#User}. + * @param user - The new {@link User}. * * @public */ diff --git a/packages-exp/auth-exp/src/core/persistence/in_memory.ts b/packages-exp/auth-exp/src/core/persistence/in_memory.ts index 9b9c909ebaa..86188df8a62 100644 --- a/packages-exp/auth-exp/src/core/persistence/in_memory.ts +++ b/packages-exp/auth-exp/src/core/persistence/in_memory.ts @@ -58,7 +58,7 @@ export class InMemoryPersistence implements PersistenceInternal { } /** - * An implementation of {@link @firebase/auth-types#Persistence} of type 'NONE'. + * An implementation of {@link Persistence} of type 'NONE'. * * @public */ diff --git a/packages-exp/auth-exp/src/core/providers/facebook.ts b/packages-exp/auth-exp/src/core/providers/facebook.ts index 98eb052e35b..39bfee44069 100644 --- a/packages-exp/auth-exp/src/core/providers/facebook.ts +++ b/packages-exp/auth-exp/src/core/providers/facebook.ts @@ -28,7 +28,7 @@ import { OAuthCredential } from '../credentials/oauth'; import { OAuthProvider } from './oauth'; /** - * Provider for generating an {@link OAuthCredential} for {@link @firebase/auth-types#ProviderId.FACEBOOK}. + * Provider for generating an {@link OAuthCredential} for {@link ProviderId.FACEBOOK}. * * @example * ```javascript @@ -67,9 +67,9 @@ import { OAuthProvider } from './oauth'; * @public */ export class FacebookAuthProvider extends OAuthProvider { - /** Always set to {@link @firebase/auth-types#SignInMethod.FACEBOOK}. */ + /** Always set to {@link SignInMethod.FACEBOOK}. */ static readonly FACEBOOK_SIGN_IN_METHOD = SignInMethod.FACEBOOK; - /** Always set to {@link @firebase/auth-types#ProviderId.FACEBOOK}. */ + /** Always set to {@link ProviderId.FACEBOOK}. */ static readonly PROVIDER_ID = ProviderId.FACEBOOK; constructor() { @@ -97,7 +97,7 @@ export class FacebookAuthProvider extends OAuthProvider { } /** - * Used to extract the underlying {@link OAuthCredential} from a {@link @firebase/auth-types#UserCredential}. + * Used to extract the underlying {@link OAuthCredential} from a {@link UserCredential}. * * @param userCredential - The user credential. */ @@ -110,7 +110,7 @@ export class FacebookAuthProvider extends OAuthProvider { } /** - * Used to extract the underlying {@link OAuthCredential} from a {@link @firebase/auth-types#AuthError} which was + * Used to extract the underlying {@link OAuthCredential} from a {@link AuthError} which was * thrown during a sign-in, link, or reauthenticate operation. * * @param userCredential - The user credential. diff --git a/packages-exp/auth-exp/src/core/providers/github.ts b/packages-exp/auth-exp/src/core/providers/github.ts index dbbb6c5bbf6..7f16c616c24 100644 --- a/packages-exp/auth-exp/src/core/providers/github.ts +++ b/packages-exp/auth-exp/src/core/providers/github.ts @@ -28,7 +28,7 @@ import { OAuthCredential } from '../credentials/oauth'; import { OAuthProvider } from './oauth'; /** - * Provider for generating an {@link OAuthCredential} for {@link @firebase/auth-types#ProviderId.GITHUB}. + * Provider for generating an {@link OAuthCredential} for {@link ProviderId.GITHUB}. * * @remarks * GitHub requires an OAuth 2.0 redirect, so you can either handle the redirect directly, or use @@ -70,9 +70,9 @@ import { OAuthProvider } from './oauth'; * @public */ export class GithubAuthProvider extends OAuthProvider { - /** Always set to {@link @firebase/auth-types#SignInMethod.GITHUB}. */ + /** Always set to {@link SignInMethod.GITHUB}. */ static readonly GITHUB_SIGN_IN_METHOD = SignInMethod.GITHUB; - /** Always set to {@link @firebase/auth-types#ProviderId.GITHUB}. */ + /** Always set to {@link ProviderId.GITHUB}. */ static readonly PROVIDER_ID = ProviderId.GITHUB; constructor() { @@ -93,7 +93,7 @@ export class GithubAuthProvider extends OAuthProvider { } /** - * Used to extract the underlying {@link OAuthCredential} from a {@link @firebase/auth-types#UserCredential}. + * Used to extract the underlying {@link OAuthCredential} from a {@link UserCredential}. * * @param userCredential - The user credential. */ @@ -106,7 +106,7 @@ export class GithubAuthProvider extends OAuthProvider { } /** - * Used to extract the underlying {@link OAuthCredential} from a {@link @firebase/auth-types#AuthError} which was + * Used to extract the underlying {@link OAuthCredential} from a {@link AuthError} which was * thrown during a sign-in, link, or reauthenticate operation. * * @param userCredential - The user credential. diff --git a/packages-exp/auth-exp/src/core/providers/google.ts b/packages-exp/auth-exp/src/core/providers/google.ts index 35bbf69963d..aeee3b4d1e7 100644 --- a/packages-exp/auth-exp/src/core/providers/google.ts +++ b/packages-exp/auth-exp/src/core/providers/google.ts @@ -29,7 +29,7 @@ import { OAuthCredential } from '../credentials/oauth'; import { OAuthProvider } from './oauth'; /** - * Provider for generating an an {@link OAuthCredential} for {@link @firebase/auth-types#ProviderId.GOOGLE}. + * Provider for generating an an {@link OAuthCredential} for {@link ProviderId.GOOGLE}. * * @example * ```javascript @@ -70,9 +70,9 @@ import { OAuthProvider } from './oauth'; * @public */ export class GoogleAuthProvider extends OAuthProvider { - /** Always set to {@link @firebase/auth-types#SignInMethod.GOOGLE}. */ + /** Always set to {@link SignInMethod.GOOGLE}. */ static readonly GOOGLE_SIGN_IN_METHOD = SignInMethod.GOOGLE; - /** Always set to {@link @firebase/auth-types#ProviderId.GOOGLE}. */ + /** Always set to {@link ProviderId.GOOGLE}. */ static readonly PROVIDER_ID = ProviderId.GOOGLE; constructor() { @@ -106,7 +106,7 @@ export class GoogleAuthProvider extends OAuthProvider { } /** - * Used to extract the underlying {@link OAuthCredential} from a {@link @firebase/auth-types#UserCredential}. + * Used to extract the underlying {@link OAuthCredential} from a {@link UserCredential}. * * @param userCredential - The user credential. */ @@ -118,7 +118,7 @@ export class GoogleAuthProvider extends OAuthProvider { ); } /** - * Used to extract the underlying {@link OAuthCredential} from a {@link @firebase/auth-types#AuthError} which was + * Used to extract the underlying {@link OAuthCredential} from a {@link AuthError} which was * thrown during a sign-in, link, or reauthenticate operation. * * @param userCredential - The user credential. diff --git a/packages-exp/auth-exp/src/core/providers/oauth.ts b/packages-exp/auth-exp/src/core/providers/oauth.ts index 0ff6142eeef..caeb1ebcce0 100644 --- a/packages-exp/auth-exp/src/core/providers/oauth.ts +++ b/packages-exp/auth-exp/src/core/providers/oauth.ts @@ -207,7 +207,7 @@ export class OAuthProvider implements AuthProvider { } /** - * Used to extract the underlying {@link OAuthCredential} from a {@link @firebase/auth-types#UserCredential}. + * Used to extract the underlying {@link OAuthCredential} from a {@link UserCredential}. * * @param userCredential - The user credential. */ @@ -219,7 +219,7 @@ export class OAuthProvider implements AuthProvider { ); } /** - * Used to extract the underlying {@link OAuthCredential} from a {@link @firebase/auth-types#AuthError} which was + * Used to extract the underlying {@link OAuthCredential} from a {@link AuthError} which was * thrown during a sign-in, link, or reauthenticate operation. * * @param userCredential - The user credential. diff --git a/packages-exp/auth-exp/src/core/providers/twitter.ts b/packages-exp/auth-exp/src/core/providers/twitter.ts index 1e926fb29a9..1c14e32b646 100644 --- a/packages-exp/auth-exp/src/core/providers/twitter.ts +++ b/packages-exp/auth-exp/src/core/providers/twitter.ts @@ -46,7 +46,7 @@ import { OAuthCredential } from '../credentials/oauth'; import { OAuthProvider } from './oauth'; /** - * Provider for generating an {@link OAuthCredential} for {@link @firebase/auth-types#ProviderId.TWITTER}. + * Provider for generating an {@link OAuthCredential} for {@link ProviderId.TWITTER}. * * @example * ```javascript @@ -108,7 +108,7 @@ export class TwitterAuthProvider extends OAuthProvider { } /** - * Used to extract the underlying {@link OAuthCredential} from a {@link @firebase/auth-types#UserCredential}. + * Used to extract the underlying {@link OAuthCredential} from a {@link UserCredential}. * * @param userCredential - The user credential. */ @@ -121,7 +121,7 @@ export class TwitterAuthProvider extends OAuthProvider { } /** - * Used to extract the underlying {@link OAuthCredential} from a {@link @firebase/auth-types#AuthError} which was + * Used to extract the underlying {@link OAuthCredential} from a {@link AuthError} which was * thrown during a sign-in, link, or reauthenticate operation. * * @param userCredential - The user credential. diff --git a/packages-exp/auth-exp/src/core/strategies/credential.ts b/packages-exp/auth-exp/src/core/strategies/credential.ts index ad1893f9d28..c0736e0875d 100644 --- a/packages-exp/auth-exp/src/core/strategies/credential.ts +++ b/packages-exp/auth-exp/src/core/strategies/credential.ts @@ -58,7 +58,7 @@ export async function _signInWithCredential( * Asynchronously signs in with the given credentials. * * @remarks - * An {@link @firebase/auth-types#AuthProvider} can be used to generate the credential. + * An {@link AuthProvider} can be used to generate the credential. * * @param auth - The Auth instance. * @param credential - The auth credential. @@ -76,7 +76,7 @@ export async function signInWithCredential( * Links the user account with the given credentials. * * @remarks - * An {@link @firebase/auth-types#AuthProvider} can be used to generate the credential. + * An {@link AuthProvider} can be used to generate the credential. * * @param user - The user. * @param credential - The auth credential. diff --git a/packages-exp/auth-exp/src/core/strategies/email.ts b/packages-exp/auth-exp/src/core/strategies/email.ts index 3eb5b8f3dbe..86b37e2b256 100644 --- a/packages-exp/auth-exp/src/core/strategies/email.ts +++ b/packages-exp/auth-exp/src/core/strategies/email.ts @@ -37,8 +37,8 @@ import { _setActionCodeSettingsOnRequest } from './action_code_settings'; * @remarks * This is useful to differentiate methods of sign-in for the same provider, eg. * {@link EmailAuthProvider} which has 2 methods of sign-in, - * {@link @firebase/auth-types#SignInMethod.EMAIL_PASSWORD} and - * {@link @firebase/auth-types#SignInMethod.EMAIL_LINK} . + * {@link SignInMethod.EMAIL_PASSWORD} and + * {@link SignInMethod.EMAIL_LINK} . * * @param auth - The Auth instance. * @param email - The user's email address. @@ -89,7 +89,7 @@ export async function fetchSignInMethodsForEmail( * ``` * * @param user - The user. - * @param actionCodeSettings - The {@link @firebase/auth-types#ActionCodeSettings}. + * @param actionCodeSettings - The {@link ActionCodeSettings}. * * @public */ @@ -148,7 +148,7 @@ export async function sendEmailVerification( * * @param user - The user. * @param newEmail - The new email address to be verified before update. - * @param actionCodeSettings - The {@link @firebase/auth-types#ActionCodeSettings}. + * @param actionCodeSettings - The {@link ActionCodeSettings}. * * @public */ diff --git a/packages-exp/auth-exp/src/core/strategies/email_and_password.ts b/packages-exp/auth-exp/src/core/strategies/email_and_password.ts index bc8d8c3abc5..fc738ad57c3 100644 --- a/packages-exp/auth-exp/src/core/strategies/email_and_password.ts +++ b/packages-exp/auth-exp/src/core/strategies/email_and_password.ts @@ -64,7 +64,7 @@ import { AuthErrorCode } from '../errors'; * * @param auth - The Auth instance. * @param email - The user's email address. - * @param actionCodeSettings - The {@link @firebase/auth-types#ActionCodeSettings}. + * @param actionCodeSettings - The {@link ActionCodeSettings}. * * @public */ diff --git a/packages-exp/auth-exp/src/core/strategies/email_link.ts b/packages-exp/auth-exp/src/core/strategies/email_link.ts index c0c918d6b7f..66140290cb1 100644 --- a/packages-exp/auth-exp/src/core/strategies/email_link.ts +++ b/packages-exp/auth-exp/src/core/strategies/email_link.ts @@ -65,7 +65,7 @@ import { _assert } from '../util/assert'; * * @param auth - The Auth instance. * @param email - The user's email address. - * @param actionCodeSettings - The {@link @firebase/auth-types#ActionCodeSettings}. + * @param actionCodeSettings - The {@link ActionCodeSettings}. * * @public */ diff --git a/packages-exp/auth-exp/src/core/user/additional_user_info.ts b/packages-exp/auth-exp/src/core/user/additional_user_info.ts index 200a0ff11ae..fec089be3f9 100644 --- a/packages-exp/auth-exp/src/core/user/additional_user_info.ts +++ b/packages-exp/auth-exp/src/core/user/additional_user_info.ts @@ -132,7 +132,7 @@ class TwitterAdditionalUserInfo extends FederatedAdditionalUserInfoWithUsername } /** - * Extracts provider specific {@link @firebase/auth-types#AdditionalUserInfo} for the given credential. + * Extracts provider specific {@link AdditionalUserInfo} for the given credential. * * @param userCredential - The user credential. * diff --git a/packages-exp/auth-exp/src/mfa/mfa_resolver.ts b/packages-exp/auth-exp/src/mfa/mfa_resolver.ts index a33886a82e0..e286650daa4 100644 --- a/packages-exp/auth-exp/src/mfa/mfa_resolver.ts +++ b/packages-exp/auth-exp/src/mfa/mfa_resolver.ts @@ -111,11 +111,11 @@ export class MultiFactorResolverImpl implements MultiFactorResolver { } /** - * Provides a {@link @firebase/auth-types#MultiFactorResolver} suitable for completion of a + * Provides a {@link MultiFactorResolver} suitable for completion of a * multi-factor flow. * * @param auth - The auth instance. - * @param error - The {@link @firebase/auth-types#MultiFactorError} raised during a sign-in, or + * @param error - The {@link MultiFactorError} raised during a sign-in, or * reauthentication operation. * * @public diff --git a/packages-exp/auth-exp/src/mfa/mfa_user.ts b/packages-exp/auth-exp/src/mfa/mfa_user.ts index 66fa8af5c5a..b052986d27d 100644 --- a/packages-exp/auth-exp/src/mfa/mfa_user.ts +++ b/packages-exp/auth-exp/src/mfa/mfa_user.ts @@ -103,7 +103,7 @@ export class MultiFactorUserImpl implements MultiFactorUser { const multiFactorUserCache = new WeakMap(); /** - * The {@link @firebase/auth-types#MultiFactorUser} corresponding to the user. + * The {@link MultiFactorUser} corresponding to the user. * * @remarks * This is used to access all multi-factor properties and operations related to the user. diff --git a/packages-exp/auth-exp/src/model/public_types.ts b/packages-exp/auth-exp/src/model/public_types.ts index d10c8fbec70..82f6817231e 100644 --- a/packages-exp/auth-exp/src/model/public_types.ts +++ b/packages-exp/auth-exp/src/model/public_types.ts @@ -524,7 +524,7 @@ export interface ApplicationVerifier { } /** - * Interface that represents an auth provider, used to facilitate creating {@link @firebase/auth-types#AuthCredential}. + * Interface that represents an auth provider, used to facilitate creating {@link AuthCredential}. * * @public */ @@ -556,7 +556,7 @@ export interface ConfirmationResult { * * @remarks * This can be used along with the verification code to initialize a - * {@link @firebase/auth-types#PhoneAuthCredential}. + * {@link PhoneAuthCredential}. */ readonly verificationId: string; /** @@ -643,7 +643,7 @@ export interface MultiFactorInfo { } /** - * The class used to facilitate recovery from {@link @firebase/auth-types#MultiFactorError} when a user needs to + * The class used to facilitate recovery from {@link MultiFactorError} when a user needs to * provide a second factor to sign in. * * @example @@ -701,7 +701,7 @@ export interface MultiFactorResolver { readonly session: MultiFactorSession; /** * A helper function to help users complete sign in with a second factor using an - * {@link @firebase/auth-types#MultiFactorAssertion} confirming the user successfully completed the second factor + * {@link MultiFactorAssertion} confirming the user successfully completed the second factor * challenge. * * @example @@ -757,12 +757,12 @@ export interface MultiFactorUser { * await multiFactorUser.enroll(multiFactorAssertion); * ``` * - * @returns The promise that resolves with the {@link @firebase/auth-types#MultiFactorSession}. + * @returns The promise that resolves with the {@link MultiFactorSession}. */ getSession(): Promise; /** * - * Enrolls a second factor as identified by the {@link @firebase/auth-types#MultiFactorAssertion} for the + * Enrolls a second factor as identified by the {@link MultiFactorAssertion} for the * user. * * @remarks @@ -825,7 +825,7 @@ export interface MultiFactorUser { /** * The class for asserting ownership of a phone second factor. Provided by - * {@link @firebase/auth-types#PhoneMultiFactorGenerator.assertion}. + * {@link PhoneMultiFactorGenerator.assertion}. * * @public */ diff --git a/packages-exp/auth-exp/src/platform_browser/persistence/indexed_db.ts b/packages-exp/auth-exp/src/platform_browser/persistence/indexed_db.ts index 22d8c139dd0..3a060b58e0d 100644 --- a/packages-exp/auth-exp/src/platform_browser/persistence/indexed_db.ts +++ b/packages-exp/auth-exp/src/platform_browser/persistence/indexed_db.ts @@ -436,7 +436,7 @@ class IndexedDBLocalPersistence implements InternalPersistence { } /** - * An implementation of {@link @firebase/auth-types#Persistence} of type 'LOCAL' using `indexedDB` + * An implementation of {@link Persistence} of type 'LOCAL' using `indexedDB` * for the underlying storage. * * @public diff --git a/packages-exp/auth-exp/src/platform_browser/persistence/local_storage.ts b/packages-exp/auth-exp/src/platform_browser/persistence/local_storage.ts index 9cc53e4f7e7..2a9662368bc 100644 --- a/packages-exp/auth-exp/src/platform_browser/persistence/local_storage.ts +++ b/packages-exp/auth-exp/src/platform_browser/persistence/local_storage.ts @@ -242,7 +242,7 @@ class BrowserLocalPersistence } /** - * An implementation of {@link @firebase/auth-types#Persistence} of type 'LOCAL' using `localStorage` + * An implementation of {@link Persistence} of type 'LOCAL' using `localStorage` * for the underlying storage. * * @public diff --git a/packages-exp/auth-exp/src/platform_browser/persistence/session_storage.ts b/packages-exp/auth-exp/src/platform_browser/persistence/session_storage.ts index c6f78e08bfd..fd8c6a0895c 100644 --- a/packages-exp/auth-exp/src/platform_browser/persistence/session_storage.ts +++ b/packages-exp/auth-exp/src/platform_browser/persistence/session_storage.ts @@ -45,7 +45,7 @@ class BrowserSessionPersistence } /** - * An implementation of {@link @firebase/auth-types#Persistence} of 'SESSION' using `sessionStorage` + * An implementation of {@link Persistence} of 'SESSION' using `sessionStorage` * for the underlying storage. * * @public diff --git a/packages-exp/auth-exp/src/platform_browser/popup_redirect.ts b/packages-exp/auth-exp/src/platform_browser/popup_redirect.ts index f6663812392..c24cea432ba 100644 --- a/packages-exp/auth-exp/src/platform_browser/popup_redirect.ts +++ b/packages-exp/auth-exp/src/platform_browser/popup_redirect.ts @@ -167,7 +167,7 @@ class BrowserPopupRedirectResolver implements PopupRedirectResolverInternal { } /** - * An implementation of {@link @firebase/auth-types#PopupRedirectResolver} suitable for browser + * An implementation of {@link PopupRedirectResolver} suitable for browser * based applications. * * @public diff --git a/packages-exp/auth-exp/src/platform_browser/strategies/phone.ts b/packages-exp/auth-exp/src/platform_browser/strategies/phone.ts index 08011922061..eb56cb48936 100644 --- a/packages-exp/auth-exp/src/platform_browser/strategies/phone.ts +++ b/packages-exp/auth-exp/src/platform_browser/strategies/phone.ts @@ -71,11 +71,11 @@ class ConfirmationResultImpl implements ConfirmationResult { * * @remarks * This method sends a code via SMS to the given - * phone number, and returns a {@link @firebase/auth-types#ConfirmationResult}. After the user - * provides the code sent to their phone, call {@link @firebase/auth-types#ConfirmationResult.confirm} + * phone number, and returns a {@link ConfirmationResult}. After the user + * provides the code sent to their phone, call {@link ConfirmationResult.confirm} * with the code to sign the user in. * - * For abuse prevention, this method also requires a {@link @firebase/auth-types#ApplicationVerifier}. + * For abuse prevention, this method also requires a {@link ApplicationVerifier}. * This SDK includes a reCAPTCHA-based implementation, {@link RecaptchaVerifier}. * * @example @@ -89,7 +89,7 @@ class ConfirmationResultImpl implements ConfirmationResult { * * @param auth - The Auth instance. * @param phoneNumber - The user's phone number in E.164 format (e.g. +16505550101). - * @param appVerifier - The {@link @firebase/auth-types#ApplicationVerifier}. + * @param appVerifier - The {@link ApplicationVerifier}. * * @public */ @@ -113,7 +113,7 @@ export async function signInWithPhoneNumber( * * @param user - The user. * @param phoneNumber - The user's phone number in E.164 format (e.g. +16505550101). - * @param appVerifier - The {@link @firebase/auth-types#ApplicationVerifier}. + * @param appVerifier - The {@link ApplicationVerifier}. * * @public */ @@ -141,7 +141,7 @@ export async function linkWithPhoneNumber( * * @param user - The user. * @param phoneNumber - The user's phone number in E.164 format (e.g. +16505550101). - * @param appVerifier - The {@link @firebase/auth-types#ApplicationVerifier}. + * @param appVerifier - The {@link ApplicationVerifier}. * * @public */ diff --git a/packages-exp/auth-exp/src/platform_browser/strategies/popup.ts b/packages-exp/auth-exp/src/platform_browser/strategies/popup.ts index 5cff26b1cd2..a895ef2fa6a 100644 --- a/packages-exp/auth-exp/src/platform_browser/strategies/popup.ts +++ b/packages-exp/auth-exp/src/platform_browser/strategies/popup.ts @@ -70,7 +70,7 @@ export const _POLL_WINDOW_CLOSE_TIMEOUT = new Delay(2000, 10000); * @param auth - The Auth instance. * @param provider - The provider to authenticate. The provider has to be an {@link OAuthProvider}. * Non-OAuth providers like {@link EmailAuthProvider} will throw an error. - * @param resolver - An instance of {@link @firebase/auth-types#PopupRedirectResolver}, optional + * @param resolver - An instance of {@link PopupRedirectResolver}, optional * if already supplied to {@link initializeAuth} or provided by {@link getAuth}. * * @@ -118,7 +118,7 @@ export async function signInWithPopup( * @param user - The user. * @param provider - The provider to authenticate. The provider has to be an {@link OAuthProvider}. * Non-OAuth providers like {@link EmailAuthProvider} will throw an error. - * @param resolver - An instance of {@link @firebase/auth-types#PopupRedirectResolver}, optional + * @param resolver - An instance of {@link PopupRedirectResolver}, optional * if already supplied to {@link initializeAuth} or provided by {@link getAuth}. * * @public @@ -165,7 +165,7 @@ export async function reauthenticateWithPopup( * @param user - The user. * @param provider - The provider to authenticate. The provider has to be an {@link OAuthProvider}. * Non-OAuth providers like {@link EmailAuthProvider} will throw an error. - * @param resolver - An instance of {@link @firebase/auth-types#PopupRedirectResolver}, optional + * @param resolver - An instance of {@link PopupRedirectResolver}, optional * if already supplied to {@link initializeAuth} or provided by {@link getAuth}. * * @public diff --git a/packages-exp/auth-exp/src/platform_browser/strategies/redirect.ts b/packages-exp/auth-exp/src/platform_browser/strategies/redirect.ts index a2dd6b3407a..a423e680aac 100644 --- a/packages-exp/auth-exp/src/platform_browser/strategies/redirect.ts +++ b/packages-exp/auth-exp/src/platform_browser/strategies/redirect.ts @@ -68,7 +68,7 @@ import { RedirectAction } from '../../core/strategies/redirect'; * @param auth - The Auth instance. * @param provider - The provider to authenticate. The provider has to be an {@link OAuthProvider}. * Non-OAuth providers like {@link EmailAuthProvider} will throw an error. - * @param resolver - An instance of {@link @firebase/auth-types#PopupRedirectResolver}, optional + * @param resolver - An instance of {@link PopupRedirectResolver}, optional * if already supplied to {@link initializeAuth} or provided by {@link getAuth}. * * @public @@ -115,7 +115,7 @@ export async function signInWithRedirect( * @param user - The user. * @param provider - The provider to authenticate. The provider has to be an {@link OAuthProvider}. * Non-OAuth providers like {@link EmailAuthProvider} will throw an error. - * @param resolver - An instance of {@link @firebase/auth-types#PopupRedirectResolver}, optional + * @param resolver - An instance of {@link PopupRedirectResolver}, optional * if already supplied to {@link initializeAuth} or provided by {@link getAuth}. * * @public @@ -163,7 +163,7 @@ export async function reauthenticateWithRedirect( * @param user - The user. * @param provider - The provider to authenticate. The provider has to be an {@link OAuthProvider}. * Non-OAuth providers like {@link EmailAuthProvider} will throw an error. - * @param resolver - An instance of {@link @firebase/auth-types#PopupRedirectResolver}, optional + * @param resolver - An instance of {@link PopupRedirectResolver}, optional * if already supplied to {@link initializeAuth} or provided by {@link getAuth}. * * @@ -195,11 +195,11 @@ export async function linkWithRedirect( } /** - * Returns a {@link @firebase/auth-types#UserCredential} from the redirect-based sign-in flow. + * Returns a {@link UserCredential} from the redirect-based sign-in flow. * * @remarks * If sign-in succeeded, returns the signed in user. If sign-in was unsuccessful, fails with an - * error. If no redirect operation was called, returns a {@link @firebase/auth-types#UserCredential} + * error. If no redirect operation was called, returns a {@link UserCredential} * with a null `user`. * * @example @@ -228,7 +228,7 @@ export async function linkWithRedirect( * ``` * * @param auth - The Auth instance. - * @param resolver - An instance of {@link @firebase/auth-types#PopupRedirectResolver}, optional + * @param resolver - An instance of {@link PopupRedirectResolver}, optional * if already supplied to {@link initializeAuth} or provided by {@link getAuth}. * * @public diff --git a/packages-exp/auth-exp/src/platform_cordova/popup_redirect/popup_redirect.ts b/packages-exp/auth-exp/src/platform_cordova/popup_redirect/popup_redirect.ts index dfa13bfb573..a6036fa61fd 100644 --- a/packages-exp/auth-exp/src/platform_cordova/popup_redirect/popup_redirect.ts +++ b/packages-exp/auth-exp/src/platform_cordova/popup_redirect/popup_redirect.ts @@ -156,7 +156,7 @@ class CordovaPopupRedirectResolver implements PopupRedirectResolverInternal { } /** - * An implementation of {@link @firebase/auth-types#PopupRedirectResolver} suitable for Cordova + * An implementation of {@link PopupRedirectResolver} suitable for Cordova * based applications. * * @public From 79cf7fe88d446c015ca130143d6dc5d177164dfe Mon Sep 17 00:00:00 2001 From: Feiyang1 Date: Thu, 18 Feb 2021 16:43:17 -0800 Subject: [PATCH 09/13] update auth-compat --- packages-exp/auth-compat-exp/index.node.ts | 1 - packages-exp/auth-compat-exp/index.ts | 2 +- packages-exp/auth-compat-exp/package.json | 2 +- packages-exp/auth-compat-exp/src/auth.test.ts | 17 ++- packages-exp/auth-compat-exp/src/auth.ts | 119 +++++++++--------- .../auth-compat-exp/src/persistence.ts | 5 +- .../src/phone_auth_provider.ts | 17 ++- .../auth-compat-exp/src/recaptcha_verifier.ts | 15 ++- packages-exp/auth-compat-exp/src/user.ts | 75 ++++++----- .../auth-compat-exp/src/user_credential.ts | 52 ++++---- .../auth-exp/demo/src/worker/web-worker.ts | 1 - packages-exp/auth-exp/internal/index.ts | 7 +- 12 files changed, 150 insertions(+), 163 deletions(-) diff --git a/packages-exp/auth-compat-exp/index.node.ts b/packages-exp/auth-compat-exp/index.node.ts index da6929c604f..e5319ff827c 100644 --- a/packages-exp/auth-compat-exp/index.node.ts +++ b/packages-exp/auth-compat-exp/index.node.ts @@ -21,5 +21,4 @@ * implementation that mandates having a separate entrypoint. Otherwise you can * just use index.ts */ - export * from './index'; diff --git a/packages-exp/auth-compat-exp/index.ts b/packages-exp/auth-compat-exp/index.ts index e5703130b0c..b970e3f030c 100644 --- a/packages-exp/auth-compat-exp/index.ts +++ b/packages-exp/auth-compat-exp/index.ts @@ -17,7 +17,7 @@ import firebase, { _FirebaseNamespace } from '@firebase/app-compat'; import * as impl from '@firebase/auth-exp/internal'; -import * as externs from '@firebase/auth-types-exp'; +import * as externs from '@firebase/auth-exp'; import { Component, ComponentType, diff --git a/packages-exp/auth-compat-exp/package.json b/packages-exp/auth-compat-exp/package.json index a364fb45bc9..63315766e68 100644 --- a/packages-exp/auth-compat-exp/package.json +++ b/packages-exp/auth-compat-exp/package.json @@ -20,7 +20,7 @@ "test:all": "run-p test:browser test:node", "test:ci": "node ../../scripts/run_tests_in_ci.js -s test:all", "test:browser": "karma start --single-run", - "test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha src/**/*.test.* --config ../../config/mocharc.node.js" + "test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha src/**/*.test.* --file ../auth-exp/src/platform_browser/iframe/gapi.iframes.ts --config ../../config/mocharc.node.js" }, "peerDependencies": { "@firebase/app-compat": "0.x" diff --git a/packages-exp/auth-compat-exp/src/auth.test.ts b/packages-exp/auth-compat-exp/src/auth.test.ts index 5b031ea29cc..77c5e7bc11f 100644 --- a/packages-exp/auth-compat-exp/src/auth.test.ts +++ b/packages-exp/auth-compat-exp/src/auth.test.ts @@ -16,8 +16,7 @@ */ import { FirebaseApp } from '@firebase/app-compat'; -import * as impl from '@firebase/auth-exp/internal'; -import { Config } from '@firebase/auth-exp'; +import * as exp from '@firebase/auth-exp/internal'; import { expect, use } from 'chai'; import * as sinon from 'sinon'; import * as sinonChai from 'sinon-chai'; @@ -29,13 +28,13 @@ use(sinonChai); // of the auth compat layer are more complicated: these tests cover those describe('auth compat', () => { context('redirect persistence key storage', () => { - let underlyingAuth: impl.AuthImpl; + let underlyingAuth: exp.AuthImpl; let app: FirebaseApp; beforeEach(() => { app = { options: { apiKey: 'api-key' } } as FirebaseApp; - underlyingAuth = new impl.AuthImpl(app, { + underlyingAuth = new exp.AuthImpl(app, { apiKey: 'api-key' - } as Config); + } as exp.Config); sinon.stub(underlyingAuth, '_initializeWithPersistence'); }); @@ -48,7 +47,7 @@ describe('auth compat', () => { if (typeof self !== 'undefined') { sinon.stub(underlyingAuth, '_getPersistence').returns('TEST'); // eslint-disable-next-line @typescript-eslint/no-floating-promises - authCompat.signInWithRedirect(new impl.GoogleAuthProvider()); + authCompat.signInWithRedirect(new exp.GoogleAuthProvider()); expect( sessionStorage.getItem('firebase:persistence:api-key:undefined') ).to.eq('TEST'); @@ -67,10 +66,10 @@ describe('auth compat', () => { underlyingAuth._initializeWithPersistence ).to.have.been.calledWith( [ - impl._getInstance(impl.inMemoryPersistence), - impl._getInstance(impl.indexedDBLocalPersistence) + exp._getInstance(exp.inMemoryPersistence), + exp._getInstance(exp.indexedDBLocalPersistence) ], - impl.browserPopupRedirectResolver + exp.browserPopupRedirectResolver ); } }); diff --git a/packages-exp/auth-compat-exp/src/auth.ts b/packages-exp/auth-compat-exp/src/auth.ts index cd5136c355b..992f6e27218 100644 --- a/packages-exp/auth-compat-exp/src/auth.ts +++ b/packages-exp/auth-compat-exp/src/auth.ts @@ -16,9 +16,8 @@ */ import { FirebaseApp, _FirebaseService } from '@firebase/app-compat'; -import * as impl from '@firebase/auth-exp/internal'; +import * as exp from '@firebase/auth-exp/internal'; import * as compat from '@firebase/auth-types'; -import * as externs from '@firebase/auth-exp'; import { ErrorFn, isIndexedDBAvailable, @@ -36,13 +35,13 @@ import { import { unwrap, Wrapper } from './wrap'; const PERSISTENCE_KEY = 'persistence'; -const _assert: typeof impl._assert = impl._assert; +const _assert: typeof exp._assert = exp._assert; export class Auth - implements compat.FirebaseAuth, Wrapper, _FirebaseService { + implements compat.FirebaseAuth, Wrapper, _FirebaseService { // private readonly auth: impl.AuthImpl; - constructor(readonly app: FirebaseApp, private readonly auth: impl.AuthImpl) { + constructor(readonly app: FirebaseApp, private readonly auth: exp.AuthImpl) { const { apiKey } = app.options; if (this.auth._deleted) { return; @@ -53,24 +52,26 @@ export class Auth // the fallback (if no user is found) to be the stored persistence type const storedPersistence = this.getPersistenceFromRedirect(); const persistences = storedPersistence ? [storedPersistence] : []; - persistences.push(impl.indexedDBLocalPersistence); + persistences.push(exp.indexedDBLocalPersistence); // TODO(avolkovi): Implement proper persistence fallback - const hierarchy = persistences.map(impl._getInstance); + const hierarchy = persistences.map( + exp._getInstance + ); // TODO: platform needs to be determined using heuristics - _assert(apiKey, impl.AuthErrorCode.INVALID_API_KEY, { + _assert(apiKey, exp.AuthErrorCode.INVALID_API_KEY, { appName: app.name }); - this.auth._updateErrorMap(impl.debugErrorMap); + this.auth._updateErrorMap(exp.debugErrorMap); // This promise is intended to float; auth initialization happens in the // background, meanwhile the auth object may be used by the app. // eslint-disable-next-line @typescript-eslint/no-floating-promises this.auth._initializeWithPersistence( hierarchy, - impl.browserPopupRedirectResolver + exp.browserPopupRedirectResolver ); } @@ -101,18 +102,18 @@ export class Auth return this.auth.signOut(); } useEmulator(url: string, options?: { disableWarnings: boolean }): void { - impl.useAuthEmulator(this.auth, url, options); + exp.useAuthEmulator(this.auth, url, options); } applyActionCode(code: string): Promise { - return impl.applyActionCode(this.auth, code); + return exp.applyActionCode(this.auth, code); } checkActionCode(code: string): Promise { - return impl.checkActionCode(this.auth, code); + return exp.checkActionCode(this.auth, code); } confirmPasswordReset(code: string, newPassword: string): Promise { - return impl.confirmPasswordReset(this.auth, code, newPassword); + return exp.confirmPasswordReset(this.auth, code, newPassword); } async createUserWithEmailAndPassword( @@ -121,27 +122,27 @@ export class Auth ): Promise { return convertCredential( this.auth, - impl.createUserWithEmailAndPassword(this.auth, email, password) + exp.createUserWithEmailAndPassword(this.auth, email, password) ); } fetchProvidersForEmail(email: string): Promise { return this.fetchSignInMethodsForEmail(email); } fetchSignInMethodsForEmail(email: string): Promise { - return impl.fetchSignInMethodsForEmail(this.auth, email); + return exp.fetchSignInMethodsForEmail(this.auth, email); } isSignInWithEmailLink(emailLink: string): boolean { - return impl.isSignInWithEmailLink(this.auth, emailLink); + return exp.isSignInWithEmailLink(this.auth, emailLink); } async getRedirectResult(): Promise { _assert( _isPopupRedirectSupported(), this.auth, - impl.AuthErrorCode.OPERATION_NOT_SUPPORTED + exp.AuthErrorCode.OPERATION_NOT_SUPPORTED ); - const credential = await impl.getRedirectResult( + const credential = await exp.getRedirectResult( this.auth, - impl.browserPopupRedirectResolver + exp.browserPopupRedirectResolver ); if (!credential) { return { @@ -179,13 +180,13 @@ export class Auth email: string, actionCodeSettings: compat.ActionCodeSettings ): Promise { - return impl.sendSignInLinkToEmail(this.auth, email, actionCodeSettings); + return exp.sendSignInLinkToEmail(this.auth, email, actionCodeSettings); } sendPasswordResetEmail( email: string, actionCodeSettings?: compat.ActionCodeSettings | null ): Promise { - return impl.sendPasswordResetEmail( + return exp.sendPasswordResetEmail( this.auth, email, actionCodeSettings || undefined @@ -193,21 +194,21 @@ export class Auth } async setPersistence(persistence: string): Promise { function convertPersistence( - auth: externs.Auth, + auth: exp.Auth, persistenceCompat: string - ): externs.Persistence { + ): exp.Persistence { _validatePersistenceArgument(auth, persistence); switch (persistenceCompat) { case Persistence.SESSION: - return impl.browserSessionPersistence; + return exp.browserSessionPersistence; case Persistence.LOCAL: return isIndexedDBAvailable() - ? impl.indexedDBLocalPersistence - : impl.browserLocalPersistence; + ? exp.indexedDBLocalPersistence + : exp.browserLocalPersistence; case Persistence.NONE: - return impl.inMemoryPersistence; + return exp.inMemoryPersistence; default: - return impl._fail(impl.AuthErrorCode.ARGUMENT_ERROR, { + return exp._fail(exp.AuthErrorCode.ARGUMENT_ERROR, { appName: auth.name }); } @@ -222,20 +223,20 @@ export class Auth return this.signInWithCredential(credential); } signInAnonymously(): Promise { - return convertCredential(this.auth, impl.signInAnonymously(this.auth)); + return convertCredential(this.auth, exp.signInAnonymously(this.auth)); } signInWithCredential( credential: compat.AuthCredential ): Promise { return convertCredential( this.auth, - impl.signInWithCredential(this.auth, credential as externs.AuthCredential) + exp.signInWithCredential(this.auth, credential as exp.AuthCredential) ); } signInWithCustomToken(token: string): Promise { return convertCredential( this.auth, - impl.signInWithCustomToken(this.auth, token) + exp.signInWithCustomToken(this.auth, token) ); } signInWithEmailAndPassword( @@ -244,7 +245,7 @@ export class Auth ): Promise { return convertCredential( this.auth, - impl.signInWithEmailAndPassword(this.auth, email, password) + exp.signInWithEmailAndPassword(this.auth, email, password) ); } signInWithEmailLink( @@ -253,7 +254,7 @@ export class Auth ): Promise { return convertCredential( this.auth, - impl.signInWithEmailLink(this.auth, email, emailLink) + exp.signInWithEmailLink(this.auth, email, emailLink) ); } signInWithPhoneNumber( @@ -262,7 +263,7 @@ export class Auth ): Promise { return convertConfirmationResult( this.auth, - impl.signInWithPhoneNumber( + exp.signInWithPhoneNumber( this.auth, phoneNumber, unwrap(applicationVerifier) @@ -275,14 +276,14 @@ export class Auth _assert( _isPopupRedirectSupported(), this.auth, - impl.AuthErrorCode.OPERATION_NOT_SUPPORTED + exp.AuthErrorCode.OPERATION_NOT_SUPPORTED ); return convertCredential( this.auth, - impl.signInWithPopup( + exp.signInWithPopup( this.auth, - provider as externs.AuthProvider, - impl.browserPopupRedirectResolver + provider as exp.AuthProvider, + exp.browserPopupRedirectResolver ) ); } @@ -290,22 +291,22 @@ export class Auth _assert( _isPopupRedirectSupported(), this.auth, - impl.AuthErrorCode.OPERATION_NOT_SUPPORTED + exp.AuthErrorCode.OPERATION_NOT_SUPPORTED ); this.savePersistenceForRedirect(); - return impl.signInWithRedirect( + return exp.signInWithRedirect( this.auth, - provider as externs.AuthProvider, - impl.browserPopupRedirectResolver + provider as exp.AuthProvider, + exp.browserPopupRedirectResolver ); } updateCurrentUser(user: compat.User | null): Promise { return this.auth.updateCurrentUser(unwrap(user)); } verifyPasswordResetCode(code: string): Promise { - return impl.verifyPasswordResetCode(this.auth, code); + return exp.verifyPasswordResetCode(this.auth, code); } - unwrap(): externs.Auth { + unwrap(): exp.Auth { return this.auth; } _delete(): Promise { @@ -314,7 +315,7 @@ export class Auth private savePersistenceForRedirect(): void { const win = getSelfWindow(); - const key = impl._persistenceKeyName( + const key = exp._persistenceKeyName( PERSISTENCE_KEY, this.auth.config.apiKey, this.auth.name @@ -324,13 +325,13 @@ export class Auth } } - private getPersistenceFromRedirect(): externs.Persistence | null { + private getPersistenceFromRedirect(): exp.Persistence | null { const win = getSelfWindow(); if (!win?.sessionStorage) { return null; } - const key = impl._persistenceKeyName( + const key = exp._persistenceKeyName( PERSISTENCE_KEY, this.auth.config.apiKey, this.auth.name @@ -338,14 +339,14 @@ export class Auth const persistence = win.sessionStorage.getItem(key); switch (persistence) { - case impl.inMemoryPersistence.type: - return impl.inMemoryPersistence; - case impl.indexedDBLocalPersistence.type: - return impl.indexedDBLocalPersistence; - case impl.browserSessionPersistence.type: - return impl.browserSessionPersistence; - case impl.browserLocalPersistence.type: - return impl.browserLocalPersistence; + case exp.inMemoryPersistence.type: + return exp.inMemoryPersistence; + case exp.indexedDBLocalPersistence.type: + return exp.indexedDBLocalPersistence; + case exp.browserSessionPersistence.type: + return exp.browserSessionPersistence; + case exp.browserLocalPersistence.type: + return exp.browserLocalPersistence; default: return null; } @@ -360,7 +361,7 @@ function wrapObservers( nextOrObserver: Observer | ((a: compat.User | null) => unknown), error?: (error: compat.Error) => unknown, complete?: Unsubscribe -): Partial> { +): Partial> { let next = nextOrObserver; if (typeof nextOrObserver !== 'function') { ({ next, error, complete } = nextOrObserver); @@ -369,8 +370,8 @@ function wrapObservers( // We know 'next' is now a function const oldNext = next as (a: compat.User | null) => unknown; - const newNext = (user: externs.User | null): unknown => - oldNext(user && User.getOrCreate(user as externs.User)); + const newNext = (user: exp.User | null): unknown => + oldNext(user && User.getOrCreate(user as exp.User)); return { next: newNext, error: error as ErrorFn, diff --git a/packages-exp/auth-compat-exp/src/persistence.ts b/packages-exp/auth-compat-exp/src/persistence.ts index de5767d96ed..ac415935197 100644 --- a/packages-exp/auth-compat-exp/src/persistence.ts +++ b/packages-exp/auth-compat-exp/src/persistence.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { _assert, AuthErrorCode } from '@firebase/auth-exp/internal'; -import * as externs from '@firebase/auth-exp'; +import { _assert, AuthErrorCode, Auth } from '@firebase/auth-exp/internal'; import { isIndexedDBAvailable, isNode, isReactNative } from '@firebase/util'; import { _isWebStorageSupported, _isWorker } from './platform'; @@ -31,7 +30,7 @@ export const Persistence = { * is specified, an error is thrown synchronously. */ export function _validatePersistenceArgument( - auth: externs.Auth, + auth: Auth, persistence: string ): void { _assert( diff --git a/packages-exp/auth-compat-exp/src/phone_auth_provider.ts b/packages-exp/auth-compat-exp/src/phone_auth_provider.ts index 539ae47a454..d6564e2b88b 100644 --- a/packages-exp/auth-compat-exp/src/phone_auth_provider.ts +++ b/packages-exp/auth-compat-exp/src/phone_auth_provider.ts @@ -15,31 +15,30 @@ * limitations under the License. */ -import * as impl from '@firebase/auth-exp/internal'; +import * as exp from '@firebase/auth-exp/internal'; import * as compat from '@firebase/auth-types'; -import * as externs from '@firebase/auth-exp'; import firebase from '@firebase/app-compat'; import { unwrap, Wrapper } from './wrap'; export class PhoneAuthProvider - implements compat.PhoneAuthProvider, Wrapper { + implements compat.PhoneAuthProvider, Wrapper { providerId = 'phone'; - private readonly phoneProvider: impl.PhoneAuthProvider; + private readonly phoneProvider: exp.PhoneAuthProvider; - static PHONE_SIGN_IN_METHOD = impl.PhoneAuthProvider.PHONE_SIGN_IN_METHOD; - static PROVIDER_ID = impl.PhoneAuthProvider.PROVIDER_ID; + static PHONE_SIGN_IN_METHOD = exp.PhoneAuthProvider.PHONE_SIGN_IN_METHOD; + static PROVIDER_ID = exp.PhoneAuthProvider.PROVIDER_ID; static credential( verificationId: string, verificationCode: string ): compat.AuthCredential { - return impl.PhoneAuthProvider.credential(verificationId, verificationCode); + return exp.PhoneAuthProvider.credential(verificationId, verificationCode); } constructor() { // TODO: remove ts-ignore when moving types from auth-types to auth-compat // @ts-ignore - this.phoneProvider = new impl.PhoneAuthProvider(unwrap(firebase.auth!())); + this.phoneProvider = new exp.PhoneAuthProvider(unwrap(firebase.auth!())); } verifyPhoneNumber( @@ -58,7 +57,7 @@ export class PhoneAuthProvider ); } - unwrap(): externs.PhoneAuthProvider { + unwrap(): exp.PhoneAuthProvider { return this.phoneProvider; } } diff --git a/packages-exp/auth-compat-exp/src/recaptcha_verifier.ts b/packages-exp/auth-compat-exp/src/recaptcha_verifier.ts index 6ad59197b57..2b60d75f44e 100644 --- a/packages-exp/auth-compat-exp/src/recaptcha_verifier.ts +++ b/packages-exp/auth-compat-exp/src/recaptcha_verifier.ts @@ -16,16 +16,15 @@ */ import firebase, { FirebaseApp } from '@firebase/app-compat'; -import * as impl from '@firebase/auth-exp/internal'; +import * as exp from '@firebase/auth-exp/internal'; import * as compat from '@firebase/auth-types'; -import * as externs from '@firebase/auth-types-exp'; import { unwrap, Wrapper } from './wrap'; -const _assert: typeof impl._assert = impl._assert; +const _assert: typeof exp._assert = exp._assert; export class RecaptchaVerifier - implements compat.RecaptchaVerifier, Wrapper { - readonly verifier: externs.RecaptchaVerifier; + implements compat.RecaptchaVerifier, Wrapper { + readonly verifier: exp.RecaptchaVerifier; type: string; constructor( container: HTMLElement | string, @@ -33,10 +32,10 @@ export class RecaptchaVerifier app: FirebaseApp = firebase.app() ) { // API key is required for web client RPC calls. - _assert(app.options?.apiKey, impl.AuthErrorCode.INVALID_API_KEY, { + _assert(app.options?.apiKey, exp.AuthErrorCode.INVALID_API_KEY, { appName: app.name }); - this.verifier = new impl.RecaptchaVerifier( + this.verifier = new exp.RecaptchaVerifier( container, // eslint-disable-next-line @typescript-eslint/no-explicit-any parameters as any, @@ -56,7 +55,7 @@ export class RecaptchaVerifier verify(): Promise { return this.verifier.verify(); } - unwrap(): externs.ApplicationVerifier { + unwrap(): exp.ApplicationVerifier { return this.verifier; } } diff --git a/packages-exp/auth-compat-exp/src/user.ts b/packages-exp/auth-compat-exp/src/user.ts index 2bd42039e26..6a1dc97849d 100644 --- a/packages-exp/auth-compat-exp/src/user.ts +++ b/packages-exp/auth-compat-exp/src/user.ts @@ -15,27 +15,26 @@ * limitations under the License. */ -import * as impl from '@firebase/auth-exp/internal'; +import * as exp from '@firebase/auth-exp/internal'; import * as compat from '@firebase/auth-types'; -import * as externs from '@firebase/auth-types-exp'; import { convertConfirmationResult, convertCredential } from './user_credential'; import { unwrap, Wrapper } from './wrap'; -export class User implements compat.User, Wrapper { +export class User implements compat.User, Wrapper { // Maintain a map so that there's always a 1:1 mapping between new User and // legacy compat users - private static readonly USER_MAP = new WeakMap(); + private static readonly USER_MAP = new WeakMap(); readonly multiFactor: compat.MultiFactorUser; - private constructor(private readonly user: externs.User) { - this.multiFactor = impl.multiFactor(user); + private constructor(private readonly user: exp.User) { + this.multiFactor = exp.multiFactor(user); } - static getOrCreate(user: externs.User): User { + static getOrCreate(user: exp.User): User { if (!User.USER_MAP.has(user)) { User.USER_MAP.set(user, new User(user)); } @@ -68,7 +67,7 @@ export class User implements compat.User, Wrapper { ): Promise { return convertCredential( this.auth, - impl.linkWithCredential(this.user, credential as externs.AuthCredential) + exp.linkWithCredential(this.user, credential as exp.AuthCredential) ); } async linkWithPhoneNumber( @@ -77,7 +76,7 @@ export class User implements compat.User, Wrapper { ): Promise { return convertConfirmationResult( this.auth, - impl.linkWithPhoneNumber( + exp.linkWithPhoneNumber( this.user, phoneNumber, unwrap(applicationVerifier) @@ -89,18 +88,18 @@ export class User implements compat.User, Wrapper { ): Promise { return convertCredential( this.auth, - impl.linkWithPopup( + exp.linkWithPopup( this.user, - provider as externs.AuthProvider, - impl.browserPopupRedirectResolver + provider as exp.AuthProvider, + exp.browserPopupRedirectResolver ) ); } linkWithRedirect(provider: compat.AuthProvider): Promise { - return impl.linkWithRedirect( + return exp.linkWithRedirect( this.user, - provider as externs.AuthProvider, - impl.browserPopupRedirectResolver + provider as exp.AuthProvider, + exp.browserPopupRedirectResolver ); } reauthenticateAndRetrieveDataWithCredential( @@ -112,10 +111,10 @@ export class User implements compat.User, Wrapper { credential: compat.AuthCredential ): Promise { return convertCredential( - (this.auth as unknown) as externs.Auth, - impl.reauthenticateWithCredential( + (this.auth as unknown) as exp.Auth, + exp.reauthenticateWithCredential( this.user, - credential as externs.AuthCredential + credential as exp.AuthCredential ) ); } @@ -125,7 +124,7 @@ export class User implements compat.User, Wrapper { ): Promise { return convertConfirmationResult( this.auth, - impl.reauthenticateWithPhoneNumber( + exp.reauthenticateWithPhoneNumber( this.user, phoneNumber, unwrap(applicationVerifier) @@ -137,58 +136,54 @@ export class User implements compat.User, Wrapper { ): Promise { return convertCredential( this.auth, - impl.reauthenticateWithPopup( + exp.reauthenticateWithPopup( this.user, - provider as externs.AuthProvider, - impl.browserPopupRedirectResolver + provider as exp.AuthProvider, + exp.browserPopupRedirectResolver ) ); } reauthenticateWithRedirect(provider: compat.AuthProvider): Promise { - return impl.reauthenticateWithRedirect( + return exp.reauthenticateWithRedirect( this.user, - provider as externs.AuthProvider, - impl.browserPopupRedirectResolver + provider as exp.AuthProvider, + exp.browserPopupRedirectResolver ); } sendEmailVerification( actionCodeSettings?: compat.ActionCodeSettings | null ): Promise { - return impl.sendEmailVerification(this.user, actionCodeSettings); + return exp.sendEmailVerification(this.user, actionCodeSettings); } async unlink(providerId: string): Promise { - await impl.unlink(this.user, providerId as externs.ProviderId); + await exp.unlink(this.user, providerId as exp.ProviderId); return this; } updateEmail(newEmail: string): Promise { - return impl.updateEmail(this.user, newEmail); + return exp.updateEmail(this.user, newEmail); } updatePassword(newPassword: string): Promise { - return impl.updatePassword(this.user, newPassword); + return exp.updatePassword(this.user, newPassword); } updatePhoneNumber(phoneCredential: compat.AuthCredential): Promise { - return impl.updatePhoneNumber( + return exp.updatePhoneNumber( this.user, - phoneCredential as externs.AuthCredential + phoneCredential as exp.PhoneAuthCredential ); } updateProfile(profile: { displayName?: string | null; photoURL?: string | null; }): Promise { - return impl.updateProfile(this.user, profile); + return exp.updateProfile(this.user, profile); } verifyBeforeUpdateEmail( newEmail: string, actionCodeSettings?: compat.ActionCodeSettings | null ): Promise { - return impl.verifyBeforeUpdateEmail( - this.user, - newEmail, - actionCodeSettings - ); + return exp.verifyBeforeUpdateEmail(this.user, newEmail, actionCodeSettings); } - unwrap(): externs.User { + unwrap(): exp.User { return this.user; } get emailVerified(): boolean { @@ -227,7 +222,7 @@ export class User implements compat.User, Wrapper { get uid(): string { return this.user.uid; } - private get auth(): externs.Auth { - return ((this.user as impl.UserImpl).auth as unknown) as externs.Auth; + private get auth(): exp.Auth { + return ((this.user as exp.UserImpl).auth as unknown) as exp.Auth; } } diff --git a/packages-exp/auth-compat-exp/src/user_credential.ts b/packages-exp/auth-compat-exp/src/user_credential.ts index 00d5c2f1fa7..e7ad902129e 100644 --- a/packages-exp/auth-compat-exp/src/user_credential.ts +++ b/packages-exp/auth-compat-exp/src/user_credential.ts @@ -15,14 +15,13 @@ * limitations under the License. */ -import * as impl from '@firebase/auth-exp/internal'; +import * as exp from '@firebase/auth-exp/internal'; import * as compat from '@firebase/auth-types'; -import * as externs from '@firebase/auth-exp'; import { User } from './user'; function credentialFromResponse( - userCredential: impl.UserCredential -): externs.AuthCredential | null { + userCredential: exp.UserCredentialInternal +): exp.AuthCredential | null { const { providerId, _tokenResponse } = userCredential; if (!_tokenResponse) { return null; @@ -30,24 +29,23 @@ function credentialFromResponse( // Handle phone Auth credential responses, as they have a different format // from other backend responses (i.e. no providerId). if ('temporaryProof' in _tokenResponse && 'phoneNumber' in _tokenResponse) { - // return impl.PhoneAuthProvider.credentialFromResult(userCredential); - return impl.PhoneAuthProvider.credentialFromResult({} as any); + return exp.PhoneAuthProvider.credentialFromResult(userCredential); } // Email and password is not supported as there is no situation where the // server would return the password to the client. - if (!providerId || providerId === externs.ProviderId.PASSWORD) { + if (!providerId || providerId === exp.ProviderId.PASSWORD) { return null; } switch (providerId) { - case externs.ProviderId.GOOGLE: - return impl.GoogleAuthProvider.credentialFromResult(userCredential); - case externs.ProviderId.FACEBOOK: - return impl.FacebookAuthProvider.credentialFromResult(userCredential!); - case externs.ProviderId.GITHUB: - return impl.GithubAuthProvider.credentialFromResult(userCredential!); - case externs.ProviderId.TWITTER: - return impl.TwitterAuthProvider.credentialFromResult(userCredential); + case exp.ProviderId.GOOGLE: + return exp.GoogleAuthProvider.credentialFromResult(userCredential); + case exp.ProviderId.FACEBOOK: + return exp.FacebookAuthProvider.credentialFromResult(userCredential!); + case exp.ProviderId.GITHUB: + return exp.GithubAuthProvider.credentialFromResult(userCredential!); + case exp.ProviderId.TWITTER: + return exp.TwitterAuthProvider.credentialFromResult(userCredential); default: const { oauthIdToken, @@ -55,7 +53,7 @@ function credentialFromResponse( oauthTokenSecret, pendingToken, nonce - } = _tokenResponse as impl.SignInWithIdpResponse; + } = _tokenResponse as exp.SignInWithIdpResponse; if ( !oauthAccessToken && !oauthTokenSecret && @@ -80,7 +78,7 @@ function credentialFromResponse( // providerId); // } // } - return new impl.OAuthProvider(providerId).credential({ + return new exp.OAuthProvider(providerId).credential({ idToken: oauthIdToken, accessToken: oauthAccessToken, rawNonce: nonce @@ -89,15 +87,15 @@ function credentialFromResponse( } export async function convertCredential( - auth: externs.Auth, - credentialPromise: Promise + auth: exp.Auth, + credentialPromise: Promise ): Promise { - let credential: externs.UserCredential; + let credential: exp.UserCredential; try { credential = await credentialPromise; } catch (e) { if (e.code === 'auth/multi-factor-auth-required') { - e.resolver = impl.getMultiFactorResolver(auth, e); + e.resolver = exp.getMultiFactorResolver(auth, e); } throw e; } @@ -105,17 +103,19 @@ export async function convertCredential( return { operationType, - credential: credentialFromResponse(credential as impl.UserCredential), - additionalUserInfo: impl.getAdditionalUserInfo( - credential as impl.UserCredential + credential: credentialFromResponse( + credential as exp.UserCredentialInternal + ), + additionalUserInfo: exp.getAdditionalUserInfo( + credential as exp.UserCredential ), user: User.getOrCreate(user) }; } export async function convertConfirmationResult( - auth: externs.Auth, - confirmationResultPromise: Promise + auth: exp.Auth, + confirmationResultPromise: Promise ): Promise { const confirmationResultExp = await confirmationResultPromise; return { diff --git a/packages-exp/auth-exp/demo/src/worker/web-worker.ts b/packages-exp/auth-exp/demo/src/worker/web-worker.ts index b6a20defd0d..39a089e7d56 100644 --- a/packages-exp/auth-exp/demo/src/worker/web-worker.ts +++ b/packages-exp/auth-exp/demo/src/worker/web-worker.ts @@ -24,7 +24,6 @@ import { signInWithCredential, signInWithEmailAndPassword, updateProfile, - OAuthCredential, User } from '@firebase/auth-exp'; diff --git a/packages-exp/auth-exp/internal/index.ts b/packages-exp/auth-exp/internal/index.ts index 32fadd398b2..b66c1059389 100644 --- a/packages-exp/auth-exp/internal/index.ts +++ b/packages-exp/auth-exp/internal/index.ts @@ -22,14 +22,11 @@ export * from '../index'; export { SignInWithIdpResponse } from '../src/api/authentication/idp'; export { AuthErrorCode } from '../src/core/errors'; -export { PersistenceInternal as Persistence } from '../src/core/persistence'; +export { PersistenceInternal } from '../src/core/persistence'; export { _persistenceKeyName } from '../src/core/persistence/persistence_user_manager'; export { UserImpl } from '../src/core/user/user_impl'; export { _getInstance } from '../src/core/util/instantiator'; -export { - UserCredentialInternal as UserCredential, - UserParameters -} from '../src/model/user'; +export { UserCredentialInternal, UserParameters } from '../src/model/user'; export { registerAuth } from '../src/core/auth/register'; export { DefaultConfig, AuthImpl } from '../src/core/auth/auth_impl'; From 92a31947e1ca11afd75a76f64ea4dae130a182bf Mon Sep 17 00:00:00 2001 From: Feiyang1 Date: Thu, 18 Feb 2021 23:21:59 -0800 Subject: [PATCH 10/13] remove problematic link --- packages-exp/auth-exp/src/core/strategies/credential.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages-exp/auth-exp/src/core/strategies/credential.ts b/packages-exp/auth-exp/src/core/strategies/credential.ts index c0736e0875d..9ea1b160d6b 100644 --- a/packages-exp/auth-exp/src/core/strategies/credential.ts +++ b/packages-exp/auth-exp/src/core/strategies/credential.ts @@ -99,8 +99,7 @@ export async function linkWithCredential( * * @remarks * Use before operations such as {@link updatePassword} that require tokens from recent sign-in - * attempts. This method can be used to recover from a - * {@link debugErrorMap.CREDENTIAL_TOO_OLD_LOGIN_AGAIN} error. + * attempts. This method can be used to recover from a CREDENTIAL_TOO_OLD_LOGIN_AGAIN error. * * @param user - The user. * @param credential - The auth credential. From 67208d3745512c96f09489dd32b8ca2d8b615920 Mon Sep 17 00:00:00 2001 From: Feiyang1 Date: Fri, 19 Feb 2021 11:23:31 -0800 Subject: [PATCH 11/13] uncomment build rules --- packages-exp/auth-exp/rollup.config.shared.js | 120 +++++++++--------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/packages-exp/auth-exp/rollup.config.shared.js b/packages-exp/auth-exp/rollup.config.shared.js index db2299ef127..81d65847521 100644 --- a/packages-exp/auth-exp/rollup.config.shared.js +++ b/packages-exp/auth-exp/rollup.config.shared.js @@ -57,69 +57,69 @@ export function getConfig({ isReleaseBuild }) { output: [{ dir: 'dist/esm5', format: 'esm', sourcemap: true }], plugins: es5BuildPlugins, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) - } + }, /** * Web Worker Build (compiled without DOM) */ - // { - // input: 'index.webworker.ts', - // output: [{ file: pkg.webworker, format: 'es', sourcemap: true }], - // plugins: [ - // ...commonPlugins, - // getTypesScriptPlugin({ - // isReleaseBuild, - // compilerOptions: { - // lib: [ - // // Remove dom after we figure out why navigator stuff doesn't exist - // 'dom', - // 'es2015', - // 'webworker' - // ] - // } - // }) - // ], - // external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) - // }, - // /** - // * Node.js Build - // */ - // { - // input: { - // index: 'index.node.ts', - // internal: 'internal/index.ts' - // }, - // output: [{ dir: 'dist/node', format: 'cjs', sourcemap: true }], - // plugins: es5BuildPlugins, - // external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) - // }, - // /** - // * Cordova Builds - // */ - // { - // input: { - // index: 'index.cordova.ts', - // internal: 'internal/index.ts' - // }, - // output: [{ dir: 'dist/cordova', format: 'es', sourcemap: true }], - // plugins: es5BuildPlugins, - // external: id => - // [...deps, 'cordova'].some(dep => id === dep || id.startsWith(`${dep}/`)) - // }, - // /** - // * React Native Builds - // */ - // { - // input: { - // index: 'index.rn.ts', - // internal: 'internal/index.ts' - // }, - // output: [{ dir: 'dist/rn', format: 'cjs', sourcemap: true }], - // plugins: es5BuildPlugins, - // external: id => - // [...deps, 'react-native'].some( - // dep => id === dep || id.startsWith(`${dep}/`) - // ) - // } + { + input: 'index.webworker.ts', + output: [{ file: pkg.webworker, format: 'es', sourcemap: true }], + plugins: [ + ...commonPlugins, + getTypesScriptPlugin({ + isReleaseBuild, + compilerOptions: { + lib: [ + // Remove dom after we figure out why navigator stuff doesn't exist + 'dom', + 'es2015', + 'webworker' + ] + } + }) + ], + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) + }, + /** + * Node.js Build + */ + { + input: { + index: 'index.node.ts', + internal: 'internal/index.ts' + }, + output: [{ dir: 'dist/node', format: 'cjs', sourcemap: true }], + plugins: es5BuildPlugins, + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) + }, + /** + * Cordova Builds + */ + { + input: { + index: 'index.cordova.ts', + internal: 'internal/index.ts' + }, + output: [{ dir: 'dist/cordova', format: 'es', sourcemap: true }], + plugins: es5BuildPlugins, + external: id => + [...deps, 'cordova'].some(dep => id === dep || id.startsWith(`${dep}/`)) + }, + /** + * React Native Builds + */ + { + input: { + index: 'index.rn.ts', + internal: 'internal/index.ts' + }, + output: [{ dir: 'dist/rn', format: 'cjs', sourcemap: true }], + plugins: es5BuildPlugins, + external: id => + [...deps, 'react-native'].some( + dep => id === dep || id.startsWith(`${dep}/`) + ) + } ]; /** From a86b1201db1d89291f54b2d8e94912a6b262553b Mon Sep 17 00:00:00 2001 From: Feiyang1 Date: Tue, 23 Feb 2021 12:53:06 -0800 Subject: [PATCH 12/13] remove unnecessary renaming --- packages-exp/auth-exp/src/api/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages-exp/auth-exp/src/api/index.ts b/packages-exp/auth-exp/src/api/index.ts index 5c3d8284d7f..a16751f5c78 100644 --- a/packages-exp/auth-exp/src/api/index.ts +++ b/packages-exp/auth-exp/src/api/index.ts @@ -23,7 +23,7 @@ import { Delay } from '../core/util/delay'; import { _emulatorUrl } from '../core/util/emulator'; import { FetchProvider } from '../core/util/fetch_provider'; import { Auth } from '../model/public_types'; -import { AuthInternal as AuthInternal } from '../model/auth'; +import { AuthInternal } from '../model/auth'; import { IdTokenResponse, TaggedWithTokenResponse } from '../model/id_token'; import { IdTokenMfaResponse } from './authentication/mfa'; import { SERVER_ERROR_MAP, ServerError, ServerErrorMap } from './errors'; From 9af08bee609b1fdce9a483071b4b407786e0f5da Mon Sep 17 00:00:00 2001 From: Feiyang1 Date: Tue, 23 Feb 2021 12:55:58 -0800 Subject: [PATCH 13/13] remove stray reference to auth-types-exp --- .github/CODEOWNERS | 2 -- packages-exp/auth-exp/demo/package.json | 1 - 2 files changed, 3 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index e8c1b23497e..4cb5320fcd1 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -90,7 +90,6 @@ scripts/docgen/content-sources/ @firebase/firebase-techwriters @firebase/jssdk-g # Auth-Exp Code packages-exp/auth-exp @avolkovi @samhorlbeck @yuchenshi @firebase/jssdk-global-approvers -packages-exp/auth-types-exp @avolkovi @samhorlbeck @yuchenshi @firebase/jssdk-global-approvers packages-exp/auth-compat-exp @avolkovi @samhorlbeck @yuchenshi @firebase/jssdk-global-approvers # Installations-Exp Code @@ -103,5 +102,4 @@ packages/performance-types-exp @alikn @zijianjoy @firebase/jssdk-global-approve # RC-Exp Code packages/remote-config-exp @erikeldridge @firebase/jssdk-global-approvers -packages/remote-config-types-exp @erikeldridge @firebase/jssdk-global-approvers packages/remote-config-compat @erikeldridge @firebase/jssdk-global-approvers \ No newline at end of file diff --git a/packages-exp/auth-exp/demo/package.json b/packages-exp/auth-exp/demo/package.json index 961dc9fd08d..25bceaa84f6 100644 --- a/packages-exp/auth-exp/demo/package.json +++ b/packages-exp/auth-exp/demo/package.json @@ -18,7 +18,6 @@ "dependencies": { "@firebase/app-exp": "0.0.900", "@firebase/auth-exp": "0.0.900", - "@firebase/auth-types-exp": "0.0.900", "@firebase/logger": "0.2.6", "@firebase/util": "0.3.4", "tslib": "^1.11.1"