From dbc3db30a946a38826925221dda3e510b5b45141 Mon Sep 17 00:00:00 2001 From: Vikram Kalta Date: Thu, 28 Sep 2023 13:00:47 +0100 Subject: [PATCH 1/5] fix(import): fixed stack inaccessible issue --- packages/contentstack-import/src/import/module-importer.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/contentstack-import/src/import/module-importer.ts b/packages/contentstack-import/src/import/module-importer.ts index 36551d16d0..030f2e5243 100755 --- a/packages/contentstack-import/src/import/module-importer.ts +++ b/packages/contentstack-import/src/import/module-importer.ts @@ -37,8 +37,8 @@ class ModuleImporter { }, }); - if (data.error_code === 161) { - throw new Error(data.error_message); + if ([161, 105].includes(data.error_code)) { + throw new Error(data.error_code === 105 ? 'Sorry but you don\'t have access to this stack' : data.error_message); } if (!this.importConfig.master_locale) { From 12ed34769cc82c3916d218667ea84d33b48d4aea Mon Sep 17 00:00:00 2001 From: Vikram Kalta Date: Thu, 5 Oct 2023 13:16:03 +0100 Subject: [PATCH 2/5] fix: updated version --- package-lock.json | 2 +- packages/contentstack-import/package.json | 2 +- pnpm-lock.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8ac7a4dd98..a7fd24a91d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24178,7 +24178,7 @@ }, "packages/contentstack-import": { "name": "@contentstack/cli-cm-import", - "version": "1.9.0", + "version": "1.9.1", "license": "MIT", "dependencies": { "@contentstack/cli-command": "~1.2.12", diff --git a/packages/contentstack-import/package.json b/packages/contentstack-import/package.json index f92f51477c..c77d3651c0 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.9.0", + "version": "1.9.1", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 71c060cd31..f77a2dacca 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,7 +17,7 @@ importers: '@contentstack/cli-cm-clone': ~1.5.0 '@contentstack/cli-cm-export': ~1.9.0 '@contentstack/cli-cm-export-to-csv': ~1.4.2 - '@contentstack/cli-cm-import': ~1.9.0 + '@contentstack/cli-cm-import': ~1.9.1 '@contentstack/cli-cm-migrate-rte': ~1.4.11 '@contentstack/cli-cm-seed': ~1.5.0 '@contentstack/cli-command': ~1.2.12 From e2dab55507ce58a43137e776f9620b9c22762780 Mon Sep 17 00:00:00 2001 From: Vikram Kalta Date: Fri, 6 Oct 2023 12:04:17 +0100 Subject: [PATCH 3/5] fix: updated version --- package-lock.json | 2 +- packages/contentstack-import/package.json | 2 +- pnpm-lock.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 071561e287..b6d109bc10 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24423,7 +24423,7 @@ }, "packages/contentstack-import": { "name": "@contentstack/cli-cm-import", - "version": "1.9.1", + "version": "1.9.2", "license": "MIT", "dependencies": { "@contentstack/cli-command": "~1.2.13", diff --git a/packages/contentstack-import/package.json b/packages/contentstack-import/package.json index 001d5b5000..65667a586f 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.9.1", + "version": "1.9.2", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8bb2c1460a..638ea7df43 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -18,7 +18,7 @@ importers: '@contentstack/cli-cm-clone': ~1.5.1 '@contentstack/cli-cm-export': ~1.9.1 '@contentstack/cli-cm-export-to-csv': ~1.4.3 - '@contentstack/cli-cm-import': ~1.9.1 + '@contentstack/cli-cm-import': ~1.9.2 '@contentstack/cli-cm-migrate-rte': ~1.4.12 '@contentstack/cli-cm-seed': ~1.5.1 '@contentstack/cli-command': ~1.2.13 From b457fbd1c726ee58ef6ffa79c95d1d3552ac0723 Mon Sep 17 00:00:00 2001 From: Vikram Kalta Date: Wed, 18 Oct 2023 11:47:26 +0100 Subject: [PATCH 4/5] fix: minor fix --- .../src/import/module-importer.ts | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/packages/contentstack-import/src/import/module-importer.ts b/packages/contentstack-import/src/import/module-importer.ts index e89ea9948e..f6270792d9 100755 --- a/packages/contentstack-import/src/import/module-importer.ts +++ b/packages/contentstack-import/src/import/module-importer.ts @@ -26,19 +26,21 @@ class ModuleImporter { // Temporarily adding this api call to verify management token has read and write permissions // TODO: CS-40354 - CLI | import rewrite | Migrate HTTP call to SDK call once fix is ready from SDK side - const httpClient = new HttpClient({ - headers: { api_key: this.importConfig.apiKey, authorization: this.importConfig.management_token }, - }); - - const { data } = await httpClient.post(`https://${this.importConfig.host}/v3/locales`, { - locale: { - name: 'English', - code: 'en-us', - }, - }); - - if ([161, 105].includes(data.error_code)) { - throw new Error(data.error_code === 105 ? 'Sorry but you don\'t have access to this stack' : data.error_message); + if (this.importConfig.management_token) { + const httpClient = new HttpClient({ + headers: { api_key: this.importConfig.apiKey, authorization: this.importConfig.management_token }, + }); + + const { data } = await httpClient.post(`https://${this.importConfig.host}/v3/locales`, { + locale: { + name: 'English', + code: 'en-us', + }, + }); + + if ([161, 105].includes(data.error_code)) { + throw new Error(data.error_code === 105 ? 'Sorry but you don\'t have access to this stack' : data.error_message); + } } if (!this.importConfig.master_locale) { From 921cf49d168b2a6f60aa1bcfd0fef940230e3d39 Mon Sep 17 00:00:00 2001 From: Vikram Kalta Date: Tue, 14 Nov 2023 14:54:59 +0000 Subject: [PATCH 5/5] fix: added add locale util --- package-lock.json | 6 ++---- packages/contentstack-import/package.json | 2 +- .../src/import/module-importer.ts | 17 ++--------------- packages/contentstack-utilities/package.json | 2 +- .../contentstack-utilities/src/add-locale.ts | 18 ++++++++++++++++++ packages/contentstack-utilities/src/index.ts | 1 + pnpm-lock.yaml | 2 ++ 7 files changed, 27 insertions(+), 21 deletions(-) create mode 100644 packages/contentstack-utilities/src/add-locale.ts diff --git a/package-lock.json b/package-lock.json index 6b8ba4c9f2..93ecf986df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24048,7 +24048,6 @@ "winston": "^3.7.2" }, "devDependencies": { - "@contentstack/cli-dev-dependencies": "^1.2.3", "@oclif/test": "^2.2.10", "@types/chai": "^4.2.18", "@types/inquirer": "^9.0.3", @@ -24639,7 +24638,7 @@ }, "packages/contentstack-import": { "name": "@contentstack/cli-cm-import", - "version": "1.11.0", + "version": "1.11.1", "license": "MIT", "dependencies": { "@contentstack/cli-command": "~1.2.15", @@ -25417,7 +25416,7 @@ }, "packages/contentstack-utilities": { "name": "@contentstack/cli-utilities", - "version": "1.5.6", + "version": "1.5.7", "license": "MIT", "dependencies": { "@contentstack/management": "~1.11.0", @@ -28472,7 +28471,6 @@ "version": "file:packages/contentstack-config", "requires": { "@contentstack/cli-command": "~1.2.15", - "@contentstack/cli-dev-dependencies": "^1.2.3", "@contentstack/cli-utilities": "~1.5.5", "@oclif/test": "^2.2.10", "@types/chai": "^4.2.18", diff --git a/packages/contentstack-import/package.json b/packages/contentstack-import/package.json index 756eba878c..44d4f00a28 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.11.0", + "version": "1.11.1", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { diff --git a/packages/contentstack-import/src/import/module-importer.ts b/packages/contentstack-import/src/import/module-importer.ts index 9a89200315..f42c66ade8 100755 --- a/packages/contentstack-import/src/import/module-importer.ts +++ b/packages/contentstack-import/src/import/module-importer.ts @@ -1,4 +1,4 @@ -import { ContentstackClient, HttpClient } from '@contentstack/cli-utilities'; +import { addLocale, ContentstackClient } from '@contentstack/cli-utilities'; import startModuleImport from './modules'; import startJSModuleImport from './modules-js'; @@ -28,20 +28,7 @@ class ModuleImporter { // TODO: CS-40354 - CLI | import rewrite | Migrate HTTP call to SDK call once fix is ready from SDK side if (this.importConfig.management_token) { - const httpClient = new HttpClient({ - headers: { api_key: this.importConfig.apiKey, authorization: this.importConfig.management_token }, - }); - - const { data } = await httpClient.post(`https://${this.importConfig.host}/v3/locales`, { - locale: { - name: 'English', - code: 'en-us', - }, - }); - - if ([161, 105].includes(data.error_code)) { - throw new Error(data.error_code === 105 ? 'Sorry but you don\'t have access to this stack' : data.error_message); - } + await addLocale(this.importConfig.apiKey, this.importConfig.management_token, this.importConfig.host); } if (!this.importConfig.master_locale) { diff --git a/packages/contentstack-utilities/package.json b/packages/contentstack-utilities/package.json index 08b65d90dc..3ed617b3ab 100644 --- a/packages/contentstack-utilities/package.json +++ b/packages/contentstack-utilities/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/cli-utilities", - "version": "1.5.6", + "version": "1.5.7", "description": "Utilities for contentstack projects", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/packages/contentstack-utilities/src/add-locale.ts b/packages/contentstack-utilities/src/add-locale.ts new file mode 100644 index 0000000000..c1a7845c22 --- /dev/null +++ b/packages/contentstack-utilities/src/add-locale.ts @@ -0,0 +1,18 @@ +import { HttpClient } from './http-client'; + +export const addLocale = async (apiKey, managementToken, host) => { + const httpClient = new HttpClient({ + headers: { api_key: apiKey, authorization: managementToken }, + }); + + const { data } = await httpClient.post(`https://${host}/v3/locales`, { + locale: { + name: 'English', + code: 'en-us', + }, + }); + + if ([161, 105].includes(data.error_code)) { + throw new Error(data.error_code === 105 ? 'Sorry but you don\'t have access to this stack' : data.error_message); + } +} \ No newline at end of file diff --git a/packages/contentstack-utilities/src/index.ts b/packages/contentstack-utilities/src/index.ts index 0a9d76f8dc..61703a1584 100644 --- a/packages/contentstack-utilities/src/index.ts +++ b/packages/contentstack-utilities/src/index.ts @@ -19,6 +19,7 @@ export { Args as args, Flags as flags, Command } from './cli-ux'; export * from './helpers'; export * from './interfaces'; export * from './date-time'; +export * from './add-locale'; // NOTE Exporting all @oclif/core modules: So that all the module can be acessed through cli-utility export { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 73fec971f7..94071405f5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -122,6 +122,7 @@ importers: packages/contentstack-audit: specifiers: '@contentstack/cli-command': ~1.2.15 + '@contentstack/cli-dev-dependencies': ^1.2.3 '@contentstack/cli-utilities': ~1.5.5 '@oclif/plugin-help': ^5 '@oclif/plugin-plugins': ^3.8.4 @@ -161,6 +162,7 @@ importers: uuid: 9.0.1 winston: 3.10.0 devDependencies: + '@contentstack/cli-dev-dependencies': link:../contentstack-dev-dependencies '@oclif/test': 2.3.31_eyayto62fyd4eo5o5fvolpu7d4 '@types/chai': 4.3.5 '@types/fs-extra': 11.0.2