@contentstack/cli-cm-export 1.20.2 → 2.0.0-beta.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 (72) hide show
  1. package/README.md +1 -1
  2. package/lib/commands/cm/stacks/export.js +15 -6
  3. package/lib/config/index.js +0 -2
  4. package/lib/export/module-exporter.js +37 -38
  5. package/lib/export/modules/assets.js +71 -14
  6. package/lib/export/modules/base-class.d.ts +17 -0
  7. package/lib/export/modules/base-class.js +45 -0
  8. package/lib/export/modules/content-types.js +30 -8
  9. package/lib/export/modules/custom-roles.js +61 -21
  10. package/lib/export/modules/entries.d.ts +2 -0
  11. package/lib/export/modules/entries.js +137 -37
  12. package/lib/export/modules/environments.js +45 -20
  13. package/lib/export/modules/extensions.js +42 -17
  14. package/lib/export/modules/global-fields.d.ts +1 -1
  15. package/lib/export/modules/global-fields.js +24 -6
  16. package/lib/export/modules/index.d.ts +1 -0
  17. package/lib/export/modules/index.js +1 -0
  18. package/lib/export/modules/labels.js +43 -16
  19. package/lib/export/modules/locales.js +31 -12
  20. package/lib/export/modules/marketplace-apps.d.ts +5 -2
  21. package/lib/export/modules/marketplace-apps.js +95 -25
  22. package/lib/export/modules/personalize.d.ts +12 -2
  23. package/lib/export/modules/personalize.js +181 -46
  24. package/lib/export/modules/stack.js +83 -28
  25. package/lib/export/modules/taxonomies.d.ts +4 -9
  26. package/lib/export/modules/taxonomies.js +123 -75
  27. package/lib/export/modules/webhooks.js +40 -17
  28. package/lib/export/modules/workflows.js +57 -20
  29. package/lib/types/default-config.d.ts +0 -2
  30. package/lib/types/index.d.ts +1 -1
  31. package/lib/utils/common-helper.d.ts +1 -2
  32. package/lib/utils/common-helper.js +1 -12
  33. package/lib/utils/constants.d.ts +147 -0
  34. package/lib/utils/constants.js +160 -0
  35. package/lib/utils/export-config-handler.js +2 -0
  36. package/lib/utils/index.d.ts +1 -0
  37. package/lib/utils/index.js +6 -1
  38. package/lib/utils/marketplace-app-helper.d.ts +1 -0
  39. package/lib/utils/marketplace-app-helper.js +21 -12
  40. package/lib/utils/progress-strategy-registry.d.ts +7 -0
  41. package/lib/utils/progress-strategy-registry.js +98 -0
  42. package/messages/index.json +4 -2
  43. package/oclif.manifest.json +1 -1
  44. package/package.json +3 -3
  45. package/lib/export/modules-js/assets.d.ts +0 -43
  46. package/lib/export/modules-js/assets.js +0 -396
  47. package/lib/export/modules-js/content-types.d.ts +0 -21
  48. package/lib/export/modules-js/content-types.js +0 -76
  49. package/lib/export/modules-js/custom-roles.d.ts +0 -21
  50. package/lib/export/modules-js/custom-roles.js +0 -76
  51. package/lib/export/modules-js/entries.d.ts +0 -18
  52. package/lib/export/modules-js/entries.js +0 -143
  53. package/lib/export/modules-js/environments.d.ts +0 -16
  54. package/lib/export/modules-js/environments.js +0 -62
  55. package/lib/export/modules-js/extensions.d.ts +0 -18
  56. package/lib/export/modules-js/extensions.js +0 -57
  57. package/lib/export/modules-js/global-fields.d.ts +0 -22
  58. package/lib/export/modules-js/global-fields.js +0 -108
  59. package/lib/export/modules-js/index.d.ts +0 -2
  60. package/lib/export/modules-js/index.js +0 -31
  61. package/lib/export/modules-js/labels.d.ts +0 -14
  62. package/lib/export/modules-js/labels.js +0 -56
  63. package/lib/export/modules-js/locales.d.ts +0 -23
  64. package/lib/export/modules-js/locales.js +0 -68
  65. package/lib/export/modules-js/marketplace-apps.d.ts +0 -21
  66. package/lib/export/modules-js/marketplace-apps.js +0 -132
  67. package/lib/export/modules-js/stack.d.ts +0 -18
  68. package/lib/export/modules-js/stack.js +0 -91
  69. package/lib/export/modules-js/webhooks.d.ts +0 -18
  70. package/lib/export/modules-js/webhooks.js +0 -60
  71. package/lib/export/modules-js/workflows.d.ts +0 -16
  72. package/lib/export/modules-js/workflows.js +0 -89
@@ -12,43 +12,83 @@ class ExportStack extends base_class_1.default {
12
12
  this.stackConfig = exportConfig.modules.stack;
13
13
  this.qs = { include_count: true };
14
14
  this.stackFolderPath = (0, node_path_1.resolve)(this.exportConfig.data, this.exportConfig.branchName || '', this.stackConfig.dirName);
15
- this.exportConfig.context.module = 'stack';
15
+ this.exportConfig.context.module = utils_1.MODULE_CONTEXTS.STACK;
16
+ this.currentModuleName = utils_1.MODULE_NAMES[utils_1.MODULE_CONTEXTS.STACK];
16
17
  }
