Skip to content

Commit 177eece

Browse files
Merge pull request #825 from contentstack/dev
Dev to Stage Push
2 parents 41eba76 + 0062135 commit 177eece

File tree

42 files changed

+6685
-14070
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+6685
-14070
lines changed

.gitignore

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,14 @@ upload-api/build
356356
ui/.env
357357
upload-api/sitecoreMigrationData
358358
upload-api/cmsMigrationData
359-
upload-api/extracted_files
359+
upload-api/extracted_files*
360360
*copy*
361361
.qodo
362362
.vscode
363-
app.json
363+
app.json
364+
# Snyk Security Extension - AI Rules (auto-generated)
365+
.cursor/rules/snyk_rules.mdc
366+
*extracted_files*
367+
*MigrationData*
368+
*.zip
369+
app.json

api/.eslintrc.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"parser": "@typescript-eslint/parser",
1313
"parserOptions": {
1414
"ecmaVersion": 2022,
15-
"project": ["./tsconfig.json"],
1615
"sourceType": "module"
1716
},
1817
"plugins": ["@typescript-eslint"],

api/package-lock.json

Lines changed: 1314 additions & 2201 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@
2525
},
2626
"homepage": "https://github.com/contentstack/migration-v2.git#readme",
2727
"dependencies": {
28-
"@contentstack/cli": "1.41.0",
29-
"@contentstack/cli-utilities": "^1.12.0",
30-
"@contentstack/json-rte-serializer": "^2.0.7",
31-
"@contentstack/marketplace-sdk": "^1.2.4",
28+
"@contentstack/cli": "^1.51.1",
29+
"@contentstack/cli-utilities": "^1.14.2",
30+
"@contentstack/json-rte-serializer": "^3.0.4",
31+
"@contentstack/marketplace-sdk": "^1.4.0",
3232
"axios": "^1.12.0",
3333
"chokidar": "^3.6.0",
3434
"cors": "^2.8.5",
35+
"dayjs": "^1.11.18",
3536
"dotenv": "^16.3.1",
3637
"express": "^4.21.0",
3738
"express-validator": "^7.3.0",

api/src/services/contentMapper.service.ts

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ const putTestData = async (req: Request) => {
5555
return { ...item, id, projectId };
5656
});
5757

