@internxt/cli 1.2.2 → 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.
Files changed (92) hide show
  1. package/.env +2 -1
  2. package/README.md +404 -25
  3. package/bin/dev.js +0 -0
  4. package/bin/run.js +0 -0
  5. package/dist/commands/config.js +1 -1
  6. package/dist/commands/list.js +1 -2
  7. package/dist/commands/{move.d.ts → move-file.d.ts} +5 -4
  8. package/dist/commands/move-file.js +84 -0
  9. package/dist/commands/move-folder.d.ts +19 -0
  10. package/dist/commands/move-folder.js +84 -0
  11. package/dist/commands/rename.d.ts +18 -0
  12. package/dist/commands/{move.js → rename.js} +29 -29
  13. package/dist/commands/trash-clear.d.ts +15 -0
  14. package/dist/commands/trash-clear.js +64 -0
  15. package/dist/commands/trash-list.d.ts +20 -0
  16. package/dist/commands/trash-list.js +95 -0
  17. package/dist/commands/trash-restore-file.d.ts +19 -0
  18. package/dist/commands/trash-restore-file.js +87 -0
  19. package/dist/commands/trash-restore-folder.d.ts +19 -0
  20. package/dist/commands/trash-restore-folder.js +87 -0
  21. package/dist/commands/webdav-config.d.ts +17 -0
  22. package/dist/commands/webdav-config.js +91 -0
  23. package/dist/commands/webdav.d.ts +1 -1
  24. package/dist/commands/webdav.js +5 -2
  25. package/dist/database/migrations/20241018114828-add-parent-column.d.ts +1 -0
  26. package/dist/database/migrations/20241018114828-add-parent-column.js +24 -0
  27. package/dist/hooks/prerun/auth_check.js +2 -1
  28. package/dist/services/analytics.service.d.ts +9 -6
  29. package/dist/services/analytics.service.js +2 -35
  30. package/dist/services/config.service.d.ts +6 -1
  31. package/dist/services/config.service.js +24 -0
  32. package/dist/services/database/drive-database-manager.service.d.ts +10 -7
  33. package/dist/services/database/drive-database-manager.service.js +34 -24
  34. package/dist/services/database/drive-file/drive-file.attributes.d.ts +1 -0
  35. package/dist/services/database/drive-file/drive-file.domain.d.ts +4 -1
  36. package/dist/services/database/drive-file/drive-file.domain.js +21 -1
  37. package/dist/services/database/drive-file/drive-file.model.d.ts +1 -0
  38. package/dist/services/database/drive-file/drive-file.model.js +4 -0
  39. package/dist/services/database/drive-folder/drive-folder.attributes.d.ts +1 -0
  40. package/dist/services/database/drive-folder/drive-folder.domain.d.ts +4 -1
  41. package/dist/services/database/drive-folder/drive-folder.domain.js +18 -1
  42. package/dist/services/database/drive-folder/drive-folder.model.d.ts +1 -0
  43. package/dist/services/database/drive-folder/drive-folder.model.js +5 -0
  44. package/dist/services/drive/drive-file.service.d.ts +5 -0
  45. package/dist/services/drive/drive-file.service.js +10 -0
  46. package/dist/services/drive/drive-folder.service.d.ts +7 -2
  47. package/dist/services/drive/drive-folder.service.js +16 -0
  48. package/dist/services/drive/trash.service.d.ts +7 -0
  49. package/dist/services/drive/trash.service.js +30 -0
  50. package/dist/services/network/upload.service.js +5 -1
  51. package/dist/services/sdk-manager.service.d.ts +1 -2
  52. package/dist/services/sdk-manager.service.js +0 -5
  53. package/dist/services/usage.service.d.ts +2 -1
  54. package/dist/services/usage.service.js +3 -7
  55. package/dist/services/validation.service.d.ts +2 -0
  56. package/dist/services/validation.service.js +6 -0
  57. package/dist/types/command.types.d.ts +16 -0
  58. package/dist/types/command.types.js +29 -1
  59. package/dist/types/config.types.d.ts +0 -1
  60. package/dist/types/drive.types.d.ts +2 -1
  61. package/dist/types/network.types.d.ts +5 -0
  62. package/dist/types/webdav.types.d.ts +1 -0
  63. package/dist/utils/cli.utils.d.ts +1 -1
  64. package/dist/utils/drive.utils.js +3 -1
  65. package/dist/utils/network.utils.d.ts +3 -9
  66. package/dist/utils/network.utils.js +21 -7
  67. package/dist/utils/webdav.utils.d.ts +16 -2
  68. package/dist/utils/webdav.utils.js +70 -19
  69. package/dist/utils/xml.utils.d.ts +1 -0
  70. package/dist/utils/xml.utils.js +3 -0
  71. package/dist/webdav/handlers/DELETE.handler.d.ts +5 -1
  72. package/dist/webdav/handlers/DELETE.handler.js +15 -12
  73. package/dist/webdav/handlers/GET.handler.d.ts +1 -2
  74. package/dist/webdav/handlers/GET.handler.js +10 -13
  75. package/dist/webdav/handlers/HEAD.handler.d.ts +1 -1
  76. package/dist/webdav/handlers/HEAD.handler.js +2 -2
  77. package/dist/webdav/handlers/MKCOL.handler.d.ts +1 -1
  78. package/dist/webdav/handlers/MKCOL.handler.js +14 -15
  79. package/dist/webdav/handlers/MOVE.handler.d.ts +11 -1
  80. package/dist/webdav/handlers/MOVE.handler.js +73 -2
  81. package/dist/webdav/handlers/OPTIONS.handler.d.ts +1 -1
  82. package/dist/webdav/handlers/OPTIONS.handler.js +2 -2
  83. package/dist/webdav/handlers/PROPFIND.handler.d.ts +11 -12
  84. package/dist/webdav/handlers/PROPFIND.handler.js +62 -76
  85. package/dist/webdav/handlers/PUT.handler.d.ts +5 -8
  86. package/dist/webdav/handlers/PUT.handler.js +34 -18
  87. package/dist/webdav/middewares/request-logger.middleware.js +1 -1
  88. package/dist/webdav/webdav-server.d.ts +14 -14
  89. package/dist/webdav/webdav-server.js +31 -14
  90. package/oclif.manifest.json +441 -8
  91. package/package.json +22 -26
  92. package/scripts/add-cert.sh +19 -5
