@internxt/cli 0.1.4
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.
- package/.env +11 -0
- package/README.md +297 -0
- package/bin/dev.cmd +3 -0
- package/bin/dev.js +7 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +7 -0
- package/dist/commands/config.d.ts +18 -0
- package/dist/commands/config.js +50 -0
- package/dist/commands/download.d.ts +19 -0
- package/dist/commands/download.js +119 -0
- package/dist/commands/list.d.ts +22 -0
- package/dist/commands/list.js +125 -0
- package/dist/commands/login.d.ts +21 -0
- package/dist/commands/login.js +124 -0
- package/dist/commands/logout.d.ts +9 -0
- package/dist/commands/logout.js +28 -0
- package/dist/commands/logs.d.ts +6 -0
- package/dist/commands/logs.js +12 -0
- package/dist/commands/move.d.ts +18 -0
- package/dist/commands/move.js +109 -0
- package/dist/commands/trash.d.ts +15 -0
- package/dist/commands/trash.js +85 -0
- package/dist/commands/upload.d.ts +15 -0
- package/dist/commands/upload.js +93 -0
- package/dist/commands/webdav.d.ts +12 -0
- package/dist/commands/webdav.js +64 -0
- package/dist/commands/whoami.d.ts +9 -0
- package/dist/commands/whoami.js +27 -0
- package/dist/database/migrations/20240402164914-create-files.d.ts +1 -0
- package/dist/database/migrations/20240402164914-create-files.js +55 -0
- package/dist/database/migrations/20240402165418-create-folders.d.ts +1 -0
- package/dist/database/migrations/20240402165418-create-folders.js +37 -0
- package/dist/hooks/prerun/auth_check.d.ts +3 -0
- package/dist/hooks/prerun/auth_check.js +32 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/dist/services/auth.service.d.ts +14 -0
- package/dist/services/auth.service.js +79 -0
- package/dist/services/config.service.d.ts +19 -0
- package/dist/services/config.service.js +79 -0
- package/dist/services/crypto.service.d.ts +22 -0
- package/dist/services/crypto.service.js +126 -0
- package/dist/services/database/drive-database-manager.service.d.ts +18 -0
- package/dist/services/database/drive-database-manager.service.js +76 -0
- package/dist/services/database/drive-file/drive-file.attributes.d.ts +14 -0
- package/dist/services/database/drive-file/drive-file.attributes.js +2 -0
- package/dist/services/database/drive-file/drive-file.domain.d.ts +18 -0
- package/dist/services/database/drive-file/drive-file.domain.js +51 -0
- package/dist/services/database/drive-file/drive-file.model.d.ts +17 -0
- package/dist/services/database/drive-file/drive-file.model.js +82 -0
- package/dist/services/database/drive-file/drive-file.repository.d.ts +11 -0
- package/dist/services/database/drive-file/drive-file.repository.js +40 -0
- package/dist/services/database/drive-folder/drive-folder.attributes.d.ts +9 -0
- package/dist/services/database/drive-folder/drive-folder.attributes.js +2 -0
- package/dist/services/database/drive-folder/drive-folder.domain.d.ts +13 -0
- package/dist/services/database/drive-folder/drive-folder.domain.js +36 -0
- package/dist/services/database/drive-folder/drive-folder.model.d.ts +12 -0
- package/dist/services/database/drive-folder/drive-folder.model.js +56 -0
- package/dist/services/database/drive-folder/drive-folder.repository.d.ts +11 -0
- package/dist/services/database/drive-folder/drive-folder.repository.js +40 -0
- package/dist/services/drive/drive-file.service.d.ts +15 -0
- package/dist/services/drive/drive-file.service.js +51 -0
- package/dist/services/drive/drive-folder.service.d.ts +15 -0
- package/dist/services/drive/drive-folder.service.js +49 -0
- package/dist/services/drive/trash.service.d.ts +5 -0
- package/dist/services/drive/trash.service.js +12 -0
- package/dist/services/keys.service.d.ts +14 -0
- package/dist/services/keys.service.js +110 -0
- package/dist/services/network/download.service.d.ts +7 -0
- package/dist/services/network/download.service.js +33 -0
- package/dist/services/network/network-facade.service.d.ts +21 -0
- package/dist/services/network/network-facade.service.js +128 -0
- package/dist/services/network/upload.service.d.ts +9 -0
- package/dist/services/network/upload.service.js +20 -0
- package/dist/services/realms/drive-files.realm.d.ts +23 -0
- package/dist/services/realms/drive-files.realm.js +76 -0
- package/dist/services/realms/drive-folders.realm.d.ts +20 -0
- package/dist/services/realms/drive-folders.realm.js +68 -0
- package/dist/services/realms/drive-realm-manager.service.d.ts +15 -0
- package/dist/services/realms/drive-realm-manager.service.js +63 -0
- package/dist/services/sdk-manager.service.d.ts +28 -0
- package/dist/services/sdk-manager.service.js +107 -0
- package/dist/services/usage.service.d.ts +6 -0
- package/dist/services/usage.service.js +23 -0
- package/dist/services/validation.service.d.ts +7 -0
- package/dist/services/validation.service.js +21 -0
- package/dist/types/command.types.d.ts +42 -0
- package/dist/types/command.types.js +59 -0
- package/dist/types/config.types.d.ts +13 -0
- package/dist/types/config.types.js +2 -0
- package/dist/types/drive.types.d.ts +14 -0
- package/dist/types/drive.types.js +2 -0
- package/dist/types/keys.types.d.ts +16 -0
- package/dist/types/keys.types.js +31 -0
- package/dist/types/network.types.d.ts +11 -0
- package/dist/types/network.types.js +2 -0
- package/dist/types/webdav.types.d.ts +15 -0
- package/dist/types/webdav.types.js +6 -0
- package/dist/utils/cli.utils.d.ts +32 -0
- package/dist/utils/cli.utils.js +105 -0
- package/dist/utils/crypto.utils.d.ts +6 -0
- package/dist/utils/crypto.utils.js +10 -0
- package/dist/utils/drive.utils.d.ts +6 -0
- package/dist/utils/drive.utils.js +34 -0
- package/dist/utils/errors.utils.d.ts +19 -0
- package/dist/utils/errors.utils.js +50 -0
- package/dist/utils/format.utils.d.ts +6 -0
- package/dist/utils/format.utils.js +30 -0
- package/dist/utils/hash.utils.d.ts +15 -0
- package/dist/utils/hash.utils.js +37 -0
- package/dist/utils/logger.utils.d.ts +3 -0
- package/dist/utils/logger.utils.js +50 -0
- package/dist/utils/network.utils.d.ts +22 -0
- package/dist/utils/network.utils.js +49 -0
- package/dist/utils/pm2.utils.d.ts +10 -0
- package/dist/utils/pm2.utils.js +65 -0
- package/dist/utils/stream.utils.d.ts +7 -0
- package/dist/utils/stream.utils.js +56 -0
- package/dist/utils/webdav.utils.d.ts +7 -0
- package/dist/utils/webdav.utils.js +47 -0
- package/dist/utils/xml.utils.d.ts +8 -0
- package/dist/utils/xml.utils.js +23 -0
- package/dist/webdav/handlers/GET.handler.d.ts +23 -0
- package/dist/webdav/handlers/GET.handler.js +52 -0
- package/dist/webdav/handlers/HEAD.handler.d.ts +5 -0
- package/dist/webdav/handlers/HEAD.handler.js +9 -0
- package/dist/webdav/handlers/OPTIONS.handler.d.ts +5 -0
- package/dist/webdav/handlers/OPTIONS.handler.js +11 -0
- package/dist/webdav/handlers/PROPFIND.handler.d.ts +21 -0
- package/dist/webdav/handlers/PROPFIND.handler.js +234 -0
- package/dist/webdav/handlers/PUT.handler.d.ts +23 -0
- package/dist/webdav/handlers/PUT.handler.js +51 -0
- package/dist/webdav/index.d.ts +1 -0
- package/dist/webdav/index.js +30 -0
- package/dist/webdav/middewares/auth.middleware.d.ts +3 -0
- package/dist/webdav/middewares/auth.middleware.js +27 -0
- package/dist/webdav/middewares/errors.middleware.d.ts +2 -0
- package/dist/webdav/middewares/errors.middleware.js +20 -0
- package/dist/webdav/middewares/request-logger.middleware.d.ts +7 -0
- package/dist/webdav/middewares/request-logger.middleware.js +15 -0
- package/dist/webdav/webdav-server.d.ts +25 -0
- package/dist/webdav/webdav-server.js +98 -0
- package/oclif.manifest.json +593 -0
- package/package.json +122 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
|
+
const config_service_1 = require("../services/config.service");
|
|
5
|
+
const drive_folder_service_1 = require("../services/drive/drive-folder.service");
|
|
6
|
+
const cli_utils_1 = require("../utils/cli.utils");
|
|
7
|
+
const command_types_1 = require("../types/command.types");
|
|
8
|
+
const validation_service_1 = require("../services/validation.service");
|
|
9
|
+
const format_utils_1 = require("../utils/format.utils");
|
|
10
|
+
const errors_utils_1 = require("../utils/errors.utils");
|
|
11
|
+
class List extends core_1.Command {
|
|
12
|
+
static args = {};
|
|
13
|
+
static description = 'Lists the content of a folder id.';
|
|
14
|
+
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
15
|
+
static flags = {
|
|
16
|
+
...cli_utils_1.CLIUtils.CommonFlags,
|
|
17
|
+
id: core_1.Flags.string({
|
|
18
|
+
char: 'f',
|
|
19
|
+
description: 'The folder id to list. Leave empty for the root folder.',
|
|
20
|
+
required: false,
|
|
21
|
+
parse: cli_utils_1.CLIUtils.parseEmpty,
|
|
22
|
+
}),
|
|
23
|
+
...core_1.ux.table.flags(),
|
|
24
|
+
};
|
|
25
|
+
async run() {
|
|
26
|
+
const { flags } = await this.parse(List);
|
|
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
|
+
let folderUuid = await this.getFolderUuid(flags['id'], nonInteractive);
|
|
32
|
+
if (folderUuid.trim().length === 0) {
|
|
33
|
+
folderUuid = userCredentials.root_folder_uuid;
|
|
34
|
+
}
|
|
35
|
+
const { folders, files } = await drive_folder_service_1.DriveFolderService.instance.getFolderContent(folderUuid);
|
|
36
|
+
const allItems = [
|
|
37
|
+
...folders.map((folder) => {
|
|
38
|
+
return {
|
|
39
|
+
isFolder: true,
|
|
40
|
+
plainName: folder.plainName,
|
|
41
|
+
uuid: folder.uuid,
|
|
42
|
+
type: '',
|
|
43
|
+
size: BigInt(0),
|
|
44
|
+
updatedAt: folder.updatedAt,
|
|
45
|
+
};
|
|
46
|
+
}),
|
|
47
|
+
...files.map((file) => {
|
|
48
|
+
return {
|
|
49
|
+
isFolder: false,
|
|
50
|
+
plainName: file.plainName,
|
|
51
|
+
uuid: file.uuid,
|
|
52
|
+
type: file.type,
|
|
53
|
+
size: file.size,
|
|
54
|
+
updatedAt: file.updatedAt,
|
|
55
|
+
};
|
|
56
|
+
}),
|
|
57
|
+
];
|
|
58
|
+
core_1.ux.table(allItems, {
|
|
59
|
+
type: {
|
|
60
|
+
header: 'Type',
|
|
61
|
+
get: (row) => (row.isFolder ? 'folder' : 'file'),
|
|
62
|
+
},
|
|
63
|
+
name: {
|
|
64
|
+
header: 'Name',
|
|
65
|
+
get: (row) => (row.isFolder ? row.plainName : `${row.plainName}.${row.type}`),
|
|
66
|
+
},
|
|
67
|
+
updatedAt: {
|
|
68
|
+
header: 'Modified',
|
|
69
|
+
get: (row) => {
|
|
70
|
+
if (flags.output) {
|
|
71
|
+
return row.updatedAt;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return format_utils_1.FormatUtils.formatDate(row.updatedAt);
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
extended: true,
|
|
78
|
+
},
|
|
79
|
+
size: {
|
|
80
|
+
header: 'Size',
|
|
81
|
+
get: (row) => {
|
|
82
|
+
if (flags.output) {
|
|
83
|
+
return row.isFolder ? '0' : row.size;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return row.isFolder ? '' : format_utils_1.FormatUtils.humanFileSize(Number(row.size));
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
extended: true,
|
|
90
|
+
},
|
|
91
|
+
uuid: {
|
|
92
|
+
header: 'ID',
|
|
93
|
+
get: (row) => row.uuid,
|
|
94
|
+
},
|
|
95
|
+
}, {
|
|
96
|
+
printLine: this.log.bind(this),
|
|
97
|
+
...flags,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
async catch(error) {
|
|
101
|
+
errors_utils_1.ErrorUtils.report(error, { command: this.id });
|
|
102
|
+
cli_utils_1.CLIUtils.error(error.message);
|
|
103
|
+
this.exit(1);
|
|
104
|
+
}
|
|
105
|
+
getFolderUuid = async (folderUuidFlag, nonInteractive) => {
|
|
106
|
+
let folderUuid = cli_utils_1.CLIUtils.getValueFromFlag({
|
|
107
|
+
value: folderUuidFlag,
|
|
108
|
+
name: List.flags['id'].name,
|
|
109
|
+
error: new command_types_1.NotValidFolderUuidError(),
|
|
110
|
+
canBeEmpty: true,
|
|
111
|
+
}, nonInteractive, (folderUuid) => validation_service_1.ValidationService.instance.validateUUIDv4(folderUuid));
|
|
112
|
+
if (!folderUuid && folderUuid !== '') {
|
|
113
|
+
folderUuid = (await this.getFolderUuidInteractively()).trim();
|
|
114
|
+
}
|
|
115
|
+
return folderUuid;
|
|
116
|
+
};
|
|
117
|
+
getFolderUuidInteractively = () => {
|
|
118
|
+
return cli_utils_1.CLIUtils.prompt({
|
|
119
|
+
message: 'What is the folder id you want to list? (leave empty for the root folder)',
|
|
120
|
+
options: { required: false },
|
|
121
|
+
error: new command_types_1.NotValidFolderUuidError(),
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
exports.default = List;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class Login extends Command {
|
|
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.";
|
|
5
|
+
static readonly examples: string[];
|
|
6
|
+
static readonly flags: {
|
|
7
|
+
email: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
8
|
+
password: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
9
|
+
twofactor: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
10
|
+
'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
11
|
+
};
|
|
12
|
+
run(): Promise<void>;
|
|
13
|
+
catch(error: Error): Promise<void>;
|
|
14
|
+
getEmail: (emailFlag: string | undefined, nonInteractive: boolean) => Promise<string>;
|
|
15
|
+
getPassword: (passwordFlag: string | undefined, nonInteractive: boolean) => Promise<string>;
|
|
16
|
+
getTwoFactorCode: (twoFactorFlag: string | undefined, nonInteractive: boolean) => Promise<string>;
|
|
17
|
+
private static readonly MAX_ATTEMPTS;
|
|
18
|
+
getEmailInteractively: () => Promise<string>;
|
|
19
|
+
getPasswordInteractively: () => Promise<string>;
|
|
20
|
+
getTwoFactorCodeInteractively: () => Promise<string>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
|
+
const command_types_1 = require("../types/command.types");
|
|
5
|
+
const auth_service_1 = require("../services/auth.service");
|
|
6
|
+
const config_service_1 = require("../services/config.service");
|
|
7
|
+
const validation_service_1 = require("../services/validation.service");
|
|
8
|
+
const cli_utils_1 = require("../utils/cli.utils");
|
|
9
|
+
const errors_utils_1 = require("../utils/errors.utils");
|
|
10
|
+
const drive_folder_service_1 = require("../services/drive/drive-folder.service");
|
|
11
|
+
const sdk_manager_service_1 = require("../services/sdk-manager.service");
|
|
12
|
+
const drive_database_manager_service_1 = require("../services/database/drive-database-manager.service");
|
|
13
|
+
class Login extends core_1.Command {
|
|
14
|
+
static args = {};
|
|
15
|
+
static description = 'Logs into an Internxt account. If the account is two-factor protected, then an extra code will be required.';
|
|
16
|
+
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
17
|
+
static flags = {
|
|
18
|
+
...cli_utils_1.CLIUtils.CommonFlags,
|
|
19
|
+
email: core_1.Flags.string({
|
|
20
|
+
char: 'e',
|
|
21
|
+
aliases: ['mail'],
|
|
22
|
+
env: 'INXT_EMAIL',
|
|
23
|
+
description: 'The email to log in',
|
|
24
|
+
required: false,
|
|
25
|
+
}),
|
|
26
|
+
password: core_1.Flags.string({
|
|
27
|
+
char: 'p',
|
|
28
|
+
aliases: ['pass'],
|
|
29
|
+
env: 'INXT_PASSWORD',
|
|
30
|
+
description: 'The plain password to log in',
|
|
31
|
+
required: false,
|
|
32
|
+
}),
|
|
33
|
+
twofactor: core_1.Flags.string({
|
|
34
|
+
char: 'w',
|
|
35
|
+
aliases: ['two', 'two-factor'],
|
|
36
|
+
env: 'INXT_TWOFACTORCODE',
|
|
37
|
+
description: 'The two factor auth code (only needed if the account is two-factor protected)',
|
|
38
|
+
required: false,
|
|
39
|
+
helpValue: '123456',
|
|
40
|
+
}),
|
|
41
|
+
};
|
|
42
|
+
async run() {
|
|
43
|
+
const { flags } = await this.parse(Login);
|
|
44
|
+
const nonInteractive = flags['non-interactive'];
|
|
45
|
+
const email = await this.getEmail(flags['email'], nonInteractive);
|
|
46
|
+
const password = await this.getPassword(flags['password'], nonInteractive);
|
|
47
|
+
const is2FANeeded = await auth_service_1.AuthService.instance.is2FANeeded(email);
|
|
48
|
+
let twoFactorCode;
|
|
49
|
+
if (is2FANeeded) {
|
|
50
|
+
twoFactorCode = await this.getTwoFactorCode(flags['twofactor'], nonInteractive);
|
|
51
|
+
}
|
|
52
|
+
const loginCredentials = await auth_service_1.AuthService.instance.doLogin(email, password, twoFactorCode);
|
|
53
|
+
sdk_manager_service_1.SdkManager.init({
|
|
54
|
+
token: loginCredentials.token,
|
|
55
|
+
newToken: loginCredentials.newToken,
|
|
56
|
+
});
|
|
57
|
+
const rootMeta = await drive_folder_service_1.DriveFolderService.instance.getFolderMetaById(loginCredentials.user.root_folder_id);
|
|
58
|
+
await config_service_1.ConfigService.instance.saveUser(Object.assign(loginCredentials, { root_folder_uuid: rootMeta.uuid }));
|
|
59
|
+
await drive_database_manager_service_1.DriveDatabaseManager.init();
|
|
60
|
+
await drive_database_manager_service_1.DriveDatabaseManager.clean();
|
|
61
|
+
cli_utils_1.CLIUtils.success(`Succesfully logged in to: ${loginCredentials.user.email} `);
|
|
62
|
+
}
|
|
63
|
+
async catch(error) {
|
|
64
|
+
errors_utils_1.ErrorUtils.report(error, { command: this.id });
|
|
65
|
+
cli_utils_1.CLIUtils.error(error.message);
|
|
66
|
+
this.exit(1);
|
|
67
|
+
}
|
|
68
|
+
getEmail = async (emailFlag, nonInteractive) => {
|
|
69
|
+
let email = cli_utils_1.CLIUtils.getValueFromFlag({
|
|
70
|
+
value: emailFlag,
|
|
71
|
+
name: Login.flags['email'].name,
|
|
72
|
+
error: new command_types_1.NotValidEmailError(),
|
|
73
|
+
}, nonInteractive, validation_service_1.ValidationService.instance.validateEmail);
|
|
74
|
+
if (!email) {
|
|
75
|
+
email = await this.getEmailInteractively();
|
|
76
|
+
}
|
|
77
|
+
return email;
|
|
78
|
+
};
|
|
79
|
+
getPassword = async (passwordFlag, nonInteractive) => {
|
|
80
|
+
let password = cli_utils_1.CLIUtils.getValueFromFlag({
|
|
81
|
+
value: passwordFlag,
|
|
82
|
+
name: Login.flags['password'].name,
|
|
83
|
+
error: new command_types_1.EmptyPasswordError(),
|
|
84
|
+
}, nonInteractive, (password) => password.trim().length > 0);
|
|
85
|
+
if (!password) {
|
|
86
|
+
password = await this.getPasswordInteractively();
|
|
87
|
+
}
|
|
88
|
+
return password;
|
|
89
|
+
};
|
|
90
|
+
getTwoFactorCode = async (twoFactorFlag, nonInteractive) => {
|
|
91
|
+
let twoFactor = cli_utils_1.CLIUtils.getValueFromFlag({
|
|
92
|
+
value: twoFactorFlag,
|
|
93
|
+
name: Login.flags['twofactor'].name,
|
|
94
|
+
error: new command_types_1.NotValidTwoFactorCodeError(),
|
|
95
|
+
}, nonInteractive, validation_service_1.ValidationService.instance.validate2FA);
|
|
96
|
+
if (!twoFactor) {
|
|
97
|
+
twoFactor = await this.getTwoFactorCodeInteractively();
|
|
98
|
+
}
|
|
99
|
+
return twoFactor;
|
|
100
|
+
};
|
|
101
|
+
static MAX_ATTEMPTS = 3;
|
|
102
|
+
getEmailInteractively = () => {
|
|
103
|
+
return cli_utils_1.CLIUtils.promptWithAttempts({
|
|
104
|
+
message: 'What is your email?',
|
|
105
|
+
options: { required: true },
|
|
106
|
+
error: new command_types_1.NotValidEmailError(),
|
|
107
|
+
}, Login.MAX_ATTEMPTS, validation_service_1.ValidationService.instance.validateEmail);
|
|
108
|
+
};
|
|
109
|
+
getPasswordInteractively = () => {
|
|
110
|
+
return cli_utils_1.CLIUtils.promptWithAttempts({
|
|
111
|
+
message: 'What is your password?',
|
|
112
|
+
options: { type: 'hide', required: true },
|
|
113
|
+
error: new command_types_1.EmptyPasswordError(),
|
|
114
|
+
}, Login.MAX_ATTEMPTS, (password) => password.trim().length > 0);
|
|
115
|
+
};
|
|
116
|
+
getTwoFactorCodeInteractively = () => {
|
|
117
|
+
return cli_utils_1.CLIUtils.promptWithAttempts({
|
|
118
|
+
message: 'What is your two-factor token?',
|
|
119
|
+
options: { type: 'mask', required: true },
|
|
120
|
+
error: new command_types_1.NotValidTwoFactorCodeError(),
|
|
121
|
+
}, Login.MAX_ATTEMPTS, validation_service_1.ValidationService.instance.validate2FA);
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
exports.default = Login;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class Logout extends Command {
|
|
3
|
+
static readonly args: {};
|
|
4
|
+
static readonly description = "Logs out the current internxt user that is logged into the Internxt CLI.";
|
|
5
|
+
static readonly examples: string[];
|
|
6
|
+
static readonly flags: {};
|
|
7
|
+
run(): Promise<void>;
|
|
8
|
+
catch(error: Error): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 errors_utils_1 = require("../utils/errors.utils");
|
|
7
|
+
class Logout extends core_1.Command {
|
|
8
|
+
static args = {};
|
|
9
|
+
static description = 'Logs out the current internxt user that is logged into the Internxt CLI.';
|
|
10
|
+
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
11
|
+
static flags = {};
|
|
12
|
+
async run() {
|
|
13
|
+
const user = await config_service_1.ConfigService.instance.readUser();
|
|
14
|
+
if (user) {
|
|
15
|
+
await config_service_1.ConfigService.instance.clearUser();
|
|
16
|
+
cli_utils_1.CLIUtils.success('User logged out correctly');
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
cli_utils_1.CLIUtils.error('You are not logged in');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async catch(error) {
|
|
23
|
+
errors_utils_1.ErrorUtils.report(error, { command: this.id });
|
|
24
|
+
cli_utils_1.CLIUtils.error(error.message);
|
|
25
|
+
this.exit(1);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.default = Logout;
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
class Logs extends core_1.Command {
|
|
6
|
+
static description = 'Displays the Internxt CLI logs directory path';
|
|
7
|
+
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
8
|
+
async run() {
|
|
9
|
+
this.log(`Internxt CLI logs are at ${config_service_1.ConfigService.INTERNXT_CLI_LOGS_DIR}`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.default = Logs;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class Move extends Command {
|
|
3
|
+
static readonly args: {};
|
|
4
|
+
static readonly description = "Move a folder/file into a destination folder.";
|
|
5
|
+
static readonly examples: string[];
|
|
6
|
+
static readonly flags: {
|
|
7
|
+
id: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
8
|
+
destination: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
9
|
+
'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
10
|
+
};
|
|
11
|
+
run(): Promise<void>;
|
|
12
|
+
catch(error: Error): Promise<void>;
|
|
13
|
+
getItemUuid: (itemUuidFlag: string | undefined, nonInteractive: boolean) => Promise<string>;
|
|
14
|
+
getDestinationFolderUuid: (destinationFolderUuidFlag: string | undefined, nonInteractive: boolean) => Promise<string>;
|
|
15
|
+
private static readonly MAX_ATTEMPTS;
|
|
16
|
+
getItemUuidInteractively: () => Promise<string>;
|
|
17
|
+
getDestinationFolderUuidInteractively: () => Promise<string>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
|
+
const config_service_1 = require("../services/config.service");
|
|
5
|
+
const drive_folder_service_1 = require("../services/drive/drive-folder.service");
|
|
6
|
+
const cli_utils_1 = require("../utils/cli.utils");
|
|
7
|
+
const command_types_1 = require("../types/command.types");
|
|
8
|
+
const validation_service_1 = require("../services/validation.service");
|
|
9
|
+
const drive_file_service_1 = require("../services/drive/drive-file.service");
|
|
10
|
+
const errors_utils_1 = require("../utils/errors.utils");
|
|
11
|
+
class Move extends core_1.Command {
|
|
12
|
+
static args = {};
|
|
13
|
+
static description = 'Move a folder/file into a destination folder.';
|
|
14
|
+
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
15
|
+
static flags = {
|
|
16
|
+
...cli_utils_1.CLIUtils.CommonFlags,
|
|
17
|
+
id: core_1.Flags.string({
|
|
18
|
+
char: 'i',
|
|
19
|
+
description: 'The item id to be moved (it can be a file id or a folder id).',
|
|
20
|
+
required: false,
|
|
21
|
+
}),
|
|
22
|
+
destination: core_1.Flags.string({
|
|
23
|
+
char: 'd',
|
|
24
|
+
description: 'The destination folder id where the item is going to be moved.',
|
|
25
|
+
required: false,
|
|
26
|
+
}),
|
|
27
|
+
};
|
|
28
|
+
async run() {
|
|
29
|
+
const { flags } = await this.parse(Move);
|
|
30
|
+
const nonInteractive = flags['non-interactive'];
|
|
31
|
+
const userCredentials = await config_service_1.ConfigService.instance.readUser();
|
|
32
|
+
if (!userCredentials)
|
|
33
|
+
throw new command_types_1.MissingCredentialsError();
|
|
34
|
+
const itemUuid = await this.getItemUuid(flags['id'], nonInteractive);
|
|
35
|
+
const destinationFolderUuid = await this.getDestinationFolderUuid(flags['destination'], nonInteractive);
|
|
36
|
+
let item;
|
|
37
|
+
let isFolder = false;
|
|
38
|
+
try {
|
|
39
|
+
if (!item) {
|
|
40
|
+
item = await drive_file_service_1.DriveFileService.instance.getFileMetadata(itemUuid);
|
|
41
|
+
isFolder = false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
if (!item) {
|
|
48
|
+
item = await drive_folder_service_1.DriveFolderService.instance.getFolderMetaByUuid(itemUuid);
|
|
49
|
+
isFolder = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
}
|
|
54
|
+
if (!item)
|
|
55
|
+
throw new command_types_1.ItemNotFoundError();
|
|
56
|
+
if (isFolder) {
|
|
57
|
+
await drive_folder_service_1.DriveFolderService.instance.moveFolder({ folderUuid: item.uuid, destinationFolderUuid });
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
await drive_file_service_1.DriveFileService.instance.moveFile({ fileUuid: item.uuid, destinationFolderUuid });
|
|
61
|
+
}
|
|
62
|
+
cli_utils_1.CLIUtils.success(`${isFolder ? 'Folder' : 'File'} moved successfully to: ${destinationFolderUuid}`);
|
|
63
|
+
}
|
|
64
|
+
async catch(error) {
|
|
65
|
+
errors_utils_1.ErrorUtils.report(error, { command: this.id });
|
|
66
|
+
cli_utils_1.CLIUtils.error(error.message);
|
|
67
|
+
this.exit(1);
|
|
68
|
+
}
|
|
69
|
+
getItemUuid = async (itemUuidFlag, nonInteractive) => {
|
|
70
|
+
let itemUuid = cli_utils_1.CLIUtils.getValueFromFlag({
|
|
71
|
+
value: itemUuidFlag,
|
|
72
|
+
name: Move.flags['id'].name,
|
|
73
|
+
error: new command_types_1.NotValidItemUuidError(),
|
|
74
|
+
canBeEmpty: true,
|
|
75
|
+
}, nonInteractive, (itemUuid) => validation_service_1.ValidationService.instance.validateUUIDv4(itemUuid));
|
|
76
|
+
if (!itemUuid) {
|
|
77
|
+
itemUuid = (await this.getItemUuidInteractively()).trim();
|
|
78
|
+
}
|
|
79
|
+
return itemUuid;
|
|
80
|
+
};
|
|
81
|
+
getDestinationFolderUuid = async (destinationFolderUuidFlag, nonInteractive) => {
|
|
82
|
+
let destinationFolderUuid = cli_utils_1.CLIUtils.getValueFromFlag({
|
|
83
|
+
value: destinationFolderUuidFlag,
|
|
84
|
+
name: Move.flags['destination'].name,
|
|
85
|
+
error: new command_types_1.NotValidFolderUuidError(),
|
|
86
|
+
canBeEmpty: true,
|
|
87
|
+
}, nonInteractive, (folderUuid) => validation_service_1.ValidationService.instance.validateUUIDv4(folderUuid));
|
|
88
|
+
if (!destinationFolderUuid) {
|
|
89
|
+
destinationFolderUuid = (await this.getDestinationFolderUuidInteractively()).trim();
|
|
90
|
+
}
|
|
91
|
+
return destinationFolderUuid;
|
|
92
|
+
};
|
|
93
|
+
static MAX_ATTEMPTS = 3;
|
|
94
|
+
getItemUuidInteractively = () => {
|
|
95
|
+
return cli_utils_1.CLIUtils.promptWithAttempts({
|
|
96
|
+
message: 'What is the item id you want to move?',
|
|
97
|
+
options: { required: true },
|
|
98
|
+
error: new command_types_1.NotValidItemUuidError(),
|
|
99
|
+
}, Move.MAX_ATTEMPTS, validation_service_1.ValidationService.instance.validateUUIDv4);
|
|
100
|
+
};
|
|
101
|
+
getDestinationFolderUuidInteractively = () => {
|
|
102
|
+
return cli_utils_1.CLIUtils.promptWithAttempts({
|
|
103
|
+
message: 'What is the destination folder id?',
|
|
104
|
+
options: { required: true },
|
|
105
|
+
error: new command_types_1.NotValidFolderUuidError(),
|
|
106
|
+
}, Move.MAX_ATTEMPTS, validation_service_1.ValidationService.instance.validateUUIDv4);
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
exports.default = Move;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class Trash extends Command {
|
|
3
|
+
static readonly args: {};
|
|
4
|
+
static readonly description = "Moves a given folder/file to the trash.";
|
|
5
|
+
static readonly examples: string[];
|
|
6
|
+
static readonly flags: {
|
|
7
|
+
id: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
8
|
+
'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
};
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
catch(error: Error): Promise<void>;
|
|
12
|
+
getItemUuid: (itemUuidFlag: string | undefined, nonInteractive: boolean) => Promise<string>;
|
|
13
|
+
private static readonly MAX_ATTEMPTS;
|
|
14
|
+
getItemUuidInteractively: () => Promise<string>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
|
+
const config_service_1 = require("../services/config.service");
|
|
5
|
+
const drive_folder_service_1 = require("../services/drive/drive-folder.service");
|
|
6
|
+
const cli_utils_1 = require("../utils/cli.utils");
|
|
7
|
+
const command_types_1 = require("../types/command.types");
|
|
8
|
+
const validation_service_1 = require("../services/validation.service");
|
|
9
|
+
const drive_file_service_1 = require("../services/drive/drive-file.service");
|
|
10
|
+
const errors_utils_1 = require("../utils/errors.utils");
|
|
11
|
+
const trash_service_1 = require("../services/drive/trash.service");
|
|
12
|
+
class Trash extends core_1.Command {
|
|
13
|
+
static args = {};
|
|
14
|
+
static description = 'Moves a given folder/file to the trash.';
|
|
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 item id to be trashed (it can be a file id or a folder id).',
|
|
21
|
+
required: false,
|
|
22
|
+
}),
|
|
23
|
+
};
|
|
24
|
+
async run() {
|
|
25
|
+
const { flags } = await this.parse(Trash);
|
|
26
|
+
const nonInteractive = flags['non-interactive'];
|
|
27
|
+
const userCredentials = await config_service_1.ConfigService.instance.readUser();
|
|
28
|
+
if (!userCredentials)
|
|
29
|
+
throw new command_types_1.MissingCredentialsError();
|
|
30
|
+
const itemUuid = await this.getItemUuid(flags['id'], nonInteractive);
|
|
31
|
+
let item;
|
|
32
|
+
let isFolder = false;
|
|
33
|
+
try {
|
|
34
|
+
if (!item) {
|
|
35
|
+
item = await drive_file_service_1.DriveFileService.instance.getFileMetadata(itemUuid);
|
|
36
|
+
isFolder = false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
if (!item) {
|
|
43
|
+
item = await drive_folder_service_1.DriveFolderService.instance.getFolderMetaByUuid(itemUuid);
|
|
44
|
+
isFolder = true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
}
|
|
49
|
+
if (!item)
|
|
50
|
+
throw new command_types_1.ItemNotFoundError();
|
|
51
|
+
if (isFolder) {
|
|
52
|
+
await trash_service_1.TrashService.instance.trashItems({ items: [{ uuid: item.uuid, type: 'folder' }] });
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
await trash_service_1.TrashService.instance.trashItems({ items: [{ uuid: item.uuid, type: 'file' }] });
|
|
56
|
+
}
|
|
57
|
+
cli_utils_1.CLIUtils.success(`${isFolder ? 'Folder' : 'File'} trashed successfully, you can restore or delete it permanently on: https://drive.internxt.com/trash`);
|
|
58
|
+
}
|
|
59
|
+
async catch(error) {
|
|
60
|
+
errors_utils_1.ErrorUtils.report(error, { command: this.id });
|
|
61
|
+
cli_utils_1.CLIUtils.error(error.message);
|
|
62
|
+
this.exit(1);
|
|
63
|
+
}
|
|
64
|
+
getItemUuid = async (itemUuidFlag, nonInteractive) => {
|
|
65
|
+
let itemUuid = cli_utils_1.CLIUtils.getValueFromFlag({
|
|
66
|
+
value: itemUuidFlag,
|
|
67
|
+
name: Trash.flags['id'].name,
|
|
68
|
+
error: new command_types_1.NotValidItemUuidError(),
|
|
69
|
+
canBeEmpty: true,
|
|
70
|
+
}, nonInteractive, (itemUuid) => validation_service_1.ValidationService.instance.validateUUIDv4(itemUuid));
|
|
71
|
+
if (!itemUuid) {
|
|
72
|
+
itemUuid = (await this.getItemUuidInteractively()).trim();
|
|
73
|
+
}
|
|
74
|
+
return itemUuid;
|
|
75
|
+
};
|
|
76
|
+
static MAX_ATTEMPTS = 3;
|
|
77
|
+
getItemUuidInteractively = () => {
|
|
78
|
+
return cli_utils_1.CLIUtils.promptWithAttempts({
|
|
79
|
+
message: 'What is the item id you want to trash?',
|
|
80
|
+
options: { required: true },
|
|
81
|
+
error: new command_types_1.NotValidItemUuidError(),
|
|
82
|
+
}, Trash.MAX_ATTEMPTS, validation_service_1.ValidationService.instance.validateUUIDv4);
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
exports.default = Trash;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class Upload extends Command {
|
|
3
|
+
static readonly description = "Upload a file to Internxt Drive";
|
|
4
|
+
static readonly examples: string[];
|
|
5
|
+
static readonly enableJsonFlag = true;
|
|
6
|
+
static readonly flags: {
|
|
7
|
+
file: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
8
|
+
id: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
9
|
+
};
|
|
10
|
+
catch(error: Error): Promise<void>;
|
|
11
|
+
run(): Promise<{
|
|
12
|
+
fileId: string;
|
|
13
|
+
uuid: string;
|
|
14
|
+
}>;
|
|
15
|
+
}
|