@simplito/privmx-webendpoint 2.6.1 → 2.6.3

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.
@@ -1,5 +1,4 @@
1
1
  import { Types } from "..";
2
- import { ThreadEventSelectorType, ThreadEventType } from "../Types";
3
2
  import { GenericEvent } from "./managers";
4
3
  export type ThreadCallbackPayload = {
5
4
  [Types.ThreadEventType.THREAD_CREATE]: Types.Thread;
@@ -75,8 +74,14 @@ export type KvdbCallbackPayload = {
75
74
  };
76
75
  [Types.KvdbEventType.COLLECTION_CHANGE]: Types.CollectionChangedEventData;
77
76
  };
77
+ export type UserEventCallbackPayload = {
78
+ [Types.ConnectionEventType.USER_ADD]: Types.ContextUserEventData;
79
+ [Types.ConnectionEventType.USER_REMOVE]: Types.ContextUserEventData;
80
+ [Types.ConnectionEventType.USER_STATUS]: Types.ContextUsersStatusChangedEventData;
81
+ };
82
+ export type EventsCallbackPayload = Types.ContextCustomEventData;
78
83
  export type EventCallback = {
79
- callback: (e: Types.Event) => void;
84
+ callback: (e: Types.Event | GenericEvent<unknown>) => void;
80
85
  symbol: Symbol;
81
86
  };
82
87
  export interface Subscription<T, S> {
@@ -129,37 +134,54 @@ export declare function createInboxSubscription<T extends Types.InboxEventType,
129
134
  selector: S;
130
135
  id: string;
131
136
  };
