@twilio/conversations 1.3.0-rc7 → 2.0.0-rc.3

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 (282) hide show
  1. package/CHANGELOG.md +201 -0
  2. package/README.md +5 -5
  3. package/dist/browser.js +7866 -0
  4. package/dist/browser.js.map +1 -0
  5. package/dist/docs/assets/css/main.css +2660 -0
  6. package/dist/docs/assets/images/icons.png +0 -0
  7. package/dist/docs/assets/images/icons@2x.png +0 -0
  8. package/dist/docs/assets/images/widgets.png +0 -0
  9. package/dist/docs/assets/images/widgets@2x.png +0 -0
  10. package/dist/docs/assets/js/main.js +248 -0
  11. package/dist/docs/assets/js/search.js +1 -0
  12. package/dist/docs/classes/AggregatedDeliveryReceipt.html +3286 -0
  13. package/dist/docs/classes/Client.html +4181 -0
  14. package/dist/docs/classes/Conversation.html +4397 -0
  15. package/dist/docs/classes/DetailedDeliveryReceipt.html +3265 -0
  16. package/dist/docs/classes/Media.html +3295 -0
  17. package/dist/docs/classes/Message.html +3713 -0
  18. package/dist/docs/classes/MessageBuilder.html +3280 -0
  19. package/dist/docs/classes/Participant.html +3517 -0
  20. package/dist/docs/classes/PushNotification.html +3232 -0
  21. package/dist/docs/classes/RestPaginator.html +3262 -0
  22. package/dist/docs/classes/UnsentMessage.html +3144 -0
  23. package/dist/docs/classes/User.html +3451 -0
  24. package/dist/docs/index.html +3387 -212
  25. package/dist/docs/interfaces/ClientOptions.html +3136 -0
  26. package/dist/docs/interfaces/ConversationState.html +3152 -0
  27. package/dist/docs/interfaces/CreateConversationOptions.html +3168 -0
  28. package/dist/docs/interfaces/LastMessage.html +3152 -0
  29. package/dist/docs/interfaces/Paginator.html +3243 -0
  30. package/dist/docs/interfaces/PushNotificationData.html +3168 -0
  31. package/dist/docs/interfaces/SendEmailOptions.html +3136 -0
  32. package/dist/docs/interfaces/SendMediaOptions.html +3169 -0
  33. package/dist/docs/modules.html +3418 -0
  34. package/dist/lib.d.ts +1944 -0
  35. package/dist/lib.js +7866 -0
  36. package/dist/lib.js.map +1 -0
  37. package/dist/post-install.js +29 -0
  38. package/dist/react-native.js +4031 -0
  39. package/dist/react-native.js.map +1 -0
  40. package/dist/twilio-conversations.js +40905 -0
  41. package/dist/twilio-conversations.min.js +156 -0
  42. package/package.json +59 -48
  43. package/.circleci/config.yml +0 -650
  44. package/.deepsource.toml +0 -6
  45. package/.env.example +0 -13
  46. package/browser/aggregateddeliveryreceipt.js +0 -152
  47. package/browser/client.js +0 -991
  48. package/browser/configuration.js +0 -80
  49. package/browser/conversation.js +0 -1826
  50. package/browser/data/conversations.js +0 -665
  51. package/browser/data/messages.js +0 -522
  52. package/browser/data/participants.js +0 -411
  53. package/browser/data/users.js +0 -281
  54. package/browser/detaileddeliveryreceipt.js +0 -44
  55. package/browser/index.js +0 -4
  56. package/browser/interfaces/limits.js +0 -3
  57. package/browser/interfaces/notificationtypes.js +0 -21
  58. package/browser/interfaces/paginator.js +0 -53
  59. package/browser/interfaces/responsecodes.js +0 -20
  60. package/browser/interfaces/transport.js +0 -3
  61. package/browser/logger.js +0 -141
  62. package/browser/media.js +0 -198
  63. package/browser/message.js +0 -685
  64. package/browser/participant.js +0 -415
  65. package/browser/pushnotification.js +0 -49
  66. package/browser/restpaginator.js +0 -74
  67. package/browser/services/network.js +0 -223
  68. package/browser/services/readhorizon.js +0 -181
  69. package/browser/services/typingindicator.js +0 -142
  70. package/browser/session.js +0 -505
  71. package/browser/sessionerror.js +0 -93
  72. package/browser/sri.json +0 -1
  73. package/browser/synclist.js +0 -90
  74. package/browser/synclistdescriptor.js +0 -29
  75. package/browser/syncpaginator.js +0 -63
  76. package/browser/user.js +0 -431
  77. package/browser/util/deferred.js +0 -56
  78. package/browser/util/index.js +0 -108
  79. package/dist/@twilio/conversations.js +0 -35565
  80. package/dist/@twilio/conversations.min.js +0 -204
  81. package/dist/docs/AggregatedDeliveryReceipt.html +0 -948
  82. package/dist/docs/Client.html +0 -5075
  83. package/dist/docs/Conversation.html +0 -6018
  84. package/dist/docs/DetailedDeliveryReceipt.html +0 -641
  85. package/dist/docs/Media.html +0 -694
  86. package/dist/docs/Message.html +0 -1934
  87. package/dist/docs/Paginator.html +0 -605
  88. package/dist/docs/Participant.html +0 -1510
  89. package/dist/docs/PushNotification.html +0 -836
  90. package/dist/docs/SessionError.html +0 -379
  91. package/dist/docs/User.html +0 -1315
  92. package/dist/docs/classes.list.html +0 -4431
  93. package/dist/docs/fonts/glyphicons-halflings-regular.eot +0 -0
  94. package/dist/docs/fonts/glyphicons-halflings-regular.svg +0 -288
  95. package/dist/docs/fonts/glyphicons-halflings-regular.ttf +0 -0
  96. package/dist/docs/fonts/glyphicons-halflings-regular.woff +0 -0
  97. package/dist/docs/fonts/glyphicons-halflings-regular.woff2 +0 -0
  98. package/dist/docs/img/glyphicons-halflings-white.png +0 -0
  99. package/dist/docs/img/glyphicons-halflings.png +0 -0
  100. package/dist/docs/quicksearch.html +0 -31
  101. package/dist/docs/scripts/docstrap.lib.js +0 -11
  102. package/dist/docs/scripts/fulltext-search-ui.js +0 -89
  103. package/dist/docs/scripts/fulltext-search.js +0 -36
  104. package/dist/docs/scripts/lunr.min.js +0 -6
  105. package/dist/docs/scripts/prettify/Apache-License-2.0.txt +0 -202
  106. package/dist/docs/scripts/prettify/jquery.min.js +0 -6
  107. package/dist/docs/scripts/prettify/lang-css.js +0 -21
  108. package/dist/docs/scripts/prettify/prettify.js +0 -496
  109. package/dist/docs/scripts/sunlight.js +0 -1157
  110. package/dist/docs/scripts/toc.js +0 -203
  111. package/dist/docs/styles/darkstrap.css +0 -960
  112. package/dist/docs/styles/prettify-tomorrow.css +0 -132
  113. package/dist/docs/styles/site.cerulean.css +0 -7008
  114. package/dist/docs/styles/site.cosmo.css +0 -7061
  115. package/dist/docs/styles/site.cyborg.css +0 -7048
  116. package/dist/docs/styles/site.darkly.css +0 -7171
  117. package/dist/docs/styles/site.darkstrap.css +0 -5638
  118. package/dist/docs/styles/site.dibs-bootstrap.css +0 -5899
  119. package/dist/docs/styles/site.flatly.css +0 -7147
  120. package/dist/docs/styles/site.journal.css +0 -6973
  121. package/dist/docs/styles/site.lumen.css +0 -7298
  122. package/dist/docs/styles/site.paper.css +0 -7623
  123. package/dist/docs/styles/site.readable.css +0 -6997
  124. package/dist/docs/styles/site.sandstone.css +0 -7035
  125. package/dist/docs/styles/site.simplex.css +0 -7023
  126. package/dist/docs/styles/site.slate.css +0 -7343
  127. package/dist/docs/styles/site.spacelab.css +0 -7055
  128. package/dist/docs/styles/site.superhero.css +0 -7131
  129. package/dist/docs/styles/site.united.css +0 -6895
  130. package/dist/docs/styles/site.yeti.css +0 -7195
  131. package/dist/docs/styles/sunlight.dark.css +0 -345
  132. package/dist/docs/styles/sunlight.default.css +0 -344
  133. package/dist/sri.json +0 -1
  134. package/lib/aggregateddeliveryreceipt.d.ts +0 -98
  135. package/lib/aggregateddeliveryreceipt.js +0 -112
  136. package/lib/client.d.ts +0 -317
  137. package/lib/client.js +0 -633
  138. package/lib/configuration.d.ts +0 -21
  139. package/lib/configuration.js +0 -41
  140. package/lib/conversation.d.ts +0 -460
  141. package/lib/conversation.js +0 -940
  142. package/lib/data/conversations.d.ts +0 -57
  143. package/lib/data/conversations.js +0 -318
  144. package/lib/data/messages.d.ts +0 -75
  145. package/lib/data/messages.js +0 -208
  146. package/lib/data/participants.d.ts +0 -94
  147. package/lib/data/participants.js +0 -204
  148. package/lib/data/users.d.ts +0 -42
  149. package/lib/data/users.js +0 -113
  150. package/lib/detaileddeliveryreceipt.d.ts +0 -45
  151. package/lib/detaileddeliveryreceipt.js +0 -34
  152. package/lib/index.d.ts +0 -1
  153. package/lib/index.js +0 -3
  154. package/lib/interfaces/limits.d.ts +0 -8
  155. package/lib/interfaces/limits.js +0 -2
  156. package/lib/interfaces/notificationtypes.d.ts +0 -8
  157. package/lib/interfaces/notificationtypes.js +0 -11
  158. package/lib/interfaces/paginator.d.ts +0 -52
  159. package/lib/interfaces/paginator.js +0 -28
  160. package/lib/interfaces/responsecodes.d.ts +0 -8
  161. package/lib/interfaces/responsecodes.js +0 -10
  162. package/lib/interfaces/transport.d.ts +0 -13
  163. package/lib/interfaces/transport.js +0 -2
  164. package/lib/logger.d.ts +0 -18
  165. package/lib/logger.js +0 -35
  166. package/lib/media.d.ts +0 -52
  167. package/lib/media.js +0 -69
  168. package/lib/message.d.ts +0 -136
  169. package/lib/message.js +0 -305
  170. package/lib/participant.d.ts +0 -142
  171. package/lib/participant.js +0 -219
  172. package/lib/pushnotification.d.ts +0 -48
  173. package/lib/pushnotification.js +0 -39
  174. package/lib/restpaginator.d.ts +0 -19
  175. package/lib/restpaginator.js +0 -36
  176. package/lib/services/network.d.ts +0 -22
  177. package/lib/services/network.js +0 -87
  178. package/lib/services/readhorizon.d.ts +0 -28
  179. package/lib/services/readhorizon.js +0 -112
  180. package/lib/services/typingindicator.d.ts +0 -50
  181. package/lib/services/typingindicator.js +0 -102
  182. package/lib/session.d.ts +0 -63
  183. package/lib/session.js +0 -213
  184. package/lib/sessionerror.d.ts +0 -12
  185. package/lib/sessionerror.js +0 -24
  186. package/lib/sri.json +0 -1
  187. package/lib/synclist.d.ts +0 -24
  188. package/lib/synclist.js +0 -28
  189. package/lib/synclistdescriptor.d.ts +0 -27
  190. package/lib/synclistdescriptor.js +0 -19
  191. package/lib/syncpaginator.d.ts +0 -22
  192. package/lib/syncpaginator.js +0 -37
  193. package/lib/user.d.ts +0 -98
  194. package/lib/user.js +0 -219
  195. package/lib/util/deferred.d.ts +0 -12
  196. package/lib/util/deferred.js +0 -22
  197. package/lib/util/index.d.ts +0 -28
  198. package/lib/util/index.js +0 -82
  199. package/tools/rtd-sdk-cdn-pin/.gitrepo +0 -12
  200. package/tools/rtd-sdk-cdn-pin/README.md +0 -54
  201. package/tools/rtd-sdk-cdn-pin/bintray-settings.xml.template +0 -16
  202. package/tools/rtd-sdk-cdn-pin/cdn-common/cdn-prepare.sh +0 -67
  203. package/tools/rtd-sdk-cdn-pin/cdn-pin-latest.sh +0 -19
  204. package/tools/rtd-sdk-cdn-pin/cdn-pin.sh +0 -19
  205. package/tools/rtd-sdk-cdn-pin/cdn-upload.sh +0 -13
  206. package/tools/rtd-sdk-cdn-pin/fetch/common/fetch-bintray-android.sh +0 -34
  207. package/tools/rtd-sdk-cdn-pin/fetch/common/fetch-npm.sh +0 -18
  208. package/tools/rtd-sdk-cdn-pin/fetch/twilio-chat-android.sh +0 -5
  209. package/tools/rtd-sdk-cdn-pin/fetch/twilio-chat-js.sh +0 -5
  210. package/tools/rtd-sdk-cdn-pin/fetch/twilio-conversations-android.sh +0 -6
  211. package/tools/rtd-sdk-cdn-pin/fetch/twilio-conversations-js.sh +0 -5
  212. package/tools/rtd-sdk-cdn-pin/fetch/twilio-sync-android.sh +0 -5
  213. package/tools/rtd-sdk-cdn-pin/fetch/twilio-sync-js.sh +0 -5
  214. package/tools/rtd-sdk-cdn-pin/fetch-artifact.sh +0 -26
  215. package/tools/sdk-release-tool/.gitrepo +0 -12
  216. package/tools/sdk-release-tool/Makefile +0 -49
  217. package/tools/sdk-release-tool/README.md +0 -275
  218. package/tools/sdk-release-tool/delete +0 -3
  219. package/tools/sdk-release-tool/download +0 -3
  220. package/tools/sdk-release-tool/get-cors +0 -3
  221. package/tools/sdk-release-tool/list +0 -3
  222. package/tools/sdk-release-tool/pin +0 -3
  223. package/tools/sdk-release-tool/pin-latest +0 -3
  224. package/tools/sdk-release-tool/requirements.txt +0 -4
  225. package/tools/sdk-release-tool/sdk-release-tool +0 -3
  226. package/tools/sdk-release-tool/sdk_release_tools/__init__.py +0 -0
  227. package/tools/sdk-release-tool/sdk_release_tools/__main__.py +0 -110
  228. package/tools/sdk-release-tool/sdk_release_tools/aws.py +0 -70
  229. package/tools/sdk-release-tool/sdk_release_tools/cli.py +0 -181
  230. package/tools/sdk-release-tool/sdk_release_tools/log.py +0 -24
  231. package/tools/sdk-release-tool/sdk_release_tools/ops.py +0 -295
  232. package/tools/sdk-release-tool/sdk_release_tools/rpm.py +0 -28
  233. package/tools/sdk-release-tool/sdk_release_tools/util.py +0 -186
  234. package/tools/sdk-release-tool/sdk_release_tools/versions.py +0 -362
  235. package/tools/sdk-release-tool/signal-sdk-js.json +0 -28
  236. package/tools/sdk-release-tool/tests/test_versions.py +0 -94
  237. package/tools/sdk-release-tool/twilio-accessmanager-android.json +0 -19
  238. package/tools/sdk-release-tool/twilio-accessmanager-ios.json +0 -26
  239. package/tools/sdk-release-tool/twilio-auth-ios.json +0 -29
  240. package/tools/sdk-release-tool/twilio-authenticator-ios.json +0 -29
  241. package/tools/sdk-release-tool/twilio-chat-android-2.json +0 -19
  242. package/tools/sdk-release-tool/twilio-chat-android.json +0 -22
  243. package/tools/sdk-release-tool/twilio-chat-ios.json +0 -26
  244. package/tools/sdk-release-tool/twilio-chat-js.json +0 -27
  245. package/tools/sdk-release-tool/twilio-client-android-aar.json +0 -22
  246. package/tools/sdk-release-tool/twilio-client-android.json +0 -22
  247. package/tools/sdk-release-tool/twilio-client-ios.json +0 -20
  248. package/tools/sdk-release-tool/twilio-client-js.json +0 -17
  249. package/tools/sdk-release-tool/twilio-client-sounds-js.json +0 -14
  250. package/tools/sdk-release-tool/twilio-common-android-maven.json +0 -16
  251. package/tools/sdk-release-tool/twilio-common-android.json +0 -22
  252. package/tools/sdk-release-tool/twilio-common-ios-rtc.json +0 -25
  253. package/tools/sdk-release-tool/twilio-common-ios.json +0 -25
  254. package/tools/sdk-release-tool/twilio-common-js.json +0 -19
  255. package/tools/sdk-release-tool/twilio-conversations-android.json +0 -22
  256. package/tools/sdk-release-tool/twilio-conversations-ios.json +0 -26
  257. package/tools/sdk-release-tool/twilio-conversations-js.json +0 -27
  258. package/tools/sdk-release-tool/twilio-flex-js.json +0 -20
  259. package/tools/sdk-release-tool/twilio-flex-webchat-js.json +0 -16
  260. package/tools/sdk-release-tool/twilio-frame-chat-android.json +0 -22
  261. package/tools/sdk-release-tool/twilio-frame-chat-ios.json +0 -23
  262. package/tools/sdk-release-tool/twilio-frame-chat-js.json +0 -23
  263. package/tools/sdk-release-tool/twilio-ip-messaging-android-maven.json +0 -16
  264. package/tools/sdk-release-tool/twilio-ip-messaging-android.json +0 -22
  265. package/tools/sdk-release-tool/twilio-ip-messaging-ios.json +0 -25
  266. package/tools/sdk-release-tool/twilio-ip-messaging-js.json +0 -21
  267. package/tools/sdk-release-tool/twilio-sync-android.json +0 -22
  268. package/tools/sdk-release-tool/twilio-sync-ios.json +0 -26
  269. package/tools/sdk-release-tool/twilio-sync-js.json +0 -39
  270. package/tools/sdk-release-tool/twilio-taskrouter-js.json +0 -17
  271. package/tools/sdk-release-tool/twilio-video-android.json +0 -22
  272. package/tools/sdk-release-tool/twilio-video-cpp-linux-cross-rootfs.json +0 -13
  273. package/tools/sdk-release-tool/twilio-video-cpp.json +0 -33
  274. package/tools/sdk-release-tool/twilio-video-ios.json +0 -25
  275. package/tools/sdk-release-tool/twilio-video-js.json +0 -19
  276. package/tools/sdk-release-tool/twilio-video-jsdocs.json +0 -14
  277. package/tools/sdk-release-tool/twilio-voice-android.json +0 -22
  278. package/tools/sdk-release-tool/twilio-voice-ios.json +0 -29
  279. package/tools/sdk-release-tool/unpin +0 -3
  280. package/tools/sdk-release-tool/unpin-latest +0 -3
  281. package/tools/sdk-release-tool/upload +0 -3
  282. package/twilio-chat.js.iml +0 -9
