Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

1.4 KB
Raw Blame
import { z } from "zod/v4";

import { createCustomErrorParams } from "./form/i18n";

export const certificateValidFileNameSchema = z.string().regex(/^[\w\-. ]+$/);

export const rootCertificateFileNameSchema = z
  .string()
  .max(128)
  .regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]*\.(crt|pem)$/);

export const rootCertificateMetadataSchema = z.object({
  fileName: rootCertificateFileNameSchema,
  sha256: z.string(),
  fingerprint256: z.string(),
  ca: z.literal(true),
  validFrom: z.string(),
  validTo: z.string(),
});

export const checkCertificateFile: z.core.CheckFn<File> = (context) => {
  const result = certificateValidFileNameSchema.safeParse(context.value.name);
  if (!result.success) {
    context.issues.push({
      code: "custom",
      params: createCustomErrorParams({
        key: "invalidFileName",
        params: {},
      }),
      input: context.value.name,
    });
    return;
  }

  if (!context.value.name.endsWith(".crt") && !context.value.name.endsWith(".pem")) {
    context.issues.push({
      code: "custom",
      params: createCustomErrorParams({
        key: "invalidFileType",
        params: { expected: ".crt" },
      }),
      input: context.value.name,
    });
    return;
  }

  if (context.value.size > 1024 * 1024) {
    context.issues.push({
      code: "custom",
      params: createCustomErrorParams({
        key: "fileTooLarge",
        params: { maxSize: "1 MiB" },
      }),
      input: context.value.size,
    });
    return;
  }
};