@twilio/conversations 2.1.0-rc.1 → 2.1.0-rc.5

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 (67) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/NOTICE.txt +679 -0
  3. package/builds/browser.js +676 -587
  4. package/builds/browser.js.map +1 -1
  5. package/builds/lib.d.ts +287 -117
  6. package/builds/lib.js +676 -587
  7. package/builds/lib.js.map +1 -1
  8. package/builds/twilio-conversations.js +854 -909
  9. package/builds/twilio-conversations.min.js +2 -14
  10. package/dist/aggregated-delivery-receipt.js +6 -1
  11. package/dist/aggregated-delivery-receipt.js.map +1 -1
  12. package/dist/client.js +165 -142
  13. package/dist/client.js.map +1 -1
  14. package/dist/command-executor.js +16 -14
  15. package/dist/command-executor.js.map +1 -1
  16. package/dist/configuration.js +14 -10
  17. package/dist/configuration.js.map +1 -1
  18. package/dist/conversation.js +212 -153
  19. package/dist/conversation.js.map +1 -1
  20. package/dist/data/conversations.js +81 -77
  21. package/dist/data/conversations.js.map +1 -1
  22. package/dist/data/messages.js +42 -38
  23. package/dist/data/messages.js.map +1 -1
  24. package/dist/data/participants.js +93 -75
  25. package/dist/data/participants.js.map +1 -1
  26. package/dist/data/users.js +24 -22
  27. package/dist/data/users.js.map +1 -1
  28. package/dist/detailed-delivery-receipt.js +1 -1
  29. package/dist/detailed-delivery-receipt.js.map +1 -1
  30. package/dist/interfaces/attributes.js +4 -4
  31. package/dist/interfaces/attributes.js.map +1 -1
  32. package/dist/interfaces/notification-types.js +5 -5
  33. package/dist/interfaces/notification-types.js.map +1 -1
  34. package/dist/logger.js +36 -15
  35. package/dist/logger.js.map +1 -1
  36. package/dist/media.js +21 -9
  37. package/dist/media.js.map +1 -1
  38. package/dist/message-builder.js +10 -9
  39. package/dist/message-builder.js.map +1 -1
  40. package/dist/message.js +130 -81
  41. package/dist/message.js.map +1 -1
  42. package/dist/packages/conversations/package.json.js +1 -1
  43. package/dist/participant.js +85 -51
  44. package/dist/participant.js.map +1 -1
  45. package/dist/push-notification.js.map +1 -1
  46. package/dist/rest-paginator.js +16 -6
  47. package/dist/rest-paginator.js.map +1 -1
  48. package/dist/services/network.js +18 -14
  49. package/dist/services/network.js.map +1 -1
  50. package/dist/services/typing-indicator.js +20 -17
  51. package/dist/services/typing-indicator.js.map +1 -1
  52. package/dist/unsent-message.js.map +1 -1
  53. package/dist/user.js +85 -59
  54. package/dist/user.js.map +1 -1
  55. package/dist/util/deferred.js +3 -1
  56. package/dist/util/deferred.js.map +1 -1
  57. package/dist/util/index.js +6 -6
  58. package/dist/util/index.js.map +1 -1
  59. package/docs/classes/Client.html +24 -30
  60. package/docs/classes/Conversation.html +30 -30
  61. package/docs/classes/DetailedDeliveryReceipt.html +1 -1
  62. package/docs/classes/Message.html +7 -7
  63. package/docs/classes/MessageBuilder.html +2 -2
  64. package/docs/classes/Participant.html +7 -7
  65. package/docs/classes/User.html +7 -7
  66. package/docs/interfaces/CreateConversationOptions.html +1 -1
  67. package/package.json +23 -17
@@ -146,21 +146,21 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
146
146
 
147
147
  var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
148
148
 
149
- const log = logger.Logger.scope('Conversation');
149
+ const log = logger.Logger.scope("Conversation");
150
150
  const fieldMappings = {
151
- lastMessage: 'lastMessage',
152
- attributes: 'attributes',
153
- createdBy: 'createdBy',
154
- dateCreated: 'dateCreated',
155
- dateUpdated: 'dateUpdated',
156
- friendlyName: 'friendlyName',
157
- lastConsumedMessageIndex: 'lastConsumedMessageIndex',
158
- notificationLevel: 'notificationLevel',
159
- sid: 'sid',
160
- status: 'status',
161
- uniqueName: 'uniqueName',
162
- state: 'state',
163
- bindings: 'bindings'
151
+ lastMessage: "lastMessage",
152
+ attributes: "attributes",
153
+ createdBy: "createdBy",
154
+ dateCreated: "dateCreated",
155
+ dateUpdated: "dateUpdated",
156
+ friendlyName: "friendlyName",
157
+ lastConsumedMessageIndex: "lastConsumedMessageIndex",
158
+ notificationLevel: "notificationLevel",
159
+ sid: "sid",
160
+ status: "status",
161
+ uniqueName: "uniqueName",
162
+ state: "state",
163
+ bindings: "bindings",
164
164
  };
