UNPKG

@simplito/privmx-webendpoint

Version:

PrivMX Web Endpoint library

119 lines (116 loc) 4.01 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.Connection = void 0; const BaseApi_1 = require("./BaseApi"); class Connection extends BaseApi_1.BaseApi { native; /** * //doc-gen:ignore */ apisRefs = {}; /** * //doc-gen:ignore */ nativeApisDeps = {}; constructor(native, ptr) { super(ptr); this.native = native; } /** * Gets the ID of the current connection. * * @returns {number} ID of the connection */ async getConnectionId() { return this.native.getConnectionId(this.servicePtr, []); } /** * Gets a list of Contexts available for the user. * * @param pagingQuery with list query parameters * @returns {PagingList<Context>} containing a list of Contexts */ async listContexts(pagingQuery) { return this.native.listContexts(this.servicePtr, [pagingQuery]); } /** * Gets a list of users of given context. * * @param contextId ID of the Context * * @returns a list of the UserInfo objects */ async listContextUsers(contextId, pagingQuery) { return this.native.listContextUsers(this.servicePtr, [contextId, pagingQuery]); } /** * Subscribe for the Context events on the given subscription query. * * @param {string[]} subscriptionQueries list of queries * @return list of subscriptionIds in matching order to subscriptionQueries */ async subscribeFor(subscriptionQueries) { return this.native.subscribeFor(this.servicePtr, [subscriptionQueries]); } /** * Unsubscribe from events for the given subscriptionId. * @param {string[]} subscriptionIds list of subscriptionId */ async unsubscribeFrom(subscriptionIds) { return this.native.unsubscribeFrom(this.servicePtr, [subscriptionIds]); } /** * Generate subscription Query for the Context events. * @param {EventType} eventType type of event which you listen for * @param {EventSelectorType} selectorType scope on which you listen for events * @param {string} selectorId ID of the selector */ async buildSubscriptionQuery(eventType, selectorType, selectorId) { return this.native.buildSubscriptionQuery(this.servicePtr, [ eventType, selectorType, selectorId, ]); } /** * Disconnects from the Platform backend. * */ async disconnect() { await this.native.disconnect(this.servicePtr, []); await this.freeApis(); await this.native.deleteConnection(this.servicePtr); } /** * Sets user's custom verification callback. * * The feature allows the developer to set up a callback for user verification. * A developer can implement an interface and pass the implementation to the function. * Each time data is read from the container, a callback will be triggered, allowing the developer to validate the sender in an external service, * e.g. Developer's Application Server or PKI Server. * @param verifier an implementation of the UserVerifierInterface * */ setUserVerifier(verifier) { return this.native.setUserVerifier(this.servicePtr, [this.servicePtr, verifier]); } async freeApis() { console.warn("freeApis disabled for debugging purposes. Please re-enable"); // for (const apiId in this.apisRefs) { // if (this.nativeApisDeps[apiId]) { // await this.nativeApisDeps[apiId].deleteApi( // this.apisRefs[apiId]._apiServicePtr // ); // } // } } } exports.Connection = Connection;