@twilio/conversations 3.0.1-rc.1 → 3.0.1-rc.103

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 (136) hide show
  1. package/builds/browser.js +9543 -4302
  2. package/builds/browser.js.map +1 -1
  3. package/builds/lib.d.ts +256 -61
  4. package/builds/lib.js +9543 -4302
  5. package/builds/lib.js.map +1 -1
  6. package/builds/twilio-conversations.js +44686 -27540
  7. package/builds/twilio-conversations.min.js +1 -200
  8. package/dist/channel-metadata-client.js +1 -1
  9. package/dist/channel-metadata-client.js.map +1 -1
  10. package/dist/client.js +153 -43
  11. package/dist/client.js.map +1 -1
  12. package/dist/command-executor.js +31 -50
  13. package/dist/command-executor.js.map +1 -1
  14. package/dist/configuration.js +8 -4
  15. package/dist/configuration.js.map +1 -1
  16. package/dist/content-template.js +1 -1
  17. package/dist/content-template.js.map +1 -1
  18. package/dist/conversation.js +12 -46
  19. package/dist/conversation.js.map +1 -1
  20. package/dist/data/conversations.js +2 -18
  21. package/dist/data/conversations.js.map +1 -1
  22. package/dist/data/messages.js +13 -3
  23. package/dist/data/messages.js.map +1 -1
  24. package/dist/data/participants.js +2 -4
  25. package/dist/data/participants.js.map +1 -1
  26. package/dist/data/users.js +2 -2
  27. package/dist/data/users.js.map +1 -1
  28. package/dist/index.js +5 -6
  29. package/dist/index.js.map +1 -1
  30. package/dist/media.js.map +1 -1
  31. package/dist/message-builder.js.map +1 -1
  32. package/dist/message-recipients-client.js +237 -0
  33. package/dist/message-recipients-client.js.map +1 -0
  34. package/dist/message.js +57 -0
  35. package/dist/message.js.map +1 -1
  36. package/dist/node_modules/quick-lru/index.js.map +1 -1
  37. package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
  38. package/dist/packages/conversations/package.json.js +1 -1
  39. package/dist/participant.js +34 -34
  40. package/dist/participant.js.map +1 -1
  41. package/dist/push-notification.js.map +1 -1
  42. package/dist/rest-paginator.js +11 -11
  43. package/dist/rest-paginator.js.map +1 -1
  44. package/dist/services/network.js +11 -101
  45. package/dist/services/network.js.map +1 -1
  46. package/dist/services/typing-indicator.js +5 -13
  47. package/dist/services/typing-indicator.js.map +1 -1
  48. package/dist/unsent-message.js.map +1 -1
  49. package/dist/user.js.map +1 -1
  50. package/dist/util/index.js.map +1 -1
  51. package/docs/assets/css/main.css +2660 -0
  52. package/docs/assets/images/icons.png +0 -0
  53. package/docs/assets/images/icons@2x.png +0 -0
  54. package/docs/assets/images/widgets.png +0 -0
  55. package/docs/assets/images/widgets@2x.png +0 -0
  56. package/docs/assets/js/main.js +248 -0
  57. package/docs/assets/js/search.js +1 -0
  58. package/docs/classes/AggregatedDeliveryReceipt.html +3182 -144
  59. package/docs/classes/CancellablePromise.html +3209 -224
  60. package/docs/classes/ChannelMetadata.html +3049 -66
  61. package/docs/classes/Client.html +4276 -701
  62. package/docs/classes/ContentTemplate.html +3115 -96
  63. package/docs/classes/ContentTemplateVariable.html +3114 -88
  64. package/docs/classes/Conversation.html +4380 -768
  65. package/docs/classes/DetailedDeliveryReceipt.html +3162 -116
  66. package/docs/classes/EmailRecipientDescriptor.html +3098 -0
  67. package/docs/classes/Media.html +3165 -119
  68. package/docs/classes/Message.html +3824 -417
  69. package/docs/classes/MessageBuilder.html +3315 -208
  70. package/docs/classes/Participant.html +3442 -258
  71. package/docs/classes/PushNotification.html +3129 -101
  72. package/docs/classes/RestPaginator.html +3158 -120
  73. package/docs/classes/UnknownRecipientDescriptor.html +3067 -0
  74. package/docs/classes/UnsentMessage.html +3040 -63
  75. package/docs/classes/User.html +3347 -209
  76. package/docs/index.html +4366 -146
  77. package/docs/interfaces/ClientOptions.html +3065 -66
  78. package/docs/interfaces/ConversationBindings.html +3000 -109
  79. package/docs/interfaces/ConversationEmailBinding.html +3000 -109
  80. package/docs/interfaces/ConversationLimits.html +3097 -87
  81. package/docs/interfaces/ConversationState.html +3049 -66
  82. package/docs/interfaces/ConversationUpdatedEventArgs.html +3000 -109
  83. package/docs/interfaces/CreateConversationOptions.html +3065 -73
  84. package/docs/interfaces/LastMessage.html +3049 -66
  85. package/docs/interfaces/Paginator.html +3139 -110
  86. package/docs/interfaces/ParticipantBindings.html +3000 -109
  87. package/docs/interfaces/ParticipantEmailBinding.html +3000 -109
  88. package/docs/interfaces/PushNotificationData.html +3113 -94
  89. package/docs/interfaces/SendEmailOptions.html +3033 -59
  90. package/docs/interfaces/SendMediaOptions.html +3067 -75
  91. package/docs/modules.html +4373 -180
  92. package/package.json +13 -14
  93. package/docs/.nojekyll +0 -1
  94. package/docs/assets/highlight.css +0 -113
  95. package/docs/assets/main.js +0 -58
  96. package/docs/assets/search.js +0 -1
  97. package/docs/assets/style.css +0 -1279
  98. package/docs/classes/CancellationError.html +0 -112
  99. package/docs/interfaces/ParticipantBindingOptions.html +0 -110
  100. package/docs/types/ChannelType.html +0 -106
  101. package/docs/types/ConnectionState.html +0 -115
  102. package/docs/types/ContentData.html +0 -106
  103. package/docs/types/ContentDataAction.html +0 -107
  104. package/docs/types/ContentDataActionOther.html +0 -121
  105. package/docs/types/ContentDataActionPhone.html +0 -128
  106. package/docs/types/ContentDataActionReply.html +0 -133
  107. package/docs/types/ContentDataActionUrl.html +0 -128
  108. package/docs/types/ContentDataCallToAction.html +0 -131
  109. package/docs/types/ContentDataCard.html +0 -137
  110. package/docs/types/ContentDataListItem.html +0 -121
  111. package/docs/types/ContentDataListPicker.html +0 -134
  112. package/docs/types/ContentDataLocation.html +0 -134
  113. package/docs/types/ContentDataMedia.html +0 -129
  114. package/docs/types/ContentDataOther.html +0 -121
  115. package/docs/types/ContentDataQuickReply.html +0 -131
  116. package/docs/types/ContentDataReply.html +0 -119
  117. package/docs/types/ContentDataText.html +0 -125
  118. package/docs/types/ConversationStatus.html +0 -107
  119. package/docs/types/ConversationUpdateReason.html +0 -106
  120. package/docs/types/DeliveryAmount.html +0 -106
  121. package/docs/types/DeliveryStatus.html +0 -106
  122. package/docs/types/JSONArray.html +0 -106
  123. package/docs/types/JSONObject.html +0 -111
  124. package/docs/types/JSONValue.html +0 -106
  125. package/docs/types/LogLevel.html +0 -106
  126. package/docs/types/MediaCategory.html +0 -106
  127. package/docs/types/MessageType.html +0 -106
  128. package/docs/types/MessageUpdateReason.html +0 -106
  129. package/docs/types/NotificationLevel.html +0 -109
  130. package/docs/types/NotificationsChannelType.html +0 -110
  131. package/docs/types/ParticipantEmailLevel.html +0 -108
  132. package/docs/types/ParticipantType.html +0 -107
  133. package/docs/types/ParticipantUpdateReason.html +0 -106
  134. package/docs/types/PushNotificationType.html +0 -106
  135. package/docs/types/State.html +0 -110
  136. package/docs/types/UserUpdateReason.html +0 -106
