@twilio/conversations 2.0.0-rc.1 → 2.0.1-canary.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 (90) hide show
  1. package/README.md +25 -28
  2. package/dist/browser.js +3125 -3460
  3. package/dist/browser.js.map +1 -1
  4. package/dist/docs/assets/js/search.js +1 -1
  5. package/dist/docs/classes/AggregatedDeliveryReceipt.html +22 -6
  6. package/dist/docs/classes/Client.html +78 -33
  7. package/dist/docs/classes/Conversation.html +33 -17
  8. package/dist/docs/classes/DetailedDeliveryReceipt.html +22 -6
  9. package/dist/docs/classes/Media.html +23 -7
  10. package/dist/docs/classes/Message.html +23 -7
  11. package/dist/docs/classes/MessageBuilder.html +3280 -0
  12. package/dist/docs/classes/Participant.html +23 -7
  13. package/dist/docs/classes/PushNotification.html +24 -8
  14. package/dist/docs/classes/RestPaginator.html +28 -9
  15. package/dist/docs/classes/UnsentMessage.html +3144 -0
  16. package/dist/docs/classes/User.html +25 -9
  17. package/dist/docs/index.html +89 -47
  18. package/dist/docs/interfaces/ClientOptions.html +22 -6
  19. package/dist/docs/interfaces/ConversationState.html +22 -6
  20. package/dist/docs/interfaces/CreateConversationOptions.html +22 -6
  21. package/dist/docs/interfaces/LastMessage.html +22 -6
  22. package/dist/docs/interfaces/Paginator.html +3243 -0
  23. package/dist/docs/interfaces/PushNotificationData.html +3168 -0
  24. package/dist/docs/interfaces/SendEmailOptions.html +22 -6
  25. package/dist/docs/interfaces/SendMediaOptions.html +24 -7
  26. package/dist/docs/modules.html +88 -46
  27. package/dist/lib/aggregated-delivery-receipt.js +227 -0
  28. package/dist/lib/aggregated-delivery-receipt.js.map +1 -0
  29. package/dist/lib/client.js +872 -0
  30. package/dist/lib/client.js.map +1 -0
  31. package/dist/lib/command-executor.js +203 -0
  32. package/dist/lib/command-executor.js.map +1 -0
  33. package/dist/lib/configuration.js +196 -0
  34. package/dist/lib/configuration.js.map +1 -0
  35. package/dist/lib/conversation.js +973 -0
  36. package/dist/lib/conversation.js.map +1 -0
  37. package/dist/lib/data/conversations.js +443 -0
  38. package/dist/lib/data/conversations.js.map +1 -0
  39. package/dist/lib/data/messages.js +341 -0
  40. package/dist/lib/data/messages.js.map +1 -0
  41. package/dist/lib/data/participants.js +313 -0
  42. package/dist/lib/data/participants.js.map +1 -0
  43. package/dist/lib/data/users.js +228 -0
  44. package/dist/lib/data/users.js.map +1 -0
  45. package/dist/lib/detailed-delivery-receipt.js +154 -0
  46. package/dist/lib/detailed-delivery-receipt.js.map +1 -0
  47. package/dist/lib/index.js +167 -0
  48. package/dist/lib/index.js.map +1 -0
  49. package/dist/lib/interfaces/notification-types.js +143 -0
  50. package/dist/lib/interfaces/notification-types.js.map +1 -0
  51. package/dist/lib/logger.js +190 -0
  52. package/dist/lib/logger.js.map +1 -0
  53. package/dist/lib/media.js +213 -0
  54. package/dist/lib/media.js.map +1 -0
  55. package/dist/lib/message-builder.js +209 -0
  56. package/dist/lib/message-builder.js.map +1 -0
  57. package/dist/lib/message.js +450 -0
  58. package/dist/lib/message.js.map +1 -0
  59. package/dist/lib/node_modules/tslib/tslib.es6.js +161 -0
  60. package/dist/lib/node_modules/tslib/tslib.es6.js.map +1 -0
  61. package/dist/lib/packages/conversations/package.json.js +136 -0
  62. package/dist/lib/packages/conversations/package.json.js.map +1 -0
  63. package/dist/lib/participant.js +346 -0
  64. package/dist/lib/participant.js.map +1 -0
  65. package/dist/lib/push-notification.js +152 -0
  66. package/dist/lib/push-notification.js.map +1 -0
  67. package/dist/lib/rest-paginator.js +175 -0
  68. package/dist/lib/rest-paginator.js.map +1 -0
  69. package/dist/lib/services/network.js +205 -0
  70. package/dist/lib/services/network.js.map +1 -0
  71. package/dist/lib/services/typing-indicator.js +235 -0
  72. package/dist/lib/services/typing-indicator.js.map +1 -0
  73. package/dist/lib/unsent-message.js +159 -0
  74. package/dist/lib/unsent-message.js.map +1 -0
  75. package/dist/lib/user.js +392 -0
  76. package/dist/lib/user.js.map +1 -0
  77. package/dist/lib/util/deferred.js +154 -0
  78. package/dist/lib/util/deferred.js.map +1 -0
  79. package/dist/lib/util/index.js +206 -0
  80. package/dist/lib/util/index.js.map +1 -0
  81. package/dist/lib.d.ts +250 -59
  82. package/dist/lib.js +3055 -2919
  83. package/dist/lib.js.map +1 -1
  84. package/dist/twilio-conversations.js +25175 -23918
  85. package/dist/twilio-conversations.min.js +14 -2
  86. package/package.json +16 -14
  87. package/CHANGELOG.md +0 -168
  88. package/dist/post-install.js +0 -29
  89. package/dist/react-native.js +0 -4412
  90. package/dist/react-native.js.map +0 -1
