@contentstack/cli-cm-export-to-csv 1.0.2 → 1.0.3

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 +1 @@
1
- {"version":"1.0.2","commands":{"cm:export-to-csv":{"id":"cm:export-to-csv","description":"Export entries or organization users to csv using this command","pluginName":"@contentstack/cli-cm-export-to-csv","pluginType":"core","aliases":[],"examples":["csdx cm:export-to-csv","","Exporting entries to csv","csdx cm:export-to-csv --action <entries> --locale <locale> --alias <management-token-alias> --content-type <content-type>","","Exporting entries to csv with stack name provided","csdx cm:export-to-csv --action <entries> --locale <locale> --alias <management-token-alias> --content-type <content-type> --stack-name <stack-name>","","Exporting organization users to csv","csdx cm:export-to-csv --action <users> --org <org-uid>","","Exporting organization users to csv with organization name provided","csdx cm:export-to-csv --action <users> --org <org-uid> --org-name <org-name>"],"flags":{"action":{"name":"action","type":"option","description":"Option to export data (entries, users)","required":false,"options":["entries","users"]},"alias":{"name":"alias","type":"option","char":"a","description":"Alias of the management token"},"org":{"name":"org","type":"option","description":"Provide organization UID to clone org users","required":false},"stack-name":{"name":"stack-name","type":"option","char":"n","description":"Name of the stack that needs to be created as csv filename.","required":false},"org-name":{"name":"org-name","type":"option","description":"Name of the organization that needs to be created as csv filename.","required":false},"locale":{"name":"locale","type":"option","description":"Locale for which entries need to be exported","required":false},"content-type":{"name":"content-type","type":"option","description":"Content type for which entries needs to be exported","required":false}},"args":[]}}}
1
+ {"version":"1.0.3","commands":{"cm:export-to-csv":{"id":"cm:export-to-csv","description":"Export entries or organization users to csv using this command","pluginName":"@contentstack/cli-cm-export-to-csv","pluginType":"core","aliases":[],"examples":["csdx cm:export-to-csv","","Exporting entries to csv","csdx cm:export-to-csv --action <entries> --locale <locale> --alias <management-token-alias> --content-type <content-type>","","Exporting entries to csv with stack name provided","csdx cm:export-to-csv --action <entries> --locale <locale> --alias <management-token-alias> --content-type <content-type> --stack-name <stack-name>","","Exporting organization users to csv","csdx cm:export-to-csv --action <users> --org <org-uid>","","Exporting organization users to csv with organization name provided","csdx cm:export-to-csv --action <users> --org <org-uid> --org-name <org-name>"],"flags":{"action":{"name":"action","type":"option","description":"Option to export data (entries, users)","required":false,"options":["entries","users"]},"alias":{"name":"alias","type":"option","char":"a","description":"Alias of the management token"},"org":{"name":"org","type":"option","description":"Provide organization UID to clone org users","required":false},"stack-name":{"name":"stack-name","type":"option","char":"n","description":"Name of the stack that needs to be created as csv filename.","required":false},"org-name":{"name":"org-name","type":"option","description":"Name of the organization that needs to be created as csv filename.","required":false},"locale":{"name":"locale","type":"option","description":"Locale for which entries need to be exported","required":false},"content-type":{"name":"content-type","type":"option","description":"Content type for which entries needs to be exported","required":false}},"args":[]}}}
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-export-to-csv",
3
3
  "description": "Export entities to csv",
4
- "version": "1.0.2",
4
+ "version": "1.0.3",
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.2",
9
- "@contentstack/cli-utilities": "^1.0.3",
10
- "@contentstack/management": "^1.3.0",
8
+ "@contentstack/cli-command": "^1.0.3",
9
+ "@contentstack/cli-utilities": "^1.0.4",
10
+ "@contentstack/management": "^1.6.0",
11
11
  "@oclif/command": "^1.8.16",
12
12
  "@oclif/config": "^1.18.3",
13
13
  "chalk": "^4.1.0",
14
14
  "fast-csv": "^4.3.6",
15
- "inquirer": "^8.2.4",
16
- "inquirer-checkbox-plus-prompt": "^1.0.1",
15
+ "inquirer": "8.2.4",
16
+ "inquirer-checkbox-plus-prompt": "1.0.1",
17
17
  "mkdirp": "^1.0.4"
18
18
  },
19
19
  "devDependencies": {
@@ -26,7 +26,7 @@
26
26
  "eslint-config-oclif": "^4.0.0",
27
27
  "globby": "^10.0.2",
28
28
  "mocha": "^10.0.0",
29
- "nyc": "^14.1.1"
29
+ "nyc": "^15.1.0"
30
30
  },
31
31
  "engines": {
32
32
  "node": ">=8.0.0"
package/src/util/index.js CHANGED
@@ -383,7 +383,7 @@ function getOrgUsers(managementAPIClient, orgUid, ecsv) {
383
383
  return new Promise((resolve, reject) => {
384
384
  managementAPIClient
385
385
  .getUser({ include_orgs_roles: true })
386
- .then((response) => {
386
+ .then(async (response) => {
387
387
  let organization = response.organizations.filter((org) => org.uid === orgUid).pop();
388
388
  if (organization.is_owner === true) {
389
389
  let cma = ecsv.region.cma;
@@ -396,12 +396,34 @@ function getOrgUsers(managementAPIClient, orgUid, ecsv) {
396
396
  if (!organization.getInvitations) {
397
397
  return reject(new Error(config.adminError));
398
398
  }
399
- organization.getInvitations().then((users) => resolve(users));
399
+ try {
400
+ const users = await getUsers(organization, { skip: 0, page: 1, limit: 100 });
401
+ return resolve({ items: users });
402
+ } catch (error) {
403
+ return reject(error);
404
+ }
400
405
  })
401
406
  .catch((error) => reject(error));
402
407
  });
403
408
  }
404
409
 
410
+ async function getUsers(organization, params, result = []) {
411
+ try {
412
+ const users = await organization.getInvitations(params);
413
+ if (!users.items || (users.items && !users.items.length)) {
414
+ return result;
415
+ } else {
416
+ result = result.concat(users.items);
417
+ params.skip = params.page * params.limit;
418
+ params.page++;
419
+ await wait(200);
420
+ return getUsers(organization, params, result);
421
+ }
422
+ } catch (error) {
423
+ throw error;
424
+ }
425
+ }
426
+
405
427
  function getMappedUsers(users) {
406
428
  let mappedUsers = {};
407
429
  users.items.forEach((user) => {
@@ -528,6 +550,12 @@ function formatError(error) {
528
550
  return message;
529
551
  }
530
552
 
553
+ function wait(time) {
554
+ return new Promise(res => {
555
+ setTimeout(res, time);
556
+ });
557
+ }
558
+
531
559
  module.exports = {
532
560
  chooseOrganization: chooseOrganization,
533
561
  chooseStack: chooseStack,