@twilio/conversations 2.1.0-rc.5 → 2.1.0-rc.6
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 +9 -0
- package/builds/browser.js +3 -5
- package/builds/browser.js.map +1 -1
- package/builds/lib.d.ts +15 -6
- package/builds/lib.js +3 -5
- package/builds/lib.js.map +1 -1
- package/builds/twilio-conversations.js +3 -5
- package/builds/twilio-conversations.min.js +1 -1
- package/dist/configuration.js.map +1 -1
- package/dist/conversation.js.map +1 -1
- package/dist/message-builder.js.map +1 -1
- package/dist/message.js +2 -3
- package/dist/message.js.map +1 -1
- package/dist/packages/conversations/package.json.js +1 -1
- package/docs/assets/js/search.js +1 -1
- package/docs/classes/AggregatedDeliveryReceipt.html +0 -117
- package/docs/classes/Client.html +0 -117
- package/docs/classes/Conversation.html +12 -129
- package/docs/classes/DetailedDeliveryReceipt.html +0 -117
- package/docs/classes/Media.html +0 -117
- package/docs/classes/Message.html +4 -121
- package/docs/classes/MessageBuilder.html +2 -119
- package/docs/classes/Participant.html +4 -121
- package/docs/classes/PushNotification.html +0 -117
- package/docs/classes/RestPaginator.html +0 -117
- package/docs/classes/UnsentMessage.html +0 -117
- package/docs/classes/User.html +4 -121
- package/docs/index.html +56 -0
- package/docs/interfaces/ClientOptions.html +0 -117
- package/docs/interfaces/ConversationBindings.html +0 -117
- package/docs/interfaces/ConversationEmailBinding.html +0 -117
- package/docs/interfaces/ConversationState.html +0 -117
- package/docs/interfaces/CreateConversationOptions.html +1 -118
- package/docs/interfaces/LastMessage.html +0 -117
- package/docs/interfaces/Paginator.html +0 -117
- package/docs/interfaces/ParticipantBindings.html +0 -117
- package/docs/interfaces/ParticipantEmailBinding.html +0 -117
- package/docs/interfaces/PushNotificationData.html +0 -117
- package/docs/interfaces/SendEmailOptions.html +0 -117
- package/docs/interfaces/SendMediaOptions.html +0 -117
- package/docs/modules.html +56 -0
- package/package.json +1 -1
@@ -141,4 +141,4 @@ this.Twilio=this.Twilio||{},this.Twilio.Conversations=function(e){"use strict";v
|
|
141
141
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
142
142
|
PERFORMANCE OF THIS SOFTWARE.
|
143
143
|
***************************************************************************** */
|
144
|
-
function h(e,t,n,r){var i,a=arguments.length,s=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":Ca(Reflect))&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(s=(a<3?i(s):a>3?i(t,n,s):i(t,n))||s);return a>3&&s&&Object.defineProperty(t,n,s),s}function v(e,t){if("object"===("undefined"==typeof Reflect?"undefined":Ca(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function y(e,t){return["".concat((new Date).toISOString()," MCS Client ").concat(e,":")].concat(Array.from(t))}var m=function(){function e(t){Ma(this,e),f.default(this,"prefix",""),this.prefix=null!=t&&t.length>0?t+" ":""}return Ta(e,[{key:"setLevel",value:function(e){p.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.trace.apply(null,y(this.prefix+"T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.debug.apply(null,y(this.prefix+"D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.info.apply(null,y(this.prefix+"I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.warn.apply(null,y(this.prefix+"W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.error.apply(null,y(this.prefix+"E",t))}}],[{key:"scope",value:function(t){return new e(t)}},{key:"setLevel",value:function(e){p.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.trace.apply(null,y("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.debug.apply(null,y("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.info.apply(null,y("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.warn.apply(null,y("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.error.apply(null,y("E",t))}}]),e}(),g=function(e,t){return"".concat((n=e,n.startsWith("http")?"":function(e){return"https://mcs.".concat(null!=e?e:"us1",".twilio.com")}(t))).concat(e);var n},b=function(){function e(t,n,r,i){var a,s,o,u,c,l;Ma(this,e);var f=null!==(a=null!==(s=i.MCS)&&void 0!==s?s:i)&&void 0!==a?a:{};this.region=null!==(o=null!==(u=f.region)&&void 0!==u?u:i.region)&&void 0!==o?o:"us1",this.mediaUrl=g(n,this.region),this.mediaSetUrl=r?g(r):"".concat(this.mediaUrl,"Set"),this.token=t,this.retryWhenThrottledOverride=null===(c=f.retryWhenThrottledOverride)||void 0===c||c,this.backoffConfigOverride=null!==(l=f.backoffConfigOverride)&&void 0!==l?l:e.backoffConfigDefault}return Ta(e,[{key:"updateToken",value:function(e){this.token=e}}],[{key:"backoffConfigDefault",get:function(){return{min:1e3,max:4e3,maxAttemptsCount:3}}},{key:"retryWhenThrottledDefault",get:function(){return true}}]),e}(),Media=function(){function Media(e,t,n){Ma(this,Media),this.config=e,this.network=t,this._update(n)}return Ta(Media,[{key:"sid",get:function(){return this.state.sid}},{key:"serviceSid",get:function(){return this.state.serviceSid}},{key:"dateCreated",get:function(){return this.state.dateCreated}},{key:"dateUpdated",get:function(){return this.state.dateUpdated}},{key:"contentType",get:function(){return this.state.contentType}},{key:"size",get:function(){return this.state.size}},{key:"fileName",get:function(){return this.state.filename}},{key:"filename",get:function(){return this.state.filename}},{key:"category",get:function(){return this.state.category}},{key:"getContentUrl",value:function(){var e=this;return l.default(d.default.mark((function t(){var n;return d.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.network.get("".concat(e.config.mediaUrl,"/").concat(e.sid));case 2:return n=t.sent,e._update(n.body),t.abrupt("return",Promise.resolve(e.state.contentDirectUrl));case 5:case"end":return t.stop()}}),t)})))()}},{key:"getCachedContentUrl",value:function(){var e=this;return l.default(d.default.mark((function t(){return d.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!e.state.contentDirectUrl){t.next=2;break}return t.abrupt("return",Promise.resolve(e.state.contentDirectUrl));case 2:return t.next=4,e.getContentUrl();case 4:return t.abrupt("return",t.sent);case 5:case"end":return t.stop()}}),t)})))()}},{key:"_update",value:function(e){var t,n,r,i;this.state={sid:e.sid,serviceSid:e.service_sid,channelSid:e.channel_sid,messageSid:e.message_sid,dateCreated:e.date_created?new Date(e.date_created):null,dateUploadUpdated:e.date_upload_updated?new Date(e.date_upload_updated):null,dateUpdated:e.date_updated?new Date(e.date_updated):null,size:e.size,contentType:e.content_type,author:e.author,url:e.url,contentUrl:e.links.content,contentDirectUrl:null!==(t=e.links.content_direct_temporary)&&void 0!==t?t:null,filename:null!==(n=e.filename)&&void 0!==n?n:null,category:null!==(r=e.category)&&void 0!==r?r:"media",isMultipartUpstream:null!==(i=e.is_multipart_upstream)&&void 0!==i&&i}}}]),Media}(),k=function(e){Oa(n,e);var t=tP(n);function n(e,r,i,a,s){var o;return Ma(this,n),(o=t.call(this,e)).code=r,o.body=i,o.status=a,o.headers=s,o}return n}(WR(Error)),w=t.XMLHttpRequest||{};function x(e){var t=e.getResponseHeader("Content-Type");if(!t||0!==t.indexOf("application/json")||0===e.responseText.length)return e.responseText;try{return JSON.parse(e.responseText)}catch(t){return e.responseText}}var _,S,E=function(){function e(){Ma(this,e)}return Ta(e,[{key:"get",value:function(t,n){return l.default(d.default.mark((function r(){return d.default.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",e.request("GET",t,n));case 1:case"end":return r.stop()}}),r)})))()}},{key:"post",value:function(t,n,r){return l.default(d.default.mark((function i(){return d.default.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return i.abrupt("return",e.request("POST",t,n,r));case 1:case"end":return i.stop()}}),i)})))()}}],[{key:"request",value:function(e,t,n,r){return l.default(d.default.mark((function i(){return d.default.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return i.abrupt("return",new Promise((function(i,a){var s=new w;for(var o in s.open(e,t,!0),s.onreadystatechange=function(){if(4===s.readyState){var e,t=(e=s.getAllResponseHeaders())?e.split("\r\n").map((function(e){return e.split(": ")})).filter((function(e){return 2===e.length&&e[1].length>0})).reduce((function(e,t){return e[t[0]]=t[1],e}),{}):{},n=x(s);if(200<=s.status&&s.status<300)i({status:s.status,headers:t,body:n});else{var r,o,u=null!==(r=s.statusText)&&void 0!==r?r:"NONE";o="string"==typeof n?n&&1===n.split("\n",2).length?n:"":JSON.stringify(n);var c="".concat(s.status,": [").concat(u,"] ").concat(o);a(new k(c,s.status,n,u,t))}}},n)s.setRequestHeader(o,n[o]),"Content-Type"===o&&"application/json"===n[o]&&(r=JSON.stringify(r));s.send(r)})));case 1:case"end":return i.stop()}}),i)})))()}}]),e}(),T=m.scope("Network"),R=function(){function e(t,n){Ma(this,e),this.config=t,this.transport=n}return Ta(e,[{key:"backoffConfig",value:function(){return Object.assign(b.backoffConfigDefault,this.config.backoffConfigOverride)}},{key:"retryWhenThrottled",value:function(){var e,t;return null!==(e=null!==(t=this.config.retryWhenThrottledOverride)&&void 0!==t?t:b.retryWhenThrottledDefault)&&void 0!==e&&e}},{key:"executeWithRetry",value:function(e,t){var n=this;return l.default(d.default.mark((function r(){return d.default.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",new Promise((function(r,i){var a=[502,503,504];t&&a.push(429);var o=new s.Retrier(n.backoffConfig());o.on("attempt",l.default(d.default.mark((function t(){var n;return d.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,e();case 3:n=t.sent,o.succeeded(n),t.next=10;break;case 7:t.prev=7,t.t0=t.catch(0),a.indexOf(t.t0.status)>-1||"Twilsock disconnected"===t.t0.message?o.failed(t.t0):(o.removeAllListeners(),o.cancel(),i(t.t0));case 10:case"end":return t.stop()}}),t,null,[[0,7]])})))),o.on("succeeded",(function(e){r(e)})),o.on("cancelled",(function(e){return i(e)})),o.on("failed",(function(e){return i(e)})),o.start()})));case 1:case"end":return r.stop()}}),r)})))()}},{key:"get",value:function(e){var t=this;return l.default(d.default.mark((function n(){var r,i;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return r={"X-Twilio-Token":t.config.token},T.trace("sending GET request to ",e," headers ",r),n.prev=2,n.next=5,t.executeWithRetry((function(){return t.transport.get(e,r)}),t.retryWhenThrottled());case 5:return i=n.sent,T.trace("response",i),n.abrupt("return",i);case 10:throw n.prev=10,n.t0=n.catch(2),T.debug("get() error ".concat(n.t0)),n.t0;case 14:case"end":return n.stop()}}),n,null,[[2,10]])})))()}},{key:"post",value:function(e,n,r,i,a){var s=this;return l.default(d.default.mark((function o(){var u,c,l;return d.default.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return u={"X-Twilio-Token":s.config.token},"undefined"!=typeof FormData&&r instanceof FormData||!i||Object.assign(u,{"Content-Type":i}),c=new URL(e),n&&c.searchParams.append("Category",n),a&&c.searchParams.append("Filename",a),T.trace("sending POST request to ".concat(e," with headers ").concat(u)),o.prev=6,o.next=9,s.transport.post(c.href,u,r);case 9:l=o.sent,o.next=18;break;case 12:if(o.prev=12,o.t0=o.catch(6),!(void 0===t.XMLHttpRequest&&r instanceof FormData)){o.next=16;break}throw new TypeError("Posting FormData supported only with browser engine's FormData");case 16:throw T.debug("post() error ".concat(o.t0)),o.t0;case 18:return T.trace("response",l),o.abrupt("return",l);case 20:case"end":return o.stop()}}),o,null,[[6,12]])})))()}}]),e}(),I=m.scope("");e.default=(S=_=function(){function Client(e,t,n){var r,i;Ma(this,Client);var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};this.options=a,this.options.logLevel=null!==(r=this.options.logLevel)&&void 0!==r?r:"silent",this.config=new b(e,t,n,this.options),I.setLevel(this.options.logLevel),this.options.transport=null!==(i=this.options.transport)&&void 0!==i?i:new E,this.transport=this.options.transport,this.network=new R(this.config,this.transport)}return Ta(Client,[{key:"updateToken",value:function(e){I.info("updateToken"),this.config.updateToken(e)}},{key:"get",value:function(e){var t=this;return l.default(d.default.mark((function n(){var r;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,t.network.get("".concat(t.config.mediaUrl,"/").concat(e));case 2:return r=n.sent,n.abrupt("return",new Media(t.config,t.network,r.body));case 4:case"end":return n.stop()}}),n)})))()}},{key:"post",value:function(e,t,n,r){var i=this;return l.default(d.default.mark((function a(){var s;return d.default.wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,i.network.post(i.config.mediaUrl,null!=n?n:"media",t,e,r);case 2:return s=a.sent,a.abrupt("return",new Media(i.config,i.network,s.body));case 4:case"end":return a.stop()}}),a)})))()}},{key:"postFormData",value:function(e,t){var n=this;return l.default(d.default.mark((function r(){var i;return d.default.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,n.network.post(n.config.mediaUrl,null!=t?t:"media",e);case 2:return i=r.sent,r.abrupt("return",new Media(n.config,n.network,i.body));case 4:case"end":return r.stop()}}),r)})))()}},{key:"mediaSetGet",value:function(e){var t=this;return l.default(d.default.mark((function n(){var r,i;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return r={command:"get",list:e.map((function(e){return{media_sid:e}}))},n.next=3,t.network.post("".concat(t.config.mediaSetUrl),null,r,"application/json");case 3:return i=n.sent,n.abrupt("return",i.body.map((function(e){if(200!==e.code)throw new Error("Failed to obtain detailed information about Media items (failed SID ".concat(e.media_record.sid,")"));return new Media(t.config,t.network,e.media_record)})));case 5:case"end":return n.stop()}}),n)})))()}}]),Client}(),f.default(_,"version","0.5.3-rc.0"),S),h([o.validateTypes(o.nonEmptyString),v("design:type",Function),v("design:paramtypes",[String]),v("design:returntype",void 0)],e.default.prototype,"updateToken",null),h([o.validateTypesAsync(o.nonEmptyString),v("design:type",Function),v("design:paramtypes",[String]),v("design:returntype",Promise)],e.default.prototype,"get",null),e.default=h([o.validateConstructorTypes(o.nonEmptyString,o.nonEmptyString,[o.nonEmptyString,o.literal(null)],[o.pureObject,"undefined"]),v("design:paramtypes",[String,String,Object,Object])],e.default),e.Client=e.default,e.McsClient=e.default,e.McsMedia=Media,e.Media=Media,e.default=e.default}($R);var rP=is,iP="ArrayBuffer",aP=Gk.ArrayBuffer;function sP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}In({global:!0,forced:i.ArrayBuffer!==aP},{ArrayBuffer:aP}),rP(iP);var oP=rd.scope("Participant"),Participant=function(e){Oa(Participant,e);var t,n,r,i=sP(Participant);function Participant(e,t,n,r,a){var s,o,u;if(Ma(this,Participant),(u=i.call(this)).conversation=n,u.links=r,u.services=a,u.state={attributes:nh(e.attributes,"Retrieved malformed attributes from the server for participant: "+t,oP),dateCreated:e.dateCreated?th(e.dateCreated):null,dateUpdated:e.dateCreated?th(e.dateUpdated):null,sid:t,typingTimeout:null,isTyping:!1,identity:e.identity,roleSid:null!==(s=e.roleSid)&&void 0!==s?s:"",lastReadMessageIndex:Number.isInteger(e.lastConsumedMessageIndex)?e.lastConsumedMessageIndex:null,lastReadTimestamp:e.lastConsumptionTimestamp?th(e.lastConsumptionTimestamp):null,type:e.type||"chat",userInfo:e.userInfo,bindings:null!==(o=e.bindings)&&void 0!==o?o:{}},!e.identity&&!e.type)throw new Error("Received invalid Participant object from server: Missing identity or type of Participant.");return u}return Ta(Participant,[{key:"sid",get:function(){return this.state.sid}},{key:"attributes",get:function(){return this.state.attributes}},{key:"dateCreated",get:function(){return this.state.dateCreated}},{key:"dateUpdated",get:function(){return this.state.dateUpdated}},{key:"identity",get:function(){return this.state.identity}},{key:"isTyping",get:function(){return this.state.isTyping}},{key:"lastReadMessageIndex",get:function(){return this.state.lastReadMessageIndex}},{key:"lastReadTimestamp",get:function(){return this.state.lastReadTimestamp}},{key:"roleSid",get:function(){return this.state.roleSid}},{key:"type",get:function(){return this.state.type}},{key:"bindings",get:function(){var e;return null!==(e=this.state.bindings)&&void 0!==e?e:{}}},{key:"_startTyping",value:function(e){var t=this;return this.state.typingTimeout&&clearTimeout(this.state.typingTimeout),this.state.isTyping=!0,this.emit("typingStarted",this),this.conversation.emit("typingStarted",this),this.state.typingTimeout=Number(setTimeout((function(){return t._endTyping()}),e)),this}},{key:"_endTyping",value:function(){this.state.typingTimeout&&(this.state.isTyping=!1,this.emit("typingEnded",this),this.conversation.emit("typingEnded",this),clearInterval(this.state.typingTimeout),this.state.typingTimeout=null)}},{key:"_update",value:function(e){var t=[],n=nh(e.attributes,"Retrieved malformed attributes from the server for participant: "+this.state.sid,oP);e.attributes&&!By(this.state.attributes,n)&&(this.state.attributes=n,t.push("attributes"));var r=th(e.dateUpdated);e.dateUpdated&&(null==r?void 0:r.getTime())!==(this.state.dateUpdated&&this.state.dateUpdated.getTime())&&(this.state.dateUpdated=r,t.push("dateUpdated"));var i=th(e.dateCreated);if(e.dateCreated&&(null==i?void 0:i.getTime())!==(this.state.dateCreated&&this.state.dateCreated.getTime())&&(this.state.dateCreated=i,t.push("dateCreated")),e.roleSid&&this.state.roleSid!==e.roleSid&&(this.state.roleSid=e.roleSid,t.push("roleSid")),!Number.isInteger(e.lastConsumedMessageIndex)&&null!==e.lastConsumedMessageIndex||this.state.lastReadMessageIndex===e.lastConsumedMessageIndex||(this.state.lastReadMessageIndex=e.lastConsumedMessageIndex,t.push("lastReadMessageIndex")),e.lastConsumptionTimestamp){var a=new Date(e.lastConsumptionTimestamp);this.state.lastReadTimestamp&&this.state.lastReadTimestamp.getTime()===a.getTime()||(this.state.lastReadTimestamp=a,t.push("lastReadTimestamp"))}return e.bindings&&!By(this.state.bindings,e.bindings)&&(this.state.bindings=e.bindings,t.push("bindings")),t.length>0&&this.emit("updated",{participant:this,updateReasons:t}),this}},{key:"getUser",value:(r=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("chat"==this.type){e.next=2;break}throw new Error("Getting User is not supported for this Participant type: "+this.type);case 2:return e.abrupt("return",this.services.users.getUser(this.state.identity,this.state.userInfo));case 3:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"remove",value:(n=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.conversation.removeParticipant(this));case 1:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"updateAttributes",value:(t=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{attributes:JSON.stringify(t)});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),Participant}(Dy);function uP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}ja(Participant,"typingStarted","typingStarted"),ja(Participant,"typingEnded","typingEnded"),ja(Participant,"updated","updated"),wl([Xv(Zv),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],Participant.prototype,"updateAttributes",null);var cP=rd.scope("Participants"),lP=function(e){Oa(u,e);var t,n,r,i,a,s,o=uP(u);function u(e,t,n,r,i){var a;return Ma(this,u),ja(Ra(a=o.call(this)),"rosterEntityPromise",null),a.conversation=e,a.participants=t,a.links=n,a.configuration=r,a.services=i,a}return Ta(u,[{key:"unsubscribe",value:(s=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.rosterEntityPromise){e.next=6;break}return e.next=3,this.rosterEntityPromise;case 3:e.sent.close(),this.rosterEntityPromise=null;case 6:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"subscribe",value:function(e){var t=this;return this.rosterEntityPromise=this.rosterEntityPromise||this.services.syncClient.map({id:e,mode:"open_existing"}).then((function(e){e.on("itemAdded",(function(e){cP.debug(t.conversation.sid+" itemAdded: "+e.item.key),t.upsertParticipant(e.item.key,e.item.data).then((function(e){t.emit("participantJoined",e)}))})),e.on("itemRemoved",(function(e){cP.debug(t.conversation.sid+" itemRemoved: "+e.key);var n=e.key;if(t.participants.has(n)){var r=t.participants.get(n);t.participants.delete(n),r&&t.emit("participantLeft",r)}})),e.on("itemUpdated",(function(e){cP.debug(t.conversation.sid+" itemUpdated: "+e.item.key),t.upsertParticipant(e.item.key,e.item.data)}));var n=[];return e.getItems().then((function e(r){return r.items.forEach((function(e){n.push(t.upsertParticipant(e.key,e.data))})),r.hasNextPage?r.nextPage().then(e):null})).then((function(){return Promise.all(n)})).then((function(){return e}))})).catch((function(e){throw t.rosterEntityPromise=null,"disconnected"!=t.services.syncClient.connectionState&&cP.error("Failed to get roster object for conversation",t.conversation.sid,e),cP.debug("ERROR: Failed to get roster object for conversation",t.conversation.sid,e),e}))}},{key:"upsertParticipant",value:(a=Sa(bl.mark((function e(t,n){var r,i,a=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(r=this.participants.get(t))){e.next=3;break}return e.abrupt("return",r._update(n));case 3:return i={self:"".concat(this.links.participants,"/").concat(t)},r=new Participant(n,t,this.conversation,i,this.services),this.participants.set(t,r),r.on("updated",(function(e){return a.emit("participantUpdated",e)})),e.abrupt("return",r);case 8:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"getParticipants",value:(i=Sa(bl.mark((function e(){var t=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.rosterEntityPromise?this.rosterEntityPromise.then((function(){var e=[];return t.participants.forEach((function(t){return e.push(t)})),e})):[]);case 1:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"getParticipantBySid",value:(r=Sa(bl.mark((function e(t){var n=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.rosterEntityPromise?this.rosterEntityPromise.then((function(){var e=n.participants.get(t);if(!e)throw new Error("Participant with SID "+t+" was not found");return e})):null);case 1:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"getParticipantByIdentity",value:(n=Sa(bl.mark((function e(t){var n,r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=null,e.abrupt("return",this.rosterEntityPromise?this.rosterEntityPromise.then((function(){if(r.participants.forEach((function(e){e.identity===t&&(n=e)})),!n)throw new Error("Participant with identity "+t+" was not found");return n})):null);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"add",value:(t=Sa(bl.mark((function e(t,n){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.participants,{identity:t,attributes:void 0!==n?JSON.stringify(n):void 0});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e,n){return t.apply(this,arguments)})},{key:"addNonChatParticipant",value:function(e,t){var n,r,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return this.services.commandExecutor.mutateResource("post",this.links.participants,{attributes:void 0!==i?JSON.stringify(i):void 0,messaging_binding:{address:t,proxy_address:e,name:null==a||null===(n=a.email)||void 0===n?void 0:n.name,level:null==a||null===(r=a.email)||void 0===r?void 0:r.level}})}},{key:"remove",value:function(e){return this.services.commandExecutor.mutateResource("delete","".concat(this.links.participants,"/").concat(e))}}]),u}(Dy),fP=In,dP=On,pP=Q,hP=Ut,vP=gr,yP=s,mP=T_,gP=ec,bP=I_,kP=O_,wP=L,xP=P_,_P=[],SP=_P.sort,EP=yP((function(){_P.sort(void 0)})),TP=yP((function(){_P.sort(null)})),RP=gP("sort"),IP=!yP((function(){if(wP)return wP<70;if(!(bP&&bP>3)){if(kP)return!0;if(xP)return xP<603;var e,t,n,r,i="";for(e=65;e<76;e++){switch(t=String.fromCharCode(e),e){case 66:case 69:case 70:case 72:n=3;break;case 68:case 71:n=4;break;default:n=2}for(r=0;r<47;r++)_P.push({k:t+r,v:n})}for(_P.sort((function(e,t){return t.v-e.v})),r=0;r<_P.length;r++)t=_P[r].k.charAt(0),i.charAt(i.length-1)!==t&&(i+=t);return"DGBEFHACIJK"!==i}}));fP({target:"Array",proto:!0,forced:EP||!TP||!RP||!IP},{sort:function(e){void 0!==e&&dP(e);var t=pP(this);if(IP)return void 0===e?SP.call(t):SP.call(t,e);var n,r,i=[],a=hP(t.length);for(r=0;r<a;r++)r in t&&i.push(t[r]);for(n=(i=mP(i,function(e){return function(t,n){return void 0===n?-1:void 0===t?1:void 0!==e?+e(t,n)||0:vP(t)>vP(n)?1:-1}}(e))).length,r=0;r<n;)t[r]=i[r++];for(;r<a;)delete t[r++];return t}});var OP=JR,CP=k,PP=gr;In({target:"String",proto:!0,forced:!HR("includes")},{includes:function(e){return!!~PP(CP(this)).indexOf(PP(OP(e)),arguments.length>1?arguments[1]:void 0)}});var Media=function(){function Media(e,t){Ma(this,Media),ja(this,"mcsMedia",null),this.services=t,e instanceof $R.McsMedia&&(this.mcsMedia=e),this.state={sid:e.sid,category:e.category,filename:e.filename,contentType:e.contentType,size:e.size}}var e,t,n;return Ta(Media,[{key:"sid",get:function(){return this.state.sid}},{key:"filename",get:function(){return this.state.filename}},{key:"contentType",get:function(){return this.state.contentType}},{key:"size",get:function(){return this.state.size}},{key:"category",get:function(){return this.state.category}},{key:"getContentTemporaryUrl",value:(n=Sa(bl.mark((function e(){var t,n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._fetchMcsMedia();case 2:return e.abrupt("return",null!==(t=null===(n=this.mcsMedia)||void 0===n?void 0:n.getContentUrl())&&void 0!==t?t:null);case 3:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"getCachedTemporaryUrl",value:(t=Sa(bl.mark((function e(){var t,n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._fetchMcsMedia();case 2:return e.abrupt("return",null!==(t=null===(n=this.mcsMedia)||void 0===n?void 0:n.getCachedContentUrl())&&void 0!==t?t:null);case 3:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"_fetchMcsMedia",value:(e=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.mcsMedia){e.next=8;break}if(!this.services.mcsClient){e.next=7;break}return e.next=4,this.services.mcsClient.get(this.state.sid);case 4:this.mcsMedia=e.sent,e.next=8;break;case 7:throw new Error("Media Content Service is unavailable");case 8:case"end":return e.stop()}}),e,this)}))),function(){return e.apply(this,arguments)})}]),Media}(),AggregatedDeliveryReceipt=function(){function AggregatedDeliveryReceipt(e){Ma(this,AggregatedDeliveryReceipt),this.state=e}return Ta(AggregatedDeliveryReceipt,[{key:"total",get:function(){return this.state.total}},{key:"sent",get:function(){return this.state.sent}},{key:"delivered",get:function(){return this.state.delivered}},{key:"read",get:function(){return this.state.read}},{key:"undelivered",get:function(){return this.state.undelivered}},{key:"failed",get:function(){return this.state.failed}},{key:"_update",value:function(e){this.state=e}},{key:"_isEquals",value:function(e){var t=this.total===e.total,n=this.sent===e.sent,r=this.delivered===e.delivered,i=this.read===e.read,a=this.undelivered===e.undelivered,s=this.failed===e.failed;return t&&n&&r&&i&&a&&s}}]),AggregatedDeliveryReceipt}(),AP=function(){function e(t,n,r,i){Ma(this,e),this.state={prevToken:r,nextToken:i,source:n,items:t}}return Ta(e,[{key:"hasNextPage",get:function(){return!!this.state.nextToken}},{key:"hasPrevPage",get:function(){return!!this.state.prevToken}},{key:"items",get:function(){return this.state.items}},{key:"nextPage",value:function(){return this.hasNextPage?this.state.source(this.state.nextToken):Promise.reject(new Error("No next page"))}},{key:"prevPage",value:function(){return this.hasPrevPage?this.state.source(this.state.prevToken):Promise.reject(new Error("No previous page"))}}]),e}(),DetailedDeliveryReceipt=function DetailedDeliveryReceipt(e){Ma(this,DetailedDeliveryReceipt),this.sid=e.sid,this.messageSid=e.message_sid,this.conversationSid=e.conversation_sid,this.channelMessageSid=e.channel_message_sid,this.participantSid=e.participant_sid,this.status=e.status||"queued",this.errorCode=e.error_code||0,this.dateCreated=e.date_created,this.dateUpdated=e.date_updated};function jP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}var MP=rd.scope("Message"),Message=function(e){Oa(Message,e);var t,n,r,i,a,s,o,u=jP(Message);function Message(e,t,n,r,i,a){var s,o,c,l,f;return Ma(this,Message),(f=u.call(this)).conversation=n,f.links=r,f.configuration=i,f.services=a,f.state={sid:t.sid,index:e,author:t.author,subject:t.subject,body:null!==(s=t.text)&&void 0!==s?s:null,timestamp:t.timestamp?new Date(t.timestamp):null,dateUpdated:t.dateUpdated?new Date(t.dateUpdated):null,lastUpdatedBy:null!==(o=t.lastUpdatedBy)&&void 0!==o?o:null,attributes:nh(t.attributes,"Got malformed attributes for the message ".concat(t.sid),MP),type:null!==(c=t.type)&&void 0!==c?c:"text",media:t.type&&"media"===t.type&&t.media?new Media(t.media,f.services):null,medias:t.type&&"media"===t.type&&t.medias?t.medias.map((function(e){return new Media(e,f.services)})):null,participantSid:null!==(l=t.memberSid)&&void 0!==l?l:null,aggregatedDeliveryReceipt:t.delivery?new AggregatedDeliveryReceipt(t.delivery):null},f}return Ta(Message,[{key:"sid",get:function(){return this.state.sid}},{key:"author",get:function(){return this.state.author}},{key:"subject",get:function(){return this.state.subject}},{key:"body",get:function(){return this.state.body}},{key:"dateUpdated",get:function(){return this.state.dateUpdated}},{key:"index",get:function(){return this.state.index}},{key:"lastUpdatedBy",get:function(){return this.state.lastUpdatedBy}},{key:"dateCreated",get:function(){return this.state.timestamp}},{key:"attributes",get:function(){return this.state.attributes}},{key:"type",get:function(){return this.state.type}},{key:"media",get:function(){return this.state.media}},{key:"attachedMedia",get:function(){return this.getMediaByCategory(["media"])}},{key:"participantSid",get:function(){var e;return null!==(e=this.state.participantSid)&&void 0!==e?e:""}},{key:"aggregatedDeliveryReceipt",get:function(){return this.state.aggregatedDeliveryReceipt}},{key:"getMediaByCategory",value:function(e){var t;return(null!==(t=this.state.medias)&&void 0!==t?t:[]).filter((function(t){return e.includes(t.category)}))}},{key:"getEmailBody",value:function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"text/plain";return null!==(e=null===(t=this.getMediaByCategory(["body"]))||void 0===t?void 0:t.filter((function(e){return e.contentType==n})).shift())&&void 0!==e?e:null}},{key:"getEmailHistory",value:function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"text/plain";return null!==(e=null===(t=this.getMediaByCategory(["history"]))||void 0===t?void 0:t.filter((function(e){return e.contentType==n})).shift())&&void 0!==e?e:null}},{key:"_update",value:function(e){var t=[];!e.text&&"string"!=typeof e.text||e.text===this.state.body||(this.state.body=e.text,t.push("body")),e.subject&&e.subject!==this.state.subject&&(this.state.subject=e.subject,t.push("subject")),e.lastUpdatedBy&&e.lastUpdatedBy!==this.state.lastUpdatedBy&&(this.state.lastUpdatedBy=e.lastUpdatedBy,t.push("lastUpdatedBy")),e.author&&e.author!==this.state.author&&(this.state.author=e.author,t.push("author")),e.dateUpdated&&new Date(e.dateUpdated).getTime()!==(this.state.dateUpdated&&this.state.dateUpdated.getTime())&&(this.state.dateUpdated=new Date(e.dateUpdated),t.push("dateUpdated")),e.timestamp&&new Date(e.timestamp).getTime()!==(this.state.timestamp&&this.state.timestamp.getTime())&&(this.state.timestamp=new Date(e.timestamp),t.push("dateCreated"));var n=nh(e.attributes,"Got malformed attributes for the message ".concat(this.sid),MP);By(this.state.attributes,n)||(this.state.attributes=n,t.push("attributes"));var r=e.delivery,i=this.state.aggregatedDeliveryReceipt;!!(r&&r.total&&r.delivered&&r.failed&&r.read&&r.sent&&r.undelivered)&&(i?i._isEquals(r)||(i._update(r),t.push("deliveryReceipt")):(this.state.aggregatedDeliveryReceipt=new AggregatedDeliveryReceipt(r),t.push("deliveryReceipt"))),t.length>0&&this.emit("updated",{message:this,updateReasons:t})}},{key:"getParticipant",value:(o=Sa(bl.mark((function e(){var t,n,r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=null,!this.state.participantSid){e.next=5;break}return e.next=4,this.conversation.getParticipantBySid(this.participantSid).catch((function(){return MP.debug('Participant with sid "'.concat(r.participantSid,'" not found for message ').concat(r.sid)),null}));case 4:t=e.sent;case 5:if(t||!this.state.author){e.next=9;break}return e.next=8,this.conversation.getParticipantByIdentity(this.state.author).catch((function(){return MP.debug('Participant with identity "'.concat(r.author,'" not found for message ').concat(r.sid)),null}));case 8:t=e.sent;case 9:if(!t){e.next=11;break}return e.abrupt("return",t);case 11:throw n="Participant with ",this.state.participantSid&&(n+="SID '"+this.state.participantSid+"' "),this.state.author&&(this.state.participantSid&&(n+="or "),n+="identity '"+this.state.author+"' "),"Participant with "===n&&(n="Participant "),n+="was not found",new Error(n);case 17:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"getDetailedDeliveryReceipts",value:(s=Sa(bl.mark((function e(){var t,n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._getDetailedDeliveryReceiptsPaginator();case 2:t=e.sent,n=[];case 4:if(n=[].concat(nP(n),nP(t.items)),t.hasNextPage){e.next=8;break}return e.abrupt("break",13);case 8:return e.next=10,t.nextPage();case 10:t=e.sent,e.next=4;break;case 13:return e.abrupt("return",n);case 14:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"remove",value:(a=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("delete",this.links.self);case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"updateBody",value:(i=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{body:t});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"updateAttributes",value:(r=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{attributes:void 0!==t?JSON.stringify(t):void 0});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"attachTemporaryUrlsFor",value:(n=Sa(bl.mark((function e(t){var n,r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=null==t?void 0:t.map((function(e){return e.sid})),!this.services.mcsClient||!n){e.next=7;break}return e.next=4,this.services.mcsClient.mediaSetGet(n);case 4:return e.abrupt("return",e.sent.map((function(e){return new Media(e,r.services)})));case 7:throw new Error("Media Content Service is unavailable");case 8:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"_getDetailedDeliveryReceiptsPaginator",value:(t=Sa(bl.mark((function e(t){var n,r,i,a=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.configuration.links.messagesReceipts.replace("%s",this.conversation.sid).replace("%s",this.sid),r=new rh(n).arg("PageToken",null==t?void 0:t.pageToken).arg("PageSize",null==t?void 0:t.pageSize).build(),e.next=4,this.services.network.get(r);case 4:return i=e.sent,e.abrupt("return",new AP(i.body.delivery_receipts.map((function(e){return new DetailedDeliveryReceipt(e)})),(function(e,t){return a._getDetailedDeliveryReceiptsPaginator({pageToken:e,pageSize:t})}),i.body.meta.previous_token,i.body.meta.next_token));case 6:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),Message}(Dy);function LP(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return NP(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return NP(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function NP(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function UP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}ja(Message,"updated","updated"),wl([Qv(Vv),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Media)],Message.prototype,"getEmailBody",null),wl([Qv(Vv),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Media)],Message.prototype,"getEmailHistory",null),wl([Xv("string"),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Message.prototype,"updateBody",null),wl([Xv(Zv),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],Message.prototype,"updateAttributes",null),wl([Xv(Gv((function(e){return[e instanceof Array&&e.length>0&&e.reduce((function(e,t){return e&&t instanceof Media}),!0),"a non-empty array of Media"]}))),xl("design:type",Function),xl("design:paramtypes",[Array]),xl("design:returntype",Promise)],Message.prototype,"attachTemporaryUrlsFor",null);var DP=rd.scope("Messages"),FP=function(e){Oa(c,e);var t,n,r,i,a,s,o,u=UP(c);function c(e,t,n){var r;return Ma(this,c),(r=u.call(this)).conversation=e,r.configuration=t,r.services=n,r.messagesByIndex=new Map,r.messagesListPromise=null,r}return Ta(c,[{key:"subscribe",value:(o=Sa(bl.mark((function e(t){var n,r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.messagesListPromise){e.next=2;break}return e.abrupt("return",this.messagesListPromise);case 2:return this.messagesListPromise=this.services.syncClient.list({id:t,mode:"open_existing"}),e.prev=3,e.next=6,this.messagesListPromise;case 6:return(n=e.sent).on("itemAdded",(function(e){DP.debug("".concat(r.conversation.sid," itemAdded: ").concat(e.item.index));var t={self:"".concat(r.conversation.links.messages,"/").concat(e.item.data.sid),conversation:r.conversation.links.self,messages_receipts:"".concat(r.conversation.links.messages,"/").concat(e.item.data.sid,"/Receipts")},n=new Message(e.item.index,e.item.data,r.conversation,t,r.configuration,r.services);r.messagesByIndex.has(n.index)?DP.debug("Message arrived, but is already known and ignored",r.conversation.sid,n.index):(r.messagesByIndex.set(n.index,n),n.on("updated",(function(e){return r.emit("messageUpdated",e)})),r.emit("messageAdded",n))})),n.on("itemRemoved",(function(e){DP.debug("#{this.conversation.sid} itemRemoved: ".concat(e.index));var t=e.index;if(r.messagesByIndex.has(t)){var n=r.messagesByIndex.get(t);if(!n)return;r.messagesByIndex.delete(n.index),n.removeAllListeners("updated"),r.emit("messageRemoved",n)}})),n.on("itemUpdated",(function(e){DP.debug("".concat(r.conversation.sid," itemUpdated: ").concat(e.item.index));var t=r.messagesByIndex.get(e.item.index);t&&t._update(e.item.data)})),e.abrupt("return",n);case 13:throw e.prev=13,e.t0=e.catch(3),this.messagesListPromise=null,"disconnected"!==this.services.syncClient.connectionState&&DP.error("Failed to get messages object for conversation",this.conversation.sid,e.t0),DP.debug("ERROR: Failed to get messages object for conversation",this.conversation.sid,e.t0),e.t0;case 19:case"end":return e.stop()}}),e,this,[[3,13]])}))),function(e){return o.apply(this,arguments)})},{key:"unsubscribe",value:(s=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.messagesListPromise){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,this.messagesListPromise;case 4:e.sent.close(),this.messagesListPromise=null;case 7:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"sendV2",value:(a=Sa(bl.mark((function e(t){var n,r,i,a,s,o,u,c,l;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:DP.debug("Sending message V2",t.mediaContent,t.attributes,t.emailOptions),r=[],i=LP(t.mediaContent),e.prev=3,i.s();case 5:if((a=i.n()).done){e.next=22;break}if(u=$y(a.value,2),c=u[0],l=u[1],DP.debug("Adding media to a message as ".concat(l instanceof FormData?"FormData":"SendMediaOptions"),l),e.t0=r,!(l instanceof FormData)){e.next=15;break}return e.next=12,this.services.mcsClient.postFormData(l,c);case 12:e.t1=e.sent,e.next=18;break;case 15:return e.next=17,this.services.mcsClient.post(null!==(s=l.contentType)&&void 0!==s?s:"",null!==(o=l.media)&&void 0!==o?o:"",c,l.filename);case 17:e.t1=e.sent;case 18:e.t2=e.t1,e.t0.push.call(e.t0,e.t2);case 20:e.next=5;break;case 22:e.next=27;break;case 24:e.prev=24,e.t3=e.catch(3),i.e(e.t3);case 27:return e.prev=27,i.f(),e.finish(27);case 30:return e.next=32,this.services.commandExecutor.mutateResource("post",this.conversation.links.messages,{body:t.text,subject:null===(n=t.emailOptions)||void 0===n?void 0:n.subject,media_sids:r.map((function(e){return e.sid})),attributes:void 0!==t.attributes?JSON.stringify(t.attributes):void 0});case 32:return e.abrupt("return",e.sent);case 33:case"end":return e.stop()}}),e,this,[[3,24,27,30]])}))),function(e){return a.apply(this,arguments)})},{key:"send",value:(i=Sa(bl.mark((function e(t){var n,r,i=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=i.length>1&&void 0!==i[1]?i[1]:{},r=i.length>2?i[2]:void 0,DP.debug("Sending text message",t,n,r),e.next=5,this.services.commandExecutor.mutateResource("post",this.conversation.links.messages,{body:null!=t?t:"",attributes:void 0!==n?JSON.stringify(n):void 0,subject:null==r?void 0:r.subject});case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"sendMedia",value:(r=Sa(bl.mark((function e(t){var n,r,i,a,s,o=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=o.length>1&&void 0!==o[1]?o[1]:{},a=o.length>2?o[2]:void 0,DP.debug("Sending media message",t,i,a),DP.debug("Sending media message as ".concat(t instanceof FormData?"FormData":"SendMediaOptions"),t,i),!(t instanceof FormData)){e.next=10;break}return e.next=7,this.services.mcsClient.postFormData(t);case 7:e.t0=e.sent,e.next=13;break;case 10:return e.next=12,this.services.mcsClient.post(null!==(n=t.contentType)&&void 0!==n?n:"",null!==(r=t.media)&&void 0!==r?r:"","media",t.filename);case 12:e.t0=e.sent;case 13:return s=e.t0,e.next=16,this.services.commandExecutor.mutateResource("post",this.conversation.links.messages,{media_sids:[s.sid],attributes:void 0!==i?JSON.stringify(i):void 0});case 16:return e.abrupt("return",e.sent);case 17:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"getMessages",value:(n=Sa(bl.mark((function e(t,n){var r,i=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=i.length>2&&void 0!==i[2]?i[2]:"backwards",e.abrupt("return",this._getMessages(t,n,r));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"_wrapPaginator",value:function(e,t,n){var r=this,i="desc"===e,a=function(){return t.nextPage().then((function(t){return r._wrapPaginator(e,t,n)}))},s=function(){return t.prevPage().then((function(t){return r._wrapPaginator(e,t,n)}))};return n(t.items).then((function(e){return{items:e.sort((function(e,t){return e.index-t.index})),hasPrevPage:i?t.hasNextPage:t.hasPrevPage,hasNextPage:i?t.hasPrevPage:t.hasNextPage,prevPage:i?a:s,nextPage:i?s:a}}))}},{key:"_upsertMessage",value:function(e,t){var n=this,r=this.messagesByIndex.get(e);if(r)return r;var i={self:"".concat(this.conversation.links.messages,"/").concat(t.sid),conversation:this.conversation.links.self,messages_receipts:"".concat(this.conversation.links.messages,"/").concat(t.sid,"/Receipts")},a=new Message(e,t,this.conversation,i,this.configuration,this.services);return this.messagesByIndex.set(a.index,a),a.on("updated",(function(e){return n.emit("messageUpdated",e)})),a}},{key:"_getMessages",value:(t=Sa(bl.mark((function e(){var t,n,r,i,a,s,o=this,u=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=u.length>0&&void 0!==u[0]?u[0]:30,n=u.length>1&&void 0!==u[1]?u[1]:"end",r=u.length>2&&void 0!==u[2]?u[2]:"forward",i="backwards"===r?"desc":"asc",e.next=6,this.messagesListPromise;case 6:return a=e.sent,e.next=9,null==a?void 0:a.getItems({from:"end"!==n?n:void 0,pageSize:t,order:i,limit:t});case 9:return s=e.sent,e.next=12,this._wrapPaginator(i,s,(function(e){return Promise.all(e.map((function(e){return o._upsertMessage(e.index,e.data)})))}));case 12:return e.abrupt("return",e.sent);case 13:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),c}(Dy),BP=function(){function e(t){Ma(this,e),ja(this,"attributes",{}),ja(this,"mediaContent",[]),ja(this,"emailOptions",{}),this.messagesEntity=t}var t;return Ta(e,[{key:"send",value:(t=Sa(bl.mark((function e(){var t;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.messagesEntity.sendV2(this);case 2:return t=e.sent,e.abrupt("return",eh(t.index));case 4:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}(),qP=function(){function e(t,n){Ma(this,e),this.limits=t,this.message=new BP(n),this.emailBodies=new Map,this.emailHistories=new Map}return Ta(e,[{key:"setBody",value:function(e){return this.message.text=e,this}},{key:"setSubject",value:function(e){return this.message.emailOptions.subject=e,this}},{key:"setAttributes",value:function(e){return this.message.attributes=e,this}},{key:"setEmailBody",value:function(e,t){return this.emailBodies.set(e,t),this}},{key:"setEmailHistory",value:function(e,t){return this.emailHistories.set(e,t),this}},{key:"addMedia",value:function(e){if("undefined"==typeof FormData&&e instanceof FormData)throw new Error("Could not add FormData content whilst not in a browser");if(!(e instanceof FormData)){var t=e;if(!t.contentType||!t.media)throw new Error("Media content in SendMediaOptions must contain non-empty contentType and media")}return this.message.mediaContent.push(["media",e]),this}},{key:"build",value:function(){var e=this;if(this.emailBodies.forEach((function(t,n){if(!e.limits.emailBodiesAllowedMimeTypes.includes(n))throw new Error("Unsupported email body MIME type ".concat(n))})),this.emailHistories.forEach((function(t,n){if(!e.limits.emailHistoriesAllowedMimeTypes.includes(n))throw new Error("Unsupported email history MIME type ".concat(n))})),this.emailBodies.size>this.limits.emailBodiesAllowedMimeTypes.length)throw new Error("Too many email bodies attached to the message (".concat(this.emailBodies.size," > ").concat(this.limits.emailBodiesAllowedMimeTypes.length,")"));if(this.emailHistories.size>this.limits.emailHistoriesAllowedMimeTypes.length)throw new Error("Too many email histories attached to the message (".concat(this.emailHistories.size," > ").concat(this.limits.emailHistoriesAllowedMimeTypes.length,")"));if(this.message.mediaContent.length>this.limits.mediaAttachmentsCountLimit)throw new Error("Too many media attachments in the message (".concat(this.message.mediaContent.length," > ").concat(this.limits.mediaAttachmentsCountLimit,")"));return this.emailBodies.forEach((function(t){e.message.mediaContent.push(["body",t])})),this.emailHistories.forEach((function(t){e.message.mediaContent.push(["history",t])})),this.message}},{key:"getPayloadContentType",value:function(e){return"undefined"!=typeof FormData&&e instanceof FormData?e.get("Content-Type"):e.contentType}}]),e}();function zP(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return WP(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return WP(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function WP(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function GP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}var $P=rd.scope("Conversation"),VP={lastMessage:"lastMessage",attributes:"attributes",createdBy:"createdBy",dateCreated:"dateCreated",dateUpdated:"dateUpdated",friendlyName:"friendlyName",lastConsumedMessageIndex:"lastConsumedMessageIndex",notificationLevel:"notificationLevel",sid:"sid",status:"status",uniqueName:"uniqueName",state:"state",bindings:"bindings"};function JP(e){try{return new Date(e)}catch(e){return null}}var Conversation=function(e){Oa(Conversation,e);var t,n,r,i,a,s,o,u,c,l,f,d,p,h,v,y,m,g,b,k,w,x,_,S,E,T,R=GP(Conversation);function Conversation(e,t,n,r,i){var a,s;Ma(this,Conversation),(s=R.call(this)).sid=t,s.links=n,s.configuration=r,s.services=i;var o=e.attributes||{},u=e.createdBy,c=JP(e.dateCreated),l=JP(e.dateUpdated),f=e.friendlyName||null,d=Number.isInteger(e.lastConsumedMessageIndex)?e.lastConsumedMessageIndex:null,p=e.uniqueName||null;try{JSON.stringify(o)}catch(e){throw new Error("Attributes must be a valid JSON object.")}s.entityName=e.channel,s.channelState={uniqueName:p,status:"notParticipating",attributes:o,createdBy:u,dateCreated:c,dateUpdated:l,friendlyName:f,lastReadMessageIndex:d,bindings:null!==(a=e.bindings)&&void 0!==a?a:{}},e.notificationLevel&&(s.channelState.notificationLevel=e.notificationLevel);var h={participants:s.links.participants};return s.participants=new Map,s.participantsEntity=new lP(Ra(s),s.participants,h,s.configuration,s.services),s.participantsEntity.on("participantJoined",(function(e){return s.emit("participantJoined",e)})),s.participantsEntity.on("participantLeft",(function(e){return s.emit("participantLeft",e)})),s.participantsEntity.on("participantUpdated",(function(e){return s.emit("participantUpdated",e)})),s.messagesEntity=new FP(Ra(s),r,i),s.messagesEntity.on("messageAdded",(function(e){return s._onMessageAdded(e)})),s.messagesEntity.on("messageUpdated",(function(e){return s.emit("messageUpdated",e)})),s.messagesEntity.on("messageRemoved",(function(e){return s.emit("messageRemoved",e)})),s}return Ta(Conversation,[{key:"uniqueName",get:function(){return this.channelState.uniqueName}},{key:"status",get:function(){return this.channelState.status}},{key:"friendlyName",get:function(){return this.channelState.friendlyName}},{key:"dateUpdated",get:function(){return this.channelState.dateUpdated}},{key:"dateCreated",get:function(){return this.channelState.dateCreated}},{key:"createdBy",get:function(){var e;return null!==(e=this.channelState.createdBy)&&void 0!==e?e:""}},{key:"attributes",get:function(){return this.channelState.attributes}},{key:"lastReadMessageIndex",get:function(){return this.channelState.lastReadMessageIndex}},{key:"lastMessage",get:function(){var e;return null!==(e=this.channelState.lastMessage)&&void 0!==e?e:void 0}},{key:"notificationLevel",get:function(){var e;return null!==(e=this.channelState.notificationLevel)&&void 0!==e?e:"default"}},{key:"bindings",get:function(){return this.channelState.bindings}},{key:"limits",get:function(){return this.configuration.limits}},{key:"state",get:function(){return this.channelState.state}},{key:"_subscribe",value:function(){var e,t=this;return this.entityPromise=null!==(e=this.entityPromise)&&void 0!==e?e:this.services.syncClient.document({id:this.entityName,mode:"open_existing"}).then((function(e){return t.entity=e,t.entity.on("updated",(function(e){t._update(e.data)})),t.entity.on("removed",(function(){return t.emit("removed",t)})),t._update(t.entity.data),e})).catch((function(e){throw t.entity=null,t.entityPromise=null,"disconnected"!=t.services.syncClient.connectionState&&$P.error("Failed to get conversation object",e),$P.debug("ERROR: Failed to get conversation object",e),e}))}},{key:"_subscribeStreams",value:(T=Sa(bl.mark((function e(){var t,n,r,i,a;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this._subscribe();case 3:return $P.trace("_subscribeStreams, this.entity.data=",null===(t=this.entity)||void 0===t?void 0:t.data),i=null===(n=this.entity)||void 0===n?void 0:n.data.messages,a=null===(r=this.entity)||void 0===r?void 0:r.data.roster,e.next=8,Promise.all([this.messagesEntity.subscribe(i),this.participantsEntity.subscribe(a)]);case 8:e.next=15;break;case 10:throw e.prev=10,e.t0=e.catch(0),"disconnected"!==this.services.syncClient.connectionState&&$P.error("Failed to subscribe on conversation objects",this.sid,e.t0),$P.debug("ERROR: Failed to subscribe on conversation objects",this.sid,e.t0),e.t0;case 15:case"end":return e.stop()}}),e,this,[[0,10]])}))),function(){return T.apply(this,arguments)})},{key:"_unsubscribe",value:(E=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.entity){e.next=5;break}return e.next=3,this.entity.close();case 3:this.entity=null,this.entityPromise=null;case 5:return e.abrupt("return",Promise.all([this.participantsEntity.unsubscribe(),this.messagesEntity.unsubscribe()]));case 6:case"end":return e.stop()}}),e,this)}))),function(){return E.apply(this,arguments)})},{key:"_setStatus",value:function(e,t){var n=this;this.statusSource=t,this.channelState.status!==e&&(this.channelState.status=e,"joined"===e?this._subscribeStreams().catch((function(t){if($P.debug("ERROR while setting conversation status "+e,t),"disconnected"!==n.services.syncClient.connectionState)throw t})):this.entityPromise&&this._unsubscribe().catch((function(t){if($P.debug("ERROR while setting conversation status "+e,t),"disconnected"!==n.services.syncClient.connectionState)throw t})))}},{key:"_statusSource",value:function(){return this.statusSource}},{key:"_update",value:function(e){var t,n,r,i,a;$P.trace("_update",e),Conversation.preprocessUpdate(e,this.sid);for(var s=new Set,o=0,u=Object.keys(e);o<u.length;o++){var c=u[o],l=VP[c];if(l)switch(l){case VP.status:if(!e.status||"unknown"===e.status||this.channelState.status===e.status)break;this.channelState.status=e.status,s.add(l);break;case VP.attributes:if(By(this.channelState.attributes,e.attributes))break;this.channelState.attributes=e.attributes,s.add(l);break;case VP.lastConsumedMessageIndex:if(void 0===e.lastConsumedMessageIndex||e.lastConsumedMessageIndex===this.channelState.lastReadMessageIndex)break;this.channelState.lastReadMessageIndex=e.lastConsumedMessageIndex,s.add("lastReadMessageIndex");break;case VP.lastMessage:if(this.channelState.lastMessage&&!e.lastMessage){delete this.channelState.lastMessage,s.add(l);break}this.channelState.lastMessage=this.channelState.lastMessage||{},void 0!==(null===(t=e.lastMessage)||void 0===t?void 0:t.index)&&e.lastMessage.index!==this.channelState.lastMessage.index&&(this.channelState.lastMessage.index=e.lastMessage.index,s.add(l)),void 0!==(null===(n=e.lastMessage)||void 0===n?void 0:n.timestamp)&&(null===(r=this.channelState.lastMessage)||void 0===r||null===(i=r.dateCreated)||void 0===i?void 0:i.getTime())!==e.lastMessage.timestamp.getTime()&&(this.channelState.lastMessage.dateCreated=e.lastMessage.timestamp,s.add(l)),By(this.channelState.lastMessage,{})&&delete this.channelState.lastMessage;break;case VP.state:var f=e.state||void 0;if(void 0!==f&&(f.dateUpdated=new Date(f.dateUpdated)),By(this.channelState.state,f))break;this.channelState.state=f,s.add(l);break;case VP.bindings:if(By(this.channelState.bindings,e.bindings))break;this.channelState.bindings=e.bindings,s.add(l);break;default:var d=e[c]instanceof Date,p=d&&(null===(a=this.channelState[l])||void 0===a?void 0:a.getTime())===e[c].getTime(),h=!d&&this[l]===e[c];if(p||h)break;this.channelState[l]=e[c],s.add(l)}}s.size>0&&this.emit("updated",{conversation:this,updateReasons:nP(s)})}},{key:"_onMessageAdded",value:function(e){var t,n=zP(this.participants.values());try{for(n.s();!(t=n.n()).done;){var r=t.value;if(r.identity===e.author){r._endTyping();break}}}catch(e){n.e(e)}finally{n.f()}this.emit("messageAdded",e)}},{key:"_setLastReadMessageIndex",value:(S=Sa(bl.mark((function e(t){var n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post","".concat(this.configuration.links.myConversations,"/").concat(this.sid),{last_read_message_index:t});case 2:return n=e.sent,e.abrupt("return",n.unread_messages_count);case 4:case"end":return e.stop()}}),e,this)}))),function(e){return S.apply(this,arguments)})},{key:"add",value:(_=Sa(bl.mark((function e(t,n){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.participantsEntity.add(t,null!=n?n:{}));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t){return _.apply(this,arguments)})},{key:"addNonChatParticipant",value:(x=Sa(bl.mark((function e(t,n){var r,i,a=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=a.length>2&&void 0!==a[2]?a[2]:{},i=a.length>3&&void 0!==a[3]?a[3]:{},e.abrupt("return",this.participantsEntity.addNonChatParticipant(t,n,null!=r?r:{},null!=i?i:{}));case 3:case"end":return e.stop()}}),e,this)}))),function(e,t){return x.apply(this,arguments)})},{key:"advanceLastReadMessageIndex",value:(w=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:if(!(t<(this.lastReadMessageIndex||0))){e.next=6;break}return e.next=5,this._setLastReadMessageIndex(this.lastReadMessageIndex);case 5:return e.abrupt("return",e.sent);case 6:return e.next=8,this._setLastReadMessageIndex(t);case 8:return e.abrupt("return",e.sent);case 9:case"end":return e.stop()}}),e,this)}))),function(e){return w.apply(this,arguments)})},{key:"delete",value:(k=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("delete",this.links.self);case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(){return k.apply(this,arguments)})},{key:"getAttributes",value:(b=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribe();case 2:return e.abrupt("return",this.attributes);case 3:case"end":return e.stop()}}),e,this)}))),function(){return b.apply(this,arguments)})},{key:"getMessages",value:(g=Sa(bl.mark((function e(t,n,r){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.abrupt("return",this.messagesEntity.getMessages(t,n,r));case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return g.apply(this,arguments)})},{key:"getParticipants",value:(m=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.abrupt("return",this.participantsEntity.getParticipants());case 3:case"end":return e.stop()}}),e,this)}))),function(){return m.apply(this,arguments)})},{key:"getParticipantsCount",value:(y=Sa(bl.mark((function e(){var t,n,r;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new rh(this.configuration.links.conversations).path(this.sid).build(),e.next=3,this.services.network.get(n);case 3:return r=e.sent,e.abrupt("return",null!==(t=r.body.participants_count)&&void 0!==t?t:0);case 5:case"end":return e.stop()}}),e,this)}))),function(){return y.apply(this,arguments)})},{key:"getParticipantBySid",value:(v=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.participantsEntity.getParticipantBySid(t));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return v.apply(this,arguments)})},{key:"getParticipantByIdentity",value:(h=Sa(bl.mark((function e(){var t,n=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>0&&void 0!==n[0]?n[0]:"",e.abrupt("return",this.participantsEntity.getParticipantByIdentity(null!=t?t:""));case 2:case"end":return e.stop()}}),e,this)}))),function(){return h.apply(this,arguments)})},{key:"getMessagesCount",value:(p=Sa(bl.mark((function e(){var t,n,r;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new rh(this.configuration.links.conversations).path(this.sid).build(),e.next=3,this.services.network.get(n);case 3:return r=e.sent,e.abrupt("return",null!==(t=r.body.messages_count)&&void 0!==t?t:0);case 5:case"end":return e.stop()}}),e,this)}))),function(){return p.apply(this,arguments)})},{key:"getUnreadMessagesCount",value:(d=Sa(bl.mark((function e(){var t,n,r;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=new rh(this.configuration.links.myConversations).path(this.sid).build(),e.next=3,this.services.network.get(t);case 3:if((n=e.sent).body.conversation_sid===this.sid){e.next=6;break}throw new Error("Conversation was not found in the user conversations list");case 6:if("number"!=typeof(r=n.body.unread_messages_count)){e.next=9;break}return e.abrupt("return",r);case 9:return e.abrupt("return",null);case 10:case"end":return e.stop()}}),e,this)}))),function(){return d.apply(this,arguments)})},{key:"join",value:(f=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.participants,{identity:this.configuration.userIdentity});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(){return f.apply(this,arguments)})},{key:"leave",value:(l=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("joined"!==this.channelState.status){e.next=3;break}return e.next=3,this.services.commandExecutor.mutateResource("delete","".concat(this.links.participants,"/").concat(this.configuration.userIdentity));case 3:return e.abrupt("return",this);case 4:case"end":return e.stop()}}),e,this)}))),function(){return l.apply(this,arguments)})},{key:"removeParticipant",value:(c=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.participantsEntity.remove("string"==typeof t?t:t.sid);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return c.apply(this,arguments)})},{key:"sendMessage",value:(u=Sa(bl.mark((function e(t,n,r){var i,a,s,o;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("string"!=typeof t&&null!==t){e.next=5;break}return e.next=3,this.messagesEntity.send(t,n,r);case 3:return s=e.sent,e.abrupt("return",null!==(a=eh(s.index))&&void 0!==a?a:0);case 5:return e.next=7,this.messagesEntity.sendMedia(t,n,r);case 7:return o=e.sent,e.abrupt("return",null!==(i=eh(o.index))&&void 0!==i?i:0);case 9:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return u.apply(this,arguments)})},{key:"prepareMessage",value:function(){return new qP(this.limits,this.messagesEntity)}},{key:"setAllMessagesRead",value:(o=Sa(bl.mark((function e(){var t;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.next=4,this.getMessages(1);case 4:if(!((t=e.sent).items.length>0)){e.next=7;break}return e.abrupt("return",this.advanceLastReadMessageIndex(t.items[0].index));case 7:return e.abrupt("return",Promise.resolve(0));case 8:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"setAllMessagesUnread",value:(s=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.next=4,this._setLastReadMessageIndex(null);case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"setUserNotificationLevel",value:(a=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post","".concat(this.configuration.links.myConversations,"/").concat(this.sid),{notification_level:t});case 2:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"typing",value:function(){return this.services.typingIndicator.send(this.sid)}},{key:"updateAttributes",value:(i=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{attributes:void 0!==t?JSON.stringify(t):void 0});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"updateFriendlyName",value:(r=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.channelState.friendlyName===t){e.next=3;break}return e.next=3,this.services.commandExecutor.mutateResource("post",this.links.self,{friendly_name:t});case 3:return e.abrupt("return",this);case 4:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"updateLastReadMessageIndex",value:(n=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.abrupt("return",this._setLastReadMessageIndex(t));case 3:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"updateUniqueName",value:(t=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.channelState.uniqueName===t){e.next=4;break}return t||(t=""),e.next=4,this.services.commandExecutor.mutateResource("post",this.links.self,{unique_name:t});case 4:return e.abrupt("return",this);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}],[{key:"preprocessUpdate",value:function(e,t){try{"string"==typeof e.attributes?e.attributes=JSON.parse(e.attributes):e.attributes&&JSON.stringify(e.attributes)}catch(n){$P.warn("Retrieved malformed attributes from the server for conversation: "+t),e.attributes={}}try{e.dateCreated&&(e.dateCreated=new Date(e.dateCreated))}catch(n){$P.warn("Retrieved malformed dateCreated from the server for conversation: "+t),delete e.dateCreated}try{e.dateUpdated&&(e.dateUpdated=new Date(e.dateUpdated))}catch(n){$P.warn("Retrieved malformed dateUpdated from the server for conversation: "+t),delete e.dateUpdated}try{e.lastMessage&&e.lastMessage.timestamp&&(e.lastMessage.timestamp=new Date(e.lastMessage.timestamp))}catch(n){$P.warn("Retrieved malformed lastMessage.timestamp from the server for conversation: "+t),delete e.lastMessage.timestamp}}}]),Conversation}(Dy);ja(Conversation,"participantJoined","participantJoined"),ja(Conversation,"participantLeft","participantLeft"),ja(Conversation,"participantUpdated","participantUpdated"),ja(Conversation,"messageAdded","messageAdded"),ja(Conversation,"messageRemoved","messageRemoved"),ja(Conversation,"messageUpdated","messageUpdated"),ja(Conversation,"typingEnded","typingEnded"),ja(Conversation,"typingStarted","typingStarted"),ja(Conversation,"updated","updated"),ja(Conversation,"removed","removed"),wl([Xv(Vv,ey),xl("design:type",Function),xl("design:paramtypes",[String,Object]),xl("design:returntype",Promise)],Conversation.prototype,"add",null),wl([Xv(Vv,Vv,ey),xl("design:type",Function),xl("design:paramtypes",[String,String,Object,Object]),xl("design:returntype",Promise)],Conversation.prototype,"addNonChatParticipant",null),wl([Xv(Jv),xl("design:type",Function),xl("design:paramtypes",[Number]),xl("design:returntype",Promise)],Conversation.prototype,"advanceLastReadMessageIndex",null),wl([Xv(["undefined",Jv],["undefined",Jv],["undefined",$v("backwards","forward")]),xl("design:type",Function),xl("design:paramtypes",[Number,Number,String]),xl("design:returntype",Promise)],Conversation.prototype,"getMessages",null),wl([Xv(Vv),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"getParticipantBySid",null),wl([Xv(Vv),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"getParticipantByIdentity",null),wl([Xv([Vv,Participant]),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],Conversation.prototype,"removeParticipant",null),wl([Xv(["string",$v(null),Gv((function(e){return[e instanceof FormData,"an instance of FormData"]})),Kv("media options",{contentType:Vv,media:Gv((function(e){var t="string"==typeof e&&e.length>0||e instanceof Uint8Array||e instanceof ArrayBuffer;return"function"==typeof Blob&&(t=t||e instanceof Blob),[t,"a non-empty string, an instance of Buffer or an instance of Blob"]}))})],ey,["undefined",$v(null),Kv("email attributes",{subject:[Vv,"undefined"]})]),xl("design:type",Function),xl("design:paramtypes",[Object,Object,Object]),xl("design:returntype",Promise)],Conversation.prototype,"sendMessage",null),wl([Xv($v("default","muted")),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"setUserNotificationLevel",null),wl([Xv(Zv),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],Conversation.prototype,"updateAttributes",null),wl([Xv(["string"]),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"updateFriendlyName",null),wl([Xv([$v(null),Jv]),xl("design:type",Function),xl("design:paramtypes",[Number]),xl("design:returntype",Promise)],Conversation.prototype,"updateLastReadMessageIndex",null),wl([Xv(["string",$v(null)]),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"updateUniqueName",null);var KP=function(){function e(){var t=this;Ma(this,e),this._promise=new Promise((function(e,n){t._resolve=e,t._reject=n}))}return Ta(e,[{key:"promise",get:function(){return this._promise}},{key:"update",value:function(e){this._resolve(e)}},{key:"set",value:function(e){this.current=e,this._resolve(e)}},{key:"fail",value:function(e){this._reject(e)}}]),e}();function HP(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return YP(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return YP(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function YP(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function QP(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function XP(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?QP(Object(n),!0).forEach((function(t){ja(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):QP(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function ZP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}var eA=rd.scope("Conversations"),tA=function(e){Oa(p,e);var t,n,r,i,a,s,o,u,c,l,f,d=ZP(p);function p(e,t){var n;return Ma(this,p),ja(Ra(n=d.call(this)),"conversations",new Map),ja(Ra(n),"myConversationsRead",new KP),ja(Ra(n),"tombstones",new Set),ja(Ra(n),"myConversationsFetched",!1),n.configuration=e,n.services=t,n}return Ta(p,[{key:"addConversation",value:(f=Sa(bl.mark((function e(t){var n,r,i,a,s,o,u,c,l,f;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=void 0!==(null==t?void 0:t.attributes)?t.attributes:{},e.next=3,this.services.commandExecutor.mutateResource("post",this.configuration.links.conversations,{friendly_name:t.friendlyName,unique_name:t.uniqueName,attributes:void 0!==a?JSON.stringify(a):void 0});case 3:if(s=e.sent,o=null!==(n=s.sid)&&void 0!==n?n:null,u=null!==(r=null===(i=s.sync_objects)||void 0===i?void 0:i.conversation)&&void 0!==r?r:null,c=XP({self:s.url},s.links),!(l=this.conversations.get(o))){e.next=12;break}return e.next=11,l._subscribe();case 11:return e.abrupt("return",l);case 12:return f=new Conversation({channel:u,entityName:"",uniqueName:"",attributes:null,createdBy:"",friendlyName:"",lastConsumedMessageIndex:0,dateCreated:null,dateUpdated:null},o,c,this.configuration,this.services),this.conversations.set(f.sid,f),this._registerForEvents(f),e.next=17,f._subscribe();case 17:return this.emit("conversationAdded",f),e.abrupt("return",f);case 19:case"end":return e.stop()}}),e,this)}))),function(e){return f.apply(this,arguments)})},{key:"fetchConversations",value:(l=Sa(bl.mark((function e(){var t,n,r,i,a,s,o,u=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this._getMap();case 3:return(t=e.sent).on("itemAdded",(function(e){eA.debug("itemAdded: ".concat(e.item.key)),u._upsertConversation("sync",e.item.key,e.item.data)})),t.on("itemRemoved",(function(e){eA.debug("itemRemoved: ".concat(e.key));var t=e.key;u.myConversationsFetched||u.tombstones.add(t);var n=u.conversations.get(t);n&&("joined"===n.status&&(n._setStatus("notParticipating","sync"),u.emit("conversationLeft",n)),u.conversations.delete(t),u.emit("conversationRemoved",n),n.emit("removed",n))})),t.on("itemUpdated",(function(e){eA.debug("itemUpdated: ".concat(e.item.key)),u._upsertConversation("sync",e.item.key,e.item.data)})),e.next=9,this._fetchMyConversations();case 9:n=e.sent,r=[],i=HP(n);try{for(i.s();!(a=i.n()).done;)s=a.value,r.push(this._upsertConversation("rest",s.channel_sid,s))}catch(e){i.e(e)}finally{i.f()}return this.myConversationsRead.set(!0),e.next=16,Promise.all(r);case 16:return this.myConversationsFetched=!0,this.tombstones.clear(),eA.debug("The conversations list has been successfully fetched"),e.abrupt("return",this);case 22:throw e.prev=22,e.t0=e.catch(0),o="Failed to fetch the conversations list","disconnected"!==this.services.syncClient.connectionState&&eA.error(o,e.t0),eA.debug("ERROR: ".concat(o),e.t0),e.t0;case 28:case"end":return e.stop()}}),e,this,[[0,22]])}))),function(){return l.apply(this,arguments)})},{key:"getConversations",value:(c=Sa(bl.mark((function e(){var t,n,r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._getMap();case 2:return t=e.sent,e.next=5,t.getItems();case 5:return n=e.sent,e.abrupt("return",this._wrapPaginator(n,(function(e){return Promise.all(e.map((function(e){return r._upsertConversation("sync",e.key,e.data)})))})));case 7:case"end":return e.stop()}}),e,this)}))),function(){return c.apply(this,arguments)})},{key:"getConversation",value:(u=Sa(bl.mark((function e(t){var n,r,i,a=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._getMap();case 2:return n=e.sent,e.next=5,n.getItems({key:t});case 5:return r=e.sent,i=r.items.map((function(e){return a._upsertConversation("sync",e.key,e.data)})),e.abrupt("return",i.length>0?i[0]:null);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return u.apply(this,arguments)})},{key:"getConversationByUniqueName",value:(o=Sa(bl.mark((function e(t){var n,r,i,a,s;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new rh(this.configuration.links.myConversations).path(t).build(),e.next=3,this.services.network.get(n);case 3:return r=e.sent,i=r.body,a=i.conversation_sid,s={entityName:null,lastConsumedMessageIndex:i.last_read_message_index,status:(null==i?void 0:i.status)||"unknown",friendlyName:i.friendly_name,dateUpdated:i.date_updated,dateCreated:i.date_created,uniqueName:i.unique_name,createdBy:i.created_by,attributes:i.attributes,channel:i.sync_objects.conversation,notificationLevel:null==i?void 0:i.notification_level,sid:a},e.abrupt("return",a?this._upsertConversation("sync",a,s):null);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"peekConversation",value:(s=Sa(bl.mark((function e(t){var n,r,i,a;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new rh(this.configuration.links.conversations).path(t).build(),e.next=3,this.services.network.get(n);case 3:return r=e.sent,i=r.body,a={entityName:null,status:(null==i?void 0:i.status)||"unknown",friendlyName:i.friendly_name,dateUpdated:i.date_updated,dateCreated:i.date_created,uniqueName:i.unique_name,createdBy:i.created_by,attributes:i.attributes,channel:"".concat(t,".channel"),sid:t},e.abrupt("return",this._upsertConversation("sync",t,a));case 7:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"_getMap",value:(a=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.syncClient.map({id:this.configuration.myConversations,mode:"open_existing"});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"_wrapPaginator",value:(i=Sa(bl.mark((function e(t,n){var r,i=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,n(t.items);case 2:return r=e.sent,e.abrupt("return",{items:r,hasNextPage:t.hasNextPage,hasPrevPage:t.hasPrevPage,nextPage:function(){return t.nextPage().then((function(e){return i._wrapPaginator(e,n)}))},prevPage:function(){return t.prevPage().then((function(e){return i._wrapPaginator(e,n)}))}});case 4:case"end":return e.stop()}}),e)}))),function(e,t){return i.apply(this,arguments)})},{key:"_updateConversation",value:(r=Sa(bl.mark((function e(t,n,r){var i,a,s,o=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=void 0!==n._statusSource()&&t!==n._statusSource(),a="rest"!==t||"sync"===n._statusSource(),!i||!a||"sync"===t){e.next=5;break}return eA.trace("upsertConversation: conversation is known from sync and came from chat, ignoring",{sid:n.sid,data:r.status,conversation:n.status}),e.abrupt("return");case 5:if("joined"!==r.status||"joined"===n.status){e.next=13;break}return n._setStatus("joined",t),s={},void 0!==r.notificationLevel&&(s.notificationLevel=r.notificationLevel),void 0!==r.lastConsumedMessageIndex&&(s.lastConsumedMessageIndex=r.lastConsumedMessageIndex),By(s,{})||n._update(s),n._subscribe().then((function(){o.emit("conversationJoined",n)})),e.abrupt("return");case 13:if("notParticipating"!==r.status||"joined"!==n.status){e.next=20;break}return n._setStatus("notParticipating",t),n._update(r),e.next=18,n._subscribe();case 18:return this.emit("conversationLeft",n),e.abrupt("return");case 20:if("notParticipating"!==r.status){e.next=24;break}return e.next=23,n._subscribe();case 23:return e.abrupt("return");case 24:n._update(r);case 25:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return r.apply(this,arguments)})},{key:"_upsertConversation",value:(n=Sa(bl.mark((function e(t,n,r){var i,a,s,o;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(eA.trace("upsertConversation called for ".concat(n),r),!(i=this.conversations.get(n))){e.next=9;break}return eA.trace("upsertConversation: the conversation ".concat(i.sid," is known;")+"its status is known from the source ".concat(i._statusSource()," ")+"and the update came from the source ".concat(t),i),e.next=6,this._updateConversation(t,i,r);case 6:return e.next=8,i._subscribe();case 8:return e.abrupt("return",i);case 9:if(!["chat","rest"].includes(t)||!this.tombstones.has(n)){e.next=12;break}return eA.trace("upsertChannel: the channel is deleted but reappeared again from chat, ignoring",n),e.abrupt("return",null);case 12:return eA.trace("upsertConversation: creating a local conversation object with sid "+n,r),a="".concat(this.configuration.links.conversations,"/").concat(n),s={self:a,messages:"".concat(a,"/Messages"),participants:"".concat(a,"/Participants")},o=new Conversation(r,n,s,this.configuration,this.services),this.conversations.set(n,o),e.next=19,o._subscribe();case 19:return this._registerForEvents(o),this.emit("conversationAdded",o),"joined"===r.status&&(o._setStatus("joined",t),this.emit("conversationJoined",o)),e.abrupt("return",o);case 23:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return n.apply(this,arguments)})},{key:"_fetchMyConversations",value:(t=Sa(bl.mark((function e(){var t,n,r,i,a,s;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=[],n=null;case 2:return i=new rh(this.configuration.links.myConversations),n&&i.arg("PageToken",n),e.next=6,this.services.network.get(i.build());case 6:a=e.sent,s=null===(r=a.body)||void 0===r?void 0:r.conversations.map((function(e){return{descriptor:e,channel_sid:e.conversation_sid,status:e.status,channel:e.sync_objects.conversation,messages:e.sync_objects.messages,roster:"".concat(e.conversation_sid,".roster"),lastConsumedMessageIndex:e.last_read_message_index,notificationLevel:e.notification_level}})),n=a.body.meta.next_token,t=[].concat(nP(t),nP(s));case 10:if(n){e.next=2;break}case 11:return e.abrupt("return",t);case 12:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"_onConversationRemoved",value:function(e){var t=this.conversations.get(e);t&&(this.conversations.delete(e),this.emit("conversationRemoved",t))}},{key:"_registerForEvents",value:function(e){var t=this;e.on("removed",(function(){return t._onConversationRemoved(e.sid)})),e.on("updated",(function(e){return t.emit("conversationUpdated",e)})),e.on("participantJoined",(function(e){return t.emit("participantJoined",e)})),e.on("participantLeft",(function(e){return t.emit("participantLeft",e)})),e.on("participantUpdated",(function(e){return t.emit("participantUpdated",e)})),e.on("messageAdded",(function(e){return t.emit("messageAdded",e)})),e.on("messageUpdated",(function(e){return t.emit("messageUpdated",e)})),e.on("messageRemoved",(function(e){return t.emit("messageRemoved",e)})),e.on("typingStarted",(function(e){return t.emit("typingStarted",e)})),e.on("typingEnded",(function(e){return t.emit("typingEnded",e)}))}}]),p}(Dy),nA=In,rA=Hr.find,iA=kd,aA="find",sA=!0;function oA(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}aA in[]&&Array(1).find((function(){sA=!1})),nA({target:"Array",proto:!0,forced:sA},{find:function(e){return rA(this,e,arguments.length>1?arguments[1]:void 0)}}),iA(aA);var uA=function(e){Oa(a,e);var t,n,r,i=oA(a);function a(e,t,n){var r;return Ma(this,a),(r=i.call(this)).configuration=t,r.services=n,r.fifoStack=[],r.myself=e,r.myself.on("updated",(function(e){return r.emit("userUpdated",e)})),r.myself.on("userSubscribed",(function(){return r.emit("userSubscribed",r.myself)})),r.myself.on("userUnsubscribed",(function(){r.emit("userUnsubscribed",r.myself),r.myself._ensureFetched()})),r.subscribedUsers=new Map,r}return Ta(a,[{key:"handleUnsubscribeUser",value:function(e){this.subscribedUsers.has(e.identity)&&this.subscribedUsers.delete(e.identity);var t=0;this.fifoStack.find((function(n,r){return n==e.identity&&(t=r,!0)}))&&this.fifoStack.splice(t,1),this.emit("userUnsubscribed",e)}},{key:"handleSubscribeUser",value:function(e){if(!this.subscribedUsers.has(e.identity)){if(this.fifoStack.length>=this.configuration.userInfosToSubscribe){var t,n,r=this.fifoStack.shift();null===(t=this.subscribedUsers)||void 0===t||null===(n=t.get(r))||void 0===n||n.unsubscribe()}this.fifoStack.push(e.identity),this.subscribedUsers.set(e.identity,e),this.emit("userSubscribed",e)}}},{key:"getUser",value:(r=Sa(bl.mark((function e(){var t,n,r,i,a=this,s=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=s.length>0&&void 0!==s[0]?s[0]:"",n=s.length>1&&void 0!==s[1]?s[1]:"",e.next=4,this.myself._ensureFetched();case 4:if(t!=this.myself.identity){e.next=6;break}return e.abrupt("return",this.myself);case 6:if(!(r=this.subscribedUsers.get(t))){e.next=9;break}return e.abrupt("return",r);case 9:if(e.t0=n,e.t0){e.next=14;break}return e.next=13,this.getSyncUniqueName(t);case 13:e.t0=e.sent;case 14:return n=e.t0,(i=new User(t,n,this.configuration,this.services)).on("updated",(function(e){return a.emit("userUpdated",e)})),i.on("userSubscribed",(function(){return a.handleSubscribeUser(i)})),i.on("userUnsubscribed",(function(){return a.handleUnsubscribeUser(i)})),e.next=21,i._ensureFetched();case 21:return e.abrupt("return",i);case 22:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"getSubscribedUsers",value:(n=Sa(bl.mark((function e(){var t;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.myself._ensureFetched();case 2:return t=[this.myself],this.subscribedUsers.forEach((function(e){return t.push(e)})),e.abrupt("return",t);case 5:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"getSyncUniqueName",value:(t=Sa(bl.mark((function e(t){var n,r,i,a;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=new rh(this.configuration.links.users).path(t).build(),e.next=3,this.services.network.get(i);case 3:return a=e.sent,e.abrupt("return",null!==(n=null===(r=a.body)||void 0===r?void 0:r.sync_objects.user_info_map)&&void 0!==n?n:"");case 5:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),a}(Dy),cA=rd.scope("TypingIndicator"),lA=function(){function e(t,n,r){Ma(this,e),this.configuration=n,this.services=r,this.getConversation=t,this.serviceTypingTimeout=null,this.sentUpdates=new Map}var t;return Ta(e,[{key:"typingTimeout",get:function(){return this.configuration.typingIndicatorTimeoutOverride||this.serviceTypingTimeout||this.configuration.typingIndicatorTimeoutDefault}},{key:"initialize",value:function(){var e=this;this.services.notificationClient.on("message",function(){var t=Sa(bl.mark((function t(n,r){return bl.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n!==gg.TYPING_INDICATOR){t.next=3;break}return t.next=3,e._handleRemoteTyping(r);case 3:case"end":return t.stop()}}),t)})));return function(e,n){return t.apply(this,arguments)}}())}},{key:"_handleRemoteTyping",value:(t=Sa(bl.mark((function e(t){var n=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:cA.trace("Got new typing indicator ",t),this.getConversation(t.channel_sid).then((function(e){e&&e.participants.forEach((function(e){if(e.identity===t.identity){var r=n.configuration.typingIndicatorTimeoutOverride?n.configuration.typingIndicatorTimeoutOverride+1e3:1e3*t.typing_timeout;e._startTyping(r)}}))})).catch((function(e){throw cA.error(e),e}));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"send",value:function(e){var t=this.sentUpdates.get(e);return t&&t>Date.now()-this.typingTimeout?Promise.resolve():(this.sentUpdates.set(e,Date.now()),this._send(e))}},{key:"_send",value:function(e){var t=this;cA.trace("Sending typing indicator");var n=this.configuration.links.typing,r="ChannelSid=".concat(e);return this.services.twilsockClient.post(n,{"Content-Type":"application/x-www-form-urlencoded"},r,this.configuration.productId).then((function(e){e.body.hasOwnProperty("typing_timeout")&&(t.serviceTypingTimeout=1e3*e.body.typing_timeout)})).catch((function(e){throw cA.error("Failed to send typing indicator:",e),e}))}}]),e}(),PushNotification=function PushNotification(e){Ma(this,PushNotification),this.title=e.title||null,this.body=e.body||null,this.sound=e.sound||null,this.badge=e.badge||null,this.action=e.action||null,this.type=e.type||null,this.data=e.data||{}};function fA(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function dA(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?fA(Object(n),!0).forEach((function(t){ja(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):fA(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var pA,hA,vA,yA=function(e){return e.replace(/(^\/+|\/+$)/g,"")},mA=function(){function e(t,n,r){Ma(this,e),this._serviceUrl=t,this._services=n,this._productId=r}var t,n,r;return Ta(e,[{key:"_preProcessUrl",value:function(e){var t=yA(e);return/^https?:\/\//.test(e)?t:"".concat(yA(this._serviceUrl),"/").concat(t)}},{key:"_makeRequest",value:(r=Sa(bl.mark((function e(t,n,r,i){var a,s,o,u;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a=this._preProcessUrl(n),s=dA({"Content-Type":"application/json; charset=utf-8"},i||{}),e.t0=t,e.next="get"===e.t0?5:"post"===e.t0?11:"delete"===e.t0?15:19;break;case 5:return u=a,r&&(u+="?"+Object.entries(r).map((function(e){return e.map(encodeURIComponent).join("=")})).join("&")),e.next=9,this._services.transport.get(u,s,this._productId);case 9:return o=e.sent,e.abrupt("break",19);case 11:return e.next=13,this._services.transport.post(a,s,JSON.stringify(r),this._productId);case 13:return o=e.sent,e.abrupt("break",19);case 15:return e.next=17,this._services.transport.delete(a,s,{},this._productId);case 17:return o=e.sent,e.abrupt("break",19);case 19:if(!(o.status.code<200||o.status.code>=300)){e.next=21;break}throw new Error("Request responded with a non-success code ".concat(o.status.code));case 21:return e.abrupt("return",o);case 22:case"end":return e.stop()}}),e,this)}))),function(e,t,n,i){return r.apply(this,arguments)})},{key:"fetchResource",value:(n=Sa(bl.mark((function e(t,n){var r,i=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=1,e.next=4,new pg({min:50,max:1600,maxAttemptsCount:6}).run((function(){return i._makeRequest("get",t,n)}));case 4:return r=e.sent,e.abrupt("return",r.body);case 8:throw e.prev=8,e.t0=e.catch(1),new Error('Fetch resource from "'.concat(t,'" failed.'));case 11:case"end":return e.stop()}}),e,null,[[1,8]])}))),function(e,t){return n.apply(this,arguments)})},{key:"mutateResource",value:(t=Sa(bl.mark((function e(t,n,r){var i;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._makeRequest(t,n,r,{"X-Twilio-Mutation-Id":tb.v4()});case 2:if(202!==(i=e.sent).status.code){e.next=7;break}return e.next=6,this.fetchResource(i.body.resource_url);case 6:return e.abrupt("return",e.sent);case 7:return e.abrupt("return",i.body);case 8:case"end":return e.stop()}}),e,this)}))),function(e,n,r){return t.apply(this,arguments)})}]),e}();function gA(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function bA(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?gA(Object(n),!0).forEach((function(t){ja(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):gA(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function kA(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}var wA=rd.scope("Client"),xA="2.1.0-rc.5",_A=function e(){Ma(this,e)};return e.Client=(hA=pA=function(e){Oa(Client,e);var t,n,r,i,a,s,o,u,c,l,f,d,p,h,v=kA(Client);function Client(e){var t,n,r,i,a,s,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(Ma(this,Client),ja(Ra(s=v.call(this)),"connectionState","unknown"),ja(Ra(s),"version",xA),ja(Ra(s),"parsePushNotification",vA.parsePushNotification),s.fpaToken=null!=e?e:"",s.options=null!=o?o:{},!s.options.disableDeepClone){var u=bA(bA({},s.options),{},{transport:void 0,twilsockClient:void 0});(u=Zp(u)).transport=s.options.transport,u.twilsockClient=s.options.twilsockClient,s.options=u}s.options.logLevel=null!==(t=s.options.logLevel)&&void 0!==t?t:"silent",wA.setLevel(s.options.logLevel);var c=s.options.productId="ip_messaging";if(s.options.clientMetadata=s.options.clientMetadata||{},s.options.clientMetadata.hasOwnProperty("type")||(s.options.clientMetadata.type="conversations"),s.options.clientMetadata.hasOwnProperty("sdk")||(s.options.clientMetadata.sdk="JS",s.options.clientMetadata.sdkv=xA),s.options.Sync=s.options.Sync||{},void 0===s.options.Sync.enableSessionStorage&&(s.options.Sync.enableSessionStorage=!0),s.options.region&&(s.options.Sync.region=s.options.region),!e)throw new Error("A valid Twilio token should be provided");s.services=new _A,s._myself=new User("","",null,s.services);var l=!s.options.twilsockClient;if(!s.options.initRegistrations){var f=new bg.InitRegistration(c);vA.populateInitRegistrations(f),s.options.initRegistrations=[f]}s.services.twilsockClient=s.options.twilsockClient=null!==(n=s.options.twilsockClient)&&void 0!==n?n:new bg.TwilsockClient(e,c,s.options),s.services.twilsockClient.on("tokenAboutToExpire",(function(e){return s.emit("tokenAboutToExpire",e)})),s.services.twilsockClient.on("tokenExpired",(function(){return s.emit("tokenExpired")})),s.services.twilsockClient.on("connectionError",(function(e){return s.emit("connectionError",e)})),s.services.twilsockClient.on("stateChanged",(function(e){wA.debug("Handling stateChanged for ConversationsClient: new state ".concat(e)),e!==s.connectionState&&(s.connectionState=e,s.emit("connectionStateChanged",s.connectionState))})),s.services.transport=s.options.transport=null!==(r=s.options.transport)&&void 0!==r?r:s.options.twilsockClient,s.services.notificationClient=s.options.notificationsClient=null!==(i=s.options.notificationsClient)&&void 0!==i?i:new aE.Notifications(e,s.options),s.services.syncClient=s.options.syncClient=null!==(a=s.options.syncClient)&&void 0!==a?a:new BR(e,s.options);var d=(null==o?void 0:o.Chat)||(null==o?void 0:o.IPMessaging)||o||{},p=d.region||(null==o?void 0:o.region),h=d.apiUri||d.typingUri||"https://aim.".concat(p||"us1",".twilio.com");s.services.commandExecutor=new mA(h,{transport:s.options.transport},c);var y=function(e){s._rejectEnsureReady(e),s.emit("stateChanged","failed")};return s.services.twilsockClient.once("connectionError",y),s.services.twilsockClient.once("disconnected",y),s.services.twilsockClient.once("connected",Sa(bl.mark((function e(){var t;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return wA.debug("ConversationsClient started INITIALIZING"),s.services.twilsockClient.off("connectionError",y),s.services.twilsockClient.off("disconnected",y),e.prev=3,t="conversations.client.startup",s.services.twilsockClient.addPartialTelemetryEvent(new bg.TelemetryEventDescription(t,"Conversations client startup",new Date),t,bg.TelemetryPoint.Start),e.next=8,s._initialize();case 8:s.services.twilsockClient.addPartialTelemetryEvent(new bg.TelemetryEventDescription("","",new Date),t,bg.TelemetryPoint.End),e.next=15;break;case 11:e.prev=11,e.t0=e.catch(3),s._rejectEnsureReady(e.t0),s.emit("stateChanged","failed");case 15:case"end":return e.stop()}}),e,null,[[3,11]])})))),s._ensureReady=new Promise((function(e,t){s._resolveEnsureReady=e,s._rejectEnsureReady=t})).catch((function(){})),l&&s.services.twilsockClient.connect(),s}return Ta(Client,[{key:"user",get:function(){return this._myself}},{key:"reachabilityEnabled",get:function(){if(!this.configuration)throw new Error("Reachability information could not yet be accessed as the client has not yet been initialized. Subscribe to the 'stateChanged' event to properly react to the client initialization.");return this.configuration.reachabilityEnabled}},{key:"token",get:function(){return this.fpaToken}},{key:"_subscribeToPushNotifications",value:function(e){var t=this;[gg.NEW_MESSAGE,gg.ADDED_TO_CONVERSATION,gg.REMOVED_FROM_CONVERSATION,gg.TYPING_INDICATOR,gg.CONSUMPTION_UPDATE].forEach((function(n){t.services.notificationClient.subscribe(e,n)}))}},{key:"_unsubscribeFromPushNotifications",value:function(e){var t=this;[gg.NEW_MESSAGE,gg.ADDED_TO_CONVERSATION,gg.REMOVED_FROM_CONVERSATION,gg.TYPING_INDICATOR,gg.CONSUMPTION_UPDATE].forEach((function(n){t.services.notificationClient.unsubscribe(e,n)}))}},{key:"_initialize",value:(h=Sa(bl.mark((function e(){var t,n=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.fetchResource("Client/v2/Configuration");case 2:return t=e.sent,this.configuration=new hd(this.options,t,wA),this._myself._resolveInitialization(this.configuration,this.configuration.userIdentity,this.configuration.userInfo,!0),this.services.typingIndicator=new lA(this.getConversationBySid.bind(this),this.configuration,this.services),this.services.network=new mg(this.configuration,this.services),this.services.users=new uA(this._myself,this.configuration,this.services),this.services.users.on("userSubscribed",(function(e){n.emit("userSubscribed",e)})),this.services.users.on("userUpdated",(function(e){return n.emit("userUpdated",e)})),this.services.users.on("userUnsubscribed",(function(e){n.emit("userUnsubscribed",e)})),this.conversations=new tA(this.configuration,this.services),this.conversations.on("conversationAdded",(function(e){n.emit("conversationAdded",e)})),this.conversations.on("conversationRemoved",(function(e){n.emit("conversationRemoved",e)})),this.conversations.on("conversationJoined",(function(e){n.emit("conversationJoined",e)})),this.conversations.on("conversationLeft",(function(e){n.emit("conversationLeft",e)})),this.conversations.on("conversationUpdated",(function(e){return n.emit("conversationUpdated",e)})),this.conversations.on("participantJoined",(function(e){n.emit("participantJoined",e)})),this.conversations.on("participantLeft",(function(e){n.emit("participantLeft",e)})),this.conversations.on("participantUpdated",(function(e){return n.emit("participantUpdated",e)})),this.conversations.on("messageAdded",(function(e){return n.emit("messageAdded",e)})),this.conversations.on("messageUpdated",(function(e){return n.emit("messageUpdated",e)})),this.conversations.on("messageRemoved",(function(e){return n.emit("messageRemoved",e)})),this.conversations.on("typingStarted",(function(e){return n.emit("typingStarted",e)})),this.conversations.on("typingEnded",(function(e){return n.emit("typingEnded",e)})),this.conversationsPromise=this.conversations.fetchConversations().then((function(){return n.conversations})).catch((function(e){throw e})),e.next=28,this.services.users.myself._ensureFetched();case 28:vA.supportedPushChannels.forEach((function(e){return n._subscribeToPushNotifications(e)})),this.services.typingIndicator.initialize(),this.services.mcsClient=new $R.McsClient(this.fpaToken,this.configuration.links.mediaService,this.configuration.links.mediaSetService,bA(bA({},this.options),{},{transport:void 0})),this._resolveEnsureReady(),this.emit("stateChanged","initialized");case 33:case"end":return e.stop()}}),e,this)}))),function(){return h.apply(this,arguments)})},{key:"shutdown",value:(p=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.next=4,this.services.twilsockClient.disconnect();case 4:case"end":return e.stop()}}),e,this)}))),function(){return p.apply(this,arguments)})},{key:"updateToken",value:(d=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:if(wA.info("updateToken"),this.fpaToken!==t){e.next=5;break}return e.abrupt("return",this);case 5:return e.next=7,this.services.twilsockClient.updateToken(t);case 7:return e.next=9,this.services.notificationClient.updateToken(t);case 9:return e.next=11,this.services.mcsClient.updateToken(t);case 11:return this.fpaToken=t,e.abrupt("return",this);case 13:case"end":return e.stop()}}),e,this)}))),function(e){return d.apply(this,arguments)})},{key:"getConversationBySid",value:(f=Sa(bl.mark((function e(t){var n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.next=4,this.conversations.myConversationsRead.promise;case 4:return e.next=6,this.conversations.getConversation(t);case 6:if(n=e.sent){e.next=11;break}return e.next=10,this.conversations.peekConversation(t);case 10:n=e.sent;case 11:if(n){e.next=13;break}throw new Error("Conversation with SID ".concat(t," is not found."));case 13:return e.abrupt("return",n);case 14:case"end":return e.stop()}}),e,this)}))),function(e){return f.apply(this,arguments)})},{key:"getConversationByUniqueName",value:(l=Sa(bl.mark((function e(t){var n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.next=4,this.conversations.myConversationsRead.promise;case 4:return e.next=6,this.conversations.getConversationByUniqueName(t);case 6:if(n=e.sent){e.next=9;break}throw new Error("Conversation with unique name ".concat(t," is not found."));case 9:return e.abrupt("return",n);case 10:case"end":return e.stop()}}),e,this)}))),function(e){return l.apply(this,arguments)})},{key:"getSubscribedConversations",value:(c=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.abrupt("return",this.conversationsPromise.then((function(e){return e.getConversations()})));case 3:case"end":return e.stop()}}),e,this)}))),function(){return c.apply(this,arguments)})},{key:"createConversation",value:(u=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return t=t||{},e.abrupt("return",this.conversationsPromise.then((function(e){return e.addConversation(t)})));case 4:case"end":return e.stop()}}),e,this)}))),function(e){return u.apply(this,arguments)})},{key:"setPushRegistrationId",value:(o=Sa(bl.mark((function e(t,n){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return this._subscribeToPushNotifications(t),this.services.notificationClient.setPushRegistrationId(t,n),e.next=6,this.services.notificationClient.commitChanges();case 6:case"end":return e.stop()}}),e,this)}))),function(e,t){return o.apply(this,arguments)})},{key:"unsetPushRegistrationId",value:(s=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return this._unsubscribeFromPushNotifications(t),e.next=5,this.services.notificationClient.commitChanges();case 5:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"removePushRegistrations",value:(a=Sa(bl.mark((function e(t,n){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.notificationClient.removeRegistrations(t,n);case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"handlePushNotification",value:(i=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:wA.debug("handlePushNotification, notificationPayload=",t),this.emit("pushNotification",vA.parsePushNotification(t));case 4:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"getUser",value:(r=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.abrupt("return",this.services.users.getUser(t));case 3:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"getSubscribedUsers",value:(n=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.abrupt("return",this.services.users.getSubscribedUsers());case 3:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})}],[{key:"populateInitRegistrations",value:function(e){e.populateInitRegistrations([gg.TYPING_INDICATOR]),BR.populateInitRegistrations(e)}},{key:"create",value:(t=Sa(bl.mark((function e(t,n){var r;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==n||!n.twilsockClient){e.next=2;break}throw new Error("Obsolete usage of ConversationsClient.create() factory method: if you pass twilsock from the outside then you must use ConversationsClient constructor and be prepared to work with uninitialized client.");case 2:return r=new vA(t,n),e.next=5,r._ensureReady;case 5:return e.abrupt("return",r);case 6:case"end":return e.stop()}}),e)}))),function(e,n){return t.apply(this,arguments)})},{key:"parsePushNotificationChatData",value:function(e){var t={};for(var n in vA.supportedPushDataFields)void 0!==e[n]&&null!==e[n]&&("message_index"===n?null!==eh(e[n])&&(t[vA.supportedPushDataFields[n]]=Number(e[n])):t[vA.supportedPushDataFields[n]]=e[n]);return t}},{key:"parsePushNotification",value:function(e){if(wA.debug("parsePushNotification, notificationPayload=",e),void 0!==e.aps){if(!e.twi_message_type)throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");var t,n=vA.parsePushNotificationChatData(e),r=e.aps,i=null;return"string"==typeof r.alert?t=r.alert||null:(t=r.alert.body||null,i=r.alert.title||null),new PushNotification({title:i,body:t,sound:r.sound||null,badge:r.badge||null,action:r.category||null,type:e.twi_message_type,data:n})}if(void 0!==e.data){var a=e.data;if(!a.twi_message_type)throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");var s=vA.parsePushNotificationChatData(e.data);return new PushNotification({title:a.twi_title||null,body:a.twi_body||null,sound:a.twi_sound||null,badge:null,action:a.twi_action||null,type:a.twi_message_type,data:s})}throw new Error("Provided push notification payload is not Programmable Chat notification")}}]),Client}(Dy),ja(pA,"version",xA),ja(pA,"supportedPushChannels",["fcm","apn"]),ja(pA,"supportedPushDataFields",{conversation_sid:"conversationSid",message_sid:"messageSid",message_index:"messageIndex"}),ja(pA,"conversationAdded","conversationAdded"),ja(pA,"conversationJoined","conversationJoined"),ja(pA,"conversationLeft","conversationLeft"),ja(pA,"conversationRemoved","conversationRemoved"),ja(pA,"conversationUpdated","conversationUpdated"),ja(pA,"participantJoined","participantJoined"),ja(pA,"participantLeft","participantLeft"),ja(pA,"participantUpdated","participantUpdated"),ja(pA,"messageAdded","messageAdded"),ja(pA,"messageRemoved","messageRemoved"),ja(pA,"messageUpdated","messageUpdated"),ja(pA,"tokenAboutToExpire","tokenAboutToExpire"),ja(pA,"tokenExpired","tokenExpired"),ja(pA,"typingEnded","typingEnded"),ja(pA,"typingStarted","typingStarted"),ja(pA,"pushNotification","pushNotification"),ja(pA,"userSubscribed","userSubscribed"),ja(pA,"userUnsubscribed","userUnsubscribed"),ja(pA,"userUpdated","userUpdated"),ja(pA,"stateChanged","stateChanged"),ja(pA,"connectionStateChanged","connectionStateChanged"),ja(pA,"connectionError","connectionError"),vA=hA),wl([Xv(Vv),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"updateToken",null),wl([Xv(Vv),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"getConversationBySid",null),wl([Xv(Vv),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"getConversationByUniqueName",null),wl([Xv(["undefined",Kv("conversation options",{friendlyName:["string","undefined"],isPrivate:["boolean","undefined"],uniqueName:["string","undefined"]})]),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],e.Client.prototype,"createConversation",null),wl([Xv($v("fcm","apn"),"string"),xl("design:type",Function),xl("design:paramtypes",[String,String]),xl("design:returntype",Promise)],e.Client.prototype,"setPushRegistrationId",null),wl([Xv($v("fcm","apn")),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"unsetPushRegistrationId",null),wl([Xv($v("fcm","apn"),Vv),xl("design:type",Function),xl("design:paramtypes",[String,String]),xl("design:returntype",Promise)],e.Client.prototype,"removePushRegistrations",null),wl([Xv(Hv),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],e.Client.prototype,"handlePushNotification",null),wl([Xv(Vv),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"getUser",null),wl([Xv("string",["undefined",Hv]),xl("design:type",Function),xl("design:paramtypes",[String,Object]),xl("design:returntype",Promise)],e.Client,"create",null),wl([Qv(Hv),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",PushNotification)],e.Client,"parsePushNotification",null),e.Client=vA=wl([Yv(Vv,[Hv,"undefined"]),xl("design:paramtypes",[String,Object])],e.Client),e.AggregatedDeliveryReceipt=AggregatedDeliveryReceipt,e.Conversation=Conversation,e.DetailedDeliveryReceipt=DetailedDeliveryReceipt,e.Media=Media,e.Message=Message,e.MessageBuilder=qP,e.NotificationTypes=gg,e.Participant=Participant,e.PushNotification=PushNotification,e.RestPaginator=AP,e.UnsentMessage=BP,e.User=User,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
|
144
|
+
function h(e,t,n,r){var i,a=arguments.length,s=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":Ca(Reflect))&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(s=(a<3?i(s):a>3?i(t,n,s):i(t,n))||s);return a>3&&s&&Object.defineProperty(t,n,s),s}function v(e,t){if("object"===("undefined"==typeof Reflect?"undefined":Ca(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function y(e,t){return["".concat((new Date).toISOString()," MCS Client ").concat(e,":")].concat(Array.from(t))}var m=function(){function e(t){Ma(this,e),f.default(this,"prefix",""),this.prefix=null!=t&&t.length>0?t+" ":""}return Ta(e,[{key:"setLevel",value:function(e){p.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.trace.apply(null,y(this.prefix+"T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.debug.apply(null,y(this.prefix+"D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.info.apply(null,y(this.prefix+"I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.warn.apply(null,y(this.prefix+"W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.error.apply(null,y(this.prefix+"E",t))}}],[{key:"scope",value:function(t){return new e(t)}},{key:"setLevel",value:function(e){p.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.trace.apply(null,y("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.debug.apply(null,y("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.info.apply(null,y("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.warn.apply(null,y("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.error.apply(null,y("E",t))}}]),e}(),g=function(e,t){return"".concat((n=e,n.startsWith("http")?"":function(e){return"https://mcs.".concat(null!=e?e:"us1",".twilio.com")}(t))).concat(e);var n},b=function(){function e(t,n,r,i){var a,s,o,u,c,l;Ma(this,e);var f=null!==(a=null!==(s=i.MCS)&&void 0!==s?s:i)&&void 0!==a?a:{};this.region=null!==(o=null!==(u=f.region)&&void 0!==u?u:i.region)&&void 0!==o?o:"us1",this.mediaUrl=g(n,this.region),this.mediaSetUrl=r?g(r):"".concat(this.mediaUrl,"Set"),this.token=t,this.retryWhenThrottledOverride=null===(c=f.retryWhenThrottledOverride)||void 0===c||c,this.backoffConfigOverride=null!==(l=f.backoffConfigOverride)&&void 0!==l?l:e.backoffConfigDefault}return Ta(e,[{key:"updateToken",value:function(e){this.token=e}}],[{key:"backoffConfigDefault",get:function(){return{min:1e3,max:4e3,maxAttemptsCount:3}}},{key:"retryWhenThrottledDefault",get:function(){return true}}]),e}(),Media=function(){function Media(e,t,n){Ma(this,Media),this.config=e,this.network=t,this._update(n)}return Ta(Media,[{key:"sid",get:function(){return this.state.sid}},{key:"serviceSid",get:function(){return this.state.serviceSid}},{key:"dateCreated",get:function(){return this.state.dateCreated}},{key:"dateUpdated",get:function(){return this.state.dateUpdated}},{key:"contentType",get:function(){return this.state.contentType}},{key:"size",get:function(){return this.state.size}},{key:"fileName",get:function(){return this.state.filename}},{key:"filename",get:function(){return this.state.filename}},{key:"category",get:function(){return this.state.category}},{key:"getContentUrl",value:function(){var e=this;return l.default(d.default.mark((function t(){var n;return d.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.network.get("".concat(e.config.mediaUrl,"/").concat(e.sid));case 2:return n=t.sent,e._update(n.body),t.abrupt("return",Promise.resolve(e.state.contentDirectUrl));case 5:case"end":return t.stop()}}),t)})))()}},{key:"getCachedContentUrl",value:function(){var e=this;return l.default(d.default.mark((function t(){return d.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!e.state.contentDirectUrl){t.next=2;break}return t.abrupt("return",Promise.resolve(e.state.contentDirectUrl));case 2:return t.next=4,e.getContentUrl();case 4:return t.abrupt("return",t.sent);case 5:case"end":return t.stop()}}),t)})))()}},{key:"_update",value:function(e){var t,n,r,i;this.state={sid:e.sid,serviceSid:e.service_sid,channelSid:e.channel_sid,messageSid:e.message_sid,dateCreated:e.date_created?new Date(e.date_created):null,dateUploadUpdated:e.date_upload_updated?new Date(e.date_upload_updated):null,dateUpdated:e.date_updated?new Date(e.date_updated):null,size:e.size,contentType:e.content_type,author:e.author,url:e.url,contentUrl:e.links.content,contentDirectUrl:null!==(t=e.links.content_direct_temporary)&&void 0!==t?t:null,filename:null!==(n=e.filename)&&void 0!==n?n:null,category:null!==(r=e.category)&&void 0!==r?r:"media",isMultipartUpstream:null!==(i=e.is_multipart_upstream)&&void 0!==i&&i}}}]),Media}(),k=function(e){Oa(n,e);var t=tP(n);function n(e,r,i,a,s){var o;return Ma(this,n),(o=t.call(this,e)).code=r,o.body=i,o.status=a,o.headers=s,o}return n}(WR(Error)),w=t.XMLHttpRequest||{};function x(e){var t=e.getResponseHeader("Content-Type");if(!t||0!==t.indexOf("application/json")||0===e.responseText.length)return e.responseText;try{return JSON.parse(e.responseText)}catch(t){return e.responseText}}var _,S,E=function(){function e(){Ma(this,e)}return Ta(e,[{key:"get",value:function(t,n){return l.default(d.default.mark((function r(){return d.default.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",e.request("GET",t,n));case 1:case"end":return r.stop()}}),r)})))()}},{key:"post",value:function(t,n,r){return l.default(d.default.mark((function i(){return d.default.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return i.abrupt("return",e.request("POST",t,n,r));case 1:case"end":return i.stop()}}),i)})))()}}],[{key:"request",value:function(e,t,n,r){return l.default(d.default.mark((function i(){return d.default.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return i.abrupt("return",new Promise((function(i,a){var s=new w;for(var o in s.open(e,t,!0),s.onreadystatechange=function(){if(4===s.readyState){var e,t=(e=s.getAllResponseHeaders())?e.split("\r\n").map((function(e){return e.split(": ")})).filter((function(e){return 2===e.length&&e[1].length>0})).reduce((function(e,t){return e[t[0]]=t[1],e}),{}):{},n=x(s);if(200<=s.status&&s.status<300)i({status:s.status,headers:t,body:n});else{var r,o,u=null!==(r=s.statusText)&&void 0!==r?r:"NONE";o="string"==typeof n?n&&1===n.split("\n",2).length?n:"":JSON.stringify(n);var c="".concat(s.status,": [").concat(u,"] ").concat(o);a(new k(c,s.status,n,u,t))}}},n)s.setRequestHeader(o,n[o]),"Content-Type"===o&&"application/json"===n[o]&&(r=JSON.stringify(r));s.send(r)})));case 1:case"end":return i.stop()}}),i)})))()}}]),e}(),T=m.scope("Network"),R=function(){function e(t,n){Ma(this,e),this.config=t,this.transport=n}return Ta(e,[{key:"backoffConfig",value:function(){return Object.assign(b.backoffConfigDefault,this.config.backoffConfigOverride)}},{key:"retryWhenThrottled",value:function(){var e,t;return null!==(e=null!==(t=this.config.retryWhenThrottledOverride)&&void 0!==t?t:b.retryWhenThrottledDefault)&&void 0!==e&&e}},{key:"executeWithRetry",value:function(e,t){var n=this;return l.default(d.default.mark((function r(){return d.default.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",new Promise((function(r,i){var a=[502,503,504];t&&a.push(429);var o=new s.Retrier(n.backoffConfig());o.on("attempt",l.default(d.default.mark((function t(){var n;return d.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,e();case 3:n=t.sent,o.succeeded(n),t.next=10;break;case 7:t.prev=7,t.t0=t.catch(0),a.indexOf(t.t0.status)>-1||"Twilsock disconnected"===t.t0.message?o.failed(t.t0):(o.removeAllListeners(),o.cancel(),i(t.t0));case 10:case"end":return t.stop()}}),t,null,[[0,7]])})))),o.on("succeeded",(function(e){r(e)})),o.on("cancelled",(function(e){return i(e)})),o.on("failed",(function(e){return i(e)})),o.start()})));case 1:case"end":return r.stop()}}),r)})))()}},{key:"get",value:function(e){var t=this;return l.default(d.default.mark((function n(){var r,i;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return r={"X-Twilio-Token":t.config.token},T.trace("sending GET request to ",e," headers ",r),n.prev=2,n.next=5,t.executeWithRetry((function(){return t.transport.get(e,r)}),t.retryWhenThrottled());case 5:return i=n.sent,T.trace("response",i),n.abrupt("return",i);case 10:throw n.prev=10,n.t0=n.catch(2),T.debug("get() error ".concat(n.t0)),n.t0;case 14:case"end":return n.stop()}}),n,null,[[2,10]])})))()}},{key:"post",value:function(e,n,r,i,a){var s=this;return l.default(d.default.mark((function o(){var u,c,l;return d.default.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return u={"X-Twilio-Token":s.config.token},"undefined"!=typeof FormData&&r instanceof FormData||!i||Object.assign(u,{"Content-Type":i}),c=new URL(e),n&&c.searchParams.append("Category",n),a&&c.searchParams.append("Filename",a),T.trace("sending POST request to ".concat(e," with headers ").concat(u)),o.prev=6,o.next=9,s.transport.post(c.href,u,r);case 9:l=o.sent,o.next=18;break;case 12:if(o.prev=12,o.t0=o.catch(6),!(void 0===t.XMLHttpRequest&&r instanceof FormData)){o.next=16;break}throw new TypeError("Posting FormData supported only with browser engine's FormData");case 16:throw T.debug("post() error ".concat(o.t0)),o.t0;case 18:return T.trace("response",l),o.abrupt("return",l);case 20:case"end":return o.stop()}}),o,null,[[6,12]])})))()}}]),e}(),I=m.scope("");e.default=(S=_=function(){function Client(e,t,n){var r,i;Ma(this,Client);var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};this.options=a,this.options.logLevel=null!==(r=this.options.logLevel)&&void 0!==r?r:"silent",this.config=new b(e,t,n,this.options),I.setLevel(this.options.logLevel),this.options.transport=null!==(i=this.options.transport)&&void 0!==i?i:new E,this.transport=this.options.transport,this.network=new R(this.config,this.transport)}return Ta(Client,[{key:"updateToken",value:function(e){I.info("updateToken"),this.config.updateToken(e)}},{key:"get",value:function(e){var t=this;return l.default(d.default.mark((function n(){var r;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,t.network.get("".concat(t.config.mediaUrl,"/").concat(e));case 2:return r=n.sent,n.abrupt("return",new Media(t.config,t.network,r.body));case 4:case"end":return n.stop()}}),n)})))()}},{key:"post",value:function(e,t,n,r){var i=this;return l.default(d.default.mark((function a(){var s;return d.default.wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,i.network.post(i.config.mediaUrl,null!=n?n:"media",t,e,r);case 2:return s=a.sent,a.abrupt("return",new Media(i.config,i.network,s.body));case 4:case"end":return a.stop()}}),a)})))()}},{key:"postFormData",value:function(e,t){var n=this;return l.default(d.default.mark((function r(){var i;return d.default.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,n.network.post(n.config.mediaUrl,null!=t?t:"media",e);case 2:return i=r.sent,r.abrupt("return",new Media(n.config,n.network,i.body));case 4:case"end":return r.stop()}}),r)})))()}},{key:"mediaSetGet",value:function(e){var t=this;return l.default(d.default.mark((function n(){var r,i;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return r={command:"get",list:e.map((function(e){return{media_sid:e}}))},n.next=3,t.network.post("".concat(t.config.mediaSetUrl),null,r,"application/json");case 3:return i=n.sent,n.abrupt("return",i.body.map((function(e){if(200!==e.code)throw new Error("Failed to obtain detailed information about Media items (failed SID ".concat(e.media_record.sid,")"));return new Media(t.config,t.network,e.media_record)})));case 5:case"end":return n.stop()}}),n)})))()}}]),Client}(),f.default(_,"version","0.5.3-rc.0"),S),h([o.validateTypes(o.nonEmptyString),v("design:type",Function),v("design:paramtypes",[String]),v("design:returntype",void 0)],e.default.prototype,"updateToken",null),h([o.validateTypesAsync(o.nonEmptyString),v("design:type",Function),v("design:paramtypes",[String]),v("design:returntype",Promise)],e.default.prototype,"get",null),e.default=h([o.validateConstructorTypes(o.nonEmptyString,o.nonEmptyString,[o.nonEmptyString,o.literal(null)],[o.pureObject,"undefined"]),v("design:paramtypes",[String,String,Object,Object])],e.default),e.Client=e.default,e.McsClient=e.default,e.McsMedia=Media,e.Media=Media,e.default=e.default}($R);var rP=is,iP="ArrayBuffer",aP=Gk.ArrayBuffer;function sP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}In({global:!0,forced:i.ArrayBuffer!==aP},{ArrayBuffer:aP}),rP(iP);var oP=rd.scope("Participant"),Participant=function(e){Oa(Participant,e);var t,n,r,i=sP(Participant);function Participant(e,t,n,r,a){var s,o,u;if(Ma(this,Participant),(u=i.call(this)).conversation=n,u.links=r,u.services=a,u.state={attributes:nh(e.attributes,"Retrieved malformed attributes from the server for participant: "+t,oP),dateCreated:e.dateCreated?th(e.dateCreated):null,dateUpdated:e.dateCreated?th(e.dateUpdated):null,sid:t,typingTimeout:null,isTyping:!1,identity:e.identity,roleSid:null!==(s=e.roleSid)&&void 0!==s?s:"",lastReadMessageIndex:Number.isInteger(e.lastConsumedMessageIndex)?e.lastConsumedMessageIndex:null,lastReadTimestamp:e.lastConsumptionTimestamp?th(e.lastConsumptionTimestamp):null,type:e.type||"chat",userInfo:e.userInfo,bindings:null!==(o=e.bindings)&&void 0!==o?o:{}},!e.identity&&!e.type)throw new Error("Received invalid Participant object from server: Missing identity or type of Participant.");return u}return Ta(Participant,[{key:"sid",get:function(){return this.state.sid}},{key:"attributes",get:function(){return this.state.attributes}},{key:"dateCreated",get:function(){return this.state.dateCreated}},{key:"dateUpdated",get:function(){return this.state.dateUpdated}},{key:"identity",get:function(){return this.state.identity}},{key:"isTyping",get:function(){return this.state.isTyping}},{key:"lastReadMessageIndex",get:function(){return this.state.lastReadMessageIndex}},{key:"lastReadTimestamp",get:function(){return this.state.lastReadTimestamp}},{key:"roleSid",get:function(){return this.state.roleSid}},{key:"type",get:function(){return this.state.type}},{key:"bindings",get:function(){var e;return null!==(e=this.state.bindings)&&void 0!==e?e:{}}},{key:"_startTyping",value:function(e){var t=this;return this.state.typingTimeout&&clearTimeout(this.state.typingTimeout),this.state.isTyping=!0,this.emit("typingStarted",this),this.conversation.emit("typingStarted",this),this.state.typingTimeout=Number(setTimeout((function(){return t._endTyping()}),e)),this}},{key:"_endTyping",value:function(){this.state.typingTimeout&&(this.state.isTyping=!1,this.emit("typingEnded",this),this.conversation.emit("typingEnded",this),clearInterval(this.state.typingTimeout),this.state.typingTimeout=null)}},{key:"_update",value:function(e){var t=[],n=nh(e.attributes,"Retrieved malformed attributes from the server for participant: "+this.state.sid,oP);e.attributes&&!By(this.state.attributes,n)&&(this.state.attributes=n,t.push("attributes"));var r=th(e.dateUpdated);e.dateUpdated&&(null==r?void 0:r.getTime())!==(this.state.dateUpdated&&this.state.dateUpdated.getTime())&&(this.state.dateUpdated=r,t.push("dateUpdated"));var i=th(e.dateCreated);if(e.dateCreated&&(null==i?void 0:i.getTime())!==(this.state.dateCreated&&this.state.dateCreated.getTime())&&(this.state.dateCreated=i,t.push("dateCreated")),e.roleSid&&this.state.roleSid!==e.roleSid&&(this.state.roleSid=e.roleSid,t.push("roleSid")),!Number.isInteger(e.lastConsumedMessageIndex)&&null!==e.lastConsumedMessageIndex||this.state.lastReadMessageIndex===e.lastConsumedMessageIndex||(this.state.lastReadMessageIndex=e.lastConsumedMessageIndex,t.push("lastReadMessageIndex")),e.lastConsumptionTimestamp){var a=new Date(e.lastConsumptionTimestamp);this.state.lastReadTimestamp&&this.state.lastReadTimestamp.getTime()===a.getTime()||(this.state.lastReadTimestamp=a,t.push("lastReadTimestamp"))}return e.bindings&&!By(this.state.bindings,e.bindings)&&(this.state.bindings=e.bindings,t.push("bindings")),t.length>0&&this.emit("updated",{participant:this,updateReasons:t}),this}},{key:"getUser",value:(r=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("chat"==this.type){e.next=2;break}throw new Error("Getting User is not supported for this Participant type: "+this.type);case 2:return e.abrupt("return",this.services.users.getUser(this.state.identity,this.state.userInfo));case 3:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"remove",value:(n=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.conversation.removeParticipant(this));case 1:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"updateAttributes",value:(t=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{attributes:JSON.stringify(t)});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),Participant}(Dy);function uP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}ja(Participant,"typingStarted","typingStarted"),ja(Participant,"typingEnded","typingEnded"),ja(Participant,"updated","updated"),wl([Xv(Zv),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],Participant.prototype,"updateAttributes",null);var cP=rd.scope("Participants"),lP=function(e){Oa(u,e);var t,n,r,i,a,s,o=uP(u);function u(e,t,n,r,i){var a;return Ma(this,u),ja(Ra(a=o.call(this)),"rosterEntityPromise",null),a.conversation=e,a.participants=t,a.links=n,a.configuration=r,a.services=i,a}return Ta(u,[{key:"unsubscribe",value:(s=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.rosterEntityPromise){e.next=6;break}return e.next=3,this.rosterEntityPromise;case 3:e.sent.close(),this.rosterEntityPromise=null;case 6:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"subscribe",value:function(e){var t=this;return this.rosterEntityPromise=this.rosterEntityPromise||this.services.syncClient.map({id:e,mode:"open_existing"}).then((function(e){e.on("itemAdded",(function(e){cP.debug(t.conversation.sid+" itemAdded: "+e.item.key),t.upsertParticipant(e.item.key,e.item.data).then((function(e){t.emit("participantJoined",e)}))})),e.on("itemRemoved",(function(e){cP.debug(t.conversation.sid+" itemRemoved: "+e.key);var n=e.key;if(t.participants.has(n)){var r=t.participants.get(n);t.participants.delete(n),r&&t.emit("participantLeft",r)}})),e.on("itemUpdated",(function(e){cP.debug(t.conversation.sid+" itemUpdated: "+e.item.key),t.upsertParticipant(e.item.key,e.item.data)}));var n=[];return e.getItems().then((function e(r){return r.items.forEach((function(e){n.push(t.upsertParticipant(e.key,e.data))})),r.hasNextPage?r.nextPage().then(e):null})).then((function(){return Promise.all(n)})).then((function(){return e}))})).catch((function(e){throw t.rosterEntityPromise=null,"disconnected"!=t.services.syncClient.connectionState&&cP.error("Failed to get roster object for conversation",t.conversation.sid,e),cP.debug("ERROR: Failed to get roster object for conversation",t.conversation.sid,e),e}))}},{key:"upsertParticipant",value:(a=Sa(bl.mark((function e(t,n){var r,i,a=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(r=this.participants.get(t))){e.next=3;break}return e.abrupt("return",r._update(n));case 3:return i={self:"".concat(this.links.participants,"/").concat(t)},r=new Participant(n,t,this.conversation,i,this.services),this.participants.set(t,r),r.on("updated",(function(e){return a.emit("participantUpdated",e)})),e.abrupt("return",r);case 8:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"getParticipants",value:(i=Sa(bl.mark((function e(){var t=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.rosterEntityPromise?this.rosterEntityPromise.then((function(){var e=[];return t.participants.forEach((function(t){return e.push(t)})),e})):[]);case 1:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"getParticipantBySid",value:(r=Sa(bl.mark((function e(t){var n=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.rosterEntityPromise?this.rosterEntityPromise.then((function(){var e=n.participants.get(t);if(!e)throw new Error("Participant with SID "+t+" was not found");return e})):null);case 1:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"getParticipantByIdentity",value:(n=Sa(bl.mark((function e(t){var n,r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=null,e.abrupt("return",this.rosterEntityPromise?this.rosterEntityPromise.then((function(){if(r.participants.forEach((function(e){e.identity===t&&(n=e)})),!n)throw new Error("Participant with identity "+t+" was not found");return n})):null);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"add",value:(t=Sa(bl.mark((function e(t,n){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.participants,{identity:t,attributes:void 0!==n?JSON.stringify(n):void 0});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e,n){return t.apply(this,arguments)})},{key:"addNonChatParticipant",value:function(e,t){var n,r,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return this.services.commandExecutor.mutateResource("post",this.links.participants,{attributes:void 0!==i?JSON.stringify(i):void 0,messaging_binding:{address:t,proxy_address:e,name:null==a||null===(n=a.email)||void 0===n?void 0:n.name,level:null==a||null===(r=a.email)||void 0===r?void 0:r.level}})}},{key:"remove",value:function(e){return this.services.commandExecutor.mutateResource("delete","".concat(this.links.participants,"/").concat(e))}}]),u}(Dy),fP=In,dP=On,pP=Q,hP=Ut,vP=gr,yP=s,mP=T_,gP=ec,bP=I_,kP=O_,wP=L,xP=P_,_P=[],SP=_P.sort,EP=yP((function(){_P.sort(void 0)})),TP=yP((function(){_P.sort(null)})),RP=gP("sort"),IP=!yP((function(){if(wP)return wP<70;if(!(bP&&bP>3)){if(kP)return!0;if(xP)return xP<603;var e,t,n,r,i="";for(e=65;e<76;e++){switch(t=String.fromCharCode(e),e){case 66:case 69:case 70:case 72:n=3;break;case 68:case 71:n=4;break;default:n=2}for(r=0;r<47;r++)_P.push({k:t+r,v:n})}for(_P.sort((function(e,t){return t.v-e.v})),r=0;r<_P.length;r++)t=_P[r].k.charAt(0),i.charAt(i.length-1)!==t&&(i+=t);return"DGBEFHACIJK"!==i}}));fP({target:"Array",proto:!0,forced:EP||!TP||!RP||!IP},{sort:function(e){void 0!==e&&dP(e);var t=pP(this);if(IP)return void 0===e?SP.call(t):SP.call(t,e);var n,r,i=[],a=hP(t.length);for(r=0;r<a;r++)r in t&&i.push(t[r]);for(n=(i=mP(i,function(e){return function(t,n){return void 0===n?-1:void 0===t?1:void 0!==e?+e(t,n)||0:vP(t)>vP(n)?1:-1}}(e))).length,r=0;r<n;)t[r]=i[r++];for(;r<a;)delete t[r++];return t}});var OP=JR,CP=k,PP=gr;In({target:"String",proto:!0,forced:!HR("includes")},{includes:function(e){return!!~PP(CP(this)).indexOf(PP(OP(e)),arguments.length>1?arguments[1]:void 0)}});var Media=function(){function Media(e,t){Ma(this,Media),ja(this,"mcsMedia",null),this.services=t,e instanceof $R.McsMedia&&(this.mcsMedia=e),this.state={sid:e.sid,category:e.category,filename:e.filename,contentType:e.contentType,size:e.size}}var e,t,n;return Ta(Media,[{key:"sid",get:function(){return this.state.sid}},{key:"filename",get:function(){return this.state.filename}},{key:"contentType",get:function(){return this.state.contentType}},{key:"size",get:function(){return this.state.size}},{key:"category",get:function(){return this.state.category}},{key:"getContentTemporaryUrl",value:(n=Sa(bl.mark((function e(){var t,n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._fetchMcsMedia();case 2:return e.abrupt("return",null!==(t=null===(n=this.mcsMedia)||void 0===n?void 0:n.getContentUrl())&&void 0!==t?t:null);case 3:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"getCachedTemporaryUrl",value:(t=Sa(bl.mark((function e(){var t,n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._fetchMcsMedia();case 2:return e.abrupt("return",null!==(t=null===(n=this.mcsMedia)||void 0===n?void 0:n.getCachedContentUrl())&&void 0!==t?t:null);case 3:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"_fetchMcsMedia",value:(e=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.mcsMedia){e.next=8;break}if(!this.services.mcsClient){e.next=7;break}return e.next=4,this.services.mcsClient.get(this.state.sid);case 4:this.mcsMedia=e.sent,e.next=8;break;case 7:throw new Error("Media Content Service is unavailable");case 8:case"end":return e.stop()}}),e,this)}))),function(){return e.apply(this,arguments)})}]),Media}(),AggregatedDeliveryReceipt=function(){function AggregatedDeliveryReceipt(e){Ma(this,AggregatedDeliveryReceipt),this.state=e}return Ta(AggregatedDeliveryReceipt,[{key:"total",get:function(){return this.state.total}},{key:"sent",get:function(){return this.state.sent}},{key:"delivered",get:function(){return this.state.delivered}},{key:"read",get:function(){return this.state.read}},{key:"undelivered",get:function(){return this.state.undelivered}},{key:"failed",get:function(){return this.state.failed}},{key:"_update",value:function(e){this.state=e}},{key:"_isEquals",value:function(e){var t=this.total===e.total,n=this.sent===e.sent,r=this.delivered===e.delivered,i=this.read===e.read,a=this.undelivered===e.undelivered,s=this.failed===e.failed;return t&&n&&r&&i&&a&&s}}]),AggregatedDeliveryReceipt}(),AP=function(){function e(t,n,r,i){Ma(this,e),this.state={prevToken:r,nextToken:i,source:n,items:t}}return Ta(e,[{key:"hasNextPage",get:function(){return!!this.state.nextToken}},{key:"hasPrevPage",get:function(){return!!this.state.prevToken}},{key:"items",get:function(){return this.state.items}},{key:"nextPage",value:function(){return this.hasNextPage?this.state.source(this.state.nextToken):Promise.reject(new Error("No next page"))}},{key:"prevPage",value:function(){return this.hasPrevPage?this.state.source(this.state.prevToken):Promise.reject(new Error("No previous page"))}}]),e}(),DetailedDeliveryReceipt=function DetailedDeliveryReceipt(e){Ma(this,DetailedDeliveryReceipt),this.sid=e.sid,this.messageSid=e.message_sid,this.conversationSid=e.conversation_sid,this.channelMessageSid=e.channel_message_sid,this.participantSid=e.participant_sid,this.status=e.status||"queued",this.errorCode=e.error_code||0,this.dateCreated=e.date_created,this.dateUpdated=e.date_updated};function jP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}var MP=rd.scope("Message"),Message=function(e){Oa(Message,e);var t,n,r,i,a,s,o,u=jP(Message);function Message(e,t,n,r,i,a){var s,o,c,l,f;return Ma(this,Message),(f=u.call(this)).conversation=n,f.links=r,f.configuration=i,f.services=a,f.state={sid:t.sid,index:e,author:t.author,subject:t.subject,body:null!==(s=t.text)&&void 0!==s?s:null,timestamp:t.timestamp?new Date(t.timestamp):null,dateUpdated:t.dateUpdated?new Date(t.dateUpdated):null,lastUpdatedBy:null!==(o=t.lastUpdatedBy)&&void 0!==o?o:null,attributes:nh(t.attributes,"Got malformed attributes for the message ".concat(t.sid),MP),type:null!==(c=t.type)&&void 0!==c?c:"text",media:t.type&&"media"===t.type&&t.media?new Media(t.media,f.services):null,medias:t.type&&"media"===t.type&&t.medias?t.medias.map((function(e){return new Media(e,f.services)})):null,participantSid:null!==(l=t.memberSid)&&void 0!==l?l:null,aggregatedDeliveryReceipt:t.delivery?new AggregatedDeliveryReceipt(t.delivery):null},f}return Ta(Message,[{key:"sid",get:function(){return this.state.sid}},{key:"author",get:function(){return this.state.author}},{key:"subject",get:function(){return this.state.subject}},{key:"body",get:function(){return this.state.body}},{key:"dateUpdated",get:function(){return this.state.dateUpdated}},{key:"index",get:function(){return this.state.index}},{key:"lastUpdatedBy",get:function(){return this.state.lastUpdatedBy}},{key:"dateCreated",get:function(){return this.state.timestamp}},{key:"attributes",get:function(){return this.state.attributes}},{key:"type",get:function(){return this.state.type}},{key:"media",get:function(){return this.state.media}},{key:"attachedMedia",get:function(){return this.getMediaByCategory(["media"])}},{key:"participantSid",get:function(){return this.state.participantSid}},{key:"aggregatedDeliveryReceipt",get:function(){return this.state.aggregatedDeliveryReceipt}},{key:"getMediaByCategory",value:function(e){var t;return(null!==(t=this.state.medias)&&void 0!==t?t:[]).filter((function(t){return e.includes(t.category)}))}},{key:"getEmailBody",value:function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"text/plain";return null!==(e=null===(t=this.getMediaByCategory(["body"]))||void 0===t?void 0:t.filter((function(e){return e.contentType==n})).shift())&&void 0!==e?e:null}},{key:"getEmailHistory",value:function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"text/plain";return null!==(e=null===(t=this.getMediaByCategory(["history"]))||void 0===t?void 0:t.filter((function(e){return e.contentType==n})).shift())&&void 0!==e?e:null}},{key:"_update",value:function(e){var t=[];!e.text&&"string"!=typeof e.text||e.text===this.state.body||(this.state.body=e.text,t.push("body")),e.subject&&e.subject!==this.state.subject&&(this.state.subject=e.subject,t.push("subject")),e.lastUpdatedBy&&e.lastUpdatedBy!==this.state.lastUpdatedBy&&(this.state.lastUpdatedBy=e.lastUpdatedBy,t.push("lastUpdatedBy")),e.author&&e.author!==this.state.author&&(this.state.author=e.author,t.push("author")),e.dateUpdated&&new Date(e.dateUpdated).getTime()!==(this.state.dateUpdated&&this.state.dateUpdated.getTime())&&(this.state.dateUpdated=new Date(e.dateUpdated),t.push("dateUpdated")),e.timestamp&&new Date(e.timestamp).getTime()!==(this.state.timestamp&&this.state.timestamp.getTime())&&(this.state.timestamp=new Date(e.timestamp),t.push("dateCreated"));var n=nh(e.attributes,"Got malformed attributes for the message ".concat(this.sid),MP);By(this.state.attributes,n)||(this.state.attributes=n,t.push("attributes"));var r=e.delivery,i=this.state.aggregatedDeliveryReceipt;!!(r&&r.total&&r.delivered&&r.failed&&r.read&&r.sent&&r.undelivered)&&(i?i._isEquals(r)||(i._update(r),t.push("deliveryReceipt")):(this.state.aggregatedDeliveryReceipt=new AggregatedDeliveryReceipt(r),t.push("deliveryReceipt"))),t.length>0&&this.emit("updated",{message:this,updateReasons:t})}},{key:"getParticipant",value:(o=Sa(bl.mark((function e(){var t,n,r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=null,!this.state.participantSid){e.next=5;break}return e.next=4,this.conversation.getParticipantBySid(this.state.participantSid).catch((function(){return MP.debug('Participant with sid "'.concat(r.participantSid,'" not found for message ').concat(r.sid)),null}));case 4:t=e.sent;case 5:if(t||!this.state.author){e.next=9;break}return e.next=8,this.conversation.getParticipantByIdentity(this.state.author).catch((function(){return MP.debug('Participant with identity "'.concat(r.author,'" not found for message ').concat(r.sid)),null}));case 8:t=e.sent;case 9:if(!t){e.next=11;break}return e.abrupt("return",t);case 11:throw n="Participant with ",this.state.participantSid&&(n+="SID '"+this.state.participantSid+"' "),this.state.author&&(this.state.participantSid&&(n+="or "),n+="identity '"+this.state.author+"' "),"Participant with "===n&&(n="Participant "),n+="was not found",new Error(n);case 17:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"getDetailedDeliveryReceipts",value:(s=Sa(bl.mark((function e(){var t,n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._getDetailedDeliveryReceiptsPaginator();case 2:t=e.sent,n=[];case 4:if(n=[].concat(nP(n),nP(t.items)),t.hasNextPage){e.next=8;break}return e.abrupt("break",13);case 8:return e.next=10,t.nextPage();case 10:t=e.sent,e.next=4;break;case 13:return e.abrupt("return",n);case 14:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"remove",value:(a=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("delete",this.links.self);case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"updateBody",value:(i=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{body:t});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"updateAttributes",value:(r=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{attributes:void 0!==t?JSON.stringify(t):void 0});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"attachTemporaryUrlsFor",value:(n=Sa(bl.mark((function e(t){var n,r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=null==t?void 0:t.map((function(e){return e.sid})),!this.services.mcsClient||!n){e.next=7;break}return e.next=4,this.services.mcsClient.mediaSetGet(n);case 4:return e.abrupt("return",e.sent.map((function(e){return new Media(e,r.services)})));case 7:throw new Error("Media Content Service is unavailable");case 8:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"_getDetailedDeliveryReceiptsPaginator",value:(t=Sa(bl.mark((function e(t){var n,r,i,a=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.configuration.links.messagesReceipts.replace("%s",this.conversation.sid).replace("%s",this.sid),r=new rh(n).arg("PageToken",null==t?void 0:t.pageToken).arg("PageSize",null==t?void 0:t.pageSize).build(),e.next=4,this.services.network.get(r);case 4:return i=e.sent,e.abrupt("return",new AP(i.body.delivery_receipts.map((function(e){return new DetailedDeliveryReceipt(e)})),(function(e,t){return a._getDetailedDeliveryReceiptsPaginator({pageToken:e,pageSize:t})}),i.body.meta.previous_token,i.body.meta.next_token));case 6:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),Message}(Dy);function LP(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return NP(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return NP(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function NP(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function UP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}ja(Message,"updated","updated"),wl([Qv(Vv),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Media)],Message.prototype,"getEmailBody",null),wl([Qv(Vv),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Media)],Message.prototype,"getEmailHistory",null),wl([Xv("string"),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Message.prototype,"updateBody",null),wl([Xv(Zv),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],Message.prototype,"updateAttributes",null),wl([Xv(Gv((function(e){return[e instanceof Array&&e.length>0&&e.reduce((function(e,t){return e&&t instanceof Media}),!0),"a non-empty array of Media"]}))),xl("design:type",Function),xl("design:paramtypes",[Array]),xl("design:returntype",Promise)],Message.prototype,"attachTemporaryUrlsFor",null);var DP=rd.scope("Messages"),FP=function(e){Oa(c,e);var t,n,r,i,a,s,o,u=UP(c);function c(e,t,n){var r;return Ma(this,c),(r=u.call(this)).conversation=e,r.configuration=t,r.services=n,r.messagesByIndex=new Map,r.messagesListPromise=null,r}return Ta(c,[{key:"subscribe",value:(o=Sa(bl.mark((function e(t){var n,r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.messagesListPromise){e.next=2;break}return e.abrupt("return",this.messagesListPromise);case 2:return this.messagesListPromise=this.services.syncClient.list({id:t,mode:"open_existing"}),e.prev=3,e.next=6,this.messagesListPromise;case 6:return(n=e.sent).on("itemAdded",(function(e){DP.debug("".concat(r.conversation.sid," itemAdded: ").concat(e.item.index));var t={self:"".concat(r.conversation.links.messages,"/").concat(e.item.data.sid),conversation:r.conversation.links.self,messages_receipts:"".concat(r.conversation.links.messages,"/").concat(e.item.data.sid,"/Receipts")},n=new Message(e.item.index,e.item.data,r.conversation,t,r.configuration,r.services);r.messagesByIndex.has(n.index)?DP.debug("Message arrived, but is already known and ignored",r.conversation.sid,n.index):(r.messagesByIndex.set(n.index,n),n.on("updated",(function(e){return r.emit("messageUpdated",e)})),r.emit("messageAdded",n))})),n.on("itemRemoved",(function(e){DP.debug("#{this.conversation.sid} itemRemoved: ".concat(e.index));var t=e.index;if(r.messagesByIndex.has(t)){var n=r.messagesByIndex.get(t);if(!n)return;r.messagesByIndex.delete(n.index),n.removeAllListeners("updated"),r.emit("messageRemoved",n)}})),n.on("itemUpdated",(function(e){DP.debug("".concat(r.conversation.sid," itemUpdated: ").concat(e.item.index));var t=r.messagesByIndex.get(e.item.index);t&&t._update(e.item.data)})),e.abrupt("return",n);case 13:throw e.prev=13,e.t0=e.catch(3),this.messagesListPromise=null,"disconnected"!==this.services.syncClient.connectionState&&DP.error("Failed to get messages object for conversation",this.conversation.sid,e.t0),DP.debug("ERROR: Failed to get messages object for conversation",this.conversation.sid,e.t0),e.t0;case 19:case"end":return e.stop()}}),e,this,[[3,13]])}))),function(e){return o.apply(this,arguments)})},{key:"unsubscribe",value:(s=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.messagesListPromise){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,this.messagesListPromise;case 4:e.sent.close(),this.messagesListPromise=null;case 7:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"sendV2",value:(a=Sa(bl.mark((function e(t){var n,r,i,a,s,o,u,c,l;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:DP.debug("Sending message V2",t.mediaContent,t.attributes,t.emailOptions),r=[],i=LP(t.mediaContent),e.prev=3,i.s();case 5:if((a=i.n()).done){e.next=22;break}if(u=$y(a.value,2),c=u[0],l=u[1],DP.debug("Adding media to a message as ".concat(l instanceof FormData?"FormData":"SendMediaOptions"),l),e.t0=r,!(l instanceof FormData)){e.next=15;break}return e.next=12,this.services.mcsClient.postFormData(l,c);case 12:e.t1=e.sent,e.next=18;break;case 15:return e.next=17,this.services.mcsClient.post(null!==(s=l.contentType)&&void 0!==s?s:"",null!==(o=l.media)&&void 0!==o?o:"",c,l.filename);case 17:e.t1=e.sent;case 18:e.t2=e.t1,e.t0.push.call(e.t0,e.t2);case 20:e.next=5;break;case 22:e.next=27;break;case 24:e.prev=24,e.t3=e.catch(3),i.e(e.t3);case 27:return e.prev=27,i.f(),e.finish(27);case 30:return e.next=32,this.services.commandExecutor.mutateResource("post",this.conversation.links.messages,{body:t.text,subject:null===(n=t.emailOptions)||void 0===n?void 0:n.subject,media_sids:r.map((function(e){return e.sid})),attributes:void 0!==t.attributes?JSON.stringify(t.attributes):void 0});case 32:return e.abrupt("return",e.sent);case 33:case"end":return e.stop()}}),e,this,[[3,24,27,30]])}))),function(e){return a.apply(this,arguments)})},{key:"send",value:(i=Sa(bl.mark((function e(t){var n,r,i=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=i.length>1&&void 0!==i[1]?i[1]:{},r=i.length>2?i[2]:void 0,DP.debug("Sending text message",t,n,r),e.next=5,this.services.commandExecutor.mutateResource("post",this.conversation.links.messages,{body:null!=t?t:"",attributes:void 0!==n?JSON.stringify(n):void 0,subject:null==r?void 0:r.subject});case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"sendMedia",value:(r=Sa(bl.mark((function e(t){var n,r,i,a,s,o=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=o.length>1&&void 0!==o[1]?o[1]:{},a=o.length>2?o[2]:void 0,DP.debug("Sending media message",t,i,a),DP.debug("Sending media message as ".concat(t instanceof FormData?"FormData":"SendMediaOptions"),t,i),!(t instanceof FormData)){e.next=10;break}return e.next=7,this.services.mcsClient.postFormData(t);case 7:e.t0=e.sent,e.next=13;break;case 10:return e.next=12,this.services.mcsClient.post(null!==(n=t.contentType)&&void 0!==n?n:"",null!==(r=t.media)&&void 0!==r?r:"","media",t.filename);case 12:e.t0=e.sent;case 13:return s=e.t0,e.next=16,this.services.commandExecutor.mutateResource("post",this.conversation.links.messages,{media_sids:[s.sid],attributes:void 0!==i?JSON.stringify(i):void 0});case 16:return e.abrupt("return",e.sent);case 17:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"getMessages",value:(n=Sa(bl.mark((function e(t,n){var r,i=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=i.length>2&&void 0!==i[2]?i[2]:"backwards",e.abrupt("return",this._getMessages(t,n,r));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"_wrapPaginator",value:function(e,t,n){var r=this,i="desc"===e,a=function(){return t.nextPage().then((function(t){return r._wrapPaginator(e,t,n)}))},s=function(){return t.prevPage().then((function(t){return r._wrapPaginator(e,t,n)}))};return n(t.items).then((function(e){return{items:e.sort((function(e,t){return e.index-t.index})),hasPrevPage:i?t.hasNextPage:t.hasPrevPage,hasNextPage:i?t.hasPrevPage:t.hasNextPage,prevPage:i?a:s,nextPage:i?s:a}}))}},{key:"_upsertMessage",value:function(e,t){var n=this,r=this.messagesByIndex.get(e);if(r)return r;var i={self:"".concat(this.conversation.links.messages,"/").concat(t.sid),conversation:this.conversation.links.self,messages_receipts:"".concat(this.conversation.links.messages,"/").concat(t.sid,"/Receipts")},a=new Message(e,t,this.conversation,i,this.configuration,this.services);return this.messagesByIndex.set(a.index,a),a.on("updated",(function(e){return n.emit("messageUpdated",e)})),a}},{key:"_getMessages",value:(t=Sa(bl.mark((function e(){var t,n,r,i,a,s,o=this,u=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=u.length>0&&void 0!==u[0]?u[0]:30,n=u.length>1&&void 0!==u[1]?u[1]:"end",r=u.length>2&&void 0!==u[2]?u[2]:"forward",i="backwards"===r?"desc":"asc",e.next=6,this.messagesListPromise;case 6:return a=e.sent,e.next=9,null==a?void 0:a.getItems({from:"end"!==n?n:void 0,pageSize:t,order:i,limit:t});case 9:return s=e.sent,e.next=12,this._wrapPaginator(i,s,(function(e){return Promise.all(e.map((function(e){return o._upsertMessage(e.index,e.data)})))}));case 12:return e.abrupt("return",e.sent);case 13:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),c}(Dy),BP=function(){function e(t){Ma(this,e),ja(this,"attributes",{}),ja(this,"mediaContent",[]),ja(this,"emailOptions",{}),this.messagesEntity=t}var t;return Ta(e,[{key:"send",value:(t=Sa(bl.mark((function e(){var t;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.messagesEntity.sendV2(this);case 2:return t=e.sent,e.abrupt("return",eh(t.index));case 4:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}(),qP=function(){function e(t,n){Ma(this,e),this.limits=t,this.message=new BP(n),this.emailBodies=new Map,this.emailHistories=new Map}return Ta(e,[{key:"setBody",value:function(e){return this.message.text=e,this}},{key:"setSubject",value:function(e){return this.message.emailOptions.subject=e,this}},{key:"setAttributes",value:function(e){return this.message.attributes=e,this}},{key:"setEmailBody",value:function(e,t){return this.emailBodies.set(e,t),this}},{key:"setEmailHistory",value:function(e,t){return this.emailHistories.set(e,t),this}},{key:"addMedia",value:function(e){if("undefined"==typeof FormData&&e instanceof FormData)throw new Error("Could not add FormData content whilst not in a browser");if(!(e instanceof FormData)){var t=e;if(!t.contentType||!t.media)throw new Error("Media content in SendMediaOptions must contain non-empty contentType and media")}return this.message.mediaContent.push(["media",e]),this}},{key:"build",value:function(){var e=this;if(this.emailBodies.forEach((function(t,n){if(!e.limits.emailBodiesAllowedMimeTypes.includes(n))throw new Error("Unsupported email body MIME type ".concat(n))})),this.emailHistories.forEach((function(t,n){if(!e.limits.emailHistoriesAllowedMimeTypes.includes(n))throw new Error("Unsupported email history MIME type ".concat(n))})),this.emailBodies.size>this.limits.emailBodiesAllowedMimeTypes.length)throw new Error("Too many email bodies attached to the message (".concat(this.emailBodies.size," > ").concat(this.limits.emailBodiesAllowedMimeTypes.length,")"));if(this.emailHistories.size>this.limits.emailHistoriesAllowedMimeTypes.length)throw new Error("Too many email histories attached to the message (".concat(this.emailHistories.size," > ").concat(this.limits.emailHistoriesAllowedMimeTypes.length,")"));if(this.message.mediaContent.length>this.limits.mediaAttachmentsCountLimit)throw new Error("Too many media attachments in the message (".concat(this.message.mediaContent.length," > ").concat(this.limits.mediaAttachmentsCountLimit,")"));return this.emailBodies.forEach((function(t){e.message.mediaContent.push(["body",t])})),this.emailHistories.forEach((function(t){e.message.mediaContent.push(["history",t])})),this.message}},{key:"getPayloadContentType",value:function(e){return"undefined"!=typeof FormData&&e instanceof FormData?e.get("Content-Type"):e.contentType}}]),e}();function zP(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return WP(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return WP(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function WP(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function GP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}var $P=rd.scope("Conversation"),VP={lastMessage:"lastMessage",attributes:"attributes",createdBy:"createdBy",dateCreated:"dateCreated",dateUpdated:"dateUpdated",friendlyName:"friendlyName",lastConsumedMessageIndex:"lastConsumedMessageIndex",notificationLevel:"notificationLevel",sid:"sid",status:"status",uniqueName:"uniqueName",state:"state",bindings:"bindings"};function JP(e){try{return new Date(e)}catch(e){return null}}var Conversation=function(e){Oa(Conversation,e);var t,n,r,i,a,s,o,u,c,l,f,d,p,h,v,y,m,g,b,k,w,x,_,S,E,T,R=GP(Conversation);function Conversation(e,t,n,r,i){var a,s;Ma(this,Conversation),(s=R.call(this)).sid=t,s.links=n,s.configuration=r,s.services=i;var o=e.attributes||{},u=e.createdBy,c=JP(e.dateCreated),l=JP(e.dateUpdated),f=e.friendlyName||null,d=Number.isInteger(e.lastConsumedMessageIndex)?e.lastConsumedMessageIndex:null,p=e.uniqueName||null;try{JSON.stringify(o)}catch(e){throw new Error("Attributes must be a valid JSON object.")}s.entityName=e.channel,s.channelState={uniqueName:p,status:"notParticipating",attributes:o,createdBy:u,dateCreated:c,dateUpdated:l,friendlyName:f,lastReadMessageIndex:d,bindings:null!==(a=e.bindings)&&void 0!==a?a:{}},e.notificationLevel&&(s.channelState.notificationLevel=e.notificationLevel);var h={participants:s.links.participants};return s.participants=new Map,s.participantsEntity=new lP(Ra(s),s.participants,h,s.configuration,s.services),s.participantsEntity.on("participantJoined",(function(e){return s.emit("participantJoined",e)})),s.participantsEntity.on("participantLeft",(function(e){return s.emit("participantLeft",e)})),s.participantsEntity.on("participantUpdated",(function(e){return s.emit("participantUpdated",e)})),s.messagesEntity=new FP(Ra(s),r,i),s.messagesEntity.on("messageAdded",(function(e){return s._onMessageAdded(e)})),s.messagesEntity.on("messageUpdated",(function(e){return s.emit("messageUpdated",e)})),s.messagesEntity.on("messageRemoved",(function(e){return s.emit("messageRemoved",e)})),s}return Ta(Conversation,[{key:"uniqueName",get:function(){return this.channelState.uniqueName}},{key:"status",get:function(){return this.channelState.status}},{key:"friendlyName",get:function(){return this.channelState.friendlyName}},{key:"dateUpdated",get:function(){return this.channelState.dateUpdated}},{key:"dateCreated",get:function(){return this.channelState.dateCreated}},{key:"createdBy",get:function(){var e;return null!==(e=this.channelState.createdBy)&&void 0!==e?e:""}},{key:"attributes",get:function(){return this.channelState.attributes}},{key:"lastReadMessageIndex",get:function(){return this.channelState.lastReadMessageIndex}},{key:"lastMessage",get:function(){var e;return null!==(e=this.channelState.lastMessage)&&void 0!==e?e:void 0}},{key:"notificationLevel",get:function(){var e;return null!==(e=this.channelState.notificationLevel)&&void 0!==e?e:"default"}},{key:"bindings",get:function(){return this.channelState.bindings}},{key:"limits",get:function(){return this.configuration.limits}},{key:"state",get:function(){return this.channelState.state}},{key:"_subscribe",value:function(){var e,t=this;return this.entityPromise=null!==(e=this.entityPromise)&&void 0!==e?e:this.services.syncClient.document({id:this.entityName,mode:"open_existing"}).then((function(e){return t.entity=e,t.entity.on("updated",(function(e){t._update(e.data)})),t.entity.on("removed",(function(){return t.emit("removed",t)})),t._update(t.entity.data),e})).catch((function(e){throw t.entity=null,t.entityPromise=null,"disconnected"!=t.services.syncClient.connectionState&&$P.error("Failed to get conversation object",e),$P.debug("ERROR: Failed to get conversation object",e),e}))}},{key:"_subscribeStreams",value:(T=Sa(bl.mark((function e(){var t,n,r,i,a;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this._subscribe();case 3:return $P.trace("_subscribeStreams, this.entity.data=",null===(t=this.entity)||void 0===t?void 0:t.data),i=null===(n=this.entity)||void 0===n?void 0:n.data.messages,a=null===(r=this.entity)||void 0===r?void 0:r.data.roster,e.next=8,Promise.all([this.messagesEntity.subscribe(i),this.participantsEntity.subscribe(a)]);case 8:e.next=15;break;case 10:throw e.prev=10,e.t0=e.catch(0),"disconnected"!==this.services.syncClient.connectionState&&$P.error("Failed to subscribe on conversation objects",this.sid,e.t0),$P.debug("ERROR: Failed to subscribe on conversation objects",this.sid,e.t0),e.t0;case 15:case"end":return e.stop()}}),e,this,[[0,10]])}))),function(){return T.apply(this,arguments)})},{key:"_unsubscribe",value:(E=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.entity){e.next=5;break}return e.next=3,this.entity.close();case 3:this.entity=null,this.entityPromise=null;case 5:return e.abrupt("return",Promise.all([this.participantsEntity.unsubscribe(),this.messagesEntity.unsubscribe()]));case 6:case"end":return e.stop()}}),e,this)}))),function(){return E.apply(this,arguments)})},{key:"_setStatus",value:function(e,t){var n=this;this.statusSource=t,this.channelState.status!==e&&(this.channelState.status=e,"joined"===e?this._subscribeStreams().catch((function(t){if($P.debug("ERROR while setting conversation status "+e,t),"disconnected"!==n.services.syncClient.connectionState)throw t})):this.entityPromise&&this._unsubscribe().catch((function(t){if($P.debug("ERROR while setting conversation status "+e,t),"disconnected"!==n.services.syncClient.connectionState)throw t})))}},{key:"_statusSource",value:function(){return this.statusSource}},{key:"_update",value:function(e){var t,n,r,i,a;$P.trace("_update",e),Conversation.preprocessUpdate(e,this.sid);for(var s=new Set,o=0,u=Object.keys(e);o<u.length;o++){var c=u[o],l=VP[c];if(l)switch(l){case VP.status:if(!e.status||"unknown"===e.status||this.channelState.status===e.status)break;this.channelState.status=e.status,s.add(l);break;case VP.attributes:if(By(this.channelState.attributes,e.attributes))break;this.channelState.attributes=e.attributes,s.add(l);break;case VP.lastConsumedMessageIndex:if(void 0===e.lastConsumedMessageIndex||e.lastConsumedMessageIndex===this.channelState.lastReadMessageIndex)break;this.channelState.lastReadMessageIndex=e.lastConsumedMessageIndex,s.add("lastReadMessageIndex");break;case VP.lastMessage:if(this.channelState.lastMessage&&!e.lastMessage){delete this.channelState.lastMessage,s.add(l);break}this.channelState.lastMessage=this.channelState.lastMessage||{},void 0!==(null===(t=e.lastMessage)||void 0===t?void 0:t.index)&&e.lastMessage.index!==this.channelState.lastMessage.index&&(this.channelState.lastMessage.index=e.lastMessage.index,s.add(l)),void 0!==(null===(n=e.lastMessage)||void 0===n?void 0:n.timestamp)&&(null===(r=this.channelState.lastMessage)||void 0===r||null===(i=r.dateCreated)||void 0===i?void 0:i.getTime())!==e.lastMessage.timestamp.getTime()&&(this.channelState.lastMessage.dateCreated=e.lastMessage.timestamp,s.add(l)),By(this.channelState.lastMessage,{})&&delete this.channelState.lastMessage;break;case VP.state:var f=e.state||void 0;if(void 0!==f&&(f.dateUpdated=new Date(f.dateUpdated)),By(this.channelState.state,f))break;this.channelState.state=f,s.add(l);break;case VP.bindings:if(By(this.channelState.bindings,e.bindings))break;this.channelState.bindings=e.bindings,s.add(l);break;default:var d=e[c]instanceof Date,p=d&&(null===(a=this.channelState[l])||void 0===a?void 0:a.getTime())===e[c].getTime(),h=!d&&this[l]===e[c];if(p||h)break;this.channelState[l]=e[c],s.add(l)}}s.size>0&&this.emit("updated",{conversation:this,updateReasons:nP(s)})}},{key:"_onMessageAdded",value:function(e){var t,n=zP(this.participants.values());try{for(n.s();!(t=n.n()).done;){var r=t.value;if(r.identity===e.author){r._endTyping();break}}}catch(e){n.e(e)}finally{n.f()}this.emit("messageAdded",e)}},{key:"_setLastReadMessageIndex",value:(S=Sa(bl.mark((function e(t){var n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post","".concat(this.configuration.links.myConversations,"/").concat(this.sid),{last_read_message_index:t});case 2:return n=e.sent,e.abrupt("return",n.unread_messages_count);case 4:case"end":return e.stop()}}),e,this)}))),function(e){return S.apply(this,arguments)})},{key:"add",value:(_=Sa(bl.mark((function e(t,n){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.participantsEntity.add(t,null!=n?n:{}));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t){return _.apply(this,arguments)})},{key:"addNonChatParticipant",value:(x=Sa(bl.mark((function e(t,n){var r,i,a=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=a.length>2&&void 0!==a[2]?a[2]:{},i=a.length>3&&void 0!==a[3]?a[3]:{},e.abrupt("return",this.participantsEntity.addNonChatParticipant(t,n,null!=r?r:{},null!=i?i:{}));case 3:case"end":return e.stop()}}),e,this)}))),function(e,t){return x.apply(this,arguments)})},{key:"advanceLastReadMessageIndex",value:(w=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:if(!(t<(this.lastReadMessageIndex||0))){e.next=6;break}return e.next=5,this._setLastReadMessageIndex(this.lastReadMessageIndex);case 5:return e.abrupt("return",e.sent);case 6:return e.next=8,this._setLastReadMessageIndex(t);case 8:return e.abrupt("return",e.sent);case 9:case"end":return e.stop()}}),e,this)}))),function(e){return w.apply(this,arguments)})},{key:"delete",value:(k=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("delete",this.links.self);case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(){return k.apply(this,arguments)})},{key:"getAttributes",value:(b=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribe();case 2:return e.abrupt("return",this.attributes);case 3:case"end":return e.stop()}}),e,this)}))),function(){return b.apply(this,arguments)})},{key:"getMessages",value:(g=Sa(bl.mark((function e(t,n,r){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.abrupt("return",this.messagesEntity.getMessages(t,n,r));case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return g.apply(this,arguments)})},{key:"getParticipants",value:(m=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.abrupt("return",this.participantsEntity.getParticipants());case 3:case"end":return e.stop()}}),e,this)}))),function(){return m.apply(this,arguments)})},{key:"getParticipantsCount",value:(y=Sa(bl.mark((function e(){var t,n,r;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new rh(this.configuration.links.conversations).path(this.sid).build(),e.next=3,this.services.network.get(n);case 3:return r=e.sent,e.abrupt("return",null!==(t=r.body.participants_count)&&void 0!==t?t:0);case 5:case"end":return e.stop()}}),e,this)}))),function(){return y.apply(this,arguments)})},{key:"getParticipantBySid",value:(v=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.participantsEntity.getParticipantBySid(t));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return v.apply(this,arguments)})},{key:"getParticipantByIdentity",value:(h=Sa(bl.mark((function e(){var t,n=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>0&&void 0!==n[0]?n[0]:"",e.abrupt("return",this.participantsEntity.getParticipantByIdentity(null!=t?t:""));case 2:case"end":return e.stop()}}),e,this)}))),function(){return h.apply(this,arguments)})},{key:"getMessagesCount",value:(p=Sa(bl.mark((function e(){var t,n,r;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new rh(this.configuration.links.conversations).path(this.sid).build(),e.next=3,this.services.network.get(n);case 3:return r=e.sent,e.abrupt("return",null!==(t=r.body.messages_count)&&void 0!==t?t:0);case 5:case"end":return e.stop()}}),e,this)}))),function(){return p.apply(this,arguments)})},{key:"getUnreadMessagesCount",value:(d=Sa(bl.mark((function e(){var t,n,r;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=new rh(this.configuration.links.myConversations).path(this.sid).build(),e.next=3,this.services.network.get(t);case 3:if((n=e.sent).body.conversation_sid===this.sid){e.next=6;break}throw new Error("Conversation was not found in the user conversations list");case 6:if("number"!=typeof(r=n.body.unread_messages_count)){e.next=9;break}return e.abrupt("return",r);case 9:return e.abrupt("return",null);case 10:case"end":return e.stop()}}),e,this)}))),function(){return d.apply(this,arguments)})},{key:"join",value:(f=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.participants,{identity:this.configuration.userIdentity});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(){return f.apply(this,arguments)})},{key:"leave",value:(l=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("joined"!==this.channelState.status){e.next=3;break}return e.next=3,this.services.commandExecutor.mutateResource("delete","".concat(this.links.participants,"/").concat(this.configuration.userIdentity));case 3:return e.abrupt("return",this);case 4:case"end":return e.stop()}}),e,this)}))),function(){return l.apply(this,arguments)})},{key:"removeParticipant",value:(c=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.participantsEntity.remove("string"==typeof t?t:t.sid);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return c.apply(this,arguments)})},{key:"sendMessage",value:(u=Sa(bl.mark((function e(t,n,r){var i,a,s,o;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("string"!=typeof t&&null!==t){e.next=5;break}return e.next=3,this.messagesEntity.send(t,n,r);case 3:return s=e.sent,e.abrupt("return",null!==(a=eh(s.index))&&void 0!==a?a:0);case 5:return e.next=7,this.messagesEntity.sendMedia(t,n,r);case 7:return o=e.sent,e.abrupt("return",null!==(i=eh(o.index))&&void 0!==i?i:0);case 9:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return u.apply(this,arguments)})},{key:"prepareMessage",value:function(){return new qP(this.limits,this.messagesEntity)}},{key:"setAllMessagesRead",value:(o=Sa(bl.mark((function e(){var t;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.next=4,this.getMessages(1);case 4:if(!((t=e.sent).items.length>0)){e.next=7;break}return e.abrupt("return",this.advanceLastReadMessageIndex(t.items[0].index));case 7:return e.abrupt("return",Promise.resolve(0));case 8:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"setAllMessagesUnread",value:(s=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.next=4,this._setLastReadMessageIndex(null);case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"setUserNotificationLevel",value:(a=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post","".concat(this.configuration.links.myConversations,"/").concat(this.sid),{notification_level:t});case 2:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"typing",value:function(){return this.services.typingIndicator.send(this.sid)}},{key:"updateAttributes",value:(i=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{attributes:void 0!==t?JSON.stringify(t):void 0});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"updateFriendlyName",value:(r=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.channelState.friendlyName===t){e.next=3;break}return e.next=3,this.services.commandExecutor.mutateResource("post",this.links.self,{friendly_name:t});case 3:return e.abrupt("return",this);case 4:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"updateLastReadMessageIndex",value:(n=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.abrupt("return",this._setLastReadMessageIndex(t));case 3:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"updateUniqueName",value:(t=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.channelState.uniqueName===t){e.next=4;break}return t||(t=""),e.next=4,this.services.commandExecutor.mutateResource("post",this.links.self,{unique_name:t});case 4:return e.abrupt("return",this);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}],[{key:"preprocessUpdate",value:function(e,t){try{"string"==typeof e.attributes?e.attributes=JSON.parse(e.attributes):e.attributes&&JSON.stringify(e.attributes)}catch(n){$P.warn("Retrieved malformed attributes from the server for conversation: "+t),e.attributes={}}try{e.dateCreated&&(e.dateCreated=new Date(e.dateCreated))}catch(n){$P.warn("Retrieved malformed dateCreated from the server for conversation: "+t),delete e.dateCreated}try{e.dateUpdated&&(e.dateUpdated=new Date(e.dateUpdated))}catch(n){$P.warn("Retrieved malformed dateUpdated from the server for conversation: "+t),delete e.dateUpdated}try{e.lastMessage&&e.lastMessage.timestamp&&(e.lastMessage.timestamp=new Date(e.lastMessage.timestamp))}catch(n){$P.warn("Retrieved malformed lastMessage.timestamp from the server for conversation: "+t),delete e.lastMessage.timestamp}}}]),Conversation}(Dy);ja(Conversation,"participantJoined","participantJoined"),ja(Conversation,"participantLeft","participantLeft"),ja(Conversation,"participantUpdated","participantUpdated"),ja(Conversation,"messageAdded","messageAdded"),ja(Conversation,"messageRemoved","messageRemoved"),ja(Conversation,"messageUpdated","messageUpdated"),ja(Conversation,"typingEnded","typingEnded"),ja(Conversation,"typingStarted","typingStarted"),ja(Conversation,"updated","updated"),ja(Conversation,"removed","removed"),wl([Xv(Vv,ey),xl("design:type",Function),xl("design:paramtypes",[String,Object]),xl("design:returntype",Promise)],Conversation.prototype,"add",null),wl([Xv(Vv,Vv,ey),xl("design:type",Function),xl("design:paramtypes",[String,String,Object,Object]),xl("design:returntype",Promise)],Conversation.prototype,"addNonChatParticipant",null),wl([Xv(Jv),xl("design:type",Function),xl("design:paramtypes",[Number]),xl("design:returntype",Promise)],Conversation.prototype,"advanceLastReadMessageIndex",null),wl([Xv(["undefined",Jv],["undefined",Jv],["undefined",$v("backwards","forward")]),xl("design:type",Function),xl("design:paramtypes",[Number,Number,String]),xl("design:returntype",Promise)],Conversation.prototype,"getMessages",null),wl([Xv(Vv),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"getParticipantBySid",null),wl([Xv(Vv),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"getParticipantByIdentity",null),wl([Xv([Vv,Participant]),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],Conversation.prototype,"removeParticipant",null),wl([Xv(["string",$v(null),Gv((function(e){return[e instanceof FormData,"an instance of FormData"]})),Kv("media options",{contentType:Vv,media:Gv((function(e){var t="string"==typeof e&&e.length>0||e instanceof Uint8Array||e instanceof ArrayBuffer;return"function"==typeof Blob&&(t=t||e instanceof Blob),[t,"a non-empty string, an instance of Buffer or an instance of Blob"]}))})],ey,["undefined",$v(null),Kv("email attributes",{subject:[Vv,"undefined"]})]),xl("design:type",Function),xl("design:paramtypes",[Object,Object,Object]),xl("design:returntype",Promise)],Conversation.prototype,"sendMessage",null),wl([Xv($v("default","muted")),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"setUserNotificationLevel",null),wl([Xv(Zv),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],Conversation.prototype,"updateAttributes",null),wl([Xv(["string"]),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"updateFriendlyName",null),wl([Xv([$v(null),Jv]),xl("design:type",Function),xl("design:paramtypes",[Number]),xl("design:returntype",Promise)],Conversation.prototype,"updateLastReadMessageIndex",null),wl([Xv(["string",$v(null)]),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"updateUniqueName",null);var KP=function(){function e(){var t=this;Ma(this,e),this._promise=new Promise((function(e,n){t._resolve=e,t._reject=n}))}return Ta(e,[{key:"promise",get:function(){return this._promise}},{key:"update",value:function(e){this._resolve(e)}},{key:"set",value:function(e){this.current=e,this._resolve(e)}},{key:"fail",value:function(e){this._reject(e)}}]),e}();function HP(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return YP(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return YP(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function YP(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function QP(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function XP(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?QP(Object(n),!0).forEach((function(t){ja(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):QP(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function ZP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}var eA=rd.scope("Conversations"),tA=function(e){Oa(p,e);var t,n,r,i,a,s,o,u,c,l,f,d=ZP(p);function p(e,t){var n;return Ma(this,p),ja(Ra(n=d.call(this)),"conversations",new Map),ja(Ra(n),"myConversationsRead",new KP),ja(Ra(n),"tombstones",new Set),ja(Ra(n),"myConversationsFetched",!1),n.configuration=e,n.services=t,n}return Ta(p,[{key:"addConversation",value:(f=Sa(bl.mark((function e(t){var n,r,i,a,s,o,u,c,l,f;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=void 0!==(null==t?void 0:t.attributes)?t.attributes:{},e.next=3,this.services.commandExecutor.mutateResource("post",this.configuration.links.conversations,{friendly_name:t.friendlyName,unique_name:t.uniqueName,attributes:void 0!==a?JSON.stringify(a):void 0});case 3:if(s=e.sent,o=null!==(n=s.sid)&&void 0!==n?n:null,u=null!==(r=null===(i=s.sync_objects)||void 0===i?void 0:i.conversation)&&void 0!==r?r:null,c=XP({self:s.url},s.links),!(l=this.conversations.get(o))){e.next=12;break}return e.next=11,l._subscribe();case 11:return e.abrupt("return",l);case 12:return f=new Conversation({channel:u,entityName:"",uniqueName:"",attributes:null,createdBy:"",friendlyName:"",lastConsumedMessageIndex:0,dateCreated:null,dateUpdated:null},o,c,this.configuration,this.services),this.conversations.set(f.sid,f),this._registerForEvents(f),e.next=17,f._subscribe();case 17:return this.emit("conversationAdded",f),e.abrupt("return",f);case 19:case"end":return e.stop()}}),e,this)}))),function(e){return f.apply(this,arguments)})},{key:"fetchConversations",value:(l=Sa(bl.mark((function e(){var t,n,r,i,a,s,o,u=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this._getMap();case 3:return(t=e.sent).on("itemAdded",(function(e){eA.debug("itemAdded: ".concat(e.item.key)),u._upsertConversation("sync",e.item.key,e.item.data)})),t.on("itemRemoved",(function(e){eA.debug("itemRemoved: ".concat(e.key));var t=e.key;u.myConversationsFetched||u.tombstones.add(t);var n=u.conversations.get(t);n&&("joined"===n.status&&(n._setStatus("notParticipating","sync"),u.emit("conversationLeft",n)),u.conversations.delete(t),u.emit("conversationRemoved",n),n.emit("removed",n))})),t.on("itemUpdated",(function(e){eA.debug("itemUpdated: ".concat(e.item.key)),u._upsertConversation("sync",e.item.key,e.item.data)})),e.next=9,this._fetchMyConversations();case 9:n=e.sent,r=[],i=HP(n);try{for(i.s();!(a=i.n()).done;)s=a.value,r.push(this._upsertConversation("rest",s.channel_sid,s))}catch(e){i.e(e)}finally{i.f()}return this.myConversationsRead.set(!0),e.next=16,Promise.all(r);case 16:return this.myConversationsFetched=!0,this.tombstones.clear(),eA.debug("The conversations list has been successfully fetched"),e.abrupt("return",this);case 22:throw e.prev=22,e.t0=e.catch(0),o="Failed to fetch the conversations list","disconnected"!==this.services.syncClient.connectionState&&eA.error(o,e.t0),eA.debug("ERROR: ".concat(o),e.t0),e.t0;case 28:case"end":return e.stop()}}),e,this,[[0,22]])}))),function(){return l.apply(this,arguments)})},{key:"getConversations",value:(c=Sa(bl.mark((function e(){var t,n,r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._getMap();case 2:return t=e.sent,e.next=5,t.getItems();case 5:return n=e.sent,e.abrupt("return",this._wrapPaginator(n,(function(e){return Promise.all(e.map((function(e){return r._upsertConversation("sync",e.key,e.data)})))})));case 7:case"end":return e.stop()}}),e,this)}))),function(){return c.apply(this,arguments)})},{key:"getConversation",value:(u=Sa(bl.mark((function e(t){var n,r,i,a=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._getMap();case 2:return n=e.sent,e.next=5,n.getItems({key:t});case 5:return r=e.sent,i=r.items.map((function(e){return a._upsertConversation("sync",e.key,e.data)})),e.abrupt("return",i.length>0?i[0]:null);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return u.apply(this,arguments)})},{key:"getConversationByUniqueName",value:(o=Sa(bl.mark((function e(t){var n,r,i,a,s;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new rh(this.configuration.links.myConversations).path(t).build(),e.next=3,this.services.network.get(n);case 3:return r=e.sent,i=r.body,a=i.conversation_sid,s={entityName:null,lastConsumedMessageIndex:i.last_read_message_index,status:(null==i?void 0:i.status)||"unknown",friendlyName:i.friendly_name,dateUpdated:i.date_updated,dateCreated:i.date_created,uniqueName:i.unique_name,createdBy:i.created_by,attributes:i.attributes,channel:i.sync_objects.conversation,notificationLevel:null==i?void 0:i.notification_level,sid:a},e.abrupt("return",a?this._upsertConversation("sync",a,s):null);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"peekConversation",value:(s=Sa(bl.mark((function e(t){var n,r,i,a;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new rh(this.configuration.links.conversations).path(t).build(),e.next=3,this.services.network.get(n);case 3:return r=e.sent,i=r.body,a={entityName:null,status:(null==i?void 0:i.status)||"unknown",friendlyName:i.friendly_name,dateUpdated:i.date_updated,dateCreated:i.date_created,uniqueName:i.unique_name,createdBy:i.created_by,attributes:i.attributes,channel:"".concat(t,".channel"),sid:t},e.abrupt("return",this._upsertConversation("sync",t,a));case 7:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"_getMap",value:(a=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.syncClient.map({id:this.configuration.myConversations,mode:"open_existing"});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"_wrapPaginator",value:(i=Sa(bl.mark((function e(t,n){var r,i=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,n(t.items);case 2:return r=e.sent,e.abrupt("return",{items:r,hasNextPage:t.hasNextPage,hasPrevPage:t.hasPrevPage,nextPage:function(){return t.nextPage().then((function(e){return i._wrapPaginator(e,n)}))},prevPage:function(){return t.prevPage().then((function(e){return i._wrapPaginator(e,n)}))}});case 4:case"end":return e.stop()}}),e)}))),function(e,t){return i.apply(this,arguments)})},{key:"_updateConversation",value:(r=Sa(bl.mark((function e(t,n,r){var i,a,s,o=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=void 0!==n._statusSource()&&t!==n._statusSource(),a="rest"!==t||"sync"===n._statusSource(),!i||!a||"sync"===t){e.next=5;break}return eA.trace("upsertConversation: conversation is known from sync and came from chat, ignoring",{sid:n.sid,data:r.status,conversation:n.status}),e.abrupt("return");case 5:if("joined"!==r.status||"joined"===n.status){e.next=13;break}return n._setStatus("joined",t),s={},void 0!==r.notificationLevel&&(s.notificationLevel=r.notificationLevel),void 0!==r.lastConsumedMessageIndex&&(s.lastConsumedMessageIndex=r.lastConsumedMessageIndex),By(s,{})||n._update(s),n._subscribe().then((function(){o.emit("conversationJoined",n)})),e.abrupt("return");case 13:if("notParticipating"!==r.status||"joined"!==n.status){e.next=20;break}return n._setStatus("notParticipating",t),n._update(r),e.next=18,n._subscribe();case 18:return this.emit("conversationLeft",n),e.abrupt("return");case 20:if("notParticipating"!==r.status){e.next=24;break}return e.next=23,n._subscribe();case 23:return e.abrupt("return");case 24:n._update(r);case 25:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return r.apply(this,arguments)})},{key:"_upsertConversation",value:(n=Sa(bl.mark((function e(t,n,r){var i,a,s,o;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(eA.trace("upsertConversation called for ".concat(n),r),!(i=this.conversations.get(n))){e.next=9;break}return eA.trace("upsertConversation: the conversation ".concat(i.sid," is known;")+"its status is known from the source ".concat(i._statusSource()," ")+"and the update came from the source ".concat(t),i),e.next=6,this._updateConversation(t,i,r);case 6:return e.next=8,i._subscribe();case 8:return e.abrupt("return",i);case 9:if(!["chat","rest"].includes(t)||!this.tombstones.has(n)){e.next=12;break}return eA.trace("upsertChannel: the channel is deleted but reappeared again from chat, ignoring",n),e.abrupt("return",null);case 12:return eA.trace("upsertConversation: creating a local conversation object with sid "+n,r),a="".concat(this.configuration.links.conversations,"/").concat(n),s={self:a,messages:"".concat(a,"/Messages"),participants:"".concat(a,"/Participants")},o=new Conversation(r,n,s,this.configuration,this.services),this.conversations.set(n,o),e.next=19,o._subscribe();case 19:return this._registerForEvents(o),this.emit("conversationAdded",o),"joined"===r.status&&(o._setStatus("joined",t),this.emit("conversationJoined",o)),e.abrupt("return",o);case 23:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return n.apply(this,arguments)})},{key:"_fetchMyConversations",value:(t=Sa(bl.mark((function e(){var t,n,r,i,a,s;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=[],n=null;case 2:return i=new rh(this.configuration.links.myConversations),n&&i.arg("PageToken",n),e.next=6,this.services.network.get(i.build());case 6:a=e.sent,s=null===(r=a.body)||void 0===r?void 0:r.conversations.map((function(e){return{descriptor:e,channel_sid:e.conversation_sid,status:e.status,channel:e.sync_objects.conversation,messages:e.sync_objects.messages,roster:"".concat(e.conversation_sid,".roster"),lastConsumedMessageIndex:e.last_read_message_index,notificationLevel:e.notification_level}})),n=a.body.meta.next_token,t=[].concat(nP(t),nP(s));case 10:if(n){e.next=2;break}case 11:return e.abrupt("return",t);case 12:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"_onConversationRemoved",value:function(e){var t=this.conversations.get(e);t&&(this.conversations.delete(e),this.emit("conversationRemoved",t))}},{key:"_registerForEvents",value:function(e){var t=this;e.on("removed",(function(){return t._onConversationRemoved(e.sid)})),e.on("updated",(function(e){return t.emit("conversationUpdated",e)})),e.on("participantJoined",(function(e){return t.emit("participantJoined",e)})),e.on("participantLeft",(function(e){return t.emit("participantLeft",e)})),e.on("participantUpdated",(function(e){return t.emit("participantUpdated",e)})),e.on("messageAdded",(function(e){return t.emit("messageAdded",e)})),e.on("messageUpdated",(function(e){return t.emit("messageUpdated",e)})),e.on("messageRemoved",(function(e){return t.emit("messageRemoved",e)})),e.on("typingStarted",(function(e){return t.emit("typingStarted",e)})),e.on("typingEnded",(function(e){return t.emit("typingEnded",e)}))}}]),p}(Dy),nA=In,rA=Hr.find,iA=kd,aA="find",sA=!0;function oA(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}aA in[]&&Array(1).find((function(){sA=!1})),nA({target:"Array",proto:!0,forced:sA},{find:function(e){return rA(this,e,arguments.length>1?arguments[1]:void 0)}}),iA(aA);var uA=function(e){Oa(a,e);var t,n,r,i=oA(a);function a(e,t,n){var r;return Ma(this,a),(r=i.call(this)).configuration=t,r.services=n,r.fifoStack=[],r.myself=e,r.myself.on("updated",(function(e){return r.emit("userUpdated",e)})),r.myself.on("userSubscribed",(function(){return r.emit("userSubscribed",r.myself)})),r.myself.on("userUnsubscribed",(function(){r.emit("userUnsubscribed",r.myself),r.myself._ensureFetched()})),r.subscribedUsers=new Map,r}return Ta(a,[{key:"handleUnsubscribeUser",value:function(e){this.subscribedUsers.has(e.identity)&&this.subscribedUsers.delete(e.identity);var t=0;this.fifoStack.find((function(n,r){return n==e.identity&&(t=r,!0)}))&&this.fifoStack.splice(t,1),this.emit("userUnsubscribed",e)}},{key:"handleSubscribeUser",value:function(e){if(!this.subscribedUsers.has(e.identity)){if(this.fifoStack.length>=this.configuration.userInfosToSubscribe){var t,n,r=this.fifoStack.shift();null===(t=this.subscribedUsers)||void 0===t||null===(n=t.get(r))||void 0===n||n.unsubscribe()}this.fifoStack.push(e.identity),this.subscribedUsers.set(e.identity,e),this.emit("userSubscribed",e)}}},{key:"getUser",value:(r=Sa(bl.mark((function e(){var t,n,r,i,a=this,s=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=s.length>0&&void 0!==s[0]?s[0]:"",n=s.length>1&&void 0!==s[1]?s[1]:"",e.next=4,this.myself._ensureFetched();case 4:if(t!=this.myself.identity){e.next=6;break}return e.abrupt("return",this.myself);case 6:if(!(r=this.subscribedUsers.get(t))){e.next=9;break}return e.abrupt("return",r);case 9:if(e.t0=n,e.t0){e.next=14;break}return e.next=13,this.getSyncUniqueName(t);case 13:e.t0=e.sent;case 14:return n=e.t0,(i=new User(t,n,this.configuration,this.services)).on("updated",(function(e){return a.emit("userUpdated",e)})),i.on("userSubscribed",(function(){return a.handleSubscribeUser(i)})),i.on("userUnsubscribed",(function(){return a.handleUnsubscribeUser(i)})),e.next=21,i._ensureFetched();case 21:return e.abrupt("return",i);case 22:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"getSubscribedUsers",value:(n=Sa(bl.mark((function e(){var t;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.myself._ensureFetched();case 2:return t=[this.myself],this.subscribedUsers.forEach((function(e){return t.push(e)})),e.abrupt("return",t);case 5:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"getSyncUniqueName",value:(t=Sa(bl.mark((function e(t){var n,r,i,a;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=new rh(this.configuration.links.users).path(t).build(),e.next=3,this.services.network.get(i);case 3:return a=e.sent,e.abrupt("return",null!==(n=null===(r=a.body)||void 0===r?void 0:r.sync_objects.user_info_map)&&void 0!==n?n:"");case 5:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),a}(Dy),cA=rd.scope("TypingIndicator"),lA=function(){function e(t,n,r){Ma(this,e),this.configuration=n,this.services=r,this.getConversation=t,this.serviceTypingTimeout=null,this.sentUpdates=new Map}var t;return Ta(e,[{key:"typingTimeout",get:function(){return this.configuration.typingIndicatorTimeoutOverride||this.serviceTypingTimeout||this.configuration.typingIndicatorTimeoutDefault}},{key:"initialize",value:function(){var e=this;this.services.notificationClient.on("message",function(){var t=Sa(bl.mark((function t(n,r){return bl.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n!==gg.TYPING_INDICATOR){t.next=3;break}return t.next=3,e._handleRemoteTyping(r);case 3:case"end":return t.stop()}}),t)})));return function(e,n){return t.apply(this,arguments)}}())}},{key:"_handleRemoteTyping",value:(t=Sa(bl.mark((function e(t){var n=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:cA.trace("Got new typing indicator ",t),this.getConversation(t.channel_sid).then((function(e){e&&e.participants.forEach((function(e){if(e.identity===t.identity){var r=n.configuration.typingIndicatorTimeoutOverride?n.configuration.typingIndicatorTimeoutOverride+1e3:1e3*t.typing_timeout;e._startTyping(r)}}))})).catch((function(e){throw cA.error(e),e}));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"send",value:function(e){var t=this.sentUpdates.get(e);return t&&t>Date.now()-this.typingTimeout?Promise.resolve():(this.sentUpdates.set(e,Date.now()),this._send(e))}},{key:"_send",value:function(e){var t=this;cA.trace("Sending typing indicator");var n=this.configuration.links.typing,r="ChannelSid=".concat(e);return this.services.twilsockClient.post(n,{"Content-Type":"application/x-www-form-urlencoded"},r,this.configuration.productId).then((function(e){e.body.hasOwnProperty("typing_timeout")&&(t.serviceTypingTimeout=1e3*e.body.typing_timeout)})).catch((function(e){throw cA.error("Failed to send typing indicator:",e),e}))}}]),e}(),PushNotification=function PushNotification(e){Ma(this,PushNotification),this.title=e.title||null,this.body=e.body||null,this.sound=e.sound||null,this.badge=e.badge||null,this.action=e.action||null,this.type=e.type||null,this.data=e.data||{}};function fA(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function dA(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?fA(Object(n),!0).forEach((function(t){ja(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):fA(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var pA,hA,vA,yA=function(e){return e.replace(/(^\/+|\/+$)/g,"")},mA=function(){function e(t,n,r){Ma(this,e),this._serviceUrl=t,this._services=n,this._productId=r}var t,n,r;return Ta(e,[{key:"_preProcessUrl",value:function(e){var t=yA(e);return/^https?:\/\//.test(e)?t:"".concat(yA(this._serviceUrl),"/").concat(t)}},{key:"_makeRequest",value:(r=Sa(bl.mark((function e(t,n,r,i){var a,s,o,u;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a=this._preProcessUrl(n),s=dA({"Content-Type":"application/json; charset=utf-8"},i||{}),e.t0=t,e.next="get"===e.t0?5:"post"===e.t0?11:"delete"===e.t0?15:19;break;case 5:return u=a,r&&(u+="?"+Object.entries(r).map((function(e){return e.map(encodeURIComponent).join("=")})).join("&")),e.next=9,this._services.transport.get(u,s,this._productId);case 9:return o=e.sent,e.abrupt("break",19);case 11:return e.next=13,this._services.transport.post(a,s,JSON.stringify(r),this._productId);case 13:return o=e.sent,e.abrupt("break",19);case 15:return e.next=17,this._services.transport.delete(a,s,{},this._productId);case 17:return o=e.sent,e.abrupt("break",19);case 19:if(!(o.status.code<200||o.status.code>=300)){e.next=21;break}throw new Error("Request responded with a non-success code ".concat(o.status.code));case 21:return e.abrupt("return",o);case 22:case"end":return e.stop()}}),e,this)}))),function(e,t,n,i){return r.apply(this,arguments)})},{key:"fetchResource",value:(n=Sa(bl.mark((function e(t,n){var r,i=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=1,e.next=4,new pg({min:50,max:1600,maxAttemptsCount:6}).run((function(){return i._makeRequest("get",t,n)}));case 4:return r=e.sent,e.abrupt("return",r.body);case 8:throw e.prev=8,e.t0=e.catch(1),new Error('Fetch resource from "'.concat(t,'" failed.'));case 11:case"end":return e.stop()}}),e,null,[[1,8]])}))),function(e,t){return n.apply(this,arguments)})},{key:"mutateResource",value:(t=Sa(bl.mark((function e(t,n,r){var i;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._makeRequest(t,n,r,{"X-Twilio-Mutation-Id":tb.v4()});case 2:if(202!==(i=e.sent).status.code){e.next=7;break}return e.next=6,this.fetchResource(i.body.resource_url);case 6:return e.abrupt("return",e.sent);case 7:return e.abrupt("return",i.body);case 8:case"end":return e.stop()}}),e,this)}))),function(e,n,r){return t.apply(this,arguments)})}]),e}();function gA(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function bA(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?gA(Object(n),!0).forEach((function(t){ja(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):gA(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function kA(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}var wA=rd.scope("Client"),xA="2.1.0-rc.6",_A=function e(){Ma(this,e)};return e.Client=(hA=pA=function(e){Oa(Client,e);var t,n,r,i,a,s,o,u,c,l,f,d,p,h,v=kA(Client);function Client(e){var t,n,r,i,a,s,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(Ma(this,Client),ja(Ra(s=v.call(this)),"connectionState","unknown"),ja(Ra(s),"version",xA),ja(Ra(s),"parsePushNotification",vA.parsePushNotification),s.fpaToken=null!=e?e:"",s.options=null!=o?o:{},!s.options.disableDeepClone){var u=bA(bA({},s.options),{},{transport:void 0,twilsockClient:void 0});(u=Zp(u)).transport=s.options.transport,u.twilsockClient=s.options.twilsockClient,s.options=u}s.options.logLevel=null!==(t=s.options.logLevel)&&void 0!==t?t:"silent",wA.setLevel(s.options.logLevel);var c=s.options.productId="ip_messaging";if(s.options.clientMetadata=s.options.clientMetadata||{},s.options.clientMetadata.hasOwnProperty("type")||(s.options.clientMetadata.type="conversations"),s.options.clientMetadata.hasOwnProperty("sdk")||(s.options.clientMetadata.sdk="JS",s.options.clientMetadata.sdkv=xA),s.options.Sync=s.options.Sync||{},void 0===s.options.Sync.enableSessionStorage&&(s.options.Sync.enableSessionStorage=!0),s.options.region&&(s.options.Sync.region=s.options.region),!e)throw new Error("A valid Twilio token should be provided");s.services=new _A,s._myself=new User("","",null,s.services);var l=!s.options.twilsockClient;if(!s.options.initRegistrations){var f=new bg.InitRegistration(c);vA.populateInitRegistrations(f),s.options.initRegistrations=[f]}s.services.twilsockClient=s.options.twilsockClient=null!==(n=s.options.twilsockClient)&&void 0!==n?n:new bg.TwilsockClient(e,c,s.options),s.services.twilsockClient.on("tokenAboutToExpire",(function(e){return s.emit("tokenAboutToExpire",e)})),s.services.twilsockClient.on("tokenExpired",(function(){return s.emit("tokenExpired")})),s.services.twilsockClient.on("connectionError",(function(e){return s.emit("connectionError",e)})),s.services.twilsockClient.on("stateChanged",(function(e){wA.debug("Handling stateChanged for ConversationsClient: new state ".concat(e)),e!==s.connectionState&&(s.connectionState=e,s.emit("connectionStateChanged",s.connectionState))})),s.services.transport=s.options.transport=null!==(r=s.options.transport)&&void 0!==r?r:s.options.twilsockClient,s.services.notificationClient=s.options.notificationsClient=null!==(i=s.options.notificationsClient)&&void 0!==i?i:new aE.Notifications(e,s.options),s.services.syncClient=s.options.syncClient=null!==(a=s.options.syncClient)&&void 0!==a?a:new BR(e,s.options);var d=(null==o?void 0:o.Chat)||(null==o?void 0:o.IPMessaging)||o||{},p=d.region||(null==o?void 0:o.region),h=d.apiUri||d.typingUri||"https://aim.".concat(p||"us1",".twilio.com");s.services.commandExecutor=new mA(h,{transport:s.options.transport},c);var y=function(e){s._rejectEnsureReady(e),s.emit("stateChanged","failed")};return s.services.twilsockClient.once("connectionError",y),s.services.twilsockClient.once("disconnected",y),s.services.twilsockClient.once("connected",Sa(bl.mark((function e(){var t;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return wA.debug("ConversationsClient started INITIALIZING"),s.services.twilsockClient.off("connectionError",y),s.services.twilsockClient.off("disconnected",y),e.prev=3,t="conversations.client.startup",s.services.twilsockClient.addPartialTelemetryEvent(new bg.TelemetryEventDescription(t,"Conversations client startup",new Date),t,bg.TelemetryPoint.Start),e.next=8,s._initialize();case 8:s.services.twilsockClient.addPartialTelemetryEvent(new bg.TelemetryEventDescription("","",new Date),t,bg.TelemetryPoint.End),e.next=15;break;case 11:e.prev=11,e.t0=e.catch(3),s._rejectEnsureReady(e.t0),s.emit("stateChanged","failed");case 15:case"end":return e.stop()}}),e,null,[[3,11]])})))),s._ensureReady=new Promise((function(e,t){s._resolveEnsureReady=e,s._rejectEnsureReady=t})).catch((function(){})),l&&s.services.twilsockClient.connect(),s}return Ta(Client,[{key:"user",get:function(){return this._myself}},{key:"reachabilityEnabled",get:function(){if(!this.configuration)throw new Error("Reachability information could not yet be accessed as the client has not yet been initialized. Subscribe to the 'stateChanged' event to properly react to the client initialization.");return this.configuration.reachabilityEnabled}},{key:"token",get:function(){return this.fpaToken}},{key:"_subscribeToPushNotifications",value:function(e){var t=this;[gg.NEW_MESSAGE,gg.ADDED_TO_CONVERSATION,gg.REMOVED_FROM_CONVERSATION,gg.TYPING_INDICATOR,gg.CONSUMPTION_UPDATE].forEach((function(n){t.services.notificationClient.subscribe(e,n)}))}},{key:"_unsubscribeFromPushNotifications",value:function(e){var t=this;[gg.NEW_MESSAGE,gg.ADDED_TO_CONVERSATION,gg.REMOVED_FROM_CONVERSATION,gg.TYPING_INDICATOR,gg.CONSUMPTION_UPDATE].forEach((function(n){t.services.notificationClient.unsubscribe(e,n)}))}},{key:"_initialize",value:(h=Sa(bl.mark((function e(){var t,n=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.fetchResource("Client/v2/Configuration");case 2:return t=e.sent,this.configuration=new hd(this.options,t,wA),this._myself._resolveInitialization(this.configuration,this.configuration.userIdentity,this.configuration.userInfo,!0),this.services.typingIndicator=new lA(this.getConversationBySid.bind(this),this.configuration,this.services),this.services.network=new mg(this.configuration,this.services),this.services.users=new uA(this._myself,this.configuration,this.services),this.services.users.on("userSubscribed",(function(e){n.emit("userSubscribed",e)})),this.services.users.on("userUpdated",(function(e){return n.emit("userUpdated",e)})),this.services.users.on("userUnsubscribed",(function(e){n.emit("userUnsubscribed",e)})),this.conversations=new tA(this.configuration,this.services),this.conversations.on("conversationAdded",(function(e){n.emit("conversationAdded",e)})),this.conversations.on("conversationRemoved",(function(e){n.emit("conversationRemoved",e)})),this.conversations.on("conversationJoined",(function(e){n.emit("conversationJoined",e)})),this.conversations.on("conversationLeft",(function(e){n.emit("conversationLeft",e)})),this.conversations.on("conversationUpdated",(function(e){return n.emit("conversationUpdated",e)})),this.conversations.on("participantJoined",(function(e){n.emit("participantJoined",e)})),this.conversations.on("participantLeft",(function(e){n.emit("participantLeft",e)})),this.conversations.on("participantUpdated",(function(e){return n.emit("participantUpdated",e)})),this.conversations.on("messageAdded",(function(e){return n.emit("messageAdded",e)})),this.conversations.on("messageUpdated",(function(e){return n.emit("messageUpdated",e)})),this.conversations.on("messageRemoved",(function(e){return n.emit("messageRemoved",e)})),this.conversations.on("typingStarted",(function(e){return n.emit("typingStarted",e)})),this.conversations.on("typingEnded",(function(e){return n.emit("typingEnded",e)})),this.conversationsPromise=this.conversations.fetchConversations().then((function(){return n.conversations})).catch((function(e){throw e})),e.next=28,this.services.users.myself._ensureFetched();case 28:vA.supportedPushChannels.forEach((function(e){return n._subscribeToPushNotifications(e)})),this.services.typingIndicator.initialize(),this.services.mcsClient=new $R.McsClient(this.fpaToken,this.configuration.links.mediaService,this.configuration.links.mediaSetService,bA(bA({},this.options),{},{transport:void 0})),this._resolveEnsureReady(),this.emit("stateChanged","initialized");case 33:case"end":return e.stop()}}),e,this)}))),function(){return h.apply(this,arguments)})},{key:"shutdown",value:(p=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.next=4,this.services.twilsockClient.disconnect();case 4:case"end":return e.stop()}}),e,this)}))),function(){return p.apply(this,arguments)})},{key:"updateToken",value:(d=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:if(wA.info("updateToken"),this.fpaToken!==t){e.next=5;break}return e.abrupt("return",this);case 5:return e.next=7,this.services.twilsockClient.updateToken(t);case 7:return e.next=9,this.services.notificationClient.updateToken(t);case 9:return e.next=11,this.services.mcsClient.updateToken(t);case 11:return this.fpaToken=t,e.abrupt("return",this);case 13:case"end":return e.stop()}}),e,this)}))),function(e){return d.apply(this,arguments)})},{key:"getConversationBySid",value:(f=Sa(bl.mark((function e(t){var n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.next=4,this.conversations.myConversationsRead.promise;case 4:return e.next=6,this.conversations.getConversation(t);case 6:if(n=e.sent){e.next=11;break}return e.next=10,this.conversations.peekConversation(t);case 10:n=e.sent;case 11:if(n){e.next=13;break}throw new Error("Conversation with SID ".concat(t," is not found."));case 13:return e.abrupt("return",n);case 14:case"end":return e.stop()}}),e,this)}))),function(e){return f.apply(this,arguments)})},{key:"getConversationByUniqueName",value:(l=Sa(bl.mark((function e(t){var n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.next=4,this.conversations.myConversationsRead.promise;case 4:return e.next=6,this.conversations.getConversationByUniqueName(t);case 6:if(n=e.sent){e.next=9;break}throw new Error("Conversation with unique name ".concat(t," is not found."));case 9:return e.abrupt("return",n);case 10:case"end":return e.stop()}}),e,this)}))),function(e){return l.apply(this,arguments)})},{key:"getSubscribedConversations",value:(c=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.abrupt("return",this.conversationsPromise.then((function(e){return e.getConversations()})));case 3:case"end":return e.stop()}}),e,this)}))),function(){return c.apply(this,arguments)})},{key:"createConversation",value:(u=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return t=t||{},e.abrupt("return",this.conversationsPromise.then((function(e){return e.addConversation(t)})));case 4:case"end":return e.stop()}}),e,this)}))),function(e){return u.apply(this,arguments)})},{key:"setPushRegistrationId",value:(o=Sa(bl.mark((function e(t,n){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return this._subscribeToPushNotifications(t),this.services.notificationClient.setPushRegistrationId(t,n),e.next=6,this.services.notificationClient.commitChanges();case 6:case"end":return e.stop()}}),e,this)}))),function(e,t){return o.apply(this,arguments)})},{key:"unsetPushRegistrationId",value:(s=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return this._unsubscribeFromPushNotifications(t),e.next=5,this.services.notificationClient.commitChanges();case 5:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"removePushRegistrations",value:(a=Sa(bl.mark((function e(t,n){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.notificationClient.removeRegistrations(t,n);case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"handlePushNotification",value:(i=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:wA.debug("handlePushNotification, notificationPayload=",t),this.emit("pushNotification",vA.parsePushNotification(t));case 4:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"getUser",value:(r=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.abrupt("return",this.services.users.getUser(t));case 3:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"getSubscribedUsers",value:(n=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.abrupt("return",this.services.users.getSubscribedUsers());case 3:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})}],[{key:"populateInitRegistrations",value:function(e){e.populateInitRegistrations([gg.TYPING_INDICATOR]),BR.populateInitRegistrations(e)}},{key:"create",value:(t=Sa(bl.mark((function e(t,n){var r;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==n||!n.twilsockClient){e.next=2;break}throw new Error("Obsolete usage of ConversationsClient.create() factory method: if you pass twilsock from the outside then you must use ConversationsClient constructor and be prepared to work with uninitialized client.");case 2:return r=new vA(t,n),e.next=5,r._ensureReady;case 5:return e.abrupt("return",r);case 6:case"end":return e.stop()}}),e)}))),function(e,n){return t.apply(this,arguments)})},{key:"parsePushNotificationChatData",value:function(e){var t={};for(var n in vA.supportedPushDataFields)void 0!==e[n]&&null!==e[n]&&("message_index"===n?null!==eh(e[n])&&(t[vA.supportedPushDataFields[n]]=Number(e[n])):t[vA.supportedPushDataFields[n]]=e[n]);return t}},{key:"parsePushNotification",value:function(e){if(wA.debug("parsePushNotification, notificationPayload=",e),void 0!==e.aps){if(!e.twi_message_type)throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");var t,n=vA.parsePushNotificationChatData(e),r=e.aps,i=null;return"string"==typeof r.alert?t=r.alert||null:(t=r.alert.body||null,i=r.alert.title||null),new PushNotification({title:i,body:t,sound:r.sound||null,badge:r.badge||null,action:r.category||null,type:e.twi_message_type,data:n})}if(void 0!==e.data){var a=e.data;if(!a.twi_message_type)throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");var s=vA.parsePushNotificationChatData(e.data);return new PushNotification({title:a.twi_title||null,body:a.twi_body||null,sound:a.twi_sound||null,badge:null,action:a.twi_action||null,type:a.twi_message_type,data:s})}throw new Error("Provided push notification payload is not Programmable Chat notification")}}]),Client}(Dy),ja(pA,"version",xA),ja(pA,"supportedPushChannels",["fcm","apn"]),ja(pA,"supportedPushDataFields",{conversation_sid:"conversationSid",message_sid:"messageSid",message_index:"messageIndex"}),ja(pA,"conversationAdded","conversationAdded"),ja(pA,"conversationJoined","conversationJoined"),ja(pA,"conversationLeft","conversationLeft"),ja(pA,"conversationRemoved","conversationRemoved"),ja(pA,"conversationUpdated","conversationUpdated"),ja(pA,"participantJoined","participantJoined"),ja(pA,"participantLeft","participantLeft"),ja(pA,"participantUpdated","participantUpdated"),ja(pA,"messageAdded","messageAdded"),ja(pA,"messageRemoved","messageRemoved"),ja(pA,"messageUpdated","messageUpdated"),ja(pA,"tokenAboutToExpire","tokenAboutToExpire"),ja(pA,"tokenExpired","tokenExpired"),ja(pA,"typingEnded","typingEnded"),ja(pA,"typingStarted","typingStarted"),ja(pA,"pushNotification","pushNotification"),ja(pA,"userSubscribed","userSubscribed"),ja(pA,"userUnsubscribed","userUnsubscribed"),ja(pA,"userUpdated","userUpdated"),ja(pA,"stateChanged","stateChanged"),ja(pA,"connectionStateChanged","connectionStateChanged"),ja(pA,"connectionError","connectionError"),vA=hA),wl([Xv(Vv),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"updateToken",null),wl([Xv(Vv),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"getConversationBySid",null),wl([Xv(Vv),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"getConversationByUniqueName",null),wl([Xv(["undefined",Kv("conversation options",{friendlyName:["string","undefined"],isPrivate:["boolean","undefined"],uniqueName:["string","undefined"]})]),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],e.Client.prototype,"createConversation",null),wl([Xv($v("fcm","apn"),"string"),xl("design:type",Function),xl("design:paramtypes",[String,String]),xl("design:returntype",Promise)],e.Client.prototype,"setPushRegistrationId",null),wl([Xv($v("fcm","apn")),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"unsetPushRegistrationId",null),wl([Xv($v("fcm","apn"),Vv),xl("design:type",Function),xl("design:paramtypes",[String,String]),xl("design:returntype",Promise)],e.Client.prototype,"removePushRegistrations",null),wl([Xv(Hv),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],e.Client.prototype,"handlePushNotification",null),wl([Xv(Vv),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"getUser",null),wl([Xv("string",["undefined",Hv]),xl("design:type",Function),xl("design:paramtypes",[String,Object]),xl("design:returntype",Promise)],e.Client,"create",null),wl([Qv(Hv),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",PushNotification)],e.Client,"parsePushNotification",null),e.Client=vA=wl([Yv(Vv,[Hv,"undefined"]),xl("design:paramtypes",[String,Object])],e.Client),e.AggregatedDeliveryReceipt=AggregatedDeliveryReceipt,e.Conversation=Conversation,e.DetailedDeliveryReceipt=DetailedDeliveryReceipt,e.Media=Media,e.Message=Message,e.MessageBuilder=qP,e.NotificationTypes=gg,e.Participant=Participant,e.PushNotification=PushNotification,e.RestPaginator=AP,e.UnsentMessage=BP,e.User=User,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
|