UNPKG

@simplito/privmx-webendpoint

Version:

PrivMX Web Endpoint library

247 lines (244 loc) 8.7 kB
"use strict"; /*! 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. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.StoreApi = void 0; const BaseApi_1 = require("./BaseApi"); class StoreApi extends BaseApi_1.BaseApi { native; constructor(native, ptr) { super(ptr); this.native = native; } /** * Creates a new Store in given Context. * * @param {string} contextId ID of the Context to create the Store in * @param {UserWithPubKey[]} users array of UserWithPubKey structs which indicates who will have access to the created Store * @param {UserWithPubKey[]} managers array of UserWithPubKey structs which indicates who will have access (and management rights) to the * created Store * @param {Uint8Array} publicMeta public (unencrypted) metadata * @param {Uint8Array} privateMeta private (encrypted) metadata * @param {ContainerPolicy} policies Store's policies * @returns {string} created Store ID */ async createStore(contextId, users, managers, publicMeta, privateMeta, policies) { return this.native.createStore(this.servicePtr, [ contextId, users, managers, publicMeta, privateMeta, policies ]); } /** * Updates an existing Store. * * @param {string} storeId ID of the Store to update * @param {UserWithPubKey[]} users array of UserWithPubKey structs which indicates who will have access to the created Store * @param {UserWithPubKey[]} managers array of UserWithPubKey structs which indicates who will have access (and management rights) to the * created Store * @param {Uint8Array} publicMeta public (unencrypted) metadata * @param {Uint8Array} privateMeta private (encrypted) metadata * @param {number} version current version of the updated Store * @param {boolean} force force update (without checking version) * @param {boolean} forceGenerateNewKey force to regenerate a key for the Store * @param {ContainerPolicy} policies Store's policies */ async updateStore(storeId, users, managers, publicMeta, privateMeta, version, force, forceGenerateNewKey, policies) { return this.native.updateStore(this.servicePtr, [ storeId, users, managers, publicMeta, privateMeta, version, force, forceGenerateNewKey, policies ]); } /** * Deletes a Store by given Store ID. * * @param {string} storeId ID of the Store to delete */ async deleteStore(storeId) { return this.native.deleteStore(this.servicePtr, [storeId]); } /** * Gets a single Store by given Store ID. * * @param {string} storeId ID of the Store to get * @returns {Store} struct containing information about the Store */ async getStore(storeId) { return this.native.getStore(this.servicePtr, [storeId]); } /** * Gets a list of Stores in given Context. * * @param {string} contextId ID of the Context to get the Stores from * @param {PagingQuery} pagingQuery struct with list query parameters * @returns {PagingList<Store>} struct containing list of Stores */ async listStores(contextId, pagingQuery) { return this.native.listStores(this.servicePtr, [contextId, pagingQuery]); } /** * Creates a new file in a Store. * * @param {string} storeId ID of the Store to create the file in * @param {Uint8Array} publicMeta public file metadata * @param {Uint8Array} privateMeta private file metadata * @param {number} size size of the file * @returns {number} handle to write data */ async createFile(storeId, publicMeta, privateMeta, size) { return this.native.createFile(this.servicePtr, [ storeId, publicMeta, privateMeta, size, ]); } /** * Update an existing file in a Store. * * @param {string} fileId ID of the file to update * @param {Uint8Array} publicMeta public file metadata * @param {Uint8Array} privateMeta private file metadata * @param {number} size size of the file * @returns {number} handle to write file data */ async updateFile(fileId, publicMeta, privateMeta, size) { return this.native.updateFile(this.servicePtr, [ fileId, publicMeta, privateMeta, size, ]); } /** * Update metadata of an existing file in a Store. * * @param {string} fileId ID of the file to update * @param {Uint8Array} publicMeta public file metadata * @param {Uint8Array} privateMeta private file metadata */ async updateFileMeta(fileId, publicMeta, privateMeta) { return this.native.updateFileMeta(this.servicePtr, [ fileId, publicMeta, privateMeta, ]); } /** * Writes a file data. * * @param {number} fileHandle handle to write file data * @param {Uint8Array} dataChunk file data chunk */ async writeToFile(fileHandle, dataChunk) { return this.native.writeToFile(this.servicePtr, [fileHandle, dataChunk]); } /** * Deletes a file by given ID. * * @param {string} fileId ID of the file to delete */ async deleteFile(fileId) { return this.native.deleteFile(this.servicePtr, [fileId]); } /** * Gets a single file by the given file ID. * * @param {string} fileId ID of the file to get * @returns {File} struct containing information about the file */ async getFile(fileId) { return this.native.getFile(this.servicePtr, [fileId]); } /** * Gets a list of files in given Store. * * @param {string} storeId ID of the Store to get files from * @param {PagingQuery} pagingQuery struct with list query parameters * @returns {PagingList<File>} struct containing list of files */ async listFiles(storeId, pagingQuery) { return this.native.listFiles(this.servicePtr, [storeId, pagingQuery]); } /** * Opens a file to read. * * @param {string} fileId ID of the file to read * @returns {number} handle to read file data */ async openFile(fileId) { return this.native.openFile(this.servicePtr, [fileId]); } /** * 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 {string} fileHandle handle to write file data * @param {number} length size of data to read * @returns {Uint8Array} array buffer with file data chunk */ async readFromFile(fileHandle, length) { return this.native.readFromFile(this.servicePtr, [fileHandle, length]); } /** * Moves read cursor. * * @param {string} fileHandle handle to write file data * @param {number} position new cursor position */ async seekInFile(fileHandle, position) { return this.native.seekInFile(this.servicePtr, [fileHandle, position]); } /** * Closes the file handle. * * @param {string} fileHandle handle to read/write file data * @returns {string} ID of closed file */ async closeFile(fileHandle) { return this.native.closeFile(this.servicePtr, [fileHandle]); } /** * Subscribes for the Store module main events. */ async subscribeForStoreEvents() { return this.native.subscribeForStoreEvents(this.servicePtr, []); } /** * Unsubscribes from the Store module main events. */ async unsubscribeFromStoreEvents() { return this.native.unsubscribeFromStoreEvents(this.servicePtr, []); } /** * Subscribes for events in given Store. * @param {string} storeId ID of the Store to subscribe */ async subscribeForFileEvents(storeId) { return this.native.subscribeForFileEvents(this.servicePtr, [storeId]); } /** * Unsubscribes from events in given Store. * @param {string} storeId ID of the Store to unsubscribe */ async unsubscribeFromFileEvents(storeId) { return this.native.unsubscribeFromFileEvents(this.servicePtr, [storeId]); } } exports.StoreApi = StoreApi;