@internxt/cli 1.6.6 → 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 (85) 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 +6 -4
  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-list.js +5 -3
  19. package/dist/commands/trash-restore-file.d.ts +1 -0
  20. package/dist/commands/trash-restore-file.js +1 -1
  21. package/dist/commands/trash-restore-folder.js +1 -1
  22. package/dist/commands/upload-file.d.ts +1 -0
  23. package/dist/commands/upload-file.js +22 -13
  24. package/dist/commands/whoami.js +6 -3
  25. package/dist/hooks/prerun/auth_check.js +2 -2
  26. package/dist/services/auth.service.d.ts +3 -3
  27. package/dist/services/auth.service.js +35 -44
  28. package/dist/services/crypto.service.d.ts +0 -4
  29. package/dist/services/crypto.service.js +1 -32
  30. package/dist/services/database/drive-item/drive-item.model.js +1 -0
  31. package/dist/services/database/drive-item/drive-item.repository.js +12 -2
  32. package/dist/services/drive/drive-file.service.d.ts +2 -0
  33. package/dist/services/drive/drive-file.service.js +48 -18
  34. package/dist/services/drive/drive-folder.service.d.ts +2 -0
  35. package/dist/services/drive/drive-folder.service.js +14 -46
  36. package/dist/services/drive/trash.service.d.ts +2 -0
  37. package/dist/services/drive/trash.service.js +14 -41
  38. package/dist/services/network/upload/upload-file.service.js +5 -9
  39. package/dist/services/network/upload/upload.types.d.ts +2 -1
  40. package/dist/services/sdk-manager.service.d.ts +0 -2
  41. package/dist/services/sdk-manager.service.js +0 -7
  42. package/dist/services/thumbnail.service.d.ts +4 -13
  43. package/dist/services/thumbnail.service.js +7 -21
  44. package/dist/services/universal-link.service.d.ts +1 -1
  45. package/dist/services/universal-link.service.js +2 -2
  46. package/dist/services/validation.service.d.ts +3 -13
  47. package/dist/services/validation.service.js +4 -28
  48. package/dist/types/command.types.d.ts +1 -29
  49. package/dist/types/command.types.js +1 -15
  50. package/dist/types/network.types.d.ts +3 -11
  51. package/dist/types/webdav.types.d.ts +0 -3
  52. package/dist/utils/cli.utils.js +9 -22
  53. package/dist/utils/drive.utils.d.ts +1 -0
  54. package/dist/utils/drive.utils.js +5 -1
  55. package/dist/utils/format.utils.js +6 -2
  56. package/dist/utils/logger.utils.js +9 -2
  57. package/dist/utils/network.utils.js +2 -2
  58. package/dist/utils/stream.utils.d.ts +2 -2
  59. package/dist/utils/stream.utils.js +7 -6
  60. package/dist/utils/thumbnail.utils.d.ts +1 -3
  61. package/dist/utils/thumbnail.utils.js +3 -13
  62. package/dist/utils/upload.utils.d.ts +1 -1
  63. package/dist/utils/upload.utils.js +2 -2
  64. package/dist/utils/webdav.utils.d.ts +2 -0
  65. package/dist/utils/webdav.utils.js +16 -0
  66. package/dist/webdav/handlers/GET.handler.js +4 -2
  67. package/dist/webdav/handlers/HEAD.handler.js +2 -0
  68. package/dist/webdav/handlers/MKCOL.handler.js +3 -3
  69. package/dist/webdav/handlers/PROPFIND.handler.js +8 -4
  70. package/dist/webdav/handlers/PUT.handler.js +24 -10
  71. package/dist/webdav/index.js +2 -2
  72. package/dist/webdav/middewares/auth.middleware.js +2 -1
  73. package/dist/webdav/middewares/errors.middleware.js +29 -5
  74. package/dist/webdav/middewares/webdav-auth.middleware.js +1 -0
  75. package/dist/webdav/webdav-server.js +2 -2
  76. package/oclif.manifest.json +9 -198
  77. package/package.json +23 -22
  78. package/dist/commands/workspaces-list.d.ts +0 -20
  79. package/dist/commands/workspaces-list.js +0 -68
  80. package/dist/commands/workspaces-unset.d.ts +0 -23
  81. package/dist/commands/workspaces-unset.js +0 -46
  82. package/dist/commands/workspaces-use.d.ts +0 -27
  83. package/dist/commands/workspaces-use.js +0 -114
  84. package/dist/services/drive/workspace.service.d.ts +0 -7
  85. package/dist/services/drive/workspace.service.js +0 -30
