@internxt/cli 1.3.2 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env +13 -0
- package/README.md +590 -176
- package/dist/commands/add-cert.d.ts +10 -3
- package/dist/commands/add-cert.js +24 -38
- package/dist/commands/config.d.ts +15 -12
- package/dist/commands/config.js +24 -28
- package/dist/commands/create-folder.d.ts +16 -8
- package/dist/commands/create-folder.js +67 -24
- package/dist/commands/delete-permanently-file.d.ts +18 -0
- package/dist/commands/delete-permanently-file.js +63 -0
- package/dist/commands/delete-permanently-folder.d.ts +18 -0
- package/dist/commands/delete-permanently-folder.js +63 -0
- package/dist/commands/download-file.d.ts +26 -0
- package/dist/commands/{download.js → download-file.js} +98 -56
- package/dist/commands/list.d.ts +12 -12
- package/dist/commands/list.js +45 -73
- package/dist/commands/login.d.ts +11 -9
- package/dist/commands/login.js +46 -49
- package/dist/commands/logout.d.ts +7 -2
- package/dist/commands/logout.js +14 -8
- package/dist/commands/logs.d.ts +11 -2
- package/dist/commands/logs.js +16 -3
- package/dist/commands/move-file.d.ts +9 -7
- package/dist/commands/move-file.js +38 -37
- package/dist/commands/move-folder.d.ts +9 -7
- package/dist/commands/move-folder.js +38 -37
- package/dist/commands/rename-file.d.ts +24 -0
- package/dist/commands/rename-file.js +80 -0
- package/dist/commands/rename-folder.d.ts +24 -0
- package/dist/commands/rename-folder.js +80 -0
- package/dist/commands/trash-clear.d.ts +9 -5
- package/dist/commands/trash-clear.js +21 -19
- package/dist/commands/trash-file.d.ts +21 -0
- package/dist/commands/trash-file.js +58 -0
- package/dist/commands/trash-folder.d.ts +21 -0
- package/dist/commands/trash-folder.js +58 -0
- package/dist/commands/trash-list.d.ts +10 -11
- package/dist/commands/trash-list.js +33 -62
- package/dist/commands/trash-restore-file.d.ts +10 -8
- package/dist/commands/trash-restore-file.js +33 -35
- package/dist/commands/trash-restore-folder.d.ts +10 -8
- package/dist/commands/trash-restore-folder.js +33 -35
- package/dist/commands/upload-file.d.ts +21 -0
- package/dist/commands/upload-file.js +140 -0
- package/dist/commands/webdav-config.d.ts +11 -9
- package/dist/commands/webdav-config.js +40 -66
- package/dist/commands/webdav.d.ts +16 -9
- package/dist/commands/webdav.js +77 -61
- package/dist/commands/whoami.d.ts +14 -2
- package/dist/commands/whoami.js +40 -11
- package/dist/hooks/prerun/auth_check.js +6 -4
- package/dist/services/auth.service.d.ts +2 -8
- package/dist/services/auth.service.js +33 -24
- package/dist/services/config.service.d.ts +3 -3
- package/dist/services/config.service.js +8 -8
- package/dist/services/crypto.service.d.ts +1 -3
- package/dist/services/crypto.service.js +11 -36
- package/dist/services/database/drive-file/drive-file.repository.d.ts +3 -3
- package/dist/services/database/drive-folder/drive-folder.repository.d.ts +3 -3
- package/dist/services/drive/drive-file.service.d.ts +1 -8
- package/dist/services/drive/drive-file.service.js +9 -23
- package/dist/services/drive/drive-folder.service.d.ts +1 -4
- package/dist/services/drive/drive-folder.service.js +2 -5
- package/dist/services/drive/trash.service.d.ts +2 -0
- package/dist/services/drive/trash.service.js +8 -0
- package/dist/services/keys.service.js +17 -7
- package/dist/services/network/network-facade.service.d.ts +1 -3
- package/dist/services/network/network-facade.service.js +20 -13
- package/dist/services/network/upload.service.d.ts +0 -1
- package/dist/services/sdk-manager.service.d.ts +2 -3
- package/dist/services/sdk-manager.service.js +14 -12
- package/dist/services/validation.service.d.ts +10 -0
- package/dist/services/validation.service.js +40 -1
- package/dist/types/command.types.d.ts +26 -17
- package/dist/types/command.types.js +38 -24
- package/dist/types/network.types.d.ts +0 -1
- package/dist/types/webdav.types.d.ts +1 -2
- package/dist/utils/cli.utils.d.ts +28 -19
- package/dist/utils/cli.utils.js +64 -44
- package/dist/utils/errors.utils.d.ts +1 -1
- package/dist/utils/errors.utils.js +3 -3
- package/dist/utils/hash.utils.d.ts +4 -7
- package/dist/utils/hash.utils.js +6 -6
- package/dist/utils/inquirer.utils.d.ts +4 -0
- package/dist/utils/inquirer.utils.js +24 -0
- package/dist/utils/network.utils.d.ts +2 -2
- package/dist/utils/network.utils.js +10 -8
- package/dist/utils/pm2.utils.d.ts +5 -1
- package/dist/utils/pm2.utils.js +35 -3
- package/dist/utils/stream.utils.d.ts +1 -4
- package/dist/utils/webdav.utils.js +4 -4
- package/dist/utils/xml.utils.js +4 -1
- package/dist/webdav/handlers/GET.handler.js +8 -3
- package/dist/webdav/handlers/MKCOL.handler.js +2 -6
- package/dist/webdav/handlers/MOVE.handler.js +0 -3
- package/dist/webdav/handlers/PROPFIND.handler.js +2 -2
- package/dist/webdav/handlers/PUT.handler.js +14 -9
- package/dist/webdav/middewares/errors.middleware.js +1 -1
- package/dist/webdav/middewares/request-logger.middleware.d.ts +1 -2
- package/dist/webdav/middewares/request-logger.middleware.js +6 -5
- package/dist/webdav/webdav-server.js +2 -3
- package/oclif.manifest.json +517 -350
- package/package.json +42 -47
- package/dist/commands/download.d.ts +0 -19
- package/dist/commands/rename.d.ts +0 -18
- package/dist/commands/rename.js +0 -109
- package/dist/commands/trash.d.ts +0 -15
- package/dist/commands/trash.js +0 -85
- package/dist/commands/upload.d.ts +0 -15
- package/dist/commands/upload.js +0 -93
- package/dist/services/analytics.service.d.ts +0 -22
- package/dist/services/analytics.service.js +0 -20
|
@@ -12,30 +12,112 @@ const crypto_service_1 = require("../services/crypto.service");
|
|
|
12
12
|
const download_service_1 = require("../services/network/download.service");
|
|
13
13
|
const upload_service_1 = require("../services/network/upload.service");
|
|
14
14
|
const sdk_manager_service_1 = require("../services/sdk-manager.service");
|
|
15
|
-
const
|
|
16
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
17
|
-
const
|
|
15
|
+
const node_fs_1 = require("node:fs");
|
|
16
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
17
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
18
18
|
const stream_utils_1 = require("../utils/stream.utils");
|
|
19
19
|
const errors_utils_1 = require("../utils/errors.utils");
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const command_types_1 = require("../types/command.types");
|
|
21
|
+
const validation_service_1 = require("../services/validation.service");
|
|
22
|
+
class DownloadFile extends core_1.Command {
|
|
23
|
+
static args = {};
|
|
24
|
+
static description = 'Download and decrypts a file from Internxt Drive to a directory. The file name will be the same as the file name in your Drive.';
|
|
25
|
+
static aliases = ['download:file'];
|
|
22
26
|
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
23
27
|
static flags = {
|
|
24
|
-
|
|
28
|
+
...cli_utils_1.CLIUtils.CommonFlags,
|
|
25
29
|
id: core_1.Flags.string({
|
|
30
|
+
char: 'i',
|
|
26
31
|
description: 'The id of the file to download. Use <%= config.bin %> list to view your files ids',
|
|
27
|
-
required:
|
|
32
|
+
required: false,
|
|
28
33
|
}),
|
|
29
34
|
directory: core_1.Flags.string({
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
char: 'd',
|
|
36
|
+
description: 'The directory to download the file to. Leave empty for the current folder.',
|
|
37
|
+
required: false,
|
|
38
|
+
parse: cli_utils_1.CLIUtils.parseEmpty,
|
|
39
|
+
}),
|
|
40
|
+
overwrite: core_1.Flags.boolean({
|
|
41
|
+
char: 'o',
|
|
42
|
+
description: 'Overwrite the file if it already exists',
|
|
43
|
+
default: false,
|
|
32
44
|
}),
|
|
33
45
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
46
|
+
static enableJsonFlag = true;
|
|
47
|
+
run = async () => {
|
|
48
|
+
const { flags } = await this.parse(DownloadFile);
|
|
49
|
+
const nonInteractive = flags['non-interactive'];
|
|
50
|
+
const overwrite = flags['overwrite'];
|
|
51
|
+
let downloadDirectory = await this.getDirectory(flags['directory'], nonInteractive);
|
|
52
|
+
if (downloadDirectory.trim().length === 0) {
|
|
53
|
+
downloadDirectory = '.';
|
|
54
|
+
}
|
|
55
|
+
const fileUuid = await this.getFileUuid(flags['id'], nonInteractive);
|
|
56
|
+
const driveFile = await this.getFileMetadata(fileUuid);
|
|
57
|
+
const downloadPath = await this.getDownloadPath(downloadDirectory, driveFile, overwrite);
|
|
58
|
+
const { user } = await auth_service_1.AuthService.instance.getAuthDetails();
|
|
59
|
+
const networkFacade = await this.prepareNetwork(user);
|
|
60
|
+
const fileWriteStream = (0, node_fs_1.createWriteStream)(downloadPath);
|
|
61
|
+
const progressBar = cli_utils_1.CLIUtils.progress({
|
|
62
|
+
format: 'Downloading file [{bar}] {percentage}%',
|
|
63
|
+
linewrap: true,
|
|
64
|
+
});
|
|
65
|
+
progressBar.start(100, 0);
|
|
66
|
+
const [executeDownload, abortable] = await networkFacade.downloadToStream(user.bucket, user.mnemonic, driveFile.fileId, stream_utils_1.StreamUtils.writeStreamToWritableStream(fileWriteStream), {
|
|
67
|
+
abortController: new AbortController(),
|
|
68
|
+
progressCallback: (progress) => {
|
|
69
|
+
progressBar.update(progress);
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
process.on('SIGINT', () => {
|
|
73
|
+
abortable.abort('SIGINT received');
|
|
74
|
+
process.exit(1);
|
|
75
|
+
});
|
|
76
|
+
await executeDownload;
|
|
77
|
+
progressBar.update(100);
|
|
78
|
+
progressBar.stop();
|
|
79
|
+
const message = `File downloaded successfully to ${downloadPath}`;
|
|
80
|
+
cli_utils_1.CLIUtils.success(this.log.bind(this), message);
|
|
81
|
+
return { success: true, message, file: driveFile };
|
|
82
|
+
};
|
|
83
|
+
catch = async (error) => {
|
|
84
|
+
errors_utils_1.ErrorUtils.report(this.error.bind(this), error, { command: this.id });
|
|
85
|
+
cli_utils_1.CLIUtils.error(this.log.bind(this), error.message);
|
|
37
86
|
this.exit(1);
|
|
38
|
-
}
|
|
87
|
+
};
|
|
88
|
+
getFileUuid = async (fileUuidFlag, nonInteractive) => {
|
|
89
|
+
const fileUuid = await cli_utils_1.CLIUtils.getValueFromFlag({
|
|
90
|
+
value: fileUuidFlag,
|
|
91
|
+
name: DownloadFile.flags['id'].name,
|
|
92
|
+
}, {
|
|
93
|
+
nonInteractive,
|
|
94
|
+
prompt: {
|
|
95
|
+
message: 'What is the file id you want to download?',
|
|
96
|
+
options: { type: 'input' },
|
|
97
|
+
},
|
|
98
|
+
}, {
|
|
99
|
+
validate: validation_service_1.ValidationService.instance.validateUUIDv4,
|
|
100
|
+
error: new command_types_1.NotValidFileUuidError(),
|
|
101
|
+
}, this.log.bind(this));
|
|
102
|
+
return fileUuid;
|
|
103
|
+
};
|
|
104
|
+
getDirectory = async (directoryFlag, nonInteractive) => {
|
|
105
|
+
const directory = await cli_utils_1.CLIUtils.getValueFromFlag({
|
|
106
|
+
value: directoryFlag,
|
|
107
|
+
name: DownloadFile.flags['directory'].name,
|
|
108
|
+
}, {
|
|
109
|
+
nonInteractive,
|
|
110
|
+
prompt: {
|
|
111
|
+
message: 'Where would you like to download the file? (Enter the local folder path on your computer)',
|
|
112
|
+
options: { type: 'input' },
|
|
113
|
+
},
|
|
114
|
+
}, {
|
|
115
|
+
validate: validation_service_1.ValidationService.instance.validateDirectoryExists,
|
|
116
|
+
error: new command_types_1.NotValidDirectoryError(),
|
|
117
|
+
canBeEmpty: true,
|
|
118
|
+
}, this.log.bind(this));
|
|
119
|
+
return directory;
|
|
120
|
+
};
|
|
39
121
|
getFileMetadata = async (uuid) => {
|
|
40
122
|
cli_utils_1.CLIUtils.doing('Getting file metadata');
|
|
41
123
|
const driveFile = await drive_file_service_1.DriveFileService.instance.getFileMetadata(uuid);
|
|
@@ -45,20 +127,12 @@ class Download extends core_1.Command {
|
|
|
45
127
|
}
|
|
46
128
|
return driveFile;
|
|
47
129
|
};
|
|
48
|
-
getUser = async () => {
|
|
49
|
-
const { mnemonic } = await auth_service_1.AuthService.instance.getAuthDetails();
|
|
50
|
-
const user = await auth_service_1.AuthService.instance.getUser();
|
|
51
|
-
return {
|
|
52
|
-
...user,
|
|
53
|
-
mnemonic,
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
130
|
getDownloadPath = async (downloadDirectory, driveFile, overwrite) => {
|
|
57
|
-
const filename =
|
|
131
|
+
const filename = node_path_1.default.format({
|
|
58
132
|
name: driveFile.name,
|
|
59
133
|
ext: `.${driveFile.type}`,
|
|
60
134
|
});
|
|
61
|
-
const downloadPath =
|
|
135
|
+
const downloadPath = node_path_1.default.join(downloadDirectory, filename);
|
|
62
136
|
await promises_1.default.access(downloadDirectory, promises_1.default.constants.W_OK);
|
|
63
137
|
try {
|
|
64
138
|
const stat = await promises_1.default.stat(downloadPath);
|
|
@@ -83,37 +157,5 @@ class Download extends core_1.Command {
|
|
|
83
157
|
cli_utils_1.CLIUtils.done();
|
|
84
158
|
return networkFacade;
|
|
85
159
|
};
|
|
86
|
-
async run() {
|
|
87
|
-
const { flags } = await this.parse(Download);
|
|
88
|
-
const { directory: downloadDirectory, id: fileUuid, overwrite } = flags;
|
|
89
|
-
const directoryStat = await promises_1.default.stat(downloadDirectory);
|
|
90
|
-
if (!directoryStat.isDirectory()) {
|
|
91
|
-
throw new Error('The directory provided is not a directory');
|
|
92
|
-
}
|
|
93
|
-
const driveFile = await this.getFileMetadata(fileUuid);
|
|
94
|
-
const downloadPath = await this.getDownloadPath(downloadDirectory, driveFile, overwrite);
|
|
95
|
-
const user = await this.getUser();
|
|
96
|
-
const networkFacade = await this.prepareNetwork(user);
|
|
97
|
-
const fileWriteStream = (0, fs_1.createWriteStream)(downloadPath);
|
|
98
|
-
const progressBar = core_1.ux.progress({
|
|
99
|
-
format: 'Downloading file [{bar}] {percentage}%',
|
|
100
|
-
linewrap: true,
|
|
101
|
-
});
|
|
102
|
-
progressBar.start(100, 0);
|
|
103
|
-
const [executeDownload, abortable] = await networkFacade.downloadToStream(user.bucket, user.mnemonic, driveFile.fileId, stream_utils_1.StreamUtils.writeStreamToWritableStream(fileWriteStream), {
|
|
104
|
-
abortController: new AbortController(),
|
|
105
|
-
progressCallback: (progress) => {
|
|
106
|
-
progressBar.update(progress);
|
|
107
|
-
},
|
|
108
|
-
});
|
|
109
|
-
process.on('SIGINT', () => {
|
|
110
|
-
abortable.abort('SIGINT received');
|
|
111
|
-
process.exit(1);
|
|
112
|
-
});
|
|
113
|
-
await executeDownload;
|
|
114
|
-
progressBar.update(100);
|
|
115
|
-
progressBar.stop();
|
|
116
|
-
cli_utils_1.CLIUtils.success(`File downloaded successfully to ${downloadPath}`);
|
|
117
|
-
}
|
|
118
160
|
}
|
|
119
|
-
exports.default =
|
|
161
|
+
exports.default = DownloadFile;
|
package/dist/commands/list.d.ts
CHANGED
|
@@ -2,21 +2,21 @@ import { Command } from '@oclif/core';
|
|
|
2
2
|
export default class List extends Command {
|
|
3
3
|
static readonly args: {};
|
|
4
4
|
static readonly description = "Lists the content of a folder id.";
|
|
5
|
+
static readonly aliases: never[];
|
|
5
6
|
static readonly examples: string[];
|
|
6
7
|
static readonly flags: {
|
|
7
|
-
columns: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
8
|
-
csv: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
9
|
-
extended: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
10
|
-
filter: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
11
|
-
'no-header': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
12
|
-
'no-truncate': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
13
|
-
output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
14
|
-
sort: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
15
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>;
|
|
16
10
|
'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
17
11
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
static readonly enableJsonFlag = true;
|
|
13
|
+
run: () => Promise<{
|
|
14
|
+
success: boolean;
|
|
15
|
+
list: {
|
|
16
|
+
folders: import("@internxt/sdk/dist/drive/storage/types").FetchPaginatedFolder[];
|
|
17
|
+
files: import("@internxt/sdk/dist/drive/storage/types").FetchPaginatedFile[];
|
|
18
|
+
};
|
|
19
|
+
}>;
|
|
20
|
+
catch: (error: Error) => Promise<never>;
|
|
21
|
+
private getFolderUuid;
|
|
22
22
|
}
|
package/dist/commands/list.js
CHANGED
|
@@ -11,18 +11,24 @@ const errors_utils_1 = require("../utils/errors.utils");
|
|
|
11
11
|
class List extends core_1.Command {
|
|
12
12
|
static args = {};
|
|
13
13
|
static description = 'Lists the content of a folder id.';
|
|
14
|
+
static aliases = [];
|
|
14
15
|
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
15
16
|
static flags = {
|
|
16
17
|
...cli_utils_1.CLIUtils.CommonFlags,
|
|
17
18
|
id: core_1.Flags.string({
|
|
18
|
-
char: '
|
|
19
|
+
char: 'i',
|
|
19
20
|
description: 'The folder id to list. Leave empty for the root folder.',
|
|
20
21
|
required: false,
|
|
21
22
|
parse: cli_utils_1.CLIUtils.parseEmpty,
|
|
22
23
|
}),
|
|
23
|
-
|
|
24
|
+
extended: core_1.Flags.boolean({
|
|
25
|
+
char: 'e',
|
|
26
|
+
description: 'Displays additional information in the list.',
|
|
27
|
+
required: false,
|
|
28
|
+
}),
|
|
24
29
|
};
|
|
25
|
-
|
|
30
|
+
static enableJsonFlag = true;
|
|
31
|
+
run = async () => {
|
|
26
32
|
const { flags } = await this.parse(List);
|
|
27
33
|
const nonInteractive = flags['non-interactive'];
|
|
28
34
|
const userCredentials = await config_service_1.ConfigService.instance.readUser();
|
|
@@ -30,95 +36,61 @@ class List extends core_1.Command {
|
|
|
30
36
|
throw new command_types_1.MissingCredentialsError();
|
|
31
37
|
let folderUuid = await this.getFolderUuid(flags['id'], nonInteractive);
|
|
32
38
|
if (folderUuid.trim().length === 0) {
|
|
33
|
-
folderUuid = userCredentials.
|
|
39
|
+
folderUuid = userCredentials.user.rootFolderId;
|
|
34
40
|
}
|
|
35
41
|
const { folders, files } = await drive_folder_service_1.DriveFolderService.instance.getFolderContent(folderUuid);
|
|
36
42
|
const allItems = [
|
|
37
43
|
...folders.map((folder) => {
|
|
38
44
|
return {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
updatedAt: folder.updatedAt,
|
|
45
|
+
type: 'folder',
|
|
46
|
+
name: folder.plainName,
|
|
47
|
+
id: folder.uuid,
|
|
48
|
+
size: '-',
|
|
49
|
+
modified: format_utils_1.FormatUtils.formatDate(folder.updatedAt),
|
|
45
50
|
};
|
|
46
51
|
}),
|
|
47
52
|
...files.map((file) => {
|
|
48
53
|
return {
|
|
49
|
-
|
|
50
|
-
plainName: file.plainName,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
updatedAt: file.updatedAt,
|
|
54
|
+
type: 'file',
|
|
55
|
+
name: file.type && file.type.length > 0 ? `${file.plainName}.${file.type}` : file.plainName,
|
|
56
|
+
id: file.uuid,
|
|
57
|
+
size: format_utils_1.FormatUtils.humanFileSize(Number(file.size)),
|
|
58
|
+
modified: format_utils_1.FormatUtils.formatDate(file.updatedAt),
|
|
55
59
|
};
|
|
56
60
|
}),
|
|
57
61
|
];
|
|
58
|
-
|
|
59
|
-
type:
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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);
|
|
62
|
+
const headers = [
|
|
63
|
+
{ value: 'type', alias: 'Type' },
|
|
64
|
+
{ value: 'name', alias: 'Name' },
|
|
65
|
+
{ value: 'id', alias: 'Id' },
|
|
66
|
+
];
|
|
67
|
+
if (flags.extended) {
|
|
68
|
+
headers.push({ value: 'modified', alias: 'Modified' }, { value: 'size', alias: 'Size' });
|
|
69
|
+
}
|
|
70
|
+
cli_utils_1.CLIUtils.table(this.log.bind(this), headers, allItems);
|
|
71
|
+
return { success: true, list: { folders, files } };
|
|
72
|
+
};
|
|
73
|
+
catch = async (error) => {
|
|
74
|
+
errors_utils_1.ErrorUtils.report(this.error.bind(this), error, { command: this.id });
|
|
75
|
+
cli_utils_1.CLIUtils.error(this.log.bind(this), error.message);
|
|
103
76
|
this.exit(1);
|
|
104
|
-
}
|
|
77
|
+
};
|
|
105
78
|
getFolderUuid = async (folderUuidFlag, nonInteractive) => {
|
|
106
|
-
|
|
79
|
+
const folderUuid = await cli_utils_1.CLIUtils.getValueFromFlag({
|
|
107
80
|
value: folderUuidFlag,
|
|
108
81
|
name: List.flags['id'].name,
|
|
82
|
+
}, {
|
|
83
|
+
nonInteractive,
|
|
84
|
+
prompt: {
|
|
85
|
+
message: 'What is the folder id you want to list? (leave empty for the root folder)',
|
|
86
|
+
options: { type: 'input' },
|
|
87
|
+
},
|
|
88
|
+
}, {
|
|
89
|
+
validate: validation_service_1.ValidationService.instance.validateUUIDv4,
|
|
109
90
|
error: new command_types_1.NotValidFolderUuidError(),
|
|
110
91
|
canBeEmpty: true,
|
|
111
|
-
},
|
|
112
|
-
if (!folderUuid) {
|
|
113
|
-
folderUuid = (await this.getFolderUuidInteractively()).trim();
|
|
114
|
-
}
|
|
92
|
+
}, this.log.bind(this));
|
|
115
93
|
return folderUuid;
|
|
116
94
|
};
|
|
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
|
-
});
|
|
122
|
-
};
|
|
123
95
|
}
|
|
124
96
|
exports.default = List;
|
package/dist/commands/login.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Command } from '@oclif/core';
|
|
|
2
2
|
export default class Login extends Command {
|
|
3
3
|
static readonly args: {};
|
|
4
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 aliases: never[];
|
|
5
6
|
static readonly examples: string[];
|
|
6
7
|
static readonly flags: {
|
|
7
8
|
email: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
@@ -9,13 +10,14 @@ export default class Login extends Command {
|
|
|
9
10
|
twofactor: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
10
11
|
'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
static readonly enableJsonFlag = true;
|
|
14
|
+
run: () => Promise<{
|
|
15
|
+
success: boolean;
|
|
16
|
+
message: string;
|
|
17
|
+
login: import("../types/command.types").LoginCredentials;
|
|
18
|
+
}>;
|
|
19
|
+
catch: (error: Error) => Promise<never>;
|
|
20
|
+
private getEmail;
|
|
21
|
+
private getPassword;
|
|
22
|
+
private getTwoFactorCode;
|
|
21
23
|
}
|
package/dist/commands/login.js
CHANGED
|
@@ -7,13 +7,12 @@ const config_service_1 = require("../services/config.service");
|
|
|
7
7
|
const validation_service_1 = require("../services/validation.service");
|
|
8
8
|
const cli_utils_1 = require("../utils/cli.utils");
|
|
9
9
|
const errors_utils_1 = require("../utils/errors.utils");
|
|
10
|
-
const drive_folder_service_1 = require("../services/drive/drive-folder.service");
|
|
11
10
|
const sdk_manager_service_1 = require("../services/sdk-manager.service");
|
|
12
11
|
const drive_database_manager_service_1 = require("../services/database/drive-database-manager.service");
|
|
13
|
-
const analytics_service_1 = require("../services/analytics.service");
|
|
14
12
|
class Login extends core_1.Command {
|
|
15
13
|
static args = {};
|
|
16
14
|
static description = 'Logs into an Internxt account. If the account is two-factor protected, then an extra code will be required.';
|
|
15
|
+
static aliases = [];
|
|
17
16
|
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
18
17
|
static flags = {
|
|
19
18
|
...cli_utils_1.CLIUtils.CommonFlags,
|
|
@@ -40,7 +39,8 @@ class Login extends core_1.Command {
|
|
|
40
39
|
helpValue: '123456',
|
|
41
40
|
}),
|
|
42
41
|
};
|
|
43
|
-
|
|
42
|
+
static enableJsonFlag = true;
|
|
43
|
+
run = async () => {
|
|
44
44
|
const { flags } = await this.parse(Login);
|
|
45
45
|
const nonInteractive = flags['non-interactive'];
|
|
46
46
|
const email = await this.getEmail(flags['email'], nonInteractive);
|
|
@@ -55,72 +55,69 @@ class Login extends core_1.Command {
|
|
|
55
55
|
token: loginCredentials.token,
|
|
56
56
|
newToken: loginCredentials.newToken,
|
|
57
57
|
});
|
|
58
|
-
|
|
59
|
-
await config_service_1.ConfigService.instance.saveUser(Object.assign(loginCredentials, { root_folder_uuid: rootMeta.uuid }));
|
|
58
|
+
await config_service_1.ConfigService.instance.saveUser(loginCredentials);
|
|
60
59
|
await drive_database_manager_service_1.DriveDatabaseManager.init();
|
|
61
60
|
await drive_database_manager_service_1.DriveDatabaseManager.clean();
|
|
62
|
-
|
|
63
|
-
cli_utils_1.CLIUtils.success(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
const message = `Succesfully logged in to: ${loginCredentials.user.email}`;
|
|
62
|
+
cli_utils_1.CLIUtils.success(this.log.bind(this), message);
|
|
63
|
+
return {
|
|
64
|
+
success: true,
|
|
65
|
+
message,
|
|
66
|
+
login: loginCredentials,
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
catch = async (error) => {
|
|
70
|
+
errors_utils_1.ErrorUtils.report(this.error.bind(this), error, { command: this.id });
|
|
71
|
+
cli_utils_1.CLIUtils.error(this.log.bind(this), error.message);
|
|
68
72
|
this.exit(1);
|
|
69
|
-
}
|
|
73
|
+
};
|
|
70
74
|
getEmail = async (emailFlag, nonInteractive) => {
|
|
71
|
-
|
|
75
|
+
const email = await cli_utils_1.CLIUtils.getValueFromFlag({
|
|
72
76
|
value: emailFlag,
|
|
73
77
|
name: Login.flags['email'].name,
|
|
78
|
+
}, {
|
|
79
|
+
nonInteractive,
|
|
80
|
+
prompt: {
|
|
81
|
+
message: 'What is your email?',
|
|
82
|
+
options: { type: 'input' },
|
|
83
|
+
},
|
|
84
|
+
}, {
|
|
85
|
+
validate: validation_service_1.ValidationService.instance.validateEmail,
|
|
74
86
|
error: new command_types_1.NotValidEmailError(),
|
|
75
|
-
},
|
|
76
|
-
if (!email) {
|
|
77
|
-
email = await this.getEmailInteractively();
|
|
78
|
-
}
|
|
87
|
+
}, this.log.bind(this));
|
|
79
88
|
return email;
|
|
80
89
|
};
|
|
81
90
|
getPassword = async (passwordFlag, nonInteractive) => {
|
|
82
|
-
|
|
91
|
+
const password = await cli_utils_1.CLIUtils.getValueFromFlag({
|
|
83
92
|
value: passwordFlag,
|
|
84
93
|
name: Login.flags['password'].name,
|
|
94
|
+
}, {
|
|
95
|
+
nonInteractive,
|
|
96
|
+
prompt: {
|
|
97
|
+
message: 'What is your password?',
|
|
98
|
+
options: { type: 'password' },
|
|
99
|
+
},
|
|
100
|
+
}, {
|
|
101
|
+
validate: validation_service_1.ValidationService.instance.validateStringIsNotEmpty,
|
|
85
102
|
error: new command_types_1.EmptyPasswordError(),
|
|
86
|
-
},
|
|
87
|
-
if (!password) {
|
|
88
|
-
password = await this.getPasswordInteractively();
|
|
89
|
-
}
|
|
103
|
+
}, this.log.bind(this));
|
|
90
104
|
return password;
|
|
91
105
|
};
|
|
92
106
|
getTwoFactorCode = async (twoFactorFlag, nonInteractive) => {
|
|
93
|
-
|
|
107
|
+
const twoFactor = await cli_utils_1.CLIUtils.getValueFromFlag({
|
|
94
108
|
value: twoFactorFlag,
|
|
95
109
|
name: Login.flags['twofactor'].name,
|
|
110
|
+
}, {
|
|
111
|
+
nonInteractive,
|
|
112
|
+
prompt: {
|
|
113
|
+
message: 'What is your two-factor token?',
|
|
114
|
+
options: { type: 'mask' },
|
|
115
|
+
},
|
|
116
|
+
}, {
|
|
117
|
+
validate: validation_service_1.ValidationService.instance.validate2FA,
|
|
96
118
|
error: new command_types_1.NotValidTwoFactorCodeError(),
|
|
97
|
-
},
|
|
98
|
-
if (!twoFactor) {
|
|
99
|
-
twoFactor = await this.getTwoFactorCodeInteractively();
|
|
100
|
-
}
|
|
119
|
+
}, this.log.bind(this));
|
|
101
120
|
return twoFactor;
|
|
102
121
|
};
|
|
103
|
-
static MAX_ATTEMPTS = 3;
|
|
104
|
-
getEmailInteractively = () => {
|
|
105
|
-
return cli_utils_1.CLIUtils.promptWithAttempts({
|
|
106
|
-
message: 'What is your email?',
|
|
107
|
-
options: { required: true },
|
|
108
|
-
error: new command_types_1.NotValidEmailError(),
|
|
109
|
-
}, Login.MAX_ATTEMPTS, validation_service_1.ValidationService.instance.validateEmail);
|
|
110
|
-
};
|
|
111
|
-
getPasswordInteractively = () => {
|
|
112
|
-
return cli_utils_1.CLIUtils.promptWithAttempts({
|
|
113
|
-
message: 'What is your password?',
|
|
114
|
-
options: { type: 'hide', required: true },
|
|
115
|
-
error: new command_types_1.EmptyPasswordError(),
|
|
116
|
-
}, Login.MAX_ATTEMPTS, (password) => password.trim().length > 0);
|
|
117
|
-
};
|
|
118
|
-
getTwoFactorCodeInteractively = () => {
|
|
119
|
-
return cli_utils_1.CLIUtils.promptWithAttempts({
|
|
120
|
-
message: 'What is your two-factor token?',
|
|
121
|
-
options: { type: 'mask', required: true },
|
|
122
|
-
error: new command_types_1.NotValidTwoFactorCodeError(),
|
|
123
|
-
}, Login.MAX_ATTEMPTS, validation_service_1.ValidationService.instance.validate2FA);
|
|
124
|
-
};
|
|
125
122
|
}
|
|
126
123
|
exports.default = Login;
|
|
@@ -2,8 +2,13 @@ import { Command } from '@oclif/core';
|
|
|
2
2
|
export default class Logout extends Command {
|
|
3
3
|
static readonly args: {};
|
|
4
4
|
static readonly description = "Logs out the current internxt user that is logged into the Internxt CLI.";
|
|
5
|
+
static readonly aliases: never[];
|
|
5
6
|
static readonly examples: string[];
|
|
6
7
|
static readonly flags: {};
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
static readonly enableJsonFlag = true;
|
|
9
|
+
run: () => Promise<{
|
|
10
|
+
success: boolean;
|
|
11
|
+
message: string;
|
|
12
|
+
}>;
|
|
13
|
+
catch: (error: Error) => Promise<never>;
|
|
9
14
|
}
|
package/dist/commands/logout.js
CHANGED
|
@@ -8,23 +8,29 @@ const drive_database_manager_service_1 = require("../services/database/drive-dat
|
|
|
8
8
|
class Logout extends core_1.Command {
|
|
9
9
|
static args = {};
|
|
10
10
|
static description = 'Logs out the current internxt user that is logged into the Internxt CLI.';
|
|
11
|
+
static aliases = [];
|
|
11
12
|
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
12
13
|
static flags = {};
|
|
13
|
-
|
|
14
|
+
static enableJsonFlag = true;
|
|
15
|
+
run = async () => {
|
|
14
16
|
const user = await config_service_1.ConfigService.instance.readUser();
|
|
15
17
|
if (user) {
|
|
16
18
|
await config_service_1.ConfigService.instance.clearUser();
|
|
17
19
|
await drive_database_manager_service_1.DriveDatabaseManager.clean();
|
|
18
|
-
|
|
20
|
+
const message = 'User logged out successfully.';
|
|
21
|
+
cli_utils_1.CLIUtils.success(this.log.bind(this), message);
|
|
22
|
+
return { success: true, message };
|
|
19
23
|
}
|
|
20
24
|
else {
|
|
21
|
-
|
|
25
|
+
const message = 'No user is currently logged in.';
|
|
26
|
+
cli_utils_1.CLIUtils.error(this.log.bind(this), message);
|
|
27
|
+
return { success: false, message };
|
|
22
28
|
}
|
|
23
|
-
}
|
|
24
|
-
async
|
|
25
|
-
errors_utils_1.ErrorUtils.report(error, { command: this.id });
|
|
26
|
-
cli_utils_1.CLIUtils.error(error.message);
|
|
29
|
+
};
|
|
30
|
+
catch = async (error) => {
|
|
31
|
+
errors_utils_1.ErrorUtils.report(this.error.bind(this), error, { command: this.id });
|
|
32
|
+
cli_utils_1.CLIUtils.error(this.log.bind(this), error.message);
|
|
27
33
|
this.exit(1);
|
|
28
|
-
}
|
|
34
|
+
};
|
|
29
35
|
}
|
|
30
36
|
exports.default = Logout;
|
package/dist/commands/logs.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { Command } from '@oclif/core';
|
|
2
2
|
export default class Logs extends Command {
|
|
3
|
+
static readonly args: {};
|
|
3
4
|
static readonly description = "Displays the Internxt CLI logs directory path";
|
|
4
|
-
static
|
|
5
|
-
|
|
5
|
+
static readonly aliases: never[];
|
|
6
|
+
static readonly examples: string[];
|
|
7
|
+
static readonly flags: {};
|
|
8
|
+
static readonly enableJsonFlag = true;
|
|
9
|
+
run: () => Promise<{
|
|
10
|
+
success: boolean;
|
|
11
|
+
message: string;
|
|
12
|
+
path: string;
|
|
13
|
+
}>;
|
|
14
|
+
catch: (error: Error) => Promise<never>;
|
|
6
15
|
}
|
package/dist/commands/logs.js
CHANGED
|
@@ -2,11 +2,24 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const core_1 = require("@oclif/core");
|
|
4
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");
|
|
5
7
|
class Logs extends core_1.Command {
|
|
8
|
+
static args = {};
|
|
6
9
|
static description = 'Displays the Internxt CLI logs directory path';
|
|
10
|
+
static aliases = [];
|
|
7
11
|
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
static flags = {};
|
|
13
|
+
static enableJsonFlag = true;
|
|
14
|
+
run = async () => {
|
|
15
|
+
const message = `Internxt CLI logs are located at ${config_service_1.ConfigService.INTERNXT_CLI_LOGS_DIR}`;
|
|
16
|
+
cli_utils_1.CLIUtils.log(this.log.bind(this), message);
|
|
17
|
+
return { success: true, message, path: config_service_1.ConfigService.INTERNXT_CLI_LOGS_DIR };
|
|
18
|
+
};
|
|
19
|
+
catch = async (error) => {
|
|
20
|
+
errors_utils_1.ErrorUtils.report(this.error.bind(this), error, { command: this.id });
|
|
21
|
+
cli_utils_1.CLIUtils.error(this.log.bind(this), error.message);
|
|
22
|
+
this.exit(1);
|
|
23
|
+
};
|
|
11
24
|
}
|
|
12
25
|
exports.default = Logs;
|