mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-07 19:22:14 +09:00
feat(admin): accept domain entries in the email blocklist (#3129)
This commit is contained in:
@@ -60,7 +60,7 @@ import {
|
||||
SnowflakeType,
|
||||
withOpenApiType,
|
||||
} from '@fluxer/schema/src/primitives/SchemaPrimitives';
|
||||
import {EmailType} from '@fluxer/schema/src/primitives/UserValidators';
|
||||
import {EmailBlocklistEntryType} from '@fluxer/schema/src/primitives/UserValidators';
|
||||
import {schemaMetadata} from '@fluxer/schema/src/SchemaMetadata';
|
||||
import {z} from 'zod';
|
||||
|
||||
@@ -299,7 +299,9 @@ export const BanIpRequest = z.object({
|
||||
export type BanIpRequest = z.infer<typeof BanIpRequest>;
|
||||
|
||||
export const BanEmailRequest = z.object({
|
||||
email: EmailType.describe('Email address to ban'),
|
||||
email: EmailBlocklistEntryType.describe(
|
||||
'Email address to ban, or a domain written as @example.com to ban every address at it and its subdomains',
|
||||
),
|
||||
});
|
||||
|
||||
export type BanEmailRequest = z.infer<typeof BanEmailRequest>;
|
||||
|
||||
@@ -50,6 +50,21 @@ export const EmailType = withOpenApiType(
|
||||
}, ValidationErrorCodes.INVALID_EMAIL_LOCAL_PART),
|
||||
'EmailType',
|
||||
);
|
||||
|
||||
const EMAIL_BLOCKLIST_DOMAIN_REGEX =
|
||||
/^@[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)+$/;
|
||||
|
||||
export const EmailBlocklistEntryType = withOpenApiType(
|
||||
z
|
||||
.string()
|
||||
.overwrite(normalizeString)
|
||||
.refine(
|
||||
(value: string) =>
|
||||
EMAIL_BLOCKLIST_DOMAIN_REGEX.test(value) ? value.length <= 254 : EmailType.safeParse(value).success,
|
||||
ValidationErrorCodes.INVALID_EMAIL_FORMAT,
|
||||
),
|
||||
'EmailBlocklistEntryType',
|
||||
);
|
||||
export const DiscriminatorType = withOpenApiType(
|
||||
z
|
||||
.union([z.string(), z.number()])
|
||||
|
||||
Reference in New Issue
Block a user