165
165
  function parseTime(timeString) {
166
166
  try {
@@ -184,23 +184,25 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
184
184
  this.links = links;
185
185
  this.configuration = configuration;
186
186
  this.services = services;
187
- let attributes = descriptor.attributes || {};
188
- let createdBy = descriptor.createdBy;
189
- let dateCreated = parseTime(descriptor.dateCreated);
190
- let dateUpdated = parseTime(descriptor.dateUpdated);
191
- let friendlyName = descriptor.friendlyName || null;
192
- let lastReadMessageIndex = Number.isInteger(descriptor.lastConsumedMessageIndex) ? descriptor.lastConsumedMessageIndex : null;
193
- let uniqueName = descriptor.uniqueName || null;
187
+ const attributes = descriptor.attributes || {};
188
+ const createdBy = descriptor.createdBy;
189
+ const dateCreated = parseTime(descriptor.dateCreated);
190
+ const dateUpdated = parseTime(descriptor.dateUpdated);
191
+ const friendlyName = descriptor.friendlyName || null;
192
+ const lastReadMessageIndex = Number.isInteger(descriptor.lastConsumedMessageIndex)
193
+ ? descriptor.lastConsumedMessageIndex
194
+ : null;
195
+ const uniqueName = descriptor.uniqueName || null;
194
196
  try {
195
197
  JSON.stringify(attributes);
196
198
  }
197
199
  catch (e) {
198
- throw new Error('Attributes must be a valid JSON object.');
200
+ throw new Error("Attributes must be a valid JSON object.");
199
201
  }
200
202
  this.entityName = descriptor.channel;
201
203
  this.channelState = {
202
204
  uniqueName,
203
- status: 'notParticipating',
205
+ status: "notParticipating",
204
206
  attributes,
205
207
  createdBy,
206
208
  dateCreated,
@@ -213,64 +215,93 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
213
215
  this.channelState.notificationLevel = descriptor.notificationLevel;
214
216
  }
215
217
  const participantsLinks = {
216
- participants: this.links.participants
218
+ participants: this.links.participants,
217
219
  };
218
220
  this.participants = new Map();
219
221
  this.participantsEntity = new participants.Participants(this, this.participants, participantsLinks, this.configuration, this.services);
220
- this.participantsEntity.on('participantJoined', this.emit.bind(this, 'participantJoined'));
221
- this.participantsEntity.on('participantLeft', this.emit.bind(this, 'participantLeft'));
222
- this.participantsEntity.on('participantUpdated', (args) => this.emit('participantUpdated', args));
222
+ this.participantsEntity.on("participantJoined", (participant) => this.emit("participantJoined", participant));
223
+ this.participantsEntity.on("participantLeft", (participant) => this.emit("participantLeft", participant));
224
+ this.participantsEntity.on("participantUpdated", (args) => this.emit("participantUpdated", args));
223
225
  this.messagesEntity = new messages.Messages(this, configuration, services);
224
- this.messagesEntity.on('messageAdded', message => this._onMessageAdded(message));
225
- this.messagesEntity.on('messageUpdated', (args) => this.emit('messageUpdated', args));
226
- this.messagesEntity.on('messageRemoved', this.emit.bind(this, 'messageRemoved'));
226
+ this.messagesEntity.on("messageAdded", (message) => this._onMessageAdded(message));
227
+ this.messagesEntity.on("messageUpdated", (args) => this.emit("messageUpdated", args));
228
+ this.messagesEntity.on("messageRemoved", (message) => this.emit("messageRemoved", message));
227
229
  }
228
230
  /**
229
231
  * Unique name of the conversation.
230
232
  */
231
- get uniqueName() { return this.channelState.uniqueName; }
233
+ get uniqueName() {
234
+ return this.channelState.uniqueName;
235
+ }
232
236
  /**
233
237
  * Status of the conversation.
234
238
  */
235
- get status() { return this.channelState.status; }
239
+ get status() {
240
+ return this.channelState.status;
241
+ }
236
242
  /**
237
243
  * Name of the conversation.
238
244
  */
239
- get friendlyName() { return this.channelState.friendlyName; }
245
+ get friendlyName() {
246
+ return this.channelState.friendlyName;
247
+ }
240
248
  /**
241
249
  * Date this conversation was last updated on.
242
250
  */
243
- get dateUpdated() { return this.channelState.dateUpdated; }
251
+ get dateUpdated() {
252
+ return this.channelState.dateUpdated;
253
+ }
244
254
  /**
245
255
  * Date this conversation was created on.
246
256
  */
247
- get dateCreated() { return this.channelState.dateCreated; }
257
+ get dateCreated() {
258
+ return this.channelState.dateCreated;
259
+ }
248
260
  /**
249
261
  * Identity of the user that created this conversation.
250
262
  */
251
- get createdBy() { return this.channelState.createdBy; }
263
+ get createdBy() {
264
+ var _a;
265
+ return (_a = this.channelState.createdBy) !== null && _a !== void 0 ? _a : "";
266
+ }
252
267
  /**
253
268
  * Custom attributes of the conversation.
254
269
  */
255
- get attributes() { return this.channelState.attributes; }
270
+ get attributes() {
271
+ return this.channelState.attributes;
272
+ }
256
273
  /**
257
274
  * Index of the last message the user has read in this conversation.
258
275
  */
259
- get lastReadMessageIndex() { return this.channelState.lastReadMessageIndex; }
276
+ get lastReadMessageIndex() {
277
+ return this.channelState.lastReadMessageIndex;
278
+ }
260
279
  /**
261
280
  * Last message sent to this conversation.
262
281
  */
263
- get lastMessage() { return this.channelState.lastMessage; }
282
+ get lastMessage() {
283
+ var _a;
284
+ return (_a = this.channelState.lastMessage) !== null && _a !== void 0 ? _a : undefined;
285
+ }
264
286
  /**
265
287
  * User notification level for this conversation.
266
288
  */
267
- get notificationLevel() { return this.channelState.notificationLevel; }
268
- get bindings() { return this.channelState.bindings; }
269
- get limits() { return this.configuration.limits; }
289
+ get notificationLevel() {
290
+ var _a;
291
+ return (_a = this.channelState.notificationLevel) !== null && _a !== void 0 ? _a : "default";
292
+ }
293
+ get bindings() {
294
+ return this.channelState.bindings;
295
+ }
296
+ get limits() {
297
+ return this.configuration.limits;
298
+ }
270
299
  /**
271
300
  * State of the conversation.
272
301
  */
273
- get state() { return this.channelState.state; }
302
+ get state() {
303
+ return this.channelState.state;
304
+ }
274
305
  /**
275
306
  * Load and subscribe to this conversation and do not subscribe to its participants and messages.
276
307
  * This or _subscribeStreams will need to be called before any events on conversation will fire.
@@ -278,23 +309,27 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
278
309
  */
279
310
  _subscribe() {
280
311
  var _a;
281
- return this.entityPromise = (_a = this.entityPromise) !== null && _a !== void 0 ? _a : this.services.syncClient.document({ id: this.entityName, mode: 'open_existing' })
282
- .then(entity => {
283
- this.entity = entity;
284
- this.entity.on('updated', args => { this._update(args.data); });
285
- this.entity.on('removed', () => this.emit('removed', this));
286
- this._update(this.entity.data);
287
- return entity;
288
- })
289
- .catch(err => {
290
- this.entity = null;
291
- this.entityPromise = null;
292
- if (this.services.syncClient.connectionState != 'disconnected') {
293
- log.error('Failed to get conversation object', err);
294
- }
295
- log.debug('ERROR: Failed to get conversation object', err);
296
- throw err;
297
- });
312
+ return (this.entityPromise =
313
+ (_a = this.entityPromise) !== null && _a !== void 0 ? _a : this.services.syncClient
314
+ .document({ id: this.entityName, mode: "open_existing" })
315
+ .then((entity) => {
316
+ this.entity = entity;
317
+ this.entity.on("updated", (args) => {
318
+ this._update(args.data);
319
+ });
320
+ this.entity.on("removed", () => this.emit("removed", this));
321
+ this._update(this.entity.data);
322
+ return entity;
323
+ })
324
+ .catch((err) => {
325
+ this.entity = null;
326
+ this.entityPromise = null;
327
+ if (this.services.syncClient.connectionState != "disconnected") {
328
+ log.error("Failed to get conversation object", err);
329
+ }
330
+ log.debug("ERROR: Failed to get conversation object", err);
331
+ throw err;
332
+ }));
298
333
  }
299
334
  /**
300
335
  * Load the attributes of this conversation and instantiate its participants and messages.
@@ -303,21 +338,24 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
303
338
  * @internal
304
339
  */
305
340
  async _subscribeStreams() {
341
+ var _a, _b, _c;
306
342
  try {
307
343
  await this._subscribe();
308
- log.trace('_subscribeStreams, this.entity.data=', this.entity.data);
309
- const messagesObjectName = this.entity.data.messages;
310
- const rosterObjectName = this.entity.data.roster;
344
+ log.trace("_subscribeStreams, this.entity.data=", (_a = this.entity) === null || _a === void 0 ? void 0 : _a.data);
345
+ const messagesObjectName = ((_b = this.entity) === null || _b === void 0 ? void 0 : _b.data)
346
+ .messages;
347
+ const rosterObjectName = ((_c = this.entity) === null || _c === void 0 ? void 0 : _c.data)
348
+ .roster;
311
349
  await Promise.all([
312
350
  this.messagesEntity.subscribe(messagesObjectName),
313
- this.participantsEntity.subscribe(rosterObjectName)
351
+ this.participantsEntity.subscribe(rosterObjectName),
314
352
  ]);
315
353
  }
316
354
  catch (err) {
317
- if (this.services.syncClient.connectionState !== 'disconnected') {
318
- log.error('Failed to subscribe on conversation objects', this.sid, err);
355
+ if (this.services.syncClient.connectionState !== "disconnected") {
356
+ log.error("Failed to subscribe on conversation objects", this.sid, err);
319
357
  }
320
- log.debug('ERROR: Failed to subscribe on conversation objects', this.sid, err);
358
+ log.debug("ERROR: Failed to subscribe on conversation objects", this.sid, err);
321
359
  throw err;
322
360
  }
323
361
  }
@@ -333,7 +371,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
333
371
  }
334
372
  return Promise.all([
335
373
  this.participantsEntity.unsubscribe(),
336
- this.messagesEntity.unsubscribe()
374
+ this.messagesEntity.unsubscribe(),
337
375
  ]);
338
376
  }
