@contentstack/cli-cm-export 1.17.0 → 1.18.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.
Files changed (39) hide show
  1. package/README.md +1 -1
  2. package/lib/commands/cm/stacks/export.d.ts +2 -0
  3. package/lib/commands/cm/stacks/export.js +43 -15
  4. package/lib/export/module-exporter.js +16 -10
  5. package/lib/export/modules/assets.d.ts +0 -5
  6. package/lib/export/modules/assets.js +47 -32
  7. package/lib/export/modules/base-class.d.ts +1 -0
  8. package/lib/export/modules/base-class.js +16 -2
  9. package/lib/export/modules/content-types.d.ts +1 -1
  10. package/lib/export/modules/content-types.js +25 -12
  11. package/lib/export/modules/custom-roles.js +50 -9
  12. package/lib/export/modules/entries.d.ts +1 -1
  13. package/lib/export/modules/entries.js +63 -16
  14. package/lib/export/modules/environments.js +29 -7
  15. package/lib/export/modules/extensions.js +30 -7
  16. package/lib/export/modules/global-fields.js +27 -7
  17. package/lib/export/modules/index.js +10 -3
  18. package/lib/export/modules/labels.js +29 -7
  19. package/lib/export/modules/locales.d.ts +1 -1
  20. package/lib/export/modules/locales.js +29 -7
  21. package/lib/export/modules/marketplace-apps.d.ts +2 -1
  22. package/lib/export/modules/marketplace-apps.js +62 -15
  23. package/lib/export/modules/personalize.js +23 -6
  24. package/lib/export/modules/stack.js +57 -12
  25. package/lib/export/modules/taxonomies.d.ts +0 -1
  26. package/lib/export/modules/taxonomies.js +40 -30
  27. package/lib/export/modules/webhooks.js +29 -7
  28. package/lib/export/modules/workflows.js +38 -10
  29. package/lib/types/export-config.d.ts +6 -1
  30. package/lib/types/index.d.ts +11 -0
  31. package/lib/utils/basic-login.js +7 -8
  32. package/lib/utils/common-helper.js +3 -4
  33. package/lib/utils/export-config-handler.js +44 -0
  34. package/lib/utils/marketplace-app-helper.js +1 -2
  35. package/lib/utils/setup-branches.js +1 -1
  36. package/lib/utils/setup-export-dir.js +1 -1
  37. package/messages/index.json +69 -1
  38. package/oclif.manifest.json +9 -1
  39. package/package.json +4 -4
@@ -28,10 +28,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  var _a;
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
30
  exports.ExportAssets = void 0;
31
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
31
32
  async function startModuleExport(modulePayload) {
32
- const { default: ModuleRunner } = await (_a = `./${modulePayload.moduleName}`, Promise.resolve().then(() => __importStar(require(_a))));
33
- const moduleRunner = new ModuleRunner(modulePayload);
34
- return moduleRunner.start();
33
+ try {
34
+ const { default: ModuleRunner } = await (_a = `./${modulePayload.moduleName}`, Promise.resolve().then(() => __importStar(require(_a))));
35
+ const moduleRunner = new ModuleRunner(modulePayload);
36
+ return moduleRunner.start();
37
+ }
38
+ catch (error) {
39
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, modulePayload.exportConfig.context), { module: modulePayload.moduleName }));
40
+ throw error;
41
+ }
35
42
  }
36
43
  exports.default = startModuleExport;
37
44
  var assets_1 = require("./assets");
@@ -4,6 +4,7 @@ const tslib_1 = require("tslib");
4
4
  const omit_1 = tslib_1.__importDefault(require("lodash/omit"));
5
5
  const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
6
6
  const node_path_1 = require("node:path");
7
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
7
8
  const base_class_1 = tslib_1.__importDefault(require("./base-class"));
8
9
  const utils_1 = require("../../utils");
