@internxt/cli 1.5.8 → 1.6.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 (86) hide show
  1. package/README.md +187 -95
  2. package/dist/commands/create-folder.d.ts +3 -3
  3. package/dist/commands/delete-permanently-file.d.ts +2 -2
  4. package/dist/commands/delete-permanently-folder.d.ts +2 -2
  5. package/dist/commands/download-file.d.ts +4 -5
  6. package/dist/commands/download-file.js +22 -37
  7. package/dist/commands/list.d.ts +4 -4
  8. package/dist/commands/login-legacy.d.ts +24 -0
  9. package/dist/commands/login-legacy.js +175 -0
  10. package/dist/commands/login.d.ts +3 -9
  11. package/dist/commands/login.js +18 -132
  12. package/dist/commands/move-file.d.ts +4 -4
  13. package/dist/commands/move-folder.d.ts +3 -3
  14. package/dist/commands/rename-file.d.ts +3 -3
  15. package/dist/commands/rename-folder.d.ts +3 -3
  16. package/dist/commands/trash-clear.d.ts +2 -2
  17. package/dist/commands/trash-file.d.ts +2 -2
  18. package/dist/commands/trash-file.js +1 -1
  19. package/dist/commands/trash-folder.d.ts +2 -2
  20. package/dist/commands/trash-folder.js +1 -1
  21. package/dist/commands/trash-list.d.ts +2 -2
  22. package/dist/commands/trash-restore-file.d.ts +4 -4
  23. package/dist/commands/trash-restore-folder.d.ts +3 -3
  24. package/dist/commands/upload-file.d.ts +8 -8
  25. package/dist/commands/upload-file.js +7 -40
  26. package/dist/commands/upload-folder.d.ts +16 -0
  27. package/dist/commands/upload-folder.js +87 -0
  28. package/dist/commands/webdav-config.d.ts +6 -6
  29. package/dist/commands/webdav.d.ts +1 -1
  30. package/dist/commands/whoami.js +1 -1
  31. package/dist/hooks/prerun/auth_check.js +2 -1
  32. package/dist/services/auth.service.d.ts +1 -2
  33. package/dist/services/auth.service.js +11 -26
  34. package/dist/services/crypto.service.js +1 -1
  35. package/dist/services/database/drive-file/drive-file.domain.js +1 -0
  36. package/dist/services/database/drive-folder/drive-folder.domain.js +1 -0
  37. package/dist/services/drive/drive-file.service.js +1 -0
  38. package/dist/services/drive/drive-folder.service.d.ts +1 -1
  39. package/dist/services/drive/trash.service.d.ts +1 -1
  40. package/dist/services/local-filesystem/local-filesystem.service.d.ts +6 -0
  41. package/dist/services/local-filesystem/local-filesystem.service.js +57 -0
  42. package/dist/services/local-filesystem/local-filesystem.types.d.ts +13 -0
  43. package/dist/services/local-filesystem/local-filesystem.types.js +2 -0
  44. package/dist/services/network/upload/upload-facade.service.d.ts +9 -0
  45. package/dist/services/network/upload/upload-facade.service.js +53 -0
  46. package/dist/services/network/upload/upload-file.service.d.ts +7 -0
  47. package/dist/services/network/upload/upload-file.service.js +112 -0
  48. package/dist/services/network/upload/upload-folder.service.d.ts +6 -0
  49. package/dist/services/network/upload/upload-folder.service.js +62 -0
  50. package/dist/services/network/upload/upload.types.d.ts +53 -0
  51. package/dist/services/network/upload/upload.types.js +6 -0
  52. package/dist/services/thumbnail.service.js +1 -34
  53. package/dist/services/universal-link.service.d.ts +10 -0
  54. package/dist/services/universal-link.service.js +85 -0
  55. package/dist/types/command.types.d.ts +3 -2
  56. package/dist/types/command.types.js +8 -1
  57. package/dist/types/drive.types.d.ts +2 -0
  58. package/dist/types/fast-xml-parser.types.d.ts +59 -0
  59. package/dist/types/fast-xml-parser.types.js +2 -0
  60. package/dist/types/webdav.types.d.ts +0 -1
  61. package/dist/utils/cli.utils.d.ts +13 -2
  62. package/dist/utils/cli.utils.js +47 -0
  63. package/dist/utils/drive.utils.js +3 -0
  64. package/dist/utils/errors.utils.d.ts +1 -0
  65. package/dist/utils/errors.utils.js +5 -0
  66. package/dist/utils/logger.utils.js +10 -0
  67. package/dist/utils/network.utils.d.ts +2 -2
  68. package/dist/utils/network.utils.js +7 -5
  69. package/dist/utils/thumbnail.utils.d.ts +17 -0
  70. package/dist/utils/thumbnail.utils.js +29 -1
  71. package/dist/utils/webdav.utils.d.ts +12 -10
  72. package/dist/utils/webdav.utils.js +39 -29
  73. package/dist/utils/xml.utils.d.ts +1 -1
  74. package/dist/webdav/handlers/DELETE.handler.js +5 -5
  75. package/dist/webdav/handlers/GET.handler.js +43 -33
  76. package/dist/webdav/handlers/HEAD.handler.js +5 -10
  77. package/dist/webdav/handlers/MKCOL.handler.js +4 -4
  78. package/dist/webdav/handlers/MOVE.handler.js +19 -17
  79. package/dist/webdav/handlers/OPTIONS.handler.js +3 -3
  80. package/dist/webdav/handlers/PROPFIND.handler.js +7 -31
  81. package/dist/webdav/handlers/PUT.handler.d.ts +2 -0
  82. package/dist/webdav/handlers/PUT.handler.js +10 -8
  83. package/dist/webdav/services/webdav-folder.service.js +5 -4
  84. package/dist/webdav/webdav-server.js +1 -0
  85. package/oclif.manifest.json +121 -3
  86. package/package.json +33 -32
