@simplito/privmx-webendpoint
Version:
PrivMX Web Endpoint library
185 lines (182 loc) • 8.68 kB
TypeScript
/*!
PrivMX Web Endpoint.
Copyright © 2024 Simplito sp. z o.o.
This file is part of the PrivMX Platform (https://privmx.dev).
This software is Licensed under the PrivMX Free License.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { BaseApi } from "./BaseApi";
import { InboxApiNative } from "../api/InboxApiNative";
import { PagingQuery, PagingList, UserWithPubKey, Inbox, InboxPublicView, InboxEntry, FilesConfig, ContainerWithoutItemPolicy, InboxEventType, InboxEventSelectorType } from "../Types";
export declare class InboxApi extends BaseApi {
private native;
constructor(native: InboxApiNative, ptr: number);
/**
* Creates a new Inbox.
*
* @param {string} contextId ID of the Context of the new Inbox
* @param {UserWithPubKey[]} users vector of UserWithPubKey structs which indicates who will have access to the created Inbox
* @param {UserWithPubKey[]} managers vector of UserWithPubKey structs which indicates who will have access (and management rights) to
* the created Inbox
* @param {Uint8Array} publicMeta public (unencrypted) metadata
* @param {Uint8Array} privateMeta private (encrypted) metadata
* @param {FilesConfig} filesConfig to override default file configuration
* @param {ContainerWithoutItemPolicy} policies Inbox policies
* @returns {string} ID of the created Inbox
*/
createInbox(contextId: string, users: UserWithPubKey[], managers: UserWithPubKey[], publicMeta: Uint8Array, privateMeta: Uint8Array, filesConfig?: FilesConfig, policies?: ContainerWithoutItemPolicy): Promise<string>;
/**
* Updates an existing Inbox.
*
* @param {string} inboxId ID of the Inbox to update
* @param {UserWithPubKey[]} users vector of UserWithPubKey structs which indicates who will have access to the created Inbox
* @param {UserWithPubKey[]} managers vector of UserWithPubKey structs which indicates who will have access (and management rights) to
* the created Inbox
* @param {Uint8Array} publicMeta public (unencrypted) metadata
* @param {Uint8Array} privateMeta private (encrypted) metadata
* @param {FilesConfig} filesConfig to override default files configuration
* @param {number} version current version of the updated Inbox
* @param {boolean} force force update (without checking version)
* @param {boolean} forceGenerateNewKey force to regenerate a key for the Inbox
* @param {ContainerWithoutItemPolicy} policies Inbox policies
*/
updateInbox(inboxId: string, users: UserWithPubKey[], managers: UserWithPubKey[], publicMeta: Uint8Array, privateMeta: Uint8Array, filesConfig: FilesConfig | undefined, version: number, force: boolean, forceGenerateNewKey: boolean, policies?: ContainerWithoutItemPolicy): Promise<void>;
/**
* Gets a single Inbox by given Inbox ID.
*
* @param {string} inboxId ID of the Inbox to get
* @returns {Inbox} containing information about the Inbox
*/
getInbox(inboxId: string): Promise<Inbox>;
/**
* Gets s list of Inboxes in given Context.
*
* @param {string} contextId ID of the Context to get Inboxes from
* @param {PagingQuery} pagingQuery with list query parameters
* @returns {PagingList<Inbox>} containing list of Inboxes
*/
listInboxes(contextId: string, pagingQuery: PagingQuery): Promise<PagingList<Inbox>>;
/**
* Gets public data of given Inbox.
* You do not have to be logged in to call this function.
*
* @param {string} inboxId ID of the Inbox to get
* @returns {InboxPublicView} containing public accessible information about the Inbox
*/
getInboxPublicView(inboxId: string): Promise<InboxPublicView>;
/**
* Deletes an Inbox by given Inbox ID.
*
* @param {string} inboxId ID of the Inbox to delete
*/
deleteInbox(inboxId: string): Promise<void>;
/**
* Prepares a request to send data to an Inbox.
* You do not have to be logged in to call this function.
*
* @param {string} inboxId ID of the Inbox to which the request applies
* @param {Uint8Array} data entry data to send
* @param {number[]} [inboxFileHandles] optional list of file handles that will be sent with the request
* @param {string} [userPrivKey] optional sender's private key which can be used later to encrypt data for that sender
* @returns {number} Inbox handle
*/
prepareEntry(inboxId: string, data: Uint8Array, inboxFileHandles: number[], userPrivKey?: string | undefined): Promise<number>;
/**
* Sends data to an Inbox.
* You do not have to be logged in to call this function.
*
* @param {string} inboxHandle ID of the Inbox to which the request applies
*/
sendEntry(inboxHandle: number): Promise<void>;
/**
* Gets an entry from an Inbox.
*
* @param {string} inboxEntryId ID of an entry to read from the Inbox
* @returns {InboxEntry} containing data of the selected entry stored in the Inbox
*/
readEntry(inboxEntryId: string): Promise<InboxEntry>;
/**
* Gets list of entries in given Inbox.
*
* @param {string} inboxId ID of the Inbox
* @param {PagingQuery} pagingQuery with list query parameters
* @returns {PagingList<InboxEntry>} containing list of entries
*/
listEntries(inboxId: string, pagingQuery: PagingQuery): Promise<PagingList<InboxEntry>>;
/**
* Delete an entry from an Inbox.
*
* @param {string} inboxEntryId ID of an entry to delete from the Inbox
*/
deleteEntry(inboxEntryId: string): Promise<void>;
/**
* Creates a file handle to send a file to an Inbox.
* You do not have to be logged in to call this function.
*
* @param {Uint8Array} publicMeta public file metadata
* @param {Uint8Array} privateMeta private file metadata
* @param {number} fileSize size of the file to send
* @returns {number} file handle
*/
createFileHandle(publicMeta: Uint8Array, privateMeta: Uint8Array, fileSize: number): Promise<number>;
/**
* Sends a file's data chunk to an Inbox.
* (note: To send the entire file - divide it into pieces of the desired size and call the function for each fragment.)
* You do not have to be logged in to call this function.
*
* @param {number} inboxHandle Handle to the prepared Inbox entry
* @param {number} inboxFileHandle handle to the file where the uploaded chunk belongs
* @param {Uint8Array} dataChunk - file chunk to send
*/
writeToFile(inboxHandle: number, inboxFileHandle: number, dataChunk: Uint8Array): Promise<void>;
/**
* Opens a file to read.
*
* @param {string} fileId ID of the file to read
* @returns {number} handle to read file data
*/
openFile(fileId: string): Promise<number>;
/**
* Reads file data.
* Single read call moves the files's cursor position by declared length or set it at the end of the file.
*
* @param {number} fileHandle handle to the file
* @param {number} length size of data to read
* @returns {Uint8Array} buffer with file data chunk
*/
readFromFile(fileHandle: number, length: number): Promise<Uint8Array>;
/**
* Moves file's read cursor.
*
* @param {number} fileHandle handle to the file
* @param {number} position sets new cursor position
*/
seekInFile(fileHandle: number, position: number): Promise<void>;
/**
* Closes a file by given handle.
*
* @param {number} fileHandle handle to the file
* @returns {string} ID of closed file
*/
closeFile(fileHandle: number): Promise<string>;
/**
* Subscribe for the Inbox events on the given subscription query.
*
* @param {string[]} subscriptionQueries list of queries
* @return list of subscriptionIds in maching order to subscriptionQueries
*/
subscribeFor(subscriptionQueries: string[]): Promise<string[]>;
/**
* Unsubscribe from events for the given subscriptionId.
* @param {string[]} subscriptionIds list of subscriptionId
*/
unsubscribeFrom(subscriptionIds: string[]): Promise<void>;
/**
* Generate subscription Query for the Inbox events.
* @param {EventType} eventType type of event which you listen for
* @param {EventSelectorType} selectorType scope on which you listen for events
* @param {string} selectorId ID of the selector
*/
buildSubscriptionQuery(eventType: InboxEventType, selectorType: InboxEventSelectorType, selectorId: string): Promise<string>;
}