@contentstack/cli-cm-import 1.28.1 → 2.0.1-beta

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 (85) hide show
  1. package/README.md +5 -7
  2. package/lib/commands/cm/stacks/import.d.ts +2 -0
  3. package/lib/commands/cm/stacks/import.js +46 -11
  4. package/lib/config/index.js +0 -1
  5. package/lib/import/module-importer.js +6 -20
  6. package/lib/import/modules/assets.d.ts +6 -0
  7. package/lib/import/modules/assets.js +102 -25
  8. package/lib/import/modules/base-class.d.ts +17 -0
  9. package/lib/import/modules/base-class.js +45 -0
  10. package/lib/import/modules/content-types.d.ts +7 -10
  11. package/lib/import/modules/content-types.js +132 -68
  12. package/lib/import/modules/custom-roles.d.ts +6 -2
  13. package/lib/import/modules/custom-roles.js +80 -69
  14. package/lib/import/modules/entries.d.ts +7 -0
  15. package/lib/import/modules/entries.js +278 -163
  16. package/lib/import/modules/environments.d.ts +3 -0
  17. package/lib/import/modules/environments.js +69 -38
  18. package/lib/import/modules/extensions.d.ts +3 -0
  19. package/lib/import/modules/extensions.js +99 -64
  20. package/lib/import/modules/global-fields.d.ts +8 -1
  21. package/lib/import/modules/global-fields.js +123 -63
  22. package/lib/import/modules/index.d.ts +1 -0
  23. package/lib/import/modules/index.js +1 -0
  24. package/lib/import/modules/labels.d.ts +3 -0
  25. package/lib/import/modules/labels.js +104 -54
  26. package/lib/import/modules/locales.d.ts +15 -4
  27. package/lib/import/modules/locales.js +194 -94
  28. package/lib/import/modules/marketplace-apps.d.ts +6 -3
  29. package/lib/import/modules/marketplace-apps.js +177 -102
  30. package/lib/import/modules/personalize.d.ts +11 -4
  31. package/lib/import/modules/personalize.js +138 -47
  32. package/lib/import/modules/stack.d.ts +6 -0
  33. package/lib/import/modules/stack.js +71 -27
  34. package/lib/import/modules/taxonomies.d.ts +4 -2
  35. package/lib/import/modules/taxonomies.js +60 -46
  36. package/lib/import/modules/variant-entries.d.ts +7 -4
  37. package/lib/import/modules/variant-entries.js +76 -35
  38. package/lib/import/modules/webhooks.d.ts +3 -0
  39. package/lib/import/modules/webhooks.js +71 -40
  40. package/lib/import/modules/workflows.d.ts +3 -0
  41. package/lib/import/modules/workflows.js +98 -48
  42. package/lib/types/default-config.d.ts +0 -1
  43. package/lib/types/import-config.d.ts +0 -1
  44. package/lib/types/index.d.ts +1 -12
  45. package/lib/utils/backup-handler.js +0 -1
  46. package/lib/utils/constants.d.ts +243 -0
  47. package/lib/utils/constants.js +264 -0
  48. package/lib/utils/import-config-handler.js +2 -0
  49. package/lib/utils/import-path-resolver.js +3 -13
  50. package/lib/utils/index.d.ts +1 -1
  51. package/lib/utils/index.js +6 -2
  52. package/lib/utils/marketplace-app-helper.js +3 -8
  53. package/lib/utils/progress-strategy-registry.d.ts +7 -0
  54. package/lib/utils/progress-strategy-registry.js +78 -0
  55. package/lib/utils/setup-branch.js +1 -1
  56. package/oclif.manifest.json +2 -2
  57. package/package.json +3 -3
  58. package/lib/import/modules-js/assets.d.ts +0 -33
  59. package/lib/import/modules-js/assets.js +0 -428
  60. package/lib/import/modules-js/content-types.d.ts +0 -34
  61. package/lib/import/modules-js/content-types.js +0 -204
  62. package/lib/import/modules-js/custom-roles.d.ts +0 -15
  63. package/lib/import/modules-js/custom-roles.js +0 -143
  64. package/lib/import/modules-js/entries.d.ts +0 -54
  65. package/lib/import/modules-js/entries.js +0 -1280
  66. package/lib/import/modules-js/environments.d.ts +0 -13
  67. package/lib/import/modules-js/environments.js +0 -85
  68. package/lib/import/modules-js/extensions.d.ts +0 -18
  69. package/lib/import/modules-js/extensions.js +0 -86
  70. package/lib/import/modules-js/global-fields.d.ts +0 -13
  71. package/lib/import/modules-js/global-fields.js +0 -106
  72. package/lib/import/modules-js/index.d.ts +0 -1
  73. package/lib/import/modules-js/index.js +0 -33
  74. package/lib/import/modules-js/labels.d.ts +0 -20
  75. package/lib/import/modules-js/labels.js +0 -148
  76. package/lib/import/modules-js/locales.d.ts +0 -24
  77. package/lib/import/modules-js/locales.js +0 -196
  78. package/lib/import/modules-js/marketplace-apps.d.ts +0 -63
  79. package/lib/import/modules-js/marketplace-apps.js +0 -429
  80. package/lib/import/modules-js/webhooks.d.ts +0 -17
  81. package/lib/import/modules-js/webhooks.js +0 -85
  82. package/lib/import/modules-js/workflows.d.ts +0 -19
  83. package/lib/import/modules-js/workflows.js +0 -170
  84. package/lib/utils/log.d.ts +0 -12
  85. package/lib/utils/log.js +0 -31
