@internxt/cli 0.1.4 → 0.1.6

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 CHANGED
@@ -7,10 +7,25 @@ A CLI tool to interact with yout Internxt encrypted files
7
7
 
8
8
  <!-- toc -->
9
9
  * [Internxt CLI](#internxt-cli)
10
+ * [Installation](#installation)
10
11
  * [Usage](#usage)
11
12
  * [Commands](#commands)
12
13
  <!-- tocstop -->
13
14
 
15
+ # Installation
16
+
17
+ Binaries and specific installers are available in the latest release:
18
+
19
+ [View Internxt CLI latest release here](https://github.com/internxt/cli/releases/latest)
20
+
21
+ You can install the Internxt CLI in different ways:
22
+
23
+ ### NPM
24
+
25
+ Requires Node >= 20.0.0
26
+
27
+ `npm i -g @internxt/cli`
28
+
14
29
  # Usage
15
30
 
16
31
  <!-- usage -->
@@ -19,7 +34,7 @@ $ npm install -g @internxt/cli
19
34
  $ internxt COMMAND
20
35
  running command...
21
36
  $ internxt (--version)
22
- @internxt/cli/0.1.4 darwin-arm64 node-v18.16.1
37
+ @internxt/cli/0.1.6 darwin-arm64 node-v20.10.0
23
38
  $ internxt --help [COMMAND]
24
39
  USAGE
25
40
  $ internxt COMMAND
@@ -69,7 +84,7 @@ EXAMPLES
69
84
  $ internxt config
70
85
  ```
71
86
 
72
- _See code: [src/commands/config.ts](https://github.com/internxt/cli/blob/v0.1.4/src/commands/config.ts)_
87
+ _See code: [src/commands/config.ts](https://github.com/internxt/cli/blob/v0.1.6/src/commands/config.ts)_
73
88
 
74
89
  ## `internxt download`
75
90
 
@@ -92,7 +107,7 @@ EXAMPLES
92
107
  $ internxt download
93
108
  ```
94
109
 
95
- _See code: [src/commands/download.ts](https://github.com/internxt/cli/blob/v0.1.4/src/commands/download.ts)_
110
+ _See code: [src/commands/download.ts](https://github.com/internxt/cli/blob/v0.1.6/src/commands/download.ts)_
96
111
 
97
112
  ## `internxt list`
98
113
 
@@ -126,7 +141,7 @@ EXAMPLES
126
141
  $ internxt list
127
142
  ```
128
143
 
129
- _See code: [src/commands/list.ts](https://github.com/internxt/cli/blob/v0.1.4/src/commands/list.ts)_
144
+ _See code: [src/commands/list.ts](https://github.com/internxt/cli/blob/v0.1.6/src/commands/list.ts)_
130
145
 
131
146
  ## `internxt login`
132
147
 
@@ -152,7 +167,7 @@ EXAMPLES
152
167
  $ internxt login
153
168
  ```
154
169
 
155
- _See code: [src/commands/login.ts](https://github.com/internxt/cli/blob/v0.1.4/src/commands/login.ts)_
170
+ _See code: [src/commands/login.ts](https://github.com/internxt/cli/blob/v0.1.6/src/commands/login.ts)_
156
171
 
157
172
  ## `internxt logout`
158
173
 
@@ -169,7 +184,7 @@ EXAMPLES
169
184
  $ internxt logout
170
185
  ```
171
186
 
172
- _See code: [src/commands/logout.ts](https://github.com/internxt/cli/blob/v0.1.4/src/commands/logout.ts)_
187
+ _See code: [src/commands/logout.ts](https://github.com/internxt/cli/blob/v0.1.6/src/commands/logout.ts)_
173
188
 
174
189
  ## `internxt logs`
175
190
 
@@ -186,7 +201,7 @@ EXAMPLES
186
201
  $ internxt logs
187
202
  ```
188
203
 
189
- _See code: [src/commands/logs.ts](https://github.com/internxt/cli/blob/v0.1.4/src/commands/logs.ts)_
204
+ _See code: [src/commands/logs.ts](https://github.com/internxt/cli/blob/v0.1.6/src/commands/logs.ts)_
190
205
 
191
206
  ## `internxt move`
192
207
 
@@ -211,7 +226,7 @@ EXAMPLES
211
226
  $ internxt move
212
227
  ```
213
228
 
214
- _See code: [src/commands/move.ts](https://github.com/internxt/cli/blob/v0.1.4/src/commands/move.ts)_
229
+ _See code: [src/commands/move.ts](https://github.com/internxt/cli/blob/v0.1.6/src/commands/move.ts)_
215
230
 
216
231
  ## `internxt trash`
217
232
 
@@ -235,7 +250,7 @@ EXAMPLES
235
250
  $ internxt trash
236
251
  ```
237
252
 
238
- _See code: [src/commands/trash.ts](https://github.com/internxt/cli/blob/v0.1.4/src/commands/trash.ts)_
253
+ _See code: [src/commands/trash.ts](https://github.com/internxt/cli/blob/v0.1.6/src/commands/trash.ts)_
239
254
 
240
255
  ## `internxt upload`
241
256
 
@@ -259,7 +274,7 @@ EXAMPLES
259
274
  $ internxt upload
260
275
  ```
261
276
 
262
- _See code: [src/commands/upload.ts](https://github.com/internxt/cli/blob/v0.1.4/src/commands/upload.ts)_
277
+ _See code: [src/commands/upload.ts](https://github.com/internxt/cli/blob/v0.1.6/src/commands/upload.ts)_
263
278
 
264
279
  ## `internxt webdav ACTION`
265
280
 
@@ -276,7 +291,7 @@ EXAMPLES
276
291
  $ internxt webdav
277
292
  ```
278
293
 
279
- _See code: [src/commands/webdav.ts](https://github.com/internxt/cli/blob/v0.1.4/src/commands/webdav.ts)_
294
+ _See code: [src/commands/webdav.ts](https://github.com/internxt/cli/blob/v0.1.6/src/commands/webdav.ts)_
280
295
 
281
296
  ## `internxt whoami`
282
297
 
@@ -293,5 +308,5 @@ EXAMPLES
293
308
  $ internxt whoami
294
309
  ```
295
310
 
296
- _See code: [src/commands/whoami.ts](https://github.com/internxt/cli/blob/v0.1.4/src/commands/whoami.ts)_
311
+ _See code: [src/commands/whoami.ts](https://github.com/internxt/cli/blob/v0.1.6/src/commands/whoami.ts)_
297
312
  <!-- commandsstop -->
@@ -34,6 +34,7 @@ const inxt_js_1 = require("@internxt/inxt-js");
34
34
  const crypto_1 = __importDefault(require("crypto"));
35
35
  const validation_service_1 = require("../validation.service");
36
36
  const hash_utils_1 = require("../../utils/hash.utils");
37
+ const stream_utils_1 = require("../../utils/stream.utils");
37
38
  class NetworkFacade {
38
39
  network;
39
40
  uploadService;
@@ -94,23 +95,26 @@ class NetworkFacade {
94
95
  const abortable = options?.abortController ?? new AbortController();
95
96
  let fileHash;
96
97
  let encryptionTransform;
98
+ const progressTransform = new stream_utils_1.ProgressTransform({ totalBytes: size }, (progress) => {
99
+ if (options?.progressCallback) {
100
+ options.progressCallback(progress * 0.95);
101
+ }
102
+ });
97
103
  const onProgress = (progress) => {
98
104
  if (!options?.progressCallback)
99
105
  return;
100
106
  options.progressCallback(progress);
101
107
  };
102
- const onUploadProgress = (progress) => {
103
- onProgress(progress * 0.9);
104
- };
105
108
  const encryptFile = async (_, key, iv) => {
106
109
  encryptionTransform = from
107
110
  .pipe(await this.cryptoService.getEncryptionTransform(Buffer.from(key), Buffer.from(iv)))
108
111
  .pipe(hashStream);
109
112
  };
110
113
  const uploadFile = async (url) => {
111
- await this.uploadService.uploadFile(url, encryptionTransform, {
114
+ await this.uploadService.uploadFile(url, encryptionTransform.pipe(progressTransform), {
112
115
  abortController: abortable,
113
- progressCallback: onUploadProgress,
116
+ progressCallback: () => {
117
+ },
114
118
  });
115
119
  return hashStream.getHash().toString('hex');
116
120
  };
@@ -1,7 +1,20 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
2
4
  import { ReadStream, WriteStream } from 'fs';
5
+ import { Transform, TransformCallback } from 'node:stream';
3
6
  export declare class StreamUtils {
4
7
  static readStreamToReadableStream(readStream: ReadStream): ReadableStream<Uint8Array>;
5
8
  static writeStreamToWritableStream(writeStream: WriteStream): WritableStream<Uint8Array>;
6
9
  static joinReadableBinaryStreams(streams: ReadableStream<Uint8Array>[]): ReadableStream<Uint8Array>;
7
10
  }
11
+ export declare class ProgressTransform extends Transform {
12
+ private options;
13
+ private progressCallback;
14
+ private receivedBytes;
15
+ constructor(options: {
16
+ totalBytes: number;
17
+ }, progressCallback: (percentage: number) => void);
18
+ _transform(chunk: Buffer, encoding: BufferEncoding, callback: TransformCallback): void;
19
+ _flush(callback: (err: Error | null) => void): void;
20
+ }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StreamUtils = void 0;
3
+ exports.ProgressTransform = exports.StreamUtils = void 0;
4
+ const node_stream_1 = require("node:stream");
4
5
  class StreamUtils {
5
6
  static readStreamToReadableStream(readStream) {
6
7
  const readable = new ReadableStream({
@@ -54,3 +55,24 @@ class StreamUtils {
54
55
  }
55
56
  }
56
57
  exports.StreamUtils = StreamUtils;
58
+ class ProgressTransform extends node_stream_1.Transform {
59
+ options;
60
+ progressCallback;
61
+ receivedBytes = 0;
62
+ constructor(options, progressCallback) {
63
+ super();
64
+ this.options = options;
65
+ this.progressCallback = progressCallback;
66
+ }
67
+ _transform(chunk, encoding, callback) {
68
+ this.receivedBytes += chunk.length;
69
+ const percentage = this.receivedBytes / this.options.totalBytes;
70
+ this.progressCallback(percentage);
71
+ this.push(chunk);
72
+ callback();
73
+ }
74
+ _flush(callback) {
75
+ callback(null);
76
+ }
77
+ }
78
+ exports.ProgressTransform = ProgressTransform;
@@ -589,5 +589,5 @@
589
589
  ]
590
590
  }
591
591
  },
592
- "version": "0.1.4"
592
+ "version": "0.1.6"
593
593
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "author": "PixoDev",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Internxt CLI to manage your encrypted storage",
5
5
  "scripts": {
6
6
  "build": "tsc",
@@ -13,7 +13,9 @@
13
13
  "dev:webdav": "nodemon -e ts --exec ts-node src/webdav/index.ts",
14
14
  "version": "oclif readme && git add README.md",
15
15
  "migrate": "sequelize db:migrate",
16
- "migrate:undo": "sequelize db:migrate:undo"
16
+ "migrate:undo": "sequelize db:migrate:undo",
17
+ "publish:npm": "npm publish --scope=@internxt --registry=https://registry.npmjs.org/ --access public",
18
+ "publish:github": "npm publish"
17
19
  },
18
20
  "publishConfig": {
19
21
  "access": "public",
@@ -33,10 +35,8 @@
33
35
  "/oclif.manifest.json"
34
36
  ],
35
37
  "dependencies": {
36
- "@internxt/eslint-config-internxt": "^1.0.9",
37
38
  "@internxt/inxt-js": "^2.0.9",
38
39
  "@internxt/lib": "^1.2.0",
39
- "@internxt/prettier-config": "^1.0.2",
40
40
  "@internxt/sdk": "^1.4.76",
41
41
  "@oclif/core": "^3",
42
42
  "axios": "^1.6.7",
@@ -62,6 +62,8 @@
62
62
  "winston": "^3.12.0"
63
63
  },
64
64
  "devDependencies": {
65
+ "@internxt/eslint-config-internxt": "^1.0.9",
66
+ "@internxt/prettier-config": "^1.0.2",
65
67
  "@oclif/prettier-config": "^0.2.1",
66
68
  "@oclif/test": "^3",
67
69
  "@openpgp/web-stream-tools": "0.0.11-patch-0",
@@ -95,7 +97,7 @@
95
97
  "typescript": "^5.4.2"
96
98
  },
97
99
  "engines": {
98
- "node": ">=18.0.0"
100
+ "node": ">=20.0.0"
99
101
  },
100
102
  "bin": {
101
103
  "internxt": "./bin/run.js"
@@ -1,23 +0,0 @@
1
- import Realm, { ObjectSchema } from 'realm';
2
- import { DriveFileItem } from '../../types/drive.types';
3
- export declare class DriveFileRealmSchema extends Realm.Object<DriveFileRealmSchema> {
4
- id: number;
5
- name: string;
6
- type?: string;
7
- uuid: string;
8
- file_id: string;
9
- folder_id: number;
10
- bucket: string;
11
- relative_path: string;
12
- created_at: Date;
13
- updated_at: Date;
14
- size: number;
15
- status: 'EXISTS' | 'REMOVED' | 'TRASHED';
16
- static readonly schema: ObjectSchema;
17
- }
18
- export declare class DriveFilesRealm {
19
- private realm;
20
- constructor(realm: Realm);
21
- findByRelativePath(relativePath: string): DriveFileRealmSchema | null;
22
- createOrReplace(driveFile: DriveFileItem, relativePath: string): void;
23
- }
@@ -1,76 +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
- exports.DriveFilesRealm = exports.DriveFileRealmSchema = void 0;
7
- const realm_1 = __importDefault(require("realm"));
8
- class DriveFileRealmSchema extends realm_1.default.Object {
9
- id;
10
- name;
11
- type;
12
- uuid;
13
- file_id;
14
- folder_id;
15
- bucket;
16
- relative_path;
17
- created_at;
18
- updated_at;
19
- size;
20
- status;
21
- static schema = {
22
- name: 'DriveFile',
23
- properties: {
24
- id: 'int',
25
- name: 'string',
26
- type: 'string?',
27
- uuid: { type: 'string', indexed: true },
28
- file_id: 'string',
29
- folder_id: 'int',
30
- bucket: 'string',
31
- relative_path: { type: 'string', indexed: true },
32
- created_at: 'date',
33
- updated_at: 'date',
34
- size: 'int',
35
- status: 'string',
36
- },
37
- primaryKey: 'id',
38
- };
39
- }
40
- exports.DriveFileRealmSchema = DriveFileRealmSchema;
41
- class DriveFilesRealm {
42
- realm;
43
- constructor(realm) {
44
- this.realm = realm;
45
- }
46
- findByRelativePath(relativePath) {
47
- const object = this.realm
48
- .objects('DriveFile')
49
- .filtered('relative_path = $0', relativePath)
50
- .find((file) => file.relative_path === relativePath);
51
- return object ?? null;
52
- }
53
- createOrReplace(driveFile, relativePath) {
54
- const existingObject = this.realm.objectForPrimaryKey('DriveFile', driveFile.id);
55
- this.realm.write(() => {
56
- if (existingObject) {
57
- this.realm.delete(existingObject);
58
- }
59
- this.realm.create('DriveFile', {
60
- id: driveFile.id,
61
- name: driveFile.name,
62
- type: driveFile.type,
63
- uuid: driveFile.uuid,
64
- file_id: driveFile.fileId,
65
- folder_id: driveFile.folderId,
66
- bucket: driveFile.bucket,
67
- relative_path: relativePath,
68
- created_at: driveFile.createdAt,
69
- updated_at: driveFile.updatedAt,
70
- size: driveFile.size,
71
- status: 'EXISTS',
72
- });
73
- });
74
- }
75
- }
76
- exports.DriveFilesRealm = DriveFilesRealm;
@@ -1,20 +0,0 @@
1
- import Realm, { ObjectSchema } from 'realm';
2
- import { DriveFolderItem } from '../../types/drive.types';
3
- export declare class DriveFolderRealmSchema extends Realm.Object<DriveFolderRealmSchema> {
4
- id: number;
5
- name: string;
6
- uuid: string;
7
- relative_path: string;
8
- parent_id?: number;
9
- created_at: Date;
10
- updated_at: Date;
11
- status: 'EXISTS' | 'REMOVED' | 'TRASHED';
12
- static readonly schema: ObjectSchema;
13
- }
14
- export declare class DriveFoldersRealm {
15
- private realm;
16
- constructor(realm: Realm);
17
- findByRelativePath(relativePath: string): DriveFolderRealmSchema | null;
18
- findByParentId(parentId: number | null): DriveFolderRealmSchema | null;
19
- createOrReplace(driveFolder: DriveFolderItem, relativePath: string): void;
20
- }
@@ -1,68 +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
- exports.DriveFoldersRealm = exports.DriveFolderRealmSchema = void 0;
7
- const realm_1 = __importDefault(require("realm"));
8
- class DriveFolderRealmSchema extends realm_1.default.Object {
9
- id;
10
- name;
11
- uuid;
12
- relative_path;
13
- parent_id;
14
- created_at;
15
- updated_at;
16
- status;
17
- static schema = {
18
- name: 'DriveFolder',
19
- properties: {
20
- id: 'int',
21
- name: 'string',
22
- uuid: { type: 'string', indexed: true },
23
- relative_path: { type: 'string', indexed: true },
24
- parent_id: { type: 'int', indexed: true, default: -1 },
25
- created_at: 'date',
26
- updated_at: 'date',
27
- status: 'string',
28
- },
29
- primaryKey: 'id',
30
- };
31
- }
32
- exports.DriveFolderRealmSchema = DriveFolderRealmSchema;
33
- class DriveFoldersRealm {
34
- realm;
35
- constructor(realm) {
36
- this.realm = realm;
37
- }
38
- findByRelativePath(relativePath) {
39
- const object = this.realm
40
- .objects('DriveFolder')
41
- .filtered('relative_path = $0', relativePath)
42
- .find((folder) => folder.relative_path === relativePath);
43
- return object ?? null;
44
- }
45
- findByParentId(parentId) {
46
- const parentFolder = this.realm.objectForPrimaryKey('DriveFolder', parentId ?? -1);
47
- return parentFolder;
48
- }
49
- createOrReplace(driveFolder, relativePath) {
50
- const existingObject = this.realm.objectForPrimaryKey('DriveFolder', driveFolder.id);
51
- this.realm.write(() => {
52
- if (existingObject) {
53
- this.realm.delete(existingObject);
54
- }
55
- this.realm.create('DriveFolder', {
56
- id: driveFolder.id,
57
- name: driveFolder.name,
58
- uuid: driveFolder.uuid,
59
- parent_id: driveFolder.parentId ?? -1,
60
- created_at: driveFolder.createdAt,
61
- updated_at: driveFolder.updatedAt,
62
- status: 'EXISTS',
63
- relative_path: relativePath,
64
- });
65
- });
66
- }
67
- }
68
- exports.DriveFoldersRealm = DriveFoldersRealm;
@@ -1,15 +0,0 @@
1
- import { DriveFileItem, DriveFolderItem } from '../../types/drive.types';
2
- import { DriveFileRealmSchema, DriveFilesRealm } from './drive-files.realm';
3
- import { DriveFolderRealmSchema, DriveFoldersRealm } from './drive-folders.realm';
4
- import Realm from 'realm';
5
- export declare class DriveRealmManager {
6
- private driveFilesRealm;
7
- private driveFoldersRealm;
8
- constructor(driveFilesRealm: DriveFilesRealm, driveFoldersRealm: DriveFoldersRealm);
9
- static getRealm(): Realm.ProgressRealmPromise;
10
- findByRelativePath(relativePath: string): DriveFolderRealmSchema | DriveFileRealmSchema | null;
11
- createFolder(driveFolder: DriveFolderItem): void;
12
- createFile(driveFile: DriveFileItem): void;
13
- buildRelativePathForFile(fileName: string, parentId: number | null): string;
14
- buildRelativePathForFolder(folderName: string, parentId: number | null): string;
15
- }
@@ -1,63 +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
- exports.DriveRealmManager = void 0;
7
- const drive_files_realm_1 = require("./drive-files.realm");
8
- const drive_folders_realm_1 = require("./drive-folders.realm");
9
- const webdav_utils_1 = require("../../utils/webdav.utils");
10
- const config_service_1 = require("../config.service");
11
- const realm_1 = __importDefault(require("realm"));
12
- class DriveRealmManager {
13
- driveFilesRealm;
14
- driveFoldersRealm;
15
- constructor(driveFilesRealm, driveFoldersRealm) {
16
- this.driveFilesRealm = driveFilesRealm;
17
- this.driveFoldersRealm = driveFoldersRealm;
18
- }
19
- static getRealm() {
20
- return realm_1.default.open({
21
- path: config_service_1.ConfigService.DRIVE_REALM_FILE,
22
- schema: [drive_files_realm_1.DriveFileRealmSchema, drive_folders_realm_1.DriveFolderRealmSchema],
23
- deleteRealmIfMigrationNeeded: true,
24
- });
25
- }
26
- findByRelativePath(relativePath) {
27
- const driveFile = this.driveFilesRealm.findByRelativePath(relativePath);
28
- if (driveFile)
29
- return driveFile;
30
- let folderRelativePath = relativePath;
31
- if (!relativePath.endsWith('/'))
32
- folderRelativePath = relativePath.concat('/');
33
- const driveFolder = this.driveFoldersRealm.findByRelativePath(folderRelativePath);
34
- if (driveFolder)
35
- return driveFolder;
36
- return null;
37
- }
38
- createFolder(driveFolder) {
39
- const relativePath = this.buildRelativePathForFolder(driveFolder.name, driveFolder.parentId ?? null);
40
- return this.driveFoldersRealm.createOrReplace(driveFolder, relativePath);
41
- }
42
- createFile(driveFile) {
43
- const relativePath = this.buildRelativePathForFile(driveFile.type ? `${driveFile.name}.${driveFile.type}` : driveFile.name, driveFile.folderId);
44
- return this.driveFilesRealm.createOrReplace(driveFile, relativePath);
45
- }
46
- buildRelativePathForFile(fileName, parentId) {
47
- const parentFolder = this.driveFoldersRealm.findByParentId(parentId);
48
- if (!parentFolder) {
49
- return webdav_utils_1.WebDavUtils.joinURL('/', fileName);
50
- }
51
- const parentPath = this.buildRelativePathForFile(parentFolder.name, parentFolder.parent_id ?? null);
52
- return webdav_utils_1.WebDavUtils.joinURL(parentPath, fileName);
53
- }
54
- buildRelativePathForFolder(folderName, parentId) {
55
- const parentFolder = this.driveFoldersRealm.findByParentId(parentId);
56
- if (!parentFolder) {
57
- return webdav_utils_1.WebDavUtils.joinURL('/', folderName, '/');
58
- }
59
- const parentPath = this.buildRelativePathForFolder(parentFolder.name, parentFolder.parent_id ?? null);
60
- return webdav_utils_1.WebDavUtils.joinURL(parentPath, folderName, '/');
61
- }
62
- }
63
- exports.DriveRealmManager = DriveRealmManager;