1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8196],{92981:function(e,t,n){var a,r,i=n(67133).lW,s=void 0!==s?s:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};n(882),n(84812),n(89352),n(6778),n(85184),n(80107),n(33559);var o=n(64662),u=n(95248),c=n(35684),l=n(60746),d=n(83654),p=n(8104),f=n(1127),h=n(86358);n(20680),n(37753),n(30890),n(26803);var y=n(74001),m=n(61565);n(67998),n(26343),n(28839);var v=n(84794),_=n(46421);n(41135),n(88910),n(92648),n(21587),n(789),n(31490),n(55096);var g=n(54217),b=n(15433);n(33546);var k=n(49543);n(7122),n(3616),n(94331),n(68428),n(11414);var w=n(12184);n(70440);var x=n(52406),C=n(39459),S=n(31799),P=n(85117),R=n(68827);n(60191),n(529),n(73997),n(11547),n(10462),n(82582),n(1491),n(64954),n(13356),n(29712),n(12695),n(2101),n(46315),n(21735),n(52507),n(26137),n(43025),n(52451),n(46801),n(8479),n(59689),n(98031),n(65085),n(68053),n(33604),n(36721),n(53402),n(71147),n(1385),n(88852),n(98797),n(79712);var E=n(93933);n(28065),n(97599),n(41967);var T=n(15058);function _interopDefaultLegacy(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}n(40009);var M=_interopDefaultLegacy(o),O=_interopDefaultLegacy(u),U=_interopDefaultLegacy(c),A=_interopDefaultLegacy(l),j=_interopDefaultLegacy(d),I=_interopDefaultLegacy(p),N=_interopDefaultLegacy(f),D=_interopDefaultLegacy(h),L=_interopDefaultLegacy(y),B=_interopDefaultLegacy(m),z=function(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,Object.freeze(t)}(v),$=_interopDefaultLegacy(b),q=_interopDefaultLegacy(w),J=_interopDefaultLegacy(T);function __decorate(e,t,n,a){var r,i=arguments.length,s=i<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if(("undefined"==typeof Reflect?"undefined":B.default(Reflect))==="object"&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,a);else for(var o=e.length-1;o>=0;o--)(r=e[o])&&(s=(i<3?r(s):i>3?r(t,n,s):r(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s}function __metadata(e,t){if(("undefined"==typeof Reflect?"undefined":B.default(Reflect))==="object"&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function prepareLine(e,t){return["".concat(new Date().toISOString()," Conversations ").concat(e,":")].concat(Array.from(t))}var K=z.getLogger("twilio-conversations"),H=function(){function Logger(e){D.default(this,Logger),I.default(this,"prefix",""),this.prefix=null!=e&&e.length>0?e+" ":""}return N.default(Logger,[{key:"setLevel",value:function(e){K.setLevel(e)}},{key:"trace",value:function(){if(K.getLevel()==K.levels.TRACE){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];K.debug.apply(null,prepareLine(this.prefix+"T",t))}}},{key:"debug",value:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];K.debug.apply(null,prepareLine(this.prefix+"D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];K.info.apply(null,prepareLine(this.prefix+"I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];K.warn.apply(null,prepareLine(this.prefix+"W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];K.error.apply(null,prepareLine(this.prefix+"E",t))}}],[{key:"scope",value:function(e){return new Logger(e)}},{key:"setLevel",value:function(e){K.setLevel(e)}},{key:"trace",value:function(){if(K.getLevel()==K.levels.TRACE){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];K.debug.apply(null,prepareLine("T",t))}}},{key:"debug",value:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];K.debug.apply(null,prepareLine("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];K.info.apply(null,prepareLine("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];K.warn.apply(null,prepareLine("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];K.error.apply(null,prepareLine("E",t))}}]),Logger}();function ownKeys$5(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,a)}return n}var V="PT5S",G="PT5S",W=N.default(function Configuration(){var e,t,n,a,r,i,s,o,u=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},c=arguments.length>1?arguments[1]:void 0,l=arguments.length>2?arguments[2]:void 0;D.default(this,Configuration),I.default(this,"typingIndicatorTimeoutDefault",5e3);var d=u.Chat||u.IPMessaging||u||{};this.productId=d.productId,this.links={myConversations:c.links.my_conversations,conversations:c.links.conversations,users:c.links.users,currentUser:c.links.current_user,typing:c.links.typing,mediaService:c.links.media_service,mediaSetService:c.links.media_set_service,messagesReceipts:c.links.messages_receipts},this.limits={mediaAttachmentsCountLimit:c.options.media_attachments_count_limit,mediaAttachmentSizeLimitInMb:c.options.media_attachment_size_limit_in_mb,mediaAttachmentsTotalSizeLimitInMb:c.options.media_attachments_total_size_limit_in_mb,emailHistoriesAllowedContentTypes:c.options.email_histories_allowed_mime_types,emailBodiesAllowedContentTypes:c.options.email_bodies_allowed_mime_types},this.typingIndicatorTimeoutOverride=d.typingIndicatorTimeoutOverride,this.backoffConfiguration=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};
1t%2?ownKeys$5(Object(n),!0).forEach(function(t){I.default(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys$5(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}({min:1e3,max:4e3,maxAttemptsCount:3},d.backoffConfigOverride),this.retryWhenThrottled=void 0===d.retryWhenThrottledOverride||d.retryWhenThrottledOverride,this.userInfosToSubscribe=null!==(e=null!==(t=d.userInfosToSubscribeOverride)&&void 0!==t?t:c.options.user_infos_to_subscribe)&&void 0!==e?e:100,this.reachabilityEnabled=c.options.reachability_enabled,this.userIdentity=c.identity,this.userInfo=c.sync_objects.my_user_info,this.myConversations=c.sync_objects.my_conversations;var p=null!==(n=null!==(a=d.httpCacheIntervalOverride)&&void 0!==a?a:c.options.http_cache_interval)&&void 0!==n?n:V;try{this.httpCacheInterval=_.toSeconds(_.parse(p))}catch(e){l.error("Failed to parse http cache interval ".concat(p,", using default value ").concat(V)),this.httpCacheInterval=_.toSeconds(_.parse(V))}var f=null!==(r=null!==(i=d.consumptionReportIntervalOverride)&&void 0!==i?i:c.options.consumption_report_interval)&&void 0!==r?r:G;try{this.consumptionReportInterval=_.toSeconds(_.parse(f))}catch(e){l.error("Failed to parse consumption report interval ".concat(f,", using default value ").concat(G)),this.consumptionReportInterval=_.toSeconds(_.parse(G))}this.channelMetadataCacheCapacity=null!==(s=u.channelMetadataCacheCapacity)&&void 0!==s?s:100,this.messageRecipientsCacheCapacity=null!==(o=u.messageRecipientsCacheCapacity)&&void 0!==o?o:1e3});function parseToNumber(e){return void 0===e||isNaN(Number(e))?null:Number(e)}function parseTime(e){try{return new Date(e)}catch(e){return null}}function parseAttributes(e,t,n){var a={};if(e)try{a=JSON.parse(e)}catch(e){n.warn(t,e)}return a}var Y=function(){function UriBuilder(e){D.default(this,UriBuilder),this.base=e.replace(/\/$/,""),this.args=[],this.paths=[]}return N.default(UriBuilder,[{key:"arg",value:function(e,t){return void 0!==t&&this.args.push(encodeURIComponent(e)+"="+encodeURIComponent(t)),this}},{key:"path",value:function(e){return this.paths.push(encodeURIComponent(e)),this}},{key:"build",value:function(){var e=this.base;return this.paths.length&&(e+="/"+this.paths.join("/")),this.args.length&&(e+="?"+this.args.join("&")),e}}]),UriBuilder}();function isEqual(e,t){if(e===t)return!0;if(null===e||null===t||void 0===e||void 0===t)return e===t;if(B.default(e)!==B.default(t))return!1;if("object"!==B.default(e))return e===t;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every(function(e,n){return isEqual(e,t[n])});if(Array.isArray(e)||Array.isArray(t))return!1;var n=Object.keys(e),a=Object.keys(t);return n.length===a.length&&n.every(function(n){return isEqual(e[n],t[n])})}var Q=g.custom(function(e){return[["string","number","boolean","object"].includes(B.default(e)),"a JSON type"]}),X=g.custom(function(e){return[["undefined","string","number","boolean","object"].includes(B.default(e)),"an optional JSON type"]}),Z=g.objectSchema("send media options",{contentType:[g.literal(null),"string"],filename:["string","undefined"],media:[g.literal("null"),"string"].concat($.default("function"==typeof i?[i]:[]),$.default("function"==typeof Blob?[Blob]:[]))}),ee=H.scope("User"),et=function(e){U.default(User,e);var t,n,a,r,i,s,o,u,c=(t=function(){if("undefined"==typeof Reflect||!Reflect.construct||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}}(),function(){var e,n=j.default(User);if(t){var a=j.default(this).constructor;e=Reflect.construct(n,arguments,a)}else e=n.apply(this,arguments);return A.default(this,e)});function User(e,t,n,a){var r;return D.default(this,User),r=c.call(this),I.default(O.default(r),"promiseToFetch",null),I.default(O.default(r),"updated","updated"),I.default(O.default(r),"userSubscribed","userSubscribed"),I.default(O.default(r),"userUnsubscribed","userUnsubscribed"),r.services=a,r.subscribed="initializing",r.setMaxListeners(0),r.state={identity:e,entityName:t,friendlyName:null,attributes:{},online:null,notifiable:null},r._initializationPromise=new Promise(function(e){r._resolveInitializationPromise=e}),null!==n&&r._resolveInitialization(n,e,t,!1),r}return N.default(User,[{key:"identity",get:function(){return this.state.identity},set:function(e){this.state.identity=e}},{key:"entityName",set:function(e){this.state.entityName=e}},{key:"attributes",get:function(){return this.state.attributes}},{key:"friendlyName",get:function(){return this.state.friendlyName}},{key:"isOnline",get:function(){return this.state.online}},{key:"isNotifiable",get:function(){return this.state.notifiable}},{key:"isSubscribed",get:function(){return"subscribed"==this.subscribed}},{key:"_update",value:(n=M.default(L.default.mark(function _callee(e,t){var n,a;return L.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this._initializationPromise;case 2:n=[],ee.debug("User for",this.state.identity,"updated:",e,t),r.t0=e,r.next="friendlyName"===r.t0?7:"attributes"===r.t0?9:"reachability"===r.t0?12:15;break;case 7:return this.state.friendlyName!==t.value&&(n.push("friendlyName"),this.state.friendlyName=t.value),r.abrupt("break",16);case 9:return a=parseAttributes(t.value,"Retrieved malformed attributes from the server for user: ".concat(this.state.identity),ee),isEqual(this.state.attributes,a)||(this.state.attributes=a,n.push("attributes")),r.abrupt("break",16);case 12:return this.state.online!==t.online&&(this.state.online=t.online,n.push("reachabilityOnline")),this.state.notifiable!==t.notifiable&&(this.state.notifiable=t.notifiable,n.push("reachabilityNotifiable")),r.abrupt("break",16);case 15:return r.abrupt("return");case 16:n.length>
10&&this.emit("updated",{user:this,updateReasons:n});case 17:case"end":return r.stop()}},_callee,this)})),function(e,t){return n.apply(this,arguments)})},{key:"_updateReachabilityInfo",value:(a=M.default(L.default.mark(function _callee2(e,t){var n=this;return L.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,this._initializationPromise;case 2:if(this.configuration.reachabilityEnabled){a.next=4;break}return a.abrupt("return",Promise.resolve());case 4:return a.abrupt("return",e.get("reachability").then(t).catch(function(e){ee.warn("Failed to get reachability info for ",n.state.identity,e)}));case 5:case"end":return a.stop()}},_callee2,this)})),function(e,t){return a.apply(this,arguments)})},{key:"_fetch",value:(r=M.default(L.default.mark(function _callee3(){var e=this;return L.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._initializationPromise;case 2:if(this.state.entityName){t.next=4;break}return t.abrupt("return",this);case 4:return this.promiseToFetch=this.services.syncClient.map({id:this.state.entityName,mode:"open_existing",includeItems:!0}).then(function(t){return e.entity=t,t.on("itemUpdated",function(t){return ee.debug(e.state.entityName+" ("+e.state.identity+") itemUpdated: "+t.item.key),e._update(t.item.key,t.item.data)}),t.on("itemAdded",function(t){return ee.debug(e.state.entityName+" ("+e.state.identity+") itemAdded: "+t.item.key),e._update(t.item.key,t.item.data)}),Promise.all([t.get("friendlyName").then(function(t){return e._update(t.key,t.data)}),t.get("attributes").then(function(t){return e._update(t.key,t.data)}),e._updateReachabilityInfo(t,function(t){return e._update(t.key,t.data)})])}).then(function(){return ee.debug("Fetched for",e.identity),e.subscribed="subscribed",e.emit("userSubscribed",e),e}).catch(function(t){throw e.promiseToFetch=null,t}),t.abrupt("return",this.promiseToFetch);case 6:case"end":return t.stop()}},_callee3,this)})),function(){return r.apply(this,arguments)})},{key:"_ensureFetched",value:(i=M.default(L.default.mark(function _callee4(){return L.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._initializationPromise;case 2:return e.abrupt("return",this.promiseToFetch||this._fetch());case 3:case"end":return e.stop()}},_callee4,this)})),function(){return i.apply(this,arguments)})},{key:"updateAttributes",value:(s=M.default(L.default.mark(function _callee5(e){return L.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._initializationPromise;case 2:if("unsubscribed"!=this.subscribed){t.next=4;break}throw Error("Can't modify unsubscribed object");case 4:return t.next=6,this.services.commandExecutor.mutateResource("post",this.links.self,{attributes:JSON.stringify(e)});case 6:return t.abrupt("return",this);case 7:case"end":return t.stop()}},_callee5,this)})),function(e){return s.apply(this,arguments)})},{key:"updateFriendlyName",value:(o=M.default(L.default.mark(function _callee6(e){return L.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._initializationPromise;case 2:if("unsubscribed"!=this.subscribed){t.next=4;break}throw Error("Can't modify unsubscribed object");case 4:return t.next=6,this.services.commandExecutor.mutateResource("post",this.links.self,{friendly_name:e});case 6:return t.abrupt("return",this);case 7:case"end":return t.stop()}},_callee6,this)})),function(e){return o.apply(this,arguments)})},{key:"unsubscribe",value:(u=M.default(L.default.mark(function _callee7(){return L.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._initializationPromise;case 2:if(!this.promiseToFetch){e.next=9;break}return e.next=5,this.promiseToFetch;case 5:this.entity.close(),this.promiseToFetch=null,this.subscribed="unsubscribed",this.emit("userUnsubscribed",this);case 9:case"end":return e.stop()}},_callee7,this)})),function(){return u.apply(this,arguments)})},{key:"_resolveInitialization",value:function(e,t,n,a){this.configuration=e,this.identity=t,this.entityName=n,this.links={self:"".concat(this.configuration.links.users,"/").concat(encodeURIComponent(this.identity))}
1,this._resolveInitializationPromise(),a&&this.emit("updated",{user:this,updateReasons:["friendlyName","attributes","reachabilityOnline","reachabilityNotifiable"]})}}]),User}(k.ReplayEventEmitter);function _arrayLikeToArray$5(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=Array(t);n<t;n++)a[n]=e[n];return a}__decorate([g.validateTypesAsync(Q),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],et.prototype,"updateAttributes",null),__decorate([g.validateTypesAsync(["string"]),__metadata("design:type",Function),__metadata("design:paramtypes",[String]),__metadata("design:returntype",Promise)],et.prototype,"updateFriendlyName",null);var en=function(){var e;function Network(e,t){D.default(this,Network),this.configuration=e,this.services=t,this.cache=new Map,this.cacheLifetime=100*this.configuration.httpCacheInterval,this.cleanupCache()}return N.default(Network,[{key:"isExpired",value:function(e){return!this.cacheLifetime||Date.now()-e>this.cacheLifetime}},{key:"cleanupCache",value:function(){var e,t=function(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray$5(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray$5(e,t)}}(e))){n&&(e=n);var a=0,F=function(){};return{s:F,n:function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}},e:function(e){throw e},f:F}}throw TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,i=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return i=e.done,e},e:function(e){s=!0,r=e},f:function(){try{i||null==n.return||n.return()}finally{if(s)throw r}}}}(this.cache);try{for(t.s();!(e=t.n()).done;){var n=q.default(e.value,2),a=n[0],r=n[1];this.isExpired(r.timestamp)&&this.cache.delete(a)}}catch(e){t.e(e)}finally{t.f()}0===this.cache.size&&clearInterval(this.timer)}},{key:"pokeTimer",value:function(){var e=this;this.timer=this.timer||setInterval(function(){return e.cleanupCache()},2*this.cacheLifetime)}},{key:"executeWithRetry",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return new Promise(function(a,r){var i=[502,503,504];n&&i.push(429);var s=new x.Retrier(t.configuration.backoffConfiguration);s.on("attempt",function(){e().then(function(e){return s.succeeded(e)}).catch(function(e){i.indexOf(e.status)>-1?s.failed(e):"Twilsock disconnected"===e.message?s.failed(e):(s.removeAllListeners(),s.cancel(),r(e))})}),s.on("succeeded",function(e){a(e)}),s.on("cancelled",function(e){return r(e)}),s.on("failed",function(e){return r(e)}),s.start()})}},{key:"get",value:(e=M.default(L.default.mark(function _callee(e){var t,n,a,r=this;return L.default.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(!((t=this.cache.get(e))&&!this.isExpired(t.timestamp))){i.next=3;break}return i.abrupt("return",t.response);case 3:return n={},i.next=6,this.executeWithRetry(function(){return r.services.transport.get(e,n,r.configuration.productId)},this.configuration.retryWhenThrottled);case 6:return a=i.sent,this.cache.set(e,{response:a,timestamp:Date.now()}),this.pokeTimer(),i.abrupt("return",a);case 10:case"end":return i.stop()}},_callee,this)})),function(t){return e.apply(this,arguments)})}]),Network}(),ea=N.default(function NotificationTypes(){D.default(this,NotificationTypes)});I.default(ea,"TYPING_INDICATOR","twilio.ipmsg.typing_indicator"),I.default(ea,"NEW_MESSAGE","twilio.conversations.new_message"),I.default(ea,"ADDED_TO_CONVERSATION","twilio.conversations.added_to_conversation"),I.default(ea,"REMOVED_FROM_CONVERSATION","twilio.conversations.removed_from_conversation"),I.default(ea,"CONSUMPTION_UPDATE","twilio.channel.consumption_update");var er=H.scope("Participant"),ei=function(e){U.default(Participant,e);var t,n,a,r,i=(t=function(){if("undefined"==typeof Reflect||!Reflect.construct||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}}(),function(){var e,n=j.default(Participant);
1if(t){var a=j.default(this).constructor;e=Reflect.construct(n,arguments,a)}else e=n.apply(this,arguments);return A.default(this,e)});function Participant(e,t,n,a,r){var s,o,u;if(D.default(this,Participant),(u=i.call(this)).conversation=n,u.links=a,u.services=r,u.state={attributes:parseAttributes(e.attributes,"Retrieved malformed attributes from the server for participant: "+t,er),dateCreated:e.dateCreated?parseTime(e.dateCreated):null,dateUpdated:e.dateCreated?parseTime(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?parseTime(e.lastConsumptionTimestamp):null,type:e.type||"chat",userInfo:e.userInfo,bindings:null!==(o=e.bindings)&&void 0!==o?o:{}},!e.identity&&!e.type)throw Error("Received invalid Participant object from server: Missing identity or type of Participant.");return u}return N.default(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(Participant.typingStarted,this),this.conversation.emit(eC.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(Participant.typingEnded,this),this.conversation.emit(eC.typingEnded,this),clearInterval(this.state.typingTimeout),this.state.typingTimeout=null)}},{key:"_update",value:function(e){var t=[],n=parseAttributes(e.attributes,"Retrieved malformed attributes from the server for participant: "+this.state.sid,er);e.attributes&&!isEqual(this.state.attributes,n)&&(this.state.attributes=n,t.push("attributes"));var a=parseTime(e.dateUpdated);e.dateUpdated&&(null==a?void 0:a.getTime())!==(this.state.dateUpdated&&this.state.dateUpdated.getTime())&&(this.state.dateUpdated=a,t.push("dateUpdated"));var r=parseTime(e.dateCreated);if(e.dateCreated&&(null==r?void 0:r.getTime())!==(this.state.dateCreated&&this.state.dateCreated.getTime())&&(this.state.dateCreated=r,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 i=new Date(e.lastConsumptionTimestamp);this.state.lastReadTimestamp&&this.state.lastReadTimestamp.getTime()===i.getTime()||(this.state.lastReadTimestamp=i,t.push("lastReadTimestamp"))}return e.bindings&&!isEqual(this.state.bindings,e.bindings)&&(this.state.bindings=e.bindings,t.push("bindings")),t.length>0&&this.emit(Participant.updated,{participant:this,updateReasons:t}),this}},{key:"getUser",value:(n=M.default(L.default.mark(function _callee(){return L.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!("chat"!=this.type)){e.next=2;break}throw 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()}},_callee,this)})),function(){return n.apply(this,arguments)})},{key:"remove",value:(a=M.default(L.default.mark(function _callee2(){return L.default.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()}},_callee2,this)})),function(){return a.apply(this,arguments)})},{key:"updateAttributes",value:(r=M.default(L.default.mark(function _callee3(e){return L.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{attributes:JSON.stringify(e)});case 2:return t.abrupt("return",this);case 3:case"end":return t.stop()}},_callee3,this)})),function(e){return r.apply(this,arguments)})}]),Participant}(k.ReplayEventEmitter);I.default(ei,"typingStarted","typingStarted"),I.default(ei,"typingEnded","typingEnded"),I.default(ei,"updated","updated"),__decorate([g.validateTypesAsync(Q),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],ei.prototype,"updateAttributes",null);var es=H.scope("Participants"),eo=function(e){U.default(Participants,e);var t,n,a,r,i,s,o,u,c,l=(t=function(){if("undefined"==typeof Reflect||!Reflect.construct||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}}(),function(){var e,n=j.default(Participants);if(t){var a=j.default(this).constructor;e=Reflect.construct(n,arguments,a)}else e=n.apply(this,arguments);return A.default(this,e)});function Participants(e,t,n,a){var r;return D.default(this,Participants),r=l.call(this),I.default(O.default(r),"rosterEntityPromise",null),r.conversation=e,r.participants=t,r.links=n,r.services=a,r}return N.default(Participants,[{key:"unsubscribe",value:(n=M.default(L.default.mark(function _callee(){return L.default.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()}},_callee,this)})),function(){return n.apply(this,arguments)})},{key:"subscribe",value:function(e){var t=this,n="string"==typeof e?this.services.syncClient.map({id:e,mode:"open_existing"}):Promise.resolve(e);return this.rosterEntityPromise=this.rosterEntityPromise||n.then(function(e){e.on(P.SyncMap.itemAdded,function(e){es.debug(t.conversation.sid+" itemAdded: "+e.item.key),t.upsertParticipant(e.item.key,e.item.data).then(function(e){t.emit(eC.participantJoined,e)})}),e.on(P.SyncMap.itemRemoved,function(e){es.debug(t.conversation.sid+" itemRemoved: "+e.key);var n=e.key;if(t.participants.has(n)){var a=t.participants.get(n);t.participants.delete(n),a&&t.emit(eC.participantLeft,a)}}),e.on(P.SyncMap.itemUpdated,function(e){es.debug(t.conversation.sid+" itemUpdated: "+e.item.key),t.upsertParticipant(e.item.key,e.item.data).catch(function(e){return es.error(e)})});var n=[];return e.getItems().then(function rosterMapHandler(e){return e.items.forEac
1h(function(e){n.push(t.upsertParticipant(e.key,e.data))}),e.hasNextPage?e.nextPage().then(rosterMapHandler):null}).then(function(){return Promise.all(n)}).then(function(){return e})}).catch(function(e){throw t.rosterEntityPromise=null,"disconnected"!=t.services.syncClient.connectionState&&es.error("Failed to get roster object for conversation",t.conversation.sid,e),es.debug("ERROR: Failed to get roster object for conversation",t.conversation.sid,e),e})}},{key:"upsertParticipantFromResponse",value:(a=M.default(L.default.mark(function _callee2(e){var t,n,a,r,i,s,o,u;return L.default.wrap(function(c){for(;;)switch(c.prev=c.next){case 0:return n=e.sid,a=e.attributes,r=e.date_created,i=e.date_updated,s=e.identity,o=e.role_sid,u=e.messaging_binding,c.next=3,this.upsertParticipant(n,{attributes:a,dateCreated:new Date(r),dateUpdated:new Date(i),identity:s,roleSid:o,lastConsumedMessageIndex:null,lastConsumptionTimestamp:null,type:null!==(t=null==u?void 0:u.type)&&void 0!==t?t:"chat"});case 3:return c.abrupt("return",c.sent);case 4:case"end":return c.stop()}},_callee2,this)})),function(e){return a.apply(this,arguments)})},{key:"upsertParticipant",value:(r=M.default(L.default.mark(function _callee3(e,t){var n,a,r=this;return L.default.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(!(n=this.participants.get(e))){i.next=3;break}return i.abrupt("return",n._update(t));case 3:return a={self:"".concat(this.links.participants,"/").concat(e)},n=new ei(t,e,this.conversation,a,this.services),this.participants.set(e,n),n.on(ei.updated,function(e){return r.emit(eC.participantUpdated,e)}),i.abrupt("return",n);case 8:case"end":return i.stop()}},_callee3,this)})),function(e,t){return r.apply(this,arguments)})},{key:"getParticipants",value:(i=M.default(L.default.mark(function _callee4(){var e=this;return L.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.rosterEntityPromise?this.rosterEntityPromise.then(function(){var t=[];
1return e.participants.forEach(function(e){return t.push(e)}),t}):[]);case 1:case"end":return t.stop()}},_callee4,this)})),function(){return i.apply(this,arguments)})},{key:"getParticipantBySid",value:(s=M.default(L.default.mark(function _callee5(e){var t=this;return L.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.abrupt("return",this.rosterEntityPromise?this.rosterEntityPromise.then(function(){var n=t.participants.get(e);if(!n)throw Error("Participant with SID "+e+" was not found");return n}):null);case 1:case"end":return n.stop()}},_callee5,this)})),function(e){return s.apply(this,arguments)})},{key:"getParticipantByIdentity",value:(o=M.default(L.default.mark(function _callee6(e){var t,n=this;return L.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return t=null,a.abrupt("return",this.rosterEntityPromise?this.rosterEntityPromise.then(function(){if(n.participants.forEach(function(n){n.identity===e&&(t=n)}),!t)throw Error("Participant with identity "+e+" was not found");return t}):null);case 2:case"end":return a.stop()}},_callee6,this)})),function(e){return o.apply(this,arguments)})},{key:"add",value:(u=M.default(L.default.mark(function _callee7(e,t){return L.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,this.services.commandExecutor.mutateResource("post",this.links.participants,{identity:e,attributes:void 0!==t?JSON.stringify(t):void 0});case 2:return n.abrupt("return",n.sent);case 3:case"end":return n.stop()}},_callee7,this)})),function(e,t){return u.apply(this,arguments)})},{key:"addNonChatParticipant",value:(c=M.default(L.default.mark(function _callee8(e,t){var n,a,r,i,s=arguments;return L.default.wrap(function(o){for(;;)switch(o.prev=o.next){case 0:return r=s.length>2&&void 0!==s[2]?s[2]:{},i=s.length>3&&void 0!==s[3]?s[3]:{},o.next=4,this.services.commandExecutor.mutateResource("post",this.links.participants,{attributes:void 0!==r?JSON.stringify(r):void 0,messaging_binding:{address:t,proxy_address:e,name:null==i?void 0:null===(n=i.email)||void 0===n?void 0:n.name,level:null==i?void 0:null===(a=i.email)||void 0===a?void 0:a.level}});case 4:return o.abrupt("return",o.sent);case 5:case"end":return o.stop()}},_callee8,this)})),function(e,t){return c.apply(this,arguments)})},{key:"remove",value:function(e){return this.services.commandExecutor.mutateResource("delete","".concat(this.links.participants,"/").concat(encodeURIComponent(e)))}}]),Participants}(k.ReplayEventEmitter),eu=function(){function Media(e,t){var n;D.default(this,Media),I.default(this,"mcsMedia",null),this.services=t,e instanceof R.McsMedia&&(this.mcsMedia=e),this.state={sid:e.sid,category:e.category,filename:null!==(n=e.filename)&&void 0!==n?n:null,contentType:e.contentType,size:e.size}}return N.default(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:function(){var e,t=this;return new R.CancellablePromise((e=M.default(L.default.mark(function _callee(e,n,a){var r,i,s,o;return L.default.wrap(function(u){for(;;)switch(u.prev=u.next){case 0:if(i=t.mcsMedia?void 0:t._fetchMcsMedia(),s=null===(r=t.mcsMedia)||void 0===r?void 0:r.getContentUrl(),a(function(){i&&i.cancel(),s&&s.cancel()}),u.prev=3,s){u.next=9;break}return u.next=7,i;case 7:s=null==(o=u.sent)?void 0:o.getContentUrl();case 9:if(u.t0=e,!s){u.next=16;break}return u.next=13,s;case 13:u.t1=u.sent,u.next=17;break;case 16:u.t1=null;case 17:u.t2=u.t1,(0,u.t0)(u.t2),u.next=24;break;case 21:u.prev=21,u.t3=u.catch(3),n(u.t3);case 24:case"end":return u.stop()}},_callee,null,[[3,21]])})),function(t,n,a){return e.apply(this,arguments)}))}},{key:"_fetchMcsMedia",value:function(){var e,t=this;return new R.CancellablePromise((e=M.default(L.default.mark(function _callee2(e,n,a){var r;return L.default.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return null===t.services.mcsClient&&n(Error("Media Content Service is unavailable")),r=t.services.mcsClient.get(t.state.sid),a(function(){return r.cancel()}),i.prev=3,i.next=6,r;case 6:t.mcsMedia=i.sent,t.state=t.mcsMedia._state(),e(t.mcsMedia),i.next=14;break;case 11:i.prev=11,i.t0=i.catch(3),n(i.t0);case 14:case"end":return i.stop()}},_callee2,null,[[3,11]])})),function(t,n,a){return e.apply(this,arguments)}))}},{key:"_state",value:function(){return this.state}}]),Media}(),ec=function(){function AggregatedDeliveryReceipt(e){D.default(this,AggregatedDeliveryReceipt),this.state=e}return N.default(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,a=this.delivered===e.delivered,r=this.read===e.read,i=this.undelivered===e.undelivered,s=this.failed===e.failed;return t&&n&&a&&r&&i&&s}}]),AggregatedDeliveryReceipt}(),el=function(){function RestPaginator(e,t,n,a){D.default(this,RestPaginator),this.state={prevToken:n,nextToken:a,source:t,items:e}}return N.default(RestPaginator,[{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(Error("No next page"))}},{key:"prevPage",value:function(){return this.hasPrevPage?this.state.source(this.state.prevToken):Promise.reject(Error("No previous page"))}}]),RestPaginator}(),ed=N.default(function DetailedDeliveryReceipt(e){D.default(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}),collectActions=function(e){return e.map(function(e){var t,n,a,r,i=JSON.stringify(e);switch(e.type){case"QUICK_REPLY":return{type:"reply",title:e.title,id:null!==(t=e.id)&&void 0!==t?t:"",index:null!==(n=e.index)&&void 0!==n?n:0,rawData:i};case"PHONE_NUMBER":return{type:"phone",title:e.title,phone:null!==(a=e.phone)&&void 0!==a?a:"",rawData:i};case"URL":return{type:"url",title:e.title,url:null!==(r=e.url)&&void 0!==r?r:"",rawData:i};default:return{type:"other",rawData:i}}})},parseVariant=function(e,t){var n,a,r=JSON.stringify(t);switch(e){case"twilio/text":return{type:"text",body:t.body,rawData:r};case"twilio/media":return{type:"media",body:t.body,media:t.media,rawData:r};case"twilio/location":return{type:"location",longitude:t.longitude,latitude:t.latitude,label:t.label,rawData:r};case"twilio/quick-reply":return{type:"quickReply",body:t.body,replies:t.actions,rawData:r};case"twilio/call-to-action":return{type:"callToAction",body:t.body,actions:collectActions(t.actions),rawData:r};case"twilio/list-picker":return{type:"listPicker",body:t.body,button:t.button,items:t.items,rawData:r};case"twilio/card":return{type:"card",title:t.title,subtitle:t.subtitle,media:null!==(n=t.media)&&void 0!==n?n:[],actions:collectActions(null!==(a=t.actions)&&void 0!==a?a:[]),rawData:r};default:return{type:"other",rawData:r}}},collectVariants=function(e){for(var t=new Map,n=0,a=Object.entries(e);n<a.length;n++){var r=q.default(a[n],2),i=r[0],s=r[1];t.set(i,parseVariant(i,s))}return t},ep=function(){function ContentTemplateVariable(e,t){D.default(this,ContentTemplateVariable),this.name=e,this.value=t}
1return N.default(ContentTemplateVariable,[{key:"copyWithValue",value:function(e){return new ContentTemplateVariable(this.name,e)}}]),ContentTemplateVariable}(),ef=N.default(function ContentTemplate(e){D.default(this,ContentTemplate),this.sid=e.sid,this.friendlyName=e.friendly_name,this.variables=Object.entries(JSON.parse(e.variables)).map(function(e){var t=q.default(e,2),n=t[0],a=t[1];return new ep(n,a)}),this.variants=collectVariants(e.variants),this.dateCreated=new Date(e.date_created),this.dateUpdated=new Date(e.date_updated)});function ownKeys$4(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,a)}return n}function _objectSpread$4(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys$4(Object(n),!0).forEach(function(t){I.default(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys$4(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function _classPrivateMethodInitSpec(e,t){(function(e,t){if(t.has(e))throw TypeError("Cannot initialize the same private elements twice on an object")})(e,t),t.add(e)}function _classPrivateMethodGet(e,t,n){if(!t.has(e))throw TypeError("attempted to get private field on non-instance");return n}var eh=H.scope("Message"),ey=s.XMLHttpRequest||{},em=new WeakSet,ev=new WeakSet,e_=function(e){U.default(Message,e);var t,n,a,r,i,s,o,u,c,l,d=(t=function(){if("undefined"==typeof Reflect||!Reflect.construct||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}}(),function(){var e,n=j.default(Message);if(t){var a=j.default(this).constructor;e=Reflect.construct(n,arguments,a)}else e=n.apply(this,arguments);return A.default(this,e)});function Message(e,t,n,a,r,i){var s,o,u,c,l,p,f,h;return D.default(this,Message),h=d.call(this),_classPrivateMethodInitSpec(O.default(h),ev),_classPrivateMethodInitSpec(O.default(h),em),h.conversation=n,h.links=a,h.configuration=r,h.services=i,h.state={sid:t.sid,index:e,author:t.author,subject:t.subject,contentSid:t.contentSid,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:parseAttributes(t.attributes,"Got malformed attributes for the message ".concat(t.sid),eh),type:null!==(u=t.type)&&void 0!==u?u:"text",media:null,medias:null,participantSid:null!==(c=t.memberSid)&&void 0!==c?c:null,aggregatedDeliveryReceipt:t.delivery?new ec(t.delivery):null,hasChannelMetadata:null!==(l=t.channelMetadata)&&void 0!==l&&l},_classPrivateMethodGet(O.default(h),ev,_assignMedias2).call(O.default(h),null!==(p=t.medias)&&void 0!==p?p:null,null!==(f=t.media)&&void 0!==f?f:null),h}return N.default(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:"contentSid",get:function(){return this.state.contentSid}},{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.getMediaByCategories(["media"])}},{key:"participantSid",get:function(){return this.state.participantSid}},{key:"aggregatedDeliveryReceipt",get:function(){return this.state.aggregatedDeliveryReceipt}},{key:"getMediaByCategory",value:function(e){return this.getMediaByCategories(e)}},{key:"getMediaByCategories",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.getMediaByCategories(["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.getMediaByCategories(["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,n,a,r,i,s,o=this,u=[];(e.text||"string"==typeof e.text)&&e.text!==this.state.body&&(this.state.body=e.text,u.push("body")),e.subject&&e.subject!==this.state.subject&&(this.state.subject=e.subject,u.push("subject")),e.lastUpdatedBy&&e.lastUpdatedBy!==this.state.lastUpdatedBy&&(this.state.lastUpdatedBy=e.lastUpdatedBy,u.push("lastUpdatedBy")),e.author&&e.author!==this.state.author&&(this.state.author=e.author,u.push("author")),e.dateUpdated&&new Date(e.dateUpdated).getTime()!==(this.state.dateUpdated&&this.state.dateUpdated.getTime())&&(this.state.dateUpdated=new Date(e.dateUpdated),u.push("dateUpdated")),e.timestamp&&new Date(e.timestamp).getTime()!==(this.state.timestamp&&this.state.timestamp.getTime())&&(this.state.timestamp=new Date(e.timestamp),u.push("dateCreated"));var c=parseAttributes(e.attributes,"Got malformed attributes for the message ".concat(this.sid),eh);
1isEqual(this.state.attributes,c)||(this.state.attributes=c,u.push("attributes"));var l=e.delivery,d=this.state.aggregatedDeliveryReceipt;l&&l.total&&l.delivered&&l.failed&&l.read&&l.sent&&l.undelivered&&(d?d._isEquals(l)||(d._update(l),u.push("deliveryReceipt")):(this.state.aggregatedDeliveryReceipt=new ec(l),u.push("deliveryReceipt"))),isEqual((null!==(a=e.medias)&&void 0!==a?a:[]).map(function(e){var t;return null===(t=_classPrivateMethodGet(o,em,_wrapMedia2).call(o,e))||void 0===t?void 0:t._state()}).filter(function(e){return null!==e}),(null!==(r=this.state.medias)&&void 0!==r?r:[]).map(function(e){return e._state()}).filter(function(e){return null!==e}))&&isEqual(null===(i=_classPrivateMethodGet(this,em,_wrapMedia2).call(this,e.media))||void 0===i?void 0:i._state(),null===(s=this.state.media)||void 0===s?void 0:s._state())||(_classPrivateMethodGet(this,ev,_assignMedias2).call(this,null!==(t=e.medias)&&void 0!==t?t:null,null!==(n=e.media)&&void 0!==n?n:null),u.push("media")),u.length>0&&this.emit("updated",{message:this,updateReasons:u})}},{key:"getParticipant",value:(n=M.default(L.default.mark(function _callee(){var e,t,n=this;return L.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(e=null,!this.state.participantSid){a.next=5;break}return a.next=4,this.conversation.getParticipantBySid(this.state.participantSid).catch(function(){return eh.debug('Participant with sid "'.concat(n.participantSid,'" not found for message ').concat(n.sid)),null});case 4:e=a.sent;case 5:if(!(!e&&this.state.author)){a.next=9;break}return a.next=8,this.conversation.getParticipantByIdentity(this.state.author).catch(function(){return eh.debug('Participant with identity "'.concat(n.author,'" not found for message ').concat(n.sid)),null});case 8:e=a.sent;case 9:if(!e){a.next=11;break}return a.abrupt("return",e);case 11:throw t="Participant with ",this.state.participantSid&&(t+="SID '"+this.state.participantSid+"' "),this.state.author&&(this.state.participantSid&&(t+="or "),t+="identity '"+this.state.author+"' "),"Participant with "===t&&(t="Participant "),Error(t+="was not found");case 17:case"end":return a.stop()}},_callee,this)})),function(){return n.apply(this,arguments)})},{key:"getDetailedDeliveryReceipts",value:(a=M.default(L.default.mark(function _callee2(){var e,t;return L.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,this._getDetailedDeliveryReceiptsPaginator();case 2:t=(e=n.sent).items;case 4:if(!e.hasNextPage){n.next=11;break}return n.next=7,e.nextPage();case 7:e=n.sent,t=[].concat($.default(t),$.default(e.items)),n.next=4;break;case 11:return n.abrupt("return",t);case 12:case"end":return n.stop()}},_callee2,this)})),function(){return a.apply(this,arguments)})},{key:"remove",value:(r=M.default(L.default.mark(function _callee3(){return L.default.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()}},_callee3,this)})),function(){return r.apply(this,arguments)})},{key:"updateBody",value:(i=M.default(L.default.mark(function _callee4(e){return L.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{body:e});case 2:return t.abrupt("return",this);case 3:case"end":return t.stop()}},_callee4,this)})),function(e){return i.apply(this,arguments)})},{key:"updateAttributes",value:(s=M.default(L.default.mark(function _callee5(e){return L.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{attributes:void 0!==e?JSON.stringify(e):void 0});case 2:return t.abrupt("return",this);case 3:case"end":return t.stop()}},_callee5,this)})),function(e){return s.apply(this,arguments)})},{key:"attachTemporaryUrlsFor",value:(o=M.default(L.default.mark(function _callee6(e){var t,n=this;return L.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(t=null==e?void 0:e.map(function(e){return e.sid}),!(this.services.mcsClient&&t)){a.next=7;break}return a.next=4,this.services.mcsClient.mediaSetGet(t);case 4:return a.abrupt("return",a.sent.map(function(e){return new eu(e,n.services)}));case 7:throw Error("Media Content Service is unavailable");case 8:case"end":return a.stop()}},_callee6,this)})),function(e){return o.apply(this,arguments)})},{key:"getTemporaryContentUrlsForMedia",value:function(e){var t=e.map(function(e){return e.sid});return this.getTemporaryContentUrlsForMediaSids(t)}},{key:"getTemporaryContentUrlsForMediaSids",value:function(e){var t,n=this;
1return new R.CancellablePromise((t=M.default(L.default.mark(function _callee7(t,a,r){var i;return L.default.wrap(function(s){for(;;)switch(s.prev=s.next){case 0:if(i=n.services.mcsClient.mediaSetGetContentUrls(null!=e?e:[]),!(!n.services.mcsClient||!e)){s.next=4;break}return a(Error("Media Content Service is unavailable")),s.abrupt("return");case 4:return r(function(){i.cancel()}),s.prev=5,s.next=8,i;case 8:t(s.sent),s.next=15;break;case 12:s.prev=12,s.t0=s.catch(5),a(s.t0);case 15:case"end":return s.stop()}},_callee7,null,[[5,12]])})),function(e,n,a){return t.apply(this,arguments)}))}},{key:"getTemporaryContentUrlsForAttachedMedia",value:function(){var e,t=this.attachedMedia,n=null!==(e=null==t?void 0:t.map(function(e){return e.sid}))&&void 0!==e?e:[];return this.getTemporaryContentUrlsForMediaSids(n)}},{key:"_getDetailedDeliveryReceiptsPaginator",value:(u=M.default(L.default.mark(function _callee8(e){var t,n,a,r=this;return L.default.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return t=this.configuration.links.messagesReceipts.replace("%s",this.conversation.sid).replace("%s",this.sid),n=new Y(t).arg("PageToken",null==e?void 0:e.pageToken).arg("PageSize",null==e?void 0:e.pageSize).build(),i.next=4,this.services.network.get(n);case 4:return a=i.sent,i.abrupt("return",new el(a.body.delivery_receipts.map(function(e){return new ed(e)}),function(e,t){return r._getDetailedDeliveryReceiptsPaginator({pageToken:e,pageSize:t})},a.body.meta.previous_token,a.body.meta.next_token));case 6:case"end":return i.stop()}},_callee8,this)})),function(e){return u.apply(this,arguments)})},{key:"getContentData",value:function(){var e,t=this;return new R.CancellablePromise((e=M.default(L.default.mark(function _callee9(e,n,a){var r,i,s,o,u,c,l,d;return L.default.wrap(function(p){for(;;)switch(p.prev=p.next){case 0:if(null!==t.state.contentSid){p.next=3;break}return e(null),p.abrupt("return");case 3:if(null!==(r=t.getMediaByCategories(["body"]))){p.next=7;break}return e(null),p.abrupt("return");case 7:if(i="application/x-vnd.com.twilio.rich.",0!==(s=r.filter(function(e){return e.contentType.startsWith(i)})).length){p.next=12;break}return e(null),p.abrupt("return");case 12:return u=(o=s[0]).getContentTemporaryUrl(),a(function(){u.cancel()}),p.prev=15,p.next=18,u;case 18:c=p.sent,p.next=25;break;case 21:return p.prev=21,p.t0=p.catch(15),n(p.t0),p.abrupt("return");case 25:if(null!==c){p.next=28;break}return e(null),p.abrupt("return");case 28:return l=new Promise(function(e,t){var n,r=!1,i=new ey;i.open("GET",null!==(n=c)&&void 0!==n?n:"",!0),i.responseType="text",i.onreadystatechange=function(){4!==i.readyState||r||e(i.responseText)},i.onerror=function(){t(i.statusText)},a(function(){r=!0,i.abort(),t(Error("XHR has been aborted"))}),i.send()}),p.prev=29,p.next=32,l;case 32:d=JSON.parse(p.sent),p.next=40;break;case 36:return p.prev=36,p.t1=p.catch(29),n(p.t1),p.abrupt("return");case 40:e(parseVariant(o.contentType.replace(i,"").replace(".","/"),d.data));case 42:case"end":return p.stop()}},_callee9,null,[[15,21],[29,36]])})),function(t,n,a){return e.apply(this,arguments)}))}},{key:"getChannelMetadata",value:(c=M.default(L.default.mark(function _callee10(){return L.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.state.hasChannelMetadata){e.next=2;break}return e.abrupt("return",null);case 2:return e.next=4,this.services.channelMetadataClient.getChannelMetadata(this.conversation.sid,this.sid);case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}},_callee10,this)})),function(){return c.apply(this,arguments)})},{key:"getMessageRecipients",value:(l=M.default(L.default.mark(function _callee11(){return L.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.messageRecipientsClient.getRecipientsFromMessage(this.conversation.sid,this.sid);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},_callee11,this)})),function(){return l.apply(this,arguments)})}]),Message}(k.ReplayEventEmitter);function _wrapMedia2(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return e?t?new eu(_objectSpread$4(_objectSpread$4({},e),{},{category:t}),this.services):new eu(e,this.services):null}function _assignMedias2(e,t){var n=this;this.state.media=_classPrivateMethodGet(this,em,_wrapMedia2).call(this,t),this.state.medias=e?e.map(function(e){return _classPrivateMethodGet(n,em,_wrapMedia2).call(n,e)}).filter(function(e){return null!==e}):t&&!e?[_classPrivateMethodGet(this,em,_wrapMedia2).call(this,t,"media")].filter(function(e){return null!==e}):null}function ownKeys$3(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,a)}return n}function _objectSpread$3(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};
1t%2?ownKeys$3(Object(n),!0).forEach(function(t){I.default(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys$3(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function _arrayLikeToArray$4(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=Array(t);n<t;n++)a[n]=e[n];return a}I.default(e_,"updated","updated"),__decorate([E.deprecated("getMediaByCategory","getMediaByCategories"),__metadata("design:type",Function),__metadata("design:paramtypes",[Array]),__metadata("design:returntype",Array)],e_.prototype,"getMediaByCategory",null),__decorate([g.validateTypes([g.nonEmptyString,"undefined"]),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",eu)],e_.prototype,"getEmailBody",null),__decorate([g.validateTypes([g.nonEmptyString,"undefined"]),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",eu)],e_.prototype,"getEmailHistory",null),__decorate([g.validateTypesAsync("string"),__metadata("design:type",Function),__metadata("design:paramtypes",[String]),__metadata("design:returntype",Promise)],e_.prototype,"updateBody",null),__decorate([g.validateTypesAsync(Q),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],e_.prototype,"updateAttributes",null),__decorate([E.deprecated("attachTemporaryUrlsFor","getTemporaryContentUrlsForMedia"),__metadata("design:type",Function),__metadata("design:paramtypes",[Array]),__metadata("design:returntype",Promise)],e_.prototype,"attachTemporaryUrlsFor",null),__decorate([g.validateTypesAsync(g.nonEmptyArray("media",eu)),__metadata("design:type",Function),__metadata("design:paramtypes",[Array]),__metadata("design:returntype",R.CancellablePromise)],e_.prototype,"getTemporaryContentUrlsForMedia",null),__decorate([g.validateTypesAsync(g.nonEmptyArray("strings","string")),__metadata("design:type",Function),__metadata("design:paramtypes",[Array]),__metadata("design:returntype",R.CancellablePromise)],e_.prototype,"getTemporaryContentUrlsForMediaSids",null);var eg=H.scope("Messages"),eb=function(e){U.default(Messages,e);var t,n,a,r,i,s,o,u=(t=function(){if("undefined"==typeof Reflect||!Reflect.construct||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}}(),function(){var e,n=j.default(Messages);if(t){var a=j.default(this).constructor;e=Reflect.construct(n,arguments,a)}else e=n.apply(this,arguments);return A.default(this,e)});function Messages(e,t,n){var a;return D.default(this,Messages),(a=u.call(this)).conversation=e,a.configuration=t,a.services=n,a.messagesByIndex=new Map,a.messagesListPromise=null,a}return N.default(Messages,[{key:"subscribe",value:(n=M.default(L.default.mark(function _callee(e){var t,n=this;return L.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(!this.messagesListPromise){a.next=2;break}return a.abrupt("return",this.messagesListPromise);case 2:return this.messagesListPromise="string"==typeof e?this.services.syncClient.list({id:e,mode:"open_existing"}):Promise.resolve(e),a.prev=3,a.next=6,this.messagesListPromise;case 6:return(t=a.sent).on("itemAdded",function(e){eg.debug("".concat(n.conversation.sid," itemAdded: ").concat(e.item.index));var t={self:"".concat(n.conversation._links.messages,"/").concat(e.item.data.sid),conversation:n.conversation._links.self,messages_receipts:"".concat(n.conversation._links.messages,"/").concat(e.item.data.sid,"/Receipts")},a=new e_(e.item.index,e.item.data,n.conversation,t,n.configuration,n.services);if(n.messagesByIndex.has(a.index)){eg.debug("Message arrived, but is already known and ignored",n.conversation.sid,a.index);return}n.messagesByIndex.set(a.index,a),a.on("updated",function(e){return n.emit("messageUpdated",e)}),n.emit("messageAdded",a)}),t.on("itemRemoved",function(e){eg.debug("#{this.conversation.sid} itemRemoved: ".concat(e.index));var t=e.index;if(n.messagesByIndex.has(t)){var a=n.messagesByIndex.get(t);if(!a)return;n.messagesByIndex.delete(a.index),a.removeAllListeners("updated"),n.emit("messageRemoved",a)}}),t.on("itemUpdated",function(e){eg.debug("".concat(n.conversation.sid," itemUpdated: ").concat(e.item.index));var t=n.messagesByIndex.get(e.item.index);t&&t._update(e.item.data)}),a.abrupt("return",t);case 13:throw a.prev=13,a.t0=a.catch(3),this.messagesListPromise=null,"disconnected"!==this.services.syncClient.connectionState&&eg.error("Failed to get messages object for conversation",this.conversation.sid,a.t0),eg.debug("ERROR: Failed to get messages object for conversation",this.conversation.sid,a.t0),a.t0;case 19:case"end":return a.stop()}},_callee,this,[[3,13]])})),function(e){return n.apply(this,arguments)})},{key:"unsubscribe",value:(a=M.default(L.default.mark(function _callee2(){return L.default.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()}},_callee2,this)})),function(){return a.apply(this,arguments)})},{key:"sendV2",value:function(e){var t,n=this;return eg.debug("Sending message V2",e.mediaContent,e.attributes,e.emailOptions),new R.CancellablePromise((t=M.default(L.default.mark(function _callee3(t,a,r){var i,s,o,u,c,l,d,p,f,h,y,m;return L.default.wrap(function(v){for(;;)switch(v.prev=v.next){case 0:s=[],o=[],r(function(){o.forEach(function(e){return e.cancel()})}),u=function(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];
1if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray$4(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray$4(e,t)}}(e))){n&&(e=n);var a=0,F=function(){};return{s:F,n:function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}},e:function(e){throw e},f:F}}throw TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,i=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return i=e.done,e},e:function(e){s=!0,r=e},f:function(){try{i||null==n.return||n.return()}finally{if(s)throw r}}}}(e.mediaContent),v.prev=4,u.s();case 6:if((c=u.n()).done){v.next=25;break}return d=(l=q.default(c.value,2))[0],p=l[1],v.prev=8,eg.debug("Adding media to a message as ".concat(p instanceof FormData?"FormData":"SendMediaOptions"),p),y=p instanceof FormData?n.services.mcsClient.postFormData(p,d):n.services.mcsClient.post(null!==(f=p.contentType)&&void 0!==f?f:"",null!==(h=p.media)&&void 0!==h?h:"",d,p.filename),o.push(y),v.t0=s,v.next=15,y;case 15:v.t1=v.sent,v.t0.push.call(v.t0,v.t1),v.next=23;break;case 19:return v.prev=19,v.t2=v.catch(8),a(v.t2),v.abrupt("return");case 23:v.next=6;break;case 25:v.next=30;break;case 27:v.prev=27,v.t3=v.catch(4),u.e(v.t3);case 30:return v.prev=30,u.f(),v.finish(30);case 33:return m=n.services.commandExecutor.mutateResource("post",n.conversation._links.messages,{body:e.text,subject:null===(i=e.emailOptions)||void 0===i?void 0:i.subject,media_sids:s.map(function(e){return e.sid}),attributes:void 0!==e.attributes?JSON.stringify(e.attributes):void 0,content_sid:e.contentSid,content_variables:void 0!==e.contentVariables?JSON.stringify(e.contentVariables.reduce(function(e,t){return _objectSpread$3(_objectSpread$3({},e),{},I.default({},t.name,t.value))},{})):void 0}),v.prev=34,v.t4=t,v.next=38,m;case 38:v.t5=v.sent,(0,v.t4)(v.t5),v.next=45;break;case 42:v.prev=42,v.t6=v.catch(34),a(v.t6);case 45:case"end":return v.stop()}},_callee3,null,[[4,27,30,33],[8,19],[34,42]])})),function(e,n,a){return t.apply(this,arguments)}))}},{key:"send",value:(r=M.default(L.default.mark(function _callee4(e){var t,n,a=arguments;return L.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return t=a.length>1&&void 0!==a[1]?a[1]:{},n=a.length>2?a[2]:void 0,eg.debug("Sending text message",e,t,n),r.abrupt("return",this.services.commandExecutor.mutateResource("post",this.conversation._links.messages,{body:null!=e?e:"",attributes:void 0!==t?JSON.stringify(t):void 0,subject:null==n?void 0:n.subject}));case 4:case"end":return r.stop()}},_callee4,this)})),function(e){return r.apply(this,arguments)})},{key:"sendMedia",value:(i=M.default(L.default.mark(function _callee5(e){var t,n,a,r,i,s=arguments;return L.default.wrap(function(o){for(;;)switch(o.prev=o.next){case 0:if(a=s.length>1&&void 0!==s[1]?s[1]:{},r=s.length>2?s[2]:void 0,eg.debug("Sending media message",e,a,r),eg.debug("Sending media message as ".concat(e instanceof FormData?"FormData":"SendMediaOptions"),e,a),!(e instanceof FormData)){o.next=10;break}return o.next=7,this.services.mcsClient.postFormData(e);case 7:o.t0=o.sent,o.next=13;break;case 10:return o.next=12,this.services.mcsClient.post(null!==(t=e.contentType)&&void 0!==t?t:"",null!==(n=e.media)&&void 0!==n?n:"","media",e.filename);case 12:o.t0=o.sent;case 13:return i=o.t0,o.next=16,this.services.commandExecutor.mutateResource("post",this.conversation._links.messages,{media_sids:[i.sid],attributes:void 0!==a?JSON.stringify(a):void 0});case 16:return o.abrupt("return",o.sent);case 17:case"end":return o.stop()}},_callee5,this)})),function(e){return i.apply(this,arguments)})},{key:"getMessages",value:(s=M.default(L.default.mark(function _callee6(e,t){var n,a=arguments;return L.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return n=a.length>2&&void 0!==a[2]?a[2]:"backwards",r.abrupt("return",this._getMessages(e,t,n
1));case 2:case"end":return r.stop()}},_callee6,this)})),function(e,t){return s.apply(this,arguments)})},{key:"_wrapPaginator",value:function(e,t,n){var a=this,r="desc"===e,nextPage=function(){return t.nextPage().then(function(t){return a._wrapPaginator(e,t,n)})},previousPage=function(){return t.prevPage().then(function(t){return a._wrapPaginator(e,t,n)})};return n(t.items).then(function(e){return{items:e.sort(function(e,t){return e.index-t.index}),hasPrevPage:r?t.hasNextPage:t.hasPrevPage,hasNextPage:r?t.hasPrevPage:t.hasNextPage,prevPage:r?nextPage:previousPage,nextPage:r?previousPage:nextPage}})}},{key:"_upsertMessage",value:function(e,t){var n=this,a=this.messagesByIndex.get(e);if(a)return a;var r={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")},i=new e_(e,t,this.conversation,r,this.configuration,this.services);return this.messagesByIndex.set(i.index,i),i.on("updated",function(e){return n.emit("messageUpdated",e)}),i}},{key:"_getMessages",value:(o=M.default(L.default.mark(function _callee7(){var e,t,n,a,r,i=this,s=arguments;return L.default.wrap(function(o){for(;;)switch(o.prev=o.next){case 0:return e=s.length>0&&void 0!==s[0]?s[0]:30,t=s.length>1&&void 0!==s[1]?s[1]:"end",n="backwards"===(s.length>2&&void 0!==s[2]?s[2]:"forward")?"desc":"asc",o.next=6,this.messagesListPromise;case 6:return a=o.sent,o.next=9,null==a?void 0:a.getItems({from:"end"!==t?t:void 0,pageSize:e,order:n,limit:e});case 9:return r=o.sent,o.next=12,this._wrapPaginator(n,r,function(e){return Promise.all(e.map(function(e){return i._upsertMessage(e.index,e.data)}))});case 12:return o.abrupt("return",o.sent);case 13:case"end":return o.stop()}},_callee7,this)})),function(){return o.apply(this,arguments)})}]),Messages}(k.ReplayEventEmitter),ek=function(){function UnsentMessage(e){D.default(this,UnsentMessage),I.default(this,"attributes",{}),I.default(this,"mediaContent",[]),I.default(this,"emailOptions",{}),this.messagesEntity=e}return N.default(UnsentMessage,[{key:"send",value:function(){var e,t=this;return new R.CancellablePromise((e=M.default(L.default.mark(function _callee(e,n,a){var r;return L.default.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return r=t.messagesEntity.sendV2(t),a(function(){return r.cancel()}),i.prev=2,i.next=5,r;case 5:e(parseToNumber(i.sent.index)),i.next=12;break;case 9:i.prev=9,i.t0=i.catch(2),n(i.t0);case 12:case"end":return i.stop()}},_callee,null,[[2,9]])})),function(t,n,a){return e.apply(this,arguments)}))}}]),UnsentMessage}(),ew=function(){function MessageBuilder(e,t){D.default(this,MessageBuilder),this.limits=e,this.message=new ek(t),this.emailBodies=new Map,this.emailHistories=new Map}return N.default(MessageBuilder,[{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:"setContentTemplate",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return this.message.contentSid=e,this.message.contentVariables=t,this}},{key:"addMedia",value:function(e){if("undefined"==typeof FormData&&e instanceof FormData)throw Error("Could not add FormData content whilst not in a browser");if(!(e instanceof FormData)&&(!e.contentType||!e.media))throw 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.emailBodiesAllowedContentTypes.includes(n))throw Error("Unsupported email body content type ".concat(n))}),this.emailHistories.forEach(function(t,n){if(!e.limits.emailHistoriesAllowedContentTypes.includes(n))throw Error("Unsupported email history content type ".concat(n))}),this.emailBodies.size>this.limits.emailBodiesAllowedContentTypes.length)throw Error("Too many email bodies attached to the message (".concat(this.emailBodies.size," > ").concat(this.limits.emailBodiesAllowedContentTypes.length,")"));if(this.emailHistories.size>this.limits.emailHistoriesAllowedContentTypes.length)throw Error("Too many email histories attached to the message (".concat(this.emailHistories.size," > ").concat(this.limits.emailHistoriesAllowedContentTypes.length,")"));if(this.message.mediaContent.length>this.limits.mediaAttachmentsCountLimit)throw Error("Too many media attachments in the message (".concat(this.message.mediaContent.length," > ").concat(this.limits.mediaAttachmentsCountLimit,")"));
1return 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:"buildAndSend",value:function(){return this.build().send()}}]),MessageBuilder}();function _arrayLikeToArray$3(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=Array(t);n<t;n++)a[n]=e[n];return a}__decorate([g.validateTypes("string"),__metadata("design:type",Function),__metadata("design:paramtypes",[String]),__metadata("design:returntype",ew)],ew.prototype,"setBody",null),__decorate([g.validateTypes("string"),__metadata("design:type",Function),__metadata("design:paramtypes",[String]),__metadata("design:returntype",ew)],ew.prototype,"setSubject",null),__decorate([g.validateTypes(Q),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",ew)],ew.prototype,"setAttributes",null),__decorate([g.validateTypes("string",[FormData,Z]),__metadata("design:type",Function),__metadata("design:paramtypes",[String,Object]),__metadata("design:returntype",ew)],ew.prototype,"setEmailBody",null),__decorate([g.validateTypes("string",[FormData,Z]),__metadata("design:type",Function),__metadata("design:paramtypes",[String,Object]),__metadata("design:returntype",ew)],ew.prototype,"setEmailHistory",null),__decorate([g.validateTypes("string",[g.array("content variables",ep),"undefined"]),__metadata("design:type",Function),__metadata("design:paramtypes",[String,Array]),__metadata("design:returntype",ew)],ew.prototype,"setContentTemplate",null),__decorate([g.validateTypes([FormData,Z]),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",ew)],ew.prototype,"addMedia",null);var ex={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"},eC=function(e){U.default(Conversation,e);var t,n,a,r,i,s,o,u,c,l,d,p,f,h,y,m,v,_,g,b,k,w,x,C,S,R,E,T,I,B,z=(t=function(){if("undefined"==typeof Reflect||!Reflect.construct||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}}(),function(){var e,n=j.default(Conversation);if(t){var a=j.default(this).constructor;e=Reflect.construct(n,arguments,a)}else e=n.apply(this,arguments);return A.default(this,e)});function Conversation(e,t,n,a,r){D.default(this,Conversation),(o=z.call(this)).sid=t,o._links=n,o._configuration=a,o._services=r,o._entityName=e.channel,o._internalState={uniqueName:e.uniqueName||null,status:"notParticipating",attributes:null!==(i=e.attributes)&&void 0!==i?i:{},createdBy:e.createdBy,dateCreated:parseTime(e.dateCreated),dateUpdated:parseTime(e.dateUpdated),friendlyName:e.friendlyName||null,lastReadMessageIndex:Number.isInteger(e.lastConsumedMessageIndex)?e.lastConsumedMessageIndex:null,bindings:null!==(s=e.bindings)&&void 0!==s?s:{}},e.notificationLevel&&(o._internalState.notificationLevel=e.notificationLevel);var i,s,o,u={participants:o._links.participants};return o._participants=new Map,o._participantsEntity=new eo(O.default(o),o._participants,u,o._services),o._participantsEntity.on(Conversation.participantJoined,function(e){return o.emit(Conversation.participantJoined,e)}),o._participantsEntity.on(Conversation.participantLeft,function(e){return o.emit(Conversation.participantLeft,e)}),o._participantsEntity.on(Conversation.participantUpdated,function(e){return o.emit(Conversation.participantUpdated,e)}),o._messagesEntity=new eb(O.default(o),a,r),o._messagesEntity.on(Conversation.messageAdded,function(e){return o._onMessageAdded(e)}),o._messagesEntity.on(Conversation.messageUpdated,function(e){return o.emit(Conversation.messageUpdated,e)}),o._messagesEntity.on(Conversation.messageRemoved,function(e){return o.emit(Conversation.messageRemoved,e)}),o}return N.default(Conversation,[{key:"uniqueName",get:function(){return this._internalState.uniqueName}},{key:"status",get:function(){return this._internalState.status}},{key:"friendlyName",get:function(){return this._internalState.friendlyName}},{key:"dateUpdated",get:function(){return this._internalState.dateUpdated}},{key:"dateCreated",get:function(){return this._internalState.dateCreated}},{key:"createdBy",get:function(){var e;return null!==(e=this._internalState.createdBy)&&void 0!==e?e:""}},{key:"attributes",get:function(){return this._internalState.attributes}},{key:"lastReadMessageIndex",get:function(){return this._internalState.lastReadMessageIndex}},{key:"lastMessage",get:function(){var e;return null!==(e=this._internalState.lastMessage)&&void 0!==e?e:void 0}},{key:"notificationLevel",get:function(){var e;return null!==(e=this._internalState.notificationLevel)&&void 0!==e?e:"default"}},{key:"bindings",get:function(){return this._internalState.bindings}},{key:"limits",get:function(){return this._configuration.limits}},{key:"state",get:function(){return this._internalState.state}},{key:"_statusSource",get:function(){return this._dataSource}},{key:"add",value:(n=M.default(L.default.mark(function _callee(e,t){return L.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.abrupt("return",this._participantsEntity.add(e,null!=t?t:{}));case 1:case"end":return n.stop()}},_callee,this)})),function(e,t){return n.apply(this,arguments)})},{key:"addNonChatParticipant",value:(a=M.default(L.default.mark(function _callee2(e,t){var n,a,r=arguments;return L.default.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return n=r.length>2&&void 0!==r[2]?r[2]:{},a=r.length>3&&void 0!==r[3]?r[3]:{},i.abrupt("return",this._participantsEntity.addNonChatParticipant(e,t,null!=n?n:{},null!=a?a:{}));case 3:case"end":return i.stop()}},_callee2,this)})),function(e,t){return a.apply(this,arguments)})},{key:"advanceLastReadMessageIndex",value:(r=M.default(L.default.mark(function _callee3(e){var t;return L.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,this._subscribeStreams();case 2:if(!(e<(null!==(t=this.lastReadMessageIndex)&&void 0!==t?t:0))){n.next=6;break}return n.next=5,this._setLastReadMessageIndex(this.lastReadMessageIndex);case 5:case 8:return n.abrupt("return",n.sent);case 6:return n.next=8,this._setLastReadMessageIndex(e);case 9:case"end":return n.stop()}},_callee3,this)})),function(e){return r.apply(this,arguments)})},{key:"delete",value:(i=M.default(L.default.mark(function _callee4(){return L.default.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()}},_callee4,this)})),function(){return i.apply(this,arguments)})},{key:"getAttributes",value:(s=M.default(L.default.mark(function _callee5(){return L.default.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()}},_callee5,this)})),function(){return s.apply(this,arguments)})},{key:"getMessages",value:(o=M.default(L.default.mark(function _callee6(e,t,n){return L.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,this._subscribeStreams();case 2:return a.abrupt("return",this._messagesEntity.getMessages(e,t,n
1));case 3:case"end":return a.stop()}},_callee6,this)})),function(e,t,n){return o.apply(this,arguments)})},{key:"getParticipants",value:(u=M.default(L.default.mark(function _callee7(){return L.default.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()}},_callee7,this)})),function(){return u.apply(this,arguments)})},{key:"getParticipantsCount",value:(c=M.default(L.default.mark(function _callee8(){var e,t,n;return L.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return t=new Y(this._configuration.links.conversations).path(this.sid).build(),a.next=3,this._services.network.get(t);case 3:return n=a.sent,a.abrupt("return",null!==(e=n.body.participants_count)&&void 0!==e?e:0);case 5:case"end":return a.stop()}},_callee8,this)})),function(){return c.apply(this,arguments)})},{key:"getParticipantBySid",value:(l=M.default(L.default.mark(function _callee9(e){return L.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this._participantsEntity.getParticipantBySid(e));case 1:case"end":return t.stop()}},_callee9,this)})),function(e){return l.apply(this,arguments)})},{key:"getParticipantByIdentity",value:(d=M.default(L.default.mark(function _callee10(){var e,t=arguments;return L.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return e=t.length>0&&void 0!==t[0]?t[0]:"",n.abrupt("return",this._participantsEntity.getParticipantByIdentity(null!=e?e:""));case 2:case"end":return n.stop()}},_callee10,this)})),function(){return d.apply(this,arguments)})},{key:"getMessagesCount",value:(p=M.default(L.default.mark(function _callee11(){var e,t,n;return L.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return t=new Y(this._configuration.links.conversations).path(this.sid).build(),a.next=3,this._services.network.get(t);case 3:return n=a.sent,a.abrupt("return",null!==(e=n.body.messages_count)&&void 0!==e?e:0);case 5:case"end":return a.stop()}},_callee11,this)})),function(){return p.apply(this,arguments)})},{key:"getUnreadMessagesCount",value:(f=M.default(L.default.mark(function _callee12(){var e,t,n;return L.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return e=new Y(this._configuration.links.myConversations).path(this.sid).build(),a.next=3,this._services.network.get(e);case 3:if(!((t=a.sent).body.conversation_sid!==this.sid)){a.next=6;break}throw Error("Conversation was not found in the user conversations list");case 6:if("number"!=typeof(n=t.body.unread_messages_count)){a.next=9;break}return a.abrupt("return",n);case 9:return a.abrupt("return",null);case 10:case"end":return a.stop()}},_callee12,this)})),function(){return f.apply(this,arguments)})},{key:"join",value:(h=M.default(L.default.mark(function _callee13(){return L.default.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()}},_callee13,this)})),function(){return h.apply(this,arguments)})},{key:"leave",value:(y=M.default(L.default.mark(function _callee14(){return L.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if("joined"!==this._internalState.status){e.next=3;break}return e.next=3,this._services.commandExecutor.mutateResource("delete","".concat(this._links.participants,"/").concat(encodeURIComponent(this._configuration.userIdentity)));case 3:return e.abrupt("return",this);case 4:case"end":return e.stop()}},_callee14,this)})),function(){return y.apply(this,arguments)})},{key:"removeParticipant",value:(m=M.default(L.default.mark(function _callee15(e){return L.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._participantsEntity.remove("string"==typeof e?e:e.sid);case 2:case"end":return t.stop()}},_callee15,this)})),function(e){return m.apply(this,arguments)})},{key:"sendMessage",value:(v=M.default(L.default.mark(function _callee16(e,t,n){var a,r,i,s;return L.default.wrap(function(o){for(;;)switch(o.prev=o.next){case 0:if(!("string"==typeof e||null===e)){o.next=5;break}return o.next=3,this._messagesEntity.send(e,t,n);case 3:return i=o.sent,o.abrupt("return",null!==(r=parseToNumber(i.index))&&void 0!==r?r:0);
1case 5:return o.next=7,this._messagesEntity.sendMedia(e,t,n);case 7:return s=o.sent,o.abrupt("return",null!==(a=parseToNumber(s.index))&&void 0!==a?a:0);case 9:case"end":return o.stop()}},_callee16,this)})),function(e,t,n){return v.apply(this,arguments)})},{key:"prepareMessage",value:function(){return new ew(this.limits,this._messagesEntity)}},{key:"setAllMessagesRead",value:(_=M.default(L.default.mark(function _callee17(){var e;return L.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._subscribeStreams();case 2:return t.next=4,this.getMessages(1);case 4:if(!((e=t.sent).items.length>0)){t.next=7;break}return t.abrupt("return",this.advanceLastReadMessageIndex(e.items[0].index));case 7:return t.abrupt("return",0);case 8:case"end":return t.stop()}},_callee17,this)})),function(){return _.apply(this,arguments)})},{key:"setAllMessagesUnread",value:(g=M.default(L.default.mark(function _callee18(){return L.default.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()}},_callee18,this)})),function(){return g.apply(this,arguments)})},{key:"setUserNotificationLevel",value:(b=M.default(L.default.mark(function _callee19(e){return L.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._services.commandExecutor.mutateResource("post","".concat(this._configuration.links.myConversations,"/").concat(this.sid),{notification_level:e});case 2:case"end":return t.stop()}},_callee19,this)})),function(e){return b.apply(this,arguments)})},{key:"typing",value:function(){return this._services.typingIndicator.send(this.sid)}},{key:"updateAttributes",value:(k=M.default(L.default.mark(function _callee20(e){return L.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._services.commandExecutor.mutateResource("post",this._links.self,{attributes:void 0!==e?JSON.stringify(e):void 0});case 2:return t.abrupt("return",this);case 3:case"end":return t.stop()}},_callee20,this)})),function(e){return k.apply(this,arguments)})},{key:"updateFriendlyName",value:(w=M.default(L.default.mark(function _callee21(e){return L.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!(this._internalState.friendlyName!==e)){t.next=3;break}return t.next=3,this._services.commandExecutor.mutateResource("post",this._links.self,{friendly_name:e});case 3:return t.abrupt("return",this);case 4:case"end":return t.stop()}},_callee21,this)})),function(e){return w.apply(this,arguments)})},{key:"updateLastReadMessageIndex",value:(x=M.default(L.default.mark(function _callee22(e){return L.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._subscribeStreams();case 2:return t.abrupt("return",this._setLastReadMessageIndex(e));case 3:case"end":return t.stop()}},_callee22,this)})),function(e){return x.apply(this,arguments)})},{key:"updateUniqueName",value:(C=M.default(L.default.mark(function _callee23(e){return L.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!(this._internalState.uniqueName!==e)){t.next=4;break}return e||(e=""),t.next=4,this._services.commandExecutor.mutateResource("post",this._links.self,{unique_name:e});case 4:return t.abrupt("return",this);case 5:case"end":return t.stop()}},_callee23,this)})),function(e){return C.apply(this,arguments)})},{key:"getMessageRecipients",value:(S=M.default(L.default.mark(function _callee24(e){return L.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._services.messageRecipientsClient.getRecipientsFromConversation(this.sid,e);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},_callee24,this)})),function(e){return S.apply(this,arguments)})},{key:"_subscribe",value:(R=M.default(L.default.mark(function _callee25(){var e=this;return L.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this._entityPromise){t.next=2;break}return t.abrupt("return",this._entityPromise);case 2:return this._entityPromise=this._services.syncClient.document({id:this._entityName,mode:"open_existing"}),t.prev=3,t.next=6,this._entityPromise;case 6:return this._entity=t.sent,this._entity.on(P.SyncDocument.updated,function(t){return e._update(t.data)}),this._entity.on(P.SyncDocument.removed,function(){return e.emit(Conversation.removed,e)}),this._update(this._entity.data),t.abrupt("return",this._entity);case 13:throw t.prev=13,t.t0=t.catch(3),this._entity=null,this._entityPromise=null,"disconnected"!=this._services.syncClient.connectionState&&Conversation._logger.error("Failed to get conversation object",t.t0),Conversation._logger.debug("ERROR: Failed to get conversation object",t.t0),t.t0;case 20:case"end":return t.stop()}},_callee25,this,[[3,13]])})),function(){return R.apply(this,arguments)})},{key:"_fetchStreams",value:(E=M.default(L.default.mark(function _callee27(){var e=this;return L.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this._streamsPromise){t.next=2;break}return t.abrupt("return",this._streamsPromise);case 2:return this._streamsPromise=new Promise(function(){var t=M.default(L.default.mark(function _callee26(t,n){var a,r,i;return L.default.wrap(function(s){for(;;)switch(s.prev=s.next){case 0:return s.prev=0,s.next=3,e._subscribe();case 3:s.next=9;break;case 5:return s.prev=5,s.t0=s.catch(0),Conversation._logger.trace("Failed to subscribe to conversation",s.t0),s.abrupt("return",n(s.t0));case 9:Conversation._logger.trace("_streamsAvailable, this.entity.data=",null===(a=e._entity)||void 0===a?void 0:a.data),i=null===(r=e._entity)||void 0===r?void 0:r.data,Promise.all([e._services.syncClient.list({id:i.messages,mode:"open_existing"}).then(function(t){return e._messagesList=t,t}),e._services.syncClient.map({id:i.roster,mode:"open_existing"}).then(function(t){return e._participantsMap=t,t})]).then(function(){return t(!0)}).catch(function(t){Conversation._logger.trace("Failed to fetch conversation streams for conversation",e.sid,t),n(t)});case 14:case"end":return s.stop()}},_callee26,null,[[0,5]])}));return function(e,n){return t.apply(this,arguments)}}()),t.abrupt("return",this._streamsPromise.catch(function(t){throw e._streamsPromise=null,t}));case 4:case"end":return t.stop()}},_callee27,this)})),function(){return E.apply(this,arguments)})},{key:"_subscribeStreams",value:(T=M.default(L.default.mark(function _callee28(){var e,t,n,a,r,i,s;return L.default.wrap(function(o){for(;;)switch(o.prev=o.next){case 0:return o.prev=0,o.next=3,this._fetchStreams();case 3:return Conversation._logger.trace("_subscribeStreams, this.entity.data=",null===(e=this._entity)||void 0===e?void 0:e.data),i=(r=null===(t=this._entity)||void 0===t?void 0:t.data).messages,s=r.roster,o.next=9,Promise.all([this._messagesEntity.subscribe(null!==(n=this._messagesList)&&void 0!==n?n:i),this._participantsEntity.subscribe(null!==(a=this._participantsMap)&&void 0!==a?a:s)]);case 9:o.next=16;break;case 11:throw o.prev=11,o.t0=o.catch(0),"disconnected"!==this._services.syncClient.connectionState&&Conversation._logger.error("Failed to subscribe on conversation objects",this.sid,o.t0),Conversation._logger.debug("ERROR: Failed to subscribe on conversation objects",this.sid,o.t0),o.t0;case 16:case"end":return o.stop()}},_callee28,this,[[0,11]])})),function(){return T.apply(this,arguments)})},{key:"_unsubscribe",value:(I=M.default(L.default.mark(function _callee29(){return L.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this._entity&&(this._entity.close(),this._entity=null,this._entityPromise=null),e.abrupt("return",Promise.all([this._participantsEntity.unsubscribe(),this._messagesEntity.unsubscribe()]));case 2:case"end":return e.stop()}},_callee29,this)})),function(){return I.apply(this,arguments)})},{key:"_setStatus",value:function(e,t){var n=this;if(this._dataSource=t,this._internalState.status!==e){if(this._internalState.status=e,"joined"===e){this._subscribeStreams().catch(function(t){if(Conversation._logger.debug("ERROR while setting conversation status "+e,t),"disconnected"!==n._services.syncClient.connectionState)throw t});return}this._entityPromise&&this._unsubscribe().catch(function(t){if(Conversation._logger.debug("ERROR while setting conversation status "+e,t),"disconnected"!==n._services.syncClient.connectionState)throw t})}}},{key:"_update",value:function(e){Conversation._logger.trace("_update",e),Conversation.preprocessUpdate(e,this.sid);for(var t,n,a,r,i,s=new Set,o=0,u=Object.keys(e);o<u.length;o++){var c=u[o],l=ex[c];if(l)switch(l){case ex.status:if(!e.status||"unknown"===e.status||this._internalState.status===e.status)break;this._internalState.status=e.status,s.add(l);break;case ex.attributes:if(isEqual(this._internalState.attributes,e.attributes))break;this._internalState.attributes=e.attributes,s.add(l);break;
1case ex.lastConsumedMessageIndex:if(void 0===e.lastConsumedMessageIndex||e.lastConsumedMessageIndex===this._internalState.lastReadMessageIndex)break;this._internalState.lastReadMessageIndex=e.lastConsumedMessageIndex,s.add("lastReadMessageIndex");break;case ex.lastMessage:if(this._internalState.lastMessage&&!e.lastMessage){delete this._internalState.lastMessage,s.add(l);break}this._internalState.lastMessage=this._internalState.lastMessage||{},(null===(t=e.lastMessage)||void 0===t?void 0:t.index)!==void 0&&e.lastMessage.index!==this._internalState.lastMessage.index&&(this._internalState.lastMessage.index=e.lastMessage.index,s.add(l)),(null===(n=e.lastMessage)||void 0===n?void 0:n.timestamp)!==void 0&&(null===(a=this._internalState.lastMessage)||void 0===a?void 0:null===(r=a.dateCreated)||void 0===r?void 0:r.getTime())!==e.lastMessage.timestamp.getTime()&&(this._internalState.lastMessage.dateCreated=e.lastMessage.timestamp,s.add(l)),isEqual(this._internalState.lastMessage,{})&&delete this._internalState.lastMessage;break;case ex.state:var d=e.state||void 0;if(void 0!==d&&(d.dateUpdated=new Date(d.dateUpdated)),isEqual(this._internalState.state,d))break;this._internalState.state=d,s.add(l);break;case ex.bindings:if(isEqual(this._internalState.bindings,e.bindings))break;this._internalState.bindings=e.bindings,s.add(l);break;default:var p=e[c]instanceof Date,f=p&&(null===(i=this._internalState[l])||void 0===i?void 0:i.getTime())===e[c].getTime(),h=!p&&this[l]===e[c];if(f||h)break;this._internalState[l]=e[c],s.add(l)}}s.size>0&&this.emit(Conversation.updated,{conversation:this,updateReasons:$.default(s)})}},{key:"_onMessageAdded",value:function(e){var t,n=function(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray$3(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray$3(e,t)}}(e))){n&&(e=n);var a=0,F=function(){};return{s:F,n:function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}},e:function(e){throw e},f:F}}throw TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,i=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return i=e.done,e},e:function(e){s=!0,r=e},f:function(){try{i||null==n.return||n.return()}finally{if(s)throw r}}}}(this._participants.values());try{for(n.s();!(t=n.n()).done;){var a=t.value;if(a.identity===e.author){a._endTyping();break}}}catch(e){n.e(e)}finally{n.f()}this.emit(Conversation.messageAdded,e)}},{key:"_setLastReadMessageIndex",value:(B=M.default(L.default.mark(function _callee30(e){var t;return L.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,this._services.commandExecutor.mutateResource("post","".concat(this._configuration.links.myConversations,"/").concat(this.sid),{last_read_message_index:e});case 2:return t=n.sent,n.abrupt("return",t.unread_messages_count);case 4:case"end":return n.stop()}},_callee30,this)})),function(e){return B.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){Conversation._logger.warn("Retrieved malformed attributes from the server for conversation: "+t),e.attributes={}}try{e.dateCreated&&(e.dateCreated=new Date(e.dateCreated))}catch(n){Conversation._logger.warn("Retrieved malformed dateCreated from the server for conversation: "+t),delete e.dateCreated}try{e.dateUpdated&&(e.dateUpdated=new Date(e.dateUpdated))}catch(n){Conversation._logger.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){Conversation._logger.warn("Retrieved malformed lastMessage.timestamp from the server for conversation: "+t),delete e.lastMessage.timestamp}}}]),Conversation}(k.ReplayEventEmitter);I.default(eC,"participantJoined","participantJoined"),I.default(eC,"participantLeft","participantLeft"),I.default(eC,"participantUpdated","participantUpdated"),I.default(eC,"messageAdded","messageAdded"),I.default(eC,"messageRemoved","messageRemoved"),I.default(eC,"messageUpdated","messageUpdated"),I.default(eC,"typingEnded","typingEnded"),I.default(eC,"typingStarted","typingStarted"),I.default(eC,"updated","updated"),I.default(eC,"removed","removed"),I.default(eC,"_logger",H.scope("Conversation")),__decorate([g.validateTypesAsync(g.nonEmptyString,X),__metadata("design:type",Function),__metadata("design:paramtypes",[String,Object]),__metadata("design:returntype",Promise)],eC.prototype,"add",null),__decorate([g.validateTypesAsync(g.nonEmptyString,g.nonEmptyString,X,X
1),__metadata("design:type",Function),__metadata("design:paramtypes",[String,String,Object,Object]),__metadata("design:returntype",Promise)],eC.prototype,"addNonChatParticipant",null),__decorate([g.validateTypesAsync(g.nonNegativeInteger),__metadata("design:type",Function),__metadata("design:paramtypes",[Number]),__metadata("design:returntype",Promise)],eC.prototype,"advanceLastReadMessageIndex",null),__decorate([g.validateTypesAsync(["undefined",g.nonNegativeInteger],["undefined",g.nonNegativeInteger],["undefined",g.literal("backwards","forward")]),__metadata("design:type",Function),__metadata("design:paramtypes",[Number,Number,String]),__metadata("design:returntype",Promise)],eC.prototype,"getMessages",null),__decorate([g.validateTypesAsync(g.nonEmptyString),__metadata("design:type",Function),__metadata("design:paramtypes",[String]),__metadata("design:returntype",Promise)],eC.prototype,"getParticipantBySid",null),__decorate([g.validateTypesAsync(g.nonEmptyString),__metadata("design:type",Function),__metadata("design:paramtypes",[String]),__metadata("design:returntype",Promise)],eC.prototype,"getParticipantByIdentity",null),__decorate([g.validateTypesAsync([g.nonEmptyString,ei]),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],eC.prototype,"removeParticipant",null),__decorate([g.validateTypesAsync(["string",FormData,g.literal(null),g.objectSchema("media options",{contentType:g.nonEmptyString,media:g.custom(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"]})})],X,["undefined",g.literal(null),g.objectSchema("email attributes",{subject:[g.nonEmptyString,"undefined"]})]),__metadata("design:type",Function),__metadata("design:paramtypes",[Object,Object,Object]),__metadata("design:returntype",Promise)],eC.prototype,"sendMessage",null),__decorate([g.validateTypesAsync(g.literal("default","muted")),__metadata("design:type",Function),__metadata("design:paramtypes",[String]),__metadata("design:returntype",Promise)],eC.prototype,"setUserNotificationLevel",null),__decorate([g.validateTypesAsync(Q),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],eC.prototype,"updateAttributes",null),__decorate([g.validateTypesAsync("string"),__metadata("design:type",Function),__metadata("design:paramtypes",[String]),__metadata("design:returntype",Promise)],eC.prototype,"updateFriendlyName",null),__decorate([g.validateTypesAsync([g.literal(null),g.nonNegativeInteger]),__metadata("design:type",Function),__metadata("design:paramtypes",[Number]),__metadata("design:returntype",Promise)],eC.prototype,"updateLastReadMessageIndex",null),__decorate([g.validateTypesAsync(["string",g.literal(null)]),__metadata("design:type",Function),__metadata("design:paramtypes",[String]),__metadata("design:returntype",Promise)],eC.prototype,"updateUniqueName",null);var eS=function(){function Deferred(){var e=this;D.default(this,Deferred),this._promise=new Promise(function(t,n){e._resolve=t,e._reject=n})}return N.default(Deferred,[{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)}}]),Deferred}();function _arrayLikeToArray$2(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=Array(t);n<t;n++)a[n]=e[n];return a}function ownKeys$2(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,a)}return n}var eP=H.scope("Conversations"),eR=function(e){U.default(Conversations,e);var t,n,a,r,i,s,o,u,c,l,d,p,f=(t=function(){if("undefined"==typeof Reflect||!Reflect.construct||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}}(),function(){var e,n=j.default(Conversations);if(t){var a=j.default(this).constructor;e=Reflect.construct(n,arguments,a)}else e=n.apply(this,arguments);return A.default(this,e)});function Conversations(e,t){var n;return D.default(this,Conversations),n=f.call(this),I.default(O.default(n),"conversations",new Map),I.default(O.default(n),"myConversationsRead",new eS),I.default(O.default(n),"tombstones",new Set),I.default(O.default(n),"myConversationsFetched",!1),n.configuration=e,n.services=t,n}return N.default(Conversations,[{key:"addConversation",value:(n=M.default(L.default.mark(function _callee(e){var t,n,a,r,i,s,o,u,c,l;return L.default.wrap(function(d){for(;;)switch(d.prev=d.next){case 0:return r=void 0!==(null==e?void 0:e.attributes)?e.attributes:{},d.next=3,this.services.commandExecutor.mutateResource("post",this.configuration.links.conversations,{friendly_name:e.friendlyName,unique_name:e.uniqueName,access:e.access,attributes:void 0!==r?JSON.stringify(r):void 0});case 3:if(s=null!==(t=(i=d.sent).sid)&&void 0!==t?t:null,o=null!==(n=null===(a=i.sync_objects)||void 0===a?void 0:a.conversation)&&void 0!==n?n:null,u=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};
1t%2?ownKeys$2(Object(n),!0).forEach(function(t){I.default(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys$2(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}({self:i.url},i.links),!(c=this.conversations.get(s))){d.next=12;break}return d.next=11,c._subscribe();case 11:return d.abrupt("return",c);case 12:return l=new eC({channel:o,entityName:"",uniqueName:"",attributes:null,createdBy:"",friendlyName:"",lastConsumedMessageIndex:0,dateCreated:null,dateUpdated:null},s,u,this.configuration,this.services),this.conversations.set(l.sid,l),this._registerForEvents(l),d.next=17,l._subscribe();case 17:return this.emit("conversationAdded",l),d.abrupt("return",l);case 19:case"end":return d.stop()}},_callee,this)})),function(e){return n.apply(this,arguments)})},{key:"fetchConversations",value:(a=M.default(L.default.mark(function _callee2(){var e,t,n,a,r,i,s,o=this;return L.default.wrap(function(u){for(;;)switch(u.prev=u.next){case 0:return u.prev=0,u.next=3,this._getMap();case 3:return(e=u.sent).on(P.SyncMap.itemAdded,function(e){eP.debug("itemAdded: ".concat(e.item.key)),o._upsertConversation("sync",e.item.key,e.item.data)}),e.on(P.SyncMap.itemRemoved,function(e){eP.debug("itemRemoved: ".concat(e.key));var t=e.key;o.myConversationsFetched||o.tombstones.add(t);var n=o.conversations.get(t);n&&("joined"===n.status&&(n._setStatus("notParticipating","sync"),o.emit("conversationLeft",n)),o.conversations.delete(t),o.emit("conversationRemoved",n),n.emit("removed",n))}),e.on(P.SyncMap.itemUpdated,function(e){eP.debug("itemUpdated: ".concat(e.item.key)),o._upsertConversation("sync",e.item.key,e.item.data)}),u.next=9,this._fetchMyConversations();case 9:t=u.sent,n=[],a=function(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray$2(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray$2(e,t)}}(e))){n&&(e=n);var a=0,F=function(){};return{s:F,n:function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}},e:function(e){throw e},f:F}}throw TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,i=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return i=e.done,e},e:function(e){s=!0,r=e},f:function(){try{i||null==n.return||n.return()}finally{if(s)throw r}}}}(t);try{for(a.s();!(r=a.n()).done;)i=r.value,n.push(this._upsertConversation("rest",i.channel_sid,i))}catch(e){a.e(e)}finally{a.f()}return this.myConversationsRead.set(!0),u.next=16,Promise.all(n);case 16:return this.myConversationsFetched=!0,this.tombstones.clear(),eP.debug("The conversations list has been successfully fetched"),u.abrupt("return",this);case 22:throw u.prev=22,u.t0=u.catch(0),s="Failed to fetch the conversations list","disconnected"!==this.services.syncClient.connectionState&&eP.error(s,u.t0),eP.debug("ERROR: ".concat(s),u.t0),u.t0;case 28:case"end":return u.stop()}},_callee2,this,[[0,22]])})),function(){return a.apply(this,arguments)})},{key:"getConversations",value:(r=M.default(L.default.mark(function _callee3(){var e,t,n=this;return L.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,this._getMap();case 2:return e=a.sent,a.next=5,e.getItems();case 5:return t=a.sent,a.abrupt("return",this._wrapPaginator(t,function(e){return Promise.all(e.map(function(e){return n._upsertConversation("sync",e.key,e.data)}))}));case 7:case"end":return a.stop()}},_callee3,this)})),function(){return r.apply(this,arguments)})},{key:"getConversation",value:(i=M.default(L.default.mark(function _callee4(e){var t,n,a=this;return L.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this._getMap();case 2:return t=r.sent,r.next=5,t.getItems({key:e});case 5:return n=r.sent.items.map(function(e){return a._upsertConversation("sync",e.key,e.data)}),r.abrupt("return",n.length>0?n[0]:null);case 8:case"end":return r.stop()}},_callee4,this)})),function(e){return i.apply(this,arguments)})},{key:"getConversationByUniqueName",value:(s=M.default(L.default.mark(function _callee5(e){var t,n,a,r;return L.default.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return t=new Y(this.configuration.links.myConversations).path(e).build(),i.next=3,this.services.network.get(t);case 3:return a=(n=i.sent.body).conversation_sid,r={entityName:null,lastConsumedMessageIndex:n.last_read_message_index,status:(null==n?void 0:n.status)||"unknown",friendlyName:n.friendly_name,dateUpdated:n.date_updated,dateCreated:n.date_created,uniqueName:n.unique_name,createdBy:n.created_by,attributes:n.attributes,channel:n.sync_objects.conversation,roster:n.sync_objects.participants,messages:n.sync_objects.messages,notificationLevel:null==n?void 0:n.notification_level,sid:a},i.abrupt("return",a?this._upsertConversation("sync",a,r):null);case 8:case"end":return i.stop()}},_callee5,this)})),function(e){return s.apply(this,arguments)})},{key:"peekConversation",value:(o=M.default(L.default.mark(function _callee6(e){var t,n,a;return L.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return t=new Y(this.configuration.links.conversations).path(e).build(),r.next=3,this.services.network.get(t);case 3:return a={entityName:null,status:(null==(n=r.sent.body)?void 0:n.status)||"unknown",friendlyName:n.friendly_name,dateUpdated:n.date_updated,dateCreated:n.date_created,uniqueName:n.unique_name,createdBy:n.created_by,attributes:n.attributes,channel:n.sync_objects.conversation||"".concat(e,".channel"),roster:n.sync_objects.participants,messages:n.sync_objects.messages,notificationLevel:null==n?void 0:n.notification_level,sid:e},r.abrupt("return",this._upsertConversation("sync",e,a));case 7:case"end":return r.stop()}},_callee6,this)})),function(e){return o.apply(this,arguments)})},{key:"_getMap",value:(u=M.default(L.default.mark(function _callee7(){return L.default.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()}},_callee7,this)})),function(){return u.apply(this,arguments)})},{key:"_wrapPaginator",value:(c=M.default(L.default.mark(function _callee8(e,t){var n,a=this;return L.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,t(e.items);case 2:return n=r.sent,r.abrupt("return",{items:n.filter(function(e){return null!==e}),hasNextPage:e.hasNextPage,hasPrevPage:e.hasPrevPage,nextPage:function(){return e.nextPage().then(function(e){return a._wrapPaginator(e,t)})},prevPage:function(){return e.prevPage().then(function(e){return a._wrapPaginator(e,t)})}});case 4:case"end":return r.stop()}},_callee8)})),function(e,t){return c.apply(this,arguments)})},{key:"_updateConversation",value:(l=M.default(L.default.mark(function _callee9(e,t,n){var a,r,i;return L.default.wrap(function(s){for(;;)switch(s.prev=s.next){case 0:if(a=void 0!==t._statusSource&&e!==t._statusSource,r="rest"!==e||"sync"===t._statusSource,!(a&&r&&"sync"!==e)){s.next=5;break}return eP.trace("upsertConversation: conversation is known from sync and came from REST, ignoring",{sid:t.sid,data:n.status,conversation:t.status}),s.abrupt("return");case 5:if(!("joined"===n.status&&"joined"!==t.status)){s.next=15;break}return t._setStatus("joined",e),i={},void 0!==n.notificationLevel&&(i.notificationLevel=n.notificationLevel),void 0!==n.lastConsumedMessageIndex&&(i.lastConsumedMessageIndex=n.lastConsumedMessageIndex),isEqual(i,{})||t._update(i),s.next=13,t._subscribe();
1case 13:return this.emit("conversationJoined",t),s.abrupt("return");case 15:if(!("notParticipating"===n.status&&"joined"===t.status)){s.next=22;break}return t._setStatus("notParticipating",e),t._update(n),s.next=20,t._subscribe();case 20:return this.emit("conversationLeft",t),s.abrupt("return");case 22:if("notParticipating"!==n.status){s.next=26;break}return s.next=25,t._subscribe();case 25:return s.abrupt("return");case 26:t._update(n);case 27:case"end":return s.stop()}},_callee9,this)})),function(e,t,n){return l.apply(this,arguments)})},{key:"_upsertConversation",value:(d=M.default(L.default.mark(function _callee10(e,t,n){var a,r,i,s;return L.default.wrap(function(o){for(;;)switch(o.prev=o.next){case 0:if(eP.trace("upsertConversation called for ".concat(t),n),!(a=this.conversations.get(t))){o.next=9;break}return eP.trace("upsertConversation: the conversation ".concat(a.sid," is known;")+"its status is known from the source ".concat(a._statusSource," ")+"and the update came from the source ".concat(e),a),o.next=6,this._updateConversation(e,a,n);case 6:return o.next=8,a._subscribe();case 8:return o.abrupt("return",a);case 9:if(!("rest"===e&&this.tombstones.has(t))){o.next=12;break}return eP.trace("upsertChannel: the conversation is deleted but reappeared again from REST, ignoring",t),o.abrupt("return",null);case 12:return eP.trace("upsertConversation: creating a local conversation object with sid "+t,n),i={self:r="".concat(this.configuration.links.conversations,"/").concat(t),messages:"".concat(r,"/Messages"),participants:"".concat(r,"/Participants")},s=new eC(n,t,i,this.configuration,this.services),this.conversations.set(t,s),o.prev=17,o.next=20,s._subscribe();case 20:if("joined"!==n.status){o.next=23;break}return o.next=23,s._fetchStreams();case 23:o.next=32;break;case 25:if(o.prev=25,o.t0=o.catch(17),!("SyncError"!==o.t0.name)){o.next=29;break}throw o.t0;case 29:return eP.trace("upsertChannel: the conversation is missing some Sync entity(ies), ignoring",t,o.t0),this.conversations.delete(t),o.abrupt("return",null);case 32:return this._registerForEvents(s),this.emit("conversationAdded",s),"joined"===n.status&&(s._setStatus("joined",e),this.emit("conversationJoined",s)),o.abrupt("return",s);case 36:case"end":return o.stop()}},_callee10,this,[[17,25]])})),function(e,t,n){return d.apply(this,arguments)})},{key:"_fetchMyConversations",value:(p=M.default(L.default.mark(function _callee11(){var e,t,n,a,r,i;return L.default.wrap(function(s){for(;;)switch(s.prev=s.next){case 0:e=[],t=null;case 2:return a=new Y(this.configuration.links.myConversations),t&&a.arg("PageToken",t),s.next=6,this.services.network.get(a.build());case 6:i=null===(n=(r=s.sent).body)||void 0===n?void 0:n.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:e.sync_objects.participants||"".concat(e.conversation_sid,".roster"),lastConsumedMessageIndex:e.last_read_message_index,notificationLevel:e.notification_level}}),t=r.body.meta.next_token,e=[].concat($.default(e),$.default(i));case 10:if(t){s.next=2;break}case 11:return s.abrupt("return",e);case 12:case"end":return s.stop()}},_callee11,this)})),function(){return p.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)})}}]),Conversations}(k.ReplayEventEmitter),eE=function(e){U.default(Users,e);var t,n,a,r,i=(t=function(){if("undefined"==typeof Reflect||!Reflect.construct||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}}(),function(){var e,n=j.default(Users);if(t){var a=j.default(this).constructor;e=Reflect.construct(n,arguments,a)}else e=n.apply(this,arguments);return A.default(this,e)});function Users(e,t,n){var a;return D.default(this,Users),(a=i.call(this)).configuration=t,a.services=n,a.fifoStack=[],a.myself=e,a.myself.on("updated",function(e){return a.emit("userUpdated",e)}),a.myself.on("userSubscribed",function(){return a.emit("userSubscribed",a.myself)}
1),a.myself.on("userUnsubscribed",function(){a.emit("userUnsubscribed",a.myself),a.myself._ensureFetched()}),a.subscribedUsers=new Map,a}return N.default(Users,[{key:"handleUnsubscribeUser",value:function(e){this.subscribedUsers.has(e.identity)&&this.subscribedUsers.delete(e.identity);var t=0;this.fifoStack.find(function(n,a){return n==e.identity&&(t=a,!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,a=this.fifoStack.shift();null===(t=this.subscribedUsers)||void 0===t||null===(n=t.get(a))||void 0===n||n.unsubscribe()}this.fifoStack.push(e.identity),this.subscribedUsers.set(e.identity,e),this.emit("userSubscribed",e)}}},{key:"getUser",value:(n=M.default(L.default.mark(function _callee(e,t){var n,a,r,i=this;return L.default.wrap(function(s){for(;;)switch(s.prev=s.next){case 0:return s.next=2,this.myself._ensureFetched();case 2:if(e!=this.myself.identity){s.next=4;break}return s.abrupt("return",this.myself);case 4:if(!(n=this.subscribedUsers.get(e))){s.next=7;break}return s.abrupt("return",n);case 7:if(!(null!==(r=t)&&void 0!==r)){s.next=11;break}s.next=14;break;case 11:return s.next=13,this.getSyncUniqueName(e);case 13:t=s.sent;case 14:return(a=new et(e,t,this.configuration,this.services)).on("updated",function(e){return i.emit("userUpdated",e)}),a.on("userSubscribed",function(){return i.handleSubscribeUser(a)}),a.on("userUnsubscribed",function(){return i.handleUnsubscribeUser(a)}),s.next=20,a._ensureFetched();case 20:return s.abrupt("return",a);case 21:case"end":return s.stop()}},_callee,this)})),function(e,t){return n.apply(this,arguments)})},{key:"getSubscribedUsers",value:(a=M.default(L.default.mark(function _callee2(){var e;return L.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.myself._ensureFetched();case 2:return e=[this.myself],this.subscribedUsers.forEach(function(t){return e.push(t)}),t.abrupt("return",e);case 5:case"end":return t.stop()}},_callee2,this)})),function(){return a.apply(this,arguments)})},{key:"getSyncUniqueName",value:(r=M.default(L.default.mark(function _callee3(e){var t,n,a,r;return L.default.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return a=new Y(this.configuration.links.users).path(e).build(),i.next=3,this.services.network.get(a);case 3:return r=i.sent,i.abrupt("return",null!==(t=null===(n=r.body)||void 0===n?void 0:n.sync_objects.user_info_map)&&void 0!==t?t:"");case 5:case"end":return i.stop()}},_callee3,this)})),function(e){return r.apply(this,arguments)})}]),Users}(k.ReplayEventEmitter),eT=H.scope("TypingIndicator"),eM=function(){var e;function TypingIndicator(e,t,n){D.default(this,TypingIndicator),this.configuration=t,this.services=n,this.getConversation=e,this.serviceTypingTimeout=null,this.sentUpdates=new Map}return N.default(TypingIndicator,[{key:"typingTimeout",get:function(){return this.configuration.typingIndicatorTimeoutOverride||this.serviceTypingTimeout||this.configuration.typingIndicatorTimeoutDefault}},{key:"initialize",value:function(){var e,t=this;this.services.notificationClient.on("message",(e=M.default(L.default.mark(function _callee(e,n){return L.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(e!==ea.TYPING_INDICATOR){a.next=3;break}return a.next=3,t._handleRemoteTyping(n);case 3:case"end":return a.stop()}},_callee)})),function(t,n){return e.apply(this,arguments)}))}},{key:"_handleRemoteTyping",value:(e=M.default(L.default.mark(function _callee2(e){var t=this;return L.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:eT.trace("Got new typing indicator ",e),this.getConversation(e.channel_sid).then(function(n){n&&n._participants.forEac
1h(function(n){if(n.identity===e.identity||"apple"===n.type){var a=t.configuration.typingIndicatorTimeoutOverride?t.configuration.typingIndicatorTimeoutOverride+1e3:1e3*e.typing_timeout;n._startTyping(a)}})}).catch(function(e){throw eT.error(e),e});case 2:case"end":return n.stop()}},_callee2,this)})),function(t){return e.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;eT.trace("Sending typing indicator");var n=this.configuration.links.typing,a="ChannelSid=".concat(e);return this.services.twilsockClient.post(n,{"Content-Type":"application/x-www-form-urlencoded"},a,this.configuration.productId).then(function(e){e.body.hasOwnProperty("typing_timeout")&&(t.serviceTypingTimeout=1e3*e.body.typing_timeout)}).catch(function(e){throw eT.error("Failed to send typing indicator:",e),e})}}]),TypingIndicator}(),eO=N.default(function PushNotification(e){D.default(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||{}}),eU="3.0.1";function ownKeys$1(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,a)}return n}var trimSlashes=function(e){return e.replace(/(^\/+|\/+$)/g,"")},eA=function(e){U.default(ChannelMetadataNotFoundError,e);var t,n=(t=function(){if("undefined"==typeof Reflect||!Reflect.construct||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}}(),function(){var e,n=j.default(ChannelMetadataNotFoundError);if(t){var a=j.default(this).constructor;e=Reflect.construct(n,arguments,a)}else e=n.apply(this,arguments);return A.default(this,e)});function ChannelMetadataNotFoundError(e){return D.default(this,ChannelMetadataNotFoundError),n.call(this,e)}return N.default(ChannelMetadataNotFoundError)}(J.default(Error)),ej=function(){var e,t,n;function CommandExecutor(e,t,n){D.default(this,CommandExecutor),this._serviceUrl=e,this._services=t,this._productId=n}return N.default(CommandExecutor,[{key:"_preProcessUrl",value:function(e){var t=trimSlashes(e);return/^https?:\/\//.test(e)?t:"".concat(trimSlashes(this._serviceUrl),"/").concat(t)}},{key:"_makeRequest",value:(e=M.default(L.default.mark(function _callee(e,t,n,a){var r,i,s,o;return L.default.wrap(function(u){for(;;)switch(u.prev=u.next){case 0:r=this._preProcessUrl(t),i=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys$1(Object(n),!0).forEach(function(t){I.default(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys$1(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}({"Content-Type":"application/json; charset=utf-8"},a||{}),u.t0=e,u.next="get"===u.t0?5:"post"===u.t0?11:"delete"===u.t0?15:19;break;case 5:return o=r,n&&(o+="?"+Object.entries(n).map(function(e){return e.map(encodeURIComponent).join("=")}).join("&")),u.next=9,this._services.transport.get(o,i,this._productId);case 9:case 13:case 17:return s=u.sent,u.abrupt("break",19);case 11:return u.next=13,this._services.transport.post(r,i,JSON.stringify(n),this._productId);case 15:return u.next=17,this._services.transport.delete(r,i,{},this._productId);case 19:if(!(s.status.code<200||s.status.code>=300)){u.next=21;break}throw Error("Request responded with a non-success code ".concat(s.status.code));case 21:return u.abrupt("return",s);case 22:case"end":return u.stop()}},_callee,this)})),function(t,n,a,r){return e.apply(this,arguments)})},{key:"fetchResource",value:(t=M.default(L.default.mark(function _callee3(e,t){var n,a,r=this;return L.default.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return n=new x.AsyncRetrier({min:50,max:1600,maxAttemptsCount:6}),i.prev=2,i.next=5,n.run(M.default(L.default.mark(function _callee2(){var n,a,i;return L.default.wrap(function(s){for(;;)switch(s.prev=s.next){case 0:return s.prev=0,s.next=3,r._makeRequest
1("get",e,t);case 3:return n=s.sent,s.abrupt("return",{type:"success",data:n.body});case 7:if(s.prev=7,s.t0=s.catch(0),!((null===s.t0||void 0===s.t0?void 0:null===(a=s.t0.body)||void 0===a?void 0:a.status)===404&&(null===s.t0||void 0===s.t0?void 0:null===(i=s.t0.body)||void 0===i?void 0:i.code)===50530)){s.next=11;break}return s.abrupt("return",{type:"noMetadata"});case 11:throw s.t0;case 12:case"end":return s.stop()}},_callee2,null,[[0,7]])})));case 5:a=i.sent,i.next=11;break;case 8:throw i.prev=8,i.t0=i.catch(2),Error('Fetch resource from "'.concat(e,'" failed.'));case 11:if("noMetadata"!==a.type){i.next=13;break}throw new eA("No metadata found.");case 13:return i.abrupt("return",a.data);case 14:case"end":return i.stop()}},_callee3,null,[[2,8]])})),function(e,n){return t.apply(this,arguments)})},{key:"mutateResource",value:(n=M.default(L.default.mark(function _callee4(e,t,n){var a;return L.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this._makeRequest(e,t,n,{"X-Twilio-Mutation-Id":crypto.randomUUID()});case 2:if(202!==(a=r.sent).status.code){r.next=7;break}return r.next=6,this.fetchResource(a.body.resource_url);case 6:return r.abrupt("return",r.sent);case 7:return r.abrupt("return",a.body);case 8:case"end":return r.stop()}},_callee4,this)})),function(e,t,a){return n.apply(this,arguments)})}]),CommandExecutor}(),eI=function(){var e,t;function ContentClient(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:5e3;D.default(this,ContentClient),I.default(this,"_cachedTemplates",null),this._services=e,this._pageSize=t,this._cacheTtlMs=n}return N.default(ContentClient,[{key:"getContentTemplates",value:(e=M.default(L.default.mark(function _callee(){var e,t,n,a,r,i,s,o=this;return L.default.wrap(function(u){for(;;)switch(u.prev=u.next){case 0:if(!(null!==this._cachedTemplates)){u.next=2;break}return u.abrupt("return",this._cachedTemplates);case 2:return u.next=4,this._fetchContentTemplates();case 4:e=u.sent,n=(t=q.default(e,2))[0],a=t[1],r=n;case 9:if(!(null!==a)){u.next=19;break}return u.next=12,this._fetchContentTemplates(a);case 12:i=u.sent,n=(s=q.default(i,2))[0],a=s[1],r=[].concat($.default(r),$.default(n)),u.next=9;break;case 19:return this._cachedTemplates=Object.freeze(r),setTimeout(function(){o._cachedTemplates=null},this._cacheTtlMs),u.abrupt("return",r);case 22:case"end":return u.stop()}},_callee,this)})),function(){return e.apply(this,arguments)})},{key:"_fetchContentTemplates",value:(t=M.default(L.default.mark(function _callee2(e){var t,n;return L.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return(t=new Y("Client/v2/ContentTemplates")).arg("PageSize",this._pageSize),void 0!==e&&t.arg("PageToken",e),a.next=6,this._services.commandExecutor.fetchResource(t.build());case 6:return n=a.sent,a.abrupt("return",[n.templates.map(function(e){return new ef(e)}),n.meta.next_token]);case 8:case"end":return a.stop()}},_callee2,this)})),function(e){return t.apply(this,arguments)})}]),ContentClient}();function _createForOfIteratorHelper$1(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray$1(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray$1(e,t)}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var a=0,F=function(){};return{s:F,n:function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}},e:function(e){throw e},f:F}}throw TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,i=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return i=e.done,e},e:function(e){s=!0,r=e},f:function(){try{i||null==n.return||n.return()}finally{if(s)throw r}}}}function _arrayLikeToArray$1(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=Array(t);n<t;n++)a[n]=e[n];return a}var eN=function(e){function QuickLRU(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(D.default(this,QuickLRU),!(e.maxSize&&e.maxSize>0))throw TypeError("`maxSize` must be a number greater than 0");this.maxSize=e.maxSize,this.onEviction=e.onEviction,this.cache=new Map,this.oldCache=new Map,this._size=0}return N.default(QuickLRU,[{key:"_set",value:function(e,t){if(this.cache.set(e,t),this._size++,this._size>=this.maxSize){if(this._size=0,"function"==typeof this.onEviction){var n,a=_createForOfIteratorHelper$1(this.oldCache.entries());try{for(a.s();!(n=a.n()).done;){var r=q.default(n.value,2),i=r[0],s=r[1];this.onEviction(i,s)}}catch(e){a.e(e)}finally{a.f()}}this.oldCache=this.cache,this.cache=new Map}}},{key:"get",value:function(e){if(this.cache.has(e))return this.cache.get(e);if(this.oldCache.has(e)){var t=this.oldCache.get(e);return this.oldCache.delete(e),this._set(e,t),t}}},{key:"set",value:function(e,t){return this.cache.has(e)?this.cache.set(e,t):this._set(e,t),this}},{key:"has",value:function(e){return this.cache.has(e)||this.oldCache.has(e)}},{key:"peek",value:function(e){return this.cache.has(e)?this.cache.get(e):this.oldCache.has(e)?this.oldCache.get(e):void 0}},{key:"delete",value:function(e){var t=this.cache.delete(e);return t&&this._size--,this.oldCache.delete(e)||t}},{key:"clear",value:function(){this.cache.clear(),this.oldCache.clear(),this._size=0}},{key:"keys",value:L.default.mark(function keys(){var e,t,n;return L.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:e=_createForOfIteratorHelper$1(this),a.prev=1,e.s();case 3:if((t=e.n()).done){a.next=9;break}return n=q.default(t.value,1)[0],a.next=7,n;case 7:a.next=3;break;case 9:a.next=14;break;case 11:a.prev=11,a.t0=a.catch(1),e.e(a.t0);case 14:return a.prev=14,e.f(),a.finish(14);case 17:case"end":return a.stop()}},keys,this,[[1,11,14,17]])})},{key:"values",value:L.default.mark(function values(){var e,t,n;return L.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:e=_createForOfIteratorHelper$1(this),a.prev=1,e.s();case 3:if((t=e.n()).done){a.next=9;break}return n=q.default(t.value,2)[1],a.next=7,n;case 7:a.next=3;break;case 9:a.next=14;break;case 11:a.prev=11,a.t0=a.catch(1),e.e(a.t0);case 14:return a.prev=14,e.f(),a.finish(14);case 17:case"end":return a.stop()}},values,this,[[1,11,14,17]])})},{key:e,value:L.default.mark(function value(){var e,t,n,a,r,i,s;return L.default.wrap(function(o){for(;;)switch(o.prev=o.next){case 0:e=_createForOfIteratorHelper$1(this.cache),o.prev=1,e.s();case 3:if((t=e.n()).done){o.next=9;break}return n=t.value,o.next=7,n;case 7:o.next=3;break;case 9:o.next=14;break;case 11:o.prev=11,o.t0=o.catch(1),e.e(o.t0);case 14:return o.prev=14,e.f(),o.finish(14);case 17:a=_createForOfIteratorHelper$1(this.oldCache),o.prev=18,a.s();case 20:if((r=a.n()).done){o.next=28;break}if(i=r.value,s=q.default(i,1)[0],this.cache.has(s)){o.next=26;break}return o.next=26,i;case 26:o.next=20;break;case 28:o.next=33;break;case 30:o.prev=30,o.t1=o.catch(18),a.e(o.t1);case 33:return o.prev=33,a.f(),o.finish(33);case 36:case"end":return o.stop()}},value,this,[[1,11,14,17],[18,30,33,36]])})},{key:"size",get:function(){var e,t=0,n=_createForOfIteratorHelper$1(this.oldCache.keys());try{for(n.s();!(e=n.n()).done;){var a=e.value;!this.cache.has(a)&&t++}}catch(e){n.e(e)}finally{n.f()}return Math.min(this._size+t,this.maxSize)}}]),QuickLRU}(Symbol.iterator),eF=N.default(function ChannelMetadata(e,t){D.default(this,ChannelMetadata),this.type=e,this.data=t,Object.freeze(t)}),eD=function(){var e;function ChannelMetadataClient(e,t){D.default(this,ChannelMetadataClient),this._services=e,this._configuration=t,this._cache=new eN({maxSize:t.channelMetadataCacheCapacity})}return N.default(ChannelMetadataClient,[{key:"getChannelMetadata",value:(e=M.default(L.default.mark(function _callee(e,t){var n,a,r,i,s;return L.default.wrap(function(o){for(;;)switch(o.prev=o.next){case 0:if(n="".concat(e,",").concat(t),!(a=this._cache.get(n))){o.next=4;break}return o.abrupt("return",a.item);case 4:return r="".concat(this._configuration.links.conversations,"/").concat(e,"/Messages/").concat(t,"/ChannelMetadata"),o.prev=5,o.next=8,this._services.commandExecutor.fetchResource(r);case 8:i=o.sent,o.next=17;break;case 11:if(o.prev=11,o.t0=o.catch(5),!(o.t0 instanceof eA)){o.next=16;break}return this._cache.set(n,{item:null}),o.abrupt("return",null);case 16:throw Error(o.t0);case 17:return s=new eF(i.type,i.data),this._cache.set(n,{item:s}),o.abrupt("return",s);case 20:case"end":return o.stop()}},_callee,this,[[5,11]])})),function(t,n){return e.apply(this,arguments)})}]),ChannelMetadataClient}();function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=Array(t);n<t;n++)a[n]=e[n];return a}var eL=N.default(function EmailRecipientDescriptor(e){D.default(this,EmailRecipientDescriptor),I.default(this,"type","email"),this.messageSid=e.message_sid,this.level=e.level,this.name=e.name,this.address=e.address}),eB=N.default(function UnknownRecipientDescriptor(e){D.default(this,UnknownRecipientDescriptor),this.type=e.type,this.messageSid=e.message_sid,this.rawData=JSON.stringify(e)}),ez=function(){var e,t;function MessageRecipientsClient(e,t){D.default(this,MessageRecipientsClient),this._services=e,this._configuration=t,this._cache=new eN({maxSize:t.messageRecipientsCacheCapacity})}return N.default(MessageRecipientsClient,[{key:"getRecipientsFromMessage",value:(e=M.default(L.default.mark(function _callee(e,t){var n,a,r,i,s=this;return L.default.wrap(function(o){for(;;)switch(o.prev=o.next){case 0:if(n="".concat(e,",").concat(t),!(a=this._cache.get(n))){o.next=4;break}return o.abrupt("return",a.item);case 4:return r=new Y(this._configuration.links.conversations).path(e).path("MessageRecipients").arg("MessageSid",t).build(),o.next=7,this._services.commandExecutor.fetchResource(r);case 7:return(i=o.sent.message_recipients.map(function(e){return s._wrapResponse(e)})).length>0&&this._cache.set(n,{item:i}),o.abrupt("return",i);case 11:case"end":return o.stop()}},_callee,this)})),function(t,n){return e.apply(this,arguments)})},{key:"getRecipientsFromConversation",value:(t=M.default(L.default.mark(function _callee2(e,t){var n,a,r,i,s,o,u,c,l,d,p,f,h=this;return L.default.wrap(function(y){for(;;)switch(y.prev=y.next){case 0:return n=new Y(this._configuration.links.conversations).path(e).path("MessageRecipients").arg("PageToken",null!==(p=null==t?void 0:t.pageToken)&&void 0!==p?p:void 0).arg("PageSize",null!==(f=null==t?void 0:t.pageSize)&&void 0!==f?f:void 0).build(),y.next=3,this._services.commandExecutor.fetchResource(n);case 3:i=function(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];
1if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(e,t)}}(e))){n&&(e=n);var a=0,F=function(){};return{s:F,n:function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}},e:function(e){throw e},f:F}}throw TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,i=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return i=e.done,e},e:function(e){s=!0,r=e},f:function(){try{i||null==n.return||n.return()}finally{if(s)throw r}}}}(r=(a=y.sent).message_recipients.map(function(e){return h._wrapResponse(e)}));try{for(i.s();!(s=i.n()).done;)c=s.value,l="".concat(e,",").concat(c.messageSid),d=null!==(o=null===(u=this._cache.get(l))||void 0===u?void 0:u.item)&&void 0!==o?o:[],this._cache.set(l,{item:[].concat($.default(d),[c])})}catch(e){i.e(e)}finally{i.f()}return y.abrupt("return",new el(r,function(t,n){return h.getRecipientsFromConversation(e,{pageToken:t,pageSize:n})},a.meta.previous_token,a.meta.next_token));case 8:case"end":return y.stop()}},_callee2,this)})),function(e,n){return t.apply(this,arguments)})},{key:"_wrapResponse",value:function(e){return"email"===e.type?new eL(e):new eB(e)}}]),MessageRecipientsClient}();function ownKeys(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,a)}return n}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(n),!0).forEach(function(t){I.default(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var e$=N.default(function ClientServices(){D.default(this,ClientServices)});t.KU=(a=function(e){U.default(Client,e);var t,n,a,i,s,o,u,c,l,d,p,f,h,y,m,v,_,g=(t=function(){if("undefined"==typeof Reflect||!Reflect.construct||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}}(),function(){var e,n=j.default(Client);if(t){var a=j.default(this).constructor;e=Reflect.construct(n,arguments,a)}else e=n.apply(this,arguments);return A.default(this,e)});function Client(e){var t,n,a,i,s,o,u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(D.default(this,Client),o=g.call(this),I.default(O.default(o),"version",eU),I.default(O.default(o),"connectionState","unknown"),I.default(O.default(o),"parsePushNotification",r.parsePushNotification),o._fpaToken=null!=e?e:"",o._options=null!=u?u:{},!o._options.disableDeepClone){var c=_objectSpread(_objectSpread({},o._options),{},{transport:void 0,twilsockClient:void 0});(c=JSON.parse(JSON.stringify(c))).transport=o._options.transport,c.twilsockClient=o._options.twilsockClient,o._options=c}o._options.logLevel=null!==(t=o._options.logLevel)&&void 0!==t?t:"silent",r._logger.setLevel(o._options.logLevel);var l=o._options.productId="ip_messaging";if(o._options.clientMetadata=o._options.clientMetadata||{},o._options.clientMetadata.hasOwnProperty("type")||(o._options.clientMetadata.type="conversations"),o._options.clientMetadata.hasOwnProperty("sdk")||(o._options.clientMetadata.sdk="JS",o._options.clientMetadata.sdkv=eU),o._options.Sync=o._options.Sync||{},void 0===o._options.Sync.enableSessionStorage&&(o._options.Sync.enableSessionStorage=!0),o._options.region&&(o._options.Sync.region=o._options.region),!e)throw Error("A valid Twilio token should be provided");o._services=new e$,o._myself=new et("","",null,o._services);var d=!o._options.twilsockClient;if(!o._options.initRegistrations){var p=new C.InitRegistration(l);r.populateInitRegistrations(p),o._options.initRegistrations=[p]}o._services.twilsockClient=o._options.twilsockClient=null!==(n=o._options.twilsockClient)&&void 0!==n?n:new C.TwilsockClient(e,l,o._options),o._services.twilsockClient.on(r.tokenAboutToExpire,function(){return o.emit(r.tokenAboutToExpire)}),o._services.twilsockClient.on(r.tokenExpired,function(){return o.emit(r.tokenExpired)}),o._services.twilsockClient.on(r.connectionError,function(e){return o.emit(r.connectionError,e)}),o._services.twilsockClient.on("stateChanged",function(e){r._logger.debug("Handling stateChanged for ConversationsClient: new state ".concat(e)),e!==o.connectionState&&(o.connectionState=e,o.emit(r.connectionStateChanged,o.connectionState))}),o._services.transport=o._options.transport=null!==(a=o._options.transport)&&void 0!==a?a:o._options.twilsockClient,o._services.notificationClient=o._options.notificationsClient=null!==(i=o._options.notificationsClient)&&void 0!==i?i:new S.Notifications(e,o._options),o._services.syncClient=o._options.syncCl
1ient=null!==(s=o._options.syncClient)&&void 0!==s?s:new P.SyncClient(e,o._options);var f=(null==u?void 0:u.Chat)||(null==u?void 0:u.IPMessaging)||u||{},h=f.region||(null==u?void 0:u.region),y=f.apiUri||f.typingUri||"https://aim.".concat(h||"us1",".twilio.com");o._services.commandExecutor=new ej(y,{transport:o._options.transport},l),o._services.contentClient=new eI(o._services);var emitFailed=function(e){o._rejectEnsureReady(e),o.emit(r.stateChanged,"failed"),o.emit(r.initFailed,{error:e})},emitDisconnected=function(){emitFailed({terminal:!0,message:"Twilsock has disconnected."}),o._initializeEnsureReady((null==u?void 0:u.throwErrorsAlways)||!1)};return o._services.twilsockClient.once("connectionError",emitFailed),o._services.twilsockClient.once("disconnected",emitDisconnected),o._services.twilsockClient.once("connected",M.default(L.default.mark(function _callee(){var e,t;return L.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return r._logger.debug("ConversationsClient started INITIALIZING"),o._services.twilsockClient.off("connectionError",emitFailed),o._services.twilsockClient.off("disconnected",emitDisconnected),n.prev=3,e="conversations.client.startup",o._services.twilsockClient.addPartialTelemetryEvent(new C.TelemetryEventDescription(e,"Conversations client startup",new Date),e,C.TelemetryPoint.Start),n.next=8,o._initialize();case 8:o._services.twilsockClient.addPartialTelemetryEvent(new C.TelemetryEventDescription("","",new Date),e,C.TelemetryPoint.End),n.next=17;break;case 11:n.prev=11,n.t0=n.catch(3),t={terminal:!0,message:n.t0.message},o._rejectEnsureReady(t),o.emit(r.stateChanged,"failed"),o.emit(r.initFailed,{error:t});case 17:case"end":return n.stop()}},_callee,null,[[3,11]])}))),o._initializeEnsureReady((null==u?void 0:u.throwErrorsAlways)||!1),d&&o._services.twilsockClient.connect(),o}return N.default(Client,[{key:"user",get:function(){return this._myself}},{key:"reachabilityEnabled",get:function(){if(!this._configuration)throw 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:"shutdown",value:(n=M.default(L.default.mark(function _callee2(){return L.default.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()}},_callee2,this)})),function(){return n.apply(this,arguments)})},{key:"updateToken",value:(a=M.default(L.default.mark(function _callee3(e){return L.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._ensureReady;case 2:if(r._logger.info("updateToken"),this._fpaToken!==e){t.next=5;break}return t.abrupt("return",this);case 5:return t.next=7,this._services.twilsockClient.updateToken(e);case 7:return t.next=9,this._services.notificationClient.updateToken(e);case 9:return t.next=11,this._services.mcsClient.updateToken(e);case 11:return this._fpaToken=e,t.abrupt("return",this);case 13:case"end":return t.stop()}},_callee3,this)})),function(e){return a.apply(this,arguments)})},{key:"getConversationBySid",value:(i=M.default(L.default.mark(function _callee4(e){var t;return L.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,this._ensureReady;case 2:return n.next=4,this._conversationsEntity.myConversationsRead.promise;case 4:return n.next=6,this._conversationsEntity.getConversation(e);case 6:if(t=n.sent){n.next=12;break}return n.next=10,this.peekConversationBySid(e);case 10:(t=n.sent)&&E.deprecationWarning("The method getConversationBySid is deprecated to retrieve conversations you're not part of. Use peekConversationBySid instead.");case 12:if(t){n.next=14;break}throw Error("Conversation with SID ".concat(e," was not found."));case 14:return n.abrupt("return",t);case 15:case"end":return n.stop()}},_callee4,this)})),function(e){return i.apply(this,arguments)})},{key:"peekConversationBySid",value:(s=M.default(L.default.mark(function _callee5(e){var t;return L.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,this._ensureReady;case 2:return n.next=4,this._conversationsEntity.peekConversation(e);case 4:if(t=n.sent){n.next=7;break}throw Error("Conversation with SID ".concat(e," was not found."));case 7:return n.abrupt("return",t);case 8:case"end":return n.stop()}},_callee5,this)})),function(e){return s.apply(this,arguments)})},{key:"getConversationByUniqueName",value:(o=M.default(L.default.mark(function _callee6(e){var t;return L.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,this._ensureReady;case 2:return n.next=4,this._conversationsEntity.myConversationsRead.promise;case 4:return n.next=6,this._conversationsEntity.getConversationByUniqueName(e);case 6:if(t=n.sent){n.next=9;break}throw Error("Conversation with unique name ".concat(e," was not found."));case 9:return n.abrupt("return",t);case 10:case"end":return n.stop()}},_callee6,this)})),function(e){return o.apply(this,arguments)})},{key:"getSubscribedConversations",value:(u=M.default(L.default.mark(function _callee7(){return L.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;
1case 2:return e.abrupt("return",this._conversationsPromise.then(function(e){return e.getConversations()}));case 3:case"end":return e.stop()}},_callee7,this)})),function(){return u.apply(this,arguments)})},{key:"createConversation",value:(c=M.default(L.default.mark(function _callee8(e){return L.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._ensureReady;case 2:return e=e||{},t.abrupt("return",this._conversationsPromise.then(function(t){return t.addConversation(e)}));case 4:case"end":return t.stop()}},_callee8,this)})),function(e){return c.apply(this,arguments)})},{key:"setPushRegistrationId",value:(l=M.default(L.default.mark(function _callee9(e,t){return L.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,this._ensureReady;case 2:return this._subscribeToPushNotifications(e),this._services.notificationClient.setPushRegistrationId(e,t),n.next=6,this._services.notificationClient.commitChanges();case 6:case"end":return n.stop()}},_callee9,this)})),function(e,t){return l.apply(this,arguments)})},{key:"unsetPushRegistrationId",value:(d=M.default(L.default.mark(function _callee10(e){return L.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._ensureReady;case 2:return this._unsubscribeFromPushNotifications(e),t.next=5,this._services.notificationClient.commitChanges();case 5:case"end":return t.stop()}},_callee10,this)})),function(e){return d.apply(this,arguments)})},{key:"removePushRegistrations",value:(p=M.default(L.default.mark(function _callee11(e,t){return L.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,this._services.notificationClient.removeRegistrations(e,t);case 2:case"end":return n.stop()}},_callee11,this)})),function(e,t){return p.apply(this,arguments)})},{key:"handlePushNotification",value:(f=M.default(L.default.mark(function _callee12(e){return L.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._ensureReady;case 2:r._logger.debug("handlePushNotification, notificationPayload=",e),this.emit("pushNotification",r.parsePushNotification(e));case 4:case"end":return t.stop()}},_callee12,this)})),function(e){return f.apply(this,arguments)})},{key:"getUser",value:(h=M.default(L.default.mark(function _callee13(e){return L.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._ensureReady;case 2:return t.abrupt("return",this._services.users.getUser(e));case 3:case"end":return t.stop()}},_callee13,this)})),function(e){return h.apply(this,arguments)})},{key:"getSubscribedUsers",value:(y=M.default(L.default.mark(function _callee14(){return L.default.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()}},_callee14,this)})),function(){return y.apply(this,arguments)})},{key:"getTemporaryContentUrlsForMediaSids",value:function(e){var t,n=this;return new R.CancellablePromise((t=M.default(L.default.mark(function _callee15(t,a,r){var i;return L.default.wrap(function(s){for(;;)switch(s.prev=s.next){case 0:if(!(!n._services.mcsClient||!e)){s.next=3;break}return a(Error("Media Content Service is unavailable")),s.abrupt("return");case 3:return i=n._services.mcsClient.mediaSetGetContentUrls(e),r(function(){i.cancel()}),s.prev=5,s.next=8,i;case 8:t(s.sent),s.next=15;break;case 12:s.prev=12,s.t0=s.catch(5),a(s.t0);case 15:case"end":return s.stop()}},_callee15,null,[[5,12]])})),function(e,n,a){return t.apply(this,arguments)}))}},{key:"getTemporaryContentUrlsForMedia",value:function(e){var t=e.map(function(e){return e.sid});return this.getTemporaryContentUrlsForMediaSids(t)}},{key:"getContentTemplates",value:(m=M.default(L.default.mark(function _callee16(){return L.default.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.contentClient.getContentTemplates();case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}},_callee16,this)})),function(){return m.apply(this,arguments)})},{key:"_initialize",value:(v=M.default(L.default.mark(function _callee17(){var e,t=this;return L.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,this._services.commandExecutor.fetchResource("Client/v2/Configuration");case 2:return e=n.sent,this._configuration=new W(this._options,e,r._logger),this._services.channelMetadataClient=new eD(this._services,this._configuration),this._services.messageRecipientsClient=new ez(this._services,this._configuration),this._myself._resolveInitialization(this._configuration,this._configuration.userIdentity,this._configuration.userInfo,!0),this._services.typingIndicator=new eM(this.getConversationBySid.bind(this),this._configuration,this._services),this._services.network=new en(this._configuration,this._services),this._services.users=new eE(this._myself,this._configuration,this._services),this._services.users.on("userSubscribed",function(e){t.emit("userSubscribed",e)}),this._services.users.on("userUpdated",function(e){return t.emit("userUpdated",e)}),this._services.users.on("userUnsubscribed",function(e){t.emit("userUnsubscribed",e)}),this._conversationsEntity=new eR(this._configuration,this._services),this._conversationsEntity.on("conversationAdded",function(e){t.emit("conversationAdded",e)}),this._conversationsEntity.on("conversationRemoved",function(e){t.emit("conversationRemoved",e)}),this._conversationsEntity.on("conversationJoined",function(e){t.emit("conversationJoined",e)}),this._conversationsEntity.on("conversationLeft",function(e){t.emit("conversationLeft",e)}),this._conversationsEntity.on("conversationUpdated",function(e){return t.emit("conversationUpdated",e)}),this._conversationsEntity.on("participantJoined",function(e){t.emit("participantJoined",e)}),this._conversationsEntity.on("participantLeft",function(e){t.emit("participantLeft",e)}),this._conversationsEntity.on("participantUpdated",function(e){return t.emit("participantUpdated",e)}),this._conversationsEntity.on("messageAdded",function(e){return t.emit("messageAdded",e)}),this._conversationsEntity.on("messageUpdated",function(e){return t.emit("messageUpdated",e)}),this._conversationsEntity.on("messageRemoved",function(e){return t.emit("messageRemoved",e)}),this._conversationsEntity.on("typingStarted",function(e){return t.emit("typingStarted",e)}),this._conversationsEntity.on("typingEnded",function(e){return t.emit("typingEnded",e)}
1),this._conversationsPromise=this._conversationsEntity.fetchConversations().then(function(){return t._conversationsEntity}).catch(function(e){throw console.error("Failed to fetch conversations _conversationsPromise -> client.ts",e),e}),n.next=30,this._services.users.myself._ensureFetched();case 30:r._supportedPushChannels.forEach(function(e){return t._subscribeToPushNotifications(e)}),this._services.typingIndicator.initialize(),this._services.mcsClient=new R.McsClient(this._fpaToken,this._configuration.links.mediaService,this._configuration.links.mediaSetService,_objectSpread(_objectSpread({},this._options),{},{transport:void 0})),this._resolveEnsureReady(),this.emit(r.stateChanged,"initialized"),this.emit(r.initialized);case 36:case"end":return n.stop()}},_callee17,this)})),function(){return v.apply(this,arguments)})},{key:"_subscribeToPushNotifications",value:function(e){var t=this;[ea.NEW_MESSAGE,ea.ADDED_TO_CONVERSATION,ea.REMOVED_FROM_CONVERSATION,ea.TYPING_INDICATOR,ea.CONSUMPTION_UPDATE].forEach(function(n){t._services.notificationClient.subscribe(e,n)})}},{key:"_unsubscribeFromPushNotifications",value:function(e){var t=this;[ea.NEW_MESSAGE,ea.ADDED_TO_CONVERSATION,ea.REMOVED_FROM_CONVERSATION,ea.TYPING_INDICATOR,ea.CONSUMPTION_UPDATE].forEac
1h(function(n){t._services.notificationClient.unsubscribe(e,n)})}},{key:"_initializeEnsureReady",value:function(e){var t=this;this._ensureReady=new Promise(function(e,n){t._resolveEnsureReady=e,t._rejectEnsureReady=n}).catch(function(t){if(e)throw t})}}],[{key:"create",value:(_=M.default(L.default.mark(function _callee18(e,t){var n;return L.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(!(null!=t&&t.twilsockClient)){a.next=2;break}throw 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 n=new r(e,t),a.next=5,n._ensureReady;case 5:return a.abrupt("return",n);case 6:case"end":return a.stop()}},_callee18)})),function(e,t){return _.apply(this,arguments)})},{key:"parsePushNotification",value:function(e){if(r._logger.debug("parsePushNotification, notificationPayload=",e),void 0!==e.aps){if(!e.twi_message_type)throw Error("Provided push notification payload does not contain Programmable Chat push notification type");var t,n,a,i=r._parsePushNotificationChatData(e),s=e.aps,o=null;return"string"==typeof s.alert?t=s.alert||null:(t=(null===(n=s.alert)||void 0===n?void 0:n.body)||null,o=(null===(a=s.alert)||void 0===a?void 0:a.title)||null),new eO({title:o,body:t,sound:s.sound||null,badge:s.badge||null,action:s.category||null,type:e.twi_message_type,data:i})}if(void 0!==e.data){var u=e.data;if(!u.twi_message_type)throw Error("Provided push notification payload does not contain Programmable Chat push notification type");var c=r._parsePushNotificationChatData(e.data);return new eO({title:u.twi_title||null,body:u.twi_body||null,sound:u.twi_sound||null,badge:null,action:u.twi_action||null,type:u.twi_message_type,data:c})}throw Error("Provided push notification payload is not Programmable Chat notification")}},{key:"_parsePushNotificationChatData",value:function(e){var t={};for(var n in r._supportedPushDataFields){var a=e[n];if(null!=a){if("message_index"===n||"media_count"===n){var i=parseToNumber(a);null!==i&&(t[r._supportedPushDataFields[n]]=i);continue}if("media"===n){if("string"==typeof a)try{t[r._supportedPushDataFields[n]]=JSON.parse(a)}catch(e){r._logger.debug("Media message notification parsing error")}continue}t[r._supportedPushDataFields[n]]=a}}return t}},{key:"populateInitRegistrations",value:function(e){e.populateInitRegistrations([ea.TYPING_INDICATOR]),P.SyncClient.populateInitRegistrations(e)}}]),Client}(k.ReplayEventEmitter),I.default(a,"conversationAdded","conversationAdded"),I.default(a,"conversationJoined","conversationJoined"),I.default(a,"conversationLeft","conversationLeft"),I.default(a,"conversationRemoved","conversationRemoved"),I.default(a,"conversationUpdated","conversationUpdated"),I.default(a,"participantJoined","participantJoined"),I.default(a,"participantLeft","participantLeft"),I.default(a,"participantUpdated","participantUpdated"),I.default(a,"messageAdded","messageAdded"),I.default(a,"messageRemoved","messageRemoved"),I.default(a,"messageUpdated","messageUpdated"),I.default(a,"tokenAboutToExpire","tokenAboutToExpire"),I.default(a,"tokenExpired","tokenExpired"),I.default(a,"typingEnded","typingEnded"),I.default(a,"typingStarted","typingStarted"),I.default(a,"pushNotification","pushNotification"),I.default(a,"userSubscribed","userSubscribed"),I.default(a,"userUnsubscribed","userUnsubscribed"),I.default(a,"userUpdated","userUpdated"),I.default(a,"stateChanged","stateChanged"),I.default(a,"initialized","initialized"),I.default(a,"initFailed","initFailed"),I.default(a,"connectionStateChanged","connectionStateChanged"),I.default(a,"connectionError","connectionError"),I.default(a,"version",eU),I.default(a,"_logger",H.scope("Client")),I.default(a,"_supportedPushChannels",["fcm","apn"]),I.default(a,"_supportedPushDataFields",{conversation_sid:"conversationSid",conversation_title:"conversationTitle",message_sid:"messageSid",message_index:"messageIndex",media_count:"mediaCount",media:"media"}),r=a),__decorate([E.deprecated("token"),__metadata("design:type",String),__metadata("design:paramtypes",[])],t.KU.prototype,"token",null),__decorate([g.validateTypesAsync(g.nonEmptyString),__metadata("design:type",Function),__metadata("design:paramtypes",[String]),__metadata("design:returntype",Promise)],t.KU.prototype,"updateToken",null),__decorate([g.validateTypesAsync(g.nonEmptyString),__metadata("design:type",Function),__metadata("design:paramtypes",[String]),__metadata("design:returntype",Promise)],t.KU.prototype,"getConversationBySid",null),__decorate([g.validateTypesAsync(g.nonEmptyString),__metadata("design:type",Function),__metadata("design:paramtypes",[String]),__metadata("design:returntype",Promise)],t.KU.prototype,"peekConversationBySid",null),__decorate([g.validateTypesAsync(g.nonEmptyString),__metadata("design:type",Function),__metadata("design:paramtypes",[String]),__metadata("design:returntype",Promise)],t.KU.prototype,"getConversationByUniqueName",null),__decorate([g.validateTypesAsync(["undefined",g.objectSchema("conversation options",{friendlyName:["string","undefined"],isPrivate:["boolean","undefined"],uniqueName:["string","undefined"]})]),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],t.KU.prototype,"createConversation",null),__decorate([g.validateTypesAsync(g.literal("fcm","apn"),"string"),__metadata("design:type",Function),__metadata("design:paramtypes",[String,String]),__metadata("design:returntype",Promise)],t.KU.prototype,"setPushRegistrationId",null),__decorate([g.validateTypesAsync(g.literal("fcm","apn")),__metadata("design:type",Function),__metadata("design:paramtypes",[String]),__metadata("design:returntype",Promise)],t.KU.prototype,"unsetPushRegistrationId",null),__decorate([g.validateTypesAsync(g.literal("fcm","apn"),g.nonEmptyString),__metadata("design:type",Function),__metadata("design:paramtypes",[String,String]),__metadata("design:returntype",Promise)],t.KU.prototype,"removePushRegistrations",null),__decorate([g.validateTypesAsync(g.pureObject),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],t.KU.prototype,"handlePushNotification",null),__decorate([g.validateTypesAsync(g.nonEmptyString),__metadata("design:type",Function),__metadata("design:paramtypes",[String]),__metadata("design:returntype",Promise)],t.KU.prototype,"getUser",null),__decorate([g.validateTypesAsync(g.nonEmptyArray("strings","string")),__metadata("design:type",Function),__metadata("design:paramtypes",[Array]),__metadata("design:returntype",R.CancellablePromise)],t.KU.prototype,"getTemporaryContentUrlsForMediaSids",null),__decorate([g.validateTypesAsync(g.nonEmptyArray("media",eu)),__metadata("design:type",Function),__metadata("design:paramtypes",[Array]),__metadata("design:returntype",R.CancellablePromise)],t.KU.prototype,"getTemporaryContentUrlsForMedia",null),__decorate([E.deprecated("Client.create()","new Client()"),g.validateTypesAsync("string",["undefined",g.pureObject]),__metadata("design:type",Function),__metadata("design:paramtypes",[String,Object]),__metadata("design:returntype",Promise)],t.KU,"create",null),__decorate([g.validateTypes(g.pureObject),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",eO)],t.KU,"parsePushNotification",null),t.KU=r=__decorate([g.validateConstructorTypes(g.nonEmptyString,[g.pureObject,"undefined"]),__metadata("design:paramtypes",[String,Object])],t.KU)}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.