@simplito/privmx-webendpoint 2.6.2 → 2.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
@@ -0,0 +1,2 @@
1
+ /*! For license information please see privmx-endpoint-web.js.LICENSE.txt */
2
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["privmx-webendpoint"]=t():e.PrivmxWebEndpoint=t()}(self,(()=>(()=>{"use strict";var e={667:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Api=void 0;const s=i(785);t.Api=class{lib;promises;taskIdGenerator;constructor(e){this.lib=e,this.taskIdGenerator=new s.IdGenerator,this.promises=new Map,this.setResultsCallback()}async runAsync(e){return new Promise(((t,i)=>{const s=this.generateId();this.promises.set(s,{resolve:t,reject:i}),e(s)}))}resolveResult(e){1==e.status?this.promises.get(e.taskId).resolve(e.result):this.promises.get(e.taskId).reject(e.error),this.promises.delete(e.taskId)}generateId(){return this.taskIdGenerator.generateId()}setResultsCallback(){this.lib.setResultsCallback((e=>this.resolveResult(e)))}}},361:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BaseNative=void 0,t.BaseNative=class{_api;constructor(e){this._api=e}get api(){if(!this._api)throw new Error("This API instance is no longer valid because the connection associated with it has been closed.");return this._api}deleteApiRef(){this._api=null}async runAsync(e){if(!this.api)throw new Error("This API instance is no longer valid because the connection associated with it has been closed.");return this.api.runAsync(e)}}},140:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ConnectionNative=void 0;const s=i(361);class n extends s.BaseNative{lastConnectionId=-1;async newApi(e){throw new Error("Use the newConnection() - specialized version of method instead.")}async deleteApi(e){await this.runAsync((t=>this.api.lib.Connection_deleteConnection(t,e))),this.deleteApiRef()}async newConnection(){return this.runAsync((e=>this.api.lib.Connection_newConnection(e)))}async deleteConnection(e){await this.runAsync((t=>this.api.lib.Connection_deleteConnection(t,e))),this.deleteApiRef()}async connect(e,t){await this.runAsync((i=>this.api.lib.Connection_connect(i,e,t))),await this.getConnectionId(e,[])}async connectPublic(e,t){return this.runAsync((i=>this.api.lib.Connection_connectPublic(i,e,t)))}async getConnectionId(e,t){return this.lastConnectionId<0&&(this.lastConnectionId=await this.runAsync((i=>this.api.lib.Connection_getConnectionId(i,e,t)))),this.lastConnectionId}async listContexts(e,t){return this.runAsync((i=>this.api.lib.Connection_listContexts(i,e,t)))}async disconnect(e,t){await this.runAsync((i=>this.api.lib.Connection_disconnect(i,e,t)))}}t.ConnectionNative=n},711:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CryptoApiNative=void 0;const s=i(361);class n extends s.BaseNative{async newApi(){return this.runAsync((e=>this.api.lib.CryptoApi_newCryptoApi(e)))}async deleteApi(e){await this.runAsync((t=>this.api.lib.CryptoApi_deleteCryptoApi(t,e))),this.deleteApiRef()}async create(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_create(i,e,t)))}async signData(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_signData(i,e,t)))}async generatePrivateKey(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_generatePrivateKey(i,e,t)))}async derivePrivateKey(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_derivePrivateKey(i,e,t)))}async derivePrivateKey2(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_derivePrivateKey2(i,e,t)))}async derivePublicKey(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_derivePublicKey(i,e,t)))}async generateKeySymmetric(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_generateKeySymmetric(i,e,t)))}async encryptDataSymmetric(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_encryptDataSymmetric(i,e,t)))}async decryptDataSymmetric(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_decryptDataSymmetric(i,e,t)))}async convertPEMKeytoWIFKey(e,t){return this.runAsync((i=>this.api.lib.CryptoApi_convertPEMKeytoWIFKey(i,e,t)))}}t.CryptoApiNative=n},467:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EventQueueNative=void 0;const s=i(361);class n extends s.BaseNative{async newApi(e){throw new Error("Use the newEventQueue() - specialized version of method instead.")}async deleteApi(e){await this.runAsync((t=>this.api.lib.EventQueue_deleteEventQueue(t,e))),this.deleteApiRef()}async newEventQueue(){return this.runAsync((e=>this.api.lib.EventQueue_newEventQueue(e)))}async deleteEventQueue(e){await this.runAsync((t=>this.api.lib.EventQueue_deleteEventQueue(t,e))),this.deleteApiRef()}async waitEvent(e,t){return this.runAsync((i=>this.api.lib.EventQueue_waitEvent(i,e,t)))}async emitBreakEvent(e,t){return this.runAsync((i=>this.api.lib.EventQueue_emitBreakEvent(i,e,t)))}}t.EventQueueNative=n},785:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.IdGenerator=void 0,t.IdGenerator=class{_id=0;generateId(){return this._id++,this._id}}},252:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.InboxApiNative=void 0;const s=i(361);class n extends s.BaseNative{async newApi(e,t,i){return this.runAsync((s=>this.api.lib.InboxApi_newInboxApi(s,e,t,i)))}async deleteApi(e){await this.runAsync((t=>this.api.lib.InboxApi_deleteInboxApi(t,e))),this.deleteApiRef()}async create(e,t){return this.runAsync((i=>this.api.lib.InboxApi_create(i,e,t)))}async createInbox(e,t){return this.runAsync((i=>this.api.lib.InboxApi_createInbox(i,e,t)))}async updateInbox(e,t){return this.runAsync((i=>this.api.lib.InboxApi_updateInbox(i,e,t)))}async getInbox(e,t){return this.runAsync((i=>this.api.lib.InboxApi_getInbox(i,e,t)))}async listInboxes(e,t){return this.runAsync((i=>this.api.lib.InboxApi_listInboxes(i,e,t)))}async getInboxPublicView(e,t){return this.runAsync((i=>this.api.lib.InboxApi_getInboxPublicView(i,e,t)))}async deleteInbox(e,t){return this.runAsync((i=>this.api.lib.InboxApi_deleteInbox(i,e,t)))}async prepareEntry(e,t){return this.runAsync((i=>this.api.lib.InboxApi_prepareEntry(i,e,t)))}async sendEntry(e,t){return this.runAsync((i=>this.api.lib.InboxApi_sendEntry(i,e,t)))}async readEntry(e,t){return this.runAsync((i=>this.api.lib.InboxApi_readEntry(i,e,t)))}async deleteEntry(e,t){return this.runAsync((i=>this.api.lib.InboxApi_deleteEntry(i,e,t)))}async listEntries(e,t){return this.runAsync((i=>this.api.lib.InboxApi_listEntries(i,e,t)))}async createFileHandle(e,t){return this.runAsync((i=>this.api.lib.InboxApi_createFileHandle(i,e,t)))}async writeToFile(e,t){return this.runAsync((i=>this.api.lib.InboxApi_writeToFile(i,e,t)))}async openFile(e,t){return this.runAsync((i=>this.api.lib.InboxApi_openFile(i,e,t)))}async readFromFile(e,t){return this.runAsync((i=>this.api.lib.InboxApi_readFromFile(i,e,t)))}async seekInFile(e,t){return this.runAsync((i=>this.api.lib.InboxApi_seekInFile(i,e,t)))}async closeFile(e,t){return this.runAsync((i=>this.api.lib.InboxApi_closeFile(i,e,t)))}async subscribeForInboxEvents(e,t){return this.runAsync((i=>this.api.lib.InboxApi_subscribeForInboxEvents(i,e,t)))}async unsubscribeFromInboxEvents(e,t){return this.runAsync((i=>this.api.lib.InboxApi_unsubscribeFromInboxEvents(i,e,t)))}async subscribeForEntryEvents(e,t){return this.runAsync((i=>this.api.lib.InboxApi_subscribeForEntryEvents(i,e,t)))}async unsubscribeFromEntryEvents(e,t){return this.runAsync((i=>this.api.lib.InboxApi_unsubscribeFromEntryEvents(i,e,t)))}}t.InboxApiNative=n},243:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StoreApiNative=void 0;const s=i(361);class n extends s.BaseNative{async newApi(e){return this.runAsync((t=>this.api.lib.StoreApi_newStoreApi(t,e)))}async deleteApi(e){await this.runAsync((t=>this.api.lib.StoreApi_deleteStoreApi(t,e))),this.deleteApiRef()}async create(e,t){return this.runAsync((i=>this.api.lib.StoreApi_create(i,e,t)))}async createStore(e,t){return this.runAsync((i=>this.api.lib.StoreApi_createStore(i,e,t)))}async updateStore(e,t){return this.runAsync((i=>this.api.lib.StoreApi_updateStore(i,e,t)))}async deleteStore(e,t){return this.runAsync((i=>this.api.lib.StoreApi_deleteStore(i,e,t)))}async getStore(e,t){return this.runAsync((i=>this.api.lib.StoreApi_getStore(i,e,t)))}async listStores(e,t){return this.runAsync((i=>this.api.lib.StoreApi_listStores(i,e,t)))}async createFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_createFile(i,e,t)))}async updateFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_updateFile(i,e,t)))}async updateFileMeta(e,t){return this.runAsync((i=>this.api.lib.StoreApi_updateFileMeta(i,e,t)))}async writeToFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_writeToFile(i,e,t)))}async deleteFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_deleteFile(i,e,t)))}async getFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_getFile(i,e,t)))}async listFiles(e,t){return this.runAsync((i=>this.api.lib.StoreApi_listFiles(i,e,t)))}async openFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_openFile(i,e,t)))}async readFromFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_readFromFile(i,e,t)))}async seekInFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_seekInFile(i,e,t)))}async closeFile(e,t){return this.runAsync((i=>this.api.lib.StoreApi_closeFile(i,e,t)))}async subscribeForStoreEvents(e,t){return this.runAsync((i=>this.api.lib.StoreApi_subscribeForStoreEvents(i,e,t)))}async unsubscribeFromStoreEvents(e,t){return this.runAsync((i=>this.api.lib.StoreApi_unsubscribeFromStoreEvents(i,e,t)))}async subscribeForFileEvents(e,t){return this.runAsync((i=>this.api.lib.StoreApi_subscribeForFileEvents(i,e,t)))}async unsubscribeFromFileEvents(e,t){return this.runAsync((i=>this.api.lib.StoreApi_unsubscribeFromFileEvents(i,e,t)))}}t.StoreApiNative=n},272:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ThreadApiNative=void 0;const s=i(361);class n extends s.BaseNative{async newApi(e){return this.runAsync((t=>this.api.lib.ThreadApi_newThreadApi(t,e)))}async deleteApi(e){await this.runAsync((t=>this.api.lib.ThreadApi_deleteThreadApi(t,e))),this.deleteApiRef()}async create(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_create(i,e,t)))}async createThread(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_createThread(i,e,t)))}async updateThread(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_updateThread(i,e,t)))}async deleteThread(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_deleteThread(i,e,t)))}async getThread(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_getThread(i,e,t)))}async listThreads(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_listThreads(i,e,t)))}async getMessage(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_getMessage(i,e,t)))}async listMessages(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_listMessages(i,e,t)))}async sendMessage(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_sendMessage(i,e,t)))}async deleteMessage(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_deleteMessage(i,e,t)))}async updateMessage(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_updateMessage(i,e,t)))}async subscribeForThreadEvents(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_subscribeForThreadEvents(i,e,t)))}async unsubscribeFromThreadEvents(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_unsubscribeFromThreadEvents(i,e,t)))}async subscribeForMessageEvents(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_subscribeForMessageEvents(i,e,t)))}async unsubscribeFromMessageEvents(e,t){return this.runAsync((i=>this.api.lib.ThreadApi_unsubscribeFromMessageEvents(i,e,t)))}}t.ThreadApiNative=n},647:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BaseApi=void 0,t.BaseApi=class{_servicePtr;constructor(e){this._servicePtr=e}get servicePtr(){if(this._servicePtr<0)throw new Error("This API instance is no longer valid because the connection associated with it has been closed.");return this._servicePtr}destroyRefs(){this._servicePtr=-1}}},262:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Connection=void 0;const s=i(647);class n extends s.BaseApi{native;apisRefs={};nativeApisDeps={};constructor(e,t){super(t),this.native=e}async getConnectionId(){return this.native.getConnectionId(this.servicePtr,[])}async listContexts(e){return this.native.listContexts(this.servicePtr,[e])}async disconnect(){await this.native.disconnect(this.servicePtr,[]),await this.freeApis(),await this.native.deleteConnection(this.servicePtr)}async freeApis(){for(const e in this.apisRefs)this.nativeApisDeps[e]&&await this.nativeApisDeps[e].deleteApi(this.apisRefs[e]._apiServicePtr)}}t.Connection=n},11:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CryptoApi=void 0;const s=i(647);class n extends s.BaseApi{native;constructor(e,t){super(t),this.native=e}async signData(e,t){return this.native.signData(this.servicePtr,[e,t])}async generatePrivateKey(e){return this.native.generatePrivateKey(this.servicePtr,[e])}async derivePrivateKey(e,t){return this.native.derivePrivateKey(this.servicePtr,[e,t])}async derivePrivateKey2(e,t){return this.native.derivePrivateKey2(this.servicePtr,[e,t])}async derivePublicKey(e){return this.native.derivePublicKey(this.servicePtr,[e])}async generateKeySymmetric(){return this.native.generateKeySymmetric(this.servicePtr,[])}async encryptDataSymmetric(e,t){return this.native.encryptDataSymmetric(this.servicePtr,[e,t])}async decryptDataSymmetric(e,t){return this.native.decryptDataSymmetric(this.servicePtr,[e,t])}async convertPEMKeytoWIFKey(e){return this.native.convertPEMKeytoWIFKey(this.servicePtr,[e])}}t.CryptoApi=n},181:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EndpointFactory=void 0;const s=i(667),n=i(140),r=i(711),a=i(467),c=i(252),o=i(243),u=i(272),h=i(262),p=i(11),y=i(297),l=i(134),v=i(985),d=i(148);class b{static api;static eventQueueInstance;static async setup(e){const t=e||document.currentScript.src.split("/").slice(0,-1).join("/"),i=["driver-web-context.js","endpoint-wasm-module.js"];for(const e of i)await this.loadScript(t+"/"+e);const s=await endpointWasmModule();b.init(s)}static async loadScript(e){return new Promise((t=>{const i=document.getElementsByTagName("head")[0],s=document.createElement("script");s.type="text/javascript",s.src=e,s.onload=()=>{t()},i.appendChild(s)}))}static init(e){this.api=new s.Api(e)}static async getEventQueue(){if(!this.eventQueueInstance){const e=new a.EventQueueNative(this.api),t=await e.newEventQueue();this.eventQueueInstance=new y.EventQueue(e,t)}return this.eventQueueInstance}static async connect(e,t,i){const s=new n.ConnectionNative(this.api),r=await s.newConnection();return await s.connect(r,[e,t,i]),new h.Connection(s,r)}static async connectPublic(e,t){const i=new n.ConnectionNative(this.api),s=await i.newConnection();return await i.connectPublic(s,[e,t]),new h.Connection(i,s)}static async createThreadApi(e){if("threads"in e.apisRefs)throw new Error("ThreadApi already registered for given connection.");const t=new u.ThreadApiNative(this.api),i=await t.newApi(e.servicePtr);return await t.create(i,[]),e.apisRefs.threads={_apiServicePtr:i},e.nativeApisDeps.threads=t,new d.ThreadApi(t,i)}static async createStoreApi(e){if("stores"in e.apisRefs)throw new Error("StoreApi already registered for given connection.");const t=new o.StoreApiNative(this.api),i=await t.newApi(e.servicePtr);return e.apisRefs.stores={_apiServicePtr:i},e.nativeApisDeps.stores=t,await t.create(i,[]),new v.StoreApi(t,i)}static async createInboxApi(e,t,i){if("inboxes"in e.apisRefs)throw new Error("InboxApi already registered for given connection.");const s=new c.InboxApiNative(this.api),n=await s.newApi(e.servicePtr,t.servicePtr,i.servicePtr);return e.apisRefs.inboxes={_apiServicePtr:n},e.nativeApisDeps.inboxes=s,await s.create(n,[]),new l.InboxApi(s,n)}static async createCryptoApi(){const e=new r.CryptoApiNative(this.api),t=await e.newApi();return await e.create(t,[]),new p.CryptoApi(e,t)}}t.EndpointFactory=b},297:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EventQueue=void 0;const s=i(647);class n extends s.BaseApi{native;isPending=!1;constructor(e,t){super(t),this.native=e}async waitEvent(){if(this.isPending)throw"WaitEvent() is already in a pending state waiting for new events";try{return await this.native.waitEvent(this.servicePtr,[])}finally{this.isPending=!1}}async emitBreakEvent(){return this.native.emitBreakEvent(this.servicePtr,[])}}t.EventQueue=n},134:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.InboxApi=void 0;const s=i(647);class n extends s.BaseApi{native;constructor(e,t){super(t),this.native=e}async createInbox(e,t,i,s,n,r,a){return this.native.createInbox(this.servicePtr,[e,t,i,s,n,r,a])}async updateInbox(e,t,i,s,n,r,a,c,o,u){return this.native.updateInbox(this.servicePtr,[e,t,i,s,n,r,a,c,o,u])}async getInbox(e){return this.native.getInbox(this.servicePtr,[e])}async listInboxes(e,t){return this.native.listInboxes(this.servicePtr,[e,t])}async getInboxPublicView(e){return this.native.getInboxPublicView(this.servicePtr,[e])}async deleteInbox(e){return this.native.deleteInbox(this.servicePtr,[e])}async prepareEntry(e,t,i,s){return this.native.prepareEntry(this.servicePtr,[e,t,i,s])}async sendEntry(e){return this.native.sendEntry(this.servicePtr,[e])}async readEntry(e){return this.native.readEntry(this.servicePtr,[e])}async listEntries(e,t){return this.native.listEntries(this.servicePtr,[e,t])}async deleteEntry(e){return this.native.deleteEntry(this.servicePtr,[e])}async createFileHandle(e,t,i){return this.native.createFileHandle(this.servicePtr,[e,t,i])}async writeToFile(e,t,i){return this.native.writeToFile(this.servicePtr,[e,t,i])}async openFile(e){return this.native.openFile(this.servicePtr,[e])}async readFromFile(e,t){return this.native.readFromFile(this.servicePtr,[e,t])}async seekInFile(e,t){return this.native.seekInFile(this.servicePtr,[e,t])}async closeFile(e){return this.native.closeFile(this.servicePtr,[e])}async subscribeForInboxEvents(){return this.native.subscribeForInboxEvents(this.servicePtr,[])}async unsubscribeFromInboxEvents(){return this.native.unsubscribeFromInboxEvents(this.servicePtr,[])}async subscribeForEntryEvents(e){return this.native.subscribeForEntryEvents(this.servicePtr,[e])}async unsubscribeFromEntryEvents(e){return this.native.unsubscribeFromEntryEvents(this.servicePtr,[e])}}t.InboxApi=n},985:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StoreApi=void 0;const s=i(647);class n extends s.BaseApi{native;constructor(e,t){super(t),this.native=e}async createStore(e,t,i,s,n,r){return this.native.createStore(this.servicePtr,[e,t,i,s,n,r])}async updateStore(e,t,i,s,n,r,a,c,o){return this.native.updateStore(this.servicePtr,[e,t,i,s,n,r,a,c,o])}async deleteStore(e){return this.native.deleteStore(this.servicePtr,[e])}async getStore(e){return this.native.getStore(this.servicePtr,[e])}async listStores(e,t){return this.native.listStores(this.servicePtr,[e,t])}async createFile(e,t,i,s){return this.native.createFile(this.servicePtr,[e,t,i,s])}async updateFile(e,t,i,s){return this.native.updateFile(this.servicePtr,[e,t,i,s])}async updateFileMeta(e,t,i){return this.native.updateFileMeta(this.servicePtr,[e,t,i])}async writeToFile(e,t){return this.native.writeToFile(this.servicePtr,[e,t])}async deleteFile(e){return this.native.deleteFile(this.servicePtr,[e])}async getFile(e){return this.native.getFile(this.servicePtr,[e])}async listFiles(e,t){return this.native.listFiles(this.servicePtr,[e,t])}async openFile(e){return this.native.openFile(this.servicePtr,[e])}async readFromFile(e,t){return this.native.readFromFile(this.servicePtr,[e,t])}async seekInFile(e,t){return this.native.seekInFile(this.servicePtr,[e,t])}async closeFile(e){return this.native.closeFile(this.servicePtr,[e])}async subscribeForStoreEvents(){return this.native.subscribeForStoreEvents(this.servicePtr,[])}async unsubscribeFromStoreEvents(){return this.native.unsubscribeFromStoreEvents(this.servicePtr,[])}async subscribeForFileEvents(e){return this.native.subscribeForFileEvents(this.servicePtr,[e])}async unsubscribeFromFileEvents(e){return this.native.unsubscribeFromFileEvents(this.servicePtr,[e])}}t.StoreApi=n},148:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ThreadApi=void 0;const s=i(647);class n extends s.BaseApi{native;constructor(e,t){super(t),this.native=e}async createThread(e,t,i,s,n,r){return this.native.createThread(this.servicePtr,[e,t,i,s,n,r])}async updateThread(e,t,i,s,n,r,a,c,o){return this.native.updateThread(this.servicePtr,[e,t,i,s,n,r,a,c,o])}async deleteThread(e){return this.native.deleteThread(this.servicePtr,[e])}async getThread(e){return this.native.getThread(this.servicePtr,[e])}async listThreads(e,t){return this.native.listThreads(this.servicePtr,[e,t])}async getMessage(e){return this.native.getMessage(this.servicePtr,[e])}async listMessages(e,t){return this.native.listMessages(this.servicePtr,[e,t])}async sendMessage(e,t,i,s){return this.native.sendMessage(this.servicePtr,[e,t,i,s])}async deleteMessage(e){return this.native.deleteMessage(this.servicePtr,[e])}async updateMessage(e,t,i,s){return this.native.updateMessage(this.servicePtr,[e,t,i,s])}async subscribeForThreadEvents(){return this.native.subscribeForThreadEvents(this.servicePtr,[])}async unsubscribeFromThreadEvents(){return this.native.unsubscribeFromThreadEvents(this.servicePtr,[])}async subscribeForMessageEvents(e){return this.native.subscribeForMessageEvents(this.servicePtr,[e])}async unsubscribeFromMessageEvents(e){return this.native.unsubscribeFromMessageEvents(this.servicePtr,[e])}}t.ThreadApi=n}},t={};function i(s){var n=t[s];if(void 0!==n)return n.exports;var r=t[s]={exports:{}};return e[s](r,r.exports,i),r.exports}var s={};return(()=>{var e=s;Object.defineProperty(e,"__esModule",{value:!0}),e.Endpoint=void 0;const t=i(181);Object.defineProperty(e,"Endpoint",{enumerable:!0,get:function(){return t.EndpointFactory}})})(),s})()));
@@ -1,6 +1,6 @@
1
1
  import { Connection, CryptoApi, EventQueue, InboxApi, StoreApi, ThreadApi, KvdbApi, EventApi } from '../service';
