InboxClient
Wrapper class for the InboxApi.
Constructors
constructor
constructor(inboxId: string,endpoint: Endpoint,eventDispatcher: EventDispatcher)
Name | Type | Description |
---|---|---|
inboxId | string | |
endpoint | Endpoint | |
eventDispatcher | EventDispatcher |
Fields
inboxId
get inboxId(): string
Static Methods
createInbox
Creates a new Inbox
static async createInbox(api: InboxApi, newInbox: {
contextId: string;
filesConfig: FilesConfig;
managers: UserWithPubKey[];
privateMeta: Uint8Array;
publicMeta: Uint8Array;
users: UserWithPubKey[];
})
Name | Type | Description |
---|---|---|
api | InboxApi | InboxApi `InboxApi` |
newInbox.contextId | string | ID of the Context for the new Inbox |
newInbox.filesConfig | FilesConfig | object to override default file configuration |
newInbox.managers | UserWithPubKey[] | list of `UserWithPubKey` objects which indicates who will have access (and management rights) to the created Inbox |
newInbox.privateMeta | Uint8Array | (encrypted) private Inbox metadata |
newInbox.publicMeta | Uint8Array | (unencrypted) public Inbox metadata |
newInbox.users | UserWithPubKey[] | list of `UserWithPubKey` objects which indicates who will have access to the created Inbox |
Type | Description |
---|---|
Promise<string> | Created Inbox ID |
deleteEntry
Deletes an entry from Inbox
static async deleteEntry(api: InboxApi, entryId: string)
Name | Type | Description |
---|---|---|
api | InboxApi | InboxApi `InboxApi` |
entryId | string | ID of entry to delete |
Type | Description |
---|---|
Promise<void> |
downloadFile
Downloads file from Inbox to your local environment
static async downloadFile(api: InboxApi, storeApi: StoreApi, file: {
fileId: string;
fileName: string;
progressCallback: (progress: number)=>void;
})
Name | Type | Description |
---|---|---|
api | InboxApi | InboxApi `InboxApi` |
storeApi | StoreApi | StoreApi `StoreApi` |
file.fileId | string | File ID |
file.fileName | string | optional name that will be assigned to the file |
file.progressCallback | (progress: number)=>void | Optional callback function to report progress |
Type | Description |
---|---|
Promise<void> | a promise that resolves with void and download the file to the browser environment |
getEntry
Gets an Inbox entry based on its ID
static async getEntry(api: InboxApi, entryId: string)
Name | Type | Description |
---|---|---|
api | InboxApi | InboxApi `InboxApi` |
entryId | string | Id of the entry |
Type | Description |
---|---|
Promise<InboxEntry> | `Promise<InboxEntry> |
getFileContents
Get the content of given file
static async getFileContents(api: InboxApi, fileId: string, progressCallback: (progress: number)=>void)
Name | Type | Description |
---|---|---|
api | InboxApi | InboxApi `InboxApi` instance |
fileId | string | ID of the file to get the content from |
progressCallback | (progress: number)=>void | optional function to report progress |
Type | Description |
---|---|
Promise<Uint8Array> | content of the file |
getInboxes
Gets a list of Inboxes in the given Context.
static async getInboxes(api: InboxApi, contextId: string, pageIndex: number, options: ListOptions)
Name | Type | Description |
---|---|---|
api | InboxApi | InboxApi `InboxApi` |
contextId | string | ID of the Context to get Inboxes from |
pageIndex | number | indicates from which page the list should start |
options | ListOptions | optional options object |
Type | Description |
---|---|
Promise<PagingList<Inbox>> | - |
on
Registers an event listener for Inbox-related events.
static on(eventDispatcher: EventDispatcher, eventType: T, callback: (payload: Extract<InboxCreatedEvent, {type: T;}> | Extract<InboxUpdatedEvent, {type: T;}> | Extract<InboxDeletedEvent, {type: T;}>)=>void)
Name | Type | Description |
---|---|---|
eventDispatcher | EventDispatcher | |
eventType | T | type of event to listen for. |
callback | (payload: Extract<InboxCreatedEvent, {type: T;}> | Extract<InboxUpdatedEvent, {type: T;}> | Extract<InboxDeletedEvent, {type: T;}>)=>void | callback function to execute when the event occurs. |
Type | Description |
---|---|
SubscribeForChannel<"inbox"> & {
removeEventListener: ()=>void;
} | object containing the |
streamRead
Reads a file and returns a stream handler along with its metadata.
static async streamRead(api: InboxApi, fileId: string)
Name | Type | Description |
---|---|---|
api | InboxApi | InboxApi `InboxApi` instance |
fileId | string | The ID of the file to be read. |
Type | Description |
---|---|
Promise<StreamReader> | A promise that resolves with an object containing the stream reader, file size, MIME type, and file name. |
subscribeForInboxEvents
Subscribes to events related to inboxes: - `inboxCreated` - `inboxDeleted` - `inboxUpdated`
static async subscribeForInboxEvents(api: InboxApi, eventDispatcher: EventDispatcher)
Name | Type | Description |
---|---|---|
api | InboxApi | InboxApi `InboxApi` |
eventDispatcher | EventDispatcher | eventDispatcher |
Type | Description |
---|---|
Promise<SubscribeForChannel<"inbox">> | <'inbox'> `Promise<SubscribeForChannel<'inbox'>> |
unsubscribeFromInboxEvents
Unsubscribes from Inbox related events on this Inbox
static async unsubscribeFromInboxEvents(api: InboxApi, eventDispatcher: EventDispatcher)
Name | Type | Description |
---|---|---|
api | InboxApi | InboxApi `InboxApi` |
eventDispatcher | EventDispatcher | eventDispatcher |
Type | Description |
---|---|
Promise<void> | a promise that resolves with void |
Methods
deleteInbox
Deletes current Inbox
async deleteInbox()
Type | Description |
---|---|
Promise<void> | a promise that resolves with void |
getInboxInfo
Fetches info about current Inbox
async getInboxInfo()
Type | Description |
---|---|
Promise<Inbox> | `Inbox` |
getPublicView
Fetches inbox public meta.
async getPublicView()
Type | Description |
---|---|
Promise<InboxPublicView> |
listEntries
Gets a list of entries from current Inbox.
async listEntries(pageIndex: number, options: ListOptions)
Name | Type | Description |
---|---|---|
pageIndex | number | |
options | ListOptions | optional `options` object |
Type | Description |
---|---|
Promise<PagingList<InboxEntry>> | `PagingList<InboxEntry> |
on
Registers an event listener for Inbox entry-related events.
on(eventType: T, callback: (payload: Extract<InboxEntryCreatedEvent, {type: T;}> | Extract<InboxEntryDeletedEvent, {type: T;}>)=>void)
Name | Type | Description |
---|---|---|
eventType | T | type of event to listen for. |
callback | (payload: Extract<InboxEntryCreatedEvent, {type: T;}> | Extract<InboxEntryDeletedEvent, {type: T;}>)=>void | callback function to execute when the event occurs. |
Type | Description |
---|---|
SubscribeForChannel<"inboxEntries"> & {
removeEventListener: ()=>void;
} | object containing the |
sendData
Sends data and optional files to an Inbox.
async sendData(entry: InboxEntryPayload)
Name | Type | Description |
---|---|---|
entry | InboxEntryPayload | `InboxEntryPayload` object |
Type | Description |
---|---|
Promise<void> | A promise that resolves when the data and files have been successfully sent to the Inbox. |
subscribeForEntryEvents
Subscribes to entry events on given Inbox: - `inboxNewEntry` - `inboxEntryDeleted`
async subscribeForEntryEvents()
Type | Description |
---|---|
Promise<SubscribeForChannel<"inboxEntries">> | <'inboxEntries'> `Promise<SubscribeForChannel<'inboxEntries'>> |
unsubscribeFromEntryEvents
Unsubscribes from events related to entries on this Inbox
async unsubscribeFromEntryEvents()
Type | Description |
---|---|
Promise<void> | a promise that resolves with void |
updateInbox
Updates an existing Inbox.
async updateInbox(updatedData: {
filesConfig: FilesConfig;
managers: UserWithPubKey[];
options: {
force: boolean;
forceGenerateNewKey: boolean;
};
privateMeta: Uint8Array;
publicMeta: Uint8Array;
users: UserWithPubKey[];
version: number;
})
Name | Type | Description |
---|---|---|
updatedData.filesConfig | FilesConfig | object to override default file configuration. Provide undefined if you want to leave the default configuration. |
updatedData.managers | UserWithPubKey[] | list of `UserWithPubKey` objects which indicates who will have access (and management rights) to the updated Inbox |
updatedData.options | {
force: boolean;
forceGenerateNewKey: boolean;
} | |
updatedData.privateMeta | Uint8Array | (encrypted) private Inbox metadata |
updatedData.publicMeta | Uint8Array | (unencrypted) public Inbox metadata |
updatedData.users | UserWithPubKey[] | list of `UserWithPubKey` objects which indicates who will have access to the updated Inbox |
updatedData.version | number | current version of the updated Inbox |
Type | Description |
---|---|
Promise<void> |