@contentstack/cli-cm-import 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-import
37
37
  $ csdx COMMAND
38
38
  running command...
39
39
  $ csdx (--version)
40
- @contentstack/cli-cm-import/1.5.0 linux-x64 node-v16.20.0
40
+ @contentstack/cli-cm-import/1.5.1 linux-x64 node-v16.20.0
41
41
  $ csdx --help [COMMAND]
42
42
  USAGE
43
43
  $ csdx COMMAND
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.0",
2
+ "version": "1.5.1",
3
3
  "commands": {
4
4
  "cm:stacks:import": {
5
5
  "id": "cm:stacks:import",
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-import",
3
3
  "description": "Contentstack CLI plugin to import content into stack",
4
- "version": "1.5.0",
4
+ "version": "1.5.1",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
8
- "@contentstack/cli-command": "^1.2.1",
9
- "@contentstack/cli-utilities": "^1.2.1",
8
+ "@contentstack/cli-command": "^1.2.2",
9
+ "@contentstack/cli-utilities": "^1.3.1",
10
10
  "@oclif/config": "^1.18.3",
11
11
  "big-json": "^3.2.0",
12
12
  "bluebird": "^3.7.2",
@@ -50,6 +50,7 @@
50
50
  "prepack": "oclif manifest && oclif readme",
51
51
  "test": "nyc mocha --forbid-only \"test/**/*.test.js\"",
52
52
  "version": "oclif readme && git add README.md",
53
+ "test:integration": "mocha --forbid-only \"test/run.test.js\" --integration-test --timeout 60000",
53
54
  "clean": "rm -rf ./node_modules tsconfig.build.tsbuildinfo"
54
55
  },
55
56
  "main": "./src/commands/cm/stacks/import.js",
package/src/app.js CHANGED
@@ -58,10 +58,16 @@ exports.initial = (configData) => {
58
58
  };
59
59
 
60
60
  if (config) {
61
- if ((config.email && config.password) || isAuthenticated()) {
62
- login(config).then(backupAndImportData(APIClient, stackAPIClient)).catch(reject);
63
- } else if (config.management_token) {
61
+ if (config.management_token || config.isAuthenticated) {
64
62
  await backupAndImportData(APIClient, stackAPIClient);
63
+ } else if ((config.email && config.password) || isAuthenticated()) {
64
+ login(config).then(backupAndImportData(APIClient, stackAPIClient)).catch(reject);
65
+ } else if (config.email && config.password) {
66
+ login(config)
67
+ .then(backupAndImportData.apply(null, [APIClient, stackAPIClient]))
68
+ .catch(reject);
69
+ } else {
70
+ reject('Kindly login or provide management_token');
65
71
  }
66
72
  }
67
73
  });
