@poolse/sdk 2.0.3 → 2.0.6

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/README.md CHANGED
@@ -103,12 +103,14 @@ chat.conversations.one(id): ConversationHandle;
103
103
  name?: string | null;
104
104
  avatar_url?: string | null;
105
105
  member_limit?: number | null;
106
- member_external_ids?: string[]; // your IDs; poolse looks them up by tenant
106
+ member_external_ids?: string[];
107
107
  custom_data?: Record<string, unknown>;
108
108
  settings?: Record<string, unknown>;
109
109
  }
110
110
  ```
111
111
 
112
+ `member_external_ids` is your tenant's own ids — poolse looks them up by tenant and lazily provisions any that don't exist yet. The returned `Conversation` carries `member_external_ids` (the array of external_ids for every member) and `last_message_preview` (server-denormalized first ~80 chars of the most recent message body, used to render inbox rows without a per-row decrypt round-trip).
113
+
112
114
  `ConversationHandle` (returned by `chat.conversations.one(id)`):
113
115
 
114
116
  ```ts
@@ -300,11 +302,16 @@ Payload shapes are exact:
300
302
  Returned by `chat.realtime.user(id)`. Only the user matching the JWT can join their own channel — the server rejects other ids.
301
303
 
302
304
  ```ts
303
- channel.onMention(fn): Unsubscribe; // mention:new
304
- channel.onConversationCreated(fn): Unsubscribe; // conversation:created
305
+ channel.onMention(fn): Unsubscribe;
306
+ channel.onConversationCreated(fn): Unsubscribe;
307
+ channel.onConversationUpdated(fn): Unsubscribe;
305
308
  ```
306
309
 
307
- `mention:new` carries `{ message_id, conversation_id, sender_id }` — fetch the full message via REST if you need the body. `conversation:created` fires whenever the user is added to a conversation (including ones they created themselves) and carries the full `Conversation`.
310
+ `onMention` corresponds to the `mention:new` push and carries `{ message_id, conversation_id, sender_id }` — fetch the full message via REST if you need the body.
311
+
312
+ `onConversationCreated` corresponds to the `conversation:created` push, which fires whenever the user is added to a conversation (including ones they created themselves) and carries the full `Conversation` row with `member_external_ids` preloaded.
313
+
314
+ `onConversationUpdated` corresponds to the `conversation:updated` push and fires after every message sent in any of the user's conversations. Payload shape is `{ conversation: Conversation, by_user_id: Uuid | null }` — `by_user_id` is the sender's id, so a client can avoid bumping its own unread when the server already advanced its read cursor in the same transaction. The `conversation` carries the freshly written `last_message_preview`, `last_message_at`, and `last_sequence` so an inbox UI can update without a refetch.
308
315
 
309
316
  ## Token caching
310
317
 
package/dist/index.cjs CHANGED
@@ -4,26 +4,16 @@ var phoenix = require('phoenix');
4
4
 
5
5
  // src/uuid.ts
6
6
  function safeUuid() {
7
- try {
8
- const c = globalThis.crypto;
9
- if (c && typeof c.randomUUID === "function") {
10
- const out = c.randomUUID();
11
- if (typeof out === "string") return out;
12
- }
13
- if (c && typeof c.getRandomValues === "function") {
14
- const bytes = new Uint8Array(16);
15
- c.getRandomValues(bytes);
16
- return formatV4(bytes);
7
+ const c = globalThis.crypto;
8
+ if (c?.randomUUID) return c.randomUUID();
9
+ const bytes = new Uint8Array(16);
10
+ if (c?.getRandomValues) {
11
+ c.getRandomValues(bytes);
12
+ } else {
13
+ for (let i = 0; i < 16; i++) {
14
+ bytes[i] = Math.floor(Math.random() * 256);
17
15
  }
18
- } catch {
19
16
  }
20
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (ch) => {
21
- const r = Math.random() * 16 | 0;
22
- const v = ch === "x" ? r : r & 3 | 8;
23
- return v.toString(16);
24
- });
25
- }
26
- function formatV4(bytes) {
27
17
  bytes[6] = bytes[6] & 15 | 64;
28
18
  bytes[8] = bytes[8] & 63 | 128;
29
19
  const hex = [];
@@ -368,8 +358,10 @@ var UserChannel = class {
368
358
  channel;
369
359
  mentionListeners = /* @__PURE__ */ new Set();
370
360
  conversationCreatedListeners = /* @__PURE__ */ new Set();
361
+ conversationUpdatedListeners = /* @__PURE__ */ new Set();
371
362
  mentionBound = false;
372
363
  conversationCreatedBound = false;
364
+ conversationUpdatedBound = false;
373
365
  constructor(userId, channel) {
374
366
  this.userId = userId;
375
367
  this.channel = channel;
@@ -406,6 +398,28 @@ var UserChannel = class {
406
398
  this.conversationCreatedListeners.delete(fn);
407
399
  };
408
400
  }
401
+ /**
402
+ * Subscribe to "an existing conversation changed" notifications —
403
+ * fires after every `send_message` in any conversation you're a
404
+ * member of. Use this to update the conversation-list row's last
405
+ * message preview, timestamp, and unread badge without polling.
406
+ *
407
+ * Compare `evt.by_user_id` to your own user id to decide whether
408
+ * to increment a local unread counter; the server already keeps
409
+ * your own outbound messages out of your unread count.
410
+ */
411
+ onConversationUpdated(fn) {
412
+ if (!this.conversationUpdatedBound) {
413
+ this.conversationUpdatedBound = true;
414
+ this.channel.on("conversation:updated", (payload) => {
415
+ this.conversationUpdatedListeners.forEach((l) => l(payload));
416
+ });
417
+ }
418
+ this.conversationUpdatedListeners.add(fn);
419
+ return () => {
420
+ this.conversationUpdatedListeners.delete(fn);
421
+ };
422
+ }
409
423
  /** @internal */
410
424
  _join() {
411
425
  this.channel.join();
@@ -414,6 +428,7 @@ var UserChannel = class {
414
428
  _destroy() {
415
429
  this.mentionListeners.clear();
416
430
  this.conversationCreatedListeners.clear();
431
+ this.conversationUpdatedListeners.clear();
417
432
  this.channel.leave();
418
433
  }
419
434
  };
@@ -1191,7 +1206,7 @@ var Poolse = class {
1191
1206
  };
1192
1207
 
1193
1208
  // src/version.ts
1194
- var version = "2.0.3";
1209
+ var version = "2.0.2";
1195
1210
 
1196
1211
  exports.ApiError = ApiError;
1197
1212
  exports.AttachmentHandle = AttachmentHandle;