@contentstack/cli-cm-export-to-csv 1.0.1 → 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.
- package/README.md +5 -5
- package/oclif.manifest.json +1 -1
- package/package.json +21 -19
- package/src/util/index.js +30 -2
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
@contentstack/cli-cm-export-to-csv
|
|
2
2
|
=============
|
|
3
3
|
|
|
4
|
-
The cm:export-to-csv command allows you to export the following data into a CSV file:
|
|
4
|
+
The cm:export-to-csv command allows you to export the following data into a CSV file:
|
|
5
5
|
* Multiple stack’s content and structure (schema)
|
|
6
6
|
* [Organization users’ details](https://www.contentstack.com/docs/owners-and-admins/organization-users/)
|
|
7
|
-
|
|
8
|
-
To be able to export the content of a stack, you need to have access to it. Likewise, to export an organization’s user data, you need to be the “[owner](https://www.contentstack.com/docs/owners-and-admins/organization-roles/#organization-owner)” or an “[admin](https://www.contentstack.com/docs/owners-and-admins/organization-roles/#organization-admin)” user of that organization.
|
|
9
7
|
|
|
10
|
-
|
|
8
|
+
To be able to export the content of a stack, you need to have access to it. Likewise, to export an organization’s user data, you need to be the “[owner](https://www.contentstack.com/docs/owners-and-admins/organization-roles/#organization-owner)” or an “[admin](https://www.contentstack.com/docs/owners-and-admins/organization-roles/#organization-admin)” user of that organization.
|
|
9
|
+
|
|
10
|
+
Refer to the [Export Content to .CSV](https://www.contentstack.com/docs/developers/cli/export-content-to-csv-file/) file guide to learn more.
|
|
11
11
|
|
|
12
12
|
[](https://github.com/contentstack/cli/blob/main/LICENSE)
|
|
13
13
|
|
|
@@ -37,4 +37,4 @@ USAGE
|
|
|
37
37
|
$ csdx cm:export-to-csv
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
_See code: [src/commands/cm/export-to-csv.js](https://github.com/contentstack/cli/blob/
|
|
40
|
+
_See code: [src/commands/cm/export-to-csv.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-export-to-csv/src/commands/cm/export-to-csv.js)_
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"1.0.
|
|
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.
|
|
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.
|
|
9
|
-
"@contentstack/cli-utilities": "^1.0.
|
|
10
|
-
"@contentstack/management": "^1.
|
|
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": "
|
|
16
|
-
"inquirer-checkbox-plus-prompt": "
|
|
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": "^
|
|
29
|
+
"nyc": "^15.1.0"
|
|
30
30
|
},
|
|
31
31
|
"engines": {
|
|
32
32
|
"node": ">=8.0.0"
|
|
@@ -43,23 +43,25 @@
|
|
|
43
43
|
"cli",
|
|
44
44
|
"plugin"
|
|
45
45
|
],
|
|
46
|
+
"scripts": {
|
|
47
|
+
"pack": "npm pack && mv *.tgz ../../build",
|
|
48
|
+
"postpack": "rm -f oclif.manifest.json",
|
|
49
|
+
"prepack": "oclif-dev manifest && oclif-dev readme",
|
|
50
|
+
"test": "nyc mocha --forbid-only \"test/**/*.test.js\"",
|
|
51
|
+
"version": "oclif-dev readme && git add README.md"
|
|
52
|
+
},
|
|
53
|
+
"csdxConfig": {
|
|
54
|
+
"expiredCommands": {}
|
|
55
|
+
},
|
|
56
|
+
"main": "./src/commands/cm/export-to-csv.js",
|
|
46
57
|
"license": "MIT",
|
|
47
58
|
"oclif": {
|
|
48
59
|
"commands": "./src/commands",
|
|
49
60
|
"bin": "csdx",
|
|
50
61
|
"devPlugins": [
|
|
51
62
|
"@oclif/plugin-help"
|
|
52
|
-
]
|
|
63
|
+
],
|
|
64
|
+
"repositoryPrefix": "<%- repo %>/blob/main/packages/contentstack-export-to-csv/<%- commandPath %>"
|
|
53
65
|
},
|
|
54
|
-
"
|
|
55
|
-
"expiredCommands": {}
|
|
56
|
-
},
|
|
57
|
-
"repository": "contentstack/cli",
|
|
58
|
-
"scripts": {
|
|
59
|
-
"postpack": "rm -f oclif.manifest.json",
|
|
60
|
-
"posttest": "eslint .",
|
|
61
|
-
"prepack": "oclif-dev manifest && oclif-dev readme",
|
|
62
|
-
"test": "nyc --reporter=html mocha --forbid-only \"test/**/*.test.js\"",
|
|
63
|
-
"version": "oclif-dev readme && git add README.md"
|
|
64
|
-
}
|
|
66
|
+
"repository": "https://github.com/contentstack/cli"
|
|
65
67
|
}
|
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
|
-
|
|
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,
|