@pmate/chat-sdk 0.12.0-next.21 → 0.12.0-next.23

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.
@@ -140,12 +140,15 @@ export class ChatSession {
140
140
  /** One-time migration only: never establishes trusted history coverage. */
141
141
  importLegacyMessages(threadId, messages) { this.assertOpen(); return this.messages.importLegacy(threadId, messages); }
142
142
  getReadingSnapshot() { return this.closed || this.withdrawn ? undefined : this.reading.getSnapshot(); }
143
- subscribeReading(listener) { this.assertOpen(); return this.reading.subscribe(listener); }
143
+ subscribeReading(listener) { if (this.closed || this.withdrawn)
144
+ return () => { }; return this.reading.subscribe(listener); }
144
145
  refreshReading() { this.assertOpen(); this.reading.refresh(); }
145
146
  synchronizeReading(cursor, profileId) { this.assertOpen(); return this.reading.synchronize(cursor, profileId); }
146
147
  /** Explicit text-history acknowledgement; unheard audio stays unread. */
147
- markRead(threadId, messages = []) { this.assertOpen(); return this.reading.markRead(threadId, messages); }
148
- updateReading(transform) { this.assertOpen(); return this.reading.update(transform); }
148
+ markRead(threadId, messages = []) { this.assertOpen(); return this.reading.markRead(threadId, messages).then(next => { if (this.withdrawn)
149
+ throw new Error("CHAT_ACCESS_REVOKED"); return next; }); }
150
+ updateReading(transform) { this.assertOpen(); return this.reading.update(transform).then(next => { if (this.withdrawn)
151
+ throw new Error("CHAT_ACCESS_REVOKED"); return next; }); }
149
152
  assertOpen() { if (this.withdrawn)
150
153
  throw new Error("CHAT_ACCESS_REVOKED"); if (this.closed)
151
154
  throw new Error("CHAT_SESSION_CLOSED"); }
@@ -170,6 +173,7 @@ export class ChatSession {
170
173
  await this.sender.confirm(page.messages.map(message => message.id));
171
174
  if (this.initializing && !this.readingStarted && page.complete)
172
175
  await this.startReading();
176
+ this.assertOpen();
173
177
  const edge = this.historyEdges.get(threadId);
174
178
  if (!options.before && page.complete && (!edge || edge.version !== page.resetVersion))
175
179
  this.rememberHistoryEdge(threadId, page);
@@ -230,6 +234,7 @@ export class ChatSession {
230
234
  return { messages: pages.reverse().flat(), hasEarlier: false, complete: true, resetVersion: version };
231
235
  }
232
236
  catch (error) {
237
+ this.assertOpen();
233
238
  if ([401, 403].includes(error?.status ?? 0))
234
239
  throw error;
235
240
  if (String(error).includes("MESSAGE_PROJECTION_CHANGED"))
@@ -243,7 +248,8 @@ export class ChatSession {
243
248
  }
244
249
  sendMessage(threadId, input) {
245
250
  this.assertOpen();
246
- return this.sender.enqueue(threadId, input);
251
+ return this.sender.enqueue(threadId, input).then(next => { if (this.withdrawn)
252
+ throw new Error("CHAT_ACCESS_REVOKED"); return next; });
247
253
  }
248
254
  async getReaders(threadId, messageId, page = {}, signal) {
249
255
  this.assertOpen();
@@ -260,16 +266,18 @@ export class ChatSession {
260
266
  }
261
267
  retryMessage(messageId) { this.assertOpen(); return this.sender.retry(messageId); }
262
268
  observeMessages(threadId, ids, event, clientInstanceId) {
263
- if (this.closed && event === "receipts" && !threadId)
264
- return Promise.resolve();
265
- this.assertOpen();
269
+ if (this.closed || this.withdrawn) {
270
+ if (event === "receipts" && !threadId)
271
+ return Promise.resolve();
272
+ return Promise.reject(new Error(this.withdrawn ? "CHAT_ACCESS_REVOKED" : "CHAT_SESSION_CLOSED"));
273
+ }
266
274
  if (event === "receipts") {
267
275
  this.watchCounts(threadId, ids, clientInstanceId);
268
276
  return Promise.resolve();
269
277
  }
270
278
  if (!threadId)
271
279
  throw new Error("INVALID_READING_THREAD");
272
- return event === "played" ? this.reading.recordExplicit(threadId, ids) : this.reading.recordVisible(threadId, ids);
280
+ return (event === "played" ? this.reading.recordExplicit(threadId, ids) : this.reading.recordVisible(threadId, ids)).then(next => { this.assertOpen(); return next; });
273
281
  }
274
282
  /** Bridge transports can delegate social events without maintaining clients. */
275
283
  async handleReach(event) {
@@ -377,7 +385,8 @@ export class ChatSession {
377
385
  return snapshot;
378
386
  }
379
387
  subscribe(target, listener, fields) {
380
- this.assertOpen();
388
+ if (this.closed || this.withdrawn)
389
+ return () => { };
381
390
  if (typeof target === "function") {
382
391
  this.globalListeners.add(target);
383
392
  return () => { this.globalListeners.delete(target); };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmate/chat-sdk",
3
- "version": "0.12.0-next.21",
3
+ "version": "0.12.0-next.23",
4
4
  "description": "Cross-platform PMate chat input components, voice input primitives, and ASR helpers",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",