17
18
  async start() {
18
- cli_utilities_1.log.debug('Starting stack export process...', this.exportConfig.context);
19
- if ((0, cli_utilities_1.isAuthenticated)()) {
20
- cli_utilities_1.log.debug('User is authenticated, fetching stack data...', this.exportConfig.context);
21
- const stackData = await this.getStack();
19
+ try {
20
+ cli_utilities_1.log.debug('Starting stack export process...', this.exportConfig.context);
21
+ // Initial analysis with loading spinner
22
+ const [stackData] = await this.withLoadingSpinner('STACK: Analyzing stack configuration...', async () => {
23
+ const stackData = (0, cli_utilities_1.isAuthenticated)() ? await this.getStack() : null;
24
+ return [stackData];
25
+ });
26
+ // Create nested progress manager
27
+ const progress = this.createNestedProgress(this.currentModuleName);
28
+ // Add processes based on configuration
29
+ let processCount = 0;
22
30
  if (stackData === null || stackData === void 0 ? void 0 : stackData.org_uid) {
23
31
  cli_utilities_1.log.debug(`Found organization UID: ${stackData.org_uid}`, this.exportConfig.context);
24
32
  this.exportConfig.org_uid = stackData.org_uid;
25
33
  this.exportConfig.sourceStackName = stackData.name;
26
34
  cli_utilities_1.log.debug(`Set source stack name: ${stackData.name}`, this.exportConfig.context);
27
35
  }
36
+ if (!this.exportConfig.management_token) {
37
+ progress.addProcess(utils_1.PROCESS_NAMES.STACK_SETTINGS, 1);
38
+ processCount++;
39
+ }
40
+ if (!this.exportConfig.preserveStackVersion && !this.exportConfig.hasOwnProperty('master_locale')) {
41
+ progress.addProcess(utils_1.PROCESS_NAMES.STACK_LOCALE, 1);
42
+ processCount++;
43
+ }
44
+ else if (this.exportConfig.preserveStackVersion) {
45
+ progress.addProcess(utils_1.PROCESS_NAMES.STACK_DETAILS, 1);
46
+ processCount++;
47
+ }
48
+ // Execute processes
49
+ if (!this.exportConfig.management_token) {
50
+ progress
51
+ .startProcess(utils_1.PROCESS_NAMES.STACK_SETTINGS)
52
+ .updateStatus(utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.STACK_SETTINGS].EXPORTING, utils_1.PROCESS_NAMES.STACK_SETTINGS);
53
+ await this.exportStackSettings();
54
+ progress.completeProcess(utils_1.PROCESS_NAMES.STACK_SETTINGS, true);
55
+ }
28
56
  else {
29
- cli_utilities_1.log.debug('No stack data found or missing org_uid', this.exportConfig.context);
57
+ cli_utilities_1.log.info('Skipping stack settings export: Operation is not supported when using a management token.', this.exportConfig.context);
30
58
  }
59
+ if (!this.exportConfig.preserveStackVersion && !this.exportConfig.hasOwnProperty('master_locale')) {
60
+ progress
61
+ .startProcess(utils_1.PROCESS_NAMES.STACK_LOCALE)
62
+ .updateStatus(utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.STACK_LOCALE].FETCHING, utils_1.PROCESS_NAMES.STACK_LOCALE);
63
+ const masterLocale = await this.getLocales();
64
+ progress.completeProcess(utils_1.PROCESS_NAMES.STACK_LOCALE, true);
65
+ if (masterLocale === null || masterLocale === void 0 ? void 0 : masterLocale.code) {
66
+ this.exportConfig.master_locale = { code: masterLocale.code };
67
+ cli_utilities_1.log.debug(`Set master locale: ${masterLocale.code}`, this.exportConfig.context);
68
+ }
69
+ this.completeProgress(true);
70
+ return masterLocale;
71
+ }
72
+ else if (this.exportConfig.preserveStackVersion) {
73
+ progress
74
+ .startProcess(utils_1.PROCESS_NAMES.STACK_DETAILS)
75
+ .updateStatus(utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.STACK_DETAILS].EXPORTING, utils_1.PROCESS_NAMES.STACK_DETAILS);
76
+ const stackResult = await this.exportStack();
77
+ progress.completeProcess(utils_1.PROCESS_NAMES.STACK_DETAILS, true);
78
+ this.completeProgress(true);
79
+ return stackResult;
80
+ }
81
+ else {
82
+ cli_utilities_1.log.debug('Locale locale already set, skipping locale fetch', this.exportConfig.context);
83
+ }
84
+ this.completeProgress(true);
85
+ cli_utilities_1.log.success('Stack export completed successfully', this.exportConfig.context);
31
86
  }