@@ -586,19 +586,6 @@
586
586
  "allowNo": false,
587
587
  "type": "boolean"
588
588
  },
589
- "host": {
590
- "aliases": [
591
- "host"
592
- ],
593
- "char": "h",
594
- "description": "IP address of the machine where the CLI is running. If you are opening the login page in a browser on another device, set this to the IP address of the machine running the CLI. Defaults to 127.0.0.1.",
595
- "env": "INXT_LOGIN_SERVER_HOST",
596
- "name": "host",
597
- "required": false,
598
- "hasDynamicHelp": false,
599
- "multiple": false,
600
- "type": "option"
601
- },
602
589
  "port": {
603
590
  "aliases": [
604
591
  "port"
@@ -1443,6 +1430,14 @@
1443
1430
  "hasDynamicHelp": false,
1444
1431
  "multiple": false,
1445
1432
  "type": "option"
1433
+ },
1434
+ "overwrite": {
1435
+ "char": "o",
1436
+ "description": "Overwrite the file if a file with the same name already exists in the cloud destination folder.",
1437
+ "name": "overwrite",
1438
+ "required": false,
1439
+ "allowNo": false,
1440
+ "type": "boolean"
1446
1441
  }
1447
1442
  },
1448
1443
  "hasDynamicHelp": false,
@@ -1786,191 +1781,7 @@
1786
1781
  "commands",
1787
1782
  "whoami.js"
1788
1783
  ]
