Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge staging to development #1209

Merged
merged 30 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
bf3b4e9
fix html rte
Aug 9, 2023
c0e0d1b
merged latest
Aug 9, 2023
96ee8c3
merged latest
shafeeqd959 Dec 6, 2023
0a30a1e
bumped version
shafeeqd959 Dec 4, 2023
bdae538
Merge pull request #1187 from contentstack/fix/CS-42696
shafeeqd959 Nov 29, 2023
b40b691
updated lock and readme files
shafeeqd959 Dec 6, 2023
fbd4f80
fixed ts config import
shafeeqd959 Dec 6, 2023
c576130
bumped oclif plugins dependency to 4.1.9 to fix vulnerabilities repor…
shafeeqd959 Dec 6, 2023
18f86cd
bumped cli version
shafeeqd959 Dec 7, 2023
140a8b4
Fix: Entry import fails if JSON RTE has a reference inside the table,…
antonyagustine Dec 7, 2023
c938306
fix: vulnerabilities fix
antonyagustine Dec 7, 2023
5c8e873
Fix: Extension code change reverted
antonyagustine Dec 7, 2023
8927c31
Fix: Replace reference issue related fix
antonyagustine Dec 7, 2023
19bd303
Fix: Reference mapper fixes on json rte
antonyagustine Dec 7, 2023
ba58d56
Fix: Missing uid mapper added
antonyagustine Dec 8, 2023
cb2d340
Code clean
antonyagustine Dec 8, 2023
f77f81c
Code clean
antonyagustine Dec 8, 2023
0280b1a
Fix: Cannot read properties of undefined (reading 'type')
antonyagustine Dec 8, 2023
b89afb9
fix: handle entry deleted from compare branch condition
aman19K Dec 8, 2023
0c81f89
Version bump
antonyagustine Dec 8, 2023
2b68c03
Merge branch 'release/hotfix-CS-42696' into fix/CS-42996
antonyagustine Dec 8, 2023
13e63d2
Doc: Readme updated
antonyagustine Dec 8, 2023
719e397
Merge pull request #1205 from contentstack/fix/CS-42996
antonyagustine Dec 8, 2023
dfd4edd
Merge branch 'release/hotfix-CS-42696' into fix/CS-42677
aman19K Dec 8, 2023
8d7cd4c
Merge pull request #1206 from contentstack/fix/CS-42677
aman19K Dec 8, 2023
75cc053
Merge pull request #1204 from contentstack/release/hotfix-CS-42696
aman19K Dec 11, 2023
472377e
Merge branch 'main' into main-to-staging
aman19K Dec 11, 2023
303b0f7
Merge pull request #1208 from contentstack/main-to-staging
aman19K Dec 11, 2023
a0d0629
Merge branch 'staging' into staging-to-dev
aman19K Dec 11, 2023
03b727f
updated pnpm lock file
aman19K Dec 11, 2023
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
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/contentstack-branches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-branches
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-branches/1.0.18 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-branches/1.0.19 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-branches/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-branches",
"description": "Contentstack CLI plugin to do branches operations",
"version": "1.0.18",
"version": "1.0.19",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
18 changes: 10 additions & 8 deletions packages/contentstack-branches/src/utils/entry-create-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,15 +475,17 @@ export function entryCreateScript(contentType) {
try {
compareFilteredProperties.length !== 0 &&
compareFilteredProperties.forEach(async (entryDetails) => {
entryDetails = updateAssetDetailsInEntries(entryDetails);
let createdEntry = await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails }).catch(error => {
throw error;
});
if(createdEntry){
if (flag.references) {
await updateReferences(entryDetails, createdEntry, references);
if(entryDetails !== undefined){
entryDetails = updateAssetDetailsInEntries(entryDetails);
let createdEntry = await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails }).catch(error => {
throw error;
});
if(createdEntry){
if (flag.references) {
await updateReferences(entryDetails, createdEntry, references);
}
await updateEntry(createdEntry, entryDetails);
}
await updateEntry(createdEntry, entryDetails);
}
});
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,56 +494,70 @@ export function entryCreateUpdateScript(contentType) {
}