32
- else {
33
- cli_utilities_1.log.debug('User is not authenticated, skipping stack data fetch', this.exportConfig.context);
34
- }
35
- if (this.exportConfig.management_token) {
36
- cli_utilities_1.log.info('Skipping stack settings export: Operation is not supported when using a management token.', this.exportConfig.context);
37
- }
38
- else {
39
- await this.exportStackSettings();
40
- }
41
- if (!this.exportConfig.preserveStackVersion && !this.exportConfig.hasOwnProperty('master_locale')) {
42
- cli_utilities_1.log.debug('Preserve stack version is false and master locale not set, fetching locales...', this.exportConfig.context);
43
- //fetch master locale details
44
- return this.getLocales();
45
- }
46
- else if (this.exportConfig.preserveStackVersion) {
47
- cli_utilities_1.log.debug('Preserve stack version is true, exporting stack...', this.exportConfig.context);
48
- return this.exportStack();
49
- }
50
- else {
51
- cli_utilities_1.log.debug('Master locale already set, skipping locale fetch', this.exportConfig.context);
87
+ catch (error) {
88
+ cli_utilities_1.log.debug('Error occurred during stack export', this.exportConfig.context);
89
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context));
90
+ this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Stack export failed');
91
+ throw error;
52
92
  }
53
93
  }
