From 1f7efd36806e2d5c33684a90cf2fa9516de91d7c Mon Sep 17 00:00:00 2001 From: Darcy Ye Date: Wed, 28 Dec 2022 10:29:28 +0800 Subject: [PATCH] chore(phrases,core): change 'passcode' to 'verification code' in content (#2740) --- packages/core/src/libraries/passcode.test.ts | 14 +++++++------- packages/core/src/libraries/passcode.ts | 14 +++++++------- .../src/routes/session/forgot-password.test.ts | 2 +- .../src/routes/session/passwordless.test.ts | 2 +- packages/phrases/src/locales/de/errors.ts | 18 +++++++++--------- packages/phrases/src/locales/en/errors.ts | 15 ++++++++------- packages/phrases/src/locales/fr/errors.ts | 16 ++++++++-------- packages/phrases/src/locales/ko/errors.ts | 17 +++++++++-------- packages/phrases/src/locales/pt-br/errors.ts | 17 +++++++++-------- packages/phrases/src/locales/pt-pt/errors.ts | 16 ++++++++-------- packages/phrases/src/locales/tr-tr/errors.ts | 17 +++++++++-------- packages/phrases/src/locales/zh-cn/errors.ts | 2 +- .../use-shared-error-handler.ts | 4 ++-- 13 files changed, 79 insertions(+), 75 deletions(-) diff --git a/packages/core/src/libraries/passcode.test.ts b/packages/core/src/libraries/passcode.test.ts index 46262cc8a..2f3e27ae2 100644 --- a/packages/core/src/libraries/passcode.test.ts +++ b/packages/core/src/libraries/passcode.test.ts @@ -113,7 +113,7 @@ describe('sendPasscode', () => { createdAt: Date.now(), }; await expect(sendPasscode(passcode)).rejects.toThrowError( - new RequestError('passcode.phone_email_empty') + new RequestError('verification_code.phone_email_empty') ); }); @@ -230,7 +230,7 @@ describe('verifyPasscode', () => { findUnconsumedPasscodeByJtiAndType.mockResolvedValue(null); await expect( verifyPasscode(passcode.interactionJti, passcode.type, passcode.code, { phone: 'phone' }) - ).rejects.toThrow(new RequestError('passcode.not_found')); + ).rejects.toThrow(new RequestError('verification_code.not_found')); }); it('should fail when phone mismatch', async () => { @@ -239,7 +239,7 @@ describe('verifyPasscode', () => { verifyPasscode(passcode.interactionJti, passcode.type, passcode.code, { phone: 'invalid_phone', }) - ).rejects.toThrow(new RequestError('passcode.phone_mismatch')); + ).rejects.toThrow(new RequestError('verification_code.phone_mismatch')); }); it('should fail when email mismatch', async () => { @@ -252,7 +252,7 @@ describe('verifyPasscode', () => { verifyPasscode(passcode.interactionJti, passcode.type, passcode.code, { email: 'invalid_email', }) - ).rejects.toThrow(new RequestError('passcode.email_mismatch')); + ).rejects.toThrow(new RequestError('verification_code.email_mismatch')); }); it('should fail when expired', async () => { @@ -262,7 +262,7 @@ describe('verifyPasscode', () => { }); await expect( verifyPasscode(passcode.interactionJti, passcode.type, passcode.code, { phone: 'phone' }) - ).rejects.toThrow(new RequestError('passcode.expired')); + ).rejects.toThrow(new RequestError('verification_code.expired')); }); it('should fail when exceed max count', async () => { @@ -272,14 +272,14 @@ describe('verifyPasscode', () => { }); await expect( verifyPasscode(passcode.interactionJti, passcode.type, passcode.code, { phone: 'phone' }) - ).rejects.toThrow(new RequestError('passcode.exceed_max_try')); + ).rejects.toThrow(new RequestError('verification_code.exceed_max_try')); }); it('should fail when invalid code, and should increase try_count', async () => { findUnconsumedPasscodeByJtiAndType.mockResolvedValue(passcode); await expect( verifyPasscode(passcode.interactionJti, passcode.type, 'invalid', { phone: 'phone' }) - ).rejects.toThrow(new RequestError('passcode.code_mismatch')); + ).rejects.toThrow(new RequestError('verification_code.code_mismatch')); expect(increasePasscodeTryCount).toHaveBeenCalledWith(passcode.id); }); }); diff --git a/packages/core/src/libraries/passcode.ts b/packages/core/src/libraries/passcode.ts index 5e8f99ef3..dc4ca8c2d 100644 --- a/packages/core/src/libraries/passcode.ts +++ b/packages/core/src/libraries/passcode.ts @@ -45,7 +45,7 @@ export const sendPasscode = async (passcode: Passcode) => { const emailOrPhone = passcode.email ?? passcode.phone; if (!emailOrPhone) { - throw new RequestError('passcode.phone_email_empty'); + throw new RequestError('verification_code.phone_email_empty'); } const expectType = passcode.phone ? ConnectorType.Sms : ConnectorType.Email; @@ -95,28 +95,28 @@ export const verifyPasscode = async ( const passcode = await findUnconsumedPasscodeByJtiAndType(sessionId, type); if (!passcode) { - throw new RequestError('passcode.not_found'); + throw new RequestError('verification_code.not_found'); } if ('phone' in payload && passcode.phone !== payload.phone) { - throw new RequestError('passcode.phone_mismatch'); + throw new RequestError('verification_code.phone_mismatch'); } if ('email' in payload && passcode.email !== payload.email) { - throw new RequestError('passcode.email_mismatch'); + throw new RequestError('verification_code.email_mismatch'); } if (passcode.createdAt + passcodeExpiration < Date.now()) { - throw new RequestError('passcode.expired'); + throw new RequestError('verification_code.expired'); } if (passcode.tryCount >= passcodeMaxTryCount) { - throw new RequestError('passcode.exceed_max_try'); + throw new RequestError('verification_code.exceed_max_try'); } if (code !== passcode.code) { await increasePasscodeTryCount(passcode.id); - throw new RequestError('passcode.code_mismatch'); + throw new RequestError('verification_code.code_mismatch'); } await consumePasscode(passcode.id); diff --git a/packages/core/src/routes/session/forgot-password.test.ts b/packages/core/src/routes/session/forgot-password.test.ts index 4d416743c..7cc2a843d 100644 --- a/packages/core/src/routes/session/forgot-password.test.ts +++ b/packages/core/src/routes/session/forgot-password.test.ts @@ -48,7 +48,7 @@ jest.mock('#src/libraries/passcode.js', () => ({ sendPasscode: async () => sendPasscode(), verifyPasscode: async (_a: unknown, _b: unknown, code: string) => { if (code !== '1234') { - throw new RequestError('passcode.code_mismatch'); + throw new RequestError('verification_code.code_mismatch'); } }, })); diff --git a/packages/core/src/routes/session/passwordless.test.ts b/packages/core/src/routes/session/passwordless.test.ts index aa79b8ec7..1f0710abb 100644 --- a/packages/core/src/routes/session/passwordless.test.ts +++ b/packages/core/src/routes/session/passwordless.test.ts @@ -65,7 +65,7 @@ jest.mock('#src/libraries/passcode.js', () => ({ sendPasscode: async () => sendPasscode(), verifyPasscode: async (_a: unknown, _b: unknown, code: string) => { if (code !== '1234') { - throw new RequestError('passcode.code_mismatch'); + throw new RequestError('verification_code.code_mismatch'); } }, })); diff --git a/packages/phrases/src/locales/de/errors.ts b/packages/phrases/src/locales/de/errors.ts index 33969db08..2ccf0a686 100644 --- a/packages/phrases/src/locales/de/errors.ts +++ b/packages/phrases/src/locales/de/errors.ts @@ -125,15 +125,15 @@ const errors = { cannot_overwrite_metadata_for_non_standard_connector: "This connector's 'metadata' cannot be overwritten.", }, - passcode: { - phone_email_empty: 'Telefonnummer oder E-Mail darf nicht leer sein.', - not_found: 'Passcode nicht gefunden. Bitte sende erst einen Passcode.', - phone_mismatch: - 'Telefonnummer stimmt nicht mit Passcode überein. Frage einen neuen Passcode an.', - email_mismatch: 'E-Mail stimmt nicht mit Passcode überein. Frage einen neuen Passcode an.', - code_mismatch: 'Ungültiger Passcode.', - expired: 'Passcode ist abgelaufen. Frage einen neuen Passcode an.', - exceed_max_try: 'Passcode wurde zu oft versucht. Frage einen neuen Passcode an.', + verification_code: { + phone_email_empty: 'Both phone and email are empty.', // UNTRANSLATED + not_found: 'Verification code not found. Please send verification code first.', // UNTRANSLATED + phone_mismatch: 'Phone mismatch. Please request a new verification code.', // UNTRANSLATED + email_mismatch: 'Email mismatch. Please request a new verification code.', // UNTRANSLATED + code_mismatch: 'Invalid verification code.', // UNTRANSLATED + expired: 'Verification code has expired. Please request a new verification code.', // UNTRANSLATED + exceed_max_try: + 'Verification code retries limitation exceeded. Please request a new verification code.', // UNTRANSLATED }, sign_in_experiences: { empty_content_url_of_terms_of_use: diff --git a/packages/phrases/src/locales/en/errors.ts b/packages/phrases/src/locales/en/errors.ts index 8067df94c..904ddc169 100644 --- a/packages/phrases/src/locales/en/errors.ts +++ b/packages/phrases/src/locales/en/errors.ts @@ -124,14 +124,15 @@ const errors = { cannot_overwrite_metadata_for_non_standard_connector: "This connector's 'metadata' cannot be overwritten.", }, - passcode: { + verification_code: { phone_email_empty: 'Both phone and email are empty.', - not_found: 'Passcode not found. Please send passcode first.', - phone_mismatch: 'Phone mismatch. Please request a new passcode.', - email_mismatch: 'Email mismatch. Please request a new passcode.', - code_mismatch: 'Invalid passcode.', - expired: 'Passcode has expired. Please request a new passcode.', - exceed_max_try: 'Passcode verification limitation exceeded. Please request a new passcode.', + not_found: 'Verification code not found. Please send verification code first.', + phone_mismatch: 'Phone mismatch. Please request a new verification code.', + email_mismatch: 'Email mismatch. Please request a new verification code.', + code_mismatch: 'Invalid verification code.', + expired: 'Verification code has expired. Please request a new verification code.', + exceed_max_try: + 'Verification code retries limitation exceeded. Please request a new verification code.', }, sign_in_experiences: { empty_content_url_of_terms_of_use: diff --git a/packages/phrases/src/locales/fr/errors.ts b/packages/phrases/src/locales/fr/errors.ts index ce7df60e3..2072820cd 100644 --- a/packages/phrases/src/locales/fr/errors.ts +++ b/packages/phrases/src/locales/fr/errors.ts @@ -131,15 +131,15 @@ const errors = { cannot_overwrite_metadata_for_non_standard_connector: "This connector's 'metadata' cannot be overwritten.", // UNTRANSLATED }, - passcode: { - phone_email_empty: "Le téléphone et l'email sont vides.", - not_found: "Le code d'accès n'a pas été trouvé. Veuillez envoyer le code d'accès en premier.", - phone_mismatch: "Le téléphone ne correspond pas. Veuillez demander un nouveau code d'accès.", - email_mismatch: "Erreur d'email. Veuillez demander un nouveau code d'accès.", - code_mismatch: "Code d'accès invalide.", - expired: "Le code d'accès a expiré. Veuillez demander un nouveau code d'accès.", + verification_code: { + phone_email_empty: 'Both phone and email are empty.', // UNTRANSLATED + not_found: 'Verification code not found. Please send verification code first.', // UNTRANSLATED + phone_mismatch: 'Phone mismatch. Please request a new verification code.', // UNTRANSLATED + email_mismatch: 'Email mismatch. Please request a new verification code.', // UNTRANSLATED + code_mismatch: 'Invalid verification code.', // UNTRANSLATED + expired: 'Verification code has expired. Please request a new verification code.', // UNTRANSLATED exceed_max_try: - "La limite de vérification du code d'accès est dépassée. Veuillez demander un nouveau code d'accès.", + 'Verification code retries limitation exceeded. Please request a new verification code.', // UNTRANSLATED }, sign_in_experiences: { empty_content_url_of_terms_of_use: diff --git a/packages/phrases/src/locales/ko/errors.ts b/packages/phrases/src/locales/ko/errors.ts index 8f75d2960..8d59f3a26 100644 --- a/packages/phrases/src/locales/ko/errors.ts +++ b/packages/phrases/src/locales/ko/errors.ts @@ -118,14 +118,15 @@ const errors = { cannot_overwrite_metadata_for_non_standard_connector: '이 연동의 메타데이터를 덮어쓸 수 없어요.', }, - passcode: { - phone_email_empty: '휴대전화번호 그리고 이메일이 비어있어요.', - not_found: '비밀번호를 찾을 수 없어요. 비밀번호를 먼저 보내주세요.', - phone_mismatch: '휴대전화번호가 일치하지 않아요. 새로운 비밀번호를 요청해주세요.', - email_mismatch: '이메일이 일치하지 않아요. 새로운 비밀번호를 요청해주세요.', - code_mismatch: '비밀번호가 유효하지 않아요.', - expired: '비밀번호가 만료되었어요. 새로운 비밀번호를 요청해주세요.', - exceed_max_try: '해당 비밀번호는 인증 횟수를 초과하였어요. 새로운 비밀번호를 요청해주세요.', + verification_code: { + phone_email_empty: 'Both phone and email are empty.', // UNTRANSLATED + not_found: 'Verification code not found. Please send verification code first.', // UNTRANSLATED + phone_mismatch: 'Phone mismatch. Please request a new verification code.', // UNTRANSLATED + email_mismatch: 'Email mismatch. Please request a new verification code.', // UNTRANSLATED + code_mismatch: 'Invalid verification code.', // UNTRANSLATED + expired: 'Verification code has expired. Please request a new verification code.', // UNTRANSLATED + exceed_max_try: + 'Verification code retries limitation exceeded. Please request a new verification code.', // UNTRANSLATED }, sign_in_experiences: { empty_content_url_of_terms_of_use: diff --git a/packages/phrases/src/locales/pt-br/errors.ts b/packages/phrases/src/locales/pt-br/errors.ts index e22105524..e84922fab 100644 --- a/packages/phrases/src/locales/pt-br/errors.ts +++ b/packages/phrases/src/locales/pt-br/errors.ts @@ -128,14 +128,15 @@ const errors = { cannot_overwrite_metadata_for_non_standard_connector: "This connector's 'metadata' cannot be overwritten.", // UNTRANSLATED }, - passcode: { - phone_email_empty: 'Telefone e e-mail estão vazios.', - not_found: 'Senha não encontrada. Por favor, envie a senha primeiro.', - phone_mismatch: 'Incompatibilidade de telefone. Solicite uma nova senha.', - email_mismatch: 'Incompatibilidade de e-mail. Solicite uma nova senha.', - code_mismatch: 'Senha inválida.', - expired: 'A senha expirou. Solicite uma nova senha.', - exceed_max_try: 'Limite de verificação de senha excedida. Solicite uma nova senha.', + verification_code: { + phone_email_empty: 'Both phone and email are empty.', // UNTRANSLATED + not_found: 'Verification code not found. Please send verification code first.', // UNTRANSLATED + phone_mismatch: 'Phone mismatch. Please request a new verification code.', // UNTRANSLATED + email_mismatch: 'Email mismatch. Please request a new verification code.', // UNTRANSLATED + code_mismatch: 'Invalid verification code.', // UNTRANSLATED + expired: 'Verification code has expired. Please request a new verification code.', // UNTRANSLATED + exceed_max_try: + 'Verification code retries limitation exceeded. Please request a new verification code.', // UNTRANSLATED }, sign_in_experiences: { empty_content_url_of_terms_of_use: diff --git a/packages/phrases/src/locales/pt-pt/errors.ts b/packages/phrases/src/locales/pt-pt/errors.ts index 1ed612f54..4fe262255 100644 --- a/packages/phrases/src/locales/pt-pt/errors.ts +++ b/packages/phrases/src/locales/pt-pt/errors.ts @@ -126,15 +126,15 @@ const errors = { cannot_overwrite_metadata_for_non_standard_connector: "This connector's 'metadata' cannot be overwritten.", // UNTRANSLATED }, - passcode: { - phone_email_empty: 'O campos telefone e email estão vazios.', - not_found: 'Senha não encontrada. Por favor, envie a senha primeiro.', - phone_mismatch: 'O telefone não correspond. Por favor, solicite uma nova senha.', - email_mismatch: 'O email não corresponde. Por favor, solicite uma nova senha.', - code_mismatch: 'Senha inválida.', - expired: 'A senha expirou. Por favor, solicite uma nova senha.', + verification_code: { + phone_email_empty: 'Both phone and email are empty.', // UNTRANSLATED + not_found: 'Verification code not found. Please send verification code first.', // UNTRANSLATED + phone_mismatch: 'Phone mismatch. Please request a new verification code.', // UNTRANSLATED + email_mismatch: 'Email mismatch. Please request a new verification code.', // UNTRANSLATED + code_mismatch: 'Invalid verification code.', // UNTRANSLATED + expired: 'Verification code has expired. Please request a new verification code.', // UNTRANSLATED exceed_max_try: - 'Limitação de verificação de senha excedida. Por favor, solicite uma nova senha.', + 'Verification code retries limitation exceeded. Please request a new verification code.', // UNTRANSLATED }, sign_in_experiences: { empty_content_url_of_terms_of_use: diff --git a/packages/phrases/src/locales/tr-tr/errors.ts b/packages/phrases/src/locales/tr-tr/errors.ts index 2a470db10..8c2740ee2 100644 --- a/packages/phrases/src/locales/tr-tr/errors.ts +++ b/packages/phrases/src/locales/tr-tr/errors.ts @@ -125,14 +125,15 @@ const errors = { cannot_overwrite_metadata_for_non_standard_connector: "This connector's 'metadata' cannot be overwritten.", // UNTRANSLATED }, - passcode: { - phone_email_empty: 'Hem telefon hem de e-posta adresi yok.', - not_found: 'Kod bulunamadı. Lütfen önce kodu gönderiniz.', - phone_mismatch: 'Telefon numarası eşleşmedi. Lütfen yeni bir kod isteyiniz.', - email_mismatch: 'E-posta adresi eşleşmedi. Lütfen yeni bir kod isteyiniz.', - code_mismatch: 'Geçersiz kod.', - expired: 'Kodun Süresi doldu. Lütfen yeni bir kod isteyiniz.', - exceed_max_try: 'Kod doğrulama sınırı aşıldı. Lütfen yeni bir kod isteyiniz.', + verification_code: { + phone_email_empty: 'Both phone and email are empty.', // UNTRANSLATED + not_found: 'Verification code not found. Please send verification code first.', // UNTRANSLATED + phone_mismatch: 'Phone mismatch. Please request a new verification code.', // UNTRANSLATED + email_mismatch: 'Email mismatch. Please request a new verification code.', // UNTRANSLATED + code_mismatch: 'Invalid verification code.', // UNTRANSLATED + expired: 'Verification code has expired. Please request a new verification code.', // UNTRANSLATED + exceed_max_try: + 'Verification code retries limitation exceeded. Please request a new verification code.', // UNTRANSLATED }, sign_in_experiences: { empty_content_url_of_terms_of_use: diff --git a/packages/phrases/src/locales/zh-cn/errors.ts b/packages/phrases/src/locales/zh-cn/errors.ts index 425860939..ca835aefa 100644 --- a/packages/phrases/src/locales/zh-cn/errors.ts +++ b/packages/phrases/src/locales/zh-cn/errors.ts @@ -114,7 +114,7 @@ const errors = { multiple_target_with_same_platform: '不能同时存在多个有相同 target 和平台类型的社交连接器。', cannot_overwrite_metadata_for_non_standard_connector: '不可覆盖该连接器的 metadata 参数。', }, - passcode: { + verification_code: { phone_email_empty: '手机号与邮箱地址均为空', not_found: '验证码不存在,请先请求发送验证码', phone_mismatch: '手机号码不匹配,请尝试请求新的验证码。', diff --git a/packages/ui/src/containers/PasscodeValidation/use-shared-error-handler.ts b/packages/ui/src/containers/PasscodeValidation/use-shared-error-handler.ts index 5dbff3bfb..71f87f946 100644 --- a/packages/ui/src/containers/PasscodeValidation/use-shared-error-handler.ts +++ b/packages/ui/src/containers/PasscodeValidation/use-shared-error-handler.ts @@ -8,10 +8,10 @@ const useSharedErrorHandler = () => { // Have to wrap up in a useMemo hook otherwise the handler updates on every cycle const sharedErrorHandlers: ErrorHandlers = useMemo( () => ({ - 'passcode.expired': (error) => { + 'verification_code.expired': (error) => { setErrorMessage(error.message); }, - 'passcode.code_mismatch': (error) => { + 'verification_code.code_mismatch': (error) => { setErrorMessage(error.message); }, }),