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
94 changes: 52 additions & 42 deletions api/src/services/aem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,12 @@ function findAssetByPath(
}

async function writeOneFile(indexPath: string, fileMeta: any) {
fs.writeFile(indexPath, JSON.stringify(fileMeta), (err) => {
if (err) {
console.error('Error writing file: 3', err);
}
});
try {
await fs.promises.writeFile(indexPath, JSON.stringify(fileMeta));
} catch (err) {
console.error('Error writing file:', err);
throw err;
}
}

async function writeFiles(
Expand All @@ -121,23 +122,18 @@ async function writeFiles(
try {
const indexPath = path.join(entryPath, 'index.json');
const localePath = path.join(entryPath, `${locale}.json`);
fs.access(entryPath, async (err) => {
if (err) {
fs.mkdir(entryPath, { recursive: true }, async (err) => {
if (err) {
console.error('Error writing file: 2', err);
} else {
await writeOneFile(indexPath, fileMeta);
await writeOneFile(localePath, entryLocale);
}
});
} else {
await writeOneFile(indexPath, fileMeta);
await writeOneFile(localePath, entryLocale);
}
});

try {
await fs.promises.access(entryPath);
} catch {
await fs.promises.mkdir(entryPath, { recursive: true });
}

await fs.promises.writeFile(indexPath, JSON.stringify(fileMeta));
await fs.promises.writeFile(localePath, JSON.stringify(entryLocale));
} catch (error) {
console.error('Error writing files:', error);
throw error;
}
}

Expand Down Expand Up @@ -460,8 +456,9 @@ function processFieldsRecursive(fields: any[], items: any, title: string, assetJ
break;
}
case 'boolean': {
const value = items?.[field?.uid];
const uid = getLastKey(field?.contentstackFieldUid);
const aemFieldName = field?.otherCmsField ? getLastKey(field.otherCmsField, ' > ') : getLastKey(field?.uid);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add field?.otherCmsField

const value = items?.[aemFieldName];
const uid = getLastKey(field?.contentstackFieldUid);
if (typeof value === 'boolean' || (typeof value === 'object' && value?.[':type']?.includes('separator'))) {
obj[uid] = typeof value === 'boolean' ? value : true;
}
Expand All @@ -484,19 +481,24 @@ function processFieldsRecursive(fields: any[], items: any, title: string, assetJ
break;
}
case 'reference': {
for (const [, val] of Object.entries(items) as [string, Record<string, unknown>][]) {
const fieldKey = getLastKey(field?.contentstackFieldUid);
const refCtUid = field?.referenceTo?.[0] || field?.uid;
for (const [key, val] of Object.entries(items) as [string, Record<string, unknown>][]) {
if (!val?.configured || (val[':type'] as string) === 'nt:folder') {
continue;
}
if (
(typeof field?.uid === 'string' && !['title', 'url'].includes(field.uid)) &&
field?.contentstackFieldType === "reference" &&
(val[':type'] as string) !== 'nt:folder' &&
val?.configured
(val[':type'] as string)?.includes('experiencefragment') &&
typeof val?.localizedFragmentVariationPath === 'string'
) {
if (typeof val?.localizedFragmentVariationPath === 'string' &&
val.localizedFragmentVariationPath.includes(`/${field?.uid}`)) {
obj[field?.uid as string] = [{
const pathMatchesField = val.localizedFragmentVariationPath.includes(`/${field?.uid}`);
const pathMatchesRefType = val.localizedFragmentVariationPath.includes(`/${refCtUid}`);
if (pathMatchesField || pathMatchesRefType) {
obj[fieldKey] = [{
"uid": val?.id,
"_content_type_uid": field?.uid,
"_content_type_uid": refCtUid
}];
break;
}
}
}
Expand Down Expand Up @@ -559,7 +561,6 @@ const createEntry = async ({
contentTypes,
destinationStackId,
projectId,
// keyMapper,
project
}: CreateEntryOptions) => {
const srcFunc = 'createEntry';
Expand All @@ -569,17 +570,21 @@ const createEntry = async ({
const assetJson = path.join(assetsSave, ASSETS_SCHEMA_FILE);
const exists = await isAssetJsonCreated(assetJson);
let assetJsonData: Record<string, AssetJSON> = {};

if (exists) {
const assetData = await fs.promises.readFile(assetJson, 'utf-8');
if (typeof assetData === 'string') {
assetJsonData = JSON.parse(assetData);
}
}

const entriesDir = path.resolve(packagePath ?? '');
const damPath = path.join(entriesDir, AEM_DAM_DIR);
const entriesData: Record<string, Record<string, any[]>> = {};
const allLocales: object = { ...project?.master_locale, ...project?.locales };
const entryMapping: Record<string, string[]> = {};

// FIRST PASS: Process all entries and build mappings
for await (const fileName of read(entriesDir)) {
const filePath = path.join(entriesDir, fileName);
if (filePath?.startsWith?.(damPath)) {
Expand All @@ -599,11 +604,11 @@ const createEntry = async ({
const data = containerCreator(contentType?.fieldMapping, items, title, assetJsonData);
data.uid = uid;
data.publish_details = [];

if (contentType?.contentstackUid && data && mappedLocale) {
const message = getLogMessage(
srcFunc,
`Entry title "${data?.title}"(${contentType?.contentstackUid}
}) in the ${mappedLocale} locale has been successfully transformed.`,
`Entry title "${data?.title}"(${contentType?.contentstackUid}) in the ${mappedLocale} locale has been successfully transformed.`,
{}
);
await customLogger(
Expand All @@ -625,25 +630,30 @@ const createEntry = async ({
for (const entry of entries) {
const flatData = deepFlattenObject(entry);
for (const [key, value] of Object.entries(flatData)) {
if (key.endsWith('._content_type_uid')) {
const uidFeild = key.replace('._content_type_uid', '');
if (uidFeild && typeof value === 'string') {
const refs: string[] = entryMapping?.[value];
if (refs?.length) {
_.set(entry, `${uidFeild}.uid`, refs?.[0]);
}
if (key.endsWith('._content_type_uid') && typeof value === 'string') {
const uidField = key.replace('._content_type_uid', '');
const refs: string[] = entryMapping?.[value];

if (refs?.length) {
_.set(entry, `${uidField}.uid`, refs[0]);
} else {
console.info(`✗ No entry found for content type: ${value}`);
}
}
}
}
const entriesObject: Record<string, any> = {};
for (const entry of entries) {
entriesObject[entry.uid] = entry;
}
const fileMeta = { '1': `${locale}.json` };
const entryPath = path.join(
process.cwd(),
entrySave,
ctUid,
locale
);
await writeFiles(entryPath, fileMeta, entries, locale);
await writeFiles(entryPath, fileMeta, entriesObject, locale);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/AdvancePropertise/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const AdvancePropertise = (props: SchemaProps) => {
value: item
}));

const referencedItems = props?.data?.referenceTo?.map((item: string) => ({
const referencedItems = props?.data?.refrenceTo?.map((item: string) => ({
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Property name 'refrenceTo' appears to be a misspelling of 'referenceTo'.

Suggested change
const referencedItems = props?.data?.refrenceTo?.map((item: string) => ({
const referencedItems = props?.data?.referenceTo?.map((item: string) => ({

Copilot uses AI. Check for mistakes.
label: item,
value: item
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export interface FieldMapType {
contentstackUid: string;
_invalid?: boolean;
backupFieldUid: string;
referenceTo: string[];
refrenceTo: string[];
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Property name 'refrenceTo' appears to be a misspelling of 'referenceTo'.

Suggested change
refrenceTo: string[];
referenceTo: string[];

Copilot uses AI. Check for mistakes.
}

export interface Advanced {
Expand Down
4 changes: 2 additions & 2 deletions ui/src/components/ContentMapper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
// Make title and url field non editable
useEffect(() => {
tableData?.forEach((field) => {
if(field?.backupFieldType === 'reference' && field?.referenceTo?.length === 0) {
if(field?.backupFieldType === 'reference' && field?.refrenceTo?.length === 0) {
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Property name 'refrenceTo' appears to be a misspelling of 'referenceTo'.

Suggested change
if(field?.backupFieldType === 'reference' && field?.refrenceTo?.length === 0) {
if(field?.backupFieldType === 'reference' && field?.referenceTo?.length === 0) {

Copilot uses AI. Check for mistakes.
field._canSelect = false;
}
else if (field?.backupFieldType !== 'text' && field?.backupFieldType !== 'url') {
Expand Down Expand Up @@ -860,7 +860,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
if (row?.uid === rowId && row?.contentstackFieldUid === rowContentstackFieldUid) {
const updatedRow = {
...row,
referenceTo: updatedSettings?.referenedItems,
refrenceTo: updatedSettings?.referenedItems,
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Property name 'refrenceTo' appears to be a misspelling of 'referenceTo'.

Suggested change
refrenceTo: updatedSettings?.referenedItems,
referenceTo: updatedSettings?.referenedItems,

Copilot uses AI. Check for mistakes.
advanced: { ...row?.advanced, ...updatedSettings }
};
return updatedRow;
Expand Down
3 changes: 3 additions & 0 deletions upload-api/migration-aem/helper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ export const uidCorrector = (uid: string) => {
// Remove leading colon if present (e.g., ':items' becomes 'items')
let newUid = uid.replace(/^:/, '');

// Insert underscore before uppercase letters, then lowercase everything
newUid = newUid.replace(/([a-z0-9])([A-Z])/g, '$1_$2');

// Replace spaces, hyphens, and colons with underscores
newUid = newUid.replace(/[ :-]/g, '_');

Expand Down