Barazo AppView backend
barazo.forum
1import { z } from 'zod/v4'
2
3// ---------------------------------------------------------------------------
4// Body schemas
5// ---------------------------------------------------------------------------
6
7/** Schema for PUT /api/users/me/preferences body. */
8export const userPreferencesSchema = z.object({
9 maturityLevel: z.enum(['sfw', 'mature']).optional(),
10 mutedWords: z.array(z.string().min(1).max(200)).max(500).optional(),
11 blockedDids: z.array(z.string().min(1)).max(1000).optional(),
12 mutedDids: z.array(z.string().min(1)).max(1000).optional(),
13 crossPostBluesky: z.boolean().optional(),
14 crossPostFrontpage: z.boolean().optional(),
15})
16
17export type UserPreferencesInput = z.infer<typeof userPreferencesSchema>
18
19/** Schema for PUT /api/users/me/communities/:communityId/preferences body. */
20export const communityPreferencesSchema = z.object({
21 maturityOverride: z.enum(['sfw', 'mature']).nullable().optional(),
22 mutedWords: z.array(z.string().min(1).max(200)).max(500).nullable().optional(),
23 blockedDids: z.array(z.string().min(1)).max(1000).nullable().optional(),
24 mutedDids: z.array(z.string().min(1)).max(1000).nullable().optional(),
25 notificationPrefs: z
26 .object({
27 replies: z.boolean(),
28 reactions: z.boolean(),
29 mentions: z.boolean(),
30 modActions: z.boolean(),
31 })
32 .nullable()
33 .optional(),
34})
35
36export type CommunityPreferencesInput = z.infer<typeof communityPreferencesSchema>
37
38/** Valid declared age values: 0 = "rather not say", then jurisdiction thresholds + 18 */
39const VALID_DECLARED_AGES = [0, 13, 14, 15, 16, 18] as const
40
41/** Schema for POST /api/users/me/age-declaration body. */
42export const ageDeclarationSchema = z.object({
43 declaredAge: z
44 .number()
45 .refine(
46 (val): val is (typeof VALID_DECLARED_AGES)[number] =>
47 (VALID_DECLARED_AGES as readonly number[]).includes(val),
48 { message: 'declaredAge must be one of: 0, 13, 14, 15, 16, 18' }
49 ),
50})
51
52export type AgeDeclarationInput = z.infer<typeof ageDeclarationSchema>
53
54// ---------------------------------------------------------------------------
55// Query schemas
56// ---------------------------------------------------------------------------
57
58/** Schema for GET /api/users/resolve-handles query string. */
59export const resolveHandlesSchema = z.object({
60 handles: z
61 .string()
62 .min(1)
63 .transform((val) =>
64 val
65 .split(',')
66 .map((h) => h.trim())
67 .filter(Boolean)
68 )
69 .pipe(z.array(z.string().min(1)).min(1).max(25)),
70})
71
72export type ResolveHandlesInput = z.infer<typeof resolveHandlesSchema>