import { StoreApi } from '../api/store/StoreApi'; import { EventDispatcher } from '../EventDispatcher'; import { ListOptions, PagingList } from '../types/core'; import { EventsByChannel, StoreEvents, StoreFileEvents, SubscribeForChannel } from '../types/events'; import { EndpointApiEvent, PrivmxFile, Store, UserWithPubKey } from '../types/index'; import { StoreFilePayload } from '../types/store'; import { Endpoint } from './Endpoint'; import { FileUploader } from './FileUploader'; import { StreamReader } from './StreamReader'; import { StreamUploader } from './StreamUploader'; export declare class StoreClient { private _storeId; private _endpoint; private _eventDispatcher; constructor(storeId: string, endpoint: Endpoint, eventDispatcher: EventDispatcher); get storeId(): string; /** * Gets Store metadata by given Store ID * @param {string} storeId - ID of given Store * @returns {Promise} - {@link Store `Promise`} */ static getStore(api: StoreApi, storeId: string): Promise; /** * Gets associated StoreApi * @returns {Promise} {@link StoreApi `Promise`} */ private getApi; /** * Returns info about current Store * @returns {Promise} - {@link Store} */ getInfo(): Promise; /** * Creates a new Store in Context * @param {StoreApi} api {@link StoreApi `StoreApi`} instance * @param {object} newStore * @param {string} newStore.contextId Context ID in which the Store should be created * @param {UserWithPubKey[]} newStore.users list of {@link UserWithPubKey} with access to this Store * @param {UserWithPubKey[]} newStore.managers list of {@link UserWithPubKey} with manage rights to this Store * @param {Uint8Array} newStore.publicMeta optional public (unencrypted) metadata * @param {Uint8Array} newStore.privateMeta optional (encrypted) metadata * * @returns {Promise} ID of the created Store */ static createStore(api: StoreApi, newStore: { contextId: string; users: UserWithPubKey[]; managers: UserWithPubKey[]; publicMeta?: Uint8Array; privateMeta?: Uint8Array; }): Promise; /** * Returns metadata about given file * @param {string} fileId - The ID of the file to get metadata from * @returns {Promise} {@link PrivmxFile `Promise`} */ static getFileMetaData(api: StoreApi, fileId: string): Promise; /** * Updates file metadata * @param {StoreApi} api {@link StoreApi `StoreApi`} instance * @param {object} file * @param {string} file.fileId - ID of file to update * @param {Uint8Array} file.publicMeta - metadata that will be unencrypted * @param {Uint8Array} file.privateMeta - metadata that will be encrypted * @returns {Promise} - a promise that resolves with void */ static updateFileMeta(api: StoreApi, file: { fileId: string; publicMeta?: Uint8Array; privateMeta?: Uint8Array; }): Promise; /** * Gets a list of files in the given Store. * @param pageIndex * @param {ListOptions} options optional {@link ListOptions options} object * @returns {Promise>} {@link PagingList `PagingList`} */ getFiles(pageIndex?: number, options?: ListOptions): Promise>; /** * List Stores the user has access to * @param {StoreApi} api {@link StoreApi `StoreApi`} instance * @param {string} contextId * @param {number} pageIndex - indicates from which page the list should start * @param {ListOptions} options optional {@link ListOptions options} object * @returns {Promise>} - {@link PagingList `PagingList`} */ static getStores(api: StoreApi, contextId: string, pageIndex?: number, options?: ListOptions): Promise>; /** * Reads a file and returns a stream handler along with its metadata. * @param {string} fileId - The ID of the file to be read. * @returns {Promise<{streamReader: StreamReader, size: number, mimetype: string, name: string}>} * A promise that resolves with object containing the stream reader, file size, MIME type, and file name. * * @example *```js *const fileStream = await StoreClient.readFile('sdjvs'); * while (await fileStream.streamReader.readNextChunk()) { * console.log('Current progress: ', fileStream.streamReader.progress); *} * fileStream.streamReader.close(); *``` */ static streamRead(api: StoreApi, fileId: string): Promise; /** * Get the content of given file * @param {StoreApi} api {@link StoreApi `StoreApi`} instance * @param {string} fileId - ID of the file to get the content from * @param {function(number): void} progressCallback optional function to report progress * @returns {Promise} content of the file */ static getFileContents(api: StoreApi, fileId: string, progressCallback?: (progress: number) => void): Promise; /** * Downloads file from Store to your local environment * @param {StoreApi} api {@link StoreApi `StoreApi`} instance * @param {object} file * @param {string} file.fileId File ID * @param {string} [file.name] - Optional name given to the file * @param {function(number): void} [file.progressCallback] - Optional callback function to report progress * * @returns {Promise} a promise that resolves with void and download the file to the browser environment */ static downloadFile(api: StoreApi, file: { fileId: string; name?: string; progressCallback?: (progress: number) => void; }): Promise; /** * Downloads file using the window.showSaveFilePicker * @param {StoreApi} api {@link StoreApi `StoreApi`} instance * @param {object} file * @param {string} file.fileId File ID * @param {string} [file.name] - name given to the file * @param {function(number): void} [file.progressCallback] - Optional callback function to report progress */ private static chunkDownload; /** * Streams a file to a Store. * * @param {StoreFilePayload} newFile - The file to be streamed. * @returns {Promise} - A promise that resolves to a StreamUploader instance if successful, or void if an error occurs. */ streamData(newFile: StoreFilePayload): Promise; /** * Allows you to handle streaming a file from web File Handler * @param {object} newFile * @param {File} newFile.file * @param {Uint8Array=} [newFile.publicMeta] contains data that can be accessed by everyone and is not encrypted. * @param {Uint8Array=} [newFile.privateMeta] contains confidential data that will be encrypted before sent to server * @returns {Promise} instance of a FileUploader */ streamFile(newFile: { file: File; publicMeta?: Uint8Array; privateMeta?: Uint8Array; }): Promise; /** * Upload custom data to a Store * @param {StoreFilePayload} newData {@link StoreFilePayload `StoreFilePayload`} * @param {function(number): void} progressCallback - Optional callback function to report progress * @returns {Promise} file ID */ uploadData(newData: StoreFilePayload, progressCallback?: (progress: number) => void): Promise; /** * Update file contents * @param {StoreApi} api {@link StoreApi `StoreApi`} instance * @param {object} params * @param {string} params.fileId fileId * @param {Uint8Array} params.data * @param {number} params.offset - where to start appending data * @param {function(number): void} [params.progressCallback] - Optional callback function to report progress * @returns {Promise} file ID */ static updateFile(api: StoreApi, params: { fileId: string; data: Uint8Array; offset?: number; progressCallback?: (progress: number) => void; }): Promise; /** * Override file contents * @param {StoreApi} api {@link StoreApi `StoreApi`} instance * @param {object} params - params * @param {string} params.fileId - fileId * @param {StoreFilePayload} params.file {@link StoreFilePayload `StoreFilePayload`} object * @param {function(number): void} [params.progressCallback] - Optional callback function to report progress * @returns {Promise} file ID */ static overrideFile(api: StoreApi, params: { fileId: string; file: StoreFilePayload; progressCallback?: (progress: number) => void; }): Promise; /** * Deletes file from Store. * @param {string} fileId - The ID of the file to delete. * @returns {Promise} A promise that resolves when the file is successfully deleted. */ static deleteFile(api: StoreApi, fileId: string): Promise; /** * Deletes current Store. * @returns {Promise} A promise that resolves when the Store updates successfully deleted. */ deleteStore(): Promise; /** * Updates metadata about the given Store. * * @param {Object} newStore - The new Store data. * @param {UserWithPubKey[]} newStore.users list of {@link UserWithPubKey} with access to this Store * @param {UserWithPubKey[]} newStore.managers list of {@link UserWithPubKey} with manage rights to this Store * @param {Uint8Array} newStore.publicMeta public (unencrypted) metadata * @param {Uint8Array} newStore.privateMeta (encrypted) metadata * @param {number} newStore.version - The version number of the Store data. * @param {boolean} [newStore.options.force] - optional flag to generate a new key ID for the Store * @param {boolean} [newStore.options.forceGenerateNewKey] - optional flag to allow new users to access old data * @returns {Promise} A promise that resolves when the Store update is complete. */ storeUpdate(newStore: { users: UserWithPubKey[]; managers: UserWithPubKey[]; publicMeta?: Uint8Array; privateMeta?: Uint8Array; version: number; options?: { force?: boolean; forceGenerateNewKey?: boolean; }; }): Promise; private getOn; /** * Subscribes to file-related events in given Store: * - `storeFileCreated` * - `storeFileDeleted` * - `storeFileUpdated` * @returns {Promise>} {@link SubscribeForChannel<'storeFiles'> `Promise>`} */ subscribeForFileEvents(): Promise>; /** * Unsubscribes from file-related events in this Store * @returns {Promise} a promise that resolves with void */ unsubscribeFromFileEvents(): Promise; /** * Registers an event listener for store file-related events. * * @template T * @param {T & EventsByChannel<'storeFiles'>} eventType - type of event to listen for. * @param {function(Extract): void} callback - callback function to execute when the event occurs. * @returns {Promise<{on: SubscribeForChannel<'storeFiles'>, removeEventListener: function() void}>} object containing the `on` function for chaining and `removeEventListener` to unregister the event listener. */ on>(eventType: T, callback: (payload: Extract) => void): SubscribeForChannel<'storeFiles'> & { removeEventListener: () => void; }; private static getOn; /** * Subscribes to events related to Stores: * - `storeCreated` * - `storeDeleted` * - `storeStatsChanged` * - `storeUpdated` * @param {StoreApi} api - instance of Store Api * @param {EventDispatcher} eventDispatcher {@link EventDispatcher eventDispatcher} * @returns {Promise>} {@link SubscribeForChannel<'store'> `Promise>`} */ static subscribeForStoreEvents(api: StoreApi, eventDispatcher: EventDispatcher): Promise>; /** * Unsubscribes from events related to stores * @param {StoreApi} api - instance of Store Api * @param {EventDispatcher} eventDispatcher {@link EventDispatcher eventDispatcher} * @returns {Promise} a promise that resolves with void */ static unsubscribeFromStoreEvents(api: StoreApi, eventDispatcher: EventDispatcher): Promise; /** * Registers an event listener for Store-related events. * * @template T * @param {EventDispatcher} eventDispatcher * @param {T & EventsByChannel<'store'>} eventType - type of event to listen for. * @param {function(Extract): void} callback - callback function to execute when the event occurs. * @returns {Promise<{on: SubscribeForChannel<'store'>, removeEventListener: function() void}>} object containing the `on` function for chaining and `removeEventListener` to unregister the event listener. */ static on>(eventDispatcher: EventDispatcher, eventType: T, callback: (payload: Extract) => void): SubscribeForChannel<'store'> & { removeEventListener: () => void; }; /** * Function to upload a file from a browser {@link File `File`} handle * @param {object} newFile * @param {File} newFile.file - file to upload * @param {Uint8Array} newFile.publicMeta optional public (unencrypted) metadata * @param {Uint8Array} newFile.privateMeta optional (encrypted) metadata * @param {function(number): void} progressCallback optional function to report progress * @returns {Promise} return the ID of the uploaded file */ uploadFile(newFile: { file: File; publicMeta?: Uint8Array; privateMeta?: Uint8Array; }, progressCallback?: (progress: number) => void): Promise; }