@contentstack/cli-cm-import 1.14.1 → 1.14.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 +3 -3
- package/lib/import/module-importer.js +2 -2
- package/lib/import/modules/content-types.js +1 -1
- package/lib/utils/asset-helper.js +3 -2
- package/lib/utils/common-helper.js +5 -1
- package/lib/utils/entries-helper.js +4 -2
- package/lib/utils/import-config-handler.js +8 -0
- package/lib/utils/interactive.js +3 -1
- package/lib/utils/log.js +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +3 -3
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.14.
|
|
50
|
+
@contentstack/cli-cm-import/1.14.2 linux-x64 node-v18.19.1
|
|
51
51
|
$ csdx --help [COMMAND]
|
|
52
52
|
USAGE
|
|
53
53
|
$ csdx COMMAND
|
|
@@ -26,11 +26,11 @@ 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 '${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.backupDir, 'logs', 'import'))}'`, 'success');
|
|
30
30
|
}
|
|
31
31
|
catch (error) {
|
|
32
|
-
(0, utils_1.log)({ data: backupDir !== null && backupDir !== void 0 ? backupDir : 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 } ? node_path_1.default.join(backupDir || __dirname, 'logs', 'import') : node_path_1.default.join(__dirname, 'logs')}`, 'info');
|
|
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 } ? (0, cli_utilities_1.pathValidator)(node_path_1.default.join(backupDir || __dirname, 'logs', 'import')) : (0, cli_utilities_1.pathValidator)(node_path_1.default.join(__dirname, 'logs'))}`, 'info');
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -39,7 +39,7 @@ class ModuleImporter {
|
|
|
39
39
|
// NOTE audit and fix the import content.
|
|
40
40
|
if (!this.importConfig.skipAudit &&
|
|
41
41
|
(!this.importConfig.moduleName ||
|
|
42
|
-
['content-types', 'global-fields', 'entries'].includes(this.importConfig.moduleName))) {
|
|
42
|
+
['content-types', 'global-fields', 'entries', 'extensions', 'workflows'].includes(this.importConfig.moduleName))) {
|
|
43
43
|
if (!(await this.auditImportData(logger))) {
|
|
44
44
|
return { noSuccessMsg: true };
|
|
45
45
|
}
|
|
@@ -113,7 +113,7 @@ class ModuleImporter {
|
|
|
113
113
|
}
|
|
114
114
|
else if (this.importConfig.modules.types.length) {
|
|
115
115
|
this.importConfig.modules.types
|
|
116
|
-
.filter((val) => ['content-types', 'global-fields', 'entries'].includes(val))
|
|
116
|
+
.filter((val) => ['content-types', 'global-fields', 'entries', 'extensions', 'workflows'].includes(val))
|
|
117
117
|
.forEach((val) => {
|
|
118
118
|
args.push('--modules', val);
|
|
119
119
|
});
|
|
@@ -196,7 +196,7 @@ class ContentTypesImport extends base_class_1.default {
|
|
|
196
196
|
}
|
|
197
197
|
async updatePendingExtensions() {
|
|
198
198
|
let apiContent = utils_1.fsUtil.readFile(this.extPendingPath);
|
|
199
|
-
if (apiContent.length === 0) {
|
|
199
|
+
if ((apiContent === null || apiContent === void 0 ? void 0 : apiContent.length) === 0) {
|
|
200
200
|
(0, utils_1.log)(this.importConfig, `No extensions found to be updated.`, 'success');
|
|
201
201
|
return;
|
|
202
202
|
}
|
|
@@ -234,8 +234,9 @@ const lookupAssets = function (data, mappedAssetUids, mappedAssetUrls, assetUidM
|
|
|
234
234
|
assetUrls.forEach(function (assetUrl) {
|
|
235
235
|
let mappedAssetUrl = mappedAssetUrls[assetUrl];
|
|
236
236
|
if (typeof mappedAssetUrl !== 'undefined') {
|
|
237
|
-
const
|
|
238
|
-
|
|
237
|
+
const sanitizedUrl = (0, cli_utilities_1.escapeRegExp)(assetUrl);
|
|
238
|
+
const escapedMappedUrl = (0, cli_utilities_1.escapeRegExp)(mappedAssetUrl);
|
|
239
|
+
entry = entry.replace(new RegExp(sanitizedUrl, 'img'), escapedMappedUrl);
|
|
239
240
|
matchedUrls.push(mappedAssetUrl);
|
|
240
241
|
}
|
|
241
242
|
else {
|
|
@@ -145,7 +145,11 @@ const field_rules_update = (importConfig, ctPath) => {
|
|
|
145
145
|
management_token: importConfig.management_token,
|
|
146
146
|
});
|
|
147
147
|
let ctObj = stackAPIClient.contentType(schema.uid);
|
|
148
|
-
Object.assign(ctObj, _.cloneDeep(schema));
|
|
148
|
+
//NOTE:- Remove this code Object.assign(ctObj, _.cloneDeep(schema)); -> security vulnerabilities due to mass assignment
|
|
149
|
+
const schemaKeys = Object.keys(schema);
|
|
150
|
+
for (const key of schemaKeys) {
|
|
151
|
+
ctObj[key] = _.cloneDeep(schema[key]);
|
|
152
|
+
}
|
|
149
153
|
ctObj
|
|
150
154
|
.update()
|
|
151
155
|
.then(() => {
|
|
@@ -10,6 +10,7 @@ const path = tslib_1.__importStar(require("path"));
|
|
|
10
10
|
const _ = tslib_1.__importStar(require("lodash"));
|
|
11
11
|
const config_1 = tslib_1.__importDefault(require("../config"));
|
|
12
12
|
const fileHelper = tslib_1.__importStar(require("./file-helper"));
|
|
13
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
13
14
|
// update references in entry object
|
|
14
15
|
const lookupEntries = function (data, mappedUids, uidMapperPath) {
|
|
15
16
|
let parent = [];
|
|
@@ -198,8 +199,9 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
|
|
|
198
199
|
let entry = JSON.stringify(data.entry);
|
|
199
200
|
uids.forEach(function (uid) {
|
|
200
201
|
if (mappedUids.hasOwnProperty(uid)) {
|
|
201
|
-
const
|
|
202
|
-
|
|
202
|
+
const sanitizedUid = (0, cli_utilities_1.escapeRegExp)(uid);
|
|
203
|
+
const escapedMappedUid = (0, cli_utilities_1.escapeRegExp)(mappedUids[uid]);
|
|
204
|
+
entry = entry.replace(new RegExp(sanitizedUid, 'img'), escapedMappedUid);
|
|
203
205
|
mapped.push(uid);
|
|
204
206
|
}
|
|
205
207
|
else {
|
|
@@ -22,6 +22,14 @@ const setupConfig = async (importCmdFlags) => {
|
|
|
22
22
|
config = merge_1.default.recursive(config, externalConfig);
|
|
23
23
|
}
|
|
24
24
|
config.contentDir = importCmdFlags['data'] || importCmdFlags['data-dir'] || config.data || (await (0, interactive_1.askContentDir)());
|
|
25
|
+
const pattern = /[*$%#<>{}!&?]/g;
|
|
26
|
+
if (pattern.test(config.contentDir)) {
|
|
27
|
+
cli_utilities_1.cliux.print(`\nPlease add a directory path without any of the special characters: (*,&,{,},[,],$,%,<,>,?,!)`, {
|
|
28
|
+
color: 'yellow',
|
|
29
|
+
});
|
|
30
|
+
config.contentDir = await (0, interactive_1.askContentDir)();
|
|
31
|
+
}
|
|
32
|
+
config.contentDir = config.contentDir.replace(/['"]/g, '');
|
|
25
33
|
config.contentDir = path.resolve(config.contentDir);
|
|
26
34
|
//Note to support the old key
|
|
27
35
|
config.data = config.contentDir;
|
package/lib/utils/interactive.js
CHANGED
|
@@ -7,11 +7,13 @@ const path = tslib_1.__importStar(require("path"));
|
|
|
7
7
|
const first_1 = tslib_1.__importDefault(require("lodash/first"));
|
|
8
8
|
const split_1 = tslib_1.__importDefault(require("lodash/split"));
|
|
9
9
|
const askContentDir = async () => {
|
|
10
|
-
|
|
10
|
+
let result = await cli_utilities_1.cliux.inquire({
|
|
11
11
|
type: 'input',
|
|
12
12
|
message: 'Enter the path for the content',
|
|
13
13
|
name: 'dir',
|
|
14
|
+
validate: cli_utilities_1.validatePath,
|
|
14
15
|
});
|
|
16
|
+
result = result.replace(/["']/g, '');
|
|
15
17
|
return path.resolve(result);
|
|
16
18
|
};
|
|
17
19
|
exports.askContentDir = askContentDir;
|
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, path_1.join)((_a = config === null || config === void 0 ? void 0 : config.data) !== null && _a !== void 0 ? _a : process.cwd(), 'logs', 'import');
|
|
25
|
+
const basePath = (0, cli_utilities_1.pathValidator)((0, path_1.join)((_a = config === null || config === void 0 ? void 0 : config.data) !== 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/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-import",
|
|
3
3
|
"description": "Contentstack CLI plugin to import content into stack",
|
|
4
|
-
"version": "1.14.
|
|
4
|
+
"version": "1.14.2",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@contentstack/cli-audit": "~1.
|
|
8
|
+
"@contentstack/cli-audit": "~1.5.0",
|
|
9
9
|
"@contentstack/cli-command": "~1.2.16",
|
|
10
|
-
"@contentstack/cli-utilities": "~1.
|
|
10
|
+
"@contentstack/cli-utilities": "~1.6.0",
|
|
11
11
|
"@contentstack/management": "~1.15.3",
|
|
12
12
|
"@oclif/core": "^2.9.3",
|
|
13
13
|
"big-json": "^3.2.0",
|