UNPKG

@zcatalyst/filestore

Version:

ZOHO CATALYST SDK for JavaScript Filestore for Node.js and Browser.

134 lines (133 loc) 5.57 kB
import { Handler } from '@zcatalyst/transport'; import { ICatalystGResponse, ParsableComponent } from '@zcatalyst/utils'; import { IncomingMessage } from 'http'; import { Filestore } from './filestore'; import { ICatalystFile, ICatalystFolder } from './utils/interface'; export type ICatalystFolderDetails = ICatalystFolder & Pick<ICatalystGResponse, Exclude<keyof ICatalystGResponse, 'modified_time' | 'modified_by'>>; type ICatalystFileDetails = ICatalystFile & ICatalystGResponse; export declare class Folder implements ParsableComponent<ICatalystFolderDetails> { _folderDetails: ICatalystFolderDetails; requester: Handler; constructor(fileInstance: Filestore, folderDetails: ICatalystFolderDetails); /** * Retrieves the name of the file store component. * * @returns {string} The name of the component. */ getComponentName(): string; /** * Fetches details of a specific file. * * @param {string} id - The ID of the file. * @returns {ICatalystFileDetails} The details of the requested file. * @throws {CatalystFileStoreError} If the file ID is invalid or the request fails. * * @example * const fileDetails = await fileStoreInstance.getFileDetails('12345'); * console.log(fileDetails.name); */ getFileDetails(id: string): Promise<ICatalystFileDetails>; /** * Deletes a file by its ID. * * @param {string} id - The ID of the file to delete. * @returns {boolean} `true` if the file was successfully deleted, otherwise `false`. * @throws {CatalystFileStoreError} If the file ID is invalid or the request fails. * * @example * const isDeleted = await fileStoreInstance.deleteFile('12345'); * console.log(isDeleted); // true */ deleteFile(id: string): Promise<boolean>; /** * Uploads a file to the file store. * * @param {Object} fileDetails - The file details object. * @param {string | Blob} fileDetails.code - The file content as a string or Blob. * @param {string} fileDetails.name - The name of the file. * @param {AbortSignal} [fileDetails.signal] - Optional abort signal for cancellation. * @returns {Omit<ICatalystFileDetails, 'modified_time' | 'modified_by'>} The uploaded file details. * @throws {CatalystFileStoreError} If the file details are invalid. * * @example * const file = new Blob(["Hello, World!"], { type: "text/plain" }); * const response = await fileStoreInstance.uploadFile({ code: file, name: "hello.txt" }); * console.log(response.file_id); */ uploadFile(fileDetails: { code: File; name: string; signal?: AbortSignal; }): Promise<Pick<ICatalystFileDetails, Exclude<keyof ICatalystFileDetails, 'modified_time' | 'modified_by'>>>; /** * Generates a request configuration for downloading a file. * * @param {string} id - The ID of the file to download. * @returns {IRequestConfig} The request configuration object. * @throws {CatalystFileStoreError} If the file ID is invalid. */ private getDownloadRequest; /** * Downloads a file as a buffer. * * @param {string} id - The ID of the file to download. * @returns {unknown} The file buffer data. * @throws {CatalystFileStoreError} If the file ID is invalid or the request fails. * * @example * const fileBuffer = await fileStoreInstance.downloadFile('12345'); * console.log(fileBuffer); */ downloadFile(id: string): Promise<unknown>; /** * Retrieves a readable stream for the file. * * @param {string} id - The ID of the file. * @returns {IncomingMessage} The file stream. * @throws {CatalystFileStoreError} If the file ID is invalid. * * @example * const fileStream = await fileStoreInstance.getFileStream('12345'); * fileStream.pipe(fs.createWriteStream("downloaded_file.txt")); */ getFileStream(id: string): Promise<IncomingMessage>; /** * Converts the folder details to a JSON string. * * @returns {string} A JSON string representation of the folder details. */ toString(): string; /** * Retrieves the folder details in JSON format. * * @returns {ICatalystFolderDetails} The folder details. */ toJSON(): ICatalystFolderDetails; } export declare class FolderAdmin extends Folder { constructor(fileInstance: Filestore, folderDetails: ICatalystFolderDetails); /** * Updates the folder details. * * @param {Omit<ICatalystFolder, 'id'>} folderDetails - The updated folder details. * @returns {ICatalystFolderDetails} The updated folder information. * @throws {CatalystFileStoreError} If the folder details are invalid. * * @example * const updatedFolder = await folderInstance.update({ folder_name: "New Folder Name" }); * console.log(updatedFolder); */ update(folderDetails: Pick<ICatalystFolder, Exclude<keyof ICatalystFolder, 'id'>>): Promise<ICatalystFolderDetails>; /** * Deletes the folder. * * @returns {boolean} `true` if the folder was successfully deleted, otherwise `false`. * @throws {CatalystFileStoreError} If the request fails. * * @example * const isDeleted = await folderInstance.delete(); * console.log(isDeleted); */ delete(): Promise<boolean>; } export {};