@@ -5,8 +5,8 @@ export default class TrashClear extends Command {
5
5
  static readonly aliases: string[];
6
6
  static readonly examples: string[];
7
7
  static readonly flags: {
8
- force: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
9
- 'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
8
+ force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
9
+ 'non-interactive': import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
10
  };
11
11
  static readonly enableJsonFlag = true;
12
12
  run: () => Promise<{
@@ -5,8 +5,8 @@ export default class TrashFile extends Command {
5
5
  static readonly aliases: string[];
6
6
  static readonly examples: string[];
7
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>;
8
+ id: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ 'non-interactive': import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
10
  };
11
11
  static readonly enableJsonFlag = true;
12
12
  run: () => Promise<{
@@ -27,7 +27,7 @@ class TrashFile extends core_1.Command {
27
27
  if (!userCredentials)
28
28
  throw new command_types_1.MissingCredentialsError();
29
29
  const uuid = await this.getFileUuid(flags['id'], nonInteractive);
30
- await trash_service_1.TrashService.instance.trashItems({ items: [{ uuid, type: 'file', id: null }] });
30
+ await trash_service_1.TrashService.instance.trashItems({ items: [{ uuid, type: 'file' }] });
31
31
  const message = 'File trashed successfully.';
32
32
  cli_utils_1.CLIUtils.success(this.log.bind(this), message);
33
33
  return { success: true, message, file: { uuid } };
@@ -5,8 +5,8 @@ export default class TrashFolder extends Command {
5
5
  static readonly aliases: string[];
6
6
  static readonly examples: string[];
7
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>;
8
+ id: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ 'non-interactive': import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
10
  };
11
11
  static readonly enableJsonFlag = true;
12
12
  run: () => Promise<{
@@ -27,7 +27,7 @@ class TrashFolder extends core_1.Command {
27
27
  if (!userCredentials)
28
28
  throw new command_types_1.MissingCredentialsError();
29
29
  const uuid = await this.getFolderUuid(flags['id'], nonInteractive);
30
- await trash_service_1.TrashService.instance.trashItems({ items: [{ uuid, type: 'folder', id: null }] });
30
+ await trash_service_1.TrashService.instance.trashItems({ items: [{ uuid, type: 'folder' }] });
31
31
  const message = 'Folder trashed successfully.';
32
32
  cli_utils_1.CLIUtils.success(this.log.bind(this), message);
33
33
  return { success: true, message, folder: { uuid } };
@@ -5,7 +5,7 @@ export default class TrashList extends Command {
5
5
  static readonly aliases: string[];
6
6
  static readonly examples: string[];
7
7
  static readonly flags: {
8
- extended: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
8
+ extended: import("@oclif/core/interfaces").BooleanFlag<boolean>;
9
9
  };
10
10
  static readonly enableJsonFlag = true;
11
11
  run: () => Promise<{
@@ -35,7 +35,7 @@ export default class TrashList extends Command {
35
35
  files: {
36
36
  id: number;
37
37
  uuid: string;
38
- fileId: string;
38
+ fileId: string | null;
39
39
  name: string;
40
40
  type: string;
41
41
  size: string;
@@ -5,9 +5,9 @@ export default class TrashRestoreFile extends Command {
5
5
  static readonly aliases: string[];
6
6
  static readonly examples: string[];
7
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>;
8
+ id: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ destination: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ 'non-interactive': import("@oclif/core/interfaces").BooleanFlag<boolean>;
11
11
  };
12
12
  static readonly enableJsonFlag = true;
13
13
  run: () => Promise<{
@@ -16,7 +16,7 @@ export default class TrashRestoreFile extends Command {
16
16
  file: {
17
17
  id: number;
18
18
  uuid: string;
19
- fileId: string;
19
+ fileId: string | null;
20
20
  name: string;
21
21
  type: string;
22
22
  size: string;
@@ -5,9 +5,9 @@ export default class TrashRestoreFolder extends Command {
5
5
  static readonly aliases: string[];
6
6
  static readonly examples: string[];
7
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>;
8
+ id: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ destination: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ 'non-interactive': import("@oclif/core/interfaces").BooleanFlag<boolean>;
11
11
  };
12
12
  static readonly enableJsonFlag = true;
13
13
  run: () => Promise<{
@@ -5,9 +5,9 @@ export default class UploadFile extends Command {
5
5
  static readonly aliases: string[];
6
6
  static readonly examples: string[];
7
7
  static readonly flags: {
8
- file: 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>;
8
+ file: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ destination: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ 'non-interactive': import("@oclif/core/interfaces").BooleanFlag<boolean>;
11
11
  };
12
12
  static readonly enableJsonFlag = true;
13
13
  run: () => Promise<{
@@ -15,14 +15,15 @@ export default class UploadFile extends Command {
15
15
  message: string;
16
16
  file: {
17
17
  plainName: string;
18
+ status: "EXISTS" | "TRASHED" | "DELETED";
18
19
  name: string;
19
20
  id: number;
20
- bucket: string;
21
21
  uuid: string;
22
- folderUuid: string;
22
+ fileId: string | null;
23
+ bucket: string;
23
24
  folderId: number;
24
- status: "EXISTS" | "TRASHED" | "DELETED";
25
- fileId: string;
25
+ folderUuid: string;
26
+ itemType: "file";
26
27
  size: number;
27
28
  createdAt: Date;
28
29
  updatedAt: Date;
@@ -32,6 +33,5 @@ export default class UploadFile extends Command {
32
33
  };
33
34
  }>;
34
35
  catch: (error: Error) => Promise<never>;
35
- private getDestinationFolderUuid;
36
36
  private getFilePath;
37
37
  }
@@ -6,15 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const core_1 = require("@oclif/core");
7
7
  const promises_1 = require("node:fs/promises");
8
8
  const node_fs_1 = require("node:fs");
9
- const network_facade_service_1 = require("../services/network/network-facade.service");
10
- const sdk_manager_service_1 = require("../services/sdk-manager.service");
11
9
  const auth_service_1 = require("../services/auth.service");
12
10
  const cli_utils_1 = require("../utils/cli.utils");
13
11
  const config_service_1 = require("../services/config.service");
14
12
  const node_path_1 = __importDefault(require("node:path"));
15
13
  const drive_file_service_1 = require("../services/drive/drive-file.service");
16
- const crypto_service_1 = require("../services/crypto.service");
17
- const download_service_1 = require("../services/network/download.service");
18
14
  const errors_utils_1 = require("../utils/errors.utils");
19
15
  const command_types_1 = require("../types/command.types");
20
16
  const validation_service_1 = require("../services/validation.service");
@@ -22,7 +18,6 @@ const types_1 = require("@internxt/sdk/dist/drive/storage/types");
22
18
  const thumbnail_service_1 = require("../services/thumbnail.service");
23
19
  const stream_utils_1 = require("../utils/stream.utils");
24
20
  const thumbnail_utils_1 = require("../utils/thumbnail.utils");
25
- const inxt_js_1 = require("@internxt/inxt-js");
26
21
  class UploadFile extends core_1.Command {
27
22
  static args = {};
28
23
  static description = 'Upload a file to Internxt Drive';
@@ -54,24 +49,13 @@ class UploadFile extends core_1.Command {
54
49
  }
55
50
  const fileInfo = node_path_1.default.parse(filePath);
56
51
  const fileType = fileInfo.ext.replaceAll('.', '');
57
- let destinationFolderUuid = await this.getDestinationFolderUuid(flags['destination'], nonInteractive);
58
- if (destinationFolderUuid.trim().length === 0) {
59
- destinationFolderUuid = user.rootFolderId;
60
- }
61
- cli_utils_1.CLIUtils.doing('Preparing Network', flags['json']);
62
- const networkModule = sdk_manager_service_1.SdkManager.instance.getNetwork({
63
- user: user.bridgeUser,
64
- pass: user.userId,
65
- });
66
- const environment = new inxt_js_1.Environment({
67
- bridgeUser: user.bridgeUser,
68
- bridgePass: user.userId,
69
- bridgeUrl: config_service_1.ConfigService.instance.get('NETWORK_URL'),
70
- encryptionKey: user.mnemonic,
71
- appDetails: sdk_manager_service_1.SdkManager.getAppDetails(),
72
- });
73
- const networkFacade = new network_facade_service_1.NetworkFacade(networkModule, environment, download_service_1.DownloadService.instance, crypto_service_1.CryptoService.instance);
74
- cli_utils_1.CLIUtils.done(flags['json']);
52
+ const destinationFolderUuid = (await cli_utils_1.CLIUtils.getDestinationFolderUuid({
53
+ destinationFolderUuidFlag: flags['destination'],
54
+ destinationFlagName: UploadFile.flags['destination'].name,
55
+ nonInteractive,
56
+ reporter: this.log.bind(this),
57
+ })) ?? user.rootFolderId;
58
+ const networkFacade = await cli_utils_1.CLIUtils.prepareNetwork({ loginUserDetails: user, jsonFlag: flags['json'] });
75
59
  const readStream = (0, node_fs_1.createReadStream)(filePath);
76
60
  const timer = cli_utils_1.CLIUtils.timer();
77
61
  const progressBar = cli_utils_1.CLIUtils.progress({
@@ -148,23 +132,6 @@ class UploadFile extends core_1.Command {
148
132
  });
149
133
  this.exit(1);
150
134
  };
151
- getDestinationFolderUuid = async (destinationFolderUuidFlag, nonInteractive) => {
152
- const destinationFolderUuid = await cli_utils_1.CLIUtils.getValueFromFlag({
153
- value: destinationFolderUuidFlag,
154
- name: UploadFile.flags['destination'].name,
155
- }, {
156
- nonInteractive,
157
- prompt: {
158
- message: 'What is the destination folder id? (leave empty for the root folder)',
159
- options: { type: 'input' },
160
- },
161
- }, {
162
- validate: validation_service_1.ValidationService.instance.validateUUIDv4,
163
- error: new command_types_1.NotValidFolderUuidError(),
164
- canBeEmpty: true,
165
- }, this.log.bind(this));
166
- return destinationFolderUuid;
167
- };
168
135
  getFilePath = async (fileFlag, nonInteractive) => {
169
136
  const filePath = await cli_utils_1.CLIUtils.getValueFromFlag({
170
137
  value: fileFlag,
@@ -0,0 +1,16 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class UploadFolder extends Command {
3
+ static readonly args: {};
4
+ static readonly description = "Upload a folder to Internxt Drive";
5
+ static readonly aliases: string[];
6
+ static readonly examples: string[];
7
+ static readonly flags: {
8
+ folder: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ destination: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ 'non-interactive': import("@oclif/core/interfaces").BooleanFlag<boolean>;
11
+ };
12
+ static readonly enableJsonFlag = true;
13
+ run: () => Promise<void>;
14
+ catch: (error: Error) => Promise<never>;
15
+ private getFolderPath;
16
+ }
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const cli_utils_1 = require("../utils/cli.utils");
5
+ const auth_service_1 = require("../services/auth.service");
6
+ const validation_service_1 = require("../services/validation.service");
7
+ const config_service_1 = require("../services/config.service");
8
+ const upload_facade_service_1 = require("../services/network/upload/upload-facade.service");
9
+ const command_types_1 = require("../types/command.types");
10
+ class UploadFolder extends core_1.Command {
11
+ static args = {};
12
+ static description = 'Upload a folder to Internxt Drive';
13
+ static aliases = ['upload:folder'];
14
+ static examples = ['<%= config.bin %> <%= command.id %>'];
15
+ static flags = {
16
+ ...cli_utils_1.CLIUtils.CommonFlags,
17
+ folder: core_1.Flags.string({
18
+ char: 'f',
19
+ description: 'The path to the folder on your system.',
20
+ required: false,
21
+ }),
22
+ destination: core_1.Flags.string({
23
+ char: 'i',
24
+ description: 'The folder id where the folder is going to be uploaded to. Leave empty for the root folder.',
25
+ required: false,
26
+ parse: cli_utils_1.CLIUtils.parseEmpty,
27
+ }),
28
+ };
29
+ static enableJsonFlag = true;
30
+ run = async () => {
31
+ const { user } = await auth_service_1.AuthService.instance.getAuthDetails();
32
+ const { flags } = await this.parse(UploadFolder);
33
+ const localPath = await this.getFolderPath(flags['folder'], flags['non-interactive']);
34
+ const destinationFolderUuid = (await cli_utils_1.CLIUtils.getDestinationFolderUuid({
35
+ destinationFolderUuidFlag: flags['destination'],
36
+ destinationFlagName: UploadFolder.flags['destination'].name,
37
+ nonInteractive: flags['non-interactive'],
38
+ reporter: this.log.bind(this),
39
+ })) ?? user.rootFolderId;
40
+ const progressBar = cli_utils_1.CLIUtils.progress({
41
+ format: 'Uploading folder [{bar}] {percentage}%',
42
+ linewrap: true,
43
+ }, flags['json']);
44
+ progressBar?.start(100, 0);
45
+ const data = await upload_facade_service_1.UploadFacade.instance.uploadFolder({
46
+ localPath,
47
+ destinationFolderUuid,
48
+ loginUserDetails: user,
49
+ jsonFlag: flags['json'],
50
+ onProgress: (progress) => {
51
+ progressBar?.update(progress.percentage);
52
+ },
53
+ });
54
+ progressBar?.update(100);
55
+ progressBar?.stop();
56
+ const driveUrl = config_service_1.ConfigService.instance.get('DRIVE_WEB_URL');
57
+ const folderUrl = `${driveUrl}/folder/${data.rootFolderId}`;
58
+ const message = `Folder uploaded in ${data.uploadTimeMs}ms, view it at ${folderUrl} (${data.totalBytes} bytes)`;
59
+ cli_utils_1.CLIUtils.success(this.log.bind(this), message);
60
+ };
61
+ catch = async (error) => {
62
+ const { flags } = await this.parse(UploadFolder);
63
+ cli_utils_1.CLIUtils.catchError({
64
+ error,
65
+ command: this.id,
66
+ logReporter: this.log.bind(this),
67
+ jsonFlag: flags['json'],
68
+ });
69
+ this.exit(1);
70
+ };
71
+ getFolderPath = async (folderFlag, nonInteractive) => {
72
+ return await cli_utils_1.CLIUtils.getValueFromFlag({
73
+ value: folderFlag,
74
+ name: UploadFolder.flags['folder'].name,
75
+ }, {
76
+ nonInteractive,
77
+ prompt: {
78
+ message: 'What is the path to the folder on your computer?',
79
+ options: { type: 'input' },
80
+ },
81
+ }, {
82
+ validate: validation_service_1.ValidationService.instance.validateDirectoryExists,
83
+ error: new command_types_1.NotValidDirectoryError(),
84
+ }, this.log.bind(this));
85
+ };
86
+ }
87
+ exports.default = UploadFolder;
@@ -5,12 +5,12 @@ export default class WebDAVConfig extends Command {
5
5
  static readonly aliases: never[];
6
6
  static readonly examples: string[];
7
7
  static readonly flags: {
8
- host: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
9
- port: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
10
- https: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
11
- http: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
12
- timeout: import("@oclif/core/lib/interfaces").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
13
- createFullPath: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
8
+ host: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ port: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ https: import("@oclif/core/interfaces").BooleanFlag<boolean>;
11
+ http: import("@oclif/core/interfaces").BooleanFlag<boolean>;
12
+ timeout: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ createFullPath: import("@oclif/core/interfaces").BooleanFlag<boolean>;
14
14
  };
15
15
  static readonly enableJsonFlag = true;
16
16
  run: () => Promise<{
@@ -1,7 +1,7 @@
1
1
  import { Command } from '@oclif/core';
2
2
  export default class Webdav extends Command {
3
3
  static readonly args: {
4
- action: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
4
+ action: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
5
5
  };
6
6
  static readonly description = "Enable, disable, restart or get the status of the Internxt CLI WebDav server";
7
7
  static readonly aliases: never[];
@@ -30,7 +30,7 @@ class Whoami extends core_1.Command {
30
30
  else {
31
31
  if (validCreds.refreshRequired) {
32
32
  try {
33
- await auth_service_1.AuthService.instance.refreshUserToken(userCredentials);
33
+ await auth_service_1.AuthService.instance.refreshUserToken(userCredentials.token, userCredentials.user.mnemonic);
34
34
  }
35
35
  catch {
36
36
  }
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const whoami_1 = __importDefault(require("../../commands/whoami"));
7
7
  const login_1 = __importDefault(require("../../commands/login"));
8
+ const login_legacy_1 = __importDefault(require("../../commands/login-legacy"));
8
9
  const logout_1 = __importDefault(require("../../commands/logout"));
9
10
  const logs_1 = __importDefault(require("../../commands/logs"));
10
11
  const cli_utils_1 = require("../../utils/cli.utils");
@@ -12,7 +13,7 @@ const sdk_manager_service_1 = require("../../services/sdk-manager.service");
12
13
  const auth_service_1 = require("../../services/auth.service");
13
14
  const webdav_1 = __importDefault(require("../../commands/webdav"));
14
15
  const webdav_config_1 = __importDefault(require("../../commands/webdav-config"));
15
- const CommandsToSkip = [whoami_1.default, login_1.default, logout_1.default, logs_1.default, webdav_1.default, webdav_config_1.default];
16
+ const CommandsToSkip = [whoami_1.default, login_1.default, login_legacy_1.default, logout_1.default, logs_1.default, webdav_1.default, webdav_config_1.default];
16
17
  const hook = async function (opts) {
17
18
  const { Command, argv } = opts;
18
19
  const jsonFlag = argv.includes('--json');
@@ -4,7 +4,6 @@ export declare class AuthService {
4
4
  doLogin: (email: string, password: string, twoFactorCode?: string) => Promise<LoginCredentials>;
5
5
  is2FANeeded: (email: string) => Promise<boolean>;
6
6
  getAuthDetails: () => Promise<LoginCredentials>;
7
- refreshUserDetails: (oldCreds: LoginCredentials) => Promise<LoginCredentials>;
8
- refreshUserToken: (oldCreds: LoginCredentials) => Promise<LoginCredentials>;
7
+ refreshUserToken: (oldToken: string, mnemonic: string) => Promise<LoginCredentials>;
9
8
  logout: () => Promise<void>;
10
9
  }
@@ -25,8 +25,6 @@ class AuthService {
25
25
  return {
26
26
  user: clearUser,
27
27
  token: newToken,
28
- lastLoggedInAt: new Date().toISOString(),
29
- lastTokenRefreshAt: new Date().toISOString(),
30
28
  };
31
29
  };
32
30
  is2FANeeded = async (email) => {
@@ -51,38 +49,25 @@ class AuthService {
51
49
  }
52
50
  const refreshToken = tokenDetails.expiration.refreshRequired;
53
51
  if (refreshToken) {
54
- loginCreds = await this.refreshUserToken(loginCreds);
52
+ loginCreds = await this.refreshUserToken(loginCreds.token, loginCreds.user.mnemonic);
55
53
  }
56
54
  return loginCreds;
57
55
  };
58
- refreshUserDetails = async (oldCreds) => {
59
- sdk_manager_service_1.SdkManager.init({ token: oldCreds.token });
56
+ refreshUserToken = async (oldToken, mnemonic) => {
57
+ sdk_manager_service_1.SdkManager.init({ token: oldToken });
58
+ const isValidMnemonic = validation_service_1.ValidationService.instance.validateMnemonic(mnemonic);
59
+ if (!isValidMnemonic) {
60
+ throw new command_types_1.InvalidCredentialsError();
61
+ }
60
62
  const usersClient = sdk_manager_service_1.SdkManager.instance.getUsers();
61
- const newCreds = await usersClient.getUserData({ userUuid: oldCreds.user.uuid });
62
- const loginCreds = {
63
+ const newCreds = await usersClient.refreshUserCredentials();
64
+ sdk_manager_service_1.SdkManager.init({ token: newCreds.newToken });
65
+ const newLoginCreds = {
63
66
  user: {
64
67
  ...newCreds.user,
65
- mnemonic: oldCreds.user.mnemonic,
66
- createdAt: new Date(newCreds.user.createdAt).toISOString(),
68
+ mnemonic: mnemonic,
67
69
  },
68
70
  token: newCreds.newToken,
69
- lastLoggedInAt: oldCreds.lastLoggedInAt,
70
- lastTokenRefreshAt: new Date().toISOString(),
71
- };
72
- sdk_manager_service_1.SdkManager.init({ token: newCreds.newToken });
73
- await config_service_1.ConfigService.instance.saveUser(loginCreds);
74
- return loginCreds;
75
- };
76
- refreshUserToken = async (oldCreds) => {
77
- sdk_manager_service_1.SdkManager.init({ token: oldCreds.token });
78
- const usersClient = sdk_manager_service_1.SdkManager.instance.getUsers();
79
- const newCreds = await usersClient.refreshUser();
80
- sdk_manager_service_1.SdkManager.init({ token: newCreds.newToken });
81
- const newLoginCreds = {
82
- ...oldCreds,
83
- token: newCreds.newToken,
84
- lastLoggedInAt: oldCreds.lastLoggedInAt,
85
- lastTokenRefreshAt: new Date().toISOString(),
86
71
  };
87
72
  await config_service_1.ConfigService.instance.saveUser(newLoginCreds);
88
73
  return newLoginCreds;
@@ -104,7 +104,7 @@ class CryptoService {
104
104
  };
105
105
  getKeyAndIvFrom = (secret, salt) => {
106
106
  const TRANSFORM_ROUNDS = 3;
107
- const password = Buffer.concat([Buffer.from(secret, 'binary'), salt]);
107
+ const password = Buffer.concat([Buffer.from(secret, 'utf8'), salt]);
108
108
  const md5Hashes = [];
109
109
  let digest = password;
110
110
  for (let i = 0; i < TRANSFORM_ROUNDS; i++) {
@@ -58,6 +58,7 @@ class DriveFile {
58
58
  }
59
59
  toItem() {
60
60
  return {
61
+ itemType: 'file',
61
62
  id: this.id,
62
63
  name: this.name,
63
64
  type: this.type,
@@ -40,6 +40,7 @@ class DriveFolder {
40
40
  }
41
41
  toItem() {
42
42
  return {
43
+ itemType: 'folder',
43
44
  id: this.id,
44
45
  name: this.name,
45
46
  uuid: this.uuid,
@@ -9,6 +9,7 @@ class DriveFileService {
9
9
  const storageClient = sdk_manager_service_1.SdkManager.instance.getStorage();
10
10
  const driveFile = await storageClient.createFileEntryByUuid(payload);
11
11
  return {
12
+ itemType: 'file',
12
13
  name: payload.plainName,
13
14
  id: driveFile.id,
14
15
  uuid: driveFile.uuid,
@@ -30,7 +30,7 @@ export declare class DriveFolderService {
30
30
  files: {
31
31
  id: number;
32
32
  uuid: string;
33
- fileId: string;
33
+ fileId: string | null;
34
34
  name: string;
35
35
  type: string;
36
36
  size: string;
@@ -32,7 +32,7 @@ export declare class TrashService {
32
32
  files: {
33
33
  id: number;
34
34
  uuid: string;
35
- fileId: string;
35
+ fileId: string | null;
36
36
  name: string;
37
37
  type: string;
38
38
  size: string;
@@ -0,0 +1,6 @@
1
+ import { FileSystemNode, ScanResult } from './local-filesystem.types';
2
+ export declare class LocalFilesystemService {
3
+ static readonly instance: LocalFilesystemService;
4
+ scanLocalDirectory(path: string): Promise<ScanResult>;
5
+ scanRecursive(currentPath: string, parentPath: string, folders: FileSystemNode[], files: FileSystemNode[]): Promise<number>;
6
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LocalFilesystemService = void 0;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_path_1 = require("node:path");
6
+ const logger_utils_1 = require("../../utils/logger.utils");
7
+ class LocalFilesystemService {
8
+ static instance = new LocalFilesystemService();
9
+ async scanLocalDirectory(path) {
10
+ const folders = [];
11
+ const files = [];
12
+ const parentPath = (0, node_path_1.dirname)(path);
13
+ const totalBytes = await this.scanRecursive(path, parentPath, folders, files);
14
+ return {
15
+ folders,
16
+ files,
17
+ totalItems: folders.length + files.length,
18
+ totalBytes,
19
+ };
20
+ }
21
+ async scanRecursive(currentPath, parentPath, folders, files) {
22
+ try {
23
+ const stats = await node_fs_1.promises.stat(currentPath);
24
+ const relativePath = (0, node_path_1.relative)(parentPath, currentPath);
25
+ if (stats.isFile() && stats.size > 0) {
26
+ const fileInfo = (0, node_path_1.parse)(currentPath);
27
+ files.push({
28
+ type: 'file',
29
+ name: fileInfo.name,
30
+ absolutePath: currentPath,
31
+ relativePath,
32
+ size: stats.size,
33
+ });
34
+ return stats.size;
35
+ }
36
+ if (stats.isDirectory()) {
37
+ folders.push({
38
+ type: 'folder',
39
+ name: (0, node_path_1.basename)(currentPath),
40
+ absolutePath: currentPath,
41
+ relativePath,
42
+ size: 0,
43
+ });
44
+ const entries = await node_fs_1.promises.readdir(currentPath, { withFileTypes: true });
45
+ const validEntries = entries.filter((e) => !e.isSymbolicLink());
46
+ const bytesArray = await Promise.all(validEntries.map((e) => this.scanRecursive((0, node_path_1.join)(currentPath, e.name), parentPath, folders, files)));
47
+ return bytesArray.reduce((sum, bytes) => sum + bytes, 0);
48
+ }
49
+ return 0;
50
+ }
51
+ catch (error) {
52
+ logger_utils_1.logger.warn(`Error scanning path ${currentPath}: ${error.message} - skipping...`);
53
+ return 0;
54
+ }
55
+ }
56
+ }
57
+ exports.LocalFilesystemService = LocalFilesystemService;
@@ -0,0 +1,13 @@
1
+ export interface FileSystemNode {
2
+ type: 'file' | 'folder';
3
+ name: string;
4
+ size: number;
5
+ absolutePath: string;
6
+ relativePath: string;
7
+ }
8
+ export interface ScanResult {
9
+ folders: FileSystemNode[];
10
+ files: FileSystemNode[];
11
+ totalItems: number;
12
+ totalBytes: number;
13
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ import { UploadFolderParams } from './upload.types';
2
+ export declare class UploadFacade {
3
+ static readonly instance: UploadFacade;
4
+ uploadFolder({ localPath, destinationFolderUuid, loginUserDetails, jsonFlag, onProgress }: UploadFolderParams): Promise<{
5
+ totalBytes: number;
6
+ rootFolderId: string;
7
+ uploadTimeMs: number;
8
+ }>;
9
+ }