Skip to content

Commit e50a5a8

Browse files
committed
refactor(mosaic): name reverification message keys in plain camelCase
Adds a test that every message key segment is camelCase, with id-keyed maps exempt, and drops reverification keys no view reads.
1 parent 3f703c6 commit e50a5a8

5 files changed

Lines changed: 121 additions & 95 deletions

File tree

‎packages/mosaic/src/features/reverification/__tests__/reverification.feature.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1748,7 +1748,7 @@ describe('Reverification', () => {
17481748
guardedAction(),
17491749
verificationSeed({ firstFactors: [passwordFactor] }),
17501750
{
1751-
messages: { 'reverification.unstable__errors__generic': 'Something custom went wrong' },
1751+
messages: { 'reverification.attemptFailed': 'Something custom went wrong' },
17521752
},
17531753
);
17541754
const user = await startVerification();

‎packages/mosaic/src/features/reverification/reverification.controller.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ function useReverificationState(model: ReverificationModel): ReverificationContr
502502
direction: context.direction,
503503
value: context.inputValue,
504504
onValueChange: (value: string) => send({ type: 'TYPE', value }),
505-
errorMessage: context.error ? errorText(context.error, m.unstable__errors__generic) : undefined,
505+
errorMessage: context.error ? errorText(context.error, m.attemptFailed) : undefined,
506506
isPending: pendingStates.has(state),
507507
onSubmit: () => send({ type: 'SUBMIT' }),
508508
onShowMethods: () => send({ type: 'SHOW_METHODS' }),
Lines changed: 50 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,79 @@
11
export const reverificationMessages = {
2-
alternativeMethods: {
3-
actionLink: 'Get help',
4-
actionText: 'Don’t have any of these?',
5-
blockButton__backupCode: 'Use a backup code',
6-
blockButton__emailCode: 'Email code to {identifier}',
7-
blockButton__passkey: 'Use your passkey',
8-
blockButton__password: 'Continue with your password',
9-
blockButton__phoneCode: 'Send SMS code to {identifier}',
10-
blockButton__totp: 'Use your authenticator app',
11-
getHelp: {
12-
blockButton__emailSupport: 'Email support',
13-
description:
14-
'If you have trouble verifying your account, email us and we will work with you to restore access as soon as possible.',
15-
title: 'Get help',
16-
},
17-
description: 'Facing issues? You can use any of these methods for verification.',
18-
title: 'Use another method',
19-
},
20-
backupCodeMfa: {
21-
description: 'Enter the backup code you received when setting up two-step authentication',
22-
title: 'Enter a backup code',
23-
},
242
loading: {
253
title: 'Verification required',
264
},
27-
emailCode: {
28-
description: 'Enter the code sent to your email to continue',
29-
formTitle: 'Verification code',
30-
resendButton: 'Resend',
31-
resendCountdown: 'Resend ({seconds})',
32-
resendText: 'Didn’t receive a code?',
5+
password: {
336
title: 'Verification required',
7+
description: 'Enter your current password to continue',
8+
label: 'Password',
9+
placeholder: 'Enter your password',
10+
showPassword: 'Show password',
11+
hidePassword: 'Hide password',
3412
},
3513
passkey: {
36-
blockButton__passkey: 'Use your passkey',
14+
title: 'Use your passkey',
3715
description:
3816
'Using your passkey confirms your identity. Your device may ask for your fingerprint, face, or screen lock.',
39-
title: 'Use your passkey',
4017
},
41-
password: {
42-
actionLink: 'Use another method',
43-
description: 'Enter your current password to continue',
18+
emailCode: {
4419
title: 'Verification required',
20+
description: 'Enter the code sent to your email to continue',
21+
label: 'Verification code',
22+
resendText: 'Didn’t receive a code?',
23+
resend: 'Resend',
24+
resendCountdown: 'Resend ({seconds})',
4525
},
4626
phoneCode: {
47-
description: 'Enter the code sent to your phone to continue',
48-
formTitle: 'Verification code',
49-
resendButton: 'Resend',
50-
resendCountdown: 'Resend ({seconds})',
51-
resendText: 'Didn’t receive a code?',
5227
title: 'Verification required',
53-
},
54-
phoneCodeMfa: {
5528
description: 'Enter the code sent to your phone to continue',
56-
formTitle: 'Verification code',
57-
resendButton: 'Resend',
58-
resendCountdown: 'Resend ({seconds})',
29+
label: 'Verification code',
5930
resendText: 'Didn’t receive a code?',
31+
resend: 'Resend',
32+
resendCountdown: 'Resend ({seconds})',
33+
},
34+
totp: {
6035
title: 'Verification required',
36+
description: 'Enter the code generated by your authenticator app to continue',
37+
label: 'Verification code',
38+
},
39+
backupCode: {
40+
title: 'Enter a backup code',
41+
description: 'Enter the backup code you received when setting up two-step authentication',
42+
label: 'Backup code',
43+
},
44+
methods: {
45+
title: 'Use another method',
46+
description: 'Facing issues? You can use any of these methods for verification.',
47+
password: 'Continue with your password',
48+
passkey: 'Use your passkey',
49+
emailCode: 'Email code to {identifier}',
50+
phoneCode: 'Send SMS code to {identifier}',
51+
totp: 'Use your authenticator app',
52+
backupCode: 'Use a backup code',
53+
helpText: 'Don’t have any of these?',
54+
help: 'Get help',
55+
},
56+
help: {
57+
title: 'Get help',
58+
description:
59+
'If you have trouble verifying your account, email us and we will work with you to restore access as soon as possible.',
60+
emailSupport: 'Email support',
6161
},
6262
error: {
63-
closeButton: 'Close',
63+
close: 'Close',
6464
generic: {
65-
description: 'Please try again.',
6665
title: 'Something went wrong',
66+
description: 'Please try again.',
6767
},
6868
noFactors: {
69-
description: 'Cannot proceed with verification. No suitable authentication factor is configured.',
7069
title: 'Cannot verify your account',
70+
description: 'Cannot proceed with verification. No suitable authentication factor is configured.',
7171
},
7272
},
73-
totpMfa: {
74-
description: 'Enter the code generated by your authenticator app to continue',
75-
formTitle: 'Verification code',
76-
title: 'Verification required',
77-
},
78-
backButton: 'Back',
79-
footerActionLink__useAnotherMethod: 'Use another method',
80-
formButtonPrimary: 'Continue',
81-
formButtonReset: 'Cancel',
82-
formFieldAction__hidePassword: 'Hide password',
83-
formFieldAction__showPassword: 'Show password',
84-
formFieldInputPlaceholder__password: 'Enter your password',
85-
formFieldLabel__backupCode: 'Backup code',
86-
formFieldLabel__password: 'Password',
87-
identityPreviewEditButton__emailAddress: 'Edit email address',
88-
identityPreviewEditButton__identifier: 'Edit identifier',
89-
identityPreviewEditButton__phoneNumber: 'Edit phone number',
90-
unstable__errors__generic: 'Something went wrong. Please try again.',
73+
continue: 'Continue',
74+
useAnotherMethod: 'Use another method',
75+
back: 'Back',
76+
attemptFailed: 'Something went wrong. Please try again.',
9177
/** Announced while an attempt is in flight; the button's own label stays visible. */
9278
verifying: 'Verifying',
9379
} as const;

‎packages/mosaic/src/features/reverification/reverification.view.tsx‎

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ function methodLabel(method: ReverificationMethod, m: Messages): string {
4242
const identifier = 'identifier' in method ? method.identifier : '';
4343
switch (method.strategy) {
4444
case 'password':
45-
return m.alternativeMethods.blockButton__password;
45+
return m.methods.password;
4646
case 'passkey':
47-
return m.alternativeMethods.blockButton__passkey;
47+
return m.methods.passkey;
4848
case 'email_code':
49-
return fill(m.alternativeMethods.blockButton__emailCode, { identifier });
49+
return fill(m.methods.emailCode, { identifier });
5050
case 'phone_code':
51-
return fill(m.alternativeMethods.blockButton__phoneCode, { identifier });
51+
return fill(m.methods.phoneCode, { identifier });
5252
case 'totp':
53-
return m.alternativeMethods.blockButton__totp;
53+
return m.methods.totp;
5454
case 'backup_code':
55-
return m.alternativeMethods.blockButton__backupCode;
55+
return m.methods.backupCode;
5656
}
5757
}
5858

@@ -76,7 +76,7 @@ export function ReverificationError({ reason, onClose }: { reason: Reverificatio
7676
fullWidth
7777
onClick={onClose}
7878
>
79-
{m.error.closeButton}
79+
{m.error.close}
8080
</Button>
8181
</Card.Footer>
8282
) : null}
@@ -105,7 +105,7 @@ export function ReverificationPending() {
105105
disabled
106106
xstyle={styles.pendingAction}
107107
>
108-
{m.formButtonPrimary}
108+
{m.continue}
109109
</Button>
110110
</Card.Footer>
111111
</>
@@ -119,7 +119,7 @@ function otpCopy(channel: ReverificationOtpChannel | undefined, m: Messages) {
119119
if (channel === 'phone') {
120120
return m.phoneCode;
121121
}
122-
return m.totpMfa;
122+
return m.totp;
123123
}
124124

125125
export function ReverificationView({
@@ -147,8 +147,8 @@ export function ReverificationView({
147147

148148
const otp = otpCopy(otpChannel, m);
149149
const actions = {
150-
secondaryActionLabel: m.footerActionLink__useAnotherMethod,
151-
primaryActionLabel: m.formButtonPrimary,
150+
secondaryActionLabel: m.useAnotherMethod,
151+
primaryActionLabel: m.continue,
152152
pendingLabel: m.verifying,
153153
};
154154
const hasAlternatives = methods.length > 0;
@@ -166,7 +166,7 @@ export function ReverificationView({
166166
})}
167167
</span>
168168
) : (
169-
resendCopy.resendButton
169+
resendCopy.resend
170170
),
171171
disabled: !canResend || isPending,
172172
onClick: onResend,
@@ -187,10 +187,10 @@ export function ReverificationView({
187187
messages={{
188188
title: m.password.title,
189189
description: m.password.description,
190-
fieldLabel: m.formFieldLabel__password,
191-
fieldPlaceholder: m.formFieldInputPlaceholder__password,
192-
showPasswordLabel: m.formFieldAction__showPassword,
193-
hidePasswordLabel: m.formFieldAction__hidePassword,
190+
fieldLabel: m.password.label,
191+
fieldPlaceholder: m.password.placeholder,
192+
showPasswordLabel: m.password.showPassword,
193+
hidePasswordLabel: m.password.hidePassword,
194194
...actions,
195195
}}
196196
value={value}
@@ -223,7 +223,7 @@ export function ReverificationView({
223223
messages={{
224224
title: otp.title,
225225
description: otp.description,
226-
fieldLabel: otp.formTitle,
226+
fieldLabel: otp.label,
227227
...actions,
228228
}}
229229
value={value}
@@ -244,9 +244,9 @@ export function ReverificationView({
244244
<ReverificationBackupCode
245245
focusRef={focusRef}
246246
messages={{
247-
title: m.backupCodeMfa.title,
248-
description: m.backupCodeMfa.description,
249-
fieldLabel: m.formFieldLabel__backupCode,
247+
title: m.backupCode.title,
248+
description: m.backupCode.description,
249+
fieldLabel: m.backupCode.label,
250250
...actions,
251251
}}
252252
value={value}
@@ -262,11 +262,11 @@ export function ReverificationView({
262262
<ReverificationMethodPicker
263263
focusRef={focusRef}
264264
messages={{
265-
title: m.alternativeMethods.title,
266-
description: m.alternativeMethods.description,
267-
backButton: m.backButton,
268-
helpText: m.alternativeMethods.actionText,
269-
helpButton: m.alternativeMethods.actionLink,
265+
title: m.methods.title,
266+
description: m.methods.description,
267+
backButton: m.back,
268+
helpText: m.methods.helpText,
269+
helpButton: m.methods.help,
270270
}}
271271
methods={methods.map(method => ({
272272
id: method.id,
@@ -283,10 +283,10 @@ export function ReverificationView({
283283
<Flow.Step ids={['help']}>
284284
<ReverificationHelp
285285
messages={{
286-
title: m.alternativeMethods.getHelp.title,
287-
description: m.alternativeMethods.getHelp.description,
288-
backButton: m.backButton,
289-
supportButton: m.alternativeMethods.getHelp.blockButton__emailSupport,
286+
title: m.help.title,
287+
description: m.help.description,
288+
backButton: m.back,
289+
supportButton: m.help.emailSupport,
290290
}}
291291
onEmailSupport={onEmailSupport}
292292
onBack={onBack}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { describe, expect, it } from 'vitest';
2+
3+
import { mosaicMessages } from '../registry';
4+
5+
const CAMEL_CASE = /^[a-z][a-zA-Z0-9]*$/;
6+
const ID_KEYED_MAPS = [
7+
'errors',
8+
'roles',
9+
'userProfile.mfa.methods',
10+
'userProfile.mfa.addDialog.methods',
11+
'apiKeys.expirationOptions',
12+
];
13+
14+
describe('mosaicMessages', () => {
15+
it('names every key segment in camelCase', () => {
16+
const malformed = keyPaths(mosaicMessages).filter(path => {
17+
const named = namedSegments(path);
18+
return path.length < 2 || named.some(segment => !CAMEL_CASE.test(segment));
19+
});
20+
21+
expect(malformed.map(path => path.join('.'))).toEqual([]);
22+
});
23+
});
24+
25+
function namedSegments(path: string[]): string[] {
26+
const joined = path.join('.');
27+
const map = ID_KEYED_MAPS.find(prefix => joined.startsWith(`${prefix}.`));
28+
return map === undefined ? path : map.split('.');
29+
}
30+
31+
function keyPaths(value: unknown, prefix: string[] = []): string[][] {
32+
if (typeof value !== 'object' || value === null || isPluralForms(value)) {
33+
return [prefix];
34+
}
35+
return Object.entries(value).flatMap(([key, child]) => keyPaths(child, [...prefix, key]));
36+
}
37+
38+
function isPluralForms(value: object): boolean {
39+
return 'other' in value && typeof Reflect.get(value, 'other') === 'string';
40+
}

0 commit comments

Comments
 (0)