@@ -0,0 +1,313 @@
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
+ Object.defineProperty(exports, '__esModule', { value: true });
132
+
133
+ var participant = require('../participant.js');
134
+ var logger = require('../logger.js');
135
+ var replayEventEmitter = require('@twilio/replay-event-emitter');
136
+
137
+ const log = logger.Logger.scope('Participants');
138
+ /**
139
+ * @classdesc Represents the collection of participants for the conversation
140
+ * @fires Participants#participantJoined
141
+ * @fires Participants#participantLeft
142
+ * @fires Participants#participantUpdated
143
+ */
144
+ class Participants extends replayEventEmitter.ReplayEventEmitter {
145
+ constructor(conversation, participants, links, configuration, services) {
146
+ super();
147
+ this.conversation = conversation;
148
+ this.participants = participants;
149
+ this.links = links;
150
+ this.configuration = configuration;
151
+ this.services = services;
152
+ }
153
+ async unsubscribe() {
154
+ if (this.rosterEntityPromise) {
155
+ let entity = await this.rosterEntityPromise;
156
+ entity.close();
157
+ this.rosterEntityPromise = null;
158
+ }
159
+ }
160
+ subscribe(rosterObjectName) {
161
+ return this.rosterEntityPromise = this.rosterEntityPromise
162
+ || this.services.syncClient.map({ id: rosterObjectName, mode: 'open_existing' })
163
+ .then(rosterMap => {
164
+ rosterMap.on('itemAdded', args => {
165
+ log.debug(this.conversation.sid + ' itemAdded: ' + args.item.key);
166
+ this.upsertParticipant(args.item.key, args.item.data)
167
+ .then(participant => {
168
+ this.emit('participantJoined', participant);
169
+ });
170
+ });
171
+ rosterMap.on('itemRemoved', args => {
172
+ log.debug(this.conversation.sid + ' itemRemoved: ' + args.key);
173
+ let participantSid = args.key;
174
+ if (!this.participants.has(participantSid)) {
175
+ return;
176
+ }
177
+ let leftParticipant = this.participants.get(participantSid);
178
+ this.participants.delete(participantSid);
179
+ this.emit('participantLeft', leftParticipant);
180
+ });
181
+ rosterMap.on('itemUpdated', args => {
182
+ log.debug(this.conversation.sid + ' itemUpdated: ' + args.item.key);
183
+ this.upsertParticipant(args.item.key, args.item.data);
184
+ });
185
+ let participantsPromises = [];
186
+ let that = this;
187
+ const rosterMapHandler = function (paginator) {
188
+ paginator.items.forEach(item => { participantsPromises.push(that.upsertParticipant(item.key, item.data)); });
189
+ return paginator.hasNextPage ? paginator.nextPage().then(rosterMapHandler) : null;
190
+ };
191
+ return rosterMap
192
+ .getItems()
193
+ .then(rosterMapHandler)
194
+ .then(() => Promise.all(participantsPromises))
195
+ .then(() => rosterMap);
196
+ })
197
+ .catch(err => {
198
+ this.rosterEntityPromise = null;
199
+ if (this.services.syncClient.connectionState != 'disconnected') {
200
+ log.error('Failed to get roster object for conversation', this.conversation.sid, err);
201
+ }
202
+ log.debug('ERROR: Failed to get roster object for conversation', this.conversation.sid, err);
203
+ throw err;
204
+ });
205
+ }
206
+ async upsertParticipant(participantSid, data) {
207
+ let participant$1 = this.participants.get(participantSid);
208
+ if (participant$1) {
209
+ return participant$1._update(data);
210
+ }
211
+ const links = {
212
+ self: `${this.links.participants}/${participantSid}`
213
+ };
214
+ participant$1 = new participant.Participant(data, participantSid, this.conversation, links, this.services);
215
+ this.participants.set(participantSid, participant$1);
216
+ participant$1.on('updated', (args) => this.emit('participantUpdated', args));
217
+ return participant$1;
218
+ }
219
+ /**
220
+ * @returns {Promise<Array<Participant>>} returns list of participants {@see Participant}
221
+ */
222
+ getParticipants() {
223
+ return this.rosterEntityPromise.then(() => {
224
+ let participants = [];
225
+ this.participants.forEach(participant => participants.push(participant));
226
+ return participants;
227
+ });
228
+ }
229
+ /**
230
+ * Get participant by SID from conversation
231
+ * @returns {Promise<Participant>}
232
+ */
233
+ async getParticipantBySid(participantSid) {
234
+ return this.rosterEntityPromise.then(() => {
235
+ let participant = this.participants.get(participantSid);
236
+ if (!participant) {
237
+ throw new Error('Participant with SID ' + participantSid + ' was not found');
238
+ }
239
+ return participant;
240
+ });
241
+ }
242
+ /**
243
+ * Get participant by identity from conversation
244
+ * @returns {Promise<Participant>}
245
+ */
246
+ async getParticipantByIdentity(identity) {
247
+ let foundParticipant = null;
248
+ return this.rosterEntityPromise.then(() => {
249
+ this.participants.forEach(participant => {
250
+ if (participant.identity === identity) {
251
+ foundParticipant = participant;
252
+ }
253
+ });
254
+ if (!foundParticipant) {
255
+ throw new Error('Participant with identity ' + identity + ' was not found');
256
+ }
257
+ return foundParticipant;
258
+ });
259
+ }
260
+ /**
261
+ * Add a chat participant to the conversation
262
+ * @returns {Promise<any>}
263
+ */
264
+ async add(identity, attributes) {
265
+ return await this.services.commandExecutor.mutateResource('post', this.links.participants, {
266
+ identity,
267
+ attributes: typeof attributes !== 'undefined' ? JSON.stringify(attributes) : undefined
268
+ });
269
+ }
270
+ /**
271
+ * Add a non-chat participant to the conversation.
272
+ *
273
+ * @param proxyAddress
274
+ * @param address
275
+ * @param attributes
276
+ * @returns {Promise<any>}
277
+ */
278
+ addNonChatParticipant(proxyAddress, address, attributes) {
279
+ return this.services.commandExecutor.mutateResource('post', this.links.participants, {
280
+ attributes: typeof attributes !== 'undefined' ? JSON.stringify(attributes) : undefined,
281
+ messaging_binding: {
282
+ address,
283
+ proxy_address: proxyAddress
284
+ }
285
+ });
286
+ }
287
+ /**
288
+ * Remove the participant with a given identity from a conversation.
289
+ */
290
+ remove(identity) {
291
+ return this.services.commandExecutor.mutateResource('delete', `${this.links.participants}/${identity}`);
292
+ }
293
+ }
294
+ /**
295
+ * Fired when participant joined conversation
296
+ * @event Participants#participantJoined
297
+ * @type {Participant}
298
+ */
299
+ /**
300
+ * Fired when participant left conversation
301
+ * @event Participants#participantLeft
302
+ * @type {Participant}
303
+ */
304
+ /**
305
+ * Fired when participant updated
306
+ * @event Participants#participantUpdated
307
+ * @type {Object}
308
+ * @property {Participant} participant - Updated Participant
309
+ * @property {Participant#UpdateReason[]} updateReasons - Array of Participant's updated event reasons
310
+ */
311
+
312
+ exports.Participants = Participants;
313
+ //# sourceMappingURL=participants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"participants.js","sources":["../../../src/data/participants.ts"],"sourcesContent":["import { EventEmitter } from 'events';\nimport {\n ParticipantDescriptor,\n Participant,\n ParticipantUpdatedEventArgs,\n ParticipantUpdateReason\n} from '../participant';\nimport { Logger } from '../logger';\n\nimport { Conversation } from '../conversation';\n\nimport { SyncMap, SyncClient } from 'twilio-sync';\nimport { Users } from './users';\nimport { CommandExecutor } from '../command-executor';\nimport {\n AddParticipantRequest\n} from '../interfaces/commands/add-participant';\nimport { Configuration } from '../configuration';\nimport { ParticipantResponse } from '../interfaces/commands/participant-response';\nimport { ReplayEventEmitter } from '@twilio/replay-event-emitter';\n\ntype ParticipantsEvents = {\n participantJoined: (participant: Participant) => void;\n participantLeft: (participant: Participant) => void;\n participantUpdated: (data: {\n participant: Participant;\n updateReasons: ParticipantUpdateReason[];\n }) => void;\n};\n\nconst log = Logger.scope('Participants');\n\nexport interface ParticipantsServices {\n syncClient: SyncClient;\n users: Users;\n commandExecutor: CommandExecutor;\n}\n\ninterface ParticipantsLinks {\n participants: string;\n}\n\n/**\n * @classdesc Represents the collection of participants for the conversation\n * @fires Participants#participantJoined\n * @fires Participants#participantLeft\n * @fires Participants#participantUpdated\n */\nclass Participants extends ReplayEventEmitter<ParticipantsEvents> {\n\n private readonly configuration: Configuration;\n private readonly services: ParticipantsServices;\n private readonly links: ParticipantsLinks;\n\n rosterEntityPromise: Promise<SyncMap>;\n\n public readonly conversation: Conversation;\n public readonly participants: Map<string, Participant>;\n\n constructor(\n conversation: Conversation,\n participants: Map<string, Participant>,\n links: ParticipantsLinks,\n configuration: Configuration,\n services: ParticipantsServices,\n ) {\n super();\n this.conversation = conversation;\n this.participants = participants;\n this.links = links;\n this.configuration = configuration;\n this.services = services;\n }\n\n async unsubscribe(): Promise<void> {\n if (this.rosterEntityPromise) {\n let entity = await this.rosterEntityPromise;\n entity.close();\n this.rosterEntityPromise = null;\n }\n }\n\n subscribe(rosterObjectName: string) {\n return this.rosterEntityPromise = this.rosterEntityPromise\n || this.services.syncClient.map({ id: rosterObjectName, mode: 'open_existing' })\n .then(rosterMap => {\n rosterMap.on('itemAdded', args => {\n log.debug(this.conversation.sid + ' itemAdded: ' + args.item.key);\n this.upsertParticipant(args.item.key, args.item.data)\n .then(participant => {\n this.emit('participantJoined', participant);\n });\n });\n\n rosterMap.on('itemRemoved', args => {\n log.debug(this.conversation.sid + ' itemRemoved: ' + args.key);\n let participantSid = args.key;\n if (!this.participants.has(participantSid)) {\n return;\n }\n let leftParticipant = this.participants.get(participantSid);\n this.participants.delete(participantSid);\n this.emit('participantLeft', leftParticipant);\n });\n\n rosterMap.on('itemUpdated', args => {\n log.debug(this.conversation.sid + ' itemUpdated: ' + args.item.key);\n this.upsertParticipant(args.item.key, args.item.data);\n });\n\n let participantsPromises = [];\n let that = this;\n const rosterMapHandler = function(paginator) {\n paginator.items.forEach(item => { participantsPromises.push(that.upsertParticipant(item.key, item.data)); });\n return paginator.hasNextPage ? paginator.nextPage().then(rosterMapHandler) : null;\n };\n\n return rosterMap\n .getItems()\n .then(rosterMapHandler)\n .then(() => Promise.all(participantsPromises))\n .then(() => rosterMap);\n })\n .catch(err => {\n this.rosterEntityPromise = null;\n if (this.services.syncClient.connectionState != 'disconnected') {\n log.error('Failed to get roster object for conversation', this.conversation.sid, err);\n }\n log.debug('ERROR: Failed to get roster object for conversation', this.conversation.sid, err);\n throw err;\n });\n }\n\n async upsertParticipant(participantSid: string, data: ParticipantDescriptor): Promise<Participant> {\n let participant = this.participants.get(participantSid);\n if (participant) {\n return participant._update(data);\n }\n\n const links = {\n self: `${this.links.participants}/${participantSid}`\n };\n\n participant = new Participant(data, participantSid, this.conversation, links, this.services);\n this.participants.set(participantSid, participant);\n participant.on('updated', (args: ParticipantUpdatedEventArgs) => this.emit('participantUpdated', args));\n return participant;\n }\n\n /**\n * @returns {Promise<Array<Participant>>} returns list of participants {@see Participant}\n */\n getParticipants(): Promise<Array<Participant>> {\n return this.rosterEntityPromise.then(() => {\n let participants = [];\n this.participants.forEach(participant => participants.push(participant));\n return participants;\n });\n }\n\n /**\n * Get participant by SID from conversation\n * @returns {Promise<Participant>}\n */\n async getParticipantBySid(participantSid: string): Promise<Participant> {\n return this.rosterEntityPromise.then(() => {\n let participant = this.participants.get(participantSid);\n if (!participant) {\n throw new Error('Participant with SID ' + participantSid + ' was not found');\n }\n return participant;\n });\n }\n\n /**\n * Get participant by identity from conversation\n * @returns {Promise<Participant>}\n */\n async getParticipantByIdentity(identity: string): Promise<Participant> {\n let foundParticipant = null;\n return this.rosterEntityPromise.then(() => {\n this.participants.forEach(participant => {\n if (participant.identity === identity) {\n foundParticipant = participant;\n }\n });\n if (!foundParticipant) {\n throw new Error('Participant with identity ' + identity + ' was not found');\n }\n return foundParticipant;\n });\n }\n\n /**\n * Add a chat participant to the conversation\n * @returns {Promise<any>}\n */\n async add(identity: string, attributes: any): Promise<any> {\n return await this.services.commandExecutor.mutateResource<AddParticipantRequest, ParticipantResponse>(\n 'post',\n this.links.participants,\n {\n identity,\n attributes: typeof attributes !== 'undefined' ? JSON.stringify(attributes) : undefined\n }\n );\n }\n\n /**\n * Add a non-chat participant to the conversation.\n *\n * @param proxyAddress\n * @param address\n * @param attributes\n * @returns {Promise<any>}\n */\n addNonChatParticipant(proxyAddress: string, address: string, attributes: any): Promise<any> {\n return this.services.commandExecutor.mutateResource<AddParticipantRequest, ParticipantResponse>(\n 'post',\n this.links.participants,\n {\n attributes: typeof attributes !== 'undefined' ? JSON.stringify(attributes) : undefined,\n messaging_binding: {\n address,\n proxy_address: proxyAddress\n }\n }\n );\n }\n\n /**\n * Remove the participant with a given identity from a conversation.\n */\n remove(identity: string): Promise<any> {\n return this.services.commandExecutor.mutateResource(\n 'delete',\n `${this.links.participants}/${identity}`,\n );\n }\n}\n\nexport { Participants };\n\n/**\n * Fired when participant joined conversation\n * @event Participants#participantJoined\n * @type {Participant}\n */\n\n/**\n * Fired when participant left conversation\n * @event Participants#participantLeft\n * @type {Participant}\n */\n\n/**\n * Fired when participant updated\n * @event Participants#participantUpdated\n * @type {Object}\n * @property {Participant} participant - Updated Participant\n * @property {Participant#UpdateReason[]} updateReasons - Array of Participant's updated event reasons\n */\n"],"names":["Logger","ReplayEventEmitter","participant","Participant"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAM,GAAG,GAAGA,aAAM,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;AAYzC;;;;;;AAMA,MAAM,YAAa,SAAQC,qCAAsC;IAW/D,YACE,YAA0B,EAC1B,YAAsC,EACtC,KAAwB,EACxB,aAA4B,EAC5B,QAA8B;QAE9B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,YAAY,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CAAC,YAAoB,EAAE,OAAe,EAAE,UAAe;QAC1E,OAAO,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,cAAc,CACjD,MAAM,EACN,IAAI,CAAC,KAAK,CAAC,YAAY,EACvB;YACE,UAAU,EAAE,OAAO,UAAU,KAAK,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,SAAS;YACtF,iBAAiB,EAAE;gBACjB,OAAO;gBACP,aAAa,EAAE,YAAY;aAC5B;SACF,CACF,CAAC;KACH;;;;IAKD,MAAM,CAAC,QAAgB;QACrB,OAAO,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,cAAc,CACjD,QAAQ,EACR,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,IAAI,QAAQ,EAAE,CACzC,CAAC;KACH;CACF;AAID;;;;;AAMA;;;;;AAMA;;;;;;;;;;"}
@@ -0,0 +1,228 @@
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
+ Object.defineProperty(exports, '__esModule', { value: true });
132
+
133
+ var user = require('../user.js');
134
+ var index = require('../util/index.js');
135
+ var replayEventEmitter = require('@twilio/replay-event-emitter');
136
+
137
+ /**
138
+ * Container for known users
139
+ */
140
+ class Users extends replayEventEmitter.ReplayEventEmitter {
141
+ constructor(myself, configuration, services) {
142
+ super();
143
+ this.configuration = configuration;
144
+ this.services = services;
145
+ this.fifoStack = [];
146
+ this.myself = myself;
147
+ this.myself.on('updated', (args) => this.emit('userUpdated', args));
148
+ this.myself.on('userSubscribed', () => this.emit('userSubscribed', this.myself));
149
+ this.myself.on('userUnsubscribed', () => {
150
+ this.emit('userUnsubscribed', this.myself);
151
+ this.myself._ensureFetched();
152
+ });
153
+ this.subscribedUsers = new Map();
154
+ }
155
+ handleUnsubscribeUser(user) {
156
+ if (this.subscribedUsers.has(user.identity)) {
157
+ this.subscribedUsers.delete(user.identity);
158
+ }
159
+ let foundItemIndex = -1;
160
+ let foundItem = this.fifoStack.find((item, index) => {
161
+ if (item == user.identity) {
162
+ foundItemIndex = index;
163
+ return true;
164
+ }
165
+ return false;
166
+ });
167
+ if (foundItem) {
168
+ this.fifoStack.splice(foundItemIndex, 1);
169
+ }
170
+ this.emit('userUnsubscribed', user);
171
+ }
172
+ handleSubscribeUser(user) {
173
+ if (this.subscribedUsers.has(user.identity)) {
174
+ return;
175
+ }
176
+ if (this.fifoStack.length >= this.configuration.userInfosToSubscribe) {
177
+ this.subscribedUsers.get(this.fifoStack.shift()).unsubscribe();
178
+ }
179
+ this.fifoStack.push(user.identity);
180
+ this.subscribedUsers.set(user.identity, user);
181
+ this.emit('userSubscribed', user);
182
+ }
183
+ /**
184
+ * Gets user, if it's in subscribed list - then return the user object from it,
185
+ * if not - then subscribes and adds user to the FIFO stack
186
+ * @returns {Promise<User>} Fully initialized user
187
+ */
188
+ async getUser(identity, entityName = null) {
189
+ await this.myself._ensureFetched();
190
+ if (identity == this.myself.identity) {
191
+ return this.myself;
192
+ }
193
+ let user$1 = this.subscribedUsers.get(identity);
194
+ if (!user$1) {
195
+ if (!entityName) {
196
+ entityName = await this.getSyncUniqueName(identity);
197
+ }
198
+ user$1 = new user.User(identity, entityName, this.configuration, this.services);
199
+ user$1.on('updated', (args) => this.emit('userUpdated', args));
200
+ user$1.on('userSubscribed', () => this.handleSubscribeUser(user$1));
201
+ user$1.on('userUnsubscribed', () => this.handleUnsubscribeUser(user$1));
202
+ await user$1._ensureFetched();
203
+ }
204
+ return user$1;
205
+ }
206
+ /**
207
+ * @returns {Promise<Array<User>>} returns list of subscribed User objects {@see User}
208
+ */
209
+ async getSubscribedUsers() {
210
+ await this.myself._ensureFetched();
211
+ const users = [this.myself];
212
+ this.subscribedUsers.forEach((user) => users.push(user));
213
+ return users;
214
+ }
215
+ /**
216
+ * @returns {Promise<string>} User's sync unique name
217
+ */
218
+ async getSyncUniqueName(identity) {
219
+ const url = new index.UriBuilder(this.configuration.links.users)
220
+ .path(identity)
221
+ .build();
222
+ const response = await this.services.network.get(url);
223
+ return response.body.sync_objects.user_info_map;
224
+ }
225
+ }
226
+
227
+ exports.Users = Users;
228
+ //# sourceMappingURL=users.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"users.js","sources":["../../../src/data/users.ts"],"sourcesContent":["import { User, UserUpdatedEventArgs, UserUpdateReason } from '../user';\nimport { Network } from '../services/network';\nimport { SyncClient } from 'twilio-sync';\nimport { UriBuilder } from '../util';\nimport { Configuration } from '../configuration';\nimport { CommandExecutor } from '../command-executor';\nimport { ReplayEventEmitter } from '@twilio/replay-event-emitter';\n\ntype UsersEvents = {\n userUpdated: (data: {\n user: User;\n updateReasons: UserUpdateReason[]\n }) => void;\n userSubscribed: (user: User) => void;\n userUnsubscribed: (user: User) => void;\n};\n\nexport interface UsersServices {\n network: Network;\n syncClient: SyncClient;\n commandExecutor: CommandExecutor;\n}\n\n/**\n * Container for known users\n */\nclass Users extends ReplayEventEmitter<UsersEvents> {\n private readonly configuration: Configuration;\n private readonly services: UsersServices;\n\n private subscribedUsers: Map<string, User>;\n private fifoStack: any;\n public readonly myself: User;\n\n constructor(myself: User, configuration: Configuration, services: UsersServices) {\n super();\n\n this.configuration = configuration;\n this.services = services;\n\n this.fifoStack = [];\n this.myself = myself;\n this.myself.on('updated', (args: UserUpdatedEventArgs) => this.emit('userUpdated', args));\n this.myself.on('userSubscribed', () => this.emit('userSubscribed', this.myself));\n this.myself.on('userUnsubscribed', () => {\n this.emit('userUnsubscribed', this.myself);\n this.myself._ensureFetched();\n });\n\n this.subscribedUsers = new Map<string, User>();\n }\n\n private handleUnsubscribeUser(user: User): void {\n if (this.subscribedUsers.has(user.identity)) {\n this.subscribedUsers.delete(user.identity);\n }\n let foundItemIndex = -1;\n let foundItem = this.fifoStack.find((item, index) => {\n if (item == user.identity) {\n foundItemIndex = index;\n return true;\n }\n return false;\n });\n if (foundItem) {\n this.fifoStack.splice(foundItemIndex, 1);\n }\n this.emit('userUnsubscribed', user);\n }\n\n private handleSubscribeUser(user: User): void {\n if (this.subscribedUsers.has(user.identity)) {\n return;\n }\n if (this.fifoStack.length >= this.configuration.userInfosToSubscribe) {\n this.subscribedUsers.get(this.fifoStack.shift()).unsubscribe();\n }\n this.fifoStack.push(user.identity);\n this.subscribedUsers.set(user.identity, user);\n this.emit('userSubscribed', user);\n }\n\n /**\n * Gets user, if it's in subscribed list - then return the user object from it,\n * if not - then subscribes and adds user to the FIFO stack\n * @returns {Promise<User>} Fully initialized user\n */\n async getUser(identity: string, entityName: string = null): Promise<User> {\n await this.myself._ensureFetched();\n\n if (identity == this.myself.identity) {\n return this.myself;\n }\n\n let user = this.subscribedUsers.get(identity);\n if (!user) {\n if (!entityName) {\n entityName = await this.getSyncUniqueName(identity);\n }\n\n user = new User(identity, entityName, this.configuration, this.services);\n user.on('updated', (args: UserUpdatedEventArgs) => this.emit('userUpdated', args));\n user.on('userSubscribed', () => this.handleSubscribeUser(user));\n user.on('userUnsubscribed', () => this.handleUnsubscribeUser(user));\n await user._ensureFetched();\n }\n\n return user;\n }\n\n /**\n * @returns {Promise<Array<User>>} returns list of subscribed User objects {@see User}\n */\n async getSubscribedUsers(): Promise<Array<User>> {\n await this.myself._ensureFetched();\n\n const users = [this.myself];\n this.subscribedUsers.forEach((user) => users.push(user));\n\n return users;\n }\n\n /**\n * @returns {Promise<string>} User's sync unique name\n */\n private async getSyncUniqueName(identity: string): Promise<string> {\n const url = new UriBuilder(this.configuration.links.users)\n .path(identity)\n .build();\n const response = await this.services.network.get(url);\n return response.body.sync_objects.user_info_map;\n }\n}\n\nexport { Users };\n"],"names":["ReplayEventEmitter","user","User","UriBuilder"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA;;;AAGA,MAAM,KAAM,SAAQA,qCAA+B;IAQjD,YAAY,MAAY,EAAE,aAA4B,EAAE,QAAuB;QAC7E,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QACpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,IAA0B,KAAK,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC,CAAC;QAC1F,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,gBAAgB,EAAE,MAAM,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;QACjF,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,kBAAkB,EAAE;YACjC,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YAC3C,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;SAC9B,CAAC,CAAC;QAEH,IAAI,CAAC,eAAe,GAAG,IAAI,GAAG,EAAgB,CAAC;KAChD;IAEO,qBAAqB,CAAC,IAAU;QACtC,IAAI,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,C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