Skip to main content
reference

StoreClient

Constructors

constructor

constructor(storeId: string,endpoint: Endpoint,eventDispatcher: EventDispatcher)

NameTypeDescription
storeIdstring
endpointEndpoint
eventDispatcherEventDispatcher

Fields

storeId

get storeId(): string

Static Methods

createStore

Creates a new Store in Context

static async createStore(api: StoreApi, newStore: {
contextId: string;
managers: UserWithPubKey[];
privateMeta: Uint8Array;
publicMeta: Uint8Array;
users: UserWithPubKey[];
})

NameTypeDescription
apiStoreApiStoreApi `StoreApi` instance
newStore.contextIdstringContext ID in which the Store should be created
newStore.managersUserWithPubKey[]list of UserWithPubKey with manage rights to this Store
newStore.privateMetaUint8Arrayoptional (encrypted) metadata
newStore.publicMetaUint8Arrayoptional public (unencrypted) metadata
newStore.usersUserWithPubKey[]list of UserWithPubKey with access to this Store

TypeDescription
Promise<string> ID of the created Store

deleteFile

Deletes file from Store.

static async deleteFile(api: StoreApi, fileId: string)

NameTypeDescription
apiStoreApi
fileIdstringThe ID of the file to delete.

TypeDescription
Promise<void> A promise that resolves when the file is successfully deleted.

downloadFile

Downloads file from Store to your local environment

static async downloadFile(api: StoreApi, file: {
fileId: string;
name: string;
progressCallback: (progress: number)=>void;
})

NameTypeDescription
apiStoreApiStoreApi `StoreApi` instance
file.fileIdstringFile ID
file.namestringOptional name given to the file
file.progressCallback(progress: number)=>voidOptional callback function to report progress

TypeDescription
Promise<void> a promise that resolves with void and download the file to the browser environment

getFileContents

Get the content of given file

static async getFileContents(api: StoreApi, fileId: string, progressCallback: (progress: number)=>void)

NameTypeDescription
apiStoreApiStoreApi `StoreApi` instance
fileIdstringID of the file to get the content from
progressCallback(progress: number)=>voidoptional function to report progress

TypeDescription
Promise<Uint8Array> content of the file

getFileMetaData

Returns metadata about given file

static async getFileMetaData(api: StoreApi, fileId: string)

NameTypeDescription
apiStoreApi
fileIdstringThe ID of the file to get metadata from

TypeDescription
Promise<PrivmxFile> `Promise<PrivmxFile>

getStore

Gets Store metadata by given Store ID

static async getStore(api: StoreApi, storeId: string)

NameTypeDescription
apiStoreApi
storeIdstringID of given Store

TypeDescription
Promise<Store> -

getStores

List Stores the user has access to

static async getStores(api: StoreApi, contextId: string, pageIndex: number, options: ListOptions)

NameTypeDescription
apiStoreApiStoreApi `StoreApi` instance
contextIdstring
pageIndexnumberindicates from which page the list should start
optionsListOptionsoptional options object

TypeDescription
Promise<PagingList<Store>> -

on

Registers an event listener for Store-related events.

static on(eventDispatcher: EventDispatcher, eventType: T, callback: (payload: Extract<StoreCreatedEvent, {type: T;}> | Extract<StoreUpdatedEvent, {type: T;}> | Extract<StoreDeletedEvent, {type: T;}> | Extract<StoreStatsChangedEvent, {type: T;}>)=>void)

NameTypeDescription
eventDispatcherEventDispatcher
eventTypeTtype of event to listen for.
callback(payload: Extract<StoreCreatedEvent, {type: T;}> | Extract<StoreUpdatedEvent, {type: T;}> | Extract<StoreDeletedEvent, {type: T;}> | Extract<StoreStatsChangedEvent, {type: T;}>)=>voidcallback function to execute when the event occurs.

TypeDescription
SubscribeForChannel<"store"> & { removeEventListener: ()=>void; } object containing the

overrideFile

Override file contents

static async overrideFile(api: StoreApi, params: {
file: StoreFilePayload;
fileId: string;
progressCallback: (progress: number)=>void;
})

NameTypeDescription
apiStoreApiStoreApi `StoreApi` instance
params.fileStoreFilePayload`StoreFilePayload` object
params.fileIdstringfileId
params.progressCallback(progress: number)=>voidOptional callback function to report progress

TypeDescription
Promise<string> file ID

streamRead

Reads a file and returns a stream handler along with its metadata.

static async streamRead(api: StoreApi, fileId: string)

NameTypeDescription
apiStoreApi
fileIdstringThe ID of the file to be read.

TypeDescription
Promise<StreamReader> A promise that resolves with object containing the stream reader, file size, MIME type, and file name.

subscribeForStoreEvents

Subscribes to events related to Stores: - `storeCreated` - `storeDeleted` - `storeStatsChanged` - `storeUpdated`

static async subscribeForStoreEvents(api: StoreApi, eventDispatcher: EventDispatcher)

NameTypeDescription
apiStoreApiinstance of Store Api
eventDispatcherEventDispatchereventDispatcher

TypeDescription
Promise<SubscribeForChannel<"store">> <'store'> `Promise<SubscribeForChannel<'store'>>

unsubscribeFromStoreEvents

Unsubscribes from events related to stores

static async unsubscribeFromStoreEvents(api: StoreApi, eventDispatcher: EventDispatcher)