try {
if (contentType.options.singleton) {
compareBranchEntries.items.map(async (el) => {
if (contentType?.options?.singleton) {
compareBranchEntries?.items?.map(async (el) => {
let entryDetails = deleteUnwantedKeysFromObject(el, keysToRemove);
entryDetails = updateAssetDetailsInEntries(entryDetails);

if (baseBranchEntries && baseBranchEntries.items.length) {
let baseEntryUid = baseBranchEntries.items[0].uid;
let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntryUid);
if(entryDetails !== undefined){
entryDetails = updateAssetDetailsInEntries(entryDetails);

if (baseBranchEntries && baseBranchEntries.items.length) {
let baseEntryUid = baseBranchEntries.items[0].uid;
let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntryUid);

if (flag.references) {
await updateReferences(entryDetails, baseBranchEntries.items[0], references);
}

await updateEntry(entry, entryDetails);
} else {
let createdEntry = await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails });

if (flag.references) {
await updateReferences(entryDetails, baseBranchEntries.items[0], references);
}

await updateEntry(entry, entryDetails);
} else {
let createdEntry = await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails });

if (flag.references) {
await updateReferences(entryDetails, createdEntry, references);
if (flag.references) {
await updateReferences(entryDetails, createdEntry, references);
}

await updateEntry(createdEntry, entryDetails);
}

await updateEntry(createdEntry, entryDetails);
}
});
} else {
let compareMap = new Map(converter(compareBranchEntries.items));
let baseMap = new Map(converter(baseBranchEntries.items));


//NOTE: Filter distinct entries from the base and compare branches according to their titles.
//TODO: Need to discuss this approach and replace it with uid condition
let arr = uniquelyConcatenateArrays(Array.from(compareMap.keys()), Array.from(baseMap.keys()));

arr.map(async (el) => {
let entryDetails = deleteUnwantedKeysFromObject(compareMap.get(el), keysToRemove);
entryDetails = updateAssetDetailsInEntries(entryDetails);
if (compareMap.get(el) && !baseMap.get(el)) {
let createdEntry = await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails });

if (flag.references) {
await updateReferences(entryDetails, createdEntry, references);
}
//NOTE: In the compare branch, entry must exist. Condition of deleted entry not handled
if(entryDetails !== undefined){
entryDetails = updateAssetDetailsInEntries(entryDetails);
if (compareMap.get(el) && !baseMap.get(el)) {
let createdEntry = await stackSDKInstance
.contentType('${contentType}')
.entry()
.create({ entry: entryDetails })
.catch(err => {
(err?.errorMessage || err?.message) ? err?.errorMessage || err?.message : 'Something went wrong!'
})

if(createdEntry){
if (flag.references) {
await updateReferences(entryDetails, createdEntry, references);
}
await updateEntry(createdEntry, entryDetails);
}
} else if (compareMap.get(el) && baseMap.get(el)) {
let baseEntry = baseMap.get(el);
let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntry.uid);

if (flag.references) {
await updateReferences(entryDetails, baseEntry, references);
}

await updateEntry(createdEntry, entryDetails);
} else if (compareMap.get(el) && baseMap.get(el)) {
let baseEntry = baseMap.get(el);
let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntry.uid);

if (flag.references) {
await updateReferences(entryDetails, baseEntry, references);
await updateEntry(entry, entryDetails);
}

await updateEntry(entry, entryDetails);
}
});
}
Expand Down
86 changes: 50 additions & 36 deletions packages/contentstack-branches/src/utils/entry-update-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,56 +491,70 @@ export function entryUpdateScript(contentType) {
}