9
10
  class ExportLabels extends base_class_1.default {
@@ -12,52 +13,73 @@ class ExportLabels extends base_class_1.default {
12
13
  this.labels = {};
13
14
  this.labelConfig = exportConfig.modules.labels;
14
15
  this.qs = { include_count: true };
16
+ this.exportConfig.context.module = 'labels';
15
17
  }
16
18
  async start() {
17
- (0, utils_1.log)(this.exportConfig, 'Starting labels export', 'info');
19
+ cli_utilities_1.log.debug('Starting labels export process...', this.exportConfig.context);
18
20
  this.labelsFolderPath = (0, node_path_1.resolve)(this.exportConfig.data, this.exportConfig.branchName || '', this.labelConfig.dirName);
21
+ cli_utilities_1.log.debug(`Labels folder path: ${this.labelsFolderPath}`, this.exportConfig.context);
19
22
  await utils_1.fsUtil.makeDirectory(this.labelsFolderPath);
23
+ cli_utilities_1.log.debug('Created labels directory', this.exportConfig.context);
20
24
  await this.getLabels();
25
+ cli_utilities_1.log.debug(`Retrieved ${Object.keys(this.labels).length} labels`, this.exportConfig.context);
21
26
  if (this.labels === undefined || (0, isEmpty_1.default)(this.labels)) {
22
- (0, utils_1.log)(this.exportConfig, 'No labels found', 'info');
27
+ cli_utilities_1.log.info(cli_utilities_1.messageHandler.parse('LABELS_NOT_FOUND'), this.exportConfig.context);
23
28
  }
24
29
  else {
25
- utils_1.fsUtil.writeFile((0, node_path_1.resolve)(this.labelsFolderPath, this.labelConfig.fileName), this.labels);
26
- (0, utils_1.log)(this.exportConfig, 'All the labels have been exported successfully!', 'success');
30
+ const labelsFilePath = (0, node_path_1.resolve)(this.labelsFolderPath, this.labelConfig.fileName);
31
+ cli_utilities_1.log.debug(`Writing labels to: ${labelsFilePath}`, this.exportConfig.context);
32
+ utils_1.fsUtil.writeFile(labelsFilePath, this.labels);
33
+ cli_utilities_1.log.success(cli_utilities_1.messageHandler.parse('LABELS_EXPORT_COMPLETE', Object.keys(this.labels).length), this.exportConfig.context);
27
34
  }
28
35
  }
29
36
  async getLabels(skip = 0) {
30
37
  if (skip) {
31
38
  this.qs.skip = skip;
39
+ cli_utilities_1.log.debug(`Fetching labels with skip: ${skip}`, this.exportConfig.context);
32
40
  }
41
+ else {
42
+ cli_utilities_1.log.debug('Fetching labels with initial query', this.exportConfig.context);
43
+ }
44
+ cli_utilities_1.log.debug(`Query parameters: ${JSON.stringify(this.qs)}`, this.exportConfig.context);
33
45
  await this.stack
34
46
  .label()
35
47
  .query(this.qs)
36
48
  .find()
37
49
  .then(async (data) => {
38
50
  const { items, count } = data;
51
+ cli_utilities_1.log.debug(`Fetched ${(items === null || items === void 0 ? void 0 : items.length) || 0} labels out of total ${count}`, this.exportConfig.context);
39
52
  if (items === null || items === void 0 ? void 0 : items.length) {
53
+ cli_utilities_1.log.debug(`Processing ${items.length} labels`, this.exportConfig.context);
40
54
  this.sanitizeAttribs(items);
41
55
  skip += this.labelConfig.limit || 100;
42
56
  if (skip >= count) {
57
+ cli_utilities_1.log.debug('Completed fetching all labels', this.exportConfig.context);
43
58
  return;
44
59
  }
60
+ cli_utilities_1.log.debug(`Continuing to fetch labels with skip: ${skip}`, this.exportConfig.context);
45
61
  return await this.getLabels(skip);
46
62
  }
63
+ else {
64
+ cli_utilities_1.log.debug('No labels found to process', this.exportConfig.context);
65
+ }
47
66
  })
48
67
  .catch((error) => {
49
- (0, utils_1.log)(this.exportConfig, `Failed to export labels. ${(0, utils_1.formatError)(error)}`, 'error');
50
- (0, utils_1.log)(this.exportConfig, error, 'error');
68
+ cli_utilities_1.log.debug('Error occurred while fetching labels', this.exportConfig.context);
69
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context));
51
70
  });
52
71
  }
53
72
  sanitizeAttribs(labels) {
54
73
  var _a;
74
+ cli_utilities_1.log.debug(`Sanitizing ${labels.length} labels`, this.exportConfig.context);
55
75
  for (let index = 0; index < (labels === null || labels === void 0 ? void 0 : labels.length); index++) {
56
76
  const labelUid = labels[index].uid;
57
77
  const labelName = (_a = labels[index]) === null || _a === void 0 ? void 0 : _a.name;
78
+ cli_utilities_1.log.debug(`Processing label: ${labelName} (${labelUid})`, this.exportConfig.context);
58
79
  this.labels[labelUid] = (0, omit_1.default)(labels[index], this.labelConfig.invalidKeys);
59
- (0, utils_1.log)(this.exportConfig, `'${labelName}' label was exported successfully`, 'success');
80
+ cli_utilities_1.log.info(cli_utilities_1.messageHandler.parse('LABEL_EXPORT_SUCCESS', labelName), this.exportConfig.context);
60
81
  }
82
+ cli_utilities_1.log.debug(`Sanitization complete. Total labels processed: ${Object.keys(this.labels).length}`, this.exportConfig.context);
61
83
  }