package/lib/client.js DELETED
@@ -1,633 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const events_1 = require("events");
13
- const logger_1 = require("./logger");
14
- const configuration_1 = require("./configuration");
15
- const user_1 = require("./user");
16
- exports.User = user_1.User;
17
- const network_1 = require("./services/network");
18
- const notificationtypes_1 = require("./interfaces/notificationtypes");
19
- const synclist_1 = require("./synclist");
20
- const twilsock_1 = require("twilsock");
21
- const twilio_notifications_1 = require("twilio-notifications");
22
- const twilio_sync_1 = require("twilio-sync");
23
- const twilio_mcs_client_1 = require("twilio-mcs-client");
24
- const session_1 = require("./session");
25
- const conversations_1 = require("./data/conversations");
26
- const users_1 = require("./data/users");
27
- const typingindicator_1 = require("./services/typingindicator");
28
- const readhorizon_1 = require("./services/readhorizon");
29
- const pushnotification_1 = require("./pushnotification");
30
- exports.PushNotification = pushnotification_1.PushNotification;
31
- const util_1 = require("./util");
32
- const telemetrytracker_1 = require("twilsock/lib/services/telemetrytracker");
33
- const twilio_sdk_type_validator_1 = require("twilio-sdk-type-validator");
34
- const log = logger_1.Logger.scope('Client');
35
- const SDK_VERSION = require('./../package.json').version;
36
- class ClientServices {
37
- }
38
- /**
39
- * A Client is a starting point to access Twilio Conversations functionality.
40
- *
41
- * @property {Client#ConnectionState} connectionState - Client connection state
42
- * @property {Boolean} reachabilityEnabled - Client reachability state
43
- * @property {User} user - Information for logged in user
44
- * @property {String} version - Current version of Conversations client
45
- *
46
- * @fires Client#connectionError
47
- * @fires Client#connectionStateChanged
48
- * @fires Client#conversationAdded
49
- * @fires Client#conversationJoined
50
- * @fires Client#conversationLeft
51
- * @fires Client#conversationRemoved
52
- * @fires Client#conversationUpdated
53
- * @fires Client#participantJoined
54
- * @fires Client#participantLeft
55
- * @fires Client#participantUpdated
56
- * @fires Client#messageAdded
57
- * @fires Client#messageRemoved
58
- * @fires Client#messageUpdated
59
- * @fires Client#pushNotification
60
- * @fires Client#tokenAboutToExpire
61
- * @fires Client#tokenExpired
62
- * @fires Client#typingEnded
63
- * @fires Client#typingStarted
64
- * @fires Client#userSubscribed
65
- * @fires Client#userUnsubscribed
66
- * @fires Client#userUpdated
67
- */
68
- class Client extends events_1.EventEmitter {
69
- /**
70
- * These options can be passed to Client constructor.
71
- * @typedef {Object} Client#ClientOptions
72
- * @property {String} [logLevel='error'] - The level of logging to enable. Valid options
73
- * (from strictest to broadest): ['silent', 'error', 'warn', 'info', 'debug', 'trace']
74
- */
75
- /**
76
- * These options can be passed to {@link Client#createConversation}.
77
- * @typedef {Object} Client#CreateConversationOptions
78
- * @property {any} [attributes] - Any custom attributes to attach to the Conversation
79
- * @property {String} [friendlyName] - The non-unique display name of the Conversation
80
- * @property {String} [uniqueName] - The unique identifier of the Conversation
81
- */
82
- /**
83
- * Connection state of Client.
84
- * @typedef {('connecting'|'connected'|'disconnecting'|'disconnected'|'denied')} Client#ConnectionState
85
- */
86
- /**
87
- * Notifications channel type.
88
- * @typedef {('fcm'|'apn')} Client#NotificationsChannelType
89
- */
90
- constructor(token, options) {
91
- super();
92
- this.connectionState = 'connecting';
93
- this.sessionPromise = null;
94
- this.conversationsPromise = null;
95
- this.version = SDK_VERSION;
96
- this.parsePushNotification = Client.parsePushNotification;
97
- this.options = (options || {});
98
- if (!this.options.disableDeepClone) {
99
- let options = Object.assign(Object.assign({}, this.options), { transport: undefined, twilsockClient: undefined });
100
- options = util_1.deepClone(options);
101
- options.transport = this.options.transport;
102
- options.twilsockClient = this.options.twilsockClient;
103
- this.options = options;
104
- }
105
- this.options.logLevel = this.options.logLevel || 'silent';
106
- log.setLevel(this.options.logLevel);
107
- const productId = this.options.productId = 'ip_messaging';
108
- // Filling ClientMetadata
109
- this.options.clientMetadata = this.options.clientMetadata || {};
110
- if (!this.options.clientMetadata.hasOwnProperty('type')) {
111
- this.options.clientMetadata.type = 'conversations';
112
- }
113
- if (!this.options.clientMetadata.hasOwnProperty('sdk')) {
114
- this.options.clientMetadata.sdk = 'JS';
115
- this.options.clientMetadata.sdkv = SDK_VERSION;
116
- }
117
- // Enable session local storage for Sync
118
- this.options.Sync = this.options.Sync || {};
119
- if (typeof this.options.Sync.enableSessionStorage === 'undefined') {
120
- this.options.Sync.enableSessionStorage = true;
121
- }
122
- if (this.options.region) {
123
- this.options.Sync.region = this.options.region;
124
- }
125
- if (!token) {
126
- throw new Error('A valid Twilio token should be provided');
127
- }
128
- this.services = new ClientServices();
129
- this.config = new configuration_1.Configuration(this.options);
130
- this.options.twilsockClient = this.options.twilsockClient || new twilsock_1.Twilsock(token, productId, this.options);
131
- this.options.transport = this.options.transport || this.options.twilsockClient;
132
- this.options.notificationsClient = this.options.notificationsClient || new twilio_notifications_1.Notifications(token, this.options);
133
- this.options.syncClient = this.options.syncClient || new twilio_sync_1.SyncClient(token, this.options);
134
- this.services.syncClient = this.options.syncClient;
135
- this.services.transport = this.options.transport;
136
- this.services.twilsockClient = this.options.twilsockClient;
137
- this.services.notificationClient = this.options.notificationsClient;
138
- this.services.session = new session_1.Session(this.services, this.config);
139
- this.sessionPromise = this.services.session.initialize();
140
- this.services.network = new network_1.Network(this.config, this.services);
141
- this.services.users = new users_1.Users({
142
- session: this.services.session,
143
- network: this.services.network,
144
- syncClient: this.services.syncClient
145
- });
146
- this.services.users.on('userSubscribed', this.emit.bind(this, 'userSubscribed'));
147
- this.services.users.on('userUpdated', (args) => this.emit('userUpdated', args));
148
- this.services.users.on('userUnsubscribed', this.emit.bind(this, 'userUnsubscribed'));
149
- this.services.twilsockClient.on('tokenAboutToExpire', ttl => this.emit('tokenAboutToExpire', ttl));
150
- this.services.twilsockClient.on('tokenExpired', () => this.emit('tokenExpired'));
151
- this.services.twilsockClient.on('connectionError', (error) => this.emit('connectionError', error));
152
- this.services.readHorizon = new readhorizon_1.ReadHorizon(this.services);
153
- this.services.typingIndicator = new typingindicator_1.TypingIndicator(this.config, {
154
- transport: this.services.twilsockClient,
155
- notificationClient: this.services.notificationClient
156
- }, this.getConversationBySid.bind(this));
157
- this.services.syncList = new synclist_1.SyncList(this.services);
158
- this.conversations = new conversations_1.Conversations(this.services);
159
- this.conversationsPromise = this.sessionPromise.then(() => {
160
- this.conversations.on('conversationAdded', this.emit.bind(this, 'conversationAdded'));
161
- this.conversations.on('conversationRemoved', this.emit.bind(this, 'conversationRemoved'));
162
- this.conversations.on('conversationJoined', this.emit.bind(this, 'conversationJoined'));
163
- this.conversations.on('conversationLeft', this.emit.bind(this, 'conversationLeft'));
164
- this.conversations.on('conversationUpdated', (args) => this.emit('conversationUpdated', args));
165
- this.conversations.on('participantJoined', this.emit.bind(this, 'participantJoined'));
166
- this.conversations.on('participantLeft', this.emit.bind(this, 'participantLeft'));
167
- this.conversations.on('participantUpdated', (args) => this.emit('participantUpdated', args));
168
- this.conversations.on('messageAdded', this.emit.bind(this, 'messageAdded'));
169
- this.conversations.on('messageUpdated', (args) => this.emit('messageUpdated', args));
170
- this.conversations.on('messageRemoved', this.emit.bind(this, 'messageRemoved'));
171
- this.conversations.on('typingStarted', this.emit.bind(this, 'typingStarted'));
172
- this.conversations.on('typingEnded', this.emit.bind(this, 'typingEnded'));
173
- return this.conversations.fetchConversations();
174
- }).then(() => this.conversations);
175
- this.services.notificationClient.on('connectionStateChanged', (state) => {
176
- let changedConnectionState = null;
177
- switch (state) {
178
- case 'connected':
179
- changedConnectionState = 'connected';
180
- break;
181
- case 'denied':
182
- changedConnectionState = 'denied';
183
- break;
184
- case 'disconnecting':
185
- changedConnectionState = 'disconnecting';
186
- break;
187
- case 'disconnected':
188
- changedConnectionState = 'disconnected';
189
- break;
190
- default:
191
- changedConnectionState = 'connecting';
192
- }
193
- if (changedConnectionState !== this.connectionState) {
194
- this.connectionState = changedConnectionState;
195
- this.emit('connectionStateChanged', this.connectionState);
196
- }
197
- });
198
- this.fpaToken = token;
199
- }
200
- /**
201
- * Factory method to create Conversations client instance.
202
- *
203
- * @param {String} token - Access token
204
- * @param {Client#ClientOptions} [options] - Options to customize the Client
205
- * @returns {Promise<Client>}
206
- */
207
- static async create(token, options) {
208
- let client = new Client(token, options);
209
- const startupEvent = 'conversations.client.startup';
210
- client.services.twilsockClient.addPartialTelemetryEvent(new telemetrytracker_1.TelemetryEventDescription(startupEvent, 'Conversations client startup', new Date()), startupEvent, telemetrytracker_1.TelemetryPoint.Start);
211
- await client.initialize();
212
- client.services.twilsockClient.addPartialTelemetryEvent(new telemetrytracker_1.TelemetryEventDescription('', '', new Date()), startupEvent, telemetrytracker_1.TelemetryPoint.End);
213
- return client;
214
- }
215
- get user() { return this.services.users.myself; }
216
- get reachabilityEnabled() { return this.services.session.reachabilityEnabled; }
217
- get token() { return this.fpaToken; }
218
- subscribeToPushNotifications(channelType) {
219
- let subscriptions = [];
220
- [notificationtypes_1.NotificationTypes.NEW_MESSAGE,
221
- notificationtypes_1.NotificationTypes.ADDED_TO_CONVERSATION,
222
- notificationtypes_1.NotificationTypes.REMOVED_FROM_CONVERSATION,
223
- notificationtypes_1.NotificationTypes.TYPING_INDICATOR,
224
- notificationtypes_1.NotificationTypes.CONSUMPTION_UPDATE]
225
- .forEach(messageType => {
226
- subscriptions.push(this.services.notificationClient.subscribe(messageType, channelType));
227
- });
228
- return Promise.all(subscriptions);
229
- }
230
- unsubscribeFromPushNotifications(channelType) {
231
- let subscriptions = [];
232
- [notificationtypes_1.NotificationTypes.NEW_MESSAGE,
233
- notificationtypes_1.NotificationTypes.ADDED_TO_CONVERSATION,
234
- notificationtypes_1.NotificationTypes.REMOVED_FROM_CONVERSATION,
235
- notificationtypes_1.NotificationTypes.TYPING_INDICATOR,
236
- notificationtypes_1.NotificationTypes.CONSUMPTION_UPDATE]
237
- .forEach(messageType => {
238
- subscriptions.push(this.services.notificationClient.unsubscribe(messageType, channelType));
239
- });
240
- return Promise.all(subscriptions);
241
- }
242
- async initialize() {
243
- await this.sessionPromise;
244
- Client.supportedPushChannels.forEach(channelType => this.subscribeToPushNotifications(channelType));
245
- let links = await this.services.session.getSessionLinks();
246
- let options = Object.assign(this.options);
247
- options.transport = null;
248
- this.services.mcsClient = new twilio_mcs_client_1.McsClient(this.fpaToken, links.mediaServiceUrl, links.mediaSetServiceUrl, options);
249
- await this.services.typingIndicator.initialize();
250
- }
251
- /**
252
- * Gracefully shutting down library instance.
253
- * @public
254
- * @returns {Promise<void>}
255
- */
256
- async shutdown() {
257
- await this.services.twilsockClient.disconnect();
258
- }
259
- /**
260
- * Update the token used by the Client and re-register with Conversations services.
261
- * @param {String} token - Access token
262
- * @public
263
- * @returns {Promise<Client>}
264
- */
265
- async updateToken(token) {
266
- log.info('updateToken');
267
- if (this.fpaToken === token) {
268
- return this;
269
- }
270
- await this.services.twilsockClient.updateToken(token)
271
- .then(() => this.fpaToken = token)
272
- .then(() => this.services.mcsClient.updateToken(token))
273
- .then(() => this.sessionPromise);
274
- return this;
275
- }
276
- /**
277
- * Get a known Conversation by its SID.
278
- * @param {String} conversationSid - Conversation sid
279
- * @returns {Promise<Conversation>}
280
- */
281
- async getConversationBySid(conversationSid) {
282
- await this.conversations.syncListRead.promise;
283
- let conversation = await this.conversations.getConversation(conversationSid);
284
- if (!conversation) {
285
- conversation = await this.conversations.getWhisperConversation(conversationSid);
286
- }
287
- if (!conversation) {
288
- throw new Error(`Conversation with SID ${conversationSid} is not found.`);
289
- }
290
- return conversation;
291
- }
292
- /**
293
- * Get a known Conversation by its unique identifier name.
294
- * @param {String} uniqueName - The unique identifier name of the Conversation to get
295
- * @returns {Promise<Conversation>}
296
- */
297
- async getConversationByUniqueName(uniqueName) {
298
- await this.conversations.syncListRead.promise;
299
- const conversation = await this.conversations.getConversationByUniqueName(uniqueName);
300
- if (!conversation) {
301
- throw new Error(`Conversation with unique name ${uniqueName} is not found.`);
302
- }
303
- return conversation;
304
- }
305
- /**
306
- * Get the current list of all subscribed Conversations.
307
- * @returns {Promise<Paginator<Conversation>>}
308
- */
309
- getSubscribedConversations(args) {
310
- return this.conversationsPromise.then(conversations => conversations.getConversations(args));
311
- }
312
- /**
313
- * Create a Conversation on the server and subscribe to its events.
314
- * The default is a Conversation with an empty friendlyName.
315
- * @param {Client#CreateConversationOptions} [options] - Options for the Conversation
316
- * @returns {Promise<Conversation>}
317
- */
318
- createConversation(options) {
319
- options = options || {};
320
- return this.conversationsPromise.then(conversationsEntity => conversationsEntity.addConversation(options));
321
- }
322
- /**
323
- * Registers for push notifications.
324
- * @param {Client#NotificationsChannelType} channelType - 'apn' and 'fcm' are supported
325
- * @param {string} registrationId - Push notification id provided by the platform
326
- * @returns {Promise<void>}
327
- */
328
- async setPushRegistrationId(channelType, registrationId) {
329
- await this.subscribeToPushNotifications(channelType)
330
- .then(() => {
331
- return this.services.notificationClient.setPushRegistrationId(registrationId, channelType);
332
- });
333
- }
334
- /**
335
- * Unregisters from push notifications.
336
- * @param {Client#NotificationsChannelType} channelType - 'apn' and 'fcm' are supported
337
- * @returns {Promise<void>}
338
- */
339
- async unsetPushRegistrationId(channelType) {
340
- if (Client.supportedPushChannels.indexOf(channelType) === -1) {
341
- throw new Error('Invalid or unsupported channelType: ' + channelType);
342
- }
343
- await this.unsubscribeFromPushNotifications(channelType);
344
- }
345
- static parsePushNotificationChatData(data) {
346
- let result = {};
347
- for (let key in Client.supportedPushDataFields) {
348
- if (typeof data[key] !== 'undefined' && data[key] !== null) {
349
- if (key === 'message_index') {
350
- if (util_1.parseToNumber(data[key]) !== null) {
351
- result[Client.supportedPushDataFields[key]] = Number(data[key]);
352
- }
353
- }
354
- else {
355
- result[Client.supportedPushDataFields[key]] = data[key];
356
- }
357
- }
358
- }
359
- return result;
360
- }
361
- /**
362
- * Static method for push notification payload parsing. Returns parsed push as {@link PushNotification} object
363
- * @param {Object} notificationPayload - Push notification payload
364
- * @returns {PushNotification|Error}
365
- */
366
- static parsePushNotification(notificationPayload) {
367
- log.debug('parsePushNotification, notificationPayload=', notificationPayload);
368
- // APNS specifics
369
- if (typeof notificationPayload.aps !== 'undefined') {
370
- if (!notificationPayload.twi_message_type) {
371
- throw new Error('Provided push notification payload does not contain Programmable Chat push notification type');
372
- }
373
- let data = Client.parsePushNotificationChatData(notificationPayload);
374
- let apsPayload = notificationPayload.aps;
375
- let body = null;
376
- let title = null;
377
- if (typeof apsPayload.alert === 'string') {
378
- body = apsPayload.alert || null;
379
- }
380
- else {
381
- body = apsPayload.alert.body || null;
382
- title = apsPayload.alert.title || null;
383
- }
384
- return new pushnotification_1.PushNotification({
385
- title: title,
386
- body: body,
387
- sound: apsPayload.sound || null,
388
- badge: apsPayload.badge || null,
389
- action: apsPayload.category || null,
390
- type: notificationPayload.twi_message_type,
391
- data: data
392
- });
393
- }
394
- // FCM specifics
395
- if (typeof notificationPayload.data !== 'undefined') {
396
- let dataPayload = notificationPayload.data;
397
- if (!dataPayload.twi_message_type) {
398
- throw new Error('Provided push notification payload does not contain Programmable Chat push notification type');
399
- }
400
- let data = Client.parsePushNotificationChatData(notificationPayload.data);
401
- return new pushnotification_1.PushNotification({
402
- title: dataPayload.twi_title || null,
403
- body: dataPayload.twi_body || null,
404
- sound: dataPayload.twi_sound || null,
405
- badge: null,
406
- action: dataPayload.twi_action || null,
407
- type: dataPayload.twi_message_type,
408
- data: data
409
- });
410
- }
411
- throw new Error('Provided push notification payload is not Programmable Chat notification');
412
- }
413
- /**
414
- * Handle push notification payload parsing and emits event {@link Client#event:pushNotification} on this {@link Client} instance.
415
- * @param {Object} notificationPayload - Push notification payload
416
- * @returns {Promise<void>}
417
- */
418
- async handlePushNotification(notificationPayload) {
419
- log.debug('handlePushNotification, notificationPayload=', notificationPayload);
420
- this.emit('pushNotification', Client.parsePushNotification(notificationPayload));
421
- }
422
- /**
423
- * Gets user for given identity, if it's in subscribed list - then return the user object from it,
424
- * if not - then subscribes and adds user to the subscribed list.
425
- * @param {String} identity - Identity of User
426
- * @returns {Promise<User>} Fully initialized user
427
- */
428
- getUser(identity) {
429
- return this.services.users.getUser(identity);
430
- }
431
- /**
432
- * @returns {Promise<Array<User>>} List of subscribed User objects
433
- */
434
- async getSubscribedUsers() {
435
- return this.services.users.getSubscribedUsers();
436
- }
437
- }
438
- Client.version = SDK_VERSION;
439
- Client.supportedPushChannels = ['fcm', 'apn'];
440
- Client.supportedPushDataFields = {
441
- 'conversation_sid': 'conversationSid',
442
- 'message_sid': 'messageSid',
443
- 'message_index': 'messageIndex'
444
- };
445
- __decorate([
446
- twilio_sdk_type_validator_1.validateTypesAsync(twilio_sdk_type_validator_1.nonEmptyString),
447
- __metadata("design:type", Function),
448
- __metadata("design:paramtypes", [String]),
449
- __metadata("design:returntype", Promise)
450
- ], Client.prototype, "updateToken", null);
451
- __decorate([
452
- twilio_sdk_type_validator_1.validateTypesAsync(twilio_sdk_type_validator_1.nonEmptyString),
453
- __metadata("design:type", Function),
454
- __metadata("design:paramtypes", [String]),
455
- __metadata("design:returntype", Promise)
456
- ], Client.prototype, "getConversationBySid", null);
457
- __decorate([
458
- twilio_sdk_type_validator_1.validateTypesAsync(twilio_sdk_type_validator_1.nonEmptyString),
459
- __metadata("design:type", Function),
460
- __metadata("design:paramtypes", [String]),
461
- __metadata("design:returntype", Promise)
462
- ], Client.prototype, "getConversationByUniqueName", null);
463
- __decorate([
464
- twilio_sdk_type_validator_1.validateTypesAsync([
465
- 'undefined',
466
- twilio_sdk_type_validator_1.objectSchema('conversation options', {
467
- friendlyName: ['string', 'undefined'],
468
- isPrivate: ['boolean', 'undefined'],
469
- uniqueName: ['string', 'undefined']
470
- })
471
- ]),
472
- __metadata("design:type", Function),
473
- __metadata("design:paramtypes", [Object]),
474
- __metadata("design:returntype", Promise)
475
- ], Client.prototype, "createConversation", null);
476
- __decorate([
477
- twilio_sdk_type_validator_1.validateTypesAsync(twilio_sdk_type_validator_1.literal('fcm', 'apn'), 'string'),
478
- __metadata("design:type", Function),
479
- __metadata("design:paramtypes", [String, String]),
480
- __metadata("design:returntype", Promise)
481
- ], Client.prototype, "setPushRegistrationId", null);
482
- __decorate([
483
- twilio_sdk_type_validator_1.validateTypesAsync(twilio_sdk_type_validator_1.literal('fcm', 'apn')),
484
- __metadata("design:type", Function),
485
- __metadata("design:paramtypes", [String]),
486
- __metadata("design:returntype", Promise)
487
- ], Client.prototype, "unsetPushRegistrationId", null);
488
- __decorate([
489
- twilio_sdk_type_validator_1.validateTypesAsync(twilio_sdk_type_validator_1.pureObject),
490
- __metadata("design:type", Function),
491
- __metadata("design:paramtypes", [Object]),
492
- __metadata("design:returntype", Promise)
493
- ], Client.prototype, "handlePushNotification", null);
494
- __decorate([
495
- twilio_sdk_type_validator_1.validateTypesAsync(twilio_sdk_type_validator_1.nonEmptyString),
496
- __metadata("design:type", Function),
497
- __metadata("design:paramtypes", [String]),
498
- __metadata("design:returntype", Promise)
499
- ], Client.prototype, "getUser", null);
500
- __decorate([
501
- twilio_sdk_type_validator_1.validateTypesAsync('string', ['undefined', twilio_sdk_type_validator_1.pureObject]),
502
- __metadata("design:type", Function),
503
- __metadata("design:paramtypes", [String, Object]),
504
- __metadata("design:returntype", Promise)
505
- ], Client, "create", null);
506
- __decorate([
507
- twilio_sdk_type_validator_1.validateTypes(twilio_sdk_type_validator_1.pureObject),
508
- __metadata("design:type", Function),
509
- __metadata("design:paramtypes", [Object]),
510
- __metadata("design:returntype", pushnotification_1.PushNotification)
511
- ], Client, "parsePushNotification", null);
512
- exports.Client = Client;
513
- exports.default = Client;
514
- /**
515
- * Fired when a Conversation becomes visible to the Client. The event is also triggered when the client creates a new Conversation.
516
- * Fired for all conversations Client has joined.
517
- * @event Client#conversationAdded
518
- * @type {Conversation}
519
- */
520
- /**
521
- * Fired when the Client joins a Conversation.
522
- * @event Client#conversationJoined
523
- * @type {Conversation}
524
- */
525
- /**
526
- * Fired when the Client leaves a Conversation.
527
- * @event Client#conversationLeft
528
- * @type {Conversation}
529
- */
530
- /**
531
- * Fired when a Conversation is no longer visible to the Client.
532
- * @event Client#conversationRemoved
533
- * @type {Conversation}
534
- */
535
- /**
536
- * Fired when a Conversation's attributes or metadata have been updated.
537
- * During Conversation's {@link Client.create| creation and initialization} this event might be fired multiple times
538
- * for same joined or created Conversation as new data is arriving from different sources.
539
- * @event Client#conversationUpdated
540
- * @type {Object}
541
- * @property {Conversation} conversation - Updated Conversation
542
- * @property {Conversation#UpdateReason[]} updateReasons - Array of Conversation's updated event reasons
543
- */
544
- /**
545
- * Fired when Client's connection state has been changed.
546
- * @event Client#connectionStateChanged
547
- * @type {Client#ConnectionState}
548
- */
549
- /**
550
- * Fired when a Participant has joined the Conversation.
551
- * @event Client#participantJoined
552
- * @type {Participant}
553
- */
554
- /**
555
- * Fired when a Participant has left the Conversation.
556
- * @event Client#participantLeft
557
- * @type {Participant}
558
- */
559
- /**
560
- * Fired when a Participant's fields has been updated.
561
- * @event Client#participantUpdated
562
- * @type {Object}
563
- * @property {Participant} participant - Updated Participant
564
- * @property {Participant#UpdateReason[]} updateReasons - Array of Participant's updated event reasons
565
- */
566
- /**
567
- * Fired when a new Message has been added to the Conversation on the server.
568
- * @event Client#messageAdded
569
- * @type {Message}
570
- */
571
- /**
572
- * Fired when Message is removed from Conversation's message list.
573
- * @event Client#messageRemoved
574
- * @type {Message}
575
- */
576
- /**
577
- * Fired when an existing Message's fields are updated with new values.
578
- * @event Client#messageUpdated
579
- * @type {Object}
580
- * @property {Message} message - Updated Message
581
- * @property {Message#UpdateReason[]} updateReasons - Array of Message's updated event reasons
582
- */
583
- /**
584
- * Fired when token is about to expire and needs to be updated.
585
- * @event Client#tokenAboutToExpire
586
- * @type {void}
587
- */
588
- /**
589
- * Fired when token is expired.
590
- * @event Client#tokenExpired
591
- * @type {void}
592
- */
593
- /**
594
- * Fired when a Participant has stopped typing.
595
- * @event Client#typingEnded
596
- * @type {Participant}
597
- */
598
- /**
599
- * Fired when a Participant has started typing.
600
- * @event Client#typingStarted
601
- * @type {Participant}
602
- */
603
- /**
604
- * Fired when client received (and parsed) push notification via one of push channels (apn or fcm).
605
- * @event Client#pushNotification
606
- * @type {PushNotification}
607
- */
608
- /**
609
- * Fired when the Client is subscribed to a User.
610
- * @event Client#userSubscribed
611
- * @type {User}
612
- */
613
- /**
614
- * Fired when the Client is unsubscribed from a User.
615
- * @event Client#userUnsubscribed
616
- * @type {User}
617
- */
618
- /**
619
- * Fired when the User's properties or reachability status have been updated.
620
- * @event Client#userUpdated
621
- * @type {Object}
622
- * @property {User} user - Updated User
623
- * @property {User#UpdateReason[]} updateReasons - Array of User's updated event reasons
624
- */
625
- /**
626
- * Fired when connection is interrupted by unexpected reason
627
- * @event Client#connectionError
628
- * @type {Object}
629
- * @property {Boolean} terminal - twilsock will stop connection attempts
630
- * @property {String} message - root cause
631
- * @property {Number} [httpStatusCode] - http status code if available
632
- * @property {Number} [errorCode] - Twilio public error code if available
633
- */
@@ -1,21 +0,0 @@
1
- declare class Configuration {
2
- token: string;
3
- readonly typingIndicatorTimeoutOverride?: number;
4
- readonly httpCacheIntervalOverride?: string;
5
- readonly consumptionReportIntervalOverride?: number;
6
- readonly userInfosToSubscribeOverride?: number;
7
- readonly retryWhenThrottledOverride?: boolean;
8
- readonly backoffConfigOverride?: any;
9
- readonly typingIndicatorUri: string;
10
- readonly productId: string;
11
- private baseUrl;
12
- private region;
13
- constructor(options: any);
14
- get typingIndicatorTimeoutDefault(): number;
15
- get httpCacheIntervalDefault(): string;
16
- get consumptionReportIntervalDefault(): string;
17
- get userInfosToSubscribeDefault(): number;
18
- get retryWhenThrottledDefault(): boolean;
19
- get backoffConfigDefault(): any;
20
- }
21
- export { Configuration };