@talkjs/core 1.5.2 → 1.5.3

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.
@@ -529,12 +529,12 @@ class I extends x {
529
529
  this.connection.call("SUBSCRIBE", ["users"], { ids: e2 }).then((e3) => this.subscribeCalls.forEach((t2) => t2.deferred.resolve(e3)));
530
530
  }
531
531
  }
532
- class T extends x {
532
+ class S extends x {
533
533
  constructor(e2, t2, s2) {
534
534
  super(s2, () => this.sendMutate()), this.conversationId = e2, this.connection = t2, this.calls = [];
535
535
  }
536
536
  canPush(e2, t2) {
537
- return !!T.isCorrectBatchTypeFor(e2, t2) && t2[1] === this.conversationId;
537
+ return !!S.isCorrectBatchTypeFor(e2, t2) && t2[1] === this.conversationId;
538
538
  }
539
539
  static isCorrectBatchTypeFor(e2, t2) {
540
540
  return s(t2, ["conversations", "*", "participants", "*"]) && ("PUT" === e2 || "POST" === e2 || "PATCH" === e2);
@@ -555,7 +555,7 @@ class T extends x {
555
555
  });
556
556
  }
557
557
  }
558
- class S {
558
+ class T {
559
559
  constructor(e2, t2, s2) {
560
560
  this.pendingBatch = null, this.connection = new E(e2, t2, s2);
561
561
  }
@@ -577,9 +577,9 @@ class S {
577
577
  }
578
578
  createEmptyBatchFor(e2, t2) {
579
579
  if (I.isCorrectBatchTypeFor(e2, t2)) return new I(this.connection, () => this.pendingBatch = null);
580
- if (T.isCorrectBatchTypeFor(e2, t2)) {
580
+ if (S.isCorrectBatchTypeFor(e2, t2)) {
581
581
  const e3 = t2[1];
582
- return new T(e3, this.connection, () => this.pendingBatch = null);
582
+ return new S(e3, this.connection, () => this.pendingBatch = null);
583
583
  }
584
584
  return null;
585
585
  }
@@ -587,7 +587,7 @@ class S {
587
587
  const D = { 200: "RESOLVE", 400: "RESOLVE", 401: "RETRY", 402: "RESOLVE", 403: "RESOLVE", 404: "RESOLVE", 405: "RESOLVE", 409: "RESOLVE", 429: "DELAY", 500: "DELAY" };
588
588
  class M {
589
589
  constructor(e2, t2, s2) {
590
- this.throttler = new F(), this.alive = true, this.connection = new S(e2, t2, s2);
590
+ this.throttler = new F(), this.alive = true, this.connection = new T(e2, t2, s2);
591
591
  }
592
592
  call(e2, t2, s2) {
593
593
  return __async(this, null, function* () {
@@ -799,7 +799,7 @@ class $ extends j {
799
799
  class W extends $ {
800
800
  constructor(e2, t2) {
801
801
  const s2 = new Promise((e3) => setTimeout(e3)).then(() => this.fetchInitial(e2));
802
- super({ seq: e2, resultPromise: s2 }, t2), this.initialSeq = e2, this.getDeepMutex = new U(), this.lastDeep = void 0;
802
+ super({ seq: e2, resultPromise: s2 }, t2.onTeardown), this.initialSeq = e2, this.getDeepMutex = new U(), this.lastDeep = void 0;
803
803
  }
804
804
  refetchInitial(e2) {
805
805
  return __async(this, null, function* () {
@@ -868,15 +868,9 @@ class q extends W {
868
868
  this.setError(l("UNSUBSCRIBED"));
869
869
  }, this.unsubscribeDebounceMs);
870
870
  }
871
- getLoadMoreSeq() {
872
- var _a2;
873
- const e2 = (_a2 = this.lastEmitSeq) != null ? _a2 : 0, t2 = this.mostRecentState.seq;
874
- return Math.max(e2, t2) + 1e-6;
875
- }
876
871
  emit(e2) {
877
872
  return __async(this, null, function* () {
878
873
  var _a2;
879
- if (this.onlyUsedInternally) return;
880
874
  if (this.lastEmitSeq && this.lastEmitSeq >= e2) return;
881
875
  if (false === ((_a2 = this.lastEmitResult) == null ? void 0 : _a2.ok)) return;
882
876
  this.lastEmitSeq = e2;
@@ -1082,7 +1076,7 @@ function se(e2, t2) {
1082
1076
  }
1083
1077
  class ne extends W {
1084
1078
  constructor(e2, t2, s2, n2) {
1085
- super(e2), this.conversationId = t2, this.message = s2, this.realtimeClient = n2;
1079
+ super(e2, {}), this.conversationId = t2, this.message = s2, this.realtimeClient = n2;
1086
1080
  }
1087
1081
  get messageId() {
1088
1082
  return "string" == typeof this.message ? this.message : this.message.id;
@@ -1168,7 +1162,7 @@ function ie(e2) {
1168
1162
  }
1169
1163
  class ae extends W {
1170
1164
  constructor(e2, t2, s2, n2) {
1171
- super(e2), this.createdAt = t2, this.dataStore = s2, this.referencedDataStore = n2;
1165
+ super(e2, {}), this.createdAt = t2, this.dataStore = s2, this.referencedDataStore = n2;
1172
1166
  }
1173
1167
  get messageId() {
1174
1168
  return this.dataStore.messageId;
@@ -1208,7 +1202,7 @@ class ae extends W {
1208
1202
  }
1209
1203
  class oe extends q {
1210
1204
  constructor(e2, t2, s2, n2, r2) {
1211
- super(e2, n2, r2), this.conversationId = t2, this.realtimeClient = s2, this.unsubscribeDebounceMs = 1e3, this.pendingLoadMore = void 0;
1205
+ super(e2, n2, r2), this.conversationId = t2, this.realtimeClient = s2, this.handlers = r2, this.unsubscribeDebounceMs = 1e3, this.pendingLoadMore = void 0;
1212
1206
  }
1213
1207
  listen(e2) {
1214
1208
  return this.onlyUsedInternally && this.mostRecentState.resultPromise.then((e3) => {
@@ -1274,10 +1268,13 @@ class oe extends q {
1274
1268
  const t2 = yield this.mostRecentState.resultPromise;
1275
1269
  if (!t2.ok) return;
1276
1270
  if (null === t2.value.windowEnd) return;
1277
- const s2 = t2.value.windowEnd.cursor, n2 = yield ue({ count: e2, cursor: s2, conversationId: this.conversationId, realtimeClient: this.realtimeClient }), r2 = this.getLoadMoreSeq();
1278
- this.mutate(r2, (e3) => null === e3.value.windowEnd || s2 !== e3.value.windowEnd.cursor ? e3 : n2.ok ? null === n2.value.messages ? (console.warn("[TalkJS] When loading more messages, the conversation no longer existed. We should have been told about this."), e3) : ce({ seq: r2, prevState: e3.value, messages: n2.value.messages, cursor: n2.value.nextCursor, conversationId: this.conversationId, realtimeClient: this.realtimeClient }) : n2), yield this.emitMutex.runExclusive(() => this.emit(r2));
1271
+ const s2 = t2.value.windowEnd.cursor, n2 = yield ue({ count: e2, cursor: s2, conversationId: this.conversationId, realtimeClient: this.realtimeClient });
1272
+ yield this.handlers.onLoadedMore({ type: "virtual.messages.loadedmore", conversationId: this.conversationId, data: n2 });
1279
1273
  });
1280
1274
  }
1275
+ loadedMore(e2, t2) {
1276
+ this.mutate(e2, (s2) => null === s2.value.windowEnd ? s2 : t2.data.ok ? null === t2.data.value.messages ? (console.warn("[TalkJS] When loading more messages, the conversation no longer existed. We should have been told about this."), s2) : ce({ seq: e2, prevState: s2.value, messages: t2.data.value.messages, cursor: t2.data.value.nextCursor, conversationId: this.conversationId, realtimeClient: this.realtimeClient }) : t2.data);
1277
+ }
1281
1278
  messageCreated(e2, t2) {
1282
1279
  this.mutate(e2, (s2) => {
1283
1280
  if (null === s2.value.stores) return console.warn("[TalkJS] Received a 'message.created' event for a nonexistent conversation."), s2;
@@ -1490,7 +1487,7 @@ class pe extends q {
1490
1487
  }
1491
1488
  class fe extends W {
1492
1489
  constructor(e2, t2, s2, n2) {
1493
- super(e2), this.conversationId = t2, this.participantData = s2, this.realtimeClient = n2;
1490
+ super(e2, {}), this.conversationId = t2, this.participantData = s2, this.realtimeClient = n2;
1494
1491
  }
1495
1492
  fetchInitial(e2) {
1496
1493
  return __async(this, null, function* () {
@@ -1546,7 +1543,7 @@ class fe extends W {
1546
1543
  }
1547
1544
  class me extends q {
1548
1545
  constructor(e2, t2, s2, n2, r2) {
1549
- super(e2, n2, r2), this.conversationId = t2, this.realtimeClient = s2, this.unsubscribeDebounceMs = 1e3, this.pendingLoadMore = void 0;
1546
+ super(e2, n2, r2), this.conversationId = t2, this.realtimeClient = s2, this.handlers = r2, this.unsubscribeDebounceMs = 1e3, this.pendingLoadMore = void 0;
1550
1547
  }
1551
1548
  fetchInitial(e2) {
1552
1549
  return __async(this, null, function* () {
@@ -1593,10 +1590,13 @@ class me extends q {
1593
1590
  const t2 = yield this.mostRecentState.resultPromise;
1594
1591
  if (!t2.ok) return;
1595
1592
  if (null === t2.value.windowEnd) return;
1596
- const s2 = t2.value.windowEnd.cursor, n2 = yield ge({ count: e2, cursor: s2, conversationId: this.conversationId, realtimeClient: this.realtimeClient }), r2 = this.getLoadMoreSeq();
1597
- this.mutate(r2, (e3) => null === e3.value.windowEnd || s2 !== e3.value.windowEnd.cursor ? e3 : n2.ok ? null === n2.value.participants ? (console.warn("[TalkJS] When loading more participants, the conversation no longer existed. We should have been told about this."), e3) : ve({ seq: r2, prevStores: e3.value.stores, participants: n2.value.participants, cursor: n2.value.nextCursor, conversationId: this.conversationId, realtimeClient: this.realtimeClient }) : n2), yield this.emitMutex.runExclusive(() => this.emit(r2));
1593
+ const s2 = t2.value.windowEnd.cursor, n2 = yield ge({ count: e2, cursor: s2, conversationId: this.conversationId, realtimeClient: this.realtimeClient });
1594
+ yield this.handlers.onLoadedMore({ type: "virtual.participants.loadedmore", conversationId: this.conversationId, data: n2 });
1598
1595
  });
1599
1596
  }
1597
+ loadedMore(e2, t2) {
1598
+ this.mutate(e2, (s2) => null === s2.value.windowEnd ? s2 : t2.data.ok ? null === t2.data.value.participants ? (console.warn("[TalkJS] When loading more participants, the conversation no longer existed. We should have been told about this."), s2) : ve({ seq: e2, prevStores: s2.value.stores, participants: t2.data.value.participants, cursor: t2.data.value.nextCursor, conversationId: this.conversationId, realtimeClient: this.realtimeClient }) : t2.data);
1599
+ }
1600
1600
  participantCreated(e2, t2) {
1601
1601
  this.mutate(e2, (s2) => {
1602
1602
  if (null === s2.value.stores) return console.warn("[TalkJS] Received a 'participant.created' event for a nonexistent conversation."), s2;
@@ -1663,7 +1663,7 @@ function ve({ seq: e2, prevStores: t2, participants: s2, cursor: n2, conversatio
1663
1663
  }
1664
1664
  class we extends q {
1665
1665
  constructor(e2, t2, s2, n2, r2) {
1666
- super(e2, n2, r2), this.getConvDataStore = t2, this.realtimeClient = s2, this.unsubscribeDebounceMs = 1e3, this.pendingLoadMore = void 0;
1666
+ super(e2, n2, r2), this.getConvDataStore = t2, this.realtimeClient = s2, this.handlers = r2, this.unsubscribeDebounceMs = 1e3, this.pendingLoadMore = void 0;
1667
1667
  }
1668
1668
  fetchInitial(e2) {
1669
1669
  return __async(this, null, function* () {
@@ -1712,8 +1712,8 @@ class we extends q {
1712
1712
  const t2 = yield this.mostRecentState.resultPromise;
1713
1713
  if (!t2.ok) return;
1714
1714
  if (null === t2.value.windowEnd) return;
1715
- const s2 = t2.value.windowEnd.cursor, n2 = yield be({ count: e2, cursor: s2, realtimeClient: this.realtimeClient }), r2 = this.getLoadMoreSeq();
1716
- this.mutate(r2, (e3) => null === e3.value.windowEnd || s2 !== e3.value.windowEnd.cursor ? e3 : n2.ok ? null === n2.value.conversations ? (console.warn("[TalkJS] When loading more conversations, the user stopped existing, which should be impossible."), e3) : ye({ seq: r2, prevStores: e3.value.stores, conversations: n2.value.conversations, cursor: n2.value.nextCursor, getConvDataStore: this.getConvDataStore }) : n2), yield this.emitMutex.runExclusive(() => this.emit(r2));
1715
+ const s2 = t2.value.windowEnd.cursor, n2 = yield be({ count: e2, cursor: s2, realtimeClient: this.realtimeClient });
1716
+ yield this.handlers.onLoadedMore({ type: "virtual.conversations.loadedmore", data: n2 });
1717
1717
  });
1718
1718
  }
1719
1719
  getConvFromCache(e2) {
@@ -1725,6 +1725,9 @@ class we extends q {
1725
1725
  return void 0 === s2 ? l("NOT_IN_CACHE") : s2.store.getFromCache();
1726
1726
  });
1727
1727
  }
1728
+ loadedMore(e2, t2) {
1729
+ this.mutate(e2, (s2) => null === s2.value.windowEnd ? s2 : t2.data.ok ? null === t2.data.value.conversations ? (console.warn("[TalkJS] When loading more conversations, the user stopped existing, which should be impossible."), s2) : ye({ seq: e2, prevStores: s2.value.stores, conversations: t2.data.value.conversations, cursor: t2.data.value.nextCursor, getConvDataStore: this.getConvDataStore }) : t2.data);
1730
+ }
1728
1731
  userCreated(e2, t2) {
1729
1732
  this.mutate(e2, (e3) => null !== e3.value.stores ? e3 : c({ lastChanged: e3.value.lastChanged, stores: {}, windowEnd: null }));
1730
1733
  }
@@ -1897,28 +1900,28 @@ class Ee extends q {
1897
1900
  }
1898
1901
  class ke {
1899
1902
  constructor(e2, t2, s2) {
1900
- this.realtimeClient = s2, this.convDataStores = {}, this.storeMap = {}, this.emitMutex = new U(), this.seqOffset = 0, this.seqInThisConnection = 0, this.refetchOnNextNetworkLoss = true, this.connection = new N(e2, t2, { onUpstreamRestarting: () => {
1903
+ this.realtimeClient = s2, this.convDataStores = {}, this.storeMap = {}, this.emitMutex = new U(), this.virtualSeqOffset = 0, this.realPublishSeq = 0, this.refetchOnNextNetworkLoss = true, this.connection = new N(e2, t2, { onUpstreamRestarting: () => {
1901
1904
  this.refetchOnNextNetworkLoss = false;
1902
1905
  }, onReady: () => {
1903
1906
  this.refetchOnNextNetworkLoss = true;
1904
1907
  }, onResubscribeSent: () => {
1905
- if (this.seqOffset += this.seq, this.seqInThisConnection = 0, this.refetchOnNextNetworkLoss) {
1906
- this.seqOffset++;
1907
- const e3 = this.seq;
1908
+ if (this.virtualSeqOffset += this.realPublishSeq, this.realPublishSeq = 0, this.refetchOnNextNetworkLoss) {
1909
+ this.virtualSeqOffset++;
1910
+ const e3 = this.virtualSeq;
1908
1911
  this.refetchAll(e3), this.emitAll(e3);
1909
1912
  }
1910
1913
  }, onResubscribeError: (e3, t3) => {
1911
1914
  var _a2;
1912
1915
  (_a2 = this.storeMap[xe(e3)]) == null ? void 0 : _a2.setError(t3);
1913
1916
  }, onPublish: (e3, t3) => {
1914
- this.seqInThisConnection = e3;
1915
- const s3 = this.seq;
1917
+ this.realPublishSeq = e3;
1918
+ const s3 = this.virtualSeq;
1916
1919
  for (const e4 of t3) this.handlePublish(s3, e4);
1917
1920
  this.emitAll(s3);
1918
1921
  } });
1919
1922
  }
1920
- get seq() {
1921
- return this.seqOffset + this.seqInThisConnection;
1923
+ get virtualSeq() {
1924
+ return this.realPublishSeq + this.virtualSeqOffset;
1922
1925
  }
1923
1926
  refetchAll(e2) {
1924
1927
  Object.values(this.storeMap).forEach((t2) => t2 == null ? void 0 : t2.refetch(e2));
@@ -1930,7 +1933,7 @@ class ke {
1930
1933
  }));
1931
1934
  }
1932
1935
  handlePublish(e2, t2) {
1933
- var _a2, _b, _c, _d, _e2, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t2, _u, _v, _w, _x, _y, _z, _A;
1936
+ var _a2, _b, _c, _d, _e2, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t2, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D;
1934
1937
  switch (t2.type) {
1935
1938
  case "user.created":
1936
1939
  return (_a2 = this.storeMap[`/users/${t2.userId}`]) == null ? void 0 : _a2.userCreated(e2, t2), (_b = this.storeMap["/me/conversations"]) == null ? void 0 : _b.userCreated(e2, t2), void ((_c = this.storeMap[`/users/${t2.userId}/online`]) == null ? void 0 : _c.userCreated(e2, t2));
@@ -1964,6 +1967,12 @@ class ke {
1964
1967
  return void ((_z = this.storeMap[`/me/conversations/${t2.conversationId}/participants`]) == null ? void 0 : _z.participantDeleted(e2, t2));
1965
1968
  case "user.online.changed":
1966
1969
  return void ((_A = this.storeMap[`/users/${t2.userId}/online`]) == null ? void 0 : _A.userOnlineChanged(e2, t2));
1970
+ case "virtual.conversations.loadedmore":
1971
+ return void ((_B = this.storeMap["/me/conversations"]) == null ? void 0 : _B.loadedMore(e2, t2));
1972
+ case "virtual.messages.loadedmore":
1973
+ return void ((_C = this.storeMap[`/me/conversations/${t2.conversationId}/messages`]) == null ? void 0 : _C.loadedMore(e2, t2));
1974
+ case "virtual.participants.loadedmore":
1975
+ return void ((_D = this.storeMap[`/me/conversations/${t2.conversationId}/participants`]) == null ? void 0 : _D.loadedMore(e2, t2));
1967
1976
  }
1968
1977
  }
1969
1978
  call(e2, t2, n2, r2) {
@@ -2033,6 +2042,13 @@ class ke {
2033
2042
  }
2034
2043
  }, a2;
2035
2044
  }
2045
+ onVirtualPublish(e2) {
2046
+ return __async(this, null, function* () {
2047
+ this.virtualSeqOffset++;
2048
+ const t2 = this.virtualSeq;
2049
+ this.handlePublish(t2, e2), yield this.emitAll(t2);
2050
+ });
2051
+ }
2036
2052
  getOrCreateStore(e2) {
2037
2053
  const t2 = xe(e2);
2038
2054
  if (t2 in this.storeMap) return this.storeMap[t2];
@@ -2051,13 +2067,13 @@ class ke {
2051
2067
  return this.connection.isConnected();
2052
2068
  }
2053
2069
  instantiateStore(e2, t2) {
2054
- if (s(e2, ["users", "*"])) return new G(this.seq, e2[1], this.realtimeClient, this.emitMutex, t2);
2055
- if (s(e2, ["me", "conversations", "*"])) return new le(this.seq, this.subscribeConvData(e2[2]), this.realtimeClient, this.emitMutex, t2);
2056
- if (s(e2, ["me", "conversations", "*", "messages"])) return new oe(this.seq, e2[2], this.realtimeClient, this.emitMutex, t2);
2057
- if (s(e2, ["me", "conversations", "*", "participants"])) return new me(this.seq, e2[2], this.realtimeClient, this.emitMutex, t2);
2058
- if (s(e2, ["me", "conversations", "*", "typing"])) return new pe(this.seq, e2[2], this.realtimeClient, this.emitMutex, t2);
2059
- if (s(e2, ["me", "conversations"])) return new we(this.seq, (e3) => this.subscribeConvData(e3), this.realtimeClient, this.emitMutex, t2);
2060
- if (s(e2, ["users", "*", "online"])) return new Ee(this.seq, e2[1], this.realtimeClient, this.emitMutex, t2);
2070
+ if (s(e2, ["users", "*"])) return new G(this.virtualSeq, e2[1], this.realtimeClient, this.emitMutex, { onTeardown: t2 });
2071
+ if (s(e2, ["me", "conversations", "*"])) return new le(this.virtualSeq, this.subscribeConvData(e2[2]), this.realtimeClient, this.emitMutex, { onTeardown: t2 });
2072
+ if (s(e2, ["me", "conversations", "*", "messages"])) return new oe(this.virtualSeq, e2[2], this.realtimeClient, this.emitMutex, { onTeardown: t2, onLoadedMore: (e3) => this.onVirtualPublish(e3) });
2073
+ if (s(e2, ["me", "conversations", "*", "participants"])) return new me(this.virtualSeq, e2[2], this.realtimeClient, this.emitMutex, { onTeardown: t2, onLoadedMore: (e3) => this.onVirtualPublish(e3) });
2074
+ if (s(e2, ["me", "conversations", "*", "typing"])) return new pe(this.virtualSeq, e2[2], this.realtimeClient, this.emitMutex, { onTeardown: t2 });
2075
+ if (s(e2, ["me", "conversations"])) return new we(this.virtualSeq, (e3) => this.subscribeConvData(e3), this.realtimeClient, this.emitMutex, { onTeardown: t2, onLoadedMore: (e3) => this.onVirtualPublish(e3) });
2076
+ if (s(e2, ["users", "*", "online"])) return new Ee(this.virtualSeq, e2[1], this.realtimeClient, this.emitMutex, { onTeardown: t2 });
2061
2077
  throw "Unreachable";
2062
2078
  }
2063
2079
  subscribeConvData(e2) {
@@ -2066,9 +2082,9 @@ class ke {
2066
2082
  const e3 = this.convDataStores[t2];
2067
2083
  return { store: e3, unsubscribe: e3.registerInternalSubscription() };
2068
2084
  }
2069
- const s2 = new Ce(this.seq, e2, this.realtimeClient, this.emitMutex, () => {
2085
+ const s2 = new Ce(this.virtualSeq, e2, this.realtimeClient, this.emitMutex, { onTeardown: () => {
2070
2086
  delete this.convDataStores[t2];
2071
- });
2087
+ } });
2072
2088
  return this.convDataStores[t2] = s2, { store: s2, unsubscribe: s2.registerInternalSubscription() };
2073
2089
  }
2074
2090
  }
@@ -2102,7 +2118,7 @@ class Ie {
2102
2118
  listMessages(e2, t2) {
2103
2119
  return __async(this, null, function* () {
2104
2120
  const s2 = yield this.call("GET", ["me", "conversations", e2, "messages"], t2);
2105
- if (!s2.ok) return Te(s2, "Listing messages in " + e2);
2121
+ if (!s2.ok) return Se(s2, "Listing messages in " + e2);
2106
2122
  const n2 = s2.value.data.data, r2 = yield Promise.all(n2.map((t3) => this.createMessageSnapshot(t3, e2))), i2 = r2.find((e3) => !e3.ok);
2107
2123
  if (void 0 !== i2 && !i2.ok) return i2;
2108
2124
  return c(r2.map(({ value: e3 }) => e3));
@@ -2131,7 +2147,7 @@ class Ie {
2131
2147
  const s2 = yield this.call("GET", ["me", "conversations", e2, "messages", t2], {});
2132
2148
  if (!s2.ok && "server" === s2.where && 404 === s2.value.status) return c(null);
2133
2149
  if (!s2.ok && "server" === s2.where && 403 === s2.value.status && "NOT_A_PARTICIPANT" === s2.value.errorCode) return c(null);
2134
- if (!s2.ok) return Te(s2, `Fetching referenced message ${t2} in conversation ${e2}`);
2150
+ if (!s2.ok) return Se(s2, `Fetching referenced message ${t2} in conversation ${e2}`);
2135
2151
  const n2 = s2.value.data, r2 = yield this.getUser(n2.senderId);
2136
2152
  if (!r2.ok) return r2;
2137
2153
  const i2 = r2.value;
@@ -2142,7 +2158,7 @@ class Ie {
2142
2158
  return __async(this, null, function* () {
2143
2159
  const t2 = yield this.call("GET", ["users", e2], { includePrivateFields: false });
2144
2160
  if (!t2.ok && "server" === t2.where && 404 === t2.value.status) return c(null);
2145
- if (!t2.ok) return Te(t2, "Get user " + e2);
2161
+ if (!t2.ok) return Se(t2, "Get user " + e2);
2146
2162
  return c(this.createUserSnapshot(t2.value.data));
2147
2163
  });
2148
2164
  }
@@ -2153,10 +2169,10 @@ class Ie {
2153
2169
  return { id: e2.id, type: e2.type, sender: t2, referencedMessageId: e2.referencedMessageId, custom: e2.custom, createdAt: e2.createdAt, editedAt: e2.editedAt, origin: e2.origin, content: e2.content, reactions: ie(e2.reactions), plaintext: te(e2.content, {}) };
2154
2170
  }
2155
2171
  }
2156
- function Te(e2, t2) {
2172
+ function Se(e2, t2) {
2157
2173
  return "server" === e2.where ? h(__spreadProps(__spreadValues({}, e2.value), { operation: t2 })) : e2;
2158
2174
  }
2159
- function Se(e2, s2) {
2175
+ function Te(e2, s2) {
2160
2176
  var _a2;
2161
2177
  if (s2.ok) return s2.value;
2162
2178
  throw "SESSION_DESTROYED" === s2.value ? new Error(`${e2} failed because the session was destroyed`) : new Error(t((_a2 = s2.value.operation) != null ? _a2 : e2, s2.value));
@@ -2171,7 +2187,7 @@ class De {
2171
2187
  get() {
2172
2188
  return __async(this, null, function* () {
2173
2189
  const e2 = yield this._realtimeClient.getUser(this.brandedId);
2174
- return Se("Get user " + this.id, e2);
2190
+ return Te("Get user " + this.id, e2);
2175
2191
  });
2176
2192
  }
2177
2193
  set(t2) {
@@ -2737,7 +2753,7 @@ var Qe, Ve = function() {
2737
2753
  }, e2.urlMatchDoesNotHaveAtLeastOneWordChar = function(e3, t2) {
2738
2754
  return !(!e3 || !t2) && (!this.hasFullProtocolRegex.test(t2) && !this.hasWordCharAfterProtocolRegex.test(e3));
2739
2755
  }, e2.hasFullProtocolRegex = /^[A-Za-z][-.+A-Za-z0-9]*:\/\//, e2.uriSchemeRegex = /^[A-Za-z][-.+A-Za-z0-9]*:/, e2.hasWordCharAfterProtocolRegex = new RegExp(":[^\\s]*?[" + ct + "]"), e2.ipRegex = /[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?(:[0-9]*)?\/?$/, e2;
2740
- }(), xt = (Qe = new RegExp("[/?#](?:[" + pt + "\\-+&@#/%=~_()|'$*\\[\\]{}?!:,.;^✓]*[" + pt + "\\-+&@#/%=~_()|'$*\\[\\]{}✓])?"), new RegExp(["(?:", "(", /(?:[A-Za-z][-.+A-Za-z0-9]{0,63}:(?![A-Za-z][-.+A-Za-z0-9]{0,63}:\/\/)(?!\d+\/?)(?:\/\/)?)/.source, vt(2), ")", "|", "(", "(//)?", /(?:www\.)/.source, vt(6), ")", "|", "(", "(//)?", vt(10) + "\\.", bt.source, "(?![-" + dt + "])", ")", ")", "(?::[0-9]+)?", "(?:" + Qe.source + ")?"].join(""), "gi")), It = new RegExp("[" + pt + "]"), Tt = function(e2) {
2756
+ }(), xt = (Qe = new RegExp("[/?#](?:[" + pt + "\\-+&@#/%=~_()|'$*\\[\\]{}?!:,.;^✓]*[" + pt + "\\-+&@#/%=~_()|'$*\\[\\]{}✓])?"), new RegExp(["(?:", "(", /(?:[A-Za-z][-.+A-Za-z0-9]{0,63}:(?![A-Za-z][-.+A-Za-z0-9]{0,63}:\/\/)(?!\d+\/?)(?:\/\/)?)/.source, vt(2), ")", "|", "(", "(//)?", /(?:www\.)/.source, vt(6), ")", "|", "(", "(//)?", vt(10) + "\\.", bt.source, "(?![-" + dt + "])", ")", ")", "(?::[0-9]+)?", "(?:" + Qe.source + ")?"].join(""), "gi")), It = new RegExp("[" + pt + "]"), St = function(e2) {
2741
2757
  function t2(t3) {
2742
2758
  var s2 = e2.call(this, t3) || this;
2743
2759
  return s2.stripPrefix = { scheme: true, www: true }, s2.stripTrailingSlash = true, s2.decodePercentEncoding = true, s2.matcherRegex = xt, s2.wordCharRegExp = It, s2.stripPrefix = t3.stripPrefix, s2.stripTrailingSlash = t3.stripTrailingSlash, s2.decodePercentEncoding = t3.decodePercentEncoding, s2;
@@ -2784,10 +2800,10 @@ var Qe, Ve = function() {
2784
2800
  var n2 = new RegExp("^((.?//)?[-." + pt + "]*[-" + pt + "]\\.[-" + pt + "]+)").exec(e3);
2785
2801
  return null === n2 ? -1 : (s2 += n2[1].length, e3 = e3.slice(n2[1].length), /^[^-.A-Za-z0-9:\/?#]/.test(e3) ? s2 : -1);
2786
2802
  }, t2;
2787
- }(st), St = new RegExp("#[_" + pt + "]{1,139}(?![_" + pt + "])", "g"), Dt = new RegExp("[^" + pt + "]"), Mt = function(e2) {
2803
+ }(st), Tt = new RegExp("#[_" + pt + "]{1,139}(?![_" + pt + "])", "g"), Dt = new RegExp("[^" + pt + "]"), Mt = function(e2) {
2788
2804
  function t2(t3) {
2789
2805
  var s2 = e2.call(this, t3) || this;
2790
- return s2.serviceName = "twitter", s2.matcherRegex = St, s2.nonWordCharRegex = Dt, s2.serviceName = t3.serviceName, s2;
2806
+ return s2.serviceName = "twitter", s2.matcherRegex = Tt, s2.nonWordCharRegex = Dt, s2.serviceName = t3.serviceName, s2;
2791
2807
  }
2792
2808
  return Ye(t2, e2), t2.prototype.parseMatches = function(e3) {
2793
2809
  for (var t3, s2 = this.matcherRegex, n2 = this.nonWordCharRegex, r2 = this.serviceName, i2 = this.tagBuilder, a2 = []; null !== (t3 = s2.exec(e3)); ) {
@@ -2872,10 +2888,10 @@ function Ut(e2, t2) {
2872
2888
  I2(f2);
2873
2889
  break;
2874
2890
  case 12:
2875
- T2(f2);
2891
+ S2(f2);
2876
2892
  break;
2877
2893
  case 13:
2878
- S2();
2894
+ T2();
2879
2895
  break;
2880
2896
  case 14:
2881
2897
  D2(f2);
@@ -2939,10 +2955,10 @@ function Ut(e2, t2) {
2939
2955
  function I2(e3) {
2940
2956
  at.test(e3) ? h2 = 4 : "/" === e3 ? h2 = 12 : ">" === e3 ? U2() : "<" === e3 ? O2() : (h2 = 4, c2--);
2941
2957
  }
2942
- function T2(e3) {
2958
+ function S2(e3) {
2943
2959
  ">" === e3 ? (p2 = new jt(Ve(Ve({}, p2), { isClosing: true })), U2()) : h2 = 4;
2944
2960
  }
2945
- function S2(t3) {
2961
+ function T2(t3) {
2946
2962
  "--" === e2.substr(c2, 2) ? (c2 += 2, p2 = new jt(Ve(Ve({}, p2), { type: "comment" })), h2 = 14) : "DOCTYPE" === e2.substr(c2, 7).toUpperCase() ? (c2 += 7, p2 = new jt(Ve(Ve({}, p2), { type: "doctype" })), h2 = 20) : P2();
2947
2963
  }
2948
2964
  function D2(e3) {
@@ -3082,12 +3098,12 @@ var jt = function(e2) {
3082
3098
  return this.replaceFn && (t2 = this.replaceFn.call(this.context, e3)), "string" == typeof t2 ? t2 : false === t2 ? e3.getMatchedText() : t2 instanceof Ge ? t2.toAnchorString() : e3.buildTag().toAnchorString();
3083
3099
  }, e2.prototype.getMatchers = function() {
3084
3100
  if (this.matchers) return this.matchers;
3085
- var e3 = this.getTagBuilder(), t2 = [new Mt({ tagBuilder: e3, serviceName: this.hashtag }), new At({ tagBuilder: e3 }), new Bt({ tagBuilder: e3 }), new Ot({ tagBuilder: e3, serviceName: this.mention }), new Tt({ tagBuilder: e3, stripPrefix: this.stripPrefix, stripTrailingSlash: this.stripTrailingSlash, decodePercentEncoding: this.decodePercentEncoding })];
3101
+ var e3 = this.getTagBuilder(), t2 = [new Mt({ tagBuilder: e3, serviceName: this.hashtag }), new At({ tagBuilder: e3 }), new Bt({ tagBuilder: e3 }), new Ot({ tagBuilder: e3, serviceName: this.mention }), new St({ tagBuilder: e3, stripPrefix: this.stripPrefix, stripTrailingSlash: this.stripTrailingSlash, decodePercentEncoding: this.decodePercentEncoding })];
3086
3102
  return this.matchers = t2;
3087
3103
  }, e2.prototype.getTagBuilder = function() {
3088
3104
  var e3 = this.tagBuilder;
3089
3105
  return e3 || (e3 = this.tagBuilder = new Le({ newWindow: this.newWindow, truncate: this.truncate, className: this.className })), e3;
3090
- }, e2.version = "3.14.3", e2.AnchorTagBuilder = Le, e2.HtmlTag = Ge, e2.matcher = { Email: At, Hashtag: Mt, Matcher: st, Mention: Ot, Phone: Bt, Url: Tt }, e2.match = { Email: Ze, Hashtag: Ke, Match: ze, Mention: Xe, Phone: et, Url: tt }, e2;
3106
+ }, e2.version = "3.14.3", e2.AnchorTagBuilder = Le, e2.HtmlTag = Ge, e2.matcher = { Email: At, Hashtag: Mt, Matcher: st, Mention: Ot, Phone: Bt, Url: St }, e2.match = { Email: Ze, Hashtag: Ke, Match: ze, Mention: Xe, Phone: et, Url: tt }, e2;
3091
3107
  }();
3092
3108
  function Wt(e2, t2 = e2) {
3093
3109
  return { type: "autolink", url: e2, text: t2 };
@@ -3218,7 +3234,7 @@ class us {
3218
3234
  if (!t2.ok && "server" === t2.where && 404 === t2.value.status) return null;
3219
3235
  if (!t2.ok && "server" === t2.where && 403 === t2.value.status && "NOT_A_PARTICIPANT" === t2.value.errorCode) return null;
3220
3236
  const s2 = e("Get message " + this.id, t2), n2 = yield this._realtimeClient.createMessageSnapshot(s2, this.brandedConversationId);
3221
- return Se("Get message " + this.id, n2);
3237
+ return Te("Get message " + this.id, n2);
3222
3238
  });
3223
3239
  }
3224
3240
  edit(t2) {
@@ -3270,7 +3286,7 @@ class ls {
3270
3286
  return __async(this, null, function* () {
3271
3287
  const t2 = this._realtimeClient.listMessages(this.brandedId, { limit: 1 }), s2 = yield this._realtimeClient.call("GET", ["me", "conversations", this.brandedId], {});
3272
3288
  if (!s2.ok && "server" === s2.where && 404 === s2.value.status) return null;
3273
- const n2 = e("Get conversation " + this.id, s2), r2 = Se("Get last message in conversation " + this.id, yield t2), i2 = 0 === r2.length ? null : r2[0];
3289
+ const n2 = e("Get conversation " + this.id, s2), r2 = Te("Get last message in conversation " + this.id, yield t2), i2 = 0 === r2.length ? null : r2[0];
3274
3290
  return this._realtimeClient.createConversationSnapshotPreloaded(n2, i2);
3275
3291
  });
3276
3292
  }
@@ -3378,7 +3394,7 @@ class ps {
3378
3394
  function fs({ method: e2, url: t2, data: s2, options: n2, attempts: r2, shouldRetry: i2, authProvider: o2 }) {
3379
3395
  var _a2;
3380
3396
  (!r2 || r2 <= 0) && (r2 = 1);
3381
- const u2 = { "x-talkjs-client-build": "jssdk-dev", "x-talkjs-client-date": "2025-08-28T08:53:22.349Z" };
3397
+ const u2 = { "x-talkjs-client-build": "jssdk-dev", "x-talkjs-client-date": "2025-09-02T09:13:11.435Z" };
3382
3398
  s2 instanceof FormData || (u2["Content-Type"] = (_a2 = n2 == null ? void 0 : n2.contentType) != null ? _a2 : "application/json");
3383
3399
  return a(r2, () => __async(this, null, function* () {
3384
3400
  if (o2) {
@@ -3431,7 +3447,7 @@ const Cs = gs.startsWith("app.talkjs.com");
3431
3447
  const As = "undefined" == typeof window ? { log: (e2) => Promise.resolve(), setData: (e2) => {
3432
3448
  } } : new class {
3433
3449
  constructor(e2) {
3434
- this._timeCreated = Date.now(), this._enabled = Cs, this._trackJSData = { customer: { application: "", correlationId: "", sessionId: "", token: "", userId: "", version: "dev-2025-08-28T08:53:22.349Z" }, entry: "direct", environment: { age: Date.now() - this._timeCreated, dependencies: {}, originalUrl: window.location.href, referrer: document.referrer, userAgent: window.navigator.userAgent }, metadata: [], nav: [], network: [], url: window.location.href, stack: "", timestamp: (/* @__PURE__ */ new Date()).toISOString(), version: "dev-2025-08-28T08:53:22.349Z", throttled: 0 }, this._url = `https://capture.trackjs.com/capture?token=${e2}`, this._trackJSData.customer.token = e2;
3450
+ this._timeCreated = Date.now(), this._enabled = Cs, this._trackJSData = { customer: { application: "", correlationId: "", sessionId: "", token: "", userId: "", version: "dev-2025-09-02T09:13:11.435Z" }, entry: "direct", environment: { age: Date.now() - this._timeCreated, dependencies: {}, originalUrl: window.location.href, referrer: document.referrer, userAgent: window.navigator.userAgent }, metadata: [], nav: [], network: [], url: window.location.href, stack: "", timestamp: (/* @__PURE__ */ new Date()).toISOString(), version: "dev-2025-09-02T09:13:11.435Z", throttled: 0 }, this._url = `https://capture.trackjs.com/capture?token=${e2}`, this._trackJSData.customer.token = e2;
3435
3451
  }
3436
3452
  setData({ appId: e2, meId: t2, sessionId: s2 }) {
3437
3453
  this._trackJSData.customer.userId = e2, this._trackJSData.customer.sessionId = `${e2}/${t2}`, this._trackJSData.customer.correlationId = s2;
@@ -3659,7 +3675,7 @@ class Is {
3659
3675
  return this.target;
3660
3676
  }
3661
3677
  }
3662
- const Ts = new class {
3678
+ const Ss = new class {
3663
3679
  constructor() {
3664
3680
  this.registry = {};
3665
3681
  }
@@ -3678,8 +3694,8 @@ const Ts = new class {
3678
3694
  return `${e2}:${t2}`;
3679
3695
  }
3680
3696
  }();
3681
- function Ss(e2) {
3682
- return e2.forceCreateNew ? new Ds(e2) : Ts.getOrCreate(e2);
3697
+ function Ts(e2) {
3698
+ return e2.forceCreateNew ? new Ds(e2) : Ss.getOrCreate(e2);
3683
3699
  }
3684
3700
  class Ds {
3685
3701
  constructor(e2) {
@@ -3693,7 +3709,7 @@ class Ds {
3693
3709
  const { appId: t2, userId: s2, token: n2, tokenFetcher: r2, signature: i2 } = e2;
3694
3710
  this._appId = t2, this._apiUrls = e2.apiUrls ? new ps(e2.apiUrls.realtimeWsApiUrl, e2.apiUrls.internalHttpApiUrl, e2.apiUrls.restApiHttpUrl) : ps.fromHost(e2.host), this._authProvider = new ks(this._apiUrls, t2, s2, n2, r2, i2);
3695
3711
  const a2 = Math.random().toString().split(".")[1];
3696
- this._realtimeClient = new Ie(this._apiUrls.getRealtimeWsUrl(t2, s2, "1.5.1", a2, e2.clientBuild), s2, this._authProvider), this.currentUser = new De(this._realtimeClient.userId, this._realtimeClient), this._terminationReason = o(), this._terminationReason.promise.then((e3) => {
3712
+ this._realtimeClient = new Ie(this._apiUrls.getRealtimeWsUrl(t2, s2, "1.5.2", a2, e2.clientBuild), s2, this._authProvider), this.currentUser = new De(this._realtimeClient.userId, this._realtimeClient), this._terminationReason = o(), this._terminationReason.promise.then((e3) => {
3697
3713
  console.error(`[TalkSession] ${e3}`);
3698
3714
  }), function(e3, t3, s3) {
3699
3715
  return __async(this, null, function* () {
@@ -3731,7 +3747,7 @@ class Ds {
3731
3747
  return this._realtimeClient.subscribe(["me", "conversations"], e2);
3732
3748
  }
3733
3749
  terminate(e2) {
3734
- Ts.deregister(this._appId, this.currentUser.id), this._terminationReason.resolve(e2), this._realtimeClient.destroy();
3750
+ Ss.deregister(this._appId, this.currentUser.id), this._terminationReason.resolve(e2), this._realtimeClient.destroy();
3735
3751
  }
3736
3752
  _isConnected() {
3737
3753
  return this._realtimeClient.isConnected();
@@ -3765,7 +3781,7 @@ function Ms(_0, _1, _2, _3) {
3765
3781
  });
3766
3782
  }
3767
3783
  export {
3768
- Ss as getTalkSession,
3784
+ Ts as getTalkSession,
3769
3785
  f as registerPolyfills
3770
3786
  };
3771
3787
  //# sourceMappingURL=talkSession.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@talkjs/core",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "Lets you connect to your TalkJS chat as a user and read, subscribe to, and update your chat data.",
5
5
  "bugs": {
6
6
  "url": "https://talkjs.com/?chat"