Skip to content

Commit ab8db4f

Browse files
authored
Merge pull request #1596 from contentstack/fix/DX-1513
fix: logger, custom attribute ref & error
2 parents 5a2e734 + e94f2dd commit ab8db4f

File tree

11 files changed

+59
-39
lines changed

11 files changed

+59
-39
lines changed

packages/contentstack-export/src/export/modules/marketplace-apps.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ export default class ExportMarketplaceApps {
138138
*/
139139
async getAppConfigurations(index: number, appInstallation: any) {
140140
const appName = appInstallation?.manifest?.name;
141-
log(this.exportConfig, `Exporting ${appName} app and it's config.`, 'info');
141+
const appUid = appInstallation?.manifest?.uid;
142+
const app = appName || appUid;
143+
log(this.exportConfig, `Exporting ${app} app and it's config.`, 'info');
142144

143145
await this.appSdk
144146
.marketplace(this.exportConfig.org_uid)
@@ -158,17 +160,17 @@ export default class ExportMarketplaceApps {
158160

159161
if (!isEmpty(data?.server_configuration)) {
160162
this.installedApps[index]['server_configuration'] = this.nodeCrypto.encrypt(data.server_configuration);
161-
log(this.exportConfig, `Exported ${appName} app and it's config.`, 'success');
163+
log(this.exportConfig, `Exported ${app} app and it's config.`, 'success');
162164
} else {
163-
log(this.exportConfig, `Exported ${appName} app`, 'success');
165+
log(this.exportConfig, `Exported ${app} app`, 'success');
164166
}
165167
} else if (error) {
166-
log(this.exportConfig, `Error on exporting ${appName} app and it's config.`, 'error');
168+
log(this.exportConfig, `Error on exporting ${app} app and it's config.`, 'error');
167169
log(this.exportConfig, error, 'error');
168170
}
169171
})
170172
.catch((error: any) => {
171-
log(this.exportConfig, `Failed to export ${appName} app config ${formatError(error)}`, 'error');
173+
log(this.exportConfig, `Failed to export ${app} app config ${formatError(error)}`, 'error');
172174
log(this.exportConfig, error, 'error');
173175
});
174176
}

packages/contentstack-export/src/export/modules/personalize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
AnyProperty,
88
} from '@contentstack/cli-variants';
99

10-
import { log, formatError } from '../../utils';
10+
import { log } from '../../utils';
1111
import { ModuleClassParams, ExportConfig } from '../../types';
1212

1313
export default class ExportPersonalize {

packages/contentstack-import/src/import/modules/marketplace-apps.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ export default class ImportMarketplaceApps {
438438
);
439439

440440
if (installation.installation_uid) {
441-
const appName = this.appNameMapping[app.manifest.name] ?? app.manifest.name;
441+
const appName = this.appNameMapping[app.manifest.name] || app.manifest.name || app.manifest.uid;
442442
log(this.importConfig, `${appName} app installed successfully.!`, 'success');
443443
await makeRedirectUrlCall(installation, appName, this.importConfig);
444444
this.installationUidMapping[app.uid] = installation.installation_uid;
@@ -448,7 +448,8 @@ export default class ImportMarketplaceApps {
448448
await confirmToCloseProcess(installation, this.importConfig);
449449
}
450450
} else if (!isEmpty(configuration) || !isEmpty(server_configuration)) {
451-
log(this.importConfig, `${app.manifest.name} is already installed`, 'success');
451+
const appName = app.manifest.name || app.manifest.uid;
452+
log(this.importConfig, `${appName} is already installed`, 'success');
452453
updateParam = await ifAppAlreadyExist(app, currentStackApp, this.importConfig);
453454
}
454455

@@ -481,7 +482,8 @@ export default class ImportMarketplaceApps {
481482
trace(data, 'error', true);
482483
log(this.importConfig, formatError(data.message), 'success');
483484
} else {
484-
log(this.importConfig, `${app.manifest.name} app config updated successfully.!`, 'success');
485+
const appName = app.manifest.name || app.manifest.uid;
486+
log(this.importConfig, `${appName} app config updated successfully.!`, 'success');
485487
}
486488
})
487489
.catch((error: any) => {

packages/contentstack-import/src/utils/entries-helper.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -548,11 +548,17 @@ export const restoreJsonRteEntryRefs = (
548548
});
549549
} else {
550550
entry[element.uid] = restoreReferenceInJsonRTE(sourceStackEntry[element.uid], uidMapper);
551-
entry[element.uid].children = entry[element.uid].children.map((child: any) => {
552-
child = setDirtyTrue(child);
553-
child = resolveAssetRefsInEntryRefsForJsonRte(child, mappedAssetUids, mappedAssetUrls);
554-
return child;
555-
});
551+
if (entry[element.uid].children && entry[element.uid].children.length > 0) {
552+
entry[element.uid].children = entry[element.uid].children.map((child: any) => {
553+
child = setDirtyTrue(child);
554+
child = resolveAssetRefsInEntryRefsForJsonRte(child, mappedAssetUids, mappedAssetUrls);
555+
return child;
556+
});
557+
} else {
558+
entry[element.uid].children = [
559+
{ type: 'p', attrs: { style: {}, 'redactor-attributes': {}, dir: 'ltr' } },
560+
];
561+
}
556562
}
557563
}
558564
break;

