@twilio/conversations 2.0.1-rc.5 → 2.0.1-rc.9
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.
- package/CHANGELOG.md +33 -0
- package/{dist → builds}/browser.js +1 -1
- package/{dist → builds}/browser.js.map +0 -0
- package/{dist → builds}/lib.d.ts +0 -0
- package/{dist → builds}/lib.js +1 -1
- package/{dist → builds}/lib.js.map +0 -0
- package/{dist → builds}/twilio-conversations.js +8 -188
- package/{dist → builds}/twilio-conversations.min.js +2 -2
- package/dist/aggregated-delivery-receipt.js +227 -0
- package/dist/aggregated-delivery-receipt.js.map +1 -0
- package/dist/client.js +872 -0
- package/dist/client.js.map +1 -0
- package/dist/command-executor.js +203 -0
- package/dist/command-executor.js.map +1 -0
- package/dist/configuration.js +196 -0
- package/dist/configuration.js.map +1 -0
- package/dist/conversation.js +973 -0
- package/dist/conversation.js.map +1 -0
- package/dist/data/conversations.js +443 -0
- package/dist/data/conversations.js.map +1 -0
- package/dist/data/messages.js +341 -0
- package/dist/data/messages.js.map +1 -0
- package/dist/data/participants.js +313 -0
- package/dist/data/participants.js.map +1 -0
- package/dist/data/users.js +228 -0
- package/dist/data/users.js.map +1 -0
- package/dist/detailed-delivery-receipt.js +154 -0
- package/dist/detailed-delivery-receipt.js.map +1 -0
- package/dist/index.js +167 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/notification-types.js +143 -0
- package/dist/interfaces/notification-types.js.map +1 -0
- package/dist/logger.js +190 -0
- package/dist/logger.js.map +1 -0
- package/dist/media.js +213 -0
- package/dist/media.js.map +1 -0
- package/dist/message-builder.js +209 -0
- package/dist/message-builder.js.map +1 -0
- package/dist/message.js +450 -0
- package/dist/message.js.map +1 -0
- package/dist/node_modules/tslib/tslib.es6.js +161 -0
- package/dist/node_modules/tslib/tslib.es6.js.map +1 -0
- package/dist/packages/conversations/package.json.js +136 -0
- package/dist/packages/conversations/package.json.js.map +1 -0
- package/dist/participant.js +346 -0
- package/dist/participant.js.map +1 -0
- package/dist/push-notification.js +152 -0
- package/dist/push-notification.js.map +1 -0
- package/dist/rest-paginator.js +175 -0
- package/dist/rest-paginator.js.map +1 -0
- package/dist/services/network.js +205 -0
- package/dist/services/network.js.map +1 -0
- package/dist/services/typing-indicator.js +235 -0
- package/dist/services/typing-indicator.js.map +1 -0
- package/dist/unsent-message.js +159 -0
- package/dist/unsent-message.js.map +1 -0
- package/dist/user.js +392 -0
- package/dist/user.js.map +1 -0
- package/dist/util/deferred.js +154 -0
- package/dist/util/deferred.js.map +1 -0
- package/dist/util/index.js +206 -0
- package/dist/util/index.js.map +1 -0
- package/{dist/docs → docs}/assets/css/main.css +0 -0
- package/{dist/docs → docs}/assets/images/icons.png +0 -0
- package/{dist/docs → docs}/assets/images/icons@2x.png +0 -0
- package/{dist/docs → docs}/assets/images/widgets.png +0 -0
- package/{dist/docs → docs}/assets/images/widgets@2x.png +0 -0
- package/{dist/docs → docs}/assets/js/main.js +0 -0
- package/{dist/docs → docs}/assets/js/search.js +0 -0
- package/{dist/docs → docs}/classes/AggregatedDeliveryReceipt.html +0 -0
- package/{dist/docs → docs}/classes/Client.html +0 -0
- package/{dist/docs → docs}/classes/Conversation.html +0 -0
- package/{dist/docs → docs}/classes/DetailedDeliveryReceipt.html +0 -0
- package/{dist/docs → docs}/classes/Media.html +0 -0
- package/{dist/docs → docs}/classes/Message.html +0 -0
- package/{dist/docs → docs}/classes/MessageBuilder.html +0 -0
- package/{dist/docs → docs}/classes/Participant.html +0 -0
- package/{dist/docs → docs}/classes/PushNotification.html +0 -0
- package/{dist/docs → docs}/classes/RestPaginator.html +0 -0
- package/{dist/docs → docs}/classes/UnsentMessage.html +0 -0
- package/{dist/docs → docs}/classes/User.html +0 -0
- package/{dist/docs → docs}/index.html +0 -0
- package/{dist/docs → docs}/interfaces/ClientOptions.html +0 -0
- package/{dist/docs → docs}/interfaces/ConversationState.html +0 -0
- package/{dist/docs → docs}/interfaces/CreateConversationOptions.html +0 -0
- package/{dist/docs → docs}/interfaces/LastMessage.html +0 -0
- package/{dist/docs → docs}/interfaces/Paginator.html +0 -0
- package/{dist/docs → docs}/interfaces/PushNotificationData.html +0 -0
- package/{dist/docs → docs}/interfaces/SendEmailOptions.html +0 -0
- package/{dist/docs → docs}/interfaces/SendMediaOptions.html +0 -0
- package/{dist/docs → docs}/modules.html +0 -0
- package/package.json +23 -24
- package/dist/post-install.js +0 -29
- package/dist/react-native.js +0 -4035
- package/dist/react-native.js.map +0 -1
package/dist/user.js
ADDED
@@ -0,0 +1,392 @@
|
|
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 tslib_es6 = require('./node_modules/tslib/tslib.es6.js');
|
134
|
+
var logger = require('./logger.js');
|
135
|
+
var index = require('./util/index.js');
|
136
|
+
var declarativeTypeValidator = require('@twilio/declarative-type-validator');
|
137
|
+
var replayEventEmitter = require('@twilio/replay-event-emitter');
|
138
|
+
var isEqual = require('lodash.isequal');
|
139
|
+
|
140
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
141
|
+
|
142
|
+
var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
|
143
|
+
|
144
|
+
const log = logger.Logger.scope('User');
|
145
|
+
/**
|
146
|
+
* Extended user information.
|
147
|
+
* Note that `isOnline` and `isNotifiable` properties are eligible
|
148
|
+
* for use only if the reachability function is enabled.
|
149
|
+
* You may check if it is enabled by reading the value of {@link Client.reachabilityEnabled}.
|
150
|
+
*/
|
151
|
+
class User extends replayEventEmitter.ReplayEventEmitter {
|
152
|
+
/**
|
153
|
+
* @internal
|
154
|
+
*/
|
155
|
+
constructor(identity, entityName, configuration, services) {
|
156
|
+
super();
|
157
|
+
this.promiseToFetch = null;
|
158
|
+
/**
|
159
|
+
* Fired when the properties or the reachability status of the message has been updated.
|
160
|
+
*
|
161
|
+
* Parameters:
|
162
|
+
* 1. object `data` - info object provided with the event. It has the following properties:
|
163
|
+
* * {@link User} `user` - the user in question
|
164
|
+
* * {@link UserUpdateReason}[] `updateReasons` - array of reasons for the update
|
165
|
+
* @event
|
166
|
+
*/
|
167
|
+
this.updated = 'updated';
|
168
|
+
/**
|
169
|
+
* Fired when the client has subscribed to the user.
|
170
|
+
*
|
171
|
+
* Parameters:
|
172
|
+
* 1. {@link User} `user` - the user in question
|
173
|
+
* @event
|
174
|
+
*/
|
175
|
+
this.userSubscribed = 'userSubscribed';
|
176
|
+
/**
|
177
|
+
* Fired when the client has unsubscribed from the user.
|
178
|
+
*
|
179
|
+
* Parameters:
|
180
|
+
* 1. {@link User} `user` - the user in question
|
181
|
+
* @event
|
182
|
+
*/
|
183
|
+
this.userUnsubscribed = 'userUnsubscribed';
|
184
|
+
this.services = services;
|
185
|
+
this.subscribed = 'initializing';
|
186
|
+
this.setMaxListeners(0);
|
187
|
+
this.state = {
|
188
|
+
identity,
|
189
|
+
entityName,
|
190
|
+
friendlyName: null,
|
191
|
+
attributes: {},
|
192
|
+
online: null,
|
193
|
+
notifiable: null
|
194
|
+
};
|
195
|
+
this._initializationPromise = new Promise((resolve) => {
|
196
|
+
this._resolveInitializationPromise = resolve;
|
197
|
+
});
|
198
|
+
if (configuration !== null) {
|
199
|
+
this._resolveInitialization(configuration, identity, entityName, false);
|
200
|
+
}
|
201
|
+
}
|
202
|
+
/**
|
203
|
+
* User identity.
|
204
|
+
*/
|
205
|
+
get identity() { return this.state.identity; }
|
206
|
+
set identity(identity) { this.state.identity = identity; }
|
207
|
+
set entityName(name) { this.state.entityName = name; }
|
208
|
+
/**
|
209
|
+
* Custom attributes of the user.
|
210
|
+
*/
|
211
|
+
get attributes() { return this.state.attributes; }
|
212
|
+
/**
|
213
|
+
* Friendly name of the user, null if not set.
|
214
|
+
*/
|
215
|
+
get friendlyName() { return this.state.friendlyName; }
|
216
|
+
/**
|
217
|
+
* Status of the real-time conversation connection of the user.
|
218
|
+
*/
|
219
|
+
get isOnline() { return this.state.online; }
|
220
|
+
/**
|
221
|
+
* User push notification registration status.
|
222
|
+
*/
|
223
|
+
get isNotifiable() { return this.state.notifiable; }
|
224
|
+
/**
|
225
|
+
* True if this user is receiving real-time status updates.
|
226
|
+
*/
|
227
|
+
get isSubscribed() { return this.subscribed == 'subscribed'; }
|
228
|
+
// Handles service updates
|
229
|
+
async _update(key, value) {
|
230
|
+
await this._initializationPromise;
|
231
|
+
let updateReasons = [];
|
232
|
+
log.debug('User for', this.state.identity, 'updated:', key, value);
|
233
|
+
switch (key) {
|
234
|
+
case 'friendlyName':
|
235
|
+
if (this.state.friendlyName !== value.value) {
|
236
|
+
updateReasons.push('friendlyName');
|
237
|
+
this.state.friendlyName = value.value;
|
238
|
+
}
|
239
|
+
break;
|
240
|
+
case 'attributes':
|
241
|
+
const updateAttributes = index.parseAttributes(value.value, `Retrieved malformed attributes from the server for user: ${this.state.identity}`, log);
|
242
|
+
if (!isEqual__default['default'](this.state.attributes, updateAttributes)) {
|
243
|
+
this.state.attributes = updateAttributes;
|
244
|
+
updateReasons.push('attributes');
|
245
|
+
}
|
246
|
+
break;
|
247
|
+
case 'reachability':
|
248
|
+
if (this.state.online !== value.online) {
|
249
|
+
this.state.online = value.online;
|
250
|
+
updateReasons.push('reachabilityOnline');
|
251
|
+
}
|
252
|
+
if (this.state.notifiable !== value.notifiable) {
|
253
|
+
this.state.notifiable = value.notifiable;
|
254
|
+
updateReasons.push('reachabilityNotifiable');
|
255
|
+
}
|
256
|
+
break;
|
257
|
+
default:
|
258
|
+
return;
|
259
|
+
}
|
260
|
+
if (updateReasons.length > 0) {
|
261
|
+
this.emit('updated', { user: this, updateReasons: updateReasons });
|
262
|
+
}
|
263
|
+
}
|
264
|
+
// Fetch reachability info
|
265
|
+
async _updateReachabilityInfo(map, update) {
|
266
|
+
await this._initializationPromise;
|
267
|
+
if (!this.configuration.reachabilityEnabled) {
|
268
|
+
return Promise.resolve();
|
269
|
+
}
|
270
|
+
return map.get('reachability')
|
271
|
+
.then(update)
|
272
|
+
.catch(err => { log.warn('Failed to get reachability info for ', this.state.identity, err); });
|
273
|
+
}
|
274
|
+
// Fetch user
|
275
|
+
async _fetch() {
|
276
|
+
await this._initializationPromise;
|
277
|
+
if (!this.state.entityName) {
|
278
|
+
return this;
|
279
|
+
}
|
280
|
+
this.promiseToFetch = this.services.syncClient.map({
|
281
|
+
id: this.state.entityName,
|
282
|
+
mode: 'open_existing',
|
283
|
+
includeItems: true
|
284
|
+
})
|
285
|
+
.then(map => {
|
286
|
+
this.entity = map;
|
287
|
+
map.on('itemUpdated', args => {
|
288
|
+
log.debug(this.state.entityName + ' (' + this.state.identity + ') itemUpdated: ' + args.item.key);
|
289
|
+
return this._update(args.item.key, args.item.data);
|
290
|
+
});
|
291
|
+
return Promise.all([
|
292
|
+
map.get('friendlyName')
|
293
|
+
.then(item => this._update(item.key, item.data)),
|
294
|
+
map.get('attributes')
|
295
|
+
.then(item => this._update(item.key, item.data)),
|
296
|
+
this._updateReachabilityInfo(map, item => this._update(item.key, item.data))
|
297
|
+
]);
|
298
|
+
})
|
299
|
+
.then(() => {
|
300
|
+
log.debug('Fetched for', this.identity);
|
301
|
+
this.subscribed = 'subscribed';
|
302
|
+
this.emit('userSubscribed', this);
|
303
|
+
return this;
|
304
|
+
})
|
305
|
+
.catch(err => {
|
306
|
+
this.promiseToFetch = null;
|
307
|
+
throw err;
|
308
|
+
});
|
309
|
+
return this.promiseToFetch;
|
310
|
+
}
|
311
|
+
async _ensureFetched() {
|
312
|
+
await this._initializationPromise;
|
313
|
+
return this.promiseToFetch || this._fetch();
|
314
|
+
}
|
315
|
+
/**
|
316
|
+
* Edit user attributes.
|
317
|
+
* @param attributes New attributes.
|
318
|
+
*/
|
319
|
+
async updateAttributes(attributes) {
|
320
|
+
await this._initializationPromise;
|
321
|
+
if (this.subscribed == 'unsubscribed') {
|
322
|
+
throw new Error('Can\'t modify unsubscribed object');
|
323
|
+
}
|
324
|
+
await this.services.commandExecutor.mutateResource('post', this.links.self, {
|
325
|
+
attributes: JSON.stringify(attributes)
|
326
|
+
});
|
327
|
+
return this;
|
328
|
+
}
|
329
|
+
/**
|
330
|
+
* Update the friendly name of the user.
|
331
|
+
* @param friendlyName New friendly name.
|
332
|
+
*/
|
333
|
+
async updateFriendlyName(friendlyName) {
|
334
|
+
await this._initializationPromise;
|
335
|
+
if (this.subscribed == 'unsubscribed') {
|
336
|
+
throw new Error('Can\'t modify unsubscribed object');
|
337
|
+
}
|
338
|
+
await this.services.commandExecutor.mutateResource('post', this.links.self, {
|
339
|
+
friendly_name: friendlyName
|
340
|
+
});
|
341
|
+
return this;
|
342
|
+
}
|
343
|
+
/**
|
344
|
+
* Remove the user from the subscription list.
|
345
|
+
* @return A promise of completion.
|
346
|
+
*/
|
347
|
+
async unsubscribe() {
|
348
|
+
await this._initializationPromise;
|
349
|
+
if (this.promiseToFetch) {
|
350
|
+
await this.promiseToFetch;
|
351
|
+
this.entity.close();
|
352
|
+
this.promiseToFetch = null;
|
353
|
+
this.subscribed = 'unsubscribed';
|
354
|
+
this.emit('userUnsubscribed', this);
|
355
|
+
}
|
356
|
+
}
|
357
|
+
_resolveInitialization(configuration, identity, entityName, emitUpdated) {
|
358
|
+
this.configuration = configuration;
|
359
|
+
this.identity = identity;
|
360
|
+
this.entityName = entityName;
|
361
|
+
this.links = {
|
362
|
+
self: `${this.configuration.links.users}/${this.identity}`
|
363
|
+
};
|
364
|
+
this._resolveInitializationPromise();
|
365
|
+
if (emitUpdated) {
|
366
|
+
this.emit('updated', {
|
367
|
+
user: this,
|
368
|
+
updateReasons: [
|
369
|
+
'friendlyName',
|
370
|
+
'attributes',
|
371
|
+
'reachabilityOnline',
|
372
|
+
'reachabilityNotifiable'
|
373
|
+
]
|
374
|
+
});
|
375
|
+
}
|
376
|
+
}
|
377
|
+
}
|
378
|
+
tslib_es6.__decorate([
|
379
|
+
declarativeTypeValidator.validateTypesAsync(['string', 'number', 'boolean', 'object', declarativeTypeValidator.literal(null)]),
|
380
|
+
tslib_es6.__metadata("design:type", Function),
|
381
|
+
tslib_es6.__metadata("design:paramtypes", [Object]),
|
382
|
+
tslib_es6.__metadata("design:returntype", Promise)
|
383
|
+
], User.prototype, "updateAttributes", null);
|
384
|
+
tslib_es6.__decorate([
|
385
|
+
declarativeTypeValidator.validateTypesAsync(['string']),
|
386
|
+
tslib_es6.__metadata("design:type", Function),
|
387
|
+
tslib_es6.__metadata("design:paramtypes", [String]),
|
388
|
+
tslib_es6.__metadata("design:returntype", Promise)
|
389
|
+
], User.prototype, "updateFriendlyName", null);
|
390
|
+
|
391
|
+
exports.User = User;
|
392
|
+
//# sourceMappingURL=user.js.map
|
package/dist/user.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"user.js","sources":["../src/user.ts"],"sourcesContent":["import { Logger } from './logger';\nimport { SyncClient } from 'twilio-sync';\nimport { parseAttributes } from './util';\nimport { validateTypesAsync, literal } from '@twilio/declarative-type-validator';\nimport { Configuration } from './configuration';\nimport { CommandExecutor } from './command-executor';\nimport { EditUserRequest, EditUserResponse } from './interfaces/commands/edit-user';\nimport { ReplayEventEmitter } from '@twilio/replay-event-emitter';\nimport isEqual from 'lodash.isequal';\n\ntype UserEvents = {\n updated: (data: {\n user: User,\n updateReasons: UserUpdateReason[]\n }) => void;\n userSubscribed: (user: User) => void;\n userUnsubscribed: (user: User) => void;\n};\n\nconst log = Logger.scope('User');\n\ninterface UserState {\n identity: string;\n entityName: string;\n friendlyName: string;\n attributes: any;\n online: boolean;\n notifiable: boolean;\n}\n\ninterface UserServices {\n syncClient: SyncClient;\n commandExecutor: CommandExecutor;\n}\n\ninterface UserLinks {\n self: string;\n}\n\ntype SubscriptionState = 'initializing' | 'subscribed' | 'unsubscribed';\n\n/**\n * The reason for the `updated` event being emitted by a user.\n */\ntype UserUpdateReason =\n | 'friendlyName'\n | 'attributes'\n | 'reachabilityOnline'\n | 'reachabilityNotifiable';\n\ninterface UserUpdatedEventArgs {\n user: User;\n updateReasons: UserUpdateReason[];\n}\n\n/**\n * Extended user information.\n * Note that `isOnline` and `isNotifiable` properties are eligible\n * for use only if the reachability function is enabled.\n * You may check if it is enabled by reading the value of {@link Client.reachabilityEnabled}.\n */\nclass User extends ReplayEventEmitter<UserEvents> {\n private links: UserLinks;\n private configuration: Configuration;\n private readonly services: UserServices;\n\n private entity: any;\n private state: UserState;\n private promiseToFetch: Promise<User> | null = null;\n private subscribed: SubscriptionState;\n\n private _initializationPromise: Promise<void>;\n private _resolveInitializationPromise: any;\n\n /**\n * @internal\n */\n constructor(\n identity: string,\n entityName: string,\n configuration: Configuration | null,\n services: UserServices\n ) {\n super();\n\n this.services = services;\n\n this.subscribed = 'initializing';\n this.setMaxListeners(0);\n\n this.state = {\n identity,\n entityName,\n friendlyName: null,\n attributes: {},\n online: null,\n notifiable: null\n };\n\n this._initializationPromise = new Promise((resolve) => {\n this._resolveInitializationPromise = resolve;\n });\n\n if (configuration !== null) {\n this._resolveInitialization(\n configuration,\n identity,\n entityName,\n false\n );\n }\n }\n\n /**\n * Fired when the properties or the reachability status of the message has been updated.\n *\n * Parameters:\n * 1. object `data` - info object provided with the event. It has the following properties:\n * * {@link User} `user` - the user in question\n * * {@link UserUpdateReason}[] `updateReasons` - array of reasons for the update\n * @event\n */\n public readonly updated = 'updated';\n\n /**\n * Fired when the client has subscribed to the user.\n *\n * Parameters:\n * 1. {@link User} `user` - the user in question\n * @event\n */\n public readonly userSubscribed = 'userSubscribed';\n\n /**\n * Fired when the client has unsubscribed from the user.\n *\n * Parameters:\n * 1. {@link User} `user` - the user in question\n * @event\n */\n public readonly userUnsubscribed = 'userUnsubscribed';\n\n /**\n * User identity.\n */\n public get identity(): string { return this.state.identity; }\n\n public set identity(identity: string) { this.state.identity = identity; }\n\n public set entityName(name: string) { this.state.entityName = name; }\n\n /**\n * Custom attributes of the user.\n */\n public get attributes() { return this.state.attributes; }\n\n /**\n * Friendly name of the user, null if not set.\n */\n public get friendlyName(): string { return this.state.friendlyName; }\n\n /**\n * Status of the real-time conversation connection of the user.\n */\n public get isOnline(): boolean { return this.state.online; }\n\n /**\n * User push notification registration status.\n */\n public get isNotifiable(): boolean { return this.state.notifiable; }\n\n /**\n * True if this user is receiving real-time status updates.\n */\n public get isSubscribed(): boolean { return this.subscribed == 'subscribed'; }\n\n // Handles service updates\n async _update(key: string, value: any) {\n await this._initializationPromise;\n\n let updateReasons: UserUpdateReason[] = [];\n log.debug('User for', this.state.identity, 'updated:', key, value);\n switch (key) {\n case 'friendlyName':\n if (this.state.friendlyName !== value.value) {\n updateReasons.push('friendlyName');\n this.state.friendlyName = value.value;\n }\n break;\n case 'attributes':\n const updateAttributes = parseAttributes(value.value, `Retrieved malformed attributes from the server for user: ${this.state.identity}`, log);\n if (!isEqual(this.state.attributes, updateAttributes)) {\n this.state.attributes = updateAttributes;\n updateReasons.push('attributes');\n }\n break;\n case 'reachability':\n if (this.state.online !== value.online) {\n this.state.online = value.online;\n updateReasons.push('reachabilityOnline');\n }\n if (this.state.notifiable !== value.notifiable) {\n this.state.notifiable = value.notifiable;\n updateReasons.push('reachabilityNotifiable');\n }\n break;\n default:\n return;\n }\n if (updateReasons.length > 0) {\n this.emit('updated', { user: this, updateReasons: updateReasons });\n }\n }\n\n // Fetch reachability info\n private async _updateReachabilityInfo(map, update) {\n await this._initializationPromise;\n\n if (!this.configuration.reachabilityEnabled) {\n return Promise.resolve();\n }\n\n return map.get('reachability')\n .then(update)\n .catch(err => { log.warn('Failed to get reachability info for ', this.state.identity, err); });\n }\n\n // Fetch user\n async _fetch(): Promise<User> {\n await this._initializationPromise;\n\n if (!this.state.entityName) {\n return this;\n }\n\n this.promiseToFetch = this.services.syncClient.map({\n id: this.state.entityName,\n mode: 'open_existing',\n includeItems: true\n })\n .then(map => {\n this.entity = map;\n map.on('itemUpdated', args => {\n log.debug(this.state.entityName + ' (' + this.state.identity + ') itemUpdated: ' + args.item.key);\n return this._update(args.item.key, args.item.data);\n });\n return Promise.all([\n map.get('friendlyName')\n .then(item => this._update(item.key, item.data)),\n map.get('attributes')\n .then(item => this._update(item.key, item.data)),\n this._updateReachabilityInfo(map,\n item => this._update(item.key, item.data))\n ]);\n })\n .then(() => {\n log.debug('Fetched for', this.identity);\n this.subscribed = 'subscribed';\n this.emit('userSubscribed', this);\n return this;\n })\n .catch(err => {\n this.promiseToFetch = null;\n throw err;\n });\n return this.promiseToFetch;\n }\n\n async _ensureFetched() {\n await this._initializationPromise;\n return this.promiseToFetch || this._fetch();\n }\n\n /**\n * Edit user attributes.\n * @param attributes New attributes.\n */\n @validateTypesAsync(['string', 'number', 'boolean', 'object', literal(null)])\n public async updateAttributes(attributes: any): Promise<User> {\n await this._initializationPromise;\n\n if (this.subscribed == 'unsubscribed') {\n throw new Error('Can\\'t modify unsubscribed object');\n }\n\n await this.services.commandExecutor.mutateResource<EditUserRequest, EditUserResponse>(\n 'post',\n this.links.self,\n {\n attributes: JSON.stringify(attributes)\n }\n );\n\n return this;\n }\n\n /**\n * Update the friendly name of the user.\n * @param friendlyName New friendly name.\n */\n @validateTypesAsync(['string'])\n public async updateFriendlyName(friendlyName: string): Promise<User> {\n await this._initializationPromise;\n\n if (this.subscribed == 'unsubscribed') {\n throw new Error('Can\\'t modify unsubscribed object');\n }\n\n await this.services.commandExecutor.mutateResource<EditUserRequest, EditUserResponse>(\n 'post',\n this.links.self,\n {\n friendly_name: friendlyName\n }\n );\n\n return this;\n }\n\n /**\n * Remove the user from the subscription list.\n * @return A promise of completion.\n */\n async unsubscribe(): Promise<void> {\n await this._initializationPromise;\n\n if (this.promiseToFetch) {\n await this.promiseToFetch;\n this.entity.close();\n this.promiseToFetch = null;\n this.subscribed = 'unsubscribed';\n this.emit('userUnsubscribed', this);\n }\n }\n\n public _resolveInitialization(\n configuration: Configuration,\n identity: string,\n entityName: string,\n emitUpdated: boolean\n ): void {\n this.configuration = configuration;\n this.identity = identity;\n this.entityName = entityName;\n this.links = {\n self: `${this.configuration.links.users}/${this.identity}`\n };\n this._resolveInitializationPromise();\n\n if (emitUpdated) {\n this.emit('updated', {\n user: this,\n updateReasons: [\n 'friendlyName',\n 'attributes',\n 'reachabilityOnline',\n 'reachabilityNotifiable'\n ]\n });\n }\n }\n}\n\nexport {\n User,\n UserServices,\n SubscriptionState,\n UserUpdateReason,\n User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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
|
+
class Deferred {
|
134
|
+
constructor() {
|
135
|
+
this._promise = new Promise((resolve, reject) => {
|
136
|
+
this._resolve = resolve;
|
137
|
+
this._reject = reject;
|
138
|
+
});
|
139
|
+
}
|
140
|
+
get promise() { return this._promise; }
|
141
|
+
update(value) {
|
142
|
+
this._resolve(value);
|
143
|
+
}
|
144
|
+
set(value) {
|
145
|
+
this.current = value;
|
146
|
+
this._resolve(value);
|
147
|
+
}
|
148
|
+
fail(e) {
|
149
|
+
this._reject(e);
|
150
|
+
}
|
151
|
+
}
|
152
|
+
|
153
|
+
exports.Deferred = Deferred;
|
154
|
+
//# sourceMappingURL=deferred.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"deferred.js","sources":["../../src/util/deferred.ts"],"sourcesContent":["class Deferred<T> {\n private _promise: Promise<T>;\n private _resolve;\n private _reject;\n\n public current: T;\n\n constructor() {\n this._promise = new Promise<T>((resolve, reject) => {\n this._resolve = resolve;\n this._reject = reject;\n });\n }\n\n public get promise(): Promise<T> { return this._promise; }\n\n update(value: T) {\n this._resolve(value);\n }\n\n set(value: T) {\n this.current = value;\n this._resolve(value);\n }\n\n fail(e) {\n this._reject(e);\n }\n}\n\nexport { Deferred };\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAM,QAAQ;IAOZ;QACE,IAAI,CAAC,QAAQ,GAAG,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM;YAC7C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;YACxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;SACvB,CAAC,CAAC;KACJ;IAED,IAAW,OAAO,KAAiB,OAAO,IAAI,CAAC,QAAQ,CAAC,EAAE;IAE1D,MAAM,CAAC,KAAQ;QACb,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;KACtB;IAED,GAAG,CAAC,KAAQ;QACV,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;KACtB;IAED,IAAI,CAAC,CAAC;QACJ,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;KACjB;;;;;"}
|