Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

2.3 KB
Raw Blame
import {
  FOLDER_USER_ROLE,
  FOLDER_WORKSPACE_ACCESS,
} from "@/lib/folder/constants";
import { FolderAccessLevel } from "@/lib/types";
import { FolderType, FolderUserRole } from "@prisma/client";
import * as z from "zod/v4";
import { getPaginationQuerySchema } from "./misc";

const folderAccessLevelSchema = z.enum(
  Object.keys(FOLDER_WORKSPACE_ACCESS) as [
    FolderAccessLevel,
    ...FolderAccessLevel[],
  ],
);

const workspaceFolderAccess = folderAccessLevelSchema
  .nullish()
  .default("write")
  .describe(
    "The workspace-level access level settings for the folder. Default is `write` which allows full access to the folder for all team members. The other options are `read` (view-only access) and `null` (no access) and are only available on Business plans and above.",
  );

export const folderUserRoleSchema = z
  .enum(Object.keys(FOLDER_USER_ROLE) as [FolderUserRole, ...FolderUserRole[]])
  .describe("The role of the user in the folder.");

export const FolderSchema = z.object({
  id: z.string().describe("The unique ID of the folder."),
  name: z.string().describe("The name of the folder."),
  description: z.string().nullable().describe("The description of the folder."),
  type: z.enum(Object.keys(FolderType) as [FolderType, ...FolderType[]]),
  accessLevel: workspaceFolderAccess,
  createdAt: z.date().describe("The date the folder was created."),
  updatedAt: z.date().describe("The date the folder was updated."),
});

export const FOLDER_MAX_DESCRIPTION_LENGTH = 500;

export const createFolderSchema = z.object({
  name: z.string().describe("The name of the folder.").max(190),
  description: z
    .string()
    .max(FOLDER_MAX_DESCRIPTION_LENGTH)
    .nullish()
    .describe("The description of the folder."),
  accessLevel: workspaceFolderAccess,
});

export const FOLDERS_MAX_PAGE_SIZE = 50;

export const listFoldersQuerySchema = z
  .object({
    search: z
      .string()
      .optional()
      .describe("The search term to filter the folders by."),
  })
  .extend(getPaginationQuerySchema({ pageSize: FOLDERS_MAX_PAGE_SIZE }));

export const updateFolderSchema = z.object({
  name: createFolderSchema.shape.name.optional(),
  description: createFolderSchema.shape.description.optional(),
  accessLevel: folderAccessLevelSchema
    .nullish()
    .describe("The access level of the folder within the workspace."),
});