@internxt/cli 1.3.2 → 1.4.1

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 (112) hide show
  1. package/.env +13 -0
  2. package/README.md +590 -176
  3. package/dist/commands/add-cert.d.ts +10 -3
  4. package/dist/commands/add-cert.js +24 -38
  5. package/dist/commands/config.d.ts +15 -12
  6. package/dist/commands/config.js +24 -28
  7. package/dist/commands/create-folder.d.ts +16 -8
  8. package/dist/commands/create-folder.js +67 -24
  9. package/dist/commands/delete-permanently-file.d.ts +18 -0
  10. package/dist/commands/delete-permanently-file.js +63 -0
  11. package/dist/commands/delete-permanently-folder.d.ts +18 -0
  12. package/dist/commands/delete-permanently-folder.js +63 -0
  13. package/dist/commands/download-file.d.ts +26 -0
  14. package/dist/commands/{download.js → download-file.js} +98 -56
  15. package/dist/commands/list.d.ts +12 -12
  16. package/dist/commands/list.js +45 -73
  17. package/dist/commands/login.d.ts +11 -9
  18. package/dist/commands/login.js +46 -49
  19. package/dist/commands/logout.d.ts +7 -2
  20. package/dist/commands/logout.js +14 -8
  21. package/dist/commands/logs.d.ts +11 -2
  22. package/dist/commands/logs.js +16 -3
  23. package/dist/commands/move-file.d.ts +9 -7
  24. package/dist/commands/move-file.js +38 -37
  25. package/dist/commands/move-folder.d.ts +9 -7
  26. package/dist/commands/move-folder.js +38 -37
  27. package/dist/commands/rename-file.d.ts +24 -0
  28. package/dist/commands/rename-file.js +80 -0
  29. package/dist/commands/rename-folder.d.ts +24 -0
  30. package/dist/commands/rename-folder.js +80 -0
  31. package/dist/commands/trash-clear.d.ts +9 -5
  32. package/dist/commands/trash-clear.js +21 -19
  33. package/dist/commands/trash-file.d.ts +21 -0
  34. package/dist/commands/trash-file.js +58 -0
  35. package/dist/commands/trash-folder.d.ts +21 -0
  36. package/dist/commands/trash-folder.js +58 -0
  37. package/dist/commands/trash-list.d.ts +10 -11
  38. package/dist/commands/trash-list.js +33 -62
  39. package/dist/commands/trash-restore-file.d.ts +10 -8
  40. package/dist/commands/trash-restore-file.js +33 -35
  41. package/dist/commands/trash-restore-folder.d.ts +10 -8
  42. package/dist/commands/trash-restore-folder.js +33 -35
  43. package/dist/commands/upload-file.d.ts +21 -0
  44. package/dist/commands/upload-file.js +140 -0
  45. package/dist/commands/webdav-config.d.ts +11 -9
  46. package/dist/commands/webdav-config.js +40 -66
  47. package/dist/commands/webdav.d.ts +16 -9
  48. package/dist/commands/webdav.js +77 -61
  49. package/dist/commands/whoami.d.ts +14 -2
  50. package/dist/commands/whoami.js +40 -11
  51. package/dist/hooks/prerun/auth_check.js +6 -4
  52. package/dist/services/auth.service.d.ts +2 -8
  53. package/dist/services/auth.service.js +33 -24
  54. package/dist/services/config.service.d.ts +3 -3
  55. package/dist/services/config.service.js +8 -8
  56. package/dist/services/crypto.service.d.ts +1 -3
  57. package/dist/services/crypto.service.js +11 -36
  58. package/dist/services/database/drive-file/drive-file.repository.d.ts +3 -3
  59. package/dist/services/database/drive-folder/drive-folder.repository.d.ts +3 -3
  60. package/dist/services/drive/drive-file.service.d.ts +1 -8
  61. package/dist/services/drive/drive-file.service.js +9 -23
  62. package/dist/services/drive/drive-folder.service.d.ts +1 -4
  63. package/dist/services/drive/drive-folder.service.js +2 -5
  64. package/dist/services/drive/trash.service.d.ts +2 -0
  65. package/dist/services/drive/trash.service.js +8 -0
  66. package/dist/services/keys.service.js +17 -7
  67. package/dist/services/network/network-facade.service.d.ts +1 -3
  68. package/dist/services/network/network-facade.service.js +20 -13
  69. package/dist/services/network/upload.service.d.ts +0 -1
  70. package/dist/services/sdk-manager.service.d.ts +2 -3
  71. package/dist/services/sdk-manager.service.js +14 -12
  72. package/dist/services/validation.service.d.ts +10 -0
  73. package/dist/services/validation.service.js +40 -1
  74. package/dist/types/command.types.d.ts +26 -17
  75. package/dist/types/command.types.js +38 -24
  76. package/dist/types/network.types.d.ts +0 -1
  77. package/dist/types/webdav.types.d.ts +1 -2
  78. package/dist/utils/cli.utils.d.ts +28 -19
  79. package/dist/utils/cli.utils.js +64 -44
  80. package/dist/utils/errors.utils.d.ts +1 -1
  81. package/dist/utils/errors.utils.js +3 -3
  82. package/dist/utils/hash.utils.d.ts +4 -7
  83. package/dist/utils/hash.utils.js +6 -6
  84. package/dist/utils/inquirer.utils.d.ts +4 -0
  85. package/dist/utils/inquirer.utils.js +24 -0
  86. package/dist/utils/network.utils.d.ts +2 -2
  87. package/dist/utils/network.utils.js +10 -8
  88. package/dist/utils/pm2.utils.d.ts +5 -1
  89. package/dist/utils/pm2.utils.js +35 -3
  90. package/dist/utils/stream.utils.d.ts +1 -4
  91. package/dist/utils/webdav.utils.js +4 -4
  92. package/dist/utils/xml.utils.js +4 -1
  93. package/dist/webdav/handlers/GET.handler.js +8 -3
  94. package/dist/webdav/handlers/MKCOL.handler.js +2 -6
  95. package/dist/webdav/handlers/MOVE.handler.js +0 -3
  96. package/dist/webdav/handlers/PROPFIND.handler.js +2 -2
  97. package/dist/webdav/handlers/PUT.handler.js +14 -9
  98. package/dist/webdav/middewares/errors.middleware.js +1 -1
  99. package/dist/webdav/middewares/request-logger.middleware.d.ts +1 -2
  100. package/dist/webdav/middewares/request-logger.middleware.js +6 -5
  101. package/dist/webdav/webdav-server.js +2 -3
  102. package/oclif.manifest.json +517 -350
  103. package/package.json +42 -47
  104. package/dist/commands/download.d.ts +0 -19
  105. package/dist/commands/rename.d.ts +0 -18
  106. package/dist/commands/rename.js +0 -109
  107. package/dist/commands/trash.d.ts +0 -15
  108. package/dist/commands/trash.js +0 -85
  109. package/dist/commands/upload.d.ts +0 -15
  110. package/dist/commands/upload.js +0 -93
  111. package/dist/services/analytics.service.d.ts +0 -22
  112. package/dist/services/analytics.service.js +0 -20
