@internxt/cli 1.6.2 → 1.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +411 -72
- 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 +42 -31
- 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 +11 -8
- package/dist/services/network/network-facade.service.js +19 -32
- 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 +38 -30
- 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 +34 -9
- 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 +5 -20
- package/dist/utils/webdav.utils.js +31 -14
- package/dist/utils/xml.utils.d.ts +1 -1
- package/dist/webdav/handlers/DELETE.handler.d.ts +0 -9
- package/dist/webdav/handlers/DELETE.handler.js +2 -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 +37 -43
- 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 +27 -22
- package/dist/types/fast-xml-parser.types.d.ts +0 -59
- package/dist/types/fast-xml-parser.types.js +0 -2
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ThumbnailService = void 0;
|
|
4
4
|
const node_stream_1 = require("node:stream");
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
5
6
|
const drive_file_service_1 = require("./drive/drive-file.service");
|
|
6
7
|
const drive_1 = require("@internxt/sdk/dist/drive");
|
|
7
8
|
const thumbnail_utils_1 = require("../utils/thumbnail.utils");
|
|
9
|
+
const stream_utils_1 = require("../utils/stream.utils");
|
|
10
|
+
const errors_utils_1 = require("../utils/errors.utils");
|
|
11
|
+
const async_utils_1 = require("../utils/async.utils");
|
|
8
12
|
let sharpDependency = null;
|
|
9
13
|
const getSharp = async () => {
|
|
10
14
|
if (!sharpDependency) {
|
|
@@ -19,20 +23,19 @@ const getSharp = async () => {
|
|
|
19
23
|
};
|
|
20
24
|
class ThumbnailService {
|
|
21
25
|
static instance = new ThumbnailService();
|
|
22
|
-
|
|
26
|
+
static MAX_THUMBNAIL_TIMEOUT = 30000;
|
|
27
|
+
uploadThumbnail = async (fileContent, fileType, userBucket, file_id, networkFacade, fileSize) => {
|
|
23
28
|
let thumbnailBuffer;
|
|
24
|
-
if (
|
|
29
|
+
if (thumbnail_utils_1.ThumbnailUtils.isImageThumbnailable(fileType, fileSize)) {
|
|
25
30
|
thumbnailBuffer = await this.getThumbnailFromImageBuffer(fileContent);
|
|
26
31
|
}
|
|
27
32
|
if (thumbnailBuffer) {
|
|
28
33
|
const size = thumbnailBuffer.length;
|
|
29
|
-
const fileId = await
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
resolve(res);
|
|
35
|
-
}, () => { });
|
|
34
|
+
const fileId = await networkFacade.uploadFile({
|
|
35
|
+
from: node_stream_1.Readable.from(thumbnailBuffer),
|
|
36
|
+
size: size,
|
|
37
|
+
bucketId: userBucket,
|
|
38
|
+
progressCallback: () => { },
|
|
36
39
|
});
|
|
37
40
|
const createdThumbnailFile = await drive_file_service_1.DriveFileService.instance.createThumbnail({
|
|
38
41
|
fileUuid: file_id,
|
|
@@ -62,5 +65,27 @@ class ThumbnailService {
|
|
|
62
65
|
.toBuffer();
|
|
63
66
|
}
|
|
64
67
|
};
|
|
68
|
+
tryUploadThumbnail = async ({ bufferStream, fileType, bucket, fileUuid, networkFacade, size, }) => {
|
|
69
|
+
try {
|
|
70
|
+
const thumbnailBuffer = bufferStream?.getBuffer();
|
|
71
|
+
if (thumbnailBuffer) {
|
|
72
|
+
await async_utils_1.AsyncUtils.withTimeout(ThumbnailService.instance.uploadThumbnail(thumbnailBuffer, fileType, bucket, fileUuid, networkFacade, size), ThumbnailService.MAX_THUMBNAIL_TIMEOUT, 'Thumbnail upload timeout');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
errors_utils_1.ErrorUtils.report(error);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
createFileStreamWithBuffer = ({ path, fileType, }) => {
|
|
80
|
+
const readable = (0, node_fs_1.createReadStream)(path);
|
|
81
|
+
if (thumbnail_utils_1.ThumbnailUtils.isFileThumbnailable(fileType)) {
|
|
82
|
+
const bufferStream = new stream_utils_1.BufferStream();
|
|
83
|
+
return {
|
|
84
|
+
bufferStream,
|
|
85
|
+
fileStream: readable.pipe(bufferStream),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return { fileStream: readable };
|
|
89
|
+
};
|
|
65
90
|
}
|
|
66
91
|
exports.ThumbnailService = ThumbnailService;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { LoginCredentials } from '../types/command.types';
|
|
2
|
+
import { LogReporter } from '../utils/cli.utils';
|
|
2
3
|
export declare class UniversalLinkService {
|
|
3
4
|
static readonly instance: UniversalLinkService;
|
|
4
5
|
getUserCredentials: (userSession: {
|
|
5
6
|
mnemonic: string;
|
|
6
7
|
token: string;
|
|
8
|
+
privateKey: string;
|
|
7
9
|
}) => Promise<LoginCredentials>;
|
|
8
10
|
buildLoginUrl: (redirectUri: string) => string;
|
|
9
|
-
loginSSO: (jsonFlag: boolean, reporter:
|
|
11
|
+
loginSSO: (jsonFlag: boolean, reporter: LogReporter, hostIp?: string, forcedPort?: number) => Promise<LoginCredentials>;
|
|
10
12
|
}
|
|
@@ -14,11 +14,22 @@ class UniversalLinkService {
|
|
|
14
14
|
getUserCredentials = async (userSession) => {
|
|
15
15
|
const clearMnemonic = Buffer.from(userSession.mnemonic, 'base64').toString('utf-8');
|
|
16
16
|
const clearToken = Buffer.from(userSession.token, 'base64').toString('utf-8');
|
|
17
|
-
const
|
|
17
|
+
const clearPrivateKey = Buffer.from(userSession.privateKey, 'base64').toString('utf-8');
|
|
18
|
+
const loginCredentials = await auth_service_1.AuthService.instance.refreshUserToken(clearToken, clearMnemonic, clearPrivateKey);
|
|
18
19
|
return {
|
|
19
20
|
user: {
|
|
20
21
|
...loginCredentials.user,
|
|
21
22
|
mnemonic: clearMnemonic,
|
|
23
|
+
keys: {
|
|
24
|
+
ecc: {
|
|
25
|
+
privateKey: clearPrivateKey,
|
|
26
|
+
publicKey: loginCredentials.user.keys.ecc.publicKey,
|
|
27
|
+
},
|
|
28
|
+
kyber: {
|
|
29
|
+
privateKey: loginCredentials.user.keys.kyber.privateKey,
|
|
30
|
+
publicKey: loginCredentials.user.keys.kyber.publicKey,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
22
33
|
},
|
|
23
34
|
token: clearToken,
|
|
24
35
|
};
|
|
@@ -41,10 +52,11 @@ class UniversalLinkService {
|
|
|
41
52
|
try {
|
|
42
53
|
const mnemonic = parsedUrl.searchParams.get('mnemonic');
|
|
43
54
|
const token = parsedUrl.searchParams.get('newToken');
|
|
44
|
-
|
|
55
|
+
const privateKey = parsedUrl.searchParams.get('privateKey');
|
|
56
|
+
if (!mnemonic || !token || !privateKey) {
|
|
45
57
|
throw new Error('Login has failed, please try again');
|
|
46
58
|
}
|
|
47
|
-
const loginCredentials = await this.getUserCredentials({ mnemonic, token });
|
|
59
|
+
const loginCredentials = await this.getUserCredentials({ mnemonic, token, privateKey });
|
|
48
60
|
res.writeHead(302, {
|
|
49
61
|
Location: `${driveUrl}/auth-link-ok`,
|
|
50
62
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { UsageResponseV2 } from '@internxt/sdk/dist/drive/storage/types';
|
|
2
1
|
export declare class UsageService {
|
|
3
2
|
static readonly instance: UsageService;
|
|
4
3
|
static readonly INFINITE_LIMIT: number;
|
|
5
|
-
fetchUsage: () => Promise<
|
|
4
|
+
fetchUsage: () => Promise<number>;
|
|
6
5
|
fetchSpaceLimit: () => Promise<number>;
|
|
7
6
|
}
|
|
@@ -8,7 +8,7 @@ class UsageService {
|
|
|
8
8
|
fetchUsage = async () => {
|
|
9
9
|
const storageClient = sdk_manager_service_1.SdkManager.instance.getStorage();
|
|
10
10
|
const driveUsage = await storageClient.spaceUsageV2();
|
|
11
|
-
return driveUsage;
|
|
11
|
+
return driveUsage.total;
|
|
12
12
|
};
|
|
13
13
|
fetchSpaceLimit = async () => {
|
|
14
14
|
const storageClient = sdk_manager_service_1.SdkManager.instance.getStorage();
|
|
@@ -31,12 +31,22 @@ class ValidationService {
|
|
|
31
31
|
return str.trim().length > 0;
|
|
32
32
|
};
|
|
33
33
|
validateDirectoryExists = async (path) => {
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
try {
|
|
35
|
+
const directoryStat = await promises_1.default.stat(path);
|
|
36
|
+
return directoryStat.isDirectory();
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
36
41
|
};
|
|
37
42
|
validateFileExists = async (path) => {
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
try {
|
|
44
|
+
const fileStat = await promises_1.default.stat(path);
|
|
45
|
+
return fileStat.isFile();
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
40
50
|
};
|
|
41
51
|
validateJwtAndCheckExpiration = (token) => {
|
|
42
52
|
if (!token || typeof token !== 'string' || token.split('.').length !== 3) {
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import { ConfigService } from '../../services/config.service';
|
|
2
|
-
import { DriveFolderService } from '../../services/drive/drive-folder.service';
|
|
3
1
|
import { DriveFolderItem } from '../../types/drive.types';
|
|
4
2
|
export declare class WebDavFolderService {
|
|
5
|
-
|
|
6
|
-
constructor(dependencies: {
|
|
7
|
-
driveFolderService: DriveFolderService;
|
|
8
|
-
configService: ConfigService;
|
|
9
|
-
});
|
|
3
|
+
static readonly instance: WebDavFolderService;
|
|
10
4
|
getDriveFolderItemFromPath: (path: string) => Promise<DriveFolderItem | undefined>;
|
|
11
5
|
createFolder: ({ folderName, parentFolderUuid, }: {
|
|
12
6
|
folderName: string;
|
|
@@ -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;
|