@@ -179,7 +179,7 @@ class ChannelMetadataClient {
179
179
  this._cache.set(key, { item: null });
180
180
  return null;
181
181
  }
182
- throw e;
182
+ throw new Error(e);
183
183
  }
184
184
  const metadata = new ChannelMetadata(metadataResponse.type, metadataResponse.data);
185
185
  this._cache.set(key, { item: metadata });
@@ -1 +1 @@
1
- {"version":3,"file":"channel-metadata-client.js","sources":["../src/channel-metadata-client.ts"],"sourcesContent":["import {\n ChannelMetadataNotFoundError,\n CommandExecutor,\n} from \"./command-executor\";\nimport { ChannelMetadataResponse } from \"./interfaces/commands/channel-metadata-response\";\nimport QuickLRU from \"quick-lru\";\nimport { Configuration } from \"./configuration\";\n\ntype ChannelMetadataClientServices = {\n commandExecutor: CommandExecutor;\n};\n\ntype CacheEntry = {\n item: ChannelMetadata | null;\n};\n\n/**\n * Represents channel metadata.\n */\nclass ChannelMetadata {\n /**\n * Communication channel type.\n */\n public readonly type: string;\n\n /**\n * The actual metadata.\n */\n public readonly data: unknown;\n\n /**\n * @internal\n */\n public constructor(type: string, data: unknown) {\n this.type = type;\n this.data = data;\n\n Object.freeze(data);\n }\n}\n\nclass ChannelMetadataClient {\n private readonly _services: ChannelMetadataClientServices;\n private readonly _configuration: Configuration;\n private readonly _cache: QuickLRU<string, CacheEntry>;\n\n public constructor(\n services: ChannelMetadataClientServices,\n configuration: Configuration\n ) {\n this._services = services;\n this._configuration = configuration;\n this._cache = new QuickLRU({\n maxSize: configuration.channelMetadataCacheCapacity,\n });\n }\n\n public async getChannelMetadata(\n conversationSid: string,\n messageSid: string\n ): Promise<ChannelMetadata | null> {\n const key = `${conversationSid},${messageSid}`;\n const cachedItem = this._cache.get(key);\n\n if (cachedItem) {\n return cachedItem.item;\n }\n\n const url = `${this._configuration.links.conversations}/${conversationSid}/Messages/${messageSid}/ChannelMetadata`;\n let metadataResponse: ChannelMetadataResponse;\n\n try {\n metadataResponse = await this._services.commandExecutor.fetchResource<\n void,\n ChannelMetadataResponse\n >(url);\n } catch (e) {\n if (e instanceof ChannelMetadataNotFoundError) {\n this._cache.set(key, { item: null });\n return null;\n }\n\n throw e;\n }\n\n const metadata = new ChannelMetadata(\n metadataResponse.type,\n metadataResponse.data\n );\n this._cache.set(key, { item: metadata });\n return metadata;\n }\n}\n\nexport { ChannelMetadataClient, ChannelMetadata };\n"],"names":["QuickLRU","ChannelMetadataNotFoundError"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA;;AAEG;AACH,MAAM,eAAe,CAAA;AAWnB;;AAEG;IACH,WAAmB,CAAA,IAAY,EAAE,IAAa,EAAA;AAC5C,QAAA,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;AACjB,QAAA,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;AAEjB,QAAA,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;KACrB;AACF,CAAA;AAED,MAAM,qBAAqB,CAAA;IAKzB,WACE,CAAA,QAAuC,EACvC,aAA4B,EAAA;AAE5B,QAAA,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;AAC1B,QAAA,IAAI,CAAC,cAAc,GAAG,aAAa,CAA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AACF;;;;;"}
1
+ {"version":3,"file":"channel-metadata-client.js","sources":["../src/channel-metadata-client.ts"],"sourcesContent":["import {\n ChannelMetadataNotFoundError,\n CommandExecutor,\n} from \"./command-executor\";\nimport { ChannelMetadataResponse } from \"./interfaces/commands/channel-metadata-response\";\nimport QuickLRU from \"quick-lru\";\nimport { Configuration } from \"./configuration\";\n\ntype ChannelMetadataClientServices = {\n commandExecutor: CommandExecutor;\n};\n\ntype CacheEntry = {\n item: ChannelMetadata | null;\n};\n\n/**\n * Represents channel metadata.\n */\nclass ChannelMetadata {\n /**\n * Communication channel type.\n */\n public readonly type: string;\n\n /**\n * The actual metadata.\n */\n public readonly data: unknown;\n\n /**\n * @internal\n */\n public constructor(type: string, data: unknown) {\n this.type = type;\n this.data = data;\n\n Object.freeze(data);\n }\n}\n\nclass ChannelMetadataClient {\n private readonly _services: ChannelMetadataClientServices;\n private readonly _configuration: Configuration;\n private readonly _cache: QuickLRU<string, CacheEntry>;\n\n public constructor(\n services: ChannelMetadataClientServices,\n configuration: Configuration\n ) {\n this._services = services;\n this._configuration = configuration;\n this._cache = new QuickLRU({\n maxSize: configuration.channelMetadataCacheCapacity,\n });\n }\n\n public async getChannelMetadata(\n conversationSid: string,\n messageSid: string\n ): Promise<ChannelMetadata | null> {\n const key = `${conversationSid},${messageSid}`;\n const cachedItem = this._cache.get(key);\n\n if (cachedItem) {\n return cachedItem.item;\n }\n\n const url = `${this._configuration.links.conversations}/${conversationSid}/Messages/${messageSid}/ChannelMetadata`;\n let metadataResponse: ChannelMetadataResponse;\n\n try {\n metadataResponse = await this._services.commandExecutor.fetchResource<\n void,\n ChannelMetadataResponse\n >(url);\n } catch (e) {\n if (e instanceof ChannelMetadataNotFoundError) {\n this._cache.set(key, { item: null });\n return null;\n }\n\n throw new Error(e);\n }\n\n const metadata = new ChannelMetadata(\n metadataResponse.type,\n metadataResponse.data\n );\n this._cache.set(key, { item: metadata });\n return metadata;\n }\n}\n\nexport { ChannelMetadataClient, ChannelM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,QAAA,IAAI,gBAAyC,CAAC;QAE9C,IAAI;AACF,YAAA,gBAAgB,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,aAAa,CAGnE,GAAG,CAAC,CAAC;AACR,SAAA;AAAC,QAAA,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,YAAYC,4CAA4B,EAAE;AAC7C,gBAAA,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;AACrC,gBAAA,OAAO,IAAI,CAAC;AACb,aAAA;AAED,YAAA,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC;AACpB,SAAA;AAED,QAAA,MAAM,QAAQ,GAAG,IAAI,eAAe,CAClC,gBAAgB,CAAC,IAAI,EACrB,gBAAgB,CAAC,IAAI,CACtB,CAAC;AACF,QAAA,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;AACzC,QAAA,OAAO,QAAQ,CAAC;KACjB;AACF;;;;;"}
package/dist/client.js CHANGED
@@ -159,8 +159,10 @@ var _package = require('./packages/conversations/package.json.js');
159
159
  var commandExecutor = require('./command-executor.js');
160
160
  var replayEventEmitter = require('@twilio/replay-event-emitter');
161
161
  var media = require('./media.js');
162
+ var deprecationDecorator = require('@twilio/deprecation-decorator');
162
163
  var contentClient = require('./content-client.js');
163
164
  var channelMetadataClient = require('./channel-metadata-client.js');
165
+ var messageRecipientsClient = require('./message-recipients-client.js');
164
166
 
165
167
  var Client_1;
166
168
  /**
@@ -233,31 +235,25 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
233
235
  this._services = new ClientServices();
234
236
  this._myself = new user.User("", "", null, this._services);
235
237
  const startTwilsock = !this._options.twilsockClient;
238
+ // Create default init registrations if none were provided.
239
+ // Otherwise, the outside party have to list all the init registrations they
240
+ // need.
241
+ // Init registrations passed to the Conversations client will be passed down
242
+ // to the Sync client as well.
243
+ if (!this._options.initRegistrations) {
244
+ const initRegistration = new twilsock.InitRegistration(productId);
245
+ Client_1.populateInitRegistrations(initRegistration);
246
+ this._options.initRegistrations = [initRegistration];
247
+ }
236
248
  this._services.twilsockClient = this._options.twilsockClient =
237
- (_b = this._options.twilsockClient) !== null && _b !== void 0 ? _b :
238
- // todo: remove any after the release of new Twilsock
239
- new twilsock.TwilsockClient(fpaToken, productId, this._options);
240
- this._services.twilsockClient.populateInitRegistrations(new Set([notificationTypes.NotificationTypes.TYPING_INDICATOR]));
249
+ (_b = this._options.twilsockClient) !== null && _b !== void 0 ? _b : new twilsock.TwilsockClient(fpaToken, productId, this._options);
241
250
  this._services.twilsockClient.on("tokenAboutToExpire", () => this.emit("tokenAboutToExpire"));
242
251
  this._services.twilsockClient.on("tokenExpired", () => this.emit("tokenExpired"));
243
- this._services.twilsockClient.on("disconnected", () => {
244
- Client_1._logger.debug(`Handling stateChanged for ConversationsClient: new state disconnected`);
245
- if ("disconnected" !== this.connectionState) {
246
- this.connectionState = "disconnected";
247
- this.emit("connectionStateChanged", this.connectionState);
248
- }
249
- });
250
- this._services.twilsockClient.on("connecting", () => {
251
- Client_1._logger.debug(`Handling stateChanged for ConversationsClient: new state connecting`);
252
- if ("connecting" !== this.connectionState) {
253
- this.connectionState = "connecting";
254
- this.emit("connectionStateChanged", this.connectionState);
255
- }
256
- });
257
- this._services.twilsockClient.on("connected", () => {
258
- Client_1._logger.debug(`Handling stateChanged for ConversationsClient: new state connected`);
259
- if ("connected" !== this.connectionState) {
260
- this.connectionState = "connected";
252
+ this._services.twilsockClient.on("connectionError", (error) => this.emit("connectionError", error));
253
+ this._services.twilsockClient.on("stateChanged", (state) => {
254
+ Client_1._logger.debug(`Handling stateChanged for ConversationsClient: new state ${state}`);
255
+ if (state !== this.connectionState) {
256
+ this.connectionState = state;
261
257
  this.emit("connectionStateChanged", this.connectionState);
262
258
  }
263
259
  });
@@ -274,19 +270,28 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
274
270
  `https://aim.${region || "us1"}.twilio.com`;
275
271
  this._services.commandExecutor = new commandExecutor.CommandExecutor(baseUrl, { transport: this._options.transport }, productId);
276
272
  this._services.contentClient = new contentClient.ContentClient(this._services);
277
- const unsubscribeFatalError = this._services.twilsockClient.onceWithReplay("fatalError", (errorInfo) => {
278
- const error = {
279
- terminal: true,
280
- message: errorInfo.description,
281
- };
273
+ const emitFailed = (error) => {
282
274
  this._rejectEnsureReady(error);
275
+ this.emit("stateChanged", "failed");
283
276
  this.emit("initFailed", { error });
284
- });
285
- this._services.twilsockClient.onceWithReplay("connected", async () => {
277
+ };
278
+ const emitDisconnected = () => {
279
+ emitFailed({
280
+ terminal: true,
281
+ message: "Twilsock has disconnected.",
282
+ });
283
+ };
284
+ this._services.twilsockClient.once("connectionError", emitFailed);
285
+ this._services.twilsockClient.once("disconnected", emitDisconnected);
286
+ this._services.twilsockClient.once("connected", async () => {
286
287
  Client_1._logger.debug(`ConversationsClient started INITIALIZING`);
287
- unsubscribeFatalError();
288
+ this._services.twilsockClient.off("connectionError", emitFailed);
289
+ this._services.twilsockClient.off("disconnected", emitDisconnected);
288
290
  try {
291
+ const startupEvent = "conversations.client.startup";
292
+ this._services.twilsockClient.addPartialTelemetryEvent(new twilsock.TelemetryEventDescription(startupEvent, "Conversations client startup", new Date()), startupEvent, twilsock.TelemetryPoint.Start);
289
293
  await this._initialize();
294
+ this._services.twilsockClient.addPartialTelemetryEvent(new twilsock.TelemetryEventDescription("", "", new Date()), startupEvent, twilsock.TelemetryPoint.End);
290
295
  }
291
296
  catch (err) {
292
297
  // Fail ChatClient if initialization is incomplete
@@ -295,6 +300,7 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
295
300
  message: err.message,
296
301
  };
297
302
  this._rejectEnsureReady(connectionError);
303
+ this.emit("stateChanged", "failed");
298
304
  this.emit("initFailed", {
299
305
  error: connectionError,
300
306
  });
@@ -303,9 +309,7 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
303
309
  this._ensureReady = new Promise((resolve, reject) => {
304
310
  this._resolveEnsureReady = resolve;
305
311
  this._rejectEnsureReady = reject;
306
- }).catch((e) => {
307
- Client_1._logger.error(e);
308
- });
312
+ }).catch(() => void 0); // @todo How to process unhandled rejection here?
309
313
  if (startTwilsock) {
310
314
  this._services.twilsockClient.connect();
311
315
  }
@@ -325,11 +329,54 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
325
329
  get reachabilityEnabled() {
326
330
  if (!this._configuration) {
327
331
  throw new Error("Reachability information could not yet be accessed as the client " +
328
- "has not yet been initialized. Subscribe to 'initialized' and " +
329
- "'initFailed' events to properly react to the client initialization.");
332
+ "has not yet been initialized. Subscribe to the 'stateChanged' event " +
333
+ "to properly react to the client initialization.");
330
334
  }
331
335
  return this._configuration.reachabilityEnabled;
332
336
  }
337
+ /**
338
+ * @deprecated
339
+ * Current token.
340
+ * @internal
341
+ */
342
+ get token() {
343
+ return this._fpaToken;
344
+ }
345
+ /**
346
+ * @deprecated Call constructor directly.
347
+ *
348
+ * Factory method to create a Conversations client instance.
349
+ *
350
+ * The factory method will automatically trigger connection.
351
+ * Do not use it if you need finer-grained control.
352
+ *
353
+ * Since this method returns an already-initialized client, some of the events
354
+ * will be lost because they happen *before* the initialization. It is
355
+ * recommended that `client.onWithReplay` is used as opposed to `client.on`
356
+ * for subscribing to client events. The `client.onWithReplay` will re-emit
357
+ * the most recent value for a given event if it emitted before the
358
+ * subscription.
359
+ *
360
+ * @param token Access token.
361
+ * @param options Options to customize the client.
362
+ * @returns Returns a fully initialized client.
363
+ */
364
+ static async create(token, options) {
365
+ // The logic is as follows:
366
+ // - If twilsock is not passed in, then the ConversationsClient constructor will call twilsock.connect() by itself
367
+ // and we do not need to do it here.
368
+ // - If twilsock was passed in from the outside, but customer called ConversationsClient.create() then they are
369
+ // using an obsolete workflow and the startup sequence will never complete.
370
+ if (options === null || options === void 0 ? void 0 : options.twilsockClient) {
371
+ throw new Error("Obsolete usage of ConversationsClient.create() " +
372
+ "factory method: if you pass twilsock from the outside then you must " +
373
+ "use ConversationsClient constructor and be prepared to work with " +
374
+ "uninitialized client.");
375
+ }
376
+ const client = new Client_1(token, options);
377
+ await client._ensureReady;
378
+ return client;
379
+ }
333
380
  /**
334
381
  * Static method for push notification payload parsing. Returns parsed push as
335
382
  * a {@link PushNotification} object.
@@ -416,13 +463,20 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
416
463
  }
417
464
  return result;
418
465
  }
466
+ /**
467
+ * Populate the client with init registrations.
468
+ * @param reg The init registration to populate.
469
+ */
470
+ static populateInitRegistrations(reg) {
471
+ reg.populateInitRegistrations([notificationTypes.NotificationTypes.TYPING_INDICATOR]);
472
+ twilioSync.SyncClient.populateInitRegistrations(reg);
473
+ }
419
474
  /**
420
475
  * Gracefully shut down the client.
421
476
  */
422
477
  async shutdown() {
423
- var _a;
424
478
  await this._ensureReady;
425
- await ((_a = this._services.network) === null || _a === void 0 ? void 0 : _a.disconnect());
479
+ await this._services.twilsockClient.disconnect();
426
480
  }
427
481
  /**
428
482
  * Update the token used by the client and re-register with the Conversations services.
@@ -447,7 +501,13 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
447
501
  async getConversationBySid(conversationSid) {
448
502
  await this._ensureReady;
449
503
  await this._conversationsEntity.myConversationsRead.promise;
450
- const conversation = await this._conversationsEntity.getConversation(conversationSid);
504
+ let conversation = await this._conversationsEntity.getConversation(conversationSid);
505
+ if (!conversation) {
506
+ conversation = await this.peekConversationBySid(conversationSid);
507
+ if (conversation) {
508
+ deprecationDecorator.deprecationWarning("The method getConversationBySid is deprecated to retrieve conversations you're not part of. Use peekConversationBySid instead.");
509
+ }
510
+ }
451
511
  if (!conversation) {
452
512
  throw new Error(`Conversation with SID ${conversationSid} was not found.`);
453
513
  }
@@ -484,8 +544,7 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
484
544
  */
485
545
  async getSubscribedConversations() {
486
546
  await this._ensureReady;
487
- const conversations = await this._conversationsPromise;
488
- return await conversations.getConversations();
547
+ return this._conversationsPromise.then((conversations) => conversations.getConversations());
489
548
  }
490
549
  /**
491
550
  * Create a conversation on the server and subscribe to its events.
@@ -509,6 +568,16 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
509
568
  this._services.notificationClient.setPushRegistrationId(channelType, registrationId);
510
569
  await this._services.notificationClient.commitChanges(); // Committing before this point is useless because we have no push id
511
570
  }
571
+ /**
572
+ * Unregister from push notifications.
573
+ * @param channelType Channel type.
574
+ * @deprecated Use removePushRegistrations() instead.
575
+ */
576
+ async unsetPushRegistrationId(channelType) {
577
+ await this._ensureReady;
578
+ this._unsubscribeFromPushNotifications(channelType);
579
+ await this._services.notificationClient.commitChanges();
580
+ }
512
581
  /**
513
582
  * Clear existing registrations directly using provided device token.
514
583
  * This is useful to ensure stopped subscriptions without resubscribing.
@@ -605,6 +674,7 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
605
674
  const configurationResponse = await this._services.commandExecutor.fetchResource("Client/v2/Configuration");
606
675
  this._configuration = new configuration.Configuration(this._options, configurationResponse, Client_1._logger);
607
676
  this._services.channelMetadataClient = new channelMetadataClient.ChannelMetadataClient(this._services, this._configuration);
677
+ this._services.messageRecipientsClient = new messageRecipientsClient.MessageRecipientsClient(this._services, this._configuration);
608
678
  this._myself._resolveInitialization(this._configuration, this._configuration.userIdentity, this._configuration.userInfo, true);
609
679
  this._services.typingIndicator = new typingIndicator.TypingIndicator(this.getConversationBySid.bind(this), this._configuration, this._services);
610
680
  this._services.network = new network.Network(this._configuration, this._services);
@@ -646,9 +716,6 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
646
716
  .fetchConversations()
647
717
  .then(() => this._conversationsEntity)
648
718
  .catch((error) => {
649
- if (error.message === "Client has been shut down.") {
650
- return this._conversationsEntity;
651
- }
652
719
  throw error;
653
720
  });
654
721
  await this._services.users.myself._ensureFetched();
@@ -656,6 +723,7 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
656
723
  this._services.typingIndicator.initialize();
657
724
  this._services.mcsClient = new mcsClient.McsClient(this._fpaToken, this._configuration.links.mediaService, this._configuration.links.mediaSetService, Object.assign(Object.assign({}, this._options), { transport: undefined }));
658
725
  this._resolveEnsureReady();
726
+ this.emit("stateChanged", "initialized");
659
727
  this.emit("initialized");
660
728
  }
661
729
  /**
@@ -673,6 +741,21 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
673
741
  this._services.notificationClient.subscribe(channelType, messageType);
674
742
  });
675
743
  }
744
+ /**
745
+ * Unsubscribe from push notifications.
746
+ * @param channelType The channel type to unsubscribe from.
747
+ */
748
+ _unsubscribeFromPushNotifications(channelType) {
749
+ [
750
+ notificationTypes.NotificationTypes.NEW_MESSAGE,
751
+ notificationTypes.NotificationTypes.ADDED_TO_CONVERSATION,
752
+ notificationTypes.NotificationTypes.REMOVED_FROM_CONVERSATION,
753
+ notificationTypes.NotificationTypes.TYPING_INDICATOR,
754
+ notificationTypes.NotificationTypes.CONSUMPTION_UPDATE,
755
+ ].forEach((messageType) => {
756
+ this._services.notificationClient.unsubscribe(channelType, messageType);
757
+ });
758
+ }
676
759
  };
677
760
  /**
678
761
  * Fired when a conversation becomes visible to the client. The event is also
@@ -844,6 +927,15 @@ exports.Client.userUnsubscribed = "userUnsubscribed";
844
927
  * @event
845
928
  */
846
929
  exports.Client.userUpdated = "userUpdated";
930
+ /**
931
+ * @deprecated Use initialized or initFailed events instead
932
+ * Fired when the state of the client has been changed.
933
+ *
934
+ * Parameters:
935
+ * 1. {@link State} `state` - the new client state
936
+ * @event
937
+ */
938
+ exports.Client.stateChanged = "stateChanged";
847
939
  /**
848
940
  * Fired when the client has completed initialization successfully.
849
941
  * @event
@@ -906,6 +998,11 @@ exports.Client._supportedPushDataFields = {
906
998
  media_count: "mediaCount",
907
999
  media: "media", // object
908
1000
  };
1001
+ tslib_es6.__decorate([
1002
+ deprecationDecorator.deprecated("token"),
1003
+ tslib_es6.__metadata("design:type", String),
1004
+ tslib_es6.__metadata("design:paramtypes", [])
1005
+ ], exports.Client.prototype, "token", null);
909
1006
  tslib_es6.__decorate([
910
1007
  declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString),
911
1008
  tslib_es6.__metadata("design:type", Function),
@@ -949,6 +1046,12 @@ tslib_es6.__decorate([
949
1046
  tslib_es6.__metadata("design:paramtypes", [String, String]),
950
1047
  tslib_es6.__metadata("design:returntype", Promise)
951
1048
  ], exports.Client.prototype, "setPushRegistrationId", null);
1049
+ tslib_es6.__decorate([
1050
+ declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.literal("fcm", "apn")),
1051
+ tslib_es6.__metadata("design:type", Function),
1052
+ tslib_es6.__metadata("design:paramtypes", [String]),
1053
+ tslib_es6.__metadata("design:returntype", Promise)
1054
+ ], exports.Client.prototype, "unsetPushRegistrationId", null);
952
1055
  tslib_es6.__decorate([
953
1056
  declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.literal("fcm", "apn"), declarativeTypeValidator.nonEmptyString),
954
1057
  tslib_es6.__metadata("design:type", Function),
@@ -979,6 +1082,13 @@ tslib_es6.__decorate([
979
1082
  tslib_es6.__metadata("design:paramtypes", [Array]),
980
1083
  tslib_es6.__metadata("design:returntype", mcsClient.CancellablePromise)
981
1084
  ], exports.Client.prototype, "getTemporaryContentUrlsForMedia", null);
1085
+ tslib_es6.__decorate([
1086
+ deprecationDecorator.deprecated("Client.create()", "new Client()"),
1087
+ declarativeTypeValidator.validateTypesAsync("string", ["undefined", declarativeTypeValidator.pureObject]),
1088
+ tslib_es6.__metadata("design:type", Function),
1089
+ tslib_es6.__metadata("design:paramtypes", [String, Object]),
1090
+ tslib_es6.__metadata("design:returntype", Promise)
1091
+ ], exports.Client, "create", null);
982
1092
  tslib_es6.__decorate([
983
1093
  declarativeTypeValidator.validateTypes(declarativeTypeValidator.pureObject),
984
1094
  tslib_es6.__metadata("design:type", Function),