@internxt/cli 1.3.3 → 1.4.2
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/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 +60 -65
- 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
|
@@ -3,10 +3,8 @@ export interface LoginCredentials {
|
|
|
3
3
|
user: UserSettings;
|
|
4
4
|
token: string;
|
|
5
5
|
newToken: string;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export interface CLICredentials extends LoginCredentials {
|
|
9
|
-
root_folder_uuid: string;
|
|
6
|
+
lastLoggedInAt: string;
|
|
7
|
+
lastTokenRefreshAt: string;
|
|
10
8
|
}
|
|
11
9
|
export interface WebdavConfig {
|
|
12
10
|
port: string;
|
|
@@ -27,32 +25,43 @@ export declare class NotValidFolderUuidError extends Error {
|
|
|
27
25
|
export declare class NotValidFileUuidError extends Error {
|
|
28
26
|
constructor();
|
|
29
27
|
}
|
|
30
|
-
export declare class
|
|
28
|
+
export declare class NoRootFolderIdFoundError extends Error {
|
|
31
29
|
constructor();
|
|
32
30
|
}
|
|
33
|
-
export declare class
|
|
31
|
+
export declare class MissingCredentialsError extends Error {
|
|
34
32
|
constructor();
|
|
35
33
|
}
|
|
36
|
-
export declare class
|
|
34
|
+
export declare class ExpiredCredentialsError extends Error {
|
|
37
35
|
constructor();
|
|
38
36
|
}
|
|
39
|
-
export declare class
|
|
37
|
+
export declare class InvalidCredentialsError extends Error {
|
|
40
38
|
constructor();
|
|
41
39
|
}
|
|
42
|
-
export declare class
|
|
40
|
+
export declare class EmptyFileNameError extends Error {
|
|
43
41
|
constructor();
|
|
44
42
|
}
|
|
45
|
-
export declare class
|
|
43
|
+
export declare class EmptyFolderNameError extends Error {
|
|
46
44
|
constructor();
|
|
47
45
|
}
|
|
48
46
|
export declare class NotValidPortError extends Error {
|
|
49
47
|
constructor();
|
|
50
48
|
}
|
|
51
|
-
export
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
export declare class NotValidDirectoryError extends Error {
|
|
50
|
+
constructor();
|
|
51
|
+
}
|
|
52
|
+
export declare class NotValidFileError extends Error {
|
|
53
|
+
constructor();
|
|
54
|
+
}
|
|
55
|
+
export interface PaginatedItem {
|
|
56
|
+
name: string;
|
|
55
57
|
type: string;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
id: string;
|
|
59
|
+
size: string;
|
|
60
|
+
modified: string;
|
|
61
|
+
}
|
|
62
|
+
export interface PromptOptions {
|
|
63
|
+
type: 'input' | 'password' | 'mask' | 'confirm';
|
|
64
|
+
confirm?: {
|
|
65
|
+
default: boolean;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NotValidPortError = exports.
|
|
3
|
+
exports.NotValidFileError = exports.NotValidDirectoryError = exports.NotValidPortError = exports.EmptyFolderNameError = exports.EmptyFileNameError = exports.InvalidCredentialsError = exports.ExpiredCredentialsError = exports.MissingCredentialsError = exports.NoRootFolderIdFoundError = exports.NotValidFileUuidError = exports.NotValidFolderUuidError = exports.NotValidTwoFactorCodeError = exports.EmptyPasswordError = exports.NotValidEmailError = void 0;
|
|
4
4
|
class NotValidEmailError extends Error {
|
|
5
5
|
constructor() {
|
|
6
6
|
super('Email is not valid');
|
|
@@ -36,20 +36,6 @@ class NotValidFileUuidError extends Error {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
exports.NotValidFileUuidError = NotValidFileUuidError;
|
|
39
|
-
class NotValidItemUuidError extends Error {
|
|
40
|
-
constructor() {
|
|
41
|
-
super('Item UUID is not valid (it must be a valid v4 UUID)');
|
|
42
|
-
Object.setPrototypeOf(this, NotValidItemUuidError.prototype);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
exports.NotValidItemUuidError = NotValidItemUuidError;
|
|
46
|
-
class ItemNotFoundError extends Error {
|
|
47
|
-
constructor() {
|
|
48
|
-
super('Item not found');
|
|
49
|
-
Object.setPrototypeOf(this, ItemNotFoundError.prototype);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.ItemNotFoundError = ItemNotFoundError;
|
|
53
39
|
class NoRootFolderIdFoundError extends Error {
|
|
54
40
|
constructor() {
|
|
55
41
|
super('No root folder id found on your account');
|
|
@@ -59,25 +45,39 @@ class NoRootFolderIdFoundError extends Error {
|
|
|
59
45
|
exports.NoRootFolderIdFoundError = NoRootFolderIdFoundError;
|
|
60
46
|
class MissingCredentialsError extends Error {
|
|
61
47
|
constructor() {
|
|
62
|
-
super('Missing credentials, login first');
|
|
48
|
+
super('Missing credentials, please login first');
|
|
63
49
|
Object.setPrototypeOf(this, MissingCredentialsError.prototype);
|
|
64
50
|
}
|
|
65
51
|
}
|
|
66
52
|
exports.MissingCredentialsError = MissingCredentialsError;
|
|
67
|
-
class
|
|
53
|
+
class ExpiredCredentialsError extends Error {
|
|
68
54
|
constructor() {
|
|
69
|
-
super('
|
|
70
|
-
Object.setPrototypeOf(this,
|
|
55
|
+
super('The session has expired, please login again');
|
|
56
|
+
Object.setPrototypeOf(this, ExpiredCredentialsError.prototype);
|
|
71
57
|
}
|
|
72
58
|
}
|
|
73
|
-
exports.
|
|
74
|
-
class
|
|
59
|
+
exports.ExpiredCredentialsError = ExpiredCredentialsError;
|
|
60
|
+
class InvalidCredentialsError extends Error {
|
|
75
61
|
constructor() {
|
|
76
|
-
super('
|
|
77
|
-
Object.setPrototypeOf(this,
|
|
62
|
+
super('Corrupted credentials, please login again');
|
|
63
|
+
Object.setPrototypeOf(this, InvalidCredentialsError.prototype);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.InvalidCredentialsError = InvalidCredentialsError;
|
|
67
|
+
class EmptyFileNameError extends Error {
|
|
68
|
+
constructor() {
|
|
69
|
+
super('File name can not be empty');
|
|
70
|
+
Object.setPrototypeOf(this, EmptyFileNameError.prototype);
|
|
78
71
|
}
|
|
79
72
|
}
|
|
80
|
-
exports.
|
|
73
|
+
exports.EmptyFileNameError = EmptyFileNameError;
|
|
74
|
+
class EmptyFolderNameError extends Error {
|
|
75
|
+
constructor() {
|
|
76
|
+
super('Folder name can not be empty');
|
|
77
|
+
Object.setPrototypeOf(this, EmptyFolderNameError.prototype);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.EmptyFolderNameError = EmptyFolderNameError;
|
|
81
81
|
class NotValidPortError extends Error {
|
|
82
82
|
constructor() {
|
|
83
83
|
super('Port should be a number between 1 and 65535');
|
|
@@ -85,3 +85,17 @@ class NotValidPortError extends Error {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
exports.NotValidPortError = NotValidPortError;
|
|
88
|
+
class NotValidDirectoryError extends Error {
|
|
89
|
+
constructor() {
|
|
90
|
+
super('The specified path is not a valid directory');
|
|
91
|
+
Object.setPrototypeOf(this, NotValidDirectoryError.prototype);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.NotValidDirectoryError = NotValidDirectoryError;
|
|
95
|
+
class NotValidFileError extends Error {
|
|
96
|
+
constructor() {
|
|
97
|
+
super('The specified path is not a valid file.');
|
|
98
|
+
Object.setPrototypeOf(this, NotValidFileError.prototype);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.NotValidFileError = NotValidFileError;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { Request, Response } from 'express';
|
|
3
|
-
import { ParsedPath } from 'path';
|
|
2
|
+
import { ParsedPath } from 'node:path';
|
|
4
3
|
export declare abstract class WebDavMethodHandler {
|
|
5
4
|
abstract handle(request: Request, response: Response): Promise<void>;
|
|
6
5
|
}
|
|
@@ -1,32 +1,41 @@
|
|
|
1
|
-
import
|
|
1
|
+
import cliProgress from 'cli-progress';
|
|
2
|
+
import { Header } from 'tty-table';
|
|
3
|
+
import { PromptOptions } from '../types/command.types';
|
|
2
4
|
export declare class CLIUtils {
|
|
3
|
-
static clearPreviousLine()
|
|
4
|
-
static warning(message: string): void;
|
|
5
|
-
static error(message: string): void;
|
|
6
|
-
static doing(message: string)
|
|
7
|
-
static success(message: string): void;
|
|
8
|
-
static
|
|
5
|
+
static readonly clearPreviousLine: () => void;
|
|
6
|
+
static readonly warning: (reporter: (message: string) => void, message: string) => void;
|
|
7
|
+
static readonly error: (reporter: (message: string) => void, message: string) => void;
|
|
8
|
+
static readonly doing: (message: string) => void;
|
|
9
|
+
static readonly success: (reporter: (message: string) => void, message: string) => void;
|
|
10
|
+
static readonly log: (reporter: (message: string) => void, message: string) => void;
|
|
11
|
+
static readonly done: () => void;
|
|
12
|
+
static readonly progress: (opts: cliProgress.Options) => cliProgress.SingleBar;
|
|
13
|
+
static readonly table: (reporter: (message: string) => void, header: Header[], rows: object[]) => void;
|
|
14
|
+
static readonly generateTableHeaderFromType: <T extends object>() => Header[];
|
|
9
15
|
static readonly CommonFlags: {
|
|
10
16
|
'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
11
17
|
};
|
|
12
18
|
static readonly getValueFromFlag: (flag: {
|
|
13
19
|
value?: string;
|
|
14
20
|
name: string;
|
|
21
|
+
}, command: {
|
|
22
|
+
nonInteractive: boolean;
|
|
23
|
+
maxAttempts?: number;
|
|
24
|
+
prompt: {
|
|
25
|
+
message: string;
|
|
26
|
+
options: PromptOptions;
|
|
27
|
+
};
|
|
28
|
+
}, validation: {
|
|
29
|
+
validate: (value: string) => Promise<boolean> | boolean;
|
|
15
30
|
error: Error;
|
|
16
31
|
canBeEmpty?: boolean;
|
|
17
|
-
},
|
|
18
|
-
static readonly promptWithAttempts
|
|
19
|
-
|
|
20
|
-
options?: ux.IPromptOptions;
|
|
21
|
-
error: Error;
|
|
22
|
-
}, maxAttempts: number, validate: (value: string) => boolean) => Promise<string>;
|
|
23
|
-
static timer(): {
|
|
32
|
+
}, reporter: (message: string) => void) => Promise<string>;
|
|
33
|
+
private static readonly promptWithAttempts;
|
|
34
|
+
static readonly timer: () => {
|
|
24
35
|
stop: () => number;
|
|
25
36
|
};
|
|
26
|
-
static readonly prompt: (prompt: {
|
|
27
|
-
message: string;
|
|
28
|
-
options?: ux.IPromptOptions;
|
|
29
|
-
error?: Error;
|
|
30
|
-
}, validate?: ((value: string) => boolean) | undefined) => Promise<string>;
|
|
31
37
|
static readonly parseEmpty: (input: string) => Promise<string>;
|
|
32
38
|
}
|
|
39
|
+
export declare class NoFlagProvidedError extends Error {
|
|
40
|
+
constructor(flag: string);
|
|
41
|
+
}
|
package/dist/utils/cli.utils.js
CHANGED
|
@@ -1,80 +1,109 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CLIUtils = void 0;
|
|
6
|
+
exports.NoFlagProvidedError = exports.CLIUtils = void 0;
|
|
4
7
|
const core_1 = require("@oclif/core");
|
|
8
|
+
const cli_progress_1 = __importDefault(require("cli-progress"));
|
|
9
|
+
const tty_table_1 = __importDefault(require("tty-table"));
|
|
10
|
+
const inquirer_utils_1 = require("./inquirer.utils");
|
|
5
11
|
class CLIUtils {
|
|
6
|
-
static clearPreviousLine() {
|
|
12
|
+
static clearPreviousLine = () => {
|
|
7
13
|
process.stdout.write('\x1b[1A');
|
|
8
14
|
process.stdout.clearLine(0);
|
|
9
|
-
}
|
|
10
|
-
static warning(message) {
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
static error(message) {
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
static doing(message) {
|
|
15
|
+
};
|
|
16
|
+
static warning = (reporter, message) => {
|
|
17
|
+
reporter(core_1.ux.colorize('#a67805', `⚠ Warning: ${message}`));
|
|
18
|
+
};
|
|
19
|
+
static error = (reporter, message) => {
|
|
20
|
+
reporter(core_1.ux.colorize('red', `⚠ Error: ${message}`));
|
|
21
|
+
};
|
|
22
|
+
static doing = (message) => {
|
|
17
23
|
core_1.ux.action.start(message, undefined, {});
|
|
18
|
-
}
|
|
19
|
-
static success(message) {
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
static
|
|
24
|
+
};
|
|
25
|
+
static success = (reporter, message) => {
|
|
26
|
+
reporter(core_1.ux.colorize('green', `✓ ${message}`));
|
|
27
|
+
};
|
|
28
|
+
static log = (reporter, message) => {
|
|
29
|
+
reporter(`${message}`);
|
|
30
|
+
};
|
|
31
|
+
static done = () => {
|
|
23
32
|
core_1.ux.action.stop(core_1.ux.colorize('green', 'done ✓'));
|
|
24
|
-
}
|
|
33
|
+
};
|
|
34
|
+
static progress = (opts) => {
|
|
35
|
+
return new cli_progress_1.default.SingleBar({ noTTYOutput: Boolean(!process.stdin.isTTY), ...opts }, cli_progress_1.default.Presets.shades_classic);
|
|
36
|
+
};
|
|
37
|
+
static table = (reporter, header, rows) => {
|
|
38
|
+
const table = (0, tty_table_1.default)(header, rows);
|
|
39
|
+
reporter(table.render());
|
|
40
|
+
};
|
|
41
|
+
static generateTableHeaderFromType = () => {
|
|
42
|
+
return Object.keys({}).map((key) => ({
|
|
43
|
+
value: key,
|
|
44
|
+
alias: key.charAt(0).toUpperCase() + key.slice(1),
|
|
45
|
+
}));
|
|
46
|
+
};
|
|
25
47
|
static CommonFlags = {
|
|
26
48
|
'non-interactive': core_1.Flags.boolean({
|
|
27
|
-
char: '
|
|
49
|
+
char: 'x',
|
|
28
50
|
env: 'INXT_NONINTERACTIVE',
|
|
29
51
|
helpGroup: 'helper',
|
|
30
|
-
description: '
|
|
52
|
+
description: 'Prevents the CLI from being interactive. When enabled, the CLI will not request input through the console and will throw errors directly.',
|
|
31
53
|
required: false,
|
|
32
54
|
}),
|
|
33
55
|
};
|
|
34
|
-
static getValueFromFlag = (flag,
|
|
35
|
-
if (flag.
|
|
36
|
-
if (
|
|
56
|
+
static getValueFromFlag = async (flag, command, validation, reporter) => {
|
|
57
|
+
if (flag.value) {
|
|
58
|
+
if (validation.canBeEmpty && flag.value.trim().length === 0) {
|
|
37
59
|
return '';
|
|
38
60
|
}
|
|
39
|
-
|
|
40
|
-
if (flag.value) {
|
|
41
|
-
const isValid = validate(flag.value);
|
|
61
|
+
const isValid = await validation.validate(flag.value);
|
|
42
62
|
if (isValid) {
|
|
43
63
|
return flag.value;
|
|
44
64
|
}
|
|
45
|
-
else if (nonInteractive) {
|
|
46
|
-
throw
|
|
65
|
+
else if (command.nonInteractive) {
|
|
66
|
+
throw validation.error;
|
|
47
67
|
}
|
|
48
68
|
else {
|
|
49
|
-
CLIUtils.error(
|
|
69
|
+
CLIUtils.error(reporter, validation.error.message);
|
|
50
70
|
}
|
|
51
71
|
}
|
|
52
|
-
|
|
72
|
+
if (command.nonInteractive) {
|
|
53
73
|
throw new NoFlagProvidedError(flag.name);
|
|
54
74
|
}
|
|
75
|
+
else {
|
|
76
|
+
const maxAttempts = command.maxAttempts ?? 3;
|
|
77
|
+
return await CLIUtils.promptWithAttempts(command.prompt, maxAttempts, validation, reporter);
|
|
78
|
+
}
|
|
55
79
|
};
|
|
56
|
-
static promptWithAttempts = async (prompt, maxAttempts,
|
|
80
|
+
static promptWithAttempts = async (prompt, maxAttempts, validation, reporter) => {
|
|
57
81
|
let isValid = false;
|
|
58
82
|
let currentAttempts = 0;
|
|
59
83
|
let promptValue = '';
|
|
60
84
|
do {
|
|
61
|
-
promptValue = await
|
|
62
|
-
|
|
85
|
+
promptValue = await inquirer_utils_1.InquirerUtils.prompt(prompt.message, prompt.options);
|
|
86
|
+
if (validation.canBeEmpty) {
|
|
87
|
+
if (!promptValue || promptValue.trim().length === 0) {
|
|
88
|
+
return '';
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
isValid = await validation.validate(promptValue);
|
|
63
92
|
if (!isValid) {
|
|
64
93
|
currentAttempts++;
|
|
65
94
|
if (currentAttempts < maxAttempts) {
|
|
66
|
-
CLIUtils.warning(
|
|
95
|
+
CLIUtils.warning(reporter, validation.error.message + ', please type it again');
|
|
67
96
|
}
|
|
68
97
|
}
|
|
69
98
|
} while (!isValid && currentAttempts < maxAttempts);
|
|
70
99
|
if (!isValid) {
|
|
71
|
-
throw
|
|
100
|
+
throw validation.error;
|
|
72
101
|
}
|
|
73
102
|
else {
|
|
74
103
|
return promptValue;
|
|
75
104
|
}
|
|
76
105
|
};
|
|
77
|
-
static timer() {
|
|
106
|
+
static timer = () => {
|
|
78
107
|
const start = new Date();
|
|
79
108
|
return {
|
|
80
109
|
stop: () => {
|
|
@@ -83,16 +112,6 @@ class CLIUtils {
|
|
|
83
112
|
return time;
|
|
84
113
|
},
|
|
85
114
|
};
|
|
86
|
-
}
|
|
87
|
-
static prompt = async (prompt, validate) => {
|
|
88
|
-
const promptValue = await core_1.ux.prompt(prompt.message, prompt.options);
|
|
89
|
-
if (validate) {
|
|
90
|
-
const isValid = validate(promptValue);
|
|
91
|
-
if (!isValid) {
|
|
92
|
-
throw prompt.error;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return promptValue;
|
|
96
115
|
};
|
|
97
116
|
static parseEmpty = async (input) => (input.trim().length === 0 ? ' ' : input);
|
|
98
117
|
}
|
|
@@ -103,3 +122,4 @@ class NoFlagProvidedError extends Error {
|
|
|
103
122
|
Object.setPrototypeOf(this, NoFlagProvidedError.prototype);
|
|
104
123
|
}
|
|
105
124
|
}
|
|
125
|
+
exports.NoFlagProvidedError = NoFlagProvidedError;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare class ErrorUtils {
|
|
2
|
-
static report(error: unknown, props?: Record<string, unknown>): void;
|
|
2
|
+
static report(reporter: (error: string) => void, error: unknown, props?: Record<string, unknown>): void;
|
|
3
3
|
}
|
|
4
4
|
export declare class ConflictError extends Error {
|
|
5
5
|
statusCode: number;
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NotImplementedError = exports.UnsupportedMediaTypeError = exports.BadRequestError = exports.NotFoundError = exports.ConflictError = exports.ErrorUtils = void 0;
|
|
4
4
|
class ErrorUtils {
|
|
5
|
-
static report(error, props = {}) {
|
|
5
|
+
static report(reporter, error, props = {}) {
|
|
6
6
|
if (error instanceof Error) {
|
|
7
|
-
|
|
7
|
+
reporter(`[REPORTED_ERROR]: ${error.message}\nProperties => ${JSON.stringify(props, null, 2)}\nStack => ${error.stack}`);
|
|
8
8
|
}
|
|
9
9
|
else {
|
|
10
|
-
|
|
10
|
+
reporter(`[REPORTED_ERROR]: ${JSON.stringify(error)}\nProperties => ${JSON.stringify(props, null, 2)}\n`);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/// <reference types="node" />
|
|
4
|
-
import { Hash } from 'crypto';
|
|
5
|
-
import { Transform, TransformCallback, TransformOptions } from 'stream';
|
|
1
|
+
import { Hash } from 'node:crypto';
|
|
2
|
+
import { Transform, TransformCallback, TransformOptions } from 'node:stream';
|
|
6
3
|
export declare class HashStream extends Transform {
|
|
7
4
|
hasher: Hash;
|
|
8
5
|
finalHash: Buffer;
|
|
@@ -10,6 +7,6 @@ export declare class HashStream extends Transform {
|
|
|
10
7
|
_transform(chunk: Buffer, enc: BufferEncoding, cb: TransformCallback): void;
|
|
11
8
|
_flush(cb: (err: Error | null) => void): Hash;
|
|
12
9
|
reset(): void;
|
|
13
|
-
readHash(): Buffer
|
|
14
|
-
getHash(): Buffer
|
|
10
|
+
readHash(): Buffer<ArrayBufferLike>;
|
|
11
|
+
getHash(): Buffer<ArrayBufferLike>;
|
|
15
12
|
}
|
package/dist/utils/hash.utils.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HashStream = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
class HashStream extends
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const node_stream_1 = require("node:stream");
|
|
6
|
+
class HashStream extends node_stream_1.Transform {
|
|
7
7
|
hasher;
|
|
8
8
|
finalHash;
|
|
9
9
|
constructor(opts) {
|
|
10
10
|
super(opts);
|
|
11
|
-
this.hasher = (0,
|
|
11
|
+
this.hasher = (0, node_crypto_1.createHash)('sha256');
|
|
12
12
|
this.finalHash = Buffer.alloc(0);
|
|
13
13
|
}
|
|
14
14
|
_transform(chunk, enc, cb) {
|
|
@@ -19,7 +19,7 @@ class HashStream extends stream_1.Transform {
|
|
|
19
19
|
return this.hasher.end(cb);
|
|
20
20
|
}
|
|
21
21
|
reset() {
|
|
22
|
-
this.hasher = (0,
|
|
22
|
+
this.hasher = (0, node_crypto_1.createHash)('sha256');
|
|
23
23
|
}
|
|
24
24
|
readHash() {
|
|
25
25
|
if (!this.finalHash.length) {
|
|
@@ -31,7 +31,7 @@ class HashStream extends stream_1.Transform {
|
|
|
31
31
|
if (!this.finalHash.length) {
|
|
32
32
|
this.readHash();
|
|
33
33
|
}
|
|
34
|
-
return (0,
|
|
34
|
+
return (0, node_crypto_1.createHash)('ripemd160').update(this.finalHash).digest();
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
exports.HashStream = HashStream;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InquirerUtils = void 0;
|
|
4
|
+
const prompts_1 = require("@inquirer/prompts");
|
|
5
|
+
class InquirerUtils {
|
|
6
|
+
static async prompt(message, options) {
|
|
7
|
+
switch (options.type) {
|
|
8
|
+
case 'password': {
|
|
9
|
+
return (0, prompts_1.password)({ message, mask: false });
|
|
10
|
+
}
|
|
11
|
+
case 'mask': {
|
|
12
|
+
return (0, prompts_1.password)({ message, mask: true });
|
|
13
|
+
}
|
|
14
|
+
case 'confirm': {
|
|
15
|
+
const confirmation = await (0, prompts_1.confirm)({ message, default: options.confirm?.default || false });
|
|
16
|
+
return confirmation ? 'y' : 'n';
|
|
17
|
+
}
|
|
18
|
+
case 'input': {
|
|
19
|
+
return (0, prompts_1.input)({ message });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.InquirerUtils = InquirerUtils;
|
|
@@ -10,7 +10,7 @@ export declare class NetworkUtils {
|
|
|
10
10
|
privateKey: string;
|
|
11
11
|
};
|
|
12
12
|
static generateNewSelfsignedCerts(): SelfsignedCert;
|
|
13
|
-
static getWebdavSSLCerts(): SelfsignedCert
|
|
14
|
-
static saveWebdavSSLCerts(pems: selfsigned.GenerateResult): void
|
|
13
|
+
static getWebdavSSLCerts(): Promise<SelfsignedCert>;
|
|
14
|
+
static saveWebdavSSLCerts(pems: selfsigned.GenerateResult): Promise<void>;
|
|
15
15
|
static generateSelfSignedSSLCerts(): selfsigned.GenerateResult;
|
|
16
16
|
}
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.NetworkUtils = void 0;
|
|
7
7
|
const node_crypto_1 = require("node:crypto");
|
|
8
|
-
const
|
|
8
|
+
const promises_1 = require("node:fs/promises");
|
|
9
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
10
10
|
const selfsigned_1 = __importDefault(require("selfsigned"));
|
|
11
11
|
const config_service_1 = require("../services/config.service");
|
|
@@ -28,14 +28,16 @@ class NetworkUtils {
|
|
|
28
28
|
key: newCerts.private,
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
-
static getWebdavSSLCerts() {
|
|
32
|
-
|
|
31
|
+
static async getWebdavSSLCerts() {
|
|
32
|
+
const existCert = !!(await (0, promises_1.stat)(this.WEBDAV_SSL_CERTS_PATH.cert).catch(() => false));
|
|
33
|
+
const existKey = !!(await (0, promises_1.stat)(this.WEBDAV_SSL_CERTS_PATH.privateKey).catch(() => false));
|
|
34
|
+
if (!existCert || !existKey) {
|
|
33
35
|
return this.generateNewSelfsignedCerts();
|
|
34
36
|
}
|
|
35
37
|
else {
|
|
36
38
|
let selfsignedCert = {
|
|
37
|
-
cert: (0,
|
|
38
|
-
key: (0,
|
|
39
|
+
cert: await (0, promises_1.readFile)(this.WEBDAV_SSL_CERTS_PATH.cert),
|
|
40
|
+
key: await (0, promises_1.readFile)(this.WEBDAV_SSL_CERTS_PATH.privateKey),
|
|
39
41
|
};
|
|
40
42
|
const { validTo } = new node_crypto_1.X509Certificate(selfsignedCert.cert);
|
|
41
43
|
const dateToday = new Date();
|
|
@@ -50,9 +52,9 @@ class NetworkUtils {
|
|
|
50
52
|
return selfsignedCert;
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
|
-
static saveWebdavSSLCerts(pems) {
|
|
54
|
-
(0,
|
|
55
|
-
(0,
|
|
55
|
+
static async saveWebdavSSLCerts(pems) {
|
|
56
|
+
await (0, promises_1.writeFile)(this.WEBDAV_SSL_CERTS_PATH.cert, pems.cert, 'utf8');
|
|
57
|
+
await (0, promises_1.writeFile)(this.WEBDAV_SSL_CERTS_PATH.privateKey, pems.private, 'utf8');
|
|
56
58
|
}
|
|
57
59
|
static generateSelfSignedSSLCerts() {
|
|
58
60
|
const attrs = [{ name: 'commonName', value: config_service_1.ConfigService.WEBDAV_LOCAL_URL }];
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import pm2 from 'pm2';
|
|
2
|
+
export type WebDavProcessStatus = 'online' | 'stopping' | 'stopped' | 'launching' | 'errored' | 'one-launch-status' | 'offline' | 'unknown';
|
|
2
3
|
export declare class PM2Utils {
|
|
3
4
|
private static WEBDAV_APP_NAME;
|
|
4
5
|
static connect(): Promise<void>;
|
|
6
|
+
static disconnect(): void;
|
|
7
|
+
static clean(): Promise<void>;
|
|
8
|
+
static list(): Promise<pm2.ProcessDescription[]>;
|
|
5
9
|
static killWebDavServer(): Promise<void>;
|
|
6
10
|
static webdavServerStatus(): Promise<{
|
|
7
11
|
status: WebDavProcessStatus;
|
package/dist/utils/pm2.utils.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.PM2Utils = void 0;
|
|
7
|
-
const
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
8
|
const pm2_1 = __importDefault(require("pm2"));
|
|
9
9
|
class PM2Utils {
|
|
10
10
|
static WEBDAV_APP_NAME = 'Internxt CLI WebDav';
|
|
@@ -20,6 +20,36 @@ class PM2Utils {
|
|
|
20
20
|
});
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
|
+
static disconnect() {
|
|
24
|
+
pm2_1.default.disconnect();
|
|
25
|
+
}
|
|
26
|
+
static async clean() {
|
|
27
|
+
const list = await this.list();
|
|
28
|
+
if (list.length === 0) {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
pm2_1.default.killDaemon((err) => {
|
|
31
|
+
if (err) {
|
|
32
|
+
reject(err);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
resolve();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
static list() {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
pm2_1.default.list((err, processes) => {
|
|
44
|
+
if (err) {
|
|
45
|
+
reject(err);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
resolve(processes);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
23
53
|
static killWebDavServer() {
|
|
24
54
|
return new Promise((resolve) => {
|
|
25
55
|
pm2_1.default.delete(this.WEBDAV_APP_NAME, () => {
|
|
@@ -34,7 +64,9 @@ class PM2Utils {
|
|
|
34
64
|
reject(err);
|
|
35
65
|
}
|
|
36
66
|
else if (processDescription.length === 0) {
|
|
37
|
-
|
|
67
|
+
resolve({
|
|
68
|
+
status: 'offline',
|
|
69
|
+
});
|
|
38
70
|
}
|
|
39
71
|
else {
|
|
40
72
|
const process = processDescription[0];
|
|
@@ -49,7 +81,7 @@ class PM2Utils {
|
|
|
49
81
|
return new Promise((resolve, reject) => {
|
|
50
82
|
pm2_1.default.start({
|
|
51
83
|
wait_ready: true,
|
|
52
|
-
script:
|
|
84
|
+
script: node_path_1.default.join(__dirname, '../webdav/index.js'),
|
|
53
85
|
name: this.WEBDAV_APP_NAME,
|
|
54
86
|
}, (err) => {
|
|
55
87
|
if (err) {
|