UNPKG

@simplito/privmx-webendpoint

Version:

PrivMX Web Endpoint library

187 lines (184 loc) 6.8 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.ThreadApi = void 0; const BaseApi_1 = require("./BaseApi"); class ThreadApi extends BaseApi_1.BaseApi { native; constructor(native, ptr) { super(ptr); this.native = native; } /** * Creates a new Thread in given Context. * * @param {string} contextId ID of the Context to create the Thread in * @param {UserWithPubKey[]} users array of UserWithPubKey structs which indicates who will have access to the created Thread * @param {UserWithPubKey[]} managers array of UserWithPubKey structs which indicates who will have access (and management rights) to * the created Thread * @param {Uint8Array} publicMeta public (unencrypted) metadata * @param {Uint8Array} privateMeta private (encrypted) metadata * @param {ContainerPolicy} policies Thread's policies * @returns {string} ID of the created Thread */ async createThread(contextId, users, managers, publicMeta, privateMeta, policies) { return this.native.createThread(this.servicePtr, [ contextId, users, managers, publicMeta, privateMeta, policies, ]); } /** * Updates an existing Thread. * * @param {string} threadId ID of the Thread to update * @param {UserWithPubKey[]} users array of UserWithPubKey structs which indicates who will have access to the created Thread * @param {UserWithPubKey[]} managers array of UserWithPubKey structs which indicates who will have access (and management rights) to * the created Thread * @param {Uint8Array} publicMeta public (unencrypted) metadata * @param {Uint8Array} privateMeta private (encrypted) metadata * @param {number} version current version of the updated Thread * @param {boolean} force force update (without checking version) * @param {boolean} forceGenerateNewKey force to regenerate a key for the Thread * @param {ContainerPolicy} policies Thread's policies */ async updateThread(threadId, users, managers, publicMeta, privateMeta, version, force, forceGenerateNewKey, policies) { return this.native.updateThread(this.servicePtr, [ threadId, users, managers, publicMeta, privateMeta, version, force, forceGenerateNewKey, policies, ]); } /** * Deletes a Thread by given Thread ID. * * @param {string} threadId ID of the Thread to delete */ async deleteThread(threadId) { return this.native.deleteThread(this.servicePtr, [threadId]); } /** * Gets a Thread by given Thread ID. * * @param {string} threadId ID of Thread to get * @returns {Thread} struct containing info about the Thread */ async getThread(threadId) { return this.native.getThread(this.servicePtr, [threadId]); } /** * Gets a list of Threads in given Context. * * @param {string} contextId ID of the Context to get the Threads from * @param {PagingQuery} pagingQuery struct with list query parameters * @returns {PagingList<Thread>} struct containing a list of Threads */ async listThreads(contextId, pagingQuery) { return this.native.listThreads(this.servicePtr, [contextId, pagingQuery]); } /** * Gets a message by given message ID. * * @param {string} messageId ID of the message to get * @returns {Message} struct containing the message */ async getMessage(messageId) { return this.native.getMessage(this.servicePtr, [messageId]); } /** * Gets a list of messages from a Thread. * * @param {string} threadId ID of the Thread to list messages from * @param {PagingQuery} pagingQuery struct with list query parameters * @returns {PagingList<Message>} struct containing a list of messages */ async listMessages(threadId, pagingQuery) { return this.native.listMessages(this.servicePtr, [threadId, pagingQuery]); } /** * Sends a message in a Thread. * * @param {string} threadId ID of the Thread to send message to * @param {Uint8Array} publicMeta public message metadata * @param {Uint8Array} privateMeta private message metadata * @param {Uint8Array} data content of the message * @returns {string} ID of the new message */ async sendMessage(threadId, publicMeta, privateMeta, data) { return this.native.sendMessage(this.servicePtr, [ threadId, publicMeta, privateMeta, data, ]); } /** * Deletes a message by given message ID. * * @param {string} messageId ID of the message to delete */ async deleteMessage(messageId) { return this.native.deleteMessage(this.servicePtr, [messageId]); } /** * Update message in a Thread. * * @param {string} messageId ID of the message to update * @param {Uint8Array} publicMeta public message metadata * @param {Uint8Array} privateMeta private message metadata * @param {Uint8Array} data content of the message */ async updateMessage(messageId, publicMeta, privateMeta, data) { return this.native.updateMessage(this.servicePtr, [ messageId, publicMeta, privateMeta, data, ]); } /** * Subscribes for the Thread module main events. */ async subscribeForThreadEvents() { return this.native.subscribeForThreadEvents(this.servicePtr, []); } /** * Unsubscribes from the Thread module main events. */ async unsubscribeFromThreadEvents() { return this.native.unsubscribeFromThreadEvents(this.servicePtr, []); } /** * Subscribes for events in given Thread. * @param {string} threadId ID of the Thread to subscribe */ async subscribeForMessageEvents(threadId) { return this.native.subscribeForMessageEvents(this.servicePtr, [threadId]); } /** * Unsubscribes from events in given Thread. * @param {string} threadId ID of the Thread to unsubscribe */ async unsubscribeFromMessageEvents(threadId) { return this.native.unsubscribeFromMessageEvents(this.servicePtr, [ threadId, ]); } } exports.ThreadApi = ThreadApi;