62
84
  }
63
85
  exports.default = ExportLabels;
@@ -1,5 +1,5 @@
1
- import { ExportConfig, ModuleClassParams } from '../../types';
2
1
  import BaseClass from './base-class';
2
+ import { ExportConfig, ModuleClassParams } from '../../types';
3
3
  export default class LocaleExport extends BaseClass {
4
4
  private stackAPIClient;
5
5
  exportConfig: ExportConfig;
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const path = tslib_1.__importStar(require("path"));
5
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
5
6
  const utils_1 = require("../../utils");
6
7
  const base_class_1 = tslib_1.__importDefault(require("./base-class"));
7
- const cli_utilities_1 = require("@contentstack/cli-utilities");
8
8
  class LocaleExport extends base_class_1.default {
9
9
  constructor({ exportConfig, stackAPIClient }) {
10
10
  super({ exportConfig, stackAPIClient });
@@ -21,36 +21,55 @@ class LocaleExport extends base_class_1.default {
21
21
  this.localesPath = path.resolve((0, cli_utilities_1.sanitizePath)(exportConfig.data), (0, cli_utilities_1.sanitizePath)(exportConfig.branchName || ''), (0, cli_utilities_1.sanitizePath)(this.localeConfig.dirName));
22
22
  this.locales = {};
23
23
  this.masterLocale = {};
24
+ this.exportConfig.context.module = 'locales';
24
25
  }
25
26
  async start() {
26
27
  try {
27
- (0, utils_1.log)(this.exportConfig, 'Starting locale export', 'success');
28
+ cli_utilities_1.log.debug('Starting locales export process...', this.exportConfig.context);
29
+ cli_utilities_1.log.debug(`Locales path: ${this.localesPath}`, this.exportConfig.context);
28
30
  await utils_1.fsUtil.makeDirectory(this.localesPath);
31
+ cli_utilities_1.log.debug('Created locales directory', this.exportConfig.context);
29
32
  await this.getLocales();
30
- utils_1.fsUtil.writeFile(path.join(this.localesPath, this.localeConfig.fileName), this.locales);
31
- utils_1.fsUtil.writeFile(path.join(this.localesPath, this.masterLocaleConfig.fileName), this.masterLocale);
32
- (0, utils_1.log)(this.exportConfig, 'Completed locale export', 'success');
33
+ cli_utilities_1.log.debug(`Retrieved ${Object.keys(this.locales).length} locales and ${Object.keys(this.masterLocale).length} master locales`, this.exportConfig.context);
34
+ const localesFilePath = path.join(this.localesPath, this.localeConfig.fileName);
35
+ const masterLocaleFilePath = path.join(this.localesPath, this.masterLocaleConfig.fileName);
36
+ cli_utilities_1.log.debug(`Writing locales to: ${localesFilePath}`, this.exportConfig.context);
37
+ utils_1.fsUtil.writeFile(localesFilePath, this.locales);
38
+ cli_utilities_1.log.debug(`Writing master locale to: ${masterLocaleFilePath}`, this.exportConfig.context);
39
+ utils_1.fsUtil.writeFile(masterLocaleFilePath, this.masterLocale);
40
+ cli_utilities_1.log.success(cli_utilities_1.messageHandler.parse('LOCALES_EXPORT_COMPLETE', Object.keys(this.locales).length, Object.keys(this.masterLocale).length), this.exportConfig.context);
33
41
  }
34
42
  catch (error) {
35
- (0, utils_1.log)(this.exportConfig, `Failed to export locales. ${(0, utils_1.formatError)(error)}`, 'error');
36
- throw new Error('Failed to export locales');
43
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context));
44
+ throw error;
37
45
  }
38
46
  }
39
47
  async getLocales(skip = 0) {
48
+ var _a;
40
49
  if (skip) {
41
50
  this.qs.skip = skip;
51
+ cli_utilities_1.log.debug(`Fetching locales with skip: ${skip}`, this.exportConfig.context);
42
52
  }
53
+ cli_utilities_1.log.debug(`Query parameters: ${JSON.stringify(this.qs)}`, this.exportConfig.context);
43
54
  let localesFetchResponse = await this.stackAPIClient.locale().query(this.qs).find();
55
+ cli_utilities_1.log.debug(`Fetched ${((_a = localesFetchResponse.items) === null || _a === void 0 ? void 0 : _a.length) || 0} locales out of total ${localesFetchResponse.count}`, this.exportConfig.context);
44
56
  if (Array.isArray(localesFetchResponse.items) && localesFetchResponse.items.length > 0) {
57
+ cli_utilities_1.log.debug(`Processing ${localesFetchResponse.items.length} locales`, this.exportConfig.context);
45
58
  this.sanitizeAttribs(localesFetchResponse.items);
46
59
  skip += this.localeConfig.limit || 100;
47
60
  if (skip > localesFetchResponse.count) {
61
+ cli_utilities_1.log.debug('Completed fetching all locales', this.exportConfig.context);
48
62
  return;
49
63
  }
64
+ cli_utilities_1.log.debug(`Continuing to fetch locales with skip: ${skip}`, this.exportConfig.context);
50
65
  return await this.getLocales(skip);
51
66
  }
67
+ else {
68
+ cli_utilities_1.log.debug('No locales found to process', this.exportConfig.context);
69
+ }
52
70
  }
53
71
  sanitizeAttribs(locales) {
72
+ cli_utilities_1.log.debug(`Sanitizing ${locales.length} locales`, this.exportConfig.context);
54
73
  locales.forEach((locale) => {
55
74
  var _a, _b;
56
75
  for (let key in locale) {
@@ -59,12 +78,15 @@ class LocaleExport extends base_class_1.default {
59
78
  }
60
79
  }
61
80
  if ((locale === null || locale === void 0 ? void 0 : locale.code) === ((_b = (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.master_locale) === null || _b === void 0 ? void 0 : _b.code)) {
81
+ cli_utilities_1.log.debug(`Adding locale ${locale.uid} to master locale`, this.exportConfig.context);
62
82
  this.masterLocale[locale.uid] = locale;
63
83
  }
64
84
  else {
85
+ cli_utilities_1.log.debug(`Adding locale ${locale.uid} to regular locales`, this.exportConfig.context);
65
86
  this.locales[locale.uid] = locale;
66
87
  }
67
88
  });
89
+ cli_utilities_1.log.debug(`Sanitization complete. Master locales: ${Object.keys(this.masterLocale).length}, Regular locales: ${Object.keys(this.locales).length}`, this.exportConfig.context);
68
90
  }
69
91
  }
70
92
  exports.default = LocaleExport;
@@ -1,6 +1,6 @@
1
+ import { Command } from '@contentstack/cli-command';
1
2
  import { NodeCrypto, ContentstackMarketplaceClient } from '@contentstack/cli-utilities';
2
3
  import { ModuleClassParams, MarketplaceAppsConfig, ExportConfig, Installation } from '../../types';
3
- import { Command } from '@contentstack/cli-command';
4
4
  export default class ExportMarketplaceApps {
5
5
  protected marketplaceAppConfig: MarketplaceAppsConfig;
6
6
  protected installedApps: Installation[];
@@ -10,6 +10,7 @@ export default class ExportMarketplaceApps {
10
10
  appSdk: ContentstackMarketplaceClient;
11
11
  exportConfig: ExportConfig;
12
12
  command: Command;
13
+ query: Record<string, any>;
13
14
  constructor({ exportConfig }: Omit<ModuleClassParams, 'stackAPIClient' | 'moduleName'>);
14
15
  start(): Promise<void>;
15
16
  /**
@@ -15,58 +15,90 @@ class ExportMarketplaceApps {
15
15
  this.installedApps = [];
16
16
  this.exportConfig = exportConfig;
17
17
  this.marketplaceAppConfig = exportConfig.modules.marketplace_apps;
18
+ this.exportConfig.context.module = 'marketplace-apps';
18
19
  }
19
20
  async start() {
21
+ cli_utilities_1.log.debug('Starting marketplace apps export process...', this.exportConfig.context);
20
22
  if (!(0, cli_utilities_1.isAuthenticated)()) {
21
23
  cli_utilities_1.cliux.print('WARNING!!! To export Marketplace apps, you must be logged in. Please check csdx auth:login --help to log in', { color: 'yellow' });
22
24
  return Promise.resolve();
23
25
  }
24
- (0, utils_1.log)(this.exportConfig, 'Starting marketplace app export', 'info');
25
26
  this.marketplaceAppPath = (0, node_path_1.resolve)(this.exportConfig.data, this.exportConfig.branchName || '', this.marketplaceAppConfig.dirName);
27
+ cli_utilities_1.log.debug(`Marketplace apps folder path: ${this.marketplaceAppPath}`, this.exportConfig.context);
26
28
  await utils_1.fsUtil.makeDirectory(this.marketplaceAppPath);
29
+ cli_utilities_1.log.debug('Created marketplace apps directory', this.exportConfig.context);
27
30
  this.developerHubBaseUrl = this.exportConfig.developerHubBaseUrl || (await (0, utils_1.getDeveloperHubUrl)(this.exportConfig));
31
+ cli_utilities_1.log.debug(`Developer hub base URL: ${this.developerHubBaseUrl}`, this.exportConfig.context);
28
32
  this.exportConfig.org_uid = await (0, utils_1.getOrgUid)(this.exportConfig);
33
+ this.query = { target_uids: this.exportConfig.source_stack };
34
+ cli_utilities_1.log.debug(`Organization UID: ${this.exportConfig.org_uid}`, this.exportConfig.context);
29
35
  // NOTE init marketplace app sdk
30
36
  const host = this.developerHubBaseUrl.split('://').pop();
37
+ cli_utilities_1.log.debug(`Initializing marketplace SDK with host: ${host}`, this.exportConfig.context);
31
38
  this.appSdk = await (0, cli_utilities_1.marketplaceSDKClient)({ host });
32
39
  await this.exportApps();
40
+ cli_utilities_1.log.debug('Marketplace apps export process completed', this.exportConfig.context);
33
41
  }
34
42
  /**
35
43
  * The function `exportApps` encrypts the configuration of installed apps using a Node.js crypto
36
44
  * library if it is available.
37
45
  */
38
46
  async exportApps() {
47
+ var _a, _b, _c, _d, _e, _f, _g;
48
+ cli_utilities_1.log.debug('Starting apps export process...', this.exportConfig.context);
49
+ // currently support only app_uids or installation_uids
50
+ const externalQuery = (_a = this.exportConfig.query) === null || _a === void 0 ? void 0 : _a.modules['marketplace-apps'];
51
+ if (externalQuery) {
52
+ if (((_c = (_b = externalQuery.app_uid) === null || _b === void 0 ? void 0 : _b.$in) === null || _c === void 0 ? void 0 : _c.length) > 0) {
53
+ this.query.app_uids = externalQuery.app_uid.$in.join(',');
54
+ }
55
+ if (((_e = (_d = externalQuery.installation_uid) === null || _d === void 0 ? void 0 : _d.$in) === null || _e === void 0 ? void 0 : _e.length) > 0) {
56
+ this.query.installation_uids = (_g = (_f = externalQuery.installation_uid) === null || _f === void 0 ? void 0 : _f.$in) === null || _g === void 0 ? void 0 : _g.join(',');
57
+ }
58
+ }
39
59
  await this.getStackSpecificApps();
60
+ cli_utilities_1.log.debug(`Retrieved ${this.installedApps.length} stack-specific apps`, this.exportConfig.context);
40
61
  await this.getAppManifestAndAppConfig();
62
+ cli_utilities_1.log.debug('Completed app manifest and configuration processing', this.exportConfig.context);
41
63
  if (!this.nodeCrypto && (0, find_1.default)(this.installedApps, (app) => !(0, isEmpty_1.default)(app.configuration))) {
64
+ cli_utilities_1.log.debug('Initializing NodeCrypto for app configuration encryption', this.exportConfig.context);
42
65
  this.nodeCrypto = await (0, utils_1.createNodeCryptoInstance)(this.exportConfig);
43
66
  }
44
67
  this.installedApps = (0, map_1.default)(this.installedApps, (app) => {
68
+ var _a;
45
69
  if ((0, has_1.default)(app, 'configuration')) {
70
+ cli_utilities_1.log.debug(`Encrypting configuration for app: ${((_a = app.manifest) === null || _a === void 0 ? void 0 : _a.name) || app.uid}`, this.exportConfig.context);
46
71
  app['configuration'] = this.nodeCrypto.encrypt(app.configuration);
47
72
  }
48
73
  return app;
49
74
  });
75
+ cli_utilities_1.log.debug(`Processed ${this.installedApps.length} total marketplace apps`, this.exportConfig.context);
50
76
  }
51
77
  /**
52
78
  * The function `getAppManifestAndAppConfig` exports the manifest and configurations of installed
53
79
  * marketplace apps.
54
80
  */
55
81
  async getAppManifestAndAppConfig() {
82
+ var _a;
56
83
  if ((0, isEmpty_1.default)(this.installedApps)) {
57
- (0, utils_1.log)(this.exportConfig, 'No marketplace apps found', 'info');
84
+ cli_utilities_1.log.info(cli_utilities_1.messageHandler.parse('MARKETPLACE_APPS_NOT_FOUND'), this.exportConfig.context);
58
85
  }
59
86
  else {
87
+ cli_utilities_1.log.debug(`Processing ${this.installedApps.length} installed apps`, this.exportConfig.context);
60
88
  for (const [index, app] of (0, entries_1.default)(this.installedApps)) {
61
89
  if (app.manifest.visibility === 'private') {
90
+ cli_utilities_1.log.debug(`Processing private app manifest: ${app.manifest.name}`, this.exportConfig.context);
62
91
  await this.getPrivateAppsManifest(+index, app);
63
92
  }
64
93
  }
65
94
  for (const [index, app] of (0, entries_1.default)(this.installedApps)) {
95
+ cli_utilities_1.log.debug(`Processing app configurations: ${((_a = app.manifest) === null || _a === void 0 ? void 0 : _a.name) || app.uid}`, this.exportConfig.context);
66
96
  await this.getAppConfigurations(+index, app);
67
97
  }
68
- utils_1.fsUtil.writeFile((0, node_path_1.resolve)(this.marketplaceAppPath, this.marketplaceAppConfig.fileName), this.installedApps);
69
- (0, utils_1.log)(this.exportConfig, 'All the marketplace apps have been exported successfully', 'info');
98
+ const marketplaceAppsFilePath = (0, node_path_1.resolve)(this.marketplaceAppPath, this.marketplaceAppConfig.fileName);
99
+ cli_utilities_1.log.debug(`Writing marketplace apps to: ${marketplaceAppsFilePath}`, this.exportConfig.context);
100
+ utils_1.fsUtil.writeFile(marketplaceAppsFilePath, this.installedApps);
101
+ cli_utilities_1.log.success(cli_utilities_1.messageHandler.parse('MARKETPLACE_APPS_EXPORT_COMPLETE', Object.keys(this.installedApps).length), this.exportConfig.context);
70
102
  }
71
103
  }
72
104
  /**
@@ -79,14 +111,17 @@ class ExportMarketplaceApps {
79
111
  * app's manifest.
80
112
  */
81
113
  async getPrivateAppsManifest(index, appInstallation) {
114
+ cli_utilities_1.log.debug(`Fetching private app manifest for: ${appInstallation.manifest.name} (${appInstallation.manifest.uid})`, this.exportConfig.context);
82
115
  const manifest = await this.appSdk
83
116
  .marketplace(this.exportConfig.org_uid)
84
117
  .app(appInstallation.manifest.uid)
85
118
  .fetch({ include_oauth: true })
86
119
  .catch((error) => {
87
- (0, utils_1.log)(this.exportConfig, error, 'error');
120
+ cli_utilities_1.log.debug(`Failed to fetch private app manifest for: ${appInstallation.manifest.name}`, this.exportConfig.context);
121
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context), cli_utilities_1.messageHandler.parse('MARKETPLACE_APP_MANIFEST_EXPORT_FAILED', appInstallation.manifest.name));
88
122
  });
89
123
  if (manifest) {
124
+ cli_utilities_1.log.debug(`Successfully fetched private app manifest for: ${appInstallation.manifest.name}`, this.exportConfig.context);
90
125
  this.installedApps[index].manifest = manifest;
91
126
  }
92
127
  }
@@ -105,7 +140,8 @@ class ExportMarketplaceApps {
105
140
  const appName = (_a = appInstallation === null || appInstallation === void 0 ? void 0 : appInstallation.manifest) === null || _a === void 0 ? void 0 : _a.name;
106
141
  const appUid = (_b = appInstallation === null || appInstallation === void 0 ? void 0 : appInstallation.manifest) === null || _b === void 0 ? void 0 : _b.uid;
107
142
  const app = appName || appUid;
108
- (0, utils_1.log)(this.exportConfig, `Exporting ${app} app and it's config.`, 'info');
143
+ cli_utilities_1.log.debug(`Fetching app configuration for: ${app}`, this.exportConfig.context);
144
+ cli_utilities_1.log.info(cli_utilities_1.messageHandler.parse('MARKETPLACE_APP_CONFIG_EXPORT', app), this.exportConfig.context);
109
145
  await this.appSdk
110
146
  .marketplace(this.exportConfig.org_uid)
111
147
  .installation(appInstallation.uid)
@@ -113,28 +149,32 @@ class ExportMarketplaceApps {
113
149
  .then(async (result) => {
114
150
  const { data, error } = result;
115
151
  if ((0, has_1.default)(data, 'server_configuration') || (0, has_1.default)(data, 'configuration')) {
152
+ cli_utilities_1.log.debug(`Found configuration data for app: ${app}`, this.exportConfig.context);
116
153
  if (!this.nodeCrypto && ((0, has_1.default)(data, 'server_configuration') || (0, has_1.default)(data, 'configuration'))) {
154
+ cli_utilities_1.log.debug(`Initializing NodeCrypto for app: ${app}`, this.exportConfig.context);
117
155
  this.nodeCrypto = await (0, utils_1.createNodeCryptoInstance)(this.exportConfig);
118
156
  }
119
157
  if (!(0, isEmpty_1.default)(data === null || data === void 0 ? void 0 : data.configuration)) {
158
+ cli_utilities_1.log.debug(`Encrypting configuration for app: ${app}`, this.exportConfig.context);
120
159
  this.installedApps[index]['configuration'] = this.nodeCrypto.encrypt(data.configuration);
121
160
  }
122
161
  if (!(0, isEmpty_1.default)(data === null || data === void 0 ? void 0 : data.server_configuration)) {
162
+ cli_utilities_1.log.debug(`Encrypting server configuration for app: ${app}`, this.exportConfig.context);
123
163
  this.installedApps[index]['server_configuration'] = this.nodeCrypto.encrypt(data.server_configuration);
124
- (0, utils_1.log)(this.exportConfig, `Exported ${app} app and it's config.`, 'success');
164
+ cli_utilities_1.log.success(cli_utilities_1.messageHandler.parse('MARKETPLACE_APP_CONFIG_SUCCESS', app), this.exportConfig.context);
125
165
  }
126
166
  else {
127
- (0, utils_1.log)(this.exportConfig, `Exported ${app} app`, 'success');
167
+ cli_utilities_1.log.success(cli_utilities_1.messageHandler.parse('MARKETPLACE_APP_EXPORT_SUCCESS', app), this.exportConfig.context);
128
168
  }
129
169
  }
130
170
  else if (error) {
131
- (0, utils_1.log)(this.exportConfig, `Error on exporting ${app} app and it's config.`, 'error');
132
- (0, utils_1.log)(this.exportConfig, error, 'error');
171
+ cli_utilities_1.log.debug(`Error in app configuration data for: ${app}`, this.exportConfig.context);
172
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context), cli_utilities_1.messageHandler.parse('MARKETPLACE_APP_CONFIG_EXPORT_FAILED', app));
133
173
  }
134
174
  })
135
175
  .catch((error) => {
136
- (0, utils_1.log)(this.exportConfig, `Failed to export ${app} app config ${(0, utils_1.formatError)(error)}`, 'error');
137
- (0, utils_1.log)(this.exportConfig, error, 'error');
176
+ cli_utilities_1.log.debug(`Failed to fetch app configuration for: ${app}`, this.exportConfig.context);
177
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context), cli_utilities_1.messageHandler.parse('MARKETPLACE_APP_CONFIG_EXPORT_FAILED', app));
138
178
  });