@@ -9,11 +9,13 @@ export default class MoveFile extends Command {
9
9
  destination: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
10
10
  'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
11
11
  };
12
- run(): Promise<void>;
13
- catch(error: Error): Promise<void>;
14
- getFileUuid: (fileUuidFlag: string | undefined, nonInteractive: boolean) => Promise<string>;
15
- getDestinationFolderUuid: (destinationFolderUuidFlag: string | undefined, nonInteractive: boolean) => Promise<string>;
16
- private static readonly MAX_ATTEMPTS;
17
- getFileUuidInteractively: () => Promise<string>;
18
- getDestinationFolderUuidInteractively: () => Promise<string>;
12
+ static readonly enableJsonFlag = true;
13
+ run: () => Promise<{
14
+ success: boolean;
15
+ message: string;
16
+ file: import("@internxt/sdk/dist/drive/storage/types").FileMeta;
17
+ }>;
18
+ catch: (error: Error) => Promise<never>;
19
+ private getFileUuid;
20
+ private getDestinationFolderUuid;
19
21
  }
@@ -16,69 +16,70 @@ class MoveFile extends core_1.Command {
16
16
  ...cli_utils_1.CLIUtils.CommonFlags,
17
17
  id: core_1.Flags.string({
18
18
  char: 'i',
19
- description: 'The file id to be moved.',
19
+ description: 'The ID of the file to be moved.',
20
20
  required: false,
21
21
  }),
22
22
  destination: core_1.Flags.string({
23
23
  char: 'd',
24
- description: 'The destination folder id where the file is going to be moved.',
24
+ description: 'The destination folder id where the file is going to be moved. Leave empty for the root folder.',
25
25
  required: false,
26
+ parse: cli_utils_1.CLIUtils.parseEmpty,
26
27
  }),
27
28
  };
