@twilio/conversations 2.1.0-rc.8 → 2.2.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 (70) hide show
  1. package/CHANGELOG.md +174 -0
  2. package/README.md +8 -4
  3. package/builds/browser.js +2916 -1975
  4. package/builds/browser.js.map +1 -1
  5. package/builds/lib.d.ts +574 -284
  6. package/builds/lib.js +2916 -1975
  7. package/builds/lib.js.map +1 -1
  8. package/builds/twilio-conversations.js +27256 -11899
  9. package/builds/twilio-conversations.min.js +1 -16
  10. package/dist/aggregated-delivery-receipt.js.map +1 -1
  11. package/dist/client.js +466 -281
  12. package/dist/client.js.map +1 -1
  13. package/dist/command-executor.js.map +1 -1
  14. package/dist/configuration.js +2 -2
  15. package/dist/configuration.js.map +1 -1
  16. package/dist/conversation.js +428 -369
  17. package/dist/conversation.js.map +1 -1
  18. package/dist/data/conversations.js +25 -13
  19. package/dist/data/conversations.js.map +1 -1
  20. package/dist/data/messages.js +56 -32
  21. package/dist/data/messages.js.map +1 -1
  22. package/dist/data/participants.js +21 -12
  23. package/dist/data/participants.js.map +1 -1
  24. package/dist/data/users.js +2 -2
  25. package/dist/data/users.js.map +1 -1
  26. package/dist/detailed-delivery-receipt.js.map +1 -1
  27. package/dist/index.js +6 -4
  28. package/dist/index.js.map +1 -1
  29. package/dist/interfaces/attributes.js.map +1 -1
  30. package/dist/interfaces/notification-types.js.map +1 -1
  31. package/dist/logger.js +2 -4
  32. package/dist/logger.js.map +1 -1
  33. package/dist/media.js +36 -25
  34. package/dist/media.js.map +1 -1
  35. package/dist/message-builder.js +24 -18
  36. package/dist/message-builder.js.map +1 -1
  37. package/dist/message.js +89 -17
  38. package/dist/message.js.map +1 -1
  39. package/dist/node_modules/tslib/tslib.es6.js +1 -1
  40. package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
  41. package/dist/packages/conversations/package.json.js +1 -1
  42. package/dist/participant.js +2 -2
  43. package/dist/participant.js.map +1 -1
  44. package/dist/push-notification.js.map +1 -1
  45. package/dist/rest-paginator.js.map +1 -1
  46. package/dist/services/network.js.map +1 -1
  47. package/dist/services/typing-indicator.js +1 -1
  48. package/dist/services/typing-indicator.js.map +1 -1
  49. package/dist/unsent-message.js +13 -3
  50. package/dist/unsent-message.js.map +1 -1
  51. package/dist/user.js +2 -2
  52. package/dist/user.js.map +1 -1
  53. package/dist/util/deferred.js.map +1 -1
  54. package/dist/util/index.js.map +1 -1
  55. package/docs/assets/js/search.js +1 -1
  56. package/docs/classes/CancellablePromise.html +3213 -0
  57. package/docs/classes/Client.html +243 -58
  58. package/docs/classes/Conversation.html +99 -47
  59. package/docs/classes/Media.html +2 -28
  60. package/docs/classes/Message.html +94 -39
  61. package/docs/classes/MessageBuilder.html +31 -8
  62. package/docs/classes/PushNotification.html +1 -1
  63. package/docs/classes/UnsentMessage.html +2 -2
  64. package/docs/index.html +25 -28
  65. package/docs/interfaces/ConversationLimits.html +12 -12
  66. package/docs/interfaces/ConversationState.html +2 -2
  67. package/docs/interfaces/ConversationUpdatedEventArgs.html +3001 -0
  68. package/docs/interfaces/PushNotificationData.html +48 -0
  69. package/docs/modules.html +24 -27
  70. package/package.json +24 -20
package/dist/client.js CHANGED
@@ -149,10 +149,13 @@ var declarativeTypeValidator = require('@twilio/declarative-type-validator');
149
149
  var _package = require('./packages/conversations/package.json.js');
150
150
  var commandExecutor = require('./command-executor.js');
151
151
  var replayEventEmitter = require('@twilio/replay-event-emitter');
152
+ var media = require('./media.js');
153
+ var deprecationDecorator = require('@twilio/deprecation-decorator');
152
154
 
153
155
  var Client_1;
154
- const log = logger.Logger.scope("Client");
155
- const SDK_VERSION = _package.version;
156
+ /**
157
+ * Client services.
158
+ */
156
159
  class ClientServices {
157
160
  }
158
161
  /**
@@ -160,9 +163,11 @@ class ClientServices {
160
163
  */
