Skip to content

The open alternative to Salesforce, designed for AI.

1.0 KB
Raw Blame
import { t } from '@lingui/core/macro';
import { isValidUrl } from 'twenty-shared/utils';
import { z } from 'zod';

export const getWebhookFormSchema = () =>
  z.object({
    targetUrl: z
      .string()
      .trim()
      .min(1, { error: () => t`URL is required` })
      .refine((url) => isValidUrl(url), {
        error: () => t`Please enter a valid URL`,
      }),
    description: z.string().optional(),
    operations: z
      .array(
        z.object({
          object: z.string().nullable(),
          action: z.string(),
        }),
      )
      .min(1, { error: () => t`At least one operation is required` })
      .refine(
        (operations) =>
          operations.some((op) => op.object !== null && op.action !== null),
        {
          error: () => t`At least one complete operation is required`,
        },
      ),
    secret: z.string().optional(),
    roleId: z.string().min(1, { error: () => t`A role is required` }),
  });

export type WebhookFormValues = z.infer<
  ReturnType<typeof getWebhookFormSchema>
>;