diff --git a/package-lock.json b/package-lock.json index f0e68b052c..3736390e5d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -883,9 +883,9 @@ } }, "node_modules/@contentstack/management": { - "version": "1.15.1", - "resolved": "https://registry.npmjs.org/@contentstack/management/-/management-1.15.1.tgz", - "integrity": "sha512-FAw2NAuDW/3JVbRu4t/BA9POYpKeZNsItTpld/CGJr/OenKbZLJfh527LH3v1Bj+jkhIDP8rIXoyJy4WI/ORVQ==", + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/@contentstack/management/-/management-1.15.2.tgz", + "integrity": "sha512-DAgOuG5k6g6OkkQv44O8f6EhzbTxdfwJJa0NHNkEYGkl/FIEHZYakuNG41aVWDbf35Nv3p59UV6Ph4q5kNYg8Q==", "dependencies": { "@slack/bolt": "^3.17.0", "axios": "^1.6.5", @@ -23991,9 +23991,9 @@ "@contentstack/cli-cm-bootstrap": "~1.8.0", "@contentstack/cli-cm-branches": "~1.0.22", "@contentstack/cli-cm-bulk-publish": "~1.4.0", - "@contentstack/cli-cm-clone": "~1.10.0", + "@contentstack/cli-cm-clone": "~1.10.1", "@contentstack/cli-cm-export": "~1.11.0", - "@contentstack/cli-cm-export-to-csv": "~1.6.2", + "@contentstack/cli-cm-export-to-csv": "~1.7.0", "@contentstack/cli-cm-import": "~1.14.0", "@contentstack/cli-cm-migrate-rte": "~1.4.15", "@contentstack/cli-cm-seed": "~1.7.1", @@ -24002,7 +24002,7 @@ "@contentstack/cli-launch": "~1.0.16", "@contentstack/cli-migration": "~1.4.2", "@contentstack/cli-utilities": "~1.5.12", - "@contentstack/management": "~1.15.1", + "@contentstack/management": "~1.15.2", "@oclif/core": "^2.9.3", "@oclif/plugin-help": "^5", "@oclif/plugin-not-found": "^2.4.0", @@ -24531,12 +24531,12 @@ }, "packages/contentstack-clone": { "name": "@contentstack/cli-cm-clone", - "version": "1.10.0", + "version": "1.10.1", "license": "MIT", "dependencies": { "@colors/colors": "^1.5.0", - "@contentstack/cli-cm-export": "~1.10.5", - "@contentstack/cli-cm-import": "~1.13.4", + "@contentstack/cli-cm-export": "~1.11.0", + "@contentstack/cli-cm-import": "~1.14.0", "@contentstack/cli-command": "~1.2.16", "@contentstack/cli-utilities": "~1.5.12", "async": "^3.2.4", @@ -24567,88 +24567,6 @@ "node": ">=14.0.0" } }, - "packages/contentstack-clone/node_modules/@contentstack/cli-cm-export": { - "version": "1.10.4", - "resolved": "https://registry.npmjs.org/@contentstack/cli-cm-export/-/cli-cm-export-1.10.4.tgz", - "integrity": "sha512-t9bDER2DIUzQPCwtzQDmcKkHBW0Cc8xAXj7eWcqMsEhZSyDQSbDdhbel5/8jpDXkEhpfaJJByQrNvgz43/+EmQ==", - "dependencies": { - "@contentstack/cli-command": "~1.2.16", - "@contentstack/cli-utilities": "~1.5.11", - "@oclif/core": "^2.9.3", - "async": "^3.2.4", - "big-json": "^3.2.0", - "bluebird": "^3.7.2", - "chalk": "^4.1.2", - "is-valid-path": "^0.1.1", - "lodash": "^4.17.20", - "merge": "^2.1.1", - "mkdirp": "^1.0.4", - "path": "^0.12.7", - "progress-stream": "^2.0.0", - "promise-limit": "^2.7.0", - "proxyquire": "^2.1.3", - "tslib": "^2.4.1", - "winston": "^3.7.2" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "packages/contentstack-clone/node_modules/@contentstack/cli-cm-import": { - "version": "1.13.3", - "resolved": "https://registry.npmjs.org/@contentstack/cli-cm-import/-/cli-cm-import-1.13.3.tgz", - "integrity": "sha512-W2A6frSuK8p9fS1S6VXRo9xOj4fv09h+VnHGmtYhRGa3GdAbAZZdCKq+g/uUAn9HbwEvuxgZIpAJignOYYYxeg==", - "dependencies": { - "@contentstack/cli-audit": "^1.3.3", - "@contentstack/cli-command": "~1.2.16", - "@contentstack/cli-utilities": "~1.5.11", - "@contentstack/management": "~1.13.0", - "@oclif/core": "^2.9.3", - "big-json": "^3.2.0", - "bluebird": "^3.7.2", - "chalk": "^4.1.2", - "debug": "^4.1.0", - "fs-extra": "^11.1.1", - "lodash": "^4.17.20", - "marked": "^4.0.17", - "merge": "^2.1.1", - "mkdirp": "^1.0.4", - "promise-limit": "^2.7.0", - "tslib": "^2.4.1", - "uuid": "^9.0.0", - "winston": "^3.7.2" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "packages/contentstack-clone/node_modules/@contentstack/management": { - "version": "1.13.0", - "resolved": "https://registry.npmjs.org/@contentstack/management/-/management-1.13.0.tgz", - "integrity": "sha512-zVApJ9dpZTq6yBvSTdwrTjPxe20PiXy9x5CGU49by2n1V7hWhsKtSpcIK+Fx9jylYfYU4SEM/HQIKq/i0roMew==", - "dependencies": { - "axios": "^1.6.0", - "form-data": "^3.0.1", - "lodash": "^4.17.21", - "qs": "^6.11.2" - }, - "engines": { - "node": ">=8.0.0" - } - }, - "packages/contentstack-clone/node_modules/form-data": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz", - "integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, "packages/contentstack-clone/node_modules/rimraf": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", @@ -25100,7 +25018,7 @@ }, "packages/contentstack-export-to-csv": { "name": "@contentstack/cli-cm-export-to-csv", - "version": "1.6.2", + "version": "1.7.0", "license": "MIT", "dependencies": { "@contentstack/cli-command": "~1.2.16", @@ -25524,7 +25442,7 @@ "@contentstack/cli-audit": "~1.4.0", "@contentstack/cli-command": "~1.2.16", "@contentstack/cli-utilities": "~1.5.12", - "@contentstack/management": "^1.15.1", + "@contentstack/management": "^1.15.2", "@oclif/core": "^2.9.3", "big-json": "^3.2.0", "bluebird": "^3.7.2", @@ -25997,7 +25915,7 @@ "version": "1.7.1", "license": "MIT", "dependencies": { - "@contentstack/cli-cm-import": "~1.13.4", + "@contentstack/cli-cm-import": "~1.14.0", "@contentstack/cli-command": "~1.2.16", "@contentstack/cli-utilities": "~1.5.12", "inquirer": "8.2.4", @@ -26029,48 +25947,6 @@ "node": ">=14.0.0" } }, - "packages/contentstack-seed/node_modules/@contentstack/cli-cm-import": { - "version": "1.13.3", - "resolved": "https://registry.npmjs.org/@contentstack/cli-cm-import/-/cli-cm-import-1.13.3.tgz", - "integrity": "sha512-W2A6frSuK8p9fS1S6VXRo9xOj4fv09h+VnHGmtYhRGa3GdAbAZZdCKq+g/uUAn9HbwEvuxgZIpAJignOYYYxeg==", - "dependencies": { - "@contentstack/cli-audit": "^1.3.3", - "@contentstack/cli-command": "~1.2.16", - "@contentstack/cli-utilities": "~1.5.11", - "@contentstack/management": "~1.13.0", - "@oclif/core": "^2.9.3", - "big-json": "^3.2.0", - "bluebird": "^3.7.2", - "chalk": "^4.1.2", - "debug": "^4.1.0", - "fs-extra": "^11.1.1", - "lodash": "^4.17.20", - "marked": "^4.0.17", - "merge": "^2.1.1", - "mkdirp": "^1.0.4", - "promise-limit": "^2.7.0", - "tslib": "^2.4.1", - "uuid": "^9.0.0", - "winston": "^3.7.2" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "packages/contentstack-seed/node_modules/@contentstack/management": { - "version": "1.13.0", - "resolved": "https://registry.npmjs.org/@contentstack/management/-/management-1.13.0.tgz", - "integrity": "sha512-zVApJ9dpZTq6yBvSTdwrTjPxe20PiXy9x5CGU49by2n1V7hWhsKtSpcIK+Fx9jylYfYU4SEM/HQIKq/i0roMew==", - "dependencies": { - "axios": "^1.6.0", - "form-data": "^3.0.1", - "lodash": "^4.17.21", - "qs": "^6.11.2" - }, - "engines": { - "node": ">=8.0.0" - } - }, "packages/contentstack-seed/node_modules/@types/node": { "version": "14.18.63", "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.63.tgz", @@ -26086,19 +25962,6 @@ "node": ">=0.3.1" } }, - "packages/contentstack-seed/node_modules/form-data": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz", - "integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, "packages/contentstack-seed/node_modules/source-map-support": { "version": "0.5.21", "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", @@ -26139,7 +26002,7 @@ "version": "1.5.12", "license": "MIT", "dependencies": { - "@contentstack/management": "^1.15.1", + "@contentstack/management": "^1.15.2", "@contentstack/marketplace-sdk": "^1.0.1", "@oclif/core": "^2.9.3", "axios": "^1.6.4", @@ -26256,6 +26119,21 @@ "url": "https://github.com/sponsors/isaacs" } }, + "packages/contentstack/node_modules/@contentstack/cli-cm-export-to-csv/node_modules/mkdirp": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-3.0.1.tgz", + "integrity": "sha512-+NsyUUAZDmo6YVHzL/stxSu3t9YS1iljliy3BSDrXJ/dkn1KYdmtZODGGjLcc9XLgVVpH4KshHB8XmZgMhaBXg==", + "extraneous": true, + "bin": { + "mkdirp": "dist/cjs/src/bin.js" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "packages/contentstack/node_modules/@contentstack/cli-cm-seed/node_modules/@contentstack/cli-cm-import": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/@contentstack/cli-cm-import/-/cli-cm-import-1.10.0.tgz", diff --git a/packages/contentstack-bootstrap/README.md b/packages/contentstack-bootstrap/README.md index e4995d2897..2c40af0a0f 100644 --- a/packages/contentstack-bootstrap/README.md +++ b/packages/contentstack-bootstrap/README.md @@ -15,7 +15,7 @@ $ npm install -g @contentstack/cli-cm-bootstrap $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-cm-bootstrap/1.7.1 darwin-arm64 node-v20.8.0 +@contentstack/cli-cm-bootstrap/1.8.0 darwin-arm64 node-v18.19.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-clone/README.md b/packages/contentstack-clone/README.md index 85de4211c1..2d16d69ea4 100644 --- a/packages/contentstack-clone/README.md +++ b/packages/contentstack-clone/README.md @@ -16,7 +16,7 @@ $ npm install -g @contentstack/cli-cm-clone $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-cm-clone/1.10.0 darwin-arm64 node-v20.8.0 +@contentstack/cli-cm-clone/1.10.1 darwin-arm64 node-v20.8.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-clone/package.json b/packages/contentstack-clone/package.json index 43aa7a03b6..2f3277f101 100644 --- a/packages/contentstack-clone/package.json +++ b/packages/contentstack-clone/package.json @@ -1,12 +1,12 @@ { "name": "@contentstack/cli-cm-clone", "description": "Contentstack stack clone plugin", - "version": "1.10.0", + "version": "1.10.1", "author": "Contentstack", "bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues", "dependencies": { - "@contentstack/cli-cm-export": "~1.10.5", - "@contentstack/cli-cm-import": "~1.13.4", + "@contentstack/cli-cm-export": "~1.11.0", + "@contentstack/cli-cm-import": "~1.14.0", "@contentstack/cli-command": "~1.2.16", "@contentstack/cli-utilities": "~1.5.12", "@colors/colors": "^1.5.0", diff --git a/packages/contentstack-export-to-csv/package.json b/packages/contentstack-export-to-csv/package.json index 86bde2c529..a30542cf26 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.6.2", + "version": "1.7.0", "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 4c646b3779..0285ed6ff1 100644 --- a/packages/contentstack-export-to-csv/src/util/index.js +++ b/packages/contentstack-export-to-csv/src/util/index.js @@ -460,7 +460,7 @@ function write(command, entries, fileName, message, delimiter, headers) { process.chdir(directory); } // eslint-disable-next-line no-undef - cliux.print(`Writing ${message} to file: ${process.cwd()}${delimeter}${fileName}`); + cliux.print(`Writing ${message} to file: "${process.cwd()}${delimeter}${fileName}"`); if (headers?.length) fastcsv.writeToPath(fileName, entries, { headers, delimiter }); else fastcsv.writeToPath(fileName, entries, { headers: true, delimiter }); } @@ -700,10 +700,10 @@ function handleErrorMsg(err) { /** * This function does the sdk calls to get all the teams in org - * @param {object} managementAPIClient - * @param {object} org - * @param {object} queryParam - * @returns + * @param {object} managementAPIClient + * @param {object} org + * @param {object} queryParam + * @returns */ async function getAllTeams(managementAPIClient, org, queryParam = {}) { try { @@ -715,8 +715,8 @@ async function getAllTeams(managementAPIClient, org, queryParam = {}) { /** * This function is used to handle the pagination and call the sdk - * @param {object} managementAPIClient - * @param {object} org + * @param {object} managementAPIClient + * @param {object} org */ async function exportOrgTeams(managementAPIClient, org) { let allTeamsInOrg = []; @@ -737,9 +737,9 @@ async function exportOrgTeams(managementAPIClient, org) { } /** - * This function will get all the org level roles - * @param {object} managementAPIClient - * @param {object} org + * This function will get all the org level roles + * @param {object} managementAPIClient + * @param {object} org */ async function getOrgRolesForTeams(managementAPIClient, org) { let roleMap = {}; // for org level there are two roles only admin and member @@ -763,9 +763,9 @@ async function getOrgRolesForTeams(managementAPIClient, org) { /** * Removes the unnecessary fields from the objects in the data and assign org level roles to the team based on role uid - * @param {array} data - * @param {object} managementAPIClient - * @param {object} org + * @param {array} data + * @param {object} managementAPIClient + * @param {object} org */ async function cleanTeamsData(data, managementAPIClient, org) { const roleMap = await getOrgRolesForTeams(managementAPIClient, org); @@ -784,7 +784,7 @@ async function cleanTeamsData(data, managementAPIClient, org) { 'delete', 'fetch', 'stackRoleMappings', - 'teamUsers' + 'teamUsers', ]; if (data?.length) { return data.map((team) => { @@ -806,10 +806,10 @@ async function cleanTeamsData(data, managementAPIClient, org) { /** * This function is used to call all the other teams function to export the required files - * @param {object} managementAPIClient - * @param {object} organization - * @param {string} teamUid - * @param {character} delimiter + * @param {object} managementAPIClient + * @param {object} organization + * @param {string} teamUid + * @param {character} delimiter */ async function exportTeams(managementAPIClient, organization, teamUid, delimiter) { cliux.print( @@ -852,10 +852,10 @@ async function exportTeams(managementAPIClient, organization, teamUid, delimiter /** * This function is used to get individual team user details and write to file - * @param {array} allTeamsData - * @param {object} organization + * @param {array} allTeamsData + * @param {object} organization * @param {string} teamUid optional - * @param {character} delimiter + * @param {character} delimiter */ async function getTeamsDetail(allTeamsData, organization, teamUid, delimiter) { if (!teamUid) { @@ -883,10 +883,10 @@ async function getTeamsDetail(allTeamsData, organization, teamUid, delimiter) { /** * This will export the role mappings of the team, for which stack the team has which role - * @param {object} managementAPIClient - * @param {array} allTeamsData Data for all the teams in the stack + * @param {object} managementAPIClient + * @param {array} allTeamsData Data for all the teams in the stack * @param {string} teamUid for a particular team who's data we want - * @param {character} delimiter + * @param {character} delimiter */ async function exportRoleMappings(managementAPIClient, allTeamsData, teamUid, delimiter) { let stackRoleWithTeamData = []; @@ -935,7 +935,7 @@ async function exportRoleMappings(managementAPIClient, allTeamsData, teamUid, de ]; try { const exportStackRole = await inquirer.prompt(export_stack_role); - if(exportStackRole.chooseExport==='no') { + if (exportStackRole.chooseExport === 'no') { process.exit(1); } } catch (error) { @@ -953,10 +953,10 @@ async function exportRoleMappings(managementAPIClient, allTeamsData, teamUid, de /** * Mapping the team stacks with the stack role and returning and array of object - * @param {object} managementAPIClient - * @param {array} stackRoleMapping - * @param {string} teamName - * @param {string} teamUid + * @param {object} managementAPIClient + * @param {array} stackRoleMapping + * @param {string} teamName + * @param {string} teamUid */ async function mapRoleWithTeams(managementAPIClient, stackRoleMapping, teamName, teamUid) { const roles = await getRoleData(managementAPIClient, stackRoleMapping.stackApiKey); @@ -982,8 +982,8 @@ async function mapRoleWithTeams(managementAPIClient, stackRoleMapping, teamName, /** * Making sdk call to get all the roles in the given stack - * @param {object} managementAPIClient - * @param {string} stackApiKey + * @param {object} managementAPIClient + * @param {string} stackApiKey */ async function getRoleData(managementAPIClient, stackApiKey) { try { @@ -995,7 +995,7 @@ async function getRoleData(managementAPIClient, stackApiKey) { /** * Here in the users array we are adding the team-name and team-uid to individual users and returning an array of object of user details only - * @param {array} teams + * @param {array} teams */ async function getTeamsUserDetails(teams) { const allTeamUsers = []; @@ -1080,7 +1080,7 @@ async function getTaxonomy(payload) { * @returns {*} Promise */ async function taxonomySDKHandler(payload, skip) { - const { stackAPIClient, taxonomyUID, type } = payload; + const { stackAPIClient, taxonomyUID, type, format } = payload; const queryParams = { include_count: true, limit: payload.limit }; if (skip >= 0) queryParams['skip'] = skip || 0; @@ -1092,13 +1092,13 @@ async function taxonomySDKHandler(payload, skip) { .query(queryParams) .find() .then((data) => data) - .catch((err) => handleErrorMsg(err)); + .catch((err) => handleTaxonomyErrorMsg(err)); case 'taxonomy': return await stackAPIClient .taxonomy(taxonomyUID) .fetch() .then((data) => data) - .catch((err) => handleErrorMsg(err)); + .catch((err) => handleTaxonomyErrorMsg(err)); case 'terms': queryParams['depth'] = 0; return await stackAPIClient @@ -1107,9 +1107,15 @@ async function taxonomySDKHandler(payload, skip) { .query(queryParams) .find() .then((data) => data) - .catch((err) => handleErrorMsg(err)); + .catch((err) => handleTaxonomyErrorMsg(err)); + case 'export-taxonomies': + return await stackAPIClient + .taxonomy(taxonomyUID) + .export({format}) + .then((data) => data) + .catch((err) => handleTaxonomyErrorMsg(err)); default: - handleErrorMsg({ errorMessage: 'Invalid module!' }); + handleTaxonomyErrorMsg({ errorMessage: 'Invalid module!' }); } } @@ -1152,7 +1158,7 @@ function formatTermsOfTaxonomyData(terms, taxonomyUID) { } } -function handleErrorMsg(err) { +function handleTaxonomyErrorMsg(err) { if (err?.errorMessage) { cliux.print(`Error: ${err.errorMessage}`, { color: 'red' }); } else if (err?.message) { @@ -1166,60 +1172,57 @@ function handleErrorMsg(err) { } /** - * create an importable CSV file, to utilize with the migration script. + * Generate a CSV file that can be imported for use with the migration script. * @param {*} payload api request payload * @param {*} taxonomies taxonomies data * @returns */ async function createImportableCSV(payload, taxonomies) { - let taxonomiesData = []; - let headers = ['Taxonomy Name', 'Taxonomy UID', 'Taxonomy Description']; - for (let index = 0; index < taxonomies?.length; index++) { - const taxonomy = taxonomies[index]; - const taxonomyUID = taxonomy?.uid; - if (taxonomyUID) { - const sanitizedTaxonomy = sanitizeData({ - 'Taxonomy Name': taxonomy?.name, - 'Taxonomy UID': taxonomyUID, - 'Taxonomy Description': taxonomy?.description, - }); - taxonomiesData.push(sanitizedTaxonomy); - payload['taxonomyUID'] = taxonomyUID; - const terms = await getAllTermsOfTaxonomy(payload); - //fetch all parent terms - const parentTerms = terms.filter((term) => term?.parent_uid === null); - const termsData = getParentAndChildTerms(parentTerms, terms, headers); - taxonomiesData.push(...termsData); + try { + let taxonomiesData = []; + let headers = []; + payload['type'] = 'export-taxonomies'; + payload['format'] = 'csv'; + for (const taxonomy of taxonomies) { + if (taxonomy?.uid) { + payload['taxonomyUID'] = taxonomy?.uid; + const data = await taxonomySDKHandler(payload); + const taxonomies = await csvParse(data, headers); + taxonomiesData.push(...taxonomies); + } } - } - return { taxonomiesData, headers }; + return { taxonomiesData, headers }; + } catch (err) { + throw err; + } } /** - * Get the parent and child terms, then arrange them hierarchically in a CSV file. - * @param {*} parentTerms list of parent terms - * @param {*} terms respective terms of taxonomies - * @param {*} headers list of csv headers include taxonomy and terms column - * @param {*} termsData parent and child terms + * Parse the CSV data and segregate the headers from the actual data. + * @param {*} data taxonomy csv data with headers + * @param {*} headers list of csv headers + * @returns taxonomy data without headers */ -function getParentAndChildTerms(parentTerms, terms, headers, termsData = []) { - for (let i = 0; i < parentTerms?.length; i++) { - const parentTerm = parentTerms[i]; - const levelUID = `Term Level${parentTerm.depth} UID`; - const levelName = `Term Level${parentTerm.depth} Name`; - if (headers.indexOf(levelName) === -1) headers.push(levelName); - if (headers.indexOf(levelUID) === -1) headers.push(levelUID); - const sanitizedTermData = sanitizeData({ [levelName]: parentTerm.name, [levelUID]: parentTerm.uid }); - termsData.push(sanitizedTermData); - //fetch all sibling terms - const newParents = terms.filter((term) => term.parent_uid === parentTerm.uid); - if (newParents?.length) { - getParentAndChildTerms(newParents, terms, headers, termsData); - } - } - return termsData; -} +const csvParse = (data, headers) => { + return new Promise((resolve, reject) => { + const taxonomies = []; + const stream = fastcsv.parseStream(fastcsv.parse()); + stream.write(data); + stream.end(); + stream + .on('data', (data) => { + taxonomies.push(data); + }) + .on('error', (err) => reject(err)) + .on('end', () => { + taxonomies[0]?.forEach((header) => { + if (!headers.includes(header)) headers.push(header); + }); + resolve(taxonomies.splice(1)); + }); + }); +}; module.exports = { chooseOrganization: chooseOrganization, diff --git a/packages/contentstack-export-to-csv/test/mock-data/common.mock.json b/packages/contentstack-export-to-csv/test/mock-data/common.mock.json index 24ad077062..e715cd5c60 100644 --- a/packages/contentstack-export-to-csv/test/mock-data/common.mock.json +++ b/packages/contentstack-export-to-csv/test/mock-data/common.mock.json @@ -395,5 +395,6 @@ "users": ["user_1_uid_member", "user_2_uid_member", "user_3_uid_member", "user_4_uid_member"] } ] - } + }, + "taxonomyCSVData": "`taxonomy1,taxonomy1,,,,,,,\n,,,term1,term1,,,,\n,,,,,term1_2,term1_2,,\n,,,term2,term2,,,,\n,,,,,term2_2,term2_2,,\n,,,,,,,term2_2_1,term2_2_1\n,,,,,term2_1,term2_1,,`" } diff --git a/packages/contentstack-export-to-csv/test/unit/commands/export-to-csv.test.js b/packages/contentstack-export-to-csv/test/unit/commands/export-to-csv.test.js index 7afb959731..0891675929 100644 --- a/packages/contentstack-export-to-csv/test/unit/commands/export-to-csv.test.js +++ b/packages/contentstack-export-to-csv/test/unit/commands/export-to-csv.test.js @@ -1,7 +1,6 @@ const fs = require('fs'); const mkdirp = require('mkdirp'); -const { test, expect } = require('@oclif/test'); -const { join } = require('path'); +const { test: fancy } = require('@oclif/test'); const { PassThrough } = require('stream'); const inquirer = require('inquirer'); const mockData = require('../../mock-data/common.mock.json'); @@ -10,6 +9,7 @@ const { configHandler } = require('@contentstack/cli-utilities'); const { cma } = configHandler.get('region'); describe('export-to-csv with action taxonomies', () => { + const test = fancy.loadConfig({ root: process.cwd() }); describe('Create taxonomies & terms csv file with all flags including taxonomy uid', () => { test .stdout({ print: process.env.PRINT === 'true' || false }) @@ -29,9 +29,9 @@ describe('export-to-csv with action taxonomies', () => { .nock(cma, (api) => { api .get( - `/v3/taxonomies/${mockData.taxonomiesResp.taxonomies[0].uid}/terms?include_count=true&limit=100&skip=0&depth=0`, + `/v3/taxonomies/${mockData.taxonomiesResp.taxonomies[0].uid}/export?format=csv`, ) - .reply(200, mockData.termsResp); + .reply(200, mockData.taxonomyCSVData); }) .command([ 'cm:export-to-csv', @@ -64,16 +64,16 @@ describe('export-to-csv with action taxonomies', () => { .nock(cma, (api) => { api .get( - `/v3/taxonomies/${mockData.taxonomiesResp.taxonomies[0].uid}/terms?include_count=true&limit=100&skip=0&depth=0`, + `/v3/taxonomies/${mockData.taxonomiesResp.taxonomies[0].uid}/export?format=csv`, ) - .reply(200, mockData.termsResp); + .reply(200, mockData.taxonomyCSVData); }) .nock(cma, (api) => { api .get( - `/v3/taxonomies/${mockData.taxonomiesResp.taxonomies[1].uid}/terms?include_count=true&limit=100&skip=0&depth=0`, + `/v3/taxonomies/${mockData.taxonomiesResp.taxonomies[1].uid}/export?format=csv`, ) - .reply(200, { terms: [], count: 0 }); + .reply(200, mockData.taxonomyCSVData); }) .command([ 'cm:export-to-csv', @@ -117,9 +117,9 @@ describe('export-to-csv with action taxonomies', () => { .nock(cma, (api) => { api .get( - `/v3/taxonomies/${mockData.taxonomiesResp.taxonomies[0].uid}/terms?include_count=true&limit=100&skip=0&depth=0`, + `/v3/taxonomies/${mockData.taxonomiesResp.taxonomies[0].uid}/export?format=csv`, ) - .reply(200, mockData.termsResp); + .reply(200, mockData.taxonomyCSVData); }) .command(['cm:export-to-csv', '--taxonomy-uid', 'taxonomy_uid_1']) .it('CSV file should be created'); @@ -127,6 +127,7 @@ describe('export-to-csv with action taxonomies', () => { }); describe('export-to-csv with action entries', () => { + const test = fancy.loadConfig({ root: process.cwd() }); describe('Create entries csv file with flags', () => { test .stdout({ print: process.env.PRINT === 'true' || false }) @@ -239,6 +240,7 @@ describe('export-to-csv with action entries', () => { }); describe('export-to-csv with action users', () => { + const test = fancy.loadConfig({ root: process.cwd() }); describe('Export users csv file with flags', () => { test .stdout({ print: process.env.PRINT === 'true' || false }) @@ -290,7 +292,7 @@ describe('export-to-csv with action users', () => { }); describe('Testing the teams support in cli export-to-csv', () => { - + const test = fancy.loadConfig({ root: process.cwd() }); describe('Testing Teams Command with using org flag and team flag', () => { test .stdout({ print: process.env.PRINT === 'true' || false }) @@ -409,4 +411,4 @@ describe('Testing the teams support in cli export-to-csv', () => { .command(['cm:export-to-csv']) .it('CSV file should be created'); }); -}); \ No newline at end of file +}); diff --git a/packages/contentstack-import/package.json b/packages/contentstack-import/package.json index 1f031f07ce..f9bce332e0 100644 --- a/packages/contentstack-import/package.json +++ b/packages/contentstack-import/package.json @@ -8,7 +8,7 @@ "@contentstack/cli-audit": "~1.4.0", "@contentstack/cli-command": "~1.2.16", "@contentstack/cli-utilities": "~1.5.12", - "@contentstack/management": "^1.15.1", + "@contentstack/management": "^1.15.2", "@oclif/core": "^2.9.3", "big-json": "^3.2.0", "bluebird": "^3.7.2", diff --git a/packages/contentstack-seed/package.json b/packages/contentstack-seed/package.json index 22a7c5808e..29aa4985c6 100644 --- a/packages/contentstack-seed/package.json +++ b/packages/contentstack-seed/package.json @@ -5,7 +5,7 @@ "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { - "@contentstack/cli-cm-import": "~1.13.4", + "@contentstack/cli-cm-import": "~1.14.0", "@contentstack/cli-command": "~1.2.16", "@contentstack/cli-utilities": "~1.5.12", "inquirer": "8.2.4", diff --git a/packages/contentstack-utilities/package.json b/packages/contentstack-utilities/package.json index 09046f9574..0ba83fa15d 100644 --- a/packages/contentstack-utilities/package.json +++ b/packages/contentstack-utilities/package.json @@ -32,7 +32,7 @@ "author": "contentstack", "license": "MIT", "dependencies": { - "@contentstack/management": "^1.15.1", + "@contentstack/management": "^1.15.2", "@contentstack/marketplace-sdk": "^1.0.1", "@oclif/core": "^2.9.3", "axios": "^1.6.4", diff --git a/packages/contentstack/README.md b/packages/contentstack/README.md index 092ad93fcf..2a6ee9444b 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.13.3 darwin-arm64 node-v20.8.0 +@contentstack/cli/1.14.0 darwin-arm64 node-v20.8.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND @@ -169,14 +169,14 @@ Perform audits and fix possible errors in the exported Contentstack data. USAGE $ csdx audit:fix [-c ] [-d ] [--report-path ] [--modules content-types|global-fields|entries] [--copy-path --copy-dir] [--fix-only - reference|global_field|json:rte|json:custom-field|blocks|group] [--columns | ] [--sort ] [--filter + reference|global_field|json:rte|json:extension|blocks|group] [--columns | ] [--sort ] [--filter ] [--csv | --no-truncate] FLAGS --copy-dir Create backup from the original data. --copy-path= Provide the path to backup the copied data --fix-only=