54
94
  async getStack() {
@@ -81,10 +121,13 @@ class ExportStack extends base_class_1.default {
81
121
  .query(this.qs)
82
122
  .find()
83
123
  .then(async (data) => {
124
+ var _a;
84
125
  const { items, count } = data;
85
126
  cli_utilities_1.log.debug(`Fetched ${(items === null || items === void 0 ? void 0 : items.length) || 0} locales out of total ${count}`, this.exportConfig.context);
86
127
  if (items === null || items === void 0 ? void 0 : items.length) {
87
128
  cli_utilities_1.log.debug(`Processing ${items.length} locales to find master locale`, this.exportConfig.context);
129
+ // Track progress for each locale processed
130
+ (_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(true, 'Fetch locale', null, utils_1.PROCESS_NAMES.STACK_LOCALE);
88
131
  skip += this.stackConfig.limit || 100;
89
132
  const masterLocalObj = (0, find_1.default)(items, (locale) => {
90
133
  if (locale.fallback_locale === null) {
@@ -97,12 +140,12 @@ class ExportStack extends base_class_1.default {
97
140
  return masterLocalObj;
98
141
  }
99
142
  else if (skip >= count) {
100
- cli_utilities_1.log.error(`Master locale not found in the stack ${this.exportConfig.source_stack}. Please ensure that the stack has a master locale.`, this.exportConfig.context);
143
+ cli_utilities_1.log.error(`Locale locale not found in the stack ${this.exportConfig.source_stack}. Please ensure that the stack has a master locale.`, this.exportConfig.context);
101
144
  cli_utilities_1.log.debug('Completed searching all locales without finding master locale', this.exportConfig.context);
102
145
  return;
103
146
  }
104
147
  else {
105
- cli_utilities_1.log.debug(`Master locale not found in current batch, continuing with skip: ${skip}`, this.exportConfig.context);
148
+ cli_utilities_1.log.debug(`Locale locale not found in current batch, continuing with skip: ${skip}`, this.exportConfig.context);
106
149
  return await this.getLocales(skip);
107
150
  }
108
151
  }
@@ -111,7 +154,9 @@ class ExportStack extends base_class_1.default {
111
154
  }
112
155
  })
113
156
  .catch((error) => {
157
+ var _a;
114
158
  cli_utilities_1.log.debug(`Error occurred while fetching locales for stack: ${this.exportConfig.source_stack}`, this.exportConfig.context);
159
+ (_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(false, 'locale fetch', (error === null || error === void 0 ? void 0 : error.message) || utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.STACK_LOCALE].FAILED, utils_1.PROCESS_NAMES.STACK_LOCALE);
115
160
  (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context), `Failed to fetch locales for stack ${this.exportConfig.source_stack}`);
116
161
  throw error;
117
162
  });
@@ -123,15 +168,20 @@ class ExportStack extends base_class_1.default {
123
168
  return this.stack
124
169
  .fetch()
125
170
  .then((resp) => {
171
+ var _a;
126
172
  const stackFilePath = (0, node_path_1.resolve)(this.stackFolderPath, this.stackConfig.fileName);
127
173
  cli_utilities_1.log.debug(`Writing stack data to: ${stackFilePath}`, this.exportConfig.context);
128
174
  utils_1.fsUtil.writeFile(stackFilePath, resp);
175
+ // Track progress for stack export completion
176
+ (_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(true, `stack: ${this.exportConfig.source_stack}`, null, utils_1.PROCESS_NAMES.STACK_DETAILS);
129
177
  cli_utilities_1.log.success(`Stack details exported successfully for stack ${this.exportConfig.source_stack}`, this.exportConfig.context);
130
178
  cli_utilities_1.log.debug('Stack export completed successfully', this.exportConfig.context);
131
179
  return resp;
132
180
  })
133
181
  .catch((error) => {
182
+ var _a;
134
183
  cli_utilities_1.log.debug(`Error occurred while exporting stack: ${this.exportConfig.source_stack}`, this.exportConfig.context);
184
+ (_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(false, 'stack export', (error === null || error === void 0 ? void 0 : error.message) || utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.STACK_DETAILS].FAILED, utils_1.PROCESS_NAMES.STACK_DETAILS);
135
185
  (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context));
136
186
  });
137
187
  }
@@ -141,11 +191,16 @@ class ExportStack extends base_class_1.default {
141
191
  return this.stack
142
192
  .settings()
143
193
  .then((resp) => {
194
+ var _a;
144
195
  utils_1.fsUtil.writeFile((0, node_path_1.resolve)(this.stackFolderPath, 'settings.json'), resp);
196
+ // Track progress for stack settings completion
197
+ (_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(true, 'stack settings', null, utils_1.PROCESS_NAMES.STACK_SETTINGS);
145
198
  cli_utilities_1.log.success('Exported stack settings successfully!', this.exportConfig.context);
146
199
  return resp;
147
200
  })
148
201
  .catch((error) => {
202
+ var _a;
203
+ (_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(false, 'stack settings', (error === null || error === void 0 ? void 0 : error.message) || utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.STACK_SETTINGS].FAILED, utils_1.PROCESS_NAMES.STACK_SETTINGS);
149
204
  (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context));
150
205
  });
151
206
  }
@@ -8,20 +8,15 @@ export default class ExportTaxonomies extends BaseClass {
8
8
  constructor({ exportConfig, stackAPIClient }: ModuleClassParams);
9
9
  start(): Promise<void>;
10
10
  /**
11
- * fetch all taxonomies in the provided stack
11
+ * Fetch in the provided stack
12
12
  * @param {number} skip
13
13
  * @returns {Promise<any>}
14
14
  */
15
15
  getAllTaxonomies(skip?: number): Promise<any>;
16
- /**
17
- * remove invalid keys and write data into taxonomies
18
- * @function sanitizeTaxonomiesAttribs
19
- * @param taxonomies
20
- */
21
- sanitizeTaxonomiesAttribs(taxonomies: Record<string, string>[]): void;
16
+ sanitizeTaxonomiesAttribs(taxonomies: Record<string, any>[]): void;
22
17
  /**
23
18
  * Export all taxonomies details using metadata(this.taxonomies) and write it into respective <taxonomy-uid>.json file
24
- * @returns {Promise<void>}
19
+ * @returns {Promise<any>}
25
20
  */
26
- exportTaxonomies(): Promise<void>;
21
+ exportTaxonomies(): Promise<any>;
27
22
  }
@@ -15,38 +15,73 @@ class ExportTaxonomies extends base_class_1.default {
15
15
  this.taxonomiesConfig = exportConfig.modules.taxonomies;
16
16
  this.qs = { include_count: true, limit: this.taxonomiesConfig.limit || 100, skip: 0 };
17
17
  this.applyQueryFilters(this.qs, 'taxonomies');
18
- this.exportConfig.context.module = 'taxonomies';
18
+ this.exportConfig.context.module = utils_1.MODULE_CONTEXTS.TAXONOMIES;
19
+ this.currentModuleName = utils_1.MODULE_NAMES[utils_1.MODULE_CONTEXTS.TAXONOMIES];
19
20
  }
20
21
  async start() {
21
- cli_utilities_1.log.debug('Starting taxonomies export process...', this.exportConfig.context);
22
- //create taxonomies folder
23
- this.taxonomiesFolderPath = (0, node_path_1.resolve)(this.exportConfig.data, this.exportConfig.branchName || '', this.taxonomiesConfig.dirName);
24
- cli_utilities_1.log.debug(`Taxonomies folder path: ${this.taxonomiesFolderPath}`, this.exportConfig.context);
25
- await utils_1.fsUtil.makeDirectory(this.taxonomiesFolderPath);
26
- cli_utilities_1.log.debug('Created taxonomies directory', this.exportConfig.context);
27
- //fetch all taxonomies and write into taxonomies folder
28
- cli_utilities_1.log.debug('Fetching all taxonomies...', this.exportConfig.context);
29
- await this.getAllTaxonomies();
30
- cli_utilities_1.log.debug(`Retrieved ${Object.keys(this.taxonomies).length} taxonomies`, this.exportConfig.context);
31
- if (this.taxonomies === undefined || (0, isEmpty_1.default)(this.taxonomies)) {
32
- cli_utilities_1.log.info(cli_utilities_1.messageHandler.parse('TAXONOMY_NOT_FOUND'), this.exportConfig.context);
33
- return;
22
+ var _a;
23
+ try {
24
+ cli_utilities_1.log.debug('Starting taxonomies export process...', this.exportConfig.context);
25
+ // Setup with loading spinner
26
+ const [totalCount] = await this.withLoadingSpinner('TAXONOMIES: Analyzing taxonomy structure...', async () => {
27
+ this.taxonomiesFolderPath = (0, node_path_1.resolve)(this.exportConfig.data, this.exportConfig.branchName || '', this.taxonomiesConfig.dirName);
28
+ await utils_1.fsUtil.makeDirectory(this.taxonomiesFolderPath);
29
+ // Get count first for progress tracking
30
+ const countResponse = await this.stack
31
+ .taxonomy()
32
+ .query(Object.assign(Object.assign({}, this.qs), { include_count: true, limit: 1 }))
33
+ .find();
34
+ return [countResponse.count || 0];
35
+ });
36
+ if (totalCount === 0) {
37
+ cli_utilities_1.log.info(cli_utilities_1.messageHandler.parse('TAXONOMY_NOT_FOUND'), this.exportConfig.context);
38
+ return;
39
+ }
40
+ // Create nested progress manager
41
+ const progress = this.createNestedProgress(this.currentModuleName);
42
+ // Add sub-processes
43
+ progress.addProcess(utils_1.PROCESS_NAMES.FETCH_TAXONOMIES, totalCount);
44
+ progress.addProcess(utils_1.PROCESS_NAMES.EXPORT_TAXONOMIES_TERMS, totalCount);
45
+ // Fetch taxonomies
46
+ progress
47
+ .startProcess(utils_1.PROCESS_NAMES.FETCH_TAXONOMIES)
48
+ .updateStatus(utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.FETCH_TAXONOMIES].FETCHING, utils_1.PROCESS_NAMES.FETCH_TAXONOMIES);
49
+ await this.getAllTaxonomies();
50
+ progress.completeProcess(utils_1.PROCESS_NAMES.FETCH_TAXONOMIES, true);
51
+ const actualTaxonomyCount = (_a = Object.keys(this.taxonomies || {})) === null || _a === void 0 ? void 0 : _a.length;
52
+ cli_utilities_1.log.debug(`Found ${actualTaxonomyCount} taxonomies to export (API reported ${totalCount})`, this.exportConfig.context);
53
+ // Update progress for export step if counts differ
54
+ if (actualTaxonomyCount !== totalCount && actualTaxonomyCount > 0) {
55
+ // Remove the old process and add with correct count
56
+ progress.addProcess(utils_1.PROCESS_NAMES.EXPORT_TAXONOMIES_TERMS, actualTaxonomyCount);
57
+ }
58
+ // Export detailed taxonomies
59
+ if (actualTaxonomyCount > 0) {
60
+ progress
61
+ .startProcess(utils_1.PROCESS_NAMES.EXPORT_TAXONOMIES_TERMS)
62
+ .updateStatus(utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.EXPORT_TAXONOMIES_TERMS].EXPORTING, utils_1.PROCESS_NAMES.EXPORT_TAXONOMIES_TERMS);
63
+ await this.exportTaxonomies();
64
+ progress.completeProcess(utils_1.PROCESS_NAMES.EXPORT_TAXONOMIES_TERMS, true);
65
+ }
66
+ else {
67
+ cli_utilities_1.log.info('No taxonomies found to export detailed information', this.exportConfig.context);
68
+ }
69
+ const taxonomyCount = Object.keys(this.taxonomies || {}).length;
70
+ cli_utilities_1.log.success(cli_utilities_1.messageHandler.parse('TAXONOMY_EXPORT_COMPLETE', taxonomyCount), this.exportConfig.context);
71
+ this.completeProgress(true);
34
72
  }
35
- else {
36
- const taxonomiesFilePath = (0, node_path_1.resolve)(this.taxonomiesFolderPath, 'taxonomies.json');
37
- cli_utilities_1.log.debug(`Writing taxonomies metadata to: ${taxonomiesFilePath}`, this.exportConfig.context);
38
- utils_1.fsUtil.writeFile(taxonomiesFilePath, this.taxonomies);
39
- cli_utilities_1.log.debug('Starting detailed taxonomy export...', this.exportConfig.context);
40
- await this.exportTaxonomies();
73
+ catch (error) {
74
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context));
75
+ this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Taxonomies export failed');
41
76
  }
42
- cli_utilities_1.log.success(cli_utilities_1.messageHandler.parse('TAXONOMY_EXPORT_COMPLETE', (0, keys_1.default)(this.taxonomies).length), this.exportConfig.context);
43
77
  }
44
78
  /**
45
- * fetch all taxonomies in the provided stack
79
+ * Fetch in the provided stack
46
80
  * @param {number} skip
47
81
  * @returns {Promise<any>}
48
82
  */
49
83
  async getAllTaxonomies(skip = 0) {
84
+ var _a, _b;
50
85
  if (skip) {
51
86
  this.qs.skip = skip;
52
87
  cli_utilities_1.log.debug(`Fetching taxonomies with skip: ${skip}`, this.exportConfig.context);
@@ -55,78 +90,91 @@ class ExportTaxonomies extends base_class_1.default {
55
90
  cli_utilities_1.log.debug('Fetching taxonomies with initial query', this.exportConfig.context);
56
91
  }
57
92
  cli_utilities_1.log.debug(`Query parameters: ${JSON.stringify(this.qs)}`, this.exportConfig.context);
58
- await this.stack
59
- .taxonomy()
60
- .query(this.qs)
61
- .find()
62
- .then(async (data) => {
63
- const { items, count } = data;
64
- const taxonomiesCount = count !== undefined ? count : items === null || items === void 0 ? void 0 : items.length;
65
- cli_utilities_1.log.debug(`Fetched ${(items === null || items === void 0 ? void 0 : items.length) || 0} taxonomies out of total ${taxonomiesCount}`, this.exportConfig.context);
66
- if (items === null || items === void 0 ? void 0 : items.length) {
67
- cli_utilities_1.log.debug(`Processing ${items.length} taxonomies`, this.exportConfig.context);
68
- this.sanitizeTaxonomiesAttribs(items);
69
- skip += this.qs.limit || 100;
70
- if (skip >= taxonomiesCount) {
71
- cli_utilities_1.log.debug('Completed fetching all taxonomies', this.exportConfig.context);
72
- return;
73
- }
74
- cli_utilities_1.log.debug(`Continuing to fetch taxonomies with skip: ${skip}`, this.exportConfig.context);
75
- return await this.getAllTaxonomies(skip);
76
- }
77
- else {
78
- cli_utilities_1.log.debug('No taxonomies found to process', this.exportConfig.context);
93
+ let taxonomyResult = await this.stack.taxonomy().query(this.qs).find();
94
+ cli_utilities_1.log.debug(`Fetched ${((_a = taxonomyResult.items) === null || _a === void 0 ? void 0 : _a.length) || 0} taxonomies out of total ${taxonomyResult.count}`, this.exportConfig.context);
95
+ if ((taxonomyResult === null || taxonomyResult === void 0 ? void 0 : taxonomyResult.items) && ((_b = taxonomyResult === null || taxonomyResult === void 0 ? void 0 : taxonomyResult.items) === null || _b === void 0 ? void 0 : _b.length) > 0) {
96
+ cli_utilities_1.log.debug(`Processing ${taxonomyResult.items.length} taxonomies`, this.exportConfig.context);
97
+ this.sanitizeTaxonomiesAttribs(taxonomyResult.items);
98
+ skip += this.taxonomiesConfig.limit;
99
+ if (skip >= taxonomyResult.count) {
100
+ cli_utilities_1.log.debug('Completed fetching all taxonomies', this.exportConfig.context);
101
+ return;
79
102
  }
80
- })
81
- .catch((error) => {
82
- cli_utilities_1.log.debug('Error occurred while fetching taxonomies', this.exportConfig.context);
83
- (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context));
84
- });
103
+ cli_utilities_1.log.debug(`Continuing to fetch taxonomies with skip: ${skip}`, this.exportConfig.context);
104
+ return await this.getAllTaxonomies(skip);
105
+ }
106
+ else {
107
+ cli_utilities_1.log.info(cli_utilities_1.messageHandler.parse('TAXONOMY_NOT_FOUND'), this.exportConfig.context);
108
+ }
85
109
  }
86
- /**
87
- * remove invalid keys and write data into taxonomies
88
- * @function sanitizeTaxonomiesAttribs
89
- * @param taxonomies
90
- */
91
110
  sanitizeTaxonomiesAttribs(taxonomies) {
92
111
  var _a;
93
112
  cli_utilities_1.log.debug(`Sanitizing ${taxonomies.length} taxonomies`, this.exportConfig.context);
94
113
  for (let index = 0; index < (taxonomies === null || taxonomies === void 0 ? void 0 : taxonomies.length); index++) {
95
- const taxonomyUID = taxonomies[index].uid;
96
- const taxonomyName = (_a = taxonomies[index]) === null || _a === void 0 ? void 0 : _a.name;
97
- cli_utilities_1.log.debug(`Processing taxonomy: ${taxonomyName} (${taxonomyUID})`, this.exportConfig.context);
98
- this.taxonomies[taxonomyUID] = (0, omit_1.default)(taxonomies[index], this.taxonomiesConfig.invalidKeys);
114
+ const taxonomy = taxonomies[index];
115
+ const taxonomyUid = taxonomy.uid;
116
+ const taxonomyName = taxonomy === null || taxonomy === void 0 ? void 0 : taxonomy.name;
117
+ cli_utilities_1.log.debug(`Processing taxonomy: ${taxonomyName} (${taxonomyUid})`, this.exportConfig.context);
118
+ if (this.taxonomiesConfig.invalidKeys && this.taxonomiesConfig.invalidKeys.length > 0) {
119
+ this.taxonomies[taxonomyUid] = (0, omit_1.default)(taxonomy, this.taxonomiesConfig.invalidKeys);
120
+ }
121
+ else {
122
+ this.taxonomies[taxonomyUid] = taxonomy;
123
+ }
124
+ // Track progress for each taxonomy
125
+ (_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(true, `taxonomy: ${taxonomyName || taxonomyUid}`, null, utils_1.PROCESS_NAMES.FETCH_TAXONOMIES);
99
126
  }
100
- cli_utilities_1.log.debug(`Sanitization complete. Total taxonomies processed: ${Object.keys(this.taxonomies).length}`, this.exportConfig.context);
127
+ cli_utilities_1.log.debug(`Sanitization complete. Total taxonomies processed: ${Object.keys(this.taxonomies || {}).length}`, this.exportConfig.context);
101
128
  }
102
129
  /**
103
130
  * Export all taxonomies details using metadata(this.taxonomies) and write it into respective <taxonomy-uid>.json file
104
- * @returns {Promise<void>}
131
+ * @returns {Promise<any>}
105
132
  */
106
133
  async exportTaxonomies() {
107
- const taxonomiesUID = (0, keys_1.default)(this.taxonomies) || [];
108
- cli_utilities_1.log.debug(`Exporting detailed data for ${taxonomiesUID.length} taxonomies`, this.exportConfig.context);
134
+ var _a;
135
+ cli_utilities_1.log.debug(`Exporting ${(_a = Object.keys(this.taxonomies || {})) === null || _a === void 0 ? void 0 : _a.length} taxonomies with detailed information`, this.exportConfig.context);
136
+ if ((0, isEmpty_1.default)(this.taxonomies)) {
137
+ cli_utilities_1.log.info(cli_utilities_1.messageHandler.parse('TAXONOMY_NOT_FOUND'), this.exportConfig.context);
138
+ return;
139
+ }
109
140
  const onSuccess = ({ response, uid }) => {
141
+ var _a, _b;
142
+ const taxonomyName = (_a = this.taxonomies[uid]) === null || _a === void 0 ? void 0 : _a.name;
110
143
  const filePath = (0, node_path_1.resolve)(this.taxonomiesFolderPath, `${uid}.json`);
111
- cli_utilities_1.log.debug(`Writing detailed taxonomy data to: ${filePath}`, this.exportConfig.context);
144
+ cli_utilities_1.log.debug(`Writing detailed taxonomy to: ${filePath}`, this.exportConfig.context);
112
145
  utils_1.fsUtil.writeFile(filePath, response);
113
- cli_utilities_1.log.success(cli_utilities_1.messageHandler.parse('TAXONOMY_EXPORT_SUCCESS', uid), this.exportConfig.context);
146
+ // Track progress for each exported taxonomy
147
+ (_b = this.progressManager) === null || _b === void 0 ? void 0 : _b.tick(true, `taxonomy: ${taxonomyName || uid}`, null, utils_1.PROCESS_NAMES.EXPORT_TAXONOMIES_TERMS);
148
+ cli_utilities_1.log.success(cli_utilities_1.messageHandler.parse('TAXONOMY_EXPORT_SUCCESS', taxonomyName || uid), this.exportConfig.context);
114
149
  };
115
150
  const onReject = ({ error, uid }) => {
116
- cli_utilities_1.log.debug(`Failed to export detailed data for taxonomy: ${uid}`, this.exportConfig.context);
117
- (0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.exportConfig.context), { uid }));
151
+ var _a, _b;
152
+ const taxonomyName = (_a = this.taxonomies[uid]) === null || _a === void 0 ? void 0 : _a.name;
153
+ // Track failure
154
+ (_b = this.progressManager) === null || _b === void 0 ? void 0 : _b.tick(false, `taxonomy: ${taxonomyName || uid}`, (error === null || error === void 0 ? void 0 : error.message) || utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.EXPORT_TAXONOMIES_TERMS].FAILED, utils_1.PROCESS_NAMES.EXPORT_TAXONOMIES_TERMS);
155
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.exportConfig.context), { uid }), cli_utilities_1.messageHandler.parse('TAXONOMY_EXPORT_FAILED', taxonomyName || uid));
118
156
  };