339
377
  /**
@@ -346,19 +384,18 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
346
384
  return;
347
385
  }
348
386
  this.channelState.status = status;
349
- if (status === 'joined') {
350
- this._subscribeStreams()
351
- .catch(err => {
352
- log.debug('ERROR while setting conversation status ' + status, err);
353
- if (this.services.syncClient.connectionState !== 'disconnected') {
387
+ if (status === "joined") {
388
+ this._subscribeStreams().catch((err) => {
389
+ log.debug("ERROR while setting conversation status " + status, err);
390
+ if (this.services.syncClient.connectionState !== "disconnected") {
354
391
  throw err;
355
392
  }
356
393
  });
357
394
  }
358
395
  else if (this.entityPromise) {
359
- this._unsubscribe().catch(err => {
360
- log.debug('ERROR while setting conversation status ' + status, err);
361
- if (this.services.syncClient.connectionState !== 'disconnected') {
396
+ this._unsubscribe().catch((err) => {
397
+ log.debug("ERROR while setting conversation status " + status, err);
398
+ if (this.services.syncClient.connectionState !== "disconnected") {
362
399
  throw err;
363
400
  }
364
401
  });
@@ -373,7 +410,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
373
410
  }
374
411
  static preprocessUpdate(update, conversationSid) {
375
412
  try {
376
- if (typeof update.attributes === 'string') {
413
+ if (typeof update.attributes === "string") {
377
414
  update.attributes = JSON.parse(update.attributes);
378
415
  }
379
416
  else if (update.attributes) {
@@ -381,7 +418,8 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
381
418
  }
382
419
  }
383
420
  catch (e) {
384
- log.warn('Retrieved malformed attributes from the server for conversation: ' + conversationSid);
421
+ log.warn("Retrieved malformed attributes from the server for conversation: " +
422
+ conversationSid);
385
423
  update.attributes = {};
386
424
  }
387
425
  try {
@@ -390,7 +428,8 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
390
428
  }
391
429
  }
392
430
  catch (e) {
393
- log.warn('Retrieved malformed dateCreated from the server for conversation: ' + conversationSid);
431
+ log.warn("Retrieved malformed dateCreated from the server for conversation: " +
432
+ conversationSid);
394
433
  delete update.dateCreated;
395
434
  }
396
435
  try {
@@ -399,7 +438,8 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
399
438
  }
400
439
  }
401
440
  catch (e) {
402
- log.warn('Retrieved malformed dateUpdated from the server for conversation: ' + conversationSid);
441
+ log.warn("Retrieved malformed dateUpdated from the server for conversation: " +
442
+ conversationSid);
403
443
  delete update.dateUpdated;
404
444
  }
405
445
  try {
@@ -408,7 +448,8 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
408
448
  }
409
449
  }
410
450
  catch (e) {
411
- log.warn('Retrieved malformed lastMessage.timestamp from the server for conversation: ' + conversationSid);
451
+ log.warn("Retrieved malformed lastMessage.timestamp from the server for conversation: " +
452
+ conversationSid);
412
453
  delete update.lastMessage.timestamp;
413
454
  }
414
455
  }
@@ -418,7 +459,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
418
459
  */
