@internxt/cli 1.6.2 → 1.6.3
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 +410 -71
- package/dist/commands/add-cert.d.ts +1 -1
- package/dist/commands/add-cert.js +1 -1
- package/dist/commands/config.d.ts +7 -1
- package/dist/commands/config.js +36 -5
- package/dist/commands/create-folder.d.ts +2 -1
- package/dist/commands/create-folder.js +10 -7
- package/dist/commands/delete-permanently-file.d.ts +1 -0
- package/dist/commands/delete-permanently-folder.d.ts +1 -0
- package/dist/commands/download-file.d.ts +1 -0
- package/dist/commands/download-file.js +4 -2
- package/dist/commands/list.d.ts +1 -0
- package/dist/commands/list.js +2 -4
- package/dist/commands/login-legacy.d.ts +1 -0
- package/dist/commands/move-file.d.ts +1 -1
- package/dist/commands/move-file.js +7 -21
- package/dist/commands/move-folder.d.ts +1 -1
- package/dist/commands/move-folder.js +7 -21
- package/dist/commands/rename-file.d.ts +1 -0
- package/dist/commands/rename-folder.d.ts +1 -0
- package/dist/commands/trash-clear.d.ts +1 -0
- package/dist/commands/trash-file.d.ts +1 -0
- package/dist/commands/trash-folder.d.ts +1 -0
- package/dist/commands/trash-restore-file.d.ts +1 -1
- package/dist/commands/trash-restore-file.js +7 -21
- package/dist/commands/trash-restore-folder.d.ts +1 -1
- package/dist/commands/trash-restore-folder.js +7 -21
- package/dist/commands/upload-file.d.ts +4 -5
- package/dist/commands/upload-file.js +32 -21
- package/dist/commands/upload-folder.d.ts +1 -0
- package/dist/commands/upload-folder.js +11 -6
- package/dist/commands/webdav-config.d.ts +19 -1
- package/dist/commands/webdav-config.js +81 -3
- package/dist/commands/webdav.d.ts +1 -1
- package/dist/commands/webdav.js +10 -5
- package/dist/commands/whoami.js +2 -1
- package/dist/commands/workspaces-list.d.ts +20 -0
- package/dist/commands/workspaces-list.js +67 -0
- package/dist/commands/workspaces-unset.d.ts +23 -0
- package/dist/commands/workspaces-unset.js +45 -0
- package/dist/commands/workspaces-use.d.ts +27 -0
- package/dist/commands/workspaces-use.js +113 -0
- package/dist/constants/configs.d.ts +2 -1
- package/dist/constants/configs.js +4 -3
- package/dist/hooks/prerun/auth_check.js +13 -4
- package/dist/services/auth.service.d.ts +5 -2
- package/dist/services/auth.service.js +69 -12
- package/dist/services/config.service.d.ts +1 -1
- package/dist/services/config.service.js +12 -4
- package/dist/services/crypto.service.d.ts +5 -0
- package/dist/services/crypto.service.js +43 -0
- package/dist/services/database/database.service.d.ts +9 -0
- package/dist/services/database/database.service.js +39 -0
- package/dist/services/database/drive-file/drive-file.attributes.d.ts +3 -6
- package/dist/services/database/drive-file/drive-file.domain.d.ts +3 -6
- package/dist/services/database/drive-file/drive-file.domain.js +1 -12
- package/dist/services/database/drive-file/drive-file.model.d.ts +15 -0
- package/dist/services/database/drive-file/drive-file.model.js +67 -0
- package/dist/services/database/drive-file/drive-file.repository.d.ts +11 -0
- package/dist/services/database/drive-file/drive-file.repository.js +63 -0
- package/dist/services/database/drive-folder/drive-folder.attributes.d.ts +3 -4
- package/dist/services/database/drive-folder/drive-folder.domain.d.ts +4 -5
- package/dist/services/database/drive-folder/drive-folder.domain.js +11 -15
- package/dist/services/database/drive-folder/drive-folder.model.d.ts +11 -0
- package/dist/services/database/drive-folder/drive-folder.model.js +51 -0
- package/dist/services/database/drive-folder/drive-folder.repository.d.ts +13 -0
- package/dist/services/database/drive-folder/drive-folder.repository.js +99 -0
- package/dist/services/drive/drive-file.service.d.ts +2 -0
- package/dist/services/drive/drive-file.service.js +71 -15
- package/dist/services/drive/drive-folder.service.d.ts +6 -1
- package/dist/services/drive/drive-folder.service.js +157 -31
- package/dist/services/drive/trash.service.d.ts +3 -0
- package/dist/services/drive/trash.service.js +52 -16
- package/dist/services/drive/workspace.service.d.ts +7 -0
- package/dist/services/drive/workspace.service.js +30 -0
- package/dist/services/keys.service.d.ts +7 -0
- package/dist/services/keys.service.js +55 -0
- package/dist/services/local-filesystem/local-filesystem.service.d.ts +2 -2
- package/dist/services/local-filesystem/local-filesystem.service.js +4 -4
- package/dist/services/network/download.service.d.ts +2 -2
- package/dist/services/network/download.service.js +2 -2
- package/dist/services/network/network-facade.service.d.ts +3 -7
- package/dist/services/network/network-facade.service.js +9 -11
- package/dist/services/network/upload/upload-facade.service.d.ts +1 -1
- package/dist/services/network/upload/upload-facade.service.js +14 -7
- package/dist/services/network/upload/upload-file.service.d.ts +3 -3
- package/dist/services/network/upload/upload-file.service.js +33 -23
- package/dist/services/network/upload/upload-folder.service.d.ts +2 -2
- package/dist/services/network/upload/upload-folder.service.js +15 -10
- package/dist/services/network/upload/upload.types.d.ts +11 -0
- package/dist/services/sdk-manager.service.d.ts +9 -7
- package/dist/services/sdk-manager.service.js +27 -13
- package/dist/services/thumbnail.service.d.ts +19 -1
- package/dist/services/thumbnail.service.js +29 -2
- package/dist/services/universal-link.service.d.ts +3 -1
- package/dist/services/universal-link.service.js +15 -3
- package/dist/services/usage.service.d.ts +1 -2
- package/dist/services/usage.service.js +1 -1
- package/dist/services/validation.service.js +14 -4
- package/dist/{webdav/services → services/webdav}/webdav-folder.service.d.ts +1 -7
- package/dist/{webdav/services → services/webdav}/webdav-folder.service.js +6 -10
- package/dist/types/command.types.d.ts +44 -1
- package/dist/types/command.types.js +29 -1
- package/dist/types/config.types.d.ts +1 -0
- package/dist/types/drive.types.d.ts +7 -6
- package/dist/types/network.types.d.ts +6 -0
- package/dist/utils/async.utils.d.ts +2 -1
- package/dist/utils/async.utils.js +13 -2
- package/dist/utils/cli.utils.d.ts +20 -15
- package/dist/utils/cli.utils.js +48 -18
- package/dist/utils/crypto.utils.d.ts +3 -1
- package/dist/utils/crypto.utils.js +15 -2
- package/dist/utils/database.utils.d.ts +11 -0
- package/dist/utils/database.utils.js +26 -0
- package/dist/utils/drive.utils.js +7 -10
- package/dist/utils/errors.utils.d.ts +4 -4
- package/dist/utils/errors.utils.js +16 -19
- package/dist/utils/format.utils.d.ts +1 -0
- package/dist/utils/format.utils.js +3 -0
- package/dist/utils/inquirer.utils.js +10 -1
- package/dist/utils/path.utils.d.ts +7 -0
- package/dist/utils/path.utils.js +18 -0
- package/dist/utils/thumbnail.utils.d.ts +6 -20
- package/dist/utils/thumbnail.utils.js +16 -41
- package/dist/utils/webdav.utils.d.ts +4 -20
- package/dist/utils/webdav.utils.js +12 -14
- package/dist/webdav/handlers/DELETE.handler.d.ts +0 -9
- package/dist/webdav/handlers/DELETE.handler.js +18 -16
- package/dist/webdav/handlers/GET.handler.d.ts +0 -13
- package/dist/webdav/handlers/GET.handler.js +6 -11
- package/dist/webdav/handlers/HEAD.handler.d.ts +0 -5
- package/dist/webdav/handlers/HEAD.handler.js +11 -23
- package/dist/webdav/handlers/MKCOL.handler.d.ts +0 -7
- package/dist/webdav/handlers/MKCOL.handler.js +5 -12
- package/dist/webdav/handlers/MOVE.handler.d.ts +0 -9
- package/dist/webdav/handlers/MOVE.handler.js +10 -16
- package/dist/webdav/handlers/PROPFIND.handler.d.ts +0 -7
- package/dist/webdav/handlers/PROPFIND.handler.js +7 -19
- package/dist/webdav/handlers/PUT.handler.d.ts +0 -15
- package/dist/webdav/handlers/PUT.handler.js +24 -26
- package/dist/webdav/index.js +6 -8
- package/dist/webdav/middewares/auth.middleware.d.ts +1 -2
- package/dist/webdav/middewares/auth.middleware.js +5 -4
- package/dist/webdav/middewares/errors.middleware.js +2 -2
- package/dist/webdav/middewares/webdav-auth.middleware.d.ts +3 -0
- package/dist/webdav/middewares/webdav-auth.middleware.js +44 -0
- package/dist/webdav/webdav-server.d.ts +3 -16
- package/dist/webdav/webdav-server.js +29 -87
- package/oclif.manifest.json +429 -6
- package/package.json +25 -20
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WebDavFolderService = void 0;
|
|
4
|
+
const config_service_1 = require("../../services/config.service");
|
|
5
|
+
const drive_folder_service_1 = require("../../services/drive/drive-folder.service");
|
|
4
6
|
const errors_utils_1 = require("../../utils/errors.utils");
|
|
5
7
|
const webdav_utils_1 = require("../../utils/webdav.utils");
|
|
6
8
|
const async_utils_1 = require("../../utils/async.utils");
|
|
7
9
|
const auth_service_1 = require("../../services/auth.service");
|
|
8
10
|
const drive_utils_1 = require("../../utils/drive.utils");
|
|
9
11
|
class WebDavFolderService {
|
|
10
|
-
|
|
11
|
-
constructor(dependencies) {
|
|
12
|
-
this.dependencies = dependencies;
|
|
13
|
-
}
|
|
12
|
+
static instance = new WebDavFolderService();
|
|
14
13
|
getDriveFolderItemFromPath = async (path) => {
|
|
15
14
|
const { url } = await webdav_utils_1.WebDavUtils.getRequestedResource(path, false);
|
|
16
|
-
return await webdav_utils_1.WebDavUtils.getDriveFolderFromResource(
|
|
17
|
-
url,
|
|
18
|
-
driveFolderService: this.dependencies.driveFolderService,
|
|
19
|
-
});
|
|
15
|
+
return await webdav_utils_1.WebDavUtils.getDriveFolderFromResource(url);
|
|
20
16
|
};
|
|
21
17
|
createFolder = async ({ folderName, parentFolderUuid, }) => {
|
|
22
|
-
const [createFolderPromise] =
|
|
18
|
+
const [createFolderPromise] = await drive_folder_service_1.DriveFolderService.instance.createFolder({
|
|
23
19
|
plainName: folderName,
|
|
24
20
|
parentFolderUuid: parentFolderUuid,
|
|
25
21
|
});
|
|
@@ -28,7 +24,7 @@ class WebDavFolderService {
|
|
|
28
24
|
return drive_utils_1.DriveUtils.createFolderResponseToItem(newFolder);
|
|
29
25
|
};
|
|
30
26
|
createParentPathOrThrow = async (parentPath) => {
|
|
31
|
-
const { createFullPath } = await
|
|
27
|
+
const { createFullPath } = await config_service_1.ConfigService.instance.readWebdavConfig();
|
|
32
28
|
if (!createFullPath) {
|
|
33
29
|
throw new errors_utils_1.ConflictError(`Parent folders not found on Internxt Drive at ${webdav_utils_1.WebDavUtils.decodeUrl(parentPath, false)},
|
|
34
30
|
createFullPath flag is set to: ${createFullPath}`);
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { WorkspaceData } from '@internxt/sdk/dist/workspaces';
|
|
2
|
+
import { NetworkCredentials } from './network.types';
|
|
1
3
|
export interface LoginUserDetails {
|
|
2
4
|
userId: string;
|
|
3
5
|
uuid: string;
|
|
@@ -23,9 +25,21 @@ export interface LoginUserDetails {
|
|
|
23
25
|
avatar: string | null;
|
|
24
26
|
emailVerified: boolean;
|
|
25
27
|
}
|
|
28
|
+
export interface WorkspaceCredentialsDetails {
|
|
29
|
+
id: string;
|
|
30
|
+
bucket: string;
|
|
31
|
+
workspaceUserId: string;
|
|
32
|
+
credentials: NetworkCredentials;
|
|
33
|
+
token: string;
|
|
34
|
+
}
|
|
35
|
+
export interface Workspace {
|
|
36
|
+
workspaceData: WorkspaceData;
|
|
37
|
+
workspaceCredentials: WorkspaceCredentialsDetails;
|
|
38
|
+
}
|
|
26
39
|
export interface LoginCredentials {
|
|
27
40
|
user: LoginUserDetails;
|
|
28
41
|
token: string;
|
|
42
|
+
workspace?: Workspace;
|
|
29
43
|
}
|
|
30
44
|
export interface WebdavConfig {
|
|
31
45
|
host: string;
|
|
@@ -33,6 +47,10 @@ export interface WebdavConfig {
|
|
|
33
47
|
protocol: 'http' | 'https';
|
|
34
48
|
timeoutMinutes: number;
|
|
35
49
|
createFullPath: boolean;
|
|
50
|
+
customAuth: boolean;
|
|
51
|
+
username: string;
|
|
52
|
+
password: string;
|
|
53
|
+
deleteFilesPermanently: boolean;
|
|
36
54
|
}
|
|
37
55
|
export declare class NotValidEmailError extends Error {
|
|
38
56
|
constructor();
|
|
@@ -70,6 +88,12 @@ export declare class EmptyFileNameError extends Error {
|
|
|
70
88
|
export declare class EmptyFolderNameError extends Error {
|
|
71
89
|
constructor();
|
|
72
90
|
}
|
|
91
|
+
export declare class EmptyCustomAuthUsernameError extends Error {
|
|
92
|
+
constructor();
|
|
93
|
+
}
|
|
94
|
+
export declare class EmptyCustomAuthPasswordError extends Error {
|
|
95
|
+
constructor();
|
|
96
|
+
}
|
|
73
97
|
export declare class NotValidPortError extends Error {
|
|
74
98
|
constructor();
|
|
75
99
|
}
|
|
@@ -79,6 +103,12 @@ export declare class NotValidDirectoryError extends Error {
|
|
|
79
103
|
export declare class NotValidFileError extends Error {
|
|
80
104
|
constructor();
|
|
81
105
|
}
|
|
106
|
+
export declare class NotValidWorkspaceUuidError extends Error {
|
|
107
|
+
constructor();
|
|
108
|
+
}
|
|
109
|
+
export declare class MissingCredentialsWhenUsingAuthError extends Error {
|
|
110
|
+
constructor();
|
|
111
|
+
}
|
|
82
112
|
export interface PaginatedItem {
|
|
83
113
|
name: string;
|
|
84
114
|
type: string;
|
|
@@ -87,8 +117,21 @@ export interface PaginatedItem {
|
|
|
87
117
|
modified: string;
|
|
88
118
|
}
|
|
89
119
|
export interface PromptOptions {
|
|
90
|
-
type: 'input' | 'password' | 'mask' | 'confirm';
|
|
120
|
+
type: 'input' | 'password' | 'mask' | 'confirm' | 'list';
|
|
91
121
|
confirm?: {
|
|
92
122
|
default: boolean;
|
|
93
123
|
};
|
|
124
|
+
choices?: {
|
|
125
|
+
values: string[];
|
|
126
|
+
default?: number;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
export interface PaginatedWorkspace {
|
|
130
|
+
name: string;
|
|
131
|
+
id: string;
|
|
132
|
+
usedSpace: string;
|
|
133
|
+
availableSpace: string;
|
|
134
|
+
owner: string;
|
|
135
|
+
address: string;
|
|
136
|
+
created: string;
|
|
94
137
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NotValidFileError = exports.NotValidDirectoryError = exports.NotValidPortError = exports.EmptyFolderNameError = exports.EmptyFileNameError = exports.InvalidCredentialsError = exports.ExpiredCredentialsError = exports.MissingCredentialsError = exports.NoRootFolderIdFoundError = exports.NotValidFileIdError = exports.NotValidFileUuidError = exports.NotValidFolderUuidError = exports.NotValidTwoFactorCodeError = exports.EmptyPasswordError = exports.NotValidEmailError = void 0;
|
|
3
|
+
exports.MissingCredentialsWhenUsingAuthError = exports.NotValidWorkspaceUuidError = exports.NotValidFileError = exports.NotValidDirectoryError = exports.NotValidPortError = exports.EmptyCustomAuthPasswordError = exports.EmptyCustomAuthUsernameError = exports.EmptyFolderNameError = exports.EmptyFileNameError = exports.InvalidCredentialsError = exports.ExpiredCredentialsError = exports.MissingCredentialsError = exports.NoRootFolderIdFoundError = exports.NotValidFileIdError = 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');
|
|
@@ -85,6 +85,20 @@ class EmptyFolderNameError extends Error {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
exports.EmptyFolderNameError = EmptyFolderNameError;
|
|
88
|
+
class EmptyCustomAuthUsernameError extends Error {
|
|
89
|
+
constructor() {
|
|
90
|
+
super('Custom auth username can not be empty');
|
|
91
|
+
Object.setPrototypeOf(this, EmptyCustomAuthUsernameError.prototype);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.EmptyCustomAuthUsernameError = EmptyCustomAuthUsernameError;
|
|
95
|
+
class EmptyCustomAuthPasswordError extends Error {
|
|
96
|
+
constructor() {
|
|
97
|
+
super('Custom auth password can not be empty');
|
|
98
|
+
Object.setPrototypeOf(this, EmptyCustomAuthPasswordError.prototype);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.EmptyCustomAuthPasswordError = EmptyCustomAuthPasswordError;
|
|
88
102
|
class NotValidPortError extends Error {
|
|
89
103
|
constructor() {
|
|
90
104
|
super('Port should be a number between 1 and 65535');
|
|
@@ -106,3 +120,17 @@ class NotValidFileError extends Error {
|
|
|
106
120
|
}
|
|
107
121
|
}
|
|
108
122
|
exports.NotValidFileError = NotValidFileError;
|
|
123
|
+
class NotValidWorkspaceUuidError extends Error {
|
|
124
|
+
constructor() {
|
|
125
|
+
super('Workspace UUID is not valid (it must be a valid v4 UUID)');
|
|
126
|
+
Object.setPrototypeOf(this, NotValidWorkspaceUuidError.prototype);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.NotValidWorkspaceUuidError = NotValidWorkspaceUuidError;
|
|
130
|
+
class MissingCredentialsWhenUsingAuthError extends Error {
|
|
131
|
+
constructor() {
|
|
132
|
+
super('When using custom WebDAV authentication, both username and password must be provided');
|
|
133
|
+
Object.setPrototypeOf(this, MissingCredentialsWhenUsingAuthError.prototype);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.MissingCredentialsWhenUsingAuthError = MissingCredentialsWhenUsingAuthError;
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type DriveFileItem =
|
|
1
|
+
import { FileMeta, FolderMeta } from '@internxt/sdk/dist/drive/storage/types';
|
|
2
|
+
export type DriveFileItem = Pick<FileMeta, 'uuid' | 'name' | 'bucket' | 'folderUuid' | 'status'> & {
|
|
3
3
|
itemType: 'file';
|
|
4
4
|
size: number;
|
|
5
5
|
createdAt: Date;
|
|
6
6
|
updatedAt: Date;
|
|
7
7
|
creationTime: Date;
|
|
8
8
|
modificationTime: Date;
|
|
9
|
-
type
|
|
9
|
+
type: string | null;
|
|
10
|
+
fileId: string | null;
|
|
10
11
|
};
|
|
11
|
-
export type DriveFolderItem = Pick<
|
|
12
|
+
export type DriveFolderItem = Pick<FolderMeta, 'uuid' | 'name' | 'bucket'> & {
|
|
12
13
|
itemType: 'folder';
|
|
13
|
-
encryptedName: string;
|
|
14
|
-
uuid: string;
|
|
15
14
|
createdAt: Date;
|
|
16
15
|
updatedAt: Date;
|
|
16
|
+
creationTime: Date;
|
|
17
|
+
modificationTime: Date;
|
|
17
18
|
status: 'EXISTS' | 'TRASHED';
|
|
18
19
|
parentUuid: string | null;
|
|
19
20
|
};
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
import { NetworkFacade } from '../services/network/network-facade.service';
|
|
1
2
|
export interface NetworkCredentials {
|
|
2
3
|
user: string;
|
|
3
4
|
pass: string;
|
|
4
5
|
}
|
|
6
|
+
export interface NetworkOptions {
|
|
7
|
+
networkFacade: NetworkFacade;
|
|
8
|
+
bucket: string;
|
|
9
|
+
mnemonic: string;
|
|
10
|
+
}
|
|
5
11
|
export type DownloadProgressCallback = (downloadedBytes: number) => void;
|
|
6
12
|
export type UploadProgressCallback = (uploadedBytes: number) => void;
|
|
7
13
|
export interface NetworkOperationBaseOptions {
|
|
@@ -2,8 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AsyncUtils = void 0;
|
|
4
4
|
class AsyncUtils {
|
|
5
|
-
static sleep(ms) {
|
|
5
|
+
static sleep = (ms) => {
|
|
6
6
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
7
|
-
}
|
|
7
|
+
};
|
|
8
|
+
static withTimeout = async (promise, timeoutMs, errorMessage = 'Operation timed out') => {
|
|
9
|
+
let timeoutId;
|
|
10
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
11
|
+
timeoutId = setTimeout(() => {
|
|
12
|
+
reject(new Error(errorMessage));
|
|
13
|
+
}, timeoutMs);
|
|
14
|
+
});
|
|
15
|
+
return Promise.race([promise, timeoutPromise]).finally(() => {
|
|
16
|
+
clearTimeout(timeoutId);
|
|
17
|
+
});
|
|
18
|
+
};
|
|
8
19
|
}
|
|
9
20
|
exports.AsyncUtils = AsyncUtils;
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import cliProgress from 'cli-progress';
|
|
2
2
|
import { Header } from 'tty-table';
|
|
3
|
-
import { LoginUserDetails, PromptOptions } from '../types/command.types';
|
|
4
|
-
import {
|
|
3
|
+
import { LoginCredentials, LoginUserDetails, PromptOptions } from '../types/command.types';
|
|
4
|
+
import { NetworkCredentials, NetworkOptions } from '../types/network.types';
|
|
5
|
+
export type LogReporter = (message: string) => void;
|
|
5
6
|
export declare class CLIUtils {
|
|
6
7
|
static readonly clearPreviousLine: (jsonFlag?: boolean) => void;
|
|
7
|
-
static readonly warning: (reporter:
|
|
8
|
-
static readonly error: (reporter:
|
|
9
|
-
static readonly success: (reporter:
|
|
10
|
-
static readonly log: (reporter:
|
|
8
|
+
static readonly warning: (reporter: LogReporter, message: string) => void;
|
|
9
|
+
static readonly error: (reporter: LogReporter, message: string) => void;
|
|
10
|
+
static readonly success: (reporter: LogReporter, message: string) => void;
|
|
11
|
+
static readonly log: (reporter: LogReporter, message: string) => void;
|
|
11
12
|
static readonly consoleLog: (message: string) => void;
|
|
12
13
|
static readonly doing: (message: string, jsonFlag?: boolean) => void;
|
|
13
14
|
static readonly done: (jsonFlag?: boolean) => void;
|
|
14
15
|
static readonly failed: (jsonFlag?: boolean) => void;
|
|
15
16
|
static readonly progress: (opts: cliProgress.Options, jsonFlag?: boolean) => cliProgress.SingleBar | undefined;
|
|
16
|
-
static readonly table: (reporter:
|
|
17
|
+
static readonly table: (reporter: LogReporter, header: Header[], rows: object[]) => void;
|
|
17
18
|
static readonly generateTableHeaderFromType: <T extends object>() => Header[];
|
|
18
19
|
static readonly CommonFlags: {
|
|
19
20
|
'non-interactive': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
21
|
+
debug: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
20
22
|
};
|
|
21
23
|
static readonly getValueFromFlag: (flag: {
|
|
22
24
|
value?: string;
|
|
@@ -32,13 +34,13 @@ export declare class CLIUtils {
|
|
|
32
34
|
validate: (value: string) => Promise<boolean> | boolean;
|
|
33
35
|
error: Error;
|
|
34
36
|
canBeEmpty?: boolean;
|
|
35
|
-
}, reporter:
|
|
37
|
+
}, reporter: LogReporter) => Promise<string>;
|
|
36
38
|
static readonly getDestinationFolderUuid: ({ destinationFolderUuidFlag, destinationFlagName, nonInteractive, reporter, }: {
|
|
37
39
|
destinationFolderUuidFlag: string | undefined;
|
|
38
40
|
destinationFlagName: string;
|
|
39
41
|
nonInteractive: boolean;
|
|
40
|
-
reporter:
|
|
41
|
-
}) => Promise<string
|
|
42
|
+
reporter: LogReporter;
|
|
43
|
+
}) => Promise<string>;
|
|
42
44
|
private static readonly promptWithAttempts;
|
|
43
45
|
static readonly timer: () => {
|
|
44
46
|
stop: () => number;
|
|
@@ -49,14 +51,17 @@ export declare class CLIUtils {
|
|
|
49
51
|
static readonly catchError: ({ error, logReporter, command, jsonFlag, }: {
|
|
50
52
|
error: Error;
|
|
51
53
|
command?: string;
|
|
52
|
-
logReporter:
|
|
54
|
+
logReporter: LogReporter;
|
|
53
55
|
jsonFlag?: boolean;
|
|
54
56
|
}) => void;
|
|
55
57
|
static readonly parseEmpty: (input: string) => Promise<string>;
|
|
56
|
-
static readonly prepareNetwork: (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
static readonly prepareNetwork: (loginUserDetails: LoginUserDetails) => Promise<NetworkOptions>;
|
|
59
|
+
static readonly fallbackToRootFolderIdIfEmpty: (folderId: string) => Promise<string>;
|
|
60
|
+
static readonly getNetworkCreds: (userCredentials: LoginCredentials["user"]) => Promise<{
|
|
61
|
+
bucket: string;
|
|
62
|
+
credentials: NetworkCredentials;
|
|
63
|
+
mnemonic: string;
|
|
64
|
+
}>;
|
|
60
65
|
}
|
|
61
66
|
export declare class NoFlagProvidedError extends Error {
|
|
62
67
|
constructor(flag: string);
|
package/dist/utils/cli.utils.js
CHANGED
|
@@ -15,8 +15,7 @@ const sdk_manager_service_1 = require("../services/sdk-manager.service");
|
|
|
15
15
|
const inxt_js_1 = require("@internxt/inxt-js");
|
|
16
16
|
const config_service_1 = require("../services/config.service");
|
|
17
17
|
const network_facade_service_1 = require("../services/network/network-facade.service");
|
|
18
|
-
const
|
|
19
|
-
const crypto_service_1 = require("../services/crypto.service");
|
|
18
|
+
const auth_service_1 = require("../services/auth.service");
|
|
20
19
|
class CLIUtils {
|
|
21
20
|
static clearPreviousLine = (jsonFlag) => {
|
|
22
21
|
if (!jsonFlag) {
|
|
@@ -77,6 +76,12 @@ class CLIUtils {
|
|
|
77
76
|
description: 'Prevents the CLI from being interactive. When enabled, the CLI will not request input through the console and will throw errors directly.',
|
|
78
77
|
required: false,
|
|
79
78
|
}),
|
|
79
|
+
debug: core_1.Flags.boolean({
|
|
80
|
+
env: 'INXT_DEBUG',
|
|
81
|
+
helpGroup: 'helper',
|
|
82
|
+
description: 'Enables debug mode. When enabled, the CLI will print debug messages to the console.',
|
|
83
|
+
required: false,
|
|
84
|
+
}),
|
|
80
85
|
};
|
|
81
86
|
static getValueFromFlag = async (flag, command, validation, reporter) => {
|
|
82
87
|
if (flag.value) {
|
|
@@ -117,12 +122,7 @@ class CLIUtils {
|
|
|
117
122
|
error: new command_types_1.NotValidFolderUuidError(),
|
|
118
123
|
canBeEmpty: true,
|
|
119
124
|
}, reporter);
|
|
120
|
-
|
|
121
|
-
return undefined;
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
return destinationFolderUuid;
|
|
125
|
-
}
|
|
125
|
+
return destinationFolderUuid;
|
|
126
126
|
};
|
|
127
127
|
static promptWithAttempts = async (prompt, maxAttempts, validation, reporter) => {
|
|
128
128
|
let isValid = false;
|
|
@@ -212,22 +212,52 @@ class CLIUtils {
|
|
|
212
212
|
}
|
|
213
213
|
};
|
|
214
214
|
static parseEmpty = async (input) => (input.trim().length === 0 ? ' ' : input);
|
|
215
|
-
static prepareNetwork = (
|
|
216
|
-
|
|
215
|
+
static prepareNetwork = async (loginUserDetails) => {
|
|
216
|
+
const { credentials, mnemonic, bucket } = await this.getNetworkCreds(loginUserDetails);
|
|
217
217
|
const networkModule = sdk_manager_service_1.SdkManager.instance.getNetwork({
|
|
218
|
-
user:
|
|
219
|
-
pass:
|
|
218
|
+
user: credentials.user,
|
|
219
|
+
pass: credentials.pass,
|
|
220
220
|
});
|
|
221
221
|
const environment = new inxt_js_1.Environment({
|
|
222
|
-
bridgeUser:
|
|
223
|
-
bridgePass:
|
|
222
|
+
bridgeUser: credentials.user,
|
|
223
|
+
bridgePass: credentials.pass,
|
|
224
|
+
encryptionKey: mnemonic,
|
|
224
225
|
bridgeUrl: config_service_1.ConfigService.instance.get('NETWORK_URL'),
|
|
225
|
-
encryptionKey: loginUserDetails.mnemonic,
|
|
226
226
|
appDetails: sdk_manager_service_1.SdkManager.getAppDetails(),
|
|
227
227
|
});
|
|
228
|
-
const networkFacade = new network_facade_service_1.NetworkFacade(networkModule, environment
|
|
229
|
-
|
|
230
|
-
|
|
228
|
+
const networkFacade = new network_facade_service_1.NetworkFacade(networkModule, environment);
|
|
229
|
+
return { networkFacade, bucket, mnemonic };
|
|
230
|
+
};
|
|
231
|
+
static fallbackToRootFolderIdIfEmpty = async (folderId) => {
|
|
232
|
+
if (folderId.trim().length === 0) {
|
|
233
|
+
return await auth_service_1.AuthService.instance.getCurrentRootFolder();
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
return folderId;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
static getNetworkCreds = async (userCredentials) => {
|
|
240
|
+
const currentWorkspace = await auth_service_1.AuthService.instance.getCurrentWorkspace();
|
|
241
|
+
if (currentWorkspace) {
|
|
242
|
+
return {
|
|
243
|
+
bucket: currentWorkspace.workspaceCredentials.bucket,
|
|
244
|
+
credentials: {
|
|
245
|
+
user: currentWorkspace.workspaceCredentials.credentials.user,
|
|
246
|
+
pass: currentWorkspace.workspaceCredentials.credentials.pass,
|
|
247
|
+
},
|
|
248
|
+
mnemonic: currentWorkspace.workspaceData.workspaceUser.key,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
return {
|
|
253
|
+
bucket: userCredentials.bucket,
|
|
254
|
+
credentials: {
|
|
255
|
+
user: userCredentials.bridgeUser,
|
|
256
|
+
pass: userCredentials.userId,
|
|
257
|
+
},
|
|
258
|
+
mnemonic: userCredentials.mnemonic,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
231
261
|
};
|
|
232
262
|
}
|
|
233
263
|
exports.CLIUtils = CLIUtils;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare class CryptoUtils {
|
|
2
|
-
static getAesInit()
|
|
2
|
+
static readonly getAesInit: () => {
|
|
3
3
|
iv: string;
|
|
4
4
|
salt: string;
|
|
5
5
|
};
|
|
6
|
+
static readonly extendSecret: (secret: Uint8Array, length: number) => Promise<string>;
|
|
7
|
+
static readonly XORhex: (a: string, b: string) => string;
|
|
6
8
|
}
|
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CryptoUtils = void 0;
|
|
4
|
+
const hash_wasm_1 = require("hash-wasm");
|
|
4
5
|
const config_service_1 = require("../services/config.service");
|
|
5
6
|
class CryptoUtils {
|
|
6
|
-
static getAesInit() {
|
|
7
|
+
static getAesInit = () => {
|
|
7
8
|
return { iv: config_service_1.ConfigService.instance.get('APP_MAGIC_IV'), salt: config_service_1.ConfigService.instance.get('APP_MAGIC_SALT') };
|
|
8
|
-
}
|
|
9
|
+
};
|
|
10
|
+
static extendSecret = (secret, length) => {
|
|
11
|
+
return (0, hash_wasm_1.blake3)(secret, length);
|
|
12
|
+
};
|
|
13
|
+
static XORhex = (a, b) => {
|
|
14
|
+
let res = '', i = a.length, j = b.length;
|
|
15
|
+
if (i != j) {
|
|
16
|
+
throw new Error('Can XOR only strings with identical length');
|
|
17
|
+
}
|
|
18
|
+
while (i-- > 0 && j-- > 0)
|
|
19
|
+
res = (Number.parseInt(a.charAt(i), 16) ^ Number.parseInt(b.charAt(j), 16)).toString(16) + res;
|
|
20
|
+
return res;
|
|
21
|
+
};
|
|
9
22
|
}
|
|
10
23
|
exports.CryptoUtils = CryptoUtils;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class DatabaseUtils {
|
|
2
|
+
static readonly CREATE_BATCH_SIZE = 100;
|
|
3
|
+
static readonly getFolderByPathGeneric: <T>({ path, parentUuid, onFound, getByParentAndName, }: {
|
|
4
|
+
path: string;
|
|
5
|
+
parentUuid: string;
|
|
6
|
+
onFound: (uuid: string) => Promise<T>;
|
|
7
|
+
getByParentAndName: (parentUuid: string, name: string) => Promise<{
|
|
8
|
+
uuid: string;
|
|
9
|
+
} | null | undefined>;
|
|
10
|
+
}) => Promise<T | undefined>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DatabaseUtils = void 0;
|
|
4
|
+
class DatabaseUtils {
|
|
5
|
+
static CREATE_BATCH_SIZE = 100;
|
|
6
|
+
static getFolderByPathGeneric = async ({ path, parentUuid, onFound, getByParentAndName, }) => {
|
|
7
|
+
path = path.replace(/^\//, '').replace(/\/$/, '');
|
|
8
|
+
if (path.trim().length === 0) {
|
|
9
|
+
return onFound(parentUuid);
|
|
10
|
+
}
|
|
11
|
+
const slashIndex = path.indexOf('/');
|
|
12
|
+
const currentFolder = slashIndex === -1 ? path : path.substring(0, slashIndex);
|
|
13
|
+
const nextPath = slashIndex === -1 ? '' : path.substring(slashIndex + 1);
|
|
14
|
+
const folder = await getByParentAndName(parentUuid, currentFolder);
|
|
15
|
+
if (!folder) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
return this.getFolderByPathGeneric({
|
|
19
|
+
path: nextPath,
|
|
20
|
+
parentUuid: folder.uuid,
|
|
21
|
+
onFound,
|
|
22
|
+
getByParentAndName,
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
exports.DatabaseUtils = DatabaseUtils;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DriveUtils = void 0;
|
|
4
|
+
const types_1 = require("@internxt/sdk/dist/drive/storage/types");
|
|
4
5
|
class DriveUtils {
|
|
5
6
|
static driveFileMetaToItem(fileMeta) {
|
|
6
7
|
return {
|
|
7
8
|
itemType: 'file',
|
|
8
9
|
uuid: fileMeta.uuid ?? '',
|
|
9
10
|
status: fileMeta.status,
|
|
10
|
-
folderId: fileMeta.folderId,
|
|
11
11
|
folderUuid: fileMeta.folderUuid,
|
|
12
12
|
size: Number(fileMeta.size),
|
|
13
13
|
name: fileMeta.plainName ?? fileMeta.name,
|
|
@@ -17,7 +17,6 @@ class DriveUtils {
|
|
|
17
17
|
creationTime: new Date(fileMeta.creationTime ?? fileMeta.createdAt),
|
|
18
18
|
modificationTime: new Date(fileMeta.modificationTime ?? fileMeta.updatedAt),
|
|
19
19
|
fileId: fileMeta.fileId,
|
|
20
|
-
id: fileMeta.id,
|
|
21
20
|
type: fileMeta.type,
|
|
22
21
|
};
|
|
23
22
|
}
|
|
@@ -25,30 +24,28 @@ class DriveUtils {
|
|
|
25
24
|
return {
|
|
26
25
|
itemType: 'folder',
|
|
27
26
|
uuid: folderMeta.uuid,
|
|
28
|
-
id: folderMeta.id,
|
|
29
27
|
bucket: folderMeta.bucket,
|
|
30
|
-
status: folderMeta.deleted || folderMeta.removed ?
|
|
28
|
+
status: folderMeta.deleted || folderMeta.removed ? types_1.FileStatus.TRASHED : types_1.FileStatus.EXISTS,
|
|
31
29
|
name: folderMeta.plainName ?? folderMeta.name,
|
|
32
|
-
encryptedName: folderMeta.name,
|
|
33
|
-
parentId: folderMeta.parentId,
|
|
34
30
|
parentUuid: folderMeta.parentUuid,
|
|
35
31
|
createdAt: new Date(folderMeta.createdAt),
|
|
36
32
|
updatedAt: new Date(folderMeta.updatedAt),
|
|
33
|
+
creationTime: new Date(folderMeta.creation_time),
|
|
34
|
+
modificationTime: new Date(folderMeta.creation_time),
|
|
37
35
|
};
|
|
38
36
|
}
|
|
39
37
|
static createFolderResponseToItem(folderResponse) {
|
|
40
38
|
return {
|
|
41
39
|
itemType: 'folder',
|
|
42
40
|
uuid: folderResponse.uuid,
|
|
43
|
-
id: folderResponse.id,
|
|
44
41
|
bucket: folderResponse.bucket,
|
|
45
|
-
status: folderResponse.deleted || folderResponse.removed ?
|
|
42
|
+
status: folderResponse.deleted || folderResponse.removed ? types_1.FileStatus.TRASHED : types_1.FileStatus.EXISTS,
|
|
46
43
|
name: folderResponse.plainName ?? folderResponse.name,
|
|
47
|
-
encryptedName: folderResponse.name,
|
|
48
|
-
parentId: folderResponse.parentId,
|
|
49
44
|
parentUuid: folderResponse.parentUuid,
|
|
50
45
|
createdAt: new Date(folderResponse.createdAt),
|
|
51
46
|
updatedAt: new Date(folderResponse.updatedAt),
|
|
47
|
+
creationTime: new Date(folderResponse.creationTime),
|
|
48
|
+
modificationTime: new Date(folderResponse.modificationTime),
|
|
52
49
|
};
|
|
53
50
|
}
|
|
54
51
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export declare function isError(error: unknown): error is Error;
|
|
2
|
-
export declare function isAlreadyExistsError(error: unknown): error is Error;
|
|
3
|
-
export declare function isFileNotFoundError(error: unknown): error is NodeJS.ErrnoException;
|
|
4
1
|
export declare class ErrorUtils {
|
|
5
|
-
static
|
|
2
|
+
static readonly isError: (error: unknown) => error is Error;
|
|
3
|
+
static readonly report: (error: unknown, props?: Record<string, unknown>) => void;
|
|
4
|
+
static readonly isAlreadyExistsError: (error: unknown) => error is Error;
|
|
5
|
+
static readonly isFileNotFoundError: (error: unknown) => error is NodeJS.ErrnoException;
|
|
6
6
|
}
|
|
7
7
|
export declare class ConflictError extends Error {
|
|
8
8
|
statusCode: number;
|
|
@@ -1,32 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NotImplementedError = exports.MethodNotAllowed = exports.UnsupportedMediaTypeError = exports.BadRequestError = exports.NotFoundError = exports.ConflictError = exports.ErrorUtils = void 0;
|
|
4
|
-
exports.isError = isError;
|
|
5
|
-
exports.isAlreadyExistsError = isAlreadyExistsError;
|
|
6
|
-
exports.isFileNotFoundError = isFileNotFoundError;
|
|
7
4
|
const logger_utils_1 = require("./logger.utils");
|
|
8
|
-
function isError(error) {
|
|
9
|
-
return typeof Error.isError === 'function'
|
|
10
|
-
? Error.isError(error)
|
|
11
|
-
: error instanceof Error ||
|
|
12
|
-
(typeof error === 'object' && error !== null && 'message' in error && ('stack' in error || 'name' in error));
|
|
13
|
-
}
|
|
14
|
-
function isAlreadyExistsError(error) {
|
|
15
|
-
return ((isError(error) && error.message.includes('already exists')) ||
|
|
16
|
-
(typeof error === 'object' && error !== null && 'status' in error && error.status === 409));
|
|
17
|
-
}
|
|
18
|
-
function isFileNotFoundError(error) {
|
|
19
|
-
return isError(error) && 'code' in error && error.code === 'ENOENT';
|
|
20
|
-
}
|
|
21
5
|
class ErrorUtils {
|
|
22
|
-
static
|
|
23
|
-
|
|
6
|
+
static isError = (error) => {
|
|
7
|
+
return typeof Error.isError === 'function'
|
|
8
|
+
? Error.isError(error)
|
|
9
|
+
: error instanceof Error ||
|
|
10
|
+
(typeof error === 'object' && error !== null && 'message' in error && ('stack' in error || 'name' in error));
|
|
11
|
+
};
|
|
12
|
+
static report = (error, props = {}) => {
|
|
13
|
+
if (this.isError(error)) {
|
|
24
14
|
logger_utils_1.logger.error(`[REPORTED_ERROR]: ${error.message}\nProperties => ${JSON.stringify(props, null, 2)}\nStack => ${error.stack}`);
|
|
25
15
|
}
|
|
26
16
|
else {
|
|
27
17
|
logger_utils_1.logger.error(`[REPORTED_ERROR]: ${JSON.stringify(error)}\nProperties => ${JSON.stringify(props, null, 2)}\n`);
|
|
28
18
|
}
|
|
29
|
-
}
|
|
19
|
+
};
|
|
20
|
+
static isAlreadyExistsError = (error) => {
|
|
21
|
+
return ((this.isError(error) && error.message.includes('already exists')) ||
|
|
22
|
+
(typeof error === 'object' && error !== null && 'status' in error && error.status === 409));
|
|
23
|
+
};
|
|
24
|
+
static isFileNotFoundError = (error) => {
|
|
25
|
+
return this.isError(error) && 'code' in error && error.code === 'ENOENT';
|
|
26
|
+
};
|
|
30
27
|
}
|
|
31
28
|
exports.ErrorUtils = ErrorUtils;
|
|
32
29
|
class ConflictError extends Error {
|
|
@@ -3,4 +3,5 @@ export declare class FormatUtils {
|
|
|
3
3
|
static readonly formatDate: (date: string | Date) => string;
|
|
4
4
|
static readonly formatDateForWebDav: (date: string | Date) => string;
|
|
5
5
|
static readonly formatLimit: (limit: number) => string;
|
|
6
|
+
static readonly capitalizeFirstLetter: (string: string) => string;
|
|
6
7
|
}
|