Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(import): fixed stack inaccessible issue #1067

Merged
merged 15 commits into from
Nov 24, 2023
Merged
6 changes: 2 additions & 4 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",
netrajpatel marked this conversation as resolved.
Show resolved Hide resolved
"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);
vkalta marked this conversation as resolved.
Show resolved Hide resolved
}

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
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

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

Loading