28
- async run() {
29
+ static enableJsonFlag = true;
30
+ run = async () => {
29
31
  const { flags } = await this.parse(MoveFile);
30
32
  const nonInteractive = flags['non-interactive'];
31
33
  const userCredentials = await config_service_1.ConfigService.instance.readUser();
32
34
  if (!userCredentials)
33
35
  throw new command_types_1.MissingCredentialsError();
34
36
  const fileUuid = await this.getFileUuid(flags['id'], nonInteractive);
35
- const destinationFolderUuid = await this.getDestinationFolderUuid(flags['destination'], nonInteractive);
36
- await drive_file_service_1.DriveFileService.instance.moveFile({ fileUuid, destinationFolderUuid });
37
- cli_utils_1.CLIUtils.success(`File moved successfully to: ${destinationFolderUuid}`);
38
- }
39
- async catch(error) {
40
- errors_utils_1.ErrorUtils.report(error, { command: this.id });
41
- cli_utils_1.CLIUtils.error(error.message);
37
+ let destinationFolderUuid = await this.getDestinationFolderUuid(flags['destination'], nonInteractive);
38
+ if (destinationFolderUuid.trim().length === 0) {
39
+ destinationFolderUuid = userCredentials.user.rootFolderId;
40
+ }
41
+ const newFile = await drive_file_service_1.DriveFileService.instance.moveFile({ fileUuid, destinationFolderUuid });
42
+ const message = `File moved successfully to: ${destinationFolderUuid}`;
43
+ cli_utils_1.CLIUtils.success(this.log.bind(this), message);
44
+ return { success: true, message, file: newFile };
45
+ };
46
+ 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);
42
49
  this.exit(1);
43
- }
50
+ };
44
51
  getFileUuid = async (fileUuidFlag, nonInteractive) => {
45
- let fileUuid = cli_utils_1.CLIUtils.getValueFromFlag({
52
+ const fileUuid = await cli_utils_1.CLIUtils.getValueFromFlag({
46
53
  value: fileUuidFlag,
47
54
  name: MoveFile.flags['id'].name,
55
+ }, {
56
+ nonInteractive,
57
+ prompt: {
58
+ message: 'What is the file id you want to move?',
59
+ options: { type: 'input' },
60
+ },
61
+ }, {
62
+ validate: validation_service_1.ValidationService.instance.validateUUIDv4,
48
63
  error: new command_types_1.NotValidFileUuidError(),
49
- canBeEmpty: true,
50
- }, nonInteractive, (fileUuid) => validation_service_1.ValidationService.instance.validateUUIDv4(fileUuid));
51
- if (!fileUuid) {
52
- fileUuid = (await this.getFileUuidInteractively()).trim();
53
- }
64
+ }, this.log.bind(this));
54
65
  return fileUuid;
55
66
  };
56
67
  getDestinationFolderUuid = async (destinationFolderUuidFlag, nonInteractive) => {
57
- let destinationFolderUuid = cli_utils_1.CLIUtils.getValueFromFlag({
68
+ const destinationFolderUuid = await cli_utils_1.CLIUtils.getValueFromFlag({
58
69
  value: destinationFolderUuidFlag,
59
70
  name: MoveFile.flags['destination'].name,
71
+ }, {
72
+ nonInteractive,
73
+ prompt: {
74
+ message: 'What is the destination folder id? (leave empty for the root folder)',
75
+ options: { type: 'input' },
76
+ },
77
+ }, {
78
+ validate: validation_service_1.ValidationService.instance.validateUUIDv4,
60
79
  error: new command_types_1.NotValidFolderUuidError(),
61
80
  canBeEmpty: true,
62
- }, nonInteractive, (folderUuid) => validation_service_1.ValidationService.instance.validateUUIDv4(folderUuid));
63
- if (!destinationFolderUuid) {
64
- destinationFolderUuid = (await this.getDestinationFolderUuidInteractively()).trim();
65
- }
81
+ }, this.log.bind(this));
66
82
  return destinationFolderUuid;
67
83
  };
