@contentstack/cli-cm-import 0.1.1-beta.9 → 1.0.1

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.
@@ -1,159 +0,0 @@
1
- const {Command, flags} = require('@contentstack/cli-command')
2
- const {cli} = require('cli-ux')
3
- let _ = require('lodash')
4
- const Configstore = require('configstore')
5
- const credStore = new Configstore('contentstack_cli')
6
- const {configWithMToken,
7
- parameterWithMToken,
8
- withoutParameterMToken,
9
- configWithAuthToken,
10
- parametersWithAuthToken,
11
- withoutParametersWithAuthToken
12
- } = require('../../lib/util/import-flags')
13
-
14
- class ImportCommand extends Command {
15
- async run() {
16
- let self = this
17
- const {flags} = self.parse(ImportCommand)
18
- const extConfig = flags.config
19
- let targetStack = flags['stack-uid']
20
- const data = flags.data
21
- const moduleName = flags.module
22
- const backupdir = flags["backup-dir"]
23
- const alias = flags['management-token-alias']
24
- const authToken = flags['auth-token']
25
- let _authToken = credStore.get('authtoken')
26
- let host = self.cmaHost
27
-
28
- return new Promise(function (resolve, reject) {
29
- if (alias && alias !== undefined) {
30
- let managementTokens = self.getToken(alias)
31
-
32
- if (managementTokens && managementTokens !== undefined) {
33
- if (extConfig && extConfig !== undefined && _authToken) {
34
- configWithMToken(
35
- extConfig,
36
- managementTokens,
37
- moduleName,
38
- host,
39
- _authToken,
40
- backupdir
41
- )
42
- .then(() => {
43
- return resolve()
44
- })
45
- } else if (data) {
46
- parameterWithMToken(
47
- managementTokens,
48
- data,
49
- moduleName,
50
- host,
51
- _authToken,
52
- backupdir
53
- )
54
- .then(() => {
55
- return resolve()
56
- })
57
- } else {
58
- withoutParameterMToken(
59
- managementTokens,
60
- moduleName,
61
- host,
62
- _authToken,
63
- backupdir
64
- )
65
- .then(() => {
66
- return resolve()
67
- })
68
- }
69
- } else {
70
- console.log('management Token is not present please add managment token first')
71
- }
72
- } else if (authToken && authToken !== undefined && _authToken && _authToken !== undefined) {
73
- if (extConfig && extConfig !== undefined) {
74
- configWithAuthToken(
75
- extConfig,
76
- _authToken,
77
- moduleName,
78
- host,
79
- backupdir
80
- )
81
- .then(() => {
82
- return resolve()
83
- })
84
- } else if (targetStack && data) {
85
- parametersWithAuthToken(
86
- _authToken,
87
- targetStack,
88
- data,
89
- moduleName,
90
- host,
91
- backupdir
92
- )
93
- .then(() => {
94
- return resolve()
95
- })
96
- } else {
97
- withoutParametersWithAuthToken(
98
- _authToken,
99
- moduleName,
100
- host,
101
- backupdir
102
- )
103
- .then(() => {
104
- return resolve()
105
- })
106
- }
107
- } else {
108
- console.log('Provide alias for managementToken or authtoken')
109
- }
110
- })
111
- }
112
- }
113
-
114
- ImportCommand.description = `Import script for importing the content into new stack
115
- ...
116
- Once you export content from the source stack, import it to your destination stack by using the cm:import command.
117
- `
118
- ImportCommand.examples = [
119
- `csdx cm:import -A`,
120
- `csdx cm:import -A -s <stack_ApiKey> -d <path/of/export/destination/dir>`,
121
- `csdx cm:import -A -c <path/of/config/dir>`,
122
- `csdx cm:import -A -m <single module name>`,
123
- `csdx cm:import -A -m <single module name> -b <backup dir>`,
124
- `csdx cm:import -a <management_token_alias>`,
125
- `csdx cm:import -a <management_token_alias> -d <path/of/export/destination/dir>`,
126
- `csdx cm:import -a <management_token_alias> -c <path/of/config/file>`,
127
- ]
128
- ImportCommand.flags = {
129
- config: flags.string({
130
- char: 'c',
131
- description: '[optional] path of config file'
132
- }),
133
- 'stack-uid': flags.string({
134
- char: 's',
135
- description: 'API key of the target stack'
136
- }),
137
- data: flags.string({
138
- char: 'd',
139
- description: 'path and location where data is stored'
140
- }),
141
- 'management-token-alias': flags.string({
142
- char: 'a',
143
- description: 'alias of the management token'
144
- }),
145
- 'auth-token': flags.boolean({
146
- char: 'A',
147
- description: 'to use auth token'
148
- }),
149
- module: flags.string({
150
- char: 'm',
151
- description: '[optional] specific module name'
152
- }),
153
- "backup-dir": flags.string({
154
- char: 'b',
155
- description: '[optional] backup directory name when using specific module'
156
- })
157
- }
158
-
159
- module.exports = ImportCommand
@@ -1,82 +0,0 @@
1
- /*!
2
- * Contentstack Import
3
- * Copyright (c) 2019 Contentstack LLC
4
- * MIT Licensed
5
- */
6
-
7
- 'use strict';
8
-
9
- var Bluebird = require('bluebird');
10
- var request = Bluebird.promisify(require('request'));
11
- var debug = require('debug')('util:requests');
12
- var MAX_RETRY_LIMIT = 5;
13
-
14
- function validate (req) {
15
- if (typeof req !== 'object') {
16
- throw new Error(`Invalid params passed for request\n${JSON.stringify(arguments)}`);
17
- }
18
- if (typeof req.uri === 'undefined' && typeof req.url === 'undefined') {
19
- throw new Error(`Missing uri in request!\n${JSON.stringify(req)}`);
20
- }
21
- if (typeof req.method === 'undefined') {
22
- debug(`${req.uri || req.url} had no method, setting it as 'GET'`);
23
- req.method = 'GET';
24
- }
25
- if (typeof req.json === 'undefined') {
26
- req.json = true;
27
- }
28
- if (typeof req.headers === 'undefined') {
29
- var util = require('./index');
30
- var config = util.getConfig();
31
- debug(`${req.uri || req.url} had no headers`);
32
- req.headers = config.headers;
33
- }
34
- }
35
-
36
- var makeCall = module.exports = function (req, RETRY) {
37
- return new Bluebird(function (resolve, reject) {
38
- try {
39
- validate(req);
40
- if (typeof RETRY !== 'number') {
41
- RETRY = 1;
42
- } else if (RETRY > MAX_RETRY_LIMIT) {
43
- return reject(new Error('Max retry limit exceeded!'));
44
- }
45
- debug(`${req.method.toUpperCase()}: ${req.uri || req.url}`);
46
- return request(req).then(function (response) {
47
- var timeDelay;
48
- if (response.statusCode >= 200 && response.statusCode <= 399) {
49
- return resolve(response);
50
- } else if (response.statusCode === 429) {
51
- timeDelay = Math.pow(Math.SQRT2, RETRY) * 100;
52
- debug(
53
- `API rate limit exceeded.\nReceived ${response.statusCode} status\nBody ${JSON.stringify(response)}`
54
- );
55
- debug(`Retrying ${req.uri || req.url} with ${timeDelay} sec delay`);
56
- return setTimeout(function (req, RETRY) {
57
- return makeCall(req, RETRY)
58
- .then(resolve)
59
- .catch(reject);
60
- }, timeDelay, req, RETRY);
61
- } else if (response.statusCode >= 500) {
62
- // retry, with delay
63
- timeDelay = Math.pow(Math.SQRT2, RETRY) * 100;
64
- debug(`Recevied ${response.statusCode} status\nBody ${JSON.stringify(response)}`);
65
- debug(`Retrying ${req.uri || req.url} with ${timeDelay} sec delay`);
66
- RETRY++;
67
- return setTimeout(function (req, RETRY) {
68
- return makeCall(req, RETRY)
69
- .then(resolve)
70
- .catch(reject);
71
- }, timeDelay, req, RETRY);
72
- } else {
73
- debug(`Request failed\n${JSON.stringify(req)}`);
74
- return reject(response.body);
75
- }
76
- }).catch(reject);
77
- } catch (error) {
78
- debug(error);
79
- return reject(error);
80
- }
81
- });
82
- };