2
2
  import { PublicConnection } from './PublicConnection';
3
- import { ConnectionEventsManager, InboxEventsManager, StoreEventsManager, ThreadEventsManager } from "./managers";
3
+ import { ConnectionEventsManager, CustomEventsManager, InboxEventsManager, KvdbEventsManager, StoreEventsManager, ThreadEventsManager, UserEventsManager } from "./managers";
4
4
  import { EventManager } from "./events";
5
5
  /**
6
6
  * @class PrivmxClient
@@ -39,9 +39,12 @@ export declare class PrivmxClient {
39
39
  private kvdbApi;
40
40
  private eventApi;
41
41
  private connectionEventManager;
42
+ private userEventManager;
42
43
  private threadEventManager;
43
44
  private storeEventManager;
44
45
  private inboxEventManager;
46
+ private customEventsManager;
47
+ private kvdbEventsManager;
45
48
  /**
46
49
  * @constructor
47
50
  * @param {Connection} connection - The connection object.
@@ -123,6 +126,11 @@ export declare class PrivmxClient {
123
126
  * @returns {Promise<ConnectionEventsManager>}
124
127
  */
125
128
  getConnectionEventManager(): Promise<ConnectionEventsManager>;
129
+ /**
130
+ * @description Gets the User Event Manager.
131
+ * @returns {Promise<UserEventsManager>}
132
+ */
133
+ getUserEventsManager(): Promise<UserEventsManager>;
126
134
  /**
127
135
  * @description Gets the Thread Event Manager.
128
136
  * @returns {Promise<ThreadEventsManager>}
@@ -138,6 +146,12 @@ export declare class PrivmxClient {
138
146
  * @returns {Promise<InboxEventsManager>}
139
147
  */