139
179
  }
140
180
  /**
@@ -145,26 +185,33 @@ class ExportMarketplaceApps {
145
185
  * the API. In this code, it is initially set to 0, indicating that no items should be skipped in
146
186
  */
147
187
  async getStackSpecificApps(skip = 0) {
188
+ cli_utilities_1.log.debug(`Fetching stack-specific apps with skip: ${skip}`, this.exportConfig.context);
148
189
  const collection = await this.appSdk
149
190
  .marketplace(this.exportConfig.org_uid)
150
191
  .installation()
151
- .fetchAll({ target_uids: this.exportConfig.source_stack, skip })
192
+ .fetchAll(Object.assign(Object.assign({}, this.query), { skip }))
152
193
  .catch((error) => {
153
- (0, utils_1.log)(this.exportConfig, `Failed to export marketplace-apps ${(0, utils_1.formatError)(error)}`, 'error');
154
- (0, utils_1.log)(this.exportConfig, error, 'error');
194
+ cli_utilities_1.log.debug('Error occurred while fetching stack-specific apps', this.exportConfig.context);
195
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context));
155
196
  });
156
197
  if (collection) {
157
198
  const { items: apps, count } = collection;
199
+ cli_utilities_1.log.debug(`Fetched ${(apps === null || apps === void 0 ? void 0 : apps.length) || 0} apps out of total ${count}`, this.exportConfig.context);
158
200
  // NOTE Remove all the chain functions
159
201
  const installation = (0, map_1.default)(apps, (app) => (0, omitBy_1.default)(app, (val, _key) => {
160
202
  if (val instanceof Function)
161
203
  return true;
162
204
  return false;
163
205
  }));
206
+ cli_utilities_1.log.debug(`Processed ${installation.length} app installations`, this.exportConfig.context);
164
207
  this.installedApps = this.installedApps.concat(installation);
165
208
  if (count - (skip + 50) > 0) {
209
+ cli_utilities_1.log.debug(`Continuing to fetch apps with skip: ${skip + 50}`, this.exportConfig.context);
166
210
  await this.getStackSpecificApps(skip + 50);
167
211
  }
212
+ else {
213
+ cli_utilities_1.log.debug('Completed fetching all stack-specific apps', this.exportConfig.context);
214
+ }
168
215
  }
