diff --git a/packages/contentstack-export/src/export/modules/marketplace-apps.ts b/packages/contentstack-export/src/export/modules/marketplace-apps.ts index cc2a5b4e9c..ff34d2400f 100644 --- a/packages/contentstack-export/src/export/modules/marketplace-apps.ts +++ b/packages/contentstack-export/src/export/modules/marketplace-apps.ts @@ -138,7 +138,9 @@ export default class ExportMarketplaceApps { */ async getAppConfigurations(index: number, appInstallation: any) { const appName = appInstallation?.manifest?.name; - log(this.exportConfig, `Exporting ${appName} app and it's config.`, 'info'); + const appUid = appInstallation?.manifest?.uid; + const app = appName || appUid; + log(this.exportConfig, `Exporting ${app} app and it's config.`, 'info'); await this.appSdk .marketplace(this.exportConfig.org_uid) @@ -158,17 +160,17 @@ export default class ExportMarketplaceApps { if (!isEmpty(data?.server_configuration)) { this.installedApps[index]['server_configuration'] = this.nodeCrypto.encrypt(data.server_configuration); - log(this.exportConfig, `Exported ${appName} app and it's config.`, 'success'); + log(this.exportConfig, `Exported ${app} app and it's config.`, 'success'); } else { - log(this.exportConfig, `Exported ${appName} app`, 'success'); + log(this.exportConfig, `Exported ${app} app`, 'success'); } } else if (error) { - log(this.exportConfig, `Error on exporting ${appName} app and it's config.`, 'error'); + log(this.exportConfig, `Error on exporting ${app} app and it's config.`, 'error'); log(this.exportConfig, error, 'error'); } }) .catch((error: any) => { - log(this.exportConfig, `Failed to export ${appName} app config ${formatError(error)}`, 'error'); + log(this.exportConfig, `Failed to export ${app} app config ${formatError(error)}`, 'error'); log(this.exportConfig, error, 'error'); }); } diff --git a/packages/contentstack-export/src/export/modules/personalize.ts b/packages/contentstack-export/src/export/modules/personalize.ts index 45cff20807..6fa5f89b33 100644 --- a/packages/contentstack-export/src/export/modules/personalize.ts +++ b/packages/contentstack-export/src/export/modules/personalize.ts @@ -7,7 +7,7 @@ import { AnyProperty, } from '@contentstack/cli-variants'; -import { log, formatError } from '../../utils'; +import { log } from '../../utils'; import { ModuleClassParams, ExportConfig } from '../../types'; export default class ExportPersonalize { diff --git a/packages/contentstack-import/src/import/modules/marketplace-apps.ts b/packages/contentstack-import/src/import/modules/marketplace-apps.ts index 91a0d16341..f334807e92 100644 --- a/packages/contentstack-import/src/import/modules/marketplace-apps.ts +++ b/packages/contentstack-import/src/import/modules/marketplace-apps.ts @@ -438,7 +438,7 @@ export default class ImportMarketplaceApps { ); if (installation.installation_uid) { - const appName = this.appNameMapping[app.manifest.name] ?? app.manifest.name; + const appName = this.appNameMapping[app.manifest.name] || app.manifest.name || app.manifest.uid; log(this.importConfig, `${appName} app installed successfully.!`, 'success'); await makeRedirectUrlCall(installation, appName, this.importConfig); this.installationUidMapping[app.uid] = installation.installation_uid; @@ -448,7 +448,8 @@ export default class ImportMarketplaceApps { await confirmToCloseProcess(installation, this.importConfig); } } else if (!isEmpty(configuration) || !isEmpty(server_configuration)) { - log(this.importConfig, `${app.manifest.name} is already installed`, 'success'); + const appName = app.manifest.name || app.manifest.uid; + log(this.importConfig, `${appName} is already installed`, 'success'); updateParam = await ifAppAlreadyExist(app, currentStackApp, this.importConfig); } @@ -481,7 +482,8 @@ export default class ImportMarketplaceApps { trace(data, 'error', true); log(this.importConfig, formatError(data.message), 'success'); } else { - log(this.importConfig, `${app.manifest.name} app config updated successfully.!`, 'success'); + const appName = app.manifest.name || app.manifest.uid; + log(this.importConfig, `${appName} app config updated successfully.!`, 'success'); } }) .catch((error: any) => { diff --git a/packages/contentstack-import/src/utils/entries-helper.ts b/packages/contentstack-import/src/utils/entries-helper.ts index ac070662aa..503a540556 100644 --- a/packages/contentstack-import/src/utils/entries-helper.ts +++ b/packages/contentstack-import/src/utils/entries-helper.ts @@ -548,11 +548,17 @@ export const restoreJsonRteEntryRefs = ( }); } else { entry[element.uid] = restoreReferenceInJsonRTE(sourceStackEntry[element.uid], uidMapper); - entry[element.uid].children = entry[element.uid].children.map((child: any) => { - child = setDirtyTrue(child); - child = resolveAssetRefsInEntryRefsForJsonRte(child, mappedAssetUids, mappedAssetUrls); - return child; - }); + if (entry[element.uid].children && entry[element.uid].children.length > 0) { + entry[element.uid].children = entry[element.uid].children.map((child: any) => { + child = setDirtyTrue(child); + child = resolveAssetRefsInEntryRefsForJsonRte(child, mappedAssetUids, mappedAssetUrls); + return child; + }); + } else { + entry[element.uid].children = [ + { type: 'p', attrs: { style: {}, 'redactor-attributes': {}, dir: 'ltr' } }, + ]; + } } } break; diff --git a/packages/contentstack-variants/src/import/project.ts b/packages/contentstack-variants/src/import/project.ts index 0741785e49..8a98948486 100644 --- a/packages/contentstack-variants/src/import/project.ts +++ b/packages/contentstack-variants/src/import/project.ts @@ -46,7 +46,7 @@ export default class Project extends PersonalizationAdapter { description: project.description, connectedStackApiKey: this.config.apiKey, }).catch(async (error) => { - if (error === 'personalization.PROJECTS.DUPLICATE_NAME' || error === 'personalize.PROJECTS.DUPLICATE_NAME') { + if (error.includes('personalization.PROJECTS.DUPLICATE_NAME') || error.includes('personalize.PROJECTS.DUPLICATE_NAME')) { const projectName = await askProjectName('Copy Of ' + (newName || project.name)); return await createProject(projectName); } diff --git a/packages/contentstack-variants/src/import/variant-entries.ts b/packages/contentstack-variants/src/import/variant-entries.ts index c4f4c75176..f209c146e7 100644 --- a/packages/contentstack-variants/src/import/variant-entries.ts +++ b/packages/contentstack-variants/src/import/variant-entries.ts @@ -406,6 +406,7 @@ export default class VariantEntries extends VariantAdapter[], attribut // Check if attribute reference exists in attributesUid const attributeRef = rule.attribute?.ref; const attributeType = rule.attribute['__type']; - // check if type is UserAttributeReference - if (attributeType === 'UserAttributeReference') { + // check if type is CustomAttributeReference + if (attributeType === 'CustomAttributeReference') { if (attributeRef && attributesUid.hasOwnProperty(attributeRef) && attributesUid[attributeRef]) { rule.attribute.ref = attributesUid[attributeRef]; } else { diff --git a/packages/contentstack-variants/src/utils/error-helper.ts b/packages/contentstack-variants/src/utils/error-helper.ts index 58c087fbbc..7f01a7c2f7 100644 --- a/packages/contentstack-variants/src/utils/error-helper.ts +++ b/packages/contentstack-variants/src/utils/error-helper.ts @@ -9,18 +9,18 @@ export function formatErrors(errors: any): string { for (const errorKey in errors) { const errorValue = errors[errorKey]; if (Array.isArray(errorValue)) { - errorMessages.push(...errorValue.map((error: any) => formatError(error))); + errorMessages.push(...errorValue.map((error: any) => formatError(errorKey, error))); } else { - errorMessages.push(formatError(errorValue)); + errorMessages.push(formatError(errorKey, errorValue)); } } return errorMessages.join(' '); } -function formatError(error: any): string { - if (typeof error === 'object') { - return Object.values(error).join(' '); +function formatError(errorKey: string, error: any): string { + if (typeof error === 'object' && error !== null) { + return `${errorKey}: ${Object.values(error).join(' ')}`; } - return error; + return `${errorKey}: ${error}`; } diff --git a/packages/contentstack-variants/src/utils/logger.ts b/packages/contentstack-variants/src/utils/logger.ts index c1a2801cb3..2a21b13163 100644 --- a/packages/contentstack-variants/src/utils/logger.ts +++ b/packages/contentstack-variants/src/utils/logger.ts @@ -51,9 +51,9 @@ let errorLogger: winston.Logger; let successTransport; let errorTransport; -function init(_logPath: string) { +function init(_logPath: string, module: string) { if (!logger || !errorLogger) { - const logsDir = path.resolve(sanitizePath(_logPath), 'logs', 'export'); + const logsDir = path.resolve(sanitizePath(_logPath), 'logs', module); // Create dir if doesn't already exist mkdirp.sync(logsDir); @@ -131,11 +131,12 @@ function init(_logPath: string) { export const log = (config: ExportConfig | ImportConfig, message: any, type: 'info' | 'error' | 'success') => { const logsPath = config.data; // ignoring the type argument, as we are not using it to create a logfile anymore + const module = (config as ImportConfig)['backupDir'] ? 'import' : 'export'; if (type !== 'error') { // removed type argument from init method - init(logsPath).log(message); + init(logsPath, module).log(message); } else { - init(logsPath).error(message); + init(logsPath, module).error(message); } };