Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,8 @@ export const GET_AUDIT_DATA = {
AUDIT_REPORT: "audit-report",
FILTERALL: "all",
}

export const RESERVED_FIELD_MAPPINGS: Record<string, string> = {
'locale': 'cm_locale'
// Add other reserved fields if needed
};
18 changes: 15 additions & 3 deletions api/src/services/aem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class SearchComponent extends ContentstackComponent {
uid: key,
displayName: key,
description: "",
defaultValue: null
defaultValue: ""
}).toContentstack(),
object: () => null,
array: () => null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down