@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
@@ -1,8 +1,15 @@
1
1
  import { Command } from '@oclif/core';
2
2
  export default class AddCert extends Command {
3
+ static readonly args: {};
3
4
  static readonly description = "Add a self-signed certificate to the trusted store for macOS, Linux, and Windows.";
4
- static examples: string[];
5
- run(): Promise<void>;
6
- catch(error: Error): Promise<void>;
5
+ static readonly aliases: never[];
6
+ static readonly examples: string[];
7
+ static readonly flags: {};
8
+ static readonly enableJsonFlag = true;
9
+ run: () => Promise<{
10
+ success: boolean;
11
+ message: string;
12
+ } | undefined>;
13
+ catch: (error: Error) => Promise<never>;
7
14
  private executeCommand;
8
15
  }
@@ -1,66 +1,52 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
4
  };
25
5
  Object.defineProperty(exports, "__esModule", { value: true });
26
6
  const core_1 = require("@oclif/core");
27
7
  const child_process_1 = require("child_process");
28
8
  const config_service_1 = require("../services/config.service");
29
- const os = __importStar(require("os"));
30
- const path = __importStar(require("path"));
9
+ const node_os_1 = __importDefault(require("node:os"));
10
+ const node_path_1 = __importDefault(require("node:path"));
31
11
  const cli_utils_1 = require("../utils/cli.utils");
32
12
  const errors_utils_1 = require("../utils/errors.utils");
