Skip to content

Commit eddb63d

Browse files
Merge pull request #2297 from contentstack/fix/backmerge-v2-beta
Fix/backmerge v2 beta
2 parents ffa47e7 + 0c19677 commit eddb63d

File tree

21 files changed

+2010
-2021
lines changed

21 files changed

+2010
-2021
lines changed

.talismanrc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
fileignoreconfig:
22
- filename: package-lock.json
3-
checksum: 40f1c53aad40a1f8d711c5ccdde7d1c147d371618c237e1fec2d313af51edb97
3+
checksum: 6620ee3246617a534609c92b66dd982860a8f4ebb69a0c7e89570c6d92014259
44
- filename: pnpm-lock.yaml
5-
checksum: aa6177859aaa87caf2892e8034657fd485c3abe7c13a833fd28449a1d33fa950
5+
checksum: 457cb87e68a8bcbf490116e05d39272a5da442e3f06d9f23b47b646b924ffe9a
6+
- filename: packages/contentstack-bulk-publish/src/producer/add-fields.js
7+
checksum: 3e70b11978fc5f29a6a6c90b725c28c9df8d15bcc6fd74e2253fca23a3630160
68
- filename: packages/contentstack-import-setup/test/unit/backup-handler.test.ts
79
checksum: 0582d62b88834554cf12951c8690a73ef3ddbb78b82d2804d994cf4148e1ef93
810
- filename: packages/contentstack-import-setup/test/config.json

package-lock.json

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

packages/contentstack-audit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/cli-audit",
3-
"version": "2.0.0-beta.0",
3+
"version": "2.0.0-beta",
44
"description": "Contentstack audit plugin",
55
"author": "Contentstack CLI",
66
"homepage": "https://github.com/contentstack/cli",

