@twilio/conversations 3.0.0-rc.9 → 3.0.1-rc.1

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 (158) hide show
  1. package/README.md +38 -28
  2. package/builds/browser.js +4327 -7903
  3. package/builds/browser.js.map +1 -1
  4. package/builds/lib.d.ts +629 -102
  5. package/builds/lib.js +4319 -7904
  6. package/builds/lib.js.map +1 -1
  7. package/builds/twilio-conversations.js +27540 -41958
  8. package/builds/twilio-conversations.min.js +200 -1
  9. package/dist/aggregated-delivery-receipt.js +10 -1
  10. package/dist/aggregated-delivery-receipt.js.map +1 -1
  11. package/dist/channel-metadata-client.js +192 -0
  12. package/dist/channel-metadata-client.js.map +1 -0
  13. package/dist/client.js +75 -123
  14. package/dist/client.js.map +1 -1
  15. package/dist/command-executor.js +81 -20
  16. package/dist/command-executor.js.map +1 -1
  17. package/dist/configuration.js +14 -3
  18. package/dist/configuration.js.map +1 -1
  19. package/dist/content-client.js +184 -0
  20. package/dist/content-client.js.map +1 -0
  21. package/dist/content-template.js +310 -0
  22. package/dist/content-template.js.map +1 -0
  23. package/dist/conversation.js +105 -22
  24. package/dist/conversation.js.map +1 -1
  25. package/dist/data/conversations.js +43 -5
  26. package/dist/data/conversations.js.map +1 -1
  27. package/dist/data/messages.js +26 -19
  28. package/dist/data/messages.js.map +1 -1
  29. package/dist/data/participants.js +15 -4
  30. package/dist/data/participants.js.map +1 -1
  31. package/dist/data/users.js +11 -2
  32. package/dist/data/users.js.map +1 -1
  33. package/dist/detailed-delivery-receipt.js +9 -0
  34. package/dist/detailed-delivery-receipt.js.map +1 -1
  35. package/dist/index.js +20 -2
  36. package/dist/index.js.map +1 -1
  37. package/dist/interfaces/notification-types.js +9 -0
  38. package/dist/interfaces/notification-types.js.map +1 -1
  39. package/dist/interfaces/{attributes.js → rules.js} +26 -7
  40. package/dist/interfaces/rules.js.map +1 -0
  41. package/dist/logger.js +9 -0
  42. package/dist/logger.js.map +1 -1
  43. package/dist/media.js +9 -0
  44. package/dist/media.js.map +1 -1
  45. package/dist/message-builder.js +77 -6
  46. package/dist/message-builder.js.map +1 -1
  47. package/dist/message.js +115 -22
  48. package/dist/message.js.map +1 -1
  49. package/dist/node_modules/quick-lru/index.js +265 -0
  50. package/dist/node_modules/quick-lru/index.js.map +1 -0
  51. package/dist/node_modules/tslib/tslib.es6.js +9 -0
  52. package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
  53. package/dist/packages/conversations/package.json.js +10 -1
  54. package/dist/packages/conversations/package.json.js.map +1 -1
  55. package/dist/participant.js +45 -36
  56. package/dist/participant.js.map +1 -1
  57. package/dist/push-notification.js +9 -0
  58. package/dist/push-notification.js.map +1 -1
  59. package/dist/rest-paginator.js +20 -11
  60. package/dist/rest-paginator.js.map +1 -1
  61. package/dist/services/network.js +110 -11
  62. package/dist/services/network.js.map +1 -1
  63. package/dist/services/typing-indicator.js +22 -5
  64. package/dist/services/typing-indicator.js.map +1 -1
  65. package/dist/unsent-message.js +9 -0
  66. package/dist/unsent-message.js.map +1 -1
  67. package/dist/user.js +20 -3
  68. package/dist/user.js.map +1 -1
  69. package/dist/util/deferred.js +9 -0
  70. package/dist/util/deferred.js.map +1 -1
  71. package/dist/util/index.js +9 -0
  72. package/dist/util/index.js.map +1 -1
  73. package/docs/.nojekyll +1 -0
  74. package/docs/assets/highlight.css +113 -0
  75. package/docs/assets/main.js +58 -0
  76. package/docs/assets/search.js +1 -0
  77. package/docs/assets/style.css +1279 -0
  78. package/docs/classes/AggregatedDeliveryReceipt.html +144 -3182
  79. package/docs/classes/CancellablePromise.html +224 -3209
  80. package/docs/classes/CancellationError.html +112 -0
  81. package/docs/classes/ChannelMetadata.html +67 -0
  82. package/docs/classes/Client.html +701 -4237
  83. package/docs/classes/ContentTemplate.html +97 -0
  84. package/docs/classes/ContentTemplateVariable.html +90 -0
  85. package/docs/classes/Conversation.html +768 -4352
  86. package/docs/classes/DetailedDeliveryReceipt.html +116 -3162
  87. package/docs/classes/Media.html +119 -3165
  88. package/docs/classes/Message.html +417 -3730
  89. package/docs/classes/MessageBuilder.html +208 -3274
  90. package/docs/classes/Participant.html +258 -3442
  91. package/docs/classes/PushNotification.html +101 -3129
  92. package/docs/classes/RestPaginator.html +120 -3158
  93. package/docs/classes/UnsentMessage.html +63 -3040
  94. package/docs/classes/User.html +209 -3347
  95. package/docs/index.html +146 -3502
  96. package/docs/interfaces/ClientOptions.html +66 -3033
  97. package/docs/interfaces/ConversationBindings.html +109 -3000
  98. package/docs/interfaces/ConversationEmailBinding.html +109 -3000
  99. package/docs/interfaces/ConversationLimits.html +87 -3097
  100. package/docs/interfaces/ConversationState.html +66 -3049
  101. package/docs/interfaces/ConversationUpdatedEventArgs.html +109 -3000
  102. package/docs/interfaces/CreateConversationOptions.html +73 -3065
  103. package/docs/interfaces/LastMessage.html +66 -3049
  104. package/docs/interfaces/Paginator.html +110 -3139
  105. package/docs/interfaces/ParticipantBindingOptions.html +110 -0
  106. package/docs/interfaces/ParticipantBindings.html +109 -3000
  107. package/docs/interfaces/ParticipantEmailBinding.html +109 -3000
  108. package/docs/interfaces/PushNotificationData.html +94 -3113
  109. package/docs/interfaces/SendEmailOptions.html +59 -3033
  110. package/docs/interfaces/SendMediaOptions.html +75 -3067
  111. package/docs/modules.html +180 -3509
  112. package/docs/types/ChannelType.html +106 -0
  113. package/docs/types/ConnectionState.html +115 -0
  114. package/docs/types/ContentData.html +106 -0
  115. package/docs/types/ContentDataAction.html +107 -0
  116. package/docs/types/ContentDataActionOther.html +121 -0
  117. package/docs/types/ContentDataActionPhone.html +128 -0
  118. package/docs/types/ContentDataActionReply.html +133 -0
  119. package/docs/types/ContentDataActionUrl.html +128 -0
  120. package/docs/types/ContentDataCallToAction.html +131 -0
  121. package/docs/types/ContentDataCard.html +137 -0
  122. package/docs/types/ContentDataListItem.html +121 -0
  123. package/docs/types/ContentDataListPicker.html +134 -0
  124. package/docs/types/ContentDataLocation.html +134 -0
  125. package/docs/types/ContentDataMedia.html +129 -0
  126. package/docs/types/ContentDataOther.html +121 -0
  127. package/docs/types/ContentDataQuickReply.html +131 -0
  128. package/docs/types/ContentDataReply.html +119 -0
  129. package/docs/types/ContentDataText.html +125 -0
  130. package/docs/types/ConversationStatus.html +107 -0
  131. package/docs/types/ConversationUpdateReason.html +106 -0
  132. package/docs/types/DeliveryAmount.html +106 -0
  133. package/docs/types/DeliveryStatus.html +106 -0
  134. package/docs/types/JSONArray.html +106 -0
  135. package/docs/types/JSONObject.html +111 -0
  136. package/docs/types/JSONValue.html +106 -0
  137. package/docs/types/LogLevel.html +106 -0
  138. package/docs/types/MediaCategory.html +106 -0
  139. package/docs/types/MessageType.html +106 -0
  140. package/docs/types/MessageUpdateReason.html +106 -0
  141. package/docs/types/NotificationLevel.html +109 -0
  142. package/docs/types/NotificationsChannelType.html +110 -0
  143. package/docs/types/ParticipantEmailLevel.html +108 -0
  144. package/docs/types/ParticipantType.html +107 -0
  145. package/docs/types/ParticipantUpdateReason.html +106 -0
  146. package/docs/types/PushNotificationType.html +106 -0
  147. package/docs/types/State.html +110 -0
  148. package/docs/types/UserUpdateReason.html +106 -0
  149. package/package.json +22 -17
  150. package/CHANGELOG.md +0 -509
  151. package/dist/interfaces/attributes.js.map +0 -1
  152. package/docs/assets/css/main.css +0 -2660
  153. package/docs/assets/images/icons.png +0 -0
  154. package/docs/assets/images/icons@2x.png +0 -0
  155. package/docs/assets/images/widgets.png +0 -0
  156. package/docs/assets/images/widgets@2x.png +0 -0
  157. package/docs/assets/js/main.js +0 -248
  158. package/docs/assets/js/search.js +0 -1
