diff --git a/api/src/constants/index.ts b/api/src/constants/index.ts index 2ad157f4e..777712bd6 100644 --- a/api/src/constants/index.ts +++ b/api/src/constants/index.ts @@ -293,3 +293,8 @@ export const GET_AUDIT_DATA = { AUDIT_REPORT: "audit-report", FILTERALL: "all", } + +export const RESERVED_FIELD_MAPPINGS: Record = { + 'locale': 'cm_locale' + // Add other reserved fields if needed +}; \ No newline at end of file diff --git a/api/src/services/aem.service.ts b/api/src/services/aem.service.ts index f86871ad3..8631dd52e 100644 --- a/api/src/services/aem.service.ts +++ b/api/src/services/aem.service.ts @@ -6,7 +6,7 @@ import { v4 as uuidv4 } from 'uuid'; import { JSDOM } from "jsdom"; import { htmlToJson } from '@contentstack/json-rte-serializer'; import { buildSchemaTree } from '../utils/content-type-creator.utils.js'; -import { MIGRATION_DATA_CONFIG, LOCALE_MAPPER } from '../constants/index.js'; +import { MIGRATION_DATA_CONFIG, LOCALE_MAPPER, RESERVED_FIELD_MAPPINGS } from '../constants/index.js'; import { getLogMessage } from '../utils/index.js'; import customLogger from '../utils/custom-logger.utils.js'; import { orgService } from './org.service.js'; @@ -144,6 +144,17 @@ function getFieldValue(items: any, fieldName: string): any { return undefined; } + +function getActualFieldUid(uid: string, fieldUid: string): string { + if (RESERVED_FIELD_MAPPINGS[uid]) { + return RESERVED_FIELD_MAPPINGS[uid]; + } + if (RESERVED_FIELD_MAPPINGS[fieldUid]) { + return RESERVED_FIELD_MAPPINGS[fieldUid]; + } + return uid; +} + /** * Finds and returns the asset object from assetJsonData where assetPath matches the given string. * @param assetJsonData - The asset JSON data object. @@ -613,15 +624,16 @@ function processFieldsRecursive( } case 'single_line_text': { - const aemFieldName = field?.otherCmsField ? getLastKey(field.otherCmsField, ' > ') : getLastKey(field?.uid); + const aemFieldName = field?.otherCmsField ? getLastKey(field?.otherCmsField, ' > ') : getLastKey(field?.uid); let value = getFieldValue(items, aemFieldName); const uid = getLastKey(field?.contentstackFieldUid); + const actualUid = getActualFieldUid(uid, field?.uid); if (value && typeof value === 'string' && /<[^>]+>/.test(value)) { value = stripHtmlTags(value); } - obj[uid] = value !== null && value !== undefined ? String(value) : ""; + obj[actualUid] = value !== null && value !== undefined ? String(value) : ""; break; } diff --git a/upload-api/migration-aem/libs/contentType/components/SearchComponent.ts b/upload-api/migration-aem/libs/contentType/components/SearchComponent.ts index 1c2539206..4dc15edb1 100644 --- a/upload-api/migration-aem/libs/contentType/components/SearchComponent.ts +++ b/upload-api/migration-aem/libs/contentType/components/SearchComponent.ts @@ -45,7 +45,7 @@ export class SearchComponent extends ContentstackComponent { uid: key, displayName: key, description: "", - defaultValue: null + defaultValue: "" }).toContentstack(), object: () => null, array: () => null diff --git a/upload-api/migration-aem/libs/contentType/components/TeaserComponent.ts b/upload-api/migration-aem/libs/contentType/components/TeaserComponent.ts index b8e583315..2020b9278 100644 --- a/upload-api/migration-aem/libs/contentType/components/TeaserComponent.ts +++ b/upload-api/migration-aem/libs/contentType/components/TeaserComponent.ts @@ -65,7 +65,7 @@ export class TeaserComponent extends ContentstackComponent { uid: key, displayName: key, description: "", - defaultValue: null + defaultValue: "" }).toContentstack(), object: (key, schemaProp) => { const data = { convertedSchema: schemaProp }