Migrate url tooling to twenty-shared (#10440)

Migrate and unify URL tooling in twenty-shared.

We now have:
- isValidHostname which follows our own business rules
- a zod schema that can be re-used in different context and leverages is
isValidHostname
- isValidUrl on top of the zod schema
- a getAbsoluteURl and getHostname on top of the zod schema

I have added a LOT of tests to cover all the cases I've found

Also fixes: https://github.com/twentyhq/twenty/issues/10147
This commit is contained in:
Charles Bochet
2025-02-24 18:01:51 +01:00
committed by GitHub
parent d4bdae562f
commit 9046a9ac16
28 changed files with 280 additions and 158 deletions

View File

@ -7,8 +7,8 @@ import { z } from 'zod';
import { TextInput } from '@/ui/input/components/TextInput';
import { useLingui } from '@lingui/react/macro';
import { isValidHostname } from 'twenty-shared';
import { Button } from 'twenty-ui';
import { isDomain } from '~/utils/is-domain';
const StyledContainer = styled.div`
display: flex;
@ -43,12 +43,15 @@ export const SettingsAccountsBlocklistInput = ({
.trim()
.email(t`Invalid email or domain`)
.or(
z
.string()
.refine(
(value) => value.startsWith('@') && isDomain(value.slice(1)),
t`Invalid email or domain`,
),
z.string().refine(
(value) =>
value.startsWith('@') &&
isValidHostname(value.slice(1), {
allowIp: false,
allowLocalhost: false,
}),
t`Invalid email or domain`,
),
)
.refine(
(value) => !blockedEmailOrDomainList.includes(value),