isometrik-plugin-chat-sdk 2.0.18 → 2.0.19

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 (43) hide show
  1. package/dist/cjs/{client-80851676.js → client-fef5fd3d.js} +29 -1
  2. package/dist/cjs/client-fef5fd3d.js.map +1 -0
  3. package/dist/cjs/index.cjs.js +1 -1
  4. package/dist/cjs/login-page_3.cjs.entry.js +37 -11
  5. package/dist/cjs/login-page_3.cjs.entry.js.map +1 -1
  6. package/dist/collection/components/my-component/web-chat/data-fetch.js +9 -3
  7. package/dist/collection/components/my-component/web-chat/data-fetch.js.map +1 -1
  8. package/dist/collection/components/my-component/web-chat/mutations.js +7 -2
  9. package/dist/collection/components/my-component/web-chat/mutations.js.map +1 -1
  10. package/dist/collection/components/my-component/web-chat/offline-host.js +21 -5
  11. package/dist/collection/components/my-component/web-chat/offline-host.js.map +1 -1
  12. package/dist/collection/lib/offline/client.js +11 -0
  13. package/dist/collection/lib/offline/client.js.map +1 -1
  14. package/dist/collection/lib/offline/idb.js +11 -0
  15. package/dist/collection/lib/offline/idb.js.map +1 -1
  16. package/dist/collection/lib/offline/memory-db.js +6 -0
  17. package/dist/collection/lib/offline/memory-db.js.map +1 -1
  18. package/dist/components/WebChat.js +36 -10
  19. package/dist/components/WebChat.js.map +1 -1
  20. package/dist/components/client.js +28 -0
  21. package/dist/components/client.js.map +1 -1
  22. package/dist/esm/{client-4a3e00da.js → client-de7fbead.js} +29 -1
  23. package/dist/esm/client-de7fbead.js.map +1 -0
  24. package/dist/esm/index.js +1 -1
  25. package/dist/esm/login-page_3.entry.js +37 -11
  26. package/dist/esm/login-page_3.entry.js.map +1 -1
  27. package/dist/isometrik-webchat/index.esm.js +1 -1
  28. package/dist/isometrik-webchat/isometrik-webchat.esm.js +1 -1
  29. package/dist/isometrik-webchat/p-f0d4687f.js +2 -0
  30. package/dist/isometrik-webchat/p-f0d4687f.js.map +1 -0
  31. package/dist/isometrik-webchat/p-fc3fd090.entry.js +2 -0
  32. package/dist/isometrik-webchat/p-fc3fd090.entry.js.map +1 -0
  33. package/dist/types/components/my-component/web-chat/offline-host.d.ts +2 -0
  34. package/dist/types/lib/offline/client.d.ts +2 -0
  35. package/dist/types/lib/offline/idb.d.ts +2 -0
  36. package/dist/types/lib/offline/memory-db.d.ts +1 -0
  37. package/package.json +1 -1
  38. package/dist/cjs/client-80851676.js.map +0 -1
  39. package/dist/esm/client-4a3e00da.js.map +0 -1
  40. package/dist/isometrik-webchat/p-ae168135.js +0 -2
  41. package/dist/isometrik-webchat/p-ae168135.js.map +0 -1
  42. package/dist/isometrik-webchat/p-ceb08a13.entry.js +0 -2
  43. package/dist/isometrik-webchat/p-ceb08a13.entry.js.map +0 -1
