Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"test:cov": "jest --coverage",
"build": "tsc",
"lint": "eslint ./src",
"format": "prettier src/**/*.ts"
"format": "prettier src/**/*.ts --write",
"swagger": "openapi-typescript https://gateway.internxt.com/drive/api-json -o ./src/schema.d.ts && prettier ./src/schema.d.ts --write"
},
"devDependencies": {
"@internxt/eslint-config-internxt": "2.0.1",
Expand All @@ -35,6 +36,7 @@
"husky": "9.1.7",
"jest": "30.0.5",
"lint-staged": "16.1.5",
"openapi-typescript": "^7.9.1",
"prettier": "3.6.2",
"sinon": "21.0.0",
"ts-jest": "29.4.1",
Expand All @@ -46,7 +48,7 @@
},
"lint-staged": {
"*.{js,jsx,tsx,ts}": [
"prettier --write"
"yarn format"
]
}
}
30 changes: 3 additions & 27 deletions src/drive/backups/types.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,4 @@
export interface Device {
id: number
name: string
mac: string
userId: number
createdAt: string
updatedAt: string
size: number
platform: string | null
}
import { components } from '../../schema';

export interface DeviceBackup {
id: number
path: string
name: string
fileId?: string
deviceId: number
userId: number
interval: number
size?: number
bucket: string
createdAt: string
updatedAt: string
encrypt_version: string
hash?: string
enabled: boolean
lastBackupAt?: string
}
export type Device = components['schemas']['DeviceDto'];
export type DeviceBackup = components['schemas']['DeviceAsFolder'];
12 changes: 6 additions & 6 deletions src/drive/referrals/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export enum ReferralKey {
}