140
148
  getInboxEventManager(): Promise<InboxEventsManager>;
149
+ /**
150
+ * @description Gets the Custom Events Manager.
151
+ * @returns {Promise<CustomEventsManager>}
152
+ */
153
+ getCustomEventsManager(): Promise<CustomEventsManager>;
154
+ getKvdbEventsManager(): Promise<KvdbEventsManager>;
141
155
  /**
142
156
  * @description Disconnects from the PrivMX bridge.
143
157
  * @returns {Promise<void>}
@@ -41,9 +41,12 @@ class PrivmxClient {
41
41
  kvdbApi = null;
42
42
  eventApi = null;
43
43
  connectionEventManager = null;
44
+ userEventManager = null;
44
45
  threadEventManager = null;
45
46
  storeEventManager = null;
46
47
  inboxEventManager = null;
48
+ customEventsManager = null;
49
+ kvdbEventsManager = null;
47
50
  /**
48
51
  * @constructor
49
52
  * @param {Connection} connection - The connection object.
@@ -229,11 +232,25 @@ class PrivmxClient {
229
232
  this.connectionEventManager = (async () => {
230
233
  const eventManager = await PrivmxClient.getEventManager();
231
234
  const connection = this.getConnection();
232
- const connectionId = (await connection.getConnectionId());
233
- return eventManager.getConnectionEventManager(connectionId);
235
+ const connectionId = await connection.getConnectionId();
236
+ return eventManager.getConnectionEventManager(`${connectionId}`);
234
237
  })();
235
238
  return this.connectionEventManager;
236
239
  }
240
+ /**
241
+ * @description Gets the User Event Manager.
242
+ * @returns {Promise<UserEventsManager>}
243
+ */
244
+ async getUserEventsManager() {
245
+ if (this.userEventManager) {
246
+ return this.userEventManager;
247
+ }
248
+ this.userEventManager = (async () => {
249
+ const eventManager = await PrivmxClient.getEventManager();
250
+ return eventManager.getUserEventsManager(this.getConnection());
251
+ })();
252
+ return this.userEventManager;
253
+ }
237
254
  /**
238
255
  * @description Gets the Thread Event Manager.
239
256
  * @returns {Promise<ThreadEventsManager>}
@@ -276,6 +293,30 @@ class PrivmxClient {
276
293
  })();
277
294
  return this.inboxEventManager;
278
295
  }
296
+ /**
297
+ * @description Gets the Custom Events Manager.
298
+ * @returns {Promise<CustomEventsManager>}
299
+ */
300
+ async getCustomEventsManager() {
301
+ if (this.customEventsManager) {
302
+ return this.customEventsManager;
303
+ }
304
+ this.customEventsManager = (async () => {
305
+ const eventManager = await PrivmxClient.getEventManager();
306
+ return eventManager.getCustomEventsManager(await this.getEventApi());
307
+ })();
308
+ return this.customEventsManager;
309
+ }
310
+ async getKvdbEventsManager() {
311
+ if (this.kvdbEventsManager) {
312
+ return this.kvdbEventsManager;
313
+ }
314
+ this.kvdbEventsManager = (async () => {
315
+ const eventManager = await PrivmxClient.getEventManager();
316
+ return eventManager.getKvdbEventManager(await this.getKvdbApi());
317
+ })();
318
+ return this.kvdbEventsManager;
319
+ }
279
320
  /**
280
321
  * @description Disconnects from the PrivMX bridge.
281
322
  * @returns {Promise<void>}
@@ -287,9 +328,12 @@ class PrivmxClient {
287
328
  this.storeApi = null;
288
329
  this.inboxApi = null;
289
330
  this.connectionEventManager = null;
331
+ this.customEventsManager = null;
332
+ this.userEventManager = null;
290
333
  this.threadEventManager = null;
291
334
  this.storeEventManager = null;
292
335
  this.inboxEventManager = null;
336
+ this.kvdbEventsManager = null;
293
337
  }
294
338
  catch (e) {
295
339
  console.error('Error during disconnection:', e);
@@ -1,3 +1,4 @@
1
+ import { Types } from "../../index";
1
2
  export declare function createBaseEvent(subsId: string): {
2
3
  type: string;
3
4
  data: {};
@@ -61,3 +62,7 @@ export declare const MOCK_THREAD_MESSAGE_DELETED_EVENT: (threadID: string, subsI
61
62
  readonly version: number;
62
63
  readonly timestamp: number;
63
64
  };
65
+ export declare const MOCK_CONNECTION_USER_ADDED_EVENT: (subsId: string) => Types.Event;
66
+ export declare const MOCK_CONNECTION_USER_STATUS_EVENT: (subsId: string) => Types.Event;
67
+ export declare const MOCK_LIB_CONNECTED_EVENT: (connectionId: number) => Types.Event;
68
+ export declare const MOCK_CUSTOM_EVENT: (subsId: string, contextId?: string, channelName?: string) => Types.Event;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MOCK_THREAD_MESSAGE_DELETED_EVENT = exports.MOCK_THREAD_CREATED_EVENT = exports.MOCK_STORE_FILE_DELETED_EVENT = exports.MOCK_STORE_CREATED_EVENT = exports.MOCK_INBOX_ENTRY_DELETED_EVENT = exports.MOCK_INBOX_CREATED_EVENT = void 0;
3
+ exports.MOCK_CUSTOM_EVENT = exports.MOCK_LIB_CONNECTED_EVENT = exports.MOCK_CONNECTION_USER_STATUS_EVENT = exports.MOCK_CONNECTION_USER_ADDED_EVENT = exports.MOCK_THREAD_MESSAGE_DELETED_EVENT = exports.MOCK_THREAD_CREATED_EVENT = exports.MOCK_STORE_FILE_DELETED_EVENT = exports.MOCK_STORE_CREATED_EVENT = exports.MOCK_INBOX_ENTRY_DELETED_EVENT = exports.MOCK_INBOX_CREATED_EVENT = void 0;
4
4
  exports.createBaseEvent = createBaseEvent;
5
5
  function createBaseEvent(subsId) {
6
6
  return {
@@ -49,3 +49,54 @@ const MOCK_THREAD_MESSAGE_DELETED_EVENT = (threadID, subsId) => ({
49
49
  channel: `thread/${threadID}/messages`,
50
50
  });
51
51
  exports.MOCK_THREAD_MESSAGE_DELETED_EVENT = MOCK_THREAD_MESSAGE_DELETED_EVENT;
52
+ const MOCK_CONNECTION_USER_ADDED_EVENT = (subsId) => ({
53
+ ...createBaseEvent(subsId),
54
+ type: "contextUserAdded",
55
+ channel: "context/userAdded",
56
+ data: {
57
+ contextId: "ctx-1",
58
+ user: {
59
+ userId: "user-1",
60
+ pubKey: "pub-1",
61
+ },
62
+ },
63
+ });
64
+ exports.MOCK_CONNECTION_USER_ADDED_EVENT = MOCK_CONNECTION_USER_ADDED_EVENT;
65
+ const MOCK_CONNECTION_USER_STATUS_EVENT = (subsId) => ({
66
+ ...createBaseEvent(subsId),
67
+ type: "contextUserStatusChanged",
68
+ channel: "context/userStatus",
69
+ data: {
70
+ contextId: "ctx-1",
71
+ users: [
72
+ {
73
+ user: {
74
+ userId: "user-1",
75
+ pubKey: "pub-1",
76
+ },
77
+ action: "login",
78
+ },
79
+ ],
80
+ },
81
+ });
82
+ exports.MOCK_CONNECTION_USER_STATUS_EVENT = MOCK_CONNECTION_USER_STATUS_EVENT;
83
+ const MOCK_LIB_CONNECTED_EVENT = (connectionId) => ({
84
+ ...createBaseEvent("ignored"),
85
+ type: "libConnected",
86
+ channel: "channel/lib_connected",
87
+ connectionId,
88
+ });
89
+ exports.MOCK_LIB_CONNECTED_EVENT = MOCK_LIB_CONNECTED_EVENT;
90
+ const MOCK_CUSTOM_EVENT = (subsId, contextId = "ctx-1", channelName = "custom-channel") => ({
91
+ ...createBaseEvent(subsId),
92
+ type: "contextCustom",
93
+ channel: `context/${contextId}/${channelName}`,
94
+ data: {
95
+ contextId,
96
+ userId: "user-1",
97
+ payload: new Uint8Array([1, 2, 3]),
98
+ statusCode: 0,
99
+ schemaVersion: 5,
100
+ },
101
+ });
102
+ exports.MOCK_CUSTOM_EVENT = MOCK_CUSTOM_EVENT;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const constants_1 = require("../__mocks__/constants");
4
+ const utils_1 = require("../__mocks__/utils");
5
+ const subscriptions_1 = require("../subscriptions");
6
+ describe("Connection event manager", () => {
7
+ let { q, manager } = (0, utils_1.createTestSetup)();
8
+ let connectionEventsManager;
9
+ beforeEach(() => {
10
+ let { q: _q, manager: _manager } = (0, utils_1.createTestSetup)();
11
+ q = _q;
12
+ manager = _manager;
13
+ connectionEventsManager = manager.getConnectionEventManager("1");
14
+ });
15
+ it("supports legacy lib connection events", async () => {
16
+ const callback = jest.fn();
17
+ const libSubscription = (0, subscriptions_1.createConnectionSubscription)({
18
+ type: subscriptions_1.ConnectionStatusEventType.LIB_CONNECTED,
19
+ callbacks: [callback],
20
+ });
21
+ const [libSubscriptionId] = await connectionEventsManager.subscribeFor([
22
+ libSubscription,
23
+ ]);
24
+ expect(libSubscriptionId).toBe("1/channel/lib_connected");
25
+ q.dispatchEvent((0, constants_1.MOCK_LIB_CONNECTED_EVENT)(1));
26
+ await (0, utils_1.waitForNextTick)();
27
+ expect(callback).toHaveBeenCalledTimes(1);
28
+ });
29
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const index_1 = require("../../index");
4
+ const constants_1 = require("../__mocks__/constants");
5
+ const mockContainerSubscriber_1 = require("../__mocks__/mockContainerSubscriber");
6
+ const utils_1 = require("../__mocks__/utils");
7
+ const subscriptions_1 = require("../subscriptions");
8
+ describe("Custom event manager", () => {
9
+ let { q, manager } = (0, utils_1.createTestSetup)();
10
+ let customEventsManager = manager.getCustomEventsManager(new mockContainerSubscriber_1.MockContainerSubscriber(q));
11
+ beforeEach(() => {
12
+ let { q: _q, manager: _manager } = (0, utils_1.createTestSetup)();
13
+ q = _q;
14
+ manager = _manager;
15
+ customEventsManager = _manager.getCustomEventsManager(new mockContainerSubscriber_1.MockContainerSubscriber(q));
16
+ });
17
+ it("dispatches custom events to registered callbacks", async () => {
18
+ const subscriber = new mockContainerSubscriber_1.MockContainerSubscriber(q);
19
+ const buildQuerySpy = jest
20
+ .spyOn(subscriber, "buildSubscriptionQuery")
21
+ .mockImplementation(async (channel, selector, selectorId) => {
22
+ expect(channel).toBe("custom-channel");
23
+ expect(selector).toBe(index_1.Types.EventsEventSelectorType.CONTEXT_ID);
24
+ expect(selectorId).toBe("ctx-1");
25
+ return `${channel}|${selectorId}`;
26
+ });
27
+ const managerWithSpy = manager.getCustomEventsManager(subscriber);
28
+ const callback = jest.fn();
29
+ const subscription = (0, subscriptions_1.createEventSubscription)({
30
+ channel: "custom-channel",
31
+ selector: index_1.Types.EventsEventSelectorType.CONTEXT_ID,
32
+ id: "ctx-1",
33
+ callbacks: [callback],
34
+ });
35
+ const [subscriptionId] = await managerWithSpy.subscribeFor([subscription]);
36
+ expect(buildQuerySpy).toHaveBeenCalled();
37
+ q.dispatchEvent((0, constants_1.MOCK_CUSTOM_EVENT)(subscriptionId));
38
+ await (0, utils_1.waitForNextTick)();
39
+ expect(callback).toHaveBeenCalledTimes(1);
40
+ const eventArg = callback.mock.calls[0][0];
41
+ expect(eventArg.data).toEqual({
42
+ contextId: "ctx-1",
43
+ userId: "user-1",
44
+ payload: new Uint8Array([1, 2, 3]),
45
+ statusCode: 0,
46
+ schemaVersion: 5,
47
+ });
48
+ });
49
+ it("stops invoking callbacks after unsubscribe", async () => {
50
+ const callback = jest.fn();
51
+ const subscription = (0, subscriptions_1.createEventSubscription)({
52
+ channel: "custom-channel",
53
+ selector: index_1.Types.EventsEventSelectorType.CONTEXT_ID,
54
+ id: "ctx-1",
55
+ callbacks: [callback],
56
+ });
57
+ const [subscriptionId] = await customEventsManager.subscribeFor([
58
+ subscription,
59
+ ]);
60
+ await customEventsManager.unsubscribeFrom([subscriptionId]);
61
+ q.dispatchEvent((0, constants_1.MOCK_CUSTOM_EVENT)(subscriptionId));
62
+ await (0, utils_1.waitForNextTick)();
63
+ expect(callback).not.toHaveBeenCalled();
64
+ });
65
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const index_1 = require("../../index");
4
+ const constants_1 = require("../__mocks__/constants");
5
+ const mockContainerSubscriber_1 = require("../__mocks__/mockContainerSubscriber");
6
+ const utils_1 = require("../__mocks__/utils");
7
+ const subscriptions_1 = require("../subscriptions");
8
+ describe("User event manager", () => {
9
+ let { q, manager } = (0, utils_1.createTestSetup)();
10
+ let userEventsManager;
11
+ beforeEach(() => {
12
+ let { q: _q, manager: _manager } = (0, utils_1.createTestSetup)();
13
+ q = _q;
14
+ manager = _manager;
15
+ userEventsManager = manager.getUserEventsManager(new mockContainerSubscriber_1.MockContainerSubscriber(q));
16
+ });
17
+ it("dispatches user events to registered callbacks", async () => {
18
+ const callback = jest.fn();
19
+ const subscription = (0, subscriptions_1.createUserEventSubscription)({
20
+ type: index_1.Types.ConnectionEventType.USER_ADD,
21
+ selector: index_1.Types.ConnectionEventSelectorType.CONTEXT_ID,
22
+ id: "ctx-1",
23
+ callbacks: [callback],
24
+ });
25
+ const [subscriptionId] = await userEventsManager.subscribeFor([
26
+ subscription,
27
+ ]);
28
+ q.dispatchEvent((0, constants_1.MOCK_CONNECTION_USER_ADDED_EVENT)(subscriptionId));
29
+ await (0, utils_1.waitForNextTick)();
30
+ expect(callback).toHaveBeenCalledTimes(1);
31
+ expect(callback.mock.calls[0][0].data).toEqual({
32
+ contextId: "ctx-1",
33
+ user: { userId: "user-1", pubKey: "pub-1" },
34
+ });
35
+ });
36
+ it("stops invoking callbacks after unsubscribe", async () => {
37
+ const callback = jest.fn();
38
+ const subscription = (0, subscriptions_1.createUserEventSubscription)({
39
+ type: index_1.Types.ConnectionEventType.USER_STATUS,
40
+ selector: index_1.Types.ConnectionEventSelectorType.CONTEXT_ID,
41
+ id: "ctx-1",
42
+ callbacks: [callback],
43
+ });
44
+ const [subscriptionId] = await userEventsManager.subscribeFor([
45
+ subscription,
46
+ ]);
47
+ await userEventsManager.unsubscribeFrom([subscriptionId]);
48
+ q.dispatchEvent((0, constants_1.MOCK_CONNECTION_USER_STATUS_EVENT)(subscriptionId));
49
+ await (0, utils_1.waitForNextTick)();
50
+ expect(callback).not.toHaveBeenCalled();
51
+ });
52
+ });
package/extra/events.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Types } from "..";
2
- import { SubscriberForInboxEvents, SubscriberForKvdbEvents, SubscriberForStoreEvents, SubscriberForThreadsEvents } from "./subscriptions";
3
- import { BaseEventDispatcherManager, ConnectionEventsManager, InboxEventsManager, KvdbEventsManager, StoreEventsManager, ThreadEventsManager } from "./managers";
2
+ import { SubscriberForInboxEvents, SubscriberForUserEvents, SubscriberForEvents, SubscriberForKvdbEvents, SubscriberForStoreEvents, SubscriberForThreadsEvents } from "./subscriptions";
3
+ import { BaseEventDispatcherManager, ConnectionEventsManager, CustomEventsManager, InboxEventsManager, KvdbEventsManager, StoreEventsManager, ThreadEventsManager, UserEventsManager } from "./managers";
4
4
  export declare class EventManager {
5
5
  private _isEventLoopRunning;
6
6
  dispatchers: ((event: Types.Event) => void)[];
@@ -18,5 +18,7 @@ export declare class EventManager {
18
18
  getStoreEventManager(storeApi: SubscriberForStoreEvents): StoreEventsManager;
19
19
  getKvdbEventManager(kvdbApi: SubscriberForKvdbEvents): KvdbEventsManager;
20
20
  getInboxEventManager(inboxApi: SubscriberForInboxEvents): InboxEventsManager;
21
+ getCustomEventsManager(eventApi: SubscriberForEvents): CustomEventsManager;
21
22
  getConnectionEventManager(connectionId: string): ConnectionEventsManager;
23
+ getUserEventsManager(connectionApi: SubscriberForUserEvents): UserEventsManager;
22
24
  }
package/extra/events.js CHANGED
@@ -6,11 +6,11 @@ const managers_1 = require("./managers");
6
6
  function normalizeConnectionEvent(e) {
7
7
  switch (e.type) {
8
8
  case 'libDisconnected':
9
- return { ...e, subscriptions: [`${e.connectionId}/${managers_1.ConnectionChannels[subscriptions_1.ConnectionEventType.LIB_DISCONNECTED]}`] };
9
+ return { ...e, subscriptions: [`${e.connectionId}/${managers_1.ConnectionChannels[subscriptions_1.ConnectionStatusEventType.LIB_DISCONNECTED]}`] };
10
10
  case 'libPlatformDisconnected':
11
- return { ...e, subscriptions: [`${e.connectionId}/${managers_1.ConnectionChannels[subscriptions_1.ConnectionEventType.LIB_PLATFORM_DISCONNECTED]}`] };
11
+ return { ...e, subscriptions: [`${e.connectionId}/${managers_1.ConnectionChannels[subscriptions_1.ConnectionStatusEventType.LIB_PLATFORM_DISCONNECTED]}`] };
12
12
  case 'libConnected':
13
- return { ...e, subscriptions: [`${e.connectionId}/${managers_1.ConnectionChannels[subscriptions_1.ConnectionEventType.LIB_CONNECTED]}`] };
13
+ return { ...e, subscriptions: [`${e.connectionId}/${managers_1.ConnectionChannels[subscriptions_1.ConnectionStatusEventType.LIB_CONNECTED]}`] };
14
14
  default:
15
15
  return e;
16
16
  }
@@ -26,6 +26,8 @@ class EventManager {
26
26
  this.eventsQueue.waitEvent().then((event) => {
27
27
  this.onEvent(event);
28
28
  this.listenForEvents();
29
+ }).catch(() => {
30
+ this.listenForEvents();
29
31
  });
30
32
  }
31
33
  }
@@ -38,6 +40,8 @@ class EventManager {
38
40
  return;
39
41
  manager.onEvent(event);
40
42
  manager.listenForEvents();
43
+ }).catch(() => {
44
+ manager.listenForEvents();
41
45
  });
42
46
  return manager;
43
47
  }
@@ -73,10 +77,20 @@ class EventManager {
73
77
  this.registerDispatcher(manager);
74
78
  return manager;
75
79
  }
80
+ getCustomEventsManager(eventApi) {
81
+ const manager = new managers_1.CustomEventsManager(eventApi);
82
+ this.registerDispatcher(manager);
83
+ return manager;
84
+ }
76
85
  getConnectionEventManager(connectionId) {
77
86
  const manager = new managers_1.ConnectionEventsManager(connectionId);
78
87
  this.registerDispatcher(manager);
79
88
  return manager;
80
89
  }
90
+ getUserEventsManager(connectionApi) {
91
+ const manager = new managers_1.UserEventsManager(connectionApi);
92
+ this.registerDispatcher(manager);
93
+ return manager;
94
+ }
81
95
  }
82
96
  exports.EventManager = EventManager;
package/extra/index.d.ts CHANGED
@@ -6,5 +6,5 @@ import { FileUploader, StreamReader, downloadFile } from './files';
6
6
  import { PrivmxClient } from './PrivmxClient';
7
7
  import { PublicConnection } from './PublicConnection';
8
8
  export { EventManager } from "./events";
9
- export { createInboxSubscription, createThreadSubscription, createConnectionSubscription, createKvdbSubscription, createStoreSubscription, EventCallback, Subscription } from "./subscriptions";
9
+ export { createInboxSubscription, createThreadSubscription, createConnectionSubscription, createUserEventSubscription, createKvdbSubscription, createStoreSubscription, createEventSubscription, EventCallback, Subscription, ConnectionStatusEventType, ConnectionSubscription, } from "./subscriptions";
10
10
  export { Files, Inboxes, Utils, Generics, FileUploader, downloadFile, StreamReader, PrivmxClient, PublicConnection, };
package/extra/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PublicConnection = exports.PrivmxClient = exports.StreamReader = exports.downloadFile = exports.FileUploader = exports.Generics = exports.Utils = exports.Inboxes = exports.Files = exports.createStoreSubscription = exports.createKvdbSubscription = exports.createConnectionSubscription = exports.createThreadSubscription = exports.createInboxSubscription = exports.EventManager = void 0;
3
+ exports.PublicConnection = exports.PrivmxClient = exports.StreamReader = exports.downloadFile = exports.FileUploader = exports.Generics = exports.Utils = exports.Inboxes = exports.Files = exports.ConnectionStatusEventType = exports.createEventSubscription = exports.createStoreSubscription = exports.createKvdbSubscription = exports.createUserEventSubscription = exports.createConnectionSubscription = exports.createThreadSubscription = exports.createInboxSubscription = exports.EventManager = void 0;
4
4
  const Files = require("./files");
5
5
  exports.Files = Files;
6
6
  const Utils = require("./utils");
@@ -23,5 +23,8 @@ var subscriptions_1 = require("./subscriptions");
23
23
  Object.defineProperty(exports, "createInboxSubscription", { enumerable: true, get: function () { return subscriptions_1.createInboxSubscription; } });
24
24
  Object.defineProperty(exports, "createThreadSubscription", { enumerable: true, get: function () { return subscriptions_1.createThreadSubscription; } });
25
25
  Object.defineProperty(exports, "createConnectionSubscription", { enumerable: true, get: function () { return subscriptions_1.createConnectionSubscription; } });
26
+ Object.defineProperty(exports, "createUserEventSubscription", { enumerable: true, get: function () { return subscriptions_1.createUserEventSubscription; } });
26
27
  Object.defineProperty(exports, "createKvdbSubscription", { enumerable: true, get: function () { return subscriptions_1.createKvdbSubscription; } });
27
28
  Object.defineProperty(exports, "createStoreSubscription", { enumerable: true, get: function () { return subscriptions_1.createStoreSubscription; } });
29
+ Object.defineProperty(exports, "createEventSubscription", { enumerable: true, get: function () { return subscriptions_1.createEventSubscription; } });
30
+ Object.defineProperty(exports, "ConnectionStatusEventType", { enumerable: true, get: function () { return subscriptions_1.ConnectionStatusEventType; } });
@@ -1,5 +1,5 @@
1
1
  import { Types } from "..";
2
- import { ConnectionEventType, EventCallback, SubscriberForInboxEvents, SubscriberForKvdbEvents, SubscriberForStoreEvents, SubscriberForThreadsEvents, Subscription } from "./subscriptions";
2
+ import { ConnectionStatusEventType, ConnectionSubscription, EventCallback, SubscriberForEvents, SubscriberForInboxEvents, SubscriberForKvdbEvents, SubscriberForStoreEvents, SubscriberForThreadsEvents, SubscriberForUserEvents, Subscription } from "./subscriptions";
3
3
  /**
4
4
  *
5
5
  * General usage
@@ -33,7 +33,7 @@ import { ConnectionEventType, EventCallback, SubscriberForInboxEvents, Subscribe
33
33
  *
34
34
  * await manager.removeCallback(subscriptionA.callbacks[0])
35
35
  */
