@contentstack/cli-cm-export 2.0.0-beta.2 → 2.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -48,7 +48,7 @@ $ npm install -g @contentstack/cli-cm-export
48
48
  $ csdx COMMAND
49
49
  running command...
50
50
  $ csdx (--version)
51
- @contentstack/cli-cm-export/2.0.0-beta.2 linux-x64 node-v22.21.1
51
+ @contentstack/cli-cm-export/2.0.0-beta.4 linux-x64 node-v22.21.1
52
52
  $ csdx --help [COMMAND]
53
53
  USAGE
54
54
  $ csdx COMMAND
@@ -59,93 +59,39 @@ USAGE
59
59
  # Commands
60
60
 
61
61
  <!-- commands -->
62
- * [`csdx cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]`](#csdx-cmstacksexport--c-value--k-value--d-value--a-value---module-value---content-types-value---branch-value---secured-assets)
63
- * [`csdx cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]`](#csdx-cmstacksexport--c-value--k-value--d-value--a-value---module-value---content-types-value---branch-value---secured-assets)
62
+ * [`csdx cm:stacks:export [--config <value>] [--stack-api-key <value>] [--data-dir <value>] [--alias <value>] [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]`](#csdx-cmstacksexport---config-value---stack-api-key-value---data-dir-value---alias-value---module-value---content-types-value---branch-value---secured-assets)
64
63
 
65
- ## `csdx cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]`
64
+ ## `csdx cm:stacks:export [--config <value>] [--stack-api-key <value>] [--data-dir <value>] [--alias <value>] [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]`
66
65
 
67
66
  Export content from a stack
68
67
 
69
68
  ```
70
69
  USAGE
71
- $ csdx cm:export cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>]
72
- [--content-types <value>] [--branch <value>] [--secured-assets]
70
+ $ csdx cm:stacks:export [--config <value>] [--stack-api-key <value>] [--data-dir <value>] [--alias <value>]
71
+ [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]
73
72
 
74
73
  FLAGS
75
- -B, --branch=<value> [optional] The name of the branch where you want to export your content. If you don't
76
- mention the branch name, then by default the content will be exported from all the
77
- branches of your stack.
78
74
  -a, --alias=<value> The management token alias of the source stack from which you will export content.
79
75
  -c, --config=<value> [optional] Path of the config
80
76
  -d, --data-dir=<value> The path or the location in your file system to store the exported content. For e.g.,
81
77
  ./content
82
78
  -k, --stack-api-key=<value> API Key of the source stack
83
- -m, --module=<value> [optional] Specific module name. If not specified, the export command will export all
84
- the modules to the stack. The available modules are assets, content-types, entries,
85
- environments, extensions, marketplace-apps, global-fields, labels, locales, webhooks,
86
- workflows, custom-roles, and taxonomies.
87
- -t, --content-types=<value>... [optional] The UID of the content type(s) whose content you want to export. In case
88
- of multiple content types, specify the IDs separated by spaces.
89
79
  -y, --yes [optional] Force override all Marketplace prompts.
90
- --branch-alias=<value> (Optional) The alias of the branch from which you want to export content.
91
- --secured-assets [optional] Use this flag for assets that are secured.
92
-
93
- DESCRIPTION
94
- Export content from a stack
95
-
96
- ALIASES
97
- $ csdx cm:export
98
-
99
- EXAMPLES
100
- $ csdx cm:stacks:export --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>
101
-
102
- $ csdx cm:stacks:export --config <path/to/config/dir>
103
-
104
- $ csdx cm:stacks:export --alias <management_token_alias>
105
-
106
- $ csdx cm:stacks:export --alias <management_token_alias> --data-dir <path/to/export/destination/dir>
107
-
108
- $ csdx cm:stacks:export --alias <management_token_alias> --config <path/to/config/file>
109
-
110
- $ csdx cm:stacks:export --module <single module name>
111
-
112
- $ csdx cm:stacks:export --branch [optional] branch name
113
- ```
114
-
115
- ## `csdx cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]`
116
-
117
- Export content from a stack
118
-
119
- ```
120
- USAGE
121
- $ csdx cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--content-types
122
- <value>] [--branch <value>] [--secured-assets]
123
-
124
- FLAGS
125
- -B, --branch=<value> [optional] The name of the branch where you want to export your content. If you don't
80
+ --branch=<value> [optional] The name of the branch where you want to export your content. If you don't
126
81
  mention the branch name, then by default the content will be exported from all the
127
82
  branches of your stack.
128
- -a, --alias=<value> The management token alias of the source stack from which you will export content.
129
- -c, --config=<value> [optional] Path of the config
130
- -d, --data-dir=<value> The path or the location in your file system to store the exported content. For e.g.,
131
- ./content
132
- -k, --stack-api-key=<value> API Key of the source stack
133
- -m, --module=<value> [optional] Specific module name. If not specified, the export command will export all
83
+ --branch-alias=<value> (Optional) The alias of the branch from which you want to export content.
84
+ --content-types=<value>... [optional] The UID of the content type(s) whose content you want to export. In case
85
+ of multiple content types, specify the IDs separated by spaces.
86
+ --module=<value> [optional] Specific module name. If not specified, the export command will export all
134
87
  the modules to the stack. The available modules are assets, content-types, entries,
135
88
  environments, extensions, marketplace-apps, global-fields, labels, locales, webhooks,
136
- workflows, custom-roles, and taxonomies.
137
- -t, --content-types=<value>... [optional] The UID of the content type(s) whose content you want to export. In case
138
- of multiple content types, specify the IDs separated by spaces.
139
- -y, --yes [optional] Force override all Marketplace prompts.
140
- --branch-alias=<value> (Optional) The alias of the branch from which you want to export content.
89
+ workflows, custom-roles, taxonomies, and studio.
141
90
  --secured-assets [optional] Use this flag for assets that are secured.
142
91
 
143
92
  DESCRIPTION
144
93
  Export content from a stack
145
94
 
146
- ALIASES
147
- $ csdx cm:export
148
-
149
95
  EXAMPLES
150
96
  $ csdx cm:stacks:export --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>
151
97
 
@@ -5,7 +5,6 @@ export default class ExportCommand extends Command {
5
5
  static examples: string[];
6
6
  static usage: string;
7
7
  static flags: FlagInput;
8
- static aliases: string[];
9
8
  run(): Promise<void>;
10
9
  private createExportContext;
11
10
  private assignExportConfig;
@@ -14,7 +14,6 @@ class ExportCommand extends cli_command_1.Command {
14
14
  // Prepare the context object
15
15
  const context = this.createExportContext(exportConfig.apiKey, exportConfig.authenticationMethod);
16
16
  exportConfig.context = Object.assign({}, context);
17
- //log.info(`Using Cli Version: ${this.context?.cliVersion}`, exportConfig.context);
18
17
  // Assign exportConfig variables
19
18
  this.assignExportConfig(exportConfig);
20
19
  exportDir = (0, cli_utilities_1.sanitizePath)(exportConfig.cliLogsPath || exportConfig.data || exportConfig.exportDir);
@@ -67,6 +66,9 @@ class ExportCommand extends cli_command_1.Command {
67
66
  if (this.personalizeUrl) {
68
67
  exportConfig.modules.personalize.baseURL[exportConfig.region.name] = this.personalizeUrl;
69
68
  }
69
+ if (this.composableStudioUrl) {
70
+ exportConfig.modules['composable-studio'].apiBaseUrl = this.composableStudioUrl;
71
+ }
70
72
  }
71
73
  }
72
74
  exports.default = ExportCommand;
@@ -80,27 +82,16 @@ ExportCommand.examples = [
80
82
  'csdx cm:stacks:export --module <single module name>',
81
83
  'csdx cm:stacks:export --branch [optional] branch name',
82
84
  ];
83
- ExportCommand.usage = 'cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]';
85
+ ExportCommand.usage = 'cm:stacks:export [--config <value>] [--stack-api-key <value>] [--data-dir <value>] [--alias <value>] [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]';
84
86
  ExportCommand.flags = {
85
87
  config: cli_utilities_1.flags.string({
86
88
  char: 'c',
87
89
  description: '[optional] Path of the config',
88
90
  }),
89
- 'stack-uid': cli_utilities_1.flags.string({
90
- char: 's',
91
- description: 'API key of the source stack',
92
- hidden: true,
93
- parse: (0, cli_utilities_1.printFlagDeprecation)(['-s', '--stack-uid'], ['-k', '--stack-api-key']),
94
- }),
95
91
  'stack-api-key': cli_utilities_1.flags.string({
96
92
  char: 'k',
97
93
  description: 'API Key of the source stack',
98
94
  }),
99
- data: cli_utilities_1.flags.string({
100
- description: 'path or location to store the data',
101
- hidden: true,
102
- parse: (0, cli_utilities_1.printFlagDeprecation)(['--data'], ['--data-dir']),
103
- }),
104
95
  'data-dir': cli_utilities_1.flags.string({
105
96
  char: 'd',
106
97
  description: 'The path or the location in your file system to store the exported content. For e.g., ./content',
@@ -109,33 +100,16 @@ ExportCommand.flags = {
109
100
  char: 'a',
110
101
  description: 'The management token alias of the source stack from which you will export content.',
111
102
  }),
112
- 'management-token-alias': cli_utilities_1.flags.string({
113
- description: 'alias of the management token',
114
- hidden: true,
115
- parse: (0, cli_utilities_1.printFlagDeprecation)(['--management-token-alias'], ['-a', '--alias']),
116
- }),
117
- 'auth-token': cli_utilities_1.flags.boolean({
118
- char: 'A',
119
- description: 'to use auth token',
120
- hidden: true,
121
- parse: (0, cli_utilities_1.printFlagDeprecation)(['-A', '--auth-token']),
122
- }),
123
103
  module: cli_utilities_1.flags.string({
124
- char: 'm',
125
- description: '[optional] Specific module name. If not specified, the export command will export all the modules to the stack. The available modules are assets, content-types, entries, environments, extensions, marketplace-apps, global-fields, labels, locales, webhooks, workflows, custom-roles, and taxonomies.',
126
- parse: (0, cli_utilities_1.printFlagDeprecation)(['-m'], ['--module']),
104
+ description: '[optional] Specific module name. If not specified, the export command will export all the modules to the stack. The available modules are assets, content-types, entries, environments, extensions, marketplace-apps, global-fields, labels, locales, webhooks, workflows, custom-roles, taxonomies, and studio.',
127
105
  }),
128
106
  'content-types': cli_utilities_1.flags.string({
129
- char: 't',
130
107
  description: '[optional] The UID of the content type(s) whose content you want to export. In case of multiple content types, specify the IDs separated by spaces.',
131
108
  multiple: true,
132
- parse: (0, cli_utilities_1.printFlagDeprecation)(['-t'], ['--content-types']),
133
109
  }),
134
110
  branch: cli_utilities_1.flags.string({
135
- char: 'B',
136
111
  // default: 'main',
137
112
  description: "[optional] The name of the branch where you want to export your content. If you don't mention the branch name, then by default the content will be exported from all the branches of your stack.",
138
- parse: (0, cli_utilities_1.printFlagDeprecation)(['-B'], ['--branch']),
139
113
  exclusive: ['branch-alias'],
140
114
  }),
141
115
  'branch-alias': cli_utilities_1.flags.string({
@@ -155,4 +129,3 @@ ExportCommand.flags = {
155
129
  hidden: true,
156
130
  }),
157
131
  };
158
- ExportCommand.aliases = ['cm:export'];
@@ -39,6 +39,7 @@ const config = {
39
39
  'entries',
40
40
  'labels',
41
41
  'marketplace-apps',
42
+ 'composable-studio',
42
43
  ],
43
44
  locales: {
44
45
  dirName: 'locales',
@@ -212,6 +213,12 @@ const config = {
212
213
  dirName: 'marketplace_apps',
213
214
  fileName: 'marketplace_apps.json',
214
215
  },
216
+ 'composable-studio': {
217
+ dirName: 'composable_studio',
218
+ fileName: 'composable_studio.json',
219
+ apiBaseUrl: 'https://composable-studio-api.contentstack.com',
220
+ apiVersion: 'v1',
221
+ },
215
222
  taxonomies: {
216
223
  dirName: 'taxonomies',
217
224
  fileName: 'taxonomies.json',
@@ -77,7 +77,7 @@ class ModuleExporter {
77
77
  return this.exportAllModules();
78
78
  }
79
79
  async exportByModuleByName(moduleName) {
80
- cli_utilities_1.log.info(`Exporting module: ${moduleName}`, this.exportConfig.context);
80
+ cli_utilities_1.log.info(`Exporting module: '${moduleName}'...`, this.exportConfig.context);
81
81
  // export the modules by name
82
82
  // calls the module runner which inturn calls the module itself
83
83
  await (0, modules_1.default)({
@@ -93,7 +93,8 @@ class ModuleExporter {
93
93
  exportModules.push('stack');
94
94
  }
95
95
  if (!this.exportConfig.skipDependencies) {
96
- const { modules: { [moduleName]: { dependencies = [] } = {} }, } = this.exportConfig;
96
+ const moduleConfig = this.exportConfig.modules[moduleName];
97
+ const dependencies = (moduleConfig === null || moduleConfig === void 0 ? void 0 : moduleConfig.dependencies) || [];
97
98
  if (dependencies.length > 0) {
98
99
  exportModules = exportModules.concat(dependencies);
99
100
  }
@@ -0,0 +1,15 @@
1
+ import { HttpClient } from '@contentstack/cli-utilities';
2
+ import { ModuleClassParams, ComposableStudioConfig, ExportConfig, ComposableStudioProject } from '../../types';
3
+ export default class ExportComposableStudio {
4
+ protected composableStudioConfig: ComposableStudioConfig;
5
+ protected composableStudioProject: ComposableStudioProject | null;
6
+ protected apiClient: HttpClient;
7
+ composableStudioPath: string;
8
+ exportConfig: ExportConfig;
9
+ constructor({ exportConfig }: Omit<ModuleClassParams, 'stackAPIClient' | 'moduleName'>);
10
+ start(): Promise<void>;
11
+ /**
12
+ * Export Studio projects connected to the current stack
13
+ */
14
+ exportProjects(): Promise<void>;
15
+ }
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const node_path_1 = require("node:path");
4
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
5
+ const utils_1 = require("../../utils");
6
+ class ExportComposableStudio {
7
+ constructor({ exportConfig }) {
8
+ this.composableStudioProject = null;
9
+ this.exportConfig = exportConfig;
10
+ this.composableStudioConfig = exportConfig.modules['composable-studio'];
11
+ this.exportConfig.context.module = 'composable-studio';
12
+ // Initialize HttpClient with Studio API base URL
13
+ this.apiClient = new cli_utilities_1.HttpClient();
14
+ this.apiClient.baseUrl(`${this.composableStudioConfig.apiBaseUrl}/${this.composableStudioConfig.apiVersion}`);
15
+ }
16
+ async start() {
17
+ cli_utilities_1.log.debug('Starting Studio project export process...', this.exportConfig.context);
18
+ if (!(0, cli_utilities_1.isAuthenticated)()) {
19
+ cli_utilities_1.cliux.print('WARNING!!! To export Studio projects, you must be logged in. Please check csdx auth:login --help to log in', { color: 'yellow' });
20
+ return Promise.resolve();
21
+ }
22
+ this.composableStudioPath = (0, node_path_1.resolve)(this.exportConfig.data, this.exportConfig.branchName || '', this.composableStudioConfig.dirName);
23
+ cli_utilities_1.log.debug(`Studio folder path: ${this.composableStudioPath}`, this.exportConfig.context);
24
+ await utils_1.fsUtil.makeDirectory(this.composableStudioPath);
25
+ cli_utilities_1.log.debug('Created Studio directory', this.exportConfig.context);
26
+ this.exportConfig.org_uid = this.exportConfig.org_uid || (await (0, utils_1.getOrgUid)(this.exportConfig));
27
+ cli_utilities_1.log.debug(`Organization UID: ${this.exportConfig.org_uid}`, this.exportConfig.context);
28
+ await this.exportProjects();
29
+ cli_utilities_1.log.debug('Studio project export process completed', this.exportConfig.context);
30
+ }
31
+ /**
32
+ * Export Studio projects connected to the current stack
33
+ */
34
+ async exportProjects() {
35
+ var _a, _b;
36
+ cli_utilities_1.log.debug('Starting Studio project export...', this.exportConfig.context);
37
+ try {
38
+ // Get authentication details - following personalization-api-adapter pattern
39
+ cli_utilities_1.log.debug('Initializing Studio API authentication...', this.exportConfig.context);
40
+ await cli_utilities_1.authenticationHandler.getAuthDetails();
41
+ const token = cli_utilities_1.authenticationHandler.accessToken;
42
+ cli_utilities_1.log.debug(`Authentication type: ${cli_utilities_1.authenticationHandler.isOauthEnabled ? 'OAuth' : 'Token'}`, this.exportConfig.context);
43
+ // Set authentication headers based on auth type
44
+ if (cli_utilities_1.authenticationHandler.isOauthEnabled) {
45
+ cli_utilities_1.log.debug('Setting OAuth authorization header', this.exportConfig.context);
46
+ this.apiClient.headers({ authorization: token });
47
+ }
48
+ else {
49
+ cli_utilities_1.log.debug('Setting authtoken header', this.exportConfig.context);
50
+ this.apiClient.headers({ authtoken: token });
51
+ }
52
+ // Set organization_uid header
53
+ this.apiClient.headers({
54
+ organization_uid: this.exportConfig.org_uid,
55
+ Accept: 'application/json',
56
+ });
57
+ const apiUrl = '/projects';
58
+ cli_utilities_1.log.debug(`Fetching projects from: ${this.composableStudioConfig.apiBaseUrl}${apiUrl}`, this.exportConfig.context);
59
+ // Make API call to fetch projects using HttpClient
60
+ const response = await this.apiClient.get(apiUrl);
61
+ if (response.status < 200 || response.status >= 300) {
62
+ throw new Error(`API call failed with status ${response.status}: ${JSON.stringify(response.data)}`);
63
+ }
64
+ const data = response.data;
65
+ cli_utilities_1.log.debug(`Fetched ${((_a = data.projects) === null || _a === void 0 ? void 0 : _a.length) || 0} total projects`, this.exportConfig.context);
66
+ // Filter projects connected to this stack
67
+ const connectedProject = (_b = data.projects) === null || _b === void 0 ? void 0 : _b.filter((project) => project.connectedStackApiKey === this.exportConfig.apiKey);
68
+ if (!connectedProject || connectedProject.length === 0) {
69
+ cli_utilities_1.log.info(cli_utilities_1.messageHandler.parse('COMPOSABLE_STUDIO_NOT_FOUND'), this.exportConfig.context);
70
+ return;
71
+ }
72
+ // Use the first connected project (stacks should have only one project)
73
+ this.composableStudioProject = connectedProject[0];
74
+ cli_utilities_1.log.debug(`Found Studio project: ${this.composableStudioProject.name}`, this.exportConfig.context);
75
+ // Write the project to file
76
+ const composableStudioFilePath = (0, node_path_1.resolve)(this.composableStudioPath, this.composableStudioConfig.fileName);
77
+ cli_utilities_1.log.debug(`Writing Studio project to: ${composableStudioFilePath}`, this.exportConfig.context);
78
+ utils_1.fsUtil.writeFile(composableStudioFilePath, this.composableStudioProject);
79
+ cli_utilities_1.log.success(cli_utilities_1.messageHandler.parse('COMPOSABLE_STUDIO_EXPORT_COMPLETE', this.composableStudioProject.name), this.exportConfig.context);
80
+ }
81
+ catch (error) {
82
+ cli_utilities_1.log.debug('Error occurred while exporting Studio project', this.exportConfig.context);
83
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context));
84
+ }
85
+ }
86
+ }
87
+ exports.default = ExportComposableStudio;
@@ -39,12 +39,14 @@ class ContentTypesExport extends base_class_1.default {
39
39
  .find();
40
40
  return [countResponse.count || 0];
41
41
  });
42
+ // Create simple progress manager with total count
43
+ const progress = this.createSimpleProgress(this.currentModuleName, totalCount);
42
44
  if (totalCount === 0) {
43
45
  cli_utilities_1.log.info(cli_utilities_1.messageHandler.parse('CONTENT_TYPE_NO_TYPES'), this.exportConfig.context);
46
+ await this.writeContentTypes(this.contentTypes);
47
+ this.completeProgress(true);
44
48
  return;
45
49
  }
46
- // Create simple progress manager with total count
47
- const progress = this.createSimpleProgress(this.currentModuleName, totalCount);
48
50
  progress.updateStatus('Fetching content types...');
49
51
  await this.getContentTypes();
50
52
  await this.writeContentTypes(this.contentTypes);
@@ -219,7 +219,7 @@ class EntriesExport extends base_class_1.default {
219
219
  });
220
220
  cli_utilities_1.log.debug('Initialized FsUtility for writing entries', this.exportConfig.context);
221
221
  }
222
- cli_utilities_1.log.debug(`Writing ${entriesSearchResponse.items.length} entries to file`, this.exportConfig.context);
222
+ cli_utilities_1.log.debug(`Writing ${entriesSearchResponse.items.length} entries to file...`, this.exportConfig.context);
223
223
  this.entriesFileHelper.writeIntoFile(entriesSearchResponse.items, { mapKeyVal: true });
224
224
  // Track progress for individual entries
225
225
  entriesSearchResponse.items.forEach((entry) => {
@@ -227,9 +227,9 @@ class EntriesExport extends base_class_1.default {
227
227
  (_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(true, `entry: ${entry.uid}`, null, utils_1.PROCESS_NAMES.ENTRIES);
228
228
  });
229
229
  if (this.entriesConfig.exportVersions) {
230
- cli_utilities_1.log.debug('Exporting entry versions is enabled', this.exportConfig.context);
230
+ cli_utilities_1.log.debug('Exporting entry versions is enabled.', this.exportConfig.context);
231
231
  let versionedEntryPath = path.join((0, cli_utilities_2.sanitizePath)(this.entriesDirPath), (0, cli_utilities_2.sanitizePath)(options.contentType), (0, cli_utilities_2.sanitizePath)(options.locale), 'versions');
232
- cli_utilities_1.log.debug(`Creating versioned entries directory at: ${versionedEntryPath}`, this.exportConfig.context);
232
+ cli_utilities_1.log.debug(`Creating versioned entries directory at: ${versionedEntryPath}.`, this.exportConfig.context);
233
233
  utils_1.fsUtil.makeDirectory(versionedEntryPath);
234
234
  await this.fetchEntriesVersions(entriesSearchResponse.items, {
235
235
  locale: options.locale,
@@ -269,7 +269,7 @@ class EntriesExport extends base_class_1.default {
269
269
  }
270
270
  }
271
271
  async fetchEntriesVersions(entries, options) {
272
- cli_utilities_1.log.debug(`Fetching versions for ${entries.length} entries`, this.exportConfig.context);
272
+ cli_utilities_1.log.debug(`Fetching versions for ${entries.length} entries...`, this.exportConfig.context);
273
273
  const onSuccess = ({ response, apiData: entry }) => {
274
274
  var _a;
275
275
  const versionFilePath = path.join((0, cli_utilities_2.sanitizePath)(options.versionedEntryPath), (0, cli_utilities_2.sanitizePath)(`${entry.uid}.json`));
@@ -305,7 +305,7 @@ class EntriesExport extends base_class_1.default {
305
305
  return new Promise(async (resolve, reject) => {
306
306
  return await this.getEntryByVersion(apiParams.queryParam, entry)
307
307
  .then((response) => {
308
- cli_utilities_1.log.debug(`Successfully fetched versions for entry: ${entry.uid}`, this.exportConfig.context);
308
+ cli_utilities_1.log.debug(`Successfully fetched versions for entry UID: ${entry.uid}`, this.exportConfig.context);
309
309
  apiParams.resolve({
310
310
  response,
311
311
  apiData: entry,
@@ -313,7 +313,7 @@ class EntriesExport extends base_class_1.default {
313
313
  resolve(true);
314
314
  })
315
315
  .catch((error) => {
316
- cli_utilities_1.log.debug(`Failed to fetch versions for entry: ${entry.uid}`, this.exportConfig.context);
316
+ cli_utilities_1.log.debug(`Failed to fetch versions for entry UID: ${entry.uid}`, this.exportConfig.context);
317
317
  apiParams.reject({
318
318
  error,
319
319
  apiData: entry,
@@ -330,7 +330,7 @@ class EntriesExport extends base_class_1.default {
330
330
  },
331
331
  version: entry._version,
332
332
  };
333
- cli_utilities_1.log.debug(`Fetching entry version ${entry._version} for uid: ${entry.uid}`, this.exportConfig.context);
333
+ cli_utilities_1.log.debug(`Fetching entry version ${entry._version} for entry UID: '${entry.uid}'.`, this.exportConfig.context);
334
334
  const entryResponse = await this.stackAPIClient
335
335
  .contentType(options.contentType)
336
336
  .entry(entry.uid)
@@ -35,12 +35,16 @@ class GlobalFieldsExport extends base_class_1.default {
35
35
  .find();
36
36
  return [countResponse.count || 0];
37
37
  });
38
+ // Create simple progress manager for global fields
39
+ const progress = this.createSimpleProgress(this.currentModuleName, totalCount);
38
40
  if (totalCount === 0) {
39
41
  cli_utilities_1.log.info(cli_utilities_1.messageHandler.parse('GLOBAL_FIELDS_NOT_FOUND'), this.exportConfig.context);
42
+ const globalFieldsFilePath = path.join(this.globalFieldsDirPath, this.globalFieldsConfig.fileName);
43
+ cli_utilities_1.log.debug(`Writing global fields to: ${globalFieldsFilePath}`, this.exportConfig.context);
44
+ utils_1.fsUtil.writeFile(globalFieldsFilePath, this.globalFields);
45
+ this.completeProgress(true);
40
46
  return;
41
47
  }
42
- // Create simple progress manager for global fields
43
- const progress = this.createSimpleProgress(this.currentModuleName, totalCount);
44
48
  progress.updateStatus('Fetching global fields...');
45
49
  await this.getGlobalFields();
46
50
  const globalFieldsFilePath = path.join(this.globalFieldsDirPath, this.globalFieldsConfig.fileName);
@@ -75,17 +75,17 @@ class ExportMarketplaceApps extends base_class_1.default {
75
75
  }
76
76
  async setupPaths() {
77
77
  this.marketplaceAppPath = (0, node_path_1.resolve)(this.exportConfig.data, this.exportConfig.branchName || '', this.marketplaceAppConfig.dirName);
78
- cli_utilities_1.log.debug(`Marketplace apps folder path: ${this.marketplaceAppPath}`, this.exportConfig.context);
78
+ cli_utilities_1.log.debug(`Marketplace apps folder path: '${this.marketplaceAppPath}'`, this.exportConfig.context);
79
79
  await utils_1.fsUtil.makeDirectory(this.marketplaceAppPath);
80
80
  cli_utilities_1.log.debug('Created marketplace apps directory', this.exportConfig.context);
81
81
  this.developerHubBaseUrl = this.exportConfig.developerHubBaseUrl || (await (0, utils_1.getDeveloperHubUrl)(this.exportConfig));
82
- cli_utilities_1.log.debug(`Developer hub base URL: ${this.developerHubBaseUrl}`, this.exportConfig.context);
82
+ cli_utilities_1.log.debug(`Developer hub base URL: '${this.developerHubBaseUrl}'`, this.exportConfig.context);
83
83
  this.exportConfig.org_uid = await (0, utils_1.getOrgUid)(this.exportConfig);
84
84
  this.query = { target_uids: this.exportConfig.source_stack };
85
- cli_utilities_1.log.debug(`Organization UID: ${this.exportConfig.org_uid}`, this.exportConfig.context);
85
+ cli_utilities_1.log.debug(`Organization UID: '${this.exportConfig.org_uid}'.`, this.exportConfig.context);
86
86
  // NOTE init marketplace app sdk
87
87
  const host = this.developerHubBaseUrl.split('://').pop();
88
- cli_utilities_1.log.debug(`Initializing marketplace SDK with host: ${host}`, this.exportConfig.context);
88
+ cli_utilities_1.log.debug(`Initializing Marketplace SDK with host: '${host}'...`, this.exportConfig.context);
89
89
  this.appSdk = await (0, cli_utilities_1.marketplaceSDKClient)({ host });
90
90
  }
91
91
  async getAppsCount() {
@@ -119,17 +119,28 @@ class ExportMarketplaceApps extends base_class_1.default {
119
119
  * library if it is available.
120
120
  */
121
121
  async exportApps() {
122
+ var _a, _b, _c, _d, _e;
122
123
  cli_utilities_1.log.debug('Starting apps export process...', this.exportConfig.context);
124
+ // Process external query if provided
125
+ const externalQuery = (_a = this.exportConfig.query) === null || _a === void 0 ? void 0 : _a.modules['marketplace-apps'];
126
+ if (externalQuery) {
127
+ if (((_c = (_b = externalQuery.app_uid) === null || _b === void 0 ? void 0 : _b.$in) === null || _c === void 0 ? void 0 : _c.length) > 0) {
128
+ this.query.app_uids = externalQuery.app_uid.$in.join(',');
129
+ }
130
+ if (((_e = (_d = externalQuery.installation_uid) === null || _d === void 0 ? void 0 : _d.$in) === null || _e === void 0 ? void 0 : _e.length) > 0) {
131
+ this.query.installation_uids = externalQuery.installation_uid.$in.join(',');
132
+ }
133
+ }
123
134
  await this.getStackSpecificApps();
124
135
  cli_utilities_1.log.debug(`Retrieved ${this.installedApps.length} stack-specific apps`, this.exportConfig.context);
125
136
  if (!this.nodeCrypto && (0, find_1.default)(this.installedApps, (app) => !(0, isEmpty_1.default)(app.configuration))) {
126
- cli_utilities_1.log.debug('Initializing NodeCrypto for app configuration encryption', this.exportConfig.context);
137
+ cli_utilities_1.log.debug('Initializing NodeCrypto for app configuration encryption...', this.exportConfig.context);
127
138
  this.nodeCrypto = await (0, utils_1.createNodeCryptoInstance)(this.exportConfig);
128
139
  }
129
140
  this.installedApps = (0, map_1.default)(this.installedApps, (app) => {
130
141
  var _a;
131
142
  if ((0, has_1.default)(app, 'configuration')) {
132
- 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);
143
+ 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);
133
144
  app['configuration'] = this.nodeCrypto.encrypt(app.configuration);
134
145
  }
135
146
  return app;
@@ -149,18 +160,18 @@ class ExportMarketplaceApps extends base_class_1.default {
149
160
  cli_utilities_1.log.debug(`Processing ${this.installedApps.length} installed apps`, this.exportConfig.context);
150
161
  for (const [index, app] of (0, entries_1.default)(this.installedApps)) {
151
162
  if (app.manifest.visibility === 'private') {
152
- cli_utilities_1.log.debug(`Processing private app manifest: ${app.manifest.name}`, this.exportConfig.context);
163
+ cli_utilities_1.log.debug(`Processing private app manifest: '${app.manifest.name}'...`, this.exportConfig.context);
153
164
  await this.getPrivateAppsManifest(+index, app);
154
165
  }
155
166
  }
156
167
  for (const [index, app] of (0, entries_1.default)(this.installedApps)) {
157
- cli_utilities_1.log.debug(`Processing app configurations: ${((_a = app.manifest) === null || _a === void 0 ? void 0 : _a.name) || app.uid}`, this.exportConfig.context);
168
+ cli_utilities_1.log.debug(`Processing app configurations for: '${((_a = app.manifest) === null || _a === void 0 ? void 0 : _a.name) || app.uid}'...`, this.exportConfig.context);
158
169
  await this.getAppConfigurations(+index, app);
159
170
  // Track progress for each app processed
160
171
  (_b = this.progressManager) === null || _b === void 0 ? void 0 : _b.tick(true, `app: ${((_c = app.manifest) === null || _c === void 0 ? void 0 : _c.name) || app.uid}`, null, utils_1.PROCESS_NAMES.FETCH_CONFIG_MANIFEST);
161
172
  }
162
173
  const marketplaceAppsFilePath = (0, node_path_1.resolve)(this.marketplaceAppPath, this.marketplaceAppConfig.fileName);
163
- cli_utilities_1.log.debug(`Writing marketplace apps to: ${marketplaceAppsFilePath}`, this.exportConfig.context);
174
+ cli_utilities_1.log.debug(`Writing Marketplace Apps to: '${marketplaceAppsFilePath}'`, this.exportConfig.context);
164
175
  utils_1.fsUtil.writeFile(marketplaceAppsFilePath, this.installedApps);
165
176
  cli_utilities_1.log.success(cli_utilities_1.messageHandler.parse('MARKETPLACE_APPS_EXPORT_COMPLETE', Object.keys(this.installedApps || {}).length), this.exportConfig.context);
166
177
  }
@@ -175,17 +186,17 @@ class ExportMarketplaceApps extends base_class_1.default {
175
186
  * app's manifest.
176
187
  */
177
188
  async getPrivateAppsManifest(index, appInstallation) {
178
- cli_utilities_1.log.debug(`Fetching private app manifest for: ${appInstallation.manifest.name} (${appInstallation.manifest.uid})`, this.exportConfig.context);
189
+ cli_utilities_1.log.debug(`Fetching private app manifest for: '${appInstallation.manifest.name}' (${appInstallation.manifest.uid})`, this.exportConfig.context);
179
190
  const manifest = await this.appSdk
180
191
  .marketplace(this.exportConfig.org_uid)
181
192
  .app(appInstallation.manifest.uid)
182
193
  .fetch({ include_oauth: true })
183
194
  .catch((error) => {
184
- cli_utilities_1.log.debug(`Failed to fetch private app manifest for: ${appInstallation.manifest.name}`, this.exportConfig.context);
195
+ cli_utilities_1.log.debug(`Failed to fetch private app manifest for: '${appInstallation.manifest.name}'`, this.exportConfig.context);
185
196
  (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context), cli_utilities_1.messageHandler.parse('MARKETPLACE_APP_MANIFEST_EXPORT_FAILED', appInstallation.manifest.name));
186
197
  });
187
198
  if (manifest) {
188
- cli_utilities_1.log.debug(`Successfully fetched private app manifest for: ${appInstallation.manifest.name}`, this.exportConfig.context);
199
+ cli_utilities_1.log.debug(`Successfully fetched private app manifest for: '${appInstallation.manifest.name}'`, this.exportConfig.context);
189
200
  this.installedApps[index].manifest = manifest;
190
201
  }
191
202
  }
@@ -204,7 +215,7 @@ class ExportMarketplaceApps extends base_class_1.default {
204
215
  const appName = (_a = appInstallation === null || appInstallation === void 0 ? void 0 : appInstallation.manifest) === null || _a === void 0 ? void 0 : _a.name;
205
216
  const appUid = (_b = appInstallation === null || appInstallation === void 0 ? void 0 : appInstallation.manifest) === null || _b === void 0 ? void 0 : _b.uid;
206
217
  const app = appName || appUid;
207
- cli_utilities_1.log.debug(`Fetching app configuration for: ${app}`, this.exportConfig.context);
218
+ cli_utilities_1.log.debug(`Fetching app configuration for: '${app}'...`, this.exportConfig.context);
208
219
  cli_utilities_1.log.info(cli_utilities_1.messageHandler.parse('MARKETPLACE_APP_CONFIG_EXPORT', app), this.exportConfig.context);
209
220
  await this.appSdk
210
221
  .marketplace(this.exportConfig.org_uid)
@@ -214,17 +225,18 @@ class ExportMarketplaceApps extends base_class_1.default {
214
225
  var _a;
215
226
  const { data, error } = result;
216
227
  if ((0, has_1.default)(data, 'server_configuration') || (0, has_1.default)(data, 'configuration')) {
217
- cli_utilities_1.log.debug(`Found configuration data for app: ${app}`, this.exportConfig.context);
228
+ cli_utilities_1.log.debug(`Found configuration data for app: '${app}'`, this.exportConfig.context);
218
229
  if (!this.nodeCrypto && ((0, has_1.default)(data, 'server_configuration') || (0, has_1.default)(data, 'configuration'))) {
230
+ cli_utilities_1.log.debug(`Initializing NodeCrypto for app: '${app}'...`, this.exportConfig.context);
219
231
  this.nodeCrypto = await (0, utils_1.createNodeCryptoInstance)(this.exportConfig);
220
232
  (_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.updateStatus(utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.FETCH_CONFIG_MANIFEST].PROCESSING, utils_1.PROCESS_NAMES.FETCH_CONFIG_MANIFEST);
221
233
  }
222
234
  if (!(0, isEmpty_1.default)(data === null || data === void 0 ? void 0 : data.configuration)) {
223
- cli_utilities_1.log.debug(`Encrypting configuration for app: ${app}`, this.exportConfig.context);
235
+ cli_utilities_1.log.debug(`Encrypting configuration for app: '${app}'...`, this.exportConfig.context);
224
236
  this.installedApps[index]['configuration'] = this.nodeCrypto.encrypt(data.configuration);
225
237
  }
226
238
  if (!(0, isEmpty_1.default)(data === null || data === void 0 ? void 0 : data.server_configuration)) {
227
- cli_utilities_1.log.debug(`Encrypting server configuration for app: ${app}`, this.exportConfig.context);
239
+ cli_utilities_1.log.debug(`Encrypting server configuration for app: '${app}'...`, this.exportConfig.context);
228
240
  this.installedApps[index]['server_configuration'] = this.nodeCrypto.encrypt(data.server_configuration);
229
241
  cli_utilities_1.log.success(cli_utilities_1.messageHandler.parse('MARKETPLACE_APP_CONFIG_SUCCESS', app), this.exportConfig.context);
230
242
  }
@@ -233,12 +245,12 @@ class ExportMarketplaceApps extends base_class_1.default {
233
245
  }
234
246
  }
235
247
  else if (error) {
236
- cli_utilities_1.log.debug(`Error in app configuration data for: ${app}`, this.exportConfig.context);
248
+ cli_utilities_1.log.debug(`Error in app configuration data for: '${app}'.`, this.exportConfig.context);
237
249
  (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context), cli_utilities_1.messageHandler.parse('MARKETPLACE_APP_CONFIG_EXPORT_FAILED', app));
238
250
  }
239
251
  })
240
252
  .catch((error) => {
241
- cli_utilities_1.log.debug(`Failed to fetch app configuration for: ${app}`, this.exportConfig.context);
253
+ cli_utilities_1.log.debug(`Failed to fetch app configuration for: '${app}'.`, this.exportConfig.context);
242
254
  (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context), cli_utilities_1.messageHandler.parse('MARKETPLACE_APP_CONFIG_EXPORT_FAILED', app));
243
255
  });
244
256
  }
@@ -256,7 +268,7 @@ class ExportMarketplaceApps extends base_class_1.default {
256
268
  .installation()
257
269
  .fetchAll(Object.assign(Object.assign({}, this.query), { skip }))
258
270
  .catch((error) => {
259
- cli_utilities_1.log.debug('Error occurred while fetching stack-specific apps', this.exportConfig.context);
271
+ cli_utilities_1.log.debug('An error occurred while fetching stack-specific apps.', this.exportConfig.context);
260
272
  (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context));
261
273
  });
262
274
  if (collection) {
@@ -276,11 +288,11 @@ class ExportMarketplaceApps extends base_class_1.default {
276
288
  });
277
289
  this.installedApps = this.installedApps.concat(installation);
278
290
  if (count - (skip + 50) > 0) {
279
- cli_utilities_1.log.debug(`Continuing to fetch apps with skip: ${skip + 50}`, this.exportConfig.context);
291
+ cli_utilities_1.log.debug(`Continuing to fetch apps with skip: ${skip + 50}.`, this.exportConfig.context);
280
292
  await this.getStackSpecificApps(skip + 50);
281
293
  }
282
294
  else {
283
- cli_utilities_1.log.debug('Completed fetching all stack-specific apps', this.exportConfig.context);
295
+ cli_utilities_1.log.debug('Completed fetching all stack-specific apps.', this.exportConfig.context);
284
296
  }
285
297
  }
286
298
  }