58+
contentTypes?.forEach((items: any) => {
59+
items?.fieldMapping?.forEach?.((item: any) => {
60+
if (item?.advanced) {
61+
item.advanced.initial = structuredClone(item?.advanced);
62+
}
63+
});
64+
});
65+
66+
67+
5868
/*
5969
this code snippet iterates over an array of contentTypes and performs
6070
some operations on each element.
@@ -65,7 +75,6 @@ const putTestData = async (req: Request) => {
6575
Finally, it updates the fieldMapping property of each type in the contentTypes array with the fieldIds array.
6676
*/
6777
await FieldMapperModel.read();
68-
6978
contentTypes.map((type: any, index: any) => {
7079
const fieldIds: string[] = [];
7180
const fields = Array?.isArray?.(type?.fieldMapping) ? type?.fieldMapping?.filter((field: any) => field)?.map?.((field: any) => {
@@ -265,7 +274,15 @@ const getFieldMapping = async (req: Request) => {
265274

266275
return fieldMapper;
267276
});
268-
const fieldMapping: any = fieldData;
277+
278+
const fieldMapping: any = fieldData?.map((field: any) => {
279+
if (field?.advanced?.initial) {
280+
const { initial, ...restAdvanced } = field?.advanced;
281+
return { ...field, advanced: restAdvanced };
282+
}
283+
return field;
284+
});
285+
269286
if (!isEmpty(fieldMapping)) {
270287
if (search) {
271288
filteredResult = fieldMapping?.filter?.((item: any) =>
@@ -633,8 +650,16 @@ const updateContentType = async (req: Request) => {
633650
);
634651
if (fieldIndex > -1 && field?.contentstackFieldType !== "") {
635652
FieldMapperModel.update((data: any) => {
653+
const existingField = data?.field_mapper?.[fieldIndex];
654+
const preservedInitial = existingField?.advanced?.initial;
655+
656+
636657
data.field_mapper[fieldIndex] = field;
637-
//data.field_mapper[fieldIndex].isDeleted = false;
658+
659+
660+
if (preservedInitial && field?.advanced) {
661+
data.field_mapper[fieldIndex].advanced.initial = preservedInitial;
662+
}
638663
});
639664
}
640665
});
@@ -750,12 +775,17 @@ const resetToInitialMapping = async (req: Request) => {
750775
);
751776
if (fieldIndex > -1) {
752777
FieldMapperModel.update((data: any) => {
753-
data.field_mapper[fieldIndex] = {
754-
...field,
755-
contentstackField: field?.otherCmsField,
756-
contentstackFieldUid: field?.backupFieldUid,
757-
contentstackFieldType: field?.backupFieldType,
758-
};
778+
779+
data.field_mapper[fieldIndex] = {
780+
...field,
781+
contentstackField: field?.otherCmsField,
782+
contentstackFieldUid: field?.backupFieldUid,
783+
contentstackFieldType: field?.backupFieldType,
784+
advanced: {
785+
...field?.advanced?.initial,
786+
initial: field?.advanced?.initial,
787+
}
788+
}
759789
});
760790
}
761791
});
Lines changed: 60 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import path from 'path';
22
import fs from 'fs';
3-
import getAuthtoken from "../utils/auth.utils.js";
3+
import getAuthtoken from '../utils/auth.utils.js';
44
import { MIGRATION_DATA_CONFIG, KEYTOREMOVE } from '../constants/index.js';
55
import { getAppManifestAndAppConfig } from '../utils/market-app.utils.js';
6-
import { v4 as uuidv4 } from "uuid";
7-
6+
import { v4 as uuidv4 } from 'uuid';
87

98
const {
109
EXTENSIONS_MAPPER_DIR_NAME,
1110
MARKETPLACE_APPS_DIR_NAME,
12-
MARKETPLACE_APPS_FILE_NAME
11+
MARKETPLACE_APPS_FILE_NAME,
1312
} = MIGRATION_DATA_CONFIG;
1413

15-
1614
const groupByAppUid = (data: any) => {
1715
return data?.reduce?.((acc: any, item: any) => {
1816
if (!acc[item.appUid]) {
@@ -21,85 +19,114 @@ const groupByAppUid = (data: any) => {
2119
acc[item.appUid].push(item.extensionUid);
2220
return acc;
2321
}, {});
24-
}
22+
};
2523
const removeKeys = (obj: any, keysToRemove: any) => {
2624
return Object.fromEntries(
2725
Object.entries(obj).filter(([key]) => !keysToRemove.includes(key))
2826
);
29-
}
27+
};
3028

3129
const writeManifestFile = async ({ destinationStackId, appManifest }: any) => {
32-
const dirPath = path.join(process.cwd(), MIGRATION_DATA_CONFIG.DATA, destinationStackId, MARKETPLACE_APPS_DIR_NAME);
30+
const dirPath = path.join(
31+
process.cwd(),
32+
MIGRATION_DATA_CONFIG.DATA,
33+
destinationStackId,
34+
MARKETPLACE_APPS_DIR_NAME
35+
);
3336
try {
3437
await fs.promises.access(dirPath);
3538
} catch (err) {
3639
try {
3740
await fs.promises.mkdir(dirPath, { recursive: true });
3841
} catch (mkdirErr) {
39-
console.error("🚀 ~ fs.mkdir ~ err:", mkdirErr);
42+
console.error('🚀 ~ fs.mkdir ~ err:', mkdirErr);
4043
return;
4144
}
4245
}
4346
try {
4447
const filePath = path.join(dirPath, MARKETPLACE_APPS_FILE_NAME);
4548
await fs.promises.writeFile(filePath, JSON.stringify(appManifest, null, 2));
4649
} catch (writeErr) {
47-
console.error("🚀 ~ fs.writeFile ~ err:", writeErr);
50+
console.error('🚀 ~ fs.writeFile ~ err:', writeErr);
4851
}
49-
}
52+
};
5053

51-
52-
53-
const createAppManifest = async ({ destinationStackId, region, userId, orgId }: any) => {
54+
const createAppManifest = async ({
55+
destinationStackId,
56+
region,
57+
userId,
58+
orgId,
59+
}: any) => {
5460
const authtoken = await getAuthtoken(region, userId);
55-
const marketPlacePath = path.join(MIGRATION_DATA_CONFIG.DATA, destinationStackId, EXTENSIONS_MAPPER_DIR_NAME);
56-
const AppMapper: any = await fs.promises.readFile(marketPlacePath, "utf-8").catch(async () => { });
61+
const marketPlacePath = path.join(
62+
MIGRATION_DATA_CONFIG.DATA,
63+
destinationStackId,
64+
EXTENSIONS_MAPPER_DIR_NAME
65+
);
66+
const AppMapper: any = await fs.promises
67+
.readFile(marketPlacePath, 'utf-8')
68+
.catch(async () => {});
5769
if (AppMapper !== undefined) {
5870
const appManifest: any = [];
5971
const groupUids: any = groupByAppUid(JSON.parse(AppMapper));
6072
for await (const [key, value] of Object?.entries?.(groupUids) || {}) {
61-
const data: any = await getAppManifestAndAppConfig({ organizationUid: orgId, authtoken, region, manifestUid: key });
73+
const data: any = await getAppManifestAndAppConfig({
74+
organizationUid: orgId,
75+
authtoken,
76+
region,
77+
manifestUid: key,
78+
});
6279
data.manifest = removeKeys(data, KEYTOREMOVE);
63-
const extensionUids: any = new Set(value) ?? [];
80+
const extensionUids: any = new Set(Array.isArray(value) ? value : []);
6481
const locations: any = [];
65-
for (const ext of extensionUids ?? []) {
82+
for (const ext of extensionUids) {
6683
const seprateUid = ext?.split?.('-');
6784
const type: string = seprateUid?.[1];
6885
const extUid: string = seprateUid?.[0];
6986
for (const loc of data?.ui_location?.locations ?? []) {
7087
if (loc?.type === type) {
71-
const isPresent = locations?.meta?.findIndex((item: any) => item?.extension_uid === extUid);
88+
const isPresent = locations?.meta?.findIndex(
89+
(item: any) => item?.extension_uid === extUid
90+
);
7291
if (isPresent === undefined) {
7392
locations?.push({
7493
type,
75-
meta: [{ ...(loc?.meta?.[0] || {}), extension_uid: extUid }]
76-
})
94+
meta: [{ ...(loc?.meta?.[0] || {}), extension_uid: extUid }],
95+
});
7796
}
7897
}
7998
}
8099
}
81-
const configData = data?.ui_location?.locations?.find((ele: any) => ele?.type === 'cs.cm.stack.config');
100+
const configData = data?.ui_location?.locations?.find(
101+
(ele: any) => ele?.type === 'cs.cm.stack.config'
102+
);
82103
if (configData) {
83104
locations?.push({
84105
type: configData?.type,
85-
meta: [{ ...(configData?.meta?.[0] || {}), name: 'Config', extension_uid: uuidv4() }]
86-
})
106+
meta: [
107+
{
108+
...(configData?.meta?.[0] || {}),
109+
name: 'Config',
110+
extension_uid: uuidv4(),
111+
},
112+
],
113+
});
87114
}
88115
data.ui_location.locations = locations;
89-
data.status = "installed";
116+
data.status = 'installed';
90117
data.target = {
91-
"type": "stack",
92-
"uid": destinationStackId
118+
type: 'stack',
119+
uid: destinationStackId,
93120
};
94121
data.installation_uid = data?.uid;
95-
data.configuration = "";
96-
data.server_configuration = "";
122+
data.configuration = '';
123+
data.server_configuration = '';
97124
appManifest?.push(removeKeys(data, KEYTOREMOVE));
98125
}
99126
await writeManifestFile({ destinationStackId, appManifest });
100127
}
101-
}
128+
};
102129

103130
export const marketPlaceAppService = {
104-
createAppManifest
105-
}
131+
createAppManifest,
132+
};

0 commit comments

Comments
 (0)