@simplito/privmx-webendpoint
Version:
PrivMX Web Endpoint library
161 lines (160 loc) • 5.4 kB
TypeScript
import { Connection, CryptoApi, EventQueue, InboxApi, StoreApi, ThreadApi, KvdbApi, EventApi } from "../service";
import { PublicConnection } from "./PublicConnection";
import { ConnectionEventsManager, CustomEventsManager, InboxEventsManager, KvdbEventsManager, StoreEventsManager, ThreadEventsManager, UserEventsManager } from "./managers";
import { EventManager } from "./events";
/**
* @class PrivmxClient
* @classdesc A client for interacting with the PrivMX Endpoint API.
* @example
* // Initialize the PrivMX client
* await PrivmxClient.setup('/path/to/privmx/assets');
*
* // Connect to the PrivMX bridge
* const privateKey = 'your-private-key';
* const solutionId = 'your-solution-id';
* const contextId = 'your-context-id';
* const bridgeUrl = 'https://your-bridge-url.com';
* const client = await PrivmxClient.connect(privateKey, solutionId, bridgeUrl);
*
* // Get the Thread API and list threads
* const threadApi = await client.getThreadApi();
* const threads = await threadApi.listThreads(contextId, {
* skip: 0,
* limit: 100,
* sort: 'desc'
* })
*
* // Disconnect when done
* await client.disconnect();
*/
export declare class PrivmxClient {
private connection;
private static cryptoApi;
private static eventQueue;
private static isSetup;
private static eventManager;
private threadApi;
private storeApi;
private inboxApi;
private kvdbApi;
private eventApi;
private connectionEventManager;
private userEventManager;
private threadEventManager;
private storeEventManager;
private inboxEventManager;
private customEventsManager;
private kvdbEventsManager;
/**
* @constructor
* @param {Connection} connection - The connection object.
*/
private constructor();
/**
* @description Sets up the PrivMX endpoint if it hasn't been set up yet.
* @param {string} folderPath - The path to the folder where PrivMX assets are stored.
* @returns {Promise<void>}
*/
static setup(folderPath: string): Promise<void>;
private static checkSetup;
/**
* @description Gets the Crypto API.
* @returns {Promise<CryptoApi>}
*/
static getCryptoApi(): Promise<CryptoApi>;
/**
* @description Gets the Event Queue.
* @returns {Promise<EventQueue>}
*/
static getEventQueue(): Promise<EventQueue>;
/**
* @description Gets the Event Manager.
* @returns {Promise<EventManager>}
*/
static getEventManager(): Promise<EventManager>;
/**
* @description Connects to the PrivMX bridge.
* @param {string} privateKey user's private key
* @param {string} solutionId ID of the Solution
* @param {string} bridgeUrl the Bridge Server URL
* @returns {Promise<PrivmxClient>}
* @throws {Error} If the connection to the bridge fails.
*/
static connect(privateKey: string, solutionId: string, bridgeUrl: string): Promise<PrivmxClient>;
/**
* Connects to the Platform backend as a guest user.
*
* @param {string} solutionId ID of the Solution
* @param {string} bridgeUrl the Bridge Server URL
*
* @returns {Promise<PublicConnection>} Promised instance of Connection
*/
static connectPublic(solutionId: string, bridgeUrl: string): Promise<PublicConnection>;
/**
* @description Gets the connection object.
* @returns {Connection}
* @throws {Error} If there is no active connection.
*/
getConnection(): Connection;
/**
* @description Gets the Thread API.
* @returns {Promise<ThreadApi>}
*/
getThreadApi(): Promise<ThreadApi>;
/**
* @description Gets the Store API.
* @returns {Promise<StoreApi>}
*/
getStoreApi(): Promise<StoreApi>;
/**
* @description Gets the Inbox API.
* @returns {Promise<InboxApi>}
*/
getInboxApi(): Promise<InboxApi>;
/**
* @description Gets the Kvdb API.
* @returns {Promise<KvdbApi>}
*/
getKvdbApi(): Promise<KvdbApi>;
/**
* @description Gets the Event API.
* @returns {Promise<EventApi>}
*/
getEventApi(): Promise<EventApi>;
/**
* @description Gets the Connection Event Manager.
* @returns {Promise<ConnectionEventsManager>}
*/
getConnectionEventManager(): Promise<ConnectionEventsManager>;
/**
* @description Gets the User Event Manager.
* @returns {Promise<UserEventsManager>}
*/
getUserEventsManager(): Promise<UserEventsManager>;
/**
* @description Gets the Thread Event Manager.
* @returns {Promise<ThreadEventsManager>}
*/
getThreadEventManager(): Promise<ThreadEventsManager>;
/**
* @description Gets the Store Event Manager.
* @returns {Promise<StoreEventsManager>}
*/
getStoreEventManager(): Promise<StoreEventsManager>;
/**
* @description Gets the Inbox Event Manager.
* @returns {Promise<InboxEventsManager>}
*/
getInboxEventManager(): Promise<InboxEventsManager>;
/**
* @description Gets the Custom Events Manager.
* @returns {Promise<CustomEventsManager>}
*/
getCustomEventsManager(): Promise<CustomEventsManager>;
getKvdbEventsManager(): Promise<KvdbEventsManager>;
/**
* @description Disconnects from the PrivMX bridge.
* @returns {Promise<void>}
*/
disconnect(): Promise<void>;
}