@contentstack/cli-cm-import 1.3.0 → 1.5.0

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022 Contentstack
3
+ Copyright (c) 2023 Contentstack
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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.3.0 linux-x64 node-v16.19.0
40
+ @contentstack/cli-cm-import/1.5.0 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.3.0",
2
+ "version": "1.5.0",
3
3
  "commands": {
4
4
  "cm:stacks:import": {
5
5
  "id": "cm:stacks:import",
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-import",
3
3
  "description": "Contentstack CLI plugin to import content into stack",
4
- "version": "1.3.0",
4
+ "version": "1.5.0",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
8
- "@contentstack/cli-command": "^1.1.0",
9
- "@contentstack/cli-utilities": "^1.1.0",
8
+ "@contentstack/cli-command": "^1.2.1",
9
+ "@contentstack/cli-utilities": "^1.2.1",
10
10
  "@oclif/config": "^1.18.3",
11
11
  "big-json": "^3.2.0",
12
12
  "bluebird": "^3.7.2",
13
+ "chalk": "^4.1.2",
13
14
  "debug": "^4.1.0",
14
15
  "lodash": "^4.17.20",
15
16
  "marked": "^4.0.17",
@@ -19,17 +20,17 @@
19
20
  "winston": "^3.7.2"
20
21
  },
21
22
  "devDependencies": {
22
- "oclif": "^3.1.2",
23
23
  "@oclif/test": "^1.2.6",
24
24
  "chai": "^4.2.0",
25
25
  "eslint": "^8.18.0",
26
- "eslint-config-oclif": "^3.1.0",
26
+ "eslint-config-oclif": "^4.0.0",
27
27
  "globby": "^10.0.2",
28
28
  "mocha": "^10.0.0",
29
- "nyc": "^15.1.0"
29
+ "nyc": "^15.1.0",
30
+ "oclif": "^3.1.2"
30
31
  },
31
32
  "engines": {
32
- "node": ">=8.0.0"
33
+ "node": ">=14.0.0"
33
34
  },
34
35
  "files": [
35
36
  "/npm-shrinkwrap.json",
@@ -48,12 +49,8 @@
48
49
  "postpack": "rm -f oclif.manifest.json",
49
50
  "prepack": "oclif manifest && oclif readme",
50
51
  "test": "nyc mocha --forbid-only \"test/**/*.test.js\"",
51
- "version": "oclif readme && git add README.md"
52
- },
53
- "csdxConfig": {
54
- "expiredCommands": {
55
- "cm:import": "csdx cm:stacks:import"
56
- }
52
+ "version": "oclif readme && git add README.md",
53
+ "clean": "rm -rf ./node_modules tsconfig.build.tsbuildinfo"
57
54
  },
58
55
  "main": "./src/commands/cm/stacks/import.js",
59
56
  "license": "MIT",
@@ -62,5 +59,14 @@
62
59
  "bin": "csdx",
63
60
  "repositoryPrefix": "<%- repo %>/blob/main/packages/contentstack-import/<%- commandPath %>"
64
61
  },
62
+ "csdxConfig": {
63
+ "expiredCommands": {
64
+ "cm:import": "csdx cm:stacks:import"
65
+ },
66
+ "shortCommandName": {
67
+ "cm:stacks:import": "IMPRT",
68
+ "cm:import": "O-IMPRT"
69
+ }
70
+ },
65
71
  "repository": "https://github.com/contentstack/cli"
66
72
  }
package/src/app.js CHANGED
@@ -11,7 +11,7 @@ const chalk = require('chalk');
11
11
  const util = require('./lib/util/index');
12
12
  const login = require('./lib/util/login');
13
13
  const { addlogs } = require('./lib/util/log');
14
- const { managementSDKClient } = require('@contentstack/cli-utilities');
14
+ const { managementSDKClient, isAuthenticated } = require('@contentstack/cli-utilities');
15
15
 
