@contentstack/cli-cm-export-to-csv 1.0.4 → 1.1.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/oclif.manifest.json +86 -1
- package/package.json +7 -10
- package/src/commands/cm/export-to-csv.js +29 -27
- package/src/util/index.js +103 -70
package/oclif.manifest.json
CHANGED
|
@@ -1 +1,86 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": "1.1.0",
|
|
3
|
+
"commands": {
|
|
4
|
+
"cm:export-to-csv": {
|
|
5
|
+
"id": "cm:export-to-csv",
|
|
6
|
+
"description": "Export entries or organization users to csv using this command",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"pluginName": "@contentstack/cli-cm-export-to-csv",
|
|
9
|
+
"pluginAlias": "@contentstack/cli-cm-export-to-csv",
|
|
10
|
+
"pluginType": "core",
|
|
11
|
+
"aliases": [],
|
|
12
|
+
"examples": [
|
|
13
|
+
"csdx cm:export-to-csv",
|
|
14
|
+
"",
|
|
15
|
+
"Exporting entries to csv",
|
|
16
|
+
"csdx cm:export-to-csv --action <entries> --locale <locale> --alias <management-token-alias> --content-type <content-type>",
|
|
17
|
+
"",
|
|
18
|
+
"Exporting entries to csv with stack name provided",
|
|
19
|
+
"csdx cm:export-to-csv --action <entries> --locale <locale> --alias <management-token-alias> --content-type <content-type> --stack-name <stack-name>",
|
|
20
|
+
"",
|
|
21
|
+
"Exporting organization users to csv",
|
|
22
|
+
"csdx cm:export-to-csv --action <users> --org <org-uid>",
|
|
23
|
+
"",
|
|
24
|
+
"Exporting organization users to csv with organization name provided",
|
|
25
|
+
"csdx cm:export-to-csv --action <users> --org <org-uid> --org-name <org-name>"
|
|
26
|
+
],
|
|
27
|
+
"flags": {
|
|
28
|
+
"action": {
|
|
29
|
+
"name": "action",
|
|
30
|
+
"type": "option",
|
|
31
|
+
"description": "Option to export data (entries, users)",
|
|
32
|
+
"required": false,
|
|
33
|
+
"multiple": false,
|
|
34
|
+
"options": [
|
|
35
|
+
"entries",
|
|
36
|
+
"users"
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
"alias": {
|
|
40
|
+
"name": "alias",
|
|
41
|
+
"type": "option",
|
|
42
|
+
"char": "a",
|
|
43
|
+
"description": "Alias of the management token",
|
|
44
|
+
"multiple": false
|
|
45
|
+
},
|
|
46
|
+
"org": {
|
|
47
|
+
"name": "org",
|
|
48
|
+
"type": "option",
|
|
49
|
+
"description": "Provide organization UID to clone org users",
|
|
50
|
+
"required": false,
|
|
51
|
+
"multiple": false
|
|
52
|
+
},
|
|
53
|
+
"stack-name": {
|
|
54
|
+
"name": "stack-name",
|
|
55
|
+
"type": "option",
|
|
56
|
+
"char": "n",
|
|
57
|
+
"description": "Name of the stack that needs to be created as csv filename.",
|
|
58
|
+
"required": false,
|
|
59
|
+
"multiple": false
|
|
60
|
+
},
|
|
61
|
+
"org-name": {
|
|
62
|
+
"name": "org-name",
|
|
63
|
+
"type": "option",
|
|
64
|
+
"description": "Name of the organization that needs to be created as csv filename.",
|
|
65
|
+
"required": false,
|
|
66
|
+
"multiple": false
|
|
67
|
+
},
|
|
68
|
+
"locale": {
|
|
69
|
+
"name": "locale",
|
|
70
|
+
"type": "option",
|
|
71
|
+
"description": "Locale for which entries need to be exported",
|
|
72
|
+
"required": false,
|
|
73
|
+
"multiple": false
|
|
74
|
+
},
|
|
75
|
+
"content-type": {
|
|
76
|
+
"name": "content-type",
|
|
77
|
+
"type": "option",
|
|
78
|
+
"description": "Content type for which entries needs to be exported",
|
|
79
|
+
"required": false,
|
|
80
|
+
"multiple": false
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"args": {}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
package/package.json
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-export-to-csv",
|
|
3
3
|
"description": "Export entities to csv",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"author": "Abhinav Gupta @abhinav-from-contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@contentstack/cli-command": "^1.0
|
|
9
|
-
"@contentstack/cli-utilities": "^1.0
|
|
10
|
-
"@contentstack/management": "^1.6.0",
|
|
11
|
-
"@oclif/command": "^1.8.16",
|
|
12
|
-
"@oclif/config": "^1.18.3",
|
|
8
|
+
"@contentstack/cli-command": "^1.1.0",
|
|
9
|
+
"@contentstack/cli-utilities": "^1.1.0",
|
|
13
10
|
"chalk": "^4.1.0",
|
|
14
11
|
"fast-csv": "^4.3.6",
|
|
15
12
|
"inquirer": "8.2.4",
|
|
@@ -17,8 +14,8 @@
|
|
|
17
14
|
"mkdirp": "^1.0.4"
|
|
18
15
|
},
|
|
19
16
|
"devDependencies": {
|
|
20
|
-
"
|
|
21
|
-
"@oclif/test": "^
|
|
17
|
+
"oclif": "^3.1.2",
|
|
18
|
+
"@oclif/test": "^2.2.10",
|
|
22
19
|
"chai": "^4.2.0",
|
|
23
20
|
"debug": "^4.3.1",
|
|
24
21
|
"eslint": "^8.18.0",
|
|
@@ -45,9 +42,9 @@
|
|
|
45
42
|
"scripts": {
|
|
46
43
|
"pack": "npm pack && mv *.tgz ../../build",
|
|
47
44
|
"postpack": "rm -f oclif.manifest.json",
|
|
48
|
-
"prepack": "oclif
|
|
45
|
+
"prepack": "oclif manifest && oclif readme",
|
|
49
46
|
"test": "nyc mocha --forbid-only \"test/**/*.test.js\"",
|
|
50
|
-
"version": "oclif
|
|
47
|
+
"version": "oclif readme && git add README.md"
|
|
51
48
|
},
|
|
52
49
|
"csdxConfig": {
|
|
53
50
|
"expiredCommands": {}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const { Command, flags } = require('@contentstack/cli-command');
|
|
2
|
-
const { configHandler } = require('@contentstack/cli-utilities');
|
|
3
|
-
const ContentstackManagementSDK = require('@contentstack/management');
|
|
2
|
+
const { configHandler, managementSDKClient } = require('@contentstack/cli-utilities');
|
|
4
3
|
const util = require('../../util');
|
|
5
4
|
const config = require('../../util/config');
|
|
6
5
|
|
|
@@ -52,14 +51,9 @@ class ExportToCsvCommand extends Command {
|
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
53
|
|
|
55
|
-
get managementAPIClient() {
|
|
56
|
-
this._managementAPIClient = ContentstackManagementSDK.client({ host: this.cmaHost, authtoken: this.getAuthToken });
|
|
57
|
-
return this._managementAPIClient;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
54
|
async run() {
|
|
61
55
|
try {
|
|
62
|
-
let action;
|
|
56
|
+
let action, managementAPIClient;
|
|
63
57
|
const {
|
|
64
58
|
flags: {
|
|
65
59
|
org,
|
|
@@ -70,7 +64,11 @@ class ExportToCsvCommand extends Command {
|
|
|
70
64
|
'content-type': contentTypesFlag,
|
|
71
65
|
alias: managementTokenAlias,
|
|
72
66
|
},
|
|
73
|
-
} = this.parse(ExportToCsvCommand);
|
|
67
|
+
} = await this.parse(ExportToCsvCommand);
|
|
68
|
+
|
|
69
|
+
if (!managementTokenAlias) {
|
|
70
|
+
managementAPIClient = await managementSDKClient({ host: this.cmaHost });
|
|
71
|
+
}
|
|
74
72
|
|
|
75
73
|
if (actionFlag) {
|
|
76
74
|
action = actionFlag;
|
|
@@ -83,12 +81,16 @@ class ExportToCsvCommand extends Command {
|
|
|
83
81
|
case 'entries': {
|
|
84
82
|
try {
|
|
85
83
|
let stack;
|
|
86
|
-
let
|
|
84
|
+
let stackAPIClient;
|
|
87
85
|
let language;
|
|
88
86
|
let contentTypes = [];
|
|
89
87
|
const listOfTokens = configHandler.get('tokens');
|
|
90
88
|
|
|
91
89
|
if (managementTokenAlias && listOfTokens[managementTokenAlias]) {
|
|
90
|
+
managementAPIClient = await managementSDKClient({
|
|
91
|
+
host: this.cmaHost,
|
|
92
|
+
management_token: listOfTokens[managementTokenAlias].token,
|
|
93
|
+
});
|
|
92
94
|
stack = {
|
|
93
95
|
name: stackName || managementTokenAlias,
|
|
94
96
|
apiKey: listOfTokens[managementTokenAlias].apiKey,
|
|
@@ -99,7 +101,7 @@ class ExportToCsvCommand extends Command {
|
|
|
99
101
|
} else {
|
|
100
102
|
let organization;
|
|
101
103
|
|
|
102
|
-
if (!this.
|
|
104
|
+
if (!this.isAuthenticated()) {
|
|
103
105
|
this.error(config.CLI_EXPORT_CSV_ENTRIES_ERROR, {
|
|
104
106
|
exit: 2,
|
|
105
107
|
suggestions: ['https://www.contentstack.com/docs/developers/cli/authentication/'],
|
|
@@ -109,21 +111,21 @@ class ExportToCsvCommand extends Command {
|
|
|
109
111
|
if (org) {
|
|
110
112
|
organization = { uid: org };
|
|
111
113
|
} else {
|
|
112
|
-
organization = await util.chooseOrganization(
|
|
114
|
+
organization = await util.chooseOrganization(managementAPIClient); // prompt for organization
|
|
113
115
|
}
|
|
114
116
|
|
|
115
|
-
stack = await util.chooseStack(
|
|
117
|
+
stack = await util.chooseStack(managementAPIClient, organization.uid); // prompt for stack
|
|
116
118
|
}
|
|
117
119
|
|
|
118
|
-
|
|
119
|
-
const contentTypeCount = await util.getContentTypeCount(
|
|
120
|
-
const environments = await util.getEnvironments(
|
|
120
|
+
stackAPIClient = this.getStackClient(managementAPIClient, stack);
|
|
121
|
+
const contentTypeCount = await util.getContentTypeCount(stackAPIClient);
|
|
122
|
+
const environments = await util.getEnvironments(stackAPIClient); // fetch environments, because in publish details only env uid are available and we need env names
|
|
121
123
|
|
|
122
124
|
if (contentTypesFlag) {
|
|
123
125
|
contentTypes = contentTypesFlag.split(',').map(this.snakeCase);
|
|
124
126
|
} else {
|
|
125
127
|
for (let index = 0; index <= contentTypeCount / 100; index++) {
|
|
126
|
-
const contentTypesMap = await util.getContentTypes(
|
|
128
|
+
const contentTypesMap = await util.getContentTypes(stackAPIClient, index);
|
|
127
129
|
contentTypes = contentTypes.concat(Object.values(contentTypesMap)); // prompt for content Type
|
|
128
130
|
}
|
|
129
131
|
}
|
|
@@ -140,16 +142,16 @@ class ExportToCsvCommand extends Command {
|
|
|
140
142
|
if (locale) {
|
|
141
143
|
language = { code: locale };
|
|
142
144
|
} else {
|
|
143
|
-
language = await util.chooseLanguage(
|
|
145
|
+
language = await util.chooseLanguage(stackAPIClient); // prompt for language
|
|
144
146
|
}
|
|
145
147
|
|
|
146
148
|
while (contentTypes.length > 0) {
|
|
147
149
|
let contentType = contentTypes.pop();
|
|
148
150
|
|
|
149
|
-
const entriesCount = await util.getEntriesCount(
|
|
151
|
+
const entriesCount = await util.getEntriesCount(stackAPIClient, contentType, language.code);
|
|
150
152
|
let flatEntries = [];
|
|
151
153
|
for (let index = 0; index < entriesCount / 100; index++) {
|
|
152
|
-
const entriesResult = await util.getEntries(
|
|
154
|
+
const entriesResult = await util.getEntries(stackAPIClient, contentType, language.code, index);
|
|
153
155
|
const flatEntriesResult = util.cleanEntries(
|
|
154
156
|
entriesResult.items,
|
|
155
157
|
language.code,
|
|
@@ -170,7 +172,7 @@ class ExportToCsvCommand extends Command {
|
|
|
170
172
|
case config.exportUsers:
|
|
171
173
|
case 'users': {
|
|
172
174
|
try {
|
|
173
|
-
if (!this.
|
|
175
|
+
if (!this.isAuthenticated()) {
|
|
174
176
|
this.error(config.CLI_EXPORT_CSV_LOGIN_FAILED, {
|
|
175
177
|
exit: 2,
|
|
176
178
|
suggestions: ['https://www.contentstack.com/docs/developers/cli/authentication/'],
|
|
@@ -181,11 +183,11 @@ class ExportToCsvCommand extends Command {
|
|
|
181
183
|
if (org) {
|
|
182
184
|
organization = { uid: org, name: orgName || org };
|
|
183
185
|
} else {
|
|
184
|
-
organization = await util.chooseOrganization(
|
|
186
|
+
organization = await util.chooseOrganization(managementAPIClient, action); // prompt for organization
|
|
185
187
|
}
|
|
186
188
|
|
|
187
|
-
const orgUsers = await util.getOrgUsers(
|
|
188
|
-
const orgRoles = await util.getOrgRoles(
|
|
189
|
+
const orgUsers = await util.getOrgUsers(managementAPIClient, organization.uid, this);
|
|
190
|
+
const orgRoles = await util.getOrgRoles(managementAPIClient, organization.uid, this);
|
|
189
191
|
const mappedUsers = util.getMappedUsers(orgUsers);
|
|
190
192
|
const mappedRoles = util.getMappedRoles(orgRoles);
|
|
191
193
|
const listOfUsers = util.cleanOrgUsers(orgUsers, mappedUsers, mappedRoles);
|
|
@@ -213,14 +215,14 @@ class ExportToCsvCommand extends Command {
|
|
|
213
215
|
return (string || '').split(' ').join('_').toLowerCase();
|
|
214
216
|
}
|
|
215
217
|
|
|
216
|
-
getStackClient(stack) {
|
|
218
|
+
getStackClient(managementAPIClient, stack) {
|
|
217
219
|
if (stack.token) {
|
|
218
|
-
return
|
|
220
|
+
return managementAPIClient.stack({
|
|
219
221
|
api_key: stack.apiKey,
|
|
220
222
|
management_token: stack.token,
|
|
221
223
|
});
|
|
222
224
|
}
|
|
223
|
-
return
|
|
225
|
+
return managementAPIClient.stack({ api_key: stack.apiKey });
|
|
224
226
|
}
|
|
225
227
|
}
|
|
226
228
|
|
package/src/util/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const inquirer = require('inquirer');
|
|
2
|
-
const { HttpClient } = require('@contentstack/cli-utilities');
|
|
3
2
|
const os = require('os');
|
|
4
3
|
const checkboxPlus = require('inquirer-checkbox-plus-prompt');
|
|
5
4
|
const config = require('./config.js');
|
|
@@ -33,10 +32,13 @@ function chooseOrganization(managementAPIClient, action) {
|
|
|
33
32
|
loop: false,
|
|
34
33
|
},
|
|
35
34
|
];
|
|
36
|
-
inquirer
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
inquirer
|
|
36
|
+
.prompt(_chooseOrganization)
|
|
37
|
+
.then(({ chosenOrg }) => {
|
|
38
|
+
if (chosenOrg === config.cancelString) exitProgram();
|
|
39
|
+
resolve({ name: chosenOrg, uid: organizations[chosenOrg] });
|
|
40
|
+
})
|
|
41
|
+
.catch(reject);
|
|
40
42
|
} catch (error) {
|
|
41
43
|
reject(error);
|
|
42
44
|
}
|
|
@@ -98,10 +100,13 @@ function chooseStack(managementAPIClient, orgUid) {
|
|
|
98
100
|
},
|
|
99
101
|
];
|
|
100
102
|
|
|
101
|
-
inquirer
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
inquirer
|
|
104
|
+
.prompt(_chooseStack)
|
|
105
|
+
.then(({ chosenStack }) => {
|
|
106
|
+
if (chosenStack === config.cancelString) exitProgram();
|
|
107
|
+
resolve({ name: chosenStack, apiKey: stacks[chosenStack] });
|
|
108
|
+
})
|
|
109
|
+
.catch(reject);
|
|
105
110
|
} catch (error) {
|
|
106
111
|
reject(error);
|
|
107
112
|
}
|
|
@@ -109,9 +114,6 @@ function chooseStack(managementAPIClient, orgUid) {
|
|
|
109
114
|
}
|
|
110
115
|
|
|
111
116
|
function getStacks(managementAPIClient, orgUid) {
|
|
112
|
-
// Adding a query object in query, because it throws an error
|
|
113
|
-
// the error is coming from query function lib/entity.js, @contentstack/management pacakge
|
|
114
|
-
// where params.query is being set
|
|
115
117
|
return new Promise((resolve, reject) => {
|
|
116
118
|
let result = {};
|
|
117
119
|
managementAPIClient
|
|
@@ -130,12 +132,10 @@ function getStacks(managementAPIClient, orgUid) {
|
|
|
130
132
|
});
|
|
131
133
|
}
|
|
132
134
|
|
|
133
|
-
function chooseContentType(
|
|
134
|
-
return new Promise(async (resolve) => {
|
|
135
|
-
let contentTypes = await getContentTypes(
|
|
135
|
+
function chooseContentType(stackAPIClient, skip) {
|
|
136
|
+
return new Promise(async (resolve, reject) => {
|
|
137
|
+
let contentTypes = await getContentTypes(stackAPIClient, skip);
|
|
136
138
|
let contentTypesList = Object.values(contentTypes);
|
|
137
|
-
// contentTypesList.push(config.cancelString)
|
|
138
|
-
|
|
139
139
|
let _chooseContentType = [
|
|
140
140
|
{
|
|
141
141
|
type: 'checkbox',
|
|
@@ -146,9 +146,10 @@ function chooseContentType(stack, skip) {
|
|
|
146
146
|
},
|
|
147
147
|
];
|
|
148
148
|
|
|
149
|
-
inquirer
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
inquirer
|
|
150
|
+
.prompt(_chooseContentType)
|
|
151
|
+
.then(({ chosenContentTypes }) => resolve(chosenContentTypes))
|
|
152
|
+
.catch(reject);
|
|
152
153
|
});
|
|
153
154
|
}
|
|
154
155
|
|
|
@@ -182,19 +183,22 @@ function chooseInMemContentTypes(contentTypesList) {
|
|
|
182
183
|
},
|
|
183
184
|
},
|
|
184
185
|
];
|
|
185
|
-
inquirer
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
186
|
+
inquirer
|
|
187
|
+
.prompt(_chooseContentType)
|
|
188
|
+
.then(({ chosenContentTypes }) => {
|
|
189
|
+
if (chosenContentTypes.length === 0) {
|
|
190
|
+
reject('Please select atleast one content type.');
|
|
191
|
+
}
|
|
192
|
+
resolve(chosenContentTypes);
|
|
193
|
+
})
|
|
194
|
+
.catch(reject);
|
|
191
195
|
});
|
|
192
196
|
}
|
|
193
197
|
|
|
194
|
-
function getContentTypes(
|
|
198
|
+
function getContentTypes(stackAPIClient, skip) {
|
|
195
199
|
return new Promise((resolve, reject) => {
|
|
196
200
|
let result = {};
|
|
197
|
-
|
|
201
|
+
stackAPIClient
|
|
198
202
|
.contentType()
|
|
199
203
|
.query({ skip: skip * 100 })
|
|
200
204
|
.find()
|
|
@@ -208,9 +212,9 @@ function getContentTypes(stack, skip) {
|
|
|
208
212
|
});
|
|
209
213
|
}
|
|
210
214
|
|
|
211
|
-
function chooseLanguage(
|
|
212
|
-
return new Promise(async (resolve) => {
|
|
213
|
-
let languages = await getLanguages(
|
|
215
|
+
function chooseLanguage(stackAPIClient) {
|
|
216
|
+
return new Promise(async (resolve, reject) => {
|
|
217
|
+
let languages = await getLanguages(stackAPIClient);
|
|
214
218
|
let languagesList = Object.keys(languages);
|
|
215
219
|
languagesList.push(config.cancelString);
|
|
216
220
|
|
|
@@ -223,17 +227,20 @@ function chooseLanguage(stack) {
|
|
|
223
227
|
},
|
|
224
228
|
];
|
|
225
229
|
|
|
226
|
-
inquirer
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
+
inquirer
|
|
231
|
+
.prompt(_chooseLanguage)
|
|
232
|
+
.then(({ chosenLanguage }) => {
|
|
233
|
+
if (chosenLanguage === config.cancelString) exitProgram();
|
|
234
|
+
resolve({ name: chosenLanguage, code: languages[chosenLanguage] });
|
|
235
|
+
})
|
|
236
|
+
.catch(reject);
|
|
230
237
|
});
|
|
231
238
|
}
|
|
232
239
|
|
|
233
|
-
function getLanguages(
|
|
240
|
+
function getLanguages(stackAPIClient) {
|
|
234
241
|
return new Promise((resolve, reject) => {
|
|
235
242
|
let result = {};
|
|
236
|
-
|
|
243
|
+
stackAPIClient
|
|
237
244
|
.locale()
|
|
238
245
|
.query()
|
|
239
246
|
.find()
|
|
@@ -247,9 +254,9 @@ function getLanguages(stack) {
|
|
|
247
254
|
});
|
|
248
255
|
}
|
|
249
256
|
|
|
250
|
-
function getEntries(
|
|
257
|
+
function getEntries(stackAPIClient, contentType, language, skip) {
|
|
251
258
|
return new Promise((resolve, reject) => {
|
|
252
|
-
|
|
259
|
+
stackAPIClient
|
|
253
260
|
.contentType(contentType)
|
|
254
261
|
.entry()
|
|
255
262
|
.query({ include_publish_details: true, locale: language, skip: skip * 100 })
|
|
@@ -259,9 +266,9 @@ function getEntries(stack, contentType, language, skip) {
|
|
|
259
266
|
});
|
|
260
267
|
}
|
|
261
268
|
|
|
262
|
-
function getEntriesCount(
|
|
269
|
+
function getEntriesCount(stackAPIClient, contentType, language) {
|
|
263
270
|
return new Promise((resolve, reject) => {
|
|
264
|
-
|
|
271
|
+
stackAPIClient
|
|
265
272
|
.contentType(contentType)
|
|
266
273
|
.entry()
|
|
267
274
|
.query({ include_publish_details: true, locale: language })
|
|
@@ -271,9 +278,9 @@ function getEntriesCount(stack, contentType, language) {
|
|
|
271
278
|
});
|
|
272
279
|
}
|
|
273
280
|
|
|
274
|
-
function getEnvironments(
|
|
281
|
+
function getEnvironments(stackAPIClient) {
|
|
275
282
|
let result = {};
|
|
276
|
-
return
|
|
283
|
+
return stackAPIClient
|
|
277
284
|
.environment()
|
|
278
285
|
.query()
|
|
279
286
|
.find()
|
|
@@ -285,15 +292,13 @@ function getEnvironments(stack) {
|
|
|
285
292
|
});
|
|
286
293
|
}
|
|
287
294
|
|
|
288
|
-
function getContentTypeCount(
|
|
295
|
+
function getContentTypeCount(stackAPIClient) {
|
|
289
296
|
return new Promise((resolve, reject) => {
|
|
290
|
-
|
|
297
|
+
stackAPIClient
|
|
291
298
|
.contentType()
|
|
292
299
|
.query()
|
|
293
300
|
.count()
|
|
294
|
-
.then((contentTypes) =>
|
|
295
|
-
resolve(contentTypes.content_types);
|
|
296
|
-
})
|
|
301
|
+
.then((contentTypes) => resolve(contentTypes.content_types))
|
|
297
302
|
.catch((error) => reject(error));
|
|
298
303
|
});
|
|
299
304
|
}
|
|
@@ -363,7 +368,7 @@ function write(command, entries, fileName, message) {
|
|
|
363
368
|
}
|
|
364
369
|
|
|
365
370
|
function startupQuestions() {
|
|
366
|
-
return new Promise((resolve) => {
|
|
371
|
+
return new Promise((resolve, reject) => {
|
|
367
372
|
let actions = [
|
|
368
373
|
{
|
|
369
374
|
type: 'list',
|
|
@@ -372,10 +377,13 @@ function startupQuestions() {
|
|
|
372
377
|
choices: [config.exportEntries, config.exportUsers, 'Exit'],
|
|
373
378
|
},
|
|
374
379
|
];
|
|
375
|
-
inquirer
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
380
|
+
inquirer
|
|
381
|
+
.prompt(actions)
|
|
382
|
+
.then((answers) => {
|
|
383
|
+
if (answers.action === 'Exit') exitProgram();
|
|
384
|
+
resolve(answers.action);
|
|
385
|
+
})
|
|
386
|
+
.catch(reject);
|
|
379
387
|
});
|
|
380
388
|
}
|
|
381
389
|
|
|
@@ -386,12 +394,17 @@ function getOrgUsers(managementAPIClient, orgUid, ecsv) {
|
|
|
386
394
|
.then(async (response) => {
|
|
387
395
|
let organization = response.organizations.filter((org) => org.uid === orgUid).pop();
|
|
388
396
|
if (organization.is_owner === true) {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
.
|
|
393
|
-
|
|
394
|
-
|
|
397
|
+
return managementAPIClient
|
|
398
|
+
.organization(organization.uid)
|
|
399
|
+
.fetch()
|
|
400
|
+
.then((_response) => {
|
|
401
|
+
_response
|
|
402
|
+
.getInvitations()
|
|
403
|
+
.then((_data) => {
|
|
404
|
+
resolve({ items: _data.items });
|
|
405
|
+
})
|
|
406
|
+
.catch(reject);
|
|
407
|
+
});
|
|
395
408
|
}
|
|
396
409
|
if (!organization.getInvitations) {
|
|
397
410
|
return reject(new Error(config.adminError));
|
|
@@ -420,6 +433,7 @@ async function getUsers(organization, params, result = []) {
|
|
|
420
433
|
return getUsers(organization, params, result);
|
|
421
434
|
}
|
|
422
435
|
} catch (error) {
|
|
436
|
+
console.error(error);
|
|
423
437
|
throw error;
|
|
424
438
|
}
|
|
425
439
|
}
|
|
@@ -448,16 +462,25 @@ function getOrgRoles(managementAPIClient, orgUid, ecsv) {
|
|
|
448
462
|
.then((response) => {
|
|
449
463
|
let organization = response.organizations.filter((org) => org.uid === orgUid).pop();
|
|
450
464
|
if (organization.is_owner === true) {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
.
|
|
455
|
-
|
|
465
|
+
return managementAPIClient
|
|
466
|
+
.organization(organization.uid)
|
|
467
|
+
.fetch()
|
|
468
|
+
.then((_response) => {
|
|
469
|
+
_response
|
|
470
|
+
.roles()
|
|
471
|
+
.then((_data) => {
|
|
472
|
+
resolve({ items: _data.items });
|
|
473
|
+
})
|
|
474
|
+
.catch(reject);
|
|
475
|
+
});
|
|
456
476
|
}
|
|
457
477
|
if (!organization.roles) {
|
|
458
478
|
return reject(new Error(config.adminError));
|
|
459
479
|
}
|
|
460
|
-
organization
|
|
480
|
+
organization
|
|
481
|
+
.roles()
|
|
482
|
+
.then((roles) => resolve(roles))
|
|
483
|
+
.catch(reject);
|
|
461
484
|
})
|
|
462
485
|
.catch((error) => reject(error));
|
|
463
486
|
});
|
|
@@ -540,10 +563,20 @@ function formatError(error) {
|
|
|
540
563
|
if (error.errors && Object.keys(error.errors).length > 0) {
|
|
541
564
|
Object.keys(error.errors).forEach((e) => {
|
|
542
565
|
let entity = e;
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
566
|
+
switch (e) {
|
|
567
|
+
case 'authorization':
|
|
568
|
+
entity = 'Management Token';
|
|
569
|
+
break;
|
|
570
|
+
case 'api_key':
|
|
571
|
+
entity = 'Stack API key';
|
|
572
|
+
break;
|
|
573
|
+
case 'uid':
|
|
574
|
+
entity = 'Content Type';
|
|
575
|
+
break;
|
|
576
|
+
case 'access_token':
|
|
577
|
+
entity = 'Delivery Token';
|
|
578
|
+
break;
|
|
579
|
+
}
|
|
547
580
|
message += ' ' + [entity, error.errors[e]].join(' ');
|
|
548
581
|
});
|
|
549
582
|
}
|
|
@@ -551,7 +584,7 @@ function formatError(error) {
|
|
|
551
584
|
}
|
|
552
585
|
|
|
553
586
|
function wait(time) {
|
|
554
|
-
return new Promise(res => {
|
|
587
|
+
return new Promise((res) => {
|
|
555
588
|
setTimeout(res, time);
|
|
556
589
|
});
|
|
557
590
|
}
|