import { InboxApi } from '../api/inbox/InboxApi'; import { StoreApi } from '../api/store/StoreApi'; import { EventDispatcher } from '../EventDispatcher'; import { EndpointApiEvent, FilesConfig, Inbox, InboxEntry, InboxPublicView, ListOptions, PagingList, UserWithPubKey } from '../types'; import { EventsByChannel, InboxEntryEvents, InboxEvents, SubscribeForChannel } from '../types/events'; import { InboxEntryPayload } from '../types/inboxes'; import { Endpoint } from './Endpoint'; import { StreamReader } from './StreamReader'; /** * Wrapper class for the InboxApi. */ export declare class InboxClient { private _inboxId; private _endpoint; private _eventDispatcher; constructor(inboxId: string, endpoint: Endpoint, eventDispatcher: EventDispatcher); /** * @returns {string} `inboxId` */ get inboxId(): string; private getApi; /** * Creates a new Inbox * @param {InboxApi} api {@link InboxApi `InboxApi`} * @param {object} newInbox * @param {string} newInbox.contextId - ID of the Context for the new Inbox * @param {UserWithPubKey[]} newInbox.users - list of {@link UserWithPubKey `UserWithPubKey`} objects which indicates who will have access to the created Inbox * @param {UserWithPubKey[]} newInbox.managers - list of {@link UserWithPubKey `UserWithPubKey`} objects which indicates who will have access (and management rights) to the created Inbox * @param {Uint8Array} newInbox.publicMeta - (unencrypted) public Inbox metadata * @param {Uint8Array} newInbox.privateMeta - (encrypted) private Inbox metadata * @param {FilesConfig} newInbox.filesConfig object to override default file configuration * @returns {Promise} Created Inbox ID */ static createInbox(api: InboxApi, newInbox: { contextId: string; users: UserWithPubKey[]; managers: UserWithPubKey[]; publicMeta?: Uint8Array; privateMeta?: Uint8Array; filesConfig?: FilesConfig; }): Promise; /** * Gets a list of Inboxes in the given Context. * @param {InboxApi} api {@link InboxApi `InboxApi`} * @param {string} contextId ID of the Context to get Inboxes from * @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 getInboxes(api: InboxApi, contextId: string, pageIndex?: number, options?: ListOptions): Promise>; /** * Fetches info about current Inbox * @returns {Promise} {@link Inbox `Inbox`} object */ getInboxInfo(): Promise; /** * Fetches inbox public meta. * @returns {Promise} */ getPublicView(): Promise; /** * Updates an existing Inbox. * @param {object} updatedData * @param {UserWithPubKey[]} updatedData.users list of {@link UserWithPubKey `UserWithPubKey`} objects which indicates who will have access to the updated Inbox * @param {UserWithPubKey[]} updatedData.managers list of {@link UserWithPubKey `UserWithPubKey`} objects which indicates who will have access (and management rights) to the updated Inbox * @param {Uint8Array} updatedData.publicMeta - (unencrypted) public Inbox metadata * @param {Uint8Array} updatedData.privateMeta - (encrypted) private Inbox metadata * @param {FilesConfig | undefined} updatedData.filesConfig object to override default file configuration. Provide undefined if you want to leave the default configuration. * @param {number} updatedData.version current version of the updated Inbox * @param {boolean} [updatedData.options.force] - optional flag to generate a new key ID for the Inbox * @param {boolean} [updatedData.options.forceGenerateNewKey] - optional flag to allow new users to access old data * @returns {Promise} */ updateInbox(updatedData: { users: UserWithPubKey[]; managers: UserWithPubKey[]; publicMeta?: Uint8Array; privateMeta?: Uint8Array; filesConfig?: FilesConfig; version: number; options?: { force?: boolean; forceGenerateNewKey?: boolean; }; }): Promise; /** * Deletes current Inbox * @returns {Promise} a promise that resolves with void */ deleteInbox(): Promise; /** * Sends data and optional files to an Inbox. * * @param {InboxEntryPayload} entry {@link InboxEntryPayload `InboxEntryPayload`} object * @returns {Promise} A promise that resolves when the data and files have been successfully sent to the Inbox. */ sendData(entry: InboxEntryPayload): Promise; /** * Sends a file to an Inbox. * * @param {{name: string, data: Uint8Array, mimeType: string, handle: number}} fileWithHandle - The file with its handle to send. * @param {number} inboxHandle - The handle of the Inbox to which the file will be sent. * @returns {Promise} - A promise that resolves when the file has been successfully sent to the Inbox. */ private uploadFile; /** * Gets a list of entries from current Inbox. * @param {number} pageIndex * @param {ListOptions} options optional {@link ListOptions `options`} object * @returns {Promise>} {@link PagingList `PagingList`} */ listEntries(pageIndex?: number, options?: ListOptions): Promise>; /** * Gets an Inbox entry based on its ID * @param {InboxApi} api {@link InboxApi `InboxApi`} * @param {string} entryId Id of the entry * @returns {Promise} {@link InboxEntry `Promise`} */ static getEntry(api: InboxApi, entryId: string): Promise; /** * Deletes an entry from Inbox * @param {InboxApi} api {@link InboxApi `InboxApi`} * @param {string} entryId ID of entry to delete * @returns {Promise} */ static deleteEntry(api: InboxApi, entryId: string): Promise; /** * Downloads file from Inbox to your local environment * @param {InboxApi} api {@link InboxApi `InboxApi`} * @param {StoreApi} storeApi {@link StoreApi `StoreApi`} * @param {object} file * @param {string} file.fileId File ID * @param {string} file.fileName optional name that will be assigned 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: InboxApi, storeApi: StoreApi, file: { fileId: string; fileName?: 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; /** * Get the content of given file * @param {InboxApi} api {@link InboxApi `InboxApi`} 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: InboxApi, fileId: string, progressCallback?: (progress: number) => void): Promise; /** * Reads a file and returns a stream handler along with its metadata. * @param {InboxApi} api {@link InboxApi `InboxApi`} instance * @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 an 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: InboxApi, fileId: string): Promise; private getOn; /** * Subscribes to entry events on given Inbox: * - `inboxNewEntry` * - `inboxEntryDeleted` * @returns {Promise>} {@link SubscribeForChannel<'inboxEntries'> `Promise>`} */ subscribeForEntryEvents(): Promise>; /** * Unsubscribes from events related to entries on this Inbox * @returns {Promise} a promise that resolves with void */ unsubscribeFromEntryEvents(): Promise; /** * Registers an event listener for Inbox entry-related events. * * @template T * @param {T & EventsByChannel<'inboxEntries'>} eventType - type of event to listen for. * @param {function(Extract): void} callback - callback function to execute when the event occurs. * @returns {Promise<{on: SubscribeForChannel<'inboxEntries'>, 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<'inboxEntries'> & { removeEventListener: () => void; }; private static getOn; /** * Subscribes to events related to inboxes: * - `inboxCreated` * - `inboxDeleted` * - `inboxUpdated` * @param {InboxApi} api {@link InboxApi `InboxApi`} * @param {EventDispatcher} eventDispatcher {@link EventDispatcher eventDispatcher} * @returns {Promise>} {@link SubscribeForChannel<'inbox'> `Promise>`} */ static subscribeForInboxEvents(api: InboxApi, eventDispatcher: EventDispatcher): Promise>; /** * Unsubscribes from Inbox related events on this Inbox * @param {InboxApi} api {@link InboxApi `InboxApi`} * @param {EventDispatcher} eventDispatcher {@link EventDispatcher eventDispatcher} * @returns {Promise} a promise that resolves with void */ static unsubscribeFromInboxEvents(api: InboxApi, eventDispatcher: EventDispatcher): Promise; /** * Registers an event listener for Inbox-related events. * * @template T * @param {T & EventsByChannel<'inbox'>} eventType - type of event to listen for. * @param {function(Extract): void} callback - callback function to execute when the event occurs. * @returns {Promise<{on: SubscribeForChannel<'inbox'>, 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<'inbox'> & { removeEventListener: () => void; }; }