33
13
  class AddCert extends core_1.Command {
14
+ static args = {};
34
15
  static description = 'Add a self-signed certificate to the trusted store for macOS, Linux, and Windows.';
16
+ static aliases = [];
35
17
  static examples = ['<%= config.bin %> <%= command.id %>'];
36
- async run() {
18
+ static flags = {};
19
+ static enableJsonFlag = true;
20
+ run = async () => {
37
21
  try {
38
- const certPath = path.join(config_service_1.ConfigService.WEBDAV_SSL_CERTS_DIR, 'cert.crt');
39
- const platform = os.platform();
40
- const scriptBasePath = path.join(__dirname, '../../scripts');
22
+ const certPath = node_path_1.default.join(config_service_1.ConfigService.WEBDAV_SSL_CERTS_DIR, 'cert.crt');
23
+ const platform = node_os_1.default.platform();
24
+ const scriptBasePath = node_path_1.default.join(__dirname, '../../scripts');
41
25
  let command = '';
42
26
  if (platform === 'win32') {
43
- command = `powershell -ExecutionPolicy Bypass -File "${path.join(scriptBasePath, 'add-cert.ps1')}" -certPath "${certPath}"`;
27
+ command = `powershell -ExecutionPolicy Bypass -File "${node_path_1.default.join(scriptBasePath, 'add-cert.ps1')}" -certPath "${certPath}"`;
44
28
  }
45
29
  else if (platform === 'darwin' || platform === 'linux') {
46
- command = `bash "${path.join(scriptBasePath, 'add-cert.sh')}" "${certPath}"`;
30
+ command = `bash "${node_path_1.default.join(scriptBasePath, 'add-cert.sh')}" "${certPath}"`;
47
31
  }
48
32
  else {
49
33
  throw new Error(`Unsupported OS: ${platform}`);
50
34
  }
51
35
  await this.executeCommand(command);
52
- cli_utils_1.CLIUtils.success('Certificate successfully added to the trusted store.');
36
+ const message = 'Certificate successfully added to the trusted store.';
37
+ cli_utils_1.CLIUtils.success(this.log.bind(this), message);
38
+ return { success: true, message };
53
39
  }
54
40
  catch (error) {
55
41
  await this.catch(error);
56
42
  }
57
- }
58
- async catch(error) {
59
- errors_utils_1.ErrorUtils.report(error, { command: this.id });
60
- cli_utils_1.CLIUtils.error(error.message);
43
+ };
44
+ catch = async (error) => {
45
+ errors_utils_1.ErrorUtils.report(this.error.bind(this), error, { command: this.id });
46
+ cli_utils_1.CLIUtils.error(this.log.bind(this), error.message);
61
47
  this.exit(1);
62
- }
63
- executeCommand(command) {
48
+ };
49
+ executeCommand = (command) => {
64
50
  return new Promise((resolve, reject) => {
65
51
  (0, child_process_1.exec)(command, (error, stdout, stderr) => {
66
52
  if (error) {
@@ -73,6 +59,6 @@ class AddCert extends core_1.Command {
73
59
  }
74
60
  });
75
61
  });
76
- }
62
+ };
77
63
  }
78
64
  exports.default = AddCert;
@@ -2,17 +2,20 @@ import { Command } from '@oclif/core';
2
2
  export default class Config extends Command {
3
3
  static readonly args: {};
4
4
  static readonly description = "Display useful information from the user logged into the Internxt CLI.";
5
+ static readonly aliases: never[];
5
6
  static readonly examples: string[];
6
- static readonly flags: {
7
- columns: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
8
- csv: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
9
- extended: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
10
- filter: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
11
- 'no-header': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
12
- 'no-truncate': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
13
- output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
14
- sort: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
15
- };
16
- catch(error: Error): Promise<void>;
17
- run(): Promise<void>;
7
+ static readonly flags: {};
8
+ static readonly enableJsonFlag = true;
9
+ run: () => Promise<{
10
+ success: boolean;
11
+ config: {
12
+ [k: string]: string;
13
+ };
14
+ message?: undefined;
15
+ } | {
16
+ success: boolean;
17
+ message: string;
18
+ config?: undefined;
19
+ }>;
20
+ catch: (error: Error) => Promise<never>;
18
21
  }
@@ -9,42 +9,38 @@ const format_utils_1 = require("../utils/format.utils");
9
9
  class Config extends core_1.Command {
10
10
  static args = {};
11
11
  static description = 'Display useful information from the user logged into the Internxt CLI.';
12
+ static aliases = [];
12
13
  static examples = ['<%= config.bin %> <%= command.id %>'];
13
- static flags = {
14
- ...core_1.ux.table.flags(),
15
- };
16
- async catch(error) {
17
- errors_utils_1.ErrorUtils.report(error, { command: this.id });
18
- cli_utils_1.CLIUtils.error(error.message);
19
- this.exit(1);
20
- }
21
- async run() {
22
- const { flags } = await this.parse(Config);
14
+ static flags = {};
15
+ static enableJsonFlag = true;
16
+ run = async () => {
23
17
  const userCredentials = await config_service_1.ConfigService.instance.readUser();
24
18
  if (userCredentials?.user) {
19
+ const usedSpace = format_utils_1.FormatUtils.humanFileSize((await usage_service_1.UsageService.instance.fetchUsage()).total);
20
+ const availableSpace = format_utils_1.FormatUtils.formatLimit(await usage_service_1.UsageService.instance.fetchSpaceLimit());
25
21
  const configList = [
26
22
  { key: 'Email', value: userCredentials.user.email },
27
- { key: 'Root folder ID', value: userCredentials.root_folder_uuid },
28
- { key: 'Used space', value: format_utils_1.FormatUtils.humanFileSize((await usage_service_1.UsageService.instance.fetchUsage()).total) },
29
- { key: 'Available space', value: format_utils_1.FormatUtils.formatLimit(await usage_service_1.UsageService.instance.fetchSpaceLimit()) },
23
+ { key: 'Root folder ID', value: userCredentials.user.rootFolderId },
24
+ { key: 'Used space', value: usedSpace },
25
+ { key: 'Available space', value: availableSpace },
26
+ ];
27
+ const header = [
28
+ { value: 'key', alias: 'Key' },
29
+ { value: 'value', alias: 'Value' },
30
30
  ];
31
- core_1.ux.table(configList, {
32
- key: {
33
- header: 'Key',
34
- get: (row) => row.key,
35
- },
36
- value: {
37
- header: 'Value',
38
- get: (row) => row.value,
39
- },
40
- }, {
41
- printLine: this.log.bind(this),
42
- ...flags,
43
- });
31
+ cli_utils_1.CLIUtils.table(this.log.bind(this), header, configList);
32
+ return { success: true, config: Object.fromEntries(configList.map(({ key, value }) => [key, value])) };
44
33
  }
45
34
  else {
46
- cli_utils_1.CLIUtils.error('You are not logged in');
35
+ const message = 'You are not logged in.';
36
+ cli_utils_1.CLIUtils.error(this.log.bind(this), message);
37
+ return { success: false, message };
47
38
  }
48
- }
39
+ };
40
+ catch = async (error) => {
41
+ errors_utils_1.ErrorUtils.report(this.error.bind(this), error, { command: this.id });
42
+ cli_utils_1.CLIUtils.error(this.log.bind(this), error.message);
43
+ this.exit(1);
44
+ };
49
45
  }
50
46
  exports.default = Config;
@@ -1,13 +1,21 @@
1
1
  import { Command } from '@oclif/core';
2
- import { DriveFolderItem } from '../types/drive.types';
3
2
  export default class CreateFolder extends Command {
4
- static description: string;
5
- static examples: string[];
6
- static flags: {
7
- name: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
3
+ static readonly args: {};
4
+ static readonly description = "Create a folder in your Internxt Drive";
5
+ static readonly aliases: never[];
6
+ static readonly examples: string[];
7
+ static readonly flags: {
8
+ name: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
8
9
  id: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
10
+ 'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
9
11
  };
10
- catch(error: Error): Promise<void>;
11
- getParentFolder(uuid: string): Promise<DriveFolderItem>;
12
- run(): Promise<void>;
12
+ static readonly enableJsonFlag = true;
13
+ run: () => Promise<{
14
+ success: boolean;
15
+ message: string;
16
+ folder: import("@internxt/sdk/dist/drive/storage/types").CreateFolderResponse;
17
+ }>;
18
+ catch: (error: Error) => Promise<never>;
19
+ private getFolderName;
20
+ private getFolderUuid;
13
21
  }
@@ -1,44 +1,47 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const core_1 = require("@oclif/core");
4
- const auth_service_1 = require("../services/auth.service");
5
4
  const errors_utils_1 = require("../utils/errors.utils");
6
5
  const cli_utils_1 = require("../utils/cli.utils");
7
6
  const drive_folder_service_1 = require("../services/drive/drive-folder.service");
8
7
  const config_service_1 = require("../services/config.service");
8
+ const validation_service_1 = require("../services/validation.service");
9
+ const command_types_1 = require("../types/command.types");
9
10
  class CreateFolder extends core_1.Command {
11
+ static args = {};
10
12
  static description = 'Create a folder in your Internxt Drive';
13
+ static aliases = [];
11
14
  static examples = ['<%= config.bin %> <%= command.id %>'];
12
15
  static flags = {
13
- name: core_1.Flags.string({ description: 'The new folder name', required: true }),
16
+ ...cli_utils_1.CLIUtils.CommonFlags,
17
+ name: core_1.Flags.string({
18
+ char: 'n',
19
+ description: 'The new name for the folder',
20
+ required: false,
21
+ }),
14
22
  id: core_1.Flags.string({
15
- description: 'The folder id to create the folder in, defaults to your root folder',
23
+ char: 'i',
24
+ description: 'The ID of the folder where the new folder will be created. Defaults to your root folder if not specified.',
16
25
  required: false,
26
+ parse: cli_utils_1.CLIUtils.parseEmpty,
17
27
  }),
18
28
  };
19
- async catch(error) {
20
- errors_utils_1.ErrorUtils.report(error, { command: this.id });
21
- cli_utils_1.CLIUtils.error(error.message);
22
- this.exit(1);
23
- }
24
- getParentFolder(uuid) {
25
- return drive_folder_service_1.DriveFolderService.instance.getFolderMetaByUuid(uuid);
26
- }
27
- async run() {
29
+ static enableJsonFlag = true;
30
+ run = async () => {
28
31
  const { flags } = await this.parse(CreateFolder);
29
- const folderName = flags.name;
30
- const user = await auth_service_1.AuthService.instance.getUser();
31
- let parentFolder;
32
- if (flags.id) {
33
- parentFolder = await this.getParentFolder(flags.id);
34
- if (!parentFolder) {
35
- throw new Error(`Folder with id ${flags.id} not found`);
36
- }
32
+ const nonInteractive = flags['non-interactive'];
33
+ const userCredentials = await config_service_1.ConfigService.instance.readUser();
34
+ if (!userCredentials)
35
+ throw new command_types_1.MissingCredentialsError();
36
+ const folderName = await this.getFolderName(flags['name'], nonInteractive);
37
+ let folderUuid = await this.getFolderUuid(flags['id'], nonInteractive);
38
+ if (folderUuid.trim().length === 0) {
39
+ folderUuid = userCredentials.user.rootFolderId;
37
40
  }
38
41
  cli_utils_1.CLIUtils.doing('Creating folder...');
39
42
  const [createNewFolder, requestCanceler] = drive_folder_service_1.DriveFolderService.instance.createFolder({
40
- folderName,
41
- parentFolderId: parentFolder ? parentFolder.id : user.root_folder_id,
43
+ plainName: folderName,
44
+ parentFolderUuid: folderUuid,
42
45
  });
43
46
  process.on('SIGINT', () => {
44
47
  requestCanceler.cancel('SIGINT received');
@@ -46,7 +49,47 @@ class CreateFolder extends core_1.Command {
46
49
  });
47
50
  const newFolder = await createNewFolder;
48
51
  cli_utils_1.CLIUtils.done();
49
- cli_utils_1.CLIUtils.success(`Folder ${newFolder.plainName} created successfully, view it at view it at ${config_service_1.ConfigService.instance.get('DRIVE_URL')}/folder/${newFolder.uuid}`);
50
- }
52
+ const message = `Folder ${newFolder.plainName} created successfully, view it at ${config_service_1.ConfigService.instance.get('DRIVE_URL')}/folder/${newFolder.uuid}`;
53
+ cli_utils_1.CLIUtils.success(this.log.bind(this), message);
54
+ return { success: true, message, folder: newFolder };
55
+ };
56
+ catch = async (error) => {
57
+ errors_utils_1.ErrorUtils.report(this.error.bind(this), error, { command: this.id });
58
+ cli_utils_1.CLIUtils.error(this.log.bind(this), error.message);
59
+ this.exit(1);
60
+ };
61
+ getFolderName = async (folderNameFlag, nonInteractive) => {
62
+ const folderName = await cli_utils_1.CLIUtils.getValueFromFlag({
63
+ value: folderNameFlag,
64
+ name: CreateFolder.flags['name'].name,
65
+ }, {
66
+ nonInteractive,
67
+ prompt: {
68
+ message: 'What would you like to name the new folder?',
69
+ options: { type: 'input' },
70
+ },
71
+ }, {
72
+ validate: validation_service_1.ValidationService.instance.validateStringIsNotEmpty,
73
+ error: new command_types_1.EmptyFolderNameError(),
74
+ }, this.log.bind(this));
75
+ return folderName;
76
+ };
77
+ getFolderUuid = async (folderUuidFlag, nonInteractive) => {
78
+ const folderUuid = await cli_utils_1.CLIUtils.getValueFromFlag({
79
+ value: folderUuidFlag,
80
+ name: CreateFolder.flags['id'].name,
81
+ }, {
82
+ nonInteractive,
83
+ prompt: {
84
+ message: 'What is the ID of the folder where you would like to create the new folder? (leave empty for the root folder)',
85
+ options: { type: 'input' },
86
+ },
87
+ }, {
88
+ validate: validation_service_1.ValidationService.instance.validateUUIDv4,
89
+ error: new command_types_1.NotValidFolderUuidError(),
90
+ canBeEmpty: true,
91
+ }, this.log.bind(this));
92
+ return folderUuid;
93
+ };
51
94
  }
52
95
  exports.default = CreateFolder;
@@ -0,0 +1,18 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class DeletePermanentlyFile extends Command {
3
+ static readonly args: {};
4
+ static readonly description = "Deletes permanently a file. This action cannot be undone.";
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
+ }>;
16
+ catch: (error: Error) => Promise<never>;
17
+ private getFileUuid;
18
+ }
@@ -0,0 +1,63 @@
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
+ const trash_service_1 = require("../services/drive/trash.service");
11
+ class DeletePermanentlyFile extends core_1.Command {
12
+ static args = {};
13
+ static description = 'Deletes permanently a file. This action cannot be undone.';
14
+ static aliases = ['delete:permanently:file'];
15
+ static examples = ['<%= config.bin %> <%= command.id %>'];
16
+ static flags = {
17
+ ...cli_utils_1.CLIUtils.CommonFlags,
18
+ id: core_1.Flags.string({
19
+ char: 'i',
20
+ description: 'The file id to be permanently deleted.',
21
+ required: false,
22
+ }),
23
+ };
24
+ static enableJsonFlag = true;
25
+ run = async () => {
26
+ const { flags } = await this.parse(DeletePermanentlyFile);
27
+ const nonInteractive = flags['non-interactive'];
28
+ const userCredentials = await config_service_1.ConfigService.instance.readUser();
29
+ if (!userCredentials)
30
+ throw new command_types_1.MissingCredentialsError();
31
+ const fileUuid = await this.getFileUuid(flags['id'], nonInteractive);
32
+ const driveFile = await drive_file_service_1.DriveFileService.instance.getFileMetadata(fileUuid);
33
+ if (!driveFile) {
34
+ throw new Error('File not found');
35
+ }
36
+ await trash_service_1.TrashService.instance.deleteFile({ fileId: driveFile.id, folderId: driveFile.folderId });
37
+ const message = 'File permanently deleted successfully';
38
+ cli_utils_1.CLIUtils.success(this.log.bind(this), message);
39
+ return { success: true, message };
40
+ };
41
+ catch = async (error) => {
42
+ errors_utils_1.ErrorUtils.report(this.error.bind(this), error, { command: this.id });
43
+ cli_utils_1.CLIUtils.error(this.log.bind(this), error.message);
44
+ this.exit(1);
45
+ };
46
+ getFileUuid = async (fileUuidFlag, nonInteractive) => {
47
+ const fileUuid = await cli_utils_1.CLIUtils.getValueFromFlag({
48
+ value: fileUuidFlag,
49
+ name: DeletePermanentlyFile.flags['id'].name,
50
+ }, {
51
+ nonInteractive,
52
+ prompt: {
53
+ message: 'What is the file id you want to permanently delete? (This action cannot be undone)',
54
+ options: { type: 'input' },
55
+ },
56
+ }, {
57
+ validate: validation_service_1.ValidationService.instance.validateUUIDv4,
58
+ error: new command_types_1.NotValidFileUuidError(),
59
+ }, this.log.bind(this));
60
+ return fileUuid;
61
+ };
62
+ }
63
+ exports.default = DeletePermanentlyFile;
@@ -0,0 +1,18 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class DeletePermanentlyFolder extends Command {
3
+ static readonly args: {};
4
+ static readonly description = "Deletes permanently a folder. This action cannot be undone.";
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
+ }>;
16
+ catch: (error: Error) => Promise<never>;
17
+ private getFolderUuid;
18
+ }
@@ -0,0 +1,63 @@
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 errors_utils_1 = require("../utils/errors.utils");
9
+ const trash_service_1 = require("../services/drive/trash.service");
10
+ const drive_folder_service_1 = require("../services/drive/drive-folder.service");
11
+ class DeletePermanentlyFolder extends core_1.Command {
12
+ static args = {};
13
+ static description = 'Deletes permanently a folder. This action cannot be undone.';
14
+ static aliases = ['delete:permanently:folder'];
15
+ static examples = ['<%= config.bin %> <%= command.id %>'];
16
+ static flags = {
17
+ ...cli_utils_1.CLIUtils.CommonFlags,
18
+ id: core_1.Flags.string({
19
+ char: 'i',
20
+ description: 'The folder id to be permanently deleted.',
21
+ required: false,
22
+ }),
23
+ };
24
+ static enableJsonFlag = true;
25
+ run = async () => {
26
+ const { flags } = await this.parse(DeletePermanentlyFolder);
27
+ const nonInteractive = flags['non-interactive'];
28
+ const userCredentials = await config_service_1.ConfigService.instance.readUser();
29
+ if (!userCredentials)
30
+ throw new command_types_1.MissingCredentialsError();
31
+ const folderUuid = await this.getFolderUuid(flags['id'], nonInteractive);
32
+ const driveFolder = await drive_folder_service_1.DriveFolderService.instance.getFolderMetaByUuid(folderUuid);
33
+ if (!driveFolder) {
34
+ throw new Error('Folder not found');
35
+ }
36
+ await trash_service_1.TrashService.instance.deleteFolder(driveFolder.id);
37
+ const message = 'Folder permanently deleted successfully';
38
+ cli_utils_1.CLIUtils.success(this.log.bind(this), message);
39
+ return { success: true, message };
40
+ };
41
+ catch = async (error) => {
42
+ errors_utils_1.ErrorUtils.report(this.error.bind(this), error, { command: this.id });
43
+ cli_utils_1.CLIUtils.error(this.log.bind(this), error.message);
44
+ this.exit(1);
45
+ };
46
+ getFolderUuid = async (folderUuidFlag, nonInteractive) => {
47
+ const folderUuid = await cli_utils_1.CLIUtils.getValueFromFlag({
48
+ value: folderUuidFlag,
49
+ name: DeletePermanentlyFolder.flags['id'].name,
50
+ }, {
51
+ nonInteractive,
52
+ prompt: {
53
+ message: 'What is the folder id you want to permanently delete? (This action cannot be undone)',
54
+ options: { type: 'input' },
55
+ },
56
+ }, {
57
+ validate: validation_service_1.ValidationService.instance.validateUUIDv4,
58
+ error: new command_types_1.NotValidFolderUuidError(),
59
+ }, this.log.bind(this));
60
+ return folderUuid;
61
+ };
62
+ }
63
+ exports.default = DeletePermanentlyFolder;
@@ -0,0 +1,26 @@
1
+ import { Command } from '@oclif/core';
2
+ import { DriveFileItem } from '../types/drive.types';
3
+ export default class DownloadFile extends Command {
4
+ static readonly args: {};
5
+ static readonly description = "Download and decrypts a file from Internxt Drive to a directory. The file name will be the same as the file name in your Drive.";
6
+ static readonly aliases: string[];
7
+ static readonly examples: string[];
8
+ static readonly flags: {
9
+ id: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
10
+ directory: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
11
+ overwrite: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
12
+ 'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
13
+ };
14
+ static readonly enableJsonFlag = true;
15
+ run: () => Promise<{
16
+ success: boolean;
17
+ message: string;
18
+ file: DriveFileItem;
19
+ }>;
20
+ catch: (error: Error) => Promise<never>;
21
+ private getFileUuid;
22
+ private getDirectory;
23
+ private getFileMetadata;
24
+ private getDownloadPath;
25
+ private prepareNetwork;
26
+ }