mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 23:51:11 -05:00
Fix JSON violations
This commit is contained in:
@@ -59,3 +59,72 @@ export interface UppyPhotoSubmissionUploadProps {
|
||||
parkId?: string;
|
||||
rideId?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enforces minimal content structure for content_submissions.content
|
||||
* This type prevents accidental JSON blob storage
|
||||
*
|
||||
* RULE: content should ONLY contain action + max 2 reference IDs
|
||||
*/
|
||||
export interface ContentSubmissionContent {
|
||||
action: 'create' | 'edit' | 'delete';
|
||||
// Only reference IDs allowed - no actual data
|
||||
[key: string]: string | null | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard to validate content structure
|
||||
* Prevents JSON blob violations at runtime
|
||||
*/
|
||||
export function isValidSubmissionContent(content: any): content is ContentSubmissionContent {
|
||||
if (!content || typeof content !== 'object') {
|
||||
console.error('❌ VIOLATION: content_submissions.content must be an object');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!['create', 'edit', 'delete'].includes(content.action)) {
|
||||
console.error('❌ VIOLATION: content_submissions.content must have valid action:', content.action);
|
||||
return false;
|
||||
}
|
||||
|
||||
const keys = Object.keys(content);
|
||||
if (keys.length > 3) {
|
||||
console.error('❌ VIOLATION: content_submissions.content has too many fields:', keys);
|
||||
console.error(' Only action + max 2 reference IDs allowed');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for common violations
|
||||
const forbiddenKeys = ['name', 'description', 'photos', 'data', 'items', 'metadata'];
|
||||
const violations = keys.filter(k => forbiddenKeys.includes(k));
|
||||
if (violations.length > 0) {
|
||||
console.error('❌ VIOLATION: content_submissions.content contains forbidden keys:', violations);
|
||||
console.error(' These should be in submission_items.item_data instead');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to create safe submission content
|
||||
* Use this to ensure compliance with the pattern
|
||||
*/
|
||||
export function createSubmissionContent(
|
||||
action: 'create' | 'edit' | 'delete',
|
||||
referenceIds: Record<string, string> = {}
|
||||
): ContentSubmissionContent {
|
||||
const idKeys = Object.keys(referenceIds);
|
||||
|
||||
if (idKeys.length > 2) {
|
||||
throw new Error(
|
||||
`Too many reference IDs (${idKeys.length}). Maximum is 2. ` +
|
||||
`Put additional data in submission_items.item_data instead.`
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
action,
|
||||
...referenceIds
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user