@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,9 +5,9 @@ export default class CreateFolder extends Command {
5
5
  static readonly aliases: never[];
6
6
  static readonly examples: string[];
7
7
  static readonly flags: {
8
- name: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
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>;
8
+ name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ id: 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,8 +5,8 @@ export default class DeletePermanentlyFile 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<{
@@ -5,8 +5,8 @@ export default class DeletePermanentlyFolder 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<{
@@ -6,10 +6,10 @@ export default class DownloadFile extends Command {
6
6
  static readonly aliases: string[];
7
7
  static readonly examples: string[];
8
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>;
9
+ id: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ directory: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ overwrite: import("@oclif/core/interfaces").BooleanFlag<boolean>;
12
+ 'non-interactive': import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
13
  };
14
14
  static readonly enableJsonFlag = true;
15
15
  run: () => Promise<{
@@ -22,5 +22,4 @@ export default class DownloadFile extends Command {
22
22
  private getDirectory;
23
23
  private getFileMetadata;
24
24
  private getDownloadPath;
25
- private prepareNetwork;
26
25
  }
@@ -6,19 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const core_1 = require("@oclif/core");
7
7
  const drive_file_service_1 = require("../services/drive/drive-file.service");
8
8
  const cli_utils_1 = require("../utils/cli.utils");
9
- const network_facade_service_1 = require("../services/network/network-facade.service");
10
9
  const auth_service_1 = require("../services/auth.service");
11
- const crypto_service_1 = require("../services/crypto.service");
12
- const download_service_1 = require("../services/network/download.service");
13
- const sdk_manager_service_1 = require("../services/sdk-manager.service");
14
10
  const node_fs_1 = require("node:fs");
15
11
  const promises_1 = __importDefault(require("node:fs/promises"));
16
12
  const node_path_1 = __importDefault(require("node:path"));
17
13
  const stream_utils_1 = require("../utils/stream.utils");
18
14
  const command_types_1 = require("../types/command.types");
19
15
  const validation_service_1 = require("../services/validation.service");
20
- const inxt_js_1 = require("@internxt/inxt-js");
21
- const config_service_1 = require("../services/config.service");
22
16
  class DownloadFile extends core_1.Command {
23
17
  static args = {};
24
18
  static description = 'Download and decrypts a file from Internxt Drive to a directory.' +
@@ -56,25 +50,33 @@ class DownloadFile extends core_1.Command {
56
50
  const fileUuid = await this.getFileUuid(flags['id'], nonInteractive);
57
51
  const driveFile = await this.getFileMetadata(fileUuid, flags['json']);
58
52
  const downloadPath = await this.getDownloadPath(downloadDirectory, driveFile, overwrite);
59
- const { user } = await auth_service_1.AuthService.instance.getAuthDetails();
60
- const networkFacade = await this.prepareNetwork(user, flags['json']);
61
- const fileWriteStream = (0, node_fs_1.createWriteStream)(downloadPath);
62
53
  const progressBar = cli_utils_1.CLIUtils.progress({
63
54
  format: 'Downloading file [{bar}] {percentage}%',
64
55
  linewrap: true,
65
56
  }, flags['json']);
66
57
  progressBar?.start(100, 0);
67
- const [executeDownload, abortable] = await networkFacade.downloadToStream(driveFile.bucket, user.mnemonic, driveFile.fileId, driveFile.size, stream_utils_1.StreamUtils.writeStreamToWritableStream(fileWriteStream), undefined, {
68
- abortController: new AbortController(),
69
- progressCallback: (progress) => {
70
- progressBar?.update(progress * 0.99);
71
- },
72
- });
73
- process.on('SIGINT', () => {
74
- abortable.abort('SIGINT received');
75
- process.exit(1);
76
- });
77
- await executeDownload;
58
+ if (driveFile.size === 0) {
59
+ await promises_1.default.writeFile(downloadPath, '');
60
+ }
61
+ else {
62
+ if (!driveFile.fileId) {
63
+ throw new command_types_1.NotValidFileIdError();
64
+ }
65
+ const { user } = await auth_service_1.AuthService.instance.getAuthDetails();
66
+ const networkFacade = cli_utils_1.CLIUtils.prepareNetwork({ loginUserDetails: user, jsonFlag: flags['json'] });
67
+ const fileWriteStream = (0, node_fs_1.createWriteStream)(downloadPath);
68
+ const [executeDownload, abortable] = await networkFacade.downloadToStream(driveFile.bucket, user.mnemonic, driveFile.fileId, driveFile.size, stream_utils_1.StreamUtils.writeStreamToWritableStream(fileWriteStream), undefined, {
69
+ abortController: new AbortController(),
70
+ progressCallback: (progress) => {
71
+ progressBar?.update(progress * 0.99);
72
+ },
73
+ });
74
+ process.on('SIGINT', () => {
75
+ abortable.abort('SIGINT received');
76
+ process.exit(1);
77
+ });
78
+ await executeDownload;
79
+ }
78
80
  try {
79
81
  await promises_1.default.utimes(downloadPath, new Date(), driveFile.modificationTime ?? driveFile.updatedAt);
80
82
  }
@@ -159,22 +161,5 @@ class DownloadFile extends core_1.Command {
159
161
  }
160
162
  return downloadPath;
161
163
  };
162
- prepareNetwork = async (user, jsonFlag) => {
163
- cli_utils_1.CLIUtils.doing('Preparing Network', jsonFlag);
164
- const networkModule = sdk_manager_service_1.SdkManager.instance.getNetwork({
165
- user: user.bridgeUser,
166
- pass: user.userId,
167
- });
168
- const environment = new inxt_js_1.Environment({
169
- bridgeUser: user.bridgeUser,
170
- bridgePass: user.userId,
171
- bridgeUrl: config_service_1.ConfigService.instance.get('NETWORK_URL'),
172
- encryptionKey: user.mnemonic,
173
- appDetails: sdk_manager_service_1.SdkManager.getAppDetails(),
174
- });
175
- const networkFacade = new network_facade_service_1.NetworkFacade(networkModule, environment, download_service_1.DownloadService.instance, crypto_service_1.CryptoService.instance);
176
- cli_utils_1.CLIUtils.done(jsonFlag);
177
- return networkFacade;
178
- };
179
164
  }
180
165
  exports.default = DownloadFile;
@@ -5,9 +5,9 @@ export default class List extends Command {
5
5
  static readonly aliases: never[];
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
- extended: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
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
+ extended: import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
+ 'non-interactive': import("@oclif/core/interfaces").BooleanFlag<boolean>;
11
11
  };
12
12
  static readonly enableJsonFlag = true;
13
13
  run: () => Promise<{
@@ -37,7 +37,7 @@ export default class List extends Command {
37
37
  files: {
38
38
  id: number;
39
39
  uuid: string;
40
- fileId: string;
40
+ fileId: string | null;
41
41
  name: string;
42
42
  type: string;
43
43
  size: string;
@@ -0,0 +1,24 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class LoginLegacy extends Command {
3
+ static readonly args: {};
4
+ static readonly description: string;
5
+ static readonly aliases: never[];
6
+ static readonly examples: string[];
7
+ static readonly flags: {
8
+ email: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ password: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ twofactor: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ twofactortoken: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ 'non-interactive': import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
+ };
14
+ static readonly enableJsonFlag = true;
15
+ run: () => Promise<{
16
+ success: boolean;
17
+ message: string;
18
+ login: import("../types/command.types").LoginCredentials;
19
+ }>;
20
+ catch: (error: Error) => Promise<never>;
21
+ private getEmail;
22
+ private getPassword;
23
+ private getTwoFactorCode;
24
+ }
@@ -0,0 +1,175 @@
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 () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const core_1 = require("@oclif/core");
37
+ const command_types_1 = require("../types/command.types");
38
+ const auth_service_1 = require("../services/auth.service");
39
+ const config_service_1 = require("../services/config.service");
40
+ const validation_service_1 = require("../services/validation.service");
41
+ const cli_utils_1 = require("../utils/cli.utils");
42
+ const sdk_manager_service_1 = require("../services/sdk-manager.service");
43
+ const OTPAuth = __importStar(require("otpauth"));
44
+ class LoginLegacy extends core_1.Command {
45
+ static args = {};
46
+ static description = '[Legacy] Logs into an Internxt account using user and password. ' +
47
+ 'If the account is two-factor protected, then an extra code will be required.';
48
+ static aliases = [];
49
+ static examples = ['<%= config.bin %> <%= command.id %>'];
50
+ static flags = {
51
+ ...cli_utils_1.CLIUtils.CommonFlags,
52
+ email: core_1.Flags.string({
53
+ char: 'e',
54
+ aliases: ['mail'],
55
+ env: 'INXT_USER',
56
+ description: 'The email to log in',
57
+ required: false,
58
+ }),
59
+ password: core_1.Flags.string({
60
+ char: 'p',
61
+ aliases: ['pass'],
62
+ env: 'INXT_PASSWORD',
63
+ description: 'The plain password to log in',
64
+ required: false,
65
+ }),
66
+ twofactor: core_1.Flags.string({
67
+ char: 'w',
68
+ aliases: ['two', 'two-factor'],
69
+ env: 'INXT_TWOFACTORCODE',
70
+ description: 'The two factor auth code (TOTP). ',
71
+ required: false,
72
+ helpValue: '123456',
73
+ }),
74
+ twofactortoken: core_1.Flags.string({
75
+ char: 't',
76
+ aliases: ['otp', 'otp-token'],
77
+ env: 'INXT_OTPTOKEN',
78
+ description: 'The TOTP secret token. It is used to generate a TOTP code if needed.' +
79
+ ' It has prority over the two factor code flag.',
80
+ required: false,
81
+ helpValue: 'token',
82
+ }),
83
+ };
84
+ static enableJsonFlag = true;
85
+ run = async () => {
86
+ const { flags } = await this.parse(LoginLegacy);
87
+ const nonInteractive = flags['non-interactive'];
88
+ const email = await this.getEmail(flags['email'], nonInteractive);
89
+ const password = await this.getPassword(flags['password'], nonInteractive);
90
+ const is2FANeeded = await auth_service_1.AuthService.instance.is2FANeeded(email);
91
+ let twoFactorCode;
92
+ if (is2FANeeded) {
93
+ const twoFactorToken = flags['twofactortoken'];
94
+ if (twoFactorToken && twoFactorToken.trim().length > 0) {
95
+ const totp = new OTPAuth.TOTP({
96
+ secret: twoFactorToken,
97
+ digits: 6,
98
+ });
99
+ twoFactorCode = totp.generate();
100
+ }
101
+ else {
102
+ twoFactorCode = await this.getTwoFactorCode(flags['twofactor'], nonInteractive);
103
+ }
104
+ }
105
+ const loginCredentials = await auth_service_1.AuthService.instance.doLogin(email, password, twoFactorCode);
106
+ sdk_manager_service_1.SdkManager.init({ token: loginCredentials.token });
107
+ await config_service_1.ConfigService.instance.saveUser(loginCredentials);
108
+ const message = `Succesfully logged in to: ${loginCredentials.user.email}`;
109
+ cli_utils_1.CLIUtils.success(this.log.bind(this), message);
110
+ return {
111
+ success: true,
112
+ message,
113
+ login: loginCredentials,
114
+ };
115
+ };
116
+ catch = async (error) => {
117
+ const { flags } = await this.parse(LoginLegacy);
118
+ cli_utils_1.CLIUtils.catchError({
119
+ error,
120
+ command: this.id,
121
+ logReporter: this.log.bind(this),
122
+ jsonFlag: flags['json'],
123
+ });
124
+ this.exit(1);
125
+ };
126
+ getEmail = async (emailFlag, nonInteractive) => {
127
+ const email = await cli_utils_1.CLIUtils.getValueFromFlag({
128
+ value: emailFlag,
129
+ name: LoginLegacy.flags['email'].name,
130
+ }, {
131
+ nonInteractive,
132
+ prompt: {
133
+ message: 'What is your email?',
134
+ options: { type: 'input' },
135
+ },
136
+ }, {
137
+ validate: validation_service_1.ValidationService.instance.validateEmail,
138
+ error: new command_types_1.NotValidEmailError(),
139
+ }, this.log.bind(this));
140
+ return email;
141
+ };
142
+ getPassword = async (passwordFlag, nonInteractive) => {
143
+ const password = await cli_utils_1.CLIUtils.getValueFromFlag({
144
+ value: passwordFlag,
145
+ name: LoginLegacy.flags['password'].name,
146
+ }, {
147
+ nonInteractive,
148
+ prompt: {
149
+ message: 'What is your password?',
150
+ options: { type: 'password' },
151
+ },
152
+ }, {
153
+ validate: validation_service_1.ValidationService.instance.validateStringIsNotEmpty,
154
+ error: new command_types_1.EmptyPasswordError(),
155
+ }, this.log.bind(this));
156
+ return password;
157
+ };
158
+ getTwoFactorCode = async (twoFactorFlag, nonInteractive) => {
159
+ const twoFactor = await cli_utils_1.CLIUtils.getValueFromFlag({
160
+ value: twoFactorFlag,
161
+ name: LoginLegacy.flags['twofactor'].name,
162
+ }, {
163
+ nonInteractive,
164
+ prompt: {
165
+ message: 'What is your two-factor code?',
166
+ options: { type: 'mask' },
167
+ },
168
+ }, {
169
+ validate: validation_service_1.ValidationService.instance.validate2FA,
170
+ error: new command_types_1.NotValidTwoFactorCodeError(),
171
+ }, this.log.bind(this));
172
+ return twoFactor;
173
+ };
174
+ }
175
+ exports.default = LoginLegacy;
@@ -1,15 +1,12 @@
1
1
  import { Command } from '@oclif/core';
2
2
  export default class Login extends Command {
3
3
  static readonly args: {};
4
- static readonly description = "Logs into an Internxt account. If the account is two-factor protected, then an extra code will be required.";
4
+ static readonly description: string;
5
5
  static readonly aliases: never[];
6
6
  static readonly examples: string[];
7
7
  static readonly flags: {
8
- email: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
9
- password: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
10
- twofactor: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
11
- twofactortoken: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
12
- 'non-interactive': 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<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
10
  };
14
11
  static readonly enableJsonFlag = true;
15
12
  run: () => Promise<{
@@ -18,7 +15,4 @@ export default class Login extends Command {
18
15
  login: import("../types/command.types").LoginCredentials;
19
16
  }>;
20
17
  catch: (error: Error) => Promise<never>;
21
- private getEmail;
22
- private getPassword;
23
- private getTwoFactorCode;
24
18
  }
@@ -1,107 +1,41 @@
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 () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
3
  const core_1 = require("@oclif/core");
37
- const command_types_1 = require("../types/command.types");
38
- const auth_service_1 = require("../services/auth.service");
39
4
  const config_service_1 = require("../services/config.service");
40
- const validation_service_1 = require("../services/validation.service");
41
5
  const cli_utils_1 = require("../utils/cli.utils");
42
6
  const sdk_manager_service_1 = require("../services/sdk-manager.service");
43
- const OTPAuth = __importStar(require("otpauth"));
7
+ const universal_link_service_1 = require("../services/universal-link.service");
44
8
  class Login extends core_1.Command {
45
9
  static args = {};
46
- static description = 'Logs into an Internxt account. If the account is two-factor protected, then an extra code will be required.';
10
+ static description = 'Logs into your Internxt account using the web-based login flow. ' +
11
+ 'A temporary local server is started to securely receive the authentication response.';
47
12
  static aliases = [];
48
13
  static examples = ['<%= config.bin %> <%= command.id %>'];
49
14
  static flags = {
50
- ...cli_utils_1.CLIUtils.CommonFlags,
51
- email: core_1.Flags.string({
52
- char: 'e',
53
- aliases: ['mail'],
54
- env: 'INXT_USER',
55
- description: 'The email to log in',
15
+ host: core_1.Flags.string({
16
+ char: 'h',
17
+ aliases: ['host'],
18
+ env: 'INXT_LOGIN_SERVER_HOST',
19
+ description: 'IP address of the machine where the CLI is running. ' +
20
+ 'If you are opening the login page in a browser on another device, ' +
21
+ 'set this to the IP address of the machine running the CLI. Defaults to 127.0.0.1.',
56
22
  required: false,
57
23
  }),
58
- password: core_1.Flags.string({
24
+ port: core_1.Flags.integer({
59
25
  char: 'p',
60
- aliases: ['pass'],
61
- env: 'INXT_PASSWORD',
62
- description: 'The plain password to log in',
63
- required: false,
64
- }),
65
- twofactor: core_1.Flags.string({
66
- char: 'w',
67
- aliases: ['two', 'two-factor'],
68
- env: 'INXT_TWOFACTORCODE',
69
- description: 'The two factor auth code (TOTP). ',
26
+ aliases: ['port'],
27
+ env: 'INXT_LOGIN_SERVER_PORT',
28
+ description: 'Port used by the temporary local server to handle the login callback. ' +
29
+ 'If not specified, a random available port will be used automatically.',
70
30
  required: false,
71
- helpValue: '123456',
72
- }),
73
- twofactortoken: core_1.Flags.string({
74
- char: 't',
75
- aliases: ['otp', 'otp-token'],
76
- env: 'INXT_OTPTOKEN',
77
- description: 'The TOTP secret token. It is used to generate a TOTP code if needed.' +
78
- ' It has prority over the two factor code flag.',
79
- required: false,
80
- helpValue: 'token',
81
31
  }),
82
32
  };
83
33
  static enableJsonFlag = true;
84
34
  run = async () => {
85
35
  const { flags } = await this.parse(Login);
86
- const nonInteractive = flags['non-interactive'];
87
- const email = await this.getEmail(flags['email'], nonInteractive);
88
- const password = await this.getPassword(flags['password'], nonInteractive);
89
- const is2FANeeded = await auth_service_1.AuthService.instance.is2FANeeded(email);
90
- let twoFactorCode;
91
- if (is2FANeeded) {
92
- const twoFactorToken = flags['twofactortoken'];
93
- if (twoFactorToken && twoFactorToken.trim().length > 0) {
94
- const totp = new OTPAuth.TOTP({
95
- secret: twoFactorToken,
96
- digits: 6,
97
- });
98
- twoFactorCode = totp.generate();
99
- }
100
- else {
101
- twoFactorCode = await this.getTwoFactorCode(flags['twofactor'], nonInteractive);
102
- }
103
- }
104
- const loginCredentials = await auth_service_1.AuthService.instance.doLogin(email, password, twoFactorCode);
36
+ const host = flags['host'];
37
+ const port = flags['port'];
38
+ const loginCredentials = await universal_link_service_1.UniversalLinkService.instance.loginSSO(flags['json'] ?? false, this.log.bind(this), host, port);
105
39
  sdk_manager_service_1.SdkManager.init({ token: loginCredentials.token });
106
40
  await config_service_1.ConfigService.instance.saveUser(loginCredentials);
107
41
  const message = `Succesfully logged in to: ${loginCredentials.user.email}`;
@@ -122,53 +56,5 @@ class Login extends core_1.Command {
122
56
  });
123
57
  this.exit(1);
124
58
  };
125
- getEmail = async (emailFlag, nonInteractive) => {
126
- const email = await cli_utils_1.CLIUtils.getValueFromFlag({
127
- value: emailFlag,
128
- name: Login.flags['email'].name,
129
- }, {
130
- nonInteractive,
131
- prompt: {
132
- message: 'What is your email?',
133
- options: { type: 'input' },
134
- },
135
- }, {
136
- validate: validation_service_1.ValidationService.instance.validateEmail,
137
- error: new command_types_1.NotValidEmailError(),
138
- }, this.log.bind(this));
139
- return email;
140
- };
141
- getPassword = async (passwordFlag, nonInteractive) => {
142
- const password = await cli_utils_1.CLIUtils.getValueFromFlag({
143
- value: passwordFlag,
144
- name: Login.flags['password'].name,
145
- }, {
146
- nonInteractive,
147
- prompt: {
148
- message: 'What is your password?',
149
- options: { type: 'password' },
150
- },
151
- }, {
152
- validate: validation_service_1.ValidationService.instance.validateStringIsNotEmpty,
153
- error: new command_types_1.EmptyPasswordError(),
154
- }, this.log.bind(this));
155
- return password;
156
- };
157
- getTwoFactorCode = async (twoFactorFlag, nonInteractive) => {
158
- const twoFactor = await cli_utils_1.CLIUtils.getValueFromFlag({
159
- value: twoFactorFlag,
160
- name: Login.flags['twofactor'].name,
161
- }, {
162
- nonInteractive,
163
- prompt: {
164
- message: 'What is your two-factor code?',
165
- options: { type: 'mask' },
166
- },
167
- }, {
168
- validate: validation_service_1.ValidationService.instance.validate2FA,
169
- error: new command_types_1.NotValidTwoFactorCodeError(),
170
- }, this.log.bind(this));
171
- return twoFactor;
172
- };
173
59
  }
174
60
  exports.default = Login;
@@ -5,9 +5,9 @@ export default class MoveFile 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 MoveFile 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 MoveFolder 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 RenameFile 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
- name: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
10
- 'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
8
+ id: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ name: 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 RenameFolder 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
- name: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
10
- 'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
8
+ id: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ name: 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<{