68
- static MAX_ATTEMPTS = 3;
69
- getFileUuidInteractively = () => {
70
- return cli_utils_1.CLIUtils.promptWithAttempts({
71
- message: 'What is the file id you want to move?',
72
- options: { required: true },
73
- error: new command_types_1.NotValidFileUuidError(),
74
- }, MoveFile.MAX_ATTEMPTS, validation_service_1.ValidationService.instance.validateUUIDv4);
75
- };
76
- getDestinationFolderUuidInteractively = () => {
77
- return cli_utils_1.CLIUtils.promptWithAttempts({
78
- message: 'What is the destination folder id?',
79
- options: { required: true },
80
- error: new command_types_1.NotValidFolderUuidError(),
81
- }, MoveFile.MAX_ATTEMPTS, validation_service_1.ValidationService.instance.validateUUIDv4);
82
- };
83
84
  }
84
85
  exports.default = MoveFile;
@@ -9,11 +9,13 @@ export default class MoveFolder extends Command {
9
9
  destination: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
10
10
  'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
11
11
  };
12
- run(): Promise<void>;
13
- catch(error: Error): Promise<void>;
14
- getFolderUuid: (folderUuidFlag: string | undefined, nonInteractive: boolean) => Promise<string>;
15
- getDestinationFolderUuid: (destinationFolderUuidFlag: string | undefined, nonInteractive: boolean) => Promise<string>;
16
- private static readonly MAX_ATTEMPTS;
17
- getFolderUuidInteractively: () => Promise<string>;
18
- getDestinationFolderUuidInteractively: () => Promise<string>;
12
+ static readonly enableJsonFlag = true;
13
+ run: () => Promise<{
14
+ success: boolean;
15
+ message: string;
16
+ folder: import("@internxt/sdk/dist/drive/storage/types").FolderMeta;
17
+ }>;
18
+ catch: (error: Error) => Promise<never>;
19
+ private getFolderUuid;
20
+ private getDestinationFolderUuid;
19
21
  }
@@ -16,69 +16,70 @@ class MoveFolder extends core_1.Command {
16
16
  ...cli_utils_1.CLIUtils.CommonFlags,
17
17
  id: core_1.Flags.string({
18
18
  char: 'i',
19
- description: 'The folder id to be moved.',
19
+ description: 'The ID of the folder to be moved.',
20
20
  required: false,
21
21
  }),
22
22
  destination: core_1.Flags.string({
23
23
  char: 'd',
24
- description: 'The destination folder id where the folder is going to be moved.',
24
+ description: 'The destination folder id where the folder is going to be moved. Leave empty for the root folder.',
25
25
  required: false,
26
+ parse: cli_utils_1.CLIUtils.parseEmpty,
26
27
  }),
27
28
  };
28
- async run() {
29
+ static enableJsonFlag = true;
30
+ run = async () => {
29
31
  const { flags } = await this.parse(MoveFolder);
30
32
  const nonInteractive = flags['non-interactive'];
31
33
  const userCredentials = await config_service_1.ConfigService.instance.readUser();
32
34
  if (!userCredentials)
33
35
  throw new command_types_1.MissingCredentialsError();
34
36
  const folderUuid = await this.getFolderUuid(flags['id'], nonInteractive);
35
- const destinationFolderUuid = await this.getDestinationFolderUuid(flags['destination'], nonInteractive);
36
- await drive_folder_service_1.DriveFolderService.instance.moveFolder({ folderUuid, destinationFolderUuid });
37
- cli_utils_1.CLIUtils.success(`Folder moved successfully to: ${destinationFolderUuid}`);
38
- }
39
- async catch(error) {
40
- errors_utils_1.ErrorUtils.report(error, { command: this.id });
41
- cli_utils_1.CLIUtils.error(error.message);
37
+ let destinationFolderUuid = await this.getDestinationFolderUuid(flags['destination'], nonInteractive);
38
+ if (destinationFolderUuid.trim().length === 0) {
39
+ destinationFolderUuid = userCredentials.user.rootFolderId;
40
+ }
41
+ const newFolder = await drive_folder_service_1.DriveFolderService.instance.moveFolder({ folderUuid, destinationFolderUuid });
42
+ const message = `Folder moved successfully to: ${destinationFolderUuid}`;
43
+ cli_utils_1.CLIUtils.success(this.log.bind(this), message);
44
+ return { success: true, message, folder: newFolder };
45
+ };
46
+ 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);
42
49
  this.exit(1);
