@contentstack/cli-cm-export-to-csv 1.3.10 → 1.3.11

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.10",
2
+ "version": "1.3.11",
3
3
  "commands": {
4
4
  "cm:export-to-csv": {
5
5
  "id": "cm:export-to-csv",
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.10",
4
+ "version": "1.3.11",
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",
9
- "@contentstack/cli-utilities": "^1.4.5",
8
+ "@contentstack/cli-command": "^1.2.10",
9
+ "@contentstack/cli-utilities": "^1.5.0",
10
10
  "chalk": "^4.1.0",
11
11
  "fast-csv": "^4.3.6",
12
12
  "inquirer": "8.2.4",
@@ -17,7 +17,7 @@
17
17
  "@oclif/test": "^2.2.10",
18
18
  "chai": "^4.2.0",
19
19
  "debug": "^4.3.1",
20
- "eslint": "^8.18.0",
20
+ "eslint": "^7.32.0",
21
21
  "eslint-config-oclif": "^4.0.0",
22
22
  "globby": "^10.0.2",
23
23
  "mocha": "^10.0.0",
@@ -61,4 +61,4 @@
61
61
  }
62
62
  },
63
63
  "repository": "https://github.com/contentstack/cli"
64
- }
64
+ }
package/src/util/index.js CHANGED
@@ -8,7 +8,7 @@ const debug = require('debug')('export-to-csv');
8
8
  const checkboxPlus = require('inquirer-checkbox-plus-prompt');
9
9
 
10
10
  const config = require('./config.js');
11
- const { cliux } = require('@contentstack/cli-utilities');
11
+ const { cliux, configHandler } = require('@contentstack/cli-utilities');
12
12
 
13
13
  const directory = './data';
14
14
  const delimeter = os.platform() === 'win32' ? '\\' : '/';
@@ -59,8 +59,16 @@ async function getOrganizations(managementAPIClient) {
59
59
  }
60
60
 
61
61
  async function getOrganizationList(managementAPIClient, params, result = []) {
62
- const organizations = await managementAPIClient.organization().fetchAll(params);
63
- result = result.concat(organizations.items);
62
+ let organizations;
63
+ const configOrgUid = configHandler.get('oauthOrgUid');
64
+
65
+ if (configOrgUid) {
66
+ organizations = await managementAPIClient.organization(configOrgUid).fetch();
67
+ result = result.concat([organizations]);
68
+ } else {
69
+ organizations = await managementAPIClient.organization().fetchAll({ limit: 100 });
70
+ result = result.concat(organizations.items);
71
+ }
64
72
 
65
73
  if (!organizations.items || (organizations.items && organizations.items.length < params.limit)) {
66
74
  const orgMap = {};
@@ -76,26 +84,33 @@ async function getOrganizationList(managementAPIClient, params, result = []) {
76
84
  }
77
85
  }
78
86
 
79
- function getOrganizationsWhereUserIsAdmin(managementAPIClient) {
80
- return new Promise((resolve, reject) => {
87
+ async function getOrganizationsWhereUserIsAdmin(managementAPIClient) {
88
+ try {
81
89
  let result = {};
82
- managementAPIClient
83
- .getUser({ include_orgs_roles: true })
84
- .then((response) => {
85
- let organizations = response.organizations.filter((org) => {
86
- if (org.org_roles) {
87
- const org_role = org.org_roles.shift();
88
- return org_role.admin;
89
- }
90
- return org.is_owner === true;
91
- });
92
- organizations.forEach((org) => {
93
- result[org.name] = org.uid;
94
- });
95
- resolve(result);
96
- })
97
- .catch((error) => reject(error));
98
- });
90
+ const configOrgUid = configHandler.get('oauthOrgUid');
91
+
92
+ if (configOrgUid) {
93
+ const response = await managementAPIClient.organization(configOrgUid).fetch();
94
+ result[response.name] = response.uid;
95
+ } else {
96
+ const response = await managementAPIClient.getUser({ include_orgs_roles: true });
97
+ const organizations = response.organizations.filter((org) => {
98
+ if (org.org_roles) {
99
+ const org_role = org.org_roles.shift();
100
+ return org_role.admin;
101
+ }
102
+ return org.is_owner === true;
103
+ });
104
+
105
+ organizations.forEach((org) => {
106
+ result[org.name] = org.uid;
107
+ });
108
+ }
109
+
110
+ return result;
111
+ } catch (error) {
112
+ throw error;
113
+ }
99
114
  }
100
115
 
101
116
  function chooseStack(managementAPIClient, orgUid, stackApiKey) {