packages/contentstack-bootstrap/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"test:report": "nyc --reporter=lcov mocha \"test/**/*.test.js\""
1717
},
1818
"dependencies": {
19-
"@contentstack/cli-cm-seed": "~2.0.0-beta.2",
19+
"@contentstack/cli-cm-seed": "~2.0.0-beta.3",
2020
"@contentstack/cli-command": "~1.7.0",
2121
"@contentstack/cli-utilities": "~1.15.0",
2222
"@oclif/core": "^4.3.0",

packages/contentstack-bulk-publish/src/consumer/publish.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,19 @@ function removePublishDetails(elements) {
3535
function displayEntriesDetails(sanitizedData, action, mapping = []) {
3636
if (action === 'bulk_publish') {
3737
sanitizedData.forEach((entry) => {
38-
entry?.publish_details.forEach((pd) => {
39-
if (Object.keys(mapping).includes(pd.environment)) {
38+
if (Array.isArray(entry?.publish_details) && entry.publish_details.length > 0) {
39+
const matchingPublishDetails = entry.publish_details.filter((pd) =>
40+
Object.keys(mapping).includes(pd.environment)
41+
);
42+
if (matchingPublishDetails.length > 0) {
43+
const pd = matchingPublishDetails[0];
4044
console.log(
4145
chalk.green(
4246
`Entry UID: '${entry.uid}', Content Type: '${entry.content_type}', Locale: '${entry.locale}', Version: '${pd.version}', Environment: '${pd.environment}'`,
4347
),
44-
)
48+
);
4549
}
46-
});
47-
if(!Array.isArray(entry.publish_details)){
50+
} else if (!Array.isArray(entry.publish_details)) {
4851
console.log(chalk.green(`Entry UID: '${entry.uid}', Content Type: '${entry.content_type}', Locale: '${entry.locale}'`));
4952
}
5053
});

packages/contentstack-bulk-publish/src/producer/add-fields.js

Lines changed: 149 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,124 @@ function removeUnwanted(entry, unwantedkeys) {
6262
return entry;
6363
}
6464

65+
function isLinkObject(obj, keyName) {
66+
if (obj === null || typeof obj !== 'object' || Array.isArray(obj)) {
67+
return false;
68+
}
69+
70+
const linkKeyNames = ['link', 'card_link'];
71+
if (linkKeyNames.includes(keyName)) {
72+
return true;
73+
}
74+
75+
const hasTitle = 'title' in obj && obj.title !== undefined;
76+
const hasUrl = 'url' in obj && obj.url !== undefined;
77+
const hasHref = 'href' in obj && obj.href !== undefined;
78+
79+
return hasTitle && (hasUrl || hasHref);
80+
}
81+
82+
function ensureHrefIsString(linkObj) {
83+
if (linkObj.href === undefined || linkObj.href === null) {
84+
linkObj.href = '';
85+
} else if (typeof linkObj.href !== 'string') {
86+
linkObj.href = String(linkObj.href);
87+
}
88+
}
89+
90+
function isValidJsonRte(obj) {
91+
return obj !== null &&
92+
typeof obj === 'object' &&
93+
!Array.isArray(obj) &&
94+
typeof obj.type === 'string' &&
95+
obj.type !== '';
96+
}
97+
98+
function cleanJsonFields(obj) {
99+
if (obj === null || obj === undefined || typeof obj !== 'object') {
100+
return obj;
101+
}
102+
103+
if (Array.isArray(obj)) {
104+
return obj.map((item) => cleanJsonFields(item));
105+
}
106+
107+
const cleaned = {};
108+
for (const key in obj) {
109+
if (!obj.hasOwnProperty(key)) {
110+
continue;
111+
}
112+
let value = obj[key];
113+
const isJsonField = key.endsWith('_rte') || key === 'json_rte';
114+
const isAccessibilityField = key.endsWith('_accessibility') || key === 'image_preset_accessibility';
115+
116+
if (isJsonField) {
117+
if (value === '' || value === null || value === undefined) {
118+
continue;
119+
}
120+
if (typeof value === 'object' && !Array.isArray(value)) {
121+
const keyCount = Object.keys(value).length;
122+
if (keyCount === 0) {
123+
continue;
124+
}
125+
if (!isValidJsonRte(value)) {
126+
continue;
127+
}
128+
cleaned[key] = value;
129+
} else {
130+
continue;
131+
}
132+
} else if (isAccessibilityField && value === '') {
133+
cleaned[key] = {};
134+
} else if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
135+
value = cleanJsonFields(value);
136+
if (value !== null && typeof value === 'object') {
137+
cleaned[key] = value;
138+
}
139+
} else {
140+
cleaned[key] = value;
141+
}
142+
}
143+
return cleaned;
144+
}
145+
146+
function convertUrlToHref(obj) {
147+
if (obj === null || obj === undefined) {
148+
return obj;
149+
}
150+
151+
if (Array.isArray(obj)) {
152+
return obj.map((item) => convertUrlToHref(item));
153+
}
154+
155+
if (typeof obj === 'object') {
156+
const converted = {};
157+
for (const key in obj) {
158+
const value = obj[key];
159+
160+
if (isLinkObject(value, key)) {
161+
converted[key] = { ...value };
162+
if (converted[key].url !== undefined && converted[key].href === undefined) {
163+
if (typeof converted[key].url === 'string') {
164+
converted[key].href = converted[key].url;
165+
} else if (converted[key].url === null || converted[key].url === undefined) {
166+
converted[key].href = '';
167+
} else {
168+
converted[key].href = String(converted[key].url);
169+
}
170+
delete converted[key].url;
171+
}
172+
ensureHrefIsString(converted[key]);
173+
} else {
174+
converted[key] = convertUrlToHref(value);
175+
}
176+
}
177+
return converted;
178+
}
179+
180+
return obj;
181+
}
182+
65183
function fileFields(entry, uid, multiple) {
66184
if (entry[uid]) {
67185
if (typeof entry[uid] === 'object' || Array.isArray(entry[uid])) {
@@ -106,6 +224,11 @@ function addFields(contentType, entry) {
106224
}
107225
} else if (schema.enum) {
108226
entry[schema.uid] = null;
227+
} else if (schema.data_type === 'json') {
228+
const isJsonRteField = schema.uid && (schema.uid.endsWith('_rte') || schema.uid === 'json_rte');
229+
if (!isJsonRteField) {
230+
entry[schema.uid] = {};
231+
}
109232
} else if (Object.prototype.hasOwnProperty.call(defaults, schema.data_type)) {
110233
entry[schema.uid] = defaults[schema.data_type];
111234
} else {
@@ -126,19 +249,31 @@ function addFields(contentType, entry) {
126249

127250
if (schema.data_type === 'group' && !schema.multiple) {
128251
addFields(schema.schema, entry[schema.uid]);
252+
if (entry[schema.uid]) {
253+
entry[schema.uid] = convertUrlToHref(entry[schema.uid]);
254+
}
129255
}
130256
if (schema.data_type === 'group' && schema.multiple) {
131257
entry[schema.uid].forEach((field) => {
132258
addFields(schema.schema, field);
133259
});
260+
if (entry[schema.uid]) {
261+
entry[schema.uid] = convertUrlToHref(entry[schema.uid]);
262+
}
134263
}
135264
if (schema.data_type === 'global_field' && !schema.multiple) {
136265
addFields(schema.schema, entry[schema.uid]);
266+
if (entry[schema.uid]) {
267+
entry[schema.uid] = convertUrlToHref(entry[schema.uid]);
268+
}
137269
}
138270
if (schema.data_type === 'global_field' && schema.multiple) {
139271
entry[schema.uid].forEach((field) => {
140272
addFields(schema.schema, field);
141273
});
274+
if (entry[schema.uid]) {
275+
entry[schema.uid] = convertUrlToHref(entry[schema.uid]);
276+
}
142277
}
143278
if (schema.data_type === 'blocks') {
144279
if (!entry[schema.uid] && !Array.isArray(entry[schema.uid])) {
@@ -156,6 +291,9 @@ function addFields(contentType, entry) {
156291
if (filterBlockFields.length > 0) {
157292
filterBlockFields.forEach((bfield) => {
158293
addFields(block.schema, bfield[block.uid]);
294+
if (bfield[block.uid]) {
295+
bfield[block.uid] = convertUrlToHref(bfield[block.uid]);
296+
}
159297
});
160298
} else {
161299
entry[schema.uid].push({ [block.uid]: {} });
@@ -169,6 +307,9 @@ function addFields(contentType, entry) {
169307
if (filterBlockFields.length > 0) {
170308
filterBlockFields.forEach((bfield) => {
171309
addFields(block.schema, bfield[block.uid]);
310+
if (bfield[block.uid]) {
311+
bfield[block.uid] = convertUrlToHref(bfield[block.uid]);
312+
}
172313
});
173314
}
174315
}
@@ -221,8 +362,14 @@ async function getEntries(
221362
for (let index = 0; index < entriesResponse.items.length; index++) {
222363
let updatedEntry = addFields(schema, entries[index]);
223364
if (updatedEntry.changedFlag || forceUpdate) {
224-
updatedEntry = removeUnwanted(entries[index], deleteFields);
225-
const flag = await updateEntry(updatedEntry, locale);
365+
let entryData = JSON.parse(JSON.stringify(updatedEntry.entry));
366+
entryData = removeUnwanted(entryData, deleteFields);
367+
entryData = cleanJsonFields(entryData);
368+
entryData = convertUrlToHref(entryData);
369+
entryData = cleanJsonFields(entryData);
370+
const entry = stack.contentType(contentType).entry(entries[index].uid);
371+
Object.assign(entry, entryData);
372+
const flag = await updateEntry(entry, locale);
226373
if (flag) {
227374
if (bulkPublish) {
228375
if (bulkPublishSet.length < bulkPublishLimit) {
@@ -353,8 +500,6 @@ async function start(
353500
}
354501
}
355502

356-
// start()
357-
358503
module.exports = {
359504
start,
360505
getContentTypeSchema,

packages/contentstack-clone/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "@contentstack/cli-cm-clone",
33
"description": "Contentstack stack clone plugin",
4-
"version": "2.0.0-beta.2",
4+
"version": "2.0.0-beta.3",
55
"author": "Contentstack",
66
"bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues",
77
"dependencies": {
88
"@colors/colors": "^1.6.0",
9-
"@contentstack/cli-cm-export": "~2.0.0-beta.2",
10-
"@contentstack/cli-cm-import": "~2.0.0-beta.2",
9+
"@contentstack/cli-cm-export": "~2.0.0-beta.3",
10+
"@contentstack/cli-cm-import": "~2.0.0-beta.3",
1111
"@contentstack/cli-command": "~1.7.0",
1212
"@contentstack/cli-utilities": "~1.15.0",
1313
"@oclif/core": "^4.3.0",

packages/contentstack-config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@contentstack/cli-config",
33
"description": "Contentstack CLI plugin for configuration",
4-
"version": "1.16.0",
4+
"version": "1.16.1",
55
"author": "Contentstack",
66
"scripts": {
77
"build": "npm run clean && npm run compile",

packages/contentstack-config/src/commands/config/set/region.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ export default class RegionSetCommand extends BaseCommand<typeof RegionSetComman
4848
launch: _flags.string({
4949
description: 'Custom host to set for Launch API',
5050
}),
51-
'composable-studio': _flags.string({
52-
description: 'Custom host to set for Composable Studio API',
51+
studio: _flags.string({
52+
description: 'Custom host to set for Studio API',
5353
}),
5454
};
5555
static examples = [
@@ -65,8 +65,8 @@ export default class RegionSetCommand extends BaseCommand<typeof RegionSetComman
6565
'$ csdx config:set:region --cma <custom_cma_host_url> --cda <custom_cda_host_url> --ui-host <custom_ui_host_url> --name "India" --developer-hub <custom_developer_hub_url>',
6666
'$ csdx config:set:region --cma <custom_cma_host_url> --cda <custom_cda_host_url> --ui-host <custom_ui_host_url> --name "India" --personalize <custom_personalize_url>',
6767
'$ csdx config:set:region --cma <custom_cma_host_url> --cda <custom_cda_host_url> --ui-host <custom_ui_host_url> --name "India" --launch <custom_launch_url>',
68-
'$ csdx config:set:region --cma <custom_cma_host_url> --cda <custom_cda_host_url> --ui-host <custom_ui_host_url> --name "India" --composable-studio <custom_composable_studio_url>',
69-
'$ csdx config:set:region --cda <custom_cda_host_url> --cma <custom_cma_host_url> --ui-host <custom_ui_host_url> --name "India" --developer-hub <custom_developer_hub_url> --launch <custom_launch_url> --personalize <custom_personalize_url> --composable-studio <custom_composable_studio_url>',
68+
'$ csdx config:set:region --cma <custom_cma_host_url> --cda <custom_cda_host_url> --ui-host <custom_ui_host_url> --name "India" --studio <custom_studio_url>',
69+
'$ csdx config:set:region --cda <custom_cda_host_url> --cma <custom_cma_host_url> --ui-host <custom_ui_host_url> --name "India" --developer-hub <custom_developer_hub_url> --launch <custom_launch_url> --personalize <custom_personalize_url> --studio <custom_studio_url>',
7070
];
7171

7272
static args: ArgInput = {
@@ -82,7 +82,7 @@ export default class RegionSetCommand extends BaseCommand<typeof RegionSetComman
8282
let developerHubUrl = regionSetFlags['developer-hub'];
8383
let personalizeUrl = regionSetFlags['personalize'];
8484
let launchHubUrl = regionSetFlags['launch'];
85-
let composableStudioUrl = regionSetFlags['composable-studio'];
85+
let composableStudioUrl = regionSetFlags['studio'];
8686
let selectedRegion = args.region;
8787
if (!(cda && cma && uiHost && name) && !selectedRegion) {
8888
selectedRegion = await interactive.askRegions();
@@ -132,7 +132,7 @@ export default class RegionSetCommand extends BaseCommand<typeof RegionSetComman
132132
cliux.success(`Developer Hub URL: ${customRegion.developerHubUrl}`);
133133
cliux.success(`Personalize URL: ${customRegion.personalizeUrl}`);
134134
cliux.success(`Launch URL: ${customRegion.launchHubUrl}`);
135-
cliux.success(`Composable Studio URL: ${customRegion.composableStudioUrl}`);
135+
cliux.success(`Studio URL: ${customRegion.composableStudioUrl}`);
136136
} catch (error) {
137137
this.logger.error('failed to set the region', error);
138138
cliux.error(`Failed to set region due to: ${error.message}`);
@@ -151,7 +151,7 @@ export default class RegionSetCommand extends BaseCommand<typeof RegionSetComman
151151
cliux.success(`Developer Hub URL: ${regionDetails.developerHubUrl}`);
152152
cliux.success(`Personalize URL: ${regionDetails.personalizeUrl}`);
153153
cliux.success(`Launch URL: ${regionDetails.launchHubUrl}`);
154-
cliux.success(`Composable Studio URL: ${regionDetails.composableStudioUrl}`);
154+
cliux.success(`Studio URL: ${regionDetails.composableStudioUrl}`);
155155
} else {
156156
cliux.error(`Invalid region specified.`);
157157
}

packages/contentstack-config/test/unit/commands/region.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ describe('Region command', function () {
274274
expect(result.launchHubUrl).to.equal(customRegion.launchHubUrl);
275275
});
276276

277-
it('should set a custom region with composable studio URL', function () {
277+
it('should set a custom region with studio URL', function () {
278278
const customRegion = {
279279
cma: 'https://custom-cma.com',
280280
cda: 'https://custom-cda.com',

0 commit comments

Comments
 (0)