1
4
5import { z } from "zod";
6
7import { LIMITS } from "../constants.js";
8
9export const workspaceRoleSchema = z.enum(["owner", "admin", "member", "guest"]);
10export type WorkspaceRoleInput = z.infer<typeof workspaceRoleSchema>;
11
12export const workspaceSlugSchema = z
13 .string()
14 .min(2, "Slug must be at least 2 characters")
15 .max(LIMITS.MAX_SLUG, "Slug must be at most 50 characters")
16 .regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "Slug must be lowercase letters, digits and dashes");
17export type WorkspaceSlugInput = z.infer<typeof workspaceSlugSchema>;
18
19export const createWorkspaceSchema = z
20 .object({
21 name: z
22 .string()
23 .min(2, "Name must be at least 2 characters")
24 .max(LIMITS.MAX_WORKSPACE_NAME, "Name must be at most 50 characters"),
25 slug: workspaceSlugSchema,
26 description: z.string().max(500).optional(),
27 })
28 .strict();
29export type CreateWorkspace = z.infer<typeof createWorkspaceSchema>;
30
31export const updateWorkspaceSchema = z
32 .object({
33 name: z.string().min(2).max(LIMITS.MAX_WORKSPACE_NAME).optional(),
34 description: z.string().max(500).optional().nullable(),
35 icon: z.string().max(32).optional().nullable(),
36 })
37 .strict()
38 .refine((v) => Object.keys(v).length > 0, { message: "No fields to update" });
39export type UpdateWorkspace = z.infer<typeof updateWorkspaceSchema>;
40
41
42export const addMemberSchema = z
43 .object({
44 email: z.string().min(1).email(),
45 role: z.enum(["owner", "admin", "member", "guest"]),
46 })
47 .strict();
48export type AddMember = z.infer<typeof addMemberSchema>;
49
50
51export const inviteMemberSchema = z
52 .object({
53 email: z.string().min(1).email(),
54 role: z.enum(["admin", "member", "guest"]).default("member"),
55
56 teamId: z.string().min(1).optional(),
57 })
58 .strict();
59export type InviteMember = z.infer<typeof inviteMemberSchema>;
60