@contentstack/cli-cm-import-setup 2.0.0-beta.1 → 2.0.0-beta.3

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) 2024 Contentstack
3
+ Copyright (c) 2026 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
@@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import-setup
47
47
  $ csdx COMMAND
48
48
  running command...
49
49
  $ csdx (--version)
50
- @contentstack/cli-cm-import-setup/2.0.0-beta.1 linux-x64 node-v22.21.1
50
+ @contentstack/cli-cm-import-setup/2.0.0-beta.3 linux-x64 node-v22.22.0
51
51
  $ csdx --help [COMMAND]
52
52
  USAGE
53
53
  $ csdx COMMAND
@@ -59,44 +59,6 @@ USAGE
59
59
 
60
60
  <!-- commands -->
61
61
  * [`csdx cm:stacks:import-setup [-k <value>] [-d <value>] [-a <value>] [--modules <value,value>]`](#csdx-cmstacksimport-setup--k-value--d-value--a-value---modules-valuevalue)
62
- * [`csdx cm:stacks:import-setup [-k <value>] [-d <value>] [-a <value>] [--modules <value,value>]`](#csdx-cmstacksimport-setup--k-value--d-value--a-value---modules-valuevalue)
63
-
64
- ## `csdx cm:stacks:import-setup [-k <value>] [-d <value>] [-a <value>] [--modules <value,value>]`
65
-
66
- Helps to generate mappers and backup folder for importing (overwriting) specific modules
67
-
68
- ```
69
- USAGE
70
- $ csdx cm:import-setup cm:stacks:import-setup [-k <value>] [-d <value>] [-a <value>] [--modules <value,value>]
71
-
72
- FLAGS
73
- -B, --branch=<value> The name of the branch where you want to import your content. If you don't mention the
74
- branch name, then by default the content will be imported to the main branch.
75
- -a, --alias=<value> The management token of the destination stack where you will import the content.
76
- -d, --data-dir=<value> The path or the location in your file system where the content, you intend to import, is
77
- stored. For example, -d "C:\Users\Name\Desktop\cli\content". If the export folder has
78
- branches involved, then the path should point till the particular branch. For example,
79
- “-d "C:\Users\Name\Desktop\cli\content\branch_name"
80
- -k, --stack-api-key=<value> API key of the target stack
81
- --branch-alias=<value> Specify the branch alias where you want to import your content. If not specified, the
82
- content is imported into the main branch by default.
83
- --module=<option>... [optional] Specify the modules/module to import into the target stack. currently options
84
- are global-fields, content-types, entries
85
- <options: global-fields|content-types|entries>
86
-
87
- DESCRIPTION
88
- Helps to generate mappers and backup folder for importing (overwriting) specific modules
89
-
90
- ALIASES
91
- $ csdx cm:import-setup
92
-
93
- EXAMPLES
94
- $ csdx cm:stacks:import-setup --stack-api-key <target_stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name>
95
-
96
- $ csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name>
97
-
98
- $ csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name> -b <branch_name>
99
- ```
100
62
 
101
63
  ## `csdx cm:stacks:import-setup [-k <value>] [-d <value>] [-a <value>] [--modules <value,value>]`
102
64
 
@@ -107,14 +69,14 @@ USAGE
107
69
  $ csdx cm:stacks:import-setup [-k <value>] [-d <value>] [-a <value>] [--modules <value,value>]
108
70
 
109
71
  FLAGS
110
- -B, --branch=<value> The name of the branch where you want to import your content. If you don't mention the
111
- branch name, then by default the content will be imported to the main branch.
112
72
  -a, --alias=<value> The management token of the destination stack where you will import the content.
113
73
  -d, --data-dir=<value> The path or the location in your file system where the content, you intend to import, is
114
74
  stored. For example, -d "C:\Users\Name\Desktop\cli\content". If the export folder has
115
75
  branches involved, then the path should point till the particular branch. For example,
116
76
  “-d "C:\Users\Name\Desktop\cli\content\branch_name"
117
77
  -k, --stack-api-key=<value> API key of the target stack
78
+ --branch=<value> The name of the branch where you want to import your content. If you don't mention the
79
+ branch name, then by default the content will be imported to the main branch.
118
80
  --branch-alias=<value> Specify the branch alias where you want to import your content. If not specified, the
119
81
  content is imported into the main branch by default.
120
82
  --module=<option>... [optional] Specify the modules/module to import into the target stack. currently options
@@ -124,15 +86,8 @@ FLAGS
124
86
  DESCRIPTION
125
87
  Helps to generate mappers and backup folder for importing (overwriting) specific modules
126
88
 
127
- ALIASES
128
- $ csdx cm:import-setup
129
-
130
89
  EXAMPLES
131
- $ csdx cm:stacks:import-setup --stack-api-key <target_stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name>
132
-
133
- $ csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name>
134
-
135
- $ csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name> -b <branch_name>
90
+ $ csdx cm:stacks:import-setup --stack-api-key <target_stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name> --branch <branch_name>
136
91
  ```
137
92
 
138
93
  _See code: [src/commands/cm/stacks/import-setup.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-import-setup/src/commands/cm/stacks/import-setup.ts)_
@@ -54,9 +54,7 @@ class ImportSetupCommand extends cli_command_1.Command {
54
54
  exports.default = ImportSetupCommand;
55
55
  ImportSetupCommand.description = cli_utilities_1.messageHandler.parse('Helps to generate mappers and backup folder for importing (overwriting) specific modules');
56
56
  ImportSetupCommand.examples = [
57
- `csdx cm:stacks:import-setup --stack-api-key <target_stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name>`,
58
- `csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name>`,
59
- `csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name> -b <branch_name>`,
57
+ `csdx cm:stacks:import-setup --stack-api-key <target_stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name> --branch <branch_name>`,
60
58
  ];
61
59
  ImportSetupCommand.flags = {
62
60
  'stack-api-key': cli_utilities_1.flags.string({
@@ -77,15 +75,13 @@ ImportSetupCommand.flags = {
77
75
  multiple: true,
78
76
  }),
79
77
  branch: cli_utilities_1.flags.string({
80
- char: 'B',
81
78
  description: "The name of the branch where you want to import your content. If you don't mention the branch name, then by default the content will be imported to the main branch.",
82
- parse: (0, cli_utilities_1.printFlagDeprecation)(['-B'], ['--branch']),
83
- exclusive: ['branch-alias']
79
+ exclusive: ['branch-alias'],
84
80
  }),
85
81
  'branch-alias': cli_utilities_1.flags.string({
86
- description: "Specify the branch alias where you want to import your content. If not specified, the content is imported into the main branch by default.",
82
+ description: 'Specify the branch alias where you want to import your content. If not specified, the content is imported into the main branch by default.',
87
83
  exclusive: ['branch'],
88
84
  }),
89
85
  };
90
- ImportSetupCommand.aliases = ['cm:import-setup'];
86
+ ImportSetupCommand.aliases = [];
91
87
  ImportSetupCommand.usage = 'cm:stacks:import-setup [-k <value>] [-d <value>] [-a <value>] [--modules <value,value>]';
@@ -1,14 +1,28 @@
1
1
  import { ImportConfig } from '../types';
2
- import { ContentstackClient } from '@contentstack/cli-utilities';
2
+ import { backupHandler as defaultBackupHandler, setupBranchConfig as defaultSetupBranchConfig } from '../utils';
3
+ import { ContentstackClient, log as defaultLog, handleAndLogError as defaultHandleAndLogError } from '@contentstack/cli-utilities';
4
+ /**
5
+ * Dependencies for ImportSetup - can be injected for testing
6
+ */
7
+ export interface ImportSetupDeps {
8
+ backupHandler?: typeof defaultBackupHandler;
9
+ setupBranchConfig?: typeof defaultSetupBranchConfig;
10
+ log?: typeof defaultLog;
11
+ handleAndLogError?: typeof defaultHandleAndLogError;
12
+ }
3
13
  export default class ImportSetup {
4
14
  protected config: ImportConfig;
5
- private managementAPIClient;
6
- private importConfig;
7
- private stackAPIClient;
15
+ private readonly managementAPIClient;
16
+ private readonly importConfig;
17
+ private readonly stackAPIClient;
8
18
  dependencyTree: {
9
19
  [key: string]: string[];
10
20
  };
11
- constructor(config: ImportConfig, managementAPIClient: ContentstackClient);
21
+ private readonly backupHandler;
22
+ private readonly setupBranchConfig;
23
+ private readonly log;
24
+ private readonly handleAndLogError;
25
+ constructor(config: ImportConfig, managementAPIClient: ContentstackClient, deps?: ImportSetupDeps);
12
26
  /**
13
27
  * Generate mapper logic
14
28
  * This method generates dependency tree based on the selected modules
@@ -26,7 +26,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  const utils_1 = require("../utils");
27
27
  const cli_utilities_1 = require("@contentstack/cli-utilities");
28
28
  class ImportSetup {
29
- constructor(config, managementAPIClient) {
29
+ constructor(config, managementAPIClient, deps = {}) {
30
+ var _a, _b, _c, _d;
30
31
  this.dependencyTree = {};
31
32
  this.config = config;
32
33
  this.managementAPIClient = managementAPIClient;
@@ -34,6 +35,11 @@ class ImportSetup {
34
35
  api_key: this.config.apiKey,
35
36
  management_token: this.config.management_token,
36
37
  });
38
+ // Use injected dependencies or defaults
39
+ this.backupHandler = (_a = deps.backupHandler) !== null && _a !== void 0 ? _a : utils_1.backupHandler;
40
+ this.setupBranchConfig = (_b = deps.setupBranchConfig) !== null && _b !== void 0 ? _b : utils_1.setupBranchConfig;
41
+ this.log = (_c = deps.log) !== null && _c !== void 0 ? _c : cli_utilities_1.log;
42
+ this.handleAndLogError = (_d = deps.handleAndLogError) !== null && _d !== void 0 ? _d : cli_utilities_1.handleAndLogError;
37
43
  }
38
44
  /**
39
45
  * Generate mapper logic
@@ -49,7 +55,7 @@ class ImportSetup {
49
55
  return [];
50
56
  visited.add(module);
51
57
  const dependencies = ((_a = this.config.modules[module]) === null || _a === void 0 ? void 0 : _a.dependencies) || [];
52
- let allDeps = [...dependencies];
58
+ const allDeps = [...dependencies];
53
59
  for (const dependency of dependencies) {
54
60
  allDeps.push(...getAllDependencies(dependency));
55
61
  }
@@ -61,7 +67,9 @@ class ImportSetup {
61
67
  allDependencies = allDependencies.filter((dep) => !assignedDependencies.has(dep)); // Remove assigned ones
62
68
  this.dependencyTree[module] = allDependencies;
63
69
  // Mark these dependencies as assigned so they won't be included in later modules
64
- allDependencies.forEach((dep) => assignedDependencies.add(dep));
70
+ for (const dep of allDependencies) {
71
+ assignedDependencies.add(dep);
72
+ }
65
73
  }
66
74
  }
67
75
  /**
@@ -72,10 +80,13 @@ class ImportSetup {
72
80
  */
73
81
  async runModuleImports() {
74
82
  var _a;
75
- cli_utilities_1.log.debug('Starting module imports', { modules: Object.keys(this.dependencyTree) });
83
+ this.log.debug('Starting module imports', { modules: Object.keys(this.dependencyTree) });
76
84
  for (const moduleName in this.dependencyTree) {
77
85
  try {
78
- cli_utilities_1.log.debug(`Importing module: ${moduleName}`, { moduleName, dependencies: this.dependencyTree[moduleName] });
86
+ this.log.debug(`Importing module: ${moduleName}`, {
87
+ moduleName,
88
+ dependencies: this.dependencyTree[moduleName],
89
+ });
79
90
  const modulePath = `./modules/${moduleName}`;
80
91
  const { default: ModuleClass } = await (_a = modulePath, Promise.resolve().then(() => __importStar(require(_a))));
81
92
  const modulePayload = {
@@ -85,14 +96,14 @@ class ImportSetup {
85
96
  };
86
97
  const moduleInstance = new ModuleClass(modulePayload);
87
98
  await moduleInstance.start();
88
- cli_utilities_1.log.debug(`Module ${moduleName} imported successfully`);
99
+ this.log.debug(`Module ${moduleName} imported successfully`);
89
100
  }
90
101
  catch (error) {
91
- (0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.config.context), { moduleName }), `Error occurred while importing '${moduleName}'`);
102
+ this.handleAndLogError(error, Object.assign(Object.assign({}, this.config.context), { moduleName }), `Error occurred while importing '${moduleName}'`);
92
103
  throw error;
93
104
  }
94
105
  }
95
- cli_utilities_1.log.debug('All module imports completed');
106
+ this.log.debug('All module imports completed');
96
107
  }
97
108
  /**
98
109
  * Start the import setup process
@@ -107,21 +118,21 @@ class ImportSetup {
107
118
  this.config.stackName = stackDetails.name;
108
119
  this.config.org_uid = stackDetails.org_uid;
109
120
  }
110
- cli_utilities_1.log.debug('Creating backup directory');
111
- const backupDir = await (0, utils_1.backupHandler)(this.config);
121
+ this.log.debug('Creating backup directory');
122
+ const backupDir = await this.backupHandler(this.config);
112
123
  if (backupDir) {
113
124
  this.config.backupDir = backupDir;
114
- cli_utilities_1.log.debug('Backup directory created', { backupDir });
125
+ this.log.debug('Backup directory created', { backupDir });
115
126
  }
116
- cli_utilities_1.log.debug('Setting up branch configuration');
117
- await (0, utils_1.setupBranchConfig)(this.config, this.stackAPIClient);
118
- cli_utilities_1.log.debug('Branch configuration completed', { branchName: this.config.branchName });
127
+ this.log.debug('Setting up branch configuration');
128
+ await this.setupBranchConfig(this.config, this.stackAPIClient);
129
+ this.log.debug('Branch configuration completed', { branchName: this.config.branchName });
119
130
  await this.generateDependencyTree();
120
131
  await this.runModuleImports();
121
- cli_utilities_1.log.debug('Import setup process completed successfully');
132
+ this.log.debug('Import setup process completed successfully');
122
133
  }
123
134
  catch (error) {
124
- (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.config.context), 'Import setup failed');
135
+ this.handleAndLogError(error, Object.assign({}, this.config.context), 'Import setup failed');
125
136
  throw error;
126
137
  }
127
138
  }
@@ -111,7 +111,7 @@ class AssetImportSetup extends base_setup_1.default {
111
111
  (0, utils_1.log)(this.config, error, 'error');
112
112
  });
113
113
  if (chunk) {
114
- let apiContent = (0, lodash_1.orderBy)((0, lodash_1.values)(chunk), '_version');
114
+ const apiContent = (0, lodash_1.orderBy)((0, lodash_1.values)(chunk), '_version');
115
115
  await this.makeConcurrentCall({
116
116
  apiContent,
117
117
  processName,
@@ -51,7 +51,7 @@ export interface InquirePayload {
51
51
  name: string;
52
52
  message: string;
53
53
  choices?: Array<any>;
54
- transformer?: Function;
54
+ transformer?: (...args: any[]) => any;
55
55
  }
56
56
  export interface User {
57
57
  email: string;
@@ -1,2 +1,9 @@
1
+ import { log as defaultLog } from '@contentstack/cli-utilities';
1
2
  import { ImportConfig } from 'src/types';
2
- export declare const validateBranch: (stackAPIClient: any, config: ImportConfig, branch: any) => Promise<unknown>;
3
+ /**
4
+ * Dependencies for validateBranch - can be injected for testing
5
+ */
6
+ export interface ValidateBranchDeps {
7
+ log?: typeof defaultLog;
8
+ }
9
+ export declare const validateBranch: (stackAPIClient: any, config: ImportConfig, branch: any, deps?: ValidateBranchDeps) => Promise<unknown>;
@@ -4,14 +4,16 @@ exports.validateBranch = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
6
  const cli_utilities_1 = require("@contentstack/cli-utilities");
7
- const validateBranch = async (stackAPIClient, config, branch) => {
7
+ const validateBranch = async (stackAPIClient, config, branch, deps = {}) => {
8
+ var _a;
9
+ const log = (_a = deps.log) !== null && _a !== void 0 ? _a : cli_utilities_1.log;
8
10
  return new Promise(async (resolve, reject) => {
9
11
  try {
10
12
  const data = await stackAPIClient.branch(branch).fetch();
11
13
  if (data && typeof data === 'object') {
12
14
  if (data.error_message) {
13
- cli_utilities_1.log.error(chalk_1.default.red(data.error_message), { error: data.error_message });
14
- cli_utilities_1.log.error(chalk_1.default.red('No branch found with the name ' + branch), { branch });
15
+ log.error(chalk_1.default.red(data.error_message), { error: data.error_message });
16
+ log.error(chalk_1.default.red('No branch found with the name ' + branch), { branch });
15
17
  reject({ message: 'No branch found with the name ' + branch, error: data.error_message });
16
18
  }
17
19
  else {
@@ -23,7 +25,7 @@ const validateBranch = async (stackAPIClient, config, branch) => {
23
25
  }
24
26
  }
25
27
  catch (error) {
26
- cli_utilities_1.log.error(chalk_1.default.red('No branch found with the name ' + branch), { error, branch });
28
+ log.error(chalk_1.default.red('No branch found with the name ' + branch), { error, branch });
27
29
  reject({ message: 'No branch found with the name ' + branch, error });
28
30
  }
29
31
  });
@@ -7,7 +7,7 @@ export declare const readLargeFile: (filePath: string, opts?: any) => Promise<an
7
7
  export declare const writeFileSync: (filePath: string, data: any) => void;
8
8
  export declare const writeFile: (filePath: string, data: any) => Promise<any>;
9
9
  export declare const writeLargeFile: (filePath: string, data: any) => Promise<any>;
10
- export declare const makeDirectory: (dir: string) => void;
10
+ export declare const makeDirectory: (...dirs: string[]) => void;
11
11
  export declare const readdirSync: (dirPath: string) => any;
12
12
  export declare const isFolderExist: (folderPath: string) => Promise<any>;
13
13
  export declare const fileExistsSync: (path: string) => boolean;
@@ -92,7 +92,7 @@ const writeLargeFile = function (filePath, data) {
92
92
  const stringifyStream = bigJSON.createStringifyStream({
93
93
  body: data,
94
94
  });
95
- var writeStream = fs.createWriteStream(filePath, 'utf-8');
95
+ const writeStream = fs.createWriteStream(filePath, 'utf-8');
96
96
  stringifyStream.pipe(writeStream);
97
97
  writeStream.on('finish', () => {
98
98
  resolve('');
@@ -103,9 +103,9 @@ const writeLargeFile = function (filePath, data) {
103
103
  });
104
104
  };
105
105
  exports.writeLargeFile = writeLargeFile;
106
- const makeDirectory = function (dir) {
107
- for (let key in arguments) {
108
- const dirname = path.resolve(arguments[key]);
106
+ const makeDirectory = function (...dirs) {
107
+ for (const dir of dirs) {
108
+ const dirname = path.resolve(dir);
109
109
  if (!fs.existsSync(dirname)) {
110
110
  mkdirp_1.default.sync(dirname);
111
111
  }
@@ -9,6 +9,9 @@ const interactive_1 = require("./interactive");
9
9
  const login_handler_1 = tslib_1.__importDefault(require("./login-handler"));
10
10
  const setupConfig = async (importCmdFlags) => {
11
11
  var _a;
12
+ // Set progress supported module FIRST, before any log calls
13
+ // This ensures the logger respects the showConsoleLogs setting correctly
14
+ cli_utilities_1.configHandler.set('log.progressSupportedModule', 'import-setup');
12
15
  let config = (0, merge_1.default)({}, config_1.default);
13
16
  // setup the config
14
17
  // if (importCmdFlags['config']) {
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * Contentstack Export
3
- * Copyright (c) 2024 Contentstack LLC
3
+ * Copyright (c) 2026 Contentstack LLC
4
4
  * MIT Licensed
5
5
  */
6
6
  import { ImportConfig } from '../types';
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  /*!
3
3
  * Contentstack Export
4
- * Copyright (c) 2024 Contentstack LLC
4
+ * Copyright (c) 2026 Contentstack LLC
5
5
  * MIT Licensed
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -10,13 +10,12 @@ const tslib_1 = require("tslib");
10
10
  const winston = tslib_1.__importStar(require("winston"));
11
11
  const path = tslib_1.__importStar(require("path"));
12
12
  const cli_utilities_1 = require("@contentstack/cli-utilities");
13
- 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)',
16
15
  '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))',
17
16
  ].join('|');
18
17
  function returnString(args) {
19
- var returnStr = '';
18
+ let returnStr = '';
20
19
  if (args && args.length) {
21
20
  returnStr = args
22
21
  .map(function (item) {
@@ -38,7 +37,7 @@ function returnString(args) {
38
37
  returnStr = returnStr.replace(new RegExp(ansiRegexPattern, 'g'), '').trim();
39
38
  return returnStr;
40
39
  }
41
- var myCustomLevels = {
40
+ const myCustomLevels = {
42
41
  levels: {
43
42
  warn: 1,
44
43
  info: 2,
@@ -94,30 +93,26 @@ function init(_logPath) {
94
93
  });
95
94
  }
96
95
  return {
97
- log: function (message) {
98
- let args = slice.call(arguments);
99
- let logString = returnString(args);
96
+ log: function (...args) {
97
+ const logString = returnString(args);
100
98
  if (logString) {
101
99
  logger.log('info', logString);
102
100
  }
103
101
  },
104
- warn: function (message) {
105
- let args = slice.call(arguments);
106
- let logString = returnString(args);
102
+ warn: function (...args) {
103
+ const logString = returnString(args);
107
104
  if (logString) {
108
105
  logger.log('warn', logString);
109
106
  }
110
107
  },
111
- error: function (message) {
112
- let args = slice.call(arguments);
113
- let logString = returnString(args);
108
+ error: function (...args) {
109
+ const logString = returnString(args);
114
110
  if (logString) {
115
111
  errorLogger.log('error', logString);
116
112
  }
117
113
  },
118
- debug: function () {
119
- let args = slice.call(arguments);
120
- let logString = returnString(args);
114
+ debug: function (...args) {
115
+ const logString = returnString(args);
121
116
  if (logString) {
122
117
  logger.log('debug', logString);
123
118
  }
@@ -1,8 +1,17 @@
1
1
  /*!
2
2
  * Contentstack Import
3
- * Copyright (c) 2024 Contentstack LLC
3
+ * Copyright (c) 2026 Contentstack LLC
4
4
  * MIT Licensed
5
5
  */
6
+ import { managementSDKClient as defaultManagementSDKClient, isAuthenticated as defaultIsAuthenticated, log as defaultLog } from '@contentstack/cli-utilities';
6
7
  import { ImportConfig } from '../types';
7
- declare const login: (config: ImportConfig) => Promise<any>;
8
+ /**
9
+ * Dependencies for login handler - can be injected for testing
10
+ */
11
+ export interface LoginHandlerDeps {
12
+ managementSDKClient?: typeof defaultManagementSDKClient;
13
+ isAuthenticated?: typeof defaultIsAuthenticated;
14
+ log?: typeof defaultLog;
15
+ }
16
+ declare const login: (config: ImportConfig, deps?: LoginHandlerDeps) => Promise<any>;
8
17
  export default login;
@@ -4,13 +4,17 @@
4
4
  /* eslint-disable no-empty */
5
5
  /*!
6
6
  * Contentstack Import
7
- * Copyright (c) 2024 Contentstack LLC
7
+ * Copyright (c) 2026 Contentstack LLC
8
8
  * MIT Licensed
9
9
  */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  const cli_utilities_1 = require("@contentstack/cli-utilities");
12
- const login = async (config) => {
13
- const client = await (0, cli_utilities_1.managementSDKClient)(config);
12
+ const login = async (config, deps = {}) => {
13
+ var _a, _b, _c;
14
+ const managementSDKClient = (_a = deps.managementSDKClient) !== null && _a !== void 0 ? _a : cli_utilities_1.managementSDKClient;
15
+ const isAuthenticated = (_b = deps.isAuthenticated) !== null && _b !== void 0 ? _b : cli_utilities_1.isAuthenticated;
16
+ const log = (_c = deps.log) !== null && _c !== void 0 ? _c : cli_utilities_1.log;
17
+ const client = await managementSDKClient(config);
14
18
  if (config.email && config.password) {
15
19
  const { user: { authtoken = null } = {} } = await client.login({ email: config.email, password: config.password });
16
20
  if (authtoken) {
@@ -20,7 +24,7 @@ const login = async (config) => {
20
24
  authtoken: config.authtoken,
21
25
  'X-User-Agent': 'contentstack-export/v',
22
26
  };
23
- cli_utilities_1.log.success('Contentstack account authenticated successfully!');
27
+ log.success('Contentstack account authenticated successfully!');
24
28
  return config;
25
29
  }
26
30
  else {
@@ -30,19 +34,19 @@ const login = async (config) => {
30
34
  else if (config.management_token) {
31
35
  return config;
32
36
  }
33
- else if ((0, cli_utilities_1.isAuthenticated)()) {
37
+ else if (isAuthenticated()) {
34
38
  const stackAPIClient = client.stack({
35
39
  api_key: config.target_stack,
36
40
  management_token: config.management_token,
37
41
  });
38
42
  const stack = await stackAPIClient.fetch().catch((error) => {
39
43
  var _a;
40
- let errorstack_key = (_a = error === null || error === void 0 ? void 0 : error.errors) === null || _a === void 0 ? void 0 : _a.api_key;
44
+ const errorstack_key = (_a = error === null || error === void 0 ? void 0 : error.errors) === null || _a === void 0 ? void 0 : _a.api_key;
41
45
  if (errorstack_key) {
42
- cli_utilities_1.log.error('Stack Api key ' + errorstack_key[0] + 'Please enter valid Key', { error });
46
+ log.error('Stack Api key ' + errorstack_key[0] + 'Please enter valid Key', { error });
43
47
  throw error;
44
48
  }
45
- cli_utilities_1.log.error((error === null || error === void 0 ? void 0 : error.errorMessage) || 'Unknown error', { error });
49
+ log.error((error === null || error === void 0 ? void 0 : error.errorMessage) || 'Unknown error', { error });
46
50
  throw error;
47
51
  });
48
52
  config.destinationStackName = stack.name;
@@ -1,15 +1,11 @@
1
1
  {
2
2
  "commands": {
3
3
  "cm:stacks:import-setup": {
4
- "aliases": [
5
- "cm:import-setup"
6
- ],
4
+ "aliases": [],
7
5
  "args": {},
8
6
  "description": "Helps to generate mappers and backup folder for importing (overwriting) specific modules",
9
7
  "examples": [
10
- "csdx cm:stacks:import-setup --stack-api-key <target_stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name>",
11
- "csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name>",
12
- "csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name> -b <branch_name>"
8
+ "csdx cm:stacks:import-setup --stack-api-key <target_stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name> --branch <branch_name>"
13
9
  ],
14
10
  "flags": {
15
11
  "stack-api-key": {
@@ -49,7 +45,6 @@
49
45
  "type": "option"
50
46
  },
51
47
  "branch": {
52
- "char": "B",
53
48
  "description": "The name of the branch where you want to import your content. If you don't mention the branch name, then by default the content will be imported to the main branch.",
54
49
  "exclusive": [
55
50
  "branch-alias"
@@ -88,5 +83,5 @@
88
83
  ]
89
84
  }
90
85
  },
91
- "version": "2.0.0-beta.1"
86
+ "version": "2.0.0-beta.3"
92
87
  }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-import-setup",
3
3
  "description": "Contentstack CLI plugin to setup the mappers and configurations for the import command",
4
- "version": "2.0.0-beta.1",
4
+ "version": "2.0.0-beta.3",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
8
- "@contentstack/cli-command": "~1.6.1",
9
- "@contentstack/cli-utilities": "~1.15.0",
8
+ "@contentstack/cli-command": "~1.7.2",
9
+ "@contentstack/cli-utilities": "~1.17.0",
10
10
  "@oclif/core": "^4.3.0",
11
11
  "big-json": "^3.2.0",
12
12
  "chalk": "^4.1.2",
@@ -24,6 +24,7 @@
24
24
  "@types/mkdirp": "^1.0.2",
25
25
  "@types/mocha": "^8.2.3",
26
26
  "@types/node": "^14.18.63",
27
+ "@types/sinon": "^10.0.20",
27
28
  "@types/rewire": "^2.5.30",
28
29
  "@types/tar": "^6.1.13",
29
30
  "@types/uuid": "^9.0.8",
@@ -35,6 +36,7 @@
35
36
  "nyc": "^15.1.0",
36
37
  "oclif": "^4.17.46",
37
38
  "rewire": "^9.0.1",
39
+ "sinon": "^19.0.5",
38
40
  "ts-node": "^10.9.2",
39
41
  "tsx": "^4.20.3",
40
42
  "typescript": "^4.9.5"