@contentstack/cli-cm-export-to-csv 1.3.3 → 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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.3.3",
2
+ "version": "1.3.4",
3
3
  "commands": {
4
4
  "cm:export-to-csv": {
5
5
  "id": "cm:export-to-csv",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-export-to-csv",
3
3
  "description": "Export entities to csv",
4
- "version": "1.3.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": {
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
 
@@ -403,24 +406,21 @@ function getOrgUsers(managementAPIClient, orgUid, ecsv) {
403
406
  .getUser({ include_orgs_roles: true })
404
407
  .then(async (response) => {
405
408
  let organization = response.organizations.filter((org) => org.uid === orgUid).pop();
409
+ if (!organization) return reject(new Error('Org UID not found.'));
406
410
  if (organization.is_owner === true) {
407
411
  return managementAPIClient
408
412
  .organization(organization.uid)
409
- .fetch()
410
- .then((_response) => {
411
- _response
412
- .getInvitations()
413
- .then((_data) => {
414
- resolve({ items: _data.items });
415
- })
416
- .catch(reject);
417
- });
413
+ .getInvitations()
414
+ .then((data) => {
415
+ resolve({ items: data.items });
416
+ })
417
+ .catch(reject);
418
418
  }
419
- if (!organization.getInvitations) {
419
+ if (!organization.getInvitations && !find(organization.org_roles, 'admin')) {
420
420
  return reject(new Error(config.adminError));
421
421
  }
422
422
  try {
423
- const users = await getUsers(organization, { skip: 0, page: 1, limit: 100 });
423
+ const users = await getUsers(managementAPIClient, organization, { skip: 0, page: 1, limit: 100 });
424
424
  return resolve({ items: users });
425
425
  } catch (error) {
426
426
  return reject(error);
@@ -430,9 +430,9 @@ function getOrgUsers(managementAPIClient, orgUid, ecsv) {
430
430
  });
431
431
  }
432
432
 
433
- async function getUsers(organization, params, result = []) {
433
+ async function getUsers(managementAPIClient, organization, params, result = []) {
434
434
  try {
435
- const users = await organization.getInvitations(params);
435
+ const users = await managementAPIClient.organization(organization.uid).getInvitations(params);
436
436
  if (!users.items || (users.items && !users.items.length)) {
437
437
  return result;
438
438
  } else {
@@ -440,7 +440,7 @@ async function getUsers(organization, params, result = []) {
440
440
  params.skip = params.page * params.limit;
441
441
  params.page++;
442
442
  await wait(200);
443
- return getUsers(organization, params, result);
443
+ return getUsers(managementAPIClient, organization, params, result);
444
444
  }
445
445
  } catch (error) {
446
446
  console.error(error);
@@ -474,22 +474,22 @@ function getOrgRoles(managementAPIClient, orgUid, ecsv) {
474
474
  if (organization.is_owner === true) {
475
475
  return managementAPIClient
476
476
  .organization(organization.uid)
477
- .fetch()
478
- .then((_response) => {
479
- _response
480
- .roles()
481
- .then((_data) => {
482
- resolve({ items: _data.items });
483
- })
484
- .catch(reject);
485
- });
477
+ .roles()
478
+ .then((roles) => {
479
+ resolve({ items: roles.items });
480
+ })
481
+ .catch(reject);
486
482
  }
487
- if (!organization.roles) {
483
+ if (!organization.roles && !find(organization.org_roles, 'admin')) {
488
484
  return reject(new Error(config.adminError));
489
485
  }
490
- organization
486
+
487
+ managementAPIClient
488
+ .organization(organization.uid)
491
489
  .roles()
492
- .then((roles) => resolve(roles))
490
+ .then((roles) => {
491
+ resolve({ items: roles.items });
492
+ })
493
493
  .catch(reject);
494
494
  })
495
495
  .catch((error) => reject(error));