@contentstack/cli-cm-export 1.16.3 → 1.18.0
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 +1 -1
- package/lib/commands/cm/stacks/export.d.ts +2 -0
- package/lib/commands/cm/stacks/export.js +43 -15
- package/lib/config/index.js +7 -1
- package/lib/export/module-exporter.js +16 -10
- package/lib/export/modules/assets.d.ts +0 -5
- package/lib/export/modules/assets.js +47 -32
- package/lib/export/modules/base-class.d.ts +1 -0
- package/lib/export/modules/base-class.js +16 -2
- package/lib/export/modules/content-types.d.ts +1 -1
- package/lib/export/modules/content-types.js +25 -12
- package/lib/export/modules/custom-roles.js +50 -9
- package/lib/export/modules/entries.d.ts +1 -1
- package/lib/export/modules/entries.js +63 -16
- package/lib/export/modules/environments.js +29 -7
- package/lib/export/modules/extensions.js +30 -7
- package/lib/export/modules/global-fields.js +27 -7
- package/lib/export/modules/index.js +10 -3
- package/lib/export/modules/labels.js +29 -7
- package/lib/export/modules/locales.d.ts +1 -1
- package/lib/export/modules/locales.js +29 -7
- package/lib/export/modules/marketplace-apps.d.ts +2 -1
- package/lib/export/modules/marketplace-apps.js +62 -15
- package/lib/export/modules/personalize.js +23 -6
- package/lib/export/modules/stack.d.ts +1 -0
- package/lib/export/modules/stack.js +74 -9
- package/lib/export/modules/taxonomies.d.ts +0 -1
- package/lib/export/modules/taxonomies.js +40 -30
- package/lib/export/modules/webhooks.js +29 -7
- package/lib/export/modules/workflows.js +38 -10
- package/lib/types/export-config.d.ts +6 -1
- package/lib/types/index.d.ts +11 -0
- package/lib/utils/basic-login.js +7 -8
- package/lib/utils/common-helper.js +3 -4
- package/lib/utils/export-config-handler.js +44 -0
- package/lib/utils/marketplace-app-helper.js +1 -2
- package/lib/utils/setup-branches.js +1 -1
- package/lib/utils/setup-export-dir.js +1 -1
- package/messages/index.json +69 -1
- package/oclif.manifest.json +9 -1
- package/package.json +4 -4
|
@@ -11,77 +11,142 @@ class ExportStack extends base_class_1.default {
|
|
|
11
11
|
super({ exportConfig, stackAPIClient });
|
|
12
12
|
this.stackConfig = exportConfig.modules.stack;
|
|
13
13
|
this.qs = { include_count: true };
|
|
14
|
-
this.stackFolderPath = (0, node_path_1.resolve)(this.exportConfig.data, this.stackConfig.dirName);
|
|
14
|
+
this.stackFolderPath = (0, node_path_1.resolve)(this.exportConfig.data, this.exportConfig.branchName || '', this.stackConfig.dirName);
|
|
15
|
+
this.exportConfig.context.module = 'stack';
|
|
15
16
|
}
|
|
16
17
|
async start() {
|
|
18
|
+
cli_utilities_1.log.debug('Starting stack export process...', this.exportConfig.context);
|
|
17
19
|
if ((0, cli_utilities_1.isAuthenticated)()) {
|
|
20
|
+
cli_utilities_1.log.debug('User is authenticated, fetching stack data...', this.exportConfig.context);
|
|
18
21
|
const stackData = await this.getStack();
|
|
19
22
|
if (stackData === null || stackData === void 0 ? void 0 : stackData.org_uid) {
|
|
23
|
+
cli_utilities_1.log.debug(`Found organization UID: ${stackData.org_uid}`, this.exportConfig.context);
|
|
20
24
|
this.exportConfig.org_uid = stackData.org_uid;
|
|
21
25
|
this.exportConfig.sourceStackName = stackData.name;
|
|
26
|
+
cli_utilities_1.log.debug(`Set source stack name: ${stackData.name}`, this.exportConfig.context);
|
|
22
27
|
}
|
|
28
|
+
else {
|
|
29
|
+
cli_utilities_1.log.debug('No stack data found or missing org_uid', this.exportConfig.context);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
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();
|
|
23
40
|
}
|
|
24
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);
|
|
25
43
|
//fetch master locale details
|
|
26
44
|
return this.getLocales();
|
|
27
45
|
}
|
|
28
46
|
else if (this.exportConfig.preserveStackVersion) {
|
|
47
|
+
cli_utilities_1.log.debug('Preserve stack version is true, exporting stack...', this.exportConfig.context);
|
|
29
48
|
return this.exportStack();
|
|
30
49
|
}
|
|
50
|
+
else {
|
|
51
|
+
cli_utilities_1.log.debug('Master locale already set, skipping locale fetch', this.exportConfig.context);
|
|
52
|
+
}
|
|
31
53
|
}
|
|
32
54
|
async getStack() {
|
|
55
|
+
cli_utilities_1.log.debug(`Fetching stack data for stack: ${this.exportConfig.source_stack}`, this.exportConfig.context);
|
|
33
56
|
const tempAPIClient = await (0, cli_utilities_1.managementSDKClient)({ host: this.exportConfig.host });
|
|
57
|
+
cli_utilities_1.log.debug(`Created management SDK client with host: ${this.exportConfig.host}`, this.exportConfig.context);
|
|
34
58
|
return await tempAPIClient
|
|
35
59
|
.stack({ api_key: this.exportConfig.source_stack })
|
|
36
60
|
.fetch()
|
|
37
|
-
.
|
|
61
|
+
.then((data) => {
|
|
62
|
+
cli_utilities_1.log.debug(`Successfully fetched stack data for: ${this.exportConfig.source_stack}`, this.exportConfig.context);
|
|
63
|
+
return data;
|
|
64
|
+
})
|
|
65
|
+
.catch((error) => {
|
|
66
|
+
cli_utilities_1.log.debug(`Failed to fetch stack data for: ${this.exportConfig.source_stack}`, this.exportConfig.context);
|
|
67
|
+
return {};
|
|
68
|
+
});
|
|
38
69
|
}
|
|
39
70
|
async getLocales(skip = 0) {
|
|
40
71
|
if (skip) {
|
|
41
72
|
this.qs.skip = skip;
|
|
73
|
+
cli_utilities_1.log.debug(`Fetching locales with skip: ${skip}`, this.exportConfig.context);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
cli_utilities_1.log.debug('Fetching locales with initial query', this.exportConfig.context);
|
|
42
77
|
}
|
|
78
|
+
cli_utilities_1.log.debug(`Query parameters: ${JSON.stringify(this.qs)}`, this.exportConfig.context);
|
|
43
79
|
return await this.stack
|
|
44
80
|
.locale()
|
|
45
81
|
.query(this.qs)
|
|
46
82
|
.find()
|
|
47
83
|
.then(async (data) => {
|
|
48
84
|
const { items, count } = data;
|
|
85
|
+
cli_utilities_1.log.debug(`Fetched ${(items === null || items === void 0 ? void 0 : items.length) || 0} locales out of total ${count}`, this.exportConfig.context);
|
|
49
86
|
if (items === null || items === void 0 ? void 0 : items.length) {
|
|
87
|
+
cli_utilities_1.log.debug(`Processing ${items.length} locales to find master locale`, this.exportConfig.context);
|
|
50
88
|
skip += this.stackConfig.limit || 100;
|
|
51
89
|
const masterLocalObj = (0, find_1.default)(items, (locale) => {
|
|
52
90
|
if (locale.fallback_locale === null) {
|
|
91
|
+
cli_utilities_1.log.debug(`Found master locale: ${locale.name} (${locale.code})`, this.exportConfig.context);
|
|
53
92
|
return locale;
|
|
54
93
|
}
|
|
55
94
|
});
|
|
56
95
|
if (masterLocalObj) {
|
|
96
|
+
cli_utilities_1.log.debug(`Returning master locale: ${masterLocalObj.name}`, this.exportConfig.context);
|
|
57
97
|
return masterLocalObj;
|
|
58
98
|
}
|
|
59
99
|
else if (skip >= count) {
|
|
60
|
-
|
|
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);
|
|
101
|
+
cli_utilities_1.log.debug('Completed searching all locales without finding master locale', this.exportConfig.context);
|
|
61
102
|
return;
|
|
62
103
|
}
|
|
63
104
|
else {
|
|
105
|
+
cli_utilities_1.log.debug(`Master locale not found in current batch, continuing with skip: ${skip}`, this.exportConfig.context);
|
|
64
106
|
return await this.getLocales(skip);
|
|
65
107
|
}
|
|
66
108
|
}
|
|
109
|
+
else {
|
|
110
|
+
cli_utilities_1.log.debug('No locales found to process', this.exportConfig.context);
|
|
111
|
+
}
|
|
67
112
|
})
|
|
68
113
|
.catch((error) => {
|
|
69
|
-
|
|
70
|
-
(0,
|
|
114
|
+
cli_utilities_1.log.debug(`Error occurred while fetching locales for stack: ${this.exportConfig.source_stack}`, this.exportConfig.context);
|
|
115
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context), `Failed to fetch locales for stack ${this.exportConfig.source_stack}`);
|
|
116
|
+
throw error;
|
|
71
117
|
});
|
|
72
118
|
}
|
|
73
119
|
async exportStack() {
|
|
74
|
-
|
|
120
|
+
cli_utilities_1.log.debug(`Starting stack export for: ${this.exportConfig.source_stack}`, this.exportConfig.context);
|
|
75
121
|
await utils_1.fsUtil.makeDirectory(this.stackFolderPath);
|
|
122
|
+
cli_utilities_1.log.debug(`Created stack directory at: ${this.stackFolderPath}`, this.exportConfig.context);
|
|
76
123
|
return this.stack
|
|
77
124
|
.fetch()
|
|
78
125
|
.then((resp) => {
|
|
79
|
-
|
|
80
|
-
|
|
126
|
+
const stackFilePath = (0, node_path_1.resolve)(this.stackFolderPath, this.stackConfig.fileName);
|
|
127
|
+
cli_utilities_1.log.debug(`Writing stack data to: ${stackFilePath}`, this.exportConfig.context);
|
|
128
|
+
utils_1.fsUtil.writeFile(stackFilePath, resp);
|
|
129
|
+
cli_utilities_1.log.success(`Stack details exported successfully for stack ${this.exportConfig.source_stack}`, this.exportConfig.context);
|
|
130
|
+
cli_utilities_1.log.debug('Stack export completed successfully', this.exportConfig.context);
|
|
131
|
+
return resp;
|
|
132
|
+
})
|
|
133
|
+
.catch((error) => {
|
|
134
|
+
cli_utilities_1.log.debug(`Error occurred while exporting stack: ${this.exportConfig.source_stack}`, this.exportConfig.context);
|
|
135
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context));
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
async exportStackSettings() {
|
|
139
|
+
cli_utilities_1.log.info('Exporting stack settings', this.exportConfig.context);
|
|
140
|
+
await utils_1.fsUtil.makeDirectory(this.stackFolderPath);
|
|
141
|
+
return this.stack
|
|
142
|
+
.settings()
|
|
143
|
+
.then((resp) => {
|
|
144
|
+
utils_1.fsUtil.writeFile((0, node_path_1.resolve)(this.stackFolderPath, 'settings.json'), resp);
|
|
145
|
+
cli_utilities_1.log.success('Exported stack settings successfully!', this.exportConfig.context);
|
|
81
146
|
return resp;
|
|
82
147
|
})
|
|
83
148
|
.catch((error) => {
|
|
84
|
-
(0,
|
|
149
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context));
|
|
85
150
|
});
|
|
86
151
|
}
|
|
87
152
|
}
|
|
@@ -5,6 +5,7 @@ const omit_1 = tslib_1.__importDefault(require("lodash/omit"));
|
|
|
5
5
|
const keys_1 = tslib_1.__importDefault(require("lodash/keys"));
|
|
6
6
|
const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
|
|
7
7
|
const node_path_1 = require("node:path");
|
|
8
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
8
9
|
const base_class_1 = tslib_1.__importDefault(require("./base-class"));
|
|
9
10
|
const utils_1 = require("../../utils");
|
|
10
11
|
class ExportTaxonomies extends base_class_1.default {
|
|
@@ -13,23 +14,32 @@ class ExportTaxonomies extends base_class_1.default {
|
|
|
13
14
|
this.taxonomies = {};
|
|
14
15
|
this.taxonomiesConfig = exportConfig.modules.taxonomies;
|
|
15
16
|
this.qs = { include_count: true, limit: this.taxonomiesConfig.limit || 100, skip: 0 };
|
|
17
|
+
this.applyQueryFilters(this.qs, 'taxonomies');
|
|
18
|
+
this.exportConfig.context.module = 'taxonomies';
|
|
16
19
|
}
|
|
17
20
|
async start() {
|
|
18
|
-
|
|
21
|
+
cli_utilities_1.log.debug('Starting taxonomies export process...', this.exportConfig.context);
|
|
19
22
|
//create taxonomies folder
|
|
20
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);
|
|
21
25
|
await utils_1.fsUtil.makeDirectory(this.taxonomiesFolderPath);
|
|
26
|
+
cli_utilities_1.log.debug('Created taxonomies directory', this.exportConfig.context);
|
|
22
27
|
//fetch all taxonomies and write into taxonomies folder
|
|
28
|
+
cli_utilities_1.log.debug('Fetching all taxonomies...', this.exportConfig.context);
|
|
23
29
|
await this.getAllTaxonomies();
|
|
30
|
+
cli_utilities_1.log.debug(`Retrieved ${Object.keys(this.taxonomies).length} taxonomies`, this.exportConfig.context);
|
|
24
31
|
if (this.taxonomies === undefined || (0, isEmpty_1.default)(this.taxonomies)) {
|
|
25
|
-
|
|
32
|
+
cli_utilities_1.log.info(cli_utilities_1.messageHandler.parse('TAXONOMY_NOT_FOUND'), this.exportConfig.context);
|
|
26
33
|
return;
|
|
27
34
|
}
|
|
28
35
|
else {
|
|
29
|
-
|
|
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);
|
|
30
40
|
await this.exportTaxonomies();
|
|
31
41
|
}
|
|
32
|
-
(0,
|
|
42
|
+
cli_utilities_1.log.success(cli_utilities_1.messageHandler.parse('TAXONOMY_EXPORT_COMPLETE', (0, keys_1.default)(this.taxonomies).length), this.exportConfig.context);
|
|
33
43
|
}
|
|
34
44
|
/**
|
|
35
45
|
* fetch all taxonomies in the provided stack
|
|
@@ -39,7 +49,12 @@ class ExportTaxonomies extends base_class_1.default {
|
|
|
39
49
|
async getAllTaxonomies(skip = 0) {
|
|
40
50
|
if (skip) {
|
|
41
51
|
this.qs.skip = skip;
|
|
52
|
+
cli_utilities_1.log.debug(`Fetching taxonomies with skip: ${skip}`, this.exportConfig.context);
|
|
42
53
|
}
|
|
54
|
+
else {
|
|
55
|
+
cli_utilities_1.log.debug('Fetching taxonomies with initial query', this.exportConfig.context);
|
|
56
|
+
}
|
|
57
|
+
cli_utilities_1.log.debug(`Query parameters: ${JSON.stringify(this.qs)}`, this.exportConfig.context);
|
|
43
58
|
await this.stack
|
|
44
59
|
.taxonomy()
|
|
45
60
|
.query(this.qs)
|
|
@@ -47,17 +62,25 @@ class ExportTaxonomies extends base_class_1.default {
|
|
|
47
62
|
.then(async (data) => {
|
|
48
63
|
const { items, count } = data;
|
|
49
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);
|
|
50
66
|
if (items === null || items === void 0 ? void 0 : items.length) {
|
|
67
|
+
cli_utilities_1.log.debug(`Processing ${items.length} taxonomies`, this.exportConfig.context);
|
|
51
68
|
this.sanitizeTaxonomiesAttribs(items);
|
|
52
69
|
skip += this.qs.limit || 100;
|
|
53
70
|
if (skip >= taxonomiesCount) {
|
|
71
|
+
cli_utilities_1.log.debug('Completed fetching all taxonomies', this.exportConfig.context);
|
|
54
72
|
return;
|
|
55
73
|
}
|
|
74
|
+
cli_utilities_1.log.debug(`Continuing to fetch taxonomies with skip: ${skip}`, this.exportConfig.context);
|
|
56
75
|
return await this.getAllTaxonomies(skip);
|
|
57
76
|
}
|
|
77
|
+
else {
|
|
78
|
+
cli_utilities_1.log.debug('No taxonomies found to process', this.exportConfig.context);
|
|
79
|
+
}
|
|
58
80
|
})
|
|
59
81
|
.catch((error) => {
|
|
60
|
-
this.
|
|
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));
|
|
61
84
|
});
|
|
62
85
|
}
|
|
63
86
|
/**
|
|
@@ -66,10 +89,15 @@ class ExportTaxonomies extends base_class_1.default {
|
|
|
66
89
|
* @param taxonomies
|
|
67
90
|
*/
|
|
68
91
|
sanitizeTaxonomiesAttribs(taxonomies) {
|
|
92
|
+
var _a;
|
|
93
|
+
cli_utilities_1.log.debug(`Sanitizing ${taxonomies.length} taxonomies`, this.exportConfig.context);
|
|
69
94
|
for (let index = 0; index < (taxonomies === null || taxonomies === void 0 ? void 0 : taxonomies.length); index++) {
|
|
70
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);
|
|
71
98
|
this.taxonomies[taxonomyUID] = (0, omit_1.default)(taxonomies[index], this.taxonomiesConfig.invalidKeys);
|
|
72
99
|
}
|
|
100
|
+
cli_utilities_1.log.debug(`Sanitization complete. Total taxonomies processed: ${Object.keys(this.taxonomies).length}`, this.exportConfig.context);
|
|
73
101
|
}
|
|
74
102
|
/**
|
|
75
103
|
* Export all taxonomies details using metadata(this.taxonomies) and write it into respective <taxonomy-uid>.json file
|
|
@@ -77,26 +105,20 @@ class ExportTaxonomies extends base_class_1.default {
|
|
|
77
105
|
*/
|
|
78
106
|
async exportTaxonomies() {
|
|
79
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);
|
|
80
109
|
const onSuccess = ({ response, uid }) => {
|
|
81
110
|
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);
|
|
82
112
|
utils_1.fsUtil.writeFile(filePath, response);
|
|
83
|
-
|
|
113
|
+
cli_utilities_1.log.success(cli_utilities_1.messageHandler.parse('TAXONOMY_EXPORT_SUCCESS', uid), this.exportConfig.context);
|
|
84
114
|
};
|
|
85
115
|
const onReject = ({ error, uid }) => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
(0, utils_1.log)(this.exportConfig, `Failed to export taxonomy - '${uid}'! ${error.errorMessage}`, 'error');
|
|
89
|
-
}
|
|
90
|
-
else if (error === null || error === void 0 ? void 0 : error.message) {
|
|
91
|
-
const errorMsg = ((_a = error === null || error === void 0 ? void 0 : error.errors) === null || _a === void 0 ? void 0 : _a.taxonomy) || ((_b = error === null || error === void 0 ? void 0 : error.errors) === null || _b === void 0 ? void 0 : _b.term) || (error === null || error === void 0 ? void 0 : error.message);
|
|
92
|
-
(0, utils_1.log)(this.exportConfig, `Failed to export taxonomy - '${uid}'! ${errorMsg}`, 'error');
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
(0, utils_1.log)(this.exportConfig, `Failed to export taxonomy - '${uid}'! ${error}`, 'error');
|
|
96
|
-
}
|
|
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 }));
|
|
97
118
|
};
|
|
98
119
|
for (let index = 0; index < (taxonomiesUID === null || taxonomiesUID === void 0 ? void 0 : taxonomiesUID.length); index++) {
|
|
99
120
|
const taxonomyUID = taxonomiesUID[index];
|
|
121
|
+
cli_utilities_1.log.debug(`Processing detailed export for taxonomy: ${taxonomyUID}`, this.exportConfig.context);
|
|
100
122
|
await this.makeAPICall({
|
|
101
123
|
reject: onReject,
|
|
102
124
|
resolve: onSuccess,
|
|
@@ -104,19 +126,7 @@ class ExportTaxonomies extends base_class_1.default {
|
|
|
104
126
|
module: 'export-taxonomy',
|
|
105
127
|
});
|
|
106
128
|
}
|
|
107
|
-
|
|
108
|
-
handleErrorMsg(err) {
|
|
109
|
-
var _a, _b;
|
|
110
|
-
if (err === null || err === void 0 ? void 0 : err.errorMessage) {
|
|
111
|
-
(0, utils_1.log)(this.exportConfig, `Failed to export! ${err.errorMessage}`, 'error');
|
|
112
|
-
}
|
|
113
|
-
else if (err === null || err === void 0 ? void 0 : err.message) {
|
|
114
|
-
const errorMsg = ((_a = err === null || err === void 0 ? void 0 : err.errors) === null || _a === void 0 ? void 0 : _a.taxonomy) || ((_b = err === null || err === void 0 ? void 0 : err.errors) === null || _b === void 0 ? void 0 : _b.term) || (err === null || err === void 0 ? void 0 : err.message);
|
|
115
|
-
(0, utils_1.log)(this.exportConfig, `Failed to export! ${errorMsg}`, 'error');
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
(0, utils_1.log)(this.exportConfig, `Failed to export! ${err}`, 'error');
|
|
119
|
-
}
|
|
129
|
+
cli_utilities_1.log.debug('Completed detailed taxonomy export process', this.exportConfig.context);
|
|
120
130
|
}
|
|
121
131
|
}
|
|
122
132
|
exports.default = ExportTaxonomies;
|
|
@@ -4,6 +4,7 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
const omit_1 = tslib_1.__importDefault(require("lodash/omit"));
|
|
5
5
|
const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
|
|
6
6
|
const node_path_1 = require("node:path");
|
|
7
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
7
8
|
const base_class_1 = tslib_1.__importDefault(require("./base-class"));
|
|
8
9
|
const utils_1 = require("../../utils");
|
|
9
10
|
class ExportWebhooks extends base_class_1.default {
|
|
@@ -12,51 +13,72 @@ class ExportWebhooks extends base_class_1.default {
|
|
|
12
13
|
this.webhooks = {};
|
|
13
14
|
this.webhookConfig = exportConfig.modules.webhooks;
|
|
14
15
|
this.qs = { include_count: true, asc: 'updated_at' };
|
|
16
|
+
this.exportConfig.context.module = 'webhooks';
|
|
15
17
|
}
|
|
16
18
|
async start() {
|
|
17
|
-
|
|
19
|
+
cli_utilities_1.log.debug('Starting webhooks export process...', this.exportConfig.context);
|
|
18
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);
|
|
19
22
|
await utils_1.fsUtil.makeDirectory(this.webhooksFolderPath);
|
|
23
|
+
cli_utilities_1.log.debug('Created webhooks directory', this.exportConfig.context);
|
|
20
24
|
await this.getWebhooks();
|
|
25
|
+
cli_utilities_1.log.debug(`Retrieved ${Object.keys(this.webhooks).length} webhooks`, this.exportConfig.context);
|
|
21
26
|
if (this.webhooks === undefined || (0, isEmpty_1.default)(this.webhooks)) {
|
|
22
|
-
|
|
27
|
+
cli_utilities_1.log.info(cli_utilities_1.messageHandler.parse('WEBHOOK_NOT_FOUND'), this.exportConfig.context);
|
|
23
28
|
}
|
|
24
29
|
else {
|
|
25
|
-
|
|
26
|
-
|
|
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);
|
|
27
34
|
}
|
|
28
35
|
}
|
|
29
36
|
async getWebhooks(skip = 0) {
|
|
30
37
|
if (skip) {
|
|
31
38
|
this.qs.skip = skip;
|
|
39
|
+
cli_utilities_1.log.debug(`Fetching webhooks with skip: ${skip}`, this.exportConfig.context);
|
|
32
40
|
}
|
|
41
|
+
else {
|
|
42
|
+
cli_utilities_1.log.debug('Fetching webhooks with initial query', this.exportConfig.context);
|
|
43
|
+
}
|
|
44
|
+
cli_utilities_1.log.debug(`Query parameters: ${JSON.stringify(this.qs)}`, this.exportConfig.context);
|
|
33
45
|
await this.stack
|
|
34
46
|
.webhook()
|
|
35
47
|
.fetchAll(this.qs)
|
|
36
48
|
.then(async (data) => {
|
|
37
49
|
const { items, count } = data;
|
|
50
|
+
cli_utilities_1.log.debug(`Fetched ${(items === null || items === void 0 ? void 0 : items.length) || 0} webhooks out of total ${count}`, this.exportConfig.context);
|
|
38
51
|
if (items === null || items === void 0 ? void 0 : items.length) {
|
|
52
|
+
cli_utilities_1.log.debug(`Processing ${items.length} webhooks`, this.exportConfig.context);
|
|
39
53
|
this.sanitizeAttribs(items);
|
|
40
54
|
skip += this.webhookConfig.limit || 100;
|
|
41
55
|
if (skip >= count) {
|
|
56
|
+
cli_utilities_1.log.debug('Completed fetching all webhooks', this.exportConfig.context);
|
|
42
57
|
return;
|
|
43
58
|
}
|
|
59
|
+
cli_utilities_1.log.debug(`Continuing to fetch webhooks with skip: ${skip}`, this.exportConfig.context);
|
|
44
60
|
return await this.getWebhooks(skip);
|
|
45
61
|
}
|
|
62
|
+
else {
|
|
63
|
+
cli_utilities_1.log.debug('No webhooks found to process', this.exportConfig.context);
|
|
64
|
+
}
|
|
46
65
|
})
|
|
47
66
|
.catch((error) => {
|
|
48
|
-
|
|
49
|
-
(0,
|
|
67
|
+
cli_utilities_1.log.debug('Error occurred while fetching webhooks', this.exportConfig.context);
|
|
68
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context));
|
|
50
69
|
});
|
|
51
70
|
}
|
|
52
71
|
sanitizeAttribs(webhooks) {
|
|
53
72
|
var _a;
|
|
73
|
+
cli_utilities_1.log.debug(`Sanitizing ${webhooks.length} webhooks`, this.exportConfig.context);
|
|
54
74
|
for (let index = 0; index < (webhooks === null || webhooks === void 0 ? void 0 : webhooks.length); index++) {
|
|
55
75
|
const webhookUid = webhooks[index].uid;
|
|
56
76
|
const webhookName = (_a = webhooks[index]) === null || _a === void 0 ? void 0 : _a.name;
|
|
77
|
+
cli_utilities_1.log.debug(`Processing webhook: ${webhookName} (${webhookUid})`, this.exportConfig.context);
|
|
57
78
|
this.webhooks[webhookUid] = (0, omit_1.default)(webhooks[index], ['SYS_ACL']);
|
|
58
|
-
|
|
79
|
+
cli_utilities_1.log.success(cli_utilities_1.messageHandler.parse('WEBHOOK_EXPORT_SUCCESS', webhookName), this.exportConfig.context);
|
|
59
80
|
}
|
|
81
|
+
cli_utilities_1.log.debug(`Sanitization complete. Total webhooks processed: ${Object.keys(this.webhooks).length}`, this.exportConfig.context);
|
|
60
82
|
}
|
|
61
83
|
}
|
|
62
84
|
exports.default = ExportWebhooks;
|
|
@@ -4,6 +4,7 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
const omit_1 = tslib_1.__importDefault(require("lodash/omit"));
|
|
5
5
|
const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
|
|
6
6
|
const node_path_1 = require("node:path");
|
|
7
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
7
8
|
const base_class_1 = tslib_1.__importDefault(require("./base-class"));
|
|
8
9
|
const utils_1 = require("../../utils");
|
|
9
10
|
class ExportWorkFlows extends base_class_1.default {
|
|
@@ -12,24 +13,31 @@ class ExportWorkFlows extends base_class_1.default {
|
|
|
12
13
|
this.workflows = {};
|
|
13
14
|
this.workflowConfig = exportConfig.modules.workflows;
|
|
14
15
|
this.qs = { include_count: true };
|
|
16
|
+
this.exportConfig.context.module = 'workflows';
|
|
15
17
|
}
|
|
16
18
|
async start() {
|
|
17
|
-
(0, utils_1.log)(this.exportConfig, 'Starting workflows export', 'info');
|
|
18
19
|
this.webhooksFolderPath = (0, node_path_1.resolve)(this.exportConfig.data, this.exportConfig.branchName || '', this.workflowConfig.dirName);
|
|
20
|
+
cli_utilities_1.log.debug(`Workflows folder path: ${this.webhooksFolderPath}`, this.exportConfig.context);
|
|
19
21
|
await utils_1.fsUtil.makeDirectory(this.webhooksFolderPath);
|
|
22
|
+
cli_utilities_1.log.debug('Created workflows directory', this.exportConfig.context);
|
|
20
23
|
await this.getWorkflows();
|
|
24
|
+
cli_utilities_1.log.debug(`Retrieved ${Object.keys(this.workflows).length} workflows`, this.exportConfig.context);
|
|
21
25
|
if (this.workflows === undefined || (0, isEmpty_1.default)(this.workflows)) {
|
|
22
|
-
|
|
26
|
+
cli_utilities_1.log.info(cli_utilities_1.messageHandler.parse('WORKFLOW_NOT_FOUND'), this.exportConfig.context);
|
|
23
27
|
}
|
|
24
28
|
else {
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
const workflowsFilePath = (0, node_path_1.resolve)(this.webhooksFolderPath, this.workflowConfig.fileName);
|
|
30
|
+
cli_utilities_1.log.debug(`Writing workflows to: ${workflowsFilePath}`, this.exportConfig.context);
|
|
31
|
+
utils_1.fsUtil.writeFile(workflowsFilePath, this.workflows);
|
|
32
|
+
cli_utilities_1.log.success(cli_utilities_1.messageHandler.parse('WORKFLOW_EXPORT_COMPLETE', Object.keys(this.workflows).length), this.exportConfig.context);
|
|
27
33
|
}
|
|
28
34
|
}
|
|
29
35
|
async getWorkflows(skip = 0) {
|
|
30
36
|
if (skip) {
|
|
31
37
|
this.qs.skip = skip;
|
|
38
|
+
cli_utilities_1.log.debug(`Fetching workflows with skip: ${skip}`, this.exportConfig.context);
|
|
32
39
|
}
|
|
40
|
+
cli_utilities_1.log.debug(`Query parameters: ${JSON.stringify(this.qs)}`, this.exportConfig.context);
|
|
33
41
|
await this.stack
|
|
34
42
|
.workflow()
|
|
35
43
|
.fetchAll(this.qs)
|
|
@@ -37,46 +45,66 @@ class ExportWorkFlows extends base_class_1.default {
|
|
|
37
45
|
const { items, count } = data;
|
|
38
46
|
//NOTE - Handle the case where old workflow api is enabled in that case getting responses as objects.
|
|
39
47
|
const workflowCount = count !== undefined ? count : items.length;
|
|
48
|
+
cli_utilities_1.log.debug(`Fetched ${(items === null || items === void 0 ? void 0 : items.length) || 0} workflows out of total ${workflowCount}`, this.exportConfig.context);
|
|
40
49
|
if (items === null || items === void 0 ? void 0 : items.length) {
|
|
50
|
+
cli_utilities_1.log.debug(`Processing ${items.length} workflows`, this.exportConfig.context);
|
|
41
51
|
await this.sanitizeAttribs(items);
|
|
42
52
|
skip += this.workflowConfig.limit || 100;
|
|
43
53
|
if (skip >= workflowCount) {
|
|
54
|
+
cli_utilities_1.log.debug('Completed fetching all workflows', this.exportConfig.context);
|
|
44
55
|
return;
|
|
45
56
|
}
|
|
57
|
+
cli_utilities_1.log.debug(`Continuing to fetch workflows with skip: ${skip}`, this.exportConfig.context);
|
|
46
58
|
return await this.getWorkflows(skip);
|
|
47
59
|
}
|
|
60
|
+
else {
|
|
61
|
+
cli_utilities_1.log.debug('No workflows found to process', this.exportConfig.context);
|
|
62
|
+
}
|
|
48
63
|
})
|
|
49
64
|
.catch((error) => {
|
|
50
|
-
|
|
51
|
-
(0,
|
|
65
|
+
cli_utilities_1.log.debug('Error occurred while fetching workflows', this.exportConfig.context);
|
|
66
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context));
|
|
52
67
|
});
|
|
53
68
|
}
|
|
54
69
|
async sanitizeAttribs(workflows) {
|
|
55
70
|
var _a;
|
|
71
|
+
cli_utilities_1.log.debug(`Sanitizing ${workflows.length} workflows`, this.exportConfig.context);
|
|
56
72
|
for (let index = 0; index < (workflows === null || workflows === void 0 ? void 0 : workflows.length); index++) {
|
|
57
|
-
await this.getWorkflowRoles(workflows[index]);
|
|
58
73
|
const workflowUid = workflows[index].uid;
|
|
59
74
|
const workflowName = ((_a = workflows[index]) === null || _a === void 0 ? void 0 : _a.name) || '';
|
|
75
|
+
cli_utilities_1.log.debug(`Processing workflow: ${workflowName} (${workflowUid})`, this.exportConfig.context);
|
|
76
|
+
await this.getWorkflowRoles(workflows[index]);
|
|
60
77
|
this.workflows[workflowUid] = (0, omit_1.default)(workflows[index], this.workflowConfig.invalidKeys);
|
|
61
|
-
|
|
78
|
+
cli_utilities_1.log.success(cli_utilities_1.messageHandler.parse('WORKFLOW_EXPORT_SUCCESS', workflowName), this.exportConfig.context);
|
|
62
79
|
}
|
|
80
|
+
cli_utilities_1.log.debug(`Sanitization complete. Total workflows processed: ${Object.keys(this.workflows).length}`, this.exportConfig.context);
|
|
63
81
|
}
|
|
64
82
|
async getWorkflowRoles(workflow) {
|
|
65
83
|
var _a, _b, _c;
|
|
84
|
+
cli_utilities_1.log.debug(`Processing workflow roles for workflow: ${workflow.uid}`, this.exportConfig.context);
|
|
66
85
|
for (const stage of workflow === null || workflow === void 0 ? void 0 : workflow.workflow_stages) {
|
|
86
|
+
cli_utilities_1.log.debug(`Processing workflow stage: ${stage.name}`, this.exportConfig.context);
|
|
67
87
|
for (let i = 0; i < ((_c = (_b = (_a = stage === null || stage === void 0 ? void 0 : stage.SYS_ACL) === null || _a === void 0 ? void 0 : _a.roles) === null || _b === void 0 ? void 0 : _b.uids) === null || _c === void 0 ? void 0 : _c.length); i++) {
|
|
68
88
|
const roleUid = stage.SYS_ACL.roles.uids[i];
|
|
89
|
+
cli_utilities_1.log.debug(`Fetching role data for role UID: ${roleUid}`, this.exportConfig.context);
|
|
69
90
|
const roleData = await this.getRoles(roleUid);
|
|
70
91
|
stage.SYS_ACL.roles.uids[i] = roleData;
|
|
71
92
|
}
|
|
72
93
|
}
|
|
73
94
|
}
|
|
74
95
|
async getRoles(roleUid) {
|
|
96
|
+
cli_utilities_1.log.debug(`Fetching role with UID: ${roleUid}`, this.exportConfig.context);
|
|
75
97
|
return await this.stack
|
|
76
98
|
.role(roleUid)
|
|
77
99
|
.fetch({ include_rules: true, include_permissions: true })
|
|
78
|
-
.then((data) =>
|
|
79
|
-
.
|
|
100
|
+
.then((data) => {
|
|
101
|
+
cli_utilities_1.log.debug(`Successfully fetched role data for UID: ${roleUid}`, this.exportConfig.context);
|
|
102
|
+
return data;
|
|
103
|
+
})
|
|
104
|
+
.catch((err) => {
|
|
105
|
+
cli_utilities_1.log.debug(`Failed to fetch role data for UID: ${roleUid}`, this.exportConfig.context);
|
|
106
|
+
(0, cli_utilities_1.handleAndLogError)(err, Object.assign({}, this.exportConfig.context));
|
|
107
|
+
});
|
|
80
108
|
}
|
|
81
109
|
}
|
|
82
110
|
exports.default = ExportWorkFlows;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Modules, Region } from '.';
|
|
1
|
+
import { Context, Modules, Region } from '.';
|
|
2
2
|
import DefaultConfig from './default-config';
|
|
3
3
|
export default interface ExportConfig extends DefaultConfig {
|
|
4
|
+
context: Context;
|
|
4
5
|
cliLogsPath: string;
|
|
5
6
|
exportDir: string;
|
|
6
7
|
data: string;
|
|
@@ -17,6 +18,7 @@ export default interface ExportConfig extends DefaultConfig {
|
|
|
17
18
|
singleModuleExport?: boolean;
|
|
18
19
|
moduleName?: Modules;
|
|
19
20
|
master_locale: masterLocale;
|
|
21
|
+
query?: any;
|
|
20
22
|
headers?: {
|
|
21
23
|
api_key: string;
|
|
22
24
|
access_token?: string;
|
|
@@ -29,6 +31,9 @@ export default interface ExportConfig extends DefaultConfig {
|
|
|
29
31
|
source_stack?: string;
|
|
30
32
|
sourceStackName?: string;
|
|
31
33
|
region: Region;
|
|
34
|
+
skipStackSettings?: boolean;
|
|
35
|
+
skipDependencies?: boolean;
|
|
36
|
+
authenticationMethod?: string;
|
|
32
37
|
}
|
|
33
38
|
type branch = {
|
|
34
39
|
uid: string;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -96,6 +96,17 @@ export interface StackConfig {
|
|
|
96
96
|
dependencies?: Modules[];
|
|
97
97
|
limit?: number;
|
|
98
98
|
}
|
|
99
|
+
export interface Context {
|
|
100
|
+
command: string;
|
|
101
|
+
module: string;
|
|
102
|
+
userId: string | undefined;
|
|
103
|
+
email: string | undefined;
|
|
104
|
+
sessionId: string | undefined;
|
|
105
|
+
clientId?: string | undefined;
|
|
106
|
+
apiKey: string;
|
|
107
|
+
orgId: string;
|
|
108
|
+
authenticationMethod?: string;
|
|
109
|
+
}
|
|
99
110
|
export { default as DefaultConfig } from './default-config';
|
|
100
111
|
export { default as ExportConfig } from './export-config';
|
|
101
112
|
export * from './marketplace-app';
|
package/lib/utils/basic-login.js
CHANGED
|
@@ -8,11 +8,10 @@
|
|
|
8
8
|
* MIT Licensed
|
|
9
9
|
*/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
const
|
|
12
|
-
const { managementSDKClient, isAuthenticated, cliux, configHandler, authHandler, } = require('@contentstack/cli-utilities');
|
|
11
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
13
12
|
const login = async (config) => {
|
|
14
13
|
var _a;
|
|
15
|
-
const client = await managementSDKClient(config);
|
|
14
|
+
const client = await (0, cli_utilities_1.managementSDKClient)(config);
|
|
16
15
|
if (config.email && config.password) {
|
|
17
16
|
const response = await client.login({ email: config.email, password: config.password }).catch(Promise.reject);
|
|
18
17
|
if ((_a = response === null || response === void 0 ? void 0 : response.user) === null || _a === void 0 ? void 0 : _a.authtoken) {
|
|
@@ -22,18 +21,18 @@ const login = async (config) => {
|
|
|
22
21
|
authtoken: response.user.authtoken,
|
|
23
22
|
'X-User-Agent': 'contentstack-export/v',
|
|
24
23
|
};
|
|
25
|
-
await authHandler.setConfigData('basicAuth', response.user);
|
|
26
|
-
|
|
24
|
+
await cli_utilities_1.authHandler.setConfigData('basicAuth', response.user);
|
|
25
|
+
cli_utilities_1.log.success(`Contentstack account authenticated successfully!`, config.context);
|
|
27
26
|
return config;
|
|
28
27
|
}
|
|
29
28
|
else {
|
|
30
|
-
|
|
29
|
+
cli_utilities_1.log.error(`Failed to login, Invalid credentials`, config.context);
|
|
31
30
|
process.exit(1);
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
33
|
else if (!config.email && !config.password && config.source_stack && config.access_token) {
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
cli_utilities_1.log.info(`Content types, entries, assets, labels, global fields, extensions modules will be exported`, config.context);
|
|
35
|
+
cli_utilities_1.log.info(`Email, password, or management token is not set in the config, cannot export Webhook and label modules`, config.context);
|
|
37
36
|
config.headers = {
|
|
38
37
|
api_key: config.source_stack,
|
|
39
38
|
access_token: config.access_token,
|
|
@@ -7,11 +7,10 @@
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.writeExportMetaFile = exports.executeTask = exports.formatError = exports.validateConfig = void 0;
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
|
-
const promise_limit_1 = tslib_1.__importDefault(require("promise-limit"));
|
|
11
10
|
const path = tslib_1.__importStar(require("path"));
|
|
11
|
+
const promise_limit_1 = tslib_1.__importDefault(require("promise-limit"));
|
|
12
12
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
13
13
|
const file_helper_1 = require("./file-helper");
|
|
14
|
-
const cli_utilities_2 = require("@contentstack/cli-utilities");
|
|
15
14
|
const validateConfig = function (config) {
|
|
16
15
|
if (!config.host || !config.cdn) {
|
|
17
16
|
throw new Error('Host/CDN end point is missing from config');
|
|
@@ -83,8 +82,8 @@ exports.executeTask = executeTask;
|
|
|
83
82
|
const writeExportMetaFile = (exportConfig, metaFilePath) => {
|
|
84
83
|
const exportMeta = {
|
|
85
84
|
contentVersion: exportConfig.contentVersion,
|
|
86
|
-
logsPath:
|
|
85
|
+
logsPath: (0, cli_utilities_1.getLogPath)(),
|
|
87
86
|
};
|
|
88
|
-
file_helper_1.fsUtil.writeFile(path.join((0,
|
|
87
|
+
file_helper_1.fsUtil.writeFile(path.join((0, cli_utilities_1.sanitizePath)(metaFilePath || exportConfig.exportDir), 'export-info.json'), exportMeta);
|
|
89
88
|
};
|
|
90
89
|
exports.writeExportMetaFile = writeExportMetaFile;
|