@@ -0,0 +1,84 @@
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 MoveFile extends core_1.Command {
11
+ static args = {};
12
+ static description = 'Move a file into a destination folder.';
13
+ static aliases = ['move: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 file id to be moved.',
20
+ required: false,
21
+ }),
22
+ destination: core_1.Flags.string({
23
+ char: 'd',
24
+ description: 'The destination folder id where the file is going to be moved.',
25
+ required: false,
26
+ }),
27
+ };
28
+ async run() {
29
+ const { flags } = await this.parse(MoveFile);
30
+ const nonInteractive = flags['non-interactive'];
31
+ const userCredentials = await config_service_1.ConfigService.instance.readUser();
32
+ if (!userCredentials)
33
+ throw new command_types_1.MissingCredentialsError();
34
+ 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);
42
+ this.exit(1);
43
+ }
44
+ getFileUuid = async (fileUuidFlag, nonInteractive) => {
45
+ let fileUuid = cli_utils_1.CLIUtils.getValueFromFlag({
46
+ value: fileUuidFlag,
47
+ name: MoveFile.flags['id'].name,
48
+ 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
+ }
54
+ return fileUuid;
55
+ };
56
+ getDestinationFolderUuid = async (destinationFolderUuidFlag, nonInteractive) => {
57
+ let destinationFolderUuid = cli_utils_1.CLIUtils.getValueFromFlag({
58
+ value: destinationFolderUuidFlag,
59
+ name: MoveFile.flags['destination'].name,
60
+ error: new command_types_1.NotValidFolderUuidError(),
61
+ canBeEmpty: true,
62
+ }, nonInteractive, (folderUuid) => validation_service_1.ValidationService.instance.validateUUIDv4(folderUuid));
63
+ if (!destinationFolderUuid) {
64
+ destinationFolderUuid = (await this.getDestinationFolderUuidInteractively()).trim();
65
+ }
66
+ return destinationFolderUuid;
67
+ };
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
+ exports.default = MoveFile;
@@ -0,0 +1,19 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class MoveFolder extends Command {
3
+ static readonly args: {};
4
+ static readonly description = "Move a folder into a destination 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
+ destination: 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
+ 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>;
19
+ }
@@ -0,0 +1,84 @@
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 drive_folder_service_1 = require("../services/drive/drive-folder.service");
6
+ const cli_utils_1 = require("../utils/cli.utils");
7
+ const command_types_1 = require("../types/command.types");
8
+ const validation_service_1 = require("../services/validation.service");
9
+ const errors_utils_1 = require("../utils/errors.utils");
10
+ class MoveFolder extends core_1.Command {
11
+ static args = {};
12
+ static description = 'Move a folder into a destination folder.';
13
+ static aliases = ['move: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 folder id to be moved.',
20
+ required: false,
21
+ }),
22
+ destination: core_1.Flags.string({
23
+ char: 'd',
24
+ description: 'The destination folder id where the folder is going to be moved.',
25
+ required: false,
26
+ }),
27
+ };
28
+ async run() {
29
+ const { flags } = await this.parse(MoveFolder);
30
+ const nonInteractive = flags['non-interactive'];
31
+ const userCredentials = await config_service_1.ConfigService.instance.readUser();
32
+ if (!userCredentials)
33
+ throw new command_types_1.MissingCredentialsError();
34
+ 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);
42
+ this.exit(1);
43
+ }
44
+ getFolderUuid = async (folderUuidFlag, nonInteractive) => {
45
+ let folderUuid = cli_utils_1.CLIUtils.getValueFromFlag({
46
+ value: folderUuidFlag,
47
+ name: MoveFolder.flags['id'].name,
48
+ 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
+ }
54
+ return folderUuid;
55
+ };
56
+ getDestinationFolderUuid = async (destinationFolderUuidFlag, nonInteractive) => {
57
+ let destinationFolderUuid = cli_utils_1.CLIUtils.getValueFromFlag({
58
+ value: destinationFolderUuidFlag,
59
+ name: MoveFolder.flags['destination'].name,
60
+ error: new command_types_1.NotValidFolderUuidError(),
61
+ canBeEmpty: true,
62
+ }, nonInteractive, (folderUuid) => validation_service_1.ValidationService.instance.validateUUIDv4(folderUuid));
63
+ if (!destinationFolderUuid) {
64
+ destinationFolderUuid = (await this.getDestinationFolderUuidInteractively()).trim();
65
+ }
66
+ return destinationFolderUuid;
67
+ };
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
+ exports.default = MoveFolder;
@@ -0,0 +1,18 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class Rename extends Command {
3
+ static readonly args: {};
4
+ static readonly description = "Rename a folder/file.";
5
+ static readonly examples: string[];
6
+ static readonly flags: {
7
+ id: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
8
+ name: 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
+ run(): Promise<void>;
12
+ catch(error: Error): Promise<void>;
13
+ getItemUuid: (itemUuidFlag: string | undefined, nonInteractive: boolean) => Promise<string>;
14
+ getNewName: (newNameUuidFlag: string | undefined, nonInteractive: boolean) => Promise<string>;
15
+ private static readonly MAX_ATTEMPTS;
16
+ getItemUuidInteractively: () => Promise<string>;
17
+ getNewNameInteractively: () => Promise<string>;
18
+ }
@@ -8,31 +8,31 @@ const command_types_1 = require("../types/command.types");
8
8
  const validation_service_1 = require("../services/validation.service");
9
9
  const drive_file_service_1 = require("../services/drive/drive-file.service");
10
10
  const errors_utils_1 = require("../utils/errors.utils");
11
- class Move extends core_1.Command {
11
+ class Rename extends core_1.Command {
12
12
  static args = {};
13
- static description = 'Move a folder/file into a destination folder.';
13
+ static description = 'Rename a folder/file.';
14
14
  static examples = ['<%= config.bin %> <%= command.id %>'];
15
15
  static flags = {
16
16
  ...cli_utils_1.CLIUtils.CommonFlags,
17
17
  id: core_1.Flags.string({
18
18
  char: 'i',
19
- description: 'The item id to be moved (it can be a file id or a folder id).',
19
+ description: 'The ID of the item to rename (can be a file ID or a folder ID).',
20
20
  required: false,
21
21
  }),
22
- destination: core_1.Flags.string({
23
- char: 'd',
24
- description: 'The destination folder id where the item is going to be moved.',
22
+ name: core_1.Flags.string({
23
+ char: 'n',
24
+ description: 'The new name for the item.',
25
25
  required: false,
26
26
  }),
27
27
  };
28
28
  async run() {
29
- const { flags } = await this.parse(Move);
29
+ const { flags } = await this.parse(Rename);
30
30
  const nonInteractive = flags['non-interactive'];
31
31
  const userCredentials = await config_service_1.ConfigService.instance.readUser();
32
32
  if (!userCredentials)
33
33
  throw new command_types_1.MissingCredentialsError();
34
34
  const itemUuid = await this.getItemUuid(flags['id'], nonInteractive);
35
- const destinationFolderUuid = await this.getDestinationFolderUuid(flags['destination'], nonInteractive);
35
+ const newName = await this.getNewName(flags['name'], nonInteractive);
36
36
  let item;
37
37
  let isFolder = false;
38
38
  try {
@@ -54,12 +54,12 @@ class Move extends core_1.Command {
54
54
  if (!item)
55
55
  throw new command_types_1.ItemNotFoundError();
56
56
  if (isFolder) {
57
- await drive_folder_service_1.DriveFolderService.instance.moveFolder({ folderUuid: item.uuid, destinationFolderUuid });
57
+ await drive_folder_service_1.DriveFolderService.instance.renameFolder({ folderUuid: item.uuid, name: newName });
58
58
  }
59
59
  else {
60
- await drive_file_service_1.DriveFileService.instance.moveFile({ fileUuid: item.uuid, destinationFolderUuid });
60
+ await drive_file_service_1.DriveFileService.instance.renameFile(item.uuid, { plainName: newName });
61
61
  }
62
- cli_utils_1.CLIUtils.success(`${isFolder ? 'Folder' : 'File'} moved successfully to: ${destinationFolderUuid}`);
62
+ cli_utils_1.CLIUtils.success(`${isFolder ? 'Folder' : 'File'} renamed successfully with: ${newName}`);
63
63
  }
64
64
  async catch(error) {
65
65
  errors_utils_1.ErrorUtils.report(error, { command: this.id });
@@ -69,7 +69,7 @@ class Move extends core_1.Command {
69
69
  getItemUuid = async (itemUuidFlag, nonInteractive) => {
70
70
  let itemUuid = cli_utils_1.CLIUtils.getValueFromFlag({
71
71
  value: itemUuidFlag,
72
- name: Move.flags['id'].name,
72
+ name: Rename.flags['id'].name,
73
73
  error: new command_types_1.NotValidItemUuidError(),
74
74
  canBeEmpty: true,
75
75
  }, nonInteractive, (itemUuid) => validation_service_1.ValidationService.instance.validateUUIDv4(itemUuid));
@@ -78,32 +78,32 @@ class Move extends core_1.Command {
78
78
  }
79
79
  return itemUuid;
80
80
  };
81
- getDestinationFolderUuid = async (destinationFolderUuidFlag, nonInteractive) => {
82
- let destinationFolderUuid = cli_utils_1.CLIUtils.getValueFromFlag({
83
- value: destinationFolderUuidFlag,
84
- name: Move.flags['destination'].name,
85
- error: new command_types_1.NotValidFolderUuidError(),
81
+ getNewName = async (newNameUuidFlag, nonInteractive) => {
82
+ let newName = cli_utils_1.CLIUtils.getValueFromFlag({
83
+ value: newNameUuidFlag,
84
+ name: Rename.flags['name'].name,
85
+ error: new command_types_1.EmptyItemNameError(),
86
86
  canBeEmpty: true,
87
- }, nonInteractive, (folderUuid) => validation_service_1.ValidationService.instance.validateUUIDv4(folderUuid));
88
- if (!destinationFolderUuid) {
89
- destinationFolderUuid = (await this.getDestinationFolderUuidInteractively()).trim();
87
+ }, nonInteractive, (password) => password.trim().length > 0);
88
+ if (!newName) {
89
+ newName = (await this.getNewNameInteractively()).trim();
90
90
  }
91
- return destinationFolderUuid;
91
+ return newName;
92
92
  };
93
93
  static MAX_ATTEMPTS = 3;
94
94
  getItemUuidInteractively = () => {
95
95
  return cli_utils_1.CLIUtils.promptWithAttempts({
96
- message: 'What is the item id you want to move?',
96
+ message: 'What is the item id you want to rename?',
97
97
  options: { required: true },
98
98
  error: new command_types_1.NotValidItemUuidError(),
99
- }, Move.MAX_ATTEMPTS, validation_service_1.ValidationService.instance.validateUUIDv4);
99
+ }, Rename.MAX_ATTEMPTS, validation_service_1.ValidationService.instance.validateUUIDv4);
100
100
  };
101
- getDestinationFolderUuidInteractively = () => {
101
+ getNewNameInteractively = () => {
102
102
  return cli_utils_1.CLIUtils.promptWithAttempts({
103
- message: 'What is the destination folder id?',
104
- options: { required: true },
105
- error: new command_types_1.NotValidFolderUuidError(),
106
- }, Move.MAX_ATTEMPTS, validation_service_1.ValidationService.instance.validateUUIDv4);
103
+ message: 'What is the new name of the item?',
104
+ options: { required: false },
105
+ error: new command_types_1.EmptyItemNameError(),
106
+ }, Rename.MAX_ATTEMPTS, (newName) => newName.trim().length > 0);
107
107
  };
108
108
  }
109
- exports.default = Move;
109
+ exports.default = Rename;
@@ -0,0 +1,15 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class TrashClear extends Command {
3
+ static readonly args: {};
4
+ static readonly description = "Deletes permanently all the content of the trash. This action cannot be undone.";
5
+ static readonly examples: string[];
6
+ static readonly aliases: string[];
7
+ static readonly flags: {
8
+ force: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
9
+ 'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
10
+ };
11
+ run(): Promise<void>;
12
+ catch(error: Error): Promise<void>;
13
+ getConfirmation: () => Promise<string>;
14
+ getConfirmationInteractively: () => Promise<string>;
15
+ }
@@ -0,0 +1,64 @@
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 errors_utils_1 = require("../utils/errors.utils");
8
+ const trash_service_1 = require("../services/drive/trash.service");
9
+ const validation_service_1 = require("../services/validation.service");
10
+ class TrashClear extends core_1.Command {
11
+ static args = {};
12
+ static description = 'Deletes permanently all the content of the trash. This action cannot be undone.';
13
+ static examples = ['<%= config.bin %> <%= command.id %>'];
14
+ static aliases = ['trash:clear'];
15
+ static flags = {
16
+ ...cli_utils_1.CLIUtils.CommonFlags,
17
+ force: core_1.Flags.boolean({
18
+ char: 'f',
19
+ description: 'It forces the trash to be emptied without confirmation.',
20
+ required: false,
21
+ }),
22
+ };
23
+ async run() {
24
+ const { flags } = await this.parse(TrashClear);
25
+ const userCredentials = await config_service_1.ConfigService.instance.readUser();
26
+ if (!userCredentials)
27
+ throw new command_types_1.MissingCredentialsError();
28
+ if (!flags.force) {
29
+ 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;
32
+ }
33
+ const confirmation = await this.getConfirmation();
34
+ if (confirmation !== 'y') {
35
+ cli_utils_1.CLIUtils.error('User confirmation is required to empty the trash permanently.');
36
+ return;
37
+ }
38
+ }
39
+ 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);
45
+ this.exit(1);
46
+ }
47
+ getConfirmation = async () => {
48
+ let confirmation = (await this.getConfirmationInteractively()).trim().toLowerCase();
49
+ if (confirmation.length === 0) {
50
+ confirmation = 'no';
51
+ }
52
+ if (!validation_service_1.ValidationService.instance.validateYesOrNoString(confirmation)) {
53
+ throw new command_types_1.NotValidYesOrNoError();
54
+ }
55
+ return confirmation.charAt(0);
56
+ };
57
+ 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 },
61
+ });
62
+ };
63
+ }
64
+ exports.default = TrashClear;
@@ -0,0 +1,20 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class TrashList extends Command {
3
+ static readonly args: {};
4
+ static readonly description = "Lists the content of the trash.";
5
+ static readonly examples: string[];
6
+ static readonly aliases: string[];
7
+ static readonly flags: {
8
+ columns: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
9
+ csv: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
10
+ extended: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
11
+ filter: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
12
+ 'no-header': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
13
+ 'no-truncate': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
14
+ output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
15
+ sort: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
16
+ 'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
17
+ };
18
+ run(): Promise<void>;
19
+ catch(error: Error): Promise<void>;
20
+ }
@@ -0,0 +1,95 @@
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 format_utils_1 = require("../utils/format.utils");
8
+ const errors_utils_1 = require("../utils/errors.utils");
9
+ const trash_service_1 = require("../services/drive/trash.service");
10
+ class TrashList extends core_1.Command {
11
+ static args = {};
12
+ static description = 'Lists the content of the trash.';
13
+ static examples = ['<%= config.bin %> <%= command.id %>'];
14
+ static aliases = ['trash:list'];
15
+ static flags = {
16
+ ...cli_utils_1.CLIUtils.CommonFlags,
17
+ ...core_1.ux.table.flags(),
18
+ };
19
+ async run() {
20
+ const { flags } = await this.parse(TrashList);
21
+ const userCredentials = await config_service_1.ConfigService.instance.readUser();
22
+ if (!userCredentials)
23
+ throw new command_types_1.MissingCredentialsError();
24
+ const { folders, files } = await trash_service_1.TrashService.instance.getTrashFolderContent();
25
+ const allItems = [
26
+ ...folders.map((folder) => {
27
+ return {
28
+ isFolder: true,
29
+ plainName: folder.plainName,
30
+ uuid: folder.uuid,
31
+ type: '',
32
+ size: BigInt(0),
33
+ updatedAt: folder.updatedAt,
34
+ };
35
+ }),
36
+ ...files.map((file) => {
37
+ return {
38
+ isFolder: false,
39
+ plainName: file.plainName,
40
+ uuid: file.uuid,
41
+ type: file.type,
42
+ size: file.size,
43
+ updatedAt: file.updatedAt,
44
+ };
45
+ }),
46
+ ];
47
+ core_1.ux.table(allItems, {
48
+ type: {
49
+ header: 'Type',
50
+ get: (row) => (row.isFolder ? 'folder' : 'file'),
51
+ },
52
+ name: {
53
+ header: 'Name',
54
+ get: (row) => (row.isFolder ? row.plainName : `${row.plainName}.${row.type}`),
55
+ },
56
+ updatedAt: {
57
+ header: 'Modified',
58
+ get: (row) => {
59
+ if (flags.output) {
60
+ return row.updatedAt;
61
+ }
62
+ else {
63
+ return format_utils_1.FormatUtils.formatDate(row.updatedAt);
64
+ }
65
+ },
66
+ extended: true,
67
+ },
68
+ size: {
69
+ header: 'Size',
70
+ get: (row) => {
71
+ if (flags.output) {
72
+ return row.isFolder ? '0' : row.size;
73
+ }
74
+ else {
75
+ return row.isFolder ? '' : format_utils_1.FormatUtils.humanFileSize(Number(row.size));
76
+ }
77
+ },
78
+ extended: true,
79
+ },
80
+ uuid: {
81
+ header: 'ID',
82
+ get: (row) => row.uuid,
83
+ },
84
+ }, {
85
+ printLine: this.log.bind(this),
86
+ ...flags,
87
+ });
88
+ }
89
+ async catch(error) {
90
+ errors_utils_1.ErrorUtils.report(error, { command: this.id });
91
+ cli_utils_1.CLIUtils.error(error.message);
92
+ this.exit(1);
93
+ }
94
+ }
95
+ exports.default = TrashList;
@@ -0,0 +1,19 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class TrashRestoreFile extends Command {
3
+ static readonly args: {};
4
+ static readonly description = "Restore a trashed file into a destination folder.";
5
+ static readonly examples: string[];
6
+ static readonly aliases: string[];
7
+ static readonly flags: {
8
+ id: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
9
+ destination: 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
+ 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>;
19
+ }
@@ -0,0 +1,87 @@
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 TrashRestoreFile extends core_1.Command {
11
+ static args = {};
12
+ static description = 'Restore a trashed file into a destination folder.';
13
+ static examples = ['<%= config.bin %> <%= command.id %>'];
14
+ static aliases = ['trash:restore:file'];
15
+ static flags = {
16
+ ...cli_utils_1.CLIUtils.CommonFlags,
17
+ id: core_1.Flags.string({
18
+ char: 'i',
19
+ description: 'The file id to be restored from the trash.',
20
+ required: false,
21
+ }),
22
+ destination: core_1.Flags.string({
23
+ char: 'd',
24
+ description: 'The folder id where the file is going to be restored. Leave empty for the root folder.',
25
+ required: false,
26
+ parse: cli_utils_1.CLIUtils.parseEmpty,
27
+ }),
28
+ };
29
+ async run() {
30
+ const { flags } = await this.parse(TrashRestoreFile);
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
+ let destinationFolderUuid = await this.getDestinationFolderUuid(flags['destination'], nonInteractive);
37
+ if (destinationFolderUuid.trim().length === 0) {
38
+ destinationFolderUuid = userCredentials.root_folder_uuid;
39
+ }
40
+ await drive_file_service_1.DriveFileService.instance.moveFile({ fileUuid, destinationFolderUuid });
41
+ cli_utils_1.CLIUtils.success(`File restored successfully to: ${destinationFolderUuid}`);
42
+ }
43
+ async catch(error) {
44
+ errors_utils_1.ErrorUtils.report(error, { command: this.id });
45
+ cli_utils_1.CLIUtils.error(error.message);
46
+ this.exit(1);
47
+ }
48
+ getFileUuid = async (fileUuidFlag, nonInteractive) => {
49
+ let fileUuid = cli_utils_1.CLIUtils.getValueFromFlag({
50
+ value: fileUuidFlag,
51
+ name: TrashRestoreFile.flags['id'].name,
52
+ error: new command_types_1.NotValidFileUuidError(),
53
+ canBeEmpty: true,
54
+ }, nonInteractive, (fileUuid) => validation_service_1.ValidationService.instance.validateUUIDv4(fileUuid));
55
+ if (!fileUuid) {
56
+ fileUuid = (await this.getFileUuidInteractively()).trim();
57
+ }
58
+ return fileUuid;
59
+ };
60
+ getDestinationFolderUuid = async (destinationFolderUuidFlag, nonInteractive) => {
61
+ let destinationFolderUuid = cli_utils_1.CLIUtils.getValueFromFlag({
62
+ value: destinationFolderUuidFlag,
63
+ name: TrashRestoreFile.flags['destination'].name,
64
+ error: new command_types_1.NotValidFolderUuidError(),
65
+ canBeEmpty: true,
66
+ }, nonInteractive, (folderUuid) => validation_service_1.ValidationService.instance.validateUUIDv4(folderUuid));
67
+ if (!destinationFolderUuid) {
68
+ destinationFolderUuid = (await this.getDestinationFolderUuidInteractively()).trim();
69
+ }
70
+ return destinationFolderUuid;
71
+ };
72
+ static MAX_ATTEMPTS = 3;
73
+ getFileUuidInteractively = () => {
74
+ return cli_utils_1.CLIUtils.promptWithAttempts({
75
+ message: 'What is the file id you want to restore?',
76
+ options: { required: true },
77
+ error: new command_types_1.NotValidFileUuidError(),
78
+ }, TrashRestoreFile.MAX_ATTEMPTS, validation_service_1.ValidationService.instance.validateUUIDv4);
79
+ };
80
+ getDestinationFolderUuidInteractively = () => {
81
+ return cli_utils_1.CLIUtils.prompt({
82
+ message: 'What is the destination folder id? (leave empty for the root folder)',
83
+ options: { required: false },
84
+ });
85
+ };
86
+ }
87
+ exports.default = TrashRestoreFile;
@@ -0,0 +1,19 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class TrashRestoreFolder extends Command {
3
+ static readonly args: {};
4
+ static readonly description = "Restore a trashed folder into a destination folder.";
5
+ static readonly examples: string[];
6
+ static readonly aliases: string[];
7
+ static readonly flags: {
8
+ id: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
9
+ destination: 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
+ 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>;
19
+ }