119
- for (let index = 0; index < (taxonomiesUID === null || taxonomiesUID === void 0 ? void 0 : taxonomiesUID.length); index++) {
120
- const taxonomyUID = taxonomiesUID[index];
121
- cli_utilities_1.log.debug(`Processing detailed export for taxonomy: ${taxonomyUID}`, this.exportConfig.context);
122
- await this.makeAPICall({
123
- reject: onReject,
124
- resolve: onSuccess,
125
- uid: taxonomyUID,
126
- module: 'export-taxonomy',
127
- });
157
+ const taxonomyUids = (0, keys_1.default)(this.taxonomies);
158
+ cli_utilities_1.log.debug(`Starting detailed export for ${taxonomyUids.length} taxonomies`, this.exportConfig.context);
159
+ // Export each taxonomy individually
160
+ for (const uid of taxonomyUids) {
161
+ try {
162
+ cli_utilities_1.log.debug(`Exporting detailed taxonomy: ${uid}`, this.exportConfig.context);
163
+ await this.makeAPICall({
164
+ module: 'export-taxonomy',
165
+ uid,
166
+ resolve: onSuccess,
167
+ reject: onReject,
168
+ });
169
+ }
170
+ catch (error) {
171
+ onReject({ error, uid });
172
+ }
128
173
  }
129
- cli_utilities_1.log.debug('Completed detailed taxonomy export process', this.exportConfig.context);
174
+ // Write the taxonomies index file
175
+ const taxonomiesFilePath = (0, node_path_1.resolve)(this.taxonomiesFolderPath, this.taxonomiesConfig.fileName);
176
+ cli_utilities_1.log.debug(`Writing taxonomies index to: ${taxonomiesFilePath}`, this.exportConfig.context);
177
+ utils_1.fsUtil.writeFile(taxonomiesFilePath, this.taxonomies);
130
178
  }
