@contentstack/cli-cm-import 1.2.4 → 1.3.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 +84 -24
- package/oclif.manifest.json +129 -1
- package/package.json +6 -8
- package/src/app.js +47 -59
- package/src/commands/cm/stacks/import.js +1 -1
- package/src/config/default.js +1 -1
- package/src/lib/import/assets.js +261 -247
- package/src/lib/import/content-types.js +19 -21
- package/src/lib/import/custom-roles.js +7 -17
- package/src/lib/import/entries.js +344 -360
- package/src/lib/import/environments.js +5 -7
- package/src/lib/import/extensions.js +6 -9
- package/src/lib/import/global-fields.js +7 -17
- package/src/lib/import/labels.js +5 -8
- package/src/lib/import/locales.js +5 -10
- package/src/lib/import/marketplace-apps.js +389 -414
- package/src/lib/import/webhooks.js +4 -6
- package/src/lib/import/workflows.js +6 -15
- package/src/lib/util/extensionsUidReplace.js +2 -33
- package/src/lib/util/index.js +71 -72
- package/src/lib/util/login.js +45 -42
- package/src/lib/util/lookupReplaceAssets.js +6 -97
- package/src/lib/util/marketplace-app-helper.js +10 -37
- package/src/lib/util/upload.js +30 -23
- package/src/lib/util/contentstack-management-sdk.js +0 -41
package/src/lib/util/upload.js
CHANGED
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const debug = require('debug')('util:requests');
|
|
10
|
+
const MAX_RETRY_LIMIT = 5;
|
|
11
|
+
const Bluebird = require('bluebird');
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
13
|
+
const util = require('./index');
|
|
14
|
+
const config = util.getConfig();
|
|
15
|
+
const { managementSDKClient } = require('@contentstack/cli-utilities');
|
|
16
16
|
|
|
17
17
|
function validate(req) {
|
|
18
18
|
if (typeof req !== 'object') {
|
|
@@ -20,27 +20,34 @@ function validate(req) {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
const upload = (module.exports = function (req, fsPath, RETRY) {
|
|
24
24
|
return new Bluebird(function (resolve, reject) {
|
|
25
25
|
try {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
managementSDKClient(config)
|
|
27
|
+
.then((APIClient) => {
|
|
28
|
+
validate(req);
|
|
29
|
+
if (typeof RETRY !== 'number') {
|
|
30
|
+
RETRY = 1;
|
|
31
|
+
} else if (RETRY > MAX_RETRY_LIMIT) {
|
|
32
|
+
return reject(new Error('Max retry limit exceeded!'));
|
|
33
|
+
}
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
req.upload = fsPath;
|
|
36
|
+
const stackAPIClient = APIClient.stack({
|
|
37
|
+
api_key: config.target_stack,
|
|
38
|
+
management_token: config.management_token,
|
|
39
|
+
});
|
|
40
|
+
stackAPIClient
|
|
41
|
+
.asset()
|
|
42
|
+
.create(req)
|
|
43
|
+
.then((response) => {
|
|
44
|
+
return resolve(response);
|
|
45
|
+
})
|
|
46
|
+
.catch((error) => {
|
|
47
|
+
return reject(error);
|
|
48
|
+
});
|
|
40
49
|
})
|
|
41
|
-
.catch(
|
|
42
|
-
return reject(error);
|
|
43
|
-
});
|
|
50
|
+
.catch(reject);
|
|
44
51
|
} catch (error) {
|
|
45
52
|
debug(error);
|
|
46
53
|
return reject(error);
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const contentstacksdk = require('@contentstack/management');
|
|
2
|
-
const https = require('https');
|
|
3
|
-
|
|
4
|
-
const { addlogs } = require('./log');
|
|
5
|
-
|
|
6
|
-
exports.Client = function (config) {
|
|
7
|
-
const option = {
|
|
8
|
-
host: config.host,
|
|
9
|
-
authtoken: config.auth_token,
|
|
10
|
-
management_token: config.management_token,
|
|
11
|
-
api_key: config.target_stack,
|
|
12
|
-
maxContentLength: 100000000,
|
|
13
|
-
maxBodyLength: 1000000000,
|
|
14
|
-
maxRequests: 10,
|
|
15
|
-
retryLimit: 5,
|
|
16
|
-
timeout: 60000,
|
|
17
|
-
httpsAgent: new https.Agent({
|
|
18
|
-
maxSockets: 100,
|
|
19
|
-
maxFreeSockets: 10,
|
|
20
|
-
keepAlive: true,
|
|
21
|
-
timeout: 60000, // active socket keepalive for 60 seconds
|
|
22
|
-
freeSocketTimeout: 30000, // free socket keepalive for 30 seconds
|
|
23
|
-
}),
|
|
24
|
-
retryDelay: Math.floor(Math.random() * (8000 - 3000 + 1) + 3000),
|
|
25
|
-
logHandler: (level, data) => {},
|
|
26
|
-
retryCondition: (error) => {
|
|
27
|
-
// no async function should be used here
|
|
28
|
-
return error.response && (error.response.status === 429 || error.response.status === 408);
|
|
29
|
-
},
|
|
30
|
-
retryDelayOptions: {
|
|
31
|
-
base: 1000,
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
if (typeof config.branchName === 'string') {
|
|
35
|
-
option.headers = {
|
|
36
|
-
branch: config.branchName,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
const client = contentstacksdk.client(option);
|
|
40
|
-
return client;
|
|
41
|
-
};
|