@contentstack/cli-cm-import 1.4.0 → 1.5.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/oclif.manifest.json +1 -1
- package/package.json +12 -8
- package/src/app.js +2 -2
- package/src/commands/cm/stacks/import.js +5 -10
- package/src/lib/import/marketplace-apps.js +5 -5
- package/src/lib/util/import-flags.js +2 -12
- package/src/lib/util/index.js +2 -2
- package/src/lib/util/login.js +3 -4
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-import
|
|
|
37
37
|
$ csdx COMMAND
|
|
38
38
|
running command...
|
|
39
39
|
$ csdx (--version)
|
|
40
|
-
@contentstack/cli-cm-import/1.
|
|
40
|
+
@contentstack/cli-cm-import/1.5.0 linux-x64 node-v16.20.0
|
|
41
41
|
$ csdx --help [COMMAND]
|
|
42
42
|
USAGE
|
|
43
43
|
$ csdx COMMAND
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-import",
|
|
3
3
|
"description": "Contentstack CLI plugin to import content into stack",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.5.0",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@contentstack/cli-command": "^1.2.
|
|
9
|
-
"@contentstack/cli-utilities": "^1.2.
|
|
8
|
+
"@contentstack/cli-command": "^1.2.1",
|
|
9
|
+
"@contentstack/cli-utilities": "^1.2.1",
|
|
10
10
|
"@oclif/config": "^1.18.3",
|
|
11
11
|
"big-json": "^3.2.0",
|
|
12
12
|
"bluebird": "^3.7.2",
|
|
@@ -52,11 +52,6 @@
|
|
|
52
52
|
"version": "oclif readme && git add README.md",
|
|
53
53
|
"clean": "rm -rf ./node_modules tsconfig.build.tsbuildinfo"
|
|
54
54
|
},
|
|
55
|
-
"csdxConfig": {
|
|
56
|
-
"expiredCommands": {
|
|
57
|
-
"cm:import": "csdx cm:stacks:import"
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
55
|
"main": "./src/commands/cm/stacks/import.js",
|
|
61
56
|
"license": "MIT",
|
|
62
57
|
"oclif": {
|
|
@@ -64,5 +59,14 @@
|
|
|
64
59
|
"bin": "csdx",
|
|
65
60
|
"repositoryPrefix": "<%- repo %>/blob/main/packages/contentstack-import/<%- commandPath %>"
|
|
66
61
|
},
|
|
62
|
+
"csdxConfig": {
|
|
63
|
+
"expiredCommands": {
|
|
64
|
+
"cm:import": "csdx cm:stacks:import"
|
|
65
|
+
},
|
|
66
|
+
"shortCommandName": {
|
|
67
|
+
"cm:stacks:import": "IMPRT",
|
|
68
|
+
"cm:import": "O-IMPRT"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
67
71
|
"repository": "https://github.com/contentstack/cli"
|
|
68
72
|
}
|
package/src/app.js
CHANGED
|
@@ -11,7 +11,7 @@ const chalk = require('chalk');
|
|
|
11
11
|
const util = require('./lib/util/index');
|
|
12
12
|
const login = require('./lib/util/login');
|
|
13
13
|
const { addlogs } = require('./lib/util/log');
|
|
14
|
-
const { managementSDKClient } = require('@contentstack/cli-utilities');
|
|
14
|
+
const { managementSDKClient, isAuthenticated } = require('@contentstack/cli-utilities');
|
|
15
15
|
|
|
16
16
|
exports.initial = (configData) => {
|
|
17
17
|
return new Promise(async (resolve, reject) => {
|
|
@@ -58,7 +58,7 @@ exports.initial = (configData) => {
|
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
if (config) {
|
|
61
|
-
if ((config.email && config.password) ||
|
|
61
|
+
if ((config.email && config.password) || isAuthenticated()) {
|
|
62
62
|
login(config).then(backupAndImportData(APIClient, stackAPIClient)).catch(reject);
|
|
63
63
|
} else if (config.management_token) {
|
|
64
64
|
await backupAndImportData(APIClient, stackAPIClient);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const _ = require('lodash');
|
|
2
2
|
const defaultConfig = require('../../../config/default');
|
|
3
3
|
const { Command } = require('@contentstack/cli-command');
|
|
4
|
-
const {
|
|
4
|
+
const { flags, printFlagDeprecation, isAuthenticated } = require('@contentstack/cli-utilities');
|
|
5
5
|
const {
|
|
6
6
|
configWithMToken,
|
|
7
7
|
parameterWithMToken,
|
|
@@ -21,7 +21,6 @@ class ImportCommand extends Command {
|
|
|
21
21
|
const moduleName = importCommandFlags.module;
|
|
22
22
|
const backupdir = importCommandFlags['backup-dir'];
|
|
23
23
|
const alias = importCommandFlags['alias'] || importCommandFlags['management-token-alias'];
|
|
24
|
-
let _authToken = configHandler.get('authtoken');
|
|
25
24
|
importCommandFlags.branchName = importCommandFlags.branch;
|
|
26
25
|
importCommandFlags.importWebhookStatus = importCommandFlags['import-webhook-status'];
|
|
27
26
|
delete importCommandFlags.branch;
|
|
@@ -41,13 +40,12 @@ class ImportCommand extends Command {
|
|
|
41
40
|
if (managementTokens) {
|
|
42
41
|
let result;
|
|
43
42
|
|
|
44
|
-
if ((extConfig &&
|
|
43
|
+
if ((extConfig && isAuthenticated()) || alias) {
|
|
45
44
|
result = configWithMToken(
|
|
46
45
|
extConfig,
|
|
47
46
|
managementTokens,
|
|
48
47
|
moduleName,
|
|
49
48
|
host,
|
|
50
|
-
_authToken,
|
|
51
49
|
backupdir,
|
|
52
50
|
importCommandFlags,
|
|
53
51
|
);
|
|
@@ -57,7 +55,6 @@ class ImportCommand extends Command {
|
|
|
57
55
|
data,
|
|
58
56
|
moduleName,
|
|
59
57
|
host,
|
|
60
|
-
_authToken,
|
|
61
58
|
backupdir,
|
|
62
59
|
importCommandFlags,
|
|
63
60
|
);
|
|
@@ -66,7 +63,6 @@ class ImportCommand extends Command {
|
|
|
66
63
|
managementTokens,
|
|
67
64
|
moduleName,
|
|
68
65
|
host,
|
|
69
|
-
_authToken,
|
|
70
66
|
backupdir,
|
|
71
67
|
importCommandFlags,
|
|
72
68
|
);
|
|
@@ -76,14 +72,13 @@ class ImportCommand extends Command {
|
|
|
76
72
|
} else {
|
|
77
73
|
console.log('management Token is not present please add managment token first');
|
|
78
74
|
}
|
|
79
|
-
} else if (
|
|
75
|
+
} else if (isAuthenticated()) {
|
|
80
76
|
let result;
|
|
81
77
|
|
|
82
78
|
if (extConfig) {
|
|
83
|
-
result = configWithAuthToken(extConfig,
|
|
79
|
+
result = configWithAuthToken(extConfig, moduleName, host, backupdir, importCommandFlags);
|
|
84
80
|
} else if (targetStack && data) {
|
|
85
81
|
result = parametersWithAuthToken(
|
|
86
|
-
_authToken,
|
|
87
82
|
targetStack,
|
|
88
83
|
data,
|
|
89
84
|
moduleName,
|
|
@@ -92,7 +87,7 @@ class ImportCommand extends Command {
|
|
|
92
87
|
importCommandFlags,
|
|
93
88
|
);
|
|
94
89
|
} else {
|
|
95
|
-
result = withoutParametersWithAuthToken(
|
|
90
|
+
result = withoutParametersWithAuthToken(moduleName, host, backupdir, importCommandFlags);
|
|
96
91
|
}
|
|
97
92
|
|
|
98
93
|
result.then(resolve).catch(reject);
|
|
@@ -9,7 +9,7 @@ const path = require('path');
|
|
|
9
9
|
const chalk = require('chalk');
|
|
10
10
|
const mkdirp = require('mkdirp');
|
|
11
11
|
const contentstack = require('@contentstack/management');
|
|
12
|
-
const { cliux, HttpClient, NodeCrypto, managementSDKClient } = require('@contentstack/cli-utilities');
|
|
12
|
+
const { cliux, HttpClient, NodeCrypto, managementSDKClient, configHandler, isAuthenticated } = require('@contentstack/cli-utilities');
|
|
13
13
|
|
|
14
14
|
const { formatError } = require('../util');
|
|
15
15
|
let config = require('../../config/default');
|
|
@@ -44,7 +44,7 @@ module.exports = class ImportMarketplaceApps {
|
|
|
44
44
|
|
|
45
45
|
if (_.isEmpty(this.marketplaceApps)) {
|
|
46
46
|
return Promise.resolve();
|
|
47
|
-
} else if (!
|
|
47
|
+
} else if (!isAuthenticated()) {
|
|
48
48
|
cliux.print(
|
|
49
49
|
'\nWARNING!!! To import Marketplace apps, you must be logged in. Please check csdx auth:login --help to log in\n',
|
|
50
50
|
{ color: 'yellow' },
|
|
@@ -53,13 +53,13 @@ module.exports = class ImportMarketplaceApps {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
this.developerHubBaseUrl = this.config.developerHubBaseUrl || (await getDeveloperHubUrl(this.config));
|
|
56
|
-
this.client = contentstack.client({ authtoken:
|
|
56
|
+
this.client = contentstack.client({ authtoken: configHandler.get('authtoken'), endpoint: this.developerHubBaseUrl });
|
|
57
57
|
|
|
58
58
|
await this.getOrgUid();
|
|
59
59
|
|
|
60
60
|
this.httpClient = new HttpClient({
|
|
61
61
|
headers: {
|
|
62
|
-
authtoken:
|
|
62
|
+
authtoken: configHandler.get('authtoken'),
|
|
63
63
|
organization_uid: this.config.org_uid,
|
|
64
64
|
},
|
|
65
65
|
});
|
|
@@ -72,7 +72,7 @@ module.exports = class ImportMarketplaceApps {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
async getOrgUid() {
|
|
75
|
-
if (
|
|
75
|
+
if (isAuthenticated()) {
|
|
76
76
|
const tempAPIClient = await managementSDKClient({ host: this.config.host });
|
|
77
77
|
const tempStackData = await tempAPIClient
|
|
78
78
|
.stack({ api_key: this.config.target_stack })
|
|
@@ -14,7 +14,6 @@ exports.configWithMToken = function (
|
|
|
14
14
|
managementTokens,
|
|
15
15
|
moduleName,
|
|
16
16
|
host,
|
|
17
|
-
_authToken,
|
|
18
17
|
backupdir,
|
|
19
18
|
importCommandFlags,
|
|
20
19
|
) {
|
|
@@ -40,7 +39,6 @@ exports.configWithMToken = function (
|
|
|
40
39
|
defaultConfig.useBackedupDir = backupdir;
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
defaultConfig.auth_token = _authToken;
|
|
44
42
|
defaultConfig = _.merge(defaultConfig, externalConfig);
|
|
45
43
|
|
|
46
44
|
if(!defaultConfig.data) {
|
|
@@ -61,14 +59,12 @@ exports.parameterWithMToken = function (
|
|
|
61
59
|
data,
|
|
62
60
|
moduleName,
|
|
63
61
|
host,
|
|
64
|
-
_authToken,
|
|
65
62
|
backupdir,
|
|
66
63
|
importCommandFlags,
|
|
67
64
|
) {
|
|
68
65
|
return new Promise(async function (resolve, reject) {
|
|
69
66
|
defaultConfig.management_token = managementTokens.token;
|
|
70
67
|
defaultConfig.target_stack = managementTokens.apiKey;
|
|
71
|
-
defaultConfig.auth_token = _authToken;
|
|
72
68
|
defaultConfig.branchName = importCommandFlags.branchName;
|
|
73
69
|
defaultConfig.importWebhookStatus = importCommandFlags.importWebhookStatus;
|
|
74
70
|
if (moduleName && moduleName !== undefined) {
|
|
@@ -88,7 +84,6 @@ exports.withoutParameterMToken = async (
|
|
|
88
84
|
managementTokens,
|
|
89
85
|
moduleName,
|
|
90
86
|
host,
|
|
91
|
-
_authToken,
|
|
92
87
|
backupdir,
|
|
93
88
|
importCommandFlags,
|
|
94
89
|
) => {
|
|
@@ -96,7 +91,6 @@ exports.withoutParameterMToken = async (
|
|
|
96
91
|
const exporteddata = await cliux.prompt(message.promptMessageList.promptPathStoredData);
|
|
97
92
|
defaultConfig.management_token = managementTokens.token;
|
|
98
93
|
defaultConfig.target_stack = managementTokens.apiKey;
|
|
99
|
-
defaultConfig.auth_token = _authToken;
|
|
100
94
|
defaultConfig.branchName = importCommandFlags.branchName;
|
|
101
95
|
defaultConfig.importWebhookStatus = importCommandFlags.importWebhookStatus;
|
|
102
96
|
if (moduleName && moduleName !== undefined) {
|
|
@@ -111,10 +105,9 @@ exports.withoutParameterMToken = async (
|
|
|
111
105
|
});
|
|
112
106
|
};
|
|
113
107
|
|
|
114
|
-
exports.configWithAuthToken = function (config,
|
|
108
|
+
exports.configWithAuthToken = function (config, moduleName, host, backupdir, importCommandFlags) {
|
|
115
109
|
return new Promise(async function (resolve, reject) {
|
|
116
110
|
let externalConfig = require(config);
|
|
117
|
-
defaultConfig.auth_token = _authToken;
|
|
118
111
|
defaultConfig.branchName = importCommandFlags.branchName;
|
|
119
112
|
defaultConfig.importWebhookStatus = importCommandFlags.importWebhookStatus;
|
|
120
113
|
if (moduleName && moduleName !== undefined) {
|
|
@@ -140,7 +133,6 @@ exports.configWithAuthToken = function (config, _authToken, moduleName, host, ba
|
|
|
140
133
|
};
|
|
141
134
|
|
|
142
135
|
exports.parametersWithAuthToken = function (
|
|
143
|
-
_authToken,
|
|
144
136
|
targetStack,
|
|
145
137
|
data,
|
|
146
138
|
moduleName,
|
|
@@ -149,7 +141,6 @@ exports.parametersWithAuthToken = function (
|
|
|
149
141
|
importCommandFlags,
|
|
150
142
|
) {
|
|
151
143
|
return new Promise(async function (resolve, reject) {
|
|
152
|
-
defaultConfig.auth_token = _authToken;
|
|
153
144
|
defaultConfig.target_stack = targetStack;
|
|
154
145
|
defaultConfig.branchName = importCommandFlags.branchName;
|
|
155
146
|
defaultConfig.importWebhookStatus = importCommandFlags.importWebhookStatus;
|
|
@@ -168,11 +159,10 @@ exports.parametersWithAuthToken = function (
|
|
|
168
159
|
});
|
|
169
160
|
};
|
|
170
161
|
|
|
171
|
-
exports.withoutParametersWithAuthToken = async (
|
|
162
|
+
exports.withoutParametersWithAuthToken = async (moduleName, host, backupdir, importCommandFlags) => {
|
|
172
163
|
return new Promise(async function (resolve, reject) {
|
|
173
164
|
const stackUid = await cliux.prompt(message.promptMessageList.promptTargetStack);
|
|
174
165
|
const exporteddata = await cliux.prompt(message.promptMessageList.promptPathStoredData);
|
|
175
|
-
defaultConfig.auth_token = _authToken;
|
|
176
166
|
defaultConfig.target_stack = stackUid;
|
|
177
167
|
defaultConfig.data = exporteddata;
|
|
178
168
|
defaultConfig.branchName = importCommandFlags.branchName;
|
package/src/lib/util/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
const _ = require('lodash');
|
|
9
|
-
const { HttpClient, managementSDKClient } = require('@contentstack/cli-utilities');
|
|
9
|
+
const { HttpClient, managementSDKClient, isAuthenticated } = require('@contentstack/cli-utilities');
|
|
10
10
|
const fs = require('./fs');
|
|
11
11
|
const path = require('path');
|
|
12
12
|
const chalk = require('chalk');
|
|
@@ -33,7 +33,7 @@ exports.validateConfig = (importConfig) => {
|
|
|
33
33
|
!importConfig.password &&
|
|
34
34
|
!importConfig.management_token &&
|
|
35
35
|
importConfig.target_stack &&
|
|
36
|
-
!
|
|
36
|
+
!isAuthenticated()
|
|
37
37
|
) {
|
|
38
38
|
addlogs(importConfig, chalk.red('Kindly provide management_token or email and password'), 'error');
|
|
39
39
|
return 'error';
|
package/src/lib/util/login.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
const chalk = require('chalk');
|
|
9
9
|
|
|
10
10
|
const { addlogs } = require('../util/log');
|
|
11
|
-
const { managementSDKClient } = require('@contentstack/cli-utilities');
|
|
11
|
+
const { managementSDKClient, isAuthenticated } = require('@contentstack/cli-utilities');
|
|
12
12
|
|
|
13
13
|
module.exports = (config) => {
|
|
14
14
|
return new Promise((resolve, reject) => {
|
|
@@ -21,10 +21,9 @@ module.exports = (config) => {
|
|
|
21
21
|
.then((response) => {
|
|
22
22
|
// eslint-disable-next-line no-console
|
|
23
23
|
console.log(chalk.green('Contentstack account authenticated successfully!'));
|
|
24
|
-
config.authtoken = response.user.authtoken;
|
|
25
24
|
config.headers = {
|
|
26
25
|
api_key: config.target_stack,
|
|
27
|
-
authtoken:
|
|
26
|
+
authtoken: response.user.authtoken,
|
|
28
27
|
'X-User-Agent': 'contentstack-import/v',
|
|
29
28
|
};
|
|
30
29
|
return resolve(config);
|
|
@@ -32,7 +31,7 @@ module.exports = (config) => {
|
|
|
32
31
|
.catch(reject);
|
|
33
32
|
} else if (config.management_token) {
|
|
34
33
|
return resolve();
|
|
35
|
-
} else if (
|
|
34
|
+
} else if (isAuthenticated()) {
|
|
36
35
|
const stackAPIClient = APIClient.stack({
|
|
37
36
|
api_key: config.target_stack,
|
|
38
37
|
management_token: config.management_token,
|