@contentstack/cli-cm-import 1.10.0 → 1.10.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
@@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import
47
47
  $ csdx COMMAND
48
48
  running command...
49
49
  $ csdx (--version)
50
- @contentstack/cli-cm-import/1.10.0 linux-x64 node-v18.18.2
50
+ @contentstack/cli-cm-import/1.10.1 linux-x64 node-v18.18.2
51
51
  $ csdx --help [COMMAND]
52
52
  USAGE
53
53
  $ csdx COMMAND
@@ -4,6 +4,7 @@ const tslib_1 = require("tslib");
4
4
  const node_path_1 = tslib_1.__importDefault(require("node:path"));
5
5
  const cli_command_1 = require("@contentstack/cli-command");
6
6
  const cli_utilities_1 = require("@contentstack/cli-utilities");
7
+ const log_1 = require("../../../utils/log");
7
8
  const import_1 = require("../../../import");
8
9
  const utils_1 = require("../../../utils");
9
10
  class ImportCommand extends cli_command_1.Command {
@@ -25,6 +26,7 @@ class ImportCommand extends cli_command_1.Command {
25
26
  (0, utils_1.log)(importConfig, `The log has been stored at '${node_path_1.default.join(importConfig.backupDir, 'logs', 'import')}'`, 'success');
26
27
  }
27
28
  catch (error) {
29
+ (0, log_1.trace)(error, 'error', true);
28
30
  (0, utils_1.log)({ data: backupDir }, `Failed to import stack content - ${(0, utils_1.formatError)(error)}`, 'error');
29
31
  (0, utils_1.log)({ data: backupDir }, `The log has been stored at ${{ data: backupDir } ? node_path_1.default.join(backupDir || __dirname, 'logs', 'import') : node_path_1.default.join(__dirname, 'logs')}`, 'info');
30
32
  }
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const cli_utilities_1 = require("@contentstack/cli-utilities");
5
- const utils_1 = require("../utils");
6
5
  const modules_1 = tslib_1.__importDefault(require("./modules"));
7
6
  const modules_js_1 = tslib_1.__importDefault(require("./modules-js"));
7
+ const utils_1 = require("../utils");
8
8
  class ModuleImporter {
9
9
  constructor(managementAPIClient, importConfig) {
10
10
  this.managementAPIClient = managementAPIClient;
@@ -43,6 +43,8 @@ class ModuleImporter {
43
43
  // To support the old config
44
44
  this.importConfig.data = backupDir;
45
45
  }
46
+ // NOTE init log
47
+ (0, utils_1.initLogger)(this.importConfig);
46
48
  await (0, utils_1.sanitizeStack)(this.stackAPIClient);
47
49
  return this.import();
48
50
  }
@@ -58,7 +60,7 @@ class ModuleImporter {
58
60
  (0, utils_1.log)(this.importConfig, `Starting import of ${moduleName} module`, 'info');
59
61
  // import the modules by name
60
62
  // calls the module runner which inturn calls the module itself
61
- // Todo: Implement a mechanism to determine whether module is new or old
63
+ // NOTE: Implement a mechanism to determine whether module is new or old
62
64
  if (this.importConfig.contentVersion === 2) {
63
65
  return (0, modules_1.default)({
64
66
  stackAPIClient: this.stackAPIClient,
@@ -14,6 +14,7 @@ const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
14
14
  const toLower_1 = tslib_1.__importDefault(require("lodash/toLower"));
15
15
  const cli_utilities_1 = require("@contentstack/cli-utilities");
16
16
  const base_class_1 = tslib_1.__importDefault(require("./base-class"));
17
+ const log_1 = require("../../utils/log");
17
18
  const interactive_1 = require("../../utils/interactive");
18
19
  const utils_1 = require("../../utils");
19
20
  class ImportMarketplaceApps extends base_class_1.default {
@@ -54,7 +55,7 @@ class ImportMarketplaceApps extends base_class_1.default {
54
55
  this.developerHubBaseUrl = this.importConfig.developerHubBaseUrl || (await (0, utils_1.getDeveloperHubUrl)(this.importConfig));
55
56
  this.sdkClient = await (0, cli_utilities_1.managementSDKClient)({ endpoint: this.developerHubBaseUrl });
56
57
  this.appSdkAxiosInstance = await (0, cli_utilities_1.managementSDKClient)({
57
- host: this.developerHubBaseUrl.split('://').pop()
58
+ host: this.developerHubBaseUrl.split('://').pop(),
58
59
  });
59
60
  this.importConfig.org_uid = await (0, utils_1.getOrgUid)(this.importConfig);
60
61
  await this.setHttpClient();
@@ -223,6 +224,7 @@ class ImportMarketplaceApps extends base_class_1.default {
223
224
  return this.createPrivateApps(updatedApp, true, appSuffix + 1);
224
225
  }
225
226
  else {
227
+ (0, log_1.trace)(response, 'error', true);
226
228
  (0, utils_1.log)(this.importConfig, (0, utils_1.formatError)(message), 'error');
227
229
  if (this.importConfig.forceStopMarketplaceAppsPrompt)
228
230
  return Promise.resolve();
@@ -308,13 +310,17 @@ class ImportMarketplaceApps extends base_class_1.default {
308
310
  })
309
311
  .then(({ data }) => {
310
312
  if (data === null || data === void 0 ? void 0 : data.message) {
313
+ (0, log_1.trace)(data, 'error', true);
311
314
  (0, utils_1.log)(this.importConfig, (0, utils_1.formatError)(data.message), 'success');
312
315
  }
313
316
  else {
314
317
  (0, utils_1.log)(this.importConfig, `${app.manifest.name} app config updated successfully.!`, 'success');
315
318
  }
316
319
  })
317
- .catch((error) => (0, utils_1.log)(this.importConfig, (0, utils_1.formatError)(error), 'error'));
320
+ .catch((error) => {
321
+ (0, log_1.trace)(error, 'error', true);
322
+ (0, utils_1.log)(this.importConfig, (0, utils_1.formatError)(error), 'error');
323
+ });
318
324
  }
319
325
  }
320
326
  exports.default = ImportMarketplaceApps;
@@ -9,8 +9,9 @@ const path = require('path');
9
9
  const chalk = require('chalk');
10
10
  const mkdirp = require('mkdirp');
11
11
  const { cliux, HttpClient, NodeCrypto, managementSDKClient, isAuthenticated, HttpClientDecorator, OauthDecorator, } = require('@contentstack/cli-utilities');
12
- const { log, fileHelper: { readFileSync, writeFile }, formatError, } = require('../../utils');
13
- let { default: config } = require('../../config');
12
+ const { log, formatError, fileHelper: { readFileSync, writeFile }, } = require('../../utils');
13
+ const { trace } = require('../../utils/log');
14
+ const { default: config } = require('../../config');
14
15
  const { getDeveloperHubUrl, getAllStackSpecificApps } = require('../../utils/marketplace-app-helper');
15
16
  module.exports = class ImportMarketplaceApps {
16
17
  constructor(importConfig, stackAPIClient) {
@@ -306,6 +307,7 @@ module.exports = class ImportMarketplaceApps {
306
307
  updateParam = Object.assign(Object.assign({ manifest: app.manifest }, installation), { configuration, server_configuration });
307
308
  }
308
309
  else if (installation.message) {
310
+ trace(installation, 'error', true);
309
311
  log(this.config, formatError(installation.message), 'success');
310
312
  await this.confirmToCloseProcess(installation);
311
313
  }
@@ -329,6 +331,7 @@ module.exports = class ImportMarketplaceApps {
329
331
  .get(response.redirect_url)
330
332
  .then(async ({ response }) => {
331
333
  if (_.includes([501, 403], response.status)) {
334
+ trace(response, 'error', true); // NOTE Log complete stack and hide on UI
332
335
  log(this.config, `${appName} - ${response.statusText}, OAuth api call failed.!`, 'error');
333
336
  log(this.config, formatError(response), 'error');
334
337
  await this.confirmToCloseProcess({ message: response.data });
@@ -338,6 +341,7 @@ module.exports = class ImportMarketplaceApps {
338
341
  }
339
342
  })
340
343
  .catch((error) => {
344
+ trace(error, 'error', true);
341
345
  if (_.includes([501, 403], error.status)) {
342
346
  log(this.config, formatError(error), 'error');
343
347
  }
@@ -403,13 +407,17 @@ module.exports = class ImportMarketplaceApps {
403
407
  })
404
408
  .then(({ data }) => {
405
409
  if (data.message) {
410
+ trace(data, 'error', true);
406
411
  log(this.config, formatError(data.message), 'success');
407
412
  }
408
413
  else {
409
414
  log(this.config, `${app.manifest.name} app config updated successfully.!`, 'success');
410
415
  }
411
416
  })
412
- .catch((error) => log(this.config, formatError(error), 'error'));
417
+ .catch((error) => {
418
+ trace(data, 'error', true);
419
+ log(this.config, formatError(error), 'error');
420
+ });
413
421
  }
414
422
  validateAppName(name) {
415
423
  if (name.length < 3 || name.length > 20) {
@@ -1,2 +1,2 @@
1
1
  import { ImportConfig } from '../types';
2
- export default function setupBackupDir(importConfig: ImportConfig): Promise<string>;
2
+ export default function backupHandler(importConfig: ImportConfig): Promise<string>;
@@ -5,44 +5,45 @@ const path = tslib_1.__importStar(require("path"));
5
5
  const fs_extra_1 = require("fs-extra");
6
6
  const cli_utilities_1 = require("@contentstack/cli-utilities");
7
7
  const index_1 = require("./index");
8
- function setupBackupDir(importConfig) {
9
- return new Promise(async (resolve, reject) => {
10
- if (importConfig.hasOwnProperty('useBackedupDir')) {
11
- return resolve(importConfig.useBackedupDir);
12
- }
13
- const subDir = isSubDirectory(importConfig);
14
- let backupDirPath;
15
- if (subDir) {
16
- backupDirPath = path.resolve(importConfig.contentDir, '..', '_backup_' + Math.floor(Math.random() * 1000));
17
- if (importConfig.createBackupDir) {
18
- cli_utilities_1.cliux.print(`Warning!!! Provided backup directory path is a sub directory of the content directory, Cannot copy to a sub directory. Hence new backup directory created - ${backupDirPath}`, {
19
- color: 'yellow',
20
- });
21
- }
8
+ async function backupHandler(importConfig) {
9
+ if (importConfig.hasOwnProperty('useBackedupDir')) {
10
+ return importConfig.useBackedupDir;
11
+ }
12
+ let backupDirPath;
13
+ const subDir = isSubDirectory(importConfig);
14
+ if (subDir) {
15
+ backupDirPath = path.resolve(importConfig.contentDir, '..', '_backup_' + Math.floor(Math.random() * 1000));
16
+ if (importConfig.createBackupDir) {
17
+ cli_utilities_1.cliux.print(`Warning!!! Provided backup directory path is a sub directory of the content directory, Cannot copy to a sub directory. Hence new backup directory created - ${backupDirPath}`, {
18
+ color: 'yellow',
19
+ });
22
20
  }
23
- else {
24
- //NOTE: If the backup folder's directory is provided, create it at that location; otherwise, the default path (working directory).
25
- backupDirPath = path.join(process.cwd(), '_backup_' + Math.floor(Math.random() * 1000));
26
- if (importConfig.createBackupDir) {
27
- if (index_1.fileHelper.fileExistsSync(importConfig.createBackupDir)) {
28
- index_1.fileHelper.removeDirSync(importConfig.createBackupDir);
29
- }
30
- index_1.fileHelper.makeDirectory(importConfig.createBackupDir);
31
- backupDirPath = importConfig.createBackupDir;
21
+ }
22
+ else {
23
+ // NOTE: If the backup folder's directory is provided, create it at that location; otherwise, the default path (working directory).
24
+ backupDirPath = path.join(process.cwd(), '_backup_' + Math.floor(Math.random() * 1000));
25
+ if (importConfig.createBackupDir) {
26
+ if (index_1.fileHelper.fileExistsSync(importConfig.createBackupDir)) {
27
+ index_1.fileHelper.removeDirSync(importConfig.createBackupDir);
32
28
  }
29
+ index_1.fileHelper.makeDirectory(importConfig.createBackupDir);
30
+ backupDirPath = importConfig.createBackupDir;
33
31
  }
34
- if (backupDirPath) {
35
- cli_utilities_1.cliux.print('Copying content to the backup directory...');
32
+ }
33
+ if (backupDirPath) {
34
+ cli_utilities_1.cliux.print('Copying content to the backup directory...');
35
+ return new Promise((resolve, reject) => {
36
36
  return (0, fs_extra_1.copy)(importConfig.contentDir, backupDirPath, (error) => {
37
37
  if (error) {
38
+ (0, index_1.trace)(error, 'error', true);
38
39
  return reject(error);
39
40
  }
40
- return resolve(backupDirPath);
41
+ resolve(backupDirPath);
41
42
  });
42
- }
43
- });
43
+ });
44
+ }
44
45
  }
45
- exports.default = setupBackupDir;
46
+ exports.default = backupHandler;
46
47
  /**
47
48
  * Check whether provided backup directory path is sub directory or not
48
49
  * @param importConfig
@@ -53,8 +54,8 @@ function isSubDirectory(importConfig) {
53
54
  const child = importConfig.createBackupDir ? importConfig.createBackupDir : process.cwd();
54
55
  const relative = path.relative(parent, child);
55
56
  if (relative) {
56
- return relative && !relative.startsWith('..') && !path.isAbsolute(relative);
57
+ return !relative.startsWith('..') && !path.isAbsolute(relative);
57
58
  }
58
- //true if both parent and child have same path
59
+ // true if both parent and child have same path
59
60
  return true;
60
61
  }
@@ -10,3 +10,4 @@ export { schemaTemplate, suppressSchemaReference, removeReferenceFields } from '
10
10
  export { lookupExtension } from './extension-helper';
11
11
  export { lookupEntries, removeUidsFromJsonRteFields, removeEntryRefsFromJSONRTE, restoreJsonRteEntryRefs, } from './entries-helper';
12
12
  export * from './common-helper';
13
+ export * from './log';
@@ -40,3 +40,4 @@ Object.defineProperty(exports, "removeUidsFromJsonRteFields", { enumerable: true
40
40
  Object.defineProperty(exports, "removeEntryRefsFromJSONRTE", { enumerable: true, get: function () { return entries_helper_1.removeEntryRefsFromJSONRTE; } });
41
41
  Object.defineProperty(exports, "restoreJsonRteEntryRefs", { enumerable: true, get: function () { return entries_helper_1.restoreJsonRteEntryRefs; } });
42
42
  tslib_1.__exportStar(require("./common-helper"), exports);
43
+ tslib_1.__exportStar(require("./log"), exports);
@@ -0,0 +1,10 @@
1
+ import { LogEntry } from 'winston/index';
2
+ import { Logger } from '@contentstack/cli-utilities';
3
+ import { LogsType, MessageType } from '@contentstack/cli-utilities/lib/logger';
4
+ import { ImportConfig } from '../types';
5
+ export declare function isImportConfig(config: ImportConfig | MessageType): config is ImportConfig;
6
+ export declare function log(entry: LogEntry): void;
7
+ export declare function log(error: MessageType, logType: LogsType): void;
8
+ export declare function log(error: MessageType, logType: 'error', hidden: boolean): void;
9
+ export declare function initLogger(config?: ImportConfig | undefined): Logger;
10
+ export declare const trace: typeof log;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.trace = exports.initLogger = exports.log = exports.isImportConfig = void 0;
4
+ const path_1 = require("path");
5
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
6
+ let logger;
7
+ function isImportConfig(config) {
8
+ return config.data !== undefined && (config === null || config === void 0 ? void 0 : config.contentVersion) !== undefined;
9
+ }
10
+ exports.isImportConfig = isImportConfig;
11
+ function log(entryOrMessage, logType, hidden) {
12
+ logger = initLogger();
13
+ if (logType === 'error') {
14
+ logger.log(entryOrMessage, logType, hidden);
15
+ }
16
+ else {
17
+ logger.log(entryOrMessage, logType);
18
+ }
19
+ }
20
+ exports.log = log;
21
+ function initLogger(config) {
22
+ var _a;
23
+ if (!logger) {
24
+ const basePath = (0, path_1.join)((_a = config === null || config === void 0 ? void 0 : config.data) !== null && _a !== void 0 ? _a : process.cwd(), 'logs', 'import');
25
+ logger = new cli_utilities_1.Logger(Object.assign(config !== null && config !== void 0 ? config : {}, { basePath }));
26
+ }
27
+ return logger;
28
+ }
29
+ exports.initLogger = initLogger;
30
+ exports.trace = log;
@@ -9,7 +9,6 @@ exports.unlinkFileLogger = exports.log = void 0;
9
9
  const tslib_1 = require("tslib");
10
10
  const winston = tslib_1.__importStar(require("winston"));
11
11
  const path = tslib_1.__importStar(require("path"));
12
- const mkdirp_1 = tslib_1.__importDefault(require("mkdirp"));
13
12
  const slice = Array.prototype.slice;
14
13
  const ansiRegexPattern = [
15
14
  '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
@@ -55,9 +54,7 @@ let successTransport;
55
54
  let errorTransport;
56
55
  function init(_logPath) {
57
56
  if (!logger || !errorLogger) {
58
- var logsDir = path.resolve(_logPath, 'logs', 'import');
59
- // Create dir if doesn't already exist
60
- mkdirp_1.default.sync(logsDir);
57
+ const logsDir = path.resolve(_logPath, 'logs', 'import');
61
58
  successTransport = {
62
59
  filename: path.join(logsDir, 'success.log'),
63
60
  maxFiles: 20,
@@ -9,12 +9,13 @@ const includes_1 = tslib_1.__importDefault(require("lodash/includes"));
9
9
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
10
10
  const cli_utilities_1 = require("@contentstack/cli-utilities");
11
11
  const logger_1 = require("./logger");
12
- const interactive_1 = require("./interactive");
12
+ const log_1 = require("../utils/log");
13
13
  const utils_1 = require("../utils");
14
+ const interactive_1 = require("./interactive");
14
15
  const interactive_2 = require("../utils/interactive");
15
16
  const getAllStackSpecificApps = async (developerHubBaseUrl, httpClient, config) => {
16
17
  const appSdkAxiosInstance = await (0, cli_utilities_1.managementSDKClient)({
17
- host: developerHubBaseUrl.split('://').pop()
18
+ host: developerHubBaseUrl.split('://').pop(),
18
19
  });
19
20
  return await appSdkAxiosInstance.axiosInstance
20
21
  .get(`${developerHubBaseUrl}/installations?target_uids=${config.target_stack}`, {
@@ -23,7 +24,10 @@ const getAllStackSpecificApps = async (developerHubBaseUrl, httpClient, config)
23
24
  },
24
25
  })
25
26
  .then(({ data }) => data.data)
26
- .catch((error) => (0, logger_1.log)(config, `Failed to export marketplace-apps ${(0, utils_1.formatError)(error)}`, 'error'));
27
+ .catch((error) => {
28
+ (0, log_1.trace)(error, 'error', true);
29
+ (0, logger_1.log)(config, `Failed to export marketplace-apps ${(0, utils_1.formatError)(error)}`, 'error');
30
+ });
27
31
  };
28
32
  exports.getAllStackSpecificApps = getAllStackSpecificApps;
29
33
  const getDeveloperHubUrl = async (config) => {
@@ -41,6 +45,7 @@ const getOrgUid = async (config) => {
41
45
  .stack({ api_key: config.target_stack })
42
46
  .fetch()
43
47
  .catch((error) => {
48
+ (0, log_1.trace)(error, 'error', true);
44
49
  (0, logger_1.log)(config, (0, utils_1.formatError)(error), 'error');
45
50
  });
46
51
  return (tempStackData === null || tempStackData === void 0 ? void 0 : tempStackData.org_uid) || '';
@@ -92,6 +97,7 @@ const makeRedirectUrlCall = async (response, appName, config) => {
92
97
  .get(response.redirect_url)
93
98
  .then(async ({ response }) => {
94
99
  if ((0, includes_1.default)([501, 403], response.status)) {
100
+ (0, log_1.trace)(response, 'error', true);
95
101
  (0, logger_1.log)(config, `${appName} - ${response.statusText}, OAuth api call failed.!`, 'error');
96
102
  (0, logger_1.log)(config, (0, utils_1.formatError)(response), 'error');
97
103
  await (0, exports.confirmToCloseProcess)(response.data, config);
@@ -101,6 +107,7 @@ const makeRedirectUrlCall = async (response, appName, config) => {
101
107
  }
102
108
  })
103
109
  .catch((error) => {
110
+ (0, log_1.trace)(error, 'error', true);
104
111
  if ((0, includes_1.default)([501, 403], error.status)) {
105
112
  (0, logger_1.log)(config, (0, utils_1.formatError)(error), 'error');
106
113
  }
@@ -145,6 +152,9 @@ const updateAppConfig = async (client, config, app, payload) => {
145
152
  var _a;
146
153
  (0, logger_1.log)(config, `${(_a = app === null || app === void 0 ? void 0 : app.manifest) === null || _a === void 0 ? void 0 : _a.name} app config updated successfully.!`, 'success');
147
154
  })
148
- .catch((error) => (0, logger_1.log)(config, `Failed to update app config.${(0, utils_1.formatError)(error)}`, 'error'));
155
+ .catch((error) => {
156
+ (0, log_1.trace)(error, 'error', true);
157
+ (0, logger_1.log)(config, `Failed to update app config.${(0, utils_1.formatError)(error)}`, 'error');
158
+ });
149
159
  };
150
160
  exports.updateAppConfig = updateAppConfig;
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.10.0",
2
+ "version": "1.10.1",
3
3
  "commands": {
4
4
  "cm:stacks:import": {
5
5
  "id": "cm:stacks:import",
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-import",
3
3
  "description": "Contentstack CLI plugin to import content into stack",
4
- "version": "1.10.0",
4
+ "version": "1.10.1",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
8
- "@contentstack/cli-command": "~1.2.14",
9
- "@contentstack/cli-utilities": "~1.5.4",
10
- "@contentstack/management": "~1.10.2",
8
+ "@contentstack/cli-command": "~1.2.15",
9
+ "@contentstack/cli-utilities": "~1.5.5",
10
+ "@contentstack/management": "~1.11.0",
11
11
  "@oclif/core": "^2.9.3",
12
+ "axios": "^1.6.0",
12
13
  "big-json": "^3.2.0",
13
14
  "bluebird": "^3.7.2",
14
15
  "chalk": "^4.1.2",
@@ -96,4 +97,4 @@
96
97
  }
97
98
  },
98
99
  "repository": "https://github.com/contentstack/cli"
99
- }
100
+ }