@contentstack/cli-cm-import 1.2.3 → 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.
@@ -6,13 +6,13 @@
6
6
 
7
7
  'use strict';
8
8
 
9
- var debug = require('debug')('util:requests');
10
- var MAX_RETRY_LIMIT = 5;
11
- var Bluebird = require('bluebird');
9
+ const debug = require('debug')('util:requests');
10
+ const MAX_RETRY_LIMIT = 5;
11
+ const Bluebird = require('bluebird');
12
12
 
13
- var util = require('./index');
14
- var config = util.getConfig();
15
- const client = require('../util/contentstack-management-sdk').Client(config);
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
- var upload = (module.exports = function (req, fsPath, RETRY) {
23
+ const upload = (module.exports = function (req, fsPath, RETRY) {
24
24
  return new Bluebird(function (resolve, reject) {
25
25
  try {
26
- validate(req);
27
- if (typeof RETRY !== 'number') {
28
- RETRY = 1;
29
- } else if (RETRY > MAX_RETRY_LIMIT) {
30
- return reject(new Error('Max retry limit exceeded!'));
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
- req.upload = fsPath;
34
- client
35
- .stack({ api_key: config.target_stack, management_token: config.management_token })
36
- .asset()
37
- .create(req)
38
- .then((response) => {
39
- return resolve(response);
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((error) => {
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
- };