@devanachat/sdk 0.11.0 → 0.13.0

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/README.md +15 -7
  3. package/build/index.cjs.js +436 -144
  4. package/build/index.cjs.js.map +1 -1
  5. package/build/index.mjs +436 -145
  6. package/build/index.mjs.map +1 -1
  7. package/build/index.umd.js +1 -1
  8. package/build/index.umd.js.map +1 -1
  9. package/build/types/AbstractChatClient.d.ts +18 -3
  10. package/build/types/Permissions.d.ts +5 -1
  11. package/build/types/WebSocketChatClient.d.ts +29 -2
  12. package/build/types/index.d.ts +2 -2
  13. package/build/types/protocol/index.d.ts +15 -3
  14. package/build/types/protocol/schemes/Message.d.ts +4 -0
  15. package/build/types/protocol/schemes/MessageEmbed.d.ts +83 -0
  16. package/build/types/protocol/schemes/commands/AckInteraction.d.ts +10 -0
  17. package/build/types/protocol/schemes/commands/CreateMessage.d.ts +9 -0
  18. package/build/types/protocol/schemes/commands/GetGifCategories.d.ts +3 -0
  19. package/build/types/protocol/schemes/commands/GetMessages.d.ts +1 -0
  20. package/build/types/protocol/schemes/commands/Interact.d.ts +5 -0
  21. package/build/types/protocol/schemes/commands/SearchGifs.d.ts +5 -0
  22. package/build/types/protocol/schemes/commands/UpdateMessage.d.ts +8 -0
  23. package/build/types/protocol/schemes/events/Bye.d.ts +1 -0
  24. package/build/types/protocol/schemes/events/Error.d.ts +1 -0
  25. package/build/types/protocol/schemes/events/FoundGifs.d.ts +14 -0
  26. package/build/types/protocol/schemes/events/GifCategories.d.ts +8 -0
  27. package/build/types/protocol/schemes/events/Interacted.d.ts +4 -0
  28. package/build/types/protocol/schemes/events/InteractionResolved.d.ts +7 -0
  29. package/build/types/protocol/schemes/events/MessageUpdated.d.ts +6 -0
  30. package/build/types/protocol/schemes/events/Messages.d.ts +6 -2
  31. package/build/types/protocol/schemes/events/NewInteraction.d.ts +10 -0
  32. package/build/types/protocol/schemes/events/NewMessage.d.ts +3 -0
  33. package/build/types/state-tracker/RoomMessagesHistory.d.ts +7 -2
  34. package/build/types/state-tracker/RoomsManager.d.ts +12 -1
  35. package/build/types/state-tracker/StateSnapshot.d.ts +5 -1
  36. package/build/types/state-tracker/TopicHistoryWindow.d.ts +29 -2
  37. package/build/types/state-tracker/functions.d.ts +8 -1
  38. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -6,6 +6,91 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.13.0]
