diff --git a/package-lock.json b/package-lock.json index f2ac8d42f1..dd8e12105d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24797,7 +24797,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", @@ -25575,7 +25575,7 @@ }, "packages/contentstack-utilities": { "name": "@contentstack/cli-utilities", - "version": "1.5.6", + "version": "1.5.7", "license": "MIT", "dependencies": { "@contentstack/management": "~1.12.0", diff --git a/packages/contentstack-import/package.json b/packages/contentstack-import/package.json index bbe42d7137..3bdf911f95 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 1f1a09fd41..f92999429b 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'; @@ -26,19 +26,9 @@ 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 (data.error_code === 161) { - throw new Error(data.error_message); + if (this.importConfig.management_token) { + 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 34ff07bfd4..09885b7a97 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 {