131
179
  }
132
180
  exports.default = ExportTaxonomies;
@@ -13,24 +13,43 @@ class ExportWebhooks extends base_class_1.default {
13
13
  this.webhooks = {};
14
14
  this.webhookConfig = exportConfig.modules.webhooks;
15
15
  this.qs = { include_count: true, asc: 'updated_at' };
16
- this.exportConfig.context.module = 'webhooks';
16
+ this.exportConfig.context.module = utils_1.MODULE_CONTEXTS.WEBHOOKS;
17
+ this.currentModuleName = utils_1.MODULE_NAMES[utils_1.MODULE_CONTEXTS.WEBHOOKS];
17
18
  }
18
19
  async start() {
19
- cli_utilities_1.log.debug('Starting webhooks export process...', this.exportConfig.context);
20
- this.webhooksFolderPath = (0, node_path_1.resolve)(this.exportConfig.data, this.exportConfig.branchName || '', this.webhookConfig.dirName);
21
- cli_utilities_1.log.debug(`Webhooks folder path: ${this.webhooksFolderPath}`, this.exportConfig.context);
22
- await utils_1.fsUtil.makeDirectory(this.webhooksFolderPath);
23
- cli_utilities_1.log.debug('Created webhooks directory', this.exportConfig.context);
24
- await this.getWebhooks();
25
- cli_utilities_1.log.debug(`Retrieved ${Object.keys(this.webhooks).length} webhooks`, this.exportConfig.context);
26
- if (this.webhooks === undefined || (0, isEmpty_1.default)(this.webhooks)) {
27
- cli_utilities_1.log.info(cli_utilities_1.messageHandler.parse('WEBHOOK_NOT_FOUND'), this.exportConfig.context);
20
+ try {
21
+ cli_utilities_1.log.debug('Starting webhooks export process...', this.exportConfig.context);
22
+ // Setup with loading spinner
23
+ const [totalCount] = await this.withLoadingSpinner('WEBHOOKS: Analyzing webhooks...', async () => {
24
+ this.webhooksFolderPath = (0, node_path_1.resolve)(this.exportConfig.data, this.exportConfig.branchName || '', this.webhookConfig.dirName);
25
+ await utils_1.fsUtil.makeDirectory(this.webhooksFolderPath);
26
+ // Get count for progress tracking
27
+ const countResponse = await this.stack.webhook().fetchAll(Object.assign(Object.assign({}, this.qs), { limit: 1 }));
28
+ return [countResponse.count || 0];
29
+ });
30
+ if (totalCount === 0) {
31
+ cli_utilities_1.log.info(cli_utilities_1.messageHandler.parse('WEBHOOK_NOT_FOUND'), this.exportConfig.context);
32
+ return;
33
+ }
34
+ // Create simple progress manager with total count
35
+ const progress = this.createSimpleProgress(this.currentModuleName, totalCount);
36
+ progress.updateStatus('Fetching webhooks...');
37
+ await this.getWebhooks();
38
+ cli_utilities_1.log.debug(`Retrieved ${Object.keys(this.webhooks || {}).length} webhooks`, this.exportConfig.context);
39
+ if (this.webhooks === undefined || (0, isEmpty_1.default)(this.webhooks)) {
40
+ cli_utilities_1.log.info(cli_utilities_1.messageHandler.parse('WEBHOOK_NOT_FOUND'), this.exportConfig.context);
41
+ }
42
+ else {
43
+ const webhooksFilePath = (0, node_path_1.resolve)(this.webhooksFolderPath, this.webhookConfig.fileName);
44
+ cli_utilities_1.log.debug(`Writing webhooks to: ${webhooksFilePath}`, this.exportConfig.context);
45
+ utils_1.fsUtil.writeFile(webhooksFilePath, this.webhooks);
46
+ cli_utilities_1.log.success(cli_utilities_1.messageHandler.parse('WEBHOOK_EXPORT_COMPLETE', Object.keys(this.webhooks || {}).length), this.exportConfig.context);
47
+ }
48
+ this.completeProgress(true);
28
49
  }
29
- else {
30
- const webhooksFilePath = (0, node_path_1.resolve)(this.webhooksFolderPath, this.webhookConfig.fileName);
31
- cli_utilities_1.log.debug(`Writing webhooks to: ${webhooksFilePath}`, this.exportConfig.context);
32
- utils_1.fsUtil.writeFile(webhooksFilePath, this.webhooks);
33
- cli_utilities_1.log.success(cli_utilities_1.messageHandler.parse('WEBHOOK_EXPORT_COMPLETE', Object.keys(this.webhooks).length), this.exportConfig.context);
50
+ catch (error) {
51
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context));
52
+ this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Webhooks export failed');
34
53
  }
35
54
  }