36
- export type Channel = "inbox" | `inbox/${string}/entries` | "store" | `store/${string}/files` | "thread" | `thread/${string}/messages` | `connection/${string}`;
36
+ export type Channel = "inbox" | `inbox/${string}/entries` | "store" | `store/${string}/files` | "thread" | `thread/${string}/messages` | `connection/${string}` | "context/userAdded" | "context/userRemoved" | "context/userStatus" | `context/${string}/${string}`;
37
37
  export interface GenericEvent<K> extends Types.Event {
38
38
  /**
39
39
  * Data associated with the event.
@@ -81,18 +81,25 @@ export declare class KvdbEventsManager extends BaseEventDispatcherManager {
81
81
  protected apiUnsubscribeFrom(subscriptionId: string[]): Promise<void>;
82
82
  subscribeFor(subscriptions: Subscription<Types.KvdbEventType, Types.KvdbEventSelectorType>[]): Promise<string[]>;
83
83
  }
84
- export declare const ConnectionChannels: {
85
- 2: string;
86
- 0: string;
87
- 1: string;
88
- };
84
+ export declare class CustomEventsManager extends BaseEventDispatcherManager {
85
+ private eventsApi;
86
+ constructor(eventsApi: SubscriberForEvents);
87
+ protected apiSubscribeFor(channels: string[]): Promise<string[]>;
88
+ protected apiUnsubscribeFrom(subscriptionId: string[]): Promise<void>;
89
+ subscribeFor(subscriptions: Subscription<string, Types.EventsEventSelectorType>[]): Promise<string[]>;
90
+ }
91
+ export declare const ConnectionChannels: Record<ConnectionStatusEventType, string>;
89
92
  export declare class ConnectionEventsManager extends BaseEventDispatcherManager {
90
93
  private connectionId;
91
94
  constructor(connectionId: string);
92
95
  protected apiSubscribeFor(channels: string[]): Promise<string[]>;
93
96
  protected apiUnsubscribeFrom(): Promise<void>;
94
- subscribeFor(subscriptions: {
95
- type: ConnectionEventType;
96
- callbacks: EventCallback[];
97
- }[]): Promise<string[]>;
97
+ subscribeFor(subscriptions: ConnectionSubscription[]): Promise<string[]>;
98
+ }
99
+ export declare class UserEventsManager extends BaseEventDispatcherManager {
100
+ private userEventsApi;
101
+ constructor(userEventsApi: SubscriberForUserEvents);
102
+ protected apiSubscribeFor(channels: string[]): Promise<string[]>;
103
+ protected apiUnsubscribeFrom(subscriptionId: string[]): Promise<void>;
104
+ subscribeFor(subscriptions: Subscription<Types.ConnectionEventType, Types.ConnectionEventSelectorType>[]): Promise<string[]>;
98
105
  }