@contentstack/cli-cm-export-to-csv 1.3.2 → 1.3.4
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 +1 -1
- package/package.json +3 -3
- package/src/util/index.js +55 -45
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-export-to-csv",
|
|
3
3
|
"description": "Export entities to csv",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.4",
|
|
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.2.
|
|
9
|
-
"@contentstack/cli-utilities": "^1.4.
|
|
8
|
+
"@contentstack/cli-command": "^1.2.4",
|
|
9
|
+
"@contentstack/cli-utilities": "^1.4.1",
|
|
10
10
|
"chalk": "^4.1.0",
|
|
11
11
|
"fast-csv": "^4.3.6",
|
|
12
12
|
"inquirer": "8.2.4",
|
package/src/util/index.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
const inquirer = require('inquirer');
|
|
2
1
|
const os = require('os');
|
|
3
|
-
const checkboxPlus = require('inquirer-checkbox-plus-prompt');
|
|
4
|
-
const config = require('./config.js');
|
|
5
|
-
const fastcsv = require('fast-csv');
|
|
6
|
-
const mkdirp = require('mkdirp');
|
|
7
2
|
const fs = require('fs');
|
|
3
|
+
const mkdirp = require('mkdirp');
|
|
4
|
+
const find = require('lodash/find');
|
|
5
|
+
const fastcsv = require('fast-csv');
|
|
6
|
+
const inquirer = require('inquirer');
|
|
8
7
|
const debug = require('debug')('export-to-csv');
|
|
8
|
+
const checkboxPlus = require('inquirer-checkbox-plus-prompt');
|
|
9
|
+
|
|
10
|
+
const config = require('./config.js');
|
|
11
|
+
|
|
9
12
|
const directory = './data';
|
|
10
13
|
const delimeter = os.platform() === 'win32' ? '\\' : '/';
|
|
11
14
|
|
|
@@ -45,21 +48,31 @@ function chooseOrganization(managementAPIClient, action) {
|
|
|
45
48
|
});
|
|
46
49
|
}
|
|
47
50
|
|
|
48
|
-
function getOrganizations(managementAPIClient) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
async function getOrganizations(managementAPIClient) {
|
|
52
|
+
try {
|
|
53
|
+
return await getOrganizationList(managementAPIClient, { skip: 0, page: 1, limit: 100 }, []);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.log(error);
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
51
59
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
60
|
+
async function getOrganizationList(managementAPIClient, params, result = []) {
|
|
61
|
+
const organizations = await managementAPIClient.organization().fetchAll(params);
|
|
62
|
+
result = result.concat(organizations.items);
|
|
63
|
+
|
|
64
|
+
if (!organizations.items || (organizations.items && organizations.items.length < params.limit)) {
|
|
65
|
+
const orgMap = {};
|
|
66
|
+
for (const org of result) {
|
|
67
|
+
orgMap[org.name] = org.uid;
|
|
68
|
+
}
|
|
69
|
+
return orgMap;
|
|
70
|
+
} else {
|
|
71
|
+
params.skip = params.page * params.limit;
|
|
72
|
+
params.page++;
|
|
73
|
+
await wait(200);
|
|
74
|
+
return getOrganizationList(managementAPIClient, params, result);
|
|
75
|
+
}
|
|
63
76
|
}
|
|
64
77
|
|
|
65
78
|
function getOrganizationsWhereUserIsAdmin(managementAPIClient) {
|
|
@@ -393,24 +406,21 @@ function getOrgUsers(managementAPIClient, orgUid, ecsv) {
|
|
|
393
406
|
.getUser({ include_orgs_roles: true })
|
|
394
407
|
.then(async (response) => {
|
|
395
408
|
let organization = response.organizations.filter((org) => org.uid === orgUid).pop();
|
|
409
|
+
if (!organization) return reject(new Error('Org UID not found.'));
|
|
396
410
|
if (organization.is_owner === true) {
|
|
397
411
|
return managementAPIClient
|
|
398
412
|
.organization(organization.uid)
|
|
399
|
-
.
|
|
400
|
-
.then((
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
resolve({ items: _data.items });
|
|
405
|
-
})
|
|
406
|
-
.catch(reject);
|
|
407
|
-
});
|
|
413
|
+
.getInvitations()
|
|
414
|
+
.then((data) => {
|
|
415
|
+
resolve({ items: data.items });
|
|
416
|
+
})
|
|
417
|
+
.catch(reject);
|
|
408
418
|
}
|
|
409
|
-
if (!organization.getInvitations) {
|
|
419
|
+
if (!organization.getInvitations && !find(organization.org_roles, 'admin')) {
|
|
410
420
|
return reject(new Error(config.adminError));
|
|
411
421
|
}
|
|
412
422
|
try {
|
|
413
|
-
const users = await getUsers(organization, { skip: 0, page: 1, limit: 100 });
|
|
423
|
+
const users = await getUsers(managementAPIClient, organization, { skip: 0, page: 1, limit: 100 });
|
|
414
424
|
return resolve({ items: users });
|
|
415
425
|
} catch (error) {
|
|
416
426
|
return reject(error);
|
|
@@ -420,9 +430,9 @@ function getOrgUsers(managementAPIClient, orgUid, ecsv) {
|
|
|
420
430
|
});
|
|
421
431
|
}
|
|
422
432
|
|
|
423
|
-
async function getUsers(organization, params, result = []) {
|
|
433
|
+
async function getUsers(managementAPIClient, organization, params, result = []) {
|
|
424
434
|
try {
|
|
425
|
-
const users = await organization.getInvitations(params);
|
|
435
|
+
const users = await managementAPIClient.organization(organization.uid).getInvitations(params);
|
|
426
436
|
if (!users.items || (users.items && !users.items.length)) {
|
|
427
437
|
return result;
|
|
428
438
|
} else {
|
|
@@ -430,7 +440,7 @@ async function getUsers(organization, params, result = []) {
|
|
|
430
440
|
params.skip = params.page * params.limit;
|
|
431
441
|
params.page++;
|
|
432
442
|
await wait(200);
|
|
433
|
-
return getUsers(organization, params, result);
|
|
443
|
+
return getUsers(managementAPIClient, organization, params, result);
|
|
434
444
|
}
|
|
435
445
|
} catch (error) {
|
|
436
446
|
console.error(error);
|
|
@@ -464,22 +474,22 @@ function getOrgRoles(managementAPIClient, orgUid, ecsv) {
|
|
|
464
474
|
if (organization.is_owner === true) {
|
|
465
475
|
return managementAPIClient
|
|
466
476
|
.organization(organization.uid)
|
|
467
|
-
.
|
|
468
|
-
.then((
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
resolve({ items: _data.items });
|
|
473
|
-
})
|
|
474
|
-
.catch(reject);
|
|
475
|
-
});
|
|
477
|
+
.roles()
|
|
478
|
+
.then((roles) => {
|
|
479
|
+
resolve({ items: roles.items });
|
|
480
|
+
})
|
|
481
|
+
.catch(reject);
|
|
476
482
|
}
|
|
477
|
-
if (!organization.roles) {
|
|
483
|
+
if (!organization.roles && !find(organization.org_roles, 'admin')) {
|
|
478
484
|
return reject(new Error(config.adminError));
|
|
479
485
|
}
|
|
480
|
-
|
|
486
|
+
|
|
487
|
+
managementAPIClient
|
|
488
|
+
.organization(organization.uid)
|
|
481
489
|
.roles()
|
|
482
|
-
.then((roles) =>
|
|
490
|
+
.then((roles) => {
|
|
491
|
+
resolve({ items: roles.items });
|
|
492
|
+
})
|
|
483
493
|
.catch(reject);
|
|
484
494
|
})
|
|
485
495
|
.catch((error) => reject(error));
|