@contentstack/cli-cm-export-to-csv 1.1.0 → 1.3.0

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022 Contentstack
3
+ Copyright (c) 2023 Contentstack
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.1.0",
2
+ "version": "1.3.0",
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.1.0",
4
+ "version": "1.3.0",
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.1.0",
9
- "@contentstack/cli-utilities": "^1.1.0",
8
+ "@contentstack/cli-command": "^1.2.1",
9
+ "@contentstack/cli-utilities": "^1.2.1",
10
10
  "chalk": "^4.1.0",
11
11
  "fast-csv": "^4.3.6",
12
12
  "inquirer": "8.2.4",
@@ -14,7 +14,6 @@
14
14
  "mkdirp": "^1.0.4"
15
15
  },
16
16
  "devDependencies": {
17
- "oclif": "^3.1.2",
18
17
  "@oclif/test": "^2.2.10",
19
18
  "chai": "^4.2.0",
20
19
  "debug": "^4.3.1",
@@ -22,10 +21,11 @@
22
21
  "eslint-config-oclif": "^4.0.0",
23
22
  "globby": "^10.0.2",
24
23
  "mocha": "^10.0.0",
25
- "nyc": "^15.1.0"
24
+ "nyc": "^15.1.0",
25
+ "oclif": "^3.1.2"
26
26
  },
27
27
  "engines": {
28
- "node": ">=8.0.0"
28
+ "node": ">=14.0.0"
29
29
  },
30
30
  "files": [
31
31
  "/npm-shrinkwrap.json",
@@ -44,10 +44,8 @@
44
44
  "postpack": "rm -f oclif.manifest.json",
45
45
  "prepack": "oclif manifest && oclif readme",
46
46
  "test": "nyc mocha --forbid-only \"test/**/*.test.js\"",
47
- "version": "oclif readme && git add README.md"
48
- },
49
- "csdxConfig": {
50
- "expiredCommands": {}
47
+ "version": "oclif readme && git add README.md",
48
+ "clean": "rm -rf ./node_modules tsconfig.build.tsbuildinfo"
51
49
  },
52
50
  "main": "./src/commands/cm/export-to-csv.js",
53
51
  "license": "MIT",
@@ -56,5 +54,10 @@
56
54
  "bin": "csdx",
57
55
  "repositoryPrefix": "<%- repo %>/blob/main/packages/contentstack-export-to-csv/<%- commandPath %>"
58
56
  },
57
+ "csdxConfig": {
58
+ "shortCommandName": {
59
+ "cm:export-to-csv": "EXPRTCSV"
60
+ }
61
+ },
59
62
  "repository": "https://github.com/contentstack/cli"
60
63
  }
@@ -1,5 +1,5 @@
1
- const { Command, flags } = require('@contentstack/cli-command');
2
- const { configHandler, managementSDKClient } = require('@contentstack/cli-utilities');
1
+ const { Command } = require('@contentstack/cli-command');
2
+ const { configHandler, managementSDKClient, flags, isAuthenticated } = require('@contentstack/cli-utilities');
3
3
  const util = require('../../util');
4
4
  const config = require('../../util/config');
5
5
 
@@ -43,14 +43,6 @@ class ExportToCsvCommand extends Command {
43
43
  }),
44
44
  };
45
45
 
46
- get getAuthToken() {
47
- try {
48
- return this.authToken;
49
- } catch (error) {
50
- return undefined;
51
- }
52
- }
53
-
54
46
  async run() {
55
47
  try {
56
48
  let action, managementAPIClient;
@@ -101,7 +93,7 @@ class ExportToCsvCommand extends Command {
101
93
  } else {
102
94
  let organization;
103
95
 
104
- if (!this.isAuthenticated()) {
96
+ if (!isAuthenticated()) {
105
97
  this.error(config.CLI_EXPORT_CSV_ENTRIES_ERROR, {
106
98
  exit: 2,
107
99
  suggestions: ['https://www.contentstack.com/docs/developers/cli/authentication/'],
@@ -172,7 +164,7 @@ class ExportToCsvCommand extends Command {
172
164
  case config.exportUsers:
173
165
  case 'users': {
174
166
  try {
175
- if (!this.isAuthenticated()) {
167
+ if (!isAuthenticated()) {
176
168
  this.error(config.CLI_EXPORT_CSV_LOGIN_FAILED, {
177
169
  exit: 2,
178
170
  suggestions: ['https://www.contentstack.com/docs/developers/cli/authentication/'],
package/src/util/index.js CHANGED
@@ -514,8 +514,8 @@ function cleanOrgUsers(orgUsers, mappedUsers, mappedRoles) {
514
514
  formattedUser['Organization Role'] = determineUserOrgRole(user, mappedRoles);
515
515
  formattedUser['Status'] = user['status'];
516
516
  formattedUser['Invited By'] = invitedBy;
517
- formattedUser['Created Time'] = user['created_at'];
518
- formattedUser['Updated Time'] = user['updated_at'];
517
+ formattedUser['Created Time'] = getFormattedDate(user['created_at']);
518
+ formattedUser['Updated Time'] = getFormattedDate(user['updated_at']);
519
519
  userList.push(formattedUser);
520
520
  });
521
521
  return userList;
@@ -528,6 +528,16 @@ function kebabize(str) {
528
528
  .join('-');
529
529
  }
530
530
 
531
+ function getFormattedDate(date) {
532
+ if (!(date instanceof Date)) {
533
+ date = new Date(date);
534
+ }
535
+ const year = date.getFullYear();
536
+ const month = (1 + date.getMonth()).toString().padStart(2, '0');
537
+ const day = date.getDate().toString().padStart(2, '0');
538
+ return month + '/' + day + '/' + year;
539
+ }
540
+
531
541
  // https://stackoverflow.com/questions/19098797/fastest-way-to-flatten-un-flatten-nested-json-objects
532
542
  function flatten(data) {
533
543
  let result = {};