StoreClient
Constructors
constructor
constructor(storeId: string,endpoint: Endpoint,eventDispatcher: EventDispatcher)
Name | Type | Description |
---|---|---|
storeId | string | |
endpoint | Endpoint | |
eventDispatcher | EventDispatcher |
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[];
})
Name | Type | Description |
---|---|---|
api | StoreApi | StoreApi `StoreApi` instance |
newStore.contextId | string | Context ID in which the Store should be created |
newStore.managers | UserWithPubKey[] | list of UserWithPubKey with manage rights to this Store |
newStore.privateMeta | Uint8Array | optional (encrypted) metadata |
newStore.publicMeta | Uint8Array | optional public (unencrypted) metadata |
newStore.users | UserWithPubKey[] | list of UserWithPubKey with access to this Store |
Type | Description |
---|---|
Promise<string> | ID of the created Store |
deleteFile
Deletes file from Store.
static async deleteFile(api: StoreApi, fileId: string)
Name | Type | Description |
---|---|---|
api | StoreApi | |
fileId | string | The ID of the file to delete. |
Type | Description |
---|---|
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;
})
Name | Type | Description |
---|---|---|
api | StoreApi | StoreApi `StoreApi` instance |
file.fileId | string | File ID |
file.name | string | Optional name given 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 |
getFileContents
Get the content of given file
static async getFileContents(api: StoreApi, fileId: string, progressCallback: (progress: number)=>void)
Name | Type | Description |
---|---|---|
api | StoreApi | StoreApi `StoreApi` 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 |
getFileMetaData
Returns metadata about given file
static async getFileMetaData(api: StoreApi, fileId: string)
Name | Type | Description |
---|---|---|
api | StoreApi | |
fileId | string | The ID of the file to get metadata from |
Type | Description |
---|---|
Promise<PrivmxFile> | `Promise<PrivmxFile> |
getStore
Gets Store metadata by given Store ID
static async getStore(api: StoreApi, storeId: string)
Name | Type | Description |
---|---|---|
api | StoreApi | |
storeId | string | ID of given Store |
Type | Description |
---|---|
Promise<Store> | - |
getStores
List Stores the user has access to
static async getStores(api: StoreApi, contextId: string, pageIndex: number, options: ListOptions)
Name | Type | Description |
---|---|---|
api | StoreApi | StoreApi `StoreApi` instance |
contextId | string | |
pageIndex | number | indicates from which page the list should start |
options | ListOptions | optional options object |
Type | Description |
---|---|
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)
Name | Type | Description |
---|---|---|
eventDispatcher | EventDispatcher | |
eventType | T | type of event to listen for. |
callback | (payload: Extract<StoreCreatedEvent, {type: T;}> | Extract<StoreUpdatedEvent, {type: T;}> | Extract<StoreDeletedEvent, {type: T;}> | Extract<StoreStatsChangedEvent, {type: T;}>)=>void | callback function to execute when the event occurs. |
Type | Description |
---|---|
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;
})
Name | Type | Description |
---|---|---|
api | StoreApi | StoreApi `StoreApi` instance |
params.file | StoreFilePayload | `StoreFilePayload` object |
params.fileId | string | fileId |
params.progressCallback | (progress: number)=>void | Optional callback function to report progress |
Type | Description |
---|---|
Promise<string> | file ID |
streamRead
Reads a file and returns a stream handler along with its metadata.
static async streamRead(api: StoreApi, fileId: string)
Name | Type | Description |
---|---|---|
api | StoreApi | |
fileId | string | The ID of the file to be read. |
Type | Description |
---|---|
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)
Name | Type | Description |
---|---|---|
api | StoreApi | instance of Store Api |
eventDispatcher | EventDispatcher | eventDispatcher |
Type | Description |
---|---|
Promise<SubscribeForChannel<"store">> | <'store'> `Promise<SubscribeForChannel<'store'>> |
unsubscribeFromStoreEvents
Unsubscribes from events related to stores
static async unsubscribeFromStoreEvents(api: StoreApi, eventDispatcher: EventDispatcher)
Name | Type | Description |
---|---|---|
api | StoreApi | instance of Store Api |
eventDispatcher | EventDispatcher | eventDispatcher |
Type | Description |
---|---|
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;
})
Name | Type | Description |
---|---|---|
api | StoreApi | StoreApi `StoreApi` instance |
params.data | Uint8Array | |
params.fileId | string | fileId |
params.offset | number | where to start appending data |
params.progressCallback | (progress: number)=>void | Optional callback function to report progress |
Type | Description |
---|---|
Promise<string> | file ID |
updateFileMeta
Updates file metadata
static async updateFileMeta(api: StoreApi, file: {
fileId: string;
privateMeta: Uint8Array;
publicMeta: Uint8Array;
})
Name | Type | Description |
---|---|---|
api | StoreApi | StoreApi `StoreApi` instance |
file.fileId | string | ID of file to update |
file.privateMeta | Uint8Array | metadata that will be encrypted |
file.publicMeta | Uint8Array | metadata that will be unencrypted |
Type | Description |
---|---|
Promise<void> | - a promise that resolves with void |
Methods
deleteStore
Deletes current Store.
async deleteStore()
Type | Description |
---|---|
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)
Name | Type | Description |
---|---|---|
pageIndex | number | |
options | ListOptions | optional options object |
Type | Description |
---|---|
Promise<PagingList<PrivmxFile>> | `PagingList<File> |
getInfo
Returns info about current Store
async getInfo()
Type | Description |
---|---|
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)
Name | Type | Description |
---|---|---|
eventType | T | type of event to listen for. |
callback | (payload: Extract<StoreFileCreatedEvent, {type: T;}> | Extract<StoreFileUpdatedEvent, {type: T;}> | Extract<StoreFileDeletedEvent, {type: T;}>)=>void | callback function to execute when the event occurs. |
Type | Description |
---|---|
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;
})
Name | Type | Description |
---|---|---|
newStore.managers | UserWithPubKey[] | list of UserWithPubKey with manage rights to this Store |
newStore.options | {
force: boolean;
forceGenerateNewKey: boolean;
} | |
newStore.privateMeta | Uint8Array | (encrypted) metadata |
newStore.publicMeta | Uint8Array | public (unencrypted) metadata |
newStore.users | UserWithPubKey[] | list of UserWithPubKey with access to this Store |
newStore.version | number | The version number of the Store data. |
Type | Description |
---|---|
Promise<void> | A promise that resolves when the Store update is complete. |
streamData
Streams a file to a Store.
async streamData(newFile: StoreFilePayload)
Name | Type | Description |
---|---|---|
newFile | StoreFilePayload | The file to be streamed. |
Type | Description |
---|---|
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;
})
Name | Type | Description |
---|---|---|
newFile.file | File | |
newFile.privateMeta | Uint8Array | contains confidential data that will be encrypted before sent to server |
newFile.publicMeta | Uint8Array | contains data that can be accessed by everyone and is not encrypted. |
Type | Description |
---|---|
Promise<FileUploader> | instance of a FileUploader |
subscribeForFileEvents
Subscribes to file-related events in given Store: - `storeFileCreated` - `storeFileDeleted` - `storeFileUpdated`
async subscribeForFileEvents()
Type | Description |
---|---|
Promise<SubscribeForChannel<"storeFiles">> | <'storeFiles'> `Promise<SubscribeForChannel<'storeFiles'>> |
unsubscribeFromFileEvents
Unsubscribes from file-related events in this Store
async unsubscribeFromFileEvents()
Type | Description |
---|---|
Promise<void> | a promise that resolves with void |
uploadData
Upload custom data to a Store
async uploadData(newData: StoreFilePayload, progressCallback: (progress: number)=>void)
Name | Type | Description |
---|---|---|
newData | StoreFilePayload | `StoreFilePayload` |
progressCallback | (progress: number)=>void | Optional callback function to report progress |
Type | Description |
---|---|
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)
Name | Type | Description |
---|---|---|
newFile.file | File | file to upload |
newFile.privateMeta | Uint8Array | optional (encrypted) metadata |
newFile.publicMeta | Uint8Array | optional public (unencrypted) metadata |
progressCallback | (progress: number)=>void | optional function to report progress |
Type | Description |
---|---|
Promise<string> | return the ID of the uploaded file |