36
55
  async getWebhooks(skip = 0) {
@@ -64,12 +83,14 @@ class ExportWebhooks extends base_class_1.default {
64
83
  }
65
84
  })
66
85
  .catch((error) => {
86
+ var _a;
87
+ (_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(false, 'webhooks', (error === null || error === void 0 ? void 0 : error.message) || 'Failed to export webhooks');
67
88
  cli_utilities_1.log.debug('Error occurred while fetching webhooks', this.exportConfig.context);
68
89
  (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context));
69
90
  });
70
91
  }
71
92
  sanitizeAttribs(webhooks) {
72
- var _a;
93
+ var _a, _b;
73
94
  cli_utilities_1.log.debug(`Sanitizing ${webhooks.length} webhooks`, this.exportConfig.context);
74
95
  for (let index = 0; index < (webhooks === null || webhooks === void 0 ? void 0 : webhooks.length); index++) {
75
96
  const webhookUid = webhooks[index].uid;
@@ -77,8 +98,10 @@ class ExportWebhooks extends base_class_1.default {
77
98
  cli_utilities_1.log.debug(`Processing webhook: ${webhookName} (${webhookUid})`, this.exportConfig.context);
78
99
  this.webhooks[webhookUid] = (0, omit_1.default)(webhooks[index], ['SYS_ACL']);
79
100
  cli_utilities_1.log.success(cli_utilities_1.messageHandler.parse('WEBHOOK_EXPORT_SUCCESS', webhookName), this.exportConfig.context);
101
+ // Track progress for each webhook
102
+ (_b = this.progressManager) === null || _b === void 0 ? void 0 : _b.tick(true, `webhook: ${webhookName}`);
80
103
  }
81
- cli_utilities_1.log.debug(`Sanitization complete. Total webhooks processed: ${Object.keys(this.webhooks).length}`, this.exportConfig.context);
104
+ cli_utilities_1.log.debug(`Sanitization complete. Total webhooks processed: ${Object.keys(this.webhooks || {}).length}`, this.exportConfig.context);
82
105
  }
83
106
  }
84
107
  exports.default = ExportWebhooks;