From c0ac9f56d17a5496e5216cf16b2fef5b6be196be Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Fri, 21 Jun 2024 12:44:03 +0530 Subject: [PATCH] fix: handle taxonomy & environment mapper issue --- package-lock.json | 10 ++++---- packages/contentstack-clone/package.json | 2 +- packages/contentstack-import/README.md | 2 +- packages/contentstack-import/package.json | 2 +- .../src/import/modules/environments.ts | 24 +++++++++++++++---- .../src/import/modules/taxonomies.ts | 18 +++++++++----- packages/contentstack-seed/package.json | 2 +- packages/contentstack/package.json | 4 ++-- pnpm-lock.yaml | 6 ++--- 9 files changed, 46 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index 059890791b..d44785f30d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24870,7 +24870,7 @@ }, "packages/contentstack": { "name": "@contentstack/cli", - "version": "1.19.0", + "version": "1.19.1", "license": "MIT", "dependencies": { "@contentstack/cli-audit": "~1.6.2", @@ -24881,7 +24881,7 @@ "@contentstack/cli-cm-clone": "~1.10.5", "@contentstack/cli-cm-export": "~1.11.4", "@contentstack/cli-cm-export-to-csv": "~1.7.1", - "@contentstack/cli-cm-import": "~1.15.7", + "@contentstack/cli-cm-import": "~1.15.8", "@contentstack/cli-cm-migrate-rte": "~1.4.17", "@contentstack/cli-cm-seed": "~1.7.5", "@contentstack/cli-command": "~1.2.18", @@ -25423,7 +25423,7 @@ "dependencies": { "@colors/colors": "^1.5.0", "@contentstack/cli-cm-export": "~1.11.4", - "@contentstack/cli-cm-import": "~1.15.7", + "@contentstack/cli-cm-import": "~1.15.8", "@contentstack/cli-command": "~1.2.18", "@contentstack/cli-utilities": "~1.6.2", "async": "^3.2.4", @@ -26508,7 +26508,7 @@ }, "packages/contentstack-import": { "name": "@contentstack/cli-cm-import", - "version": "1.15.7", + "version": "1.15.8", "license": "MIT", "dependencies": { "@contentstack/cli-audit": "~1.6.2", @@ -26993,7 +26993,7 @@ "version": "1.7.5", "license": "MIT", "dependencies": { - "@contentstack/cli-cm-import": "~1.15.7", + "@contentstack/cli-cm-import": "~1.15.8", "@contentstack/cli-command": "~1.2.18", "@contentstack/cli-utilities": "~1.6.2", "inquirer": "8.2.4", diff --git a/packages/contentstack-clone/package.json b/packages/contentstack-clone/package.json index 1805af5db7..dd7b05af0a 100644 --- a/packages/contentstack-clone/package.json +++ b/packages/contentstack-clone/package.json @@ -7,7 +7,7 @@ "dependencies": { "@colors/colors": "^1.5.0", "@contentstack/cli-cm-export": "~1.11.4", - "@contentstack/cli-cm-import": "~1.15.7", + "@contentstack/cli-cm-import": "~1.15.8", "@contentstack/cli-command": "~1.2.18", "@contentstack/cli-utilities": "~1.6.2", "async": "^3.2.4", diff --git a/packages/contentstack-import/README.md b/packages/contentstack-import/README.md index 515c62c35e..195b856b92 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.15.6 darwin-arm64 node-v21.6.2 +@contentstack/cli-cm-import/1.15.8 darwin-arm64 node-v18.20.2 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-import/package.json b/packages/contentstack-import/package.json index 15ca62e95c..d0868cfd11 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.15.7", + "version": "1.15.8", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { diff --git a/packages/contentstack-import/src/import/modules/environments.ts b/packages/contentstack-import/src/import/modules/environments.ts index 7bff9e57c6..3695b61d4c 100644 --- a/packages/contentstack-import/src/import/modules/environments.ts +++ b/packages/contentstack-import/src/import/modules/environments.ts @@ -20,7 +20,7 @@ export default class ImportEnvironments extends BaseClass { constructor({ importConfig, stackAPIClient }: ModuleClassParams) { super({ importConfig, stackAPIClient }); - this.environmentsConfig =importConfig.modules.environments; + this.environmentsConfig = importConfig.modules.environments; this.mapperDirPath = join(this.importConfig.backupDir, 'mapper', 'environments'); this.environmentsFolderPath = join(this.importConfig.backupDir, this.environmentsConfig.dirName); this.envUidMapperPath = join(this.mapperDirPath, 'uid-mapping.json'); @@ -40,7 +40,10 @@ export default class ImportEnvironments extends BaseClass { //Step1 check folder exists or not if (fileHelper.fileExistsSync(this.environmentsFolderPath)) { - this.environments = fsUtil.readFile(join(this.environmentsFolderPath, 'environments.json'), true) as Record; + this.environments = fsUtil.readFile(join(this.environmentsFolderPath, 'environments.json'), true) as Record< + string, + unknown + >; } else { log(this.importConfig, `No such file or directory - '${this.environmentsFolderPath}'`, 'error'); return; @@ -79,10 +82,13 @@ export default class ImportEnvironments extends BaseClass { fsUtil.writeFile(this.envUidMapperPath, this.envUidMapper); }; - const onReject = ({ error, apiData }: any) => { + const onReject = async ({ error, apiData }: any) => { const err = error?.message ? JSON.parse(error.message) : error; - const { name } = apiData; + const { name, uid } = apiData; if (err?.errors?.name) { + const res = await this.getEnvDetails(name); + this.envUidMapper[uid] = res?.uid || ' '; + fsUtil.writeFile(this.envUidMapperPath, this.envUidMapper); log(this.importConfig, `Environment '${name}' already exists`, 'info'); } else { this.envFailed.push(apiData); @@ -128,4 +134,14 @@ export default class ImportEnvironments extends BaseClass { } return apiOptions; } + + async getEnvDetails(envName: string) { + return await this.stack + .environment(envName) + .fetch() + .then((data: any) => data) + .catch((error: any) => { + log(this.importConfig, `Failed to fetch environment details. ${formatError(error)}`, 'error'); + }); + } } diff --git a/packages/contentstack-import/src/import/modules/taxonomies.ts b/packages/contentstack-import/src/import/modules/taxonomies.ts index f033715768..ce2bd885f5 100644 --- a/packages/contentstack-import/src/import/modules/taxonomies.ts +++ b/packages/contentstack-import/src/import/modules/taxonomies.ts @@ -85,14 +85,20 @@ export default class ImportTaxonomies extends BaseClass { const onReject = ({ error, apiData }: any) => { const taxonomyUID = apiData?.taxonomy?.uid; - if (error?.errorMessage || error?.message) { - const errorMsg = error?.errorMessage || error?.errors?.taxonomy || error?.errors?.term || error?.message; - log(this.importConfig, `Taxonomy '${taxonomyUID}' failed to be import! ${errorMsg}`, 'error'); + if (error?.status === 409 && error?.statusText === 'Conflict') { + log(this.importConfig, `Taxonomy '${taxonomyUID}' already exists!`, 'info'); + this.createdTaxonomies[taxonomyUID] = apiData?.taxonomy; + this.createdTerms[taxonomyUID] = apiData?.terms; } else { - log(this.importConfig, `Taxonomy '${taxonomyUID}' failed to be import! ${formatError(error)}`, 'error'); + if (error?.errorMessage || error?.message) { + const errorMsg = error?.errorMessage || error?.errors?.taxonomy || error?.errors?.term || error?.message; + log(this.importConfig, `Taxonomy '${taxonomyUID}' failed to be import! ${errorMsg}`, 'error'); + } else { + log(this.importConfig, `Taxonomy '${taxonomyUID}' failed to be import! ${formatError(error)}`, 'error'); + } + this.failedTaxonomies[taxonomyUID] = apiData?.taxonomy; + this.failedTerms[taxonomyUID] = apiData?.terms; } - this.failedTaxonomies[taxonomyUID] = apiData?.taxonomy; - this.failedTerms[taxonomyUID] = apiData?.terms; }; await this.makeConcurrentCall( diff --git a/packages/contentstack-seed/package.json b/packages/contentstack-seed/package.json index cebae6f8a6..37d2a981e7 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.15.7", + "@contentstack/cli-cm-import": "~1.15.8", "@contentstack/cli-command": "~1.2.18", "@contentstack/cli-utilities": "~1.6.2", "inquirer": "8.2.4", diff --git a/packages/contentstack/package.json b/packages/contentstack/package.json index 0167d6398e..1ddc7b24c5 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.19.0", + "version": "1.19.1", "author": "Contentstack", "bin": { "csdx": "./bin/run.js" @@ -30,7 +30,7 @@ "@contentstack/cli-cm-export": "~1.11.4", "@contentstack/cli-cm-clone": "~1.10.5", "@contentstack/cli-cm-export-to-csv": "~1.7.1", - "@contentstack/cli-cm-import": "~1.15.7", + "@contentstack/cli-cm-import": "~1.15.8", "@contentstack/cli-cm-migrate-rte": "~1.4.17", "@contentstack/cli-cm-seed": "~1.7.5", "@contentstack/cli-command": "~1.2.18", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 00f3616b22..06f972caa0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -18,7 +18,7 @@ importers: '@contentstack/cli-cm-clone': ~1.10.5 '@contentstack/cli-cm-export': ~1.11.4 '@contentstack/cli-cm-export-to-csv': ~1.7.1 - '@contentstack/cli-cm-import': ~1.15.7 + '@contentstack/cli-cm-import': ~1.15.8 '@contentstack/cli-cm-migrate-rte': ~1.4.17 '@contentstack/cli-cm-seed': ~1.7.5 '@contentstack/cli-command': ~1.2.18 @@ -424,7 +424,7 @@ importers: specifiers: '@colors/colors': ^1.5.0 '@contentstack/cli-cm-export': ~1.11.4 - '@contentstack/cli-cm-import': ~1.15.7 + '@contentstack/cli-cm-import': ~1.15.8 '@contentstack/cli-command': ~1.2.18 '@contentstack/cli-utilities': ~1.6.2 '@oclif/test': ^2.5.6 @@ -990,7 +990,7 @@ importers: packages/contentstack-seed: specifiers: - '@contentstack/cli-cm-import': ~1.15.7 + '@contentstack/cli-cm-import': ~1.15.8 '@contentstack/cli-command': ~1.2.18 '@contentstack/cli-utilities': ~1.6.2 '@oclif/plugin-help': ^5.1.19