From 6a8596dd23365c374695be32c5618648fe603829 Mon Sep 17 00:00:00 2001 From: shobhit upadhyay Date: Fri, 31 Oct 2025 12:11:46 +0530 Subject: [PATCH 1/3] refactor: add reserved field mappings and improve UID handling in aem.service.ts; update defaultValue to empty string in SearchComponent and TeaserComponent Bug Fix - CMG-724 --- api/src/services/aem.service.ts | 21 +++++++++++++++++-- .../contentType/components/SearchComponent.ts | 2 +- .../contentType/components/TeaserComponent.ts | 2 +- upload-api/src/config/index.ts | 4 ++-- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/api/src/services/aem.service.ts b/api/src/services/aem.service.ts index f86871ad3..b24d83e28 100644 --- a/api/src/services/aem.service.ts +++ b/api/src/services/aem.service.ts @@ -144,6 +144,22 @@ function getFieldValue(items: any, fieldName: string): any { return undefined; } +// Reserved field helper function +const RESERVED_FIELD_MAPPINGS: Record = { + 'locale': 'cm_locale' + // Add other reserved fields if needed +}; + +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 +629,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 } diff --git a/upload-api/src/config/index.ts b/upload-api/src/config/index.ts index ca683e8b0..62dab023e 100644 --- a/upload-api/src/config/index.ts +++ b/upload-api/src/config/index.ts @@ -2,7 +2,7 @@ export default { plan: { dropdown: { optionLimit: 100 } }, - cmsType: process.env.CMS_TYPE || 'cmsType', + cmsType: process.env.CMS_TYPE || 'aem', isLocalPath: true, awsData: { awsRegion: 'us-east-2', @@ -12,5 +12,5 @@ export default { bucketName: '', bucketKey: '' }, - localPath: process.env.CONTAINER_PATH || 'your-local-legacy-cms-path', + localPath: process.env.CONTAINER_PATH || '/Users/shobhit.upadhyay/Downloads/templates', }; \ No newline at end of file From 784e7da9fa95b145f85b9061de695f16a671cf1f Mon Sep 17 00:00:00 2001 From: shobhit upadhyay Date: Fri, 31 Oct 2025 12:20:20 +0530 Subject: [PATCH 2/3] refactor: update cmsType and localPath defaults in configuration for improved clarity and maintainability --- upload-api/src/config/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/upload-api/src/config/index.ts b/upload-api/src/config/index.ts index 62dab023e..ca683e8b0 100644 --- a/upload-api/src/config/index.ts +++ b/upload-api/src/config/index.ts @@ -2,7 +2,7 @@ export default { plan: { dropdown: { optionLimit: 100 } }, - cmsType: process.env.CMS_TYPE || 'aem', + cmsType: process.env.CMS_TYPE || 'cmsType', isLocalPath: true, awsData: { awsRegion: 'us-east-2', @@ -12,5 +12,5 @@ export default { bucketName: '', bucketKey: '' }, - localPath: process.env.CONTAINER_PATH || '/Users/shobhit.upadhyay/Downloads/templates', + localPath: process.env.CONTAINER_PATH || 'your-local-legacy-cms-path', }; \ No newline at end of file From 795bc67d429e8500717a71dfe08095dc560ff96d Mon Sep 17 00:00:00 2001 From: shobhit upadhyay Date: Fri, 31 Oct 2025 12:27:02 +0530 Subject: [PATCH 3/3] refactor: add RESERVED_FIELD_MAPPINGS to constants and update aem.service.ts to utilize new field mappings for improved UID handling --- api/src/constants/index.ts | 5 +++++ api/src/services/aem.service.ts | 7 +------ 2 files changed, 6 insertions(+), 6 deletions(-) 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 b24d83e28..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,11 +144,6 @@ function getFieldValue(items: any, fieldName: string): any { return undefined; } -// Reserved field helper function -const RESERVED_FIELD_MAPPINGS: Record = { - 'locale': 'cm_locale' - // Add other reserved fields if needed -}; function getActualFieldUid(uid: string, fieldUid: string): string { if (RESERVED_FIELD_MAPPINGS[uid]) {