feat: Implement privacy modernization plan

This commit is contained in:
gpt-engineer-app[bot]
2025-10-14 19:45:39 +00:00
parent 95972a0b22
commit 5313d8e66c
4 changed files with 428 additions and 145 deletions

View File

@@ -0,0 +1,70 @@
/**
* Privacy Settings Validation
*
* Provides Zod schemas for runtime validation of privacy settings.
*
* Usage:
* ```typescript
* const validated = privacyFormSchema.parse(userInput);
* ```
*
* Security:
* - All user inputs must be validated before database writes
* - Prevents injection attacks and data corruption
* - Ensures data integrity with type-safe validation
*/
import { z } from 'zod';
/**
* Schema for privacy settings in user_preferences
*/
export const privacySettingsSchema = z.object({
activity_visibility: z.enum(['public', 'private'], {
errorMap: () => ({ message: 'Activity visibility must be public or private' })
}),
search_visibility: z.boolean(),
show_location: z.boolean(),
show_age: z.boolean(),
show_avatar: z.boolean(),
show_bio: z.boolean(),
show_activity_stats: z.boolean(),
show_home_park: z.boolean()
});
/**
* Schema for profile privacy settings
*/
export const profilePrivacySchema = z.object({
privacy_level: z.enum(['public', 'private'], {
errorMap: () => ({ message: 'Privacy level must be public or private' })
}),
show_pronouns: z.boolean()
});
/**
* Combined schema for privacy form
*/
export const privacyFormSchema = privacySettingsSchema.merge(profilePrivacySchema);
/**
* Schema for blocking a user
*/
export const blockUserSchema = z.object({
blocked_id: z.string().uuid('Invalid user ID'),
reason: z.string().max(500, 'Reason must be 500 characters or less').optional()
});
/**
* Default privacy settings for new users
*/
export const DEFAULT_PRIVACY_SETTINGS = {
activity_visibility: 'public' as const,
search_visibility: true,
show_location: false,
show_age: false,
show_avatar: true,
show_bio: true,
show_activity_stats: true,
show_home_park: false
};