132
- export declare enum ConnectionEventType {
137
+ export declare function createEventSubscription(s: {
138
+ channel: string;
139
+ selector: Types.EventsEventSelectorType;
140
+ id: string;
141
+ callbacks: ((arg: GenericEvent<EventsCallbackPayload>) => void)[];
142
+ }): Subscription<string, Types.EventsEventSelectorType> & {
143
+ channel: string;
144
+ };
145
+ export declare enum ConnectionStatusEventType {
133
146
  LIB_DISCONNECTED = 0,
134
147
  LIB_PLATFORM_DISCONNECTED = 1,
135
148
  LIB_CONNECTED = 2
136
149
  }
137
- export declare function createConnectionSubscription(s: {
138
- type: ConnectionEventType;
139
- callbacks: ((arg: GenericEvent<undefined>) => void)[];
140
- }): {
150
+ export type ConnectionSubscription = {
151
+ type: ConnectionStatusEventType;
141
152
  callbacks: EventCallback[];
142
- type: ConnectionEventType;
143
153
  };
154
+ export declare function createConnectionSubscription(s: {
155
+ type: ConnectionStatusEventType;
156
+ callbacks: ((arg: GenericEvent<undefined>) => void)[];
157
+ }): ConnectionSubscription;
158
+ export declare function createUserEventSubscription<T extends Types.ConnectionEventType, S extends Types.ConnectionEventSelectorType>(s: {
159
+ type: T;
160
+ selector: S;
161
+ id: string;
162
+ callbacks: ((arg: GenericEvent<UserEventCallbackPayload[T]>) => void)[];
163
+ }): Subscription<T, S>;
144
164
  export interface EventSubscriber<E, S> {
145
165
  /**
146
- * Subscribe for the Thread events on the given subscription query.
166
+ * Subscribe for events on the given subscription queries.
147
167
  * @param {string[]} subscriptionQueries list of queries
148
168
  */
149
169
  subscribeFor(subscriptionQueries: string[]): Promise<string[]>;
150
170
  /**
151
- * Unsubscribes from events for the given subscriptionId.
171
+ * Unsubscribe from events for the given subscriptionIds.
152
172
  */
153
173
  unsubscribeFrom(subscriptionIds: string[]): Promise<void>;
154
174
  /**
155
- * Generate subscription Query for the Thread events.
156
- * @param {EventType} eventType type of event which you listen for
157
- * @param {EventSelectorType} selectorType scope on which you listen for events
175
+ * Generate subscription query string for the requested event scope.
176
+ * @param {E} eventType type of event which you listen for
177
+ * @param {S} selectorType scope on which you listen for events
158
178
  * @param {string} selectorId ID of the selector
159
179
  */
160
180
  buildSubscriptionQuery(eventType: E, selectorType: S, selectorId: string): Promise<string>;
161
181
  }
162
- export type SubscriberForThreadsEvents = EventSubscriber<ThreadEventType, ThreadEventSelectorType>;
182
+ export type SubscriberForThreadsEvents = EventSubscriber<Types.ThreadEventType, Types.ThreadEventSelectorType>;
163
183
  export type SubscriberForStoreEvents = EventSubscriber<Types.StoreEventType, Types.StoreEventSelectorType>;
164
184
  export type SubscriberForInboxEvents = EventSubscriber<Types.InboxEventType, Types.InboxEventSelectorType>;
165
185
  export type SubscriberForKvdbEvents = EventSubscriber<Types.KvdbEventType, Types.KvdbEventSelectorType>;
186
+ export type SubscriberForUserEvents = EventSubscriber<Types.ConnectionEventType, Types.ConnectionEventSelectorType>;
187
+ export type SubscriberForEvents = EventSubscriber<string, Types.EventsEventSelectorType>;
@@ -1,51 +1,68 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConnectionEventType = void 0;
3
+ exports.ConnectionStatusEventType = void 0;
4
4
  exports.createThreadSubscription = createThreadSubscription;
5
5
  exports.createStoreSubscription = createStoreSubscription;
6
6
  exports.createKvdbSubscription = createKvdbSubscription;
7
7
  exports.createInboxSubscription = createInboxSubscription;
8
+ exports.createEventSubscription = createEventSubscription;
8
9
  exports.createConnectionSubscription = createConnectionSubscription;
10
+ exports.createUserEventSubscription = createUserEventSubscription;
9
11
  const __1 = require("..");
10
12
  function toEventCallback(f) {
11
13
  return {
12
14
  callback: f,
13
- symbol: Symbol()
15
+ symbol: Symbol(),
14
16
  };
15
17
  }
16
18
  function createThreadSubscription(s) {
17
19
  return {
18
20
  ...s,
19
- callbacks: s.callbacks.map(toEventCallback)
21
+ callbacks: s.callbacks.map(toEventCallback),
20
22
  };
21
23
  }
22
24
  function createStoreSubscription(s) {
23
25
  return {
24
26
  ...s,
25
- callbacks: s.callbacks.map(toEventCallback)
27
+ callbacks: s.callbacks.map(toEventCallback),
26
28
  };
27
29
  }
28
30
  function createKvdbSubscription(s) {
29
31
  return {
30
32
  ...s,
31
- callbacks: s.callbacks.map(toEventCallback)
33
+ callbacks: s.callbacks.map(toEventCallback),
32
34
  };
33
35
  }
34
36
  function createInboxSubscription(s) {
35
37
  return {
36
38
  ...s,
37
- callbacks: s.callbacks.map(toEventCallback)
39
+ callbacks: s.callbacks.map(toEventCallback),
38
40
  };
39
41
  }
40
- var ConnectionEventType;
41
- (function (ConnectionEventType) {
42
- ConnectionEventType[ConnectionEventType["LIB_DISCONNECTED"] = 0] = "LIB_DISCONNECTED";
43
- ConnectionEventType[ConnectionEventType["LIB_PLATFORM_DISCONNECTED"] = 1] = "LIB_PLATFORM_DISCONNECTED";
44
- ConnectionEventType[ConnectionEventType["LIB_CONNECTED"] = 2] = "LIB_CONNECTED";
45
- })(ConnectionEventType || (exports.ConnectionEventType = ConnectionEventType = {}));
42
+ function createEventSubscription(s) {
43
+ return {
44
+ type: s.channel,
45
+ selector: s.selector,
46
+ id: s.id,
47
+ callbacks: s.callbacks.map(toEventCallback),
48
+ channel: s.channel,
49
+ };
50
+ }
51
+ var ConnectionStatusEventType;
52
+ (function (ConnectionStatusEventType) {
53
+ ConnectionStatusEventType[ConnectionStatusEventType["LIB_DISCONNECTED"] = 0] = "LIB_DISCONNECTED";
54
+ ConnectionStatusEventType[ConnectionStatusEventType["LIB_PLATFORM_DISCONNECTED"] = 1] = "LIB_PLATFORM_DISCONNECTED";
55
+ ConnectionStatusEventType[ConnectionStatusEventType["LIB_CONNECTED"] = 2] = "LIB_CONNECTED";
56
+ })(ConnectionStatusEventType || (exports.ConnectionStatusEventType = ConnectionStatusEventType = {}));
46
57
  function createConnectionSubscription(s) {
47
58
  return {
48
59
  ...s,
49
- callbacks: s.callbacks.map(toEventCallback)
60
+ callbacks: s.callbacks.map(toEventCallback),
61
+ };
62
+ }
63
+ function createUserEventSubscription(s) {
64
+ return {
65
+ ...s,
66
+ callbacks: s.callbacks.map(toEventCallback),
50
67
  };
51
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplito/privmx-webendpoint",
3
- "version": "2.6.1",
3
+ "version": "2.6.3",
4
4
  "description": "PrivMX Web Endpoint library",
5
5
  "author": "Simplito",
6
6
  "license": "PrivMX Free License",
@@ -18,11 +18,11 @@ export declare class EventApi extends BaseApi {
18
18
  * Emits the custom event on the given Context and channel.
19
19
  *
20
20
  * @param {string} contextId ID of the Context
21
+ * @param {UserWithPubKey[]} users list of UserWithPubKey objects which defines the recipients of the event
21
22
  * @param {string} channelName name of the Channel
22
23
  * @param {Uint8Array} eventData event's data
23
- * @param {UserWithPubKey[]} users list of UserWithPubKey objects which defines the recipients of the event
24
24
  */
25
- emitEvent(contextId: string, channelName: string, eventData: Uint8Array, users: UserWithPubKey[]): Promise<void>;
25
+ emitEvent(contextId: string, users: UserWithPubKey[], channelName: string, eventData: Uint8Array): Promise<void>;
26
26
  /**
27
27
  * Subscribe for the custom events on the given subscription query.
28
28
  *
@@ -31,12 +31,12 @@ class EventApi extends BaseApi_1.BaseApi {
31
31
  * Emits the custom event on the given Context and channel.
32
32
  *
33
33
  * @param {string} contextId ID of the Context
34
+ * @param {UserWithPubKey[]} users list of UserWithPubKey objects which defines the recipients of the event
34
35
  * @param {string} channelName name of the Channel
35
36
  * @param {Uint8Array} eventData event's data
36
- * @param {UserWithPubKey[]} users list of UserWithPubKey objects which defines the recipients of the event
37
37
  */
38
- async emitEvent(contextId, channelName, eventData, users) {
39
- return this.native.emitEvent(this.servicePtr, [contextId, channelName, eventData, users]);
38
+ async emitEvent(contextId, users, channelName, eventData) {
39
+ return this.native.emitEvent(this.servicePtr, [contextId, users, channelName, eventData]);
40
40
  }
41
41
  // /**
42
42
  // * Subscribe for the custom events on the given channel.
@@ -1 +0,0 @@
1
- "use strict";var Module={};var ENVIRONMENT_IS_NODE=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string";if(ENVIRONMENT_IS_NODE){var nodeWorkerThreads=require("worker_threads");var parentPort=nodeWorkerThreads.parentPort;parentPort.on("message",data=>onmessage({data:data}));var fs=require("fs");Object.assign(global,{self:global,require:require,Module:Module,location:{href:__filename},Worker:nodeWorkerThreads.Worker,importScripts:f=>(0,eval)(fs.readFileSync(f,"utf8")+"//# sourceURL="+f),postMessage:msg=>parentPort.postMessage(msg),performance:global.performance||{now:Date.now}})}var initializedJS=false;function assert(condition,text){if(!condition)abort("Assertion failed: "+text)}function threadPrintErr(){var text=Array.prototype.slice.call(arguments).join(" ");if(ENVIRONMENT_IS_NODE){fs.writeSync(2,text+"\n");return}console.error(text)}function threadAlert(){var text=Array.prototype.slice.call(arguments).join(" ");postMessage({cmd:"alert",text:text,threadId:Module["_pthread_self"]()})}var out=()=>{throw"out() is not defined in worker.js."};var err=threadPrintErr;self.alert=threadAlert;var dbg=threadPrintErr;Module["instantiateWasm"]=(info,receiveInstance)=>{var module=Module["wasmModule"];Module["wasmModule"]=null;var instance=new WebAssembly.Instance(module,info);return receiveInstance(instance)};self.onunhandledrejection=e=>{throw e.reason||e};function handleMessage(e){try{if(e.data.cmd==="load"){let messageQueue=[];self.onmessage=e=>messageQueue.push(e);self.startWorker=instance=>{Module=instance;postMessage({"cmd":"loaded"});for(let msg of messageQueue){handleMessage(msg)}self.onmessage=handleMessage};Module["wasmModule"]=e.data.wasmModule;for(const handler of e.data.handlers){Module[handler]=(...args)=>{postMessage({cmd:"callHandler",handler:handler,args:args})}}Module["wasmMemory"]=e.data.wasmMemory;Module["buffer"]=Module["wasmMemory"].buffer;Module["workerID"]=e.data.workerID;Module["ENVIRONMENT_IS_PTHREAD"]=true;if(typeof e.data.urlOrBlob=="string"){importScripts(e.data.urlOrBlob)}else{var objectUrl=URL.createObjectURL(e.data.urlOrBlob);importScripts(objectUrl);URL.revokeObjectURL(objectUrl)}endpointWasmModule(Module)}else if(e.data.cmd==="run"){Module["__emscripten_thread_init"](e.data.pthread_ptr,0,0,1);Module["__emscripten_thread_mailbox_await"](e.data.pthread_ptr);assert(e.data.pthread_ptr);Module["establishStackSpace"]();Module["PThread"].receiveObjectTransfer(e.data);Module["PThread"].threadInitTLS();if(!initializedJS){Module["__embind_initialize_bindings"]();initializedJS=true}try{Module["invokeEntryPoint"](e.data.start_routine,e.data.arg)}catch(ex){if(ex!="unwind"){throw ex}}}else if(e.data.cmd==="cancel"){if(Module["_pthread_self"]()){Module["__emscripten_thread_exit"](-1)}}else if(e.data.target==="setimmediate"){}else if(e.data.cmd==="checkMailbox"){if(initializedJS){Module["checkMailbox"]()}}else if(e.data.cmd){err(`worker.js received unknown command ${e.data.cmd}`);err(e.data)}}catch(ex){err(`worker.js onmessage() captured an uncaught exception: ${ex}`);if(ex&&ex.stack)err(ex.stack);if(Module["__emscripten_thread_crashed"]){Module["__emscripten_thread_crashed"]()}throw ex}}self.onmessage=handleMessage;