419
460
  _update(update) {
420
461
  var _a, _b, _c, _d, _e;
421
- log.trace('_update', update);
462
+ log.trace("_update", update);
422
463
  Conversation.preprocessUpdate(update, this.sid);
423
464
  const updateReasons = new Set();
424
465
  for (const key of Object.keys(update)) {
@@ -428,8 +469,9 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
428
469
  }
429
470
  switch (localKey) {
430
471
  case fieldMappings.status:
431
- if (!update.status || update.status === 'unknown'
432
- || this.channelState.status === update.status) {
472
+ if (!update.status ||
473
+ update.status === "unknown" ||
474
+ this.channelState.status === update.status) {
433
475
  break;
434
476
  }
435
477
  this.channelState.status = update.status;
@@ -443,12 +485,14 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
443
485
  updateReasons.add(localKey);
444
486
  break;
445
487
  case fieldMappings.lastConsumedMessageIndex:
446
- if (update.lastConsumedMessageIndex === undefined
447
- || update.lastConsumedMessageIndex === this.channelState.lastReadMessageIndex) {
488
+ if (update.lastConsumedMessageIndex === undefined ||
489
+ update.lastConsumedMessageIndex ===
490
+ this.channelState.lastReadMessageIndex) {
448
491
  break;
449
492
  }
450
- this.channelState.lastReadMessageIndex = update.lastConsumedMessageIndex;
451
- updateReasons.add('lastReadMessageIndex');
493
+ this.channelState.lastReadMessageIndex =
494
+ update.lastConsumedMessageIndex;
495
+ updateReasons.add("lastReadMessageIndex");
452
496
  break;
453
497
  case fieldMappings.lastMessage:
454
498
  if (this.channelState.lastMessage && !update.lastMessage) {
@@ -457,14 +501,16 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
457
501
  break;
458
502
  }
459
503
  this.channelState.lastMessage = this.channelState.lastMessage || {};
460
- if (((_a = update.lastMessage) === null || _a === void 0 ? void 0 : _a.index) !== undefined
461
- && update.lastMessage.index !== this.channelState.lastMessage.index) {
504
+ if (((_a = update.lastMessage) === null || _a === void 0 ? void 0 : _a.index) !== undefined &&
505
+ update.lastMessage.index !== this.channelState.lastMessage.index) {
462
506
  this.channelState.lastMessage.index = update.lastMessage.index;
463
507
  updateReasons.add(localKey);
464
508
  }
465
- if (((_b = update.lastMessage) === null || _b === void 0 ? void 0 : _b.timestamp) !== undefined
466
- && ((_d = (_c = this.channelState.lastMessage) === null || _c === void 0 ? void 0 : _c.dateCreated) === null || _d === void 0 ? void 0 : _d.getTime()) !== update.lastMessage.timestamp.getTime()) {
467
- this.channelState.lastMessage.dateCreated = update.lastMessage.timestamp;
509
+ if (((_b = update.lastMessage) === null || _b === void 0 ? void 0 : _b.timestamp) !== undefined &&
510
+ ((_d = (_c = this.channelState.lastMessage) === null || _c === void 0 ? void 0 : _c.dateCreated) === null || _d === void 0 ? void 0 : _d.getTime()) !==
511
+ update.lastMessage.timestamp.getTime()) {
512
+ this.channelState.lastMessage.dateCreated =
513
+ update.lastMessage.timestamp;
468
514
  updateReasons.add(localKey);
469
515
  }
470
516
  if (isEqual__default['default'](this.channelState.lastMessage, {})) {
@@ -491,7 +537,8 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
491
537
  break;
492
538
  default:
493
539
  const isDate = update[key] instanceof Date;
494
- const keysMatchAsDates = isDate && ((_e = this.channelState[localKey]) === null || _e === void 0 ? void 0 : _e.getTime()) === update[key].getTime();
540
+ const keysMatchAsDates = isDate &&
541
+ ((_e = this.channelState[localKey]) === null || _e === void 0 ? void 0 : _e.getTime()) === update[key].getTime();
495
542
  const keysMatchAsNonDates = !isDate && this[localKey] === update[key];
496
543
  if (keysMatchAsDates || keysMatchAsNonDates) {
497
544
  break;
@@ -501,24 +548,27 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
501
548
  }
502
549
  }
503
550
  if (updateReasons.size > 0) {
504
- this.emit('updated', { conversation: this, updateReasons: [...updateReasons] });
551
+ this.emit("updated", {
552
+ conversation: this,
553
+ updateReasons: [...updateReasons],
554
+ });
505
555
  }
506
556
  }
507
557
  /**
508
558
  * @internal
509
559
  */
510
560
  _onMessageAdded(message) {
511
- for (let participant of this.participants.values()) {
561
+ for (const participant of this.participants.values()) {
512
562
  if (participant.identity === message.author) {
513
563
  participant._endTyping();
514
564
  break;
515
565
  }
516
566
  }
517
- this.emit('messageAdded', message);
567
+ this.emit("messageAdded", message);
518
568
  }
519
569
  async _setLastReadMessageIndex(index) {
520
- const result = await this.services.commandExecutor.mutateResource('post', `${this.configuration.links.myConversations}/${this.sid}`, {
521
- last_read_message_index: index
570
+ const result = await this.services.commandExecutor.mutateResource("post", `${this.configuration.links.myConversations}/${this.sid}`, {
571
+ last_read_message_index: index,
522
572
  });
523
573
  return result.unread_messages_count;
524
574
  }
@@ -549,7 +599,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
549
599
  */
550
600
  async advanceLastReadMessageIndex(index) {
551
601
  await this._subscribeStreams();
552
- if (index < this.lastReadMessageIndex) {
602
+ if (index < (this.lastReadMessageIndex || 0)) {
553
603
  return await this._setLastReadMessageIndex(this.lastReadMessageIndex);
554
604
  }
555
605
  return await this._setLastReadMessageIndex(index);
@@ -558,7 +608,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
558
608
  * Delete the conversation and unsubscribe from its events.
559
609
  */
560
610
  async delete() {
561
- await this.services.commandExecutor.mutateResource('delete', this.links.self);
611
+ await this.services.commandExecutor.mutateResource("delete", this.links.self);
562
612
  return this;
563
613
  }
564
614
  /**
@@ -598,11 +648,12 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
598
648
  * logic based on these counters being accurate in real time.
599
649
  */
600
650
  async getParticipantsCount() {
651
+ var _a;
601
652
  const url = new index.UriBuilder(this.configuration.links.conversations)
602
653
  .path(this.sid)
603
654
  .build();
604
655
  const response = await this.services.network.get(url);
605
- return response.body.participants_count;
656
+ return (_a = response.body.participants_count) !== null && _a !== void 0 ? _a : 0;
606
657
  }
607
658
  /**
608
659
  * Get a participant by its SID.
@@ -615,8 +666,8 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
615
666
  * Get a participant by its identity.
616
667
  * @param identity Participant identity.
617
668
  */
618
- async getParticipantByIdentity(identity) {
619
- return this.participantsEntity.getParticipantByIdentity(identity);
669
+ async getParticipantByIdentity(identity = "") {
670
+ return this.participantsEntity.getParticipantByIdentity(identity !== null && identity !== void 0 ? identity : "");
620
671
  }
621
672
  /**
622
673
  * Get the total message count in the conversation.
@@ -629,11 +680,12 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
629
680
  * logic based on these counters being accurate in real time.
630
681
  */
631
682
  async getMessagesCount() {
683
+ var _a;
632
684
  const url = new index.UriBuilder(this.configuration.links.conversations)
633
685
  .path(this.sid)
634
686
  .build();
635
687
  const response = await this.services.network.get(url);
636
- return response.body.messages_count;
688
+ return (_a = response.body.messages_count) !== null && _a !== void 0 ? _a : 0;
637
689
  }
638
690
  /**
639
691
  * Get unread messages count for the user if they are a participant of this conversation.
@@ -656,10 +708,10 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
656
708
  .build();
657
709
  const response = await this.services.network.get(url);
658
710
  if (response.body.conversation_sid !== this.sid) {
659
- throw new Error('Conversation was not found in the user conversations list');
711
+ throw new Error("Conversation was not found in the user conversations list");
660
712
  }
661
713
  const unreadMessageCount = response.body.unread_messages_count;
662
- if (typeof unreadMessageCount === 'number') {
714
+ if (typeof unreadMessageCount === "number") {
663
715
  return unreadMessageCount;
664
716
  }
665
717
  return null;
@@ -668,8 +720,8 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
668
720
  * Join the conversation and subscribe to its events.
669
721
  */
670
722
  async join() {
671
- await this.services.commandExecutor.mutateResource('post', this.links.participants, {
672
- identity: this.configuration.userIdentity
723
+ await this.services.commandExecutor.mutateResource("post", this.links.participants, {
724
+ identity: this.configuration.userIdentity,
673
725
  });
674
726
  return this;
675
727
  }
@@ -677,8 +729,8 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
677
729
  * Leave the conversation.
678
730
  */
679
731
  async leave() {
680
- if (this.channelState.status === 'joined') {
681
- await this.services.commandExecutor.mutateResource('delete', `${this.links.participants}/${this.configuration.userIdentity}`);
732
+ if (this.channelState.status === "joined") {
733
+ await this.services.commandExecutor.mutateResource("delete", `${this.links.participants}/${this.configuration.userIdentity}`);
682
734
  }
683
735
  return this;
684
736
  }
@@ -687,10 +739,10 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
687
739
  * argument, it will assume that the string is an identity or SID.
688
740
  * @param participant Identity, SID or the participant object to remove.
689
741
  */
742
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
743
+ // @ts-ignore TODO: fix validateTypesAsync typing
690
744
  async removeParticipant(participant) {
691
- await this.participantsEntity.remove(typeof participant === 'string'
692
- ? participant
693
- : participant.sid);
745
+ await this.participantsEntity.remove(typeof participant === "string" ? participant : participant.sid);
694
746
  }
695
747
  /**
696
748
  * Send a message to the conversation.
@@ -701,12 +753,13 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
701
753
  * @return Index of the new message.
702
754
  */
703
755
  async sendMessage(message, messageAttributes, emailOptions) {
704
- if (typeof message === 'string' || message === null) {
705
- let response = await this.messagesEntity.send(message, messageAttributes, emailOptions);
706
- return index.parseToNumber(response.index);
756
+ var _a, _b;
757
+ if (typeof message === "string" || message === null) {
758
+ const response = await this.messagesEntity.send(message, messageAttributes, emailOptions);
759
+ return (_a = index.parseToNumber(response.index)) !== null && _a !== void 0 ? _a : 0;
707
760
  }
708
- let response = await this.messagesEntity.sendMedia(message, messageAttributes, emailOptions);
709
- return index.parseToNumber(response.index);
761
+ const response = await this.messagesEntity.sendMedia(message, messageAttributes, emailOptions);
762
+ return (_b = index.parseToNumber(response.index)) !== null && _b !== void 0 ? _b : 0;
710
763
  }
711
764
  /**
712
765
  * New interface to prepare for sending a message.
@@ -722,7 +775,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
722
775
  */
723
776
  async setAllMessagesRead() {
724
777
  await this._subscribeStreams();
725
- let messagesPage = await this.getMessages(1);
778
+ const messagesPage = await this.getMessages(1);
726
779
  if (messagesPage.items.length > 0) {
727
780
  return this.advanceLastReadMessageIndex(messagesPage.items[0].index);
728
781
  }
@@ -741,8 +794,8 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
741
794
  * @param notificationLevel New user notification level.
742
795
  */
743
796
  async setUserNotificationLevel(notificationLevel) {
744
- await this.services.commandExecutor.mutateResource('post', `${this.configuration.links.myConversations}/${this.sid}`, {
745
- notification_level: notificationLevel
797
+ await this.services.commandExecutor.mutateResource("post", `${this.configuration.links.myConversations}/${this.sid}`, {
798
+ notification_level: notificationLevel,
746
799
  });
747
800
  }
748
801
  /**
@@ -757,8 +810,8 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
757
810
  * @param attributes New attributes.
758
811
  */
759
812
  async updateAttributes(attributes) {
760
- await this.services.commandExecutor.mutateResource('post', this.links.self, {
761
- attributes: attributes !== undefined ? JSON.stringify(attributes) : undefined
813
+ await this.services.commandExecutor.mutateResource("post", this.links.self, {
814
+ attributes: attributes !== undefined ? JSON.stringify(attributes) : undefined,
762
815
  });
763
816
  return this;
764
817
  }
@@ -768,7 +821,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
768
821
  */
769
822
  async updateFriendlyName(friendlyName) {
770
823
  if (this.channelState.friendlyName !== friendlyName) {
771
- await this.services.commandExecutor.mutateResource('post', this.links.self, { friendly_name: friendlyName });
824
+ await this.services.commandExecutor.mutateResource("post", this.links.self, { friendly_name: friendlyName });
772
825
  }
773
826
  return this;
774
827
  }
@@ -789,10 +842,10 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
789
842
  async updateUniqueName(uniqueName) {
790
843
  if (this.channelState.uniqueName !== uniqueName) {
791
844
  if (!uniqueName) {
792
- uniqueName = '';
845
+ uniqueName = "";
793
846
  }
794
- await this.services.commandExecutor.mutateResource('post', this.links.self, {
795
- unique_name: uniqueName
847
+ await this.services.commandExecutor.mutateResource("post", this.links.self, {
848
+ unique_name: uniqueName,
796
849
  });
797
850
  }
798
851
  return this;
@@ -805,7 +858,7 @@ class Conversation extends replayEventEmitter.ReplayEventEmitter {
805
858
  * 1. {@link Participant} `participant` - participant that joined the conversation
806
859
  * @event
807
860
  */
808
- Conversation.participantJoined = 'participantJoined';
861
+ Conversation.participantJoined = "participantJoined";
809
862
  /**
810
863
  * Fired when a participant has left the conversation.
811
864
  *
@@ -813,7 +866,7 @@ Conversation.participantJoined = 'participantJoined';
813
866
  * 1. {@link Participant} `participant` - participant that left the conversation
814
867
  * @event
815
868
  */
816
- Conversation.participantLeft = 'participantLeft';
869
+ Conversation.participantLeft = "participantLeft";
817
870
  /**
818
871
  * Fired when data of a participant has been updated.
819
872
  *
@@ -823,7 +876,7 @@ Conversation.participantLeft = 'participantLeft';
823
876
  * * {@link ParticipantUpdateReason}[] `updateReasons` - array of reasons for update
824
877
  * @event
825
878
  */
826
- Conversation.participantUpdated = 'participantUpdated';
879
+ Conversation.participantUpdated = "participantUpdated";
827
880
  /**
828
881
  * Fired when a new message has been added to the conversation.
829
882
  *
@@ -831,7 +884,7 @@ Conversation.participantUpdated = 'participantUpdated';
831
884
  * 1. {@link Message} `message` - message that has been added
832
885
  * @event
833
886
  */
834
- Conversation.messageAdded = 'messageAdded';
887
+ Conversation.messageAdded = "messageAdded";
835
888
  /**
836
889
  * Fired when message is removed from the conversation's message list.
837
890
  *
@@ -839,7 +892,7 @@ Conversation.messageAdded = 'messageAdded';
839
892
  * 1. {@link Message} `message` - message that has been removed
840
893
  * @event
841
894
  */
842
- Conversation.messageRemoved = 'messageRemoved';
895
+ Conversation.messageRemoved = "messageRemoved";
843
896
  /**
844
897
  * Fired when data of a message has been updated.
845
898
  *
@@ -849,7 +902,7 @@ Conversation.messageRemoved = 'messageRemoved';
849
902
  * * {@link MessageUpdateReason}[] `updateReasons` - array of reasons for update
850
903
  * @event
851
904
  */
852
- Conversation.messageUpdated = 'messageUpdated';
905
+ Conversation.messageUpdated = "messageUpdated";
853
906
  /**
854
907
  * Fired when a participant has stopped typing.
855
908
  *
@@ -857,7 +910,7 @@ Conversation.messageUpdated = 'messageUpdated';
857
910
  * 1. {@link Participant} `participant` - the participant that has stopped typing
858
911
  * @event
859
912
  */
860
- Conversation.typingEnded = 'typingEnded';
913
+ Conversation.typingEnded = "typingEnded";
861
914
  /**
862
915
  * Fired when a participant has started typing.
863
916
  *
@@ -865,7 +918,7 @@ Conversation.typingEnded = 'typingEnded';
865
918
  * 1. {@link Participant} `participant` - the participant that has started typing
866
919
  * @event
867
920
  */
868
- Conversation.typingStarted = 'typingStarted';
921
+ Conversation.typingStarted = "typingStarted";
869
922
  /**
870
923
  * Fired when the data of the conversation has been updated.
871
924
  *
@@ -875,7 +928,7 @@ Conversation.typingStarted = 'typingStarted';
875
928
  * * {@link ConversationUpdateReason}[] `updateReasons` - array of reasons for update
876
929
  * @event
877
930
  */
878
- Conversation.updated = 'updated';
931
+ Conversation.updated = "updated";
879
932
  /**
880
933
  * Fired when the conversation was destroyed or the currently-logged-in user has left private conversation.
881
934
  *
@@ -883,7 +936,7 @@ Conversation.updated = 'updated';
883
936
  * 1. {@link Conversation} `conversation` - conversation that has been removed
884
937
  * @event
885
938
  */
886
- Conversation.removed = 'removed';
939
+ Conversation.removed = "removed";
887
940
  tslib_es6.__decorate([
888
941
  declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString, attributes.optionalAttributesValidator),
889
942
  tslib_es6.__metadata("design:type", Function),
@@ -903,7 +956,7 @@ tslib_es6.__decorate([
903
956
  tslib_es6.__metadata("design:returntype", Promise)
904
957
  ], Conversation.prototype, "advanceLastReadMessageIndex", null);
905
958
  tslib_es6.__decorate([
906
- declarativeTypeValidator.validateTypesAsync(['undefined', declarativeTypeValidator.nonNegativeInteger], ['undefined', declarativeTypeValidator.nonNegativeInteger], ['undefined', declarativeTypeValidator.literal('backwards', 'forward')]),
959
+ declarativeTypeValidator.validateTypesAsync(["undefined", declarativeTypeValidator.nonNegativeInteger], ["undefined", declarativeTypeValidator.nonNegativeInteger], ["undefined", declarativeTypeValidator.literal("backwards", "forward")]),
907
960
  tslib_es6.__metadata("design:type", Function),
908
961
  tslib_es6.__metadata("design:paramtypes", [Number, Number, String]),
909
962
  tslib_es6.__metadata("design:returntype", Promise)
@@ -928,32 +981,38 @@ tslib_es6.__decorate([
928
981
  ], Conversation.prototype, "removeParticipant", null);
929
982
  tslib_es6.__decorate([
930
983
  declarativeTypeValidator.validateTypesAsync([
931
- 'string',
984
+ "string",
932
985
  declarativeTypeValidator.literal(null),
933
986
  // Wrapping it into a custom rule is necessary because the FormData class is not available on initialization.
934
- declarativeTypeValidator.custom((value) => [value instanceof FormData, 'an instance of FormData']),
935
- declarativeTypeValidator.objectSchema('media options', {
987
+ declarativeTypeValidator.custom((value) => [value instanceof FormData, "an instance of FormData"]),
988
+ declarativeTypeValidator.objectSchema("media options", {
936
989
  contentType: declarativeTypeValidator.nonEmptyString,
937
990
  media: declarativeTypeValidator.custom((value) => {
938
- let isValid = (typeof value === 'string' && value.length > 0) || value instanceof Uint8Array || value instanceof ArrayBuffer;
939
- if (typeof Blob === 'function') {
991
+ let isValid = (typeof value === "string" && value.length > 0) ||
992
+ value instanceof Uint8Array ||
993
+ value instanceof ArrayBuffer;
994
+ if (typeof Blob === "function") {
940
995
  isValid = isValid || value instanceof Blob;
941
996
  }
942
997
  return [
943
998
  isValid,
944
- 'a non-empty string, an instance of Buffer or an instance of Blob'
999
+ "a non-empty string, an instance of Buffer or an instance of Blob",
945
1000
  ];
946
- })
947
- })
948
- ], attributes.optionalAttributesValidator, ['undefined', declarativeTypeValidator.literal(null), declarativeTypeValidator.objectSchema('email attributes', {
949
- subject: [declarativeTypeValidator.nonEmptyString, 'undefined']
950
- })]),
1001
+ }),
1002
+ }),
1003
+ ], attributes.optionalAttributesValidator, [
1004
+ "undefined",
1005
+ declarativeTypeValidator.literal(null),
1006
+ declarativeTypeValidator.objectSchema("email attributes", {
1007
+ subject: [declarativeTypeValidator.nonEmptyString, "undefined"],
1008
+ }),
1009
+ ]),
951
1010
  tslib_es6.__metadata("design:type", Function),
952
1011
  tslib_es6.__metadata("design:paramtypes", [Object, Object, Object]),
953
1012
  tslib_es6.__metadata("design:returntype", Promise)
954
1013
  ], Conversation.prototype, "sendMessage", null);
955
1014
  tslib_es6.__decorate([
956
- declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.literal('default', 'muted')),
1015
+ declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.literal("default", "muted")),
957
1016
  tslib_es6.__metadata("design:type", Function),
958
1017
  tslib_es6.__metadata("design:paramtypes", [String]),
959
1018
  tslib_es6.__metadata("design:returntype", Promise)
@@ -965,7 +1024,7 @@ tslib_es6.__decorate([
965
1024
  tslib_es6.__metadata("design:returntype", Promise)
966
1025
  ], Conversation.prototype, "updateAttributes", null);
967
1026
  tslib_es6.__decorate([
968
- declarativeTypeValidator.validateTypesAsync(['string']),
1027
+ declarativeTypeValidator.validateTypesAsync(["string"]),
969
1028
  tslib_es6.__metadata("design:type", Function),
970
1029
  tslib_es6.__metadata("design:paramtypes", [String]),
971
1030
  tslib_es6.__metadata("design:returntype", Promise)
@@ -977,7 +1036,7 @@ tslib_es6.__decorate([
977
1036
  tslib_es6.__metadata("design:returntype", Promise)
978
1037
  ], Conversation.prototype, "updateLastReadMessageIndex", null);
979
1038
  tslib_es6.__decorate([
980
- declarativeTypeValidator.validateTypesAsync(['string', declarativeTypeValidator.literal(null)]),
1039
+ declarativeTypeValidator.validateTypesAsync(["string", declarativeTypeValidator.literal(null)]),
981
1040
  tslib_es6.__metadata("design:type", Function),
982
1041
  tslib_es6.__metadata("design:paramtypes", [String]),
983
1042
  tslib_es6.__metadata("design:returntype", Promise)