NameTypeDescription
apiStoreApiinstance of Store Api
eventDispatcherEventDispatchereventDispatcher

TypeDescription
Promise<void> a promise that resolves with void

updateFile

Update file contents

static async updateFile(api: StoreApi, params: {
data: Uint8Array;
fileId: string;
offset: number;
progressCallback: (progress: number)=>void;
})

NameTypeDescription
apiStoreApiStoreApi `StoreApi` instance
params.dataUint8Array
params.fileIdstringfileId
params.offsetnumberwhere to start appending data
params.progressCallback(progress: number)=>voidOptional callback function to report progress

TypeDescription
Promise<string> file ID

updateFileMeta

Updates file metadata

static async updateFileMeta(api: StoreApi, file: {
fileId: string;
privateMeta: Uint8Array;
publicMeta: Uint8Array;
})

NameTypeDescription
apiStoreApiStoreApi `StoreApi` instance
file.fileIdstringID of file to update
file.privateMetaUint8Arraymetadata that will be encrypted
file.publicMetaUint8Arraymetadata that will be unencrypted

TypeDescription
Promise<void> - a promise that resolves with void

Methods

deleteStore

Deletes current Store.

async deleteStore()

TypeDescription
Promise<void> A promise that resolves when the Store updates successfully deleted.

getFiles

Gets a list of files in the given Store.

async getFiles(pageIndex: number, options: ListOptions)

NameTypeDescription
pageIndexnumber
optionsListOptionsoptional options object

TypeDescription
Promise<PagingList<PrivmxFile>> `PagingList<File>

getInfo

Returns info about current Store

async getInfo()

TypeDescription
Promise<Store> -

on

Registers an event listener for store file-related events.

on(eventType: T, callback: (payload: Extract<StoreFileCreatedEvent, {type: T;}> | Extract<StoreFileUpdatedEvent, {type: T;}> | Extract<StoreFileDeletedEvent, {type: T;}>)=>void)

NameTypeDescription
eventTypeTtype of event to listen for.
callback(payload: Extract<StoreFileCreatedEvent, {type: T;}> | Extract<StoreFileUpdatedEvent, {type: T;}> | Extract<StoreFileDeletedEvent, {type: T;}>)=>voidcallback function to execute when the event occurs.

TypeDescription
SubscribeForChannel<"storeFiles"> & { removeEventListener: ()=>void; } object containing the

storeUpdate

Updates metadata about the given Store.

async storeUpdate(newStore: {
managers: UserWithPubKey[];
options: {
force: boolean;
forceGenerateNewKey: boolean;
};
privateMeta: Uint8Array;
publicMeta: Uint8Array;
users: UserWithPubKey[];
version: number;
})

NameTypeDescription
newStore.managersUserWithPubKey[]list of UserWithPubKey with manage rights to this Store
newStore.options{ force: boolean; forceGenerateNewKey: boolean; }
newStore.privateMetaUint8Array(encrypted) metadata
newStore.publicMetaUint8Arraypublic (unencrypted) metadata
newStore.usersUserWithPubKey[]list of UserWithPubKey with access to this Store
newStore.versionnumberThe version number of the Store data.

TypeDescription
Promise<void> A promise that resolves when the Store update is complete.

streamData

Streams a file to a Store.

async streamData(newFile: StoreFilePayload)

NameTypeDescription
newFileStoreFilePayloadThe file to be streamed.

TypeDescription
Promise<StreamUploader> - A promise that resolves to a StreamUploader instance if successful, or void if an error occurs.

streamFile

Allows you to handle streaming a file from web File Handler

async streamFile(newFile: {
file: File;
privateMeta: Uint8Array;
publicMeta: Uint8Array;
})

NameTypeDescription
newFile.fileFile
newFile.privateMetaUint8Arraycontains confidential data that will be encrypted before sent to server
newFile.publicMetaUint8Arraycontains data that can be accessed by everyone and is not encrypted.

TypeDescription
Promise<FileUploader> instance of a FileUploader

subscribeForFileEvents

Subscribes to file-related events in given Store: - `storeFileCreated` - `storeFileDeleted` - `storeFileUpdated`

async subscribeForFileEvents()

TypeDescription
Promise<SubscribeForChannel<"storeFiles">> <'storeFiles'> `Promise<SubscribeForChannel<'storeFiles'>>

unsubscribeFromFileEvents

Unsubscribes from file-related events in this Store

async unsubscribeFromFileEvents()

TypeDescription
Promise<void> a promise that resolves with void

uploadData

Upload custom data to a Store

async uploadData(newData: StoreFilePayload, progressCallback: (progress: number)=>void)

NameTypeDescription
newDataStoreFilePayload`StoreFilePayload`
progressCallback(progress: number)=>voidOptional callback function to report progress

TypeDescription
Promise<string> file ID

uploadFile

Function to upload a file from a browser File `File` handle

async uploadFile(newFile: {
file: File;
privateMeta: Uint8Array;
publicMeta: Uint8Array;
}, progressCallback: (progress: number)=>void)

NameTypeDescription
newFile.fileFilefile to upload
newFile.privateMetaUint8Arrayoptional (encrypted) metadata
newFile.publicMetaUint8Arrayoptional public (unencrypted) metadata
progressCallback(progress: number)=>voidoptional function to report progress

TypeDescription
Promise<string> return the ID of the uploaded file