@contentstack/cli-cm-import 1.25.0 → 1.26.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 +3 -3
- package/lib/commands/cm/stacks/import.d.ts +1 -0
- package/lib/commands/cm/stacks/import.js +33 -12
- package/lib/import/module-importer.js +1 -1
- package/lib/import/modules/assets.d.ts +1 -1
- package/lib/import/modules/assets.js +93 -39
- package/lib/import/modules/base-class.js +11 -3
- package/lib/import/modules/content-types.js +79 -28
- package/lib/import/modules/custom-roles.js +95 -19
- package/lib/import/modules/entries.js +128 -57
- package/lib/import/modules/environments.js +48 -14
- package/lib/import/modules/extensions.js +78 -16
- package/lib/import/modules/global-fields.js +86 -19
- package/lib/import/modules/labels.d.ts +4 -4
- package/lib/import/modules/labels.js +60 -18
- package/lib/import/modules/locales.js +63 -20
- package/lib/import/modules/marketplace-apps.js +160 -31
- package/lib/import/modules/personalize.js +33 -7
- package/lib/import/modules/stack.js +5 -0
- package/lib/import/modules/taxonomies.js +52 -13
- package/lib/import/modules/variant-entries.js +21 -3
- package/lib/import/modules/webhooks.js +44 -12
- package/lib/import/modules/workflows.js +65 -21
- package/lib/types/import-config.d.ts +3 -1
- package/lib/types/index.d.ts +22 -0
- package/lib/utils/asset-helper.js +24 -1
- package/lib/utils/backup-handler.js +15 -1
- package/lib/utils/common-helper.js +41 -16
- package/lib/utils/content-type-helper.js +35 -2
- package/lib/utils/entries-helper.js +24 -2
- package/lib/utils/extension-helper.js +35 -1
- package/lib/utils/global-field-helper.js +1 -1
- package/lib/utils/import-config-handler.js +21 -0
- package/lib/utils/login-handler.js +8 -4
- package/lib/utils/marketplace-app-helper.js +50 -11
- package/lib/utils/taxonomies-helper.js +22 -4
- package/oclif.manifest.json +2 -2
- package/package.json +5 -5
|
@@ -4,11 +4,13 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
|
|
5
5
|
const values_1 = tslib_1.__importDefault(require("lodash/values"));
|
|
6
6
|
const node_path_1 = require("node:path");
|
|
7
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
7
8
|
const utils_1 = require("../../utils");
|
|
8
9
|
const base_class_1 = tslib_1.__importDefault(require("./base-class"));
|
|
9
10
|
class ImportEnvironments extends base_class_1.default {
|
|
10
11
|
constructor({ importConfig, stackAPIClient }) {
|
|
11
12
|
super({ importConfig, stackAPIClient });
|
|
13
|
+
this.importConfig.context.module = 'environments';
|
|
12
14
|
this.environmentsConfig = importConfig.modules.environments;
|
|
13
15
|
this.mapperDirPath = (0, node_path_1.join)(this.importConfig.backupDir, 'mapper', 'environments');
|
|
14
16
|
this.environmentsFolderPath = (0, node_path_1.join)(this.importConfig.backupDir, this.environmentsConfig.dirName);
|
|
@@ -24,57 +26,80 @@ class ImportEnvironments extends base_class_1.default {
|
|
|
24
26
|
* @returns {Promise<void>} Promise<void>
|
|
25
27
|
*/
|
|
26
28
|
async start() {
|
|
27
|
-
var _a, _b;
|
|
28
|
-
|
|
29
|
+
var _a, _b, _c;
|
|
30
|
+
cli_utilities_1.log.debug('Checking for environments folder existence', this.importConfig.context);
|
|
29
31
|
//Step1 check folder exists or not
|
|
30
32
|
if (utils_1.fileHelper.fileExistsSync(this.environmentsFolderPath)) {
|
|
33
|
+
cli_utilities_1.log.debug(`Found environments folder: ${this.environmentsFolderPath}`, this.importConfig.context);
|
|
31
34
|
this.environments = utils_1.fsUtil.readFile((0, node_path_1.join)(this.environmentsFolderPath, 'environments.json'), true);
|
|
35
|
+
const envCount = Object.keys(this.environments || {}).length;
|
|
36
|
+
cli_utilities_1.log.debug(`Loaded ${envCount} environment items from file`, this.importConfig.context);
|
|
32
37
|
}
|
|
33
38
|
else {
|
|
34
|
-
|
|
39
|
+
cli_utilities_1.log.info(`No Environments Found - '${this.environmentsFolderPath}'`, this.importConfig.context);
|
|
35
40
|
return;
|
|
36
41
|
}
|
|
42
|
+
cli_utilities_1.log.debug('Creating environments mapper directory', this.importConfig.context);
|
|
37
43
|
await utils_1.fsUtil.makeDirectory(this.mapperDirPath);
|
|
44
|
+
cli_utilities_1.log.debug('Loading existing environment UID mappings', this.importConfig.context);
|
|
38
45
|
this.envUidMapper = utils_1.fileHelper.fileExistsSync(this.envUidMapperPath)
|
|
39
46
|
? utils_1.fsUtil.readFile((0, node_path_1.join)(this.envUidMapperPath), true)
|
|
40
47
|
: {};
|
|
48
|
+
if (((_a = Object.keys(this.envUidMapper)) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
49
|
+
const envUidCount = Object.keys(this.envUidMapper || {}).length;
|
|
50
|
+
cli_utilities_1.log.debug(`Loaded existing environment UID data: ${envUidCount} items`, this.importConfig.context);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
cli_utilities_1.log.debug('No existing environment UID mappings found', this.importConfig.context);
|
|
54
|
+
}
|
|
55
|
+
cli_utilities_1.log.debug('Starting environment import process', this.importConfig.context);
|
|
41
56
|
await this.importEnvironments();
|
|
42
|
-
|
|
57
|
+
cli_utilities_1.log.debug('Processing environment import results', this.importConfig.context);
|
|
58
|
+
if ((_b = this.envSuccess) === null || _b === void 0 ? void 0 : _b.length) {
|
|
43
59
|
utils_1.fsUtil.writeFile(this.envSuccessPath, this.envSuccess);
|
|
60
|
+
cli_utilities_1.log.debug(`Written ${this.envSuccess.length} successful environments to file`, this.importConfig.context);
|
|
44
61
|
}
|
|
45
|
-
if ((
|
|
62
|
+
if ((_c = this.envFailed) === null || _c === void 0 ? void 0 : _c.length) {
|
|
46
63
|
utils_1.fsUtil.writeFile(this.envFailsPath, this.envFailed);
|
|
64
|
+
cli_utilities_1.log.debug(`Written ${this.envFailed.length} failed environments to file`, this.importConfig.context);
|
|
47
65
|
}
|
|
48
|
-
|
|
66
|
+
cli_utilities_1.log.success('Environments have been imported successfully!', this.importConfig.context);
|
|
49
67
|
}
|
|
50
68
|
async importEnvironments() {
|
|
69
|
+
cli_utilities_1.log.debug('Validating environments data', this.importConfig.context);
|
|
51
70
|
if (this.environments === undefined || (0, isEmpty_1.default)(this.environments)) {
|
|
52
|
-
|
|
71
|
+
cli_utilities_1.log.info('No Environment Found', this.importConfig.context);
|
|
53
72
|
return;
|
|
54
73
|
}
|
|
55
74
|
const apiContent = (0, values_1.default)(this.environments);
|
|
75
|
+
cli_utilities_1.log.debug(`Starting to import ${apiContent.length} environments`, this.importConfig.context);
|
|
76
|
+
cli_utilities_1.log.debug(`Environment names: ${apiContent.map((e) => e.name).join(', ')}`, this.importConfig.context);
|
|
56
77
|
const onSuccess = ({ response, apiData: { uid, name } = { uid: null, name: '' } }) => {
|
|
57
78
|
this.envSuccess.push(response);
|
|
58
79
|
this.envUidMapper[uid] = response.uid;
|
|
59
|
-
|
|
80
|
+
cli_utilities_1.log.success(`Environment '${name}' imported successfully`, this.importConfig.context);
|
|
81
|
+
cli_utilities_1.log.debug(`Environment UID mapping: ${uid} → ${response.uid}`, this.importConfig.context);
|
|
60
82
|
utils_1.fsUtil.writeFile(this.envUidMapperPath, this.envUidMapper);
|
|
61
83
|
};
|
|
62
84
|
const onReject = async ({ error, apiData }) => {
|
|
63
85
|
var _a;
|
|
64
86
|
const err = (error === null || error === void 0 ? void 0 : error.message) ? JSON.parse(error.message) : error;
|
|
65
87
|
const { name, uid } = apiData;
|
|
88
|
+
cli_utilities_1.log.debug(`Environment '${name}' (${uid}) failed to import`, this.importConfig.context);
|
|
66
89
|
if ((_a = err === null || err === void 0 ? void 0 : err.errors) === null || _a === void 0 ? void 0 : _a.name) {
|
|
90
|
+
cli_utilities_1.log.debug(`Environment '${name}' already exists, fetching details`, this.importConfig.context);
|
|
67
91
|
const res = await this.getEnvDetails(name);
|
|
68
92
|
this.envUidMapper[uid] = (res === null || res === void 0 ? void 0 : res.uid) || ' ';
|
|
69
93
|
utils_1.fsUtil.writeFile(this.envUidMapperPath, this.envUidMapper);
|
|
70
|
-
|
|
94
|
+
cli_utilities_1.log.info(`Environment '${name}' already exists`, this.importConfig.context);
|
|
95
|
+
cli_utilities_1.log.debug(`Added existing environment UID mapping: ${uid} → ${res === null || res === void 0 ? void 0 : res.uid}`, this.importConfig.context);
|
|
71
96
|
}
|
|
72
97
|
else {
|
|
73
98
|
this.envFailed.push(apiData);
|
|
74
|
-
(0,
|
|
75
|
-
(0, utils_1.log)(this.importConfig, error, 'error');
|
|
99
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { name }), `Environment '${name}' failed to be import`);
|
|
76
100
|
}
|
|
77
101
|
};
|
|
102
|
+
cli_utilities_1.log.debug(`Using concurrency limit: ${this.importConfig.fetchConcurrency || 2}`, this.importConfig.context);
|
|
78
103
|
await this.makeConcurrentCall({
|
|
79
104
|
apiContent,
|
|
80
105
|
processName: 'import environments',
|
|
@@ -87,6 +112,7 @@ class ImportEnvironments extends base_class_1.default {
|
|
|
87
112
|
},
|
|
88
113
|
concurrencyLimit: this.importConfig.fetchConcurrency || 2,
|
|
89
114
|
}, undefined, false);
|
|
115
|
+
cli_utilities_1.log.debug('Environments import process completed', this.importConfig.context);
|
|
90
116
|
}
|
|
91
117
|
/**
|
|
92
118
|
* @method serializeEnvironments
|
|
@@ -95,22 +121,30 @@ class ImportEnvironments extends base_class_1.default {
|
|
|
95
121
|
*/
|
|
96
122
|
serializeEnvironments(apiOptions) {
|
|
97
123
|
const { apiData: environment } = apiOptions;
|
|
124
|
+
cli_utilities_1.log.debug(`Serializing environment: ${environment.name} (${environment.uid})`, this.importConfig.context);
|
|
98
125
|
if (this.envUidMapper.hasOwnProperty(environment.uid)) {
|
|
99
|
-
|
|
126
|
+
cli_utilities_1.log.info(`Environment '${environment.name}' already exists. Skipping it to avoid duplicates!`, this.importConfig.context);
|
|
127
|
+
cli_utilities_1.log.debug(`Skipping environment serialization for: ${environment.uid}`, this.importConfig.context);
|
|
100
128
|
apiOptions.entity = undefined;
|
|
101
129
|
}
|
|
102
130
|
else {
|
|
131
|
+
cli_utilities_1.log.debug(`Processing environment: ${environment.name}`, this.importConfig.context);
|
|
103
132
|
apiOptions.apiData = environment;
|
|
104
133
|
}
|
|
105
134
|
return apiOptions;
|
|
106
135
|
}
|
|
107
136
|
async getEnvDetails(envName) {
|
|
137
|
+
cli_utilities_1.log.debug(`Fetching environment details for: ${envName}`, this.importConfig.context);
|
|
108
138
|
return await this.stack
|
|
109
139
|
.environment(envName)
|
|
110
140
|
.fetch()
|
|
111
|
-
.then((data) =>
|
|
141
|
+
.then((data) => {
|
|
142
|
+
cli_utilities_1.log.debug(`Successfully fetched environment details for: ${envName}`, this.importConfig.context);
|
|
143
|
+
return data;
|
|
144
|
+
})
|
|
112
145
|
.catch((error) => {
|
|
113
|
-
|
|
146
|
+
cli_utilities_1.log.debug(`Error fetching environment details for: ${envName}`, this.importConfig.context);
|
|
147
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { envName }));
|
|
114
148
|
});
|
|
115
149
|
}
|
|
116
150
|
}
|
|
@@ -5,11 +5,13 @@ const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
|
|
|
5
5
|
const values_1 = tslib_1.__importDefault(require("lodash/values"));
|
|
6
6
|
const cloneDeep_1 = tslib_1.__importDefault(require("lodash/cloneDeep"));
|
|
7
7
|
const node_path_1 = require("node:path");
|
|
8
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
8
9
|
const utils_1 = require("../../utils");
|
|
9
10
|
const base_class_1 = tslib_1.__importDefault(require("./base-class"));
|
|
10
11
|
class ImportExtensions extends base_class_1.default {
|
|
11
12
|
constructor({ importConfig, stackAPIClient }) {
|
|
12
13
|
super({ importConfig, stackAPIClient });
|
|
14
|
+
this.importConfig.context.module = 'extensions';
|
|
13
15
|
this.extensionsConfig = importConfig.modules.extensions;
|
|
14
16
|
this.mapperDirPath = (0, node_path_1.join)(this.importConfig.backupDir, 'mapper', 'extensions');
|
|
15
17
|
this.extensionsFolderPath = (0, node_path_1.join)(this.importConfig.backupDir, this.extensionsConfig.dirName);
|
|
@@ -29,68 +31,98 @@ class ImportExtensions extends base_class_1.default {
|
|
|
29
31
|
*/
|
|
30
32
|
async start() {
|
|
31
33
|
var _a, _b;
|
|
32
|
-
|
|
34
|
+
cli_utilities_1.log.debug('Checking for extensions folder existence', this.importConfig.context);
|
|
33
35
|
//Step1 check folder exists or not
|
|
34
36
|
if (utils_1.fileHelper.fileExistsSync(this.extensionsFolderPath)) {
|
|
37
|
+
cli_utilities_1.log.debug(`Found extensions folder: ${this.extensionsFolderPath}`, this.importConfig.context);
|
|
35
38
|
this.extensions = utils_1.fsUtil.readFile((0, node_path_1.join)(this.extensionsFolderPath, 'extensions.json'), true);
|
|
39
|
+
// Check if extensions file was read successfully
|
|
40
|
+
if (!this.extensions) {
|
|
41
|
+
cli_utilities_1.log.info(`No extensions found in file - '${(0, node_path_1.join)(this.extensionsFolderPath, 'extensions.json')}'`, this.importConfig.context);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const extensionsCount = Object.keys(this.extensions || {}).length;
|
|
45
|
+
cli_utilities_1.log.debug(`Loaded ${extensionsCount} extension items from file`, this.importConfig.context);
|
|
36
46
|
}
|
|
37
47
|
else {
|
|
38
|
-
|
|
48
|
+
cli_utilities_1.log.info(`No Extensions Found - '${this.extensionsFolderPath}'`, this.importConfig.context);
|
|
39
49
|
return;
|
|
40
50
|
}
|
|
51
|
+
cli_utilities_1.log.debug('Creating extensions mapper directory', this.importConfig.context);
|
|
41
52
|
await utils_1.fsUtil.makeDirectory(this.mapperDirPath);
|
|
53
|
+
cli_utilities_1.log.debug('Loading existing extensions UID data', this.importConfig.context);
|
|
42
54
|
this.extUidMapper = utils_1.fileHelper.fileExistsSync(this.extUidMapperPath)
|
|
43
|
-
? utils_1.fsUtil.readFile((0, node_path_1.join)(this.extUidMapperPath), true)
|
|
55
|
+
? utils_1.fsUtil.readFile((0, node_path_1.join)(this.extUidMapperPath), true) || {}
|
|
44
56
|
: {};
|
|
57
|
+
if (this.extUidMapper && Object.keys(this.extUidMapper || {}).length > 0) {
|
|
58
|
+
const extUidCount = Object.keys(this.extUidMapper || {}).length;
|
|
59
|
+
cli_utilities_1.log.debug(`Loaded existing extensions UID data: ${extUidCount} items`, this.importConfig.context);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
cli_utilities_1.log.debug('No existing extensions UID data found', this.importConfig.context);
|
|
63
|
+
}
|
|
45
64
|
// Check whether the scope of an extension contains content-types in scope
|
|
46
65
|
// Remove the scope and store the scope with uid in pending extensions
|
|
66
|
+
cli_utilities_1.log.debug('Checking content types in extension scope', this.importConfig.context);
|
|
47
67
|
this.getContentTypesInScope();
|
|
68
|
+
cli_utilities_1.log.debug('Starting extensions import', this.importConfig.context);
|
|
48
69
|
await this.importExtensions();
|
|
49
70
|
// Update the uid of the extension
|
|
71
|
+
cli_utilities_1.log.debug('Updating extension UIDs', this.importConfig.context);
|
|
50
72
|
this.updateUidExtension();
|
|
51
73
|
// Note: if any extensions present, then update it
|
|
52
74
|
if (this.importConfig.replaceExisting && this.existingExtensions.length > 0) {
|
|
75
|
+
cli_utilities_1.log.debug(`Replacing ${this.existingExtensions.length} existing extensions`, this.importConfig.context);
|
|
53
76
|
await this.replaceExtensions().catch((error) => {
|
|
54
|
-
|
|
77
|
+
cli_utilities_1.log.debug('Error replacing extensions', this.importConfig.context);
|
|
78
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.importConfig.context));
|
|
55
79
|
});
|
|
56
80
|
}
|
|
81
|
+
cli_utilities_1.log.debug('Processing extensions import results', this.importConfig.context);
|
|
57
82
|
if ((_a = this.extSuccess) === null || _a === void 0 ? void 0 : _a.length) {
|
|
58
83
|
utils_1.fsUtil.writeFile(this.extSuccessPath, this.extSuccess);
|
|
84
|
+
cli_utilities_1.log.debug(`Written ${this.extSuccess.length} successful extensions to file`, this.importConfig.context);
|
|
59
85
|
}
|
|
60
86
|
if ((_b = this.extFailed) === null || _b === void 0 ? void 0 : _b.length) {
|
|
61
87
|
utils_1.fsUtil.writeFile(this.extFailsPath, this.extFailed);
|
|
88
|
+
cli_utilities_1.log.debug(`Written ${this.extFailed.length} failed extensions to file`, this.importConfig.context);
|
|
62
89
|
}
|
|
63
|
-
|
|
90
|
+
cli_utilities_1.log.success('Extensions have been imported successfully!', this.importConfig.context);
|
|
64
91
|
}
|
|
65
92
|
async importExtensions() {
|
|
93
|
+
cli_utilities_1.log.debug('Starting extensions import process', this.importConfig.context);
|
|
66
94
|
if (this.extensions === undefined || (0, isEmpty_1.default)(this.extensions)) {
|
|
67
|
-
|
|
95
|
+
cli_utilities_1.log.info('No Extensions Found', this.importConfig.context);
|
|
68
96
|
return;
|
|
69
97
|
}
|
|
70
98
|
const apiContent = (0, values_1.default)(this.extensions);
|
|
99
|
+
cli_utilities_1.log.debug(`Importing ${apiContent.length} extensions`, this.importConfig.context);
|
|
71
100
|
const onSuccess = ({ response, apiData: { uid, title } = { uid: null, title: '' } }) => {
|
|
72
101
|
this.extSuccess.push(response);
|
|
73
102
|
this.extUidMapper[uid] = response.uid;
|
|
74
|
-
|
|
103
|
+
cli_utilities_1.log.success(`Extension '${title}' imported successfully`, this.importConfig.context);
|
|
104
|
+
cli_utilities_1.log.debug(`Extension import completed: ${title} (${uid})`, this.importConfig.context);
|
|
75
105
|
utils_1.fsUtil.writeFile(this.extUidMapperPath, this.extUidMapper);
|
|
76
106
|
};
|
|
77
107
|
const onReject = ({ error, apiData }) => {
|
|
78
108
|
var _a;
|
|
79
109
|
const { title } = apiData;
|
|
110
|
+
cli_utilities_1.log.debug(`Extension '${title}' import failed`, this.importConfig.context);
|
|
80
111
|
if ((_a = error === null || error === void 0 ? void 0 : error.errors) === null || _a === void 0 ? void 0 : _a.title) {
|
|
81
112
|
if (this.importConfig.replaceExisting) {
|
|
82
113
|
this.existingExtensions.push(apiData);
|
|
114
|
+
cli_utilities_1.log.debug(`Extension '${title}' marked for replacement`, this.importConfig.context);
|
|
83
115
|
}
|
|
84
116
|
if (!this.importConfig.skipExisting) {
|
|
85
|
-
|
|
117
|
+
cli_utilities_1.log.info(`Extension '${title}' already exists`, this.importConfig.context);
|
|
86
118
|
}
|
|
87
119
|
}
|
|
88
120
|
else {
|
|
89
121
|
this.extFailed.push(apiData);
|
|
90
|
-
(0,
|
|
91
|
-
(0, utils_1.log)(this.importConfig, error, 'error');
|
|
122
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { title }), `Extension '${title}' failed to be import`);
|
|
92
123
|
}
|
|
93
124
|
};
|
|
125
|
+
cli_utilities_1.log.debug(`Using concurrency limit: ${this.importConfig.concurrency || this.importConfig.fetchConcurrency || 1}`, this.importConfig.context);
|
|
94
126
|
await this.makeConcurrentCall({
|
|
95
127
|
apiContent,
|
|
96
128
|
processName: 'import extensions',
|
|
@@ -102,19 +134,23 @@ class ImportExtensions extends base_class_1.default {
|
|
|
102
134
|
},
|
|
103
135
|
concurrencyLimit: this.importConfig.concurrency || this.importConfig.fetchConcurrency || 1,
|
|
104
136
|
}, undefined, false);
|
|
137
|
+
cli_utilities_1.log.debug('Extensions import process completed', this.importConfig.context);
|
|
105
138
|
}
|
|
106
139
|
async replaceExtensions() {
|
|
140
|
+
cli_utilities_1.log.debug(`Replacing ${this.existingExtensions.length} existing extensions`, this.importConfig.context);
|
|
107
141
|
const onSuccess = ({ response, apiData: { uid, title } = { uid: null, title: '' } }) => {
|
|
108
142
|
this.extSuccess.push(response);
|
|
109
143
|
this.extUidMapper[uid] = response.uid;
|
|
110
|
-
|
|
144
|
+
cli_utilities_1.log.success(`Extension '${title}' replaced successfully`, this.importConfig.context);
|
|
145
|
+
cli_utilities_1.log.debug(`Extension replacement completed: ${title} (${uid})`, this.importConfig.context);
|
|
111
146
|
utils_1.fsUtil.writeFile(this.extUidMapperPath, this.extUidMapper);
|
|
112
147
|
};
|
|
113
148
|
const onReject = ({ error, apiData }) => {
|
|
149
|
+
cli_utilities_1.log.debug(`Extension '${apiData.title}' replacement failed`, this.importConfig.context);
|
|
114
150
|
this.extFailed.push(apiData);
|
|
115
|
-
(0,
|
|
116
|
-
(0, utils_1.log)(this.importConfig, error, 'error');
|
|
151
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { title: apiData.title }), `Extension '${apiData.title}' failed to replace`);
|
|
117
152
|
};
|
|
153
|
+
cli_utilities_1.log.debug(`Using concurrency limit for replacement: ${this.importConfig.concurrency || this.importConfig.fetchConcurrency || 1}`, this.importConfig.context);
|
|
118
154
|
await this.makeConcurrentCall({
|
|
119
155
|
apiContent: this.existingExtensions,
|
|
120
156
|
processName: 'Replace extensions',
|
|
@@ -126,14 +162,18 @@ class ImportExtensions extends base_class_1.default {
|
|
|
126
162
|
},
|
|
127
163
|
concurrencyLimit: this.importConfig.concurrency || this.importConfig.fetchConcurrency || 1,
|
|
128
164
|
}, this.replaceExtensionHandler.bind(this));
|
|
165
|
+
cli_utilities_1.log.debug('Extensions replacement process completed', this.importConfig.context);
|
|
129
166
|
}
|
|
130
167
|
async replaceExtensionHandler({ apiParams, element: extension, isLastRequest, }) {
|
|
168
|
+
cli_utilities_1.log.debug(`Processing extension replacement: ${extension.title}`, this.importConfig.context);
|
|
131
169
|
return new Promise(async (resolve, reject) => {
|
|
170
|
+
cli_utilities_1.log.debug(`Searching for existing extension: ${extension.title}`, this.importConfig.context);
|
|
132
171
|
const { items: [extensionsInStack] = [] } = await this.stack
|
|
133
172
|
.extension()
|
|
134
173
|
.query({ query: { title: extension.title } })
|
|
135
174
|
.findOne()
|
|
136
175
|
.catch((error) => {
|
|
176
|
+
cli_utilities_1.log.debug(`Error searching for extension: ${extension.title}`, this.importConfig.context);
|
|
137
177
|
apiParams.reject({
|
|
138
178
|
error,
|
|
139
179
|
apiData: extension,
|
|
@@ -141,6 +181,7 @@ class ImportExtensions extends base_class_1.default {
|
|
|
141
181
|
reject(true);
|
|
142
182
|
});
|
|
143
183
|
if (extensionsInStack) {
|
|
184
|
+
cli_utilities_1.log.debug(`Found existing extension in stack: ${extension.title} (${extensionsInStack.uid})`, this.importConfig.context);
|
|
144
185
|
const extensionPayload = this.stack.extension(extension.uid);
|
|
145
186
|
Object.assign(extensionPayload, extensionsInStack, (0, cloneDeep_1.default)(extension), {
|
|
146
187
|
uid: extensionsInStack.uid,
|
|
@@ -148,9 +189,11 @@ class ImportExtensions extends base_class_1.default {
|
|
|
148
189
|
_version: extensionsInStack._version,
|
|
149
190
|
stackHeaders: extensionsInStack.stackHeaders,
|
|
150
191
|
});
|
|
192
|
+
cli_utilities_1.log.debug(`Updating extension: ${extension.title}`, this.importConfig.context);
|
|
151
193
|
return extensionPayload
|
|
152
194
|
.update()
|
|
153
195
|
.then((response) => {
|
|
196
|
+
cli_utilities_1.log.debug(`Extension update successful: ${extension.title}`, this.importConfig.context);
|
|
154
197
|
apiParams.resolve({
|
|
155
198
|
response,
|
|
156
199
|
apiData: extension,
|
|
@@ -158,6 +201,7 @@ class ImportExtensions extends base_class_1.default {
|
|
|
158
201
|
resolve(true);
|
|
159
202
|
})
|
|
160
203
|
.catch((error) => {
|
|
204
|
+
cli_utilities_1.log.debug(`Extension update failed: ${extension.title}`, this.importConfig.context);
|
|
161
205
|
apiParams.reject({
|
|
162
206
|
error,
|
|
163
207
|
apiData: extension,
|
|
@@ -166,6 +210,7 @@ class ImportExtensions extends base_class_1.default {
|
|
|
166
210
|
});
|
|
167
211
|
}
|
|
168
212
|
else {
|
|
213
|
+
cli_utilities_1.log.debug(`Extension not found in stack: ${extension.title}`, this.importConfig.context);
|
|
169
214
|
apiParams.reject({
|
|
170
215
|
error: new Error(`Extension with title ${extension.title} not found in the stack`),
|
|
171
216
|
apiData: extension,
|
|
@@ -175,24 +220,41 @@ class ImportExtensions extends base_class_1.default {
|
|
|
175
220
|
});
|
|
176
221
|
}
|
|
177
222
|
getContentTypesInScope() {
|
|
223
|
+
cli_utilities_1.log.debug('Processing content types in extension scope', this.importConfig.context);
|
|
178
224
|
const extension = (0, values_1.default)(this.extensions);
|
|
225
|
+
let processedExtensions = 0;
|
|
179
226
|
extension.forEach((ext) => {
|
|
180
227
|
var _a;
|
|
181
228
|
let ct = ((_a = ext === null || ext === void 0 ? void 0 : ext.scope) === null || _a === void 0 ? void 0 : _a.content_types) || [];
|
|
182
229
|
if ((ct.length === 1 && ct[0] !== '$all') || (ct === null || ct === void 0 ? void 0 : ct.length) > 1) {
|
|
183
|
-
|
|
230
|
+
cli_utilities_1.log.info(`Removing the content-types ${ct.join(',')} from the extension ${ext.title} ...`, this.importConfig.context);
|
|
231
|
+
cli_utilities_1.log.debug(`Extension '${ext.title}' has ${ct.length} content types in scope`, this.importConfig.context);
|
|
184
232
|
const { uid, scope } = ext;
|
|
185
233
|
this.extensionObject.push({ uid, scope });
|
|
186
234
|
delete ext.scope;
|
|
187
235
|
this.extensions[ext.uid] = ext;
|
|
236
|
+
processedExtensions++;
|
|
188
237
|
}
|
|
189
238
|
});
|
|
239
|
+
cli_utilities_1.log.debug(`Processed ${processedExtensions} extensions with content type scope`, this.importConfig.context);
|
|
240
|
+
cli_utilities_1.log.debug(`Total extensions with pending scope: ${this.extensionObject.length}`, this.importConfig.context);
|
|
190
241
|
}
|
|
191
242
|
updateUidExtension() {
|
|
243
|
+
cli_utilities_1.log.debug('Updating extension UIDs in pending extensions', this.importConfig.context);
|
|
244
|
+
let updatedCount = 0;
|
|
192
245
|
for (let i in this.extensionObject) {
|
|
193
|
-
|
|
246
|
+
const originalUid = this.extensionObject[i].uid;
|
|
247
|
+
this.extensionObject[i].uid = this.extUidMapper[originalUid];
|
|
248
|
+
if (this.extUidMapper[originalUid]) {
|
|
249
|
+
updatedCount++;
|
|
250
|
+
cli_utilities_1.log.debug(`Updated extension UID: ${originalUid} → ${this.extUidMapper[originalUid]}`, this.importConfig.context);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
cli_utilities_1.log.debug(`Updated ${updatedCount} extension UIDs in pending extensions`, this.importConfig.context);
|
|
254
|
+
if (this.extensionObject.length > 0) {
|
|
255
|
+
utils_1.fsUtil.writeFile(this.extPendingPath, this.extensionObject);
|
|
256
|
+
cli_utilities_1.log.debug(`Written ${this.extensionObject.length} pending extensions to file`, this.importConfig.context);
|
|
194
257
|
}
|
|
195
|
-
utils_1.fsUtil.writeFile(this.extPendingPath, this.extensionObject);
|
|
196
258
|
}
|
|
197
259
|
}
|
|
198
260
|
exports.default = ImportExtensions;
|