@internxt/cli 1.6.7 → 1.6.8

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.
Files changed (76) hide show
  1. package/README.md +36 -231
  2. package/dist/commands/create-folder.js +2 -6
  3. package/dist/commands/delete-permanently-file.js +1 -1
  4. package/dist/commands/delete-permanently-folder.js +1 -1
  5. package/dist/commands/download-file.js +3 -3
  6. package/dist/commands/list.d.ts +2 -0
  7. package/dist/commands/list.js +1 -1
  8. package/dist/commands/login.d.ts +0 -1
  9. package/dist/commands/login.js +1 -11
  10. package/dist/commands/move-file.d.ts +1 -0
  11. package/dist/commands/move-file.js +1 -1
  12. package/dist/commands/move-folder.js +1 -1
  13. package/dist/commands/rename-file.js +1 -1
  14. package/dist/commands/rename-folder.js +1 -1
  15. package/dist/commands/trash-file.js +1 -1
  16. package/dist/commands/trash-folder.js +1 -1
  17. package/dist/commands/trash-list.d.ts +2 -0
  18. package/dist/commands/trash-restore-file.d.ts +1 -0
  19. package/dist/commands/trash-restore-file.js +1 -1
  20. package/dist/commands/trash-restore-folder.js +1 -1
  21. package/dist/commands/upload-file.d.ts +1 -0
  22. package/dist/commands/upload-file.js +22 -13
  23. package/dist/hooks/prerun/auth_check.js +2 -2
  24. package/dist/services/auth.service.d.ts +3 -3
  25. package/dist/services/auth.service.js +30 -40
  26. package/dist/services/crypto.service.d.ts +0 -4
  27. package/dist/services/crypto.service.js +1 -32
  28. package/dist/services/database/drive-item/drive-item.model.js +1 -0
  29. package/dist/services/database/drive-item/drive-item.repository.js +12 -2
  30. package/dist/services/drive/drive-file.service.d.ts +2 -0
  31. package/dist/services/drive/drive-file.service.js +48 -18
  32. package/dist/services/drive/drive-folder.service.d.ts +2 -0
  33. package/dist/services/drive/drive-folder.service.js +14 -46
  34. package/dist/services/drive/trash.service.d.ts +2 -0
  35. package/dist/services/drive/trash.service.js +14 -41
  36. package/dist/services/network/upload/upload-file.service.js +5 -9
  37. package/dist/services/network/upload/upload.types.d.ts +2 -1
  38. package/dist/services/sdk-manager.service.d.ts +0 -2
  39. package/dist/services/sdk-manager.service.js +0 -7
  40. package/dist/services/thumbnail.service.d.ts +4 -13
  41. package/dist/services/thumbnail.service.js +7 -21
  42. package/dist/services/universal-link.service.d.ts +1 -1
  43. package/dist/services/universal-link.service.js +2 -2
  44. package/dist/services/validation.service.d.ts +1 -1
  45. package/dist/services/validation.service.js +3 -2
  46. package/dist/types/command.types.d.ts +0 -29
  47. package/dist/types/command.types.js +1 -15
  48. package/dist/types/network.types.d.ts +3 -11
  49. package/dist/types/webdav.types.d.ts +0 -3
  50. package/dist/utils/cli.utils.js +9 -22
  51. package/dist/utils/logger.utils.js +9 -2
  52. package/dist/utils/stream.utils.d.ts +2 -2
  53. package/dist/utils/stream.utils.js +7 -6
  54. package/dist/utils/thumbnail.utils.d.ts +1 -3
  55. package/dist/utils/thumbnail.utils.js +3 -13
  56. package/dist/utils/upload.utils.d.ts +1 -1
  57. package/dist/utils/upload.utils.js +2 -2
  58. package/dist/utils/webdav.utils.d.ts +2 -0
  59. package/dist/utils/webdav.utils.js +16 -0
  60. package/dist/webdav/handlers/GET.handler.js +3 -2
  61. package/dist/webdav/handlers/HEAD.handler.js +1 -0
  62. package/dist/webdav/handlers/PROPFIND.handler.js +3 -4
  63. package/dist/webdav/handlers/PUT.handler.js +24 -10
  64. package/dist/webdav/index.js +2 -2
  65. package/dist/webdav/middewares/auth.middleware.js +1 -1
  66. package/dist/webdav/middewares/errors.middleware.js +29 -5
  67. package/oclif.manifest.json +9 -198
  68. package/package.json +18 -17
  69. package/dist/commands/workspaces-list.d.ts +0 -20
  70. package/dist/commands/workspaces-list.js +0 -68
  71. package/dist/commands/workspaces-unset.d.ts +0 -23
  72. package/dist/commands/workspaces-unset.js +0 -46
  73. package/dist/commands/workspaces-use.d.ts +0 -27
  74. package/dist/commands/workspaces-use.js +0 -114
  75. package/dist/services/drive/workspace.service.d.ts +0 -7
  76. package/dist/services/drive/workspace.service.js +0 -30
