Skip to content

Commit be08d19

Browse files
authored
Remove all public const enums; export maps instead (with typings to strings) (#5022)
* Remove external const enums * Formatting * Small fixes * Fix compat build * PR feedback * PR feedback * Formatting
1 parent 9f28afb commit be08d19

File tree

8 files changed

+177
-70
lines changed

8 files changed

+177
-70
lines changed

common/api-review/auth-exp.api.md

Lines changed: 40 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ export interface ActionCodeInfo {
2020
multiFactorInfo?: MultiFactorInfo | null;
2121
previousEmail?: string | null;
2222
};
23-
operation: ActionCodeOperation;
23+
operation: typeof ActionCodeOperation[keyof typeof ActionCodeOperation];
2424
}
2525

2626
// @public
27-
export const enum ActionCodeOperation {
28-
EMAIL_SIGNIN = "EMAIL_SIGNIN",
29-
PASSWORD_RESET = "PASSWORD_RESET",
30-
RECOVER_EMAIL = "RECOVER_EMAIL",
31-
REVERT_SECOND_FACTOR_ADDITION = "REVERT_SECOND_FACTOR_ADDITION",
32-
VERIFY_AND_CHANGE_EMAIL = "VERIFY_AND_CHANGE_EMAIL",
33-
VERIFY_EMAIL = "VERIFY_EMAIL"
34-
}
27+
export const ActionCodeOperation: {
28+
readonly EMAIL_SIGNIN: "EMAIL_SIGNIN";
29+
readonly PASSWORD_RESET: "PASSWORD_RESET";
30+
readonly RECOVER_EMAIL: "RECOVER_EMAIL";
31+
readonly REVERT_SECOND_FACTOR_ADDITION: "REVERT_SECOND_FACTOR_ADDITION";
32+
readonly VERIFY_AND_CHANGE_EMAIL: "VERIFY_AND_CHANGE_EMAIL";
33+
readonly VERIFY_EMAIL: "VERIFY_EMAIL";
34+
};
3535

