@internxt/cli 1.5.2 → 1.5.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.
Files changed (38) hide show
  1. package/README.md +25 -25
  2. package/dist/commands/add-cert.d.ts +1 -1
  3. package/dist/commands/add-cert.js +23 -23
  4. package/dist/commands/config.js +8 -3
  5. package/dist/commands/create-folder.js +10 -5
  6. package/dist/commands/delete-permanently-file.js +8 -3
  7. package/dist/commands/delete-permanently-folder.js +8 -3
  8. package/dist/commands/download-file.js +21 -16
  9. package/dist/commands/list.js +8 -3
  10. package/dist/commands/login.js +8 -3
  11. package/dist/commands/logout.js +8 -3
  12. package/dist/commands/logs.js +8 -3
  13. package/dist/commands/move-file.js +8 -3
  14. package/dist/commands/move-folder.js +8 -3
  15. package/dist/commands/rename-file.js +8 -3
  16. package/dist/commands/rename-folder.js +8 -3
  17. package/dist/commands/trash-clear.js +8 -3
  18. package/dist/commands/trash-file.js +8 -3
  19. package/dist/commands/trash-folder.js +8 -3
  20. package/dist/commands/trash-list.js +8 -3
  21. package/dist/commands/trash-restore-file.js +8 -3
  22. package/dist/commands/trash-restore-folder.js +8 -3
  23. package/dist/commands/upload-file.js +15 -9
  24. package/dist/commands/webdav-config.js +8 -3
  25. package/dist/commands/webdav.js +22 -22
  26. package/dist/commands/whoami.js +8 -3
  27. package/dist/hooks/prerun/auth_check.js +13 -7
  28. package/dist/utils/cli.utils.d.ts +13 -4
  29. package/dist/utils/cli.utils.js +44 -10
  30. package/dist/utils/xml.utils.d.ts +1 -1
  31. package/dist/utils/xml.utils.js +3 -3
  32. package/dist/webdav/handlers/PROPFIND.handler.js +12 -1
  33. package/dist/webdav/middewares/auth.middleware.js +10 -2
  34. package/dist/webdav/middewares/errors.middleware.js +8 -13
  35. package/dist/webdav/webdav-server.d.ts +2 -1
  36. package/dist/webdav/webdav-server.js +6 -3
  37. package/oclif.manifest.json +1 -1
  38. package/package.json +8 -8
@@ -6,7 +6,6 @@ const cli_utils_1 = require("../utils/cli.utils");
6
6
  const command_types_1 = require("../types/command.types");
7
7
  const validation_service_1 = require("../services/validation.service");
8
8
  const drive_file_service_1 = require("../services/drive/drive-file.service");
