@ermis-network/ermis-chat-sdk 1.0.3 → 1.0.5
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.
- package/dist/index.browser.cjs +123 -4
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.full-bundle.min.js +7 -7
- package/dist/index.browser.full-bundle.min.js.map +1 -1
- package/dist/index.browser.mjs +123 -3
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.cjs +123 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +173 -0
- package/dist/index.d.ts +173 -0
- package/dist/index.mjs +123 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/channel.ts +42 -0
- package/src/channel_state.ts +27 -0
- package/src/client.ts +104 -0
- package/src/wasm/ermis_call_node_wasm.js +1 -1
package/dist/index.cjs
CHANGED
|
@@ -414,15 +414,25 @@ var createForwardMessagePayload = (message, targetCid, activeCid) => {
|
|
|
414
414
|
// src/channel_state.ts
|
|
415
415
|
var ChannelState = class {
|
|
416
416
|
_channel;
|
|
417
|
+
/** The current count of users actively watching (having an open WebSocket) this channel. */
|
|
417
418
|
watcher_count;
|
|
419
|
+
/** A dictionary of active typing events gracefully keyed by the user's ID. */
|
|
418
420
|
typing;
|
|
421
|
+
/** A dictionary of read states mapped per user's ID detailing the last viewed message. */
|
|
419
422
|
read;
|
|
423
|
+
/** The locally cached array of pinned messages across the channel. */
|
|
420
424
|
pinnedMessages;
|
|
425
|
+
/** A directory of users actively watching the channel, keyed by User ID. */
|
|
421
426
|
watchers;
|
|
427
|
+
/** A comprehensive directory mapping user IDs to their member status in the channel. */
|
|
422
428
|
members;
|
|
429
|
+
/** The count of messages not yet read by the currently authenticated user. */
|
|
423
430
|
unreadCount;
|
|
431
|
+
/** Information detailing the authenticated user's own membership relation to this channel. */
|
|
424
432
|
membership;
|
|
433
|
+
/** Timestamp indicating when the very last message was created in this chat. */
|
|
425
434
|
last_message_at;
|
|
435
|
+
/** Designates if the local channel state is entirely synchronized with the backend history. */
|
|
426
436
|
isUpToDate;
|
|
427
437
|
messageSets = [];
|
|
428
438
|
topics = [];
|
|
@@ -454,6 +464,15 @@ var ChannelState = class {
|
|
|
454
464
|
const index = this.messageSets.findIndex((s) => s.isLatest);
|
|
455
465
|
this.messageSets[index].messages = messages;
|
|
456
466
|
}
|
|
467
|
+
/**
|
|
468
|
+
* Pushes a new message directly into the sorted array of the local tracking state.
|
|
469
|
+
* Useful to achieve optimistic UI updates locally.
|
|
470
|
+
*
|
|
471
|
+
* @param newMessage - The message context payload to insert.
|
|
472
|
+
* @param timestampChanged - Specifies if the underlying `created_at` timestamp mutated.
|
|
473
|
+
* @param addIfDoesNotExist - Append it strictly if its ID doesn't already exist.
|
|
474
|
+
* @param messageSetToAddToIfDoesNotExist - Specifies which message set scope to manipulate.
|
|
475
|
+
*/
|
|
457
476
|
addMessageSorted(newMessage, timestampChanged = false, addIfDoesNotExist = true, messageSetToAddToIfDoesNotExist = "latest") {
|
|
458
477
|
return this.addMessagesSorted(
|
|
459
478
|
[newMessage],
|
|
@@ -641,6 +660,12 @@ var ChannelState = class {
|
|
|
641
660
|
const result = msgArray.filter((message) => !(!!message.id && !!msg.id && message.id === msg.id));
|
|
642
661
|
return { removed: result.length < msgArray.length, result };
|
|
643
662
|
};
|
|
663
|
+
/**
|
|
664
|
+
* Refreshes internal user references cascading across all presently active messages.
|
|
665
|
+
* Invoked instantly whenever an underlying user's profile metadata updates (e.g. name or avatar changes).
|
|
666
|
+
*
|
|
667
|
+
* @param user - The newly formatted and populated User details object.
|
|
668
|
+
*/
|
|
644
669
|
updateUserMessages = (user) => {
|
|
645
670
|
const _updateUserMessages = (messages, user2) => {
|
|
646
671
|
for (let i = 0; i < messages.length; i++) {
|
|
@@ -912,6 +937,15 @@ var Channel = class {
|
|
|
912
937
|
lastTypingEvent;
|
|
913
938
|
isTyping;
|
|
914
939
|
disconnected;
|
|
940
|
+
/**
|
|
941
|
+
* Initializes a new Channel class instance.
|
|
942
|
+
* Normally you should not call this directly; use `client.channel(type, id)` instead.
|
|
943
|
+
*
|
|
944
|
+
* @param client - The shared ErmisChat client instance initializing this channel.
|
|
945
|
+
* @param type - The type of channel (`messaging`, `team`, `livestream`, etc.).
|
|
946
|
+
* @param id - The unique ID of the channel.
|
|
947
|
+
* @param data - Initial arbitrary metadata stored within this channel.
|
|
948
|
+
*/
|
|
915
949
|
constructor(client, type, id, data) {
|
|
916
950
|
const validTypeRe = /^[\w_-]+$/;
|
|
917
951
|
const validIDRe = /^[\w!:_-]+$/;
|
|
@@ -938,6 +972,13 @@ var Channel = class {
|
|
|
938
972
|
getClient() {
|
|
939
973
|
return this._client;
|
|
940
974
|
}
|
|
975
|
+
/**
|
|
976
|
+
* Sends a message to this channel.
|
|
977
|
+
* By default, it pushes the message eagerly (optimistically) to the local UI state before the server replies.
|
|
978
|
+
*
|
|
979
|
+
* @param message - The constructed text/attachment object payload representing the message.
|
|
980
|
+
* @returns A Promise resolving to the exact API response encompassing message details.
|
|
981
|
+
*/
|
|
941
982
|
async sendMessage(message) {
|
|
942
983
|
if (!message.id) {
|
|
943
984
|
message = { ...message, id: randomId() };
|
|
@@ -1167,6 +1208,11 @@ var Channel = class {
|
|
|
1167
1208
|
const url = this.getClient().baseURL + `/invites/${this.type}/${this.id}/skip`;
|
|
1168
1209
|
return this.getClient().post(url);
|
|
1169
1210
|
}
|
|
1211
|
+
/**
|
|
1212
|
+
* Directly invites or adds registered users into this channel.
|
|
1213
|
+
*
|
|
1214
|
+
* @param members - Array of user IDs explicitly selected to be added.
|
|
1215
|
+
*/
|
|
1170
1216
|
async addMembers(members) {
|
|
1171
1217
|
return await this._update({ add_members: members });
|
|
1172
1218
|
}
|
|
@@ -1232,6 +1278,11 @@ var Channel = class {
|
|
|
1232
1278
|
})
|
|
1233
1279
|
};
|
|
1234
1280
|
}
|
|
1281
|
+
/**
|
|
1282
|
+
* Expels specified currently participating users out of the channel.
|
|
1283
|
+
*
|
|
1284
|
+
* @param members - Array of user IDs to strictly remove from this chat.
|
|
1285
|
+
*/
|
|
1235
1286
|
async removeMembers(members) {
|
|
1236
1287
|
return await this._update({ remove_members: members });
|
|
1237
1288
|
}
|
|
@@ -1311,6 +1362,10 @@ var Channel = class {
|
|
|
1311
1362
|
messageSlice.sort((a, b) => b.created_at.getTime() - a.created_at.getTime());
|
|
1312
1363
|
return messageSlice[0];
|
|
1313
1364
|
}
|
|
1365
|
+
/**
|
|
1366
|
+
* Emits a mark-read event, updating the backend that the authenticated user has viewed up to the latest known message.
|
|
1367
|
+
* @returns Successful acknowledgement from the server.
|
|
1368
|
+
*/
|
|
1314
1369
|
async markRead() {
|
|
1315
1370
|
return await this.getClient().post(this._channelURL() + "/read");
|
|
1316
1371
|
}
|
|
@@ -1324,6 +1379,13 @@ var Channel = class {
|
|
|
1324
1379
|
}
|
|
1325
1380
|
this.state.clean();
|
|
1326
1381
|
}
|
|
1382
|
+
/**
|
|
1383
|
+
* Subscribes to realtime events (WebSocket) for this channel, grabs the latest available metadata,
|
|
1384
|
+
* loads the most recent messages, and initializes the local state.
|
|
1385
|
+
*
|
|
1386
|
+
* @param options - Pagination limits like `{ watch: true, presence: true, state: true }`.
|
|
1387
|
+
* @returns The synchronized comprehensive channel state.
|
|
1388
|
+
*/
|
|
1327
1389
|
async watch(options) {
|
|
1328
1390
|
await this.getClient().wsPromise;
|
|
1329
1391
|
const combined = { ...options };
|
|
@@ -2761,32 +2823,55 @@ function isString(x) {
|
|
|
2761
2823
|
var ErmisChat = class _ErmisChat {
|
|
2762
2824
|
static _instance;
|
|
2763
2825
|
// type is undefined|ErmisChat, unknown is due to TS limitations with statics
|
|
2826
|
+
/** A map of active channels currently tracked by the client, keyed by Channel ID. */
|
|
2764
2827
|
activeChannels;
|
|
2828
|
+
/** The internal configured Axios instance used for REST API requests. */
|
|
2765
2829
|
axiosInstance;
|
|
2830
|
+
/** The primary base URL for REST API communication. */
|
|
2766
2831
|
baseURL;
|
|
2832
|
+
/** The specific base URL for standard user-focused REST calls. */
|
|
2767
2833
|
userBaseURL;
|
|
2834
|
+
/** True when the SDK is executed inside a browser environment. */
|
|
2768
2835
|
browser;
|
|
2769
2836
|
cleaningIntervalRef;
|
|
2770
2837
|
clientID;
|
|
2771
2838
|
apiKey;
|
|
2772
2839
|
projectId;
|
|
2840
|
+
/** Internal mapped registry of event listeners. */
|
|
2773
2841
|
listeners;
|
|
2774
2842
|
logger;
|
|
2843
|
+
/** Whether the client should automatically fetch missing messages upon unexpected disconnects. */
|
|
2775
2844
|
recoverStateOnReconnect;
|
|
2845
|
+
/** True when the SDK is executed in a NodeJS environment constraint. */
|
|
2776
2846
|
node;
|
|
2847
|
+
/** Custom options passed during client initialization. */
|
|
2777
2848
|
options;
|
|
2778
2849
|
setUserPromise;
|
|
2850
|
+
/** Centralized global state orchestrating user and client metadata. */
|
|
2779
2851
|
state;
|
|
2780
2852
|
tokenManager;
|
|
2853
|
+
/** The globally authenticated current user object. */
|
|
2781
2854
|
user;
|
|
2782
2855
|
userAgent;
|
|
2856
|
+
/** The unique ID of the current authenticated user. */
|
|
2783
2857
|
userID;
|
|
2858
|
+
/** The configured WebSocket endpoint base URL for realtime subscriptions. */
|
|
2784
2859
|
wsBaseURL;
|
|
2860
|
+
/** The active WebSocket connection controller. */
|
|
2785
2861
|
wsConnection;
|
|
2786
2862
|
wsPromise;
|
|
2863
|
+
/** Tracks consecutive REST API failures for exponential backoff purposes. */
|
|
2787
2864
|
consecutiveFailures;
|
|
2788
2865
|
defaultWSTimeout;
|
|
2789
2866
|
eventSource = null;
|
|
2867
|
+
/**
|
|
2868
|
+
* Initializes a new Ermis Chat Client instance.
|
|
2869
|
+
*
|
|
2870
|
+
* @param apiKey - Your public Ermis Network API Key.
|
|
2871
|
+
* @param projectId - Your specific Project UUID pointing to the app config.
|
|
2872
|
+
* @param baseURL - The API base endpoint assigned to your project.
|
|
2873
|
+
* @param options - Additional connection rules and configuration options.
|
|
2874
|
+
*/
|
|
2790
2875
|
constructor(apiKey, projectId, baseURL, options) {
|
|
2791
2876
|
this.apiKey = apiKey;
|
|
2792
2877
|
this.projectId = projectId;
|
|
@@ -2820,6 +2905,16 @@ var ErmisChat = class _ErmisChat {
|
|
|
2820
2905
|
this.logger = isFunction(inputOptions.logger) ? inputOptions.logger : () => null;
|
|
2821
2906
|
this.recoverStateOnReconnect = this.options.recoverStateOnReconnect;
|
|
2822
2907
|
}
|
|
2908
|
+
/**
|
|
2909
|
+
* Retrieves the globally registered Singleton instance of the ErmisChat client.
|
|
2910
|
+
* If the instance lacks existence, it initializes a new one.
|
|
2911
|
+
*
|
|
2912
|
+
* @param key - Your public Ermis Network API Key.
|
|
2913
|
+
* @param projectId - Your specific Project UUID.
|
|
2914
|
+
* @param baseURL - The API base endpoint.
|
|
2915
|
+
* @param options - Connection options.
|
|
2916
|
+
* @returns The shared ErmisChat client instance.
|
|
2917
|
+
*/
|
|
2823
2918
|
static getInstance(key, projectId, baseURL, options) {
|
|
2824
2919
|
if (!_ErmisChat._instance) {
|
|
2825
2920
|
_ErmisChat._instance = new _ErmisChat(key, projectId, baseURL, options);
|
|
@@ -2867,6 +2962,15 @@ var ErmisChat = class _ErmisChat {
|
|
|
2867
2962
|
}
|
|
2868
2963
|
return await response.json();
|
|
2869
2964
|
}
|
|
2965
|
+
/**
|
|
2966
|
+
* Connects a user to the Ermis network and establishes the WebSocket connection.
|
|
2967
|
+
* This is the primary method to authenticate your client application.
|
|
2968
|
+
*
|
|
2969
|
+
* @param user - The User object containing `id`, `name`, and optional `avatar`.
|
|
2970
|
+
* @param userTokenOrProvider - The JWT token or an async token provider function.
|
|
2971
|
+
* @param extenal_auth - Set to `true` to use your custom backend external authentication flow.
|
|
2972
|
+
* @returns A promise resolving to the API connection response once authenticated.
|
|
2973
|
+
*/
|
|
2870
2974
|
connectUser = async (user, userTokenOrProvider, extenal_auth) => {
|
|
2871
2975
|
this.logger("info", "client:connectUser() - started", {
|
|
2872
2976
|
tags: ["connection", "client"]
|
|
@@ -2949,6 +3053,12 @@ var ErmisChat = class _ErmisChat {
|
|
|
2949
3053
|
return this.wsPromise;
|
|
2950
3054
|
};
|
|
2951
3055
|
_setupConnection = this.openConnection;
|
|
3056
|
+
/**
|
|
3057
|
+
* Gracefully disconnects the current user, terminates the WebSocket connection,
|
|
3058
|
+
* cleans up listeners, and resets the client's internal references.
|
|
3059
|
+
*
|
|
3060
|
+
* @param timeout - Optional timeout in milliseconds before forcing the disconnect.
|
|
3061
|
+
*/
|
|
2952
3062
|
disconnectUser = async (timeout) => {
|
|
2953
3063
|
this.logger("info", "client:disconnect() - Disconnecting the client", {
|
|
2954
3064
|
tags: ["connection", "client"]
|
|
@@ -3514,6 +3624,16 @@ var ErmisChat = class _ErmisChat {
|
|
|
3514
3624
|
this.state.updateUser(response);
|
|
3515
3625
|
return response;
|
|
3516
3626
|
}
|
|
3627
|
+
/**
|
|
3628
|
+
* Queries the API for a list of channels based on provided search filters and sort conditions.
|
|
3629
|
+
* Also hydrates these channels into the local SDK state memory.
|
|
3630
|
+
*
|
|
3631
|
+
* @param filterConditions - Specific criteria to filter channels (e.g. `{ type: 'messaging', members: { $in: ['user1'] } }`).
|
|
3632
|
+
* @param sort - The sorting hierarchy applied to the channel results.
|
|
3633
|
+
* @param options - Pagination and message limit parameters.
|
|
3634
|
+
* @param stateOptions - Defines whether to skip state initialization or offline usage.
|
|
3635
|
+
* @returns An array of hydrated and locally manageable `Channel` objects.
|
|
3636
|
+
*/
|
|
3517
3637
|
async queryChannels(filterConditions, sort = [], options = {}, stateOptions = {}) {
|
|
3518
3638
|
await this.wsPromise;
|
|
3519
3639
|
let project_id = this.projectId;
|
|
@@ -3665,7 +3785,7 @@ var ErmisChat = class _ErmisChat {
|
|
|
3665
3785
|
return pinExpires;
|
|
3666
3786
|
}
|
|
3667
3787
|
getUserAgent() {
|
|
3668
|
-
return this.userAgent || `ermis-chat-sdk-javascript-client-${this.node ? "node" : "browser"}-${"1.0.
|
|
3788
|
+
return this.userAgent || `ermis-chat-sdk-javascript-client-${this.node ? "node" : "browser"}-${"1.0.5"}`;
|
|
3669
3789
|
}
|
|
3670
3790
|
setUserAgent(userAgent) {
|
|
3671
3791
|
this.userAgent = userAgent;
|
|
@@ -3781,7 +3901,6 @@ var EVENT_MAP = {
|
|
|
3781
3901
|
};
|
|
3782
3902
|
|
|
3783
3903
|
// src/wasm/ermis_call_node_wasm.js
|
|
3784
|
-
var import_meta = {};
|
|
3785
3904
|
var wasm;
|
|
3786
3905
|
var cachedUint8ArrayMemory0 = null;
|
|
3787
3906
|
function getUint8ArrayMemory0() {
|
|
@@ -5189,7 +5308,7 @@ async function __wbg_init(module_or_path) {
|
|
|
5189
5308
|
}
|
|
5190
5309
|
}
|
|
5191
5310
|
if (typeof module_or_path === "undefined") {
|
|
5192
|
-
module_or_path =
|
|
5311
|
+
module_or_path = "/ermis_call_node_wasm_bg.wasm";
|
|
5193
5312
|
}
|
|
5194
5313
|
const imports = __wbg_get_imports();
|
|
5195
5314
|
if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) {
|
|
@@ -7025,7 +7144,7 @@ var ErmisAuthProvider = class {
|
|
|
7025
7144
|
return data;
|
|
7026
7145
|
}
|
|
7027
7146
|
getUserAgent() {
|
|
7028
|
-
return this.userAgent || `ermis-chat-sdk-javascript-client-${this.node ? "node" : "browser"}-${"1.0.
|
|
7147
|
+
return this.userAgent || `ermis-chat-sdk-javascript-client-${this.node ? "node" : "browser"}-${"1.0.5"}`;
|
|
7029
7148
|
}
|
|
7030
7149
|
setUserAgent(userAgent) {
|
|
7031
7150
|
this.userAgent = userAgent;
|