diff --git a/package.json b/package.json index 01066346..6d8a1907 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@internxt/sdk", "author": "Internxt ", - "version": "1.26.0", + "version": "1.27.0", "description": "An sdk for interacting with Internxt's services", "repository": { "type": "git", diff --git a/src/drive/share/types.ts b/src/drive/share/types.ts index a6ab3a41..96d1097b 100644 --- a/src/drive/share/types.ts +++ b/src/drive/share/types.ts @@ -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; diff --git a/src/drive/storage/index.ts b/src/drive/storage/index.ts index 5adb8a35..8e92aa96 100644 --- a/src/drive/storage/index.ts +++ b/src/drive/storage/index.ts @@ -13,7 +13,6 @@ import { CreateFolderPayload, CreateFolderResponse, CreateThumbnailEntryPayload, - DeleteFilePayload, DriveFileData, FavoriteFileDto, FavoriteFolderDto, @@ -57,7 +56,6 @@ import { RestoreFileVersionResponse, SearchResultData, Thumbnail, - ThumbnailEntry, UpdateFilePayload, UpdateFolderMetadataPayload, UsageResponse, @@ -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 { - return this.client.post( - '/storage/thumbnail', - { - thumbnail: thumbnailEntry, - }, - addResourcesTokenToHeaders(this.headers(), resourcesToken), - ); - } - /** * Creates a new thumbnail entry using drive-server-wip * @param CreateThumbnailEntryPayload @@ -612,15 +596,6 @@ export class Storage { ); } - /** - * Deletes a specific file entry - * @param payload - * @deprecated Use `deleteFileByUuid` instead. - */ - public deleteFile(payload: DeleteFilePayload): Promise { - 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). * diff --git a/src/drive/storage/types.ts b/src/drive/storage/types.ts index 190a01f0..14ddd0ff 100644 --- a/src/drive/storage/types.ts +++ b/src/drive/storage/types.ts @@ -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; @@ -57,7 +56,6 @@ export interface DriveFileData { export interface Thumbnail { id: number; - file_id: number; max_width: number; max_height: number; type: string; @@ -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 'files' | 'file' ? TrashedFile : TrashedFolder; + +export interface FetchTrashContentResponse { + result: T[]; } export enum EncryptionVersion { @@ -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; @@ -335,11 +329,6 @@ export interface UpdateFilePayload { }; } -export interface DeleteFilePayload { - fileId: number; - folderId: number; -} - export interface MoveFilePayload { fileId: string; destination: number; @@ -382,7 +371,7 @@ export interface SearchResult { similarity: number; userId: string; item: { - id: number; + id?: number; bucket?: string; fileId?: string; plainName?: string; diff --git a/src/drive/trash/index.ts b/src/drive/trash/index.ts index 7de93101..22b843a3 100644 --- a/src/drive/trash/index.ts +++ b/src/drive/trash/index.ts @@ -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'; @@ -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 { - return this.client.delete(`/storage/folder/${payload.folderId}/file/${payload.fileId}`, this.headers()); - } - /** * Returns a list of items in trash */ @@ -59,13 +46,13 @@ export class Trash { * @param {number} [folderId] - The ID of the folder to retrieve content from. * @returns {Promise} - A promise that resolves with the paginated list of trashed content. */ - public getTrashedFilesPaginated( + public getTrashedFilesPaginated( limit: number, offset = 0, - type: 'files' | 'folders', + type: T, root: boolean, folderId?: number, - ): Promise { + ): Promise>> { const endpoint = '/storage/trash/paginated'; const folderIdQuery = folderId !== undefined ? `folderId=${folderId}&` : ''; @@ -86,15 +73,15 @@ export class Trash { * @param {number} [folderId] - The ID of the folder to retrieve content from. * @returns {Promise} - A promise that resolves with the paginated list of trashed content. */ - public getTrashedItemsSorted( + public getTrashedItemsSorted( limit: number, offset = 0, - type: 'files' | 'folders', + type: T, root: boolean, sort: 'plainName' | 'updatedAt', order: 'ASC' | 'DESC', folderId?: number, - ): Promise { + ): Promise>> { 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}`; diff --git a/src/drive/trash/types.ts b/src/drive/trash/types.ts index 4004559d..e9dd3991 100644 --- a/src/drive/trash/types.ts +++ b/src/drive/trash/types.ts @@ -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 { diff --git a/src/workspaces/index.ts b/src/workspaces/index.ts index 2d185ab0..647d5cd2 100644 --- a/src/workspaces/index.ts +++ b/src/workspaces/index.ts @@ -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'; @@ -210,17 +211,20 @@ export class Workspaces { ); } - public getPersonalTrash( + public getPersonalTrash( workspaceId: string, - type: ItemType, + type: T, offset = 0, limit = 50, - ): Promise { + ): Promise>> { const offsetQuery = `?offset=${offset}`; const limitQuery = `&limit=${limit}`; const typeQuery = `&type=${type}`; const query = `${offsetQuery}${limitQuery}${typeQuery}`; - return this.client.get(`/workspaces/${workspaceId}/trash${query}`, this.headers()); + return this.client.get>>( + `/workspaces/${workspaceId}/trash${query}`, + this.headers(), + ); } public emptyPersonalTrash(workspaceId: string): Promise { diff --git a/test/drive/storage/index.test.ts b/test/drive/storage/index.test.ts index 7f4e6298..8d409d1e 100644 --- a/test/drive/storage/index.test.ts +++ b/test/drive/storage/index.test.ts @@ -3,7 +3,6 @@ import { Storage, StorageTypes } from '../../../src/drive'; import { CreateFolderPayload, CreateFolderResponse, - DeleteFilePayload, DriveFolderData, EncryptionVersion, FetchPaginatedFolderContentResponse, @@ -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 @@ -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', diff --git a/test/drive/storage/mothers/fileData.mother.ts b/test/drive/storage/mothers/fileData.mother.ts index fb45f415..717f73fa 100644 --- a/test/drive/storage/mothers/fileData.mother.ts +++ b/test/drive/storage/mothers/fileData.mother.ts @@ -11,7 +11,6 @@ export function randomFileData(): DriveFileData { fileId: '', folderId: 0, folder_id: 0, - id: 0, name: '', size: 0, type: '', diff --git a/test/drive/trash/index.test.ts b/test/drive/trash/index.test.ts index 4a66a664..7bf86058 100644 --- a/test/drive/trash/index.test.ts +++ b/test/drive/trash/index.test.ts @@ -1,7 +1,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'; import { Trash } from '../../../src/drive'; import { randomFolderContentResponse } from '../storage/mothers/folderContentResponse.mother'; -import { DeleteFilePayload, DeleteItemsPermanentlyPayload } from '../../../src/drive/trash/types'; +import { DeleteItemsPermanentlyPayload } from '../../../src/drive/trash/types'; import { headersWithToken } from '../../../src/shared/headers'; import { ApiSecurity, AppDetails } from '../../../src/shared'; import { HttpClient } from '../../../src/shared/http/client'; @@ -32,31 +32,6 @@ describe('# trash service tests', () => { }); }); - describe('-> files', () => { - 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('Trash', () => { describe('get Trash', () => { it('Should return the expected elements', async () => { @@ -113,7 +88,6 @@ describe('# trash service tests', () => { items: [ { id: 36225, type: 'folder' }, { id: 36225, type: 'folder' }, - { id: '36225', type: 'file' }, ], };