10
+
11
+ ### Added
12
+
13
+ - `CreateMessage.allowedMentions` (`MessageMentions`): limits the users and roles the message mentions - empty lists
14
+ mention no one.
15
+
16
+ ### Changed
17
+
18
+ - Reconnecting spreads the clients dropped together: a retry waits a random time between 0 and the backoff delay
19
+ (it used to be 50-100% of it). After a closure by the server (close code 1001, 1012 or 1013, or after a `Bye`) the backoff
20
+ starts at `reconnect.serverCloseMinDelayMs` (5 s by default) instead of `reconnect.minDelayMs` (1 s). The backoff
21
+ starts over once a connection has stayed authenticated for `reconnect.stableConnectionMs` (30 s by default),
22
+ not as soon as it authenticates.
23
+ - `connectingTimeoutMs` (10 s) limits only the time until the socket opens. An open socket waits for `Session` up to
24
+ the new `sessionTimeoutMs` (60 s by default), so a client the server holds in its queue during a reconnect storm is
25
+ no longer dropped and sent back to the end of it.
26
+
27
+ ### Fixed
28
+
29
+ - A `Bye` with the `Service` reason (the server shutting down) is followed by a reconnect even when the server closes
30
+ the connection with code 1000; the client used to stop. `Bye` is emitted first, then `disconnect` with `true`; a
31
+ `connect()` still waiting for `Session` stays pending for the retry. Other `Bye` reasons behave as before.
32
+ - `Bye.retryAfterMs`: when the server sends it, the next reconnect waits that long instead of the backoff delay, without
33
+ further jitter; values that are not positive finite numbers are ignored and longer ones are capped at 60 s.
34
+ - A `Bye` with the `ServiceUnavailableException` error (the server too busy to take the connection) is followed by a
35
+ reconnect, like a `Service` one, instead of being treated as a rejected token: no `error` event, a pending
36
+ `connect()` stays pending for the retry. `AuthenticationException` still stops reconnecting.
37
+ - `disconnect()` called by a listener of the message being received (e.g. of `Session`, to refuse the protocol
38
+ version, or of `Bye`) is final: the client no longer authenticates the closed connection, emits `connect` or
39
+ schedules a retry afterwards, and emits `disconnect` once.
40
+
41
+ ## [0.12.0]
42
+
43
+ ### Added
44
+
45
+ - Editing messages: the `UpdateMessage` command (`{messageId, content?, embed?}` - a field left out stays, `embed: null`
46
+ removes the embed and hides a link preview for good; resolves with `MessageUpdated` or `Ok` when nothing changed), the `MessageUpdated` event carrying the whole message,
47
+ `Message.editedAt` (set only by an edit of the content) and the `EditMessages` permission (`1 << 29`, topic layer).
48
+ History windows replace the loaded message, also where they keep it as a replied one; the topics tracked by
49
+ `RoomsManager` replace it when it is their last or sticky message or the original message of a side topic.
50
+ - Replies: `CreateMessage.replyTo` and `Message.replyTo` (the id of the replied message). The replied messages come
51
+ beside the replies: in `Messages.repliedMessages` when `GetMessages.includeRepliedMessages` is set, and in
52
+ `NewMessage.repliedMessage`. History windows fetch them by default (`includeRepliedMessages`), keep them up to date
53
+ and return them with `getRepliedMessage(message)` - `null` once the replied message is deleted, `undefined` in a
54
+ window without `includeRepliedMessages` when the replied message is not loaded.
55
+ - Embeds: `Message.embed` (`MessageEmbed` - `type` `Link`, `Video`, `Gif` or `Rich`, a `root` list of components and
56
+ `flags`, see `MessageEmbedFlag`). The server builds `Link`, `Video` and `Gif` from the first link of a message and
57
+ attaches them with `MessageUpdated`; bots send `Rich` ones with `CreateMessage.embed` / `UpdateMessage.embed`
58
+ (`SendableEmbed`). `UpdateMessage` with `embed: null` hides a generated embed.
59
+ - Embed interactions: the `Interact` command (`{messageId, actionId, value?}`, resolves with `Interacted`
60
+ carrying the `interactionId`) uses a button or select of a message's embed; the author of the message (a bot) gets
61
+ the `NewInteraction` event (`{interactionId, location, messageId, user, actionId, value}`). Nothing is stored. The id
62
+ ties a later answer of the bot (such as a dialog) to the interaction and the client it came from.
63
+ - Answering interactions: a bot answers within 15 s with `CreateMessage.interactionId` or `UpdateMessage.interactionId`
64
+ (the resulting `NewMessage` / `MessageUpdated` carries the `interactionId`), or with `AckInteraction`
65
+ (`{interactionId, status?: 'Ok' | 'Fail', notice?}`). The user who interacted gets `InteractionResolved`
66
+ (`{interactionId, status, notice}`) for an `AckInteraction`, for an edit that changed nothing and, with the `Timeout`
67
+ status, when nothing came in time.
68
+ - Ephemeral bot messages: `CreateMessage.ephemeralFor` (a user id) shows the message only to that room member, as
69
+ `NewMessage` of the `Ephemeral` type, and resolves with `Ok`; it is not stored, takes no attachments or poll, may
70
+ reply to a message and mention its recipient (through `allowedMentions`, without a push). A recipient taking no
71
+ private messages at all does not get it. `RoomsManager` no longer counts `Ephemeral` messages nor makes them the last one of a topic.
72
+ - GIF search: the `SearchGifs` command (`{query, position?, locale?}`) resolving with `FoundGifs` (`{gifs, next}`, each
73
+ `FoundGif` with its post `url`, size, poster and MP4/WebM sources; pass `next` as `position` for the following page),
74
+ and the `GetGifCategories` command (`{locale?}`) resolving with `GifCategories` (`{categories}`, each `GifCategory`
75
+ with the search `term`, its English `name` and an `imageUrl`). Available when the server runs GIF search.
76
+ - Reactions of sticky messages: `RoomsManager.getStickyMyReactions(location, messageId)` returns the reactions of the
77
+ connected user on sticky messages (`MessageUserReactions`, keyed by message id) - fetched once per message with `GetMessages` (`around`,
78
+ `limit: 1`, `includeMyReactions`), as a sticky message comes with its topic, then kept up to date with `Reacted`.
79
+ The topics tracked by `RoomsManager` follow the reaction counters of their sticky message with `ReactionUpdated`.
80
+
81
+ ### Changed
82
+
83
+ - **Breaking:** `Messages.myReactions` is a list of `MessageUserReactions` (`{messageId, reactions}`) instead of a map
84
+ keyed by message id, so this version needs a server sending the list; `TopicHistoryWindow.myReactions` keeps the map.
85
+ - **Breaking:** the `RedactMessages` permission is `ManageMessages` (the same bit, `1 << 19`; the `RedactMessages`
86
+ command keeps its name). Besides deleting messages it lets `UpdateMessage` with `embed: null` hide a preview
87
+ generated by the server in any message.
88
+ - State snapshots: version 3 (with the replied messages of the saved histories); older snapshots are rejected.
89
+ - `React` with a reaction the user already has fails with `ReactionExistsAlreadyException`; `Unreact` of a reaction the
90
+ user does not have resolves with `Ok`. Both used to get no answer.
91
+
92
+ ## [0.11.0]
93
+
9
94
  ### Added
