Update enums to be all caps (#12372)

- Make custom domain public (remove from lab)
- Use ALL_CAPS definition for enums
This commit is contained in:
Félix Malfait
2025-05-29 14:08:36 +02:00
committed by GitHub
parent 76d0be7f81
commit 4485e8e3db
165 changed files with 845 additions and 847 deletions

View File

@ -35,7 +35,7 @@ export const CaptchaProviderScriptLoaderEffect = () => {
scriptElement = document.createElement('script');
scriptElement.src = scriptUrl;
scriptElement.onload = () => {
if (captcha.provider === CaptchaDriverType.GoogleRecaptcha) {
if (captcha.provider === CaptchaDriverType.GOOGLE_RECAPTCHA) {
window.grecaptcha?.ready(() => {
setIsCaptchaScriptLoaded(true);
});
@ -55,11 +55,11 @@ export const CaptchaProviderScriptLoaderEffect = () => {
let refreshInterval: NodeJS.Timeout;
switch (captcha.provider) {
case CaptchaDriverType.GoogleRecaptcha:
case CaptchaDriverType.GOOGLE_RECAPTCHA:
// Google reCAPTCHA tokens expire after 120 seconds, refresh at 110 seconds
refreshInterval = setInterval(requestFreshCaptchaToken, 110 * 1000);
break;
case CaptchaDriverType.Turnstile:
case CaptchaDriverType.TURNSTILE:
// Cloudflare Turnstile tokens expire after 500 seconds, refresh at 480 seconds
refreshInterval = setInterval(requestFreshCaptchaToken, 480 * 1000);
break;

View File

@ -41,7 +41,7 @@ export const useRequestFreshCaptchaToken = () => {
let captchaWidget: any;
switch (captcha.provider) {
case CaptchaDriverType.GoogleRecaptcha:
case CaptchaDriverType.GOOGLE_RECAPTCHA:
window.grecaptcha
.execute(captcha.siteKey, {
action: 'submit',
@ -51,7 +51,7 @@ export const useRequestFreshCaptchaToken = () => {
setIsRequestingCaptchaToken(false);
});
break;
case CaptchaDriverType.Turnstile:
case CaptchaDriverType.TURNSTILE:
captchaWidget = window.turnstile.render('#captcha-widget', {
sitekey: captcha.siteKey,
});

View File

@ -7,7 +7,7 @@ import { getCaptchaUrlByProvider } from '../getCaptchaUrlByProvider';
describe('getCaptchaUrlByProvider', () => {
it('handles GoogleRecaptcha', async () => {
const captchaUrl = getCaptchaUrlByProvider(
CaptchaDriverType.GoogleRecaptcha,
CaptchaDriverType.GOOGLE_RECAPTCHA,
'siteKey',
);
@ -16,14 +16,14 @@ describe('getCaptchaUrlByProvider', () => {
);
expect(() =>
getCaptchaUrlByProvider(CaptchaDriverType.GoogleRecaptcha, ''),
getCaptchaUrlByProvider(CaptchaDriverType.GOOGLE_RECAPTCHA, ''),
).toThrow(
'SiteKey must be provided while generating url for GoogleRecaptcha provider',
);
});
it('handles Turnstile', async () => {
const captchaUrl = getCaptchaUrlByProvider(CaptchaDriverType.Turnstile, '');
const captchaUrl = getCaptchaUrlByProvider(CaptchaDriverType.TURNSTILE, '');
expect(captchaUrl).toEqual(
'https://challenges.cloudflare.com/turnstile/v0/api.js',

View File

@ -7,14 +7,14 @@ export const getCaptchaUrlByProvider = (
siteKey: string,
) => {
switch (name) {
case CaptchaDriverType.GoogleRecaptcha:
case CaptchaDriverType.GOOGLE_RECAPTCHA:
if (!isNonEmptyString(siteKey)) {
throw new Error(
'SiteKey must be provided while generating url for GoogleRecaptcha provider',
);
}
return `https://www.google.com/recaptcha/api.js?render=${siteKey}`;
case CaptchaDriverType.Turnstile:
case CaptchaDriverType.TURNSTILE:
return 'https://challenges.cloudflare.com/turnstile/v0/api.js';
default:
throw new Error('Unknown captcha provider');