@@ -932,8 +932,9 @@ function hostInitOffline(host) {
932
932
  client.setUser(uid);
933
933
  client.startTabSync(event => {
934
934
  var _a;
935
+ // Snapshot from peer tab (incl. clear → []) — do not merge or wiped msgs return.
935
936
  if (event.type === 'messages' && event.conversationId === host.selectedConversationId) {
936
- host.allMessages = mergeMessagesById(host.allMessages || [], event.messages || []);
937
+ host.allMessages = Array.isArray(event.messages) ? event.messages : [];
937
938
  }
938
939
  if (event.type === 'conversations') {
939
940
  // Prefer newer network list; only fill gaps from peer tab
@@ -1000,14 +1001,16 @@ async function hostPersistConversations(host) {
1000
1001
  }
1001
1002
  }
1002
1003
  async function hostPersistMessages(host, conversationId) {
1003
- var _a;
1004
1004
  const uid = userIdOf(host);
1005
1005
  const id = conversationId || host.selectedConversationId;
1006
- if (!uid || !id || !((_a = host.allMessages) === null || _a === void 0 ? void 0 : _a.length))
1006
+ if (!uid || !id)
1007
1007
  return;
1008
1008
  try {
1009
- await getOfflineClient().persistMessages(uid, id, host.allMessages);
1010
- const last = host.allMessages[host.allMessages.length - 1];
1009
+ const list = Array.isArray(host.allMessages) ? host.allMessages : [];
1010
+ await getOfflineClient().persistMessages(uid, id, list);
1011
+ if (!list.length)
1012
+ return;
1013
+ const last = list[list.length - 1];
1011
1014
  const cursor = (last === null || last === void 0 ? void 0 : last.sentAt) || (last === null || last === void 0 ? void 0 : last.updatedAt) || Date.now();
1012
1015
  await getOfflineClient().setCursor(uid, id, cursor);
1013
1016
  }
@@ -1015,6 +1018,19 @@ async function hostPersistMessages(host, conversationId) {
1015
1018
  console.error('offline persist messages failed', e);
1016
1019
  }
1017
1020
  }
1021
+ /** Wipe IndexedDB thread cache after clear-chat so hydrate cannot resurrect msgs. */
1022
+ async function hostClearCachedMessages(host, conversationId) {
1023
+ const uid = userIdOf(host);
1024
+ const id = conversationId || host.selectedConversationId;
1025
+ if (!uid || !id)
1026
+ return;
1027
+ try {
1028
+ await getOfflineClient().clearMessages(uid, id);
1029
+ }
1030
+ catch (e) {
1031
+ console.error('offline clear messages failed', e);
1032
+ }
1033
+ }
1018
1034
  async function hostEnqueueFailedText(host, opts) {
1019
1035
  var _a, _b, _c;
1020
1036
  const uid = userIdOf(host);
@@ -1377,12 +1393,18 @@ async function hostGetMessages(host, skip, conversationId) {
1377
1393
  });
1378
1394
  const targetId = conversationId || host.selectedConversationId;
1379
1395
  if (skip == 0) {
1396
+ // Network page is authority. Keep only local/outbox rows so cleared
1397
+ // IndexedDB hydrate cannot resurrect server-deleted messages.
1398
+ const keepLocal = (list) => (list || []).filter((m) => (m === null || m === void 0 ? void 0 : m.localId) ||
1399
+ (m === null || m === void 0 ? void 0 : m.pendingOffline) ||
1400
+ (m === null || m === void 0 ? void 0 : m.status) === 'queued' ||
1401
+ (m === null || m === void 0 ? void 0 : m.status) === 'pending' ||
1402
+ (m === null || m === void 0 ? void 0 : m.status) === 'failed');
1380
1403
  if (conversationId) {
1381
- host.selectConversationMessages = mergeMessagesById(host.selectConversationMessages || [], messages);
1404
+ host.selectConversationMessages = mergeMessagesById(keepLocal(host.selectConversationMessages), messages);
1382
1405
  }
1383
1406
  else {
1384
- // Merge with any optimistic/outbox rows already on screen
1385
- host.allMessages = mergeMessagesById(host.allMessages || [], messages);
1407
+ host.allMessages = mergeMessagesById(keepLocal(host.allMessages), messages);
1386
1408
  }
1387
1409
  }
1388
1410
  else {
@@ -2454,8 +2476,12 @@ async function hostClearConversation(host, conversationId) {
2454
2476
  const id = conversationId || host.selectedConversationId;
2455
2477
  try {
2456
2478
  await apiClearConversationLocal(id);
2457
- host.allMessages = [];
2458
- host.allConversationList = patchListAfterClear(host.allConversationList, host.selectedConversationId);
2479
+ if (host.selectedConversationId === id) {
2480
+ host.allMessages = [];
2481
+ }
2482
+ host.allConversationList = patchListAfterClear(host.allConversationList, id);
2483
+ // IndexedDB was keeping old msgs; hydrate/merge brought them back after clear.
2484
+ await hostClearCachedMessages(host, id);
2459
2485
  }
2460
2486
  catch (error) {
2461
2487
  console.error('Error while clearing conversation:', error);