import { EndpointApiEvent, EventsByChannel, SubscribeForChannel } from '../types/events'; import { Context, ListOptions, PagingList } from '../types/core'; import { Connection } from '../api/connection/Connection'; import { ThreadApi } from '../api/thread/ThreadApi'; import { StoreApi } from '../api/store/StoreApi'; import { InboxApi } from '../api/inbox/InboxApi'; import { EventQueue } from '../api/event-queue/EventQueue'; import { PublicConnection } from './PublicConnection'; import { ContextInboxes, ContextStores, ContextThreads, GenericInbox, GenericStore, GenericThread } from './ContextClients'; /** * Wrapper class for Privmx Endpoint. * * @example * Connecting to Privmx Endpoint * ```js * const connection = await Endpoint.connect({ * bridgeUrl:BRIDGE_URL, * solutionId:SOLUTION_ID, * privKey:USER_PRIVATE_KEY * }) * ``` */ export declare class Endpoint { private _coreApi; private static _connections; private static _eventQueue; private static _isEventLoopRunning; private static _eventLoopId; private _connectionType; /** * Returns the type of current connection. * @returns {string} `user` - when connected with `connect`, `public` - when connected with `connectPublic` */ connectionType(): 'public' | 'user'; private _threadApiPromise; private _threadApi; private _storeApiPromise; private _storeApi; private _inboxApi; private _inboxApiPromise; private _connectionId; private readonly _label; private readonly eventDispatcher; private static _defaultConnectionId; /** * @returns {string} default connection ID/label which is called by `connection()` and `connectionPublic()` when no label is passed */ static getDefaultConnectionId(): string; /** * Sets the default connection ID. * @param {string} id */ static setDefaultConnectionId(id: string): void; constructor(_coreApi: Connection, connectionId: string, label: string); /** * Connects to Bridge using provided config. * @param {object} connectionConfig * @param {string} connectionConfig.bridgeUrl - URL of PrivMX Bridge instance * @param {string} connectionConfig.solutionId - ID of Solution to connect to * @param {string} connectionConfig.privKey - Private Key in WIF format; you have to register their Private Key before users can connect to Bridge * @param {string} connectionConfig.label - optional label to set if you're using multiple connections; if you're not - `connectionId` will be used by default * @returns {Promise} {@link Endpoint `Promise`} */ static connect(connectionConfig: { bridgeUrl: string; privKey: string; solutionId: string; label?: string; }): Promise; /** * Connects to the Bridge publicly using provided config. * This method of connecting to PrivMX Bridge doesn't require registering private keys earlier, they are created while connecting. * Public connection exposes limited set of Endpoint method. * @param {object} connectionConfig * @param {string} connectionConfig.bridgeUrl - URL of PrivMX Bridge instance * @param {string} connectionConfig.solutionId - ID of Solution to connect to * @param {string} connectionConfig.label - optional label to set if you're using multiple connections; if you're not - `connectionId` will be used by default * @returns {Promise} {@link Endpoint `Promise`} */ static connectPublic(connectionConfig: { bridgeUrl: string; solutionId: string; label?: string; }): Promise; /** * Function for getting current active connection. * @param {string=} label optional label passed during `Endpoint.connect` * @returns {Endpoint} * * @throws {@link ConnectionError} -Thrown when there is no current connection * @throws {@link ConnectionError} -Thrown when user uses public connection */ static connection(label?: string): Endpoint; /** * Returns a wrapper for functions that can be used in a public(guest) connection. * @returns {PublicConnection} {@link PublicConnection `AnonymousConnection` } * * @throws {@link ConnectionError} Thrown when used for getting normal connection (created using `Endpoint.connect` instead of `Endpoint.connectPublic`) * @throws {@link ConnectionError} Thrown when there is no current public connection */ static publicConnection(label?: string): PublicConnection; /** * Provides functions to manage Threads. * * @returns {ContextThreads} {@link ContextThreads `ContextThread`} */ get threads(): ContextThreads; /** * Provides a wrapper to manage given Thread. * @param {string} threadId - ID of the Thread * * @returns {GenericThread} {@link GenericThread `GenericThread`} * @throws {@link ConnectionError} Thrown when used for getting normal connection (created using `Endpoint.connect` instead of `Endpoint.connectPublic`) */ thread(threadId: string): GenericThread; /** * Provides functions to manage Stores. * * @returns {ContextStores} {@link ContextStores `ContextStores`} */ get stores(): ContextStores; /** * Provides a wrapper to manage a given Store. * @param {string} storeId - ID of the Store * * @returns {GenericStore} {@link GenericStore `GenericStore`} */ store(storeId: string): GenericStore; /** * Provides functions to manage Inboxes. * * @returns {ContextInboxes} {@link ContextInboxes `ContextInboxes`} */ get inboxes(): ContextInboxes; /** * Provides a wrapper to manage given Inbox. * @param {string} inboxId - ID of the Inbox * * @returns {GenericInbox} {@link GenericInbox `GenericInbox`} */ inbox(inboxId: string): GenericInbox; /** * Gets instance of ThreadApi associated with current connection. * @returns {Promise} {@link ThreadApi `Promise`} */ getThreadApi(): Promise; /** * Gets instance of StoreApi associated with current connection. * @returns {Promise} {@link StoreApi Promise<`StoreApi`>} */ getStoreApi(): Promise; /** * Gets instance of InboxApi associated with current connection. * @returns {Promise} {@link InboxApi `Promise`} */ getInboxApi(): Promise; /** * Gets instance of `EventQueue`. * @returns {Promise} {@link EventQueue `Promise`} */ static getEventQueue(): Promise; /** * Dispatches an event. * @param {EndpointApiEvent} event */ private static dispatchEvent; /** * Starts new event loop if there isn't already one. * @param options * @param {boolean=} options.debug (optional) if set to true, console will log incoming caught events * */ static startEventLoop(options?: { debug?: boolean; }): Promise; /** * Stops current event loop, unsubscribes from all channels and removes all event handlers. */ static stopEventLoop(): Promise; /** * Disconnects user from the Bridge. */ disconnect(): Promise; /** * Returns list of Contexts the users has access to. * * @param {number} pageIndex - indicates from which page should list start * @param {ListOptions} [options] - optional options for listing data (default value pageSize: 100, sort: 'desc') * @returns {Promise>} {@link PagingList `PagingList`} */ listContexts(pageIndex?: number, options?: ListOptions): Promise>; private getOn; /** * Registers an event listener for connection-related events. * * @template T * @param {T & EventsByChannel<'connection'>} eventType - type of event to listen for * @param {function(Extract): void} callback - callback function to execute when the event occurs * @returns {Promise<{on: SubscribeForChannel<'connection'>, removeEventListener: function() void}>} object containing the `on` function for chaining and `removeEventListener` to unregister the event listener */ on>(eventType: T, callback: (payload: Extract) => void): SubscribeForChannel<'connection'> & { removeEventListener: () => void; }; }