@@ -128,13 +128,22 @@ This software includes platform.js under the following license.
128
128
  */
129
129
  'use strict';
130
130
 
131
+ var global =
132
+ typeof global !== "undefined"
133
+ ? global
134
+ : typeof self !== "undefined"
135
+ ? self
136
+ : typeof window !== "undefined"
137
+ ? window
138
+ : {};
139
+
131
140
  Object.defineProperty(exports, '__esModule', { value: true });
132
141
 
133
142
  /**
134
143
  * Contains aggregated information about delivery statuses of a message across all participants
135
144
  * of a conversation.
136
145
  *
137
- * At any moment during the message delivery to a participant, the message can have zero or more of following
146
+ * At any moment during the message delivery to a participant, the message can have zero or more of the following
138
147
  * delivery statuses:
139
148
  * * Message is considered as **sent** to a participant if the nearest upstream carrier accepted the message.
140
149
  * * Message is considered as **delivered** to a participant if Twilio has received confirmation of message
@@ -1 +1 @@
1
- {"version":3,"file":"aggregated-delivery-receipt.js","sources":["../src/aggregated-delivery-receipt.ts"],"sourcesContent":["/**\n * Signifies the amount of participants which have the status for the message.\n */\ntype DeliveryAmount = \"none\" | \"some\" | \"all\";\n\ninterface AggregatedDeliveryDescriptor {\n total: number;\n delivered: DeliveryAmount;\n failed: DeliveryAmount;\n read: DeliveryAmount;\n sent: DeliveryAmount;\n undelivered: DeliveryAmount;\n}\n\n/**\n * Contains aggregated information about delivery statuses of a message across all participants\n * of a conversation.\n *\n * At any moment during the message delivery to a participant, the message can have zero or more of following\n * delivery statuses:\n * * Message is considered as **sent** to a participant if the nearest upstream carrier accepted the message.\n * * Message is considered as **delivered** to a participant if Twilio has received confirmation of message\n * delivery from the upstream carrier, and, where available, the destination handset.\n * * Message considered as **undelivered** to a participant if Twilio has received a delivery receipt\n * indicating that the message was not delivered. This can happen for many reasons including carrier content\n * filtering and the availability of the destination handset.\n * * Message considered as **read** by a participant if the message has been delivered and opened by the\n * recipient in a conversation. The recipient must have enabled the read receipts.\n * * Message considered as **failed** to be delivered to a participant if the message could not be sent.\n * This can happen for various reasons including queue overflows, account suspensions and media\n * errors (in the case of MMS for instance).\n *\n * {@link AggregatedDeliveryReceipt} class contains an aggregated value {@link DeliveryAmount} for each delivery status.\n */\nclass AggregatedDeliveryReceipt {\n private state: AggregatedDeliveryDescriptor;\n\n /**\n * @internal\n */\n constructor(data: AggregatedDeliveryDescriptor) {\n this.state = data;\n }\n\n /**\n * Maximum number of delivery events expected for the message.\n */\n public get total(): number {\n return this.state.total;\n }\n\n /**\n * Message is considered as **sent** to a participant if the nearest upstream carrier accepted the message.\n *\n * @return Amount of participants that have the **sent** delivery status for the message.\n */\n public get sent(): DeliveryAmount {\n return this.state.sent;\n }\n\n /**\n * Message is considered as **delivered** to a participant if Twilio has received confirmation of message\n * delivery from the upstream carrier, and, where available, the destination handset.\n *\n * @return Amount of participants that have the **delivered** delivery status for the message.\n */\n public get delivered(): DeliveryAmount {\n return this.state.delivered;\n }\n\n /**\n * Message is considered as **read** by a participant, if the message has been delivered and opened by the\n * recipient in a conversation. The recipient must have enabled the read receipts.\n *\n * @return Amount of participants that have the **read** delivery status for the message.\n */\n public get read(): DeliveryAmount {\n return this.state.read;\n }\n\n /**\n * Message is considered as **undelivered** to a participant if Twilio has received a delivery receipt\n * indicating that the message was not delivered. This can happen for many reasons including carrier content\n * filtering and the availability of the destination handset.\n *\n * @return Ammount of participants that have the **undelivered** delivery status for the message.\n */\n public get undelivered(): DeliveryAmount {\n return this.state.undelivered;\n }\n\n /**\n * Message is considered as **failed** to be delivered to a participant if the message could not be sent.\n * This can happen for various reasons including queue overflows, account suspensions and media\n * errors (in the case of MMS for instance). Twilio does not charge you for failed messages.\n *\n * @return Amount of participants that have the **failed** delivery status for the message.\n */\n public get failed(): DeliveryAmount {\n return this.state.failed;\n }\n\n _update(data: AggregatedDeliveryDescriptor): void {\n this.state = data;\n }\n\n _isEquals(data: AggregatedDeliveryDescriptor): boolean {\n const isTotalSame = this.total === data.total;\n const isSentSame = this.sent === data.sent;\n const isDeliveredSame = this.delivered === data.delivered;\n const isReadSame = this.read === data.read;\n const isUndeliveredSame = this.undelivered === data.undelivered;\n const isFailedSame = this.failed === data.failed;\n\n return (\n isTotalSame &&\n isSentSame &&\n isDeliveredSame &&\n isReadSame &&\n isUndeliveredSame &&\n isFailedSame\n );\n }\n}\n\nexport {\n AggregatedDeliveryReceipt,\n AggregatedDeliveryDescriptor,\n DeliveryAmount,\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AS,CAAC;QAC1D,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC;QAC3C,MAAM,iBAAiB,GAAG,IAAI,CAAC,WAAW,KAAK,IAAI,CAAC,WAAW,CAAC;QAChE,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,CAAC;AAEjD,QAAA,QACE,WAAW;YACX,UAAU;YACV,eAAe;YACf,UAAU;YACV,iBAAiB;AACjB,YAAA,YAAY,EACZ;KACH;AACF;;;;"}
1
+ {"version":3,"file":"aggregated-delivery-receipt.js","sources":["../src/aggregated-delivery-receipt.ts"],"sourcesContent":["/**\n * Signifies the amount of participants which have the status for the message.\n */\ntype DeliveryAmount = \"none\" | \"some\" | \"all\";\n\ninterface AggregatedDeliveryDescriptor {\n total: number;\n delivered: DeliveryAmount;\n failed: DeliveryAmount;\n read: DeliveryAmount;\n sent: DeliveryAmount;\n undelivered: DeliveryAmount;\n}\n\n/**\n * Contains aggregated information about delivery statuses of a message across all participants\n * of a conversation.\n *\n * At any moment during the message delivery to a participant, the message can have zero or more of the following\n * delivery statuses:\n * * Message is considered as **sent** to a participant if the nearest upstream carrier accepted the message.\n * * Message is considered as **delivered** to a participant if Twilio has received confirmation of message\n * delivery from the upstream carrier, and, where available, the destination handset.\n * * Message considered as **undelivered** to a participant if Twilio has received a delivery receipt\n * indicating that the message was not delivered. This can happen for many reasons including carrier content\n * filtering and the availability of the destination handset.\n * * Message considered as **read** by a participant if the message has been delivered and opened by the\n * recipient in a conversation. The recipient must have enabled the read receipts.\n * * Message considered as **failed** to be delivered to a participant if the message could not be sent.\n * This can happen for various reasons including queue overflows, account suspensions and media\n * errors (in the case of MMS for instance).\n *\n * {@link AggregatedDeliveryReceipt} class contains an aggregated value {@link DeliveryAmount} for each delivery status.\n */\nclass AggregatedDeliveryReceipt {\n private state: AggregatedDeliveryDescriptor;\n\n /**\n * @internal\n */\n constructor(data: AggregatedDeliveryDescriptor) {\n this.state = data;\n }\n\n /**\n * Maximum number of delivery events expected for the message.\n */\n public get total(): number {\n return this.state.total;\n }\n\n /**\n * Message is considered as **sent** to a participant if the nearest upstream carrier accepted the message.\n *\n * @return Amount of participants that have the **sent** delivery status for the message.\n */\n public get sent(): DeliveryAmount {\n return this.state.sent;\n }\n\n /**\n * Message is considered as **delivered** to a participant if Twilio has received confirmation of message\n * delivery from the upstream carrier, and, where available, the destination handset.\n *\n * @return Amount of participants that have the **delivered** delivery status for the message.\n */\n public get delivered(): DeliveryAmount {\n return this.state.delivered;\n }\n\n /**\n * Message is considered as **read** by a participant, if the message has been delivered and opened by the\n * recipient in a conversation. The recipient must have enabled the read receipts.\n *\n * @return Amount of participants that have the **read** delivery status for the message.\n */\n public get read(): DeliveryAmount {\n return this.state.read;\n }\n\n /**\n * Message is considered as **undelivered** to a participant if Twilio has received a delivery receipt\n * indicating that the message was not delivered. This can happen for many reasons including carrier content\n * filtering and the availability of the destination handset.\n *\n * @return Ammount of participants that have the **undelivered** delivery status for the message.\n */\n public get undelivered(): DeliveryAmount {\n return this.state.undelivered;\n }\n\n /**\n * Message is considered as **failed** to be delivered to a participant if the message could not be sent.\n * This can happen for various reasons including queue overflows, account suspensions and media\n * errors (in the case of MMS for instance). Twilio does not charge you for failed messages.\n *\n * @return Amount of participants that have the **failed** delivery status for the message.\n */\n public get failed(): DeliveryAmount {\n return this.state.failed;\n }\n\n _update(data: AggregatedDeliveryDescriptor): void {\n this.state = data;\n }\n\n _isEquals(data: AggregatedDeliveryDescriptor): boolean {\n const isTotalSame = this.total === data.total;\n const isSentSame = this.sent === data.sent;\n const isDeliveredSame = this.delivered === data.delivered;\n const isReadSame = this.read === data.read;\n const isUndeliveredSame = this.undelivered === data.undelivered;\n const isFailedSame = this.failed === data.failed;\n\n return (\n isTotalSame &&\n isSentSame &&\n isDeliveredSame &&\n isReadSame &&\n isUndeliveredSame &&\n isFailedSame\n );\n }\n}\n\nexport {\n AggregatedDeliveryReceipt,\n Aggreg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G,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC;QAC3C,MAAM,eAAe,GAAG,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC,SAAS,CAAC;QAC1D,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC;QAC3C,MAAM,iBAAiB,GAAG,IAAI,CAAC,WAAW,KAAK,IAAI,CAAC,WAAW,CAAC;QAChE,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,CAAC;AAEjD,QAAA,QACE,WAAW;YACX,UAAU;YACV,eAAe;YACf,UAAU;YACV,iBAAiB;AACjB,YAAA,YAAY,EACZ;KACH;AACF;;;;"}
@@ -0,0 +1,192 @@
1
+ /*
2
+ @license
3
+ The following license applies to all parts of this software except as
4
+ documented below.
5
+
6
+ Copyright (c) 2019, Twilio, inc.
7
+ All rights reserved.
8
+
9
+ Redistribution and use in source and binary forms, with or without
10
+ modification, are permitted provided that the following conditions are
11
+ met:
12
+
13
+ 1. Redistributions of source code must retain the above copyright
14
+ notice, this list of conditions and the following disclaimer.
15
+
16
+ 2. Redistributions in binary form must reproduce the above copyright
17
+ notice, this list of conditions and the following disclaimer in
18
+ the documentation and/or other materials provided with the
19
+ distribution.
20
+
21
+ 3. Neither the name of Twilio nor the names of its contributors may
22
+ be used to endorse or promote products derived from this software
23
+ without specific prior written permission.
24
+
25
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29
+ HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
+
37
+ This software includes javascript-state-machine under the following license.
38
+
39
+ Copyright (c) 2012, 2013, 2014, 2015, Jake Gordon and contributors
40
+
41
+ Permission is hereby granted, free of charge, to any person obtaining a copy
42
+ of this software and associated documentation files (the "Software"), to deal
43
+ in the Software without restriction, including without limitation the rights
44
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
45
+ copies of the Software, and to permit persons to whom the Software is
46
+ furnished to do so, subject to the following conditions:
47
+
48
+ The above copyright notice and this permission notice shall be included in all
49
+ copies or substantial portions of the Software.
50
+
51
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
52
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
53
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
54
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
55
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
56
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
57
+
58
+ This software includes loglevel under the following license.
59
+
60
+ Copyright (c) 2013 Tim Perry
61
+
62
+ Permission is hereby granted, free of charge, to any person
63
+ obtaining a copy of this software and associated documentation
64
+ files (the "Software"), to deal in the Software without
65
+ restriction, including without limitation the rights to use,
66
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
67
+ copies of the Software, and to permit persons to whom the
68
+ Software is furnished to do so, subject to the following
69
+ conditions:
70
+
71
+ The above copyright notice and this permission notice shall be
72
+ included in all copies or substantial portions of the Software.
73
+
74
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
75
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
76
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
77
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
78
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
79
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
80
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
81
+ OTHER DEALINGS IN THE SOFTWARE.
82
+
83
+ This software includes q under the following license.
84
+
85
+ Copyright 2009–2014 Kristopher Michael Kowal. All rights reserved.
86
+ Permission is hereby granted, free of charge, to any person obtaining a copy
87
+ of this software and associated documentation files (the "Software"), to
88
+ deal in the Software without restriction, including without limitation the
89
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
90
+ sell copies of the Software, and to permit persons to whom the Software is
91
+ furnished to do so, subject to the following conditions:
92
+
93
+ The above copyright notice and this permission notice shall be included in
94
+ all copies or substantial portions of the Software.
95
+
96
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
97
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
98
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
99
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
100
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
101
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
102
+ IN THE SOFTWARE.
103
+
104
+ This software includes platform.js under the following license.
105
+
106
+ Copyright 2014 Benjamin Tan <https://d10.github.io/>
107
+ Copyright 2011-2015 John-David Dalton <http://allyoucanleet.com/>
108
+
109
+ Permission is hereby granted, free of charge, to any person obtaining
110
+ a copy of this software and associated documentation files (the
111
+ "Software"), to deal in the Software without restriction, including
112
+ without limitation the rights to use, copy, modify, merge, publish,
113
+ distribute, sublicense, and/or sell copies of the Software, and to
114
+ permit persons to whom the Software is furnished to do so, subject to
115
+ the following conditions:
116
+
117
+ The above copyright notice and this permission notice shall be
118
+ included in all copies or substantial portions of the Software.
119
+
120
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
121
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
122
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
123
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
124
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
125
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
126
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
127
+
128
+ */
129
+ 'use strict';
130
+
131
+ var global =
132
+ typeof global !== "undefined"
133
+ ? global
134
+ : typeof self !== "undefined"
135
+ ? self
136
+ : typeof window !== "undefined"
137
+ ? window
138
+ : {};
139
+
140
+ Object.defineProperty(exports, '__esModule', { value: true });
141
+
142
+ var commandExecutor = require('./command-executor.js');
143
+ var index = require('./node_modules/quick-lru/index.js');
144
+
145
+ /**
146
+ * Represents channel metadata.
147
+ */
148
+ class ChannelMetadata {
149
+ /**
150
+ * @internal
151
+ */
152
+ constructor(type, data) {
153
+ this.type = type;
154
+ this.data = data;
155
+ Object.freeze(data);
156
+ }
157
+ }
158
+ class ChannelMetadataClient {
159
+ constructor(services, configuration) {
160
+ this._services = services;
161
+ this._configuration = configuration;
162
+ this._cache = new index["default"]({
163
+ maxSize: configuration.channelMetadataCacheCapacity,
164
+ });
165
+ }
166
+ async getChannelMetadata(conversationSid, messageSid) {
167
+ const key = `${conversationSid},${messageSid}`;
168
+ const cachedItem = this._cache.get(key);
169
+ if (cachedItem) {
170
+ return cachedItem.item;
171
+ }
172
+ const url = `${this._configuration.links.conversations}/${conversationSid}/Messages/${messageSid}/ChannelMetadata`;
173
+ let metadataResponse;
174
+ try {
175
+ metadataResponse = await this._services.commandExecutor.fetchResource(url);
176
+ }
177
+ catch (e) {
178
+ if (e instanceof commandExecutor.ChannelMetadataNotFoundError) {
179
+ this._cache.set(key, { item: null });
180
+ return null;
181
+ }
182
+ throw e;
183
+ }
184
+ const metadata = new ChannelMetadata(metadataResponse.type, metadataResponse.data);
185
+ this._cache.set(key, { item: metadata });
186
+ return metadata;
187
+ }
188
+ }
189
+
190
+ exports.ChannelMetadata = ChannelMetadata;
191
+ exports.ChannelMetadataClient = ChannelMetadataClient;
192
+ //# sourceMappingURL=channel-metadata-client.js.map
@@ -0,0 +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,C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AAC,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
@@ -128,6 +128,15 @@ This software includes platform.js under the following license.
128
128
  */
129
129
  'use strict';
130
130
 
131
+ var global =
132
+ typeof global !== "undefined"
133
+ ? global
134
+ : typeof self !== "undefined"
135
+ ? self
136
+ : typeof window !== "undefined"
137
+ ? window
138
+ : {};
139
+
131
140
  Object.defineProperty(exports, '__esModule', { value: true });
132
141
 
133
142
  var tslib_es6 = require('./node_modules/tslib/tslib.es6.js');
@@ -150,6 +159,8 @@ var _package = require('./packages/conversations/package.json.js');
150
159
  var commandExecutor = require('./command-executor.js');
151
160
  var replayEventEmitter = require('@twilio/replay-event-emitter');
152
161
  var media = require('./media.js');
162
+ var contentClient = require('./content-client.js');
163
+ var channelMetadataClient = require('./channel-metadata-client.js');
153
164
 
154
165
  var Client_1;
155
166
  /**
@@ -222,25 +233,31 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
222
233
  this._services = new ClientServices();
223
234
  this._myself = new user.User("", "", null, this._services);
224
235
  const startTwilsock = !this._options.twilsockClient;
225
- // Create default init registrations if none were provided.
226
- // Otherwise, the outside party have to list all the init registrations they
227
- // need.
228
- // Init registrations passed to the Conversations client will be passed down
229
- // to the Sync client as well.
230
- if (!this._options.initRegistrations) {
231
- const initRegistration = new twilsock.InitRegistration(productId);
232
- Client_1.populateInitRegistrations(initRegistration);
233
- this._options.initRegistrations = [initRegistration];
234
- }
235
236
  this._services.twilsockClient = this._options.twilsockClient =
236
- (_b = this._options.twilsockClient) !== null && _b !== void 0 ? _b : new twilsock.TwilsockClient(fpaToken, productId, this._options);
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]));
237
241
  this._services.twilsockClient.on("tokenAboutToExpire", () => this.emit("tokenAboutToExpire"));
238
242
  this._services.twilsockClient.on("tokenExpired", () => this.emit("tokenExpired"));
239
- this._services.twilsockClient.on("connectionError", (error) => this.emit("connectionError", error));
240
- this._services.twilsockClient.on("stateChanged", (state) => {
241
- Client_1._logger.debug(`Handling stateChanged for ConversationsClient: new state ${state}`);
242
- if (state !== this.connectionState) {
243
- this.connectionState = state;
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";
244
261
  this.emit("connectionStateChanged", this.connectionState);
245
262
  }
246
263
  });
@@ -256,27 +273,20 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
256
273
  configurationOptions.typingUri ||
257
274
  `https://aim.${region || "us1"}.twilio.com`;
258
275
  this._services.commandExecutor = new commandExecutor.CommandExecutor(baseUrl, { transport: this._options.transport }, productId);
259
- const emitFailed = (error) => {
260
- this._rejectEnsureReady(error);
261
- this.emit("stateChanged", { state: "failed", error });
262
- };
263
- const emitDisconnected = () => {
264
- emitFailed({
276
+ this._services.contentClient = new contentClient.ContentClient(this._services);
277
+ const unsubscribeFatalError = this._services.twilsockClient.onceWithReplay("fatalError", (errorInfo) => {
278
+ const error = {
265
279
  terminal: true,
266
- message: "Twilsock has disconnected.",
267
- });
268
- };
269
- this._services.twilsockClient.onceWithReplay("connectionError", emitFailed);
270
- this._services.twilsockClient.onceWithReplay("disconnected", emitDisconnected);
280
+ message: errorInfo.description,
281
+ };
282
+ this._rejectEnsureReady(error);
283
+ this.emit("initFailed", { error });
284
+ });
271
285
  this._services.twilsockClient.onceWithReplay("connected", async () => {
272
286
  Client_1._logger.debug(`ConversationsClient started INITIALIZING`);
273
- this._services.twilsockClient.off("connectionError", emitFailed);
274
- this._services.twilsockClient.off("disconnected", emitDisconnected);
287
+ unsubscribeFatalError();
275
288
  try {
276
- const startupEvent = "conversations.client.startup";
277
- this._services.twilsockClient.addPartialTelemetryEvent(new twilsock.TelemetryEventDescription(startupEvent, "Conversations client startup", new Date()), startupEvent, twilsock.TelemetryPoint.Start);
278
289
  await this._initialize();
279
- this._services.twilsockClient.addPartialTelemetryEvent(new twilsock.TelemetryEventDescription("", "", new Date()), startupEvent, twilsock.TelemetryPoint.End);
280
290
  }
281
291
  catch (err) {
282
292
  // Fail ChatClient if initialization is incomplete
@@ -285,13 +295,17 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
285
295
  message: err.message,
286
296
  };
287
297
  this._rejectEnsureReady(connectionError);
288
- this.emit("stateChanged", { state: "failed", error: connectionError });
298
+ this.emit("initFailed", {
299
+ error: connectionError,
300
+ });
289
301
  }
290
302
  });
291
303
  this._ensureReady = new Promise((resolve, reject) => {
292
304
  this._resolveEnsureReady = resolve;
293
305
  this._rejectEnsureReady = reject;
294
- }).catch(() => void 0); // @todo How to process unhandled rejection here?
306
+ }).catch((e) => {
307
+ Client_1._logger.error(e);
308
+ });
295
309
  if (startTwilsock) {
296
310
  this._services.twilsockClient.connect();
297
311
  }
@@ -311,46 +325,11 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
311
325
  get reachabilityEnabled() {
312
326
  if (!this._configuration) {
313
327
  throw new Error("Reachability information could not yet be accessed as the client " +
314
- "has not yet been initialized. Subscribe to the 'stateChanged' event " +
315
- "to properly react to the client initialization.");
328
+ "has not yet been initialized. Subscribe to 'initialized' and " +
329
+ "'initFailed' events to properly react to the client initialization.");
316
330
  }
317
331
  return this._configuration.reachabilityEnabled;
318
332
  }
319
- /**
320
- * @deprecated Call constructor directly.
321
- *
322
- * Factory method to create a Conversations client instance.
323
- *
324
- * The factory method will automatically trigger connection.
325
- * Do not use it if you need finer-grained control.
326
- *
327
- * Since this method returns an already-initialized client, some of the events
328
- * will be lost because they happen *before* the initialization. It is
329
- * recommended that `client.onWithReplay` is used as opposed to `client.on`
330
- * for subscribing to client events. The `client.onWithReplay` will re-emit
331
- * the most recent value for a given event if it emitted before the
332
- * subscription.
333
- *
334
- * @param token Access token.
335
- * @param options Options to customize the client.
336
- * @returns Returns a fully initialized client.
337
- */
338
- static async create(token, options) {
339
- // The logic is as follows:
340
- // - If twilsock is not passed in, then the ConversationsClient constructor will call twilsock.connect() by itself
341
- // and we do not need to do it here.
342
- // - If twilsock was passed in from the outside, but customer called ConversationsClient.create() then they are
343
- // using an obsolete workflow and the startup sequence will never complete.
344
- if (options === null || options === void 0 ? void 0 : options.twilsockClient) {
345
- throw new Error("Obsolete usage of ConversationsClient.create() " +
346
- "factory method: if you pass twilsock from the outside then you must " +
347
- "use ConversationsClient constructor and be prepared to work with " +
348
- "uninitialized client.");
349
- }
350
- const client = new Client_1(token, options);
351
- await client._ensureReady;
352
- return client;
353
- }
354
333
  /**
355
334
  * Static method for push notification payload parsing. Returns parsed push as
356
335
  * a {@link PushNotification} object.
@@ -437,20 +416,13 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
437
416
  }
438
417
  return result;
439
418
  }
440
- /**
441
- * Populate the client with init registrations.
442
- * @param reg The init registration to populate.
443
- */
444
- static populateInitRegistrations(reg) {
445
- reg.populateInitRegistrations([notificationTypes.NotificationTypes.TYPING_INDICATOR]);
446
- twilioSync.SyncClient.populateInitRegistrations(reg);
447
- }
448
419
  /**
449
420
  * Gracefully shut down the client.
450
421
  */
451
422
  async shutdown() {
423
+ var _a;
452
424
  await this._ensureReady;
453
- await this._services.twilsockClient.disconnect();
425
+ await ((_a = this._services.network) === null || _a === void 0 ? void 0 : _a.disconnect());
454
426
  }
455
427
  /**
456
428
  * Update the token used by the client and re-register with the Conversations services.
@@ -512,7 +484,8 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
512
484
  */
513
485
  async getSubscribedConversations() {
514
486
  await this._ensureReady;
515
- return this._conversationsPromise.then((conversations) => conversations.getConversations());
487
+ const conversations = await this._conversationsPromise;
488
+ return await conversations.getConversations();
516
489
  }
517
490
  /**
518
491
  * Create a conversation on the server and subscribe to its events.
@@ -536,16 +509,6 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
536
509
  this._services.notificationClient.setPushRegistrationId(channelType, registrationId);
537
510
  await this._services.notificationClient.commitChanges(); // Committing before this point is useless because we have no push id
538
511
  }
539
- /**
540
- * Unregister from push notifications.
541
- * @param channelType Channel type.
542
- * @deprecated Use removePushRegistrations() instead.
543
- */
544
- async unsetPushRegistrationId(channelType) {
545
- await this._ensureReady;
546
- this._unsubscribeFromPushNotifications(channelType);
547
- await this._services.notificationClient.commitChanges();
548
- }
549
512
  /**
550
513
  * Clear existing registrations directly using provided device token.
551
514
  * This is useful to ensure stopped subscriptions without resubscribing.
@@ -627,12 +590,21 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
627
590
  const sids = contentSet.map((m) => m.sid);
628
591
  return this.getTemporaryContentUrlsForMediaSids(sids);
629
592
  }
593
+ /**
594
+ * Returns rich content templates belonging to the account. Rich content
595
+ * templates can be created via the Twilio console or the REST API.
596
+ */
597
+ async getContentTemplates() {
598
+ await this._ensureReady;
599
+ return await this._services.contentClient.getContentTemplates();
600
+ }
630
601
  /**
631
602
  * Initialize the client.
632
603
  */
633
604
  async _initialize() {
634
605
  const configurationResponse = await this._services.commandExecutor.fetchResource("Client/v2/Configuration");
635
606
  this._configuration = new configuration.Configuration(this._options, configurationResponse, Client_1._logger);
607
+ this._services.channelMetadataClient = new channelMetadataClient.ChannelMetadataClient(this._services, this._configuration);
636
608
  this._myself._resolveInitialization(this._configuration, this._configuration.userIdentity, this._configuration.userInfo, true);
637
609
  this._services.typingIndicator = new typingIndicator.TypingIndicator(this.getConversationBySid.bind(this), this._configuration, this._services);
638
610
  this._services.network = new network.Network(this._configuration, this._services);
@@ -674,6 +646,9 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
674
646
  .fetchConversations()
675
647
  .then(() => this._conversationsEntity)
676
648
  .catch((error) => {
649
+ if (error.message === "Client has been shut down.") {
650
+ return this._conversationsEntity;
651
+ }
677
652
  throw error;
678
653
  });
679
654
  await this._services.users.myself._ensureFetched();
@@ -681,7 +656,7 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
681
656
  this._services.typingIndicator.initialize();
682
657
  this._services.mcsClient = new mcsClient.McsClient(this._fpaToken, this._configuration.links.mediaService, this._configuration.links.mediaSetService, Object.assign(Object.assign({}, this._options), { transport: undefined }));
683
658
  this._resolveEnsureReady();
684
- this.emit("stateChanged", { state: "initialized" });
659
+ this.emit("initialized");
685
660
  }
686
661
  /**
687
662
  * Subscribe to push notifications.
@@ -698,21 +673,6 @@ exports.Client = Client_1 = class Client extends replayEventEmitter.ReplayEventE
698
673
  this._services.notificationClient.subscribe(channelType, messageType);
699
674
  });
700
675
  }
701
- /**
702
- * Unsubscribe from push notifications.
703
- * @param channelType The channel type to unsubscribe from.
704
- */
705
- _unsubscribeFromPushNotifications(channelType) {
706
- [
707
- notificationTypes.NotificationTypes.NEW_MESSAGE,
708
- notificationTypes.NotificationTypes.ADDED_TO_CONVERSATION,
709
- notificationTypes.NotificationTypes.REMOVED_FROM_CONVERSATION,
710
- notificationTypes.NotificationTypes.TYPING_INDICATOR,
711
- notificationTypes.NotificationTypes.CONSUMPTION_UPDATE,
712
- ].forEach((messageType) => {
713
- this._services.notificationClient.unsubscribe(channelType, messageType);
714
- });
715
- }
716
676
  };
