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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@internxt/sdk",
"author": "Internxt <[email protected]>",
"version": "1.26.0",
"version": "1.27.0",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down
2 changes: 0 additions & 2 deletions src/drive/share/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,9 @@ export type SharedFiles = {
deleted: boolean;
deletedAt: string | null;
encryptVersion: string;
fileiId: number;
folder: string | null;
folderId: number;
folderUuid: string;
id: number;
modificationTime: string;
name: string;
plainName: string;
Expand Down
25 changes: 0 additions & 25 deletions src/drive/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
CreateFolderPayload,
CreateFolderResponse,
CreateThumbnailEntryPayload,
DeleteFilePayload,
DriveFileData,
FavoriteFileDto,
FavoriteFolderDto,
Expand Down Expand Up @@ -57,7 +56,6 @@ import {
RestoreFileVersionResponse,
SearchResultData,
Thumbnail,
ThumbnailEntry,
UpdateFilePayload,
UpdateFolderMetadataPayload,
UsageResponse,
Expand Down Expand Up @@ -523,20 +521,6 @@ export class Storage {
return this.client.post('/files', fileEntry, addResourcesTokenToHeaders(this.headers(), resourcesToken));
}

/**
* Creates a new thumbnail entry
* @param thumbnailEntry
*/
public createThumbnailEntry(thumbnailEntry: ThumbnailEntry, resourcesToken?: Token): Promise<Thumbnail> {
return this.client.post(
'/storage/thumbnail',
{
thumbnail: thumbnailEntry,
},
addResourcesTokenToHeaders(this.headers(), resourcesToken),
);
}

/**
* Creates a new thumbnail entry using drive-server-wip
* @param CreateThumbnailEntryPayload
Expand Down Expand Up @@ -612,15 +596,6 @@ export class Storage {
);
}

/**
* Deletes a specific file entry
* @param payload
* @deprecated Use `deleteFileByUuid` instead.
*/
public deleteFile(payload: DeleteFilePayload): Promise<unknown> {
return this.client.delete(`/storage/folder/${payload.folderId}/file/${payload.fileId}`, this.headers());
}

/**
* Deletes a file from the storage system using its unique identifier (UUID).
*
Expand Down
71 changes: 30 additions & 41 deletions src/drive/storage/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export interface DriveFileData {
folderId: number;
folder_id: number;
folderUuid: string;
id: number;
name: string;
plain_name: string | null;
plainName?: string | null;
Expand All @@ -57,7 +56,6 @@ export interface DriveFileData {

export interface Thumbnail {
id: number;
file_id: number;
max_width: number;
max_height: number;
type: string;
Expand Down Expand Up @@ -210,28 +208,35 @@ export type FetchFilesSyncResponse = paths['/files/sync']['get']['responses']['2

export type FetchFoldersSyncResponse = paths['/folders/sync']['get']['responses']['200']['content']['application/json'];

export interface FetchTrashContentResponse {
result: {
id: number;
fileId: string;
folderId: number;
folder: string | null;
name: string;
type: string;
size: string;
bucket: string;
encryptVersion: string;
deleted: boolean;
deletedAt: Date;
userId: number;
user: string | null;
modificationTime: Date;
createdAt: Date;
updatedAt: Date;
folderUuid: string | null;
uuid: string;
plainName: string;
}[];
export interface TrashedFile {
fileId: string;
folderId: number;
folder: string | null;
name: string;
type: string;
size: string;
bucket: string;
encryptVersion: string;
deleted: boolean;
deletedAt: Date;
userId: number;
user: string | null;
modificationTime: Date;
createdAt: Date;
updatedAt: Date;
folderUuid: string | null;
uuid: string;
plainName: string;
}

export type TrashedFolder = components['schemas']['FolderDto'];

export type TrashItemType = 'files' | 'folders' | 'file' | 'folder';

export type TrashedItem<T extends TrashItemType> = T extends 'files' | 'file' ? TrashedFile : TrashedFolder;

export interface FetchTrashContentResponse<T = TrashedFile> {
result: T[];
}

export enum EncryptionVersion {
Expand All @@ -251,17 +256,6 @@ export interface FileEntry {

export type FileEntryByUuid = paths['/files']['post']['requestBody']['content']['application/json'];

export interface ThumbnailEntry {
file_id: number;
max_width: number;
max_height: number;
type: string;
size: number;
bucket_id: string;
bucket_file: string;
encrypt_version: EncryptionVersion;
}

export interface CreateThumbnailEntryPayload {
fileUuid: string;
type: string;
Expand Down Expand Up @@ -335,11 +329,6 @@ export interface UpdateFilePayload {
};
}

export interface DeleteFilePayload {
fileId: number;
folderId: number;
}

export interface MoveFilePayload {
fileId: string;
destination: number;
Expand Down Expand Up @@ -382,7 +371,7 @@ export interface SearchResult {
similarity: number;
userId: string;
item: {
id: number;
id?: number;
bucket?: string;
fileId?: string;
plainName?: string;
Expand Down
29 changes: 8 additions & 21 deletions src/drive/trash/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
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 { FetchFolderContentResponse, FetchTrashContentResponse, TrashedItem } from '../storage/types';
import { AddItemsToTrashPayload, DeleteItemsPermanentlyByUUIDPayload, DeleteItemsPermanentlyPayload } from './types';

export * as TrashTypes from './types';

Expand All @@ -34,14 +29,6 @@ export class Trash {
return this.client.delete(`/storage/folder/${folderId}`, this.headers());
}

/**
* Deletes a specific file entry
* @param payload
*/
public async deleteFile(payload: DeleteFilePayload): Promise<unknown> {
return this.client.delete(`/storage/folder/${payload.folderId}/file/${payload.fileId}`, this.headers());
}

/**
* Returns a list of items in trash
*/
Expand All @@ -59,13 +46,13 @@ export class Trash {
* @param {number} [folderId] - The ID of the folder to retrieve content from.
* @returns {Promise<FetchTrashContentResponse>} - A promise that resolves with the paginated list of trashed content.
*/
public getTrashedFilesPaginated(
public getTrashedFilesPaginated<T extends 'files' | 'folders'>(
limit: number,
offset = 0,
type: 'files' | 'folders',
type: T,
root: boolean,
folderId?: number,
): Promise<FetchTrashContentResponse> {
): Promise<FetchTrashContentResponse<TrashedItem<T>>> {
const endpoint = '/storage/trash/paginated';
const folderIdQuery = folderId !== undefined ? `folderId=${folderId}&` : '';

Expand All @@ -86,15 +73,15 @@ export class Trash {
* @param {number} [folderId] - The ID of the folder to retrieve content from.
* @returns {Promise<FetchTrashContentResponse>} - A promise that resolves with the paginated list of trashed content.
*/
public getTrashedItemsSorted(
public getTrashedItemsSorted<T extends 'files' | 'folders'>(
limit: number,
offset = 0,
type: 'files' | 'folders',
type: T,
root: boolean,
sort: 'plainName' | 'updatedAt',
order: 'ASC' | 'DESC',
folderId?: number,
): Promise<FetchTrashContentResponse> {
): Promise<FetchTrashContentResponse<TrashedItem<T>>> {
const endpoint = '/storage/trash/paginated';
const folderIdQuery = folderId !== undefined ? `folderId=${folderId}&` : '';
const params = `limit=${limit}&offset=${offset}&type=${type}&root=${root}&sort=${sort}&order=${order}`;
Expand Down
7 changes: 1 addition & 6 deletions src/drive/trash/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ import { paths } from '../../schema';

export type AddItemsToTrashPayload = paths['/storage/trash/add']['post']['requestBody']['content']['application/json'];

export interface DeleteFilePayload {
fileId: number;
folderId: number;
}

export interface DeleteItemsPermanentlyPayload {
items: Array<{ id: number; type: 'folder' } | { id: string; type: 'file' }>;
items: Array<{ id: number; type: 'folder' }>;
}

export interface DeleteItemsPermanentlyByUUIDPayload {
Expand Down
12 changes: 8 additions & 4 deletions src/workspaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
DriveFileData,
FetchPaginatedFolderContentResponse,
FetchTrashContentResponse,
TrashedItem,
} from '../drive/storage/types';
import { ApiSecurity, ApiUrl, AppDetails } from '../shared';
import { addResourcesTokenToHeaders, headersWithToken } from '../shared/headers';
Expand Down Expand Up @@ -210,17 +211,20 @@ export class Workspaces {
);
}

public getPersonalTrash(
public getPersonalTrash<T extends ItemType>(
workspaceId: string,
type: ItemType,
type: T,
offset = 0,
limit = 50,
): Promise<FetchTrashContentResponse> {
): Promise<FetchTrashContentResponse<TrashedItem<T>>> {
const offsetQuery = `?offset=${offset}`;
const limitQuery = `&limit=${limit}`;
const typeQuery = `&type=${type}`;
const query = `${offsetQuery}${limitQuery}${typeQuery}`;
return this.client.get<FetchTrashContentResponse>(`/workspaces/${workspaceId}/trash${query}`, this.headers());
return this.client.get<FetchTrashContentResponse<TrashedItem<T>>>(
`/workspaces/${workspaceId}/trash${query}`,
this.headers(),
);
}

public emptyPersonalTrash(workspaceId: string): Promise<void> {
Expand Down
25 changes: 0 additions & 25 deletions test/drive/storage/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Storage, StorageTypes } from '../../../src/drive';
import {
CreateFolderPayload,
CreateFolderResponse,
DeleteFilePayload,
DriveFolderData,
EncryptionVersion,
FetchPaginatedFolderContentResponse,
Expand Down Expand Up @@ -677,29 +676,6 @@ describe('# storage service tests', () => {
});
});

describe('delete file', () => {
it('Should call with right arguments and return control', async () => {
// Arrange
const callStub = vi.spyOn(HttpClient.prototype, 'delete').mockResolvedValue({
valid: true,
});
const { client, headers } = clientAndHeaders({});
const payload: DeleteFilePayload = {
fileId: 5,
folderId: 2,
};

// Act
const body = await client.deleteFile(payload);

// Assert
expect(callStub).toHaveBeenCalledWith('/storage/folder/2/file/5', headers);
expect(body).toEqual({
valid: true,
});
});
});

describe('move file', () => {
it('Should call with right arguments & return content', async () => {
// Arrange
Expand Down Expand Up @@ -1144,7 +1120,6 @@ describe('# storage service tests', () => {

const expectedResponse: StorageTypes.Thumbnail = {
id: 456,
file_id: 123,
max_width: 200,
max_height: 200,
type: 'image/jpeg',
Expand Down
1 change: 0 additions & 1 deletion test/drive/storage/mothers/fileData.mother.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export function randomFileData(): DriveFileData {
fileId: '',
folderId: 0,
folder_id: 0,
id: 0,
name: '',
size: 0,
type: '',
Expand Down
Loading
Loading