@@ -1,23 +0,0 @@
1
- import { Command } from '@oclif/core';
2
- import { LogReporter } from '../utils/cli.utils';
3
- import { LoginCredentials } from '../types/command.types';
4
- export default class WorkspacesUnset extends Command {
5
- static readonly args: {};
6
- static readonly description: string;
7
- static readonly aliases: string[];
8
- static readonly examples: string[];
9
- static readonly flags: {
10
- 'non-interactive': import("@oclif/core/interfaces").BooleanFlag<boolean>;
11
- debug: import("@oclif/core/interfaces").BooleanFlag<boolean>;
12
- };
13
- static readonly enableJsonFlag = true;
14
- run: () => Promise<{
15
- success: boolean;
16
- message: string;
17
- }>;
18
- catch: (error: Error) => Promise<never>;
19
- static readonly unsetWorkspace: (userCredentials: LoginCredentials, reporter: LogReporter) => Promise<{
20
- success: boolean;
21
- message: string;
22
- }>;
23
- }
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const core_1 = require("@oclif/core");
4
- const config_service_1 = require("../services/config.service");
5
- const cli_utils_1 = require("../utils/cli.utils");
6
- const command_types_1 = require("../types/command.types");
7
- const sdk_manager_service_1 = require("../services/sdk-manager.service");
8
- const database_service_1 = require("../services/database/database.service");
9
- class WorkspacesUnset extends core_1.Command {
10
- static args = {};
11
- static description = 'Unset the active workspace context for the current user session. ' +
12
- 'Once a workspace is unset, WebDAV and all of the subsequent CLI commands ' +
13
- 'will operate within the personal drive space until it is changed or set again.';
14
- static aliases = ['workspaces:unset'];
15
- static examples = ['<%= config.bin %> <%= command.id %>'];
16
- static flags = {
17
- ...cli_utils_1.CLIUtils.CommonFlags,
18
- };
19
- static enableJsonFlag = true;
20
- run = async () => {
21
- await this.parse(WorkspacesUnset);
22
- const userCredentials = await config_service_1.ConfigService.instance.readUser();
23
- if (!userCredentials)
24
- throw new command_types_1.MissingCredentialsError();
25
- return WorkspacesUnset.unsetWorkspace(userCredentials, this.log.bind(this));
26
- };
27
- catch = async (error) => {
28
- const { flags } = await this.parse(WorkspacesUnset);
29
- cli_utils_1.CLIUtils.catchError({
30
- error,
31
- command: this.id,
32
- logReporter: this.log.bind(this),
33
- jsonFlag: flags['json'],
34
- debugMode: flags['debug'],
35
- });
36
- this.exit(1);
37
- };
38
- static unsetWorkspace = async (userCredentials, reporter) => {
39
- sdk_manager_service_1.SdkManager.init({ token: userCredentials.token });
40
- await config_service_1.ConfigService.instance.saveUser({ ...userCredentials, workspace: undefined });
41
- void database_service_1.DatabaseService.instance.clear();
42
- cli_utils_1.CLIUtils.success(reporter, 'Personal drive space selected successfully.');
43
- return { success: true, message: 'Personal drive space selected successfully.' };
44
- };
45
- }
46
- exports.default = WorkspacesUnset;
@@ -1,27 +0,0 @@
1
- import { Command } from '@oclif/core';
2
- import { Workspace } from '../types/command.types';
3
- export default class WorkspacesUse extends Command {
4
- static readonly args: {};
5
- static readonly description: string;
6
- static readonly aliases: string[];
7
- static readonly examples: string[];
8
- static readonly flags: {
9
- id: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
- personal: import("@oclif/core/interfaces").BooleanFlag<boolean>;
11
- 'non-interactive': import("@oclif/core/interfaces").BooleanFlag<boolean>;
12
- debug: import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
- };
14
- static readonly enableJsonFlag = true;
15
- run: () => Promise<{
16
- success: boolean;
17
- message: string;
18
- } | {
19
- success: boolean;
20
- workspace: Workspace;
21
- }>;
22
- catch: (error: Error) => Promise<never>;
23
- private getWorkspaceUuid;
24
- private extractUuidFromWorkspaceString;
25
- private getWorkspace;
26
- private setWorkspace;
27
- }
@@ -1,114 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const core_1 = require("@oclif/core");
7
- const config_service_1 = require("../services/config.service");
8
- const cli_utils_1 = require("../utils/cli.utils");
9
- const command_types_1 = require("../types/command.types");
10
- const workspace_service_1 = require("../services/drive/workspace.service");
11
- const format_utils_1 = require("../utils/format.utils");
12
- const validation_service_1 = require("../services/validation.service");
13
- const sdk_manager_service_1 = require("../services/sdk-manager.service");
14
- const workspaces_unset_1 = __importDefault(require("./workspaces-unset"));
15
- const database_service_1 = require("../services/database/database.service");
16
- class WorkspacesUse extends core_1.Command {
17
- static args = {};
18
- static description = 'Set the active workspace context for the current user session. ' +
19
- 'Once a workspace is selected, WebDAV and all of the subsequent CLI commands ' +
20
- 'will operate within that workspace until it is changed or unset.';
21
- static aliases = ['workspaces:use'];
22
- static examples = ['<%= config.bin %> <%= command.id %>'];
23
- static flags = {
24
- ...cli_utils_1.CLIUtils.CommonFlags,
25
- id: core_1.Flags.string({
26
- char: 'i',
27
- description: 'The id of the workspace to activate. ' +
28
- 'Use <%= config.bin %> workspaces list to view your available workspace ids.',
29
- required: false,
30
- exclusive: ['personal'],
31
- }),
32
- personal: core_1.Flags.boolean({
33
- char: 'p',
34
- description: 'Change to the personal drive space. It unsets the active workspace context for the current user session.',
35
- required: false,
36
- }),
37
- };
38
- static enableJsonFlag = true;
39
- run = async () => {
40
- const { flags } = await this.parse(WorkspacesUse);
41
- const nonInteractive = flags['non-interactive'];
42
- const userCredentials = await config_service_1.ConfigService.instance.readUser();
43
- if (!userCredentials)
44
- throw new command_types_1.MissingCredentialsError();
45
- const reporter = this.log.bind(this);
46
- if (flags['personal']) {
47
- return workspaces_unset_1.default.unsetWorkspace(userCredentials, reporter);
48
- }
49
- const workspace = await this.getWorkspace(userCredentials, flags['id'], nonInteractive, reporter);
50
- await this.setWorkspace(userCredentials, workspace);
51
- const message = `Workspace ${workspace.workspaceCredentials.id} selected successfully. Now WebDAV and ` +
52
- 'all of the CLI commands will operate within this workspace until it is changed or unset.';
53
- cli_utils_1.CLIUtils.success(reporter, message);
54
- return { success: true, workspace };
55
- };
56
- catch = async (error) => {
57
- const { flags } = await this.parse(WorkspacesUse);
58
- cli_utils_1.CLIUtils.catchError({
59
- error,
60
- command: this.id,
61
- logReporter: this.log.bind(this),
62
- jsonFlag: flags['json'],
63
- debugMode: flags['debug'],
64
- });
65
- this.exit(1);
66
- };
67
- getWorkspaceUuid = async (workspaceUuidFlag, availableWorkspaces, nonInteractive, reporter) => {
68
- const workspaceUuid = await cli_utils_1.CLIUtils.getValueFromFlag({
69
- value: workspaceUuidFlag ? `[${workspaceUuidFlag}]` : undefined,
70
- name: WorkspacesUse.flags['id'].name,
71
- }, {
72
- nonInteractive,
73
- prompt: {
74
- message: 'What is the workspace you want to use?',
75
- options: {
76
- type: 'list',
77
- choices: { values: availableWorkspaces },
78
- },
79
- },
80
- }, {
81
- validate: (value) => validation_service_1.ValidationService.instance.validateUUIDv4(this.extractUuidFromWorkspaceString(value)),
82
- error: new command_types_1.NotValidWorkspaceUuidError(),
83
- }, reporter);
84
- return this.extractUuidFromWorkspaceString(workspaceUuid);
85
- };
86
- extractUuidFromWorkspaceString = (workspaceString) => workspaceString.match(/\[(.*?)\]/)?.[1] ?? workspaceString;
87
- getWorkspace = async (userCredentials, workspaceUuidFlag, nonInteractive, reporter) => {
88
- const workspaces = await workspace_service_1.WorkspaceService.instance.getAvailableWorkspaces(userCredentials.user);
89
- const availableWorkspaces = workspaces.map((workspaceData) => {
90
- const name = workspaceData.workspace.name;
91
- const id = workspaceData.workspace.id;
92
- const totalUsedSpace = Number(workspaceData.workspaceUser?.driveUsage ?? 0) + Number(workspaceData.workspaceUser?.backupsUsage ?? 0);
93
- const spaceLimit = Number(workspaceData.workspaceUser?.spaceLimit ?? 0);
94
- const usedSpace = format_utils_1.FormatUtils.humanFileSize(totalUsedSpace);
95
- const availableSpace = format_utils_1.FormatUtils.formatLimit(spaceLimit);
96
- return `[${id}] Name: ${name} | Used Space: ${usedSpace} | Available Space: ${availableSpace}`;
97
- });
98
- const workspaceUuid = await this.getWorkspaceUuid(workspaceUuidFlag, availableWorkspaces, nonInteractive, reporter);
99
- const workspaceCredentials = await workspace_service_1.WorkspaceService.instance.getWorkspaceCredentials(workspaceUuid);
100
- const selectedWorkspace = workspaces.find((workspace) => workspace.workspace.id === workspaceUuid);
101
- if (!selectedWorkspace)
102
- throw new command_types_1.NotValidWorkspaceUuidError();
103
- return { workspaceCredentials, workspaceData: selectedWorkspace };
104
- };
105
- setWorkspace = async (userCredentials, workspace) => {
106
- sdk_manager_service_1.SdkManager.init({ token: userCredentials.token, workspaceToken: workspace.workspaceCredentials.token });
107
- await config_service_1.ConfigService.instance.saveUser({
108
- ...userCredentials,
109
- workspace,
110
- });
111
- void database_service_1.DatabaseService.instance.clear();
112
- };
113
- }
114
- exports.default = WorkspacesUse;
@@ -1,7 +0,0 @@
1
- import { WorkspaceData } from '@internxt/sdk/dist/workspaces';
2
- import { LoginCredentials, WorkspaceCredentialsDetails } from '../../types/command.types';
3
- export declare class WorkspaceService {
4
- static readonly instance: WorkspaceService;
5
- getAvailableWorkspaces: (user: LoginCredentials["user"]) => Promise<WorkspaceData[]>;
6
- getWorkspaceCredentials: (workspaceId: string) => Promise<WorkspaceCredentialsDetails>;
7
- }
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WorkspaceService = void 0;
4
- const sdk_manager_service_1 = require("../sdk-manager.service");
5
- const crypto_service_1 = require("../crypto.service");
6
- class WorkspaceService {
7
- static instance = new WorkspaceService();
8
- getAvailableWorkspaces = async (user) => {
9
- const workspacesClient = sdk_manager_service_1.SdkManager.instance.getWorkspaces();
10
- const workspaces = await workspacesClient.getWorkspaces();
11
- const decryptedMnemonicWorkspaces = await crypto_service_1.CryptoService.instance.decryptWorkspacesMnemonic(workspaces.availableWorkspaces, user);
12
- return decryptedMnemonicWorkspaces;
13
- };
14
- getWorkspaceCredentials = async (workspaceId) => {
15
- const workspacesClient = sdk_manager_service_1.SdkManager.instance.getWorkspaces();
16
- const workspaceCredentialsRaw = await workspacesClient.getWorkspaceCredentials(workspaceId);
17
- const workspaceCredentials = {
18
- id: workspaceCredentialsRaw.workspaceId,
19
- bucket: workspaceCredentialsRaw.bucket,
20
- workspaceUserId: workspaceCredentialsRaw.workspaceUserId,
21
- credentials: {
22
- user: workspaceCredentialsRaw.credentials.networkUser,
23
- pass: workspaceCredentialsRaw.credentials.networkPass,
24
- },
25
- token: workspaceCredentialsRaw.tokenHeader,
26
- };
27
- return workspaceCredentials;
28
- };
29
- }
30
- exports.WorkspaceService = WorkspaceService;