717
677
  /**
718
678
  * Fired when a conversation becomes visible to the client. The event is also
@@ -885,16 +845,20 @@ exports.Client.userUnsubscribed = "userUnsubscribed";
885
845
  */
886
846
  exports.Client.userUpdated = "userUpdated";
887
847
  /**
888
- * Fired when the state of the client has been changed.
848
+ * Fired when the client has completed initialization successfully.
849
+ * @event
850
+ */
851
+ exports.Client.initialized = "initialized";
852
+ /**
853
+ * Fired when the client initialization failed.
889
854
  *
890
855
  * Parameters:
891
856
  * 1. object `data` - info object provided with the event. It has the
892
- * following properties:
893
- * * {@link State} `state` - the new client state
857
+ * following property:
894
858
  * * Error? `error` - the initialization error if present
895
859
  * @event
896
860
  */
897
- exports.Client.stateChanged = "stateChanged";
861
+ exports.Client.initFailed = "initFailed";
898
862
  /**
899
863
  * Fired when the connection state of the client has been changed.
900
864
  *
@@ -985,12 +949,6 @@ tslib_es6.__decorate([
985
949
  tslib_es6.__metadata("design:paramtypes", [String, String]),
986
950
  tslib_es6.__metadata("design:returntype", Promise)
987
951
  ], exports.Client.prototype, "setPushRegistrationId", null);
988
- tslib_es6.__decorate([
989
- declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.literal("fcm", "apn")),
990
- tslib_es6.__metadata("design:type", Function),
991
- tslib_es6.__metadata("design:paramtypes", [String]),
992
- tslib_es6.__metadata("design:returntype", Promise)
993
- ], exports.Client.prototype, "unsetPushRegistrationId", null);
994
952
  tslib_es6.__decorate([
995
953
  declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.literal("fcm", "apn"), declarativeTypeValidator.nonEmptyString),
996
954
  tslib_es6.__metadata("design:type", Function),
@@ -1021,12 +979,6 @@ tslib_es6.__decorate([
1021
979
  tslib_es6.__metadata("design:paramtypes", [Array]),
1022
980
  tslib_es6.__metadata("design:returntype", mcsClient.CancellablePromise)
1023
981
  ], exports.Client.prototype, "getTemporaryContentUrlsForMedia", null);
1024
- tslib_es6.__decorate([
1025
- declarativeTypeValidator.validateTypesAsync("string", ["undefined", declarativeTypeValidator.pureObject]),
1026
- tslib_es6.__metadata("design:type", Function),
1027
- tslib_es6.__metadata("design:paramtypes", [String, Object]),
1028
- tslib_es6.__metadata("design:returntype", Promise)
1029
- ], exports.Client, "create", null);
1030
982
  tslib_es6.__decorate([
1031
983
  declarativeTypeValidator.validateTypes(declarativeTypeValidator.pureObject),
1032
984
  tslib_es6.__metadata("design:type", Function),