1789
- },
1790
- "workspaces-list": {
1791
- "aliases": [
1792
- "workspaces:list"
1793
- ],
1794
- "args": {},
1795
- "description": "Get the list of workspaces.",
1796
- "examples": [
1797
- "<%= config.bin %> <%= command.id %>"
1798
- ],
1799
- "flags": {
1800
- "json": {
1801
- "description": "Format output as json.",
1802
- "helpGroup": "GLOBAL",
1803
- "name": "json",
1804
- "allowNo": false,
1805
- "type": "boolean"
1806
- },
1807
- "non-interactive": {
1808
- "char": "x",
1809
- "description": "Prevents the CLI from being interactive. When enabled, the CLI will not request input through the console and will throw errors directly.",
1810
- "env": "INXT_NONINTERACTIVE",
1811
- "helpGroup": "helper",
1812
- "name": "non-interactive",
1813
- "required": false,
1814
- "allowNo": false,
1815
- "type": "boolean"
1816
- },
1817
- "debug": {
1818
- "description": "Enables debug mode. When enabled, the CLI will print debug messages to the console.",
1819
- "env": "INXT_DEBUG",
1820
- "helpGroup": "helper",
1821
- "name": "debug",
1822
- "required": false,
1823
- "allowNo": false,
1824
- "type": "boolean"
1825
- },
1826
- "extended": {
1827
- "char": "e",
1828
- "description": "Displays additional information in the list.",
1829
- "name": "extended",
1830
- "required": false,
1831
- "allowNo": false,
1832
- "type": "boolean"
1833
- }
1834
- },
1835
- "hasDynamicHelp": false,
1836
- "hiddenAliases": [],
1837
- "id": "workspaces-list",
1838
- "pluginAlias": "@internxt/cli",
1839
- "pluginName": "@internxt/cli",
1840
- "pluginType": "core",
1841
- "strict": true,
1842
- "enableJsonFlag": true,
1843
- "isESM": false,
1844
- "relativePath": [
1845
- "dist",
1846
- "commands",
1847
- "workspaces-list.js"
1848
- ]
1849
- },
1850
- "workspaces-unset": {
1851
- "aliases": [
1852
- "workspaces:unset"
1853
- ],
1854
- "args": {},
1855
- "description": "Unset the active workspace context for the current user session. Once a workspace is unset, WebDAV and all of the subsequent CLI commands will operate within the personal drive space until it is changed or set again.",
1856
- "examples": [
1857
- "<%= config.bin %> <%= command.id %>"
1858
- ],
1859
- "flags": {
1860
- "json": {
1861
- "description": "Format output as json.",
1862
- "helpGroup": "GLOBAL",
1863
- "name": "json",
1864
- "allowNo": false,
1865
- "type": "boolean"
1866
- },
1867
- "non-interactive": {
1868
- "char": "x",
1869
- "description": "Prevents the CLI from being interactive. When enabled, the CLI will not request input through the console and will throw errors directly.",
1870
- "env": "INXT_NONINTERACTIVE",
1871
- "helpGroup": "helper",
1872
- "name": "non-interactive",
1873
- "required": false,
1874
- "allowNo": false,
1875
- "type": "boolean"
1876
- },
1877
- "debug": {
1878
- "description": "Enables debug mode. When enabled, the CLI will print debug messages to the console.",
1879
- "env": "INXT_DEBUG",
1880
- "helpGroup": "helper",
1881
- "name": "debug",
1882
- "required": false,
1883
- "allowNo": false,
1884
- "type": "boolean"
1885
- }
1886
- },
1887
- "hasDynamicHelp": false,
1888
- "hiddenAliases": [],
1889
- "id": "workspaces-unset",
1890
- "pluginAlias": "@internxt/cli",
1891
- "pluginName": "@internxt/cli",
1892
- "pluginType": "core",
1893
- "strict": true,
1894
- "enableJsonFlag": true,
1895
- "isESM": false,
1896
- "relativePath": [
1897
- "dist",
1898
- "commands",
1899
- "workspaces-unset.js"
1900
- ]
1901
- },
1902
- "workspaces-use": {
1903
- "aliases": [
1904
- "workspaces:use"
1905
- ],
1906
- "args": {},
1907
- "description": "Set the active workspace context for the current user session. Once a workspace is selected, WebDAV and all of the subsequent CLI commands will operate within that workspace until it is changed or unset.",
1908
- "examples": [
1909
- "<%= config.bin %> <%= command.id %>"
1910
- ],
1911
- "flags": {
1912
- "json": {
1913
- "description": "Format output as json.",
1914
- "helpGroup": "GLOBAL",
1915
- "name": "json",
1916
- "allowNo": false,
1917
- "type": "boolean"
1918
- },
1919
- "non-interactive": {
1920
- "char": "x",
1921
- "description": "Prevents the CLI from being interactive. When enabled, the CLI will not request input through the console and will throw errors directly.",
1922
- "env": "INXT_NONINTERACTIVE",
1923
- "helpGroup": "helper",
1924
- "name": "non-interactive",
1925
- "required": false,
1926
- "allowNo": false,
1927
- "type": "boolean"
1928
- },
1929
- "debug": {
1930
- "description": "Enables debug mode. When enabled, the CLI will print debug messages to the console.",
1931
- "env": "INXT_DEBUG",
1932
- "helpGroup": "helper",
1933
- "name": "debug",
1934
- "required": false,
1935
- "allowNo": false,
1936
- "type": "boolean"
1937
- },
1938
- "id": {
1939
- "char": "i",
1940
- "description": "The id of the workspace to activate. Use <%= config.bin %> workspaces list to view your available workspace ids.",
1941
- "exclusive": [
1942
- "personal"
1943
- ],
1944
- "name": "id",
1945
- "required": false,
1946
- "hasDynamicHelp": false,
1947
- "multiple": false,
1948
- "type": "option"
1949
- },
1950
- "personal": {
1951
- "char": "p",
1952
- "description": "Change to the personal drive space. It unsets the active workspace context for the current user session.",
1953
- "name": "personal",
1954
- "required": false,
1955
- "allowNo": false,
1956
- "type": "boolean"
1957
- }
1958
- },
1959
- "hasDynamicHelp": false,
1960
- "hiddenAliases": [],
1961
- "id": "workspaces-use",
1962
- "pluginAlias": "@internxt/cli",
1963
- "pluginName": "@internxt/cli",
1964
- "pluginType": "core",
1965
- "strict": true,
1966
- "enableJsonFlag": true,
1967
- "isESM": false,
1968
- "relativePath": [
1969
- "dist",
1970
- "commands",
1971
- "workspaces-use.js"
1972
- ]
1973
1784
  }
