@contentstack/cli-cm-export 0.1.1-beta.7 → 1.0.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/LICENSE +21 -0
- package/README.md +44 -24
- package/oclif.manifest.json +1 -1
- package/package.json +72 -68
- package/src/app.js +120 -66
- package/src/commands/cm/stacks/export.js +177 -0
- package/src/config/default.js +18 -58
- package/src/lib/export/assets.js +325 -223
- package/src/lib/export/content-types.js +76 -66
- package/src/lib/export/entries.js +190 -135
- package/src/lib/export/environments.js +52 -45
- package/src/lib/export/extensions.js +50 -43
- package/src/lib/export/global-fields.js +92 -80
- package/src/lib/export/labels.js +52 -44
- package/src/lib/export/locales.js +74 -41
- package/src/lib/export/stack.js +72 -47
- package/src/lib/export/webhooks.js +58 -48
- package/src/lib/export/workflows.js +55 -44
- package/src/lib/util/contentstack-management-sdk.js +30 -4
- package/src/lib/util/export-flags.js +158 -87
- package/src/lib/util/helper.js +20 -20
- package/src/lib/util/index.js +32 -19
- package/src/lib/util/log.js +109 -53
- package/src/lib/util/login.js +56 -41
- package/src/lib/util/setup-branches.js +53 -0
- package/src/commands/cm/export.js +0 -123
- package/src/lib/util/request.js +0 -83
|
@@ -4,19 +4,18 @@
|
|
|
4
4
|
* MIT Licensed
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const mkdirp = require('mkdirp')
|
|
8
|
-
const path = require('path')
|
|
9
|
-
const chalk = require('chalk')
|
|
10
|
-
|
|
11
|
-
const helper = require('../util/helper')
|
|
12
|
-
const {addlogs} = require('../util/log')
|
|
13
|
-
let config = require('../../config/default')
|
|
14
|
-
let localeConfig = config.modules.locales
|
|
15
|
-
const masterLocale = config.master_locale
|
|
16
|
-
let requiredKeys = localeConfig.requiredKeys
|
|
17
|
-
let stack = require('../util/contentstack-management-sdk')
|
|
18
|
-
|
|
7
|
+
const mkdirp = require('mkdirp');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const chalk = require('chalk');
|
|
19
10
|
|
|
11
|
+
const helper = require('../util/helper');
|
|
12
|
+
const { addlogs } = require('../util/log');
|
|
13
|
+
let config = require('../../config/default');
|
|
14
|
+
let localeConfig = config.modules.locales;
|
|
15
|
+
const masterLocale = config.master_locale;
|
|
16
|
+
let requiredKeys = localeConfig.requiredKeys;
|
|
17
|
+
let stack = require('../util/contentstack-management-sdk');
|
|
18
|
+
let client
|
|
20
19
|
function ExportLocales() {
|
|
21
20
|
this.qs = {
|
|
22
21
|
include_count: true,
|
|
@@ -29,42 +28,76 @@ function ExportLocales() {
|
|
|
29
28
|
only: {
|
|
30
29
|
BASE: requiredKeys,
|
|
31
30
|
},
|
|
32
|
-
}
|
|
33
|
-
this.locales = {}
|
|
31
|
+
};
|
|
32
|
+
this.locales = {};
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
ExportLocales.prototype.start = function (credentialConfig) {
|
|
37
|
-
|
|
36
|
+
this.locales = {};
|
|
37
|
+
addlogs(credentialConfig, 'Starting locale export', 'success');
|
|
38
|
+
let self = this;
|
|
39
|
+
config = credentialConfig;
|
|
40
|
+
self.localesFolderPath = path.resolve(config.data, config.branchName || '', localeConfig.dirName);
|
|
41
|
+
mkdirp.sync(self.localesFolderPath);
|
|
42
|
+
client = stack.Client(config);
|
|
43
|
+
const apiDetails = {
|
|
44
|
+
limit: 100,
|
|
45
|
+
skip: 0,
|
|
46
|
+
include_count: true,
|
|
47
|
+
}
|
|
48
|
+
return self.getLocales(apiDetails)
|
|
49
|
+
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
ExportLocales.prototype.getLocales = function (apiDetails) {
|
|
38
53
|
let self = this
|
|
39
|
-
config = credentialConfig
|
|
40
|
-
let localesFolderPath = path.resolve(config.data, localeConfig.dirName)
|
|
41
|
-
mkdirp.sync(localesFolderPath)
|
|
42
54
|
|
|
43
|
-
let client = stack.Client(config)
|
|
44
55
|
return new Promise(function (resolve, reject) {
|
|
45
|
-
client
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
client
|
|
57
|
+
.stack({ api_key: config.source_stack, management_token: config.management_token })
|
|
58
|
+
.locale()
|
|
59
|
+
.query({ ...self.qs, ...apiDetails })
|
|
60
|
+
.find()
|
|
61
|
+
.then((localeResponse) => {
|
|
62
|
+
if (localeResponse.items.length !== 0) {
|
|
63
|
+
localeResponse.items.forEach(function (locale) {
|
|
64
|
+
addlogs(config, locale.name + ' locale was exported successfully', 'success');
|
|
65
|
+
for (const key in locale) {
|
|
66
|
+
if (requiredKeys.indexOf(key) === -1) {
|
|
67
|
+
delete locale[key];
|
|
68
|
+
}
|
|
53
69
|
}
|
|
70
|
+
self.locales[locale.uid] = locale;
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
helper.writeFile(path.join(self.localesFolderPath, localeConfig.fileName), self.locales);
|
|
74
|
+
|
|
75
|
+
apiDetails.skip += apiDetails.limit;
|
|
76
|
+
|
|
77
|
+
if (apiDetails.skip > localeResponse.count) {
|
|
78
|
+
addlogs(config, chalk.green('All the locales have been exported successfully'), 'success');
|
|
79
|
+
return resolve();
|
|
54
80
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
81
|
+
|
|
82
|
+
return self
|
|
83
|
+
.getLocales(apiDetails)
|
|
84
|
+
.then(resolve)
|
|
85
|
+
.catch((error) => {
|
|
86
|
+
console.log('Get locales errror', error && error.message);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
} else if (localeResponse.items.length === 0) {
|
|
90
|
+
addlogs(config, 'No languages found except the master language', 'success');
|
|
91
|
+
helper.writeFile(path.join(self.localesFolderPath, localeConfig.fileName), self.locales);
|
|
92
|
+
return resolve();
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
.catch((error) => {
|
|
97
|
+
addlogs(config, error, 'error');
|
|
98
|
+
return reject(error);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
68
101
|
}
|
|
69
102
|
|
|
70
|
-
module.exports = new ExportLocales()
|
|
103
|
+
module.exports = new ExportLocales();
|
package/src/lib/export/stack.js
CHANGED
|
@@ -4,64 +4,89 @@
|
|
|
4
4
|
* MIT Licensed
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
var chalk = require('chalk')
|
|
8
|
-
var mkdirp = require('mkdirp')
|
|
9
|
-
var path = require('path')
|
|
7
|
+
var chalk = require('chalk');
|
|
8
|
+
var mkdirp = require('mkdirp');
|
|
9
|
+
var path = require('path');
|
|
10
10
|
|
|
11
|
-
var app = require('../../app')
|
|
12
|
-
var helper = require('../util/helper')
|
|
13
|
-
var {addlogs} = require('../util/log')
|
|
14
|
-
const stack = require('../util/contentstack-management-sdk')
|
|
11
|
+
var app = require('../../app');
|
|
12
|
+
var helper = require('../util/helper');
|
|
13
|
+
var { addlogs } = require('../util/log');
|
|
14
|
+
const stack = require('../util/contentstack-management-sdk');
|
|
15
15
|
|
|
16
|
+
let config = require('../../config/default');
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
var stackConfig = config.modules.stack;
|
|
19
|
+
let client;
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
let client
|
|
21
|
-
|
|
22
|
-
function ExportStack () {
|
|
21
|
+
function ExportStack() {
|
|
23
22
|
this.requestOption = {
|
|
24
23
|
uri: config.host + config.apis.stacks,
|
|
25
24
|
headers: config.headers,
|
|
26
|
-
json: true
|
|
27
|
-
}
|
|
25
|
+
json: true,
|
|
26
|
+
};
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
ExportStack.prototype.start = function (credentialConfig) {
|
|
31
|
-
config = credentialConfig
|
|
32
|
-
client = stack.Client(config)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
} else if(config.preserveStackVersion) {
|
|
49
|
-
addlogs(config, 'Exporting stack details', 'success')
|
|
50
|
-
let stackFolderPath = path.resolve(config.data, stackConfig.dirName)
|
|
51
|
-
let stackContentsFile = path.resolve(stackFolderPath, stackConfig.fileName)
|
|
52
|
-
|
|
53
|
-
mkdirp.sync(stackFolderPath)
|
|
54
|
-
|
|
30
|
+
config = credentialConfig;
|
|
31
|
+
client = stack.Client(config);
|
|
32
|
+
const self = this
|
|
33
|
+
if (!config.preserveStackVersion && !config.hasOwnProperty('master_locale')) {
|
|
34
|
+
const apiDetails = {
|
|
35
|
+
limit: 100,
|
|
36
|
+
skip: 0,
|
|
37
|
+
include_count: true,
|
|
38
|
+
}
|
|
39
|
+
return self.getLocales(apiDetails)
|
|
40
|
+
} else if (config.preserveStackVersion) {
|
|
41
|
+
addlogs(config, 'Exporting stack details', 'success');
|
|
42
|
+
let stackFolderPath = path.resolve(config.data, stackConfig.dirName);
|
|
43
|
+
let stackContentsFile = path.resolve(stackFolderPath, stackConfig.fileName);
|
|
44
|
+
|
|
45
|
+
mkdirp.sync(stackFolderPath);
|
|
46
|
+
|
|
55
47
|
return new Promise((resolve, reject) => {
|
|
56
|
-
return client
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
48
|
+
return client
|
|
49
|
+
.stack({ api_key: config.source_stack })
|
|
50
|
+
.fetch()
|
|
51
|
+
.then((response) => {
|
|
52
|
+
helper.writeFile(stackContentsFile, response);
|
|
53
|
+
addlogs(config, 'Exported stack details successfully!', 'success');
|
|
54
|
+
return resolve(response);
|
|
55
|
+
})
|
|
56
|
+
.catch(reject);
|
|
57
|
+
});
|
|
64
58
|
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
ExportStack.prototype.getLocales = function (apiDetails) {
|
|
62
|
+
let self = this
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
const result = client
|
|
65
|
+
.stack({ api_key: config.source_stack, management_token: config.management_token })
|
|
66
|
+
.locale()
|
|
67
|
+
.query(apiDetails)
|
|
68
|
+
|
|
69
|
+
result
|
|
70
|
+
.find()
|
|
71
|
+
.then((response) => {
|
|
72
|
+
const masterLocalObj = response.items.find((obj) => {
|
|
73
|
+
if (obj.fallback_locale === null) {
|
|
74
|
+
return obj;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
apiDetails.skip += apiDetails.limit;
|
|
78
|
+
if (masterLocalObj) { return resolve(masterLocalObj); }
|
|
79
|
+
else if (apiDetails.skip <= response.count) {
|
|
80
|
+
return resolve(self.getLocales(apiDetails))
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
return reject('Master locale not found');
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
.catch((error) => {
|
|
87
|
+
return reject(error);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
65
90
|
}
|
|
66
91
|
|
|
67
|
-
module.exports = new ExportStack()
|
|
92
|
+
module.exports = new ExportStack();
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Contentstack Export
|
|
3
|
-
* Copyright (c) 2019 Contentstack LLC
|
|
4
|
-
* MIT Licensed
|
|
5
|
-
*/
|
|
2
|
+
* Contentstack Export
|
|
3
|
+
* Copyright (c) 2019 Contentstack LLC
|
|
4
|
+
* MIT Licensed
|
|
5
|
+
*/
|
|
6
6
|
|
|
7
|
-
const mkdirp = require('mkdirp')
|
|
8
|
-
const path = require('path')
|
|
9
|
-
const chalk = require('chalk')
|
|
7
|
+
const mkdirp = require('mkdirp');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const chalk = require('chalk');
|
|
10
10
|
|
|
11
|
-
const helper = require('../util/helper')
|
|
12
|
-
const {addlogs} = require('../util/log')
|
|
11
|
+
const helper = require('../util/helper');
|
|
12
|
+
const { addlogs } = require('../util/log');
|
|
13
13
|
|
|
14
|
-
let config = require('../../config/default')
|
|
15
|
-
const stack = require('../util/contentstack-management-sdk')
|
|
16
|
-
const webhooksConfig = config.modules.webhooks
|
|
17
|
-
let client
|
|
14
|
+
let config = require('../../config/default');
|
|
15
|
+
const stack = require('../util/contentstack-management-sdk');
|
|
16
|
+
const webhooksConfig = config.modules.webhooks;
|
|
17
|
+
let client;
|
|
18
18
|
|
|
19
19
|
// Create folder for environments
|
|
20
20
|
|
|
@@ -22,44 +22,54 @@ function ExportWebhooks() {
|
|
|
22
22
|
this.requestOptions = {
|
|
23
23
|
include_count: true,
|
|
24
24
|
asc: 'updated_at',
|
|
25
|
-
}
|
|
26
|
-
this.master = {}
|
|
27
|
-
this.webhooks = {}
|
|
25
|
+
};
|
|
26
|
+
this.master = {};
|
|
27
|
+
this.webhooks = {};
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
ExportWebhooks.prototype.start = function (credentialConfig) {
|
|
31
|
-
addlogs(config, 'Starting webhooks export', 'success')
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
addlogs(config, 'Starting webhooks export', 'success');
|
|
32
|
+
this.master = {};
|
|
33
|
+
this.webhooks = {};
|
|
34
|
+
let self = this;
|
|
35
|
+
config = credentialConfig;
|
|
36
|
+
client = stack.Client(config);
|
|
37
|
+
const webhooksFolderPath = path.resolve(config.data, config.branchName || '', webhooksConfig.dirName);
|
|
38
|
+
mkdirp.sync(webhooksFolderPath);
|
|
37
39
|
return new Promise(function (resolve, reject) {
|
|
38
|
-
client
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
client
|
|
41
|
+
.stack({ api_key: config.source_stack, management_token: config.management_token })
|
|
42
|
+
.webhook()
|
|
43
|
+
.fetchAll(self.requestOptions)
|
|
44
|
+
.then((webhooks) => {
|
|
45
|
+
if (webhooks.items.length !== 0) {
|
|
46
|
+
for (var i = 0, total = webhooks.count; i < total; i++) {
|
|
47
|
+
const webUid = webhooks.items[i].uid;
|
|
48
|
+
self.master[webUid] = '';
|
|
49
|
+
self.webhooks[webUid] = webhooks.items[i];
|
|
50
|
+
delete self.webhooks[webUid].uid;
|
|
51
|
+
delete self.webhooks[webUid].SYS_ACL;
|
|
52
|
+
}
|
|
53
|
+
helper.writeFile(path.join(webhooksFolderPath, webhooksConfig.fileName), self.webhooks);
|
|
54
|
+
addlogs(config, chalk.green('All the webhooks have been exported successfully'), 'success');
|
|
55
|
+
return resolve();
|
|
47
56
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
57
|
+
addlogs(config, 'No webhooks found', 'success');
|
|
58
|
+
return resolve();
|
|
59
|
+
})
|
|
60
|
+
.catch(function (error) {
|
|
61
|
+
if (error.statusCode === 401) {
|
|
62
|
+
addlogs(
|
|
63
|
+
config,
|
|
64
|
+
chalk.red('You are not allowed to export webhooks, Unless you provide email and password in config'),
|
|
65
|
+
'error',
|
|
66
|
+
);
|
|
67
|
+
return resolve();
|
|
68
|
+
}
|
|
69
|
+
addlogs(config, error, 'error');
|
|
70
|
+
return reject();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
};
|
|
64
74
|
|
|
65
|
-
module.exports = new ExportWebhooks()
|
|
75
|
+
module.exports = new ExportWebhooks();
|
|
@@ -4,56 +4,67 @@
|
|
|
4
4
|
* MIT Licensed
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const mkdirp = require('mkdirp')
|
|
8
|
-
const path = require('path')
|
|
9
|
-
const chalk = require('chalk')
|
|
7
|
+
const mkdirp = require('mkdirp');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const chalk = require('chalk');
|
|
10
10
|
|
|
11
|
-
let helper = require('../util/helper')
|
|
12
|
-
let {addlogs} = require('../util/log')
|
|
11
|
+
let helper = require('../util/helper');
|
|
12
|
+
let { addlogs } = require('../util/log');
|
|
13
13
|
|
|
14
|
-
const stack = require('../util/contentstack-management-sdk')
|
|
15
|
-
let config = require('../../config/default')
|
|
16
|
-
let workFlowConfig = config.modules.workflows
|
|
17
|
-
let client
|
|
14
|
+
const stack = require('../util/contentstack-management-sdk');
|
|
15
|
+
let config = require('../../config/default');
|
|
16
|
+
let workFlowConfig = config.modules.workflows;
|
|
17
|
+
let client;
|
|
18
18
|
|
|
19
19
|
function ExportWorkFlows() {
|
|
20
|
-
this.workflows = {}
|
|
20
|
+
this.workflows = {};
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
ExportWorkFlows.prototype.start = function (credentialConfig) {
|
|
24
|
-
addlogs(config, 'Starting workflow export', 'success')
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
addlogs(config, 'Starting workflow export', 'success');
|
|
25
|
+
this.workflows = {};
|
|
26
|
+
let self = this;
|
|
27
|
+
config = credentialConfig;
|
|
28
|
+
client = stack.Client(config);
|
|
28
29
|
|
|
29
|
-
let workflowsFolderPath = path.resolve(config.data, workFlowConfig.dirName)
|
|
30
|
-
mkdirp.sync(workflowsFolderPath)
|
|
31
|
-
return new Promise(function (resolve
|
|
32
|
-
return client
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
30
|
+
let workflowsFolderPath = path.resolve(config.data, config.branchName || '', workFlowConfig.dirName);
|
|
31
|
+
mkdirp.sync(workflowsFolderPath);
|
|
32
|
+
return new Promise(function (resolve) {
|
|
33
|
+
return client
|
|
34
|
+
.stack({ api_key: config.source_stack, management_token: config.management_token })
|
|
35
|
+
.workflow()
|
|
36
|
+
.fetchAll()
|
|
37
|
+
.then((response) => {
|
|
38
|
+
if (response.items.length !== 0) {
|
|
39
|
+
response.items.forEach(function (workflow) {
|
|
40
|
+
addlogs(config, workflow.name + ' workflow was exported successfully', 'success');
|
|
41
|
+
self.workflows[workflow.uid] = workflow;
|
|
42
|
+
let deleteItems = config.modules.workflows.invalidKeys;
|
|
43
|
+
deleteItems.forEach((e) => delete workflow[e]);
|
|
44
|
+
});
|
|
45
|
+
addlogs(config, chalk.green('All the workflow have been exported successfully'), 'success');
|
|
46
|
+
}
|
|
47
|
+
if (response.items.length === 0) {
|
|
48
|
+
addlogs(config, 'No workflow were found in the Stack', 'success');
|
|
49
|
+
}
|
|
50
|
+
helper.writeFile(path.join(workflowsFolderPath, workFlowConfig.fileName), self.workflows);
|
|
51
|
+
return resolve();
|
|
52
|
+
})
|
|
53
|
+
.catch(function (error) {
|
|
54
|
+
if (error.statusCode === 401) {
|
|
55
|
+
addlogs(
|
|
56
|
+
config,
|
|
57
|
+
chalk.red(
|
|
58
|
+
'You are not allowed to export workflow, Unless you provide email and password in config',
|
|
59
|
+
'error',
|
|
60
|
+
),
|
|
61
|
+
);
|
|
62
|
+
return resolve();
|
|
63
|
+
}
|
|
64
|
+
addlogs(config, error, 'error');
|
|
65
|
+
return resolve();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
};
|
|
58
69
|
|
|
59
|
-
module.exports = new ExportWorkFlows()
|
|
70
|
+
module.exports = new ExportWorkFlows();
|
|
@@ -1,13 +1,39 @@
|
|
|
1
|
-
const contentstacksdk = require('@contentstack/management')
|
|
1
|
+
const contentstacksdk = require('@contentstack/management');
|
|
2
|
+
const https = require('https');
|
|
3
|
+
|
|
4
|
+
const { addlogs } = require('./log');
|
|
2
5
|
|
|
3
6
|
exports.Client = function (config) {
|
|
4
7
|
const option = {
|
|
5
8
|
host: config.host,
|
|
6
9
|
authtoken: config.auth_token,
|
|
7
10
|
api_key: config.source_stack,
|
|
11
|
+
maxRequests: 10,
|
|
12
|
+
retryLimit: 5,
|
|
13
|
+
timeout: 60000,
|
|
14
|
+
httpsAgent: new https.Agent({
|
|
15
|
+
maxSockets: 100,
|
|
16
|
+
maxFreeSockets: 10,
|
|
17
|
+
keepAlive: true,
|
|
18
|
+
timeout: 60000, // active socket keepalive for 60 seconds
|
|
19
|
+
freeSocketTimeout: 30000, // free socket keepalive for 30 seconds
|
|
20
|
+
}),
|
|
21
|
+
retryDelay: Math.floor(Math.random() * (8000 - 3000 + 1) + 3000),
|
|
8
22
|
logHandler: (level, data) => {},
|
|
23
|
+
retryCondition: (error) => {
|
|
24
|
+
if (error.response.status === 408) {
|
|
25
|
+
addlogs({ data: error.response }, 'Timeout error', 'error');
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
if (typeof config.branchName === 'string') {
|
|
32
|
+
option.headers = {
|
|
33
|
+
branch: config.branchName,
|
|
34
|
+
};
|
|
9
35
|
}
|
|
10
36
|
|
|
11
|
-
const client = contentstacksdk.client(option)
|
|
12
|
-
return client
|
|
13
|
-
}
|
|
37
|
+
const client = contentstacksdk.client(option);
|
|
38
|
+
return client;
|
|
39
|
+
};
|