// Shared runtime schema for the content JSON files (proto/src/content/*.json). // Kept dependency-free — used by src/content/index.ts (test fixtures for // Header/Footer, MITHOME-96) and scripts/test-content-schema.js. The JSON // files themselves remain the source for scripts/migrate-content-to-payload.ts. // The standalone content-editor.js CMS that used to run this too was retired // in MITHOME-93 (superseded by Payload CMS). const string = { type: 'string' }; const boolean = { type: 'boolean' }; const array = items => ({ type: 'array', items }); const object = properties => ({ type: 'object', properties, required: Object.keys(properties), additionalProperties: false }); const ctaLink = object({ text: string, href: string, external: boolean }); const iconText = object({ icon: string, title: string, description: string }); const legal = object({ id: string, title: string, content: string }); const schemas = { common: object({ buttons: object({ contact: string, learnMore: string, webmail: string, sendMessage: string }), labels: object({ required: string, features: string }), validation: object({ required: string, invalidEmail: string, minLength: string }), staging: object({ banner: string }), footer: object({ copyright: string, address: string }), a11y: object({ openMenu: string, closeMenu: string }), }), home: object({ hero: object({ title: string, subtitle: string, description: string, trustBullets: array(string), cta: object({ primary: ctaLink, secondary: ctaLink }) }), about: object({ title: string, usps: array(object({ id: string, title: string, description: string, icon: string })) }), services: object({ title: string, subtitle: string, items: array(object({ id: string, title: string, description: string, icon: string, features: array(string), ctaText: string })) }), partners: object({ title: string, subtitle: string, items: array(object({ name: string, url: string, logo: string })) }), cta: object({ title: string, subtitle: string, button: string }), serviceFeatures: object({ title: string }), }), about: object({ meta: object({ title: string, description: string, ogDescription: string }), hero: object({ title: string, subtitle: string }), story: object({ title: string, paragraphs: array(string) }), mission: object({ title: string, subtitle: string, values: array(iconText) }), team: object({ title: string, subtitle: string, paragraphs: array(string) }), cta: object({ title: string, subtitle: string, button: string }), }), services: object({ meta: object({ title: string, description: string, ogDescription: string }), hero: object({ title: string, subtitle: string }), details: object({ title: string, subtitle: string, services: array(object({ icon: string, title: string, description: string, specs: object({ title: string, items: array(string) }) })) }), support: object({ title: string, subtitle: string, channels: array(iconText) }), cta: object({ title: string, subtitle: string, primaryButton: string, secondaryButton: string }), }), contact: object({ meta: object({ title: string, description: string }), hero: object({ title: string, subtitle: string }), form: object({ title: string, successMessage: string, errorMessage: string, fields: object({ name: object({ label: string, placeholder: string, error: string }), email: object({ label: string, placeholder: string, errorRequired: string, errorInvalid: string }), subject: object({ label: string, placeholder: string, error: string }), message: object({ label: string, placeholder: string, errorRequired: string, errorMinLength: string }), gdpr: object({ label: string, error: string }), }), submitButton: string, submittingButton: string, }), info: object({ title: string, email: object({ title: string, responseTime: string }), company: object({ title: string }), webmail: object({ title: string, linkText: string, subtitle: string }), }), faq: object({ title: string, items: array(object({ question: string, answer: string })) }), }), adatvedelem: object({ title: string, lastUpdated: string, sections: array(legal) }), hasznalatiFeltetelek: object({ title: string, lastUpdated: string, sections: array(legal) }), }; function validateNode(value, schema, path, errors) { if (schema.type === 'string' || schema.type === 'boolean') { if (typeof value !== schema.type) errors.push(`${path}: ${schema.type} érték szükséges`); return; } if (schema.type === 'array') { if (!Array.isArray(value)) { errors.push(`${path}: tömb szükséges`); return; } value.forEach((item, index) => validateNode(item, schema.items, `${path}[${index}]`, errors)); return; } if (!value || typeof value !== 'object' || Array.isArray(value)) { errors.push(`${path}: objektum szükséges`); return; } for (const key of schema.required) { if (!(key in value)) errors.push(`${path}.${key}: kötelező mező hiányzik`); } for (const key of Object.keys(value)) { if (!(key in schema.properties)) errors.push(`${path}.${key}: nem engedélyezett mező`); } for (const [key, child] of Object.entries(schema.properties)) { if (key in value) validateNode(value[key], child, `${path}.${key}`, errors); } } function validateContent(fileKey, data) { const schema = schemas[fileKey]; if (!schema) return { ok: false, errors: [`Ismeretlen content fájl: ${fileKey}`] }; const errors = []; validateNode(data, schema, '$', errors); return { ok: errors.length === 0, errors }; } module.exports = { schemas, validateContent };