@contentstack/cli-cm-import 1.15.0 → 1.15.2
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/import.js +5 -3
- package/lib/import/module-importer.js +1 -1
- package/lib/import/modules/entries.d.ts +1 -1
- package/lib/import/modules/entries.js +5 -5
- package/lib/import/modules/marketplace-apps.js +34 -24
- package/lib/import/modules-js/marketplace-apps.js +1 -1
- package/lib/types/import-config.d.ts +2 -0
- package/lib/utils/asset-helper.js +5 -3
- package/lib/utils/interactive.js +1 -1
- package/lib/utils/log.js +1 -1
- package/lib/utils/logger.js +4 -4
- package/lib/utils/marketplace-app-helper.js +11 -3
- package/oclif.manifest.json +2 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import
|
|
|
47
47
|
$ csdx COMMAND
|
|
48
48
|
running command...
|
|
49
49
|
$ csdx (--version)
|
|
50
|
-
@contentstack/cli-cm-import/1.15.
|
|
50
|
+
@contentstack/cli-cm-import/1.15.2 linux-x64 node-v18.20.2
|
|
51
51
|
$ csdx --help [COMMAND]
|
|
52
52
|
USAGE
|
|
53
53
|
$ csdx COMMAND
|
|
@@ -17,7 +17,7 @@ class ImportCommand extends cli_command_1.Command {
|
|
|
17
17
|
let importConfig = await (0, utils_1.setupImportConfig)(flags);
|
|
18
18
|
// Note setting host to create cma client
|
|
19
19
|
importConfig.host = this.cmaHost;
|
|
20
|
-
backupDir = importConfig.backupDir;
|
|
20
|
+
backupDir = importConfig.cliLogsPath || importConfig.backupDir;
|
|
21
21
|
const managementAPIClient = await (0, cli_utilities_1.managementSDKClient)(importConfig);
|
|
22
22
|
const moduleImporter = new import_1.ModuleImporter(managementAPIClient, importConfig);
|
|
23
23
|
const result = await moduleImporter.start();
|
|
@@ -26,11 +26,13 @@ class ImportCommand extends cli_command_1.Command {
|
|
|
26
26
|
? `Successfully imported the content to the stack named ${importConfig.stackName} with the API key ${importConfig.apiKey} .`
|
|
27
27
|
: `The content has been imported to the stack ${importConfig.apiKey} successfully!`, 'success');
|
|
28
28
|
}
|
|
29
|
-
(0, utils_1.log)(importConfig, `The log has been stored at '${(0, cli_utilities_1.pathValidator)(node_path_1.default.join(importConfig.backupDir, 'logs', 'import'))}'`, 'success');
|
|
29
|
+
(0, utils_1.log)(importConfig, `The log has been stored at '${(0, cli_utilities_1.pathValidator)(node_path_1.default.join(importConfig.cliLogsPath || importConfig.backupDir, 'logs', 'import'))}'`, 'success');
|
|
30
30
|
}
|
|
31
31
|
catch (error) {
|
|
32
32
|
(0, utils_1.log)({ data: backupDir !== null && backupDir !== void 0 ? backupDir : (0, cli_utilities_1.pathValidator)(node_path_1.default.join(backupDir || __dirname, 'logs', 'import')) }, `Failed to import stack content - ${(0, utils_1.formatError)(error)}`, 'error');
|
|
33
|
-
(0, utils_1.log)({ data: backupDir }, `The log has been stored at ${{ data: backupDir }
|
|
33
|
+
(0, utils_1.log)({ data: backupDir }, `The log has been stored at ${{ data: backupDir }
|
|
34
|
+
? (0, cli_utilities_1.pathValidator)(node_path_1.default.join(backupDir || __dirname, 'logs', 'import'))
|
|
35
|
+
: (0, cli_utilities_1.pathValidator)(node_path_1.default.join(__dirname, 'logs'))}`, 'info');
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
}
|
|
@@ -96,7 +96,7 @@ class ModuleImporter {
|
|
|
96
96
|
* fix available and the user confirms to proceed with the fix, otherwise it returns `false`.
|
|
97
97
|
*/
|
|
98
98
|
async auditImportData(logger) {
|
|
99
|
-
const basePath = (0, path_1.resolve)(this.importConfig.backupDir, 'logs', 'audit');
|
|
99
|
+
const basePath = (0, path_1.resolve)(this.importConfig.cliLogsPath || this.importConfig.backupDir, 'logs', 'audit');
|
|
100
100
|
const auditConfig = this.importConfig.auditConfig;
|
|
101
101
|
auditConfig.config.basePath = basePath;
|
|
102
102
|
auditConfig.config.branch = this.importConfig.branchName;
|
|
@@ -65,7 +65,7 @@ export default class EntriesImport extends BaseClass {
|
|
|
65
65
|
cTUid: string;
|
|
66
66
|
locale: string;
|
|
67
67
|
}): Promise<void>;
|
|
68
|
-
replaceEntriesHandler({ apiParams, element: entry }: {
|
|
68
|
+
replaceEntriesHandler({ apiParams, element: entry, }: {
|
|
69
69
|
apiParams: ApiOptions;
|
|
70
70
|
element: Record<string, string>;
|
|
71
71
|
isLastRequest: boolean;
|
|
@@ -429,7 +429,7 @@ class EntriesImport extends base_class_1.default {
|
|
|
429
429
|
}
|
|
430
430
|
}
|
|
431
431
|
}
|
|
432
|
-
async replaceEntriesHandler({ apiParams, element: entry }) {
|
|
432
|
+
async replaceEntriesHandler({ apiParams, element: entry, }) {
|
|
433
433
|
const { additionalInfo: { cTUid, locale } = {} } = apiParams;
|
|
434
434
|
return new Promise(async (resolve, reject) => {
|
|
435
435
|
const { items: [entryInStack] = [] } = (await this.stack
|
|
@@ -710,11 +710,11 @@ class EntriesImport extends base_class_1.default {
|
|
|
710
710
|
return Promise.resolve();
|
|
711
711
|
}
|
|
712
712
|
// log(this.importConfig, `Starting publish entries for ${cTUid} in locale ${locale}`, 'info');
|
|
713
|
-
const onSuccess = ({ response, apiData: { environments, entryUid }, additionalInfo }) => {
|
|
714
|
-
(0, utils_1.log)(this.importConfig, `Published entry: '${entryUid}' of
|
|
713
|
+
const onSuccess = ({ response, apiData: { environments, entryUid, locales }, additionalInfo }) => {
|
|
714
|
+
(0, utils_1.log)(this.importConfig, `Published the entry: '${entryUid}' of Content Type '${cTUid}' and Locale '${locale}' in Environments '${environments === null || environments === void 0 ? void 0 : environments.join(',')}' and Locales '${locales === null || locales === void 0 ? void 0 : locales.join(',')}'`, 'info');
|
|
715
715
|
};
|
|
716
|
-
const onReject = ({ error, apiData, additionalInfo }) => {
|
|
717
|
-
(0, utils_1.log)(this.importConfig,
|
|
716
|
+
const onReject = ({ error, apiData: { environments, entryUid, locales }, additionalInfo }) => {
|
|
717
|
+
(0, utils_1.log)(this.importConfig, `Failed to publish: '${entryUid}' entry of Content Type '${cTUid}' and Locale '${locale}' in Environments '${environments === null || environments === void 0 ? void 0 : environments.join(',')}' and Locales '${locales === null || locales === void 0 ? void 0 : locales.join(',')}'`, 'error');
|
|
718
718
|
(0, utils_1.log)(this.importConfig, (0, utils_1.formatError)(error), 'error');
|
|
719
719
|
};
|
|
720
720
|
for (const index in indexer) {
|
|
@@ -163,31 +163,37 @@ class ImportMarketplaceApps {
|
|
|
163
163
|
if ((0, isEmpty_1.default)(privateApps)) {
|
|
164
164
|
return Promise.resolve();
|
|
165
165
|
}
|
|
166
|
-
await (0, utils_1.getConfirmationToCreateApps)(privateApps, this.importConfig);
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
this.
|
|
172
|
-
|
|
173
|
-
|
|
166
|
+
let canCreatePrivateApp = await (0, utils_1.getConfirmationToCreateApps)(privateApps, this.importConfig);
|
|
167
|
+
this.importConfig.canCreatePrivateApp = canCreatePrivateApp;
|
|
168
|
+
if (canCreatePrivateApp) {
|
|
169
|
+
(0, utils_1.log)(this.importConfig, 'Starting developer hub private apps re-creation', 'success');
|
|
170
|
+
for (let app of privateApps) {
|
|
171
|
+
if (this.importConfig.skipPrivateAppRecreationIfExist && (await this.isPrivateAppExistInDeveloperHub(app))) {
|
|
172
|
+
// NOTE Found app already exist in the same org
|
|
173
|
+
this.appUidMapping[app.uid] = app.uid;
|
|
174
|
+
cli_utilities_1.cliux.print(`App '${app.manifest.name}' already exist. skipping app recreation.!`, { color: 'yellow' });
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
// NOTE keys can be passed to install new app in the developer hub
|
|
178
|
+
const validKeys = [
|
|
179
|
+
'uid',
|
|
180
|
+
'name',
|
|
181
|
+
'icon',
|
|
182
|
+
'oauth',
|
|
183
|
+
'webhook',
|
|
184
|
+
'visibility',
|
|
185
|
+
'target_type',
|
|
186
|
+
'description',
|
|
187
|
+
'ui_location',
|
|
188
|
+
'framework_version',
|
|
189
|
+
];
|
|
190
|
+
const manifest = (0, pick_1.default)(app.manifest, validKeys);
|
|
191
|
+
this.appOriginalName = manifest.name;
|
|
192
|
+
await this.createPrivateApp(manifest);
|
|
174
193
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
'name',
|
|
179
|
-
'icon',
|
|
180
|
-
'oauth',
|
|
181
|
-
'webhook',
|
|
182
|
-
'visibility',
|
|
183
|
-
'target_type',
|
|
184
|
-
'description',
|
|
185
|
-
'ui_location',
|
|
186
|
-
'framework_version',
|
|
187
|
-
];
|
|
188
|
-
const manifest = (0, pick_1.default)(app.manifest, validKeys);
|
|
189
|
-
this.appOriginalName = manifest.name;
|
|
190
|
-
await this.createPrivateApp(manifest);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
(0, utils_1.log)(this.importConfig, 'Skipping private apps creation on Developer Hub...', 'success');
|
|
191
197
|
}
|
|
192
198
|
this.appOriginalName = undefined;
|
|
193
199
|
}
|
|
@@ -332,6 +338,10 @@ class ImportMarketplaceApps {
|
|
|
332
338
|
const currentStackApp = (0, find_1.default)(this.installedApps, { manifest: { uid: (_a = app === null || app === void 0 ? void 0 : app.manifest) === null || _a === void 0 ? void 0 : _a.uid } });
|
|
333
339
|
if (!currentStackApp) {
|
|
334
340
|
// NOTE install new app
|
|
341
|
+
if (app.manifest.visibility === 'private' && !this.importConfig.canCreatePrivateApp) {
|
|
342
|
+
(0, utils_1.log)(this.importConfig, `Skipping the installation of the private app ${app.manifest.name}...`, 'info');
|
|
343
|
+
return Promise.resolve();
|
|
344
|
+
}
|
|
335
345
|
const installation = await this.installApp(this.importConfig,
|
|
336
346
|
// NOTE if it's private app it should get uid from mapper else will use manifest uid
|
|
337
347
|
this.appUidMapping[app.manifest.uid] || app.manifest.uid);
|
|
@@ -85,7 +85,7 @@ module.exports = class ImportMarketplaceApps {
|
|
|
85
85
|
return "Encryption key can't be empty.";
|
|
86
86
|
return true;
|
|
87
87
|
},
|
|
88
|
-
message: 'Enter
|
|
88
|
+
message: 'Enter Marketplace app configurations encryption key',
|
|
89
89
|
});
|
|
90
90
|
try {
|
|
91
91
|
appConfig = !_.isEmpty(appConfig.configuration) ? appConfig.configuration : appConfig.server_configuration;
|
|
@@ -9,6 +9,8 @@ export interface ExternalConfig {
|
|
|
9
9
|
password?: string;
|
|
10
10
|
}
|
|
11
11
|
export default interface ImportConfig extends DefaultConfig, ExternalConfig {
|
|
12
|
+
cliLogsPath: string;
|
|
13
|
+
canCreatePrivateApp: boolean;
|
|
12
14
|
contentDir: string;
|
|
13
15
|
data: string;
|
|
14
16
|
management_token?: string;
|
|
@@ -235,9 +235,11 @@ const lookupAssets = function (data, mappedAssetUids, mappedAssetUrls, assetUidM
|
|
|
235
235
|
assetUrls.forEach(function (assetUrl) {
|
|
236
236
|
let mappedAssetUrl = mappedAssetUrls[assetUrl];
|
|
237
237
|
if (typeof mappedAssetUrl !== 'undefined') {
|
|
238
|
-
|
|
239
|
-
const
|
|
240
|
-
|
|
238
|
+
//NOTE - This code was added to resolve the SRE issue but once the code was merged Assets URLs in JSON RTE started breaking
|
|
239
|
+
// const sanitizedUrl = escapeRegExp(assetUrl).replace(/\.\./g, '\\$&');
|
|
240
|
+
// const escapedMappedUrl = escapeRegExp(mappedAssetUrl).replace(/\.\./g, '\\$&');
|
|
241
|
+
// entry = entry.replace(new RegExp(sanitizedUrl, 'img'), escapedMappedUrl);
|
|
242
|
+
entry = entry.replace(new RegExp(assetUrl, 'img'), mappedAssetUrl);
|
|
241
243
|
matchedUrls.push(mappedAssetUrl);
|
|
242
244
|
}
|
|
243
245
|
else {
|
package/lib/utils/interactive.js
CHANGED
|
@@ -35,7 +35,7 @@ const askEncryptionKey = async (defaultValue) => {
|
|
|
35
35
|
return "Encryption key can't be empty.";
|
|
36
36
|
return true;
|
|
37
37
|
},
|
|
38
|
-
message: 'Enter
|
|
38
|
+
message: 'Enter Marketplace app configurations encryption key',
|
|
39
39
|
});
|
|
40
40
|
};
|
|
41
41
|
exports.askEncryptionKey = askEncryptionKey;
|
package/lib/utils/log.js
CHANGED
|
@@ -22,7 +22,7 @@ exports.log = log;
|
|
|
22
22
|
function initLogger(config) {
|
|
23
23
|
var _a;
|
|
24
24
|
if (!logger) {
|
|
25
|
-
const basePath = (0, cli_utilities_1.pathValidator)((0, path_1.join)((_a = config === null || config === void 0 ? void 0 : config.
|
|
25
|
+
const basePath = (0, cli_utilities_1.pathValidator)((0, path_1.join)((_a = config === null || config === void 0 ? void 0 : config.cliLogsPath) !== null && _a !== void 0 ? _a : process.cwd(), 'logs', 'import'));
|
|
26
26
|
exports.logger = logger = new cli_utilities_1.Logger(Object.assign(config !== null && config !== void 0 ? config : {}, { basePath }));
|
|
27
27
|
}
|
|
28
28
|
return logger;
|
package/lib/utils/logger.js
CHANGED
|
@@ -121,17 +121,17 @@ function init(_logPath) {
|
|
|
121
121
|
};
|
|
122
122
|
}
|
|
123
123
|
const log = async (config, message, type) => {
|
|
124
|
-
config.
|
|
124
|
+
config.cliLogsPath = config.cliLogsPath || config.data || path.join(__dirname, 'logs');
|
|
125
125
|
// ignoring the type argument, as we are not using it to create a logfile anymore
|
|
126
126
|
if (type !== 'error') {
|
|
127
127
|
// removed type argument from init method
|
|
128
128
|
if (type === 'warn')
|
|
129
|
-
init(config.
|
|
129
|
+
init(config.cliLogsPath).warn(message); //logged warning message in log file
|
|
130
130
|
else
|
|
131
|
-
init(config.
|
|
131
|
+
init(config.cliLogsPath).log(message);
|
|
132
132
|
}
|
|
133
133
|
else {
|
|
134
|
-
init(config.
|
|
134
|
+
init(config.cliLogsPath).error(message);
|
|
135
135
|
}
|
|
136
136
|
};
|
|
137
137
|
exports.log = log;
|
|
@@ -60,13 +60,21 @@ const getConfirmationToCreateApps = async (privateApps, config) => {
|
|
|
60
60
|
if (!config.forceStopMarketplaceAppsPrompt) {
|
|
61
61
|
if (!(await cli_utilities_1.cliux.confirm(chalk_1.default.yellow(`WARNING!!! The listed apps are private apps that are not available in the destination stack: \n\n${(0, map_1.default)(privateApps, ({ manifest: { name } }, index) => `${String(index + 1)}) ${name}`).join('\n')}\n\nWould you like to re-create the private app and then proceed with the installation? (y/n)`)))) {
|
|
62
62
|
if (await cli_utilities_1.cliux.confirm(chalk_1.default.yellow(`\nWARNING!!! Canceling the app re-creation may break the content type and entry import. Would you like to proceed without re-create the private app? (y/n)`))) {
|
|
63
|
-
return Promise.resolve(
|
|
63
|
+
return Promise.resolve(false);
|
|
64
64
|
}
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
else {
|
|
66
|
+
if (await cli_utilities_1.cliux.confirm(chalk_1.default.yellow('\nWould you like to re-create the private app and then proceed with the installation? (y/n)'))) {
|
|
67
|
+
return Promise.resolve(true);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
return Promise.resolve(false);
|
|
71
|
+
}
|
|
67
72
|
}
|
|
68
73
|
}
|
|
69
74
|
}
|
|
75
|
+
else {
|
|
76
|
+
return Promise.resolve(true);
|
|
77
|
+
}
|
|
70
78
|
};
|
|
71
79
|
exports.getConfirmationToCreateApps = getConfirmationToCreateApps;
|
|
72
80
|
const handleNameConflict = async (app, appSuffix, config) => {
|
package/oclif.manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.15.
|
|
2
|
+
"version": "1.15.2",
|
|
3
3
|
"commands": {
|
|
4
4
|
"cm:stacks:import": {
|
|
5
5
|
"id": "cm:stacks:import",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"aliases": [
|
|
13
13
|
"cm:import"
|
|
14
14
|
],
|
|
15
|
+
"hiddenAliases": [],
|
|
15
16
|
"examples": [
|
|
16
17
|
"csdx cm:stacks:import --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>",
|
|
17
18
|
"csdx cm:stacks:import --config <path/of/config/dir>",
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-import",
|
|
3
3
|
"description": "Contentstack CLI plugin to import content into stack",
|
|
4
|
-
"version": "1.15.
|
|
4
|
+
"version": "1.15.2",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@contentstack/cli-audit": "~1.5.
|
|
8
|
+
"@contentstack/cli-audit": "~1.5.4",
|
|
9
9
|
"@contentstack/cli-command": "~1.2.16",
|
|
10
10
|
"@contentstack/cli-utilities": "~1.6.0",
|
|
11
11
|
"@contentstack/management": "~1.15.3",
|