2024-03-04 22:13:40 +01:00
|
|
|
import { z } from "zod";
|
|
|
|
|
|
2025-04-06 12:37:28 +02:00
|
|
|
export const appHrefSchema = z
|
|
|
|
|
.string()
|
|
|
|
|
.trim()
|
|
|
|
|
.url()
|
2025-05-23 22:19:59 +02:00
|
|
|
.regex(/^(?!javascript)[a-zA-Z]*:\/\//i) // javascript: is not allowed, i for case insensitive (so Javascript: is also not allowed)
|
2025-04-06 12:37:28 +02:00
|
|
|
.or(z.literal(""))
|
|
|
|
|
.transform((value) => (value.length === 0 ? null : value))
|
|
|
|
|
.nullable();
|
|
|
|
|
|
|
|
|
|
export const appManageSchema = z.object({
|
2025-01-26 21:25:57 +01:00
|
|
|
name: z.string().trim().min(1).max(64),
|
|
|
|
|
description: z
|
|
|
|
|
.string()
|
|
|
|
|
.trim()
|
|
|
|
|
.max(512)
|
|
|
|
|
.transform((value) => (value.length === 0 ? null : value))
|
|
|
|
|
.nullable(),
|
|
|
|
|
iconUrl: z.string().trim().min(1),
|
2025-04-06 12:37:28 +02:00
|
|
|
href: appHrefSchema,
|
2025-02-21 22:47:30 +01:00
|
|
|
pingUrl: z
|
|
|
|
|
.string()
|
|
|
|
|
.trim()
|
|
|
|
|
.url()
|
|
|
|
|
.regex(/^https?:\/\//) // Only allow http and https for security reasons (javascript: is not allowed)
|
|
|
|
|
.or(z.literal(""))
|
|
|
|
|
.transform((value) => (value.length === 0 ? null : value))
|
|
|
|
|
.nullable(),
|
2024-03-04 22:13:40 +01:00
|
|
|
});
|
|
|
|
|
|
2025-04-06 12:37:28 +02:00
|
|
|
export const appCreateManySchema = z
|
|
|
|
|
.array(appManageSchema.omit({ iconUrl: true }).and(z.object({ iconUrl: z.string().min(1).nullable() })))
|
|
|
|
|
.min(1);
|
2024-03-04 22:13:40 +01:00
|
|
|
|
2025-04-06 12:37:28 +02:00
|
|
|
export const appEditSchema = appManageSchema.and(z.object({ id: z.string() }));
|