export interface UserReferral {
key: ReferralKey
steps: number
completedSteps: number
isCompleted: boolean
credit: number
type: ReferralType
key: ReferralKey;
steps: number;
completedSteps: number;
isCompleted: boolean;
credit: number;
type: ReferralType;
}
6 changes: 4 additions & 2 deletions src/drive/storage/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { paths } from '../../schema';
import { Token } from '../../auth';
import { ApiSecurity, ApiUrl, AppDetails } from '../../shared';
import { CustomHeaders, addResourcesTokenToHeaders, headersWithToken } from '../../shared/headers';
import { HttpClient, RequestCanceler } from '../../shared/http/client';
import { UUID } from '../../shared/types/userSettings';
import { ItemType } from './../../workspaces/types';
import {
AddItemsToTrashPayload,
CheckDuplicatedFilesPayload,
CheckDuplicatedFilesResponse,
CheckDuplicatedFolderPayload,
Expand Down Expand Up @@ -613,7 +613,9 @@ export class Storage {
* Add Items to Trash
* @param payload
*/
public addItemsToTrash(payload: AddItemsToTrashPayload): Promise<void> {
public addItemsToTrash(
payload: paths['/storage/trash/add']['post']['requestBody']['content']['application/json'],
): Promise<void> {
return this.client.post(
'/storage/trash/add',
{
Expand Down
4 changes: 0 additions & 4 deletions src/drive/storage/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
parent: string | null;
bucket: string;
userId: number;
user: any | null;

Check warning on line 96 in src/drive/storage/types.ts

View workflow job for this annotation

GitHub Actions / test (22.x)

Unexpected any. Specify a different type
encryptVersion: string;
deleted: boolean;
deletedAt: string | null;
Expand Down Expand Up @@ -140,8 +140,8 @@
id: string;
token: string;
mnemonic: string;
user: any;

Check warning on line 143 in src/drive/storage/types.ts

View workflow job for this annotation

GitHub Actions / test (22.x)

Unexpected any. Specify a different type
item: any;

Check warning on line 144 in src/drive/storage/types.ts

View workflow job for this annotation

GitHub Actions / test (22.x)

Unexpected any. Specify a different type
encryptionKey: string;
bucket: string;
itemToken: string;
Expand Down Expand Up @@ -192,7 +192,7 @@
size: bigint;
bucket: string;
folderId: number;
folder?: any;

Check warning on line 195 in src/drive/storage/types.ts

View workflow job for this annotation

GitHub Actions / test (22.x)

Unexpected any. Specify a different type
folderUuid: string;
encryptVersion: string;
deleted: boolean;
Expand Down Expand Up @@ -416,10 +416,6 @@
maxSpaceBytes: number;
}

export interface AddItemsToTrashPayload {
items: Array<{ id?: string; uuid?: string; type: string }>;
}

export interface SearchResult {
id: string;
itemId: string;
Expand Down
12 changes: 5 additions & 7 deletions src/drive/trash/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { paths } from '../../schema';
import { ApiSecurity, ApiUrl, AppDetails } from '../../shared';
import { headersWithToken } from '../../shared/headers';
import { HttpClient } from '../../shared/http/client';
import { FetchFolderContentResponse, FetchTrashContentResponse } from '../storage/types';
import {
AddItemsToTrashPayload,
DeleteFilePayload,
DeleteItemsPermanentlyByUUIDPayload,
DeleteItemsPermanentlyPayload,
} from './types';
import { DeleteFilePayload, DeleteItemsPermanentlyByUUIDPayload, DeleteItemsPermanentlyPayload } from './types';

export * as TrashTypes from './types';

Expand Down Expand Up @@ -108,7 +104,9 @@ export class Trash {
* Add Items to Trash
* @param payload
*/
public addItemsToTrash(payload: AddItemsToTrashPayload): Promise<void> {
public addItemsToTrash(
payload: paths['/storage/trash/add']['post']['requestBody']['content']['application/json'],
): Promise<void> {
return this.client.post(
'/storage/trash/add',
{
Expand Down
4 changes: 0 additions & 4 deletions src/drive/trash/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
export interface AddItemsToTrashPayload {
items: Array<{ id?: string; uuid?: string; type: string }>;
}

export interface DeleteFilePayload {
fileId: number;
folderId: number;
Expand Down
15 changes: 9 additions & 6 deletions src/network/errors/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,25 @@
*
*/
enum UploadErrorCode {
InvalidMnemonic = 11100
InvalidMnemonic = 11100,
}

enum DownloadErrorCode {
InvalidMnemonic = 12100
InvalidMnemonic = 12100,
}

type NetworkErrorCode = UploadErrorCode | DownloadErrorCode
type NetworkErrorCode = UploadErrorCode | DownloadErrorCode;

export class CodeError extends Error {
constructor(public code: NetworkErrorCode, public message: string) {
constructor(
public code: NetworkErrorCode,
public message: string,
) {
super(message);
}
}

export default {
Upload: UploadErrorCode,
Download: DownloadErrorCode
};
Download: DownloadErrorCode,
};
8 changes: 4 additions & 4 deletions src/network/errors/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ export type NetworkUploadContext = {
user: string;
crypto: {
mnemonic?: string;
}
}
};
};
export type NetworkDownloadContext = {
bucketId: string;
fileId: string;
user: string;
crypto: {
mnemonic?: string;
}
}
};
};

export type NetworkContext = NetworkUploadContext | NetworkDownloadContext;

Expand Down
21 changes: 10 additions & 11 deletions src/network/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,47 +81,46 @@ export type DownloadFileFunction = (downloadables: DownloadableShard[], fileSize
export type BinaryData = {
slice: (from: number, to: number) => BinaryData;
toString(encoding: 'hex'): string;
}
};

export enum BinaryDataEncoding {
HEX = 'hex'
HEX = 'hex',
}

export type ToBinaryDataFunction = (input: string, encoding: BinaryDataEncoding) => BinaryData;


export enum SymmetricCryptoAlgorithm {
AES256CTR = 'AES256CTR'
AES256CTR = 'AES256CTR',
}

export type Algorithm = {
type: SymmetricCryptoAlgorithm
ivSize: number
type: SymmetricCryptoAlgorithm;
ivSize: number;
};

export const ALGORITHMS: Record<SymmetricCryptoAlgorithm, Algorithm> = {
[SymmetricCryptoAlgorithm.AES256CTR]: {
type: SymmetricCryptoAlgorithm.AES256CTR,
ivSize: 32
}
ivSize: 32,
},
};

export type Crypto = {
algorithm: Algorithm;
validateMnemonic: (mnemonic: string) => boolean;
randomBytes: (bytesLength: number) => BinaryData;
generateFileKey: (mnemonic: string, bucketId: string, index: BinaryData | string) => Promise<BinaryData>;
}
};

export type EncryptFileFunction = (
algorithm: SymmetricCryptoAlgorithm,
key: BinaryData,
iv: BinaryData
iv: BinaryData,
) => Promise<void>;

export type DecryptFileFunction = (
algorithm: SymmetricCryptoAlgorithm,
key: BinaryData,
iv: BinaryData,
fileSize: number
fileSize: number,
) => Promise<void>;
Loading
Loading