@@ -26,6 +26,7 @@ class ImportCommand extends Command {
26
26
  delete importCommandFlags.branch;
27
27
  delete importCommandFlags['import-webhook-status'];
28
28
  let host = self.cmaHost;
29
+ importCommandFlags['isAuthenticated'] = isAuthenticated();
29
30
 
30
31
  return new Promise((resolve, reject) => {
31
32
  if (data) {
@@ -41,31 +42,11 @@ class ImportCommand extends Command {
41
42
  let result;
42
43
 
43
44
  if ((extConfig && isAuthenticated()) || alias) {
44
- result = configWithMToken(
45
- extConfig,
46
- managementTokens,
47
- moduleName,
48
- host,
49
- backupdir,
50
- importCommandFlags,
51
- );
45
+ result = configWithMToken(extConfig, managementTokens, moduleName, host, backupdir, importCommandFlags);
52
46
  } else if (data) {
53
- result = parameterWithMToken(
54
- managementTokens,
55
- data,
56
- moduleName,
57
- host,
58
- backupdir,
59
- importCommandFlags,
60
- );
47
+ result = parameterWithMToken(managementTokens, data, moduleName, host, backupdir, importCommandFlags);
61
48
  } else {
62
- result = withoutParameterMToken(
63
- managementTokens,
64
- moduleName,
65
- host,
66
- backupdir,
67
- importCommandFlags,
68
- );
49
+ result = withoutParameterMToken(managementTokens, moduleName, host, backupdir, importCommandFlags);
69
50
  }
70
51
 
71
52
  result.then(resolve).catch(reject);
@@ -78,14 +59,7 @@ class ImportCommand extends Command {
78
59
  if (extConfig) {
79
60
  result = configWithAuthToken(extConfig, moduleName, host, backupdir, importCommandFlags);
80
61
  } else if (targetStack && data) {
81
- result = parametersWithAuthToken(
82
- targetStack,
83
- data,
84
- moduleName,
85
- host,
86
- backupdir,
87
- importCommandFlags,
88
- );
62
+ result = parametersWithAuthToken(targetStack, data, moduleName, host, backupdir, importCommandFlags);
89
63
  } else {
90
64
  result = withoutParametersWithAuthToken(moduleName, host, backupdir, importCommandFlags);
91
65
  }
@@ -127,7 +127,7 @@ class ContentTypesImport {
127
127
  try {
128
128
  await this.stackAPIClient.contentType().create(requestObject.json);
129
129
  } catch (error) {
130
- if (error.error_code === 115 && (error.errors.uid || error.errors.title)) {
130
+ if (error.errorCode === 115 && (error.errors.uid || error.errors.title)) {
131
131
  // content type uid already exists
132
132
  // _.remove(self.contentTypes, { uid: uid });
133
133
  return true;
@@ -1007,7 +1007,7 @@ module.exports = class ImportEntries {
1007
1007
  addlogs(this.config, 'field_rules is not available', 'error');
1008
1008
  }
1009
1009
 
1010
- self.stackAPIClient
1010
+ this.stackAPIClient
1011
1011
  .contentType(schema.uid)
1012
1012
  .fetch()
1013
1013
  .then((contentTypeResponse) => {
@@ -70,7 +70,7 @@ module.exports = class ImportLanguages {
70
70
  let langUids = Object.keys(self.languages);
71
71
  return Promise.map(
72
72
  langUids,
73
- function (langUid) {
73
+ (langUid) => {
74
74
  let lang = self.languages[langUid];
75
75
  if (!self.langUidMapper.hasOwnProperty(langUid) && lang.code !== self.masterLanguage) {
76
76
  let requestOption = {
@@ -8,8 +8,15 @@ const _ = require('lodash');
8
8
  const path = require('path');
9
9
  const chalk = require('chalk');
10
10
  const mkdirp = require('mkdirp');
11
- const contentstack = require('@contentstack/management');
12
- const { cliux, HttpClient, NodeCrypto, managementSDKClient, configHandler, isAuthenticated } = require('@contentstack/cli-utilities');
11
+ const {
12
+ cliux,
13
+ HttpClient,
14
+ NodeCrypto,
15
+ managementSDKClient,
16
+ isAuthenticated,
17
+ HttpClientDecorator,
18
+ OauthDecorator,
19
+ } = require('@contentstack/cli-utilities');
13
20
 
14
21
  const { formatError } = require('../util');
15
22
  let config = require('../../config/default');
@@ -53,16 +60,19 @@ module.exports = class ImportMarketplaceApps {
53
60
  }
54
61
 
55
62
  this.developerHubBaseUrl = this.config.developerHubBaseUrl || (await getDeveloperHubUrl(this.config));
56
- this.client = contentstack.client({ authtoken: configHandler.get('authtoken'), endpoint: this.developerHubBaseUrl });
63
+ this.client = await managementSDKClient({ endpoint: this.developerHubBaseUrl });
57
64
 
58
65
  await this.getOrgUid();
59
66
 
60
- this.httpClient = new HttpClient({
61
- headers: {
62
- authtoken: configHandler.get('authtoken'),
63
- organization_uid: this.config.org_uid,
64
- },
65
- });
67
+ const httpClient = new HttpClient();
68
+ if (!this.config.auth_token) {
69
+ this.httpClient = new OauthDecorator(httpClient);
70
+ const headers = await this.httpClient.preHeadersCheck(this.config);
71
+ this.httpClient = this.httpClient.headers(headers);
72
+ } else {
73
+ this.httpClient = new HttpClientDecorator(httpClient);
74
+ this.httpClient.headers(this.config);
75
+ }
66
76
 
67
77
  if (!fs.existsSync(this.mapperDirPath)) {
68
78
  mkdirp.sync(this.mapperDirPath);
@@ -72,18 +82,16 @@ module.exports = class ImportMarketplaceApps {
72
82
  }
73
83
 
74
84
  async getOrgUid() {
75
- if (isAuthenticated()) {
76
- const tempAPIClient = await managementSDKClient({ host: this.config.host });
77
- const tempStackData = await tempAPIClient
78
- .stack({ api_key: this.config.target_stack })
79
- .fetch()
80
- .catch((error) => {
81
- console.log(error);
82
- });
85
+ const tempAPIClient = await managementSDKClient({ host: this.config.host });
86
+ const tempStackData = await tempAPIClient
87
+ .stack({ api_key: this.config.target_stack })
88
+ .fetch()
89
+ .catch((error) => {
90
+ console.log(error);
91
+ });
83
92
 
84
- if (tempStackData && tempStackData.org_uid) {
85
- this.config.org_uid = tempStackData.org_uid;
86
- }
93
+ if (tempStackData && tempStackData.org_uid) {
94
+ this.config.org_uid = tempStackData.org_uid;
87
95
  }
88
96
  }
89
97
 
@@ -288,7 +296,7 @@ module.exports = class ImportMarketplaceApps {
288
296
  } else {
289
297
  log(this.config, formatError(message), 'error');
290
298
 
291
- if (this.config.forceStopMarketplaceAppsPrompt) return resolve();
299
+ if (this.config.forceStopMarketplaceAppsPrompt) return Promise.resolve();
292
300
 
293
301
  if (
294
302
  await cliux.confirm(
@@ -297,7 +305,7 @@ module.exports = class ImportMarketplaceApps {
297
305
  ),
298
306
  )
299
307
  ) {
300
- resolve();
308
+ Promise.resolve();
301
309
  } else {
302
310
  process.exit();
303
311
  }
@@ -386,9 +394,9 @@ module.exports = class ImportMarketplaceApps {
386
394
  .catch((error) => error);
387
395
 
388
396
  if (installation.installation_uid) {
389
- let appName = (this.appNameMapping[app.manifest.name]) ?
390
- this.appNameMapping[app.manifest.name] :
391
- app.manifest.name ;
397
+ let appName = this.appNameMapping[app.manifest.name]
398
+ ? this.appNameMapping[app.manifest.name]
399
+ : app.manifest.name;
392
400
  log(this.config, `${appName} app installed successfully.!`, 'success');
393
401
  await this.makeRedirectUrlCall(installation, app.manifest.name);
394
402
  this.installationUidMapping[app.uid] = installation.installation_uid;
@@ -30,6 +30,7 @@ exports.configWithMToken = function (
30
30
  defaultConfig.target_stack = managementTokens.apiKey;
31
31
  defaultConfig.management_token = managementTokens.token;
32
32
  defaultConfig.importWebhookStatus = importCommandFlags.importWebhookStatus;
33
+ defaultConfig.isAuthenticated = importCommandFlags.isAuthenticated;
33
34
 
34
35
  if (moduleName && moduleName !== undefined) {
35
36
  defaultConfig.moduleName = moduleName;
@@ -41,9 +42,9 @@ exports.configWithMToken = function (
41
42
 
42
43
  defaultConfig = _.merge(defaultConfig, externalConfig);
43
44
 
44
- if(!defaultConfig.data) {
45
+ if (!defaultConfig.data) {
45
46
  const exporteddata = await cliux.prompt(message.promptMessageList.promptPathStoredData);
46
- defaultConfig.data = exporteddata
47
+ defaultConfig.data = exporteddata;
47
48
  }
48
49
 
49
50
  if (_.isArray(modules)) {
@@ -67,6 +68,7 @@ exports.parameterWithMToken = function (
67
68
  defaultConfig.target_stack = managementTokens.apiKey;
68
69
  defaultConfig.branchName = importCommandFlags.branchName;
69
70
  defaultConfig.importWebhookStatus = importCommandFlags.importWebhookStatus;
71
+ defaultConfig.isAuthenticated = importCommandFlags.isAuthenticated;
70
72
  if (moduleName && moduleName !== undefined) {
71
73
  defaultConfig.moduleName = moduleName;
72
74
  }
@@ -93,6 +95,7 @@ exports.withoutParameterMToken = async (
93
95
  defaultConfig.target_stack = managementTokens.apiKey;
94
96
  defaultConfig.branchName = importCommandFlags.branchName;
95
97
  defaultConfig.importWebhookStatus = importCommandFlags.importWebhookStatus;
98
+ defaultConfig.isAuthenticated = importCommandFlags.isAuthenticated;
96
99
  if (moduleName && moduleName !== undefined) {
97
100
  defaultConfig.moduleName = moduleName;
98
101
  }
@@ -110,6 +113,7 @@ exports.configWithAuthToken = function (config, moduleName, host, backupdir, imp
110
113
  let externalConfig = require(config);
111
114
  defaultConfig.branchName = importCommandFlags.branchName;
112
115
  defaultConfig.importWebhookStatus = importCommandFlags.importWebhookStatus;
116
+ defaultConfig.isAuthenticated = importCommandFlags.isAuthenticated;
113
117
  if (moduleName && moduleName !== undefined) {
114
118
  defaultConfig.moduleName = moduleName;
115
119
  }
@@ -126,7 +130,7 @@ exports.configWithAuthToken = function (config, moduleName, host, backupdir, imp
126
130
  defaultConfig = _.merge(defaultConfig, externalConfig);
127
131
  if (!defaultConfig.data) {
128
132
  const exporteddata = await cliux.prompt(message.promptMessageList.promptPathStoredData);
129
- defaultConfig.data = exporteddata
133
+ defaultConfig.data = exporteddata;
130
134
  }
131
135
  initial(defaultConfig).then(resolve).catch(reject);
132
136
  });
@@ -144,6 +148,7 @@ exports.parametersWithAuthToken = function (
144
148
  defaultConfig.target_stack = targetStack;
145
149
  defaultConfig.branchName = importCommandFlags.branchName;
146
150
  defaultConfig.importWebhookStatus = importCommandFlags.importWebhookStatus;
151
+ defaultConfig.isAuthenticated = importCommandFlags.isAuthenticated;
147
152
  if (moduleName && moduleName !== undefined && backupdir === undefined) {
148
153
  defaultConfig.moduleName = moduleName;
149
154
  } else if (moduleName && moduleName !== undefined && backupdir !== undefined) {
@@ -167,6 +172,7 @@ exports.withoutParametersWithAuthToken = async (moduleName, host, backupdir, imp
167
172
  defaultConfig.data = exporteddata;
168
173
  defaultConfig.branchName = importCommandFlags.branchName;
169
174
  defaultConfig.importWebhookStatus = importCommandFlags.importWebhookStatus;
175
+ defaultConfig.isAuthenticated = importCommandFlags.isAuthenticated;
170
176
  if (moduleName && moduleName !== undefined && backupdir === undefined) {
171
177
  defaultConfig.moduleName = moduleName;
172
178
  } else if (moduleName && moduleName !== undefined && backupdir !== undefined) {