43
- }
50
+ };
44
51
  getFolderUuid = async (folderUuidFlag, nonInteractive) => {
45
- let folderUuid = cli_utils_1.CLIUtils.getValueFromFlag({
52
+ const folderUuid = await cli_utils_1.CLIUtils.getValueFromFlag({
46
53
  value: folderUuidFlag,
47
54
  name: MoveFolder.flags['id'].name,
55
+ }, {
56
+ nonInteractive,
57
+ prompt: {
58
+ message: 'What is the folder id you want to move?',
59
+ options: { type: 'input' },
60
+ },
61
+ }, {
62
+ validate: validation_service_1.ValidationService.instance.validateUUIDv4,
48
63
  error: new command_types_1.NotValidFolderUuidError(),
49
- canBeEmpty: true,
50
- }, nonInteractive, (folderUuid) => validation_service_1.ValidationService.instance.validateUUIDv4(folderUuid));
51
- if (!folderUuid) {
52
- folderUuid = (await this.getFolderUuidInteractively()).trim();
53
- }
64
+ }, this.log.bind(this));
54
65
  return folderUuid;
55
66
  };
56
67
  getDestinationFolderUuid = async (destinationFolderUuidFlag, nonInteractive) => {
57
- let destinationFolderUuid = cli_utils_1.CLIUtils.getValueFromFlag({
68
+ const destinationFolderUuid = await cli_utils_1.CLIUtils.getValueFromFlag({
58
69
  value: destinationFolderUuidFlag,
59
70
  name: MoveFolder.flags['destination'].name,
71
+ }, {
72
+ nonInteractive,
73
+ prompt: {
74
+ message: 'What is the destination folder id? (leave empty for the root folder)',
75
+ options: { type: 'input' },
76
+ },
77
+ }, {
78
+ validate: validation_service_1.ValidationService.instance.validateUUIDv4,
60
79
  error: new command_types_1.NotValidFolderUuidError(),
61
80
  canBeEmpty: true,
62
- }, nonInteractive, (folderUuid) => validation_service_1.ValidationService.instance.validateUUIDv4(folderUuid));
63
- if (!destinationFolderUuid) {
64
- destinationFolderUuid = (await this.getDestinationFolderUuidInteractively()).trim();
65
- }
81
+ }, this.log.bind(this));
66
82
  return destinationFolderUuid;
67
83
  };
68
- static MAX_ATTEMPTS = 3;
69
- getFolderUuidInteractively = () => {
70
- return cli_utils_1.CLIUtils.promptWithAttempts({
71
- message: 'What is the folder id you want to move?',
72
- options: { required: true },
73
- error: new command_types_1.NotValidFolderUuidError(),
74
- }, MoveFolder.MAX_ATTEMPTS, validation_service_1.ValidationService.instance.validateUUIDv4);
75
- };
76
- getDestinationFolderUuidInteractively = () => {
77
- return cli_utils_1.CLIUtils.promptWithAttempts({
78
- message: 'What is the destination folder id?',
79
- options: { required: true },
80
- error: new command_types_1.NotValidFolderUuidError(),
81
- }, MoveFolder.MAX_ATTEMPTS, validation_service_1.ValidationService.instance.validateUUIDv4);
82
- };
83
84
  }
84
85
  exports.default = MoveFolder;