161
164
  exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventEmitter {
162
165
  /**
163
- * Returned Conversations instance is not yet fully initialized. Calling any operations will block until it is.
164
- * Use connection events to monitor when client becomes fully available (connectionStateChanged with state
165
- * 'connected') or not available (connectionStateChange with state 'denied', event tokenExpired, event connectionError).
166
+ * Returned Conversations instance is not yet fully initialized. Calling any
167
+ * operations will block until it is. Use connection events to monitor when
168
+ * client becomes fully available (connectionStateChanged with state
169
+ * 'connected') or not available (connectionStateChange with state 'denied',
170
+ * event tokenExpired, event connectionError).
166
171
  *
167
172
  * @param fpaToken Access token
168
173
  * @param options Options to customize the Client
@@ -171,6 +176,10 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
171
176
  constructor(fpaToken, options = {}) {
172
177
  var _a, _b, _c, _d, _e;
173
178
  super();
179
+ /**
180
+ * Current version of the Conversations client.
181
+ */
182
+ this.version = _package.version;
174
183
  /**
175
184
  * Client connection state.
176
185
  */
@@ -178,98 +187,110 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
178
187
  /**
179
188
  * Current version of the Conversations client.
180
189
  */
181
- this.version = SDK_VERSION;
182
190
  this.parsePushNotification = Client_1.parsePushNotification;
183
- this.fpaToken = fpaToken !== null && fpaToken !== void 0 ? fpaToken : "";
184
- this.options = options !== null && options !== void 0 ? options : {};
185
- if (!this.options.disableDeepClone) {
186
- let options = Object.assign(Object.assign({}, this.options), { transport: undefined, twilsockClient: undefined });
191
+ this._fpaToken = fpaToken !== null && fpaToken !== void 0 ? fpaToken : "";
192
+ this._options = options !== null && options !== void 0 ? options : {};
193
+ if (!this._options.disableDeepClone) {
194
+ let options = Object.assign(Object.assign({}, this._options), { transport: undefined, twilsockClient: undefined });
187
195
  options = index.deepClone(options);
188
- options.transport = this.options.transport;
189
- options.twilsockClient = this.options.twilsockClient;
190
- this.options = options;
196
+ options.transport = this._options.transport;
197
+ options.twilsockClient = this._options.twilsockClient;
198
+ this._options = options;
191
199
  }
192
- this.options.logLevel = (_a = this.options.logLevel) !== null && _a !== void 0 ? _a : "silent";
193
- log.setLevel(this.options.logLevel);
194
- const productId = (this.options.productId = "ip_messaging");
200
+ this._options.logLevel = (_a = this._options.logLevel) !== null && _a !== void 0 ? _a : "silent";
201
+ Client_1._logger.setLevel(this._options.logLevel);
202
+ const productId = (this._options.productId = "ip_messaging");
195
203
  // Filling ClientMetadata
196
- this.options.clientMetadata = this.options.clientMetadata || {};
197
- if (!this.options.clientMetadata.hasOwnProperty("type")) {
198
- this.options.clientMetadata.type = "conversations";
204
+ this._options.clientMetadata = this._options.clientMetadata || {};
205
+ if (!this._options.clientMetadata.hasOwnProperty("type")) {
206
+ this._options.clientMetadata.type = "conversations";
199
207
  }
200
- if (!this.options.clientMetadata.hasOwnProperty("sdk")) {
201
- this.options.clientMetadata.sdk = "JS";
202
- this.options.clientMetadata.sdkv = SDK_VERSION;
208
+ if (!this._options.clientMetadata.hasOwnProperty("sdk")) {
209
+ this._options.clientMetadata.sdk = "JS";
210
+ this._options.clientMetadata.sdkv = _package.version;
203
211
  }
204
212
  // Enable session local storage for Sync
205
- this.options.Sync = this.options.Sync || {};
206
- if (typeof this.options.Sync.enableSessionStorage === "undefined") {
207
- this.options.Sync.enableSessionStorage = true;
213
+ this._options.Sync = this._options.Sync || {};
214
+ if (typeof this._options.Sync.enableSessionStorage === "undefined") {
215
+ this._options.Sync.enableSessionStorage = true;
208
216
  }
209
- if (this.options.region) {
210
- this.options.Sync.region = this.options.region;
217
+ if (this._options.region) {
218
+ this._options.Sync.region = this._options.region;
211
219
  }
212
220
  if (!fpaToken) {
213
221
  throw new Error("A valid Twilio token should be provided");
214
222
  }
215
- this.services = new ClientServices();
216
- this._myself = new user.User("", "", null, this.services);
217
- const startTwilsock = !this.options.twilsockClient;
223
+ this._services = new ClientServices();
224
+ this._myself = new user.User("", "", null, this._services);
225
+ const startTwilsock = !this._options.twilsockClient;
218
226
  // Create default init registrations if none were provided.
219
227
  // Otherwise, the outside party have to list all the init registrations they
220
228
  // need.
221
229
  // Init registrations passed to the Conversations client will be passed down
222
230
  // to the Sync client as well.
223
- if (!this.options.initRegistrations) {
231
+ if (!this._options.initRegistrations) {
224
232
  const initRegistration = new twilsock.InitRegistration(productId);
225
233
  Client_1.populateInitRegistrations(initRegistration);
226
- this.options.initRegistrations = [initRegistration];
234
+ this._options.initRegistrations = [initRegistration];
227
235
  }
228
- this.services.twilsockClient = this.options.twilsockClient =
229
- (_b = this.options.twilsockClient) !== null && _b !== void 0 ? _b : new twilsock.TwilsockClient(fpaToken, productId, this.options);
230
- this.services.twilsockClient.on("tokenAboutToExpire", (ttl) => this.emit("tokenAboutToExpire", ttl));
231
- this.services.twilsockClient.on("tokenExpired", () => this.emit("tokenExpired"));
232
- this.services.twilsockClient.on("connectionError", (error) => this.emit("connectionError", error));
233
- this.services.twilsockClient.on("stateChanged", (state) => {
234
- log.debug(`Handling stateChanged for ConversationsClient: new state ${state}`);
236
+ this._services.twilsockClient = this._options.twilsockClient =
237
+ (_b = this._options.twilsockClient) !== null && _b !== void 0 ? _b : new twilsock.TwilsockClient(fpaToken, productId, this._options);
238
+ this._services.twilsockClient.on("tokenAboutToExpire", () => this.emit("tokenAboutToExpire"));
239
+ this._services.twilsockClient.on("tokenExpired", () => this.emit("tokenExpired"));
240
+ this._services.twilsockClient.on("connectionError", (error) => this.emit("connectionError", error));
241
+ this._services.twilsockClient.on("stateChanged", (state) => {
242
+ Client_1._logger.debug(`Handling stateChanged for ConversationsClient: new state ${state}`);
235
243
  if (state !== this.connectionState) {
236
244
  this.connectionState = state;
237
245
  this.emit("connectionStateChanged", this.connectionState);
238
246
  }
239
247
  });
240
- this.services.transport = this.options.transport = ((_c = this.options
241
- .transport) !== null && _c !== void 0 ? _c : this.options.twilsockClient);
242
- this.services.notificationClient = this.options.notificationsClient =
243
- (_d = this.options.notificationsClient) !== null && _d !== void 0 ? _d : new notifications.Notifications(fpaToken, this.options);
244
- this.services.syncClient = this.options.syncClient =
245
- (_e = this.options.syncClient) !== null && _e !== void 0 ? _e : new twilioSync.SyncClient(fpaToken, this.options);
248
+ this._services.transport = this._options.transport = ((_c = this._options
249
+ .transport) !== null && _c !== void 0 ? _c : this._options.twilsockClient);
250
+ this._services.notificationClient = this._options.notificationsClient =
251
+ (_d = this._options.notificationsClient) !== null && _d !== void 0 ? _d : new notifications.Notifications(fpaToken, this._options);
252
+ this._services.syncClient = this._options.syncClient =
253
+ (_e = this._options.syncClient) !== null && _e !== void 0 ? _e : new twilioSync.SyncClient(fpaToken, this._options);
246
254
  const configurationOptions = (options === null || options === void 0 ? void 0 : options.Chat) || (options === null || options === void 0 ? void 0 : options.IPMessaging) || options || {};
247
255
  const region = configurationOptions.region || (options === null || options === void 0 ? void 0 : options.region);
248
256
  const baseUrl = configurationOptions.apiUri ||
249
257
  configurationOptions.typingUri ||
250
258
  `https://aim.${region || "us1"}.twilio.com`;
251
- this.services.commandExecutor = new commandExecutor.CommandExecutor(baseUrl, { transport: this.options.transport }, productId);
252
- const emitFailed = (err) => {
253
- this._rejectEnsureReady(err);
259
+ this._services.commandExecutor = new commandExecutor.CommandExecutor(baseUrl, { transport: this._options.transport }, productId);
260
+ const emitFailed = (error) => {
261
+ this._rejectEnsureReady(error);
254
262
  this.emit("stateChanged", "failed");
263
+ this.emit("initFailed", { error });
255
264
  };
256
- this.services.twilsockClient.once("connectionError", emitFailed);
257
- this.services.twilsockClient.once("disconnected", emitFailed);
258
- // ConversationsClient will be able to initialize only after twilsock is connected
259
- this.services.twilsockClient.once("connected", async () => {
260
- log.debug(`ConversationsClient started INITIALIZING`);
261
- this.services.twilsockClient.off("connectionError", emitFailed);
262
- this.services.twilsockClient.off("disconnected", emitFailed);
265
+ const emitDisconnected = () => {
266
+ emitFailed({
267
+ terminal: true,
268
+ message: "Twilsock has disconnected.",
269
+ });
270
+ };
271
+ this._services.twilsockClient.on("connectionError", emitFailed);
272
+ this._services.twilsockClient.on("disconnected", emitDisconnected);
273
+ this._services.twilsockClient.on("connected", async () => {
274
+ Client_1._logger.debug(`ConversationsClient started INITIALIZING`);
275
+ this._services.twilsockClient.off("connectionError", emitFailed);
276
+ this._services.twilsockClient.off("disconnected", emitDisconnected);
263
277
  try {
264
278
  const startupEvent = "conversations.client.startup";
265
- this.services.twilsockClient.addPartialTelemetryEvent(new twilsock.TelemetryEventDescription(startupEvent, "Conversations client startup", new Date()), startupEvent, twilsock.TelemetryPoint.Start);
279
+ this._services.twilsockClient.addPartialTelemetryEvent(new twilsock.TelemetryEventDescription(startupEvent, "Conversations client startup", new Date()), startupEvent, twilsock.TelemetryPoint.Start);
266
280
  await this._initialize();
267
- this.services.twilsockClient.addPartialTelemetryEvent(new twilsock.TelemetryEventDescription("", "", new Date()), startupEvent, twilsock.TelemetryPoint.End);
281
+ this._services.twilsockClient.addPartialTelemetryEvent(new twilsock.TelemetryEventDescription("", "", new Date()), startupEvent, twilsock.TelemetryPoint.End);
268
282
  }
269
283
  catch (err) {
270
284
  // Fail ChatClient if initialization is incomplete
271
- this._rejectEnsureReady(err);
285
+ const connectionError = {
286
+ terminal: true,
287
+ message: err.message,
288
+ };
289
+ this._rejectEnsureReady(connectionError);
272
290
  this.emit("stateChanged", "failed");
291
+ this.emit("initFailed", {
292
+ error: connectionError,
293
+ });
273
294
  }
274
295
  });
275
296
  this._ensureReady = new Promise((resolve, reject) => {
@@ -277,12 +298,36 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
277
298
  this._rejectEnsureReady = reject;
278
299
  }).catch(() => void 0); // @todo How to process unhandled rejection here?
279
300
  if (startTwilsock) {
280
- this.services.twilsockClient.connect();
301
+ this._services.twilsockClient.connect();
281
302
  }
282
303
  }
283
- static populateInitRegistrations(reg) {
284
- reg.populateInitRegistrations([notificationTypes.NotificationTypes.TYPING_INDICATOR]);
285
- twilioSync.SyncClient.populateInitRegistrations(reg);
304
+ /**
305
+ * Information of the logged-in user. Before client initialization, returns an
306
+ * uninitialized user. Will trigger a {@link Client.userUpdated} event after
307
+ * initialization.
308
+ */
309
+ get user() {
310
+ return this._myself;
311
+ }
312
+ /**
313
+ * Client reachability state. Throws an error if accessed before the client
314
+ * initialization was completed.
315
+ */
316
+ get reachabilityEnabled() {
317
+ if (!this._configuration) {
318
+ throw new Error("Reachability information could not yet be accessed as the client " +
319
+ "has not yet been initialized. Subscribe to the 'stateChanged' event " +
320
+ "to properly react to the client initialization.");
321
+ }
322
+ return this._configuration.reachabilityEnabled;
323
+ }
324
+ /**
325
+ * @deprecated
326
+ * Current token.
327
+ * @internal
328
+ */
329
+ get token() {
330
+ return this._fpaToken;
286
331
  }
287
332
  /**
288
333
  * @deprecated Call constructor directly.
@@ -320,109 +365,105 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
320
365
  return client;
321
366
  }
322
367
  /**
323
- * Information of the logged-in user. Before client initialization, returns an
324
- * uninitialized user. Will trigger a {@link Client.userUpdated} event after
325
- * initialization.
368
+ * Static method for push notification payload parsing. Returns parsed push as
369
+ * a {@link PushNotification} object.
370
+ * @param notificationPayload Push notification payload.
326
371
  */
327
- get user() {
328
- return this._myself;
372
+ static parsePushNotification(notificationPayload) {
373
+ var _a, _b;
374
+ Client_1._logger.debug("parsePushNotification, notificationPayload=", notificationPayload);
375
+ // APNS specifics
376
+ if (typeof notificationPayload.aps !== "undefined") {
377
+ if (!notificationPayload.twi_message_type) {
378
+ throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");
379
+ }
380
+ const data = Client_1._parsePushNotificationChatData(notificationPayload);
381
+ const apsPayload = notificationPayload.aps;
382
+ let body;
383
+ let title = null;
384
+ if (typeof apsPayload.alert === "string") {
385
+ body = apsPayload.alert || null;
386
+ }
387
+ else {
388
+ body = ((_a = apsPayload.alert) === null || _a === void 0 ? void 0 : _a.body) || null;
389
+ title = ((_b = apsPayload.alert) === null || _b === void 0 ? void 0 : _b.title) || null;
390
+ }
391
+ return new pushNotification.PushNotification({
392
+ title,
393
+ body,
394
+ sound: apsPayload.sound || null,
395
+ badge: apsPayload.badge || null,
396
+ action: apsPayload.category || null,
397
+ type: notificationPayload.twi_message_type,
398
+ data: data,
399
+ });
400
+ }
401
+ // FCM specifics
402
+ if (typeof notificationPayload.data !== "undefined") {
403
+ const dataPayload = notificationPayload.data;
404
+ if (!dataPayload.twi_message_type) {
405
+ throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");
406
+ }
407
+ const data = Client_1._parsePushNotificationChatData(notificationPayload.data);
408
+ return new pushNotification.PushNotification({
409
+ title: dataPayload.twi_title || null,
410
+ body: dataPayload.twi_body || null,
411
+ sound: dataPayload.twi_sound || null,
412
+ badge: null,
413
+ action: dataPayload.twi_action || null,
414
+ type: dataPayload.twi_message_type,
415
+ data: data,
416
+ });
417
+ }
418
+ throw new Error("Provided push notification payload is not Programmable Chat notification");
329
419
  }
330
420
  /**
331
- * Client reachability state. Throws if accessed before the client
332
- * initialization was completed.
421
+ * Static method for parsing push notification chat data.
422
+ * @param data Data to parse
333
423
  */
334
- get reachabilityEnabled() {
335
- if (!this.configuration) {
336
- throw new Error("Reachability information could not yet be accessed as the client " +
337
- "has not yet been initialized. Subscribe to the 'stateChanged' event " +
338
- "to properly react to the client initialization.");
424
+ static _parsePushNotificationChatData(data) {
425
+ const result = {};
426
+ for (const key in Client_1._supportedPushDataFields) {
427
+ const value = data[key];
428
+ if (typeof value === "undefined" || value === null) {
429
+ continue;
430
+ }
431
+ if (key === "message_index" || key === "media_count") {
432
+ const number = index.parseToNumber(value);
433
+ if (number !== null) {
434
+ result[Client_1._supportedPushDataFields[key]] = number;
435
+ }
436
+ continue;
437
+ }
438
+ if (key === "media") {
439
+ if (typeof value === "string") {
440
+ try {
441
+ result[Client_1._supportedPushDataFields[key]] = JSON.parse(value);
442
+ }
443
+ catch (_a) {
444
+ Client_1._logger.debug("Media message notification parsing error");
445
+ }
446
+ }
447
+ continue;
448
+ }
449
+ result[Client_1._supportedPushDataFields[key]] = value;
339
450
  }
340
- return this.configuration.reachabilityEnabled;
341
- }
342
- get token() {
343
- return this.fpaToken;
344
- }
345
- _subscribeToPushNotifications(channelType) {
346
- [
347
- notificationTypes.NotificationTypes.NEW_MESSAGE,
348
- notificationTypes.NotificationTypes.ADDED_TO_CONVERSATION,
349
- notificationTypes.NotificationTypes.REMOVED_FROM_CONVERSATION,
350
- notificationTypes.NotificationTypes.TYPING_INDICATOR,
351
- notificationTypes.NotificationTypes.CONSUMPTION_UPDATE,
352
- ].forEach((messageType) => {
353
- this.services.notificationClient.subscribe(channelType, messageType);
354
- });
355
- }
356
- _unsubscribeFromPushNotifications(channelType) {
357
- [
358
- notificationTypes.NotificationTypes.NEW_MESSAGE,
359
- notificationTypes.NotificationTypes.ADDED_TO_CONVERSATION,
360
- notificationTypes.NotificationTypes.REMOVED_FROM_CONVERSATION,
361
- notificationTypes.NotificationTypes.TYPING_INDICATOR,
362
- notificationTypes.NotificationTypes.CONSUMPTION_UPDATE,
363
- ].forEach((messageType) => {
364
- this.services.notificationClient.unsubscribe(channelType, messageType);
365
- });
451
+ return result;
366
452
  }
367
- async _initialize() {
368
- const configurationResponse = await this.services.commandExecutor.fetchResource("Client/v2/Configuration");
369
- this.configuration = new configuration.Configuration(this.options, configurationResponse, log);
370
- this._myself._resolveInitialization(this.configuration, this.configuration.userIdentity, this.configuration.userInfo, true);
371
- this.services.typingIndicator = new typingIndicator.TypingIndicator(this.getConversationBySid.bind(this), this.configuration, this.services);
372
- this.services.network = new network.Network(this.configuration, this.services);
373
- this.services.users = new users.Users(this._myself, this.configuration, this.services);
374
- this.services.users.on("userSubscribed", (user) => {
375
- this.emit("userSubscribed", user);
376
- });
377
- this.services.users.on("userUpdated", (args) => this.emit("userUpdated", args));
378
- this.services.users.on("userUnsubscribed", (user) => {
379
- this.emit("userUnsubscribed", user);
380
- });
381
- this.conversations = new conversations.Conversations(this.configuration, this.services);
382
- this.conversations.on("conversationAdded", (conversation) => {
383
- this.emit("conversationAdded", conversation);
384
- });
385
- this.conversations.on("conversationRemoved", (conversation) => {
386
- this.emit("conversationRemoved", conversation);
387
- });
388
- this.conversations.on("conversationJoined", (conversation) => {
389
- this.emit("conversationJoined", conversation);
390
- });
391
- this.conversations.on("conversationLeft", (conversation) => {
392
- this.emit("conversationLeft", conversation);
393
- });
394
- this.conversations.on("conversationUpdated", (args) => this.emit("conversationUpdated", args));
395
- this.conversations.on("participantJoined", (participant) => {
396
- this.emit("participantJoined", participant);
397
- });
398
- this.conversations.on("participantLeft", (participant) => {
399
- this.emit("participantLeft", participant);
400
- });
401
- this.conversations.on("participantUpdated", (args) => this.emit("participantUpdated", args));
402
- this.conversations.on("messageAdded", (message) => this.emit("messageAdded", message));
403
- this.conversations.on("messageUpdated", (args) => this.emit("messageUpdated", args));
404
- this.conversations.on("messageRemoved", (message) => this.emit("messageRemoved", message));
405
- this.conversations.on("typingStarted", (participant) => this.emit("typingStarted", participant));
406
- this.conversations.on("typingEnded", (participant) => this.emit("typingEnded", participant));
407
- this.conversationsPromise = this.conversations
408
- .fetchConversations()
409
- .then(() => this.conversations)
410
- .catch((error) => {
411
- throw error;
412
- });
413
- await this.services.users.myself._ensureFetched();
414
- Client_1.supportedPushChannels.forEach((channelType) => this._subscribeToPushNotifications(channelType));
415
- this.services.typingIndicator.initialize();
416
- this.services.mcsClient = new mcsClient.McsClient(this.fpaToken, this.configuration.links.mediaService, this.configuration.links.mediaSetService, Object.assign(Object.assign({}, this.options), { transport: undefined }));
417
- this._resolveEnsureReady();
418
- this.emit("stateChanged", "initialized");
453
+ /**
454
+ * Populate the client with init registrations.
455
+ * @param reg The init registration to populate.
456
+ */
457
+ static populateInitRegistrations(reg) {
458
+ reg.populateInitRegistrations([notificationTypes.NotificationTypes.TYPING_INDICATOR]);
459
+ twilioSync.SyncClient.populateInitRegistrations(reg);
419
460
  }
420
461
  /**
421
462
  * Gracefully shut down the client.
422
463
  */
423
464
  async shutdown() {
424
465
  await this._ensureReady;
425
- await this.services.twilsockClient.disconnect();
466
+ await this._services.twilsockClient.disconnect();
426
467
  }
427
468
  /**
428
469
  * Update the token used by the client and re-register with the Conversations services.
@@ -430,14 +471,14 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
430
471
  */
431
472
  async updateToken(token) {
432
473
  await this._ensureReady;
433
- log.info("updateToken");
434
- if (this.fpaToken === token) {
474
+ Client_1._logger.info("updateToken");
475
+ if (this._fpaToken === token) {
435
476
  return this;
436
477
  }
437
- await this.services.twilsockClient.updateToken(token);
438
- await this.services.notificationClient.updateToken(token);
439
- await this.services.mcsClient.updateToken(token);
440
- this.fpaToken = token;
478
+ await this._services.twilsockClient.updateToken(token);
479
+ await this._services.notificationClient.updateToken(token);
480
+ await this._services.mcsClient.updateToken(token);
481
+ this._fpaToken = token;
441
482
  return this;
442
483
  }
443
484
  /**
@@ -446,13 +487,27 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
446
487
  */
447
488
  async getConversationBySid(conversationSid) {
448
489
  await this._ensureReady;
449
- await this.conversations.myConversationsRead.promise;
450
- let conversation = await this.conversations.getConversation(conversationSid);
490
+ await this._conversationsEntity.myConversationsRead.promise;
491
+ let conversation = await this._conversationsEntity.getConversation(conversationSid);
451
492
  if (!conversation) {
452
- conversation = await this.conversations.peekConversation(conversationSid);
493
+ deprecationDecorator.deprecationWarning("The method getConversationBySid is deprecated to retrieve conversations you're not part of. Use peekConversationBySid instead.");
494
+ conversation = await this.peekConversationBySid(conversationSid);
453
495
  }
454
496
  if (!conversation) {
455
- throw new Error(`Conversation with SID ${conversationSid} is not found.`);
497
+ throw new Error(`Conversation with SID ${conversationSid} was not found.`);
498
+ }
499
+ return conversation;
500
+ }
501
+ /**
502
+ * Peek a conversation by its SID.
503
+ * @param conversationSid Conversation sid
504
+ * @internal
505
+ */
506
+ async peekConversationBySid(conversationSid) {
507
+ await this._ensureReady;
508
+ const conversation = await this._conversationsEntity.peekConversation(conversationSid);
509
+ if (!conversation) {
510
+ throw new Error(`Conversation with SID ${conversationSid} was not found.`);
456
511
  }
457
512
  return conversation;
458
513
  }
@@ -462,10 +517,10 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
462
517
  */
463
518
  async getConversationByUniqueName(uniqueName) {
464
519
  await this._ensureReady;
465
- await this.conversations.myConversationsRead.promise;
466
- const conversation = await this.conversations.getConversationByUniqueName(uniqueName);
520
+ await this._conversationsEntity.myConversationsRead.promise;
521
+ const conversation = await this._conversationsEntity.getConversationByUniqueName(uniqueName);
467
522
  if (!conversation) {
468
- throw new Error(`Conversation with unique name ${uniqueName} is not found.`);
523
+ throw new Error(`Conversation with unique name ${uniqueName} was not found.`);
469
524
  }
470
525
  return conversation;
471
526
  }
@@ -474,7 +529,7 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
474
529
  */
475
530
  async getSubscribedConversations() {
476
531
  await this._ensureReady;
477
- return this.conversationsPromise.then((conversations) => conversations.getConversations());
532
+ return this._conversationsPromise.then((conversations) => conversations.getConversations());
478
533
  }
479
534
  /**
480
535
  * Create a conversation on the server and subscribe to its events.
@@ -484,18 +539,19 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
484
539
  async createConversation(options) {
485
540
  await this._ensureReady;
486
541
  options = options || {};
487
- return this.conversationsPromise.then((conversationsEntity) => conversationsEntity.addConversation(options));
542
+ return this._conversationsPromise.then((conversationsEntity) => conversationsEntity.addConversation(options));
488
543
  }
489
544
  /**
490
545
  * Register for push notifications.
491
546
  * @param channelType Channel type.
492
- * @param registrationId Push notification ID provided by the FCM/APNS service on the platform.
547
+ * @param registrationId Push notification ID provided by the FCM/APNS service
548
+ * on the platform.
493
549
  */
494
550
  async setPushRegistrationId(channelType, registrationId) {
495
551
  await this._ensureReady;
496
552
  this._subscribeToPushNotifications(channelType);
497
- this.services.notificationClient.setPushRegistrationId(channelType, registrationId);
498
- await this.services.notificationClient.commitChanges(); // Committing before this point is useless because we have no push id
553
+ this._services.notificationClient.setPushRegistrationId(channelType, registrationId);
554
+ await this._services.notificationClient.commitChanges(); // Committing before this point is useless because we have no push id
499
555
  }
500
556
  /**
501
557
  * Unregister from push notifications.
@@ -505,132 +561,181 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
505
561
  async unsetPushRegistrationId(channelType) {
506
562
  await this._ensureReady;
507
563
  this._unsubscribeFromPushNotifications(channelType);
508
- await this.services.notificationClient.commitChanges();
564
+ await this._services.notificationClient.commitChanges();
509
565
  }
510
566
  /**
511
567
  * Clear existing registrations directly using provided device token.
512
568
  * This is useful to ensure stopped subscriptions without resubscribing.
513
569
  *
514
- * This function goes completely beside the state machine and removes all registrations.
515
- * Use with caution: if it races with current state machine operations, madness will ensue.
570
+ * This function goes completely beside the state machine and removes all
571
+ * registrations.
572
+ * Use with caution: if it races with current state machine operations,
573
+ * madness will ensue.
516
574
  *
517
575
  * @param channelType Channel type.
518
- * @param registrationId Push notification ID provided by the FCM/APNS service on the platform.
576
+ * @param registrationId Push notification ID provided by the FCM/APNS service
577
+ * on the platform.
519
578
  */
520
579
  async removePushRegistrations(channelType, registrationId) {
521
580
  // do not await this._ensureReady() here - it could be called at any moment
522
- await this.services.notificationClient.removeRegistrations(channelType, registrationId);
523
- }
524
- static parsePushNotificationChatData(data) {
525
- const result = {};
526
- for (const key in Client_1.supportedPushDataFields) {
527
- if (typeof data[key] === "undefined" || data[key] === null) {
528
- continue;
529
- }
530
- if (key !== "message_index") {
531
- result[Client_1.supportedPushDataFields[key]] = data[key];
532
- continue;
533
- }
534
- if (index.parseToNumber(data[key]) !== null) {
535
- result[Client_1.supportedPushDataFields[key]] = Number(data[key]);
536
- }
537
- }
538
- return result;
539
- }
540
- /**
541
- * Static method for push notification payload parsing. Returns parsed push as a {@link PushNotification} object.
542
- * @param notificationPayload Push notification payload.
543
- */
544
- static parsePushNotification(notificationPayload) {
545
- log.debug("parsePushNotification, notificationPayload=", notificationPayload);
546
- // APNS specifics
547
- if (typeof notificationPayload.aps !== "undefined") {
548
- if (!notificationPayload.twi_message_type) {
549
- throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");
550
- }
551
- const data = Client_1.parsePushNotificationChatData(notificationPayload);
552
- const apsPayload = notificationPayload.aps;
553
- let body;
554
- let title = null;
555
- if (typeof apsPayload.alert === "string") {
556
- body = apsPayload.alert || null;
557
- }
558
- else {
559
- body = apsPayload.alert.body || null;
560
- title = apsPayload.alert.title || null;
561
- }
562
- return new pushNotification.PushNotification({
563
- title,
564
- body,
565
- sound: apsPayload.sound || null,
566
- badge: apsPayload.badge || null,
567
- action: apsPayload.category || null,
568
- type: notificationPayload.twi_message_type,
569
- data: data,
570
- });
571
- }
572
- // FCM specifics
573
- if (typeof notificationPayload.data !== "undefined") {
574
- const dataPayload = notificationPayload.data;
575
- if (!dataPayload.twi_message_type) {
576
- throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");
577
- }
578
- const data = Client_1.parsePushNotificationChatData(notificationPayload.data);
579
- return new pushNotification.PushNotification({
580
- title: dataPayload.twi_title || null,
581
- body: dataPayload.twi_body || null,
582
- sound: dataPayload.twi_sound || null,
583
- badge: null,
584
- action: dataPayload.twi_action || null,
585
- type: dataPayload.twi_message_type,
586
- data: data,
587
- });
588
- }
589
- throw new Error("Provided push notification payload is not Programmable Chat notification");
581
+ await this._services.notificationClient.removeRegistrations(channelType, registrationId);
590
582
  }
591
583
  /**
592
- * Handle push notification payload parsing and emit the {@link Client.pushNotification} event on this {@link Client} instance.
584
+ * Handle push notification payload parsing and emit the
585
+ * {@link Client.pushNotification} event on this {@link Client} instance.
593
586
  * @param notificationPayload Push notification payload
594
587
  */
595
588
  async handlePushNotification(notificationPayload) {
596
589
  await this._ensureReady;
597
- log.debug("handlePushNotification, notificationPayload=", notificationPayload);
590
+ Client_1._logger.debug("handlePushNotification, notificationPayload=", notificationPayload);
598
591
  this.emit("pushNotification", Client_1.parsePushNotification(notificationPayload));
599
592
  }
600
593
  /**
601
- * Gets a user with the given identity. If it's in the subscribed list, then return the user object from it;
594
+ * Gets a user with the given identity. If it's in the subscribed list, then
595
+ * return the user object from it;
602
596
  * if not, then subscribe and add user to the subscribed list.
603
597
  * @param identity Identity of the user.
604
598
  * @returns A fully initialized user.
605
599
  */
606
600
  async getUser(identity) {
607
601
  await this._ensureReady;
608
- return this.services.users.getUser(identity);
602
+ return this._services.users.getUser(identity);
609
603
  }
610
604
  /**
611
605
  * Get a list of subscribed user objects.
612
606
  */
613
607
  async getSubscribedUsers() {
614
608
  await this._ensureReady;
615
- return this.services.users.getSubscribedUsers();
609
+ return this._services.users.getSubscribedUsers();
610
+ }
611
+ /**
612
+ * Get content URLs for all media attachments in the given set of media sids
613
+ * using a single operation.
614
+ * @param mediaSids Set of media sids to query for the content URL.
615
+ */
616
+ getTemporaryContentUrlsForMediaSids(mediaSids) {
617
+ return new mcsClient.CancellablePromise(async (resolve, reject, onCancel) => {
618
+ if (!this._services.mcsClient || !mediaSids) {
619
+ reject(new Error("Media Content Service is unavailable"));
620
+ return;
621
+ }
622
+ const request = this._services.mcsClient.mediaSetGetContentUrls(mediaSids);
623
+ onCancel(() => {
624
+ request.cancel();
625
+ });
626
+ try {
627
+ const urls = await request;
628
+ resolve(urls);
629
+ }
630
+ catch (e) {
631
+ reject(e);
632
+ }
633
+ });
634
+ }
635
+ /**
636
+ * Get content URLs for all media attachments in the given set using a single
637
+ * operation.
638
+ * @param contentSet Set of media attachments to query content URLs.
639
+ */
640
+ getTemporaryContentUrlsForMedia(contentSet) {
641
+ // We ignore existing mcsMedia members of each of the media entries.
642
+ // Instead, we just collect their sids and pull new descriptors from a
643
+ // mediaSet GET endpoint.
644
+ const sids = contentSet.map((m) => m.sid);
645
+ return this.getTemporaryContentUrlsForMediaSids(sids);
646
+ }
647
+ /**
648
+ * Initialize the client.
649
+ */
650
+ async _initialize() {
651
+ const configurationResponse = await this._services.commandExecutor.fetchResource("Client/v2/Configuration");
652
+ this._configuration = new configuration.Configuration(this._options, configurationResponse, Client_1._logger);
653
+ this._myself._resolveInitialization(this._configuration, this._configuration.userIdentity, this._configuration.userInfo, true);
654
+ this._services.typingIndicator = new typingIndicator.TypingIndicator(this.getConversationBySid.bind(this), this._configuration, this._services);
655
+ this._services.network = new network.Network(this._configuration, this._services);
656
+ this._services.users = new users.Users(this._myself, this._configuration, this._services);
657
+ this._services.users.on("userSubscribed", (user) => {
658
+ this.emit("userSubscribed", user);
659
+ });
660
+ this._services.users.on("userUpdated", (args) => this.emit("userUpdated", args));
661
+ this._services.users.on("userUnsubscribed", (user) => {
662
+ this.emit("userUnsubscribed", user);
663
+ });
664
+ this._conversationsEntity = new conversations.Conversations(this._configuration, this._services);
665
+ this._conversationsEntity.on("conversationAdded", (conversation) => {
666
+ this.emit("conversationAdded", conversation);
667
+ });
668
+ this._conversationsEntity.on("conversationRemoved", (conversation) => {
669
+ this.emit("conversationRemoved", conversation);
670
+ });
671
+ this._conversationsEntity.on("conversationJoined", (conversation) => {
672
+ this.emit("conversationJoined", conversation);
673
+ });
674
+ this._conversationsEntity.on("conversationLeft", (conversation) => {
675
+ this.emit("conversationLeft", conversation);
676
+ });
677
+ this._conversationsEntity.on("conversationUpdated", (args) => this.emit("conversationUpdated", args));
678
+ this._conversationsEntity.on("participantJoined", (participant) => {
679
+ this.emit("participantJoined", participant);
680
+ });
681
+ this._conversationsEntity.on("participantLeft", (participant) => {
682
+ this.emit("participantLeft", participant);
683
+ });
684
+ this._conversationsEntity.on("participantUpdated", (args) => this.emit("participantUpdated", args));
685
+ this._conversationsEntity.on("messageAdded", (message) => this.emit("messageAdded", message));
686
+ this._conversationsEntity.on("messageUpdated", (args) => this.emit("messageUpdated", args));
687
+ this._conversationsEntity.on("messageRemoved", (message) => this.emit("messageRemoved", message));
688
+ this._conversationsEntity.on("typingStarted", (participant) => this.emit("typingStarted", participant));
689
+ this._conversationsEntity.on("typingEnded", (participant) => this.emit("typingEnded", participant));
690
+ this._conversationsPromise = this._conversationsEntity
691
+ .fetchConversations()
692
+ .then(() => this._conversationsEntity)
693
+ .catch((error) => {
694
+ throw error;
695
+ });
696
+ await this._services.users.myself._ensureFetched();
697
+ Client_1._supportedPushChannels.forEach((channelType) => this._subscribeToPushNotifications(channelType));
698
+ this._services.typingIndicator.initialize();
699
+ this._services.mcsClient = new mcsClient.McsClient(this._fpaToken, this._configuration.links.mediaService, this._configuration.links.mediaSetService, Object.assign(Object.assign({}, this._options), { transport: undefined }));
700
+ this._resolveEnsureReady();
701
+ this.emit("stateChanged", "initialized");
702
+ this.emit("initialized", {});
703
+ }
704
+ /**
705
+ * Subscribe to push notifications.
706
+ * @param channelType The channel type to subscribe to.
707
+ */
708
+ _subscribeToPushNotifications(channelType) {
709
+ [
710
+ notificationTypes.NotificationTypes.NEW_MESSAGE,
711
+ notificationTypes.NotificationTypes.ADDED_TO_CONVERSATION,
712
+ notificationTypes.NotificationTypes.REMOVED_FROM_CONVERSATION,
713
+ notificationTypes.NotificationTypes.TYPING_INDICATOR,
714
+ notificationTypes.NotificationTypes.CONSUMPTION_UPDATE,
715
+ ].forEach((messageType) => {
716
+ this._services.notificationClient.subscribe(channelType, messageType);
717
+ });
718
+ }
719
+ /**
720
+ * Unsubscribe from push notifications.
721
+ * @param channelType The channel type to unsubscribe from.
722
+ */
723
+ _unsubscribeFromPushNotifications(channelType) {
724
+ [
725
+ notificationTypes.NotificationTypes.NEW_MESSAGE,
726
+ notificationTypes.NotificationTypes.ADDED_TO_CONVERSATION,
727
+ notificationTypes.NotificationTypes.REMOVED_FROM_CONVERSATION,
728
+ notificationTypes.NotificationTypes.TYPING_INDICATOR,
729
+ notificationTypes.NotificationTypes.CONSUMPTION_UPDATE,
730
+ ].forEach((messageType) => {
731
+ this._services.notificationClient.unsubscribe(channelType, messageType);
732
+ });
616
733
  }
617
734
  };
618
735
  /**
619
- * Current version of the Conversations client.
620
- */
621
- exports.Client.version = SDK_VERSION;
622
- exports.Client.supportedPushChannels = [
623
- "fcm",
624
- "apn",
625
- ];
626
- exports.Client.supportedPushDataFields = {
627
- conversation_sid: "conversationSid",
628
- message_sid: "messageSid",
629
- message_index: "messageIndex",
630
- };
631
- /**
632
- * Fired when a conversation becomes visible to the client. The event is also triggered when the client creates a new conversation.
633
- * Fired for all conversations client has joined.
736
+ * Fired when a conversation becomes visible to the client. The event is also
737
+ * triggered when the client creates a new conversation.
738
+ * Fired for all conversations that the client has joined.
634
739
  *
635
740
  * Parameters:
636
741
  * 1. {@link Conversation} `conversation` - the conversation in question
@@ -662,14 +767,17 @@ exports.Client.conversationLeft = "conversationLeft";
662
767
  */
663
768
  exports.Client.conversationRemoved = "conversationRemoved";
664
769
  /**
665
- * Fired when the attributes or the metadata of a conversation have been updated.
666
- * During conversation's creation and initialization, this event might be fired multiple times
667
- * for same joined or created conversation as new data is arriving from different sources.
770
+ * Fired when the attributes or the metadata of a conversation have been
771
+ * updated. During conversation's creation and initialization, this event
772
+ * might be fired multiple times for same joined or created conversation as
773
+ * new data is arriving from different sources.
668
774
  *
669
775
  * Parameters:
670
- * 1. object `data` - info object provided with the event. It has the following properties:
776
+ * 1. object `data` - info object provided with the event. It has the
777
+ * following properties:
671
778
  * * {@link Conversation} `conversation` - the conversation in question
672
- * * {@link ConversationUpdateReason}[] `updateReasons` - array of reasons for the update
779
+ * * {@link ConversationUpdateReason}[] `updateReasons` - array of reasons
780
+ * for the update
673
781
  * @event
674
782
  */
675
783
  exports.Client.conversationUpdated = "conversationUpdated";
@@ -693,9 +801,11 @@ exports.Client.participantLeft = "participantLeft";
693
801
  * Fired when a participant's fields have been updated.
694
802
  *
695
803
  * Parameters:
696
- * 1. object `data` - info object provided with the event. It has the following properties:
804
+ * 1. object `data` - info object provided with the event. It has the
805
+ * following properties:
697
806
  * * {@link Participant} `participant` - the participant in question
698
- * * {@link ParticipantUpdateReason}[] `updateReasons` - array of reasons for the update
807
+ * * {@link ParticipantUpdateReason}[] `updateReasons` - array of reasons
808
+ * for the update
699
809
  * @event
700
810
  */
701
811
  exports.Client.participantUpdated = "participantUpdated";
@@ -719,16 +829,16 @@ exports.Client.messageRemoved = "messageRemoved";
719
829
  * Fired when the fields of an existing message are updated with new values.
720
830
  *
721
831
  * Parameters:
722
- * 1. object `data` - info object provided with the event. It has the following properties:
832
+ * 1. object `data` - info object provided with the event. It has the
833
+ * following properties:
723
834
  * * {@link Message} `message` - the message in question
724
- * * {@link MessageUpdateReason}[] `updateReasons` - array of reasons for the update
835
+ * * {@link MessageUpdateReason}[] `updateReasons` - array of reasons for
836
+ * the update
725
837
  * @event
726
838
  */
727
839
  exports.Client.messageUpdated = "messageUpdated";
728
840
  /**
729
841
  * Fired when the token is about to expire and needs to be updated.
730
- * * Parameters:
731
- * 1. number `message` - token's time to live
732
842
  * @event
733
843
  */
734
844
  exports.Client.tokenAboutToExpire = "tokenAboutToExpire";
@@ -754,10 +864,12 @@ exports.Client.typingEnded = "typingEnded";
754
864
  */
755
865
  exports.Client.typingStarted = "typingStarted";
756
866
  /**
757
- * Fired when the client has received (and parsed) a push notification via one of the push channels (apn or fcm).
867
+ * Fired when the client has received (and parsed) a push notification via one
868
+ * of the push channels (apn or fcm).
758
869
  *
759
870
  * Parameters:
760
- * 1. {@link PushNotification} `pushNotification` - the push notification in question
871
+ * 1. {@link PushNotification} `pushNotification` - the push notification in
872
+ * question
761
873
  * @event
762
874
  */
763
875
  exports.Client.pushNotification = "pushNotification";
@@ -778,16 +890,20 @@ exports.Client.userSubscribed = "userSubscribed";
778
890
  */
779
891
  exports.Client.userUnsubscribed = "userUnsubscribed";
780
892
  /**
781
- * Fired when the properties or the reachability status of a user have been updated.
893
+ * Fired when the properties or the reachability status of a user have been
894
+ * updated.
782
895
  *
783
896
  * Parameters:
784
- * 1. object `data` - info object provided with the event. It has the following properties:
897
+ * 1. object `data` - info object provided with the event. It has the
898
+ * following properties:
785
899
  * * {@link User} `user` - the user in question
786
- * * {@link UserUpdateReason}[] `updateReasons` - array of reasons for the update
900
+ * * {@link UserUpdateReason}[] `updateReasons` - array of reasons for the
901
+ * update
787
902
  * @event
788
903
  */
789
904
  exports.Client.userUpdated = "userUpdated";
790
905
  /**
906
+ * @deprecated Use initialized or initFailed events instead
791
907
  * Fired when the state of the client has been changed.
792
908
  *
793
909
  * Parameters:
@@ -795,10 +911,28 @@ exports.Client.userUpdated = "userUpdated";
795
911
  * @event
796
912
  */
797
913
  exports.Client.stateChanged = "stateChanged";
914
+ /**
915
+ * Fired when the client has completed initialization successfully.
916
+ *
917
+ * Parameters:
918
+ * 1. object `data` - Optional info object provided with the event
919
+ * @event
920
+ */
921
+ exports.Client.initialized = "initialized";
922
+ /**
923
+ * Fired when the client initialization failed.
924
+ *
925
+ * Parameters:
926
+ * 1. object `data` - info object provided with the event. It has the
927
+ * following property:
928
+ * * Error? `error` - the initialization error if present
929
+ * @event
930
+ */
931
+ exports.Client.initFailed = "initFailed";
798
932
  /**
799
933
  * Fired when the connection state of the client has been changed.
800
934
  *
801
- * Paremeters:
935
+ * Parameters:
802
936
  * 1. {@link ConnectionState} `state` - the new connection state
803
937
  * @event
804
938
  */
@@ -807,7 +941,8 @@ exports.Client.connectionStateChanged = "connectionStateChanged";
807
941
  * Fired when the connection is interrupted for an unexpected reason.
808
942
  *
809
943
  * Parameters:
810
- * 1. object `data` - info object provided with the event. It has the following properties:
944
+ * 1. object `data` - info object provided with the event. It has the
945
+ * following properties:
811
946
  * * boolean `terminal` - Twilsock will stop connection attempts if true
812
947
  * * string `message` - the error message of the root cause
813
948
  * * number? `httpStatusCode` - http status code if available
@@ -815,6 +950,37 @@ exports.Client.connectionStateChanged = "connectionStateChanged";
815
950
  * @event
816
951
  */
817
952
  exports.Client.connectionError = "connectionError";
953
+ /**
954
+ * Current version of the Conversations client.
955
+ */
956
+ exports.Client.version = _package.version;
957
+ /**
958
+ * Logger instance.
959
+ */
960
+ exports.Client._logger = logger.Logger.scope("Client");
961
+ /**
962
+ * Supported push notification channels.
963
+ */
964
+ exports.Client._supportedPushChannels = [
965
+ "fcm",
966
+ "apn",
967
+ ];
968
+ /**
969
+ * Supported push data fields.
970
+ */
971
+ exports.Client._supportedPushDataFields = {
972
+ conversation_sid: "conversationSid",
973
+ conversation_title: "conversationTitle",
974
+ message_sid: "messageSid",
975
+ message_index: "messageIndex",
976
+ media_count: "mediaCount",
977
+ media: "media", // object
978
+ };
979
+ tslib_es6.__decorate([
980
+ deprecationDecorator.deprecated("token"),
981
+ tslib_es6.__metadata("design:type", String),
982
+ tslib_es6.__metadata("design:paramtypes", [])
983
+ ], exports.Client.prototype, "token", null);
818
984
  tslib_es6.__decorate([
819
985
  declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString),
820
986
  tslib_es6.__metadata("design:type", Function),
@@ -827,6 +993,12 @@ tslib_es6.__decorate([
827
993
  tslib_es6.__metadata("design:paramtypes", [String]),
828
994
  tslib_es6.__metadata("design:returntype", Promise)
829
995
  ], exports.Client.prototype, "getConversationBySid", null);
996
+ tslib_es6.__decorate([
997
+ declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString),
998
+ tslib_es6.__metadata("design:type", Function),
999
+ tslib_es6.__metadata("design:paramtypes", [String]),
1000
+ tslib_es6.__metadata("design:returntype", Promise)
1001
+ ], exports.Client.prototype, "peekConversationBySid", null);
830
1002
  tslib_es6.__decorate([
831
1003
  declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString),
832
1004
  tslib_es6.__metadata("design:type", Function),
@@ -877,6 +1049,19 @@ tslib_es6.__decorate([
877
1049
  tslib_es6.__metadata("design:returntype", Promise)
878
1050
  ], exports.Client.prototype, "getUser", null);
879
1051
  tslib_es6.__decorate([
1052
+ declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyArray("strings", "string")),
1053
+ tslib_es6.__metadata("design:type", Function),
1054
+ tslib_es6.__metadata("design:paramtypes", [Array]),
1055
+ tslib_es6.__metadata("design:returntype", mcsClient.CancellablePromise)
1056
+ ], exports.Client.prototype, "getTemporaryContentUrlsForMediaSids", null);
1057
+ tslib_es6.__decorate([
1058
+ declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyArray("media", media.Media)),
1059
+ tslib_es6.__metadata("design:type", Function),
1060
+ tslib_es6.__metadata("design:paramtypes", [Array]),
1061
+ tslib_es6.__metadata("design:returntype", mcsClient.CancellablePromise)
1062
+ ], exports.Client.prototype, "getTemporaryContentUrlsForMedia", null);
1063
+ tslib_es6.__decorate([
1064
+ deprecationDecorator.deprecated("Client.create()", "new Client()"),
880
1065
  declarativeTypeValidator.validateTypesAsync("string", ["undefined", declarativeTypeValidator.pureObject]),
881
1066
  tslib_es6.__metadata("design:type", Function),
882
1067
  tslib_es6.__metadata("design:paramtypes", [String, Object]),