1974
1785
  },
1975
- "version": "1.6.6"
1786
+ "version": "1.6.8"
1976
1787
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "author": "Internxt <hello@internxt.com>",
3
- "version": "1.6.6",
3
+ "version": "1.6.8",
4
4
  "description": "Internxt CLI to manage your encrypted storage",
5
5
  "scripts": {
6
6
  "build": "npm run clean && tsc",
@@ -38,12 +38,12 @@
38
38
  "dependencies": {
39
39
  "@dashlane/pqc-kem-kyber512-node": "1.0.0",
40
40
  "@inquirer/prompts": "8.5.2",
41
- "@internxt/inxt-js": "3.3.1",
42
- "@internxt/lib": "1.4.2",
43
- "@internxt/sdk": "1.17.9",
44
- "@oclif/core": "4.11.10",
45
- "@oclif/plugin-autocomplete": "3.2.52",
46
- "axios": "1.18.0",
41
+ "@internxt/inxt-js": "3.3.5",
42
+ "@internxt/lib": "1.5.2",
43
+ "@internxt/sdk": "1.20.1",
44
+ "@oclif/core": "4.13.3",
45
+ "@oclif/plugin-autocomplete": "3.2.56",
46
+ "axios": "1.19.0",
47
47
  "better-sqlite3": "12.11.1",
48
48
  "bip39": "3.1.0",
49
49
  "body-parser": "2.3.0",
@@ -52,18 +52,19 @@
52
52
  "dotenv": "17.4.2",
53
53
  "express": "5.2.1",
54
54
  "express-async-handler": "1.2.0",
55
- "fast-xml-builder": "1.2.0",
56
- "fast-xml-parser": "5.9.3",
55
+ "fast-xml-builder": "1.3.1",
56
+ "fast-xml-parser": "5.10.1",
57
57
  "hash-wasm": "4.12.0",
58
58
  "mime-types": "3.0.2",
59
- "open": "11.0.0",
59
+ "open": "11.0.1",
60
60
  "openpgp": "6.3.1",
61
61
  "otpauth": "9.5.1",
62
- "pm2": "7.0.1",
63
- "range-parser": "1.2.1",
62
+ "pm2": "7.0.3",
63
+ "range-parser": "1.3.0",
64
64
  "selfsigned": "5.5.0",
65
65
  "tty-table": "5.0.0",
66
- "typeorm": "1.0.0",
66
+ "typeorm": "1.1.0",
67
+ "uuid": "14.0.1",
67
68
  "winston": "3.19.0"
68
69
  },
69
70
  "devDependencies": {
@@ -73,25 +74,25 @@
73
74
  "@types/cli-progress": "^3.11.6",
74
75
  "@types/express": "^5.0.6",
75
76
  "@types/mime-types": "^3.0.1",
76
- "@types/node": "^26.0.0",
77
+ "@types/node": "^26.2.0",
77
78
  "@types/range-parser": "^1.2.7",
78
- "@vitest/coverage-istanbul": "^4.1.9",
79
- "@vitest/spy": "^4.1.9",
80
- "eslint": "^10.5.0",
79
+ "@vitest/coverage-istanbul": "^4.1.10",
80
+ "@vitest/spy": "^4.1.10",
81
+ "eslint": "^10.8.1",
81
82
  "husky": "^9.1.7",
82
- "lint-staged": "^17.0.8",
83
+ "lint-staged": "^17.3.0",
83
84
  "nodemon": "^3.1.14",
84
- "oclif": "^4.23.19",
85
- "prettier": "^3.8.4",
85
+ "oclif": "^4.23.30",
86
+ "prettier": "^3.9.6",
86
87
  "rimraf": "^6.1.3",
87
88
  "sql.js": "^1.14.1",
88
89
  "ts-node": "^10.9.2",
89
90
  "typescript": "^6.0.3",
90
- "vitest": "^4.1.9",
91
+ "vitest": "^4.1.10",
91
92
  "vitest-mock-express": "^2.2.0"
92
93
  },
93
94
  "optionalDependencies": {
94
- "sharp": "0.35.2"
95
+ "sharp": "0.35.3"
95
96
  },
96
97
  "engines": {
97
98
  "node": "^22.13.0 || >=24.11.0"
@@ -1,20 +0,0 @@
1
- import { Command } from '@oclif/core';
2
- export default class WorkspacesList extends Command {
3
- static readonly args: {};
4
- static readonly description = "Get the list of workspaces.";
5
- static readonly aliases: string[];
6
- static readonly examples: string[];
7
- static readonly flags: {
8
- extended: import("@oclif/core/interfaces").BooleanFlag<boolean>;
9
- 'non-interactive': import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
- debug: import("@oclif/core/interfaces").BooleanFlag<boolean>;
11
- };
12
- static readonly enableJsonFlag = true;
13
- run: () => Promise<{
14
- success: boolean;
15
- list: {
16
- workspaces: import("@internxt/sdk/dist/workspaces").WorkspaceData[];
17
- };
18
- }>;
19
- catch: (error: Error) => Promise<never>;
20
- }
@@ -1,68 +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 workspace_service_1 = require("../services/drive/workspace.service");
8
- const format_utils_1 = require("../utils/format.utils");
9
- class WorkspacesList extends core_1.Command {
10
- static args = {};
11
- static description = 'Get the list of workspaces.';
12
- static aliases = ['workspaces:list'];
13
- static examples = ['<%= config.bin %> <%= command.id %>'];
14
- static flags = {
15
- ...cli_utils_1.CLIUtils.CommonFlags,
16
- extended: core_1.Flags.boolean({
17
- char: 'e',
18
- description: 'Displays additional information in the list.',
19
- required: false,
20
- }),
21
- };
22
- static enableJsonFlag = true;
23
- run = async () => {
24
- const { flags } = await this.parse(WorkspacesList);
25
- const userCredentials = await config_service_1.ConfigService.instance.readUser();
26
- if (!userCredentials)
27
- throw new command_types_1.MissingCredentialsError();
28
- const workspaces = await workspace_service_1.WorkspaceService.instance.getAvailableWorkspaces(userCredentials.user);
29
- const allItems = workspaces.map((workspaceData) => {
30
- const totalUsedSpace = Number(workspaceData.workspaceUser?.driveUsage ?? 0) + Number(workspaceData.workspaceUser?.backupsUsage ?? 0);
31
- const spaceLimit = Number(workspaceData.workspaceUser?.spaceLimit ?? 0);
32
- const usedSpace = format_utils_1.FormatUtils.humanFileSize(totalUsedSpace);
33
- const availableSpace = format_utils_1.FormatUtils.formatLimit(spaceLimit);
34
- return {
35
- name: workspaceData.workspace.name,
36
- id: workspaceData.workspace.id,
37
- usedSpace,
38
- availableSpace,
39
- owner: workspaceData.workspace.ownerId,
40
- address: workspaceData.workspace.address,
41
- created: format_utils_1.FormatUtils.formatDate(workspaceData.workspace.createdAt),
42
- };
43
- });
44
- const headers = [
45
- { value: 'name', alias: 'Name' },
46
- { value: 'id', alias: 'Workspace ID' },
47
- { value: 'usedSpace', alias: 'Used space' },
48
- { value: 'availableSpace', alias: 'Available space' },
49
- ];
50
- if (flags.extended) {
51
- headers.push({ value: 'owner', alias: 'Owner ID' }, { value: 'address', alias: 'Address' }, { value: 'created', alias: 'Created at' });
52
- }
53
- cli_utils_1.CLIUtils.table(this.log.bind(this), headers, allItems);
54
- return { success: true, list: { workspaces } };
55
- };
56
- catch = async (error) => {
57
- const { flags } = await this.parse(WorkspacesList);
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
- }
68
- exports.default = WorkspacesList;
@@ -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;