@@ -0,0 +1,24 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class RenameFile extends Command {
3
+ static readonly args: {};
4
+ static readonly description = "Rename a file.";
5
+ static readonly aliases: string[];
6
+ static readonly examples: string[];
7
+ static readonly flags: {
8
+ id: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
9
+ name: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
10
+ 'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
11
+ };
12
+ static readonly enableJsonFlag = true;
13
+ run: () => Promise<{
14
+ success: boolean;
15
+ message: string;
16
+ file: {
17
+ uuid: string;
18
+ plainName: string;
19
+ };
20
+ }>;
21
+ catch: (error: Error) => Promise<never>;
22
+ private getFileUuid;
23
+ private getFileName;
24
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const config_service_1 = require("../services/config.service");
5
+ const cli_utils_1 = require("../utils/cli.utils");
6
+ const command_types_1 = require("../types/command.types");
7
+ const validation_service_1 = require("../services/validation.service");
8
+ const drive_file_service_1 = require("../services/drive/drive-file.service");
9
+ const errors_utils_1 = require("../utils/errors.utils");
10
+ class RenameFile extends core_1.Command {
11
+ static args = {};
12
+ static description = 'Rename a file.';
13
+ static aliases = ['rename:file'];
14
+ static examples = ['<%= config.bin %> <%= command.id %>'];
15
+ static flags = {
16
+ ...cli_utils_1.CLIUtils.CommonFlags,
17
+ id: core_1.Flags.string({
18
+ char: 'i',
19
+ description: 'The ID of the file to be renamed.',
20
+ required: false,
21
+ }),
22
+ name: core_1.Flags.string({
23
+ char: 'n',
24
+ description: 'The new name for the file.',
25
+ required: false,
26
+ }),
27
+ };
28
+ static enableJsonFlag = true;
29
+ run = async () => {
30
+ const { flags } = await this.parse(RenameFile);
31
+ const nonInteractive = flags['non-interactive'];
32
+ const userCredentials = await config_service_1.ConfigService.instance.readUser();
33
+ if (!userCredentials)
34
+ throw new command_types_1.MissingCredentialsError();
35
+ const fileUuid = await this.getFileUuid(flags['id'], nonInteractive);
36
+ const newName = await this.getFileName(flags['name'], nonInteractive);
37
+ await drive_file_service_1.DriveFileService.instance.renameFile(fileUuid, { plainName: newName });
38
+ const message = `File renamed successfully with: ${newName}`;
39
+ cli_utils_1.CLIUtils.success(this.log.bind(this), message);
40
+ return { success: true, message, file: { uuid: fileUuid, plainName: newName } };
41
+ };
42
+ 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);
45
+ this.exit(1);
46
+ };
47
+ getFileUuid = async (fileUuidFlag, nonInteractive) => {
48
+ const fileUuid = await cli_utils_1.CLIUtils.getValueFromFlag({
49
+ value: fileUuidFlag,
50
+ name: RenameFile.flags['id'].name,
51
+ }, {
52
+ nonInteractive,
53
+ prompt: {
54
+ message: 'What is the file id you want to rename?',
55
+ options: { type: 'input' },
56
+ },
57
+ }, {
58
+ validate: validation_service_1.ValidationService.instance.validateUUIDv4,
59
+ error: new command_types_1.NotValidFileUuidError(),
60
+ }, this.log.bind(this));
61
+ return fileUuid;
62
+ };
63
+ getFileName = async (fileNameFlag, nonInteractive) => {
64
+ const fileName = await cli_utils_1.CLIUtils.getValueFromFlag({
65
+ value: fileNameFlag,
66
+ name: RenameFile.flags['name'].name,
67
+ }, {
68
+ nonInteractive,
69
+ prompt: {
70
+ message: 'What is the new name of the file?',
71
+ options: { type: 'input' },
72
+ },
73
+ }, {
74
+ validate: validation_service_1.ValidationService.instance.validateStringIsNotEmpty,
75
+ error: new command_types_1.EmptyFileNameError(),
76
+ }, this.log.bind(this));
77
+ return fileName;
78
+ };
79
+ }
80
+ exports.default = RenameFile;
@@ -0,0 +1,24 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class RenameFolder extends Command {
3
+ static readonly args: {};
4
+ static readonly description = "Rename a folder.";
5
+ static readonly aliases: string[];
6
+ static readonly examples: string[];
7
+ static readonly flags: {
8
+ id: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
9
+ name: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
10
+ 'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
11
+ };
12
+ static readonly enableJsonFlag = true;
13
+ run: () => Promise<{
14
+ success: boolean;
15
+ message: string;
16
+ folder: {
17
+ uuid: string;
18
+ plainName: string;
19
+ };
20
+ }>;
21
+ catch: (error: Error) => Promise<never>;
22
+ private getFolderUuid;
23
+ private getFolderName;
24
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const config_service_1 = require("../services/config.service");
5
+ const cli_utils_1 = require("../utils/cli.utils");
6
+ const command_types_1 = require("../types/command.types");
7
+ const validation_service_1 = require("../services/validation.service");
8
+ const drive_folder_service_1 = require("../services/drive/drive-folder.service");
9
+ const errors_utils_1 = require("../utils/errors.utils");
10
+ class RenameFolder extends core_1.Command {
11
+ static args = {};
12
+ static description = 'Rename a folder.';
13
+ static aliases = ['rename:folder'];
14
+ static examples = ['<%= config.bin %> <%= command.id %>'];
15
+ static flags = {
16
+ ...cli_utils_1.CLIUtils.CommonFlags,
17
+ id: core_1.Flags.string({
18
+ char: 'i',
19
+ description: 'The ID of the folder to be renamed.',
20
+ required: false,
21
+ }),
22
+ name: core_1.Flags.string({
23
+ char: 'n',
24
+ description: 'The new name for the folder.',
25
+ required: false,
26
+ }),
27
+ };
28
+ static enableJsonFlag = true;
29
+ run = async () => {
30
+ const { flags } = await this.parse(RenameFolder);
31
+ const nonInteractive = flags['non-interactive'];
32
+ const userCredentials = await config_service_1.ConfigService.instance.readUser();
33
+ if (!userCredentials)
34
+ throw new command_types_1.MissingCredentialsError();
35
+ const folderUuid = await this.getFolderUuid(flags['id'], nonInteractive);
36
+ const name = await this.getFolderName(flags['name'], nonInteractive);
37
+ await drive_folder_service_1.DriveFolderService.instance.renameFolder({ folderUuid, name });
38
+ const message = `Folder renamed successfully with: ${name}`;
39
+ cli_utils_1.CLIUtils.success(this.log.bind(this), message);
40
+ return { success: true, message, folder: { uuid: folderUuid, plainName: name } };
41
+ };
42
+ 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);
45
+ this.exit(1);
46
+ };
47
+ getFolderUuid = async (folderUuidFlag, nonInteractive) => {
48
+ const folderUuid = await cli_utils_1.CLIUtils.getValueFromFlag({
49
+ value: folderUuidFlag,
50
+ name: RenameFolder.flags['id'].name,
51
+ }, {
52
+ nonInteractive,
53
+ prompt: {
54
+ message: 'What is the folder id you want to rename?',
55
+ options: { type: 'input' },
56
+ },
57
+ }, {
58
+ validate: validation_service_1.ValidationService.instance.validateUUIDv4,
59
+ error: new command_types_1.NotValidFolderUuidError(),
60
+ }, this.log.bind(this));
61
+ return folderUuid;
62
+ };
63
+ getFolderName = async (folderNameFlag, nonInteractive) => {
64
+ const folderName = await cli_utils_1.CLIUtils.getValueFromFlag({
65
+ value: folderNameFlag,
66
+ name: RenameFolder.flags['name'].name,
67
+ }, {
68
+ nonInteractive,
69
+ prompt: {
70
+ message: 'What is the new name of the folder?',
71
+ options: { type: 'input' },
72
+ },
73
+ }, {
74
+ validate: validation_service_1.ValidationService.instance.validateStringIsNotEmpty,
75
+ error: new command_types_1.EmptyFolderNameError(),
76
+ }, this.log.bind(this));
77
+ return folderName;
78
+ };
79
+ }
80
+ exports.default = RenameFolder;
@@ -2,14 +2,18 @@ import { Command } from '@oclif/core';
2
2
  export default class TrashClear extends Command {
3
3
  static readonly args: {};
4
4
  static readonly description = "Deletes permanently all the content of the trash. This action cannot be undone.";
5
- static readonly examples: string[];
6
5
  static readonly aliases: string[];
6
+ static readonly examples: string[];
7
7
  static readonly flags: {
8
8
  force: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
9
9
  'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
10
10
  };
11
- run(): Promise<void>;
12
- catch(error: Error): Promise<void>;
13
- getConfirmation: () => Promise<string>;
14
- getConfirmationInteractively: () => Promise<string>;
11
+ static readonly enableJsonFlag = true;
12
+ run: () => Promise<{
13
+ success: boolean;
14
+ message: string;
15
+ }>;
16
+ catch: (error: Error) => Promise<never>;
17
+ private getConfirmation;
18
+ private getConfirmationInteractively;
15
19
  }
