Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,11 @@ upload-api/build
ui/.env
upload-api/sitecoreMigrationData
upload-api/cmsMigrationData
upload-api/extracted_files
upload-api/extracted_files*
*copy*
.qodo
.vscode
app.json
*extracted_files*
*MigrationData*
*.zip
app.json
3,445 changes: 1,293 additions & 2,152 deletions api/package-lock.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
},
"homepage": "https://github.com/contentstack/migration-v2.git#readme",
"dependencies": {
"@contentstack/cli": "1.41.0",
"@contentstack/cli-utilities": "^1.12.0",
"@contentstack/json-rte-serializer": "^2.0.7",
"@contentstack/marketplace-sdk": "^1.2.4",
"@contentstack/cli": "1.48.0",
"@contentstack/cli-utilities": "^1.14.2",
"@contentstack/json-rte-serializer": "^3.0.4",
"@contentstack/marketplace-sdk": "^1.4.0",
"axios": "^1.12.0",
"chokidar": "^3.6.0",
"cors": "^2.8.5",
"dayjs": "^1.11.18",
"dotenv": "^16.3.1",
"express": "^4.21.0",
"express-validator": "^7.3.0",
Expand Down
92 changes: 60 additions & 32 deletions api/src/services/marketplace.service.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import path from 'path';
import fs from 'fs';
import getAuthtoken from "../utils/auth.utils.js";
import getAuthtoken from '../utils/auth.utils.js';
import { MIGRATION_DATA_CONFIG, KEYTOREMOVE } from '../constants/index.js';
import { getAppManifestAndAppConfig } from '../utils/market-app.utils.js';
import { v4 as uuidv4 } from "uuid";

import { v4 as uuidv4 } from 'uuid';

const {
EXTENSIONS_MAPPER_DIR_NAME,
MARKETPLACE_APPS_DIR_NAME,
MARKETPLACE_APPS_FILE_NAME
MARKETPLACE_APPS_FILE_NAME,
} = MIGRATION_DATA_CONFIG;


const groupByAppUid = (data: any) => {
return data?.reduce?.((acc: any, item: any) => {
if (!acc[item.appUid]) {
Expand All @@ -21,85 +19,115 @@ const groupByAppUid = (data: any) => {
acc[item.appUid].push(item.extensionUid);
return acc;
}, {});
}
};
const removeKeys = (obj: any, keysToRemove: any) => {
return Object.fromEntries(
Object.entries(obj).filter(([key]) => !keysToRemove.includes(key))
);
}
};

const writeManifestFile = async ({ destinationStackId, appManifest }: any) => {
const dirPath = path.join(process.cwd(), MIGRATION_DATA_CONFIG.DATA, destinationStackId, MARKETPLACE_APPS_DIR_NAME);
const dirPath = path.join(
process.cwd(),
MIGRATION_DATA_CONFIG.DATA,
destinationStackId,
MARKETPLACE_APPS_DIR_NAME
);
try {
await fs.promises.access(dirPath);
} catch (err) {
try {
await fs.promises.mkdir(dirPath, { recursive: true });
} catch (mkdirErr) {
console.error("🚀 ~ fs.mkdir ~ err:", mkdirErr);
console.error('🚀 ~ fs.mkdir ~ err:', mkdirErr);
return;
}
}
try {
const filePath = path.join(dirPath, MARKETPLACE_APPS_FILE_NAME);
await fs.promises.writeFile(filePath, JSON.stringify(appManifest, null, 2));
} catch (writeErr) {
console.error("🚀 ~ fs.writeFile ~ err:", writeErr);
console.error('🚀 ~ fs.writeFile ~ err:', writeErr);
}
}
};



const createAppManifest = async ({ destinationStackId, region, userId, orgId }: any) => {
const createAppManifest = async ({
destinationStackId,
region,
userId,
orgId,
}: any) => {
const authtoken = await getAuthtoken(region, userId);
const marketPlacePath = path.join(MIGRATION_DATA_CONFIG.DATA, destinationStackId, EXTENSIONS_MAPPER_DIR_NAME);
const AppMapper: any = await fs.promises.readFile(marketPlacePath, "utf-8").catch(async () => { });
const marketPlacePath = path.join(
MIGRATION_DATA_CONFIG.DATA,
destinationStackId,
EXTENSIONS_MAPPER_DIR_NAME
);
const AppMapper: any = await fs.promises
.readFile(marketPlacePath, 'utf-8')
.catch(async () => {});
if (AppMapper !== undefined) {
const appManifest: any = [];
const groupUids: any = groupByAppUid(JSON.parse(AppMapper));
for await (const [key, value] of Object?.entries?.(groupUids) || {}) {
const data: any = await getAppManifestAndAppConfig({ organizationUid: orgId, authtoken, region, manifestUid: key });
const data: any = await getAppManifestAndAppConfig({
organizationUid: orgId,
authtoken,
region,
manifestUid: key,
});
data.manifest = removeKeys(data, KEYTOREMOVE);
const extensionUids: any = new Set(value) ?? [];
const extensionUids: any =
new Set(Array.isArray(value) ? value : []) ?? [];
const locations: any = [];
for (const ext of extensionUids ?? []) {
const seprateUid = ext?.split?.('-');
const type: string = seprateUid?.[1];
const extUid: string = seprateUid?.[0];
for (const loc of data?.ui_location?.locations ?? []) {
if (loc?.type === type) {
const isPresent = locations?.meta?.findIndex((item: any) => item?.extension_uid === extUid);
const isPresent = locations?.meta?.findIndex(
(item: any) => item?.extension_uid === extUid
);
if (isPresent === undefined) {
locations?.push({
type,
meta: [{ ...(loc?.meta?.[0] || {}), extension_uid: extUid }]
})
meta: [{ ...(loc?.meta?.[0] || {}), extension_uid: extUid }],
});
}
}
}
}
const configData = data?.ui_location?.locations?.find((ele: any) => ele?.type === 'cs.cm.stack.config');
const configData = data?.ui_location?.locations?.find(
(ele: any) => ele?.type === 'cs.cm.stack.config'
);
if (configData) {
locations?.push({
type: configData?.type,
meta: [{ ...(configData?.meta?.[0] || {}), name: 'Config', extension_uid: uuidv4() }]
})
meta: [
{
...(configData?.meta?.[0] || {}),
name: 'Config',
extension_uid: uuidv4(),
},
],
});
}
data.ui_location.locations = locations;
data.status = "installed";
data.status = 'installed';
data.target = {
"type": "stack",
"uid": destinationStackId
type: 'stack',
uid: destinationStackId,
};
data.installation_uid = data?.uid;
data.configuration = "";
data.server_configuration = "";
data.configuration = '';
data.server_configuration = '';
appManifest?.push(removeKeys(data, KEYTOREMOVE));
}
await writeManifestFile({ destinationStackId, appManifest });
}
}
};

export const marketPlaceAppService = {
createAppManifest
}
createAppManifest,
};
Loading