Skip to content

Commit

Permalink
Merge pull request #1067 from contentstack/fix/41082
Browse files Browse the repository at this point in the history
fix(import): fixed stack  inaccessible issue
  • Loading branch information
aman19K authored Nov 24, 2023
2 parents f56f374 + 23eddae commit fa3b22e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 17 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/contentstack-import/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
16 changes: 3 additions & 13 deletions packages/contentstack-import/src/import/module-importer.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-utilities/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
18 changes: 18 additions & 0 deletions packages/contentstack-utilities/src/add-locale.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
1 change: 1 addition & 0 deletions packages/contentstack-utilities/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit fa3b22e

Please sign in to comment.