@@ -13,13 +13,14 @@ const filter_1 = tslib_1.__importDefault(require("lodash/filter"));
13
13
  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
- const log_1 = require("../../utils/log");
17
16
  const interactive_1 = require("../../utils/interactive");
18
17
  const utils_1 = require("../../utils");
19
- class ImportMarketplaceApps {
20
- constructor({ importConfig }) {
21
- this.importConfig = importConfig;
22
- this.importConfig.context.module = 'marketplace-apps';
18
+ const base_class_1 = tslib_1.__importDefault(require("./base-class"));
19
+ class ImportMarketplaceApps extends base_class_1.default {
20
+ constructor({ importConfig, stackAPIClient }) {
21
+ super({ importConfig, stackAPIClient });
22
+ this.importConfig.context.module = utils_1.MODULE_CONTEXTS.MARKETPLACE_APPS;
23
+ this.currentModuleName = utils_1.MODULE_NAMES[utils_1.MODULE_CONTEXTS.MARKETPLACE_APPS];
23
24
  this.marketPlaceAppConfig = importConfig.modules.marketplace_apps;
24
25
  this.mapperDirPath = (0, node_path_1.join)(this.importConfig.backupDir, 'mapper', 'marketplace_apps');
25
26
  this.marketPlaceFolderPath = (0, node_path_1.join)(this.importConfig.backupDir, this.marketPlaceAppConfig.dirName);
@@ -36,45 +37,61 @@ class ImportMarketplaceApps {
36
37
  * @returns The function `start()` returns a `Promise<void>`.
37
38
  */
38
39
  async start() {
39
- var _a;
40
- cli_utilities_1.log.debug('Checking for marketplace apps folder existence', this.importConfig.context);
41
- if (utils_1.fileHelper.fileExistsSync(this.marketPlaceFolderPath)) {
42
- cli_utilities_1.log.debug(`Found marketplace apps folder: ${this.marketPlaceFolderPath}`, this.importConfig.context);
43
- this.marketplaceApps = utils_1.fsUtil.readFile((0, node_path_1.join)(this.marketPlaceFolderPath, this.marketPlaceAppConfig.fileName), true);
44
- cli_utilities_1.log.debug(`Found ${((_a = this.marketplaceApps) === null || _a === void 0 ? void 0 : _a.length) || 0} marketplace apps to import`, this.importConfig.context);
45
- }
46
- else {
47
- cli_utilities_1.log.info(`No Marketplace apps are found - '${this.marketPlaceFolderPath}'`, this.importConfig.context);
48
- return;
49
- }
50
- if ((0, isEmpty_1.default)(this.marketplaceApps)) {
51
- cli_utilities_1.log.debug('No marketplace apps found to import', this.importConfig.context);
52
- return Promise.resolve();
40
+ try {
41
+ cli_utilities_1.log.debug('Starting marketplace apps import process...', this.importConfig.context);
42
+ const [marketplaceAppsCount] = await this.analyzeMarketplaceApps();
43
+ if (marketplaceAppsCount === 0) {
44
+ cli_utilities_1.log.info('No marketplace apps found to import', this.importConfig.context);
45
+ return;
46
+ }
47
+ if (!(0, cli_utilities_1.isAuthenticated)()) {
48
+ cli_utilities_1.cliux.print('\nWARNING!!! To import Marketplace apps, you must be logged in. Please check csdx auth:login --help to log in\n', { color: 'yellow' });
49
+ cli_utilities_1.log.info('Skipping marketplace apps import - user not authenticated', this.importConfig.context);
50
+ return;
51
+ }
52
+ // Handle encryption key prompt BEFORE starting progress
53
+ if (!this.importConfig.forceStopMarketplaceAppsPrompt) {
54
+ cli_utilities_1.log.debug('Validating security configuration before progress start', this.importConfig.context);
55
+ await this.getAndValidateEncryptionKey(this.importConfig.marketplaceAppEncryptionKey);
56
+ }
57
+ const progress = this.createNestedProgress(this.currentModuleName);
58
+ const privateAppsCount = (0, filter_1.default)(this.marketplaceApps, { manifest: { visibility: 'private' } }).length;
59
+ progress.addProcess(utils_1.PROCESS_NAMES.SETUP_ENVIRONMENT, 1);
60
+ if (privateAppsCount > 0) {
61
+ progress.addProcess(utils_1.PROCESS_NAMES.CREATE_APPS, privateAppsCount);
62
+ }
63
+ progress.addProcess(utils_1.PROCESS_NAMES.INSTALL_APPS, marketplaceAppsCount);
64
+ this.prepareMarketplaceAppMapper();
65
+ // Step 1: Setup Environment SDK and authentication
66
+ cli_utilities_1.log.info('Setting up marketplace SDK and authentication', this.importConfig.context);
67
+ progress
68
+ .startProcess(utils_1.PROCESS_NAMES.SETUP_ENVIRONMENT)
69
+ .updateStatus(utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.SETUP_ENVIRONMENT].SETTING_UP, utils_1.PROCESS_NAMES.SETUP_ENVIRONMENT);
70
+ await this.setupMarketplaceEnvironment();
71
+ progress.completeProcess(utils_1.PROCESS_NAMES.SETUP_ENVIRONMENT, true);
72
+ // Step 2: Handle private apps creation (if any)
73
+ if (privateAppsCount > 0) {
74
+ cli_utilities_1.log.info('Starting private apps creation process', this.importConfig.context);
75
+ progress
76
+ .startProcess(utils_1.PROCESS_NAMES.CREATE_APPS)
77
+ .updateStatus(utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.CREATE_APPS].CREATING, utils_1.PROCESS_NAMES.CREATE_APPS);
78
+ await this.handleAllPrivateAppsCreationProcess();
79
+ progress.completeProcess(utils_1.PROCESS_NAMES.CREATE_APPS, true);
80
+ }
81
+ // Step 3: Install marketplace apps - FIXED THIS PART
82
+ cli_utilities_1.log.info('Starting marketplace apps installation process', this.importConfig.context);
83
+ progress
84
+ .startProcess(utils_1.PROCESS_NAMES.INSTALL_APPS)
85
+ .updateStatus(utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.INSTALL_APPS].INSTALLING, utils_1.PROCESS_NAMES.INSTALL_APPS);
86
+ await this.importMarketplaceApps();
87
+ progress.completeProcess(utils_1.PROCESS_NAMES.INSTALL_APPS, true);
88
+ this.completeProgress(true);
89
+ cli_utilities_1.log.success('Marketplace apps have been imported successfully!', this.importConfig.context);
53
90
  }
54
- else if (!(0, cli_utilities_1.isAuthenticated)()) {
55
- cli_utilities_1.cliux.print('\nWARNING!!! To import Marketplace apps, you must be logged in. Please check csdx auth:login --help to log in\n', { color: 'yellow' });
56
- cli_utilities_1.log.info('Skipping marketplace apps import - user not authenticated', this.importConfig.context);
57
- return Promise.resolve();
91
+ catch (error) {
92
+ this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Marketplace apps import failed');
93
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.importConfig.context));
58
94
  }
59
- cli_utilities_1.log.debug('Creating marketplace apps mapper directory', this.importConfig.context);
60
- await utils_1.fsUtil.makeDirectory(this.mapperDirPath);
61
- cli_utilities_1.log.debug('Created marketplace apps mapper directory', this.importConfig.context);
62
- cli_utilities_1.log.debug('Getting developer hub base URL', this.importConfig.context);
63
- this.developerHubBaseUrl = this.importConfig.developerHubBaseUrl || (await (0, utils_1.getDeveloperHubUrl)(this.importConfig));
64
- this.importConfig.developerHubBaseUrl = this.developerHubBaseUrl;
65
- cli_utilities_1.log.debug(`Using developer hub base URL: ${this.developerHubBaseUrl}`, this.importConfig.context);
66
- // NOTE init marketplace app sdk
67
- cli_utilities_1.log.debug('Initializing marketplace SDK client', this.importConfig.context);
68
- const host = this.developerHubBaseUrl.split('://').pop();
69
- this.appSdk = await (0, cli_utilities_1.marketplaceSDKClient)({ host });
70
- cli_utilities_1.log.debug('Initialized marketplace SDK client', this.importConfig.context);
71
- cli_utilities_1.log.debug('Getting organization UID', this.importConfig.context);
72
- this.importConfig.org_uid = await (0, utils_1.getOrgUid)(this.importConfig);
73
- cli_utilities_1.log.debug(`Using organization UID: ${this.importConfig.org_uid}`, this.importConfig.context);
74
- // NOTE start the marketplace import process
75
- cli_utilities_1.log.debug('Starting marketplace apps import process', this.importConfig.context);
76
- await this.importMarketplaceApps();
77
- cli_utilities_1.log.success('Marketplace apps have been imported successfully!', this.importConfig.context);
78
95
  }
79
96
  /**
80
97
  * The function `importMarketplaceApps` installs marketplace apps, handles private app creation,
@@ -89,13 +106,6 @@ class ImportMarketplaceApps {
89
106
  cli_utilities_1.log.debug('Using forced security configuration without validation', this.importConfig.context);
90
107
  this.nodeCrypto = new cli_utilities_1.NodeCrypto(cryptoArgs);
91
108
  }
92
- else {
93
- cli_utilities_1.log.debug('Validating security configuration', this.importConfig.context);
94
- await this.getAndValidateEncryptionKey(this.importConfig.marketplaceAppEncryptionKey);
95
- }
96
- // NOTE install all private apps which is not available for stack.
97
- cli_utilities_1.log.debug('Handling private apps creation process', this.importConfig.context);
98
- await this.handleAllPrivateAppsCreationProcess();
99
109
  // NOTE getting all apps to validate if it's already installed in the stack to manage conflict
100
110
  cli_utilities_1.log.debug('Getting all stack-specific apps for validation', this.importConfig.context);
101
111
  this.installedApps = await (0, utils_1.getAllStackSpecificApps)(this.importConfig);
@@ -178,6 +188,7 @@ class ImportMarketplaceApps {
178
188
  return defaultValue;
179
189
  }
180
190
  cli_utilities_1.log.debug('Found app configuration requiring security setup, asking for input', this.importConfig.context);
191
+ cli_utilities_1.cliux.print('\n');
181
192
  const encryptionKey = await (0, interactive_1.askEncryptionKey)(defaultValue);
182
193
  try {
183
194
  appConfig = !(0, isEmpty_1.default)(appConfig.configuration) ? appConfig.configuration : appConfig.server_configuration;
@@ -210,6 +221,7 @@ class ImportMarketplaceApps {
210
221
  * @returns a Promise that resolves to void.
211
222
  */
212
223
  async handleAllPrivateAppsCreationProcess() {
224
+ var _a, _b;
213
225
  cli_utilities_1.log.debug('Filtering private apps from marketplace apps', this.importConfig.context);
214
226
  const privateApps = (0, filter_1.default)(this.marketplaceApps, { manifest: { visibility: 'private' } });
215
227
  cli_utilities_1.log.debug(`Found ${privateApps.length} private apps to process`, this.importConfig.context);
@@ -218,6 +230,7 @@ class ImportMarketplaceApps {
218
230
  return Promise.resolve();
219
231
  }
220
232
  cli_utilities_1.log.debug('Getting confirmation to create private apps', this.importConfig.context);
233
+ cli_utilities_1.cliux.print('\n');
221
234
  let canCreatePrivateApp = await (0, utils_1.getConfirmationToCreateApps)(privateApps, this.importConfig);
222
235
  this.importConfig.canCreatePrivateApp = canCreatePrivateApp;
223
236
  if (canCreatePrivateApp) {
@@ -228,6 +241,7 @@ class ImportMarketplaceApps {
228
241
  if (await this.isPrivateAppExistInDeveloperHub(app)) {
229
242
  // NOTE Found app already exist in the same org
230
243
  this.appUidMapping[app.uid] = app.uid;
244
+ (_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(true, `${app.manifest.name} (already exists)`, null, utils_1.PROCESS_NAMES.CREATE_APPS);
231
245
  cli_utilities_1.cliux.print(`App '${app.manifest.name}' already exist. skipping app recreation.!`, { color: 'yellow' });
232
246
  cli_utilities_1.log.debug(`App '${app.manifest.name}' already exists, skipping recreation`, this.importConfig.context);
233
247
  continue;
@@ -255,6 +269,10 @@ class ImportMarketplaceApps {
255
269
  }
256
270
  else {
257
271
  cli_utilities_1.log.info('Skipping private apps creation on Developer Hub...', this.importConfig.context);
272
+ // Mark all private apps as skipped in progress
273
+ for (let app of privateApps) {
274
+ (_b = this.progressManager) === null || _b === void 0 ? void 0 : _b.tick(true, `${app.manifest.name} (creation skipped)`, null, utils_1.PROCESS_NAMES.CREATE_APPS);
275
+ }
258
276
  }
259
277
  this.appOriginalName = undefined;
260
278
  cli_utilities_1.log.debug('Private apps creation process completed', this.importConfig.context);
@@ -393,6 +411,7 @@ class ImportMarketplaceApps {
393
411
  * @returns a Promise.
394
412
  */
395
413
  async appCreationCallback(app, response, appSuffix) {
414
+ var _a, _b, _c;
396
415
  const { statusText, message } = response || {};
397
416
  cli_utilities_1.log.debug(`Processing app creation callback for: ${app.name} (suffix: ${appSuffix})`, this.importConfig.context);
398
417
  if (message) {
@@ -404,7 +423,7 @@ class ImportMarketplaceApps {
404
423
  return this.createPrivateApp(updatedApp, appSuffix + 1, true);
405
424
  }
406
425
  else {
407
- (0, log_1.trace)(response, 'error', true);
426
+ (_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(false, `${app.name}`, message, utils_1.PROCESS_NAMES.CREATE_APPS);
408
427
  cli_utilities_1.log.error((0, utils_1.formatError)(message), this.importConfig.context);
409
428
  if (this.importConfig.forceStopMarketplaceAppsPrompt) {
410
429
  cli_utilities_1.log.debug('Force stop marketplace apps prompt is enabled, resolving', this.importConfig.context);
@@ -422,6 +441,7 @@ class ImportMarketplaceApps {
422
441
  }
423
442
  else if (response.uid) {
424
443
  // NOTE new app installation
444
+ (_b = this.progressManager) === null || _b === void 0 ? void 0 : _b.tick(true, `${response.name}`, null, utils_1.PROCESS_NAMES.CREATE_APPS);
425
445
  cli_utilities_1.log.success(`${response.name} app created successfully.!`, this.importConfig.context);
426
446
  cli_utilities_1.log.debug(`App UID mapping: ${app.uid} → ${response.uid}`, this.importConfig.context);
427
447
  this.appUidMapping[app.uid] = response.uid;
@@ -429,6 +449,7 @@ class ImportMarketplaceApps {
429
449
  cli_utilities_1.log.debug(`App name mapping: ${this.appOriginalName} → ${response.name}`, this.importConfig.context);
430
450
  }
431
451
  else {
452
+ (_c = this.progressManager) === null || _c === void 0 ? void 0 : _c.tick(false, `${app.name}`, 'Unexpected response format', utils_1.PROCESS_NAMES.CREATE_APPS);
432
453
  cli_utilities_1.log.debug(`Unexpected response format for app: ${app.name}`, this.importConfig.context);
433
454
  }
434
455
  }
@@ -440,58 +461,69 @@ class ImportMarketplaceApps {
440
461
  * @returns {Promise<void>}
441
462
  */
442
463
  async installApps(app) {
443
- var _a, _b, _c, _d, _e, _f, _g, _h;
444
- cli_utilities_1.log.debug(`Installing app: ${((_a = app.manifest) === null || _a === void 0 ? void 0 : _a.name) || ((_b = app.manifest) === null || _b === void 0 ? void 0 : _b.uid)}`, this.importConfig.context);
445
- let updateParam;
446
- const { configuration, server_configuration } = app;
447
- const currentStackApp = (0, find_1.default)(this.installedApps, { manifest: { uid: (_c = app === null || app === void 0 ? void 0 : app.manifest) === null || _c === void 0 ? void 0 : _c.uid } });
448
- if (!currentStackApp) {
449
- cli_utilities_1.log.debug(`App not found in current stack, installing new app: ${(_d = app.manifest) === null || _d === void 0 ? void 0 : _d.name}`, this.importConfig.context);
450
- // NOTE install new app
451
- if (app.manifest.visibility === 'private' && !this.importConfig.canCreatePrivateApp) {
452
- cli_utilities_1.log.info(`Skipping the installation of the private app ${app.manifest.name}...`, this.importConfig.context);
453
- return Promise.resolve();
464
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
465
+ try {
466
+ cli_utilities_1.log.debug(`Installing app: ${((_a = app.manifest) === null || _a === void 0 ? void 0 : _a.name) || ((_b = app.manifest) === null || _b === void 0 ? void 0 : _b.uid)}`, this.importConfig.context);
467
+ let updateParam;
468
+ const { configuration, server_configuration } = app;
469
+ const currentStackApp = (0, find_1.default)(this.installedApps, { manifest: { uid: (_c = app === null || app === void 0 ? void 0 : app.manifest) === null || _c === void 0 ? void 0 : _c.uid } });
470
+ if (!currentStackApp) {
471
+ cli_utilities_1.log.debug(`App not found in current stack, installing new app: ${(_d = app.manifest) === null || _d === void 0 ? void 0 : _d.name}`, this.importConfig.context);
472
+ if (app.manifest.visibility === 'private' && !this.importConfig.canCreatePrivateApp) {
473
+ (_e = this.progressManager) === null || _e === void 0 ? void 0 : _e.tick(true, `${app.manifest.name} (skipped - private app not allowed)`, null, utils_1.PROCESS_NAMES.INSTALL_APPS);
474
+ cli_utilities_1.log.info(`Skipping the installation of the private app ${app.manifest.name}...`, this.importConfig.context);
475
+ return Promise.resolve();
476
+ }
477
+ cli_utilities_1.log.debug(`Installing app with manifest UID: ${this.appUidMapping[app.manifest.uid] || app.manifest.uid}`, this.importConfig.context);
478
+ const installation = await this.installApp(this.importConfig,
479
+ // NOTE if it's private app it should get uid from mapper else will use manifest uid
480
+ this.appUidMapping[app.manifest.uid] || app.manifest.uid);
481
+ if (installation.installation_uid) {
482
+ const appName = this.appNameMapping[app.manifest.name] || app.manifest.name || app.manifest.uid;
483
+ (_f = this.progressManager) === null || _f === void 0 ? void 0 : _f.tick(true, `${appName}`, null, utils_1.PROCESS_NAMES.INSTALL_APPS);
484
+ cli_utilities_1.log.success(`${appName} app installed successfully.!`, this.importConfig.context);
485
+ cli_utilities_1.log.debug(`Installation UID: ${installation.installation_uid}`, this.importConfig.context);
486
+ cli_utilities_1.log.debug(`Making redirect URL call for app: ${appName}`, this.importConfig.context);
487
+ await (0, utils_1.makeRedirectUrlCall)(installation, appName, this.importConfig);
488
+ this.installationUidMapping[app.uid] = installation.installation_uid;
489
+ cli_utilities_1.log.debug(`Installation UID mapping: ${app.uid} → ${installation.installation_uid}`, this.importConfig.context);
490
+ updateParam = Object.assign(Object.assign({ manifest: app.manifest }, installation), { configuration, server_configuration });
491
+ }
492
+ else if (installation.message) {
493
+ (_g = this.progressManager) === null || _g === void 0 ? void 0 : _g.tick(false, `${(_h = app.manifest) === null || _h === void 0 ? void 0 : _h.name}`, installation.message, utils_1.PROCESS_NAMES.INSTALL_APPS);
494
+ cli_utilities_1.log.info((0, utils_1.formatError)(installation.message), this.importConfig.context);
495
+ cli_utilities_1.log.debug(`Installation failed for app: ${(_j = app.manifest) === null || _j === void 0 ? void 0 : _j.name}`, this.importConfig.context);
496
+ cli_utilities_1.cliux.print('\n');
497
+ await (0, utils_1.confirmToCloseProcess)(installation, this.importConfig);
498
+ }
454
499
  }
455
- cli_utilities_1.log.debug(`Installing app with manifest UID: ${this.appUidMapping[app.manifest.uid] || app.manifest.uid}`, this.importConfig.context);
456
- const installation = await this.installApp(this.importConfig,
457
- // NOTE if it's private app it should get uid from mapper else will use manifest uid
458
- this.appUidMapping[app.manifest.uid] || app.manifest.uid);
459
- if (installation.installation_uid) {
460
- const appName = this.appNameMapping[app.manifest.name] || app.manifest.name || app.manifest.uid;
461
- cli_utilities_1.log.success(`${appName} app installed successfully.!`, this.importConfig.context);
462
- cli_utilities_1.log.debug(`Installation UID: ${installation.installation_uid}`, this.importConfig.context);
463
- cli_utilities_1.log.debug(`Making redirect URL call for app: ${appName}`, this.importConfig.context);
464
- await (0, utils_1.makeRedirectUrlCall)(installation, appName, this.importConfig);
465
- this.installationUidMapping[app.uid] = installation.installation_uid;
466
- cli_utilities_1.log.debug(`Installation UID mapping: ${app.uid} → ${installation.installation_uid}`, this.importConfig.context);
467
- updateParam = Object.assign(Object.assign({ manifest: app.manifest }, installation), { configuration, server_configuration });
500
+ else if (!(0, isEmpty_1.default)(configuration) || !(0, isEmpty_1.default)(server_configuration)) {
501
+ const appName = app.manifest.name || app.manifest.uid;
502
+ (_k = this.progressManager) === null || _k === void 0 ? void 0 : _k.tick(true, `${appName} (already installed, updating config)`, null, utils_1.PROCESS_NAMES.INSTALL_APPS);
503
+ cli_utilities_1.log.info(`${appName} is already installed`, this.importConfig.context);
504
+ cli_utilities_1.log.debug(`Handling existing app configuration for: ${appName}`, this.importConfig.context);
505
+ updateParam = await (0, utils_1.ifAppAlreadyExist)(app, currentStackApp, this.importConfig);
468
506
  }
469
- else if (installation.message) {
470
- cli_utilities_1.log.info((0, utils_1.formatError)(installation.message), this.importConfig.context);
471
- cli_utilities_1.log.debug(`Installation failed for app: ${(_e = app.manifest) === null || _e === void 0 ? void 0 : _e.name}`, this.importConfig.context);
472
- await (0, utils_1.confirmToCloseProcess)(installation, this.importConfig);
507
+ else {
508
+ (_l = this.progressManager) === null || _l === void 0 ? void 0 : _l.tick(true, `${(_m = app.manifest) === null || _m === void 0 ? void 0 : _m.name} (already installed)`, null, utils_1.PROCESS_NAMES.INSTALL_APPS);
509
+ cli_utilities_1.log.debug(`App ${(_o = app.manifest) === null || _o === void 0 ? void 0 : _o.name} is already installed with no configuration to update`, this.importConfig.context);
510
+ }
511
+ if (!this.appUidMapping[app.manifest.uid]) {
512
+ this.appUidMapping[app.manifest.uid] = currentStackApp ? currentStackApp.manifest.uid : app.manifest.uid;
513
+ cli_utilities_1.log.debug(`App UID mapping: ${app.manifest.uid} → ${this.appUidMapping[app.manifest.uid]}`, this.importConfig.context);
514
+ }
515
+ // NOTE update configurations
516
+ if (updateParam && (!(0, isEmpty_1.default)(updateParam.configuration) || !(0, isEmpty_1.default)(updateParam.server_configuration))) {
517
+ cli_utilities_1.log.debug(`Updating app configuration for: ${(_p = app.manifest) === null || _p === void 0 ? void 0 : _p.name}`, this.importConfig.context);
518
+ await this.updateAppsConfig(updateParam);
519
+ }
520
+ else {
521
+ cli_utilities_1.log.debug(`No configuration update needed for: ${(_q = app.manifest) === null || _q === void 0 ? void 0 : _q.name}`, this.importConfig.context);
473
522
  }
474
523
  }
475
- else if (!(0, isEmpty_1.default)(configuration) || !(0, isEmpty_1.default)(server_configuration)) {
476
- const appName = app.manifest.name || app.manifest.uid;
477
- cli_utilities_1.log.info(`${appName} is already installed`, this.importConfig.context);
478
- cli_utilities_1.log.debug(`Handling existing app configuration for: ${appName}`, this.importConfig.context);
479
- updateParam = await (0, utils_1.ifAppAlreadyExist)(app, currentStackApp, this.importConfig);
480
- }
481
- else {
482
- cli_utilities_1.log.debug(`App ${(_f = app.manifest) === null || _f === void 0 ? void 0 : _f.name} is already installed with no configuration to update`, this.importConfig.context);
483
- }
484
- if (!this.appUidMapping[app.manifest.uid]) {
485
- this.appUidMapping[app.manifest.uid] = currentStackApp ? currentStackApp.manifest.uid : app.manifest.uid;
486
- cli_utilities_1.log.debug(`App UID mapping: ${app.manifest.uid} → ${this.appUidMapping[app.manifest.uid]}`, this.importConfig.context);
487
- }
488
- // NOTE update configurations
489
- if (updateParam && (!(0, isEmpty_1.default)(updateParam.configuration) || !(0, isEmpty_1.default)(updateParam.server_configuration))) {
490
- cli_utilities_1.log.debug(`Updating app configuration for: ${(_g = app.manifest) === null || _g === void 0 ? void 0 : _g.name}`, this.importConfig.context);
491
- await this.updateAppsConfig(updateParam);
492
- }
493
- else {
494
- cli_utilities_1.log.debug(`No configuration update needed for: ${(_h = app.manifest) === null || _h === void 0 ? void 0 : _h.name}`, this.importConfig.context);
524
+ catch (error) {
525
+ (_r = this.progressManager) === null || _r === void 0 ? void 0 : _r.tick(false, `APP name: ${(_s = app.manifest) === null || _s === void 0 ? void 0 : _s.name}`, (error === null || error === void 0 ? void 0 : error.message) || 'Failed to install apps', utils_1.PROCESS_NAMES.INSTALL_APPS);
526
+ throw error;
495
527
  }
496
528
  }
497
529
  /**
@@ -512,7 +544,7 @@ class ImportMarketplaceApps {
512
544
  .setConfiguration(this.nodeCrypto.decrypt(configuration))
513
545
  .then(({ data }) => {
514
546
  if (data === null || data === void 0 ? void 0 : data.message) {
515
- (0, log_1.trace)(data, 'error', true);
547
+ cli_utilities_1.log.debug(data, this.importConfig.context);
516
548
  cli_utilities_1.log.info((0, utils_1.formatError)(data.message), this.importConfig.context);
517
549
  }
518
550
  else {
@@ -521,7 +553,7 @@ class ImportMarketplaceApps {
521
553
  }
522
554
  })
523
555
  .catch((error) => {
524
- (0, log_1.trace)(error, 'error', true);
556
+ cli_utilities_1.log.debug(error, this.importConfig.context);
525
557
  cli_utilities_1.log.error((0, utils_1.formatError)(error), this.importConfig.context);
526
558
  cli_utilities_1.log.debug(`Configuration update failed for: ${appName}`, this.importConfig.context);
527
559
  });
@@ -534,7 +566,7 @@ class ImportMarketplaceApps {
534
566
  .setServerConfig(this.nodeCrypto.decrypt(server_configuration))
535
567
  .then(({ data }) => {
536
568
  if (data === null || data === void 0 ? void 0 : data.message) {
537
- (0, log_1.trace)(data, 'error', true);
569
+ cli_utilities_1.log.debug(data, this.importConfig.context);
538
570
  cli_utilities_1.log.error((0, utils_1.formatError)(data.message), this.importConfig.context);
539
571
  }
540
572
  else {
@@ -543,11 +575,54 @@ class ImportMarketplaceApps {
543
575
  }
544
576
  })
545
577
  .catch((error) => {
546
- (0, log_1.trace)(error, 'error', true);
578
+ cli_utilities_1.log.debug(error, this.importConfig.context);
547
579
  cli_utilities_1.log.error((0, utils_1.formatError)(error), this.importConfig.context);
548
580
  cli_utilities_1.log.debug(`Server configuration update failed for: ${appName}`, this.importConfig.context);
549
581
  });
550
582
  }
551
583
  }
584
+ async analyzeMarketplaceApps() {
585
+ return this.withLoadingSpinner('MARKETPLACE APPS: Analyzing import data...', async () => {
586
+ var _a;
587
+ cli_utilities_1.log.debug('Checking for marketplace apps folder existence', this.importConfig.context);
588
+ if (!utils_1.fileHelper.fileExistsSync(this.marketPlaceFolderPath)) {
589
+ cli_utilities_1.log.info(`No Marketplace apps are found - '${this.marketPlaceFolderPath}'`, this.importConfig.context);
590
+ return [0];
591
+ }
592
+ cli_utilities_1.log.debug(`Found marketplace apps folder: ${this.marketPlaceFolderPath}`, this.importConfig.context);
593
+ this.marketplaceApps = utils_1.fsUtil.readFile((0, node_path_1.join)(this.marketPlaceFolderPath, this.marketPlaceAppConfig.fileName), true);
594
+ if ((0, isEmpty_1.default)(this.marketplaceApps)) {
595
+ cli_utilities_1.log.debug('No marketplace apps found to import', this.importConfig.context);
596
+ return [0];
597
+ }
598
+ const count = ((_a = this.marketplaceApps) === null || _a === void 0 ? void 0 : _a.length) || 0;
599
+ cli_utilities_1.log.debug(`Found ${count} marketplace apps to import`, this.importConfig.context);
600
+ return [count];
601
+ });
602
+ }
603
+ prepareMarketplaceAppMapper() {
604
+ cli_utilities_1.log.debug('Creating marketplace apps mapper directory', this.importConfig.context);
605
+ utils_1.fsUtil.makeDirectory(this.mapperDirPath);
606
+ cli_utilities_1.log.debug(`Created marketplace apps mapper directory, ${this.mapperDirPath}`, this.importConfig.context);
607
+ }
608
+ async setupMarketplaceEnvironment() {
609
+ try {
610
+ cli_utilities_1.log.debug('Getting developer hub base URL', this.importConfig.context);
611
+ this.developerHubBaseUrl = this.importConfig.developerHubBaseUrl || (await (0, utils_1.getDeveloperHubUrl)(this.importConfig));
612
+ this.importConfig.developerHubBaseUrl = this.developerHubBaseUrl;
613
+ cli_utilities_1.log.debug(`Using developer hub base URL: ${this.developerHubBaseUrl}`, this.importConfig.context);
614
+ // NOTE init marketplace app sdk
615
+ cli_utilities_1.log.debug('Initializing marketplace SDK client', this.importConfig.context);
616
+ const host = this.developerHubBaseUrl.split('://').pop();
617
+ this.appSdk = await (0, cli_utilities_1.marketplaceSDKClient)({ host });
618
+ cli_utilities_1.log.debug('Initialized marketplace SDK client', this.importConfig.context);
619
+ cli_utilities_1.log.debug('Getting organization UID', this.importConfig.context);
620
+ this.importConfig.org_uid = await (0, utils_1.getOrgUid)(this.importConfig);
621
+ cli_utilities_1.log.debug(`Using organization UID: ${this.importConfig.org_uid}`, this.importConfig.context);
622
+ }
623
+ catch (error) {
624
+ throw error;
625
+ }
626
+ }
552
627
  }
553
628
  exports.default = ImportMarketplaceApps;
@@ -1,11 +1,18 @@
1
+ import BaseClass from './base-class';
1
2
  import { ImportConfig, ModuleClassParams } from '../../types';
2
- export default class ImportPersonalize {
3
+ export default class ImportPersonalize extends BaseClass {
3
4
  private config;
4
5
  personalizeConfig: ImportConfig['modules']['personalize'];
5
- constructor({ importConfig }: ModuleClassParams);
6
+ private readonly moduleDisplayMapper;
7
+ constructor({ importConfig, stackAPIClient }: ModuleClassParams);
6
8
  /**
7
- * The `start` function in TypeScript asynchronously imports data based on a specified order using a
8
- * module mapper.
9
+ * @method start
10
+ * @returns {Promise<void>} Promise<void>
9
11
  */
10
12
  start(): Promise<void>;
13
+ private addProjectProcess;
14
+ private addModuleProcesses;
15
+ private importProjects;
16
+ private importModules;
17
+ private analyzePersonalize;
11
18
  }