@@ -6,12 +6,12 @@ const cli_utils_1 = require("../utils/cli.utils");
6
6
  const command_types_1 = require("../types/command.types");
7
7
  const errors_utils_1 = require("../utils/errors.utils");
8
8
  const trash_service_1 = require("../services/drive/trash.service");
9
- const validation_service_1 = require("../services/validation.service");
9
+ const inquirer_utils_1 = require("../utils/inquirer.utils");
10
10
  class TrashClear extends core_1.Command {
11
11
  static args = {};
12
12
  static description = 'Deletes permanently all the content of the trash. This action cannot be undone.';
13
- static examples = ['<%= config.bin %> <%= command.id %>'];
14
13
  static aliases = ['trash:clear'];
14
+ static examples = ['<%= config.bin %> <%= command.id %>'];
15
15
  static flags = {
16
16
  ...cli_utils_1.CLIUtils.CommonFlags,
17
17
  force: core_1.Flags.boolean({
@@ -20,44 +20,46 @@ class TrashClear extends core_1.Command {
20
20
  required: false,
21
21
  }),
22
22
  };
23
- async run() {
23
+ static enableJsonFlag = true;
24
+ run = async () => {
24
25
  const { flags } = await this.parse(TrashClear);
25
26
  const userCredentials = await config_service_1.ConfigService.instance.readUser();
26
27
  if (!userCredentials)
27
28
  throw new command_types_1.MissingCredentialsError();
28
29
  if (!flags.force) {
29
30
  if (flags['non-interactive']) {
30
- cli_utils_1.CLIUtils.error('The "non interactive" flag is enabled, but the "force" flag has not been provided. User confirmation is required to empty the trash permanently.');
31
- return;
31
+ const message = 'The "non interactive" flag is enabled, but the "force" flag has not been provided. User confirmation is required to empty the trash permanently.';
32
+ cli_utils_1.CLIUtils.error(this.log.bind(this), message);
33
+ return { success: false, message };
32
34
  }
33
35
  const confirmation = await this.getConfirmation();
34
36
  if (confirmation !== 'y') {
35
- cli_utils_1.CLIUtils.error('User confirmation is required to empty the trash permanently.');
36
- return;
37
+ const message = 'User confirmation is required to empty the trash permanently.';
38
+ cli_utils_1.CLIUtils.error(this.log.bind(this), message);
39
+ return { success: false, message };
37
40
  }
38
41
  }
39
42
  await trash_service_1.TrashService.instance.clearTrash();
40
- cli_utils_1.CLIUtils.success('Trash emptied correctly');
41
- }
42
- async catch(error) {
43
- errors_utils_1.ErrorUtils.report(error, { command: this.id });
44
- cli_utils_1.CLIUtils.error(error.message);
43
+ const message = 'Trash emptied successfully.';
44
+ cli_utils_1.CLIUtils.success(this.log.bind(this), message);
45
+ return { success: true, message };
46
+ };
47
+ 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);
45
50
  this.exit(1);
46
- }
51
+ };
47
52
  getConfirmation = async () => {
48
53
  let confirmation = (await this.getConfirmationInteractively()).trim().toLowerCase();
49
54
  if (confirmation.length === 0) {
50
55
  confirmation = 'no';
51
56
  }
52
- if (!validation_service_1.ValidationService.instance.validateYesOrNoString(confirmation)) {
53
- throw new command_types_1.NotValidYesOrNoError();
54
- }
55
57
  return confirmation.charAt(0);
56
58
  };
57
59
  getConfirmationInteractively = () => {
58
- return cli_utils_1.CLIUtils.prompt({
59
- message: 'Empty trash? All items in the Drive Trash will be permanently deleted. This action cannot be undone. [y/N]',
60
- options: { required: false },
60
+ return inquirer_utils_1.InquirerUtils.prompt('Empty trash? All items in the Drive Trash will be permanently deleted. This action cannot be undone.', {
61
+ type: 'confirm',
62
+ confirm: { default: false },
61
63
  });
62
64
  };
63
65
  }
@@ -0,0 +1,21 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class TrashFile extends Command {
3
+ static readonly args: {};
4
+ static readonly description = "Moves a given file to the trash.";
5
+ static readonly aliases: string[];
6
+ static readonly examples: string[];
7
+ static readonly flags: {
8
+ id: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
9
+ 'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
10
+ };
11
+ static readonly enableJsonFlag = true;
12
+ run: () => Promise<{
13
+ success: boolean;
14
+ message: string;
15
+ file: {
16
+ uuid: string;
17
+ };
18
+ }>;
19
+ catch: (error: Error) => Promise<never>;
20
+ private getFileUuid;
21
+ }