From 9671e4ead0a707055d9fdcb94fb13215b4854fa0 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Thu, 13 Jul 2023 19:15:31 +0530 Subject: [PATCH 01/24] Modified workflows to use the latest version of the github actions --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/jira.yml | 2 +- .github/workflows/release.yml | 50 ++++++++++++--------------- .github/workflows/sast-scan.yml | 2 +- .github/workflows/sca-scan.yml | 4 +-- .github/workflows/secrets-scan.yml | 2 +- 6 files changed, 29 insertions(+), 33 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 3566f965ec..ef4bb176cc 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -34,7 +34,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v3.5.3 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/jira.yml b/.github/workflows/jira.yml index 5ddf87a65c..c4f9d9f575 100644 --- a/.github/workflows/jira.yml +++ b/.github/workflows/jira.yml @@ -7,7 +7,7 @@ jobs: if: ${{ github.actor == 'dependabot[bot]' || github.actor == 'snyk-bot' || contains(github.event.pull_request.head.ref, 'snyk-fix-') || contains(github.event.pull_request.head.ref, 'snyk-upgrade-')}} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3.5.3 - name: Login into JIRA uses: atlassian/gajira-login@master env: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 962a304c9b..5a9c8e7ac6 100755 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,11 +8,11 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: pnpm/action-setup@v2 + - uses: actions/checkout@v3.5.3 + - uses: pnpm/action-setup@v2.2.4 with: version: 7 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v3.7.0 with: node-version: '18.x' cache: 'pnpm' @@ -32,7 +32,7 @@ jobs: working-directory: ./packages/contentstack-dev-dependencies run: npm run prepack - name: Publishing dev dependencies - uses: JS-DevTools/npm-publish@v1 + uses: JS-DevTools/npm-publish@v2.2.1 if: ${{ steps.dev-dependencies-installation.conclusion == 'success' }} with: token: ${{ secrets.NPM_TOKEN }} @@ -47,7 +47,7 @@ jobs: working-directory: ./packages/contentstack-utilities run: npm run prepack - name: Publishing utilities - uses: JS-DevTools/npm-publish@v1 + uses: JS-DevTools/npm-publish@v2.2.1 if: ${{ steps.utilities-installation.conclusion == 'success' }} with: token: ${{ secrets.NPM_TOKEN }} @@ -62,7 +62,7 @@ jobs: working-directory: ./packages/contentstack-command run: npm run prepack - name: Publishing command - uses: JS-DevTools/npm-publish@v1 + uses: JS-DevTools/npm-publish@v2.2.1 if: ${{ steps.command-installation.conclusion == 'success' }} with: token: ${{ secrets.NPM_TOKEN }} @@ -77,7 +77,7 @@ jobs: working-directory: ./packages/contentstack-config run: npm run prepack - name: Publishing config - uses: JS-DevTools/npm-publish@v1 + uses: JS-DevTools/npm-publish@v2.2.1 if: ${{ steps.config-installation.conclusion == 'success' }} with: token: ${{ secrets.NPM_TOKEN }} @@ -92,7 +92,7 @@ jobs: working-directory: ./packages/contentstack-auth run: npm run prepack - name: Publishing auth - uses: JS-DevTools/npm-publish@v1 + uses: JS-DevTools/npm-publish@v2.2.1 if: ${{ steps.auth-installation.conclusion == 'success' }} with: token: ${{ secrets.NPM_TOKEN }} @@ -103,7 +103,7 @@ jobs: working-directory: ./packages/contentstack-export run: npm install - name: Publishing export - uses: JS-DevTools/npm-publish@v1 + uses: JS-DevTools/npm-publish@v2.2.1 if: ${{ steps.export-installation.conclusion == 'success' }} with: token: ${{ secrets.NPM_TOKEN }} @@ -114,7 +114,7 @@ jobs: working-directory: ./packages/contentstack-import run: npm install - name: Publishing import - uses: JS-DevTools/npm-publish@v1 + uses: JS-DevTools/npm-publish@v2.2.1 if: ${{ steps.import-installation.conclusion == 'success' }} with: token: ${{ secrets.NPM_TOKEN }} @@ -125,7 +125,7 @@ jobs: working-directory: ./packages/contentstack-clone run: npm install - name: Publishing clone - uses: JS-DevTools/npm-publish@v1 + uses: JS-DevTools/npm-publish@v2.2.1 if: ${{ steps.clone-installation.conclusion == 'success' }} with: token: ${{ secrets.NPM_TOKEN }} @@ -136,7 +136,7 @@ jobs: working-directory: ./packages/contentstack-export-to-csv run: npm install - name: Publishing export to csv - uses: JS-DevTools/npm-publish@v1 + uses: JS-DevTools/npm-publish@v2.2.1 if: ${{ steps.export-to-csv-installation.conclusion == 'success' }} with: token: ${{ secrets.NPM_TOKEN }} @@ -147,7 +147,7 @@ jobs: working-directory: ./packages/contentstack-migrate-rte run: npm install - name: Publishing migrate rte - uses: JS-DevTools/npm-publish@v1 + uses: JS-DevTools/npm-publish@v2.2.1 if: ${{ steps.migrate-rte-installation.conclusion == 'success' }} with: token: ${{ secrets.NPM_TOKEN }} @@ -158,7 +158,7 @@ jobs: working-directory: ./packages/contentstack-migration run: npm install - name: Publishing migration - uses: JS-DevTools/npm-publish@v1 + uses: JS-DevTools/npm-publish@v2.2.1 if: ${{ steps.migration-installation.conclusion == 'success' }} with: token: ${{ secrets.NPM_TOKEN }} @@ -173,7 +173,7 @@ jobs: working-directory: ./packages/contentstack-seed run: npm run prepack - name: Publishing seed - uses: JS-DevTools/npm-publish@v1 + uses: JS-DevTools/npm-publish@v2.2.1 if: ${{ steps.seed-installation.conclusion == 'success' }} with: token: ${{ secrets.NPM_TOKEN }} @@ -188,7 +188,7 @@ jobs: working-directory: ./packages/contentstack-bootstrap run: npm run prepack - name: Publishing bootstrap - uses: JS-DevTools/npm-publish@v1 + uses: JS-DevTools/npm-publish@v2.2.1 if: ${{ steps.bootstrap-installation.conclusion == 'success' }} with: token: ${{ secrets.NPM_TOKEN }} @@ -199,7 +199,7 @@ jobs: working-directory: ./packages/contentstack-bulk-publish run: npm install - name: Publishing bulk publish - uses: JS-DevTools/npm-publish@v1 + uses: JS-DevTools/npm-publish@v2.2.1 if: ${{ steps.bulk-publish-installation.conclusion == 'success' }} with: token: ${{ secrets.NPM_TOKEN }} @@ -214,7 +214,7 @@ jobs: working-directory: ./packages/contentstack-launch run: npm run prepack - name: Publishing launch - uses: JS-DevTools/npm-publish@v1 + uses: JS-DevTools/npm-publish@v2.2.1 if: ${{ steps.launch-installation.conclusion == 'success' }} with: token: ${{ secrets.NPM_TOKEN }} @@ -230,7 +230,7 @@ jobs: working-directory: ./packages/contentstack-branches run: npm run prepack - name: Publishing branches - uses: JS-DevTools/npm-publish@v1 + uses: JS-DevTools/npm-publish@v2.2.1 if: ${{ steps.branches-installation.conclusion == 'success' }} with: token: ${{ secrets.NPM_TOKEN }} @@ -243,12 +243,12 @@ jobs: run: npm install - name: Publishing core id: publish-core - uses: JS-DevTools/npm-publish@v1 + uses: JS-DevTools/npm-publish@v2.2.1 if: ${{ steps.core-installation.conclusion == 'success' }} with: token: ${{ secrets.NPM_TOKEN }} package: ./packages/contentstack/package.json - - uses: actions/checkout@v2 + - uses: actions/checkout@v3.5.3 with: ref: 'prod-qa-pipeline' - run: echo ${{ steps.publish-core.outputs.version }} > version.md @@ -256,12 +256,8 @@ jobs: with: message: 'Released version' - name: Create Release - uses: actions/create-release@v1 + uses: actions/create-release@v1.1.4 id: create_release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: v${{ steps.publish-core.outputs.version }} - release_name: Release ${{ steps.publish-core.outputs.version }} - draft: false # Default value, but nice to set explicitly - prerelease: false # Default value, but nice to set explicitly + run: gh release create v${{ steps.publish-core.outputs.version }} --title "Release ${{ steps.publish-core.outputs.version }}" --generate-notes diff --git a/.github/workflows/sast-scan.yml b/.github/workflows/sast-scan.yml index f9316303a9..1c735eca7f 100644 --- a/.github/workflows/sast-scan.yml +++ b/.github/workflows/sast-scan.yml @@ -6,6 +6,6 @@ jobs: security: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3.5.3 - name: Horusec Scan run: docker run -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd):/src horuszup/horusec-cli:latest horusec start -p /src -P $(pwd) \ No newline at end of file diff --git a/.github/workflows/sca-scan.yml b/.github/workflows/sca-scan.yml index 1857400ff9..21ac795a5b 100644 --- a/.github/workflows/sca-scan.yml +++ b/.github/workflows/sca-scan.yml @@ -10,8 +10,8 @@ jobs: - uses: pnpm/action-setup@v2 with: version: 7 - - name: Use Node.js 16.x - uses: actions/setup-node@v3 + - name: Use Node.js 18.x + uses: actions/setup-node@v3.7.0 with: node-version: '18.x' cache: 'pnpm' diff --git a/.github/workflows/secrets-scan.yml b/.github/workflows/secrets-scan.yml index 1e8f176164..24377a5969 100644 --- a/.github/workflows/secrets-scan.yml +++ b/.github/workflows/secrets-scan.yml @@ -6,6 +6,6 @@ jobs: security: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3.5.3 - name: Gittyleaks uses: gupy-io/gittyleaks-action@v0.1 \ No newline at end of file From c8fe0b0669261969b83b306c0cee29de79cc26e4 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Thu, 13 Jul 2023 19:16:40 +0530 Subject: [PATCH 02/24] Resolved the error in yaml --- .github/workflows/release.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5a9c8e7ac6..4373684d5c 100755 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -256,7 +256,6 @@ jobs: with: message: 'Released version' - name: Create Release - uses: actions/create-release@v1.1.4 id: create_release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From dbe869403c92292566ad9507bfceb53df56e1e7b Mon Sep 17 00:00:00 2001 From: Shrutika Almeida Date: Mon, 17 Jul 2023 11:13:09 +0530 Subject: [PATCH 03/24] update merge flow --- .../src/branch/merge-handler.ts | 68 +++++++++- .../src/commands/cm/branches/merge.ts | 2 +- .../src/utils/create-merge-scripts.ts | 52 +++++--- .../src/utils/entry-create-update-script.ts | 122 ++++++++++++++++++ .../src/utils/interactive.ts | 87 +++++++++++++ 5 files changed, 309 insertions(+), 22 deletions(-) create mode 100644 packages/contentstack-branches/src/utils/entry-create-update-script.ts diff --git a/packages/contentstack-branches/src/branch/merge-handler.ts b/packages/contentstack-branches/src/branch/merge-handler.ts index 3e74f4474d..e75b4c9b5f 100644 --- a/packages/contentstack-branches/src/branch/merge-handler.ts +++ b/packages/contentstack-branches/src/branch/merge-handler.ts @@ -14,10 +14,10 @@ import { executeMerge, generateMergeScripts, selectCustomPreferences, + selectContentMergePreference, + selectContentMergeCustomPreferences, } from '../utils'; -const enableEntryExp = false; - export default class MergeHandler { private strategy: string; private strategySubOption?: string; @@ -66,6 +66,12 @@ export default class MergeHandler { await this.executeMerge(mergePayload); } else if (this.executeOption === 'export') { await this.exportSummary(mergePayload); + } else if (this.executeOption === 'merge_n_scripts') { + this.enableEntryExp = true; + await this.executeMerge(mergePayload); + } else if (this.executeOption === 'summary_n_scripts') { + this.enableEntryExp = true; + await this.exportSummary(mergePayload); } else { await this.exportSummary(mergePayload); await this.executeMerge(mergePayload); @@ -203,6 +209,10 @@ export default class MergeHandler { }; await writeFile(path.join(this.exportSummaryPath, 'merge-summary.json'), summary); cliux.success('Exported the summary successfully'); + + if (this.enableEntryExp) { + this.executeEntryExpFlow(this.stackAPIKey, mergePayload); + } } async executeMerge(mergePayload) { @@ -227,14 +237,62 @@ export default class MergeHandler { } } - executeEntryExpFlow(mergeJobUID: string, mergePayload) { - let scriptFolderPath = generateMergeScripts(this.mergeSettings.mergeContent, mergeJobUID); + async executeEntryExpFlow(mergeJobUID: string, mergePayload) { + const { mergeContent } = this.mergeSettings; + let mergePreference = await selectContentMergePreference(); + let selectedMergePreference; + + const updateEntryMergeStrategy = (items, mergeStrategy) => { + items && + items.forEach((item) => { + item.entry_merge_strategy = mergeStrategy; + }); + }; + + switch (mergePreference) { + case 'existing_new': + selectedMergePreference = 'merge_existing_new'; + updateEntryMergeStrategy(mergeContent.content_types.added, selectedMergePreference); + updateEntryMergeStrategy(mergeContent.content_types.modified, selectedMergePreference); + break; + + case 'new': + selectedMergePreference = 'merge_new'; + updateEntryMergeStrategy(mergeContent.content_types.added, selectedMergePreference); + break; + + case 'existing': + selectedMergePreference = 'merge_existing'; + updateEntryMergeStrategy(mergeContent.content_types.modified, selectedMergePreference); + break; + + case 'ask_preference': + selectedMergePreference = 'custom'; + const selectedMergeItems = await selectContentMergeCustomPreferences(mergeContent.content_types); + mergeContent.content_types = { + added: [], + modified: [], + deleted: [], + }; + + selectedMergeItems.forEach((item) => { + mergeContent.content_types[item.status].push(item.value); + }); + break; + + default: + cliux.error(`error: Invalid preference ${mergePreference}`); + process.exit(1); + } + + let scriptFolderPath = generateMergeScripts(mergeContent.content_types, mergeJobUID); if (scriptFolderPath !== undefined) { cliux.success(`\nSuccess! We have generated entry migration files in the folder ${scriptFolderPath}`); + const migrationCommand = `csdx cm:stacks:migration --multiple --file-path ./${scriptFolderPath} --config compare-branch:${mergePayload.compare_branch} --branch ${mergePayload.base_branch} --stack-api-key ${this.stackAPIKey}`; cliux.print( - `\nKindly follow the steps in the guide "https://www.contentstack.com/docs/developers/cli/migrate-branch-entries" to update the migration scripts, and then run the command \n\ncsdx cm:stacks:migration --multiple --file-path ./${scriptFolderPath} --config compare-branch:${mergePayload.compare_branch} --branch ${mergePayload.base_branch} --stack-api-key ${this.stackAPIKey}`, + `\nKindly follow the steps in the guide "https://www.contentstack.com/docs/developers/cli/migrate-branch-entries" to update the migration scripts, and then run the command:\n\n${migrationCommand}`, { color: 'blue' }, ); } diff --git a/packages/contentstack-branches/src/commands/cm/branches/merge.ts b/packages/contentstack-branches/src/commands/cm/branches/merge.ts index 377a485ec6..2d65484670 100644 --- a/packages/contentstack-branches/src/commands/cm/branches/merge.ts +++ b/packages/contentstack-branches/src/commands/cm/branches/merge.ts @@ -91,7 +91,7 @@ export default class BranchMergeCommand extends Command { exportSummaryPath: branchMergeFlags['export-summary-path'], mergeSummary: branchMergeFlags.mergeSummary, host: this.cmaHost, - enableEntryExp: true, + enableEntryExp: false, }).start(); } catch (error) { console.log('Error in Merge operations', error); diff --git a/packages/contentstack-branches/src/utils/create-merge-scripts.ts b/packages/contentstack-branches/src/utils/create-merge-scripts.ts index 1e8cc05bd8..a4736b7ab5 100644 --- a/packages/contentstack-branches/src/utils/create-merge-scripts.ts +++ b/packages/contentstack-branches/src/utils/create-merge-scripts.ts @@ -1,29 +1,45 @@ import fs from 'fs'; +import { cliux } from '@contentstack/cli-utilities'; import { entryCreateScript } from './entry-create-script'; import { entryUpdateScript } from './entry-update-script'; +import { entryCreateUpdateScript } from './entry-create-update-script'; type CreateMergeScriptsProps = { uid: string; - status: string; + entry_merge_strategy: string; }; export function generateMergeScripts(mergeSummary, mergeJobUID) { try { let scriptFolderPath; - if (mergeSummary.content_types.modified && mergeSummary.content_types.modified?.length !== 0) { - mergeSummary.content_types.modified.map((contentType) => { - let data = entryUpdateScript(contentType.uid); - scriptFolderPath = createMergeScripts(contentType, data, mergeJobUID); - }); - } + const processContentType = (contentType, scriptFunction) => { + const data = scriptFunction(contentType.uid); + scriptFolderPath = createMergeScripts(contentType, data, mergeJobUID); + }; - if (mergeSummary.content_types.added && mergeSummary.content_types.added?.length !== 0) { - mergeSummary.content_types.added?.map((contentType) => { - let data = entryCreateScript(contentType.uid); - scriptFolderPath = createMergeScripts(contentType, data, mergeJobUID); - }); - } + const mergeStrategies = { + merge_existing_new: entryCreateUpdateScript, + merge_existing: entryUpdateScript, + merge_new: entryCreateScript, + ignore: entryCreateUpdateScript, + }; + + const processContentTypes = (contentTypes, messageType) => { + if (contentTypes && contentTypes.length > 0) { + contentTypes.forEach((contentType) => { + const mergeStrategy = contentType.entry_merge_strategy; + if (mergeStrategies.hasOwnProperty(mergeStrategy)) { + processContentType(contentType, mergeStrategies[mergeStrategy]); + } + }); + } else { + cliux.print(`No ${messageType} entries selected for merge`, { color: 'yellow' }); + } + }; + + processContentTypes(mergeSummary.modified, 'Modified'); + processContentTypes(mergeSummary.added, 'New'); return scriptFolderPath; } catch (error) { @@ -32,10 +48,12 @@ export function generateMergeScripts(mergeSummary, mergeJobUID) { } export function getContentypeMergeStatus(status) { - if (status === 'modified') { + if (status === 'merge_existing') { return 'updated'; - } else if (status === 'compare_only') { + } else if (status === 'merge_new') { return 'created'; + } else if (status === 'merge_existing_new') { + return 'created_updated'; } else { return ''; } @@ -64,7 +82,9 @@ export function createMergeScripts(contentType: CreateMergeScriptsProps, content fs.mkdirSync(fullPath); } fs.writeFileSync( - `${fullPath}/${fileCreatedAt}_${getContentypeMergeStatus(contentType.status)}_${contentType.uid}.js`, + `${fullPath}/${fileCreatedAt}_${getContentypeMergeStatus(contentType.entry_merge_strategy)}_${ + contentType.uid + }.js`, content, 'utf-8', ); diff --git a/packages/contentstack-branches/src/utils/entry-create-update-script.ts b/packages/contentstack-branches/src/utils/entry-create-update-script.ts new file mode 100644 index 0000000000..b55fcc9f9b --- /dev/null +++ b/packages/contentstack-branches/src/utils/entry-create-update-script.ts @@ -0,0 +1,122 @@ +export function entryCreateUpdateScript(contentType) { + return ` + module.exports = async ({ migration, stackSDKInstance, managementAPIClient, config, branch, apiKey }) => { + const keysToRemove = [ + 'content_type_uid', + 'created_at', + 'updated_at', + 'created_by', + 'updated_by', + 'ACL', + 'stackHeaders', + 'urlPath', + '_version', + '_in_progress', + 'update', + 'delete', + 'fetch', + 'publish', + 'unpublish', + 'publishRequest', + 'setWorkflowStage', + 'import', + ]; + + let compareBranch = config['compare-branch']; + + function converter(data) { + let arr = []; + for (const elm of data.entries()) { + // @ts-ignore + arr.push([elm[1].title, elm[1]]); + } + return arr; + } + + function deleteUnwantedKeysFromObject(obj, keysToRemove) { + if(obj){ + keysToRemove.map((key) => delete obj[key]); + return obj; + } + } + + function uniquelyConcatenateArrays(compareArr, baseArr) { + let uniqueArray = compareArr.concat(baseArr.filter((item) => compareArr.indexOf(item) < 0)); + return uniqueArray; + } + + const updateEntryTask = () => { + return { + title: 'Update Entries', + successMessage: 'Entries Updated Successfully', + failedMessage: 'Failed to update entries', + task: async () => { + let compareBranchEntries = await managementAPIClient + .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) + .contentType('${contentType}') + .entry() + .query() + .find(); + + let baseBranchEntries = await stackSDKInstance.contentType('${contentType}').entry().query().find(); + + let contentType = await managementAPIClient + .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) + .contentType('${contentType}') + .fetch(); + try { + if (contentType.options.singleton) { + compareBranchEntries.items.map(async (el) => { + let entryDetails = deleteUnwantedKeysFromObject(el, keysToRemove); + + if (baseBranchEntries.items.length) { + let baseEntryUid = baseBranchEntries.items[0].uid; + let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntryUid); + Object.assign(entry, { ...entryDetails }); + entry.update(); + } else { + await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails }); + } + }); + } else { + let compareMap = new Map(converter(compareBranchEntries.items)); + let baseMap = new Map(converter(baseBranchEntries.items)); + + let arr = uniquelyConcatenateArrays(Array.from(compareMap.keys()), Array.from(baseMap.keys())); + + arr.map(async (el) => { + let entryDetails = deleteUnwantedKeysFromObject(compareMap.get(el), keysToRemove); + + if (compareMap.get(el) && !baseMap.get(el)) { + await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails }); + } else if (compareMap.get(el) && baseMap.get(el)) { + let baseEntry = baseMap.get(el); + + let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntry.uid); + Object.assign(entry, { ...entryDetails }); + entry.update(); + } + }); + } + } catch (error) { + throw error; + } + }, + }; + }; + + if (compareBranch && branch.length !== 0 && apiKey.length !== 0) { + migration.addTask(updateEntryTask()); + } else { + if (apiKey.length === 0) { + console.error('Please provide api key using --stack-api-key flag'); + } + if (!compareBranch) { + console.error('Please provide compare branch through --config compare-branch: flag'); + } + if (branch.length === 0) { + console.error('Please provide branch name through --branch flag'); + } + } + };`; +} diff --git a/packages/contentstack-branches/src/utils/interactive.ts b/packages/contentstack-branches/src/utils/interactive.ts index cfe27e9f67..958eca36e5 100644 --- a/packages/contentstack-branches/src/utils/interactive.ts +++ b/packages/contentstack-branches/src/utils/interactive.ts @@ -134,6 +134,8 @@ export async function selectMergeExecution(): Promise { choices: [ { name: 'Execute Merge', value: 'both' }, { name: 'Export Merge Summary', value: 'export' }, + { name: 'Execute Merge and Generate Content Migration Scripts', value: 'merge_n_scripts' }, + { name: 'Export Summary and Generate Content Migration Scripts', value: 'summary_n_scripts' }, { name: 'Go Back', value: 'previous' }, { name: 'Start Over', value: 'restart' }, ], @@ -148,6 +150,28 @@ export async function selectMergeExecution(): Promise { return strategy; } +export async function selectContentMergePreference(): Promise { + const strategy = await cliux + .inquire({ + type: 'list', + name: 'module', + choices: [ + { name: 'Both existing and new', value: 'existing_new' }, + { name: 'New only', value: 'new' }, + { name: 'Existing only', value: 'existing' }, + { name: 'Ask for preference', value: 'ask_preference' }, + ], + message: 'What content entries do you want to migrate?', + }) + .then((name) => name as string) + .catch((err) => { + cliux.error('Failed to collect the preference'); + process.exit(1); + }); + + return strategy; +} + export async function askExportMergeSummaryPath(): Promise { return await cliux.inquire({ type: 'input', @@ -247,3 +271,66 @@ export async function askBranchNameConfirmation(): Promise { validate: inquireRequireFieldValidation, }); } + +export async function selectContentMergeCustomPreferences(payload) { + // parse rows + const tableRows = []; + if (payload.modified?.length || payload.added?.length) { + forEach(payload.added, (item: BranchDiffRes) => { + const row: any = {}; + row.name = `+ ${item.title}`; + row.status = 'added'; + row.value = item; + tableRows.push(row); + }); + + forEach(payload.modified, (item: BranchDiffRes) => { + const row: any = {}; + row.name = `± ${item.title}`; + row.status = 'modified'; + row.value = item; + tableRows.push(row); + }); + } else { + return; + } + + const selectedStrategies = await cliux.inquire({ + type: 'table', + message: `Select the Content Entry changes for merge`, + name: 'mergeContentEntriesPreferences', + selectAll: true, + pageSize: 10, + columns: [ + { + name: 'Merge New Only', + value: 'merge_new', + }, + { + name: 'Merge Modified Only', + value: 'merge_existing', + }, + { + name: 'Merge Both', + value: 'merge_existing_new', + }, + { + name: 'Ignore', + value: 'ignore', + }, + ], + rows: tableRows, + }); + + let updatedArray = []; + forEach(selectedStrategies, (strategy: string, index: number) => { + const selectedItem = tableRows[index]; + + if (strategy && selectedItem) { + selectedItem.value.entry_merge_strategy = strategy; + updatedArray.push(selectedItem); + } + }); + + return updatedArray; // selected items +} From ec1e5ae4c6c1f9690d9016dc683c259161ef5124 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Tue, 25 Jul 2023 12:30:54 +0530 Subject: [PATCH 04/24] Removed secrets-scan --- .github/workflows/secrets-scan.yml | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 .github/workflows/secrets-scan.yml diff --git a/.github/workflows/secrets-scan.yml b/.github/workflows/secrets-scan.yml deleted file mode 100644 index 58ad2321ee..0000000000 --- a/.github/workflows/secrets-scan.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: Secrets Scan -on: - pull_request: - types: [opened, synchronize, reopened] -jobs: - security: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3.5.3 - - name: Gittyleaks - uses: gupy-io/gittyleaks-action@v0.1 From 63d93dea0dd87def3179ccc73ad040002fbb8575 Mon Sep 17 00:00:00 2001 From: Shrutika Almeida Date: Fri, 28 Jul 2023 10:39:10 +0530 Subject: [PATCH 05/24] update migration scripts with reference logic --- .../src/utils/entry-create-script.ts | 204 ++++++++---- .../src/utils/entry-create-update-script.ts | 107 +++++- .../src/utils/entry-update-script.ts | 307 ++++++++++++------ 3 files changed, 444 insertions(+), 174 deletions(-) diff --git a/packages/contentstack-branches/src/utils/entry-create-script.ts b/packages/contentstack-branches/src/utils/entry-create-script.ts index fb1c1d6ce1..0d14e106c4 100644 --- a/packages/contentstack-branches/src/utils/entry-create-script.ts +++ b/packages/contentstack-branches/src/utils/entry-create-script.ts @@ -1,69 +1,153 @@ export function entryCreateScript(contentType) { return ` -module.exports = async ({ migration, stackSDKInstance, managementAPIClient, config, branch, apiKey }) => { - const keysToRemove = [ - 'content_type_uid', - 'created_at', - 'updated_at', - 'created_by', - 'updated_by', - 'ACL', - 'stackHeaders', - 'urlPath', - '_version', - '_in_progress', - 'update', - 'delete', - 'fetch', - 'publish', - 'unpublish', - 'publishRequest', - 'setWorkflowStage', - 'import', - ]; + module.exports = async ({ migration, stackSDKInstance, managementAPIClient, config, branch, apiKey }) => { + const keysToRemove = [ + 'content_type_uid', + 'created_at', + 'updated_at', + 'created_by', + 'updated_by', + 'ACL', + 'stackHeaders', + 'urlPath', + '_version', + '_in_progress', + 'update', + 'delete', + 'fetch', + 'publish', + 'unpublish', + 'publishRequest', + 'setWorkflowStage', + 'import', + ]; - let compareBranch = config['compare-branch']; + let compareBranch = config['compare-branch']; - const createEntryTask = () => { - return { - title: 'Create Entries', - successTitle: 'Entries Created Successfully', - failedTitle: 'Failed to create entries', - task: async () => { - const compareBranchEntries = await managementAPIClient - .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) // - .contentType('${contentType}') - .entry() - .query() - .find(); - const compareFilteredProperties = compareBranchEntries.items.map((entry) => { - keysToRemove.map((key) => delete entry[key]); - return entry; - }); - try { - compareFilteredProperties.length !== 0 && - compareFilteredProperties.forEach(async (entryDetails) => { - await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails }); - }); - } catch (error) { - throw error; - } - }, - }; - }; - if (compareBranch && branch.length !== 0 && apiKey.length !== 0) { - migration.addTask(createEntryTask()); - } else { - if (apiKey.length === 0) { - console.error('Please provide api key using --stack-api-key flag'); + function getValueByPath(obj, path) { + return path.split('[').reduce((o, key) => o && o[key.replace(/\]$/, '')], obj); } - if (!compareBranch) { - console.error('Please provide compare branch through --config compare-branch: flag'); + + function updateValueByPath(obj, path, newValue) { + path.split('[').reduce((o, key, index, arr) => { + if (index === arr.length - 1) { + o[key.replace(/\]$/, '')][0].uid = newValue; + } else { + return o[key.replace(/\]$/, '')]; + } + }, obj); } - if (branch.length === 0) { - console.error('Please provide branch name through --branch flag'); + + const findReference = function (schema, path, flag) { + let references = []; + + for (const i in schema) { + const currentPath = path ? path + '[' + schema[i].uid : schema[i].uid; + if (schema[i].data_type === 'group' || schema[i].data_type === 'global_field') { + references = references.concat(findReference(schema[i].schema, currentPath, flag)); + } else if (schema[i].data_type === 'blocks') { + for (const block in schema[i].blocks) { + references = references.concat( + findReference( + schema[i].blocks[block].schema, + currentPath + '[' + block + '][' + schema[i].blocks[block].uid + ']', + flag, + ), + ); + } + } else if (schema[i].data_type === 'reference') { + flag.references = true; + references.push(currentPath); + } + } + + return references; + }; + + const createEntryTask = () => { + return { + title: 'Create Entries', + successTitle: 'Entries Created Successfully', + failedTitle: 'Failed to create entries', + task: async () => { + const compareBranchEntries = await managementAPIClient + .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) + .contentType('${contentType}') + .entry() + .query() + .find(); + + const compareFilteredProperties = compareBranchEntries.items.map((entry) => { + keysToRemove.map((key) => delete entry[key]); + return entry; + }); + + let contentType = await managementAPIClient + .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) + .contentType('${contentType}') + .fetch(); + + let flag = { + references: false, + }; + + const references = await findReference(contentType.schema, '', flag); + + async function updateEntry(entry, entryDetails) { + Object.assign(entry, { ...entryDetails }); + await entry.update(); + } + + async function updateReferences(entryDetails, baseEntry, references) { + for (let i in references) { + let compareEntryRef = getValueByPath(entryDetails, references[i]); + let baseEntryRef = getValueByPath(baseEntry, references[i]); + + if (compareEntryRef.length > 0 && baseEntryRef.length >= 0) { + let compareRefEntry = await managementAPIClient + .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) + .contentType(compareEntryRef[0]._content_type_uid) + .entry(compareEntryRef[0].uid) + .fetch(); + let baseRefEntry = await stackSDKInstance + .contentType(compareEntryRef[0]._content_type_uid) + .entry() + .query({ query: { title: compareRefEntry.title } }) + .find(); + + updateValueByPath(entryDetails, references[i], baseRefEntry.items[0].uid); + } + } + } + + try { + compareFilteredProperties.length !== 0 && + compareFilteredProperties.forEach(async (entryDetails) => { + let createdEntry = await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails }); + if (flag.references) { + await updateReferences(entryDetails, createdEntry, references); + } + await updateEntry(createdEntry, entryDetails); + }); + } catch (error) { + throw error; + } + }, + }; + }; + if (compareBranch && branch.length !== 0 && apiKey.length !== 0) { + migration.addTask(createEntryTask()); + } else { + if (apiKey.length === 0) { + console.error('Please provide api key using --stack-api-key flag'); + } + if (!compareBranch) { + console.error('Please provide compare branch through --config compare-branch: flag'); + } + if (branch.length === 0) { + console.error('Please provide branch name through --branch flag'); + } } - } -}; + }; `; } diff --git a/packages/contentstack-branches/src/utils/entry-create-update-script.ts b/packages/contentstack-branches/src/utils/entry-create-update-script.ts index b55fcc9f9b..fa2b66d646 100644 --- a/packages/contentstack-branches/src/utils/entry-create-update-script.ts +++ b/packages/contentstack-branches/src/utils/entry-create-update-script.ts @@ -45,6 +45,46 @@ export function entryCreateUpdateScript(contentType) { return uniqueArray; } + function getValueByPath(obj, path) { + return path.split('[').reduce((o, key) => o && o[key.replace(/\]$/, '')], obj); + } + + function updateValueByPath(obj, path, newValue) { + path.split('[').reduce((o, key, index, arr) => { + if (index === arr.length - 1) { + o[key.replace(/\]$/, '')][0].uid = newValue; + } else { + return o[key.replace(/\]$/, '')]; + } + }, obj); + } + + const findReference = function (schema, path, flag) { + let references = []; + + for (const i in schema) { + const currentPath = path ? path + '[' + schema[i].uid : schema[i].uid; + if (schema[i].data_type === 'group' || schema[i].data_type === 'global_field') { + references = references.concat(findReference(schema[i].schema, currentPath, flag)); + } else if (schema[i].data_type === 'blocks') { + for (const block in schema[i].blocks) { + references = references.concat( + findReference( + schema[i].blocks[block].schema, + currentPath + '[' + block + '][' + schema[i].blocks[block].uid + ']', + flag, + ), + ); + } + } else if (schema[i].data_type === 'reference') { + flag.references = true; + references.push(currentPath); + } + } + + return references; + }; + const updateEntryTask = () => { return { title: 'Update Entries', @@ -64,6 +104,40 @@ export function entryCreateUpdateScript(contentType) { .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) .contentType('${contentType}') .fetch(); + + let flag = { + references: false + }; + + const references = await findReference(contentType.schema, '', flag); + + async function updateEntry(entry, entryDetails) { + Object.assign(entry, { ...entryDetails }); + await entry.update(); + } + + async function updateReferences(entryDetails, baseEntry, references) { + for (let i in references) { + let compareEntryRef = getValueByPath(entryDetails, references[i]); + let baseEntryRef = getValueByPath(baseEntry, references[i]); + + if (compareEntryRef.length > 0 && baseEntryRef.length >= 0) { + let compareRefEntry = await managementAPIClient + .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) + .contentType(compareEntryRef[0]._content_type_uid) + .entry(compareEntryRef[0].uid) + .fetch(); + let baseRefEntry = await stackSDKInstance + .contentType(compareEntryRef[0]._content_type_uid) + .entry() + .query({ query: { title: compareRefEntry.title } }) + .find(); + + updateValueByPath(entryDetails, references[i], baseRefEntry.items[0].uid); + } + } + } + try { if (contentType.options.singleton) { compareBranchEntries.items.map(async (el) => { @@ -72,10 +146,20 @@ export function entryCreateUpdateScript(contentType) { if (baseBranchEntries.items.length) { let baseEntryUid = baseBranchEntries.items[0].uid; let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntryUid); - Object.assign(entry, { ...entryDetails }); - entry.update(); + + if (flag.references) { + await updateReferences(entryDetails, baseBranchEntries.items[0], references); + } + + await updateEntry(entry, entryDetails); } else { - await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails }); + let createdEntry = await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails }); + + if (flag.references) { + await updateReferences(entryDetails, createdEntry, references); + } + + await updateEntry(createdEntry, entryDetails); } }); } else { @@ -88,13 +172,22 @@ export function entryCreateUpdateScript(contentType) { let entryDetails = deleteUnwantedKeysFromObject(compareMap.get(el), keysToRemove); if (compareMap.get(el) && !baseMap.get(el)) { - await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails }); + 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); - Object.assign(entry, { ...entryDetails }); - entry.update(); + + if (flag.references) { + await updateReferences(entryDetails, baseEntry, references); + } + + await updateEntry(entry, entryDetails); } }); } diff --git a/packages/contentstack-branches/src/utils/entry-update-script.ts b/packages/contentstack-branches/src/utils/entry-update-script.ts index ebd4678681..fe66637ff5 100644 --- a/packages/contentstack-branches/src/utils/entry-update-script.ts +++ b/packages/contentstack-branches/src/utils/entry-update-script.ts @@ -1,122 +1,215 @@ export function entryUpdateScript(contentType) { return ` -module.exports = async ({ migration, stackSDKInstance, managementAPIClient, config, branch, apiKey }) => { - const keysToRemove = [ - 'content_type_uid', - 'created_at', - 'updated_at', - 'created_by', - 'updated_by', - 'ACL', - 'stackHeaders', - 'urlPath', - '_version', - '_in_progress', - 'update', - 'delete', - 'fetch', - 'publish', - 'unpublish', - 'publishRequest', - 'setWorkflowStage', - 'import', - ]; - - let compareBranch = config['compare-branch']; - - function converter(data) { - let arr = []; - for (const elm of data.entries()) { - // @ts-ignore - arr.push([elm[1].title, elm[1]]); + module.exports = async ({ migration, stackSDKInstance, managementAPIClient, config, branch, apiKey }) => { + const keysToRemove = [ + 'content_type_uid', + 'created_at', + 'updated_at', + 'created_by', + 'updated_by', + 'ACL', + 'stackHeaders', + 'urlPath', + '_version', + '_in_progress', + 'update', + 'delete', + 'fetch', + 'publish', + 'unpublish', + 'publishRequest', + 'setWorkflowStage', + 'import', + ]; + + let compareBranch = config['compare-branch']; + + function converter(data) { + let arr = []; + for (const elm of data.entries()) { + // @ts-ignore + arr.push([elm[1].title, elm[1]]); + } + return arr; } - return arr; - } - - function deleteUnwantedKeysFromObject(obj, keysToRemove) { - if(obj){ - keysToRemove.map((key) => delete obj[key]); - return obj; + + function deleteUnwantedKeysFromObject(obj, keysToRemove) { + if(obj){ + keysToRemove.map((key) => delete obj[key]); + return obj; + } + } + + function uniquelyConcatenateArrays(compareArr, baseArr) { + let uniqueArray = compareArr.concat(baseArr.filter((item) => compareArr.indexOf(item) < 0)); + return uniqueArray; + } + + function getValueByPath(obj, path) { + return path.split('[').reduce((o, key) => o && o[key.replace(/\]$/, '')], obj); + } + + function updateValueByPath(obj, path, newValue) { + path.split('[').reduce((o, key, index, arr) => { + if (index === arr.length - 1) { + o[key.replace(/\]$/, '')][0].uid = newValue; + } else { + return o[key.replace(/\]$/, '')]; + } + }, obj); } - } - - function uniquelyConcatenateArrays(compareArr, baseArr) { - let uniqueArray = compareArr.concat(baseArr.filter((item) => compareArr.indexOf(item) < 0)); - return uniqueArray; - } - const updateEntryTask = () => { - return { - title: 'Update Entries', - successMessage: 'Entries Updated Successfully', - failedMessage: 'Failed to update entries', - task: async () => { - let compareBranchEntries = await managementAPIClient - .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) - .contentType('${contentType}') - .entry() - .query() - .find(); + const findReference = function (schema, path, flag) { + let references = []; + + for (const i in schema) { + const currentPath = path ? path + '[' + schema[i].uid : schema[i].uid; + if (schema[i].data_type === 'group' || schema[i].data_type === 'global_field') { + references = references.concat(findReference(schema[i].schema, currentPath, flag)); + } else if (schema[i].data_type === 'blocks') { + for (const block in schema[i].blocks) { + references = references.concat( + findReference( + schema[i].blocks[block].schema, + currentPath + '[' + block + '][' + schema[i].blocks[block].uid + ']', + flag, + ), + ); + } + } else if (schema[i].data_type === 'reference') { + flag.references = true; + references.push(currentPath); + } + } + + return references; + }; - let baseBranchEntries = await stackSDKInstance.contentType('${contentType}').entry().query().find(); + const updateEntryTask = () => { + return { + title: 'Update Entries', + successMessage: 'Entries Updated Successfully', + failedMessage: 'Failed to update entries', + task: async () => { + let compareBranchEntries = await managementAPIClient + .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) + .contentType('${contentType}') + .entry() + .query() + .find(); + + let baseBranchEntries = await stackSDKInstance.contentType('${contentType}').entry().query().find(); + + let contentType = await managementAPIClient + .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) + .contentType('${contentType}') + .fetch(); - let contentType = await managementAPIClient - .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) - .contentType('${contentType}') - .fetch(); - try { - if (contentType.options.singleton) { - compareBranchEntries.items.map(async (el) => { - let entryDetails = deleteUnwantedKeysFromObject(el, keysToRemove); + let flag = { + references: false + }; + + const references = await findReference(contentType.schema, '', flag); + + async function updateEntry(entry, entryDetails) { + Object.assign(entry, { ...entryDetails }); + await entry.update(); + } - if (baseBranchEntries.items.length) { - let baseEntryUid = baseBranchEntries.items[0].uid; - let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntryUid); - Object.assign(entry, { ...entryDetails }); - entry.update(); - } else { - await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails }); + async function updateReferences(entryDetails, baseEntry, references) { + for (let i in references) { + let compareEntryRef = getValueByPath(entryDetails, references[i]); + let baseEntryRef = getValueByPath(baseEntry, references[i]); + + if (compareEntryRef.length > 0 && baseEntryRef.length >= 0) { + let compareRefEntry = await managementAPIClient + .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) + .contentType(compareEntryRef[0]._content_type_uid) + .entry(compareEntryRef[0].uid) + .fetch(); + let baseRefEntry = await stackSDKInstance + .contentType(compareEntryRef[0]._content_type_uid) + .entry() + .query({ query: { title: compareRefEntry.title } }) + .find(); + + updateValueByPath(entryDetails, references[i], baseRefEntry.items[0].uid); } - }); - } else { - let compareMap = new Map(converter(compareBranchEntries.items)); - let baseMap = new Map(converter(baseBranchEntries.items)); - - let arr = uniquelyConcatenateArrays(Array.from(compareMap.keys()), Array.from(baseMap.keys())); - - arr.map(async (el) => { - let entryDetails = deleteUnwantedKeysFromObject(compareMap.get(el), keysToRemove); + } + } - if (compareMap.get(el) && !baseMap.get(el)) { - await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails }); - } else if (compareMap.get(el) && baseMap.get(el)) { - let baseEntry = baseMap.get(el); + try { + if (contentType.options.singleton) { + compareBranchEntries.items.map(async (el) => { + let entryDetails = deleteUnwantedKeysFromObject(el, keysToRemove); + + if (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, createdEntry, references); + } + + await updateEntry(createdEntry, entryDetails); + } + }); + } else { + let compareMap = new Map(converter(compareBranchEntries.items)); + let baseMap = new Map(converter(baseBranchEntries.items)); + + let arr = uniquelyConcatenateArrays(Array.from(compareMap.keys()), Array.from(baseMap.keys())); + + arr.map(async (el) => { + let entryDetails = deleteUnwantedKeysFromObject(compareMap.get(el), keysToRemove); + + 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); + + if (flag.references) { + await updateReferences(entryDetails, baseEntry, references); + } - let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntry.uid); - Object.assign(entry, { ...entryDetails }); - entry.update(); - } - }); + await updateEntry(entry, entryDetails); + } + }); + } + } catch (error) { + throw error; } - } catch (error) { - throw error; - } - }, + }, + }; }; - }; - - if (compareBranch && branch.length !== 0 && apiKey.length !== 0) { - migration.addTask(updateEntryTask()); - } else { - if (apiKey.length === 0) { - console.error('Please provide api key using --stack-api-key flag'); - } - if (!compareBranch) { - console.error('Please provide compare branch through --config compare-branch: flag'); - } - if (branch.length === 0) { - console.error('Please provide branch name through --branch flag'); + + if (compareBranch && branch.length !== 0 && apiKey.length !== 0) { + migration.addTask(updateEntryTask()); + } else { + if (apiKey.length === 0) { + console.error('Please provide api key using --stack-api-key flag'); + } + if (!compareBranch) { + console.error('Please provide compare branch through --config compare-branch: flag'); + } + if (branch.length === 0) { + console.error('Please provide branch name through --branch flag'); + } } - } -};`; + };`; } From 8b39cc0e56eb4c69d37cb4dfa88888b9bfa6b8e2 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Fri, 4 Aug 2023 15:11:51 +0530 Subject: [PATCH 06/24] fix: migration command(undefined reading length) issue --- .../contentstack-branches/src/utils/create-merge-scripts.ts | 4 ++-- .../contentstack-branches/src/utils/entry-create-script.ts | 2 +- .../src/utils/entry-create-update-script.ts | 4 ++-- .../contentstack-branches/src/utils/entry-update-script.ts | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/contentstack-branches/src/utils/create-merge-scripts.ts b/packages/contentstack-branches/src/utils/create-merge-scripts.ts index a4736b7ab5..b17df9a930 100644 --- a/packages/contentstack-branches/src/utils/create-merge-scripts.ts +++ b/packages/contentstack-branches/src/utils/create-merge-scripts.ts @@ -47,7 +47,7 @@ export function generateMergeScripts(mergeSummary, mergeJobUID) { } } -export function getContentypeMergeStatus(status) { +export function getContentTypeMergeStatus(status) { if (status === 'merge_existing') { return 'updated'; } else if (status === 'merge_new') { @@ -82,7 +82,7 @@ export function createMergeScripts(contentType: CreateMergeScriptsProps, content fs.mkdirSync(fullPath); } fs.writeFileSync( - `${fullPath}/${fileCreatedAt}_${getContentypeMergeStatus(contentType.entry_merge_strategy)}_${ + `${fullPath}/${fileCreatedAt}_${getContentTypeMergeStatus(contentType.entry_merge_strategy)}_${ contentType.uid }.js`, content, diff --git a/packages/contentstack-branches/src/utils/entry-create-script.ts b/packages/contentstack-branches/src/utils/entry-create-script.ts index 0d14e106c4..973e3c0236 100644 --- a/packages/contentstack-branches/src/utils/entry-create-script.ts +++ b/packages/contentstack-branches/src/utils/entry-create-script.ts @@ -103,7 +103,7 @@ export function entryCreateScript(contentType) { let compareEntryRef = getValueByPath(entryDetails, references[i]); let baseEntryRef = getValueByPath(baseEntry, references[i]); - if (compareEntryRef.length > 0 && baseEntryRef.length >= 0) { + if (compareEntryRef && compareEntryRef.length > 0 && baseEntryRef && baseEntryRef.length >= 0) { let compareRefEntry = await managementAPIClient .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) .contentType(compareEntryRef[0]._content_type_uid) diff --git a/packages/contentstack-branches/src/utils/entry-create-update-script.ts b/packages/contentstack-branches/src/utils/entry-create-update-script.ts index fa2b66d646..ba8ef2a781 100644 --- a/packages/contentstack-branches/src/utils/entry-create-update-script.ts +++ b/packages/contentstack-branches/src/utils/entry-create-update-script.ts @@ -121,7 +121,7 @@ export function entryCreateUpdateScript(contentType) { let compareEntryRef = getValueByPath(entryDetails, references[i]); let baseEntryRef = getValueByPath(baseEntry, references[i]); - if (compareEntryRef.length > 0 && baseEntryRef.length >= 0) { + if (compareEntryRef && compareEntryRef.length > 0 && baseEntryRef && baseEntryRef.length >= 0) { let compareRefEntry = await managementAPIClient .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) .contentType(compareEntryRef[0]._content_type_uid) @@ -143,7 +143,7 @@ export function entryCreateUpdateScript(contentType) { compareBranchEntries.items.map(async (el) => { let entryDetails = deleteUnwantedKeysFromObject(el, keysToRemove); - if (baseBranchEntries.items.length) { + if (baseBranchEntries && baseBranchEntries.items.length) { let baseEntryUid = baseBranchEntries.items[0].uid; let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntryUid); diff --git a/packages/contentstack-branches/src/utils/entry-update-script.ts b/packages/contentstack-branches/src/utils/entry-update-script.ts index fe66637ff5..892d161733 100644 --- a/packages/contentstack-branches/src/utils/entry-update-script.ts +++ b/packages/contentstack-branches/src/utils/entry-update-script.ts @@ -121,7 +121,7 @@ export function entryUpdateScript(contentType) { let compareEntryRef = getValueByPath(entryDetails, references[i]); let baseEntryRef = getValueByPath(baseEntry, references[i]); - if (compareEntryRef.length > 0 && baseEntryRef.length >= 0) { + if (compareEntryRef && compareEntryRef.length > 0 && baseEntryRef && baseEntryRef.length >= 0) { let compareRefEntry = await managementAPIClient .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) .contentType(compareEntryRef[0]._content_type_uid) @@ -143,7 +143,7 @@ export function entryUpdateScript(contentType) { compareBranchEntries.items.map(async (el) => { let entryDetails = deleteUnwantedKeysFromObject(el, keysToRemove); - if (baseBranchEntries.items.length) { + if (baseBranchEntries && baseBranchEntries.items.length) { let baseEntryUid = baseBranchEntries.items[0].uid; let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntryUid); From 955c9884fb8d87cbb9c031bf6062ba2ff2167d8e Mon Sep 17 00:00:00 2001 From: raj pandey Date: Mon, 7 Aug 2023 15:31:49 +0530 Subject: [PATCH 07/24] Added the publish time in the publish_details colum, Version Bump, audit fix --- package-lock.json | 18 +- .../contentstack-export-to-csv/package.json | 2 +- .../src/util/index.js | 2 +- packages/contentstack/package.json | 2 +- pnpm-lock.yaml | 176 +++++++----------- 5 files changed, 82 insertions(+), 118 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7880b30e6e..a0bdd948bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18893,9 +18893,9 @@ } }, "node_modules/word-wrap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", "dev": true, "peer": true, "engines": { @@ -20307,7 +20307,7 @@ "@contentstack/cli-cm-bulk-publish": "^1.3.10", "@contentstack/cli-cm-clone": "^1.4.13", "@contentstack/cli-cm-export": "^1.7.0", - "@contentstack/cli-cm-export-to-csv": "^1.3.12", + "@contentstack/cli-cm-export-to-csv": "^1.3.13", "@contentstack/cli-cm-import": "^1.7.0", "@contentstack/cli-cm-migrate-rte": "^1.4.10", "@contentstack/cli-cm-seed": "^1.4.13", @@ -21073,7 +21073,7 @@ }, "packages/contentstack-export-to-csv": { "name": "@contentstack/cli-cm-export-to-csv", - "version": "1.3.12", + "version": "1.3.13", "license": "MIT", "dependencies": { "@contentstack/cli-command": "^1.2.11", @@ -23708,7 +23708,7 @@ "@contentstack/cli-cm-bulk-publish": "^1.3.10", "@contentstack/cli-cm-clone": "^1.4.13", "@contentstack/cli-cm-export": "^1.7.0", - "@contentstack/cli-cm-export-to-csv": "^1.3.12", + "@contentstack/cli-cm-export-to-csv": "^1.3.13", "@contentstack/cli-cm-import": "^1.7.0", "@contentstack/cli-cm-migrate-rte": "^1.4.10", "@contentstack/cli-cm-seed": "^1.4.13", @@ -39925,9 +39925,9 @@ } }, "word-wrap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", "dev": true, "peer": true }, diff --git a/packages/contentstack-export-to-csv/package.json b/packages/contentstack-export-to-csv/package.json index 1ac48ef637..d6b1826caa 100644 --- a/packages/contentstack-export-to-csv/package.json +++ b/packages/contentstack-export-to-csv/package.json @@ -1,7 +1,7 @@ { "name": "@contentstack/cli-cm-export-to-csv", "description": "Export entities to csv", - "version": "1.3.12", + "version": "1.3.13", "author": "Abhinav Gupta @abhinav-from-contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { diff --git a/packages/contentstack-export-to-csv/src/util/index.js b/packages/contentstack-export-to-csv/src/util/index.js index 5bbc2ad453..cefdf6cb4f 100644 --- a/packages/contentstack-export-to-csv/src/util/index.js +++ b/packages/contentstack-export-to-csv/src/util/index.js @@ -380,7 +380,7 @@ function cleanEntries(entries, language, environments, contentTypeUid) { let workflow = ''; const envArr = []; entry.publish_details.forEach((env) => { - envArr.push(JSON.stringify([environments[env['environment']], env['locale']])); + envArr.push(JSON.stringify([environments[env['environment']], env['locale'], env['time']])); }); delete entry.publish_details; if ('_workflow' in entry) { diff --git a/packages/contentstack/package.json b/packages/contentstack/package.json index 62974dcb3d..c6432f773e 100755 --- a/packages/contentstack/package.json +++ b/packages/contentstack/package.json @@ -27,7 +27,7 @@ "@contentstack/cli-cm-bulk-publish": "^1.3.10", "@contentstack/cli-cm-clone": "^1.4.13", "@contentstack/cli-cm-export": "^1.7.0", - "@contentstack/cli-cm-export-to-csv": "^1.3.12", + "@contentstack/cli-cm-export-to-csv": "^1.3.13", "@contentstack/cli-cm-import": "^1.7.0", "@contentstack/cli-cm-migrate-rte": "^1.4.10", "@contentstack/cli-cm-seed": "^1.4.13", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 15208cd675..e171d88256 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,7 +16,7 @@ importers: '@contentstack/cli-cm-bulk-publish': ^1.3.10 '@contentstack/cli-cm-clone': ^1.4.13 '@contentstack/cli-cm-export': ^1.7.0 - '@contentstack/cli-cm-export-to-csv': ^1.3.12 + '@contentstack/cli-cm-export-to-csv': ^1.3.13 '@contentstack/cli-cm-import': ^1.7.0 '@contentstack/cli-cm-migrate-rte': ^1.4.10 '@contentstack/cli-cm-seed': ^1.4.13 @@ -1504,9 +1504,8 @@ packages: dev: false /@contentstack/management/1.10.0: - resolution: - { integrity: sha512-wnmVS19n3cZeh6T2PbBXGCr4irktunVmuECTyPF5++Rsc6GDO+FoQGCZdvzHpRZE0GLiPFIID50z2TZuNArEOg== } - engines: { node: '>=8.0.0' } + resolution: {integrity: sha512-wnmVS19n3cZeh6T2PbBXGCr4irktunVmuECTyPF5++Rsc6GDO+FoQGCZdvzHpRZE0GLiPFIID50z2TZuNArEOg==} + engines: {node: '>=8.0.0'} dependencies: axios: 0.27.2 form-data: 3.0.1 @@ -1517,9 +1516,8 @@ packages: dev: false /@contentstack/management/1.10.0_debug@4.3.4: - resolution: - { integrity: sha512-wnmVS19n3cZeh6T2PbBXGCr4irktunVmuECTyPF5++Rsc6GDO+FoQGCZdvzHpRZE0GLiPFIID50z2TZuNArEOg== } - engines: { node: '>=8.0.0' } + resolution: {integrity: sha512-wnmVS19n3cZeh6T2PbBXGCr4irktunVmuECTyPF5++Rsc6GDO+FoQGCZdvzHpRZE0GLiPFIID50z2TZuNArEOg==} + engines: {node: '>=8.0.0'} dependencies: axios: 0.27.2_debug@4.3.4 form-data: 3.0.1 @@ -2354,9 +2352,8 @@ packages: dev: true /@oclif/color/1.0.9: - resolution: - { integrity: sha512-ntc/fZwuf4NRfYbXVoUNFyMB9IxVx/ls/WbSLKbkD9UpsmwY1I3J4DJKKRFRpenmTuxGQW8Lyzm7X3vhzHpDQA== } - engines: { node: '>=12.0.0' } + resolution: {integrity: sha512-ntc/fZwuf4NRfYbXVoUNFyMB9IxVx/ls/WbSLKbkD9UpsmwY1I3J4DJKKRFRpenmTuxGQW8Lyzm7X3vhzHpDQA==} + engines: {node: '>=12.0.0'} dependencies: ansi-styles: 4.3.0 chalk: 4.1.2 @@ -2365,9 +2362,8 @@ packages: tslib: 2.6.0 /@oclif/command/1.8.33_@oclif+config@1.18.14: - resolution: - { integrity: sha512-7ZPvThrZaICX1hoZ/S82DaGgjI3UGG2rveBfxCE9JlgvrDQQiHLA6a/N7Hf3jq6t51AkXbBMhaMOBzXtSd73QA== } - engines: { node: '>=12.0.0' } + resolution: {integrity: sha512-7ZPvThrZaICX1hoZ/S82DaGgjI3UGG2rveBfxCE9JlgvrDQQiHLA6a/N7Hf3jq6t51AkXbBMhaMOBzXtSd73QA==} + engines: {node: '>=12.0.0'} peerDependencies: '@oclif/config': ^1 dependencies: @@ -2396,9 +2392,8 @@ packages: dev: false /@oclif/config/1.18.14: - resolution: - { integrity: sha512-cLT/deFDm6A69LjAfV5ZZMMvMDlPt7sjMHYBrsOgQ5Upq5kDMgbaZM3hEbw74DmYIsuhq2E2wYrPD+Ax2qAfkA== } - engines: { node: '>=8.0.0' } + resolution: {integrity: sha512-cLT/deFDm6A69LjAfV5ZZMMvMDlPt7sjMHYBrsOgQ5Upq5kDMgbaZM3hEbw74DmYIsuhq2E2wYrPD+Ax2qAfkA==} + engines: {node: '>=8.0.0'} dependencies: '@oclif/errors': 1.3.6 '@oclif/parser': 3.8.15 @@ -2411,9 +2406,8 @@ packages: dev: false /@oclif/core/2.9.4: - resolution: - { integrity: sha512-eFRRpV+tJ6nMkhay2M9IppjSF3atRrgj6Qo83qUslaFSAW3NAl4mIhx1mKmTwQx5rgSrar03xICtSAWJ6gZtag== } - engines: { node: '>=14.0.0' } + resolution: {integrity: sha512-eFRRpV+tJ6nMkhay2M9IppjSF3atRrgj6Qo83qUslaFSAW3NAl4mIhx1mKmTwQx5rgSrar03xICtSAWJ6gZtag==} + engines: {node: '>=14.0.0'} dependencies: '@types/cli-progress': 3.11.0 ansi-escapes: 4.3.2 @@ -2453,9 +2447,8 @@ packages: dev: true /@oclif/core/2.9.4_4qcp7qp4jxxdgb4qbxgwox4hwq: - resolution: - { integrity: sha512-eFRRpV+tJ6nMkhay2M9IppjSF3atRrgj6Qo83qUslaFSAW3NAl4mIhx1mKmTwQx5rgSrar03xICtSAWJ6gZtag== } - engines: { node: '>=14.0.0' } + resolution: {integrity: sha512-eFRRpV+tJ6nMkhay2M9IppjSF3atRrgj6Qo83qUslaFSAW3NAl4mIhx1mKmTwQx5rgSrar03xICtSAWJ6gZtag==} + engines: {node: '>=14.0.0'} dependencies: '@types/cli-progress': 3.11.0 ansi-escapes: 4.3.2 @@ -2494,9 +2487,8 @@ packages: - typescript /@oclif/core/2.9.4_npeoqfxwgl5njwqojmpesqhar4: - resolution: - { integrity: sha512-eFRRpV+tJ6nMkhay2M9IppjSF3atRrgj6Qo83qUslaFSAW3NAl4mIhx1mKmTwQx5rgSrar03xICtSAWJ6gZtag== } - engines: { node: '>=14.0.0' } + resolution: {integrity: sha512-eFRRpV+tJ6nMkhay2M9IppjSF3atRrgj6Qo83qUslaFSAW3NAl4mIhx1mKmTwQx5rgSrar03xICtSAWJ6gZtag==} + engines: {node: '>=14.0.0'} dependencies: '@types/cli-progress': 3.11.0 ansi-escapes: 4.3.2 @@ -2535,9 +2527,8 @@ packages: - typescript /@oclif/core/2.9.4_typescript@4.9.5: - resolution: - { integrity: sha512-eFRRpV+tJ6nMkhay2M9IppjSF3atRrgj6Qo83qUslaFSAW3NAl4mIhx1mKmTwQx5rgSrar03xICtSAWJ6gZtag== } - engines: { node: '>=14.0.0' } + resolution: {integrity: sha512-eFRRpV+tJ6nMkhay2M9IppjSF3atRrgj6Qo83qUslaFSAW3NAl4mIhx1mKmTwQx5rgSrar03xICtSAWJ6gZtag==} + engines: {node: '>=14.0.0'} dependencies: '@types/cli-progress': 3.11.0 ansi-escapes: 4.3.2 @@ -2587,9 +2578,8 @@ packages: dev: false /@oclif/help/1.0.12: - resolution: - { integrity: sha512-nvjgcZm2HsIEXEDYqo0+lXMSNe6Bx9vxZnJ9HqxMdSX6CNxr9ovvm5EilNGc9IxbtNXYlct+DE1le6urGmrlrw== } - engines: { node: '>=8.0.0' } + resolution: {integrity: sha512-nvjgcZm2HsIEXEDYqo0+lXMSNe6Bx9vxZnJ9HqxMdSX6CNxr9ovvm5EilNGc9IxbtNXYlct+DE1le6urGmrlrw==} + engines: {node: '>=8.0.0'} dependencies: '@oclif/config': 1.18.12 '@oclif/errors': 1.3.6 @@ -2609,9 +2599,8 @@ packages: dev: false /@oclif/parser/3.8.15: - resolution: - { integrity: sha512-M7ljUexkyJkR2efqG+PL31fAWyWDW1dczaMKoY+sOVqk78sm23iDMOJj/1vkfUrhO+W8dhseoPFnpSB6Hewfyw== } - engines: { node: '>=8.0.0' } + resolution: {integrity: sha512-M7ljUexkyJkR2efqG+PL31fAWyWDW1dczaMKoY+sOVqk78sm23iDMOJj/1vkfUrhO+W8dhseoPFnpSB6Hewfyw==} + engines: {node: '>=8.0.0'} dependencies: '@oclif/errors': 1.3.6 '@oclif/linewrap': 1.0.0 @@ -2620,9 +2609,8 @@ packages: dev: false /@oclif/plugin-help/5.2.14: - resolution: - { integrity: sha512-7hMLc6zqxeRfG4nvHHQPpbaBj60efM3ULFkCpHZkdLms/ezIkNo40F661QuraIjMP/NN+U6VSfBCGuPkRyxVkA== } - engines: { node: '>=12.0.0' } + resolution: {integrity: sha512-7hMLc6zqxeRfG4nvHHQPpbaBj60efM3ULFkCpHZkdLms/ezIkNo40F661QuraIjMP/NN+U6VSfBCGuPkRyxVkA==} + engines: {node: '>=12.0.0'} dependencies: '@oclif/core': 2.9.4 transitivePeerDependencies: @@ -2633,9 +2621,8 @@ packages: dev: true /@oclif/plugin-help/5.2.14_4qcp7qp4jxxdgb4qbxgwox4hwq: - resolution: - { integrity: sha512-7hMLc6zqxeRfG4nvHHQPpbaBj60efM3ULFkCpHZkdLms/ezIkNo40F661QuraIjMP/NN+U6VSfBCGuPkRyxVkA== } - engines: { node: '>=12.0.0' } + resolution: {integrity: sha512-7hMLc6zqxeRfG4nvHHQPpbaBj60efM3ULFkCpHZkdLms/ezIkNo40F661QuraIjMP/NN+U6VSfBCGuPkRyxVkA==} + engines: {node: '>=12.0.0'} dependencies: '@oclif/core': 2.9.4_4qcp7qp4jxxdgb4qbxgwox4hwq transitivePeerDependencies: @@ -2645,9 +2632,8 @@ packages: - typescript /@oclif/plugin-help/5.2.14_npeoqfxwgl5njwqojmpesqhar4: - resolution: - { integrity: sha512-7hMLc6zqxeRfG4nvHHQPpbaBj60efM3ULFkCpHZkdLms/ezIkNo40F661QuraIjMP/NN+U6VSfBCGuPkRyxVkA== } - engines: { node: '>=12.0.0' } + resolution: {integrity: sha512-7hMLc6zqxeRfG4nvHHQPpbaBj60efM3ULFkCpHZkdLms/ezIkNo40F661QuraIjMP/NN+U6VSfBCGuPkRyxVkA==} + engines: {node: '>=12.0.0'} dependencies: '@oclif/core': 2.9.4_npeoqfxwgl5njwqojmpesqhar4 transitivePeerDependencies: @@ -2657,9 +2643,8 @@ packages: - typescript /@oclif/plugin-help/5.2.14_typescript@4.9.5: - resolution: - { integrity: sha512-7hMLc6zqxeRfG4nvHHQPpbaBj60efM3ULFkCpHZkdLms/ezIkNo40F661QuraIjMP/NN+U6VSfBCGuPkRyxVkA== } - engines: { node: '>=12.0.0' } + resolution: {integrity: sha512-7hMLc6zqxeRfG4nvHHQPpbaBj60efM3ULFkCpHZkdLms/ezIkNo40F661QuraIjMP/NN+U6VSfBCGuPkRyxVkA==} + engines: {node: '>=12.0.0'} dependencies: '@oclif/core': 2.9.4_typescript@4.9.5 transitivePeerDependencies: @@ -2670,9 +2655,8 @@ packages: dev: true /@oclif/plugin-not-found/2.3.32: - resolution: - { integrity: sha512-tVFHfR9XRUWrcxBugHjFr7HUmbLheDX05IaFr7fMF2hcvcqDs3DBjy42WKEoXSaBVTcST6KKhoSy2UVX8pk9Fg== } - engines: { node: '>=12.0.0' } + resolution: {integrity: sha512-tVFHfR9XRUWrcxBugHjFr7HUmbLheDX05IaFr7fMF2hcvcqDs3DBjy42WKEoXSaBVTcST6KKhoSy2UVX8pk9Fg==} + engines: {node: '>=12.0.0'} dependencies: '@oclif/color': 1.0.9 '@oclif/core': 2.9.4 @@ -2685,9 +2669,8 @@ packages: dev: true /@oclif/plugin-not-found/2.3.32_4qcp7qp4jxxdgb4qbxgwox4hwq: - resolution: - { integrity: sha512-tVFHfR9XRUWrcxBugHjFr7HUmbLheDX05IaFr7fMF2hcvcqDs3DBjy42WKEoXSaBVTcST6KKhoSy2UVX8pk9Fg== } - engines: { node: '>=12.0.0' } + resolution: {integrity: sha512-tVFHfR9XRUWrcxBugHjFr7HUmbLheDX05IaFr7fMF2hcvcqDs3DBjy42WKEoXSaBVTcST6KKhoSy2UVX8pk9Fg==} + engines: {node: '>=12.0.0'} dependencies: '@oclif/color': 1.0.9 '@oclif/core': 2.9.4_4qcp7qp4jxxdgb4qbxgwox4hwq @@ -2699,9 +2682,8 @@ packages: - typescript /@oclif/plugin-not-found/2.3.32_npeoqfxwgl5njwqojmpesqhar4: - resolution: - { integrity: sha512-tVFHfR9XRUWrcxBugHjFr7HUmbLheDX05IaFr7fMF2hcvcqDs3DBjy42WKEoXSaBVTcST6KKhoSy2UVX8pk9Fg== } - engines: { node: '>=12.0.0' } + resolution: {integrity: sha512-tVFHfR9XRUWrcxBugHjFr7HUmbLheDX05IaFr7fMF2hcvcqDs3DBjy42WKEoXSaBVTcST6KKhoSy2UVX8pk9Fg==} + engines: {node: '>=12.0.0'} dependencies: '@oclif/color': 1.0.9 '@oclif/core': 2.9.4_npeoqfxwgl5njwqojmpesqhar4 @@ -2714,9 +2696,8 @@ packages: dev: true /@oclif/plugin-not-found/2.3.32_typescript@4.9.5: - resolution: - { integrity: sha512-tVFHfR9XRUWrcxBugHjFr7HUmbLheDX05IaFr7fMF2hcvcqDs3DBjy42WKEoXSaBVTcST6KKhoSy2UVX8pk9Fg== } - engines: { node: '>=12.0.0' } + resolution: {integrity: sha512-tVFHfR9XRUWrcxBugHjFr7HUmbLheDX05IaFr7fMF2hcvcqDs3DBjy42WKEoXSaBVTcST6KKhoSy2UVX8pk9Fg==} + engines: {node: '>=12.0.0'} dependencies: '@oclif/color': 1.0.9 '@oclif/core': 2.9.4_typescript@4.9.5 @@ -2775,9 +2756,8 @@ packages: dev: false /@oclif/plugin-warn-if-update-available/2.0.44: - resolution: - { integrity: sha512-52Ww0B4F1tMhwjw2fe73lhmfDI/F4ynf3ur7/xnpnVBEvj5JG4sqolbEJV/0lV85+4dJNsYJRxubbPYjxcbCcA== } - engines: { node: '>=12.0.0' } + resolution: {integrity: sha512-52Ww0B4F1tMhwjw2fe73lhmfDI/F4ynf3ur7/xnpnVBEvj5JG4sqolbEJV/0lV85+4dJNsYJRxubbPYjxcbCcA==} + engines: {node: '>=12.0.0'} dependencies: '@oclif/core': 2.9.4 chalk: 4.1.2 @@ -2795,9 +2775,8 @@ packages: dev: true /@oclif/plugin-warn-if-update-available/2.0.44_4qcp7qp4jxxdgb4qbxgwox4hwq: - resolution: - { integrity: sha512-52Ww0B4F1tMhwjw2fe73lhmfDI/F4ynf3ur7/xnpnVBEvj5JG4sqolbEJV/0lV85+4dJNsYJRxubbPYjxcbCcA== } - engines: { node: '>=12.0.0' } + resolution: {integrity: sha512-52Ww0B4F1tMhwjw2fe73lhmfDI/F4ynf3ur7/xnpnVBEvj5JG4sqolbEJV/0lV85+4dJNsYJRxubbPYjxcbCcA==} + engines: {node: '>=12.0.0'} dependencies: '@oclif/core': 2.9.4_4qcp7qp4jxxdgb4qbxgwox4hwq chalk: 4.1.2 @@ -2815,9 +2794,8 @@ packages: dev: true /@oclif/plugin-warn-if-update-available/2.0.44_npeoqfxwgl5njwqojmpesqhar4: - resolution: - { integrity: sha512-52Ww0B4F1tMhwjw2fe73lhmfDI/F4ynf3ur7/xnpnVBEvj5JG4sqolbEJV/0lV85+4dJNsYJRxubbPYjxcbCcA== } - engines: { node: '>=12.0.0' } + resolution: {integrity: sha512-52Ww0B4F1tMhwjw2fe73lhmfDI/F4ynf3ur7/xnpnVBEvj5JG4sqolbEJV/0lV85+4dJNsYJRxubbPYjxcbCcA==} + engines: {node: '>=12.0.0'} dependencies: '@oclif/core': 2.9.4_npeoqfxwgl5njwqojmpesqhar4 chalk: 4.1.2 @@ -2835,9 +2813,8 @@ packages: dev: true /@oclif/plugin-warn-if-update-available/2.0.44_typescript@4.9.5: - resolution: - { integrity: sha512-52Ww0B4F1tMhwjw2fe73lhmfDI/F4ynf3ur7/xnpnVBEvj5JG4sqolbEJV/0lV85+4dJNsYJRxubbPYjxcbCcA== } - engines: { node: '>=12.0.0' } + resolution: {integrity: sha512-52Ww0B4F1tMhwjw2fe73lhmfDI/F4ynf3ur7/xnpnVBEvj5JG4sqolbEJV/0lV85+4dJNsYJRxubbPYjxcbCcA==} + engines: {node: '>=12.0.0'} dependencies: '@oclif/core': 2.9.4_typescript@4.9.5 chalk: 4.1.2 @@ -2864,9 +2841,8 @@ packages: dev: true /@oclif/test/2.3.31: - resolution: - { integrity: sha512-dTWCni+Zv9aSuzyamS95+GJaIub6EAI+CT+pA1MP10RZF54mF7CKaas7t8dvNvDp1Y194hi64cqe+cNwZlR5ng== } - engines: { node: '>=12.0.0' } + resolution: {integrity: sha512-dTWCni+Zv9aSuzyamS95+GJaIub6EAI+CT+pA1MP10RZF54mF7CKaas7t8dvNvDp1Y194hi64cqe+cNwZlR5ng==} + engines: {node: '>=12.0.0'} dependencies: '@oclif/core': 2.9.4 fancy-test: 2.0.31 @@ -2879,9 +2855,8 @@ packages: dev: true /@oclif/test/2.3.31_4qcp7qp4jxxdgb4qbxgwox4hwq: - resolution: - { integrity: sha512-dTWCni+Zv9aSuzyamS95+GJaIub6EAI+CT+pA1MP10RZF54mF7CKaas7t8dvNvDp1Y194hi64cqe+cNwZlR5ng== } - engines: { node: '>=12.0.0' } + resolution: {integrity: sha512-dTWCni+Zv9aSuzyamS95+GJaIub6EAI+CT+pA1MP10RZF54mF7CKaas7t8dvNvDp1Y194hi64cqe+cNwZlR5ng==} + engines: {node: '>=12.0.0'} dependencies: '@oclif/core': 2.9.4_4qcp7qp4jxxdgb4qbxgwox4hwq fancy-test: 2.0.31 @@ -2894,9 +2869,8 @@ packages: dev: true /@oclif/test/2.3.31_npeoqfxwgl5njwqojmpesqhar4: - resolution: - { integrity: sha512-dTWCni+Zv9aSuzyamS95+GJaIub6EAI+CT+pA1MP10RZF54mF7CKaas7t8dvNvDp1Y194hi64cqe+cNwZlR5ng== } - engines: { node: '>=12.0.0' } + resolution: {integrity: sha512-dTWCni+Zv9aSuzyamS95+GJaIub6EAI+CT+pA1MP10RZF54mF7CKaas7t8dvNvDp1Y194hi64cqe+cNwZlR5ng==} + engines: {node: '>=12.0.0'} dependencies: '@oclif/core': 2.9.4_npeoqfxwgl5njwqojmpesqhar4 fancy-test: 2.0.31 @@ -3041,23 +3015,20 @@ packages: dev: false /@sigstore/bundle/1.0.0: - resolution: - { integrity: sha512-yLvrWDOh6uMOUlFCTJIZEnwOT9Xte7NPXUqVexEKGSF5XtBAuSg5du0kn3dRR0p47a4ah10Y0mNt8+uyeQXrBQ== } - engines: { node: ^14.17.0 || ^16.13.0 || >=18.0.0 } + resolution: {integrity: sha512-yLvrWDOh6uMOUlFCTJIZEnwOT9Xte7NPXUqVexEKGSF5XtBAuSg5du0kn3dRR0p47a4ah10Y0mNt8+uyeQXrBQ==} + engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} dependencies: '@sigstore/protobuf-specs': 0.2.0 dev: true /@sigstore/protobuf-specs/0.2.0: - resolution: - { integrity: sha512-8ZhZKAVfXjIspDWwm3D3Kvj0ddbJ0HqDZ/pOs5cx88HpT8mVsotFrg7H1UMnXOuDHz6Zykwxn4mxG3QLuN+RUg== } - engines: { node: ^14.17.0 || ^16.13.0 || >=18.0.0 } + resolution: {integrity: sha512-8ZhZKAVfXjIspDWwm3D3Kvj0ddbJ0HqDZ/pOs5cx88HpT8mVsotFrg7H1UMnXOuDHz6Zykwxn4mxG3QLuN+RUg==} + engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} dev: true /@sigstore/tuf/1.0.3: - resolution: - { integrity: sha512-2bRovzs0nJZFlCN3rXirE4gwxCn97JNjMmwpecqlbgV9WcxX7WRuIrgzx/X7Ib7MYRbyUTpBYE0s2x6AmZXnlg== } - engines: { node: ^14.17.0 || ^16.13.0 || >=18.0.0 } + resolution: {integrity: sha512-2bRovzs0nJZFlCN3rXirE4gwxCn97JNjMmwpecqlbgV9WcxX7WRuIrgzx/X7Ib7MYRbyUTpBYE0s2x6AmZXnlg==} + engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} dependencies: '@sigstore/protobuf-specs': 0.2.0 tuf-js: 1.1.7 @@ -4214,9 +4185,8 @@ packages: dev: true /aws-sdk/2.1418.0: - resolution: - { integrity: sha512-6WDMJQAWKwVt+44+61c/SAXKpUSwToqBMeaqizhEe3GN8TWfxMc9RfCnsYIIwS+L+5hedmKC5oc6Fg2ujs8KUQ== } - engines: { node: '>= 10.0.0' } + resolution: {integrity: sha512-6WDMJQAWKwVt+44+61c/SAXKpUSwToqBMeaqizhEe3GN8TWfxMc9RfCnsYIIwS+L+5hedmKC5oc6Fg2ujs8KUQ==} + engines: {node: '>= 10.0.0'} dependencies: buffer: 4.9.2 events: 1.1.1 @@ -4687,8 +4657,7 @@ packages: dev: true /caniuse-lite/1.0.30001517: - resolution: - { integrity: sha512-Vdhm5S11DaFVLlyiKu4hiUTkpZu+y1KA/rZZqVQfOD5YdDT/eQKlkt7NaE0WGOFgX32diqt9MiP9CAiFeRklaA== } + resolution: {integrity: sha512-Vdhm5S11DaFVLlyiKu4hiUTkpZu+y1KA/rZZqVQfOD5YdDT/eQKlkt7NaE0WGOFgX32diqt9MiP9CAiFeRklaA==} dev: true /cardinal/2.1.1: @@ -5493,8 +5462,7 @@ packages: jake: 10.8.7 /electron-to-chromium/1.4.466: - resolution: - { integrity: sha512-TSkRvbXRXD8BwhcGlZXDsbI2lRoP8dvqR7LQnqQNk9KxXBc4tG8O+rTuXgTyIpEdiqSGKEBSqrxdqEntnjNncA== } + resolution: {integrity: sha512-TSkRvbXRXD8BwhcGlZXDsbI2lRoP8dvqR7LQnqQNk9KxXBc4tG8O+rTuXgTyIpEdiqSGKEBSqrxdqEntnjNncA==} dev: true /elegant-spinner/1.0.1: @@ -6344,9 +6312,8 @@ packages: - supports-color /fancy-test/2.0.31: - resolution: - { integrity: sha512-Ok4L7GuoVdOBKtwlHdSnBYDBSFeWazcr6+/lhcC0LWS+sJYOXgbyCPP54fTt2TM1T8QWUm4ULHKQGOHKS61pfg== } - engines: { node: '>=12.0.0' } + resolution: {integrity: sha512-Ok4L7GuoVdOBKtwlHdSnBYDBSFeWazcr6+/lhcC0LWS+sJYOXgbyCPP54fTt2TM1T8QWUm4ULHKQGOHKS61pfg==} + engines: {node: '>=12.0.0'} dependencies: '@types/chai': 4.3.5 '@types/lodash': 4.14.195 @@ -10425,9 +10392,8 @@ packages: dev: true /pnpm/7.33.5: - resolution: - { integrity: sha512-TkmfIv/+WEWqj5Rj4ThrLXLDE04OvvlAk2CthE/vApDoK0ebMusuwPMOVmB+GCDCIWeCn9YmVtQaj9DMSg9CZw== } - engines: { node: '>=14.6' } + resolution: {integrity: sha512-TkmfIv/+WEWqj5Rj4ThrLXLDE04OvvlAk2CthE/vApDoK0ebMusuwPMOVmB+GCDCIWeCn9YmVtQaj9DMSg9CZw==} + engines: {node: '>=14.6'} hasBin: true dev: true @@ -11200,9 +11166,8 @@ packages: dev: true /sigstore/1.8.0: - resolution: - { integrity: sha512-ogU8qtQ3VFBawRJ8wjsBEX/vIFeHuGs1fm4jZtjWQwjo8pfAt7T/rh+udlAN4+QUe0IzA8qRSc/YZ7dHP6kh+w== } - engines: { node: ^14.17.0 || ^16.13.0 || >=18.0.0 } + resolution: {integrity: sha512-ogU8qtQ3VFBawRJ8wjsBEX/vIFeHuGs1fm4jZtjWQwjo8pfAt7T/rh+udlAN4+QUe0IzA8qRSc/YZ7dHP6kh+w==} + engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} hasBin: true dependencies: '@sigstore/bundle': 1.0.0 @@ -12342,8 +12307,7 @@ packages: dev: false /whatwg-fetch/3.6.16: - resolution: - { integrity: sha512-83avoGbZ0qtjtNrU3UTT3/Xd3uZ7DyfSYLuc1fL5iYs+93P+UkIVF6/6xpRVWeQcvbc7kSnVybSAVbd6QFW5Fg== } + resolution: {integrity: sha512-83avoGbZ0qtjtNrU3UTT3/Xd3uZ7DyfSYLuc1fL5iYs+93P+UkIVF6/6xpRVWeQcvbc7kSnVybSAVbd6QFW5Fg==} dev: false /whatwg-mimetype/3.0.0: From 1dde36984a2e4112d611498c9db3071c5654ecc5 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Mon, 7 Aug 2023 16:57:24 +0530 Subject: [PATCH 08/24] Minor Version Update --- package-lock.json | 6 +++--- packages/contentstack-export-to-csv/package.json | 2 +- packages/contentstack/package.json | 2 +- pnpm-lock.yaml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index a0bdd948bf..5e237834c2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20307,7 +20307,7 @@ "@contentstack/cli-cm-bulk-publish": "^1.3.10", "@contentstack/cli-cm-clone": "^1.4.13", "@contentstack/cli-cm-export": "^1.7.0", - "@contentstack/cli-cm-export-to-csv": "^1.3.13", + "@contentstack/cli-cm-export-to-csv": "^1.4.12", "@contentstack/cli-cm-import": "^1.7.0", "@contentstack/cli-cm-migrate-rte": "^1.4.10", "@contentstack/cli-cm-seed": "^1.4.13", @@ -21073,7 +21073,7 @@ }, "packages/contentstack-export-to-csv": { "name": "@contentstack/cli-cm-export-to-csv", - "version": "1.3.13", + "version": "1.4.12", "license": "MIT", "dependencies": { "@contentstack/cli-command": "^1.2.11", @@ -23708,7 +23708,7 @@ "@contentstack/cli-cm-bulk-publish": "^1.3.10", "@contentstack/cli-cm-clone": "^1.4.13", "@contentstack/cli-cm-export": "^1.7.0", - "@contentstack/cli-cm-export-to-csv": "^1.3.13", + "@contentstack/cli-cm-export-to-csv": "^1.4.12", "@contentstack/cli-cm-import": "^1.7.0", "@contentstack/cli-cm-migrate-rte": "^1.4.10", "@contentstack/cli-cm-seed": "^1.4.13", diff --git a/packages/contentstack-export-to-csv/package.json b/packages/contentstack-export-to-csv/package.json index d6b1826caa..1d89f766d0 100644 --- a/packages/contentstack-export-to-csv/package.json +++ b/packages/contentstack-export-to-csv/package.json @@ -1,7 +1,7 @@ { "name": "@contentstack/cli-cm-export-to-csv", "description": "Export entities to csv", - "version": "1.3.13", + "version": "1.4.12", "author": "Abhinav Gupta @abhinav-from-contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { diff --git a/packages/contentstack/package.json b/packages/contentstack/package.json index c6432f773e..9f510006b1 100755 --- a/packages/contentstack/package.json +++ b/packages/contentstack/package.json @@ -27,7 +27,7 @@ "@contentstack/cli-cm-bulk-publish": "^1.3.10", "@contentstack/cli-cm-clone": "^1.4.13", "@contentstack/cli-cm-export": "^1.7.0", - "@contentstack/cli-cm-export-to-csv": "^1.3.13", + "@contentstack/cli-cm-export-to-csv": "^1.4.12", "@contentstack/cli-cm-import": "^1.7.0", "@contentstack/cli-cm-migrate-rte": "^1.4.10", "@contentstack/cli-cm-seed": "^1.4.13", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e171d88256..d824e36bd2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,7 +16,7 @@ importers: '@contentstack/cli-cm-bulk-publish': ^1.3.10 '@contentstack/cli-cm-clone': ^1.4.13 '@contentstack/cli-cm-export': ^1.7.0 - '@contentstack/cli-cm-export-to-csv': ^1.3.13 + '@contentstack/cli-cm-export-to-csv': ^1.4.12 '@contentstack/cli-cm-import': ^1.7.0 '@contentstack/cli-cm-migrate-rte': ^1.4.10 '@contentstack/cli-cm-seed': ^1.4.13 From 32bf4a98757f37855723fa4e0f713c415870787b Mon Sep 17 00:00:00 2001 From: raj pandey Date: Mon, 7 Aug 2023 17:23:51 +0530 Subject: [PATCH 09/24] Removed stray console.log --- .../contentstack-import/src/import/modules-js/global-fields.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/contentstack-import/src/import/modules-js/global-fields.js b/packages/contentstack-import/src/import/modules-js/global-fields.js index 368b57803a..e830271aa2 100644 --- a/packages/contentstack-import/src/import/modules-js/global-fields.js +++ b/packages/contentstack-import/src/import/modules-js/global-fields.js @@ -83,7 +83,6 @@ module.exports = class ImportGlobalFields { log(self.config, chalk.green('Global field ' + global_field_uid + ' created successfully'), 'success'); }) .catch(function (err) { - console.log let error = JSON.parse(err.message); if (error.errors.title) { // eslint-disable-next-line no-undef From 8c2688d80b1ea6699918714ac487aa30cb54bde2 Mon Sep 17 00:00:00 2001 From: Antony Date: Thu, 17 Aug 2023 10:45:07 +0530 Subject: [PATCH 10/24] Fix: Workflow stage UID remains same after export and import of stack --- .../contentstack-import/src/import/modules-js/workflows.js | 4 +++- packages/contentstack-import/src/import/modules/workflows.ts | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/contentstack-import/src/import/modules-js/workflows.js b/packages/contentstack-import/src/import/modules-js/workflows.js index 89a6e0c38b..f66f979cc8 100644 --- a/packages/contentstack-import/src/import/modules-js/workflows.js +++ b/packages/contentstack-import/src/import/modules-js/workflows.js @@ -65,6 +65,8 @@ module.exports = class importWorkflows { } for (const stage of workflowStages) { + delete stage.uid; + if (stage.SYS_ACL.users.uids.length && stage.SYS_ACL.users.uids[0] !== '$all') { stage.SYS_ACL.users.uids = ['$all']; } @@ -132,7 +134,7 @@ module.exports = class importWorkflows { // the workflow has already been created log( self.config, - chalk.white( `The Workflows ${workflow.name} already exists. Skipping it to avoid duplicates!`), + chalk.white(`The Workflows ${workflow.name} already exists. Skipping it to avoid duplicates!`), 'success', ); } diff --git a/packages/contentstack-import/src/import/modules/workflows.ts b/packages/contentstack-import/src/import/modules/workflows.ts index 4d2cb8e419..713d8c5a05 100644 --- a/packages/contentstack-import/src/import/modules/workflows.ts +++ b/packages/contentstack-import/src/import/modules/workflows.ts @@ -184,6 +184,8 @@ export default class ImportWorkflows extends BaseClass { const workflowStages = workflow.workflow_stages; let stageIndex = 0; for (const stage of workflowStages) { + delete stage.uid; + if (stage?.SYS_ACL?.users?.uids?.length && stage?.SYS_ACL?.users?.uids[0] !== '$all') { stage.SYS_ACL.users.uids = ['$all']; } From e8484db3c77cde152036743c31386b35204c31a9 Mon Sep 17 00:00:00 2001 From: Antony Date: Fri, 18 Aug 2023 13:21:11 +0530 Subject: [PATCH 11/24] Fix: Update next available stages uid on workflow --- .../src/import/modules-js/workflows.js | 48 ++++++++++++-- .../src/import/modules/base-class.ts | 4 +- .../src/import/modules/workflows.ts | 64 ++++++++++++++++--- 3 files changed, 102 insertions(+), 14 deletions(-) diff --git a/packages/contentstack-import/src/import/modules-js/workflows.js b/packages/contentstack-import/src/import/modules-js/workflows.js index f66f979cc8..ca5dcadaea 100644 --- a/packages/contentstack-import/src/import/modules-js/workflows.js +++ b/packages/contentstack-import/src/import/modules-js/workflows.js @@ -4,12 +4,13 @@ * MIT Licensed */ -const mkdirp = require('mkdirp'); const fs = require('fs'); const path = require('path'); -const Promise = require('bluebird'); const chalk = require('chalk'); -const { isEmpty, merge } = require('lodash'); +const mkdirp = require('mkdirp'); +const Promise = require('bluebird'); +const { isEmpty, merge, filter, map, cloneDeep, find } = require('lodash'); + let { default: config } = require('../../config'); const { fileHelper, log, formatError } = require('../../utils'); @@ -58,6 +59,7 @@ module.exports = class importWorkflows { if (!self.workflowUidMapper.hasOwnProperty(workflowUid)) { const roleNameMap = {}; const workflowStages = workflow.workflow_stages; + const oldWorkflowStages = cloneDeep(workflow.workflow_stages); const roles = await self.stackAPIClient.role().fetchAll(); for (const role of roles.items) { @@ -67,6 +69,10 @@ module.exports = class importWorkflows { for (const stage of workflowStages) { delete stage.uid; + if (!isEmpty(stage.next_available_stages)) { + stage.next_available_stages = ['$all']; + } + if (stage.SYS_ACL.users.uids.length && stage.SYS_ACL.users.uids[0] !== '$all') { stage.SYS_ACL.users.uids = ['$all']; } @@ -112,7 +118,20 @@ module.exports = class importWorkflows { return self.stackAPIClient .workflow() .create({ workflow }) - .then(function (response) { + .then(async function (response) { + if ( + !isEmpty(filter(oldWorkflowStages, ({ next_available_stages }) => !isEmpty(next_available_stages))) + ) { + let updateRresponse = await self + .updateNextAvailableStagesUid(response, response.workflow_stages, oldWorkflowStages) + .catch((error) => { + log(self.config, `Workflow '${workflow.name}' update failed.`, 'error'); + log(self.config, error, 'error'); + }); + + if (updateRresponse) response = updateRresponse; + } + self.workflowUidMapper[workflowUid] = response; fileHelper.writeFileSync(workflowUidMapperPath, self.workflowUidMapper); }) @@ -154,4 +173,25 @@ module.exports = class importWorkflows { }); }); } + + updateNextAvailableStagesUid(workflow, newWorkflowStages, oldWorkflowStages) { + newWorkflowStages = map(newWorkflowStages, (newStage, index) => { + const oldStage = oldWorkflowStages[index]; + if (!isEmpty(oldStage.next_available_stages)) { + newStage.next_available_stages = map(oldStage.next_available_stages, (stageUid) => { + if (stageUid === '$all') return stageUid; + const stageName = find(oldWorkflowStages, { uid: stageUid })?.name; + return find(newWorkflowStages, { name: stageName })?.uid; + }).filter((val) => val); + } + + return newStage; + }); + + workflow.workflow_stages = newWorkflowStages; + + const updateWorkflow = this.stackAPIClient.workflow(workflow.uid); + Object.assign(updateWorkflow, workflow); + return updateWorkflow.update(); + } }; diff --git a/packages/contentstack-import/src/import/modules/base-class.ts b/packages/contentstack-import/src/import/modules/base-class.ts index f2efc86e3c..932e375235 100644 --- a/packages/contentstack-import/src/import/modules/base-class.ts +++ b/packages/contentstack-import/src/import/modules/base-class.ts @@ -54,8 +54,8 @@ export type ApiOptions = { url?: string; entity: ApiModuleType; apiData?: Record | any; - resolve: (value: any) => void; - reject: (error: any) => void; + resolve: (value: any) => Promise | void; + reject: (error: any) => Promise | void; additionalInfo?: Record; includeParamOnCompletion?: boolean; serializeData?: (input: ApiOptions) => any; diff --git a/packages/contentstack-import/src/import/modules/workflows.ts b/packages/contentstack-import/src/import/modules/workflows.ts index 713d8c5a05..29055c75ec 100644 --- a/packages/contentstack-import/src/import/modules/workflows.ts +++ b/packages/contentstack-import/src/import/modules/workflows.ts @@ -1,9 +1,12 @@ import chalk from 'chalk'; -import isEmpty from 'lodash/isEmpty'; -import values from 'lodash/values'; +import map from 'lodash/map'; import find from 'lodash/find'; +import { join } from 'node:path'; +import values from 'lodash/values'; +import filter from 'lodash/filter'; +import isEmpty from 'lodash/isEmpty'; +import cloneDeep from 'lodash/cloneDeep'; import findIndex from 'lodash/findIndex'; -import { join, resolve } from 'node:path'; import config from '../../config'; import BaseClass, { ApiOptions } from './base-class'; @@ -47,7 +50,10 @@ export default class ImportWorkflows extends BaseClass { //Step1 check folder exists or not if (fileHelper.fileExistsSync(this.workflowsFolderPath)) { - this.workflows = fsUtil.readFile(join(this.workflowsFolderPath, this.workflowsConfig.fileName), true) as Record; + this.workflows = fsUtil.readFile(join(this.workflowsFolderPath, this.workflowsConfig.fileName), true) as Record< + string, + unknown + >; } else { log(this.importConfig, `No such file or directory - '${this.workflowsFolderPath}'`, 'error'); return; @@ -86,13 +92,14 @@ export default class ImportWorkflows extends BaseClass { .then((data: any) => data) .catch((err: any) => log(this.importConfig, `Failed to fetch roles. ${formatError(err)}`, 'error')); - for (const role of roles?.items) { + for (const role of roles?.items || []) { this.roleNameMap[role.name] = role.uid; } } async importWorkflows() { const apiContent = values(this.workflows); + const oldWorkflows = cloneDeep(values(this.workflows)); //check and create custom roles if not exists for (const workflow of values(this.workflows)) { @@ -101,7 +108,21 @@ export default class ImportWorkflows extends BaseClass { } } - const onSuccess = ({ response, apiData: { uid, name } = { uid: null, name: '' } }: any) => { + const onSuccess = async ({ response, apiData: { uid, name } = { uid: null, name: '' } }: any) => { + const oldWorkflowStages = find(oldWorkflows, { uid })?.workflow_stages; + if (!isEmpty(filter(oldWorkflowStages, ({ next_available_stages }) => !isEmpty(next_available_stages)))) { + let updateRresponse = await this.updateNextAvailableStagesUid( + response, + response.workflow_stages, + oldWorkflowStages, + ).catch((error) => { + log(this.importConfig, `Workflow '${name}' update failed.`, 'error'); + log(this.importConfig, error, 'error'); + }); + + if (updateRresponse) response = updateRresponse; + } + this.createdWorkflows.push(response); this.workflowUidMapper[uid] = response.uid; log(this.importConfig, `Workflow '${name}' imported successfully`, 'success'); @@ -145,6 +166,27 @@ export default class ImportWorkflows extends BaseClass { ); } + updateNextAvailableStagesUid(workflow, newWorkflowStages, oldWorkflowStages) { + newWorkflowStages = map(newWorkflowStages, (newStage, index) => { + const oldStage = oldWorkflowStages[index]; + if (!isEmpty(oldStage.next_available_stages)) { + newStage.next_available_stages = map(oldStage.next_available_stages, (stageUid) => { + if (stageUid === '$all') return stageUid; + const stageName = find(oldWorkflowStages, { uid: stageUid })?.name; + return find(newWorkflowStages, { name: stageName })?.uid; + }).filter((val) => val); + } + + return newStage; + }); + + workflow.workflow_stages = newWorkflowStages; + + const updateWorkflow = this.stack.workflow(workflow.uid); + Object.assign(updateWorkflow, workflow); + return updateWorkflow.update(); + } + /** * @method serializeWorkflows * @param {ApiOptions} apiOptions ApiOptions @@ -165,6 +207,14 @@ export default class ImportWorkflows extends BaseClass { if (!workflow.branches) { workflow.branches = ['main']; } + for (const stage of workflow.workflow_stages) { + delete stage.uid; + + if (!isEmpty(stage.next_available_stages)) { + stage.next_available_stages = ['$all']; + } + } + apiOptions.apiData = workflow; } return apiOptions; @@ -184,8 +234,6 @@ export default class ImportWorkflows extends BaseClass { const workflowStages = workflow.workflow_stages; let stageIndex = 0; for (const stage of workflowStages) { - delete stage.uid; - if (stage?.SYS_ACL?.users?.uids?.length && stage?.SYS_ACL?.users?.uids[0] !== '$all') { stage.SYS_ACL.users.uids = ['$all']; } From 0015e29da9c244d8a1955d8c5069ce7ce2d3afa0 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Fri, 18 Aug 2023 13:52:10 +0530 Subject: [PATCH 12/24] Merged development and correct minor version update --- package-lock.json | 6 +++--- packages/contentstack-export-to-csv/package.json | 2 +- packages/contentstack/package.json | 2 +- pnpm-lock.yaml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6ce05ee13f..e277ebb260 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20307,7 +20307,7 @@ "@contentstack/cli-cm-bulk-publish": "^1.3.10", "@contentstack/cli-cm-clone": "^1.4.15", "@contentstack/cli-cm-export": "~1.8.0", - "@contentstack/cli-cm-export-to-csv": "^1.3.12", + "@contentstack/cli-cm-export-to-csv": "^1.4.0", "@contentstack/cli-cm-import": "~1.8.0", "@contentstack/cli-cm-migrate-rte": "^1.4.10", "@contentstack/cli-cm-seed": "^1.4.14", @@ -21072,7 +21072,7 @@ }, "packages/contentstack-export-to-csv": { "name": "@contentstack/cli-cm-export-to-csv", - "version": "1.4.12", + "version": "1.4.0", "license": "MIT", "dependencies": { "@contentstack/cli-command": "^1.2.11", @@ -23707,7 +23707,7 @@ "@contentstack/cli-cm-bulk-publish": "^1.3.10", "@contentstack/cli-cm-clone": "^1.4.15", "@contentstack/cli-cm-export": "~1.8.0", - "@contentstack/cli-cm-export-to-csv": "^1.3.12", + "@contentstack/cli-cm-export-to-csv": "^1.4.0", "@contentstack/cli-cm-import": "~1.8.0", "@contentstack/cli-cm-migrate-rte": "^1.4.10", "@contentstack/cli-cm-seed": "^1.4.14", diff --git a/packages/contentstack-export-to-csv/package.json b/packages/contentstack-export-to-csv/package.json index 1d89f766d0..1b77029b43 100644 --- a/packages/contentstack-export-to-csv/package.json +++ b/packages/contentstack-export-to-csv/package.json @@ -1,7 +1,7 @@ { "name": "@contentstack/cli-cm-export-to-csv", "description": "Export entities to csv", - "version": "1.4.12", + "version": "1.4.0", "author": "Abhinav Gupta @abhinav-from-contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { diff --git a/packages/contentstack/package.json b/packages/contentstack/package.json index e9077783c1..d4fbe99fd9 100755 --- a/packages/contentstack/package.json +++ b/packages/contentstack/package.json @@ -27,7 +27,7 @@ "@contentstack/cli-cm-bulk-publish": "^1.3.10", "@contentstack/cli-cm-clone": "^1.4.15", "@contentstack/cli-cm-export": "~1.8.0", - "@contentstack/cli-cm-export-to-csv": "^1.3.12", + "@contentstack/cli-cm-export-to-csv": "^1.4.0", "@contentstack/cli-cm-import": "~1.8.0", "@contentstack/cli-cm-migrate-rte": "^1.4.10", "@contentstack/cli-cm-seed": "^1.4.14", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0ce2144b7a..114cb024aa 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,7 +16,7 @@ importers: '@contentstack/cli-cm-bulk-publish': ^1.3.10 '@contentstack/cli-cm-clone': ^1.4.15 '@contentstack/cli-cm-export': ~1.8.0 - '@contentstack/cli-cm-export-to-csv': ^1.3.12 + '@contentstack/cli-cm-export-to-csv': ^1.4.0 '@contentstack/cli-cm-import': ~1.8.0 '@contentstack/cli-cm-migrate-rte': ^1.4.10 '@contentstack/cli-cm-seed': ^1.4.14 From 1bb0f451ce09cd1d58df3d0eb6ee8f9d48805428 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Fri, 18 Aug 2023 15:13:16 +0530 Subject: [PATCH 13/24] feat: asset migration script --- .../src/branch/merge-handler.ts | 5 +- .../src/utils/asset-folder-create-script.ts | 157 +++++++++ .../src/utils/create-merge-scripts.ts | 32 +- .../src/utils/entry-create-script.ts | 308 ++++++++++++++++- .../src/utils/entry-create-update-script.ts | 317 +++++++++++++++++- .../src/utils/entry-update-script.ts | 314 ++++++++++++++++- .../src/commands/cm/stacks/migration.js | 8 +- 7 files changed, 1123 insertions(+), 18 deletions(-) create mode 100644 packages/contentstack-branches/src/utils/asset-folder-create-script.ts diff --git a/packages/contentstack-branches/src/branch/merge-handler.ts b/packages/contentstack-branches/src/branch/merge-handler.ts index e75b4c9b5f..823da0743a 100644 --- a/packages/contentstack-branches/src/branch/merge-handler.ts +++ b/packages/contentstack-branches/src/branch/merge-handler.ts @@ -289,8 +289,9 @@ export default class MergeHandler { if (scriptFolderPath !== undefined) { cliux.success(`\nSuccess! We have generated entry migration files in the folder ${scriptFolderPath}`); - - const migrationCommand = `csdx cm:stacks:migration --multiple --file-path ./${scriptFolderPath} --config compare-branch:${mergePayload.compare_branch} --branch ${mergePayload.base_branch} --stack-api-key ${this.stackAPIKey}`; + cliux.print('\nWARNING!!! Migration is not intended to be run more than once. Migrated(entries/assets) will be duplicated if run more than once', {color: 'yellow'}); + + const migrationCommand = `csdx cm:stacks:migration --multiple --file-path ./${scriptFolderPath} --config {compare-branch:${mergePayload.compare_branch},file-path:./${scriptFolderPath}} --branch ${mergePayload.base_branch} --stack-api-key ${this.stackAPIKey}`; cliux.print( `\nKindly follow the steps in the guide "https://www.contentstack.com/docs/developers/cli/migrate-branch-entries" to update the migration scripts, and then run the command:\n\n${migrationCommand}`, { color: 'blue' }, diff --git a/packages/contentstack-branches/src/utils/asset-folder-create-script.ts b/packages/contentstack-branches/src/utils/asset-folder-create-script.ts new file mode 100644 index 0000000000..30ad3ec1fe --- /dev/null +++ b/packages/contentstack-branches/src/utils/asset-folder-create-script.ts @@ -0,0 +1,157 @@ +export function assetFolderCreateScript(contentType) { + return ` + const fs = require('fs'); + const path = require('path'); + module.exports = async ({ migration, stackSDKInstance, managementAPIClient, config, branch, apiKey }) => { + let filePath = config['file-path'] || process.cwd(); + let compareBranch = config['compare-branch']; + let folderMapper = {}; + let folderBucket = []; + + const getAssetCount = async function (branchName, isDir = false) { + const queryParam = { + asc: 'created_at', + include_count: true, + skip: 10 ** 100, + }; + + if (isDir) queryParam.query = { is_dir: true }; + + return await managementAPIClient + .stack({ api_key: stackSDKInstance.api_key, branch_uid: branchName }) + .asset() + .query(queryParam) + .count() + .then(({ assets }) => assets) + .catch((error) => {}); + }; + + async function getFolderJSON(skip, fCount, branchName, folderData = []) { + const queryRequestObj = { + skip, + include_folders: true, + query: { is_dir: true }, + }; + + return await managementAPIClient + .stack({ api_key: stackSDKInstance.api_key, branch_uid: branchName }) + .asset() + .query(queryRequestObj) + .find() + .then(async (response) => { + skip += 100; + folderData = [...folderData, ...response.items]; + if (skip >= fCount) { + return folderData; + } + return await getFolderJSON(skip, fCount, branchName, folderData); + }) + .catch((error) => {}); + } + + function buildTree(coll) { + let tree = {}; + for (let i = 0; i < coll.length; i++) { + if (coll[i].parent_uid === null || !coll[i].hasOwnProperty('parent_uid')) { + tree[coll[i].uid] = {}; + } + } + findBranches(tree, Object.keys(tree), coll); + return tree; + } + + function findBranches(tree, branches, coll) { + branches.forEach((branch) => { + for (const element of coll) { + if (branch === element.parent_uid) { + let childUid = element.uid; + tree[branch][childUid] = {}; + return findBranches(tree[branch], [childUid], coll); + } + } + }); + } + + function buildFolderReqObjs(baseFolderUIDs, compareAssetsFolder, tree, parent_uid) { + for (let leaf in tree) { + //folder doesn't exists + if (baseFolderUIDs.indexOf(leaf) === -1) { + let folderObj = compareAssetsFolder.filter((folder) => folder.uid === leaf); + if (folderObj && folderObj.length) { + let requestOption = { + folderReq: { + asset: { + name: folderObj[0].name, + parent_uid: parent_uid || null, + }, + }, + oldUid: leaf, + }; + folderBucket.push(requestOption); + } + } + if (Object.keys(tree[leaf]).length > 0) { + buildFolderReqObjs(baseFolderUIDs, compareAssetsFolder, tree[leaf], leaf, folderBucket); + } + } + } + + async function createFolder(payload) { + if (folderMapper.hasOwnProperty(payload.folderReq.asset.parent_uid)) { + // replace old uid with new + payload.folderReq.asset.parent_uid = folderMapper[payload.folderReq.asset.parent_uid]; + } + await managementAPIClient + .stack({ api_key: apiKey, branch_uid: branch }) + .asset() + .folder() + .create(payload.folderReq) + .then((res) => { + folderMapper[payload.oldUid] = res.uid; + }) + .catch((err) => console.log(err)); + } + + const createAssetTask = () => { + return { + title: 'Create Assets Folder', + successTitle: 'Assets folder Created Successfully', + failedTitle: 'Failed to create assets folder', + task: async () => { + try { + const baseAssetsFolderCount = await getAssetCount(branch, true); + const compareAssetsFolderCount = await getAssetCount(compareBranch, true); + const baseAssetsFolder = await getFolderJSON(0, baseAssetsFolderCount, branch); + const compareAssetsFolder = await getFolderJSON(0, compareAssetsFolderCount, compareBranch); + if (Array.isArray(compareAssetsFolder) && Array.isArray(baseAssetsFolder)) { + const baseAssetUIDs = baseAssetsFolder.map((bAsset) => bAsset.uid); + //create new asset folder in base branch and update it in mapper + const tree = buildTree(compareAssetsFolder); + buildFolderReqObjs(baseAssetUIDs, compareAssetsFolder, tree, null); + for (let i = 0; i < folderBucket.length; i++) { + await createFolder(folderBucket[i]); + } + fs.writeFileSync(path.resolve(filePath, 'folder-mapper.json'), JSON.stringify(folderMapper)); + } + } catch (error) { + throw error; + } + }, + }; + }; + if (compareBranch && branch.length !== 0 && apiKey.length !== 0) { + migration.addTask(createAssetTask()); + } else { + if (apiKey.length === 0) { + console.error('Please provide api key using --stack-api-key flag'); + } + if (!compareBranch) { + console.error('Please provide compare branch through --config compare-branch: flag'); + } + if (branch.length === 0) { + console.error('Please provide branch name through --branch flag'); + } + } +} +`; +} diff --git a/packages/contentstack-branches/src/utils/create-merge-scripts.ts b/packages/contentstack-branches/src/utils/create-merge-scripts.ts index b17df9a930..9112abe615 100644 --- a/packages/contentstack-branches/src/utils/create-merge-scripts.ts +++ b/packages/contentstack-branches/src/utils/create-merge-scripts.ts @@ -3,10 +3,12 @@ import { cliux } from '@contentstack/cli-utilities'; import { entryCreateScript } from './entry-create-script'; import { entryUpdateScript } from './entry-update-script'; import { entryCreateUpdateScript } from './entry-create-update-script'; +import { assetFolderCreateScript } from './asset-folder-create-script'; type CreateMergeScriptsProps = { uid: string; entry_merge_strategy: string; + type?: string; }; export function generateMergeScripts(mergeSummary, mergeJobUID) { @@ -14,11 +16,17 @@ export function generateMergeScripts(mergeSummary, mergeJobUID) { let scriptFolderPath; const processContentType = (contentType, scriptFunction) => { - const data = scriptFunction(contentType.uid); - scriptFolderPath = createMergeScripts(contentType, data, mergeJobUID); + let data: any; + if (contentType.uid) { + data = scriptFunction(contentType.uid); + } else { + data = scriptFunction(); + } + scriptFolderPath = createMergeScripts(contentType, mergeJobUID, data); }; const mergeStrategies = { + asset_create_folder: assetFolderCreateScript, merge_existing_new: entryCreateUpdateScript, merge_existing: entryUpdateScript, merge_new: entryCreateScript, @@ -27,6 +35,10 @@ export function generateMergeScripts(mergeSummary, mergeJobUID) { const processContentTypes = (contentTypes, messageType) => { if (contentTypes && contentTypes.length > 0) { + processContentType( + { type: 'assets', uid: '', entry_merge_strategy: '' }, + mergeStrategies['asset_create_folder'], + ); contentTypes.forEach((contentType) => { const mergeStrategy = contentType.entry_merge_strategy; if (mergeStrategies.hasOwnProperty(mergeStrategy)) { @@ -59,7 +71,7 @@ export function getContentTypeMergeStatus(status) { } } -export function createMergeScripts(contentType: CreateMergeScriptsProps, content, mergeJobUID) { +export function createMergeScripts(contentType: CreateMergeScriptsProps, mergeJobUID: string, content?: any) { const date = new Date(); const rootFolder = 'merge_scripts'; const fileCreatedAt = `${date.getFullYear()}${ @@ -81,13 +93,15 @@ export function createMergeScripts(contentType: CreateMergeScriptsProps, content if (!fs.existsSync(fullPath)) { fs.mkdirSync(fullPath); } - fs.writeFileSync( - `${fullPath}/${fileCreatedAt}_${getContentTypeMergeStatus(contentType.entry_merge_strategy)}_${ + let filePath: string; + if (contentType.type === 'assets') { + filePath = `${fullPath}/${fileCreatedAt}_create_assets_folder.js`; + } else { + filePath = `${fullPath}/${fileCreatedAt}_${getContentTypeMergeStatus(contentType.entry_merge_strategy)}_${ contentType.uid - }.js`, - content, - 'utf-8', - ); + }.js`; + } + fs.writeFileSync(filePath, content, 'utf-8'); } return fullPath; } catch (error) { diff --git a/packages/contentstack-branches/src/utils/entry-create-script.ts b/packages/contentstack-branches/src/utils/entry-create-script.ts index 973e3c0236..0fdd215942 100644 --- a/packages/contentstack-branches/src/utils/entry-create-script.ts +++ b/packages/contentstack-branches/src/utils/entry-create-script.ts @@ -1,5 +1,7 @@ export function entryCreateScript(contentType) { return ` + const fs = require('fs'); + const path = require('path'); module.exports = async ({ migration, stackSDKInstance, managementAPIClient, config, branch, apiKey }) => { const keysToRemove = [ 'content_type_uid', @@ -23,6 +25,12 @@ export function entryCreateScript(contentType) { ]; let compareBranch = config['compare-branch']; + let filePath = config['file-path'] || process.cwd(); + let assetDirPath = path.resolve(filePath, 'assets'); + let cAssetDetails = []; + let assetUIDMapper = {}; + let assetUrlMapper = {}; + let assetRefPath = {}; function getValueByPath(obj, path) { return path.split('[').reduce((o, key) => o && o[key.replace(/\]$/, '')], obj); @@ -64,6 +72,279 @@ export function entryCreateScript(contentType) { return references; }; + const findAssets = function (schema, entry, refPath, path) { + for (const i in schema) { + const currentPath = path ? path + '[' + schema[i].uid : schema[i].uid; + if (schema[i].data_type === 'group' || schema[i].data_type === 'global_field') { + return findAssets(schema[i].schema, entry, refPath, currentPath); + } else if (schema[i].data_type === 'blocks') { + for (const block in schema[i].blocks) { + { + if (schema[i].blocks[block].schema) { + return findAssets( + schema[i].blocks[block].schema, + entry, + refPath, + currentPath + '[' + block + '][' + schema[i].blocks[block].uid + ']', + ); + } + } + } + } else if (schema[i].data_type === 'json' && schema[i].field_metadata.rich_text_type) { + findAssetIdsFromJsonRte(entry, schema, refPath, path); + } else if ( + schema[i].data_type === 'text' && + schema[i].field_metadata && + (schema[i].field_metadata.markdown || schema[i].field_metadata.rich_text_type) + ) { + findFileUrls(schema[i], entry); + } else if (schema[i].data_type === 'file') { + refPath.push(currentPath) + const imgDetails = getValueByPath(entry, currentPath); + if (imgDetails) { + const obj = { + uid: imgDetails.uid, + parent_uid: imgDetails.parent_uid, + description: imgDetails.description, + title: imgDetails.title, + filename: imgDetails.filename, + url: imgDetails.url, + }; + cAssetDetails.push(obj); + } + } + } + }; + + function findFileUrls(schema, _entry) { + let markdownRegEx; + let markdownMatch; + let text; + // Regex to detect v3 asset uri patterns + if (schema && schema.field_metadata && schema.field_metadata.markdown) { + text = marked(JSON.stringify(_entry)); + } else { + text = JSON.stringify(_entry); + } + markdownRegEx = new RegExp( + '(https://(assets|(eu-|azure-na-|azure-eu-)?images).contentstack.(io|com)/v3/assets/(.*?)/(.*?)/(.*?)/(.*?)(?="))', + 'g', + ); + while ((markdownMatch = markdownRegEx.exec(text)) !== null) { + if (markdownMatch && typeof markdownMatch[0] === 'string') { + const assetDetails = markdownMatch[0].split('/'); + //fetch assetUID from url + const assetUID = assetDetails && assetDetails[6]; + const obj = { + uid: assetUID, + url: markdownMatch[0], + }; + cAssetDetails.push(obj); + } + } + } + + function findAssetIdsFromJsonRte(entryObj, ctSchema) { + for (const element of ctSchema) { + switch (element.data_type) { + case 'blocks': { + if (entryObj[element.uid]) { + if (element.multiple) { + entryObj[element.uid].forEach((e) => { + let key = Object.keys(e).pop(); + let subBlock = element.blocks.filter((block) => block.uid === key).pop(); + findAssetIdsFromJsonRte(e[key], subBlock.schema); + }); + } + } + break; + } + case 'global_field': + case 'group': { + if (entryObj[element.uid]) { + if (element.multiple) { + entryObj[element.uid].forEach((e) => { + findAssetIdsFromJsonRte(e, element.schema); + }); + } else { + findAssetIdsFromJsonRte(entryObj[element.uid], element.schema); + } + } + break; + } + case 'json': { + if (entryObj[element.uid] && element.field_metadata.rich_text_type) { + if (element.multiple) { + entryObj[element.uid].forEach((jsonRteData) => { + gatherJsonRteAssetIds(jsonRteData); + }); + } else { + gatherJsonRteAssetIds(entryObj[element.uid]); + } + } + break; + } + } + } + } + + function gatherJsonRteAssetIds(jsonRteData) { + jsonRteData.children.forEach((element) => { + if (element.type) { + switch (element.type) { + case 'a': + case 'p': { + if (element.children && element.children.length > 0) { + gatherJsonRteAssetIds(element); + } + break; + } + case 'reference': { + if (Object.keys(element.attrs).length > 0 && element.attrs.type === 'asset') { + cAssetDetails.push({ uid: element.attrs['asset-uid'] }); + if (element.attrs['asset-link']) { + const assetDetails = element.attrs['asset-link'].split('/'); + //fetch assetUID from url + const assetUID = assetDetails && assetDetails[6]; + const obj = { + uid: assetUID, + url: element.attrs['asset-link'], + }; + cAssetDetails.push(obj); + } else if (element.attrs['href']) { + const assetDetails = element.attrs['href'].split('/'); + //fetch assetUID from url + const assetUID = assetDetails && assetDetails[6]; + const obj = { + uid: assetUID, + url: element.attrs['href'], + }; + cAssetDetails.push(obj); + } + } + if (element.children && element.children.length > 0) { + gatherJsonRteAssetIds(element); + } + break; + } + } + } + }); + } + + const updateAssetDetailsInEntries = function (entry) { + assetRefPath[entry.uid].forEach((refPath) => { + let imgDetails = entry[refPath]; + if (imgDetails !== 'undefined' && imgDetails?.uid) { + entry[refPath] = assetUIDMapper[imgDetails.uid]; + } else { + imgDetails = getValueByPath(entry, refPath); + if(imgDetails !== 'undefined' && imgDetails?.uid){ + updateValueByPath(entry, refPath, assetUIDMapper[imgDetails.uid]); + } + } + }); + entry = JSON.stringify(entry); + const assetUrls = cAssetDetails.map((asset) => asset.url); + const assetUIDs = cAssetDetails.map((asset) => asset.uid); + assetUrls.forEach(function (assetUrl) { + let mappedAssetUrl = assetUrlMapper[assetUrl]; + if (typeof mappedAssetUrl !== 'undefined') { + entry = entry.replace(assetUrl, mappedAssetUrl); + } + }); + + assetUIDs.forEach(function (assetUid) { + let uid = assetUIDMapper[assetUid]; + if (typeof uid !== 'undefined') { + entry = entry.replace(new RegExp(assetUid, 'img'), uid); + } + }); + return JSON.parse(entry); + }; + + const checkAndDownloadAsset = async function (cAsset) { + if (cAsset) { + const assetUID = cAsset.uid; + const bAssetDetail = await managementAPIClient + .stack({ api_key: stackSDKInstance.api_key, branch_uid: branch }) + .asset(assetUID) + .fetch() + .then((assets) => assets) + .catch((error) => {}); + if (bAssetDetail) return; + else { + const cAssetDetail = await managementAPIClient + .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) + .asset(assetUID) + .fetch() + .then((assets) => assets) + .catch((error) => {}); + const updatedObj = { + parent_uid: cAssetDetail.parent_uid, + description: cAssetDetail.description, + title: cAssetDetail.title, + filename: cAssetDetail.filename, + url: cAssetDetail.url, + }; + Object.assign(cAsset, updatedObj); + const url = cAssetDetail?.url; + if (url) { + const assetFolderPath = path.resolve(assetDirPath, assetUID); + if (!fs.existsSync(assetFolderPath)) fs.mkdirSync(assetFolderPath); + const assetFilePath = path.resolve(assetFolderPath, cAsset.filename); + const assetWriterStream = fs.createWriteStream(assetFilePath); + const data = await managementAPIClient + .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) + .asset(assetUID) + .download({ url, responseType: 'stream' }) + .then(({ data }) => data) + .catch((error) => { + throw error; + }); + assetWriterStream.on('error', (error) => { + throw error; + }); + data.pipe(assetWriterStream); + } + } + } + return cAsset; + }; + + const uploadAssets = async function () { + const assetFolderMap = JSON.parse(fs.readFileSync(path.resolve(filePath, 'folder-mapper.json'), 'utf8')); + const stackAPIClient = managementAPIClient.stack({ api_key: stackSDKInstance.api_key, branch_uid: branch }); + for (let i = 0; i < cAssetDetails?.length; i++) { + const asset = cAssetDetails[i]; + let requestOption = {}; + + requestOption.parent_uid = assetFolderMap[asset.parent_uid] || asset.parent_uid; + + if (asset.hasOwnProperty('description') && typeof asset.description === 'string') { + requestOption.description = asset.description; + } + + if (asset.hasOwnProperty('tags') && Array.isArray(asset.tags)) { + requestOption.tags = asset.tags; + } + + if (asset.hasOwnProperty('title') && typeof asset.title === 'string') { + requestOption.title = asset.title; + } + requestOption.upload = path.resolve(assetDirPath, asset.uid, asset.filename); + const res = await stackAPIClient + .asset() + .create(requestOption) + .then((asset) => asset) + .catch((error) => { + throw error; + }); + assetUIDMapper[asset.uid] = res && res.uid; + assetUrlMapper[asset.url] = res && res.url; + } + }; + const createEntryTask = () => { return { title: 'Create Entries', @@ -87,6 +368,28 @@ export function entryCreateScript(contentType) { .contentType('${contentType}') .fetch(); + for (let i = 0; i < compareBranchEntries?.items?.length; i++) { + assetRefPath[compareBranchEntries.items[i].uid] = [] + findAssets(contentType.schema, compareBranchEntries.items[i], assetRefPath[compareBranchEntries.items[i].uid]); + cAssetDetails = [...new Map(cAssetDetails.map((item) => [item['uid'], item])).values()]; + } + if (cAssetDetails && cAssetDetails.length) { + if (!fs.existsSync(assetDirPath)) { + fs.mkdirSync(assetDirPath); + } + for (let i = 0; i < cAssetDetails.length; i++) { + const asset = cAssetDetails[i]; + const updatedCAsset = await checkAndDownloadAsset(asset); + if(updatedCAsset === undefined){ + delete cAssetDetails[i]; + cAssetDetails.splice(i, 1); + --i; + } + cAssetDetails[i] = updatedCAsset; + } + await uploadAssets(); + } + let flag = { references: false, }; @@ -123,7 +426,10 @@ export function entryCreateScript(contentType) { try { compareFilteredProperties.length !== 0 && compareFilteredProperties.forEach(async (entryDetails) => { - let createdEntry = await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails }); + entryDetails = updateAssetDetailsInEntries(entryDetails); + let createdEntry = await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails }).catch(error => { + throw error; + }); if (flag.references) { await updateReferences(entryDetails, createdEntry, references); } diff --git a/packages/contentstack-branches/src/utils/entry-create-update-script.ts b/packages/contentstack-branches/src/utils/entry-create-update-script.ts index ba8ef2a781..1253200038 100644 --- a/packages/contentstack-branches/src/utils/entry-create-update-script.ts +++ b/packages/contentstack-branches/src/utils/entry-create-update-script.ts @@ -1,5 +1,7 @@ export function entryCreateUpdateScript(contentType) { return ` + const fs = require('fs'); + const path = require('path'); module.exports = async ({ migration, stackSDKInstance, managementAPIClient, config, branch, apiKey }) => { const keysToRemove = [ 'content_type_uid', @@ -23,6 +25,13 @@ export function entryCreateUpdateScript(contentType) { ]; let compareBranch = config['compare-branch']; + let filePath = config['file-path'] || process.cwd(); + let assetDirPath = path.resolve(filePath, 'assets'); + let assetDetails = []; + let newAssetDetails = []; + let assetUIDMapper = {}; + let assetUrlMapper = {}; + let assetRefPath = {}; function converter(data) { let arr = []; @@ -85,6 +94,280 @@ export function entryCreateUpdateScript(contentType) { return references; }; + const findAssets = function (schema, entry, refPath, path) { + for (const i in schema) { + const currentPath = path ? path + '[' + schema[i].uid : schema[i].uid; + if (schema[i].data_type === 'group' || schema[i].data_type === 'global_field') { + return findAssets(schema[i].schema, entry, refPath, currentPath); + } else if (schema[i].data_type === 'blocks') { + for (const block in schema[i].blocks) { + { + if (schema[i].blocks[block].schema) { + return findAssets( + schema[i].blocks[block].schema, + entry, + refPath, + currentPath + '[' + block + '][' + schema[i].blocks[block].uid + ']', + ); + } + } + } + } else if (schema[i].data_type === 'json' && schema[i].field_metadata.rich_text_type) { + findAssetIdsFromJsonRte(entry, schema, refPath, path); + } else if ( + schema[i].data_type === 'text' && + schema[i].field_metadata && + (schema[i].field_metadata.markdown || schema[i].field_metadata.rich_text_type) + ) { + findFileUrls(schema[i], entry); + } else if (schema[i].data_type === 'file') { + refPath.push(currentPath) + const imgDetails = getValueByPath(entry, currentPath); + if (imgDetails) { + const obj = { + uid: imgDetails.uid, + parent_uid: imgDetails.parent_uid, + description: imgDetails.description, + title: imgDetails.title, + filename: imgDetails.filename, + url: imgDetails.url, + }; + assetDetails.push(obj); + } + } + } + }; + + function findFileUrls(schema, _entry) { + let markdownRegEx; + let markdownMatch; + let text; + // Regex to detect v3 asset uri patterns + if (schema && schema.field_metadata && schema.field_metadata.markdown) { + text = marked(JSON.stringify(_entry)); + } else { + text = JSON.stringify(_entry); + } + markdownRegEx = new RegExp( + '(https://(assets|(eu-|azure-na-|azure-eu-)?images).contentstack.(io|com)/v3/assets/(.*?)/(.*?)/(.*?)/(.*?)(?="))', + 'g', + ); + while ((markdownMatch = markdownRegEx.exec(text)) !== null) { + if (markdownMatch && typeof markdownMatch[0] === 'string') { + const assetDetails = markdownMatch[0].split('/'); + //fetch assetUID from url + const assetUID = assetDetails && assetDetails[6]; + const obj = { + uid: assetUID, + url: markdownMatch[0], + }; + assetDetails.push(obj); + } + } + } + + function findAssetIdsFromJsonRte(entryObj, ctSchema) { + for (const element of ctSchema) { + switch (element.data_type) { + case 'blocks': { + if (entryObj[element.uid]) { + if (element.multiple) { + entryObj[element.uid].forEach((e) => { + let key = Object.keys(e).pop(); + let subBlock = element.blocks.filter((block) => block.uid === key).pop(); + findAssetIdsFromJsonRte(e[key], subBlock.schema); + }); + } + } + break; + } + case 'global_field': + case 'group': { + if (entryObj[element.uid]) { + if (element.multiple) { + entryObj[element.uid].forEach((e) => { + findAssetIdsFromJsonRte(e, element.schema); + }); + } else { + findAssetIdsFromJsonRte(entryObj[element.uid], element.schema); + } + } + break; + } + case 'json': { + if (entryObj[element.uid] && element.field_metadata.rich_text_type) { + if (element.multiple) { + entryObj[element.uid].forEach((jsonRteData) => { + gatherJsonRteAssetIds(jsonRteData); + }); + } else { + gatherJsonRteAssetIds(entryObj[element.uid]); + } + } + break; + } + } + } + } + + function gatherJsonRteAssetIds(jsonRteData) { + jsonRteData.children.forEach((element) => { + if (element.type) { + switch (element.type) { + case 'a': + case 'p': { + if (element.children && element.children.length > 0) { + gatherJsonRteAssetIds(element); + } + break; + } + case 'reference': { + if (Object.keys(element.attrs).length > 0 && element.attrs.type === 'asset') { + assetDetails.push({ uid: element.attrs['asset-uid'] }); + if (element.attrs['asset-link']) { + const assetDetails = element.attrs['asset-link'].split('/'); + //fetch assetUID from url + const assetUID = assetDetails && assetDetails[6]; + const obj = { + uid: assetUID, + url: element.attrs['asset-link'], + }; + assetDetails.push(obj); + } else if (element.attrs['href']) { + const assetDetails = element.attrs['href'].split('/'); + //fetch assetUID from url + const assetUID = assetDetails && assetDetails[6]; + const obj = { + uid: assetUID, + url: element.attrs['href'], + }; + assetDetails.push(obj); + } + } + if (element.children && element.children.length > 0) { + gatherJsonRteAssetIds(element); + } + break; + } + } + } + }); + } + + const updateAssetDetailsInEntries = function (entry) { + assetRefPath[entry.uid].forEach((refPath) => { + let imgDetails = entry[refPath]; + if (imgDetails !== 'undefined' && imgDetails?.uid) { + entry[refPath] = assetUIDMapper[imgDetails.uid]; + } else { + imgDetails = getValueByPath(entry, refPath); + if(imgDetails !== 'undefined' && imgDetails?.uid){ + updateValueByPath(entry, refPath, assetUIDMapper[imgDetails.uid]); + } + } + }); + entry = JSON.stringify(entry); + const assetUrls = assetDetails.map((asset) => asset.url); + const assetUIDs = assetDetails.map((asset) => asset.uid); + assetUrls.forEach(function (assetUrl) { + let mappedAssetUrl = assetUrlMapper[assetUrl]; + if (typeof mappedAssetUrl !== 'undefined') { + entry = entry.replace(assetUrl, mappedAssetUrl); + } + }); + + assetUIDs.forEach(function (assetUid) { + let uid = assetUIDMapper[assetUid]; + if (typeof uid !== 'undefined') { + entry = entry.replace(new RegExp(assetUid, 'img'), uid); + } + }); + return JSON.parse(entry); + }; + + const checkAndDownloadAsset = async function (cAsset) { + if (cAsset) { + const assetUID = cAsset.uid; + const bAssetDetail = await managementAPIClient + .stack({ api_key: stackSDKInstance.api_key, branch_uid: branch }) + .asset(assetUID) + .fetch() + .then((assets) => assets) + .catch((error) => {}); + if (bAssetDetail) return; + else { + const cAssetDetail = await managementAPIClient + .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) + .asset(assetUID) + .fetch() + .then((assets) => assets) + .catch((error) => {}); + const updatedObj = { + parent_uid: cAssetDetail.parent_uid, + description: cAssetDetail.description, + title: cAssetDetail.title, + filename: cAssetDetail.filename, + url: cAssetDetail.url, + }; + Object.assign(cAsset, updatedObj); + const url = cAssetDetail?.url; + if (url) { + const assetFolderPath = path.resolve(assetDirPath, assetUID); + if (!fs.existsSync(assetFolderPath)) fs.mkdirSync(assetFolderPath); + const assetFilePath = path.resolve(assetFolderPath, cAsset.filename); + const assetWriterStream = fs.createWriteStream(assetFilePath); + const data = await managementAPIClient + .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) + .asset(assetUID) + .download({ url, responseType: 'stream' }) + .then(({ data }) => data) + .catch((error) => { + throw error; + }); + assetWriterStream.on('error', (error) => { + throw error; + }); + data.pipe(assetWriterStream); + } + } + } + return cAsset; + }; + + const uploadAssets = async function () { + const assetFolderMap = JSON.parse(fs.readFileSync(path.resolve(filePath, 'folder-mapper.json'), 'utf8')); + const stackAPIClient = managementAPIClient.stack({ api_key: stackSDKInstance.api_key, branch_uid: branch }); + for (let i = 0; i < assetDetails?.length; i++) { + const asset = assetDetails[i]; + let requestOption = {}; + + requestOption.parent_uid = assetFolderMap[asset.parent_uid] || asset.parent_uid; + + if (asset.hasOwnProperty('description') && typeof asset.description === 'string') { + requestOption.description = asset.description; + } + + if (asset.hasOwnProperty('tags') && Array.isArray(asset.tags)) { + requestOption.tags = asset.tags; + } + + if (asset.hasOwnProperty('title') && typeof asset.title === 'string') { + requestOption.title = asset.title; + } + requestOption.upload = path.resolve(assetDirPath, asset.uid, asset.filename); + const res = await stackAPIClient + .asset() + .create(requestOption) + .then((asset) => asset) + .catch((error) => { + throw error; + }); + assetUIDMapper[asset.uid] = res && res.uid; + assetUrlMapper[asset.url] = res && res.url; + } + }; + + const updateEntryTask = () => { return { title: 'Update Entries', @@ -104,10 +387,35 @@ export function entryCreateUpdateScript(contentType) { .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) .contentType('${contentType}') .fetch(); + + for (let i = 0; i < compareBranchEntries?.items?.length; i++) { + assetRefPath[compareBranchEntries.items[i].uid] = [] + findAssets(contentType.schema, compareBranchEntries.items[i], assetRefPath[compareBranchEntries.items[i].uid]); + } - let flag = { - references: false - }; + for (let i = 0; i < baseBranchEntries?.items?.length; i++) { + assetRefPath[baseBranchEntries.items[i].uid] = [] + findAssets(contentType.schema, baseBranchEntries.items[i], assetRefPath[baseBranchEntries.items[i].uid]); + } + assetDetails = [...new Map(assetDetails.map((item) => [item['uid'], item])).values()]; + newAssetDetails = assetDetails; + + if (newAssetDetails && newAssetDetails.length) { + if (!fs.existsSync(assetDirPath)) { + fs.mkdirSync(assetDirPath); + } + for (let i = 0; i < newAssetDetails.length; i++) { + const asset = newAssetDetails[i]; + const updatedCAsset = await checkAndDownloadAsset(asset); + if(updatedCAsset === undefined){ + delete newAssetDetails[i]; + newAssetDetails.splice(i, 1); + --i; + } + newAssetDetails[i] = updatedCAsset; + } + await uploadAssets(); + } const references = await findReference(contentType.schema, '', flag); @@ -142,6 +450,7 @@ export function entryCreateUpdateScript(contentType) { 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; @@ -170,7 +479,7 @@ export function entryCreateUpdateScript(contentType) { 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 }); diff --git a/packages/contentstack-branches/src/utils/entry-update-script.ts b/packages/contentstack-branches/src/utils/entry-update-script.ts index 892d161733..8ea61363bd 100644 --- a/packages/contentstack-branches/src/utils/entry-update-script.ts +++ b/packages/contentstack-branches/src/utils/entry-update-script.ts @@ -1,5 +1,7 @@ export function entryUpdateScript(contentType) { return ` + const fs = require('fs'); + const path = require('path'); module.exports = async ({ migration, stackSDKInstance, managementAPIClient, config, branch, apiKey }) => { const keysToRemove = [ 'content_type_uid', @@ -23,6 +25,13 @@ export function entryUpdateScript(contentType) { ]; let compareBranch = config['compare-branch']; + let filePath = config['file-path'] || process.cwd(); + let assetDirPath = path.resolve(filePath, 'assets'); + let assetDetails = []; + let newAssetDetails = []; + let assetUIDMapper = {}; + let assetUrlMapper = {}; + let assetRefPath = {}; function converter(data) { let arr = []; @@ -85,6 +94,279 @@ export function entryUpdateScript(contentType) { return references; }; + const findAssets = function (schema, entry, refPath, path) { + for (const i in schema) { + const currentPath = path ? path + '[' + schema[i].uid : schema[i].uid; + if (schema[i].data_type === 'group' || schema[i].data_type === 'global_field') { + return findAssets(schema[i].schema, entry, refPath, currentPath); + } else if (schema[i].data_type === 'blocks') { + for (const block in schema[i].blocks) { + { + if (schema[i].blocks[block].schema) { + return findAssets( + schema[i].blocks[block].schema, + entry, + refPath, + currentPath + '[' + block + '][' + schema[i].blocks[block].uid + ']', + ); + } + } + } + } else if (schema[i].data_type === 'json' && schema[i].field_metadata.rich_text_type) { + findAssetIdsFromJsonRte(entry, schema, refPath, path); + } else if ( + schema[i].data_type === 'text' && + schema[i].field_metadata && + (schema[i].field_metadata.markdown || schema[i].field_metadata.rich_text_type) + ) { + findFileUrls(schema[i], entry); + } else if (schema[i].data_type === 'file') { + refPath.push(currentPath) + const imgDetails = getValueByPath(entry, currentPath); + if (imgDetails) { + const obj = { + uid: imgDetails.uid, + parent_uid: imgDetails.parent_uid, + description: imgDetails.description, + title: imgDetails.title, + filename: imgDetails.filename, + url: imgDetails.url, + }; + assetDetails.push(obj); + } + } + } + }; + + function findFileUrls(schema, _entry) { + let markdownRegEx; + let markdownMatch; + let text; + // Regex to detect v3 asset uri patterns + if (schema && schema.field_metadata && schema.field_metadata.markdown) { + text = marked(JSON.stringify(_entry)); + } else { + text = JSON.stringify(_entry); + } + markdownRegEx = new RegExp( + '(https://(assets|(eu-|azure-na-|azure-eu-)?images).contentstack.(io|com)/v3/assets/(.*?)/(.*?)/(.*?)/(.*?)(?="))', + 'g', + ); + while ((markdownMatch = markdownRegEx.exec(text)) !== null) { + if (markdownMatch && typeof markdownMatch[0] === 'string') { + const assetDetails = markdownMatch[0].split('/'); + //fetch assetUID from url + const assetUID = assetDetails && assetDetails[6]; + const obj = { + uid: assetUID, + url: markdownMatch[0], + }; + assetDetails.push(obj); + } + } + } + + function findAssetIdsFromJsonRte(entryObj, ctSchema) { + for (const element of ctSchema) { + switch (element.data_type) { + case 'blocks': { + if (entryObj[element.uid]) { + if (element.multiple) { + entryObj[element.uid].forEach((e) => { + let key = Object.keys(e).pop(); + let subBlock = element.blocks.filter((block) => block.uid === key).pop(); + findAssetIdsFromJsonRte(e[key], subBlock.schema); + }); + } + } + break; + } + case 'global_field': + case 'group': { + if (entryObj[element.uid]) { + if (element.multiple) { + entryObj[element.uid].forEach((e) => { + findAssetIdsFromJsonRte(e, element.schema); + }); + } else { + findAssetIdsFromJsonRte(entryObj[element.uid], element.schema); + } + } + break; + } + case 'json': { + if (entryObj[element.uid] && element.field_metadata.rich_text_type) { + if (element.multiple) { + entryObj[element.uid].forEach((jsonRteData) => { + gatherJsonRteAssetIds(jsonRteData); + }); + } else { + gatherJsonRteAssetIds(entryObj[element.uid]); + } + } + break; + } + } + } + } + + function gatherJsonRteAssetIds(jsonRteData) { + jsonRteData.children.forEach((element) => { + if (element.type) { + switch (element.type) { + case 'a': + case 'p': { + if (element.children && element.children.length > 0) { + gatherJsonRteAssetIds(element); + } + break; + } + case 'reference': { + if (Object.keys(element.attrs).length > 0 && element.attrs.type === 'asset') { + assetDetails.push({ uid: element.attrs['asset-uid'] }); + if (element.attrs['asset-link']) { + const assetDetails = element.attrs['asset-link'].split('/'); + //fetch assetUID from url + const assetUID = assetDetails && assetDetails[6]; + const obj = { + uid: assetUID, + url: element.attrs['asset-link'], + }; + assetDetails.push(obj); + } else if (element.attrs['href']) { + const assetDetails = element.attrs['href'].split('/'); + //fetch assetUID from url + const assetUID = assetDetails && assetDetails[6]; + const obj = { + uid: assetUID, + url: element.attrs['href'], + }; + assetDetails.push(obj); + } + } + if (element.children && element.children.length > 0) { + gatherJsonRteAssetIds(element); + } + break; + } + } + } + }); + } + + const updateAssetDetailsInEntries = function (entry) { + assetRefPath[entry.uid].forEach((refPath) => { + let imgDetails = entry[refPath]; + if (imgDetails !== 'undefined' && imgDetails?.uid) { + entry[refPath] = assetUIDMapper[imgDetails.uid]; + } else { + imgDetails = getValueByPath(entry, refPath); + if(imgDetails !== 'undefined' && imgDetails?.uid){ + updateValueByPath(entry, refPath, assetUIDMapper[imgDetails.uid]); + } + } + }); + entry = JSON.stringify(entry); + const assetUrls = assetDetails.map((asset) => asset.url); + const assetUIDs = assetDetails.map((asset) => asset.uid); + assetUrls.forEach(function (assetUrl) { + let mappedAssetUrl = assetUrlMapper[assetUrl]; + if (typeof mappedAssetUrl !== 'undefined') { + entry = entry.replace(assetUrl, mappedAssetUrl); + } + }); + + assetUIDs.forEach(function (assetUid) { + let uid = assetUIDMapper[assetUid]; + if (typeof uid !== 'undefined') { + entry = entry.replace(new RegExp(assetUid, 'img'), uid); + } + }); + return JSON.parse(entry); + }; + + const checkAndDownloadAsset = async function (cAsset) { + if (cAsset) { + const assetUID = cAsset.uid; + const bAssetDetail = await managementAPIClient + .stack({ api_key: stackSDKInstance.api_key, branch_uid: branch }) + .asset(assetUID) + .fetch() + .then((assets) => assets) + .catch((error) => {}); + if (bAssetDetail) return; + else { + const cAssetDetail = await managementAPIClient + .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) + .asset(assetUID) + .fetch() + .then((assets) => assets) + .catch((error) => {}); + const updatedObj = { + parent_uid: cAssetDetail.parent_uid, + description: cAssetDetail.description, + title: cAssetDetail.title, + filename: cAssetDetail.filename, + url: cAssetDetail.url, + }; + Object.assign(cAsset, updatedObj); + const url = cAssetDetail?.url; + if (url) { + const assetFolderPath = path.resolve(assetDirPath, assetUID); + if (!fs.existsSync(assetFolderPath)) fs.mkdirSync(assetFolderPath); + const assetFilePath = path.resolve(assetFolderPath, cAsset.filename); + const assetWriterStream = fs.createWriteStream(assetFilePath); + const data = await managementAPIClient + .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) + .asset(assetUID) + .download({ url, responseType: 'stream' }) + .then(({ data }) => data) + .catch((error) => { + throw error; + }); + assetWriterStream.on('error', (error) => { + throw error; + }); + data.pipe(assetWriterStream); + } + } + } + return cAsset; + }; + + const uploadAssets = async function () { + const assetFolderMap = JSON.parse(fs.readFileSync(path.resolve(filePath, 'folder-mapper.json'), 'utf8')); + const stackAPIClient = managementAPIClient.stack({ api_key: stackSDKInstance.api_key, branch_uid: branch }); + for (let i = 0; i < assetDetails?.length; i++) { + const asset = assetDetails[i]; + let requestOption = {}; + + requestOption.parent_uid = assetFolderMap[asset.parent_uid] || asset.parent_uid; + + if (asset.hasOwnProperty('description') && typeof asset.description === 'string') { + requestOption.description = asset.description; + } + + if (asset.hasOwnProperty('tags') && Array.isArray(asset.tags)) { + requestOption.tags = asset.tags; + } + + if (asset.hasOwnProperty('title') && typeof asset.title === 'string') { + requestOption.title = asset.title; + } + requestOption.upload = path.resolve(assetDirPath, asset.uid, asset.filename); + const res = await stackAPIClient + .asset() + .create(requestOption) + .then((asset) => asset) + .catch((error) => { + throw error; + }); + assetUIDMapper[asset.uid] = res && res.uid; + assetUrlMapper[asset.url] = res && res.url; + } + }; + const updateEntryTask = () => { return { title: 'Update Entries', @@ -105,6 +387,35 @@ export function entryUpdateScript(contentType) { .contentType('${contentType}') .fetch(); + for (let i = 0; i < compareBranchEntries?.items?.length; i++) { + assetRefPath[compareBranchEntries.items[i].uid] = [] + findAssets(contentType.schema, compareBranchEntries.items[i], assetRefPath[compareBranchEntries.items[i].uid]); + } + + for (let i = 0; i < baseBranchEntries?.items?.length; i++) { + assetRefPath[baseBranchEntries.items[i].uid] = [] + findAssets(contentType.schema, baseBranchEntries.items[i], assetRefPath[baseBranchEntries.items[i].uid]); + } + assetDetails = [...new Map(assetDetails.map((item) => [item['uid'], item])).values()]; + newAssetDetails = assetDetails; + + if (newAssetDetails && newAssetDetails.length) { + if (!fs.existsSync(assetDirPath)) { + fs.mkdirSync(assetDirPath); + } + for (let i = 0; i < newAssetDetails.length; i++) { + const asset = newAssetDetails[i]; + const updatedCAsset = await checkAndDownloadAsset(asset); + if(updatedCAsset === undefined){ + delete newAssetDetails[i]; + newAssetDetails.splice(i, 1); + --i; + } + newAssetDetails[i] = updatedCAsset; + } + await uploadAssets(); + } + let flag = { references: false }; @@ -142,6 +453,7 @@ export function entryUpdateScript(contentType) { 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; @@ -170,7 +482,7 @@ export function entryUpdateScript(contentType) { 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 }); diff --git a/packages/contentstack-migration/src/commands/cm/stacks/migration.js b/packages/contentstack-migration/src/commands/cm/stacks/migration.js index 0b7482817c..631245743c 100644 --- a/packages/contentstack-migration/src/commands/cm/stacks/migration.js +++ b/packages/contentstack-migration/src/commands/cm/stacks/migration.js @@ -160,7 +160,13 @@ class MigrationCommand extends Command { requests.splice(0, requests.length); } catch (error) { // errorHandler(null, null, null, error) - this.log(error); + if (error.message) { + this.log(error.message); + } else if (error.errorMessage) { + this.log(error.errorMessage); + }else{ + this.log(error) + } } } From 398fb77a71cfb641af362348a11170ec4a6186f4 Mon Sep 17 00:00:00 2001 From: Antony Date: Fri, 18 Aug 2023 17:27:14 +0530 Subject: [PATCH 14/24] Fix: Workflows typescript type definition fixes --- .../contentstack-import/src/import/modules/workflows.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/contentstack-import/src/import/modules/workflows.ts b/packages/contentstack-import/src/import/modules/workflows.ts index 29055c75ec..c1ab96975a 100644 --- a/packages/contentstack-import/src/import/modules/workflows.ts +++ b/packages/contentstack-import/src/import/modules/workflows.ts @@ -166,7 +166,11 @@ export default class ImportWorkflows extends BaseClass { ); } - updateNextAvailableStagesUid(workflow, newWorkflowStages, oldWorkflowStages) { + updateNextAvailableStagesUid( + workflow: Record, + newWorkflowStages: Record[], + oldWorkflowStages: Record[], + ) { newWorkflowStages = map(newWorkflowStages, (newStage, index) => { const oldStage = oldWorkflowStages[index]; if (!isEmpty(oldStage.next_available_stages)) { From 3f8fc669a00f3b7abff73a723addf257cc42f8c9 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Tue, 22 Aug 2023 16:48:50 +0530 Subject: [PATCH 15/24] fix: entries modified script --- .../src/utils/entry-create-update-script.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/contentstack-branches/src/utils/entry-create-update-script.ts b/packages/contentstack-branches/src/utils/entry-create-update-script.ts index 1253200038..8d9950bd4c 100644 --- a/packages/contentstack-branches/src/utils/entry-create-update-script.ts +++ b/packages/contentstack-branches/src/utils/entry-create-update-script.ts @@ -416,7 +416,11 @@ export function entryCreateUpdateScript(contentType) { } await uploadAssets(); } - + + let flag = { + references: false + }; + const references = await findReference(contentType.schema, '', flag); async function updateEntry(entry, entryDetails) { From d52ffc106383394b1c023c4e45f415568a5b69a0 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Tue, 22 Aug 2023 20:52:07 +0530 Subject: [PATCH 16/24] fix: asset fetch is not a function issue --- .../src/utils/entry-create-script.ts | 89 ++++++++---- .../src/utils/entry-create-update-script.ts | 137 +++++++++++------- .../src/utils/entry-update-script.ts | 85 ++++++++--- 3 files changed, 211 insertions(+), 100 deletions(-) diff --git a/packages/contentstack-branches/src/utils/entry-create-script.ts b/packages/contentstack-branches/src/utils/entry-create-script.ts index 0fdd215942..0d133daa0c 100644 --- a/packages/contentstack-branches/src/utils/entry-create-script.ts +++ b/packages/contentstack-branches/src/utils/entry-create-script.ts @@ -31,17 +31,22 @@ export function entryCreateScript(contentType) { let assetUIDMapper = {}; let assetUrlMapper = {}; let assetRefPath = {}; + let isAssetDownload = false; function getValueByPath(obj, path) { return path.split('[').reduce((o, key) => o && o[key.replace(/\]$/, '')], obj); } - function updateValueByPath(obj, path, newValue) { + function updateValueByPath(obj, path, newValue, type, index) { path.split('[').reduce((o, key, index, arr) => { if (index === arr.length - 1) { - o[key.replace(/\]$/, '')][0].uid = newValue; + if (type === 'file') { + o[key.replace(/]$/, '')][index] = newValue; + } else { + o[key.replace(/]$/, '')][0].uid = newValue; + } } else { - return o[key.replace(/\]$/, '')]; + return o[key.replace(/]$/, '')]; } }, obj); } @@ -101,16 +106,32 @@ export function entryCreateScript(contentType) { } else if (schema[i].data_type === 'file') { refPath.push(currentPath) const imgDetails = getValueByPath(entry, currentPath); - if (imgDetails) { - const obj = { - uid: imgDetails.uid, - parent_uid: imgDetails.parent_uid, - description: imgDetails.description, - title: imgDetails.title, - filename: imgDetails.filename, - url: imgDetails.url, - }; - cAssetDetails.push(obj); + if (schema[i].multiple) { + if (imgDetails && imgDetails.length) { + imgDetails.forEach((img) => { + const obj = { + uid: img.uid, + parent_uid: img.parent_uid, + description: img.description, + title: img.title, + filename: img.filename, + url: img.url, + }; + cAssetDetails.push(obj); + }); + } + } else { + if (imgDetails) { + const obj = { + uid: imgDetails.uid, + parent_uid: imgDetails.parent_uid, + description: imgDetails.description, + title: imgDetails.title, + filename: imgDetails.filename, + url: imgDetails.url, + }; + cAssetDetails.push(obj); + } } } } @@ -235,12 +256,26 @@ export function entryCreateScript(contentType) { const updateAssetDetailsInEntries = function (entry) { assetRefPath[entry.uid].forEach((refPath) => { let imgDetails = entry[refPath]; - if (imgDetails !== 'undefined' && imgDetails?.uid) { - entry[refPath] = assetUIDMapper[imgDetails.uid]; + if (imgDetails !== undefined) { + if (imgDetails && !Array.isArray(imgDetails)) { + entry[refPath] = assetUIDMapper[imgDetails.uid]; + } else if (imgDetails && Array.isArray(imgDetails)) { + for (let i = 0; i < imgDetails.length; i++) { + const img = imgDetails[i]; + entry[refPath][i] = assetUIDMapper[img.uid]; + } + } } else { imgDetails = getValueByPath(entry, refPath); - if(imgDetails !== 'undefined' && imgDetails?.uid){ - updateValueByPath(entry, refPath, assetUIDMapper[imgDetails.uid]); + if (imgDetails && !Array.isArray(imgDetails)) { + const imgUID = imgDetails?.uid; + updateValueByPath(entry, refPath, assetUIDMapper[imgUID], 'file', 0); + } else if (imgDetails && Array.isArray(imgDetails)) { + for (let i = 0; i < imgDetails.length; i++) { + const img = imgDetails[i]; + const imgUID = img?.uid; + updateValueByPath(entry, refPath, assetUIDMapper[imgUID], 'file', i); + } } } }); @@ -264,16 +299,21 @@ export function entryCreateScript(contentType) { }; const checkAndDownloadAsset = async function (cAsset) { - if (cAsset) { - const assetUID = cAsset.uid; + const assetUID = cAsset?.uid; + if (cAsset && assetUID) { const bAssetDetail = await managementAPIClient .stack({ api_key: stackSDKInstance.api_key, branch_uid: branch }) .asset(assetUID) .fetch() .then((assets) => assets) .catch((error) => {}); - if (bAssetDetail) return; + if (bAssetDetail) { + assetUIDMapper[cAsset.uid] = bAssetDetail.uid; + assetUrlMapper[cAsset.url] = bAssetDetail.url; + return false; + } else { + isAssetDownload = true; const cAssetDetail = await managementAPIClient .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) .asset(assetUID) @@ -380,14 +420,11 @@ export function entryCreateScript(contentType) { for (let i = 0; i < cAssetDetails.length; i++) { const asset = cAssetDetails[i]; const updatedCAsset = await checkAndDownloadAsset(asset); - if(updatedCAsset === undefined){ - delete cAssetDetails[i]; - cAssetDetails.splice(i, 1); - --i; + if (updatedCAsset) { + cAssetDetails[i] = updatedCAsset; } - cAssetDetails[i] = updatedCAsset; } - await uploadAssets(); + if (isAssetDownload) await uploadAssets(); } let flag = { diff --git a/packages/contentstack-branches/src/utils/entry-create-update-script.ts b/packages/contentstack-branches/src/utils/entry-create-update-script.ts index 8d9950bd4c..b91e3cbf3b 100644 --- a/packages/contentstack-branches/src/utils/entry-create-update-script.ts +++ b/packages/contentstack-branches/src/utils/entry-create-update-script.ts @@ -32,6 +32,7 @@ export function entryCreateUpdateScript(contentType) { let assetUIDMapper = {}; let assetUrlMapper = {}; let assetRefPath = {}; + let isAssetDownload = false; function converter(data) { let arr = []; @@ -58,15 +59,19 @@ export function entryCreateUpdateScript(contentType) { return path.split('[').reduce((o, key) => o && o[key.replace(/\]$/, '')], obj); } - function updateValueByPath(obj, path, newValue) { - path.split('[').reduce((o, key, index, arr) => { - if (index === arr.length - 1) { - o[key.replace(/\]$/, '')][0].uid = newValue; + function updateValueByPath(obj, path, newValue, type, index) { + path.split('[').reduce((o, key, index, arr) => { + if (index === arr.length - 1) { + if (type === 'file') { + o[key.replace(/]$/, '')][index] = newValue; } else { - return o[key.replace(/\]$/, '')]; + o[key.replace(/]$/, '')][0].uid = newValue; } - }, obj); - } + } else { + return o[key.replace(/]$/, '')]; + } + }, obj); + } const findReference = function (schema, path, flag) { let references = []; @@ -94,35 +99,50 @@ export function entryCreateUpdateScript(contentType) { return references; }; - const findAssets = function (schema, entry, refPath, path) { - for (const i in schema) { - const currentPath = path ? path + '[' + schema[i].uid : schema[i].uid; - if (schema[i].data_type === 'group' || schema[i].data_type === 'global_field') { - return findAssets(schema[i].schema, entry, refPath, currentPath); - } else if (schema[i].data_type === 'blocks') { - for (const block in schema[i].blocks) { - { - if (schema[i].blocks[block].schema) { - return findAssets( - schema[i].blocks[block].schema, - entry, - refPath, - currentPath + '[' + block + '][' + schema[i].blocks[block].uid + ']', - ); - } + const findAssets = function (schema, entry, refPath, path) { + for (const i in schema) { + const currentPath = path ? path + '[' + schema[i].uid : schema[i].uid; + if (schema[i].data_type === 'group' || schema[i].data_type === 'global_field') { + return findAssets(schema[i].schema, entry, refPath, currentPath); + } else if (schema[i].data_type === 'blocks') { + for (const block in schema[i].blocks) { + { + if (schema[i].blocks[block].schema) { + return findAssets( + schema[i].blocks[block].schema, + entry, + refPath, + currentPath + '[' + block + '][' + schema[i].blocks[block].uid + ']', + ); } } - } else if (schema[i].data_type === 'json' && schema[i].field_metadata.rich_text_type) { - findAssetIdsFromJsonRte(entry, schema, refPath, path); - } else if ( - schema[i].data_type === 'text' && - schema[i].field_metadata && - (schema[i].field_metadata.markdown || schema[i].field_metadata.rich_text_type) - ) { - findFileUrls(schema[i], entry); - } else if (schema[i].data_type === 'file') { - refPath.push(currentPath) - const imgDetails = getValueByPath(entry, currentPath); + } + } else if (schema[i].data_type === 'json' && schema[i].field_metadata.rich_text_type) { + findAssetIdsFromJsonRte(entry, schema, refPath, path); + } else if ( + schema[i].data_type === 'text' && + schema[i].field_metadata && + (schema[i].field_metadata.markdown || schema[i].field_metadata.rich_text_type) + ) { + findFileUrls(schema[i], entry); + } else if (schema[i].data_type === 'file') { + refPath.push(currentPath) + const imgDetails = getValueByPath(entry, currentPath); + if (schema[i].multiple) { + if (imgDetails && imgDetails.length) { + imgDetails.forEach((img) => { + const obj = { + uid: img.uid, + parent_uid: img.parent_uid, + description: img.description, + title: img.title, + filename: img.filename, + url: img.url, + }; + assetDetails.push(obj); + }); + } + } else { if (imgDetails) { const obj = { uid: imgDetails.uid, @@ -136,7 +156,8 @@ export function entryCreateUpdateScript(contentType) { } } } - }; + } + }; function findFileUrls(schema, _entry) { let markdownRegEx; @@ -255,17 +276,31 @@ export function entryCreateUpdateScript(contentType) { } const updateAssetDetailsInEntries = function (entry) { - assetRefPath[entry.uid].forEach((refPath) => { - let imgDetails = entry[refPath]; - if (imgDetails !== 'undefined' && imgDetails?.uid) { + assetRefPath[entry.uid].forEach((refPath) => { + let imgDetails = entry[refPath]; + if (imgDetails !== undefined) { + if (imgDetails && !Array.isArray(imgDetails)) { entry[refPath] = assetUIDMapper[imgDetails.uid]; - } else { - imgDetails = getValueByPath(entry, refPath); - if(imgDetails !== 'undefined' && imgDetails?.uid){ - updateValueByPath(entry, refPath, assetUIDMapper[imgDetails.uid]); + } else if (imgDetails && imgDetailsArray.isArray(imgDetails)) { + for (let i = 0; i < imgDetails.length; i++) { + const img = imgDetails[i]; + entry[refPath][i] = assetUIDMapper[img.uid]; } } - }); + } else { + imgDetails = getValueByPath(entry, refPath); + if (imgDetails && !Array.isArray(imgDetails)) { + const imgUID = imgDetails?.uid; + updateValueByPath(entry, refPath, assetUIDMapper[imgUID], 'file', 0); + } else if (imgDetails && Array.isArray(imgDetails)) { + for (let i = 0; i < imgDetails.length; i++) { + const img = imgDetails[i]; + const imgUID = img?.uid; + updateValueByPath(entry, refPath, assetUIDMapper[imgUID], 'file', i); + } + } + } + }); entry = JSON.stringify(entry); const assetUrls = assetDetails.map((asset) => asset.url); const assetUIDs = assetDetails.map((asset) => asset.uid); @@ -294,8 +329,13 @@ export function entryCreateUpdateScript(contentType) { .fetch() .then((assets) => assets) .catch((error) => {}); - if (bAssetDetail) return; + if (bAssetDetail) { + assetUIDMapper[cAsset.uid] = bAssetDetail.uid; + assetUrlMapper[cAsset.url] = bAssetDetail.url; + return false; + } else { + isAssetDownload = true; const cAssetDetail = await managementAPIClient .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) .asset(assetUID) @@ -407,14 +447,11 @@ export function entryCreateUpdateScript(contentType) { for (let i = 0; i < newAssetDetails.length; i++) { const asset = newAssetDetails[i]; const updatedCAsset = await checkAndDownloadAsset(asset); - if(updatedCAsset === undefined){ - delete newAssetDetails[i]; - newAssetDetails.splice(i, 1); - --i; + if(updatedCAsset){ + newAssetDetails[i] = updatedCAsset; } - newAssetDetails[i] = updatedCAsset; } - await uploadAssets(); + if (isAssetDownload) await uploadAssets(); } let flag = { diff --git a/packages/contentstack-branches/src/utils/entry-update-script.ts b/packages/contentstack-branches/src/utils/entry-update-script.ts index 8ea61363bd..75755c2926 100644 --- a/packages/contentstack-branches/src/utils/entry-update-script.ts +++ b/packages/contentstack-branches/src/utils/entry-update-script.ts @@ -32,6 +32,7 @@ export function entryUpdateScript(contentType) { let assetUIDMapper = {}; let assetUrlMapper = {}; let assetRefPath = {}; + let isAssetDownload = false; function converter(data) { let arr = []; @@ -58,12 +59,16 @@ export function entryUpdateScript(contentType) { return path.split('[').reduce((o, key) => o && o[key.replace(/\]$/, '')], obj); } - function updateValueByPath(obj, path, newValue) { + function updateValueByPath(obj, path, newValue, type, index) { path.split('[').reduce((o, key, index, arr) => { if (index === arr.length - 1) { - o[key.replace(/\]$/, '')][0].uid = newValue; + if (type === 'file') { + o[key.replace(/]$/, '')][index] = newValue; + } else { + o[key.replace(/]$/, '')][0].uid = newValue; + } } else { - return o[key.replace(/\]$/, '')]; + return o[key.replace(/]$/, '')]; } }, obj); } @@ -123,16 +128,32 @@ export function entryUpdateScript(contentType) { } else if (schema[i].data_type === 'file') { refPath.push(currentPath) const imgDetails = getValueByPath(entry, currentPath); - if (imgDetails) { - const obj = { - uid: imgDetails.uid, - parent_uid: imgDetails.parent_uid, - description: imgDetails.description, - title: imgDetails.title, - filename: imgDetails.filename, - url: imgDetails.url, - }; - assetDetails.push(obj); + if (schema[i].multiple) { + if (imgDetails && imgDetails.length) { + imgDetails.forEach((img) => { + const obj = { + uid: img.uid, + parent_uid: img.parent_uid, + description: img.description, + title: img.title, + filename: img.filename, + url: img.url, + }; + assetDetails.push(obj); + }); + } + } else { + if (imgDetails) { + const obj = { + uid: imgDetails.uid, + parent_uid: imgDetails.parent_uid, + description: imgDetails.description, + title: imgDetails.title, + filename: imgDetails.filename, + url: imgDetails.url, + }; + assetDetails.push(obj); + } } } } @@ -257,12 +278,26 @@ export function entryUpdateScript(contentType) { const updateAssetDetailsInEntries = function (entry) { assetRefPath[entry.uid].forEach((refPath) => { let imgDetails = entry[refPath]; - if (imgDetails !== 'undefined' && imgDetails?.uid) { - entry[refPath] = assetUIDMapper[imgDetails.uid]; + if (imgDetails !== undefined) { + if (imgDetails && !Array.isArray(imgDetails)) { + entry[refPath] = assetUIDMapper[imgDetails.uid]; + } else if (imgDetails && imgDetailsArray.isArray(imgDetails)) { + for (let i = 0; i < imgDetails.length; i++) { + const img = imgDetails[i]; + entry[refPath][i] = assetUIDMapper[img.uid]; + } + } } else { imgDetails = getValueByPath(entry, refPath); - if(imgDetails !== 'undefined' && imgDetails?.uid){ - updateValueByPath(entry, refPath, assetUIDMapper[imgDetails.uid]); + if (imgDetails && !Array.isArray(imgDetails)) { + const imgUID = imgDetails?.uid; + updateValueByPath(entry, refPath, assetUIDMapper[imgUID], 'file', 0); + } else if (imgDetails && Array.isArray(imgDetails)) { + for (let i = 0; i < imgDetails.length; i++) { + const img = imgDetails[i]; + const imgUID = img?.uid; + updateValueByPath(entry, refPath, assetUIDMapper[imgUID], 'file', i); + } } } }); @@ -294,8 +329,13 @@ export function entryUpdateScript(contentType) { .fetch() .then((assets) => assets) .catch((error) => {}); - if (bAssetDetail) return; + if (bAssetDetail) { + assetUIDMapper[cAsset.uid] = bAssetDetail.uid; + assetUrlMapper[cAsset.url] = bAssetDetail.url; + return false; + } else { + isAssetDownload = true; const cAssetDetail = await managementAPIClient .stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch }) .asset(assetUID) @@ -406,14 +446,11 @@ export function entryUpdateScript(contentType) { for (let i = 0; i < newAssetDetails.length; i++) { const asset = newAssetDetails[i]; const updatedCAsset = await checkAndDownloadAsset(asset); - if(updatedCAsset === undefined){ - delete newAssetDetails[i]; - newAssetDetails.splice(i, 1); - --i; + if(updatedCAsset){ + newAssetDetails[i] = updatedCAsset; } - newAssetDetails[i] = updatedCAsset; } - await uploadAssets(); + if (isAssetDownload) await uploadAssets(); } let flag = { From 82398fc3901575df1d8665971595930121ed722d Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Wed, 23 Aug 2023 11:46:09 +0530 Subject: [PATCH 17/24] fix: entry valid file upload issue --- .../contentstack-branches/src/utils/entry-create-script.ts | 4 ++-- .../src/utils/entry-create-update-script.ts | 4 ++-- .../contentstack-branches/src/utils/entry-update-script.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/contentstack-branches/src/utils/entry-create-script.ts b/packages/contentstack-branches/src/utils/entry-create-script.ts index 0d133daa0c..eeeec0c385 100644 --- a/packages/contentstack-branches/src/utils/entry-create-script.ts +++ b/packages/contentstack-branches/src/utils/entry-create-script.ts @@ -81,12 +81,12 @@ export function entryCreateScript(contentType) { for (const i in schema) { const currentPath = path ? path + '[' + schema[i].uid : schema[i].uid; if (schema[i].data_type === 'group' || schema[i].data_type === 'global_field') { - return findAssets(schema[i].schema, entry, refPath, currentPath); + findAssets(schema[i].schema, entry, refPath, currentPath); } else if (schema[i].data_type === 'blocks') { for (const block in schema[i].blocks) { { if (schema[i].blocks[block].schema) { - return findAssets( + findAssets( schema[i].blocks[block].schema, entry, refPath, diff --git a/packages/contentstack-branches/src/utils/entry-create-update-script.ts b/packages/contentstack-branches/src/utils/entry-create-update-script.ts index b91e3cbf3b..7a96e60c08 100644 --- a/packages/contentstack-branches/src/utils/entry-create-update-script.ts +++ b/packages/contentstack-branches/src/utils/entry-create-update-script.ts @@ -103,12 +103,12 @@ export function entryCreateUpdateScript(contentType) { for (const i in schema) { const currentPath = path ? path + '[' + schema[i].uid : schema[i].uid; if (schema[i].data_type === 'group' || schema[i].data_type === 'global_field') { - return findAssets(schema[i].schema, entry, refPath, currentPath); + findAssets(schema[i].schema, entry, refPath, currentPath); } else if (schema[i].data_type === 'blocks') { for (const block in schema[i].blocks) { { if (schema[i].blocks[block].schema) { - return findAssets( + findAssets( schema[i].blocks[block].schema, entry, refPath, diff --git a/packages/contentstack-branches/src/utils/entry-update-script.ts b/packages/contentstack-branches/src/utils/entry-update-script.ts index 75755c2926..a32a4b4b8d 100644 --- a/packages/contentstack-branches/src/utils/entry-update-script.ts +++ b/packages/contentstack-branches/src/utils/entry-update-script.ts @@ -103,12 +103,12 @@ export function entryUpdateScript(contentType) { for (const i in schema) { const currentPath = path ? path + '[' + schema[i].uid : schema[i].uid; if (schema[i].data_type === 'group' || schema[i].data_type === 'global_field') { - return findAssets(schema[i].schema, entry, refPath, currentPath); + findAssets(schema[i].schema, entry, refPath, currentPath); } else if (schema[i].data_type === 'blocks') { for (const block in schema[i].blocks) { { if (schema[i].blocks[block].schema) { - return findAssets( + findAssets( schema[i].blocks[block].schema, entry, refPath, From 8175914b173f5b6d33c0527a2208b11ca4d6758f Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Wed, 23 Aug 2023 15:21:51 +0530 Subject: [PATCH 18/24] fix: json rte field --- packages/contentstack-branches/src/utils/entry-create-script.ts | 2 +- .../src/utils/entry-create-update-script.ts | 2 +- packages/contentstack-branches/src/utils/entry-update-script.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/contentstack-branches/src/utils/entry-create-script.ts b/packages/contentstack-branches/src/utils/entry-create-script.ts index eeeec0c385..db18880b75 100644 --- a/packages/contentstack-branches/src/utils/entry-create-script.ts +++ b/packages/contentstack-branches/src/utils/entry-create-script.ts @@ -96,7 +96,7 @@ export function entryCreateScript(contentType) { } } } else if (schema[i].data_type === 'json' && schema[i].field_metadata.rich_text_type) { - findAssetIdsFromJsonRte(entry, schema, refPath, path); + findAssetIdsFromJsonRte(entry, schema[i].schema, refPath, path); } else if ( schema[i].data_type === 'text' && schema[i].field_metadata && diff --git a/packages/contentstack-branches/src/utils/entry-create-update-script.ts b/packages/contentstack-branches/src/utils/entry-create-update-script.ts index 7a96e60c08..40378c2065 100644 --- a/packages/contentstack-branches/src/utils/entry-create-update-script.ts +++ b/packages/contentstack-branches/src/utils/entry-create-update-script.ts @@ -118,7 +118,7 @@ export function entryCreateUpdateScript(contentType) { } } } else if (schema[i].data_type === 'json' && schema[i].field_metadata.rich_text_type) { - findAssetIdsFromJsonRte(entry, schema, refPath, path); + findAssetIdsFromJsonRte(entry, schema[i].schema, refPath, path); } else if ( schema[i].data_type === 'text' && schema[i].field_metadata && diff --git a/packages/contentstack-branches/src/utils/entry-update-script.ts b/packages/contentstack-branches/src/utils/entry-update-script.ts index a32a4b4b8d..92327e42db 100644 --- a/packages/contentstack-branches/src/utils/entry-update-script.ts +++ b/packages/contentstack-branches/src/utils/entry-update-script.ts @@ -118,7 +118,7 @@ export function entryUpdateScript(contentType) { } } } else if (schema[i].data_type === 'json' && schema[i].field_metadata.rich_text_type) { - findAssetIdsFromJsonRte(entry, schema, refPath, path); + findAssetIdsFromJsonRte(entry, schema[i].schema, refPath, path); } else if ( schema[i].data_type === 'text' && schema[i].field_metadata && From 2dfda6214b5b2e1b7ee7f8f8a4e2d0c0e20044ed Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Wed, 23 Aug 2023 16:51:35 +0530 Subject: [PATCH 19/24] fix: global field reference issue --- .../contentstack-branches/src/utils/entry-create-script.ts | 2 +- .../src/utils/entry-create-update-script.ts | 4 ++-- .../contentstack-branches/src/utils/entry-update-script.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/contentstack-branches/src/utils/entry-create-script.ts b/packages/contentstack-branches/src/utils/entry-create-script.ts index db18880b75..d55fd42581 100644 --- a/packages/contentstack-branches/src/utils/entry-create-script.ts +++ b/packages/contentstack-branches/src/utils/entry-create-script.ts @@ -46,7 +46,7 @@ export function entryCreateScript(contentType) { o[key.replace(/]$/, '')][0].uid = newValue; } } else { - return o[key.replace(/]$/, '')]; + return o[key.replace(/\]$/, '')]; } }, obj); } diff --git a/packages/contentstack-branches/src/utils/entry-create-update-script.ts b/packages/contentstack-branches/src/utils/entry-create-update-script.ts index 40378c2065..2ef86ce925 100644 --- a/packages/contentstack-branches/src/utils/entry-create-update-script.ts +++ b/packages/contentstack-branches/src/utils/entry-create-update-script.ts @@ -68,7 +68,7 @@ export function entryCreateUpdateScript(contentType) { o[key.replace(/]$/, '')][0].uid = newValue; } } else { - return o[key.replace(/]$/, '')]; + return o[key.replace(/\]$/, '')]; } }, obj); } @@ -281,7 +281,7 @@ export function entryCreateUpdateScript(contentType) { if (imgDetails !== undefined) { if (imgDetails && !Array.isArray(imgDetails)) { entry[refPath] = assetUIDMapper[imgDetails.uid]; - } else if (imgDetails && imgDetailsArray.isArray(imgDetails)) { + } else if (imgDetails && Array.isArray(imgDetails)) { for (let i = 0; i < imgDetails.length; i++) { const img = imgDetails[i]; entry[refPath][i] = assetUIDMapper[img.uid]; diff --git a/packages/contentstack-branches/src/utils/entry-update-script.ts b/packages/contentstack-branches/src/utils/entry-update-script.ts index 92327e42db..b39c3e2397 100644 --- a/packages/contentstack-branches/src/utils/entry-update-script.ts +++ b/packages/contentstack-branches/src/utils/entry-update-script.ts @@ -68,7 +68,7 @@ export function entryUpdateScript(contentType) { o[key.replace(/]$/, '')][0].uid = newValue; } } else { - return o[key.replace(/]$/, '')]; + return o[key.replace(/\]$/, '')]; } }, obj); } @@ -281,7 +281,7 @@ export function entryUpdateScript(contentType) { if (imgDetails !== undefined) { if (imgDetails && !Array.isArray(imgDetails)) { entry[refPath] = assetUIDMapper[imgDetails.uid]; - } else if (imgDetails && imgDetailsArray.isArray(imgDetails)) { + } else if (imgDetails && Array.isArray(imgDetails)) { for (let i = 0; i < imgDetails.length; i++) { const img = imgDetails[i]; entry[refPath][i] = assetUIDMapper[img.uid]; From 73ca7b6a143874f06e49a54db468f4bcccc22d66 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Wed, 23 Aug 2023 20:28:58 +0530 Subject: [PATCH 20/24] fix: json rte ref issue --- .../src/utils/entry-create-script.ts | 68 ++++++++++--------- .../src/utils/entry-create-update-script.ts | 68 ++++++++++--------- .../src/utils/entry-update-script.ts | 68 ++++++++++--------- 3 files changed, 105 insertions(+), 99 deletions(-) diff --git a/packages/contentstack-branches/src/utils/entry-create-script.ts b/packages/contentstack-branches/src/utils/entry-create-script.ts index d55fd42581..8b637ea2a6 100644 --- a/packages/contentstack-branches/src/utils/entry-create-script.ts +++ b/packages/contentstack-branches/src/utils/entry-create-script.ts @@ -96,7 +96,7 @@ export function entryCreateScript(contentType) { } } } else if (schema[i].data_type === 'json' && schema[i].field_metadata.rich_text_type) { - findAssetIdsFromJsonRte(entry, schema[i].schema, refPath, path); + findAssetIdsFromJsonRte(entry, schema, refPath, path); } else if ( schema[i].data_type === 'text' && schema[i].field_metadata && @@ -166,44 +166,46 @@ export function entryCreateScript(contentType) { } function findAssetIdsFromJsonRte(entryObj, ctSchema) { - for (const element of ctSchema) { - switch (element.data_type) { - case 'blocks': { - if (entryObj[element.uid]) { - if (element.multiple) { - entryObj[element.uid].forEach((e) => { - let key = Object.keys(e).pop(); - let subBlock = element.blocks.filter((block) => block.uid === key).pop(); - findAssetIdsFromJsonRte(e[key], subBlock.schema); - }); + if(ctSchema !== undefined || ctSchema !== null){ + for (const element of ctSchema) { + switch (element.data_type) { + case 'blocks': { + if (entryObj[element.uid]) { + if (element.multiple) { + entryObj[element.uid].forEach((e) => { + let key = Object.keys(e).pop(); + let subBlock = element.blocks.filter((block) => block.uid === key).pop(); + findAssetIdsFromJsonRte(e[key], subBlock.schema); + }); + } } + break; } - break; - } - case 'global_field': - case 'group': { - if (entryObj[element.uid]) { - if (element.multiple) { - entryObj[element.uid].forEach((e) => { - findAssetIdsFromJsonRte(e, element.schema); - }); - } else { - findAssetIdsFromJsonRte(entryObj[element.uid], element.schema); + case 'global_field': + case 'group': { + if (entryObj[element.uid]) { + if (element.multiple) { + entryObj[element.uid].forEach((e) => { + findAssetIdsFromJsonRte(e, element.schema); + }); + } else { + findAssetIdsFromJsonRte(entryObj[element.uid], element.schema); + } } + break; } - break; - } - case 'json': { - if (entryObj[element.uid] && element.field_metadata.rich_text_type) { - if (element.multiple) { - entryObj[element.uid].forEach((jsonRteData) => { - gatherJsonRteAssetIds(jsonRteData); - }); - } else { - gatherJsonRteAssetIds(entryObj[element.uid]); + case 'json': { + if (entryObj[element.uid] && element.field_metadata.rich_text_type) { + if (element.multiple) { + entryObj[element.uid].forEach((jsonRteData) => { + gatherJsonRteAssetIds(jsonRteData); + }); + } else { + gatherJsonRteAssetIds(entryObj[element.uid]); + } } + break; } - break; } } } diff --git a/packages/contentstack-branches/src/utils/entry-create-update-script.ts b/packages/contentstack-branches/src/utils/entry-create-update-script.ts index 2ef86ce925..94d89882c5 100644 --- a/packages/contentstack-branches/src/utils/entry-create-update-script.ts +++ b/packages/contentstack-branches/src/utils/entry-create-update-script.ts @@ -118,7 +118,7 @@ export function entryCreateUpdateScript(contentType) { } } } else if (schema[i].data_type === 'json' && schema[i].field_metadata.rich_text_type) { - findAssetIdsFromJsonRte(entry, schema[i].schema, refPath, path); + findAssetIdsFromJsonRte(entry, schema, refPath, path); } else if ( schema[i].data_type === 'text' && schema[i].field_metadata && @@ -188,44 +188,46 @@ export function entryCreateUpdateScript(contentType) { } function findAssetIdsFromJsonRte(entryObj, ctSchema) { - for (const element of ctSchema) { - switch (element.data_type) { - case 'blocks': { - if (entryObj[element.uid]) { - if (element.multiple) { - entryObj[element.uid].forEach((e) => { - let key = Object.keys(e).pop(); - let subBlock = element.blocks.filter((block) => block.uid === key).pop(); - findAssetIdsFromJsonRte(e[key], subBlock.schema); - }); + if(ctSchema !== undefined || ctSchema !== null){ + for (const element of ctSchema) { + switch (element.data_type) { + case 'blocks': { + if (entryObj[element.uid]) { + if (element.multiple) { + entryObj[element.uid].forEach((e) => { + let key = Object.keys(e).pop(); + let subBlock = element.blocks.filter((block) => block.uid === key).pop(); + findAssetIdsFromJsonRte(e[key], subBlock.schema); + }); + } } + break; } - break; - } - case 'global_field': - case 'group': { - if (entryObj[element.uid]) { - if (element.multiple) { - entryObj[element.uid].forEach((e) => { - findAssetIdsFromJsonRte(e, element.schema); - }); - } else { - findAssetIdsFromJsonRte(entryObj[element.uid], element.schema); + case 'global_field': + case 'group': { + if (entryObj[element.uid]) { + if (element.multiple) { + entryObj[element.uid].forEach((e) => { + findAssetIdsFromJsonRte(e, element.schema); + }); + } else { + findAssetIdsFromJsonRte(entryObj[element.uid], element.schema); + } } + break; } - break; - } - case 'json': { - if (entryObj[element.uid] && element.field_metadata.rich_text_type) { - if (element.multiple) { - entryObj[element.uid].forEach((jsonRteData) => { - gatherJsonRteAssetIds(jsonRteData); - }); - } else { - gatherJsonRteAssetIds(entryObj[element.uid]); + case 'json': { + if (entryObj[element.uid] && element.field_metadata.rich_text_type) { + if (element.multiple) { + entryObj[element.uid].forEach((jsonRteData) => { + gatherJsonRteAssetIds(jsonRteData); + }); + } else { + gatherJsonRteAssetIds(entryObj[element.uid]); + } } + break; } - break; } } } diff --git a/packages/contentstack-branches/src/utils/entry-update-script.ts b/packages/contentstack-branches/src/utils/entry-update-script.ts index b39c3e2397..744c4dc8b9 100644 --- a/packages/contentstack-branches/src/utils/entry-update-script.ts +++ b/packages/contentstack-branches/src/utils/entry-update-script.ts @@ -118,7 +118,7 @@ export function entryUpdateScript(contentType) { } } } else if (schema[i].data_type === 'json' && schema[i].field_metadata.rich_text_type) { - findAssetIdsFromJsonRte(entry, schema[i].schema, refPath, path); + findAssetIdsFromJsonRte(entry, schema, refPath, path); } else if ( schema[i].data_type === 'text' && schema[i].field_metadata && @@ -188,44 +188,46 @@ export function entryUpdateScript(contentType) { } function findAssetIdsFromJsonRte(entryObj, ctSchema) { - for (const element of ctSchema) { - switch (element.data_type) { - case 'blocks': { - if (entryObj[element.uid]) { - if (element.multiple) { - entryObj[element.uid].forEach((e) => { - let key = Object.keys(e).pop(); - let subBlock = element.blocks.filter((block) => block.uid === key).pop(); - findAssetIdsFromJsonRte(e[key], subBlock.schema); - }); + if(ctSchema !== undefined || ctSchema !== null){ + for (const element of ctSchema) { + switch (element.data_type) { + case 'blocks': { + if (entryObj[element.uid]) { + if (element.multiple) { + entryObj[element.uid].forEach((e) => { + let key = Object.keys(e).pop(); + let subBlock = element.blocks.filter((block) => block.uid === key).pop(); + findAssetIdsFromJsonRte(e[key], subBlock.schema); + }); + } } + break; } - break; - } - case 'global_field': - case 'group': { - if (entryObj[element.uid]) { - if (element.multiple) { - entryObj[element.uid].forEach((e) => { - findAssetIdsFromJsonRte(e, element.schema); - }); - } else { - findAssetIdsFromJsonRte(entryObj[element.uid], element.schema); + case 'global_field': + case 'group': { + if (entryObj[element.uid]) { + if (element.multiple) { + entryObj[element.uid].forEach((e) => { + findAssetIdsFromJsonRte(e, element.schema); + }); + } else { + findAssetIdsFromJsonRte(entryObj[element.uid], element.schema); + } } + break; } - break; - } - case 'json': { - if (entryObj[element.uid] && element.field_metadata.rich_text_type) { - if (element.multiple) { - entryObj[element.uid].forEach((jsonRteData) => { - gatherJsonRteAssetIds(jsonRteData); - }); - } else { - gatherJsonRteAssetIds(entryObj[element.uid]); + case 'json': { + if (entryObj[element.uid] && element.field_metadata.rich_text_type) { + if (element.multiple) { + entryObj[element.uid].forEach((jsonRteData) => { + gatherJsonRteAssetIds(jsonRteData); + }); + } else { + gatherJsonRteAssetIds(entryObj[element.uid]); + } } + break; } - break; } } } From 67287c23efb3c3cbc8726de36d93e3ddf55db3c2 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Thu, 24 Aug 2023 12:24:25 +0530 Subject: [PATCH 21/24] fix: ctSchema is not iterable --- packages/contentstack-branches/src/utils/entry-create-script.ts | 2 +- .../src/utils/entry-create-update-script.ts | 2 +- packages/contentstack-branches/src/utils/entry-update-script.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/contentstack-branches/src/utils/entry-create-script.ts b/packages/contentstack-branches/src/utils/entry-create-script.ts index 8b637ea2a6..5739966094 100644 --- a/packages/contentstack-branches/src/utils/entry-create-script.ts +++ b/packages/contentstack-branches/src/utils/entry-create-script.ts @@ -166,7 +166,7 @@ export function entryCreateScript(contentType) { } function findAssetIdsFromJsonRte(entryObj, ctSchema) { - if(ctSchema !== undefined || ctSchema !== null){ + if(ctSchema !== undefined){ for (const element of ctSchema) { switch (element.data_type) { case 'blocks': { diff --git a/packages/contentstack-branches/src/utils/entry-create-update-script.ts b/packages/contentstack-branches/src/utils/entry-create-update-script.ts index 94d89882c5..64b188d925 100644 --- a/packages/contentstack-branches/src/utils/entry-create-update-script.ts +++ b/packages/contentstack-branches/src/utils/entry-create-update-script.ts @@ -188,7 +188,7 @@ export function entryCreateUpdateScript(contentType) { } function findAssetIdsFromJsonRte(entryObj, ctSchema) { - if(ctSchema !== undefined || ctSchema !== null){ + if(ctSchema !== undefined){ for (const element of ctSchema) { switch (element.data_type) { case 'blocks': { diff --git a/packages/contentstack-branches/src/utils/entry-update-script.ts b/packages/contentstack-branches/src/utils/entry-update-script.ts index 744c4dc8b9..0e085db968 100644 --- a/packages/contentstack-branches/src/utils/entry-update-script.ts +++ b/packages/contentstack-branches/src/utils/entry-update-script.ts @@ -188,7 +188,7 @@ export function entryUpdateScript(contentType) { } function findAssetIdsFromJsonRte(entryObj, ctSchema) { - if(ctSchema !== undefined || ctSchema !== null){ + if(ctSchema !== undefined){ for (const element of ctSchema) { switch (element.data_type) { case 'blocks': { From 9b653d0e7d20bc869ba135762d734bc194948204 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Thu, 24 Aug 2023 16:03:15 +0530 Subject: [PATCH 22/24] refactor: version bump --- package-lock.json | 20 ++++++++++---------- packages/contentstack-branches/README.md | 2 +- packages/contentstack-branches/package.json | 2 +- packages/contentstack-import/README.md | 2 +- packages/contentstack-import/package.json | 2 +- packages/contentstack-migration/README.md | 2 +- packages/contentstack-migration/package.json | 2 +- packages/contentstack/README.md | 2 +- packages/contentstack/package.json | 8 ++++---- pnpm-lock.yaml | 6 +++--- 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index a13078a8f1..c491d78ee4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20298,23 +20298,23 @@ }, "packages/contentstack": { "name": "@contentstack/cli", - "version": "1.8.1", + "version": "1.8.2", "license": "MIT", "dependencies": { "@contentstack/cli-auth": "~1.3.12", "@contentstack/cli-cm-bootstrap": "~1.4.14", - "@contentstack/cli-cm-branches": "~1.0.10", + "@contentstack/cli-cm-branches": "~1.0.11", "@contentstack/cli-cm-bulk-publish": "~1.3.10", "@contentstack/cli-cm-clone": "~1.4.15", "@contentstack/cli-cm-export": "~1.8.0", "@contentstack/cli-cm-export-to-csv": "^1.4.0", - "@contentstack/cli-cm-import": "~1.8.1", + "@contentstack/cli-cm-import": "~1.8.2", "@contentstack/cli-cm-migrate-rte": "^1.4.10", "@contentstack/cli-cm-seed": "^1.4.14", "@contentstack/cli-command": "^1.2.11", "@contentstack/cli-config": "^1.4.10", "@contentstack/cli-launch": "^1.0.10", - "@contentstack/cli-migration": "^1.3.10", + "@contentstack/cli-migration": "^1.3.11", "@contentstack/cli-utilities": "^1.5.1", "@contentstack/management": "~1.10.0", "@oclif/core": "^2.9.3", @@ -20485,7 +20485,7 @@ }, "packages/contentstack-branches": { "name": "@contentstack/cli-cm-branches", - "version": "1.0.10", + "version": "1.0.11", "license": "MIT", "dependencies": { "@contentstack/cli-command": "~1.2.11", @@ -21323,7 +21323,7 @@ }, "packages/contentstack-import": { "name": "@contentstack/cli-cm-import", - "version": "1.8.1", + "version": "1.8.2", "license": "MIT", "dependencies": { "@contentstack/cli-command": "~1.2.11", @@ -21985,7 +21985,7 @@ }, "packages/contentstack-migration": { "name": "@contentstack/cli-migration", - "version": "1.3.10", + "version": "1.3.11", "license": "MIT", "dependencies": { "@contentstack/cli-command": "~1.2.11", @@ -23703,18 +23703,18 @@ "requires": { "@contentstack/cli-auth": "~1.3.12", "@contentstack/cli-cm-bootstrap": "~1.4.14", - "@contentstack/cli-cm-branches": "~1.0.10", + "@contentstack/cli-cm-branches": "~1.0.11", "@contentstack/cli-cm-bulk-publish": "~1.3.10", "@contentstack/cli-cm-clone": "~1.4.15", "@contentstack/cli-cm-export": "~1.8.0", "@contentstack/cli-cm-export-to-csv": "^1.4.0", - "@contentstack/cli-cm-import": "~1.8.1", + "@contentstack/cli-cm-import": "~1.8.2", "@contentstack/cli-cm-migrate-rte": "^1.4.10", "@contentstack/cli-cm-seed": "^1.4.14", "@contentstack/cli-command": "^1.2.11", "@contentstack/cli-config": "^1.4.10", "@contentstack/cli-launch": "^1.0.10", - "@contentstack/cli-migration": "^1.3.10", + "@contentstack/cli-migration": "^1.3.11", "@contentstack/cli-utilities": "^1.5.1", "@contentstack/management": "~1.10.0", "@oclif/core": "^2.9.3", diff --git a/packages/contentstack-branches/README.md b/packages/contentstack-branches/README.md index e961926c4c..c82e0abf23 100755 --- a/packages/contentstack-branches/README.md +++ b/packages/contentstack-branches/README.md @@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-branches $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-cm-branches/1.0.10 darwin-arm64 node-v20.3.1 +@contentstack/cli-cm-branches/1.0.11 darwin-arm64 node-v18.14.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-branches/package.json b/packages/contentstack-branches/package.json index 7ed7022517..7d788ef48f 100644 --- a/packages/contentstack-branches/package.json +++ b/packages/contentstack-branches/package.json @@ -1,7 +1,7 @@ { "name": "@contentstack/cli-cm-branches", "description": "Contentstack CLI plugin to do branches operations", - "version": "1.0.10", + "version": "1.0.11", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { diff --git a/packages/contentstack-import/README.md b/packages/contentstack-import/README.md index d4e8c90c41..ae6eaa55d9 100644 --- a/packages/contentstack-import/README.md +++ b/packages/contentstack-import/README.md @@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-cm-import/1.8.1 darwin-arm64 node-v20.3.1 +@contentstack/cli-cm-import/1.8.2 darwin-arm64 node-v18.14.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-import/package.json b/packages/contentstack-import/package.json index 0a6f07f064..0712d83cdc 100644 --- a/packages/contentstack-import/package.json +++ b/packages/contentstack-import/package.json @@ -1,7 +1,7 @@ { "name": "@contentstack/cli-cm-import", "description": "Contentstack CLI plugin to import content into stack", - "version": "1.8.1", + "version": "1.8.2", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { diff --git a/packages/contentstack-migration/README.md b/packages/contentstack-migration/README.md index fb6fdebcb9..48aa79fc52 100644 --- a/packages/contentstack-migration/README.md +++ b/packages/contentstack-migration/README.md @@ -21,7 +21,7 @@ $ npm install -g @contentstack/cli-migration $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-migration/1.3.10 darwin-arm64 node-v20.3.1 +@contentstack/cli-migration/1.3.11 darwin-arm64 node-v18.14.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-migration/package.json b/packages/contentstack-migration/package.json index f0f02f3961..606e4204b8 100644 --- a/packages/contentstack-migration/package.json +++ b/packages/contentstack-migration/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/cli-migration", - "version": "1.3.10", + "version": "1.3.11", "author": "@contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { diff --git a/packages/contentstack/README.md b/packages/contentstack/README.md index 2747f10302..ad474f5c17 100644 --- a/packages/contentstack/README.md +++ b/packages/contentstack/README.md @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli $ csdx COMMAND running command... $ csdx (--version|-v) -@contentstack/cli/1.8.1 darwin-arm64 node-v20.3.1 +@contentstack/cli/1.8.2 darwin-arm64 node-v18.14.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack/package.json b/packages/contentstack/package.json index 1f15fab899..6546441c91 100755 --- a/packages/contentstack/package.json +++ b/packages/contentstack/package.json @@ -1,7 +1,7 @@ { "name": "@contentstack/cli", "description": "Command-line tool (CLI) to interact with Contentstack", - "version": "1.8.1", + "version": "1.8.2", "author": "Contentstack", "bin": { "csdx": "./bin/run" @@ -28,16 +28,16 @@ "@contentstack/cli-cm-clone": "~1.4.15", "@contentstack/cli-cm-export": "~1.8.0", "@contentstack/cli-cm-export-to-csv": "^1.4.0", - "@contentstack/cli-cm-import": "~1.8.1", + "@contentstack/cli-cm-import": "~1.8.2", "@contentstack/cli-cm-migrate-rte": "^1.4.10", "@contentstack/cli-cm-seed": "^1.4.14", "@contentstack/cli-command": "^1.2.11", "@contentstack/cli-config": "^1.4.10", "@contentstack/cli-launch": "^1.0.10", - "@contentstack/cli-migration": "^1.3.10", + "@contentstack/cli-migration": "^1.3.11", "@contentstack/cli-utilities": "^1.5.1", "@contentstack/management": "~1.10.0", - "@contentstack/cli-cm-branches": "~1.0.10", + "@contentstack/cli-cm-branches": "~1.0.11", "@oclif/plugin-help": "^5", "@oclif/plugin-not-found": "^2.3.9", "@oclif/plugin-plugins": "^2.1.7", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e37aa87617..efa0b9b112 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,18 +12,18 @@ importers: specifiers: '@contentstack/cli-auth': ~1.3.12 '@contentstack/cli-cm-bootstrap': ~1.4.14 - '@contentstack/cli-cm-branches': ~1.0.10 + '@contentstack/cli-cm-branches': ~1.0.11 '@contentstack/cli-cm-bulk-publish': ~1.3.10 '@contentstack/cli-cm-clone': ~1.4.15 '@contentstack/cli-cm-export': ~1.8.0 '@contentstack/cli-cm-export-to-csv': ^1.4.0 - '@contentstack/cli-cm-import': ~1.8.1 + '@contentstack/cli-cm-import': ~1.8.2 '@contentstack/cli-cm-migrate-rte': ^1.4.10 '@contentstack/cli-cm-seed': ^1.4.14 '@contentstack/cli-command': ^1.2.11 '@contentstack/cli-config': ^1.4.10 '@contentstack/cli-launch': ^1.0.10 - '@contentstack/cli-migration': ^1.3.10 + '@contentstack/cli-migration': ^1.3.11 '@contentstack/cli-utilities': ^1.5.1 '@contentstack/management': ~1.10.0 '@oclif/core': ^2.9.3 From 2e54fdbc0c7e4abf34d96a7778181fa6aebe021d Mon Sep 17 00:00:00 2001 From: Abhinav Gupta Date: Thu, 24 Aug 2023 18:48:58 +0530 Subject: [PATCH 23/24] fix: changed ^ to ~ --- packages/contentstack/package.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/contentstack/package.json b/packages/contentstack/package.json index 6546441c91..14e61aab08 100755 --- a/packages/contentstack/package.json +++ b/packages/contentstack/package.json @@ -27,15 +27,15 @@ "@contentstack/cli-cm-bulk-publish": "~1.3.10", "@contentstack/cli-cm-clone": "~1.4.15", "@contentstack/cli-cm-export": "~1.8.0", - "@contentstack/cli-cm-export-to-csv": "^1.4.0", + "@contentstack/cli-cm-export-to-csv": "~1.4.0", "@contentstack/cli-cm-import": "~1.8.2", - "@contentstack/cli-cm-migrate-rte": "^1.4.10", - "@contentstack/cli-cm-seed": "^1.4.14", - "@contentstack/cli-command": "^1.2.11", - "@contentstack/cli-config": "^1.4.10", - "@contentstack/cli-launch": "^1.0.10", - "@contentstack/cli-migration": "^1.3.11", - "@contentstack/cli-utilities": "^1.5.1", + "@contentstack/cli-cm-migrate-rte": "~1.4.10", + "@contentstack/cli-cm-seed": "~1.4.14", + "@contentstack/cli-command": "~1.2.11", + "@contentstack/cli-config": "~1.4.10", + "@contentstack/cli-launch": "~1.0.10", + "@contentstack/cli-migration": "~1.3.11", + "@contentstack/cli-utilities": "~1.5.1", "@contentstack/management": "~1.10.0", "@contentstack/cli-cm-branches": "~1.0.11", "@oclif/plugin-help": "^5", From 5e12e97c3c88b94c1232d54d09d3114c882561c4 Mon Sep 17 00:00:00 2001 From: Abhinav Gupta Date: Thu, 24 Aug 2023 18:51:40 +0530 Subject: [PATCH 24/24] updated lock files and READMEs --- package-lock.json | 32 +++++++++++------------ packages/contentstack-branches/README.md | 2 +- packages/contentstack-import/README.md | 2 +- packages/contentstack-migration/README.md | 2 +- packages/contentstack/README.md | 2 +- pnpm-lock.yaml | 16 ++++++------ 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/package-lock.json b/package-lock.json index c491d78ee4..4eb63ff6ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20307,15 +20307,15 @@ "@contentstack/cli-cm-bulk-publish": "~1.3.10", "@contentstack/cli-cm-clone": "~1.4.15", "@contentstack/cli-cm-export": "~1.8.0", - "@contentstack/cli-cm-export-to-csv": "^1.4.0", + "@contentstack/cli-cm-export-to-csv": "~1.4.0", "@contentstack/cli-cm-import": "~1.8.2", - "@contentstack/cli-cm-migrate-rte": "^1.4.10", - "@contentstack/cli-cm-seed": "^1.4.14", - "@contentstack/cli-command": "^1.2.11", - "@contentstack/cli-config": "^1.4.10", - "@contentstack/cli-launch": "^1.0.10", - "@contentstack/cli-migration": "^1.3.11", - "@contentstack/cli-utilities": "^1.5.1", + "@contentstack/cli-cm-migrate-rte": "~1.4.10", + "@contentstack/cli-cm-seed": "~1.4.14", + "@contentstack/cli-command": "~1.2.11", + "@contentstack/cli-config": "~1.4.10", + "@contentstack/cli-launch": "~1.0.10", + "@contentstack/cli-migration": "~1.3.11", + "@contentstack/cli-utilities": "~1.5.1", "@contentstack/management": "~1.10.0", "@oclif/core": "^2.9.3", "@oclif/plugin-help": "^5", @@ -23707,15 +23707,15 @@ "@contentstack/cli-cm-bulk-publish": "~1.3.10", "@contentstack/cli-cm-clone": "~1.4.15", "@contentstack/cli-cm-export": "~1.8.0", - "@contentstack/cli-cm-export-to-csv": "^1.4.0", + "@contentstack/cli-cm-export-to-csv": "~1.4.0", "@contentstack/cli-cm-import": "~1.8.2", - "@contentstack/cli-cm-migrate-rte": "^1.4.10", - "@contentstack/cli-cm-seed": "^1.4.14", - "@contentstack/cli-command": "^1.2.11", - "@contentstack/cli-config": "^1.4.10", - "@contentstack/cli-launch": "^1.0.10", - "@contentstack/cli-migration": "^1.3.11", - "@contentstack/cli-utilities": "^1.5.1", + "@contentstack/cli-cm-migrate-rte": "~1.4.10", + "@contentstack/cli-cm-seed": "~1.4.14", + "@contentstack/cli-command": "~1.2.11", + "@contentstack/cli-config": "~1.4.10", + "@contentstack/cli-launch": "~1.0.10", + "@contentstack/cli-migration": "~1.3.11", + "@contentstack/cli-utilities": "~1.5.1", "@contentstack/management": "~1.10.0", "@oclif/core": "^2.9.3", "@oclif/plugin-help": "^5", diff --git a/packages/contentstack-branches/README.md b/packages/contentstack-branches/README.md index c82e0abf23..d6c9aeb884 100755 --- a/packages/contentstack-branches/README.md +++ b/packages/contentstack-branches/README.md @@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-branches $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-cm-branches/1.0.11 darwin-arm64 node-v18.14.0 +@contentstack/cli-cm-branches/1.0.11 darwin-arm64 node-v20.3.1 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-import/README.md b/packages/contentstack-import/README.md index ae6eaa55d9..20b53af987 100644 --- a/packages/contentstack-import/README.md +++ b/packages/contentstack-import/README.md @@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-cm-import/1.8.2 darwin-arm64 node-v18.14.0 +@contentstack/cli-cm-import/1.8.2 darwin-arm64 node-v20.3.1 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-migration/README.md b/packages/contentstack-migration/README.md index 48aa79fc52..23933f2703 100644 --- a/packages/contentstack-migration/README.md +++ b/packages/contentstack-migration/README.md @@ -21,7 +21,7 @@ $ npm install -g @contentstack/cli-migration $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-migration/1.3.11 darwin-arm64 node-v18.14.0 +@contentstack/cli-migration/1.3.11 darwin-arm64 node-v20.3.1 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack/README.md b/packages/contentstack/README.md index ad474f5c17..71f2806b2b 100644 --- a/packages/contentstack/README.md +++ b/packages/contentstack/README.md @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli $ csdx COMMAND running command... $ csdx (--version|-v) -@contentstack/cli/1.8.2 darwin-arm64 node-v18.14.0 +@contentstack/cli/1.8.2 darwin-arm64 node-v20.3.1 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index efa0b9b112..e2237033dc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,15 +16,15 @@ importers: '@contentstack/cli-cm-bulk-publish': ~1.3.10 '@contentstack/cli-cm-clone': ~1.4.15 '@contentstack/cli-cm-export': ~1.8.0 - '@contentstack/cli-cm-export-to-csv': ^1.4.0 + '@contentstack/cli-cm-export-to-csv': ~1.4.0 '@contentstack/cli-cm-import': ~1.8.2 - '@contentstack/cli-cm-migrate-rte': ^1.4.10 - '@contentstack/cli-cm-seed': ^1.4.14 - '@contentstack/cli-command': ^1.2.11 - '@contentstack/cli-config': ^1.4.10 - '@contentstack/cli-launch': ^1.0.10 - '@contentstack/cli-migration': ^1.3.11 - '@contentstack/cli-utilities': ^1.5.1 + '@contentstack/cli-cm-migrate-rte': ~1.4.10 + '@contentstack/cli-cm-seed': ~1.4.14 + '@contentstack/cli-command': ~1.2.11 + '@contentstack/cli-config': ~1.4.10 + '@contentstack/cli-launch': ~1.0.10 + '@contentstack/cli-migration': ~1.3.11 + '@contentstack/cli-utilities': ~1.5.1 '@contentstack/management': ~1.10.0 '@oclif/core': ^2.9.3 '@oclif/plugin-help': ^5