16
16
  exports.initial = (configData) => {
17
17
  return new Promise(async (resolve, reject) => {
@@ -48,7 +48,7 @@ exports.initial = (configData) => {
48
48
  })
49
49
  .catch((error) => {
50
50
  addlogs(config, `Failed to import contents ${util.formatError(error)}`, 'error');
51
- reject(e);
51
+ reject(error);
52
52
  process.exit(1);
53
53
  });
54
54
  } else {
@@ -58,7 +58,7 @@ exports.initial = (configData) => {
58
58
  };
59
59
 
60
60
  if (config) {
61
- if ((config.email && config.password) || config.auth_token) {
61
+ if ((config.email && config.password) || isAuthenticated()) {
62
62
  login(config).then(backupAndImportData(APIClient, stackAPIClient)).catch(reject);
63
63
  } else if (config.management_token) {
64
64
  await backupAndImportData(APIClient, stackAPIClient);
@@ -1,7 +1,7 @@
1
1
  const _ = require('lodash');
2
2
  const defaultConfig = require('../../../config/default');
3
- const { Command, flags } = require('@contentstack/cli-command');
4
- const { configHandler } = require('@contentstack/cli-utilities');
3
+ const { Command } = require('@contentstack/cli-command');
4
+ const { flags, printFlagDeprecation, isAuthenticated } = require('@contentstack/cli-utilities');
5
5
  const {
6
6
  configWithMToken,
7
7
  parameterWithMToken,
@@ -10,7 +10,6 @@ const {
10
10
  parametersWithAuthToken,
11
11
  withoutParametersWithAuthToken,
12
12
  } = require('../../../lib/util/import-flags');
13
- const { printFlagDeprecation } = require('@contentstack/cli-utilities');
14
13
 
15
14
  class ImportCommand extends Command {
16
15
  async run() {
@@ -22,7 +21,6 @@ class ImportCommand extends Command {
22
21
  const moduleName = importCommandFlags.module;
23
22
  const backupdir = importCommandFlags['backup-dir'];
24
23
  const alias = importCommandFlags['alias'] || importCommandFlags['management-token-alias'];
25
- let _authToken = configHandler.get('authtoken');
26
24
  importCommandFlags.branchName = importCommandFlags.branch;
27
25
  importCommandFlags.importWebhookStatus = importCommandFlags['import-webhook-status'];
28
26
  delete importCommandFlags.branch;
@@ -42,13 +40,12 @@ class ImportCommand extends Command {
42
40
  if (managementTokens) {
43
41
  let result;
44
42
 
45
- if ((extConfig && _authToken) || alias) {
43
+ if ((extConfig && isAuthenticated()) || alias) {
46
44
  result = configWithMToken(
47
45
  extConfig,
48
46
  managementTokens,
49
47
  moduleName,
50
48
  host,
51
- _authToken,
52
49
  backupdir,
53
50
  importCommandFlags,
54
51
  );
@@ -58,7 +55,6 @@ class ImportCommand extends Command {
58
55
  data,
59
56
  moduleName,
60
57
  host,
61
- _authToken,
62
58
  backupdir,
63
59
  importCommandFlags,
64
60
  );
@@ -67,7 +63,6 @@ class ImportCommand extends Command {
67
63
  managementTokens,
68
64
  moduleName,
69
65
  host,
70
- _authToken,
71
66
  backupdir,
72
67
  importCommandFlags,
73
68
  );
@@ -77,14 +72,13 @@ class ImportCommand extends Command {
77
72
  } else {
78
73
  console.log('management Token is not present please add managment token first');
79
74
  }
80
- } else if (_authToken) {
75
+ } else if (isAuthenticated()) {
81
76
  let result;
82
77
 
83
78
  if (extConfig) {
84
- result = configWithAuthToken(extConfig, _authToken, moduleName, host, backupdir, importCommandFlags);
79
+ result = configWithAuthToken(extConfig, moduleName, host, backupdir, importCommandFlags);
85
80
  } else if (targetStack && data) {
86
81
  result = parametersWithAuthToken(
87
- _authToken,
88
82
  targetStack,
89
83
  data,
90
84
  moduleName,
@@ -93,7 +87,7 @@ class ImportCommand extends Command {
93
87
  importCommandFlags,
94
88
  );
95
89
  } else {
96
- result = withoutParametersWithAuthToken(_authToken, moduleName, host, backupdir, importCommandFlags);
90
+ result = withoutParametersWithAuthToken(moduleName, host, backupdir, importCommandFlags);
97
91
  }
98
92
 
99
93
  result.then(resolve).catch(reject);
@@ -35,6 +35,11 @@ module.exports = {
35
35
  fileName: 'locales.json',
36
36
  requiredKeys: ['code', 'uid', 'name', 'fallback_locale'],
37
37
  },
38
+ masterLocale: {
39
+ dirName: 'locales',
40
+ fileName: 'master-locale.json',
41
+ requiredKeys: ['code', 'uid', 'name'],
42
+ },
38
43
  customRoles: {
39
44
  dirName: 'custom-roles',
40
45
  fileName: 'custom-roles.json',
@@ -11,6 +11,7 @@ let chalk = require('chalk');
11
11
  let mkdirp = require('mkdirp');
12
12
  let Promise = require('bluebird');
13
13
  let { isEmpty, merge, cloneDeep } = require('lodash');
14
+ const { cliux } = require('@contentstack/cli-utilities');
14
15
 
15
16
  let helper = require('../util/fs');
16
17
  let { addlogs } = require('../util/log');
@@ -23,6 +24,7 @@ module.exports = class ImportLanguages {
23
24
  langUidMapper = {};
24
25
  masterLanguage = config.master_locale;
25
26
  langConfig = config.modules.locales;
27
+ sourceMasterLangConfig = config.modules.masterLocale;
26
28
  reqConcurrency = config.concurrency || config.fetchConcurrency || 1;
27
29
 
28
30
  constructor(importConfig, stackAPIClient) {
@@ -37,9 +39,10 @@ module.exports = class ImportLanguages {
37
39
  let langMapperPath = path.resolve(this.config.data, 'mapper', 'languages');
38
40
  let langFolderPath = path.resolve(this.config.data, this.langConfig.dirName);
39
41
  let langFailsPath = path.resolve(this.config.data, 'mapper', 'languages', 'fails.json');
40
- let langSuccessPath = path.resolve(this.config.data, 'mapper', 'languages', 'success.json');
41
42
  let langUidMapperPath = path.resolve(this.config.data, 'mapper', 'languages', 'uid-mapper.json');
43
+ self.langSuccessPath = path.resolve(this.config.data, 'mapper', 'languages', 'success.json');
42
44
  self.languages = helper.readFileSync(path.resolve(langFolderPath, this.langConfig.fileName));
45
+ self.sourceMasterLanguages = helper.readFileSync(path.resolve(langFolderPath, this.sourceMasterLangConfig.fileName));
43
46
 
44
47
  mkdirp.sync(langMapperPath);
45
48
 
@@ -48,11 +51,22 @@ module.exports = class ImportLanguages {
48
51
  self.langUidMapper = self.langUidMapper || {};
49
52
  }
50
53
 
51
- return new Promise(function (resolve, reject) {
54
+ return new Promise(async function (resolve, reject) {
52
55
  if (self.languages === undefined || isEmpty(self.languages)) {
53
56
  addlogs(self.config, chalk.white('No Languages Found'), 'success');
54
57
  return resolve({ empty: true });
55
58
  }
59
+
60
+ let sourceMasterLangDetails = self.sourceMasterLanguages && Object.values(self.sourceMasterLanguages);
61
+ if (sourceMasterLangDetails &&
62
+ sourceMasterLangDetails[0] &&
63
+ sourceMasterLangDetails[0]["code"] &&
64
+ self.masterLanguage["code"] === sourceMasterLangDetails[0]["code"]) {
65
+ await self.checkAndUpdateMasterLocaleName(sourceMasterLangDetails).catch((error) => {
66
+ addlogs(self.config, formatError(error), 'warn');
67
+ })
68
+ }
69
+
56
70
  let langUids = Object.keys(self.languages);
57
71
  return Promise.map(
58
72
  langUids,
@@ -98,7 +112,7 @@ module.exports = class ImportLanguages {
98
112
  self
99
113
  .updateLocales(langUids)
100
114
  .then(() => {
101
- helper.writeFileSync(langSuccessPath, self.success);
115
+ helper.writeFileSync(self.langSuccessPath, self.success);
102
116
  addlogs(self.config, chalk.green('Languages have been imported successfully!'), 'success');
103
117
  resolve();
104
118
  })
@@ -142,4 +156,58 @@ module.exports = class ImportLanguages {
142
156
  });
143
157
  });
144
158
  }
159
+
160
+ checkAndUpdateMasterLocaleName(sourceMasterLangDetails) {
161
+ let self = this;
162
+ return new Promise(async function (resolve, reject) {
163
+ let masterLangDetails = await self.stackAPIClient.locale(self.masterLanguage["code"]).fetch()
164
+ .catch((error) => {
165
+ addlogs(self.config, formatError(error), 'warn');
166
+ })
167
+ if (masterLangDetails &&
168
+ masterLangDetails["name"] &&
169
+ sourceMasterLangDetails[0]["name"] &&
170
+ masterLangDetails["name"].toString().toUpperCase() !== sourceMasterLangDetails[0]["name"].toString().toUpperCase()
171
+ ) {
172
+ cliux.print(
173
+ 'WARNING!!! The master language name for the source and destination is different.',
174
+ { color: 'yellow' },
175
+ );
176
+ cliux.print(
177
+ `Old Master language name: ${masterLangDetails["name"]}`,
178
+ { color: 'red' },
179
+ );
180
+ cliux.print(
181
+ `New Master language name: ${sourceMasterLangDetails[0]["name"]}`,
182
+ { color: 'green' },
183
+ );
184
+ let confirm = await cliux.inquire({
185
+ type: 'confirm',
186
+ message: 'Are you sure you want to update name of master language?',
187
+ name: 'confirmation',
188
+ })
189
+
190
+ if (confirm) {
191
+ let languid = sourceMasterLangDetails[0] && sourceMasterLangDetails[0]["uid"];
192
+ let lang = self.sourceMasterLanguages[languid];
193
+ if (!lang) return reject('Locale not found.!');
194
+ const langObj = self.stackAPIClient.locale(lang.code);
195
+ Object.assign(langObj, { name: lang.name });
196
+ langObj.update()
197
+ .then(() => {
198
+ helper.writeFileSync(self.langSuccessPath, self.success);
199
+ addlogs(self.config, chalk.green('Master Languages name have been updated successfully!'), 'success');
200
+ resolve();
201
+ })
202
+ .catch(function (error) {
203
+ reject(error);
204
+ });
205
+ } else {
206
+ resolve();
207
+ }
208
+ } else {
209
+ resolve();
210
+ }
211
+ });
212
+ }
145
213
  };
@@ -9,7 +9,7 @@ const path = require('path');
9
9
  const chalk = require('chalk');
10
10
  const mkdirp = require('mkdirp');
11
11
  const contentstack = require('@contentstack/management');
12
- const { cliux, HttpClient, NodeCrypto, managementSDKClient } = require('@contentstack/cli-utilities');
12
+ const { cliux, HttpClient, NodeCrypto, managementSDKClient, configHandler, isAuthenticated } = require('@contentstack/cli-utilities');
13
13
 
14
14
  const { formatError } = require('../util');
15
15
  let config = require('../../config/default');
@@ -35,8 +35,6 @@ module.exports = class ImportMarketplaceApps {
35
35
  }
36
36
 
37
37
  async start() {
38
- this.developerHubBaseUrl = this.config.developerHubBaseUrl || (await getDeveloperHubUrl(this.config));
39
- this.client = contentstack.client({ authtoken: this.config.auth_token, endpoint: this.developerHubBaseUrl });
40
38
  this.mapperDirPath = path.resolve(this.config.data, 'mapper', 'marketplace_apps');
41
39
  this.uidMapperPath = path.join(this.mapperDirPath, 'uid-mapping.json');
42
40
  this.marketplaceAppFolderPath = path.resolve(this.config.data, this.marketplaceAppConfig.dirName);
@@ -46,7 +44,7 @@ module.exports = class ImportMarketplaceApps {
46
44
 
47
45
  if (_.isEmpty(this.marketplaceApps)) {
48
46
  return Promise.resolve();
49
- } else if (!this.config.auth_token) {
47
+ } else if (!isAuthenticated()) {
50
48
  cliux.print(
51
49
  '\nWARNING!!! To import Marketplace apps, you must be logged in. Please check csdx auth:login --help to log in\n',
52
50
  { color: 'yellow' },
@@ -54,11 +52,14 @@ module.exports = class ImportMarketplaceApps {
54
52
  return Promise.resolve();
55
53
  }
56
54
 
55
+ this.developerHubBaseUrl = this.config.developerHubBaseUrl || (await getDeveloperHubUrl(this.config));
56
+ this.client = contentstack.client({ authtoken: configHandler.get('authtoken'), endpoint: this.developerHubBaseUrl });
57
+
57
58
  await this.getOrgUid();
58
59
 
59
60
  this.httpClient = new HttpClient({
60
61
  headers: {
61
- authtoken: this.config.auth_token,
62
+ authtoken: configHandler.get('authtoken'),
62
63
  organization_uid: this.config.org_uid,
63
64
  },
64
65
  });
@@ -71,7 +72,7 @@ module.exports = class ImportMarketplaceApps {
71
72
  }
72
73
 
73
74
  async getOrgUid() {
74
- if (this.config.auth_token) {
75
+ if (isAuthenticated()) {
75
76
  const tempAPIClient = await managementSDKClient({ host: this.config.host });
76
77
  const tempStackData = await tempAPIClient
77
78
  .stack({ api_key: this.config.target_stack })
@@ -210,18 +211,14 @@ module.exports = class ImportMarketplaceApps {
210
211
 
211
212
  for (let app of privateApps) {
212
213
  // NOTE keys can be passed to install new app in the developer hub
213
- app.manifest = _.pick(app.manifest, [
214
- 'uid',
215
- 'name',
216
- 'description',
217
- 'icon',
218
- 'target_type',
219
- 'ui_location',
220
- 'webhook',
221
- 'oauth',
222
- ]);
214
+ app.manifest = _.pick(app.manifest, ['uid', 'name', 'description', 'icon', 'target_type', 'webhook', 'oauth']);
223
215
  this.appOrginalName = app.manifest.name;
224
- await this.createPrivateApps(app.manifest);
216
+ await this.createPrivateApps({
217
+ oauth: app.oauth,
218
+ webhook: app.webhook,
219
+ ui_location: app.ui_location,
220
+ ...app.manifest,
221
+ });
225
222
  }
226
223
 
227
224
  this.appOrginalName = undefined;
@@ -264,9 +261,9 @@ module.exports = class ImportMarketplaceApps {
264
261
  let locations = app.ui_location && app.ui_location.locations;
265
262
 
266
263
  if (!uidCleaned && !_.isEmpty(locations)) {
267
- app.ui_location.locations = this.uodateManifestUILocations(locations, 'uid');
264
+ app.ui_location.locations = this.updateManifestUILocations(locations, 'uid');
268
265
  } else if (uidCleaned && !_.isEmpty(locations)) {
269
- app.ui_location.locations = this.uodateManifestUILocations(locations, 'name', appSuffix);
266
+ app.ui_location.locations = this.updateManifestUILocations(locations, 'name', appSuffix);
270
267
  }
271
268
 
272
269
  if (app.name > 20) {
@@ -328,7 +325,7 @@ module.exports = class ImportMarketplaceApps {
328
325
  return this.createPrivateApps(app, true, appSuffix + 1);
329
326
  }
330
327
 
331
- uodateManifestUILocations(locations, type = 'uid', appSuffix = 1) {
328
+ updateManifestUILocations(locations, type = 'uid', appSuffix = 1) {
332
329
  switch (type) {
333
330
  case 'uid':
334
331
  return _.map(locations, (location) => {
@@ -389,7 +386,10 @@ module.exports = class ImportMarketplaceApps {
389
386
  .catch((error) => error);
390
387
 
391
388
  if (installation.installation_uid) {
392
- log(this.config, `${app.manifest.name} app installed successfully.!`, 'success');
389
+ let appName = (this.appNameMapping[app.manifest.name]) ?
390
+ this.appNameMapping[app.manifest.name] :
391
+ app.manifest.name ;
392
+ log(this.config, `${appName} app installed successfully.!`, 'success');
393
393
  await this.makeRedirectUrlCall(installation, app.manifest.name);
394
394
  this.installationUidMapping[app.uid] = installation.installation_uid;
395
395
  updateParam = { manifest: app.manifest, ...installation, configuration, server_configuration };
@@ -118,3 +118,7 @@ exports.readdirSync = function (dirPath) {
118
118
  return [];
119
119
  }
120
120
  };
121
+
122
+ exports.fileExistsSync = function (path) {
123
+ return fs.existsSync(path);
124
+ };
@@ -14,7 +14,6 @@ exports.configWithMToken = function (
14
14
  managementTokens,
15
15
  moduleName,
16
16
  host,
17
- _authToken,
18
17
  backupdir,
19
18
  importCommandFlags,
20
19
  ) {
@@ -40,7 +39,6 @@ exports.configWithMToken = function (
40
39
  defaultConfig.useBackedupDir = backupdir;
41
40
  }
42
41
 
43
- defaultConfig.auth_token = _authToken;
44
42
  defaultConfig = _.merge(defaultConfig, externalConfig);
45
43
 
46
44
  if(!defaultConfig.data) {
@@ -61,14 +59,12 @@ exports.parameterWithMToken = function (
61
59
  data,
62
60
  moduleName,
63
61
  host,
64
- _authToken,
65
62
  backupdir,
66
63
  importCommandFlags,
67
64
  ) {
68
65
  return new Promise(async function (resolve, reject) {
69
66
  defaultConfig.management_token = managementTokens.token;
70
67
  defaultConfig.target_stack = managementTokens.apiKey;
71
- defaultConfig.auth_token = _authToken;
72
68
  defaultConfig.branchName = importCommandFlags.branchName;
73
69
  defaultConfig.importWebhookStatus = importCommandFlags.importWebhookStatus;
74
70
  if (moduleName && moduleName !== undefined) {
@@ -88,7 +84,6 @@ exports.withoutParameterMToken = async (
88
84
  managementTokens,
89
85
  moduleName,
90
86
  host,
91
- _authToken,
92
87
  backupdir,
93
88
  importCommandFlags,
94
89
  ) => {
@@ -96,7 +91,6 @@ exports.withoutParameterMToken = async (
96
91
  const exporteddata = await cliux.prompt(message.promptMessageList.promptPathStoredData);
97
92
  defaultConfig.management_token = managementTokens.token;
98
93
  defaultConfig.target_stack = managementTokens.apiKey;
99
- defaultConfig.auth_token = _authToken;
100
94
  defaultConfig.branchName = importCommandFlags.branchName;
101
95
  defaultConfig.importWebhookStatus = importCommandFlags.importWebhookStatus;
102
96
  if (moduleName && moduleName !== undefined) {
@@ -111,10 +105,9 @@ exports.withoutParameterMToken = async (
111
105
  });
112
106
  };
113
107
 
114
- exports.configWithAuthToken = function (config, _authToken, moduleName, host, backupdir, importCommandFlags) {
108
+ exports.configWithAuthToken = function (config, moduleName, host, backupdir, importCommandFlags) {
115
109
  return new Promise(async function (resolve, reject) {
116
110
  let externalConfig = require(config);
117
- defaultConfig.auth_token = _authToken;
118
111
  defaultConfig.branchName = importCommandFlags.branchName;
119
112
  defaultConfig.importWebhookStatus = importCommandFlags.importWebhookStatus;
120
113
  if (moduleName && moduleName !== undefined) {
@@ -140,7 +133,6 @@ exports.configWithAuthToken = function (config, _authToken, moduleName, host, ba
140
133
  };
141
134
 
142
135
  exports.parametersWithAuthToken = function (
143
- _authToken,
144
136
  targetStack,
145
137
  data,
146
138
  moduleName,
@@ -149,7 +141,6 @@ exports.parametersWithAuthToken = function (
149
141
  importCommandFlags,
150
142
  ) {
151
143
  return new Promise(async function (resolve, reject) {
152
- defaultConfig.auth_token = _authToken;
153
144
  defaultConfig.target_stack = targetStack;
154
145
  defaultConfig.branchName = importCommandFlags.branchName;
155
146
  defaultConfig.importWebhookStatus = importCommandFlags.importWebhookStatus;
@@ -168,11 +159,10 @@ exports.parametersWithAuthToken = function (
168
159
  });
169
160
  };
170
161
 
171
- exports.withoutParametersWithAuthToken = async (_authToken, moduleName, host, backupdir, importCommandFlags) => {
162
+ exports.withoutParametersWithAuthToken = async (moduleName, host, backupdir, importCommandFlags) => {
172
163
  return new Promise(async function (resolve, reject) {
173
164
  const stackUid = await cliux.prompt(message.promptMessageList.promptTargetStack);
174
165
  const exporteddata = await cliux.prompt(message.promptMessageList.promptPathStoredData);
175
- defaultConfig.auth_token = _authToken;
176
166
  defaultConfig.target_stack = stackUid;
177
167
  defaultConfig.data = exporteddata;
178
168
  defaultConfig.branchName = importCommandFlags.branchName;
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  const _ = require('lodash');
9
- const { HttpClient, managementSDKClient } = require('@contentstack/cli-utilities');
9
+ const { HttpClient, managementSDKClient, isAuthenticated } = require('@contentstack/cli-utilities');
10
10
  const fs = require('./fs');
11
11
  const path = require('path');
12
12
  const chalk = require('chalk');
@@ -33,7 +33,7 @@ exports.validateConfig = (importConfig) => {
33
33
  !importConfig.password &&
34
34
  !importConfig.management_token &&
35
35
  importConfig.target_stack &&
36
- !importConfig.auth_token
36
+ !isAuthenticated()
37
37
  ) {
38
38
  addlogs(importConfig, chalk.red('Kindly provide management_token or email and password'), 'error');
39
39
  return 'error';
@@ -8,7 +8,7 @@
8
8
  const chalk = require('chalk');
9
9
 
10
10
  const { addlogs } = require('../util/log');
11
- const { managementSDKClient } = require('@contentstack/cli-utilities');
11
+ const { managementSDKClient, isAuthenticated } = require('@contentstack/cli-utilities');
12
12
 
13
13
  module.exports = (config) => {
14
14
  return new Promise((resolve, reject) => {
@@ -21,10 +21,9 @@ module.exports = (config) => {
21
21
  .then((response) => {
22
22
  // eslint-disable-next-line no-console
23
23
  console.log(chalk.green('Contentstack account authenticated successfully!'));
24
- config.authtoken = response.user.authtoken;
25
24
  config.headers = {
26
25
  api_key: config.target_stack,
27
- authtoken: config.authtoken,
26
+ authtoken: response.user.authtoken,
28
27
  'X-User-Agent': 'contentstack-import/v',
29
28
  };
30
29
  return resolve(config);
@@ -32,7 +31,7 @@ module.exports = (config) => {
32
31
  .catch(reject);
33
32
  } else if (config.management_token) {
34
33
  return resolve();
35
- } else if (config.auth_token) {
34
+ } else if (isAuthenticated()) {
36
35
  const stackAPIClient = APIClient.stack({
37
36
  api_key: config.target_stack,
38
37
  management_token: config.management_token,
@@ -219,7 +219,9 @@ module.exports = function (data, mappedAssetUids, mappedAssetUrls, assetUidMappe
219
219
  [data.entry.uid]: matchedUids,
220
220
  };
221
221
  }
222
- helper.writeFile(path.join(assetUidMapperPath, 'matched-asset-uids.json'));
222
+ if (!helper.fileExistsSync(path.join(assetUidMapperPath, 'matched-asset-uids.json'))) {
223
+ helper.writeFile(path.join(assetUidMapperPath, 'matched-asset-uids.json'));
224
+ }
223
225
  }
224
226
 
225
227
  if (unmatchedUids.length) {