9
- const errors_utils_1 = require("../utils/errors.utils");
10
9
  class RenameFile extends core_1.Command {
11
10
  static args = {};
12
11
  static description = 'Rename a file.';
@@ -40,8 +39,14 @@ class RenameFile extends core_1.Command {
40
39
  return { success: true, message, file: { uuid: fileUuid, plainName: newName } };
41
40
  };
42
41
  catch = async (error) => {
43
- errors_utils_1.ErrorUtils.report(this.error.bind(this), error, { command: this.id });
44
- cli_utils_1.CLIUtils.error(this.log.bind(this), error.message);
42
+ const { flags } = await this.parse(RenameFile);
43
+ cli_utils_1.CLIUtils.catchError({
44
+ error,
45
+ command: this.id,
46
+ logReporter: this.log.bind(this),
47
+ errorReporter: this.error.bind(this),
48
+ jsonFlag: flags['json'],
49
+ });
45
50
  this.exit(1);
46
51
  };
47
52
  getFileUuid = async (fileUuidFlag, nonInteractive) => {
@@ -6,7 +6,6 @@ const cli_utils_1 = require("../utils/cli.utils");
6
6
  const command_types_1 = require("../types/command.types");
7
7
  const validation_service_1 = require("../services/validation.service");
8
8
  const drive_folder_service_1 = require("../services/drive/drive-folder.service");
9
- const errors_utils_1 = require("../utils/errors.utils");
10
9
  class RenameFolder extends core_1.Command {
11
10
  static args = {};
12
11
  static description = 'Rename a folder.';
@@ -40,8 +39,14 @@ class RenameFolder extends core_1.Command {
40
39
  return { success: true, message, folder: { uuid: folderUuid, plainName: name } };
41
40
  };
42
41
  catch = async (error) => {
43
- errors_utils_1.ErrorUtils.report(this.error.bind(this), error, { command: this.id });
44
- cli_utils_1.CLIUtils.error(this.log.bind(this), error.message);
42
+ const { flags } = await this.parse(RenameFolder);
43
+ cli_utils_1.CLIUtils.catchError({
44
+ error,
45
+ command: this.id,
46
+ logReporter: this.log.bind(this),
47
+ errorReporter: this.error.bind(this),
48
+ jsonFlag: flags['json'],
49
+ });
45
50
  this.exit(1);
46
51
  };
47
52
  getFolderUuid = async (folderUuidFlag, nonInteractive) => {
@@ -4,7 +4,6 @@ const core_1 = require("@oclif/core");
4
4
  const config_service_1 = require("../services/config.service");
5
5
  const cli_utils_1 = require("../utils/cli.utils");
6
6
  const command_types_1 = require("../types/command.types");
7
- const errors_utils_1 = require("../utils/errors.utils");
8
7
  const trash_service_1 = require("../services/drive/trash.service");
9
8
  const inquirer_utils_1 = require("../utils/inquirer.utils");
10
9
  class TrashClear extends core_1.Command {
@@ -45,8 +44,14 @@ class TrashClear extends core_1.Command {
45
44
  return { success: true, message };
46
45
  };
47
46
  catch = async (error) => {
48
- errors_utils_1.ErrorUtils.report(this.error.bind(this), error, { command: this.id });
49
- cli_utils_1.CLIUtils.error(this.log.bind(this), error.message);
47
+ const { flags } = await this.parse(TrashClear);
48
+ cli_utils_1.CLIUtils.catchError({
49
+ error,
50
+ command: this.id,
51
+ logReporter: this.log.bind(this),
52
+ errorReporter: this.error.bind(this),
53
+ jsonFlag: flags['json'],
54
+ });
50
55
  this.exit(1);
51
56
  };
52
57
  getConfirmation = async () => {
@@ -5,7 +5,6 @@ const config_service_1 = require("../services/config.service");
5
5
  const cli_utils_1 = require("../utils/cli.utils");
6
6
  const command_types_1 = require("../types/command.types");
7
7
  const validation_service_1 = require("../services/validation.service");
8
- const errors_utils_1 = require("../utils/errors.utils");
9
8
  const trash_service_1 = require("../services/drive/trash.service");
10
9
  class TrashFile extends core_1.Command {
11
10
  static args = {};
@@ -34,8 +33,14 @@ class TrashFile extends core_1.Command {
34
33
  return { success: true, message, file: { uuid } };
35
34
  };
36
35
  catch = async (error) => {
37
- errors_utils_1.ErrorUtils.report(this.error.bind(this), error, { command: this.id });
38
- cli_utils_1.CLIUtils.error(this.log.bind(this), error.message);
36
+ const { flags } = await this.parse(TrashFile);
37
+ cli_utils_1.CLIUtils.catchError({
38
+ error,
39
+ command: this.id,
40
+ logReporter: this.log.bind(this),
41
+ errorReporter: this.error.bind(this),
42
+ jsonFlag: flags['json'],
43
+ });
39
44
  this.exit(1);
40
45
  };
41
46
  getFileUuid = async (fileUuidFlag, nonInteractive) => {
@@ -5,7 +5,6 @@ const config_service_1 = require("../services/config.service");
5
5
  const cli_utils_1 = require("../utils/cli.utils");
6
6
  const command_types_1 = require("../types/command.types");
7
7
  const validation_service_1 = require("../services/validation.service");
8
- const errors_utils_1 = require("../utils/errors.utils");
9
8
  const trash_service_1 = require("../services/drive/trash.service");
10
9
  class TrashFolder extends core_1.Command {
11
10
  static args = {};
@@ -34,8 +33,14 @@ class TrashFolder extends core_1.Command {
34
33
  return { success: true, message, folder: { uuid } };
35
34
  };
36
35
  catch = async (error) => {
37
- errors_utils_1.ErrorUtils.report(this.error.bind(this), error, { command: this.id });
38
- cli_utils_1.CLIUtils.error(this.log.bind(this), error.message);
36
+ const { flags } = await this.parse(TrashFolder);
37
+ cli_utils_1.CLIUtils.catchError({
38
+ error,
39
+ command: this.id,
40
+ logReporter: this.log.bind(this),
41
+ errorReporter: this.error.bind(this),
42
+ jsonFlag: flags['json'],
43
+ });
39
44
  this.exit(1);
40
45
  };
41
46
  getFolderUuid = async (folderUuidFlag, nonInteractive) => {
@@ -5,7 +5,6 @@ const config_service_1 = require("../services/config.service");
5
5
  const cli_utils_1 = require("../utils/cli.utils");
6
6
  const command_types_1 = require("../types/command.types");
7
7
  const format_utils_1 = require("../utils/format.utils");
8
- const errors_utils_1 = require("../utils/errors.utils");
9
8
  const trash_service_1 = require("../services/drive/trash.service");
10
9
  class TrashList extends core_1.Command {
11
10
  static args = {};
@@ -58,8 +57,14 @@ class TrashList extends core_1.Command {
58
57
  return { success: true, list: { folders, files } };
59
58
  };
60
59
  catch = async (error) => {
61
- errors_utils_1.ErrorUtils.report(this.error.bind(this), error, { command: this.id });
62
- cli_utils_1.CLIUtils.error(this.log.bind(this), error.message);
60
+ const { flags } = await this.parse(TrashList);
61
+ cli_utils_1.CLIUtils.catchError({
62
+ error,
63
+ command: this.id,
64
+ logReporter: this.log.bind(this),
65
+ errorReporter: this.error.bind(this),
66
+ jsonFlag: flags['json'],
67
+ });
63
68
  this.exit(1);
64
69
  };
65
70
  }
@@ -6,7 +6,6 @@ const cli_utils_1 = require("../utils/cli.utils");
6
6
  const command_types_1 = require("../types/command.types");
7
7
  const validation_service_1 = require("../services/validation.service");
8
8
  const drive_file_service_1 = require("../services/drive/drive-file.service");
9
- const errors_utils_1 = require("../utils/errors.utils");
10
9
  class TrashRestoreFile extends core_1.Command {
11
10
  static args = {};
12
11
  static description = 'Restore a trashed file into a destination folder.';
@@ -44,8 +43,14 @@ class TrashRestoreFile extends core_1.Command {
44
43
  return { success: true, message, file };
45
44
  };
46
45
  catch = async (error) => {
47
- errors_utils_1.ErrorUtils.report(this.error.bind(this), error, { command: this.id });
48
- cli_utils_1.CLIUtils.error(this.log.bind(this), error.message);
46
+ const { flags } = await this.parse(TrashRestoreFile);
47
+ cli_utils_1.CLIUtils.catchError({
48
+ error,
49
+ command: this.id,
50
+ logReporter: this.log.bind(this),
51
+ errorReporter: this.error.bind(this),
52
+ jsonFlag: flags['json'],
53
+ });
49
54
  this.exit(1);
50
55
  };
51
56
  getFileUuid = async (fileUuidFlag, nonInteractive) => {
@@ -6,7 +6,6 @@ const drive_folder_service_1 = require("../services/drive/drive-folder.service")
6
6
  const cli_utils_1 = require("../utils/cli.utils");
7
7
  const command_types_1 = require("../types/command.types");
8
8
  const validation_service_1 = require("../services/validation.service");
9
- const errors_utils_1 = require("../utils/errors.utils");
10
9
  class TrashRestoreFolder extends core_1.Command {
11
10
  static args = {};
12
11
  static description = 'Restore a trashed folder into a destination folder.';
@@ -44,8 +43,14 @@ class TrashRestoreFolder extends core_1.Command {
44
43
  return { success: true, message, folder };
45
44
  };
46
45
  catch = async (error) => {
47
- errors_utils_1.ErrorUtils.report(this.error.bind(this), error, { command: this.id });
48
- cli_utils_1.CLIUtils.error(this.log.bind(this), error.message);
46
+ const { flags } = await this.parse(TrashRestoreFolder);
47
+ cli_utils_1.CLIUtils.catchError({
48
+ error,
49
+ command: this.id,
50
+ logReporter: this.log.bind(this),
51
+ errorReporter: this.error.bind(this),
52
+ jsonFlag: flags['json'],
53
+ });
49
54
  this.exit(1);
50
55
  };
51
56
  getFolderUuid = async (folderUuidFlag, nonInteractive) => {
@@ -60,7 +60,7 @@ class UploadFile extends core_1.Command {
60
60
  if (destinationFolderUuid.trim().length === 0) {
61
61
  destinationFolderUuid = userCredentials.user.rootFolderId;
62
62
  }
63
- cli_utils_1.CLIUtils.doing('Preparing Network');
63
+ cli_utils_1.CLIUtils.doing('Preparing Network', flags['json']);
64
64
  const { user } = await auth_service_1.AuthService.instance.getAuthDetails();
65
65
  const networkModule = sdk_manager_service_1.SdkManager.instance.getNetwork({
66
66
  user: user.bridgeUser,
@@ -73,14 +73,14 @@ class UploadFile extends core_1.Command {
73
73
  encryptionKey: user.mnemonic,
74
74
  });
75
75
  const networkFacade = new network_facade_service_1.NetworkFacade(networkModule, environment, download_service_1.DownloadService.instance, crypto_service_1.CryptoService.instance);
76
- cli_utils_1.CLIUtils.done();
76
+ cli_utils_1.CLIUtils.done(flags['json']);
77
77
  const readStream = (0, node_fs_1.createReadStream)(filePath);
78
78
  const timer = cli_utils_1.CLIUtils.timer();
79
79
  const progressBar = cli_utils_1.CLIUtils.progress({
80
80
  format: 'Uploading file [{bar}] {percentage}%',
81
81
  linewrap: true,
82
- });
83
- progressBar.start(100, 0);
82
+ }, flags['json']);
83
+ progressBar?.start(100, 0);
84
84
  let bufferStream;
85
85
  let fileStream = readStream;
86
86
  const isThumbnailable = (0, thumbnail_utils_1.isFileThumbnailable)(fileType);
@@ -89,7 +89,7 @@ class UploadFile extends core_1.Command {
89
89
  fileStream = readStream.pipe(bufferStream);
90
90
  }
91
91
  const progressCallback = (progress) => {
92
- progressBar.update(progress * 100 * 0.99);
92
+ progressBar?.update(progress * 100 * 0.99);
93
93
  };
94
94
  const fileId = await new Promise((resolve, reject) => {
95
95
  const state = networkFacade.uploadFile(fileStream, stats.size, user.bucket, (err, res) => {
@@ -124,8 +124,8 @@ class UploadFile extends core_1.Command {
124
124
  catch (error) {
125
125
  errors_utils_1.ErrorUtils.report(this.error.bind(this), error, { command: this.id });
126
126
  }
127
- progressBar.update(100);
128
- progressBar.stop();
127
+ progressBar?.update(100);
128
+ progressBar?.stop();
129
129
  const uploadTime = timer.stop();
130
130
  this.log('\n');
131
131
  const message = `File uploaded in ${uploadTime}ms, view it at ${config_service_1.ConfigService.instance.get('DRIVE_URL')}/file/${createdDriveFile.uuid}`;
@@ -133,8 +133,14 @@ class UploadFile extends core_1.Command {
133
133
  return { success: true, message, file: createdDriveFile };
134
134
  };
135
135
  catch = async (error) => {
136
- errors_utils_1.ErrorUtils.report(this.error.bind(this), error, { command: this.id });
137
- cli_utils_1.CLIUtils.error(this.log.bind(this), error.message);
136
+ const { flags } = await this.parse(UploadFile);
137
+ cli_utils_1.CLIUtils.catchError({
138
+ error,
139
+ command: this.id,
140
+ logReporter: this.log.bind(this),
141
+ errorReporter: this.error.bind(this),
142
+ jsonFlag: flags['json'],
143
+ });
138
144
  this.exit(1);
139
145
  };
140
146
  getDestinationFolderUuid = async (destinationFolderUuidFlag, nonInteractive) => {
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const core_1 = require("@oclif/core");
4
4
  const config_service_1 = require("../services/config.service");
5
5
  const cli_utils_1 = require("../utils/cli.utils");
6
- const errors_utils_1 = require("../utils/errors.utils");
7
6
  const command_types_1 = require("../types/command.types");
8
7
  const validation_service_1 = require("../services/validation.service");
9
8
  class WebDAVConfig extends core_1.Command {
@@ -67,8 +66,14 @@ class WebDAVConfig extends core_1.Command {
67
66
  return { success: true, message, config: webdavConfig };
68
67
  };
69
68
  catch = async (error) => {
70
- errors_utils_1.ErrorUtils.report(this.error.bind(this), error, { command: this.id });
71
- cli_utils_1.CLIUtils.error(this.log.bind(this), error.message);
69
+ const { flags } = await this.parse(WebDAVConfig);
70
+ cli_utils_1.CLIUtils.catchError({
71
+ error,
72
+ command: this.id,
73
+ logReporter: this.log.bind(this),
74
+ errorReporter: this.error.bind(this),
75
+ jsonFlag: flags['json'],
76
+ });
72
77
  this.exit(1);
73
78
  };
74
79
  }
@@ -4,7 +4,6 @@ const core_1 = require("@oclif/core");
4
4
  const pm2_utils_1 = require("../utils/pm2.utils");
5
5
  const cli_utils_1 = require("../utils/cli.utils");
6
6
  const config_service_1 = require("../services/config.service");
7
- const errors_utils_1 = require("../utils/errors.utils");
8
7
  const auth_service_1 = require("../services/auth.service");
9
8
  class Webdav extends core_1.Command {
10
9
  static args = {
@@ -24,23 +23,23 @@ class Webdav extends core_1.Command {
24
23
  static flags = {};
25
24
  static enableJsonFlag = true;
26
25
  run = async () => {
27
- const { args } = await this.parse(Webdav);
26
+ const { args, flags } = await this.parse(Webdav);
28
27
  let message = '';
29
28
  let success = true;
30
29
  await pm2_utils_1.PM2Utils.connect();
31
30
  switch (args.action) {
32
31
  case 'enable': {
33
32
  await auth_service_1.AuthService.instance.getAuthDetails();
34
- message = await this.enableWebDav();
33
+ message = await this.enableWebDav(flags['json']);
35
34
  break;
36
35
  }
37
36
  case 'disable': {
38
- message = await this.disableWebDav();
37
+ message = await this.disableWebDav(flags['json']);
39
38
  break;
40
39
  }
41
40
  case 'restart': {
42
41
  await auth_service_1.AuthService.instance.getAuthDetails();
43
- message = await this.restartWebDav();
42
+ message = await this.restartWebDav(flags['json']);
44
43
  break;
45
44
  }
46
45
  case 'status': {
@@ -58,20 +57,21 @@ class Webdav extends core_1.Command {
58
57
  return { success, message, action: args.action };
59
58
  };
60
59
  catch = async (error) => {
61
- errors_utils_1.ErrorUtils.report(this.error.bind(this), error, { command: this.id });
62
- if (error instanceof Error) {
63
- cli_utils_1.CLIUtils.error(this.log.bind(this), error.message);
64
- }
65
- else {
66
- cli_utils_1.CLIUtils.error(this.log.bind(this), JSON.stringify(error));
67
- }
60
+ const { flags } = await this.parse(Webdav);
61
+ cli_utils_1.CLIUtils.catchError({
62
+ error,
63
+ command: this.id,
64
+ logReporter: this.log.bind(this),
65
+ errorReporter: this.error.bind(this),
66
+ jsonFlag: flags['json'],
67
+ });
68
68
  this.exit(1);
69
69
  };
70
- enableWebDav = async () => {
71
- cli_utils_1.CLIUtils.doing('Starting Internxt WebDav server...');
70
+ enableWebDav = async (jsonFlag) => {
71
+ cli_utils_1.CLIUtils.doing('Starting Internxt WebDav server...', jsonFlag);
72
72
  await pm2_utils_1.PM2Utils.killWebDavServer();
73
73
  await pm2_utils_1.PM2Utils.startWebDavServer();
74
- cli_utils_1.CLIUtils.done();
74
+ cli_utils_1.CLIUtils.done(jsonFlag);
75
75
  const { status } = await pm2_utils_1.PM2Utils.webdavServerStatus();
76
76
  const webdavConfigs = await config_service_1.ConfigService.instance.readWebdavConfig();
77
77
  if (status === 'online') {
@@ -87,27 +87,27 @@ class Webdav extends core_1.Command {
87
87
  return message;
88
88
  }
89
89
  };
90
- disableWebDav = async () => {
91
- cli_utils_1.CLIUtils.doing('Stopping Internxt WebDav server...');
90
+ disableWebDav = async (jsonFlag) => {
91
+ cli_utils_1.CLIUtils.doing('Stopping Internxt WebDav server...', jsonFlag);
92
92
  await pm2_utils_1.PM2Utils.killWebDavServer();
93
- cli_utils_1.CLIUtils.done();
93
+ cli_utils_1.CLIUtils.done(jsonFlag);
94
94
  const message = 'Internxt WebDav server stopped successfully';
95
95
  cli_utils_1.CLIUtils.success(this.log.bind(this), message);
96
96
  return message;
97
97
  };
98
- restartWebDav = async () => {
99
- cli_utils_1.CLIUtils.doing('Restarting Internxt WebDav server...');
98
+ restartWebDav = async (jsonFlag) => {
99
+ cli_utils_1.CLIUtils.doing('Restarting Internxt WebDav server...', jsonFlag);
100
100
  const { status } = await pm2_utils_1.PM2Utils.webdavServerStatus();
101
101
  if (status === 'online') {
102
102
  await pm2_utils_1.PM2Utils.killWebDavServer();
103
103
  await pm2_utils_1.PM2Utils.startWebDavServer();
104
- cli_utils_1.CLIUtils.done();
104
+ cli_utils_1.CLIUtils.done(jsonFlag);
105
105
  const message = 'Internxt WebDav server restarted successfully';
106
106
  cli_utils_1.CLIUtils.success(this.log.bind(this), message);
107
107
  return message;
108
108
  }
109
109
  else {
110
- cli_utils_1.CLIUtils.done();
110
+ cli_utils_1.CLIUtils.done(jsonFlag);
111
111
  const message = 'Internxt WebDav server is not running, it wont be restarted';
112
112
  cli_utils_1.CLIUtils.warning(this.log.bind(this), message);
113
113
  return message;
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const core_1 = require("@oclif/core");
4
4
  const cli_utils_1 = require("../utils/cli.utils");
5
- const errors_utils_1 = require("../utils/errors.utils");
6
5
  const config_service_1 = require("../services/config.service");
7
6
  const validation_service_1 = require("../services/validation.service");
8
7
  class Whoami extends core_1.Command {
@@ -35,8 +34,14 @@ class Whoami extends core_1.Command {
35
34
  }
36
35
  };
37
36
  catch = async (error) => {
38
- errors_utils_1.ErrorUtils.report(this.error.bind(this), error, { command: this.id });
39
- cli_utils_1.CLIUtils.error(this.log.bind(this), error.message);
37
+ const { flags } = await this.parse(Whoami);
38
+ cli_utils_1.CLIUtils.catchError({
39
+ error,
40
+ command: this.id,
41
+ logReporter: this.log.bind(this),
42
+ errorReporter: this.error.bind(this),
43
+ jsonFlag: flags['json'],
44
+ });
40
45
  this.exit(1);
41
46
  };
42
47
  checkUserAndTokens = (loginCreds) => {
@@ -14,22 +14,28 @@ const webdav_1 = __importDefault(require("../../commands/webdav"));
14
14
  const webdav_config_1 = __importDefault(require("../../commands/webdav-config"));
15
15
  const CommandsToSkip = [whoami_1.default, login_1.default, logout_1.default, logs_1.default, webdav_1.default, webdav_config_1.default];
16
16
  const hook = async function (opts) {
17
- if (!CommandsToSkip.map((command) => command.name).includes(opts.Command.name)) {
18
- cli_utils_1.CLIUtils.doing('Checking credentials');
17
+ const { Command, argv } = opts;
18
+ const jsonFlag = argv.includes('--json');
19
+ if (!CommandsToSkip.map((command) => command.name).includes(Command.name)) {
20
+ cli_utils_1.CLIUtils.doing('Checking credentials', jsonFlag);
19
21
  try {
20
22
  const { token, newToken } = await auth_service_1.AuthService.instance.getAuthDetails();
21
23
  sdk_manager_service_1.SdkManager.init({
22
24
  token,
23
25
  newToken,
24
26
  });
25
- cli_utils_1.CLIUtils.done();
26
- cli_utils_1.CLIUtils.clearPreviousLine();
27
+ cli_utils_1.CLIUtils.done(jsonFlag);
28
+ cli_utils_1.CLIUtils.clearPreviousLine(jsonFlag);
27
29
  }
28
30
  catch (error) {
29
31
  const err = error;
30
- cli_utils_1.CLIUtils.done();
31
- cli_utils_1.CLIUtils.clearPreviousLine();
32
- cli_utils_1.CLIUtils.error(this.log.bind(this), err.message);
32
+ cli_utils_1.CLIUtils.catchError({
33
+ error: err,
34
+ command: Command.id,
35
+ logReporter: this.log.bind(this),
36
+ errorReporter: this.error.bind(this),
37
+ jsonFlag,
38
+ });
33
39
  opts.context.exit(1);
34
40
  }
35
41
  }
@@ -2,14 +2,16 @@ import cliProgress from 'cli-progress';
2
2
  import { Header } from 'tty-table';
3
3
  import { PromptOptions } from '../types/command.types';
4
4
  export declare class CLIUtils {
5
- static readonly clearPreviousLine: () => void;
5
+ static readonly clearPreviousLine: (jsonFlag?: boolean) => void;
6
6
  static readonly warning: (reporter: (message: string) => void, message: string) => void;
7
7
  static readonly error: (reporter: (message: string) => void, message: string) => void;
8
- static readonly doing: (message: string) => void;
9
8
  static readonly success: (reporter: (message: string) => void, message: string) => void;
10
9
  static readonly log: (reporter: (message: string) => void, message: string) => void;
11
- static readonly done: () => void;
12
- static readonly progress: (opts: cliProgress.Options) => cliProgress.SingleBar;
10
+ static readonly consoleLog: (message: string) => void;
11
+ static readonly doing: (message: string, jsonFlag?: boolean) => void;
12
+ static readonly done: (jsonFlag?: boolean) => void;
13
+ static readonly failed: (jsonFlag?: boolean) => void;
14
+ static readonly progress: (opts: cliProgress.Options, jsonFlag?: boolean) => cliProgress.SingleBar | undefined;
13
15
  static readonly table: (reporter: (message: string) => void, header: Header[], rows: object[]) => void;
14
16
  static readonly generateTableHeaderFromType: <T extends object>() => Header[];
15
17
  static readonly CommonFlags: {
@@ -34,6 +36,13 @@ export declare class CLIUtils {
34
36
  static readonly timer: () => {
35
37
  stop: () => number;
36
38
  };
39
+ static readonly catchError: ({ error, logReporter, errorReporter, command, jsonFlag, }: {
40
+ error: Error;
41
+ command?: string;
42
+ logReporter: (message: string) => void;
43
+ errorReporter: (message: string) => void;
44
+ jsonFlag?: boolean;
45
+ }) => void;
37
46
  static readonly parseEmpty: (input: string) => Promise<string>;
38
47
  }
39
48
  export declare class NoFlagProvidedError extends Error {
@@ -8,10 +8,13 @@ const core_1 = require("@oclif/core");
8
8
  const cli_progress_1 = __importDefault(require("cli-progress"));
9
9
  const tty_table_1 = __importDefault(require("tty-table"));
10
10
  const inquirer_utils_1 = require("./inquirer.utils");
11
+ const errors_utils_1 = require("./errors.utils");
11
12
  class CLIUtils {
12
- static clearPreviousLine = () => {
13
- process.stdout.write('\x1b[1A');
14
- process.stdout.clearLine(0);
13
+ static clearPreviousLine = (jsonFlag) => {
14
+ if (!jsonFlag) {
15
+ process.stdout?.write?.('\x1b[1A');
16
+ process.stdout?.clearLine?.(0);
17
+ }
15
18
  };
16
19
  static warning = (reporter, message) => {
17
20
  reporter(core_1.ux.colorize('#a67805', `⚠ Warning: ${message}`));
@@ -19,20 +22,34 @@ class CLIUtils {
19
22
  static error = (reporter, message) => {
20
23
  reporter(core_1.ux.colorize('red', `⚠ Error: ${message}`));
21
24
  };
22
- static doing = (message) => {
23
- core_1.ux.action.start(message, undefined, {});
24
- };
25
25
  static success = (reporter, message) => {
26
26
  reporter(core_1.ux.colorize('green', `✓ ${message}`));
27
27
  };
28
28
  static log = (reporter, message) => {
29
29
  reporter(`${message}`);
30
30
  };
31
- static done = () => {
32
- core_1.ux.action.stop(core_1.ux.colorize('green', 'done ✓'));
31
+ static consoleLog = (message) => {
32
+ console.log(message);
33
+ };
34
+ static doing = (message, jsonFlag) => {
35
+ if (!jsonFlag) {
36
+ core_1.ux.action.start(message, undefined, {});
37
+ }
38
+ };
39
+ static done = (jsonFlag) => {
40
+ if (!jsonFlag && core_1.ux.action.running) {
41
+ core_1.ux.action.stop(core_1.ux.colorize('green', 'done ✓'));
42
+ }
43
+ };
44
+ static failed = (jsonFlag) => {
45
+ if (!jsonFlag && core_1.ux.action.running) {
46
+ core_1.ux.action.stop(core_1.ux.colorize('red', 'failed ✕'));
47
+ }
33
48
  };
34
- static progress = (opts) => {
35
- return new cli_progress_1.default.SingleBar({ noTTYOutput: Boolean(!process.stdin.isTTY), ...opts }, cli_progress_1.default.Presets.shades_classic);
49
+ static progress = (opts, jsonFlag) => {
50
+ if (!jsonFlag) {
51
+ return new cli_progress_1.default.SingleBar({ noTTYOutput: Boolean(!process.stdin.isTTY), ...opts }, cli_progress_1.default.Presets.shades_classic);
52
+ }
36
53
  };
37
54
  static table = (reporter, header, rows) => {
38
55
  const table = (0, tty_table_1.default)(header, rows);
@@ -113,6 +130,23 @@ class CLIUtils {
113
130
  },
114
131
  };
115
132
  };
133
+ static catchError = ({ error, logReporter, errorReporter, command, jsonFlag, }) => {
134
+ let message;
135
+ if ('message' in error && error.message.trim().length > 0) {
136
+ message = error.message;
137
+ }
138
+ else {
139
+ message = JSON.stringify(error);
140
+ }
141
+ CLIUtils.failed(jsonFlag);
142
+ if (jsonFlag) {
143
+ CLIUtils.consoleLog(JSON.stringify({ success: false, message }));
144
+ }
145
+ else {
146
+ errors_utils_1.ErrorUtils.report(errorReporter, error, { command });
147
+ CLIUtils.error(logReporter, message);
148
+ }
149
+ };
116
150
  static parseEmpty = async (input) => (input.trim().length === 0 ? ' ' : input);
117
151
  }
118
152
  exports.CLIUtils = CLIUtils;
@@ -3,7 +3,7 @@ export declare class XMLUtils {
3
3
  static readonly DEFAULT_NAMESPACE_LETTER = "D";
4
4
  static toJSON(xml: string, options?: X2jOptions): any;
5
5
  static toXML(object: object, options?: XmlBuilderOptions): string;
6
- static toWebDavXML(object: object, options: XmlBuilderOptions): string;
6
+ static toWebDavXML(object: object, options: XmlBuilderOptions, rootObject?: string): string;
7
7
  static addDefaultNamespace(key: string): string;
8
8
  static encodeWebDavUri(uri: string): string;
9
9
  }
@@ -12,12 +12,12 @@ class XMLUtils {
12
12
  const builder = new fast_xml_parser_1.XMLBuilder(options);
13
13
  return builder.build(object);
14
14
  }
15
- static toWebDavXML(object, options) {
15
+ static toWebDavXML(object, options, rootObject = 'multistatus') {
16
16
  const xmlContent = this.toXML(object, options);
17
17
  return ('<?xml version="1.0" encoding="utf-8" ?>' +
18
- `<${XMLUtils.addDefaultNamespace('multistatus')} xmlns:${XMLUtils.DEFAULT_NAMESPACE_LETTER}="DAV:">` +
18
+ `<${XMLUtils.addDefaultNamespace(rootObject)} xmlns:${XMLUtils.DEFAULT_NAMESPACE_LETTER}="DAV:">` +
19
19
  `${xmlContent}` +
20
- `</${XMLUtils.addDefaultNamespace('multistatus')}>`);
20
+ `</${XMLUtils.addDefaultNamespace(rootObject)}>`);
21
21
  }
22
22
  static addDefaultNamespace(key) {
23
23
  return `${XMLUtils.DEFAULT_NAMESPACE_LETTER}:${key}`;
@@ -41,7 +41,18 @@ class PROPFINDRequestHandler {
41
41
  }
42
42
  }
43
43
  catch {
44
- res.status(207).send();
44
+ res.status(207).send(xml_utils_1.XMLUtils.toWebDavXML({
45
+ [xml_utils_1.XMLUtils.addDefaultNamespace('response')]: {
46
+ [xml_utils_1.XMLUtils.addDefaultNamespace('href')]: xml_utils_1.XMLUtils.encodeWebDavUri(resource.url),
47
+ [xml_utils_1.XMLUtils.addDefaultNamespace('propstat')]: {
48
+ [xml_utils_1.XMLUtils.addDefaultNamespace('status')]: 'HTTP/1.1 404 Not Found',
49
+ [xml_utils_1.XMLUtils.addDefaultNamespace('prop')]: {},
50
+ },
51
+ },
52
+ }, {
53
+ ignoreAttributes: false,
54
+ suppressEmptyNode: true,
55
+ }));
45
56
  }
46
57
  };
47
58
  getFileMetaXML = async (resource, driveFileItem) => {