@contentstack/cli-cm-import-setup 1.7.2 → 2.0.0-beta.2

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.
Files changed (36) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +4 -49
  3. package/lib/commands/cm/stacks/import-setup.d.ts +1 -0
  4. package/lib/commands/cm/stacks/import-setup.js +28 -11
  5. package/lib/import/import-setup.d.ts +19 -5
  6. package/lib/import/import-setup.js +27 -16
  7. package/lib/import/modules/assets.js +48 -16
  8. package/lib/import/modules/base-setup.d.ts +20 -7
  9. package/lib/import/modules/base-setup.js +48 -15
  10. package/lib/import/modules/content-types.js +27 -5
  11. package/lib/import/modules/entries.js +11 -4
  12. package/lib/import/modules/extensions.d.ts +3 -6
  13. package/lib/import/modules/extensions.js +39 -23
  14. package/lib/import/modules/global-fields.js +27 -5
  15. package/lib/import/modules/marketplace-apps.d.ts +3 -5
  16. package/lib/import/modules/marketplace-apps.js +40 -18
  17. package/lib/import/modules/taxonomies.d.ts +5 -7
  18. package/lib/import/modules/taxonomies.js +103 -61
  19. package/lib/types/import-config.d.ts +1 -1
  20. package/lib/types/index.d.ts +8 -1
  21. package/lib/utils/common-helper.d.ts +8 -1
  22. package/lib/utils/common-helper.js +6 -4
  23. package/lib/utils/constants.d.ts +39 -0
  24. package/lib/utils/constants.js +114 -0
  25. package/lib/utils/file-helper.d.ts +1 -1
  26. package/lib/utils/file-helper.js +4 -4
  27. package/lib/utils/import-config-handler.js +3 -8
  28. package/lib/utils/index.d.ts +1 -0
  29. package/lib/utils/index.js +6 -1
  30. package/lib/utils/log.js +1 -1
  31. package/lib/utils/logger.d.ts +1 -1
  32. package/lib/utils/logger.js +11 -16
  33. package/lib/utils/login-handler.d.ts +11 -2
  34. package/lib/utils/login-handler.js +12 -8
  35. package/oclif.manifest.json +3 -8
  36. package/package.json +5 -3
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  /*!
3
3
  * Contentstack Export
4
- * Copyright (c) 2026 Contentstack LLC
4
+ * Copyright (c) 2024 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) 2026 Contentstack LLC
3
+ * Copyright (c) 2024 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) 2026 Contentstack LLC
7
+ * Copyright (c) 2024 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": "1.7.2"
86
+ "version": "2.0.0-beta.2"
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": "1.7.2",
4
+ "version": "2.0.0-beta.2",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
8
- "@contentstack/cli-command": "~1.7.1",
9
- "@contentstack/cli-utilities": "~1.16.0",
8
+ "@contentstack/cli-command": "~1.6.1",
9
+ "@contentstack/cli-utilities": "~1.15.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"