@talkjs/core 1.5.0 → 1.5.2

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.
@@ -245,6 +245,8 @@ export declare interface ConversationListActiveState {
245
245
  *
246
246
  * You can expand this window by calling {@link ConversationListSubscription.loadMore}, which extends the window further into the past.
247
247
  *
248
+ * Remember to `.unsubscribe` the subscription once you are done with it.
249
+ *
248
250
  * @public
249
251
  */
250
252
  export declare interface ConversationListSubscription {
@@ -287,6 +289,10 @@ export declare interface ConversationListSubscription {
287
289
  * @remarks
288
290
  * Calling `loadMore` multiple times in parallel will still only load one page of conversations.
289
291
  *
292
+ * Avoid calling `.loadMore` in a loop until you have loaded all conversations.
293
+ * This is usually unnecessary: any time a conversation receives a message, it appears at the start of the list of conversations.
294
+ * If you do need to call loadMore in a loop, make sure you set a small upper bound (e.g. 100) on the number of conversations, where the loop will exit.
295
+ *
290
296
  * @param count - The number of additional conversations to load. Must be between 1 and 30. Default 20.
291
297
  * @returns A promise that resolves once the additional conversations have loaded
292
298
  */
@@ -460,30 +466,43 @@ export declare interface ConversationRef {
460
466
  * Subscribes to the messages in the conversation.
461
467
  *
462
468
  * @remarks
463
- * Initially, you will be subscribed to the 30 most recent messages and any new messages.
464
- * Call `loadMore` to load additional older messages.
465
- *
466
469
  * While the subscription is active, `onSnapshot` will be called whenever the message snapshots change.
467
470
  * This includes when a message is sent, edited, deleted, and when you load more messages.
468
471
  * It also includes when nested data changes, such as when `snapshot[0].referencedMessage.sender.name` changes.
469
472
  * `loadedAll` is true when `snapshot` contains all the messages in the conversation, and false if you could load more.
470
473
  *
474
+ * The `snapshot` list is ordered chronologically with the most recent messages at the start.
475
+ * When a new message is received, it will be added to the start of the list.
476
+ *
471
477
  * The snapshot is null if you are not a participant in the conversation (including when the conversation doesn't exist)
478
+ *
479
+ * Initially, you will be subscribed to the 30 most recent messages and any new messages.
480
+ * Call `loadMore` to load additional older messages. This will trigger `onSnapshot`.
481
+ *
482
+ * Tip: If you only care about the most recent message in the conversation, use `ConversationRef.subscribe` or `Session.subscribeConversations`.
483
+ * Then use the `ConversationSnapshot.lastMessage` property. This is easier to use and slightly more efficient.
484
+ *
485
+ * Remember to call `.unsubscribe` on the subscription once you are done with it.
472
486
  */
473
487
  subscribeMessages(onSnapshot?: (snapshot: MessageSnapshot[] | null, loadedAll: boolean) => void): MessageSubscription;
474
488
  /**
475
489
  * Subscribes to the participants in the conversation.
476
490
  *
477
491
  * @remarks
478
- * Initially, you will be subscribed to the 10 participants who joined most recently, and any new participants.
479
- * Call `loadMore` to load additional older participants.
480
- *
481
492
  * While the subscription is active, `onSnapshot` will be called whenever the participant snapshots change.
482
493
  * This includes when someone joins or leaves, when their participant attributes are edited, and when you load more participants.
483
494
  * It also includes when nested data changes, such as when `snapshot[0].user.name` changes.
484
495
  * `loadedAll` is true when `snapshot` contains all the participants in the conversation, and false if you could load more.
485
496
  *
497
+ * The `snapshot` list is ordered chronologically with the participants who joined most recently at the start.
498
+ * When someone joins the conversation, they will be added to the start of the list.
499
+ *
486
500
  * The snapshot is null if you are not a participant in the conversation (including when the conversation doesn't exist)
501
+ *
502
+ * Initially, you will be subscribed to the 10 participants who joined most recently, and any new participants.
503
+ * Call `loadMore` to load additional older participants. This will trigger `onSnapshot`.
504
+ *
505
+ * Remember to call `.unsubscribe` on the subscription once you are done with it.
487
506
  */
488
507
  subscribeParticipants(onSnapshot?: (snapshot: ParticipantSnapshot[] | null, loadedAll: boolean) => void): ParticipantSubscription;
489
508
  /**
@@ -494,6 +513,8 @@ export declare interface ConversationRef {
494
513
  * This includes changes to nested data. As an extreme example, `onSnapshot` would be called when `snapshot.lastMessage.referencedMessage.sender.name` changes.
495
514
  *
496
515
  * The snapshot is null if you are not a participant in the conversation (including when the conversation doesn't exist)
516
+ *
517
+ * Remember to call `.unsubscribe` on the subscription once you are done with it.
497
518
  */
498
519
  subscribe(onSnapshot?: (snapshot: ConversationSnapshot | null) => void): ConversationSubscription;
499
520
  /**
@@ -505,6 +526,8 @@ export declare interface ConversationRef {
505
526
  * You will not be notified when there are already "many" people typing, and another person starts typing, because the snapshot does not change.
506
527
  *
507
528
  * The snapshot is null if you are not a participant in the conversation (including when the conversation doesn't exist)
529
+ *
530
+ * Remember to call `.unsubscribe` on the subscription once you are done with it.
508
531
  */
509
532
  subscribeTyping(onSnapshot?: (snapshot: TypingSnapshot | null) => void): TypingSubscription;
510
533
  /**
@@ -532,7 +555,8 @@ export declare interface ConversationRef {
532
555
  *
533
556
  * const now = Date.now();
534
557
  *
535
- * // Don't mark as typing more than once every 5s
558
+ * // Call `markAsTyping` sparingly - not on every keystroke
559
+ * // Only call if it has been at least 5 seconds since last time
536
560
  * if (now - lastMarkedAsTyping > 5000) {
537
561
  * lastMarkedAsTyping = now;
538
562
  * convRef.markAsTyping();
@@ -642,6 +666,8 @@ export declare interface ConversationSnapshot {
642
666
  * @remarks
643
667
  * Get a ConversationSubscription by calling {@link ConversationRef.subscribe}
644
668
  *
669
+ * Remember to `.unsubscribe` the subscription once you are done with it.
670
+ *
645
671
  * @public
646
672
  */
647
673
  export declare interface ConversationSubscription {
@@ -1383,6 +1409,8 @@ export declare interface MessageSnapshot {
1383
1409
  *
1384
1410
  * You can expand this window by calling {@link MessageSubscription.loadMore}, which extends the window further into the past.
1385
1411
  *
1412
+ * Remember to `.unsubscribe` the subscription once you are done with it.
1413
+ *
1386
1414
  * @public
1387
1415
  */
1388
1416
  export declare interface MessageSubscription {
@@ -1425,6 +1453,9 @@ export declare interface MessageSubscription {
1425
1453
  * @remarks
1426
1454
  * Calling `loadMore` multiple times in parallel will still only load one page of messages.
1427
1455
  *
1456
+ * Avoid calling `.loadMore` in a loop until you have loaded all messages.
1457
+ * If you do need to call loadMore in a loop, make sure you set an upper bound (e.g. 1000) on the number of messages, where the loop will exit.
1458
+ *
1428
1459
  * @param count - The number of additional messages to load. Must be between 1 and 100. Default 30.
1429
1460
  * @returns A promise that resolves once the additional messages have loaded
1430
1461
  */
@@ -1575,6 +1606,9 @@ export declare interface ParticipantSnapshot {
1575
1606
  * By default, you subscribe to the 10 most recent participants, and any participants who joined after you subscribe.
1576
1607
  *
1577
1608
  * You can expand this window by calling {@link ParticipantSubscription.loadMore}, which extends the window further into the past.
1609
+ * Do not call `.loadMore` in a loop until you have loaded all participants, unless you know that the maximum number of participants is small (under 100).
1610
+ *
1611
+ * Remember to `.unsubscribe` the subscription once you are done with it.
1578
1612
  *
1579
1613
  * @public
1580
1614
  */
@@ -1618,6 +1652,9 @@ export declare interface ParticipantSubscription {
1618
1652
  * @remarks
1619
1653
  * Calling `loadMore` multiple times in parallel will still only load one page of participants.
1620
1654
  *
1655
+ * Avoid calling `.loadMore` in a loop until you have loaded all participants.
1656
+ * If you do need to call loadMore in a loop, make sure you set a small upper bound (e.g. 100) on the number of participants, where the loop will exit.
1657
+ *
1621
1658
  * @param count - The number of additional participants to load. Must be between 1 and 50. Default 10.
1622
1659
  * @returns A promise that resolves once the additional participants have loaded
1623
1660
  */
@@ -2178,18 +2215,27 @@ export declare interface TalkSession {
2178
2215
  * Subscribes to your most recently active conversations.
2179
2216
  *
2180
2217
  * @remarks
2181
- * The subscription is 'windowed'. Initially, this window contains the 20 most recent conversations.
2182
- * Conversations are ordered by last activity. The last activity of a conversation is either `joinedAt` or `lastMessage.createdAt`, whichever is higher.
2183
- *
2184
- * If an older conversation receives a new message, or you are added to a conversation, it will appear at the start of the list.
2185
- * Call `loadMore` to load additional older conversations.
2186
- *
2187
2218
  * While the subscription is active, `onSnapshot` will be called whenever the conversation snapshots change.
2188
2219
  * This includes when you join or leave a conversation, when the conversation attributes change, and when you load more conversations.
2189
2220
  * It also includes when nested data changes, such as when `snapshot[0].lastMessage.referencedMessage.sender.name` changes.
2221
+ * Be careful when doing heavy computation inside `onSnapshot`, and consider caching the result. `onSnapshot` is called extremely often.
2190
2222
  * `loadedAll` is true when `snapshot` contains all your conversations, and false if you could load more.
2191
2223
  *
2192
- * If the current user does not exist yet, the snapshot will be an empty list.
2224
+ * The `snapshot` list is ordered chronologically with the most recently active conversations at the start.
2225
+ * The last activity of a conversation is either when the last message was sent or when you joined, whichever is later.
2226
+ * In other words, it's the max of `lastMessage.createdAt` and `joinedAt`.
2227
+ * If you join a new conversation, or you receive a message in a conversation, that conversation will appear at the start of the list.
2228
+ *
2229
+ * The snapshot is an empty list if the current user does not exist yet.
2230
+ *
2231
+ * Initially, you will be subscribed to the 20 most recently active conversations and any conversations that have activity after you subscribe.
2232
+ * Call `loadMore` to load additional older conversations. This will trigger `onSnapshot`.
2233
+ *
2234
+ * Tip: `ConversationSnapshot` has a `lastMessage` property. Whenever you are sent a message, that message will be at `snapshot[0].lastMessage`.
2235
+ * If you just want to react to newly received messages, you can use this instead of calling `ConversationRef.subscribeMessages`.
2236
+ * This is much easier and more efficient.
2237
+ *
2238
+ * Remember to call `.unsubscribe` on the subscription once you are done with it.
2193
2239
  */
2194
2240
  subscribeConversations(onSnapshot?: (snapshot: ConversationSnapshot[], loadedAll: boolean) => void): ConversationListSubscription;
2195
2241
  /**
@@ -2402,6 +2448,8 @@ export declare type TypingSnapshot = FewTypingSnapshot | ManyTypingSnapshot;
2402
2448
  * When there are "many" people typing (meaning you received {@link ManyTypingSnapshot}), the next update you receive will be {@link FewTypingSnapshot} once enough people stop typing.
2403
2449
  * Until then, your {@link ManyTypingSnapshot} is still valid and does not need to changed, so `onSnapshot` will not be called.
2404
2450
  *
2451
+ * Remember to `.unsubscribe` the subscription once you are done with it.
2452
+ *
2405
2453
  * @public
2406
2454
  */
2407
2455
  export declare interface TypingSubscription {
@@ -2514,6 +2562,8 @@ export declare interface UserOnlineSnapshot {
2514
2562
  * @remarks
2515
2563
  * Get a UserOnlineSubscription by calling {@link UserRef.subscribeOnline}.
2516
2564
  *
2565
+ * Remember to `.unsubscribe` the subscription once you are done with it.
2566
+ *
2517
2567
  * @public
2518
2568
  */
2519
2569
  export declare interface UserOnlineSubscription {
@@ -2610,6 +2660,8 @@ export declare interface UserRef {
2610
2660
  * @remarks
2611
2661
  * While the subscription is active, `onSnapshot` will be called when the user is created or the snapshot changes.
2612
2662
  *
2663
+ * Remember to call `.unsubscribe` on the subscription once you are done with it.
2664
+ *
2613
2665
  * @returns A subscription to the user
2614
2666
  */
2615
2667
  subscribe(onSnapshot?: (event: UserSnapshot | null) => void): UserSubscription;
@@ -2619,6 +2671,8 @@ export declare interface UserRef {
2619
2671
  * @remarks
2620
2672
  * While the subscription is active, `onSnapshot` will be called when the user is created or the snapshot changes (including changes to the nested UserSnapshot).
2621
2673
  *
2674
+ * Remember to call `.unsubscribe` on the subscription once you are done with it.
2675
+ *
2622
2676
  * @returns A subscription to the user's online status
2623
2677
  */
2624
2678
  subscribeOnline(onSnapshot?: (event: UserOnlineSnapshot | null) => void): UserOnlineSubscription;
@@ -2675,6 +2729,8 @@ export declare interface UserSnapshot {
2675
2729
  * @remarks
2676
2730
  * Get a UserSubscription by calling {@link UserRef.subscribe}
2677
2731
  *
2732
+ * Remember to `.unsubscribe` the subscription once you are done with it.
2733
+ *
2678
2734
  * @public
2679
2735
  */
2680
2736
  export declare interface UserSubscription {
@@ -3149,29 +3149,32 @@ const ts = function(e2) {
3149
3149
  function ss(e2, t2 = { except: [] }) {
3150
3150
  let s2 = function(e3, t3) {
3151
3151
  let s3 = [e3];
3152
- return s3 = ns(s3, t3.multilineSteps), s3 = ns(s3, [ts]), s3 = ns(s3, t3.singlelineSteps), s3 = rs(s3), s3;
3152
+ return s3 = rs(s3, t3.multilineSteps), s3 = rs(s3, [ts]), s3 = rs(s3, t3.singlelineSteps), s3 = is(s3), s3;
3153
3153
  }(e2, es(t2));
3154
- return s2 = is(s2, false), s2;
3154
+ return s2 = as(s2, false), s2;
3155
3155
  }
3156
- function ns(e2, t2) {
3156
+ function ns(e2) {
3157
+ return ss(e2, { except: ["FormattedLink", "Actions"] });
3158
+ }
3159
+ function rs(e2, t2) {
3157
3160
  return t2.reduce((e3, t3) => Be(e3, t3), e2);
3158
3161
  }
3159
- function rs(e2) {
3162
+ function is(e2) {
3160
3163
  const t2 = [];
3161
3164
  let s2 = -1;
3162
- for (const n2 of e2) "string" == typeof n2 ? "string" == typeof t2[s2] ? t2[s2] += n2 : t2[++s2] = n2 : t2[++s2] = "children" in n2 ? __spreadProps(__spreadValues({}, n2), { children: rs(n2.children) }) : n2;
3165
+ for (const n2 of e2) "string" == typeof n2 ? "string" == typeof t2[s2] ? t2[s2] += n2 : t2[++s2] = n2 : t2[++s2] = "children" in n2 ? __spreadProps(__spreadValues({}, n2), { children: is(n2.children) }) : n2;
3163
3166
  return t2;
3164
3167
  }
3165
- function is(e2, t2) {
3168
+ function as(e2, t2) {
3166
3169
  const s2 = [];
3167
3170
  let n2 = [];
3168
3171
  for (let r2 = 0; r2 < e2.length; r2++) {
3169
3172
  const i2 = e2[r2];
3170
- "string" == typeof i2 ? n2.push(i2) : "children" in i2 ? (n2.length > 0 && (s2.push(n2.join("")), n2 = []), i2.children = is(i2.children, t2 || "link" === i2.type || "actionbutton" === i2.type || "actionlink" === i2.type), s2.push(i2)) : "autolink" === i2.type && t2 ? n2.push(i2.text) : (n2.length > 0 && (s2.push(n2.join("")), n2 = []), s2.push(i2));
3173
+ "string" == typeof i2 ? n2.push(i2) : "children" in i2 ? (n2.length > 0 && (s2.push(n2.join("")), n2 = []), i2.children = as(i2.children, t2 || "link" === i2.type || "actionbutton" === i2.type || "actionlink" === i2.type), s2.push(i2)) : "autolink" === i2.type && t2 ? n2.push(i2.text) : (n2.length > 0 && (s2.push(n2.join("")), n2 = []), s2.push(i2));
3171
3174
  }
3172
3175
  return n2.length > 0 && (s2.push(n2.join("")), n2 = []), s2;
3173
3176
  }
3174
- class as {
3177
+ class os {
3175
3178
  constructor(e2, t2, s2, n2) {
3176
3179
  this.emoji = e2, this.messageId = t2, this.conversationId = s2, this._realtimeClient = n2;
3177
3180
  }
@@ -3194,7 +3197,7 @@ class as {
3194
3197
  });
3195
3198
  }
3196
3199
  }
3197
- class os {
3200
+ class us {
3198
3201
  constructor(e2, t2, s2) {
3199
3202
  this.id = e2, this.conversationId = t2, this._realtimeClient = s2;
3200
3203
  }
@@ -3207,7 +3210,7 @@ class os {
3207
3210
  reaction(e2) {
3208
3211
  if ("string" != typeof e2) throw new Error(`Creating ReactionRef failed because emoji "${e2}" is not a string`);
3209
3212
  if ("" === e2) throw new Error(`Creating ReactionRef failed because emoji "${e2}" is an empty string`);
3210
- return new as(e2, this.brandedId, this.brandedConversationId, this._realtimeClient);
3213
+ return new os(e2, this.brandedId, this.brandedConversationId, this._realtimeClient);
3211
3214
  }
3212
3215
  get() {
3213
3216
  return __async(this, null, function* () {
@@ -3220,7 +3223,7 @@ class os {
3220
3223
  }
3221
3224
  edit(t2) {
3222
3225
  return __async(this, null, function* () {
3223
- const s2 = { content: us(t2), custom: "string" == typeof t2 ? void 0 : t2.custom }, n2 = yield this._realtimeClient.call("PATCH", ["conversations", this.brandedConversationId, "messages", this.brandedId], s2);
3226
+ const s2 = { content: cs(t2), custom: "string" == typeof t2 ? void 0 : t2.custom }, n2 = yield this._realtimeClient.call("PATCH", ["conversations", this.brandedConversationId, "messages", this.brandedId], s2);
3224
3227
  e(`Edit message ${this.id} in conversation ${this.conversationId}`, n2);
3225
3228
  });
3226
3229
  }
@@ -3231,7 +3234,7 @@ class os {
3231
3234
  });
3232
3235
  }
3233
3236
  }
3234
- function us(e2) {
3237
+ function cs(e2) {
3235
3238
  if ("string" == typeof e2) {
3236
3239
  return [{ type: "text", children: ss(e2) }];
3237
3240
  }
@@ -3240,7 +3243,7 @@ function us(e2) {
3240
3243
  }
3241
3244
  if ("content" in e2 && e2.content) return e2.content;
3242
3245
  }
3243
- class cs {
3246
+ class ls {
3244
3247
  constructor(e2, t2) {
3245
3248
  this.id = e2, this._realtimeClient = t2, this.uselessObjForTypeCheck = { subject: null, photoUrl: null, welcomeMessages: null, custom: null, access: null, notify: null };
3246
3249
  }
@@ -3261,7 +3264,7 @@ class cs {
3261
3264
  message(e2) {
3262
3265
  if ("string" != typeof e2) throw new Error(`Creating MessageRef failed because ID "${e2}" is not a string`);
3263
3266
  if ("" === e2) throw new Error(`Creating MessageRef failed because ID "${e2}" is an empty string`);
3264
- return new os(e2, this.brandedId, this._realtimeClient);
3267
+ return new us(e2, this.brandedId, this._realtimeClient);
3265
3268
  }
3266
3269
  get() {
3267
3270
  return __async(this, null, function* () {
@@ -3310,8 +3313,8 @@ class cs {
3310
3313
  }
3311
3314
  send(t2) {
3312
3315
  return __async(this, null, function* () {
3313
- const s2 = { content: ls(t2), referencedMessageId: hs(t2), custom: "string" == typeof t2 ? void 0 : t2.custom, idempotencyKey: Fe((/* @__PURE__ */ new Date()).getTime()) }, n2 = yield this._realtimeClient.call("POST", ["conversations", this.brandedId, "messages"], s2), r2 = e("Send message to conversation " + this.id, n2);
3314
- return new os(r2.id, this.brandedId, this._realtimeClient);
3316
+ const s2 = { content: hs(t2), referencedMessageId: ds(t2), custom: "string" == typeof t2 ? void 0 : t2.custom, idempotencyKey: Fe((/* @__PURE__ */ new Date()).getTime()) }, n2 = yield this._realtimeClient.call("POST", ["conversations", this.brandedId, "messages"], s2), r2 = e("Send message to conversation " + this.id, n2);
3317
+ return new us(r2.id, this.brandedId, this._realtimeClient);
3315
3318
  });
3316
3319
  }
3317
3320
  subscribeMessages(e2) {
@@ -3333,21 +3336,21 @@ class cs {
3333
3336
  });
3334
3337
  }
3335
3338
  }
3336
- function ls(e2) {
3339
+ function hs(e2) {
3337
3340
  if ("string" == typeof e2) {
3338
- return [{ type: "text", children: ss(e2) }];
3341
+ return [{ type: "text", children: ns(e2) }];
3339
3342
  }
3340
3343
  if ("text" in e2) {
3341
- return [{ type: "text", children: ss(e2.text) }];
3344
+ return [{ type: "text", children: ns(e2.text) }];
3342
3345
  }
3343
3346
  return e2.content;
3344
3347
  }
3345
- function hs(e2) {
3348
+ function ds(e2) {
3346
3349
  if ("string" == typeof e2) return;
3347
3350
  const t2 = e2.referencedMessage;
3348
3351
  return void 0 !== t2 ? "string" == typeof t2 ? t2 : t2.id : void 0;
3349
3352
  }
3350
- class ds {
3353
+ class ps {
3351
3354
  constructor(e2, t2, s2) {
3352
3355
  this.realtimeWsApiUrl = e2, this.internalHttpApiUrl = t2, this.restApiHttpUrl = s2;
3353
3356
  }
@@ -3359,23 +3362,23 @@ class ds {
3359
3362
  return this.realtimeWsApiUrl + `/${e2}/realtime/${i2}?talkjs-client-build=${r2 != null ? r2 : "standalone"}&talkjs-core=${s2}&talkjs-client-id=${n2}`;
3360
3363
  }
3361
3364
  static fromHost(e2) {
3362
- const t2 = new ds("wss://realtime.talkjs.com/v1", "https://app.talkjs.com/api/v0", "https://api.talkjs.com/v1");
3365
+ const t2 = new ps("wss://realtime.talkjs.com/v1", "https://app.talkjs.com/api/v0", "https://api.talkjs.com/v1");
3363
3366
  if (!e2) return t2;
3364
3367
  if (e2.endsWith("talkjs.com")) {
3365
3368
  const s2 = e2.match(/\w+-(\w+)\.talkjs\.com/);
3366
3369
  if (s2) {
3367
3370
  const e3 = s2[1];
3368
- return new ds(`wss://realtime-${e3}.talkjs.com/v1`, `https://app-${e3}.talkjs.com/api/v0`, `https://api-${e3}.talkjs.com/v1`);
3371
+ return new ps(`wss://realtime-${e3}.talkjs.com/v1`, `https://app-${e3}.talkjs.com/api/v0`, `https://api-${e3}.talkjs.com/v1`);
3369
3372
  }
3370
3373
  return t2;
3371
3374
  }
3372
- return e2.includes("localhost") || e2.includes("localtest.me") || /^\d+\.\d+\.\d+\.\d+(:\d+)?$/.test(e2) ? new ds(`ws://${e2}/public_api/v1`, `http://${e2}/api/v0`, `http://${e2}/public_api/v1`) : new ds(`wss://${e2}/public_api/v1`, `https://${e2}/api/v0`, `https://${e2}/public_api/v1`);
3375
+ return e2.includes("localhost") || e2.includes("localtest.me") || /^\d+\.\d+\.\d+\.\d+(:\d+)?$/.test(e2) ? new ps(`ws://${e2}/public_api/v1`, `http://${e2}/api/v0`, `http://${e2}/public_api/v1`) : new ps(`wss://${e2}/public_api/v1`, `https://${e2}/api/v0`, `https://${e2}/public_api/v1`);
3373
3376
  }
3374
3377
  }
3375
- function ps({ method: e2, url: t2, data: s2, options: n2, attempts: r2, shouldRetry: i2, authProvider: o2 }) {
3378
+ function fs({ method: e2, url: t2, data: s2, options: n2, attempts: r2, shouldRetry: i2, authProvider: o2 }) {
3376
3379
  var _a2;
3377
3380
  (!r2 || r2 <= 0) && (r2 = 1);
3378
- const u2 = { "x-talkjs-client-build": "jssdk-dev", "x-talkjs-client-date": "2025-08-14T09:36:31.233Z" };
3381
+ const u2 = { "x-talkjs-client-build": "jssdk-dev", "x-talkjs-client-date": "2025-08-28T08:53:22.349Z" };
3379
3382
  s2 instanceof FormData || (u2["Content-Type"] = (_a2 = n2 == null ? void 0 : n2.contentType) != null ? _a2 : "application/json");
3380
3383
  return a(r2, () => __async(this, null, function* () {
3381
3384
  if (o2) {
@@ -3387,19 +3390,19 @@ function ps({ method: e2, url: t2, data: s2, options: n2, attempts: r2, shouldRe
3387
3390
  throw e3;
3388
3391
  });
3389
3392
  }), { initialDelay: 0.2, log: void 0, shouldRetry: (s3) => __async(this, null, function* () {
3390
- return o2 && 401 === s3.status ? (Cs.log(`401 error from ${e2} ${t2}, ${yield o2.getToken()}`), o2.refreshToken(), true) : i2 ? i2(s3) : !("status" in s3 && s3.status >= 400 && s3.status < 500);
3393
+ return o2 && 401 === s3.status ? (As.log(`401 error from ${e2} ${t2}, ${yield o2.getToken()}`), o2.refreshToken(), true) : i2 ? i2(s3) : !("status" in s3 && s3.status >= 400 && s3.status < 500);
3391
3394
  }) }).catch((s3) => {
3392
3395
  if (Math.random() < 0.1 && !t2.toString().startsWith("https://capture.trackjs.com")) {
3393
3396
  const n3 = `Network Error for ${e2} ${t2}`;
3394
3397
  if ("undefined" != typeof window) if (s3 instanceof Response) {
3395
- s3.clone().text().then((e3) => Cs.log(`${n3} ${s3.status} ${e3} (10% logged)`));
3396
- } else Cs.log(`${n3} ${s3} (10% logged)`);
3398
+ s3.clone().text().then((e3) => As.log(`${n3} ${s3.status} ${e3} (10% logged)`));
3399
+ } else As.log(`${n3} ${s3} (10% logged)`);
3397
3400
  console.error("[TalkJS]", n3);
3398
3401
  }
3399
3402
  throw s3;
3400
3403
  });
3401
3404
  }
3402
- const { cdnHost: fs, appHost: ms, restHost: gs, realtimeHost: vs, appProtocol: ws, appWsProtocol: bs } = function() {
3405
+ const { cdnHost: ms, appHost: gs, restHost: vs, realtimeHost: ws, appProtocol: bs, appWsProtocol: ys } = function() {
3403
3406
  if ("undefined" == typeof window) return { cdnHost: "test-hostname", appHost: "test-hostname", appProtocol: "http:", appWsProtocol: "ws:" };
3404
3407
  const e2 = function() {
3405
3408
  if (document.currentScript) return document.currentScript.src;
@@ -3424,11 +3427,11 @@ const { cdnHost: fs, appHost: ms, restHost: gs, realtimeHost: vs, appProtocol: w
3424
3427
  }(n2), a2 = t2.protocol;
3425
3428
  return { cdnHost: s2, appHost: n2, restHost: r2, realtimeHost: i2, appProtocol: a2, appWsProtocol: "https:" === a2 ? "wss:" : "ws:" };
3426
3429
  }();
3427
- const ys = ms.startsWith("app.talkjs.com");
3428
- const Cs = "undefined" == typeof window ? { log: (e2) => Promise.resolve(), setData: (e2) => {
3430
+ const Cs = gs.startsWith("app.talkjs.com");
3431
+ const As = "undefined" == typeof window ? { log: (e2) => Promise.resolve(), setData: (e2) => {
3429
3432
  } } : new class {
3430
3433
  constructor(e2) {
3431
- this._timeCreated = Date.now(), this._enabled = ys, this._trackJSData = { customer: { application: "", correlationId: "", sessionId: "", token: "", userId: "", version: "dev-2025-08-14T09:36:31.233Z" }, 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-14T09:36:31.233Z", throttled: 0 }, this._url = `https://capture.trackjs.com/capture?token=${e2}`, this._trackJSData.customer.token = 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;
3432
3435
  }
3433
3436
  setData({ appId: e2, meId: t2, sessionId: s2 }) {
3434
3437
  this._trackJSData.customer.userId = e2, this._trackJSData.customer.sessionId = `${e2}/${t2}`, this._trackJSData.customer.correlationId = s2;
@@ -3438,14 +3441,14 @@ const Cs = "undefined" == typeof window ? { log: (e2) => Promise.resolve(), setD
3438
3441
  try {
3439
3442
  if (!this._enabled) return Promise.resolve();
3440
3443
  const t2 = __spreadProps(__spreadValues({}, this._trackJSData), { message: e2 });
3441
- yield ps({ method: "POST", url: this._url, data: JSON.stringify(t2), options: { contentType: "text/plain" } });
3444
+ yield fs({ method: "POST", url: this._url, data: JSON.stringify(t2), options: { contentType: "text/plain" } });
3442
3445
  } catch (e3) {
3443
3446
  console.error("[TalkJS] Failed when sending an error report. Error: ", e3);
3444
3447
  }
3445
3448
  });
3446
3449
  }
3447
3450
  }("970cd0be0fb74630b75c8451051299dc");
3448
- class As {
3451
+ class Es {
3449
3452
  constructor(e2, t2 = {}) {
3450
3453
  this._onSubscription = t2, this._handlers = {};
3451
3454
  for (const t3 in e2) Object.hasOwnProperty.call(e2, t3) && (this._handlers[t3] = []);
@@ -3490,9 +3493,9 @@ class As {
3490
3493
  return this.on(e2, t2), { unsubscribe: () => this.off(e2, t2) };
3491
3494
  }
3492
3495
  }
3493
- class Es {
3496
+ class ks {
3494
3497
  constructor(e2, t2, s2, n2, r2, i2) {
3495
- if (this.appId = t2, this.userId = s2, this.tokenFetcher = r2, this.usingBokens = false, this.requestInProgress = false, this.eventEmitter = new As({ tokenChanged(e3) {
3498
+ if (this.appId = t2, this.userId = s2, this.tokenFetcher = r2, this.usingBokens = false, this.requestInProgress = false, this.eventEmitter = new Es({ tokenChanged(e3) {
3496
3499
  }, tokenRefreshFailed(e3) {
3497
3500
  }, tokenAccepted(e3) {
3498
3501
  } }), this.sessionExpiryWarningTimeoutId = void 0, i2 && (n2 || r2)) throw new Error("[TalkJS] If providing a signature for authentication, you must not provide a token or tokenFetcher.");
@@ -3584,7 +3587,7 @@ class Es {
3584
3587
  const e3 = function(e4) {
3585
3588
  const t3 = e4.split(".");
3586
3589
  if (3 !== t3.length) throw "Token does not contain exactly two `.`. Check that you generated your JWT correctly. It should be `<header>.<payload>.<signature>`.";
3587
- return { header: ks(t3[0]), payload: ks(t3[1]) };
3590
+ return { header: xs(t3[0]), payload: xs(t3[1]) };
3588
3591
  }(s2);
3589
3592
  n2 = e3.header, r2 = e3.payload;
3590
3593
  } catch (e3) {
@@ -3598,7 +3601,7 @@ class Es {
3598
3601
  const e3 = this.checkJwtPayload(r2);
3599
3602
  t2.push(...e3);
3600
3603
  }
3601
- if (t2.length) if (this.usingBokens) Cs.log(`JWT Errors detected by AuthProvider when using bokens: ${t2.join("\n")}`);
3604
+ if (t2.length) if (this.usingBokens) As.log(`JWT Errors detected by AuthProvider when using bokens: ${t2.join("\n")}`);
3602
3605
  else {
3603
3606
  console.warn("[TalkJS] Authentication token appears to be generated incorrectly. Will still attempt to authenticate, but TalkJS may not work as expected. See below for a description of any problems and how to fix them.");
3604
3607
  const s3 = t2.length > 1;
@@ -3627,7 +3630,7 @@ class Es {
3627
3630
  sendBokenRequest(e2, t2) {
3628
3631
  return __async(this, null, function* () {
3629
3632
  let s2 = 0;
3630
- const n2 = e2.getBokensUrl(this.appId, this.userId, t2), r2 = yield ps({ method: "GET", url: n2, attempts: 1e4, shouldRetry: (e3) => {
3633
+ const n2 = e2.getBokensUrl(this.appId, this.userId, t2), r2 = yield fs({ method: "GET", url: n2, attempts: 1e4, shouldRetry: (e3) => {
3631
3634
  if (e3 instanceof Error) return true;
3632
3635
  if (401 === e3.status) throw "Check that you provided a valid signature.";
3633
3636
  if (404 === e3.status) throw "Check that you specified the correct App ID.";
@@ -3640,7 +3643,7 @@ class Es {
3640
3643
  });
3641
3644
  }
3642
3645
  }
3643
- function ks(e2) {
3646
+ function xs(e2) {
3644
3647
  try {
3645
3648
  const t2 = e2.replace(/-/g, "+").replace(/_/g, "/"), s2 = decodeURIComponent(atob(t2).split("").map((e3) => "%" + ("00" + e3.charCodeAt(0).toString(16)).slice(-2)).join(""));
3646
3649
  return JSON.parse(s2);
@@ -3648,7 +3651,7 @@ function ks(e2) {
3648
3651
  throw `Could not base64-decode and JSON-parse token section: ${e2}. Check that you base-64 encoded the section correctly.`;
3649
3652
  }
3650
3653
  }
3651
- class xs {
3654
+ class Is {
3652
3655
  constructor(e2) {
3653
3656
  this.target = e2;
3654
3657
  }
@@ -3656,7 +3659,7 @@ class xs {
3656
3659
  return this.target;
3657
3660
  }
3658
3661
  }
3659
- const Is = new class {
3662
+ const Ts = new class {
3660
3663
  constructor() {
3661
3664
  this.registry = {};
3662
3665
  }
@@ -3664,7 +3667,7 @@ const Is = new class {
3664
3667
  var _a2;
3665
3668
  const t2 = this.key(e2), s2 = (_a2 = this.registry[t2]) == null ? void 0 : _a2.deref();
3666
3669
  if (s2) return s2;
3667
- const n2 = new Ss(e2), r2 = globalThis.WeakRef ? new WeakRef(n2) : new xs(n2);
3670
+ const n2 = new Ds(e2), r2 = globalThis.WeakRef ? new WeakRef(n2) : new Is(n2);
3668
3671
  return this.registry[t2] = r2, n2;
3669
3672
  }
3670
3673
  deregister(e2, t2) {
@@ -3675,10 +3678,10 @@ const Is = new class {
3675
3678
  return `${e2}:${t2}`;
3676
3679
  }
3677
3680
  }();
3678
- function Ts(e2) {
3679
- return e2.forceCreateNew ? new Ss(e2) : Is.getOrCreate(e2);
3681
+ function Ss(e2) {
3682
+ return e2.forceCreateNew ? new Ds(e2) : Ts.getOrCreate(e2);
3680
3683
  }
3681
- class Ss {
3684
+ class Ds {
3682
3685
  constructor(e2) {
3683
3686
  !function(e3) {
3684
3687
  function t3(e4, t4) {
@@ -3688,13 +3691,13 @@ class Ss {
3688
3691
  void 0 !== e3.tokenFetcher && t3("function" == typeof e3.tokenFetcher, "The `tokenFetcher` property of TalkSession#constructor must be a function.");
3689
3692
  }(e2);
3690
3693
  const { appId: t2, userId: s2, token: n2, tokenFetcher: r2, signature: i2 } = e2;
3691
- this._appId = t2, this._apiUrls = e2.apiUrls ? new ds(e2.apiUrls.realtimeWsApiUrl, e2.apiUrls.internalHttpApiUrl, e2.apiUrls.restApiHttpUrl) : ds.fromHost(e2.host), this._authProvider = new Es(this._apiUrls, t2, s2, n2, r2, i2);
3694
+ 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);
3692
3695
  const a2 = Math.random().toString().split(".")[1];
3693
- this._realtimeClient = new Ie(this._apiUrls.getRealtimeWsUrl(t2, s2, "1.4.2", a2, e2.clientBuild), s2, this._authProvider), this.currentUser = new De(this._realtimeClient.userId, this._realtimeClient), this._terminationReason = o(), this._terminationReason.promise.then((e3) => {
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) => {
3694
3697
  console.error(`[TalkSession] ${e3}`);
3695
3698
  }), function(e3, t3, s3) {
3696
3699
  return __async(this, null, function* () {
3697
- return ps({ method: "GET", url: `${t3}/${e3}/app`, authProvider: s3 }).then((e4) => 200 === e4.status || 404 !== e4.status && (console.warn(`[TalkJS] Received unexpected ${e4.status} status code when validating app ID. Assuming that the app ID is valid.`), true)).catch((e4) => {
3700
+ return fs({ method: "GET", url: `${t3}/${e3}/app`, authProvider: s3 }).then((e4) => 200 === e4.status || 404 !== e4.status && (console.warn(`[TalkJS] Received unexpected ${e4.status} status code when validating app ID. Assuming that the app ID is valid.`), true)).catch((e4) => {
3698
3701
  if ("string" != typeof e4 && "status" in e4) {
3699
3702
  const t4 = e4;
3700
3703
  return 200 === t4.status || 404 !== t4.status && (console.warn(`[TalkJS] Received unexpected ${t4.status} status code when validating app ID. Assuming that the app ID is valid.`), true);
@@ -3722,37 +3725,37 @@ class Ss {
3722
3725
  conversation(e2) {
3723
3726
  if ("string" != typeof e2) throw new Error(`Creating ConversationRef failed because ID "${e2}" is not a string`);
3724
3727
  if ("" === e2) throw new Error(`Creating ConversationRef failed because ID "${e2}" is an empty string`);
3725
- return new cs(e2, this._realtimeClient);
3728
+ return new ls(e2, this._realtimeClient);
3726
3729
  }
3727
3730
  subscribeConversations(e2) {
3728
3731
  return this._realtimeClient.subscribe(["me", "conversations"], e2);
3729
3732
  }
3730
3733
  terminate(e2) {
3731
- Is.deregister(this._appId, this.currentUser.id), this._terminationReason.resolve(e2), this._realtimeClient.destroy();
3734
+ Ts.deregister(this._appId, this.currentUser.id), this._terminationReason.resolve(e2), this._realtimeClient.destroy();
3732
3735
  }
3733
3736
  _isConnected() {
3734
3737
  return this._realtimeClient.isConnected();
3735
3738
  }
3736
3739
  uploadFile(e2, t2) {
3737
- return Ds(`${this._apiUrls.restApiHttpUrl}/${this._appId}/files`, this._authProvider, e2, t2);
3740
+ return Ms(`${this._apiUrls.restApiHttpUrl}/${this._appId}/files`, this._authProvider, e2, t2);
3738
3741
  }
3739
3742
  uploadImage(e2, t2) {
3740
- return Ds(`${this._apiUrls.restApiHttpUrl}/${this._appId}/files`, this._authProvider, e2, __spreadValues({ subtype: "image" }, t2));
3743
+ return Ms(`${this._apiUrls.restApiHttpUrl}/${this._appId}/files`, this._authProvider, e2, __spreadValues({ subtype: "image" }, t2));
3741
3744
  }
3742
3745
  uploadVideo(e2, t2) {
3743
- return Ds(`${this._apiUrls.restApiHttpUrl}/${this._appId}/files`, this._authProvider, e2, __spreadValues({ subtype: "video" }, t2));
3746
+ return Ms(`${this._apiUrls.restApiHttpUrl}/${this._appId}/files`, this._authProvider, e2, __spreadValues({ subtype: "video" }, t2));
3744
3747
  }
3745
3748
  uploadAudio(e2, t2) {
3746
- return Ds(`${this._apiUrls.restApiHttpUrl}/${this._appId}/files`, this._authProvider, e2, __spreadValues({ subtype: "audio" }, t2));
3749
+ return Ms(`${this._apiUrls.restApiHttpUrl}/${this._appId}/files`, this._authProvider, e2, __spreadValues({ subtype: "audio" }, t2));
3747
3750
  }
3748
3751
  uploadVoice(e2, t2) {
3749
- return Ds(`${this._apiUrls.restApiHttpUrl}/${this._appId}/files`, this._authProvider, e2, __spreadValues({ subtype: "voice" }, t2));
3752
+ return Ms(`${this._apiUrls.restApiHttpUrl}/${this._appId}/files`, this._authProvider, e2, __spreadValues({ subtype: "voice" }, t2));
3750
3753
  }
3751
3754
  }
3752
- function Ds(_0, _1, _2, _3) {
3755
+ function Ms(_0, _1, _2, _3) {
3753
3756
  return __async(this, arguments, function* (e2, t2, s2, { subtype: n2, filename: r2, width: i2, height: a2, duration: o2 }) {
3754
3757
  const u2 = new FormData();
3755
- return u2.set("file", s2, r2), void 0 !== n2 && u2.set("subtype", n2), void 0 !== i2 && u2.set("width", i2.toString()), void 0 !== a2 && u2.set("height", a2.toString()), void 0 !== o2 && u2.set("duration", o2.toString()), ps({ method: "POST", url: e2, data: u2, authProvider: t2 }).then((e3) => e3.json()).then((e3) => e3.attachmentToken).catch((e3) => __async(this, null, function* () {
3758
+ return u2.set("file", s2, r2), void 0 !== n2 && u2.set("subtype", n2), void 0 !== i2 && u2.set("width", i2.toString()), void 0 !== a2 && u2.set("height", a2.toString()), void 0 !== o2 && u2.set("duration", o2.toString()), fs({ method: "POST", url: e2, data: u2, authProvider: t2 }).then((e3) => e3.json()).then((e3) => e3.attachmentToken).catch((e3) => __async(this, null, function* () {
3756
3759
  if (e3 instanceof Response) {
3757
3760
  const t3 = yield e3.json(), s3 = `Unexpected response when uploading file, status code ${e3.status} ${t3.errorCode}, ${t3.reasons}`;
3758
3761
  throw new Error(s3);
@@ -3762,7 +3765,7 @@ function Ds(_0, _1, _2, _3) {
3762
3765
  });
3763
3766
  }
3764
3767
  export {
3765
- Ts as getTalkSession,
3768
+ Ss as getTalkSession,
3766
3769
  f as registerPolyfills
3767
3770
  };
3768
3771
  //# sourceMappingURL=talkSession.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@talkjs/core",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
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"
@@ -14,6 +14,7 @@
14
14
  "dist/talkSession.d.ts",
15
15
  "LICENSE.md"
16
16
  ],
17
+ "browser": "./dist/talkSession.js",
17
18
  "main": "./dist/talkSession.cjs",
18
19
  "module": "./dist/talkSession.js",
19
20
  "types": "./dist/talkSession.d.ts",
@@ -70,4 +71,4 @@
70
71
  "notification",
71
72
  "notifications"
72
73
  ]
73
- }
74
+ }