packages/contentstack-variants/src/import/project.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default class Project extends PersonalizationAdapter<ImportConfig> {
4646
description: project.description,
4747
connectedStackApiKey: this.config.apiKey,
4848
}).catch(async (error) => {
49-
if (error === 'personalization.PROJECTS.DUPLICATE_NAME' || error === 'personalize.PROJECTS.DUPLICATE_NAME') {
49+
if (error.includes('personalization.PROJECTS.DUPLICATE_NAME') || error.includes('personalize.PROJECTS.DUPLICATE_NAME')) {
5050
const projectName = await askProjectName('Copy Of ' + (newName || project.name));
5151
return await createProject(projectName);
5252
}

packages/contentstack-variants/src/import/variant-entries.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
368368
* @param variantEntry - The entry variant to update.
369369
*/
370370
updateFileFields(variantEntry: VariantEntryStruct) {
371-
const setValue = (currentObj: VariantEntryStruct, keys: Array<string>) => {
371+
const setValue = (currentObj: VariantEntryStruct, keys: string[]) => {
372372
if (!currentObj || keys.length === 0) return;
373373

374374
const [firstKey, ...restKeys] = keys;
@@ -380,21 +380,27 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
380380
} else if (currentObj && typeof currentObj === 'object') {
381381
if (firstKey in currentObj) {
382382
if (keys.length === 1) {
383-
currentObj[firstKey] = { uid: currentObj[firstKey], filename: 'dummy.jpeg' };
383+
// Check if the current property is already an object with uid and filename
384+
const existingValue = currentObj[firstKey];
385+
386+
if (existingValue && typeof existingValue === 'object' && existingValue.uid) {
387+
currentObj[firstKey] = { uid: existingValue.uid, filename: 'dummy.jpeg' };
388+
} else {
389+
currentObj[firstKey] = { uid: currentObj[firstKey], filename: 'dummy.jpeg' };
390+
}
384391
} else {
385392
setValue(currentObj[firstKey], restKeys);
386393
}
387394
}
388395
}
389396
};
390397

391-
const pathsToUpdate = variantEntry?._metadata?.references
392-
.filter((ref: any) => ref._content_type_uid === 'sys_assets')
393-
.map((ref: any) => ref.path);
398+
const pathsToUpdate =
399+
variantEntry?._metadata?.references
400+
?.filter((ref: any) => ref._content_type_uid === 'sys_assets')
401+
.map((ref: any) => ref.path) || [];
394402

395-
if (pathsToUpdate) {
396-
pathsToUpdate.forEach((path: string) => setValue(variantEntry, path.split('.')));
397-
}
403+
pathsToUpdate.forEach((path: string) => setValue(variantEntry, path.split('.')));
398404
}
399405

400406
/**
@@ -406,6 +412,11 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
406412
*/
407413
async publishVariantEntries(batch: VariantEntryStruct[], entryUid: string, content_type: string) {
408414
const allPromise = [];
415+
log(
416+
this.config,
417+
`Publishing variant entries for entry uid '${entryUid}' of Content Type '${content_type}'`,
418+
'info',
419+
);
409420
for (let [, variantEntry] of entries(batch)) {
410421
const variantEntryUID = variantEntry.uid;
411422
const oldVariantUid = variantEntry._variant._uid || '';
@@ -446,11 +457,9 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
446457
entry: {
447458
environments,
448459
locales,
449-
publish_with_base_entry: false,
450460
variants: [{ uid: newVariantUid, version: 1 }],
451461
},
452462
locale: variantEntry.locale,
453-
version: 1,
454463
};
455464

456465
const promise = this.variantInstance.publishVariantEntry(
@@ -470,6 +479,7 @@ export default class VariantEntries extends VariantAdapter<VariantHttpClient<Imp
470479
allPromise.push(promise);
471480
}
472481
await Promise.allSettled(allPromise);
482+
log(this.config, `Published variant entries for entry uid '${entryUid}' of Content Type '${content_type}'`, 'info');
473483
}
474484

475485
/**

packages/contentstack-variants/src/messages/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const expImportMsg = {
2323
UPDATING_CT_IN_EXP: 'Updating content types in experiences...',
2424
UPDATED_CT_IN_EXP: 'Successfully updated content types in experiences!',
2525
VALIDATE_VARIANT_AND_VARIANT_GRP: 'Validating variant group and variants creation...',
26-
PERSONALIZE_JOB_FAILURE: 'Something went wrong with personalize background job! Failed to fetch some variant & variant groups',
26+
PERSONALIZE_JOB_FAILURE: 'Something went wrong! Failed to fetch some variant and variant groups.',
2727
};
2828

2929
const messages: typeof errors & typeof commonMsg & typeof migrationMsg & typeof variantEntry & typeof expImportMsg = {

packages/contentstack-variants/src/types/variant-entry.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export type PublishVariantEntryDto = {
5050
entry: {
5151
environments: string[];
5252
locales: string[];
53-
publish_with_base_entry: boolean;
5453
variants: {
5554
uid: string;
5655
version?: number;

packages/contentstack-variants/src/utils/attributes-helper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export const lookUpAttributes = (attributeRules: Record<string, any>[], attribut
1212
// Check if attribute reference exists in attributesUid
1313
const attributeRef = rule.attribute?.ref;
1414
const attributeType = rule.attribute['__type'];
15-
// check if type is UserAttributeReference
16-
if (attributeType === 'UserAttributeReference') {
15+
// check if type is CustomAttributeReference
16+
if (attributeType === 'CustomAttributeReference') {
1717
if (attributeRef && attributesUid.hasOwnProperty(attributeRef) && attributesUid[attributeRef]) {
1818
rule.attribute.ref = attributesUid[attributeRef];
1919
} else {

packages/contentstack-variants/src/utils/error-helper.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ export function formatErrors(errors: any): string {
99
for (const errorKey in errors) {
1010
const errorValue = errors[errorKey];
1111
if (Array.isArray(errorValue)) {
12-
errorMessages.push(...errorValue.map((error: any) => formatError(error)));
12+
errorMessages.push(...errorValue.map((error: any) => formatError(errorKey, error)));
1313
} else {
14-
errorMessages.push(formatError(errorValue));
14+
errorMessages.push(formatError(errorKey, errorValue));
1515
}
1616
}
1717

1818
return errorMessages.join(' ');
1919
}
2020

21-
function formatError(error: any): string {
22-
if (typeof error === 'object') {
23-
return Object.values(error).join(' ');
21+
function formatError(errorKey: string, error: any): string {
22+
if (typeof error === 'object' && error !== null) {
23+
return `${errorKey}: ${Object.values(error).join(' ')}`;
2424
}
25-
return error;
25+
return `${errorKey}: ${error}`;
2626
}

0 commit comments

Comments
 (0)