10
95
 
11
96
  - Typing notifications: the `Type` command and the `Typing` event (`{location, userId}`), for rooms other than
package/README.md CHANGED
@@ -140,7 +140,7 @@ client.on('NewMessage', async ({message}) => {
140
140
  return;
141
141
  }
142
142
 
143
- const {hasAll} = await client.state!.permissions.check(['RedactMessages'], message.location);
143
+ const {hasAll} = await client.state!.permissions.check(['ManageMessages'], message.location);
144
144
 
145
145
  if (hasAll) {
146
146
  await client.send('RedactMessages', {messageId: message.id});
@@ -161,19 +161,27 @@ client.on('NewMessage', async ({message}) => {
161
161
  ## Connection maintenance
162
162
 
163
163
  `WebSocketChatClient` keeps the connection alive: after any loss (error, connecting timeout, missing pong, closure with
164
- a code other than 1000) it reconnects indefinitely, with an exponential backoff between attempts. The `disconnect` event
164
+ a code other than 1000) it reconnects indefinitely, waiting a random time up to an exponentially growing delay between
165
+ attempts. The backoff starts higher when the server closed the connection than after a network drop, and starts over
166
+ once a connection has been stable for a while. The `disconnect` event
165
167
  tells whether a retry follows. A pending `connect()` promise resolves once an attempt authenticates, and is rejected by
166
168
  `disconnect()`, which also stops reconnecting. An invalid token (`Bye` with `AuthenticationException`) rejects `connect()`
167
- with the `Bye` data, emits an `error` event and stops reconnecting as well.
169
+ with the `Bye` data, emits an `error` event and stops reconnecting as well. A `Bye` with the `Service` reason (the server
170
+ going down) or with `ServiceUnavailableException` (the server overloaded) is always followed by a retry, emitted as
171
+ `Bye` and then `disconnect` with `true`, whatever the close code.
172
+ When a `Bye` carries `retryAfterMs`, the next retry waits that long (at most 60 s) instead of the backoff delay.
168
173
 
169
174
  ```ts
170
175
  const client = new WebSocketChatClient({
171
176
  url: 'wss://s1.devana.pl:1600/ws',
172
177
  token: 'your-access-token',
173
- connectingTimeoutMs: 10000, // Per attempt (default)
178
+ connectingTimeoutMs: 10000, // Until the socket opens (default)
179
+ sessionTimeoutMs: 60000, // Until Session arrives on an open socket; the server may queue connections (default)
174
180
  reconnect: {
175
- minDelayMs: 1000, // Delay before the first retry, doubled on every next one (default)
176
- maxDelayMs: 30000, // Maximum delay between retries (default)
181
+ minDelayMs: 1000, // Limit of the first delay after a lost connection, doubled on every next one (default)
182
+ serverCloseMinDelayMs: 5000, // The same after a closure by the server: 1001, 1012, 1013 or a Bye (default)
183
+ maxDelayMs: 30000, // Maximum delay between retries; a higher minimum delay wins over it (default)
184
+ stableConnectionMs: 30000, // A connection lasting this long starts the backoff over (default)
177
185
  },
178
186
  ping: {
179
187
  noActivityTimeoutMs: 15000, // Send a ping after this much silence (default)
@@ -216,7 +224,7 @@ because some structures are rebuilt from scratch on the `Session` event.
216
224
  | Manager | What it gives you |
217
225
  |---|---|
218
226
  | `state.spaces` | Your spaces; per space: `getRooms()`, `getMembers()`, `getRoles()`, `getMe()` |
219
- | `state.rooms` | Rooms you are in; per room: `getMembers()`, `getTopics()`, `getMe()` |
227
+ | `state.rooms` | Rooms you are in; per room: `getMembers()`, `getTopics()`, `getMe()`; your reactions on a sticky message (`Topic.stickyMessage`): `getStickyMyReactions()` |
220
228
  | `state.rooms.messages` | Message history windows per topic |
221
229
  | `state.rooms.followedTopics` | Unread counters and mentions, marking rooms as read |
222
230
  | `state.permissions` | Your effective permissions in any location |