const SAFE_DOCUMENT_CATEGORIES = new Set([ "vat_invoice", "full_vat_invoice", "electronic_train_ticket", ]); function normalizeSafeMetaString(value, maxLength = 64) { if (typeof value !== "string") return null; const normalized = value.trim(); return normalized ? normalized.slice(0, maxLength) : null; } function mapInvoiceDocumentMeta(invoice) { const result = invoice?.ocr_result?.result_json; const category = normalizeSafeMetaString(result?.documentCategory); return { documentCategory: SAFE_DOCUMENT_CATEGORIES.has(category) ? category : null, documentSubtype: normalizeSafeMetaString(result?.documentSubtype), }; } module.exports = { mapInvoiceDocumentMeta };