169
216
  }
170
217
  }
@@ -1,26 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const cli_variants_1 = require("@contentstack/cli-variants");
4
- const utils_1 = require("../../utils");
4
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
5
5
  class ExportPersonalize {
6
6
  constructor({ exportConfig }) {
7
7
  this.exportConfig = exportConfig;
8
8
  this.personalizeConfig = exportConfig.modules.personalize;
9
+ this.exportConfig.context.module = 'personalize';
9
10
  }
10
11
  async start() {
11
12
  try {
13
+ cli_utilities_1.log.debug('Starting personalize export process...', this.exportConfig.context);
12
14
  if (!this.personalizeConfig.baseURL[this.exportConfig.region.name]) {
13
- (0, utils_1.log)(this.exportConfig, 'Skipping Personalize project export, personalize url is not set', 'info');
15
+ cli_utilities_1.log.debug(`Personalize URL not set for region: ${this.exportConfig.region.name}`, this.exportConfig.context);
16
+ cli_utilities_1.log.info(cli_utilities_1.messageHandler.parse('PERSONALIZE_URL_NOT_SET'), this.exportConfig.context);
14
17
  this.exportConfig.personalizationEnabled = false;
15
18
  return;
16
19
  }
17
20
  if (this.exportConfig.management_token) {
18
- (0, utils_1.log)(this.exportConfig, 'Skipping Personalize project export when using management token', 'info');
21
+ cli_utilities_1.log.debug('Management token detected, skipping personalize export', this.exportConfig.context);
22
+ cli_utilities_1.log.info(cli_utilities_1.messageHandler.parse('PERSONALIZE_SKIPPING_WITH_MANAGEMENT_TOKEN'), this.exportConfig.context);
19
23
  this.exportConfig.personalizationEnabled = false;
20
24
  return;
21
25
  }
26
+ cli_utilities_1.log.debug('Starting projects export for personalization...', this.exportConfig.context);
22
27
  await new cli_variants_1.ExportProjects(this.exportConfig).start();
23
28
  if (this.exportConfig.personalizationEnabled) {
29
+ cli_utilities_1.log.debug('Personalization is enabled, processing personalize modules...', this.exportConfig.context);
24
30
  const moduleMapper = {
25
31
  events: new cli_variants_1.ExportEvents(this.exportConfig),
26
32
  attributes: new cli_variants_1.ExportAttributes(this.exportConfig),
@@ -29,22 +35,33 @@ class ExportPersonalize {
29
35
  };
30
36
  const order = this.exportConfig.modules.personalize
31
37
  .exportOrder;
38
+ cli_utilities_1.log.debug(`Personalize export order: ${order.join(', ')}`, this.exportConfig.context);
32
39
  for (const module of order) {
40
+ cli_utilities_1.log.debug(`Processing personalize module: ${module}`, this.exportConfig.context);
33
41
  if (moduleMapper[module]) {
42
+ cli_utilities_1.log.debug(`Starting export for module: ${module}`, this.exportConfig.context);
34
43
  await moduleMapper[module].start();
44
+ cli_utilities_1.log.debug(`Completed export for module: ${module}`, this.exportConfig.context);
35
45
  }
36
46
  else {
37
- (0, utils_1.log)(this.exportConfig, `No implementation found for the module ${module}`, 'info');
47
+ cli_utilities_1.log.debug(`Module not implemented: ${module}`, this.exportConfig.context);
48
+ cli_utilities_1.log.info(cli_utilities_1.messageHandler.parse('PERSONALIZE_MODULE_NOT_IMPLEMENTED', module), this.exportConfig.context);
38
49
  }
39
50
  }
51
+ cli_utilities_1.log.debug('Completed all personalize module exports', this.exportConfig.context);
52
+ }
53
+ else {
54
+ cli_utilities_1.log.debug('Personalization is disabled, skipping personalize module exports', this.exportConfig.context);
40
55
  }
41
56
  }
42
57
  catch (error) {
43
58
  if (error === 'Forbidden') {
44
- (0, utils_1.log)(this.exportConfig, "Personalize is not enabled in the given organization!", 'info');
59
+ cli_utilities_1.log.debug('Personalize access forbidden, personalization not enabled', this.exportConfig.context);
60
+ cli_utilities_1.log.info(cli_utilities_1.messageHandler.parse('PERSONALIZE_NOT_ENABLED'), this.exportConfig.context);
45
61
  }
46
62
  else {
47
- (0, utils_1.log)(this.exportConfig, error, 'error');
63
+ cli_utilities_1.log.debug('Error occurred during personalize export', this.exportConfig.context);
64
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context));
48
65
  }
49
66
  this.exportConfig.personalizationEnabled = false;
50
67
  }