@internxt/cli 1.6.1 → 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 +3 -3
- 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/logs.js +3 -3
- 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 +5 -6
- package/dist/commands/upload-file.js +77 -52
- 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 +13 -0
- package/dist/constants/configs.js +21 -0
- package/dist/hooks/prerun/auth_check.js +13 -4
- package/dist/services/auth.service.d.ts +5 -2
- package/dist/services/auth.service.js +68 -6
- package/dist/services/config.service.d.ts +1 -13
- package/dist/services/config.service.js +44 -41
- 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 +15 -8
- package/dist/services/network/upload/upload-file.service.d.ts +5 -4
- package/dist/services/network/upload/upload-file.service.js +73 -41
- 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 +13 -2
- package/dist/services/network/upload/upload.types.js +1 -1
- package/dist/services/sdk-manager.service.d.ts +11 -9
- package/dist/services/sdk-manager.service.js +29 -15
- 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.d.ts +5 -0
- package/dist/services/validation.service.js +36 -22
- 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 +23 -15
- package/dist/utils/cli.utils.js +85 -21
- 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 -3
- package/dist/utils/errors.utils.js +16 -13
- 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/logger.utils.js +5 -5
- package/dist/utils/network.utils.js +17 -18
- 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 +20 -45
- package/dist/utils/webdav.utils.d.ts +4 -20
- package/dist/utils/webdav.utils.js +12 -14
- package/dist/utils/xml.utils.d.ts +1 -1
- package/dist/utils/xml.utils.js +1 -1
- 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 -13
- 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 +70 -57
- 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 +3 -3
- 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 +33 -91
- package/oclif.manifest.json +429 -6
- package/package.json +27 -22
|
@@ -1,7 +1,25 @@
|
|
|
1
|
+
import { Readable } from 'node:stream';
|
|
1
2
|
import { StorageTypes } from '@internxt/sdk/dist/drive';
|
|
2
3
|
import { NetworkFacade } from './network/network-facade.service';
|
|
4
|
+
import { BufferStream } from '../utils/stream.utils';
|
|
3
5
|
export declare class ThumbnailService {
|
|
4
6
|
static readonly instance: ThumbnailService;
|
|
5
|
-
|
|
7
|
+
private static readonly MAX_THUMBNAIL_TIMEOUT;
|
|
8
|
+
uploadThumbnail: (fileContent: Buffer, fileType: string, userBucket: string, file_id: string, networkFacade: NetworkFacade, fileSize: number) => Promise<StorageTypes.Thumbnail | undefined>;
|
|
6
9
|
private readonly getThumbnailFromImageBuffer;
|
|
10
|
+
tryUploadThumbnail: ({ bufferStream, fileType, bucket, fileUuid, networkFacade, size, }: {
|
|
11
|
+
bufferStream?: BufferStream;
|
|
12
|
+
fileType: string;
|
|
13
|
+
bucket: string;
|
|
14
|
+
fileUuid: string;
|
|
15
|
+
networkFacade: NetworkFacade;
|
|
16
|
+
size: number;
|
|
17
|
+
}) => Promise<void>;
|
|
18
|
+
createFileStreamWithBuffer: ({ path, fileType, }: {
|
|
19
|
+
path: string;
|
|
20
|
+
fileType: string;
|
|
21
|
+
}) => {
|
|
22
|
+
bufferStream?: BufferStream;
|
|
23
|
+
fileStream: Readable;
|
|
24
|
+
};
|
|
7
25
|
}
|
|
@@ -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,9 +23,10 @@ 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) {
|
|
@@ -62,5 +67,27 @@ class ThumbnailService {
|
|
|
62
67
|
.toBuffer();
|
|
63
68
|
}
|
|
64
69
|
};
|
|
70
|
+
tryUploadThumbnail = async ({ bufferStream, fileType, bucket, fileUuid, networkFacade, size, }) => {
|
|
71
|
+
try {
|
|
72
|
+
const thumbnailBuffer = bufferStream?.getBuffer();
|
|
73
|
+
if (thumbnailBuffer) {
|
|
74
|
+
await async_utils_1.AsyncUtils.withTimeout(ThumbnailService.instance.uploadThumbnail(thumbnailBuffer, fileType, bucket, fileUuid, networkFacade, size), ThumbnailService.MAX_THUMBNAIL_TIMEOUT, 'Thumbnail upload timeout');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
errors_utils_1.ErrorUtils.report(error);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
createFileStreamWithBuffer = ({ path, fileType, }) => {
|
|
82
|
+
const readable = (0, node_fs_1.createReadStream)(path);
|
|
83
|
+
if (thumbnail_utils_1.ThumbnailUtils.isFileThumbnailable(fileType)) {
|
|
84
|
+
const bufferStream = new stream_utils_1.BufferStream();
|
|
85
|
+
return {
|
|
86
|
+
bufferStream,
|
|
87
|
+
fileStream: readable.pipe(bufferStream),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return { fileStream: readable };
|
|
91
|
+
};
|
|
65
92
|
}
|
|
66
93
|
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();
|
|
@@ -9,6 +9,11 @@ export declare class ValidationService {
|
|
|
9
9
|
validateStringIsNotEmpty: (str: string) => boolean;
|
|
10
10
|
validateDirectoryExists: (path: string) => Promise<boolean>;
|
|
11
11
|
validateFileExists: (path: string) => Promise<boolean>;
|
|
12
|
+
validateJwtAndCheckExpiration: (token?: string) => number | null;
|
|
13
|
+
checkTokenExpiration: (expirationTimestamp: number) => {
|
|
14
|
+
expired: boolean;
|
|
15
|
+
refreshRequired: boolean;
|
|
16
|
+
};
|
|
12
17
|
validateTokenAndCheckExpiration: (token?: string) => {
|
|
13
18
|
isValid: boolean;
|
|
14
19
|
expiration: {
|
|
@@ -31,36 +31,50 @@ 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
|
-
|
|
40
|
-
|
|
41
|
-
validateTokenAndCheckExpiration = (token) => {
|
|
42
|
-
if (!token || typeof token !== 'string') {
|
|
43
|
-
return { isValid: false, expiration: { expired: true, refreshRequired: false } };
|
|
43
|
+
try {
|
|
44
|
+
const fileStat = await promises_1.default.stat(path);
|
|
45
|
+
return fileStat.isFile();
|
|
44
46
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
validateJwtAndCheckExpiration = (token) => {
|
|
52
|
+
if (!token || typeof token !== 'string' || token.split('.').length !== 3) {
|
|
53
|
+
return null;
|
|
48
54
|
}
|
|
49
55
|
try {
|
|
50
|
-
const payload = JSON.parse(atob(
|
|
51
|
-
|
|
52
|
-
return { isValid: false, expiration: { expired: true, refreshRequired: false } };
|
|
53
|
-
}
|
|
54
|
-
const currentTime = Math.floor(Date.now() / 1000);
|
|
55
|
-
const twoDaysInSeconds = 2 * 24 * 60 * 60;
|
|
56
|
-
const remainingSeconds = payload.exp - currentTime;
|
|
57
|
-
const expired = remainingSeconds <= 0;
|
|
58
|
-
const refreshRequired = remainingSeconds > 0 && remainingSeconds <= twoDaysInSeconds;
|
|
59
|
-
return { isValid: true, expiration: { expired, refreshRequired } };
|
|
56
|
+
const payload = JSON.parse(atob(token.split('.')[1]));
|
|
57
|
+
return typeof payload.exp === 'number' ? payload.exp : null;
|
|
60
58
|
}
|
|
61
59
|
catch {
|
|
62
|
-
return
|
|
60
|
+
return null;
|
|
63
61
|
}
|
|
64
62
|
};
|
|
63
|
+
checkTokenExpiration = (expirationTimestamp) => {
|
|
64
|
+
const TWO_DAYS_IN_SECONDS = 2 * 24 * 60 * 60;
|
|
65
|
+
const currentTime = Math.floor(Date.now() / 1000);
|
|
66
|
+
const remainingSeconds = expirationTimestamp - currentTime;
|
|
67
|
+
return {
|
|
68
|
+
expired: remainingSeconds <= 0,
|
|
69
|
+
refreshRequired: remainingSeconds > 0 && remainingSeconds <= TWO_DAYS_IN_SECONDS,
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
validateTokenAndCheckExpiration = (token) => {
|
|
73
|
+
const expiration = this.validateJwtAndCheckExpiration(token);
|
|
74
|
+
return {
|
|
75
|
+
isValid: expiration !== null,
|
|
76
|
+
expiration: expiration ? this.checkTokenExpiration(expiration) : { expired: true, refreshRequired: false },
|
|
77
|
+
};
|
|
78
|
+
};
|
|
65
79
|
}
|
|
66
80
|
exports.ValidationService = ValidationService;
|
|
@@ -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,28 +34,34 @@ 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;
|
|
45
47
|
};
|
|
48
|
+
static readonly formatDuration: (milliseconds: number) => string;
|
|
49
|
+
static readonly formatBytesToString: (bytes: number) => string;
|
|
50
|
+
static readonly calculateThroughputMBps: (bytes: number, milliseconds: number) => number;
|
|
46
51
|
static readonly catchError: ({ error, logReporter, command, jsonFlag, }: {
|
|
47
52
|
error: Error;
|
|
48
53
|
command?: string;
|
|
49
|
-
logReporter:
|
|
54
|
+
logReporter: LogReporter;
|
|
50
55
|
jsonFlag?: boolean;
|
|
51
56
|
}) => void;
|
|
52
57
|
static readonly parseEmpty: (input: string) => Promise<string>;
|
|
53
|
-
static readonly prepareNetwork: (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
+
}>;
|
|
57
65
|
}
|
|
58
66
|
export declare class NoFlagProvidedError extends Error {
|
|
59
67
|
constructor(flag: string);
|