3636
// @public
3737
export interface ActionCodeSettings {
@@ -56,7 +56,7 @@ export class ActionCodeURL {
5656
readonly code: string;
5757
readonly continueUrl: string | null;
5858
readonly languageCode: string | null;
59-
readonly operation: ActionCodeOperation;
59+
readonly operation: string;
6060
static parseLink(link: string): ActionCodeURL | null;
6161
readonly tenantId: string | null;
6262
}
@@ -239,9 +239,9 @@ export class FacebookAuthProvider extends BaseOAuthProvider {
239239
}
240240

241241
// @public
242-
export const enum FactorId {
243-
PHONE = "phone"
244-
}
242+
export const FactorId: {
243+
readonly PHONE: "phone";
244+
};
245245

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

325325
// @public
326326
export interface MultiFactorAssertion {
327-
readonly factorId: FactorId;
327+
readonly factorId: typeof FactorId[keyof typeof FactorId];
328328
}
329329

330330
// @public
331331
export interface MultiFactorError extends AuthError {
332-
readonly operationType: OperationType;
332+
readonly operationType: typeof OperationType[keyof typeof OperationType];
333333
}
334334

335335
// @public
336336
export interface MultiFactorInfo {
337337
readonly displayName?: string | null;
338338
readonly enrollmentTime: string;
339-
readonly factorId: FactorId;
339+
readonly factorId: typeof FactorId[keyof typeof FactorId];
340340
readonly uid: string;
341341
}
342342

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

407407
// @public
408-
export const enum OperationType {
409-
LINK = "link",
410-
REAUTHENTICATE = "reauthenticate",
411-
SIGN_IN = "signIn"
412-
}
408+
export const OperationType: {
409+
readonly LINK: "link";
410+
readonly REAUTHENTICATE: "reauthenticate";
411+
readonly SIGN_IN: "signIn";
412+
};
413413

414414
// @public
415415
export function parseActionCodeURL(link: string): ActionCodeURL | null;
@@ -502,20 +502,14 @@ export interface PopupRedirectResolver {
502502
export const prodErrorMap: AuthErrorMap;
503503

504504
// @public
505-
export const enum ProviderId {
506-
// @internal (undocumented)
507-
ANONYMOUS = "anonymous",
508-
// @internal (undocumented)
509-
CUSTOM = "custom",
510-
FACEBOOK = "facebook.com",
511-
// @internal (undocumented)
512-
FIREBASE = "firebase",
513-
GITHUB = "github.com",
514-
GOOGLE = "google.com",
515-
PASSWORD = "password",
516-
PHONE = "phone",
517-
TWITTER = "twitter.com"
518-
}
505+
export const ProviderId: {
506+
readonly FACEBOOK: "facebook.com";
507+
readonly GITHUB: "github.com";
508+
readonly GOOGLE: "google.com";
509+
readonly PASSWORD: "password";
510+
readonly PHONE: "phone";
511+
readonly TWITTER: "twitter.com";
512+
};
519513

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

585579
// @public
586-
export const enum SignInMethod {
587-
// @internal (undocumented)
588-
ANONYMOUS = "anonymous",
589-
EMAIL_LINK = "emailLink",
590-
EMAIL_PASSWORD = "password",
591-
FACEBOOK = "facebook.com",
592-
GITHUB = "github.com",
593-
GOOGLE = "google.com",
594-
PHONE = "phone",
595-
TWITTER = "twitter.com"
596-
}
580+
export const SignInMethod: {
581+
readonly EMAIL_LINK: "emailLink";
582+
readonly EMAIL_PASSWORD: "password";
583+
readonly FACEBOOK: "facebook.com";
584+
readonly GITHUB: "github.com";
585+
readonly GOOGLE: "google.com";
586+
readonly PHONE: "phone";
587+
readonly TWITTER: "twitter.com";
588+
};
597589

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

632624
// @public
633-
export function unlink(user: User, providerId: ProviderId): Promise<User>;
625+
export function unlink(user: User, providerId: string): Promise<User>;
634626

635627
export { Unsubscribe }
636628

@@ -677,7 +669,7 @@ export interface User extends UserInfo {
677669

678670
// @public
679671
export interface UserCredential {
680-
operationType: OperationType;
672+
operationType: typeof OperationType[keyof typeof OperationType];
681673
providerId: string | null;
682674
user: User;
683675
}

packages-exp/auth-compat-exp/src/user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export class User implements compat.User, Compat<exp.User> {
158158
return exp.sendEmailVerification(this._delegate, actionCodeSettings);
159159
}
160160
async unlink(providerId: string): Promise<compat.User> {
161-
await exp.unlink(this._delegate, providerId as exp.ProviderId);
161+
await exp.unlink(this._delegate, providerId);
162162
return this;
163163
}
164164
updateEmail(newEmail: string): Promise<void> {

packages-exp/auth-exp/index.node.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ FetchProvider.initialize(
4141

4242
// Core functionality shared by all clients
4343
export * from './src';
44+
export {
45+
FactorId,
46+
ProviderId,
47+
SignInMethod,
48+
OperationType,
49+
ActionCodeOperation
50+
} from './src/model/enum_maps';
4451

4552
export function getAuth(app: FirebaseApp): Auth {
4653
const provider = _getProvider(app, 'auth-exp');

packages-exp/auth-exp/index.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ import { Auth } from './src/model/public_types';
3333

3434
// Public types
3535
export {
36-
// Enums
37-
ActionCodeOperation,
38-
FactorId,
39-
OperationType,
40-
ProviderId,
41-
SignInMethod,
4236
// Interfaces
4337
ActionCodeInfo,
4438
ActionCodeSettings,
@@ -79,6 +73,15 @@ export {
7973
Unsubscribe
8074
} from './src/model/public_types';
8175

76+
// Helper maps (not used internally)
77+
export {
78+
FactorId,
79+
ProviderId,
80+
SignInMethod,
81+
OperationType,
82+
ActionCodeOperation
83+
} from './src/model/enum_maps';
84+
8285
// Core functionality shared by all clients
8386
export * from './src';
8487

packages-exp/auth-exp/src/core/action_code_url.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class ActionCodeURL {
107107
* The action performed by the email action link. It returns from one of the types from
108108
* {@link ActionCodeInfo}
109109
*/
110-
readonly operation: ActionCodeOperation;
110+
readonly operation: string;
111111
/**
112112
* The tenant ID of the email action link. Null if the email action is from the parent project.
113113
*/

packages-exp/auth-exp/src/core/user/link_unlink.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ import { getModularInstance } from '@firebase/util';
3636
*
3737
* @public
3838
*/
39-
export async function unlink(
40-
user: User,
41-
providerId: ProviderId
42-
): Promise<User> {
39+
export async function unlink(user: User, providerId: string): Promise<User> {
4340
const userInternal = getModularInstance(user) as UserInternal;
4441
await _assertLinkedStatus(true, userInternal, providerId);
4542
const { providerUserInfo } = await deleteLinkedAccounts(userInternal.auth, {
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**
2+
* @license
3+
* Copyright 2021 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/**
19+
* An enum of factors that may be used for multifactor authentication.
20+
*
21+
* @public
22+
*/
23+
export const FactorId = {
24+
/** Phone as second factor */
25+
PHONE: 'phone'
26+
} as const;
27+
28+
/**
29+
* Enumeration of supported providers.
30+
*
31+
* @public
32+
*/
33+
export const ProviderId = {
34+
/** Facebook provider ID */
35+
FACEBOOK: 'facebook.com',
36+
/** GitHub provider ID */
37+
GITHUB: 'github.com',
38+
/** Google provider ID */
39+
GOOGLE: 'google.com',
40+
/** Password provider */
41+
PASSWORD: 'password',
42+
/** Phone provider */
43+
PHONE: 'phone',
44+
/** Twitter provider ID */
45+
TWITTER: 'twitter.com'
46+
} as const;
47+
48+
/**
49+
* Enumeration of supported sign-in methods.
50+
*
51+
* @public
52+
*/
53+
export const SignInMethod = {
54+
/** Email link sign in method */
55+
EMAIL_LINK: 'emailLink',
56+
/** Email/password sign in method */
57+
EMAIL_PASSWORD: 'password',
58+
/** Facebook sign in method */
59+
FACEBOOK: 'facebook.com',
60+
/** GitHub sign in method */
61+
GITHUB: 'github.com',
62+
/** Google sign in method */
63+
GOOGLE: 'google.com',
64+
/** Phone sign in method */
65+
PHONE: 'phone',
66+
/** Twitter sign in method */
67+
TWITTER: 'twitter.com'
68+
} as const;
69+
70+
/**
71+
* Enumeration of supported operation types.
72+
*
73+
* @public
74+
*/
75+
export const OperationType = {
76+
/** Operation involving linking an additional provider to an already signed-in user. */
77+
LINK: 'link',
78+
/** Operation involving using a provider to reauthenticate an already signed-in user. */
79+
REAUTHENTICATE: 'reauthenticate',
80+
/** Operation involving signing in a user. */
81+
SIGN_IN: 'signIn'
82+
} as const;
83+
84+
/**
85+
* An enumeration of the possible email action types.
86+
*
87+
* @public
88+
*/
89+
export const ActionCodeOperation = {
90+
/** The email link sign-in action. */
91+
EMAIL_SIGNIN: 'EMAIL_SIGNIN',
92+
/** The password reset action. */
93+
PASSWORD_RESET: 'PASSWORD_RESET',
94+
/** The email revocation action. */
95+
RECOVER_EMAIL: 'RECOVER_EMAIL',
96+
/** The revert second factor addition email action. */
97+
REVERT_SECOND_FACTOR_ADDITION: 'REVERT_SECOND_FACTOR_ADDITION',
98+
/** The revert second factor addition email action. */
99+
VERIFY_AND_CHANGE_EMAIL: 'VERIFY_AND_CHANGE_EMAIL',
100+
/** The email verification action. */
101+
VERIFY_EMAIL: 'VERIFY_EMAIL'
102+
} as const;

0 commit comments

Comments
 (0)