Skip to content

Remove all public const enums; export maps instead (with typings to strings) #5022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 40 additions & 48 deletions common/api-review/auth-exp.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ export interface ActionCodeInfo {
multiFactorInfo?: MultiFactorInfo | null;
previousEmail?: string | null;
};
operation: ActionCodeOperation;
operation: typeof ActionCodeOperation[keyof typeof 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 const ActionCodeOperation: {
readonly EMAIL_SIGNIN: "EMAIL_SIGNIN";
readonly PASSWORD_RESET: "PASSWORD_RESET";
readonly RECOVER_EMAIL: "RECOVER_EMAIL";
readonly REVERT_SECOND_FACTOR_ADDITION: "REVERT_SECOND_FACTOR_ADDITION";
readonly VERIFY_AND_CHANGE_EMAIL: "VERIFY_AND_CHANGE_EMAIL";
readonly VERIFY_EMAIL: "VERIFY_EMAIL";
};

// @public
export interface ActionCodeSettings {
Expand All @@ -56,7 +56,7 @@ export class ActionCodeURL {
readonly code: string;
readonly continueUrl: string | null;
readonly languageCode: string | null;
readonly operation: ActionCodeOperation;
readonly operation: string;
static parseLink(link: string): ActionCodeURL | null;
readonly tenantId: string | null;
}
Expand Down Expand Up @@ -239,9 +239,9 @@ export class FacebookAuthProvider extends BaseOAuthProvider {
}

// @public
export const enum FactorId {
PHONE = "phone"
}
export const FactorId: {
readonly PHONE: "phone";
};

// @public
export function fetchSignInMethodsForEmail(auth: Auth, email: string): Promise<string[]>;
Expand Down Expand Up @@ -324,19 +324,19 @@ export function multiFactor(user: User): MultiFactorUser;

// @public
export interface MultiFactorAssertion {
readonly factorId: FactorId;
readonly factorId: typeof FactorId[keyof typeof FactorId];
}

// @public
export interface MultiFactorError extends AuthError {
readonly operationType: OperationType;
readonly operationType: typeof OperationType[keyof typeof OperationType];
}

// @public
export interface MultiFactorInfo {
readonly displayName?: string | null;
readonly enrollmentTime: string;
readonly factorId: FactorId;
readonly factorId: typeof FactorId[keyof typeof FactorId];
readonly uid: string;
}

Expand Down Expand Up @@ -405,11 +405,11 @@ export function onAuthStateChanged(auth: Auth, nextOrObserver: NextOrObserver<Us
export function onIdTokenChanged(auth: Auth, nextOrObserver: NextOrObserver<User>, error?: ErrorFn, completed?: CompleteFn): Unsubscribe;

// @public
export const enum OperationType {
LINK = "link",
REAUTHENTICATE = "reauthenticate",
SIGN_IN = "signIn"
}
export const OperationType: {
readonly LINK: "link";
readonly REAUTHENTICATE: "reauthenticate";
readonly SIGN_IN: "signIn";
};

// @public
export function parseActionCodeURL(link: string): ActionCodeURL | null;
Expand Down Expand Up @@ -502,20 +502,14 @@ export interface PopupRedirectResolver {
export const prodErrorMap: AuthErrorMap;

// @public
export const enum ProviderId {
// @internal (undocumented)
ANONYMOUS = "anonymous",
// @internal (undocumented)
CUSTOM = "custom",
FACEBOOK = "facebook.com",
// @internal (undocumented)
FIREBASE = "firebase",
GITHUB = "github.com",
GOOGLE = "google.com",
PASSWORD = "password",
PHONE = "phone",
TWITTER = "twitter.com"
}
export const ProviderId: {
readonly FACEBOOK: "facebook.com";
readonly GITHUB: "github.com";
readonly GOOGLE: "google.com";
readonly PASSWORD: "password";
readonly PHONE: "phone";
readonly TWITTER: "twitter.com";
};

// @public
export interface ReactNativeAsyncStorage {
Expand Down Expand Up @@ -583,17 +577,15 @@ export function setPersistence(auth: Auth, persistence: Persistence): Promise<vo
export function signInAnonymously(auth: Auth): Promise<UserCredential>;

// @public
export const enum SignInMethod {
// @internal (undocumented)
ANONYMOUS = "anonymous",
EMAIL_LINK = "emailLink",
EMAIL_PASSWORD = "password",
FACEBOOK = "facebook.com",
GITHUB = "github.com",
GOOGLE = "google.com",
PHONE = "phone",
TWITTER = "twitter.com"
}
export const SignInMethod: {
readonly EMAIL_LINK: "emailLink";
readonly EMAIL_PASSWORD: "password";
readonly FACEBOOK: "facebook.com";
readonly GITHUB: "github.com";
readonly GOOGLE: "google.com";
readonly PHONE: "phone";
readonly TWITTER: "twitter.com";
};

// @public
export function signInWithCredential(auth: Auth, credential: AuthCredential): Promise<UserCredential>;
Expand Down Expand Up @@ -630,7 +622,7 @@ export class TwitterAuthProvider extends BaseOAuthProvider {
}

// @public
export function unlink(user: User, providerId: ProviderId): Promise<User>;
export function unlink(user: User, providerId: string): Promise<User>;

export { Unsubscribe }

Expand Down Expand Up @@ -677,7 +669,7 @@ export interface User extends UserInfo {

// @public
export interface UserCredential {
operationType: OperationType;
operationType: typeof OperationType[keyof typeof OperationType];
providerId: string | null;
user: User;
}
Expand Down
2 changes: 1 addition & 1 deletion packages-exp/auth-compat-exp/src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class User implements compat.User, Compat<exp.User> {
return exp.sendEmailVerification(this._delegate, actionCodeSettings);
}
async unlink(providerId: string): Promise<compat.User> {
await exp.unlink(this._delegate, providerId as exp.ProviderId);
await exp.unlink(this._delegate, providerId);
return this;
}
updateEmail(newEmail: string): Promise<void> {
Expand Down
7 changes: 7 additions & 0 deletions packages-exp/auth-exp/index.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ FetchProvider.initialize(

// Core functionality shared by all clients
export * from './src';
export {
FactorId,
ProviderId,
SignInMethod,
OperationType,
ActionCodeOperation
} from './src/model/enum_maps';

export function getAuth(app: FirebaseApp): Auth {
const provider = _getProvider(app, 'auth-exp');
Expand Down
15 changes: 9 additions & 6 deletions packages-exp/auth-exp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ import { Auth } from './src/model/public_types';

// Public types
export {
// Enums
ActionCodeOperation,
FactorId,
OperationType,
ProviderId,
SignInMethod,
// Interfaces
ActionCodeInfo,
ActionCodeSettings,
Expand Down Expand Up @@ -79,6 +73,15 @@ export {
Unsubscribe
} from './src/model/public_types';

// Helper maps (not used internally)
export {
FactorId,
ProviderId,
SignInMethod,
OperationType,
ActionCodeOperation
} from './src/model/enum_maps';

// Core functionality shared by all clients
export * from './src';

Expand Down
2 changes: 1 addition & 1 deletion packages-exp/auth-exp/src/core/action_code_url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class ActionCodeURL {
* The action performed by the email action link. It returns from one of the types from
* {@link ActionCodeInfo}
*/
readonly operation: ActionCodeOperation;
readonly operation: string;
/**
* The tenant ID of the email action link. Null if the email action is from the parent project.
*/
Expand Down
5 changes: 1 addition & 4 deletions packages-exp/auth-exp/src/core/user/link_unlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ import { getModularInstance } from '@firebase/util';
*
* @public
*/
export async function unlink(
user: User,
providerId: ProviderId
): Promise<User> {
export async function unlink(user: User, providerId: string): Promise<User> {
const userInternal = getModularInstance(user) as UserInternal;
await _assertLinkedStatus(true, userInternal, providerId);
const { providerUserInfo } = await deleteLinkedAccounts(userInternal.auth, {
Expand Down
102 changes: 102 additions & 0 deletions packages-exp/auth-exp/src/model/enum_maps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* An enum of factors that may be used for multifactor authentication.
*
* @public
*/
export const FactorId = {
/** Phone as second factor */
PHONE: 'phone'
} as const;

/**
* Enumeration of supported providers.
*
* @public
*/
export const ProviderId = {
/** Facebook provider ID */
FACEBOOK: 'facebook.com',
/** GitHub provider ID */
GITHUB: 'github.com',
/** Google provider ID */
GOOGLE: 'google.com',
/** Password provider */
PASSWORD: 'password',
/** Phone provider */
PHONE: 'phone',
/** Twitter provider ID */
TWITTER: 'twitter.com'
} as const;

/**
* Enumeration of supported sign-in methods.
*
* @public
*/
export const SignInMethod = {
/** Email link sign in method */
EMAIL_LINK: 'emailLink',
/** Email/password sign in method */
EMAIL_PASSWORD: 'password',
/** Facebook sign in method */
FACEBOOK: 'facebook.com',
/** GitHub sign in method */
GITHUB: 'github.com',
/** Google sign in method */
GOOGLE: 'google.com',
/** Phone sign in method */
PHONE: 'phone',
/** Twitter sign in method */
TWITTER: 'twitter.com'
} as const;

/**
* Enumeration of supported operation types.
*
* @public
*/
export const OperationType = {
/** Operation involving linking an additional provider to an already signed-in user. */
LINK: 'link',
/** Operation involving using a provider to reauthenticate an already signed-in user. */
REAUTHENTICATE: 'reauthenticate',
/** Operation involving signing in a user. */
SIGN_IN: 'signIn'
} as const;

/**
* An enumeration of the possible email action types.
*
* @public
*/
export const ActionCodeOperation = {
/** The email link sign-in action. */
EMAIL_SIGNIN: 'EMAIL_SIGNIN',
/** The password reset action. */
PASSWORD_RESET: 'PASSWORD_RESET',
/** The email revocation action. */
RECOVER_EMAIL: 'RECOVER_EMAIL',
/** The revert second factor addition email action. */
REVERT_SECOND_FACTOR_ADDITION: 'REVERT_SECOND_FACTOR_ADDITION',
/** The revert second factor addition email action. */
VERIFY_AND_CHANGE_EMAIL: 'VERIFY_AND_CHANGE_EMAIL',
/** The email verification action. */
VERIFY_EMAIL: 'VERIFY_EMAIL'
} as const;
Loading