try {
if (contentType.options.singleton) {
compareBranchEntries.items.map(async (el) => {
if (contentType?.options?.singleton) {
compareBranchEntries?.items?.map(async (el) => {
let entryDetails = deleteUnwantedKeysFromObject(el, keysToRemove);
entryDetails = updateAssetDetailsInEntries(entryDetails);

if (baseBranchEntries && baseBranchEntries.items.length) {
let baseEntryUid = baseBranchEntries.items[0].uid;
let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntryUid);
if(entryDetails !== undefined){
entryDetails = updateAssetDetailsInEntries(entryDetails);
if (baseBranchEntries && baseBranchEntries.items.length) {
let baseEntryUid = baseBranchEntries.items[0].uid;
let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntryUid);

if (flag.references) {
await updateReferences(entryDetails, baseBranchEntries.items[0], references);
}

await updateEntry(entry, entryDetails);
} else {
let createdEntry = await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails });

if (flag.references) {
await updateReferences(entryDetails, baseBranchEntries.items[0], references);
if (flag.references) {
await updateReferences(entryDetails, createdEntry, references);
}

await updateEntry(createdEntry, entryDetails);
}

await updateEntry(entry, entryDetails);
} else {
let createdEntry = await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails });

if (flag.references) {
await updateReferences(entryDetails, createdEntry, references);
}

await updateEntry(createdEntry, entryDetails);
}
});
} else {
let compareMap = new Map(converter(compareBranchEntries.items));
let baseMap = new Map(converter(baseBranchEntries.items));


//NOTE: Filter distinct entries from the base and compare branches according to their titles.
//TODO: Need to discuss this approach and replace it with uid approach
let arr = uniquelyConcatenateArrays(Array.from(compareMap.keys()), Array.from(baseMap.keys()));

arr.map(async (el) => {
let entryDetails = deleteUnwantedKeysFromObject(compareMap.get(el), keysToRemove);
entryDetails = updateAssetDetailsInEntries(entryDetails);
if (compareMap.get(el) && !baseMap.get(el)) {
let createdEntry = await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails });

if (flag.references) {
await updateReferences(entryDetails, createdEntry, references);
}

await updateEntry(createdEntry, entryDetails);
} else if (compareMap.get(el) && baseMap.get(el)) {
let baseEntry = baseMap.get(el);
let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntry.uid);
//NOTE: In the compare branch, entry must exist. Condition of deleted entry not handled
if(entryDetails !== undefined){
entryDetails = updateAssetDetailsInEntries(entryDetails);
if (compareMap.get(el) && !baseMap.get(el)) {
let createdEntry = await stackSDKInstance
.contentType('${contentType}')
.entry()
.create({ entry: entryDetails })
.catch(err => {
(err?.errorMessage || err?.message) ? err?.errorMessage || err?.message : 'Something went wrong!'
})

if (flag.references) {
await updateReferences(entryDetails, baseEntry, references);
if(createdEntry){
if (flag.references) {
await updateReferences(entryDetails, createdEntry, references);
}

await updateEntry(createdEntry, entryDetails);
}
} else if (compareMap.get(el) && baseMap.get(el)) {
let baseEntry = baseMap.get(el);
let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntry.uid);

if (flag.references) {
await updateReferences(entryDetails, baseEntry, references);
}

await updateEntry(entry, entryDetails);
}

await updateEntry(entry, entryDetails);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ export default class ImportCommand extends Command {
'success',
);
} catch (error) {
trace(error, 'error', true);
log({ data: backupDir } as ImportConfig, `Failed to import stack content - ${formatError(error)}`, 'error');
log(
{ data: backupDir } as ImportConfig,
Expand Down
16 changes: 8 additions & 8 deletions packages/contentstack-import/src/import/modules/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import * as path from 'path';
import { isEmpty, values, cloneDeep, find, indexOf, forEach } from 'lodash';
import { ContentType, FsUtility } from '@contentstack/cli-utilities';
import { FsUtility } from '@contentstack/cli-utilities';
import {
fsUtil,
log,
Expand Down Expand Up @@ -125,7 +125,7 @@ export default class EntriesImport extends BaseClass {
await fileHelper.writeLargeFile(path.join(this.entriesMapperPath, 'uid-mapping.json'), this.entriesUidMapper); // TBD: manages mapper in one file, should find an alternative
fsUtil.writeFile(path.join(this.entriesMapperPath, 'failed-entries.json'), this.failedEntries);

if (this.autoCreatedEntries.length > 0) {
if (this.autoCreatedEntries?.length > 0) {
log(this.importConfig, 'Removing entries from master language which got created by default', 'info');
await this.removeAutoCreatedEntries().catch((error) => {
log(
Expand Down Expand Up @@ -528,8 +528,7 @@ export default class EntriesImport extends BaseClass {

async replaceEntriesHandler({
apiParams,
element: entry,
isLastRequest,
element: entry
}: {
apiParams: ApiOptions;
element: Record<string, string>;
Expand Down Expand Up @@ -672,6 +671,7 @@ export default class EntriesImport extends BaseClass {
if (this.jsonRteCTs.indexOf(cTUid) > -1) {
// the entries stored in eSuccessFilePath, have the same uids as the entries from source data
entry = restoreJsonRteEntryRefs(entry, sourceEntry, contentType.schema, {
uidMapper: this.entriesUidMapper,
mappedAssetUids: this.assetUidMapper,
mappedAssetUrls: this.assetUrlMapper,
});
Expand Down Expand Up @@ -785,13 +785,13 @@ export default class EntriesImport extends BaseClass {
const contentType: any = find(cTs, { uid: cTUid });
if (contentType.field_rules) {
const fieldDatatypeMap: { [key: string]: string } = {};
for (let i = 0; i < contentType.schema.length; i++) {
for (let i = 0; i < contentType.schema?.length; i++) {
const field = contentType.schema[i].uid;
fieldDatatypeMap[field] = contentType.schema[i].data_type;
}
let fieldRuleLength = contentType.field_rules.length;
let fieldRuleLength = contentType.field_rules?.length;
for (let k = 0; k < fieldRuleLength; k++) {
let fieldRuleConditionLength = contentType.field_rules[k].conditions.length;
let fieldRuleConditionLength = contentType.field_rules[k].conditions?.length;
for (let i = 0; i < fieldRuleConditionLength; i++) {
if (fieldDatatypeMap[contentType.field_rules[k].conditions[i].operand_field] === 'reference') {
let fieldRulesValue = contentType.field_rules[k].conditions[i].value;
Expand Down Expand Up @@ -905,7 +905,7 @@ export default class EntriesImport extends BaseClass {
locales: [],
entryUid: this.entriesUidMapper[entry.uid],
};
if (entry.publish_details && entry.publish_details.length > 0) {
if (entry.publish_details && entry.publish_details?.length > 0) {
forEach(entry.publish_details, (pubObject) => {
if (
this.envs.hasOwnProperty(pubObject.environment) &&
Expand Down
9 changes: 9 additions & 0 deletions packages/contentstack-import/src/types/entries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type EntryJsonRTEFieldDataType = {
uid?: string;
type?: string;
text?: string;
attrs?: { 'entry-uid'?: string; type?: string } & Record<string, any>;
children?: EntryJsonRTEFieldDataType[];
};

export { EntryJsonRTEFieldDataType };
2 changes: 2 additions & 0 deletions packages/contentstack-import/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,6 @@ export interface TermsConfig{

export { default as DefaultConfig } from './default-config';
export { default as ImportConfig } from './import-config';

export * from './entries'
export * from './marketplace-app'
Loading
Loading