mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-25 05:31:12 -05:00
feat: Implement privacy modernization plan
This commit is contained in:
70
src/lib/privacyValidation.ts
Normal file
70
src/lib/privacyValidation.ts
Normal 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
|
||||
};
|
||||
Reference in New Issue
Block a user